startmacro
!
! Test incremental ZOOM IN / OUT  (BUG 1487).
!
! Author:  J. Bauer
!
switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE
switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE

call setDatDir

set defaultInstructions &
    "Should see a plot of the world with the nations of the world.\n\n&
     1) Use slider to set 'ZOOM' button incremental zoom percentage\n\n&
     2) Click all the buttons and verify ZOOM IN or OUT percentage.\n\n&
     3) You cannot ZOOM OUT farther than the original file borders\n\n&
     5) While zoomed in, use the 'L', 'R', 'U', 'D', 'I', and 'O'\n   &
        keys to move Left, Right, Up, Down, In, Out, respectively.\n\n&
     5) Double click with the right mouse button to ZOOM out\n\n&
     6) Press the 'DISABLE' button to disable double-click zooms\n   &
        and try it again."

if interAct then
  pipe init
  
  ! Change the keyMap to custom settings
  env set KEYMAP {PLOT={LEFT="L",RIGHT="R",in=i,down=d,up=u,out=o}}

  panel/setup/controls=gc
  plot/msgid=MAIN/id=idplot/mousewheelzoom/usemouseposition/READOUT="+OnAxis"/zoomadj=.1/DBLCLICKZOOM &
          ^{datDir}.world.shp|nxm.sys.test.points.shp view=latlon 

  gcontrol label mainLabel "Main"
   gcontrol menu main "Exit with Status = " "PASS,FAIL" /tleft
   set gc.main.itemColors {PASS=GREEN,FAIL=RED}
  gcontrol text idtext "Instructions" "^defaultInstructions" 40 18 /title

  gcontrol DVAL dval1 "ZOOM % " 50 1 99 1   /slider   /msg=yes
  gcontrol button dvalbutton "" "ZOOM"

  gcontrol/nc=2 button zoominout "INCREMENTAL ZOOMS" &
                  "ZOOM IN 10%,ZOOM IN 50%,ZOOM IN 90%,ZOOM OUT 10%,ZOOM OUT 50%,ZOOM OUT 90%"
 
  gcontrol/nc=1 button zoomallout "" "ZOOM ALL THE WAY OUT" 
 
  gcontrol button dblclick "DOUBLE CLICK ZOOMS" "DISABLE,ENABLE" "ENABLE" /ChkBox
 
  pipe off

endif

endmacro

!******************************************************************************!
procedure processMessage m:msg

!say "msg.name ^msg.name, data ^msg.data"

if msg.name eqs "MAIN" then
  assert/text="Plot ZOOM tests" msg.data eqss "PASS" 
  ! Set keyMap back to default
  res t:km "nxm.sys.cfg.keyMap.tbl"
  env set keymap ^km
  pipe stop
elseif msg.name eqs "DVALBUTTON" then
  calc val ^gc.dval1.value 100 /
  message FUNC=sendw ID=IDPLOT NAME=ZOOMIN  DATA=val
elseif msg.name eqs "ZOOMINOUT" then
  if msg.data eqs "ZOOM IN 10%" then
    message FUNC=sendw ID=IDPLOT NAME=ZOOMIN  DATA=.1
  elseif msg.data eqs "ZOOM OUT 10%" then
    message FUNC=sendw ID=IDPLOT NAME=ZOOMOUT DATA=.1
  elseif msg.data eqs "ZOOM IN 50%" then
    message FUNC=sendw ID=IDPLOT NAME=ZOOMIN 
  elseif msg.data eqs "ZOOM OUT 50%" then
    message FUNC=sendw ID=IDPLOT NAME=ZOOMOUT
  elseif msg.data eqs "ZOOM IN 90%" then
    message FUNC=sendw ID=IDPLOT NAME=ZOOMIN DATA=.9
  elseif msg.data eqs "ZOOM OUT 90%" then
    message FUNC=sendw ID=IDPLOT NAME=ZOOMOUT DATA=.9 
  endif
elseif msg.name eqs "ZOOMALLOUT" then
  message FUNC=sendw ID=IDPLOT NAME=ZOOMOUT DATA=-1
elseif msg.name eqs "DBLCLICK" then
  if msg.data eqs "DISABLE" then
    message FUNC=sendw ID=IDPLOT NAME=DBLCLICK DATA=FALSE
  elseif msg.data eqs "ENABLE" then
    message func=sendw id=IDPLOT name=DBLCLICK data=TRUE 
  endif 
else
  ! do nothing
  !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

!******************************************************************************!
procedure open
  ! Automatically called
return
