gtkmm 4.14.0
Public Member Functions | Static Public Member Functions | Related Functions | List of all members
Gdk::Clipboard Class Reference

Share data between applications for Copy-and-Paste. More...

#include <gdkmm/clipboard.h>

Inheritance diagram for Gdk::Clipboard:
Inheritance graph
[legend]

Public Member Functions

 Clipboard (Clipboard && src) noexcept
 
Clipboardoperator= (Clipboard && src) noexcept
 
 ~Clipboard () noexcept override
 
GdkClipboard * gobj ()
 Provides access to the underlying C GObject. More...
 
const GdkClipboard * gobj () const
 Provides access to the underlying C GObject. More...
 
GdkClipboard * gobj_copy ()
 Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. More...
 
Glib::RefPtr< Displayget_display ()
 Gets the Gdk::Display that the clipboard was created for. More...
 
Glib::RefPtr< const Displayget_display () const
 Gets the Gdk::Display that the clipboard was created for. More...
 
Glib::RefPtr< ContentFormatsget_formats ()
 Gets the formats that the clipboard can provide its current contents in. More...
 
Glib::RefPtr< const ContentFormatsget_formats () const
 Gets the formats that the clipboard can provide its current contents in. More...
 
bool is_local () const
 Returns if the clipboard is local. More...
 
Glib::RefPtr< ContentProviderget_content ()
 Returns the Gdk::ContentProvider currently set on clipboard. More...
 
Glib::RefPtr< const ContentProviderget_content () const
 Returns the Gdk::ContentProvider currently set on clipboard. More...
 
void read_async (const std::vector< Glib::ustring > & mime_types, int io_priority, const Gio::SlotAsyncReady & slot, const Glib::RefPtr< Gio::Cancellable > & cancellable)
 Asynchronously requests an input stream to read the clipboard's contents from. More...
 
void read_async (const std::vector< Glib::ustring > & mime_types, int io_priority, const Gio::SlotAsyncReady & slot)
 A read_async() convenience overload. More...
 
Glib::RefPtr< Gio::InputStream > read_finish (const Glib::RefPtr< Gio::AsyncResult > & result, Glib::ustring & out_mime_type)
 Finishes an asynchronous clipboard read. More...
 
void read_texture_async (const Gio::SlotAsyncReady & slot, const Glib::RefPtr< Gio::Cancellable > & cancellable)
 Asynchronously request the clipboard contents converted to a Gdk::Pixbuf. More...
 
void read_texture_async (const Gio::SlotAsyncReady & slot)
 A read_texture_async() convenience overload. More...
 
Glib::RefPtr< Textureread_texture_finish (const Glib::RefPtr< Gio::AsyncResult > & result)
 Finishes an asynchronous clipboard read. More...
 
void read_text_async (const Gio::SlotAsyncReady & slot, const Glib::RefPtr< Gio::Cancellable > & cancellable)
 Asynchronously request the clipboard contents converted to a string. More...
 
void read_text_async (const Gio::SlotAsyncReady & slot)
 A read_text_async() convenience overload. More...
 
Glib::ustring read_text_finish (const Glib::RefPtr< Gio::AsyncResult > & result)
 Finishes an asynchronous clipboard read. More...
 
bool set_content (const Glib::RefPtr< const ContentProvider > & provider)
 Sets a new content provider on clipboard. More...
 
bool unset_content ()
 Clears the clipboard. More...
 
void set_text (const Glib::ustring & text)
 Puts the given text into the clipboard. More...
 
void set_texture (const Glib::RefPtr< const Texture > & texture)
 Puts the given texture into the clipboard. More...
 
Glib::PropertyProxy_ReadOnly< Glib::RefPtr< Display > > property_display () const
 The Gdk::Display that the clipboard belongs to. More...
 
Glib::PropertyProxy_ReadOnly< Glib::RefPtr< ContentFormats > > property_formats () const
 The possible formats that the clipboard can provide its data in. More...
 
Glib::PropertyProxy_ReadOnly< bool > property_local () const
 true if the contents of the clipboard are owned by this process. More...
 
Glib::PropertyProxy_ReadOnly< Glib::RefPtr< ContentProvider > > property_content () const
 The Gdk::ContentProvider or nullptr if the clipboard is empty or contents are provided otherwise. More...
 
Glib::SignalProxy< void()> signal_changed ()
 

Static Public Member Functions

static GType get_type ()
 Get the GType for this class, for use with the underlying GObject type system. More...
 

Related Functions

(Note that these are not member functions.)

Glib::RefPtr< Gdk::Clipboardwrap (GdkClipboard * object, bool take_copy=false)
 A Glib::wrap() method for this object. More...
 

Detailed Description

Share data between applications for Copy-and-Paste.

The Gdk::Clipboard object represents a clipboard of data shared between different applications or between different parts of the same application.

