| Maintainer | gtk2hs-users@lists.sourceforge.net |
|---|---|
| Stability | provisional |
| Portability | portable (depends on GHC) |
| Safe Haskell | None |
| Language | Haskell98 |
Graphics.UI.Gtk.General.Clipboard
Description
Storing data on clipboards
- data Clipboard
- class GObjectClass o => ClipboardClass o
- castToClipboard :: GObjectClass obj => obj -> Clipboard
- gTypeClipboard :: GType
- toClipboard :: ClipboardClass o => o -> Clipboard
- selectionPrimary :: SelectionTag
- selectionSecondary :: SelectionTag
- selectionClipboard :: SelectionTag
- clipboardGet :: SelectionTag -> IO Clipboard
- clipboardGetForDisplay :: Display -> SelectionTag -> IO Clipboard
- clipboardGetDisplay :: ClipboardClass self => self -> IO Display
- clipboardSetWithData :: ClipboardClass self => self -> [(TargetTag, InfoId)] -> (InfoId -> SelectionDataM ()) -> IO () -> IO Bool
- clipboardSetText :: (ClipboardClass self, GlibString string) => self -> string -> IO ()
- clipboardSetImage :: ClipboardClass self => self -> Pixbuf -> IO ()
- clipboardRequestContents :: ClipboardClass self => self -> TargetTag -> SelectionDataM () -> IO ()
- clipboardRequestText :: (ClipboardClass self, GlibString string) => self -> (Maybe string -> IO ()) -> IO ()
- clipboardRequestImage :: ClipboardClass self => self -> (Maybe Pixbuf -> IO ()) -> IO ()
- clipboardRequestTargets :: ClipboardClass self => self -> (Maybe [TargetTag] -> IO ()) -> IO ()
- clipboardRequestRichText :: (ClipboardClass self, TextBufferClass buffer, GlibString string) => self -> buffer -> (Maybe (TargetTag, string) -> IO ()) -> IO ()
- clipboardSetCanStore :: ClipboardClass self => self -> Maybe [(TargetTag, InfoId)] -> IO ()
- clipboardStore :: ClipboardClass self => self -> IO ()
Detail
The Clipboard object represents a clipboard of data shared between different processes or between different widgets in the same process. Each clipboard is identified by a SelectionTag which itself is an Atom. The default clipboard corresponds to the selectionClipboard tag; another commonly used clipboard is the selectionPrimary tag, which, in X, traditionally contains the currently selected text.
To support having a number of different formats on the clipboard at the same time, the clipboard mechanism allows providing callbacks instead of the actual data. When you set the contents of the clipboard, you can either supply the data directly (via functions like clipboardSetText), or you can supply a callback to be called at a later time when the data is needed (via clipboardSetWithData). Providing a callback also avoids having to make copies of the data when it is not needed.
Setting clipboard data is done using clipboardSetWithData and clipboardSetWithOwner. Both functions are quite similar; the choice between the two depends mostly on which is more convenient in a particular situation. The former is most useful when you want to have a blob of data with callbacks to convert it into the various data types that you advertise. When the clearFunc you provided is called, you simply free the data blob. The latter is more useful when the contents of clipboard reflect the internal state of a GObject (As an example, for the selectionPrimary clipboard, when an entry widget provides the clipboard's contents the contents are simply the text within the selected region.) If the contents change, the entry widget can call clipboardSetWithOwner to update the timestamp for clipboard ownership, without having to worry about clearFunc being called.
Requesting the data from the clipboard is essentially asynchronous. If the contents of the clipboard are provided within the same process, then a direct function call will be made to retrieve the data, but if they are provided by another process, then the data needs to be retrieved from the other process, which may take some time. To avoid blocking the user interface, the call to request the selection, clipboardRequestContents takes a callback that will be called when the contents are received (or when the request fails.) If you don't want to deal with providing a separate callback, you can also use clipboardWaitForContents. What this does is run the GLib main loop recursively waiting for the contents. This can simplify the code flow, but you still have to be aware that other callbacks in your program can be called while this recursive mainloop is running.
Along with the functions to get the clipboard contents as an arbitrary data chunk, there are also functions to retrieve it as text, clipboardRequestText and clipboardWaitForText. These functions take care of determining which formats are advertised by the clipboard provider, asking for the clipboard in the best available format and converting the its content.
Class Hierarchy
| GObject | +----Clipboard Types
class GObjectClass o => ClipboardClass o Source
Instances
castToClipboard :: GObjectClass obj => obj -> Clipboard Source
toClipboard :: ClipboardClass o => o -> Clipboard Source
Constants
selectionPrimary :: SelectionTag Source
The primary selection (the currently highlighted text in X11 that can in many applications be pasted using the middle button).
selectionSecondary :: SelectionTag Source
The secondary selection. Rarely used.
selectionClipboard :: SelectionTag Source
The modern clipboard that is filled by copy or cut commands.
Methods
Arguments
| :: SelectionTag |
|
| -> IO Clipboard | returns the appropriate clipboard object. If no clipboard already exists, a new one will be created. Once a clipboard object has been created, it is persistent. |
Returns the clipboard object for the given selection. See clipboardGetForDisplay for complete details.
Arguments
| :: Display |
|
| -> SelectionTag |
|
| -> IO Clipboard | returns the appropriate clipboard object. If no clipboard already exists, a new one will be created. Once a clipboard object has been created, it is persistent. |
Returns the clipboard object for the given selection. Cut/copy/paste menu items and keyboard shortcuts should use the default clipboard, returned by passing selectionClipboard for selection. The currently-selected object or text should be provided on the clipboard identified by selectionPrimary. Cut/copy/paste menu items conceptually copy the contents of the selectionPrimary clipboard to the default clipboard, i.e. they copy the selection to what the user sees as the clipboard.
See <http: discussion of the selectionClipboard vs. selectionPrimary selections under the X window system. On Win32 the selectionPrimary clipboard is essentially ignored.
It's possible to have arbitrary named clipboards; if you do invent new clipboards, you should prefix the selection name with an underscore (because the ICCCM requires that nonstandard atoms are underscore-prefixed), and namespace it as well. For example, if your application called "Foo" has a special-purpose clipboard, you could create it using atomNew "_FOO_SPECIAL_CLIPBOARD".
- Available since Gtk+ version 2.2
Arguments
| :: ClipboardClass self | |
| => self | |
| -> IO Display | returns the |
Gets the Display associated with clipboard
- Available since Gtk+ version 2.2
Arguments
| :: ClipboardClass self | |
| => self | |
| -> [(TargetTag, InfoId)] |
|
| -> (InfoId -> SelectionDataM ()) |
|
| -> IO () |
|
| -> IO Bool | returns |
Virtually sets the contents of the specified clipboard by providing a list of supported formats for the clipboard data and a function to call to get the actual data when it is requested.
Arguments
| :: (ClipboardClass self, GlibString string) | |
| => self | |
| -> string |
|
| -> IO () |
Sets the contents of the clipboard to the given UTF-8 string. Gtk+ will make a copy of the text and take responsibility for responding for requests for the text, and for converting the text into the requested format.
Arguments
| :: ClipboardClass self | |
| => self | |
| -> Pixbuf |
|
| -> IO () |
Sets the contents of the clipboard to the given Pixbuf. Gtk+ will take responsibility for responding for requests for the image, and for converting the image into the requested format.
- Available since Gtk+ version 2.6
clipboardRequestContents Source
Arguments
| :: ClipboardClass self | |
| => self | |
| -> TargetTag |
|
| -> SelectionDataM () |
|
| -> IO () |
Requests the contents of clipboard as the given target. When the results of the result are later received the supplied callback will be called.
Arguments
| :: (ClipboardClass self, GlibString string) | |
| => self | |
| -> (Maybe string -> IO ()) |
|
| -> IO () |
Requests the contents of the clipboard as text. When the text is later received, it will be converted if it is stored in a different character set if necessary, and callback will be called.
The text parameter to callback will contain the resulting text if the request succeeded, or Nothing if it failed. This could happen for various reasons, in particular if the clipboard was empty or if the contents of the clipboard could not be converted into text form.
Arguments
| :: ClipboardClass self | |
| => self | |
| -> (Maybe Pixbuf -> IO ()) |
|
| -> IO () |
Requests the contents of the clipboard as image. When the image is later received, it will be converted to a Pixbuf, and callback will be called.
The pixbuf parameter to callback will contain the resulting Pixbuf if the request succeeded, or Nothing if it failed. This could happen for various reasons, in particular if the clipboard was empty or if the contents of the clipboard could not be converted into an image.
- Available since Gtk+ version 2.6
clipboardRequestTargets Source
Arguments
| :: ClipboardClass self | |
| => self | |
| -> (Maybe [TargetTag] -> IO ()) |
|
| -> IO () |
Requests the contents of the clipboard as list of supported targets. When the list is later received, callback will be called.
The targets parameter to callback will contain the resulting targets if the request succeeded, or Nothing if it failed.
- Available since Gtk+ version 2.4
clipboardRequestRichText Source
Arguments
| :: (ClipboardClass self, TextBufferClass buffer, GlibString string) | |
| => self | |
| -> buffer |
|
| -> (Maybe (TargetTag, string) -> IO ()) |
|
| -> IO () |
Requests the contents of the clipboard as rich text. When the rich text is later received, callback will be called.
The text parameter to callback will contain the resulting rich text if the request succeeded, or Nothing if it failed. This function can fail for various reasons, in particular if the clipboard was empty or if the contents of the clipboard could not be converted into rich text form.
- Available since Gtk+ version 2.10
Arguments
| :: ClipboardClass self | |
| => self | |
| -> Maybe [(TargetTag, InfoId)] |
|
| -> IO () |
Hints that the clipboard data should be stored somewhere when the application exits or when clipboardStore is called.
This value is reset when the clipboard owner changes. Where the clipboard data is stored is platform dependent, see displayStoreClipboard for more information.
- Available since Gtk+ version 2.6
clipboardStore :: ClipboardClass self => self -> IO () Source
Stores the current clipboard data somewhere so that it will stay around after the application has quit.
- Available since Gtk+ version 2.6