!******************************************************************************!
! Tests the /edit switch, both inside and outside of a panel
!
! @bug      NXM-3889 GWidget should allow hovers, even if NOEDIT
! @bug      NXM-3890 GPrompt EDIT=F not working when widget is independent of panel
! @since    NeXtMidas 4.1.2
! @author:  Zachary Matthews
!******************************************************************************!
startmacro
  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)

  if interAct then
    say "A set of four standalone GControls should appear, and they should not allow editing. Right-click to close each of them."
    gcontrol/nomsg prompt prompt_nopanel_noedit "PROMPT_NO_PANEL_NOEDIT" ""          /edit=f
    gcontrol/nomsg button button_nopanel_noedit "BUTTON_NO_PANEL_NOEDIT" "A,B,C" "A" /edit=f
    gcontrol/nomsg menu     menu_nopanel_noedit   "MENU_NO_PANEL_NOEDIT" "A,B,C" "A" /edit=f
    gcontrol/nomsg choice choice_nopanel_noedit "CHOICE_NO_PANEL_NOEDIT" "A,B,C" "A" /edit=f
    say "A second set of four standalone GControls should allow editing. Focus and hit enter or select a choice to close each of them."
    gcontrol/nomsg prompt prompt_nopanel_edit "PROMPT_NO_PANEL_EDIT" ""
    gcontrol/nomsg button button_nopanel_edit "BUTTON_NO_PANEL_EDIT" "A,B,C" "A"
    gcontrol/nomsg menu     menu_nopanel_edit   "MENU_NO_PANEL_EDIT" "A,B,C" "A"
    gcontrol/nomsg choice choice_nopanel_edit "CHOICE_NO_PANEL_EDIT" "A,B,C" "A"

    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
      set instructions "Testing the /edit=f switch inside a panel\n\n&
                        1. The PANEL_NOEDIT GControls should not be editable.\n&
                        2. The PANEL_EDIT GControls should be editable.\n\n&
                        3. There should be hover readouts with all PANEL_NOEDIT and PANEL_EDIT GControls.\n\n&
                        PASS this test if both cases above passed."
      gcontrol text  idtext "Instructions" instructions 24 10 /title

      gcontrol label noedit "GControls with /edit=f inside a panel"
      gcontrol/nomsg prompt prompt_panel_noedit "PROMPT_PANEL_NOEDIT" ""          /edit=f
      gcontrol/nomsg button button_panel_noedit "BUTTON_PANEL_NOEDIT" "A,B,C" "A" /edit=f /tleft
      gcontrol/nomsg menu     menu_panel_noedit   "MENU_PANEL_NOEDIT" "A,B,C" "A" /edit=f /tleft /nc=3
      gcontrol/nomsg choice choice_panel_noedit "CHOICE_PANEL_NOEDIT" "A,B,C" "A" /edit=f /tleft

      gcontrol label edit "GControls without /edit=f inside a panel"
      gcontrol/nomsg prompt prompt_panel_edit "PROMPT_PANEL_EDIT" ""
      gcontrol/nomsg button button_panel_edit "BUTTON_PANEL_EDIT" "A,B,C" "A" /tleft
      gcontrol/nomsg menu     menu_panel_edit   "MENU_PANEL_EDIT" "A,B,C" "A" /tleft /nc=3
      gcontrol/nomsg choice choice_panel_edit "CHOICE_PANEL_EDIT" "A,B,C" "A" /tleft

    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
  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
