.============================================================
.  YOUR SUBROUTINES -- Write your VNW logic here
.
.  In every subroutine, each control has its own auto-set variables:
.    [ctrl_id.name]   = ID of the control that fired
.    [ctrl_id.event]  = event name (e.g. Left_Click, Value_Changed)
.    [ctrl_id.value]  = current value / state of the control
.    [ctrl_id.sub]    = primary subroutine name
.    [ctrl_id.prop]   = primary property name
.
.  To set a control property from VNW:
.    SetVar "[lbl_result.caption]"   "Hello!"
.    SetVar "[SetObjectProperty]"    "lbl_result.caption"
.    GoSub "SetProp"
.
.  Or use the Companion plugin command:
.    NWID_Set "Rectangle1" "label:lbl_result" "caption" "Hello!"
.============================================================

. No event subroutines assigned yet.
. Assign eventSub names to controls in the designer,
. then re-export to generate stubs here.
.------------------------------------------------------------
. PAGE EVENTS  one pair per page
. Add your logic above each Return
.------------------------------------------------------------

:Page_1_OnEnter
. Fires every time the Page_1 page becomes active
. [NWID.PageName] = Page_1
Return

:Page_1_OnExit
. Fires just before leaving the Page_1 page
. [NWID.PageName] = Page_1
Return

.------------------------------------------------------------
. :NWID_OnReady -- fires once when the runtime is fully loaded
.   All per-control variables are already initialised.
.   Use this for one-time startup logic (load data, set defaults, etc.)
.------------------------------------------------------------
:NWID_OnReady
. Add your startup logic here
Return

.------------------------------------------------------------
. :NWID_OnPageChanged -- fires after every page change (global)
.   [NWID.PageName]  = name of the new active page
.   [NWID.PageIndex] = 0-based index of the new active page
.------------------------------------------------------------
:NWID_OnPageChanged
. Add your page-change logic here
Return

.------------------------------------------------------------
. :NWID_OnPropValue -- fires when NWID_Get returns a value.
.   [NWID.PropName]  = property that was read
.   [NWID.PropValue] = the returned value
.------------------------------------------------------------
:NWID_OnPropValue
. Fires when getProp() returns a value.
. [NWID.PropName] = property name
. [NWID.PropValue] = value returned
Return


.============================================================
.  NWID RUNTIME SUBROUTINES -- AUTO-GENERATED
.  NeoWin Interface Designer
.
.  *** DO NOT EDIT ANYTHING BELOW THIS LINE ***
.  *** Re-export from NWID to regenerate      ***
.============================================================

.============================================================
.  INFRASTRUCTURE -- Do not edit
.============================================================

:Initialize
ezEdgeAvailable "[isEdgeAvailable]" "[Result]"
If "[isEdgeAvailable]" "=" "True"
  ezEdgeCreate "Rectangle1" "[TempDir]NWIDCache" "NWID_EdgeReady" "" "[Result]"
Else
  AlertBox "Error" "WebView2 Runtime is required.[#13]Please install it from Microsoft."
  Run "explorer.exe" "https://developer.microsoft.com/en-us/microsoft-edge/webview2/#download-section" "Normal" "" ""
  Exit "" ""
EndIf
Return

:NWID_EdgeReady
ezEdgeMessageReceived "Rectangle1" "[NWID.Msg]" "NWID_OnMessage" "[Result]"
ezEdgeNavComplete "Rectangle1" "[NWID.NavTitle]" "NWID_OnNavComplete" "[Result]"
SetVar "[NWID.Rect]" "Rectangle1"
. *** Load your exported runtime HTML below -- update the path ***
. ezEdgeGoTo "Rectangle1" "[PubDir]runtime.html" "[Result]"
Return

:NWID_OnNavComplete
ezEdgeMessageReceived "Rectangle1" "[NWID.Msg]" "NWID_OnMessage" "[Result]"
. NWID_OnReady fires when the runtime sends NWID_READY: (after JS initialises).
. Do NOT GoSub NWID_OnReady here -- controls are not set up yet at nav time.
Return

