!******************************************************************************!
! Test adjusting a widget based on clicking a list2
!
! Arguments: None
!
! Note1: Much of the logic and flow in this macro is designed to mimic user's scenario
!
! @bug      2508 LIST2: clicks on list no longer can populate widgets since 2.9.3 (REGRESSION)
! @author:  J Bauer
! @version: $Id: test_list2_click_msg.mm,v 1.1 2011/11/14 21:56:09 jwb Exp $
!******************************************************************************!
startmacro
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE  ! for normal interactive test(s)
  switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE  ! for defects or more obscure test case(s)

  if interAct then
    set instructions "Click on a row in the LIST to change the value of the GWidgets"

    res mystate {}
    res mystate.tuner "TUNER1"
    
    call createArchiveTemplate

    pipe on
      panel/msgid=MAIN/setup/controls=gc
      gcontrol label macro "Test MACRO"
      gcontrol menu  main "Exit with Status =" "PASS,FAIL" TABLE={ItemColors={PASS="GREEN",FAIL="RED"}} /tleft

      gcontrol text  idtext "Instructions" instructions 24 8 /title
      
      list2/msgid=main/id=myList/legacy/prevandcurr=true  template=archTempl autoselect=true &
                                              clickaction={CELL=ROW} 

      !control/input/mon=mystate.tuner choice myChoice "CHOICE" "TUNER1,TUNER2 "" 
      gcontrol CHOICE tuner      "Tuner"      "TUNER1,TUNER2" "TUNER1" /input /mon=mystate.tuner
      
      !gcontrol button myButt "" "POP ROWS" ""
      
      message FUNC=send ID=MAIN NAME=START
      
    pipe off

  endif
endmacro

!******************************************************************************!
! Main process message for this macro. Should be right after the ENDMACRO.
procedure processMessage m:msg
  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name: User indicated tests" msg.data eqss "PASS"
    pipe stop
   
  elseif msg.name eqs "MYBUTT" then
    call popRows

  elseif msg.fid eqs "MYLIST" then
    !info "Msg= ^msg DATA= ^msg.data"
    call processSelect
    
  elseif msg.name eqs "START" then
    call popRows
    
  else
    !say "Unhandled message name: ^msg.name from fid: ^msg.fid data: ^msg.data"
  endif
return

!******************************************************************************!
! If an unexpected exception is caught, mark test as failed
!******************************************************************************!
procedure processException m:emsg
  assert/text="^reg.main.name: Caught unexpected exception ^{emsg.data}" "FALSE" isTrue
  if "Trace" SUBS ENV.DEBUG invoke ,, emsg.data.printStackTrace()
return

!**************************************************************************************************!
! Intial template used in the List2
procedure createArchiveTemplate
  res archTempl {}
  res archTempl._GLOBAL_ {AUTOHIDE=OFF,BGCOLOR=FIELD_INWB,COLORMAP=WHITE,GREEN,YELLOW}
!!!  res archTempl.VRF      {LABEL="WB Freq",WIDTH=8}
  res archTempl.TUNER    {LABEL="Tuner",WIDTH=8}
  res archTempl.START    {LABEL="Start"}
  res archTempl.END      {LABEL="End"}
  res archTempl.DUR      {LABEL="Dur (s)",WIDTH=8}
  res archTempl.SBT      {LABEL="Freq (MHz)",WIDTH=10}
  res archTempl.BW       {LABEL="Bw (Hz)",WIDTH=10}
  res enumTab {E1={LABEL="YES",VALUE="1",COLOR="GREEN"},E2={LABEL="NO",VALUE="0",COLOR="RED"},E3={LABEL="PARTIAL",VALUE="2",COLOR="BLUE"}}
  res archTempl.INWB     {LABEL="In WB?",WIDTH=8,TYPE="ENUM",ENUM=^enumTab}
  res archTempl.FEATNAME {LABEL="Feature Name",WIDTH=16}
return

!**************************************************************************************************!
!! Initial populating of List2
procedure popRows
  res row {}
  res row.tuner "TUNER1"
  res row.start "START1"
  res row.end "END1"
  res row.dur "DUR1"
  res row.sbt "SBT1"
  res row.bw  "BW1"
  res row.featname "FEATNAME1"
  
  invoke ,, reg.mylist.addRow(row)

  res row2 {}
  res row2.tuner "TUNER2"
  res row2.start "START2"
  res row2.end "END2"
  res row2.dur "DUR2"
  res row2.sbt "SBT2"
  res row2.bw  "BW2"
  res row2.featname "FEATNAME2"
  
  invoke ,, reg.mylist.addRow(row2)

return

!**************************************************************************************************!
procedure processSelect
  foreach key intable msg.data.currsel
    info "setting tuner to  ^msg.data.currsel.^{key}.tuner"
    res mystate.tuner "^msg.data.currsel.^{key}.tuner"
  endfor

return