CtkTreeSelection

CtkTreeSelection — The selection object for CtkTreeView

Functions

Properties

CtkSelectionMode mode Read / Write

Signals

void changed Run First

Types and Values

Object Hierarchy

    GObject
    ╰── CtkTreeSelection

Includes

#include <ctk/ctk.h>

Description

The CtkTreeSelection object is a helper object to manage the selection for a CtkTreeView widget. The CtkTreeSelection object is automatically created when a new CtkTreeView widget is created, and cannot exist independently of this widget. The primary reason the CtkTreeSelection objects exists is for cleanliness of code and API. That is, there is no conceptual reason all these functions could not be methods on the CtkTreeView widget instead of a separate function.

The CtkTreeSelection object is gotten from a CtkTreeView by calling ctk_tree_view_get_selection(). It can be manipulated to check the selection status of the tree, as well as select and deselect individual rows. Selection is done completely view side. As a result, multiple views of the same model can have completely different selections. Additionally, you cannot change the selection of a row on the model that is not currently displayed by the view without expanding its parents first.

One of the important things to remember when monitoring the selection of a view is that the “changed” signal is mostly a hint. That is, it may only emit one signal when a range of rows is selected. Additionally, it may on occasion emit a “changed” signal when nothing has happened (mostly as a result of programmers calling select_row on an already selected row).

Functions

CtkTreeSelectionFunc ()

gboolean
(*CtkTreeSelectionFunc) (CtkTreeSelection *selection,
                         CtkTreeModel *model,
                         CtkTreePath *path,
                         gboolean path_currently_selected,
                         gpointer data);

A function used by ctk_tree_selection_set_select_function() to filter whether or not a row may be selected. It is called whenever a row's state might change. A return value of TRUE indicates to selection that it is okay to change the selection.

Parameters

selection

A CtkTreeSelection

 

model

A CtkTreeModel being viewed

 

path

The CtkTreePath of the row in question

 

path_currently_selected

TRUE, if the path is currently selected

 

data

user data.

[closure]

Returns

TRUE, if the selection state of the row can be toggled


CtkTreeSelectionForeachFunc ()

void
(*CtkTreeSelectionForeachFunc) (CtkTreeModel *model,
                                CtkTreePath *path,
                                CtkTreeIter *iter,
                                gpointer data);

A function used by ctk_tree_selection_selected_foreach() to map all selected rows. It will be called on every selected row in the view.

Parameters

model

The CtkTreeModel being viewed

 

path

The CtkTreePath of a selected row

 

iter

A CtkTreeIter pointing to a selected row

 

data

user data.

[closure]

ctk_tree_selection_set_mode ()

void
ctk_tree_selection_set_mode (CtkTreeSelection *selection,
                             CtkSelectionMode type);

Sets the selection mode of the selection . If the previous type was CTK_SELECTION_MULTIPLE, then the anchor is kept selected, if it was previously selected.

Parameters

selection

A CtkTreeSelection.

 

type

The selection mode

 

ctk_tree_selection_get_mode ()

CtkSelectionMode
ctk_tree_selection_get_mode (CtkTreeSelection *selection);

Gets the selection mode for selection . See ctk_tree_selection_set_mode().

Parameters

selection

a CtkTreeSelection

 

Returns

the current selection mode


ctk_tree_selection_set_select_function ()

void
ctk_tree_selection_set_select_function
                               (CtkTreeSelection *selection,
                                CtkTreeSelectionFunc func,
                                gpointer data,
                                GDestroyNotify destroy);

Sets the selection function.

If set, this function is called before any node is selected or unselected, giving some control over which nodes are selected. The select function should return TRUE if the state of the node may be toggled, and FALSE if the state of the node should be left unchanged.

Parameters

selection

A CtkTreeSelection.

 

func

The selection function. May be NULL.

[nullable]

data

The selection function’s data. May be NULL

 

destroy

The destroy function for user data. May be NULL

 

ctk_tree_selection_get_select_function ()

