! Tests the HTTPWINDOW command
!
! @author  Jay Hallam
!
startmacro
  switch INTERACTIVE interAct GET DEF=TRUE

  set usersGuideURL "file:///^{env.nmroot}/htdocs/usersguide/index.html"
  set trainingURL   "file:///^{env.nmroot}/htdocs/training/index.html"
  set homeURL       "file:///^{env.nmroot}/htdocs/index.html"
  set mainIndexURL  "file:///^{env.nmroot}/htdocs/help/index.html"

  invoke isWindows nxm.sys.lib.Shell.isWindows()
  if isWindows then
    set backslash "\\"
    invoke usersGuideURL usersGuideURL.replace(backslash,"/")
    invoke trainingURL   trainingURL.replace(backslash,"/")
    invoke homeURL       homeURL.replace(backslash,"/")
    invoke mainIndexURL  mainIndexURL.replace(backslash,"/")
  endif

  if interAct then
    pipe init
      panel/setup/controls=gc
      httpwin/id=hw1/exit="MESSAGE"/title="HttpWindow 1"
      httpwin/id=hw2/ONEXIT=CLOSE/exit="ALL"/SHOW/title="HttpWindow 2" PAGE="^homeURL"

      set instructions1 "WINDOW 1 - Is hidden on startup, should exit on MESSAGE only and HIDE on CLOSE/EXIT.  &
                         Click Show Users Guide to make window visible and to display Users Guide"

      set instructions2 "WINDOW 2 - Can EXIT on WINDOW or MESSAGE and CLOSES on exit.  &
                         Click Show Training to make this window visible and to display Training"

      set instructions3 "MULTI-HEAD ONLY - On a multiheaded workstation, move the display to each &
                         head by selecting the display pull-down."


      gcontrol label  MACRO "Main"
        gcontrol menu main "Exit with Status = " "PASS,FAIL" "PASS" /tleft
        set gc.MAIN.itemColors {PASS=GREEN,FAIL=RED}

        gcontrol text idtext1 "Instructions - Window 1" "^instructions1" 24 5 /title
        gcontrol text idtext2 "Instructions - Window 2" "^instructions2" 24 5 /title
        gcontrol menu showwin1 "Window 1" "Show" "" /tleft /toggle /chkbox
        gcontrol menu showwin2 "Window 2" "Show" "Show" /tleft /toggle /chkbox
        gcontrol button showUsersGuide "" "Show Users Guide - Window 1" "" /tleft
        gcontrol button showTraining "" "Show Training - Window 2" "" /tleft
        gcontrol button showMainIndex "" "Show main index page via message to Window 2" "" /tleft
        gcontrol text idtext3 "Display Instructions" "^instructions3" 24 3 /title
    pipe wait
    pipe off
  endif

endmacro

procedure processMessage m:msg
  if msg.name eqs "MAIN"
    assert/text="^reg.main.name: user indicated" msg.data eqs "PASS"
    pipe stop
  elseif msg.name eqs "SHOWWIN1" then
    set reg.hw1.show msg.info

  elseif msg.name eqs "SHOWWIN2" then
    set reg.hw2.show msg.info

  elseif msg.name eqs "SHOWUSERSGUIDE" then
    set reg.hw1.show 1
    set reg.hw2.show 0
    set reg.hw1.page "^usersGuideURL"

  elseif msg.name eqs "SHOWTRAINING" then
    set reg.hw2.show 1
    set reg.hw1.show 0
    set reg.hw2.page("^trainingURL")

  elseif msg.name eqs "SHOWMAININDEX" then
    set reg.hw2.show 1
    set reg.hw1.show 0
    message send hw2 ,, "SETPAGE",, mainIndexURL

  else
    ! do nothing
    say "Unhandled message name: ^msg.name from fid: ^msg.fid data: ^msg.data"
  endif

return

procedure failedATest s:msg
  assert/text="^reg.main.name: ^msg" FALSE
  calc L:failedTests failedTests 1 +
return

