! Tests the MULTIPLOT command
!
! @author  Jay Hallam
!
startmacro 
  invoke vscrollList nxm.ucl.prim.multiplot.vscrollList

  set numFiles 4
  set numCols 4
  set colors "GREEN,RED,BLUE,CYAN,ORANGE"
  set xmin FILE(fftdemo).xstart
  calc xExtent FILE(fftdemo).xdelta FILE(fftdemo).size *
  do i 1 numFiles
    thin fftdemo test_multiplot_^i
    calc xs xExtent i 1 - * xmin +
    calc xmax xs xExtent +
    headermod test_multiplot_^i xstart=xs
    if /debugm then stat test_multiplot_^i
  enddo
  if /verbose then
    info "^reg.main.name: xmin ^xmin, xmax ^xmax"
  endif
  switch INTERACTIVE interAct GET DEF=TRUE

  set files ""         ! This is the file list for MULTIPLOT
  do i numFiles 1 -1
    sedit/onebase "^colors" color "ELEM" i ","
    set str "test_multiplot_^{i}{TAG=T^{i}}"
    if files EQS ""
      set files "^str"
    else
      set files "^{files}|^{str}"
    endif
  enddo  
 
  if /verbose then
    info "^reg.main.name: Files to plot ^files"
    info "^reg.main.name: xmin ^xmin, xmax ^xmax"
  endif

  if interAct then
    pipe init
      panel/setup/controls=gc
      gcontrol menu   main         "Exit with Status = "   "PASS,FAIL" /tleft
      set gc.MAIN.itemColors {PASS=GREEN,FAIL=RED}
      plot "^files"
      set switches "/MSGID=MAIN"
      multiplot/id=mplot/IDPREFIX="MP_P_"/title="^numCols"/xmin=xmin/xmax=xmax/gridby=XS &
           files="^{files}" cols=numCols switches="^switches"

      set instructions "Should see 4 plots in a scrollable pane. Plots should form &
                        a staircase from left to right, bottom to top."

      do i 1 numFiles
        set L:offset i-1
        calc L:iColor numFiles i - 1 +
        sedit/onebase "^colors" color "ELEM" iColor ","
        !info "Setting MP_P_^{offset} to color ^color"
        set reg.mp_p_^{offset}.layer.color "^color"
        set reg.mp_p_^{offset}.layer.name "T1"
      enddo

      gcontrol label  MACRO "MULITPLOT TESTS"
        gcontrol text   idtext       "Instructions - Window 1" "^instructions" 24 7 /title
        gcontrol button addplot      "" "AddPlot" ""
        gcontrol button scrollsticky "Auto ScrollEnd Sticky" "^vscrollList"
        gcontrol button vscroll      "Scroll To"             "^vscrollList"
        

    pipe wait
    pipe off
  endif

  !BUG1744
  do i 1 numFiles
    erase test_multiplot_^i
  enddo 

endmacro

procedure processMessage m:msg
  if msg.name eqs "MAIN"
    assert/text="^reg.main.name: user indicated" msg.data eqs "PASS"
    pipe stop

  elseif msg.name eqs "ADDPLOT"
    mess send mplot ,,openfile,,test_multiplot_2{LAYER={COLOR=ORANGE}}
    set instructions "Should see another plot in 2nd column at the bottom"
    set gc.IDTEXT.value "^instructions"
  elseif msg.name eqs "VSCROLL"
    mess send mplot ,,vscroll,,msg.data
    if msg.data eqs "OFF" then
      set instructions "This should have not scrolled the multiplot window"
    else
      set instructions "This should have scrolled to the ^msg.data of the multiplot window"
    endif
    set gc.IDTEXT.value "^instructions"
  elseif msg.name eqs "SCROLLSTICKY" then
    set reg.mplot.scrollend ^msg.data
    if msg.data eqs "TOP" OR msg.data eqs "BOTTOM" then
      set instructions "This should have scrolled to the ^msg.data of the multiplot window. &
                       Adding new plots, should keep the vertical scroll at the ^msg.data"
    else ! everything else defaults to off
      set instructions "The vertical scroll is now set to OFF, so adding new plots should &
                        not scroll the multiplot window"
    endif
    set gc.IDTEXT.value "^instructions"
  else
    ! do nothing
    say "Unhandled message name: ^msg.name from fid: ^msg.fid data: ^msg.data"
  endif

return
