The latest version of this document can be found at www.broad.ology.org.uk/amiga/proaction/PAHello.html
1: /* PAHello.rexx 2: HelloWorld program for ProAction. 3: ©2012 Niels Bache, permission granted to use and copy partly or fully. 4: Parts taken from BroadBlues' demo script in the ProAction archive, 5: ScaleProjectWithContents.rexx. 6: BroadBlues is given special permission to use a verbatim or modified copy 7: as part of his ProAction distribution. 8: $VER: PAHello.rexx 1.1 (7.8.2012) 9: */ 10: 11: options results 12: 13: /* Make sure rexxsupport is available */ 14: if ~show('L', "rexxsupport.library") then do 15: if ~addlib("rexxsupport.library", 0, -30, 0) then do 16: say "Cannot add rexxsupport.library!" 17: exit 10 18: end 19: end 20: 21: /* Make sure ProAction is available */ 22: if ~show('P', "PROACTION") then do 23: myCmd = "run <>NIL: *>NIL: APPDIR:ProAction" 24: address command myCmd 25: myCmd = "WaitForPort PROACTION" 26: address command myCmd 27: if RC >= 5 | ~show('P', "PROACTION") then do 28: say "Cannot start ProAction server!" 29: exit 10 30: end 31: end 32: 33: /* Target the ProAction server as default from now on */ 34: address PROACTION 35: 36: /* Make a unique name for our own port - the one where we 37: receive events from ProAction */ 38: myPortname = "PAHello" || pragma('I') 39: 40: if ~openport(myPortName) then do 41: say "Cannot open own message port!" 42: exit 10 43: end 44: 45: /* This is the main window, the basis of the GUI. */ 46: myGuiTags.0 = 11 47: myGuiTags.1.TAGNAME = "WA_Width" 48: myGuiTags.1.TAGVALUE = 300 49: myGuiTags.2.TAGNAME = "WA_Height" 50: myGuiTags.2.TAGVALUE = 50 51: myGuiTags.3.TAGNAME = "WA_DragBar" 52: myGuiTags.3.TAGVALUE = 1 53: myGuiTags.4.TAGNAME = "WA_DepthGadget" 54: myGuiTags.4.TAGVALUE = 1 55: myGuiTags.5.TAGNAME = "WA_SizeGadget" 56: myGuiTags.5.TAGVALUE = 1 57: myGuiTags.6.TAGNAME = "WA_CloseGadget" 58: myGuiTags.6.TAGVALUE = 1 59: myGuiTags.7.TAGNAME = "WA_Activate" 60: myGuiTags.7.TAGVALUE = 1 61: myGuiTags.8.TAGNAME = "WA_Title" 62: myGuiTags.8.TAGVALUE ="PAHello" 63: myGuiTags.9.TAGNAME = "WA_PubScreenName" 64: myGuiTags.9.TAGVALUE = "Workbench" 65: myGuiTags.10.TAGNAME = "WA_PubScreenFallBack" 66: myGuiTags.10.TAGVALUE = 1 67: myGuiTags.11.TAGNAME = "WINDOW_Position" 68: myGuiTags.11.TAGVALUE = "WPOS_CENTERSCREEN" 69: 70: /* This is the root (and in this case only) layout gadget inside the window. 71: It will make room for one column of two gadgets: a string with a button 72: below it. */ 73: myLayoutTags.0 = 1 74: myLayoutTags.1.TAGNAME = "LAYOUT_Orientation" 75: myLayoutTags.1.TAGVALUE = "LAYOUT_ORIENT_VERT" 76: 77: /* First we ask ProAction to create a GUI; this consists of the window 78: (which is not yet opened, but just created). ProAction gives us back a 79: key for all further communication, which we store as myGuiKey. */ 80: 'CREATEGUI PORTNAME "' || myPortName || '"TAGSTEM myGuiTags' 81: if RC > 0 then do 82: say "Cannot create GUI!" 83: exit 10 84: end 85: 86: myGuiKey = RESULT 87: 88: /* Now add the root layout gadget we prepared above. */ 89: 'ADDLAYOUT GUIID ' || myGuiKey || ' TAGSTEM myLayoutTags' 90: myLayoutKey = RESULT 91: /* And inside that, add the two gadgets. 92: We haven't bothered creating a stem variable with tags for each of 93: those, but we could have. Instead, we just specify the tags as a 94: literal tag string. Note that we save the keys returned in RESULT for 95: each gadget; this lets us know later which gadget is manipulated by 96: the user. */ 97: 'ADDGADGET GUIID ' || myGuiKey || ' GADGETCLASS "string.gadget" ' || , 98: 'TAGSTRING "STRINGA_TextVal,Hello ProAction World!,' || , 99: 'STRINGA_Justification,GACT_STRINGCENTER,' || , 100: 'GA_ReadOnly,1,' || , 101: 'TAG_DONE"' 102: myStringGadKey = RESULT 103: 'ADDGADGET GUIID ' || myGuiKey || ' GADGETCLASS "button.gadget" ' || , 104: 'TAGSTRING "GA_Text,Hi!,' || , 105: 'GA_RelVerify,1,' || , 106: 'TAG_DONE"' 107: myButtonKey = RESULT 108: 109: /* Tell ProAction we're done setting up the GUI, and to open the window with 110: our GUI and start transmitting any events to us. */ 111: 'ENDLAYOUT GUIID ' || myGuiKey 112: 113: 'OPENGUIWINDOW GUIID ' || myGuiKey 114: 115: /* The main event handling loop. 116: We are prepared for handling the following events: 117: 1. A QUIT ARexx command sent from e.g. another ARexx script. 118: 2. The user hitting the close gadget of our window. 119: 3. The user hitting the button in our GUI. */ 120: do events = 1 /* The iterator ('events') is not used, except for giving us a 121: name to specify when leaving the loop. */ 122: gotMsg = waitpkt(myPortName) 123: if gotMsg then do /* Some message arrived at our port; 124: find out what it was. */ 125: pkt = getpkt(myPortName) 126: do while pkt ~= '0000 0000'x /* Get and process all packets which are 127: waiting, until we get the "end marker". */ 128: cmd = getarg(pkt) 129: call reply(pkt) /* We have to reply each one ASAP. */ 130: if cmd = "QUIT" then leave events /* Case 1 above: 131: We receive only the string 'QUIT'. 132: This doesn't (necessarily) come from ProAction and therefore 133: doesn't refer to our GUI key. */ 134: parse var cmd event " GUIID" sentGuiKey . 135: select 136: when event = "CLOSE" then leave events /* Case 2 above: 137: The string contains "CLOSE GUIID x"; 138: we're just interested in the word CLOSE. */ 139: when event = "GADGETUP" then do /* Case 3 above: 140: The string contains "GADGETUP GUIID x GADGETID y CODE z", 141: where y is the key to the gadget which was manipulated. 142: We only care about the event if the gadget was our button. */ 143: parse var cmd junk "GADGETID " gadId " CODE " eventCode . 144: select 145: when gadId = myButtonKey then do 146: 'SETATTRS GUIID ' || myGuiKey || , 147: ' OBJECTID ' || myStringGadKey || , 148: ' TAGSTRING "STRINGA_TextVal,' || , 149: 'Gooodbye cruel ProAction World!,' || , 150: 'TAG_DONE"' 151: 'SETATTRS GUIID ' || myGuiKey || , 152: ' OBJECTID ' || myButtonKey || , 153: ' TAGSTRING "GA_Text,Arrrgh!,' || , 154: 'GA_Disabled,1,' || , 155: 'TAG_DONE"' 156: address command "Wait 3 SECS" /* Just so we get a chance 157: to see the new texts. */ 158: leave events /* Jump out of the main event handling loop 159: and clean up. */ 160: end /* do - set attributes on the gadgets */ 161: otherwise nop 162: end /* select - which gadget sent a GADGETUP? */ 163: end /* event = GADGETUP */ 164: otherwise nop 165: end /* select event */ 166: pkt = getpkt(myPortName) 167: end /* while loop for getting all waiting packets */ 168: end /* if gotMsg */ 169: end /* events loop */ 170: 171: /* Clean up and leave the program. */ 172: 'CLOSEGUIWINDOW GUIID ' || myGuiKey 173: 'DESTROYGUI GUIID ' || myGuiKey 174: 175: exit 176: