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_Down, GDK_MOD1_MASK,
622 gtk_binding_entry_add_signal (binding_set, GDK_KP_Down, GDK_MOD1_MASK,
625 gtk_binding_entry_add_signal (binding_set, GDK_Up, GDK_MOD1_MASK,
627 gtk_binding_entry_add_signal (binding_set, GDK_KP_Up, GDK_MOD1_MASK,
629 gtk_binding_entry_add_signal (binding_set, GDK_Escape, 0,
632 gtk_binding_entry_add_signal (binding_set, GDK_Up, 0,
634 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_UP);
635 gtk_binding_entry_add_signal (binding_set, GDK_KP_Up, 0,
637 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_UP);
638 gtk_binding_entry_add_signal (binding_set, GDK_Page_Up, 0,
640 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_PAGE_UP);
641 gtk_binding_entry_add_signal (binding_set, GDK_KP_Page_Up, 0,
643 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_PAGE_UP);
644 gtk_binding_entry_add_signal (binding_set, GDK_Home, 0,
646 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_START);
647 gtk_binding_entry_add_signal (binding_set, GDK_KP_Home, 0,
649 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_START);
651 gtk_binding_entry_add_signal (binding_set, GDK_Down, 0,
653 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_DOWN);
654 gtk_binding_entry_add_signal (binding_set, GDK_KP_Down, 0,
656 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_DOWN);
657 gtk_binding_entry_add_signal (binding_set, GDK_Page_Down, 0,
659 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_PAGE_DOWN);
660 gtk_binding_entry_add_signal (binding_set, GDK_KP_Page_Down, 0,
662 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_PAGE_DOWN);
663 gtk_binding_entry_add_signal (binding_set, GDK_End, 0,
665 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_END);
666 gtk_binding_entry_add_signal (binding_set, GDK_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 &widget->style->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 &widget->style->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 && priv->cell_view->parent)
1242 gtk_widget_unparent (priv->cell_view);
1243 _gtk_bin_set_child (GTK_BIN (container), NULL);
1244 gtk_widget_queue_resize (GTK_WIDGET (container));
1247 gtk_widget_set_parent (widget, GTK_WIDGET (container));
1248 _gtk_bin_set_child (GTK_BIN (container), widget);
1250 if (priv->cell_view &&
1251 widget != priv->cell_view)
1253 /* since the cell_view was unparented, it's gone now */
1254 priv->cell_view = NULL;
1256 if (!priv->tree_view && priv->separator)
1258 gtk_container_remove (GTK_CONTAINER (priv->separator->parent),
1260 priv->separator = NULL;
1262 gtk_widget_queue_resize (GTK_WIDGET (container));
1264 else if (priv->cell_view_frame)
1266 gtk_widget_unparent (priv->cell_view_frame);
1267 priv->cell_view_frame = NULL;
1274 gtk_combo_box_remove (GtkContainer *container,
1277 GtkComboBox *combo_box = GTK_COMBO_BOX (container);
1278 GtkComboBoxPrivate *priv = combo_box->priv;
1280 gboolean appears_as_list;
1282 if (widget == priv->cell_view)
1283 priv->cell_view = NULL;
1285 gtk_widget_unparent (widget);
1286 _gtk_bin_set_child (GTK_BIN (container), NULL);
1288 if (GTK_OBJECT_FLAGS (combo_box) & GTK_IN_DESTRUCTION)
1291 gtk_widget_queue_resize (GTK_WIDGET (container));
1293 if (!priv->tree_view)
1294 appears_as_list = FALSE;
1296 appears_as_list = TRUE;
1298 if (appears_as_list)
1299 gtk_combo_box_list_destroy (combo_box);
1300 else if (GTK_IS_MENU (priv->popup_widget))
1302 gtk_combo_box_menu_destroy (combo_box);
1303 gtk_menu_detach (GTK_MENU (priv->popup_widget));
1304 priv->popup_widget = NULL;
1307 if (!priv->cell_view)
1309 priv->cell_view = gtk_cell_view_new ();
1310 gtk_widget_set_parent (priv->cell_view, GTK_WIDGET (container));
1311 _gtk_bin_set_child (GTK_BIN (container), priv->cell_view);
1313 gtk_widget_show (priv->cell_view);
1314 gtk_cell_view_set_model (GTK_CELL_VIEW (priv->cell_view),
1316 gtk_combo_box_sync_cells (combo_box, GTK_CELL_LAYOUT (priv->cell_view));
1320 if (appears_as_list)
1321 gtk_combo_box_list_setup (combo_box);
1323 gtk_combo_box_menu_setup (combo_box, TRUE);
1325 if (gtk_tree_row_reference_valid (priv->active_row))
1327 path = gtk_tree_row_reference_get_path (priv->active_row);
1328 gtk_combo_box_set_active_internal (combo_box, path);
1329 gtk_tree_path_free (path);
1332 gtk_combo_box_set_active_internal (combo_box, NULL);
1335 static ComboCellInfo *
1336 gtk_combo_box_get_cell_info (GtkComboBox *combo_box,
1337 GtkCellRenderer *cell)
1341 for (i = combo_box->priv->cells; i; i = i->next)
1343 ComboCellInfo *info = (ComboCellInfo *)i->data;
1345 if (info && info->cell == cell)
1353 gtk_combo_box_menu_show (GtkWidget *menu,
1356 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
1357 GtkComboBoxPrivate *priv = combo_box->priv;
1359 gtk_combo_box_child_show (menu, user_data);
1361 priv->popup_in_progress = TRUE;
1362 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->button),
1364 priv->popup_in_progress = FALSE;
1368 gtk_combo_box_menu_hide (GtkWidget *menu,
1371 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
1373 gtk_combo_box_child_hide (menu,user_data);
1375 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
1380 gtk_combo_box_detacher (GtkWidget *widget,
1383 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
1384 GtkComboBoxPrivate *priv = combo_box->priv;
1386 g_return_if_fail (priv->popup_widget == (GtkWidget *) menu);
1388 g_signal_handlers_disconnect_by_func (menu->toplevel,
1389 gtk_combo_box_menu_show,
1391 g_signal_handlers_disconnect_by_func (menu->toplevel,
1392 gtk_combo_box_menu_hide,
1395 priv->popup_widget = NULL;
1399 gtk_combo_box_set_popup_widget (GtkComboBox *combo_box,
1402 GtkComboBoxPrivate *priv = combo_box->priv;
1404 if (GTK_IS_MENU (priv->popup_widget))
1406 gtk_menu_detach (GTK_MENU (priv->popup_widget));
1407 priv->popup_widget = NULL;
1409 else if (priv->popup_widget)
1411 gtk_container_remove (GTK_CONTAINER (priv->scrolled_window),
1412 priv->popup_widget);
1413 g_object_unref (priv->popup_widget);
1414 priv->popup_widget = NULL;
1417 if (GTK_IS_MENU (popup))
1419 if (priv->popup_window)
1421 gtk_widget_destroy (priv->popup_window);
1422 priv->popup_window = NULL;
1425 priv->popup_widget = popup;
1428 * Note that we connect to show/hide on the toplevel, not the
1429 * menu itself, since the menu is not shown/hidden when it is
1430 * popped up while torn-off.
1432 g_signal_connect (GTK_MENU (popup)->toplevel, "show",
1433 G_CALLBACK (gtk_combo_box_menu_show), combo_box);
1434 g_signal_connect (GTK_MENU (popup)->toplevel, "hide",
1435 G_CALLBACK (gtk_combo_box_menu_hide), combo_box);
1437 gtk_menu_attach_to_widget (GTK_MENU (popup),
1438 GTK_WIDGET (combo_box),
1439 gtk_combo_box_detacher);
1443 if (!priv->popup_window)
1445 GtkWidget *toplevel;
1447 priv->popup_window = gtk_window_new (GTK_WINDOW_POPUP);
1448 gtk_widget_set_name (priv->popup_window, "gtk-combobox-popup-window");
1450 gtk_window_set_type_hint (GTK_WINDOW (priv->popup_window),
1451 GDK_WINDOW_TYPE_HINT_COMBO);
1453 g_signal_connect (GTK_WINDOW (priv->popup_window),"show",
1454 G_CALLBACK (gtk_combo_box_child_show),
1456 g_signal_connect (GTK_WINDOW (priv->popup_window),"hide",
1457 G_CALLBACK (gtk_combo_box_child_hide),
1460 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (combo_box));
1461 if (GTK_IS_WINDOW (toplevel))
1463 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
1464 GTK_WINDOW (priv->popup_window));
1465 gtk_window_set_transient_for (GTK_WINDOW (priv->popup_window),
1466 GTK_WINDOW (toplevel));
1469 gtk_window_set_resizable (GTK_WINDOW (priv->popup_window), FALSE);
1470 gtk_window_set_screen (GTK_WINDOW (priv->popup_window),
1471 gtk_widget_get_screen (GTK_WIDGET (combo_box)));
1473 priv->scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1475 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
1478 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (priv->scrolled_window),
1481 gtk_widget_show (priv->scrolled_window);
1483 gtk_container_add (GTK_CONTAINER (priv->popup_window),
1484 priv->scrolled_window);
1487 gtk_container_add (GTK_CONTAINER (priv->scrolled_window),
1490 gtk_widget_show (popup);
1491 g_object_ref (popup);
1492 priv->popup_widget = popup;
1497 gtk_combo_box_menu_position_below (GtkMenu *menu,
1503 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
1509 GdkRectangle monitor;
1511 /* FIXME: is using the size request here broken? */
1512 child = gtk_bin_get_child (GTK_BIN (combo_box));
1516 if (!gtk_widget_get_has_window (child))
1518 sx += child->allocation.x;
1519 sy += child->allocation.y;
1522 gdk_window_get_root_coords (child->window, sx, sy, &sx, &sy);
1524 if (GTK_SHADOW_NONE != combo_box->priv->shadow_type)
1525 sx -= GTK_WIDGET (combo_box)->style->xthickness;
1527 gtk_widget_size_request (GTK_WIDGET (menu), &req);
1529 if (gtk_widget_get_direction (GTK_WIDGET (combo_box)) == GTK_TEXT_DIR_LTR)
1532 *x = sx + child->allocation.width - req.width;
1535 screen = gtk_widget_get_screen (GTK_WIDGET (combo_box));
1536 monitor_num = gdk_screen_get_monitor_at_window (screen,
1537 GTK_WIDGET (combo_box)->window);
1538 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
1542 else if (*x + req.width > monitor.x + monitor.width)
1543 *x = monitor.x + monitor.width - req.width;
1545 if (monitor.y + monitor.height - *y - child->allocation.height >= req.height)
1546 *y += child->allocation.height;
1547 else if (*y - monitor.y >= req.height)
1549 else if (monitor.y + monitor.height - *y - child->allocation.height > *y - monitor.y)
1550 *y += child->allocation.height;
1558 gtk_combo_box_menu_position_over (GtkMenu *menu,
1564 GtkComboBox *combo_box;
1568 GtkRequisition requisition;
1570 guint horizontal_padding, border_width;
1572 gint menu_item_avail_width;
1573 gint min_item_height;
1578 combo_box = GTK_COMBO_BOX (user_data);
1579 widget = GTK_WIDGET (combo_box);
1581 gtk_widget_style_get (GTK_WIDGET (menu),
1582 "horizontal-padding", &horizontal_padding,
1585 border_width = gtk_container_get_border_width (GTK_CONTAINER (menu));
1587 /* Get the minimum height for minimum width of the menu */
1588 gtk_size_request_get_size (GTK_SIZE_REQUEST (menu), &requisition, NULL);
1589 menu_width = requisition.width;
1591 /* Get the size for the height-for-width menu-item requests */
1592 menu_item_avail_width =
1593 menu_width - (border_width + horizontal_padding + widget->style->xthickness) * 2;
1595 active = gtk_menu_get_active (GTK_MENU (combo_box->priv->popup_widget));
1597 menu_xpos = widget->allocation.x;
1598 menu_ypos = widget->allocation.y + widget->allocation.height / 2 - 2;
1602 gtk_size_request_get_height_for_width (GTK_SIZE_REQUEST (active),
1603 menu_item_avail_width, &min_item_height, NULL);
1604 menu_ypos -= min_item_height / 2;
1607 children = GTK_MENU_SHELL (combo_box->priv->popup_widget)->children;
1610 child = children->data;
1612 if (active == child)
1615 if (gtk_widget_get_visible (child))
1617 gtk_size_request_get_height_for_width (GTK_SIZE_REQUEST (child),
1618 menu_item_avail_width, &min_item_height, NULL);
1619 menu_ypos -= min_item_height;
1622 children = children->next;
1625 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1626 menu_xpos = menu_xpos + widget->allocation.width - menu_width;
1628 gdk_window_get_root_coords (widget->window, menu_xpos, menu_ypos,
1629 &menu_xpos, &menu_ypos);
1631 /* Clamp the position on screen */
1632 screen_width = gdk_screen_get_width (gtk_widget_get_screen (widget));
1636 else if ((menu_xpos + menu_width) > screen_width)
1637 menu_xpos -= ((menu_xpos + menu_width) - screen_width);
1646 gtk_combo_box_menu_position (GtkMenu *menu,
1652 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
1653 GtkComboBoxPrivate *priv = combo_box->priv;
1654 GtkWidget *menu_item;
1657 if (priv->wrap_width > 0 || priv->cell_view == NULL)
1658 gtk_combo_box_menu_position_below (menu, x, y, push_in, user_data);
1661 /* FIXME handle nested menus better */
1662 menu_item = gtk_menu_get_active (GTK_MENU (priv->popup_widget));
1664 gtk_menu_shell_select_item (GTK_MENU_SHELL (priv->popup_widget),
1667 gtk_combo_box_menu_position_over (menu, x, y, push_in, user_data);
1670 if (!gtk_widget_get_visible (GTK_MENU (priv->popup_widget)->toplevel))
1671 gtk_window_set_type_hint (GTK_WINDOW (GTK_MENU (priv->popup_widget)->toplevel),
1672 GDK_WINDOW_TYPE_HINT_COMBO);
1676 gtk_combo_box_list_position (GtkComboBox *combo_box,
1682 GtkComboBoxPrivate *priv = combo_box->priv;
1685 GdkRectangle monitor;
1686 GtkRequisition popup_req;
1687 GtkPolicyType hpolicy, vpolicy;
1689 /* under windows, the drop down list is as wide as the combo box itself.
1691 GtkWidget *sample = GTK_WIDGET (combo_box);
1695 if (!gtk_widget_get_has_window (sample))
1697 *x += sample->allocation.x;
1698 *y += sample->allocation.y;
1701 gdk_window_get_root_coords (sample->window, *x, *y, x, y);
1703 *width = sample->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,
1722 GTK_WIDGET (combo_box)->window);
1723 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
1727 else if (*x + *width > monitor.x + monitor.width)
1728 *x = monitor.x + monitor.width - *width;
1730 if (*y + sample->allocation.height + *height <= monitor.y + monitor.height)
1731 *y += sample->allocation.height;
1732 else if (*y - *height >= monitor.y)
1734 else if (monitor.y + monitor.height - (*y + sample->allocation.height) > *y - monitor.y)
1736 *y += sample->allocation.height;
1737 *height = monitor.y + monitor.height - *y;
1741 *height = *y - monitor.y;
1745 if (popup_req.height > *height)
1747 vpolicy = GTK_POLICY_ALWAYS;
1749 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
1755 cell_view_is_sensitive (GtkCellView *cell_view)
1757 GList *cells, *list;
1760 cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (cell_view));
1763 for (list = cells; list; list = list->next)
1765 g_object_get (list->data, "sensitive", &sensitive, NULL);
1770 g_list_free (cells);
1776 tree_column_row_is_sensitive (GtkComboBox *combo_box,
1779 GtkComboBoxPrivate *priv = combo_box->priv;
1780 GList *cells, *list;
1786 if (priv->row_separator_func)
1788 if (priv->row_separator_func (priv->model, iter,
1789 priv->row_separator_data))
1793 gtk_tree_view_column_cell_set_cell_data (priv->column,
1795 iter, FALSE, FALSE);
1797 cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (priv->column));
1800 for (list = cells; list; list = list->next)
1802 g_object_get (list->data, "sensitive", &sensitive, NULL);
1807 g_list_free (cells);
1813 update_menu_sensitivity (GtkComboBox *combo_box,
1816 GtkComboBoxPrivate *priv = combo_box->priv;
1817 GList *children, *child;
1818 GtkWidget *item, *submenu, *separator;
1819 GtkWidget *cell_view;
1825 children = gtk_container_get_children (GTK_CONTAINER (menu));
1827 for (child = children; child; child = child->next)
1829 item = GTK_WIDGET (child->data);
1830 cell_view = gtk_bin_get_child (GTK_BIN (item));
1832 if (!GTK_IS_CELL_VIEW (cell_view))
1835 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (item));
1836 if (submenu != NULL)
1838 gtk_widget_set_sensitive (item, TRUE);
1839 update_menu_sensitivity (combo_box, submenu);
1843 sensitive = cell_view_is_sensitive (GTK_CELL_VIEW (cell_view));
1845 if (menu != priv->popup_widget && child == children)
1847 separator = GTK_WIDGET (child->next->data);
1848 g_object_set (item, "visible", sensitive, NULL);
1849 g_object_set (separator, "visible", sensitive, NULL);
1852 gtk_widget_set_sensitive (item, sensitive);
1856 g_list_free (children);
1860 gtk_combo_box_menu_popup (GtkComboBox *combo_box,
1862 guint32 activate_time)
1864 GtkComboBoxPrivate *priv = combo_box->priv;
1867 gint width, min_width;
1869 update_menu_sensitivity (combo_box, priv->popup_widget);
1872 if (gtk_tree_row_reference_valid (priv->active_row))
1874 path = gtk_tree_row_reference_get_path (priv->active_row);
1875 active_item = gtk_tree_path_get_indices (path)[0];
1876 gtk_tree_path_free (path);
1878 if (priv->add_tearoffs)
1882 /* FIXME handle nested menus better */
1883 gtk_menu_set_active (GTK_MENU (priv->popup_widget), active_item);
1885 if (priv->wrap_width == 0)
1887 width = GTK_WIDGET (combo_box)->allocation.width;
1888 gtk_widget_set_size_request (priv->popup_widget, -1, -1);
1889 gtk_size_request_get_width (GTK_SIZE_REQUEST (priv->popup_widget), &min_width, NULL);
1891 gtk_widget_set_size_request (priv->popup_widget,
1892 MAX (width, min_width), -1);
1895 gtk_menu_popup (GTK_MENU (priv->popup_widget),
1897 gtk_combo_box_menu_position, combo_box,
1898 button, activate_time);
1902 popup_grab_on_window (GdkWindow *window,
1903 GdkDevice *keyboard,
1905 guint32 activate_time)
1908 gdk_device_grab (keyboard, window,
1909 GDK_OWNERSHIP_WINDOW, TRUE,
1910 GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
1911 NULL, activate_time) != GDK_GRAB_SUCCESS)
1915 gdk_device_grab (pointer, window,
1916 GDK_OWNERSHIP_WINDOW, TRUE,
1917 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
1918 GDK_POINTER_MOTION_MASK,
1919 NULL, activate_time) != GDK_GRAB_SUCCESS)
1922 gdk_device_ungrab (keyboard, activate_time);
1931 * gtk_combo_box_popup:
1932 * @combo_box: a #GtkComboBox
1934 * Pops up the menu or dropdown list of @combo_box.
1936 * This function is mostly intended for use by accessibility technologies;
1937 * applications should have little use for it.
1942 gtk_combo_box_popup (GtkComboBox *combo_box)
1944 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
1946 g_signal_emit (combo_box, combo_box_signals[POPUP], 0);
1950 * gtk_combo_box_popup_for_device:
1951 * @combo_box: a #GtkComboBox
1952 * @device: a #GdkDevice
1954 * Pops up the menu or dropdown list of @combo_box, the popup window
1955 * will be grabbed so only @device and its associated pointer/keyboard
1956 * are the only #GdkDevice<!-- -->s able to send events to it.
1961 gtk_combo_box_popup_for_device (GtkComboBox *combo_box,
1964 GtkComboBoxPrivate *priv = combo_box->priv;
1965 gint x, y, width, height;
1966 GtkTreePath *path = NULL, *ppath;
1967 GtkWidget *toplevel;
1968 GdkDevice *keyboard, *pointer;
1971 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
1972 g_return_if_fail (GDK_IS_DEVICE (device));
1974 if (!gtk_widget_get_realized (GTK_WIDGET (combo_box)))
1977 if (gtk_widget_get_mapped (priv->popup_widget))
1980 if (priv->grab_pointer && priv->grab_keyboard)
1983 time = gtk_get_current_event_time ();
1985 if (device->source == GDK_SOURCE_KEYBOARD)
1988 pointer = gdk_device_get_associated_device (device);
1993 keyboard = gdk_device_get_associated_device (device);
1996 if (GTK_IS_MENU (priv->popup_widget))
1998 gtk_combo_box_menu_popup (combo_box,
1999 priv->activate_button,
2000 priv->activate_time);
2004 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (combo_box));
2005 if (GTK_IS_WINDOW (toplevel))
2006 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
2007 GTK_WINDOW (priv->popup_window));
2009 gtk_widget_show_all (priv->scrolled_window);
2010 gtk_combo_box_list_position (combo_box, &x, &y, &width, &height);
2012 gtk_widget_set_size_request (priv->popup_window, width, height);
2013 gtk_window_move (GTK_WINDOW (priv->popup_window), x, y);
2015 if (gtk_tree_row_reference_valid (priv->active_row))
2017 path = gtk_tree_row_reference_get_path (priv->active_row);
2018 ppath = gtk_tree_path_copy (path);
2019 if (gtk_tree_path_up (ppath))
2020 gtk_tree_view_expand_to_path (GTK_TREE_VIEW (priv->tree_view),
2022 gtk_tree_path_free (ppath);
2024 gtk_tree_view_set_hover_expand (GTK_TREE_VIEW (priv->tree_view),
2028 gtk_widget_show (priv->popup_window);
2032 gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->tree_view),
2034 gtk_tree_path_free (path);
2037 gtk_widget_grab_focus (priv->popup_window);
2038 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->button),
2041 if (!gtk_widget_has_focus (priv->tree_view))
2042 gtk_widget_grab_focus (priv->tree_view);
2044 if (!popup_grab_on_window (priv->popup_window->window,
2045 keyboard, pointer, time))
2047 gtk_widget_hide (priv->popup_window);
2051 gtk_device_grab_add (priv->popup_window, pointer, TRUE);
2052 priv->grab_pointer = pointer;
2053 priv->grab_keyboard = keyboard;
2057 gtk_combo_box_real_popup (GtkComboBox *combo_box)
2061 device = gtk_get_current_event_device ();
2065 GdkDeviceManager *device_manager;
2066 GdkDisplay *display;
2069 display = gtk_widget_get_display (GTK_WIDGET (combo_box));
2070 device_manager = gdk_display_get_device_manager (display);
2072 /* No device was set, pick the first master device */
2073 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
2074 device = devices->data;
2075 g_list_free (devices);
2078 gtk_combo_box_popup_for_device (combo_box, device);
2082 gtk_combo_box_real_popdown (GtkComboBox *combo_box)
2084 if (combo_box->priv->popup_shown)
2086 gtk_combo_box_popdown (combo_box);
2094 * gtk_combo_box_popdown:
2095 * @combo_box: a #GtkComboBox
2097 * Hides the menu or dropdown list of @combo_box.
2099 * This function is mostly intended for use by accessibility technologies;
2100 * applications should have little use for it.
2105 gtk_combo_box_popdown (GtkComboBox *combo_box)
2107 GtkComboBoxPrivate *priv = combo_box->priv;
2109 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
2111 if (GTK_IS_MENU (priv->popup_widget))
2113 gtk_menu_popdown (GTK_MENU (priv->popup_widget));
2117 if (!gtk_widget_get_realized (GTK_WIDGET (combo_box)))
2120 gtk_device_grab_remove (priv->popup_window, priv->grab_pointer);
2121 gtk_widget_hide_all (priv->popup_window);
2122 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->button),
2125 priv->grab_pointer = NULL;
2126 priv->grab_keyboard = NULL;
2130 gtk_combo_box_update_requested_width (GtkComboBox *combo_box,
2133 GtkComboBoxPrivate *priv = combo_box->priv;
2134 gint padding, min_width, nat_width;
2136 if (priv->cell_view)
2137 gtk_widget_style_get (priv->cell_view,
2138 "focus-line-width", &padding,
2143 /* add some pixels for good measure */
2144 padding += BONUS_PADDING;
2146 if (priv->cell_view)
2147 gtk_cell_view_get_desired_width_of_row (GTK_CELL_VIEW (priv->cell_view),
2148 path, &min_width, &nat_width);
2150 min_width = nat_width = 0;
2152 min_width += padding;
2153 nat_width += padding;
2155 if (min_width > priv->minimum_width || nat_width > priv->natural_width)
2157 priv->minimum_width = MAX (priv->minimum_width, min_width);
2158 priv->natural_width = MAX (priv->natural_width, nat_width);
2160 if (priv->cell_view)
2162 gtk_widget_set_size_request (priv->cell_view, min_width, -1);
2163 gtk_widget_queue_resize (priv->cell_view);
2168 #define GTK_COMBO_BOX_SIZE_ALLOCATE_BUTTON \
2169 gtk_widget_size_request (combo_box->priv->button, &req); \
2172 child.x = allocation->x + shadow_width; \
2174 child.x = allocation->x + allocation->width - req.width - shadow_width; \
2176 child.y = allocation->y + shadow_height; \
2177 child.width = req.width; \
2178 child.height = allocation->height - 2 * shadow_height; \
2179 child.width = MAX (1, child.width); \
2180 child.height = MAX (1, child.height); \
2182 gtk_widget_size_allocate (combo_box->priv->button, &child);
2185 gtk_combo_box_size_allocate (GtkWidget *widget,
2186 GtkAllocation *allocation)
2188 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
2189 GtkComboBoxPrivate *priv = combo_box->priv;
2190 GtkWidget *child_widget;
2191 gint shadow_width, shadow_height;
2192 gint focus_width, focus_pad;
2193 GtkAllocation child;
2195 gboolean is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2197 widget->allocation = *allocation;
2198 child_widget = gtk_bin_get_child (GTK_BIN (widget));
2200 gtk_widget_style_get (GTK_WIDGET (widget),
2201 "focus-line-width", &focus_width,
2202 "focus-padding", &focus_pad,
2205 if (GTK_SHADOW_NONE != priv->shadow_type)
2207 shadow_width = widget->style->xthickness;
2208 shadow_height = widget->style->ythickness;
2216 if (!priv->tree_view)
2218 if (priv->cell_view)
2220 gint xthickness, ythickness;
2225 allocation->x += shadow_width;
2226 allocation->y += shadow_height;
2227 allocation->width -= 2 * shadow_width;
2228 allocation->height -= 2 * shadow_height;
2230 gtk_widget_size_allocate (priv->button, allocation);
2232 /* set some things ready */
2233 border_width = gtk_container_get_border_width (GTK_CONTAINER (priv->button));
2234 xthickness = priv->button->style->xthickness;
2235 ythickness = priv->button->style->ythickness;
2237 child.x = allocation->x;
2238 child.y = allocation->y;
2239 width = allocation->width;
2240 child.height = allocation->height;
2242 if (!priv->is_cell_renderer)
2244 child.x += border_width + xthickness + focus_width + focus_pad;
2245 child.y += border_width + ythickness + focus_width + focus_pad;
2246 width -= 2 * (child.x - allocation->x);
2247 child.height -= 2 * (child.y - allocation->y);
2251 /* handle the children */
2252 gtk_widget_size_request (priv->arrow, &req);
2253 child.width = req.width;
2255 child.x += width - req.width;
2256 child.width = MAX (1, child.width);
2257 child.height = MAX (1, child.height);
2258 gtk_widget_size_allocate (priv->arrow, &child);
2260 child.x += req.width;
2261 gtk_widget_size_request (priv->separator, &req);
2262 child.width = req.width;
2264 child.x -= req.width;
2265 child.width = MAX (1, child.width);
2266 child.height = MAX (1, child.height);
2267 gtk_widget_size_allocate (priv->separator, &child);
2271 child.x += req.width;
2272 child.width = allocation->x + allocation->width
2273 - (border_width + xthickness + focus_width + focus_pad)
2278 child.width = child.x;
2279 child.x = allocation->x
2280 + border_width + xthickness + focus_width + focus_pad;
2281 child.width -= child.x;
2284 if (gtk_widget_get_visible (priv->popup_widget))
2286 gint width, min_width;
2288 if (priv->wrap_width == 0)
2290 width = GTK_WIDGET (combo_box)->allocation.width;
2291 gtk_widget_set_size_request (priv->popup_widget, -1, -1);
2292 gtk_size_request_get_width (GTK_SIZE_REQUEST (priv->popup_widget), &min_width, NULL);
2293 gtk_widget_set_size_request (priv->popup_widget,
2294 MAX (width, min_width), -1);
2297 /* reposition the menu after giving it a new width */
2298 gtk_menu_reposition (GTK_MENU (priv->popup_widget));
2301 child.width = MAX (1, child.width);
2302 child.height = MAX (1, child.height);
2303 gtk_widget_size_allocate (child_widget, &child);
2307 GTK_COMBO_BOX_SIZE_ALLOCATE_BUTTON
2310 child.x = allocation->x + req.width + shadow_width;
2312 child.x = allocation->x + shadow_width;
2313 child.y = allocation->y + shadow_height;
2314 child.width = allocation->width - req.width - 2 * shadow_width;
2315 child.width = MAX (1, child.width);
2316 child.height = MAX (1, child.height);
2317 gtk_widget_size_allocate (child_widget, &child);
2324 /* Combobox thickness + border-width */
2325 guint border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
2326 int delta_x = shadow_width + border_width;
2327 int delta_y = shadow_height + border_width;
2330 GTK_COMBO_BOX_SIZE_ALLOCATE_BUTTON
2334 child.x = allocation->x + req.width;
2336 child.x = allocation->x;
2338 child.y = allocation->y;
2339 child.width = allocation->width - req.width;
2340 child.height = allocation->height;
2342 if (priv->cell_view_frame)
2346 child.width = MAX (1, child.width - delta_x * 2);
2347 child.height = MAX (1, child.height - delta_y * 2);
2348 gtk_widget_size_allocate (priv->cell_view_frame, &child);
2351 if (priv->has_frame)
2353 border_width = gtk_container_get_border_width (GTK_CONTAINER (priv->cell_view_frame));
2354 delta_x = border_width + GTK_WIDGET (priv->cell_view_frame)->style->xthickness;
2355 delta_y = border_width + GTK_WIDGET (priv->cell_view_frame)->style->ythickness;
2359 child.width -= delta_x * 2;
2360 child.height -= delta_y * 2;
2367 child.width -= delta_x * 2;
2368 child.height -= delta_y * 2;
2371 if (gtk_widget_get_visible (priv->popup_window))
2373 gint x, y, width, height;
2374 gtk_combo_box_list_position (combo_box, &x, &y, &width, &height);
2375 gtk_window_move (GTK_WINDOW (priv->popup_window), x, y);
2376 gtk_widget_set_size_request (priv->popup_window, width, height);
2380 child.width = MAX (1, child.width);
2381 child.height = MAX (1, child.height);
2383 gtk_widget_size_allocate (child_widget, &child);
2387 #undef GTK_COMBO_BOX_ALLOCATE_BUTTON
2390 gtk_combo_box_unset_model (GtkComboBox *combo_box)
2392 GtkComboBoxPrivate *priv = combo_box->priv;
2396 g_signal_handler_disconnect (priv->model,
2398 g_signal_handler_disconnect (priv->model,
2400 g_signal_handler_disconnect (priv->model,
2401 priv->reordered_id);
2402 g_signal_handler_disconnect (priv->model,
2407 if (!priv->tree_view)
2409 if (priv->popup_widget)
2410 gtk_container_foreach (GTK_CONTAINER (priv->popup_widget),
2411 (GtkCallback)gtk_widget_destroy, NULL);
2416 g_object_unref (priv->model);
2420 if (priv->active_row)
2422 gtk_tree_row_reference_free (priv->active_row);
2423 priv->active_row = NULL;
2426 if (priv->cell_view)
2427 gtk_cell_view_set_model (GTK_CELL_VIEW (priv->cell_view), NULL);
2431 gtk_combo_box_forall (GtkContainer *container,
2432 gboolean include_internals,
2433 GtkCallback callback,
2434 gpointer callback_data)
2436 GtkComboBox *combo_box = GTK_COMBO_BOX (container);
2437 GtkComboBoxPrivate *priv = combo_box->priv;
2440 if (include_internals)
2443 (* callback) (priv->button, callback_data);
2444 if (priv->cell_view_frame)
2445 (* callback) (priv->cell_view_frame, callback_data);
2448 child = gtk_bin_get_child (GTK_BIN (container));
2450 (* callback) (child, callback_data);
2454 gtk_combo_box_child_show (GtkWidget *widget,
2455 GtkComboBox *combo_box)
2457 GtkComboBoxPrivate *priv = combo_box->priv;
2459 priv->popup_shown = TRUE;
2460 g_object_notify (G_OBJECT (combo_box), "popup-shown");
2464 gtk_combo_box_child_hide (GtkWidget *widget,
2465 GtkComboBox *combo_box)
2467 GtkComboBoxPrivate *priv = combo_box->priv;
2469 priv->popup_shown = FALSE;
2470 g_object_notify (G_OBJECT (combo_box), "popup-shown");
2474 gtk_combo_box_expose_event (GtkWidget *widget,
2475 GdkEventExpose *event)
2477 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
2478 GtkComboBoxPrivate *priv = combo_box->priv;
2480 if (gtk_widget_is_drawable (widget) &&
2481 GTK_SHADOW_NONE != priv->shadow_type)
2483 gtk_paint_shadow (widget->style, widget->window,
2484 GTK_STATE_NORMAL, priv->shadow_type,
2485 NULL, widget, "combobox",
2486 widget->allocation.x, widget->allocation.y,
2487 widget->allocation.width, widget->allocation.height);
2490 gtk_container_propagate_expose (GTK_CONTAINER (widget),
2491 priv->button, event);
2493 if (priv->tree_view && priv->cell_view_frame)
2495 gtk_container_propagate_expose (GTK_CONTAINER (widget),
2496 priv->cell_view_frame, event);
2499 gtk_container_propagate_expose (GTK_CONTAINER (widget),
2500 gtk_bin_get_child (GTK_BIN (widget)),
2516 path_visible (GtkTreeView *view,
2522 /* Note that we rely on the fact that collapsed rows don't have nodes
2524 return _gtk_tree_view_find_node (view, path, &tree, &node);
2528 tree_next_func (GtkTreeModel *model,
2533 SearchData *search_data = (SearchData *)data;
2535 if (search_data->found)
2537 if (!tree_column_row_is_sensitive (search_data->combo, iter))
2540 if (search_data->visible &&
2541 !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
2544 search_data->set = TRUE;
2545 search_data->iter = *iter;
2550 if (gtk_tree_path_compare (path, search_data->path) == 0)
2551 search_data->found = TRUE;
2557 tree_next (GtkComboBox *combo,
2558 GtkTreeModel *model,
2563 SearchData search_data;
2565 search_data.combo = combo;
2566 search_data.path = gtk_tree_model_get_path (model, iter);
2567 search_data.visible = visible;
2568 search_data.found = FALSE;
2569 search_data.set = FALSE;
2571 gtk_tree_model_foreach (model, tree_next_func, &search_data);
2573 *next = search_data.iter;
2575 gtk_tree_path_free (search_data.path);
2577 return search_data.set;
2581 tree_prev_func (GtkTreeModel *model,
2586 SearchData *search_data = (SearchData *)data;
2588 if (gtk_tree_path_compare (path, search_data->path) == 0)
2590 search_data->found = TRUE;
2594 if (!tree_column_row_is_sensitive (search_data->combo, iter))
2597 if (search_data->visible &&
2598 !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
2601 search_data->set = TRUE;
2602 search_data->iter = *iter;
2608 tree_prev (GtkComboBox *combo,
2609 GtkTreeModel *model,
2614 SearchData search_data;
2616 search_data.combo = combo;
2617 search_data.path = gtk_tree_model_get_path (model, iter);
2618 search_data.visible = visible;
2619 search_data.found = FALSE;
2620 search_data.set = FALSE;
2622 gtk_tree_model_foreach (model, tree_prev_func, &search_data);
2624 *prev = search_data.iter;
2626 gtk_tree_path_free (search_data.path);
2628 return search_data.set;
2632 tree_last_func (GtkTreeModel *model,
2637 SearchData *search_data = (SearchData *)data;
2639 if (!tree_column_row_is_sensitive (search_data->combo, iter))
2642 /* Note that we rely on the fact that collapsed rows don't have nodes
2644 if (search_data->visible &&
2645 !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
2648 search_data->set = TRUE;
2649 search_data->iter = *iter;
2655 tree_last (GtkComboBox *combo,
2656 GtkTreeModel *model,
2660 SearchData search_data;
2662 search_data.combo = combo;
2663 search_data.visible = visible;
2664 search_data.set = FALSE;
2666 gtk_tree_model_foreach (model, tree_last_func, &search_data);
2668 *last = search_data.iter;
2670 return search_data.set;
2675 tree_first_func (GtkTreeModel *model,
2680 SearchData *search_data = (SearchData *)data;
2682 if (!tree_column_row_is_sensitive (search_data->combo, iter))
2685 if (search_data->visible &&
2686 !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
2689 search_data->set = TRUE;
2690 search_data->iter = *iter;
2696 tree_first (GtkComboBox *combo,
2697 GtkTreeModel *model,
2701 SearchData search_data;
2703 search_data.combo = combo;
2704 search_data.visible = visible;
2705 search_data.set = FALSE;
2707 gtk_tree_model_foreach (model, tree_first_func, &search_data);
2709 *first = search_data.iter;
2711 return search_data.set;
2715 gtk_combo_box_scroll_event (GtkWidget *widget,
2716 GdkEventScroll *event)
2718 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
2721 GtkTreeIter new_iter;
2723 if (!gtk_combo_box_get_active_iter (combo_box, &iter))
2726 if (event->direction == GDK_SCROLL_UP)
2727 found = tree_prev (combo_box, combo_box->priv->model,
2728 &iter, &new_iter, FALSE);
2730 found = tree_next (combo_box, combo_box->priv->model,
2731 &iter, &new_iter, FALSE);
2734 gtk_combo_box_set_active_iter (combo_box, &new_iter);
2744 gtk_combo_box_sync_cells (GtkComboBox *combo_box,
2745 GtkCellLayout *cell_layout)
2747 GtkComboBoxPrivate *priv = combo_box->priv;
2750 for (k = priv->cells; k; k = k->next)
2753 ComboCellInfo *info = (ComboCellInfo *)k->data;
2755 if (info->pack == GTK_PACK_START)
2756 gtk_cell_layout_pack_start (cell_layout,
2757 info->cell, info->expand);
2758 else if (info->pack == GTK_PACK_END)
2759 gtk_cell_layout_pack_end (cell_layout,
2760 info->cell, info->expand);
2762 gtk_cell_layout_set_cell_data_func (cell_layout,
2764 combo_cell_data_func, info, NULL);
2766 for (j = info->attributes; j; j = j->next->next)
2768 gtk_cell_layout_add_attribute (cell_layout,
2771 GPOINTER_TO_INT (j->next->data));
2777 gtk_combo_box_menu_setup (GtkComboBox *combo_box,
2778 gboolean add_children)
2780 GtkComboBoxPrivate *priv = combo_box->priv;
2784 child = gtk_bin_get_child (GTK_BIN (combo_box));
2786 if (priv->cell_view)
2788 priv->button = gtk_toggle_button_new ();
2789 gtk_button_set_focus_on_click (GTK_BUTTON (priv->button),
2790 priv->focus_on_click);
2792 g_signal_connect (priv->button, "toggled",
2793 G_CALLBACK (gtk_combo_box_button_toggled), combo_box);
2794 gtk_widget_set_parent (priv->button,
2795 gtk_widget_get_parent (child));
2797 priv->box = gtk_hbox_new (FALSE, 0);
2798 gtk_container_add (GTK_CONTAINER (priv->button), priv->box);
2800 priv->separator = gtk_vseparator_new ();
2801 gtk_container_add (GTK_CONTAINER (priv->box), priv->separator);
2803 priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
2804 gtk_container_add (GTK_CONTAINER (priv->box), priv->arrow);
2806 gtk_widget_show_all (priv->button);
2810 priv->button = gtk_toggle_button_new ();
2811 gtk_button_set_focus_on_click (GTK_BUTTON (priv->button),
2812 priv->focus_on_click);
2814 g_signal_connect (priv->button, "toggled",
2815 G_CALLBACK (gtk_combo_box_button_toggled), combo_box);
2816 gtk_widget_set_parent (priv->button,
2817 gtk_widget_get_parent (child));
2819 priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
2820 gtk_container_add (GTK_CONTAINER (priv->button), priv->arrow);
2821 gtk_widget_show_all (priv->button);
2824 g_signal_connect (priv->button, "button-press-event",
2825 G_CALLBACK (gtk_combo_box_menu_button_press),
2827 g_signal_connect (priv->button, "state-changed",
2828 G_CALLBACK (gtk_combo_box_button_state_changed),
2831 /* create our funky menu */
2832 menu = gtk_menu_new ();
2833 gtk_widget_set_name (menu, "gtk-combobox-popup-menu");
2834 gtk_menu_set_reserve_toggle_size (GTK_MENU (menu), FALSE);
2836 g_signal_connect (menu, "key-press-event",
2837 G_CALLBACK (gtk_combo_box_menu_key_press), combo_box);
2838 gtk_combo_box_set_popup_widget (combo_box, menu);
2842 gtk_combo_box_menu_fill (combo_box);
2844 /* the column is needed in tree_column_row_is_sensitive() */
2845 priv->column = gtk_tree_view_column_new ();
2846 g_object_ref_sink (priv->column);
2847 gtk_combo_box_sync_cells (combo_box, GTK_CELL_LAYOUT (priv->column));
2849 gtk_combo_box_update_title (combo_box);
2850 gtk_combo_box_update_sensitivity (combo_box);
2854 gtk_combo_box_menu_fill (GtkComboBox *combo_box)
2856 GtkComboBoxPrivate *priv = combo_box->priv;
2862 menu = priv->popup_widget;
2864 if (priv->add_tearoffs)
2866 GtkWidget *tearoff = gtk_tearoff_menu_item_new ();
2868 gtk_widget_show (tearoff);
2870 if (priv->wrap_width)
2871 gtk_menu_attach (GTK_MENU (menu), tearoff, 0, priv->wrap_width, 0, 1);
2873 gtk_menu_shell_append (GTK_MENU_SHELL (menu), tearoff);
2876 gtk_combo_box_menu_fill_level (combo_box, menu, NULL);
2880 gtk_cell_view_menu_item_new (GtkComboBox *combo_box,
2881 GtkTreeModel *model,
2884 GtkWidget *cell_view;
2889 cell_view = gtk_cell_view_new ();
2890 item = gtk_menu_item_new ();
2891 gtk_container_add (GTK_CONTAINER (item), cell_view);
2893 gtk_cell_view_set_model (GTK_CELL_VIEW (cell_view), model);
2894 path = gtk_tree_model_get_path (model, iter);
2895 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (cell_view), path);
2896 gtk_tree_path_free (path);
2898 gtk_combo_box_sync_cells (combo_box, GTK_CELL_LAYOUT (cell_view));
2899 gtk_widget_size_request (cell_view, &req);
2900 gtk_widget_show (cell_view);
2906 gtk_combo_box_menu_fill_level (GtkComboBox *combo_box,
2908 GtkTreeIter *parent)
2910 GtkComboBoxPrivate *priv = combo_box->priv;
2911 GtkTreeModel *model = priv->model;
2912 GtkWidget *item, *submenu, *subitem, *separator;
2914 gboolean is_separator;
2919 n_children = gtk_tree_model_iter_n_children (model, parent);
2922 for (i = 0; i < n_children; i++)
2924 gtk_tree_model_iter_nth_child (model, &iter, parent, i);
2926 if (priv->row_separator_func)
2927 is_separator = priv->row_separator_func (priv->model, &iter,
2928 priv->row_separator_data);
2930 is_separator = FALSE;
2934 item = gtk_separator_menu_item_new ();
2935 path = gtk_tree_model_get_path (model, &iter);
2936 g_object_set_data_full (G_OBJECT (item),
2937 I_("gtk-combo-box-item-path"),
2938 gtk_tree_row_reference_new (model, path),
2939 (GDestroyNotify)gtk_tree_row_reference_free);
2940 gtk_tree_path_free (path);
2944 item = gtk_cell_view_menu_item_new (combo_box, model, &iter);
2945 if (gtk_tree_model_iter_has_child (model, &iter))
2947 submenu = gtk_menu_new ();
2948 gtk_menu_set_reserve_toggle_size (GTK_MENU (submenu), FALSE);
2949 gtk_widget_show (submenu);
2950 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
2952 /* Ugly - since menus can only activate leafs, we have to
2953 * duplicate the item inside the submenu.
2955 subitem = gtk_cell_view_menu_item_new (combo_box, model, &iter);
2956 separator = gtk_separator_menu_item_new ();
2957 gtk_widget_show (subitem);
2958 gtk_widget_show (separator);
2959 g_signal_connect (subitem, "activate",
2960 G_CALLBACK (gtk_combo_box_menu_item_activate),
2962 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), subitem);
2963 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), separator);
2965 gtk_combo_box_menu_fill_level (combo_box, submenu, &iter);
2967 g_signal_connect (item, "activate",
2968 G_CALLBACK (gtk_combo_box_menu_item_activate),
2972 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
2973 if (priv->wrap_width && menu == priv->popup_widget)
2974 gtk_combo_box_relayout_item (combo_box, item, &iter, last);
2975 gtk_widget_show (item);
2982 gtk_combo_box_menu_destroy (GtkComboBox *combo_box)
2984 GtkComboBoxPrivate *priv = combo_box->priv;
2986 g_signal_handlers_disconnect_matched (priv->button,
2987 G_SIGNAL_MATCH_DATA,
2989 gtk_combo_box_menu_button_press, NULL);
2990 g_signal_handlers_disconnect_matched (priv->button,
2991 G_SIGNAL_MATCH_DATA,
2993 gtk_combo_box_button_state_changed, combo_box);
2995 /* unparent will remove our latest ref */
2996 gtk_widget_unparent (priv->button);
2999 priv->button = NULL;
3001 priv->separator = NULL;
3003 g_object_unref (priv->column);
3004 priv->column = NULL;
3006 /* changing the popup window will unref the menu and the children */
3014 menu_occupied (GtkMenu *menu,
3018 guint bottom_attach)
3022 for (i = GTK_MENU_SHELL (menu)->children; i; i = i->next)
3026 gtk_container_child_get (GTK_CONTAINER (menu),
3030 "bottom-attach", &b,
3034 /* look if this item intersects with the given coordinates */
3035 if (right_attach > l && left_attach < r && bottom_attach > t && top_attach < b)
3043 gtk_combo_box_relayout_item (GtkComboBox *combo_box,
3048 GtkComboBoxPrivate *priv = combo_box->priv;
3049 gint current_col = 0, current_row = 0;
3050 gint rows = 1, cols = 1;
3051 GtkWidget *menu = priv->popup_widget;
3053 if (!GTK_IS_MENU_SHELL (menu))
3056 if (priv->col_column == -1 &&
3057 priv->row_column == -1 &&
3060 gtk_container_child_get (GTK_CONTAINER (menu),
3062 "right-attach", ¤t_col,
3063 "top-attach", ¤t_row,
3065 if (current_col + cols > priv->wrap_width)
3073 if (priv->col_column != -1)
3074 gtk_tree_model_get (priv->model, iter,
3075 priv->col_column, &cols,
3077 if (priv->row_column != -1)
3078 gtk_tree_model_get (priv->model, iter,
3079 priv->row_column, &rows,
3084 if (current_col + cols > priv->wrap_width)
3090 if (!menu_occupied (GTK_MENU (menu),
3091 current_col, current_col + cols,
3092 current_row, current_row + rows))
3099 /* set attach props */
3100 gtk_menu_attach (GTK_MENU (menu), item,
3101 current_col, current_col + cols,
3102 current_row, current_row + rows);
3106 gtk_combo_box_relayout (GtkComboBox *combo_box)
3111 menu = combo_box->priv->popup_widget;
3113 /* do nothing unless we are in menu style and realized */
3114 if (combo_box->priv->tree_view || !GTK_IS_MENU_SHELL (menu))
3117 list = gtk_container_get_children (GTK_CONTAINER (menu));
3119 for (j = g_list_last (list); j; j = j->prev)
3120 gtk_container_remove (GTK_CONTAINER (menu), j->data);
3122 gtk_combo_box_menu_fill (combo_box);
3129 gtk_combo_box_menu_button_press (GtkWidget *widget,
3130 GdkEventButton *event,
3133 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3134 GtkComboBoxPrivate *priv = combo_box->priv;
3136 if (GTK_IS_MENU (priv->popup_widget) &&
3137 event->type == GDK_BUTTON_PRESS && event->button == 1)
3139 if (priv->focus_on_click &&
3140 !gtk_widget_has_focus (priv->button))
3141 gtk_widget_grab_focus (priv->button);
3143 gtk_combo_box_menu_popup (combo_box, event->button, event->time);
3152 gtk_combo_box_menu_item_activate (GtkWidget *item,
3155 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3156 GtkWidget *cell_view;
3160 cell_view = gtk_bin_get_child (GTK_BIN (item));
3162 g_return_if_fail (GTK_IS_CELL_VIEW (cell_view));
3164 path = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (cell_view));
3166 if (gtk_tree_model_get_iter (combo_box->priv->model, &iter, path))
3168 if (gtk_menu_item_get_submenu (GTK_MENU_ITEM (item)) == NULL)
3169 gtk_combo_box_set_active_iter (combo_box, &iter);
3172 gtk_tree_path_free (path);
3174 g_object_set (combo_box,
3175 "editing-canceled", FALSE,
3180 gtk_combo_box_update_sensitivity (GtkComboBox *combo_box)
3183 gboolean sensitive = TRUE; /* fool code checkers */
3185 if (!combo_box->priv->button)
3188 switch (combo_box->priv->button_sensitivity)
3190 case GTK_SENSITIVITY_ON:
3193 case GTK_SENSITIVITY_OFF:
3196 case GTK_SENSITIVITY_AUTO:
3197 sensitive = combo_box->priv->model &&
3198 gtk_tree_model_get_iter_first (combo_box->priv->model, &iter);
3201 g_assert_not_reached ();
3205 gtk_widget_set_sensitive (combo_box->priv->button, sensitive);
3207 /* In list-mode, we also need to update sensitivity of the event box */
3208 if (GTK_IS_TREE_VIEW (combo_box->priv->tree_view)
3209 && combo_box->priv->cell_view)
3210 gtk_widget_set_sensitive (combo_box->priv->box, sensitive);
3214 gtk_combo_box_model_row_inserted (GtkTreeModel *model,
3219 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3221 if (combo_box->priv->tree_view)
3222 gtk_combo_box_list_popup_resize (combo_box);
3224 gtk_combo_box_menu_row_inserted (model, path, iter, user_data);
3226 gtk_combo_box_update_sensitivity (combo_box);
3230 gtk_combo_box_model_row_deleted (GtkTreeModel *model,
3234 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3235 GtkComboBoxPrivate *priv = combo_box->priv;
3237 if (!gtk_tree_row_reference_valid (priv->active_row))
3239 if (priv->cell_view)
3240 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (priv->cell_view), NULL);
3241 g_signal_emit (combo_box, combo_box_signals[CHANGED], 0);
3244 if (priv->tree_view)
3245 gtk_combo_box_list_popup_resize (combo_box);
3247 gtk_combo_box_menu_row_deleted (model, path, user_data);
3249 gtk_combo_box_update_sensitivity (combo_box);
3253 gtk_combo_box_model_rows_reordered (GtkTreeModel *model,
3259 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3261 gtk_tree_row_reference_reordered (G_OBJECT (user_data), path, iter, new_order);
3263 if (!combo_box->priv->tree_view)
3264 gtk_combo_box_menu_rows_reordered (model, path, iter, new_order, user_data);
3268 gtk_combo_box_model_row_changed (GtkTreeModel *model,
3273 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3274 GtkComboBoxPrivate *priv = combo_box->priv;
3275 GtkTreePath *active_path;
3277 /* FIXME this belongs to GtkCellView */
3278 if (gtk_tree_row_reference_valid (priv->active_row))
3280 active_path = gtk_tree_row_reference_get_path (priv->active_row);
3281 if (gtk_tree_path_compare (path, active_path) == 0 &&
3283 gtk_widget_queue_resize (GTK_WIDGET (priv->cell_view));
3284 gtk_tree_path_free (active_path);
3287 if (priv->tree_view)
3288 gtk_combo_box_list_row_changed (model, path, iter, user_data);
3290 gtk_combo_box_menu_row_changed (model, path, iter, user_data);
3294 list_popup_resize_idle (gpointer user_data)
3296 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3297 GtkComboBoxPrivate *priv = combo_box->priv;
3298 gint x, y, width, height;
3300 if (priv->tree_view && gtk_widget_get_mapped (priv->popup_window))
3302 gtk_combo_box_list_position (combo_box, &x, &y, &width, &height);
3304 gtk_widget_set_size_request (priv->popup_window, width, height);
3305 gtk_window_move (GTK_WINDOW (priv->popup_window), x, y);
3308 priv->resize_idle_id = 0;
3314 gtk_combo_box_list_popup_resize (GtkComboBox *combo_box)
3316 GtkComboBoxPrivate *priv = combo_box->priv;
3318 if (!priv->resize_idle_id)
3319 priv->resize_idle_id =
3320 gdk_threads_add_idle (list_popup_resize_idle, combo_box);
3324 gtk_combo_box_model_row_expanded (GtkTreeModel *model,
3329 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3331 gtk_combo_box_list_popup_resize (combo_box);
3336 find_menu_by_path (GtkWidget *menu,
3338 gboolean skip_first)
3344 GtkTreeRowReference *mref;
3348 list = gtk_container_get_children (GTK_CONTAINER (menu));
3351 for (i = list; i; i = i->next)
3353 child = gtk_bin_get_child (i->data);
3354 if (GTK_IS_SEPARATOR_MENU_ITEM (i->data))
3356 mref = g_object_get_data (G_OBJECT (i->data), "gtk-combo-box-item-path");
3359 else if (!gtk_tree_row_reference_valid (mref))
3362 mpath = gtk_tree_row_reference_get_path (mref);
3364 else if (GTK_IS_CELL_VIEW (child))
3372 mpath = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (child));
3377 /* this case is necessary, since the row reference of
3378 * the cell view may already be updated after a deletion
3385 if (gtk_tree_path_compare (mpath, path) == 0)
3387 gtk_tree_path_free (mpath);
3391 if (gtk_tree_path_is_ancestor (mpath, path))
3393 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
3394 if (submenu != NULL)
3396 gtk_tree_path_free (mpath);
3397 item = find_menu_by_path (submenu, path, TRUE);
3401 gtk_tree_path_free (mpath);
3411 dump_menu_tree (GtkWidget *menu,
3418 list = gtk_container_get_children (GTK_CONTAINER (menu));
3419 for (i = list; i; i = i->next)
3421 if (GTK_IS_CELL_VIEW (GTK_BIN (i->data)->child))
3423 path = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (GTK_BIN (i->data)->child));
3424 g_print ("%*s%s\n", 2 * level, " ", gtk_tree_path_to_string (path));
3425 gtk_tree_path_free (path);
3427 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
3428 if (submenu != NULL)
3429 dump_menu_tree (submenu, level + 1);
3438 gtk_combo_box_menu_row_inserted (GtkTreeModel *model,
3443 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3444 GtkComboBoxPrivate *priv = combo_box->priv;
3446 GtkWidget *item, *menu, *separator;
3450 gboolean is_separator;
3452 if (!priv->popup_widget)
3455 depth = gtk_tree_path_get_depth (path);
3456 pos = gtk_tree_path_get_indices (path)[depth - 1];
3459 ppath = gtk_tree_path_copy (path);
3460 gtk_tree_path_up (ppath);
3461 parent = find_menu_by_path (priv->popup_widget, ppath, FALSE);
3462 gtk_tree_path_free (ppath);
3464 menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (parent));
3467 menu = gtk_menu_new ();
3468 gtk_menu_set_reserve_toggle_size (GTK_MENU (menu), FALSE);
3469 gtk_widget_show (menu);
3470 gtk_menu_item_set_submenu (GTK_MENU_ITEM (parent), menu);
3472 /* Ugly - since menus can only activate leaves, we have to
3473 * duplicate the item inside the submenu.
3475 gtk_tree_model_iter_parent (model, &piter, iter);
3476 item = gtk_cell_view_menu_item_new (combo_box, model, &piter);
3477 separator = gtk_separator_menu_item_new ();
3478 g_signal_connect (item, "activate",
3479 G_CALLBACK (gtk_combo_box_menu_item_activate),
3481 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
3482 gtk_menu_shell_append (GTK_MENU_SHELL (menu), separator);
3483 if (cell_view_is_sensitive (GTK_CELL_VIEW (gtk_bin_get_child (GTK_BIN (item)))))
3485 gtk_widget_show (item);
3486 gtk_widget_show (separator);
3493 menu = priv->popup_widget;
3494 if (priv->add_tearoffs)
3498 if (priv->row_separator_func)
3499 is_separator = priv->row_separator_func (model, iter,
3500 priv->row_separator_data);
3502 is_separator = FALSE;
3506 item = gtk_separator_menu_item_new ();
3507 g_object_set_data_full (G_OBJECT (item),
3508 I_("gtk-combo-box-item-path"),
3509 gtk_tree_row_reference_new (model, path),
3510 (GDestroyNotify)gtk_tree_row_reference_free);
3514 item = gtk_cell_view_menu_item_new (combo_box, model, iter);
3516 g_signal_connect (item, "activate",
3517 G_CALLBACK (gtk_combo_box_menu_item_activate),
3521 gtk_widget_show (item);
3522 gtk_menu_shell_insert (GTK_MENU_SHELL (menu), item, pos);
3526 gtk_combo_box_menu_row_deleted (GtkTreeModel *model,
3530 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3531 GtkComboBoxPrivate *priv = combo_box->priv;
3535 if (!priv->popup_widget)
3538 item = find_menu_by_path (priv->popup_widget, path, FALSE);
3539 menu = gtk_widget_get_parent (item);
3540 gtk_container_remove (GTK_CONTAINER (menu), item);
3542 if (gtk_tree_path_get_depth (path) > 1)
3544 GtkTreePath *parent_path;
3548 parent_path = gtk_tree_path_copy (path);
3549 gtk_tree_path_up (parent_path);
3550 gtk_tree_model_get_iter (model, &iter, parent_path);
3552 if (!gtk_tree_model_iter_has_child (model, &iter))
3554 parent = find_menu_by_path (priv->popup_widget,
3555 parent_path, FALSE);
3556 gtk_menu_item_set_submenu (GTK_MENU_ITEM (parent), NULL);
3562 gtk_combo_box_menu_rows_reordered (GtkTreeModel *model,
3568 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3570 gtk_combo_box_relayout (combo_box);
3574 gtk_combo_box_menu_row_changed (GtkTreeModel *model,
3579 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3580 GtkComboBoxPrivate *priv = combo_box->priv;
3582 gboolean is_separator;
3584 if (!priv->popup_widget)
3587 item = find_menu_by_path (priv->popup_widget, path, FALSE);
3589 if (priv->row_separator_func)
3590 is_separator = priv->row_separator_func (model, iter,
3591 priv->row_separator_data);
3593 is_separator = FALSE;
3595 if (is_separator != GTK_IS_SEPARATOR_MENU_ITEM (item))
3597 gtk_combo_box_menu_row_deleted (model, path, combo_box);
3598 gtk_combo_box_menu_row_inserted (model, path, iter, combo_box);
3601 if (priv->wrap_width && item->parent == priv->popup_widget)
3603 GtkWidget *pitem = NULL;
3606 prev = gtk_tree_path_copy (path);
3608 if (gtk_tree_path_prev (prev))
3609 pitem = find_menu_by_path (priv->popup_widget, prev, FALSE);
3611 gtk_tree_path_free (prev);
3613 /* unattach item so gtk_combo_box_relayout_item() won't spuriously
3615 gtk_container_child_set (GTK_CONTAINER (priv->popup_widget),
3620 "bottom-attach", -1,
3623 gtk_combo_box_relayout_item (combo_box, item, iter, pitem);
3626 gtk_combo_box_update_requested_width (combo_box, path);
3634 gtk_combo_box_list_setup (GtkComboBox *combo_box)
3636 GtkComboBoxPrivate *priv = combo_box->priv;
3637 GtkTreeSelection *sel;
3640 GtkWidget *widget = GTK_WIDGET (combo_box);
3642 priv->button = gtk_toggle_button_new ();
3643 child = gtk_bin_get_child (GTK_BIN (combo_box));
3644 gtk_widget_set_parent (priv->button,
3645 gtk_widget_get_parent (child));
3646 g_signal_connect (priv->button, "button-press-event",
3647 G_CALLBACK (gtk_combo_box_list_button_pressed), combo_box);
3648 g_signal_connect (priv->button, "toggled",
3649 G_CALLBACK (gtk_combo_box_button_toggled), combo_box);
3651 priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
3652 gtk_container_add (GTK_CONTAINER (priv->button), priv->arrow);
3653 priv->separator = NULL;
3654 gtk_widget_show_all (priv->button);
3656 if (priv->cell_view)
3658 style = gtk_widget_get_style (widget);
3659 gtk_cell_view_set_background_color (GTK_CELL_VIEW (priv->cell_view),
3660 &style->base[gtk_widget_get_state (widget)]);
3662 priv->box = gtk_event_box_new ();
3663 gtk_event_box_set_visible_window (GTK_EVENT_BOX (priv->box),
3666 if (priv->has_frame)
3668 priv->cell_view_frame = gtk_frame_new (NULL);
3669 gtk_frame_set_shadow_type (GTK_FRAME (priv->cell_view_frame),
3674 combo_box->priv->cell_view_frame = gtk_event_box_new ();
3675 gtk_event_box_set_visible_window (GTK_EVENT_BOX (combo_box->priv->cell_view_frame),
3679 gtk_widget_set_parent (priv->cell_view_frame,
3680 gtk_widget_get_parent (child));
3681 gtk_container_add (GTK_CONTAINER (priv->cell_view_frame), priv->box);
3682 gtk_widget_show_all (priv->cell_view_frame);
3684 g_signal_connect (priv->box, "button-press-event",
3685 G_CALLBACK (gtk_combo_box_list_button_pressed),
3689 priv->tree_view = gtk_tree_view_new ();
3690 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view));
3691 gtk_tree_selection_set_mode (sel, GTK_SELECTION_BROWSE);
3692 gtk_tree_selection_set_select_function (sel,
3693 gtk_combo_box_list_select_func,
3695 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->tree_view),
3697 gtk_tree_view_set_hover_selection (GTK_TREE_VIEW (priv->tree_view),
3699 if (priv->row_separator_func)
3700 gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (priv->tree_view),
3701 priv->row_separator_func,
3702 priv->row_separator_data,
3705 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->tree_view), priv->model);
3707 priv->column = gtk_tree_view_column_new ();
3708 gtk_tree_view_append_column (GTK_TREE_VIEW (priv->tree_view), priv->column);
3711 gtk_combo_box_sync_cells (combo_box,
3712 GTK_CELL_LAYOUT (priv->column));
3714 if (gtk_tree_row_reference_valid (priv->active_row))
3718 path = gtk_tree_row_reference_get_path (priv->active_row);
3719 gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->tree_view),
3721 gtk_tree_path_free (path);
3724 /* set sample/popup widgets */
3725 gtk_combo_box_set_popup_widget (combo_box, priv->tree_view);
3727 g_signal_connect (priv->tree_view, "key-press-event",
3728 G_CALLBACK (gtk_combo_box_list_key_press),
3730 g_signal_connect (priv->tree_view, "enter-notify-event",
3731 G_CALLBACK (gtk_combo_box_list_enter_notify),
3733 g_signal_connect (priv->tree_view, "row-expanded",
3734 G_CALLBACK (gtk_combo_box_model_row_expanded),
3736 g_signal_connect (priv->tree_view, "row-collapsed",
3737 G_CALLBACK (gtk_combo_box_model_row_expanded),
3739 g_signal_connect (priv->popup_window, "button-press-event",
3740 G_CALLBACK (gtk_combo_box_list_button_pressed),
3742 g_signal_connect (priv->popup_window, "button-release-event",
3743 G_CALLBACK (gtk_combo_box_list_button_released),
3746 gtk_widget_show (priv->tree_view);
3748 gtk_combo_box_update_sensitivity (combo_box);
3752 gtk_combo_box_list_destroy (GtkComboBox *combo_box)
3754 GtkComboBoxPrivate *priv = combo_box->priv;
3756 /* disconnect signals */
3757 g_signal_handlers_disconnect_matched (priv->tree_view,
3758 G_SIGNAL_MATCH_DATA,
3759 0, 0, NULL, NULL, combo_box);
3760 g_signal_handlers_disconnect_matched (priv->button,
3761 G_SIGNAL_MATCH_DATA,
3763 gtk_combo_box_list_button_pressed,
3765 g_signal_handlers_disconnect_matched (priv->popup_window,
3766 G_SIGNAL_MATCH_DATA,
3768 gtk_combo_box_list_button_pressed,
3770 g_signal_handlers_disconnect_matched (priv->popup_window,
3771 G_SIGNAL_MATCH_DATA,
3773 gtk_combo_box_list_button_released,
3776 g_signal_handlers_disconnect_matched (priv->popup_window,
3777 G_SIGNAL_MATCH_DATA,
3779 gtk_combo_box_child_show,
3782 g_signal_handlers_disconnect_matched (priv->popup_window,
3783 G_SIGNAL_MATCH_DATA,
3785 gtk_combo_box_child_hide,
3789 g_signal_handlers_disconnect_matched (priv->box,
3790 G_SIGNAL_MATCH_DATA,
3792 gtk_combo_box_list_button_pressed,
3795 /* destroy things (unparent will kill the latest ref from us)
3796 * last unref on button will destroy the arrow
3798 gtk_widget_unparent (priv->button);
3799 priv->button = NULL;
3802 if (priv->cell_view)
3804 g_object_set (priv->cell_view,
3805 "background-set", FALSE,
3809 if (priv->cell_view_frame)
3811 gtk_widget_unparent (priv->cell_view_frame);
3812 priv->cell_view_frame = NULL;
3816 if (priv->scroll_timer)
3818 g_source_remove (priv->scroll_timer);
3819 priv->scroll_timer = 0;
3822 if (priv->resize_idle_id)
3824 g_source_remove (priv->resize_idle_id);
3825 priv->resize_idle_id = 0;
3828 gtk_widget_destroy (priv->tree_view);
3830 priv->tree_view = NULL;
3831 if (priv->popup_widget)
3833 g_object_unref (priv->popup_widget);
3834 priv->popup_widget = NULL;
3841 gtk_combo_box_list_button_pressed (GtkWidget *widget,
3842 GdkEventButton *event,
3845 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3846 GtkComboBoxPrivate *priv = combo_box->priv;
3848 GtkWidget *ewidget = gtk_get_event_widget ((GdkEvent *)event);
3850 if (ewidget == priv->popup_window)
3853 if ((ewidget != priv->button && ewidget != priv->box) ||
3854 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->button)))
3857 if (priv->focus_on_click &&
3858 !gtk_widget_has_focus (priv->button))
3859 gtk_widget_grab_focus (priv->button);
3861 gtk_combo_box_popup_for_device (combo_box, event->device);
3863 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->button), TRUE);
3865 priv->auto_scroll = FALSE;
3866 if (priv->scroll_timer == 0)
3867 priv->scroll_timer = gdk_threads_add_timeout (SCROLL_TIME,
3868 (GSourceFunc) gtk_combo_box_list_scroll_timeout,
3871 priv->popup_in_progress = TRUE;
3877 gtk_combo_box_list_button_released (GtkWidget *widget,
3878 GdkEventButton *event,
3882 GtkTreePath *path = NULL;
3885 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3886 GtkComboBoxPrivate *priv = combo_box->priv;
3888 gboolean popup_in_progress = FALSE;
3890 GtkWidget *ewidget = gtk_get_event_widget ((GdkEvent *)event);
3892 if (priv->popup_in_progress)
3894 popup_in_progress = TRUE;
3895 priv->popup_in_progress = FALSE;
3898 gtk_tree_view_set_hover_expand (GTK_TREE_VIEW (priv->tree_view),
3900 if (priv->scroll_timer)
3902 g_source_remove (priv->scroll_timer);
3903 priv->scroll_timer = 0;
3906 if (ewidget != priv->tree_view)
3908 if ((ewidget == priv->button ||
3909 ewidget == priv->box) &&
3910 !popup_in_progress &&
3911 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->button)))
3913 gtk_combo_box_popdown (combo_box);
3917 /* released outside treeview */
3918 if (ewidget != priv->button && ewidget != priv->box)
3920 gtk_combo_box_popdown (combo_box);
3928 /* select something cool */
3929 ret = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (priv->tree_view),
3935 return TRUE; /* clicked outside window? */
3937 gtk_tree_model_get_iter (priv->model, &iter, path);
3938 gtk_tree_path_free (path);
3940 gtk_combo_box_popdown (combo_box);
3942 if (tree_column_row_is_sensitive (combo_box, &iter))
3943 gtk_combo_box_set_active_iter (combo_box, &iter);
3949 gtk_combo_box_menu_key_press (GtkWidget *widget,
3953 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3955 if (!gtk_bindings_activate_event (GTK_OBJECT (widget), event))
3957 /* The menu hasn't managed the
3958 * event, forward it to the combobox
3960 gtk_bindings_activate_event (GTK_OBJECT (combo_box), event);
3967 gtk_combo_box_list_key_press (GtkWidget *widget,
3971 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3974 if (event->keyval == GDK_Return || event->keyval == GDK_ISO_Enter || event->keyval == GDK_KP_Enter ||
3975 event->keyval == GDK_space || event->keyval == GDK_KP_Space)
3977 GtkTreeModel *model = NULL;
3979 gtk_combo_box_popdown (combo_box);
3981 if (combo_box->priv->model)
3983 GtkTreeSelection *sel;
3985 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (combo_box->priv->tree_view));
3987 if (gtk_tree_selection_get_selected (sel, &model, &iter))
3988 gtk_combo_box_set_active_iter (combo_box, &iter);
3994 if (!gtk_bindings_activate_event (GTK_OBJECT (widget), event))
3996 /* The list hasn't managed the
3997 * event, forward it to the combobox
3999 gtk_bindings_activate_event (GTK_OBJECT (combo_box), event);
4006 gtk_combo_box_list_auto_scroll (GtkComboBox *combo_box,
4010 GtkWidget *tree_view = combo_box->priv->tree_view;
4014 adj = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (combo_box->priv->scrolled_window));
4015 if (adj && adj->upper - adj->lower > adj->page_size)
4017 if (x <= tree_view->allocation.x &&
4018 adj->lower < adj->value)
4020 value = adj->value - (tree_view->allocation.x - x + 1);
4021 gtk_adjustment_set_value (adj, value);
4023 else if (x >= tree_view->allocation.x + tree_view->allocation.width &&
4024 adj->upper - adj->page_size > adj->value)
4026 value = adj->value + (x - tree_view->allocation.x - tree_view->allocation.width + 1);
4027 gtk_adjustment_set_value (adj, MAX (value, 0.0));
4031 adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (combo_box->priv->scrolled_window));
4032 if (adj && adj->upper - adj->lower > adj->page_size)
4034 if (y <= tree_view->allocation.y &&
4035 adj->lower < adj->value)
4037 value = adj->value - (tree_view->allocation.y - y + 1);
4038 gtk_adjustment_set_value (adj, value);
4040 else if (y >= tree_view->allocation.height &&
4041 adj->upper - adj->page_size > adj->value)
4043 value = adj->value + (y - tree_view->allocation.height + 1);
4044 gtk_adjustment_set_value (adj, MAX (value, 0.0));
4050 gtk_combo_box_list_scroll_timeout (GtkComboBox *combo_box)
4052 GtkComboBoxPrivate *priv = combo_box->priv;
4055 if (priv->auto_scroll)
4057 gdk_window_get_device_position (priv->tree_view->window,
4060 gtk_combo_box_list_auto_scroll (combo_box, x, y);
4067 gtk_combo_box_list_enter_notify (GtkWidget *widget,
4068 GdkEventCrossing *event,
4071 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
4073 combo_box->priv->auto_scroll = TRUE;
4079 gtk_combo_box_list_select_func (GtkTreeSelection *selection,
4080 GtkTreeModel *model,
4082 gboolean path_currently_selected,
4086 gboolean sensitive = FALSE;
4088 for (list = selection->tree_view->priv->columns; list && !sensitive; list = list->next)
4090 GList *cells, *cell;
4091 gboolean cell_sensitive, cell_visible;
4093 GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN (list->data);
4095 if (!column->visible)
4098 gtk_tree_model_get_iter (model, &iter, path);
4099 gtk_tree_view_column_cell_set_cell_data (column, model, &iter,
4102 cell = cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (column));
4105 g_object_get (cell->data,
4106 "sensitive", &cell_sensitive,
4107 "visible", &cell_visible,
4110 if (cell_visible && cell_sensitive)
4115 g_list_free (cells);
4117 sensitive = cell_sensitive;
4124 gtk_combo_box_list_row_changed (GtkTreeModel *model,
4129 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
4131 gtk_combo_box_update_requested_width (combo_box, path);
4135 * GtkCellLayout implementation
4139 pack_start_recurse (GtkWidget *menu,
4140 GtkCellRenderer *cell,
4147 list = gtk_container_get_children (GTK_CONTAINER (menu));
4148 for (i = list; i; i = i->next)
4150 child = gtk_bin_get_child (GTK_BIN (i->data));
4151 if (GTK_IS_CELL_LAYOUT (child))
4152 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (child),
4155 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4156 if (submenu != NULL)
4157 pack_start_recurse (submenu, cell, expand);
4164 gtk_combo_box_cell_layout_pack_start (GtkCellLayout *layout,
4165 GtkCellRenderer *cell,
4168 GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
4169 ComboCellInfo *info;
4170 GtkComboBoxPrivate *priv;
4172 priv = combo_box->priv;
4174 g_object_ref_sink (cell);
4176 info = g_slice_new0 (ComboCellInfo);
4178 info->expand = expand;
4179 info->pack = GTK_PACK_START;
4181 priv->cells = g_slist_append (priv->cells, info);
4183 if (priv->cell_view)
4185 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (priv->cell_view),
4191 gtk_tree_view_column_pack_start (priv->column, cell, expand);
4193 if (GTK_IS_MENU (priv->popup_widget))
4194 pack_start_recurse (priv->popup_widget, cell, expand);
4198 pack_end_recurse (GtkWidget *menu,
4199 GtkCellRenderer *cell,
4206 list = gtk_container_get_children (GTK_CONTAINER (menu));
4207 for (i = list; i; i = i->next)
4209 child = gtk_bin_get_child (GTK_BIN (i->data));
4210 if (GTK_IS_CELL_LAYOUT (child))
4211 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (child),
4214 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4215 if (submenu != NULL)
4216 pack_end_recurse (submenu, cell, expand);
4223 gtk_combo_box_cell_layout_pack_end (GtkCellLayout *layout,
4224 GtkCellRenderer *cell,
4227 GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
4228 ComboCellInfo *info;
4229 GtkComboBoxPrivate *priv;
4231 priv = combo_box->priv;
4233 g_object_ref_sink (cell);
4235 info = g_slice_new0 (ComboCellInfo);
4237 info->expand = expand;
4238 info->pack = GTK_PACK_END;
4240 priv->cells = g_slist_append (priv->cells, info);
4242 if (priv->cell_view)
4243 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (priv->cell_view),
4247 gtk_tree_view_column_pack_end (priv->column, cell, expand);
4249 if (GTK_IS_MENU (priv->popup_widget))
4250 pack_end_recurse (priv->popup_widget, cell, expand);
4254 gtk_combo_box_cell_layout_get_cells (GtkCellLayout *layout)
4256 GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
4258 GList *retval = NULL;
4260 for (list = combo_box->priv->cells; list; list = list->next)
4262 ComboCellInfo *info = (ComboCellInfo *)list->data;
4264 retval = g_list_prepend (retval, info->cell);
4267 return g_list_reverse (retval);
4271 clear_recurse (GtkWidget *menu)
4277 list = gtk_container_get_children (GTK_CONTAINER (menu));
4278 for (i = list; i; i = i->next)
4280 child = gtk_bin_get_child (GTK_BIN (i->data));
4281 if (GTK_IS_CELL_LAYOUT (child))
4282 gtk_cell_layout_clear (GTK_CELL_LAYOUT (child));
4284 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4285 if (submenu != NULL)
4286 clear_recurse (submenu);
4293 gtk_combo_box_cell_layout_clear (GtkCellLayout *layout)
4295 GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
4296 GtkComboBoxPrivate *priv = combo_box->priv;
4299 if (priv->cell_view)
4300 gtk_cell_layout_clear (GTK_CELL_LAYOUT (priv->cell_view));
4303 gtk_tree_view_column_clear (priv->column);
4305 for (i = priv->cells; i; i = i->next)
4307 ComboCellInfo *info = (ComboCellInfo *)i->data;
4309 gtk_combo_box_cell_layout_clear_attributes (layout, info->cell);
4310 g_object_unref (info->cell);
4311 g_slice_free (ComboCellInfo, info);
4314 g_slist_free (priv->cells);
4317 if (GTK_IS_MENU (priv->popup_widget))
4318 clear_recurse (priv->popup_widget);
4322 add_attribute_recurse (GtkWidget *menu,
4323 GtkCellRenderer *cell,
4324 const gchar *attribute,
4331 list = gtk_container_get_children (GTK_CONTAINER (menu));
4332 for (i = list; i; i = i->next)
4334 child = gtk_bin_get_child (GTK_BIN (i->data));
4335 if (GTK_IS_CELL_LAYOUT (child))
4336 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (child),
4337 cell, attribute, column);
4339 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4340 if (submenu != NULL)
4341 add_attribute_recurse (submenu, cell, attribute, column);
4348 gtk_combo_box_cell_layout_add_attribute (GtkCellLayout *layout,
4349 GtkCellRenderer *cell,
4350 const gchar *attribute,
4353 GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
4354 ComboCellInfo *info;
4356 info = gtk_combo_box_get_cell_info (combo_box, cell);
4357 g_return_if_fail (info != NULL);
4359 info->attributes = g_slist_prepend (info->attributes,
4360 GINT_TO_POINTER (column));
4361 info->attributes = g_slist_prepend (info->attributes,
4362 g_strdup (attribute));
4364 if (combo_box->priv->cell_view)
4365 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo_box->priv->cell_view),
4366 cell, attribute, column);
4368 if (combo_box->priv->column)
4369 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo_box->priv->column),
4370 cell, attribute, column);
4372 if (GTK_IS_MENU (combo_box->priv->popup_widget))
4373 add_attribute_recurse (combo_box->priv->popup_widget, cell, attribute, column);
4374 gtk_widget_queue_resize (GTK_WIDGET (combo_box));
4378 combo_cell_data_func (GtkCellLayout *cell_layout,
4379 GtkCellRenderer *cell,
4380 GtkTreeModel *tree_model,
4384 ComboCellInfo *info = (ComboCellInfo *)data;
4385 GtkWidget *parent = NULL;
4390 info->func (cell_layout, cell, tree_model, iter, info->func_data);
4392 if (GTK_IS_WIDGET (cell_layout))
4393 parent = gtk_widget_get_parent (GTK_WIDGET (cell_layout));
4395 if (GTK_IS_MENU_ITEM (parent) &&
4396 gtk_menu_item_get_submenu (GTK_MENU_ITEM (parent)))
4397 g_object_set (cell, "sensitive", TRUE, NULL);
4402 set_cell_data_func_recurse (GtkWidget *menu,
4403 GtkCellRenderer *cell,
4404 ComboCellInfo *info)
4408 GtkWidget *cell_view;
4410 list = gtk_container_get_children (GTK_CONTAINER (menu));
4411 for (i = list; i; i = i->next)
4413 cell_view = gtk_bin_get_child (GTK_BIN (i->data));
4414 if (GTK_IS_CELL_LAYOUT (cell_view))
4416 /* Override sensitivity for inner nodes; we don't
4417 * want menuitems with submenus to appear insensitive
4419 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (cell_view),
4421 combo_cell_data_func,
4423 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4424 if (submenu != NULL)
4425 set_cell_data_func_recurse (submenu, cell, info);
4433 gtk_combo_box_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4434 GtkCellRenderer *cell,
4435 GtkCellLayoutDataFunc func,
4437 GDestroyNotify destroy)
4439 GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
4440 GtkComboBoxPrivate *priv = combo_box->priv;
4441 ComboCellInfo *info;
4443 info = gtk_combo_box_get_cell_info (combo_box, cell);
4444 g_return_if_fail (info != NULL);
4448 GDestroyNotify d = info->destroy;
4450 info->destroy = NULL;
4451 d (info->func_data);
4455 info->func_data = func_data;
4456 info->destroy = destroy;
4458 if (priv->cell_view)
4459 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (priv->cell_view), cell, func, func_data, NULL);
4462 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (priv->column), cell, func, func_data, NULL);
4464 if (GTK_IS_MENU (priv->popup_widget))
4465 set_cell_data_func_recurse (priv->popup_widget, cell, info);
4467 gtk_widget_queue_resize (GTK_WIDGET (combo_box));
4471 clear_attributes_recurse (GtkWidget *menu,
4472 GtkCellRenderer *cell)
4478 list = gtk_container_get_children (GTK_CONTAINER (menu));
4479 for (i = list; i; i = i->next)
4481 child = gtk_bin_get_child (GTK_BIN (i->data));
4482 if (GTK_IS_CELL_LAYOUT (child))
4483 gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (child), cell);
4485 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4486 if (submenu != NULL)
4487 clear_attributes_recurse (submenu, cell);
4494 gtk_combo_box_cell_layout_clear_attributes (GtkCellLayout *layout,
4495 GtkCellRenderer *cell)
4497 GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
4498 GtkComboBoxPrivate *priv;
4499 ComboCellInfo *info;
4502 priv = combo_box->priv;
4504 info = gtk_combo_box_get_cell_info (combo_box, cell);
4505 g_return_if_fail (info != NULL);
4507 list = info->attributes;
4508 while (list && list->next)
4510 g_free (list->data);
4511 list = list->next->next;
4513 g_slist_free (info->attributes);
4514 info->attributes = NULL;
4516 if (priv->cell_view)
4517 gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (priv->cell_view), cell);
4520 gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (priv->column), cell);
4522 if (GTK_IS_MENU (priv->popup_widget))
4523 clear_attributes_recurse (priv->popup_widget, cell);
4525 gtk_widget_queue_resize (GTK_WIDGET (combo_box));
4529 reorder_recurse (GtkWidget *menu,
4530 GtkCellRenderer *cell,
4537 list = gtk_container_get_children (GTK_CONTAINER (menu));
4538 for (i = list; i; i = i->next)
4540 child = gtk_bin_get_child (GTK_BIN (i->data));
4541 if (GTK_IS_CELL_LAYOUT (child))
4542 gtk_cell_layout_reorder (GTK_CELL_LAYOUT (child),
4545 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4546 if (submenu != NULL)
4547 reorder_recurse (submenu, cell, position);
4554 gtk_combo_box_cell_layout_reorder (GtkCellLayout *layout,
4555 GtkCellRenderer *cell,
4558 GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
4559 GtkComboBoxPrivate *priv;
4560 ComboCellInfo *info;
4563 priv = combo_box->priv;
4565 info = gtk_combo_box_get_cell_info (combo_box, cell);
4567 g_return_if_fail (info != NULL);
4568 g_return_if_fail (position >= 0);
4570 link = g_slist_find (priv->cells, info);
4572 g_return_if_fail (link != NULL);
4574 priv->cells = g_slist_delete_link (priv->cells, link);
4575 priv->cells = g_slist_insert (priv->cells, info, position);
4577 if (priv->cell_view)
4578 gtk_cell_layout_reorder (GTK_CELL_LAYOUT (priv->cell_view),
4582 gtk_cell_layout_reorder (GTK_CELL_LAYOUT (priv->column),
4585 if (GTK_IS_MENU (priv->popup_widget))
4586 reorder_recurse (priv->popup_widget, cell, position);
4588 gtk_widget_queue_draw (GTK_WIDGET (combo_box));
4596 * gtk_combo_box_new:
4598 * Creates a new empty #GtkComboBox.
4600 * Return value: A new #GtkComboBox.
4605 gtk_combo_box_new (void)
4607 return g_object_new (GTK_TYPE_COMBO_BOX, NULL);
4611 * gtk_combo_box_new_with_model:
4612 * @model: A #GtkTreeModel.
4614 * Creates a new #GtkComboBox with the model initialized to @model.
4616 * Return value: A new #GtkComboBox.
4621 gtk_combo_box_new_with_model (GtkTreeModel *model)
4623 GtkComboBox *combo_box;
4625 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
4627 combo_box = g_object_new (GTK_TYPE_COMBO_BOX, "model", model, NULL);
4629 return GTK_WIDGET (combo_box);
4633 * gtk_combo_box_get_wrap_width:
4634 * @combo_box: A #GtkComboBox
4636 * Returns the wrap width which is used to determine the number of columns
4637 * for the popup menu. If the wrap width is larger than 1, the combo box
4640 * Returns: the wrap width.
4645 gtk_combo_box_get_wrap_width (GtkComboBox *combo_box)
4647 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), -1);
4649 return combo_box->priv->wrap_width;
4653 * gtk_combo_box_set_wrap_width:
4654 * @combo_box: A #GtkComboBox
4655 * @width: Preferred number of columns
4657 * Sets the wrap width of @combo_box to be @width. The wrap width is basically
4658 * the preferred number of columns when you want the popup to be layed out
4664 gtk_combo_box_set_wrap_width (GtkComboBox *combo_box,
4667 GtkComboBoxPrivate *priv;
4669 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4670 g_return_if_fail (width >= 0);
4672 priv = combo_box->priv;
4674 if (width != priv->wrap_width)
4676 priv->wrap_width = width;
4678 gtk_combo_box_check_appearance (combo_box);
4679 gtk_combo_box_relayout (combo_box);
4681 g_object_notify (G_OBJECT (combo_box), "wrap-width");
4686 * gtk_combo_box_get_row_span_column:
4687 * @combo_box: A #GtkComboBox
4689 * Returns the column with row span information for @combo_box.
4691 * Returns: the row span column.
4696 gtk_combo_box_get_row_span_column (GtkComboBox *combo_box)
4698 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), -1);
4700 return combo_box->priv->row_column;
4704 * gtk_combo_box_set_row_span_column:
4705 * @combo_box: A #GtkComboBox.
4706 * @row_span: A column in the model passed during construction.
4708 * Sets the column with row span information for @combo_box to be @row_span.
4709 * The row span column contains integers which indicate how many rows
4710 * an item should span.
4715 gtk_combo_box_set_row_span_column (GtkComboBox *combo_box,
4718 GtkComboBoxPrivate *priv;
4721 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4723 priv = combo_box->priv;
4725 col = gtk_tree_model_get_n_columns (priv->model);
4726 g_return_if_fail (row_span >= -1 && row_span < col);
4728 if (row_span != priv->row_column)
4730 priv->row_column = row_span;
4732 gtk_combo_box_relayout (combo_box);
4734 g_object_notify (G_OBJECT (combo_box), "row-span-column");
4739 * gtk_combo_box_get_column_span_column:
4740 * @combo_box: A #GtkComboBox
4742 * Returns the column with column span information for @combo_box.
4744 * Returns: the column span column.
4749 gtk_combo_box_get_column_span_column (GtkComboBox *combo_box)
4751 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), -1);
4753 return combo_box->priv->col_column;
4757 * gtk_combo_box_set_column_span_column:
4758 * @combo_box: A #GtkComboBox
4759 * @column_span: A column in the model passed during construction
4761 * Sets the column with column span information for @combo_box to be
4762 * @column_span. The column span column contains integers which indicate
4763 * how many columns an item should span.
4768 gtk_combo_box_set_column_span_column (GtkComboBox *combo_box,
4771 GtkComboBoxPrivate *priv;
4774 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4776 priv = combo_box->priv;
4778 col = gtk_tree_model_get_n_columns (priv->model);
4779 g_return_if_fail (column_span >= -1 && column_span < col);
4781 if (column_span != priv->col_column)
4783 priv->col_column = column_span;
4785 gtk_combo_box_relayout (combo_box);
4787 g_object_notify (G_OBJECT (combo_box), "column-span-column");
4792 * gtk_combo_box_get_active:
4793 * @combo_box: A #GtkComboBox
4795 * Returns the index of the currently active item, or -1 if there's no
4796 * active item. If the model is a non-flat treemodel, and the active item
4797 * is not an immediate child of the root of the tree, this function returns
4798 * <literal>gtk_tree_path_get_indices (path)[0]</literal>, where
4799 * <literal>path</literal> is the #GtkTreePath of the active item.
4801 * Return value: An integer which is the index of the currently active item,
4802 * or -1 if there's no active item.
4807 gtk_combo_box_get_active (GtkComboBox *combo_box)
4809 GtkComboBoxPrivate *priv;
4812 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), 0);
4814 priv = combo_box->priv;
4816 if (gtk_tree_row_reference_valid (priv->active_row))
4820 path = gtk_tree_row_reference_get_path (priv->active_row);
4821 result = gtk_tree_path_get_indices (path)[0];
4822 gtk_tree_path_free (path);
4831 * gtk_combo_box_set_active:
4832 * @combo_box: A #GtkComboBox
4833 * @index_: An index in the model passed during construction, or -1 to have
4836 * Sets the active item of @combo_box to be the item at @index.
4841 gtk_combo_box_set_active (GtkComboBox *combo_box,
4844 GtkTreePath *path = NULL;
4845 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4846 g_return_if_fail (index_ >= -1);
4848 if (combo_box->priv->model == NULL)
4850 /* Save index, in case the model is set after the index */
4851 combo_box->priv->active = index_;
4857 path = gtk_tree_path_new_from_indices (index_, -1);
4859 gtk_combo_box_set_active_internal (combo_box, path);
4862 gtk_tree_path_free (path);
4866 gtk_combo_box_set_active_internal (GtkComboBox *combo_box,
4869 GtkComboBoxPrivate *priv = combo_box->priv;
4870 GtkTreePath *active_path;
4873 /* Remember whether the initially active row is valid. */
4874 gboolean is_valid_row_reference = gtk_tree_row_reference_valid (priv->active_row);
4876 if (path && is_valid_row_reference)
4878 active_path = gtk_tree_row_reference_get_path (priv->active_row);
4879 path_cmp = gtk_tree_path_compare (path, active_path);
4880 gtk_tree_path_free (active_path);
4885 if (priv->active_row)
4887 gtk_tree_row_reference_free (priv->active_row);
4888 priv->active_row = NULL;
4893 if (priv->tree_view)
4894 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view)));
4897 GtkMenu *menu = GTK_MENU (priv->popup_widget);
4899 if (GTK_IS_MENU (menu))
4900 gtk_menu_set_active (menu, -1);
4903 if (priv->cell_view)
4904 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (priv->cell_view), NULL);
4907 * Do not emit a "changed" signal when an already invalid selection was
4908 * now set to invalid.
4910 if (!is_valid_row_reference)
4916 gtk_tree_row_reference_new (priv->model, path);
4918 if (priv->tree_view)
4920 gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->tree_view),
4923 else if (GTK_IS_MENU (priv->popup_widget))
4925 /* FIXME handle nested menus better */
4926 gtk_menu_set_active (GTK_MENU (priv->popup_widget),
4927 gtk_tree_path_get_indices (path)[0]);
4930 if (priv->cell_view)
4931 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (priv->cell_view),
4935 g_signal_emit (combo_box, combo_box_signals[CHANGED], 0);
4936 g_object_notify (G_OBJECT (combo_box), "active");
4941 * gtk_combo_box_get_active_iter:
4942 * @combo_box: A #GtkComboBox
4943 * @iter: (out): The uninitialized #GtkTreeIter
4945 * Sets @iter to point to the current active item, if it exists.
4947 * Return value: %TRUE, if @iter was set
4952 gtk_combo_box_get_active_iter (GtkComboBox *combo_box,
4958 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE);
4960 if (!gtk_tree_row_reference_valid (combo_box->priv->active_row))
4963 path = gtk_tree_row_reference_get_path (combo_box->priv->active_row);
4964 result = gtk_tree_model_get_iter (combo_box->priv->model, iter, path);
4965 gtk_tree_path_free (path);
4971 * gtk_combo_box_set_active_iter:
4972 * @combo_box: A #GtkComboBox
4973 * @iter: (allow-none): The #GtkTreeIter, or %NULL
4975 * Sets the current active item to be the one referenced by @iter, or
4976 * unsets the active item if @iter is %NULL.
4978 * @iter must correspond to a path of depth one, or be %NULL.
4983 gtk_combo_box_set_active_iter (GtkComboBox *combo_box,
4986 GtkTreePath *path = NULL;
4988 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4991 path = gtk_tree_model_get_path (gtk_combo_box_get_model (combo_box), iter);
4993 gtk_combo_box_set_active_internal (combo_box, path);
4994 gtk_tree_path_free (path);
4998 * gtk_combo_box_set_model:
4999 * @combo_box: A #GtkComboBox
5000 * @model: (allow-none): A #GtkTreeModel
5002 * Sets the model used by @combo_box to be @model. Will unset a previously set
5003 * model (if applicable). If model is %NULL, then it will unset the model.
5005 * Note that this function does not clear the cell renderers, you have to
5006 * call gtk_cell_layout_clear() yourself if you need to set up different
5007 * cell renderers for the new model.
5012 gtk_combo_box_set_model (GtkComboBox *combo_box,
5013 GtkTreeModel *model)
5015 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5016 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
5018 if (model == combo_box->priv->model)
5021 gtk_combo_box_unset_model (combo_box);
5026 combo_box->priv->model = model;
5027 g_object_ref (combo_box->priv->model);
5029 combo_box->priv->inserted_id =
5030 g_signal_connect (combo_box->priv->model, "row-inserted",
5031 G_CALLBACK (gtk_combo_box_model_row_inserted),
5033 combo_box->priv->deleted_id =
5034 g_signal_connect (combo_box->priv->model, "row-deleted",
5035 G_CALLBACK (gtk_combo_box_model_row_deleted),
5037 combo_box->priv->reordered_id =
5038 g_signal_connect (combo_box->priv->model, "rows-reordered",
5039 G_CALLBACK (gtk_combo_box_model_rows_reordered),
5041 combo_box->priv->changed_id =
5042 g_signal_connect (combo_box->priv->model, "row-changed",
5043 G_CALLBACK (gtk_combo_box_model_row_changed),
5046 if (combo_box->priv->tree_view)
5049 gtk_tree_view_set_model (GTK_TREE_VIEW (combo_box->priv->tree_view),
5050 combo_box->priv->model);
5051 gtk_combo_box_list_popup_resize (combo_box);
5056 if (combo_box->priv->popup_widget)
5057 gtk_combo_box_menu_fill (combo_box);
5061 if (combo_box->priv->cell_view)
5062 gtk_cell_view_set_model (GTK_CELL_VIEW (combo_box->priv->cell_view),
5063 combo_box->priv->model);
5065 if (combo_box->priv->active != -1)
5067 /* If an index was set in advance, apply it now */
5068 gtk_combo_box_set_active (combo_box, combo_box->priv->active);
5069 combo_box->priv->active = -1;
5073 gtk_combo_box_update_sensitivity (combo_box);
5075 g_object_notify (G_OBJECT (combo_box), "model");
5079 * gtk_combo_box_get_model
5080 * @combo_box: A #GtkComboBox
5082 * Returns the #GtkTreeModel which is acting as data source for @combo_box.
5084 * Return value: (transfer none): A #GtkTreeModel which was passed during construction.
5089 gtk_combo_box_get_model (GtkComboBox *combo_box)
5091 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
5093 return combo_box->priv->model;
5097 /* convenience API for simple text combos */
5100 * gtk_combo_box_new_text:
5102 * Convenience function which constructs a new text combo box, which is a
5103 * #GtkComboBox just displaying strings. If you use this function to create
5104 * a text combo box, you should only manipulate its data source with the
5105 * following convenience functions: gtk_combo_box_append_text(),
5106 * gtk_combo_box_insert_text(), gtk_combo_box_prepend_text() and
5107 * gtk_combo_box_remove_text().
5109 * Return value: (transfer none): A new text combo box.
5114 gtk_combo_box_new_text (void)
5116 GtkWidget *combo_box;
5117 GtkCellRenderer *cell;
5118 GtkListStore *store;
5120 store = gtk_list_store_new (1, G_TYPE_STRING);
5121 combo_box = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));
5122 g_object_unref (store);
5124 cell = gtk_cell_renderer_text_new ();
5125 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), cell, TRUE);
5126 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), cell,
5134 * gtk_combo_box_append_text:
5135 * @combo_box: A #GtkComboBox constructed using gtk_combo_box_new_text()
5138 * Appends @string to the list of strings stored in @combo_box. Note that
5139 * you can only use this function with combo boxes constructed with
5140 * gtk_combo_box_new_text().
5145 gtk_combo_box_append_text (GtkComboBox *combo_box,
5149 GtkListStore *store;
5151 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5152 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
5153 g_return_if_fail (gtk_tree_model_get_column_type (combo_box->priv->model, 0)
5155 g_return_if_fail (text != NULL);
5157 store = GTK_LIST_STORE (combo_box->priv->model);
5159 gtk_list_store_append (store, &iter);
5160 gtk_list_store_set (store, &iter, 0, text, -1);
5164 * gtk_combo_box_insert_text:
5165 * @combo_box: A #GtkComboBox constructed using gtk_combo_box_new_text()
5166 * @position: An index to insert @text
5169 * Inserts @string at @position in the list of strings stored in @combo_box.
5170 * Note that you can only use this function with combo boxes constructed
5171 * with gtk_combo_box_new_text().
5176 gtk_combo_box_insert_text (GtkComboBox *combo_box,
5181 GtkListStore *store;
5183 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5184 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
5185 g_return_if_fail (position >= 0);
5186 g_return_if_fail (gtk_tree_model_get_column_type (combo_box->priv->model, 0)
5188 g_return_if_fail (text != NULL);
5190 store = GTK_LIST_STORE (combo_box->priv->model);
5192 gtk_list_store_insert (store, &iter, position);
5193 gtk_list_store_set (store, &iter, 0, text, -1);
5197 * gtk_combo_box_prepend_text:
5198 * @combo_box: A #GtkComboBox constructed with gtk_combo_box_new_text()
5201 * Prepends @string to the list of strings stored in @combo_box. Note that
5202 * you can only use this function with combo boxes constructed with
5203 * gtk_combo_box_new_text().
5208 gtk_combo_box_prepend_text (GtkComboBox *combo_box,
5212 GtkListStore *store;
5214 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5215 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
5216 g_return_if_fail (gtk_tree_model_get_column_type (combo_box->priv->model, 0)
5218 g_return_if_fail (text != NULL);
5220 store = GTK_LIST_STORE (combo_box->priv->model);
5222 gtk_list_store_prepend (store, &iter);
5223 gtk_list_store_set (store, &iter, 0, text, -1);
5227 * gtk_combo_box_remove_text:
5228 * @combo_box: A #GtkComboBox constructed with gtk_combo_box_new_text()
5229 * @position: Index of the item to remove
5231 * Removes the string at @position from @combo_box. Note that you can only use
5232 * this function with combo boxes constructed with gtk_combo_box_new_text().
5237 gtk_combo_box_remove_text (GtkComboBox *combo_box,
5241 GtkListStore *store;
5243 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5244 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
5245 g_return_if_fail (gtk_tree_model_get_column_type (combo_box->priv->model, 0)
5247 g_return_if_fail (position >= 0);
5249 store = GTK_LIST_STORE (combo_box->priv->model);
5251 if (gtk_tree_model_iter_nth_child (combo_box->priv->model, &iter,
5253 gtk_list_store_remove (store, &iter);
5257 * gtk_combo_box_get_active_text:
5258 * @combo_box: A #GtkComboBox constructed with gtk_combo_box_new_text()
5260 * Returns the currently active string in @combo_box or %NULL if none
5261 * is selected. Note that you can only use this function with combo
5262 * boxes constructed with gtk_combo_box_new_text() and with
5263 * #GtkComboBoxEntry<!-- -->s.
5265 * Returns: a newly allocated string containing the currently active text.
5266 * Must be freed with g_free().
5271 gtk_combo_box_get_active_text (GtkComboBox *combo_box)
5273 GtkComboBoxClass *class;
5275 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
5277 class = GTK_COMBO_BOX_GET_CLASS (combo_box);
5279 if (class->get_active_text)
5280 return class->get_active_text (combo_box);
5286 gtk_combo_box_real_get_active_text (GtkComboBox *combo_box)
5291 g_return_val_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model), NULL);
5292 g_return_val_if_fail (gtk_tree_model_get_column_type (combo_box->priv->model, 0)
5293 == G_TYPE_STRING, NULL);
5295 if (gtk_combo_box_get_active_iter (combo_box, &iter))
5296 gtk_tree_model_get (combo_box->priv->model, &iter,
5303 gtk_combo_box_real_move_active (GtkComboBox *combo_box,
5304 GtkScrollType scroll)
5307 GtkTreeIter new_iter;
5308 gboolean active_iter;
5311 if (!combo_box->priv->model)
5313 gtk_widget_error_bell (GTK_WIDGET (combo_box));
5317 active_iter = gtk_combo_box_get_active_iter (combo_box, &iter);
5321 case GTK_SCROLL_STEP_BACKWARD:
5322 case GTK_SCROLL_STEP_UP:
5323 case GTK_SCROLL_STEP_LEFT:
5326 found = tree_prev (combo_box, combo_box->priv->model,
5327 &iter, &new_iter, FALSE);
5330 /* else fall through */
5332 case GTK_SCROLL_PAGE_FORWARD:
5333 case GTK_SCROLL_PAGE_DOWN:
5334 case GTK_SCROLL_PAGE_RIGHT:
5335 case GTK_SCROLL_END:
5336 found = tree_last (combo_box, combo_box->priv->model, &new_iter, FALSE);
5339 case GTK_SCROLL_STEP_FORWARD:
5340 case GTK_SCROLL_STEP_DOWN:
5341 case GTK_SCROLL_STEP_RIGHT:
5344 found = tree_next (combo_box, combo_box->priv->model,
5345 &iter, &new_iter, FALSE);
5348 /* else fall through */
5350 case GTK_SCROLL_PAGE_BACKWARD:
5351 case GTK_SCROLL_PAGE_UP:
5352 case GTK_SCROLL_PAGE_LEFT:
5353 case GTK_SCROLL_START:
5354 found = tree_first (combo_box, combo_box->priv->model, &new_iter, FALSE);
5361 if (found && active_iter)
5363 GtkTreePath *old_path;
5364 GtkTreePath *new_path;
5366 old_path = gtk_tree_model_get_path (combo_box->priv->model, &iter);
5367 new_path = gtk_tree_model_get_path (combo_box->priv->model, &new_iter);
5369 if (gtk_tree_path_compare (old_path, new_path) == 0)
5372 gtk_tree_path_free (old_path);
5373 gtk_tree_path_free (new_path);
5378 gtk_combo_box_set_active_iter (combo_box, &new_iter);
5382 gtk_widget_error_bell (GTK_WIDGET (combo_box));
5387 gtk_combo_box_mnemonic_activate (GtkWidget *widget,
5388 gboolean group_cycling)
5390 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
5392 gtk_widget_grab_focus (combo_box->priv->button);
5398 gtk_combo_box_grab_focus (GtkWidget *widget)
5400 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
5402 gtk_widget_grab_focus (combo_box->priv->button);
5406 gtk_combo_box_destroy (GtkObject *object)
5408 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
5410 if (combo_box->priv->popup_idle_id > 0)
5412 g_source_remove (combo_box->priv->popup_idle_id);
5413 combo_box->priv->popup_idle_id = 0;
5416 gtk_combo_box_popdown (combo_box);
5418 if (combo_box->priv->row_separator_destroy)
5419 combo_box->priv->row_separator_destroy (combo_box->priv->row_separator_data);
5421 combo_box->priv->row_separator_func = NULL;
5422 combo_box->priv->row_separator_data = NULL;
5423 combo_box->priv->row_separator_destroy = NULL;
5425 GTK_OBJECT_CLASS (gtk_combo_box_parent_class)->destroy (object);
5426 combo_box->priv->cell_view = NULL;
5430 gtk_combo_box_dispose(GObject* object)
5432 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
5434 if (GTK_IS_MENU (combo_box->priv->popup_widget))
5436 gtk_combo_box_menu_destroy (combo_box);
5437 gtk_menu_detach (GTK_MENU (combo_box->priv->popup_widget));
5438 combo_box->priv->popup_widget = NULL;
5441 G_OBJECT_CLASS (gtk_combo_box_parent_class)->dispose (object);
5445 gtk_combo_box_finalize (GObject *object)
5447 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
5450 if (GTK_IS_TREE_VIEW (combo_box->priv->tree_view))
5451 gtk_combo_box_list_destroy (combo_box);
5453 if (combo_box->priv->popup_window)
5454 gtk_widget_destroy (combo_box->priv->popup_window);
5456 gtk_combo_box_unset_model (combo_box);
5458 for (i = combo_box->priv->cells; i; i = i->next)
5460 ComboCellInfo *info = (ComboCellInfo *)i->data;
5461 GSList *list = info->attributes;
5464 info->destroy (info->func_data);
5466 while (list && list->next)
5468 g_free (list->data);
5469 list = list->next->next;
5471 g_slist_free (info->attributes);
5473 g_object_unref (info->cell);
5474 g_slice_free (ComboCellInfo, info);
5476 g_slist_free (combo_box->priv->cells);
5478 g_free (combo_box->priv->tearoff_title);
5480 G_OBJECT_CLASS (gtk_combo_box_parent_class)->finalize (object);
5484 gtk_cell_editable_key_press (GtkWidget *widget,
5488 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
5490 if (event->keyval == GDK_Escape)
5492 g_object_set (combo_box,
5493 "editing-canceled", TRUE,
5495 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (combo_box));
5496 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (combo_box));
5500 else if (event->keyval == GDK_Return ||
5501 event->keyval == GDK_ISO_Enter ||
5502 event->keyval == GDK_KP_Enter)
5504 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (combo_box));
5505 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (combo_box));
5514 popdown_idle (gpointer data)
5516 GtkComboBox *combo_box;
5518 combo_box = GTK_COMBO_BOX (data);
5520 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (combo_box));
5521 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (combo_box));
5523 g_object_unref (combo_box);
5529 popdown_handler (GtkWidget *widget,
5532 gdk_threads_add_idle (popdown_idle, g_object_ref (data));
5536 popup_idle (gpointer data)
5538 GtkComboBox *combo_box;
5540 combo_box = GTK_COMBO_BOX (data);
5542 if (GTK_IS_MENU (combo_box->priv->popup_widget) &&
5543 combo_box->priv->cell_view)
5544 g_signal_connect_object (combo_box->priv->popup_widget,
5545 "unmap", G_CALLBACK (popdown_handler),
5548 /* we unset this if a menu item is activated */
5549 g_object_set (combo_box,
5550 "editing-canceled", TRUE,
5552 gtk_combo_box_popup (combo_box);
5554 combo_box->priv->popup_idle_id = 0;
5555 combo_box->priv->activate_button = 0;
5556 combo_box->priv->activate_time = 0;
5562 gtk_combo_box_start_editing (GtkCellEditable *cell_editable,
5565 GtkComboBox *combo_box = GTK_COMBO_BOX (cell_editable);
5568 combo_box->priv->is_cell_renderer = TRUE;
5570 if (combo_box->priv->cell_view)
5572 g_signal_connect_object (combo_box->priv->button, "key-press-event",
5573 G_CALLBACK (gtk_cell_editable_key_press),
5576 gtk_widget_grab_focus (combo_box->priv->button);
5580 child = gtk_bin_get_child (GTK_BIN (combo_box));
5582 g_signal_connect_object (child, "key-press-event",
5583 G_CALLBACK (gtk_cell_editable_key_press),
5586 gtk_widget_grab_focus (child);
5587 gtk_widget_set_can_focus (combo_box->priv->button, FALSE);
5590 /* we do the immediate popup only for the optionmenu-like
5593 if (combo_box->priv->is_cell_renderer &&
5594 combo_box->priv->cell_view && !combo_box->priv->tree_view)
5596 if (event && event->type == GDK_BUTTON_PRESS)
5598 GdkEventButton *event_button = (GdkEventButton *)event;
5600 combo_box->priv->activate_button = event_button->button;
5601 combo_box->priv->activate_time = event_button->time;
5604 combo_box->priv->popup_idle_id =
5605 gdk_threads_add_idle (popup_idle, combo_box);
5611 * gtk_combo_box_get_add_tearoffs:
5612 * @combo_box: a #GtkComboBox
5614 * Gets the current value of the :add-tearoffs property.
5616 * Return value: the current value of the :add-tearoffs property.
5619 gtk_combo_box_get_add_tearoffs (GtkComboBox *combo_box)
5621 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE);
5623 return combo_box->priv->add_tearoffs;
5627 * gtk_combo_box_set_add_tearoffs:
5628 * @combo_box: a #GtkComboBox
5629 * @add_tearoffs: %TRUE to add tearoff menu items
5631 * Sets whether the popup menu should have a tearoff
5637 gtk_combo_box_set_add_tearoffs (GtkComboBox *combo_box,
5638 gboolean add_tearoffs)
5640 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5642 add_tearoffs = add_tearoffs != FALSE;
5644 if (combo_box->priv->add_tearoffs != add_tearoffs)
5646 combo_box->priv->add_tearoffs = add_tearoffs;
5647 gtk_combo_box_check_appearance (combo_box);
5648 gtk_combo_box_relayout (combo_box);
5649 g_object_notify (G_OBJECT (combo_box), "add-tearoffs");
5654 * gtk_combo_box_get_title:
5655 * @combo_box: a #GtkComboBox
5657 * Gets the current title of the menu in tearoff mode. See
5658 * gtk_combo_box_set_add_tearoffs().
5660 * Returns: the menu's title in tearoff mode. This is an internal copy of the
5661 * string which must not be freed.
5665 G_CONST_RETURN gchar*
5666 gtk_combo_box_get_title (GtkComboBox *combo_box)
5668 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
5670 return combo_box->priv->tearoff_title;
5674 gtk_combo_box_update_title (GtkComboBox *combo_box)
5676 gtk_combo_box_check_appearance (combo_box);
5678 if (combo_box->priv->popup_widget &&
5679 GTK_IS_MENU (combo_box->priv->popup_widget))
5680 gtk_menu_set_title (GTK_MENU (combo_box->priv->popup_widget),
5681 combo_box->priv->tearoff_title);
5685 * gtk_combo_box_set_title:
5686 * @combo_box: a #GtkComboBox
5687 * @title: a title for the menu in tearoff mode
5689 * Sets the menu's title in tearoff mode.
5694 gtk_combo_box_set_title (GtkComboBox *combo_box,
5697 GtkComboBoxPrivate *priv;
5699 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5701 priv = combo_box->priv;
5703 if (strcmp (title ? title : "",
5704 priv->tearoff_title ? priv->tearoff_title : "") != 0)
5706 g_free (priv->tearoff_title);
5707 priv->tearoff_title = g_strdup (title);
5709 gtk_combo_box_update_title (combo_box);
5711 g_object_notify (G_OBJECT (combo_box), "tearoff-title");
5716 * gtk_combo_box_get_popup_accessible:
5717 * @combo_box: a #GtkComboBox
5719 * Gets the accessible object corresponding to the combo box's popup.
5721 * This function is mostly intended for use by accessibility technologies;
5722 * applications should have little use for it.
5724 * Returns: the accessible object corresponding to the combo box's popup.
5729 gtk_combo_box_get_popup_accessible (GtkComboBox *combo_box)
5733 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
5735 if (combo_box->priv->popup_widget)
5737 atk_obj = gtk_widget_get_accessible (combo_box->priv->popup_widget);
5745 * gtk_combo_box_get_row_separator_func:
5746 * @combo_box: a #GtkComboBox
5748 * Returns the current row separator function.
5750 * Return value: the current row separator function.
5754 GtkTreeViewRowSeparatorFunc
5755 gtk_combo_box_get_row_separator_func (GtkComboBox *combo_box)
5757 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
5759 return combo_box->priv->row_separator_func;
5763 * gtk_combo_box_set_row_separator_func:
5764 * @combo_box: a #GtkComboBox
5765 * @func: a #GtkTreeViewRowSeparatorFunc
5766 * @data: (allow-none): user data to pass to @func, or %NULL
5767 * @destroy: (allow-none): destroy notifier for @data, or %NULL
5769 * Sets the row separator function, which is used to determine
5770 * whether a row should be drawn as a separator. If the row separator
5771 * function is %NULL, no separators are drawn. This is the default value.
5776 gtk_combo_box_set_row_separator_func (GtkComboBox *combo_box,
5777 GtkTreeViewRowSeparatorFunc func,
5779 GDestroyNotify destroy)
5781 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5783 if (combo_box->priv->row_separator_destroy)
5784 combo_box->priv->row_separator_destroy (combo_box->priv->row_separator_data);
5786 combo_box->priv->row_separator_func = func;
5787 combo_box->priv->row_separator_data = data;
5788 combo_box->priv->row_separator_destroy = destroy;
5790 if (combo_box->priv->tree_view)
5791 gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (combo_box->priv->tree_view),
5794 gtk_combo_box_relayout (combo_box);
5796 gtk_widget_queue_draw (GTK_WIDGET (combo_box));
5800 * gtk_combo_box_set_button_sensitivity:
5801 * @combo_box: a #GtkComboBox
5802 * @sensitivity: specify the sensitivity of the dropdown button
5804 * Sets whether the dropdown button of the combo box should be
5805 * always sensitive (%GTK_SENSITIVITY_ON), never sensitive (%GTK_SENSITIVITY_OFF)
5806 * or only if there is at least one item to display (%GTK_SENSITIVITY_AUTO).
5811 gtk_combo_box_set_button_sensitivity (GtkComboBox *combo_box,
5812 GtkSensitivityType sensitivity)
5814 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5816 if (combo_box->priv->button_sensitivity != sensitivity)
5818 combo_box->priv->button_sensitivity = sensitivity;
5819 gtk_combo_box_update_sensitivity (combo_box);
5821 g_object_notify (G_OBJECT (combo_box), "button-sensitivity");
5826 * gtk_combo_box_get_button_sensitivity:
5827 * @combo_box: a #GtkComboBox
5829 * Returns whether the combo box sets the dropdown button
5830 * sensitive or not when there are no items in the model.
5832 * Return Value: %GTK_SENSITIVITY_ON if the dropdown button
5833 * is sensitive when the model is empty, %GTK_SENSITIVITY_OFF
5834 * if the button is always insensitive or
5835 * %GTK_SENSITIVITY_AUTO if it is only sensitive as long as
5836 * the model has one item to be selected.
5841 gtk_combo_box_get_button_sensitivity (GtkComboBox *combo_box)
5843 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE);
5845 return combo_box->priv->button_sensitivity;
5850 * gtk_combo_box_set_focus_on_click:
5851 * @combo: a #GtkComboBox
5852 * @focus_on_click: whether the combo box grabs focus when clicked
5855 * Sets whether the combo box will grab focus when it is clicked with
5856 * the mouse. Making mouse clicks not grab focus is useful in places
5857 * like toolbars where you don't want the keyboard focus removed from
5858 * the main area of the application.
5863 gtk_combo_box_set_focus_on_click (GtkComboBox *combo_box,
5864 gboolean focus_on_click)
5866 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5868 focus_on_click = focus_on_click != FALSE;
5870 if (combo_box->priv->focus_on_click != focus_on_click)
5872 combo_box->priv->focus_on_click = focus_on_click;
5874 if (combo_box->priv->button)
5875 gtk_button_set_focus_on_click (GTK_BUTTON (combo_box->priv->button),
5878 g_object_notify (G_OBJECT (combo_box), "focus-on-click");
5883 * gtk_combo_box_get_focus_on_click:
5884 * @combo: a #GtkComboBox
5886 * Returns whether the combo box grabs focus when it is clicked
5887 * with the mouse. See gtk_combo_box_set_focus_on_click().
5889 * Return value: %TRUE if the combo box grabs focus when it is
5890 * clicked with the mouse.
5895 gtk_combo_box_get_focus_on_click (GtkComboBox *combo_box)
5897 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE);
5899 return combo_box->priv->focus_on_click;
5904 gtk_combo_box_buildable_custom_tag_start (GtkBuildable *buildable,
5905 GtkBuilder *builder,
5907 const gchar *tagname,
5908 GMarkupParser *parser,
5911 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
5912 tagname, parser, data))
5915 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
5916 tagname, parser, data);
5920 gtk_combo_box_buildable_custom_tag_end (GtkBuildable *buildable,
5921 GtkBuilder *builder,
5923 const gchar *tagname,
5926 if (strcmp (tagname, "attributes") == 0)
5927 _gtk_cell_layout_buildable_custom_tag_end (buildable, builder, child, tagname,
5930 parent_buildable_iface->custom_tag_end (buildable, builder, child, tagname,
5936 gtk_combo_box_size_request_init (GtkSizeRequestIface *iface)
5938 iface->get_width = gtk_combo_box_get_width;
5939 iface->get_height = gtk_combo_box_get_height;
5940 iface->get_height_for_width = gtk_combo_box_get_height_for_width;
5941 iface->get_width_for_height = gtk_combo_box_get_width_for_height;
5945 gtk_combo_box_remeasure (GtkComboBox *combo_box)
5947 GtkComboBoxPrivate *priv = combo_box->priv;
5952 !gtk_tree_model_get_iter_first (priv->model, &iter))
5955 priv->minimum_width = priv->natural_width = 0;
5957 path = gtk_tree_path_new_from_indices (0, -1);
5961 gint row_min = 0, row_nat = 0;
5963 if (priv->cell_view)
5964 gtk_cell_view_get_desired_width_of_row (GTK_CELL_VIEW (priv->cell_view),
5965 path, &row_min, &row_nat);
5967 priv->minimum_width = MAX (priv->minimum_width, row_min);
5968 priv->natural_width = MAX (priv->natural_width, row_nat);
5970 gtk_tree_path_next (path);
5972 while (gtk_tree_model_iter_next (priv->model, &iter));
5974 gtk_tree_path_free (path);
5979 gtk_combo_box_measure_height_for_width (GtkComboBox *combo_box,
5985 GtkComboBoxPrivate *priv = combo_box->priv;
5988 gint child_min, child_nat;
5990 child = gtk_bin_get_child (GTK_BIN (combo_box));
5992 gtk_size_request_get_height_for_width (GTK_SIZE_REQUEST (child), avail_width,
5993 &child_min, &child_nat);
5996 !gtk_tree_model_get_iter_first (priv->model, &iter))
5999 path = gtk_tree_path_new_from_indices (0, -1);
6003 gint row_min = 0, row_nat = 0;
6005 if (priv->cell_view)
6006 gtk_cell_view_get_desired_height_for_width_of_row (GTK_CELL_VIEW (priv->cell_view),
6008 &row_min, &row_nat);
6010 child_min = MAX (child_min, row_min);
6011 child_nat = MAX (child_nat, row_nat);
6013 gtk_tree_path_next (path);
6015 while (gtk_tree_model_iter_next (priv->model, &iter));
6017 gtk_tree_path_free (path);
6022 *min_height = child_min;
6024 *nat_height = child_nat;
6029 gtk_combo_box_get_width (GtkSizeRequest *widget,
6033 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
6034 GtkComboBoxPrivate *priv = combo_box->priv;
6035 gint focus_width, focus_pad;
6036 gint font_size, arrow_size;
6037 PangoContext *context;
6038 PangoFontMetrics *metrics;
6039 PangoFontDescription *font_desc;
6041 gint minimum_width, natural_width;
6042 gint child_min, child_nat;
6044 child = gtk_bin_get_child (GTK_BIN (widget));
6047 gtk_size_request_get_width (GTK_SIZE_REQUEST (child), &child_min, &child_nat);
6048 gtk_combo_box_remeasure (combo_box);
6050 child_min = MAX (child_min, priv->minimum_width);
6051 child_nat = MAX (child_nat, priv->natural_width);
6053 gtk_widget_style_get (GTK_WIDGET (widget),
6054 "focus-line-width", &focus_width,
6055 "focus-padding", &focus_pad,
6056 "arrow-size", &arrow_size,
6059 font_desc = child->style->font_desc;
6060 context = gtk_widget_get_pango_context (GTK_WIDGET (widget));
6061 metrics = pango_context_get_metrics (context, font_desc,
6062 pango_context_get_language (context));
6063 font_size = PANGO_PIXELS (pango_font_metrics_get_ascent (metrics) +
6064 pango_font_metrics_get_descent (metrics));
6065 pango_font_metrics_unref (metrics);
6067 arrow_size = MAX (arrow_size, font_size);
6069 gtk_widget_set_size_request (priv->arrow, arrow_size, arrow_size);
6071 if (!priv->tree_view)
6075 if (priv->cell_view)
6077 gint sep_width, arrow_width;
6078 gint border_width, xthickness, xpad;
6080 border_width = gtk_container_get_border_width (GTK_CONTAINER (combo_box));
6081 xthickness = priv->button->style->xthickness;
6083 gtk_size_request_get_width (GTK_SIZE_REQUEST (priv->separator), &sep_width, NULL);
6084 gtk_size_request_get_width (GTK_SIZE_REQUEST (priv->arrow), &arrow_width, NULL);
6086 xpad = 2*(border_width + xthickness + focus_width + focus_pad);
6088 minimum_width = child_min + sep_width + arrow_width + xpad;
6089 natural_width = child_nat + sep_width + arrow_width + xpad;
6093 gint but_width, but_nat_width;
6095 gtk_size_request_get_width (GTK_SIZE_REQUEST (priv->button),
6096 &but_width, &but_nat_width);
6098 minimum_width = child_min + but_width;
6099 natural_width = child_nat + but_nat_width;
6105 gint button_width, button_nat_width;
6107 /* sample + frame */
6108 minimum_width = child_min;
6109 natural_width = child_nat;
6111 minimum_width += 2 * focus_width;
6112 natural_width += 2 * focus_width;
6114 if (priv->cell_view_frame)
6116 if (priv->has_frame)
6118 gint border_width = gtk_container_get_border_width (GTK_CONTAINER (priv->cell_view_frame));
6119 gint xpad = 2 * (border_width + GTK_WIDGET (priv->cell_view_frame)->style->xthickness);
6121 minimum_width += xpad;
6122 natural_width += xpad;
6127 gtk_size_request_get_width (GTK_SIZE_REQUEST (priv->button),
6128 &button_width, &button_nat_width);
6130 minimum_width += button_width;
6131 natural_width += button_nat_width;
6134 if (GTK_SHADOW_NONE != priv->shadow_type)
6136 minimum_width += 2 * GTK_WIDGET (widget)->style->xthickness;
6137 natural_width += 2 * GTK_WIDGET (widget)->style->xthickness;
6141 *minimum_size = minimum_width;
6144 *natural_size = natural_width;
6148 gtk_combo_box_get_height (GtkSizeRequest *widget,
6154 /* Combo box is height-for-width only
6155 * (so we always just reserve enough height for the minimum width) */
6156 gtk_size_request_get_width (widget, &min_width, NULL);
6157 gtk_size_request_get_height_for_width (widget, min_width, minimum_size, natural_size);
6161 gtk_combo_box_get_width_for_height (GtkSizeRequest *widget,
6166 /* Combo box is height-for-width only
6167 * (so we assume we always reserved enough height for the minimum width) */
6168 gtk_size_request_get_width (widget, minimum_size, natural_size);
6173 gtk_combo_box_get_height_for_width (GtkSizeRequest *widget,
6178 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
6179 GtkComboBoxPrivate *priv = combo_box->priv;
6180 gint focus_width, focus_pad;
6181 gint min_height, nat_height;
6184 gtk_widget_style_get (GTK_WIDGET (widget),
6185 "focus-line-width", &focus_width,
6186 "focus-padding", &focus_pad,
6191 if (GTK_SHADOW_NONE != priv->shadow_type)
6192 size -= GTK_WIDGET (widget)->style->xthickness;
6194 if (!priv->tree_view)
6197 if (priv->cell_view)
6199 /* calculate x/y padding and separator/arrow size */
6200 gint sep_width, arrow_width, sep_height, arrow_height;
6201 gint border_width, xthickness, ythickness, xpad, ypad;
6203 border_width = gtk_container_get_border_width (GTK_CONTAINER (combo_box));
6204 xthickness = priv->button->style->xthickness;
6205 ythickness = priv->button->style->ythickness;
6207 gtk_size_request_get_width (GTK_SIZE_REQUEST (priv->separator), &sep_width, NULL);
6208 gtk_size_request_get_width (GTK_SIZE_REQUEST (priv->arrow), &arrow_width, NULL);
6209 gtk_size_request_get_height_for_width (GTK_SIZE_REQUEST (priv->separator),
6210 sep_width, &sep_height, NULL);
6211 gtk_size_request_get_height_for_width (GTK_SIZE_REQUEST (priv->arrow),
6212 arrow_width, &arrow_height, NULL);
6214 xpad = 2*(border_width + xthickness + focus_width + focus_pad);
6215 ypad = 2*(border_width + ythickness + focus_width + focus_pad);
6217 size -= sep_width + arrow_width + xpad;
6219 gtk_combo_box_measure_height_for_width (combo_box, size, &min_height, &nat_height);
6221 arrow_height = MAX (arrow_height, sep_height);
6222 min_height = MAX (min_height, arrow_height);
6223 nat_height = MAX (nat_height, arrow_height);
6230 /* there is a custom child widget inside (no priv->cell_view) */
6231 gint but_width, but_height;
6233 gtk_size_request_get_width (GTK_SIZE_REQUEST (priv->button), &but_width, NULL);
6234 gtk_size_request_get_height_for_width (GTK_SIZE_REQUEST (priv->button),
6235 but_width, &but_height, NULL);
6239 gtk_combo_box_measure_height_for_width (combo_box, size, &min_height, &nat_height);
6241 min_height = MAX (min_height, but_height);
6242 nat_height = MAX (nat_height, but_height);
6248 gint but_width, but_height;
6249 gint xpad = 0, ypad = 0;
6251 gtk_size_request_get_width (GTK_SIZE_REQUEST (priv->button), &but_width, NULL);
6252 gtk_size_request_get_height_for_width (GTK_SIZE_REQUEST (priv->button),
6253 but_width, &but_height, NULL);
6255 if (priv->cell_view_frame && priv->has_frame)
6257 gint border_width = gtk_container_get_border_width (GTK_CONTAINER (priv->cell_view_frame));
6259 xpad = 2 * (border_width + GTK_WIDGET (priv->cell_view_frame)->style->xthickness);
6260 ypad = 2 * (border_width + GTK_WIDGET (priv->cell_view_frame)->style->ythickness);
6264 size -= 2 * focus_width;
6267 gtk_combo_box_measure_height_for_width (combo_box, size, &min_height, &nat_height);
6269 min_height = MAX (min_height, but_height);
6270 nat_height = MAX (nat_height, but_height);
6276 if (GTK_SHADOW_NONE != priv->shadow_type)
6278 min_height += 2 * GTK_WIDGET (widget)->style->ythickness;
6279 nat_height += 2 * GTK_WIDGET (widget)->style->ythickness;
6283 *minimum_size = min_height;
6286 *natural_size = nat_height;