!******************************************************************************!
! Macro to test ability for TEXT and STEXT setBounds timing errors that result
! in the width or vertical starting location being incorrect
!
! @issue    NXM-3550 GCONTROL: TEXT and STEXT timing error causes width to be incorrect
! @author:  Jeanette McCall
! @since    NeXtMidas 3.9.4
!******************************************************************************!
startmacro S:throttle["REAL"]
  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

  !!!!! WARNING !!!!! BE CAREFUL ALTERTERING INSTRUCTIONS !!!!!!!!!!!!!!!!!!!!!!!!
  ! The instruction / html length is specifically designed so all four vertical  !
  ! scroll bars appear at almost exactly the same control pane width.            !
  ! This makes it much easier to test and see failures.                          !
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  res htmlstr1 "<html>&
             <body BGCOLOR="#000000" TEXT="#80c0c0" LINK="#ff8080" VLINK="#ff0000" ALINK="#a05050">&
             <div ALIGN="left">&
             <table BGCOLOR="#000080" BORDER=3 BORDERCOLOR="#0000ff"><tr>&
             <td><h1><font FACE="courier" SIZE=3><font SIZE=4>T</font>ESTING GSTEXT WITH HTML!</font></h1></td>&
             </tr></table>&
             </div><br><br>&
             <p>&nbsp;&nbsp;Hi there!<br>&
             <h2><font SIZE=4 COLOR="#00ff00">Welcome to this challenge</h2><br>&
             <li><font SIZE=4 COLOR="#00ff00"><b>Try to make the GTEXT or GSTEXT the wrong width or start at the wrong place vertically</b></font></li>&
             <li><font SIZE=4 COLOR="#00ff00"><b>Resize the control pane FAST - just the control section, not the whole panel</b></font></li>&
             </body></html>"



  if interAct then
    set instructions "1) grab the right edge of the panel and move &
                      it to the left making the whole panel narrower.\n&
                      Is there now a vertical gap in the instruction area &
                      before the text block really begins?\n&
                      If so, the first test failed.\n\n&
                      2) Resize the graphics pane wildly narrower then wider, while &
                      KEEPING the VERTICAL SCROLL BAR always PRESENT.\n&
                      Can you get it to a point where there is even a momentary gap between &
                      the vertical scroll bar and the right side of Pane 0 (control pane)?\n&
                      If you get the gap then part 1 of this test failed.\n\n&
                      --------------------------------------------&
                      --------------------------------------------&
                      --------------------------------------------&
                      --------------------------------------------&
                      keep filler so vertical scroll bars appear at same time &
                      --------------------------------------------&
                      --------------------------------------------&
                      --------------------------------------------&
                      --------------------------------------------&
                      "
    set moretext     "--------------------------------------------&
                      keep filler so have vertical scrollbar at same time &
                      --------------------------------------------&
                      --------------------------------------------&
                      --------------------------------------------&
                      --------------------------------------------&
                      --------------------------------------------&
                      --------------------------------------------&
                      ---------------&
                      "

    ! Having the plots just adds load to increase chance of timing error
    set format sf
    set sr 1e4
    set over 0
    set sfreq sr/10
    set chirpamt sfreq/4
    set amp 1e4
    set noiseamp 1e2
    set fsize 512
    set numelem 10e10
    set firstClick true
    invoke tcur nxm.sys.lib.Time.current()

    pipe on
      panel/msgid=MAIN/setup/controls=gc
      gcontrol label macro "Test MACRO"
      gcontrol menu main "Exit with Status =" "PASS,FAIL" TABLE={ItemColors={PASS="GREEN",FAIL="RED"}} /tleft

      gcontrol label  macro   "TEXT Instructions"
      gcontrol text idtext "Instructions" instructions 24 15 /title

      gcontrol label  macro   "more TEXT"
      gcontrol text idtext "" moretext 24 5 /title

      gcontrol label  macro  "STEXT HTML Comments"
      ! HTML styled text string passed to STEXT command
      gcontrol STEXT gstext "HTML/Styled Text Below" htmlstr1 24 15 /title

      gcontrol STEXT gstext2 "" "<body>Okay, this is a tricky test!!!!! You should spend a couple minutes trying to get this to fail.</body>" 24 1 /wtheme={CWFG=YELLOW,CWBG=BLUE}

      ! This is just for load on the test
      ! Create waveforms with adjustable frequency (2nd one has frequency chirped each TL)
      waveform/id=wave/throttle=^throttle _wave format elem=numelem cos freq=sfreq amp=amp delta=1/sr start=^tcur
      waveform/id=wavec/throttle=^throttle/tl=4k _wavechirp format elem=numelem cos freq=sfreq amp=amp delta=1/sr chirp=^chirpamt start=^tcur
      ! Create ffts of the 2 waveforms (frame size can be adjusted using gcontrol)
      fft/dbf/id=fft _wave _fft{form=sf} fsize over=over
      fft/dbf/id=fftchirp _wavechirp _fftchirp fsize over=over
      ! plot the ffts
      plot/id=plotfft/msgid=MAIN/READOUT=Show|OnAxis|T|dT _fft view=iXY 
      plot/id=plotfftchirp/msgid=MAIN/READOUT=Show|OnAxis|T|dT _fftchirp view=iXY
      plot/id=plotfftcopy/msgid=MAIN/READOUT=Show|OnAxis|T|dT _fft view=iXY 
      plot/id=plotfftchirpcopy/msgid=MAIN/READOUT=Show|OnAxis|T|dT _fftchirp view=iXY
      list2/id=list ^{datDir}.coneflags5000.prm

      ! add a logger to match Jeff's test
      msglog/id=logger/msgid=main/wrap/file=logFile
      res INFO 0
      message send logger ,, LOG ,INFO, "Hope your day is going well! Hang in there on testing!"

    pipe off
  endif
endmacro

!******************************************************************************!
! Main process message for this macro. Should be right after the 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 "RESIZE" then

   say "resize"
  else
    say "Unhandled message name: ^msg.name from fid: ^msg.fid data: ^msg.data"
  endif
return

!******************************************************************************!
! If an unexpected exception is caught, mark test as failed, unless it is expected
!******************************************************************************!
procedure processException m:emsg
  if expectedException REXISTS then
    assert/text="^reg.main.name: Expected ERROR starts with: ^{expectedException}" expectedException EQSS emsg.data.message
    remove expectedException
  else
    assert/text="^reg.main.name: Caught unexpected exception ^{emsg.data}" "FALSE" isTrue
    if "Trace" SUBS ENV.DEBUG then invoke ,, emsg.data.printStackTrace()
  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
