!******************************************************************************!
! purpose: Test the POPUP graphic primitive
!
! @author : Jay Hallam / J. Czechowski IV
!******************************************************************************!
startmacro
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE  ! for normal interactive test(s)
  switch COREGRAPHICS  coregraphics GET DEF=FALSE SDEF=TRUE  ! for a quick check of graphics - more extreme tests - since 3.8.1
  set theTitle "My Test Title"
  set instructions "Click on one of the TESTS options.  For each test option select &
                    one of the message types. The User Input field should show your selection &
                    or the text you entered. The title should be '^theTitle'"

  ! Big list of colors used when testing MASK/S
  set colors "aliceblue,antiquewhite,aqua,aquamarine,azure,beige,bisque,&
              black,blanchedalmond,blue,blueviolet,brown,burlywood,&
              cadetblue,chartreuse,chocolate,coral,cornflowerblue,&
              cornsilk,crimson,darkblue,darkcyan,darkgoldenrod,darkgray,&
              darkgreen,darkkhaki,darkmagenta,darkolivegreen,darkorange,&
              darkorchid,darkred,darksalmon,darkseagreen,darkslateblue,&
              darkslategray,darkturquoise,darkviolet,deeppink,deepskyblue,&
              dimgray,dodgerblue,firebrick,floralwhite,forestgreen,fuchsia,&
              gainsboro,ghostwhite,goldenrod,gray,green,greenyellow,&
              honeydew,hotpink,indianred,indigo,ivory,khaki,lavender,&
              lavenderblush,lawngreen,lemonchiffon,lightblue,lightcoral,&
              lightcyan,lightgoldenrodyellow,lightgreen,lightgrey,&
              lightpink,lightsalmon,lightseagreen,lightskyblue,&
              lightslategray,lightsteelblue,lightyellow,lime,limegreen,&
              linen,magenta,maroon,mediumaquamarine,mediumblue,&
              mediumorchid,mediumpurple,mediumseagreen,mediumslateblue,&
              mediumspringgreen,mediumturquoise,mediumvioletred,&
              midnightblue,mintcream,mistyrose,moccasin,navajowhite,navy,&
              oldlace,olive,olivedrab,orange,orangered,orchid,&
              palegoldenrod,palegreen,paleturquoise,palevioletred,&
              papayawhip,peachpuff,powderblue,purple,red,rosybrown,&
              royalblue,saddlebrown,salmon,sandybrown,seagreen,seashell,&
              sienna,silver,skyblue,slateblue,slategray,springgreen,&
              steelblue,teal,thistle,tomato,turquoise,violet,wheat,white,&
              whitesmoke,yellow,yellowgreen"

  set popupResult "No test chosen yet"
  if interAct or coregraphics then
    invoke blockingOptionsList nxm.sys.prim.popup.blockingOptionsList

    pipe on

      panel/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 "^instructions" 24 5 /title

      gcontrol MENU   TESTS    "TESTS" "Alert,Buttons,Choice,Choice2,Color,Login,Mask,Mask/S,Ok,&
                                        OkCancel,Password,Text,YesNo,YesNoCancel,File" 0 /NC=3
      gcontrol LABEL  OPTLBL   "Options"
      gcontrol PROMPT defaults "Default Text Value  " "Hello World!" /msg=f /title
      gcontrol MENU   blocking "Blocking Options    " "^blockingOptionsList" "None" /onerow /msg=f /tleft /flags="Toggle|ChkBox|NoState"
      gcontrol MENU   msgType  "POPUP Message Type  " "ERROR,INFO,WARNING,QUESTION,PLAIN" "QUESTION" /onerow /msg=f /tleft
      gcontrol MENU   position "POPUP Position      " "Center,Mouse,ManualXY,ManualXYWH" "Center" /onerow /msg=f /tleft
      gcontrol MENU   cancel   "Send CANCEL to Popup" "<Send Now>" /onerow /tleft
      gcontrol MENU   popt     "PATHOPT Display (FILE)" "FullPath,NoPath,AuxPath,AuxQual" "AuxQual" /onerow /msg=f /tleft

      gcontrol TEXT userInput "User Input" "^popupResult" 24 4 /title
    pipe off
    
    %test_popup_theme
    
  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 "CANCEL" then
    message send popupid ,, cancel

  elseif msg.name eqs "POPUP" then
    set gc.userInput.value "Got POPUP message INFO=^msg.info DATA=^msg.data"

  elseif msg.name eqs "TESTS" then
    set function "^msg.data"
    set options  ""
    set defaults ""
    set message "A test for the ^{function} popup."
    set position "^gc.position.value"

    if position eqs ManualXY then
      set position "(10,10)"
    elseif position eqs ManualXYWH then
      set position "(1,100,300,200)"
    endif

    if function EQS Login then
      set defaults "^env.user"
    elseif function EQS Alert then
      set message "Setting Blocking="None". Send CANCEL to close."
      set gc.blocking.value "None"
    elseif function EQS Text then
      set defaults gc.defaults.value
    elseif function EQS Choice or function EQS Buttons then
      set options "Option1,Option2,Option3"
    elseif function EQS Choice2 then
      set options "Cool,Cancel,NotCool"
      set function "CHOICE"
    elseif function EQS mask then
      set options  "red,yellow,green,blue"
      set defaults "|red|blue|"
    elseif function EQS "MASK/S" then
      set function "MASK/S"
      set message "A test for the MASK popup with many options."
      set options "^colors"
      set defaults "aliceblue|cornflowerblue"
    endif

    set gc.userInput.value ""
    set popupResult "<Waiting for Message>"
    if function eqs YesNoCancel then
      set L:popWidth 20
      set message "^message This popup should only be ^popWidth characters (max) wide."
      popup/wpos="^position"/blocking="^gc.blocking.value"/id=popupid/msgid=main&
         /msgname="POPUP"/title="^theTitle"/popWidth=^popWidth &
         popupResult "^function" "^message" "^gc.msgType.value" "^options" "^defaults"
    elseif function eqs File then
      popup/id=popupid/msgid=main popupResult FUNC=file FILE/M AUXLIST=DAT &
         PATHOPT="^gc.popt.value" FILTER="*.prm|*.tmp"
    else
      popup/wpos="^position"/blocking="^gc.blocking.value"/id=popupid/msgid=main&
         /msgname="POPUP"/title="^theTitle" &
         popupResult "^function" "^message" "^gc.msgType.value" "^options" "^defaults"
    endif
    set gc.userInput.value "^popupResult"

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

return
