Interface
GtkSelectionModel
Description [src]
interface Gtk.SelectionModel : Gio.ListModel
GtkSelectionModel
is an interface that add 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 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 item indicating if an item is
selected or not. This can be queried via gtk_selection_model_is_selected()
.
When the selected state of one or more items 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
GListModel::items-changed
signal are selected or not is up to the implementation.
Note that items added via GListModel::items-changed
may already
be selected and no GtkSelectionModel::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, GtkSelectionModel
s 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.
Prerequisite
In order to implement SelectionModel, your type must inherit fromGListModel
.
Instance methods
gtk_selection_model_get_selection
Gets the set containing all currently selected items in the model.
Signals
Gtk.SelectionModel::selection-changed
Emitted when the selection state of some of the items in model
changes.
Interface structure
struct GtkSelectionModelInterface {
gboolean (* is_selected) (
GtkSelectionModel* model,
guint position
);
GtkBitset* (* get_selection_in_range) (
GtkSelectionModel* model,
guint position,
guint n_items
);
gboolean (* select_item) (
GtkSelectionModel* model,
guint position,
gboolean unselect_rest
);
gboolean (* unselect_item) (
GtkSelectionModel* model,
guint position
);
gboolean (* select_range) (
GtkSelectionModel* model,
guint position,
guint n_items,
gboolean unselect_rest
);
gboolean (* unselect_range) (
GtkSelectionModel* model,
guint position,
guint n_items
);
gboolean (* select_all) (
GtkSelectionModel* model
);
gboolean (* unselect_all) (
GtkSelectionModel* model
);
gboolean (* set_selection) (
GtkSelectionModel* model,
GtkBitset* selected,
GtkBitset* mask
);
}
The list of virtual functions for the GtkSelectionModel
interface.
No function must be implemented, but unless GtkSelectionModel::is_selected()
is implemented, it will not be possible to select items in the set.
The model does not need to implement any functions to support either selecting or unselecting items. Of course, if the model does not do that, it means that users cannot select or unselect items in a list widget using the model.
All selection functions fall back to GtkSelectionModel::set_selection()
so it is sufficient to implement just that function for full selection support.
Interface members
is_selected |
|
Return if the item at the given position is selected. |
|
get_selection_in_range |
|
Return a bitset with all currently selected
items in the given range. By default, this function will call
|
|
select_item |
|
Select the item in the given position. If the operation
is known to fail, return |
|
unselect_item |
|
Unselect the item in the given position. If the
operation is known to fail, return |
|
select_range |
|
Select all items in the given range. If the operation
is unsupported or known to fail for all items, return |
|
unselect_range |
|
Unselect all items in the given range. If the
operation is unsupported or known to fail for all items, return
|
|
select_all |
|
Select all items in the model. If the operation is
unsupported or known to fail for all items, return |
|
unselect_all |
|
Unselect all items in the model. If the operation is
unsupported or known to fail for all items, return |
|
set_selection |
|
Set selection state of all items in mask to selected.
See |