!******************************************************************************!
! Tests that the data associated with Mouse Clicks does not get lost when the event
! get switched over to a NeXtMidas Message, but now the java.awt.event.MouseEvent 
! gets saved in the Message quals field (a table with the entry ORIG_MSG_DATA 
! containing the MouseEvent)
!
! Since 3.5.4 for bugs 2927
! @author  Jeanette McCall
!******************************************************************************!
startmacro/msgid=main/theme=gear4
  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

  pipe on
    set instructions "Test that the original Mouse Event Data is Saved in Quals:\n\n&
                      (1) LMB (left mouse button) click in one of the plots\n     &
                         (Gives a popup stating the click location, but no Modifiers)\n\n& 
                      (2) LMB+Ctrl click in one of the plots\n    &
                         (Gives a popup stating the click location, and Modifiers: Cntrl)\n\n& 
                      (3) LMB+Shift click in one of the plots\n   &
                         (Gives a popup stating the click location, and Modifiers: Shift)\n\n& 
                      (4) LMB+Shift+Ctrl click in one of the plots\n   &
                         (Gives a popup stating the click location, and Modifiers: Ctrl+Shift)"

  panel/setup/controls=gc
      plot/id=penny ^{datDir}.apenny.prm axis=frame type=contour
      plot/id=apan ^{datDir}.world.prm|^{datDir}.cities.prm

      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" 40 35 /title

  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 "WINDOW" and msg.data eqs "CLOSING" then
    popup/blocking=none popup OK "You clicked the close button!" "INFO"

  elseif msg.name EQS "MARK" then  !check for message generated by user clicking PUSHPOP icon
    ! The MARK message was created from a MouseEvent - retrieve the original MouseEvent data
    res mouse_event msg.quals.orig_msg_data
    res loc_x mouse_event.getX()
    res loc_y mouse_event.getY()
    res loc_x_screen mouse_event.getXOnScreen()
    res loc_y_screen mouse_event.getYOnScreen()
    res modifiers mouse_event.getModifiersEx()
    invoke modifiers_text java.awt.event.InputEvent.getModifiersExText(modifiers)
    ! Create a popup message with the MouseEvent data
    popup/WPOS=(100,300,400,200)/blocking=none popup OK &
       "(In Pixels) \nMouse Click Location: x=^{loc_x}, y=^{loc_y} \nAbsolute Location: x=^{loc_x_screen}, y=^{loc_y_screen} \nModifiers: ^{modifiers_text}" &
       "INFO"
  elseif msg.name EQS "POPUP" then  ! expect, but ignore these
  else
    say "Unhandled message ^msg.name from ^msg.fid"
  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
