1 /*
2  * Copyright (c) 2013 Red Hat, Inc.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or (at your
7  * option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
12  * License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17  *
18  * Author: Alexander Larsson <alexl@redhat.com>
19  *
20  */
21 
22 #ifndef __GTK_LIST_BOX_H__
23 #define __GTK_LIST_BOX_H__
24 
25 #if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
26 #error "Only <gtk/gtk.h> can be included directly."
27 #endif
28 
29 #include <gtk/gtkbin.h>
30 
31 G_BEGIN_DECLS
32 
33 
34 #define GTK_TYPE_LIST_BOX (gtk_list_box_get_type ())
35 #define GTK_LIST_BOX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_LIST_BOX, GtkListBox))
36 #define GTK_LIST_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_LIST_BOX, GtkListBoxClass))
37 #define GTK_IS_LIST_BOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_LIST_BOX))
38 #define GTK_IS_LIST_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_LIST_BOX))
39 #define GTK_LIST_BOX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_LIST_BOX, GtkListBoxClass))
40 
41 typedef struct _GtkListBox        GtkListBox;
42 typedef struct _GtkListBoxClass   GtkListBoxClass;
43 
44 typedef struct _GtkListBoxRow        GtkListBoxRow;
45 typedef struct _GtkListBoxRowClass   GtkListBoxRowClass;
46 
47 struct _GtkListBox
48 {
49   GtkContainer parent_instance;
50 };
51 
52 /**
53  * GtkListBoxClass:
54  * @parent_class: The parent class.
55  * @row_selected: Class handler for the #GtkListBox::row-selected signal
56  * @row_activated: Class handler for the #GtkListBox::row-activated signal
57  * @activate_cursor_row: Class handler for the #GtkListBox::activate-cursor-row signal
58  * @toggle_cursor_row: Class handler for the #GtkListBox::toggle-cursor-row signal
59  * @move_cursor: Class handler for the #GtkListBox::move-cursor signal
60  * @selected_rows_changed: Class handler for the #GtkListBox::selected-rows-changed signal
61  * @select_all: Class handler for the #GtkListBox::select-all signal
62  * @unselect_all: Class handler for the #GtkListBox::unselect-all signal
63  */
64 struct _GtkListBoxClass
65 {
66   GtkContainerClass parent_class;
67 
68   /*< public >*/
69 
70   void (*row_selected)        (GtkListBox      *box,
71                                GtkListBoxRow   *row);
72   void (*row_activated)       (GtkListBox      *box,
73                                GtkListBoxRow   *row);
74   void (*activate_cursor_row) (GtkListBox      *box);
75   void (*toggle_cursor_row)   (GtkListBox      *box);
76   void (*move_cursor)         (GtkListBox      *box,
77                                GtkMovementStep  step,
78                                gint             count);
79   void (*selected_rows_changed) (GtkListBox    *box);
80   void (*select_all)            (GtkListBox    *box);
81   void (*unselect_all)          (GtkListBox    *box);
82 
83   /*< private >*/
84 
85   /* Padding for future expansion */
86   void (*_gtk_reserved1) (void);
87   void (*_gtk_reserved2) (void);
88   void (*_gtk_reserved3) (void);
89 };
90 
91 #define GTK_TYPE_LIST_BOX_ROW            (gtk_list_box_row_get_type ())
92 #define GTK_LIST_BOX_ROW(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_LIST_BOX_ROW, GtkListBoxRow))
93 #define GTK_LIST_BOX_ROW_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_LIST_BOX_ROW, GtkListBoxRowClass))
94 #define GTK_IS_LIST_BOX_ROW(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_LIST_BOX_ROW))
95 #define GTK_IS_LIST_BOX_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_LIST_BOX_ROW))
96 #define GTK_LIST_BOX_ROW_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_LIST_BOX_ROW, GtkListBoxRowClass))
97 
98 struct _GtkListBoxRow
99 {
100   GtkBin parent_instance;
101 };
102 
103 /**
104  * GtkListBoxRowClass:
105  * @parent_class: The parent class.
106  * @activate:
107  */
108 struct _GtkListBoxRowClass
109 {
110   GtkBinClass parent_class;
111 
112   /*< public >*/
113 
114   void (* activate) (GtkListBoxRow *row);
115 
116   /*< private >*/
117 
118   /* Padding for future expansion */
119   void (*_gtk_reserved1) (void);
120   void (*_gtk_reserved2) (void);
121 };
122 
123 /**
124  * GtkListBoxFilterFunc:
125  * @row: the row that may be filtered
126  * @user_data: (closure): user data
127  *
128  * Will be called whenever the row changes or is added and lets you control
129  * if the row should be visible or not.
130  *
131  * Returns: %TRUE if the row should be visible, %FALSE otherwise
132  *
133  * Since: 3.10
134  */
135 typedef gboolean (*GtkListBoxFilterFunc) (GtkListBoxRow *row,
136                                           gpointer       user_data);
137 
138 /**
139  * GtkListBoxSortFunc:
140  * @row1: the first row
141  * @row2: the second row
142  * @user_data: (closure): user data
143  *
144  * Compare two rows to determine which should be first.
145  *
146  * Returns: < 0 if @row1 should be before @row2, 0 if they are
147  *     equal and > 0 otherwise
148  *
149  * Since: 3.10
150  */
151 typedef gint (*GtkListBoxSortFunc) (GtkListBoxRow *row1,
152                                     GtkListBoxRow *row2,
153                                     gpointer       user_data);
154 
155 /**
156  * GtkListBoxUpdateHeaderFunc:
157  * @row: the row to update
158  * @before: (allow-none): the row before @row, or %NULL if it is first
159  * @user_data: (closure): user data
160  *
161  * Whenever @row changes or which row is before @row changes this
162  * is called, which lets you update the header on @row. You may
163  * remove or set a new one via gtk_list_box_row_set_header() or
164  * just change the state of the current header widget.
165  *
166  * Since: 3.10
167  */
168 typedef void (*GtkListBoxUpdateHeaderFunc) (GtkListBoxRow *row,
169                                             GtkListBoxRow *before,
170                                             gpointer       user_data);
171 
172 /**
173  * GtkListBoxCreateWidgetFunc:
174  * @item: (type GObject): the item from the model for which to create a widget for
175  * @user_data: (closure): user data
176  *
177  * Called for list boxes that are bound to a #GListModel with
178  * gtk_list_box_bind_model() for each item that gets added to the model.
179  *
180  * Versions of GTK+ prior to 3.18 called gtk_widget_show_all() on the rows
181  * created by the GtkListBoxCreateWidgetFunc, but this forced all widgets
182  * inside the row to be shown, and is no longer the case. Applications should
183  * be updated to show the desired row widgets.
184  *
185  * Returns: (transfer full): a #GtkWidget that represents @item
186  *
187  * Since: 3.16
188  */
189 typedef GtkWidget * (*GtkListBoxCreateWidgetFunc) (gpointer item,
190                                                    gpointer user_data);
191 
192 GDK_AVAILABLE_IN_3_10
193 GType      gtk_list_box_row_get_type      (void) G_GNUC_CONST;
194 GDK_AVAILABLE_IN_3_10
195 GtkWidget* gtk_list_box_row_new           (void);
196 GDK_AVAILABLE_IN_3_10
197 GtkWidget* gtk_list_box_row_get_header    (GtkListBoxRow *row);
198 GDK_AVAILABLE_IN_3_10
199 void       gtk_list_box_row_set_header    (GtkListBoxRow *row,
200                                            GtkWidget     *header);
201 GDK_AVAILABLE_IN_3_10
202 gint       gtk_list_box_row_get_index     (GtkListBoxRow *row);
203 GDK_AVAILABLE_IN_3_10
204 void       gtk_list_box_row_changed       (GtkListBoxRow *row);
205 
206 GDK_AVAILABLE_IN_3_14
207 gboolean   gtk_list_box_row_is_selected   (GtkListBoxRow *row);
208 
209 GDK_AVAILABLE_IN_3_14
210 void       gtk_list_box_row_set_selectable (GtkListBoxRow *row,
211                                             gboolean       selectable);
212 GDK_AVAILABLE_IN_3_14
213 gboolean   gtk_list_box_row_get_selectable (GtkListBoxRow *row);
214 
215 
216 GDK_AVAILABLE_IN_3_14
217 void       gtk_list_box_row_set_activatable (GtkListBoxRow *row,
218                                              gboolean       activatable);
219 GDK_AVAILABLE_IN_3_14
220 gboolean   gtk_list_box_row_get_activatable (GtkListBoxRow *row);
221 
222 GDK_AVAILABLE_IN_3_10
223 GType          gtk_list_box_get_type                     (void) G_GNUC_CONST;
224 GDK_AVAILABLE_IN_3_10
225 void           gtk_list_box_prepend                      (GtkListBox                    *box,
226                                                           GtkWidget                     *child);
227 GDK_AVAILABLE_IN_3_10
228 void           gtk_list_box_insert                       (GtkListBox                    *box,
229                                                           GtkWidget                     *child,
230                                                           gint                           position);
231 GDK_AVAILABLE_IN_3_10
232 GtkListBoxRow* gtk_list_box_get_selected_row             (GtkListBox                    *box);
233 GDK_AVAILABLE_IN_3_10
234 GtkListBoxRow* gtk_list_box_get_row_at_index             (GtkListBox                    *box,
235                                                           gint                           index_);
236 GDK_AVAILABLE_IN_3_10
237 GtkListBoxRow* gtk_list_box_get_row_at_y                 (GtkListBox                    *box,
238                                                           gint                           y);
239 GDK_AVAILABLE_IN_3_10
240 void           gtk_list_box_select_row                   (GtkListBox                    *box,
241                                                           GtkListBoxRow                 *row);
242 GDK_AVAILABLE_IN_3_10
243 void           gtk_list_box_set_placeholder              (GtkListBox                    *box,
244                                                           GtkWidget                     *placeholder);
245 GDK_AVAILABLE_IN_3_10
246 void           gtk_list_box_set_adjustment               (GtkListBox                    *box,
247                                                           GtkAdjustment                 *adjustment);
248 GDK_AVAILABLE_IN_3_10
249 GtkAdjustment *gtk_list_box_get_adjustment               (GtkListBox                    *box);
250 
251 typedef void (* GtkListBoxForeachFunc) (GtkListBox      *box,
252                                         GtkListBoxRow   *row,
253                                         gpointer         user_data);
254 
255 GDK_AVAILABLE_IN_3_14
256 void           gtk_list_box_selected_foreach             (GtkListBox                    *box,
257                                                           GtkListBoxForeachFunc          func,
258                                                           gpointer                       data);
259 GDK_AVAILABLE_IN_3_14
260 GList         *gtk_list_box_get_selected_rows            (GtkListBox                    *box);
261 GDK_AVAILABLE_IN_3_14
262 void           gtk_list_box_unselect_row                 (GtkListBox                    *box,
263                                                           GtkListBoxRow                 *row);
264 GDK_AVAILABLE_IN_3_14
265 void           gtk_list_box_select_all                   (GtkListBox                    *box);
266 GDK_AVAILABLE_IN_3_14
267 void           gtk_list_box_unselect_all                 (GtkListBox                    *box);
268 
269 GDK_AVAILABLE_IN_3_10
270 void           gtk_list_box_set_selection_mode           (GtkListBox                    *box,
271                                                           GtkSelectionMode               mode);
272 GDK_AVAILABLE_IN_3_10
273 GtkSelectionMode gtk_list_box_get_selection_mode         (GtkListBox                    *box);
274 GDK_AVAILABLE_IN_3_10
275 void           gtk_list_box_set_filter_func              (GtkListBox                    *box,
276                                                           GtkListBoxFilterFunc           filter_func,
277                                                           gpointer                       user_data,
278                                                           GDestroyNotify                 destroy);
279 GDK_AVAILABLE_IN_3_10
280 void           gtk_list_box_set_header_func              (GtkListBox                    *box,
281                                                           GtkListBoxUpdateHeaderFunc     update_header,
282                                                           gpointer                       user_data,
283                                                           GDestroyNotify                 destroy);
284 GDK_AVAILABLE_IN_3_10
285 void           gtk_list_box_invalidate_filter            (GtkListBox                    *box);
286 GDK_AVAILABLE_IN_3_10
287 void           gtk_list_box_invalidate_sort              (GtkListBox                    *box);
288 GDK_AVAILABLE_IN_3_10
289 void           gtk_list_box_invalidate_headers           (GtkListBox                    *box);
290 GDK_AVAILABLE_IN_3_10
291 void           gtk_list_box_set_sort_func                (GtkListBox                    *box,
292                                                           GtkListBoxSortFunc             sort_func,
293                                                           gpointer                       user_data,
294                                                           GDestroyNotify                 destroy);
295 GDK_AVAILABLE_IN_3_10
296 void           gtk_list_box_set_activate_on_single_click (GtkListBox                    *box,
297                                                           gboolean                       single);
298 GDK_AVAILABLE_IN_3_10
299 gboolean       gtk_list_box_get_activate_on_single_click (GtkListBox                    *box);
300 GDK_AVAILABLE_IN_3_10
301 void           gtk_list_box_drag_unhighlight_row         (GtkListBox                    *box);
302 GDK_AVAILABLE_IN_3_10
303 void           gtk_list_box_drag_highlight_row           (GtkListBox                    *box,
304                                                           GtkListBoxRow                 *row);
305 GDK_AVAILABLE_IN_3_10
306 GtkWidget*     gtk_list_box_new                          (void);
307 
308 
309 GDK_AVAILABLE_IN_3_16
310 void           gtk_list_box_bind_model                   (GtkListBox                   *box,
311                                                           GListModel                   *model,
312                                                           GtkListBoxCreateWidgetFunc    create_widget_func,
313                                                           gpointer                      user_data,
314                                                           GDestroyNotify                user_data_free_func);
315 
316 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkListBox, g_object_unref)
317 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkListBoxRow, g_object_unref)
318 
319 G_END_DECLS
320 
321 #endif
322