/* PAHello.rexx HelloWorld program for ProAction. ©2012 Niels Bache, permission granted to use and copy partly or fully. Parts taken from BroadBlues' demo script in the ProAction archive, ScaleProjectWithContents.rexx. BroadBlues is given special permission to use a verbatim or modified copy as part of his ProAction distribution. $VER: PAHello.rexx 1.1 (7.8.2012) */ options results /* Make sure rexxsupport is available */ if ~show('L', "rexxsupport.library") then do if ~addlib("rexxsupport.library", 0, -30, 0) then do say "Cannot add rexxsupport.library!" exit 10 end end /* Make sure ProAction is available */ if ~show('P', "PROACTION") then do myCmd = "run <>NIL: *>NIL: APPDIR:ProAction" address command myCmd myCmd = "WaitForPort PROACTION" address command myCmd if RC >= 5 | ~show('P', "PROACTION") then do say "Cannot start ProAction server!" exit 10 end end /* Target the ProAction server as default from now on */ address PROACTION /* Make a unique name for our own port - the one where we receive events from ProAction */ myPortname = "PAHello" || pragma('I') if ~openport(myPortName) then do say "Cannot open own message port!" exit 10 end /* This is the main window, the basis of the GUI. */ myGuiTags.0 = 11 myGuiTags.1.TAGNAME = "WA_Width" myGuiTags.1.TAGVALUE = 300 myGuiTags.2.TAGNAME = "WA_Height" myGuiTags.2.TAGVALUE = 50 myGuiTags.3.TAGNAME = "WA_DragBar" myGuiTags.3.TAGVALUE = 1 myGuiTags.4.TAGNAME = "WA_DepthGadget" myGuiTags.4.TAGVALUE = 1 myGuiTags.5.TAGNAME = "WA_SizeGadget" myGuiTags.5.TAGVALUE = 1 myGuiTags.6.TAGNAME = "WA_CloseGadget" myGuiTags.6.TAGVALUE = 1 myGuiTags.7.TAGNAME = "WA_Activate" myGuiTags.7.TAGVALUE = 1 myGuiTags.8.TAGNAME = "WA_Title" myGuiTags.8.TAGVALUE ="PAHello" myGuiTags.9.TAGNAME = "WA_PubScreenName" myGuiTags.9.TAGVALUE = "Workbench" myGuiTags.10.TAGNAME = "WA_PubScreenFallBack" myGuiTags.10.TAGVALUE = 1 myGuiTags.11.TAGNAME = "WINDOW_Position" myGuiTags.11.TAGVALUE = "WPOS_CENTERSCREEN" /* This is the root (and in this case only) layout gadget inside the window. It will make room for one column of two gadgets: a string with a button below it. */ myLayoutTags.0 = 1 myLayoutTags.1.TAGNAME = "LAYOUT_Orientation" myLayoutTags.1.TAGVALUE = "LAYOUT_ORIENT_VERT" /* First we ask ProAction to create a GUI; this consists of the window (which is not yet opened, but just created). ProAction gives us back a key for all further communication, which we store as myGuiKey. */ 'CREATEGUI PORTNAME "' || myPortName || '"TAGSTEM myGuiTags' if RC > 0 then do say "Cannot create GUI!" exit 10 end myGuiKey = RESULT /* Now add the root layout gadget we prepared above. */ 'ADDLAYOUT GUIID ' || myGuiKey || ' TAGSTEM myLayoutTags' myLayoutKey = RESULT /* And inside that, add the two gadgets. We haven't bothered creating a stem variable with tags for each of those, but we could have. Instead, we just specify the tags as a literal tag string. Note that we save the keys returned in RESULT for each gadget; this lets us know later which gadget is manipulated by the user. */ 'ADDGADGET GUIID ' || myGuiKey || ' GADGETCLASS "string.gadget" ' || , 'TAGSTRING "STRINGA_TextVal,Hello ProAction World!,' || , 'STRINGA_Justification,GACT_STRINGCENTER,' || , 'GA_ReadOnly,1,' || , 'TAG_DONE"' myStringGadKey = RESULT 'ADDGADGET GUIID ' || myGuiKey || ' GADGETCLASS "button.gadget" ' || , 'TAGSTRING "GA_Text,Hi!,' || , 'GA_RelVerify,1,' || , 'TAG_DONE"' myButtonKey = RESULT /* Tell ProAction we're done setting up the GUI, and to open the window with our GUI and start transmitting any events to us. */ 'ENDLAYOUT GUIID ' || myGuiKey 'OPENGUIWINDOW GUIID ' || myGuiKey /* The main event handling loop. We are prepared for handling the following events: 1. A QUIT ARexx command sent from e.g. another ARexx script. 2. The user hitting the close gadget of our window. 3. The user hitting the button in our GUI. */ do events = 1 /* The iterator ('events') is not used, except for giving us a name to specify when leaving the loop. */ gotMsg = waitpkt(myPortName) if gotMsg then do /* Some message arrived at our port; find out what it was. */ pkt = getpkt(myPortName) do while pkt ~= '0000 0000'x /* Get and process all packets which are waiting, until we get the "end marker". */ cmd = getarg(pkt) call reply(pkt) /* We have to reply each one ASAP. */ if cmd = "QUIT" then leave events /* Case 1 above: We receive only the string 'QUIT'. This doesn't (necessarily) come from ProAction and therefore doesn't refer to our GUI key. */ parse var cmd event " GUIID" sentGuiKey . select when event = "CLOSE" then leave events /* Case 2 above: The string contains "CLOSE GUIID x"; we're just interested in the word CLOSE. */ when event = "GADGETUP" then do /* Case 3 above: The string contains "GADGETUP GUIID x GADGETID y CODE z", where y is the key to the gadget which was manipulated. We only care about the event if the gadget was our button. */ parse var cmd junk "GADGETID " gadId " CODE " eventCode . select when gadId = myButtonKey then do 'SETATTRS GUIID ' || myGuiKey || , ' OBJECTID ' || myStringGadKey || , ' TAGSTRING "STRINGA_TextVal,' || , 'Gooodbye cruel ProAction World!,' || , 'TAG_DONE"' 'SETATTRS GUIID ' || myGuiKey || , ' OBJECTID ' || myButtonKey || , ' TAGSTRING "GA_Text,Arrrgh!,' || , 'GA_Disabled,1,' || , 'TAG_DONE"' address command "Wait 3 SECS" /* Just so we get a chance to see the new texts. */ leave events /* Jump out of the main event handling loop and clean up. */ end /* do - set attributes on the gadgets */ otherwise nop end /* select - which gadget sent a GADGETUP? */ end /* event = GADGETUP */ otherwise nop end /* select event */ pkt = getpkt(myPortName) end /* while loop for getting all waiting packets */ end /* if gotMsg */ end /* events loop */ /* Clean up and leave the program. */ 'CLOSEGUIWINDOW GUIID ' || myGuiKey 'DESTROYGUI GUIID ' || myGuiKey exit