!******************************************************************************!
! Tests popping out the panel onto a selected screen/display
! @Note    Does not work with Xinerama displays, since they count as one (large) screen.
! @Bug     2458 Panel: Need ability to choose which screen to pop panel to
! @Bug     2690 PANEL: running a macro with a panel and /ICON shows a blank frame when user de-iconifys
! @author  J. Bauer
!******************************************************************************!
startmacro/msgid=main
  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

  set instructions "PANEL advanced pop/push test:\n &
                    1) CTRL+click the PUSHPOP icon (NE SW arrows) on the plot of apenny. You should be asked which screen &
                       you wish to pop out to.\n &
                    2) Choose a display and ensure that the popout goes to that screen.\n &
                    3) Move the popout on the screen and then click the PUSHPOP icon again. The plot &
                       should return to the macro panel.\n &
                    4) Click on the PUSHPOP icon again and the plot should return to the display it popped out to.\n &
                    5) CTRL+click on the PUSHPOP icon again and you should get prompted again.\n &
                    6) CTRL+click on the PUSHPOP icon on the plot of the world. You should NOT get prompted.\n &
                    7) Choose a display and bounds for the apenny plot and push the button below.\n &
                    8) De-iconify the iconified SD360 macro either via button or Window Manager. &
                       It and it's plots should not be blank. Close the SD360 macro."
    pipe on

      panel/setup/controls=gc/msgid=main

        plot/id=world ^{datDir}.world.prm  options=+bstore view=geo
        plot/id=penny ^{datDir}.apenny.prm axis=frame     type=cont

        gcontrol label macro "MACRO"
          gcontrol menu main "Exit with Status = " "PASS,FAIL" /tleft
          set gc.main.itemColors {PASS=GREEN,FAIL=RED}

          gcontrol text idtext  "INSTRUCTIONS" "^instructions" 24 22 /title
          gcontrol line

        gcontrol label popPos "Custom APENNY Popout Position"
          gcontrol menu winNo "Pop to screen number: " "1" "1" /tleft
          invoke numscr nxm.sys.intr.Environment.getNumScreens(false)  ! get the number of screens
          do count 2 numscr 1
            invoke gc.winNo.addItem("^count")
          enddo
          gcontrol lval xpos   "X Pos"  100 0  1500 1  /slider
          gcontrol lval ypos   "Y Pos"  100 0  1500 1  /slider
          gcontrol lval width  "Width"  600 50 1500 10 /slider
          gcontrol lval height "Height" 300 50 1000 10 /slider

          gcontrol button popButt "" "Pop It!"

        ! TODO: why do we need /BG to prevent sub-macro from blocking pipe section from continuing?
        ! since 3.3.0: run sd360 to test BUG 2690
        sd360/ID=SD360/DISPLAY=ICON/BG infinity
        gcontrol label labelicon "Test De-Iconify macro (BUG 2690)" AlwaysOpen
          gcontrol button deiconButton "" "De-Iconfiy SD360 macro"

      set reg.world.enableAdvancedPopOut false
    pipe off


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 popButt then
    res t:dev {DISP=^gc.winNo.value,BOUNDS={X=^gc.xpos.value,Y=^gc.ypos.value,W=^gc.width.value,H=^gc.height.value}}
    message send id=penny name="POP" info=-1 quals=dev

  elseif msg.name eqs deiconButton then
    invoke ,, reg.sd360.reg.panel.setDisplay("FRONT")

  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
