Class: Wx::Clipboard

Inherits:
Object show all
Defined in:
lib/wx/doc/gen/clipboard.rb,
lib/wx/doc/clipboard.rb

Overview

Note:

This class is untracked and should not be derived from nor instances extended!

A class for manipulating the clipboard.

To use the clipboard, you call member functions of the global Clipboard object passed to the block for Clipboard.open. See the DataObject Overview for further information. Call Clipboard.open to get ownership of the (global) clipboard and execute the given block. You now own the clipboard passed to the given block. Call #set_data to put data on the clipboard, or #get_data to retrieve data from the clipboard. The clipboard is closed and ownership relinquished when the block returns. You should keep the clipboard open only momentarily. For example:

# Write some text to the clipboard
  Wx::Clipboard.open do |clip|
    # This data object is held by the clipboard
    clip.place(Wx::TextDataObject.new("Some text"))
    # or alternatively
    # clip.set_data(Wx::TextDataObject.new("Some text"))
  end

  # Read some text
  data = Wx::TextDataObject.new
  Wx::Clipboard.open do |clip|
     if clip.supported?(Wx::DF_TEXT)
       clip.fetch(data) # or clip.get_data(data)
     end
  end
  Wx.message_box(data.get_text)

On GTK, the clipboard behavior can vary depending on the configuration of the end-user’s machine. In order for the clipboard data to persist after the window closes, a clipboard manager must be installed. Some clipboard managers will automatically flush the clipboard after each new piece of data is added, while others will not. The #flush function will force the clipboard manager to flush the data.

Category: Clipboard and Drag & Drop

See Also:

Requires:

  • USE_CLIPBOARD

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Object

#clone, #dup, #is_same_as, #un_share

Constructor Details

#initializeWx::Clipboard

Default constructor.



53
# File 'lib/wx/doc/gen/clipboard.rb', line 53

def initialize; end

Class Method Details

.getWx::Clipboard

Returns the global instance (TheClipboard) of the clipboard object.

Returns:



139
# File 'lib/wx/doc/gen/clipboard.rb', line 139

def self.get; end

.open {|clip| ... } ⇒ ::Object

Opens the global clipboard and passes the clipboard object to the block.

Yield Parameters:

Returns:

  • (::Object)

    block result



18
# File 'lib/wx/doc/clipboard.rb', line 18

def self.open; end

Instance Method Details

#add_data(data) ⇒ Boolean

Call this function to add the data object to the clipboard.

This is an obsolete synonym for #set_data.

Parameters:

Returns:

  • (Boolean)


60
# File 'lib/wx/doc/gen/clipboard.rb', line 60

def add_data(data) end

#clearvoid

This method returns an undefined value.

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



64
# File 'lib/wx/doc/gen/clipboard.rb', line 64

def clear; end

#closevoid

This method returns an undefined value.

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



68
# File 'lib/wx/doc/gen/clipboard.rb', line 68

def close; end

#fetchObject



13
# File 'lib/wx/doc/clipboard.rb', line 13

alias :fetch :get_data

#flushBoolean

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.

Currently this method is implemented in MSW and GTK and always returns false otherwise.

Note:

On GTK, only the non-primary selection can be flushed. Calling this function when the clipboard is using the primary selection will return false and not make any data available after the program exits.

false if the operation is unsuccessful for any reason.

Returns:

  • (Boolean)


82
# File 'lib/wx/doc/gen/clipboard.rb', line 82

def flush; end

#get_data(data) ⇒ Boolean Also known as: data

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

Returns true on success.

Parameters:

Returns:

  • (Boolean)


89
# File 'lib/wx/doc/gen/clipboard.rb', line 89

def get_data(data) end

#is_openedBoolean Also known as: opened?

Returns true if the clipboard has been opened.

Returns:

  • (Boolean)


94
# File 'lib/wx/doc/gen/clipboard.rb', line 94

def is_opened; end

#is_supported(format) ⇒ Boolean Also known as: supported?

Returns true if there is data which matches the data format of the given data object currently available on the clipboard.

TodoThe name of this function is misleading. This should be renamed to something that more accurately indicates what it does.

Parameters:

Returns:

  • (Boolean)


102
# File 'lib/wx/doc/gen/clipboard.rb', line 102

def is_supported(format) end

#is_using_primary_selectionBoolean Also known as: using_primary_selection?

Returns true if we are using the primary selection, false if clipboard one.

Returns:

  • (Boolean)

See Also:



110
# File 'lib/wx/doc/gen/clipboard.rb', line 110

def is_using_primary_selection; end

#openBoolean

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

Call #close when you have finished with the clipboard. You should keep the clipboard open for only a very short time. true on success. This should be tested (as in the sample shown above).

Returns:

  • (Boolean)


118
# File 'lib/wx/doc/gen/clipboard.rb', line 118

def open; end

#placeObject



12
# File 'lib/wx/doc/clipboard.rb', line 12

alias :place :set_data

#set_data(data) ⇒ Boolean Also known as: data=

Call this function to set the data object to the clipboard.

The new data object replaces any previously set one, so if the application wants to provide clipboard data in several different formats, it must use a composite data object supporting all of the formats instead of calling this function several times with different data objects as this would only leave data from the last one in the clipboard. After this function has been called, the clipboard owns the data, so do not delete the data explicitly.

Parameters:

Returns:

  • (Boolean)


126
# File 'lib/wx/doc/gen/clipboard.rb', line 126

def set_data(data) end

#use_primary_selection(primary = false) ⇒ void

This method returns an undefined value.

On platforms supporting it (all X11-based ports), Wx::Clipboard uses the CLIPBOARD X11 selection by default.

When this function is called with true, all subsequent clipboard operations will use PRIMARY selection until this function is called again with false. On the other platforms, there is no PRIMARY selection and so all clipboard operations will fail. This allows implementing the standard X11 handling of the clipboard which consists in copying data to the CLIPBOARD selection only when the user explicitly requests it (i.e. by selecting the “Copy” menu command) but putting the currently selected text into the PRIMARY selection automatically, without overwriting the normal clipboard contents with the currently selected text on the other platforms.

Parameters:

  • primary (Boolean) (defaults to: false)


135
# File 'lib/wx/doc/gen/clipboard.rb', line 135

def use_primary_selection(primary=false) end