!------------------------------------------------------------------------------!
! Tests for f1 help key listener
! NOTE:  this is an interactive test and requires operator verification
!        in order to determine test success.
!
!   Author : L. Tursky
!
!------------------------------------------------------------------------------!
startmacro

switch INTERACTIVE interAct GET DEF=TRUE
switch BASELINE    baseline GET DEF=FALSE

call setDatDir

if interAct then
  ! INPUT files used for tests
  timex now sod=sod

  pipe init
    panel/msgid=MAIN/controls=gc/setup
    set sr 1e5
    waveform/rt _wave{ps=16k} shape=sin form=cf elem=1e9 amp=32e3 freq=sr/10 delta=1/sr
    fft/psd/log _wave _waveb nfft=1k
! Don't use DEMOD since it requires DSP on the path
!    demod/lut _wave _waved{ps=32k} mode=fm

    gcontrol LABEL macro "MACRO"
    gcontrol MENU MAIN "Exit with Status = " "PASS,FAIL" /tleft
    set gc.MAIN.itemColors {PASS=GREEN,FAIL=RED}

    gcontrol LABEL cp "Control Panel"
    gcontrol dval secondofday "Seconds-of-day" sod -1 1e9 /fmt="#.000"
    set instructions "Press the F1 key while the mouse pointer is hovering over a widget. &
       The shellgui will display the help message received by the macro. Message format is: &
       ID=NULL, NAME=HELP, DATA={NAME=widgetName, VALUE=currentValue}. If the &
       mouse is hovering over a list, the data table will also contain values &
       for ROW and COL, which indicates the current table selection."

    gcontrol choice opts "Choice" "One,Two,Three" "One"
    gcontrol lval   gain  "Gain  " 5 0 10 1 /gauge
    gcontrol button state "" "Run,Pause,Stop"  1 /lh=40
    gcontrol PANEL plotPanel "Plot" 200 200
    gcontrol prompt prom "Prompt" "Initial prompt text"
    gcontrol pipemon pmon _waveb

    list/id=idlist "^{datDir}.apenny.prm"
    !list/grid=on/msgid=MAIN/win=pane1/id=idlist apenny AUTOSELECT=^autosel
    shellgui/id=shellPanel/attach
    textdisplay/id=td/exit=none/title="Instructions" text="^instructions"
    plot/id=plotPanel "^{datDir}.apenny.prm"

  pipe off

  ! Erase temporary files
  erase/quiet/warn=no temp_list_poll

endif

endmacro

!------------------------------------------------------------------------------!
procedure processMessage m:msg
!
! Procedure for handling all messages
!
  if msg.name EQS "HELP" then
    say "Got ^msg.name message with data ^msg.data"

  elseif msg.name EQS "MAIN" then
    assert/text="List tests" "PASS" SUBS msg.data
    pipe stop

  else
    !say "^reg.main.name: Unhandled messagename: ^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
