wxRuby Documentation Home

Wx::Clipboard

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

Object

See also

DataObject

Methods

Clipboard.new

Clipboard.open

Clipboard.open() { … }

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

Clipboard#add_data

Boolean add_data(%(arg-type)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

Clipboard#set_data

Clipboard#clear

clear()

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

Clipboard#close

close()

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

Clipboard#flush

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.

Clipboard#get_data

Boolean get_data(%(arg-type)DataObject% data)

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

Clipboard#is_opened

Boolean is_opened()

Returns true if the clipboard has been opened.

Clipboard#is_supported

Boolean is_supported(%(arg-type)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.

Clipboard#open

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).

Clipboard#set_data

Boolean set_data(%(arg-type)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

Clipboard#add_data

Clipboard#use_primary_selection

use_primary_selection(%(arg-type)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 2023-06-13 21:31:40 +0000]