:NWID_OnMessage
SetVar "[NWID.Rect]" "Rectangle1"
SearchStr "NWID_ROWDATA:" "[NWID.Msg]" "[_NP]" "CaseSensitive"
If "[_NP]" "=" "1"
  StrLen "[NWID.Msg]" "[_NL]"
  SubStr "[NWID.Msg]" "14" "[_NL]-13" "[_RD]"
  SearchStr "|" "[_RD]" "[_RP]" "CaseSensitive"
  If "[_RP]" ">" "0"
    SubStr "[_RD]" "1" "[_RP]-1" "[NWID.Row]"
    SubStr "[_RD]" "[_RP]+1" "[_NL]" "[NWID.RowData]"
  Else
    SetVar "[NWID.Row]" "[_RD]"
    SetVar "[NWID.RowData]" ""
  EndIf
EndIf
SearchStr "NWID_GOSUB:" "[NWID.Msg]" "[_NP]" "CaseSensitive"
If "[_NP]" "=" "1"
  StrLen "[NWID.Msg]" "[_NL]"
  SubStr "[NWID.Msg]" "12" "[_NL]-11" "[_NP1]"
  SearchStr "|" "[_NP1]" "[_P1]" "CaseSensitive"
  If "[_P1]" ">" "0"
    SubStr "[_NP1]" "1" "[_P1]-1" "[NWID.SubName]"
    SubStr "[_NP1]" "[_P1]+1" "[_NL]" "[_NP2]"
    SearchStr "|" "[_NP2]" "[_P2]" "CaseSensitive"
    If "[_P2]" ">" "0"
      SubStr "[_NP2]" "1" "[_P2]-1" "[NWID.ObjName]"
      SubStr "[_NP2]" "[_P2]+1" "[_NL]" "[_NP3]"
      SearchStr "|" "[_NP3]" "[_P3]" "CaseSensitive"
      If "[_P3]" ">" "0"
        SubStr "[_NP3]" "1" "[_P3]-1" "[NWID.EventName]"
        SubStr "[_NP3]" "[_P3]+1" "[_NL]" "[_NP4]"
        SearchStr "|" "[_NP4]" "[_P4]" "CaseSensitive"
        If "[_P4]" ">" "0"
          SubStr "[_NP4]" "1" "[_P4]-1" "[NWID.Value]"
          SubStr "[_NP4]" "[_P4]+1" "[_NL]" "[_NP5]"
          SearchStr "|" "[_NP5]" "[_P5]" "CaseSensitive"
          If "[_P5]" ">" "0"
            SubStr "[_NP5]" "1" "[_P5]-1" "[NWID.Key]"
            SubStr "[_NP5]" "[_P5]+1" "[_NL]" "[_NP6]"
            SearchStr "|" "[_NP6]" "[_P6]" "CaseSensitive"
            If "[_P6]" ">" "0"
              SubStr "[_NP6]" "1" "[_P6]-1" "[NWID.KeyStr]"
              SubStr "[_NP6]" "[_P6]+1" "[_NL]" "[_NP7]"
              SearchStr "|" "[_NP7]" "[_P7]" "CaseSensitive"
              If "[_P7]" ">" "0"
                SubStr "[_NP7]" "1" "[_P7]-1" "[NWID.KeyCode]"
              EndIf
            EndIf
          EndIf
        Else
          SetVar "[NWID.Value]" "[_NP4]"
        EndIf
      EndIf
    EndIf
    If "[NWID.ObjName]" "=" "txa_1"
      SetVar "[txa_1.value]" "[NWID.Value]"
      SetVar "[txa_1.name]" "txa_1"
      SetVar "[txa_1.event]" "[NWID.EventName]"
      SetVar "[txa_1.sub]"  ""
      SetVar "[txa_1.prop]" "value"
    EndIf
    If "[NWID.SubName]" "<>" ""
      GoSub "[NWID.SubName]"
    EndIf
  EndIf
EndIf
SearchStr "NWID_VALUE:" "[NWID.Msg]" "[_NP]" "CaseSensitive"
If "[_NP]" "=" "1"
  StrLen "[NWID.Msg]" "[_NL]"
  SubStr "[NWID.Msg]" "12" "[_NL]-11" "[_VP]"
  SearchStr "|" "[_VP]" "[_PP]" "CaseSensitive"
  If "[_PP]" ">" "0"
    SubStr "[_VP]" "1" "[_PP]-1" "[NWID.PropName]"
    SubStr "[_VP]" "[_PP]+1" "[_NL]" "[NWID.PropValue]"
  Else
    SetVar "[NWID.PropName]" "[_VP]"
    SetVar "[NWID.PropValue]" ""
  EndIf
  GoSub "NWID_OnPropValue"
