home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rxdlg11.zip / loop2.cmd < prev    next >
OS/2 REXX Batch file  |  1995-03-01  |  15KB  |  436 lines

  1. /* This creates a Main Window, and numerous Child Dialogs. Then it does a
  2.    message loop, letting the user interact with any of those windows. Some
  3.    of the windows have Groups which cause RXDLG to return. Other windows have
  4.    the RESULT flag set so that the user can end by pressing ESC or ENTER. Of
  5.    course, clicking upon a CLOSE BOX always causes RXDLG to return. We check
  6.    the RXWIND variable and do some appropriate processing for that window --
  7.    namely, we just print out the returned value for that window's groups.
  8. */
  9.  
  10. /* Trap ERROR and FAILURE */
  11. SIGNAL ON ERROR
  12. SIGNAL ON FAILURE
  13.  
  14.  
  15. /* ================ Create "Main Window" =============== */
  16. /* First Group is ENTRY */
  17. RXTYPE.1 = 'ENTRY'
  18.  
  19. /* Use of a control in this group causes RXDLG to return */
  20. RXFLAGS.1 = 'END'
  21.  
  22. /* Labels for each entry, and Groupbox. Note: 3rd entry has no label */
  23. RXLABEL.1 = 'Range|Second||Fourth|All'
  24.  
  25. /* Variable name where the text "typed into" the entries is stored */
  26. RXVAL.1 = 'TEXT'
  27.  
  28. /* TotalControls, ControlsPerLine, WidthOfControls */
  29. RXINFO.1 = '4 2 45'
  30.  
  31. /* Position of Group */
  32. RXX.1 = 65
  33. RXY.1 = 70
  34.  
  35. /* The text for the 4 entries */
  36. TEXT.1 = 'Hello'
  37. TEXT.2 = 'Hi'
  38. TEXT.3 = ' '         /* A blank entry initially */
  39. TEXT.4 = 'More text'
  40.  
  41. /* Default size and position (also gives us sizing and max button) */
  42. RXWIN1 = ''
  43.  
  44. /* Specify NOCLOSE (since we'll do the closing ourselves, and also
  45.     RESULT so that RXDLG returns upon ESC or ENTER */
  46. RXDLG 1 '"Main Window"' 'RXWIN1' 'NOCLOSE|RESULT'
  47.  
  48.  
  49.  
  50.  
  51. /* =================== Create "Drop Stuff" Dialog =================== */
  52. /* First Group is DROP */
  53. RXTYPE.1 = 'DROP'
  54.  
  55. /* Default */
  56. RXFLAGS.1 = ''
  57.  
  58. /* Labels for each dropbox, and Groupbox. Note: No label for 3rd dropbox,
  59.     nor Groupbox */
  60. RXLABEL.1 = 'First | Range'
  61.  
  62. /* Stem variable names to fetch the strings for each dropbox in the group */
  63. RXVAL.1 = 'BLORT | CHOICE | LIST'
  64.  
  65. /* TotalControls, ControlsPerLine, WidthOfControls */
  66. RXINFO.1 = '3 2 100'
  67.  
  68. /* Position */
  69. RXX.1 = 65
  70. RXY.1 = 56
  71.  
  72. /* First List items */
  73. BLORT.1 = 'This is 1'
  74. BLORT.2 = 'This is 2'
  75. BLORT.3 = 'This is 3'
  76. BLORT.4 = 'This is 4'
  77. BLORT.5 = 'This is 5'
  78. BLORT.6 = 'This is 6'
  79. BLORT.7 = 'This is 7'
  80. BLORT.8 = ' '  /* Marks the end of the list */
  81.  
  82. /* Second List items */
  83. CHOICE.1 = 'OS/2'
  84. CHOICE.2 = 'Windows'  /* "Ack!", says Bill The Gates */
  85. CHOICE.3 = ' '  /* Marks the end of the list */
  86.  
  87. /* Third List items */
  88. LIST.1 = 'Bananas'
  89. LIST.2 = 'Oranges'
  90. LIST.3 = 'Grapes'
  91. LIST.4 = 'Apples'
  92. LIST.5 = ' '  /* Marks the end of the list */
  93.  
  94. RXWIN3 = '350 130 40 40'
  95. RXDLG 1 '"Drop Stuff"' 'RXWIN3' 'NOCLOSE|RESULT'
  96.  
  97.  
  98.  
  99.  
  100. /* ================= Create "Indexes" Dialog ================== */
  101. /* First Group is DROP */
  102. RXTYPE.1 = 'DROP'
  103.  
  104. /* Give me index rather than the text for the selected item. If I typed
  105.     in something, not in the droplist, then that text is returned. Also,
  106.     cause RXDLG to return when control is used */
  107. RXFLAGS.1 = 'INDEX'
  108.  
  109. /* Labels for each dropbox, and Groupbox */
  110. RXLABEL.1 = 'Type Here:|Drop Me'
  111.  
  112. /* Stem variable names to fetch the strings for each dropbox in the group */
  113. RXVAL.1 = 'BLORT'
  114.  
  115. /* TotalControls, ControlsPerLine, WidthOfControls */
  116. RXINFO.1 = '1 1 100'
  117.  
  118. /* Position */
  119. RXX.1 = 95
  120. RXY.1 = 56
  121.  
  122. /* First List items */
  123. BLORT.1 = 'This is 1'
  124. BLORT.2 = 'This is 2'
  125. BLORT.3 = 'This is 3'
  126. BLORT.4 = 'This is 4'
  127. BLORT.5 = 'This is 5'
  128. BLORT.6 = 'This is 6'
  129. BLORT.7 = 'This is 7'
  130. BLORT.8 = ' '  /* Marks the end of the list */
  131.  
  132. RXWIN4 = '220 120 84 70'
  133. RXDLG 1 '"Indexes"' 'RXWIN4'  'NOCLOSE|RESULT'
  134.  
  135.  
  136.  
  137. /* ================= Create "List 1" Dialog ================== */
  138. /* First Group is LIST */
  139. RXTYPE.1 = 'LIST'
  140.  
  141. /* Give me index # of item, rather than the text for it. Also cause RXDLG
  142.      to return */
  143. RXFLAGS.1 = 'INDEX|END'
  144.  
  145. /* Labels for each listbox, and Groupbox */
  146. RXLABEL.1 = 'Items: | Fruits: | List boxes'
  147.  
  148. /* Stem variable names to fetch the strings for each dropbox in the group */
  149. RXVAL.1 = 'BLORT|LIST'
  150.  
  151. /* TotalControls, ControlsPerLine, WidthOfControls, *AND* NumVisibleItems */
  152. RXINFO.1 = '2 1 100 4'
  153.  
  154. /* Position */
  155. RXX.1 = 10
  156. RXY.1 = 10
  157.  
  158. /* First List items */
  159. BLORT.1 = 'One'
  160. BLORT.2 = 'Two'
  161. BLORT.3 = 'Three'
  162. BLORT.4 = 'Four'
  163. BLORT.5 = 'Five'
  164. BLORT.6 = ' '  /* Marks the end of the list */
  165.  
  166. /* Second List items */
  167. LIST.1 = 'Bananas'
  168. LIST.2 = 'Oranges'
  169. LIST.3 = 'Grapes'
  170. LIST.4 = 'Apples'
  171. LIST.5 = ' '  /* Marks the end of the list */
  172.  
  173. RXWIN5 = '130 234 100 8'
  174. RXDLG 1 '"List 1"' 'RXWIN5' 'NOCLOSE|RESULT'
  175.  
  176.  
  177.  
  178.  
  179. /* ============== Create "MultiSelect Lists" dialog ================ */
  180. /* First Group is LIST */
  181. RXTYPE.1 = 'LIST'
  182.  
  183. /* Flags */
  184. RXFLAGS.1 = 'MULTIPLE|ALLNONE'
  185.  
  186. /* Labels for each listbox, and Groupbox. NOTE: No Groupbox */
  187. RXLABEL.1 = 'Items: | Fruits:'
  188.  
  189. /* Stem variable names to fetch the strings for each listbox in the group */
  190. RXVAL.1 = 'BLORT|LIST'
  191.  
  192. /* TotalControls, ControlsPerLine, WidthOfControls, *AND* NumVisibleItems */
  193. RXINFO.1 = '2 1 100 4'
  194.  
  195. /* Position */
  196. RXX.1 = 16
  197. RXY.1 = 30
  198.  
  199. /* First List items */
  200. BLORT.1 = 'One'
  201. BLORT.2 = 'Two'
  202. BLORT.3 = 'Three'
  203. BLORT.4 = 'Four'
  204. BLORT.5 = 'Five'
  205. BLORT.6 = ' '  /* Marks the end of the list */
  206.  
  207. /* Second List items */
  208. LIST.1 = 'Bananas'
  209. LIST.2 = 'Oranges'
  210. LIST.3 = 'Grapes'
  211. LIST.4 = 'Apples'
  212. LIST.5 = 'Pears'
  213. LIST.6 = 'Titties and Beer'
  214. LIST.7 = ' '  /* Marks the end of the list */
  215.  
  216. /* Second Group is RESULT */
  217. RXTYPE.2 = 'RESULT'
  218.  
  219. /* Return a 1 for OK, YES, RETRY, ENTER, etc. Return a 0 for
  220.     CANCEL, NO, IGNORE, etc. No need to set 'END' since
  221.     RESULTBUTTON group always causes RXDLG to return */
  222. RXFLAGS.2 = 'BOOL'
  223.  
  224. /* No groupbox */
  225. RXLABEL.2 = ' '
  226.  
  227. /* Give me "Ok" and "Cancel" */
  228. RXINFO.2 = '1 2'
  229.  
  230. /* RXVAL is Irrelevant for RESULTBUTTON */
  231.  
  232. /* Position */
  233. RXX.2 = 3
  234. RXY.2 = 3
  235.  
  236. RXWIN6 = '150 274 10 100'
  237. RXDLG 2 '"MultiSelect Lists"' 'RXWIN6' 'NOCLOSE|RESULT'
  238.  
  239.  
  240.  
  241.  
  242. /* ================ Create "Electric Slide" Dialog ================ */
  243. /* First Group is SLIDER */
  244. RXTYPE.1 = 'SLIDER'
  245.  
  246. /* Print out value of slider knob as it moves */
  247. RXFLAGS.1 = 'VALUE'
  248.  
  249. /* Range/Detent/Label for each slider, and Groupbox.
  250.     NOTE: First slider has no Detent (ie, 255) */
  251. RXLABEL.1 = '128 255 Range 1:| 64 0 Range 2:|Try us'
  252.  
  253. /* Initial values for slider knobs */
  254. RXVAL.1 = '64 32'
  255.  
  256. /* TotalControls, ControlsPerLine, SizeOfControl */
  257. RXINFO.1 = '2 1 142'
  258.  
  259. /* Position */
  260. RXX.1 = 80
  261. RXY.1 = 18
  262.  
  263. RXWIN7 = '280 104 80 80'
  264. RXDLG 1 '"Electric Slide"' 'RXWIN7' 'NOCLOSE|RESULT'
  265.  
  266.  
  267.  
  268. /* ============= Message loop on the dialog windows ============ */
  269. more:
  270.    /* Because we have more than 1 window open and have not specified MODAL
  271.        for the active one, the window that is active when we call RXDLG may
  272.        not be the same window that is active when RXDLG returns (ie, it may
  273.        not be the same window that causes RXDLG to return and sets all of the
  274.        RXVAL and any LIST/DROP BOX stem variables, RXID, RXSUBID, and RXWIND
  275.        variables, and the Dimensions string for that window. For this
  276.        reason, let's not specify any window title nor operation to RXDLG. This will
  277.        cause RXDLG to pick up on the window that was last active,
  278.        will interact with the user, and won't force any dialog closure (unless the
  279.        user happens to have activated a window that wasn't created with
  280.        NOCLOSE (here, all of our windows are NOCLOSE).
  281.        Note that if all of the windows are closed (including the main window),
  282.        and we don't specify a window title, this amounts to specifying a
  283.        window title that isn't open. In this case, Rexx Dialog sets an ERROR (ie,
  284.        "Can't find REXX dialog." error message), and we would branch to that
  285.        label. In fact, our way out of here is to EXIT after we detect that the
  286.        user has clicked on the main window CLOSE ICON (and we kill that
  287.        window).
  288.  */
  289.  
  290.    /* Wait on the window(s). We go to sleep while user manipulates dialogs,
  291.        until such time as the user presses ESC or ENTER, or tries to close a dialog
  292.        using its CLOSE ICON, or uses a RESULT Group or a Control within some
  293.        Group that has its END Flag set. Other things that could cause RXDLG to
  294.        return are a window timeout and if the user pressed a key in a window
  295.        with its KEYS Flag set... but we haven't utilized those features */
  296.    RXDLG  /* NOTE: No window title means "use Main Window". No operation
  297.            specified means an operation of 0 (ie, PROCESS) */
  298.  
  299.    /* RXWIND now specifies which window woke us up. (The window is still
  300.       there because we specified NOCLOSE and didn't do an Operation that
  301.       causes a window closure).
  302.      All of the RXVAL (and any LIST/DROP BOX stem) variables, RXID,
  303.      RXSUBID, and RXWIND variables (and the Dimensions string for that
  304.      window) have been setup according to the state of this window when RXDLG
  305.      returned */
  306.  
  307.    /* Did user press ESC or click on the CLOSE ICON? Note that we haven't set
  308.       the KEYS flag of any window, so we don't need to check for particular
  309.       negative values of RXID because the only 2 we ever receive here are
  310.       for the ESC key and CLOSE ICON */
  311.    IF RXID < 0 THEN DO
  312.       RXSAY '"'RXWIND'" aborted.'
  313.       IF RXWIND = 'Main Window' THEN EXIT
  314.    END
  315.  
  316.    /* If user didn't abort, then display the value strings for this window.
  317.        IMPORTANT: If he didn't abort, then he either pushed some SUCCESS (ie,
  318.        OK, RETRY, ENTER, etc) or FAILURE (ie, CANCEL, IGNORE, NO, etc)
  319.        button in a RESULT Group, or he used some Group whose 'END' Flag
  320.        we set, or he pressed the ENTER key while the window itself had the
  321.        focus, or a timeout occured if we setup that for this window, or some
  322.        key was pressed if the window had its KEYS Flag set.
  323.        If we had a RESULT Group with a FAILURE type button in the window,
  324.        and that caused RXDLG to return, normally we'd check the RXVAL of that
  325.        Group, and if an odd number, abort any operation. (For BOOL, we'd
  326.        abort on 0) */
  327.  
  328.     ELSE DO
  329.        /* =========================================== */
  330.        /* Did user press the ENTER key while the window had the focus?
  331.        Note that we haven't setup a timeout, nor set the KEYS flag
  332.        of any window, so we don't need to check RXSUBID. It's always
  333.        going to be 10 (ie, ENTER) here if RXID is 0 */
  334.        IF RXID = 0 THEN DO
  335.        RXSAY 'Pressed ENTER on "'RXWIND'".'
  336.        END
  337.  
  338.        /* Display the Group #, Control # of the control that caused RXDLG to return */
  339.        ELSE RXSAY 'Group #'RXID', Control #'RXSUBID' ended "'RXWIND'" dialog.'
  340.  
  341.        SELECT
  342.        /* =============== Indexes Dialog ================ */
  343.        WHEN RXWIND = "Indexes" THEN DO
  344.        /* Display index of chosen item in the Group's only DROPBOX */
  345.            RXSAY '"'RXWIND'" Group 1, drop index is 'BLORT.0
  346.        END
  347.  
  348.        /* ============== Drop Stuff Dialog ============== */
  349.        WHEN RXWIND = "Drop Stuff" THEN DO
  350.        /* Display the selection for each of the 3 drop boxes */
  351.            RXSAY '"'RXWIND'" Group 1, drop 1 choice is "'BLORT.0'"'
  352.            RXSAY '"'RXWIND'" Group 1, drop 2 choice is "'CHOICE.0'"'
  353.            RXSAY '"'RXWIND'" Group 1, drop 3 choice is "'LIST.0'"'
  354.        END
  355.  
  356.        /* ================= List 1 Dialog ================ */
  357.        WHEN RXWIND = "List 1" THEN DO
  358.        /* Display the selection for each of the 2 list boxes.
  359.            NOTE: This group is SINGLE SELECT */
  360.            RXSAY '"'RXWIND'" Group 1, list 1 choice is "'BLORT.0'"'
  361.            RXSAY '"'RXWIND'" Group 1, list 2 choice is "'LIST.0'"'
  362.        END
  363.  
  364.        /* ============== MultiSelect Lists Dialog ============== */
  365.        WHEN RXWIND = "MultiSelect Lists" THEN DO
  366.        /* Let's check the result button to see if user pressed OK or
  367.            CANCEL, and if CANCEL, skip displaying the list selections.
  368.            NOTE: Since the MultiSelects Lists dialog had its
  369.            RESULT Flag set, RXDLG could also have returned because
  370.            user pressed the ENTER or ESC key while the dialog had the
  371.            Focus. In that case, our RESULT value is setup to either
  372.            FAILURE or SUCCESS.  In this case, since we only have 1
  373.            SUCCESS and 1 FAILURE type of button, and we specified BOOL,
  374.            the RESULT's value will be 1 for ESC and 0 for ENTER (ie,
  375.            the same as if he chose CANCEL or OK respectively). If we setup
  376.            a timeout, that would set the RESULT's value to 0 too */
  377.            IF RXVAL.2 = 1 THEN DO
  378.            /* Display the selections for BLORT (ie, first listbox in Group 1),
  379.                one by one */
  380.            DO i = 1 TO BLORT.0
  381.                RXSAY '"'RXWIND'" Group 1, list 1, choice 'i' is "'BLORT.0.i'"'
  382.            END
  383.            /* Display the selections for LIST, (ie, second listbox in Group 1)
  384.                one by one */
  385.            DO i = 1 TO LIST.0
  386.                RXSAY '"'RXWIND'" Group 1, list 1, choice 'i' is "'LIST.0.i'"'
  387.            END
  388.            END
  389.        END
  390.  
  391.        /* ============== Electric Slide Dialog ============== */
  392.        WHEN RXWIND = "Electric Slide" THEN DO
  393.        /* Print out each slider's value */
  394.            DO i = 1 TO 2
  395.            PARSE VAR RXVAL.1 knob RXVAL.1
  396.            RXSAY '"'RXWIND'" Group 1, Slider #'i' = 'knob
  397.            END
  398.        END
  399.  
  400.        /* ================ Main Window ================= */
  401.        WHEN RXWIND = "Main Window" THEN DO
  402.        /* Display each entry's text, one entry at a time */
  403.            DO i = 1 TO 4 /* There are 4 entries in this Group */
  404.            RXSAY '"'RXWIND'" Group 1, entry #'i' is "'TEXT.i'"'
  405.            END
  406.        END
  407.  
  408.        END
  409.    END
  410.  
  411.    /* If this isn't the main window, then close this window (without
  412.        setting up any variables again, ie, Operation 4). We let the user
  413.        specifically decide when it's time to close the main window. Note
  414.        that we could eliminate this if we just made all of our child dialogs
  415.        without NOCLOSE. But don't try to close a window that was automatically
  416.        closed by Rexx Dialog, or you'll get the "Can't find Rexx Dialog" error */
  417.    IF RXWIND \= 'Main Window' & RXWIND \= '' THEN RXDLG '"'RXWIND'"' 4
  418.  
  419. /* Do another message loop */
  420. SIGNAL more
  421.  
  422. /* =================================================== */
  423.  
  424. FAILURE:
  425.     /* NOTE: the variable RC contains the returned error message (not a number,
  426.     unless we use RXERR to set up Rexx Dialog to return error numbers instead).
  427.     Because we used the default severity level, Rexx Dialog has already displayed
  428.     this error message to the enduser */
  429.     EXIT
  430. ERROR:
  431.     /* NOTE: the variable RC contains the returned error message (not a number,
  432.     unless we use RXERR to set up Rexx Dialog to return error numbers instead).
  433.     Because we used the default severity level, Rexx Dialog has already displayed
  434.     this error message to the enduser */
  435.     EXIT
  436.