gtklistbox.h 14 KB
Newer Older
Alexander Larsson's avatar
Alexander Larsson committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/*
 * Copyright (c) 2013 Red Hat, Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Author: Alexander Larsson <alexl@redhat.com>
 *
 */

#ifndef __GTK_LIST_BOX_H__
#define __GTK_LIST_BOX_H__

#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
#error "Only <gtk/gtk.h> can be included directly."
#endif

Matthias Clasen's avatar
Matthias Clasen committed
29
#include <gtk/gtkbin.h>
Alexander Larsson's avatar
Alexander Larsson committed
30 31 32 33 34 35 36 37 38 39 40

G_BEGIN_DECLS


#define GTK_TYPE_LIST_BOX (gtk_list_box_get_type ())
#define GTK_LIST_BOX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_LIST_BOX, GtkListBox))
#define GTK_LIST_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_LIST_BOX, GtkListBoxClass))
#define GTK_IS_LIST_BOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_LIST_BOX))
#define GTK_IS_LIST_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_LIST_BOX))
#define GTK_LIST_BOX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_LIST_BOX, GtkListBoxClass))

Matthias Clasen's avatar
Matthias Clasen committed
41 42
typedef struct _GtkListBox        GtkListBox;
typedef struct _GtkListBoxClass   GtkListBoxClass;
Alexander Larsson's avatar
Alexander Larsson committed
43

Matthias Clasen's avatar
Matthias Clasen committed
44 45
typedef struct _GtkListBoxRow        GtkListBoxRow;
typedef struct _GtkListBoxRowClass   GtkListBoxRowClass;
Alexander Larsson's avatar
Alexander Larsson committed
46 47 48 49 50 51

struct _GtkListBox
{
  GtkContainer parent_instance;
};

52 53 54
/**
 * GtkListBoxClass:
 * @parent_class: The parent class.
55 56 57
 * @row_selected: Class handler for the #GtkListBox::row-selected signal
 * @row_activated: Class handler for the #GtkListBox::row-activated signal
 * @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 60 61 62
 * @move_cursor: Class handler for the #GtkListBox::move-cursor signal
 * @selected_rows_changed: Class handler for the #GtkListBox::selected-rows-changed signal
 * @select_all: Class handler for the #GtkListBox::select-all signal
 * @unselect_all: Class handler for the #GtkListBox::unselect-all signal
63
 */
Alexander Larsson's avatar
Alexander Larsson committed
64 65 66 67
struct _GtkListBoxClass
{
  GtkContainerClass parent_class;

68 69
  /*< public >*/

70
  void (*row_selected)        (GtkListBox      *box,
Matthias Clasen's avatar
Matthias Clasen committed
71
                               GtkListBoxRow   *row);
72
  void (*row_activated)       (GtkListBox      *box,
Matthias Clasen's avatar
Matthias Clasen committed
73
                               GtkListBoxRow   *row);
74 75 76
  void (*activate_cursor_row) (GtkListBox      *box);
  void (*toggle_cursor_row)   (GtkListBox      *box);
  void (*move_cursor)         (GtkListBox      *box,
Matthias Clasen's avatar
Matthias Clasen committed
77 78
                               GtkMovementStep  step,
                               gint             count);
79 80 81
  void (*selected_rows_changed) (GtkListBox    *box);
  void (*select_all)            (GtkListBox    *box);
  void (*unselect_all)          (GtkListBox    *box);
Alexander Larsson's avatar
Alexander Larsson committed
82

83 84
  /*< private >*/

Alexander Larsson's avatar
Alexander Larsson committed
85 86 87 88 89 90
  /* Padding for future expansion */
  void (*_gtk_reserved1) (void);
  void (*_gtk_reserved2) (void);
  void (*_gtk_reserved3) (void);
};

Matthias Clasen's avatar
Matthias Clasen committed
91 92 93 94
#define GTK_TYPE_LIST_BOX_ROW            (gtk_list_box_row_get_type ())
#define GTK_LIST_BOX_ROW(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_LIST_BOX_ROW, GtkListBoxRow))
#define GTK_LIST_BOX_ROW_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_LIST_BOX_ROW, GtkListBoxRowClass))
#define GTK_IS_LIST_BOX_ROW(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_LIST_BOX_ROW))
Alexander Larsson's avatar
Alexander Larsson committed
95
#define GTK_IS_LIST_BOX_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_LIST_BOX_ROW))
Matthias Clasen's avatar
Matthias Clasen committed
96
#define GTK_LIST_BOX_ROW_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_LIST_BOX_ROW, GtkListBoxRowClass))
Alexander Larsson's avatar
Alexander Larsson committed
97 98 99 100 101 102