EndIf
SearchStr "NWID_READY:" "[NWID.Msg]" "[_NP]" "CaseSensitive"
If "[_NP]" "=" "1"
  StrLen "[NWID.Msg]" "[_NL]"
  SubStr "[NWID.Msg]" "12" "[_NL]-11" "[_DIMS]"
  SearchStr ":" "[_DIMS]" "[_CP]" "CaseSensitive"
  If "[_CP]" ">" "0"
    SubStr "[_DIMS]" "1" "[_CP]-1" "[NWID.CanvasW]"
    SubStr "[_DIMS]" "[_CP]+1" "[_NL]" "[NWID.CanvasH]"
  EndIf
  GoSub "_NWID_InitVars"
EndIf
SearchStr "NWID_PAGE_EXIT:" "[NWID.Msg]" "[_NP]" "CaseSensitive"
If "[_NP]" "=" "1"
  StrLen "[NWID.Msg]" "[_NL]"
  SubStr "[NWID.Msg]" "16" "[_NL]-15" "[_PP]"
  SearchStr "|" "[_PP]" "[_PS]" "CaseSensitive"
  If "[_PS]" ">" "0"
    SubStr "[_PP]" "1" "[_PS]-1" "[NWID.PageName]"
    SubStr "[_PP]" "[_PS]+1" "[_NL]" "[NWID.PageIndex]"
  EndIf
  GoSub "NWID_OnPageExit"
EndIf
SearchStr "NWID_PAGE_ENTER:" "[NWID.Msg]" "[_NP]" "CaseSensitive"
If "[_NP]" "=" "1"
  StrLen "[NWID.Msg]" "[_NL]"
  SubStr "[NWID.Msg]" "17" "[_NL]-16" "[_PP]"
  SearchStr "|" "[_PP]" "[_PS]" "CaseSensitive"
  If "[_PS]" ">" "0"
    SubStr "[_PP]" "1" "[_PS]-1" "[NWID.PageName]"
    SubStr "[_PP]" "[_PS]+1" "[_NL]" "[NWID.PageIndex]"
  EndIf
  GoSub "NWID_OnPageEnter"
EndIf
SearchStr "NWID_PAGE_CHANGED:" "[NWID.Msg]" "[_NP]" "CaseSensitive"
If "[_NP]" "=" "1"
  StrLen "[NWID.Msg]" "[_NL]"
  SubStr "[NWID.Msg]" "20" "[_NL]-19" "[_PP]"
  SearchStr "|" "[_PP]" "[_PS]" "CaseSensitive"
  If "[_PS]" ">" "0"
    SubStr "[_PP]" "1" "[_PS]-1" "[NWID.PageName]"
    SubStr "[_PP]" "[_PS]+1" "[_NL]" "[NWID.PageIndex]"
  EndIf
  GoSub "NWID_OnPageChanged"
EndIf
SearchStr "NWID_ERROR:" "[NWID.Msg]" "[_NP]" "CaseSensitive"
If "[_NP]" "=" "1"
  StrLen "[NWID.Msg]" "[_NL]"
  SubStr "[NWID.Msg]" "12" "[_NL]-11" "[NWID.ErrorMsg]"
  AlertBox "NWID Runtime Error" "[NWID.ErrorMsg]"
EndIf
Return

