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"
55 /* WELCOME, to THE house of evil code */
57 typedef struct _ComboCellInfo ComboCellInfo;
60 GtkCellRenderer *cell;
63 GtkCellLayoutDataFunc func;
65 GDestroyNotify destroy;
72 struct _GtkComboBoxPrivate
80 GtkShadowType shadow_type;
82 gint active; /* Only temporary */
83 GtkTreeRowReference *active_row;
86 GtkTreeViewColumn *column;
89 GtkWidget *cell_view_frame;
96 GtkWidget *popup_widget;
97 GtkWidget *popup_window;
98 GtkWidget *scrolled_window;
105 guint activate_button;
106 guint32 activate_time;
108 guint resize_idle_id;
115 guint popup_in_progress : 1;
116 guint popup_shown : 1;
117 guint add_tearoffs : 1;
119 guint is_cell_renderer : 1;
120 guint editing_canceled : 1;
121 guint auto_scroll : 1;
122 guint focus_on_click : 1;
123 guint button_sensitivity : 2;
125 GtkTreeViewRowSeparatorFunc row_separator_func;
126 gpointer row_separator_data;
127 GDestroyNotify row_separator_destroy;
129 GdkDevice *grab_pointer;
130 GdkDevice *grab_keyboard;
132 gchar *tearoff_title;
135 /* While debugging this evil code, I have learned that
136 * there are actually 4 modes to this widget, which can
137 * be characterized as follows
139 * 1) menu mode, no child added
142 * cell_view -> GtkCellView, regular child
143 * cell_view_frame -> NULL
144 * button -> GtkToggleButton set_parent to combo
145 * arrow -> GtkArrow set_parent to button
146 * separator -> GtkVSepator set_parent to button
147 * popup_widget -> GtkMenu
148 * popup_window -> NULL
149 * scrolled_window -> NULL
151 * 2) menu mode, child added
155 * cell_view_frame -> NULL
156 * button -> GtkToggleButton set_parent to combo
157 * arrow -> GtkArrow, child of button
159 * popup_widget -> GtkMenu
160 * popup_window -> NULL
161 * scrolled_window -> NULL
163 * 3) list mode, no child added
165 * tree_view -> GtkTreeView, child of scrolled_window
166 * cell_view -> GtkCellView, regular child
167 * cell_view_frame -> GtkFrame, set parent to combo
168 * button -> GtkToggleButton, set_parent to combo
169 * arrow -> GtkArrow, child of button
171 * popup_widget -> tree_view
172 * popup_window -> GtkWindow
173 * scrolled_window -> GtkScrolledWindow, child of popup_window
175 * 4) list mode, child added
177 * tree_view -> GtkTreeView, child of scrolled_window
179 * cell_view_frame -> NULL
180 * button -> GtkToggleButton, set_parent to combo
181 * arrow -> GtkArrow, child of button
183 * popup_widget -> tree_view
184 * popup_window -> GtkWindow
185 * scrolled_window -> GtkScrolledWindow, child of popup_window
201 PROP_ROW_SPAN_COLUMN,
202 PROP_COLUMN_SPAN_COLUMN,
209 PROP_BUTTON_SENSITIVITY,
210 PROP_EDITING_CANCELED
213 static guint combo_box_signals[LAST_SIGNAL] = {0,};
215 #define BONUS_PADDING 4
216 #define SCROLL_TIME 100
220 static void gtk_combo_box_cell_layout_init (GtkCellLayoutIface *iface);
221 static void gtk_combo_box_cell_editable_init (GtkCellEditableIface *iface);
222 static void gtk_combo_box_dispose (GObject *object);
223 static void gtk_combo_box_finalize (GObject *object);
224 static void gtk_combo_box_destroy (GtkWidget *widget);
226 static void gtk_combo_box_set_property (GObject *object,
230 static void gtk_combo_box_get_property (GObject *object,
235 static void gtk_combo_box_state_changed (GtkWidget *widget,
236 GtkStateType previous);
237 static void gtk_combo_box_grab_focus (GtkWidget *widget);
238 static void gtk_combo_box_style_set (GtkWidget *widget,
240 static void gtk_combo_box_button_toggled (GtkWidget *widget,
242 static void gtk_combo_box_button_state_changed (GtkWidget *widget,
243 GtkStateType previous,
245 static void gtk_combo_box_add (GtkContainer *container,
247 static void gtk_combo_box_remove (GtkContainer *container,
250 static ComboCellInfo *gtk_combo_box_get_cell_info (GtkComboBox *combo_box,
251 GtkCellRenderer *cell);
253 static void gtk_combo_box_menu_show (GtkWidget *menu,
255 static void gtk_combo_box_menu_hide (GtkWidget *menu,
258 static void gtk_combo_box_set_popup_widget (GtkComboBox *combo_box,
260 static void gtk_combo_box_menu_position_below (GtkMenu *menu,
265 static void gtk_combo_box_menu_position_over (GtkMenu *menu,
270 static void gtk_combo_box_menu_position (GtkMenu *menu,
276 static void gtk_combo_box_update_requested_width(GtkComboBox *combo_box,
278 static void gtk_combo_box_remeasure (GtkComboBox *combo_box);
280 static void gtk_combo_box_unset_model (GtkComboBox *combo_box);
282 static void gtk_combo_box_size_allocate (GtkWidget *widget,
283 GtkAllocation *allocation);
284 static void gtk_combo_box_forall (GtkContainer *container,
285 gboolean include_internals,
286 GtkCallback callback,
287 gpointer callback_data);
288 static gboolean gtk_combo_box_draw (GtkWidget *widget,
290 static gboolean gtk_combo_box_scroll_event (GtkWidget *widget,
291 GdkEventScroll *event);
292 static void gtk_combo_box_set_active_internal (GtkComboBox *combo_box,
295 static void gtk_combo_box_check_appearance (GtkComboBox *combo_box);
296 static gchar * gtk_combo_box_real_get_active_text (GtkComboBox *combo_box);
297 static void gtk_combo_box_real_move_active (GtkComboBox *combo_box,
298 GtkScrollType scroll);
299 static void gtk_combo_box_real_popup (GtkComboBox *combo_box);
300 static gboolean gtk_combo_box_real_popdown (GtkComboBox *combo_box);
302 /* listening to the model */
303 static void gtk_combo_box_model_row_inserted (GtkTreeModel *model,
307 static void gtk_combo_box_model_row_deleted (GtkTreeModel *model,
310 static void gtk_combo_box_model_rows_reordered (GtkTreeModel *model,
315 static void gtk_combo_box_model_row_changed (GtkTreeModel *model,
319 static void gtk_combo_box_model_row_expanded (GtkTreeModel *model,
325 static void gtk_combo_box_list_position (GtkComboBox *combo_box,
330 static void gtk_combo_box_list_setup (GtkComboBox *combo_box);
331 static void gtk_combo_box_list_destroy (GtkComboBox *combo_box);
333 static gboolean gtk_combo_box_list_button_released (GtkWidget *widget,
334 GdkEventButton *event,
336 static gboolean gtk_combo_box_list_key_press (GtkWidget *widget,
339 static gboolean gtk_combo_box_list_enter_notify (GtkWidget *widget,
340 GdkEventCrossing *event,
342 static void gtk_combo_box_list_auto_scroll (GtkComboBox *combo,
345 static gboolean gtk_combo_box_list_scroll_timeout (GtkComboBox *combo);
346 static gboolean gtk_combo_box_list_button_pressed (GtkWidget *widget,
347 GdkEventButton *event,
350 static gboolean gtk_combo_box_list_select_func (GtkTreeSelection *selection,
353 gboolean path_currently_selected,
356 static void gtk_combo_box_list_row_changed (GtkTreeModel *model,
360 static void gtk_combo_box_list_popup_resize (GtkComboBox *combo_box);
363 static void gtk_combo_box_menu_setup (GtkComboBox *combo_box,
364 gboolean add_children);
365 static void gtk_combo_box_menu_fill (GtkComboBox *combo_box);
366 static void gtk_combo_box_menu_fill_level (GtkComboBox *combo_box,
369 static void gtk_combo_box_update_title (GtkComboBox *combo_box);
370 static void gtk_combo_box_menu_destroy (GtkComboBox *combo_box);
372 static void gtk_combo_box_relayout_item (GtkComboBox *combo_box,
376 static void gtk_combo_box_relayout (GtkComboBox *combo_box);
378 static gboolean gtk_combo_box_menu_button_press (GtkWidget *widget,
379 GdkEventButton *event,
381 static void gtk_combo_box_menu_item_activate (GtkWidget *item,
384 static void gtk_combo_box_update_sensitivity (GtkComboBox *combo_box);
385 static void gtk_combo_box_menu_row_inserted (GtkTreeModel *model,
389 static void gtk_combo_box_menu_row_deleted (GtkTreeModel *model,
392 static void gtk_combo_box_menu_rows_reordered (GtkTreeModel *model,
397 static void gtk_combo_box_menu_row_changed (GtkTreeModel *model,
401 static gboolean gtk_combo_box_menu_key_press (GtkWidget *widget,
404 static void gtk_combo_box_menu_popup (GtkComboBox *combo_box,
406 guint32 activate_time);
407 static GtkWidget *gtk_cell_view_menu_item_new (GtkComboBox *combo_box,
412 static void gtk_combo_box_cell_layout_pack_start (GtkCellLayout *layout,
413 GtkCellRenderer *cell,
415 static void gtk_combo_box_cell_layout_pack_end (GtkCellLayout *layout,
416 GtkCellRenderer *cell,
418 static GList *gtk_combo_box_cell_layout_get_cells (GtkCellLayout *layout);
419 static void gtk_combo_box_cell_layout_clear (GtkCellLayout *layout);
420 static void gtk_combo_box_cell_layout_add_attribute (GtkCellLayout *layout,
421 GtkCellRenderer *cell,
422 const gchar *attribute,
424 static void gtk_combo_box_cell_layout_set_cell_data_func (GtkCellLayout *layout,
425 GtkCellRenderer *cell,
426 GtkCellLayoutDataFunc func,
428 GDestroyNotify destroy);
429 static void gtk_combo_box_cell_layout_clear_attributes (GtkCellLayout *layout,
430 GtkCellRenderer *cell);
431 static void gtk_combo_box_cell_layout_reorder (GtkCellLayout *layout,
432 GtkCellRenderer *cell,
434 static gboolean gtk_combo_box_mnemonic_activate (GtkWidget *widget,
435 gboolean group_cycling);
437 static void gtk_combo_box_sync_cells (GtkComboBox *combo_box,
438 GtkCellLayout *cell_layout);
439 static void combo_cell_data_func (GtkCellLayout *cell_layout,
440 GtkCellRenderer *cell,
441 GtkTreeModel *tree_model,
444 static void gtk_combo_box_child_show (GtkWidget *widget,
445 GtkComboBox *combo_box);
446 static void gtk_combo_box_child_hide (GtkWidget *widget,
447 GtkComboBox *combo_box);
449 /* GtkBuildable method implementation */
450 static GtkBuildableIface *parent_buildable_iface;
452 static void gtk_combo_box_buildable_init (GtkBuildableIface *iface);
453 static gboolean gtk_combo_box_buildable_custom_tag_start (GtkBuildable *buildable,
456 const gchar *tagname,
457 GMarkupParser *parser,
459 static void gtk_combo_box_buildable_custom_tag_end (GtkBuildable *buildable,
462 const gchar *tagname,
465 /* GtkCellEditable method implementations */
466 static void gtk_combo_box_start_editing (GtkCellEditable *cell_editable,
469 static void gtk_combo_box_get_preferred_width (GtkWidget *widget,
472 static void gtk_combo_box_get_preferred_height (GtkWidget *widget,
475 static void gtk_combo_box_get_preferred_width_for_height (GtkWidget *widget,
479 static void gtk_combo_box_get_preferred_height_for_width (GtkWidget *widget,
485 G_DEFINE_TYPE_WITH_CODE (GtkComboBox, gtk_combo_box, GTK_TYPE_BIN,
486 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
487 gtk_combo_box_cell_layout_init)
488 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
489 gtk_combo_box_cell_editable_init)
490 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
491 gtk_combo_box_buildable_init))
496 gtk_combo_box_class_init (GtkComboBoxClass *klass)
498 GObjectClass *object_class;
499 GtkContainerClass *container_class;
500 GtkWidgetClass *widget_class;
501 GtkBindingSet *binding_set;
503 klass->get_active_text = gtk_combo_box_real_get_active_text;
505 container_class = (GtkContainerClass *)klass;
506 container_class->forall = gtk_combo_box_forall;
507 container_class->add = gtk_combo_box_add;
508 container_class->remove = gtk_combo_box_remove;
510 widget_class = (GtkWidgetClass *)klass;
511 widget_class->size_allocate = gtk_combo_box_size_allocate;
512 widget_class->draw = gtk_combo_box_draw;
513 widget_class->scroll_event = gtk_combo_box_scroll_event;
514 widget_class->mnemonic_activate = gtk_combo_box_mnemonic_activate;
515 widget_class->grab_focus = gtk_combo_box_grab_focus;
516 widget_class->style_set = gtk_combo_box_style_set;
517 widget_class->state_changed = gtk_combo_box_state_changed;
518 widget_class->get_preferred_width = gtk_combo_box_get_preferred_width;
519 widget_class->get_preferred_height = gtk_combo_box_get_preferred_height;
520 widget_class->get_preferred_height_for_width = gtk_combo_box_get_preferred_height_for_width;
521 widget_class->get_preferred_width_for_height = gtk_combo_box_get_preferred_width_for_height;
522 widget_class->destroy = gtk_combo_box_destroy;
524 object_class = (GObjectClass *)klass;
525 object_class->dispose = gtk_combo_box_dispose;
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;
532 * GtkComboBox::changed:
533 * @widget: the object which received the signal
535 * The changed signal is emitted when the active
536 * item is changed. The can be due to the user selecting
537 * a different item from the list, or due to a
538 * call to gtk_combo_box_set_active_iter().
539 * It will also be emitted while typing into a GtkComboBoxEntry,
540 * as well as when selecting an item from the GtkComboBoxEntry's list.
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 * GtkComboBox::move-active:
554 * @widget: the object that received the signal
555 * @scroll_type: a #GtkScrollType
557 * The ::move-active signal is a
558 * <link linkend="keybinding-signals">keybinding signal</link>
559 * which gets emitted to move the active selection.
563 combo_box_signals[MOVE_ACTIVE] =
564 g_signal_new_class_handler (I_("move-active"),
565 G_OBJECT_CLASS_TYPE (klass),
566 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
567 G_CALLBACK (gtk_combo_box_real_move_active),
569 g_cclosure_marshal_VOID__ENUM,
571 GTK_TYPE_SCROLL_TYPE);
574 * GtkComboBox::popup:
575 * @widget: the object that received the signal
577 * The ::popup signal is a
578 * <link linkend="keybinding-signals">keybinding signal</link>
579 * which gets emitted to popup the combo box list.
581 * The default binding for this signal is Alt+Down.
585 combo_box_signals[POPUP] =
586 g_signal_new_class_handler (I_("popup"),
587 G_OBJECT_CLASS_TYPE (klass),
588 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
589 G_CALLBACK (gtk_combo_box_real_popup),
591 g_cclosure_marshal_VOID__VOID,
594 * GtkComboBox::popdown:
595 * @button: the object which received the signal
597 * The ::popdown signal is a
598 * <link linkend="keybinding-signals">keybinding signal</link>
599 * which gets emitted to popdown the combo box list.
601 * The default bindings for this signal are Alt+Up and Escape.
605 combo_box_signals[POPDOWN] =
606 g_signal_new_class_handler (I_("popdown"),
607 G_OBJECT_CLASS_TYPE (klass),
608 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
609 G_CALLBACK (gtk_combo_box_real_popdown),
611 _gtk_marshal_BOOLEAN__VOID,
615 binding_set = gtk_binding_set_by_class (widget_class);
617 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Down, GDK_MOD1_MASK,
619 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Down, GDK_MOD1_MASK,
622 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Up, GDK_MOD1_MASK,
624 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Up, GDK_MOD1_MASK,
626 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Escape, 0,
629 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Up, 0,
631 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_UP);
632 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Up, 0,
634 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_UP);
635 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Page_Up, 0,
637 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_PAGE_UP);
638 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Page_Up, 0,
640 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_PAGE_UP);
641 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Home, 0,
643 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_START);
644 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Home, 0,
646 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_START);
648 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Down, 0,
650 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_DOWN);
651 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Down, 0,
653 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_DOWN);
654 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Page_Down, 0,
656 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_PAGE_DOWN);
657 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Page_Down, 0,
659 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_PAGE_DOWN);
660 gtk_binding_entry_add_signal (binding_set, GDK_KEY_End, 0,
662 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_END);
663 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_End, 0,
665 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_END);
668 g_object_class_override_property (object_class,
669 PROP_EDITING_CANCELED,
675 * The model from which the combo box takes the values shown
680 g_object_class_install_property (object_class,
682 g_param_spec_object ("model",
683 P_("ComboBox model"),
684 P_("The model for the combo box"),
686 GTK_PARAM_READWRITE));
689 * GtkComboBox:wrap-width:
691 * If wrap-width is set to a positive value, the list will be
692 * displayed in multiple columns, the number of columns is
693 * determined by wrap-width.
697 g_object_class_install_property (object_class,
699 g_param_spec_int ("wrap-width",
701 P_("Wrap width for laying out the items in a grid"),
705 GTK_PARAM_READWRITE));
709 * GtkComboBox:row-span-column:
711 * If this is set to a non-negative value, it must be the index of a column
712 * of type %G_TYPE_INT in the model.
714 * The values of that column are used to determine how many rows a value in
715 * the list will span. Therefore, the values in the model column pointed to
716 * by this property must be greater than zero and not larger than wrap-width.
720 g_object_class_install_property (object_class,
721 PROP_ROW_SPAN_COLUMN,
722 g_param_spec_int ("row-span-column",
723 P_("Row span column"),
724 P_("TreeModel column containing the row span values"),
728 GTK_PARAM_READWRITE));
732 * GtkComboBox:column-span-column:
734 * If this is set to a non-negative value, it must be the index of a column
735 * of type %G_TYPE_INT in the model.
737 * The values of that column are used to determine how many columns a value
738 * in the list will span.
742 g_object_class_install_property (object_class,
743 PROP_COLUMN_SPAN_COLUMN,
744 g_param_spec_int ("column-span-column",
745 P_("Column span column"),
746 P_("TreeModel column containing the column span values"),
750 GTK_PARAM_READWRITE));
754 * GtkComboBox:active:
756 * The item which is currently active. If the model is a non-flat treemodel,
757 * and the active item is not an immediate child of the root of the tree,
758 * this property has the value
759 * <literal>gtk_tree_path_get_indices (path)[0]</literal>,
760 * where <literal>path</literal> is the #GtkTreePath of the active item.
764 g_object_class_install_property (object_class,
766 g_param_spec_int ("active",
768 P_("The item which is currently active"),
772 GTK_PARAM_READWRITE));
775 * GtkComboBox:add-tearoffs:
777 * The add-tearoffs property controls whether generated menus
778 * have tearoff menu items.
780 * Note that this only affects menu style combo boxes.
784 g_object_class_install_property (object_class,
786 g_param_spec_boolean ("add-tearoffs",
787 P_("Add tearoffs to menus"),
788 P_("Whether dropdowns should have a tearoff menu item"),
790 GTK_PARAM_READWRITE));
793 * GtkComboBox:has-frame:
795 * The has-frame property controls whether a frame
796 * is drawn around the entry.
800 g_object_class_install_property (object_class,
802 g_param_spec_boolean ("has-frame",
804 P_("Whether the combo box draws a frame around the child"),
806 GTK_PARAM_READWRITE));
808 g_object_class_install_property (object_class,
810 g_param_spec_boolean ("focus-on-click",
811 P_("Focus on click"),
812 P_("Whether the combo box grabs focus when it is clicked with the mouse"),
814 GTK_PARAM_READWRITE));
817 * GtkComboBox:tearoff-title:
819 * A title that may be displayed by the window manager
820 * when the popup is torn-off.
824 g_object_class_install_property (object_class,
826 g_param_spec_string ("tearoff-title",
828 P_("A title that may be displayed by the window manager when the popup is torn-off"),
830 GTK_PARAM_READWRITE));
834 * GtkComboBox:popup-shown:
836 * Whether the combo boxes dropdown is popped up.
837 * Note that this property is mainly useful, because
838 * it allows you to connect to notify::popup-shown.
842 g_object_class_install_property (object_class,
844 g_param_spec_boolean ("popup-shown",
846 P_("Whether the combo's dropdown is shown"),
848 GTK_PARAM_READABLE));
852 * GtkComboBox:button-sensitivity:
854 * Whether the dropdown button is sensitive when
855 * the model is empty.
859 g_object_class_install_property (object_class,
860 PROP_BUTTON_SENSITIVITY,
861 g_param_spec_enum ("button-sensitivity",
862 P_("Button Sensitivity"),
863 P_("Whether the dropdown button is sensitive when the model is empty"),
864 GTK_TYPE_SENSITIVITY_TYPE,
865 GTK_SENSITIVITY_AUTO,
866 GTK_PARAM_READWRITE));
868 gtk_widget_class_install_style_property (widget_class,
869 g_param_spec_boolean ("appears-as-list",
870 P_("Appears as list"),
871 P_("Whether dropdowns should look like lists rather than menus"),
873 GTK_PARAM_READABLE));
876 * GtkComboBox:arrow-size:
878 * Sets the minimum size of the arrow in the combo box. Note
879 * that the arrow size is coupled to the font size, so in case
880 * a larger font is used, the arrow will be larger than set
885 gtk_widget_class_install_style_property (widget_class,
886 g_param_spec_int ("arrow-size",
888 P_("The minimum size of the arrow in the combo box"),
892 GTK_PARAM_READABLE));
895 * GtkComboBox:shadow-type:
897 * Which kind of shadow to draw around the combo box.
901 gtk_widget_class_install_style_property (widget_class,
902 g_param_spec_enum ("shadow-type",
904 P_("Which kind of shadow to draw around the combo box"),
905 GTK_TYPE_SHADOW_TYPE,
907 GTK_PARAM_READABLE));
909 g_type_class_add_private (object_class, sizeof (GtkComboBoxPrivate));
913 gtk_combo_box_buildable_init (GtkBuildableIface *iface)
915 parent_buildable_iface = g_type_interface_peek_parent (iface);
916 iface->add_child = _gtk_cell_layout_buildable_add_child;
917 iface->custom_tag_start = gtk_combo_box_buildable_custom_tag_start;
918 iface->custom_tag_end = gtk_combo_box_buildable_custom_tag_end;
922 gtk_combo_box_cell_layout_init (GtkCellLayoutIface *iface)
924 iface->pack_start = gtk_combo_box_cell_layout_pack_start;
925 iface->pack_end = gtk_combo_box_cell_layout_pack_end;
926 iface->get_cells = gtk_combo_box_cell_layout_get_cells;
927 iface->clear = gtk_combo_box_cell_layout_clear;
928 iface->add_attribute = gtk_combo_box_cell_layout_add_attribute;
929 iface->set_cell_data_func = gtk_combo_box_cell_layout_set_cell_data_func;
930 iface->clear_attributes = gtk_combo_box_cell_layout_clear_attributes;
931 iface->reorder = gtk_combo_box_cell_layout_reorder;
935 gtk_combo_box_cell_editable_init (GtkCellEditableIface *iface)
937 iface->start_editing = gtk_combo_box_start_editing;
941 gtk_combo_box_init (GtkComboBox *combo_box)
943 GtkComboBoxPrivate *priv;
945 combo_box->priv = G_TYPE_INSTANCE_GET_PRIVATE (combo_box,
948 priv = combo_box->priv;
950 priv->cell_view = gtk_cell_view_new ();
951 gtk_widget_set_parent (priv->cell_view, GTK_WIDGET (combo_box));
952 _gtk_bin_set_child (GTK_BIN (combo_box), priv->cell_view);
953 gtk_widget_show (priv->cell_view);
955 priv->minimum_width = 0;
956 priv->natural_width = 0;
958 priv->wrap_width = 0;
961 priv->active_row = NULL;
962 priv->col_column = -1;
963 priv->row_column = -1;
965 priv->popup_shown = FALSE;
966 priv->add_tearoffs = FALSE;
967 priv->has_frame = TRUE;
968 priv->is_cell_renderer = FALSE;
969 priv->editing_canceled = FALSE;
970 priv->auto_scroll = FALSE;
971 priv->focus_on_click = TRUE;
972 priv->button_sensitivity = GTK_SENSITIVITY_AUTO;
974 gtk_combo_box_check_appearance (combo_box);
978 gtk_combo_box_set_property (GObject *object,
983 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
988 gtk_combo_box_set_model (combo_box, g_value_get_object (value));
991 case PROP_WRAP_WIDTH:
992 gtk_combo_box_set_wrap_width (combo_box, g_value_get_int (value));
995 case PROP_ROW_SPAN_COLUMN:
996 gtk_combo_box_set_row_span_column (combo_box, g_value_get_int (value));
999 case PROP_COLUMN_SPAN_COLUMN:
1000 gtk_combo_box_set_column_span_column (combo_box, g_value_get_int (value));
1004 gtk_combo_box_set_active (combo_box, g_value_get_int (value));
1007 case PROP_ADD_TEAROFFS:
1008 gtk_combo_box_set_add_tearoffs (combo_box, g_value_get_boolean (value));
1011 case PROP_HAS_FRAME:
1012 combo_box->priv->has_frame = g_value_get_boolean (value);
1015 case PROP_FOCUS_ON_CLICK:
1016 gtk_combo_box_set_focus_on_click (combo_box,
1017 g_value_get_boolean (value));
1020 case PROP_TEAROFF_TITLE:
1021 gtk_combo_box_set_title (combo_box, g_value_get_string (value));
1024 case PROP_POPUP_SHOWN:
1025 if (g_value_get_boolean (value))
1026 gtk_combo_box_popup (combo_box);
1028 gtk_combo_box_popdown (combo_box);
1031 case PROP_BUTTON_SENSITIVITY:
1032 gtk_combo_box_set_button_sensitivity (combo_box,
1033 g_value_get_enum (value));
1036 case PROP_EDITING_CANCELED:
1037 combo_box->priv->editing_canceled = g_value_get_boolean (value);
1041 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1047 gtk_combo_box_get_property (GObject *object,
1052 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
1053 GtkComboBoxPrivate *priv = combo_box->priv;
1058 g_value_set_object (value, combo_box->priv->model);
1061 case PROP_WRAP_WIDTH:
1062 g_value_set_int (value, combo_box->priv->wrap_width);
1065 case PROP_ROW_SPAN_COLUMN:
1066 g_value_set_int (value, combo_box->priv->row_column);
1069 case PROP_COLUMN_SPAN_COLUMN:
1070 g_value_set_int (value, combo_box->priv->col_column);
1074 g_value_set_int (value, gtk_combo_box_get_active (combo_box));
1077 case PROP_ADD_TEAROFFS:
1078 g_value_set_boolean (value, gtk_combo_box_get_add_tearoffs (combo_box));
1081 case PROP_HAS_FRAME:
1082 g_value_set_boolean (value, combo_box->priv->has_frame);
1085 case PROP_FOCUS_ON_CLICK:
1086 g_value_set_boolean (value, combo_box->priv->focus_on_click);
1089 case PROP_TEAROFF_TITLE:
1090 g_value_set_string (value, gtk_combo_box_get_title (combo_box));
1093 case PROP_POPUP_SHOWN:
1094 g_value_set_boolean (value, combo_box->priv->popup_shown);
1097 case PROP_BUTTON_SENSITIVITY:
1098 g_value_set_enum (value, combo_box->priv->button_sensitivity);
1101 case PROP_EDITING_CANCELED:
1102 g_value_set_boolean (value, priv->editing_canceled);
1106 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1112 gtk_combo_box_state_changed (GtkWidget *widget,
1113 GtkStateType previous)
1115 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
1116 GtkComboBoxPrivate *priv = combo_box->priv;
1118 if (gtk_widget_get_realized (widget))
1120 if (priv->tree_view && priv->cell_view)
1121 gtk_cell_view_set_background_color (GTK_CELL_VIEW (priv->cell_view),
1122 >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
1125 gtk_widget_queue_draw (widget);
1129 gtk_combo_box_button_state_changed (GtkWidget *widget,
1130 GtkStateType previous,
1133 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
1134 GtkComboBoxPrivate *priv = combo_box->priv;
1136 if (gtk_widget_get_realized (widget))
1138 if (!priv->tree_view && priv->cell_view)
1140 if ((gtk_widget_get_state (widget) == GTK_STATE_INSENSITIVE) !=
1141 (gtk_widget_get_state (priv->cell_view) == GTK_STATE_INSENSITIVE))
1142 gtk_widget_set_sensitive (priv->cell_view, gtk_widget_get_sensitive (widget));
1144 gtk_widget_set_state (priv->cell_view,
1145 gtk_widget_get_state (widget));
1149 gtk_widget_queue_draw (widget);
1153 gtk_combo_box_check_appearance (GtkComboBox *combo_box)
1155 GtkComboBoxPrivate *priv = combo_box->priv;
1156 gboolean appears_as_list;
1158 /* if wrap_width > 0, then we are in grid-mode and forced to use
1161 if (priv->wrap_width)
1162 appears_as_list = FALSE;
1164 gtk_widget_style_get (GTK_WIDGET (combo_box),
1165 "appears-as-list", &appears_as_list,
1168 if (appears_as_list)
1170 /* Destroy all the menu mode widgets, if they exist. */
1171 if (GTK_IS_MENU (priv->popup_widget))
1172 gtk_combo_box_menu_destroy (combo_box);
1174 /* Create the list mode widgets, if they don't already exist. */
1175 if (!GTK_IS_TREE_VIEW (priv->tree_view))
1176 gtk_combo_box_list_setup (combo_box);
1180 /* Destroy all the list mode widgets, if they exist. */
1181 if (GTK_IS_TREE_VIEW (priv->tree_view))
1182 gtk_combo_box_list_destroy (combo_box);
1184 /* Create the menu mode widgets, if they don't already exist. */
1185 if (!GTK_IS_MENU (priv->popup_widget))
1186 gtk_combo_box_menu_setup (combo_box, TRUE);
1189 gtk_widget_style_get (GTK_WIDGET (combo_box),
1190 "shadow-type", &priv->shadow_type,
1195 gtk_combo_box_style_set (GtkWidget *widget,
1198 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
1199 GtkComboBoxPrivate *priv = combo_box->priv;
1202 gtk_combo_box_check_appearance (combo_box);
1204 if (priv->tree_view && priv->cell_view)
1205 gtk_cell_view_set_background_color (GTK_CELL_VIEW (priv->cell_view),
1206 >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
1208 child = gtk_bin_get_child (GTK_BIN (combo_box));
1209 if (GTK_IS_ENTRY (child))
1210 g_object_set (child, "shadow-type",
1211 GTK_SHADOW_NONE == priv->shadow_type ?
1212 GTK_SHADOW_IN : GTK_SHADOW_NONE, NULL);
1216 gtk_combo_box_button_toggled (GtkWidget *widget,
1219 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
1221 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
1223 if (!combo_box->priv->popup_in_progress)
1224 gtk_combo_box_popup (combo_box);
1227 gtk_combo_box_popdown (combo_box);
1231 gtk_combo_box_add (GtkContainer *container,
1234 GtkComboBox *combo_box = GTK_COMBO_BOX (container);
1235 GtkComboBoxPrivate *priv = combo_box->priv;
1237 if (priv->cell_view &&
1238 gtk_widget_get_parent (priv->cell_view))
1240 gtk_widget_unparent (priv->cell_view);
1241 _gtk_bin_set_child (GTK_BIN (container), NULL);
1242 gtk_widget_queue_resize (GTK_WIDGET (container));
1245 gtk_widget_set_parent (widget, GTK_WIDGET (container));
1246 _gtk_bin_set_child (GTK_BIN (container), widget);
1248 if (priv->cell_view &&
1249 widget != priv->cell_view)
1251 /* since the cell_view was unparented, it's gone now */
1252 priv->cell_view = NULL;
1254 if (!priv->tree_view && priv->separator)
1256 gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (priv->separator)),
1258 priv->separator = NULL;
1260 gtk_widget_queue_resize (GTK_WIDGET (container));
1262 else if (priv->cell_view_frame)
1264 gtk_widget_unparent (priv->cell_view_frame);
1265 priv->cell_view_frame = NULL;
1272 gtk_combo_box_remove (GtkContainer *container,
1275 GtkComboBox *combo_box = GTK_COMBO_BOX (container);
1276 GtkComboBoxPrivate *priv = combo_box->priv;
1278 gboolean appears_as_list;
1280 if (widget == priv->cell_view)
1281 priv->cell_view = NULL;
1283 gtk_widget_unparent (widget);
1284 _gtk_bin_set_child (GTK_BIN (container), NULL);
1286 if (gtk_widget_in_destruction (combo_box))
1289 gtk_widget_queue_resize (GTK_WIDGET (container));
1291 if (!priv->tree_view)
1292 appears_as_list = FALSE;
1294 appears_as_list = TRUE;
1296 if (appears_as_list)
1297 gtk_combo_box_list_destroy (combo_box);
1298 else if (GTK_IS_MENU (priv->popup_widget))
1300 gtk_combo_box_menu_destroy (combo_box);
1301 gtk_menu_detach (GTK_MENU (priv->popup_widget));
1302 priv->popup_widget = NULL;
1305 if (!priv->cell_view)
1307 priv->cell_view = gtk_cell_view_new ();
1308 gtk_widget_set_parent (priv->cell_view, GTK_WIDGET (container));
1309 _gtk_bin_set_child (GTK_BIN (container), priv->cell_view);
1311 gtk_widget_show (priv->cell_view);
1312 gtk_cell_view_set_model (GTK_CELL_VIEW (priv->cell_view),
1314 gtk_combo_box_sync_cells (combo_box, GTK_CELL_LAYOUT (priv->cell_view));
1318 if (appears_as_list)
1319 gtk_combo_box_list_setup (combo_box);
1321 gtk_combo_box_menu_setup (combo_box, TRUE);
1323 if (gtk_tree_row_reference_valid (priv->active_row))
1325 path = gtk_tree_row_reference_get_path (priv->active_row);
1326 gtk_combo_box_set_active_internal (combo_box, path);
1327 gtk_tree_path_free (path);
1330 gtk_combo_box_set_active_internal (combo_box, NULL);
1333 static ComboCellInfo *
1334 gtk_combo_box_get_cell_info (GtkComboBox *combo_box,
1335 GtkCellRenderer *cell)
1339 for (i = combo_box->priv->cells; i; i = i->next)
1341 ComboCellInfo *info = (ComboCellInfo *)i->data;
1343 if (info && info->cell == cell)
1351 gtk_combo_box_menu_show (GtkWidget *menu,
1354 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
1355 GtkComboBoxPrivate *priv = combo_box->priv;
1357 gtk_combo_box_child_show (menu, user_data);
1359 priv->popup_in_progress = TRUE;
1360 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->button),
1362 priv->popup_in_progress = FALSE;
1366 gtk_combo_box_menu_hide (GtkWidget *menu,
1369 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
1371 gtk_combo_box_child_hide (menu,user_data);
1373 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
1378 gtk_combo_box_detacher (GtkWidget *widget,
1381 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
1382 GtkComboBoxPrivate *priv = combo_box->priv;
1384 g_return_if_fail (priv->popup_widget == (GtkWidget *) menu);
1386 g_signal_handlers_disconnect_by_func (menu->toplevel,
1387 gtk_combo_box_menu_show,
1389 g_signal_handlers_disconnect_by_func (menu->toplevel,
1390 gtk_combo_box_menu_hide,
1393 priv->popup_widget = NULL;
1397 gtk_combo_box_set_popup_widget (GtkComboBox *combo_box,
1400 GtkComboBoxPrivate *priv = combo_box->priv;
1402 if (GTK_IS_MENU (priv->popup_widget))
1404 gtk_menu_detach (GTK_MENU (priv->popup_widget));
1405 priv->popup_widget = NULL;
1407 else if (priv->popup_widget)
1409 gtk_container_remove (GTK_CONTAINER (priv->scrolled_window),
1410 priv->popup_widget);
1411 g_object_unref (priv->popup_widget);
1412 priv->popup_widget = NULL;
1415 if (GTK_IS_MENU (popup))
1417 if (priv->popup_window)
1419 gtk_widget_destroy (priv->popup_window);
1420 priv->popup_window = NULL;
1423 priv->popup_widget = popup;
1426 * Note that we connect to show/hide on the toplevel, not the
1427 * menu itself, since the menu is not shown/hidden when it is
1428 * popped up while torn-off.
1430 g_signal_connect (GTK_MENU (popup)->toplevel, "show",
1431 G_CALLBACK (gtk_combo_box_menu_show), combo_box);
1432 g_signal_connect (GTK_MENU (popup)->toplevel, "hide",
1433 G_CALLBACK (gtk_combo_box_menu_hide), combo_box);
1435 gtk_menu_attach_to_widget (GTK_MENU (popup),
1436 GTK_WIDGET (combo_box),
1437 gtk_combo_box_detacher);
1441 if (!priv->popup_window)
1443 GtkWidget *toplevel;
1445 priv->popup_window = gtk_window_new (GTK_WINDOW_POPUP);
1446 gtk_widget_set_name (priv->popup_window, "gtk-combobox-popup-window");
1448 gtk_window_set_type_hint (GTK_WINDOW (priv->popup_window),
1449 GDK_WINDOW_TYPE_HINT_COMBO);
1451 g_signal_connect (GTK_WINDOW (priv->popup_window),"show",
1452 G_CALLBACK (gtk_combo_box_child_show),
1454 g_signal_connect (GTK_WINDOW (priv->popup_window),"hide",
1455 G_CALLBACK (gtk_combo_box_child_hide),
1458 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (combo_box));
1459 if (GTK_IS_WINDOW (toplevel))
1461 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
1462 GTK_WINDOW (priv->popup_window));
1463 gtk_window_set_transient_for (GTK_WINDOW (priv->popup_window),
1464 GTK_WINDOW (toplevel));
1467 gtk_window_set_resizable (GTK_WINDOW (priv->popup_window), FALSE);
1468 gtk_window_set_screen (GTK_WINDOW (priv->popup_window),
1469 gtk_widget_get_screen (GTK_WIDGET (combo_box)));
1471 priv->scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1473 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
1476 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (priv->scrolled_window),
1479 gtk_widget_show (priv->scrolled_window);
1481 gtk_container_add (GTK_CONTAINER (priv->popup_window),
1482 priv->scrolled_window);
1485 gtk_container_add (GTK_CONTAINER (priv->scrolled_window),
1488 gtk_widget_show (popup);
1489 g_object_ref (popup);
1490 priv->popup_widget = popup;
1495 gtk_combo_box_menu_position_below (GtkMenu *menu,
1501 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
1502 GtkAllocation child_allocation;
1508 GdkRectangle monitor;
1510 /* FIXME: is using the size request here broken? */
1511 child = gtk_bin_get_child (GTK_BIN (combo_box));
1515 gtk_widget_get_allocation (child, &child_allocation);
1517 if (!gtk_widget_get_has_window (child))
1519 sx += child_allocation.x;
1520 sy += child_allocation.y;
1523 gdk_window_get_root_coords (gtk_widget_get_window (child),
1526 if (GTK_SHADOW_NONE != combo_box->priv->shadow_type)
1527 sx -= gtk_widget_get_style (GTK_WIDGET (combo_box))->xthickness;
1529 gtk_widget_get_preferred_size (GTK_WIDGET (menu),
1532 if (gtk_widget_get_direction (GTK_WIDGET (combo_box)) == GTK_TEXT_DIR_LTR)
1535 *x = sx + child_allocation.width - req.width;
1538 screen = gtk_widget_get_screen (GTK_WIDGET (combo_box));
1539 monitor_num = gdk_screen_get_monitor_at_window (screen,
1540 gtk_widget_get_window (GTK_WIDGET (combo_box)));
1541 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
1545 else if (*x + req.width > monitor.x + monitor.width)
1546 *x = monitor.x + monitor.width - req.width;
1548 if (monitor.y + monitor.height - *y - child_allocation.height >= req.height)
1549 *y += child_allocation.height;
1550 else if (*y - monitor.y >= req.height)
1552 else if (monitor.y + monitor.height - *y - child_allocation.height > *y - monitor.y)
1553 *y += child_allocation.height;
1561 gtk_combo_box_menu_position_over (GtkMenu *menu,
1567 GtkComboBox *combo_box;
1571 GtkAllocation allocation;
1572 GtkAllocation child_allocation;
1579 combo_box = GTK_COMBO_BOX (user_data);
1580 widget = GTK_WIDGET (combo_box);
1582 active = gtk_menu_get_active (GTK_MENU (combo_box->priv->popup_widget));
1584 gtk_widget_get_allocation (widget, &allocation);
1586 menu_xpos = allocation.x;
1587 menu_ypos = allocation.y + allocation.height / 2 - 2;
1589 gtk_widget_get_preferred_width (GTK_WIDGET (menu), &menu_width, NULL);
1593 gtk_widget_get_allocation (active, &child_allocation);
1594 menu_ypos -= child_allocation.height / 2;
1597 children = GTK_MENU_SHELL (combo_box->priv->popup_widget)->children;
1600 child = children->data;
1602 if (active == child)
1605 if (gtk_widget_get_visible (child))
1607 gtk_widget_get_allocation (child, &child_allocation);
1609 menu_ypos -= child_allocation.height;
1612 children = children->next;
1615 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1616 menu_xpos = menu_xpos + allocation.width - menu_width;
1618 gdk_window_get_root_coords (gtk_widget_get_window (widget),
1619 menu_xpos, menu_ypos,
1620 &menu_xpos, &menu_ypos);
1622 /* Clamp the position on screen */
1623 screen_width = gdk_screen_get_width (gtk_widget_get_screen (widget));
1627 else if ((menu_xpos + menu_width) > screen_width)
1628 menu_xpos -= ((menu_xpos + menu_width) - screen_width);
1637 gtk_combo_box_menu_position (GtkMenu *menu,
1643 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
1644 GtkComboBoxPrivate *priv = combo_box->priv;
1645 GtkWidget *menu_item;
1648 if (priv->wrap_width > 0 || priv->cell_view == NULL)
1649 gtk_combo_box_menu_position_below (menu, x, y, push_in, user_data);
1652 /* FIXME handle nested menus better */
1653 menu_item = gtk_menu_get_active (GTK_MENU (priv->popup_widget));
1655 gtk_menu_shell_select_item (GTK_MENU_SHELL (priv->popup_widget),
1658 gtk_combo_box_menu_position_over (menu, x, y, push_in, user_data);
1661 if (!gtk_widget_get_visible (GTK_MENU (priv->popup_widget)->toplevel))
1662 gtk_window_set_type_hint (GTK_WINDOW (GTK_MENU (priv->popup_widget)->toplevel),
1663 GDK_WINDOW_TYPE_HINT_COMBO);
1667 gtk_combo_box_list_position (GtkComboBox *combo_box,
1673 GtkComboBoxPrivate *priv = combo_box->priv;
1674 GtkAllocation allocation;
1677 GdkRectangle monitor;
1678 GtkRequisition popup_req;
1679 GtkPolicyType hpolicy, vpolicy;
1682 /* under windows, the drop down list is as wide as the combo box itself.
1684 GtkWidget *widget = GTK_WIDGET (combo_box);
1688 gtk_widget_get_allocation (widget, &allocation);
1690 if (!gtk_widget_get_has_window (widget))
1696 window = gtk_widget_get_window (widget);
1698 gdk_window_get_root_coords (gtk_widget_get_window (widget),
1701 *width = allocation.width;
1703 hpolicy = vpolicy = GTK_POLICY_NEVER;
1704 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
1706 gtk_widget_get_preferred_size (priv->scrolled_window,
1709 if (popup_req.width > *width)
1711 hpolicy = GTK_POLICY_ALWAYS;
1712 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
1714 gtk_widget_get_preferred_size (priv->scrolled_window,
1718 *height = popup_req.height;
1720 screen = gtk_widget_get_screen (GTK_WIDGET (combo_box));
1721 monitor_num = gdk_screen_get_monitor_at_window (screen, window);
1722 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
1726 else if (*x + *width > monitor.x + monitor.width)
1727 *x = monitor.x + monitor.width - *width;
1729 if (*y + allocation.height + *height <= monitor.y + monitor.height)
1730 *y += allocation.height;
1731 else if (*y - *height >= monitor.y)
1733 else if (monitor.y + monitor.height - (*y + allocation.height) > *y - monitor.y)
1735 *y += allocation.height;
1736 *height = monitor.y + monitor.height - *y;
1740 *height = *y - monitor.y;
1744 if (popup_req.height > *height)
1746 vpolicy = GTK_POLICY_ALWAYS;
1748 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
1754 cell_view_is_sensitive (GtkCellView *cell_view)
1756 GList *cells, *list;
1759 cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (cell_view));
1762 for (list = cells; list; list = list->next)
1764 g_object_get (list->data, "sensitive", &sensitive, NULL);
1769 g_list_free (cells);
1775 tree_column_row_is_sensitive (GtkComboBox *combo_box,
1778 GtkComboBoxPrivate *priv = combo_box->priv;
1779 GList *cells, *list;
1785 if (priv->row_separator_func)
1787 if (priv->row_separator_func (priv->model, iter,
1788 priv->row_separator_data))
1792 gtk_tree_view_column_cell_set_cell_data (priv->column,
1794 iter, FALSE, FALSE);
1796 cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (priv->column));
1799 for (list = cells; list; list = list->next)
1801 g_object_get (list->data, "sensitive", &sensitive, NULL);
1806 g_list_free (cells);
1812 update_menu_sensitivity (GtkComboBox *combo_box,
1815 GtkComboBoxPrivate *priv = combo_box->priv;
1816 GList *children, *child;
1817 GtkWidget *item, *submenu, *separator;
1818 GtkWidget *cell_view;
1824 children = gtk_container_get_children (GTK_CONTAINER (menu));
1826 for (child = children; child; child = child->next)
1828 item = GTK_WIDGET (child->data);
1829 cell_view = gtk_bin_get_child (GTK_BIN (item));
1831 if (!GTK_IS_CELL_VIEW (cell_view))
1834 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (item));
1835 if (submenu != NULL)
1837 gtk_widget_set_sensitive (item, TRUE);
1838 update_menu_sensitivity (combo_box, submenu);
1842 sensitive = cell_view_is_sensitive (GTK_CELL_VIEW (cell_view));
1844 if (menu != priv->popup_widget && child == children)
1846 separator = GTK_WIDGET (child->next->data);
1847 g_object_set (item, "visible", sensitive, NULL);
1848 g_object_set (separator, "visible", sensitive, NULL);
1851 gtk_widget_set_sensitive (item, sensitive);
1855 g_list_free (children);
1859 gtk_combo_box_menu_popup (GtkComboBox *combo_box,
1861 guint32 activate_time)
1863 GtkComboBoxPrivate *priv = combo_box->priv;
1866 gint width, min_width;
1868 update_menu_sensitivity (combo_box, priv->popup_widget);
1871 if (gtk_tree_row_reference_valid (priv->active_row))
1873 path = gtk_tree_row_reference_get_path (priv->active_row);
1874 active_item = gtk_tree_path_get_indices (path)[0];
1875 gtk_tree_path_free (path);
1877 if (priv->add_tearoffs)
1881 /* FIXME handle nested menus better */
1882 gtk_menu_set_active (GTK_MENU (priv->popup_widget), active_item);
1884 if (priv->wrap_width == 0)
1886 GtkAllocation allocation;
1888 gtk_widget_get_allocation (GTK_WIDGET (combo_box), &allocation);
1889 width = allocation.width;
1890 gtk_widget_set_size_request (priv->popup_widget, -1, -1);
1891 gtk_widget_get_preferred_width (priv->popup_widget, &min_width, NULL);
1893 gtk_widget_set_size_request (priv->popup_widget,
1894 MAX (width, min_width), -1);
1897 gtk_menu_popup (GTK_MENU (priv->popup_widget),
1899 gtk_combo_box_menu_position, combo_box,
1900 button, activate_time);
1904 popup_grab_on_window (GdkWindow *window,
1905 GdkDevice *keyboard,
1907 guint32 activate_time)
1910 gdk_device_grab (keyboard, window,
1911 GDK_OWNERSHIP_WINDOW, TRUE,
1912 GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
1913 NULL, activate_time) != GDK_GRAB_SUCCESS)
1917 gdk_device_grab (pointer, window,
1918 GDK_OWNERSHIP_WINDOW, TRUE,
1919 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
1920 GDK_POINTER_MOTION_MASK,
1921 NULL, activate_time) != GDK_GRAB_SUCCESS)
1924 gdk_device_ungrab (keyboard, activate_time);
1933 * gtk_combo_box_popup:
1934 * @combo_box: a #GtkComboBox
1936 * Pops up the menu or dropdown list of @combo_box.
1938 * This function is mostly intended for use by accessibility technologies;
1939 * applications should have little use for it.
1944 gtk_combo_box_popup (GtkComboBox *combo_box)
1946 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
1948 g_signal_emit (combo_box, combo_box_signals[POPUP], 0);
1952 * gtk_combo_box_popup_for_device:
1953 * @combo_box: a #GtkComboBox
1954 * @device: a #GdkDevice
1956 * Pops up the menu or dropdown list of @combo_box, the popup window
1957 * will be grabbed so only @device and its associated pointer/keyboard
1958 * are the only #GdkDevice<!-- -->s able to send events to it.
1963 gtk_combo_box_popup_for_device (GtkComboBox *combo_box,
1966 GtkComboBoxPrivate *priv = combo_box->priv;
1967 gint x, y, width, height;
1968 GtkTreePath *path = NULL, *ppath;
1969 GtkWidget *toplevel;
1970 GdkDevice *keyboard, *pointer;
1973 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
1974 g_return_if_fail (GDK_IS_DEVICE (device));
1976 if (!gtk_widget_get_realized (GTK_WIDGET (combo_box)))
1979 if (gtk_widget_get_mapped (priv->popup_widget))
1982 if (priv->grab_pointer && priv->grab_keyboard)
1985 time = gtk_get_current_event_time ();
1987 if (device->source == GDK_SOURCE_KEYBOARD)
1990 pointer = gdk_device_get_associated_device (device);
1995 keyboard = gdk_device_get_associated_device (device);
1998 if (GTK_IS_MENU (priv->popup_widget))
2000 gtk_combo_box_menu_popup (combo_box,
2001 priv->activate_button,
2002 priv->activate_time);
2006 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (combo_box));
2007 if (GTK_IS_WINDOW (toplevel))
2008 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
2009 GTK_WINDOW (priv->popup_window));
2011 gtk_widget_show_all (priv->scrolled_window);
2012 gtk_combo_box_list_position (combo_box, &x, &y, &width, &height);
2014 gtk_widget_set_size_request (priv->popup_window, width, height);
2015 gtk_window_move (GTK_WINDOW (priv->popup_window), x, y);
2017 if (gtk_tree_row_reference_valid (priv->active_row))
2019 path = gtk_tree_row_reference_get_path (priv->active_row);
2020 ppath = gtk_tree_path_copy (path);
2021 if (gtk_tree_path_up (ppath))
2022 gtk_tree_view_expand_to_path (GTK_TREE_VIEW (priv->tree_view),
2024 gtk_tree_path_free (ppath);
2026 gtk_tree_view_set_hover_expand (GTK_TREE_VIEW (priv->tree_view),
2030 gtk_widget_show (priv->popup_window);
2034 gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->tree_view),
2036 gtk_tree_path_free (path);
2039 gtk_widget_grab_focus (priv->popup_window);
2040 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->button),
2043 if (!gtk_widget_has_focus (priv->tree_view))
2044 gtk_widget_grab_focus (priv->tree_view);
2046 if (!popup_grab_on_window (gtk_widget_get_window (priv->popup_window),
2047 keyboard, pointer, time))
2049 gtk_widget_hide (priv->popup_window);
2053 gtk_device_grab_add (priv->popup_window, pointer, TRUE);
2054 priv->grab_pointer = pointer;
2055 priv->grab_keyboard = keyboard;
2059 gtk_combo_box_real_popup (GtkComboBox *combo_box)
2063 device = gtk_get_current_event_device ();
2067 GdkDeviceManager *device_manager;
2068 GdkDisplay *display;
2071 display = gtk_widget_get_display (GTK_WIDGET (combo_box));
2072 device_manager = gdk_display_get_device_manager (display);
2074 /* No device was set, pick the first master device */
2075 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
2076 device = devices->data;
2077 g_list_free (devices);
2080 gtk_combo_box_popup_for_device (combo_box, device);
2084 gtk_combo_box_real_popdown (GtkComboBox *combo_box)
2086 if (combo_box->priv->popup_shown)
2088 gtk_combo_box_popdown (combo_box);
2096 * gtk_combo_box_popdown:
2097 * @combo_box: a #GtkComboBox
2099 * Hides the menu or dropdown list of @combo_box.
2101 * This function is mostly intended for use by accessibility technologies;
2102 * applications should have little use for it.
2107 gtk_combo_box_popdown (GtkComboBox *combo_box)
2109 GtkComboBoxPrivate *priv = combo_box->priv;
2111 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
2113 if (GTK_IS_MENU (priv->popup_widget))
2115 gtk_menu_popdown (GTK_MENU (priv->popup_widget));
2119 if (!gtk_widget_get_realized (GTK_WIDGET (combo_box)))
2122 gtk_device_grab_remove (priv->popup_window, priv->grab_pointer);
2123 gtk_widget_hide_all (priv->popup_window);
2124 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->button),
2127 priv->grab_pointer = NULL;
2128 priv->grab_keyboard = NULL;
2132 gtk_combo_box_update_requested_width (GtkComboBox *combo_box,
2135 GtkComboBoxPrivate *priv = combo_box->priv;
2136 gint padding, min_width, nat_width;
2138 if (priv->cell_view)
2139 gtk_widget_style_get (priv->cell_view,
2140 "focus-line-width", &padding,
2145 /* add some pixels for good measure */
2146 padding += BONUS_PADDING;
2148 if (priv->cell_view)
2149 gtk_cell_view_get_desired_width_of_row (GTK_CELL_VIEW (priv->cell_view),
2150 path, &min_width, &nat_width);
2152 min_width = nat_width = 0;
2154 min_width += padding;
2155 nat_width += padding;
2157 if (min_width > priv->minimum_width || nat_width > priv->natural_width)
2159 priv->minimum_width = MAX (priv->minimum_width, min_width);
2160 priv->natural_width = MAX (priv->natural_width, nat_width);
2162 if (priv->cell_view)
2164 gtk_widget_set_size_request (priv->cell_view, min_width, -1);
2165 gtk_widget_queue_resize (priv->cell_view);
2170 #define GTK_COMBO_BOX_SIZE_ALLOCATE_BUTTON \
2171 gtk_widget_get_preferred_size (combo_box->priv->button, \
2175 child.x = allocation->x + shadow_width; \
2177 child.x = allocation->x + allocation->width - req.width - shadow_width; \
2179 child.y = allocation->y + shadow_height; \
2180 child.width = req.width; \
2181 child.height = allocation->height - 2 * shadow_height; \
2182 child.width = MAX (1, child.width); \
2183 child.height = MAX (1, child.height); \
2185 gtk_widget_size_allocate (combo_box->priv->button, &child);
2188 gtk_combo_box_size_allocate (GtkWidget *widget,
2189 GtkAllocation *allocation)
2191 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
2192 GtkComboBoxPrivate *priv = combo_box->priv;
2193 GtkWidget *child_widget;
2194 gint shadow_width, shadow_height;
2195 gint focus_width, focus_pad;
2196 GtkAllocation child;
2199 gboolean is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2201 gtk_widget_set_allocation (widget, allocation);
2202 child_widget = gtk_bin_get_child (GTK_BIN (widget));
2204 style = gtk_widget_get_style (widget);
2205 gtk_widget_style_get (widget,
2206 "focus-line-width", &focus_width,
2207 "focus-padding", &focus_pad,
2210 if (GTK_SHADOW_NONE != priv->shadow_type)
2212 shadow_width = style->xthickness;
2213 shadow_height = style->ythickness;
2221 if (!priv->tree_view)
2223 if (priv->cell_view)
2225 gint xthickness, ythickness;
2230 allocation->x += shadow_width;
2231 allocation->y += shadow_height;
2232 allocation->width -= 2 * shadow_width;
2233 allocation->height -= 2 * shadow_height;
2235 gtk_widget_size_allocate (priv->button, allocation);
2237 /* set some things ready */
2238 border_width = gtk_container_get_border_width (GTK_CONTAINER (priv->button));
2239 style = gtk_widget_get_style (priv->button);
2240 xthickness = style->xthickness;
2241 ythickness = style->ythickness;
2243 child.x = allocation->x;
2244 child.y = allocation->y;
2245 width = allocation->width;
2246 child.height = allocation->height;
2248 if (!priv->is_cell_renderer)
2250 child.x += border_width + xthickness + focus_width + focus_pad;
2251 child.y += border_width + ythickness + focus_width + focus_pad;
2252 width -= 2 * (child.x - allocation->x);
2253 child.height -= 2 * (child.y - allocation->y);
2257 /* handle the children */
2258 gtk_widget_get_preferred_size (priv->arrow, &req, NULL);
2259 child.width = req.width;
2261 child.x += width - req.width;
2262 child.width = MAX (1, child.width);
2263 child.height = MAX (1, child.height);
2264 gtk_widget_size_allocate (priv->arrow, &child);
2266 child.x += req.width;
2267 gtk_widget_get_preferred_size (priv->separator, &req, NULL);
2268 child.width = req.width;
2270 child.x -= req.width;
2271 child.width = MAX (1, child.width);
2272 child.height = MAX (1, child.height);
2273 gtk_widget_size_allocate (priv->separator, &child);
2277 child.x += req.width;
2278 child.width = allocation->x + allocation->width
2279 - (border_width + xthickness + focus_width + focus_pad)
2284 child.width = child.x;
2285 child.x = allocation->x
2286 + border_width + xthickness + focus_width + focus_pad;
2287 child.width -= child.x;
2290 if (gtk_widget_get_visible (priv->popup_widget))
2292 gint width, min_width;
2294 if (priv->wrap_width == 0)
2296 GtkAllocation combo_box_allocation;
2298 gtk_widget_get_allocation (GTK_WIDGET (combo_box), &combo_box_allocation);
2299 width = combo_box_allocation.width;
2300 gtk_widget_set_size_request (priv->popup_widget, -1, -1);
2301 gtk_widget_get_preferred_width (priv->popup_widget, &min_width, NULL);
2302 gtk_widget_set_size_request (priv->popup_widget,
2303 MAX (width, min_width), -1);
2306 /* reposition the menu after giving it a new width */
2307 gtk_menu_reposition (GTK_MENU (priv->popup_widget));
2310 child.width = MAX (1, child.width);
2311 child.height = MAX (1, child.height);
2312 gtk_widget_size_allocate (child_widget, &child);
2316 GTK_COMBO_BOX_SIZE_ALLOCATE_BUTTON
2319 child.x = allocation->x + req.width + shadow_width;
2321 child.x = allocation->x + shadow_width;
2322 child.y = allocation->y + shadow_height;
2323 child.width = allocation->width - req.width - 2 * shadow_width;
2324 child.width = MAX (1, child.width);
2325 child.height = MAX (1, child.height);
2326 gtk_widget_size_allocate (child_widget, &child);
2333 /* Combobox thickness + border-width */
2334 guint border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
2335 int delta_x = shadow_width + border_width;
2336 int delta_y = shadow_height + border_width;
2339 GTK_COMBO_BOX_SIZE_ALLOCATE_BUTTON
2343 child.x = allocation->x + req.width;
2345 child.x = allocation->x;
2347 child.y = allocation->y;
2348 child.width = allocation->width - req.width;
2349 child.height = allocation->height;
2351 if (priv->cell_view_frame)
2355 child.width = MAX (1, child.width - delta_x * 2);
2356 child.height = MAX (1, child.height - delta_y * 2);
2357 gtk_widget_size_allocate (priv->cell_view_frame, &child);
2360 if (priv->has_frame)
2362 border_width = gtk_container_get_border_width (GTK_CONTAINER (priv->cell_view_frame));
2363 style = gtk_widget_get_style (priv->cell_view_frame);
2364 delta_x = border_width + style->xthickness;
2365 delta_y = border_width + style->ythickness;
2369 child.width -= delta_x * 2;
2370 child.height -= delta_y * 2;
2377 child.width -= delta_x * 2;
2378 child.height -= delta_y * 2;
2381 if (gtk_widget_get_visible (priv->popup_window))
2383 gint x, y, width, height;
2384 gtk_combo_box_list_position (combo_box, &x, &y, &width, &height);
2385 gtk_window_move (GTK_WINDOW (priv->popup_window), x, y);
2386 gtk_widget_set_size_request (priv->popup_window, width, height);
2390 child.width = MAX (1, child.width);
2391 child.height = MAX (1, child.height);
2393 gtk_widget_size_allocate (child_widget, &child);
2397 #undef GTK_COMBO_BOX_ALLOCATE_BUTTON
2400 gtk_combo_box_unset_model (GtkComboBox *combo_box)
2402 GtkComboBoxPrivate *priv = combo_box->priv;
2406 g_signal_handler_disconnect (priv->model,
2408 g_signal_handler_disconnect (priv->model,
2410 g_signal_handler_disconnect (priv->model,
2411 priv->reordered_id);
2412 g_signal_handler_disconnect (priv->model,
2417 if (!priv->tree_view)
2419 if (priv->popup_widget)
2420 gtk_container_foreach (GTK_CONTAINER (priv->popup_widget),
2421 (GtkCallback)gtk_widget_destroy, NULL);
2426 g_object_unref (priv->model);
2430 if (priv->active_row)
2432 gtk_tree_row_reference_free (priv->active_row);
2433 priv->active_row = NULL;
2436 if (priv->cell_view)
2437 gtk_cell_view_set_model (GTK_CELL_VIEW (priv->cell_view), NULL);
2441 gtk_combo_box_forall (GtkContainer *container,
2442 gboolean include_internals,
2443 GtkCallback callback,
2444 gpointer callback_data)
2446 GtkComboBox *combo_box = GTK_COMBO_BOX (container);
2447 GtkComboBoxPrivate *priv = combo_box->priv;
2450 if (include_internals)
2453 (* callback) (priv->button, callback_data);
2454 if (priv->cell_view_frame)
2455 (* callback) (priv->cell_view_frame, callback_data);
2458 child = gtk_bin_get_child (GTK_BIN (container));
2460 (* callback) (child, callback_data);
2464 gtk_combo_box_child_show (GtkWidget *widget,
2465 GtkComboBox *combo_box)
2467 GtkComboBoxPrivate *priv = combo_box->priv;
2469 priv->popup_shown = TRUE;
2470 g_object_notify (G_OBJECT (combo_box), "popup-shown");
2474 gtk_combo_box_child_hide (GtkWidget *widget,
2475 GtkComboBox *combo_box)
2477 GtkComboBoxPrivate *priv = combo_box->priv;
2479 priv->popup_shown = FALSE;
2480 g_object_notify (G_OBJECT (combo_box), "popup-shown");
2484 gtk_combo_box_draw (GtkWidget *widget,
2487 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
2488 GtkComboBoxPrivate *priv = combo_box->priv;
2490 if (priv->shadow_type != GTK_SHADOW_NONE)
2492 gtk_paint_shadow (gtk_widget_get_style (widget),
2494 GTK_STATE_NORMAL, priv->shadow_type,
2497 gtk_widget_get_allocated_width (widget),
2498 gtk_widget_get_allocated_height (widget));
2501 gtk_container_propagate_draw (GTK_CONTAINER (widget),
2504 if (priv->tree_view && priv->cell_view_frame)
2506 gtk_container_propagate_draw (GTK_CONTAINER (widget),
2507 priv->cell_view_frame, cr);
2510 gtk_container_propagate_draw (GTK_CONTAINER (widget),
2511 gtk_bin_get_child (GTK_BIN (widget)),
2527 path_visible (GtkTreeView *view,
2533 /* Note that we rely on the fact that collapsed rows don't have nodes
2535 return _gtk_tree_view_find_node (view, path, &tree, &node);
2539 tree_next_func (GtkTreeModel *model,
2544 SearchData *search_data = (SearchData *)data;
2546 if (search_data->found)
2548 if (!tree_column_row_is_sensitive (search_data->combo, iter))
2551 if (search_data->visible &&
2552 !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
2555 search_data->set = TRUE;
2556 search_data->iter = *iter;
2561 if (gtk_tree_path_compare (path, search_data->path) == 0)
2562 search_data->found = TRUE;
2568 tree_next (GtkComboBox *combo,
2569 GtkTreeModel *model,
2574 SearchData search_data;
2576 search_data.combo = combo;
2577 search_data.path = gtk_tree_model_get_path (model, iter);
2578 search_data.visible = visible;
2579 search_data.found = FALSE;
2580 search_data.set = FALSE;
2582 gtk_tree_model_foreach (model, tree_next_func, &search_data);
2584 *next = search_data.iter;
2586 gtk_tree_path_free (search_data.path);
2588 return search_data.set;
2592 tree_prev_func (GtkTreeModel *model,
2597 SearchData *search_data = (SearchData *)data;
2599 if (gtk_tree_path_compare (path, search_data->path) == 0)
2601 search_data->found = TRUE;
2605 if (!tree_column_row_is_sensitive (search_data->combo, iter))
2608 if (search_data->visible &&
2609 !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
2612 search_data->set = TRUE;
2613 search_data->iter = *iter;
2619 tree_prev (GtkComboBox *combo,
2620 GtkTreeModel *model,
2625 SearchData search_data;
2627 search_data.combo = combo;
2628 search_data.path = gtk_tree_model_get_path (model, iter);
2629 search_data.visible = visible;
2630 search_data.found = FALSE;
2631 search_data.set = FALSE;
2633 gtk_tree_model_foreach (model, tree_prev_func, &search_data);
2635 *prev = search_data.iter;
2637 gtk_tree_path_free (search_data.path);
2639 return search_data.set;
2643 tree_last_func (GtkTreeModel *model,
2648 SearchData *search_data = (SearchData *)data;
2650 if (!tree_column_row_is_sensitive (search_data->combo, iter))
2653 /* Note that we rely on the fact that collapsed rows don't have nodes
2655 if (search_data->visible &&
2656 !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
2659 search_data->set = TRUE;
2660 search_data->iter = *iter;
2666 tree_last (GtkComboBox *combo,
2667 GtkTreeModel *model,
2671 SearchData search_data;
2673 search_data.combo = combo;
2674 search_data.visible = visible;
2675 search_data.set = FALSE;
2677 gtk_tree_model_foreach (model, tree_last_func, &search_data);
2679 *last = search_data.iter;
2681 return search_data.set;
2686 tree_first_func (GtkTreeModel *model,
2691 SearchData *search_data = (SearchData *)data;
2693 if (!tree_column_row_is_sensitive (search_data->combo, iter))
2696 if (search_data->visible &&
2697 !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
2700 search_data->set = TRUE;
2701 search_data->iter = *iter;
2707 tree_first (GtkComboBox *combo,
2708 GtkTreeModel *model,
2712 SearchData search_data;
2714 search_data.combo = combo;
2715 search_data.visible = visible;
2716 search_data.set = FALSE;
2718 gtk_tree_model_foreach (model, tree_first_func, &search_data);
2720 *first = search_data.iter;
2722 return search_data.set;
2726 gtk_combo_box_scroll_event (GtkWidget *widget,
2727 GdkEventScroll *event)
2729 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
2732 GtkTreeIter new_iter;
2734 if (!gtk_combo_box_get_active_iter (combo_box, &iter))
2737 if (event->direction == GDK_SCROLL_UP)
2738 found = tree_prev (combo_box, combo_box->priv->model,
2739 &iter, &new_iter, FALSE);
2741 found = tree_next (combo_box, combo_box->priv->model,
2742 &iter, &new_iter, FALSE);
2745 gtk_combo_box_set_active_iter (combo_box, &new_iter);
2755 gtk_combo_box_sync_cells (GtkComboBox *combo_box,
2756 GtkCellLayout *cell_layout)
2758 GtkComboBoxPrivate *priv = combo_box->priv;
2761 for (k = priv->cells; k; k = k->next)
2764 ComboCellInfo *info = (ComboCellInfo *)k->data;
2766 if (info->pack == GTK_PACK_START)
2767 gtk_cell_layout_pack_start (cell_layout,
2768 info->cell, info->expand);
2769 else if (info->pack == GTK_PACK_END)
2770 gtk_cell_layout_pack_end (cell_layout,
2771 info->cell, info->expand);
2773 gtk_cell_layout_set_cell_data_func (cell_layout,
2775 combo_cell_data_func, info, NULL);
2777 for (j = info->attributes; j; j = j->next->next)
2779 gtk_cell_layout_add_attribute (cell_layout,
2782 GPOINTER_TO_INT (j->next->data));
2788 gtk_combo_box_menu_setup (GtkComboBox *combo_box,
2789 gboolean add_children)
2791 GtkComboBoxPrivate *priv = combo_box->priv;
2795 child = gtk_bin_get_child (GTK_BIN (combo_box));
2797 if (priv->cell_view)
2799 priv->button = gtk_toggle_button_new ();
2800 gtk_button_set_focus_on_click (GTK_BUTTON (priv->button),
2801 priv->focus_on_click);
2803 g_signal_connect (priv->button, "toggled",
2804 G_CALLBACK (gtk_combo_box_button_toggled), combo_box);
2805 gtk_widget_set_parent (priv->button,
2806 gtk_widget_get_parent (child));
2808 priv->box = gtk_hbox_new (FALSE, 0);
2809 gtk_container_add (GTK_CONTAINER (priv->button), priv->box);
2811 priv->separator = gtk_vseparator_new ();
2812 gtk_container_add (GTK_CONTAINER (priv->box), priv->separator);
2814 priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
2815 gtk_container_add (GTK_CONTAINER (priv->box), priv->arrow);
2817 gtk_widget_show_all (priv->button);
2821 priv->button = gtk_toggle_button_new ();
2822 gtk_button_set_focus_on_click (GTK_BUTTON (priv->button),
2823 priv->focus_on_click);
2825 g_signal_connect (priv->button, "toggled",
2826 G_CALLBACK (gtk_combo_box_button_toggled), combo_box);
2827 gtk_widget_set_parent (priv->button,
2828 gtk_widget_get_parent (child));
2830 priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
2831 gtk_container_add (GTK_CONTAINER (priv->button), priv->arrow);
2832 gtk_widget_show_all (priv->button);
2835 g_signal_connect (priv->button, "button-press-event",
2836 G_CALLBACK (gtk_combo_box_menu_button_press),
2838 g_signal_connect (priv->button, "state-changed",
2839 G_CALLBACK (gtk_combo_box_button_state_changed),
2842 /* create our funky menu */
2843 menu = gtk_menu_new ();
2844 gtk_widget_set_name (menu, "gtk-combobox-popup-menu");
2845 gtk_menu_set_reserve_toggle_size (GTK_MENU (menu), FALSE);
2847 g_signal_connect (menu, "key-press-event",
2848 G_CALLBACK (gtk_combo_box_menu_key_press), combo_box);
2849 gtk_combo_box_set_popup_widget (combo_box, menu);
2853 gtk_combo_box_menu_fill (combo_box);
2855 /* the column is needed in tree_column_row_is_sensitive() */
2856 priv->column = gtk_tree_view_column_new ();
2857 g_object_ref_sink (priv->column);
2858 gtk_combo_box_sync_cells (combo_box, GTK_CELL_LAYOUT (priv->column));
2860 gtk_combo_box_update_title (combo_box);
2861 gtk_combo_box_update_sensitivity (combo_box);
2865 gtk_combo_box_menu_fill (GtkComboBox *combo_box)
2867 GtkComboBoxPrivate *priv = combo_box->priv;
2873 menu = priv->popup_widget;
2875 if (priv->add_tearoffs)
2877 GtkWidget *tearoff = gtk_tearoff_menu_item_new ();
2879 gtk_widget_show (tearoff);
2881 if (priv->wrap_width)
2882 gtk_menu_attach (GTK_MENU (menu), tearoff, 0, priv->wrap_width, 0, 1);
2884 gtk_menu_shell_append (GTK_MENU_SHELL (menu), tearoff);
2887 gtk_combo_box_menu_fill_level (combo_box, menu, NULL);
2891 gtk_cell_view_menu_item_new (GtkComboBox *combo_box,
2892 GtkTreeModel *model,
2895 GtkWidget *cell_view;
2900 cell_view = gtk_cell_view_new ();
2901 item = gtk_menu_item_new ();
2902 gtk_container_add (GTK_CONTAINER (item), cell_view);
2904 gtk_cell_view_set_model (GTK_CELL_VIEW (cell_view), model);
2905 path = gtk_tree_model_get_path (model, iter);
2906 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (cell_view), path);
2907 gtk_tree_path_free (path);
2909 gtk_combo_box_sync_cells (combo_box, GTK_CELL_LAYOUT (cell_view));
2910 gtk_widget_get_preferred_size (cell_view, &req, NULL);
2911 gtk_widget_show (cell_view);
2917 gtk_combo_box_menu_fill_level (GtkComboBox *combo_box,
2919 GtkTreeIter *parent)
2921 GtkComboBoxPrivate *priv = combo_box->priv;
2922 GtkTreeModel *model = priv->model;
2923 GtkWidget *item, *submenu, *subitem, *separator;
2925 gboolean is_separator;
2930 n_children = gtk_tree_model_iter_n_children (model, parent);
2933 for (i = 0; i < n_children; i++)
2935 gtk_tree_model_iter_nth_child (model, &iter, parent, i);
2937 if (priv->row_separator_func)
2938 is_separator = priv->row_separator_func (priv->model, &iter,
2939 priv->row_separator_data);
2941 is_separator = FALSE;
2945 item = gtk_separator_menu_item_new ();
2946 path = gtk_tree_model_get_path (model, &iter);
2947 g_object_set_data_full (G_OBJECT (item),
2948 I_("gtk-combo-box-item-path"),
2949 gtk_tree_row_reference_new (model, path),
2950 (GDestroyNotify)gtk_tree_row_reference_free);
2951 gtk_tree_path_free (path);
2955 item = gtk_cell_view_menu_item_new (combo_box, model, &iter);
2956 if (gtk_tree_model_iter_has_child (model, &iter))
2958 submenu = gtk_menu_new ();
2959 gtk_menu_set_reserve_toggle_size (GTK_MENU (submenu), FALSE);
2960 gtk_widget_show (submenu);
2961 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
2963 /* Ugly - since menus can only activate leafs, we have to
2964 * duplicate the item inside the submenu.
2966 subitem = gtk_cell_view_menu_item_new (combo_box, model, &iter);
2967 separator = gtk_separator_menu_item_new ();
2968 gtk_widget_show (subitem);
2969 gtk_widget_show (separator);
2970 g_signal_connect (subitem, "activate",
2971 G_CALLBACK (gtk_combo_box_menu_item_activate),
2973 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), subitem);
2974 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), separator);
2976 gtk_combo_box_menu_fill_level (combo_box, submenu, &iter);
2978 g_signal_connect (item, "activate",
2979 G_CALLBACK (gtk_combo_box_menu_item_activate),
2983 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
2984 if (priv->wrap_width && menu == priv->popup_widget)
2985 gtk_combo_box_relayout_item (combo_box, item, &iter, last);
2986 gtk_widget_show (item);
2993 gtk_combo_box_menu_destroy (GtkComboBox *combo_box)
2995 GtkComboBoxPrivate *priv = combo_box->priv;
2997 g_signal_handlers_disconnect_matched (priv->button,
2998 G_SIGNAL_MATCH_DATA,
3000 gtk_combo_box_menu_button_press, NULL);
3001 g_signal_handlers_disconnect_matched (priv->button,
3002 G_SIGNAL_MATCH_DATA,
3004 gtk_combo_box_button_state_changed, combo_box);
3006 /* unparent will remove our latest ref */
3007 gtk_widget_unparent (priv->button);
3010 priv->button = NULL;
3012 priv->separator = NULL;
3014 g_object_unref (priv->column);
3015 priv->column = NULL;
3017 /* changing the popup window will unref the menu and the children */
3025 menu_occupied (GtkMenu *menu,
3029 guint bottom_attach)
3033 for (i = GTK_MENU_SHELL (menu)->children; i; i = i->next)
3037 gtk_container_child_get (GTK_CONTAINER (menu),
3041 "bottom-attach", &b,
3045 /* look if this item intersects with the given coordinates */
3046 if (right_attach > l && left_attach < r && bottom_attach > t && top_attach < b)
3054 gtk_combo_box_relayout_item (GtkComboBox *combo_box,
3059 GtkComboBoxPrivate *priv = combo_box->priv;
3060 gint current_col = 0, current_row = 0;
3061 gint rows = 1, cols = 1;
3062 GtkWidget *menu = priv->popup_widget;
3064 if (!GTK_IS_MENU_SHELL (menu))
3067 if (priv->col_column == -1 &&
3068 priv->row_column == -1 &&
3071 gtk_container_child_get (GTK_CONTAINER (menu),
3073 "right-attach", ¤t_col,
3074 "top-attach", ¤t_row,
3076 if (current_col + cols > priv->wrap_width)
3084 if (priv->col_column != -1)
3085 gtk_tree_model_get (priv->model, iter,
3086 priv->col_column, &cols,
3088 if (priv->row_column != -1)
3089 gtk_tree_model_get (priv->model, iter,
3090 priv->row_column, &rows,
3095 if (current_col + cols > priv->wrap_width)
3101 if (!menu_occupied (GTK_MENU (menu),
3102 current_col, current_col + cols,
3103 current_row, current_row + rows))
3110 /* set attach props */
3111 gtk_menu_attach (GTK_MENU (menu), item,
3112 current_col, current_col + cols,
3113 current_row, current_row + rows);
3117 gtk_combo_box_relayout (GtkComboBox *combo_box)
3122 menu = combo_box->priv->popup_widget;
3124 /* do nothing unless we are in menu style and realized */
3125 if (combo_box->priv->tree_view || !GTK_IS_MENU_SHELL (menu))
3128 list = gtk_container_get_children (GTK_CONTAINER (menu));
3130 for (j = g_list_last (list); j; j = j->prev)
3131 gtk_container_remove (GTK_CONTAINER (menu), j->data);
3133 gtk_combo_box_menu_fill (combo_box);
3140 gtk_combo_box_menu_button_press (GtkWidget *widget,
3141 GdkEventButton *event,
3144 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3145 GtkComboBoxPrivate *priv = combo_box->priv;
3147 if (GTK_IS_MENU (priv->popup_widget) &&
3148 event->type == GDK_BUTTON_PRESS && event->button == 1)
3150 if (priv->focus_on_click &&
3151 !gtk_widget_has_focus (priv->button))
3152 gtk_widget_grab_focus (priv->button);
3154 gtk_combo_box_menu_popup (combo_box, event->button, event->time);
3163 gtk_combo_box_menu_item_activate (GtkWidget *item,
3166 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3167 GtkWidget *cell_view;
3171 cell_view = gtk_bin_get_child (GTK_BIN (item));
3173 g_return_if_fail (GTK_IS_CELL_VIEW (cell_view));
3175 path = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (cell_view));
3177 if (gtk_tree_model_get_iter (combo_box->priv->model, &iter, path))
3179 if (gtk_menu_item_get_submenu (GTK_MENU_ITEM (item)) == NULL)
3180 gtk_combo_box_set_active_iter (combo_box, &iter);
3183 gtk_tree_path_free (path);
3185 g_object_set (combo_box,
3186 "editing-canceled", FALSE,
3191 gtk_combo_box_update_sensitivity (GtkComboBox *combo_box)
3194 gboolean sensitive = TRUE; /* fool code checkers */
3196 if (!combo_box->priv->button)
3199 switch (combo_box->priv->button_sensitivity)
3201 case GTK_SENSITIVITY_ON:
3204 case GTK_SENSITIVITY_OFF:
3207 case GTK_SENSITIVITY_AUTO:
3208 sensitive = combo_box->priv->model &&
3209 gtk_tree_model_get_iter_first (combo_box->priv->model, &iter);
3212 g_assert_not_reached ();
3216 gtk_widget_set_sensitive (combo_box->priv->button, sensitive);
3218 /* In list-mode, we also need to update sensitivity of the event box */
3219 if (GTK_IS_TREE_VIEW (combo_box->priv->tree_view)
3220 && combo_box->priv->cell_view)
3221 gtk_widget_set_sensitive (combo_box->priv->box, sensitive);
3225 gtk_combo_box_model_row_inserted (GtkTreeModel *model,
3230 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3232 if (combo_box->priv->tree_view)
3233 gtk_combo_box_list_popup_resize (combo_box);
3235 gtk_combo_box_menu_row_inserted (model, path, iter, user_data);
3237 gtk_combo_box_update_sensitivity (combo_box);
3241 gtk_combo_box_model_row_deleted (GtkTreeModel *model,
3245 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3246 GtkComboBoxPrivate *priv = combo_box->priv;
3248 if (!gtk_tree_row_reference_valid (priv->active_row))
3250 if (priv->cell_view)
3251 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (priv->cell_view), NULL);
3252 g_signal_emit (combo_box, combo_box_signals[CHANGED], 0);
3255 if (priv->tree_view)
3256 gtk_combo_box_list_popup_resize (combo_box);
3258 gtk_combo_box_menu_row_deleted (model, path, user_data);
3260 gtk_combo_box_update_sensitivity (combo_box);
3264 gtk_combo_box_model_rows_reordered (GtkTreeModel *model,
3270 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3272 gtk_tree_row_reference_reordered (G_OBJECT (user_data), path, iter, new_order);
3274 if (!combo_box->priv->tree_view)
3275 gtk_combo_box_menu_rows_reordered (model, path, iter, new_order, user_data);
3279 gtk_combo_box_model_row_changed (GtkTreeModel *model,
3284 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3285 GtkComboBoxPrivate *priv = combo_box->priv;
3286 GtkTreePath *active_path;
3288 /* FIXME this belongs to GtkCellView */
3289 if (gtk_tree_row_reference_valid (priv->active_row))
3291 active_path = gtk_tree_row_reference_get_path (priv->active_row);
3292 if (gtk_tree_path_compare (path, active_path) == 0 &&
3294 gtk_widget_queue_resize (GTK_WIDGET (priv->cell_view));
3295 gtk_tree_path_free (active_path);
3298 if (priv->tree_view)
3299 gtk_combo_box_list_row_changed (model, path, iter, user_data);
3301 gtk_combo_box_menu_row_changed (model, path, iter, user_data);
3305 list_popup_resize_idle (gpointer user_data)
3307 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3308 GtkComboBoxPrivate *priv = combo_box->priv;
3309 gint x, y, width, height;
3311 if (priv->tree_view && gtk_widget_get_mapped (priv->popup_window))
3313 gtk_combo_box_list_position (combo_box, &x, &y, &width, &height);
3315 gtk_widget_set_size_request (priv->popup_window, width, height);
3316 gtk_window_move (GTK_WINDOW (priv->popup_window), x, y);
3319 priv->resize_idle_id = 0;
3325 gtk_combo_box_list_popup_resize (GtkComboBox *combo_box)
3327 GtkComboBoxPrivate *priv = combo_box->priv;
3329 if (!priv->resize_idle_id)
3330 priv->resize_idle_id =
3331 gdk_threads_add_idle (list_popup_resize_idle, combo_box);
3335 gtk_combo_box_model_row_expanded (GtkTreeModel *model,
3340 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3342 gtk_combo_box_list_popup_resize (combo_box);
3347 find_menu_by_path (GtkWidget *menu,
3349 gboolean skip_first)
3355 GtkTreeRowReference *mref;
3359 list = gtk_container_get_children (GTK_CONTAINER (menu));
3362 for (i = list; i; i = i->next)
3364 child = gtk_bin_get_child (i->data);
3365 if (GTK_IS_SEPARATOR_MENU_ITEM (i->data))
3367 mref = g_object_get_data (G_OBJECT (i->data), "gtk-combo-box-item-path");
3370 else if (!gtk_tree_row_reference_valid (mref))
3373 mpath = gtk_tree_row_reference_get_path (mref);
3375 else if (GTK_IS_CELL_VIEW (child))
3383 mpath = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (child));
3388 /* this case is necessary, since the row reference of
3389 * the cell view may already be updated after a deletion
3396 if (gtk_tree_path_compare (mpath, path) == 0)
3398 gtk_tree_path_free (mpath);
3402 if (gtk_tree_path_is_ancestor (mpath, path))
3404 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
3405 if (submenu != NULL)
3407 gtk_tree_path_free (mpath);
3408 item = find_menu_by_path (submenu, path, TRUE);
3412 gtk_tree_path_free (mpath);
3422 dump_menu_tree (GtkWidget *menu,
3429 list = gtk_container_get_children (GTK_CONTAINER (menu));
3430 for (i = list; i; i = i->next)
3432 if (GTK_IS_CELL_VIEW (GTK_BIN (i->data)->child))
3434 path = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (GTK_BIN (i->data)->child));
3435 g_print ("%*s%s\n", 2 * level, " ", gtk_tree_path_to_string (path));
3436 gtk_tree_path_free (path);
3438 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
3439 if (submenu != NULL)
3440 dump_menu_tree (submenu, level + 1);
3449 gtk_combo_box_menu_row_inserted (GtkTreeModel *model,
3454 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3455 GtkComboBoxPrivate *priv = combo_box->priv;
3457 GtkWidget *item, *menu, *separator;
3461 gboolean is_separator;
3463 if (!priv->popup_widget)
3466 depth = gtk_tree_path_get_depth (path);
3467 pos = gtk_tree_path_get_indices (path)[depth - 1];
3470 ppath = gtk_tree_path_copy (path);
3471 gtk_tree_path_up (ppath);
3472 parent = find_menu_by_path (priv->popup_widget, ppath, FALSE);
3473 gtk_tree_path_free (ppath);
3475 menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (parent));
3478 menu = gtk_menu_new ();
3479 gtk_menu_set_reserve_toggle_size (GTK_MENU (menu), FALSE);
3480 gtk_widget_show (menu);
3481 gtk_menu_item_set_submenu (GTK_MENU_ITEM (parent), menu);
3483 /* Ugly - since menus can only activate leaves, we have to
3484 * duplicate the item inside the submenu.
3486 gtk_tree_model_iter_parent (model, &piter, iter);
3487 item = gtk_cell_view_menu_item_new (combo_box, model, &piter);
3488 separator = gtk_separator_menu_item_new ();
3489 g_signal_connect (item, "activate",
3490 G_CALLBACK (gtk_combo_box_menu_item_activate),
3492 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
3493 gtk_menu_shell_append (GTK_MENU_SHELL (menu), separator);
3494 if (cell_view_is_sensitive (GTK_CELL_VIEW (gtk_bin_get_child (GTK_BIN (item)))))
3496 gtk_widget_show (item);
3497 gtk_widget_show (separator);
3504 menu = priv->popup_widget;
3505 if (priv->add_tearoffs)
3509 if (priv->row_separator_func)
3510 is_separator = priv->row_separator_func (model, iter,
3511 priv->row_separator_data);
3513 is_separator = FALSE;
3517 item = gtk_separator_menu_item_new ();
3518 g_object_set_data_full (G_OBJECT (item),
3519 I_("gtk-combo-box-item-path"),
3520 gtk_tree_row_reference_new (model, path),
3521 (GDestroyNotify)gtk_tree_row_reference_free);
3525 item = gtk_cell_view_menu_item_new (combo_box, model, iter);
3527 g_signal_connect (item, "activate",
3528 G_CALLBACK (gtk_combo_box_menu_item_activate),
3532 gtk_widget_show (item);
3533 gtk_menu_shell_insert (GTK_MENU_SHELL (menu), item, pos);
3537 gtk_combo_box_menu_row_deleted (GtkTreeModel *model,
3541 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3542 GtkComboBoxPrivate *priv = combo_box->priv;
3546 if (!priv->popup_widget)
3549 item = find_menu_by_path (priv->popup_widget, path, FALSE);
3550 menu = gtk_widget_get_parent (item);
3551 gtk_container_remove (GTK_CONTAINER (menu), item);
3553 if (gtk_tree_path_get_depth (path) > 1)
3555 GtkTreePath *parent_path;
3559 parent_path = gtk_tree_path_copy (path);
3560 gtk_tree_path_up (parent_path);
3561 gtk_tree_model_get_iter (model, &iter, parent_path);
3563 if (!gtk_tree_model_iter_has_child (model, &iter))
3565 parent = find_menu_by_path (priv->popup_widget,
3566 parent_path, FALSE);
3567 gtk_menu_item_set_submenu (GTK_MENU_ITEM (parent), NULL);
3573 gtk_combo_box_menu_rows_reordered (GtkTreeModel *model,
3579 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3581 gtk_combo_box_relayout (combo_box);
3585 gtk_combo_box_menu_row_changed (GtkTreeModel *model,
3590 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3591 GtkComboBoxPrivate *priv = combo_box->priv;
3593 gboolean is_separator;
3595 if (!priv->popup_widget)
3598 item = find_menu_by_path (priv->popup_widget, path, FALSE);
3600 if (priv->row_separator_func)
3601 is_separator = priv->row_separator_func (model, iter,
3602 priv->row_separator_data);
3604 is_separator = FALSE;
3606 if (is_separator != GTK_IS_SEPARATOR_MENU_ITEM (item))
3608 gtk_combo_box_menu_row_deleted (model, path, combo_box);
3609 gtk_combo_box_menu_row_inserted (model, path, iter, combo_box);
3612 if (priv->wrap_width &&
3613 gtk_widget_get_parent (item) == priv->popup_widget)
3615 GtkWidget *pitem = NULL;
3618 prev = gtk_tree_path_copy (path);
3620 if (gtk_tree_path_prev (prev))
3621 pitem = find_menu_by_path (priv->popup_widget, prev, FALSE);
3623 gtk_tree_path_free (prev);
3625 /* unattach item so gtk_combo_box_relayout_item() won't spuriously
3627 gtk_container_child_set (GTK_CONTAINER (priv->popup_widget),
3632 "bottom-attach", -1,
3635 gtk_combo_box_relayout_item (combo_box, item, iter, pitem);
3638 gtk_combo_box_update_requested_width (combo_box, path);
3646 gtk_combo_box_list_setup (GtkComboBox *combo_box)
3648 GtkComboBoxPrivate *priv = combo_box->priv;
3649 GtkTreeSelection *sel;
3652 GtkWidget *widget = GTK_WIDGET (combo_box);
3654 priv->button = gtk_toggle_button_new ();
3655 child = gtk_bin_get_child (GTK_BIN (combo_box));
3656 gtk_widget_set_parent (priv->button,
3657 gtk_widget_get_parent (child));
3658 g_signal_connect (priv->button, "button-press-event",
3659 G_CALLBACK (gtk_combo_box_list_button_pressed), combo_box);
3660 g_signal_connect (priv->button, "toggled",
3661 G_CALLBACK (gtk_combo_box_button_toggled), combo_box);
3663 priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
3664 gtk_container_add (GTK_CONTAINER (priv->button), priv->arrow);
3665 priv->separator = NULL;
3666 gtk_widget_show_all (priv->button);
3668 if (priv->cell_view)
3670 style = gtk_widget_get_style (widget);
3671 gtk_cell_view_set_background_color (GTK_CELL_VIEW (priv->cell_view),
3672 &style->base[gtk_widget_get_state (widget)]);
3674 priv->box = gtk_event_box_new ();
3675 gtk_event_box_set_visible_window (GTK_EVENT_BOX (priv->box),
3678 if (priv->has_frame)
3680 priv->cell_view_frame = gtk_frame_new (NULL);
3681 gtk_frame_set_shadow_type (GTK_FRAME (priv->cell_view_frame),
3686 combo_box->priv->cell_view_frame = gtk_event_box_new ();
3687 gtk_event_box_set_visible_window (GTK_EVENT_BOX (combo_box->priv->cell_view_frame),
3691 gtk_widget_set_parent (priv->cell_view_frame,
3692 gtk_widget_get_parent (child));
3693 gtk_container_add (GTK_CONTAINER (priv->cell_view_frame), priv->box);
3694 gtk_widget_show_all (priv->cell_view_frame);
3696 g_signal_connect (priv->box, "button-press-event",
3697 G_CALLBACK (gtk_combo_box_list_button_pressed),
3701 priv->tree_view = gtk_tree_view_new ();
3702 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view));
3703 gtk_tree_selection_set_mode (sel, GTK_SELECTION_BROWSE);
3704 gtk_tree_selection_set_select_function (sel,
3705 gtk_combo_box_list_select_func,
3707 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->tree_view),
3709 gtk_tree_view_set_hover_selection (GTK_TREE_VIEW (priv->tree_view),
3711 if (priv->row_separator_func)
3712 gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (priv->tree_view),
3713 priv->row_separator_func,
3714 priv->row_separator_data,
3717 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->tree_view), priv->model);
3719 priv->column = gtk_tree_view_column_new ();
3720 gtk_tree_view_append_column (GTK_TREE_VIEW (priv->tree_view), priv->column);
3723 gtk_combo_box_sync_cells (combo_box,
3724 GTK_CELL_LAYOUT (priv->column));
3726 if (gtk_tree_row_reference_valid (priv->active_row))
3730 path = gtk_tree_row_reference_get_path (priv->active_row);
3731 gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->tree_view),
3733 gtk_tree_path_free (path);
3736 /* set sample/popup widgets */
3737 gtk_combo_box_set_popup_widget (combo_box, priv->tree_view);
3739 g_signal_connect (priv->tree_view, "key-press-event",
3740 G_CALLBACK (gtk_combo_box_list_key_press),
3742 g_signal_connect (priv->tree_view, "enter-notify-event",
3743 G_CALLBACK (gtk_combo_box_list_enter_notify),
3745 g_signal_connect (priv->tree_view, "row-expanded",
3746 G_CALLBACK (gtk_combo_box_model_row_expanded),
3748 g_signal_connect (priv->tree_view, "row-collapsed",
3749 G_CALLBACK (gtk_combo_box_model_row_expanded),
3751 g_signal_connect (priv->popup_window, "button-press-event",
3752 G_CALLBACK (gtk_combo_box_list_button_pressed),
3754 g_signal_connect (priv->popup_window, "button-release-event",
3755 G_CALLBACK (gtk_combo_box_list_button_released),
3758 gtk_widget_show (priv->tree_view);
3760 gtk_combo_box_update_sensitivity (combo_box);
3764 gtk_combo_box_list_destroy (GtkComboBox *combo_box)
3766 GtkComboBoxPrivate *priv = combo_box->priv;
3768 /* disconnect signals */
3769 g_signal_handlers_disconnect_matched (priv->tree_view,
3770 G_SIGNAL_MATCH_DATA,
3771 0, 0, NULL, NULL, combo_box);
3772 g_signal_handlers_disconnect_matched (priv->button,
3773 G_SIGNAL_MATCH_DATA,
3775 gtk_combo_box_list_button_pressed,
3777 g_signal_handlers_disconnect_matched (priv->popup_window,
3778 G_SIGNAL_MATCH_DATA,
3780 gtk_combo_box_list_button_pressed,
3782 g_signal_handlers_disconnect_matched (priv->popup_window,
3783 G_SIGNAL_MATCH_DATA,
3785 gtk_combo_box_list_button_released,
3788 g_signal_handlers_disconnect_matched (priv->popup_window,
3789 G_SIGNAL_MATCH_DATA,
3791 gtk_combo_box_child_show,
3794 g_signal_handlers_disconnect_matched (priv->popup_window,
3795 G_SIGNAL_MATCH_DATA,
3797 gtk_combo_box_child_hide,
3801 g_signal_handlers_disconnect_matched (priv->box,
3802 G_SIGNAL_MATCH_DATA,
3804 gtk_combo_box_list_button_pressed,
3807 /* destroy things (unparent will kill the latest ref from us)
3808 * last unref on button will destroy the arrow
3810 gtk_widget_unparent (priv->button);
3811 priv->button = NULL;
3814 if (priv->cell_view)
3816 g_object_set (priv->cell_view,
3817 "background-set", FALSE,
3821 if (priv->cell_view_frame)
3823 gtk_widget_unparent (priv->cell_view_frame);
3824 priv->cell_view_frame = NULL;
3828 if (priv->scroll_timer)
3830 g_source_remove (priv->scroll_timer);
3831 priv->scroll_timer = 0;
3834 if (priv->resize_idle_id)
3836 g_source_remove (priv->resize_idle_id);
3837 priv->resize_idle_id = 0;
3840 gtk_widget_destroy (priv->tree_view);
3842 priv->tree_view = NULL;
3843 if (priv->popup_widget)
3845 g_object_unref (priv->popup_widget);
3846 priv->popup_widget = NULL;
3853 gtk_combo_box_list_button_pressed (GtkWidget *widget,
3854 GdkEventButton *event,
3857 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3858 GtkComboBoxPrivate *priv = combo_box->priv;
3860 GtkWidget *ewidget = gtk_get_event_widget ((GdkEvent *)event);
3862 if (ewidget == priv->popup_window)
3865 if ((ewidget != priv->button && ewidget != priv->box) ||
3866 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->button)))
3869 if (priv->focus_on_click &&
3870 !gtk_widget_has_focus (priv->button))
3871 gtk_widget_grab_focus (priv->button);
3873 gtk_combo_box_popup_for_device (combo_box, event->device);
3875 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->button), TRUE);
3877 priv->auto_scroll = FALSE;
3878 if (priv->scroll_timer == 0)
3879 priv->scroll_timer = gdk_threads_add_timeout (SCROLL_TIME,
3880 (GSourceFunc) gtk_combo_box_list_scroll_timeout,
3883 priv->popup_in_progress = TRUE;
3889 gtk_combo_box_list_button_released (GtkWidget *widget,
3890 GdkEventButton *event,
3894 GtkTreePath *path = NULL;
3897 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3898 GtkComboBoxPrivate *priv = combo_box->priv;
3900 gboolean popup_in_progress = FALSE;
3902 GtkWidget *ewidget = gtk_get_event_widget ((GdkEvent *)event);
3904 if (priv->popup_in_progress)
3906 popup_in_progress = TRUE;
3907 priv->popup_in_progress = FALSE;
3910 gtk_tree_view_set_hover_expand (GTK_TREE_VIEW (priv->tree_view),
3912 if (priv->scroll_timer)
3914 g_source_remove (priv->scroll_timer);
3915 priv->scroll_timer = 0;
3918 if (ewidget != priv->tree_view)
3920 if ((ewidget == priv->button ||
3921 ewidget == priv->box) &&
3922 !popup_in_progress &&
3923 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->button)))
3925 gtk_combo_box_popdown (combo_box);
3929 /* released outside treeview */
3930 if (ewidget != priv->button && ewidget != priv->box)
3932 gtk_combo_box_popdown (combo_box);
3940 /* select something cool */
3941 ret = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (priv->tree_view),
3947 return TRUE; /* clicked outside window? */
3949 gtk_tree_model_get_iter (priv->model, &iter, path);
3950 gtk_tree_path_free (path);
3952 gtk_combo_box_popdown (combo_box);
3954 if (tree_column_row_is_sensitive (combo_box, &iter))
3955 gtk_combo_box_set_active_iter (combo_box, &iter);
3961 gtk_combo_box_menu_key_press (GtkWidget *widget,
3965 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3967 if (!gtk_bindings_activate_event (G_OBJECT (widget), event))
3969 /* The menu hasn't managed the
3970 * event, forward it to the combobox
3972 gtk_bindings_activate_event (G_OBJECT (combo_box), event);
3979 gtk_combo_box_list_key_press (GtkWidget *widget,
3983 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3986 if (event->keyval == GDK_KEY_Return || event->keyval == GDK_KEY_ISO_Enter || event->keyval == GDK_KEY_KP_Enter ||
3987 event->keyval == GDK_KEY_space || event->keyval == GDK_KEY_KP_Space)
3989 GtkTreeModel *model = NULL;
3991 gtk_combo_box_popdown (combo_box);
3993 if (combo_box->priv->model)
3995 GtkTreeSelection *sel;
3997 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (combo_box->priv->tree_view));
3999 if (gtk_tree_selection_get_selected (sel, &model, &iter))
4000 gtk_combo_box_set_active_iter (combo_box, &iter);
4006 if (!gtk_bindings_activate_event (G_OBJECT (widget), event))
4008 /* The list hasn't managed the
4009 * event, forward it to the combobox
4011 gtk_bindings_activate_event (G_OBJECT (combo_box), event);
4018 gtk_combo_box_list_auto_scroll (GtkComboBox *combo_box,
4023 GtkAllocation allocation;
4024 GtkWidget *tree_view = combo_box->priv->tree_view;
4027 gtk_widget_get_allocation (tree_view, &allocation);
4029 adj = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (combo_box->priv->scrolled_window));
4030 if (adj && adj->upper - adj->lower > adj->page_size)
4032 if (x <= allocation.x &&
4033 adj->lower < adj->value)
4035 value = adj->value - (allocation.x - x + 1);
4036 gtk_adjustment_set_value (adj, value);
4038 else if (x >= allocation.x + allocation.width &&
4039 adj->upper - adj->page_size > adj->value)
4041 value = adj->value + (x - allocation.x - allocation.width + 1);
4042 gtk_adjustment_set_value (adj, MAX (value, 0.0));
4046 adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (combo_box->priv->scrolled_window));
4047 if (adj && adj->upper - adj->lower > adj->page_size)
4049 if (y <= allocation.y &&
4050 adj->lower < adj->value)
4052 value = adj->value - (allocation.y - y + 1);
4053 gtk_adjustment_set_value (adj, value);
4055 else if (y >= allocation.height &&
4056 adj->upper - adj->page_size > adj->value)
4058 value = adj->value + (y - allocation.height + 1);
4059 gtk_adjustment_set_value (adj, MAX (value, 0.0));
4065 gtk_combo_box_list_scroll_timeout (GtkComboBox *combo_box)
4067 GtkComboBoxPrivate *priv = combo_box->priv;
4070 if (priv->auto_scroll)
4072 gdk_window_get_device_position (gtk_widget_get_window (priv->tree_view),
4075 gtk_combo_box_list_auto_scroll (combo_box, x, y);
4082 gtk_combo_box_list_enter_notify (GtkWidget *widget,
4083 GdkEventCrossing *event,
4086 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
4088 combo_box->priv->auto_scroll = TRUE;
4094 gtk_combo_box_list_select_func (GtkTreeSelection *selection,
4095 GtkTreeModel *model,
4097 gboolean path_currently_selected,
4101 gboolean sensitive = FALSE;
4103 for (list = selection->tree_view->priv->columns; list && !sensitive; list = list->next)
4105 GList *cells, *cell;
4106 gboolean cell_sensitive, cell_visible;
4108 GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN (list->data);
4110 if (!column->visible)
4113 gtk_tree_model_get_iter (model, &iter, path);
4114 gtk_tree_view_column_cell_set_cell_data (column, model, &iter,
4117 cell = cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (column));
4120 g_object_get (cell->data,
4121 "sensitive", &cell_sensitive,
4122 "visible", &cell_visible,
4125 if (cell_visible && cell_sensitive)
4130 g_list_free (cells);
4132 sensitive = cell_sensitive;
4139 gtk_combo_box_list_row_changed (GtkTreeModel *model,
4144 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
4146 gtk_combo_box_update_requested_width (combo_box, path);
4150 * GtkCellLayout implementation
4154 pack_start_recurse (GtkWidget *menu,
4155 GtkCellRenderer *cell,
4162 list = gtk_container_get_children (GTK_CONTAINER (menu));
4163 for (i = list; i; i = i->next)
4165 child = gtk_bin_get_child (GTK_BIN (i->data));
4166 if (GTK_IS_CELL_LAYOUT (child))
4167 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (child),
4170 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4171 if (submenu != NULL)
4172 pack_start_recurse (submenu, cell, expand);
4179 gtk_combo_box_cell_layout_pack_start (GtkCellLayout *layout,
4180 GtkCellRenderer *cell,
4183 GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
4184 ComboCellInfo *info;
4185 GtkComboBoxPrivate *priv;
4187 priv = combo_box->priv;
4189 g_object_ref_sink (cell);
4191 info = g_slice_new0 (ComboCellInfo);
4193 info->expand = expand;
4194 info->pack = GTK_PACK_START;
4196 priv->cells = g_slist_append (priv->cells, info);
4198 if (priv->cell_view)
4200 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (priv->cell_view),
4206 gtk_tree_view_column_pack_start (priv->column, cell, expand);
4208 if (GTK_IS_MENU (priv->popup_widget))
4209 pack_start_recurse (priv->popup_widget, cell, expand);
4213 pack_end_recurse (GtkWidget *menu,
4214 GtkCellRenderer *cell,
4221 list = gtk_container_get_children (GTK_CONTAINER (menu));
4222 for (i = list; i; i = i->next)
4224 child = gtk_bin_get_child (GTK_BIN (i->data));
4225 if (GTK_IS_CELL_LAYOUT (child))
4226 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (child),
4229 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4230 if (submenu != NULL)
4231 pack_end_recurse (submenu, cell, expand);
4238 gtk_combo_box_cell_layout_pack_end (GtkCellLayout *layout,
4239 GtkCellRenderer *cell,
4242 GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
4243 ComboCellInfo *info;
4244 GtkComboBoxPrivate *priv;
4246 priv = combo_box->priv;
4248 g_object_ref_sink (cell);
4250 info = g_slice_new0 (ComboCellInfo);
4252 info->expand = expand;
4253 info->pack = GTK_PACK_END;
4255 priv->cells = g_slist_append (priv->cells, info);
4257 if (priv->cell_view)
4258 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (priv->cell_view),
4262 gtk_tree_view_column_pack_end (priv->column, cell, expand);
4264 if (GTK_IS_MENU (priv->popup_widget))
4265 pack_end_recurse (priv->popup_widget, cell, expand);
4269 gtk_combo_box_cell_layout_get_cells (GtkCellLayout *layout)
4271 GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
4273 GList *retval = NULL;
4275 for (list = combo_box->priv->cells; list; list = list->next)
4277 ComboCellInfo *info = (ComboCellInfo *)list->data;
4279 retval = g_list_prepend (retval, info->cell);
4282 return g_list_reverse (retval);
4286 clear_recurse (GtkWidget *menu)
4292 list = gtk_container_get_children (GTK_CONTAINER (menu));
4293 for (i = list; i; i = i->next)
4295 child = gtk_bin_get_child (GTK_BIN (i->data));
4296 if (GTK_IS_CELL_LAYOUT (child))
4297 gtk_cell_layout_clear (GTK_CELL_LAYOUT (child));
4299 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4300 if (submenu != NULL)
4301 clear_recurse (submenu);
4308 gtk_combo_box_cell_layout_clear (GtkCellLayout *layout)
4310 GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
4311 GtkComboBoxPrivate *priv = combo_box->priv;
4314 if (priv->cell_view)
4315 gtk_cell_layout_clear (GTK_CELL_LAYOUT (priv->cell_view));
4318 gtk_tree_view_column_clear (priv->column);
4320 for (i = priv->cells; i; i = i->next)
4322 ComboCellInfo *info = (ComboCellInfo *)i->data;
4324 gtk_combo_box_cell_layout_clear_attributes (layout, info->cell);
4325 g_object_unref (info->cell);
4326 g_slice_free (ComboCellInfo, info);
4329 g_slist_free (priv->cells);
4332 if (GTK_IS_MENU (priv->popup_widget))
4333 clear_recurse (priv->popup_widget);
4337 add_attribute_recurse (GtkWidget *menu,
4338 GtkCellRenderer *cell,
4339 const gchar *attribute,
4346 list = gtk_container_get_children (GTK_CONTAINER (menu));
4347 for (i = list; i; i = i->next)
4349 child = gtk_bin_get_child (GTK_BIN (i->data));
4350 if (GTK_IS_CELL_LAYOUT (child))
4351 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (child),
4352 cell, attribute, column);
4354 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4355 if (submenu != NULL)
4356 add_attribute_recurse (submenu, cell, attribute, column);
4363 gtk_combo_box_cell_layout_add_attribute (GtkCellLayout *layout,
4364 GtkCellRenderer *cell,
4365 const gchar *attribute,
4368 GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
4369 ComboCellInfo *info;
4371 info = gtk_combo_box_get_cell_info (combo_box, cell);
4372 g_return_if_fail (info != NULL);
4374 info->attributes = g_slist_prepend (info->attributes,
4375 GINT_TO_POINTER (column));
4376 info->attributes = g_slist_prepend (info->attributes,
4377 g_strdup (attribute));
4379 if (combo_box->priv->cell_view)
4380 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo_box->priv->cell_view),
4381 cell, attribute, column);
4383 if (combo_box->priv->column)
4384 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo_box->priv->column),
4385 cell, attribute, column);
4387 if (GTK_IS_MENU (combo_box->priv->popup_widget))
4388 add_attribute_recurse (combo_box->priv->popup_widget, cell, attribute, column);
4389 gtk_widget_queue_resize (GTK_WIDGET (combo_box));
4393 combo_cell_data_func (GtkCellLayout *cell_layout,
4394 GtkCellRenderer *cell,
4395 GtkTreeModel *tree_model,
4399 ComboCellInfo *info = (ComboCellInfo *)data;
4400 GtkWidget *parent = NULL;
4405 info->func (cell_layout, cell, tree_model, iter, info->func_data);
4407 if (GTK_IS_WIDGET (cell_layout))
4408 parent = gtk_widget_get_parent (GTK_WIDGET (cell_layout));
4410 if (GTK_IS_MENU_ITEM (parent) &&
4411 gtk_menu_item_get_submenu (GTK_MENU_ITEM (parent)))
4412 g_object_set (cell, "sensitive", TRUE, NULL);
4417 set_cell_data_func_recurse (GtkWidget *menu,
4418 GtkCellRenderer *cell,
4419 ComboCellInfo *info)
4423 GtkWidget *cell_view;
4425 list = gtk_container_get_children (GTK_CONTAINER (menu));
4426 for (i = list; i; i = i->next)
4428 cell_view = gtk_bin_get_child (GTK_BIN (i->data));
4429 if (GTK_IS_CELL_LAYOUT (cell_view))
4431 /* Override sensitivity for inner nodes; we don't
4432 * want menuitems with submenus to appear insensitive
4434 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (cell_view),
4436 combo_cell_data_func,
4438 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4439 if (submenu != NULL)
4440 set_cell_data_func_recurse (submenu, cell, info);
4448 gtk_combo_box_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4449 GtkCellRenderer *cell,
4450 GtkCellLayoutDataFunc func,
4452 GDestroyNotify destroy)
4454 GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
4455 GtkComboBoxPrivate *priv = combo_box->priv;
4456 ComboCellInfo *info;
4458 info = gtk_combo_box_get_cell_info (combo_box, cell);
4459 g_return_if_fail (info != NULL);
4463 GDestroyNotify d = info->destroy;
4465 info->destroy = NULL;
4466 d (info->func_data);
4470 info->func_data = func_data;
4471 info->destroy = destroy;
4473 if (priv->cell_view)
4474 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (priv->cell_view), cell, func, func_data, NULL);
4477 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (priv->column), cell, func, func_data, NULL);
4479 if (GTK_IS_MENU (priv->popup_widget))
4480 set_cell_data_func_recurse (priv->popup_widget, cell, info);
4482 gtk_widget_queue_resize (GTK_WIDGET (combo_box));
4486 clear_attributes_recurse (GtkWidget *menu,
4487 GtkCellRenderer *cell)
4493 list = gtk_container_get_children (GTK_CONTAINER (menu));
4494 for (i = list; i; i = i->next)
4496 child = gtk_bin_get_child (GTK_BIN (i->data));
4497 if (GTK_IS_CELL_LAYOUT (child))
4498 gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (child), cell);
4500 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4501 if (submenu != NULL)
4502 clear_attributes_recurse (submenu, cell);
4509 gtk_combo_box_cell_layout_clear_attributes (GtkCellLayout *layout,
4510 GtkCellRenderer *cell)
4512 GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
4513 GtkComboBoxPrivate *priv;
4514 ComboCellInfo *info;
4517 priv = combo_box->priv;
4519 info = gtk_combo_box_get_cell_info (combo_box, cell);
4520 g_return_if_fail (info != NULL);
4522 list = info->attributes;
4523 while (list && list->next)
4525 g_free (list->data);
4526 list = list->next->next;
4528 g_slist_free (info->attributes);
4529 info->attributes = NULL;
4531 if (priv->cell_view)
4532 gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (priv->cell_view), cell);
4535 gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (priv->column), cell);
4537 if (GTK_IS_MENU (priv->popup_widget))
4538 clear_attributes_recurse (priv->popup_widget, cell);
4540 gtk_widget_queue_resize (GTK_WIDGET (combo_box));
4544 reorder_recurse (GtkWidget *menu,
4545 GtkCellRenderer *cell,
4552 list = gtk_container_get_children (GTK_CONTAINER (menu));
4553 for (i = list; i; i = i->next)
4555 child = gtk_bin_get_child (GTK_BIN (i->data));
4556 if (GTK_IS_CELL_LAYOUT (child))
4557 gtk_cell_layout_reorder (GTK_CELL_LAYOUT (child),
4560 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4561 if (submenu != NULL)
4562 reorder_recurse (submenu, cell, position);
4569 gtk_combo_box_cell_layout_reorder (GtkCellLayout *layout,
4570 GtkCellRenderer *cell,
4573 GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
4574 GtkComboBoxPrivate *priv;
4575 ComboCellInfo *info;
4578 priv = combo_box->priv;
4580 info = gtk_combo_box_get_cell_info (combo_box, cell);
4582 g_return_if_fail (info != NULL);
4583 g_return_if_fail (position >= 0);
4585 link = g_slist_find (priv->cells, info);
4587 g_return_if_fail (link != NULL);
4589 priv->cells = g_slist_delete_link (priv->cells, link);
4590 priv->cells = g_slist_insert (priv->cells, info, position);
4592 if (priv->cell_view)
4593 gtk_cell_layout_reorder (GTK_CELL_LAYOUT (priv->cell_view),
4597 gtk_cell_layout_reorder (GTK_CELL_LAYOUT (priv->column),
4600 if (GTK_IS_MENU (priv->popup_widget))
4601 reorder_recurse (priv->popup_widget, cell, position);
4603 gtk_widget_queue_draw (GTK_WIDGET (combo_box));
4611 * gtk_combo_box_new:
4613 * Creates a new empty #GtkComboBox.
4615 * Return value: A new #GtkComboBox.
4620 gtk_combo_box_new (void)
4622 return g_object_new (GTK_TYPE_COMBO_BOX, NULL);
4626 * gtk_combo_box_new_with_model:
4627 * @model: A #GtkTreeModel.
4629 * Creates a new #GtkComboBox with the model initialized to @model.
4631 * Return value: A new #GtkComboBox.
4636 gtk_combo_box_new_with_model (GtkTreeModel *model)
4638 GtkComboBox *combo_box;
4640 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
4642 combo_box = g_object_new (GTK_TYPE_COMBO_BOX, "model", model, NULL);
4644 return GTK_WIDGET (combo_box);
4648 * gtk_combo_box_get_wrap_width:
4649 * @combo_box: A #GtkComboBox
4651 * Returns the wrap width which is used to determine the number of columns
4652 * for the popup menu. If the wrap width is larger than 1, the combo box
4655 * Returns: the wrap width.
4660 gtk_combo_box_get_wrap_width (GtkComboBox *combo_box)
4662 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), -1);
4664 return combo_box->priv->wrap_width;
4668 * gtk_combo_box_set_wrap_width:
4669 * @combo_box: A #GtkComboBox
4670 * @width: Preferred number of columns
4672 * Sets the wrap width of @combo_box to be @width. The wrap width is basically
4673 * the preferred number of columns when you want the popup to be layed out
4679 gtk_combo_box_set_wrap_width (GtkComboBox *combo_box,
4682 GtkComboBoxPrivate *priv;
4684 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4685 g_return_if_fail (width >= 0);
4687 priv = combo_box->priv;
4689 if (width != priv->wrap_width)
4691 priv->wrap_width = width;
4693 gtk_combo_box_check_appearance (combo_box);
4694 gtk_combo_box_relayout (combo_box);
4696 g_object_notify (G_OBJECT (combo_box), "wrap-width");
4701 * gtk_combo_box_get_row_span_column:
4702 * @combo_box: A #GtkComboBox
4704 * Returns the column with row span information for @combo_box.
4706 * Returns: the row span column.
4711 gtk_combo_box_get_row_span_column (GtkComboBox *combo_box)
4713 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), -1);
4715 return combo_box->priv->row_column;
4719 * gtk_combo_box_set_row_span_column:
4720 * @combo_box: A #GtkComboBox.
4721 * @row_span: A column in the model passed during construction.
4723 * Sets the column with row span information for @combo_box to be @row_span.
4724 * The row span column contains integers which indicate how many rows
4725 * an item should span.
4730 gtk_combo_box_set_row_span_column (GtkComboBox *combo_box,
4733 GtkComboBoxPrivate *priv;
4736 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4738 priv = combo_box->priv;
4740 col = gtk_tree_model_get_n_columns (priv->model);
4741 g_return_if_fail (row_span >= -1 && row_span < col);
4743 if (row_span != priv->row_column)
4745 priv->row_column = row_span;
4747 gtk_combo_box_relayout (combo_box);
4749 g_object_notify (G_OBJECT (combo_box), "row-span-column");
4754 * gtk_combo_box_get_column_span_column:
4755 * @combo_box: A #GtkComboBox
4757 * Returns the column with column span information for @combo_box.
4759 * Returns: the column span column.
4764 gtk_combo_box_get_column_span_column (GtkComboBox *combo_box)
4766 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), -1);
4768 return combo_box->priv->col_column;
4772 * gtk_combo_box_set_column_span_column:
4773 * @combo_box: A #GtkComboBox
4774 * @column_span: A column in the model passed during construction
4776 * Sets the column with column span information for @combo_box to be
4777 * @column_span. The column span column contains integers which indicate
4778 * how many columns an item should span.
4783 gtk_combo_box_set_column_span_column (GtkComboBox *combo_box,
4786 GtkComboBoxPrivate *priv;
4789 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4791 priv = combo_box->priv;
4793 col = gtk_tree_model_get_n_columns (priv->model);
4794 g_return_if_fail (column_span >= -1 && column_span < col);
4796 if (column_span != priv->col_column)
4798 priv->col_column = column_span;
4800 gtk_combo_box_relayout (combo_box);
4802 g_object_notify (G_OBJECT (combo_box), "column-span-column");
4807 * gtk_combo_box_get_active:
4808 * @combo_box: A #GtkComboBox
4810 * Returns the index of the currently active item, or -1 if there's no
4811 * active item. If the model is a non-flat treemodel, and the active item
4812 * is not an immediate child of the root of the tree, this function returns
4813 * <literal>gtk_tree_path_get_indices (path)[0]</literal>, where
4814 * <literal>path</literal> is the #GtkTreePath of the active item.
4816 * Return value: An integer which is the index of the currently active item,
4817 * or -1 if there's no active item.
4822 gtk_combo_box_get_active (GtkComboBox *combo_box)
4824 GtkComboBoxPrivate *priv;
4827 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), 0);
4829 priv = combo_box->priv;
4831 if (gtk_tree_row_reference_valid (priv->active_row))
4835 path = gtk_tree_row_reference_get_path (priv->active_row);
4836 result = gtk_tree_path_get_indices (path)[0];
4837 gtk_tree_path_free (path);
4846 * gtk_combo_box_set_active:
4847 * @combo_box: A #GtkComboBox
4848 * @index_: An index in the model passed during construction, or -1 to have
4851 * Sets the active item of @combo_box to be the item at @index.
4856 gtk_combo_box_set_active (GtkComboBox *combo_box,
4859 GtkTreePath *path = NULL;
4860 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4861 g_return_if_fail (index_ >= -1);
4863 if (combo_box->priv->model == NULL)
4865 /* Save index, in case the model is set after the index */
4866 combo_box->priv->active = index_;
4872 path = gtk_tree_path_new_from_indices (index_, -1);
4874 gtk_combo_box_set_active_internal (combo_box, path);
4877 gtk_tree_path_free (path);
4881 gtk_combo_box_set_active_internal (GtkComboBox *combo_box,
4884 GtkComboBoxPrivate *priv = combo_box->priv;
4885 GtkTreePath *active_path;
4888 /* Remember whether the initially active row is valid. */
4889 gboolean is_valid_row_reference = gtk_tree_row_reference_valid (priv->active_row);
4891 if (path && is_valid_row_reference)
4893 active_path = gtk_tree_row_reference_get_path (priv->active_row);
4894 path_cmp = gtk_tree_path_compare (path, active_path);
4895 gtk_tree_path_free (active_path);
4900 if (priv->active_row)
4902 gtk_tree_row_reference_free (priv->active_row);
4903 priv->active_row = NULL;
4908 if (priv->tree_view)
4909 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view)));
4912 GtkMenu *menu = GTK_MENU (priv->popup_widget);
4914 if (GTK_IS_MENU (menu))
4915 gtk_menu_set_active (menu, -1);
4918 if (priv->cell_view)
4919 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (priv->cell_view), NULL);
4922 * Do not emit a "changed" signal when an already invalid selection was
4923 * now set to invalid.
4925 if (!is_valid_row_reference)
4931 gtk_tree_row_reference_new (priv->model, path);
4933 if (priv->tree_view)
4935 gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->tree_view),
4938 else if (GTK_IS_MENU (priv->popup_widget))
4940 /* FIXME handle nested menus better */
4941 gtk_menu_set_active (GTK_MENU (priv->popup_widget),
4942 gtk_tree_path_get_indices (path)[0]);
4945 if (priv->cell_view)
4946 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (priv->cell_view),
4950 g_signal_emit (combo_box, combo_box_signals[CHANGED], 0);
4951 g_object_notify (G_OBJECT (combo_box), "active");
4956 * gtk_combo_box_get_active_iter:
4957 * @combo_box: A #GtkComboBox
4958 * @iter: (out): The uninitialized #GtkTreeIter
4960 * Sets @iter to point to the current active item, if it exists.
4962 * Return value: %TRUE, if @iter was set
4967 gtk_combo_box_get_active_iter (GtkComboBox *combo_box,
4973 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE);
4975 if (!gtk_tree_row_reference_valid (combo_box->priv->active_row))
4978 path = gtk_tree_row_reference_get_path (combo_box->priv->active_row);
4979 result = gtk_tree_model_get_iter (combo_box->priv->model, iter, path);
4980 gtk_tree_path_free (path);
4986 * gtk_combo_box_set_active_iter:
4987 * @combo_box: A #GtkComboBox
4988 * @iter: (allow-none): The #GtkTreeIter, or %NULL
4990 * Sets the current active item to be the one referenced by @iter, or
4991 * unsets the active item if @iter is %NULL.
4996 gtk_combo_box_set_active_iter (GtkComboBox *combo_box,
4999 GtkTreePath *path = NULL;
5001 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5004 path = gtk_tree_model_get_path (gtk_combo_box_get_model (combo_box), iter);
5006 gtk_combo_box_set_active_internal (combo_box, path);
5007 gtk_tree_path_free (path);
5011 * gtk_combo_box_set_model:
5012 * @combo_box: A #GtkComboBox
5013 * @model: (allow-none): A #GtkTreeModel
5015 * Sets the model used by @combo_box to be @model. Will unset a previously set
5016 * model (if applicable). If model is %NULL, then it will unset the model.
5018 * Note that this function does not clear the cell renderers, you have to
5019 * call gtk_cell_layout_clear() yourself if you need to set up different
5020 * cell renderers for the new model.
5025 gtk_combo_box_set_model (GtkComboBox *combo_box,
5026 GtkTreeModel *model)
5028 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5029 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
5031 if (model == combo_box->priv->model)
5034 gtk_combo_box_unset_model (combo_box);
5039 combo_box->priv->model = model;
5040 g_object_ref (combo_box->priv->model);
5042 combo_box->priv->inserted_id =
5043 g_signal_connect (combo_box->priv->model, "row-inserted",
5044 G_CALLBACK (gtk_combo_box_model_row_inserted),
5046 combo_box->priv->deleted_id =
5047 g_signal_connect (combo_box->priv->model, "row-deleted",
5048 G_CALLBACK (gtk_combo_box_model_row_deleted),
5050 combo_box->priv->reordered_id =
5051 g_signal_connect (combo_box->priv->model, "rows-reordered",
5052 G_CALLBACK (gtk_combo_box_model_rows_reordered),
5054 combo_box->priv->changed_id =
5055 g_signal_connect (combo_box->priv->model, "row-changed",
5056 G_CALLBACK (gtk_combo_box_model_row_changed),
5059 if (combo_box->priv->tree_view)
5062 gtk_tree_view_set_model (GTK_TREE_VIEW (combo_box->priv->tree_view),
5063 combo_box->priv->model);
5064 gtk_combo_box_list_popup_resize (combo_box);
5069 if (combo_box->priv->popup_widget)
5070 gtk_combo_box_menu_fill (combo_box);
5074 if (combo_box->priv->cell_view)
5075 gtk_cell_view_set_model (GTK_CELL_VIEW (combo_box->priv->cell_view),
5076 combo_box->priv->model);
5078 if (combo_box->priv->active != -1)
5080 /* If an index was set in advance, apply it now */
5081 gtk_combo_box_set_active (combo_box, combo_box->priv->active);
5082 combo_box->priv->active = -1;
5086 gtk_combo_box_update_sensitivity (combo_box);
5088 g_object_notify (G_OBJECT (combo_box), "model");
5092 * gtk_combo_box_get_model:
5093 * @combo_box: A #GtkComboBox
5095 * Returns the #GtkTreeModel which is acting as data source for @combo_box.
5097 * Return value: (transfer none): A #GtkTreeModel which was passed
5098 * during construction.
5103 gtk_combo_box_get_model (GtkComboBox *combo_box)
5105 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
5107 return combo_box->priv->model;
5111 /* convenience API for simple text combos */
5114 * gtk_combo_box_new_text:
5116 * Convenience function which constructs a new text combo box, which is a
5117 * #GtkComboBox just displaying strings. If you use this function to create
5118 * a text combo box, you should only manipulate its data source with the
5119 * following convenience functions: gtk_combo_box_append_text(),
5120 * gtk_combo_box_insert_text(), gtk_combo_box_prepend_text() and
5121 * gtk_combo_box_remove_text().
5123 * Return value: (transfer none): A new text combo box.
5128 gtk_combo_box_new_text (void)
5130 GtkWidget *combo_box;
5131 GtkCellRenderer *cell;
5132 GtkListStore *store;
5134 store = gtk_list_store_new (1, G_TYPE_STRING);
5135 combo_box = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));
5136 g_object_unref (store);
5138 cell = gtk_cell_renderer_text_new ();
5139 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), cell, TRUE);
5140 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), cell,
5148 * gtk_combo_box_append_text:
5149 * @combo_box: A #GtkComboBox constructed using gtk_combo_box_new_text()
5152 * Appends @string to the list of strings stored in @combo_box. Note that
5153 * you can only use this function with combo boxes constructed with
5154 * gtk_combo_box_new_text().
5159 gtk_combo_box_append_text (GtkComboBox *combo_box,
5163 GtkListStore *store;
5165 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5166 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
5167 g_return_if_fail (gtk_tree_model_get_column_type (combo_box->priv->model, 0)
5169 g_return_if_fail (text != NULL);
5171 store = GTK_LIST_STORE (combo_box->priv->model);
5173 gtk_list_store_append (store, &iter);
5174 gtk_list_store_set (store, &iter, 0, text, -1);
5178 * gtk_combo_box_insert_text:
5179 * @combo_box: A #GtkComboBox constructed using gtk_combo_box_new_text()
5180 * @position: An index to insert @text
5183 * Inserts @string at @position in the list of strings stored in @combo_box.
5184 * Note that you can only use this function with combo boxes constructed
5185 * with gtk_combo_box_new_text().
5190 gtk_combo_box_insert_text (GtkComboBox *combo_box,
5195 GtkListStore *store;
5197 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5198 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
5199 g_return_if_fail (position >= 0);
5200 g_return_if_fail (gtk_tree_model_get_column_type (combo_box->priv->model, 0)
5202 g_return_if_fail (text != NULL);
5204 store = GTK_LIST_STORE (combo_box->priv->model);
5206 gtk_list_store_insert (store, &iter, position);
5207 gtk_list_store_set (store, &iter, 0, text, -1);
5211 * gtk_combo_box_prepend_text:
5212 * @combo_box: A #GtkComboBox constructed with gtk_combo_box_new_text()
5215 * Prepends @string to the list of strings stored in @combo_box. Note that
5216 * you can only use this function with combo boxes constructed with
5217 * gtk_combo_box_new_text().
5222 gtk_combo_box_prepend_text (GtkComboBox *combo_box,
5226 GtkListStore *store;
5228 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5229 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
5230 g_return_if_fail (gtk_tree_model_get_column_type (combo_box->priv->model, 0)
5232 g_return_if_fail (text != NULL);
5234 store = GTK_LIST_STORE (combo_box->priv->model);
5236 gtk_list_store_prepend (store, &iter);
5237 gtk_list_store_set (store, &iter, 0, text, -1);
5241 * gtk_combo_box_remove_text:
5242 * @combo_box: A #GtkComboBox constructed with gtk_combo_box_new_text()
5243 * @position: Index of the item to remove
5245 * Removes the string at @position from @combo_box. Note that you can only use
5246 * this function with combo boxes constructed with gtk_combo_box_new_text().
5251 gtk_combo_box_remove_text (GtkComboBox *combo_box,
5255 GtkListStore *store;
5257 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5258 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
5259 g_return_if_fail (gtk_tree_model_get_column_type (combo_box->priv->model, 0)
5261 g_return_if_fail (position >= 0);
5263 store = GTK_LIST_STORE (combo_box->priv->model);
5265 if (gtk_tree_model_iter_nth_child (combo_box->priv->model, &iter,
5267 gtk_list_store_remove (store, &iter);
5271 * gtk_combo_box_get_active_text:
5272 * @combo_box: A #GtkComboBox constructed with gtk_combo_box_new_text()
5274 * Returns the currently active string in @combo_box or %NULL if none
5275 * is selected. Note that you can only use this function with combo
5276 * boxes constructed with gtk_combo_box_new_text() and with
5277 * #GtkComboBoxEntry<!-- -->s.
5279 * Returns: a newly allocated string containing the currently active text.
5280 * Must be freed with g_free().
5285 gtk_combo_box_get_active_text (GtkComboBox *combo_box)
5287 GtkComboBoxClass *class;
5289 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
5291 class = GTK_COMBO_BOX_GET_CLASS (combo_box);
5293 if (class->get_active_text)
5294 return class->get_active_text (combo_box);
5300 gtk_combo_box_real_get_active_text (GtkComboBox *combo_box)
5305 g_return_val_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model), NULL);
5306 g_return_val_if_fail (gtk_tree_model_get_column_type (combo_box->priv->model, 0)
5307 == G_TYPE_STRING, NULL);
5309 if (gtk_combo_box_get_active_iter (combo_box, &iter))
5310 gtk_tree_model_get (combo_box->priv->model, &iter,
5317 gtk_combo_box_real_move_active (GtkComboBox *combo_box,
5318 GtkScrollType scroll)
5321 GtkTreeIter new_iter;
5322 gboolean active_iter;
5325 if (!combo_box->priv->model)
5327 gtk_widget_error_bell (GTK_WIDGET (combo_box));
5331 active_iter = gtk_combo_box_get_active_iter (combo_box, &iter);
5335 case GTK_SCROLL_STEP_BACKWARD:
5336 case GTK_SCROLL_STEP_UP:
5337 case GTK_SCROLL_STEP_LEFT:
5340 found = tree_prev (combo_box, combo_box->priv->model,
5341 &iter, &new_iter, FALSE);
5344 /* else fall through */
5346 case GTK_SCROLL_PAGE_FORWARD:
5347 case GTK_SCROLL_PAGE_DOWN:
5348 case GTK_SCROLL_PAGE_RIGHT:
5349 case GTK_SCROLL_END:
5350 found = tree_last (combo_box, combo_box->priv->model, &new_iter, FALSE);
5353 case GTK_SCROLL_STEP_FORWARD:
5354 case GTK_SCROLL_STEP_DOWN:
5355 case GTK_SCROLL_STEP_RIGHT:
5358 found = tree_next (combo_box, combo_box->priv->model,
5359 &iter, &new_iter, FALSE);
5362 /* else fall through */
5364 case GTK_SCROLL_PAGE_BACKWARD:
5365 case GTK_SCROLL_PAGE_UP:
5366 case GTK_SCROLL_PAGE_LEFT:
5367 case GTK_SCROLL_START:
5368 found = tree_first (combo_box, combo_box->priv->model, &new_iter, FALSE);
5375 if (found && active_iter)
5377 GtkTreePath *old_path;
5378 GtkTreePath *new_path;
5380 old_path = gtk_tree_model_get_path (combo_box->priv->model, &iter);
5381 new_path = gtk_tree_model_get_path (combo_box->priv->model, &new_iter);
5383 if (gtk_tree_path_compare (old_path, new_path) == 0)
5386 gtk_tree_path_free (old_path);
5387 gtk_tree_path_free (new_path);
5392 gtk_combo_box_set_active_iter (combo_box, &new_iter);
5396 gtk_widget_error_bell (GTK_WIDGET (combo_box));
5401 gtk_combo_box_mnemonic_activate (GtkWidget *widget,
5402 gboolean group_cycling)
5404 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
5406 gtk_widget_grab_focus (combo_box->priv->button);
5412 gtk_combo_box_grab_focus (GtkWidget *widget)
5414 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
5416 gtk_widget_grab_focus (combo_box->priv->button);
5420 gtk_combo_box_destroy (GtkWidget *widget)
5422 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
5424 if (combo_box->priv->popup_idle_id > 0)
5426 g_source_remove (combo_box->priv->popup_idle_id);
5427 combo_box->priv->popup_idle_id = 0;
5430 gtk_combo_box_popdown (combo_box);
5432 if (combo_box->priv->row_separator_destroy)
5433 combo_box->priv->row_separator_destroy (combo_box->priv->row_separator_data);
5435 combo_box->priv->row_separator_func = NULL;
5436 combo_box->priv->row_separator_data = NULL;
5437 combo_box->priv->row_separator_destroy = NULL;
5439 GTK_WIDGET_CLASS (gtk_combo_box_parent_class)->destroy (widget);
5440 combo_box->priv->cell_view = NULL;
5444 gtk_combo_box_dispose(GObject* object)
5446 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
5448 if (GTK_IS_MENU (combo_box->priv->popup_widget))
5450 gtk_combo_box_menu_destroy (combo_box);
5451 gtk_menu_detach (GTK_MENU (combo_box->priv->popup_widget));
5452 combo_box->priv->popup_widget = NULL;
5455 G_OBJECT_CLASS (gtk_combo_box_parent_class)->dispose (object);
5459 gtk_combo_box_finalize (GObject *object)
5461 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
5464 if (GTK_IS_TREE_VIEW (combo_box->priv->tree_view))
5465 gtk_combo_box_list_destroy (combo_box);
5467 if (combo_box->priv->popup_window)
5468 gtk_widget_destroy (combo_box->priv->popup_window);
5470 gtk_combo_box_unset_model (combo_box);
5472 for (i = combo_box->priv->cells; i; i = i->next)
5474 ComboCellInfo *info = (ComboCellInfo *)i->data;
5475 GSList *list = info->attributes;
5478 info->destroy (info->func_data);
5480 while (list && list->next)
5482 g_free (list->data);
5483 list = list->next->next;
5485 g_slist_free (info->attributes);
5487 g_object_unref (info->cell);
5488 g_slice_free (ComboCellInfo, info);
5490 g_slist_free (combo_box->priv->cells);
5492 g_free (combo_box->priv->tearoff_title);
5494 G_OBJECT_CLASS (gtk_combo_box_parent_class)->finalize (object);
5498 gtk_cell_editable_key_press (GtkWidget *widget,
5502 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
5504 if (event->keyval == GDK_KEY_Escape)
5506 g_object_set (combo_box,
5507 "editing-canceled", TRUE,
5509 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (combo_box));
5510 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (combo_box));
5514 else if (event->keyval == GDK_KEY_Return ||
5515 event->keyval == GDK_KEY_ISO_Enter ||
5516 event->keyval == GDK_KEY_KP_Enter)
5518 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (combo_box));
5519 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (combo_box));
5528 popdown_idle (gpointer data)
5530 GtkComboBox *combo_box;
5532 combo_box = GTK_COMBO_BOX (data);
5534 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (combo_box));
5535 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (combo_box));
5537 g_object_unref (combo_box);
5543 popdown_handler (GtkWidget *widget,
5546 gdk_threads_add_idle (popdown_idle, g_object_ref (data));
5550 popup_idle (gpointer data)
5552 GtkComboBox *combo_box;
5554 combo_box = GTK_COMBO_BOX (data);
5556 if (GTK_IS_MENU (combo_box->priv->popup_widget) &&
5557 combo_box->priv->cell_view)
5558 g_signal_connect_object (combo_box->priv->popup_widget,
5559 "unmap", G_CALLBACK (popdown_handler),
5562 /* we unset this if a menu item is activated */
5563 g_object_set (combo_box,
5564 "editing-canceled", TRUE,
5566 gtk_combo_box_popup (combo_box);
5568 combo_box->priv->popup_idle_id = 0;
5569 combo_box->priv->activate_button = 0;
5570 combo_box->priv->activate_time = 0;
5576 gtk_combo_box_start_editing (GtkCellEditable *cell_editable,
5579 GtkComboBox *combo_box = GTK_COMBO_BOX (cell_editable);
5582 combo_box->priv->is_cell_renderer = TRUE;
5584 if (combo_box->priv->cell_view)
5586 g_signal_connect_object (combo_box->priv->button, "key-press-event",
5587 G_CALLBACK (gtk_cell_editable_key_press),
5590 gtk_widget_grab_focus (combo_box->priv->button);
5594 child = gtk_bin_get_child (GTK_BIN (combo_box));
5596 g_signal_connect_object (child, "key-press-event",
5597 G_CALLBACK (gtk_cell_editable_key_press),
5600 gtk_widget_grab_focus (child);
5601 gtk_widget_set_can_focus (combo_box->priv->button, FALSE);
5604 /* we do the immediate popup only for the optionmenu-like
5607 if (combo_box->priv->is_cell_renderer &&
5608 combo_box->priv->cell_view && !combo_box->priv->tree_view)
5610 if (event && event->type == GDK_BUTTON_PRESS)
5612 GdkEventButton *event_button = (GdkEventButton *)event;
5614 combo_box->priv->activate_button = event_button->button;
5615 combo_box->priv->activate_time = event_button->time;
5618 combo_box->priv->popup_idle_id =
5619 gdk_threads_add_idle (popup_idle, combo_box);
5625 * gtk_combo_box_get_add_tearoffs:
5626 * @combo_box: a #GtkComboBox
5628 * Gets the current value of the :add-tearoffs property.
5630 * Return value: the current value of the :add-tearoffs property.
5633 gtk_combo_box_get_add_tearoffs (GtkComboBox *combo_box)
5635 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE);
5637 return combo_box->priv->add_tearoffs;
5641 * gtk_combo_box_set_add_tearoffs:
5642 * @combo_box: a #GtkComboBox
5643 * @add_tearoffs: %TRUE to add tearoff menu items
5645 * Sets whether the popup menu should have a tearoff
5651 gtk_combo_box_set_add_tearoffs (GtkComboBox *combo_box,
5652 gboolean add_tearoffs)
5654 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5656 add_tearoffs = add_tearoffs != FALSE;
5658 if (combo_box->priv->add_tearoffs != add_tearoffs)
5660 combo_box->priv->add_tearoffs = add_tearoffs;
5661 gtk_combo_box_check_appearance (combo_box);
5662 gtk_combo_box_relayout (combo_box);
5663 g_object_notify (G_OBJECT (combo_box), "add-tearoffs");
5668 * gtk_combo_box_get_title:
5669 * @combo_box: a #GtkComboBox
5671 * Gets the current title of the menu in tearoff mode. See
5672 * gtk_combo_box_set_add_tearoffs().
5674 * Returns: the menu's title in tearoff mode. This is an internal copy of the
5675 * string which must not be freed.
5679 G_CONST_RETURN gchar*
5680 gtk_combo_box_get_title (GtkComboBox *combo_box)
5682 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
5684 return combo_box->priv->tearoff_title;
5688 gtk_combo_box_update_title (GtkComboBox *combo_box)
5690 gtk_combo_box_check_appearance (combo_box);
5692 if (combo_box->priv->popup_widget &&
5693 GTK_IS_MENU (combo_box->priv->popup_widget))
5694 gtk_menu_set_title (GTK_MENU (combo_box->priv->popup_widget),
5695 combo_box->priv->tearoff_title);
5699 * gtk_combo_box_set_title:
5700 * @combo_box: a #GtkComboBox
5701 * @title: a title for the menu in tearoff mode
5703 * Sets the menu's title in tearoff mode.
5708 gtk_combo_box_set_title (GtkComboBox *combo_box,
5711 GtkComboBoxPrivate *priv;
5713 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5715 priv = combo_box->priv;
5717 if (strcmp (title ? title : "",
5718 priv->tearoff_title ? priv->tearoff_title : "") != 0)
5720 g_free (priv->tearoff_title);
5721 priv->tearoff_title = g_strdup (title);
5723 gtk_combo_box_update_title (combo_box);
5725 g_object_notify (G_OBJECT (combo_box), "tearoff-title");
5730 * gtk_combo_box_get_popup_accessible:
5731 * @combo_box: a #GtkComboBox
5733 * Gets the accessible object corresponding to the combo box's popup.
5735 * This function is mostly intended for use by accessibility technologies;
5736 * applications should have little use for it.
5738 * Returns: (transfer none): the accessible object corresponding
5739 * to the combo box's popup.
5744 gtk_combo_box_get_popup_accessible (GtkComboBox *combo_box)
5748 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
5750 if (combo_box->priv->popup_widget)
5752 atk_obj = gtk_widget_get_accessible (combo_box->priv->popup_widget);
5760 * gtk_combo_box_get_row_separator_func:
5761 * @combo_box: a #GtkComboBox
5763 * Returns the current row separator function.
5765 * Return value: the current row separator function.
5769 GtkTreeViewRowSeparatorFunc
5770 gtk_combo_box_get_row_separator_func (GtkComboBox *combo_box)
5772 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
5774 return combo_box->priv->row_separator_func;
5778 * gtk_combo_box_set_row_separator_func:
5779 * @combo_box: a #GtkComboBox
5780 * @func: a #GtkTreeViewRowSeparatorFunc
5781 * @data: (allow-none): user data to pass to @func, or %NULL
5782 * @destroy: (allow-none): destroy notifier for @data, or %NULL
5784 * Sets the row separator function, which is used to determine
5785 * whether a row should be drawn as a separator. If the row separator
5786 * function is %NULL, no separators are drawn. This is the default value.
5791 gtk_combo_box_set_row_separator_func (GtkComboBox *combo_box,
5792 GtkTreeViewRowSeparatorFunc func,
5794 GDestroyNotify destroy)
5796 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5798 if (combo_box->priv->row_separator_destroy)
5799 combo_box->priv->row_separator_destroy (combo_box->priv->row_separator_data);
5801 combo_box->priv->row_separator_func = func;
5802 combo_box->priv->row_separator_data = data;
5803 combo_box->priv->row_separator_destroy = destroy;
5805 if (combo_box->priv->tree_view)
5806 gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (combo_box->priv->tree_view),
5809 gtk_combo_box_relayout (combo_box);
5811 gtk_widget_queue_draw (GTK_WIDGET (combo_box));
5815 * gtk_combo_box_set_button_sensitivity:
5816 * @combo_box: a #GtkComboBox
5817 * @sensitivity: specify the sensitivity of the dropdown button
5819 * Sets whether the dropdown button of the combo box should be
5820 * always sensitive (%GTK_SENSITIVITY_ON), never sensitive (%GTK_SENSITIVITY_OFF)
5821 * or only if there is at least one item to display (%GTK_SENSITIVITY_AUTO).
5826 gtk_combo_box_set_button_sensitivity (GtkComboBox *combo_box,
5827 GtkSensitivityType sensitivity)
5829 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5831 if (combo_box->priv->button_sensitivity != sensitivity)
5833 combo_box->priv->button_sensitivity = sensitivity;
5834 gtk_combo_box_update_sensitivity (combo_box);
5836 g_object_notify (G_OBJECT (combo_box), "button-sensitivity");
5841 * gtk_combo_box_get_button_sensitivity:
5842 * @combo_box: a #GtkComboBox
5844 * Returns whether the combo box sets the dropdown button
5845 * sensitive or not when there are no items in the model.
5847 * Return Value: %GTK_SENSITIVITY_ON if the dropdown button
5848 * is sensitive when the model is empty, %GTK_SENSITIVITY_OFF
5849 * if the button is always insensitive or
5850 * %GTK_SENSITIVITY_AUTO if it is only sensitive as long as
5851 * the model has one item to be selected.
5856 gtk_combo_box_get_button_sensitivity (GtkComboBox *combo_box)
5858 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE);
5860 return combo_box->priv->button_sensitivity;
5865 * gtk_combo_box_set_focus_on_click:
5866 * @combo: a #GtkComboBox
5867 * @focus_on_click: whether the combo box grabs focus when clicked
5870 * Sets whether the combo box will grab focus when it is clicked with
5871 * the mouse. Making mouse clicks not grab focus is useful in places
5872 * like toolbars where you don't want the keyboard focus removed from
5873 * the main area of the application.
5878 gtk_combo_box_set_focus_on_click (GtkComboBox *combo_box,
5879 gboolean focus_on_click)
5881 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5883 focus_on_click = focus_on_click != FALSE;
5885 if (combo_box->priv->focus_on_click != focus_on_click)
5887 combo_box->priv->focus_on_click = focus_on_click;
5889 if (combo_box->priv->button)
5890 gtk_button_set_focus_on_click (GTK_BUTTON (combo_box->priv->button),
5893 g_object_notify (G_OBJECT (combo_box), "focus-on-click");
5898 * gtk_combo_box_get_focus_on_click:
5899 * @combo: a #GtkComboBox
5901 * Returns whether the combo box grabs focus when it is clicked
5902 * with the mouse. See gtk_combo_box_set_focus_on_click().
5904 * Return value: %TRUE if the combo box grabs focus when it is
5905 * clicked with the mouse.
5910 gtk_combo_box_get_focus_on_click (GtkComboBox *combo_box)
5912 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE);
5914 return combo_box->priv->focus_on_click;
5919 gtk_combo_box_buildable_custom_tag_start (GtkBuildable *buildable,
5920 GtkBuilder *builder,
5922 const gchar *tagname,
5923 GMarkupParser *parser,
5926 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
5927 tagname, parser, data))
5930 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
5931 tagname, parser, data);
5935 gtk_combo_box_buildable_custom_tag_end (GtkBuildable *buildable,
5936 GtkBuilder *builder,
5938 const gchar *tagname,
5941 if (strcmp (tagname, "attributes") == 0)
5942 _gtk_cell_layout_buildable_custom_tag_end (buildable, builder, child, tagname,
5945 parent_buildable_iface->custom_tag_end (buildable, builder, child, tagname,
5951 gtk_combo_box_remeasure (GtkComboBox *combo_box)
5953 GtkComboBoxPrivate *priv = combo_box->priv;
5958 !gtk_tree_model_get_iter_first (priv->model, &iter))
5961 priv->minimum_width = priv->natural_width = 0;
5963 path = gtk_tree_path_new_from_indices (0, -1);
5967 gint row_min = 0, row_nat = 0;
5969 if (priv->cell_view)
5970 gtk_cell_view_get_desired_width_of_row (GTK_CELL_VIEW (priv->cell_view),
5971 path, &row_min, &row_nat);
5973 priv->minimum_width = MAX (priv->minimum_width, row_min);
5974 priv->natural_width = MAX (priv->natural_width, row_nat);
5976 gtk_tree_path_next (path);
5978 while (gtk_tree_model_iter_next (priv->model, &iter));
5980 gtk_tree_path_free (path);
5985 gtk_combo_box_measure_height_for_width (GtkComboBox *combo_box,
5991 GtkComboBoxPrivate *priv = combo_box->priv;
5994 gint child_min, child_nat;
5996 child = gtk_bin_get_child (GTK_BIN (combo_box));
5998 gtk_widget_get_preferred_height_for_width (child, avail_width,
5999 &child_min, &child_nat);
6002 !gtk_tree_model_get_iter_first (priv->model, &iter))
6005 path = gtk_tree_path_new_from_indices (0, -1);
6009 gint row_min = 0, row_nat = 0;
6011 if (priv->cell_view)
6012 gtk_cell_view_get_desired_height_for_width_of_row (GTK_CELL_VIEW (priv->cell_view),
6014 &row_min, &row_nat);
6016 child_min = MAX (child_min, row_min);
6017 child_nat = MAX (child_nat, row_nat);
6019 gtk_tree_path_next (path);
6021 while (gtk_tree_model_iter_next (priv->model, &iter));
6023 gtk_tree_path_free (path);
6028 *min_height = child_min;
6030 *nat_height = child_nat;
6035 gtk_combo_box_get_preferred_width (GtkWidget *widget,
6039 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
6040 GtkComboBoxPrivate *priv = combo_box->priv;
6042 gint focus_width, focus_pad;
6043 gint font_size, arrow_size;
6044 PangoContext *context;
6045 PangoFontMetrics *metrics;
6046 PangoFontDescription *font_desc;
6048 gint minimum_width, natural_width;
6049 gint child_min, child_nat;
6051 child = gtk_bin_get_child (GTK_BIN (widget));
6054 gtk_widget_get_preferred_width (child, &child_min, &child_nat);
6055 gtk_combo_box_remeasure (combo_box);
6057 child_min = MAX (child_min, priv->minimum_width);
6058 child_nat = MAX (child_nat, priv->natural_width);
6060 gtk_widget_style_get (GTK_WIDGET (widget),
6061 "focus-line-width", &focus_width,
6062 "focus-padding", &focus_pad,
6063 "arrow-size", &arrow_size,
6066 font_desc = gtk_widget_get_style (child)->font_desc;
6067 context = gtk_widget_get_pango_context (GTK_WIDGET (widget));
6068 metrics = pango_context_get_metrics (context, font_desc,
6069 pango_context_get_language (context));
6070 font_size = PANGO_PIXELS (pango_font_metrics_get_ascent (metrics) +
6071 pango_font_metrics_get_descent (metrics));
6072 pango_font_metrics_unref (metrics);
6074 arrow_size = MAX (arrow_size, font_size);
6076 gtk_widget_set_size_request (priv->arrow, arrow_size, arrow_size);
6078 if (!priv->tree_view)
6082 if (priv->cell_view)
6084 gint sep_width, arrow_width;
6085 gint border_width, xthickness, xpad;
6087 border_width = gtk_container_get_border_width (GTK_CONTAINER (combo_box));
6088 xthickness = gtk_widget_get_style (priv->button)->xthickness;
6090 gtk_widget_get_preferred_width (priv->separator, &sep_width, NULL);
6091 gtk_widget_get_preferred_width (priv->arrow, &arrow_width, NULL);
6093 xpad = 2*(border_width + xthickness + focus_width + focus_pad);
6095 minimum_width = child_min + sep_width + arrow_width + xpad;
6096 natural_width = child_nat + sep_width + arrow_width + xpad;
6100 gint but_width, but_nat_width;
6102 gtk_widget_get_preferred_width (priv->button,
6103 &but_width, &but_nat_width);
6105 minimum_width = child_min + but_width;
6106 natural_width = child_nat + but_nat_width;
6112 gint button_width, button_nat_width;
6114 /* sample + frame */
6115 minimum_width = child_min;
6116 natural_width = child_nat;
6118 minimum_width += 2 * focus_width;
6119 natural_width += 2 * focus_width;
6121 if (priv->cell_view_frame)
6123 if (priv->has_frame)
6125 gint border_width = gtk_container_get_border_width (GTK_CONTAINER (priv->cell_view_frame));
6126 gint xpad = 2 * (border_width + gtk_widget_get_style (GTK_WIDGET (priv->cell_view_frame))->xthickness);
6128 minimum_width += xpad;
6129 natural_width += xpad;
6134 gtk_widget_get_preferred_width (priv->button,
6135 &button_width, &button_nat_width);
6137 minimum_width += button_width;
6138 natural_width += button_nat_width;
6141 if (GTK_SHADOW_NONE != priv->shadow_type)
6143 style = gtk_widget_get_style (GTK_WIDGET (widget));
6145 minimum_width += 2 * style->xthickness;
6146 natural_width += 2 * style->xthickness;
6150 *minimum_size = minimum_width;
6153 *natural_size = natural_width;
6157 gtk_combo_box_get_preferred_height (GtkWidget *widget,
6163 /* Combo box is height-for-width only
6164 * (so we always just reserve enough height for the minimum width) */
6165 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, &min_width, NULL);
6166 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height_for_width (widget, min_width, minimum_size, natural_size);
6170 gtk_combo_box_get_preferred_width_for_height (GtkWidget *widget,
6175 /* Combo box is height-for-width only
6176 * (so we assume we always reserved enough height for the minimum width) */
6177 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_size, natural_size);
6182 gtk_combo_box_get_preferred_height_for_width (GtkWidget *widget,
6187 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
6188 GtkComboBoxPrivate *priv = combo_box->priv;
6190 gint focus_width, focus_pad;
6191 gint min_height, nat_height;
6194 gtk_widget_style_get (GTK_WIDGET (widget),
6195 "focus-line-width", &focus_width,
6196 "focus-padding", &focus_pad,
6201 if (GTK_SHADOW_NONE != priv->shadow_type)
6202 size -= gtk_widget_get_style (GTK_WIDGET (widget))->xthickness;
6204 if (!priv->tree_view)
6207 if (priv->cell_view)
6209 GtkStyle *button_style;
6210 /* calculate x/y padding and separator/arrow size */
6211 gint sep_width, arrow_width, sep_height, arrow_height;
6212 gint border_width, xthickness, ythickness, xpad, ypad;
6214 border_width = gtk_container_get_border_width (GTK_CONTAINER (combo_box));
6215 button_style = gtk_widget_get_style (priv->button);
6217 xthickness = button_style->xthickness;
6218 ythickness = button_style->ythickness;
6220 gtk_widget_get_preferred_width (priv->separator, &sep_width, NULL);
6221 gtk_widget_get_preferred_width (priv->arrow, &arrow_width, NULL);
6222 gtk_widget_get_preferred_height_for_width (priv->separator,
6223 sep_width, &sep_height, NULL);
6224 gtk_widget_get_preferred_height_for_width (priv->arrow,
6225 arrow_width, &arrow_height, NULL);
6227 xpad = 2*(border_width + xthickness + focus_width + focus_pad);
6228 ypad = 2*(border_width + ythickness + focus_width + focus_pad);
6230 size -= sep_width + arrow_width + xpad;
6232 gtk_combo_box_measure_height_for_width (combo_box, size, &min_height, &nat_height);
6234 arrow_height = MAX (arrow_height, sep_height);
6235 min_height = MAX (min_height, arrow_height);
6236 nat_height = MAX (nat_height, arrow_height);
6243 /* there is a custom child widget inside (no priv->cell_view) */
6244 gint but_width, but_height;
6246 gtk_widget_get_preferred_width (priv->button, &but_width, NULL);
6247 gtk_widget_get_preferred_height_for_width (priv->button,
6248 but_width, &but_height, NULL);
6252 gtk_combo_box_measure_height_for_width (combo_box, size, &min_height, &nat_height);
6254 min_height = MAX (min_height, but_height);
6255 nat_height = MAX (nat_height, but_height);
6261 gint but_width, but_height;
6262 gint xpad = 0, ypad = 0;
6264 gtk_widget_get_preferred_width (priv->button, &but_width, NULL);
6265 gtk_widget_get_preferred_height_for_width (priv->button,
6266 but_width, &but_height, NULL);
6268 if (priv->cell_view_frame && priv->has_frame)
6270 GtkStyle *cell_style;
6273 border_width = gtk_container_get_border_width (GTK_CONTAINER (priv->cell_view_frame));
6274 cell_style = gtk_widget_get_style (GTK_WIDGET (priv->cell_view_frame));
6276 xpad = 2 * (border_width + cell_style->xthickness);
6277 ypad = 2 * (border_width + cell_style->ythickness);
6281 size -= 2 * focus_width;
6284 gtk_combo_box_measure_height_for_width (combo_box, size, &min_height, &nat_height);
6286 min_height = MAX (min_height, but_height);
6287 nat_height = MAX (nat_height, but_height);
6293 if (GTK_SHADOW_NONE != priv->shadow_type)
6295 style = gtk_widget_get_style (GTK_WIDGET (widget));
6297 min_height += 2 * style->ythickness;
6298 nat_height += 2 * style->ythickness;
6302 *minimum_size = min_height;
6305 *natural_size = nat_height;