1 | /* |
2 | * Copyright © 2018 Benjamin Otte |
3 | * |
4 | * This library is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Lesser General Public |
6 | * License as published by the Free Software Foundation; either |
7 | * version 2.1 of the License, or (at your option) any later version. |
8 | * |
9 | * This library is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Lesser General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU Lesser General Public |
15 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. |
16 | * |
17 | * Authors: Benjamin Otte <otte@gnome.org> |
18 | */ |
19 | |
20 | #ifndef __GTK_SELECTION_MODEL_H__ |
21 | #define __GTK_SELECTION_MODEL_H__ |
22 | |
23 | #if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION) |
24 | #error "Only <gtk/gtk.h> can be included directly." |
25 | #endif |
26 | |
27 | #include <gtk/gtktypes.h> |
28 | |
29 | G_BEGIN_DECLS |
30 | |
31 | #define GTK_TYPE_SELECTION_MODEL (gtk_selection_model_get_type ()) |
32 | |
33 | GDK_AVAILABLE_IN_ALL |
34 | G_DECLARE_INTERFACE (GtkSelectionModel, gtk_selection_model, GTK, SELECTION_MODEL, GListModel) |
35 | |
36 | /** |
37 | * GtkSelectionModelInterface: |
38 | * @is_selected: Return if the item at the given position is selected. |
39 | * @get_selection_in_range: Return a bitset with all currently selected |
40 | * items in the given range. By default, this function will call |
41 | * `GtkSelectionModel::is_selected()` on all items in the given range. |
42 | * @select_item: Select the item in the given position. If the operation |
43 | * is known to fail, return %FALSE. |
44 | * @unselect_item: Unselect the item in the given position. If the |
45 | * operation is known to fail, return %FALSE. |
46 | * @select_range: Select all items in the given range. If the operation |
47 | * is unsupported or known to fail for all items, return %FALSE. |
48 | * @unselect_range: Unselect all items in the given range. If the |
49 | * operation is unsupported or known to fail for all items, return |
50 | * %FALSE. |
51 | * @select_all: Select all items in the model. If the operation is |
52 | * unsupported or known to fail for all items, return %FALSE. |
53 | * @unselect_all: Unselect all items in the model. If the operation is |
54 | * unsupported or known to fail for all items, return %FALSE. |
55 | * @set_selection: Set selection state of all items in mask to selected. |
56 | * See gtk_selection_model_set_selection() for a detailed explanation |
57 | * of this function. |
58 | * |
59 | * The list of virtual functions for the `GtkSelectionModel` interface. |
60 | * No function must be implemented, but unless `GtkSelectionModel::is_selected()` |
61 | * is implemented, it will not be possible to select items in the set. |
62 | * |
63 | * The model does not need to implement any functions to support either |
64 | * selecting or unselecting items. Of course, if the model does not do that, |
65 | * it means that users cannot select or unselect items in a list widget |
66 | * using the model. |
67 | * |
68 | * All selection functions fall back to `GtkSelectionModel::set_selection()` |
69 | * so it is sufficient to implement just that function for full selection |
70 | * support. |
71 | */ |
72 | struct _GtkSelectionModelInterface |
73 | { |
74 | /*< private >*/ |
75 | GTypeInterface g_iface; |
76 | |
77 | /*< public >*/ |
78 | gboolean (* is_selected) (GtkSelectionModel *model, |
79 | guint position); |
80 | GtkBitset * (* get_selection_in_range) (GtkSelectionModel *model, |
81 | guint position, |
82 | guint n_items); |
83 | |
84 | gboolean (* select_item) (GtkSelectionModel *model, |
85 | guint position, |
86 | gboolean unselect_rest); |
87 | gboolean (* unselect_item) (GtkSelectionModel *model, |
88 | guint position); |
89 | gboolean (* select_range) (GtkSelectionModel *model, |
90 | guint position, |
91 | guint n_items, |
92 | gboolean unselect_rest); |
93 | gboolean (* unselect_range) (GtkSelectionModel *model, |
94 | guint position, |
95 | guint n_items); |
96 | gboolean (* select_all) (GtkSelectionModel *model); |
97 | gboolean (* unselect_all) (GtkSelectionModel *model); |
98 | gboolean (* set_selection) (GtkSelectionModel *model, |
99 | GtkBitset *selected, |
100 | GtkBitset *mask); |
101 | }; |
102 | |
103 | GDK_AVAILABLE_IN_ALL |
104 | gboolean gtk_selection_model_is_selected (GtkSelectionModel *model, |
105 | guint position); |
106 | GDK_AVAILABLE_IN_ALL |
107 | GtkBitset * gtk_selection_model_get_selection (GtkSelectionModel *model); |
108 | GDK_AVAILABLE_IN_ALL |
109 | GtkBitset * gtk_selection_model_get_selection_in_range |
110 | (GtkSelectionModel *model, |
111 | guint position, |
112 | guint n_items); |
113 | |
114 | GDK_AVAILABLE_IN_ALL |
115 | gboolean gtk_selection_model_select_item (GtkSelectionModel *model, |
116 | guint position, |
117 | gboolean unselect_rest); |
118 | GDK_AVAILABLE_IN_ALL |
119 | gboolean gtk_selection_model_unselect_item (GtkSelectionModel *model, |
120 | guint position); |
121 | GDK_AVAILABLE_IN_ALL |
122 | gboolean gtk_selection_model_select_range (GtkSelectionModel *model, |
123 | guint position, |
124 | guint n_items, |
125 | gboolean unselect_rest); |
126 | GDK_AVAILABLE_IN_ALL |
127 | gboolean gtk_selection_model_unselect_range (GtkSelectionModel *model, |
128 | guint position, |
129 | guint n_items); |
130 | GDK_AVAILABLE_IN_ALL |
131 | gboolean gtk_selection_model_select_all (GtkSelectionModel *model); |
132 | GDK_AVAILABLE_IN_ALL |
133 | gboolean gtk_selection_model_unselect_all (GtkSelectionModel *model); |
134 | GDK_AVAILABLE_IN_ALL |
135 | gboolean gtk_selection_model_set_selection (GtkSelectionModel *model, |
136 | GtkBitset *selected, |
137 | GtkBitset *mask); |
138 | |
139 | /* for implementations only */ |
140 | GDK_AVAILABLE_IN_ALL |
141 | void gtk_selection_model_selection_changed (GtkSelectionModel *model, |
142 | guint position, |
143 | guint n_items); |
144 | |
145 | G_END_DECLS |
146 | |
147 | #endif /* __GTK_SELECTION_MODEL_H__ */ |
148 | |