Guidance
指路人
g.yi.org
Software / Reginald / Examples / RxSet11.rex

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
/* This example creates a TREE Group with 1 Tree control, and some
 * buttons to add items to the TREE. It shows how to use RXSET()'s
 * ADD operation with a TREE.
 */

SIGNAL ON ERROR
CALL RXERR('ERROR|DISPLAY')

rx1 = ''

/* First Group is TREE */
rx1type.1 = 'TREE'

/* Default */
rx1flags.1 = 'LINES|BUTTONS|ROOTLINES|REPORT'

/* Labels for each Tree, and Groupbox */
rx1label.1 = '|'

/* Stem variable names to fetch the strings for each dropbox in the group */
rx1val.1 = 'TREE'

/* ControlsPerLine, X Position, Y Position, Width, NumVisibleItems */
rx1pos.1 = '1 10 20 150 10'

/* No Tree items (ie, initially an empty tree */
tree.1 = '' /* Marks the end of the parent items for the tree */

/* No initial selection */
tree.0 = ''

/* Use a TEXT Group to display the currently selected item's position */
rx1type.2 = 'TEXT'

/* Default */
rx1flags.2 = 'NOBORDER'

/* Text line */
rx1label.2 = '|'

/* PhrasesPerLine, X Position, Y Position, WidthOfPhrase, BetweenPhrases=0 */
rx1pos.2 = '1 8 1 250'

/* Add some buttons to add items to the TREE */
rx1type.3 = 'PUSH'

/* Default */
rx1flags.3 = 'REPORT'

/* Button labels */
rx1label.3 = 'Add Root|Add item|Edit Label|'

/* ControlsPerLine, X Position, Y Position, Width=0 */
rx1pos.3 = '1 170 20 0'

/* Create 'Trees' window */
CALL RXCREATE('Rx1', 3, 'RXSET() ADD - TREE', 'NOCLOSE')

DO FOREVER

   /* Do user interaction until he closes the windows */
   CALL RXMSG()

   /* Let's check if the user clicked the CLOSE BOX, RXID will be an
    * empty string.
    */
   IF rxid == '' THEN EXIT

   /* Did he select an item in the tree? If so, display its position */
   IF rxid == 1 THEN CALL RXSET(, 'VALUE', tree.0, 2, 1)

   /* Did he click on the "Add Root" button. If so, add another root item */
   IF rxid == 3 & rxsubid == 1 THEN DO

      /* Present a window with an ENTRY to get his label for the item */
      line = getlabel('Enter label')
      IF line \== '' THEN CALL RXSET(, 'ADD', line || '|-1', 1, 1)

      /* Query what position it got added at by querying current selection (ie, adding an item selects it) */
      CALL RXQUERY(, 'VALUE', 'position', 1, 1)

      /* Display selection */
      CALL RXSET(, 'VALUE', position.0, 2, 1)

   END

   /* Did he click on the "Add Item" button. If so, add another item under the currently selected item */
   IF rxid == 3 & rxsubid == 2 THEN DO

      /* Get the currently selected item's position */
      CALL RXQUERY(, 'VALUE', 'position', 1, 1)

      /* Is some item selected? */
      IF position.0 \== '' THEN DO

         /* Add an item under it, at the end */
         line = getlabel('Enter label')
         IF line \== '' THEN CALL RXSET(, 'ADD', line || '|' || position.0 || '.-1', 1, 1)

         /* Query what position it got added at by querying current selection (ie, adding an item selects it) */
         CALL RXQUERY(, 'VALUE', 'position', 1, 1)

         /* Display selection */
         CALL RXSET(, 'VALUE', position.0, 2, 1)

      END

   END

   /* Did he click on the "Edit Label" button. If so, change the currently selected item's label */
   IF rxid == 3 & rxsubid == 3 THEN DO

      /* Get the currently selected item's position */
      CALL RXQUERY(, 'VALUE', 'position', 1, 1)

      /* Is some item selected? */
      IF position.0 \== '' THEN DO

         /* Get a new label and set it */
         line = getlabel('Enter label')
         IF line \== '' THEN CALL RXSET(, 'ADD', line || '|' || position.0, 1, 1)

      END

   END



END

/* ==================== Error Handling ====================== */
syntax:
    CALL RXSAY(CONDITION('D') || '0D0A0D0A'x || SOURCELINE(sigl),,'Error '||condition('E')||' at line '||sigl)

halt:
error:
    /* NOTE: CONDITION('D') fetches error message. CONDITION('E') fetches the
     * error number. SIGL is the line number where the error occurred.
     * Rexx Dialog has already displayed a message since we specified DISPLAY
     * option.
     */
    CALL RXMSG(,'END')
    EXIT



/* ========================================================== */
/* Subroutine to get a label for an item */
getlabel:
rxl = ''
rxltype.1 = 'ENTRY'
rxllabel.1 = '|'
IF ARG() \= 0 THEN rxllabel.1 = ARG(1) || ':|'
rxlpos.1 = '1 8 8 80'
rxlflags.1 = 'REPORT' /* As soon as he presses ENTER, we accept his line */
rxlval.1 = 'TEXT'
text.1 = ''  /* Initially, an empty line */

/* Create the window without NOCLOSE, so that as soon as
 * he presses ENTER, the window closes.
 */
CALL RXCREATE('RXL', 1, rxllabel.1)

/* Do interaction */
CALL RXMSG()

/* Return the entered line */
RETURN text.1
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Thu 2024-4-18  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2013-06-18 23:35:18