! Tests moving MWindow (e.g. plot) to different display on multi-headed systems.
!
! added /EventFilter=NoMiddleMouse on startmacro line to test BUG 2712
!
! Author:  Neon Ngo
!******************************************************************************!
startmacro/EVENTFILTER=NoMiddleMouse
  switch INTERACTIVE interAct GET DEF=TRUE

  call setDatDir

  environment get NUMSCREENS numscreens
  results displaychoices "0"
  do i 1 ^{numscreens}-1
    results displaychoices "^{displaychoices}, ^i"
  enddo

  ! 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 "1. If you have multi-headed displays, select display number &
      		            to pop the PLOT from panel and move to display. Verify &
      		            that the PLOT moves to the specified screen. \n&
      		            2. The middle mouse button (MMB) should also be disabled on the PLOT, &
      		            the PANEL, and the GCONTROLs. You can still bring up the configure menu &
      		            by clicking inside the PLOT or PANEL and pressing the 'M' key."
      gcontrol text idtext  "Instructions" "^instructions" 24 14 /title

      gcontrol choice movedisplay "Move to Display" ^displaychoices 0
      plot/id=gplot ^{datDir}.altitude.prm

    pipe off
  endif

endmacro

!******************************************************************************!
! process messages for interactive tests
!******************************************************************************!
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 "MOVEDISPLAY" then
    message sendw gplot ,, "WINDOW" ,, "PUSH"
    invoke ,, reg.gplot.mw.moveDisplay(^msg.data)
    message sendw gplot ,, "WINDOW" ,, "POP"
  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
