GtkSingleSelection — A selection model that allows selecting a single item
GtkSingleSelection * | gtk_single_selection_new () |
GListModel * | gtk_single_selection_get_model () |
void | gtk_single_selection_set_model () |
guint | gtk_single_selection_get_selected () |
void | gtk_single_selection_set_selected () |
gpointer | gtk_single_selection_get_selected_item () |
gboolean | gtk_single_selection_get_autoselect () |
void | gtk_single_selection_set_autoselect () |
gboolean | gtk_single_selection_get_can_unselect () |
void | gtk_single_selection_set_can_unselect () |
gboolean | autoselect | Read / Write |
gboolean | can-unselect | Read / Write |
GListModel * | model | Read / Write |
guint | selected | Read / Write |
GObject * | selected-item | Read |
GObject ╰── GtkSingleSelection
GtkSingleSelection implements GListModel and GtkSelectionModel.
#include <gtk/gtk.h>
GtkSingleSelection is an implementation of the GtkSelectionModel interface that allows selecting a single element. It is the default selection method used by list widgets in GTK.
Note that the selection is *persistent* -- if the selected item is removed and re-added in the same “items-changed” emission, it stays selected. In particular, this means that changing the sort order of an underlying sort model will preserve the selection.
GtkSingleSelection *
gtk_single_selection_new (GListModel *model
);
Creates a new selection to handle model
.
model | the GListModel to manage, or | [allow-none][transfer full] |
GListModel *
gtk_single_selection_get_model (GtkSingleSelection *self
);
Gets the model that self
is wrapping.
self |
The model being wrapped.
[transfer none]
void gtk_single_selection_set_model (GtkSingleSelection *self
,GListModel *model
);
Sets the model that self
should wrap. If model
is NULL
, self
will be empty.
self | ||
model | A GListModel to wrap. | [allow-none] |
guint
gtk_single_selection_get_selected (GtkSingleSelection *self
);
Gets the position of the selected item. If no item is selected, GTK_INVALID_LIST_POSITION is returned.
self |
The position of the selected item
void gtk_single_selection_set_selected (GtkSingleSelection *self
,guint position
);
Selects the item at the given position.
If the list does not have an item at position
or GTK_INVALID_LIST_POSITION is given, the behavior depends on the value of the “autoselect” property: If it is set, no change will occur and the old item will stay selected. If it is unset, the selection will be unset and no item will be selected.
self | ||
position | the item to select or GTK_INVALID_LIST_POSITION |
gpointer
gtk_single_selection_get_selected_item
(GtkSingleSelection *self
);
Gets the selected item.
If no item is selected, NULL
is returned.
self |
The selected item.
[transfer none]
gboolean
gtk_single_selection_get_autoselect (GtkSingleSelection *self
);
Checks if autoselect has been enabled or disabled via gtk_single_selection_set_autoselect()
.
self |
TRUE
if autoselect is enabled
void gtk_single_selection_set_autoselect (GtkSingleSelection *self
,gboolean autoselect
);
If autoselect
is TRUE
, self
will enforce that an item is always selected. It will select a new item when the currently selected item is deleted and it will disallow unselecting the current item.
self | ||
autoselect |
|
gboolean
gtk_single_selection_get_can_unselect (GtkSingleSelection *self
);
If TRUE
, gtk_selection_model_unselect_item()
is supported and allows unselecting the selected item.
self |
TRUE
to support unselecting
void gtk_single_selection_set_can_unselect (GtkSingleSelection *self
,gboolean can_unselect
);
If TRUE
, unselecting the current item via gtk_selection_model_unselect_item()
is supported.
Note that setting “autoselect” will cause the unselecting to not work, so it practically makes no sense to set both at the same time the same time.
self | ||
can_unselect |
|
typedef struct _GtkSingleSelection GtkSingleSelection;
#define GTK_INVALID_LIST_POSITION (G_MAXUINT)
The value used to refer to a guaranteed invalid position in a GListModel. This value may be returned from some functions, others may accept it as input. Its interpretation may differ for different functions.
Refer to each function's documentation for if this value is allowed and what it does.
“autoselect”
property“autoselect” gboolean
If the selection will always select an item
Owner: GtkSingleSelection
Flags: Read / Write
Default value: TRUE
“can-unselect”
property“can-unselect” gboolean
If unselecting the selected item is allowed
Owner: GtkSingleSelection
Flags: Read / Write
Default value: FALSE
“model”
property“model” GListModel *
The model being managed
Owner: GtkSingleSelection
Flags: Read / Write
“selected”
property“selected” guint
Position of the selected item
Owner: GtkSingleSelection
Flags: Read / Write
Default value: 4294967295
“selected-item”
property“selected-item” GObject *
The selected item
Owner: GtkSingleSelection
Flags: Read
© 2005–2020 The GNOME Project
Licensed under the GNU Lesser General Public License version 2.1 or later.
https://developer.gnome.org/gtk4/4.0/GtkSingleSelection.html