struct _GtkListBoxRow
{
  GtkBin parent_instance;
};

103 104 105 106 107
/**
 * GtkListBoxRowClass:
 * @parent_class: The parent class.
 * @activate: 
 */
Alexander Larsson's avatar
Alexander Larsson committed
108 109 110 111
struct _GtkListBoxRowClass
{
  GtkBinClass parent_class;

112 113
  /*< public >*/

114 115
  void (* activate) (GtkListBoxRow *row);

116 117
  /*< private >*/

Alexander Larsson's avatar
Alexander Larsson committed
118 119 120 121 122
  /* Padding for future expansion */
  void (*_gtk_reserved1) (void);
  void (*_gtk_reserved2) (void);
};

Alexander Larsson's avatar
Alexander Larsson committed
123 124
/**
 * GtkListBoxFilterFunc:
Matthias Clasen's avatar
Matthias Clasen committed
125 126
 * @row: the row that may be filtered
 * @user_data: (closure): user data
Alexander Larsson's avatar
Alexander Larsson committed
127 128 129 130 131 132 133 134
 *
 * Will be called whenever the row changes or is added and lets you control
 * if the row should be visible or not.
 *
 * Returns: %TRUE if the row should be visible, %FALSE otherwise
 *
 * Since: 3.10
 */
Matthias Clasen's avatar
Matthias Clasen committed
135 136 137
typedef gboolean (*GtkListBoxFilterFunc) (GtkListBoxRow *row,
                                          gpointer       user_data);

Alexander Larsson's avatar
Alexander Larsson committed
138 139
/**
 * GtkListBoxSortFunc:
Matthias Clasen's avatar
Matthias Clasen committed
140 141 142
 * @row1: the first row
 * @row2: the second row
 * @user_data: (closure): user data
Alexander Larsson's avatar
Alexander Larsson committed
143
 *
Matthias Clasen's avatar
Matthias Clasen committed
144
 * Compare two rows to determine which should be first.
Alexander Larsson's avatar
Alexander Larsson committed
145
 *
Matthias Clasen's avatar
Matthias Clasen committed
146 147
 * Returns: < 0 if @row1 should be before @row2, 0 if they are
 *     equal and > 0 otherwise
Alexander Larsson's avatar
Alexander Larsson committed
148 149 150 151 152 153
 *
 * Since: 3.10
 */
typedef gint (*GtkListBoxSortFunc) (GtkListBoxRow *row1,
                                    GtkListBoxRow *row2,
                                    gpointer       user_data);
Matthias Clasen's avatar
Matthias Clasen committed
154

Alexander Larsson's avatar
Alexander Larsson committed
155
/**
156
 * GtkListBoxUpdateHeaderFunc:
Matthias Clasen's avatar
Matthias Clasen committed
157
 * @row: the row to update
158
 * @before: (allow-none): the row before @row, or %NULL if it is first
Matthias Clasen's avatar
Matthias Clasen committed
159
 * @user_data: (closure): user data
Alexander Larsson's avatar
Alexander Larsson committed
160
 *
Matthias Clasen's avatar
Matthias Clasen committed
161 162 163 164
 * Whenever @row changes or which row is before @row changes this
 * is called, which lets you update the header on @row. You may
 * remove or set a new one via gtk_list_box_row_set_header() or
 * just change the state of the current header widget.
Alexander Larsson's avatar
Alexander Larsson committed
165 166 167
 *
 * Since: 3.10
 */
168 169 170
typedef void (*GtkListBoxUpdateHeaderFunc) (GtkListBoxRow *row,
                                            GtkListBoxRow *before,
                                            gpointer       user_data);
Alexander Larsson's avatar
Alexander Larsson committed
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 178 179
 *
 * Called for list boxes that are bound to a #GListModel with
 * gtk_list_box_bind_model() for each item that gets added to the model.
 *