:_NWID_InitVars
. Internal  sets up per-control variables, then calls :NWID_OnReady
. [NWID.CanvasW] and [NWID.CanvasH] are set to the first page dimensions.
.
. Control name variables -- auto-generated from your layout.
. [ctrl_id.name]  = control ID string
. [ctrl_id.event] = name of the event that fired
. [ctrl_id.sub]   = primary event subroutine name
. [ctrl_id.prop]  = primary readable/writable property
. For tables: [ctrl_id.col1] [ctrl_id.col2] ... = auto-parsed row columns
. For tables: [ctrl_id.colCount] = number of columns in clicked row
.
. txa_1  (textArea)
SetVar "[txa_1.name]" "txa_1"
SetVar "[txa_1.sub]"  ""  . wire a Value_Changed event to populate this
SetVar "[txa_1.prop]" "value"
SetVar "[txa_1.propKey]" "value"
.
. Page variables -- auto-generated from your layout.
. [PageName.name]   = page name string
. [PageName.width]  = canvas width in pixels
. [PageName.height] = canvas height in pixels
. [PageName.index]  = zero-based page index
. [PageName.mode]   = "center" / "fill" / "custom"
.
. Page_1  (page 0: Page_1)
SetVar "[Page_1.name]"   "Page_1"
SetVar "[Page_1.width]"  "1024"
SetVar "[Page_1.height]" "768"
SetVar "[Page_1.index]"  "0"
SetVar "[Page_1.mode]"   "center"
SetVar "[NWID.PageCount]" "1"
GoSub "_NWID_ApplyVars_Page_1"
GoSub "NWID_OnReady"
Return


:NWID_OnPageExit
. Fires just before leaving a page.
. [NWID.PageName]  = name of the page being left
. [NWID.PageIndex] = 0-based index of the page being left
If "[NWID.PageName]" "=" "Page_1"
  GoSub "Page_1_OnExit"
EndIf
Return

:NWID_OnPageEnter
. Fires when arriving on a page.
. [NWID.PageName]  = name of the page just entered
. [NWID.PageIndex] = 0-based index of the page just entered
If "[NWID.PageName]" "=" "Page_1"
  GoSub "_NWID_ApplyVars_Page_1"
  GoSub "Page_1_OnEnter"
EndIf
Return

:_NWID_ApplyVars_Page_1
. Auto-generated  substitutes VNW variables into text properties for "Page_1".
ezEdgeExecScript "[NWID.Rect]" "window.NWID.setProp('txa_1','value','VisualNeo Win Global Variables:\n\nTime: [Time]\nDate: [DateLong]\n\nSystem: [SystemLanguage]\n');" "" "[NWID.ExecResult]"
Return

.============================================================
.  NWID MACROS -- Do not edit
.============================================================

:SetProp
. Generic property setter  uses per-control variable names.
. Usage:
.   SetVar "[btn_go.caption]" "My new caption!"
.   SetVar "[SetObjectProperty]" "btn_go.caption"
.   GoSub "SetProp"
SearchStr "." "[SetObjectProperty]" "[_SPDot]" "CaseSensitive"
If "[_SPDot]" ">" "0"
  SubStr "[SetObjectProperty]" "1" "[_SPDot]-1" "[NWID.TargetId]"
  StrLen "[SetObjectProperty]" "[_SPLen]"
  SubStr "[SetObjectProperty]" "[_SPDot]+1" "[_SPLen]" "[NWID.SetPropName]"
  SetVar "[NWID.SetPropValue]" "[[SetObjectProperty]]"
  GoSub "NWID_SetProp"
EndIf
Return

:NWID_SetProp
. Low-level property setter (used by :SetProp internally).
. [NWID.TargetId]     = control id
. [NWID.SetPropName]  = property name
. [NWID.SetPropValue] = value
StrReplace "[NWID.SetPropValue]" "'" "\\'" "[_SafeVal]" ""
ezEdgeExecScript "[NWID.Rect]" "window.NWID.setProp('[NWID.TargetId]','[NWID.SetPropName]','[_SafeVal]');" "" "[NWID.ExecResult]"
Return

:NWID_GetProp
. Get a control property -- response fires NWID_OnPropValue.
. [NWID.TargetId]    = control id
. [NWID.GetPropName] = property name
ezEdgeExecScript "[NWID.Rect]" "window.NWID.getProp('[NWID.TargetId]','[NWID.GetPropName]');" "" "[NWID.ExecResult]"
Return

:NWID_GetPropSync
. Read a property IMMEDIATELY -- result goes straight into a variable.
. No callback needed. Much simpler than NWID_GetProp for most uses.
. [NWID.TargetId]    = control id
. [NWID.GetPropName] = property name
. [NWID.PropResult]  = receives the value
ezEdgeExecScript "[NWID.Rect]" "window.NWID.getPropSync('[NWID.TargetId]','[NWID.GetPropName]');" "[NWID.PropResult]" "[NWID.ExecResult]"
Return