To get a Clipboard object, use Gdk::Display::get_clipboard() or Gdk::Display::get_primary_clipboard(). You can find out about the data that is currently available in a clipboard using get_formats().

To make text or image data available in a clipboard, use set_text() or set_texture(). For other data, you can use set_content(), which takes a Gdk::ContentProvider object.

To read textual or image data from a clipboard, use read_text_async() or read_texture_async(). For other data, use read_async(), which provides a Gio::InputStream object.

See also
Gdk::ContentProvider, Gdk::ContentFormats
Since gtkmm 3.94:

Constructor & Destructor Documentation

◆ Clipboard()

Gdk::Clipboard::Clipboard ( Clipboard &&  src)
noexcept

◆ ~Clipboard()

Gdk::Clipboard::~Clipboard ( )
overridenoexcept

Member Function Documentation

◆ get_content() [1/2]

Glib::RefPtr< ContentProvider > Gdk::Clipboard::get_content ( )

Returns the Gdk::ContentProvider currently set on clipboard.

If the clipboard is empty or its contents are not owned by the current process, nullptr will be returned.

Returns
The content of a clipboard if the clipboard does not maintain any content.

◆ get_content() [2/2]

Glib::RefPtr< const ContentProvider > Gdk::Clipboard::get_content ( ) const

Returns the Gdk::ContentProvider currently set on clipboard.

If the clipboard is empty or its contents are not owned by the current process, nullptr will be returned.

Returns
The content of a clipboard if the clipboard does not maintain any content.

◆ get_display() [1/2]

Glib::RefPtr< Display > Gdk::Clipboard::get_display ( )

Gets the Gdk::Display that the clipboard was created for.

Returns
A Gdk::Display.

◆ get_display() [2/2]

Glib::RefPtr< const Display > Gdk::Clipboard::get_display ( ) const

Gets the Gdk::Display that the clipboard was created for.

Returns
A Gdk::Display.

◆ get_formats() [1/2]

Glib::RefPtr< ContentFormats > Gdk::Clipboard::get_formats ( )

Gets the formats that the clipboard can provide its current contents in.

Returns
The formats of the clipboard.

◆ get_formats() [2/2]

Glib::RefPtr< const ContentFormats > Gdk::Clipboard::get_formats ( ) const

Gets the formats that the clipboard can provide its current contents in.

Returns
The formats of the clipboard.

◆ get_type()

static GType Gdk::Clipboard::get_type ( )
static

Get the GType for this class, for use with the underlying GObject type system.

◆ gobj() [1/2]

GdkClipboard * Gdk::Clipboard::gobj ( )
inline

Provides access to the underlying C GObject.

◆ gobj() [2/2]

const GdkClipboard * Gdk::Clipboard::gobj ( ) const
inline

Provides access to the underlying C GObject.

◆ gobj_copy()

GdkClipboard * Gdk::Clipboard::gobj_copy ( )

Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.

◆ is_local()

bool Gdk::Clipboard::is_local ( ) const

Returns if the clipboard is local.

A clipboard is considered local if it was last claimed by the running application.

Note that get_content() may return nullptr even on a local clipboard. In this case the clipboard is empty.

Returns
true if the clipboard is local.

◆ operator=()

Clipboard & Gdk::Clipboard::operator= ( Clipboard &&  src)
noexcept

◆ property_content()

Glib::PropertyProxy_ReadOnly< Glib::RefPtr< ContentProvider > > Gdk::Clipboard::property_content ( ) const

The Gdk::ContentProvider or nullptr if the clipboard is empty or contents are provided otherwise.

Returns
A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

◆ property_display()

Glib::PropertyProxy_ReadOnly< Glib::RefPtr< Display > > Gdk::Clipboard::property_display ( ) const

The Gdk::Display that the clipboard belongs to.

Returns
A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

◆ property_formats()

Glib::PropertyProxy_ReadOnly< Glib::RefPtr< ContentFormats > > Gdk::Clipboard::property_formats ( ) const

The possible formats that the clipboard can provide its data in.

Returns
A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

◆ property_local()

Glib::PropertyProxy_ReadOnly< bool > Gdk::Clipboard::property_local ( ) const

true if the contents of the clipboard are owned by this process.

Default value: true

Returns
A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

◆ read_async() [1/2]

void Gdk::Clipboard::read_async ( const std::vector< Glib::ustring > &  mime_types,
int  io_priority,
const Gio::SlotAsyncReady &  slot 
)

A read_async() convenience overload.

◆ read_async() [2/2]

void Gdk::Clipboard::read_async ( const std::vector< Glib::ustring > &  mime_types,
int  io_priority,
const Gio::SlotAsyncReady &  slot,
const Glib::RefPtr< Gio::Cancellable > &  cancellable 
)

Asynchronously requests an input stream to read the clipboard's contents from.

When the operation is finished slot will be called. You must then call read_finish() to get the result of the operation.