CtkTreeSelectionFunc
ctk_tree_selection_get_select_function
                               (CtkTreeSelection *selection);

Returns the current selection function.

[skip]

Parameters

selection

A CtkTreeSelection.

 

Returns

The function.

Since: 2.14


ctk_tree_selection_get_user_data ()

gpointer
ctk_tree_selection_get_user_data (CtkTreeSelection *selection);

Returns the user data for the selection function.

[skip]

Parameters

selection

A CtkTreeSelection.

 

Returns

The user data.


ctk_tree_selection_get_tree_view ()

CtkTreeView *
ctk_tree_selection_get_tree_view (CtkTreeSelection *selection);

Returns the tree view associated with selection .

Parameters

selection

A CtkTreeSelection

 

Returns

A CtkTreeView.

[transfer none]


ctk_tree_selection_get_selected ()

gboolean
ctk_tree_selection_get_selected (CtkTreeSelection *selection,
                                 CtkTreeModel **model,
                                 CtkTreeIter *iter);

Sets iter to the currently selected node if selection is set to CTK_SELECTION_SINGLE or CTK_SELECTION_BROWSE. iter may be NULL if you just want to test if selection has any selected nodes. model is filled with the current model as a convenience. This function will not work if you use selection is CTK_SELECTION_MULTIPLE.

Parameters

selection

A CtkTreeSelection.

 

model

A pointer to set to the CtkTreeModel, or NULL.

[out][allow-none][transfer none]

iter

The CtkTreeIter, or NULL.

[out][allow-none]

Returns

TRUE, if there is a selected node.


ctk_tree_selection_selected_foreach ()

void
ctk_tree_selection_selected_foreach (CtkTreeSelection *selection,
                                     CtkTreeSelectionForeachFunc func,
                                     gpointer data);

Calls a function for each selected node. Note that you cannot modify the tree or selection from within this function. As a result, ctk_tree_selection_get_selected_rows() might be more useful.

Parameters

selection

A CtkTreeSelection.

 

func

The function to call for each selected node.

[scope call]

data

user data to pass to the function.

 

ctk_tree_selection_get_selected_rows ()

GList *
ctk_tree_selection_get_selected_rows (CtkTreeSelection *selection,
                                      CtkTreeModel **model);

Creates a list of path of all selected rows. Additionally, if you are planning on modifying the model after calling this function, you may want to convert the returned list into a list of CtkTreeRowReferences. To do this, you can use ctk_tree_row_reference_new().

To free the return value, use:

1
g_list_free_full (list, (GDestroyNotify) ctk_tree_path_free);

Parameters

selection

A CtkTreeSelection.

 

model

A pointer to set to the CtkTreeModel, or NULL.

[out][allow-none][transfer none]

Returns

A GList containing a CtkTreePath for each selected row.

[element-type CtkTreePath][transfer full]

Since: 2.2


ctk_tree_selection_count_selected_rows ()

gint
ctk_tree_selection_count_selected_rows
                               (CtkTreeSelection *selection);

Returns the number of rows that have been selected in tree .

Parameters

selection

A CtkTreeSelection.

 

Returns

The number of rows selected.

Since: 2.2


ctk_tree_selection_select_path ()

void
ctk_tree_selection_select_path (CtkTreeSelection *selection,
                                CtkTreePath *path);

Select the row at path .

Parameters

selection

A CtkTreeSelection.

 

path

The CtkTreePath to be selected.

 

ctk_tree_selection_unselect_path ()

void
ctk_tree_selection_unselect_path (CtkTreeSelection *selection,
                                  CtkTreePath *path);

Unselects the row at path .

Parameters

selection

A CtkTreeSelection.

 

path

The CtkTreePath to be unselected.

 

ctk_tree_selection_path_is_selected ()

gboolean
ctk_tree_selection_path_is_selected (CtkTreeSelection *selection,
                                     CtkTreePath *path);

