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;
787 gtk_combo_box_set_property (GObject *object,
792 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
797 gtk_combo_box_set_model (combo_box, g_value_get_object (value));
800 case PROP_WRAP_WIDTH:
801 gtk_combo_box_set_wrap_width (combo_box, g_value_get_int (value));
804 case PROP_ROW_SPAN_COLUMN:
805 gtk_combo_box_set_row_span_column (combo_box, g_value_get_int (value));
808 case PROP_COLUMN_SPAN_COLUMN:
809 gtk_combo_box_set_column_span_column (combo_box, g_value_get_int (value));
813 gtk_combo_box_set_active (combo_box, g_value_get_int (value));
816 case PROP_ADD_TEAROFFS:
817 gtk_combo_box_set_add_tearoffs (combo_box, g_value_get_boolean (value));
821 combo_box->priv->has_frame = g_value_get_boolean (value);
824 case PROP_FOCUS_ON_CLICK:
825 gtk_combo_box_set_focus_on_click (combo_box,
826 g_value_get_boolean (value));
829 case PROP_TEAROFF_TITLE:
830 gtk_combo_box_set_title (combo_box, g_value_get_string (value));
839 gtk_combo_box_get_property (GObject *object,
844 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
849 g_value_set_object (value, combo_box->priv->model);
852 case PROP_WRAP_WIDTH:
853 g_value_set_int (value, combo_box->priv->wrap_width);
856 case PROP_ROW_SPAN_COLUMN:
857 g_value_set_int (value, combo_box->priv->row_column);
860 case PROP_COLUMN_SPAN_COLUMN:
861 g_value_set_int (value, combo_box->priv->col_column);
865 g_value_set_int (value, gtk_combo_box_get_active (combo_box));
868 case PROP_ADD_TEAROFFS:
869 g_value_set_boolean (value, gtk_combo_box_get_add_tearoffs (combo_box));
873 g_value_set_boolean (value, combo_box->priv->has_frame);
876 case PROP_FOCUS_ON_CLICK:
877 g_value_set_boolean (value, combo_box->priv->focus_on_click);
880 case PROP_TEAROFF_TITLE:
881 g_value_set_string (value, gtk_combo_box_get_title (combo_box));
885 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
891 gtk_combo_box_state_changed (GtkWidget *widget,
892 GtkStateType previous)
894 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
896 if (GTK_WIDGET_REALIZED (widget))
898 if (combo_box->priv->tree_view && combo_box->priv->cell_view)
899 gtk_cell_view_set_background_color (GTK_CELL_VIEW (combo_box->priv->cell_view),
900 &widget->style->base[GTK_WIDGET_STATE (widget)]);
903 gtk_widget_queue_draw (widget);
907 gtk_combo_box_button_state_changed (GtkWidget *widget,
908 GtkStateType previous,
911 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
913 if (GTK_WIDGET_REALIZED (widget))
915 if (!combo_box->priv->tree_view && combo_box->priv->cell_view)
917 if ((GTK_WIDGET_STATE (widget) == GTK_STATE_INSENSITIVE) !=
918 (GTK_WIDGET_STATE (combo_box->priv->cell_view) == GTK_STATE_INSENSITIVE))
919 gtk_widget_set_sensitive (combo_box->priv->cell_view, GTK_WIDGET_SENSITIVE (widget));
921 gtk_widget_set_state (combo_box->priv->cell_view,
922 GTK_WIDGET_STATE (widget));
927 gtk_widget_queue_draw (widget);
931 gtk_combo_box_check_appearance (GtkComboBox *combo_box)
933 gboolean appears_as_list;
935 /* if wrap_width > 0, then we are in grid-mode and forced to use
938 if (combo_box->priv->wrap_width)
939 appears_as_list = FALSE;
941 gtk_widget_style_get (GTK_WIDGET (combo_box),
942 "appears-as-list", &appears_as_list,
947 /* Destroy all the menu mode widgets, if they exist. */
948 if (GTK_IS_MENU (combo_box->priv->popup_widget))
949 gtk_combo_box_menu_destroy (combo_box);
951 /* Create the list mode widgets, if they don't already exist. */
952 if (!GTK_IS_TREE_VIEW (combo_box->priv->tree_view))
953 gtk_combo_box_list_setup (combo_box);
957 /* Destroy all the list mode widgets, if they exist. */
958 if (GTK_IS_TREE_VIEW (combo_box->priv->tree_view))
959 gtk_combo_box_list_destroy (combo_box);
961 /* Create the menu mode widgets, if they don't already exist. */
962 if (!GTK_IS_MENU (combo_box->priv->popup_widget))
963 gtk_combo_box_menu_setup (combo_box, TRUE);
968 gtk_combo_box_style_set (GtkWidget *widget,
971 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
973 gtk_combo_box_check_appearance (combo_box);
975 if (combo_box->priv->tree_view && combo_box->priv->cell_view)
976 gtk_cell_view_set_background_color (GTK_CELL_VIEW (combo_box->priv->cell_view),
977 &widget->style->base[GTK_WIDGET_STATE (widget)]);
981 gtk_combo_box_button_toggled (GtkWidget *widget,
984 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
986 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
988 if (!combo_box->priv->popup_in_progress)
989 gtk_combo_box_popup (combo_box);
992 gtk_combo_box_popdown (combo_box);
996 gtk_combo_box_add (GtkContainer *container,
999 GtkComboBox *combo_box = GTK_COMBO_BOX (container);
1001 if (combo_box->priv->cell_view && combo_box->priv->cell_view->parent)
1003 gtk_widget_unparent (combo_box->priv->cell_view);
1004 GTK_BIN (container)->child = NULL;
1005 gtk_widget_queue_resize (GTK_WIDGET (container));
1008 gtk_widget_set_parent (widget, GTK_WIDGET (container));
1009 GTK_BIN (container)->child = widget;
1011 if (combo_box->priv->cell_view &&
1012 widget != combo_box->priv->cell_view)
1014 /* since the cell_view was unparented, it's gone now */
1015 combo_box->priv->cell_view = NULL;
1017 if (!combo_box->priv->tree_view && combo_box->priv->separator)
1019 gtk_container_remove (GTK_CONTAINER (combo_box->priv->separator->parent),
1020 combo_box->priv->separator);
1021 combo_box->priv->separator = NULL;
1023 gtk_widget_queue_resize (GTK_WIDGET (container));
1025 else if (combo_box->priv->cell_view_frame)
1027 gtk_widget_unparent (combo_box->priv->cell_view_frame);
1028 combo_box->priv->cell_view_frame = NULL;
1029 combo_box->priv->box = NULL;
1035 gtk_combo_box_remove (GtkContainer *container,
1038 GtkComboBox *combo_box = GTK_COMBO_BOX (container);
1040 gboolean appears_as_list;
1042 gtk_widget_unparent (widget);
1043 GTK_BIN (container)->child = NULL;
1045 if (combo_box->priv->destroying)
1048 gtk_widget_queue_resize (GTK_WIDGET (container));
1050 if (!combo_box->priv->tree_view)
1051 appears_as_list = FALSE;
1053 appears_as_list = TRUE;
1055 if (appears_as_list)
1056 gtk_combo_box_list_destroy (combo_box);
1057 else if (GTK_IS_MENU (combo_box->priv->popup_widget))
1059 gtk_combo_box_menu_destroy (combo_box);
1060 gtk_menu_detach (GTK_MENU (combo_box->priv->popup_widget));
1061 combo_box->priv->popup_widget = NULL;
1064 if (!combo_box->priv->cell_view)
1066 combo_box->priv->cell_view = gtk_cell_view_new ();
1067 gtk_widget_set_parent (combo_box->priv->cell_view, GTK_WIDGET (container));
1068 GTK_BIN (container)->child = combo_box->priv->cell_view;
1070 gtk_widget_show (combo_box->priv->cell_view);
1071 gtk_cell_view_set_model (GTK_CELL_VIEW (combo_box->priv->cell_view),
1072 combo_box->priv->model);
1073 gtk_combo_box_sync_cells (combo_box, GTK_CELL_LAYOUT (combo_box->priv->cell_view));
1077 if (appears_as_list)
1078 gtk_combo_box_list_setup (combo_box);
1080 gtk_combo_box_menu_setup (combo_box, TRUE);
1082 if (gtk_tree_row_reference_valid (combo_box->priv->active_row))
1084 path = gtk_tree_row_reference_get_path (combo_box->priv->active_row);
1085 gtk_combo_box_set_active_internal (combo_box, path);
1086 gtk_tree_path_free (path);
1089 gtk_combo_box_set_active_internal (combo_box, NULL);
1092 static ComboCellInfo *
1093 gtk_combo_box_get_cell_info (GtkComboBox *combo_box,
1094 GtkCellRenderer *cell)
1098 for (i = combo_box->priv->cells; i; i = i->next)
1100 ComboCellInfo *info = (ComboCellInfo *)i->data;
1102 if (info && info->cell == cell)
1110 gtk_combo_box_menu_show (GtkWidget *menu,
1113 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
1115 gtk_combo_box_child_show (menu, user_data);
1117 combo_box->priv->popup_in_progress = TRUE;
1118 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
1120 combo_box->priv->popup_in_progress = FALSE;
1124 gtk_combo_box_menu_hide (GtkWidget *menu,
1127 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
1129 gtk_combo_box_child_hide(menu,user_data);
1131 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
1136 gtk_combo_box_detacher (GtkWidget *widget,
1139 GtkComboBox *combo_box;
1141 g_return_if_fail (GTK_IS_COMBO_BOX (widget));
1143 combo_box = GTK_COMBO_BOX (widget);
1144 g_return_if_fail (combo_box->priv->popup_widget == (GtkWidget*) menu);
1146 g_signal_handlers_disconnect_by_func (menu->toplevel,
1147 gtk_combo_box_menu_show,
1149 g_signal_handlers_disconnect_by_func (menu->toplevel,
1150 gtk_combo_box_menu_hide,
1153 combo_box->priv->popup_widget = NULL;
1157 gtk_combo_box_set_popup_widget (GtkComboBox *combo_box,
1160 if (GTK_IS_MENU (combo_box->priv->popup_widget))
1162 gtk_menu_detach (GTK_MENU (combo_box->priv->popup_widget));
1163 combo_box->priv->popup_widget = NULL;
1165 else if (combo_box->priv->popup_widget)
1167 gtk_container_remove (GTK_CONTAINER (combo_box->priv->popup_frame),
1168 combo_box->priv->popup_widget);
1169 g_object_unref (combo_box->priv->popup_widget);
1170 combo_box->priv->popup_widget = NULL;
1173 if (GTK_IS_MENU (popup))
1175 if (combo_box->priv->popup_window)
1177 gtk_widget_destroy (combo_box->priv->popup_window);
1178 combo_box->priv->popup_window = NULL;
1179 combo_box->priv->popup_frame = NULL;
1182 combo_box->priv->popup_widget = popup;
1185 * Note that we connect to show/hide on the toplevel, not the
1186 * menu itself, since the menu is not shown/hidden when it is
1187 * popped up while torn-off.
1189 g_signal_connect (GTK_MENU (popup)->toplevel, "show",
1190 G_CALLBACK (gtk_combo_box_menu_show), combo_box);
1191 g_signal_connect (GTK_MENU (popup)->toplevel, "hide",
1192 G_CALLBACK (gtk_combo_box_menu_hide), combo_box);
1194 gtk_menu_attach_to_widget (GTK_MENU (popup),
1195 GTK_WIDGET (combo_box),
1196 gtk_combo_box_detacher);
1200 if (!combo_box->priv->popup_window)
1202 GtkWidget *toplevel;
1204 combo_box->priv->popup_window = gtk_window_new (GTK_WINDOW_POPUP);
1206 g_signal_connect (GTK_WINDOW(combo_box->priv->popup_window),"show",
1207 G_CALLBACK (gtk_combo_box_child_show),
1209 g_signal_connect (GTK_WINDOW(combo_box->priv->popup_window),"hide",
1210 G_CALLBACK (gtk_combo_box_child_hide),
1213 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (combo_box));
1214 if (GTK_IS_WINDOW (toplevel))
1215 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
1216 GTK_WINDOW (combo_box->priv->popup_window));
1218 gtk_window_set_resizable (GTK_WINDOW (combo_box->priv->popup_window), FALSE);
1219 gtk_window_set_screen (GTK_WINDOW (combo_box->priv->popup_window),
1220 gtk_widget_get_screen (GTK_WIDGET (combo_box)));
1222 combo_box->priv->popup_frame = gtk_frame_new (NULL);
1223 gtk_frame_set_shadow_type (GTK_FRAME (combo_box->priv->popup_frame),
1224 GTK_SHADOW_ETCHED_IN);
1225 gtk_container_add (GTK_CONTAINER (combo_box->priv->popup_window),
1226 combo_box->priv->popup_frame);
1228 gtk_widget_show (combo_box->priv->popup_frame);
1230 combo_box->priv->scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1232 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (combo_box->priv->scrolled_window),
1235 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (combo_box->priv->scrolled_window),
1238 gtk_widget_show (combo_box->priv->scrolled_window);
1240 gtk_container_add (GTK_CONTAINER (combo_box->priv->popup_frame),
1241 combo_box->priv->scrolled_window);
1244 gtk_container_add (GTK_CONTAINER (combo_box->priv->scrolled_window),
1247 gtk_widget_show (popup);
1248 g_object_ref (popup);
1249 combo_box->priv->popup_widget = popup;
1254 gtk_combo_box_menu_position_below (GtkMenu *menu,
1260 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
1266 GdkRectangle monitor;
1268 /* FIXME: is using the size request here broken? */
1269 child = GTK_BIN (combo_box)->child;
1271 gdk_window_get_origin (child->window, &sx, &sy);
1273 if (GTK_WIDGET_NO_WINDOW (child))
1275 sx += child->allocation.x;
1276 sy += child->allocation.y;
1279 gtk_widget_size_request (GTK_WIDGET (menu), &req);
1281 if (gtk_widget_get_direction (GTK_WIDGET (combo_box)) == GTK_TEXT_DIR_LTR)
1284 *x = sx + child->allocation.width - req.width;
1287 screen = gtk_widget_get_screen (GTK_WIDGET (combo_box));
1288 monitor_num = gdk_screen_get_monitor_at_window (screen,
1289 GTK_WIDGET (combo_box)->window);
1290 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
1294 else if (*x + req.width > monitor.x + monitor.width)
1295 *x = monitor.x + monitor.width - req.width;
1297 if (monitor.y + monitor.height - *y - child->allocation.height >= req.height)
1298 *y += child->allocation.height;
1299 else if (*y - monitor.y >= req.height)
1301 else if (monitor.y + monitor.height - *y - child->allocation.height > *y - monitor.y)
1302 *y += child->allocation.height;
1310 gtk_combo_box_menu_position_over (GtkMenu *menu,
1316 GtkComboBox *combo_box;
1320 GtkRequisition requisition;
1327 g_return_if_fail (GTK_IS_COMBO_BOX (user_data));
1329 combo_box = GTK_COMBO_BOX (user_data);
1330 widget = GTK_WIDGET (combo_box);
1332 gtk_widget_get_child_requisition (GTK_WIDGET (menu), &requisition);
1333 menu_width = requisition.width;
1335 active = gtk_menu_get_active (GTK_MENU (combo_box->priv->popup_widget));
1336 gdk_window_get_origin (widget->window, &menu_xpos, &menu_ypos);
1338 menu_xpos += widget->allocation.x;
1339 menu_ypos += widget->allocation.y + widget->allocation.height / 2 - 2;
1343 gtk_widget_get_child_requisition (active, &requisition);
1344 menu_ypos -= requisition.height / 2;
1347 children = GTK_MENU_SHELL (combo_box->priv->popup_widget)->children;
1350 child = children->data;
1352 if (active == child)
1355 if (GTK_WIDGET_VISIBLE (child))
1357 gtk_widget_get_child_requisition (child, &requisition);
1358 menu_ypos -= requisition.height;
1361 children = children->next;
1364 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1365 menu_xpos = menu_xpos + widget->allocation.width - menu_width;
1367 /* Clamp the position on screen */
1368 screen_width = gdk_screen_get_width (gtk_widget_get_screen (widget));
1372 else if ((menu_xpos + menu_width) > screen_width)
1373 menu_xpos -= ((menu_xpos + menu_width) - screen_width);
1382 gtk_combo_box_menu_position (GtkMenu *menu,
1388 GtkComboBox *combo_box;
1389 GtkWidget *menu_item;
1391 combo_box = GTK_COMBO_BOX (user_data);
1393 if (combo_box->priv->wrap_width > 0 || combo_box->priv->cell_view == NULL)
1394 gtk_combo_box_menu_position_below (menu, x, y, push_in, user_data);
1397 /* FIXME handle nested menus better */
1398 menu_item = gtk_menu_get_active (GTK_MENU (combo_box->priv->popup_widget));
1400 gtk_menu_shell_select_item (GTK_MENU_SHELL (combo_box->priv->popup_widget),
1403 gtk_combo_box_menu_position_over (menu, x, y, push_in, user_data);
1409 gtk_combo_box_list_position (GtkComboBox *combo_box,
1418 GdkRectangle monitor;
1419 GtkRequisition popup_req;
1420 GtkPolicyType hpolicy, vpolicy;
1422 sample = GTK_BIN (combo_box)->child;
1424 gdk_window_get_origin (sample->window, x, y);
1426 if (GTK_WIDGET_NO_WINDOW (sample))
1428 *x += sample->allocation.x;
1429 *y += sample->allocation.y;
1432 *width = sample->allocation.width;
1434 if (combo_box->priv->cell_view_frame && combo_box->priv->has_frame)
1436 *x -= GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
1437 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->xthickness;
1438 *width += 2 * (GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
1439 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->xthickness);
1442 hpolicy = vpolicy = GTK_POLICY_NEVER;
1443 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (combo_box->priv->scrolled_window),
1445 gtk_widget_size_request (combo_box->priv->popup_frame, &popup_req);
1447 if (popup_req.width > *width)
1449 hpolicy = GTK_POLICY_ALWAYS;
1450 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (combo_box->priv->scrolled_window),
1452 gtk_widget_size_request (combo_box->priv->popup_frame, &popup_req);
1455 *height = popup_req.height;
1457 screen = gtk_widget_get_screen (GTK_WIDGET (combo_box));
1458 monitor_num = gdk_screen_get_monitor_at_window (screen,
1459 GTK_WIDGET (combo_box)->window);
1460 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
1464 else if (*x + *width > monitor.x + monitor.width)
1465 *x = monitor.x + monitor.width - *width;
1467 if (*y + sample->allocation.height + *height <= monitor.y + monitor.height)
1468 *y += sample->allocation.height;
1469 else if (*y - *height >= monitor.y)
1471 else if (monitor.y + monitor.height - (*y + sample->allocation.height) > *y - monitor.y)
1473 *y += sample->allocation.height;
1474 *height = monitor.y + monitor.height - *y;
1478 *height = *y - monitor.y;
1482 if (popup_req.height > *height)
1484 vpolicy = GTK_POLICY_ALWAYS;
1486 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (combo_box->priv->scrolled_window),
1492 cell_view_is_sensitive (GtkCellView *cell_view)
1494 GList *cells, *list;
1497 cells = gtk_cell_view_get_cell_renderers (cell_view);
1503 g_object_get (list->data, "sensitive", &sensitive, NULL);
1510 g_list_free (cells);
1516 tree_column_row_is_sensitive (GtkComboBox *combo_box,
1519 GList *cells, *list;
1522 if (!combo_box->priv->column)
1525 if (combo_box->priv->row_separator_func)
1527 if ((*combo_box->priv->row_separator_func) (combo_box->priv->model, iter,
1528 combo_box->priv->row_separator_data))
1532 gtk_tree_view_column_cell_set_cell_data (combo_box->priv->column,
1533 combo_box->priv->model,
1534 iter, FALSE, FALSE);
1536 cells = gtk_tree_view_column_get_cell_renderers (combo_box->priv->column);
1542 g_object_get (list->data, "sensitive", &sensitive, NULL);
1549 g_list_free (cells);
1555 update_menu_sensitivity (GtkComboBox *combo_box,
1558 GList *children, *child;
1559 GtkWidget *item, *submenu, *separator;
1560 GtkWidget *cell_view;
1563 if (!combo_box->priv->model)
1566 children = gtk_container_get_children (GTK_CONTAINER (menu));
1568 for (child = children; child; child = child->next)
1570 item = GTK_WIDGET (child->data);
1571 cell_view = GTK_BIN (item)->child;
1573 if (!GTK_IS_CELL_VIEW (cell_view))
1576 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (item));
1577 if (submenu != NULL)
1579 gtk_widget_set_sensitive (item, TRUE);
1580 update_menu_sensitivity (combo_box, submenu);
1584 sensitive = cell_view_is_sensitive (GTK_CELL_VIEW (cell_view));
1586 if (menu != combo_box->priv->popup_widget && child == children)
1588 separator = GTK_WIDGET (child->next->data);
1589 g_object_set (item, "visible", sensitive, NULL);
1590 g_object_set (separator, "visible", sensitive, NULL);
1593 gtk_widget_set_sensitive (item, sensitive);
1597 g_list_free (children);
1601 gtk_combo_box_menu_popup (GtkComboBox *combo_box,
1603 guint32 activate_time)
1607 GtkRequisition requisition;
1610 update_menu_sensitivity (combo_box, combo_box->priv->popup_widget);
1613 if (gtk_tree_row_reference_valid (combo_box->priv->active_row))
1615 path = gtk_tree_row_reference_get_path (combo_box->priv->active_row);
1616 active_item = gtk_tree_path_get_indices (path)[0];
1617 gtk_tree_path_free (path);
1619 if (combo_box->priv->add_tearoffs)
1623 /* FIXME handle nested menus better */
1624 gtk_menu_set_active (GTK_MENU (combo_box->priv->popup_widget), active_item);
1626 if (combo_box->priv->wrap_width == 0)
1628 width = GTK_WIDGET (combo_box)->allocation.width;
1629 gtk_widget_set_size_request (combo_box->priv->popup_widget, -1, -1);
1630 gtk_widget_size_request (combo_box->priv->popup_widget, &requisition);
1632 gtk_widget_set_size_request (combo_box->priv->popup_widget,
1633 MAX (width, requisition.width), -1);
1636 gtk_menu_popup (GTK_MENU (combo_box->priv->popup_widget),
1638 gtk_combo_box_menu_position, combo_box,
1639 button, activate_time);
1643 popup_grab_on_window (GdkWindow *window,
1644 guint32 activate_time,
1645 gboolean grab_keyboard)
1647 if ((gdk_pointer_grab (window, TRUE,
1648 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
1649 GDK_POINTER_MOTION_MASK,
1650 NULL, NULL, activate_time) == 0))
1652 if (!grab_keyboard ||
1653 gdk_keyboard_grab (window, TRUE,
1654 activate_time) == 0)
1658 gdk_display_pointer_ungrab (gdk_drawable_get_display (window),
1668 * gtk_combo_box_popup:
1669 * @combo_box: a #GtkComboBox
1671 * Pops up the menu or dropdown list of @combo_box.
1673 * This function is mostly intended for use by accessibility technologies;
1674 * applications should have little use for it.
1679 gtk_combo_box_popup (GtkComboBox *combo_box)
1681 gint x, y, width, height;
1682 GtkTreePath *path, *ppath;
1683 GtkWidget *toplevel;
1685 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
1687 if (!GTK_WIDGET_REALIZED (combo_box))
1690 if (GTK_WIDGET_MAPPED (combo_box->priv->popup_widget))
1693 if (GTK_IS_MENU (combo_box->priv->popup_widget))
1695 gtk_combo_box_menu_popup (combo_box, 0, 0);
1699 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (combo_box));
1700 if (GTK_IS_WINDOW (toplevel))
1701 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
1702 GTK_WINDOW (combo_box->priv->popup_window));
1704 gtk_widget_show_all (combo_box->priv->popup_frame);
1705 gtk_combo_box_list_position (combo_box, &x, &y, &width, &height);
1707 gtk_widget_set_size_request (combo_box->priv->popup_window, width, height);
1708 gtk_window_move (GTK_WINDOW (combo_box->priv->popup_window), x, y);
1710 if (gtk_tree_row_reference_valid (combo_box->priv->active_row))
1712 path = gtk_tree_row_reference_get_path (combo_box->priv->active_row);
1713 ppath = gtk_tree_path_copy (path);
1714 if (gtk_tree_path_up (ppath))
1715 gtk_tree_view_expand_to_path (GTK_TREE_VIEW (combo_box->priv->tree_view),
1717 gtk_tree_view_set_cursor (GTK_TREE_VIEW (combo_box->priv->tree_view),
1719 gtk_tree_path_free (path);
1720 gtk_tree_path_free (ppath);
1722 gtk_tree_view_set_hover_expand (GTK_TREE_VIEW (combo_box->priv->tree_view),
1726 gtk_widget_show (combo_box->priv->popup_window);
1728 gtk_widget_grab_focus (combo_box->priv->popup_window);
1729 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
1732 if (!GTK_WIDGET_HAS_FOCUS (combo_box->priv->tree_view))
1733 gtk_widget_grab_focus (combo_box->priv->tree_view);
1735 if (!popup_grab_on_window (combo_box->priv->popup_window->window,
1736 GDK_CURRENT_TIME, TRUE))
1738 gtk_widget_hide (combo_box->priv->popup_window);
1742 gtk_grab_add (combo_box->priv->popup_window);
1746 * gtk_combo_box_popdown:
1747 * @combo_box: a #GtkComboBox
1749 * Hides the menu or dropdown list of @combo_box.
1751 * This function is mostly intended for use by accessibility technologies;
1752 * applications should have little use for it.
1757 gtk_combo_box_popdown (GtkComboBox *combo_box)
1759 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
1761 if (GTK_IS_MENU (combo_box->priv->popup_widget))
1763 gtk_menu_popdown (GTK_MENU (combo_box->priv->popup_widget));
1767 if (!GTK_WIDGET_REALIZED (GTK_WIDGET (combo_box)))
1770 gtk_grab_remove (combo_box->priv->popup_window);
1771 gtk_widget_hide_all (combo_box->priv->popup_window);
1772 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
1777 gtk_combo_box_calc_requested_width (GtkComboBox *combo_box,
1783 if (combo_box->priv->cell_view)
1784 gtk_widget_style_get (combo_box->priv->cell_view,
1785 "focus-line-width", &padding,
1790 /* add some pixels for good measure */
1791 padding += BONUS_PADDING;
1793 if (combo_box->priv->cell_view)
1794 gtk_cell_view_get_size_of_row (GTK_CELL_VIEW (combo_box->priv->cell_view),
1799 return req.width + padding;
1803 gtk_combo_box_remeasure (GtkComboBox *combo_box)
1808 if (!combo_box->priv->model ||
1809 !gtk_tree_model_get_iter_first (combo_box->priv->model, &iter))
1812 combo_box->priv->width = 0;
1814 path = gtk_tree_path_new_from_indices (0, -1);
1820 if (combo_box->priv->cell_view)
1821 gtk_cell_view_get_size_of_row (GTK_CELL_VIEW (combo_box->priv->cell_view),
1826 combo_box->priv->width = MAX (combo_box->priv->width, req.width);
1828 gtk_tree_path_next (path);
1830 while (gtk_tree_model_iter_next (combo_box->priv->model, &iter));
1832 gtk_tree_path_free (path);
1836 gtk_combo_box_size_request (GtkWidget *widget,
1837 GtkRequisition *requisition)
1840 gint focus_width, focus_pad;
1841 GtkRequisition bin_req;
1843 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
1845 gtk_combo_box_check_appearance (combo_box);
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 gtk_combo_box_check_appearance (combo_box);
1941 widget->allocation = *allocation;
1943 gtk_widget_style_get (GTK_WIDGET (widget),
1944 "focus-line-width", &focus_width,
1945 "focus-padding", &focus_pad,
1948 if (!combo_box->priv->tree_view)
1950 if (combo_box->priv->cell_view)
1952 gint border_width, xthickness, ythickness;
1956 gtk_widget_size_allocate (combo_box->priv->button, allocation);
1958 /* set some things ready */
1959 border_width = GTK_CONTAINER (combo_box->priv->button)->border_width;
1960 xthickness = combo_box->priv->button->style->xthickness;
1961 ythickness = combo_box->priv->button->style->ythickness;
1963 child.x = allocation->x;
1964 child.y = allocation->y;
1965 width = allocation->width;
1966 child.height = allocation->height;
1968 if (!combo_box->priv->is_cell_renderer)
1970 child.x += border_width + xthickness + focus_width + focus_pad;
1971 child.y += border_width + ythickness + focus_width + focus_pad;
1972 width -= 2 * (child.x - allocation->x);
1973 child.height -= 2 * (child.y - allocation->y);
1977 /* handle the children */
1978 gtk_widget_size_request (combo_box->priv->arrow, &req);
1979 child.width = req.width;
1981 child.x += width - req.width;
1982 child.width = MAX (1, child.width);
1983 child.height = MAX (1, child.height);
1984 gtk_widget_size_allocate (combo_box->priv->arrow, &child);
1986 child.x += req.width;
1987 gtk_widget_size_request (combo_box->priv->separator, &req);
1988 child.width = req.width;
1990 child.x -= req.width;
1991 child.width = MAX (1, child.width);
1992 child.height = MAX (1, child.height);
1993 gtk_widget_size_allocate (combo_box->priv->separator, &child);
1997 child.x += req.width;
1998 child.width = allocation->x + allocation->width
1999 - (border_width + xthickness + focus_width + focus_pad)
2004 child.width = child.x;
2005 child.x = allocation->x
2006 + border_width + xthickness + focus_width + focus_pad;
2007 child.width -= child.x;
2010 child.width = MAX (1, child.width);
2011 child.height = MAX (1, child.height);
2012 gtk_widget_size_allocate (GTK_BIN (widget)->child, &child);
2016 gtk_widget_size_request (combo_box->priv->button, &req);
2018 child.x = allocation->x;
2020 child.x = allocation->x + allocation->width - req.width;
2021 child.y = allocation->y;
2022 child.width = req.width;
2023 child.height = allocation->height;
2024 child.width = MAX (1, child.width);
2025 child.height = MAX (1, child.height);
2026 gtk_widget_size_allocate (combo_box->priv->button, &child);
2029 child.x = allocation->x + req.width;
2031 child.x = allocation->x;
2032 child.y = allocation->y;
2033 child.width = allocation->width - req.width;
2034 child.width = MAX (1, child.width);
2035 child.height = MAX (1, child.height);
2036 gtk_widget_size_allocate (GTK_BIN (widget)->child, &child);
2044 gtk_widget_size_request (combo_box->priv->button, &req);
2046 child.x = allocation->x;
2048 child.x = allocation->x + allocation->width - req.width;
2049 child.y = allocation->y;
2050 child.width = req.width;
2051 child.height = allocation->height;
2052 child.width = MAX (1, child.width);
2053 child.height = MAX (1, child.height);
2054 gtk_widget_size_allocate (combo_box->priv->button, &child);
2058 child.x = allocation->x + req.width;
2060 child.x = allocation->x;
2061 child.y = allocation->y;
2062 child.width = allocation->width - req.width;
2063 child.height = allocation->height;
2065 if (combo_box->priv->cell_view_frame)
2067 child.width = MAX (1, child.width);
2068 child.height = MAX (1, child.height);
2069 gtk_widget_size_allocate (combo_box->priv->cell_view_frame, &child);
2072 if (combo_box->priv->has_frame)
2075 GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
2076 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->xthickness;
2078 GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
2079 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->ythickness;
2080 child.width -= 2 * (
2081 GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
2082 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->xthickness);
2083 child.height -= 2 * (
2084 GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
2085 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->ythickness);
2089 child.width = MAX (1, child.width);
2090 child.height = MAX (1, child.height);
2091 gtk_widget_size_allocate (GTK_BIN (combo_box)->child, &child);
2096 gtk_combo_box_unset_model (GtkComboBox *combo_box)
2098 if (combo_box->priv->model)
2100 g_signal_handler_disconnect (combo_box->priv->model,
2101 combo_box->priv->inserted_id);
2102 g_signal_handler_disconnect (combo_box->priv->model,
2103 combo_box->priv->deleted_id);
2104 g_signal_handler_disconnect (combo_box->priv->model,
2105 combo_box->priv->reordered_id);
2106 g_signal_handler_disconnect (combo_box->priv->model,
2107 combo_box->priv->changed_id);
2111 if (!combo_box->priv->tree_view)
2113 if (combo_box->priv->popup_widget)
2114 gtk_container_foreach (GTK_CONTAINER (combo_box->priv->popup_widget),
2115 (GtkCallback)gtk_widget_destroy, NULL);
2118 if (combo_box->priv->model)
2120 g_object_unref (combo_box->priv->model);
2121 combo_box->priv->model = NULL;
2124 if (combo_box->priv->active_row)
2126 gtk_tree_row_reference_free (combo_box->priv->active_row);
2127 combo_box->priv->active_row = NULL;
2130 if (combo_box->priv->cell_view)
2131 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (combo_box->priv->cell_view), NULL);
2135 gtk_combo_box_forall (GtkContainer *container,
2136 gboolean include_internals,
2137 GtkCallback callback,
2138 gpointer callback_data)
2140 GtkComboBox *combo_box = GTK_COMBO_BOX (container);
2142 if (include_internals)
2144 if (combo_box->priv->button)
2145 (* callback) (combo_box->priv->button, callback_data);
2146 if (combo_box->priv->cell_view_frame)
2147 (* callback) (combo_box->priv->cell_view_frame, callback_data);
2150 if (GTK_BIN (container)->child)
2151 (* callback) (GTK_BIN (container)->child, callback_data);
2155 gtk_combo_box_child_show (GtkWidget *widget,
2158 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2159 g_signal_emit (combo_box, combo_box_signals[POPUP_SHOW], 0);
2163 gtk_combo_box_child_hide (GtkWidget *widget,
2166 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2167 g_signal_emit (combo_box, combo_box_signals[POPUP_HIDE], 0);
2171 gtk_combo_box_expose_event (GtkWidget *widget,
2172 GdkEventExpose *event)
2174 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
2176 if (!combo_box->priv->tree_view)
2178 gtk_container_propagate_expose (GTK_CONTAINER (widget),
2179 combo_box->priv->button, event);
2183 gtk_container_propagate_expose (GTK_CONTAINER (widget),
2184 combo_box->priv->button, event);
2186 if (combo_box->priv->cell_view_frame)
2187 gtk_container_propagate_expose (GTK_CONTAINER (widget),
2188 combo_box->priv->cell_view_frame, event);
2191 gtk_container_propagate_expose (GTK_CONTAINER (widget),
2192 GTK_BIN (widget)->child, event);
2207 path_visible (GtkTreeView *view,
2213 /* Note that we rely on the fact that collapsed rows don't have nodes
2215 return _gtk_tree_view_find_node (view, path, &tree, &node);
2219 tree_next_func (GtkTreeModel *model,
2224 SearchData *search_data = (SearchData *)data;
2226 if (search_data->found)
2228 if (!tree_column_row_is_sensitive (search_data->combo, iter))
2231 if (search_data->visible &&
2232 !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
2235 search_data->set = TRUE;
2236 search_data->iter = *iter;
2241 if (gtk_tree_path_compare (path, search_data->path) == 0)
2242 search_data->found = TRUE;
2248 tree_next (GtkComboBox *combo,
2249 GtkTreeModel *model,
2254 SearchData search_data;
2256 search_data.combo = combo;
2257 search_data.path = gtk_tree_model_get_path (model, iter);
2258 search_data.visible = visible;
2259 search_data.found = FALSE;
2260 search_data.set = FALSE;
2262 gtk_tree_model_foreach (model, tree_next_func, &search_data);
2264 *next = search_data.iter;
2266 gtk_tree_path_free (search_data.path);
2268 return search_data.set;
2272 tree_prev_func (GtkTreeModel *model,
2277 SearchData *search_data = (SearchData *)data;
2279 if (gtk_tree_path_compare (path, search_data->path) == 0)
2281 search_data->found = TRUE;
2285 if (!tree_column_row_is_sensitive (search_data->combo, iter))
2288 if (search_data->visible &&
2289 !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
2292 search_data->set = TRUE;
2293 search_data->iter = *iter;
2299 tree_prev (GtkComboBox *combo,
2300 GtkTreeModel *model,
2305 SearchData search_data;
2307 search_data.combo = combo;
2308 search_data.path = gtk_tree_model_get_path (model, iter);
2309 search_data.visible = visible;
2310 search_data.found = FALSE;
2311 search_data.set = FALSE;
2313 gtk_tree_model_foreach (model, tree_prev_func, &search_data);
2315 *prev = search_data.iter;
2317 gtk_tree_path_free (search_data.path);
2319 return search_data.set;
2323 tree_last_func (GtkTreeModel *model,
2328 SearchData *search_data = (SearchData *)data;
2330 if (!tree_column_row_is_sensitive (search_data->combo, iter))
2333 /* Note that we rely on the fact that collapsed rows don't have nodes
2335 if (search_data->visible &&
2336 !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
2339 search_data->set = TRUE;
2340 search_data->iter = *iter;
2346 tree_last (GtkComboBox *combo,
2347 GtkTreeModel *model,
2351 SearchData search_data;
2353 search_data.combo = combo;
2354 search_data.visible = visible;
2355 search_data.set = FALSE;
2357 gtk_tree_model_foreach (model, tree_last_func, &search_data);
2359 *last = search_data.iter;
2361 return search_data.set;
2366 tree_first_func (GtkTreeModel *model,
2371 SearchData *search_data = (SearchData *)data;
2373 if (!tree_column_row_is_sensitive (search_data->combo, iter))
2376 if (search_data->visible &&
2377 !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
2380 search_data->set = TRUE;
2381 search_data->iter = *iter;
2387 tree_first (GtkComboBox *combo,
2388 GtkTreeModel *model,
2392 SearchData search_data;
2394 search_data.combo = combo;
2395 search_data.visible = visible;
2396 search_data.set = FALSE;
2398 gtk_tree_model_foreach (model, tree_first_func, &search_data);
2400 *first = search_data.iter;
2402 return search_data.set;
2406 gtk_combo_box_scroll_event (GtkWidget *widget,
2407 GdkEventScroll *event)
2409 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
2412 GtkTreeIter new_iter;
2414 if (!gtk_combo_box_get_active_iter (combo_box, &iter))
2417 if (event->direction == GDK_SCROLL_UP)
2418 found = tree_prev (combo_box, combo_box->priv->model,
2419 &iter, &new_iter, FALSE);
2421 found = tree_next (combo_box, combo_box->priv->model,
2422 &iter, &new_iter, FALSE);
2425 gtk_combo_box_set_active_iter (combo_box, &new_iter);
2435 gtk_combo_box_sync_cells (GtkComboBox *combo_box,
2436 GtkCellLayout *cell_layout)
2440 for (k = combo_box->priv->cells; k; k = k->next)
2443 ComboCellInfo *info = (ComboCellInfo *)k->data;
2445 if (info->pack == GTK_PACK_START)
2446 gtk_cell_layout_pack_start (cell_layout,
2447 info->cell, info->expand);
2448 else if (info->pack == GTK_PACK_END)
2449 gtk_cell_layout_pack_end (cell_layout,
2450 info->cell, info->expand);
2452 gtk_cell_layout_set_cell_data_func (cell_layout,
2454 combo_cell_data_func, info, NULL);
2456 for (j = info->attributes; j; j = j->next->next)
2458 gtk_cell_layout_add_attribute (cell_layout,
2461 GPOINTER_TO_INT (j->next->data));
2467 gtk_combo_box_menu_setup (GtkComboBox *combo_box,
2468 gboolean add_children)
2472 if (combo_box->priv->cell_view)
2474 combo_box->priv->button = gtk_toggle_button_new ();
2475 gtk_button_set_focus_on_click (GTK_BUTTON (combo_box->priv->button),
2476 combo_box->priv->focus_on_click);
2478 g_signal_connect (combo_box->priv->button, "toggled",
2479 G_CALLBACK (gtk_combo_box_button_toggled), combo_box);
2480 g_signal_connect_after (combo_box->priv->button,
2482 G_CALLBACK (gtk_combo_box_key_press), combo_box);
2483 gtk_widget_set_parent (combo_box->priv->button,
2484 GTK_BIN (combo_box)->child->parent);
2486 combo_box->priv->box = gtk_hbox_new (FALSE, 0);
2487 gtk_container_add (GTK_CONTAINER (combo_box->priv->button),
2488 combo_box->priv->box);
2490 combo_box->priv->separator = gtk_vseparator_new ();
2491 gtk_container_add (GTK_CONTAINER (combo_box->priv->box),
2492 combo_box->priv->separator);
2494 combo_box->priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
2495 gtk_container_add (GTK_CONTAINER (combo_box->priv->box),
2496 combo_box->priv->arrow);
2498 gtk_widget_show_all (combo_box->priv->button);
2502 combo_box->priv->button = gtk_toggle_button_new ();
2503 gtk_button_set_focus_on_click (GTK_BUTTON (combo_box->priv->button),
2504 combo_box->priv->focus_on_click);
2506 g_signal_connect (combo_box->priv->button, "toggled",
2507 G_CALLBACK (gtk_combo_box_button_toggled), combo_box);
2508 g_signal_connect_after (combo_box, "key_press_event",
2509 G_CALLBACK (gtk_combo_box_key_press), combo_box);
2510 gtk_widget_set_parent (combo_box->priv->button,
2511 GTK_BIN (combo_box)->child->parent);
2513 combo_box->priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
2514 gtk_container_add (GTK_CONTAINER (combo_box->priv->button),
2515 combo_box->priv->arrow);
2516 gtk_widget_show_all (combo_box->priv->button);
2519 g_signal_connect (combo_box->priv->button, "button_press_event",
2520 G_CALLBACK (gtk_combo_box_menu_button_press),
2522 g_signal_connect (combo_box->priv->button, "state_changed",
2523 G_CALLBACK (gtk_combo_box_button_state_changed),
2526 /* create our funky menu */
2527 menu = gtk_menu_new ();
2528 g_signal_connect (menu, "key_press_event",
2529 G_CALLBACK (gtk_combo_box_menu_key_press), combo_box);
2530 gtk_combo_box_set_popup_widget (combo_box, menu);
2534 gtk_combo_box_menu_fill (combo_box);
2536 /* the column is needed in tree_column_row_is_sensitive() */
2537 combo_box->priv->column = gtk_tree_view_column_new ();
2538 g_object_ref_sink (combo_box->priv->column);
2539 gtk_combo_box_sync_cells (combo_box,
2540 GTK_CELL_LAYOUT (combo_box->priv->column));
2542 gtk_combo_box_update_title (combo_box);
2546 gtk_combo_box_menu_fill (GtkComboBox *combo_box)
2550 if (!combo_box->priv->model)
2553 menu = combo_box->priv->popup_widget;
2555 if (combo_box->priv->add_tearoffs)
2557 GtkWidget *tearoff = gtk_tearoff_menu_item_new ();
2559 gtk_widget_show (tearoff);
2561 if (combo_box->priv->wrap_width)
2562 gtk_menu_attach (GTK_MENU (menu), tearoff,
2563 0, combo_box->priv->wrap_width, 0, 1);
2565 gtk_menu_shell_append (GTK_MENU_SHELL (menu), tearoff);
2568 gtk_combo_box_menu_fill_level (combo_box, menu, NULL);
2572 gtk_cell_view_menu_item_new (GtkComboBox *combo_box,
2573 GtkTreeModel *model,
2576 GtkWidget *cell_view;
2581 cell_view = gtk_cell_view_new ();
2582 gtk_cell_view_set_model (GTK_CELL_VIEW (cell_view), model);
2583 path = gtk_tree_model_get_path (model, iter);
2584 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (cell_view), path);
2585 gtk_tree_path_free (path);
2587 gtk_combo_box_sync_cells (combo_box, GTK_CELL_LAYOUT (cell_view));
2588 gtk_widget_size_request (cell_view, &req);
2589 gtk_widget_show (cell_view);
2591 item = gtk_menu_item_new ();
2592 gtk_container_add (GTK_CONTAINER (item), cell_view);
2598 gtk_combo_box_menu_fill_level (GtkComboBox *combo_box,
2600 GtkTreeIter *parent)
2602 GtkTreeModel *model = combo_box->priv->model;
2603 GtkWidget *item, *submenu, *subitem, *separator;
2605 gboolean is_separator;
2610 n_children = gtk_tree_model_iter_n_children (model, parent);
2613 for (i = 0; i < n_children; i++)
2615 gtk_tree_model_iter_nth_child (model, &iter, parent, i);
2617 if (combo_box->priv->row_separator_func)
2618 is_separator = (*combo_box->priv->row_separator_func) (combo_box->priv->model, &iter,
2619 combo_box->priv->row_separator_data);
2621 is_separator = FALSE;
2625 item = gtk_separator_menu_item_new ();
2626 path = gtk_tree_model_get_path (model, &iter);
2627 g_object_set_data_full (G_OBJECT (item),
2628 I_("gtk-combo-box-item-path"),
2629 gtk_tree_row_reference_new (model, path),
2630 (GDestroyNotify)gtk_tree_row_reference_free);
2631 gtk_tree_path_free (path);
2635 item = gtk_cell_view_menu_item_new (combo_box, model, &iter);
2636 if (gtk_tree_model_iter_has_child (model, &iter))
2638 submenu = gtk_menu_new ();
2639 gtk_widget_show (submenu);
2640 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
2642 /* Ugly - since menus can only activate leafs, we have to
2643 * duplicate the item inside the submenu.
2645 subitem = gtk_cell_view_menu_item_new (combo_box, model, &iter);
2646 separator = gtk_separator_menu_item_new ();
2647 gtk_widget_show (subitem);
2648 gtk_widget_show (separator);
2649 g_signal_connect (subitem, "activate",
2650 G_CALLBACK (gtk_combo_box_menu_item_activate),
2652 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), subitem);
2653 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), separator);
2655 gtk_combo_box_menu_fill_level (combo_box, submenu, &iter);
2658 g_signal_connect (item, "activate",
2659 G_CALLBACK (gtk_combo_box_menu_item_activate),
2663 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
2664 if (combo_box->priv->wrap_width && menu == combo_box->priv->popup_widget)
2665 gtk_combo_box_relayout_item (combo_box, item, &iter, last);
2666 gtk_widget_show (item);
2673 gtk_combo_box_menu_destroy (GtkComboBox *combo_box)
2675 g_signal_handlers_disconnect_matched (combo_box->priv->button,
2676 G_SIGNAL_MATCH_DATA,
2678 gtk_combo_box_menu_button_press, NULL);
2679 g_signal_handlers_disconnect_matched (combo_box->priv->button,
2680 G_SIGNAL_MATCH_DATA,
2682 gtk_combo_box_button_state_changed, combo_box);
2684 /* unparent will remove our latest ref */
2685 gtk_widget_unparent (combo_box->priv->button);
2687 combo_box->priv->box = NULL;
2688 combo_box->priv->button = NULL;
2689 combo_box->priv->arrow = NULL;
2690 combo_box->priv->separator = NULL;
2692 g_object_unref (combo_box->priv->column);
2693 combo_box->priv->column = NULL;
2695 /* changing the popup window will unref the menu and the children */
2703 menu_occupied (GtkMenu *menu,
2707 guint bottom_attach)
2711 for (i = GTK_MENU_SHELL (menu)->children; i; i = i->next)
2715 gtk_container_child_get (GTK_CONTAINER (menu),
2719 "bottom-attach", &b,
2723 /* look if this item intersects with the given coordinates */
2724 if (right_attach > l && left_attach < r && bottom_attach > t && top_attach < b)
2732 gtk_combo_box_relayout_item (GtkComboBox *combo_box,
2737 gint current_col = 0, current_row = 0;
2738 gint rows = 1, cols = 1;
2739 GtkWidget *menu = combo_box->priv->popup_widget;
2741 if (!GTK_IS_MENU_SHELL (menu))
2744 if (combo_box->priv->col_column == -1 &&
2745 combo_box->priv->row_column == -1 &&
2748 gtk_container_child_get (GTK_CONTAINER (menu),
2750 "right_attach", ¤t_col,
2751 "top_attach", ¤t_row,
2753 if (current_col + cols > combo_box->priv->wrap_width)
2761 if (combo_box->priv->col_column != -1)
2762 gtk_tree_model_get (combo_box->priv->model, iter,
2763 combo_box->priv->col_column, &cols,
2765 if (combo_box->priv->row_column != -1)
2766 gtk_tree_model_get (combo_box->priv->model, iter,
2767 combo_box->priv->row_column, &rows,
2772 if (current_col + cols > combo_box->priv->wrap_width)
2778 if (!menu_occupied (GTK_MENU (menu),
2779 current_col, current_col + cols,
2780 current_row, current_row + rows))
2787 /* set attach props */
2788 gtk_menu_attach (GTK_MENU (menu), item,
2789 current_col, current_col + cols,
2790 current_row, current_row + rows);
2794 gtk_combo_box_relayout (GtkComboBox *combo_box)
2799 menu = combo_box->priv->popup_widget;
2801 /* do nothing unless we are in menu style and realized */
2802 if (combo_box->priv->tree_view || !GTK_IS_MENU_SHELL (menu))
2805 list = gtk_container_get_children (GTK_CONTAINER (menu));
2807 for (j = g_list_last (list); j; j = j->prev)
2808 gtk_container_remove (GTK_CONTAINER (menu), j->data);
2810 gtk_combo_box_menu_fill (combo_box);
2817 gtk_combo_box_menu_button_press (GtkWidget *widget,
2818 GdkEventButton *event,
2821 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2823 if (GTK_IS_MENU (combo_box->priv->popup_widget) &&
2824 event->type == GDK_BUTTON_PRESS && event->button == 1)
2826 if (combo_box->priv->focus_on_click &&
2827 !GTK_WIDGET_HAS_FOCUS (combo_box->priv->button))
2828 gtk_widget_grab_focus (combo_box->priv->button);
2830 gtk_combo_box_menu_popup (combo_box, event->button, event->time);
2839 gtk_combo_box_menu_item_activate (GtkWidget *item,
2842 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2843 GtkWidget *cell_view;
2847 cell_view = GTK_BIN (item)->child;
2849 g_return_if_fail (GTK_IS_CELL_VIEW (cell_view));
2851 path = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (cell_view));
2853 if (gtk_tree_model_get_iter (combo_box->priv->model, &iter, path))
2854 gtk_combo_box_set_active_iter (combo_box, &iter);
2856 gtk_tree_path_free (path);
2858 combo_box->priv->editing_canceled = FALSE;
2862 gtk_combo_box_model_row_inserted (GtkTreeModel *model,
2867 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2869 if (combo_box->priv->tree_view)
2870 gtk_combo_box_list_popup_resize (combo_box);
2872 gtk_combo_box_menu_row_inserted (model, path, iter, user_data);
2876 gtk_combo_box_model_row_deleted (GtkTreeModel *model,
2880 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2882 if (combo_box->priv->cell_view)
2884 if (!gtk_tree_row_reference_valid (combo_box->priv->active_row))
2885 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (combo_box->priv->cell_view), NULL);
2888 if (combo_box->priv->tree_view)
2889 gtk_combo_box_list_popup_resize (combo_box);
2891 gtk_combo_box_menu_row_deleted (model, path, user_data);
2895 gtk_combo_box_model_rows_reordered (GtkTreeModel *model,
2901 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2903 gtk_tree_row_reference_reordered (G_OBJECT (user_data), path, iter, new_order);
2905 if (!combo_box->priv->tree_view)
2906 gtk_combo_box_menu_rows_reordered (model, path, iter, new_order, user_data);
2910 gtk_combo_box_model_row_changed (GtkTreeModel *model,
2915 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2916 GtkTreePath *active_path;
2918 /* FIXME this belongs to GtkCellView */
2919 if (gtk_tree_row_reference_valid (combo_box->priv->active_row))
2921 active_path = gtk_tree_row_reference_get_path (combo_box->priv->active_row);
2922 if (gtk_tree_path_compare (path, active_path) == 0 &&
2923 combo_box->priv->cell_view)
2924 gtk_widget_queue_resize (GTK_WIDGET (combo_box->priv->cell_view));
2925 gtk_tree_path_free (active_path);
2928 if (combo_box->priv->tree_view)
2929 gtk_combo_box_list_row_changed (model, path, iter, user_data);
2931 gtk_combo_box_menu_row_changed (model, path, iter, user_data);
2935 list_popup_resize_idle (gpointer user_data)
2937 GtkComboBox *combo_box;
2938 gint x, y, width, height;
2940 GDK_THREADS_ENTER ();
2942 combo_box = GTK_COMBO_BOX (user_data);
2944 if (combo_box->priv->tree_view &&
2945 GTK_WIDGET_MAPPED (combo_box->priv->popup_window))
2947 gtk_combo_box_list_position (combo_box, &x, &y, &width, &height);
2949 gtk_widget_set_size_request (combo_box->priv->popup_window, width, height);
2950 gtk_window_move (GTK_WINDOW (combo_box->priv->popup_window), x, y);
2953 combo_box->priv->resize_idle_id = 0;
2955 GDK_THREADS_LEAVE ();
2961 gtk_combo_box_list_popup_resize (GtkComboBox *combo_box)
2963 if (!combo_box->priv->resize_idle_id)
2964 combo_box->priv->resize_idle_id =
2965 g_idle_add (list_popup_resize_idle, combo_box);
2969 gtk_combo_box_model_row_expanded (GtkTreeModel *model,
2974 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2976 gtk_combo_box_list_popup_resize (combo_box);
2981 find_menu_by_path (GtkWidget *menu,
2983 gboolean skip_first)
2988 GtkTreeRowReference *mref;
2992 list = gtk_container_get_children (GTK_CONTAINER (menu));
2995 for (i = list; i; i = i->next)
2997 if (GTK_IS_SEPARATOR_MENU_ITEM (i->data))
2999 mref = g_object_get_data (G_OBJECT (i->data), "gtk-combo-box-item-path");
3002 else if (!gtk_tree_row_reference_valid (mref))
3005 mpath = gtk_tree_row_reference_get_path (mref);
3007 else if (GTK_IS_CELL_VIEW (GTK_BIN (i->data)->child))
3015 mpath = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (GTK_BIN (i->data)->child));
3020 /* this case is necessary, since the row reference of
3021 * the cell view may already be updated after a deletion
3028 if (gtk_tree_path_compare (mpath, path) == 0)
3030 gtk_tree_path_free (mpath);
3034 if (gtk_tree_path_is_ancestor (mpath, path))
3036 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
3037 if (submenu != NULL)
3039 gtk_tree_path_free (mpath);
3040 item = find_menu_by_path (submenu, path, TRUE);
3044 gtk_tree_path_free (mpath);
3054 dump_menu_tree (GtkWidget *menu,
3061 list = gtk_container_get_children (GTK_CONTAINER (menu));
3062 for (i = list; i; i = i->next)
3064 if (GTK_IS_CELL_VIEW (GTK_BIN (i->data)->child))
3066 path = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (GTK_BIN (i->data)->child));
3067 g_print ("%*s%s\n", 2 * level, " ", gtk_tree_path_to_string (path));
3068 gtk_tree_path_free (path);
3070 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
3071 if (submenu != NULL)
3072 dump_menu_tree (submenu, level + 1);
3081 gtk_combo_box_menu_row_inserted (GtkTreeModel *model,
3087 GtkWidget *item, *menu, *separator;
3088 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3092 gboolean is_separator;
3094 if (!combo_box->priv->popup_widget)
3097 depth = gtk_tree_path_get_depth (path);
3098 pos = gtk_tree_path_get_indices (path)[depth - 1];
3101 ppath = gtk_tree_path_copy (path);
3102 gtk_tree_path_up (ppath);
3103 parent = find_menu_by_path (combo_box->priv->popup_widget, ppath, FALSE);
3104 gtk_tree_path_free (ppath);
3106 menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (parent));
3109 menu = gtk_menu_new ();
3110 gtk_widget_show (menu);
3111 gtk_menu_item_set_submenu (GTK_MENU_ITEM (parent), menu);
3113 /* Ugly - since menus can only activate leaves, we have to
3114 * duplicate the item inside the submenu.
3116 gtk_tree_model_iter_parent (model, &piter, iter);
3117 item = gtk_cell_view_menu_item_new (combo_box, model, &piter);
3118 separator = gtk_separator_menu_item_new ();
3119 g_signal_connect (item, "activate",
3120 G_CALLBACK (gtk_combo_box_menu_item_activate),
3122 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
3123 gtk_menu_shell_append (GTK_MENU_SHELL (menu), separator);
3124 if (cell_view_is_sensitive (GTK_CELL_VIEW (GTK_BIN (item)->child)))
3126 gtk_widget_show (item);
3127 gtk_widget_show (separator);
3134 menu = combo_box->priv->popup_widget;
3135 if (combo_box->priv->add_tearoffs)
3139 if (combo_box->priv->row_separator_func)
3140 is_separator = (*combo_box->priv->row_separator_func) (model, iter,
3141 combo_box->priv->row_separator_data);
3143 is_separator = FALSE;
3147 item = gtk_separator_menu_item_new ();
3148 g_object_set_data_full (G_OBJECT (item),
3149 I_("gtk-combo-box-item-path"),
3150 gtk_tree_row_reference_new (model, path),
3151 (GDestroyNotify)gtk_tree_row_reference_free);
3155 item = gtk_cell_view_menu_item_new (combo_box, model, iter);
3157 g_signal_connect (item, "activate",
3158 G_CALLBACK (gtk_combo_box_menu_item_activate),
3162 gtk_widget_show (item);
3163 gtk_menu_shell_insert (GTK_MENU_SHELL (menu), item, pos);
3167 gtk_combo_box_menu_row_deleted (GtkTreeModel *model,
3171 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3175 if (!combo_box->priv->popup_widget)
3178 item = find_menu_by_path (combo_box->priv->popup_widget, path, FALSE);
3179 menu = gtk_widget_get_parent (item);
3180 gtk_container_remove (GTK_CONTAINER (menu), item);
3184 gtk_combo_box_menu_rows_reordered (GtkTreeModel *model,
3190 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3192 gtk_combo_box_relayout (combo_box);
3196 gtk_combo_box_menu_row_changed (GtkTreeModel *model,
3201 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3204 gboolean is_separator;
3206 if (!combo_box->priv->popup_widget)
3209 item = find_menu_by_path (combo_box->priv->popup_widget, path, FALSE);
3211 if (combo_box->priv->row_separator_func)
3212 is_separator = (*combo_box->priv->row_separator_func) (model, iter,
3213 combo_box->priv->row_separator_data);
3215 is_separator = FALSE;
3217 if (is_separator != GTK_IS_SEPARATOR_MENU_ITEM (item))
3219 gtk_combo_box_menu_row_deleted (model, path, combo_box);
3220 gtk_combo_box_menu_row_inserted (model, path, iter, combo_box);
3223 if (combo_box->priv->wrap_width
3224 && item->parent == combo_box->priv->popup_widget)
3226 GtkWidget *pitem = NULL;
3229 prev = gtk_tree_path_copy (path);
3231 if (gtk_tree_path_prev (prev))
3232 pitem = find_menu_by_path (combo_box->priv->popup_widget, prev, FALSE);
3234 gtk_tree_path_free (prev);
3236 /* unattach item so gtk_combo_box_relayout_item() won't spuriously
3238 gtk_container_child_set (GTK_CONTAINER (combo_box->priv->popup_widget),
3243 "bottom-attach", -1,
3246 gtk_combo_box_relayout_item (combo_box, item, iter, pitem);
3249 width = gtk_combo_box_calc_requested_width (combo_box, path);
3251 if (width > combo_box->priv->width)
3253 if (combo_box->priv->cell_view)
3255 gtk_widget_set_size_request (combo_box->priv->cell_view, width, -1);
3256 gtk_widget_queue_resize (combo_box->priv->cell_view);
3258 combo_box->priv->width = width;
3267 gtk_combo_box_list_setup (GtkComboBox *combo_box)
3269 GtkTreeSelection *sel;
3271 combo_box->priv->button = gtk_toggle_button_new ();
3272 gtk_widget_set_parent (combo_box->priv->button,
3273 GTK_BIN (combo_box)->child->parent);
3274 g_signal_connect (combo_box->priv->button, "button_press_event",
3275 G_CALLBACK (gtk_combo_box_list_button_pressed), combo_box);
3276 g_signal_connect (combo_box->priv->button, "toggled",
3277 G_CALLBACK (gtk_combo_box_button_toggled), combo_box);
3278 g_signal_connect_after (combo_box, "key_press_event",
3279 G_CALLBACK (gtk_combo_box_key_press), combo_box);
3281 combo_box->priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
3282 gtk_container_add (GTK_CONTAINER (combo_box->priv->button),
3283 combo_box->priv->arrow);
3284 combo_box->priv->separator = NULL;
3285 gtk_widget_show_all (combo_box->priv->button);
3287 if (combo_box->priv->cell_view)
3289 gtk_cell_view_set_background_color (GTK_CELL_VIEW (combo_box->priv->cell_view),
3290 >K_WIDGET (combo_box)->style->base[GTK_WIDGET_STATE (combo_box)]);
3292 combo_box->priv->box = gtk_event_box_new ();
3293 gtk_event_box_set_visible_window (GTK_EVENT_BOX (combo_box->priv->box),
3296 if (combo_box->priv->has_frame)
3298 combo_box->priv->cell_view_frame = gtk_frame_new (NULL);
3299 gtk_frame_set_shadow_type (GTK_FRAME (combo_box->priv->cell_view_frame),
3304 combo_box->priv->cell_view_frame = gtk_event_box_new ();
3305 gtk_event_box_set_visible_window (GTK_EVENT_BOX (combo_box->priv->cell_view_frame),
3309 gtk_widget_set_parent (combo_box->priv->cell_view_frame,
3310 GTK_BIN (combo_box)->child->parent);
3311 gtk_container_add (GTK_CONTAINER (combo_box->priv->cell_view_frame),
3312 combo_box->priv->box);
3313 gtk_widget_show_all (combo_box->priv->cell_view_frame);
3315 g_signal_connect (combo_box->priv->box, "button_press_event",
3316 G_CALLBACK (gtk_combo_box_list_button_pressed),
3320 combo_box->priv->tree_view = gtk_tree_view_new ();
3321 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (combo_box->priv->tree_view));
3322 gtk_tree_selection_set_mode (sel, GTK_SELECTION_BROWSE);
3323 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (combo_box->priv->tree_view),
3325 gtk_tree_view_set_hover_selection (GTK_TREE_VIEW (combo_box->priv->tree_view),
3327 if (combo_box->priv->row_separator_func)
3328 gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (combo_box->priv->tree_view),
3329 combo_box->priv->row_separator_func,
3330 combo_box->priv->row_separator_data,
3332 if (combo_box->priv->model)
3333 gtk_tree_view_set_model (GTK_TREE_VIEW (combo_box->priv->tree_view),
3334 combo_box->priv->model);
3336 combo_box->priv->column = gtk_tree_view_column_new ();
3337 gtk_tree_view_append_column (GTK_TREE_VIEW (combo_box->priv->tree_view),
3338 combo_box->priv->column);
3341 gtk_combo_box_sync_cells (combo_box,
3342 GTK_CELL_LAYOUT (combo_box->priv->column));
3344 if (gtk_tree_row_reference_valid (combo_box->priv->active_row))
3348 path = gtk_tree_row_reference_get_path (combo_box->priv->active_row);
3349 gtk_tree_view_set_cursor (GTK_TREE_VIEW (combo_box->priv->tree_view),
3351 gtk_tree_path_free (path);
3354 /* set sample/popup widgets */
3355 gtk_combo_box_set_popup_widget (combo_box, combo_box->priv->tree_view);
3357 g_signal_connect (combo_box->priv->tree_view, "key_press_event",
3358 G_CALLBACK (gtk_combo_box_list_key_press),
3360 g_signal_connect (combo_box->priv->tree_view, "enter_notify_event",
3361 G_CALLBACK (gtk_combo_box_list_enter_notify),
3363 g_signal_connect (combo_box->priv->tree_view, "row_expanded",
3364 G_CALLBACK (gtk_combo_box_model_row_expanded),
3366 g_signal_connect (combo_box->priv->tree_view, "row_collapsed",
3367 G_CALLBACK (gtk_combo_box_model_row_expanded),
3369 g_signal_connect (combo_box->priv->popup_window, "button_press_event",
3370 G_CALLBACK (gtk_combo_box_list_button_pressed),
3372 g_signal_connect (combo_box->priv->popup_window, "button_release_event",
3373 G_CALLBACK (gtk_combo_box_list_button_released),
3376 gtk_widget_show (combo_box->priv->tree_view);
3380 gtk_combo_box_list_destroy (GtkComboBox *combo_box)
3382 /* disconnect signals */
3383 g_signal_handlers_disconnect_matched (combo_box->priv->tree_view,
3384 G_SIGNAL_MATCH_DATA,
3385 0, 0, NULL, NULL, combo_box);
3386 g_signal_handlers_disconnect_matched (combo_box->priv->button,
3387 G_SIGNAL_MATCH_DATA,
3389 gtk_combo_box_list_button_pressed,
3391 g_signal_handlers_disconnect_matched (combo_box->priv->popup_window,
3392 G_SIGNAL_MATCH_DATA,
3394 gtk_combo_box_list_button_pressed,
3396 g_signal_handlers_disconnect_matched (combo_box->priv->popup_window,
3397 G_SIGNAL_MATCH_DATA,
3399 gtk_combo_box_list_button_released,
3402 g_signal_handlers_disconnect_matched (combo_box->priv->popup_window,
3403 G_SIGNAL_MATCH_DATA,
3405 gtk_combo_box_child_show,
3408 g_signal_handlers_disconnect_matched (combo_box->priv->popup_window,
3409 G_SIGNAL_MATCH_DATA,
3411 gtk_combo_box_child_hide,
3414 if (combo_box->priv->box)
3415 g_signal_handlers_disconnect_matched (combo_box->priv->box,
3416 G_SIGNAL_MATCH_DATA,
3418 gtk_combo_box_list_button_pressed,
3421 /* destroy things (unparent will kill the latest ref from us)
3422 * last unref on button will destroy the arrow
3424 gtk_widget_unparent (combo_box->priv->button);
3425 combo_box->priv->button = NULL;
3426 combo_box->priv->arrow = NULL;
3428 if (combo_box->priv->cell_view)
3430 g_object_set (combo_box->priv->cell_view,
3431 "background-set", FALSE,
3435 if (combo_box->priv->cell_view_frame)
3437 gtk_widget_unparent (combo_box->priv->cell_view_frame);
3438 combo_box->priv->cell_view_frame = NULL;
3439 combo_box->priv->box = NULL;
3442 if (combo_box->priv->scroll_timer)
3444 g_source_remove (combo_box->priv->scroll_timer);
3445 combo_box->priv->scroll_timer = 0;
3448 if (combo_box->priv->resize_idle_id)
3450 g_source_remove (combo_box->priv->resize_idle_id);
3451 combo_box->priv->resize_idle_id = 0;
3454 gtk_widget_destroy (combo_box->priv->tree_view);
3456 combo_box->priv->tree_view = NULL;
3457 combo_box->priv->popup_widget = NULL;
3463 gtk_combo_box_list_button_pressed (GtkWidget *widget,
3464 GdkEventButton *event,
3467 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3469 GtkWidget *ewidget = gtk_get_event_widget ((GdkEvent *)event);
3471 if (ewidget == combo_box->priv->popup_window)
3474 if ((ewidget != combo_box->priv->button && ewidget != combo_box->priv->box) ||
3475 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (combo_box->priv->button)))
3478 if (combo_box->priv->focus_on_click &&
3479 !GTK_WIDGET_HAS_FOCUS (combo_box->priv->button))
3480 gtk_widget_grab_focus (combo_box->priv->button);
3482 gtk_combo_box_popup (combo_box);
3484 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
3487 combo_box->priv->auto_scroll = FALSE;
3488 if (combo_box->priv->scroll_timer == 0)
3489 combo_box->priv->scroll_timer = g_timeout_add (SCROLL_TIME,
3490 (GSourceFunc) gtk_combo_box_list_scroll_timeout,
3493 combo_box->priv->popup_in_progress = TRUE;
3499 gtk_combo_box_list_button_released (GtkWidget *widget,
3500 GdkEventButton *event,
3504 GtkTreePath *path = NULL;
3507 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3509 gboolean popup_in_progress = FALSE;
3511 GtkWidget *ewidget = gtk_get_event_widget ((GdkEvent *)event);
3513 if (combo_box->priv->popup_in_progress)
3515 popup_in_progress = TRUE;
3516 combo_box->priv->popup_in_progress = FALSE;
3519 gtk_tree_view_set_hover_expand (GTK_TREE_VIEW (combo_box->priv->tree_view),
3521 if (combo_box->priv->scroll_timer)
3523 g_source_remove (combo_box->priv->scroll_timer);
3524 combo_box->priv->scroll_timer = 0;
3527 if (ewidget != combo_box->priv->tree_view)
3529 if ((ewidget == combo_box->priv->button ||
3530 ewidget == combo_box->priv->box) &&
3531 !popup_in_progress &&
3532 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (combo_box->priv->button)))
3534 gtk_combo_box_popdown (combo_box);
3538 /* released outside treeview */
3539 if (ewidget != combo_box->priv->button &&
3540 ewidget != combo_box->priv->box)
3542 gtk_combo_box_popdown (combo_box);
3550 /* select something cool */
3551 ret = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (combo_box->priv->tree_view),
3557 return TRUE; /* clicked outside window? */
3559 gtk_tree_model_get_iter (combo_box->priv->model, &iter, path);
3560 gtk_tree_path_free (path);
3562 if (tree_column_row_is_sensitive (combo_box, &iter))
3563 gtk_combo_box_set_active_iter (combo_box, &iter);
3565 gtk_combo_box_popdown (combo_box);
3571 gtk_combo_box_key_press (GtkWidget *widget,
3575 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3576 guint state = event->state & gtk_accelerator_get_default_mod_mask ();
3579 GtkTreeIter new_iter;
3581 if (combo_box->priv->model == NULL)
3584 if ((event->keyval == GDK_Down || event->keyval == GDK_KP_Down) &&
3585 state == GDK_MOD1_MASK)
3587 gtk_combo_box_popup (combo_box);
3595 switch (event->keyval)
3599 if (gtk_combo_box_get_active_iter (combo_box, &iter))
3601 found = tree_next (combo_box, combo_box->priv->model,
3602 &iter, &new_iter, FALSE);
3605 /* else fall through */
3607 case GDK_KP_Page_Up:
3610 found = tree_first (combo_box, combo_box->priv->model, &new_iter, FALSE);
3615 if (gtk_combo_box_get_active_iter (combo_box, &iter))
3617 found = tree_prev (combo_box, combo_box->priv->model,
3618 &iter, &new_iter, FALSE);
3621 /* else fall through */
3623 case GDK_KP_Page_Down:
3626 found = tree_last (combo_box, combo_box->priv->model, &new_iter, FALSE);
3633 gtk_combo_box_set_active_iter (combo_box, &new_iter);
3639 gtk_combo_box_menu_key_press (GtkWidget *widget,
3643 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3644 guint state = event->state & gtk_accelerator_get_default_mod_mask ();
3646 if ((event->keyval == GDK_Up || event->keyval == GDK_KP_Up) &&
3647 state == GDK_MOD1_MASK)
3649 gtk_combo_box_popdown (combo_box);
3658 gtk_combo_box_list_key_press (GtkWidget *widget,
3662 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3664 guint state = event->state & gtk_accelerator_get_default_mod_mask ();
3666 if (event->keyval == GDK_Escape ||
3667 ((event->keyval == GDK_Up || event->keyval == GDK_KP_Up) &&
3668 state == GDK_MOD1_MASK))
3670 /* reset active item -- this is incredibly lame and ugly */
3671 if (gtk_combo_box_get_active_iter (combo_box, &iter))
3672 gtk_combo_box_set_active_iter (combo_box, &iter);
3674 gtk_combo_box_popdown (combo_box);
3679 if (event->keyval == GDK_Return || event->keyval == GDK_KP_Enter ||
3680 event->keyval == GDK_space || event->keyval == GDK_KP_Space)
3683 GtkTreeModel *model = NULL;
3685 if (combo_box->priv->model)
3687 GtkTreeSelection *sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (combo_box->priv->tree_view));
3689 if (gtk_tree_selection_get_selected (sel, &model, &iter))
3690 gtk_combo_box_set_active_iter (combo_box, &iter);
3693 gtk_combo_box_popdown (combo_box);
3702 gtk_combo_box_list_auto_scroll (GtkComboBox *combo_box,
3706 GtkWidget *tree_view = combo_box->priv->tree_view;
3710 adj = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (combo_box->priv->scrolled_window));
3711 if (adj && adj->upper - adj->lower > adj->page_size)
3713 if (x <= tree_view->allocation.x &&
3714 adj->lower < adj->value)
3716 value = adj->value - (tree_view->allocation.x - x + 1);
3717 gtk_adjustment_set_value (adj, CLAMP (value, adj->lower, adj->upper - adj->page_size));
3719 else if (x >= tree_view->allocation.x + tree_view->allocation.width &&
3720 adj->upper - adj->page_size > adj->value)
3722 value = adj->value + (x - tree_view->allocation.x - tree_view->allocation.width + 1);
3723 gtk_adjustment_set_value (adj, CLAMP (value, 0.0, adj->upper - adj->page_size));
3727 adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (combo_box->priv->scrolled_window));
3728 if (adj && adj->upper - adj->lower > adj->page_size)
3730 if (y <= tree_view->allocation.y &&
3731 adj->lower < adj->value)
3733 value = adj->value - (tree_view->allocation.y - y + 1);
3734 gtk_adjustment_set_value (adj, CLAMP (value, adj->lower, adj->upper - adj->page_size));
3736 else if (y >= tree_view->allocation.height &&
3737 adj->upper - adj->page_size > adj->value)
3739 value = adj->value + (y - tree_view->allocation.height + 1);
3740 gtk_adjustment_set_value (adj, CLAMP (value, 0.0, adj->upper - adj->page_size));
3746 gtk_combo_box_list_scroll_timeout (GtkComboBox *combo_box)
3750 GDK_THREADS_ENTER ();
3752 if (combo_box->priv->auto_scroll)
3754 gdk_window_get_pointer (combo_box->priv->tree_view->window,
3756 gtk_combo_box_list_auto_scroll (combo_box, x, y);
3759 GDK_THREADS_LEAVE ();
3765 gtk_combo_box_list_enter_notify (GtkWidget *widget,
3766 GdkEventCrossing *event,
3769 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3771 combo_box->priv->auto_scroll = TRUE;
3778 gtk_combo_box_list_row_changed (GtkTreeModel *model,
3783 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3786 width = gtk_combo_box_calc_requested_width (combo_box, path);
3788 if (width > combo_box->priv->width)
3790 if (combo_box->priv->cell_view)
3792 gtk_widget_set_size_request (combo_box->priv->cell_view, width, -1);
3793 gtk_widget_queue_resize (combo_box->priv->cell_view);
3795 combo_box->priv->width = width;
3800 * GtkCellLayout implementation
3804 pack_start_recurse (GtkWidget *menu,
3805 GtkCellRenderer *cell,
3811 list = gtk_container_get_children (GTK_CONTAINER (menu));
3812 for (i = list; i; i = i->next)
3814 if (GTK_IS_CELL_LAYOUT (GTK_BIN (i->data)->child))
3815 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (GTK_BIN (i->data)->child),
3818 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
3819 if (submenu != NULL)
3820 pack_start_recurse (submenu, cell, expand);
3827 gtk_combo_box_cell_layout_pack_start (GtkCellLayout *layout,
3828 GtkCellRenderer *cell,
3831 ComboCellInfo *info;
3832 GtkComboBox *combo_box;
3834 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
3835 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
3837 combo_box = GTK_COMBO_BOX (layout);
3839 g_object_ref_sink (cell);
3841 info = g_new0 (ComboCellInfo, 1);
3843 info->expand = expand;
3844 info->pack = GTK_PACK_START;
3846 combo_box->priv->cells = g_slist_append (combo_box->priv->cells, info);
3848 if (combo_box->priv->cell_view)
3849 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box->priv->cell_view),
3852 if (combo_box->priv->column)
3853 gtk_tree_view_column_pack_start (combo_box->priv->column, cell, expand);
3855 if (GTK_IS_MENU (combo_box->priv->popup_widget))
3856 pack_start_recurse (combo_box->priv->popup_widget, cell, expand);
3860 pack_end_recurse (GtkWidget *menu,
3861 GtkCellRenderer *cell,
3867 list = gtk_container_get_children (GTK_CONTAINER (menu));
3868 for (i = list; i; i = i->next)
3870 if (GTK_IS_CELL_LAYOUT (GTK_BIN (i->data)->child))
3871 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (GTK_BIN (i->data)->child),
3874 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
3875 if (submenu != NULL)
3876 pack_end_recurse (submenu, cell, expand);
3883 gtk_combo_box_cell_layout_pack_end (GtkCellLayout *layout,
3884 GtkCellRenderer *cell,
3887 ComboCellInfo *info;
3888 GtkComboBox *combo_box;
3890 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
3891 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
3893 combo_box = GTK_COMBO_BOX (layout);
3895 g_object_ref_sink (cell);
3897 info = g_new0 (ComboCellInfo, 1);
3899 info->expand = expand;
3900 info->pack = GTK_PACK_END;
3902 combo_box->priv->cells = g_slist_append (combo_box->priv->cells, info);
3904 if (combo_box->priv->cell_view)
3905 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (combo_box->priv->cell_view),
3908 if (combo_box->priv->column)
3909 gtk_tree_view_column_pack_end (combo_box->priv->column, cell, expand);
3911 if (GTK_IS_MENU (combo_box->priv->popup_widget))
3912 pack_end_recurse (combo_box->priv->popup_widget, cell, expand);
3916 clear_recurse (GtkWidget *menu)
3921 list = gtk_container_get_children (GTK_CONTAINER (menu));
3922 for (i = list; i; i = i->next)
3924 if (GTK_IS_CELL_LAYOUT (GTK_BIN (i->data)->child))
3925 gtk_cell_layout_clear (GTK_CELL_LAYOUT (GTK_BIN (i->data)->child));
3927 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
3928 if (submenu != NULL)
3929 clear_recurse (submenu);
3936 gtk_combo_box_cell_layout_clear (GtkCellLayout *layout)
3938 GtkComboBox *combo_box;
3941 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
3943 combo_box = GTK_COMBO_BOX (layout);
3945 if (combo_box->priv->cell_view)
3946 gtk_cell_layout_clear (GTK_CELL_LAYOUT (combo_box->priv->cell_view));
3948 if (combo_box->priv->column)
3949 gtk_tree_view_column_clear (combo_box->priv->column);
3951 for (i = combo_box->priv->cells; i; i = i->next)
3953 ComboCellInfo *info = (ComboCellInfo *)i->data;
3955 gtk_combo_box_cell_layout_clear_attributes (layout, info->cell);
3956 g_object_unref (info->cell);
3960 g_slist_free (combo_box->priv->cells);
3961 combo_box->priv->cells = NULL;
3963 if (GTK_IS_MENU (combo_box->priv->popup_widget))
3964 clear_recurse (combo_box->priv->popup_widget);
3968 add_attribute_recurse (GtkWidget *menu,
3969 GtkCellRenderer *cell,
3970 const gchar *attribute,
3976 list = gtk_container_get_children (GTK_CONTAINER (menu));
3977 for (i = list; i; i = i->next)
3979 if (GTK_IS_CELL_LAYOUT (GTK_BIN (i->data)->child))
3980 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (GTK_BIN (i->data)->child),
3981 cell, attribute, column);
3983 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
3984 if (submenu != NULL)
3985 add_attribute_recurse (submenu, cell, attribute, column);
3992 gtk_combo_box_cell_layout_add_attribute (GtkCellLayout *layout,
3993 GtkCellRenderer *cell,
3994 const gchar *attribute,
3997 ComboCellInfo *info;
3998 GtkComboBox *combo_box;
4000 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
4001 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4003 combo_box = GTK_COMBO_BOX (layout);
4005 info = gtk_combo_box_get_cell_info (combo_box, cell);
4007 info->attributes = g_slist_prepend (info->attributes,
4008 GINT_TO_POINTER (column));
4009 info->attributes = g_slist_prepend (info->attributes,
4010 g_strdup (attribute));
4012 if (combo_box->priv->cell_view)
4013 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo_box->priv->cell_view),
4014 cell, attribute, column);
4016 if (combo_box->priv->column)
4017 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo_box->priv->column),
4018 cell, attribute, column);
4020 if (GTK_IS_MENU (combo_box->priv->popup_widget))
4021 add_attribute_recurse (combo_box->priv->popup_widget, cell, attribute, column);
4022 gtk_widget_queue_resize (GTK_WIDGET (combo_box));
4026 combo_cell_data_func (GtkCellLayout *cell_layout,
4027 GtkCellRenderer *cell,
4028 GtkTreeModel *tree_model,
4032 ComboCellInfo *info = (ComboCellInfo *)data;
4033 GtkWidget *parent = NULL;
4038 (*info->func) (cell_layout, cell, tree_model, iter, info->func_data);
4040 if (GTK_IS_WIDGET (cell_layout))
4041 parent = gtk_widget_get_parent (GTK_WIDGET (cell_layout));
4043 if (GTK_IS_MENU_ITEM (parent) &&
4044 gtk_menu_item_get_submenu (GTK_MENU_ITEM (parent)))
4045 g_object_set (cell, "sensitive", TRUE, NULL);
4050 set_cell_data_func_recurse (GtkWidget *menu,
4051 GtkCellRenderer *cell,
4052 ComboCellInfo *info)
4056 GtkWidget *cell_view;
4058 list = gtk_container_get_children (GTK_CONTAINER (menu));
4059 for (i = list; i; i = i->next)
4061 cell_view = GTK_BIN (i->data)->child;
4062 if (GTK_IS_CELL_LAYOUT (cell_view))
4064 /* Override sensitivity for inner nodes; we don't
4065 * want menuitems with submenus to appear insensitive
4067 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (cell_view),
4069 combo_cell_data_func,
4071 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4072 if (submenu != NULL)
4073 set_cell_data_func_recurse (submenu, cell, info);
4081 gtk_combo_box_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4082 GtkCellRenderer *cell,
4083 GtkCellLayoutDataFunc func,
4085 GDestroyNotify destroy)
4087 ComboCellInfo *info;
4088 GtkComboBox *combo_box;
4090 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
4092 combo_box = GTK_COMBO_BOX (layout);
4094 info = gtk_combo_box_get_cell_info (combo_box, cell);
4095 g_return_if_fail (info != NULL);
4099 GDestroyNotify d = info->destroy;
4101 info->destroy = NULL;
4102 d (info->func_data);
4106 info->func_data = func_data;
4107 info->destroy = destroy;
4109 if (combo_box->priv->cell_view)
4110 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo_box->priv->cell_view), cell, func, func_data, NULL);
4112 if (combo_box->priv->column)
4113 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo_box->priv->column), cell, func, func_data, NULL);
4115 if (GTK_IS_MENU (combo_box->priv->popup_widget))
4116 set_cell_data_func_recurse (combo_box->priv->popup_widget, cell, info);
4118 gtk_widget_queue_resize (GTK_WIDGET (combo_box));
4122 clear_attributes_recurse (GtkWidget *menu,
4123 GtkCellRenderer *cell)
4128 list = gtk_container_get_children (GTK_CONTAINER (menu));
4129 for (i = list; i; i = i->next)
4131 if (GTK_IS_CELL_LAYOUT (GTK_BIN (i->data)->child))
4132 gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (GTK_BIN (i->data)->child),
4135 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4136 if (submenu != NULL)
4137 clear_attributes_recurse (submenu, cell);
4144 gtk_combo_box_cell_layout_clear_attributes (GtkCellLayout *layout,
4145 GtkCellRenderer *cell)
4147 ComboCellInfo *info;
4148 GtkComboBox *combo_box;
4151 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
4152 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4154 combo_box = GTK_COMBO_BOX (layout);
4156 info = gtk_combo_box_get_cell_info (combo_box, cell);
4157 g_return_if_fail (info != NULL);
4159 list = info->attributes;
4160 while (list && list->next)
4162 g_free (list->data);
4163 list = list->next->next;
4165 g_slist_free (info->attributes);
4166 info->attributes = NULL;
4168 if (combo_box->priv->cell_view)
4169 gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (combo_box->priv->cell_view), cell);
4171 if (combo_box->priv->column)
4172 gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (combo_box->priv->column), cell);
4174 if (GTK_IS_MENU (combo_box->priv->popup_widget))
4175 clear_attributes_recurse (combo_box->priv->popup_widget, cell);
4177 gtk_widget_queue_resize (GTK_WIDGET (combo_box));
4181 reorder_recurse (GtkWidget *menu,
4182 GtkCellRenderer *cell,
4188 list = gtk_container_get_children (GTK_CONTAINER (menu));
4189 for (i = list; i; i = i->next)
4191 if (GTK_IS_CELL_LAYOUT (GTK_BIN (i->data)->child))
4192 gtk_cell_layout_reorder (GTK_CELL_LAYOUT (GTK_BIN (i->data)->child),
4195 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4196 if (submenu != NULL)
4197 reorder_recurse (submenu, cell, position);
4204 gtk_combo_box_cell_layout_reorder (GtkCellLayout *layout,
4205 GtkCellRenderer *cell,
4208 ComboCellInfo *info;
4209 GtkComboBox *combo_box;
4212 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
4213 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4215 combo_box = GTK_COMBO_BOX (layout);
4217 info = gtk_combo_box_get_cell_info (combo_box, cell);
4219 g_return_if_fail (info != NULL);
4220 g_return_if_fail (position >= 0);
4222 link = g_slist_find (combo_box->priv->cells, info);
4224 g_return_if_fail (link != NULL);
4226 combo_box->priv->cells = g_slist_remove_link (combo_box->priv->cells, link);
4227 combo_box->priv->cells = g_slist_insert (combo_box->priv->cells, info,
4230 if (combo_box->priv->cell_view)
4231 gtk_cell_layout_reorder (GTK_CELL_LAYOUT (combo_box->priv->cell_view),
4234 if (combo_box->priv->column)
4235 gtk_cell_layout_reorder (GTK_CELL_LAYOUT (combo_box->priv->column),
4238 if (GTK_IS_MENU (combo_box->priv->popup_widget))
4239 reorder_recurse (combo_box->priv->popup_widget, cell, position);
4241 gtk_widget_queue_draw (GTK_WIDGET (combo_box));
4249 * gtk_combo_box_new:
4251 * Creates a new empty #GtkComboBox.
4253 * Return value: A new #GtkComboBox.
4258 gtk_combo_box_new (void)
4260 return g_object_new (GTK_TYPE_COMBO_BOX, NULL);
4264 * gtk_combo_box_new_with_model:
4265 * @model: A #GtkTreeModel.
4267 * Creates a new #GtkComboBox with the model initialized to @model.
4269 * Return value: A new #GtkComboBox.
4274 gtk_combo_box_new_with_model (GtkTreeModel *model)
4276 GtkComboBox *combo_box;
4278 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
4280 combo_box = g_object_new (GTK_TYPE_COMBO_BOX, "model", model, NULL);
4282 return GTK_WIDGET (combo_box);
4286 * gtk_combo_box_get_wrap_width:
4287 * @combo_box: A #GtkComboBox.
4289 * Returns the wrap width which is used to determine the number
4290 * of columns for the popup menu. If the wrap width is larger than
4291 * 1, the combo box is in table mode.
4293 * Returns: the wrap width.
4298 gtk_combo_box_get_wrap_width (GtkComboBox *combo_box)
4300 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), -1);
4302 return combo_box->priv->wrap_width;
4306 * gtk_combo_box_set_wrap_width:
4307 * @combo_box: A #GtkComboBox.
4308 * @width: Preferred number of columns.
4310 * Sets the wrap width of @combo_box to be @width. The wrap width is basically
4311 * the preferred number of columns when you want the popup to be layed out
4317 gtk_combo_box_set_wrap_width (GtkComboBox *combo_box,
4320 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4321 g_return_if_fail (width >= 0);
4323 if (width != combo_box->priv->wrap_width)
4325 combo_box->priv->wrap_width = width;
4327 gtk_combo_box_check_appearance (combo_box);
4328 gtk_combo_box_relayout (combo_box);
4330 g_object_notify (G_OBJECT (combo_box), "wrap-width");
4335 * gtk_combo_box_get_row_span_column:
4336 * @combo_box: A #GtkComboBox.
4338 * Returns the column with row span information for @combo_box.
4340 * Returns: the row span column.
4345 gtk_combo_box_get_row_span_column (GtkComboBox *combo_box)
4347 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), -1);
4349 return combo_box->priv->row_column;
4353 * gtk_combo_box_set_row_span_column:
4354 * @combo_box: A #GtkComboBox.
4355 * @row_span: A column in the model passed during construction.
4357 * Sets the column with row span information for @combo_box to be @row_span.
4358 * The row span column contains integers which indicate how many rows
4359 * an item should span.
4364 gtk_combo_box_set_row_span_column (GtkComboBox *combo_box,
4369 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4371 col = gtk_tree_model_get_n_columns (combo_box->priv->model);
4372 g_return_if_fail (row_span >= -1 && row_span < col);
4374 if (row_span != combo_box->priv->row_column)
4376 combo_box->priv->row_column = row_span;
4378 gtk_combo_box_relayout (combo_box);
4380 g_object_notify (G_OBJECT (combo_box), "row-span-column");
4385 * gtk_combo_box_get_column_span_column:
4386 * @combo_box: A #GtkComboBox.
4388 * Returns the column with column span information for @combo_box.
4390 * Returns: the column span column.
4395 gtk_combo_box_get_column_span_column (GtkComboBox *combo_box)
4397 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), -1);
4399 return combo_box->priv->col_column;
4403 * gtk_combo_box_set_column_span_column:
4404 * @combo_box: A #GtkComboBox.
4405 * @column_span: A column in the model passed during construction.
4407 * Sets the column with column span information for @combo_box to be
4408 * @column_span. The column span column contains integers which indicate
4409 * how many columns an item should span.
4414 gtk_combo_box_set_column_span_column (GtkComboBox *combo_box,
4419 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4421 col = gtk_tree_model_get_n_columns (combo_box->priv->model);
4422 g_return_if_fail (column_span >= -1 && column_span < col);
4424 if (column_span != combo_box->priv->col_column)
4426 combo_box->priv->col_column = column_span;
4428 gtk_combo_box_relayout (combo_box);
4430 g_object_notify (G_OBJECT (combo_box), "column-span-column");
4435 * gtk_combo_box_get_active:
4436 * @combo_box: A #GtkComboBox.
4438 * Returns the index of the currently active item, or -1 if there's no
4439 * active item. If the model is a non-flat treemodel, and the active item
4440 * is not an immediate child of the root of the tree, this function returns
4441 * <literal>gtk_tree_path_get_indices (path)[0]</literal>, where
4442 * <literal>path</literal> is the #GtkTreePath of the active item.
4444 * Return value: An integer which is the index of the currently active item, or
4445 * -1 if there's no active item.
4450 gtk_combo_box_get_active (GtkComboBox *combo_box)
4453 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), 0);
4455 if (gtk_tree_row_reference_valid (combo_box->priv->active_row))
4459 path = gtk_tree_row_reference_get_path (combo_box->priv->active_row);
4460 result = gtk_tree_path_get_indices (path)[0];
4461 gtk_tree_path_free (path);
4470 * gtk_combo_box_set_active:
4471 * @combo_box: A #GtkComboBox.
4472 * @index_: An index in the model passed during construction, or -1 to have
4475 * Sets the active item of @combo_box to be the item at @index.
4480 gtk_combo_box_set_active (GtkComboBox *combo_box,
4483 GtkTreePath *path = NULL;
4484 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4485 g_return_if_fail (index_ >= -1);
4488 path = gtk_tree_path_new_from_indices (index_, -1);
4490 gtk_combo_box_set_active_internal (combo_box, path);
4493 gtk_tree_path_free (path);
4497 gtk_combo_box_set_active_internal (GtkComboBox *combo_box,
4500 GtkTreePath *active_path;
4503 if (path && gtk_tree_row_reference_valid (combo_box->priv->active_row))
4505 active_path = gtk_tree_row_reference_get_path (combo_box->priv->active_row);
4506 path_cmp = gtk_tree_path_compare (path, active_path);
4507 gtk_tree_path_free (active_path);
4512 if (combo_box->priv->active_row)
4514 gtk_tree_row_reference_free (combo_box->priv->active_row);
4515 combo_box->priv->active_row = NULL;
4520 if (combo_box->priv->tree_view)
4521 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (combo_box->priv->tree_view)));
4524 GtkMenu *menu = GTK_MENU (combo_box->priv->popup_widget);
4526 if (GTK_IS_MENU (menu))
4527 gtk_menu_set_active (menu, -1);
4530 if (combo_box->priv->cell_view)
4531 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (combo_box->priv->cell_view), NULL);
4535 combo_box->priv->active_row =
4536 gtk_tree_row_reference_new (combo_box->priv->model, path);
4538 if (combo_box->priv->tree_view)
4540 gtk_tree_view_set_cursor (GTK_TREE_VIEW (combo_box->priv->tree_view),
4543 else if (GTK_IS_MENU (combo_box->priv->popup_widget))
4545 /* FIXME handle nested menus better */
4546 gtk_menu_set_active (GTK_MENU (combo_box->priv->popup_widget),
4547 gtk_tree_path_get_indices (path)[0]);
4550 if (combo_box->priv->cell_view)
4551 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (combo_box->priv->cell_view),
4555 g_signal_emit (combo_box, combo_box_signals[CHANGED], 0);
4556 g_object_notify (G_OBJECT (combo_box), "active");
4561 * gtk_combo_box_get_active_iter:
4562 * @combo_box: A #GtkComboBox
4563 * @iter: The uninitialized #GtkTreeIter.
4565 * Sets @iter to point to the current active item, if it exists.
4567 * Return value: %TRUE, if @iter was set
4572 gtk_combo_box_get_active_iter (GtkComboBox *combo_box,
4578 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE);
4580 if (!gtk_tree_row_reference_valid (combo_box->priv->active_row))
4583 path = gtk_tree_row_reference_get_path (combo_box->priv->active_row);
4584 result = gtk_tree_model_get_iter (combo_box->priv->model, iter, path);
4585 gtk_tree_path_free (path);
4591 * gtk_combo_box_set_active_iter:
4592 * @combo_box: A #GtkComboBox
4593 * @iter: The #GtkTreeIter.
4595 * Sets the current active item to be the one referenced by @iter.
4596 * @iter must correspond to a path of depth one.
4601 gtk_combo_box_set_active_iter (GtkComboBox *combo_box,
4606 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4608 path = gtk_tree_model_get_path (gtk_combo_box_get_model (combo_box), iter);
4609 gtk_combo_box_set_active_internal (combo_box, path);
4610 gtk_tree_path_free (path);
4614 * gtk_combo_box_set_model:
4615 * @combo_box: A #GtkComboBox.
4616 * @model: A #GtkTreeModel.
4618 * Sets the model used by @combo_box to be @model. Will unset a previously set
4619 * model (if applicable). If model is %NULL, then it will unset the model.
4621 * Note that this function does not clear the cell renderers, you have to
4622 * call gtk_combo_box_cell_layout_clear() yourself if you need to set up
4623 * different cell renderers for the new model.
4628 gtk_combo_box_set_model (GtkComboBox *combo_box,
4629 GtkTreeModel *model)
4631 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4635 gtk_combo_box_unset_model (combo_box);
4639 g_return_if_fail (GTK_IS_TREE_MODEL (model));
4641 if (model == combo_box->priv->model)
4644 if (combo_box->priv->model)
4645 gtk_combo_box_unset_model (combo_box);
4647 combo_box->priv->model = model;
4648 g_object_ref (combo_box->priv->model);
4650 combo_box->priv->inserted_id =
4651 g_signal_connect (combo_box->priv->model, "row_inserted",
4652 G_CALLBACK (gtk_combo_box_model_row_inserted),
4654 combo_box->priv->deleted_id =
4655 g_signal_connect (combo_box->priv->model, "row_deleted",
4656 G_CALLBACK (gtk_combo_box_model_row_deleted),
4658 combo_box->priv->reordered_id =
4659 g_signal_connect (combo_box->priv->model, "rows_reordered",
4660 G_CALLBACK (gtk_combo_box_model_rows_reordered),
4662 combo_box->priv->changed_id =
4663 g_signal_connect (combo_box->priv->model, "row_changed",
4664 G_CALLBACK (gtk_combo_box_model_row_changed),
4667 if (combo_box->priv->tree_view)
4670 gtk_tree_view_set_model (GTK_TREE_VIEW (combo_box->priv->tree_view),
4671 combo_box->priv->model);
4672 gtk_combo_box_list_popup_resize (combo_box);
4677 if (combo_box->priv->popup_widget)
4678 gtk_combo_box_menu_fill (combo_box);
4682 if (combo_box->priv->cell_view)
4683 gtk_cell_view_set_model (GTK_CELL_VIEW (combo_box->priv->cell_view),
4684 combo_box->priv->model);
4688 * gtk_combo_box_get_model
4689 * @combo_box: A #GtkComboBox.
4691 * Returns the #GtkTreeModel which is acting as data source for @combo_box.
4693 * Return value: A #GtkTreeModel which was passed during construction.
4698 gtk_combo_box_get_model (GtkComboBox *combo_box)
4700 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
4702 return combo_box->priv->model;
4706 /* convenience API for simple text combos */
4709 * gtk_combo_box_new_text:
4711 * Convenience function which constructs a new text combo box, which is a
4712 * #GtkComboBox just displaying strings. If you use this function to create
4713 * a text combo box, you should only manipulate its data source with the
4714 * following convenience functions: gtk_combo_box_append_text(),
4715 * gtk_combo_box_insert_text(), gtk_combo_box_prepend_text() and
4716 * gtk_combo_box_remove_text().
4718 * Return value: A new text combo box.
4723 gtk_combo_box_new_text (void)
4725 GtkWidget *combo_box;
4726 GtkCellRenderer *cell;
4727 GtkListStore *store;
4729 store = gtk_list_store_new (1, G_TYPE_STRING);
4730 combo_box = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));
4731 g_object_unref (store);
4733 cell = gtk_cell_renderer_text_new ();
4734 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), cell, TRUE);
4735 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), cell,
4743 * gtk_combo_box_append_text:
4744 * @combo_box: A #GtkComboBox constructed using gtk_combo_box_new_text().
4747 * Appends @string to the list of strings stored in @combo_box. Note that
4748 * you can only use this function with combo boxes constructed with
4749 * gtk_combo_box_new_text().
4754 gtk_combo_box_append_text (GtkComboBox *combo_box,
4758 GtkListStore *store;
4760 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4761 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
4762 g_return_if_fail (text != NULL);
4764 store = GTK_LIST_STORE (combo_box->priv->model);
4766 gtk_list_store_append (store, &iter);
4767 gtk_list_store_set (store, &iter, 0, text, -1);
4771 * gtk_combo_box_insert_text:
4772 * @combo_box: A #GtkComboBox constructed using gtk_combo_box_new_text().
4773 * @position: An index to insert @text.
4776 * Inserts @string at @position in the list of strings stored in @combo_box.
4777 * Note that you can only use this function with combo boxes constructed
4778 * with gtk_combo_box_new_text().
4783 gtk_combo_box_insert_text (GtkComboBox *combo_box,
4788 GtkListStore *store;
4790 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4791 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
4792 g_return_if_fail (position >= 0);
4793 g_return_if_fail (text != NULL);
4795 store = GTK_LIST_STORE (combo_box->priv->model);
4797 gtk_list_store_insert (store, &iter, position);
4798 gtk_list_store_set (store, &iter, 0, text, -1);
4802 * gtk_combo_box_prepend_text:
4803 * @combo_box: A #GtkComboBox constructed with gtk_combo_box_new_text().
4806 * Prepends @string to the list of strings stored in @combo_box. Note that
4807 * you can only use this function with combo boxes constructed with
4808 * gtk_combo_box_new_text().
4813 gtk_combo_box_prepend_text (GtkComboBox *combo_box,
4817 GtkListStore *store;
4819 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4820 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
4821 g_return_if_fail (text != NULL);
4823 store = GTK_LIST_STORE (combo_box->priv->model);
4825 gtk_list_store_prepend (store, &iter);
4826 gtk_list_store_set (store, &iter, 0, text, -1);
4830 * gtk_combo_box_remove_text:
4831 * @combo_box: A #GtkComboBox constructed with gtk_combo_box_new_text().
4832 * @position: Index of the item to remove.
4834 * Removes the string at @position from @combo_box. Note that you can only use
4835 * this function with combo boxes constructed with gtk_combo_box_new_text().
4840 gtk_combo_box_remove_text (GtkComboBox *combo_box,
4844 GtkListStore *store;
4846 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4847 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
4848 g_return_if_fail (position >= 0);
4850 store = GTK_LIST_STORE (combo_box->priv->model);
4852 if (gtk_tree_model_iter_nth_child (combo_box->priv->model, &iter,
4854 gtk_list_store_remove (store, &iter);
4858 * gtk_combo_box_get_active_text:
4859 * @combo_box: A #GtkComboBox constructed with gtk_combo_box_new_text().
4861 * Returns the currently active string in @combo_box or %NULL if none
4862 * is selected. Note that you can only use this function with combo
4863 * boxes constructed with gtk_combo_box_new_text() and with
4864 * #GtkComboBoxEntry<!-- -->s.
4866 * Returns: a newly allocated string containing the currently active text.
4871 gtk_combo_box_get_active_text (GtkComboBox *combo_box)
4873 GtkComboBoxClass *class;
4875 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
4877 class = GTK_COMBO_BOX_GET_CLASS (combo_box);
4879 if (class->get_active_text)
4880 return (* class->get_active_text) (combo_box);
4886 gtk_combo_box_real_get_active_text (GtkComboBox *combo_box)
4891 g_return_val_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model), NULL);
4893 if (gtk_combo_box_get_active_iter (combo_box, &iter))
4894 gtk_tree_model_get (combo_box->priv->model, &iter,
4901 gtk_combo_box_mnemonic_activate (GtkWidget *widget,
4902 gboolean group_cycling)
4904 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
4906 gtk_widget_grab_focus (combo_box->priv->button);
4912 gtk_combo_box_grab_focus (GtkWidget *widget)
4914 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
4916 gtk_widget_grab_focus (combo_box->priv->button);
4920 gtk_combo_box_destroy (GtkObject *object)
4922 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
4924 if (combo_box->priv->popup_idle_id > 0)
4926 g_source_remove (combo_box->priv->popup_idle_id);
4927 combo_box->priv->popup_idle_id = 0;
4930 gtk_combo_box_popdown (combo_box);
4932 if (combo_box->priv->row_separator_destroy)
4933 (* combo_box->priv->row_separator_destroy) (combo_box->priv->row_separator_data);
4935 combo_box->priv->row_separator_func = NULL;
4936 combo_box->priv->row_separator_data = NULL;
4937 combo_box->priv->row_separator_destroy = NULL;
4939 combo_box->priv->destroying = 1;
4941 GTK_OBJECT_CLASS (parent_class)->destroy (object);
4942 combo_box->priv->cell_view = NULL;
4944 combo_box->priv->destroying = 0;
4948 gtk_combo_box_finalize (GObject *object)
4950 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
4953 if (GTK_IS_MENU (combo_box->priv->popup_widget))
4955 gtk_combo_box_menu_destroy (combo_box);
4956 gtk_menu_detach (GTK_MENU (combo_box->priv->popup_widget));
4957 combo_box->priv->popup_widget = NULL;
4960 if (GTK_IS_TREE_VIEW (combo_box->priv->tree_view))
4961 gtk_combo_box_list_destroy (combo_box);
4963 if (combo_box->priv->popup_window)
4964 gtk_widget_destroy (combo_box->priv->popup_window);
4966 gtk_combo_box_unset_model (combo_box);
4968 for (i = combo_box->priv->cells; i; i = i->next)
4970 ComboCellInfo *info = (ComboCellInfo *)i->data;
4971 GSList *list = info->attributes;
4974 info->destroy (info->func_data);
4976 while (list && list->next)
4978 g_free (list->data);
4979 list = list->next->next;
4981 g_slist_free (info->attributes);
4983 g_object_unref (info->cell);
4986 g_slist_free (combo_box->priv->cells);
4988 G_OBJECT_CLASS (parent_class)->finalize (object);
4992 gtk_cell_editable_key_press (GtkWidget *widget,
4996 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
4998 if (event->keyval == GDK_Escape)
5000 combo_box->priv->editing_canceled = TRUE;
5002 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (combo_box));
5003 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (combo_box));
5007 else if (event->keyval == GDK_Return)
5009 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (combo_box));
5010 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (combo_box));
5019 popdown_idle (gpointer data)
5021 GtkComboBox *combo_box;
5023 GDK_THREADS_ENTER ();
5025 combo_box = GTK_COMBO_BOX (data);
5027 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (combo_box));
5028 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (combo_box));
5030 g_object_unref (combo_box);
5032 GDK_THREADS_LEAVE ();
5038 popdown_handler (GtkWidget *widget,
5041 g_idle_add (popdown_idle, g_object_ref (data));
5045 popup_idle (gpointer data)
5047 GtkComboBox *combo_box;
5049 GDK_THREADS_ENTER ();
5051 combo_box = GTK_COMBO_BOX (data);
5053 if (GTK_IS_MENU (combo_box->priv->popup_widget) &&
5054 combo_box->priv->cell_view)
5055 g_signal_connect_object (combo_box->priv->popup_widget,
5056 "unmap", G_CALLBACK (popdown_handler),
5059 /* we unset this if a menu item is activated */
5060 combo_box->priv->editing_canceled = TRUE;
5061 gtk_combo_box_popup (combo_box);
5063 combo_box->priv->popup_idle_id = 0;
5065 GDK_THREADS_LEAVE ();
5071 gtk_combo_box_start_editing (GtkCellEditable *cell_editable,
5074 GtkComboBox *combo_box = GTK_COMBO_BOX (cell_editable);
5076 combo_box->priv->is_cell_renderer = TRUE;
5078 if (combo_box->priv->cell_view)
5080 g_signal_connect_object (combo_box->priv->button, "key_press_event",
5081 G_CALLBACK (gtk_cell_editable_key_press),
5084 gtk_widget_grab_focus (combo_box->priv->button);
5088 g_signal_connect_object (GTK_BIN (combo_box)->child, "key_press_event",
5089 G_CALLBACK (gtk_cell_editable_key_press),
5092 gtk_widget_grab_focus (GTK_WIDGET (GTK_BIN (combo_box)->child));
5093 GTK_WIDGET_UNSET_FLAGS (combo_box->priv->button, GTK_CAN_FOCUS);
5096 /* we do the immediate popup only for the optionmenu-like
5099 if (combo_box->priv->is_cell_renderer &&
5100 combo_box->priv->cell_view && !combo_box->priv->tree_view)
5101 combo_box->priv->popup_idle_id = g_idle_add (popup_idle, combo_box);
5106 * gtk_combo_box_get_add_tearoffs:
5107 * @combo_box: a #GtkComboBox
5109 * Gets the current value of the :add-tearoffs property.
5111 * Return value: the current value of the :add-tearoffs property.
5114 gtk_combo_box_get_add_tearoffs (GtkComboBox *combo_box)
5116 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE);
5118 return combo_box->priv->add_tearoffs;
5122 * gtk_combo_box_set_add_tearoffs:
5123 * @combo_box: a #GtkComboBox
5124 * @add_tearoffs: %TRUE to add tearoff menu items
5126 * Sets whether the popup menu should have a tearoff
5132 gtk_combo_box_set_add_tearoffs (GtkComboBox *combo_box,
5133 gboolean add_tearoffs)
5135 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5137 add_tearoffs = add_tearoffs != FALSE;
5139 if (combo_box->priv->add_tearoffs != add_tearoffs)
5141 combo_box->priv->add_tearoffs = add_tearoffs;
5142 gtk_combo_box_check_appearance (combo_box);
5143 gtk_combo_box_relayout (combo_box);
5144 g_object_notify (G_OBJECT (combo_box), "add-tearoffs");
5149 * gtk_combo_box_get_title:
5150 * @combo_box: a #GtkComboBox
5152 * Gets the current title of the menu in tearoff mode. See
5153 * gtk_combo_box_set_add_tearoffs().
5155 * Returns: the menu's title in tearoff mode. This is an internal copy of the
5156 * string which must not be freed.
5160 G_CONST_RETURN gchar*
5161 gtk_combo_box_get_title (GtkComboBox *combo_box)
5163 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
5165 return combo_box->priv->tearoff_title;
5169 gtk_combo_box_update_title (GtkComboBox *combo_box)
5171 gtk_combo_box_check_appearance (combo_box);
5173 if (combo_box->priv->popup_widget &&
5174 GTK_IS_MENU (combo_box->priv->popup_widget))
5175 gtk_menu_set_title (GTK_MENU (combo_box->priv->popup_widget),
5176 combo_box->priv->tearoff_title);
5180 * gtk_combo_box_set_title:
5181 * @combo_box: a #GtkComboBox
5182 * @title: a title for the menu in tearoff mode.
5184 * Sets the menu's title in tearoff mode.
5189 gtk_combo_box_set_title (GtkComboBox *combo_box,
5192 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5194 if (strcmp (title ? title : "",
5195 combo_box->priv->tearoff_title ? combo_box->priv->tearoff_title : "") != 0)
5197 g_free (combo_box->priv->tearoff_title);
5198 combo_box->priv->tearoff_title = g_strdup (title);
5200 gtk_combo_box_update_title (combo_box);
5202 g_object_notify (G_OBJECT (combo_box), "tearoff-title");
5207 _gtk_combo_box_editing_canceled (GtkComboBox *combo_box)
5209 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), TRUE);
5211 return combo_box->priv->editing_canceled;
5215 * gtk_combo_box_get_popup_accessible:
5216 * @combo_box: a #GtkComboBox
5218 * Gets the accessible object corresponding to the combo box's popup.
5220 * This function is mostly intended for use by accessibility technologies;
5221 * applications should have little use for it.
5223 * Returns: the accessible object corresponding to the combo box's popup.
5228 gtk_combo_box_get_popup_accessible (GtkComboBox *combo_box)
5232 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
5234 if (combo_box->priv->popup_widget)
5236 atk_obj = gtk_widget_get_accessible (combo_box->priv->popup_widget);
5244 * gtk_combo_box_get_row_separator_func:
5245 * @combo_box: a #GtkComboBox
5247 * Returns the current row separator function.
5249 * Return value: the current row separator function.
5253 GtkTreeViewRowSeparatorFunc
5254 gtk_combo_box_get_row_separator_func (GtkComboBox *combo_box)
5256 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
5258 return combo_box->priv->row_separator_func;
5262 * gtk_combo_box_set_row_separator_func:
5263 * @combo_box: a #GtkComboBox
5264 * @func: a #GtkTreeViewRowSeparatorFunc
5265 * @data: user data to pass to @func, or %NULL
5266 * @destroy: destroy notifier for @data, or %NULL
5268 * Sets the row separator function, which is used to determine
5269 * whether a row should be drawn as a separator. If the row separator
5270 * function is %NULL, no separators are drawn. This is the default value.
5275 gtk_combo_box_set_row_separator_func (GtkComboBox *combo_box,
5276 GtkTreeViewRowSeparatorFunc func,
5278 GtkDestroyNotify destroy)
5280 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5282 if (combo_box->priv->row_separator_destroy)
5283 (* combo_box->priv->row_separator_destroy) (combo_box->priv->row_separator_data);
5285 combo_box->priv->row_separator_func = func;
5286 combo_box->priv->row_separator_data = data;
5287 combo_box->priv->row_separator_destroy = destroy;
5289 if (combo_box->priv->tree_view)
5290 gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (combo_box->priv->tree_view),
5293 gtk_combo_box_relayout (combo_box);
5295 gtk_widget_queue_draw (GTK_WIDGET (combo_box));
5300 * gtk_combo_box_set_focus_on_click:
5301 * @combo: a #GtkComboBox
5302 * @focus_on_click: whether the combo box grabs focus when clicked
5305 * Sets whether the combo box will grab focus when it is clicked with
5306 * the mouse. Making mouse clicks not grab focus is useful in places
5307 * like toolbars where you don't want the keyboard focus removed from
5308 * the main area of the application.
5313 gtk_combo_box_set_focus_on_click (GtkComboBox *combo_box,
5314 gboolean focus_on_click)
5316 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5318 focus_on_click = focus_on_click != FALSE;
5320 if (combo_box->priv->focus_on_click != focus_on_click)
5322 combo_box->priv->focus_on_click = focus_on_click;
5324 if (combo_box->priv->button)
5325 gtk_button_set_focus_on_click (GTK_BUTTON (combo_box->priv->button),
5328 g_object_notify (G_OBJECT (combo_box), "focus-on-click");
5333 * gtk_combo_box_get_focus_on_click:
5334 * @combo: a #GtkComboBox
5336 * Returns whether the combo box grabs focus when it is clicked
5337 * with the mouse. See gtk_combo_box_set_focus_on_click().
5339 * Return value: %TRUE if the combo box grabs focus when it is
5340 * clicked with the mouse.
5345 gtk_combo_box_get_focus_on_click (GtkComboBox *combo_box)
5347 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE);
5349 return combo_box->priv->focus_on_click;
5353 #define __GTK_COMBO_BOX_C__
5354 #include "gtkaliasdef.c"