Selections

Selections — Functions for handling inter-process communication via selections

Functions

CtkTargetEntry * ctk_target_entry_new ()
CtkTargetEntry * ctk_target_entry_copy ()
void ctk_target_entry_free ()
CtkTargetList * ctk_target_list_new ()
CtkTargetList * ctk_target_list_ref ()
void ctk_target_list_unref ()
void ctk_target_list_add ()
void ctk_target_list_add_table ()
void ctk_target_list_add_text_targets ()
void ctk_target_list_add_image_targets ()
void ctk_target_list_add_uri_targets ()
void ctk_target_list_add_rich_text_targets ()
void ctk_target_list_remove ()
gboolean ctk_target_list_find ()
void ctk_target_table_free ()
CtkTargetEntry * ctk_target_table_new_from_list ()
gboolean ctk_selection_owner_set ()
gboolean ctk_selection_owner_set_for_display ()
void ctk_selection_add_target ()
void ctk_selection_add_targets ()
void ctk_selection_clear_targets ()
gboolean ctk_selection_convert ()
void ctk_selection_data_set ()
gboolean ctk_selection_data_set_text ()
guchar * ctk_selection_data_get_text ()
gboolean ctk_selection_data_set_pixbuf ()
GdkPixbuf * ctk_selection_data_get_pixbuf ()
gboolean ctk_selection_data_set_uris ()
gchar ** ctk_selection_data_get_uris ()
gboolean ctk_selection_data_get_targets ()
gboolean ctk_selection_data_targets_include_image ()
gboolean ctk_selection_data_targets_include_text ()
gboolean ctk_selection_data_targets_include_uri ()
gboolean ctk_selection_data_targets_include_rich_text ()
CdkAtom ctk_selection_data_get_selection ()
const guchar * ctk_selection_data_get_data ()
gint ctk_selection_data_get_length ()
const guchar * ctk_selection_data_get_data_with_length ()
CdkAtom ctk_selection_data_get_data_type ()
CdkDisplay * ctk_selection_data_get_display ()
gint ctk_selection_data_get_format ()
CdkAtom ctk_selection_data_get_target ()
gboolean ctk_targets_include_image ()
gboolean ctk_targets_include_text ()
gboolean ctk_targets_include_uri ()
gboolean ctk_targets_include_rich_text ()
void ctk_selection_remove_all ()
CtkSelectionData * ctk_selection_data_copy ()
void ctk_selection_data_free ()

Types and Values

Object Hierarchy

    GBoxed
    ├── CtkSelectionData
    ╰── CtkTargetList

Includes

#include <ctk/ctk.h>

Description

The selection mechanism provides the basis for different types of communication between processes. In particular, drag and drop and CtkClipboard work via selections. You will very seldom or never need to use most of the functions in this section directly; CtkClipboard provides a nicer interface to the same functionality.

If an application is expected to exchange image data and work on Windows, it is highly advised to support at least "image/bmp" target for the widest possible compatibility with third-party applications. CtkClipboard already does that by using ctk_target_list_add_image_targets() and ctk_selection_data_set_pixbuf() or ctk_selection_data_get_pixbuf(), which is one of the reasons why it is advised to use CtkClipboard.

Some of the datatypes defined this section are used in the CtkClipboard and drag-and-drop API’s as well. The CtkTargetEntry and CtkTargetList objects represent lists of data types that are supported when sending or receiving data. The CtkSelectionData object is used to store a chunk of data along with the data type and other associated information.

Functions

ctk_target_entry_new ()

CtkTargetEntry *
ctk_target_entry_new (const gchar *target,
                      guint flags,
                      guint info);

Makes a new CtkTargetEntry.

Parameters

target

String identifier for target

 

flags

Set of flags, see CtkTargetFlags

 

info

an ID that will be passed back to the application

 

Returns

a pointer to a new CtkTargetEntry. Free with ctk_target_entry_free()


ctk_target_entry_copy ()

CtkTargetEntry *
ctk_target_entry_copy (CtkTargetEntry *data);

Makes a copy of a CtkTargetEntry and its data.

Parameters

data

a pointer to a CtkTargetEntry

 

