!------------------------------------------------------------------------------!
! Tests for LIST2 command.
!
!   Author : J. Czechowski IV
!------------------------------------------------------------------------------!
startmacro/tsetup=nxm.sys.test.test_list2_setup.tbl
  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
    invoke buttonActionList nxm.sys.prim.list2.buttonActionList
    set t:ButtonActionDescr {None="do nothing",Menu="toggle graphical menu",&
                             Message="send a message to the macro that is displayed &
                             below. MsgName should be the button name (MMB,RMB), MsgInfo &
                             is always 0, and MsgData should be a table containing the number &
                             of the ROW and COL selected (-1 if invalid).",&
                             ClearSelection="clear any rows/cells selected"}
    
    set instructions "Try out the different functions for the mouse buttons."

    pipe init
      panel/msgid=MAIN/id=panel/controls=gc
      list2/grid=on/msgid=MAIN/id=idlist ^{datDir}.testxy3000.prm {_GLOBAL_={FGCOLOR="yellow"}}

      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" "^{instructions}" 24 12 /title
      gcontrol label  listTest   "Options" AlwaysOpen
      gcontrol choice mmb       "MMB:    " "^{buttonActionList}" "^{reg.idlist.buttonAction.mmb}"
      gcontrol choice rmb       "RMB:    " "^{buttonActionList}" "^{reg.idlist.buttonAction.rmb}"
      gcontrol prompt msgName   "Msg Name:" "<no messages>" /tleft /edit=f
      gcontrol prompt msgInfo   "Msg Info:" "<no messages>" /tleft /edit=f
      gcontrol prompt msgData   "Msg Data:" "<no messages>" /tleft /edit=f

    pipe off
  endif
endmacro

!------------------------------------------------------------------------------!
procedure processMessage m:msg
!
! Procedure for handling all messages
!
  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
    set gc.msgName.value "^msg.name"
    set gc.msgInfo.value "^msg.info"
    set gc.msgData.value "^msg.data"
  
  elseif msg.name EQS "MMB" then
    set gc.msgName.value "<no messages>"
    set gc.msgInfo.value "<no messages>"
    set gc.msgData.value "<no messages>"
    set reg.idlist.buttonAction {MMB=^{msg.data}}
    set gc.idtext.value "The MMB button should now ^{ButtonActionDescr.^{msg.data}}."

  elseif msg.name EQS "RMB" then
    set gc.msgName.value "<no messages>"
    set gc.msgInfo.value "<no messages>"
    set gc.msgData.value "<no messages>"
    set reg.idlist.buttonAction {RMB=^{msg.data}}
    set gc.idtext.value "The RMB button should now ^{ButtonActionDescr.^{msg.data}}."

  else
    say "Unhandled messagename: ^msg.name from fid: ^msg.fid data: ^msg.data"
  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
