! 
! purpose: 
!   1. Bug 1580 - Test for flicker when setting flags in GWidget
!   2. Bug 1617 - Check that VBOX is drawn when called programmatically
!   3. Bug 1580 - Assert that GWidget.getFlag is working properly
!
! author: J. Bauer

startmacro

switch INTERACTIVE  interAct     GET DEF=TRUE  SDEF=TRUE  ! for normal interactive test(s)
switch COREGRAPHICS coreGraphics GET DEF=FALSE SDEF=TRUE  ! for a quick check of graphics - more extreme tests - since 3.8.1

if interAct or coreGraphics then

  pipe on
    set instructions "Click each button below and observe behaviour. &
                      Should not be able to edit when using NOEDIT. &
                      The gcontrols should not flicker when set to NOEDIT, &
                      but may when set to VBOX. VBOX should appear when set &
                      when NOEDIT is not on."
    
    panel/msgid=MAIN/setup/controls=gc/options=-CompressControls

    gcontrol/tleft  menu MAIN   "Exit with Status = " "PASS,FAIL" table={ITEMCOLORS={PASS=GREEN,FAIL=RED}}

    gcontrol text idtext  "Instructions" "^instructions" 50 2 /title
    
    gcontrol button  BUTTON1  ""       "SET +VBOX USING (+/-)String SetFlags"
    gcontrol button  BUTTON4  ""       "SET -VBOX USING (+/-)String SetFlags"
    gcontrol button  BUTTON5  ""       "SET VBOX USING INT SetFlag"
    gcontrol button  BUTTON6  ""       "UNSET VBOX USING INT SetFlag"
    gcontrol button  BUTTON2  ""       "SET +NOEDIT USING (+/-)String SetFlags"
    gcontrol button  BUTTON3  ""       "SET -NOEDIT USING (+/-)String SetFlags"  
    gcontrol button  BUTTON7  ""       "SET NOEDIT USING INT SetFlag"
    gcontrol button  BUTTON8  ""       "UNSET NOEDIT USING INT SetFlag"
    
    ! Create the 50 prompts which will get modified using the buttons
    do count 1 50 1
      gcontrol prompt  prompt^{count} "Prompt^{count}"  "Text^{count}"
    enddo
  pipe off

endif

endmacro

procedure processMessage m:msg
!say "Got message name=^msg.name info=^msg.info data=^msg.data fid=^msg.fid"
  ! Variables for mask values
  set l:vbox   64
  set l:noedit 8
  
  if msg.name EQS "MAIN" then
    assert/text="^reg.main.name: Menu Table" "PASS" SUBS msg.data
    pipe stop
  elseif msg.name eqs "BUTTON1" then
    call set_prompt "+VBOX"
    call check_getFlag
  elseif msg.name eqs "BUTTON2" then
   call set_prompt "+NOEDIT"
  elseif msg.name eqs "BUTTON3" then
    call set_prompt "-NOEDIT"
  elseif msg.name eqs "BUTTON4" then
    call set_prompt "-VBOX"
  elseif msg.name eqs "BUTTON5" then
    call invoke_prompt vbox true
  elseif msg.name eqs "BUTTON6" then
    call invoke_prompt vbox false
  elseif msg.name eqs "BUTTON7" then
    call invoke_prompt noedit true
  elseif msg.name eqs "BUTTON8" then
    call invoke_prompt noedit false
  else
    !say "^reg.main.name: Unhandled message name=^msg.name info=^msg.info data=^msg.data"
  endif

return

!-----------------------------------------------------------------------------
!
!  Set the flag on each prompt using the GWidget.setFlags method
!
procedure set_prompt s:value
  do count 1 50 1
      set gc.prompt^{count}.flags "^{value}"
  enddo

return

!-----------------------------------------------------------------------------
!
!  Set the flag on each prompt using the GWidget.setFlag method
!
procedure invoke_prompt s:value s:bool
  do count 1 50 1
    invoke ,, gc.prompt^{count}.flag(^{value}, ^{bool})
  enddo

return

!------------------------------------------------------------------------------
!
!  Use assert to check that GWidget.getFlag returns the proper value
!
procedure check_getFlag
  set l:vbox 64
  set l:noedit 8
  invoke xx gc.prompt1.getFlag(vbox)
  assert/text="Checking getFlag=VBOX" xx eqs true
  invoke yy gc.prompt1.getFlag(noedit)
  assert/text="Checking getFlag=NOEDIT" yy eqs false

return