Returns

a pointer to a copy of data . Free with ctk_target_entry_free()


ctk_target_entry_free ()

void
ctk_target_entry_free (CtkTargetEntry *data);

Frees a CtkTargetEntry returned from ctk_target_entry_new() or ctk_target_entry_copy().

Parameters

data

a pointer to a CtkTargetEntry.

 

ctk_target_list_new ()

CtkTargetList *
ctk_target_list_new (const CtkTargetEntry *targets,
                     guint ntargets);

Creates a new CtkTargetList from an array of CtkTargetEntry.

Parameters

targets

Pointer to an array of CtkTargetEntry.

[array length=ntargets][allow-none]

ntargets

number of entries in targets .

 

Returns

the new CtkTargetList.

[transfer full]


ctk_target_list_ref ()

CtkTargetList *
ctk_target_list_ref (CtkTargetList *list);

Increases the reference count of a CtkTargetList by one.

Parameters

list

a CtkTargetList

 

Returns

the passed in CtkTargetList.


ctk_target_list_unref ()

void
ctk_target_list_unref (CtkTargetList *list);

Decreases the reference count of a CtkTargetList by one. If the resulting reference count is zero, frees the list.

Parameters

list

a CtkTargetList

 

ctk_target_list_add ()

void
ctk_target_list_add (CtkTargetList *list,
                     CdkAtom target,
                     guint flags,
                     guint info);

Appends another target to a CtkTargetList.

Parameters

list

a CtkTargetList

 

target

the interned atom representing the target

 

flags

the flags for this target

 

info

an ID that will be passed back to the application

 

ctk_target_list_add_table ()

void
ctk_target_list_add_table (CtkTargetList *list,
                           const CtkTargetEntry *targets,
                           guint ntargets);

Prepends a table of CtkTargetEntry to a target list.

Parameters

list

a CtkTargetList

 

targets

the table of CtkTargetEntry.

[array length=ntargets]

ntargets

number of targets in the table

 

ctk_target_list_add_text_targets ()

void
ctk_target_list_add_text_targets (CtkTargetList *list,
                                  guint info);

Appends the text targets supported by CtkSelectionData to the target list. All targets are added with the same info .

Parameters

list

a CtkTargetList

 

info

an ID that will be passed back to the application

 

Since: 2.6


ctk_target_list_add_image_targets ()

void
ctk_target_list_add_image_targets (CtkTargetList *list,
                                   guint info,
                                   gboolean writable);

Appends the image targets supported by CtkSelectionData to the target list. All targets are added with the same info .

Parameters

list

a CtkTargetList

 

info

an ID that will be passed back to the application

 

writable

whether to add only targets for which CTK+ knows how to convert a pixbuf into the format

 

Since: 2.6


ctk_target_list_add_uri_targets ()

void
ctk_target_list_add_uri_targets (CtkTargetList *list,
                                 guint info);

Appends the URI targets supported by CtkSelectionData to the target list. All targets are added with the same info .

Parameters

list

a CtkTargetList

 

info

an ID that will be passed back to the application

 

Since: 2.6


ctk_target_list_add_rich_text_targets ()

void
ctk_target_list_add_rich_text_targets (CtkTargetList *list,
                                       guint info,
                                       gboolean deserializable,
                                       CtkTextBuffer *buffer);

Appends the rich text targets registered with ctk_text_buffer_register_serialize_format() or ctk_text_buffer_register_deserialize_format() to the target list. All targets are added with the same info .

Parameters

list

a CtkTargetList

 

info

an ID that will be passed back to the application

 

deserializable

if TRUE, then deserializable rich text formats will be added, serializable formats otherwise.

 

buffer

a CtkTextBuffer.

 

Since: 2.10


ctk_target_list_remove ()

void
ctk_target_list_remove (CtkTargetList *list,
                        CdkAtom target);

Removes a target from a target list.

Parameters

list

a CtkTargetList

 

target

the interned atom representing the target

 

ctk_target_list_find ()

gboolean
ctk_target_list_find (CtkTargetList *list,
                      CdkAtom target,
                      guint *info);

Looks up a given target in a CtkTargetList.

