wxRuby Documentation Home


A class for manipulating the clipboard.

Call Clipboard#open to get ownership of the clipboard. The resulting block will be passed a Wx::Clipboard, and you now own the clipboard. Call Clipboard#set_data to put data on the clipboard, or Clipboard#get_data to retrieve data from the clipboard.

You should keep the clipboard open only momentarily. It is strongly recommended that you use the block form of Clipboard::open as this will ensure the clipboard is closed in a timely fashion.

For example:

  1. Write some text to the clipboard Wx::Clipboard.open do | clip | clip.data = Wx::TextDataObject.new(“Some text”) end
  1. Read some text Wx::Clipboard.open do | clip | if clip.supported?( Wx::DF_TEXT ) txt = Wx::TextDataObject.new clip.get_data(txt) message_box(txt.text) end end

Derived from


See also





Clipboard.open() { ... }

Opens the clipboard and passes it to the enclosed block. Ensures that the clipboard is closed when the block is ended.


Boolean add_data(DataObject data)

Call this function to add the data object to the clipboard. You may call this function repeatedly after having cleared the clipboard using Clipboard#clear.

After this function has been called, the clipboard owns the data, so do not delete the data explicitly.

See also




Clears the global clipboard object and the system’s clipboard if possible.



Call this function to close the clipboard, having opened it with Clipboard#open.


Boolean flush()

Flushes the clipboard: this means that the data which is currently on clipboard will stay available even after the application exits (possibly eating memory), otherwise the clipboard will be emptied on exit. Returns false if the operation is unsuccessful for any reason.


Boolean get_data(DataObject data)

Call this function to fill data with data on the clipboard, if available in the required format. Returns true on success.


Boolean is_opened()

Returns true if the clipboard has been opened.


Boolean is_supported(DataFormat format)

Returns true if there is data which matches the data format of the given data object currently available (IsSupported sounds like a misnomer, FIXME: better deprecate this name?) on the clipboard.


Boolean open()

Call this function to open the clipboard before calling Clipboard#set_data and Clipboard#get_data.

Call Clipboard#close when you have finished with the clipboard. You should keep the clipboard open for only a very short time.

Returns true on success. This should be tested (as in the sample shown above).


Boolean set_data(DataObject data)

Call this function to set the data object to the clipboard. This function will clear all previous contents in the clipboard, so calling it several times does not make any sense.

After this function has been called, the clipboard owns the data, so do not delete the data explicitly.

See also



use_primary_selection(Boolean primary = true)

On platforms supporting it (currently only GTK), selects the so called PRIMARY SELECTION as the clipboard as opposed to the normal clipboard, if primary is true.

[This page automatically generated from the Textile source at Wed Sep 09 02:21:02 +0100 2009]