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 "gtkeventbox.h"
31 #include "gtkliststore.h"
34 #include "gtkscrolledwindow.h"
35 #include "gtkseparatormenuitem.h"
36 #include "gtktearoffmenuitem.h"
37 #include "gtktogglebutton.h"
38 #include "gtktreeselection.h"
39 #include "gtkvseparator.h"
40 #include "gtkwindow.h"
41 #include "gtkprivate.h"
43 #include <gdk/gdkkeysyms.h>
45 #include <gobject/gvaluecollector.h>
50 #include "gtkmarshalers.h"
53 #include "gtktreeprivate.h"
56 /* WELCOME, to THE house of evil code */
58 typedef struct _ComboCellInfo ComboCellInfo;
61 GtkCellRenderer *cell;
64 GtkCellLayoutDataFunc func;
66 GDestroyNotify destroy;
72 #define GTK_COMBO_BOX_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_COMBO_BOX, GtkComboBoxPrivate))
74 struct _GtkComboBoxPrivate
83 GtkTreeRowReference *active_row;
86 GtkTreeViewColumn *column;
89 GtkWidget *cell_view_frame;
96 GtkWidget *popup_widget;
97 GtkWidget *popup_window;
98 GtkWidget *popup_frame;
99 GtkWidget *scrolled_window;
107 guint resize_idle_id;
112 guint popup_in_progress : 1;
113 guint destroying : 1;
114 guint add_tearoffs : 1;
116 guint is_cell_renderer : 1;
117 guint editing_canceled : 1;
118 guint auto_scroll : 1;
119 guint focus_on_click : 1;
121 GtkTreeViewRowSeparatorFunc row_separator_func;
122 gpointer row_separator_data;
123 GtkDestroyNotify row_separator_destroy;
125 gchar *tearoff_title;
128 /* While debugging this evil code, I have learned that
129 * there are actually 4 modes to this widget, which can
130 * be characterized as follows
132 * 1) menu mode, no child added
135 * cell_view -> GtkCellView, regular child
136 * cell_view_frame -> NULL
137 * button -> GtkToggleButton set_parent to combo
138 * arrow -> GtkArrow set_parent to button
139 * separator -> GtkVSepator set_parent to button
140 * popup_widget -> GtkMenu
141 * popup_window -> NULL
142 * popup_frame -> NULL
143 * scrolled_window -> NULL
145 * 2) menu mode, child added
149 * cell_view_frame -> NULL
150 * button -> GtkToggleButton set_parent to combo
151 * arrow -> GtkArrow, child of button
153 * popup_widget -> GtkMenu
154 * popup_window -> NULL
155 * popup_frame -> NULL
156 * scrolled_window -> NULL
158 * 3) list mode, no child added
160 * tree_view -> GtkTreeView, child of popup_frame
161 * cell_view -> GtkCellView, regular child
162 * cell_view_frame -> GtkFrame, set parent to combo
163 * button -> GtkToggleButton, set_parent to combo
164 * arrow -> GtkArrow, child of button
166 * popup_widget -> tree_view
167 * popup_window -> GtkWindow
168 * popup_frame -> GtkFrame, child of popup_window
169 * scrolled_window -> GtkScrolledWindow, child of popup_frame
171 * 4) list mode, child added
173 * tree_view -> GtkTreeView, child of popup_frame
175 * cell_view_frame -> NULL
176 * button -> GtkToggleButton, set_parent to combo
177 * arrow -> GtkArrow, child of button
179 * popup_widget -> tree_view
180 * popup_window -> GtkWindow
181 * popup_frame -> GtkFrame, child of popup_window
182 * scrolled_window -> GtkScrolledWindow, child of popup_frame
197 PROP_ROW_SPAN_COLUMN,
198 PROP_COLUMN_SPAN_COLUMN,
206 static GtkBinClass *parent_class = NULL;
207 static guint combo_box_signals[LAST_SIGNAL] = {0,};
209 #define BONUS_PADDING 4
210 #define SCROLL_TIME 100
214 static void gtk_combo_box_class_init (GtkComboBoxClass *klass);
215 static void gtk_combo_box_cell_layout_init (GtkCellLayoutIface *iface);
216 static void gtk_combo_box_cell_editable_init (GtkCellEditableIface *iface);
217 static void gtk_combo_box_init (GtkComboBox *combo_box);
218 static void gtk_combo_box_finalize (GObject *object);
219 static void gtk_combo_box_destroy (GtkObject *object);
221 static void gtk_combo_box_set_property (GObject *object,
225 static void gtk_combo_box_get_property (GObject *object,
230 static void gtk_combo_box_state_changed (GtkWidget *widget,
231 GtkStateType previous);
232 static void gtk_combo_box_grab_focus (GtkWidget *widget);
233 static void gtk_combo_box_style_set (GtkWidget *widget,
235 static void gtk_combo_box_button_toggled (GtkWidget *widget,
237 static void gtk_combo_box_button_state_changed (GtkWidget *widget,
238 GtkStateType previous,
240 static void gtk_combo_box_add (GtkContainer *container,
242 static void gtk_combo_box_remove (GtkContainer *container,
245 static ComboCellInfo *gtk_combo_box_get_cell_info (GtkComboBox *combo_box,
246 GtkCellRenderer *cell);
248 static void gtk_combo_box_menu_show (GtkWidget *menu,
250 static void gtk_combo_box_menu_hide (GtkWidget *menu,
253 static void gtk_combo_box_set_popup_widget (GtkComboBox *combo_box,
255 static void gtk_combo_box_menu_position_below (GtkMenu *menu,
260 static void gtk_combo_box_menu_position_over (GtkMenu *menu,
265 static void gtk_combo_box_menu_position (GtkMenu *menu,
271 static gint gtk_combo_box_calc_requested_width (GtkComboBox *combo_box,
273 static void gtk_combo_box_remeasure (GtkComboBox *combo_box);
275 static void gtk_combo_box_unset_model (GtkComboBox *combo_box);
277 static void gtk_combo_box_size_request (GtkWidget *widget,
278 GtkRequisition *requisition);
279 static void gtk_combo_box_size_allocate (GtkWidget *widget,
280 GtkAllocation *allocation);
281 static void gtk_combo_box_forall (GtkContainer *container,
282 gboolean include_internals,
283 GtkCallback callback,
284 gpointer callback_data);
285 static gboolean gtk_combo_box_expose_event (GtkWidget *widget,
286 GdkEventExpose *event);
287 static gboolean gtk_combo_box_scroll_event (GtkWidget *widget,
288 GdkEventScroll *event);
289 static void gtk_combo_box_set_active_internal (GtkComboBox *combo_box,
291 static gboolean gtk_combo_box_key_press (GtkWidget *widget,
295 static void gtk_combo_box_check_appearance (GtkComboBox *combo_box);
296 static gchar * gtk_combo_box_real_get_active_text (GtkComboBox *combo_box);
298 /* listening to the model */
299 static void gtk_combo_box_model_row_inserted (GtkTreeModel *model,
303 static void gtk_combo_box_model_row_deleted (GtkTreeModel *model,
306 static void gtk_combo_box_model_rows_reordered (GtkTreeModel *model,
311 static void gtk_combo_box_model_row_changed (GtkTreeModel *model,
315 static void gtk_combo_box_model_row_expanded (GtkTreeModel *model,
321 static void gtk_combo_box_list_position (GtkComboBox *combo_box,
326 static void gtk_combo_box_list_setup (GtkComboBox *combo_box);
327 static void gtk_combo_box_list_destroy (GtkComboBox *combo_box);
329 static gboolean gtk_combo_box_list_button_released (GtkWidget *widget,
330 GdkEventButton *event,
332 static gboolean gtk_combo_box_list_key_press (GtkWidget *widget,
335 static gboolean gtk_combo_box_list_enter_notify (GtkWidget *widget,
336 GdkEventCrossing *event,
338 static void gtk_combo_box_list_auto_scroll (GtkComboBox *combo,
341 static gboolean gtk_combo_box_list_scroll_timeout (GtkComboBox *combo);
342 static gboolean gtk_combo_box_list_button_pressed (GtkWidget *widget,
343 GdkEventButton *event,
346 static void gtk_combo_box_list_row_changed (GtkTreeModel *model,
350 static void gtk_combo_box_list_popup_resize (GtkComboBox *combo_box);
353 static void gtk_combo_box_menu_setup (GtkComboBox *combo_box,
354 gboolean add_children);
355 static void gtk_combo_box_menu_fill (GtkComboBox *combo_box);
356 static void gtk_combo_box_menu_fill_level (GtkComboBox *combo_box,
359 static void gtk_combo_box_update_title (GtkComboBox *combo_box);
360 static void gtk_combo_box_menu_destroy (GtkComboBox *combo_box);
362 static void gtk_combo_box_relayout_item (GtkComboBox *combo_box,
366 static void gtk_combo_box_relayout (GtkComboBox *combo_box);
368 static gboolean gtk_combo_box_menu_button_press (GtkWidget *widget,
369 GdkEventButton *event,
371 static void gtk_combo_box_menu_item_activate (GtkWidget *item,
373 static void gtk_combo_box_menu_row_inserted (GtkTreeModel *model,
377 static void gtk_combo_box_menu_row_deleted (GtkTreeModel *model,
380 static void gtk_combo_box_menu_rows_reordered (GtkTreeModel *model,
385 static void gtk_combo_box_menu_row_changed (GtkTreeModel *model,
389 static gboolean gtk_combo_box_menu_key_press (GtkWidget *widget,
392 static void gtk_combo_box_menu_popup (GtkComboBox *combo_box,
394 guint32 activate_time);
395 static GtkWidget *gtk_cell_view_menu_item_new (GtkComboBox *combo_box,
400 static void gtk_combo_box_cell_layout_pack_start (GtkCellLayout *layout,
401 GtkCellRenderer *cell,
403 static void gtk_combo_box_cell_layout_pack_end (GtkCellLayout *layout,
404 GtkCellRenderer *cell,
406 static void gtk_combo_box_cell_layout_clear (GtkCellLayout *layout);
407 static void gtk_combo_box_cell_layout_add_attribute (GtkCellLayout *layout,
408 GtkCellRenderer *cell,
409 const gchar *attribute,
411 static void gtk_combo_box_cell_layout_set_cell_data_func (GtkCellLayout *layout,
412 GtkCellRenderer *cell,
413 GtkCellLayoutDataFunc func,
415 GDestroyNotify destroy);
416 static void gtk_combo_box_cell_layout_clear_attributes (GtkCellLayout *layout,
417 GtkCellRenderer *cell);
418 static void gtk_combo_box_cell_layout_reorder (GtkCellLayout *layout,
419 GtkCellRenderer *cell,
421 static gboolean gtk_combo_box_mnemonic_activate (GtkWidget *widget,
422 gboolean group_cycling);
424 static void gtk_combo_box_sync_cells (GtkComboBox *combo_box,
425 GtkCellLayout *cell_layout);
426 static void combo_cell_data_func (GtkCellLayout *cell_layout,
427 GtkCellRenderer *cell,
428 GtkTreeModel *tree_model,
431 static void gtk_combo_box_child_show (GtkWidget *widget,
433 static void gtk_combo_box_child_hide (GtkWidget *widget,
437 /* GtkCellEditable method implementations */
438 static void gtk_combo_box_start_editing (GtkCellEditable *cell_editable,
443 gtk_combo_box_get_type (void)
445 static GType combo_box_type = 0;
449 static const GTypeInfo combo_box_info =
451 sizeof (GtkComboBoxClass),
452 NULL, /* base_init */
453 NULL, /* base_finalize */
454 (GClassInitFunc) gtk_combo_box_class_init,
455 NULL, /* class_finalize */
456 NULL, /* class_data */
457 sizeof (GtkComboBox),
459 (GInstanceInitFunc) gtk_combo_box_init
462 static const GInterfaceInfo cell_layout_info =
464 (GInterfaceInitFunc) gtk_combo_box_cell_layout_init,
469 static const GInterfaceInfo cell_editable_info =
471 (GInterfaceInitFunc) gtk_combo_box_cell_editable_init,
476 combo_box_type = g_type_register_static (GTK_TYPE_BIN,
481 g_type_add_interface_static (combo_box_type,
482 GTK_TYPE_CELL_LAYOUT,
486 g_type_add_interface_static (combo_box_type,
487 GTK_TYPE_CELL_EDITABLE,
488 &cell_editable_info);
493 return combo_box_type;
498 gtk_combo_box_class_init (GtkComboBoxClass *klass)
500 GObjectClass *object_class;
501 GtkObjectClass *gtk_object_class;
502 GtkContainerClass *container_class;
503 GtkWidgetClass *widget_class;
505 klass->get_active_text = gtk_combo_box_real_get_active_text;
507 container_class = (GtkContainerClass *)klass;
508 container_class->forall = gtk_combo_box_forall;
509 container_class->add = gtk_combo_box_add;
510 container_class->remove = gtk_combo_box_remove;
512 widget_class = (GtkWidgetClass *)klass;
513 widget_class->size_allocate = gtk_combo_box_size_allocate;
514 widget_class->size_request = gtk_combo_box_size_request;
515 widget_class->expose_event = gtk_combo_box_expose_event;
516 widget_class->scroll_event = gtk_combo_box_scroll_event;
517 widget_class->mnemonic_activate = gtk_combo_box_mnemonic_activate;
518 widget_class->grab_focus = gtk_combo_box_grab_focus;
519 widget_class->style_set = gtk_combo_box_style_set;
520 widget_class->state_changed = gtk_combo_box_state_changed;
522 gtk_object_class = (GtkObjectClass *)klass;
523 gtk_object_class->destroy = gtk_combo_box_destroy;
525 object_class = (GObjectClass *)klass;
526 object_class->finalize = gtk_combo_box_finalize;
527 object_class->set_property = gtk_combo_box_set_property;
528 object_class->get_property = gtk_combo_box_get_property;
530 parent_class = g_type_class_peek_parent (klass);
534 * GtkComboBox::changed:
535 * @widget: the object which received the signal
537 * The changed signal gets emitted when the active
538 * item is changed. The can be due to the user selecting
539 * a different item from the list, or due to a
540 * call to gtk_combo_box_set_active_iter().
544 combo_box_signals[CHANGED] =
545 g_signal_new (I_("changed"),
546 G_OBJECT_CLASS_TYPE (klass),
548 G_STRUCT_OFFSET (GtkComboBoxClass, changed),
550 g_cclosure_marshal_VOID__VOID,
553 combo_box_signals[POPUP_SHOW] =
554 g_signal_new ("popup-show",
555 G_OBJECT_CLASS_TYPE (klass),
559 g_cclosure_marshal_VOID__VOID,
562 combo_box_signals[POPUP_HIDE] =
563 g_signal_new ("popup-hide",
564 G_OBJECT_CLASS_TYPE (klass),
568 g_cclosure_marshal_VOID__VOID,
576 * The model from which the combo box takes the values shown
581 g_object_class_install_property (object_class,
583 g_param_spec_object ("model",
584 P_("ComboBox model"),
585 P_("The model for the combo box"),
587 GTK_PARAM_READWRITE));
590 * GtkComboBox:wrap-width:
592 * If wrap-width is set to a positive value, the list will be
593 * displayed in multiple columns, the number of columns is
594 * determined by wrap-width.
598 g_object_class_install_property (object_class,
600 g_param_spec_int ("wrap-width",
602 P_("Wrap width for laying out the items in a grid"),
606 GTK_PARAM_READWRITE));
610 * GtkComboBox:row-span-column:
612 * If this is set to a non-negative value, it must be the index of a column
613 * of type %G_TYPE_INT in the model.
615 * The values of that column are used to determine how many rows a value
616 * in the list will span. Therefore, the values in the model column pointed
617 * to by this property must be greater than zero and not larger than wrap-width.
621 g_object_class_install_property (object_class,
622 PROP_ROW_SPAN_COLUMN,
623 g_param_spec_int ("row-span-column",
624 P_("Row span column"),
625 P_("TreeModel column containing the row span values"),
629 GTK_PARAM_READWRITE));
633 * GtkComboBox:column-span-column:
635 * If this is set to a non-negative value, it must be the index of a column
636 * of type %G_TYPE_INT in the model.
638 * The values of that column are used to determine how many columns a value
639 * in the list will span.
643 g_object_class_install_property (object_class,
644 PROP_COLUMN_SPAN_COLUMN,
645 g_param_spec_int ("column-span-column",
646 P_("Column span column"),
647 P_("TreeModel column containing the column span values"),
651 GTK_PARAM_READWRITE));
655 * GtkComboBox:active:
657 * The item which is currently active. If the model is a non-flat treemodel,
658 * and the active item is not an immediate child of the root of the tree,
659 * this property has the value <literal>gtk_tree_path_get_indices (path)[0]</literal>,
660 * where <literal>path</literal> is the #GtkTreePath of the active item.
664 g_object_class_install_property (object_class,
666 g_param_spec_int ("active",
668 P_("The item which is currently active"),
672 GTK_PARAM_READWRITE));
675 * GtkComboBox:add-tearoffs:
677 * The add-tearoffs property controls whether generated menus
678 * have tearoff menu items.
680 * Note that this only affects menu style combo boxes.
684 g_object_class_install_property (object_class,
686 g_param_spec_boolean ("add-tearoffs",
687 P_("Add tearoffs to menus"),
688 P_("Whether dropdowns should have a tearoff menu item"),
690 GTK_PARAM_READWRITE));
693 * GtkComboBox:has-frame:
695 * The has-frame property controls whether a frame
696 * is drawn around the entry.
700 g_object_class_install_property (object_class,
702 g_param_spec_boolean ("has-frame",
704 P_("Whether the combo box draws a frame around the child"),
706 GTK_PARAM_READWRITE));
708 g_object_class_install_property (object_class,
710 g_param_spec_boolean ("focus-on-click",
711 P_("Focus on click"),
712 P_("Whether the combo box grabs focus when it is clicked with the mouse"),
714 GTK_PARAM_READWRITE));
717 * GtkComboBox:tearoff-title:
719 * A title that may be displayed by the window manager
720 * when the popup is torn-off.
724 g_object_class_install_property (object_class,
726 g_param_spec_string ("tearoff-title",
728 P_("A title that may be displayed by the window manager when the popup is torn-off"),
730 GTK_PARAM_READWRITE));
733 gtk_widget_class_install_style_property (widget_class,
734 g_param_spec_boolean ("appears-as-list",
735 P_("Appears as list"),
736 P_("Whether dropdowns should look like lists rather than menus"),
738 GTK_PARAM_READABLE));
740 g_type_class_add_private (object_class, sizeof (GtkComboBoxPrivate));
744 gtk_combo_box_cell_layout_init (GtkCellLayoutIface *iface)
746 iface->pack_start = gtk_combo_box_cell_layout_pack_start;
747 iface->pack_end = gtk_combo_box_cell_layout_pack_end;
748 iface->clear = gtk_combo_box_cell_layout_clear;
749 iface->add_attribute = gtk_combo_box_cell_layout_add_attribute;
750 iface->set_cell_data_func = gtk_combo_box_cell_layout_set_cell_data_func;
751 iface->clear_attributes = gtk_combo_box_cell_layout_clear_attributes;
752 iface->reorder = gtk_combo_box_cell_layout_reorder;
756 gtk_combo_box_cell_editable_init (GtkCellEditableIface *iface)
758 iface->start_editing = gtk_combo_box_start_editing;
762 gtk_combo_box_init (GtkComboBox *combo_box)
764 combo_box->priv = GTK_COMBO_BOX_GET_PRIVATE (combo_box);
766 combo_box->priv->cell_view = gtk_cell_view_new ();
767 gtk_widget_set_parent (combo_box->priv->cell_view, GTK_WIDGET (combo_box));
768 GTK_BIN (combo_box)->child = combo_box->priv->cell_view;
769 gtk_widget_show (combo_box->priv->cell_view);
771 combo_box->priv->width = 0;
772 combo_box->priv->wrap_width = 0;
774 combo_box->priv->active_row = NULL;
775 combo_box->priv->col_column = -1;
776 combo_box->priv->row_column = -1;
778 combo_box->priv->add_tearoffs = FALSE;
779 combo_box->priv->has_frame = TRUE;
780 combo_box->priv->is_cell_renderer = FALSE;
781 combo_box->priv->editing_canceled = FALSE;
782 combo_box->priv->auto_scroll = FALSE;
783 combo_box->priv->focus_on_click = TRUE;
785 gtk_combo_box_check_appearance (combo_box);
789 gtk_combo_box_set_property (GObject *object,
794 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
799 gtk_combo_box_set_model (combo_box, g_value_get_object (value));
802 case PROP_WRAP_WIDTH:
803 gtk_combo_box_set_wrap_width (combo_box, g_value_get_int (value));
806 case PROP_ROW_SPAN_COLUMN:
807 gtk_combo_box_set_row_span_column (combo_box, g_value_get_int (value));
810 case PROP_COLUMN_SPAN_COLUMN:
811 gtk_combo_box_set_column_span_column (combo_box, g_value_get_int (value));
815 gtk_combo_box_set_active (combo_box, g_value_get_int (value));
818 case PROP_ADD_TEAROFFS:
819 gtk_combo_box_set_add_tearoffs (combo_box, g_value_get_boolean (value));
823 combo_box->priv->has_frame = g_value_get_boolean (value);
826 case PROP_FOCUS_ON_CLICK:
827 gtk_combo_box_set_focus_on_click (combo_box,
828 g_value_get_boolean (value));
831 case PROP_TEAROFF_TITLE:
832 gtk_combo_box_set_title (combo_box, g_value_get_string (value));
841 gtk_combo_box_get_property (GObject *object,
846 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
851 g_value_set_object (value, combo_box->priv->model);
854 case PROP_WRAP_WIDTH:
855 g_value_set_int (value, combo_box->priv->wrap_width);
858 case PROP_ROW_SPAN_COLUMN:
859 g_value_set_int (value, combo_box->priv->row_column);
862 case PROP_COLUMN_SPAN_COLUMN:
863 g_value_set_int (value, combo_box->priv->col_column);
867 g_value_set_int (value, gtk_combo_box_get_active (combo_box));
870 case PROP_ADD_TEAROFFS:
871 g_value_set_boolean (value, gtk_combo_box_get_add_tearoffs (combo_box));
875 g_value_set_boolean (value, combo_box->priv->has_frame);
878 case PROP_FOCUS_ON_CLICK:
879 g_value_set_boolean (value, combo_box->priv->focus_on_click);
882 case PROP_TEAROFF_TITLE:
883 g_value_set_string (value, gtk_combo_box_get_title (combo_box));
887 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
893 gtk_combo_box_state_changed (GtkWidget *widget,
894 GtkStateType previous)
896 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
898 if (GTK_WIDGET_REALIZED (widget))
900 if (combo_box->priv->tree_view && combo_box->priv->cell_view)
901 gtk_cell_view_set_background_color (GTK_CELL_VIEW (combo_box->priv->cell_view),
902 &widget->style->base[GTK_WIDGET_STATE (widget)]);
905 gtk_widget_queue_draw (widget);
909 gtk_combo_box_button_state_changed (GtkWidget *widget,
910 GtkStateType previous,
913 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
915 if (GTK_WIDGET_REALIZED (widget))
917 if (!combo_box->priv->tree_view && combo_box->priv->cell_view)
919 if ((GTK_WIDGET_STATE (widget) == GTK_STATE_INSENSITIVE) !=
920 (GTK_WIDGET_STATE (combo_box->priv->cell_view) == GTK_STATE_INSENSITIVE))
921 gtk_widget_set_sensitive (combo_box->priv->cell_view, GTK_WIDGET_SENSITIVE (widget));
923 gtk_widget_set_state (combo_box->priv->cell_view,
924 GTK_WIDGET_STATE (widget));
929 gtk_widget_queue_draw (widget);
933 gtk_combo_box_check_appearance (GtkComboBox *combo_box)
935 gboolean appears_as_list;
937 /* if wrap_width > 0, then we are in grid-mode and forced to use
940 if (combo_box->priv->wrap_width)
941 appears_as_list = FALSE;
943 gtk_widget_style_get (GTK_WIDGET (combo_box),
944 "appears-as-list", &appears_as_list,
949 /* Destroy all the menu mode widgets, if they exist. */
950 if (GTK_IS_MENU (combo_box->priv->popup_widget))
951 gtk_combo_box_menu_destroy (combo_box);
953 /* Create the list mode widgets, if they don't already exist. */
954 if (!GTK_IS_TREE_VIEW (combo_box->priv->tree_view))
955 gtk_combo_box_list_setup (combo_box);
959 /* Destroy all the list mode widgets, if they exist. */
960 if (GTK_IS_TREE_VIEW (combo_box->priv->tree_view))
961 gtk_combo_box_list_destroy (combo_box);
963 /* Create the menu mode widgets, if they don't already exist. */
964 if (!GTK_IS_MENU (combo_box->priv->popup_widget))
965 gtk_combo_box_menu_setup (combo_box, TRUE);
970 gtk_combo_box_style_set (GtkWidget *widget,
973 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
975 gtk_combo_box_check_appearance (combo_box);
977 if (combo_box->priv->tree_view && combo_box->priv->cell_view)
978 gtk_cell_view_set_background_color (GTK_CELL_VIEW (combo_box->priv->cell_view),
979 &widget->style->base[GTK_WIDGET_STATE (widget)]);
983 gtk_combo_box_button_toggled (GtkWidget *widget,
986 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
988 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
990 if (!combo_box->priv->popup_in_progress)
991 gtk_combo_box_popup (combo_box);
994 gtk_combo_box_popdown (combo_box);
998 gtk_combo_box_add (GtkContainer *container,
1001 GtkComboBox *combo_box = GTK_COMBO_BOX (container);
1003 if (combo_box->priv->cell_view && combo_box->priv->cell_view->parent)
1005 gtk_widget_unparent (combo_box->priv->cell_view);
1006 GTK_BIN (container)->child = NULL;
1007 gtk_widget_queue_resize (GTK_WIDGET (container));
1010 gtk_widget_set_parent (widget, GTK_WIDGET (container));
1011 GTK_BIN (container)->child = widget;
1013 if (combo_box->priv->cell_view &&
1014 widget != combo_box->priv->cell_view)
1016 /* since the cell_view was unparented, it's gone now */
1017 combo_box->priv->cell_view = NULL;
1019 if (!combo_box->priv->tree_view && combo_box->priv->separator)
1021 gtk_container_remove (GTK_CONTAINER (combo_box->priv->separator->parent),
1022 combo_box->priv->separator);
1023 combo_box->priv->separator = NULL;
1025 gtk_widget_queue_resize (GTK_WIDGET (container));
1027 else if (combo_box->priv->cell_view_frame)
1029 gtk_widget_unparent (combo_box->priv->cell_view_frame);
1030 combo_box->priv->cell_view_frame = NULL;
1031 combo_box->priv->box = NULL;
1037 gtk_combo_box_remove (GtkContainer *container,
1040 GtkComboBox *combo_box = GTK_COMBO_BOX (container);
1042 gboolean appears_as_list;
1044 gtk_widget_unparent (widget);
1045 GTK_BIN (container)->child = NULL;
1047 if (combo_box->priv->destroying)
1050 gtk_widget_queue_resize (GTK_WIDGET (container));
1052 if (!combo_box->priv->tree_view)
1053 appears_as_list = FALSE;
1055 appears_as_list = TRUE;
1057 if (appears_as_list)
1058 gtk_combo_box_list_destroy (combo_box);
1059 else if (GTK_IS_MENU (combo_box->priv->popup_widget))
1061 gtk_combo_box_menu_destroy (combo_box);
1062 gtk_menu_detach (GTK_MENU (combo_box->priv->popup_widget));
1063 combo_box->priv->popup_widget = NULL;
1066 if (!combo_box->priv->cell_view)
1068 combo_box->priv->cell_view = gtk_cell_view_new ();
1069 gtk_widget_set_parent (combo_box->priv->cell_view, GTK_WIDGET (container));
1070 GTK_BIN (container)->child = combo_box->priv->cell_view;
1072 gtk_widget_show (combo_box->priv->cell_view);
1073 gtk_cell_view_set_model (GTK_CELL_VIEW (combo_box->priv->cell_view),
1074 combo_box->priv->model);
1075 gtk_combo_box_sync_cells (combo_box, GTK_CELL_LAYOUT (combo_box->priv->cell_view));
1079 if (appears_as_list)
1080 gtk_combo_box_list_setup (combo_box);
1082 gtk_combo_box_menu_setup (combo_box, TRUE);
1084 if (gtk_tree_row_reference_valid (combo_box->priv->active_row))
1086 path = gtk_tree_row_reference_get_path (combo_box->priv->active_row);
1087 gtk_combo_box_set_active_internal (combo_box, path);
1088 gtk_tree_path_free (path);
1091 gtk_combo_box_set_active_internal (combo_box, NULL);
1094 static ComboCellInfo *
1095 gtk_combo_box_get_cell_info (GtkComboBox *combo_box,
1096 GtkCellRenderer *cell)
1100 for (i = combo_box->priv->cells; i; i = i->next)
1102 ComboCellInfo *info = (ComboCellInfo *)i->data;
1104 if (info && info->cell == cell)
1112 gtk_combo_box_menu_show (GtkWidget *menu,
1115 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
1117 gtk_combo_box_child_show (menu, user_data);
1119 combo_box->priv->popup_in_progress = TRUE;
1120 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
1122 combo_box->priv->popup_in_progress = FALSE;
1126 gtk_combo_box_menu_hide (GtkWidget *menu,
1129 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
1131 gtk_combo_box_child_hide(menu,user_data);
1133 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
1138 gtk_combo_box_detacher (GtkWidget *widget,
1141 GtkComboBox *combo_box;
1143 g_return_if_fail (GTK_IS_COMBO_BOX (widget));
1145 combo_box = GTK_COMBO_BOX (widget);
1146 g_return_if_fail (combo_box->priv->popup_widget == (GtkWidget*) menu);
1148 g_signal_handlers_disconnect_by_func (menu->toplevel,
1149 gtk_combo_box_menu_show,
1151 g_signal_handlers_disconnect_by_func (menu->toplevel,
1152 gtk_combo_box_menu_hide,
1155 combo_box->priv->popup_widget = NULL;
1159 gtk_combo_box_set_popup_widget (GtkComboBox *combo_box,
1162 if (GTK_IS_MENU (combo_box->priv->popup_widget))
1164 gtk_menu_detach (GTK_MENU (combo_box->priv->popup_widget));
1165 combo_box->priv->popup_widget = NULL;
1167 else if (combo_box->priv->popup_widget)
1169 gtk_container_remove (GTK_CONTAINER (combo_box->priv->popup_frame),
1170 combo_box->priv->popup_widget);
1171 g_object_unref (combo_box->priv->popup_widget);
1172 combo_box->priv->popup_widget = NULL;
1175 if (GTK_IS_MENU (popup))
1177 if (combo_box->priv->popup_window)
1179 gtk_widget_destroy (combo_box->priv->popup_window);
1180 combo_box->priv->popup_window = NULL;
1181 combo_box->priv->popup_frame = NULL;
1184 combo_box->priv->popup_widget = popup;
1187 * Note that we connect to show/hide on the toplevel, not the
1188 * menu itself, since the menu is not shown/hidden when it is
1189 * popped up while torn-off.
1191 g_signal_connect (GTK_MENU (popup)->toplevel, "show",
1192 G_CALLBACK (gtk_combo_box_menu_show), combo_box);
1193 g_signal_connect (GTK_MENU (popup)->toplevel, "hide",
1194 G_CALLBACK (gtk_combo_box_menu_hide), combo_box);
1196 gtk_menu_attach_to_widget (GTK_MENU (popup),
1197 GTK_WIDGET (combo_box),
1198 gtk_combo_box_detacher);
1202 if (!combo_box->priv->popup_window)
1204 GtkWidget *toplevel;
1206 combo_box->priv->popup_window = gtk_window_new (GTK_WINDOW_POPUP);
1208 g_signal_connect (GTK_WINDOW(combo_box->priv->popup_window),"show",
1209 G_CALLBACK (gtk_combo_box_child_show),
1211 g_signal_connect (GTK_WINDOW(combo_box->priv->popup_window),"hide",
1212 G_CALLBACK (gtk_combo_box_child_hide),
1215 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (combo_box));
1216 if (GTK_IS_WINDOW (toplevel))
1217 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
1218 GTK_WINDOW (combo_box->priv->popup_window));
1220 gtk_window_set_resizable (GTK_WINDOW (combo_box->priv->popup_window), FALSE);
1221 gtk_window_set_screen (GTK_WINDOW (combo_box->priv->popup_window),
1222 gtk_widget_get_screen (GTK_WIDGET (combo_box)));
1224 combo_box->priv->popup_frame = gtk_frame_new (NULL);
1225 gtk_frame_set_shadow_type (GTK_FRAME (combo_box->priv->popup_frame),
1226 GTK_SHADOW_ETCHED_IN);
1227 gtk_container_add (GTK_CONTAINER (combo_box->priv->popup_window),
1228 combo_box->priv->popup_frame);
1230 gtk_widget_show (combo_box->priv->popup_frame);
1232 combo_box->priv->scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1234 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (combo_box->priv->scrolled_window),
1237 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (combo_box->priv->scrolled_window),
1240 gtk_widget_show (combo_box->priv->scrolled_window);
1242 gtk_container_add (GTK_CONTAINER (combo_box->priv->popup_frame),
1243 combo_box->priv->scrolled_window);
1246 gtk_container_add (GTK_CONTAINER (combo_box->priv->scrolled_window),
1249 gtk_widget_show (popup);
1250 g_object_ref (popup);
1251 combo_box->priv->popup_widget = popup;
1256 gtk_combo_box_menu_position_below (GtkMenu *menu,
1262 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
1268 GdkRectangle monitor;
1270 /* FIXME: is using the size request here broken? */
1271 child = GTK_BIN (combo_box)->child;
1273 gdk_window_get_origin (child->window, &sx, &sy);
1275 if (GTK_WIDGET_NO_WINDOW (child))
1277 sx += child->allocation.x;
1278 sy += child->allocation.y;
1281 gtk_widget_size_request (GTK_WIDGET (menu), &req);
1283 if (gtk_widget_get_direction (GTK_WIDGET (combo_box)) == GTK_TEXT_DIR_LTR)
1286 *x = sx + child->allocation.width - req.width;
1289 screen = gtk_widget_get_screen (GTK_WIDGET (combo_box));
1290 monitor_num = gdk_screen_get_monitor_at_window (screen,
1291 GTK_WIDGET (combo_box)->window);
1292 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
1296 else if (*x + req.width > monitor.x + monitor.width)
1297 *x = monitor.x + monitor.width - req.width;
1299 if (monitor.y + monitor.height - *y - child->allocation.height >= req.height)
1300 *y += child->allocation.height;
1301 else if (*y - monitor.y >= req.height)
1303 else if (monitor.y + monitor.height - *y - child->allocation.height > *y - monitor.y)
1304 *y += child->allocation.height;
1312 gtk_combo_box_menu_position_over (GtkMenu *menu,
1318 GtkComboBox *combo_box;
1322 GtkRequisition requisition;
1329 g_return_if_fail (GTK_IS_COMBO_BOX (user_data));
1331 combo_box = GTK_COMBO_BOX (user_data);
1332 widget = GTK_WIDGET (combo_box);
1334 gtk_widget_get_child_requisition (GTK_WIDGET (menu), &requisition);
1335 menu_width = requisition.width;
1337 active = gtk_menu_get_active (GTK_MENU (combo_box->priv->popup_widget));
1338 gdk_window_get_origin (widget->window, &menu_xpos, &menu_ypos);
1340 menu_xpos += widget->allocation.x;
1341 menu_ypos += widget->allocation.y + widget->allocation.height / 2 - 2;
1345 gtk_widget_get_child_requisition (active, &requisition);
1346 menu_ypos -= requisition.height / 2;
1349 children = GTK_MENU_SHELL (combo_box->priv->popup_widget)->children;
1352 child = children->data;
1354 if (active == child)
1357 if (GTK_WIDGET_VISIBLE (child))
1359 gtk_widget_get_child_requisition (child, &requisition);
1360 menu_ypos -= requisition.height;
1363 children = children->next;
1366 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1367 menu_xpos = menu_xpos + widget->allocation.width - menu_width;
1369 /* Clamp the position on screen */
1370 screen_width = gdk_screen_get_width (gtk_widget_get_screen (widget));
1374 else if ((menu_xpos + menu_width) > screen_width)
1375 menu_xpos -= ((menu_xpos + menu_width) - screen_width);
1384 gtk_combo_box_menu_position (GtkMenu *menu,
1390 GtkComboBox *combo_box;
1391 GtkWidget *menu_item;
1393 combo_box = GTK_COMBO_BOX (user_data);
1395 if (combo_box->priv->wrap_width > 0 || combo_box->priv->cell_view == NULL)
1396 gtk_combo_box_menu_position_below (menu, x, y, push_in, user_data);
1399 /* FIXME handle nested menus better */
1400 menu_item = gtk_menu_get_active (GTK_MENU (combo_box->priv->popup_widget));
1402 gtk_menu_shell_select_item (GTK_MENU_SHELL (combo_box->priv->popup_widget),
1405 gtk_combo_box_menu_position_over (menu, x, y, push_in, user_data);
1411 gtk_combo_box_list_position (GtkComboBox *combo_box,
1420 GdkRectangle monitor;
1421 GtkRequisition popup_req;
1422 GtkPolicyType hpolicy, vpolicy;
1424 sample = GTK_BIN (combo_box)->child;
1426 gdk_window_get_origin (sample->window, x, y);
1428 if (GTK_WIDGET_NO_WINDOW (sample))
1430 *x += sample->allocation.x;
1431 *y += sample->allocation.y;
1434 *width = sample->allocation.width;
1436 if (combo_box->priv->cell_view_frame && combo_box->priv->has_frame)
1438 *x -= GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
1439 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->xthickness;
1440 *width += 2 * (GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
1441 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->xthickness);
1444 hpolicy = vpolicy = GTK_POLICY_NEVER;
1445 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (combo_box->priv->scrolled_window),
1447 gtk_widget_size_request (combo_box->priv->popup_frame, &popup_req);
1449 if (popup_req.width > *width)
1451 hpolicy = GTK_POLICY_ALWAYS;
1452 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (combo_box->priv->scrolled_window),
1454 gtk_widget_size_request (combo_box->priv->popup_frame, &popup_req);
1457 *height = popup_req.height;
1459 screen = gtk_widget_get_screen (GTK_WIDGET (combo_box));
1460 monitor_num = gdk_screen_get_monitor_at_window (screen,
1461 GTK_WIDGET (combo_box)->window);
1462 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
1466 else if (*x + *width > monitor.x + monitor.width)
1467 *x = monitor.x + monitor.width - *width;
1469 if (*y + sample->allocation.height + *height <= monitor.y + monitor.height)
1470 *y += sample->allocation.height;
1471 else if (*y - *height >= monitor.y)
1473 else if (monitor.y + monitor.height - (*y + sample->allocation.height) > *y - monitor.y)
1475 *y += sample->allocation.height;
1476 *height = monitor.y + monitor.height - *y;
1480 *height = *y - monitor.y;
1484 if (popup_req.height > *height)
1486 vpolicy = GTK_POLICY_ALWAYS;
1488 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (combo_box->priv->scrolled_window),
1494 cell_view_is_sensitive (GtkCellView *cell_view)
1496 GList *cells, *list;
1499 cells = gtk_cell_view_get_cell_renderers (cell_view);
1505 g_object_get (list->data, "sensitive", &sensitive, NULL);
1512 g_list_free (cells);
1518 tree_column_row_is_sensitive (GtkComboBox *combo_box,
1521 GList *cells, *list;
1524 if (!combo_box->priv->column)
1527 if (combo_box->priv->row_separator_func)
1529 if ((*combo_box->priv->row_separator_func) (combo_box->priv->model, iter,
1530 combo_box->priv->row_separator_data))
1534 gtk_tree_view_column_cell_set_cell_data (combo_box->priv->column,
1535 combo_box->priv->model,
1536 iter, FALSE, FALSE);
1538 cells = gtk_tree_view_column_get_cell_renderers (combo_box->priv->column);
1544 g_object_get (list->data, "sensitive", &sensitive, NULL);
1551 g_list_free (cells);
1557 update_menu_sensitivity (GtkComboBox *combo_box,
1560 GList *children, *child;
1561 GtkWidget *item, *submenu, *separator;
1562 GtkWidget *cell_view;
1565 if (!combo_box->priv->model)
1568 children = gtk_container_get_children (GTK_CONTAINER (menu));
1570 for (child = children; child; child = child->next)
1572 item = GTK_WIDGET (child->data);
1573 cell_view = GTK_BIN (item)->child;
1575 if (!GTK_IS_CELL_VIEW (cell_view))
1578 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (item));
1579 if (submenu != NULL)
1581 gtk_widget_set_sensitive (item, TRUE);
1582 update_menu_sensitivity (combo_box, submenu);
1586 sensitive = cell_view_is_sensitive (GTK_CELL_VIEW (cell_view));
1588 if (menu != combo_box->priv->popup_widget && child == children)
1590 separator = GTK_WIDGET (child->next->data);
1591 g_object_set (item, "visible", sensitive, NULL);
1592 g_object_set (separator, "visible", sensitive, NULL);
1595 gtk_widget_set_sensitive (item, sensitive);
1599 g_list_free (children);
1603 gtk_combo_box_menu_popup (GtkComboBox *combo_box,
1605 guint32 activate_time)
1609 GtkRequisition requisition;
1612 update_menu_sensitivity (combo_box, combo_box->priv->popup_widget);
1615 if (gtk_tree_row_reference_valid (combo_box->priv->active_row))
1617 path = gtk_tree_row_reference_get_path (combo_box->priv->active_row);
1618 active_item = gtk_tree_path_get_indices (path)[0];
1619 gtk_tree_path_free (path);
1621 if (combo_box->priv->add_tearoffs)
1625 /* FIXME handle nested menus better */
1626 gtk_menu_set_active (GTK_MENU (combo_box->priv->popup_widget), active_item);
1628 if (combo_box->priv->wrap_width == 0)
1630 width = GTK_WIDGET (combo_box)->allocation.width;
1631 gtk_widget_set_size_request (combo_box->priv->popup_widget, -1, -1);
1632 gtk_widget_size_request (combo_box->priv->popup_widget, &requisition);
1634 gtk_widget_set_size_request (combo_box->priv->popup_widget,
1635 MAX (width, requisition.width), -1);
1638 gtk_menu_popup (GTK_MENU (combo_box->priv->popup_widget),
1640 gtk_combo_box_menu_position, combo_box,
1641 button, activate_time);
1645 popup_grab_on_window (GdkWindow *window,
1646 guint32 activate_time,
1647 gboolean grab_keyboard)
1649 if ((gdk_pointer_grab (window, TRUE,
1650 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
1651 GDK_POINTER_MOTION_MASK,
1652 NULL, NULL, activate_time) == 0))
1654 if (!grab_keyboard ||
1655 gdk_keyboard_grab (window, TRUE,
1656 activate_time) == 0)
1660 gdk_display_pointer_ungrab (gdk_drawable_get_display (window),
1670 * gtk_combo_box_popup:
1671 * @combo_box: a #GtkComboBox
1673 * Pops up the menu or dropdown list of @combo_box.
1675 * This function is mostly intended for use by accessibility technologies;
1676 * applications should have little use for it.
1681 gtk_combo_box_popup (GtkComboBox *combo_box)
1683 gint x, y, width, height;
1684 GtkTreePath *path, *ppath;
1685 GtkWidget *toplevel;
1687 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
1689 if (!GTK_WIDGET_REALIZED (combo_box))
1692 if (GTK_WIDGET_MAPPED (combo_box->priv->popup_widget))
1695 if (GTK_IS_MENU (combo_box->priv->popup_widget))
1697 gtk_combo_box_menu_popup (combo_box, 0, 0);
1701 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (combo_box));
1702 if (GTK_IS_WINDOW (toplevel))
1703 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
1704 GTK_WINDOW (combo_box->priv->popup_window));
1706 gtk_widget_show_all (combo_box->priv->popup_frame);
1707 gtk_combo_box_list_position (combo_box, &x, &y, &width, &height);
1709 gtk_widget_set_size_request (combo_box->priv->popup_window, width, height);
1710 gtk_window_move (GTK_WINDOW (combo_box->priv->popup_window), x, y);
1712 if (gtk_tree_row_reference_valid (combo_box->priv->active_row))
1714 path = gtk_tree_row_reference_get_path (combo_box->priv->active_row);
1715 ppath = gtk_tree_path_copy (path);
1716 if (gtk_tree_path_up (ppath))
1717 gtk_tree_view_expand_to_path (GTK_TREE_VIEW (combo_box->priv->tree_view),
1719 gtk_tree_view_set_cursor (GTK_TREE_VIEW (combo_box->priv->tree_view),
1721 gtk_tree_path_free (path);
1722 gtk_tree_path_free (ppath);
1724 gtk_tree_view_set_hover_expand (GTK_TREE_VIEW (combo_box->priv->tree_view),
1728 gtk_widget_show (combo_box->priv->popup_window);
1730 gtk_widget_grab_focus (combo_box->priv->popup_window);
1731 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
1734 if (!GTK_WIDGET_HAS_FOCUS (combo_box->priv->tree_view))
1735 gtk_widget_grab_focus (combo_box->priv->tree_view);
1737 if (!popup_grab_on_window (combo_box->priv->popup_window->window,
1738 GDK_CURRENT_TIME, TRUE))
1740 gtk_widget_hide (combo_box->priv->popup_window);
1744 gtk_grab_add (combo_box->priv->popup_window);
1748 * gtk_combo_box_popdown:
1749 * @combo_box: a #GtkComboBox
1751 * Hides the menu or dropdown list of @combo_box.
1753 * This function is mostly intended for use by accessibility technologies;
1754 * applications should have little use for it.
1759 gtk_combo_box_popdown (GtkComboBox *combo_box)
1761 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
1763 if (GTK_IS_MENU (combo_box->priv->popup_widget))
1765 gtk_menu_popdown (GTK_MENU (combo_box->priv->popup_widget));
1769 if (!GTK_WIDGET_REALIZED (GTK_WIDGET (combo_box)))
1772 gtk_grab_remove (combo_box->priv->popup_window);
1773 gtk_widget_hide_all (combo_box->priv->popup_window);
1774 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
1779 gtk_combo_box_calc_requested_width (GtkComboBox *combo_box,
1785 if (combo_box->priv->cell_view)
1786 gtk_widget_style_get (combo_box->priv->cell_view,
1787 "focus-line-width", &padding,
1792 /* add some pixels for good measure */
1793 padding += BONUS_PADDING;
1795 if (combo_box->priv->cell_view)
1796 gtk_cell_view_get_size_of_row (GTK_CELL_VIEW (combo_box->priv->cell_view),
1801 return req.width + padding;
1805 gtk_combo_box_remeasure (GtkComboBox *combo_box)
1810 if (!combo_box->priv->model ||
1811 !gtk_tree_model_get_iter_first (combo_box->priv->model, &iter))
1814 combo_box->priv->width = 0;
1816 path = gtk_tree_path_new_from_indices (0, -1);
1822 if (combo_box->priv->cell_view)
1823 gtk_cell_view_get_size_of_row (GTK_CELL_VIEW (combo_box->priv->cell_view),
1828 combo_box->priv->width = MAX (combo_box->priv->width, req.width);
1830 gtk_tree_path_next (path);
1832 while (gtk_tree_model_iter_next (combo_box->priv->model, &iter));
1834 gtk_tree_path_free (path);
1838 gtk_combo_box_size_request (GtkWidget *widget,
1839 GtkRequisition *requisition)
1842 gint focus_width, focus_pad;
1843 GtkRequisition bin_req;
1845 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
1848 gtk_widget_size_request (GTK_BIN (widget)->child, &bin_req);
1849 gtk_combo_box_remeasure (combo_box);
1850 bin_req.width = MAX (bin_req.width, combo_box->priv->width);
1852 gtk_widget_style_get (GTK_WIDGET (widget),
1853 "focus-line-width", &focus_width,
1854 "focus-padding", &focus_pad,
1857 if (!combo_box->priv->tree_view)
1861 if (combo_box->priv->cell_view)
1863 GtkRequisition button_req, sep_req, arrow_req;
1864 gint border_width, xthickness, ythickness;
1866 gtk_widget_size_request (combo_box->priv->button, &button_req);
1867 border_width = GTK_CONTAINER (combo_box)->border_width;
1868 xthickness = combo_box->priv->button->style->xthickness;
1869 ythickness = combo_box->priv->button->style->ythickness;
1871 bin_req.width = MAX (bin_req.width, combo_box->priv->width);
1873 gtk_widget_size_request (combo_box->priv->separator, &sep_req);
1874 gtk_widget_size_request (combo_box->priv->arrow, &arrow_req);
1876 height = MAX (sep_req.height, arrow_req.height);
1877 height = MAX (height, bin_req.height);
1879 width = bin_req.width + sep_req.width + arrow_req.width;
1881 height += 2*(border_width + ythickness + focus_width + focus_pad);
1882 width += 2*(border_width + xthickness + focus_width + focus_pad);
1884 requisition->width = width;
1885 requisition->height = height;
1889 GtkRequisition but_req;
1891 gtk_widget_size_request (combo_box->priv->button, &but_req);
1893 requisition->width = bin_req.width + but_req.width;
1894 requisition->height = MAX (bin_req.height, but_req.height);
1900 GtkRequisition button_req, frame_req;
1902 /* sample + frame */
1903 *requisition = bin_req;
1905 requisition->width += 2 * focus_width;
1907 if (combo_box->priv->cell_view_frame)
1909 gtk_widget_size_request (combo_box->priv->cell_view_frame, &frame_req);
1910 if (combo_box->priv->has_frame)
1912 requisition->width += 2 *
1913 (GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
1914 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->xthickness);
1915 requisition->height += 2 *
1916 (GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
1917 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->ythickness);
1922 gtk_widget_size_request (combo_box->priv->button, &button_req);
1924 requisition->height = MAX (requisition->height, button_req.height);
1925 requisition->width += button_req.width;
1930 gtk_combo_box_size_allocate (GtkWidget *widget,
1931 GtkAllocation *allocation)
1933 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
1934 gint focus_width, focus_pad;
1935 GtkAllocation child;
1937 gboolean is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
1939 widget->allocation = *allocation;
1941 gtk_widget_style_get (GTK_WIDGET (widget),
1942 "focus-line-width", &focus_width,
1943 "focus-padding", &focus_pad,
1946 if (!combo_box->priv->tree_view)
1948 if (combo_box->priv->cell_view)
1950 gint border_width, xthickness, ythickness;
1954 gtk_widget_size_allocate (combo_box->priv->button, allocation);
1956 /* set some things ready */
1957 border_width = GTK_CONTAINER (combo_box->priv->button)->border_width;
1958 xthickness = combo_box->priv->button->style->xthickness;
1959 ythickness = combo_box->priv->button->style->ythickness;
1961 child.x = allocation->x;
1962 child.y = allocation->y;
1963 width = allocation->width;
1964 child.height = allocation->height;
1966 if (!combo_box->priv->is_cell_renderer)
1968 child.x += border_width + xthickness + focus_width + focus_pad;
1969 child.y += border_width + ythickness + focus_width + focus_pad;
1970 width -= 2 * (child.x - allocation->x);
1971 child.height -= 2 * (child.y - allocation->y);
1975 /* handle the children */
1976 gtk_widget_size_request (combo_box->priv->arrow, &req);
1977 child.width = req.width;
1979 child.x += width - req.width;
1980 child.width = MAX (1, child.width);
1981 child.height = MAX (1, child.height);
1982 gtk_widget_size_allocate (combo_box->priv->arrow, &child);
1984 child.x += req.width;
1985 gtk_widget_size_request (combo_box->priv->separator, &req);
1986 child.width = req.width;
1988 child.x -= req.width;
1989 child.width = MAX (1, child.width);
1990 child.height = MAX (1, child.height);
1991 gtk_widget_size_allocate (combo_box->priv->separator, &child);
1995 child.x += req.width;
1996 child.width = allocation->x + allocation->width
1997 - (border_width + xthickness + focus_width + focus_pad)
2002 child.width = child.x;
2003 child.x = allocation->x
2004 + border_width + xthickness + focus_width + focus_pad;
2005 child.width -= child.x;
2008 child.width = MAX (1, child.width);
2009 child.height = MAX (1, child.height);
2010 gtk_widget_size_allocate (GTK_BIN (widget)->child, &child);
2014 gtk_widget_size_request (combo_box->priv->button, &req);
2016 child.x = allocation->x;
2018 child.x = allocation->x + allocation->width - req.width;
2019 child.y = allocation->y;
2020 child.width = req.width;
2021 child.height = allocation->height;
2022 child.width = MAX (1, child.width);
2023 child.height = MAX (1, child.height);
2024 gtk_widget_size_allocate (combo_box->priv->button, &child);
2027 child.x = allocation->x + req.width;
2029 child.x = allocation->x;
2030 child.y = allocation->y;
2031 child.width = allocation->width - req.width;
2032 child.width = MAX (1, child.width);
2033 child.height = MAX (1, child.height);
2034 gtk_widget_size_allocate (GTK_BIN (widget)->child, &child);
2042 gtk_widget_size_request (combo_box->priv->button, &req);
2044 child.x = allocation->x;
2046 child.x = allocation->x + allocation->width - req.width;
2047 child.y = allocation->y;
2048 child.width = req.width;
2049 child.height = allocation->height;
2050 child.width = MAX (1, child.width);
2051 child.height = MAX (1, child.height);
2052 gtk_widget_size_allocate (combo_box->priv->button, &child);
2056 child.x = allocation->x + req.width;
2058 child.x = allocation->x;
2059 child.y = allocation->y;
2060 child.width = allocation->width - req.width;
2061 child.height = allocation->height;
2063 if (combo_box->priv->cell_view_frame)
2065 child.width = MAX (1, child.width);
2066 child.height = MAX (1, child.height);
2067 gtk_widget_size_allocate (combo_box->priv->cell_view_frame, &child);
2070 if (combo_box->priv->has_frame)
2073 GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
2074 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->xthickness;
2076 GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
2077 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->ythickness;
2078 child.width -= 2 * (
2079 GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
2080 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->xthickness);
2081 child.height -= 2 * (
2082 GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
2083 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->ythickness);
2087 child.width = MAX (1, child.width);
2088 child.height = MAX (1, child.height);
2089 gtk_widget_size_allocate (GTK_BIN (combo_box)->child, &child);
2094 gtk_combo_box_unset_model (GtkComboBox *combo_box)
2096 if (combo_box->priv->model)
2098 g_signal_handler_disconnect (combo_box->priv->model,
2099 combo_box->priv->inserted_id);
2100 g_signal_handler_disconnect (combo_box->priv->model,
2101 combo_box->priv->deleted_id);
2102 g_signal_handler_disconnect (combo_box->priv->model,
2103 combo_box->priv->reordered_id);
2104 g_signal_handler_disconnect (combo_box->priv->model,
2105 combo_box->priv->changed_id);
2109 if (!combo_box->priv->tree_view)
2111 if (combo_box->priv->popup_widget)
2112 gtk_container_foreach (GTK_CONTAINER (combo_box->priv->popup_widget),
2113 (GtkCallback)gtk_widget_destroy, NULL);
2116 if (combo_box->priv->model)
2118 g_object_unref (combo_box->priv->model);
2119 combo_box->priv->model = NULL;
2122 if (combo_box->priv->active_row)
2124 gtk_tree_row_reference_free (combo_box->priv->active_row);
2125 combo_box->priv->active_row = NULL;
2128 if (combo_box->priv->cell_view)
2129 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (combo_box->priv->cell_view), NULL);
2133 gtk_combo_box_forall (GtkContainer *container,
2134 gboolean include_internals,
2135 GtkCallback callback,
2136 gpointer callback_data)
2138 GtkComboBox *combo_box = GTK_COMBO_BOX (container);
2140 if (include_internals)
2142 if (combo_box->priv->button)
2143 (* callback) (combo_box->priv->button, callback_data);
2144 if (combo_box->priv->cell_view_frame)
2145 (* callback) (combo_box->priv->cell_view_frame, callback_data);
2148 if (GTK_BIN (container)->child)
2149 (* callback) (GTK_BIN (container)->child, callback_data);
2153 gtk_combo_box_child_show (GtkWidget *widget,
2156 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2157 g_signal_emit (combo_box, combo_box_signals[POPUP_SHOW], 0);
2161 gtk_combo_box_child_hide (GtkWidget *widget,
2164 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2165 g_signal_emit (combo_box, combo_box_signals[POPUP_HIDE], 0);
2169 gtk_combo_box_expose_event (GtkWidget *widget,
2170 GdkEventExpose *event)
2172 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
2174 if (!combo_box->priv->tree_view)
2176 gtk_container_propagate_expose (GTK_CONTAINER (widget),
2177 combo_box->priv->button, event);
2181 gtk_container_propagate_expose (GTK_CONTAINER (widget),
2182 combo_box->priv->button, event);
2184 if (combo_box->priv->cell_view_frame)
2185 gtk_container_propagate_expose (GTK_CONTAINER (widget),
2186 combo_box->priv->cell_view_frame, event);
2189 gtk_container_propagate_expose (GTK_CONTAINER (widget),
2190 GTK_BIN (widget)->child, event);
2205 path_visible (GtkTreeView *view,
2211 /* Note that we rely on the fact that collapsed rows don't have nodes
2213 return _gtk_tree_view_find_node (view, path, &tree, &node);
2217 tree_next_func (GtkTreeModel *model,
2222 SearchData *search_data = (SearchData *)data;
2224 if (search_data->found)
2226 if (!tree_column_row_is_sensitive (search_data->combo, iter))
2229 if (search_data->visible &&
2230 !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
2233 search_data->set = TRUE;
2234 search_data->iter = *iter;
2239 if (gtk_tree_path_compare (path, search_data->path) == 0)
2240 search_data->found = TRUE;
2246 tree_next (GtkComboBox *combo,
2247 GtkTreeModel *model,
2252 SearchData search_data;
2254 search_data.combo = combo;
2255 search_data.path = gtk_tree_model_get_path (model, iter);
2256 search_data.visible = visible;
2257 search_data.found = FALSE;
2258 search_data.set = FALSE;
2260 gtk_tree_model_foreach (model, tree_next_func, &search_data);
2262 *next = search_data.iter;
2264 gtk_tree_path_free (search_data.path);
2266 return search_data.set;
2270 tree_prev_func (GtkTreeModel *model,
2275 SearchData *search_data = (SearchData *)data;
2277 if (gtk_tree_path_compare (path, search_data->path) == 0)
2279 search_data->found = TRUE;
2283 if (!tree_column_row_is_sensitive (search_data->combo, iter))
2286 if (search_data->visible &&
2287 !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
2290 search_data->set = TRUE;
2291 search_data->iter = *iter;
2297 tree_prev (GtkComboBox *combo,
2298 GtkTreeModel *model,
2303 SearchData search_data;
2305 search_data.combo = combo;
2306 search_data.path = gtk_tree_model_get_path (model, iter);
2307 search_data.visible = visible;
2308 search_data.found = FALSE;
2309 search_data.set = FALSE;
2311 gtk_tree_model_foreach (model, tree_prev_func, &search_data);
2313 *prev = search_data.iter;
2315 gtk_tree_path_free (search_data.path);
2317 return search_data.set;
2321 tree_last_func (GtkTreeModel *model,
2326 SearchData *search_data = (SearchData *)data;
2328 if (!tree_column_row_is_sensitive (search_data->combo, iter))
2331 /* Note that we rely on the fact that collapsed rows don't have nodes
2333 if (search_data->visible &&
2334 !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
2337 search_data->set = TRUE;
2338 search_data->iter = *iter;
2344 tree_last (GtkComboBox *combo,
2345 GtkTreeModel *model,
2349 SearchData search_data;
2351 search_data.combo = combo;
2352 search_data.visible = visible;
2353 search_data.set = FALSE;
2355 gtk_tree_model_foreach (model, tree_last_func, &search_data);
2357 *last = search_data.iter;
2359 return search_data.set;
2364 tree_first_func (GtkTreeModel *model,
2369 SearchData *search_data = (SearchData *)data;
2371 if (!tree_column_row_is_sensitive (search_data->combo, iter))
2374 if (search_data->visible &&
2375 !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
2378 search_data->set = TRUE;
2379 search_data->iter = *iter;
2385 tree_first (GtkComboBox *combo,
2386 GtkTreeModel *model,
2390 SearchData search_data;
2392 search_data.combo = combo;
2393 search_data.visible = visible;
2394 search_data.set = FALSE;
2396 gtk_tree_model_foreach (model, tree_first_func, &search_data);
2398 *first = search_data.iter;
2400 return search_data.set;
2404 gtk_combo_box_scroll_event (GtkWidget *widget,
2405 GdkEventScroll *event)
2407 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
2410 GtkTreeIter new_iter;
2412 if (!gtk_combo_box_get_active_iter (combo_box, &iter))
2415 if (event->direction == GDK_SCROLL_UP)
2416 found = tree_prev (combo_box, combo_box->priv->model,
2417 &iter, &new_iter, FALSE);
2419 found = tree_next (combo_box, combo_box->priv->model,
2420 &iter, &new_iter, FALSE);
2423 gtk_combo_box_set_active_iter (combo_box, &new_iter);
2433 gtk_combo_box_sync_cells (GtkComboBox *combo_box,
2434 GtkCellLayout *cell_layout)
2438 for (k = combo_box->priv->cells; k; k = k->next)
2441 ComboCellInfo *info = (ComboCellInfo *)k->data;
2443 if (info->pack == GTK_PACK_START)
2444 gtk_cell_layout_pack_start (cell_layout,
2445 info->cell, info->expand);
2446 else if (info->pack == GTK_PACK_END)
2447 gtk_cell_layout_pack_end (cell_layout,
2448 info->cell, info->expand);
2450 gtk_cell_layout_set_cell_data_func (cell_layout,
2452 combo_cell_data_func, info, NULL);
2454 for (j = info->attributes; j; j = j->next->next)
2456 gtk_cell_layout_add_attribute (cell_layout,
2459 GPOINTER_TO_INT (j->next->data));
2465 gtk_combo_box_menu_setup (GtkComboBox *combo_box,
2466 gboolean add_children)
2470 if (combo_box->priv->cell_view)
2472 combo_box->priv->button = gtk_toggle_button_new ();
2473 gtk_button_set_focus_on_click (GTK_BUTTON (combo_box->priv->button),
2474 combo_box->priv->focus_on_click);
2476 g_signal_connect (combo_box->priv->button, "toggled",
2477 G_CALLBACK (gtk_combo_box_button_toggled), combo_box);
2478 g_signal_connect_after (combo_box->priv->button,
2480 G_CALLBACK (gtk_combo_box_key_press), combo_box);
2481 gtk_widget_set_parent (combo_box->priv->button,
2482 GTK_BIN (combo_box)->child->parent);
2484 combo_box->priv->box = gtk_hbox_new (FALSE, 0);
2485 gtk_container_add (GTK_CONTAINER (combo_box->priv->button),
2486 combo_box->priv->box);
2488 combo_box->priv->separator = gtk_vseparator_new ();
2489 gtk_container_add (GTK_CONTAINER (combo_box->priv->box),
2490 combo_box->priv->separator);
2492 combo_box->priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
2493 gtk_container_add (GTK_CONTAINER (combo_box->priv->box),
2494 combo_box->priv->arrow);
2496 gtk_widget_show_all (combo_box->priv->button);
2500 combo_box->priv->button = gtk_toggle_button_new ();
2501 gtk_button_set_focus_on_click (GTK_BUTTON (combo_box->priv->button),
2502 combo_box->priv->focus_on_click);
2504 g_signal_connect (combo_box->priv->button, "toggled",
2505 G_CALLBACK (gtk_combo_box_button_toggled), combo_box);
2506 g_signal_connect_after (combo_box, "key_press_event",
2507 G_CALLBACK (gtk_combo_box_key_press), combo_box);
2508 gtk_widget_set_parent (combo_box->priv->button,
2509 GTK_BIN (combo_box)->child->parent);
2511 combo_box->priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
2512 gtk_container_add (GTK_CONTAINER (combo_box->priv->button),
2513 combo_box->priv->arrow);
2514 gtk_widget_show_all (combo_box->priv->button);
2517 g_signal_connect (combo_box->priv->button, "button_press_event",
2518 G_CALLBACK (gtk_combo_box_menu_button_press),
2520 g_signal_connect (combo_box->priv->button, "state_changed",
2521 G_CALLBACK (gtk_combo_box_button_state_changed),
2524 /* create our funky menu */
2525 menu = gtk_menu_new ();
2526 g_signal_connect (menu, "key_press_event",
2527 G_CALLBACK (gtk_combo_box_menu_key_press), combo_box);
2528 gtk_combo_box_set_popup_widget (combo_box, menu);
2532 gtk_combo_box_menu_fill (combo_box);
2534 /* the column is needed in tree_column_row_is_sensitive() */
2535 combo_box->priv->column = gtk_tree_view_column_new ();
2536 g_object_ref_sink (combo_box->priv->column);
2537 gtk_combo_box_sync_cells (combo_box,
2538 GTK_CELL_LAYOUT (combo_box->priv->column));
2540 gtk_combo_box_update_title (combo_box);
2544 gtk_combo_box_menu_fill (GtkComboBox *combo_box)
2548 if (!combo_box->priv->model)
2551 menu = combo_box->priv->popup_widget;
2553 if (combo_box->priv->add_tearoffs)
2555 GtkWidget *tearoff = gtk_tearoff_menu_item_new ();
2557 gtk_widget_show (tearoff);
2559 if (combo_box->priv->wrap_width)
2560 gtk_menu_attach (GTK_MENU (menu), tearoff,
2561 0, combo_box->priv->wrap_width, 0, 1);
2563 gtk_menu_shell_append (GTK_MENU_SHELL (menu), tearoff);
2566 gtk_combo_box_menu_fill_level (combo_box, menu, NULL);
2570 gtk_cell_view_menu_item_new (GtkComboBox *combo_box,
2571 GtkTreeModel *model,
2574 GtkWidget *cell_view;
2579 cell_view = gtk_cell_view_new ();
2580 gtk_cell_view_set_model (GTK_CELL_VIEW (cell_view), model);
2581 path = gtk_tree_model_get_path (model, iter);
2582 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (cell_view), path);
2583 gtk_tree_path_free (path);
2585 gtk_combo_box_sync_cells (combo_box, GTK_CELL_LAYOUT (cell_view));
2586 gtk_widget_size_request (cell_view, &req);
2587 gtk_widget_show (cell_view);
2589 item = gtk_menu_item_new ();
2590 gtk_container_add (GTK_CONTAINER (item), cell_view);
2596 gtk_combo_box_menu_fill_level (GtkComboBox *combo_box,
2598 GtkTreeIter *parent)
2600 GtkTreeModel *model = combo_box->priv->model;
2601 GtkWidget *item, *submenu, *subitem, *separator;
2603 gboolean is_separator;
2608 n_children = gtk_tree_model_iter_n_children (model, parent);
2611 for (i = 0; i < n_children; i++)
2613 gtk_tree_model_iter_nth_child (model, &iter, parent, i);
2615 if (combo_box->priv->row_separator_func)
2616 is_separator = (*combo_box->priv->row_separator_func) (combo_box->priv->model, &iter,
2617 combo_box->priv->row_separator_data);
2619 is_separator = FALSE;
2623 item = gtk_separator_menu_item_new ();
2624 path = gtk_tree_model_get_path (model, &iter);
2625 g_object_set_data_full (G_OBJECT (item),
2626 I_("gtk-combo-box-item-path"),
2627 gtk_tree_row_reference_new (model, path),
2628 (GDestroyNotify)gtk_tree_row_reference_free);
2629 gtk_tree_path_free (path);
2633 item = gtk_cell_view_menu_item_new (combo_box, model, &iter);
2634 if (gtk_tree_model_iter_has_child (model, &iter))
2636 submenu = gtk_menu_new ();
2637 gtk_widget_show (submenu);
2638 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
2640 /* Ugly - since menus can only activate leafs, we have to
2641 * duplicate the item inside the submenu.
2643 subitem = gtk_cell_view_menu_item_new (combo_box, model, &iter);
2644 separator = gtk_separator_menu_item_new ();
2645 gtk_widget_show (subitem);
2646 gtk_widget_show (separator);
2647 g_signal_connect (subitem, "activate",
2648 G_CALLBACK (gtk_combo_box_menu_item_activate),
2650 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), subitem);
2651 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), separator);
2653 gtk_combo_box_menu_fill_level (combo_box, submenu, &iter);
2656 g_signal_connect (item, "activate",
2657 G_CALLBACK (gtk_combo_box_menu_item_activate),
2661 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
2662 if (combo_box->priv->wrap_width && menu == combo_box->priv->popup_widget)
2663 gtk_combo_box_relayout_item (combo_box, item, &iter, last);
2664 gtk_widget_show (item);
2671 gtk_combo_box_menu_destroy (GtkComboBox *combo_box)
2673 g_signal_handlers_disconnect_matched (combo_box->priv->button,
2674 G_SIGNAL_MATCH_DATA,
2676 gtk_combo_box_menu_button_press, NULL);
2677 g_signal_handlers_disconnect_matched (combo_box->priv->button,
2678 G_SIGNAL_MATCH_DATA,
2680 gtk_combo_box_button_state_changed, combo_box);
2682 /* unparent will remove our latest ref */
2683 gtk_widget_unparent (combo_box->priv->button);
2685 combo_box->priv->box = NULL;
2686 combo_box->priv->button = NULL;
2687 combo_box->priv->arrow = NULL;
2688 combo_box->priv->separator = NULL;
2690 g_object_unref (combo_box->priv->column);
2691 combo_box->priv->column = NULL;
2693 /* changing the popup window will unref the menu and the children */
2701 menu_occupied (GtkMenu *menu,
2705 guint bottom_attach)
2709 for (i = GTK_MENU_SHELL (menu)->children; i; i = i->next)
2713 gtk_container_child_get (GTK_CONTAINER (menu),
2717 "bottom-attach", &b,
2721 /* look if this item intersects with the given coordinates */
2722 if (right_attach > l && left_attach < r && bottom_attach > t && top_attach < b)
2730 gtk_combo_box_relayout_item (GtkComboBox *combo_box,
2735 gint current_col = 0, current_row = 0;
2736 gint rows = 1, cols = 1;
2737 GtkWidget *menu = combo_box->priv->popup_widget;
2739 if (!GTK_IS_MENU_SHELL (menu))
2742 if (combo_box->priv->col_column == -1 &&
2743 combo_box->priv->row_column == -1 &&
2746 gtk_container_child_get (GTK_CONTAINER (menu),
2748 "right_attach", ¤t_col,
2749 "top_attach", ¤t_row,
2751 if (current_col + cols > combo_box->priv->wrap_width)
2759 if (combo_box->priv->col_column != -1)
2760 gtk_tree_model_get (combo_box->priv->model, iter,
2761 combo_box->priv->col_column, &cols,
2763 if (combo_box->priv->row_column != -1)
2764 gtk_tree_model_get (combo_box->priv->model, iter,
2765 combo_box->priv->row_column, &rows,
2770 if (current_col + cols > combo_box->priv->wrap_width)
2776 if (!menu_occupied (GTK_MENU (menu),
2777 current_col, current_col + cols,
2778 current_row, current_row + rows))
2785 /* set attach props */
2786 gtk_menu_attach (GTK_MENU (menu), item,
2787 current_col, current_col + cols,
2788 current_row, current_row + rows);
2792 gtk_combo_box_relayout (GtkComboBox *combo_box)
2797 menu = combo_box->priv->popup_widget;
2799 /* do nothing unless we are in menu style and realized */
2800 if (combo_box->priv->tree_view || !GTK_IS_MENU_SHELL (menu))
2803 list = gtk_container_get_children (GTK_CONTAINER (menu));
2805 for (j = g_list_last (list); j; j = j->prev)
2806 gtk_container_remove (GTK_CONTAINER (menu), j->data);
2808 gtk_combo_box_menu_fill (combo_box);
2815 gtk_combo_box_menu_button_press (GtkWidget *widget,
2816 GdkEventButton *event,
2819 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2821 if (GTK_IS_MENU (combo_box->priv->popup_widget) &&
2822 event->type == GDK_BUTTON_PRESS && event->button == 1)
2824 if (combo_box->priv->focus_on_click &&
2825 !GTK_WIDGET_HAS_FOCUS (combo_box->priv->button))
2826 gtk_widget_grab_focus (combo_box->priv->button);
2828 gtk_combo_box_menu_popup (combo_box, event->button, event->time);
2837 gtk_combo_box_menu_item_activate (GtkWidget *item,
2840 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2841 GtkWidget *cell_view;
2845 cell_view = GTK_BIN (item)->child;
2847 g_return_if_fail (GTK_IS_CELL_VIEW (cell_view));
2849 path = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (cell_view));
2851 if (gtk_tree_model_get_iter (combo_box->priv->model, &iter, path))
2852 gtk_combo_box_set_active_iter (combo_box, &iter);
2854 gtk_tree_path_free (path);
2856 combo_box->priv->editing_canceled = FALSE;
2860 gtk_combo_box_model_row_inserted (GtkTreeModel *model,
2865 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2867 if (combo_box->priv->tree_view)
2868 gtk_combo_box_list_popup_resize (combo_box);
2870 gtk_combo_box_menu_row_inserted (model, path, iter, user_data);
2874 gtk_combo_box_model_row_deleted (GtkTreeModel *model,
2878 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2880 if (combo_box->priv->cell_view)
2882 if (!gtk_tree_row_reference_valid (combo_box->priv->active_row))
2883 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (combo_box->priv->cell_view), NULL);
2886 if (combo_box->priv->tree_view)
2887 gtk_combo_box_list_popup_resize (combo_box);
2889 gtk_combo_box_menu_row_deleted (model, path, user_data);
2893 gtk_combo_box_model_rows_reordered (GtkTreeModel *model,
2899 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2901 gtk_tree_row_reference_reordered (G_OBJECT (user_data), path, iter, new_order);
2903 if (!combo_box->priv->tree_view)
2904 gtk_combo_box_menu_rows_reordered (model, path, iter, new_order, user_data);
2908 gtk_combo_box_model_row_changed (GtkTreeModel *model,
2913 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2914 GtkTreePath *active_path;
2916 /* FIXME this belongs to GtkCellView */
2917 if (gtk_tree_row_reference_valid (combo_box->priv->active_row))
2919 active_path = gtk_tree_row_reference_get_path (combo_box->priv->active_row);
2920 if (gtk_tree_path_compare (path, active_path) == 0 &&
2921 combo_box->priv->cell_view)
2922 gtk_widget_queue_resize (GTK_WIDGET (combo_box->priv->cell_view));
2923 gtk_tree_path_free (active_path);
2926 if (combo_box->priv->tree_view)
2927 gtk_combo_box_list_row_changed (model, path, iter, user_data);
2929 gtk_combo_box_menu_row_changed (model, path, iter, user_data);
2933 list_popup_resize_idle (gpointer user_data)
2935 GtkComboBox *combo_box;
2936 gint x, y, width, height;
2938 GDK_THREADS_ENTER ();
2940 combo_box = GTK_COMBO_BOX (user_data);
2942 if (combo_box->priv->tree_view &&
2943 GTK_WIDGET_MAPPED (combo_box->priv->popup_window))
2945 gtk_combo_box_list_position (combo_box, &x, &y, &width, &height);
2947 gtk_widget_set_size_request (combo_box->priv->popup_window, width, height);
2948 gtk_window_move (GTK_WINDOW (combo_box->priv->popup_window), x, y);
2951 combo_box->priv->resize_idle_id = 0;
2953 GDK_THREADS_LEAVE ();
2959 gtk_combo_box_list_popup_resize (GtkComboBox *combo_box)
2961 if (!combo_box->priv->resize_idle_id)
2962 combo_box->priv->resize_idle_id =
2963 g_idle_add (list_popup_resize_idle, combo_box);
2967 gtk_combo_box_model_row_expanded (GtkTreeModel *model,
2972 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2974 gtk_combo_box_list_popup_resize (combo_box);
2979 find_menu_by_path (GtkWidget *menu,
2981 gboolean skip_first)
2986 GtkTreeRowReference *mref;
2990 list = gtk_container_get_children (GTK_CONTAINER (menu));
2993 for (i = list; i; i = i->next)
2995 if (GTK_IS_SEPARATOR_MENU_ITEM (i->data))
2997 mref = g_object_get_data (G_OBJECT (i->data), "gtk-combo-box-item-path");
3000 else if (!gtk_tree_row_reference_valid (mref))
3003 mpath = gtk_tree_row_reference_get_path (mref);
3005 else if (GTK_IS_CELL_VIEW (GTK_BIN (i->data)->child))
3013 mpath = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (GTK_BIN (i->data)->child));
3018 /* this case is necessary, since the row reference of
3019 * the cell view may already be updated after a deletion
3026 if (gtk_tree_path_compare (mpath, path) == 0)
3028 gtk_tree_path_free (mpath);
3032 if (gtk_tree_path_is_ancestor (mpath, path))
3034 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
3035 if (submenu != NULL)
3037 gtk_tree_path_free (mpath);
3038 item = find_menu_by_path (submenu, path, TRUE);
3042 gtk_tree_path_free (mpath);
3052 dump_menu_tree (GtkWidget *menu,
3059 list = gtk_container_get_children (GTK_CONTAINER (menu));
3060 for (i = list; i; i = i->next)
3062 if (GTK_IS_CELL_VIEW (GTK_BIN (i->data)->child))
3064 path = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (GTK_BIN (i->data)->child));
3065 g_print ("%*s%s\n", 2 * level, " ", gtk_tree_path_to_string (path));
3066 gtk_tree_path_free (path);
3068 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
3069 if (submenu != NULL)
3070 dump_menu_tree (submenu, level + 1);
3079 gtk_combo_box_menu_row_inserted (GtkTreeModel *model,
3085 GtkWidget *item, *menu, *separator;
3086 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3090 gboolean is_separator;
3092 if (!combo_box->priv->popup_widget)
3095 depth = gtk_tree_path_get_depth (path);
3096 pos = gtk_tree_path_get_indices (path)[depth - 1];
3099 ppath = gtk_tree_path_copy (path);
3100 gtk_tree_path_up (ppath);
3101 parent = find_menu_by_path (combo_box->priv->popup_widget, ppath, FALSE);
3102 gtk_tree_path_free (ppath);
3104 menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (parent));
3107 menu = gtk_menu_new ();
3108 gtk_widget_show (menu);
3109 gtk_menu_item_set_submenu (GTK_MENU_ITEM (parent), menu);
3111 /* Ugly - since menus can only activate leaves, we have to
3112 * duplicate the item inside the submenu.
3114 gtk_tree_model_iter_parent (model, &piter, iter);
3115 item = gtk_cell_view_menu_item_new (combo_box, model, &piter);
3116 separator = gtk_separator_menu_item_new ();
3117 g_signal_connect (item, "activate",
3118 G_CALLBACK (gtk_combo_box_menu_item_activate),
3120 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
3121 gtk_menu_shell_append (GTK_MENU_SHELL (menu), separator);
3122 if (cell_view_is_sensitive (GTK_CELL_VIEW (GTK_BIN (item)->child)))
3124 gtk_widget_show (item);
3125 gtk_widget_show (separator);
3132 menu = combo_box->priv->popup_widget;
3133 if (combo_box->priv->add_tearoffs)
3137 if (combo_box->priv->row_separator_func)
3138 is_separator = (*combo_box->priv->row_separator_func) (model, iter,
3139 combo_box->priv->row_separator_data);
3141 is_separator = FALSE;
3145 item = gtk_separator_menu_item_new ();
3146 g_object_set_data_full (G_OBJECT (item),
3147 I_("gtk-combo-box-item-path"),
3148 gtk_tree_row_reference_new (model, path),
3149 (GDestroyNotify)gtk_tree_row_reference_free);
3153 item = gtk_cell_view_menu_item_new (combo_box, model, iter);
3155 g_signal_connect (item, "activate",
3156 G_CALLBACK (gtk_combo_box_menu_item_activate),
3160 gtk_widget_show (item);
3161 gtk_menu_shell_insert (GTK_MENU_SHELL (menu), item, pos);
3165 gtk_combo_box_menu_row_deleted (GtkTreeModel *model,
3169 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3173 if (!combo_box->priv->popup_widget)
3176 item = find_menu_by_path (combo_box->priv->popup_widget, path, FALSE);
3177 menu = gtk_widget_get_parent (item);
3178 gtk_container_remove (GTK_CONTAINER (menu), item);
3182 gtk_combo_box_menu_rows_reordered (GtkTreeModel *model,
3188 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3190 gtk_combo_box_relayout (combo_box);
3194 gtk_combo_box_menu_row_changed (GtkTreeModel *model,
3199 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3202 gboolean is_separator;
3204 if (!combo_box->priv->popup_widget)
3207 item = find_menu_by_path (combo_box->priv->popup_widget, path, FALSE);
3209 if (combo_box->priv->row_separator_func)
3210 is_separator = (*combo_box->priv->row_separator_func) (model, iter,
3211 combo_box->priv->row_separator_data);
3213 is_separator = FALSE;
3215 if (is_separator != GTK_IS_SEPARATOR_MENU_ITEM (item))
3217 gtk_combo_box_menu_row_deleted (model, path, combo_box);
3218 gtk_combo_box_menu_row_inserted (model, path, iter, combo_box);
3221 if (combo_box->priv->wrap_width
3222 && item->parent == combo_box->priv->popup_widget)
3224 GtkWidget *pitem = NULL;
3227 prev = gtk_tree_path_copy (path);
3229 if (gtk_tree_path_prev (prev))
3230 pitem = find_menu_by_path (combo_box->priv->popup_widget, prev, FALSE);
3232 gtk_tree_path_free (prev);
3234 /* unattach item so gtk_combo_box_relayout_item() won't spuriously
3236 gtk_container_child_set (GTK_CONTAINER (combo_box->priv->popup_widget),
3241 "bottom-attach", -1,
3244 gtk_combo_box_relayout_item (combo_box, item, iter, pitem);
3247 width = gtk_combo_box_calc_requested_width (combo_box, path);
3249 if (width > combo_box->priv->width)
3251 if (combo_box->priv->cell_view)
3253 gtk_widget_set_size_request (combo_box->priv->cell_view, width, -1);
3254 gtk_widget_queue_resize (combo_box->priv->cell_view);
3256 combo_box->priv->width = width;
3265 gtk_combo_box_list_setup (GtkComboBox *combo_box)
3267 GtkTreeSelection *sel;
3269 combo_box->priv->button = gtk_toggle_button_new ();
3270 gtk_widget_set_parent (combo_box->priv->button,
3271 GTK_BIN (combo_box)->child->parent);
3272 g_signal_connect (combo_box->priv->button, "button_press_event",
3273 G_CALLBACK (gtk_combo_box_list_button_pressed), combo_box);
3274 g_signal_connect (combo_box->priv->button, "toggled",
3275 G_CALLBACK (gtk_combo_box_button_toggled), combo_box);
3276 g_signal_connect_after (combo_box, "key_press_event",
3277 G_CALLBACK (gtk_combo_box_key_press), combo_box);
3279 combo_box->priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
3280 gtk_container_add (GTK_CONTAINER (combo_box->priv->button),
3281 combo_box->priv->arrow);
3282 combo_box->priv->separator = NULL;
3283 gtk_widget_show_all (combo_box->priv->button);
3285 if (combo_box->priv->cell_view)
3287 gtk_cell_view_set_background_color (GTK_CELL_VIEW (combo_box->priv->cell_view),
3288 >K_WIDGET (combo_box)->style->base[GTK_WIDGET_STATE (combo_box)]);
3290 combo_box->priv->box = gtk_event_box_new ();
3291 gtk_event_box_set_visible_window (GTK_EVENT_BOX (combo_box->priv->box),
3294 if (combo_box->priv->has_frame)
3296 combo_box->priv->cell_view_frame = gtk_frame_new (NULL);
3297 gtk_frame_set_shadow_type (GTK_FRAME (combo_box->priv->cell_view_frame),
3302 combo_box->priv->cell_view_frame = gtk_event_box_new ();
3303 gtk_event_box_set_visible_window (GTK_EVENT_BOX (combo_box->priv->cell_view_frame),
3307 gtk_widget_set_parent (combo_box->priv->cell_view_frame,
3308 GTK_BIN (combo_box)->child->parent);
3309 gtk_container_add (GTK_CONTAINER (combo_box->priv->cell_view_frame),
3310 combo_box->priv->box);
3311 gtk_widget_show_all (combo_box->priv->cell_view_frame);
3313 g_signal_connect (combo_box->priv->box, "button_press_event",
3314 G_CALLBACK (gtk_combo_box_list_button_pressed),
3318 combo_box->priv->tree_view = gtk_tree_view_new ();
3319 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (combo_box->priv->tree_view));
3320 gtk_tree_selection_set_mode (sel, GTK_SELECTION_BROWSE);
3321 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (combo_box->priv->tree_view),
3323 gtk_tree_view_set_hover_selection (GTK_TREE_VIEW (combo_box->priv->tree_view),
3325 if (combo_box->priv->row_separator_func)
3326 gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (combo_box->priv->tree_view),
3327 combo_box->priv->row_separator_func,
3328 combo_box->priv->row_separator_data,
3330 if (combo_box->priv->model)
3331 gtk_tree_view_set_model (GTK_TREE_VIEW (combo_box->priv->tree_view),
3332 combo_box->priv->model);
3334 combo_box->priv->column = gtk_tree_view_column_new ();
3335 gtk_tree_view_append_column (GTK_TREE_VIEW (combo_box->priv->tree_view),
3336 combo_box->priv->column);
3339 gtk_combo_box_sync_cells (combo_box,
3340 GTK_CELL_LAYOUT (combo_box->priv->column));
3342 if (gtk_tree_row_reference_valid (combo_box->priv->active_row))
3346 path = gtk_tree_row_reference_get_path (combo_box->priv->active_row);
3347 gtk_tree_view_set_cursor (GTK_TREE_VIEW (combo_box->priv->tree_view),
3349 gtk_tree_path_free (path);
3352 /* set sample/popup widgets */
3353 gtk_combo_box_set_popup_widget (combo_box, combo_box->priv->tree_view);
3355 g_signal_connect (combo_box->priv->tree_view, "key_press_event",
3356 G_CALLBACK (gtk_combo_box_list_key_press),
3358 g_signal_connect (combo_box->priv->tree_view, "enter_notify_event",
3359 G_CALLBACK (gtk_combo_box_list_enter_notify),
3361 g_signal_connect (combo_box->priv->tree_view, "row_expanded",
3362 G_CALLBACK (gtk_combo_box_model_row_expanded),
3364 g_signal_connect (combo_box->priv->tree_view, "row_collapsed",
3365 G_CALLBACK (gtk_combo_box_model_row_expanded),
3367 g_signal_connect (combo_box->priv->popup_window, "button_press_event",
3368 G_CALLBACK (gtk_combo_box_list_button_pressed),
3370 g_signal_connect (combo_box->priv->popup_window, "button_release_event",
3371 G_CALLBACK (gtk_combo_box_list_button_released),
3374 gtk_widget_show (combo_box->priv->tree_view);
3378 gtk_combo_box_list_destroy (GtkComboBox *combo_box)
3380 /* disconnect signals */
3381 g_signal_handlers_disconnect_matched (combo_box->priv->tree_view,
3382 G_SIGNAL_MATCH_DATA,
3383 0, 0, NULL, NULL, combo_box);
3384 g_signal_handlers_disconnect_matched (combo_box->priv->button,
3385 G_SIGNAL_MATCH_DATA,
3387 gtk_combo_box_list_button_pressed,
3389 g_signal_handlers_disconnect_matched (combo_box->priv->popup_window,
3390 G_SIGNAL_MATCH_DATA,
3392 gtk_combo_box_list_button_pressed,
3394 g_signal_handlers_disconnect_matched (combo_box->priv->popup_window,
3395 G_SIGNAL_MATCH_DATA,
3397 gtk_combo_box_list_button_released,
3400 g_signal_handlers_disconnect_matched (combo_box->priv->popup_window,
3401 G_SIGNAL_MATCH_DATA,
3403 gtk_combo_box_child_show,
3406 g_signal_handlers_disconnect_matched (combo_box->priv->popup_window,
3407 G_SIGNAL_MATCH_DATA,
3409 gtk_combo_box_child_hide,
3412 if (combo_box->priv->box)
3413 g_signal_handlers_disconnect_matched (combo_box->priv->box,
3414 G_SIGNAL_MATCH_DATA,
3416 gtk_combo_box_list_button_pressed,
3419 /* destroy things (unparent will kill the latest ref from us)
3420 * last unref on button will destroy the arrow
3422 gtk_widget_unparent (combo_box->priv->button);
3423 combo_box->priv->button = NULL;
3424 combo_box->priv->arrow = NULL;
3426 if (combo_box->priv->cell_view)
3428 g_object_set (combo_box->priv->cell_view,
3429 "background-set", FALSE,
3433 if (combo_box->priv->cell_view_frame)
3435 gtk_widget_unparent (combo_box->priv->cell_view_frame);
3436 combo_box->priv->cell_view_frame = NULL;
3437 combo_box->priv->box = NULL;
3440 if (combo_box->priv->scroll_timer)
3442 g_source_remove (combo_box->priv->scroll_timer);
3443 combo_box->priv->scroll_timer = 0;
3446 if (combo_box->priv->resize_idle_id)
3448 g_source_remove (combo_box->priv->resize_idle_id);
3449 combo_box->priv->resize_idle_id = 0;
3452 gtk_widget_destroy (combo_box->priv->tree_view);
3454 combo_box->priv->tree_view = NULL;
3455 combo_box->priv->popup_widget = NULL;
3461 gtk_combo_box_list_button_pressed (GtkWidget *widget,
3462 GdkEventButton *event,
3465 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3467 GtkWidget *ewidget = gtk_get_event_widget ((GdkEvent *)event);
3469 if (ewidget == combo_box->priv->popup_window)
3472 if ((ewidget != combo_box->priv->button && ewidget != combo_box->priv->box) ||
3473 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (combo_box->priv->button)))
3476 if (combo_box->priv->focus_on_click &&
3477 !GTK_WIDGET_HAS_FOCUS (combo_box->priv->button))
3478 gtk_widget_grab_focus (combo_box->priv->button);
3480 gtk_combo_box_popup (combo_box);
3482 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
3485 combo_box->priv->auto_scroll = FALSE;
3486 if (combo_box->priv->scroll_timer == 0)
3487 combo_box->priv->scroll_timer = g_timeout_add (SCROLL_TIME,
3488 (GSourceFunc) gtk_combo_box_list_scroll_timeout,
3491 combo_box->priv->popup_in_progress = TRUE;
3497 gtk_combo_box_list_button_released (GtkWidget *widget,
3498 GdkEventButton *event,
3502 GtkTreePath *path = NULL;
3505 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3507 gboolean popup_in_progress = FALSE;
3509 GtkWidget *ewidget = gtk_get_event_widget ((GdkEvent *)event);
3511 if (combo_box->priv->popup_in_progress)
3513 popup_in_progress = TRUE;
3514 combo_box->priv->popup_in_progress = FALSE;
3517 gtk_tree_view_set_hover_expand (GTK_TREE_VIEW (combo_box->priv->tree_view),
3519 if (combo_box->priv->scroll_timer)
3521 g_source_remove (combo_box->priv->scroll_timer);
3522 combo_box->priv->scroll_timer = 0;
3525 if (ewidget != combo_box->priv->tree_view)
3527 if ((ewidget == combo_box->priv->button ||
3528 ewidget == combo_box->priv->box) &&
3529 !popup_in_progress &&
3530 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (combo_box->priv->button)))
3532 gtk_combo_box_popdown (combo_box);
3536 /* released outside treeview */
3537 if (ewidget != combo_box->priv->button &&
3538 ewidget != combo_box->priv->box)
3540 gtk_combo_box_popdown (combo_box);
3548 /* select something cool */
3549 ret = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (combo_box->priv->tree_view),
3555 return TRUE; /* clicked outside window? */
3557 gtk_tree_model_get_iter (combo_box->priv->model, &iter, path);
3558 gtk_tree_path_free (path);
3560 if (tree_column_row_is_sensitive (combo_box, &iter))
3561 gtk_combo_box_set_active_iter (combo_box, &iter);
3563 gtk_combo_box_popdown (combo_box);
3569 gtk_combo_box_key_press (GtkWidget *widget,
3573 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3574 guint state = event->state & gtk_accelerator_get_default_mod_mask ();
3577 GtkTreeIter new_iter;
3579 if (combo_box->priv->model == NULL)
3582 if ((event->keyval == GDK_Down || event->keyval == GDK_KP_Down) &&
3583 state == GDK_MOD1_MASK)
3585 gtk_combo_box_popup (combo_box);
3593 switch (event->keyval)
3597 if (gtk_combo_box_get_active_iter (combo_box, &iter))
3599 found = tree_next (combo_box, combo_box->priv->model,
3600 &iter, &new_iter, FALSE);
3603 /* else fall through */
3605 case GDK_KP_Page_Up:
3608 found = tree_first (combo_box, combo_box->priv->model, &new_iter, FALSE);
3613 if (gtk_combo_box_get_active_iter (combo_box, &iter))
3615 found = tree_prev (combo_box, combo_box->priv->model,
3616 &iter, &new_iter, FALSE);
3619 /* else fall through */
3621 case GDK_KP_Page_Down:
3624 found = tree_last (combo_box, combo_box->priv->model, &new_iter, FALSE);
3631 gtk_combo_box_set_active_iter (combo_box, &new_iter);
3637 gtk_combo_box_menu_key_press (GtkWidget *widget,
3641 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3642 guint state = event->state & gtk_accelerator_get_default_mod_mask ();
3644 if ((event->keyval == GDK_Up || event->keyval == GDK_KP_Up) &&
3645 state == GDK_MOD1_MASK)
3647 gtk_combo_box_popdown (combo_box);
3656 gtk_combo_box_list_key_press (GtkWidget *widget,
3660 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3662 guint state = event->state & gtk_accelerator_get_default_mod_mask ();
3664 if (event->keyval == GDK_Escape ||
3665 ((event->keyval == GDK_Up || event->keyval == GDK_KP_Up) &&
3666 state == GDK_MOD1_MASK))
3668 /* reset active item -- this is incredibly lame and ugly */
3669 if (gtk_combo_box_get_active_iter (combo_box, &iter))
3670 gtk_combo_box_set_active_iter (combo_box, &iter);
3672 gtk_combo_box_popdown (combo_box);
3677 if (event->keyval == GDK_Return || event->keyval == GDK_KP_Enter ||
3678 event->keyval == GDK_space || event->keyval == GDK_KP_Space)
3681 GtkTreeModel *model = NULL;
3683 if (combo_box->priv->model)
3685 GtkTreeSelection *sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (combo_box->priv->tree_view));
3687 if (gtk_tree_selection_get_selected (sel, &model, &iter))
3688 gtk_combo_box_set_active_iter (combo_box, &iter);
3691 gtk_combo_box_popdown (combo_box);
3700 gtk_combo_box_list_auto_scroll (GtkComboBox *combo_box,
3704 GtkWidget *tree_view = combo_box->priv->tree_view;
3708 adj = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (combo_box->priv->scrolled_window));
3709 if (adj && adj->upper - adj->lower > adj->page_size)
3711 if (x <= tree_view->allocation.x &&
3712 adj->lower < adj->value)
3714 value = adj->value - (tree_view->allocation.x - x + 1);
3715 gtk_adjustment_set_value (adj, CLAMP (value, adj->lower, adj->upper - adj->page_size));
3717 else if (x >= tree_view->allocation.x + tree_view->allocation.width &&
3718 adj->upper - adj->page_size > adj->value)
3720 value = adj->value + (x - tree_view->allocation.x - tree_view->allocation.width + 1);
3721 gtk_adjustment_set_value (adj, CLAMP (value, 0.0, adj->upper - adj->page_size));
3725 adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (combo_box->priv->scrolled_window));
3726 if (adj && adj->upper - adj->lower > adj->page_size)
3728 if (y <= tree_view->allocation.y &&
3729 adj->lower < adj->value)
3731 value = adj->value - (tree_view->allocation.y - y + 1);
3732 gtk_adjustment_set_value (adj, CLAMP (value, adj->lower, adj->upper - adj->page_size));
3734 else if (y >= tree_view->allocation.height &&
3735 adj->upper - adj->page_size > adj->value)
3737 value = adj->value + (y - tree_view->allocation.height + 1);
3738 gtk_adjustment_set_value (adj, CLAMP (value, 0.0, adj->upper - adj->page_size));
3744 gtk_combo_box_list_scroll_timeout (GtkComboBox *combo_box)
3748 GDK_THREADS_ENTER ();
3750 if (combo_box->priv->auto_scroll)
3752 gdk_window_get_pointer (combo_box->priv->tree_view->window,
3754 gtk_combo_box_list_auto_scroll (combo_box, x, y);
3757 GDK_THREADS_LEAVE ();
3763 gtk_combo_box_list_enter_notify (GtkWidget *widget,
3764 GdkEventCrossing *event,
3767 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3769 combo_box->priv->auto_scroll = TRUE;
3776 gtk_combo_box_list_row_changed (GtkTreeModel *model,
3781 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3784 width = gtk_combo_box_calc_requested_width (combo_box, path);
3786 if (width > combo_box->priv->width)
3788 if (combo_box->priv->cell_view)
3790 gtk_widget_set_size_request (combo_box->priv->cell_view, width, -1);
3791 gtk_widget_queue_resize (combo_box->priv->cell_view);
3793 combo_box->priv->width = width;
3798 * GtkCellLayout implementation
3802 pack_start_recurse (GtkWidget *menu,
3803 GtkCellRenderer *cell,
3809 list = gtk_container_get_children (GTK_CONTAINER (menu));
3810 for (i = list; i; i = i->next)
3812 if (GTK_IS_CELL_LAYOUT (GTK_BIN (i->data)->child))
3813 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (GTK_BIN (i->data)->child),
3816 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
3817 if (submenu != NULL)
3818 pack_start_recurse (submenu, cell, expand);
3825 gtk_combo_box_cell_layout_pack_start (GtkCellLayout *layout,
3826 GtkCellRenderer *cell,
3829 ComboCellInfo *info;
3830 GtkComboBox *combo_box;
3832 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
3833 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
3835 combo_box = GTK_COMBO_BOX (layout);
3837 g_object_ref_sink (cell);
3839 info = g_new0 (ComboCellInfo, 1);
3841 info->expand = expand;
3842 info->pack = GTK_PACK_START;
3844 combo_box->priv->cells = g_slist_append (combo_box->priv->cells, info);
3846 if (combo_box->priv->cell_view)
3847 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box->priv->cell_view),
3850 if (combo_box->priv->column)
3851 gtk_tree_view_column_pack_start (combo_box->priv->column, cell, expand);
3853 if (GTK_IS_MENU (combo_box->priv->popup_widget))
3854 pack_start_recurse (combo_box->priv->popup_widget, cell, expand);
3858 pack_end_recurse (GtkWidget *menu,
3859 GtkCellRenderer *cell,
3865 list = gtk_container_get_children (GTK_CONTAINER (menu));
3866 for (i = list; i; i = i->next)
3868 if (GTK_IS_CELL_LAYOUT (GTK_BIN (i->data)->child))
3869 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (GTK_BIN (i->data)->child),
3872 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
3873 if (submenu != NULL)
3874 pack_end_recurse (submenu, cell, expand);
3881 gtk_combo_box_cell_layout_pack_end (GtkCellLayout *layout,
3882 GtkCellRenderer *cell,
3885 ComboCellInfo *info;
3886 GtkComboBox *combo_box;
3888 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
3889 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
3891 combo_box = GTK_COMBO_BOX (layout);
3893 g_object_ref_sink (cell);
3895 info = g_new0 (ComboCellInfo, 1);
3897 info->expand = expand;
3898 info->pack = GTK_PACK_END;
3900 combo_box->priv->cells = g_slist_append (combo_box->priv->cells, info);
3902 if (combo_box->priv->cell_view)
3903 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (combo_box->priv->cell_view),
3906 if (combo_box->priv->column)
3907 gtk_tree_view_column_pack_end (combo_box->priv->column, cell, expand);
3909 if (GTK_IS_MENU (combo_box->priv->popup_widget))
3910 pack_end_recurse (combo_box->priv->popup_widget, cell, expand);
3914 clear_recurse (GtkWidget *menu)
3919 list = gtk_container_get_children (GTK_CONTAINER (menu));
3920 for (i = list; i; i = i->next)
3922 if (GTK_IS_CELL_LAYOUT (GTK_BIN (i->data)->child))
3923 gtk_cell_layout_clear (GTK_CELL_LAYOUT (GTK_BIN (i->data)->child));
3925 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
3926 if (submenu != NULL)
3927 clear_recurse (submenu);
3934 gtk_combo_box_cell_layout_clear (GtkCellLayout *layout)
3936 GtkComboBox *combo_box;
3939 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
3941 combo_box = GTK_COMBO_BOX (layout);
3943 if (combo_box->priv->cell_view)
3944 gtk_cell_layout_clear (GTK_CELL_LAYOUT (combo_box->priv->cell_view));
3946 if (combo_box->priv->column)
3947 gtk_tree_view_column_clear (combo_box->priv->column);
3949 for (i = combo_box->priv->cells; i; i = i->next)
3951 ComboCellInfo *info = (ComboCellInfo *)i->data;
3953 gtk_combo_box_cell_layout_clear_attributes (layout, info->cell);
3954 g_object_unref (info->cell);
3958 g_slist_free (combo_box->priv->cells);
3959 combo_box->priv->cells = NULL;
3961 if (GTK_IS_MENU (combo_box->priv->popup_widget))
3962 clear_recurse (combo_box->priv->popup_widget);
3966 add_attribute_recurse (GtkWidget *menu,
3967 GtkCellRenderer *cell,
3968 const gchar *attribute,
3974 list = gtk_container_get_children (GTK_CONTAINER (menu));
3975 for (i = list; i; i = i->next)
3977 if (GTK_IS_CELL_LAYOUT (GTK_BIN (i->data)->child))
3978 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (GTK_BIN (i->data)->child),
3979 cell, attribute, column);
3981 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
3982 if (submenu != NULL)
3983 add_attribute_recurse (submenu, cell, attribute, column);
3990 gtk_combo_box_cell_layout_add_attribute (GtkCellLayout *layout,
3991 GtkCellRenderer *cell,
3992 const gchar *attribute,
3995 ComboCellInfo *info;
3996 GtkComboBox *combo_box;
3998 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
3999 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4001 combo_box = GTK_COMBO_BOX (layout);
4003 info = gtk_combo_box_get_cell_info (combo_box, cell);
4005 info->attributes = g_slist_prepend (info->attributes,
4006 GINT_TO_POINTER (column));
4007 info->attributes = g_slist_prepend (info->attributes,
4008 g_strdup (attribute));
4010 if (combo_box->priv->cell_view)
4011 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo_box->priv->cell_view),
4012 cell, attribute, column);
4014 if (combo_box->priv->column)
4015 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo_box->priv->column),
4016 cell, attribute, column);
4018 if (GTK_IS_MENU (combo_box->priv->popup_widget))
4019 add_attribute_recurse (combo_box->priv->popup_widget, cell, attribute, column);
4020 gtk_widget_queue_resize (GTK_WIDGET (combo_box));
4024 combo_cell_data_func (GtkCellLayout *cell_layout,
4025 GtkCellRenderer *cell,
4026 GtkTreeModel *tree_model,
4030 ComboCellInfo *info = (ComboCellInfo *)data;
4031 GtkWidget *parent = NULL;
4036 (*info->func) (cell_layout, cell, tree_model, iter, info->func_data);
4038 if (GTK_IS_WIDGET (cell_layout))
4039 parent = gtk_widget_get_parent (GTK_WIDGET (cell_layout));
4041 if (GTK_IS_MENU_ITEM (parent) &&
4042 gtk_menu_item_get_submenu (GTK_MENU_ITEM (parent)))
4043 g_object_set (cell, "sensitive", TRUE, NULL);
4048 set_cell_data_func_recurse (GtkWidget *menu,
4049 GtkCellRenderer *cell,
4050 ComboCellInfo *info)
4054 GtkWidget *cell_view;
4056 list = gtk_container_get_children (GTK_CONTAINER (menu));
4057 for (i = list; i; i = i->next)
4059 cell_view = GTK_BIN (i->data)->child;
4060 if (GTK_IS_CELL_LAYOUT (cell_view))
4062 /* Override sensitivity for inner nodes; we don't
4063 * want menuitems with submenus to appear insensitive
4065 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (cell_view),
4067 combo_cell_data_func,
4069 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4070 if (submenu != NULL)
4071 set_cell_data_func_recurse (submenu, cell, info);
4079 gtk_combo_box_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4080 GtkCellRenderer *cell,
4081 GtkCellLayoutDataFunc func,
4083 GDestroyNotify destroy)
4085 ComboCellInfo *info;
4086 GtkComboBox *combo_box;
4088 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
4090 combo_box = GTK_COMBO_BOX (layout);
4092 info = gtk_combo_box_get_cell_info (combo_box, cell);
4093 g_return_if_fail (info != NULL);
4097 GDestroyNotify d = info->destroy;
4099 info->destroy = NULL;
4100 d (info->func_data);
4104 info->func_data = func_data;
4105 info->destroy = destroy;
4107 if (combo_box->priv->cell_view)
4108 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo_box->priv->cell_view), cell, func, func_data, NULL);
4110 if (combo_box->priv->column)
4111 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo_box->priv->column), cell, func, func_data, NULL);
4113 if (GTK_IS_MENU (combo_box->priv->popup_widget))
4114 set_cell_data_func_recurse (combo_box->priv->popup_widget, cell, info);
4116 gtk_widget_queue_resize (GTK_WIDGET (combo_box));
4120 clear_attributes_recurse (GtkWidget *menu,
4121 GtkCellRenderer *cell)
4126 list = gtk_container_get_children (GTK_CONTAINER (menu));
4127 for (i = list; i; i = i->next)
4129 if (GTK_IS_CELL_LAYOUT (GTK_BIN (i->data)->child))
4130 gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (GTK_BIN (i->data)->child),
4133 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4134 if (submenu != NULL)
4135 clear_attributes_recurse (submenu, cell);
4142 gtk_combo_box_cell_layout_clear_attributes (GtkCellLayout *layout,
4143 GtkCellRenderer *cell)
4145 ComboCellInfo *info;
4146 GtkComboBox *combo_box;
4149 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
4150 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4152 combo_box = GTK_COMBO_BOX (layout);
4154 info = gtk_combo_box_get_cell_info (combo_box, cell);
4155 g_return_if_fail (info != NULL);
4157 list = info->attributes;
4158 while (list && list->next)
4160 g_free (list->data);
4161 list = list->next->next;
4163 g_slist_free (info->attributes);
4164 info->attributes = NULL;
4166 if (combo_box->priv->cell_view)
4167 gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (combo_box->priv->cell_view), cell);
4169 if (combo_box->priv->column)
4170 gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (combo_box->priv->column), cell);
4172 if (GTK_IS_MENU (combo_box->priv->popup_widget))
4173 clear_attributes_recurse (combo_box->priv->popup_widget, cell);
4175 gtk_widget_queue_resize (GTK_WIDGET (combo_box));
4179 reorder_recurse (GtkWidget *menu,
4180 GtkCellRenderer *cell,
4186 list = gtk_container_get_children (GTK_CONTAINER (menu));
4187 for (i = list; i; i = i->next)
4189 if (GTK_IS_CELL_LAYOUT (GTK_BIN (i->data)->child))
4190 gtk_cell_layout_reorder (GTK_CELL_LAYOUT (GTK_BIN (i->data)->child),
4193 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4194 if (submenu != NULL)
4195 reorder_recurse (submenu, cell, position);
4202 gtk_combo_box_cell_layout_reorder (GtkCellLayout *layout,
4203 GtkCellRenderer *cell,
4206 ComboCellInfo *info;
4207 GtkComboBox *combo_box;
4210 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
4211 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4213 combo_box = GTK_COMBO_BOX (layout);
4215 info = gtk_combo_box_get_cell_info (combo_box, cell);
4217 g_return_if_fail (info != NULL);
4218 g_return_if_fail (position >= 0);
4220 link = g_slist_find (combo_box->priv->cells, info);
4222 g_return_if_fail (link != NULL);
4224 combo_box->priv->cells = g_slist_remove_link (combo_box->priv->cells, link);
4225 combo_box->priv->cells = g_slist_insert (combo_box->priv->cells, info,
4228 if (combo_box->priv->cell_view)
4229 gtk_cell_layout_reorder (GTK_CELL_LAYOUT (combo_box->priv->cell_view),
4232 if (combo_box->priv->column)
4233 gtk_cell_layout_reorder (GTK_CELL_LAYOUT (combo_box->priv->column),
4236 if (GTK_IS_MENU (combo_box->priv->popup_widget))
4237 reorder_recurse (combo_box->priv->popup_widget, cell, position);
4239 gtk_widget_queue_draw (GTK_WIDGET (combo_box));
4247 * gtk_combo_box_new:
4249 * Creates a new empty #GtkComboBox.
4251 * Return value: A new #GtkComboBox.
4256 gtk_combo_box_new (void)
4258 return g_object_new (GTK_TYPE_COMBO_BOX, NULL);
4262 * gtk_combo_box_new_with_model:
4263 * @model: A #GtkTreeModel.
4265 * Creates a new #GtkComboBox with the model initialized to @model.
4267 * Return value: A new #GtkComboBox.
4272 gtk_combo_box_new_with_model (GtkTreeModel *model)
4274 GtkComboBox *combo_box;
4276 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
4278 combo_box = g_object_new (GTK_TYPE_COMBO_BOX, "model", model, NULL);
4280 return GTK_WIDGET (combo_box);
4284 * gtk_combo_box_get_wrap_width:
4285 * @combo_box: A #GtkComboBox.
4287 * Returns the wrap width which is used to determine the number
4288 * of columns for the popup menu. If the wrap width is larger than
4289 * 1, the combo box is in table mode.
4291 * Returns: the wrap width.
4296 gtk_combo_box_get_wrap_width (GtkComboBox *combo_box)
4298 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), -1);
4300 return combo_box->priv->wrap_width;
4304 * gtk_combo_box_set_wrap_width:
4305 * @combo_box: A #GtkComboBox.
4306 * @width: Preferred number of columns.
4308 * Sets the wrap width of @combo_box to be @width. The wrap width is basically
4309 * the preferred number of columns when you want the popup to be layed out
4315 gtk_combo_box_set_wrap_width (GtkComboBox *combo_box,
4318 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4319 g_return_if_fail (width >= 0);
4321 if (width != combo_box->priv->wrap_width)
4323 combo_box->priv->wrap_width = width;
4325 gtk_combo_box_check_appearance (combo_box);
4326 gtk_combo_box_relayout (combo_box);
4328 g_object_notify (G_OBJECT (combo_box), "wrap-width");
4333 * gtk_combo_box_get_row_span_column:
4334 * @combo_box: A #GtkComboBox.
4336 * Returns the column with row span information for @combo_box.
4338 * Returns: the row span column.
4343 gtk_combo_box_get_row_span_column (GtkComboBox *combo_box)
4345 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), -1);
4347 return combo_box->priv->row_column;
4351 * gtk_combo_box_set_row_span_column:
4352 * @combo_box: A #GtkComboBox.
4353 * @row_span: A column in the model passed during construction.
4355 * Sets the column with row span information for @combo_box to be @row_span.
4356 * The row span column contains integers which indicate how many rows
4357 * an item should span.
4362 gtk_combo_box_set_row_span_column (GtkComboBox *combo_box,
4367 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4369 col = gtk_tree_model_get_n_columns (combo_box->priv->model);
4370 g_return_if_fail (row_span >= -1 && row_span < col);
4372 if (row_span != combo_box->priv->row_column)
4374 combo_box->priv->row_column = row_span;
4376 gtk_combo_box_relayout (combo_box);
4378 g_object_notify (G_OBJECT (combo_box), "row-span-column");
4383 * gtk_combo_box_get_column_span_column:
4384 * @combo_box: A #GtkComboBox.
4386 * Returns the column with column span information for @combo_box.
4388 * Returns: the column span column.
4393 gtk_combo_box_get_column_span_column (GtkComboBox *combo_box)
4395 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), -1);
4397 return combo_box->priv->col_column;
4401 * gtk_combo_box_set_column_span_column:
4402 * @combo_box: A #GtkComboBox.
4403 * @column_span: A column in the model passed during construction.
4405 * Sets the column with column span information for @combo_box to be
4406 * @column_span. The column span column contains integers which indicate
4407 * how many columns an item should span.
4412 gtk_combo_box_set_column_span_column (GtkComboBox *combo_box,
4417 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4419 col = gtk_tree_model_get_n_columns (combo_box->priv->model);
4420 g_return_if_fail (column_span >= -1 && column_span < col);
4422 if (column_span != combo_box->priv->col_column)
4424 combo_box->priv->col_column = column_span;
4426 gtk_combo_box_relayout (combo_box);
4428 g_object_notify (G_OBJECT (combo_box), "column-span-column");
4433 * gtk_combo_box_get_active:
4434 * @combo_box: A #GtkComboBox.
4436 * Returns the index of the currently active item, or -1 if there's no
4437 * active item. If the model is a non-flat treemodel, and the active item
4438 * is not an immediate child of the root of the tree, this function returns
4439 * <literal>gtk_tree_path_get_indices (path)[0]</literal>, where
4440 * <literal>path</literal> is the #GtkTreePath of the active item.
4442 * Return value: An integer which is the index of the currently active item, or
4443 * -1 if there's no active item.
4448 gtk_combo_box_get_active (GtkComboBox *combo_box)
4451 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), 0);
4453 if (gtk_tree_row_reference_valid (combo_box->priv->active_row))
4457 path = gtk_tree_row_reference_get_path (combo_box->priv->active_row);
4458 result = gtk_tree_path_get_indices (path)[0];
4459 gtk_tree_path_free (path);
4468 * gtk_combo_box_set_active:
4469 * @combo_box: A #GtkComboBox.
4470 * @index_: An index in the model passed during construction, or -1 to have
4473 * Sets the active item of @combo_box to be the item at @index.
4478 gtk_combo_box_set_active (GtkComboBox *combo_box,
4481 GtkTreePath *path = NULL;
4482 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4483 g_return_if_fail (index_ >= -1);
4486 path = gtk_tree_path_new_from_indices (index_, -1);
4488 gtk_combo_box_set_active_internal (combo_box, path);
4491 gtk_tree_path_free (path);
4495 gtk_combo_box_set_active_internal (GtkComboBox *combo_box,
4498 GtkTreePath *active_path;
4501 if (path && gtk_tree_row_reference_valid (combo_box->priv->active_row))
4503 active_path = gtk_tree_row_reference_get_path (combo_box->priv->active_row);
4504 path_cmp = gtk_tree_path_compare (path, active_path);
4505 gtk_tree_path_free (active_path);
4510 if (combo_box->priv->active_row)
4512 gtk_tree_row_reference_free (combo_box->priv->active_row);
4513 combo_box->priv->active_row = NULL;
4518 if (combo_box->priv->tree_view)
4519 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (combo_box->priv->tree_view)));
4522 GtkMenu *menu = GTK_MENU (combo_box->priv->popup_widget);
4524 if (GTK_IS_MENU (menu))
4525 gtk_menu_set_active (menu, -1);
4528 if (combo_box->priv->cell_view)
4529 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (combo_box->priv->cell_view), NULL);
4533 combo_box->priv->active_row =
4534 gtk_tree_row_reference_new (combo_box->priv->model, path);
4536 if (combo_box->priv->tree_view)
4538 gtk_tree_view_set_cursor (GTK_TREE_VIEW (combo_box->priv->tree_view),
4541 else if (GTK_IS_MENU (combo_box->priv->popup_widget))
4543 /* FIXME handle nested menus better */
4544 gtk_menu_set_active (GTK_MENU (combo_box->priv->popup_widget),
4545 gtk_tree_path_get_indices (path)[0]);
4548 if (combo_box->priv->cell_view)
4549 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (combo_box->priv->cell_view),
4553 g_signal_emit (combo_box, combo_box_signals[CHANGED], 0);
4554 g_object_notify (G_OBJECT (combo_box), "active");
4559 * gtk_combo_box_get_active_iter:
4560 * @combo_box: A #GtkComboBox
4561 * @iter: The uninitialized #GtkTreeIter.
4563 * Sets @iter to point to the current active item, if it exists.
4565 * Return value: %TRUE, if @iter was set
4570 gtk_combo_box_get_active_iter (GtkComboBox *combo_box,
4576 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE);
4578 if (!gtk_tree_row_reference_valid (combo_box->priv->active_row))
4581 path = gtk_tree_row_reference_get_path (combo_box->priv->active_row);
4582 result = gtk_tree_model_get_iter (combo_box->priv->model, iter, path);
4583 gtk_tree_path_free (path);
4589 * gtk_combo_box_set_active_iter:
4590 * @combo_box: A #GtkComboBox
4591 * @iter: The #GtkTreeIter.
4593 * Sets the current active item to be the one referenced by @iter.
4594 * @iter must correspond to a path of depth one.
4599 gtk_combo_box_set_active_iter (GtkComboBox *combo_box,
4604 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4606 path = gtk_tree_model_get_path (gtk_combo_box_get_model (combo_box), iter);
4607 gtk_combo_box_set_active_internal (combo_box, path);
4608 gtk_tree_path_free (path);
4612 * gtk_combo_box_set_model:
4613 * @combo_box: A #GtkComboBox.
4614 * @model: A #GtkTreeModel.
4616 * Sets the model used by @combo_box to be @model. Will unset a previously set
4617 * model (if applicable). If model is %NULL, then it will unset the model.
4619 * Note that this function does not clear the cell renderers, you have to
4620 * call gtk_combo_box_cell_layout_clear() yourself if you need to set up
4621 * different cell renderers for the new model.
4626 gtk_combo_box_set_model (GtkComboBox *combo_box,
4627 GtkTreeModel *model)
4629 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4633 gtk_combo_box_unset_model (combo_box);
4637 g_return_if_fail (GTK_IS_TREE_MODEL (model));
4639 if (model == combo_box->priv->model)
4642 if (combo_box->priv->model)
4643 gtk_combo_box_unset_model (combo_box);
4645 combo_box->priv->model = model;
4646 g_object_ref (combo_box->priv->model);
4648 combo_box->priv->inserted_id =
4649 g_signal_connect (combo_box->priv->model, "row_inserted",
4650 G_CALLBACK (gtk_combo_box_model_row_inserted),
4652 combo_box->priv->deleted_id =
4653 g_signal_connect (combo_box->priv->model, "row_deleted",
4654 G_CALLBACK (gtk_combo_box_model_row_deleted),
4656 combo_box->priv->reordered_id =
4657 g_signal_connect (combo_box->priv->model, "rows_reordered",
4658 G_CALLBACK (gtk_combo_box_model_rows_reordered),
4660 combo_box->priv->changed_id =
4661 g_signal_connect (combo_box->priv->model, "row_changed",
4662 G_CALLBACK (gtk_combo_box_model_row_changed),
4665 if (combo_box->priv->tree_view)
4668 gtk_tree_view_set_model (GTK_TREE_VIEW (combo_box->priv->tree_view),
4669 combo_box->priv->model);
4670 gtk_combo_box_list_popup_resize (combo_box);
4675 if (combo_box->priv->popup_widget)
4676 gtk_combo_box_menu_fill (combo_box);
4680 if (combo_box->priv->cell_view)
4681 gtk_cell_view_set_model (GTK_CELL_VIEW (combo_box->priv->cell_view),
4682 combo_box->priv->model);
4686 * gtk_combo_box_get_model
4687 * @combo_box: A #GtkComboBox.
4689 * Returns the #GtkTreeModel which is acting as data source for @combo_box.
4691 * Return value: A #GtkTreeModel which was passed during construction.
4696 gtk_combo_box_get_model (GtkComboBox *combo_box)
4698 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
4700 return combo_box->priv->model;
4704 /* convenience API for simple text combos */
4707 * gtk_combo_box_new_text:
4709 * Convenience function which constructs a new text combo box, which is a
4710 * #GtkComboBox just displaying strings. If you use this function to create
4711 * a text combo box, you should only manipulate its data source with the
4712 * following convenience functions: gtk_combo_box_append_text(),
4713 * gtk_combo_box_insert_text(), gtk_combo_box_prepend_text() and
4714 * gtk_combo_box_remove_text().
4716 * Return value: A new text combo box.
4721 gtk_combo_box_new_text (void)
4723 GtkWidget *combo_box;
4724 GtkCellRenderer *cell;
4725 GtkListStore *store;
4727 store = gtk_list_store_new (1, G_TYPE_STRING);
4728 combo_box = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));
4729 g_object_unref (store);
4731 cell = gtk_cell_renderer_text_new ();
4732 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), cell, TRUE);
4733 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), cell,
4741 * gtk_combo_box_append_text:
4742 * @combo_box: A #GtkComboBox constructed using gtk_combo_box_new_text().
4745 * Appends @string to the list of strings stored in @combo_box. Note that
4746 * you can only use this function with combo boxes constructed with
4747 * gtk_combo_box_new_text().
4752 gtk_combo_box_append_text (GtkComboBox *combo_box,
4756 GtkListStore *store;
4758 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4759 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
4760 g_return_if_fail (text != NULL);
4762 store = GTK_LIST_STORE (combo_box->priv->model);
4764 gtk_list_store_append (store, &iter);
4765 gtk_list_store_set (store, &iter, 0, text, -1);
4769 * gtk_combo_box_insert_text:
4770 * @combo_box: A #GtkComboBox constructed using gtk_combo_box_new_text().
4771 * @position: An index to insert @text.
4774 * Inserts @string at @position in the list of strings stored in @combo_box.
4775 * Note that you can only use this function with combo boxes constructed
4776 * with gtk_combo_box_new_text().
4781 gtk_combo_box_insert_text (GtkComboBox *combo_box,
4786 GtkListStore *store;
4788 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4789 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
4790 g_return_if_fail (position >= 0);
4791 g_return_if_fail (text != NULL);
4793 store = GTK_LIST_STORE (combo_box->priv->model);
4795 gtk_list_store_insert (store, &iter, position);
4796 gtk_list_store_set (store, &iter, 0, text, -1);
4800 * gtk_combo_box_prepend_text:
4801 * @combo_box: A #GtkComboBox constructed with gtk_combo_box_new_text().
4804 * Prepends @string to the list of strings stored in @combo_box. Note that
4805 * you can only use this function with combo boxes constructed with
4806 * gtk_combo_box_new_text().
4811 gtk_combo_box_prepend_text (GtkComboBox *combo_box,
4815 GtkListStore *store;
4817 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4818 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
4819 g_return_if_fail (text != NULL);
4821 store = GTK_LIST_STORE (combo_box->priv->model);
4823 gtk_list_store_prepend (store, &iter);
4824 gtk_list_store_set (store, &iter, 0, text, -1);
4828 * gtk_combo_box_remove_text:
4829 * @combo_box: A #GtkComboBox constructed with gtk_combo_box_new_text().
4830 * @position: Index of the item to remove.
4832 * Removes the string at @position from @combo_box. Note that you can only use
4833 * this function with combo boxes constructed with gtk_combo_box_new_text().
4838 gtk_combo_box_remove_text (GtkComboBox *combo_box,
4842 GtkListStore *store;
4844 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4845 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
4846 g_return_if_fail (position >= 0);
4848 store = GTK_LIST_STORE (combo_box->priv->model);
4850 if (gtk_tree_model_iter_nth_child (combo_box->priv->model, &iter,
4852 gtk_list_store_remove (store, &iter);
4856 * gtk_combo_box_get_active_text:
4857 * @combo_box: A #GtkComboBox constructed with gtk_combo_box_new_text().
4859 * Returns the currently active string in @combo_box or %NULL if none
4860 * is selected. Note that you can only use this function with combo
4861 * boxes constructed with gtk_combo_box_new_text() and with
4862 * #GtkComboBoxEntry<!-- -->s.
4864 * Returns: a newly allocated string containing the currently active text.
4869 gtk_combo_box_get_active_text (GtkComboBox *combo_box)
4871 GtkComboBoxClass *class;
4873 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
4875 class = GTK_COMBO_BOX_GET_CLASS (combo_box);
4877 if (class->get_active_text)
4878 return (* class->get_active_text) (combo_box);
4884 gtk_combo_box_real_get_active_text (GtkComboBox *combo_box)
4889 g_return_val_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model), NULL);
4891 if (gtk_combo_box_get_active_iter (combo_box, &iter))
4892 gtk_tree_model_get (combo_box->priv->model, &iter,
4899 gtk_combo_box_mnemonic_activate (GtkWidget *widget,
4900 gboolean group_cycling)
4902 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
4904 gtk_widget_grab_focus (combo_box->priv->button);
4910 gtk_combo_box_grab_focus (GtkWidget *widget)
4912 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
4914 gtk_widget_grab_focus (combo_box->priv->button);
4918 gtk_combo_box_destroy (GtkObject *object)
4920 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
4922 if (combo_box->priv->popup_idle_id > 0)
4924 g_source_remove (combo_box->priv->popup_idle_id);
4925 combo_box->priv->popup_idle_id = 0;
4928 gtk_combo_box_popdown (combo_box);
4930 if (combo_box->priv->row_separator_destroy)
4931 (* combo_box->priv->row_separator_destroy) (combo_box->priv->row_separator_data);
4933 combo_box->priv->row_separator_func = NULL;
4934 combo_box->priv->row_separator_data = NULL;
4935 combo_box->priv->row_separator_destroy = NULL;
4937 combo_box->priv->destroying = 1;
4939 GTK_OBJECT_CLASS (parent_class)->destroy (object);
4940 combo_box->priv->cell_view = NULL;
4942 combo_box->priv->destroying = 0;
4946 gtk_combo_box_finalize (GObject *object)
4948 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
4951 if (GTK_IS_MENU (combo_box->priv->popup_widget))
4953 gtk_combo_box_menu_destroy (combo_box);
4954 gtk_menu_detach (GTK_MENU (combo_box->priv->popup_widget));
4955 combo_box->priv->popup_widget = NULL;
4958 if (GTK_IS_TREE_VIEW (combo_box->priv->tree_view))
4959 gtk_combo_box_list_destroy (combo_box);
4961 if (combo_box->priv->popup_window)
4962 gtk_widget_destroy (combo_box->priv->popup_window);
4964 gtk_combo_box_unset_model (combo_box);
4966 for (i = combo_box->priv->cells; i; i = i->next)
4968 ComboCellInfo *info = (ComboCellInfo *)i->data;
4969 GSList *list = info->attributes;
4972 info->destroy (info->func_data);
4974 while (list && list->next)
4976 g_free (list->data);
4977 list = list->next->next;
4979 g_slist_free (info->attributes);
4981 g_object_unref (info->cell);
4984 g_slist_free (combo_box->priv->cells);
4986 G_OBJECT_CLASS (parent_class)->finalize (object);
4990 gtk_cell_editable_key_press (GtkWidget *widget,
4994 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
4996 if (event->keyval == GDK_Escape)
4998 combo_box->priv->editing_canceled = TRUE;
5000 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (combo_box));
5001 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (combo_box));
5005 else if (event->keyval == GDK_Return)
5007 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (combo_box));
5008 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (combo_box));
5017 popdown_idle (gpointer data)
5019 GtkComboBox *combo_box;
5021 GDK_THREADS_ENTER ();
5023 combo_box = GTK_COMBO_BOX (data);
5025 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (combo_box));
5026 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (combo_box));
5028 g_object_unref (combo_box);
5030 GDK_THREADS_LEAVE ();
5036 popdown_handler (GtkWidget *widget,
5039 g_idle_add (popdown_idle, g_object_ref (data));
5043 popup_idle (gpointer data)
5045 GtkComboBox *combo_box;
5047 GDK_THREADS_ENTER ();
5049 combo_box = GTK_COMBO_BOX (data);
5051 if (GTK_IS_MENU (combo_box->priv->popup_widget) &&
5052 combo_box->priv->cell_view)
5053 g_signal_connect_object (combo_box->priv->popup_widget,
5054 "unmap", G_CALLBACK (popdown_handler),
5057 /* we unset this if a menu item is activated */
5058 combo_box->priv->editing_canceled = TRUE;
5059 gtk_combo_box_popup (combo_box);
5061 combo_box->priv->popup_idle_id = 0;
5063 GDK_THREADS_LEAVE ();
5069 gtk_combo_box_start_editing (GtkCellEditable *cell_editable,
5072 GtkComboBox *combo_box = GTK_COMBO_BOX (cell_editable);
5074 combo_box->priv->is_cell_renderer = TRUE;
5076 if (combo_box->priv->cell_view)
5078 g_signal_connect_object (combo_box->priv->button, "key_press_event",
5079 G_CALLBACK (gtk_cell_editable_key_press),
5082 gtk_widget_grab_focus (combo_box->priv->button);
5086 g_signal_connect_object (GTK_BIN (combo_box)->child, "key_press_event",
5087 G_CALLBACK (gtk_cell_editable_key_press),
5090 gtk_widget_grab_focus (GTK_WIDGET (GTK_BIN (combo_box)->child));
5091 GTK_WIDGET_UNSET_FLAGS (combo_box->priv->button, GTK_CAN_FOCUS);
5094 /* we do the immediate popup only for the optionmenu-like
5097 if (combo_box->priv->is_cell_renderer &&
5098 combo_box->priv->cell_view && !combo_box->priv->tree_view)
5099 combo_box->priv->popup_idle_id = g_idle_add (popup_idle, combo_box);
5104 * gtk_combo_box_get_add_tearoffs:
5105 * @combo_box: a #GtkComboBox
5107 * Gets the current value of the :add-tearoffs property.
5109 * Return value: the current value of the :add-tearoffs property.
5112 gtk_combo_box_get_add_tearoffs (GtkComboBox *combo_box)
5114 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE);
5116 return combo_box->priv->add_tearoffs;
5120 * gtk_combo_box_set_add_tearoffs:
5121 * @combo_box: a #GtkComboBox
5122 * @add_tearoffs: %TRUE to add tearoff menu items
5124 * Sets whether the popup menu should have a tearoff
5130 gtk_combo_box_set_add_tearoffs (GtkComboBox *combo_box,
5131 gboolean add_tearoffs)
5133 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5135 add_tearoffs = add_tearoffs != FALSE;
5137 if (combo_box->priv->add_tearoffs != add_tearoffs)
5139 combo_box->priv->add_tearoffs = add_tearoffs;
5140 gtk_combo_box_check_appearance (combo_box);
5141 gtk_combo_box_relayout (combo_box);
5142 g_object_notify (G_OBJECT (combo_box), "add-tearoffs");
5147 * gtk_combo_box_get_title:
5148 * @combo_box: a #GtkComboBox
5150 * Gets the current title of the menu in tearoff mode. See
5151 * gtk_combo_box_set_add_tearoffs().
5153 * Returns: the menu's title in tearoff mode. This is an internal copy of the
5154 * string which must not be freed.
5158 G_CONST_RETURN gchar*
5159 gtk_combo_box_get_title (GtkComboBox *combo_box)
5161 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
5163 return combo_box->priv->tearoff_title;
5167 gtk_combo_box_update_title (GtkComboBox *combo_box)
5169 gtk_combo_box_check_appearance (combo_box);
5171 if (combo_box->priv->popup_widget &&
5172 GTK_IS_MENU (combo_box->priv->popup_widget))
5173 gtk_menu_set_title (GTK_MENU (combo_box->priv->popup_widget),
5174 combo_box->priv->tearoff_title);
5178 * gtk_combo_box_set_title:
5179 * @combo_box: a #GtkComboBox
5180 * @title: a title for the menu in tearoff mode.
5182 * Sets the menu's title in tearoff mode.
5187 gtk_combo_box_set_title (GtkComboBox *combo_box,
5190 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5192 if (strcmp (title ? title : "",
5193 combo_box->priv->tearoff_title ? combo_box->priv->tearoff_title : "") != 0)
5195 g_free (combo_box->priv->tearoff_title);
5196 combo_box->priv->tearoff_title = g_strdup (title);
5198 gtk_combo_box_update_title (combo_box);
5200 g_object_notify (G_OBJECT (combo_box), "tearoff-title");
5205 _gtk_combo_box_editing_canceled (GtkComboBox *combo_box)
5207 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), TRUE);
5209 return combo_box->priv->editing_canceled;
5213 * gtk_combo_box_get_popup_accessible:
5214 * @combo_box: a #GtkComboBox
5216 * Gets the accessible object corresponding to the combo box's popup.
5218 * This function is mostly intended for use by accessibility technologies;
5219 * applications should have little use for it.
5221 * Returns: the accessible object corresponding to the combo box's popup.
5226 gtk_combo_box_get_popup_accessible (GtkComboBox *combo_box)
5230 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
5232 if (combo_box->priv->popup_widget)
5234 atk_obj = gtk_widget_get_accessible (combo_box->priv->popup_widget);
5242 * gtk_combo_box_get_row_separator_func:
5243 * @combo_box: a #GtkComboBox
5245 * Returns the current row separator function.
5247 * Return value: the current row separator function.
5251 GtkTreeViewRowSeparatorFunc
5252 gtk_combo_box_get_row_separator_func (GtkComboBox *combo_box)
5254 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
5256 return combo_box->priv->row_separator_func;
5260 * gtk_combo_box_set_row_separator_func:
5261 * @combo_box: a #GtkComboBox
5262 * @func: a #GtkTreeViewRowSeparatorFunc
5263 * @data: user data to pass to @func, or %NULL
5264 * @destroy: destroy notifier for @data, or %NULL
5266 * Sets the row separator function, which is used to determine
5267 * whether a row should be drawn as a separator. If the row separator
5268 * function is %NULL, no separators are drawn. This is the default value.
5273 gtk_combo_box_set_row_separator_func (GtkComboBox *combo_box,
5274 GtkTreeViewRowSeparatorFunc func,
5276 GtkDestroyNotify destroy)
5278 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5280 if (combo_box->priv->row_separator_destroy)
5281 (* combo_box->priv->row_separator_destroy) (combo_box->priv->row_separator_data);
5283 combo_box->priv->row_separator_func = func;
5284 combo_box->priv->row_separator_data = data;
5285 combo_box->priv->row_separator_destroy = destroy;
5287 if (combo_box->priv->tree_view)
5288 gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (combo_box->priv->tree_view),
5291 gtk_combo_box_relayout (combo_box);
5293 gtk_widget_queue_draw (GTK_WIDGET (combo_box));
5298 * gtk_combo_box_set_focus_on_click:
5299 * @combo: a #GtkComboBox
5300 * @focus_on_click: whether the combo box grabs focus when clicked
5303 * Sets whether the combo box will grab focus when it is clicked with
5304 * the mouse. Making mouse clicks not grab focus is useful in places
5305 * like toolbars where you don't want the keyboard focus removed from
5306 * the main area of the application.
5311 gtk_combo_box_set_focus_on_click (GtkComboBox *combo_box,
5312 gboolean focus_on_click)
5314 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5316 focus_on_click = focus_on_click != FALSE;
5318 if (combo_box->priv->focus_on_click != focus_on_click)
5320 combo_box->priv->focus_on_click = focus_on_click;
5322 if (combo_box->priv->button)
5323 gtk_button_set_focus_on_click (GTK_BUTTON (combo_box->priv->button),
5326 g_object_notify (G_OBJECT (combo_box), "focus-on-click");
5331 * gtk_combo_box_get_focus_on_click:
5332 * @combo: a #GtkComboBox
5334 * Returns whether the combo box grabs focus when it is clicked
5335 * with the mouse. See gtk_combo_box_set_focus_on_click().
5337 * Return value: %TRUE if the combo box grabs focus when it is
5338 * clicked with the mouse.
5343 gtk_combo_box_get_focus_on_click (GtkComboBox *combo_box)
5345 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE);
5347 return combo_box->priv->focus_on_click;
5351 #define __GTK_COMBO_BOX_C__
5352 #include "gtkaliasdef.c"