Parameters

list

a CtkTargetList

 

target

an interned atom representing the target to search for

 

info

a pointer to the location to store application info for target, or NULL.

[out][allow-none]

Returns

TRUE if the target was found, otherwise FALSE


ctk_target_table_free ()

void
ctk_target_table_free (CtkTargetEntry *targets,
                       gint n_targets);

This function frees a target table as returned by ctk_target_table_new_from_list()

Parameters

targets

a CtkTargetEntry array.

[array length=n_targets]

n_targets

the number of entries in the array

 

Since: 2.10


ctk_target_table_new_from_list ()

CtkTargetEntry *
ctk_target_table_new_from_list (CtkTargetList *list,
                                gint *n_targets);

This function creates an CtkTargetEntry array that contains the same targets as the passed list. The returned table is newly allocated and should be freed using ctk_target_table_free() when no longer needed.

Parameters

list

a CtkTargetList

 

n_targets

return location for the number ot targets in the table.

[out]

Returns

the new table.

[array length=n_targets][transfer full]

Since: 2.10


ctk_selection_owner_set ()

gboolean
ctk_selection_owner_set (CtkWidget *widget,
                         CdkAtom selection,
                         guint32 time_);

Claims ownership of a given selection for a particular widget, or, if widget is NULL, release ownership of the selection.

Parameters

widget

a CtkWidget, or NULL.

[allow-none]

selection

an interned atom representing the selection to claim

 

time_

timestamp with which to claim the selection

 

Returns

TRUE if the operation succeeded


ctk_selection_owner_set_for_display ()

gboolean
ctk_selection_owner_set_for_display (CdkDisplay *display,
                                     CtkWidget *widget,
                                     CdkAtom selection,
                                     guint32 time_);

Claim ownership of a given selection for a particular widget, or, if widget is NULL, release ownership of the selection.

Parameters

display

the CdkDisplay where the selection is set

 

widget

new selection owner (a CtkWidget), or NULL.

[allow-none]

selection

an interned atom representing the selection to claim.

 

time_

timestamp with which to claim the selection

 

Returns

TRUE if the operation succeeded

Since: 2.2


ctk_selection_add_target ()

void
ctk_selection_add_target (CtkWidget *widget,
                          CdkAtom selection,
                          CdkAtom target,
                          guint info);

Appends a specified target to the list of supported targets for a given widget and selection.

Parameters

widget

a CtkWidget

 

selection

the selection

 

target

target to add.

 

info

A unsigned integer which will be passed back to the application.

 

ctk_selection_add_targets ()

void
ctk_selection_add_targets (CtkWidget *widget,
                           CdkAtom selection,
                           const CtkTargetEntry *targets,
                           guint ntargets);

Prepends a table of targets to the list of supported targets for a given widget and selection.

Parameters

widget

a CtkWidget

 

selection

the selection

 

targets

a table of targets to add.

[array length=ntargets]

ntargets

number of entries in targets

 

ctk_selection_clear_targets ()

void
ctk_selection_clear_targets (CtkWidget *widget,
                             CdkAtom selection);

Remove all targets registered for the given selection for the widget.

Parameters

widget

a CtkWidget

 

selection

an atom representing a selection

 

ctk_selection_convert ()

gboolean
ctk_selection_convert (CtkWidget *widget,
                       CdkAtom selection,
                       CdkAtom target,
                       guint32 time_);

Requests the contents of a selection. When received, a “selection-received” signal will be generated.

Parameters

widget

The widget which acts as requestor

 

selection

Which selection to get

 

target

Form of information desired (e.g., STRING)

 

time_

Time of request (usually of triggering event) In emergency, you could use CDK_CURRENT_TIME

 

Returns

TRUE if requested succeeded. FALSE if we could not process request. (e.g., there was already a request in process for this widget).


ctk_selection_data_set ()

void
ctk_selection_data_set (CtkSelectionData *selection_data,
                        CdkAtom type,
                        gint format,
                        const guchar *data,
                        gint length);

Stores new data into a CtkSelectionData object. Should only be called from a selection handler callback. Zero-terminates the stored data.

Parameters

selection_data

