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

  1. /* An example of opening several (non MODAL) windows simultaneously. It
  2.    creates a Main Window, and numerous Child Dialogs. Each window has
  3.    only 1 Group in it. That's not to say that you can't have more Groups in a
  4.    window, but just that it simplifies this example. Then it does a message
  5.    loop, letting the user choose which window to interact with. Some of the
  6.    windows have a Group which causes RXDLG to return (ie, END Flag set).
  7.    Other windows have the RESULT flag set so that the user can end by pressing
  8.    ESC or ENTER.  Of course, clicking upon a CLOSE BOX always causes RXDLG to
  9.    return. We check the RXWIND variable and do some appropriate processing for
  10.    that window -- namely, we just print out the returned value for that
  11.    window's groups.
  12. */
  13.  
  14. /* Trap ERROR and FAILURE */
  15. SIGNAL ON ERROR
  16. SIGNAL ON FAILURE
  17.  
  18.  
  19. /* ================ Create "Main Window" dialog =============== */
  20. /* First Group is ENTRY */
  21. RXTYPE.1 = 'ENTRY'
  22.  
  23. /* Use of a control in this group causes RXDLG to return */
  24. RXFLAGS.1 = 'END'
  25.  
  26. /* Labels for each entry, and Groupbox. Note: 3rd entry has no label */
  27. RXLABEL.1 = 'Range|Second||Fourth|All'
  28.  
  29. /* Variable name where the text "typed into" the entries is stored */
  30. RXVAL.1 = 'TEXT'
  31.  
  32. /* TotalControls, ControlsPerLine, WidthOfControls */
  33. RXINFO.1 = '4 2 45'
  34.  
  35. /* Position of Group */
  36. RXX.1 = 65
  37. RXY.1 = 70
  38.  
  39. /* The text for the 4 entries */
  40. TEXT.1 = 'Hello'
  41. TEXT.2 = 'Hi'
  42. TEXT.3 = ' '         /* A blank entry initially */
  43. TEXT.4 = 'More text'
  44.  
  45. /* Default size and position (also gives us sizing and max button) */
  46. RXWIN1 = ''
  47.  
  48. /* Specify NOCLOSE (since we'll do the closing ourselves, and also
  49.     RESULT so that RXDLG returns upon ESC or ENTER */
  50. RXDLG 1 '"Main Window"' 'RXWIN1' 'NOCLOSE|RESULT'
  51.  
  52.  
  53.  
  54. /* ================ Create "PushButtons"  dialog =============== */
  55. /* First Group is PUSH */
  56. RXTYPE.1 = 'PUSH'
  57.  
  58. /* Use of a control in this group causes RXDLG to return */
  59. RXFLAGS.1 = 'END'
  60.  
  61. /* Labels for each button, and Groupbox */
  62. RXLABEL.1 = 'One|Two|Three|Four|Choices'
  63.  
  64. /* TotalControls, ControlsPerLine, WidthOfControls */
  65. RXINFO.1 = '4 2 0'
  66.  
  67. /* Default choice for PushButton is nothing */
  68. RXVAL.1 = ''
  69.  
  70. /* Position */
  71. RXX.1 = 7
  72. RXY.1 = 6
  73.  
  74. RXWIN2 = '190 108 8 8'
  75. RXDLG 1 '"Pushbuttons"' 'RXWIN2' 'NOCLOSE|MIN|RESULT'
  76.  
  77.  
  78.  
  79.  
  80. /* ================== Create "Spin Me" dialog ================= */
  81. /* First Group is SPIN */
  82. RXTYPE.1 = 'SPIN'
  83.  
  84. /* Use of a control in this group causes RXDLG to return */
  85. RXFLAGS.1 = 'END'
  86.  
  87. /* Max, Min, Label for each slider, and groupbox */
  88. RXLABEL.1 = '255 0 Range 1:| 20 10 Range 2:|Try us'
  89.  
  90. /* Values for each slider */
  91. RXVAL.1 = '64 19'
  92.  
  93. /* TotalControls, ControlsPerLine, WidthOfControls */
  94. RXINFO.1 = '2 1 70'
  95.  
  96. /* Position */
  97. RXX.1 = 80
  98. RXY.1 = 18
  99.  
  100. RXWIN3 = '190 104 30 30'
  101. RXDLG 1 '"Spin Me"' 'RXWIN3' 'NOCLOSE|SIZE|RESULT'
  102.  
  103.  
  104.  
  105.  
  106. /* ================= Create "Understand?" dialog ================ */
  107. /* First Group is RESULT */
  108. RXTYPE.1 = 'RESULT'
  109.  
  110. /* Return a 1 for OK, YES, RETRY, ENTER, etc. Return a 0 for
  111.     CANCEL, NO, IGNORE, etc. No need to set 'END' since
  112.     RESULTBUTTON group always causes RXDLG to return */
  113. RXFLAGS.1 = 'BOOL'
  114.  
  115. /* No groupbox */
  116. RXLABEL.1 = ' '
  117.  
  118. /* Give me "Yes" and "No" */
  119. RXINFO.1 = '3 4'
  120.  
  121. /* Irrelevant for RESULTBUTTON */
  122. RXVAL.1 = ''
  123.  
  124. /* Position */
  125. RXX.1 = 3
  126. RXY.1 = 3
  127.  
  128. RXWIN4 = '112 60 8 50'
  129. RXDLG 1 '"Understand?"' 'RXWIN4' 'NOCLOSE|RESULT'
  130.  
  131.  
  132.  
  133.  
  134. /* ============= Message loop on the dialog windows ============ */
  135. more:
  136.    /* Because we have more than 1 window open and have not specified MODAL
  137.        for the active one, the window that is active when we call RXDLG may
  138.        not be the same window that is active when RXDLG returns (ie, it may
  139.        not be the same window that causes RXDLG to return and sets all of the
  140.        RXVAL and any LIST/DROP BOX stem variables, RXID, RXSUBID, and RXWIND
  141.        variables, and the Dimensions string for that window. For this
  142.        reason, let's not specify any window title nor operation to RXDLG. This will
  143.        cause RXDLG to pick up on the window that was last active,
  144.        will interact with the user, and won't force any dialog closure (unless the
  145.        user happens to have activated a window that wasn't created with
  146.        NOCLOSE (here, all of our windows are NOCLOSE).
  147.        Note that if all of the windows are closed (including the main window),
  148.        and we don't specify a window title, this amounts to specifying a
  149.        window title that isn't open. In this case, Rexx Dialog sets an ERROR (ie,
  150.        "Can't find REXX dialog." error message), and we would branch to that
  151.        label. In fact, our way out of here is to EXIT after we detect that the
  152.        user has clicked on the main window CLOSE ICON (and we kill that
  153.        window).
  154.  */
  155.  
  156.    /* Wait on the window(s). We go to sleep while user manipulates dialogs,
  157.        until such time as the user presses ESC or ENTER, or tries to close a dialog
  158.        using its CLOSE ICON, or uses a RESULT Group or a Control within some
  159.        Group that has its END Flag set. Other things that could cause RXDLG to
  160.        return are a window timeout and if the user pressed a key in a window
  161.        with its KEYS Flag set... but we haven't utilized those features */
  162.    RXDLG  /* NOTE: No window title means "use Main Window". No operation
  163.            specified means an operation of 0 (ie, PROCESS) */
  164.  
  165.    /* RXWIND now specifies which window woke us up. (The window is still
  166.       there because we specified NOCLOSE and didn't do an Operation that
  167.       causes a window closure).
  168.      All of the RXVAL (and any LIST/DROP BOX stem) variables, RXID,
  169.      RXSUBID, and RXWIND variables (and the Dimensions string for that
  170.      window) have been setup according to the state of this window when RXDLG
  171.      returned */
  172.  
  173.    /* Close that window (without setting up any variables again, ie,
  174.        Operation 4). NOTE: You might not want to do this without
  175.        checking RXWIND. After all, we could be closing our main window
  176.        right now. Also, you might want to continue leaving this window
  177.        open, or maybe only close it if the user pressed ESC or clicked the
  178.        CLOSE ICON or selected a CANCEL/NO/IGNORE/OFF button in a
  179.        RESULT Group. We haven't tested for those conditions yet.
  180.        Actually, what I'm doing here is EXACTLY what Rexx Dialog would
  181.        be doing if we created all of our windows without NOCLOSE, and
  182.        we could eliminate this Operation. Try it */
  183.    RXDLG '"'RXWIND'"' 4
  184.  
  185.    /* Did user press ESC or click on the CLOSE ICON? Note that we haven't set
  186.       the KEYS flag of any window, so we don't need to check for particular
  187.       negative values of RXID because the only 2 we ever receive here are
  188.       for the ESC key and CLOSE ICON */
  189.    IF RXID < 0 THEN DO
  190.       RXSAY '"'RXWIND'" aborted.'
  191.       IF RXWIND = 'Main Window' THEN EXIT
  192.    END
  193.  
  194.    ELSE DO
  195.    /* If user didn't abort, then display the value strings for this window.
  196.        IMPORTANT: If he didn't abort, then he either pushed some SUCCESS (ie,
  197.        OK, RETRY, ENTER, etc) or FAILURE (ie, CANCEL, IGNORE, NO, etc)
  198.        button in a RESULT Group, or he used some Group whose 'END' Flag
  199.        we set, or he pressed the ENTER key while the window itself had the
  200.        focus, or a timeout occured if we setup that for this window, or some
  201.        key was pressed if the window had its KEYS Flag set.
  202.        If we had a RESULT Group with a FAILURE type button in the window,
  203.        and that caused RXDLG to return, normally we'd check the RXVAL of that
  204.        Group, and if an odd number, abort any operation. (For BOOL, we'd
  205.        abort on 0) */
  206.  
  207.        /* Did user press the ENTER key while the window had the focus?
  208.        Note that we haven't setup a timeout, nor set the KEYS flag
  209.        of any window, so we don't need to check RXSUBID. It's always
  210.        going to be 10 (ie, ENTER) here if RXID is 0 */
  211.        IF RXID = 0 THEN DO
  212.        RXSAY 'Pressed ENTER on "'RXWIND'".'
  213.        END
  214.  
  215.        /* Display the Group #, Control # of the control that caused RXDLG to return */
  216.        ELSE RXSAY 'Group #'RXID', Control #'RXSUBID' ended "'RXWIND'" dialog.'
  217.  
  218.        SELECT
  219.        /* =============== Spin Me Dialog ================ */
  220.        WHEN RXWIND = "Spin Me" THEN DO
  221.        /* Display spin values for this group, one spin at a time */
  222.            DO i = 1 TO 2
  223.            PARSE VAR RXVAL.1 knob RXVAL.1
  224.            RXSAY '"'RXWIND'" Group 1, Knob #'i' = 'knob
  225.            END
  226.         END
  227.  
  228.        /* ============== Pushbuttons Dialog ============== */
  229.        WHEN RXWIND = "Pushbuttons" THEN DO
  230.        /* NOTE: RXVAL could be "" for a PUSH/CHECK/RADIO button group if
  231.            the user didn't use any buttons and we didn't initially set any
  232.            of them (ie, RXVAL was a null string when the group was
  233.            created), or if there are ALL\NONE buttons and the user
  234.            selected ALL. By setting the RXVAL for a PUSH or RADIO BUTTON
  235.            group to "" before calling RXDLG to create a window, you can determine
  236.            whether the user selected any of the buttons */
  237.            IF RXVAL.1 > '' THEN RXSAY '"'RXWIND'" Group 1, pushed button #'RXVAL.1
  238.            ELSE RXSAY '"'RXWIND'" Group 1, no button pushed.'
  239.        END
  240.  
  241.        /* ============== Understand? Dialog ============== */
  242.        WHEN RXWIND = "Understand?" THEN DO
  243.        /* See IMPORTANT above. We know that Group 1 in this dialog is a
  244.            RESULTBUTTON. Normally, we'd check the group's RXVAL, (in this
  245.            case, RXVAL.1), and if an odd number, abort any operation that
  246.            this dialog was supposed to provide us input for. Since we
  247.            asked for YES and NO buttons, and also specified BOOL result,
  248.            RXVAL will be 1 for YES and 0 for NO */
  249.            i = 'NO'
  250.            IF RXVAL.1 THEN i = 'YES'
  251.            RXSAY '"'RXWIND'" Group 1, result is 'i
  252.        END
  253.  
  254.        /* ================ Main Window ================= */
  255.        WHEN RXWIND = "Main Window" THEN DO
  256.        /* Display each entry's text, one entry at a time */
  257.            DO i = 1 TO 4 /* There are 4 entries in this Group */
  258.            RXSAY '"'RXWIND'" Group 1, entry #'i' is "'TEXT.i'"'
  259.            END
  260.  
  261.        /* NOTE: If you wanted a graceful end to the program (ie, so that
  262.            you don't get the "Can't find REXX dialog." error message),
  263.            you could do an EXIT right here. After all, we already closed
  264.            the main window (and therefore any children that were still
  265.            open), so if we try to do RXDLG again, that's when the FAILURE
  266.            occurs */
  267.            EXIT
  268.        END
  269.        END
  270.    END
  271.  
  272. /* Do another message loop */
  273. SIGNAL more
  274.  
  275. /* ========================== Done ========================== */
  276.  
  277. FAILURE:
  278.     /* NOTE: the variable RC contains the returned error message (not a number,
  279.     unless we use RXERR to set up Rexx Dialog to return error numbers instead).
  280.     Because we used the default severity level, Rexx Dialog has already displayed
  281.     this error message to the enduser */
  282.     EXIT
  283. ERROR:
  284.     /* NOTE: the variable RC contains the returned error message (not a number,
  285.     unless we use RXERR to set up Rexx Dialog to return error numbers instead).
  286.     Because we used the default severity level, Rexx Dialog has already displayed
  287.     this error message to the enduser */
  288.     EXIT
  289.