startmacro o:wtheme[{CWBG=WHITE,CWFG=BLUE,CWFH=RED,CWTI=RED}]
!
! Tests the GCONTROL /WTHEME switch
! @author  Jay Hallam
!
switch INTERACTIVE interAct GET DEF=TRUE
switch COREGRAPHICS coreGraphics GET DEF=FALSE SDEF=TRUE ! for a quick check of graphics - more extreme tests - since 3.8.1

if interAct or coreGraphics then

  !JPH -- Jeff's idea is to set the widget theme to a reference and then it can be
  ! updated to affect any widget using it. But I have not yet been able to get
  ! that to work.

  res z:enableThemeObjects false

  if enableThemeObjects then
    theme create themeObj wtheme | Create a theme object based off the current theme
  endif

  invoke strArray nxm.sys.lib.Theme.getThemeNames()
  sedit strArray themeList JOIN ","
  res themeList "^{themeList},Custom"
  set myInstructions "All widgets with the /WTHEME switch should have a WHITE background, red titles &
                      and BLUE items. Change any of the /WTHEME widgets to see that the theme is &
                      maintained in the popout box.  Changing the CHOICE will test that data is &
                      valid.  Any GLOBAL THEME widget should match the current theme. &
                      Press the '...Test Dialog...' button to see that matches the &
                      dialog theme you choose (custom is ^wTheme).&
                      \n\n&
                      Test theme visibility:\n&
                      a) Select Ocean Theme\n&
                      b) Select 'Press to test Dialog with /WTHEME'.\n&
                      c) Verify that the selected ITEM under Menu is visible."
  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}
      gcontrol TEXT idtext INSTRUCTIONS "^myInstructions" 60 12 /title

    gcontrol label  tests "TESTS"
      gcontrol PROMPT promptWidgetTheme    "Prompt with /WTHEME=table" "OK" /wtheme=wTheme
      gcontrol CHOICE choiceWidgetTheme "Choice with /WTHEME" "Choice1,Choice2,Choice3" "Choice2" /wtheme=^wTheme
      gcontrol CHOICE choiceGlobalTheme "Choice with GLOBAL theme " "Choice1,Choice2,Choice3" "Choice3"
      gcontrol BUTTON dialogTheme "Choose theme for dialog" themeList "CUSTOM" /msg=f /nc=3
      gcontrol BUTTON showAlert  "BUTTON w/ Global Theme" "Press to test ALERT with /WTHEME" /tleft /nodepress
      gcontrol BUTTON showDialog "BUTTON w/ Global Theme" "Press to test Dialog with /WTHEME" /tleft /nodepress

    if enableThemeObjects then
      gcontrol label  tests "Theme Object Atrributes"
      gcontrol PROMPT promptWidgetThemeObj "Prompt with /WTHEME=themeObj" "OK" /wtheme=themeObj
      set gc.themecontrol {}
      set colorNameList "RED,PURPLE,BLACK,GREEN,BLUE"
      gcontrol CHOICE themecontrol.CWTI "Theme Control - Title Color (CWTI)" "^colorNameList" RED
      ! JPH-- TBD to control all of the theme atributes
    endif

  pipe off
endif

endmacro

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

if gc.dialogTheme.value EQS "CUSTOM" then
  res dialogTheme wTheme
else
  res dialogTheme "^gc.dialogTheme.value"
endif

if msg.name eqs "MAIN"
  assert/text="^reg.main.name: user indicated" msg.data eqs "PASS"
  pipe stop
elseif msg.name EQSS "THEMECONTROL." then
  set themeObj.widgettitle ^msg.data
  invoke ,, gc.promptWidgetThemeObj.refresh()

elseif msg.name eqs "CHOICEWIDGETTHEME"  then
  assert/text="^reg.main.name: msg data is one of items in choice list" &
          msg.data EQS CHOICE1 OR msg.data EQS CHOICE2 OR msg.data EQS CHOICE3

elseif msg.name eqs "CHOICEGLOBALTHEME"  then
  assert/text="^reg.main.name: msg data is one of items in choice list" &
          msg.data EQS CHOICE1 OR msg.data EQS CHOICE2 OR msg.data EQS CHOICE3

elseif msg.name eqs "SHOWALERT"  then
  if dialogTheme instanceof nxm.sys.lib.Table then
    set myTitle "Is this TITLE ^dialogTheme.cwti and the OK=^dialogTheme.cwfg?"
  else
    set myTitle "Does this look like the ^dialogTheme theme?"
  endif
  gcontrol/wtheme=^dialogTheme/temp/msg=f alert tempalert "Alert " "^myTitle"

elseif msg.name eqs "SHOWDIALOG"  then
  gcontrol/temp/msg=f/handle="DLOG"/wtheme=^dialogTheme DIALOG dialog "Dialog Box" 300 3 "Add,Apply,Close" "Add,Apply"
  res dlw reg.DLOG.widgets
  if wTheme instanceof nxm.sys.lib.Table then
    set dialogInstructions "Dialog should have a ^dialogTheme theme, EXCEPT for the CHOICE widget which &
                             has CYAN (AQUA) title and follows the GLOBAL theme for items."
  else
    set dialogInstructions "All titles have a ^wTheme theme EXCEPT for the CHOICE widget which has a &
                            CYAN (AQUA) title and follows current theme for items."
  endif
  gcontrol/panel=dlog text   dialogChild_text    "Text   " "^dialogInstructions" 30 5
  gcontrol/panel=dlog button dialogChild_button  "Button " "ITEM1,ITEM2,ITEM3,ITEM4" "ITEM1"
  gcontrol/panel=dlog choice dialogChild_choice  "Choice " "CHOICE1,CHOICE2,CHOICE3,CHOICE4" "CHOICE1" &
          /wtheme={CWTI=CYAN}
  gcontrol/panel=dlog dval   dialogChild_cdval   "DoubleVal " DEF=0 MIN=-1e9 MAX=1e9 INC=1
  gcontrol/panel=dlog label  dialogChild_label   "Label  " "AlwaysOpen"
  gcontrol/panel=dlog menu   dialogChild_menu    "Menu   " "ITEM1,ITEM2,ITEM3,ITEM4" "ITEM1"
  gcontrol/panel=dlog prompt dialogChild_prompt   "PROMPT - please check the theme" "Ok"

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

return