a pointer to a CtkSelectionData.

 

type

the type of selection data

 

format

format (number of bits in a unit)

 

data

pointer to the data (will be copied).

[array length=length]

length

length of the data

 

ctk_selection_data_set_text ()

gboolean
ctk_selection_data_set_text (CtkSelectionData *selection_data,
                             const gchar *str,
                             gint len);

Sets the contents of the selection from a UTF-8 encoded string. The string is converted to the form determined by selection_data->target .

Parameters

selection_data

a CtkSelectionData

 

str

a UTF-8 string

 

len

the length of str , or -1 if str is nul-terminated.

 

Returns

TRUE if the selection was successfully set, otherwise FALSE.


ctk_selection_data_get_text ()

guchar *
ctk_selection_data_get_text (const CtkSelectionData *selection_data);

Gets the contents of the selection data as a UTF-8 string.

Parameters

selection_data

a CtkSelectionData

 

Returns

if the selection data contained a recognized text type and it could be converted to UTF-8, a newly allocated string containing the converted text, otherwise NULL. If the result is non-NULL it must be freed with g_free().

[type utf8][nullable][transfer full]


ctk_selection_data_set_pixbuf ()

gboolean
ctk_selection_data_set_pixbuf (CtkSelectionData *selection_data,
                               GdkPixbuf *pixbuf);

Sets the contents of the selection from a GdkPixbuf The pixbuf is converted to the form determined by selection_data->target .

Parameters

selection_data

a CtkSelectionData

 

pixbuf

a GdkPixbuf

 

Returns

TRUE if the selection was successfully set, otherwise FALSE.

Since: 2.6


ctk_selection_data_get_pixbuf ()

GdkPixbuf *
ctk_selection_data_get_pixbuf (const CtkSelectionData *selection_data);

Gets the contents of the selection data as a GdkPixbuf.

Parameters

selection_data

a CtkSelectionData

 

Returns

if the selection data contained a recognized image type and it could be converted to a GdkPixbuf, a newly allocated pixbuf is returned, otherwise NULL. If the result is non-NULL it must be freed with g_object_unref().

[nullable][transfer full]

Since: 2.6


ctk_selection_data_set_uris ()

gboolean
ctk_selection_data_set_uris (CtkSelectionData *selection_data,
                             gchar **uris);

Sets the contents of the selection from a list of URIs. The string is converted to the form determined by selection_data->target .

Parameters

selection_data

a CtkSelectionData

 

uris

a NULL-terminated array of strings holding URIs.

[array zero-terminated=1]

Returns

TRUE if the selection was successfully set, otherwise FALSE.

Since: 2.6


ctk_selection_data_get_uris ()

gchar **
ctk_selection_data_get_uris (const CtkSelectionData *selection_data);

Gets the contents of the selection data as array of URIs.

Parameters

selection_data

a CtkSelectionData

 

Returns

if the selection data contains a list of URIs, a newly allocated NULL-terminated string array containing the URIs, otherwise NULL. If the result is non-NULL it must be freed with g_strfreev().

[array zero-terminated=1][element-type utf8][transfer full]

Since: 2.6


ctk_selection_data_get_targets ()

gboolean
ctk_selection_data_get_targets (const CtkSelectionData *selection_data,
                                CdkAtom **targets,
                                gint *n_atoms);

Gets the contents of selection_data as an array of targets. This can be used to interpret the results of getting the standard TARGETS target that is always supplied for any selection.

Parameters

selection_data

a CtkSelectionData object

 

targets

location to store an array of targets. The result stored here must be freed with g_free().

[out][array length=n_atoms][transfer container]

n_atoms

location to store number of items in targets .

 

Returns

TRUE if selection_data contains a valid array of targets, otherwise FALSE.


ctk_selection_data_targets_include_image ()

gboolean
ctk_selection_data_targets_include_image
                               (const CtkSelectionData *selection_data,
                                gboolean writable);

Given a CtkSelectionData object holding a list of targets, determines if any of the targets in targets can be used to provide a GdkPixbuf.

Parameters

selection_data

a CtkSelectionData object

 

writable

