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 "gtksizerequest.h"
42 #include "gtkprivate.h"
44 #include <gdk/gdkkeysyms.h>
46 #include <gobject/gvaluecollector.h>
51 #include "gtkmarshalers.h"
54 #include "gtktreeprivate.h"
56 /* WELCOME, to THE house of evil code */
58 typedef struct _ComboCellInfo ComboCellInfo;
61 GtkCellRenderer *cell;
64 GtkCellLayoutDataFunc func;
66 GDestroyNotify destroy;
73 struct _GtkComboBoxPrivate
81 GtkShadowType shadow_type;
83 gint active; /* Only temporary */
84 GtkTreeRowReference *active_row;
87 GtkTreeViewColumn *column;
90 GtkWidget *cell_view_frame;
97 GtkWidget *popup_widget;
98 GtkWidget *popup_window;
99 GtkWidget *scrolled_window;
106 guint activate_button;
107 guint32 activate_time;
109 guint resize_idle_id;
116 guint popup_in_progress : 1;
117 guint popup_shown : 1;
118 guint add_tearoffs : 1;
120 guint is_cell_renderer : 1;
121 guint editing_canceled : 1;
122 guint auto_scroll : 1;
123 guint focus_on_click : 1;
124 guint button_sensitivity : 2;
126 GtkTreeViewRowSeparatorFunc row_separator_func;
127 gpointer row_separator_data;
128 GDestroyNotify row_separator_destroy;
130 GdkDevice *grab_pointer;
131 GdkDevice *grab_keyboard;
133 gchar *tearoff_title;
136 /* While debugging this evil code, I have learned that
137 * there are actually 4 modes to this widget, which can
138 * be characterized as follows
140 * 1) menu mode, no child added
143 * cell_view -> GtkCellView, regular child
144 * cell_view_frame -> NULL
145 * button -> GtkToggleButton set_parent to combo
146 * arrow -> GtkArrow set_parent to button
147 * separator -> GtkVSepator set_parent to button
148 * popup_widget -> GtkMenu
149 * popup_window -> NULL
150 * scrolled_window -> NULL
152 * 2) menu mode, child added
156 * cell_view_frame -> NULL
157 * button -> GtkToggleButton set_parent to combo
158 * arrow -> GtkArrow, child of button
160 * popup_widget -> GtkMenu
161 * popup_window -> NULL
162 * scrolled_window -> NULL
164 * 3) list mode, no child added
166 * tree_view -> GtkTreeView, child of scrolled_window
167 * cell_view -> GtkCellView, regular child
168 * cell_view_frame -> GtkFrame, set parent to combo
169 * button -> GtkToggleButton, set_parent to combo
170 * arrow -> GtkArrow, child of button
172 * popup_widget -> tree_view
173 * popup_window -> GtkWindow
174 * scrolled_window -> GtkScrolledWindow, child of popup_window
176 * 4) list mode, child added
178 * tree_view -> GtkTreeView, child of scrolled_window
180 * cell_view_frame -> NULL
181 * button -> GtkToggleButton, set_parent to combo
182 * arrow -> GtkArrow, child of button
184 * popup_widget -> tree_view
185 * popup_window -> GtkWindow
186 * scrolled_window -> GtkScrolledWindow, child of popup_window
202 PROP_ROW_SPAN_COLUMN,
203 PROP_COLUMN_SPAN_COLUMN,
210 PROP_BUTTON_SENSITIVITY,
211 PROP_EDITING_CANCELED
214 static guint combo_box_signals[LAST_SIGNAL] = {0,};
216 #define BONUS_PADDING 4
217 #define SCROLL_TIME 100
221 static void gtk_combo_box_cell_layout_init (GtkCellLayoutIface *iface);
222 static void gtk_combo_box_cell_editable_init (GtkCellEditableIface *iface);
223 static void gtk_combo_box_dispose (GObject *object);
224 static void gtk_combo_box_finalize (GObject *object);
225 static void gtk_combo_box_destroy (GtkObject *object);
227 static void gtk_combo_box_set_property (GObject *object,
231 static void gtk_combo_box_get_property (GObject *object,
236 static void gtk_combo_box_state_changed (GtkWidget *widget,
237 GtkStateType previous);
238 static void gtk_combo_box_grab_focus (GtkWidget *widget);
239 static void gtk_combo_box_style_set (GtkWidget *widget,
241 static void gtk_combo_box_button_toggled (GtkWidget *widget,
243 static void gtk_combo_box_button_state_changed (GtkWidget *widget,
244 GtkStateType previous,
246 static void gtk_combo_box_add (GtkContainer *container,
248 static void gtk_combo_box_remove (GtkContainer *container,
251 static ComboCellInfo *gtk_combo_box_get_cell_info (GtkComboBox *combo_box,
252 GtkCellRenderer *cell);
254 static void gtk_combo_box_menu_show (GtkWidget *menu,
256 static void gtk_combo_box_menu_hide (GtkWidget *menu,
259 static void gtk_combo_box_set_popup_widget (GtkComboBox *combo_box,
261 static void gtk_combo_box_menu_position_below (GtkMenu *menu,
266 static void gtk_combo_box_menu_position_over (GtkMenu *menu,
271 static void gtk_combo_box_menu_position (GtkMenu *menu,
277 static void gtk_combo_box_update_requested_width(GtkComboBox *combo_box,
279 static void gtk_combo_box_remeasure (GtkComboBox *combo_box);
281 static void gtk_combo_box_unset_model (GtkComboBox *combo_box);
283 static void gtk_combo_box_size_allocate (GtkWidget *widget,
284 GtkAllocation *allocation);
285 static void gtk_combo_box_forall (GtkContainer *container,
286 gboolean include_internals,
287 GtkCallback callback,
288 gpointer callback_data);
289 static gboolean gtk_combo_box_expose_event (GtkWidget *widget,
290 GdkEventExpose *event);
291 static gboolean gtk_combo_box_scroll_event (GtkWidget *widget,
292 GdkEventScroll *event);
293 static void gtk_combo_box_set_active_internal (GtkComboBox *combo_box,
296 static void gtk_combo_box_check_appearance (GtkComboBox *combo_box);
297 static gchar * gtk_combo_box_real_get_active_text (GtkComboBox *combo_box);
298 static void gtk_combo_box_real_move_active (GtkComboBox *combo_box,
299 GtkScrollType scroll);
300 static void gtk_combo_box_real_popup (GtkComboBox *combo_box);
301 static gboolean gtk_combo_box_real_popdown (GtkComboBox *combo_box);
303 /* listening to the model */
304 static void gtk_combo_box_model_row_inserted (GtkTreeModel *model,
308 static void gtk_combo_box_model_row_deleted (GtkTreeModel *model,
311 static void gtk_combo_box_model_rows_reordered (GtkTreeModel *model,
316 static void gtk_combo_box_model_row_changed (GtkTreeModel *model,
320 static void gtk_combo_box_model_row_expanded (GtkTreeModel *model,
326 static void gtk_combo_box_list_position (GtkComboBox *combo_box,
331 static void gtk_combo_box_list_setup (GtkComboBox *combo_box);
332 static void gtk_combo_box_list_destroy (GtkComboBox *combo_box);
334 static gboolean gtk_combo_box_list_button_released (GtkWidget *widget,
335 GdkEventButton *event,
337 static gboolean gtk_combo_box_list_key_press (GtkWidget *widget,
340 static gboolean gtk_combo_box_list_enter_notify (GtkWidget *widget,
341 GdkEventCrossing *event,
343 static void gtk_combo_box_list_auto_scroll (GtkComboBox *combo,
346 static gboolean gtk_combo_box_list_scroll_timeout (GtkComboBox *combo);
347 static gboolean gtk_combo_box_list_button_pressed (GtkWidget *widget,
348 GdkEventButton *event,
351 static gboolean gtk_combo_box_list_select_func (GtkTreeSelection *selection,
354 gboolean path_currently_selected,
357 static void gtk_combo_box_list_row_changed (GtkTreeModel *model,
361 static void gtk_combo_box_list_popup_resize (GtkComboBox *combo_box);
364 static void gtk_combo_box_menu_setup (GtkComboBox *combo_box,
365 gboolean add_children);
366 static void gtk_combo_box_menu_fill (GtkComboBox *combo_box);
367 static void gtk_combo_box_menu_fill_level (GtkComboBox *combo_box,
370 static void gtk_combo_box_update_title (GtkComboBox *combo_box);
371 static void gtk_combo_box_menu_destroy (GtkComboBox *combo_box);
373 static void gtk_combo_box_relayout_item (GtkComboBox *combo_box,
377 static void gtk_combo_box_relayout (GtkComboBox *combo_box);
379 static gboolean gtk_combo_box_menu_button_press (GtkWidget *widget,
380 GdkEventButton *event,
382 static void gtk_combo_box_menu_item_activate (GtkWidget *item,
385 static void gtk_combo_box_update_sensitivity (GtkComboBox *combo_box);
386 static void gtk_combo_box_menu_row_inserted (GtkTreeModel *model,
390 static void gtk_combo_box_menu_row_deleted (GtkTreeModel *model,
393 static void gtk_combo_box_menu_rows_reordered (GtkTreeModel *model,
398 static void gtk_combo_box_menu_row_changed (GtkTreeModel *model,
402 static gboolean gtk_combo_box_menu_key_press (GtkWidget *widget,
405 static void gtk_combo_box_menu_popup (GtkComboBox *combo_box,
407 guint32 activate_time);
408 static GtkWidget *gtk_cell_view_menu_item_new (GtkComboBox *combo_box,
413 static void gtk_combo_box_cell_layout_pack_start (GtkCellLayout *layout,
414 GtkCellRenderer *cell,
416 static void gtk_combo_box_cell_layout_pack_end (GtkCellLayout *layout,
417 GtkCellRenderer *cell,
419 static GList *gtk_combo_box_cell_layout_get_cells (GtkCellLayout *layout);
420 static void gtk_combo_box_cell_layout_clear (GtkCellLayout *layout);
421 static void gtk_combo_box_cell_layout_add_attribute (GtkCellLayout *layout,
422 GtkCellRenderer *cell,
423 const gchar *attribute,
425 static void gtk_combo_box_cell_layout_set_cell_data_func (GtkCellLayout *layout,
426 GtkCellRenderer *cell,
427 GtkCellLayoutDataFunc func,
429 GDestroyNotify destroy);
430 static void gtk_combo_box_cell_layout_clear_attributes (GtkCellLayout *layout,
431 GtkCellRenderer *cell);
432 static void gtk_combo_box_cell_layout_reorder (GtkCellLayout *layout,
433 GtkCellRenderer *cell,
435 static gboolean gtk_combo_box_mnemonic_activate (GtkWidget *widget,
436 gboolean group_cycling);
438 static void gtk_combo_box_sync_cells (GtkComboBox *combo_box,
439 GtkCellLayout *cell_layout);
440 static void combo_cell_data_func (GtkCellLayout *cell_layout,
441 GtkCellRenderer *cell,
442 GtkTreeModel *tree_model,
445 static void gtk_combo_box_child_show (GtkWidget *widget,
446 GtkComboBox *combo_box);
447 static void gtk_combo_box_child_hide (GtkWidget *widget,
448 GtkComboBox *combo_box);
450 /* GtkBuildable method implementation */
451 static GtkBuildableIface *parent_buildable_iface;
453 static void gtk_combo_box_buildable_init (GtkBuildableIface *iface);
454 static gboolean gtk_combo_box_buildable_custom_tag_start (GtkBuildable *buildable,
457 const gchar *tagname,
458 GMarkupParser *parser,
460 static void gtk_combo_box_buildable_custom_tag_end (GtkBuildable *buildable,
463 const gchar *tagname,
466 /* GtkCellEditable method implementations */
467 static void gtk_combo_box_start_editing (GtkCellEditable *cell_editable,
470 static void gtk_combo_box_size_request_init (GtkSizeRequestIface *iface);
471 static void gtk_combo_box_get_width (GtkSizeRequest *widget,
474 static void gtk_combo_box_get_height (GtkSizeRequest *widget,
477 static void gtk_combo_box_get_width_for_height (GtkSizeRequest *widget,
481 static void gtk_combo_box_get_height_for_width (GtkSizeRequest *widget,
487 G_DEFINE_TYPE_WITH_CODE (GtkComboBox, gtk_combo_box, GTK_TYPE_BIN,
488 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
489 gtk_combo_box_cell_layout_init)
490 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
491 gtk_combo_box_cell_editable_init)
492 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
493 gtk_combo_box_buildable_init)
494 G_IMPLEMENT_INTERFACE (GTK_TYPE_SIZE_REQUEST,
495 gtk_combo_box_size_request_init))
500 gtk_combo_box_class_init (GtkComboBoxClass *klass)
502 GObjectClass *object_class;
503 GtkObjectClass *gtk_object_class;
504 GtkContainerClass *container_class;
505 GtkWidgetClass *widget_class;
506 GtkBindingSet *binding_set;
508 klass->get_active_text = gtk_combo_box_real_get_active_text;
510 container_class = (GtkContainerClass *)klass;
511 container_class->forall = gtk_combo_box_forall;
512 container_class->add = gtk_combo_box_add;
513 container_class->remove = gtk_combo_box_remove;
515 widget_class = (GtkWidgetClass *)klass;
516 widget_class->size_allocate = gtk_combo_box_size_allocate;
517 widget_class->expose_event = gtk_combo_box_expose_event;
518 widget_class->scroll_event = gtk_combo_box_scroll_event;
519 widget_class->mnemonic_activate = gtk_combo_box_mnemonic_activate;
520 widget_class->grab_focus = gtk_combo_box_grab_focus;
521 widget_class->style_set = gtk_combo_box_style_set;
522 widget_class->state_changed = gtk_combo_box_state_changed;
524 gtk_object_class = (GtkObjectClass *)klass;
525 gtk_object_class->destroy = gtk_combo_box_destroy;
527 object_class = (GObjectClass *)klass;
528 object_class->dispose = gtk_combo_box_dispose;
529 object_class->finalize = gtk_combo_box_finalize;
530 object_class->set_property = gtk_combo_box_set_property;
531 object_class->get_property = gtk_combo_box_get_property;
535 * GtkComboBox::changed:
536 * @widget: the object which received the signal
538 * The changed signal is emitted when the active
539 * item is changed. The can be due to the user selecting
540 * a different item from the list, or due to a
541 * call to gtk_combo_box_set_active_iter().
542 * It will also be emitted while typing into a GtkComboBoxEntry,
543 * as well as when selecting an item from the GtkComboBoxEntry's list.
547 combo_box_signals[CHANGED] =
548 g_signal_new (I_("changed"),
549 G_OBJECT_CLASS_TYPE (klass),
551 G_STRUCT_OFFSET (GtkComboBoxClass, changed),
553 g_cclosure_marshal_VOID__VOID,
556 * GtkComboBox::move-active:
557 * @widget: the object that received the signal
558 * @scroll_type: a #GtkScrollType
560 * The ::move-active signal is a
561 * <link linkend="keybinding-signals">keybinding signal</link>
562 * which gets emitted to move the active selection.
566 combo_box_signals[MOVE_ACTIVE] =
567 g_signal_new_class_handler (I_("move-active"),
568 G_OBJECT_CLASS_TYPE (klass),
569 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
570 G_CALLBACK (gtk_combo_box_real_move_active),
572 g_cclosure_marshal_VOID__ENUM,
574 GTK_TYPE_SCROLL_TYPE);
577 * GtkComboBox::popup:
578 * @widget: the object that received the signal
580 * The ::popup signal is a
581 * <link linkend="keybinding-signals">keybinding signal</link>
582 * which gets emitted to popup the combo box list.
584 * The default binding for this signal is Alt+Down.
588 combo_box_signals[POPUP] =
589 g_signal_new_class_handler (I_("popup"),
590 G_OBJECT_CLASS_TYPE (klass),
591 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
592 G_CALLBACK (gtk_combo_box_real_popup),
594 g_cclosure_marshal_VOID__VOID,
597 * GtkComboBox::popdown:
598 * @button: the object which received the signal
600 * The ::popdown signal is a
601 * <link linkend="keybinding-signals">keybinding signal</link>
602 * which gets emitted to popdown the combo box list.
604 * The default bindings for this signal are Alt+Up and Escape.
608 combo_box_signals[POPDOWN] =
609 g_signal_new_class_handler (I_("popdown"),
610 G_OBJECT_CLASS_TYPE (klass),
611 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
612 G_CALLBACK (gtk_combo_box_real_popdown),
614 _gtk_marshal_BOOLEAN__VOID,
618 binding_set = gtk_binding_set_by_class (widget_class);
620 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Down, GDK_MOD1_MASK,
622 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Down, GDK_MOD1_MASK,
625 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Up, GDK_MOD1_MASK,
627 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Up, GDK_MOD1_MASK,
629 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Escape, 0,
632 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Up, 0,
634 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_UP);
635 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Up, 0,
637 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_UP);
638 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Page_Up, 0,
640 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_PAGE_UP);
641 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Page_Up, 0,
643 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_PAGE_UP);
644 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Home, 0,
646 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_START);
647 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Home, 0,
649 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_START);
651 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Down, 0,
653 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_DOWN);
654 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Down, 0,
656 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_DOWN);
657 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Page_Down, 0,
659 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_PAGE_DOWN);
660 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Page_Down, 0,
662 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_PAGE_DOWN);
663 gtk_binding_entry_add_signal (binding_set, GDK_KEY_End, 0,
665 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_END);
666 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_End, 0,
668 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_END);
671 g_object_class_override_property (object_class,
672 PROP_EDITING_CANCELED,
678 * The model from which the combo box takes the values shown
683 g_object_class_install_property (object_class,
685 g_param_spec_object ("model",
686 P_("ComboBox model"),
687 P_("The model for the combo box"),
689 GTK_PARAM_READWRITE));
692 * GtkComboBox:wrap-width:
694 * If wrap-width is set to a positive value, the list will be
695 * displayed in multiple columns, the number of columns is
696 * determined by wrap-width.
700 g_object_class_install_property (object_class,
702 g_param_spec_int ("wrap-width",
704 P_("Wrap width for laying out the items in a grid"),
708 GTK_PARAM_READWRITE));
712 * GtkComboBox:row-span-column:
714 * If this is set to a non-negative value, it must be the index of a column
715 * of type %G_TYPE_INT in the model.
717 * The values of that column are used to determine how many rows a value in
718 * the list will span. Therefore, the values in the model column pointed to
719 * by this property must be greater than zero and not larger than wrap-width.
723 g_object_class_install_property (object_class,
724 PROP_ROW_SPAN_COLUMN,
725 g_param_spec_int ("row-span-column",
726 P_("Row span column"),
727 P_("TreeModel column containing the row span values"),
731 GTK_PARAM_READWRITE));
735 * GtkComboBox:column-span-column:
737 * If this is set to a non-negative value, it must be the index of a column
738 * of type %G_TYPE_INT in the model.
740 * The values of that column are used to determine how many columns a value
741 * in the list will span.
745 g_object_class_install_property (object_class,
746 PROP_COLUMN_SPAN_COLUMN,
747 g_param_spec_int ("column-span-column",
748 P_("Column span column"),
749 P_("TreeModel column containing the column span values"),
753 GTK_PARAM_READWRITE));
757 * GtkComboBox:active:
759 * The item which is currently active. If the model is a non-flat treemodel,
760 * and the active item is not an immediate child of the root of the tree,
761 * this property has the value
762 * <literal>gtk_tree_path_get_indices (path)[0]</literal>,
763 * where <literal>path</literal> is the #GtkTreePath of the active item.
767 g_object_class_install_property (object_class,
769 g_param_spec_int ("active",
771 P_("The item which is currently active"),
775 GTK_PARAM_READWRITE));
778 * GtkComboBox:add-tearoffs:
780 * The add-tearoffs property controls whether generated menus
781 * have tearoff menu items.
783 * Note that this only affects menu style combo boxes.
787 g_object_class_install_property (object_class,
789 g_param_spec_boolean ("add-tearoffs",
790 P_("Add tearoffs to menus"),
791 P_("Whether dropdowns should have a tearoff menu item"),
793 GTK_PARAM_READWRITE));
796 * GtkComboBox:has-frame:
798 * The has-frame property controls whether a frame
799 * is drawn around the entry.
803 g_object_class_install_property (object_class,
805 g_param_spec_boolean ("has-frame",
807 P_("Whether the combo box draws a frame around the child"),
809 GTK_PARAM_READWRITE));
811 g_object_class_install_property (object_class,
813 g_param_spec_boolean ("focus-on-click",
814 P_("Focus on click"),
815 P_("Whether the combo box grabs focus when it is clicked with the mouse"),
817 GTK_PARAM_READWRITE));
820 * GtkComboBox:tearoff-title:
822 * A title that may be displayed by the window manager
823 * when the popup is torn-off.
827 g_object_class_install_property (object_class,
829 g_param_spec_string ("tearoff-title",
831 P_("A title that may be displayed by the window manager when the popup is torn-off"),
833 GTK_PARAM_READWRITE));
837 * GtkComboBox:popup-shown:
839 * Whether the combo boxes dropdown is popped up.
840 * Note that this property is mainly useful, because
841 * it allows you to connect to notify::popup-shown.
845 g_object_class_install_property (object_class,
847 g_param_spec_boolean ("popup-shown",
849 P_("Whether the combo's dropdown is shown"),
851 GTK_PARAM_READABLE));
855 * GtkComboBox:button-sensitivity:
857 * Whether the dropdown button is sensitive when
858 * the model is empty.
862 g_object_class_install_property (object_class,
863 PROP_BUTTON_SENSITIVITY,
864 g_param_spec_enum ("button-sensitivity",
865 P_("Button Sensitivity"),
866 P_("Whether the dropdown button is sensitive when the model is empty"),
867 GTK_TYPE_SENSITIVITY_TYPE,
868 GTK_SENSITIVITY_AUTO,
869 GTK_PARAM_READWRITE));
871 gtk_widget_class_install_style_property (widget_class,
872 g_param_spec_boolean ("appears-as-list",
873 P_("Appears as list"),
874 P_("Whether dropdowns should look like lists rather than menus"),
876 GTK_PARAM_READABLE));
879 * GtkComboBox:arrow-size:
881 * Sets the minimum size of the arrow in the combo box. Note
882 * that the arrow size is coupled to the font size, so in case
883 * a larger font is used, the arrow will be larger than set
888 gtk_widget_class_install_style_property (widget_class,
889 g_param_spec_int ("arrow-size",
891 P_("The minimum size of the arrow in the combo box"),
895 GTK_PARAM_READABLE));
898 * GtkComboBox:shadow-type:
900 * Which kind of shadow to draw around the combo box.
904 gtk_widget_class_install_style_property (widget_class,
905 g_param_spec_enum ("shadow-type",
907 P_("Which kind of shadow to draw around the combo box"),
908 GTK_TYPE_SHADOW_TYPE,
910 GTK_PARAM_READABLE));
912 g_type_class_add_private (object_class, sizeof (GtkComboBoxPrivate));
916 gtk_combo_box_buildable_init (GtkBuildableIface *iface)
918 parent_buildable_iface = g_type_interface_peek_parent (iface);
919 iface->add_child = _gtk_cell_layout_buildable_add_child;
920 iface->custom_tag_start = gtk_combo_box_buildable_custom_tag_start;
921 iface->custom_tag_end = gtk_combo_box_buildable_custom_tag_end;
925 gtk_combo_box_cell_layout_init (GtkCellLayoutIface *iface)
927 iface->pack_start = gtk_combo_box_cell_layout_pack_start;
928 iface->pack_end = gtk_combo_box_cell_layout_pack_end;
929 iface->get_cells = gtk_combo_box_cell_layout_get_cells;
930 iface->clear = gtk_combo_box_cell_layout_clear;
931 iface->add_attribute = gtk_combo_box_cell_layout_add_attribute;
932 iface->set_cell_data_func = gtk_combo_box_cell_layout_set_cell_data_func;
933 iface->clear_attributes = gtk_combo_box_cell_layout_clear_attributes;
934 iface->reorder = gtk_combo_box_cell_layout_reorder;
938 gtk_combo_box_cell_editable_init (GtkCellEditableIface *iface)
940 iface->start_editing = gtk_combo_box_start_editing;
944 gtk_combo_box_init (GtkComboBox *combo_box)
946 GtkComboBoxPrivate *priv;
948 combo_box->priv = G_TYPE_INSTANCE_GET_PRIVATE (combo_box,
951 priv = combo_box->priv;
953 priv->cell_view = gtk_cell_view_new ();
954 gtk_widget_set_parent (priv->cell_view, GTK_WIDGET (combo_box));
955 _gtk_bin_set_child (GTK_BIN (combo_box), priv->cell_view);
956 gtk_widget_show (priv->cell_view);
958 priv->minimum_width = 0;
959 priv->natural_width = 0;
961 priv->wrap_width = 0;
964 priv->active_row = NULL;
965 priv->col_column = -1;
966 priv->row_column = -1;
968 priv->popup_shown = FALSE;
969 priv->add_tearoffs = FALSE;
970 priv->has_frame = TRUE;
971 priv->is_cell_renderer = FALSE;
972 priv->editing_canceled = FALSE;
973 priv->auto_scroll = FALSE;
974 priv->focus_on_click = TRUE;
975 priv->button_sensitivity = GTK_SENSITIVITY_AUTO;
977 gtk_combo_box_check_appearance (combo_box);
981 gtk_combo_box_set_property (GObject *object,
986 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
991 gtk_combo_box_set_model (combo_box, g_value_get_object (value));
994 case PROP_WRAP_WIDTH:
995 gtk_combo_box_set_wrap_width (combo_box, g_value_get_int (value));
998 case PROP_ROW_SPAN_COLUMN:
999 gtk_combo_box_set_row_span_column (combo_box, g_value_get_int (value));
1002 case PROP_COLUMN_SPAN_COLUMN:
1003 gtk_combo_box_set_column_span_column (combo_box, g_value_get_int (value));
1007 gtk_combo_box_set_active (combo_box, g_value_get_int (value));
1010 case PROP_ADD_TEAROFFS:
1011 gtk_combo_box_set_add_tearoffs (combo_box, g_value_get_boolean (value));
1014 case PROP_HAS_FRAME:
1015 combo_box->priv->has_frame = g_value_get_boolean (value);
1018 case PROP_FOCUS_ON_CLICK:
1019 gtk_combo_box_set_focus_on_click (combo_box,
1020 g_value_get_boolean (value));
1023 case PROP_TEAROFF_TITLE:
1024 gtk_combo_box_set_title (combo_box, g_value_get_string (value));
1027 case PROP_POPUP_SHOWN:
1028 if (g_value_get_boolean (value))
1029 gtk_combo_box_popup (combo_box);
1031 gtk_combo_box_popdown (combo_box);
1034 case PROP_BUTTON_SENSITIVITY:
1035 gtk_combo_box_set_button_sensitivity (combo_box,
1036 g_value_get_enum (value));
1039 case PROP_EDITING_CANCELED:
1040 combo_box->priv->editing_canceled = g_value_get_boolean (value);
1044 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1050 gtk_combo_box_get_property (GObject *object,
1055 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
1056 GtkComboBoxPrivate *priv = combo_box->priv;
1061 g_value_set_object (value, combo_box->priv->model);
1064 case PROP_WRAP_WIDTH:
1065 g_value_set_int (value, combo_box->priv->wrap_width);
1068 case PROP_ROW_SPAN_COLUMN:
1069 g_value_set_int (value, combo_box->priv->row_column);
1072 case PROP_COLUMN_SPAN_COLUMN:
1073 g_value_set_int (value, combo_box->priv->col_column);
1077 g_value_set_int (value, gtk_combo_box_get_active (combo_box));
1080 case PROP_ADD_TEAROFFS:
1081 g_value_set_boolean (value, gtk_combo_box_get_add_tearoffs (combo_box));
1084 case PROP_HAS_FRAME:
1085 g_value_set_boolean (value, combo_box->priv->has_frame);
1088 case PROP_FOCUS_ON_CLICK:
1089 g_value_set_boolean (value, combo_box->priv->focus_on_click);
1092 case PROP_TEAROFF_TITLE:
1093 g_value_set_string (value, gtk_combo_box_get_title (combo_box));
1096 case PROP_POPUP_SHOWN:
1097 g_value_set_boolean (value, combo_box->priv->popup_shown);
1100 case PROP_BUTTON_SENSITIVITY:
1101 g_value_set_enum (value, combo_box->priv->button_sensitivity);
1104 case PROP_EDITING_CANCELED:
1105 g_value_set_boolean (value, priv->editing_canceled);
1109 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1115 gtk_combo_box_state_changed (GtkWidget *widget,
1116 GtkStateType previous)
1118 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
1119 GtkComboBoxPrivate *priv = combo_box->priv;
1121 if (gtk_widget_get_realized (widget))
1123 if (priv->tree_view && priv->cell_view)
1124 gtk_cell_view_set_background_color (GTK_CELL_VIEW (priv->cell_view),
1125 >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
1128 gtk_widget_queue_draw (widget);
1132 gtk_combo_box_button_state_changed (GtkWidget *widget,
1133 GtkStateType previous,
1136 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
1137 GtkComboBoxPrivate *priv = combo_box->priv;
1139 if (gtk_widget_get_realized (widget))
1141 if (!priv->tree_view && priv->cell_view)
1143 if ((gtk_widget_get_state (widget) == GTK_STATE_INSENSITIVE) !=
1144 (gtk_widget_get_state (priv->cell_view) == GTK_STATE_INSENSITIVE))
1145 gtk_widget_set_sensitive (priv->cell_view, gtk_widget_get_sensitive (widget));
1147 gtk_widget_set_state (priv->cell_view,
1148 gtk_widget_get_state (widget));
1152 gtk_widget_queue_draw (widget);
1156 gtk_combo_box_check_appearance (GtkComboBox *combo_box)
1158 GtkComboBoxPrivate *priv = combo_box->priv;
1159 gboolean appears_as_list;
1161 /* if wrap_width > 0, then we are in grid-mode and forced to use
1164 if (priv->wrap_width)
1165 appears_as_list = FALSE;
1167 gtk_widget_style_get (GTK_WIDGET (combo_box),
1168 "appears-as-list", &appears_as_list,
1171 if (appears_as_list)
1173 /* Destroy all the menu mode widgets, if they exist. */
1174 if (GTK_IS_MENU (priv->popup_widget))
1175 gtk_combo_box_menu_destroy (combo_box);
1177 /* Create the list mode widgets, if they don't already exist. */
1178 if (!GTK_IS_TREE_VIEW (priv->tree_view))
1179 gtk_combo_box_list_setup (combo_box);
1183 /* Destroy all the list mode widgets, if they exist. */
1184 if (GTK_IS_TREE_VIEW (priv->tree_view))
1185 gtk_combo_box_list_destroy (combo_box);
1187 /* Create the menu mode widgets, if they don't already exist. */
1188 if (!GTK_IS_MENU (priv->popup_widget))
1189 gtk_combo_box_menu_setup (combo_box, TRUE);
1192 gtk_widget_style_get (GTK_WIDGET (combo_box),
1193 "shadow-type", &priv->shadow_type,
1198 gtk_combo_box_style_set (GtkWidget *widget,
1201 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
1202 GtkComboBoxPrivate *priv = combo_box->priv;
1205 gtk_combo_box_check_appearance (combo_box);
1207 if (priv->tree_view && priv->cell_view)
1208 gtk_cell_view_set_background_color (GTK_CELL_VIEW (priv->cell_view),
1209 >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
1211 child = gtk_bin_get_child (GTK_BIN (combo_box));
1212 if (GTK_IS_ENTRY (child))
1213 g_object_set (child, "shadow-type",
1214 GTK_SHADOW_NONE == priv->shadow_type ?
1215 GTK_SHADOW_IN : GTK_SHADOW_NONE, NULL);
1219 gtk_combo_box_button_toggled (GtkWidget *widget,
1222 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
1224 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
1226 if (!combo_box->priv->popup_in_progress)
1227 gtk_combo_box_popup (combo_box);
1230 gtk_combo_box_popdown (combo_box);
1234 gtk_combo_box_add (GtkContainer *container,
1237 GtkComboBox *combo_box = GTK_COMBO_BOX (container);
1238 GtkComboBoxPrivate *priv = combo_box->priv;
1240 if (priv->cell_view &&
1241 gtk_widget_get_parent (priv->cell_view))
1243 gtk_widget_unparent (priv->cell_view);
1244 _gtk_bin_set_child (GTK_BIN (container), NULL);
1245 gtk_widget_queue_resize (GTK_WIDGET (container));
1248 gtk_widget_set_parent (widget, GTK_WIDGET (container));
1249 _gtk_bin_set_child (GTK_BIN (container), widget);
1251 if (priv->cell_view &&
1252 widget != priv->cell_view)
1254 /* since the cell_view was unparented, it's gone now */
1255 priv->cell_view = NULL;
1257 if (!priv->tree_view && priv->separator)
1259 gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (priv->separator)),
1261 priv->separator = NULL;
1263 gtk_widget_queue_resize (GTK_WIDGET (container));
1265 else if (priv->cell_view_frame)
1267 gtk_widget_unparent (priv->cell_view_frame);
1268 priv->cell_view_frame = NULL;
1275 gtk_combo_box_remove (GtkContainer *container,
1278 GtkComboBox *combo_box = GTK_COMBO_BOX (container);
1279 GtkComboBoxPrivate *priv = combo_box->priv;
1281 gboolean appears_as_list;
1283 if (widget == priv->cell_view)
1284 priv->cell_view = NULL;
1286 gtk_widget_unparent (widget);
1287 _gtk_bin_set_child (GTK_BIN (container), NULL);
1289 if (GTK_OBJECT_FLAGS (combo_box) & GTK_IN_DESTRUCTION)
1292 gtk_widget_queue_resize (GTK_WIDGET (container));
1294 if (!priv->tree_view)
1295 appears_as_list = FALSE;
1297 appears_as_list = TRUE;
1299 if (appears_as_list)
1300 gtk_combo_box_list_destroy (combo_box);
1301 else if (GTK_IS_MENU (priv->popup_widget))
1303 gtk_combo_box_menu_destroy (combo_box);
1304 gtk_menu_detach (GTK_MENU (priv->popup_widget));
1305 priv->popup_widget = NULL;
1308 if (!priv->cell_view)
1310 priv->cell_view = gtk_cell_view_new ();
1311 gtk_widget_set_parent (priv->cell_view, GTK_WIDGET (container));
1312 _gtk_bin_set_child (GTK_BIN (container), priv->cell_view);
1314 gtk_widget_show (priv->cell_view);
1315 gtk_cell_view_set_model (GTK_CELL_VIEW (priv->cell_view),
1317 gtk_combo_box_sync_cells (combo_box, GTK_CELL_LAYOUT (priv->cell_view));
1321 if (appears_as_list)
1322 gtk_combo_box_list_setup (combo_box);
1324 gtk_combo_box_menu_setup (combo_box, TRUE);
1326 if (gtk_tree_row_reference_valid (priv->active_row))
1328 path = gtk_tree_row_reference_get_path (priv->active_row);
1329 gtk_combo_box_set_active_internal (combo_box, path);
1330 gtk_tree_path_free (path);
1333 gtk_combo_box_set_active_internal (combo_box, NULL);
1336 static ComboCellInfo *
1337 gtk_combo_box_get_cell_info (GtkComboBox *combo_box,
1338 GtkCellRenderer *cell)
1342 for (i = combo_box->priv->cells; i; i = i->next)
1344 ComboCellInfo *info = (ComboCellInfo *)i->data;
1346 if (info && info->cell == cell)
1354 gtk_combo_box_menu_show (GtkWidget *menu,
1357 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
1358 GtkComboBoxPrivate *priv = combo_box->priv;
1360 gtk_combo_box_child_show (menu, user_data);
1362 priv->popup_in_progress = TRUE;
1363 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->button),
1365 priv->popup_in_progress = FALSE;
1369 gtk_combo_box_menu_hide (GtkWidget *menu,
1372 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
1374 gtk_combo_box_child_hide (menu,user_data);
1376 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
1381 gtk_combo_box_detacher (GtkWidget *widget,
1384 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
1385 GtkComboBoxPrivate *priv = combo_box->priv;
1387 g_return_if_fail (priv->popup_widget == (GtkWidget *) menu);
1389 g_signal_handlers_disconnect_by_func (menu->toplevel,
1390 gtk_combo_box_menu_show,
1392 g_signal_handlers_disconnect_by_func (menu->toplevel,
1393 gtk_combo_box_menu_hide,
1396 priv->popup_widget = NULL;
1400 gtk_combo_box_set_popup_widget (GtkComboBox *combo_box,
1403 GtkComboBoxPrivate *priv = combo_box->priv;
1405 if (GTK_IS_MENU (priv->popup_widget))
1407 gtk_menu_detach (GTK_MENU (priv->popup_widget));
1408 priv->popup_widget = NULL;
1410 else if (priv->popup_widget)
1412 gtk_container_remove (GTK_CONTAINER (priv->scrolled_window),
1413 priv->popup_widget);
1414 g_object_unref (priv->popup_widget);
1415 priv->popup_widget = NULL;
1418 if (GTK_IS_MENU (popup))
1420 if (priv->popup_window)
1422 gtk_widget_destroy (priv->popup_window);
1423 priv->popup_window = NULL;
1426 priv->popup_widget = popup;
1429 * Note that we connect to show/hide on the toplevel, not the
1430 * menu itself, since the menu is not shown/hidden when it is
1431 * popped up while torn-off.
1433 g_signal_connect (GTK_MENU (popup)->toplevel, "show",
1434 G_CALLBACK (gtk_combo_box_menu_show), combo_box);
1435 g_signal_connect (GTK_MENU (popup)->toplevel, "hide",
1436 G_CALLBACK (gtk_combo_box_menu_hide), combo_box);
1438 gtk_menu_attach_to_widget (GTK_MENU (popup),
1439 GTK_WIDGET (combo_box),
1440 gtk_combo_box_detacher);
1444 if (!priv->popup_window)
1446 GtkWidget *toplevel;
1448 priv->popup_window = gtk_window_new (GTK_WINDOW_POPUP);
1449 gtk_widget_set_name (priv->popup_window, "gtk-combobox-popup-window");
1451 gtk_window_set_type_hint (GTK_WINDOW (priv->popup_window),
1452 GDK_WINDOW_TYPE_HINT_COMBO);
1454 g_signal_connect (GTK_WINDOW (priv->popup_window),"show",
1455 G_CALLBACK (gtk_combo_box_child_show),
1457 g_signal_connect (GTK_WINDOW (priv->popup_window),"hide",
1458 G_CALLBACK (gtk_combo_box_child_hide),
1461 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (combo_box));
1462 if (GTK_IS_WINDOW (toplevel))
1464 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
1465 GTK_WINDOW (priv->popup_window));
1466 gtk_window_set_transient_for (GTK_WINDOW (priv->popup_window),
1467 GTK_WINDOW (toplevel));
1470 gtk_window_set_resizable (GTK_WINDOW (priv->popup_window), FALSE);
1471 gtk_window_set_screen (GTK_WINDOW (priv->popup_window),
1472 gtk_widget_get_screen (GTK_WIDGET (combo_box)));
1474 priv->scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1476 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
1479 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (priv->scrolled_window),
1482 gtk_widget_show (priv->scrolled_window);
1484 gtk_container_add (GTK_CONTAINER (priv->popup_window),
1485 priv->scrolled_window);
1488 gtk_container_add (GTK_CONTAINER (priv->scrolled_window),
1491 gtk_widget_show (popup);
1492 g_object_ref (popup);
1493 priv->popup_widget = popup;
1498 gtk_combo_box_menu_position_below (GtkMenu *menu,
1504 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
1505 GtkAllocation child_allocation;
1511 GdkRectangle monitor;
1513 /* FIXME: is using the size request here broken? */
1514 child = gtk_bin_get_child (GTK_BIN (combo_box));
1518 gtk_widget_get_allocation (child, &child_allocation);
1520 if (!gtk_widget_get_has_window (child))
1522 sx += child_allocation.x;
1523 sy += child_allocation.y;
1526 gdk_window_get_root_coords (gtk_widget_get_window (child),
1529 if (GTK_SHADOW_NONE != combo_box->priv->shadow_type)
1530 sx -= gtk_widget_get_style (GTK_WIDGET (combo_box))->xthickness;
1532 gtk_widget_size_request (GTK_WIDGET (menu), &req);
1534 if (gtk_widget_get_direction (GTK_WIDGET (combo_box)) == GTK_TEXT_DIR_LTR)
1537 *x = sx + child_allocation.width - req.width;
1540 screen = gtk_widget_get_screen (GTK_WIDGET (combo_box));
1541 monitor_num = gdk_screen_get_monitor_at_window (screen,
1542 gtk_widget_get_window (GTK_WIDGET (combo_box)));
1543 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
1547 else if (*x + req.width > monitor.x + monitor.width)
1548 *x = monitor.x + monitor.width - req.width;
1550 if (monitor.y + monitor.height - *y - child_allocation.height >= req.height)
1551 *y += child_allocation.height;
1552 else if (*y - monitor.y >= req.height)
1554 else if (monitor.y + monitor.height - *y - child_allocation.height > *y - monitor.y)
1555 *y += child_allocation.height;
1563 gtk_combo_box_menu_position_over (GtkMenu *menu,
1569 GtkComboBox *combo_box;
1573 GtkAllocation allocation;
1574 GtkAllocation child_allocation;
1581 combo_box = GTK_COMBO_BOX (user_data);
1582 widget = GTK_WIDGET (combo_box);
1584 active = gtk_menu_get_active (GTK_MENU (combo_box->priv->popup_widget));
1586 gtk_widget_get_allocation (widget, &allocation);
1588 menu_xpos = allocation.x;
1589 menu_ypos = allocation.y + allocation.height / 2 - 2;
1591 gtk_size_request_get_width (GTK_SIZE_REQUEST (menu), &menu_width, NULL);
1595 gtk_widget_get_allocation (active, &child_allocation);
1596 menu_ypos -= child_allocation.height / 2;
1599 children = GTK_MENU_SHELL (combo_box->priv->popup_widget)->children;
1602 child = children->data;
1604 if (active == child)
1607 if (gtk_widget_get_visible (child))
1609 gtk_widget_get_allocation (child, &child_allocation);
1611 menu_ypos -= child_allocation.height;
1614 children = children->next;
1617 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1618 menu_xpos = menu_xpos + allocation.width - menu_width;
1620 gdk_window_get_root_coords (gtk_widget_get_window (widget),
1621 menu_xpos, menu_ypos,
1622 &menu_xpos, &menu_ypos);
1624 /* Clamp the position on screen */
1625 screen_width = gdk_screen_get_width (gtk_widget_get_screen (widget));
1629 else if ((menu_xpos + menu_width) > screen_width)
1630 menu_xpos -= ((menu_xpos + menu_width) - screen_width);
1639 gtk_combo_box_menu_position (GtkMenu *menu,
1645 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
1646 GtkComboBoxPrivate *priv = combo_box->priv;
1647 GtkWidget *menu_item;
1650 if (priv->wrap_width > 0 || priv->cell_view == NULL)
1651 gtk_combo_box_menu_position_below (menu, x, y, push_in, user_data);
1654 /* FIXME handle nested menus better */
1655 menu_item = gtk_menu_get_active (GTK_MENU (priv->popup_widget));
1657 gtk_menu_shell_select_item (GTK_MENU_SHELL (priv->popup_widget),
1660 gtk_combo_box_menu_position_over (menu, x, y, push_in, user_data);
1663 if (!gtk_widget_get_visible (GTK_MENU (priv->popup_widget)->toplevel))
1664 gtk_window_set_type_hint (GTK_WINDOW (GTK_MENU (priv->popup_widget)->toplevel),
1665 GDK_WINDOW_TYPE_HINT_COMBO);
1669 gtk_combo_box_list_position (GtkComboBox *combo_box,
1675 GtkComboBoxPrivate *priv = combo_box->priv;
1676 GtkAllocation allocation;
1679 GdkRectangle monitor;
1680 GtkRequisition popup_req;
1681 GtkPolicyType hpolicy, vpolicy;
1684 /* under windows, the drop down list is as wide as the combo box itself.
1686 GtkWidget *widget = GTK_WIDGET (combo_box);
1690 gtk_widget_get_allocation (widget, &allocation);
1692 if (!gtk_widget_get_has_window (widget))
1698 window = gtk_widget_get_window (widget);
1700 gdk_window_get_root_coords (gtk_widget_get_window (widget),
1703 *width = allocation.width;
1705 hpolicy = vpolicy = GTK_POLICY_NEVER;
1706 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
1708 gtk_widget_size_request (priv->scrolled_window, &popup_req);
1710 if (popup_req.width > *width)
1712 hpolicy = GTK_POLICY_ALWAYS;
1713 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
1715 gtk_widget_size_request (priv->scrolled_window, &popup_req);
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_size_request_get_width (GTK_SIZE_REQUEST (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_size_request (combo_box->priv->button, &req); \
2174 child.x = allocation->x + shadow_width; \
2176 child.x = allocation->x + allocation->width - req.width - shadow_width; \
2178 child.y = allocation->y + shadow_height; \
2179 child.width = req.width; \
2180 child.height = allocation->height - 2 * shadow_height; \
2181 child.width = MAX (1, child.width); \
2182 child.height = MAX (1, child.height); \
2184 gtk_widget_size_allocate (combo_box->priv->button, &child);
2187 gtk_combo_box_size_allocate (GtkWidget *widget,
2188 GtkAllocation *allocation)
2190 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
2191 GtkComboBoxPrivate *priv = combo_box->priv;
2192 GtkWidget *child_widget;
2193 gint shadow_width, shadow_height;
2194 gint focus_width, focus_pad;
2195 GtkAllocation child;
2198 gboolean is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2200 gtk_widget_set_allocation (widget, allocation);
2201 child_widget = gtk_bin_get_child (GTK_BIN (widget));
2203 style = gtk_widget_get_style (widget);
2204 gtk_widget_style_get (widget,
2205 "focus-line-width", &focus_width,
2206 "focus-padding", &focus_pad,
2209 if (GTK_SHADOW_NONE != priv->shadow_type)
2211 shadow_width = style->xthickness;
2212 shadow_height = style->ythickness;
2220 if (!priv->tree_view)
2222 if (priv->cell_view)
2224 gint xthickness, ythickness;
2229 allocation->x += shadow_width;
2230 allocation->y += shadow_height;
2231 allocation->width -= 2 * shadow_width;
2232 allocation->height -= 2 * shadow_height;
2234 gtk_widget_size_allocate (priv->button, allocation);
2236 /* set some things ready */
2237 border_width = gtk_container_get_border_width (GTK_CONTAINER (priv->button));
2238 style = gtk_widget_get_style (priv->button);
2239 xthickness = style->xthickness;
2240 ythickness = style->ythickness;
2242 child.x = allocation->x;
2243 child.y = allocation->y;
2244 width = allocation->width;
2245 child.height = allocation->height;
2247 if (!priv->is_cell_renderer)
2249 child.x += border_width + xthickness + focus_width + focus_pad;
2250 child.y += border_width + ythickness + focus_width + focus_pad;
2251 width -= 2 * (child.x - allocation->x);
2252 child.height -= 2 * (child.y - allocation->y);
2256 /* handle the children */
2257 gtk_widget_size_request (priv->arrow, &req);
2258 child.width = req.width;
2260 child.x += width - req.width;
2261 child.width = MAX (1, child.width);
2262 child.height = MAX (1, child.height);
2263 gtk_widget_size_allocate (priv->arrow, &child);
2265 child.x += req.width;
2266 gtk_widget_size_request (priv->separator, &req);
2267 child.width = req.width;
2269 child.x -= req.width;
2270 child.width = MAX (1, child.width);
2271 child.height = MAX (1, child.height);
2272 gtk_widget_size_allocate (priv->separator, &child);
2276 child.x += req.width;
2277 child.width = allocation->x + allocation->width
2278 - (border_width + xthickness + focus_width + focus_pad)
2283 child.width = child.x;
2284 child.x = allocation->x
2285 + border_width + xthickness + focus_width + focus_pad;
2286 child.width -= child.x;
2289 if (gtk_widget_get_visible (priv->popup_widget))
2291 gint width, min_width;
2293 if (priv->wrap_width == 0)
2295 GtkAllocation combo_box_allocation;
2297 gtk_widget_get_allocation (GTK_WIDGET (combo_box), &combo_box_allocation);
2298 width = combo_box_allocation.width;
2299 gtk_widget_set_size_request (priv->popup_widget, -1, -1);
2300 gtk_size_request_get_width (GTK_SIZE_REQUEST (priv->popup_widget), &min_width, NULL);
2301 gtk_widget_set_size_request (priv->popup_widget,
2302 MAX (width, min_width), -1);
2305 /* reposition the menu after giving it a new width */
2306 gtk_menu_reposition (GTK_MENU (priv->popup_widget));
2309 child.width = MAX (1, child.width);
2310 child.height = MAX (1, child.height);
2311 gtk_widget_size_allocate (child_widget, &child);
2315 GTK_COMBO_BOX_SIZE_ALLOCATE_BUTTON
2318 child.x = allocation->x + req.width + shadow_width;
2320 child.x = allocation->x + shadow_width;
2321 child.y = allocation->y + shadow_height;
2322 child.width = allocation->width - req.width - 2 * shadow_width;
2323 child.width = MAX (1, child.width);
2324 child.height = MAX (1, child.height);
2325 gtk_widget_size_allocate (child_widget, &child);
2332 /* Combobox thickness + border-width */
2333 guint border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
2334 int delta_x = shadow_width + border_width;
2335 int delta_y = shadow_height + border_width;
2338 GTK_COMBO_BOX_SIZE_ALLOCATE_BUTTON
2342 child.x = allocation->x + req.width;
2344 child.x = allocation->x;
2346 child.y = allocation->y;
2347 child.width = allocation->width - req.width;
2348 child.height = allocation->height;
2350 if (priv->cell_view_frame)
2354 child.width = MAX (1, child.width - delta_x * 2);
2355 child.height = MAX (1, child.height - delta_y * 2);
2356 gtk_widget_size_allocate (priv->cell_view_frame, &child);
2359 if (priv->has_frame)
2361 border_width = gtk_container_get_border_width (GTK_CONTAINER (priv->cell_view_frame));
2362 style = gtk_widget_get_style (priv->cell_view_frame);
2363 delta_x = border_width + style->xthickness;
2364 delta_y = border_width + style->ythickness;
2368 child.width -= delta_x * 2;
2369 child.height -= delta_y * 2;
2376 child.width -= delta_x * 2;
2377 child.height -= delta_y * 2;
2380 if (gtk_widget_get_visible (priv->popup_window))
2382 gint x, y, width, height;
2383 gtk_combo_box_list_position (combo_box, &x, &y, &width, &height);
2384 gtk_window_move (GTK_WINDOW (priv->popup_window), x, y);
2385 gtk_widget_set_size_request (priv->popup_window, width, height);
2389 child.width = MAX (1, child.width);
2390 child.height = MAX (1, child.height);
2392 gtk_widget_size_allocate (child_widget, &child);
2396 #undef GTK_COMBO_BOX_ALLOCATE_BUTTON
2399 gtk_combo_box_unset_model (GtkComboBox *combo_box)
2401 GtkComboBoxPrivate *priv = combo_box->priv;
2405 g_signal_handler_disconnect (priv->model,
2407 g_signal_handler_disconnect (priv->model,
2409 g_signal_handler_disconnect (priv->model,
2410 priv->reordered_id);
2411 g_signal_handler_disconnect (priv->model,
2416 if (!priv->tree_view)
2418 if (priv->popup_widget)
2419 gtk_container_foreach (GTK_CONTAINER (priv->popup_widget),
2420 (GtkCallback)gtk_widget_destroy, NULL);
2425 g_object_unref (priv->model);
2429 if (priv->active_row)
2431 gtk_tree_row_reference_free (priv->active_row);
2432 priv->active_row = NULL;
2435 if (priv->cell_view)
2436 gtk_cell_view_set_model (GTK_CELL_VIEW (priv->cell_view), NULL);
2440 gtk_combo_box_forall (GtkContainer *container,
2441 gboolean include_internals,
2442 GtkCallback callback,
2443 gpointer callback_data)
2445 GtkComboBox *combo_box = GTK_COMBO_BOX (container);
2446 GtkComboBoxPrivate *priv = combo_box->priv;
2449 if (include_internals)
2452 (* callback) (priv->button, callback_data);
2453 if (priv->cell_view_frame)
2454 (* callback) (priv->cell_view_frame, callback_data);
2457 child = gtk_bin_get_child (GTK_BIN (container));
2459 (* callback) (child, callback_data);
2463 gtk_combo_box_child_show (GtkWidget *widget,
2464 GtkComboBox *combo_box)
2466 GtkComboBoxPrivate *priv = combo_box->priv;
2468 priv->popup_shown = TRUE;
2469 g_object_notify (G_OBJECT (combo_box), "popup-shown");
2473 gtk_combo_box_child_hide (GtkWidget *widget,
2474 GtkComboBox *combo_box)
2476 GtkComboBoxPrivate *priv = combo_box->priv;
2478 priv->popup_shown = FALSE;
2479 g_object_notify (G_OBJECT (combo_box), "popup-shown");
2483 gtk_combo_box_expose_event (GtkWidget *widget,
2484 GdkEventExpose *event)
2486 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
2487 GtkComboBoxPrivate *priv = combo_box->priv;
2489 if (gtk_widget_is_drawable (widget) &&
2490 GTK_SHADOW_NONE != priv->shadow_type)
2492 GtkAllocation allocation;
2494 gtk_widget_get_allocation (widget, &allocation);
2496 gtk_paint_shadow (gtk_widget_get_style (widget),
2497 gtk_widget_get_window (widget),
2498 GTK_STATE_NORMAL, priv->shadow_type,
2499 NULL, widget, "combobox",
2500 allocation.x, allocation.y,
2501 allocation.width, allocation.height);
2504 gtk_container_propagate_expose (GTK_CONTAINER (widget),
2505 priv->button, event);
2507 if (priv->tree_view && priv->cell_view_frame)
2509 gtk_container_propagate_expose (GTK_CONTAINER (widget),
2510 priv->cell_view_frame, event);
2513 gtk_container_propagate_expose (GTK_CONTAINER (widget),
2514 gtk_bin_get_child (GTK_BIN (widget)),
2530 path_visible (GtkTreeView *view,
2536 /* Note that we rely on the fact that collapsed rows don't have nodes
2538 return _gtk_tree_view_find_node (view, path, &tree, &node);
2542 tree_next_func (GtkTreeModel *model,
2547 SearchData *search_data = (SearchData *)data;
2549 if (search_data->found)
2551 if (!tree_column_row_is_sensitive (search_data->combo, iter))
2554 if (search_data->visible &&
2555 !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
2558 search_data->set = TRUE;
2559 search_data->iter = *iter;
2564 if (gtk_tree_path_compare (path, search_data->path) == 0)
2565 search_data->found = TRUE;
2571 tree_next (GtkComboBox *combo,
2572 GtkTreeModel *model,
2577 SearchData search_data;
2579 search_data.combo = combo;
2580 search_data.path = gtk_tree_model_get_path (model, iter);
2581 search_data.visible = visible;
2582 search_data.found = FALSE;
2583 search_data.set = FALSE;
2585 gtk_tree_model_foreach (model, tree_next_func, &search_data);
2587 *next = search_data.iter;
2589 gtk_tree_path_free (search_data.path);
2591 return search_data.set;
2595 tree_prev_func (GtkTreeModel *model,
2600 SearchData *search_data = (SearchData *)data;
2602 if (gtk_tree_path_compare (path, search_data->path) == 0)
2604 search_data->found = TRUE;
2608 if (!tree_column_row_is_sensitive (search_data->combo, iter))
2611 if (search_data->visible &&
2612 !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
2615 search_data->set = TRUE;
2616 search_data->iter = *iter;
2622 tree_prev (GtkComboBox *combo,
2623 GtkTreeModel *model,
2628 SearchData search_data;
2630 search_data.combo = combo;
2631 search_data.path = gtk_tree_model_get_path (model, iter);
2632 search_data.visible = visible;
2633 search_data.found = FALSE;
2634 search_data.set = FALSE;
2636 gtk_tree_model_foreach (model, tree_prev_func, &search_data);
2638 *prev = search_data.iter;
2640 gtk_tree_path_free (search_data.path);
2642 return search_data.set;
2646 tree_last_func (GtkTreeModel *model,
2651 SearchData *search_data = (SearchData *)data;
2653 if (!tree_column_row_is_sensitive (search_data->combo, iter))
2656 /* Note that we rely on the fact that collapsed rows don't have nodes
2658 if (search_data->visible &&
2659 !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
2662 search_data->set = TRUE;
2663 search_data->iter = *iter;
2669 tree_last (GtkComboBox *combo,
2670 GtkTreeModel *model,
2674 SearchData search_data;
2676 search_data.combo = combo;
2677 search_data.visible = visible;
2678 search_data.set = FALSE;
2680 gtk_tree_model_foreach (model, tree_last_func, &search_data);
2682 *last = search_data.iter;
2684 return search_data.set;
2689 tree_first_func (GtkTreeModel *model,
2694 SearchData *search_data = (SearchData *)data;
2696 if (!tree_column_row_is_sensitive (search_data->combo, iter))
2699 if (search_data->visible &&
2700 !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
2703 search_data->set = TRUE;
2704 search_data->iter = *iter;
2710 tree_first (GtkComboBox *combo,
2711 GtkTreeModel *model,
2715 SearchData search_data;
2717 search_data.combo = combo;
2718 search_data.visible = visible;
2719 search_data.set = FALSE;
2721 gtk_tree_model_foreach (model, tree_first_func, &search_data);
2723 *first = search_data.iter;
2725 return search_data.set;
2729 gtk_combo_box_scroll_event (GtkWidget *widget,
2730 GdkEventScroll *event)
2732 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
2735 GtkTreeIter new_iter;
2737 if (!gtk_combo_box_get_active_iter (combo_box, &iter))
2740 if (event->direction == GDK_SCROLL_UP)
2741 found = tree_prev (combo_box, combo_box->priv->model,
2742 &iter, &new_iter, FALSE);
2744 found = tree_next (combo_box, combo_box->priv->model,
2745 &iter, &new_iter, FALSE);
2748 gtk_combo_box_set_active_iter (combo_box, &new_iter);
2758 gtk_combo_box_sync_cells (GtkComboBox *combo_box,
2759 GtkCellLayout *cell_layout)
2761 GtkComboBoxPrivate *priv = combo_box->priv;
2764 for (k = priv->cells; k; k = k->next)
2767 ComboCellInfo *info = (ComboCellInfo *)k->data;
2769 if (info->pack == GTK_PACK_START)
2770 gtk_cell_layout_pack_start (cell_layout,
2771 info->cell, info->expand);
2772 else if (info->pack == GTK_PACK_END)
2773 gtk_cell_layout_pack_end (cell_layout,
2774 info->cell, info->expand);
2776 gtk_cell_layout_set_cell_data_func (cell_layout,
2778 combo_cell_data_func, info, NULL);
2780 for (j = info->attributes; j; j = j->next->next)
2782 gtk_cell_layout_add_attribute (cell_layout,
2785 GPOINTER_TO_INT (j->next->data));
2791 gtk_combo_box_menu_setup (GtkComboBox *combo_box,
2792 gboolean add_children)
2794 GtkComboBoxPrivate *priv = combo_box->priv;
2798 child = gtk_bin_get_child (GTK_BIN (combo_box));
2800 if (priv->cell_view)
2802 priv->button = gtk_toggle_button_new ();
2803 gtk_button_set_focus_on_click (GTK_BUTTON (priv->button),
2804 priv->focus_on_click);
2806 g_signal_connect (priv->button, "toggled",
2807 G_CALLBACK (gtk_combo_box_button_toggled), combo_box);
2808 gtk_widget_set_parent (priv->button,
2809 gtk_widget_get_parent (child));
2811 priv->box = gtk_hbox_new (FALSE, 0);
2812 gtk_container_add (GTK_CONTAINER (priv->button), priv->box);
2814 priv->separator = gtk_vseparator_new ();
2815 gtk_container_add (GTK_CONTAINER (priv->box), priv->separator);
2817 priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
2818 gtk_container_add (GTK_CONTAINER (priv->box), priv->arrow);
2820 gtk_widget_show_all (priv->button);
2824 priv->button = gtk_toggle_button_new ();
2825 gtk_button_set_focus_on_click (GTK_BUTTON (priv->button),
2826 priv->focus_on_click);
2828 g_signal_connect (priv->button, "toggled",
2829 G_CALLBACK (gtk_combo_box_button_toggled), combo_box);
2830 gtk_widget_set_parent (priv->button,
2831 gtk_widget_get_parent (child));
2833 priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
2834 gtk_container_add (GTK_CONTAINER (priv->button), priv->arrow);
2835 gtk_widget_show_all (priv->button);
2838 g_signal_connect (priv->button, "button-press-event",
2839 G_CALLBACK (gtk_combo_box_menu_button_press),
2841 g_signal_connect (priv->button, "state-changed",
2842 G_CALLBACK (gtk_combo_box_button_state_changed),
2845 /* create our funky menu */
2846 menu = gtk_menu_new ();
2847 gtk_widget_set_name (menu, "gtk-combobox-popup-menu");
2848 gtk_menu_set_reserve_toggle_size (GTK_MENU (menu), FALSE);
2850 g_signal_connect (menu, "key-press-event",
2851 G_CALLBACK (gtk_combo_box_menu_key_press), combo_box);
2852 gtk_combo_box_set_popup_widget (combo_box, menu);
2856 gtk_combo_box_menu_fill (combo_box);
2858 /* the column is needed in tree_column_row_is_sensitive() */
2859 priv->column = gtk_tree_view_column_new ();
2860 g_object_ref_sink (priv->column);
2861 gtk_combo_box_sync_cells (combo_box, GTK_CELL_LAYOUT (priv->column));
2863 gtk_combo_box_update_title (combo_box);
2864 gtk_combo_box_update_sensitivity (combo_box);
2868 gtk_combo_box_menu_fill (GtkComboBox *combo_box)
2870 GtkComboBoxPrivate *priv = combo_box->priv;
2876 menu = priv->popup_widget;
2878 if (priv->add_tearoffs)
2880 GtkWidget *tearoff = gtk_tearoff_menu_item_new ();
2882 gtk_widget_show (tearoff);
2884 if (priv->wrap_width)
2885 gtk_menu_attach (GTK_MENU (menu), tearoff, 0, priv->wrap_width, 0, 1);
2887 gtk_menu_shell_append (GTK_MENU_SHELL (menu), tearoff);
2890 gtk_combo_box_menu_fill_level (combo_box, menu, NULL);
2894 gtk_cell_view_menu_item_new (GtkComboBox *combo_box,
2895 GtkTreeModel *model,
2898 GtkWidget *cell_view;
2903 cell_view = gtk_cell_view_new ();
2904 item = gtk_menu_item_new ();
2905 gtk_container_add (GTK_CONTAINER (item), cell_view);
2907 gtk_cell_view_set_model (GTK_CELL_VIEW (cell_view), model);
2908 path = gtk_tree_model_get_path (model, iter);
2909 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (cell_view), path);
2910 gtk_tree_path_free (path);
2912 gtk_combo_box_sync_cells (combo_box, GTK_CELL_LAYOUT (cell_view));
2913 gtk_widget_size_request (cell_view, &req);
2914 gtk_widget_show (cell_view);
2920 gtk_combo_box_menu_fill_level (GtkComboBox *combo_box,
2922 GtkTreeIter *parent)
2924 GtkComboBoxPrivate *priv = combo_box->priv;
2925 GtkTreeModel *model = priv->model;
2926 GtkWidget *item, *submenu, *subitem, *separator;
2928 gboolean is_separator;
2933 n_children = gtk_tree_model_iter_n_children (model, parent);
2936 for (i = 0; i < n_children; i++)
2938 gtk_tree_model_iter_nth_child (model, &iter, parent, i);
2940 if (priv->row_separator_func)
2941 is_separator = priv->row_separator_func (priv->model, &iter,
2942 priv->row_separator_data);
2944 is_separator = FALSE;
2948 item = gtk_separator_menu_item_new ();
2949 path = gtk_tree_model_get_path (model, &iter);
2950 g_object_set_data_full (G_OBJECT (item),
2951 I_("gtk-combo-box-item-path"),
2952 gtk_tree_row_reference_new (model, path),
2953 (GDestroyNotify)gtk_tree_row_reference_free);
2954 gtk_tree_path_free (path);
2958 item = gtk_cell_view_menu_item_new (combo_box, model, &iter);
2959 if (gtk_tree_model_iter_has_child (model, &iter))
2961 submenu = gtk_menu_new ();
2962 gtk_menu_set_reserve_toggle_size (GTK_MENU (submenu), FALSE);
2963 gtk_widget_show (submenu);
2964 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
2966 /* Ugly - since menus can only activate leafs, we have to
2967 * duplicate the item inside the submenu.
2969 subitem = gtk_cell_view_menu_item_new (combo_box, model, &iter);
2970 separator = gtk_separator_menu_item_new ();
2971 gtk_widget_show (subitem);
2972 gtk_widget_show (separator);
2973 g_signal_connect (subitem, "activate",
2974 G_CALLBACK (gtk_combo_box_menu_item_activate),
2976 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), subitem);
2977 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), separator);
2979 gtk_combo_box_menu_fill_level (combo_box, submenu, &iter);
2981 g_signal_connect (item, "activate",
2982 G_CALLBACK (gtk_combo_box_menu_item_activate),
2986 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
2987 if (priv->wrap_width && menu == priv->popup_widget)
2988 gtk_combo_box_relayout_item (combo_box, item, &iter, last);
2989 gtk_widget_show (item);
2996 gtk_combo_box_menu_destroy (GtkComboBox *combo_box)
2998 GtkComboBoxPrivate *priv = combo_box->priv;
3000 g_signal_handlers_disconnect_matched (priv->button,
3001 G_SIGNAL_MATCH_DATA,
3003 gtk_combo_box_menu_button_press, NULL);
3004 g_signal_handlers_disconnect_matched (priv->button,
3005 G_SIGNAL_MATCH_DATA,
3007 gtk_combo_box_button_state_changed, combo_box);
3009 /* unparent will remove our latest ref */
3010 gtk_widget_unparent (priv->button);
3013 priv->button = NULL;
3015 priv->separator = NULL;
3017 g_object_unref (priv->column);
3018 priv->column = NULL;
3020 /* changing the popup window will unref the menu and the children */
3028 menu_occupied (GtkMenu *menu,
3032 guint bottom_attach)
3036 for (i = GTK_MENU_SHELL (menu)->children; i; i = i->next)
3040 gtk_container_child_get (GTK_CONTAINER (menu),
3044 "bottom-attach", &b,
3048 /* look if this item intersects with the given coordinates */
3049 if (right_attach > l && left_attach < r && bottom_attach > t && top_attach < b)
3057 gtk_combo_box_relayout_item (GtkComboBox *combo_box,
3062 GtkComboBoxPrivate *priv = combo_box->priv;
3063 gint current_col = 0, current_row = 0;
3064 gint rows = 1, cols = 1;
3065 GtkWidget *menu = priv->popup_widget;
3067 if (!GTK_IS_MENU_SHELL (menu))
3070 if (priv->col_column == -1 &&
3071 priv->row_column == -1 &&
3074 gtk_container_child_get (GTK_CONTAINER (menu),
3076 "right-attach", ¤t_col,
3077 "top-attach", ¤t_row,
3079 if (current_col + cols > priv->wrap_width)
3087 if (priv->col_column != -1)
3088 gtk_tree_model_get (priv->model, iter,
3089 priv->col_column, &cols,
3091 if (priv->row_column != -1)
3092 gtk_tree_model_get (priv->model, iter,
3093 priv->row_column, &rows,
3098 if (current_col + cols > priv->wrap_width)
3104 if (!menu_occupied (GTK_MENU (menu),
3105 current_col, current_col + cols,
3106 current_row, current_row + rows))
3113 /* set attach props */
3114 gtk_menu_attach (GTK_MENU (menu), item,
3115 current_col, current_col + cols,
3116 current_row, current_row + rows);
3120 gtk_combo_box_relayout (GtkComboBox *combo_box)
3125 menu = combo_box->priv->popup_widget;
3127 /* do nothing unless we are in menu style and realized */
3128 if (combo_box->priv->tree_view || !GTK_IS_MENU_SHELL (menu))
3131 list = gtk_container_get_children (GTK_CONTAINER (menu));
3133 for (j = g_list_last (list); j; j = j->prev)
3134 gtk_container_remove (GTK_CONTAINER (menu), j->data);
3136 gtk_combo_box_menu_fill (combo_box);
3143 gtk_combo_box_menu_button_press (GtkWidget *widget,
3144 GdkEventButton *event,
3147 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3148 GtkComboBoxPrivate *priv = combo_box->priv;
3150 if (GTK_IS_MENU (priv->popup_widget) &&
3151 event->type == GDK_BUTTON_PRESS && event->button == 1)
3153 if (priv->focus_on_click &&
3154 !gtk_widget_has_focus (priv->button))
3155 gtk_widget_grab_focus (priv->button);
3157 gtk_combo_box_menu_popup (combo_box, event->button, event->time);
3166 gtk_combo_box_menu_item_activate (GtkWidget *item,
3169 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3170 GtkWidget *cell_view;
3174 cell_view = gtk_bin_get_child (GTK_BIN (item));
3176 g_return_if_fail (GTK_IS_CELL_VIEW (cell_view));
3178 path = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (cell_view));
3180 if (gtk_tree_model_get_iter (combo_box->priv->model, &iter, path))
3182 if (gtk_menu_item_get_submenu (GTK_MENU_ITEM (item)) == NULL)
3183 gtk_combo_box_set_active_iter (combo_box, &iter);
3186 gtk_tree_path_free (path);
3188 g_object_set (combo_box,
3189 "editing-canceled", FALSE,
3194 gtk_combo_box_update_sensitivity (GtkComboBox *combo_box)
3197 gboolean sensitive = TRUE; /* fool code checkers */
3199 if (!combo_box->priv->button)
3202 switch (combo_box->priv->button_sensitivity)
3204 case GTK_SENSITIVITY_ON:
3207 case GTK_SENSITIVITY_OFF:
3210 case GTK_SENSITIVITY_AUTO:
3211 sensitive = combo_box->priv->model &&
3212 gtk_tree_model_get_iter_first (combo_box->priv->model, &iter);
3215 g_assert_not_reached ();
3219 gtk_widget_set_sensitive (combo_box->priv->button, sensitive);
3221 /* In list-mode, we also need to update sensitivity of the event box */
3222 if (GTK_IS_TREE_VIEW (combo_box->priv->tree_view)
3223 && combo_box->priv->cell_view)
3224 gtk_widget_set_sensitive (combo_box->priv->box, sensitive);
3228 gtk_combo_box_model_row_inserted (GtkTreeModel *model,
3233 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3235 if (combo_box->priv->tree_view)
3236 gtk_combo_box_list_popup_resize (combo_box);
3238 gtk_combo_box_menu_row_inserted (model, path, iter, user_data);
3240 gtk_combo_box_update_sensitivity (combo_box);
3244 gtk_combo_box_model_row_deleted (GtkTreeModel *model,
3248 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3249 GtkComboBoxPrivate *priv = combo_box->priv;
3251 if (!gtk_tree_row_reference_valid (priv->active_row))
3253 if (priv->cell_view)
3254 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (priv->cell_view), NULL);
3255 g_signal_emit (combo_box, combo_box_signals[CHANGED], 0);
3258 if (priv->tree_view)
3259 gtk_combo_box_list_popup_resize (combo_box);
3261 gtk_combo_box_menu_row_deleted (model, path, user_data);
3263 gtk_combo_box_update_sensitivity (combo_box);
3267 gtk_combo_box_model_rows_reordered (GtkTreeModel *model,
3273 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3275 gtk_tree_row_reference_reordered (G_OBJECT (user_data), path, iter, new_order);
3277 if (!combo_box->priv->tree_view)
3278 gtk_combo_box_menu_rows_reordered (model, path, iter, new_order, user_data);
3282 gtk_combo_box_model_row_changed (GtkTreeModel *model,
3287 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3288 GtkComboBoxPrivate *priv = combo_box->priv;
3289 GtkTreePath *active_path;
3291 /* FIXME this belongs to GtkCellView */
3292 if (gtk_tree_row_reference_valid (priv->active_row))
3294 active_path = gtk_tree_row_reference_get_path (priv->active_row);
3295 if (gtk_tree_path_compare (path, active_path) == 0 &&
3297 gtk_widget_queue_resize (GTK_WIDGET (priv->cell_view));
3298 gtk_tree_path_free (active_path);
3301 if (priv->tree_view)
3302 gtk_combo_box_list_row_changed (model, path, iter, user_data);
3304 gtk_combo_box_menu_row_changed (model, path, iter, user_data);
3308 list_popup_resize_idle (gpointer user_data)
3310 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3311 GtkComboBoxPrivate *priv = combo_box->priv;
3312 gint x, y, width, height;
3314 if (priv->tree_view && gtk_widget_get_mapped (priv->popup_window))
3316 gtk_combo_box_list_position (combo_box, &x, &y, &width, &height);
3318 gtk_widget_set_size_request (priv->popup_window, width, height);
3319 gtk_window_move (GTK_WINDOW (priv->popup_window), x, y);
3322 priv->resize_idle_id = 0;
3328 gtk_combo_box_list_popup_resize (GtkComboBox *combo_box)
3330 GtkComboBoxPrivate *priv = combo_box->priv;
3332 if (!priv->resize_idle_id)
3333 priv->resize_idle_id =
3334 gdk_threads_add_idle (list_popup_resize_idle, combo_box);
3338 gtk_combo_box_model_row_expanded (GtkTreeModel *model,
3343 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3345 gtk_combo_box_list_popup_resize (combo_box);
3350 find_menu_by_path (GtkWidget *menu,
3352 gboolean skip_first)
3358 GtkTreeRowReference *mref;
3362 list = gtk_container_get_children (GTK_CONTAINER (menu));
3365 for (i = list; i; i = i->next)
3367 child = gtk_bin_get_child (i->data);
3368 if (GTK_IS_SEPARATOR_MENU_ITEM (i->data))
3370 mref = g_object_get_data (G_OBJECT (i->data), "gtk-combo-box-item-path");
3373 else if (!gtk_tree_row_reference_valid (mref))
3376 mpath = gtk_tree_row_reference_get_path (mref);
3378 else if (GTK_IS_CELL_VIEW (child))
3386 mpath = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (child));
3391 /* this case is necessary, since the row reference of
3392 * the cell view may already be updated after a deletion
3399 if (gtk_tree_path_compare (mpath, path) == 0)
3401 gtk_tree_path_free (mpath);
3405 if (gtk_tree_path_is_ancestor (mpath, path))
3407 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
3408 if (submenu != NULL)
3410 gtk_tree_path_free (mpath);
3411 item = find_menu_by_path (submenu, path, TRUE);
3415 gtk_tree_path_free (mpath);
3425 dump_menu_tree (GtkWidget *menu,
3432 list = gtk_container_get_children (GTK_CONTAINER (menu));
3433 for (i = list; i; i = i->next)
3435 if (GTK_IS_CELL_VIEW (GTK_BIN (i->data)->child))
3437 path = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (GTK_BIN (i->data)->child));
3438 g_print ("%*s%s\n", 2 * level, " ", gtk_tree_path_to_string (path));
3439 gtk_tree_path_free (path);
3441 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
3442 if (submenu != NULL)
3443 dump_menu_tree (submenu, level + 1);
3452 gtk_combo_box_menu_row_inserted (GtkTreeModel *model,
3457 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3458 GtkComboBoxPrivate *priv = combo_box->priv;
3460 GtkWidget *item, *menu, *separator;
3464 gboolean is_separator;
3466 if (!priv->popup_widget)
3469 depth = gtk_tree_path_get_depth (path);
3470 pos = gtk_tree_path_get_indices (path)[depth - 1];
3473 ppath = gtk_tree_path_copy (path);
3474 gtk_tree_path_up (ppath);
3475 parent = find_menu_by_path (priv->popup_widget, ppath, FALSE);
3476 gtk_tree_path_free (ppath);
3478 menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (parent));
3481 menu = gtk_menu_new ();
3482 gtk_menu_set_reserve_toggle_size (GTK_MENU (menu), FALSE);
3483 gtk_widget_show (menu);
3484 gtk_menu_item_set_submenu (GTK_MENU_ITEM (parent), menu);
3486 /* Ugly - since menus can only activate leaves, we have to
3487 * duplicate the item inside the submenu.
3489 gtk_tree_model_iter_parent (model, &piter, iter);
3490 item = gtk_cell_view_menu_item_new (combo_box, model, &piter);
3491 separator = gtk_separator_menu_item_new ();
3492 g_signal_connect (item, "activate",
3493 G_CALLBACK (gtk_combo_box_menu_item_activate),
3495 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
3496 gtk_menu_shell_append (GTK_MENU_SHELL (menu), separator);
3497 if (cell_view_is_sensitive (GTK_CELL_VIEW (gtk_bin_get_child (GTK_BIN (item)))))
3499 gtk_widget_show (item);
3500 gtk_widget_show (separator);
3507 menu = priv->popup_widget;
3508 if (priv->add_tearoffs)
3512 if (priv->row_separator_func)
3513 is_separator = priv->row_separator_func (model, iter,
3514 priv->row_separator_data);
3516 is_separator = FALSE;
3520 item = gtk_separator_menu_item_new ();
3521 g_object_set_data_full (G_OBJECT (item),
3522 I_("gtk-combo-box-item-path"),
3523 gtk_tree_row_reference_new (model, path),
3524 (GDestroyNotify)gtk_tree_row_reference_free);
3528 item = gtk_cell_view_menu_item_new (combo_box, model, iter);
3530 g_signal_connect (item, "activate",
3531 G_CALLBACK (gtk_combo_box_menu_item_activate),
3535 gtk_widget_show (item);
3536 gtk_menu_shell_insert (GTK_MENU_SHELL (menu), item, pos);
3540 gtk_combo_box_menu_row_deleted (GtkTreeModel *model,
3544 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3545 GtkComboBoxPrivate *priv = combo_box->priv;
3549 if (!priv->popup_widget)
3552 item = find_menu_by_path (priv->popup_widget, path, FALSE);
3553 menu = gtk_widget_get_parent (item);
3554 gtk_container_remove (GTK_CONTAINER (menu), item);
3556 if (gtk_tree_path_get_depth (path) > 1)
3558 GtkTreePath *parent_path;
3562 parent_path = gtk_tree_path_copy (path);
3563 gtk_tree_path_up (parent_path);
3564 gtk_tree_model_get_iter (model, &iter, parent_path);
3566 if (!gtk_tree_model_iter_has_child (model, &iter))
3568 parent = find_menu_by_path (priv->popup_widget,
3569 parent_path, FALSE);
3570 gtk_menu_item_set_submenu (GTK_MENU_ITEM (parent), NULL);
3576 gtk_combo_box_menu_rows_reordered (GtkTreeModel *model,
3582 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3584 gtk_combo_box_relayout (combo_box);
3588 gtk_combo_box_menu_row_changed (GtkTreeModel *model,
3593 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3594 GtkComboBoxPrivate *priv = combo_box->priv;
3596 gboolean is_separator;
3598 if (!priv->popup_widget)
3601 item = find_menu_by_path (priv->popup_widget, path, FALSE);
3603 if (priv->row_separator_func)
3604 is_separator = priv->row_separator_func (model, iter,
3605 priv->row_separator_data);
3607 is_separator = FALSE;
3609 if (is_separator != GTK_IS_SEPARATOR_MENU_ITEM (item))
3611 gtk_combo_box_menu_row_deleted (model, path, combo_box);
3612 gtk_combo_box_menu_row_inserted (model, path, iter, combo_box);
3615 if (priv->wrap_width &&
3616 gtk_widget_get_parent (item) == priv->popup_widget)
3618 GtkWidget *pitem = NULL;
3621 prev = gtk_tree_path_copy (path);
3623 if (gtk_tree_path_prev (prev))
3624 pitem = find_menu_by_path (priv->popup_widget, prev, FALSE);
3626 gtk_tree_path_free (prev);
3628 /* unattach item so gtk_combo_box_relayout_item() won't spuriously
3630 gtk_container_child_set (GTK_CONTAINER (priv->popup_widget),
3635 "bottom-attach", -1,
3638 gtk_combo_box_relayout_item (combo_box, item, iter, pitem);
3641 gtk_combo_box_update_requested_width (combo_box, path);
3649 gtk_combo_box_list_setup (GtkComboBox *combo_box)
3651 GtkComboBoxPrivate *priv = combo_box->priv;
3652 GtkTreeSelection *sel;
3655 GtkWidget *widget = GTK_WIDGET (combo_box);
3657 priv->button = gtk_toggle_button_new ();
3658 child = gtk_bin_get_child (GTK_BIN (combo_box));
3659 gtk_widget_set_parent (priv->button,
3660 gtk_widget_get_parent (child));
3661 g_signal_connect (priv->button, "button-press-event",
3662 G_CALLBACK (gtk_combo_box_list_button_pressed), combo_box);
3663 g_signal_connect (priv->button, "toggled",
3664 G_CALLBACK (gtk_combo_box_button_toggled), combo_box);
3666 priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
3667 gtk_container_add (GTK_CONTAINER (priv->button), priv->arrow);
3668 priv->separator = NULL;
3669 gtk_widget_show_all (priv->button);
3671 if (priv->cell_view)
3673 style = gtk_widget_get_style (widget);
3674 gtk_cell_view_set_background_color (GTK_CELL_VIEW (priv->cell_view),
3675 &style->base[gtk_widget_get_state (widget)]);
3677 priv->box = gtk_event_box_new ();
3678 gtk_event_box_set_visible_window (GTK_EVENT_BOX (priv->box),
3681 if (priv->has_frame)
3683 priv->cell_view_frame = gtk_frame_new (NULL);
3684 gtk_frame_set_shadow_type (GTK_FRAME (priv->cell_view_frame),
3689 combo_box->priv->cell_view_frame = gtk_event_box_new ();
3690 gtk_event_box_set_visible_window (GTK_EVENT_BOX (combo_box->priv->cell_view_frame),
3694 gtk_widget_set_parent (priv->cell_view_frame,
3695 gtk_widget_get_parent (child));
3696 gtk_container_add (GTK_CONTAINER (priv->cell_view_frame), priv->box);
3697 gtk_widget_show_all (priv->cell_view_frame);
3699 g_signal_connect (priv->box, "button-press-event",
3700 G_CALLBACK (gtk_combo_box_list_button_pressed),
3704 priv->tree_view = gtk_tree_view_new ();
3705 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view));
3706 gtk_tree_selection_set_mode (sel, GTK_SELECTION_BROWSE);
3707 gtk_tree_selection_set_select_function (sel,
3708 gtk_combo_box_list_select_func,
3710 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->tree_view),
3712 gtk_tree_view_set_hover_selection (GTK_TREE_VIEW (priv->tree_view),
3714 if (priv->row_separator_func)
3715 gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (priv->tree_view),
3716 priv->row_separator_func,
3717 priv->row_separator_data,
3720 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->tree_view), priv->model);
3722 priv->column = gtk_tree_view_column_new ();
3723 gtk_tree_view_append_column (GTK_TREE_VIEW (priv->tree_view), priv->column);
3726 gtk_combo_box_sync_cells (combo_box,
3727 GTK_CELL_LAYOUT (priv->column));
3729 if (gtk_tree_row_reference_valid (priv->active_row))
3733 path = gtk_tree_row_reference_get_path (priv->active_row);
3734 gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->tree_view),
3736 gtk_tree_path_free (path);
3739 /* set sample/popup widgets */
3740 gtk_combo_box_set_popup_widget (combo_box, priv->tree_view);
3742 g_signal_connect (priv->tree_view, "key-press-event",
3743 G_CALLBACK (gtk_combo_box_list_key_press),
3745 g_signal_connect (priv->tree_view, "enter-notify-event",
3746 G_CALLBACK (gtk_combo_box_list_enter_notify),
3748 g_signal_connect (priv->tree_view, "row-expanded",
3749 G_CALLBACK (gtk_combo_box_model_row_expanded),
3751 g_signal_connect (priv->tree_view, "row-collapsed",
3752 G_CALLBACK (gtk_combo_box_model_row_expanded),
3754 g_signal_connect (priv->popup_window, "button-press-event",
3755 G_CALLBACK (gtk_combo_box_list_button_pressed),
3757 g_signal_connect (priv->popup_window, "button-release-event",
3758 G_CALLBACK (gtk_combo_box_list_button_released),
3761 gtk_widget_show (priv->tree_view);
3763 gtk_combo_box_update_sensitivity (combo_box);
3767 gtk_combo_box_list_destroy (GtkComboBox *combo_box)
3769 GtkComboBoxPrivate *priv = combo_box->priv;
3771 /* disconnect signals */
3772 g_signal_handlers_disconnect_matched (priv->tree_view,
3773 G_SIGNAL_MATCH_DATA,
3774 0, 0, NULL, NULL, combo_box);
3775 g_signal_handlers_disconnect_matched (priv->button,
3776 G_SIGNAL_MATCH_DATA,
3778 gtk_combo_box_list_button_pressed,
3780 g_signal_handlers_disconnect_matched (priv->popup_window,
3781 G_SIGNAL_MATCH_DATA,
3783 gtk_combo_box_list_button_pressed,
3785 g_signal_handlers_disconnect_matched (priv->popup_window,
3786 G_SIGNAL_MATCH_DATA,
3788 gtk_combo_box_list_button_released,
3791 g_signal_handlers_disconnect_matched (priv->popup_window,
3792 G_SIGNAL_MATCH_DATA,
3794 gtk_combo_box_child_show,
3797 g_signal_handlers_disconnect_matched (priv->popup_window,
3798 G_SIGNAL_MATCH_DATA,
3800 gtk_combo_box_child_hide,
3804 g_signal_handlers_disconnect_matched (priv->box,
3805 G_SIGNAL_MATCH_DATA,
3807 gtk_combo_box_list_button_pressed,
3810 /* destroy things (unparent will kill the latest ref from us)
3811 * last unref on button will destroy the arrow
3813 gtk_widget_unparent (priv->button);
3814 priv->button = NULL;
3817 if (priv->cell_view)
3819 g_object_set (priv->cell_view,
3820 "background-set", FALSE,
3824 if (priv->cell_view_frame)
3826 gtk_widget_unparent (priv->cell_view_frame);
3827 priv->cell_view_frame = NULL;
3831 if (priv->scroll_timer)
3833 g_source_remove (priv->scroll_timer);
3834 priv->scroll_timer = 0;
3837 if (priv->resize_idle_id)
3839 g_source_remove (priv->resize_idle_id);
3840 priv->resize_idle_id = 0;
3843 gtk_widget_destroy (priv->tree_view);
3845 priv->tree_view = NULL;
3846 if (priv->popup_widget)
3848 g_object_unref (priv->popup_widget);
3849 priv->popup_widget = NULL;
3856 gtk_combo_box_list_button_pressed (GtkWidget *widget,
3857 GdkEventButton *event,
3860 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3861 GtkComboBoxPrivate *priv = combo_box->priv;
3863 GtkWidget *ewidget = gtk_get_event_widget ((GdkEvent *)event);
3865 if (ewidget == priv->popup_window)
3868 if ((ewidget != priv->button && ewidget != priv->box) ||
3869 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->button)))
3872 if (priv->focus_on_click &&
3873 !gtk_widget_has_focus (priv->button))
3874 gtk_widget_grab_focus (priv->button);
3876 gtk_combo_box_popup_for_device (combo_box, event->device);
3878 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->button), TRUE);
3880 priv->auto_scroll = FALSE;
3881 if (priv->scroll_timer == 0)
3882 priv->scroll_timer = gdk_threads_add_timeout (SCROLL_TIME,
3883 (GSourceFunc) gtk_combo_box_list_scroll_timeout,
3886 priv->popup_in_progress = TRUE;
3892 gtk_combo_box_list_button_released (GtkWidget *widget,
3893 GdkEventButton *event,
3897 GtkTreePath *path = NULL;
3900 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3901 GtkComboBoxPrivate *priv = combo_box->priv;
3903 gboolean popup_in_progress = FALSE;
3905 GtkWidget *ewidget = gtk_get_event_widget ((GdkEvent *)event);
3907 if (priv->popup_in_progress)
3909 popup_in_progress = TRUE;
3910 priv->popup_in_progress = FALSE;
3913 gtk_tree_view_set_hover_expand (GTK_TREE_VIEW (priv->tree_view),
3915 if (priv->scroll_timer)
3917 g_source_remove (priv->scroll_timer);
3918 priv->scroll_timer = 0;
3921 if (ewidget != priv->tree_view)
3923 if ((ewidget == priv->button ||
3924 ewidget == priv->box) &&
3925 !popup_in_progress &&
3926 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->button)))
3928 gtk_combo_box_popdown (combo_box);
3932 /* released outside treeview */
3933 if (ewidget != priv->button && ewidget != priv->box)
3935 gtk_combo_box_popdown (combo_box);
3943 /* select something cool */
3944 ret = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (priv->tree_view),
3950 return TRUE; /* clicked outside window? */
3952 gtk_tree_model_get_iter (priv->model, &iter, path);
3953 gtk_tree_path_free (path);
3955 gtk_combo_box_popdown (combo_box);
3957 if (tree_column_row_is_sensitive (combo_box, &iter))
3958 gtk_combo_box_set_active_iter (combo_box, &iter);
3964 gtk_combo_box_menu_key_press (GtkWidget *widget,
3968 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3970 if (!gtk_bindings_activate_event (GTK_OBJECT (widget), event))
3972 /* The menu hasn't managed the
3973 * event, forward it to the combobox
3975 gtk_bindings_activate_event (GTK_OBJECT (combo_box), event);
3982 gtk_combo_box_list_key_press (GtkWidget *widget,
3986 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3989 if (event->keyval == GDK_KEY_Return || event->keyval == GDK_KEY_ISO_Enter || event->keyval == GDK_KEY_KP_Enter ||
3990 event->keyval == GDK_KEY_space || event->keyval == GDK_KEY_KP_Space)
3992 GtkTreeModel *model = NULL;
3994 gtk_combo_box_popdown (combo_box);
3996 if (combo_box->priv->model)
3998 GtkTreeSelection *sel;
4000 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (combo_box->priv->tree_view));
4002 if (gtk_tree_selection_get_selected (sel, &model, &iter))
4003 gtk_combo_box_set_active_iter (combo_box, &iter);
4009 if (!gtk_bindings_activate_event (GTK_OBJECT (widget), event))
4011 /* The list hasn't managed the
4012 * event, forward it to the combobox
4014 gtk_bindings_activate_event (GTK_OBJECT (combo_box), event);
4021 gtk_combo_box_list_auto_scroll (GtkComboBox *combo_box,
4026 GtkAllocation allocation;
4027 GtkWidget *tree_view = combo_box->priv->tree_view;
4030 gtk_widget_get_allocation (tree_view, &allocation);
4032 adj = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (combo_box->priv->scrolled_window));
4033 if (adj && adj->upper - adj->lower > adj->page_size)
4035 if (x <= allocation.x &&
4036 adj->lower < adj->value)
4038 value = adj->value - (allocation.x - x + 1);
4039 gtk_adjustment_set_value (adj, value);
4041 else if (x >= allocation.x + allocation.width &&
4042 adj->upper - adj->page_size > adj->value)
4044 value = adj->value + (x - allocation.x - allocation.width + 1);
4045 gtk_adjustment_set_value (adj, MAX (value, 0.0));
4049 adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (combo_box->priv->scrolled_window));
4050 if (adj && adj->upper - adj->lower > adj->page_size)
4052 if (y <= allocation.y &&
4053 adj->lower < adj->value)
4055 value = adj->value - (allocation.y - y + 1);
4056 gtk_adjustment_set_value (adj, value);
4058 else if (y >= allocation.height &&
4059 adj->upper - adj->page_size > adj->value)
4061 value = adj->value + (y - allocation.height + 1);
4062 gtk_adjustment_set_value (adj, MAX (value, 0.0));
4068 gtk_combo_box_list_scroll_timeout (GtkComboBox *combo_box)
4070 GtkComboBoxPrivate *priv = combo_box->priv;
4073 if (priv->auto_scroll)
4075 gdk_window_get_device_position (gtk_widget_get_window (priv->tree_view),
4078 gtk_combo_box_list_auto_scroll (combo_box, x, y);
4085 gtk_combo_box_list_enter_notify (GtkWidget *widget,
4086 GdkEventCrossing *event,
4089 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
4091 combo_box->priv->auto_scroll = TRUE;
4097 gtk_combo_box_list_select_func (GtkTreeSelection *selection,
4098 GtkTreeModel *model,
4100 gboolean path_currently_selected,
4104 gboolean sensitive = FALSE;
4106 for (list = selection->tree_view->priv->columns; list && !sensitive; list = list->next)
4108 GList *cells, *cell;
4109 gboolean cell_sensitive, cell_visible;
4111 GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN (list->data);
4113 if (!column->visible)
4116 gtk_tree_model_get_iter (model, &iter, path);
4117 gtk_tree_view_column_cell_set_cell_data (column, model, &iter,
4120 cell = cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (column));
4123 g_object_get (cell->data,
4124 "sensitive", &cell_sensitive,
4125 "visible", &cell_visible,
4128 if (cell_visible && cell_sensitive)
4133 g_list_free (cells);
4135 sensitive = cell_sensitive;
4142 gtk_combo_box_list_row_changed (GtkTreeModel *model,
4147 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
4149 gtk_combo_box_update_requested_width (combo_box, path);
4153 * GtkCellLayout implementation
4157 pack_start_recurse (GtkWidget *menu,
4158 GtkCellRenderer *cell,
4165 list = gtk_container_get_children (GTK_CONTAINER (menu));
4166 for (i = list; i; i = i->next)
4168 child = gtk_bin_get_child (GTK_BIN (i->data));
4169 if (GTK_IS_CELL_LAYOUT (child))
4170 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (child),
4173 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4174 if (submenu != NULL)
4175 pack_start_recurse (submenu, cell, expand);
4182 gtk_combo_box_cell_layout_pack_start (GtkCellLayout *layout,
4183 GtkCellRenderer *cell,
4186 GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
4187 ComboCellInfo *info;
4188 GtkComboBoxPrivate *priv;
4190 priv = combo_box->priv;
4192 g_object_ref_sink (cell);
4194 info = g_slice_new0 (ComboCellInfo);
4196 info->expand = expand;
4197 info->pack = GTK_PACK_START;
4199 priv->cells = g_slist_append (priv->cells, info);
4201 if (priv->cell_view)
4203 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (priv->cell_view),
4209 gtk_tree_view_column_pack_start (priv->column, cell, expand);
4211 if (GTK_IS_MENU (priv->popup_widget))
4212 pack_start_recurse (priv->popup_widget, cell, expand);
4216 pack_end_recurse (GtkWidget *menu,
4217 GtkCellRenderer *cell,
4224 list = gtk_container_get_children (GTK_CONTAINER (menu));
4225 for (i = list; i; i = i->next)
4227 child = gtk_bin_get_child (GTK_BIN (i->data));
4228 if (GTK_IS_CELL_LAYOUT (child))
4229 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (child),
4232 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4233 if (submenu != NULL)
4234 pack_end_recurse (submenu, cell, expand);
4241 gtk_combo_box_cell_layout_pack_end (GtkCellLayout *layout,
4242 GtkCellRenderer *cell,
4245 GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
4246 ComboCellInfo *info;
4247 GtkComboBoxPrivate *priv;
4249 priv = combo_box->priv;
4251 g_object_ref_sink (cell);
4253 info = g_slice_new0 (ComboCellInfo);
4255 info->expand = expand;
4256 info->pack = GTK_PACK_END;
4258 priv->cells = g_slist_append (priv->cells, info);
4260 if (priv->cell_view)
4261 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (priv->cell_view),
4265 gtk_tree_view_column_pack_end (priv->column, cell, expand);
4267 if (GTK_IS_MENU (priv->popup_widget))
4268 pack_end_recurse (priv->popup_widget, cell, expand);
4272 gtk_combo_box_cell_layout_get_cells (GtkCellLayout *layout)
4274 GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
4276 GList *retval = NULL;
4278 for (list = combo_box->priv->cells; list; list = list->next)
4280 ComboCellInfo *info = (ComboCellInfo *)list->data;
4282 retval = g_list_prepend (retval, info->cell);
4285 return g_list_reverse (retval);
4289 clear_recurse (GtkWidget *menu)
4295 list = gtk_container_get_children (GTK_CONTAINER (menu));
4296 for (i = list; i; i = i->next)
4298 child = gtk_bin_get_child (GTK_BIN (i->data));
4299 if (GTK_IS_CELL_LAYOUT (child))
4300 gtk_cell_layout_clear (GTK_CELL_LAYOUT (child));
4302 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4303 if (submenu != NULL)
4304 clear_recurse (submenu);
4311 gtk_combo_box_cell_layout_clear (GtkCellLayout *layout)
4313 GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
4314 GtkComboBoxPrivate *priv = combo_box->priv;
4317 if (priv->cell_view)
4318 gtk_cell_layout_clear (GTK_CELL_LAYOUT (priv->cell_view));
4321 gtk_tree_view_column_clear (priv->column);
4323 for (i = priv->cells; i; i = i->next)
4325 ComboCellInfo *info = (ComboCellInfo *)i->data;
4327 gtk_combo_box_cell_layout_clear_attributes (layout, info->cell);
4328 g_object_unref (info->cell);
4329 g_slice_free (ComboCellInfo, info);
4332 g_slist_free (priv->cells);
4335 if (GTK_IS_MENU (priv->popup_widget))
4336 clear_recurse (priv->popup_widget);
4340 add_attribute_recurse (GtkWidget *menu,
4341 GtkCellRenderer *cell,
4342 const gchar *attribute,
4349 list = gtk_container_get_children (GTK_CONTAINER (menu));
4350 for (i = list; i; i = i->next)
4352 child = gtk_bin_get_child (GTK_BIN (i->data));
4353 if (GTK_IS_CELL_LAYOUT (child))
4354 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (child),
4355 cell, attribute, column);
4357 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4358 if (submenu != NULL)
4359 add_attribute_recurse (submenu, cell, attribute, column);
4366 gtk_combo_box_cell_layout_add_attribute (GtkCellLayout *layout,
4367 GtkCellRenderer *cell,
4368 const gchar *attribute,
4371 GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
4372 ComboCellInfo *info;
4374 info = gtk_combo_box_get_cell_info (combo_box, cell);
4375 g_return_if_fail (info != NULL);
4377 info->attributes = g_slist_prepend (info->attributes,
4378 GINT_TO_POINTER (column));
4379 info->attributes = g_slist_prepend (info->attributes,
4380 g_strdup (attribute));
4382 if (combo_box->priv->cell_view)
4383 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo_box->priv->cell_view),
4384 cell, attribute, column);
4386 if (combo_box->priv->column)
4387 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo_box->priv->column),
4388 cell, attribute, column);
4390 if (GTK_IS_MENU (combo_box->priv->popup_widget))
4391 add_attribute_recurse (combo_box->priv->popup_widget, cell, attribute, column);
4392 gtk_widget_queue_resize (GTK_WIDGET (combo_box));
4396 combo_cell_data_func (GtkCellLayout *cell_layout,
4397 GtkCellRenderer *cell,
4398 GtkTreeModel *tree_model,
4402 ComboCellInfo *info = (ComboCellInfo *)data;
4403 GtkWidget *parent = NULL;
4408 info->func (cell_layout, cell, tree_model, iter, info->func_data);
4410 if (GTK_IS_WIDGET (cell_layout))
4411 parent = gtk_widget_get_parent (GTK_WIDGET (cell_layout));
4413 if (GTK_IS_MENU_ITEM (parent) &&
4414 gtk_menu_item_get_submenu (GTK_MENU_ITEM (parent)))
4415 g_object_set (cell, "sensitive", TRUE, NULL);
4420 set_cell_data_func_recurse (GtkWidget *menu,
4421 GtkCellRenderer *cell,
4422 ComboCellInfo *info)
4426 GtkWidget *cell_view;
4428 list = gtk_container_get_children (GTK_CONTAINER (menu));
4429 for (i = list; i; i = i->next)
4431 cell_view = gtk_bin_get_child (GTK_BIN (i->data));
4432 if (GTK_IS_CELL_LAYOUT (cell_view))
4434 /* Override sensitivity for inner nodes; we don't
4435 * want menuitems with submenus to appear insensitive
4437 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (cell_view),
4439 combo_cell_data_func,
4441 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4442 if (submenu != NULL)
4443 set_cell_data_func_recurse (submenu, cell, info);
4451 gtk_combo_box_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4452 GtkCellRenderer *cell,
4453 GtkCellLayoutDataFunc func,
4455 GDestroyNotify destroy)
4457 GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
4458 GtkComboBoxPrivate *priv = combo_box->priv;
4459 ComboCellInfo *info;
4461 info = gtk_combo_box_get_cell_info (combo_box, cell);
4462 g_return_if_fail (info != NULL);
4466 GDestroyNotify d = info->destroy;
4468 info->destroy = NULL;
4469 d (info->func_data);
4473 info->func_data = func_data;
4474 info->destroy = destroy;
4476 if (priv->cell_view)
4477 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (priv->cell_view), cell, func, func_data, NULL);
4480 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (priv->column), cell, func, func_data, NULL);
4482 if (GTK_IS_MENU (priv->popup_widget))
4483 set_cell_data_func_recurse (priv->popup_widget, cell, info);
4485 gtk_widget_queue_resize (GTK_WIDGET (combo_box));
4489 clear_attributes_recurse (GtkWidget *menu,
4490 GtkCellRenderer *cell)
4496 list = gtk_container_get_children (GTK_CONTAINER (menu));
4497 for (i = list; i; i = i->next)
4499 child = gtk_bin_get_child (GTK_BIN (i->data));
4500 if (GTK_IS_CELL_LAYOUT (child))
4501 gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (child), cell);
4503 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4504 if (submenu != NULL)
4505 clear_attributes_recurse (submenu, cell);
4512 gtk_combo_box_cell_layout_clear_attributes (GtkCellLayout *layout,
4513 GtkCellRenderer *cell)
4515 GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
4516 GtkComboBoxPrivate *priv;
4517 ComboCellInfo *info;
4520 priv = combo_box->priv;
4522 info = gtk_combo_box_get_cell_info (combo_box, cell);
4523 g_return_if_fail (info != NULL);
4525 list = info->attributes;
4526 while (list && list->next)
4528 g_free (list->data);
4529 list = list->next->next;
4531 g_slist_free (info->attributes);
4532 info->attributes = NULL;
4534 if (priv->cell_view)
4535 gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (priv->cell_view), cell);
4538 gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (priv->column), cell);
4540 if (GTK_IS_MENU (priv->popup_widget))
4541 clear_attributes_recurse (priv->popup_widget, cell);
4543 gtk_widget_queue_resize (GTK_WIDGET (combo_box));
4547 reorder_recurse (GtkWidget *menu,
4548 GtkCellRenderer *cell,
4555 list = gtk_container_get_children (GTK_CONTAINER (menu));
4556 for (i = list; i; i = i->next)
4558 child = gtk_bin_get_child (GTK_BIN (i->data));
4559 if (GTK_IS_CELL_LAYOUT (child))
4560 gtk_cell_layout_reorder (GTK_CELL_LAYOUT (child),
4563 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4564 if (submenu != NULL)
4565 reorder_recurse (submenu, cell, position);
4572 gtk_combo_box_cell_layout_reorder (GtkCellLayout *layout,
4573 GtkCellRenderer *cell,
4576 GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
4577 GtkComboBoxPrivate *priv;
4578 ComboCellInfo *info;
4581 priv = combo_box->priv;
4583 info = gtk_combo_box_get_cell_info (combo_box, cell);
4585 g_return_if_fail (info != NULL);
4586 g_return_if_fail (position >= 0);
4588 link = g_slist_find (priv->cells, info);
4590 g_return_if_fail (link != NULL);
4592 priv->cells = g_slist_delete_link (priv->cells, link);
4593 priv->cells = g_slist_insert (priv->cells, info, position);
4595 if (priv->cell_view)
4596 gtk_cell_layout_reorder (GTK_CELL_LAYOUT (priv->cell_view),
4600 gtk_cell_layout_reorder (GTK_CELL_LAYOUT (priv->column),
4603 if (GTK_IS_MENU (priv->popup_widget))
4604 reorder_recurse (priv->popup_widget, cell, position);
4606 gtk_widget_queue_draw (GTK_WIDGET (combo_box));
4614 * gtk_combo_box_new:
4616 * Creates a new empty #GtkComboBox.
4618 * Return value: A new #GtkComboBox.
4623 gtk_combo_box_new (void)
4625 return g_object_new (GTK_TYPE_COMBO_BOX, NULL);
4629 * gtk_combo_box_new_with_model:
4630 * @model: A #GtkTreeModel.
4632 * Creates a new #GtkComboBox with the model initialized to @model.
4634 * Return value: A new #GtkComboBox.
4639 gtk_combo_box_new_with_model (GtkTreeModel *model)
4641 GtkComboBox *combo_box;
4643 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
4645 combo_box = g_object_new (GTK_TYPE_COMBO_BOX, "model", model, NULL);
4647 return GTK_WIDGET (combo_box);
4651 * gtk_combo_box_get_wrap_width:
4652 * @combo_box: A #GtkComboBox
4654 * Returns the wrap width which is used to determine the number of columns
4655 * for the popup menu. If the wrap width is larger than 1, the combo box
4658 * Returns: the wrap width.
4663 gtk_combo_box_get_wrap_width (GtkComboBox *combo_box)
4665 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), -1);
4667 return combo_box->priv->wrap_width;
4671 * gtk_combo_box_set_wrap_width:
4672 * @combo_box: A #GtkComboBox
4673 * @width: Preferred number of columns
4675 * Sets the wrap width of @combo_box to be @width. The wrap width is basically
4676 * the preferred number of columns when you want the popup to be layed out
4682 gtk_combo_box_set_wrap_width (GtkComboBox *combo_box,
4685 GtkComboBoxPrivate *priv;
4687 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4688 g_return_if_fail (width >= 0);
4690 priv = combo_box->priv;
4692 if (width != priv->wrap_width)
4694 priv->wrap_width = width;
4696 gtk_combo_box_check_appearance (combo_box);
4697 gtk_combo_box_relayout (combo_box);
4699 g_object_notify (G_OBJECT (combo_box), "wrap-width");
4704 * gtk_combo_box_get_row_span_column:
4705 * @combo_box: A #GtkComboBox
4707 * Returns the column with row span information for @combo_box.
4709 * Returns: the row span column.
4714 gtk_combo_box_get_row_span_column (GtkComboBox *combo_box)
4716 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), -1);
4718 return combo_box->priv->row_column;
4722 * gtk_combo_box_set_row_span_column:
4723 * @combo_box: A #GtkComboBox.
4724 * @row_span: A column in the model passed during construction.
4726 * Sets the column with row span information for @combo_box to be @row_span.
4727 * The row span column contains integers which indicate how many rows
4728 * an item should span.
4733 gtk_combo_box_set_row_span_column (GtkComboBox *combo_box,
4736 GtkComboBoxPrivate *priv;
4739 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4741 priv = combo_box->priv;
4743 col = gtk_tree_model_get_n_columns (priv->model);
4744 g_return_if_fail (row_span >= -1 && row_span < col);
4746 if (row_span != priv->row_column)
4748 priv->row_column = row_span;
4750 gtk_combo_box_relayout (combo_box);
4752 g_object_notify (G_OBJECT (combo_box), "row-span-column");
4757 * gtk_combo_box_get_column_span_column:
4758 * @combo_box: A #GtkComboBox
4760 * Returns the column with column span information for @combo_box.
4762 * Returns: the column span column.
4767 gtk_combo_box_get_column_span_column (GtkComboBox *combo_box)
4769 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), -1);
4771 return combo_box->priv->col_column;
4775 * gtk_combo_box_set_column_span_column:
4776 * @combo_box: A #GtkComboBox
4777 * @column_span: A column in the model passed during construction
4779 * Sets the column with column span information for @combo_box to be
4780 * @column_span. The column span column contains integers which indicate
4781 * how many columns an item should span.
4786 gtk_combo_box_set_column_span_column (GtkComboBox *combo_box,
4789 GtkComboBoxPrivate *priv;
4792 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4794 priv = combo_box->priv;
4796 col = gtk_tree_model_get_n_columns (priv->model);
4797 g_return_if_fail (column_span >= -1 && column_span < col);
4799 if (column_span != priv->col_column)
4801 priv->col_column = column_span;
4803 gtk_combo_box_relayout (combo_box);
4805 g_object_notify (G_OBJECT (combo_box), "column-span-column");
4810 * gtk_combo_box_get_active:
4811 * @combo_box: A #GtkComboBox
4813 * Returns the index of the currently active item, or -1 if there's no
4814 * active item. If the model is a non-flat treemodel, and the active item
4815 * is not an immediate child of the root of the tree, this function returns
4816 * <literal>gtk_tree_path_get_indices (path)[0]</literal>, where
4817 * <literal>path</literal> is the #GtkTreePath of the active item.
4819 * Return value: An integer which is the index of the currently active item,
4820 * or -1 if there's no active item.
4825 gtk_combo_box_get_active (GtkComboBox *combo_box)
4827 GtkComboBoxPrivate *priv;
4830 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), 0);
4832 priv = combo_box->priv;
4834 if (gtk_tree_row_reference_valid (priv->active_row))
4838 path = gtk_tree_row_reference_get_path (priv->active_row);
4839 result = gtk_tree_path_get_indices (path)[0];
4840 gtk_tree_path_free (path);
4849 * gtk_combo_box_set_active:
4850 * @combo_box: A #GtkComboBox
4851 * @index_: An index in the model passed during construction, or -1 to have
4854 * Sets the active item of @combo_box to be the item at @index.
4859 gtk_combo_box_set_active (GtkComboBox *combo_box,
4862 GtkTreePath *path = NULL;
4863 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4864 g_return_if_fail (index_ >= -1);
4866 if (combo_box->priv->model == NULL)
4868 /* Save index, in case the model is set after the index */
4869 combo_box->priv->active = index_;
4875 path = gtk_tree_path_new_from_indices (index_, -1);
4877 gtk_combo_box_set_active_internal (combo_box, path);
4880 gtk_tree_path_free (path);
4884 gtk_combo_box_set_active_internal (GtkComboBox *combo_box,
4887 GtkComboBoxPrivate *priv = combo_box->priv;
4888 GtkTreePath *active_path;
4891 /* Remember whether the initially active row is valid. */
4892 gboolean is_valid_row_reference = gtk_tree_row_reference_valid (priv->active_row);
4894 if (path && is_valid_row_reference)
4896 active_path = gtk_tree_row_reference_get_path (priv->active_row);
4897 path_cmp = gtk_tree_path_compare (path, active_path);
4898 gtk_tree_path_free (active_path);
4903 if (priv->active_row)
4905 gtk_tree_row_reference_free (priv->active_row);
4906 priv->active_row = NULL;
4911 if (priv->tree_view)
4912 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view)));
4915 GtkMenu *menu = GTK_MENU (priv->popup_widget);
4917 if (GTK_IS_MENU (menu))
4918 gtk_menu_set_active (menu, -1);
4921 if (priv->cell_view)
4922 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (priv->cell_view), NULL);
4925 * Do not emit a "changed" signal when an already invalid selection was
4926 * now set to invalid.
4928 if (!is_valid_row_reference)
4934 gtk_tree_row_reference_new (priv->model, path);
4936 if (priv->tree_view)
4938 gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->tree_view),
4941 else if (GTK_IS_MENU (priv->popup_widget))
4943 /* FIXME handle nested menus better */
4944 gtk_menu_set_active (GTK_MENU (priv->popup_widget),
4945 gtk_tree_path_get_indices (path)[0]);
4948 if (priv->cell_view)
4949 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (priv->cell_view),
4953 g_signal_emit (combo_box, combo_box_signals[CHANGED], 0);
4954 g_object_notify (G_OBJECT (combo_box), "active");
4959 * gtk_combo_box_get_active_iter:
4960 * @combo_box: A #GtkComboBox
4961 * @iter: (out): The uninitialized #GtkTreeIter
4963 * Sets @iter to point to the current active item, if it exists.
4965 * Return value: %TRUE, if @iter was set
4970 gtk_combo_box_get_active_iter (GtkComboBox *combo_box,
4976 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE);
4978 if (!gtk_tree_row_reference_valid (combo_box->priv->active_row))
4981 path = gtk_tree_row_reference_get_path (combo_box->priv->active_row);
4982 result = gtk_tree_model_get_iter (combo_box->priv->model, iter, path);
4983 gtk_tree_path_free (path);
4989 * gtk_combo_box_set_active_iter:
4990 * @combo_box: A #GtkComboBox
4991 * @iter: (allow-none): The #GtkTreeIter, or %NULL
4993 * Sets the current active item to be the one referenced by @iter, or
4994 * unsets the active item if @iter is %NULL.
4999 gtk_combo_box_set_active_iter (GtkComboBox *combo_box,
5002 GtkTreePath *path = NULL;
5004 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5007 path = gtk_tree_model_get_path (gtk_combo_box_get_model (combo_box), iter);
5009 gtk_combo_box_set_active_internal (combo_box, path);
5010 gtk_tree_path_free (path);
5014 * gtk_combo_box_set_model:
5015 * @combo_box: A #GtkComboBox
5016 * @model: (allow-none): A #GtkTreeModel
5018 * Sets the model used by @combo_box to be @model. Will unset a previously set
5019 * model (if applicable). If model is %NULL, then it will unset the model.
5021 * Note that this function does not clear the cell renderers, you have to
5022 * call gtk_cell_layout_clear() yourself if you need to set up different
5023 * cell renderers for the new model.
5028 gtk_combo_box_set_model (GtkComboBox *combo_box,
5029 GtkTreeModel *model)
5031 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5032 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
5034 if (model == combo_box->priv->model)
5037 gtk_combo_box_unset_model (combo_box);
5042 combo_box->priv->model = model;
5043 g_object_ref (combo_box->priv->model);
5045 combo_box->priv->inserted_id =
5046 g_signal_connect (combo_box->priv->model, "row-inserted",
5047 G_CALLBACK (gtk_combo_box_model_row_inserted),
5049 combo_box->priv->deleted_id =
5050 g_signal_connect (combo_box->priv->model, "row-deleted",
5051 G_CALLBACK (gtk_combo_box_model_row_deleted),
5053 combo_box->priv->reordered_id =
5054 g_signal_connect (combo_box->priv->model, "rows-reordered",
5055 G_CALLBACK (gtk_combo_box_model_rows_reordered),
5057 combo_box->priv->changed_id =
5058 g_signal_connect (combo_box->priv->model, "row-changed",
5059 G_CALLBACK (gtk_combo_box_model_row_changed),
5062 if (combo_box->priv->tree_view)
5065 gtk_tree_view_set_model (GTK_TREE_VIEW (combo_box->priv->tree_view),
5066 combo_box->priv->model);
5067 gtk_combo_box_list_popup_resize (combo_box);
5072 if (combo_box->priv->popup_widget)
5073 gtk_combo_box_menu_fill (combo_box);
5077 if (combo_box->priv->cell_view)
5078 gtk_cell_view_set_model (GTK_CELL_VIEW (combo_box->priv->cell_view),
5079 combo_box->priv->model);
5081 if (combo_box->priv->active != -1)
5083 /* If an index was set in advance, apply it now */
5084 gtk_combo_box_set_active (combo_box, combo_box->priv->active);
5085 combo_box->priv->active = -1;
5089 gtk_combo_box_update_sensitivity (combo_box);
5091 g_object_notify (G_OBJECT (combo_box), "model");
5095 * gtk_combo_box_get_model
5096 * @combo_box: A #GtkComboBox
5098 * Returns the #GtkTreeModel which is acting as data source for @combo_box.
5100 * Return value: (transfer none): A #GtkTreeModel which was passed during construction.
5105 gtk_combo_box_get_model (GtkComboBox *combo_box)
5107 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
5109 return combo_box->priv->model;
5113 /* convenience API for simple text combos */
5116 * gtk_combo_box_new_text:
5118 * Convenience function which constructs a new text combo box, which is a
5119 * #GtkComboBox just displaying strings. If you use this function to create
5120 * a text combo box, you should only manipulate its data source with the
5121 * following convenience functions: gtk_combo_box_append_text(),
5122 * gtk_combo_box_insert_text(), gtk_combo_box_prepend_text() and
5123 * gtk_combo_box_remove_text().
5125 * Return value: (transfer none): A new text combo box.
5130 gtk_combo_box_new_text (void)
5132 GtkWidget *combo_box;
5133 GtkCellRenderer *cell;
5134 GtkListStore *store;
5136 store = gtk_list_store_new (1, G_TYPE_STRING);
5137 combo_box = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));
5138 g_object_unref (store);
5140 cell = gtk_cell_renderer_text_new ();
5141 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), cell, TRUE);
5142 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), cell,
5150 * gtk_combo_box_append_text:
5151 * @combo_box: A #GtkComboBox constructed using gtk_combo_box_new_text()
5154 * Appends @string to the list of strings stored in @combo_box. Note that
5155 * you can only use this function with combo boxes constructed with
5156 * gtk_combo_box_new_text().
5161 gtk_combo_box_append_text (GtkComboBox *combo_box,
5165 GtkListStore *store;
5167 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5168 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
5169 g_return_if_fail (gtk_tree_model_get_column_type (combo_box->priv->model, 0)
5171 g_return_if_fail (text != NULL);
5173 store = GTK_LIST_STORE (combo_box->priv->model);
5175 gtk_list_store_append (store, &iter);
5176 gtk_list_store_set (store, &iter, 0, text, -1);
5180 * gtk_combo_box_insert_text:
5181 * @combo_box: A #GtkComboBox constructed using gtk_combo_box_new_text()
5182 * @position: An index to insert @text
5185 * Inserts @string at @position in the list of strings stored in @combo_box.
5186 * Note that you can only use this function with combo boxes constructed
5187 * with gtk_combo_box_new_text().
5192 gtk_combo_box_insert_text (GtkComboBox *combo_box,
5197 GtkListStore *store;
5199 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5200 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
5201 g_return_if_fail (position >= 0);
5202 g_return_if_fail (gtk_tree_model_get_column_type (combo_box->priv->model, 0)
5204 g_return_if_fail (text != NULL);
5206 store = GTK_LIST_STORE (combo_box->priv->model);
5208 gtk_list_store_insert (store, &iter, position);
5209 gtk_list_store_set (store, &iter, 0, text, -1);
5213 * gtk_combo_box_prepend_text:
5214 * @combo_box: A #GtkComboBox constructed with gtk_combo_box_new_text()
5217 * Prepends @string to the list of strings stored in @combo_box. Note that
5218 * you can only use this function with combo boxes constructed with
5219 * gtk_combo_box_new_text().
5224 gtk_combo_box_prepend_text (GtkComboBox *combo_box,
5228 GtkListStore *store;
5230 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5231 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
5232 g_return_if_fail (gtk_tree_model_get_column_type (combo_box->priv->model, 0)
5234 g_return_if_fail (text != NULL);
5236 store = GTK_LIST_STORE (combo_box->priv->model);
5238 gtk_list_store_prepend (store, &iter);
5239 gtk_list_store_set (store, &iter, 0, text, -1);
5243 * gtk_combo_box_remove_text:
5244 * @combo_box: A #GtkComboBox constructed with gtk_combo_box_new_text()
5245 * @position: Index of the item to remove
5247 * Removes the string at @position from @combo_box. Note that you can only use
5248 * this function with combo boxes constructed with gtk_combo_box_new_text().
5253 gtk_combo_box_remove_text (GtkComboBox *combo_box,
5257 GtkListStore *store;
5259 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5260 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
5261 g_return_if_fail (gtk_tree_model_get_column_type (combo_box->priv->model, 0)
5263 g_return_if_fail (position >= 0);
5265 store = GTK_LIST_STORE (combo_box->priv->model);
5267 if (gtk_tree_model_iter_nth_child (combo_box->priv->model, &iter,
5269 gtk_list_store_remove (store, &iter);
5273 * gtk_combo_box_get_active_text:
5274 * @combo_box: A #GtkComboBox constructed with gtk_combo_box_new_text()
5276 * Returns the currently active string in @combo_box or %NULL if none
5277 * is selected. Note that you can only use this function with combo
5278 * boxes constructed with gtk_combo_box_new_text() and with
5279 * #GtkComboBoxEntry<!-- -->s.
5281 * Returns: a newly allocated string containing the currently active text.
5282 * Must be freed with g_free().
5287 gtk_combo_box_get_active_text (GtkComboBox *combo_box)
5289 GtkComboBoxClass *class;
5291 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
5293 class = GTK_COMBO_BOX_GET_CLASS (combo_box);
5295 if (class->get_active_text)
5296 return class->get_active_text (combo_box);
5302 gtk_combo_box_real_get_active_text (GtkComboBox *combo_box)
5307 g_return_val_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model), NULL);
5308 g_return_val_if_fail (gtk_tree_model_get_column_type (combo_box->priv->model, 0)
5309 == G_TYPE_STRING, NULL);
5311 if (gtk_combo_box_get_active_iter (combo_box, &iter))
5312 gtk_tree_model_get (combo_box->priv->model, &iter,
5319 gtk_combo_box_real_move_active (GtkComboBox *combo_box,
5320 GtkScrollType scroll)
5323 GtkTreeIter new_iter;
5324 gboolean active_iter;
5327 if (!combo_box->priv->model)
5329 gtk_widget_error_bell (GTK_WIDGET (combo_box));
5333 active_iter = gtk_combo_box_get_active_iter (combo_box, &iter);
5337 case GTK_SCROLL_STEP_BACKWARD:
5338 case GTK_SCROLL_STEP_UP:
5339 case GTK_SCROLL_STEP_LEFT:
5342 found = tree_prev (combo_box, combo_box->priv->model,
5343 &iter, &new_iter, FALSE);
5346 /* else fall through */
5348 case GTK_SCROLL_PAGE_FORWARD:
5349 case GTK_SCROLL_PAGE_DOWN:
5350 case GTK_SCROLL_PAGE_RIGHT:
5351 case GTK_SCROLL_END:
5352 found = tree_last (combo_box, combo_box->priv->model, &new_iter, FALSE);
5355 case GTK_SCROLL_STEP_FORWARD:
5356 case GTK_SCROLL_STEP_DOWN:
5357 case GTK_SCROLL_STEP_RIGHT:
5360 found = tree_next (combo_box, combo_box->priv->model,
5361 &iter, &new_iter, FALSE);
5364 /* else fall through */
5366 case GTK_SCROLL_PAGE_BACKWARD:
5367 case GTK_SCROLL_PAGE_UP:
5368 case GTK_SCROLL_PAGE_LEFT:
5369 case GTK_SCROLL_START:
5370 found = tree_first (combo_box, combo_box->priv->model, &new_iter, FALSE);
5377 if (found && active_iter)
5379 GtkTreePath *old_path;
5380 GtkTreePath *new_path;
5382 old_path = gtk_tree_model_get_path (combo_box->priv->model, &iter);
5383 new_path = gtk_tree_model_get_path (combo_box->priv->model, &new_iter);
5385 if (gtk_tree_path_compare (old_path, new_path) == 0)
5388 gtk_tree_path_free (old_path);
5389 gtk_tree_path_free (new_path);
5394 gtk_combo_box_set_active_iter (combo_box, &new_iter);
5398 gtk_widget_error_bell (GTK_WIDGET (combo_box));
5403 gtk_combo_box_mnemonic_activate (GtkWidget *widget,
5404 gboolean group_cycling)
5406 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
5408 gtk_widget_grab_focus (combo_box->priv->button);
5414 gtk_combo_box_grab_focus (GtkWidget *widget)
5416 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
5418 gtk_widget_grab_focus (combo_box->priv->button);
5422 gtk_combo_box_destroy (GtkObject *object)
5424 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
5426 if (combo_box->priv->popup_idle_id > 0)
5428 g_source_remove (combo_box->priv->popup_idle_id);
5429 combo_box->priv->popup_idle_id = 0;
5432 gtk_combo_box_popdown (combo_box);
5434 if (combo_box->priv->row_separator_destroy)
5435 combo_box->priv->row_separator_destroy (combo_box->priv->row_separator_data);
5437 combo_box->priv->row_separator_func = NULL;
5438 combo_box->priv->row_separator_data = NULL;
5439 combo_box->priv->row_separator_destroy = NULL;
5441 GTK_OBJECT_CLASS (gtk_combo_box_parent_class)->destroy (object);
5442 combo_box->priv->cell_view = NULL;
5446 gtk_combo_box_dispose(GObject* object)
5448 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
5450 if (GTK_IS_MENU (combo_box->priv->popup_widget))
5452 gtk_combo_box_menu_destroy (combo_box);
5453 gtk_menu_detach (GTK_MENU (combo_box->priv->popup_widget));
5454 combo_box->priv->popup_widget = NULL;
5457 G_OBJECT_CLASS (gtk_combo_box_parent_class)->dispose (object);
5461 gtk_combo_box_finalize (GObject *object)
5463 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
5466 if (GTK_IS_TREE_VIEW (combo_box->priv->tree_view))
5467 gtk_combo_box_list_destroy (combo_box);
5469 if (combo_box->priv->popup_window)
5470 gtk_widget_destroy (combo_box->priv->popup_window);
5472 gtk_combo_box_unset_model (combo_box);
5474 for (i = combo_box->priv->cells; i; i = i->next)
5476 ComboCellInfo *info = (ComboCellInfo *)i->data;
5477 GSList *list = info->attributes;
5480 info->destroy (info->func_data);
5482 while (list && list->next)
5484 g_free (list->data);
5485 list = list->next->next;
5487 g_slist_free (info->attributes);
5489 g_object_unref (info->cell);
5490 g_slice_free (ComboCellInfo, info);
5492 g_slist_free (combo_box->priv->cells);
5494 g_free (combo_box->priv->tearoff_title);
5496 G_OBJECT_CLASS (gtk_combo_box_parent_class)->finalize (object);
5500 gtk_cell_editable_key_press (GtkWidget *widget,
5504 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
5506 if (event->keyval == GDK_KEY_Escape)
5508 g_object_set (combo_box,
5509 "editing-canceled", TRUE,
5511 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (combo_box));
5512 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (combo_box));
5516 else if (event->keyval == GDK_KEY_Return ||
5517 event->keyval == GDK_KEY_ISO_Enter ||
5518 event->keyval == GDK_KEY_KP_Enter)
5520 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (combo_box));
5521 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (combo_box));
5530 popdown_idle (gpointer data)
5532 GtkComboBox *combo_box;
5534 combo_box = GTK_COMBO_BOX (data);
5536 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (combo_box));
5537 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (combo_box));
5539 g_object_unref (combo_box);
5545 popdown_handler (GtkWidget *widget,
5548 gdk_threads_add_idle (popdown_idle, g_object_ref (data));
5552 popup_idle (gpointer data)
5554 GtkComboBox *combo_box;
5556 combo_box = GTK_COMBO_BOX (data);
5558 if (GTK_IS_MENU (combo_box->priv->popup_widget) &&
5559 combo_box->priv->cell_view)
5560 g_signal_connect_object (combo_box->priv->popup_widget,
5561 "unmap", G_CALLBACK (popdown_handler),
5564 /* we unset this if a menu item is activated */
5565 g_object_set (combo_box,
5566 "editing-canceled", TRUE,
5568 gtk_combo_box_popup (combo_box);
5570 combo_box->priv->popup_idle_id = 0;
5571 combo_box->priv->activate_button = 0;
5572 combo_box->priv->activate_time = 0;
5578 gtk_combo_box_start_editing (GtkCellEditable *cell_editable,
5581 GtkComboBox *combo_box = GTK_COMBO_BOX (cell_editable);
5584 combo_box->priv->is_cell_renderer = TRUE;
5586 if (combo_box->priv->cell_view)
5588 g_signal_connect_object (combo_box->priv->button, "key-press-event",
5589 G_CALLBACK (gtk_cell_editable_key_press),
5592 gtk_widget_grab_focus (combo_box->priv->button);
5596 child = gtk_bin_get_child (GTK_BIN (combo_box));
5598 g_signal_connect_object (child, "key-press-event",
5599 G_CALLBACK (gtk_cell_editable_key_press),
5602 gtk_widget_grab_focus (child);
5603 gtk_widget_set_can_focus (combo_box->priv->button, FALSE);
5606 /* we do the immediate popup only for the optionmenu-like
5609 if (combo_box->priv->is_cell_renderer &&
5610 combo_box->priv->cell_view && !combo_box->priv->tree_view)
5612 if (event && event->type == GDK_BUTTON_PRESS)
5614 GdkEventButton *event_button = (GdkEventButton *)event;
5616 combo_box->priv->activate_button = event_button->button;
5617 combo_box->priv->activate_time = event_button->time;
5620 combo_box->priv->popup_idle_id =
5621 gdk_threads_add_idle (popup_idle, combo_box);
5627 * gtk_combo_box_get_add_tearoffs:
5628 * @combo_box: a #GtkComboBox
5630 * Gets the current value of the :add-tearoffs property.
5632 * Return value: the current value of the :add-tearoffs property.
5635 gtk_combo_box_get_add_tearoffs (GtkComboBox *combo_box)
5637 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE);
5639 return combo_box->priv->add_tearoffs;
5643 * gtk_combo_box_set_add_tearoffs:
5644 * @combo_box: a #GtkComboBox
5645 * @add_tearoffs: %TRUE to add tearoff menu items
5647 * Sets whether the popup menu should have a tearoff
5653 gtk_combo_box_set_add_tearoffs (GtkComboBox *combo_box,
5654 gboolean add_tearoffs)
5656 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5658 add_tearoffs = add_tearoffs != FALSE;
5660 if (combo_box->priv->add_tearoffs != add_tearoffs)
5662 combo_box->priv->add_tearoffs = add_tearoffs;
5663 gtk_combo_box_check_appearance (combo_box);
5664 gtk_combo_box_relayout (combo_box);
5665 g_object_notify (G_OBJECT (combo_box), "add-tearoffs");
5670 * gtk_combo_box_get_title:
5671 * @combo_box: a #GtkComboBox
5673 * Gets the current title of the menu in tearoff mode. See
5674 * gtk_combo_box_set_add_tearoffs().
5676 * Returns: the menu's title in tearoff mode. This is an internal copy of the
5677 * string which must not be freed.
5681 G_CONST_RETURN gchar*
5682 gtk_combo_box_get_title (GtkComboBox *combo_box)
5684 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
5686 return combo_box->priv->tearoff_title;
5690 gtk_combo_box_update_title (GtkComboBox *combo_box)
5692 gtk_combo_box_check_appearance (combo_box);
5694 if (combo_box->priv->popup_widget &&
5695 GTK_IS_MENU (combo_box->priv->popup_widget))
5696 gtk_menu_set_title (GTK_MENU (combo_box->priv->popup_widget),
5697 combo_box->priv->tearoff_title);
5701 * gtk_combo_box_set_title:
5702 * @combo_box: a #GtkComboBox
5703 * @title: a title for the menu in tearoff mode
5705 * Sets the menu's title in tearoff mode.
5710 gtk_combo_box_set_title (GtkComboBox *combo_box,
5713 GtkComboBoxPrivate *priv;
5715 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5717 priv = combo_box->priv;
5719 if (strcmp (title ? title : "",
5720 priv->tearoff_title ? priv->tearoff_title : "") != 0)
5722 g_free (priv->tearoff_title);
5723 priv->tearoff_title = g_strdup (title);
5725 gtk_combo_box_update_title (combo_box);
5727 g_object_notify (G_OBJECT (combo_box), "tearoff-title");
5732 * gtk_combo_box_get_popup_accessible:
5733 * @combo_box: a #GtkComboBox
5735 * Gets the accessible object corresponding to the combo box's popup.
5737 * This function is mostly intended for use by accessibility technologies;
5738 * applications should have little use for it.
5740 * Returns: the accessible object corresponding to the combo box's popup.
5745 gtk_combo_box_get_popup_accessible (GtkComboBox *combo_box)
5749 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
5751 if (combo_box->priv->popup_widget)
5753 atk_obj = gtk_widget_get_accessible (combo_box->priv->popup_widget);
5761 * gtk_combo_box_get_row_separator_func:
5762 * @combo_box: a #GtkComboBox
5764 * Returns the current row separator function.
5766 * Return value: the current row separator function.
5770 GtkTreeViewRowSeparatorFunc
5771 gtk_combo_box_get_row_separator_func (GtkComboBox *combo_box)
5773 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
5775 return combo_box->priv->row_separator_func;
5779 * gtk_combo_box_set_row_separator_func:
5780 * @combo_box: a #GtkComboBox
5781 * @func: a #GtkTreeViewRowSeparatorFunc
5782 * @data: (allow-none): user data to pass to @func, or %NULL
5783 * @destroy: (allow-none): destroy notifier for @data, or %NULL
5785 * Sets the row separator function, which is used to determine
5786 * whether a row should be drawn as a separator. If the row separator
5787 * function is %NULL, no separators are drawn. This is the default value.
5792 gtk_combo_box_set_row_separator_func (GtkComboBox *combo_box,
5793 GtkTreeViewRowSeparatorFunc func,
5795 GDestroyNotify destroy)
5797 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5799 if (combo_box->priv->row_separator_destroy)
5800 combo_box->priv->row_separator_destroy (combo_box->priv->row_separator_data);
5802 combo_box->priv->row_separator_func = func;
5803 combo_box->priv->row_separator_data = data;
5804 combo_box->priv->row_separator_destroy = destroy;
5806 if (combo_box->priv->tree_view)
5807 gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (combo_box->priv->tree_view),
5810 gtk_combo_box_relayout (combo_box);
5812 gtk_widget_queue_draw (GTK_WIDGET (combo_box));
5816 * gtk_combo_box_set_button_sensitivity:
5817 * @combo_box: a #GtkComboBox
5818 * @sensitivity: specify the sensitivity of the dropdown button
5820 * Sets whether the dropdown button of the combo box should be
5821 * always sensitive (%GTK_SENSITIVITY_ON), never sensitive (%GTK_SENSITIVITY_OFF)
5822 * or only if there is at least one item to display (%GTK_SENSITIVITY_AUTO).
5827 gtk_combo_box_set_button_sensitivity (GtkComboBox *combo_box,
5828 GtkSensitivityType sensitivity)
5830 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5832 if (combo_box->priv->button_sensitivity != sensitivity)
5834 combo_box->priv->button_sensitivity = sensitivity;
5835 gtk_combo_box_update_sensitivity (combo_box);
5837 g_object_notify (G_OBJECT (combo_box), "button-sensitivity");
5842 * gtk_combo_box_get_button_sensitivity:
5843 * @combo_box: a #GtkComboBox
5845 * Returns whether the combo box sets the dropdown button
5846 * sensitive or not when there are no items in the model.
5848 * Return Value: %GTK_SENSITIVITY_ON if the dropdown button
5849 * is sensitive when the model is empty, %GTK_SENSITIVITY_OFF
5850 * if the button is always insensitive or
5851 * %GTK_SENSITIVITY_AUTO if it is only sensitive as long as
5852 * the model has one item to be selected.
5857 gtk_combo_box_get_button_sensitivity (GtkComboBox *combo_box)
5859 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE);
5861 return combo_box->priv->button_sensitivity;
5866 * gtk_combo_box_set_focus_on_click:
5867 * @combo: a #GtkComboBox
5868 * @focus_on_click: whether the combo box grabs focus when clicked
5871 * Sets whether the combo box will grab focus when it is clicked with
5872 * the mouse. Making mouse clicks not grab focus is useful in places
5873 * like toolbars where you don't want the keyboard focus removed from
5874 * the main area of the application.
5879 gtk_combo_box_set_focus_on_click (GtkComboBox *combo_box,
5880 gboolean focus_on_click)
5882 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5884 focus_on_click = focus_on_click != FALSE;
5886 if (combo_box->priv->focus_on_click != focus_on_click)
5888 combo_box->priv->focus_on_click = focus_on_click;
5890 if (combo_box->priv->button)
5891 gtk_button_set_focus_on_click (GTK_BUTTON (combo_box->priv->button),
5894 g_object_notify (G_OBJECT (combo_box), "focus-on-click");
5899 * gtk_combo_box_get_focus_on_click:
5900 * @combo: a #GtkComboBox
5902 * Returns whether the combo box grabs focus when it is clicked
5903 * with the mouse. See gtk_combo_box_set_focus_on_click().
5905 * Return value: %TRUE if the combo box grabs focus when it is
5906 * clicked with the mouse.
5911 gtk_combo_box_get_focus_on_click (GtkComboBox *combo_box)
5913 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE);
5915 return combo_box->priv->focus_on_click;
5920 gtk_combo_box_buildable_custom_tag_start (GtkBuildable *buildable,
5921 GtkBuilder *builder,
5923 const gchar *tagname,
5924 GMarkupParser *parser,
5927 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
5928 tagname, parser, data))
5931 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
5932 tagname, parser, data);
5936 gtk_combo_box_buildable_custom_tag_end (GtkBuildable *buildable,
5937 GtkBuilder *builder,
5939 const gchar *tagname,
5942 if (strcmp (tagname, "attributes") == 0)
5943 _gtk_cell_layout_buildable_custom_tag_end (buildable, builder, child, tagname,
5946 parent_buildable_iface->custom_tag_end (buildable, builder, child, tagname,
5952 gtk_combo_box_size_request_init (GtkSizeRequestIface *iface)
5954 iface->get_width = gtk_combo_box_get_width;
5955 iface->get_height = gtk_combo_box_get_height;
5956 iface->get_height_for_width = gtk_combo_box_get_height_for_width;
5957 iface->get_width_for_height = gtk_combo_box_get_width_for_height;
5961 gtk_combo_box_remeasure (GtkComboBox *combo_box)
5963 GtkComboBoxPrivate *priv = combo_box->priv;
5968 !gtk_tree_model_get_iter_first (priv->model, &iter))
5971 priv->minimum_width = priv->natural_width = 0;
5973 path = gtk_tree_path_new_from_indices (0, -1);
5977 gint row_min = 0, row_nat = 0;
5979 if (priv->cell_view)
5980 gtk_cell_view_get_desired_width_of_row (GTK_CELL_VIEW (priv->cell_view),
5981 path, &row_min, &row_nat);
5983 priv->minimum_width = MAX (priv->minimum_width, row_min);
5984 priv->natural_width = MAX (priv->natural_width, row_nat);
5986 gtk_tree_path_next (path);
5988 while (gtk_tree_model_iter_next (priv->model, &iter));
5990 gtk_tree_path_free (path);
5995 gtk_combo_box_measure_height_for_width (GtkComboBox *combo_box,
6001 GtkComboBoxPrivate *priv = combo_box->priv;
6004 gint child_min, child_nat;
6006 child = gtk_bin_get_child (GTK_BIN (combo_box));
6008 gtk_size_request_get_height_for_width (GTK_SIZE_REQUEST (child), avail_width,
6009 &child_min, &child_nat);
6012 !gtk_tree_model_get_iter_first (priv->model, &iter))
6015 path = gtk_tree_path_new_from_indices (0, -1);
6019 gint row_min = 0, row_nat = 0;
6021 if (priv->cell_view)
6022 gtk_cell_view_get_desired_height_for_width_of_row (GTK_CELL_VIEW (priv->cell_view),
6024 &row_min, &row_nat);
6026 child_min = MAX (child_min, row_min);
6027 child_nat = MAX (child_nat, row_nat);
6029 gtk_tree_path_next (path);
6031 while (gtk_tree_model_iter_next (priv->model, &iter));
6033 gtk_tree_path_free (path);
6038 *min_height = child_min;
6040 *nat_height = child_nat;
6045 gtk_combo_box_get_width (GtkSizeRequest *widget,
6049 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
6050 GtkComboBoxPrivate *priv = combo_box->priv;
6052 gint focus_width, focus_pad;
6053 gint font_size, arrow_size;
6054 PangoContext *context;
6055 PangoFontMetrics *metrics;
6056 PangoFontDescription *font_desc;
6058 gint minimum_width, natural_width;
6059 gint child_min, child_nat;
6061 child = gtk_bin_get_child (GTK_BIN (widget));
6064 gtk_size_request_get_width (GTK_SIZE_REQUEST (child), &child_min, &child_nat);
6065 gtk_combo_box_remeasure (combo_box);
6067 child_min = MAX (child_min, priv->minimum_width);
6068 child_nat = MAX (child_nat, priv->natural_width);
6070 gtk_widget_style_get (GTK_WIDGET (widget),
6071 "focus-line-width", &focus_width,
6072 "focus-padding", &focus_pad,
6073 "arrow-size", &arrow_size,
6076 font_desc = gtk_widget_get_style (child)->font_desc;
6077 context = gtk_widget_get_pango_context (GTK_WIDGET (widget));
6078 metrics = pango_context_get_metrics (context, font_desc,
6079 pango_context_get_language (context));
6080 font_size = PANGO_PIXELS (pango_font_metrics_get_ascent (metrics) +
6081 pango_font_metrics_get_descent (metrics));
6082 pango_font_metrics_unref (metrics);
6084 arrow_size = MAX (arrow_size, font_size);
6086 gtk_widget_set_size_request (priv->arrow, arrow_size, arrow_size);
6088 if (!priv->tree_view)
6092 if (priv->cell_view)
6094 gint sep_width, arrow_width;
6095 gint border_width, xthickness, xpad;
6097 border_width = gtk_container_get_border_width (GTK_CONTAINER (combo_box));
6098 xthickness = gtk_widget_get_style (priv->button)->xthickness;
6100 gtk_size_request_get_width (GTK_SIZE_REQUEST (priv->separator), &sep_width, NULL);
6101 gtk_size_request_get_width (GTK_SIZE_REQUEST (priv->arrow), &arrow_width, NULL);
6103 xpad = 2*(border_width + xthickness + focus_width + focus_pad);
6105 minimum_width = child_min + sep_width + arrow_width + xpad;
6106 natural_width = child_nat + sep_width + arrow_width + xpad;
6110 gint but_width, but_nat_width;
6112 gtk_size_request_get_width (GTK_SIZE_REQUEST (priv->button),
6113 &but_width, &but_nat_width);
6115 minimum_width = child_min + but_width;
6116 natural_width = child_nat + but_nat_width;
6122 gint button_width, button_nat_width;
6124 /* sample + frame */
6125 minimum_width = child_min;
6126 natural_width = child_nat;
6128 minimum_width += 2 * focus_width;
6129 natural_width += 2 * focus_width;
6131 if (priv->cell_view_frame)
6133 if (priv->has_frame)
6135 gint border_width = gtk_container_get_border_width (GTK_CONTAINER (priv->cell_view_frame));
6136 gint xpad = 2 * (border_width + gtk_widget_get_style (GTK_WIDGET (priv->cell_view_frame))->xthickness);
6138 minimum_width += xpad;
6139 natural_width += xpad;
6144 gtk_size_request_get_width (GTK_SIZE_REQUEST (priv->button),
6145 &button_width, &button_nat_width);
6147 minimum_width += button_width;
6148 natural_width += button_nat_width;
6151 if (GTK_SHADOW_NONE != priv->shadow_type)
6153 style = gtk_widget_get_style (GTK_WIDGET (widget));
6155 minimum_width += 2 * style->xthickness;
6156 natural_width += 2 * style->xthickness;
6160 *minimum_size = minimum_width;
6163 *natural_size = natural_width;
6167 gtk_combo_box_get_height (GtkSizeRequest *widget,
6173 /* Combo box is height-for-width only
6174 * (so we always just reserve enough height for the minimum width) */
6175 GTK_SIZE_REQUEST_GET_IFACE (widget)->get_width (widget, &min_width, NULL);
6176 GTK_SIZE_REQUEST_GET_IFACE (widget)->get_height_for_width (widget, min_width, minimum_size, natural_size);
6180 gtk_combo_box_get_width_for_height (GtkSizeRequest *widget,
6185 /* Combo box is height-for-width only
6186 * (so we assume we always reserved enough height for the minimum width) */
6187 GTK_SIZE_REQUEST_GET_IFACE (widget)->get_width (widget, minimum_size, natural_size);
6192 gtk_combo_box_get_height_for_width (GtkSizeRequest *widget,
6197 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
6198 GtkComboBoxPrivate *priv = combo_box->priv;
6200 gint focus_width, focus_pad;
6201 gint min_height, nat_height;
6204 gtk_widget_style_get (GTK_WIDGET (widget),
6205 "focus-line-width", &focus_width,
6206 "focus-padding", &focus_pad,
6211 if (GTK_SHADOW_NONE != priv->shadow_type)
6212 size -= gtk_widget_get_style (GTK_WIDGET (widget))->xthickness;
6214 if (!priv->tree_view)
6217 if (priv->cell_view)
6219 GtkStyle *button_style;
6220 /* calculate x/y padding and separator/arrow size */
6221 gint sep_width, arrow_width, sep_height, arrow_height;
6222 gint border_width, xthickness, ythickness, xpad, ypad;
6224 border_width = gtk_container_get_border_width (GTK_CONTAINER (combo_box));
6225 button_style = gtk_widget_get_style (priv->button);
6227 xthickness = button_style->xthickness;
6228 ythickness = button_style->ythickness;
6230 gtk_size_request_get_width (GTK_SIZE_REQUEST (priv->separator), &sep_width, NULL);
6231 gtk_size_request_get_width (GTK_SIZE_REQUEST (priv->arrow), &arrow_width, NULL);
6232 gtk_size_request_get_height_for_width (GTK_SIZE_REQUEST (priv->separator),
6233 sep_width, &sep_height, NULL);
6234 gtk_size_request_get_height_for_width (GTK_SIZE_REQUEST (priv->arrow),
6235 arrow_width, &arrow_height, NULL);
6237 xpad = 2*(border_width + xthickness + focus_width + focus_pad);
6238 ypad = 2*(border_width + ythickness + focus_width + focus_pad);
6240 size -= sep_width + arrow_width + xpad;
6242 gtk_combo_box_measure_height_for_width (combo_box, size, &min_height, &nat_height);
6244 arrow_height = MAX (arrow_height, sep_height);
6245 min_height = MAX (min_height, arrow_height);
6246 nat_height = MAX (nat_height, arrow_height);
6253 /* there is a custom child widget inside (no priv->cell_view) */
6254 gint but_width, but_height;
6256 gtk_size_request_get_width (GTK_SIZE_REQUEST (priv->button), &but_width, NULL);
6257 gtk_size_request_get_height_for_width (GTK_SIZE_REQUEST (priv->button),
6258 but_width, &but_height, NULL);
6262 gtk_combo_box_measure_height_for_width (combo_box, size, &min_height, &nat_height);
6264 min_height = MAX (min_height, but_height);
6265 nat_height = MAX (nat_height, but_height);
6271 gint but_width, but_height;
6272 gint xpad = 0, ypad = 0;
6274 gtk_size_request_get_width (GTK_SIZE_REQUEST (priv->button), &but_width, NULL);
6275 gtk_size_request_get_height_for_width (GTK_SIZE_REQUEST (priv->button),
6276 but_width, &but_height, NULL);
6278 if (priv->cell_view_frame && priv->has_frame)
6280 GtkStyle *cell_style;
6283 border_width = gtk_container_get_border_width (GTK_CONTAINER (priv->cell_view_frame));
6284 cell_style = gtk_widget_get_style (GTK_WIDGET (priv->cell_view_frame));
6286 xpad = 2 * (border_width + cell_style->xthickness);
6287 ypad = 2 * (border_width + cell_style->ythickness);
6291 size -= 2 * focus_width;
6294 gtk_combo_box_measure_height_for_width (combo_box, size, &min_height, &nat_height);
6296 min_height = MAX (min_height, but_height);
6297 nat_height = MAX (nat_height, but_height);
6303 if (GTK_SHADOW_NONE != priv->shadow_type)
6305 style = gtk_widget_get_style (GTK_WIDGET (widget));
6307 min_height += 2 * style->ythickness;
6308 nat_height += 2 * style->ythickness;
6312 *minimum_size = min_height;
6315 *natural_size = nat_height;