Try OpenEdge Now
skip to main content
Programming Interfaces
External Program Interfaces : System Clipboard : Single-item data transfers : Implementing single-item transfers : Copy operations
 
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. For example:
DEFINE VARIABLE lStat AS LOGICAL NO-UNDO.
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.
      lStat           = 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
      lStat = FOCUS:REPLACE-SELECTION-TEXT(CLIPBOARD:VALUE).
    ELSE
      lStat = FOCUS:INSERT-STRING(CLIPBOARD:VALUE).
  END.
  ELSE /* For FILL-IN */
    FOCUS:SCREEN-VALUE = CLIPBOARD:VALUE.
END. /* ON CHOOSE OF MENU-ITEM EM_Paste */