gtkmm 4.10.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:
[legend]

## Public Member Functions
| Clipboard (Clipboard && src) noexcept
Clipboard & | operator= (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< Display > | get_display ()
| Gets the `Gdk::Display` that the clipboard was created for. More...
Glib::RefPtr< const Display > | get_display () const
| Gets the `Gdk::Display` that the clipboard was created for. More...
Glib::RefPtr< ContentFormats > | get_formats ()
| Gets the formats that the clipboard can provide its current contents in. More...
Glib::RefPtr< const ContentFormats > | get_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< ContentProvider > | get_content ()
| Returns the `Gdk::ContentProvider` currently set on clipboard. More...
Glib::RefPtr< const ContentProvider > | get_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< Texture > | read_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 ()
Public Member Functions inherited from Glib::Object
| Object (const Object &)=delete
Object & | operator= (const Object &)=delete
| Object (Object &&src) noexcept
Object & | operator= (Object &&src) noexcept
void * | get_data (const QueryQuark &key)
void | set_data (const Quark &key, void *data)
void | set_data (const Quark &key, void *data, DestroyNotify notify)
void | remove_data (const QueryQuark &quark)
void * | steal_data (const QueryQuark &quark)
Glib::RefPtr< Glib::Object > | wrap (GObject *object, bool take_copy=false)
Public Member Functions inherited from Glib::ObjectBase
| ObjectBase (const ObjectBase &)=delete
ObjectBase & | operator= (const ObjectBase &)=delete
void | set_property_value (const Glib::ustring &property_name, const Glib::ValueBase &value)
void | get_property_value (const Glib::ustring &property_name, Glib::ValueBase &value) const
void | set_property (const Glib::ustring &property_name, const PropertyType &value)
void | get_property (const Glib::ustring &property_name, PropertyType &value) const
PropertyType | get_property (const Glib::ustring &property_name) const
sigc::connection | connect_property_changed (const Glib::ustring &property_name, const sigc::slot< void()> &slot)
sigc::connection | connect_property_changed (const Glib::ustring &property_name, sigc::slot< void()> &&slot)
void | freeze_notify ()
void | thaw_notify ()
virtual void | reference () const
virtual void | unreference () const
GObject * | gobj ()
const GObject * | gobj () const
GObject * | gobj_copy () const
Public Member Functions inherited from sigc::trackable
| trackable () noexcept
| trackable (const trackable &src) noexcept
| trackable (trackable &&src) noexcept
| ~trackable ()
void | add_destroy_notify_callback (notifiable *data, func_destroy_notify func) const
void | notify_callbacks ()
trackable & | operator= (const trackable &src)
trackable & | operator= (trackable &&src) noexcept
void | remove_destroy_notify_callback (notifiable *data) const

## 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::Clipboard > | wrap (GdkClipboard * object, bool take_copy=false)
| A Glib::wrap() method for this object. More...

## Additional Inherited Members
Public Types inherited from Glib::Object
typedef void(*)(gpointer data | DestroyNotify)
Public Types inherited from sigc::trackable
typedef internal::func_destroy_notify | func_destroy_notify
Public Types inherited from sigc::notifiable
typedef internal::func_destroy_notify | func_destroy_notify
Protected Member Functions inherited from Glib::Object
| Object ()
| Object (const Glib::ConstructParams &construct_params)
| Object (GObject *castitem)
| ~Object () noexcept override
Protected Member Functions inherited from Glib::ObjectBase
| ObjectBase ()
| ObjectBase (const char *custom_type_name)
| ObjectBase (const std::type_info &custom_type_info)
| ObjectBase (ObjectBase &&src) noexcept
ObjectBase & | operator= (ObjectBase &&src) noexcept
virtual | ~ObjectBase () noexcept=0
void | initialize (GObject *castitem)
void | initialize_move (GObject *castitem, Glib::ObjectBase *previous_wrapper)

## 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 | ( |  | ) |
| override noexcept

## 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_types | A `nullptr`-terminated array of mime types to choose from.
  io_priority | The I/O priority of the request.
  cancellable | Optional `Gio::Cancellable` object.
  slot | Callback 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

  result | A `Gio::AsyncResult`.
  out_mime_type | Location 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

  cancellable | Optional `Gio::Cancellable` object.
  slot | Callback 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

  result | A `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

  cancellable | Optional `Gio::Cancellable` object, `nullptr` to ignore.
  slot | Callback 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

  result | A `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

  provider | The 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

  text | Text 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

  texture | A `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

  object | The C instance.
  take_copy | False 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.