!******************************************************************************!
! Test selecting row by value after sorting
!
! Arguments: None
!
! @bug      2467: LIST2: Row selection by value is WRONG if the table is sorted
! @author:  J Bauer 
!******************************************************************************!
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)

  call setDatDir

  if interAct then
    set instructions "Click on the button to select rows. Sort the table, then &
                      click on the button again."

    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/id=idlist/msgid=main ^{datDir}.testxy3000.prm
      
      gcontrol/nc=1 button test "Click Buttons in Order" "SelectRows_ABSC=1,SortRows,SelectRows_ABSC=3,Clear"
    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 "SELROWS" then
    invoke ,, reg.idlist.selectRow("ABSC","1.0",true)
    
  elseif msg.name eqs "SORTROWS" then
    invoke ,, reg.idlist.setSort("ORD")
  
  elseif msg.name eqs "TEST" then 
    if msg.data eqs "SELECTROWS_ABSC=1" then
      invoke ,, reg.idlist.selectRowByColVal("ABSC","1.0","-MSG|-CLEAR|+IGNORECASE")  ! new method
      set gc.idtext.value "You should see two rows selected, both with ABSC=1.0"
    elseif msg.data eqs "SELECTROWS_ABSC=3" then
      invoke ,, reg.idlist.selectRow("ABSC","3.0",true)   ! old method
      set gc.idtext.value "You should see two rows selected, both with ABSC=3.0"
    elseif msg.data eqs "SORTROWS" then
      invoke ,, reg.idlist.setSort("ORD")
      set gc.idtext.value "The list should be sorted by the ORD column (selections disappear)."
    elseif msg.data eqs "CLEAR" then
      invoke ,, reg.idlist.clearSelection()
      set gc.idtext.value "Any selections should be de-selected."
    endif
  
  else
    !say "Unhandled message name: ^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
