! author : R. Hernandez /  J. Hallam
!
! purpose: test /MON switch support to PROMPT type GCONTROLS

startmacro

set L:failedTests 0
switch INTERACTIVE interAct GET DEF=TRUE
if interAct then

  pipe on
    if /inputborder EQS "MO" then
      set instructions "GControl /inputborder=mo test: This macro was run with the /inputborder=mo switch. &
                        As you mouse over each of the controls, you should see &
                        a hairline border over any control which can be right-clicked &
                        to bring up a text entry field."
    elseif /inputborder EQS "PERM" then
      set instructions "GControl /inputborder=PERM test: This macro was run with the /inputborder=perm switch. &
                        You should see a hairline border over any control which can be right-clicked &
                        to bring up a text entry field."
    endif
    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}
    gcontrol text idtext  "Instructions" "^instructions" 80 4 /title

    gcontrol label TESTS "TESTS"
    gcontrol MENU testnew "Press here to Test Dialog Pop-Up" "DIALOG" /tleft
    gc button state "Should default to NO button pressed" "One,Two,Three" ""
    gcontrol/CS CHOICE choice "Change and PROMPT should change (case preserved)" &
                              "UPPERCASE,MixedCase","UPPERCASE"
    set gc.CHOICE.itemcolors {uppercase=orange,mixedcase=red}
    gcontrol/mon=monStr/msg=f/edit=f prompt PROMPT "PROMPT : NOT editable!" "___"

  !!!jph -- TBD, limit width and echo character for PASSWORDS
    gcontrol prompt shortPrompt "Enter string and watch PROMPT change" "Defa" 4

    gcontrol/msg=y       DVAL val1 "Change and VAL2 should change" 1 0 100 1
    gcontrol/mon=val1Res/msg=f/edit=f dval val2 "VAL2: NOT editable!" 1 0 100 1
    gcontrol/msg=y       DVAL valFormat "Units shown only when NOT selected" &
                                         1 0 100 1 /fmt="##.# MHz"
    gcontrol/msg=y       LVAL lval "Change and select LVAL" &
                                   1 0 100 1 /fmt="## MHz"
    gcontrol/msg=y       TVAL tval "Change and select TVAL" 1 0 86400 1

    assert/text="^reg.main.name: item count" gc.main.itemCount EQ 2

  pipe off

endif

endmacro

procedure processMessage m:msg

if msg.name eqs "MAIN"
  if failedTests EQ 0 then
    assert/text="^reg.main.name: user indicated" msg.data eqs "PASS"
  else
    assert/text="^reg.main.name: detected ^failedTests failures" "FAIL"
  endif
  pipe stop
elseif msg.name eqs "CHOICE" or msg.name EQS "SHORTPROMPT" then
  set monStr "^msg.data"
elseif msg.name eqs "VAL1"  then
  set val1Res ^msg.data
elseif msg.name eqs "VAL2"  then
  call failedATest "/MSG=FALSE did not work on ^msg.name widget"
elseif msg.name eqs "VALFORMAT"  then
elseif msg.name eqs "LVAL"  then
elseif msg.name eqs "STATE"  then
  info "Expected a message from ^msg.name data: ^msg.data"
elseif msg.name eqs "TVAL"  then

elseif msg.name eqss "TEST"  then
  gcontrol/temp/msg=t/handle="DLOG" DIALOG dialog "Dialog Box" 300 3 "Add,Apply,Close" "Add,Apply"
  res dlw reg.DLOG.widgets
  res choices "ITEM1,ITEM2,ITEM3,ITEM4,ITEM5,ITEM6"
  gcontrol/panel=dlog/msg=true choice dialogChild_msg "Choice Message  " choices ""
  gcontrol/panel=dlog choice dialogChild_nomsg "Choice No Message  " choices ""
  gcontrol/panel=dlog text   text  "TextInfo" "Changing Choice should send message" 30 3
  assert/text="DIALOG widget table creation" dlw.TEXT.title EQS "TextInfo"
elseif msg.name eqs "DIALOG"  then
  ! Message(s) from dialog button press

elseif msg.name eqss "DIALOGCHILD"  then
  if msg.name eqs "DIALOGCHILD_NOMSG" then
    call failedATest "Did NOT expect a message from ^msg.name"
  else
    info "Expected a message from ^msg.name"
  endif
elseif msg.name eqs "SHOWN" then
  !Ignore
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

