ruby-****@sourc*****
ruby-****@sourc*****
2003年 9月 22日 (月) 11:41:35 JST
------------------------- REMOTE_ADDR = 61.204.181.66 REMOTE_HOST = URL = http://ruby-gnome2.sourceforge.jp/?Gtk%3A%3AClipboard ------------------------- = class Gtk::Clipboard - The Gtk::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 name encoded as a Gdk::Atom. (Conversion to and from strings can be done with Gdk::Atom#intern and Gtk::Atom#name.) The default clipboard corresponds to the "CLIPBOARD" atom; another commonly used clipboard is the "PRIMARY" clipboard, which, in X, traditionally contains the currently selected text. + The Gtk::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 name encoded as a Gdk::Atom. (Conversion to and from strings can be done with Gdk::Atom#intern and Gdk::Atom#name.) The default clipboard corresponds to the "CLIPBOARD" atom; another commonly used clipboard is the "PRIMARY" clipboard, 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 methods like Gtk::Clipboard#set_text), or you can supply a callback to be called at a later time when the data is needed (via Gtk::Clipboard#set_with_data) Providing a callback also avoids having to make copies of the data when it is not needed. Requesting the data from the clipboard is essentially asynchronous. If the contents of the clipboard are provided within the same process, then a direct method 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, Gtk::Clipboard#request_contents 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 Gtk::Clipboard#wait_for_contents(). 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 methods to get the clipboard contents as an arbitrary data chunk, there are also methods to retrieve it as text, Gtk::Clipboard#request_text and Gtk::Clipboard#wait_for_text. These methods take care of determining which formats are advertised by the clipboard provider, asking for the clipboard in the best available format and converting the results into the UTF-8 encoding. (The standard form for representing strings in GTK+.) == Object Hierarchy * Object * GLib::Instantiatable * GLib::Object * Gtk::Clipboard == Class Methods --- Gtk::Clipboard.new(selection) Returns the clipboard object for the given selection. * selection : a Gdk::Atom which identifies the clipboard to use. * 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 for all time and cannot be freed. * Returns: self --- Gtk::Clipboard.new(display, selection) Cut/copy/paste menu items and keyboard shortcuts should use the default clipboard, returned by passing Gdk::Selection::CLIPBOARD for selection. The currently-selected object or text should be provided on the clipboard identified by Gdk::Selection::PRIMARY. Cut/copy/paste menu items conceptually copy the contents of the Gdk::Selection::PRIMARY clipboard to the default clipboard, i.e. they copy the selection to what the user sees as the clipboard. (See http://www.freedesktop.org/standards/clipboards.txt for a detailed discussion of the "CLIPBOARD" vs. "PRIMARY" selections under the X window system. On Win32 the Gdk::Selection::PRIMARY 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 might call it "_FOO_SPECIAL_CLIPBOARD". ((* Since 2.2 *)) * display: the display for which the clipboard is to be retrieved or created * selection: a Gdk::Atom which identifies the clipboard to use. * 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 for all time and cannot be freed. == Instance Methods --- display Gets the Gdk::Display associated with clipboard. ((* Since 2.2 *)) * Returns: the Gdk::Display associated with clipboard --- set(targets){|clipboard, selection_data| ... } Virtually sets the contents of the specified clipboard by providing a list of supported formats for the clipboard data. * targets: [[target1, flags1, info1], [target2, flags2, info2]]: an array containing information about the available forms for the clipboard data * target: the drag type (String) * flags: ((<GtkTargetFlags|Gtk::Drag#GtkTargetFlags>)) * info: an application assigned integer ID. * { |clipboard, selection_data| ... }: A block that will be called to provide the contents of the selection. If multiple types of data were advertised, the requested type can be determined from the info parameter or by checking the target field of selection_data. If the data could successfully be converted into then it should be stored into the selection_data object by calling Gtk::Selection#set (or related functions such as Gtk::Selection#text=). If no data is set, the requestor will be informed that the attempt to get the data failed. * clipboard: the Gtk::Clipboard * selection_data: a Gtk::SelectionData argument in which the requested data should be stored. * info: the info field corresponding to the requested target from the target array passed to Gtk::Clipboard#set. * Returns: true if setting the clipboard data succeeded. If setting the clipboard data failed the provided callback functions will be ignored. --- clear Clears the contents of the clipboard. * Returns: self --- text=(text) 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. * text: a UTF-8 string. * Returns: text --- set_text(text) Same as text=. * text: a UTF-8 string. * Returns: self --- request_contents(target){|clipboard, selection_data| ... } Requests the contents of clipboard as the given target. When the results of the result are later received the supplied callback will be called. * target: an Gdk::Atom representing the form into which the clipboard owner should convert the selection. * {|clipboard, selection_data| ... }: A block to call when the results are received (or the retrieval fails). If the retrieval fails the length field of selection_data will be negative. * clipboard: the Gtk::Clipboard * selection_data: a Gtk::SelectionData argument in which the requested data should be stored. * Returns: self --- request_text{|clipboard, text| ... } Requests the contents of the clipboard as text. When the text is later received, it will be converted to UTF-8 if necessary, and callback will be called. The text parameter to callback will contain the resulting text if the request succeeded, or nil 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. * {|clipboard, text| ... }: a block to call when the text is received, or the retrieval fails. (It will always be called one way or the other.) * clipboard: the Gtk::Clipboard * text: the text received, as a UTF-8 encoded string, or nil if retrieving the data failed. * Returns: self --- wait_for_contents(target) Requests the contents of the clipboard using the given target. This method waits for the data to be received using the main loop, so events, timeouts, etc, may be dispatched during the wait. * target: an Gdk::Atom representing the form into which the clipboard owner should convert the selection. * Returns: a new Gtk::SelectionData object or nil if retrieving the given target failed. --- wait_for_text Requests the contents of the clipboard as text and converts the result to UTF-8 if necessary. This method waits for the data to be received using the main loop, so events, timeouts, etc, may be dispatched during the wait. * Returns : a new UTF-8 string, or nil if retrieving the selection data 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.) --- wait_is_text_available? Test to see if there is text available to be pasted This is done by requesting the TARGETS atom and checking if it contains any of the names: STRING, TEXT, COMPOUND_TEXT, UTF8_STRING. This method waits for the data to be received using the main loop, so events, timeouts, etc, may be dispatched during the wait. * This method is a little faster than calling Gtk::Clipboard#wait_for_text since it doesn't need to retrieve the actual text. * Returns: true is there is text available, false otherwise. == See Also Gtk::Selection Gtk::Clipboard provides a high-level wrapper around the lower level routines that deal with X selections. It is also possibly to directly manipulate the X selections, though it is seldom necessary to do so. - ((<Masao>))