! Tests the attaching to multiple panels.
! Also test /ICON switch on PLOT (graphical primitive)
!
! Author:  Neon Ngo
!
startmacro
  switch INTERACTIVE interAct GET DEF=TRUE SDEF=TRUE
  invoke L:ICON  "nxm.sys.libg.MWindow.ICON"
  invoke L:FRONT "nxm.sys.libg.MWindow.FRONT"
  call setDatDir

  ! Start Interactive test section
  if interAct then
    pipe on
      panel/msgid=MAIN/setup/controls=gc
      gcontrol label  MACRO "MACRO"
      gcontrol menu main "Exit with Status = " "PASS,FAIL" /tleft
      set gc.main.itemColors {PASS=GREEN,FAIL=RED}

      set instructions "Should see two panels in their own frame with a plot &
                        of apenny.prm in one and fftdemo.prm in the other. There is another plot (alaska) that &
                        should not be visible (it is iconified).\n\n&
                        Click on the top set of buttons to ICONIFY and DEICONIFY the line plot (fftdemo).\n\n&
                        Next, use the mouse to ICONIFY (by clicking the '-' in the top right corner) the &
                        line plot and then use the DEICONIFY button to restore it.\n\n&
                        Next, click ICONIFY in the top set of buttons to minimize the plot again and then use the mouse to restore it.\n\n&
                        Finally, use the DEICONIFY and ICONIFY buttons to restore the hidden plot (alaska) and iconify it again."
      gcontrol text idtext  "Instructions" "^instructions" 24 30 /title

      gcontrol button myButt "Toggle Plot 2 (fftdemo) Display" "ICONIFY,DEICONIFY"
      ! buttons to make it easier to test /ICON on plot3
      gcontrol button MYBTN2 "Toggle Plot 3 (alaska) Display"  "ICONIFY,DEICONIFY"

      panel/panes=win1/setup=win1
      panel/id=panel3/panes=win2/setup=win2

      plot/id=plot1/win=win1.pane1 ^{datDir}.apenny.prm
      plot/id=plot2/win=win2.pane1 ^{datDir}.fftdemo.prm
      ! next plot is used for testing /ICON switch on graphical primitives (code in MWindow)
      plot/id=plot3/icon/wpos=(290,360) ^{datDir}.alaska.prm

    pipe off
  endif

endmacro

!******************************************************************************!
! process messages for interactive tests
!******************************************************************************!
procedure processMessage m:msg
  !say "msg.name ^msg.name, data ^msg.data"

  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name: Tests" msg.data eqss "PASS"
    pipe stop
  elseif msg.name eqs "MYBUTT" then
    res L:myinfo msg.info
    if msg.data eqss "ICON"
      set myinfo ICON
    else
      set myinfo FRONT
    endif
    message send panel3 name="SHOW" info=myinfo data=^msg.data
  elseif msg.name eqs "MYBTN2" then
    invoke ,, reg.plot3.mw.setDisplay(msg.data)
  else
    say "^reg.main.name: 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
