Release 10.1A: OpenEdge Development:
Programming Interfaces

> ## Implementing single-item transfers

> You can implement each clipboard operation based on the type of widget that currently has the input focus (`FOCUS:TYPE`) and the state of its text selection and other attributes. For example, you can decide whether to copy all or part of an editor widget value by the values of the `SELECTION-START` and `SELECTION-END` attributes. You typically implement each clipboard operation in the trigger block of the `CHOOSE` event for the corresponding Edit menu option. In this way, the user can only perform a clipboard operation associated with an Edit menu option that is enabled.

> The following code example implements the clipboard operations enabled by the code example in the previous section. Note that for editor widgets (`FOCUS:TYPE = "EDITOR"`), if the user has text selected, the procedure transfers data between the clipboard and the `SELECTION-TEXT` rather than the `VALUE` attribute itself.

> ##### Paste operations

> For example, the paste operation (`ON CHOOSE OF MENU-ITEM EM_Paste`) replaces only the selected text (rather than the whole text) in an editor widget with the data in the clipboard. (In a fill-in widget, paste operations always replace all data in the widget.)

> ##### Cut operations

> For cut operations (`ON CHOOSE OF MENU-ITEM EM_Cut`), the procedure sets the appropriate widget attribute (`SELECTION-TEXT` or `VALUE`) to the empty string after transferring the data to the clipboard. The corresponding text disappears from the display as the Cut operation completes.

> ##### Copy operations

> Copy operations (`ON CHOOSE OF MENU-ITEM EM_Copy`) are similar to cut operations except that they leave the `FOCUS` data unchanged. However, if the data to be copied is a radio set, the example assumes that the character value of the radio set label visible on the display (`FOCUS:LABEL`) is what the user wants to copy rather than its value (`FOCUS:VALUE`). This is a useful implementation where the radio set represents an integer and the `FOCUS:VALUE` attribute contains a right-justified integer string:

>     DEFINE VARIABLE Stat AS LOGICAL.
>     DEFINE MENU EditMenu
>         MENU-ITEM EM_Cut       LABEL "&Cut "
>         MENU-ITEM EM_Copy      LABEL "C&opy "
>         MENU-ITEM EM_Paste     LABEL "&Paste ".

>     ON CHOOSE OF MENU-ITEM EM_Cut IN MENU EditMenu DO:
>         IF FOCUS:TYPE = "EDITOR" THEN DO:
>             IF FOCUS:SELECTION-START <> FOCUS:SELECTION-END THEN DO:
>                 CLIPBOARD:VALUE = FOCUS:SELECTION-TEXT.
>                 Stat = FOCUS:REPLACE-SELECTION-TEXT("").
>             END.
>             ELSE DO:
>                 CLIPBOARD:VALUE = FOCUS:SCREEN-VALUE.
>                 FOCUS:SCREEN-VALUE = "".
>             END.
>         END.
>         ELSE DO: /* For FILL-IN */
>             CLIPBOARD:VALUE = FOCUS:SCREEN-VALUE.
>             FOCUS:SCREEN-VALUE = "".
>         END.
>     END. /* ON CHOOSE OF MENU-ITEM EM_Cut */
>     ON CHOOSE OF MENU-ITEM EM_Copy IN MENU EditMenu DO:
>         IF FOCUS:TYPE = "EDITOR" THEN
>             IF FOCUS:SELECTION-START <> FOCUS:SELECTION-END THEN
>                 CLIPBOARD:VALUE = FOCUS:SELECTION-TEXT.
>             ELSE
>                 CLIPBOARD:VALUE = FOCUS:SCREEN-VALUE.
>         ELSE IF FOCUS:TYPE = "RADIO-SET" THEN
>             CLIPBOARD:VALUE = ENTRY(LOOKUP(FOCUS:SCREEN-VALUE,
>                                            FOCUS:RADIO-BUTTONS) - 1,
>                                     FOCUS:RADIO-BUTTONS).
>         ELSE IF FOCUS:TYPE = "TOGGLE-BOX" THEN
>             IF FOCUS:SCREEN-VALUE = "yes" THEN
>                 CLIPBOARD:VALUE = FOCUS:LABEL + " selected.".
>             ELSE
>                 CLIPBOARD:VALUE = FOCUS:LABEL + " not selected.".
>         ELSE /* For FILL-IN */
>             CLIPBOARD:VALUE = FOCUS:SCREEN-VALUE.
>     END. /* ON CHOOSE OF MENU-ITEM EM_Copy */
>     ON CHOOSE OF MENU-ITEM EM_Paste IN MENU EditMenu DO:
>         IF FOCUS:TYPE = "EDITOR" THEN DO:
>             IF FOCUS:SELECTION-START <> FOCUS:SELECTION-END THEN
>                 Stat = FOCUS:REPLACE-SELECTION-TEXT(CLIPBOARD:VALUE).
>             ELSE
>                 Stat = FOCUS:INSERT-STRING(CLIPBOARD:VALUE).
>         END.
>         ELSE /* For FILL-IN */
>             FOCUS:SCREEN-VALUE = CLIPBOARD:VALUE.
>     END. /* ON CHOOSE OF MENU-ITEM EM_Paste */

Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095