whether to accept only targets for which CTK+ knows how to convert a pixbuf into the format

 

Returns

TRUE if selection_data holds a list of targets, and a suitable target for images is included, otherwise FALSE.

Since: 2.6


ctk_selection_data_targets_include_text ()

gboolean
ctk_selection_data_targets_include_text
                               (const CtkSelectionData *selection_data);

Given a CtkSelectionData object holding a list of targets, determines if any of the targets in targets can be used to provide text.

Parameters

selection_data

a CtkSelectionData object

 

Returns

TRUE if selection_data holds a list of targets, and a suitable target for text is included, otherwise FALSE.


ctk_selection_data_targets_include_uri ()

gboolean
ctk_selection_data_targets_include_uri
                               (const CtkSelectionData *selection_data);

Given a CtkSelectionData object holding a list of targets, determines if any of the targets in targets can be used to provide a list or URIs.

Parameters

selection_data

a CtkSelectionData object

 

Returns

TRUE if selection_data holds a list of targets, and a suitable target for URI lists is included, otherwise FALSE.

Since: 2.10


ctk_selection_data_targets_include_rich_text ()

gboolean
ctk_selection_data_targets_include_rich_text
                               (const CtkSelectionData *selection_data,
                                CtkTextBuffer *buffer);

Given a CtkSelectionData object holding a list of targets, determines if any of the targets in targets can be used to provide rich text.

Parameters

selection_data

a CtkSelectionData object

 

buffer

a CtkTextBuffer

 

Returns

TRUE if selection_data holds a list of targets, and a suitable target for rich text is included, otherwise FALSE.

Since: 2.10


ctk_selection_data_get_selection ()

CdkAtom
ctk_selection_data_get_selection (const CtkSelectionData *selection_data);

Retrieves the selection CdkAtom of the selection data.

Parameters

selection_data

a pointer to a CtkSelectionData.

 

Returns

the selection CdkAtom of the selection data.

[transfer none]

Since: 2.16


ctk_selection_data_get_data ()

const guchar *
ctk_selection_data_get_data (const CtkSelectionData *selection_data);

Retrieves the raw data of the selection.

[skip]

Parameters

selection_data

a pointer to a CtkSelectionData.

 

Returns

the raw data of the selection.

[array][element-type guint8]

Since: 2.14


ctk_selection_data_get_length ()

gint
ctk_selection_data_get_length (const CtkSelectionData *selection_data);

Retrieves the length of the raw data of the selection.

Parameters

selection_data

a pointer to a CtkSelectionData.

 

Returns

the length of the data of the selection.

Since: 2.14


ctk_selection_data_get_data_with_length ()

const guchar *
ctk_selection_data_get_data_with_length
                               (const CtkSelectionData *selection_data,
                                gint *length);

Retrieves the raw data of the selection along with its length.

[rename-to ctk_selection_data_get_data]

Parameters

selection_data

a pointer to a CtkSelectionData.

 

length

return location for length of the data segment.

[out]

Returns

the raw data of the selection.

[array length=length]

Since: 3.0


ctk_selection_data_get_data_type ()

CdkAtom
ctk_selection_data_get_data_type (const CtkSelectionData *selection_data);

Retrieves the data type of the selection.

Parameters

selection_data

a pointer to a CtkSelectionData.

 

Returns

the data type of the selection.

[transfer none]

Since: 2.14


ctk_selection_data_get_display ()

CdkDisplay *
ctk_selection_data_get_display (const CtkSelectionData *selection_data);

Retrieves the display of the selection.

Parameters

selection_data

a pointer to a CtkSelectionData.

 

Returns

the display of the selection.

[transfer none]

Since: 2.14


ctk_selection_data_get_format ()

gint
ctk_selection_data_get_format (const CtkSelectionData *selection_data);

Retrieves the format of the selection.

Parameters

selection_data

a pointer to a CtkSelectionData.

 

Returns

the format of the selection.

Since: 2.14


ctk_selection_data_get_target ()

CdkAtom
ctk_selection_data_get_target (const CtkSelectionData *selection_data);

Retrieves the target of the selection.

Parameters

selection_data

a pointer to a CtkSelectionData.

 

