!**************************************************************************************************!
! author : JPH
!
! purpose: test DVAL GCONTROLS
!**************************************************************************************************!
startmacro
  switch INTERACTIVE interAct GET DEF=TRUE SDEF=TRUE  ! for normal interactive test(s)

  set L:failedTests 0
  res expectedVal -1
  res myValue 0

  pipe on

    if interAct ISFALSE then
      panel/msgid=MAIN/headless/controls=gc
    else
      panel/msgid=MAIN/setup/controls=gc
    endif

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

    gcontrol label  BASICSLAB "Basics"
      set instructions "After a brief (3 sec) pause, the control panel will adjust &
                        to fit all the label groups on the panel. &
                        Enter embedded and trailing spaces as well as &
                        other invalid characters in the xVAL widgets &
                        popup to ensure exceptions do not occur. The macro control &
                        panel should not be flickering and resizing. Ignore the controls &
                        in all the 'Group <X>' sections."
      gcontrol TEXT instructBasics INSTRUCTIONS "^instructions" 24 4 /title
      gcontrol DVAL dval1 "Change and VAL2 and VAL3 should change via /MON (val=-1)" 1 0 100 1           /msg=yes
      gcontrol DVAL dval4 "Change and VAL2 and VAL3 should change via MSG  (val=-2)" 1 0 100 1           /msg=yes
      gcontrol DVAL dval2 "VAL2: NOT editable!" 1 0 100 1          /msg=false   /edit=false 
      gcontrol DVAL dval3 "VAL3: editable" 1 0 100 1               /msg=yes  /mon=val1Res /slider /msg=yes
      gcontrol DVAL dvalUnits "Units should display except when editing (right-click)" 1 0 100 1  /msg=no /fmt="##.# MHz"
      gcontrol DVAL "" "Click to change"

    gcontrol label  FormatMult "FMT and MULT Switches" "OPEN"
      set instructions "Change the DVAL 'NO /MULT', which should show units in GHz. &
                        All others should show units in MHz except the /FMT=DMS.  Select various digits &
                        in the DMS string to make sure they can be incremented and decremented."
      gcontrol TEXT instructMULT INSTRUCTIONS "^instructions" 24 3 /title
      set def 1.5e9
      set min 0
      set max 10e9
      set inc 1e6
      gcontrol DVAL valFormat         "DVAL - No /MULT"   DEF=def MIN=min MAX=max INC=inc /fmt="##.### ?Hz" /MSG=T
      gcontrol DVAL valFormatMult6    "DVAL - /MULT=6"    DEF=def MIN=min MAX=max INC=inc /fmt="##.### ?Hz" /MSG=F /MULT=6
      gcontrol DVAL valFormatMultM    "DVAL - /MULT=M"    DEF=def MIN=min MAX=max INC=inc /fmt="##.### ?Hz" /MSG=F /MULT=M
      gcontrol DVAL valFormatMultMega "DVAL - /MULT=Mega" DEF=def MIN=min MAX=max INC=inc /fmt="##.### ?Hz" /MSG=F /MULT=Mega

      gcontrol DVAL dvalFormatDMS     "DVAL - /FMT=DMS"   DEF=0   MIN=-180 MAX=180 INC=1 /fmt=DMS       /MSG=F /UNITS=DMS

      gcontrol label groupA "Group A" "CLOSED"
        gcontrol dval   grpADval "A DVAL:" 1 0 100 1           /msg=yes
        gcontrol prompt grpAprompt "A prompt:" "Prompt text"
        gcontrol button grpAButt   "" "A Button"
        gcontrol choice grpAChoice    "A Choice" "0,1,2,3,4" "3"
        gcontrol menu   grpAMenu "A Menu" "PASS,FAIL" /tleft

      gcontrol label groupB "Group B" "HIDDEN"
        gcontrol dval   grpBDval "A DVAL:" 1 0 100 1           /msg=yes
        gcontrol prompt grpBprompt "A prompt:" "Prompt text"
        gcontrol button grpBButt   "" "A Button"
        gcontrol choice grpBChoice    "A Choice" "0,1,2,3,4" "3"
        gcontrol menu   grpBMenu "A Menu" "PASS,FAIL" /tleft 

     gcontrol label groupC "Group C" "OPEN"
        gcontrol dval   grpCDval "A DVAL:" 1 0 100 1           /msg=yes
        gcontrol prompt grpCprompt "A prompt:" "Prompt text"
        gcontrol button grpCButt   "" "A Button"
        gcontrol choice grpCChoice    "A Choice" "0,1,2,3,4" "3"
        gcontrol menu   grpCMenu "A Menu" "PASS,FAIL" /tleft /nc=3

      gcontrol label groupD "Group D" "CLOSED"
        gcontrol dval   grpDDval "A DVAL:" 1 0 100 1           /msg=yes
        gcontrol prompt grpDprompt "A prompt:" "Prompt text"
        gcontrol button grpDButt   "" "A Button"
        gcontrol choice grpDChoice    "A Choice" "0,1,2,3,4" "3"
        gcontrol menu   grpDMenu "A Menu" "PASS,FAIL" /tleft 

        gcontrol label groupE "Group E" "OPEN"
        gcontrol dval   grpEDval "A DVAL:" 1 0 100 1           /msg=yes
        gcontrol prompt grpEprompt "A prompt:" "Prompt text"
        gcontrol button grpEButt   "" "A Button"
        gcontrol choice grpEChoice    "A Choice" "0,1,2,3,4" "3"
        gcontrol menu   grpEMenu "A Menu" "PASS,FAIL" /tleft /nc=3

      gcontrol label groupF "Group F" "CLOSED"
        gcontrol dval   grpFDval "A DVAL:" 1 0 100 1           /msg=yes
        gcontrol prompt grpFprompt "A prompt:" "Prompt text"
        gcontrol button grpFButt   "" "A Button"
        gcontrol choice grpFChoice    "A Choice" "0,1,2,3,4" "3"
        gcontrol menu   grpFMenu "A Menu" "PASS,FAIL" /tleft 

      gcontrol label groupG "Group G" "CLOSED"
        gcontrol dval   grpGDval "A DVAL:" 1 0 100 1           /msg=yes
        gcontrol prompt grpGprompt "A prompt:" "Prompt text"
        gcontrol button grpGButt   "" "A Button"
        gcontrol choice grpGChoice    "A Choice" "0,1,2,3,4" "3"
        gcontrol menu   grpGMenu "A Menu" "PASS,FAIL" /tleft

      gcontrol label groupH "Group H" "HIDDEN"
        gcontrol dval   grpHDval "A DVAL:" 1 0 100 1           /msg=yes
        gcontrol prompt grpHprompt "A prompt:" "Prompt text"
        gcontrol button grpHButt   "" "A Button"
        gcontrol choice grpHChoice    "A Choice" "0,1,2,3,4" "3"
        gcontrol menu   grpHMenu "A Menu" "PASS,FAIL" /tleft 

        gcontrol label groupI "Group I" "HIDDEN"
        gcontrol dval   grpIDval "A DVAL:" 1 0 100 1           /msg=yes
        gcontrol prompt grpIprompt "A prompt:" "Prompt text"
        gcontrol button grpIButt   "" "A Button"
        gcontrol choice grpIChoice    "A Choice" "0,1,2,3,4" "3"
        gcontrol menu   grpIMenu "A Menu" "PASS,FAIL" /tleft

      gcontrol label groupJ "Group J" "HIDDEN"
        gcontrol dval   grpJDval "A DVAL:" 1 0 100 1           /msg=yes
        gcontrol prompt grpJprompt "A prompt:" "Prompt text"
        gcontrol button grpJButt   "" "A Button"
        gcontrol choice grpJChoice    "A Choice" "0,1,2,3,4" "3"
        gcontrol menu   grpJMenu "A Menu" "PASS,FAIL" /tleft 

      gcontrol label groupK "Group K" "HIDDEN"
        gcontrol dval   grpKDval "A DVAL:" 1 0 100 1           /msg=yes
        gcontrol prompt grpKprompt "A prompt:" "Prompt text"
        gcontrol button grpKButt   "" "A Button"
        gcontrol choice grpKChoice    "A Choice" "0,1,2,3,4" "3"
        gcontrol menu   grpKMenu "A Menu" "PASS,FAIL" /tleft

      gcontrol label groupL "Group L" "HIDDEN"
        gcontrol dval   grpLDval "A DVAL:" 1 0 100 1           /msg=yes
        gcontrol prompt grpLprompt "A prompt:" "Prompt text"
        gcontrol button grpLButt   "" "A Button"
        gcontrol choice grpLChoice    "A Choice" "0,1,2,3,4" "3"
        gcontrol menu   grpLMenu "A Menu" "IF YOU SEE THIS,PRESS FAIL!!!!!!!!!!" /tleft 

    call hide_dvals

    pause 3   ! delay to notice if hidden widgets draw at the top of the panel (Bug 2217)

    set this.timer(0) 0.1   ! Timer to see if flickering occurs when updating hidden widgets
  pipe off

  %test_gcontrol_dval_rightjustified/interactive=^interAct

