!**************************************************************************************************!
! author : JPH
!
! purpose: BUG 1900: test the GCONTROL /EDIT switch
!**************************************************************************************************!
startmacro
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE  ! for normal interactive test(s)

  res valTab {}
  res D:valTab.dval1 1.0
  res L:valTab.fval1 1.0
  res L:valTab.lval1 1
  res D:valTab.tval1 1
  res S:valTab.prompt1 "Initial"
  res S:valTab.button1 "Initial"
  res S:valTab.menu1   "Initial"
  res S:valTab.choice1 "Initial"

  res L:numValTabMsgs 0
  calc L:expectedNumValTabMsgs valTab.getSize ! 1 for each simulated click (action)

  res z:actionChangeClicked false
  pipe on

    panel/msgid=MAIN/setup/controls=gc

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

    set instructions "1) Click only once on the ACTION_CHANGE test.\n&
                      2) Clicking on any of the 'Controls with /EDIT=F' should NOT change &
                      their appearance or send a message.\n\n&
                      Upon exiting this test, check the terminal for the automatic test results.\n\n&"

    gcontrol TEXT instructText instructions "^instructions" 24 6 /title

    gcontrol button ACTIONCHANGE    "" "ACTION_CHANGE"

    gcontrol label  xvalLab "Controls with /EDIT=f"
      set gc.valTab {}
      gcontrol DVAL valTab.dval1 "DVAL1" DEF=1 MIN=0 MAX=-1 INC=0.001  /edit=f
      gcontrol FVAL valTab.fval1 "FVAL1" DEF=1 MIN=0 MAX=-1 INC=0.001  /edit=f       
      gcontrol LVAL valTab.lval1 "LVAL1" DEF=1 MIN=0 MAX=-1 INC=0.001  /edit=f
      gcontrol TVAL valTab.tval1 "TVAL1" DEF=1 MIN=0 MAX=-1 INC=0.001  /edit=f

    !gcontrol label  otherLab ""
      gcontrol prompt valTab.prompt1 "PROMPT1          "    DEF=valTab.prompt1         /edit=f
      gcontrol button valTab.button1 "BUTTON1        " "B1,B2,Initial" valTab.button1  /edit=f /tleft 
      gcontrol menu   valTab.menu1   "MENU1          " "B1,B2,Initial" valTab.menu1    /edit=f  /tleft /nc=3
      gcontrol choice valTab.choice1 "CHOICE1        " "B1,B2,Initial" valTab.choice1  /edit=f  /input

    if interAct ISFALSE then message FUNC=SEND ID=MAIN NAME="ACTIONCHANGE"
  pipe off
endmacro

!**************************************************************************************************!
procedure processMessage m:msg

!say "^reg.main.name: msg ^msg.name INFO=^msg.info DATA=^msg.data QUALS=^msg.quals"
  if msg.name eqs "MAIN" or msg.name EQS "CLOSE" then
    assert/text="^reg.main.name: number valTab. msgs ^numValTabMsgs = ^expectedNumValTabMsgs expected?" &
                expectedNumValTabMsgs EQ numValTabMsgs
    pipe stop

  elseif msg.name eqs "ACTIONCHANGE" then
    if actionChangeClicked ISFALSE then
      set expected_quals -2   
      set expected_quals_string "CHANGED_BY_MSG"   
      res gc.valTab.dval1.action 1
      res gc.valTab.fval1.action 1
      res gc.valTab.lval1.action 1
      res gc.valTab.tval1.action 1
      set gc.valTab.prompt1.action "Action change"      
      res gc.valTab.button1.action "B1"
      !res gc.valTab.button2.action "B1"  !no button 2, so skipping
      res gc.valTab.menu1.action   "B1"
      res gc.valTab.choice1.action "B1"
      res z:actionChangeClicked true
      if interAct ISFALSE then message FUNC=SEND ID=MAIN NAME="CLOSE"
    else
      info "^reg.main.name: ACTIONCHANGE has already been clicked."
    endif

  elseif msg.name eqss "VALTAB."  then
    sedit "^msg.name" shortID "SUBS" "VALTAB." ""
    if numValTabMsgs NREXISTS then
      res L:numValTabMsgs 0
    endif
    calc L:numValTabMsgs numValTabMsgs+1
    set s:at msg.quals.actiontypestring  ! new msg.quals field

    if shortID eqs "DVAL1" or shortID eqs "LVAL1" or shortID eqs "FVAL1" or shortID eqs "TVAL1" then
      assert/text="^reg.main.name: ^shortID:  expected quals=^expected_quals_string, got quals=^at" expected_quals_string EQS ^at
      assert/text="^reg.main.name: ^shortID: action change value=^msg.data" msg.data EQ 1

    elseif shortID eqs "BUTTON1" or shortID eqs "BUTTON2" or shortID eqs "MENU1" or shortID eqs "CHOICE1" then
      assert/text="^reg.main.name: ^shortID:  expected quals=^expected_quals_string, got quals=^at" expected_quals_string EQS ^at
      assert/text="^reg.main.name: ^shortID: action change value=^msg.data" "^msg.data" EQS "B1"

    elseif shortID eqs "PROMPT1"  then
      assert/text="^reg.main.name: ^shortID:  expected quals=^expected_quals_string, got quals=^at" expected_quals_string EQS ^at
      assert/text="^reg.main.name: ^shortID: msg.data='^msg.data'" "^msg.data" EQS "Action Change"

    else
      assert/text="^reg.main.name: ^shortID - unexpected message ^msg" false
      message FUNC=SEND ID=MAIN NAME="CLOSE"
    endif

  else
    ! do nothing
    say "^reg.main.name: unhandled message ^msg"
  endif

return