Returns TRUE if the row pointed to by path is currently selected. If path does not point to a valid location, FALSE is returned

Parameters

selection

A CtkTreeSelection.

 

path

A CtkTreePath to check selection on.

 

Returns

TRUE if path is selected.


ctk_tree_selection_select_iter ()

void
ctk_tree_selection_select_iter (CtkTreeSelection *selection,
                                CtkTreeIter *iter);

Selects the specified iterator.

Parameters

selection

A CtkTreeSelection.

 

iter

The CtkTreeIter to be selected.

 

ctk_tree_selection_unselect_iter ()

void
ctk_tree_selection_unselect_iter (CtkTreeSelection *selection,
                                  CtkTreeIter *iter);

Unselects the specified iterator.

Parameters

selection

A CtkTreeSelection.

 

iter

The CtkTreeIter to be unselected.

 

ctk_tree_selection_iter_is_selected ()

gboolean
ctk_tree_selection_iter_is_selected (CtkTreeSelection *selection,
                                     CtkTreeIter *iter);

Returns TRUE if the row at iter is currently selected.

Parameters

selection

A CtkTreeSelection

 

iter

A valid CtkTreeIter

 

Returns

TRUE, if iter is selected


ctk_tree_selection_select_all ()

void
ctk_tree_selection_select_all (CtkTreeSelection *selection);

Selects all the nodes. selection must be set to CTK_SELECTION_MULTIPLE mode.

Parameters

selection

A CtkTreeSelection.

 

ctk_tree_selection_unselect_all ()

void
ctk_tree_selection_unselect_all (CtkTreeSelection *selection);

Unselects all the nodes.

Parameters

selection

A CtkTreeSelection.

 

ctk_tree_selection_select_range ()

void
ctk_tree_selection_select_range (CtkTreeSelection *selection,
                                 CtkTreePath *start_path,
                                 CtkTreePath *end_path);

Selects a range of nodes, determined by start_path and end_path inclusive. selection must be set to CTK_SELECTION_MULTIPLE mode.

Parameters

selection

A CtkTreeSelection.

 

start_path

The initial node of the range.

 

end_path

The final node of the range.

 

ctk_tree_selection_unselect_range ()

void
ctk_tree_selection_unselect_range (CtkTreeSelection *selection,
                                   CtkTreePath *start_path,
                                   CtkTreePath *end_path);

Unselects a range of nodes, determined by start_path and end_path inclusive.

Parameters

selection

A CtkTreeSelection.

 

start_path

The initial node of the range.

 

end_path

The initial node of the range.

 

Since: 2.2

Types and Values

CtkTreeSelection

typedef struct _CtkTreeSelection CtkTreeSelection;

CtkTreeSelectionClass

typedef struct {
  GObjectClass parent_class;

  void (* changed) (CtkTreeSelection *selection);
} CtkTreeSelectionClass;

Members

changed ()

Signal emitted whenever the selection has (possibly) changed.

 

Property Details

The “mode” property

  “mode”                     CtkSelectionMode

Selection mode. See ctk_tree_selection_set_mode() for more information on this property.

Owner: CtkTreeSelection

Flags: Read / Write

Default value: CTK_SELECTION_SINGLE

Since: 3.2

Signal Details

The “changed” signal

void
user_function (CtkTreeSelection *treeselection,
               gpointer          user_data)

Emitted whenever the selection has (possibly) changed. Please note that this signal is mostly a hint. It may only be emitted once when a range of rows are selected, and it may occasionally be emitted when nothing has happened.

Parameters

treeselection

the object which received the signal.

 

user_data

user data set when the signal handler was connected.

 

Flags: Run First

See Also

CtkTreeView, CtkTreeViewColumn, CtkTreeModel, CtkTreeSortable, CtkTreeModelSort, CtkListStore, CtkTreeStore, CtkCellRenderer, CtkCellEditable, CtkCellRendererPixbuf, CtkCellRendererText, CtkCellRendererToggle, CtkTreeView drag-and-drop