Class: Wx::Clipboard
- Defined in:
- lib/wx/doc/gen/clipboard.rb,
lib/wx/doc/clipboard.rb
Overview
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.(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
Class Method Summary collapse
-
.get ⇒ Wx::Clipboard
Returns the global instance (TheClipboard) of the clipboard object.
-
.open {|clip| ... } ⇒ ::Object
Opens the global clipboard and passes the clipboard object to the block.
Instance Method Summary collapse
-
#add_data(data) ⇒ Boolean
Call this function to add the data object to the clipboard.
-
#clear ⇒ void
Clears the global clipboard object and the system’s clipboard if possible.
-
#close ⇒ void
Call this function to close the clipboard, having opened it with Clipboard.open.
- #fetch ⇒ Object
-
#flush ⇒ Boolean
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.
-
#get_data(data) ⇒ Boolean
(also: #data)
Call this function to fill data with data on the clipboard, if available in the required format.
-
#initialize ⇒ Wx::Clipboard
constructor
Default constructor.
-
#is_opened ⇒ Boolean
(also: #opened?)
Returns true if the clipboard has been opened.
-
#is_supported(format) ⇒ Boolean
(also: #supported?)
Returns true if there is data which matches the data format of the given data object currently available on the clipboard.
-
#is_using_primary_selection ⇒ Boolean
(also: #using_primary_selection?)
Returns true if we are using the primary selection, false if clipboard one.
- #open ⇒ Boolean
- #place ⇒ Object
-
#set_data(data) ⇒ Boolean
(also: #data=)
Call this function to set the data object to the clipboard.
-
#use_primary_selection(primary = false) ⇒ void
On platforms supporting it (all X11-based ports), Clipboard uses the CLIPBOARD X11 selection by default.
Methods inherited from Object
#clone, #dup, #is_same_as, #un_share
Constructor Details
#initialize ⇒ Wx::Clipboard
Default constructor.
53 |
# File 'lib/wx/doc/gen/clipboard.rb', line 53 def initialize; end |
Class Method Details
.get ⇒ Wx::Clipboard
Returns the global instance (TheClipboard) of the clipboard object.
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.
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.
60 |
# File 'lib/wx/doc/gen/clipboard.rb', line 60 def add_data(data) end |
#clear ⇒ void
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 |
#close ⇒ void
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 |
#fetch ⇒ Object
13 |
# File 'lib/wx/doc/clipboard.rb', line 13 alias :fetch :get_data |
#flush ⇒ Boolean
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.
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.
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.
89 |
# File 'lib/wx/doc/gen/clipboard.rb', line 89 def get_data(data) end |
#is_opened ⇒ Boolean Also known as: opened?
Returns true if the clipboard has been opened.
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.
102 |
# File 'lib/wx/doc/gen/clipboard.rb', line 102 def is_supported(format) end |
#is_using_primary_selection ⇒ Boolean Also known as: using_primary_selection?
Returns true if we are using the primary selection, false if clipboard one.
110 |
# File 'lib/wx/doc/gen/clipboard.rb', line 110 def is_using_primary_selection; end |
#open ⇒ Boolean
118 |
# File 'lib/wx/doc/gen/clipboard.rb', line 118 def open; end |
#place ⇒ Object
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.
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.
135 |
# File 'lib/wx/doc/gen/clipboard.rb', line 135 def use_primary_selection(primary=false) end |