endmacro

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

!say "Got msg ^msg data=^msg.data"

  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 "DVAL1"  then
    invoke expectedVal nxm.sys.libg.GValue.changed_by_poll
    set val1Res ^msg.data
    set gc.dval2.value ^msg.data
    call update_dvals ^msg.data
  elseif msg.name eqs "DVAL4" then
    invoke expectedVal nxm.sys.libg.GValue.changed_by_msg
    set gc.dval2.action ^msg.data
    set gc.dval3.action ^msg.data
    call update_dvals ^msg.data
  elseif msg.name eqs "DVAL2"  then
    call failedATest "/MSG=FALSE did not work on ^msg.name widget"
  elseif msg.name eqs "DVAL3" then
    assert/text="DVAL3 Expected ^expectedVal got ^msg.quals.actiontype" ^expectedVal eq ^msg.quals.actiontype
    set expectedVal 0
  elseif msg.name eqss "VALFORMAT"  then
    foreach control INTAB gc
      if control EQSS "VALFORMATMULT" then
        set gc.^{control}.value ^msg.data
      endif
    endfor
  elseif msg.name eqs "TIMER" then
    calc myValue myValue 1 + 
    call update_dvals ^myValue
    if interAct ISFALSE then pipe stop
  else
    ! do nothing
    !say "^reg.main.name: 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

!**************************************************************************************************!
procedure hide_dvals 
  foreach dv intable gc
    if dv eqss "GRP" then
      if dv.indexof("DVAL") > 0 then
        set gc.^{dv}.show 0
      endif
    endif
  endfor
return
!**************************************************************************************************!
procedure update_dvals i:val
set reg.panel.holdLayout true
  foreach dv intable gc
    if dv eqss "GRP" then
      if dv.indexof("DVAL") then
        set gc.^{dv}.show 1
      endif
    endif
  endfor
  foreach dv intable gc
  if dv eqss "GRP" then
      if dv.indexof("DVAL") then
        set gc.^{dv}.value ^val
      endif
    endif
  endfor
  foreach dv intable gc
  if dv eqss "GRP" then
      if dv.indexof("DVAL") then
        set gc.^{dv}.show 0
      endif
    endif
  endfor
set reg.panel.holdLayout false
return
