!------------------------------------------------------------------------------!
! Tests for LIST2 command.
!
!   Author : J. Czechowski IV / J Bauer
!------------------------------------------------------------------------------!
startmacro 
  !! JWB - now uses a .mmp, not "/tsetup=nxm.sys.test.test_list2_setup_split.tbl" 
  !! JWB - Delete in future release if not used  s:autoSelect[false]
  switch dolegacy     dolegacy     GET DEF=TRUE SDEF=TRUE 
  switch INTERACTIVE  interAct     GET DEF=TRUE
  switch standalone   standalone   GET DEF=TRUE
  switch COREGRAPHICS coregraphics GET DEF=FALSE SDEF=TRUE  ! for a quick check of graphics - more extreme tests - since 3.8.1

  call setDatDir

  if interAct OR coreGraphics then
    set instr "Top two grids have AUTOSELECT=TRUE. \n&
               The bottom two have AUTOSELECT=FALSE. \n&
               Clicking on a cell/row in the top two should &
               select it; doing the same in the bottom two should do nothing. \n&
               The left two grids have the /LEGACY switch. The right two grids &
               do not. \nClicking on a cell/row in ANY LIST sends a message.\n&
               Use the buttons to &
               programmatically change the selection (should alter both top &
               and bottom sets).\n&
               Finally, click on a row number in one of the top two plots to select a row. Hit ENTER. &
               There should not be a stack trace"

    set fname ^{datDir}.testxy3000.prm
    set templ {_GLOBAL_={SORTENABLED=F}}

    pipe init
      panel/setup/msgid=MAIN/id=panel/controls=gc
      list2/grid=on/msgid=MAIN/id=idlist/legacy=^dolegacy    fname templ autoselect=true
      list2/grid=on/msgid=MAIN/id=idlegacy/legacy=^dolegacy  fname templ AUTOSELECT=false 
      list2/grid=on/msgid=MAIN/id=idlist2                    fname templ autoselect=true
      list2/grid=on/msgid=MAIN/id=idlegacy2                  fname templ AUTOSELECT=false
      if standalone isTrue then
        gcontrol label  macro   "MACRO"
        gcontrol menu MAIN "Exit with Status = " "PASS,FAIL" /tleft
        set gc.MAIN.itemColors {PASS=GREEN,FAIL=RED}
      endif

      gcontrol text idtext "Instructions" "^{instr}" 24 17 /title
      gcontrol/nc=2 button test "ListTest" &
              "SelectOnlyRow1,SelectOnlyRow5,AddSelectionRow5,ClearSelection" none

      gcontrol text idtext2 "Message Sent by LIST2" "" 14 1 /title
    pipe off

  endif
endmacro

!------------------------------------------------------------------------------!
procedure processMessage m:msg
!say "Got Msg. Name = ^{msg.name}, data = ^{msg.data}, from= ^{msg.fid}"
  res S:msgString "^{msg.name}"
  sedit msgString subString "BETWEEN" ^msgString.length-1 ^msgString.length-6
  
  if msg.name EQS "MAIN" then
    if msg.data EQS "EXIT" then
      pipe stop
    else
      assert/text="LIST2 tests" "PASS" SUBS msg.data
      pipe stop
    endif
  elseif msg.fid EQS "IDLIST" then
    !say "Got ^msg.name from ^msg.fid"

  elseif msg.fid EQS "IDLEGACY" then
    !say "Got ^msg.name from ^msg.fid"
  
  elseif msg.name EQS "TEST" then
    if msg.data EQS "SELECTONLYROW1" then
      invoke xxx reg.idlist.selectRow(1)
      invoke xxx reg.idlegacy.selectRow(1)
      invoke xxx reg.idlist2.selectRow(1)
      invoke xxx reg.idlegacy2.selectRow(1)
    elseif msg.data EQS "SELECTONLYROW5" then
      invoke xxx reg.idlist.selectRow(5,true)
      invoke xxx reg.idlegacy.selectRow(5,"MSG|CLEAR")
      invoke xxx reg.idlist2.selectRow(5,true)
      invoke xxx reg.idlegacy2.selectRow(5,true)
    elseif msg.data EQS "ADDSELECTIONROW5" then
      invoke xxx reg.idlist.selectRow(5,false)
      invoke xxx reg.idlegacy.selectRow(5,"MSG")
      invoke xxx reg.idlist2.selectRow(5,false)
      invoke xxx reg.idlegacy2.selectRow(5,false)
    elseif msg.data EQS "CLEARSELECTION" then
      invoke xxx reg.idlist.clearSelection()
      invoke xxx reg.idlegacy.clearSelection()
      invoke xxx reg.idlist2.clearSelection()
      invoke xxx reg.idlegacy2.clearSelection()
    endif

  elseif str eqs "SELECT" then
    !say "Got SELECT!" 

  else
    !say "Unhandled messagename: ^msg.name from fid: ^msg.fid data: ^msg.data"
  endif

  if subString eqs "SELECT" then 
    set gc.idtext2.value "Got message! Msg: ^{msg.name}"
    pause .25
    set gc.idtext2.value ""
  else
    set gc.idtext2.value ""
  endif
return

!******************************************************************************!
! Set the dat directory
!******************************************************************************!
procedure setDatDir
  invoke nxmMajor env.nmversion.subString(0,1)
  invoke major java.lang.Integer.valueOf(nxmMajor)
  if major GE 4 then
    invoke s:datDir           nxm.sys.test.DatLocator.getDatDirLocation()
    invoke s:datDirSlash      nxm.sys.test.DatLocator.getDatDirSlashLocation()
    invoke z:sysDatFull       nxm.sys.test.DatLocator.sysDatFull()
    invoke z:sysTestDatExists nxm.sys.test.DatLocator.sysTestDatExists()
  else
    set s:datDir           "nxm.sys.dat"
    set s:datDirSlash      "nxm/sys/dat"
    set z:sysDatFull       true
    set z:sysTestDatExists false
  endif
return