:NWID_Show
SetVar "[NWID.SetPropName]" "visible"
SetVar "[NWID.SetPropValue]" "true"
GoSub "NWID_SetProp"
Return

:NWID_Hide
SetVar "[NWID.SetPropName]" "visible"
SetVar "[NWID.SetPropValue]" "false"
GoSub "NWID_SetProp"
Return

:NWID_Enable
SetVar "[NWID.SetPropName]" "enabled"
SetVar "[NWID.SetPropValue]" "true"
GoSub "NWID_SetProp"
Return

:NWID_Disable
SetVar "[NWID.SetPropName]" "enabled"
SetVar "[NWID.SetPropValue]" "false"
GoSub "NWID_SetProp"
Return

:NWID_SetFocus
. Set keyboard focus to a control.
. [NWID.TargetId] = control ID
ezEdgeExecScript "[NWID.Rect]" "window.NWID.setFocus('[NWID.TargetId]');" "" "[NWID.ExecResult]"
Return

:NWID_ShowPage
. Switch to a named or indexed page in the runtime.
. [NWID.SetPropValue] = page name or 0-based index
ezEdgeExecScript "[NWID.Rect]" "window.NWID.showPage('[NWID.SetPropValue]');" "" "[NWID.ExecResult]"
Return

:NWID_NextPage
. Advance to the next page (wraps around).
ezEdgeExecScript "[NWID.Rect]" "window.NWID.nextPage();" "" "[NWID.ExecResult]"
Return

:NWID_PrevPage
. Go back to the previous page (wraps around).
ezEdgeExecScript "[NWID.Rect]" "window.NWID.prevPage();" "" "[NWID.ExecResult]"
Return

:NWID_LoadFile
. Load an HTML file into the runtime rectangle.
. [NWID.Rect]     = rectangle name (already set)
. [NWID.LoadPath] = full path to HTML file
ezEdgeGoTo "[NWID.Rect]" "[NWID.LoadPath]" "[Result]"
Return

:OnAppExit
. Kill all JS timers and silence the bridge before teardown
ezEdgeExecScript "[NWID.Rect]" "if(window.NWID_shutdown)window.NWID_shutdown();" "" "[NWID.ExecResult]"
Delay "300"
ezEdgeGoTo "[NWID.Rect]" "about:blank" "[Result]"
Delay "500"
ezEdgeDeleteCache "[NWID.Rect]" "[TempDir]NWIDCache" "[Result]"
ezEdgeDelete "[NWID.Rect]" "[Result]"
Delay "200"
Exit "" ""
Return


.============================================================
.  CONTROL-SPECIFIC HELPERS (auto-generated -- do not edit)
.  These are convenience wrappers for your layout controls.
.============================================================

.------------------------------------------------------------
. txa_1  (textArea)
.------------------------------------------------------------
:Set_txa_1
. Set text value on txa_1
. Preferred: SetVar "[txa_1.value]" "your value"
.            SetVar "[SetObjectProperty]" "txa_1.value"
.            GoSub "SetProp"
. Legacy:    SetVar "[NWID.SetPropValue]" "your value"
.            GoSub "Set_txa_1"
SetVar "[NWID.TargetId]" "txa_1"
SetVar "[NWID.SetPropName]" "value"
GoSub "NWID_SetProp"
Return

:Show_txa_1
. Show txa_1
SetVar "[NWID.TargetId]" "txa_1"
GoSub "NWID_Show"
Return

:Hide_txa_1
. Hide txa_1
SetVar "[NWID.TargetId]" "txa_1"
GoSub "NWID_Hide"
Return

:Focus_txa_1
. Set focus to txa_1
SetVar "[NWID.TargetId]" "txa_1"
GoSub "NWID_SetFocus"
Return

:Get_txa_1
. Read text value from txa_1 into [NWID.PropResult].
. No callback -- value is available immediately after GoSub returns.
SetVar "[NWID.TargetId]" "txa_1"
SetVar "[NWID.GetPropName]" "value"
GoSub "NWID_GetPropSync"
. [NWID.PropResult] now contains the value
Return
