!******************************************************************************!
! purpose: test GCONTROL DIALOG
!
! author : J. Hallam, J. Bauer
!******************************************************************************!
startmacro
  switch INTERACTIVE interAct GET DEF=TRUE SDEF=TRUE

  if interAct then
    pipe on
      set sr 1e5
      waveform/rt _wave{ps=32k} shape=sin form=cf elem=inf amp=32e3 freq=sr/10 delta=1/sr
      fft/psd/log _wave _waveb nfft=1k

      panel/msgid=MAIN/setup/controls=gc

      gcontrol label  MACRO "MACRO"
      gcontrol menu main "Exit with Status = " "PASS,FAIL" /tleft
      set gc.main.itemcolors {PASS=GREEN,FAIL=RED}
      
      set instructions "This test case behaves incorrectly in conf/baseline. &
                        Therefore, if you encountered this during conf/baseline &
                        testing, open a new NeXtMidas session and run this stand &
                        alone.\n\nPress the button and change widgets on dialog &
                        as instructed. The dialog may flicker if in all-SWING &
                        graphics mode. "
      
      gcontrol TEXT idtext INSTRUCTIONS "^instructions" 24 13 /title

      gcontrol button SHOWDIALOG "" "Press here to Test Dialog Pop-Up" /tleft

      plot/id=plot2 _waveb type=line cnt=click axis=bf

    pipe off

    %test_gcontrol_dialog_rollup
  endif

endmacro

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

if msg.name eqs "MAIN"
  assert/text="^reg.main.name: user indicated" msg.data eqs "PASS"
  pipe stop

elseif msg.name eqs "SHOWDIALOG"  then
  set diaText "Changing 'Choice Message' should send a message. \n\n&
               Changing 'Choice NO Message' should not. \n\n&
               Middle Mouse Click on the Prompt Title, You should see the GPrompt config menu popup.\n\n&
               Finally, click on Apply, Add, and/or Close button."
  gcontrol/temp/msg=t/handle="DLOG" DIALOG dialog "Dialog Box" 300 3 "Add,Apply,Close" "Add,Apply"
    res dlw reg.DLOG.widgets
    res choices "ITEM1,ITEM2,ITEM3,ITEM4,ITEM5,ITEM6"
    gcontrol/panel=dlog/msg=t text   text  "TextInfo" "^diaText" 30 15
    gcontrol/panel=dlog  prompt testPrompt "Sample Prompt" "This is a sample prompt in a dialog"
    gcontrol/panel=dlog/msg=true choice dialogChild_msg "Choice Message  " choices "ITEM1"
    gcontrol/panel=dlog choice dialogChild_nomsg "Choice No Message  " choices "ITEM1"
    invoke ,, dlog.resize(1)

  assert/text="DIALOG widget table creation" dlw.TEXT.title EQS "TextInfo"

elseif msg.name eqs "DIALOG"  then
  ! Message(s) from dialog button press
  if this.verbose isTrue then say "Got message from DIALOG: ^msg"
  ! for testing BUG 2490
  assert/text="^reg.main.name: message's info contains one-based index of selected button: ^msg.info" msg.info GT 0

elseif msg.name eqss "DIALOGCHILD"  then
  if msg.name eqs "DIALOGCHILD_NOMSG" then
    assert/text="^reg.main.name: Did NOT expect a message from ^msg.name" FALSE
  else
    assert/text="^reg.main.name: Expected a message from ^msg.name" "^msg.name" EQS "DIALOGCHILD_MSG"
  endif

else
  say "^reg.main.name: Unhandled message name: ^msg.name from fid: ^msg.fid"
endif

return
