An interface that adds support for selection to list models.
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 most common selection modes such as [classGtk.SingleSelection], 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 item indicating if an item is selected or not. This can be queried via [methodGtk.SelectionModel.is_selected]. When the selected state of one or more items changes, the model will emit the [signalGtk.SelectionModel::selection-changed] signal by calling the [methodGtk.SelectionModel.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 [signalGio.ListModel::items-changed] signal are selected or not is up to the implementation.
Note that items added via [signalGio.ListModel::items-changed] may already be selected and no [signalGtk.SelectionModel::selection-changed] will be emitted for them. So to track which items are selected, it is necessary to listen to both signals.
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.
function "+" (W : Gtk_Selection_Model) return Gtk_Selection_Model
type Cb_GObject_Guint_Guint_Void is not null access procedure
(Self : access Glib.Object.GObject_Record'Class;
Position : Guint;
N_Items : Guint);
type Cb_Gtk_Selection_Model_Guint_Guint_Void is not null access procedure
(Self : Gtk_Selection_Model;
Position : Guint;
N_Items : Guint);
function Get_Selection
(Self : Gtk_Selection_Model) return Gtk.Bitset.Gtk_Bitset
Gets the set containing all currently selected items in the model. This function may be slow, so if you are only interested in single item, consider using [methodGtk.SelectionModel.is_selected] or if you are only interested in a few, consider [methodGtk.SelectionModel.get_selection_in_range].
a GtkBitset containing all the values currently selected in Model. If no items are selected, the bitset is empty. The bitset must not be modified. Has transfer-ownership='full'.
function Get_Selection_In_Range
(Self : Gtk_Selection_Model;
Position : Guint;
N_Items : Guint) return Gtk.Bitset.Gtk_Bitset
Gets the set of selected items in a range. This function is an optimization for [methodGtk.SelectionModel.get_selection] when you are only interested in part of the model's selected state. A common use case is in response to the [signalGtk.SelectionModel::selection-changed] signal.
start of the queried range
number of items in the queried range
A GtkBitset that matches the selection state for the given range with all other values being undefined. The bitset must not be modified. Has transfer-ownership='full'.
function Get_Type return Glib.GType
type Gtk_Selection_Model is new Glib.Types.GType_Interface;
function Is_Selected
(Self : Gtk_Selection_Model;
Position : Guint) return Boolean
Checks if the given item is selected.
the position of the item to query
True if the item is selected
Null_Gtk_Selection_Model : constant Gtk_Selection_Model;
procedure On_Selection_Changed
(Self : Gtk_Selection_Model;
Call : Cb_GObject_Guint_Guint_Void;
Slot : not null access Glib.Object.GObject_Record'Class;
After : Boolean := False)
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.
Callback parameters: -- @param Position The first item that may have changed -- @param N_Items number of items with changes
procedure On_Selection_Changed
(Self : Gtk_Selection_Model;
Call : Cb_Gtk_Selection_Model_Guint_Guint_Void;
After : Boolean := False)
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.
Callback parameters: -- @param Position The first item that may have changed -- @param N_Items number of items with changes
function Select_All (Self : Gtk_Selection_Model) return Boolean
Requests to select all items in the model.
True if this action was supported and no fallback should be tried. This does not mean that all items are now selected.
function Select_Item
(Self : Gtk_Selection_Model;
Position : Guint;
Unselect_Rest : Boolean) return Boolean
Requests to select an item in the model.
the position of the item to select
whether previously selected items should be unselected
True if this action was supported and no fallback should be tried. This does not mean the item was selected.
function Select_Range
(Self : Gtk_Selection_Model;
Position : Guint;
N_Items : Guint;
Unselect_Rest : Boolean) return Boolean
Requests to select a range of items in the model.
the first item to select
the number of items to select
whether previously selected items should be unselected
True if this action was supported and no fallback should be tried. This does not mean the range was selected.
procedure Selection_Changed
(Self : Gtk_Selection_Model;
Position : Guint;
N_Items : Guint)
Helper function for implementations of GtkSelectionModel. Call this when the selection changes to emit the [signalGtk.SelectionModel::selection-changed] signal.
the first changed item
the number of changed items
subtype Selection_Model_Interface_Descr is Glib.Object.Interface_Description;
procedure Set_Get_Selection_In_Range
(Self : Selection_Model_Interface_Descr;
Handler : Virtual_Get_Selection_In_Range)
procedure Set_Is_Selected
(Self : Selection_Model_Interface_Descr;
Handler : Virtual_Is_Selected)
procedure Set_Select_All
(Self : Selection_Model_Interface_Descr;
Handler : Virtual_Select_All)
procedure Set_Select_Item
(Self : Selection_Model_Interface_Descr;
Handler : Virtual_Select_Item)
procedure Set_Select_Range
(Self : Selection_Model_Interface_Descr;
Handler : Virtual_Select_Range)
function Set_Selection
(Self : Gtk_Selection_Model;
Selected : Gtk.Bitset.Gtk_Bitset;
Mask : Gtk.Bitset.Gtk_Bitset) return Boolean
Make selection changes. This is the most advanced selection updating method that allows the most fine-grained control over selection changes. If you can, you should try the simpler versions, as implementations are more likely to implement support for those. Requests that the selection state of all positions set in Mask be updated to the respective value in the Selected bitmask. In pseudocode, it would look something like this:
mask if (!gtk_bitset_contains (mask, i)) continue;
if (gtk_bitset_contains (selected, i)) select_item (i); else
unselect_item (i); }
gtk_selection_model_selection_changed (model, first_changed_item,
n_changed_items); ```
Mask and Selected must not be modified. They may refer to the same
bitset, which would mean that every item in the set should be selected.
bitmask specifying if items should be selected or unselected
bitmask specifying which items should be updated
True if this action was supported and no fallback should be tried. This does not mean that all items were updated according to the inputs.
procedure Set_Set_Selection
(Self : Selection_Model_Interface_Descr;
Handler : Virtual_Set_Selection)
procedure Set_Unselect_All
(Self : Selection_Model_Interface_Descr;
Handler : Virtual_Unselect_All)
procedure Set_Unselect_Item
(Self : Selection_Model_Interface_Descr;
Handler : Virtual_Unselect_Item)
procedure Set_Unselect_Range
(Self : Selection_Model_Interface_Descr;
Handler : Virtual_Unselect_Range)
See Glib.Object.Add_Interface
Signal_Selection_Changed : constant Glib.Signal_Name := "selection-changed";
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.
Callback parameters: -- @param Position The first item that may have changed -- @param N_Items number of items with changes
function Unselect_All (Self : Gtk_Selection_Model) return Boolean
Requests to unselect all items in the model.
True if this action was supported and no fallback should be tried. This does not mean that all items are now unselected.
function Unselect_Item
(Self : Gtk_Selection_Model;
Position : Guint) return Boolean
Requests to unselect an item in the model.
the position of the item to unselect
True if this action was supported and no fallback should be tried. This does not mean the item was unselected.
function Unselect_Range
(Self : Gtk_Selection_Model;
Position : Guint;
N_Items : Guint) return Boolean
Requests to unselect a range of items in the model.
the first item to unselect
the number of items to unselect
True if this action was supported and no fallback should be tried. This does not mean the range was unselected.
type Virtual_Get_Selection_In_Range is access function
(Self : Gtk_Selection_Model;
Position : Guint;
N_Items : Guint) return System.Address;
Gets the set of selected items in a range. This function is an optimization for [methodGtk.SelectionModel.get_selection] when you are only interested in part of the model's selected state. A common use case is in response to the [signalGtk.SelectionModel::selection-changed] signal.
start of the queried range
number of items in the queried range
A GtkBitset that matches the selection state for the given range with all other values being undefined. The bitset must not be modified. Has transfer-ownership='full'.
type Virtual_Is_Selected is access function
(Self : Gtk_Selection_Model;
Position : Guint) return Glib.Gboolean;
Checks if the given item is selected.
the position of the item to query
True if the item is selected
type Virtual_Select_All is access function (Self : Gtk_Selection_Model) return Glib.Gboolean;
Requests to select all items in the model.
True if this action was supported and no fallback should be tried. This does not mean that all items are now selected.
type Virtual_Select_Item is access function
(Self : Gtk_Selection_Model;
Position : Guint;
Unselect_Rest : Glib.Gboolean) return Glib.Gboolean;
Requests to select an item in the model.
the position of the item to select
whether previously selected items should be unselected
True if this action was supported and no fallback should be tried. This does not mean the item was selected.
type Virtual_Select_Range is access function
(Self : Gtk_Selection_Model;
Position : Guint;
N_Items : Guint;
Unselect_Rest : Glib.Gboolean) return Glib.Gboolean;
Requests to select a range of items in the model.
the first item to select
the number of items to select
whether previously selected items should be unselected
True if this action was supported and no fallback should be tried. This does not mean the range was selected.
type Virtual_Set_Selection is access function
(Self : Gtk_Selection_Model;
Selected : System.Address;
Mask : System.Address) return Glib.Gboolean;
Make selection changes. This is the most advanced selection updating method that allows the most fine-grained control over selection changes. If you can, you should try the simpler versions, as implementations are more likely to implement support for those. Requests that the selection state of all positions set in Mask be updated to the respective value in the Selected bitmask. In pseudocode, it would look something like this:
mask if (!gtk_bitset_contains (mask, i)) continue;
if (gtk_bitset_contains (selected, i)) select_item (i); else
unselect_item (i); }
gtk_selection_model_selection_changed (model, first_changed_item,
n_changed_items); ```
Mask and Selected must not be modified. They may refer to the same
bitset, which would mean that every item in the set should be selected.
bitmask specifying if items should be selected or unselected
bitmask specifying which items should be updated
True if this action was supported and no fallback should be tried. This does not mean that all items were updated according to the inputs.
type Virtual_Unselect_All is access function (Self : Gtk_Selection_Model) return Glib.Gboolean;
Requests to unselect all items in the model.
True if this action was supported and no fallback should be tried. This does not mean that all items are now unselected.
type Virtual_Unselect_Item is access function
(Self : Gtk_Selection_Model;
Position : Guint) return Glib.Gboolean;
Requests to unselect an item in the model.
the position of the item to unselect
True if this action was supported and no fallback should be tried. This does not mean the item was unselected.
type Virtual_Unselect_Range is access function
(Self : Gtk_Selection_Model;
Position : Guint;
N_Items : Guint) return Glib.Gboolean;
Requests to unselect a range of items in the model.
the first item to unselect
the number of items to unselect
True if this action was supported and no fallback should be tried. This does not mean the range was unselected.