!**************************************************************************************************!
! Tests for the MENU type of GCONTROL
!
! @author  Unknown, J. Czechowski IV
!**************************************************************************************************!
startmacro
  switch INTERACTIVE  interAct     GET DEF=TRUE
  switch COREGRAPHICS coreGraphics GET DEF=FALSE SDEF=TRUE ! for a quick check of graphics - more extreme tests - since 3.8.1

  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}
    gcontrol/title TEXT instructions INSTRUCTIONS &
           "Mask String, Value and True/False states should match settings on display. The first &
            menu should show 31 options (A to Z, 0 to 4). The other menus should have three options &
            each (A,B,C)." 48 4

    info "^reg.main.name: Should see a warning indicating 'TOGGLE list has max length of 31...'"
    res longList "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,0,1,2,3,4,5,6,7,8,9" ! 36 entries
    gcontrol/nc=8/chkbox/toggle/tleft MENU menuTooLong    "MENU limited to 32 entries   - Mask     = A|4" "^longList" "A|4" /togglelist
    gcontrol/nc=3/chkbox/toggle/tleft MENU menuToggle     "MENU with /TOGGLE            - Mask     = A|C" "A,B,C"     "A|C" 
    gcontrol/nc=3/chkbox/toggle/tleft MENU menuToggleInt  "MENU with /TOGGLE            - Int Mask = 5  " "A,B,C"       5
    gcontrol/nc=3/chkbox/toggle/tleft MENU menuToggleList "MENU with /TOGGLE/TOGGLELIST - Int Mask = 5  " "A,B,C"       5   /togglelist

    assert/text="^reg.main.name: Initial value for GC.MENUTOOLONG.VALUE=|A|4|" GC.MENUTOOLONG.VALUE eqs "|A|4|"
    call checkMenuInit "MENUTOGGLE"
    call checkMenuInit "MENUTOGGLEINT"
    call checkMenuInit "MENUTOGGLELIST"

    gcontrol LABEL idlabel "MESSAGE AND GCONTROL VALUES" AlwaysOpen
    gcontrol TEXT  idtext1 "" "MESSAGE:  <waiting for entry>" 48 2
    gcontrol TEXT  idtext2 "" "GCONTROL: <waiting for entry>" 48 2

    message FUNC=send ID=MAIN NAME=START
  pipe off
endmacro

procedure processMessage m:msg
  if msg.name eqs "START" then
    if interAct ISFALSE and coreGraphics ISFALSE then pipe stop
  elseif msg.name eqs "MAIN"
    assert/text="^reg.main.name: user indicated" msg.data eqs "PASS"
    pipe stop
  elseif msg.name eqss "MENUTOOLONG"  then
    set s:value  gc.^{msg.name}.value()
    set gc.idtext1.value "MESSAGE:  NAME=^{msg.name} INFO=^{msg.info} DATA=^{msg.data}"
    set gc.idtext2.value "GCONTROL: VALUE=^{value}"
    assert/text="^reg.main.name: MSG.DATA matches GC.^{msg.name}.VALUE" msg.data eqs value
    
  elseif msg.name eqss "MENU"  then
    set s:value  gc.^{msg.name}.value()
    set z:isSetA gc.^{msg.name}.isSet("A")
    set z:isSetB gc.^{msg.name}.isSet("B")
    set z:isSetC gc.^{msg.name}.isSet("C")
    set gc.idtext1.value "MESSAGE:  NAME=^{msg.name} INFO=^{msg.info} DATA=^{msg.data}"
    set gc.idtext2.value "GCONTROL: VALUE=^{value} A=^{isSetA} B=^{isSetB} C=^{isSetC}"

    set expMask "|"
    set expInfo 0
    if isSetA isTrue then
      set  expMask "^{expMask}A|"
      calc expInfo expInfo 1 +
    endif
    if isSetB isTrue then
      set  expMask "^{expMask}B|"
      calc expInfo expInfo 2 +
    endif
    if isSetC isTrue then
      set  expMask "^{expMask}C|"
      calc expInfo expInfo 4 +
    endif

    assert/text="^reg.main.name: MSG.INFO indicates mask value"             msg.info eq  expInfo
    assert/text="^reg.main.name: GC.^{msg.name}.VALUE indicates mask value" value    eqs expMask
    
    if msg.name eqs "MENUTOGGLELIST" then
      assert/text="^reg.main.name: MSG.DATA indicates mask value" msg.data eqs expMask
    else
      assert/text="^reg.main.name: MSG.DATA indicates value clicked" "/^{msg.data}/" subs "/A/B/C/"
    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

! Checks initial settings of the menu
procedure checkMenuInit s:name
  set s:value  gc.^{name}.value()
  set z:isSetA gc.^{name}.isSet("A")
  set z:isSetB gc.^{name}.isSet("B")
  set z:isSetC gc.^{name}.isSet("C")
  
  assert/text="^reg.main.name: Initial value for ^{name} VALUE=|A|C|" value eqs "|A|C|"
  assert/text="^reg.main.name: Initial value for ^{name} A=true"      isSetA isTrue
  assert/text="^reg.main.name: Initial value for ^{name} B=false"     isSetB isFalse
  assert/text="^reg.main.name: Initial value for ^{name} C=true"      isSetC isTrue
return
