GtkSingleSelection

GtkSingleSelection — A selection model that allows selecting a single item

Properties

gboolean autoselect Read / Write
gboolean can-unselect Read / Write
GListModel * model Read / Write
guint selected Read / Write
GObject * selected-item Read

Types and Values

Object Hierarchy

    GObject
    ╰── GtkSingleSelection

Implemented Interfaces

GtkSingleSelection implements GListModel and GtkSelectionModel.

Includes

#include <gtk/gtk.h>

Description

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.

Functions

gtk_single_selection_new ()

GtkSingleSelection *
gtk_single_selection_new (GListModel *model);

Creates a new selection to handle model .

Parameters

model

the GListModel to manage, or NULL.

[allow-none][transfer full]

Returns

a new GtkSingleSelection.

[transfer full][type GtkSingleSelection]


gtk_single_selection_get_model ()

GListModel *
gtk_single_selection_get_model (GtkSingleSelection *self);

Gets the model that self is wrapping.

Parameters

self

a GtkSingleSelection

 

Returns

The model being wrapped.

[transfer none]


gtk_single_selection_set_model ()

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.

Parameters

self

a GtkSingleSelection

 

model

A GListModel to wrap.

[allow-none]

gtk_single_selection_get_selected ()

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.

Parameters

self

a GtkSingleSelection

 

Returns

The position of the selected item


gtk_single_selection_set_selected ()

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.

Parameters

self

a GtkSingleSelection

 

position

the item to select or GTK_INVALID_LIST_POSITION

 

gtk_single_selection_get_selected_item ()

gpointer
gtk_single_selection_get_selected_item
                               (GtkSingleSelection *self);

Gets the selected item.

If no item is selected, NULL is returned.

Parameters

self

a GtkSingleSelection

 

Returns

The selected item.

[transfer none]


gtk_single_selection_get_autoselect ()

gboolean
gtk_single_selection_get_autoselect (GtkSingleSelection *self);

Checks if autoselect has been enabled or disabled via gtk_single_selection_set_autoselect().

Parameters

self

a GtkSingleSelection

 

Returns

TRUE if autoselect is enabled


gtk_single_selection_set_autoselect ()

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.

Parameters

self

a GtkSingleSelection

 

autoselect

TRUE to always select an item

 

gtk_single_selection_get_can_unselect ()

gboolean
gtk_single_selection_get_can_unselect (GtkSingleSelection *self);

If TRUE, gtk_selection_model_unselect_item() is supported and allows unselecting the selected item.

Parameters

self

a GtkSingleSelection

 

Returns

TRUE to support unselecting


gtk_single_selection_set_can_unselect ()

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.

Parameters

self

a GtkSingleSelection

 

can_unselect

TRUE to allow unselecting

 

Types and Values

GtkSingleSelection

typedef struct _GtkSingleSelection GtkSingleSelection;

GTK_INVALID_LIST_POSITION

#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.

Property Details

The “autoselect” property

  “autoselect”               gboolean

If the selection will always select an item

Owner: GtkSingleSelection

Flags: Read / Write

Default value: TRUE


The “can-unselect” property

  “can-unselect”             gboolean

If unselecting the selected item is allowed

Owner: GtkSingleSelection

Flags: Read / Write

Default value: FALSE


The “model” property

  “model”                    GListModel *

The model being managed

Owner: GtkSingleSelection

Flags: Read / Write


The “selected” property

  “selected”                 guint

Position of the selected item

Owner: GtkSingleSelection

Flags: Read / Write

Default value: 4294967295


The “selected-item” property

  “selected-item”            GObject *

The selected item

Owner: GtkSingleSelection

Flags: Read