GtkSelectionModel

GtkSelectionModel — An extension of the list model interface that handles selections

Functions

Signals

void selection-changed Run Last

Types and Values

Object Hierarchy

    GInterface
    ╰── GtkSelectionModel

Prerequisites

GtkSelectionModel requires GListModel and GObject.

Known Implementations

GtkSelectionModel is implemented by GtkSingleSelection.

Includes

#include <gtk/gtk.h>

Description

GtkSelectionModel is an interface that extends the GListModel interface by adding support for selections. This support is then used by widgets using list models to add the ability to select and unselect various items.

GTK provides default implementations of the mode common selection modes such as GtkSingleSelection, so you will only need to implement this interface if you want detailed control about how selections should be handled.

A GtkSelectionModel supports a single boolean per row indicating if a row is selected or not. This can be queried via gtk_selection_model_is_selected(). When the selected state of one or more rows changes, the model will emit the GtkSelectionModel::selection-changed signal by calling the gtk_selection_model_selection_changed() function. The positions given in that signal may have their selection state changed, though that is not a requirement. If new items added to the model via the “items-changed” signal are selected or not is up to the implementation.

Additionally, the interface can expose functionality to select and unselect items. If these functions are implemented, GTK's list widgets will allow users to select and unselect items. However, GtkSelectionModels are free to only implement them partially or not at all. In that case the widgets will not support the unimplemented operations.

When selecting or unselecting is supported by a model, the return values of the selection functions do NOT indicate if selection or unselection happened. They are only meant to indicate complete failure, like when this mode of selecting is not supported by the model. Selections may happen asynchronously, so the only reliable way to find out when an item was selected is to listen to the signals that indicate selection.

Functions

gtk_selection_model_is_selected ()

gboolean
gtk_selection_model_is_selected (GtkSelectionModel *model,
                                 guint position);

Checks if the given item is selected.

Parameters

model

a GtkSelectionModel

 

position

the position of the item to query

 

Returns

TRUE if the item is selected


gtk_selection_model_select_item ()

gboolean
gtk_selection_model_select_item (GtkSelectionModel *model,
                                 guint position,
                                 gboolean exclusive);

gtk_selection_model_unselect_item ()

gboolean
gtk_selection_model_unselect_item (GtkSelectionModel *model,
                                   guint position);

gtk_selection_model_select_range ()

gboolean
gtk_selection_model_select_range (GtkSelectionModel *model,
                                  guint position,
                                  guint n_items,
                                  gboolean exclusive);

gtk_selection_model_unselect_range ()

gboolean
gtk_selection_model_unselect_range (GtkSelectionModel *model,
                                    guint position,
                                    guint n_items);

gtk_selection_model_select_all ()

gboolean
gtk_selection_model_select_all (GtkSelectionModel *model);

gtk_selection_model_unselect_all ()

gboolean
gtk_selection_model_unselect_all (GtkSelectionModel *model);

gtk_selection_model_selection_changed ()

void
gtk_selection_model_selection_changed (GtkSelectionModel *model,
                                       guint position,
                                       guint n_items);

Types and Values

GtkSelectionModel

typedef struct _GtkSelectionModel GtkSelectionModel;

Signal Details

The “selection-changed” signal

void
user_function (GtkSelectionModel *model,
               guint              position,
               guint              n_items,
               gpointer           user_data)

Emitted when the selection state of some of the items in model changes.

Note that this signal does not specify the new selection state of the items, they need to be queried manually. It is also not necessary for a model to change the selection state of any of the items in the selection model, though it would be rather useless to emit such a signal.

Parameters

model

a GtkSelectionModel

 

position

The first item that may have changed

 

n_items

number of items with changes

 

user_data

user data set when the signal handler was connected.

 

Flags: Run Last

See Also

GListModel, GtkSingleSelection