The clipboard will choose the most suitable mime type from the given list to fulfill the request, preferring the ones listed first.

Parameters
mime_typesA nullptr-terminated array of mime types to choose from.
io_priorityThe I/O priority of the request.
cancellableOptional Gio::Cancellable object.
slotCallback to call when the request is satisfied.

◆ read_finish()

Glib::RefPtr< Gio::InputStream > Gdk::Clipboard::read_finish ( const Glib::RefPtr< Gio::AsyncResult > &  result,
Glib::ustring &  out_mime_type 
)

Finishes an asynchronous clipboard read.

See read_async().

Parameters
resultA Gio::AsyncResult.
out_mime_typeLocation to store the chosen mime type.
Returns
A Gio::InputStream.
Exceptions
Glib::Error

◆ read_text_async() [1/2]

void Gdk::Clipboard::read_text_async ( const Gio::SlotAsyncReady &  slot)

A read_text_async() convenience overload.

◆ read_text_async() [2/2]

void Gdk::Clipboard::read_text_async ( const Gio::SlotAsyncReady &  slot,
const Glib::RefPtr< Gio::Cancellable > &  cancellable 
)

Asynchronously request the clipboard contents converted to a string.

When the operation is finished slot will be called. You must then call read_text_finish() to get the result.

This is a simple wrapper around read_value_async(). Use that function or read_async() directly if you need more control over the operation.

Parameters
cancellableOptional Gio::Cancellable object.
slotCallback to call when the request is satisfied.

◆ read_text_finish()

Glib::ustring Gdk::Clipboard::read_text_finish ( const Glib::RefPtr< Gio::AsyncResult > &  result)

Finishes an asynchronous clipboard read.

See read_text_async().

Parameters
resultA Gio::AsyncResult.
Returns
A new string.
Exceptions
Glib::Error

◆ read_texture_async() [1/2]

void Gdk::Clipboard::read_texture_async ( const Gio::SlotAsyncReady &  slot)

A read_texture_async() convenience overload.

◆ read_texture_async() [2/2]

void Gdk::Clipboard::read_texture_async ( const Gio::SlotAsyncReady &  slot,
const Glib::RefPtr< Gio::Cancellable > &  cancellable 
)

Asynchronously request the clipboard contents converted to a Gdk::Pixbuf.

When the operation is finished slot will be called. You must then call read_texture_finish() to get the result.

This is a simple wrapper around read_value_async(). Use that function or read_async() directly if you need more control over the operation.

Parameters
cancellableOptional Gio::Cancellable object, nullptr to ignore.
slotCallback to call when the request is satisfied.

◆ read_texture_finish()

Glib::RefPtr< Texture > Gdk::Clipboard::read_texture_finish ( const Glib::RefPtr< Gio::AsyncResult > &  result)

Finishes an asynchronous clipboard read.

See read_texture_async().

Parameters
resultA Gio::AsyncResult.
Returns
A new Gdk::Texture.
Exceptions
Glib::Error

◆ set_content()

bool Gdk::Clipboard::set_content ( const Glib::RefPtr< const ContentProvider > &  provider)

Sets a new content provider on clipboard.

The clipboard will claim the Gdk::Display's resources and advertise these new contents to other applications.

In the rare case of a failure, this function will return false. The clipboard will then continue reporting its old contents and ignore provider.

If the contents are read by either an external application or the clipboard's read functions, clipboard will select the best format to transfer the contents and then request that format from provider.

Parameters
providerThe new contents of clipboard or nullptr to clear the clipboard.
Returns
true if setting the clipboard succeeded.

◆ set_text()

void Gdk::Clipboard::set_text ( const Glib::ustring &  text)

Puts the given text into the clipboard.

Parameters
textText to put into the clipboard.

◆ set_texture()

void Gdk::Clipboard::set_texture ( const Glib::RefPtr< const Texture > &  texture)

Puts the given texture into the clipboard.

Parameters
textureA Gdk::Texture to put into the clipboard.

◆ signal_changed()

Glib::SignalProxy< void()> Gdk::Clipboard::signal_changed ( )
Slot Prototype:
void on_my_changed()

Flags: Run Last

Emitted when the clipboard changes ownership.

◆ unset_content()

bool Gdk::Clipboard::unset_content ( )

Clears the clipboard.

In the rare case of a failure, this function will return false. The clipboard will then continue reporting its old contents.

Returns
true if unsetting the clipboard succeeded.

Friends And Related Function Documentation

◆ wrap()

Glib::RefPtr< Gdk::Clipboard > wrap ( GdkClipboard *  object,
bool  take_copy = false 
)
related

A Glib::wrap() method for this object.

Parameters
objectThe C instance.
take_copyFalse if the result should take ownership of the C instance. True if it should take a new copy or ref.
Returns
A C++ instance that wraps this C instance.