!******************************************************************************!
! purpose: test various types of GCONTROLS
!
! author : JPH and others
!******************************************************************************!
startmacro/theme={cfg=0xF0F0F0,cbg=0x000000,cwbg=0x000000,cwts=0x606060,cwbs=0x303030,cwfg=0xD88000,cwfh=0x7ABAE0,cwfg=0xF0F0F0,cwms=0x001010}
  ! NOTE: Do not change the /theme={...} on the startmacro line. This setting
  !       duplicates the problem with Bug 1136 see bug report for details, do
  !       not change this value!
  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)
  switch COREGRAPHICS  coreGraphics GET DEF=FALSE SDEF=TRUE  ! for a quick check of graphics - more extreme tests - since 3.8.1

  if interAct then

    res butt1 "One"
    res butt2 "Two"
    res butt3 "Three"

    pipe on

      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 "Titles on each widget indicate test behavior. &
                        Select each button below and verify a message &
                        is printed to your terminal screen that passes. &
                        Enter embedded and trailing spaces as well as &
                        other invalid characters in the xVAL widgets &
                        popup to ensure exceptions do not occur.\n&
                        Note: Please run this test in stand-alone mode to &
                        see the button messages."
      gcontrol TEXT idtext INSTRUCTIONS "^instructions" 24 7 /title

      gcontrol label TESTS "TESTS" AlwaysOpen

      gc button state "Should default to NO button pressed" "One,Two,Three" "" /cs
      gcontrol/CS CHOICE choice "Change and PROMPT should change (case preserved)" &
                                "UPPERCASE,MixedCase","UPPERCASE"
      set gc.CHOICE.itemcolors {uppercase=orange,mixedcase=red}
      gcontrol/mon=monStr/msg=f/edit=f prompt PROMPT "PROMPT : NOT editable!" "___"

    !!!jph -- TBD, limit width and echo character for PASSWORDS
      gcontrol prompt shortPrompt "Enter string and watch PROMPT change" "Defa" 4

      gcontrol TVAL tval "Change and select TVAL" DEF=1 MIN=0 MAX=86400 INC=1 /msg=y

      assert/text="^reg.main.name: item count" gc.main.itemCount EQ 2
    pipe off

    lookandfeel gear3  ! reset theme
  endif

  invoke shellHeadless nxm.sys.lib.Shell.isHeadless()
  if shellHeadless then
    %test_gcontrol_panel_headless/headlessmode ! NXM-4064
    %test_gcontrol_panel_headless              ! NXM-4064
  endif

  ! Also run test_gcontrol with inputborder switch (both settings)
  if baseline then
    if shellHeadless ISFALSE then %test_gcontrol_panel_headless/interactive=^interAct ! NXM-4064
    %test_gcontrol_choice/interactive=^interAct
    %test_gcontrol_dval/interactive=^interAct
    %test_gcontrol_menu/interactive=^interAct
    %test_gcontrol_switch_edit/interactive=^interAct ! Bug 1900
    %test_gcontrol_switch_gc/interactive=^interAct ! This one runs without user interaction
    %test_gcontrol_indexing  ! Bug 2319, 2320

    if interAct ISFALSE then
      %test_gcontrol_switch_mon/headless ! This one runs without user interaction
    else
      ! test both mouseover (MO) and permanent (PERM) input border
      %test_gcontrol_alert
      %test_gcontrol_bean
      %test_gcontrol_button
      %test_gcontrol_calendar
      %test_gcontrol_dialog
      %test_gcontrol_lval
      %test_gcontrol_tval
      %test_gcontrol_file
      %test_gcontrol_files_sticky    ! BUG 2022
      %test_gcontrol_flags
      %test_gcontrol_label
      %test_gcontrol_label_open      ! Bug 2680
      %test_gcontrol_line
      %test_gcontrol_pipemon
      %test_gcontrol_switch_edit_false ! NXM-3889, NXM-3890
      %test_gcontrol_switch_wait
      %test_gcontrol_switch_mon ! This one runs without user interaction
      %test_gcontrol_prompt       ! Bug 2223
      !%test_gcontrol_flicker    ! Bug 1065, 1208  ! disabled because it cannot reliably showing the issue
      %test_gcontrol_inputborder/inputborder=mo
      %test_gcontrol_inputborder/inputborder=perm
      %test_gcontrol_button2
      %test_gcontrol_switch_wtheme
      %test_gcontrol_disable
      %test_gcontrol_grayout
      !%test_gcontrol_perm
      %test_gcontrol_setshow
      %test_gcontrol_theme_color  ! Bug 2398
      %test_gcontrol_button_theme ! Bug 2480
      %test_gcontrol_text         ! Bug 2473
      %test_gcontrol_stext        ! Bug 2534
      %test_gcontrol_readout      ! Bug 2681
      %test_gcontrol_panel        ! Bug 42
      %test_gcontrol_menu_scroll  ! Bug 2825
      %test_gcontrol_progressbar  ! NXM-3493
      %test_gcontrol_maxval       ! NXM-3224
      %test_gcontrol_stext_text_width  ! NXM-3550
      %test_gcontrol_dialog_max_size   ! NXM-3557

      ! Also run the following test macros for DR's related to GCONTROL
      %test_dr505441-1
      call run_ucl_macros
    endif

  ! If COREGRAPHICS run a short list of extreme tests that tend to be the ones to show graphical issues
  elseif coreGraphics then
    %test_gcontrol_calendar/COREGRAPHICS
    %test_gcontrol_flags/COREGRAPHICS
    %test_gcontrol_menu/COREGRAPHICS
    %test_gcontrol_switch_wtheme/COREGRAPHICS
    %test_gcontrol_progressbar/COREGRAPHICS  ! NXM-3493
    call run_ucl_macros
  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 "CHOICE" or msg.name EQS "SHORTPROMPT" then
    set monStr "^msg.data"

  elseif msg.name eqs "STATE"  then
    set pass "FALSE"
    !info "Expected a message from ^msg.name data: ^msg.data"
    if/cs msg.data eqs "One" OR msg.data eqs "Two" or msg.data eqs "Three"
      set pass "TRUE"
    else
      set pass "FALSE"
    endif
    assert/text="^reg.main.name: Button with /CS returned case sensitive text." pass eqs "TRUE"
  elseif msg.name eqs "TVAL"  then

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

return

!******************************************************************************!
procedure run_ucl_macros
  res savepath opt.path  ! save previous path

  path add ucl
  !make code ucl  ! only need to bld a few classes

  if nxm.ucl.libg.GDatePicker.class nfexists then
    bld GDatePicker libg ucl
    assert/text="^reg.main.name: Compiled GDatePicker" nxm.ucl.libg.GDatePicker.class fexists
  endif

  home test ucl
  %test_gcontrol_datepicker/coregraphics      ! Tests that old style custom GWidget still works
  home /restore

  path set ^savepath  ! restore previous path

return
