Generic Function | Package: cg | ToC | DocOverview | CGDoc | RelNotes | FAQ | Index | PermutedIndex
| Allegro CL version 10.1 Unrevised from 10.0 to 10.1. 10.0 version

## copy-command

Arguments: window-or-widget

Retrieves an object from the specified window or widget and places it onto the clipboard. Returns the object that was copied and its clipboard format as two values, or the single value `nil` if no copy was done.

This is largely a convenience function that combines other exported functionality as it is typically used. An application menu command could call this function directly.

window-or-widget should an instance of the `basic-pane`, `dialog-item` or `screen` class or one of their subclasses.

The default copy-command and cut-command methods are shown below, in case you need to use some variation of this typical behavior. These methods first pass the action down to the bottom-most selected-window of the window that was passed in. Then they call either copy-selection or cut-selection to retrieve the object from the window or widget, and then call push-lisp-clipboard to add the object to the lisp clipboard (a stack of arbitrary lisp objects) as well as the system-wide clipboard of the underlying window system.

    (defmethod copy-command ((stream cg-stream))
      (let* ((child (selected-window stream)))
        (if* child
           then (copy-command child)
           else (copy-or-cut-command stream nil))))

    (defmethod cut-command ((stream cg-stream))
      (let* ((child (selected-window stream)))
        (if* child
           then (cut-command child)
           else (copy-or-cut-command stream t))))

    (defun copy-or-cut-command (stream cut?)
      (setq stream (or (dialog-item stream) stream))
      (let* ((object (if cut?
                         (cut-selection stream)
                       (copy-selection stream))))
        (and object
             (let* ((format (clipboard-format-from-object object)))
               (with-object-locale (stream)
                 (push-lisp-clipboard format object))
               (values object format)))))

There are also methods on `dialog-item` that simply pass the action to the widget's window when the widget is on a parent window.

A subtle point about the above code: The function dialog-item is called on the window so that cut-selection or copy-selection is called on a widget before being called on its associated window. This allows an application to specialize added methods on a `dialog-item` subclass rather than on a `widget-window` subclass, which would require subclassing both classes and linking them with a widget-device method.

Also, clipboard-format-from-object is called to find the appropriate format for the copied object on the underlying windowing system's clipboard.

The call to with-object-locale would be needed only in unusual cases where an application uses different locales in different widgets.

See cg-clipboard.htm.

Copyright (c) 1998-2022, Franz Inc. Lafayette, CA., USA. All rights reserved.
This page was not revised from the 10.0 page.
Created 2019.8.20.

|  | ToC | DocOverview | CGDoc | RelNotes | FAQ | Index | PermutedIndex
| Allegro CL version 10.1 Unrevised from 10.0 to 10.1. 10.0 version