!------------------------------------------------------------------------------!
! 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

  if interAct OR coreGraphics then
    ! INPUT files used for tests
    fname infile1 area=test name=input_test_list_01 ext=tmp opt=sys
    fname infile2 area=test name=input_test_list_02 ext=tmp opt=sys

    pipe init
      panel/msgid=MAIN/id=panel/controls=gc
      list2/legacy/grid=on/msgid=MAIN/id=idlist
      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" "Initializing..." 24 5 /title
      gcontrol/nc=2 button nextlist "LegacyTest" &
              "ColSpacing,Templates" none
!      gcontrol/nc=3 button SCROLLEND "ScrollEnd" "ON,OFF" off

    pipe off

    ! Erase temporary files
    erase/quiet/warn=no temp_list_colspacing
    erase/quiet/warn=no temp_list_scrollend
    erase/quiet/warn=no temp_list_insert
  endif

endmacro

!------------------------------------------------------------------------------!
! Procedure for handling all messages
procedure processMessage m:msg
  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.name EQS "NEXTLIST" then
    if msg.data NEQS "POLL" then
      set reg.idlist.pollinterval 0 ! Turn off polling for all choices except POLL
    endif
    if msg.data EQS "COLSPACING" then
      call legacy_column_spacing
    elseif msg.data EQS "POLL" then
      call legacy_poll
    elseif msg.data EQS "TEMPLATES" then
      call legacy_templates
    elseif msg.data EQS "SCROLLEND" then
      call legacy_scrollEnd
    elseif msg.data EQS "INSERT" then
      call legacy_insertrows
    elseif msg.data EQS "COLOR" then
      call legacy_color
    else
      ! NONE
      call none
    endif
  elseif msg.name EQS "SCROLLEND" then
    if msg.data EQS "ON" then
      result tempState 1
    else
      result tempState 0
    endif
    set reg.idlist.scrollend ^tempState
    mess send idlist,,"OPENFILE" ,, temp_list_scrollend

  elseif msg.name EQS "MAIN" then
    assert/text="List tests" "PASS" SUBS msg.data
    pipe stop
  elseif msg.name EQS "SHOWN" then
    ! Do nothing
  
  else
    say "Unhandled messagename: ^msg.name from fid: ^msg.fid data: ^msg.data"
  endif


return

!------------------------------------------------------------------------------!
procedure none
  set reg.idlist.openFile ""
  set reg.panel.controls.idtext.value "List should be empty"
return

!------------------------------------------------------------------------------!
!   Test for polling and multiple selection in list
procedure legacy_poll
  mess send idlist,,"OPENFILE" ,, "^infile1"
  set reg.idlist.pollinterval 4
  set reg.panel.controls.idtext.value &
      "1. Holding down the shift key while clicking LEFT MOUSE &
       should let you select/unselect multiple cells.  &
       2. The list should refresh the file every 4 seconds."
  
return
!-----------------------------------------------------------------
!   Test list display of large window with evenly spaced columns"
procedure legacy_column_spacing
  waveform temp_list_colspacing sb 144 white 3
  headermod temp_list_colspacing format=sb type=2000 fs=12 size=12
  mess send idlist ,,"OPENFILE",,temp_list_colspacing  
  set reg.panel.controls.idtext.value &
      "You should see 12 rows in the list window, &
      with each column evenly spaced."
return

!-----------------------------------------------------------------
!   Test list template processing, allowing color by enum or field
!
!   This test is used to verify DR370-1 and DR5500-1.  Originally the
!   formatting for a template file would show up in the column where the 
!   data was initially, not where the template reordered it to be, plus you
!   couldn't specifiy COLOR by enum (MCOLORS) or by FIELD.
procedure legacy_templates
  mess send idlist,,"OPENFILE" ,, "^infile1"
  mess send idlist,,"OPENTEMPLATE" ,, "^infile2"
  set reg.panel.controls.idtext.value &
               "Data in column SR01 and SR04 should be in red text. &
                Data in column SR02: Each 'One' should be in red, &
                'Two' in yellow', Three' in green.  Data in column SR03 &
                should be in green text.  Column labels should be centered."
return

!-----------------------------------------------------------------
!   Test the SCROLLEND method when displaying lists
procedure legacy_scrollend
  waveform temp_list_scrollend sf 1k
  mess send idlist,,"OPENFILE" ,, temp_list_scrollend
  
  set reg.panel.controls.idtext.value &
      "Press the SCROLLEND button (below) to display the bottom or top of file"

return
!------------------------------------------------------------------------------
! Test ADDROW, SELECTROW methods
procedure legacy_insertrows
  noop infile1(0:10) temp_list_insert
  mess send idlist,,"OPENFILE" ,, temp_list_insert
  
  ! Build the table to add (SR01, SR02, ...)
  result t {SR01=111,SR02=222,SR03=333,SR04=444}
  set reg.panel.controls.idtext.value "Note how many rows are in the pane &
                                       initially. Click ADDROW to add an &
                                       entry to the bottom"
  gcontrol/wait BUTTON temp "ADDROW" "ADDROW,CANCEL" 1
  if temp EQS "CANCEL" return

  set reg.idlist.addrow t

  res L:rowNum 5
  set reg.panel.controls.idtext.value "This should add a row at the bottom of &
                                       the list. Click INSERTROW to INSERT an &
                                       entry at row ^rowNum"
  gcontrol/wait BUTTON temp "INSERTROW" "INSERTROW,CANCEL" 1
  if temp EQS "CANCEL" return
  set t.LIST__POS ^rowNum
  set reg.idlist.addrow t

  set reg.panel.controls.idtext.value "This should INSERT a row at row ^rowNum. &
                                       Click ADDROW to ADD an entry at the end"

  gcontrol/wait BUTTON temp "ADDROW" "ADDROW,CANCEL" 1
  if temp EQS "CANCEL" return
  set t.LIST__POS 0
  set reg.idlist.addrow t
  result selRow 10
  set reg.panel.controls.idtext.value "This should again add a row at the end. &
                                       Click SELECTROW to highlight row ^selRow"

  gcontrol/wait BUTTON temp "SELECTROW" "SELECTROW,CANCEL" 1
  if temp EQS "CANCEL" return

  set reg.idlist.selectrow ^selRow
  set reg.panel.controls.idtext.value "List should jump to the highlighted row"

return

!------------------------------------------------------------------------------!
procedure legacy_color
  mess send idlist,,"OPENFILE" ,, "^infile1"
  status infile1 size=fileSize
  set item 1
  gcontrol/wait CHOICE type "ROWORCOL" "ROW,COL" "ROW"
  gcontrol/wait LVAL item "^type number" 1 1 fileSize 1
  gcontrol/wait CHOICE Color "COLOR" "^reg.IDLIST.colorChoices" "RED"
  if type EQS "ROW" then
    set reg.IDLIST.setRowColors {ROW=^item,BG="^color"}
  else
    set reg.IDLIST.setColColors {COLUMN=^item,BG="^color"}
  endif
  set str "^type ^item should be ^color, or back to initial setting &
           if THEME is chosen"
  set reg.panel.controls.idtext.value "^str"
return
