Class ContentProvider

All Implemented Interfaces:
PointerInterface

public class ContentProvider extends Object
A `GdkContentProvider` is used to provide content for the clipboard or
for drag-and-drop operations in a number of formats.

To create a `GdkContentProvider`, use [ctor@Gdk.ContentProvider.new_for_value]
or [ctor@Gdk.ContentProvider.new_for_bytes].

GDK knows how to handle common text and image formats out-of-the-box. See
[class@Gdk.ContentSerializer] and [class@Gdk.ContentDeserializer] if you want
to add support for application-specific data formats.

https://docs.gtk.org/gdk4/class.ContentProvider.html

  • Field Details

  • Constructor Details

  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • newForBytesContentProvider

      public static ContentProvider newForBytesContentProvider(@Nonnull Str mime_type, @Nonnull Bytes bytes)
      Create a content provider that provides the given @bytes as data for
      the given @mime_type.
      Parameters:
      mime_type - the mime type
      bytes - a `GBytes` with the data for @mime_type
      Returns:
      a new `GdkContentProvider`
    • newForBytesContentProvider

      public static ContentProvider newForBytesContentProvider(String mime_type, @Nonnull Bytes bytes)
      Create a content provider that provides the given @bytes as data for
      the given @mime_type.
      Parameters:
      mime_type - the mime type
      bytes - a `GBytes` with the data for @mime_type
      Returns:
      a new `GdkContentProvider`
    • newForValueContentProvider

      public static ContentProvider newForValueContentProvider(@Nonnull Value value)
      Create a content provider that provides the given @value.
      Parameters:
      value - a `GValue`
      Returns:
      a new `GdkContentProvider`
    • newTypedContentProvider

      public static ContentProvider newTypedContentProvider(long type, Object... _elipse)
      Create a content provider that provides the value of the given
      @type.

      The value is provided using G_VALUE_COLLECT(), so the same rules
      apply as when calling g_object_new() or g_object_set().
      Parameters:
      type - Type of value to follow
      _elipse - value
      Returns:
      a new `GdkContentProvider`
    • contentChanged

      public void contentChanged()
      Emits the ::content-changed signal.
    • getValue

      public boolean getValue(@Nonnull Value value) throws AllocationError
      Gets the contents of @provider stored in @value.

      The @value will have been initialized to the `GType` the value should be
      provided in. This given `GType` does not need to be listed in the formats
      returned by [method@Gdk.ContentProvider.ref_formats]. However, if the
      given `GType` is not supported, this operation can fail and
      `G_IO_ERROR_NOT_SUPPORTED` will be reported.
      Parameters:
      value - the `GValue` to fill
      Returns:
      %TRUE if the value was set successfully. Otherwise @error will be set to describe the failure.
      Throws:
      AllocationError
    • refFormats

      public ContentFormats refFormats()
      Gets the formats that the provider can provide its current contents in.
      Returns:
      The formats of the provider
    • refStorableFormats

      public ContentFormats refStorableFormats()
      Gets the formats that the provider suggests other applications to store
      the data in.

      An example of such an application would be a clipboard manager.

      This can be assumed to be a subset of [method@Gdk.ContentProvider.ref_formats].
      Returns:
      The storable formats of the provider
    • writeMimeTypeAsync

      public void writeMimeTypeAsync(@Nonnull Str mime_type, @Nonnull OutputStream stream, int io_priority, @Nullable Cancellable cancellable, ContentProvider.OnAsyncReadyCallback callback, @Nullable Pointer user_data)
      Asynchronously writes the contents of @provider to @stream in the given
      @mime_type.

      When the operation is finished @callback will be called. You must then call
      [method@Gdk.ContentProvider.write_mime_type_finish] to get the result
      of the operation.

      The given mime type does not need to be listed in the formats returned by
      [method@Gdk.ContentProvider.ref_formats]. However, if the given `GType` is
      not supported, `G_IO_ERROR_NOT_SUPPORTED` will be reported.

      The given @stream will not be closed.
      Parameters:
      mime_type - the mime type to provide the data in
      stream - the `GOutputStream` to write to
      io_priority - I/O priority of the request.
      cancellable - optional `GCancellable` object, %NULL to ignore.
      callback - callback to call when the request is satisfied
      user_data - the data to pass to callback function
    • writeMimeTypeAsync

      public void writeMimeTypeAsync(String mime_type, @Nonnull OutputStream stream, int io_priority, @Nullable Cancellable cancellable, ContentProvider.OnAsyncReadyCallback callback, @Nullable Pointer user_data)
      Asynchronously writes the contents of @provider to @stream in the given
      @mime_type.

      When the operation is finished @callback will be called. You must then call
      [method@Gdk.ContentProvider.write_mime_type_finish] to get the result
      of the operation.

      The given mime type does not need to be listed in the formats returned by
      [method@Gdk.ContentProvider.ref_formats]. However, if the given `GType` is
      not supported, `G_IO_ERROR_NOT_SUPPORTED` will be reported.

      The given @stream will not be closed.
      Parameters:
      mime_type - the mime type to provide the data in
      stream - the `GOutputStream` to write to
      io_priority - I/O priority of the request.
      cancellable - optional `GCancellable` object, %NULL to ignore.
      callback - callback to call when the request is satisfied
      user_data - the data to pass to callback function
    • writeMimeTypeFinish

      public boolean writeMimeTypeFinish(@Nonnull AsyncResult result) throws AllocationError
      Finishes an asynchronous write operation.

      See [method@Gdk.ContentProvider.write_mime_type_async].
      Parameters:
      result - a `GAsyncResult`
      Returns:
      %TRUE if the operation was completed successfully. Otherwise @error will be set to describe the failure.
      Throws:
      AllocationError
    • onContentChanged

      public SignalHandler onContentChanged(ContentProvider.OnContentChanged signal)
      Connect to signal "content-changed".
      See ContentProvider.OnContentChanged.onContentChanged() for signal description.
      Field SIGNAL_ON_CONTENT_CHANGED contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • getTypeID

      public static long getTypeID()
    • getParentTypeID

      public static long getParentTypeID()
    • getTypeSize

      public static TypeSystem.TypeSize getTypeSize()
    • getParentTypeSize

      public static TypeSystem.TypeSize getParentTypeSize()
    • getInstanceSize

      public static int getInstanceSize()