2 * Copyright (C) 2002, 2003 Kristian Rietveld <kris@gtk.org>
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.
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.
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.
21 #include "gtkcombobox.h"
24 #include "gtkbindings.h"
25 #include "gtkcelllayout.h"
26 #include "gtkcellrenderertext.h"
27 #include "gtkcellview.h"
28 #include "gtkcellviewmenuitem.h"
29 #include "gtkeventbox.h"
32 #include "gtkliststore.h"
35 #include "gtktogglebutton.h"
36 #include "gtktreeselection.h"
37 #include "gtkvseparator.h"
38 #include "gtkwindow.h"
40 #include <gdk/gdkkeysyms.h>
42 #include <gobject/gvaluecollector.h>
47 #include "gtkmarshalers.h"
51 /* WELCOME, to THE house of evil code */
53 typedef struct _ComboCellInfo ComboCellInfo;
56 GtkCellRenderer *cell;
59 GtkCellLayoutDataFunc func;
61 GDestroyNotify destroy;
67 #define GTK_COMBO_BOX_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_COMBO_BOX, GtkComboBoxPrivate))
69 struct _GtkComboBoxPrivate
81 GtkTreeViewColumn *column;
84 GtkWidget *cell_view_frame;
91 GtkWidget *popup_widget;
92 GtkWidget *popup_window;
93 GtkWidget *popup_frame;
103 GtkComboBoxSelectionFunc selection_func;
104 gpointer selection_data;
105 GDestroyNotify selection_destroy;
107 guint popup_in_progress : 1;
108 guint destroying : 1;
111 /* While debugging this evil code, I have learned that
112 * there are actually 4 modes to this widget, which can
113 * be characterized as follows
115 * 1) menu mode, no child added
118 * cell_view -> GtkCellView, regular child
119 * cell_view_frame -> NULL
120 * button -> GtkToggleButton set_parent to combo
121 * arrow -> GtkArrow set_parent to button
122 * separator -> GtkVSepator set_parent to button
123 * popup_widget -> GtkMenu
124 * popup_window -> NULL
125 * popup_frame -> NULL
127 * 2) menu mode, child added
131 * cell_view_frame -> NULL
132 * button -> GtkToggleButton set_parent to combo
133 * arrow -> GtkArrow, child of button
135 * popup_widget -> GtkMenu
136 * popup_window -> NULL
137 * popup_frame -> NULL
139 * 3) list mode, no child added
141 * tree_view -> GtkTreeView, child of popup_frame
142 * cell_view -> GtkCellView, regular child
143 * cell_view_frame -> GtkFrame, set parent to combo
144 * button -> GtkToggleButton, set_parent to combo
145 * arrow -> GtkArrow, child of button
147 * popup_widget -> tree_view
148 * popup_window -> GtkWindow
149 * popup_frame -> GtkFrame, child of popup_window
151 * 4) list mode, child added
153 * tree_view -> GtkTreeView, child of popup_frame
155 * cell_view_frame -> NULL
156 * button -> GtkToggleButton, set_parent to combo
157 * arrow -> GtkArrow, child of button
159 * popup_widget -> tree_view
160 * popup_window -> GtkWindow
161 * popup_frame -> GtkFrame, child of popup_window
174 PROP_ROW_SPAN_COLUMN,
175 PROP_COLUMN_SPAN_COLUMN,
179 static GtkBinClass *parent_class = NULL;
180 static guint combo_box_signals[LAST_SIGNAL] = {0,};
182 #define BONUS_PADDING 4
186 static void gtk_combo_box_class_init (GtkComboBoxClass *klass);
187 static void gtk_combo_box_cell_layout_init (GtkCellLayoutIface *iface);
188 static void gtk_combo_box_init (GtkComboBox *combo_box);
189 static void gtk_combo_box_finalize (GObject *object);
190 static void gtk_combo_box_destroy (GtkObject *object);
192 static void gtk_combo_box_set_property (GObject *object,
196 static void gtk_combo_box_get_property (GObject *object,
201 static void gtk_combo_box_state_changed (GtkWidget *widget,
202 GtkStateType previous);
203 static void gtk_combo_box_style_set (GtkWidget *widget,
205 static void gtk_combo_box_button_toggled (GtkWidget *widget,
207 static void gtk_combo_box_add (GtkContainer *container,
209 static void gtk_combo_box_remove (GtkContainer *container,
212 static ComboCellInfo *gtk_combo_box_get_cell_info (GtkComboBox *combo_box,
213 GtkCellRenderer *cell);
215 static void gtk_combo_box_menu_show (GtkWidget *menu,
217 static void gtk_combo_box_menu_hide (GtkWidget *menu,
220 static void gtk_combo_box_set_popup_widget (GtkComboBox *combo_box,
222 static void gtk_combo_box_menu_position_below (GtkMenu *menu,
227 static void gtk_combo_box_menu_position_over (GtkMenu *menu,
232 static void gtk_combo_box_menu_position (GtkMenu *menu,
238 static gint gtk_combo_box_calc_requested_width (GtkComboBox *combo_box,
240 static void gtk_combo_box_remeasure (GtkComboBox *combo_box);
242 static void gtk_combo_box_unset_model (GtkComboBox *combo_box);
244 static void gtk_combo_box_size_request (GtkWidget *widget,
245 GtkRequisition *requisition);
246 static void gtk_combo_box_size_allocate (GtkWidget *widget,
247 GtkAllocation *allocation);
248 static void gtk_combo_box_forall (GtkContainer *container,
249 gboolean include_internals,
250 GtkCallback callback,
251 gpointer callback_data);
252 static gboolean gtk_combo_box_expose_event (GtkWidget *widget,
253 GdkEventExpose *event);
254 static gboolean gtk_combo_box_scroll_event (GtkWidget *widget,
255 GdkEventScroll *event);
256 static void gtk_combo_box_set_active_internal (GtkComboBox *combo_box,
258 static gboolean gtk_combo_box_key_press (GtkWidget *widget,
261 static void cell_view_sync_cells (GtkComboBox *combo_box,
262 GtkCellView *cell_view);
264 /* listening to the model */
265 static void gtk_combo_box_model_row_inserted (GtkTreeModel *model,
269 static void gtk_combo_box_model_row_deleted (GtkTreeModel *model,
272 static void gtk_combo_box_model_rows_reordered (GtkTreeModel *model,
277 static void gtk_combo_box_model_row_changed (GtkTreeModel *model,
283 static void gtk_combo_box_list_position (GtkComboBox *combo_box,
288 static void gtk_combo_box_list_setup (GtkComboBox *combo_box);
289 static void gtk_combo_box_list_destroy (GtkComboBox *combo_box);
291 static void gtk_combo_box_list_remove_grabs (GtkComboBox *combo_box);
293 static gboolean gtk_combo_box_list_button_released (GtkWidget *widget,
294 GdkEventButton *event,
296 static gboolean gtk_combo_box_list_key_press (GtkWidget *widget,
299 static gboolean gtk_combo_box_list_button_pressed (GtkWidget *widget,
300 GdkEventButton *event,
303 static void gtk_combo_box_list_row_changed (GtkTreeModel *model,
309 static void gtk_combo_box_menu_setup (GtkComboBox *combo_box,
310 gboolean add_children);
311 static void gtk_combo_box_menu_fill (GtkComboBox *combo_box);
312 static void gtk_combo_box_menu_destroy (GtkComboBox *combo_box);
314 static void gtk_combo_box_item_get_size (GtkComboBox *combo_box,
318 static void gtk_combo_box_relayout_item (GtkComboBox *combo_box,
320 static void gtk_combo_box_relayout (GtkComboBox *combo_box);
322 static gboolean gtk_combo_box_menu_button_press (GtkWidget *widget,
323 GdkEventButton *event,
325 static void gtk_combo_box_menu_item_activate (GtkWidget *item,
327 static void gtk_combo_box_menu_row_inserted (GtkTreeModel *model,
331 static void gtk_combo_box_menu_row_deleted (GtkTreeModel *model,
334 static void gtk_combo_box_menu_rows_reordered (GtkTreeModel *model,
339 static void gtk_combo_box_menu_row_changed (GtkTreeModel *model,
343 static gboolean gtk_combo_box_menu_key_press (GtkWidget *widget,
346 static void gtk_combo_box_menu_state_changed (GtkWidget *widget,
347 GtkStateType previous,
351 static void gtk_combo_box_cell_layout_pack_start (GtkCellLayout *layout,
352 GtkCellRenderer *cell,
354 static void gtk_combo_box_cell_layout_pack_end (GtkCellLayout *layout,
355 GtkCellRenderer *cell,
357 static void gtk_combo_box_cell_layout_clear (GtkCellLayout *layout);
358 static void gtk_combo_box_cell_layout_add_attribute (GtkCellLayout *layout,
359 GtkCellRenderer *cell,
360 const gchar *attribute,
362 static void gtk_combo_box_cell_layout_set_cell_data_func (GtkCellLayout *layout,
363 GtkCellRenderer *cell,
364 GtkCellLayoutDataFunc func,
366 GDestroyNotify destroy);
367 static void gtk_combo_box_cell_layout_clear_attributes (GtkCellLayout *layout,
368 GtkCellRenderer *cell);
369 static void gtk_combo_box_cell_layout_reorder (GtkCellLayout *layout,
370 GtkCellRenderer *cell,
372 static gboolean gtk_combo_box_mnemonic_activate (GtkWidget *widget,
373 gboolean group_cycling);
375 static void cell_view_sync_cells (GtkComboBox *combo_box,
376 GtkCellView *cell_view);
379 gtk_combo_box_get_type (void)
381 static GType combo_box_type = 0;
385 static const GTypeInfo combo_box_info =
387 sizeof (GtkComboBoxClass),
388 NULL, /* base_init */
389 NULL, /* base_finalize */
390 (GClassInitFunc) gtk_combo_box_class_init,
391 NULL, /* class_finalize */
392 NULL, /* class_data */
393 sizeof (GtkComboBox),
395 (GInstanceInitFunc) gtk_combo_box_init
398 static const GInterfaceInfo cell_layout_info =
400 (GInterfaceInitFunc) gtk_combo_box_cell_layout_init,
405 combo_box_type = g_type_register_static (GTK_TYPE_BIN,
410 g_type_add_interface_static (combo_box_type,
411 GTK_TYPE_CELL_LAYOUT,
415 return combo_box_type;
420 gtk_combo_box_class_init (GtkComboBoxClass *klass)
422 GObjectClass *object_class;
423 GtkBindingSet *binding_set;
424 GtkObjectClass *gtk_object_class;
425 GtkContainerClass *container_class;
426 GtkWidgetClass *widget_class;
428 binding_set = gtk_binding_set_by_class (klass);
430 container_class = (GtkContainerClass *)klass;
431 container_class->forall = gtk_combo_box_forall;
432 container_class->add = gtk_combo_box_add;
433 container_class->remove = gtk_combo_box_remove;
435 widget_class = (GtkWidgetClass *)klass;
436 widget_class->size_allocate = gtk_combo_box_size_allocate;
437 widget_class->size_request = gtk_combo_box_size_request;
438 widget_class->expose_event = gtk_combo_box_expose_event;
439 widget_class->scroll_event = gtk_combo_box_scroll_event;
440 widget_class->mnemonic_activate = gtk_combo_box_mnemonic_activate;
441 widget_class->style_set = gtk_combo_box_style_set;
442 widget_class->state_changed = gtk_combo_box_state_changed;
444 gtk_object_class = (GtkObjectClass *)klass;
445 gtk_object_class->destroy = gtk_combo_box_destroy;
447 object_class = (GObjectClass *)klass;
448 object_class->finalize = gtk_combo_box_finalize;
449 object_class->set_property = gtk_combo_box_set_property;
450 object_class->get_property = gtk_combo_box_get_property;
452 parent_class = g_type_class_peek_parent (klass);
455 combo_box_signals[CHANGED] =
456 g_signal_new ("changed",
457 G_OBJECT_CLASS_TYPE (klass),
459 G_STRUCT_OFFSET (GtkComboBoxClass, changed),
461 g_cclosure_marshal_VOID__VOID,
465 g_object_class_install_property (object_class,
467 g_param_spec_object ("model",
468 P_("ComboBox model"),
469 P_("The model for the combo box"),
473 g_object_class_install_property (object_class,
475 g_param_spec_int ("wrap_width",
477 P_("Wrap width for layouting the items in a grid"),
483 g_object_class_install_property (object_class,
484 PROP_ROW_SPAN_COLUMN,
485 g_param_spec_int ("row_span_column",
486 P_("Row span column"),
487 P_("TreeModel column containing the row span values"),
493 g_object_class_install_property (object_class,
494 PROP_COLUMN_SPAN_COLUMN,
495 g_param_spec_int ("column_span_column",
496 P_("Column span column"),
497 P_("TreeModel column containing the column span values"),
503 g_object_class_install_property (object_class,
505 g_param_spec_int ("active",
507 P_("The item which is currently active"),
513 gtk_widget_class_install_style_property (widget_class,
514 g_param_spec_boolean ("appears-as-list",
515 P_("Appears as list"),
516 P_("Whether combobox dropdowns should look like lists rather than menus"),
520 g_type_class_add_private (object_class, sizeof (GtkComboBoxPrivate));
524 gtk_combo_box_cell_layout_init (GtkCellLayoutIface *iface)
526 iface->pack_start = gtk_combo_box_cell_layout_pack_start;
527 iface->pack_end = gtk_combo_box_cell_layout_pack_end;
528 iface->clear = gtk_combo_box_cell_layout_clear;
529 iface->add_attribute = gtk_combo_box_cell_layout_add_attribute;
530 iface->set_cell_data_func = gtk_combo_box_cell_layout_set_cell_data_func;
531 iface->clear_attributes = gtk_combo_box_cell_layout_clear_attributes;
532 iface->reorder = gtk_combo_box_cell_layout_reorder;
536 gtk_combo_box_init (GtkComboBox *combo_box)
538 combo_box->priv = GTK_COMBO_BOX_GET_PRIVATE (combo_box);
540 combo_box->priv->cell_view = gtk_cell_view_new ();
541 gtk_widget_set_parent (combo_box->priv->cell_view, GTK_WIDGET (combo_box));
542 GTK_BIN (combo_box)->child = combo_box->priv->cell_view;
543 gtk_widget_show (combo_box->priv->cell_view);
545 combo_box->priv->width = 0;
546 combo_box->priv->wrap_width = 0;
548 combo_box->priv->active_item = -1;
549 combo_box->priv->col_column = -1;
550 combo_box->priv->row_column = -1;
554 gtk_combo_box_set_property (GObject *object,
559 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
564 gtk_combo_box_set_model (combo_box, g_value_get_object (value));
567 case PROP_WRAP_WIDTH:
568 gtk_combo_box_set_wrap_width (combo_box, g_value_get_int (value));
571 case PROP_ROW_SPAN_COLUMN:
572 gtk_combo_box_set_row_span_column (combo_box, g_value_get_int (value));
575 case PROP_COLUMN_SPAN_COLUMN:
576 gtk_combo_box_set_column_span_column (combo_box, g_value_get_int (value));
580 gtk_combo_box_set_active (combo_box, g_value_get_int (value));
589 gtk_combo_box_get_property (GObject *object,
594 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
599 g_value_set_object (value, combo_box->priv->model);
602 case PROP_WRAP_WIDTH:
603 g_value_set_int (value, combo_box->priv->wrap_width);
606 case PROP_ROW_SPAN_COLUMN:
607 g_value_set_int (value, combo_box->priv->row_column);
610 case PROP_COLUMN_SPAN_COLUMN:
611 g_value_set_int (value, combo_box->priv->col_column);
615 g_value_set_int (value, gtk_combo_box_get_active (combo_box));
619 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
625 gtk_combo_box_state_changed (GtkWidget *widget,
626 GtkStateType previous)
628 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
630 if (GTK_WIDGET_REALIZED (widget))
632 if (combo_box->priv->tree_view && combo_box->priv->cell_view)
633 gtk_cell_view_set_background_color (GTK_CELL_VIEW (combo_box->priv->cell_view),
634 &widget->style->base[GTK_WIDGET_STATE (widget)]);
637 gtk_widget_queue_draw (widget);
641 gtk_combo_box_check_appearance (GtkComboBox *combo_box)
643 gboolean appears_as_list;
645 /* if wrap_width > 0, then we are in grid-mode and forced to use
648 if (combo_box->priv->wrap_width)
649 appears_as_list = FALSE;
651 gtk_widget_style_get (GTK_WIDGET (combo_box),
652 "appears-as-list", &appears_as_list,
657 /* Destroy all the menu mode widgets, if they exist. */
658 if (GTK_IS_MENU (combo_box->priv->popup_widget))
659 gtk_combo_box_menu_destroy (combo_box);
661 /* Create the list mode widgets, if they don't already exist. */
662 if (!GTK_IS_TREE_VIEW (combo_box->priv->tree_view))
663 gtk_combo_box_list_setup (combo_box);
667 /* Destroy all the list mode widgets, if they exist. */
668 if (GTK_IS_TREE_VIEW (combo_box->priv->tree_view))
669 gtk_combo_box_list_destroy (combo_box);
671 /* Create the menu mode widgets, if they don't already exist. */
672 if (!GTK_IS_MENU (combo_box->priv->popup_widget))
673 gtk_combo_box_menu_setup (combo_box, TRUE);
678 gtk_combo_box_style_set (GtkWidget *widget,
681 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
683 gtk_combo_box_check_appearance (combo_box);
685 if (combo_box->priv->tree_view && combo_box->priv->cell_view)
686 gtk_cell_view_set_background_color (GTK_CELL_VIEW (combo_box->priv->cell_view),
687 &widget->style->base[GTK_WIDGET_STATE (widget)]);
691 gtk_combo_box_button_toggled (GtkWidget *widget,
694 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
696 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
698 if (!combo_box->priv->popup_in_progress)
699 gtk_combo_box_popup (combo_box);
702 gtk_combo_box_popdown (combo_box);
706 gtk_combo_box_add (GtkContainer *container,
709 GtkComboBox *combo_box = GTK_COMBO_BOX (container);
711 if (combo_box->priv->cell_view && combo_box->priv->cell_view->parent)
713 gtk_widget_unparent (combo_box->priv->cell_view);
714 GTK_BIN (container)->child = NULL;
715 gtk_widget_queue_resize (GTK_WIDGET (container));
718 gtk_widget_set_parent (widget, GTK_WIDGET (container));
719 GTK_BIN (container)->child = widget;
721 if (combo_box->priv->cell_view &&
722 widget != combo_box->priv->cell_view)
724 /* since the cell_view was unparented, it's gone now */
725 combo_box->priv->cell_view = NULL;
727 if (!combo_box->priv->tree_view && combo_box->priv->separator)
729 gtk_container_remove (GTK_CONTAINER (combo_box->priv->separator->parent),
730 combo_box->priv->separator);
731 combo_box->priv->separator = NULL;
733 gtk_widget_queue_resize (GTK_WIDGET (container));
735 else if (combo_box->priv->cell_view_frame)
737 gtk_widget_unparent (combo_box->priv->cell_view_frame);
738 combo_box->priv->cell_view_frame = NULL;
744 gtk_combo_box_remove (GtkContainer *container,
747 GtkComboBox *combo_box = GTK_COMBO_BOX (container);
748 gboolean appears_as_list;
750 gtk_widget_unparent (widget);
751 GTK_BIN (container)->child = NULL;
753 if (combo_box->priv->destroying)
756 gtk_widget_queue_resize (GTK_WIDGET (container));
758 if (!combo_box->priv->tree_view)
759 appears_as_list = FALSE;
761 appears_as_list = TRUE;
764 gtk_combo_box_list_destroy (combo_box);
765 else if (GTK_IS_MENU (combo_box->priv->popup_widget))
767 gtk_combo_box_menu_destroy (combo_box);
768 gtk_menu_detach (GTK_MENU (combo_box->priv->popup_widget));
769 combo_box->priv->popup_widget = NULL;
772 if (!combo_box->priv->cell_view)
774 combo_box->priv->cell_view = gtk_cell_view_new ();
775 gtk_widget_set_parent (combo_box->priv->cell_view, GTK_WIDGET (container));
776 GTK_BIN (container)->child = combo_box->priv->cell_view;
778 gtk_widget_show (combo_box->priv->cell_view);
779 gtk_cell_view_set_model (GTK_CELL_VIEW (combo_box->priv->cell_view),
780 combo_box->priv->model);
781 cell_view_sync_cells (combo_box, GTK_CELL_VIEW (combo_box->priv->cell_view));
786 gtk_combo_box_list_setup (combo_box);
788 gtk_combo_box_menu_setup (combo_box, TRUE);
790 gtk_combo_box_set_active_internal (combo_box, combo_box->priv->active_item);
793 static ComboCellInfo *
794 gtk_combo_box_get_cell_info (GtkComboBox *combo_box,
795 GtkCellRenderer *cell)
799 for (i = combo_box->priv->cells; i; i = i->next)
801 ComboCellInfo *info = (ComboCellInfo *)i->data;
803 if (info && info->cell == cell)
811 gtk_combo_box_menu_show (GtkWidget *menu,
814 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
816 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
818 combo_box->priv->popup_in_progress = FALSE;
822 gtk_combo_box_menu_hide (GtkWidget *menu,
825 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
827 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
832 gtk_combo_box_detacher (GtkWidget *widget,
835 GtkComboBox *combo_box;
837 g_return_if_fail (GTK_IS_COMBO_BOX (widget));
839 combo_box = GTK_COMBO_BOX (widget);
840 g_return_if_fail (combo_box->priv->popup_widget == (GtkWidget*) menu);
842 g_signal_handlers_disconnect_by_func (menu,
843 gtk_combo_box_menu_show,
845 g_signal_handlers_disconnect_by_func (menu,
846 gtk_combo_box_menu_hide,
849 combo_box->priv->popup_widget = NULL;
853 gtk_combo_box_set_popup_widget (GtkComboBox *combo_box,
856 if (GTK_IS_MENU (combo_box->priv->popup_widget))
858 gtk_menu_detach (GTK_MENU (combo_box->priv->popup_widget));
859 combo_box->priv->popup_widget = NULL;
861 else if (combo_box->priv->popup_widget)
863 gtk_container_remove (GTK_CONTAINER (combo_box->priv->popup_frame),
864 combo_box->priv->popup_widget);
865 g_object_unref (G_OBJECT (combo_box->priv->popup_widget));
866 combo_box->priv->popup_widget = NULL;
869 if (GTK_IS_MENU (popup))
871 if (combo_box->priv->popup_window)
873 gtk_widget_destroy (combo_box->priv->popup_window);
874 combo_box->priv->popup_window = NULL;
875 combo_box->priv->popup_frame = NULL;
878 combo_box->priv->popup_widget = popup;
880 g_signal_connect (popup, "show",
881 G_CALLBACK (gtk_combo_box_menu_show), combo_box);
882 g_signal_connect (popup, "hide",
883 G_CALLBACK (gtk_combo_box_menu_hide), combo_box);
885 gtk_menu_attach_to_widget (GTK_MENU (popup),
886 GTK_WIDGET (combo_box),
887 gtk_combo_box_detacher);
891 if (!combo_box->priv->popup_window)
893 combo_box->priv->popup_window = gtk_window_new (GTK_WINDOW_POPUP);
894 gtk_window_set_resizable (GTK_WINDOW (combo_box->priv->popup_window), FALSE);
895 gtk_window_set_screen (GTK_WINDOW (combo_box->priv->popup_window),
896 gtk_widget_get_screen (GTK_WIDGET (combo_box)));
898 combo_box->priv->popup_frame = gtk_frame_new (NULL);
899 gtk_frame_set_shadow_type (GTK_FRAME (combo_box->priv->popup_frame),
900 GTK_SHADOW_ETCHED_IN);
901 gtk_container_add (GTK_CONTAINER (combo_box->priv->popup_window),
902 combo_box->priv->popup_frame);
904 gtk_widget_show (combo_box->priv->popup_frame);
907 gtk_container_add (GTK_CONTAINER (combo_box->priv->popup_frame),
909 gtk_widget_show (popup);
910 g_object_ref (G_OBJECT (popup));
911 combo_box->priv->popup_widget = popup;
916 gtk_combo_box_menu_position_below (GtkMenu *menu,
925 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
927 /* FIXME: is using the size request here broken? */
928 child = GTK_BIN (combo_box)->child;
930 gdk_window_get_origin (child->window, &sx, &sy);
932 gtk_widget_size_request (GTK_WIDGET (menu), &req);
934 if (gtk_widget_get_direction (GTK_WIDGET (combo_box)) == GTK_TEXT_DIR_LTR)
937 *x = sx + child->allocation.width - req.width;
938 *y = sy + child->allocation.height;
940 if (GTK_WIDGET_NO_WINDOW (child))
942 *x += child->allocation.x;
943 *y += child->allocation.y;
950 gtk_combo_box_menu_position_over (GtkMenu *menu,
956 GtkComboBox *combo_box;
960 GtkRequisition requisition;
967 g_return_if_fail (GTK_IS_COMBO_BOX (user_data));
969 combo_box = GTK_COMBO_BOX (user_data);
970 widget = GTK_WIDGET (combo_box);
972 gtk_widget_get_child_requisition (GTK_WIDGET (menu), &requisition);
973 menu_width = requisition.width;
975 active = gtk_menu_get_active (GTK_MENU (combo_box->priv->popup_widget));
976 gdk_window_get_origin (widget->window, &menu_xpos, &menu_ypos);
978 menu_xpos += widget->allocation.x;
979 menu_ypos += widget->allocation.y + widget->allocation.height / 2 - 2;
983 gtk_widget_get_child_requisition (active, &requisition);
984 menu_ypos -= requisition.height / 2;
987 children = GTK_MENU_SHELL (combo_box->priv->popup_widget)->children;
990 child = children->data;
995 if (GTK_WIDGET_VISIBLE (child))
997 gtk_widget_get_child_requisition (child, &requisition);
998 menu_ypos -= requisition.height;
1001 children = children->next;
1004 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1005 menu_xpos = menu_xpos + widget->allocation.width - menu_width;
1007 /* Clamp the position on screen */
1008 screen_width = gdk_screen_get_width (gtk_widget_get_screen (widget));
1012 else if ((menu_xpos + menu_width) > screen_width)
1013 menu_xpos -= ((menu_xpos + menu_width) - screen_width);
1022 gtk_combo_box_menu_position (GtkMenu *menu,
1028 GtkComboBox *combo_box;
1029 GtkWidget *menu_item;
1031 combo_box = GTK_COMBO_BOX (user_data);
1033 if (combo_box->priv->wrap_width > 0 || combo_box->priv->cell_view == NULL)
1034 gtk_combo_box_menu_position_below (menu, x, y, push_in, user_data);
1037 menu_item = gtk_menu_get_active (GTK_MENU (combo_box->priv->popup_widget));
1039 gtk_menu_shell_select_item (GTK_MENU_SHELL (combo_box->priv->popup_widget),
1042 gtk_combo_box_menu_position_over (menu, x, y, push_in, user_data);
1048 gtk_combo_box_list_position (GtkComboBox *combo_box,
1057 GdkRectangle monitor;
1058 GtkRequisition popup_req;
1060 sample = GTK_BIN (combo_box)->child;
1062 *width = sample->allocation.width;
1063 gtk_widget_size_request (combo_box->priv->popup_window, &popup_req);
1064 *height = popup_req.height;
1066 gdk_window_get_origin (sample->window, x, y);
1068 if (combo_box->priv->cell_view_frame)
1070 *x -= GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
1071 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->xthickness;
1072 *width += 2 * (GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
1073 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->xthickness);
1076 if (GTK_WIDGET_NO_WINDOW (sample))
1078 *x += sample->allocation.x;
1079 *y += sample->allocation.y;
1082 screen = gtk_widget_get_screen (GTK_WIDGET (combo_box));
1083 monitor_num = gdk_screen_get_monitor_at_window (screen,
1084 GTK_WIDGET (combo_box)->window);
1085 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
1089 else if (*x + *width > monitor.x + monitor.width)
1090 *x = monitor.x + monitor.width - *width;
1092 if (*y + sample->allocation.height + *height <= monitor.y + monitor.height)
1093 *y += sample->allocation.height;
1099 update_menu_sensitivity (GtkComboBox *combo_box)
1105 if (!combo_box->priv->model || !combo_box->priv->selection_func)
1108 items = gtk_tree_model_iter_n_children (combo_box->priv->model, NULL);
1109 menu = combo_box->priv->popup_widget;
1111 children = gtk_container_get_children (GTK_CONTAINER (menu));
1112 for (i = 0; i < items; i++, children = children->next)
1118 path = gtk_tree_path_new_from_indices (i, -1);
1119 item = GTK_WIDGET (children->data);
1121 sensitive = (*combo_box->priv->selection_func) (combo_box->priv->model,
1123 i == combo_box->priv->active_item,
1124 combo_box->priv->selection_data);
1126 gtk_widget_set_sensitive (item, sensitive);
1128 gtk_tree_path_free (path);
1133 * gtk_combo_box_popup:
1134 * @combo_box: a #GtkComboBox
1136 * Pops up the menu or dropdown list of @combo_box.
1138 * This function is mostly intended for use by accessibility technologies;
1139 * applications should have little use for it.
1144 gtk_combo_box_popup (GtkComboBox *combo_box)
1146 gint x, y, width, height;
1148 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
1150 if (GTK_WIDGET_MAPPED (combo_box->priv->popup_widget))
1153 if (GTK_IS_MENU (combo_box->priv->popup_widget))
1155 update_menu_sensitivity (combo_box);
1157 gtk_menu_set_active (GTK_MENU (combo_box->priv->popup_widget),
1158 combo_box->priv->active_item);
1160 gtk_menu_popup (GTK_MENU (combo_box->priv->popup_widget),
1162 gtk_combo_box_menu_position, combo_box,
1167 gtk_widget_show_all (combo_box->priv->popup_frame);
1168 gtk_combo_box_list_position (combo_box, &x, &y, &width, &height);
1170 gtk_widget_set_size_request (combo_box->priv->popup_window, width, -1);
1171 gtk_window_move (GTK_WINDOW (combo_box->priv->popup_window), x, y);
1174 gtk_widget_show (combo_box->priv->popup_window);
1176 gtk_widget_grab_focus (combo_box->priv->popup_window);
1177 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
1180 if (!GTK_WIDGET_HAS_FOCUS (combo_box->priv->tree_view))
1182 gdk_keyboard_grab (combo_box->priv->popup_window->window,
1183 FALSE, GDK_CURRENT_TIME);
1184 gtk_widget_grab_focus (combo_box->priv->tree_view);
1187 gtk_grab_add (combo_box->priv->popup_window);
1188 gdk_pointer_grab (combo_box->priv->popup_window->window, TRUE,
1189 GDK_BUTTON_PRESS_MASK |
1190 GDK_BUTTON_RELEASE_MASK |
1191 GDK_POINTER_MOTION_MASK,
1192 NULL, NULL, GDK_CURRENT_TIME);
1194 gtk_grab_add (combo_box->priv->tree_view);
1198 * gtk_combo_box_popdown:
1199 * @combo_box: a #GtkComboBox
1201 * Hides the menu or dropdown list of @combo_box.
1203 * This function is mostly intended for use by accessibility technologies;
1204 * applications should have little use for it.
1209 gtk_combo_box_popdown (GtkComboBox *combo_box)
1211 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
1213 if (GTK_IS_MENU (combo_box->priv->popup_widget))
1215 gtk_menu_popdown (GTK_MENU (combo_box->priv->popup_widget));
1219 gtk_combo_box_list_remove_grabs (combo_box);
1220 gtk_widget_hide_all (combo_box->priv->popup_window);
1221 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
1226 gtk_combo_box_calc_requested_width (GtkComboBox *combo_box,
1232 if (combo_box->priv->cell_view)
1233 gtk_widget_style_get (combo_box->priv->cell_view,
1234 "focus-line-width", &padding,
1239 /* add some pixels for good measure */
1240 padding += BONUS_PADDING;
1242 if (combo_box->priv->cell_view)
1243 gtk_cell_view_get_size_of_row (GTK_CELL_VIEW (combo_box->priv->cell_view),
1248 return req.width + padding;
1252 gtk_combo_box_remeasure (GtkComboBox *combo_box)
1258 if (!gtk_tree_model_get_iter_first (combo_box->priv->model, &iter))
1261 combo_box->priv->width = 0;
1263 path = gtk_tree_path_new_from_indices (0, -1);
1265 if (combo_box->priv->cell_view)
1266 gtk_widget_style_get (combo_box->priv->cell_view,
1267 "focus-line-width", &padding,
1272 /* add some pixels for good measure */
1273 padding += BONUS_PADDING;
1279 if (combo_box->priv->cell_view)
1280 gtk_cell_view_get_size_of_row (GTK_CELL_VIEW (combo_box->priv->cell_view),
1285 combo_box->priv->width = MAX (combo_box->priv->width,
1286 req.width + padding);
1288 gtk_tree_path_next (path);
1290 while (gtk_tree_model_iter_next (combo_box->priv->model, &iter));
1292 gtk_tree_path_free (path);
1296 gtk_combo_box_size_request (GtkWidget *widget,
1297 GtkRequisition *requisition)
1300 GtkRequisition bin_req;
1302 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
1305 gtk_widget_size_request (GTK_BIN (widget)->child, &bin_req);
1306 gtk_combo_box_remeasure (combo_box);
1307 bin_req.width = MAX (bin_req.width, combo_box->priv->width);
1309 if (!combo_box->priv->tree_view)
1313 if (combo_box->priv->cell_view)
1315 GtkRequisition button_req, sep_req, arrow_req;
1316 gint border_width, xthickness, ythickness;
1318 gtk_widget_size_request (combo_box->priv->button, &button_req);
1319 border_width = GTK_CONTAINER (combo_box->priv->button)->border_width;
1320 xthickness = combo_box->priv->button->style->xthickness;
1321 ythickness = combo_box->priv->button->style->ythickness;
1323 bin_req.width = MAX (bin_req.width, combo_box->priv->width);
1325 gtk_widget_size_request (combo_box->priv->separator, &sep_req);
1326 gtk_widget_size_request (combo_box->priv->arrow, &arrow_req);
1328 height = MAX (sep_req.height, arrow_req.height);
1329 height = MAX (height, bin_req.height);
1331 width = bin_req.width + sep_req.width + arrow_req.width;
1333 height += border_width + 1 + ythickness * 2 + 4;
1334 width += border_width + 1 + xthickness * 2 + 4;
1336 requisition->width = width;
1337 requisition->height = height;
1341 GtkRequisition but_req;
1343 gtk_widget_size_request (combo_box->priv->button, &but_req);
1345 requisition->width = bin_req.width + but_req.width;
1346 requisition->height = MAX (bin_req.height, but_req.height);
1352 GtkRequisition button_req, frame_req;
1354 /* sample + frame */
1355 *requisition = bin_req;
1357 if (combo_box->priv->cell_view_frame)
1359 gtk_widget_size_request (combo_box->priv->cell_view_frame, &frame_req);
1360 requisition->width += 2 *
1361 (GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
1362 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->xthickness);
1363 requisition->height += 2 *
1364 (GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
1365 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->ythickness);
1369 gtk_widget_size_request (combo_box->priv->button, &button_req);
1371 requisition->height = MAX (requisition->height, button_req.height);
1372 requisition->width += button_req.width;
1377 gtk_combo_box_size_allocate (GtkWidget *widget,
1378 GtkAllocation *allocation)
1380 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
1381 GtkAllocation child;
1383 gboolean is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
1385 widget->allocation = *allocation;
1387 if (!combo_box->priv->tree_view)
1389 if (combo_box->priv->cell_view)
1391 gint border_width, xthickness, ythickness;
1395 gtk_widget_size_allocate (combo_box->priv->button, allocation);
1397 /* set some things ready */
1398 border_width = GTK_CONTAINER (combo_box->priv->button)->border_width;
1399 xthickness = combo_box->priv->button->style->xthickness;
1400 ythickness = combo_box->priv->button->style->ythickness;
1402 child.x = allocation->x + border_width + 1 + xthickness + 2;
1403 child.y = allocation->y + border_width + 1 + ythickness + 2;
1405 width = allocation->width - (border_width + 1 + xthickness * 2 + 4);
1407 /* handle the children */
1408 gtk_widget_size_request (combo_box->priv->arrow, &req);
1409 child.width = req.width;
1410 child.height = allocation->height - 2 * (child.y - allocation->y);
1412 child.x += width - req.width;
1413 gtk_widget_size_allocate (combo_box->priv->arrow, &child);
1415 child.x += req.width;
1416 gtk_widget_size_request (combo_box->priv->separator, &req);
1417 child.width = req.width;
1419 child.x -= req.width;
1420 gtk_widget_size_allocate (combo_box->priv->separator, &child);
1424 child.x += req.width;
1425 child.width = allocation->x + allocation->width
1426 - (border_width + 1 + xthickness + 2) - child.x;
1430 child.width = child.x;
1431 child.x = allocation->x + border_width + 1 + xthickness + 2;
1432 child.width -= child.x;
1435 gtk_widget_size_allocate (GTK_BIN (widget)->child, &child);
1439 gtk_widget_size_request (combo_box->priv->button, &req);
1441 child.x = allocation->x;
1443 child.x = allocation->x + allocation->width - req.width;
1444 child.y = allocation->y;
1445 child.width = req.width;
1446 child.height = allocation->height;
1447 gtk_widget_size_allocate (combo_box->priv->button, &child);
1450 child.x = allocation->x + req.width;
1452 child.x = allocation->x;
1453 child.y = allocation->y;
1454 child.width = allocation->width - req.width;
1455 gtk_widget_size_allocate (GTK_BIN (widget)->child, &child);
1463 gtk_widget_size_request (combo_box->priv->button, &req);
1465 child.x = allocation->x;
1467 child.x = allocation->x + allocation->width - req.width;
1468 child.y = allocation->y;
1469 child.width = req.width;
1470 child.height = allocation->height;
1471 gtk_widget_size_allocate (combo_box->priv->button, &child);
1475 child.x = allocation->x + req.width;
1477 child.x = allocation->x;
1478 child.y = allocation->y;
1479 child.width = allocation->width - req.width;
1480 child.height = allocation->height;
1482 if (combo_box->priv->cell_view_frame)
1484 gtk_widget_size_allocate (combo_box->priv->cell_view_frame, &child);
1488 GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
1489 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->xthickness;
1491 GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
1492 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->ythickness;
1493 child.width -= 2 * (
1494 GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
1495 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->xthickness);
1496 child.height -= 2 * (
1497 GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
1498 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->ythickness);
1501 gtk_widget_size_allocate (GTK_BIN (combo_box)->child, &child);
1506 gtk_combo_box_unset_model (GtkComboBox *combo_box)
1508 if (combo_box->priv->model)
1510 g_signal_handler_disconnect (combo_box->priv->model,
1511 combo_box->priv->inserted_id);
1512 g_signal_handler_disconnect (combo_box->priv->model,
1513 combo_box->priv->deleted_id);
1514 g_signal_handler_disconnect (combo_box->priv->model,
1515 combo_box->priv->reordered_id);
1516 g_signal_handler_disconnect (combo_box->priv->model,
1517 combo_box->priv->changed_id);
1521 if (!combo_box->priv->tree_view)
1523 if (combo_box->priv->popup_widget)
1524 gtk_container_foreach (GTK_CONTAINER (combo_box->priv->popup_widget),
1525 (GtkCallback)gtk_widget_destroy, NULL);
1528 if (combo_box->priv->model)
1530 g_object_unref (G_OBJECT (combo_box->priv->model));
1531 combo_box->priv->model = NULL;
1536 gtk_combo_box_forall (GtkContainer *container,
1537 gboolean include_internals,
1538 GtkCallback callback,
1539 gpointer callback_data)
1541 GtkComboBox *combo_box = GTK_COMBO_BOX (container);
1543 if (include_internals)
1545 if (combo_box->priv->button)
1546 (* callback) (combo_box->priv->button, callback_data);
1547 if (combo_box->priv->box)
1548 (* callback) (combo_box->priv->box, callback_data);
1549 if (combo_box->priv->separator)
1550 (* callback) (combo_box->priv->separator, callback_data);
1551 if (combo_box->priv->arrow)
1552 (* callback) (combo_box->priv->arrow, callback_data);
1553 if (combo_box->priv->cell_view_frame)
1554 (* callback) (combo_box->priv->cell_view_frame, callback_data);
1557 if (GTK_BIN (container)->child)
1558 (* callback) (GTK_BIN (container)->child, callback_data);
1562 gtk_combo_box_expose_event (GtkWidget *widget,
1563 GdkEventExpose *event)
1565 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
1567 if (!combo_box->priv->tree_view)
1569 gtk_container_propagate_expose (GTK_CONTAINER (widget),
1570 combo_box->priv->button, event);
1574 gtk_container_propagate_expose (GTK_CONTAINER (widget),
1575 combo_box->priv->button, event);
1577 if (combo_box->priv->cell_view_frame)
1578 gtk_container_propagate_expose (GTK_CONTAINER (widget),
1579 combo_box->priv->cell_view_frame, event);
1582 gtk_container_propagate_expose (GTK_CONTAINER (widget),
1583 GTK_BIN (widget)->child, event);
1589 gtk_combo_box_scroll_event (GtkWidget *widget,
1590 GdkEventScroll *event)
1592 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
1596 index = gtk_combo_box_get_active (combo_box);
1600 items = gtk_tree_model_iter_n_children (combo_box->priv->model, NULL);
1602 if (event->direction == GDK_SCROLL_UP)
1607 gtk_combo_box_set_active (combo_box, CLAMP (index, 0, items - 1));
1618 cell_view_sync_cells (GtkComboBox *combo_box,
1619 GtkCellView *cell_view)
1623 for (k = combo_box->priv->cells; k; k = k->next)
1626 ComboCellInfo *info = (ComboCellInfo *)k->data;
1628 if (info->pack == GTK_PACK_START)
1629 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (cell_view),
1630 info->cell, info->expand);
1631 else if (info->pack == GTK_PACK_END)
1632 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (cell_view),
1633 info->cell, info->expand);
1635 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (cell_view),
1637 info->func, info->func_data, NULL);
1639 for (j = info->attributes; j; j = j->next->next)
1641 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (cell_view),
1644 GPOINTER_TO_INT (j->next->data));
1650 gtk_combo_box_menu_setup (GtkComboBox *combo_box,
1651 gboolean add_children)
1655 if (combo_box->priv->cell_view)
1657 combo_box->priv->button = gtk_toggle_button_new ();
1658 g_signal_connect (combo_box->priv->button, "toggled",
1659 G_CALLBACK (gtk_combo_box_button_toggled), combo_box);
1660 g_signal_connect_after (combo_box->priv->button, "key_press_event",
1661 G_CALLBACK (gtk_combo_box_key_press), combo_box);
1662 gtk_widget_set_parent (combo_box->priv->button,
1663 GTK_BIN (combo_box)->child->parent);
1665 combo_box->priv->box = gtk_hbox_new (FALSE, 0);
1666 gtk_container_add (GTK_CONTAINER (combo_box->priv->button),
1667 combo_box->priv->box);
1669 combo_box->priv->separator = gtk_vseparator_new ();
1670 gtk_container_add (GTK_CONTAINER (combo_box->priv->box),
1671 combo_box->priv->separator);
1673 combo_box->priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
1674 gtk_container_add (GTK_CONTAINER (combo_box->priv->box),
1675 combo_box->priv->arrow);
1677 gtk_widget_show_all (combo_box->priv->button);
1681 combo_box->priv->button = gtk_toggle_button_new ();
1682 g_signal_connect (combo_box->priv->button, "toggled",
1683 G_CALLBACK (gtk_combo_box_button_toggled), combo_box);
1684 g_signal_connect_after (combo_box, "key_press_event",
1685 G_CALLBACK (gtk_combo_box_key_press), combo_box);
1686 gtk_widget_set_parent (combo_box->priv->button,
1687 GTK_BIN (combo_box)->child->parent);
1689 combo_box->priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
1690 gtk_container_add (GTK_CONTAINER (combo_box->priv->button),
1691 combo_box->priv->arrow);
1692 gtk_widget_show_all (combo_box->priv->button);
1695 g_signal_connect (combo_box->priv->button, "button_press_event",
1696 G_CALLBACK (gtk_combo_box_menu_button_press),
1698 g_signal_connect (combo_box->priv->button, "state_changed",
1699 G_CALLBACK (gtk_combo_box_menu_state_changed),
1702 /* create our funky menu */
1703 menu = gtk_menu_new ();
1704 g_signal_connect (menu, "key_press_event",
1705 G_CALLBACK (gtk_combo_box_menu_key_press), combo_box);
1706 gtk_combo_box_set_popup_widget (combo_box, menu);
1710 gtk_combo_box_menu_fill (combo_box);
1715 gtk_combo_box_menu_fill (GtkComboBox *combo_box)
1721 if (!combo_box->priv->model)
1724 items = gtk_tree_model_iter_n_children (combo_box->priv->model, NULL);
1725 menu = combo_box->priv->popup_widget;
1727 for (i = 0; i < items; i++)
1731 path = gtk_tree_path_new_from_indices (i, -1);
1732 tmp = gtk_cell_view_menu_item_new_from_model (combo_box->priv->model,
1734 g_signal_connect (tmp, "activate",
1735 G_CALLBACK (gtk_combo_box_menu_item_activate),
1738 cell_view_sync_cells (combo_box,
1739 GTK_CELL_VIEW (GTK_BIN (tmp)->child));
1741 gtk_menu_shell_append (GTK_MENU_SHELL (menu), tmp);
1743 if (combo_box->priv->wrap_width)
1744 gtk_combo_box_relayout_item (combo_box, i);
1746 gtk_widget_show (tmp);
1748 gtk_tree_path_free (path);
1753 gtk_combo_box_menu_destroy (GtkComboBox *combo_box)
1755 g_signal_handlers_disconnect_matched (combo_box->priv->button,
1756 G_SIGNAL_MATCH_DATA,
1758 gtk_combo_box_menu_button_press, NULL);
1759 g_signal_handlers_disconnect_matched (combo_box->priv->button,
1760 G_SIGNAL_MATCH_DATA,
1762 gtk_combo_box_menu_state_changed, NULL);
1764 /* unparent will remove our latest ref */
1765 gtk_widget_unparent (combo_box->priv->button);
1767 combo_box->priv->box = NULL;
1768 combo_box->priv->button = NULL;
1769 combo_box->priv->arrow = NULL;
1770 combo_box->priv->separator = NULL;
1772 /* changing the popup window will unref the menu and the children */
1780 gtk_combo_box_item_get_size (GtkComboBox *combo_box,
1787 gtk_tree_model_iter_nth_child (combo_box->priv->model, &iter, NULL, index);
1791 if (combo_box->priv->col_column == -1)
1794 gtk_tree_model_get (combo_box->priv->model, &iter,
1795 combo_box->priv->col_column, cols,
1801 if (combo_box->priv->row_column == -1)
1804 gtk_tree_model_get (combo_box->priv->model, &iter,
1805 combo_box->priv->row_column, rows,
1811 menu_occupied (GtkMenu *menu,
1815 guint bottom_attach)
1819 g_return_val_if_fail (GTK_IS_MENU (menu), TRUE);
1820 g_return_val_if_fail (left_attach < right_attach, TRUE);
1821 g_return_val_if_fail (top_attach < bottom_attach, TRUE);
1823 for (i = GTK_MENU_SHELL (menu)->children; i; i = i->next)
1826 gboolean h_intersect = FALSE;
1827 gboolean v_intersect = FALSE;
1829 gtk_container_child_get (GTK_CONTAINER (menu), i->data,
1832 "bottom_attach", &b,
1836 /* look if this item intersects with the given coordinates */
1837 h_intersect = left_attach <= l && l <= right_attach;
1838 h_intersect &= left_attach <= r && r <= right_attach;
1840 v_intersect = top_attach <= t && t <= bottom_attach;
1841 v_intersect &= top_attach <= b && b <= bottom_attach;
1843 if (h_intersect && v_intersect)
1851 gtk_combo_box_relayout_item (GtkComboBox *combo_box,
1854 gint current_col = 0, current_row = 0;
1860 menu = combo_box->priv->popup_widget;
1861 if (!GTK_IS_MENU_SHELL (menu))
1864 list = gtk_container_get_children (GTK_CONTAINER (menu));
1865 item = g_list_nth_data (list, index);
1868 gtk_combo_box_item_get_size (combo_box, index, &cols, &rows);
1870 /* look for a good spot */
1873 if (current_col + cols > combo_box->priv->wrap_width)
1879 if (!menu_occupied (GTK_MENU (menu),
1880 current_col, current_col + cols,
1881 current_row, current_row + rows))
1887 /* set attach props */
1888 gtk_menu_attach (GTK_MENU (menu), item,
1889 current_col, current_col + cols,
1890 current_row, current_row + rows);
1894 gtk_combo_box_relayout (GtkComboBox *combo_box)
1899 menu = combo_box->priv->popup_widget;
1901 /* do nothing unless we are in menu style and realized */
1902 if (combo_box->priv->tree_view || !GTK_IS_MENU_SHELL (menu))
1905 /* get rid of all children */
1906 list = gtk_container_get_children (GTK_CONTAINER (menu));
1908 for (j = g_list_last (list); j; j = j->prev)
1909 gtk_container_remove (GTK_CONTAINER (menu), j->data);
1914 gtk_combo_box_menu_fill (combo_box);
1919 gtk_combo_box_menu_button_press (GtkWidget *widget,
1920 GdkEventButton *event,
1923 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
1925 if (! GTK_IS_MENU (combo_box->priv->popup_widget))
1928 if (event->type == GDK_BUTTON_PRESS && event->button == 1)
1930 combo_box->priv->popup_in_progress = TRUE;
1932 update_menu_sensitivity (combo_box);
1934 gtk_menu_set_active (GTK_MENU (combo_box->priv->popup_widget),
1935 combo_box->priv->active_item);
1937 gtk_menu_popup (GTK_MENU (combo_box->priv->popup_widget),
1939 gtk_combo_box_menu_position, combo_box,
1940 event->button, event->time);
1949 gtk_combo_box_menu_state_changed (GtkWidget *widget,
1950 GtkStateType previous,
1953 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
1955 if (combo_box->priv->cell_view)
1957 gtk_widget_set_state (combo_box->priv->cell_view,
1958 GTK_WIDGET_STATE (widget));
1960 gtk_widget_queue_draw (combo_box->priv->cell_view);
1965 gtk_combo_box_menu_item_activate (GtkWidget *item,
1970 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
1972 menu = combo_box->priv->popup_widget;
1973 g_return_if_fail (GTK_IS_MENU (menu));
1975 index = g_list_index (GTK_MENU_SHELL (menu)->children, item);
1977 gtk_combo_box_set_active (combo_box, index);
1981 gtk_combo_box_model_row_inserted (GtkTreeModel *model,
1986 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
1987 gint index = gtk_tree_path_get_indices (path)[0];
1989 if (combo_box->priv->active_item >= index)
1990 combo_box->priv->active_item++;
1992 if (!combo_box->priv->tree_view)
1993 gtk_combo_box_menu_row_inserted (model, path, iter, user_data);
1997 gtk_combo_box_model_row_deleted (GtkTreeModel *model,
2001 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2002 gint index = gtk_tree_path_get_indices (path)[0];
2004 if (!combo_box->priv->tree_view)
2005 gtk_combo_box_menu_row_deleted (model, path, user_data);
2007 if (index == combo_box->priv->active_item)
2009 gint items = gtk_tree_model_iter_n_children (model, NULL);
2012 gtk_combo_box_set_active_internal (combo_box, -1);
2013 else if (index == items)
2014 gtk_combo_box_set_active_internal (combo_box, index - 1);
2016 gtk_combo_box_set_active_internal (combo_box, index);
2018 else if (combo_box->priv->active_item > index)
2019 combo_box->priv->active_item--;
2023 gtk_combo_box_model_rows_reordered (GtkTreeModel *model,
2029 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2030 gint items = gtk_tree_model_iter_n_children (model, NULL);
2033 for (i = 0; i < items; i++)
2034 if (new_order[i] == combo_box->priv->active_item)
2036 combo_box->priv->active_item = i;
2040 if (!combo_box->priv->tree_view)
2041 gtk_combo_box_menu_rows_reordered (model, path, iter, new_order, user_data);
2045 gtk_combo_box_model_row_changed (GtkTreeModel *model,
2050 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2051 gint index = gtk_tree_path_get_indices (path)[0];
2053 if (index == combo_box->priv->active_item &&
2054 combo_box->priv->cell_view)
2055 gtk_widget_queue_resize (GTK_WIDGET (combo_box->priv->cell_view));
2057 if (combo_box->priv->tree_view)
2058 gtk_combo_box_list_row_changed (model, path, iter, user_data);
2060 gtk_combo_box_menu_row_changed (model, path, iter, user_data);
2065 gtk_combo_box_menu_row_inserted (GtkTreeModel *model,
2072 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2074 if (!combo_box->priv->popup_widget)
2077 menu = combo_box->priv->popup_widget;
2078 g_return_if_fail (GTK_IS_MENU (menu));
2080 item = gtk_cell_view_menu_item_new_from_model (model, path);
2081 g_signal_connect (item, "activate",
2082 G_CALLBACK (gtk_combo_box_menu_item_activate),
2085 cell_view_sync_cells (combo_box, GTK_CELL_VIEW (GTK_BIN (item)->child));
2087 gtk_menu_shell_insert (GTK_MENU_SHELL (menu), item,
2088 gtk_tree_path_get_indices (path)[0]);
2089 gtk_widget_show (item);
2093 gtk_combo_box_menu_row_deleted (GtkTreeModel *model,
2100 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2102 if (!combo_box->priv->popup_widget)
2105 index = gtk_tree_path_get_indices (path)[0];
2107 menu = combo_box->priv->popup_widget;
2108 g_return_if_fail (GTK_IS_MENU (menu));
2110 item = g_list_nth_data (GTK_MENU_SHELL (menu)->children, index);
2111 g_return_if_fail (GTK_IS_MENU_ITEM (item));
2113 gtk_container_remove (GTK_CONTAINER (menu), item);
2117 gtk_combo_box_menu_rows_reordered (GtkTreeModel *model,
2123 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2125 gtk_combo_box_relayout (combo_box);
2129 gtk_combo_box_menu_row_changed (GtkTreeModel *model,
2134 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2137 if (!combo_box->priv->popup_widget)
2140 if (combo_box->priv->wrap_width)
2141 gtk_combo_box_relayout_item (combo_box,
2142 gtk_tree_path_get_indices (path)[0]);
2144 width = gtk_combo_box_calc_requested_width (combo_box, path);
2146 if (width > combo_box->priv->width)
2148 if (combo_box->priv->cell_view)
2150 gtk_widget_set_size_request (combo_box->priv->cell_view, width, -1);
2151 gtk_widget_queue_resize (combo_box->priv->cell_view);
2153 combo_box->priv->width = width;
2162 gtk_combo_box_selection_func (GtkTreeSelection *selection,
2163 GtkTreeModel *model,
2165 gboolean currently_selected,
2168 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
2170 if (combo_box->priv->selection_func)
2171 return (*combo_box->priv->selection_func) (model,
2174 combo_box->priv->selection_data);
2180 gtk_combo_box_list_setup (GtkComboBox *combo_box)
2183 GtkTreeSelection *sel;
2185 combo_box->priv->button = gtk_toggle_button_new ();
2186 gtk_widget_set_parent (combo_box->priv->button,
2187 GTK_BIN (combo_box)->child->parent);
2188 g_signal_connect (combo_box->priv->button, "button_press_event",
2189 G_CALLBACK (gtk_combo_box_list_button_pressed), combo_box);
2190 g_signal_connect (combo_box->priv->button, "toggled",
2191 G_CALLBACK (gtk_combo_box_button_toggled), combo_box);
2192 g_signal_connect_after (combo_box, "key_press_event",
2193 G_CALLBACK (gtk_combo_box_key_press), combo_box);
2195 combo_box->priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
2196 gtk_container_add (GTK_CONTAINER (combo_box->priv->button),
2197 combo_box->priv->arrow);
2198 combo_box->priv->separator = NULL;
2199 gtk_widget_show_all (combo_box->priv->button);
2201 if (combo_box->priv->cell_view)
2203 combo_box->priv->cell_view_frame = gtk_frame_new (NULL);
2204 gtk_widget_set_parent (combo_box->priv->cell_view_frame,
2205 GTK_BIN (combo_box)->child->parent);
2206 gtk_frame_set_shadow_type (GTK_FRAME (combo_box->priv->cell_view_frame),
2209 gtk_cell_view_set_background_color (GTK_CELL_VIEW (combo_box->priv->cell_view),
2210 >K_WIDGET (combo_box)->style->base[GTK_WIDGET_STATE (combo_box)]);
2212 gtk_widget_show (combo_box->priv->cell_view_frame);
2215 combo_box->priv->tree_view = gtk_tree_view_new ();
2216 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (combo_box->priv->tree_view));
2217 gtk_tree_selection_set_mode (sel, GTK_SELECTION_SINGLE);
2218 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (combo_box->priv->tree_view),
2220 if (combo_box->priv->model)
2221 gtk_tree_view_set_model (GTK_TREE_VIEW (combo_box->priv->tree_view),
2222 combo_box->priv->model);
2224 g_signal_connect (combo_box->priv->tree_view, "button_press_event",
2225 G_CALLBACK (gtk_combo_box_list_button_pressed),
2227 g_signal_connect (combo_box->priv->tree_view, "button_release_event",
2228 G_CALLBACK (gtk_combo_box_list_button_released),
2230 g_signal_connect (combo_box->priv->tree_view, "key_press_event",
2231 G_CALLBACK (gtk_combo_box_list_key_press),
2234 combo_box->priv->column = gtk_tree_view_column_new ();
2235 gtk_tree_view_append_column (GTK_TREE_VIEW (combo_box->priv->tree_view),
2236 combo_box->priv->column);
2239 for (i = combo_box->priv->cells; i; i = i->next)
2242 ComboCellInfo *info = (ComboCellInfo *)i->data;
2244 if (info->pack == GTK_PACK_START)
2245 gtk_tree_view_column_pack_start (combo_box->priv->column,
2246 info->cell, info->expand);
2247 else if (info->pack == GTK_PACK_END)
2248 gtk_tree_view_column_pack_end (combo_box->priv->column,
2249 info->cell, info->expand);
2252 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo_box->priv->column),
2253 info->cell, info->func,
2254 info->func_data, NULL);
2256 for (j = info->attributes; j; j = j->next->next)
2258 gtk_tree_view_column_add_attribute (combo_box->priv->column,
2261 GPOINTER_TO_INT (j->next->data));
2265 if (combo_box->priv->active_item != -1)
2269 path = gtk_tree_path_new_from_indices (combo_box->priv->active_item, -1);
2272 gtk_tree_view_set_cursor (GTK_TREE_VIEW (combo_box->priv->tree_view),
2274 gtk_tree_path_free (path);
2278 gtk_tree_selection_set_select_function (gtk_tree_view_get_selection (GTK_TREE_VIEW (combo_box->priv->tree_view)),
2279 gtk_combo_box_selection_func,
2283 /* set sample/popup widgets */
2284 gtk_combo_box_set_popup_widget (combo_box, combo_box->priv->tree_view);
2286 gtk_widget_show (combo_box->priv->tree_view);
2290 gtk_combo_box_list_destroy (GtkComboBox *combo_box)
2292 /* disconnect signals */
2293 g_signal_handlers_disconnect_matched (combo_box->priv->tree_view,
2294 G_SIGNAL_MATCH_DATA,
2295 0, 0, NULL, NULL, combo_box);
2296 g_signal_handlers_disconnect_matched (combo_box->priv->button,
2297 G_SIGNAL_MATCH_DATA,
2299 gtk_combo_box_list_button_pressed,
2302 /* destroy things (unparent will kill the latest ref from us)
2303 * last unref on button will destroy the arrow
2305 gtk_widget_unparent (combo_box->priv->button);
2306 combo_box->priv->button = NULL;
2307 combo_box->priv->arrow = NULL;
2309 if (combo_box->priv->cell_view)
2311 g_object_set (G_OBJECT (combo_box->priv->cell_view),
2312 "background_set", FALSE,
2316 if (combo_box->priv->cell_view_frame)
2318 gtk_widget_unparent (combo_box->priv->cell_view_frame);
2319 combo_box->priv->cell_view_frame = NULL;
2322 gtk_widget_destroy (combo_box->priv->tree_view);
2324 combo_box->priv->tree_view = NULL;
2325 combo_box->priv->popup_widget = NULL;
2330 gtk_combo_box_list_remove_grabs (GtkComboBox *combo_box)
2332 if (GTK_WIDGET_HAS_GRAB (combo_box->priv->tree_view))
2333 gtk_grab_remove (combo_box->priv->tree_view);
2335 if (GTK_WIDGET_HAS_GRAB (combo_box->priv->popup_window))
2337 gtk_grab_remove (combo_box->priv->popup_window);
2338 gdk_keyboard_ungrab (GDK_CURRENT_TIME);
2339 gdk_pointer_ungrab (GDK_CURRENT_TIME);
2344 gtk_combo_box_list_button_pressed (GtkWidget *widget,
2345 GdkEventButton *event,
2348 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
2350 GtkWidget *ewidget = gtk_get_event_widget ((GdkEvent *)event);
2352 if (ewidget == combo_box->priv->tree_view)
2355 if ((ewidget != combo_box->priv->button) ||
2356 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (combo_box->priv->button)))
2359 gtk_combo_box_popup (combo_box);
2361 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
2364 combo_box->priv->popup_in_progress = TRUE;
2370 gtk_combo_box_list_button_released (GtkWidget *widget,
2371 GdkEventButton *event,
2375 GtkTreePath *path = NULL;
2377 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
2379 gboolean popup_in_progress = FALSE;
2381 GtkWidget *ewidget = gtk_get_event_widget ((GdkEvent *)event);
2383 if (combo_box->priv->popup_in_progress)
2385 popup_in_progress = TRUE;
2386 combo_box->priv->popup_in_progress = FALSE;
2389 if (ewidget != combo_box->priv->tree_view)
2391 if (ewidget == combo_box->priv->button &&
2392 !popup_in_progress &&
2393 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (combo_box->priv->button)))
2395 gtk_combo_box_popdown (combo_box);
2399 /* released outside treeview */
2400 if (ewidget != combo_box->priv->button)
2402 gtk_combo_box_popdown (combo_box);
2410 /* select something cool */
2411 ret = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
2417 return TRUE; /* clicked outside window? */
2419 gtk_combo_box_set_active (combo_box, gtk_tree_path_get_indices (path)[0]);
2420 gtk_combo_box_popdown (combo_box);
2422 gtk_tree_path_free (path);
2428 is_selectable (GtkComboBox *combo_box,
2432 gboolean result = TRUE;
2434 path = gtk_tree_path_new_from_indices (index, -1);
2436 if (combo_box->priv->selection_func)
2437 result = (*combo_box->priv->selection_func) (combo_box->priv->model,
2440 combo_box->priv->selection_data);
2442 gtk_tree_path_free (path);
2448 gtk_combo_box_key_press (GtkWidget *widget,
2452 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
2453 guint state = event->state & gtk_accelerator_get_default_mod_mask ();
2454 gint items = gtk_tree_model_iter_n_children (combo_box->priv->model, NULL);
2455 gint index = gtk_combo_box_get_active (combo_box);
2458 if ((event->keyval == GDK_Down || event->keyval == GDK_KP_Down) &&
2459 state == GDK_MOD1_MASK)
2461 gtk_combo_box_popup (combo_box);
2466 switch (event->keyval)
2470 new_index = index + 1;
2471 while (new_index < items && !is_selectable (combo_box, new_index))
2473 if (new_index == items)
2478 new_index = index - 1;
2479 while (new_index >= 0 && !is_selectable (combo_box, new_index))
2485 case GDK_KP_Page_Up:
2489 while (new_index < items - 1 && !is_selectable (combo_box, new_index))
2493 case GDK_KP_Page_Down:
2496 new_index = items - 1;
2497 while (new_index > 0 && !is_selectable (combo_box, new_index))
2504 gtk_combo_box_set_active (combo_box, CLAMP (new_index, 0, items - 1));
2510 gtk_combo_box_menu_key_press (GtkWidget *widget,
2514 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
2515 guint state = event->state & gtk_accelerator_get_default_mod_mask ();
2517 if ((event->keyval == GDK_Up || event->keyval == GDK_KP_Up) &&
2518 state == GDK_MOD1_MASK)
2520 gtk_combo_box_popdown (combo_box);
2529 gtk_combo_box_list_key_press (GtkWidget *widget,
2533 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
2534 guint state = event->state & gtk_accelerator_get_default_mod_mask ();
2536 if (event->keyval == GDK_Escape ||
2537 ((event->keyval == GDK_Up || event->keyval == GDK_KP_Up) &&
2538 state == GDK_MOD1_MASK))
2540 /* reset active item -- this is incredibly lame and ugly */
2541 gtk_combo_box_set_active (combo_box,
2542 gtk_combo_box_get_active (combo_box));
2544 gtk_combo_box_popdown (combo_box);
2549 if (event->keyval == GDK_Return || event->keyval == GDK_KP_Enter ||
2550 event->keyval == GDK_space || event->keyval == GDK_KP_Space)
2554 GtkTreeModel *model = NULL;
2555 GtkTreeSelection *sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (combo_box->priv->tree_view));
2557 ret = gtk_tree_selection_get_selected (sel, &model, &iter);
2562 path = gtk_tree_model_get_path (model, &iter);
2565 gtk_combo_box_set_active (combo_box, gtk_tree_path_get_indices (path)[0]);
2566 gtk_tree_path_free (path);
2570 gtk_combo_box_popdown (combo_box);
2579 gtk_combo_box_list_row_changed (GtkTreeModel *model,
2584 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
2587 width = gtk_combo_box_calc_requested_width (combo_box, path);
2589 if (width > combo_box->priv->width)
2591 if (combo_box->priv->cell_view)
2593 gtk_widget_set_size_request (combo_box->priv->cell_view, width, -1);
2594 gtk_widget_queue_resize (combo_box->priv->cell_view);
2596 combo_box->priv->width = width;
2601 * GtkCellLayout implementation
2604 gtk_combo_box_cell_layout_pack_start (GtkCellLayout *layout,
2605 GtkCellRenderer *cell,
2608 ComboCellInfo *info;
2609 GtkComboBox *combo_box;
2612 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
2613 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
2615 combo_box = GTK_COMBO_BOX (layout);
2617 g_object_ref (G_OBJECT (cell));
2618 gtk_object_sink (GTK_OBJECT (cell));
2620 info = g_new0 (ComboCellInfo, 1);
2622 info->expand = expand;
2623 info->pack = GTK_PACK_START;
2625 combo_box->priv->cells = g_slist_append (combo_box->priv->cells, info);
2627 if (combo_box->priv->cell_view)
2628 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box->priv->cell_view),
2631 if (combo_box->priv->column)
2632 gtk_tree_view_column_pack_start (combo_box->priv->column, cell, expand);
2634 menu = combo_box->priv->popup_widget;
2635 if (GTK_IS_MENU (menu))
2639 list = gtk_container_get_children (GTK_CONTAINER (menu));
2640 for (i = list; i; i = i->next)
2644 if (GTK_IS_CELL_VIEW_MENU_ITEM (i->data))
2645 view = GTK_CELL_VIEW (GTK_BIN (i->data)->child);
2647 view = GTK_CELL_VIEW (i->data);
2649 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (view), cell, expand);
2656 gtk_combo_box_cell_layout_pack_end (GtkCellLayout *layout,
2657 GtkCellRenderer *cell,
2660 ComboCellInfo *info;
2661 GtkComboBox *combo_box;
2664 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
2665 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
2667 combo_box = GTK_COMBO_BOX (layout);
2669 g_object_ref (G_OBJECT (cell));
2670 gtk_object_sink (GTK_OBJECT (cell));
2672 info = g_new0 (ComboCellInfo, 1);
2674 info->expand = expand;
2675 info->pack = GTK_PACK_END;
2677 if (combo_box->priv->cell_view)
2678 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (combo_box->priv->cell_view),
2681 if (combo_box->priv->column)
2682 gtk_tree_view_column_pack_end (combo_box->priv->column, cell, expand);
2684 menu = combo_box->priv->popup_widget;
2685 if (GTK_IS_MENU (menu))
2689 list = gtk_container_get_children (GTK_CONTAINER (menu));
2690 for (i = list; i; i = i->next)
2694 if (GTK_IS_CELL_VIEW_MENU_ITEM (i->data))
2695 view = GTK_CELL_VIEW (GTK_BIN (i->data)->child);
2697 view = GTK_CELL_VIEW (i->data);
2699 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (view), cell, expand);
2706 gtk_combo_box_cell_layout_clear (GtkCellLayout *layout)
2709 GtkComboBox *combo_box;
2712 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
2714 combo_box = GTK_COMBO_BOX (layout);
2716 if (combo_box->priv->cell_view)
2717 gtk_cell_layout_clear (GTK_CELL_LAYOUT (combo_box->priv->cell_view));
2719 if (combo_box->priv->column)
2720 gtk_tree_view_column_clear (combo_box->priv->column);
2722 for (i = combo_box->priv->cells; i; i = i->next)
2724 ComboCellInfo *info = (ComboCellInfo *)i->data;
2726 gtk_combo_box_cell_layout_clear_attributes (layout, info->cell);
2727 g_object_unref (G_OBJECT (info->cell));
2731 g_slist_free (combo_box->priv->cells);
2732 combo_box->priv->cells = NULL;
2734 menu = combo_box->priv->popup_widget;
2735 if (GTK_IS_MENU (menu))
2739 list = gtk_container_get_children (GTK_CONTAINER (menu));
2740 for (i = list; i; i = i->next)
2744 if (GTK_IS_CELL_VIEW_MENU_ITEM (i->data))
2745 view = GTK_CELL_VIEW (GTK_BIN (i->data)->child);
2747 view = GTK_CELL_VIEW (i->data);
2749 gtk_cell_layout_clear (GTK_CELL_LAYOUT (view));
2756 gtk_combo_box_cell_layout_add_attribute (GtkCellLayout *layout,
2757 GtkCellRenderer *cell,
2758 const gchar *attribute,
2761 ComboCellInfo *info;
2762 GtkComboBox *combo_box;
2765 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
2766 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
2768 combo_box = GTK_COMBO_BOX (layout);
2770 info = gtk_combo_box_get_cell_info (combo_box, cell);
2772 info->attributes = g_slist_prepend (info->attributes,
2773 GINT_TO_POINTER (column));
2774 info->attributes = g_slist_prepend (info->attributes,
2775 g_strdup (attribute));
2777 if (combo_box->priv->cell_view)
2778 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo_box->priv->cell_view),
2779 cell, attribute, column);
2781 if (combo_box->priv->column)
2782 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo_box->priv->column),
2783 cell, attribute, column);
2785 menu = combo_box->priv->popup_widget;
2786 if (GTK_IS_MENU (menu))
2790 list = gtk_container_get_children (GTK_CONTAINER (menu));
2791 for (i = list; i; i = i->next)
2795 if (GTK_IS_CELL_VIEW_MENU_ITEM (i->data))
2796 view = GTK_CELL_VIEW (GTK_BIN (i->data)->child);
2798 view = GTK_CELL_VIEW (i->data);
2800 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (view), cell,
2806 gtk_widget_queue_resize (GTK_WIDGET (combo_box));
2810 gtk_combo_box_cell_layout_set_cell_data_func (GtkCellLayout *layout,
2811 GtkCellRenderer *cell,
2812 GtkCellLayoutDataFunc func,
2814 GDestroyNotify destroy)
2816 ComboCellInfo *info;
2817 GtkComboBox *combo_box;
2820 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
2822 combo_box = GTK_COMBO_BOX (layout);
2824 info = gtk_combo_box_get_cell_info (combo_box, cell);
2825 g_return_if_fail (info != NULL);
2829 GDestroyNotify d = info->destroy;
2831 info->destroy = NULL;
2832 d (info->func_data);
2836 info->func_data = func_data;
2837 info->destroy = destroy;
2839 if (combo_box->priv->cell_view)
2840 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo_box->priv->cell_view), cell, func, func_data, NULL);
2842 if (combo_box->priv->column)
2843 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo_box->priv->column), cell, func, func_data, NULL);
2845 menu = combo_box->priv->popup_widget;
2846 if (GTK_IS_MENU (menu))
2850 list = gtk_container_get_children (GTK_CONTAINER (menu));
2851 for (i = list; i; i = i->next)
2855 if (GTK_IS_CELL_VIEW_MENU_ITEM (i->data))
2856 view = GTK_CELL_VIEW (GTK_BIN (i->data)->child);
2858 view = GTK_CELL_VIEW (i->data);
2860 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (view), cell,
2861 func, func_data, NULL);
2866 gtk_widget_queue_resize (GTK_WIDGET (combo_box));
2870 gtk_combo_box_cell_layout_clear_attributes (GtkCellLayout *layout,
2871 GtkCellRenderer *cell)
2873 ComboCellInfo *info;
2874 GtkComboBox *combo_box;
2878 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
2879 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
2881 combo_box = GTK_COMBO_BOX (layout);
2883 info = gtk_combo_box_get_cell_info (combo_box, cell);
2884 g_return_if_fail (info != NULL);
2886 list = info->attributes;
2887 while (list && list->next)
2889 g_free (list->data);
2890 list = list->next->next;
2892 g_slist_free (info->attributes);
2893 info->attributes = NULL;
2895 if (combo_box->priv->cell_view)
2896 gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (combo_box->priv->cell_view), cell);
2898 if (combo_box->priv->column)
2899 gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (combo_box->priv->column), cell);
2901 menu = combo_box->priv->popup_widget;
2902 if (GTK_IS_MENU (menu))
2906 list = gtk_container_get_children (GTK_CONTAINER (menu));
2907 for (i = list; i; i = i->next)
2911 if (GTK_IS_CELL_VIEW_MENU_ITEM (i->data))
2912 view = GTK_CELL_VIEW (GTK_BIN (i->data)->child);
2914 view = GTK_CELL_VIEW (i->data);
2916 gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (view), cell);
2921 gtk_widget_queue_resize (GTK_WIDGET (combo_box));
2925 gtk_combo_box_cell_layout_reorder (GtkCellLayout *layout,
2926 GtkCellRenderer *cell,
2929 ComboCellInfo *info;
2930 GtkComboBox *combo_box;
2934 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
2935 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
2937 combo_box = GTK_COMBO_BOX (layout);
2939 info = gtk_combo_box_get_cell_info (combo_box, cell);
2941 g_return_if_fail (info != NULL);
2942 g_return_if_fail (position >= 0);
2944 link = g_slist_find (combo_box->priv->cells, info);
2946 g_return_if_fail (link != NULL);
2948 combo_box->priv->cells = g_slist_remove_link (combo_box->priv->cells, link);
2949 combo_box->priv->cells = g_slist_insert (combo_box->priv->cells, info,
2952 if (combo_box->priv->cell_view)
2953 gtk_cell_layout_reorder (GTK_CELL_LAYOUT (combo_box->priv->cell_view),
2956 if (combo_box->priv->column)
2957 gtk_cell_layout_reorder (GTK_CELL_LAYOUT (combo_box->priv->column),
2960 menu = combo_box->priv->popup_widget;
2961 if (GTK_IS_MENU (menu))
2965 list = gtk_container_get_children (GTK_CONTAINER (menu));
2966 for (i = list; i; i = i->next)
2970 if (GTK_IS_CELL_VIEW_MENU_ITEM (i->data))
2971 view = GTK_CELL_VIEW (GTK_BIN (i->data)->child);
2973 view = GTK_CELL_VIEW (i->data);
2975 gtk_cell_layout_reorder (GTK_CELL_LAYOUT (view), cell, position);
2980 gtk_widget_queue_draw (GTK_WIDGET (combo_box));
2988 * gtk_combo_box_new:
2990 * Creates a new empty #GtkComboBox.
2992 * Return value: A new #GtkComboBox.
2997 gtk_combo_box_new (void)
2999 return GTK_WIDGET (g_object_new (GTK_TYPE_COMBO_BOX, NULL));
3003 * gtk_combo_box_new_with_model:
3004 * @model: A #GtkTreeModel.
3006 * Creates a new #GtkComboBox with the model initialized to @model.
3008 * Return value: A new #GtkComboBox.
3013 gtk_combo_box_new_with_model (GtkTreeModel *model)
3015 GtkComboBox *combo_box;
3017 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
3019 combo_box = GTK_COMBO_BOX (g_object_new (GTK_TYPE_COMBO_BOX,
3023 return GTK_WIDGET (combo_box);
3027 * gtk_combo_box_set_wrap_width:
3028 * @combo_box: A #GtkComboBox.
3029 * @width: Preferred number of columns.
3031 * Sets the wrap width of @combo_box to be @width. The wrap width is basically
3032 * the preferred number of columns when you want to the popup to be layed out
3038 gtk_combo_box_set_wrap_width (GtkComboBox *combo_box,
3041 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
3042 g_return_if_fail (width >= 0);
3044 if (width != combo_box->priv->wrap_width)
3046 combo_box->priv->wrap_width = width;
3048 gtk_combo_box_check_appearance (combo_box);
3049 gtk_combo_box_relayout (combo_box);
3051 g_object_notify (G_OBJECT (combo_box), "wrap_width");
3056 * gtk_combo_box_set_row_span_column:
3057 * @combo_box: A #GtkComboBox.
3058 * @row_span: A column in the model passed during construction.
3060 * Sets the column with row span information for @combo_box to be @row_span.
3061 * The row span column contains integers which indicate how many rows
3062 * an item should span.
3067 gtk_combo_box_set_row_span_column (GtkComboBox *combo_box,
3072 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
3074 col = gtk_tree_model_get_n_columns (combo_box->priv->model);
3075 g_return_if_fail (row_span >= 0 && row_span < col);
3077 if (row_span != combo_box->priv->row_column)
3079 combo_box->priv->row_column = row_span;
3081 gtk_combo_box_relayout (combo_box);
3083 g_object_notify (G_OBJECT (combo_box), "row_span_column");
3088 * gtk_combo_box_set_column_span_column:
3089 * @combo_box: A #GtkComboBox.
3090 * @column_span: A column in the model passed during construction.
3092 * Sets the column with column span information for @combo_box to be
3093 * @column_span. The column span column contains integers which indicate
3094 * how many columns an item should span.
3099 gtk_combo_box_set_column_span_column (GtkComboBox *combo_box,
3104 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
3106 col = gtk_tree_model_get_n_columns (combo_box->priv->model);
3107 g_return_if_fail (column_span >= 0 && column_span < col);
3109 if (column_span != combo_box->priv->col_column)
3111 combo_box->priv->col_column = column_span;
3113 gtk_combo_box_relayout (combo_box);
3115 g_object_notify (G_OBJECT (combo_box), "column_span_column");
3120 * gtk_combo_box_get_active:
3121 * @combo_box: A #GtkComboBox.
3123 * Returns the index of the currently active item, or -1 if there's no
3126 * Return value: An integer which is the index of the currently active item, or
3127 * -1 if there's no active item.
3132 gtk_combo_box_get_active (GtkComboBox *combo_box)
3134 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), 0);
3136 return combo_box->priv->active_item;
3140 * gtk_combo_box_set_active:
3141 * @combo_box: A #GtkComboBox.
3142 * @index: An index in the model passed during construction, or -1 to have
3145 * Sets the active item of @combo_box to be the item at @index.
3150 gtk_combo_box_set_active (GtkComboBox *combo_box,
3153 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
3154 /* -1 means "no item selected" */
3155 g_return_if_fail (index >= -1);
3157 if (combo_box->priv->active_item == index)
3160 gtk_combo_box_set_active_internal (combo_box, index);
3164 gtk_combo_box_set_active_internal (GtkComboBox *combo_box,
3169 combo_box->priv->active_item = index;
3173 if (combo_box->priv->tree_view)
3174 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (combo_box->priv->tree_view)));
3177 GtkMenu *menu = GTK_MENU (combo_box->priv->popup_widget);
3179 if (GTK_IS_MENU (menu))
3180 gtk_menu_set_active (menu, -1);
3183 if (combo_box->priv->cell_view)
3184 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (combo_box->priv->cell_view), NULL);
3188 path = gtk_tree_path_new_from_indices (index, -1);
3190 if (combo_box->priv->tree_view)
3191 gtk_tree_view_set_cursor (GTK_TREE_VIEW (combo_box->priv->tree_view), path, NULL, FALSE);
3194 GtkMenu *menu = GTK_MENU (combo_box->priv->popup_widget);
3196 if (GTK_IS_MENU (menu))
3197 gtk_menu_set_active (GTK_MENU (menu), index);
3200 if (combo_box->priv->cell_view)
3201 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (combo_box->priv->cell_view), path);
3203 gtk_tree_path_free (path);
3206 g_signal_emit_by_name (combo_box, "changed", NULL, NULL);
3211 * gtk_combo_box_get_active_iter:
3212 * @combo_box: A #GtkComboBox
3213 * @iter: The uninitialized #GtkTreeIter.
3215 * Sets @iter to point to the current active item, if it exists.
3217 * Return value: %TRUE, if @iter was set
3222 gtk_combo_box_get_active_iter (GtkComboBox *combo_box,
3229 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE);
3231 active = gtk_combo_box_get_active (combo_box);
3235 path = gtk_tree_path_new_from_indices (active, -1);
3236 retval = gtk_tree_model_get_iter (gtk_combo_box_get_model (combo_box),
3238 gtk_tree_path_free (path);
3244 * gtk_combo_box_set_active_iter:
3245 * @combo_box: A #GtkComboBox
3246 * @iter: The #GtkTreeIter.
3248 * Sets the current active item to be the one referenced by @iter.
3249 * @iter must correspond to a path of depth one.
3254 gtk_combo_box_set_active_iter (GtkComboBox *combo_box,
3259 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
3261 path = gtk_tree_model_get_path (gtk_combo_box_get_model (combo_box), iter);
3262 g_return_if_fail (path != NULL);
3263 g_return_if_fail (gtk_tree_path_get_depth (path) == 1);
3265 gtk_combo_box_set_active (combo_box, gtk_tree_path_get_indices (path)[0]);
3266 gtk_tree_path_free (path);
3270 * gtk_combo_box_set_model:
3271 * @combo_box: A #GtkComboBox.
3272 * @model: A #GtkTreeModel.
3274 * Sets the model used by @combo_box to be @model. Will unset a
3275 * previously set model (if applicable).
3280 gtk_combo_box_set_model (GtkComboBox *combo_box,
3281 GtkTreeModel *model)
3283 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
3284 g_return_if_fail (GTK_IS_TREE_MODEL (model));
3286 if (model == combo_box->priv->model)
3289 if (combo_box->priv->model)
3290 gtk_combo_box_unset_model (combo_box);
3292 combo_box->priv->model = model;
3293 g_object_ref (G_OBJECT (combo_box->priv->model));
3295 combo_box->priv->inserted_id =
3296 g_signal_connect (combo_box->priv->model, "row_inserted",
3297 G_CALLBACK (gtk_combo_box_model_row_inserted),
3299 combo_box->priv->deleted_id =
3300 g_signal_connect (combo_box->priv->model, "row_deleted",
3301 G_CALLBACK (gtk_combo_box_model_row_deleted),
3303 combo_box->priv->reordered_id =
3304 g_signal_connect (combo_box->priv->model, "rows_reordered",
3305 G_CALLBACK (gtk_combo_box_model_rows_reordered),
3307 combo_box->priv->changed_id =
3308 g_signal_connect (combo_box->priv->model, "row_changed",
3309 G_CALLBACK (gtk_combo_box_model_row_changed),
3312 if (combo_box->priv->tree_view)
3315 gtk_tree_view_set_model (GTK_TREE_VIEW (combo_box->priv->tree_view),
3316 combo_box->priv->model);
3321 if (combo_box->priv->popup_widget)
3322 gtk_combo_box_menu_fill (combo_box);
3326 if (combo_box->priv->cell_view)
3327 gtk_cell_view_set_model (GTK_CELL_VIEW (combo_box->priv->cell_view),
3328 combo_box->priv->model);
3332 * gtk_combo_box_get_model
3333 * @combo_box: A #GtkComboBox.
3335 * Returns the #GtkTreeModel which is acting as data source for @combo_box.
3337 * Return value: A #GtkTreeModel which was passed during construction.
3342 gtk_combo_box_get_model (GtkComboBox *combo_box)
3344 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
3346 return combo_box->priv->model;
3350 /* convenience API for simple text combos */
3353 * gtk_combo_box_new_text:
3355 * Convenience function which constructs a new text combo box, which is a
3356 * #GtkComboBox just displaying strings. If you use this function to create
3357 * a text combo box, you should only manipulate its data source with the
3358 * following convenience functions: gtk_combo_box_append_text(),
3359 * gtk_combo_box_insert_text(), gtk_combo_box_prepend_text() and
3360 * gtk_combo_box_remove_text().
3362 * Return value: A new text combo box.
3367 gtk_combo_box_new_text (void)
3369 GtkWidget *combo_box;
3370 GtkCellRenderer *cell;
3371 GtkListStore *store;
3373 store = gtk_list_store_new (1, G_TYPE_STRING);
3375 combo_box = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));
3377 cell = gtk_cell_renderer_text_new ();
3378 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), cell, TRUE);
3379 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), cell,
3387 * gtk_combo_box_append_text:
3388 * @combo_box: A #GtkComboBox constructed using gtk_combo_box_new_text().
3391 * Appends @string to the list of strings stored in @combo_box. Note that
3392 * you can only use this function with combo boxes constructed with
3393 * gtk_combo_box_new_text().
3398 gtk_combo_box_append_text (GtkComboBox *combo_box,
3402 GtkListStore *store;
3404 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
3405 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
3406 g_return_if_fail (text != NULL);
3408 store = GTK_LIST_STORE (combo_box->priv->model);
3410 gtk_list_store_append (store, &iter);
3411 gtk_list_store_set (store, &iter, 0, text, -1);
3415 * gtk_combo_box_insert_text:
3416 * @combo_box: A #GtkComboBox constructed using gtk_combo_box_new_text().
3417 * @position: An index to insert @text.
3420 * Inserts @string at @position in the list of strings stored in @combo_box.
3421 * Note that you can only use this function with combo boxes constructed
3422 * with gtk_combo_box_new_text().
3427 gtk_combo_box_insert_text (GtkComboBox *combo_box,
3432 GtkListStore *store;
3434 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
3435 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
3436 g_return_if_fail (position >= 0);
3437 g_return_if_fail (text != NULL);
3439 store = GTK_LIST_STORE (combo_box->priv->model);
3441 gtk_list_store_insert (store, &iter, position);
3442 gtk_list_store_set (store, &iter, 0, text, -1);
3446 * gtk_combo_box_prepend_text:
3447 * @combo_box: A #GtkComboBox constructed with gtk_combo_box_new_text().
3450 * Prepends @string to the list of strings stored in @combo_box. Note that
3451 * you can only use this function with combo boxes constructed with
3452 * gtk_combo_box_new_text().
3457 gtk_combo_box_prepend_text (GtkComboBox *combo_box,
3461 GtkListStore *store;
3463 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
3464 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
3465 g_return_if_fail (text != NULL);
3467 store = GTK_LIST_STORE (combo_box->priv->model);
3469 gtk_list_store_prepend (store, &iter);
3470 gtk_list_store_set (store, &iter, 0, text, -1);
3474 * gtk_combo_box_remove_text:
3475 * @combo_box: A #GtkComboBox constructed with gtk_combo_box_new_text().
3476 * @position: Index of the item to remove.
3478 * Removes the string at @position from @combo_box. Note that you can only use
3479 * this function with combo boxes constructed with gtk_combo_box_new_text().
3484 gtk_combo_box_remove_text (GtkComboBox *combo_box,
3488 GtkListStore *store;
3490 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
3491 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
3492 g_return_if_fail (position >= 0);
3494 store = GTK_LIST_STORE (combo_box->priv->model);
3496 if (gtk_tree_model_iter_nth_child (combo_box->priv->model, &iter,
3498 gtk_list_store_remove (store, &iter);
3502 * gtk_combo_box_get_active_text:
3503 * @combo_box: A #GtkComboBox constructed with gtk_combo_box_new_text().
3505 * Returns the currently active string in @combo_box or %NULL if none
3506 * is selected. Note that you can only use this function with combo
3507 * boxes constructed with gtk_combo_box_new_text().
3509 * Returns: a newly allocated string containing the currently active text.
3514 gtk_combo_box_get_active_text (GtkComboBox *combo_box)
3519 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
3520 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
3522 if (gtk_combo_box_get_active_iter (combo_box, &iter))
3523 gtk_tree_model_get (combo_box->priv->model, &iter,
3530 gtk_combo_box_mnemonic_activate (GtkWidget *widget,
3531 gboolean group_cycling)
3533 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
3535 gtk_widget_grab_focus (combo_box->priv->button);
3541 gtk_combo_box_destroy (GtkObject *object)
3543 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
3545 combo_box->priv->destroying = 1;
3547 GTK_OBJECT_CLASS (parent_class)->destroy (object);
3549 combo_box->priv->cell_view = NULL;
3551 combo_box->priv->destroying = 0;
3555 gtk_combo_box_finalize (GObject *object)
3557 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
3560 if (GTK_IS_MENU (combo_box->priv->popup_widget))
3561 gtk_combo_box_menu_destroy (combo_box);
3563 if (GTK_IS_TREE_VIEW (combo_box->priv->tree_view))
3564 gtk_combo_box_list_destroy (combo_box);
3566 if (combo_box->priv->popup_window)
3567 gtk_widget_destroy (combo_box->priv->popup_window);
3569 gtk_combo_box_unset_model (combo_box);
3571 if (combo_box->priv->model)
3572 g_object_unref (combo_box->priv->model);
3574 for (i = combo_box->priv->cells; i; i = i->next)
3576 ComboCellInfo *info = (ComboCellInfo *)i->data;
3577 GSList *list = info->attributes;
3580 info->destroy (info->func_data);
3582 while (list && list->next)
3584 g_free (list->data);
3585 list = list->next->next;
3587 g_slist_free (info->attributes);
3589 g_object_unref (G_OBJECT (info->cell));
3592 g_slist_free (combo_box->priv->cells);
3594 G_OBJECT_CLASS (parent_class)->finalize (object);
3598 gtk_combo_box_set_selection_func (GtkComboBox *combo_box,
3599 GtkComboBoxSelectionFunc func,
3601 GDestroyNotify destroy)
3603 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
3605 if (combo_box->priv->selection_destroy)
3606 combo_box->priv->selection_destroy (combo_box->priv->selection_data);
3608 combo_box->priv->selection_func = func;
3609 combo_box->priv->selection_data = func_data;
3610 combo_box->priv->selection_destroy = destroy;