! Tests the GCONTROL  widget /DISABLE switch
!
! Additional testing added for disabled items in a CHOICE for Bug 2892 and Bug 2963 in 3.7.0
!
! @author  jwb
!
startmacro

switch INTERACTIVE interAct GET DEF=TRUE
if interAct then

  set L:nChars 4
  set instr "1) Should see several Gcontrol widgets controls.\n&
             - Most of the widgets should be 'grayed out' and not respond to clicks.\n&
             - The BUTTON GROUP control should have the 'B' and 'C' buttons grayed &
             out and not selectable.\n&
             - The text box should not be grayed out at all.\n\n&
             2) Click the button that corresponds to the Widget type to toggle &
             enable/disable it.\n&
             -You should see a warning appear when you try to disable the text box.\n&
             -Use the Color buttons to change the color of disabled widgets.\n&
             -The behavior of the Choice widgets should be as described by their labels.\n\n&
             3) GControl CHOICE testing:\n&
             1. On CHOICE labeled 'Nothing Disabled....'\n   &
                LMB to bring up the choices (in the area showing the selection)\n   &
                - the default selection "f" should be blue\n   &
                - change the selection and the new selection should be blue\n     &
                  as well as show as selected when the CHOICE popup is closed\n&
             2. On CHOICE labeled 'Initally A, D, & G disabled...'\n   &
                LMB to bring up the choices\n   &
                - the selection should be blue, and a,d,& g should be gray\n   &
                - change the selection and the new selection should be blue,\n     &
                  unless you selected a disabled item\n   &
                Run through the tests shown on the buttons 'Disable B&H',...,\n   &
                'Enable I' and bring up the CHOICE popup to verify the proper\n   &
                items are disabled/enabled\n\n&
             "

  pipe on

    panel/msgid=MAIN/setup/controls=gc/logger

    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 "^instr" 48 24 /title

    gcontrol label  disLabel  "LABEL" table={enabled=false}
    gcontrol prompt disPrompt "PROMPT" "PROMPT TEXT" table={enabled=false}
    gcontrol button disButton "BUTTON GROUP (B & C DISABLED)" "A,B,C,D" "A"  table={disabledItems="B,C"} 
    gcontrol menu   disMenu   "MENU" "A,B,C" /tleft  table={enabled=false}
    gcontrol choice disChoice "CHOICE" "A,B,C" table={enabled=false} /tleft 
    gcontrol lval   disLval   "LVAL" DEF=1 MIN=0 MAX=100 INC=1 table={enabled=false} /slider 
    gcontrol dval   disDval   "DVAL" 1 0 100 1 table={enabled=false} 
    gcontrol text   disText   "TEXT" "TEXT" 1 1  /tleft 
    gcontrol line
    gcontrol button disButt "TOGGLE DISABLE" "LABEL,PROMPT,BUTTON,MENU,CHOICE,LVAL,DVAL,TEXT"  /nc=4
    gcontrol button disColor "DISABLED COLOR" "GRAY,RED,GREEN,BLUE,WHITE,AQUA" "GRAY"

    gcontrol line
    gcontrol label choiceLabel "Choice GControl"
    set choice_list "a,b,,,d,e,f,,g,h,i,j"
    set choice_def "f"
    gcontrol choice choice1 "Nothing Disabled. Default 'f'" "^choice_list" ^choice_def /NC=3

    ! Since 3.7.0 - add button to make testing more automated
    gcontrol button disChoice2 "Update Disabled Items in a Choice" "Disable A&D&G,Disable B&H,Disable I&J,Enable I " "Disable A&D&G"
    gcontrol choice choice2 "Initially A,D & G disabled. Default 'f'" "^choice_list" ^choice_def TABLE={DISABLEDITEMS="A,D,G"} /NC=3

  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 "DISBUTT" then
	  invoke ,, gc.dis^{msg.data}.toggleEnabled()
	  
	elseif msg.name eqs "DISCOLOR" then
	  set gc.disLabel.disabledColor msg.data
	  set gc.disPrompt.disabledColor msg.data
	  set gc.disButton.disabledColor msg.data
	  set gc.disMenu.disabledColor msg.data
	  set gc.disChoice.disabledColor msg.data
	  set gc.disLval.disabledColor msg.data
	  set gc.disDval.disabledColor msg.data
	  
	elseif msg.name eqs "CHOICE2" then
      if msg.data eqs "A" OR msg.data eqs "D" OR msg.data eqs "G" then
	    assert/text="^reg.main.name: Disabled item sent message" false
	  endif

    ! Since 3.7.0 - add button to make testing more automated
	elseif msg.name eqs "DISCHOICE2" then
	  if msg.data eqs "Disable A&D&G"
	    res gc.choice2.disabledItems "a,d,g"
	  elseif msg.data eqs "Disable B&H"
	    res gc.choice2.disabledItems "b,h"
	  elseif msg.data eqs "Disable I&J"
	    res gc.choice2.disabledItems "i,j"
	  elseif msg.data eqs "Enable I "
	    res gc.choice2.enableItem "i"
	  endif
	
	else
	  ! do nothing
	  !say "Unhandled message name: ^msg.name from fid: ^msg.fid data: ^msg.data"
	endif

return