Returns

the target of the selection.

[transfer none]

Since: 2.14


ctk_targets_include_image ()

gboolean
ctk_targets_include_image (CdkAtom *targets,
                           gint n_targets,
                           gboolean writable);

Determines if any of the targets in targets can be used to provide a GdkPixbuf.

Parameters

targets

an array of CdkAtoms.

[array length=n_targets]

n_targets

the length of targets

 

writable

whether to accept only targets for which CTK+ knows how to convert a pixbuf into the format

 

Returns

TRUE if targets include a suitable target for images, otherwise FALSE.

Since: 2.10


ctk_targets_include_text ()

gboolean
ctk_targets_include_text (CdkAtom *targets,
                          gint n_targets);

Determines if any of the targets in targets can be used to provide text.

Parameters

targets

an array of CdkAtoms.

[array length=n_targets]

n_targets

the length of targets

 

Returns

TRUE if targets include a suitable target for text, otherwise FALSE.

Since: 2.10


ctk_targets_include_uri ()

gboolean
ctk_targets_include_uri (CdkAtom *targets,
                         gint n_targets);

Determines if any of the targets in targets can be used to provide an uri list.

Parameters

targets

an array of CdkAtoms.

[array length=n_targets]

n_targets

the length of targets

 

Returns

TRUE if targets include a suitable target for uri lists, otherwise FALSE.

Since: 2.10


ctk_targets_include_rich_text ()

gboolean
ctk_targets_include_rich_text (CdkAtom *targets,
                               gint n_targets,
                               CtkTextBuffer *buffer);

Determines if any of the targets in targets can be used to provide rich text.

Parameters

targets

an array of CdkAtoms.

[array length=n_targets]

n_targets

the length of targets

 

buffer

a CtkTextBuffer

 

Returns

TRUE if targets include a suitable target for rich text, otherwise FALSE.

Since: 2.10


ctk_selection_remove_all ()

void
ctk_selection_remove_all (CtkWidget *widget);

Removes all handlers and unsets ownership of all selections for a widget. Called when widget is being destroyed. This function will not generally be called by applications.

Parameters

widget

a CtkWidget

 

ctk_selection_data_copy ()

CtkSelectionData *
ctk_selection_data_copy (const CtkSelectionData *data);

Makes a copy of a CtkSelectionData and its data.

Parameters

data

a pointer to a CtkSelectionData.

 

Returns

a pointer to a copy of data .


ctk_selection_data_free ()

void
ctk_selection_data_free (CtkSelectionData *data);

Frees a CtkSelectionData returned from ctk_selection_data_copy().

Parameters

data

a pointer to a CtkSelectionData.

 

Types and Values

CtkSelectionData

typedef struct _CtkSelectionData CtkSelectionData;

struct CtkTargetEntry

struct CtkTargetEntry {
  gchar *target;
  guint  flags;
  guint  info;
};

A CtkTargetEntry represents a single type of data than can be supplied for by a widget for a selection or for supplied or received during drag-and-drop.

Members

gchar *target;

a string representation of the target type

 

guint flags;

CtkTargetFlags for DND

 

guint info;

an application-assigned integer ID which will get passed as a parameter to e.g the “selection-get” signal. It allows the application to identify the target type without extensive string compares.

 

CtkTargetList

typedef struct _CtkTargetList CtkTargetList;

A CtkTargetList is a reference counted list of CtkTargetPair and should be treated as opaque.


struct CtkTargetPair

struct CtkTargetPair {
  CdkAtom   target;
  guint     flags;
  guint     info;
};

A CtkTargetPair is used to represent the same information as a table of CtkTargetEntry, but in an efficient form.

Members

CdkAtom target;

CdkAtom representation of the target type

 

guint flags;

CtkTargetFlags for DND

 

guint info;

an application-assigned integer ID which will get passed as a parameter to e.g the “selection-get” signal. It allows the application to identify the target type without extensive string compares.

 

See Also

CtkWidget - Much of the operation of selections happens via signals for CtkWidget. In particular, if you are using the functions in this section, you may need to pay attention to “selection-get”, “selection-received” and “selection-clear-event” signals