10708
|
1 /* gtkcombobox.c
|
|
2 * Copyright (C) 2002, 2003 Kristian Rietveld <kris@gtk.org>
|
|
3 *
|
|
4 * This library is free software; you can redistribute it and/or
|
|
5 * modify it under the terms of the GNU Library General Public
|
|
6 * License as published by the Free Software Foundation; either
|
|
7 * version 2 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 * Library General Public License for more details.
|
|
13 *
|
|
14 * You should have received a copy of the GNU Library General Public
|
|
15 * License along with this library; if not, write to the
|
|
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
17 * Boston, MA 02111-1307, USA.
|
|
18 */
|
|
19
|
|
20 /*
|
|
21 #include <config.h>
|
|
22 */
|
|
23 #include <gtk/gtkversion.h>
|
|
24 #if !GTK_CHECK_VERSION(2,4,0)
|
|
25 #include "gtkcombobox.h"
|
|
26
|
|
27 #include <gtk/gtkarrow.h>
|
|
28 #include <gtk/gtkbindings.h>
|
|
29 #include "gtkcelllayout.h"
|
|
30 #include <gtk/gtkcellrenderertext.h>
|
|
31 #include "gtkcellview.h"
|
|
32 #include "gtkcellviewmenuitem.h"
|
|
33 #include <gtk/gtkeventbox.h>
|
|
34 #include <gtk/gtkframe.h>
|
|
35 #include <gtk/gtkhbox.h>
|
|
36 #include <gtk/gtkliststore.h>
|
|
37 #include <gtk/gtkmain.h>
|
|
38 #include <gtk/gtkmenu.h>
|
|
39 #include <gtk/gtktogglebutton.h>
|
|
40 #include <gtk/gtktreeselection.h>
|
|
41 /*
|
|
42 #include <gtk/gtktreeprivate.h>
|
|
43 */
|
|
44 #include <gtk/gtkvseparator.h>
|
|
45 #include <gtk/gtkwindow.h>
|
11780
|
46 #include <gtk/gtkversion.h>
|
10708
|
47
|
|
48 #include <gdk/gdkkeysyms.h>
|
|
49
|
|
50 #include <gobject/gvaluecollector.h>
|
|
51
|
|
52 #include <string.h>
|
|
53 #include <stdarg.h>
|
|
54
|
|
55 #ifdef ENABLE_NLS
|
|
56 # include <libintl.h>
|
|
57 # define _(x) gettext(x)
|
|
58 # ifdef gettext_noop
|
|
59 # define N_(String) gettext_noop (String)
|
|
60 # else
|
|
61 # define N_(String) (String)
|
|
62 # endif
|
|
63 #else
|
|
64 # define N_(String) (String)
|
|
65 # define _(x) (x)
|
|
66 #endif
|
|
67
|
|
68 /* WELCOME, to THE house of evil code */
|
|
69
|
|
70 typedef struct _ComboCellInfo ComboCellInfo;
|
|
71 struct _ComboCellInfo
|
|
72 {
|
|
73 GtkCellRenderer *cell;
|
|
74 GSList *attributes;
|
|
75
|
|
76 GtkCellLayoutDataFunc func;
|
|
77 gpointer func_data;
|
|
78 GDestroyNotify destroy;
|
|
79
|
|
80 guint expand : 1;
|
|
81 guint pack : 1;
|
|
82 };
|
|
83
|
|
84 struct _GtkComboBoxPrivate
|
|
85 {
|
|
86 GtkTreeModel *model;
|
|
87
|
|
88 gint col_column;
|
|
89 gint row_column;
|
|
90
|
|
91 gint wrap_width;
|
|
92
|
|
93 gint active_item;
|
|
94
|
|
95 GtkWidget *tree_view;
|
|
96 GtkTreeViewColumn *column;
|
|
97
|
|
98 GtkWidget *cell_view;
|
|
99 GtkWidget *cell_view_frame;
|
|
100
|
|
101 GtkWidget *button;
|
|
102 GtkWidget *box;
|
|
103 GtkWidget *arrow;
|
|
104 GtkWidget *separator;
|
|
105
|
|
106 GtkWidget *popup_widget;
|
|
107 GtkWidget *popup_window;
|
|
108 GtkWidget *popup_frame;
|
|
109
|
|
110 guint inserted_id;
|
|
111 guint deleted_id;
|
|
112 guint reordered_id;
|
|
113 guint changed_id;
|
|
114
|
|
115 gint width;
|
|
116 GSList *cells;
|
|
117
|
|
118 guint popup_in_progress : 1;
|
|
119 guint destroying : 1;
|
|
120 };
|
|
121
|
|
122 /* While debugging this evil code, I have learned that
|
|
123 * there are actually 4 modes to this widget, which can
|
|
124 * be characterized as follows
|
|
125 *
|
|
126 * 1) menu mode, no child added
|
|
127 *
|
|
128 * tree_view -> NULL
|
|
129 * cell_view -> GtkCellView, regular child
|
|
130 * cell_view_frame -> NULL
|
|
131 * button -> GtkToggleButton set_parent to combo
|
|
132 * box -> child of button
|
|
133 * arrow -> child of box
|
|
134 * separator -> child of box
|
|
135 * popup_widget -> GtkMenu
|
|
136 * popup_window -> NULL
|
|
137 * popup_frame -> NULL
|
|
138 *
|
|
139 * 2) menu mode, child added
|
|
140 *
|
|
141 * tree_view -> NULL
|
|
142 * cell_view -> NULL
|
|
143 * cell_view_frame -> NULL
|
|
144 * button -> GtkToggleButton set_parent to combo
|
|
145 * box -> NULL
|
|
146 * arrow -> GtkArrow, child of button
|
|
147 * separator -> NULL
|
|
148 * popup_widget -> GtkMenu
|
|
149 * popup_window -> NULL
|
|
150 * popup_frame -> NULL
|
|
151 *
|
|
152 * 3) list mode, no child added
|
|
153 *
|
|
154 * tree_view -> GtkTreeView, child of popup_frame
|
|
155 * cell_view -> GtkCellView, regular child
|
|
156 * cell_view_frame -> GtkFrame, set parent to combo
|
|
157 * button -> GtkToggleButton, set_parent to combo
|
|
158 * box -> NULL
|
|
159 * arrow -> GtkArrow, child of button
|
|
160 * separator -> NULL
|
|
161 * popup_widget -> tree_view
|
|
162 * popup_window -> GtkWindow
|
|
163 * popup_frame -> GtkFrame, child of popup_window
|
|
164 *
|
|
165 * 4) list mode, child added
|
|
166 *
|
|
167 * tree_view -> GtkTreeView, child of popup_frame
|
|
168 * cell_view -> NULL
|
|
169 * cell_view_frame -> NULL
|
|
170 * button -> GtkToggleButton, set_parent to combo
|
|
171 * box -> NULL
|
|
172 * arrow -> GtkArrow, child of button
|
|
173 * separator -> NULL
|
|
174 * popup_widget -> tree_view
|
|
175 * popup_window -> GtkWindow
|
|
176 * popup_frame -> GtkFrame, child of popup_window
|
|
177 *
|
|
178 */
|
|
179
|
|
180 enum {
|
|
181 CHANGED,
|
|
182 LAST_SIGNAL
|
|
183 };
|
|
184
|
|
185 enum {
|
|
186 PROP_0,
|
|
187 PROP_MODEL,
|
|
188 PROP_WRAP_WIDTH,
|
|
189 PROP_ROW_SPAN_COLUMN,
|
|
190 PROP_COLUMN_SPAN_COLUMN,
|
|
191 PROP_ACTIVE
|
|
192 };
|
|
193
|
|
194 static GtkBinClass *parent_class = NULL;
|
|
195 static guint combo_box_signals[LAST_SIGNAL] = {0,};
|
|
196
|
|
197 #define BONUS_PADDING 4
|
|
198
|
|
199
|
|
200 /* common */
|
|
201 static void gtk_combo_box_class_init (GtkComboBoxClass *klass);
|
|
202 static void gtk_combo_box_cell_layout_init (GtkCellLayoutIface *iface);
|
|
203 static void gtk_combo_box_init (GtkComboBox *combo_box);
|
|
204 static void gtk_combo_box_finalize (GObject *object);
|
|
205 static void gtk_combo_box_destroy (GtkObject *object);
|
|
206
|
|
207 static void gtk_combo_box_set_property (GObject *object,
|
|
208 guint prop_id,
|
|
209 const GValue *value,
|
|
210 GParamSpec *spec);
|
|
211 static void gtk_combo_box_get_property (GObject *object,
|
|
212 guint prop_id,
|
|
213 GValue *value,
|
|
214 GParamSpec *spec);
|
|
215
|
|
216 static void gtk_combo_box_state_changed (GtkWidget *widget,
|
|
217 GtkStateType previous);
|
|
218 static void gtk_combo_box_style_set (GtkWidget *widget,
|
|
219 GtkStyle *previous);
|
|
220 static void gtk_combo_box_button_toggled (GtkWidget *widget,
|
|
221 gpointer data);
|
|
222 static void gtk_combo_box_add (GtkContainer *container,
|
|
223 GtkWidget *widget);
|
|
224 static void gtk_combo_box_remove (GtkContainer *container,
|
|
225 GtkWidget *widget);
|
|
226
|
|
227 static ComboCellInfo *gtk_combo_box_get_cell_info (GtkComboBox *combo_box,
|
|
228 GtkCellRenderer *cell);
|
|
229
|
|
230 static void gtk_combo_box_menu_show (GtkWidget *menu,
|
|
231 gpointer user_data);
|
|
232 static void gtk_combo_box_menu_hide (GtkWidget *menu,
|
|
233 gpointer user_data);
|
|
234
|
|
235 static void gtk_combo_box_set_popup_widget (GtkComboBox *combo_box,
|
|
236 GtkWidget *popup);
|
11780
|
237 #if GTK_CHECK_VERSION(2,2,0)
|
10708
|
238 static void gtk_combo_box_menu_position_below (GtkMenu *menu,
|
|
239 gint *x,
|
|
240 gint *y,
|
|
241 gint *push_in,
|
|
242 gpointer user_data);
|
|
243 static void gtk_combo_box_menu_position_over (GtkMenu *menu,
|
|
244 gint *x,
|
|
245 gint *y,
|
|
246 gint *push_in,
|
|
247 gpointer user_data);
|
|
248 static void gtk_combo_box_menu_position (GtkMenu *menu,
|
|
249 gint *x,
|
|
250 gint *y,
|
|
251 gint *push_in,
|
|
252 gpointer user_data);
|
11780
|
253 #endif
|
10708
|
254
|
|
255 static gint gtk_combo_box_calc_requested_width (GtkComboBox *combo_box,
|
|
256 GtkTreePath *path);
|
|
257 static void gtk_combo_box_remeasure (GtkComboBox *combo_box);
|
|
258
|
|
259 static void gtk_combo_box_unset_model (GtkComboBox *combo_box);
|
|
260
|
|
261 static void gtk_combo_box_size_request (GtkWidget *widget,
|
|
262 GtkRequisition *requisition);
|
|
263 static void gtk_combo_box_size_allocate (GtkWidget *widget,
|
|
264 GtkAllocation *allocation);
|
|
265 static void gtk_combo_box_forall (GtkContainer *container,
|
|
266 gboolean include_internals,
|
|
267 GtkCallback callback,
|
|
268 gpointer callback_data);
|
|
269 static gboolean gtk_combo_box_expose_event (GtkWidget *widget,
|
|
270 GdkEventExpose *event);
|
|
271 static gboolean gtk_combo_box_scroll_event (GtkWidget *widget,
|
|
272 GdkEventScroll *event);
|
|
273 static void gtk_combo_box_set_active_internal (GtkComboBox *combo_box,
|
|
274 gint index);
|
|
275 static gboolean gtk_combo_box_key_press (GtkWidget *widget,
|
|
276 GdkEventKey *event,
|
|
277 gpointer data);
|
|
278
|
|
279 /* listening to the model */
|
|
280 static void gtk_combo_box_model_row_inserted (GtkTreeModel *model,
|
|
281 GtkTreePath *path,
|
|
282 GtkTreeIter *iter,
|
|
283 gpointer user_data);
|
|
284 static void gtk_combo_box_model_row_deleted (GtkTreeModel *model,
|
|
285 GtkTreePath *path,
|
|
286 gpointer user_data);
|
|
287 static void gtk_combo_box_model_rows_reordered (GtkTreeModel *model,
|
|
288 GtkTreePath *path,
|
|
289 GtkTreeIter *iter,
|
|
290 gint *new_order,
|
|
291 gpointer user_data);
|
|
292 static void gtk_combo_box_model_row_changed (GtkTreeModel *model,
|
|
293 GtkTreePath *path,
|
|
294 GtkTreeIter *iter,
|
|
295 gpointer data);
|
|
296
|
|
297 /* list */
|
11780
|
298 #if GTK_CHECK_VERSION(2,2,0)
|
10708
|
299 static void gtk_combo_box_list_position (GtkComboBox *combo_box,
|
|
300 gint *x,
|
|
301 gint *y,
|
|
302 gint *width,
|
|
303 gint *height);
|
11780
|
304 #endif
|
10708
|
305 static void gtk_combo_box_list_setup (GtkComboBox *combo_box);
|
|
306 static void gtk_combo_box_list_destroy (GtkComboBox *combo_box);
|
|
307
|
|
308 static void gtk_combo_box_list_remove_grabs (GtkComboBox *combo_box);
|
|
309
|
|
310 static gboolean gtk_combo_box_list_button_released (GtkWidget *widget,
|
|
311 GdkEventButton *event,
|
|
312 gpointer data);
|
|
313 static gboolean gtk_combo_box_list_key_press (GtkWidget *widget,
|
|
314 GdkEventKey *event,
|
|
315 gpointer data);
|
|
316 static gboolean gtk_combo_box_list_button_pressed (GtkWidget *widget,
|
|
317 GdkEventButton *event,
|
|
318 gpointer data);
|
|
319
|
|
320 static void gtk_combo_box_list_row_changed (GtkTreeModel *model,
|
|
321 GtkTreePath *path,
|
|
322 GtkTreeIter *iter,
|
|
323 gpointer data);
|
|
324
|
|
325 /* menu */
|
|
326 static void gtk_combo_box_menu_setup (GtkComboBox *combo_box,
|
|
327 gboolean add_children);
|
|
328 static void gtk_combo_box_menu_fill (GtkComboBox *combo_box);
|
|
329 static void gtk_combo_box_menu_destroy (GtkComboBox *combo_box);
|
|
330
|
|
331 static void gtk_combo_box_item_get_size (GtkComboBox *combo_box,
|
|
332 gint index,
|
|
333 gint *cols,
|
|
334 gint *rows);
|
|
335 static void gtk_combo_box_relayout_item (GtkComboBox *combo_box,
|
|
336 gint index);
|
|
337 static void gtk_combo_box_relayout (GtkComboBox *combo_box);
|
|
338
|
|
339 static gboolean gtk_combo_box_menu_button_press (GtkWidget *widget,
|
|
340 GdkEventButton *event,
|
|
341 gpointer user_data);
|
|
342 static void gtk_combo_box_menu_item_activate (GtkWidget *item,
|
|
343 gpointer user_data);
|
|
344 static void gtk_combo_box_menu_row_inserted (GtkTreeModel *model,
|
|
345 GtkTreePath *path,
|
|
346 GtkTreeIter *iter,
|
|
347 gpointer user_data);
|
|
348 static void gtk_combo_box_menu_row_deleted (GtkTreeModel *model,
|
|
349 GtkTreePath *path,
|
|
350 gpointer user_data);
|
|
351 static void gtk_combo_box_menu_rows_reordered (GtkTreeModel *model,
|
|
352 GtkTreePath *path,
|
|
353 GtkTreeIter *iter,
|
|
354 gint *new_order,
|
|
355 gpointer user_data);
|
|
356 static void gtk_combo_box_menu_row_changed (GtkTreeModel *model,
|
|
357 GtkTreePath *path,
|
|
358 GtkTreeIter *iter,
|
|
359 gpointer data);
|
|
360 static gboolean gtk_combo_box_menu_key_press (GtkWidget *widget,
|
|
361 GdkEventKey *event,
|
|
362 gpointer data);
|
|
363
|
|
364 /* cell layout */
|
|
365 static void gtk_combo_box_cell_layout_pack_start (GtkCellLayout *layout,
|
|
366 GtkCellRenderer *cell,
|
|
367 gboolean expand);
|
|
368 static void gtk_combo_box_cell_layout_pack_end (GtkCellLayout *layout,
|
|
369 GtkCellRenderer *cell,
|
|
370 gboolean expand);
|
|
371 static void gtk_combo_box_cell_layout_clear (GtkCellLayout *layout);
|
|
372 static void gtk_combo_box_cell_layout_add_attribute (GtkCellLayout *layout,
|
|
373 GtkCellRenderer *cell,
|
|
374 const gchar *attribute,
|
|
375 gint column);
|
|
376 static void gtk_combo_box_cell_layout_set_cell_data_func (GtkCellLayout *layout,
|
|
377 GtkCellRenderer *cell,
|
|
378 GtkCellLayoutDataFunc func,
|
|
379 gpointer func_data,
|
|
380 GDestroyNotify destroy);
|
|
381 static void gtk_combo_box_cell_layout_clear_attributes (GtkCellLayout *layout,
|
|
382 GtkCellRenderer *cell);
|
|
383 static void gtk_combo_box_cell_layout_reorder (GtkCellLayout *layout,
|
|
384 GtkCellRenderer *cell,
|
|
385 gint position);
|
|
386 static gboolean gtk_combo_box_mnemonic_activate (GtkWidget *widget,
|
|
387 gboolean group_cycling);
|
|
388
|
|
389 static void cell_view_sync_cells (GtkComboBox *combo_box,
|
|
390 GtkCellView *cell_view);
|
|
391
|
|
392 #if !GTK_CHECK_VERSION(2,4,0)
|
|
393 static void gtk_menu_attach (GtkMenu *menu,
|
|
394 GtkWidget *child,
|
|
395 guint left_attach,
|
|
396 guint right_attach,
|
|
397 guint top_attach,
|
|
398 guint bottom_attach);
|
|
399 #endif
|
|
400
|
|
401 GType
|
|
402 gtk_combo_box_get_type (void)
|
|
403 {
|
|
404 static GType combo_box_type = 0;
|
|
405
|
|
406 if (!combo_box_type)
|
|
407 {
|
|
408 static const GTypeInfo combo_box_info =
|
|
409 {
|
|
410 sizeof (GtkComboBoxClass),
|
|
411 NULL, /* base_init */
|
|
412 NULL, /* base_finalize */
|
|
413 (GClassInitFunc) gtk_combo_box_class_init,
|
|
414 NULL, /* class_finalize */
|
|
415 NULL, /* class_data */
|
|
416 sizeof (GtkComboBox),
|
|
417 0,
|
|
418 (GInstanceInitFunc) gtk_combo_box_init
|
|
419 };
|
|
420
|
|
421 static const GInterfaceInfo cell_layout_info =
|
|
422 {
|
|
423 (GInterfaceInitFunc) gtk_combo_box_cell_layout_init,
|
|
424 NULL,
|
|
425 NULL
|
|
426 };
|
|
427
|
|
428 combo_box_type = g_type_register_static (GTK_TYPE_BIN,
|
|
429 "GaimGtkComboBox",
|
|
430 &combo_box_info,
|
|
431 0);
|
|
432
|
|
433 g_type_add_interface_static (combo_box_type,
|
|
434 GTK_TYPE_CELL_LAYOUT,
|
|
435 &cell_layout_info);
|
|
436 }
|
|
437
|
|
438 return combo_box_type;
|
|
439 }
|
|
440
|
|
441 /* common */
|
|
442 static void
|
|
443 gtk_combo_box_class_init (GtkComboBoxClass *klass)
|
|
444 {
|
|
445 GObjectClass *object_class;
|
|
446 GtkBindingSet *binding_set;
|
|
447 GtkObjectClass *gtk_object_class;
|
|
448 GtkContainerClass *container_class;
|
|
449 GtkWidgetClass *widget_class;
|
|
450
|
|
451 binding_set = gtk_binding_set_by_class (klass);
|
|
452
|
|
453 container_class = (GtkContainerClass *)klass;
|
|
454 container_class->forall = gtk_combo_box_forall;
|
|
455 container_class->add = gtk_combo_box_add;
|
|
456 container_class->remove = gtk_combo_box_remove;
|
|
457
|
|
458 widget_class = (GtkWidgetClass *)klass;
|
|
459 widget_class->size_allocate = gtk_combo_box_size_allocate;
|
|
460 widget_class->size_request = gtk_combo_box_size_request;
|
|
461 widget_class->expose_event = gtk_combo_box_expose_event;
|
|
462 widget_class->scroll_event = gtk_combo_box_scroll_event;
|
|
463 widget_class->mnemonic_activate = gtk_combo_box_mnemonic_activate;
|
|
464 widget_class->style_set = gtk_combo_box_style_set;
|
|
465 widget_class->state_changed = gtk_combo_box_state_changed;
|
|
466
|
|
467 gtk_object_class = (GtkObjectClass *)klass;
|
|
468 gtk_object_class->destroy = gtk_combo_box_destroy;
|
|
469
|
|
470 object_class = (GObjectClass *)klass;
|
|
471 object_class->finalize = gtk_combo_box_finalize;
|
|
472 object_class->set_property = gtk_combo_box_set_property;
|
|
473 object_class->get_property = gtk_combo_box_get_property;
|
|
474
|
|
475 parent_class = g_type_class_peek_parent (klass);
|
|
476
|
|
477 /* signals */
|
|
478 combo_box_signals[CHANGED] =
|
|
479 g_signal_new ("changed",
|
|
480 G_OBJECT_CLASS_TYPE (klass),
|
|
481 G_SIGNAL_RUN_LAST,
|
|
482 G_STRUCT_OFFSET (GtkComboBoxClass, changed),
|
|
483 NULL, NULL,
|
|
484 g_cclosure_marshal_VOID__VOID,
|
|
485 G_TYPE_NONE, 0);
|
|
486
|
|
487 /* properties */
|
|
488 g_object_class_install_property (object_class,
|
|
489 PROP_MODEL,
|
|
490 g_param_spec_object ("model",
|
|
491 _("ComboBox model"),
|
|
492 _("The model for the combo box"),
|
|
493 GTK_TYPE_TREE_MODEL,
|
|
494 G_PARAM_READWRITE));
|
|
495
|
|
496 g_object_class_install_property (object_class,
|
|
497 PROP_WRAP_WIDTH,
|
|
498 g_param_spec_int ("wrap_width",
|
|
499 _("Wrap width"),
|
|
500 _("Wrap width for layouting the items in a grid"),
|
|
501 0,
|
|
502 G_MAXINT,
|
|
503 0,
|
|
504 G_PARAM_READWRITE));
|
|
505
|
|
506 g_object_class_install_property (object_class,
|
|
507 PROP_ROW_SPAN_COLUMN,
|
|
508 g_param_spec_int ("row_span_column",
|
|
509 _("Row span column"),
|
|
510 _("TreeModel column containing the row span values"),
|
|
511 0,
|
|
512 G_MAXINT,
|
|
513 0,
|
|
514 G_PARAM_READWRITE));
|
|
515
|
|
516 g_object_class_install_property (object_class,
|
|
517 PROP_COLUMN_SPAN_COLUMN,
|
|
518 g_param_spec_int ("column_span_column",
|
|
519 _("Column span column"),
|
|
520
|
|
521 _("TreeModel column containing the column span values"),
|
|
522 0,
|
|
523 G_MAXINT,
|
|
524 0,
|
|
525 G_PARAM_READWRITE));
|
|
526
|
|
527 g_object_class_install_property (object_class,
|
|
528 PROP_ACTIVE,
|
|
529 g_param_spec_int ("active",
|
|
530 _("Active item"),
|
|
531 _("The item which is currently active"),
|
|
532 -1,
|
|
533 G_MAXINT,
|
|
534 -1,
|
|
535 G_PARAM_READWRITE));
|
|
536
|
|
537 gtk_widget_class_install_style_property (widget_class,
|
|
538 g_param_spec_boolean ("appears-as-list",
|
|
539 _("Appears as list"),
|
|
540 _("Whether combobox dropdowns should look like lists rather than menus"),
|
|
541 FALSE,
|
|
542 G_PARAM_READABLE));
|
|
543 }
|
|
544
|
|
545 static void
|
|
546 gtk_combo_box_cell_layout_init (GtkCellLayoutIface *iface)
|
|
547 {
|
|
548 iface->pack_start = gtk_combo_box_cell_layout_pack_start;
|
|
549 iface->pack_end = gtk_combo_box_cell_layout_pack_end;
|
|
550 iface->clear = gtk_combo_box_cell_layout_clear;
|
|
551 iface->add_attribute = gtk_combo_box_cell_layout_add_attribute;
|
|
552 iface->set_cell_data_func = gtk_combo_box_cell_layout_set_cell_data_func;
|
|
553 iface->clear_attributes = gtk_combo_box_cell_layout_clear_attributes;
|
|
554 iface->reorder = gtk_combo_box_cell_layout_reorder;
|
|
555 }
|
|
556
|
|
557 static void
|
|
558 gtk_combo_box_init (GtkComboBox *combo_box)
|
|
559 {
|
|
560 combo_box->priv = g_new0(GtkComboBoxPrivate,1);
|
|
561
|
|
562 combo_box->priv->cell_view = gtk_cell_view_new ();
|
|
563 gtk_widget_set_parent (combo_box->priv->cell_view, GTK_WIDGET (combo_box));
|
|
564 GTK_BIN (combo_box)->child = combo_box->priv->cell_view;
|
|
565 gtk_widget_show (combo_box->priv->cell_view);
|
|
566
|
|
567 combo_box->priv->width = 0;
|
|
568 combo_box->priv->wrap_width = 0;
|
|
569
|
|
570 combo_box->priv->active_item = -1;
|
|
571 combo_box->priv->col_column = -1;
|
|
572 combo_box->priv->row_column = -1;
|
|
573 }
|
|
574
|
|
575 static void
|
|
576 gtk_combo_box_set_property (GObject *object,
|
|
577 guint prop_id,
|
|
578 const GValue *value,
|
|
579 GParamSpec *pspec)
|
|
580 {
|
|
581 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
|
|
582
|
|
583 switch (prop_id)
|
|
584 {
|
|
585 case PROP_MODEL:
|
|
586 gtk_combo_box_set_model (combo_box, g_value_get_object (value));
|
|
587 break;
|
|
588
|
|
589 case PROP_WRAP_WIDTH:
|
|
590 gtk_combo_box_set_wrap_width (combo_box, g_value_get_int (value));
|
|
591 break;
|
|
592
|
|
593 case PROP_ROW_SPAN_COLUMN:
|
|
594 gtk_combo_box_set_row_span_column (combo_box, g_value_get_int (value));
|
|
595 break;
|
|
596
|
|
597 case PROP_COLUMN_SPAN_COLUMN:
|
|
598 gtk_combo_box_set_column_span_column (combo_box, g_value_get_int (value));
|
|
599 break;
|
|
600
|
|
601 case PROP_ACTIVE:
|
|
602 gtk_combo_box_set_active (combo_box, g_value_get_int (value));
|
|
603 break;
|
|
604
|
|
605 default:
|
|
606 break;
|
|
607 }
|
|
608 }
|
|
609
|
|
610 static void
|
|
611 gtk_combo_box_get_property (GObject *object,
|
|
612 guint prop_id,
|
|
613 GValue *value,
|
|
614 GParamSpec *pspec)
|
|
615 {
|
|
616 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
|
|
617
|
|
618 switch (prop_id)
|
|
619 {
|
|
620 case PROP_MODEL:
|
|
621 g_value_set_object (value, combo_box->priv->model);
|
|
622 break;
|
|
623
|
|
624 case PROP_WRAP_WIDTH:
|
|
625 g_value_set_int (value, combo_box->priv->wrap_width);
|
|
626 break;
|
|
627
|
|
628 case PROP_ROW_SPAN_COLUMN:
|
|
629 g_value_set_int (value, combo_box->priv->row_column);
|
|
630 break;
|
|
631
|
|
632 case PROP_COLUMN_SPAN_COLUMN:
|
|
633 g_value_set_int (value, combo_box->priv->col_column);
|
|
634 break;
|
|
635
|
|
636 case PROP_ACTIVE:
|
|
637 g_value_set_int (value, gtk_combo_box_get_active (combo_box));
|
|
638 break;
|
|
639
|
|
640 default:
|
|
641 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
642 break;
|
|
643 }
|
|
644 }
|
|
645
|
|
646 static void
|
|
647 gtk_combo_box_state_changed (GtkWidget *widget,
|
|
648 GtkStateType previous)
|
|
649 {
|
|
650 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
|
|
651
|
|
652 if (GTK_WIDGET_REALIZED (widget))
|
|
653 {
|
|
654 if (combo_box->priv->tree_view && combo_box->priv->cell_view)
|
|
655 gtk_cell_view_set_background_color (GTK_CELL_VIEW (combo_box->priv->cell_view),
|
|
656 &widget->style->base[GTK_WIDGET_STATE (widget)]);
|
|
657 }
|
|
658
|
|
659 gtk_widget_queue_draw (widget);
|
|
660 }
|
|
661
|
|
662 static void
|
|
663 gtk_combo_box_check_appearance (GtkComboBox *combo_box)
|
|
664 {
|
|
665 gboolean appears_as_list;
|
|
666
|
|
667 /* if wrap_width > 0, then we are in grid-mode and forced to use
|
|
668 * unix style
|
|
669 */
|
|
670 if (combo_box->priv->wrap_width)
|
|
671 appears_as_list = FALSE;
|
|
672 else
|
|
673 gtk_widget_style_get (GTK_WIDGET (combo_box),
|
|
674 "appears-as-list", &appears_as_list,
|
|
675 NULL);
|
|
676
|
|
677 if (appears_as_list)
|
|
678 {
|
|
679 /* Destroy all the menu mode widgets, if they exist. */
|
|
680 if (GTK_IS_MENU (combo_box->priv->popup_widget))
|
|
681 gtk_combo_box_menu_destroy (combo_box);
|
|
682
|
|
683 /* Create the list mode widgets, if they don't already exist. */
|
|
684 if (!GTK_IS_TREE_VIEW (combo_box->priv->tree_view))
|
|
685 gtk_combo_box_list_setup (combo_box);
|
|
686 }
|
|
687 else
|
|
688 {
|
|
689 /* Destroy all the list mode widgets, if they exist. */
|
|
690 if (GTK_IS_TREE_VIEW (combo_box->priv->tree_view))
|
|
691 gtk_combo_box_list_destroy (combo_box);
|
|
692
|
|
693 /* Create the menu mode widgets, if they don't already exist. */
|
|
694 if (!GTK_IS_MENU (combo_box->priv->popup_widget))
|
|
695 gtk_combo_box_menu_setup (combo_box, TRUE);
|
|
696 }
|
|
697 }
|
|
698
|
|
699 static void
|
|
700 gtk_combo_box_style_set (GtkWidget *widget,
|
|
701 GtkStyle *previous)
|
|
702 {
|
|
703 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
|
|
704
|
|
705 gtk_combo_box_check_appearance (combo_box);
|
|
706
|
|
707 if (combo_box->priv->tree_view && combo_box->priv->cell_view)
|
|
708 gtk_cell_view_set_background_color (GTK_CELL_VIEW (combo_box->priv->cell_view),
|
|
709 &widget->style->base[GTK_WIDGET_STATE (widget)]);
|
|
710 }
|
|
711
|
|
712 static void
|
|
713 gtk_combo_box_button_toggled (GtkWidget *widget,
|
|
714 gpointer data)
|
|
715 {
|
|
716 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
|
|
717
|
|
718 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
|
|
719 {
|
|
720 if (!combo_box->priv->popup_in_progress)
|
|
721 gtk_combo_box_popup (combo_box);
|
|
722 }
|
|
723 else
|
|
724 gtk_combo_box_popdown (combo_box);
|
|
725 }
|
|
726
|
|
727 static void
|
|
728 gtk_combo_box_add (GtkContainer *container,
|
|
729 GtkWidget *widget)
|
|
730 {
|
|
731 GtkComboBox *combo_box = GTK_COMBO_BOX (container);
|
|
732
|
|
733 if (combo_box->priv->cell_view && combo_box->priv->cell_view->parent)
|
|
734 {
|
|
735 gtk_widget_unparent (combo_box->priv->cell_view);
|
|
736 GTK_BIN (container)->child = NULL;
|
|
737 gtk_widget_queue_resize (GTK_WIDGET (container));
|
|
738 }
|
|
739
|
|
740 gtk_widget_set_parent (widget, GTK_WIDGET (container));
|
|
741 GTK_BIN (container)->child = widget;
|
|
742
|
|
743 if (combo_box->priv->cell_view &&
|
|
744 widget != combo_box->priv->cell_view)
|
|
745 {
|
|
746 /* since the cell_view was unparented, it's gone now */
|
|
747 combo_box->priv->cell_view = NULL;
|
|
748
|
|
749 if (!combo_box->priv->tree_view && combo_box->priv->separator)
|
|
750 {
|
|
751 gtk_container_remove (GTK_CONTAINER (combo_box->priv->separator->parent),
|
|
752 combo_box->priv->separator);
|
|
753 combo_box->priv->separator = NULL;
|
|
754
|
|
755 gtk_widget_queue_resize (GTK_WIDGET (container));
|
|
756 }
|
|
757 else if (combo_box->priv->cell_view_frame)
|
|
758 {
|
|
759 gtk_widget_unparent (combo_box->priv->cell_view_frame);
|
|
760 combo_box->priv->cell_view_frame = NULL;
|
|
761 }
|
|
762 }
|
|
763 }
|
|
764
|
|
765 static void
|
|
766 gtk_combo_box_remove (GtkContainer *container,
|
|
767 GtkWidget *widget)
|
|
768 {
|
|
769 GtkComboBox *combo_box = GTK_COMBO_BOX (container);
|
|
770 gboolean appears_as_list;
|
|
771
|
|
772 gtk_widget_unparent (widget);
|
|
773 GTK_BIN (container)->child = NULL;
|
|
774
|
|
775 if (combo_box->priv->destroying)
|
|
776 return;
|
|
777
|
|
778 gtk_widget_queue_resize (GTK_WIDGET (container));
|
|
779
|
|
780 if (!combo_box->priv->tree_view)
|
|
781 appears_as_list = FALSE;
|
|
782 else
|
|
783 appears_as_list = TRUE;
|
|
784
|
|
785 if (appears_as_list)
|
|
786 gtk_combo_box_list_destroy (combo_box);
|
|
787 else if (GTK_IS_MENU (combo_box->priv->popup_widget))
|
|
788 {
|
|
789 gtk_combo_box_menu_destroy (combo_box);
|
|
790 gtk_menu_detach (GTK_MENU (combo_box->priv->popup_widget));
|
|
791 combo_box->priv->popup_widget = NULL;
|
|
792 }
|
|
793
|
|
794 if (!combo_box->priv->cell_view)
|
|
795 {
|
|
796 combo_box->priv->cell_view = gtk_cell_view_new ();
|
|
797 gtk_widget_set_parent (combo_box->priv->cell_view, GTK_WIDGET (container));
|
|
798 GTK_BIN (container)->child = combo_box->priv->cell_view;
|
|
799
|
|
800 gtk_widget_show (combo_box->priv->cell_view);
|
|
801 gtk_cell_view_set_model (GTK_CELL_VIEW (combo_box->priv->cell_view),
|
|
802 combo_box->priv->model);
|
|
803 cell_view_sync_cells (combo_box, GTK_CELL_VIEW (combo_box->priv->cell_view));
|
|
804 }
|
|
805
|
|
806
|
|
807 if (appears_as_list)
|
|
808 gtk_combo_box_list_setup (combo_box);
|
|
809 else
|
|
810 gtk_combo_box_menu_setup (combo_box, TRUE);
|
|
811
|
|
812 gtk_combo_box_set_active_internal (combo_box, combo_box->priv->active_item);
|
|
813 }
|
|
814
|
|
815 static ComboCellInfo *
|
|
816 gtk_combo_box_get_cell_info (GtkComboBox *combo_box,
|
|
817 GtkCellRenderer *cell)
|
|
818 {
|
|
819 GSList *i;
|
|
820
|
|
821 for (i = combo_box->priv->cells; i; i = i->next)
|
|
822 {
|
|
823 ComboCellInfo *info = (ComboCellInfo *)i->data;
|
|
824
|
|
825 if (info && info->cell == cell)
|
|
826 return info;
|
|
827 }
|
|
828
|
|
829 return NULL;
|
|
830 }
|
|
831
|
|
832 static void
|
|
833 gtk_combo_box_menu_show (GtkWidget *menu,
|
|
834 gpointer user_data)
|
|
835 {
|
|
836 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
|
|
837
|
|
838 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
|
|
839 TRUE);
|
|
840 combo_box->priv->popup_in_progress = FALSE;
|
|
841 }
|
|
842
|
|
843 static void
|
|
844 gtk_combo_box_menu_hide (GtkWidget *menu,
|
|
845 gpointer user_data)
|
|
846 {
|
|
847 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
|
|
848
|
|
849 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
|
|
850 FALSE);
|
|
851 }
|
|
852
|
|
853 static void
|
|
854 gtk_combo_box_detacher (GtkWidget *widget,
|
|
855 GtkMenu *menu)
|
|
856 {
|
|
857 GtkComboBox *combo_box;
|
|
858
|
|
859 g_return_if_fail (GTK_IS_COMBO_BOX (widget));
|
|
860
|
|
861 combo_box = GTK_COMBO_BOX (widget);
|
|
862 g_return_if_fail (combo_box->priv->popup_widget == (GtkWidget*) menu);
|
|
863
|
|
864 g_signal_handlers_disconnect_by_func (menu,
|
|
865 gtk_combo_box_menu_show,
|
|
866 combo_box);
|
|
867 g_signal_handlers_disconnect_by_func (menu,
|
|
868 gtk_combo_box_menu_hide,
|
|
869 combo_box);
|
|
870
|
|
871 combo_box->priv->popup_widget = NULL;
|
|
872 }
|
|
873
|
|
874 static void
|
|
875 gtk_combo_box_set_popup_widget (GtkComboBox *combo_box,
|
|
876 GtkWidget *popup)
|
|
877 {
|
|
878 if (GTK_IS_MENU (combo_box->priv->popup_widget))
|
|
879 {
|
|
880 gtk_menu_detach (GTK_MENU (combo_box->priv->popup_widget));
|
|
881 combo_box->priv->popup_widget = NULL;
|
|
882 }
|
|
883 else if (combo_box->priv->popup_widget)
|
|
884 {
|
|
885 gtk_container_remove (GTK_CONTAINER (combo_box->priv->popup_frame),
|
|
886 combo_box->priv->popup_widget);
|
|
887 g_object_unref (G_OBJECT (combo_box->priv->popup_widget));
|
|
888 combo_box->priv->popup_widget = NULL;
|
|
889 }
|
|
890
|
|
891 if (GTK_IS_MENU (popup))
|
|
892 {
|
|
893 if (combo_box->priv->popup_window)
|
|
894 {
|
|
895 gtk_widget_destroy (combo_box->priv->popup_window);
|
|
896 combo_box->priv->popup_window = NULL;
|
|
897 combo_box->priv->popup_frame = NULL;
|
|
898 }
|
|
899
|
|
900 combo_box->priv->popup_widget = popup;
|
|
901
|
|
902 g_signal_connect (popup, "show",
|
|
903 G_CALLBACK (gtk_combo_box_menu_show), combo_box);
|
|
904 g_signal_connect (popup, "hide",
|
|
905 G_CALLBACK (gtk_combo_box_menu_hide), combo_box);
|
|
906
|
|
907 gtk_menu_attach_to_widget (GTK_MENU (popup),
|
|
908 GTK_WIDGET (combo_box),
|
|
909 gtk_combo_box_detacher);
|
|
910 }
|
|
911 else
|
|
912 {
|
|
913 if (!combo_box->priv->popup_window)
|
|
914 {
|
|
915 combo_box->priv->popup_window = gtk_window_new (GTK_WINDOW_POPUP);
|
|
916 gtk_window_set_resizable (GTK_WINDOW (combo_box->priv->popup_window), FALSE);
|
11780
|
917 #if GTK_CHECK_VERSION(2,2,0)
|
10708
|
918 gtk_window_set_screen (GTK_WINDOW (combo_box->priv->popup_window),
|
|
919 gtk_widget_get_screen (GTK_WIDGET (combo_box)));
|
11780
|
920 #endif
|
10708
|
921
|
|
922 combo_box->priv->popup_frame = gtk_frame_new (NULL);
|
|
923 gtk_frame_set_shadow_type (GTK_FRAME (combo_box->priv->popup_frame),
|
|
924 GTK_SHADOW_ETCHED_IN);
|
|
925 gtk_container_add (GTK_CONTAINER (combo_box->priv->popup_window),
|
|
926 combo_box->priv->popup_frame);
|
|
927
|
|
928 gtk_widget_show (combo_box->priv->popup_frame);
|
|
929 }
|
|
930
|
|
931 gtk_container_add (GTK_CONTAINER (combo_box->priv->popup_frame),
|
|
932 popup);
|
|
933 gtk_widget_show (popup);
|
|
934 g_object_ref (G_OBJECT (popup));
|
|
935 combo_box->priv->popup_widget = popup;
|
|
936 }
|
|
937 }
|
|
938
|
11780
|
939 #if GTK_CHECK_VERSION(2,2,0)
|
10708
|
940 static void
|
|
941 gtk_combo_box_menu_position_below (GtkMenu *menu,
|
|
942 gint *x,
|
|
943 gint *y,
|
|
944 gint *push_in,
|
|
945 gpointer user_data)
|
|
946 {
|
|
947 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
|
|
948 gint sx, sy;
|
|
949 GtkWidget *child;
|
|
950 GtkRequisition req;
|
|
951 GdkScreen *screen;
|
|
952 gint monitor_num;
|
|
953 GdkRectangle monitor;
|
|
954
|
|
955 /* FIXME: is using the size request here broken? */
|
|
956 child = GTK_BIN (combo_box)->child;
|
|
957
|
|
958 gdk_window_get_origin (child->window, &sx, &sy);
|
|
959
|
|
960 if (GTK_WIDGET_NO_WINDOW (child))
|
|
961 {
|
|
962 sx += child->allocation.x;
|
|
963 sy += child->allocation.y;
|
|
964 }
|
|
965
|
|
966 gtk_widget_size_request (GTK_WIDGET (menu), &req);
|
|
967
|
|
968 if (gtk_widget_get_direction (GTK_WIDGET (combo_box)) == GTK_TEXT_DIR_LTR)
|
|
969 *x = sx;
|
|
970 else
|
|
971 *x = sx + child->allocation.width - req.width;
|
|
972 *y = sy;
|
|
973
|
|
974 screen = gtk_widget_get_screen (GTK_WIDGET (combo_box));
|
|
975 monitor_num = gdk_screen_get_monitor_at_window (screen,
|
|
976 GTK_WIDGET (combo_box)->window);
|
|
977 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
|
|
978
|
|
979 if (*x < monitor.x)
|
|
980 *x = monitor.x;
|
|
981 else if (*x + req.width > monitor.x + monitor.width)
|
|
982 *x = monitor.x + monitor.width - req.width;
|
|
983
|
|
984 if (monitor.y + monitor.height - *y - child->allocation.height >= req.height)
|
|
985 *y += child->allocation.height;
|
|
986 else if (*y - monitor.y >= req.height)
|
|
987 *y -= req.height;
|
|
988 else if (monitor.y + monitor.height - *y - child->allocation.height > *y - monitor.y)
|
|
989 *y += child->allocation.height;
|
|
990 else
|
|
991 *y -= req.height;
|
|
992
|
|
993 *push_in = FALSE;
|
|
994 }
|
|
995
|
|
996 static void
|
|
997 gtk_combo_box_menu_position_over (GtkMenu *menu,
|
|
998 gint *x,
|
|
999 gint *y,
|
|
1000 gboolean *push_in,
|
|
1001 gpointer user_data)
|
|
1002 {
|
|
1003 GtkComboBox *combo_box;
|
|
1004 GtkWidget *active;
|
|
1005 GtkWidget *child;
|
|
1006 GtkWidget *widget;
|
|
1007 GtkRequisition requisition;
|
|
1008 GList *children;
|
|
1009 gint screen_width;
|
|
1010 gint menu_xpos;
|
|
1011 gint menu_ypos;
|
|
1012 gint menu_width;
|
|
1013
|
|
1014 g_return_if_fail (GTK_IS_COMBO_BOX (user_data));
|
|
1015
|
|
1016 combo_box = GTK_COMBO_BOX (user_data);
|
|
1017 widget = GTK_WIDGET (combo_box);
|
|
1018
|
|
1019 gtk_widget_get_child_requisition (GTK_WIDGET (menu), &requisition);
|
|
1020 menu_width = requisition.width;
|
|
1021
|
|
1022 active = gtk_menu_get_active (GTK_MENU (combo_box->priv->popup_widget));
|
|
1023 gdk_window_get_origin (widget->window, &menu_xpos, &menu_ypos);
|
|
1024
|
|
1025 menu_xpos += widget->allocation.x;
|
|
1026 menu_ypos += widget->allocation.y + widget->allocation.height / 2 - 2;
|
|
1027
|
|
1028 if (active != NULL)
|
|
1029 {
|
|
1030 gtk_widget_get_child_requisition (active, &requisition);
|
|
1031 menu_ypos -= requisition.height / 2;
|
|
1032 }
|
|
1033
|
|
1034 children = GTK_MENU_SHELL (combo_box->priv->popup_widget)->children;
|
|
1035 while (children)
|
|
1036 {
|
|
1037 child = children->data;
|
|
1038
|
|
1039 if (active == child)
|
|
1040 break;
|
|
1041
|
|
1042 if (GTK_WIDGET_VISIBLE (child))
|
|
1043 {
|
|
1044 gtk_widget_get_child_requisition (child, &requisition);
|
|
1045 menu_ypos -= requisition.height;
|
|
1046 }
|
|
1047
|
|
1048 children = children->next;
|
|
1049 }
|
|
1050
|
|
1051 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
|
|
1052 menu_xpos = menu_xpos + widget->allocation.width - menu_width;
|
|
1053
|
|
1054 /* Clamp the position on screen */
|
|
1055 screen_width = gdk_screen_get_width (gtk_widget_get_screen (widget));
|
|
1056
|
|
1057 if (menu_xpos < 0)
|
|
1058 menu_xpos = 0;
|
|
1059 else if ((menu_xpos + menu_width) > screen_width)
|
|
1060 menu_xpos -= ((menu_xpos + menu_width) - screen_width);
|
|
1061
|
|
1062 *x = menu_xpos;
|
|
1063 *y = menu_ypos;
|
|
1064
|
|
1065 *push_in = TRUE;
|
|
1066 }
|
|
1067
|
|
1068 static void
|
|
1069 gtk_combo_box_menu_position (GtkMenu *menu,
|
|
1070 gint *x,
|
|
1071 gint *y,
|
|
1072 gint *push_in,
|
|
1073 gpointer user_data)
|
|
1074 {
|
|
1075 GtkComboBox *combo_box;
|
|
1076 GtkWidget *menu_item;
|
|
1077
|
|
1078 combo_box = GTK_COMBO_BOX (user_data);
|
|
1079
|
|
1080 if (combo_box->priv->wrap_width > 0 || combo_box->priv->cell_view == NULL)
|
|
1081 gtk_combo_box_menu_position_below (menu, x, y, push_in, user_data);
|
|
1082 else
|
|
1083 {
|
|
1084 menu_item = gtk_menu_get_active (GTK_MENU (combo_box->priv->popup_widget));
|
|
1085 if (menu_item)
|
|
1086 gtk_menu_shell_select_item (GTK_MENU_SHELL (combo_box->priv->popup_widget),
|
|
1087 menu_item);
|
|
1088
|
|
1089 gtk_combo_box_menu_position_over (menu, x, y, push_in, user_data);
|
|
1090 }
|
|
1091
|
|
1092 }
|
|
1093
|
|
1094 static void
|
|
1095 gtk_combo_box_list_position (GtkComboBox *combo_box,
|
|
1096 gint *x,
|
|
1097 gint *y,
|
|
1098 gint *width,
|
|
1099 gint *height)
|
|
1100 {
|
|
1101 GtkWidget *sample;
|
|
1102 GdkScreen *screen;
|
|
1103 gint monitor_num;
|
|
1104 GdkRectangle monitor;
|
|
1105 GtkRequisition popup_req;
|
|
1106
|
|
1107 sample = GTK_BIN (combo_box)->child;
|
|
1108
|
|
1109 *width = sample->allocation.width;
|
|
1110 gtk_widget_size_request (combo_box->priv->popup_window, &popup_req);
|
|
1111 *height = popup_req.height;
|
|
1112
|
|
1113 gdk_window_get_origin (sample->window, x, y);
|
|
1114
|
|
1115 if (combo_box->priv->cell_view_frame)
|
|
1116 {
|
|
1117 *x -= GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
|
|
1118 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->xthickness;
|
|
1119 *width += 2 * (GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
|
|
1120 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->xthickness);
|
|
1121 }
|
|
1122
|
|
1123 if (GTK_WIDGET_NO_WINDOW (sample))
|
|
1124 {
|
|
1125 *x += sample->allocation.x;
|
|
1126 *y += sample->allocation.y;
|
|
1127 }
|
|
1128
|
|
1129 screen = gtk_widget_get_screen (GTK_WIDGET (combo_box));
|
|
1130 monitor_num = gdk_screen_get_monitor_at_window (screen,
|
|
1131 GTK_WIDGET (combo_box)->window);
|
|
1132 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
|
|
1133
|
|
1134 if (*x < monitor.x)
|
|
1135 *x = monitor.x;
|
|
1136 else if (*x + *width > monitor.x + monitor.width)
|
|
1137 *x = monitor.x + monitor.width - *width;
|
|
1138
|
|
1139 if (*y + sample->allocation.height + *height <= monitor.y + monitor.height)
|
|
1140 *y += sample->allocation.height;
|
|
1141 else
|
|
1142 *y -= *height;
|
|
1143 }
|
11780
|
1144 #endif /* Gtk 2.2 */
|
10708
|
1145
|
|
1146 /**
|
|
1147 * gtk_combo_box_popup:
|
|
1148 * @combo_box: a #GtkComboBox
|
|
1149 *
|
|
1150 * Pops up the menu or dropdown list of @combo_box.
|
|
1151 *
|
|
1152 * This function is mostly intended for use by accessibility technologies;
|
|
1153 * applications should have little use for it.
|
|
1154 *
|
|
1155 * Since: 2.4
|
|
1156 **/
|
|
1157 void
|
|
1158 gtk_combo_box_popup (GtkComboBox *combo_box)
|
|
1159 {
|
11780
|
1160 gint x, y, width;
|
|
1161 #if GTK_CHECK_VERSION(2,2,0)
|
|
1162 gint height;
|
|
1163 #endif
|
10708
|
1164
|
|
1165 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
|
|
1166
|
|
1167 if (GTK_WIDGET_MAPPED (combo_box->priv->popup_widget))
|
|
1168 return;
|
|
1169
|
|
1170 if (GTK_IS_MENU (combo_box->priv->popup_widget))
|
|
1171 {
|
|
1172 gtk_menu_set_active (GTK_MENU (combo_box->priv->popup_widget),
|
|
1173 combo_box->priv->active_item);
|
|
1174
|
|
1175 if (combo_box->priv->wrap_width == 0)
|
|
1176 {
|
|
1177 GtkRequisition requisition;
|
|
1178
|
|
1179 width = GTK_WIDGET (combo_box)->allocation.width;
|
|
1180 gtk_widget_size_request (combo_box->priv->popup_widget, &requisition);
|
|
1181
|
|
1182 gtk_widget_set_size_request (combo_box->priv->popup_widget,
|
|
1183 MAX (width, requisition.width), -1);
|
|
1184 }
|
|
1185
|
|
1186 gtk_menu_popup (GTK_MENU (combo_box->priv->popup_widget),
|
|
1187 NULL, NULL,
|
11780
|
1188 #if GTK_CHECK_VERSION(2,2,0)
|
|
1189 gtk_combo_box_menu_position,
|
|
1190 #else
|
|
1191 NULL,
|
|
1192 #endif
|
|
1193 combo_box, 0, 0);
|
10708
|
1194 return;
|
|
1195 }
|
|
1196
|
|
1197 gtk_widget_show_all (combo_box->priv->popup_frame);
|
11780
|
1198 #if GTK_CHECK_VERSION(2,2,0)
|
10708
|
1199 gtk_combo_box_list_position (combo_box, &x, &y, &width, &height);
|
11780
|
1200 #endif
|
10708
|
1201
|
|
1202 gtk_widget_set_size_request (combo_box->priv->popup_window, width, -1);
|
|
1203 gtk_window_move (GTK_WINDOW (combo_box->priv->popup_window), x, y);
|
|
1204
|
|
1205 /* popup */
|
|
1206 gtk_widget_show (combo_box->priv->popup_window);
|
|
1207
|
|
1208 gtk_widget_grab_focus (combo_box->priv->popup_window);
|
|
1209 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
|
|
1210 TRUE);
|
|
1211
|
|
1212 if (!GTK_WIDGET_HAS_FOCUS (combo_box->priv->tree_view))
|
|
1213 {
|
|
1214 gdk_keyboard_grab (combo_box->priv->popup_window->window,
|
|
1215 FALSE, GDK_CURRENT_TIME);
|
|
1216 gtk_widget_grab_focus (combo_box->priv->tree_view);
|
|
1217 }
|
|
1218
|
|
1219 gtk_grab_add (combo_box->priv->popup_window);
|
|
1220 gdk_pointer_grab (combo_box->priv->popup_window->window, TRUE,
|
|
1221 GDK_BUTTON_PRESS_MASK |
|
|
1222 GDK_BUTTON_RELEASE_MASK |
|
|
1223 GDK_POINTER_MOTION_MASK,
|
|
1224 NULL, NULL, GDK_CURRENT_TIME);
|
|
1225
|
|
1226 gtk_grab_add (combo_box->priv->tree_view);
|
|
1227 }
|
|
1228
|
|
1229 /**
|
|
1230 * gtk_combo_box_popdown:
|
|
1231 * @combo_box: a #GtkComboBox
|
|
1232 *
|
|
1233 * Hides the menu or dropdown list of @combo_box.
|
|
1234 *
|
|
1235 * This function is mostly intended for use by accessibility technologies;
|
|
1236 * applications should have little use for it.
|
|
1237 *
|
|
1238 * Since: 2.4
|
|
1239 **/
|
|
1240 void
|
|
1241 gtk_combo_box_popdown (GtkComboBox *combo_box)
|
|
1242 {
|
|
1243 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
|
|
1244
|
|
1245 if (!GTK_WIDGET_REALIZED (GTK_WIDGET (combo_box)))
|
|
1246 return;
|
|
1247
|
|
1248 if (GTK_IS_MENU (combo_box->priv->popup_widget))
|
|
1249 {
|
|
1250 gtk_menu_popdown (GTK_MENU (combo_box->priv->popup_widget));
|
|
1251 return;
|
|
1252 }
|
|
1253
|
|
1254 gtk_combo_box_list_remove_grabs (combo_box);
|
|
1255 gtk_widget_hide_all (combo_box->priv->popup_window);
|
|
1256 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
|
|
1257 FALSE);
|
|
1258 }
|
|
1259
|
|
1260 static gint
|
|
1261 gtk_combo_box_calc_requested_width (GtkComboBox *combo_box,
|
|
1262 GtkTreePath *path)
|
|
1263 {
|
|
1264 gint padding;
|
|
1265 GtkRequisition req;
|
|
1266
|
|
1267 if (combo_box->priv->cell_view)
|
|
1268 gtk_widget_style_get (combo_box->priv->cell_view,
|
|
1269 "focus-line-width", &padding,
|
|
1270 NULL);
|
|
1271 else
|
|
1272 padding = 0;
|
|
1273
|
|
1274 /* add some pixels for good measure */
|
|
1275 padding += BONUS_PADDING;
|
|
1276
|
|
1277 if (combo_box->priv->cell_view)
|
|
1278 gtk_cell_view_get_size_of_row (GTK_CELL_VIEW (combo_box->priv->cell_view),
|
|
1279 path, &req);
|
|
1280 else
|
|
1281 req.width = 0;
|
|
1282
|
|
1283 return req.width + padding;
|
|
1284 }
|
|
1285
|
|
1286 static void
|
|
1287 gtk_combo_box_remeasure (GtkComboBox *combo_box)
|
|
1288 {
|
|
1289 GtkTreeIter iter;
|
|
1290 GtkTreePath *path;
|
|
1291 gint padding = 0;
|
|
1292
|
|
1293 if (!combo_box->priv->model ||
|
|
1294 !gtk_tree_model_get_iter_first (combo_box->priv->model, &iter))
|
|
1295 return;
|
|
1296
|
|
1297 combo_box->priv->width = 0;
|
|
1298
|
11780
|
1299 #if GTK_CHECK_VERSION(2,2,0)
|
10708
|
1300 path = gtk_tree_path_new_from_indices (0, -1);
|
11780
|
1301 #else
|
|
1302 path = gtk_tree_path_new_first();
|
|
1303 #endif
|
10708
|
1304
|
|
1305 if (combo_box->priv->cell_view)
|
|
1306 gtk_widget_style_get (combo_box->priv->cell_view,
|
|
1307 "focus-line-width", &padding,
|
|
1308 NULL);
|
|
1309 else
|
|
1310 padding = 0;
|
|
1311
|
|
1312 /* add some pixels for good measure */
|
|
1313 padding += BONUS_PADDING;
|
|
1314
|
|
1315 do
|
|
1316 {
|
|
1317 GtkRequisition req;
|
|
1318
|
|
1319 if (combo_box->priv->cell_view)
|
|
1320 gtk_cell_view_get_size_of_row (GTK_CELL_VIEW (combo_box->priv->cell_view),
|
|
1321 path, &req);
|
|
1322 else
|
|
1323 req.width = 0;
|
|
1324
|
|
1325 combo_box->priv->width = MAX (combo_box->priv->width,
|
|
1326 req.width + padding);
|
|
1327
|
|
1328 gtk_tree_path_next (path);
|
|
1329 }
|
|
1330 while (gtk_tree_model_iter_next (combo_box->priv->model, &iter));
|
|
1331
|
|
1332 gtk_tree_path_free (path);
|
|
1333 }
|
|
1334
|
|
1335 static void
|
|
1336 gtk_combo_box_size_request (GtkWidget *widget,
|
|
1337 GtkRequisition *requisition)
|
|
1338 {
|
|
1339 gint width, height;
|
|
1340 GtkRequisition bin_req;
|
|
1341
|
|
1342 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
|
|
1343
|
|
1344 /* common */
|
|
1345 gtk_widget_size_request (GTK_BIN (widget)->child, &bin_req);
|
|
1346 gtk_combo_box_remeasure (combo_box);
|
|
1347 bin_req.width = MAX (bin_req.width, combo_box->priv->width);
|
|
1348
|
|
1349 gtk_combo_box_check_appearance (combo_box);
|
|
1350
|
|
1351 if (!combo_box->priv->tree_view)
|
|
1352 {
|
|
1353 /* menu mode */
|
|
1354
|
|
1355 if (combo_box->priv->cell_view)
|
|
1356 {
|
|
1357 GtkRequisition button_req, sep_req, arrow_req;
|
|
1358 gint border_width, xthickness, ythickness;
|
|
1359
|
|
1360 gtk_widget_size_request (combo_box->priv->button, &button_req);
|
|
1361 border_width = GTK_CONTAINER (combo_box->priv->button)->border_width;
|
|
1362 xthickness = combo_box->priv->button->style->xthickness;
|
|
1363 ythickness = combo_box->priv->button->style->ythickness;
|
|
1364
|
|
1365 bin_req.width = MAX (bin_req.width, combo_box->priv->width);
|
|
1366
|
|
1367 gtk_widget_size_request (combo_box->priv->separator, &sep_req);
|
|
1368 gtk_widget_size_request (combo_box->priv->arrow, &arrow_req);
|
|
1369
|
|
1370 height = MAX (sep_req.height, arrow_req.height);
|
|
1371 height = MAX (height, bin_req.height);
|
|
1372
|
|
1373 width = bin_req.width + sep_req.width + arrow_req.width;
|
|
1374
|
|
1375 height += border_width + 1 + ythickness * 2 + 4;
|
|
1376 width += border_width + 1 + xthickness * 2 + 4;
|
|
1377
|
|
1378 requisition->width = width;
|
|
1379 requisition->height = height;
|
|
1380 }
|
|
1381 else
|
|
1382 {
|
|
1383 GtkRequisition but_req;
|
|
1384
|
|
1385 gtk_widget_size_request (combo_box->priv->button, &but_req);
|
|
1386
|
|
1387 requisition->width = bin_req.width + but_req.width;
|
|
1388 requisition->height = MAX (bin_req.height, but_req.height);
|
|
1389 }
|
|
1390 }
|
|
1391 else
|
|
1392 {
|
|
1393 /* list mode */
|
|
1394 GtkRequisition button_req, frame_req;
|
|
1395
|
|
1396 /* sample + frame */
|
|
1397 *requisition = bin_req;
|
|
1398
|
|
1399 if (combo_box->priv->cell_view_frame)
|
|
1400 {
|
|
1401 gtk_widget_size_request (combo_box->priv->cell_view_frame, &frame_req);
|
|
1402 requisition->width += 2 *
|
|
1403 (GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
|
|
1404 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->xthickness);
|
|
1405 requisition->height += 2 *
|
|
1406 (GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
|
|
1407 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->ythickness);
|
|
1408 }
|
|
1409
|
|
1410 /* the button */
|
|
1411 gtk_widget_size_request (combo_box->priv->button, &button_req);
|
|
1412
|
|
1413 requisition->height = MAX (requisition->height, button_req.height);
|
|
1414 requisition->width += button_req.width;
|
|
1415 }
|
|
1416 }
|
|
1417
|
|
1418 static void
|
|
1419 gtk_combo_box_size_allocate (GtkWidget *widget,
|
|
1420 GtkAllocation *allocation)
|
|
1421 {
|
|
1422 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
|
|
1423 GtkAllocation child;
|
|
1424 GtkRequisition req;
|
|
1425 gboolean is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
|
|
1426
|
|
1427 widget->allocation = *allocation;
|
|
1428
|
|
1429 gtk_combo_box_check_appearance (combo_box);
|
|
1430
|
|
1431 if (!combo_box->priv->tree_view)
|
|
1432 {
|
|
1433 if (combo_box->priv->cell_view)
|
|
1434 {
|
|
1435 gint border_width, xthickness, ythickness;
|
|
1436 gint width;
|
|
1437
|
|
1438 /* menu mode */
|
|
1439 gtk_widget_size_allocate (combo_box->priv->button, allocation);
|
|
1440
|
|
1441 /* set some things ready */
|
|
1442 border_width = GTK_CONTAINER (combo_box->priv->button)->border_width;
|
|
1443 xthickness = combo_box->priv->button->style->xthickness;
|
|
1444 ythickness = combo_box->priv->button->style->ythickness;
|
|
1445
|
|
1446 child.x = allocation->x + border_width + 1 + xthickness + 2;
|
|
1447 child.y = allocation->y + border_width + 1 + ythickness + 2;
|
|
1448
|
|
1449 width = MAX(1, allocation->width - (border_width + 1 + xthickness * 2 + 4));
|
|
1450
|
|
1451 /* handle the children */
|
|
1452 gtk_widget_size_request (combo_box->priv->arrow, &req);
|
|
1453 child.width = req.width;
|
|
1454 child.height = MAX(1, allocation->height - 2 * (child.y - allocation->y));
|
|
1455 if (!is_rtl)
|
|
1456 child.x += width - req.width;
|
|
1457 gtk_widget_size_allocate (combo_box->priv->arrow, &child);
|
|
1458 if (is_rtl)
|
|
1459 child.x += req.width;
|
|
1460 gtk_widget_size_request (combo_box->priv->separator, &req);
|
|
1461 child.width = req.width;
|
|
1462 if (!is_rtl)
|
|
1463 child.x -= req.width;
|
|
1464 gtk_widget_size_allocate (combo_box->priv->separator, &child);
|
|
1465
|
|
1466 if (is_rtl)
|
|
1467 {
|
|
1468 child.x += req.width;
|
|
1469 child.width = MAX(1, allocation->x + allocation->width
|
|
1470 - (border_width + 1 + xthickness + 2) - child.x);
|
|
1471 }
|
|
1472 else
|
|
1473 {
|
|
1474 child.width = child.x;
|
|
1475 child.x = allocation->x + border_width + 1 + xthickness + 2;
|
|
1476 child.width = MAX(1, child.width - child.x);
|
|
1477 }
|
|
1478
|
|
1479 gtk_widget_size_allocate (GTK_BIN (widget)->child, &child);
|
|
1480 }
|
|
1481 else
|
|
1482 {
|
|
1483 gtk_widget_size_request (combo_box->priv->button, &req);
|
|
1484 if (is_rtl)
|
|
1485 child.x = allocation->x;
|
|
1486 else
|
|
1487 child.x = allocation->x + allocation->width - req.width;
|
|
1488 child.y = allocation->y;
|
|
1489 child.width = req.width;
|
|
1490 child.height = allocation->height;
|
|
1491 gtk_widget_size_allocate (combo_box->priv->button, &child);
|
|
1492
|
|
1493 if (is_rtl)
|
|
1494 child.x = allocation->x + req.width;
|
|
1495 else
|
|
1496 child.x = allocation->x;
|
|
1497 child.y = allocation->y;
|
|
1498 child.width = MAX(1, allocation->width - req.width);
|
|
1499 gtk_widget_size_allocate (GTK_BIN (widget)->child, &child);
|
|
1500 }
|
|
1501 }
|
|
1502 else
|
|
1503 {
|
|
1504 /* list mode */
|
|
1505
|
|
1506 /* button */
|
|
1507 gtk_widget_size_request (combo_box->priv->button, &req);
|
|
1508 if (is_rtl)
|
|
1509 child.x = allocation->x;
|
|
1510 else
|
|
1511 child.x = allocation->x + allocation->width - req.width;
|
|
1512 child.y = allocation->y;
|
|
1513 child.width = req.width;
|
|
1514 child.height = allocation->height;
|
|
1515 gtk_widget_size_allocate (combo_box->priv->button, &child);
|
|
1516
|
|
1517 /* frame */
|
|
1518 if (is_rtl)
|
|
1519 child.x = allocation->x + req.width;
|
|
1520 else
|
|
1521 child.x = allocation->x;
|
|
1522 child.y = allocation->y;
|
|
1523 child.width = MAX (1, allocation->width - req.width);
|
|
1524 child.height = allocation->height;
|
|
1525
|
|
1526 if (combo_box->priv->cell_view_frame)
|
|
1527 {
|
|
1528 gtk_widget_size_allocate (combo_box->priv->cell_view_frame, &child);
|
|
1529
|
|
1530 /* the sample */
|
|
1531 child.x +=
|
|
1532 GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
|
|
1533 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->xthickness;
|
|
1534 child.y +=
|
|
1535 GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
|
|
1536 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->ythickness;
|
|
1537 child.width -= 2 * (
|
|
1538 GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
|
|
1539 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->xthickness);
|
|
1540 child.width = MAX(1,child.width);
|
|
1541 child.height -= 2 * (
|
|
1542 GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
|
|
1543 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->ythickness);
|
|
1544 child.height = MAX(1,child.height);
|
|
1545 }
|
|
1546
|
|
1547 gtk_widget_size_allocate (GTK_BIN (combo_box)->child, &child);
|
|
1548 }
|
|
1549 }
|
|
1550
|
|
1551 static void
|
|
1552 gtk_combo_box_unset_model (GtkComboBox *combo_box)
|
|
1553 {
|
|
1554 if (combo_box->priv->model)
|
|
1555 {
|
|
1556 g_signal_handler_disconnect (combo_box->priv->model,
|
|
1557 combo_box->priv->inserted_id);
|
|
1558 g_signal_handler_disconnect (combo_box->priv->model,
|
|
1559 combo_box->priv->deleted_id);
|
|
1560 g_signal_handler_disconnect (combo_box->priv->model,
|
|
1561 combo_box->priv->reordered_id);
|
|
1562 g_signal_handler_disconnect (combo_box->priv->model,
|
|
1563 combo_box->priv->changed_id);
|
|
1564 }
|
|
1565
|
|
1566 /* menu mode */
|
|
1567 if (!combo_box->priv->tree_view)
|
|
1568 {
|
|
1569 if (combo_box->priv->popup_widget)
|
|
1570 gtk_container_foreach (GTK_CONTAINER (combo_box->priv->popup_widget),
|
|
1571 (GtkCallback)gtk_widget_destroy, NULL);
|
|
1572 }
|
|
1573
|
|
1574 if (combo_box->priv->model)
|
|
1575 {
|
|
1576 g_object_unref (G_OBJECT (combo_box->priv->model));
|
|
1577 combo_box->priv->model = NULL;
|
|
1578 }
|
|
1579
|
|
1580 if (combo_box->priv->cell_view)
|
|
1581 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (combo_box->priv->cell_view), NULL);
|
|
1582 }
|
|
1583
|
|
1584 static void
|
|
1585 gtk_combo_box_forall (GtkContainer *container,
|
|
1586 gboolean include_internals,
|
|
1587 GtkCallback callback,
|
|
1588 gpointer callback_data)
|
|
1589 {
|
|
1590 GtkComboBox *combo_box = GTK_COMBO_BOX (container);
|
|
1591
|
|
1592 if (include_internals)
|
|
1593 {
|
|
1594 if (combo_box->priv->button)
|
|
1595 (* callback) (combo_box->priv->button, callback_data);
|
|
1596 if (combo_box->priv->cell_view_frame)
|
|
1597 (* callback) (combo_box->priv->cell_view_frame, callback_data);
|
|
1598 }
|
|
1599
|
|
1600 if (GTK_BIN (container)->child)
|
|
1601 (* callback) (GTK_BIN (container)->child, callback_data);
|
|
1602 }
|
|
1603
|
|
1604 static gboolean
|
|
1605 gtk_combo_box_expose_event (GtkWidget *widget,
|
|
1606 GdkEventExpose *event)
|
|
1607 {
|
|
1608 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
|
|
1609
|
|
1610 if (!combo_box->priv->tree_view)
|
|
1611 {
|
|
1612 gtk_container_propagate_expose (GTK_CONTAINER (widget),
|
|
1613 combo_box->priv->button, event);
|
|
1614 }
|
|
1615 else
|
|
1616 {
|
|
1617 gtk_container_propagate_expose (GTK_CONTAINER (widget),
|
|
1618 combo_box->priv->button, event);
|
|
1619
|
|
1620 if (combo_box->priv->cell_view_frame)
|
|
1621 gtk_container_propagate_expose (GTK_CONTAINER (widget),
|
|
1622 combo_box->priv->cell_view_frame, event);
|
|
1623 }
|
|
1624
|
|
1625 gtk_container_propagate_expose (GTK_CONTAINER (widget),
|
|
1626 GTK_BIN (widget)->child, event);
|
|
1627
|
|
1628 return FALSE;
|
|
1629 }
|
|
1630
|
|
1631 static gboolean
|
|
1632 gtk_combo_box_scroll_event (GtkWidget *widget,
|
|
1633 GdkEventScroll *event)
|
|
1634 {
|
|
1635 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
|
|
1636 gint index;
|
|
1637 gint items;
|
|
1638
|
|
1639 index = gtk_combo_box_get_active (combo_box);
|
|
1640
|
|
1641 if (index != -1)
|
|
1642 {
|
|
1643 items = gtk_tree_model_iter_n_children (combo_box->priv->model, NULL);
|
|
1644
|
|
1645 if (event->direction == GDK_SCROLL_UP)
|
|
1646 index--;
|
|
1647 else
|
|
1648 index++;
|
|
1649
|
|
1650 gtk_combo_box_set_active (combo_box, CLAMP (index, 0, items - 1));
|
|
1651 }
|
|
1652
|
|
1653 return TRUE;
|
|
1654 }
|
|
1655
|
|
1656 /*
|
|
1657 * menu style
|
|
1658 */
|
|
1659
|
|
1660 static void
|
|
1661 cell_view_sync_cells (GtkComboBox *combo_box,
|
|
1662 GtkCellView *cell_view)
|
|
1663 {
|
|
1664 GSList *k;
|
|
1665
|
|
1666 for (k = combo_box->priv->cells; k; k = k->next)
|
|
1667 {
|
|
1668 GSList *j;
|
|
1669 ComboCellInfo *info = (ComboCellInfo *)k->data;
|
|
1670
|
|
1671 if (info->pack == GTK_PACK_START)
|
|
1672 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (cell_view),
|
|
1673 info->cell, info->expand);
|
|
1674 else if (info->pack == GTK_PACK_END)
|
|
1675 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (cell_view),
|
|
1676 info->cell, info->expand);
|
|
1677
|
|
1678 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (cell_view),
|
|
1679 info->cell,
|
|
1680 info->func, info->func_data, NULL);
|
|
1681
|
|
1682 for (j = info->attributes; j; j = j->next->next)
|
|
1683 {
|
|
1684 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (cell_view),
|
|
1685 info->cell,
|
|
1686 j->data,
|
|
1687 GPOINTER_TO_INT (j->next->data));
|
|
1688 }
|
|
1689 }
|
|
1690 }
|
|
1691
|
|
1692 static void
|
|
1693 gtk_combo_box_menu_setup (GtkComboBox *combo_box,
|
|
1694 gboolean add_children)
|
|
1695 {
|
|
1696 GtkWidget *menu;
|
|
1697
|
|
1698 if (combo_box->priv->cell_view)
|
|
1699 {
|
|
1700 combo_box->priv->button = gtk_toggle_button_new ();
|
|
1701 g_signal_connect (combo_box->priv->button, "toggled",
|
|
1702 G_CALLBACK (gtk_combo_box_button_toggled), combo_box);
|
|
1703 g_signal_connect_after (combo_box->priv->button, "key_press_event",
|
|
1704 G_CALLBACK (gtk_combo_box_key_press), combo_box);
|
|
1705 gtk_widget_set_parent (combo_box->priv->button,
|
|
1706 GTK_BIN (combo_box)->child->parent);
|
|
1707
|
|
1708 combo_box->priv->box = gtk_hbox_new (FALSE, 0);
|
|
1709 gtk_container_add (GTK_CONTAINER (combo_box->priv->button),
|
|
1710 combo_box->priv->box);
|
|
1711
|
|
1712 combo_box->priv->separator = gtk_vseparator_new ();
|
|
1713 gtk_container_add (GTK_CONTAINER (combo_box->priv->box),
|
|
1714 combo_box->priv->separator);
|
|
1715
|
|
1716 combo_box->priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
|
|
1717 gtk_container_add (GTK_CONTAINER (combo_box->priv->box),
|
|
1718 combo_box->priv->arrow);
|
|
1719
|
|
1720 gtk_widget_show_all (combo_box->priv->button);
|
|
1721 }
|
|
1722 else
|
|
1723 {
|
|
1724 combo_box->priv->button = gtk_toggle_button_new ();
|
|
1725 g_signal_connect (combo_box->priv->button, "toggled",
|
|
1726 G_CALLBACK (gtk_combo_box_button_toggled), combo_box);
|
|
1727 g_signal_connect_after (combo_box, "key_press_event",
|
|
1728 G_CALLBACK (gtk_combo_box_key_press), combo_box);
|
|
1729 gtk_widget_set_parent (combo_box->priv->button,
|
|
1730 GTK_BIN (combo_box)->child->parent);
|
|
1731
|
|
1732 combo_box->priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
|
|
1733 gtk_container_add (GTK_CONTAINER (combo_box->priv->button),
|
|
1734 combo_box->priv->arrow);
|
|
1735 gtk_widget_show_all (combo_box->priv->button);
|
|
1736 }
|
|
1737
|
|
1738 g_signal_connect (combo_box->priv->button, "button_press_event",
|
|
1739 G_CALLBACK (gtk_combo_box_menu_button_press),
|
|
1740 combo_box);
|
|
1741
|
|
1742 /* create our funky menu */
|
|
1743 menu = gtk_menu_new ();
|
|
1744 g_signal_connect (menu, "key_press_event",
|
|
1745 G_CALLBACK (gtk_combo_box_menu_key_press), combo_box);
|
|
1746 gtk_combo_box_set_popup_widget (combo_box, menu);
|
|
1747
|
|
1748 /* add items */
|
|
1749 if (add_children)
|
|
1750 gtk_combo_box_menu_fill (combo_box);
|
|
1751
|
|
1752 }
|
|
1753
|
|
1754 static void
|
|
1755 gtk_combo_box_menu_fill (GtkComboBox *combo_box)
|
|
1756 {
|
|
1757 gint i, items;
|
|
1758 GtkWidget *menu;
|
|
1759 GtkWidget *tmp;
|
|
1760
|
|
1761 if (!combo_box->priv->model)
|
|
1762 return;
|
|
1763
|
|
1764 items = gtk_tree_model_iter_n_children (combo_box->priv->model, NULL);
|
|
1765 menu = combo_box->priv->popup_widget;
|
|
1766
|
|
1767 for (i = 0; i < items; i++)
|
|
1768 {
|
|
1769 GtkTreePath *path;
|
11780
|
1770 #if GTK_CHECK_VERSION(2,2,0)
|
10708
|
1771 path = gtk_tree_path_new_from_indices (i, -1);
|
11780
|
1772 #else
|
|
1773 char buf[32];
|
|
1774 g_snprintf(buf, sizeof(buf), "%d", i);
|
|
1775 path = gtk_tree_path_new_from_string(buf);
|
|
1776 #endif
|
10708
|
1777 tmp = gtk_cell_view_menu_item_new_from_model (combo_box->priv->model,
|
|
1778 path);
|
|
1779 g_signal_connect (tmp, "activate",
|
|
1780 G_CALLBACK (gtk_combo_box_menu_item_activate),
|
|
1781 combo_box);
|
|
1782
|
|
1783 cell_view_sync_cells (combo_box,
|
|
1784 GTK_CELL_VIEW (GTK_BIN (tmp)->child));
|
|
1785
|
|
1786 gtk_menu_shell_append (GTK_MENU_SHELL (menu), tmp);
|
|
1787
|
|
1788 if (combo_box->priv->wrap_width)
|
|
1789 gtk_combo_box_relayout_item (combo_box, i);
|
|
1790
|
|
1791 gtk_widget_show (tmp);
|
|
1792
|
|
1793 gtk_tree_path_free (path);
|
|
1794 }
|
|
1795 }
|
|
1796
|
|
1797 static void
|
|
1798 gtk_combo_box_menu_destroy (GtkComboBox *combo_box)
|
|
1799 {
|
|
1800 g_signal_handlers_disconnect_matched (combo_box->priv->button,
|
|
1801 G_SIGNAL_MATCH_DATA,
|
|
1802 0, 0, NULL,
|
|
1803 gtk_combo_box_menu_button_press, NULL);
|
|
1804
|
|
1805 /* unparent will remove our latest ref */
|
|
1806 gtk_widget_unparent (combo_box->priv->button);
|
|
1807
|
|
1808 combo_box->priv->box = NULL;
|
|
1809 combo_box->priv->button = NULL;
|
|
1810 combo_box->priv->arrow = NULL;
|
|
1811 combo_box->priv->separator = NULL;
|
|
1812
|
|
1813 /* changing the popup window will unref the menu and the children */
|
|
1814 }
|
|
1815
|
|
1816 /*
|
|
1817 * grid
|
|
1818 */
|
|
1819
|
|
1820 static void
|
|
1821 gtk_combo_box_item_get_size (GtkComboBox *combo_box,
|
|
1822 gint index_,
|
|
1823 gint *cols,
|
|
1824 gint *rows)
|
|
1825 {
|
|
1826 GtkTreeIter iter;
|
|
1827
|
|
1828 gtk_tree_model_iter_nth_child (combo_box->priv->model, &iter, NULL, index_);
|
|
1829
|
|
1830 if (cols)
|
|
1831 {
|
|
1832 if (combo_box->priv->col_column == -1)
|
|
1833 *cols = 1;
|
|
1834 else
|
|
1835 gtk_tree_model_get (combo_box->priv->model, &iter,
|
|
1836 combo_box->priv->col_column, cols,
|
|
1837 -1);
|
|
1838 }
|
|
1839
|
|
1840 if (rows)
|
|
1841 {
|
|
1842 if (combo_box->priv->row_column == -1)
|
|
1843 *rows = 1;
|
|
1844 else
|
|
1845 gtk_tree_model_get (combo_box->priv->model, &iter,
|
|
1846 combo_box->priv->row_column, rows,
|
|
1847 -1);
|
|
1848 }
|
|
1849 }
|
|
1850
|
|
1851 static gboolean
|
|
1852 menu_occupied (GtkMenu *menu,
|
|
1853 guint left_attach,
|
|
1854 guint right_attach,
|
|
1855 guint top_attach,
|
|
1856 guint bottom_attach)
|
|
1857 {
|
|
1858 GList *i;
|
|
1859
|
|
1860 g_return_val_if_fail (GTK_IS_MENU (menu), TRUE);
|
|
1861 g_return_val_if_fail (left_attach < right_attach, TRUE);
|
|
1862 g_return_val_if_fail (top_attach < bottom_attach, TRUE);
|
|
1863
|
|
1864 for (i = GTK_MENU_SHELL (menu)->children; i; i = i->next)
|
|
1865 {
|
|
1866 guint l, r, b, t;
|
|
1867 gboolean h_intersect = FALSE;
|
|
1868 gboolean v_intersect = FALSE;
|
|
1869
|
|
1870 gtk_container_child_get (GTK_CONTAINER (menu), i->data,
|
|
1871 "left_attach", &l,
|
|
1872 "right_attach", &r,
|
|
1873 "bottom_attach", &b,
|
|
1874 "top_attach", &t,
|
|
1875 NULL);
|
|
1876
|
|
1877 /* look if this item intersects with the given coordinates */
|
|
1878 h_intersect = left_attach <= l && l <= right_attach;
|
|
1879 h_intersect &= left_attach <= r && r <= right_attach;
|
|
1880
|
|
1881 v_intersect = top_attach <= t && t <= bottom_attach;
|
|
1882 v_intersect &= top_attach <= b && b <= bottom_attach;
|
|
1883
|
|
1884 if (h_intersect && v_intersect)
|
|
1885 return TRUE;
|
|
1886 }
|
|
1887
|
|
1888 return FALSE;
|
|
1889 }
|
|
1890
|
|
1891 static void
|
|
1892 gtk_combo_box_relayout_item (GtkComboBox *combo_box,
|
|
1893 gint index)
|
|
1894 {
|
|
1895 gint current_col = 0, current_row = 0;
|
|
1896 gint rows, cols;
|
|
1897 GList *list, *nth;
|
|
1898 GtkWidget *item, *last;
|
|
1899 GtkWidget *menu;
|
|
1900
|
|
1901 menu = combo_box->priv->popup_widget;
|
|
1902 if (!GTK_IS_MENU_SHELL (menu))
|
|
1903 return;
|
|
1904
|
|
1905 list = gtk_container_get_children (GTK_CONTAINER (menu));
|
|
1906 nth = g_list_nth (list, index);
|
|
1907 item = nth->data;
|
|
1908 if (nth->prev)
|
|
1909 last = nth->prev->data;
|
|
1910 else
|
|
1911 last = NULL;
|
|
1912 g_list_free (list);
|
|
1913
|
|
1914 gtk_combo_box_item_get_size (combo_box, index, &cols, &rows);
|
|
1915
|
|
1916 if (combo_box->priv->col_column == -1 &&
|
|
1917 combo_box->priv->row_column == -1 &&
|
|
1918 last)
|
|
1919 {
|
|
1920 gtk_container_child_get (GTK_CONTAINER (menu),
|
|
1921 last,
|
|
1922 "right_attach", ¤t_col,
|
|
1923 "top_attach", ¤t_row,
|
|
1924 NULL);
|
|
1925 if (current_col + cols > combo_box->priv->wrap_width)
|
|
1926 {
|
|
1927 current_col = 0;
|
|
1928 current_row++;
|
|
1929 }
|
|
1930 }
|
|
1931 else
|
|
1932 {
|
|
1933 /* look for a good spot */
|
|
1934 while (1)
|
|
1935 {
|
|
1936 if (current_col + cols > combo_box->priv->wrap_width)
|
|
1937 {
|
|
1938 current_col = 0;
|
|
1939 current_row++;
|
|
1940 }
|
|
1941
|
|
1942 if (!menu_occupied (GTK_MENU (menu),
|
|
1943 current_col, current_col + cols,
|
|
1944 current_row, current_row + rows))
|
|
1945 break;
|
|
1946
|
|
1947 current_col++;
|
|
1948 }
|
|
1949 }
|
|
1950
|
|
1951 /* set attach props */
|
|
1952 gtk_menu_attach (GTK_MENU (menu), item,
|
|
1953 current_col, current_col + cols,
|
|
1954 current_row, current_row + rows);
|
|
1955 }
|
|
1956
|
|
1957 static void
|
|
1958 gtk_combo_box_relayout (GtkComboBox *combo_box)
|
|
1959 {
|
|
1960 GList *list, *j;
|
|
1961 GtkWidget *menu;
|
|
1962
|
|
1963 menu = combo_box->priv->popup_widget;
|
|
1964
|
|
1965 /* do nothing unless we are in menu style and realized */
|
|
1966 if (combo_box->priv->tree_view || !GTK_IS_MENU_SHELL (menu))
|
|
1967 return;
|
|
1968
|
|
1969 /* get rid of all children */
|
|
1970 list = gtk_container_get_children (GTK_CONTAINER (menu));
|
|
1971
|
|
1972 for (j = g_list_last (list); j; j = j->prev)
|
|
1973 gtk_container_remove (GTK_CONTAINER (menu), j->data);
|
|
1974
|
|
1975 g_list_free (list);
|
|
1976
|
|
1977 /* and relayout */
|
|
1978 gtk_combo_box_menu_fill (combo_box);
|
|
1979 }
|
|
1980
|
|
1981 /* callbacks */
|
|
1982 static gboolean
|
|
1983 gtk_combo_box_menu_button_press (GtkWidget *widget,
|
|
1984 GdkEventButton *event,
|
|
1985 gpointer user_data)
|
|
1986 {
|
|
1987 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
|
|
1988
|
|
1989 if (! GTK_IS_MENU (combo_box->priv->popup_widget))
|
|
1990 return FALSE;
|
|
1991
|
|
1992 if (event->type == GDK_BUTTON_PRESS && event->button == 1)
|
|
1993 {
|
|
1994 combo_box->priv->popup_in_progress = TRUE;
|
|
1995
|
|
1996 gtk_menu_set_active (GTK_MENU (combo_box->priv->popup_widget),
|
|
1997 combo_box->priv->active_item);
|
|
1998
|
|
1999 if (combo_box->priv->wrap_width == 0)
|
|
2000 {
|
|
2001 GtkRequisition requisition;
|
|
2002 gint width;
|
|
2003
|
|
2004 width = GTK_WIDGET (combo_box)->allocation.width;
|
|
2005 gtk_widget_size_request (combo_box->priv->popup_widget, &requisition);
|
|
2006
|
|
2007 gtk_widget_set_size_request (combo_box->priv->popup_widget,
|
|
2008 MAX (width, requisition.width), -1);
|
|
2009 }
|
|
2010
|
|
2011 gtk_menu_popup (GTK_MENU (combo_box->priv->popup_widget),
|
|
2012 NULL, NULL,
|
11780
|
2013 #if GTK_CHECK_VERSION(2,2,0)
|
|
2014 gtk_combo_box_menu_position,
|
|
2015 #else
|
|
2016 NULL,
|
|
2017 #endif
|
|
2018 combo_box, event->button, event->time);
|
10708
|
2019
|
|
2020 return TRUE;
|
|
2021 }
|
|
2022
|
|
2023 return FALSE;
|
|
2024 }
|
|
2025
|
|
2026 static void
|
|
2027 gtk_combo_box_menu_item_activate (GtkWidget *item,
|
|
2028 gpointer user_data)
|
|
2029 {
|
|
2030 gint index;
|
|
2031 GtkWidget *menu;
|
|
2032 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
|
|
2033
|
|
2034 menu = combo_box->priv->popup_widget;
|
|
2035 g_return_if_fail (GTK_IS_MENU (menu));
|
|
2036
|
|
2037 index = g_list_index (GTK_MENU_SHELL (menu)->children, item);
|
|
2038
|
|
2039 gtk_combo_box_set_active (combo_box, index);
|
|
2040 }
|
|
2041
|
|
2042 static void
|
|
2043 gtk_combo_box_model_row_inserted (GtkTreeModel *model,
|
|
2044 GtkTreePath *path,
|
|
2045 GtkTreeIter *iter,
|
|
2046 gpointer user_data)
|
|
2047 {
|
|
2048 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
|
|
2049 gint index = gtk_tree_path_get_indices (path)[0];
|
|
2050
|
|
2051 if (combo_box->priv->active_item >= index)
|
|
2052 combo_box->priv->active_item++;
|
|
2053
|
|
2054 if (!combo_box->priv->tree_view)
|
|
2055 gtk_combo_box_menu_row_inserted (model, path, iter, user_data);
|
|
2056 }
|
|
2057
|
|
2058 static void
|
|
2059 gtk_combo_box_model_row_deleted (GtkTreeModel *model,
|
|
2060 GtkTreePath *path,
|
|
2061 gpointer user_data)
|
|
2062 {
|
|
2063 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
|
|
2064 gint index = gtk_tree_path_get_indices (path)[0];
|
|
2065
|
|
2066 if (!combo_box->priv->tree_view)
|
|
2067 gtk_combo_box_menu_row_deleted (model, path, user_data);
|
|
2068
|
|
2069 if (index == combo_box->priv->active_item)
|
|
2070 {
|
|
2071 gint items = gtk_tree_model_iter_n_children (model, NULL);
|
|
2072
|
|
2073 if (items == 0)
|
|
2074 gtk_combo_box_set_active_internal (combo_box, -1);
|
|
2075 else if (index == items)
|
|
2076 gtk_combo_box_set_active_internal (combo_box, index - 1);
|
|
2077 else
|
|
2078 gtk_combo_box_set_active_internal (combo_box, index);
|
|
2079 }
|
|
2080 else if (combo_box->priv->active_item > index)
|
|
2081 combo_box->priv->active_item--;
|
|
2082 }
|
|
2083
|
|
2084 static void
|
|
2085 gtk_combo_box_model_rows_reordered (GtkTreeModel *model,
|
|
2086 GtkTreePath *path,
|
|
2087 GtkTreeIter *iter,
|
|
2088 gint *new_order,
|
|
2089 gpointer user_data)
|
|
2090 {
|
|
2091 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
|
|
2092 gint items = gtk_tree_model_iter_n_children (model, NULL);
|
|
2093 gint i;
|
|
2094
|
|
2095 for (i = 0; i < items; i++)
|
|
2096 if (new_order[i] == combo_box->priv->active_item)
|
|
2097 {
|
|
2098 combo_box->priv->active_item = i;
|
|
2099 break;
|
|
2100 }
|
|
2101
|
|
2102 if (!combo_box->priv->tree_view)
|
|
2103 gtk_combo_box_menu_rows_reordered (model, path, iter, new_order, user_data);
|
|
2104 }
|
|
2105
|
|
2106 static void
|
|
2107 gtk_combo_box_model_row_changed (GtkTreeModel *model,
|
|
2108 GtkTreePath *path,
|
|
2109 GtkTreeIter *iter,
|
|
2110 gpointer user_data)
|
|
2111 {
|
|
2112 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
|
|
2113 gint index = gtk_tree_path_get_indices (path)[0];
|
|
2114
|
|
2115 if (index == combo_box->priv->active_item &&
|
|
2116 combo_box->priv->cell_view)
|
|
2117 gtk_widget_queue_resize (GTK_WIDGET (combo_box->priv->cell_view));
|
|
2118
|
|
2119 if (combo_box->priv->tree_view)
|
|
2120 gtk_combo_box_list_row_changed (model, path, iter, user_data);
|
|
2121 else
|
|
2122 gtk_combo_box_menu_row_changed (model, path, iter, user_data);
|
|
2123 }
|
|
2124
|
|
2125
|
|
2126 static void
|
|
2127 gtk_combo_box_menu_row_inserted (GtkTreeModel *model,
|
|
2128 GtkTreePath *path,
|
|
2129 GtkTreeIter *iter,
|
|
2130 gpointer user_data)
|
|
2131 {
|
|
2132 GtkWidget *menu;
|
|
2133 GtkWidget *item;
|
|
2134 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
|
|
2135
|
|
2136 if (!combo_box->priv->popup_widget)
|
|
2137 return;
|
|
2138
|
|
2139 menu = combo_box->priv->popup_widget;
|
|
2140 g_return_if_fail (GTK_IS_MENU (menu));
|
|
2141
|
|
2142 item = gtk_cell_view_menu_item_new_from_model (model, path);
|
|
2143 g_signal_connect (item, "activate",
|
|
2144 G_CALLBACK (gtk_combo_box_menu_item_activate),
|
|
2145 combo_box);
|
|
2146
|
|
2147 cell_view_sync_cells (combo_box, GTK_CELL_VIEW (GTK_BIN (item)->child));
|
|
2148
|
|
2149 gtk_menu_shell_insert (GTK_MENU_SHELL (menu), item,
|
|
2150 gtk_tree_path_get_indices (path)[0]);
|
|
2151 gtk_widget_show (item);
|
|
2152 }
|
|
2153
|
|
2154 static void
|
|
2155 gtk_combo_box_menu_row_deleted (GtkTreeModel *model,
|
|
2156 GtkTreePath *path,
|
|
2157 gpointer user_data)
|
|
2158 {
|
|
2159 gint index;
|
|
2160 GtkWidget *menu;
|
|
2161 GtkWidget *item;
|
|
2162 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
|
|
2163
|
|
2164 if (!combo_box->priv->popup_widget)
|
|
2165 return;
|
|
2166
|
|
2167 index = gtk_tree_path_get_indices (path)[0];
|
|
2168
|
|
2169 menu = combo_box->priv->popup_widget;
|
|
2170 g_return_if_fail (GTK_IS_MENU (menu));
|
|
2171
|
|
2172 item = g_list_nth_data (GTK_MENU_SHELL (menu)->children, index);
|
|
2173 g_return_if_fail (GTK_IS_MENU_ITEM (item));
|
|
2174
|
|
2175 gtk_container_remove (GTK_CONTAINER (menu), item);
|
|
2176 }
|
|
2177
|
|
2178 static void
|
|
2179 gtk_combo_box_menu_rows_reordered (GtkTreeModel *model,
|
|
2180 GtkTreePath *path,
|
|
2181 GtkTreeIter *iter,
|
|
2182 gint *new_order,
|
|
2183 gpointer user_data)
|
|
2184 {
|
|
2185 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
|
|
2186
|
|
2187 gtk_combo_box_relayout (combo_box);
|
|
2188 }
|
|
2189
|
|
2190 static void
|
|
2191 gtk_combo_box_menu_row_changed (GtkTreeModel *model,
|
|
2192 GtkTreePath *path,
|
|
2193 GtkTreeIter *iter,
|
|
2194 gpointer user_data)
|
|
2195 {
|
|
2196 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
|
|
2197 gint width;
|
|
2198
|
|
2199 if (!combo_box->priv->popup_widget)
|
|
2200 return;
|
|
2201
|
|
2202 if (combo_box->priv->wrap_width)
|
|
2203 gtk_combo_box_relayout_item (combo_box,
|
|
2204 gtk_tree_path_get_indices (path)[0]);
|
|
2205
|
|
2206 width = gtk_combo_box_calc_requested_width (combo_box, path);
|
|
2207
|
|
2208 if (width > combo_box->priv->width)
|
|
2209 {
|
|
2210 if (combo_box->priv->cell_view)
|
|
2211 {
|
|
2212 gtk_widget_set_size_request (combo_box->priv->cell_view, width, -1);
|
|
2213 gtk_widget_queue_resize (combo_box->priv->cell_view);
|
|
2214 }
|
|
2215 combo_box->priv->width = width;
|
|
2216 }
|
|
2217 }
|
|
2218
|
|
2219 /*
|
|
2220 * list style
|
|
2221 */
|
|
2222
|
|
2223 static void
|
|
2224 gtk_combo_box_list_setup (GtkComboBox *combo_box)
|
|
2225 {
|
|
2226 GSList *i;
|
|
2227 GtkTreeSelection *sel;
|
|
2228
|
|
2229 combo_box->priv->button = gtk_toggle_button_new ();
|
|
2230 gtk_widget_set_parent (combo_box->priv->button,
|
|
2231 GTK_BIN (combo_box)->child->parent);
|
|
2232 g_signal_connect (combo_box->priv->button, "button_press_event",
|
|
2233 G_CALLBACK (gtk_combo_box_list_button_pressed), combo_box);
|
|
2234 g_signal_connect (combo_box->priv->button, "toggled",
|
|
2235 G_CALLBACK (gtk_combo_box_button_toggled), combo_box);
|
|
2236 g_signal_connect_after (combo_box, "key_press_event",
|
|
2237 G_CALLBACK (gtk_combo_box_key_press), combo_box);
|
|
2238
|
|
2239 combo_box->priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
|
|
2240 gtk_container_add (GTK_CONTAINER (combo_box->priv->button),
|
|
2241 combo_box->priv->arrow);
|
|
2242 combo_box->priv->separator = NULL;
|
|
2243 gtk_widget_show_all (combo_box->priv->button);
|
|
2244
|
|
2245 if (combo_box->priv->cell_view)
|
|
2246 {
|
|
2247 combo_box->priv->cell_view_frame = gtk_frame_new (NULL);
|
|
2248 gtk_widget_set_parent (combo_box->priv->cell_view_frame,
|
|
2249 GTK_BIN (combo_box)->child->parent);
|
|
2250 gtk_frame_set_shadow_type (GTK_FRAME (combo_box->priv->cell_view_frame),
|
|
2251 GTK_SHADOW_IN);
|
|
2252
|
|
2253 gtk_cell_view_set_background_color (GTK_CELL_VIEW (combo_box->priv->cell_view),
|
|
2254 >K_WIDGET (combo_box)->style->base[GTK_WIDGET_STATE (combo_box)]);
|
|
2255
|
|
2256 combo_box->priv->box = gtk_event_box_new ();
|
|
2257 /*
|
|
2258 gtk_event_box_set_visible_window (GTK_EVENT_BOX (combo_box->priv->box),
|
|
2259 FALSE);
|
|
2260 */
|
|
2261
|
|
2262 gtk_container_add (GTK_CONTAINER (combo_box->priv->cell_view_frame),
|
|
2263 combo_box->priv->box);
|
|
2264
|
|
2265 gtk_widget_show_all (combo_box->priv->cell_view_frame);
|
|
2266
|
|
2267 g_signal_connect (combo_box->priv->box, "button_press_event",
|
|
2268 G_CALLBACK (gtk_combo_box_list_button_pressed),
|
|
2269 combo_box);
|
|
2270 }
|
|
2271
|
|
2272 combo_box->priv->tree_view = gtk_tree_view_new ();
|
|
2273 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (combo_box->priv->tree_view));
|
|
2274 gtk_tree_selection_set_mode (sel, GTK_SELECTION_BROWSE);
|
|
2275 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (combo_box->priv->tree_view),
|
|
2276 FALSE);
|
|
2277 /*
|
|
2278 _gtk_tree_view_set_hover_selection (GTK_TREE_VIEW (combo_box->priv->tree_view),
|
|
2279 TRUE);
|
|
2280 */
|
|
2281 if (combo_box->priv->model)
|
|
2282 gtk_tree_view_set_model (GTK_TREE_VIEW (combo_box->priv->tree_view),
|
|
2283 combo_box->priv->model);
|
|
2284
|
|
2285 g_signal_connect (combo_box->priv->tree_view, "button_press_event",
|
|
2286 G_CALLBACK (gtk_combo_box_list_button_pressed),
|
|
2287 combo_box);
|
|
2288 g_signal_connect (combo_box->priv->tree_view, "button_release_event",
|
|
2289 G_CALLBACK (gtk_combo_box_list_button_released),
|
|
2290 combo_box);
|
|
2291 g_signal_connect (combo_box->priv->tree_view, "key_press_event",
|
|
2292 G_CALLBACK (gtk_combo_box_list_key_press),
|
|
2293 combo_box);
|
|
2294
|
|
2295 combo_box->priv->column = gtk_tree_view_column_new ();
|
|
2296 gtk_tree_view_append_column (GTK_TREE_VIEW (combo_box->priv->tree_view),
|
|
2297 combo_box->priv->column);
|
|
2298
|
|
2299 /* sync up */
|
|
2300 for (i = combo_box->priv->cells; i; i = i->next)
|
|
2301 {
|
|
2302 GSList *j;
|
|
2303 ComboCellInfo *info = (ComboCellInfo *)i->data;
|
|
2304
|
|
2305 if (info->pack == GTK_PACK_START)
|
|
2306 gtk_tree_view_column_pack_start (combo_box->priv->column,
|
|
2307 info->cell, info->expand);
|
|
2308 else if (info->pack == GTK_PACK_END)
|
|
2309 gtk_tree_view_column_pack_end (combo_box->priv->column,
|
|
2310 info->cell, info->expand);
|
|
2311
|
|
2312 for (j = info->attributes; j; j = j->next->next)
|
|
2313 {
|
|
2314 gtk_tree_view_column_add_attribute (combo_box->priv->column,
|
|
2315 info->cell,
|
|
2316 j->data,
|
|
2317 GPOINTER_TO_INT (j->next->data));
|
|
2318 }
|
|
2319 }
|
|
2320
|
|
2321 if (combo_box->priv->active_item != -1)
|
|
2322 {
|
|
2323 GtkTreePath *path;
|
|
2324
|
11780
|
2325 #if GTK_CHECK_VERSION(2,2,0)
|
10708
|
2326 path = gtk_tree_path_new_from_indices (combo_box->priv->active_item, -1);
|
11780
|
2327 #else
|
|
2328 char buf[32];
|
|
2329 g_snprintf(buf, sizeof(buf), "%d", combo_box->priv->active_item);
|
|
2330 path = gtk_tree_path_new_from_string(buf);
|
|
2331 #endif
|
10708
|
2332 if (path)
|
|
2333 {
|
|
2334 gtk_tree_view_set_cursor (GTK_TREE_VIEW (combo_box->priv->tree_view),
|
|
2335 path, NULL, FALSE);
|
|
2336 gtk_tree_path_free (path);
|
|
2337 }
|
|
2338 }
|
|
2339
|
|
2340 /* set sample/popup widgets */
|
|
2341 gtk_combo_box_set_popup_widget (combo_box, combo_box->priv->tree_view);
|
|
2342
|
|
2343 gtk_widget_show (combo_box->priv->tree_view);
|
|
2344 }
|
|
2345
|
|
2346 static void
|
|
2347 gtk_combo_box_list_destroy (GtkComboBox *combo_box)
|
|
2348 {
|
|
2349 /* disconnect signals */
|
|
2350 g_signal_handlers_disconnect_matched (combo_box->priv->tree_view,
|
|
2351 G_SIGNAL_MATCH_DATA,
|
|
2352 0, 0, NULL, NULL, combo_box);
|
|
2353 g_signal_handlers_disconnect_matched (combo_box->priv->button,
|
|
2354 G_SIGNAL_MATCH_DATA,
|
|
2355 0, 0, NULL,
|
|
2356 gtk_combo_box_list_button_pressed,
|
|
2357 NULL);
|
|
2358 if (combo_box->priv->box)
|
|
2359 g_signal_handlers_disconnect_matched (combo_box->priv->box,
|
|
2360 G_SIGNAL_MATCH_DATA,
|
|
2361 0, 0, NULL,
|
|
2362 gtk_combo_box_list_button_pressed,
|
|
2363 NULL);
|
|
2364
|
|
2365 /* destroy things (unparent will kill the latest ref from us)
|
|
2366 * last unref on button will destroy the arrow
|
|
2367 */
|
|
2368 gtk_widget_unparent (combo_box->priv->button);
|
|
2369 combo_box->priv->button = NULL;
|
|
2370 combo_box->priv->arrow = NULL;
|
|
2371
|
|
2372 if (combo_box->priv->cell_view)
|
|
2373 {
|
|
2374 g_object_set (G_OBJECT (combo_box->priv->cell_view),
|
|
2375 "background_set", FALSE,
|
|
2376 NULL);
|
|
2377 }
|
|
2378
|
|
2379 if (combo_box->priv->cell_view_frame)
|
|
2380 {
|
|
2381 gtk_widget_unparent (combo_box->priv->cell_view_frame);
|
|
2382 combo_box->priv->cell_view_frame = NULL;
|
|
2383 combo_box->priv->box = NULL;
|
|
2384 }
|
|
2385
|
|
2386 gtk_widget_destroy (combo_box->priv->tree_view);
|
|
2387
|
|
2388 combo_box->priv->tree_view = NULL;
|
|
2389 combo_box->priv->popup_widget = NULL;
|
|
2390 }
|
|
2391
|
|
2392 /* callbacks */
|
|
2393 static void
|
|
2394 gtk_combo_box_list_remove_grabs (GtkComboBox *combo_box)
|
|
2395 {
|
|
2396 if (combo_box->priv->tree_view &&
|
|
2397 GTK_WIDGET_HAS_GRAB (combo_box->priv->tree_view))
|
|
2398 {
|
|
2399 gtk_grab_remove (combo_box->priv->tree_view);
|
|
2400 }
|
|
2401
|
|
2402 if (combo_box->priv->popup_window &&
|
|
2403 GTK_WIDGET_HAS_GRAB (combo_box->priv->popup_window))
|
|
2404 {
|
|
2405 gtk_grab_remove (combo_box->priv->popup_window);
|
|
2406 gdk_keyboard_ungrab (GDK_CURRENT_TIME);
|
|
2407 gdk_pointer_ungrab (GDK_CURRENT_TIME);
|
|
2408 }
|
|
2409 }
|
|
2410
|
|
2411 static gboolean
|
|
2412 gtk_combo_box_list_button_pressed (GtkWidget *widget,
|
|
2413 GdkEventButton *event,
|
|
2414 gpointer data)
|
|
2415 {
|
|
2416 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
|
|
2417
|
|
2418 GtkWidget *ewidget = gtk_get_event_widget ((GdkEvent *)event);
|
|
2419
|
|
2420 if (ewidget == combo_box->priv->tree_view)
|
|
2421 return TRUE;
|
|
2422
|
|
2423 if ((ewidget != combo_box->priv->button && ewidget != combo_box->priv->box) ||
|
|
2424 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (combo_box->priv->button)))
|
|
2425 return FALSE;
|
|
2426
|
|
2427 gtk_combo_box_popup (combo_box);
|
|
2428
|
|
2429 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
|
|
2430 TRUE);
|
|
2431
|
|
2432 combo_box->priv->popup_in_progress = TRUE;
|
|
2433
|
|
2434 return TRUE;
|
|
2435 }
|
|
2436
|
|
2437 static gboolean
|
|
2438 gtk_combo_box_list_button_released (GtkWidget *widget,
|
|
2439 GdkEventButton *event,
|
|
2440 gpointer data)
|
|
2441 {
|
|
2442 gboolean ret;
|
|
2443 GtkTreePath *path = NULL;
|
|
2444
|
|
2445 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
|
|
2446
|
|
2447 gboolean popup_in_progress = FALSE;
|
|
2448
|
|
2449 GtkWidget *ewidget = gtk_get_event_widget ((GdkEvent *)event);
|
|
2450
|
|
2451 if (combo_box->priv->popup_in_progress)
|
|
2452 {
|
|
2453 popup_in_progress = TRUE;
|
|
2454 combo_box->priv->popup_in_progress = FALSE;
|
|
2455 }
|
|
2456
|
|
2457 if (ewidget != combo_box->priv->tree_view)
|
|
2458 {
|
|
2459 if (ewidget == combo_box->priv->button &&
|
|
2460 !popup_in_progress &&
|
|
2461 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (combo_box->priv->button)))
|
|
2462 {
|
|
2463 gtk_combo_box_popdown (combo_box);
|
|
2464 return TRUE;
|
|
2465 }
|
|
2466
|
|
2467 /* released outside treeview */
|
|
2468 if (ewidget != combo_box->priv->button)
|
|
2469 {
|
|
2470 gtk_combo_box_popdown (combo_box);
|
|
2471
|
|
2472 return TRUE;
|
|
2473 }
|
|
2474
|
|
2475 return FALSE;
|
|
2476 }
|
|
2477
|
|
2478 /* select something cool */
|
|
2479 ret = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
|
|
2480 event->x, event->y,
|
|
2481 &path,
|
|
2482 NULL, NULL, NULL);
|
|
2483
|
|
2484 if (!ret)
|
|
2485 return TRUE; /* clicked outside window? */
|
|
2486
|
|
2487 gtk_combo_box_set_active (combo_box, gtk_tree_path_get_indices (path)[0]);
|
|
2488 gtk_combo_box_popdown (combo_box);
|
|
2489
|
|
2490 gtk_tree_path_free (path);
|
|
2491
|
|
2492 return TRUE;
|
|
2493 }
|
|
2494
|
|
2495 static gboolean
|
|
2496 gtk_combo_box_key_press (GtkWidget *widget,
|
|
2497 GdkEventKey *event,
|
|
2498 gpointer data)
|
|
2499 {
|
|
2500 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
|
|
2501 guint state = event->state & gtk_accelerator_get_default_mod_mask ();
|
|
2502 gint items = 0;
|
|
2503 gint index = gtk_combo_box_get_active (combo_box);
|
|
2504 gint new_index;
|
|
2505
|
|
2506 if (combo_box->priv->model)
|
|
2507 items = gtk_tree_model_iter_n_children (combo_box->priv->model, NULL);
|
|
2508
|
|
2509 if ((event->keyval == GDK_Down || event->keyval == GDK_KP_Down) &&
|
|
2510 state == GDK_MOD1_MASK)
|
|
2511 {
|
|
2512 gtk_combo_box_popup (combo_box);
|
|
2513
|
|
2514 return TRUE;
|
|
2515 }
|
|
2516
|
|
2517 switch (event->keyval)
|
|
2518 {
|
|
2519 case GDK_Down:
|
|
2520 case GDK_KP_Down:
|
|
2521 new_index = index + 1;
|
|
2522 break;
|
|
2523 case GDK_Up:
|
|
2524 case GDK_KP_Up:
|
|
2525 new_index = index - 1;
|
|
2526 break;
|
|
2527 case GDK_Page_Up:
|
|
2528 case GDK_KP_Page_Up:
|
|
2529 case GDK_Home:
|
|
2530 case GDK_KP_Home:
|
|
2531 new_index = 0;
|
|
2532 break;
|
|
2533 case GDK_Page_Down:
|
|
2534 case GDK_KP_Page_Down:
|
|
2535 case GDK_End:
|
|
2536 case GDK_KP_End:
|
|
2537 new_index = items - 1;
|
|
2538 break;
|
|
2539 default:
|
|
2540 return FALSE;
|
|
2541 }
|
|
2542
|
|
2543 if (items > 0)
|
|
2544 gtk_combo_box_set_active (combo_box, CLAMP (new_index, 0, items - 1));
|
|
2545
|
|
2546 return TRUE;
|
|
2547 }
|
|
2548
|
|
2549 static gboolean
|
|
2550 gtk_combo_box_menu_key_press (GtkWidget *widget,
|
|
2551 GdkEventKey *event,
|
|
2552 gpointer data)
|
|
2553 {
|
|
2554 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
|
|
2555 guint state = event->state & gtk_accelerator_get_default_mod_mask ();
|
|
2556
|
|
2557 if ((event->keyval == GDK_Up || event->keyval == GDK_KP_Up) &&
|
|
2558 state == GDK_MOD1_MASK)
|
|
2559 {
|
|
2560 gtk_combo_box_popdown (combo_box);
|
|
2561
|
|
2562 return TRUE;
|
|
2563 }
|
|
2564
|
|
2565 return FALSE;
|
|
2566 }
|
|
2567
|
|
2568 static gboolean
|
|
2569 gtk_combo_box_list_key_press (GtkWidget *widget,
|
|
2570 GdkEventKey *event,
|
|
2571 gpointer data)
|
|
2572 {
|
|
2573 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
|
|
2574 guint state = event->state & gtk_accelerator_get_default_mod_mask ();
|
|
2575
|
|
2576 if (event->keyval == GDK_Escape ||
|
|
2577 ((event->keyval == GDK_Up || event->keyval == GDK_KP_Up) &&
|
|
2578 state == GDK_MOD1_MASK))
|
|
2579 {
|
|
2580 /* reset active item -- this is incredibly lame and ugly */
|
|
2581 gtk_combo_box_set_active (combo_box,
|
|
2582 gtk_combo_box_get_active (combo_box));
|
|
2583
|
|
2584 gtk_combo_box_popdown (combo_box);
|
|
2585
|
|
2586 return TRUE;
|
|
2587 }
|
|
2588
|
|
2589 if (event->keyval == GDK_Return || event->keyval == GDK_KP_Enter ||
|
|
2590 event->keyval == GDK_space || event->keyval == GDK_KP_Space)
|
|
2591 {
|
|
2592 gboolean ret = FALSE;
|
|
2593 GtkTreeIter iter;
|
|
2594 GtkTreeModel *model = NULL;
|
|
2595
|
|
2596 if (combo_box->priv->model)
|
|
2597 {
|
|
2598 GtkTreeSelection *sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (combo_box->priv->tree_view));
|
|
2599
|
|
2600 ret = gtk_tree_selection_get_selected (sel, &model, &iter);
|
|
2601 }
|
|
2602 if (ret)
|
|
2603 {
|
|
2604 GtkTreePath *path;
|
|
2605
|
|
2606 path = gtk_tree_model_get_path (model, &iter);
|
|
2607 if (path)
|
|
2608 {
|
|
2609 gtk_combo_box_set_active (combo_box, gtk_tree_path_get_indices (path)[0]);
|
|
2610 gtk_tree_path_free (path);
|
|
2611 }
|
|
2612 }
|
|
2613
|
|
2614 gtk_combo_box_popdown (combo_box);
|
|
2615
|
|
2616 return TRUE;
|
|
2617 }
|
|
2618
|
|
2619 return FALSE;
|
|
2620 }
|
|
2621
|
|
2622 static void
|
|
2623 gtk_combo_box_list_row_changed (GtkTreeModel *model,
|
|
2624 GtkTreePath *path,
|
|
2625 GtkTreeIter *iter,
|
|
2626 gpointer data)
|
|
2627 {
|
|
2628 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
|
|
2629 gint width;
|
|
2630
|
|
2631 width = gtk_combo_box_calc_requested_width (combo_box, path);
|
|
2632
|
|
2633 if (width > combo_box->priv->width)
|
|
2634 {
|
|
2635 if (combo_box->priv->cell_view)
|
|
2636 {
|
|
2637 gtk_widget_set_size_request (combo_box->priv->cell_view, width, -1);
|
|
2638 gtk_widget_queue_resize (combo_box->priv->cell_view);
|
|
2639 }
|
|
2640 combo_box->priv->width = width;
|
|
2641 }
|
|
2642 }
|
|
2643
|
|
2644 /*
|
|
2645 * GtkCellLayout implementation
|
|
2646 */
|
|
2647 static void
|
|
2648 gtk_combo_box_cell_layout_pack_start (GtkCellLayout *layout,
|
|
2649 GtkCellRenderer *cell,
|
|
2650 gboolean expand)
|
|
2651 {
|
|
2652 ComboCellInfo *info;
|
|
2653 GtkComboBox *combo_box;
|
|
2654 GtkWidget *menu;
|
|
2655
|
|
2656 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
|
|
2657 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
|
|
2658
|
|
2659 combo_box = GTK_COMBO_BOX (layout);
|
|
2660
|
|
2661 g_object_ref (G_OBJECT (cell));
|
|
2662 gtk_object_sink (GTK_OBJECT (cell));
|
|
2663
|
|
2664 info = g_new0 (ComboCellInfo, 1);
|
|
2665 info->cell = cell;
|
|
2666 info->expand = expand;
|
|
2667 info->pack = GTK_PACK_START;
|
|
2668
|
|
2669 combo_box->priv->cells = g_slist_append (combo_box->priv->cells, info);
|
|
2670
|
|
2671 if (combo_box->priv->cell_view)
|
|
2672 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box->priv->cell_view),
|
|
2673 cell, expand);
|
|
2674
|
|
2675 if (combo_box->priv->column)
|
|
2676 gtk_tree_view_column_pack_start (combo_box->priv->column, cell, expand);
|
|
2677
|
|
2678 menu = combo_box->priv->popup_widget;
|
|
2679 if (GTK_IS_MENU (menu))
|
|
2680 {
|
|
2681 GList *i, *list;
|
|
2682
|
|
2683 list = gtk_container_get_children (GTK_CONTAINER (menu));
|
|
2684 for (i = list; i; i = i->next)
|
|
2685 {
|
|
2686 GtkCellView *view;
|
|
2687
|
|
2688 if (GTK_IS_CELL_VIEW_MENU_ITEM (i->data))
|
|
2689 view = GTK_CELL_VIEW (GTK_BIN (i->data)->child);
|
|
2690 else
|
|
2691 view = GTK_CELL_VIEW (i->data);
|
|
2692
|
|
2693 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (view), cell, expand);
|
|
2694 }
|
|
2695 g_list_free (list);
|
|
2696 }
|
|
2697 }
|
|
2698
|
|
2699 static void
|
|
2700 gtk_combo_box_cell_layout_pack_end (GtkCellLayout *layout,
|
|
2701 GtkCellRenderer *cell,
|
|
2702 gboolean expand)
|
|
2703 {
|
|
2704 ComboCellInfo *info;
|
|
2705 GtkComboBox *combo_box;
|
|
2706 GtkWidget *menu;
|
|
2707
|
|
2708 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
|
|
2709 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
|
|
2710
|
|
2711 combo_box = GTK_COMBO_BOX (layout);
|
|
2712
|
|
2713 g_object_ref (G_OBJECT (cell));
|
|
2714 gtk_object_sink (GTK_OBJECT (cell));
|
|
2715
|
|
2716 info = g_new0 (ComboCellInfo, 1);
|
|
2717 info->cell = cell;
|
|
2718 info->expand = expand;
|
|
2719 info->pack = GTK_PACK_END;
|
|
2720
|
|
2721 combo_box->priv->cells = g_slist_append (combo_box->priv->cells, info);
|
|
2722
|
|
2723 if (combo_box->priv->cell_view)
|
|
2724 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (combo_box->priv->cell_view),
|
|
2725 cell, expand);
|
|
2726
|
|
2727 if (combo_box->priv->column)
|
|
2728 gtk_tree_view_column_pack_end (combo_box->priv->column, cell, expand);
|
|
2729
|
|
2730 menu = combo_box->priv->popup_widget;
|
|
2731 if (GTK_IS_MENU (menu))
|
|
2732 {
|
|
2733 GList *i, *list;
|
|
2734
|
|
2735 list = gtk_container_get_children (GTK_CONTAINER (menu));
|
|
2736 for (i = list; i; i = i->next)
|
|
2737 {
|
|
2738 GtkCellView *view;
|
|
2739
|
|
2740 if (GTK_IS_CELL_VIEW_MENU_ITEM (i->data))
|
|
2741 view = GTK_CELL_VIEW (GTK_BIN (i->data)->child);
|
|
2742 else
|
|
2743 view = GTK_CELL_VIEW (i->data);
|
|
2744
|
|
2745 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (view), cell, expand);
|
|
2746 }
|
|
2747 g_list_free (list);
|
|
2748 }
|
|
2749 }
|
|
2750
|
|
2751 static void
|
|
2752 gtk_combo_box_cell_layout_clear (GtkCellLayout *layout)
|
|
2753 {
|
|
2754 GtkWidget *menu;
|
|
2755 GtkComboBox *combo_box;
|
|
2756 GSList *i;
|
|
2757
|
|
2758 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
|
|
2759
|
|
2760 combo_box = GTK_COMBO_BOX (layout);
|
|
2761
|
|
2762 if (combo_box->priv->cell_view)
|
|
2763 gtk_cell_layout_clear (GTK_CELL_LAYOUT (combo_box->priv->cell_view));
|
|
2764
|
|
2765 if (combo_box->priv->column)
|
|
2766 gtk_tree_view_column_clear (combo_box->priv->column);
|
|
2767
|
|
2768 for (i = combo_box->priv->cells; i; i = i->next)
|
|
2769 {
|
|
2770 ComboCellInfo *info = (ComboCellInfo *)i->data;
|
|
2771
|
|
2772 gtk_combo_box_cell_layout_clear_attributes (layout, info->cell);
|
|
2773 g_object_unref (G_OBJECT (info->cell));
|
|
2774 g_free (info);
|
|
2775 i->data = NULL;
|
|
2776 }
|
|
2777 g_slist_free (combo_box->priv->cells);
|
|
2778 combo_box->priv->cells = NULL;
|
|
2779
|
|
2780 menu = combo_box->priv->popup_widget;
|
|
2781 if (GTK_IS_MENU (menu))
|
|
2782 {
|
|
2783 GList *i, *list;
|
|
2784
|
|
2785 list = gtk_container_get_children (GTK_CONTAINER (menu));
|
|
2786 for (i = list; i; i = i->next)
|
|
2787 {
|
|
2788 GtkCellView *view;
|
|
2789
|
|
2790 if (GTK_IS_CELL_VIEW_MENU_ITEM (i->data))
|
|
2791 view = GTK_CELL_VIEW (GTK_BIN (i->data)->child);
|
|
2792 else
|
|
2793 view = GTK_CELL_VIEW (i->data);
|
|
2794
|
|
2795 gtk_cell_layout_clear (GTK_CELL_LAYOUT (view));
|
|
2796 }
|
|
2797 g_list_free (list);
|
|
2798 }
|
|
2799 }
|
|
2800
|
|
2801 static void
|
|
2802 gtk_combo_box_cell_layout_add_attribute (GtkCellLayout *layout,
|
|
2803 GtkCellRenderer *cell,
|
|
2804 const gchar *attribute,
|
|
2805 gint column)
|
|
2806 {
|
|
2807 ComboCellInfo *info;
|
|
2808 GtkComboBox *combo_box;
|
|
2809 GtkWidget *menu;
|
|
2810
|
|
2811 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
|
|
2812 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
|
|
2813
|
|
2814 combo_box = GTK_COMBO_BOX (layout);
|
|
2815
|
|
2816 info = gtk_combo_box_get_cell_info (combo_box, cell);
|
|
2817
|
|
2818 info->attributes = g_slist_prepend (info->attributes,
|
|
2819 GINT_TO_POINTER (column));
|
|
2820 info->attributes = g_slist_prepend (info->attributes,
|
|
2821 g_strdup (attribute));
|
|
2822
|
|
2823 if (combo_box->priv->cell_view)
|
|
2824 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo_box->priv->cell_view),
|
|
2825 cell, attribute, column);
|
|
2826
|
|
2827 if (combo_box->priv->column)
|
|
2828 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo_box->priv->column),
|
|
2829 cell, attribute, column);
|
|
2830
|
|
2831 menu = combo_box->priv->popup_widget;
|
|
2832 if (GTK_IS_MENU (menu))
|
|
2833 {
|
|
2834 GList *i, *list;
|
|
2835
|
|
2836 list = gtk_container_get_children (GTK_CONTAINER (menu));
|
|
2837 for (i = list; i; i = i->next)
|
|
2838 {
|
|
2839 GtkCellView *view;
|
|
2840
|
|
2841 if (GTK_IS_CELL_VIEW_MENU_ITEM (i->data))
|
|
2842 view = GTK_CELL_VIEW (GTK_BIN (i->data)->child);
|
|
2843 else
|
|
2844 view = GTK_CELL_VIEW (i->data);
|
|
2845
|
|
2846 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (view), cell,
|
|
2847 attribute, column);
|
|
2848 }
|
|
2849 g_list_free (list);
|
|
2850 }
|
|
2851
|
|
2852 gtk_widget_queue_resize (GTK_WIDGET (combo_box));
|
|
2853 }
|
|
2854
|
|
2855 static void
|
|
2856 gtk_combo_box_cell_layout_set_cell_data_func (GtkCellLayout *layout,
|
|
2857 GtkCellRenderer *cell,
|
|
2858 GtkCellLayoutDataFunc func,
|
|
2859 gpointer func_data,
|
|
2860 GDestroyNotify destroy)
|
|
2861 {
|
|
2862 ComboCellInfo *info;
|
|
2863 GtkComboBox *combo_box;
|
|
2864 GtkWidget *menu;
|
|
2865
|
|
2866 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
|
|
2867
|
|
2868 combo_box = GTK_COMBO_BOX (layout);
|
|
2869
|
|
2870 info = gtk_combo_box_get_cell_info (combo_box, cell);
|
|
2871 g_return_if_fail (info != NULL);
|
|
2872
|
|
2873 if (info->destroy)
|
|
2874 {
|
|
2875 GDestroyNotify d = info->destroy;
|
|
2876
|
|
2877 info->destroy = NULL;
|
|
2878 d (info->func_data);
|
|
2879 }
|
|
2880
|
|
2881 info->func = func;
|
|
2882 info->func_data = func_data;
|
|
2883 info->destroy = destroy;
|
|
2884
|
|
2885 if (combo_box->priv->cell_view)
|
|
2886 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo_box->priv->cell_view), cell, func, func_data, NULL);
|
|
2887
|
|
2888 if (combo_box->priv->column)
|
|
2889 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo_box->priv->column), cell, func, func_data, NULL);
|
|
2890
|
|
2891 menu = combo_box->priv->popup_widget;
|
|
2892 if (GTK_IS_MENU (menu))
|
|
2893 {
|
|
2894 GList *i, *list;
|
|
2895
|
|
2896 list = gtk_container_get_children (GTK_CONTAINER (menu));
|
|
2897 for (i = list; i; i = i->next)
|
|
2898 {
|
|
2899 GtkCellView *view;
|
|
2900
|
|
2901 if (GTK_IS_CELL_VIEW_MENU_ITEM (i->data))
|
|
2902 view = GTK_CELL_VIEW (GTK_BIN (i->data)->child);
|
|
2903 else
|
|
2904 view = GTK_CELL_VIEW (i->data);
|
|
2905
|
|
2906 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (view), cell,
|
|
2907 func, func_data, NULL);
|
|
2908 }
|
|
2909 g_list_free (list);
|
|
2910 }
|
|
2911
|
|
2912 gtk_widget_queue_resize (GTK_WIDGET (combo_box));
|
|
2913 }
|
|
2914
|
|
2915 static void
|
|
2916 gtk_combo_box_cell_layout_clear_attributes (GtkCellLayout *layout,
|
|
2917 GtkCellRenderer *cell)
|
|
2918 {
|
|
2919 ComboCellInfo *info;
|
|
2920 GtkComboBox *combo_box;
|
|
2921 GtkWidget *menu;
|
|
2922 GSList *list;
|
|
2923
|
|
2924 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
|
|
2925 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
|
|
2926
|
|
2927 combo_box = GTK_COMBO_BOX (layout);
|
|
2928
|
|
2929 info = gtk_combo_box_get_cell_info (combo_box, cell);
|
|
2930 if (info)
|
|
2931 {
|
|
2932 list = info->attributes;
|
|
2933 while (list && list->next)
|
|
2934 {
|
|
2935 g_free (list->data);
|
|
2936 list = list->next->next;
|
|
2937 }
|
|
2938 g_slist_free (info->attributes);
|
|
2939 info->attributes = NULL;
|
|
2940 }
|
|
2941
|
|
2942 if (combo_box->priv->cell_view)
|
|
2943 gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (combo_box->priv->cell_view), cell);
|
|
2944
|
|
2945 if (combo_box->priv->column)
|
|
2946 gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (combo_box->priv->column), cell);
|
|
2947
|
|
2948 menu = combo_box->priv->popup_widget;
|
|
2949 if (GTK_IS_MENU (menu))
|
|
2950 {
|
|
2951 GList *i, *list;
|
|
2952
|
|
2953 list = gtk_container_get_children (GTK_CONTAINER (menu));
|
|
2954 for (i = list; i; i = i->next)
|
|
2955 {
|
|
2956 GtkCellView *view;
|
|
2957
|
|
2958 if (GTK_IS_CELL_VIEW_MENU_ITEM (i->data))
|
|
2959 view = GTK_CELL_VIEW (GTK_BIN (i->data)->child);
|
|
2960 else
|
|
2961 view = GTK_CELL_VIEW (i->data);
|
|
2962
|
|
2963 gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (view), cell);
|
|
2964 }
|
|
2965 g_list_free (list);
|
|
2966 }
|
|
2967
|
|
2968 gtk_widget_queue_resize (GTK_WIDGET (combo_box));
|
|
2969 }
|
|
2970
|
|
2971 static void
|
|
2972 gtk_combo_box_cell_layout_reorder (GtkCellLayout *layout,
|
|
2973 GtkCellRenderer *cell,
|
|
2974 gint position)
|
|
2975 {
|
|
2976 ComboCellInfo *info;
|
|
2977 GtkComboBox *combo_box;
|
|
2978 GtkWidget *menu;
|
|
2979 GSList *link;
|
|
2980
|
|
2981 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
|
|
2982 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
|
|
2983
|
|
2984 combo_box = GTK_COMBO_BOX (layout);
|
|
2985
|
|
2986 info = gtk_combo_box_get_cell_info (combo_box, cell);
|
|
2987
|
|
2988 g_return_if_fail (info != NULL);
|
|
2989 g_return_if_fail (position >= 0);
|
|
2990
|
|
2991 link = g_slist_find (combo_box->priv->cells, info);
|
|
2992
|
|
2993 g_return_if_fail (link != NULL);
|
|
2994
|
|
2995 combo_box->priv->cells = g_slist_remove_link (combo_box->priv->cells, link);
|
|
2996 combo_box->priv->cells = g_slist_insert (combo_box->priv->cells, info,
|
|
2997 position);
|
|
2998
|
|
2999 if (combo_box->priv->cell_view)
|
|
3000 gtk_cell_layout_reorder (GTK_CELL_LAYOUT (combo_box->priv->cell_view),
|
|
3001 cell, position);
|
|
3002
|
|
3003 if (combo_box->priv->column)
|
|
3004 gtk_cell_layout_reorder (GTK_CELL_LAYOUT (combo_box->priv->column),
|
|
3005 cell, position);
|
|
3006
|
|
3007 menu = combo_box->priv->popup_widget;
|
|
3008 if (GTK_IS_MENU (menu))
|
|
3009 {
|
|
3010 GList *i, *list;
|
|
3011
|
|
3012 list = gtk_container_get_children (GTK_CONTAINER (menu));
|
|
3013 for (i = list; i; i = i->next)
|
|
3014 {
|
|
3015 GtkCellView *view;
|
|
3016
|
|
3017 if (GTK_IS_CELL_VIEW_MENU_ITEM (i->data))
|
|
3018 view = GTK_CELL_VIEW (GTK_BIN (i->data)->child);
|
|
3019 else
|
|
3020 view = GTK_CELL_VIEW (i->data);
|
|
3021
|
|
3022 gtk_cell_layout_reorder (GTK_CELL_LAYOUT (view), cell, position);
|
|
3023 }
|
|
3024 g_list_free (list);
|
|
3025 }
|
|
3026
|
|
3027 gtk_widget_queue_draw (GTK_WIDGET (combo_box));
|
|
3028 }
|
|
3029
|
|
3030 /*
|
|
3031 * public API
|
|
3032 */
|
|
3033
|
|
3034 /**
|
|
3035 * gtk_combo_box_new:
|
|
3036 *
|
|
3037 * Creates a new empty #GtkComboBox.
|
|
3038 *
|
|
3039 * Return value: A new #GtkComboBox.
|
|
3040 *
|
|
3041 * Since: 2.4
|
|
3042 */
|
|
3043 GtkWidget *
|
|
3044 gtk_combo_box_new (void)
|
|
3045 {
|
|
3046 return GTK_WIDGET (g_object_new (GTK_TYPE_COMBO_BOX, NULL));
|
|
3047 }
|
|
3048
|
|
3049 /**
|
|
3050 * gtk_combo_box_new_with_model:
|
|
3051 * @model: A #GtkTreeModel.
|
|
3052 *
|
|
3053 * Creates a new #GtkComboBox with the model initialized to @model.
|
|
3054 *
|
|
3055 * Return value: A new #GtkComboBox.
|
|
3056 *
|
|
3057 * Since: 2.4
|
|
3058 */
|
|
3059 GtkWidget *
|
|
3060 gtk_combo_box_new_with_model (GtkTreeModel *model)
|
|
3061 {
|
|
3062 GtkComboBox *combo_box;
|
|
3063
|
|
3064 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
|
|
3065
|
|
3066 combo_box = GTK_COMBO_BOX (g_object_new (GTK_TYPE_COMBO_BOX,
|
|
3067 "model", model,
|
|
3068 NULL));
|
|
3069
|
|
3070 return GTK_WIDGET (combo_box);
|
|
3071 }
|
|
3072
|
|
3073 /**
|
|
3074 * gtk_combo_box_set_wrap_width:
|
|
3075 * @combo_box: A #GtkComboBox.
|
|
3076 * @width: Preferred number of columns.
|
|
3077 *
|
|
3078 * Sets the wrap width of @combo_box to be @width. The wrap width is basically
|
|
3079 * the preferred number of columns when you want to the popup to be layed out
|
|
3080 * in a table.
|
|
3081 *
|
|
3082 * Since: 2.4
|
|
3083 */
|
|
3084 void
|
|
3085 gtk_combo_box_set_wrap_width (GtkComboBox *combo_box,
|
|
3086 gint width)
|
|
3087 {
|
|
3088 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
|
|
3089 g_return_if_fail (width >= 0);
|
|
3090
|
|
3091 if (width != combo_box->priv->wrap_width)
|
|
3092 {
|
|
3093 combo_box->priv->wrap_width = width;
|
|
3094
|
|
3095 gtk_combo_box_check_appearance (combo_box);
|
|
3096 gtk_combo_box_relayout (combo_box);
|
|
3097
|
|
3098 g_object_notify (G_OBJECT (combo_box), "wrap_width");
|
|
3099 }
|
|
3100 }
|
|
3101
|
|
3102 /**
|
|
3103 * gtk_combo_box_set_row_span_column:
|
|
3104 * @combo_box: A #GtkComboBox.
|
|
3105 * @row_span: A column in the model passed during construction.
|
|
3106 *
|
|
3107 * Sets the column with row span information for @combo_box to be @row_span.
|
|
3108 * The row span column contains integers which indicate how many rows
|
|
3109 * an item should span.
|
|
3110 *
|
|
3111 * Since: 2.4
|
|
3112 */
|
|
3113 void
|
|
3114 gtk_combo_box_set_row_span_column (GtkComboBox *combo_box,
|
|
3115 gint row_span)
|
|
3116 {
|
|
3117 gint col;
|
|
3118
|
|
3119 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
|
|
3120
|
|
3121 col = gtk_tree_model_get_n_columns (combo_box->priv->model);
|
|
3122 g_return_if_fail (row_span >= 0 && row_span < col);
|
|
3123
|
|
3124 if (row_span != combo_box->priv->row_column)
|
|
3125 {
|
|
3126 combo_box->priv->row_column = row_span;
|
|
3127
|
|
3128 gtk_combo_box_relayout (combo_box);
|
|
3129
|
|
3130 g_object_notify (G_OBJECT (combo_box), "row_span_column");
|
|
3131 }
|
|
3132 }
|
|
3133
|
|
3134 /**
|
|
3135 * gtk_combo_box_set_column_span_column:
|
|
3136 * @combo_box: A #GtkComboBox.
|
|
3137 * @column_span: A column in the model passed during construction.
|
|
3138 *
|
|
3139 * Sets the column with column span information for @combo_box to be
|
|
3140 * @column_span. The column span column contains integers which indicate
|
|
3141 * how many columns an item should span.
|
|
3142 *
|
|
3143 * Since: 2.4
|
|
3144 */
|
|
3145 void
|
|
3146 gtk_combo_box_set_column_span_column (GtkComboBox *combo_box,
|
|
3147 gint column_span)
|
|
3148 {
|
|
3149 gint col;
|
|
3150
|
|
3151 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
|
|
3152
|
|
3153 col = gtk_tree_model_get_n_columns (combo_box->priv->model);
|
|
3154 g_return_if_fail (column_span >= 0 && column_span < col);
|
|
3155
|
|
3156 if (column_span != combo_box->priv->col_column)
|
|
3157 {
|
|
3158 combo_box->priv->col_column = column_span;
|
|
3159
|
|
3160 gtk_combo_box_relayout (combo_box);
|
|
3161
|
|
3162 g_object_notify (G_OBJECT (combo_box), "column_span_column");
|
|
3163 }
|
|
3164 }
|
|
3165
|
|
3166 /**
|
|
3167 * gtk_combo_box_get_active:
|
|
3168 * @combo_box: A #GtkComboBox.
|
|
3169 *
|
|
3170 * Returns the index of the currently active item, or -1 if there's no
|
|
3171 * active item.
|
|
3172 *
|
|
3173 * Return value: An integer which is the index of the currently active item, or
|
|
3174 * -1 if there's no active item.
|
|
3175 *
|
|
3176 * Since: 2.4
|
|
3177 */
|
|
3178 gint
|
|
3179 gtk_combo_box_get_active (GtkComboBox *combo_box)
|
|
3180 {
|
|
3181 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), 0);
|
|
3182
|
|
3183 return combo_box->priv->active_item;
|
|
3184 }
|
|
3185
|
|
3186 /**
|
|
3187 * gtk_combo_box_set_active:
|
|
3188 * @combo_box: A #GtkComboBox.
|
|
3189 * @index_: An index in the model passed during construction, or -1 to have
|
|
3190 * no active item.
|
|
3191 *
|
|
3192 * Sets the active item of @combo_box to be the item at @index.
|
|
3193 *
|
|
3194 * Since: 2.4
|
|
3195 */
|
|
3196 void
|
|
3197 gtk_combo_box_set_active (GtkComboBox *combo_box,
|
|
3198 gint index_)
|
|
3199 {
|
|
3200 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
|
|
3201 /* -1 means "no item selected" */
|
|
3202 g_return_if_fail (index_ >= -1);
|
|
3203
|
|
3204 if (combo_box->priv->active_item == index_)
|
|
3205 return;
|
|
3206
|
|
3207 gtk_combo_box_set_active_internal (combo_box, index_);
|
|
3208 }
|
|
3209
|
|
3210 static void
|
|
3211 gtk_combo_box_set_active_internal (GtkComboBox *combo_box,
|
|
3212 gint index)
|
|
3213 {
|
|
3214 GtkTreePath *path;
|
|
3215
|
|
3216 combo_box->priv->active_item = index;
|
|
3217
|
|
3218 if (index == -1)
|
|
3219 {
|
|
3220 if (combo_box->priv->tree_view)
|
|
3221 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (combo_box->priv->tree_view)));
|
|
3222 else
|
|
3223 {
|
|
3224 GtkMenu *menu = GTK_MENU (combo_box->priv->popup_widget);
|
|
3225
|
|
3226 if (GTK_IS_MENU (menu))
|
|
3227 gtk_menu_set_active (menu, -1);
|
|
3228 }
|
|
3229
|
|
3230 if (combo_box->priv->cell_view)
|
|
3231 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (combo_box->priv->cell_view), NULL);
|
|
3232 }
|
|
3233 else
|
|
3234 {
|
11780
|
3235 #if GTK_CHECK_VERSION(2,2,0)
|
10708
|
3236 path = gtk_tree_path_new_from_indices (index, -1);
|
11780
|
3237 #else
|
|
3238 char buf[32];
|
|
3239 g_snprintf(buf, sizeof(buf), "%d", index);
|
|
3240 path = gtk_tree_path_new_from_string(buf);
|
|
3241 #endif
|
10708
|
3242
|
|
3243 if (combo_box->priv->tree_view)
|
|
3244 gtk_tree_view_set_cursor (GTK_TREE_VIEW (combo_box->priv->tree_view), path, NULL, FALSE);
|
|
3245 else
|
|
3246 {
|
|
3247 GtkMenu *menu = GTK_MENU (combo_box->priv->popup_widget);
|
|
3248
|
|
3249 if (GTK_IS_MENU (menu))
|
|
3250 gtk_menu_set_active (GTK_MENU (menu), index);
|
|
3251 }
|
|
3252
|
|
3253 if (combo_box->priv->cell_view)
|
|
3254 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (combo_box->priv->cell_view), path);
|
|
3255
|
|
3256 gtk_tree_path_free (path);
|
|
3257 }
|
|
3258
|
|
3259 g_signal_emit_by_name (combo_box, "changed", NULL, NULL);
|
|
3260 }
|
|
3261
|
|
3262
|
|
3263 /**
|
|
3264 * gtk_combo_box_get_active_iter:
|
|
3265 * @combo_box: A #GtkComboBox
|
|
3266 * @iter: The uninitialized #GtkTreeIter.
|
|
3267 *
|
|
3268 * Sets @iter to point to the current active item, if it exists.
|
|
3269 *
|
|
3270 * Return value: %TRUE, if @iter was set
|
|
3271 *
|
|
3272 * Since: 2.4
|
|
3273 **/
|
|
3274 gboolean
|
|
3275 gtk_combo_box_get_active_iter (GtkComboBox *combo_box,
|
|
3276 GtkTreeIter *iter)
|
|
3277 {
|
|
3278 GtkTreePath *path;
|
|
3279 gint active;
|
|
3280 gboolean retval;
|
11780
|
3281 #if !GTK_CHECK_VERSION(2,2,0)
|
|
3282 char buf[32];
|
|
3283 #endif
|
10708
|
3284
|
|
3285 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE);
|
|
3286
|
|
3287 active = gtk_combo_box_get_active (combo_box);
|
|
3288 if (active < 0)
|
|
3289 return FALSE;
|
|
3290
|
11780
|
3291 #if GTK_CHECK_VERSION(2,2,0)
|
10708
|
3292 path = gtk_tree_path_new_from_indices (active, -1);
|
11780
|
3293 #else
|
|
3294 g_snprintf(buf, sizeof(buf), "%d", active);
|
|
3295 path = gtk_tree_path_new_from_string(buf);
|
|
3296 #endif
|
10708
|
3297 retval = gtk_tree_model_get_iter (gtk_combo_box_get_model (combo_box),
|
|
3298 iter, path);
|
|
3299 gtk_tree_path_free (path);
|
|
3300
|
|
3301 return retval;
|
|
3302 }
|
|
3303
|
|
3304 /**
|
|
3305 * gtk_combo_box_set_active_iter:
|
|
3306 * @combo_box: A #GtkComboBox
|
|
3307 * @iter: The #GtkTreeIter.
|
|
3308 *
|
|
3309 * Sets the current active item to be the one referenced by @iter.
|
|
3310 * @iter must correspond to a path of depth one.
|
|
3311 *
|
|
3312 * Since: 2.4
|
|
3313 **/
|
|
3314 void
|
|
3315 gtk_combo_box_set_active_iter (GtkComboBox *combo_box,
|
|
3316 GtkTreeIter *iter)
|
|
3317 {
|
|
3318 GtkTreePath *path;
|
|
3319
|
|
3320 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
|
|
3321
|
|
3322 path = gtk_tree_model_get_path (gtk_combo_box_get_model (combo_box), iter);
|
|
3323 g_return_if_fail (path != NULL);
|
|
3324 g_return_if_fail (gtk_tree_path_get_depth (path) == 1);
|
|
3325
|
|
3326 gtk_combo_box_set_active (combo_box, gtk_tree_path_get_indices (path)[0]);
|
|
3327 gtk_tree_path_free (path);
|
|
3328 }
|
|
3329
|
|
3330 /**
|
|
3331 * gtk_combo_box_set_model:
|
|
3332 * @combo_box: A #GtkComboBox.
|
|
3333 * @model: A #GtkTreeModel.
|
|
3334 *
|
|
3335 * Sets the model used by @combo_box to be @model. Will unset a previously set
|
|
3336 * model (if applicable). If @model is %NULL, then it will unset the model.
|
|
3337 *
|
|
3338 * Note that this function does not clear the cell renderers, you have to
|
|
3339 * call gtk_combo_box_cell_layout_clear() yourself if you need to set up
|
|
3340 * different cell renderers for the new model.
|
|
3341 *
|
|
3342 * Since: 2.4
|
|
3343 */
|
|
3344 void
|
|
3345 gtk_combo_box_set_model (GtkComboBox *combo_box,
|
|
3346 GtkTreeModel *model)
|
|
3347 {
|
|
3348 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
|
|
3349
|
|
3350 if (!model)
|
|
3351 {
|
|
3352 gtk_combo_box_unset_model (combo_box);
|
|
3353 return;
|
|
3354 }
|
|
3355
|
|
3356 g_return_if_fail (GTK_IS_TREE_MODEL (model));
|
|
3357
|
|
3358 if (model == combo_box->priv->model)
|
|
3359 return;
|
|
3360
|
|
3361 if (combo_box->priv->model)
|
|
3362 gtk_combo_box_unset_model (combo_box);
|
|
3363
|
|
3364 combo_box->priv->model = model;
|
|
3365 g_object_ref (G_OBJECT (combo_box->priv->model));
|
|
3366
|
|
3367 combo_box->priv->inserted_id =
|
|
3368 g_signal_connect (combo_box->priv->model, "row_inserted",
|
|
3369 G_CALLBACK (gtk_combo_box_model_row_inserted),
|
|
3370 combo_box);
|
|
3371 combo_box->priv->deleted_id =
|
|
3372 g_signal_connect (combo_box->priv->model, "row_deleted",
|
|
3373 G_CALLBACK (gtk_combo_box_model_row_deleted),
|
|
3374 combo_box);
|
|
3375 combo_box->priv->reordered_id =
|
|
3376 g_signal_connect (combo_box->priv->model, "rows_reordered",
|
|
3377 G_CALLBACK (gtk_combo_box_model_rows_reordered),
|
|
3378 combo_box);
|
|
3379 combo_box->priv->changed_id =
|
|
3380 g_signal_connect (combo_box->priv->model, "row_changed",
|
|
3381 G_CALLBACK (gtk_combo_box_model_row_changed),
|
|
3382 combo_box);
|
|
3383
|
|
3384 if (combo_box->priv->tree_view)
|
|
3385 {
|
|
3386 /* list mode */
|
|
3387 gtk_tree_view_set_model (GTK_TREE_VIEW (combo_box->priv->tree_view),
|
|
3388 combo_box->priv->model);
|
|
3389 }
|
|
3390 else
|
|
3391 {
|
|
3392 /* menu mode */
|
|
3393 if (combo_box->priv->popup_widget)
|
|
3394 gtk_combo_box_menu_fill (combo_box);
|
|
3395
|
|
3396 }
|
|
3397
|
|
3398 if (combo_box->priv->cell_view)
|
|
3399 gtk_cell_view_set_model (GTK_CELL_VIEW (combo_box->priv->cell_view),
|
|
3400 combo_box->priv->model);
|
|
3401 }
|
|
3402
|
|
3403 /**
|
|
3404 * gtk_combo_box_get_model
|
|
3405 * @combo_box: A #GtkComboBox.
|
|
3406 *
|
|
3407 * Returns the #GtkTreeModel which is acting as data source for @combo_box.
|
|
3408 *
|
|
3409 * Return value: A #GtkTreeModel which was passed during construction.
|
|
3410 *
|
|
3411 * Since: 2.4
|
|
3412 */
|
|
3413 GtkTreeModel *
|
|
3414 gtk_combo_box_get_model (GtkComboBox *combo_box)
|
|
3415 {
|
|
3416 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
|
|
3417
|
|
3418 return combo_box->priv->model;
|
|
3419 }
|
|
3420
|
|
3421
|
|
3422 /* convenience API for simple text combos */
|
|
3423
|
|
3424 /**
|
|
3425 * gtk_combo_box_new_text:
|
|
3426 *
|
|
3427 * Convenience function which constructs a new text combo box, which is a
|
|
3428 * #GtkComboBox just displaying strings. If you use this function to create
|
|
3429 * a text combo box, you should only manipulate its data source with the
|
|
3430 * following convenience functions: gtk_combo_box_append_text(),
|
|
3431 * gtk_combo_box_insert_text(), gtk_combo_box_prepend_text() and
|
|
3432 * gtk_combo_box_remove_text().
|
|
3433 *
|
|
3434 * Return value: A new text combo box.
|
|
3435 *
|
|
3436 * Since: 2.4
|
|
3437 */
|
|
3438 GtkWidget *
|
|
3439 gtk_combo_box_new_text (void)
|
|
3440 {
|
|
3441 GtkWidget *combo_box;
|
|
3442 GtkCellRenderer *cell;
|
|
3443 GtkListStore *store;
|
|
3444
|
|
3445 store = gtk_list_store_new (1, G_TYPE_STRING);
|
|
3446 combo_box = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));
|
|
3447 g_object_unref (store);
|
|
3448
|
|
3449 cell = gtk_cell_renderer_text_new ();
|
|
3450 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), cell, TRUE);
|
|
3451 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), cell,
|
|
3452 "text", 0,
|
|
3453 NULL);
|
|
3454
|
|
3455 return combo_box;
|
|
3456 }
|
|
3457
|
|
3458 /**
|
|
3459 * gtk_combo_box_append_text:
|
|
3460 * @combo_box: A #GtkComboBox constructed using gtk_combo_box_new_text().
|
|
3461 * @text: A string.
|
|
3462 *
|
|
3463 * Appends @string to the list of strings stored in @combo_box. Note that
|
|
3464 * you can only use this function with combo boxes constructed with
|
|
3465 * gtk_combo_box_new_text().
|
|
3466 *
|
|
3467 * Since: 2.4
|
|
3468 */
|
|
3469 void
|
|
3470 gtk_combo_box_append_text (GtkComboBox *combo_box,
|
|
3471 const gchar *text)
|
|
3472 {
|
|
3473 GtkTreeIter iter;
|
|
3474 GtkListStore *store;
|
|
3475
|
|
3476 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
|
|
3477 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
|
|
3478 g_return_if_fail (text != NULL);
|
|
3479
|
|
3480 store = GTK_LIST_STORE (combo_box->priv->model);
|
|
3481
|
|
3482 gtk_list_store_append (store, &iter);
|
|
3483 gtk_list_store_set (store, &iter, 0, text, -1);
|
|
3484 }
|
|
3485
|
|
3486 /**
|
|
3487 * gtk_combo_box_insert_text:
|
|
3488 * @combo_box: A #GtkComboBox constructed using gtk_combo_box_new_text().
|
|
3489 * @position: An index to insert @text.
|
|
3490 * @text: A string.
|
|
3491 *
|
|
3492 * Inserts @string at @position in the list of strings stored in @combo_box.
|
|
3493 * Note that you can only use this function with combo boxes constructed
|
|
3494 * with gtk_combo_box_new_text().
|
|
3495 *
|
|
3496 * Since: 2.4
|
|
3497 */
|
|
3498 void
|
|
3499 gtk_combo_box_insert_text (GtkComboBox *combo_box,
|
|
3500 gint position,
|
|
3501 const gchar *text)
|
|
3502 {
|
|
3503 GtkTreeIter iter;
|
|
3504 GtkListStore *store;
|
|
3505
|
|
3506 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
|
|
3507 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
|
|
3508 g_return_if_fail (position >= 0);
|
|
3509 g_return_if_fail (text != NULL);
|
|
3510
|
|
3511 store = GTK_LIST_STORE (combo_box->priv->model);
|
|
3512
|
|
3513 gtk_list_store_insert (store, &iter, position);
|
|
3514 gtk_list_store_set (store, &iter, 0, text, -1);
|
|
3515 }
|
|
3516
|
|
3517 /**
|
|
3518 * gtk_combo_box_prepend_text:
|
|
3519 * @combo_box: A #GtkComboBox constructed with gtk_combo_box_new_text().
|
|
3520 * @text: A string.
|
|
3521 *
|
|
3522 * Prepends @string to the list of strings stored in @combo_box. Note that
|
|
3523 * you can only use this function with combo boxes constructed with
|
|
3524 * gtk_combo_box_new_text().
|
|
3525 *
|
|
3526 * Since: 2.4
|
|
3527 */
|
|
3528 void
|
|
3529 gtk_combo_box_prepend_text (GtkComboBox *combo_box,
|
|
3530 const gchar *text)
|
|
3531 {
|
|
3532 GtkTreeIter iter;
|
|
3533 GtkListStore *store;
|
|
3534
|
|
3535 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
|
|
3536 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
|
|
3537 g_return_if_fail (text != NULL);
|
|
3538
|
|
3539 store = GTK_LIST_STORE (combo_box->priv->model);
|
|
3540
|
|
3541 gtk_list_store_prepend (store, &iter);
|
|
3542 gtk_list_store_set (store, &iter, 0, text, -1);
|
|
3543 }
|
|
3544
|
|
3545 /**
|
|
3546 * gtk_combo_box_remove_text:
|
|
3547 * @combo_box: A #GtkComboBox constructed with gtk_combo_box_new_text().
|
|
3548 * @position: Index of the item to remove.
|
|
3549 *
|
|
3550 * Removes the string at @position from @combo_box. Note that you can only use
|
|
3551 * this function with combo boxes constructed with gtk_combo_box_new_text().
|
|
3552 *
|
|
3553 * Since: 2.4
|
|
3554 */
|
|
3555 void
|
|
3556 gtk_combo_box_remove_text (GtkComboBox *combo_box,
|
|
3557 gint position)
|
|
3558 {
|
|
3559 GtkTreeIter iter;
|
|
3560 GtkListStore *store;
|
|
3561
|
|
3562 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
|
|
3563 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
|
|
3564 g_return_if_fail (position >= 0);
|
|
3565
|
|
3566 store = GTK_LIST_STORE (combo_box->priv->model);
|
|
3567
|
|
3568 if (gtk_tree_model_iter_nth_child (combo_box->priv->model, &iter,
|
|
3569 NULL, position))
|
|
3570 gtk_list_store_remove (store, &iter);
|
|
3571 }
|
|
3572
|
|
3573
|
|
3574 static gboolean
|
|
3575 gtk_combo_box_mnemonic_activate (GtkWidget *widget,
|
|
3576 gboolean group_cycling)
|
|
3577 {
|
|
3578 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
|
|
3579
|
|
3580 gtk_widget_grab_focus (combo_box->priv->button);
|
|
3581
|
|
3582 return TRUE;
|
|
3583 }
|
|
3584
|
|
3585 static void
|
|
3586 gtk_combo_box_destroy (GtkObject *object)
|
|
3587 {
|
|
3588 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
|
|
3589
|
|
3590 gtk_combo_box_popdown (combo_box);
|
|
3591
|
|
3592 combo_box->priv->destroying = 1;
|
|
3593
|
|
3594 GTK_OBJECT_CLASS (parent_class)->destroy (object);
|
|
3595 combo_box->priv->cell_view = NULL;
|
|
3596
|
|
3597 combo_box->priv->destroying = 0;
|
|
3598 }
|
|
3599
|
|
3600 static void
|
|
3601 gtk_combo_box_finalize (GObject *object)
|
|
3602 {
|
|
3603 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
|
|
3604 GSList *i;
|
|
3605
|
|
3606 if (GTK_IS_MENU (combo_box->priv->popup_widget))
|
|
3607 {
|
|
3608 gtk_combo_box_menu_destroy (combo_box);
|
|
3609 gtk_menu_detach (GTK_MENU (combo_box->priv->popup_widget));
|
|
3610 combo_box->priv->popup_widget = NULL;
|
|
3611 }
|
|
3612
|
|
3613 if (GTK_IS_TREE_VIEW (combo_box->priv->tree_view))
|
|
3614 gtk_combo_box_list_destroy (combo_box);
|
|
3615
|
|
3616 if (combo_box->priv->popup_window)
|
|
3617 gtk_widget_destroy (combo_box->priv->popup_window);
|
|
3618
|
|
3619 gtk_combo_box_unset_model (combo_box);
|
|
3620
|
|
3621 for (i = combo_box->priv->cells; i; i = i->next)
|
|
3622 {
|
|
3623 ComboCellInfo *info = (ComboCellInfo *)i->data;
|
|
3624 GSList *list = info->attributes;
|
|
3625
|
|
3626 if (info->destroy)
|
|
3627 info->destroy (info->func_data);
|
|
3628
|
|
3629 while (list && list->next)
|
|
3630 {
|
|
3631 g_free (list->data);
|
|
3632 list = list->next->next;
|
|
3633 }
|
|
3634 g_slist_free (info->attributes);
|
|
3635
|
|
3636 g_object_unref (G_OBJECT (info->cell));
|
|
3637 g_free (info);
|
|
3638 }
|
|
3639 g_slist_free (combo_box->priv->cells);
|
|
3640
|
|
3641 g_free (combo_box->priv);
|
|
3642
|
|
3643 G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
3644 }
|
|
3645
|
|
3646
|
|
3647 /**
|
|
3648 * Code below this point has been pulled in from gtkmenu.c in 2.4.14
|
|
3649 * and is needed to provide gtk_menu_attach()
|
|
3650 */
|
|
3651
|
|
3652 typedef struct
|
|
3653 {
|
|
3654 gint left_attach;
|
|
3655 gint right_attach;
|
|
3656 gint top_attach;
|
|
3657 gint bottom_attach;
|
|
3658 gint effective_left_attach;
|
|
3659 gint effective_right_attach;
|
|
3660 gint effective_top_attach;
|
|
3661 gint effective_bottom_attach;
|
|
3662 } AttachInfo;
|
|
3663
|
|
3664 #define ATTACH_INFO_KEY "gtk-menu-child-attach-info-key"
|
|
3665
|
|
3666 static AttachInfo *
|
|
3667 get_attach_info (GtkWidget *child)
|
|
3668 {
|
|
3669 GObject *object = G_OBJECT (child);
|
|
3670 AttachInfo *ai = g_object_get_data (object, ATTACH_INFO_KEY);
|
|
3671
|
|
3672 if (!ai)
|
|
3673 {
|
|
3674 ai = g_new0 (AttachInfo, 1);
|
|
3675 g_object_set_data_full (object, ATTACH_INFO_KEY, ai, g_free);
|
|
3676 }
|
|
3677
|
|
3678 return ai;
|
|
3679 }
|
|
3680
|
|
3681 /**
|
|
3682 * gtk_menu_attach:
|
|
3683 * @menu: a #GtkMenu.
|
|
3684 * @child: a #GtkMenuItem.
|
|
3685 * @left_attach: The column number to attach the left side of the item to.
|
|
3686 * @right_attach: The column number to attach the right side of the item to.
|
|
3687 * @top_attach: The row number to attach the top of the item to.
|
|
3688 * @bottom_attach: The row number to attach the bottom of the item to.
|
|
3689 *
|
|
3690 * Adds a new #GtkMenuItem to a (table) menu. The number of 'cells' that
|
|
3691 * an item will occupy is specified by @left_attach, @right_attach,
|
|
3692 * @top_attach and @bottom_attach. These each represent the leftmost,
|
|
3693 * rightmost, uppermost and lower column and row numbers of the table.
|
|
3694 * (Columns and rows are indexed from zero).
|
|
3695 *
|
|
3696 * Note that this function is not related to gtk_menu_detach().
|
|
3697 *
|
|
3698 * Since: 2.4
|
|
3699 **/
|
|
3700 static void
|
|
3701 gtk_menu_attach (GtkMenu *menu,
|
|
3702 GtkWidget *child,
|
|
3703 guint left_attach,
|
|
3704 guint right_attach,
|
|
3705 guint top_attach,
|
|
3706 guint bottom_attach)
|
|
3707 {
|
|
3708 GtkMenuShell *menu_shell;
|
|
3709
|
|
3710 g_return_if_fail (GTK_IS_MENU (menu));
|
|
3711 g_return_if_fail (GTK_IS_MENU_ITEM (child));
|
|
3712 g_return_if_fail (child->parent == NULL ||
|
|
3713 child->parent == GTK_WIDGET (menu));
|
|
3714 g_return_if_fail (left_attach < right_attach);
|
|
3715 g_return_if_fail (top_attach < bottom_attach);
|
|
3716
|
|
3717 menu_shell = GTK_MENU_SHELL (menu);
|
|
3718
|
|
3719 if (!child->parent)
|
|
3720 {
|
|
3721 AttachInfo *ai = get_attach_info (child);
|
|
3722
|
|
3723 ai->left_attach = left_attach;
|
|
3724 ai->right_attach = right_attach;
|
|
3725 ai->top_attach = top_attach;
|
|
3726 ai->bottom_attach = bottom_attach;
|
|
3727
|
|
3728 menu_shell->children = g_list_append (menu_shell->children, child);
|
|
3729
|
|
3730 gtk_widget_set_parent (child, GTK_WIDGET (menu));
|
|
3731
|
|
3732 /*
|
|
3733 menu_queue_resize (menu);
|
|
3734 */
|
|
3735 }
|
|
3736 else
|
|
3737 {
|
|
3738 gtk_container_child_set (GTK_CONTAINER (child->parent), child,
|
|
3739 "left_attach", left_attach,
|
|
3740 "right_attach", right_attach,
|
|
3741 "top_attach", top_attach,
|
|
3742 "bottom_attach", bottom_attach,
|
|
3743 NULL);
|
|
3744 }
|
|
3745 }
|
|
3746 #endif /* Gtk 2.4 */
|