180 181 182 183 184
 * Versions of GTK+ prior to 3.18 called gtk_widget_show_all() on the rows
 * created by the GtkListBoxCreateWidgetFunc, but this forced all widgets
 * inside the row to be shown, and is no longer the case. Applications should
 * be updated to show the desired row widgets.
 *
185
 * Returns: (transfer full): a #GtkWidget that represents @item
186 187 188 189 190 191
 *
 * Since: 3.16
 */
typedef GtkWidget * (*GtkListBoxCreateWidgetFunc) (gpointer item,
                                                   gpointer user_data);

Alexander Larsson's avatar
Alexander Larsson committed
192 193 194 195 196
GDK_AVAILABLE_IN_3_10
GType      gtk_list_box_row_get_type      (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_3_10
GtkWidget* gtk_list_box_row_new           (void);
GDK_AVAILABLE_IN_3_10
197
GtkWidget* gtk_list_box_row_get_header    (GtkListBoxRow *row);
Alexander Larsson's avatar
Alexander Larsson committed
198
GDK_AVAILABLE_IN_3_10
199 200
void       gtk_list_box_row_set_header    (GtkListBoxRow *row,
                                           GtkWidget     *header);
Alexander Larsson's avatar
Alexander Larsson committed
201
GDK_AVAILABLE_IN_3_10
202 203
gint       gtk_list_box_row_get_index     (GtkListBoxRow *row);
GDK_AVAILABLE_IN_3_10
Alexander Larsson's avatar
Alexander Larsson committed
204 205
void       gtk_list_box_row_changed       (GtkListBoxRow *row);

206 207
GDK_AVAILABLE_IN_3_14
gboolean   gtk_list_box_row_is_selected   (GtkListBoxRow *row);
Alexander Larsson's avatar
Alexander Larsson committed
208

209 210 211 212 213 214 215
GDK_AVAILABLE_IN_3_14
void       gtk_list_box_row_set_selectable (GtkListBoxRow *row,
                                            gboolean       selectable);
GDK_AVAILABLE_IN_3_14
gboolean   gtk_list_box_row_get_selectable (GtkListBoxRow *row);


216 217 218 219 220 221
GDK_AVAILABLE_IN_3_14
void       gtk_list_box_row_set_activatable (GtkListBoxRow *row,
                                             gboolean       activatable);
GDK_AVAILABLE_IN_3_14
gboolean   gtk_list_box_row_get_activatable (GtkListBoxRow *row);

Alexander Larsson's avatar
Alexander Larsson committed
222 223 224
GDK_AVAILABLE_IN_3_10
GType          gtk_list_box_get_type                     (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_3_10
225
void           gtk_list_box_prepend                      (GtkListBox                    *box,
Paolo Borelli's avatar
Paolo Borelli committed
226 227
                                                          GtkWidget                     *child);
GDK_AVAILABLE_IN_3_10
228
void           gtk_list_box_insert                       (GtkListBox                    *box,
229 230 231
                                                          GtkWidget                     *child,
                                                          gint                           position);
GDK_AVAILABLE_IN_3_10
232
GtkListBoxRow* gtk_list_box_get_selected_row             (GtkListBox                    *box);
Alexander Larsson's avatar
Alexander Larsson committed
233
GDK_AVAILABLE_IN_3_10
234
GtkListBoxRow* gtk_list_box_get_row_at_index             (GtkListBox                    *box,
Matthias Clasen's avatar
Matthias Clasen committed
235
                                                          gint                           index_);
Alexander Larsson's avatar
Alexander Larsson committed
236
GDK_AVAILABLE_IN_3_10
237
GtkListBoxRow* gtk_list_box_get_row_at_y                 (GtkListBox                    *box,
Alexander Larsson's avatar
Alexander Larsson committed
238 239
                                                          gint                           y);
GDK_AVAILABLE_IN_3_10
240
void           gtk_list_box_select_row                   (GtkListBox                    *box,
Alexander Larsson's avatar
Alexander Larsson committed
241 242
                                                          GtkListBoxRow                 *row);
GDK_AVAILABLE_IN_3_10
243
void           gtk_list_box_set_placeholder              (GtkListBox                    *box,
244 245
                                                          GtkWidget                     *placeholder);
GDK_AVAILABLE_IN_3_10
246
void           gtk_list_box_set_adjustment               (GtkListBox                    *box,
Alexander Larsson's avatar
Alexander Larsson committed
247 248
                                                          GtkAdjustment                 *adjustment);
GDK_AVAILABLE_IN_3_10
249
GtkAdjustment *gtk_list_box_get_adjustment               (GtkListBox                    *box);
250 251 252 253 254 255

typedef void (* GtkListBoxForeachFunc) (GtkListBox      *box,
                                        GtkListBoxRow   *row,
                                        gpointer         user_data);

GDK_AVAILABLE_IN_3_14
256
void           gtk_list_box_selected_foreach             (GtkListBox                    *box,
257 258 259
                                                          GtkListBoxForeachFunc          func,
                                                          gpointer                       data);
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 264
                                                          GtkListBoxRow                 *row);
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

Alexander Larsson's avatar
Alexander Larsson committed
269
GDK_AVAILABLE_IN_3_10
270
void           gtk_list_box_set_selection_mode           (GtkListBox                    *box,
Alexander Larsson's avatar
Alexander Larsson committed
271 272
                                                          GtkSelectionMode               mode);
GDK_AVAILABLE_IN_3_10
273
GtkSelectionMode gtk_list_box_get_selection_mode         (GtkListBox                    *box);
Alexander Larsson's avatar
Alexander Larsson committed
274
GDK_AVAILABLE_IN_3_10
275
void           gtk_list_box_set_filter_func              (GtkListBox                    *box,
Alexander Larsson's avatar
Alexander Larsson committed
276 277 278 279
                                                          GtkListBoxFilterFunc           filter_func,
                                                          gpointer                       user_data,
                                                          GDestroyNotify                 destroy);
GDK_AVAILABLE_IN_3_10
280
void           gtk_list_box_set_header_func              (GtkListBox                    *box,
281
                                                          GtkListBoxUpdateHeaderFunc     update_header,
Alexander Larsson's avatar
Alexander Larsson committed
282 283 284
                                                          gpointer                       user_data,
                                                          GDestroyNotify                 destroy);
GDK_AVAILABLE_IN_3_10
285
void           gtk_list_box_invalidate_filter            (GtkListBox                    *box);
Alexander Larsson's avatar
Alexander Larsson committed
286
GDK_AVAILABLE_IN_3_10
287
void           gtk_list_box_invalidate_sort              (GtkListBox                    *box);
Alexander Larsson's avatar
Alexander Larsson committed
288
GDK_AVAILABLE_IN_3_10
289
void           gtk_list_box_invalidate_headers           (GtkListBox                    *box);
Alexander Larsson's avatar
Alexander Larsson committed
290
GDK_AVAILABLE_IN_3_10
291
void           gtk_list_box_set_sort_func                (GtkListBox                    *box,
Alexander Larsson's avatar
Alexander Larsson committed
292 293 294 295
                                                          GtkListBoxSortFunc             sort_func,
                                                          gpointer                       user_data,
                                                          GDestroyNotify                 destroy);
GDK_AVAILABLE_IN_3_10
296
void           gtk_list_box_set_activate_on_single_click (GtkListBox                    *box,
Alexander Larsson's avatar
Alexander Larsson committed
297 298
                                                          gboolean                       single);
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);
Alexander Larsson's avatar
Alexander Larsson committed
302
GDK_AVAILABLE_IN_3_10
303
void           gtk_list_box_drag_highlight_row           (GtkListBox                    *box,
Alexander Larsson's avatar
Alexander Larsson committed
304 305 306 307 308
                                                          GtkListBoxRow                 *row);
GDK_AVAILABLE_IN_3_10
GtkWidget*     gtk_list_box_new                          (void);


309 310 311 312 313 314
GDK_AVAILABLE_IN_3_16
void           gtk_list_box_bind_model                   (GtkListBox                   *box,
                                                          GListModel                   *model,
                                                          GtkListBoxCreateWidgetFunc    create_widget_func,
                                                          gpointer                      user_data,
                                                          GDestroyNotify                user_data_free_func);
315

316 317 318
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkListBox, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkListBoxRow, g_object_unref)

Alexander Larsson's avatar
Alexander Larsson committed
319 320 321
G_END_DECLS

#endif