2 * Copyright (C) 2002, 2003 Kristian Rietveld <kris@gtk.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 #include "gtkcombobox.h"
24 #include "gtkbindings.h"
25 #include "gtkcelllayout.h"
26 #include "gtkcellrenderertext.h"
27 #include "gtkcellview.h"
28 #include "gtkeventbox.h"
31 #include "gtkliststore.h"
34 #include "gtkscrolledwindow.h"
35 #include "gtkseparatormenuitem.h"
36 #include "gtktearoffmenuitem.h"
37 #include "gtktogglebutton.h"
38 #include "gtktreeselection.h"
39 #include "gtkvseparator.h"
40 #include "gtkwindow.h"
41 #include "gtksizerequest.h"
42 #include "gtkprivate.h"
44 #include <gdk/gdkkeysyms.h>
46 #include <gobject/gvaluecollector.h>
51 #include "gtkmarshalers.h"
54 #include "gtktreeprivate.h"
56 /* WELCOME, to THE house of evil code */
58 typedef struct _ComboCellInfo ComboCellInfo;
61 GtkCellRenderer *cell;
64 GtkCellLayoutDataFunc func;
66 GDestroyNotify destroy;
73 struct _GtkComboBoxPrivate
81 GtkShadowType shadow_type;
83 gint active; /* Only temporary */
84 GtkTreeRowReference *active_row;
87 GtkTreeViewColumn *column;
90 GtkWidget *cell_view_frame;
97 GtkWidget *popup_widget;
98 GtkWidget *popup_window;
99 GtkWidget *scrolled_window;
106 guint activate_button;
107 guint32 activate_time;
109 guint resize_idle_id;
116 guint popup_in_progress : 1;
117 guint popup_shown : 1;
118 guint add_tearoffs : 1;
120 guint is_cell_renderer : 1;
121 guint editing_canceled : 1;
122 guint auto_scroll : 1;
123 guint focus_on_click : 1;
124 guint button_sensitivity : 2;
126 GtkTreeViewRowSeparatorFunc row_separator_func;
127 gpointer row_separator_data;
128 GDestroyNotify row_separator_destroy;
130 GdkDevice *grab_pointer;
131 GdkDevice *grab_keyboard;
133 gchar *tearoff_title;
136 /* While debugging this evil code, I have learned that
137 * there are actually 4 modes to this widget, which can
138 * be characterized as follows
140 * 1) menu mode, no child added
143 * cell_view -> GtkCellView, regular child
144 * cell_view_frame -> NULL
145 * button -> GtkToggleButton set_parent to combo
146 * arrow -> GtkArrow set_parent to button
147 * separator -> GtkVSepator set_parent to button
148 * popup_widget -> GtkMenu
149 * popup_window -> NULL
150 * scrolled_window -> NULL
152 * 2) menu mode, child added
156 * cell_view_frame -> NULL
157 * button -> GtkToggleButton set_parent to combo
158 * arrow -> GtkArrow, child of button
160 * popup_widget -> GtkMenu
161 * popup_window -> NULL
162 * scrolled_window -> NULL
164 * 3) list mode, no child added
166 * tree_view -> GtkTreeView, child of scrolled_window
167 * cell_view -> GtkCellView, regular child
168 * cell_view_frame -> GtkFrame, set parent to combo
169 * button -> GtkToggleButton, set_parent to combo
170 * arrow -> GtkArrow, child of button
172 * popup_widget -> tree_view
173 * popup_window -> GtkWindow
174 * scrolled_window -> GtkScrolledWindow, child of popup_window
176 * 4) list mode, child added
178 * tree_view -> GtkTreeView, child of scrolled_window
180 * cell_view_frame -> NULL
181 * button -> GtkToggleButton, set_parent to combo
182 * arrow -> GtkArrow, child of button
184 * popup_widget -> tree_view
185 * popup_window -> GtkWindow
186 * scrolled_window -> GtkScrolledWindow, child of popup_window
202 PROP_ROW_SPAN_COLUMN,
203 PROP_COLUMN_SPAN_COLUMN,
210 PROP_BUTTON_SENSITIVITY,
211 PROP_EDITING_CANCELED
214 static guint combo_box_signals[LAST_SIGNAL] = {0,};
216 #define BONUS_PADDING 4
217 #define SCROLL_TIME 100
221 static void gtk_combo_box_cell_layout_init (GtkCellLayoutIface *iface);
222 static void gtk_combo_box_cell_editable_init (GtkCellEditableIface *iface);
223 static void gtk_combo_box_dispose (GObject *object);
224 static void gtk_combo_box_finalize (GObject *object);
225 static void gtk_combo_box_destroy (GtkObject *object);
227 static void gtk_combo_box_set_property (GObject *object,
231 static void gtk_combo_box_get_property (GObject *object,
236 static void gtk_combo_box_state_changed (GtkWidget *widget,
237 GtkStateType previous);
238 static void gtk_combo_box_grab_focus (GtkWidget *widget);
239 static void gtk_combo_box_style_set (GtkWidget *widget,
241 static void gtk_combo_box_button_toggled (GtkWidget *widget,
243 static void gtk_combo_box_button_state_changed (GtkWidget *widget,
244 GtkStateType previous,
246 static void gtk_combo_box_add (GtkContainer *container,
248 static void gtk_combo_box_remove (GtkContainer *container,
251 static ComboCellInfo *gtk_combo_box_get_cell_info (GtkComboBox *combo_box,
252 GtkCellRenderer *cell);
254 static void gtk_combo_box_menu_show (GtkWidget *menu,
256 static void gtk_combo_box_menu_hide (GtkWidget *menu,
259 static void gtk_combo_box_set_popup_widget (GtkComboBox *combo_box,
261 static void gtk_combo_box_menu_position_below (GtkMenu *menu,
266 static void gtk_combo_box_menu_position_over (GtkMenu *menu,
271 static void gtk_combo_box_menu_position (GtkMenu *menu,
277 static void gtk_combo_box_update_requested_width(GtkComboBox *combo_box,
279 static void gtk_combo_box_remeasure (GtkComboBox *combo_box);
281 static void gtk_combo_box_unset_model (GtkComboBox *combo_box);
283 static void gtk_combo_box_size_allocate (GtkWidget *widget,
284 GtkAllocation *allocation);
285 static void gtk_combo_box_forall (GtkContainer *container,
286 gboolean include_internals,
287 GtkCallback callback,
288 gpointer callback_data);
289 static gboolean gtk_combo_box_expose_event (GtkWidget *widget,
290 GdkEventExpose *event);
291 static gboolean gtk_combo_box_scroll_event (GtkWidget *widget,
292 GdkEventScroll *event);
293 static void gtk_combo_box_set_active_internal (GtkComboBox *combo_box,
296 static void gtk_combo_box_check_appearance (GtkComboBox *combo_box);
297 static gchar * gtk_combo_box_real_get_active_text (GtkComboBox *combo_box);
298 static void gtk_combo_box_real_move_active (GtkComboBox *combo_box,
299 GtkScrollType scroll);
300 static void gtk_combo_box_real_popup (GtkComboBox *combo_box);
301 static gboolean gtk_combo_box_real_popdown (GtkComboBox *combo_box);
303 /* listening to the model */
304 static void gtk_combo_box_model_row_inserted (GtkTreeModel *model,
308 static void gtk_combo_box_model_row_deleted (GtkTreeModel *model,
311 static void gtk_combo_box_model_rows_reordered (GtkTreeModel *model,
316 static void gtk_combo_box_model_row_changed (GtkTreeModel *model,
320 static void gtk_combo_box_model_row_expanded (GtkTreeModel *model,
326 static void gtk_combo_box_list_position (GtkComboBox *combo_box,
331 static void gtk_combo_box_list_setup (GtkComboBox *combo_box);
332 static void gtk_combo_box_list_destroy (GtkComboBox *combo_box);
334 static gboolean gtk_combo_box_list_button_released (GtkWidget *widget,
335 GdkEventButton *event,
337 static gboolean gtk_combo_box_list_key_press (GtkWidget *widget,
340 static gboolean gtk_combo_box_list_enter_notify (GtkWidget *widget,
341 GdkEventCrossing *event,
343 static void gtk_combo_box_list_auto_scroll (GtkComboBox *combo,
346 static gboolean gtk_combo_box_list_scroll_timeout (GtkComboBox *combo);
347 static gboolean gtk_combo_box_list_button_pressed (GtkWidget *widget,
348 GdkEventButton *event,
351 static gboolean gtk_combo_box_list_select_func (GtkTreeSelection *selection,
354 gboolean path_currently_selected,
357 static void gtk_combo_box_list_row_changed (GtkTreeModel *model,
361 static void gtk_combo_box_list_popup_resize (GtkComboBox *combo_box);
364 static void gtk_combo_box_menu_setup (GtkComboBox *combo_box,
365 gboolean add_children);
366 static void gtk_combo_box_menu_fill (GtkComboBox *combo_box);
367 static void gtk_combo_box_menu_fill_level (GtkComboBox *combo_box,
370 static void gtk_combo_box_update_title (GtkComboBox *combo_box);
371 static void gtk_combo_box_menu_destroy (GtkComboBox *combo_box);
373 static void gtk_combo_box_relayout_item (GtkComboBox *combo_box,
377 static void gtk_combo_box_relayout (GtkComboBox *combo_box);
379 static gboolean gtk_combo_box_menu_button_press (GtkWidget *widget,
380 GdkEventButton *event,
382 static void gtk_combo_box_menu_item_activate (GtkWidget *item,
385 static void gtk_combo_box_update_sensitivity (GtkComboBox *combo_box);
386 static void gtk_combo_box_menu_row_inserted (GtkTreeModel *model,
390 static void gtk_combo_box_menu_row_deleted (GtkTreeModel *model,
393 static void gtk_combo_box_menu_rows_reordered (GtkTreeModel *model,
398 static void gtk_combo_box_menu_row_changed (GtkTreeModel *model,
402 static gboolean gtk_combo_box_menu_key_press (GtkWidget *widget,
405 static void gtk_combo_box_menu_popup (GtkComboBox *combo_box,
407 guint32 activate_time);
408 static GtkWidget *gtk_cell_view_menu_item_new (GtkComboBox *combo_box,
413 static void gtk_combo_box_cell_layout_pack_start (GtkCellLayout *layout,
414 GtkCellRenderer *cell,
416 static void gtk_combo_box_cell_layout_pack_end (GtkCellLayout *layout,
417 GtkCellRenderer *cell,
419 static GList *gtk_combo_box_cell_layout_get_cells (GtkCellLayout *layout);
420 static void gtk_combo_box_cell_layout_clear (GtkCellLayout *layout);
421 static void gtk_combo_box_cell_layout_add_attribute (GtkCellLayout *layout,
422 GtkCellRenderer *cell,
423 const gchar *attribute,
425 static void gtk_combo_box_cell_layout_set_cell_data_func (GtkCellLayout *layout,
426 GtkCellRenderer *cell,
427 GtkCellLayoutDataFunc func,
429 GDestroyNotify destroy);
430 static void gtk_combo_box_cell_layout_clear_attributes (GtkCellLayout *layout,
431 GtkCellRenderer *cell);
432 static void gtk_combo_box_cell_layout_reorder (GtkCellLayout *layout,
433 GtkCellRenderer *cell,
435 static gboolean gtk_combo_box_mnemonic_activate (GtkWidget *widget,
436 gboolean group_cycling);
438 static void gtk_combo_box_sync_cells (GtkComboBox *combo_box,
439 GtkCellLayout *cell_layout);
440 static void combo_cell_data_func (GtkCellLayout *cell_layout,
441 GtkCellRenderer *cell,
442 GtkTreeModel *tree_model,
445 static void gtk_combo_box_child_show (GtkWidget *widget,
446 GtkComboBox *combo_box);
447 static void gtk_combo_box_child_hide (GtkWidget *widget,
448 GtkComboBox *combo_box);
450 /* GtkBuildable method implementation */
451 static GtkBuildableIface *parent_buildable_iface;
453 static void gtk_combo_box_buildable_init (GtkBuildableIface *iface);
454 static gboolean gtk_combo_box_buildable_custom_tag_start (GtkBuildable *buildable,
457 const gchar *tagname,
458 GMarkupParser *parser,
460 static void gtk_combo_box_buildable_custom_tag_end (GtkBuildable *buildable,
463 const gchar *tagname,
466 /* GtkCellEditable method implementations */
467 static void gtk_combo_box_start_editing (GtkCellEditable *cell_editable,
470 static void gtk_combo_box_size_request_init (GtkSizeRequestIface *iface);
471 static void gtk_combo_box_get_width (GtkSizeRequest *widget,
474 static void gtk_combo_box_get_height (GtkSizeRequest *widget,
477 static void gtk_combo_box_get_width_for_height (GtkSizeRequest *widget,
481 static void gtk_combo_box_get_height_for_width (GtkSizeRequest *widget,
487 G_DEFINE_TYPE_WITH_CODE (GtkComboBox, gtk_combo_box, GTK_TYPE_BIN,
488 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
489 gtk_combo_box_cell_layout_init)
490 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
491 gtk_combo_box_cell_editable_init)
492 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
493 gtk_combo_box_buildable_init)
494 G_IMPLEMENT_INTERFACE (GTK_TYPE_SIZE_REQUEST,
495 gtk_combo_box_size_request_init))
500 gtk_combo_box_class_init (GtkComboBoxClass *klass)
502 GObjectClass *object_class;
503 GtkObjectClass *gtk_object_class;
504 GtkContainerClass *container_class;
505 GtkWidgetClass *widget_class;
506 GtkBindingSet *binding_set;
508 klass->get_active_text = gtk_combo_box_real_get_active_text;
510 container_class = (GtkContainerClass *)klass;
511 container_class->forall = gtk_combo_box_forall;
512 container_class->add = gtk_combo_box_add;
513 container_class->remove = gtk_combo_box_remove;
515 widget_class = (GtkWidgetClass *)klass;
516 widget_class->size_allocate = gtk_combo_box_size_allocate;
517 widget_class->expose_event = gtk_combo_box_expose_event;
518 widget_class->scroll_event = gtk_combo_box_scroll_event;
519 widget_class->mnemonic_activate = gtk_combo_box_mnemonic_activate;
520 widget_class->grab_focus = gtk_combo_box_grab_focus;
521 widget_class->style_set = gtk_combo_box_style_set;
522 widget_class->state_changed = gtk_combo_box_state_changed;
524 gtk_object_class = (GtkObjectClass *)klass;
525 gtk_object_class->destroy = gtk_combo_box_destroy;
527 object_class = (GObjectClass *)klass;
528 object_class->dispose = gtk_combo_box_dispose;
529 object_class->finalize = gtk_combo_box_finalize;
530 object_class->set_property = gtk_combo_box_set_property;
531 object_class->get_property = gtk_combo_box_get_property;
535 * GtkComboBox::changed:
536 * @widget: the object which received the signal
538 * The changed signal is emitted when the active
539 * item is changed. The can be due to the user selecting
540 * a different item from the list, or due to a
541 * call to gtk_combo_box_set_active_iter().
542 * It will also be emitted while typing into a GtkComboBoxEntry,
543 * as well as when selecting an item from the GtkComboBoxEntry's list.
547 combo_box_signals[CHANGED] =
548 g_signal_new (I_("changed"),
549 G_OBJECT_CLASS_TYPE (klass),
551 G_STRUCT_OFFSET (GtkComboBoxClass, changed),
553 g_cclosure_marshal_VOID__VOID,
556 * GtkComboBox::move-active:
557 * @widget: the object that received the signal
558 * @scroll_type: a #GtkScrollType
560 * The ::move-active signal is a
561 * <link linkend="keybinding-signals">keybinding signal</link>
562 * which gets emitted to move the active selection.
566 combo_box_signals[MOVE_ACTIVE] =
567 g_signal_new_class_handler (I_("move-active"),
568 G_OBJECT_CLASS_TYPE (klass),
569 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
570 G_CALLBACK (gtk_combo_box_real_move_active),
572 g_cclosure_marshal_VOID__ENUM,
574 GTK_TYPE_SCROLL_TYPE);
577 * GtkComboBox::popup:
578 * @widget: the object that received the signal
580 * The ::popup signal is a
581 * <link linkend="keybinding-signals">keybinding signal</link>
582 * which gets emitted to popup the combo box list.
584 * The default binding for this signal is Alt+Down.
588 combo_box_signals[POPUP] =
589 g_signal_new_class_handler (I_("popup"),
590 G_OBJECT_CLASS_TYPE (klass),
591 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
592 G_CALLBACK (gtk_combo_box_real_popup),
594 g_cclosure_marshal_VOID__VOID,
597 * GtkComboBox::popdown:
598 * @button: the object which received the signal
600 * The ::popdown signal is a
601 * <link linkend="keybinding-signals">keybinding signal</link>
602 * which gets emitted to popdown the combo box list.
604 * The default bindings for this signal are Alt+Up and Escape.
608 combo_box_signals[POPDOWN] =
609 g_signal_new_class_handler (I_("popdown"),
610 G_OBJECT_CLASS_TYPE (klass),
611 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
612 G_CALLBACK (gtk_combo_box_real_popdown),
614 _gtk_marshal_BOOLEAN__VOID,
618 binding_set = gtk_binding_set_by_class (widget_class);
620 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Down, GDK_MOD1_MASK,
622 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Down, GDK_MOD1_MASK,
625 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Up, GDK_MOD1_MASK,
627 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Up, GDK_MOD1_MASK,
629 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Escape, 0,
632 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Up, 0,
634 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_UP);
635 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Up, 0,
637 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_UP);
638 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Page_Up, 0,
640 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_PAGE_UP);
641 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Page_Up, 0,
643 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_PAGE_UP);
644 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Home, 0,
646 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_START);
647 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Home, 0,
649 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_START);
651 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Down, 0,
653 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_DOWN);
654 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Down, 0,
656 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_DOWN);
657 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Page_Down, 0,
659 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_PAGE_DOWN);
660 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Page_Down, 0,
662 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_PAGE_DOWN);
663 gtk_binding_entry_add_signal (binding_set, GDK_KEY_End, 0,
665 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_END);
666 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_End, 0,
668 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_END);
671 g_object_class_override_property (object_class,
672 PROP_EDITING_CANCELED,
678 * The model from which the combo box takes the values shown
683 g_object_class_install_property (object_class,
685 g_param_spec_object ("model",
686 P_("ComboBox model"),
687 P_("The model for the combo box"),
689 GTK_PARAM_READWRITE));
692 * GtkComboBox:wrap-width:
694 * If wrap-width is set to a positive value, the list will be
695 * displayed in multiple columns, the number of columns is
696 * determined by wrap-width.
700 g_object_class_install_property (object_class,
702 g_param_spec_int ("wrap-width",
704 P_("Wrap width for laying out the items in a grid"),
708 GTK_PARAM_READWRITE));
712 * GtkComboBox:row-span-column:
714 * If this is set to a non-negative value, it must be the index of a column
715 * of type %G_TYPE_INT in the model.
717 * The values of that column are used to determine how many rows a value in
718 * the list will span. Therefore, the values in the model column pointed to
719 * by this property must be greater than zero and not larger than wrap-width.
723 g_object_class_install_property (object_class,
724 PROP_ROW_SPAN_COLUMN,
725 g_param_spec_int ("row-span-column",
726 P_("Row span column"),
727 P_("TreeModel column containing the row span values"),
731 GTK_PARAM_READWRITE));
735 * GtkComboBox:column-span-column:
737 * If this is set to a non-negative value, it must be the index of a column
738 * of type %G_TYPE_INT in the model.
740 * The values of that column are used to determine how many columns a value
741 * in the list will span.
745 g_object_class_install_property (object_class,
746 PROP_COLUMN_SPAN_COLUMN,
747 g_param_spec_int ("column-span-column",
748 P_("Column span column"),
749 P_("TreeModel column containing the column span values"),
753 GTK_PARAM_READWRITE));
757 * GtkComboBox:active:
759 * The item which is currently active. If the model is a non-flat treemodel,
760 * and the active item is not an immediate child of the root of the tree,
761 * this property has the value
762 * <literal>gtk_tree_path_get_indices (path)[0]</literal>,
763 * where <literal>path</literal> is the #GtkTreePath of the active item.
767 g_object_class_install_property (object_class,
769 g_param_spec_int ("active",
771 P_("The item which is currently active"),
775 GTK_PARAM_READWRITE));
778 * GtkComboBox:add-tearoffs:
780 * The add-tearoffs property controls whether generated menus
781 * have tearoff menu items.
783 * Note that this only affects menu style combo boxes.
787 g_object_class_install_property (object_class,
789 g_param_spec_boolean ("add-tearoffs",
790 P_("Add tearoffs to menus"),
791 P_("Whether dropdowns should have a tearoff menu item"),
793 GTK_PARAM_READWRITE));
796 * GtkComboBox:has-frame:
798 * The has-frame property controls whether a frame
799 * is drawn around the entry.
803 g_object_class_install_property (object_class,
805 g_param_spec_boolean ("has-frame",
807 P_("Whether the combo box draws a frame around the child"),
809 GTK_PARAM_READWRITE));
811 g_object_class_install_property (object_class,
813 g_param_spec_boolean ("focus-on-click",
814 P_("Focus on click"),
815 P_("Whether the combo box grabs focus when it is clicked with the mouse"),
817 GTK_PARAM_READWRITE));
820 * GtkComboBox:tearoff-title:
822 * A title that may be displayed by the window manager
823 * when the popup is torn-off.
827 g_object_class_install_property (object_class,
829 g_param_spec_string ("tearoff-title",
831 P_("A title that may be displayed by the window manager when the popup is torn-off"),
833 GTK_PARAM_READWRITE));
837 * GtkComboBox:popup-shown:
839 * Whether the combo boxes dropdown is popped up.
840 * Note that this property is mainly useful, because
841 * it allows you to connect to notify::popup-shown.
845 g_object_class_install_property (object_class,
847 g_param_spec_boolean ("popup-shown",
849 P_("Whether the combo's dropdown is shown"),
851 GTK_PARAM_READABLE));
855 * GtkComboBox:button-sensitivity:
857 * Whether the dropdown button is sensitive when
858 * the model is empty.
862 g_object_class_install_property (object_class,
863 PROP_BUTTON_SENSITIVITY,
864 g_param_spec_enum ("button-sensitivity",
865 P_("Button Sensitivity"),
866 P_("Whether the dropdown button is sensitive when the model is empty"),
867 GTK_TYPE_SENSITIVITY_TYPE,
868 GTK_SENSITIVITY_AUTO,
869 GTK_PARAM_READWRITE));
871 gtk_widget_class_install_style_property (widget_class,
872 g_param_spec_boolean ("appears-as-list",
873 P_("Appears as list"),
874 P_("Whether dropdowns should look like lists rather than menus"),
876 GTK_PARAM_READABLE));
879 * GtkComboBox:arrow-size:
881 * Sets the minimum size of the arrow in the combo box. Note
882 * that the arrow size is coupled to the font size, so in case
883 * a larger font is used, the arrow will be larger than set
888 gtk_widget_class_install_style_property (widget_class,
889 g_param_spec_int ("arrow-size",
891 P_("The minimum size of the arrow in the combo box"),
895 GTK_PARAM_READABLE));
898 * GtkComboBox:shadow-type:
900 * Which kind of shadow to draw around the combo box.
904 gtk_widget_class_install_style_property (widget_class,
905 g_param_spec_enum ("shadow-type",
907 P_("Which kind of shadow to draw around the combo box"),
908 GTK_TYPE_SHADOW_TYPE,
910 GTK_PARAM_READABLE));
912 g_type_class_add_private (object_class, sizeof (GtkComboBoxPrivate));
916 gtk_combo_box_buildable_init (GtkBuildableIface *iface)
918 parent_buildable_iface = g_type_interface_peek_parent (iface);
919 iface->add_child = _gtk_cell_layout_buildable_add_child;
920 iface->custom_tag_start = gtk_combo_box_buildable_custom_tag_start;
921 iface->custom_tag_end = gtk_combo_box_buildable_custom_tag_end;
925 gtk_combo_box_cell_layout_init (GtkCellLayoutIface *iface)
927 iface->pack_start = gtk_combo_box_cell_layout_pack_start;
928 iface->pack_end = gtk_combo_box_cell_layout_pack_end;
929 iface->get_cells = gtk_combo_box_cell_layout_get_cells;
930 iface->clear = gtk_combo_box_cell_layout_clear;
931 iface->add_attribute = gtk_combo_box_cell_layout_add_attribute;
932 iface->set_cell_data_func = gtk_combo_box_cell_layout_set_cell_data_func;
933 iface->clear_attributes = gtk_combo_box_cell_layout_clear_attributes;
934 iface->reorder = gtk_combo_box_cell_layout_reorder;
938 gtk_combo_box_cell_editable_init (GtkCellEditableIface *iface)
940 iface->start_editing = gtk_combo_box_start_editing;
944 gtk_combo_box_init (GtkComboBox *combo_box)
946 GtkComboBoxPrivate *priv;
948 combo_box->priv = G_TYPE_INSTANCE_GET_PRIVATE (combo_box,
951 priv = combo_box->priv;
953 priv->cell_view = gtk_cell_view_new ();
954 gtk_widget_set_parent (priv->cell_view, GTK_WIDGET (combo_box));
955 _gtk_bin_set_child (GTK_BIN (combo_box), priv->cell_view);
956 gtk_widget_show (priv->cell_view);
958 priv->minimum_width = 0;
959 priv->natural_width = 0;
961 priv->wrap_width = 0;
964 priv->active_row = NULL;
965 priv->col_column = -1;
966 priv->row_column = -1;
968 priv->popup_shown = FALSE;
969 priv->add_tearoffs = FALSE;
970 priv->has_frame = TRUE;
971 priv->is_cell_renderer = FALSE;
972 priv->editing_canceled = FALSE;
973 priv->auto_scroll = FALSE;
974 priv->focus_on_click = TRUE;
975 priv->button_sensitivity = GTK_SENSITIVITY_AUTO;
977 gtk_combo_box_check_appearance (combo_box);
981 gtk_combo_box_set_property (GObject *object,
986 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
991 gtk_combo_box_set_model (combo_box, g_value_get_object (value));
994 case PROP_WRAP_WIDTH:
995 gtk_combo_box_set_wrap_width (combo_box, g_value_get_int (value));
998 case PROP_ROW_SPAN_COLUMN:
999 gtk_combo_box_set_row_span_column (combo_box, g_value_get_int (value));
1002 case PROP_COLUMN_SPAN_COLUMN:
1003 gtk_combo_box_set_column_span_column (combo_box, g_value_get_int (value));
1007 gtk_combo_box_set_active (combo_box, g_value_get_int (value));
1010 case PROP_ADD_TEAROFFS:
1011 gtk_combo_box_set_add_tearoffs (combo_box, g_value_get_boolean (value));
1014 case PROP_HAS_FRAME:
1015 combo_box->priv->has_frame = g_value_get_boolean (value);
1018 case PROP_FOCUS_ON_CLICK:
1019 gtk_combo_box_set_focus_on_click (combo_box,
1020 g_value_get_boolean (value));
1023 case PROP_TEAROFF_TITLE:
1024 gtk_combo_box_set_title (combo_box, g_value_get_string (value));
1027 case PROP_POPUP_SHOWN:
1028 if (g_value_get_boolean (value))
1029 gtk_combo_box_popup (combo_box);
1031 gtk_combo_box_popdown (combo_box);
1034 case PROP_BUTTON_SENSITIVITY:
1035 gtk_combo_box_set_button_sensitivity (combo_box,
1036 g_value_get_enum (value));
1039 case PROP_EDITING_CANCELED:
1040 combo_box->priv->editing_canceled = g_value_get_boolean (value);
1044 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1050 gtk_combo_box_get_property (GObject *object,
1055 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
1056 GtkComboBoxPrivate *priv = combo_box->priv;
1061 g_value_set_object (value, combo_box->priv->model);
1064 case PROP_WRAP_WIDTH:
1065 g_value_set_int (value, combo_box->priv->wrap_width);
1068 case PROP_ROW_SPAN_COLUMN:
1069 g_value_set_int (value, combo_box->priv->row_column);
1072 case PROP_COLUMN_SPAN_COLUMN:
1073 g_value_set_int (value, combo_box->priv->col_column);
1077 g_value_set_int (value, gtk_combo_box_get_active (combo_box));
1080 case PROP_ADD_TEAROFFS:
1081 g_value_set_boolean (value, gtk_combo_box_get_add_tearoffs (combo_box));
1084 case PROP_HAS_FRAME:
1085 g_value_set_boolean (value, combo_box->priv->has_frame);
1088 case PROP_FOCUS_ON_CLICK:
1089 g_value_set_boolean (value, combo_box->priv->focus_on_click);
1092 case PROP_TEAROFF_TITLE:
1093 g_value_set_string (value, gtk_combo_box_get_title (combo_box));
1096 case PROP_POPUP_SHOWN:
1097 g_value_set_boolean (value, combo_box->priv->popup_shown);
1100 case PROP_BUTTON_SENSITIVITY:
1101 g_value_set_enum (value, combo_box->priv->button_sensitivity);
1104 case PROP_EDITING_CANCELED:
1105 g_value_set_boolean (value, priv->editing_canceled);
1109 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1115 gtk_combo_box_state_changed (GtkWidget *widget,
1116 GtkStateType previous)
1118 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
1119 GtkComboBoxPrivate *priv = combo_box->priv;
1121 if (gtk_widget_get_realized (widget))
1123 if (priv->tree_view && priv->cell_view)
1124 gtk_cell_view_set_background_color (GTK_CELL_VIEW (priv->cell_view),
1125 >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
1128 gtk_widget_queue_draw (widget);
1132 gtk_combo_box_button_state_changed (GtkWidget *widget,
1133 GtkStateType previous,
1136 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
1137 GtkComboBoxPrivate *priv = combo_box->priv;
1139 if (gtk_widget_get_realized (widget))
1141 if (!priv->tree_view && priv->cell_view)
1143 if ((gtk_widget_get_state (widget) == GTK_STATE_INSENSITIVE) !=
1144 (gtk_widget_get_state (priv->cell_view) == GTK_STATE_INSENSITIVE))
1145 gtk_widget_set_sensitive (priv->cell_view, gtk_widget_get_sensitive (widget));
1147 gtk_widget_set_state (priv->cell_view,
1148 gtk_widget_get_state (widget));
1152 gtk_widget_queue_draw (widget);
1156 gtk_combo_box_check_appearance (GtkComboBox *combo_box)
1158 GtkComboBoxPrivate *priv = combo_box->priv;
1159 gboolean appears_as_list;
1161 /* if wrap_width > 0, then we are in grid-mode and forced to use
1164 if (priv->wrap_width)
1165 appears_as_list = FALSE;
1167 gtk_widget_style_get (GTK_WIDGET (combo_box),
1168 "appears-as-list", &appears_as_list,
1171 if (appears_as_list)
1173 /* Destroy all the menu mode widgets, if they exist. */
1174 if (GTK_IS_MENU (priv->popup_widget))
1175 gtk_combo_box_menu_destroy (combo_box);
1177 /* Create the list mode widgets, if they don't already exist. */
1178 if (!GTK_IS_TREE_VIEW (priv->tree_view))
1179 gtk_combo_box_list_setup (combo_box);
1183 /* Destroy all the list mode widgets, if they exist. */
1184 if (GTK_IS_TREE_VIEW (priv->tree_view))
1185 gtk_combo_box_list_destroy (combo_box);
1187 /* Create the menu mode widgets, if they don't already exist. */
1188 if (!GTK_IS_MENU (priv->popup_widget))
1189 gtk_combo_box_menu_setup (combo_box, TRUE);
1192 gtk_widget_style_get (GTK_WIDGET (combo_box),
1193 "shadow-type", &priv->shadow_type,
1198 gtk_combo_box_style_set (GtkWidget *widget,
1201 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
1202 GtkComboBoxPrivate *priv = combo_box->priv;
1205 gtk_combo_box_check_appearance (combo_box);
1207 if (priv->tree_view && priv->cell_view)
1208 gtk_cell_view_set_background_color (GTK_CELL_VIEW (priv->cell_view),
1209 >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
1211 child = gtk_bin_get_child (GTK_BIN (combo_box));
1212 if (GTK_IS_ENTRY (child))
1213 g_object_set (child, "shadow-type",
1214 GTK_SHADOW_NONE == priv->shadow_type ?
1215 GTK_SHADOW_IN : GTK_SHADOW_NONE, NULL);
1219 gtk_combo_box_button_toggled (GtkWidget *widget,
1222 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
1224 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
1226 if (!combo_box->priv->popup_in_progress)
1227 gtk_combo_box_popup (combo_box);
1230 gtk_combo_box_popdown (combo_box);
1234 gtk_combo_box_add (GtkContainer *container,
1237 GtkComboBox *combo_box = GTK_COMBO_BOX (container);
1238 GtkComboBoxPrivate *priv = combo_box->priv;
1240 if (priv->cell_view &&
1241 gtk_widget_get_parent (priv->cell_view))
1243 gtk_widget_unparent (priv->cell_view);
1244 _gtk_bin_set_child (GTK_BIN (container), NULL);
1245 gtk_widget_queue_resize (GTK_WIDGET (container));
1248 gtk_widget_set_parent (widget, GTK_WIDGET (container));
1249 _gtk_bin_set_child (GTK_BIN (container), widget);
1251 if (priv->cell_view &&
1252 widget != priv->cell_view)
1254 /* since the cell_view was unparented, it's gone now */
1255 priv->cell_view = NULL;
1257 if (!priv->tree_view && priv->separator)
1259 gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (priv->separator)),
1261 priv->separator = NULL;
1263 gtk_widget_queue_resize (GTK_WIDGET (container));
1265 else if (priv->cell_view_frame)
1267 gtk_widget_unparent (priv->cell_view_frame);
1268 priv->cell_view_frame = NULL;
1275 gtk_combo_box_remove (GtkContainer *container,
1278 GtkComboBox *combo_box = GTK_COMBO_BOX (container);
1279 GtkComboBoxPrivate *priv = combo_box->priv;
1281 gboolean appears_as_list;
1283 if (widget == priv->cell_view)
1284 priv->cell_view = NULL;
1286 gtk_widget_unparent (widget);
1287 _gtk_bin_set_child (GTK_BIN (container), NULL);
1289 if (GTK_OBJECT_FLAGS (combo_box) & GTK_IN_DESTRUCTION)
1292 gtk_widget_queue_resize (GTK_WIDGET (container));
1294 if (!priv->tree_view)
1295 appears_as_list = FALSE;
1297 appears_as_list = TRUE;
1299 if (appears_as_list)
1300 gtk_combo_box_list_destroy (combo_box);
1301 else if (GTK_IS_MENU (priv->popup_widget))
1303 gtk_combo_box_menu_destroy (combo_box);
1304 gtk_menu_detach (GTK_MENU (priv->popup_widget));
1305 priv->popup_widget = NULL;
1308 if (!priv->cell_view)
1310 priv->cell_view = gtk_cell_view_new ();
1311 gtk_widget_set_parent (priv->cell_view, GTK_WIDGET (container));
1312 _gtk_bin_set_child (GTK_BIN (container), priv->cell_view);
1314 gtk_widget_show (priv->cell_view);
1315 gtk_cell_view_set_model (GTK_CELL_VIEW (priv->cell_view),
1317 gtk_combo_box_sync_cells (combo_box, GTK_CELL_LAYOUT (priv->cell_view));
1321 if (appears_as_list)
1322 gtk_combo_box_list_setup (combo_box);
1324 gtk_combo_box_menu_setup (combo_box, TRUE);
1326 if (gtk_tree_row_reference_valid (priv->active_row))
1328 path = gtk_tree_row_reference_get_path (priv->active_row);
1329 gtk_combo_box_set_active_internal (combo_box, path);
1330 gtk_tree_path_free (path);
1333 gtk_combo_box_set_active_internal (combo_box, NULL);
1336 static ComboCellInfo *
1337 gtk_combo_box_get_cell_info (GtkComboBox *combo_box,
1338 GtkCellRenderer *cell)
1342 for (i = combo_box->priv->cells; i; i = i->next)
1344 ComboCellInfo *info = (ComboCellInfo *)i->data;
1346 if (info && info->cell == cell)
1354 gtk_combo_box_menu_show (GtkWidget *menu,
1357 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
1358 GtkComboBoxPrivate *priv = combo_box->priv;
1360 gtk_combo_box_child_show (menu, user_data);
1362 priv->popup_in_progress = TRUE;
1363 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->button),
1365 priv->popup_in_progress = FALSE;
1369 gtk_combo_box_menu_hide (GtkWidget *menu,
1372 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
1374 gtk_combo_box_child_hide (menu,user_data);
1376 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
1381 gtk_combo_box_detacher (GtkWidget *widget,
1384 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
1385 GtkComboBoxPrivate *priv = combo_box->priv;
1387 g_return_if_fail (priv->popup_widget == (GtkWidget *) menu);
1389 g_signal_handlers_disconnect_by_func (menu->toplevel,
1390 gtk_combo_box_menu_show,
1392 g_signal_handlers_disconnect_by_func (menu->toplevel,
1393 gtk_combo_box_menu_hide,
1396 priv->popup_widget = NULL;
1400 gtk_combo_box_set_popup_widget (GtkComboBox *combo_box,
1403 GtkComboBoxPrivate *priv = combo_box->priv;
1405 if (GTK_IS_MENU (priv->popup_widget))
1407 gtk_menu_detach (GTK_MENU (priv->popup_widget));
1408 priv->popup_widget = NULL;
1410 else if (priv->popup_widget)
1412 gtk_container_remove (GTK_CONTAINER (priv->scrolled_window),
1413 priv->popup_widget);
1414 g_object_unref (priv->popup_widget);
1415 priv->popup_widget = NULL;
1418 if (GTK_IS_MENU (popup))
1420 if (priv->popup_window)
1422 gtk_widget_destroy (priv->popup_window);
1423 priv->popup_window = NULL;
1426 priv->popup_widget = popup;
1429 * Note that we connect to show/hide on the toplevel, not the
1430 * menu itself, since the menu is not shown/hidden when it is
1431 * popped up while torn-off.
1433 g_signal_connect (GTK_MENU (popup)->toplevel, "show",
1434 G_CALLBACK (gtk_combo_box_menu_show), combo_box);
1435 g_signal_connect (GTK_MENU (popup)->toplevel, "hide",
1436 G_CALLBACK (gtk_combo_box_menu_hide), combo_box);
1438 gtk_menu_attach_to_widget (GTK_MENU (popup),
1439 GTK_WIDGET (combo_box),
1440 gtk_combo_box_detacher);
1444 if (!priv->popup_window)
1446 GtkWidget *toplevel;
1448 priv->popup_window = gtk_window_new (GTK_WINDOW_POPUP);
1449 gtk_widget_set_name (priv->popup_window, "gtk-combobox-popup-window");
1451 gtk_window_set_type_hint (GTK_WINDOW (priv->popup_window),
1452 GDK_WINDOW_TYPE_HINT_COMBO);
1454 g_signal_connect (GTK_WINDOW (priv->popup_window),"show",
1455 G_CALLBACK (gtk_combo_box_child_show),
1457 g_signal_connect (GTK_WINDOW (priv->popup_window),"hide",
1458 G_CALLBACK (gtk_combo_box_child_hide),
1461 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (combo_box));
1462 if (GTK_IS_WINDOW (toplevel))
1464 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
1465 GTK_WINDOW (priv->popup_window));
1466 gtk_window_set_transient_for (GTK_WINDOW (priv->popup_window),
1467 GTK_WINDOW (toplevel));
1470 gtk_window_set_resizable (GTK_WINDOW (priv->popup_window), FALSE);
1471 gtk_window_set_screen (GTK_WINDOW (priv->popup_window),
1472 gtk_widget_get_screen (GTK_WIDGET (combo_box)));
1474 priv->scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1476 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
1479 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (priv->scrolled_window),
1482 gtk_widget_show (priv->scrolled_window);
1484 gtk_container_add (GTK_CONTAINER (priv->popup_window),
1485 priv->scrolled_window);
1488 gtk_container_add (GTK_CONTAINER (priv->scrolled_window),
1491 gtk_widget_show (popup);
1492 g_object_ref (popup);
1493 priv->popup_widget = popup;
1498 gtk_combo_box_menu_position_below (GtkMenu *menu,
1504 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
1505 GtkAllocation child_allocation;
1511 GdkRectangle monitor;
1513 /* FIXME: is using the size request here broken? */
1514 child = gtk_bin_get_child (GTK_BIN (combo_box));
1518 gtk_widget_get_allocation (child, &child_allocation);
1520 if (!gtk_widget_get_has_window (child))
1522 sx += child_allocation.x;
1523 sy += child_allocation.y;
1526 gdk_window_get_root_coords (gtk_widget_get_window (child),
1529 if (GTK_SHADOW_NONE != combo_box->priv->shadow_type)
1530 sx -= gtk_widget_get_style (GTK_WIDGET (combo_box))->xthickness;
1532 gtk_size_request_get_size (GTK_SIZE_REQUEST (menu),
1535 if (gtk_widget_get_direction (GTK_WIDGET (combo_box)) == GTK_TEXT_DIR_LTR)
1538 *x = sx + child_allocation.width - req.width;
1541 screen = gtk_widget_get_screen (GTK_WIDGET (combo_box));
1542 monitor_num = gdk_screen_get_monitor_at_window (screen,
1543 gtk_widget_get_window (GTK_WIDGET (combo_box)));
1544 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
1548 else if (*x + req.width > monitor.x + monitor.width)
1549 *x = monitor.x + monitor.width - req.width;
1551 if (monitor.y + monitor.height - *y - child_allocation.height >= req.height)
1552 *y += child_allocation.height;
1553 else if (*y - monitor.y >= req.height)
1555 else if (monitor.y + monitor.height - *y - child_allocation.height > *y - monitor.y)
1556 *y += child_allocation.height;
1564 gtk_combo_box_menu_position_over (GtkMenu *menu,
1570 GtkComboBox *combo_box;
1574 GtkAllocation allocation;
1575 GtkAllocation child_allocation;
1582 combo_box = GTK_COMBO_BOX (user_data);
1583 widget = GTK_WIDGET (combo_box);
1585 active = gtk_menu_get_active (GTK_MENU (combo_box->priv->popup_widget));
1587 gtk_widget_get_allocation (widget, &allocation);
1589 menu_xpos = allocation.x;
1590 menu_ypos = allocation.y + allocation.height / 2 - 2;
1592 gtk_size_request_get_width (GTK_SIZE_REQUEST (menu), &menu_width, NULL);
1596 gtk_widget_get_allocation (active, &child_allocation);
1597 menu_ypos -= child_allocation.height / 2;
1600 children = GTK_MENU_SHELL (combo_box->priv->popup_widget)->children;
1603 child = children->data;
1605 if (active == child)
1608 if (gtk_widget_get_visible (child))
1610 gtk_widget_get_allocation (child, &child_allocation);
1612 menu_ypos -= child_allocation.height;
1615 children = children->next;
1618 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1619 menu_xpos = menu_xpos + allocation.width - menu_width;
1621 gdk_window_get_root_coords (gtk_widget_get_window (widget),
1622 menu_xpos, menu_ypos,
1623 &menu_xpos, &menu_ypos);
1625 /* Clamp the position on screen */
1626 screen_width = gdk_screen_get_width (gtk_widget_get_screen (widget));
1630 else if ((menu_xpos + menu_width) > screen_width)
1631 menu_xpos -= ((menu_xpos + menu_width) - screen_width);
1640 gtk_combo_box_menu_position (GtkMenu *menu,
1646 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
1647 GtkComboBoxPrivate *priv = combo_box->priv;
1648 GtkWidget *menu_item;
1651 if (priv->wrap_width > 0 || priv->cell_view == NULL)
1652 gtk_combo_box_menu_position_below (menu, x, y, push_in, user_data);
1655 /* FIXME handle nested menus better */
1656 menu_item = gtk_menu_get_active (GTK_MENU (priv->popup_widget));
1658 gtk_menu_shell_select_item (GTK_MENU_SHELL (priv->popup_widget),
1661 gtk_combo_box_menu_position_over (menu, x, y, push_in, user_data);
1664 if (!gtk_widget_get_visible (GTK_MENU (priv->popup_widget)->toplevel))
1665 gtk_window_set_type_hint (GTK_WINDOW (GTK_MENU (priv->popup_widget)->toplevel),
1666 GDK_WINDOW_TYPE_HINT_COMBO);
1670 gtk_combo_box_list_position (GtkComboBox *combo_box,
1676 GtkComboBoxPrivate *priv = combo_box->priv;
1677 GtkAllocation allocation;
1680 GdkRectangle monitor;
1681 GtkRequisition popup_req;
1682 GtkPolicyType hpolicy, vpolicy;
1685 /* under windows, the drop down list is as wide as the combo box itself.
1687 GtkWidget *widget = GTK_WIDGET (combo_box);
1691 gtk_widget_get_allocation (widget, &allocation);
1693 if (!gtk_widget_get_has_window (widget))
1699 window = gtk_widget_get_window (widget);
1701 gdk_window_get_root_coords (gtk_widget_get_window (widget),
1704 *width = allocation.width;
1706 hpolicy = vpolicy = GTK_POLICY_NEVER;
1707 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
1709 gtk_size_request_get_size (GTK_SIZE_REQUEST (priv->scrolled_window),
1712 if (popup_req.width > *width)
1714 hpolicy = GTK_POLICY_ALWAYS;
1715 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
1717 gtk_size_request_get_size (GTK_SIZE_REQUEST (priv->scrolled_window),
1721 *height = popup_req.height;
1723 screen = gtk_widget_get_screen (GTK_WIDGET (combo_box));
1724 monitor_num = gdk_screen_get_monitor_at_window (screen, window);
1725 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
1729 else if (*x + *width > monitor.x + monitor.width)
1730 *x = monitor.x + monitor.width - *width;
1732 if (*y + allocation.height + *height <= monitor.y + monitor.height)
1733 *y += allocation.height;
1734 else if (*y - *height >= monitor.y)
1736 else if (monitor.y + monitor.height - (*y + allocation.height) > *y - monitor.y)
1738 *y += allocation.height;
1739 *height = monitor.y + monitor.height - *y;
1743 *height = *y - monitor.y;
1747 if (popup_req.height > *height)
1749 vpolicy = GTK_POLICY_ALWAYS;
1751 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
1757 cell_view_is_sensitive (GtkCellView *cell_view)
1759 GList *cells, *list;
1762 cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (cell_view));
1765 for (list = cells; list; list = list->next)
1767 g_object_get (list->data, "sensitive", &sensitive, NULL);
1772 g_list_free (cells);
1778 tree_column_row_is_sensitive (GtkComboBox *combo_box,
1781 GtkComboBoxPrivate *priv = combo_box->priv;
1782 GList *cells, *list;
1788 if (priv->row_separator_func)
1790 if (priv->row_separator_func (priv->model, iter,
1791 priv->row_separator_data))
1795 gtk_tree_view_column_cell_set_cell_data (priv->column,
1797 iter, FALSE, FALSE);
1799 cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (priv->column));
1802 for (list = cells; list; list = list->next)
1804 g_object_get (list->data, "sensitive", &sensitive, NULL);
1809 g_list_free (cells);
1815 update_menu_sensitivity (GtkComboBox *combo_box,
1818 GtkComboBoxPrivate *priv = combo_box->priv;
1819 GList *children, *child;
1820 GtkWidget *item, *submenu, *separator;
1821 GtkWidget *cell_view;
1827 children = gtk_container_get_children (GTK_CONTAINER (menu));
1829 for (child = children; child; child = child->next)
1831 item = GTK_WIDGET (child->data);
1832 cell_view = gtk_bin_get_child (GTK_BIN (item));
1834 if (!GTK_IS_CELL_VIEW (cell_view))
1837 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (item));
1838 if (submenu != NULL)
1840 gtk_widget_set_sensitive (item, TRUE);
1841 update_menu_sensitivity (combo_box, submenu);
1845 sensitive = cell_view_is_sensitive (GTK_CELL_VIEW (cell_view));
1847 if (menu != priv->popup_widget && child == children)
1849 separator = GTK_WIDGET (child->next->data);
1850 g_object_set (item, "visible", sensitive, NULL);
1851 g_object_set (separator, "visible", sensitive, NULL);
1854 gtk_widget_set_sensitive (item, sensitive);
1858 g_list_free (children);
1862 gtk_combo_box_menu_popup (GtkComboBox *combo_box,
1864 guint32 activate_time)
1866 GtkComboBoxPrivate *priv = combo_box->priv;
1869 gint width, min_width;
1871 update_menu_sensitivity (combo_box, priv->popup_widget);
1874 if (gtk_tree_row_reference_valid (priv->active_row))
1876 path = gtk_tree_row_reference_get_path (priv->active_row);
1877 active_item = gtk_tree_path_get_indices (path)[0];
1878 gtk_tree_path_free (path);
1880 if (priv->add_tearoffs)
1884 /* FIXME handle nested menus better */
1885 gtk_menu_set_active (GTK_MENU (priv->popup_widget), active_item);
1887 if (priv->wrap_width == 0)
1889 GtkAllocation allocation;
1891 gtk_widget_get_allocation (GTK_WIDGET (combo_box), &allocation);
1892 width = allocation.width;
1893 gtk_widget_set_size_request (priv->popup_widget, -1, -1);
1894 gtk_size_request_get_width (GTK_SIZE_REQUEST (priv->popup_widget), &min_width, NULL);
1896 gtk_widget_set_size_request (priv->popup_widget,
1897 MAX (width, min_width), -1);
1900 gtk_menu_popup (GTK_MENU (priv->popup_widget),
1902 gtk_combo_box_menu_position, combo_box,
1903 button, activate_time);
1907 popup_grab_on_window (GdkWindow *window,
1908 GdkDevice *keyboard,
1910 guint32 activate_time)
1913 gdk_device_grab (keyboard, window,
1914 GDK_OWNERSHIP_WINDOW, TRUE,
1915 GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
1916 NULL, activate_time) != GDK_GRAB_SUCCESS)
1920 gdk_device_grab (pointer, window,
1921 GDK_OWNERSHIP_WINDOW, TRUE,
1922 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
1923 GDK_POINTER_MOTION_MASK,
1924 NULL, activate_time) != GDK_GRAB_SUCCESS)
1927 gdk_device_ungrab (keyboard, activate_time);
1936 * gtk_combo_box_popup:
1937 * @combo_box: a #GtkComboBox
1939 * Pops up the menu or dropdown list of @combo_box.
1941 * This function is mostly intended for use by accessibility technologies;
1942 * applications should have little use for it.
1947 gtk_combo_box_popup (GtkComboBox *combo_box)
1949 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
1951 g_signal_emit (combo_box, combo_box_signals[POPUP], 0);
1955 * gtk_combo_box_popup_for_device:
1956 * @combo_box: a #GtkComboBox
1957 * @device: a #GdkDevice
1959 * Pops up the menu or dropdown list of @combo_box, the popup window
1960 * will be grabbed so only @device and its associated pointer/keyboard
1961 * are the only #GdkDevice<!-- -->s able to send events to it.
1966 gtk_combo_box_popup_for_device (GtkComboBox *combo_box,
1969 GtkComboBoxPrivate *priv = combo_box->priv;
1970 gint x, y, width, height;
1971 GtkTreePath *path = NULL, *ppath;
1972 GtkWidget *toplevel;
1973 GdkDevice *keyboard, *pointer;
1976 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
1977 g_return_if_fail (GDK_IS_DEVICE (device));
1979 if (!gtk_widget_get_realized (GTK_WIDGET (combo_box)))
1982 if (gtk_widget_get_mapped (priv->popup_widget))
1985 if (priv->grab_pointer && priv->grab_keyboard)
1988 time = gtk_get_current_event_time ();
1990 if (device->source == GDK_SOURCE_KEYBOARD)
1993 pointer = gdk_device_get_associated_device (device);
1998 keyboard = gdk_device_get_associated_device (device);
2001 if (GTK_IS_MENU (priv->popup_widget))
2003 gtk_combo_box_menu_popup (combo_box,
2004 priv->activate_button,
2005 priv->activate_time);
2009 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (combo_box));
2010 if (GTK_IS_WINDOW (toplevel))
2011 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
2012 GTK_WINDOW (priv->popup_window));
2014 gtk_widget_show_all (priv->scrolled_window);
2015 gtk_combo_box_list_position (combo_box, &x, &y, &width, &height);
2017 gtk_widget_set_size_request (priv->popup_window, width, height);
2018 gtk_window_move (GTK_WINDOW (priv->popup_window), x, y);
2020 if (gtk_tree_row_reference_valid (priv->active_row))
2022 path = gtk_tree_row_reference_get_path (priv->active_row);
2023 ppath = gtk_tree_path_copy (path);
2024 if (gtk_tree_path_up (ppath))
2025 gtk_tree_view_expand_to_path (GTK_TREE_VIEW (priv->tree_view),
2027 gtk_tree_path_free (ppath);
2029 gtk_tree_view_set_hover_expand (GTK_TREE_VIEW (priv->tree_view),
2033 gtk_widget_show (priv->popup_window);
2037 gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->tree_view),
2039 gtk_tree_path_free (path);
2042 gtk_widget_grab_focus (priv->popup_window);
2043 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->button),
2046 if (!gtk_widget_has_focus (priv->tree_view))
2047 gtk_widget_grab_focus (priv->tree_view);
2049 if (!popup_grab_on_window (gtk_widget_get_window (priv->popup_window),
2050 keyboard, pointer, time))
2052 gtk_widget_hide (priv->popup_window);
2056 gtk_device_grab_add (priv->popup_window, pointer, TRUE);
2057 priv->grab_pointer = pointer;
2058 priv->grab_keyboard = keyboard;
2062 gtk_combo_box_real_popup (GtkComboBox *combo_box)
2066 device = gtk_get_current_event_device ();
2070 GdkDeviceManager *device_manager;
2071 GdkDisplay *display;
2074 display = gtk_widget_get_display (GTK_WIDGET (combo_box));
2075 device_manager = gdk_display_get_device_manager (display);
2077 /* No device was set, pick the first master device */
2078 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
2079 device = devices->data;
2080 g_list_free (devices);
2083 gtk_combo_box_popup_for_device (combo_box, device);
2087 gtk_combo_box_real_popdown (GtkComboBox *combo_box)
2089 if (combo_box->priv->popup_shown)
2091 gtk_combo_box_popdown (combo_box);
2099 * gtk_combo_box_popdown:
2100 * @combo_box: a #GtkComboBox
2102 * Hides the menu or dropdown list of @combo_box.
2104 * This function is mostly intended for use by accessibility technologies;
2105 * applications should have little use for it.
2110 gtk_combo_box_popdown (GtkComboBox *combo_box)
2112 GtkComboBoxPrivate *priv = combo_box->priv;
2114 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
2116 if (GTK_IS_MENU (priv->popup_widget))
2118 gtk_menu_popdown (GTK_MENU (priv->popup_widget));
2122 if (!gtk_widget_get_realized (GTK_WIDGET (combo_box)))
2125 gtk_device_grab_remove (priv->popup_window, priv->grab_pointer);
2126 gtk_widget_hide_all (priv->popup_window);
2127 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->button),
2130 priv->grab_pointer = NULL;
2131 priv->grab_keyboard = NULL;
2135 gtk_combo_box_update_requested_width (GtkComboBox *combo_box,
2138 GtkComboBoxPrivate *priv = combo_box->priv;
2139 gint padding, min_width, nat_width;
2141 if (priv->cell_view)
2142 gtk_widget_style_get (priv->cell_view,
2143 "focus-line-width", &padding,
2148 /* add some pixels for good measure */
2149 padding += BONUS_PADDING;
2151 if (priv->cell_view)
2152 gtk_cell_view_get_desired_width_of_row (GTK_CELL_VIEW (priv->cell_view),
2153 path, &min_width, &nat_width);
2155 min_width = nat_width = 0;
2157 min_width += padding;
2158 nat_width += padding;
2160 if (min_width > priv->minimum_width || nat_width > priv->natural_width)
2162 priv->minimum_width = MAX (priv->minimum_width, min_width);
2163 priv->natural_width = MAX (priv->natural_width, nat_width);
2165 if (priv->cell_view)
2167 gtk_widget_set_size_request (priv->cell_view, min_width, -1);
2168 gtk_widget_queue_resize (priv->cell_view);
2173 #define GTK_COMBO_BOX_SIZE_ALLOCATE_BUTTON \
2174 gtk_size_request_get_size (GTK_SIZE_REQUEST (combo_box->priv->button), \
2178 child.x = allocation->x + shadow_width; \
2180 child.x = allocation->x + allocation->width - req.width - shadow_width; \
2182 child.y = allocation->y + shadow_height; \
2183 child.width = req.width; \
2184 child.height = allocation->height - 2 * shadow_height; \
2185 child.width = MAX (1, child.width); \
2186 child.height = MAX (1, child.height); \
2188 gtk_widget_size_allocate (combo_box->priv->button, &child);
2191 gtk_combo_box_size_allocate (GtkWidget *widget,
2192 GtkAllocation *allocation)
2194 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
2195 GtkComboBoxPrivate *priv = combo_box->priv;
2196 GtkWidget *child_widget;
2197 gint shadow_width, shadow_height;
2198 gint focus_width, focus_pad;
2199 GtkAllocation child;
2202 gboolean is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2204 gtk_widget_set_allocation (widget, allocation);
2205 child_widget = gtk_bin_get_child (GTK_BIN (widget));
2207 style = gtk_widget_get_style (widget);
2208 gtk_widget_style_get (widget,
2209 "focus-line-width", &focus_width,
2210 "focus-padding", &focus_pad,
2213 if (GTK_SHADOW_NONE != priv->shadow_type)
2215 shadow_width = style->xthickness;
2216 shadow_height = style->ythickness;
2224 if (!priv->tree_view)
2226 if (priv->cell_view)
2228 gint xthickness, ythickness;
2233 allocation->x += shadow_width;
2234 allocation->y += shadow_height;
2235 allocation->width -= 2 * shadow_width;
2236 allocation->height -= 2 * shadow_height;
2238 gtk_widget_size_allocate (priv->button, allocation);
2240 /* set some things ready */
2241 border_width = gtk_container_get_border_width (GTK_CONTAINER (priv->button));
2242 style = gtk_widget_get_style (priv->button);
2243 xthickness = style->xthickness;
2244 ythickness = style->ythickness;
2246 child.x = allocation->x;
2247 child.y = allocation->y;
2248 width = allocation->width;
2249 child.height = allocation->height;
2251 if (!priv->is_cell_renderer)
2253 child.x += border_width + xthickness + focus_width + focus_pad;
2254 child.y += border_width + ythickness + focus_width + focus_pad;
2255 width -= 2 * (child.x - allocation->x);
2256 child.height -= 2 * (child.y - allocation->y);
2260 /* handle the children */
2261 gtk_size_request_get_size (GTK_SIZE_REQUEST (priv->arrow),
2263 child.width = req.width;
2265 child.x += width - req.width;
2266 child.width = MAX (1, child.width);
2267 child.height = MAX (1, child.height);
2268 gtk_widget_size_allocate (priv->arrow, &child);
2270 child.x += req.width;
2271 gtk_size_request_get_size (GTK_SIZE_REQUEST (priv->separator),
2273 child.width = req.width;
2275 child.x -= req.width;
2276 child.width = MAX (1, child.width);
2277 child.height = MAX (1, child.height);
2278 gtk_widget_size_allocate (priv->separator, &child);
2282 child.x += req.width;
2283 child.width = allocation->x + allocation->width
2284 - (border_width + xthickness + focus_width + focus_pad)
2289 child.width = child.x;
2290 child.x = allocation->x
2291 + border_width + xthickness + focus_width + focus_pad;
2292 child.width -= child.x;
2295 if (gtk_widget_get_visible (priv->popup_widget))
2297 gint width, min_width;
2299 if (priv->wrap_width == 0)
2301 GtkAllocation combo_box_allocation;
2303 gtk_widget_get_allocation (GTK_WIDGET (combo_box), &combo_box_allocation);
2304 width = combo_box_allocation.width;
2305 gtk_widget_set_size_request (priv->popup_widget, -1, -1);
2306 gtk_size_request_get_width (GTK_SIZE_REQUEST (priv->popup_widget), &min_width, NULL);
2307 gtk_widget_set_size_request (priv->popup_widget,
2308 MAX (width, min_width), -1);
2311 /* reposition the menu after giving it a new width */
2312 gtk_menu_reposition (GTK_MENU (priv->popup_widget));
2315 child.width = MAX (1, child.width);
2316 child.height = MAX (1, child.height);
2317 gtk_widget_size_allocate (child_widget, &child);
2321 GTK_COMBO_BOX_SIZE_ALLOCATE_BUTTON
2324 child.x = allocation->x + req.width + shadow_width;
2326 child.x = allocation->x + shadow_width;
2327 child.y = allocation->y + shadow_height;
2328 child.width = allocation->width - req.width - 2 * shadow_width;
2329 child.width = MAX (1, child.width);
2330 child.height = MAX (1, child.height);
2331 gtk_widget_size_allocate (child_widget, &child);
2338 /* Combobox thickness + border-width */
2339 guint border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
2340 int delta_x = shadow_width + border_width;
2341 int delta_y = shadow_height + border_width;
2344 GTK_COMBO_BOX_SIZE_ALLOCATE_BUTTON
2348 child.x = allocation->x + req.width;
2350 child.x = allocation->x;
2352 child.y = allocation->y;
2353 child.width = allocation->width - req.width;
2354 child.height = allocation->height;
2356 if (priv->cell_view_frame)
2360 child.width = MAX (1, child.width - delta_x * 2);
2361 child.height = MAX (1, child.height - delta_y * 2);
2362 gtk_widget_size_allocate (priv->cell_view_frame, &child);
2365 if (priv->has_frame)
2367 border_width = gtk_container_get_border_width (GTK_CONTAINER (priv->cell_view_frame));
2368 style = gtk_widget_get_style (priv->cell_view_frame);
2369 delta_x = border_width + style->xthickness;
2370 delta_y = border_width + style->ythickness;
2374 child.width -= delta_x * 2;
2375 child.height -= delta_y * 2;
2382 child.width -= delta_x * 2;
2383 child.height -= delta_y * 2;
2386 if (gtk_widget_get_visible (priv->popup_window))
2388 gint x, y, width, height;
2389 gtk_combo_box_list_position (combo_box, &x, &y, &width, &height);
2390 gtk_window_move (GTK_WINDOW (priv->popup_window), x, y);
2391 gtk_widget_set_size_request (priv->popup_window, width, height);
2395 child.width = MAX (1, child.width);
2396 child.height = MAX (1, child.height);
2398 gtk_widget_size_allocate (child_widget, &child);
2402 #undef GTK_COMBO_BOX_ALLOCATE_BUTTON
2405 gtk_combo_box_unset_model (GtkComboBox *combo_box)
2407 GtkComboBoxPrivate *priv = combo_box->priv;
2411 g_signal_handler_disconnect (priv->model,
2413 g_signal_handler_disconnect (priv->model,
2415 g_signal_handler_disconnect (priv->model,
2416 priv->reordered_id);
2417 g_signal_handler_disconnect (priv->model,
2422 if (!priv->tree_view)
2424 if (priv->popup_widget)
2425 gtk_container_foreach (GTK_CONTAINER (priv->popup_widget),
2426 (GtkCallback)gtk_widget_destroy, NULL);
2431 g_object_unref (priv->model);
2435 if (priv->active_row)
2437 gtk_tree_row_reference_free (priv->active_row);
2438 priv->active_row = NULL;
2441 if (priv->cell_view)
2442 gtk_cell_view_set_model (GTK_CELL_VIEW (priv->cell_view), NULL);
2446 gtk_combo_box_forall (GtkContainer *container,
2447 gboolean include_internals,
2448 GtkCallback callback,
2449 gpointer callback_data)
2451 GtkComboBox *combo_box = GTK_COMBO_BOX (container);
2452 GtkComboBoxPrivate *priv = combo_box->priv;
2455 if (include_internals)
2458 (* callback) (priv->button, callback_data);
2459 if (priv->cell_view_frame)
2460 (* callback) (priv->cell_view_frame, callback_data);
2463 child = gtk_bin_get_child (GTK_BIN (container));
2465 (* callback) (child, callback_data);
2469 gtk_combo_box_child_show (GtkWidget *widget,
2470 GtkComboBox *combo_box)
2472 GtkComboBoxPrivate *priv = combo_box->priv;
2474 priv->popup_shown = TRUE;
2475 g_object_notify (G_OBJECT (combo_box), "popup-shown");
2479 gtk_combo_box_child_hide (GtkWidget *widget,
2480 GtkComboBox *combo_box)
2482 GtkComboBoxPrivate *priv = combo_box->priv;
2484 priv->popup_shown = FALSE;
2485 g_object_notify (G_OBJECT (combo_box), "popup-shown");
2489 gtk_combo_box_expose_event (GtkWidget *widget,
2490 GdkEventExpose *event)
2492 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
2493 GtkComboBoxPrivate *priv = combo_box->priv;
2495 if (gtk_widget_is_drawable (widget) &&
2496 GTK_SHADOW_NONE != priv->shadow_type)
2498 GtkAllocation allocation;
2500 gtk_widget_get_allocation (widget, &allocation);
2502 gtk_paint_shadow (gtk_widget_get_style (widget),
2503 gtk_widget_get_window (widget),
2504 GTK_STATE_NORMAL, priv->shadow_type,
2505 NULL, widget, "combobox",
2506 allocation.x, allocation.y,
2507 allocation.width, allocation.height);
2510 gtk_container_propagate_expose (GTK_CONTAINER (widget),
2511 priv->button, event);
2513 if (priv->tree_view && priv->cell_view_frame)
2515 gtk_container_propagate_expose (GTK_CONTAINER (widget),
2516 priv->cell_view_frame, event);
2519 gtk_container_propagate_expose (GTK_CONTAINER (widget),
2520 gtk_bin_get_child (GTK_BIN (widget)),
2536 path_visible (GtkTreeView *view,
2542 /* Note that we rely on the fact that collapsed rows don't have nodes
2544 return _gtk_tree_view_find_node (view, path, &tree, &node);
2548 tree_next_func (GtkTreeModel *model,
2553 SearchData *search_data = (SearchData *)data;
2555 if (search_data->found)
2557 if (!tree_column_row_is_sensitive (search_data->combo, iter))
2560 if (search_data->visible &&
2561 !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
2564 search_data->set = TRUE;
2565 search_data->iter = *iter;
2570 if (gtk_tree_path_compare (path, search_data->path) == 0)
2571 search_data->found = TRUE;
2577 tree_next (GtkComboBox *combo,
2578 GtkTreeModel *model,
2583 SearchData search_data;
2585 search_data.combo = combo;
2586 search_data.path = gtk_tree_model_get_path (model, iter);
2587 search_data.visible = visible;
2588 search_data.found = FALSE;
2589 search_data.set = FALSE;
2591 gtk_tree_model_foreach (model, tree_next_func, &search_data);
2593 *next = search_data.iter;
2595 gtk_tree_path_free (search_data.path);
2597 return search_data.set;
2601 tree_prev_func (GtkTreeModel *model,
2606 SearchData *search_data = (SearchData *)data;
2608 if (gtk_tree_path_compare (path, search_data->path) == 0)
2610 search_data->found = TRUE;
2614 if (!tree_column_row_is_sensitive (search_data->combo, iter))
2617 if (search_data->visible &&
2618 !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
2621 search_data->set = TRUE;
2622 search_data->iter = *iter;
2628 tree_prev (GtkComboBox *combo,
2629 GtkTreeModel *model,
2634 SearchData search_data;
2636 search_data.combo = combo;
2637 search_data.path = gtk_tree_model_get_path (model, iter);
2638 search_data.visible = visible;
2639 search_data.found = FALSE;
2640 search_data.set = FALSE;
2642 gtk_tree_model_foreach (model, tree_prev_func, &search_data);
2644 *prev = search_data.iter;
2646 gtk_tree_path_free (search_data.path);
2648 return search_data.set;
2652 tree_last_func (GtkTreeModel *model,
2657 SearchData *search_data = (SearchData *)data;
2659 if (!tree_column_row_is_sensitive (search_data->combo, iter))
2662 /* Note that we rely on the fact that collapsed rows don't have nodes
2664 if (search_data->visible &&
2665 !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
2668 search_data->set = TRUE;
2669 search_data->iter = *iter;
2675 tree_last (GtkComboBox *combo,
2676 GtkTreeModel *model,
2680 SearchData search_data;
2682 search_data.combo = combo;
2683 search_data.visible = visible;
2684 search_data.set = FALSE;
2686 gtk_tree_model_foreach (model, tree_last_func, &search_data);
2688 *last = search_data.iter;
2690 return search_data.set;
2695 tree_first_func (GtkTreeModel *model,
2700 SearchData *search_data = (SearchData *)data;
2702 if (!tree_column_row_is_sensitive (search_data->combo, iter))
2705 if (search_data->visible &&
2706 !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
2709 search_data->set = TRUE;
2710 search_data->iter = *iter;
2716 tree_first (GtkComboBox *combo,
2717 GtkTreeModel *model,
2721 SearchData search_data;
2723 search_data.combo = combo;
2724 search_data.visible = visible;
2725 search_data.set = FALSE;
2727 gtk_tree_model_foreach (model, tree_first_func, &search_data);
2729 *first = search_data.iter;
2731 return search_data.set;
2735 gtk_combo_box_scroll_event (GtkWidget *widget,
2736 GdkEventScroll *event)
2738 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
2741 GtkTreeIter new_iter;
2743 if (!gtk_combo_box_get_active_iter (combo_box, &iter))
2746 if (event->direction == GDK_SCROLL_UP)
2747 found = tree_prev (combo_box, combo_box->priv->model,
2748 &iter, &new_iter, FALSE);
2750 found = tree_next (combo_box, combo_box->priv->model,
2751 &iter, &new_iter, FALSE);
2754 gtk_combo_box_set_active_iter (combo_box, &new_iter);
2764 gtk_combo_box_sync_cells (GtkComboBox *combo_box,
2765 GtkCellLayout *cell_layout)
2767 GtkComboBoxPrivate *priv = combo_box->priv;
2770 for (k = priv->cells; k; k = k->next)
2773 ComboCellInfo *info = (ComboCellInfo *)k->data;
2775 if (info->pack == GTK_PACK_START)
2776 gtk_cell_layout_pack_start (cell_layout,
2777 info->cell, info->expand);
2778 else if (info->pack == GTK_PACK_END)
2779 gtk_cell_layout_pack_end (cell_layout,
2780 info->cell, info->expand);
2782 gtk_cell_layout_set_cell_data_func (cell_layout,
2784 combo_cell_data_func, info, NULL);
2786 for (j = info->attributes; j; j = j->next->next)
2788 gtk_cell_layout_add_attribute (cell_layout,
2791 GPOINTER_TO_INT (j->next->data));
2797 gtk_combo_box_menu_setup (GtkComboBox *combo_box,
2798 gboolean add_children)
2800 GtkComboBoxPrivate *priv = combo_box->priv;
2804 child = gtk_bin_get_child (GTK_BIN (combo_box));
2806 if (priv->cell_view)
2808 priv->button = gtk_toggle_button_new ();
2809 gtk_button_set_focus_on_click (GTK_BUTTON (priv->button),
2810 priv->focus_on_click);
2812 g_signal_connect (priv->button, "toggled",
2813 G_CALLBACK (gtk_combo_box_button_toggled), combo_box);
2814 gtk_widget_set_parent (priv->button,
2815 gtk_widget_get_parent (child));
2817 priv->box = gtk_hbox_new (FALSE, 0);
2818 gtk_container_add (GTK_CONTAINER (priv->button), priv->box);
2820 priv->separator = gtk_vseparator_new ();
2821 gtk_container_add (GTK_CONTAINER (priv->box), priv->separator);
2823 priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
2824 gtk_container_add (GTK_CONTAINER (priv->box), priv->arrow);
2826 gtk_widget_show_all (priv->button);
2830 priv->button = gtk_toggle_button_new ();
2831 gtk_button_set_focus_on_click (GTK_BUTTON (priv->button),
2832 priv->focus_on_click);
2834 g_signal_connect (priv->button, "toggled",
2835 G_CALLBACK (gtk_combo_box_button_toggled), combo_box);
2836 gtk_widget_set_parent (priv->button,
2837 gtk_widget_get_parent (child));
2839 priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
2840 gtk_container_add (GTK_CONTAINER (priv->button), priv->arrow);
2841 gtk_widget_show_all (priv->button);
2844 g_signal_connect (priv->button, "button-press-event",
2845 G_CALLBACK (gtk_combo_box_menu_button_press),
2847 g_signal_connect (priv->button, "state-changed",
2848 G_CALLBACK (gtk_combo_box_button_state_changed),
2851 /* create our funky menu */
2852 menu = gtk_menu_new ();
2853 gtk_widget_set_name (menu, "gtk-combobox-popup-menu");
2854 gtk_menu_set_reserve_toggle_size (GTK_MENU (menu), FALSE);
2856 g_signal_connect (menu, "key-press-event",
2857 G_CALLBACK (gtk_combo_box_menu_key_press), combo_box);
2858 gtk_combo_box_set_popup_widget (combo_box, menu);
2862 gtk_combo_box_menu_fill (combo_box);
2864 /* the column is needed in tree_column_row_is_sensitive() */
2865 priv->column = gtk_tree_view_column_new ();
2866 g_object_ref_sink (priv->column);
2867 gtk_combo_box_sync_cells (combo_box, GTK_CELL_LAYOUT (priv->column));
2869 gtk_combo_box_update_title (combo_box);
2870 gtk_combo_box_update_sensitivity (combo_box);
2874 gtk_combo_box_menu_fill (GtkComboBox *combo_box)
2876 GtkComboBoxPrivate *priv = combo_box->priv;
2882 menu = priv->popup_widget;
2884 if (priv->add_tearoffs)
2886 GtkWidget *tearoff = gtk_tearoff_menu_item_new ();
2888 gtk_widget_show (tearoff);
2890 if (priv->wrap_width)
2891 gtk_menu_attach (GTK_MENU (menu), tearoff, 0, priv->wrap_width, 0, 1);
2893 gtk_menu_shell_append (GTK_MENU_SHELL (menu), tearoff);
2896 gtk_combo_box_menu_fill_level (combo_box, menu, NULL);
2900 gtk_cell_view_menu_item_new (GtkComboBox *combo_box,
2901 GtkTreeModel *model,
2904 GtkWidget *cell_view;
2909 cell_view = gtk_cell_view_new ();
2910 item = gtk_menu_item_new ();
2911 gtk_container_add (GTK_CONTAINER (item), cell_view);
2913 gtk_cell_view_set_model (GTK_CELL_VIEW (cell_view), model);
2914 path = gtk_tree_model_get_path (model, iter);
2915 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (cell_view), path);
2916 gtk_tree_path_free (path);
2918 gtk_combo_box_sync_cells (combo_box, GTK_CELL_LAYOUT (cell_view));
2919 gtk_size_request_get_size (GTK_SIZE_REQUEST (cell_view),
2921 gtk_widget_show (cell_view);
2927 gtk_combo_box_menu_fill_level (GtkComboBox *combo_box,
2929 GtkTreeIter *parent)
2931 GtkComboBoxPrivate *priv = combo_box->priv;
2932 GtkTreeModel *model = priv->model;
2933 GtkWidget *item, *submenu, *subitem, *separator;
2935 gboolean is_separator;
2940 n_children = gtk_tree_model_iter_n_children (model, parent);
2943 for (i = 0; i < n_children; i++)
2945 gtk_tree_model_iter_nth_child (model, &iter, parent, i);
2947 if (priv->row_separator_func)
2948 is_separator = priv->row_separator_func (priv->model, &iter,
2949 priv->row_separator_data);
2951 is_separator = FALSE;
2955 item = gtk_separator_menu_item_new ();
2956 path = gtk_tree_model_get_path (model, &iter);
2957 g_object_set_data_full (G_OBJECT (item),
2958 I_("gtk-combo-box-item-path"),
2959 gtk_tree_row_reference_new (model, path),
2960 (GDestroyNotify)gtk_tree_row_reference_free);
2961 gtk_tree_path_free (path);
2965 item = gtk_cell_view_menu_item_new (combo_box, model, &iter);
2966 if (gtk_tree_model_iter_has_child (model, &iter))
2968 submenu = gtk_menu_new ();
2969 gtk_menu_set_reserve_toggle_size (GTK_MENU (submenu), FALSE);
2970 gtk_widget_show (submenu);
2971 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
2973 /* Ugly - since menus can only activate leafs, we have to
2974 * duplicate the item inside the submenu.
2976 subitem = gtk_cell_view_menu_item_new (combo_box, model, &iter);
2977 separator = gtk_separator_menu_item_new ();
2978 gtk_widget_show (subitem);
2979 gtk_widget_show (separator);
2980 g_signal_connect (subitem, "activate",
2981 G_CALLBACK (gtk_combo_box_menu_item_activate),
2983 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), subitem);
2984 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), separator);
2986 gtk_combo_box_menu_fill_level (combo_box, submenu, &iter);
2988 g_signal_connect (item, "activate",
2989 G_CALLBACK (gtk_combo_box_menu_item_activate),
2993 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
2994 if (priv->wrap_width && menu == priv->popup_widget)
2995 gtk_combo_box_relayout_item (combo_box, item, &iter, last);
2996 gtk_widget_show (item);
3003 gtk_combo_box_menu_destroy (GtkComboBox *combo_box)
3005 GtkComboBoxPrivate *priv = combo_box->priv;
3007 g_signal_handlers_disconnect_matched (priv->button,
3008 G_SIGNAL_MATCH_DATA,
3010 gtk_combo_box_menu_button_press, NULL);
3011 g_signal_handlers_disconnect_matched (priv->button,
3012 G_SIGNAL_MATCH_DATA,
3014 gtk_combo_box_button_state_changed, combo_box);
3016 /* unparent will remove our latest ref */
3017 gtk_widget_unparent (priv->button);
3020 priv->button = NULL;
3022 priv->separator = NULL;
3024 g_object_unref (priv->column);
3025 priv->column = NULL;
3027 /* changing the popup window will unref the menu and the children */
3035 menu_occupied (GtkMenu *menu,
3039 guint bottom_attach)
3043 for (i = GTK_MENU_SHELL (menu)->children; i; i = i->next)
3047 gtk_container_child_get (GTK_CONTAINER (menu),
3051 "bottom-attach", &b,
3055 /* look if this item intersects with the given coordinates */
3056 if (right_attach > l && left_attach < r && bottom_attach > t && top_attach < b)
3064 gtk_combo_box_relayout_item (GtkComboBox *combo_box,
3069 GtkComboBoxPrivate *priv = combo_box->priv;
3070 gint current_col = 0, current_row = 0;
3071 gint rows = 1, cols = 1;
3072 GtkWidget *menu = priv->popup_widget;
3074 if (!GTK_IS_MENU_SHELL (menu))
3077 if (priv->col_column == -1 &&
3078 priv->row_column == -1 &&
3081 gtk_container_child_get (GTK_CONTAINER (menu),
3083 "right-attach", ¤t_col,
3084 "top-attach", ¤t_row,
3086 if (current_col + cols > priv->wrap_width)
3094 if (priv->col_column != -1)
3095 gtk_tree_model_get (priv->model, iter,
3096 priv->col_column, &cols,
3098 if (priv->row_column != -1)
3099 gtk_tree_model_get (priv->model, iter,
3100 priv->row_column, &rows,
3105 if (current_col + cols > priv->wrap_width)
3111 if (!menu_occupied (GTK_MENU (menu),
3112 current_col, current_col + cols,
3113 current_row, current_row + rows))
3120 /* set attach props */
3121 gtk_menu_attach (GTK_MENU (menu), item,
3122 current_col, current_col + cols,
3123 current_row, current_row + rows);
3127 gtk_combo_box_relayout (GtkComboBox *combo_box)
3132 menu = combo_box->priv->popup_widget;
3134 /* do nothing unless we are in menu style and realized */
3135 if (combo_box->priv->tree_view || !GTK_IS_MENU_SHELL (menu))
3138 list = gtk_container_get_children (GTK_CONTAINER (menu));
3140 for (j = g_list_last (list); j; j = j->prev)
3141 gtk_container_remove (GTK_CONTAINER (menu), j->data);
3143 gtk_combo_box_menu_fill (combo_box);
3150 gtk_combo_box_menu_button_press (GtkWidget *widget,
3151 GdkEventButton *event,
3154 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3155 GtkComboBoxPrivate *priv = combo_box->priv;
3157 if (GTK_IS_MENU (priv->popup_widget) &&
3158 event->type == GDK_BUTTON_PRESS && event->button == 1)
3160 if (priv->focus_on_click &&
3161 !gtk_widget_has_focus (priv->button))
3162 gtk_widget_grab_focus (priv->button);
3164 gtk_combo_box_menu_popup (combo_box, event->button, event->time);
3173 gtk_combo_box_menu_item_activate (GtkWidget *item,
3176 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3177 GtkWidget *cell_view;
3181 cell_view = gtk_bin_get_child (GTK_BIN (item));
3183 g_return_if_fail (GTK_IS_CELL_VIEW (cell_view));
3185 path = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (cell_view));
3187 if (gtk_tree_model_get_iter (combo_box->priv->model, &iter, path))
3189 if (gtk_menu_item_get_submenu (GTK_MENU_ITEM (item)) == NULL)
3190 gtk_combo_box_set_active_iter (combo_box, &iter);
3193 gtk_tree_path_free (path);
3195 g_object_set (combo_box,
3196 "editing-canceled", FALSE,
3201 gtk_combo_box_update_sensitivity (GtkComboBox *combo_box)
3204 gboolean sensitive = TRUE; /* fool code checkers */
3206 if (!combo_box->priv->button)
3209 switch (combo_box->priv->button_sensitivity)
3211 case GTK_SENSITIVITY_ON:
3214 case GTK_SENSITIVITY_OFF:
3217 case GTK_SENSITIVITY_AUTO:
3218 sensitive = combo_box->priv->model &&
3219 gtk_tree_model_get_iter_first (combo_box->priv->model, &iter);
3222 g_assert_not_reached ();
3226 gtk_widget_set_sensitive (combo_box->priv->button, sensitive);
3228 /* In list-mode, we also need to update sensitivity of the event box */
3229 if (GTK_IS_TREE_VIEW (combo_box->priv->tree_view)
3230 && combo_box->priv->cell_view)
3231 gtk_widget_set_sensitive (combo_box->priv->box, sensitive);
3235 gtk_combo_box_model_row_inserted (GtkTreeModel *model,
3240 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3242 if (combo_box->priv->tree_view)
3243 gtk_combo_box_list_popup_resize (combo_box);
3245 gtk_combo_box_menu_row_inserted (model, path, iter, user_data);
3247 gtk_combo_box_update_sensitivity (combo_box);
3251 gtk_combo_box_model_row_deleted (GtkTreeModel *model,
3255 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3256 GtkComboBoxPrivate *priv = combo_box->priv;
3258 if (!gtk_tree_row_reference_valid (priv->active_row))
3260 if (priv->cell_view)
3261 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (priv->cell_view), NULL);
3262 g_signal_emit (combo_box, combo_box_signals[CHANGED], 0);
3265 if (priv->tree_view)
3266 gtk_combo_box_list_popup_resize (combo_box);
3268 gtk_combo_box_menu_row_deleted (model, path, user_data);
3270 gtk_combo_box_update_sensitivity (combo_box);
3274 gtk_combo_box_model_rows_reordered (GtkTreeModel *model,
3280 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3282 gtk_tree_row_reference_reordered (G_OBJECT (user_data), path, iter, new_order);
3284 if (!combo_box->priv->tree_view)
3285 gtk_combo_box_menu_rows_reordered (model, path, iter, new_order, user_data);
3289 gtk_combo_box_model_row_changed (GtkTreeModel *model,
3294 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3295 GtkComboBoxPrivate *priv = combo_box->priv;
3296 GtkTreePath *active_path;
3298 /* FIXME this belongs to GtkCellView */
3299 if (gtk_tree_row_reference_valid (priv->active_row))
3301 active_path = gtk_tree_row_reference_get_path (priv->active_row);
3302 if (gtk_tree_path_compare (path, active_path) == 0 &&
3304 gtk_widget_queue_resize (GTK_WIDGET (priv->cell_view));
3305 gtk_tree_path_free (active_path);
3308 if (priv->tree_view)
3309 gtk_combo_box_list_row_changed (model, path, iter, user_data);
3311 gtk_combo_box_menu_row_changed (model, path, iter, user_data);
3315 list_popup_resize_idle (gpointer user_data)
3317 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3318 GtkComboBoxPrivate *priv = combo_box->priv;
3319 gint x, y, width, height;
3321 if (priv->tree_view && gtk_widget_get_mapped (priv->popup_window))
3323 gtk_combo_box_list_position (combo_box, &x, &y, &width, &height);
3325 gtk_widget_set_size_request (priv->popup_window, width, height);
3326 gtk_window_move (GTK_WINDOW (priv->popup_window), x, y);
3329 priv->resize_idle_id = 0;
3335 gtk_combo_box_list_popup_resize (GtkComboBox *combo_box)
3337 GtkComboBoxPrivate *priv = combo_box->priv;
3339 if (!priv->resize_idle_id)
3340 priv->resize_idle_id =
3341 gdk_threads_add_idle (list_popup_resize_idle, combo_box);
3345 gtk_combo_box_model_row_expanded (GtkTreeModel *model,
3350 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3352 gtk_combo_box_list_popup_resize (combo_box);
3357 find_menu_by_path (GtkWidget *menu,
3359 gboolean skip_first)
3365 GtkTreeRowReference *mref;
3369 list = gtk_container_get_children (GTK_CONTAINER (menu));
3372 for (i = list; i; i = i->next)
3374 child = gtk_bin_get_child (i->data);
3375 if (GTK_IS_SEPARATOR_MENU_ITEM (i->data))
3377 mref = g_object_get_data (G_OBJECT (i->data), "gtk-combo-box-item-path");
3380 else if (!gtk_tree_row_reference_valid (mref))
3383 mpath = gtk_tree_row_reference_get_path (mref);
3385 else if (GTK_IS_CELL_VIEW (child))
3393 mpath = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (child));
3398 /* this case is necessary, since the row reference of
3399 * the cell view may already be updated after a deletion
3406 if (gtk_tree_path_compare (mpath, path) == 0)
3408 gtk_tree_path_free (mpath);
3412 if (gtk_tree_path_is_ancestor (mpath, path))
3414 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
3415 if (submenu != NULL)
3417 gtk_tree_path_free (mpath);
3418 item = find_menu_by_path (submenu, path, TRUE);
3422 gtk_tree_path_free (mpath);
3432 dump_menu_tree (GtkWidget *menu,
3439 list = gtk_container_get_children (GTK_CONTAINER (menu));
3440 for (i = list; i; i = i->next)
3442 if (GTK_IS_CELL_VIEW (GTK_BIN (i->data)->child))
3444 path = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (GTK_BIN (i->data)->child));
3445 g_print ("%*s%s\n", 2 * level, " ", gtk_tree_path_to_string (path));
3446 gtk_tree_path_free (path);
3448 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
3449 if (submenu != NULL)
3450 dump_menu_tree (submenu, level + 1);
3459 gtk_combo_box_menu_row_inserted (GtkTreeModel *model,
3464 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3465 GtkComboBoxPrivate *priv = combo_box->priv;
3467 GtkWidget *item, *menu, *separator;
3471 gboolean is_separator;
3473 if (!priv->popup_widget)
3476 depth = gtk_tree_path_get_depth (path);
3477 pos = gtk_tree_path_get_indices (path)[depth - 1];
3480 ppath = gtk_tree_path_copy (path);
3481 gtk_tree_path_up (ppath);
3482 parent = find_menu_by_path (priv->popup_widget, ppath, FALSE);
3483 gtk_tree_path_free (ppath);
3485 menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (parent));
3488 menu = gtk_menu_new ();
3489 gtk_menu_set_reserve_toggle_size (GTK_MENU (menu), FALSE);
3490 gtk_widget_show (menu);
3491 gtk_menu_item_set_submenu (GTK_MENU_ITEM (parent), menu);
3493 /* Ugly - since menus can only activate leaves, we have to
3494 * duplicate the item inside the submenu.
3496 gtk_tree_model_iter_parent (model, &piter, iter);
3497 item = gtk_cell_view_menu_item_new (combo_box, model, &piter);
3498 separator = gtk_separator_menu_item_new ();
3499 g_signal_connect (item, "activate",
3500 G_CALLBACK (gtk_combo_box_menu_item_activate),
3502 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
3503 gtk_menu_shell_append (GTK_MENU_SHELL (menu), separator);
3504 if (cell_view_is_sensitive (GTK_CELL_VIEW (gtk_bin_get_child (GTK_BIN (item)))))
3506 gtk_widget_show (item);
3507 gtk_widget_show (separator);
3514 menu = priv->popup_widget;
3515 if (priv->add_tearoffs)
3519 if (priv->row_separator_func)
3520 is_separator = priv->row_separator_func (model, iter,
3521 priv->row_separator_data);
3523 is_separator = FALSE;
3527 item = gtk_separator_menu_item_new ();
3528 g_object_set_data_full (G_OBJECT (item),
3529 I_("gtk-combo-box-item-path"),
3530 gtk_tree_row_reference_new (model, path),
3531 (GDestroyNotify)gtk_tree_row_reference_free);
3535 item = gtk_cell_view_menu_item_new (combo_box, model, iter);
3537 g_signal_connect (item, "activate",
3538 G_CALLBACK (gtk_combo_box_menu_item_activate),
3542 gtk_widget_show (item);
3543 gtk_menu_shell_insert (GTK_MENU_SHELL (menu), item, pos);
3547 gtk_combo_box_menu_row_deleted (GtkTreeModel *model,
3551 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3552 GtkComboBoxPrivate *priv = combo_box->priv;
3556 if (!priv->popup_widget)
3559 item = find_menu_by_path (priv->popup_widget, path, FALSE);
3560 menu = gtk_widget_get_parent (item);
3561 gtk_container_remove (GTK_CONTAINER (menu), item);
3563 if (gtk_tree_path_get_depth (path) > 1)
3565 GtkTreePath *parent_path;
3569 parent_path = gtk_tree_path_copy (path);
3570 gtk_tree_path_up (parent_path);
3571 gtk_tree_model_get_iter (model, &iter, parent_path);
3573 if (!gtk_tree_model_iter_has_child (model, &iter))
3575 parent = find_menu_by_path (priv->popup_widget,
3576 parent_path, FALSE);
3577 gtk_menu_item_set_submenu (GTK_MENU_ITEM (parent), NULL);
3583 gtk_combo_box_menu_rows_reordered (GtkTreeModel *model,
3589 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3591 gtk_combo_box_relayout (combo_box);
3595 gtk_combo_box_menu_row_changed (GtkTreeModel *model,
3600 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3601 GtkComboBoxPrivate *priv = combo_box->priv;
3603 gboolean is_separator;
3605 if (!priv->popup_widget)
3608 item = find_menu_by_path (priv->popup_widget, path, FALSE);
3610 if (priv->row_separator_func)
3611 is_separator = priv->row_separator_func (model, iter,
3612 priv->row_separator_data);
3614 is_separator = FALSE;
3616 if (is_separator != GTK_IS_SEPARATOR_MENU_ITEM (item))
3618 gtk_combo_box_menu_row_deleted (model, path, combo_box);
3619 gtk_combo_box_menu_row_inserted (model, path, iter, combo_box);
3622 if (priv->wrap_width &&
3623 gtk_widget_get_parent (item) == priv->popup_widget)
3625 GtkWidget *pitem = NULL;
3628 prev = gtk_tree_path_copy (path);
3630 if (gtk_tree_path_prev (prev))
3631 pitem = find_menu_by_path (priv->popup_widget, prev, FALSE);
3633 gtk_tree_path_free (prev);
3635 /* unattach item so gtk_combo_box_relayout_item() won't spuriously
3637 gtk_container_child_set (GTK_CONTAINER (priv->popup_widget),
3642 "bottom-attach", -1,
3645 gtk_combo_box_relayout_item (combo_box, item, iter, pitem);
3648 gtk_combo_box_update_requested_width (combo_box, path);
3656 gtk_combo_box_list_setup (GtkComboBox *combo_box)
3658 GtkComboBoxPrivate *priv = combo_box->priv;
3659 GtkTreeSelection *sel;
3662 GtkWidget *widget = GTK_WIDGET (combo_box);
3664 priv->button = gtk_toggle_button_new ();
3665 child = gtk_bin_get_child (GTK_BIN (combo_box));
3666 gtk_widget_set_parent (priv->button,
3667 gtk_widget_get_parent (child));
3668 g_signal_connect (priv->button, "button-press-event",
3669 G_CALLBACK (gtk_combo_box_list_button_pressed), combo_box);
3670 g_signal_connect (priv->button, "toggled",
3671 G_CALLBACK (gtk_combo_box_button_toggled), combo_box);
3673 priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
3674 gtk_container_add (GTK_CONTAINER (priv->button), priv->arrow);
3675 priv->separator = NULL;
3676 gtk_widget_show_all (priv->button);
3678 if (priv->cell_view)
3680 style = gtk_widget_get_style (widget);
3681 gtk_cell_view_set_background_color (GTK_CELL_VIEW (priv->cell_view),
3682 &style->base[gtk_widget_get_state (widget)]);
3684 priv->box = gtk_event_box_new ();
3685 gtk_event_box_set_visible_window (GTK_EVENT_BOX (priv->box),
3688 if (priv->has_frame)
3690 priv->cell_view_frame = gtk_frame_new (NULL);
3691 gtk_frame_set_shadow_type (GTK_FRAME (priv->cell_view_frame),
3696 combo_box->priv->cell_view_frame = gtk_event_box_new ();
3697 gtk_event_box_set_visible_window (GTK_EVENT_BOX (combo_box->priv->cell_view_frame),
3701 gtk_widget_set_parent (priv->cell_view_frame,
3702 gtk_widget_get_parent (child));
3703 gtk_container_add (GTK_CONTAINER (priv->cell_view_frame), priv->box);
3704 gtk_widget_show_all (priv->cell_view_frame);
3706 g_signal_connect (priv->box, "button-press-event",
3707 G_CALLBACK (gtk_combo_box_list_button_pressed),
3711 priv->tree_view = gtk_tree_view_new ();
3712 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view));
3713 gtk_tree_selection_set_mode (sel, GTK_SELECTION_BROWSE);
3714 gtk_tree_selection_set_select_function (sel,
3715 gtk_combo_box_list_select_func,
3717 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->tree_view),
3719 gtk_tree_view_set_hover_selection (GTK_TREE_VIEW (priv->tree_view),
3721 if (priv->row_separator_func)
3722 gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (priv->tree_view),
3723 priv->row_separator_func,
3724 priv->row_separator_data,
3727 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->tree_view), priv->model);
3729 priv->column = gtk_tree_view_column_new ();
3730 gtk_tree_view_append_column (GTK_TREE_VIEW (priv->tree_view), priv->column);
3733 gtk_combo_box_sync_cells (combo_box,
3734 GTK_CELL_LAYOUT (priv->column));
3736 if (gtk_tree_row_reference_valid (priv->active_row))
3740 path = gtk_tree_row_reference_get_path (priv->active_row);
3741 gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->tree_view),
3743 gtk_tree_path_free (path);
3746 /* set sample/popup widgets */
3747 gtk_combo_box_set_popup_widget (combo_box, priv->tree_view);
3749 g_signal_connect (priv->tree_view, "key-press-event",
3750 G_CALLBACK (gtk_combo_box_list_key_press),
3752 g_signal_connect (priv->tree_view, "enter-notify-event",
3753 G_CALLBACK (gtk_combo_box_list_enter_notify),
3755 g_signal_connect (priv->tree_view, "row-expanded",
3756 G_CALLBACK (gtk_combo_box_model_row_expanded),
3758 g_signal_connect (priv->tree_view, "row-collapsed",
3759 G_CALLBACK (gtk_combo_box_model_row_expanded),
3761 g_signal_connect (priv->popup_window, "button-press-event",
3762 G_CALLBACK (gtk_combo_box_list_button_pressed),
3764 g_signal_connect (priv->popup_window, "button-release-event",
3765 G_CALLBACK (gtk_combo_box_list_button_released),
3768 gtk_widget_show (priv->tree_view);
3770 gtk_combo_box_update_sensitivity (combo_box);
3774 gtk_combo_box_list_destroy (GtkComboBox *combo_box)
3776 GtkComboBoxPrivate *priv = combo_box->priv;
3778 /* disconnect signals */
3779 g_signal_handlers_disconnect_matched (priv->tree_view,
3780 G_SIGNAL_MATCH_DATA,
3781 0, 0, NULL, NULL, combo_box);
3782 g_signal_handlers_disconnect_matched (priv->button,
3783 G_SIGNAL_MATCH_DATA,
3785 gtk_combo_box_list_button_pressed,
3787 g_signal_handlers_disconnect_matched (priv->popup_window,
3788 G_SIGNAL_MATCH_DATA,
3790 gtk_combo_box_list_button_pressed,
3792 g_signal_handlers_disconnect_matched (priv->popup_window,
3793 G_SIGNAL_MATCH_DATA,
3795 gtk_combo_box_list_button_released,
3798 g_signal_handlers_disconnect_matched (priv->popup_window,
3799 G_SIGNAL_MATCH_DATA,
3801 gtk_combo_box_child_show,
3804 g_signal_handlers_disconnect_matched (priv->popup_window,
3805 G_SIGNAL_MATCH_DATA,
3807 gtk_combo_box_child_hide,
3811 g_signal_handlers_disconnect_matched (priv->box,
3812 G_SIGNAL_MATCH_DATA,
3814 gtk_combo_box_list_button_pressed,
3817 /* destroy things (unparent will kill the latest ref from us)
3818 * last unref on button will destroy the arrow
3820 gtk_widget_unparent (priv->button);
3821 priv->button = NULL;
3824 if (priv->cell_view)
3826 g_object_set (priv->cell_view,
3827 "background-set", FALSE,
3831 if (priv->cell_view_frame)
3833 gtk_widget_unparent (priv->cell_view_frame);
3834 priv->cell_view_frame = NULL;
3838 if (priv->scroll_timer)
3840 g_source_remove (priv->scroll_timer);
3841 priv->scroll_timer = 0;
3844 if (priv->resize_idle_id)
3846 g_source_remove (priv->resize_idle_id);
3847 priv->resize_idle_id = 0;
3850 gtk_widget_destroy (priv->tree_view);
3852 priv->tree_view = NULL;
3853 if (priv->popup_widget)
3855 g_object_unref (priv->popup_widget);
3856 priv->popup_widget = NULL;
3863 gtk_combo_box_list_button_pressed (GtkWidget *widget,
3864 GdkEventButton *event,
3867 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3868 GtkComboBoxPrivate *priv = combo_box->priv;
3870 GtkWidget *ewidget = gtk_get_event_widget ((GdkEvent *)event);
3872 if (ewidget == priv->popup_window)
3875 if ((ewidget != priv->button && ewidget != priv->box) ||
3876 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->button)))
3879 if (priv->focus_on_click &&
3880 !gtk_widget_has_focus (priv->button))
3881 gtk_widget_grab_focus (priv->button);
3883 gtk_combo_box_popup_for_device (combo_box, event->device);
3885 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->button), TRUE);
3887 priv->auto_scroll = FALSE;
3888 if (priv->scroll_timer == 0)
3889 priv->scroll_timer = gdk_threads_add_timeout (SCROLL_TIME,
3890 (GSourceFunc) gtk_combo_box_list_scroll_timeout,
3893 priv->popup_in_progress = TRUE;
3899 gtk_combo_box_list_button_released (GtkWidget *widget,
3900 GdkEventButton *event,
3904 GtkTreePath *path = NULL;
3907 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3908 GtkComboBoxPrivate *priv = combo_box->priv;
3910 gboolean popup_in_progress = FALSE;
3912 GtkWidget *ewidget = gtk_get_event_widget ((GdkEvent *)event);
3914 if (priv->popup_in_progress)
3916 popup_in_progress = TRUE;
3917 priv->popup_in_progress = FALSE;
3920 gtk_tree_view_set_hover_expand (GTK_TREE_VIEW (priv->tree_view),
3922 if (priv->scroll_timer)
3924 g_source_remove (priv->scroll_timer);
3925 priv->scroll_timer = 0;
3928 if (ewidget != priv->tree_view)
3930 if ((ewidget == priv->button ||
3931 ewidget == priv->box) &&
3932 !popup_in_progress &&
3933 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->button)))
3935 gtk_combo_box_popdown (combo_box);
3939 /* released outside treeview */
3940 if (ewidget != priv->button && ewidget != priv->box)
3942 gtk_combo_box_popdown (combo_box);
3950 /* select something cool */
3951 ret = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (priv->tree_view),
3957 return TRUE; /* clicked outside window? */
3959 gtk_tree_model_get_iter (priv->model, &iter, path);
3960 gtk_tree_path_free (path);
3962 gtk_combo_box_popdown (combo_box);
3964 if (tree_column_row_is_sensitive (combo_box, &iter))
3965 gtk_combo_box_set_active_iter (combo_box, &iter);
3971 gtk_combo_box_menu_key_press (GtkWidget *widget,
3975 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3977 if (!gtk_bindings_activate_event (GTK_OBJECT (widget), event))
3979 /* The menu hasn't managed the
3980 * event, forward it to the combobox
3982 gtk_bindings_activate_event (GTK_OBJECT (combo_box), event);
3989 gtk_combo_box_list_key_press (GtkWidget *widget,
3993 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3996 if (event->keyval == GDK_KEY_Return || event->keyval == GDK_KEY_ISO_Enter || event->keyval == GDK_KEY_KP_Enter ||
3997 event->keyval == GDK_KEY_space || event->keyval == GDK_KEY_KP_Space)
3999 GtkTreeModel *model = NULL;
4001 gtk_combo_box_popdown (combo_box);
4003 if (combo_box->priv->model)
4005 GtkTreeSelection *sel;
4007 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (combo_box->priv->tree_view));
4009 if (gtk_tree_selection_get_selected (sel, &model, &iter))
4010 gtk_combo_box_set_active_iter (combo_box, &iter);
4016 if (!gtk_bindings_activate_event (GTK_OBJECT (widget), event))
4018 /* The list hasn't managed the
4019 * event, forward it to the combobox
4021 gtk_bindings_activate_event (GTK_OBJECT (combo_box), event);
4028 gtk_combo_box_list_auto_scroll (GtkComboBox *combo_box,
4033 GtkAllocation allocation;
4034 GtkWidget *tree_view = combo_box->priv->tree_view;
4037 gtk_widget_get_allocation (tree_view, &allocation);
4039 adj = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (combo_box->priv->scrolled_window));
4040 if (adj && adj->upper - adj->lower > adj->page_size)
4042 if (x <= allocation.x &&
4043 adj->lower < adj->value)
4045 value = adj->value - (allocation.x - x + 1);
4046 gtk_adjustment_set_value (adj, value);
4048 else if (x >= allocation.x + allocation.width &&
4049 adj->upper - adj->page_size > adj->value)
4051 value = adj->value + (x - allocation.x - allocation.width + 1);
4052 gtk_adjustment_set_value (adj, MAX (value, 0.0));
4056 adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (combo_box->priv->scrolled_window));
4057 if (adj && adj->upper - adj->lower > adj->page_size)
4059 if (y <= allocation.y &&
4060 adj->lower < adj->value)
4062 value = adj->value - (allocation.y - y + 1);
4063 gtk_adjustment_set_value (adj, value);
4065 else if (y >= allocation.height &&
4066 adj->upper - adj->page_size > adj->value)
4068 value = adj->value + (y - allocation.height + 1);
4069 gtk_adjustment_set_value (adj, MAX (value, 0.0));
4075 gtk_combo_box_list_scroll_timeout (GtkComboBox *combo_box)
4077 GtkComboBoxPrivate *priv = combo_box->priv;
4080 if (priv->auto_scroll)
4082 gdk_window_get_device_position (gtk_widget_get_window (priv->tree_view),
4085 gtk_combo_box_list_auto_scroll (combo_box, x, y);
4092 gtk_combo_box_list_enter_notify (GtkWidget *widget,
4093 GdkEventCrossing *event,
4096 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
4098 combo_box->priv->auto_scroll = TRUE;
4104 gtk_combo_box_list_select_func (GtkTreeSelection *selection,
4105 GtkTreeModel *model,
4107 gboolean path_currently_selected,
4111 gboolean sensitive = FALSE;
4113 for (list = selection->tree_view->priv->columns; list && !sensitive; list = list->next)
4115 GList *cells, *cell;
4116 gboolean cell_sensitive, cell_visible;
4118 GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN (list->data);
4120 if (!column->visible)
4123 gtk_tree_model_get_iter (model, &iter, path);
4124 gtk_tree_view_column_cell_set_cell_data (column, model, &iter,
4127 cell = cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (column));
4130 g_object_get (cell->data,
4131 "sensitive", &cell_sensitive,
4132 "visible", &cell_visible,
4135 if (cell_visible && cell_sensitive)
4140 g_list_free (cells);
4142 sensitive = cell_sensitive;
4149 gtk_combo_box_list_row_changed (GtkTreeModel *model,
4154 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
4156 gtk_combo_box_update_requested_width (combo_box, path);
4160 * GtkCellLayout implementation
4164 pack_start_recurse (GtkWidget *menu,
4165 GtkCellRenderer *cell,
4172 list = gtk_container_get_children (GTK_CONTAINER (menu));
4173 for (i = list; i; i = i->next)
4175 child = gtk_bin_get_child (GTK_BIN (i->data));
4176 if (GTK_IS_CELL_LAYOUT (child))
4177 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (child),
4180 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4181 if (submenu != NULL)
4182 pack_start_recurse (submenu, cell, expand);
4189 gtk_combo_box_cell_layout_pack_start (GtkCellLayout *layout,
4190 GtkCellRenderer *cell,
4193 GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
4194 ComboCellInfo *info;
4195 GtkComboBoxPrivate *priv;
4197 priv = combo_box->priv;
4199 g_object_ref_sink (cell);
4201 info = g_slice_new0 (ComboCellInfo);
4203 info->expand = expand;
4204 info->pack = GTK_PACK_START;
4206 priv->cells = g_slist_append (priv->cells, info);
4208 if (priv->cell_view)
4210 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (priv->cell_view),
4216 gtk_tree_view_column_pack_start (priv->column, cell, expand);
4218 if (GTK_IS_MENU (priv->popup_widget))
4219 pack_start_recurse (priv->popup_widget, cell, expand);
4223 pack_end_recurse (GtkWidget *menu,
4224 GtkCellRenderer *cell,
4231 list = gtk_container_get_children (GTK_CONTAINER (menu));
4232 for (i = list; i; i = i->next)
4234 child = gtk_bin_get_child (GTK_BIN (i->data));
4235 if (GTK_IS_CELL_LAYOUT (child))
4236 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (child),
4239 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4240 if (submenu != NULL)
4241 pack_end_recurse (submenu, cell, expand);
4248 gtk_combo_box_cell_layout_pack_end (GtkCellLayout *layout,
4249 GtkCellRenderer *cell,
4252 GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
4253 ComboCellInfo *info;
4254 GtkComboBoxPrivate *priv;
4256 priv = combo_box->priv;
4258 g_object_ref_sink (cell);
4260 info = g_slice_new0 (ComboCellInfo);
4262 info->expand = expand;
4263 info->pack = GTK_PACK_END;
4265 priv->cells = g_slist_append (priv->cells, info);
4267 if (priv->cell_view)
4268 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (priv->cell_view),
4272 gtk_tree_view_column_pack_end (priv->column, cell, expand);
4274 if (GTK_IS_MENU (priv->popup_widget))
4275 pack_end_recurse (priv->popup_widget, cell, expand);
4279 gtk_combo_box_cell_layout_get_cells (GtkCellLayout *layout)
4281 GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
4283 GList *retval = NULL;
4285 for (list = combo_box->priv->cells; list; list = list->next)
4287 ComboCellInfo *info = (ComboCellInfo *)list->data;
4289 retval = g_list_prepend (retval, info->cell);
4292 return g_list_reverse (retval);
4296 clear_recurse (GtkWidget *menu)
4302 list = gtk_container_get_children (GTK_CONTAINER (menu));
4303 for (i = list; i; i = i->next)
4305 child = gtk_bin_get_child (GTK_BIN (i->data));
4306 if (GTK_IS_CELL_LAYOUT (child))
4307 gtk_cell_layout_clear (GTK_CELL_LAYOUT (child));
4309 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4310 if (submenu != NULL)
4311 clear_recurse (submenu);
4318 gtk_combo_box_cell_layout_clear (GtkCellLayout *layout)
4320 GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
4321 GtkComboBoxPrivate *priv = combo_box->priv;
4324 if (priv->cell_view)
4325 gtk_cell_layout_clear (GTK_CELL_LAYOUT (priv->cell_view));
4328 gtk_tree_view_column_clear (priv->column);
4330 for (i = priv->cells; i; i = i->next)
4332 ComboCellInfo *info = (ComboCellInfo *)i->data;
4334 gtk_combo_box_cell_layout_clear_attributes (layout, info->cell);
4335 g_object_unref (info->cell);
4336 g_slice_free (ComboCellInfo, info);
4339 g_slist_free (priv->cells);
4342 if (GTK_IS_MENU (priv->popup_widget))
4343 clear_recurse (priv->popup_widget);
4347 add_attribute_recurse (GtkWidget *menu,
4348 GtkCellRenderer *cell,
4349 const gchar *attribute,
4356 list = gtk_container_get_children (GTK_CONTAINER (menu));
4357 for (i = list; i; i = i->next)
4359 child = gtk_bin_get_child (GTK_BIN (i->data));
4360 if (GTK_IS_CELL_LAYOUT (child))
4361 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (child),
4362 cell, attribute, column);
4364 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4365 if (submenu != NULL)
4366 add_attribute_recurse (submenu, cell, attribute, column);
4373 gtk_combo_box_cell_layout_add_attribute (GtkCellLayout *layout,
4374 GtkCellRenderer *cell,
4375 const gchar *attribute,
4378 GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
4379 ComboCellInfo *info;
4381 info = gtk_combo_box_get_cell_info (combo_box, cell);
4382 g_return_if_fail (info != NULL);
4384 info->attributes = g_slist_prepend (info->attributes,
4385 GINT_TO_POINTER (column));
4386 info->attributes = g_slist_prepend (info->attributes,
4387 g_strdup (attribute));
4389 if (combo_box->priv->cell_view)
4390 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo_box->priv->cell_view),
4391 cell, attribute, column);
4393 if (combo_box->priv->column)
4394 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo_box->priv->column),
4395 cell, attribute, column);
4397 if (GTK_IS_MENU (combo_box->priv->popup_widget))
4398 add_attribute_recurse (combo_box->priv->popup_widget, cell, attribute, column);
4399 gtk_widget_queue_resize (GTK_WIDGET (combo_box));
4403 combo_cell_data_func (GtkCellLayout *cell_layout,
4404 GtkCellRenderer *cell,
4405 GtkTreeModel *tree_model,
4409 ComboCellInfo *info = (ComboCellInfo *)data;
4410 GtkWidget *parent = NULL;
4415 info->func (cell_layout, cell, tree_model, iter, info->func_data);
4417 if (GTK_IS_WIDGET (cell_layout))
4418 parent = gtk_widget_get_parent (GTK_WIDGET (cell_layout));
4420 if (GTK_IS_MENU_ITEM (parent) &&
4421 gtk_menu_item_get_submenu (GTK_MENU_ITEM (parent)))
4422 g_object_set (cell, "sensitive", TRUE, NULL);
4427 set_cell_data_func_recurse (GtkWidget *menu,
4428 GtkCellRenderer *cell,
4429 ComboCellInfo *info)
4433 GtkWidget *cell_view;
4435 list = gtk_container_get_children (GTK_CONTAINER (menu));
4436 for (i = list; i; i = i->next)
4438 cell_view = gtk_bin_get_child (GTK_BIN (i->data));
4439 if (GTK_IS_CELL_LAYOUT (cell_view))
4441 /* Override sensitivity for inner nodes; we don't
4442 * want menuitems with submenus to appear insensitive
4444 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (cell_view),
4446 combo_cell_data_func,
4448 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4449 if (submenu != NULL)
4450 set_cell_data_func_recurse (submenu, cell, info);
4458 gtk_combo_box_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4459 GtkCellRenderer *cell,
4460 GtkCellLayoutDataFunc func,
4462 GDestroyNotify destroy)
4464 GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
4465 GtkComboBoxPrivate *priv = combo_box->priv;
4466 ComboCellInfo *info;
4468 info = gtk_combo_box_get_cell_info (combo_box, cell);
4469 g_return_if_fail (info != NULL);
4473 GDestroyNotify d = info->destroy;
4475 info->destroy = NULL;
4476 d (info->func_data);
4480 info->func_data = func_data;
4481 info->destroy = destroy;
4483 if (priv->cell_view)
4484 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (priv->cell_view), cell, func, func_data, NULL);
4487 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (priv->column), cell, func, func_data, NULL);
4489 if (GTK_IS_MENU (priv->popup_widget))
4490 set_cell_data_func_recurse (priv->popup_widget, cell, info);
4492 gtk_widget_queue_resize (GTK_WIDGET (combo_box));
4496 clear_attributes_recurse (GtkWidget *menu,
4497 GtkCellRenderer *cell)
4503 list = gtk_container_get_children (GTK_CONTAINER (menu));
4504 for (i = list; i; i = i->next)
4506 child = gtk_bin_get_child (GTK_BIN (i->data));
4507 if (GTK_IS_CELL_LAYOUT (child))
4508 gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (child), cell);
4510 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4511 if (submenu != NULL)
4512 clear_attributes_recurse (submenu, cell);
4519 gtk_combo_box_cell_layout_clear_attributes (GtkCellLayout *layout,
4520 GtkCellRenderer *cell)
4522 GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
4523 GtkComboBoxPrivate *priv;
4524 ComboCellInfo *info;
4527 priv = combo_box->priv;
4529 info = gtk_combo_box_get_cell_info (combo_box, cell);
4530 g_return_if_fail (info != NULL);
4532 list = info->attributes;
4533 while (list && list->next)
4535 g_free (list->data);
4536 list = list->next->next;
4538 g_slist_free (info->attributes);
4539 info->attributes = NULL;
4541 if (priv->cell_view)
4542 gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (priv->cell_view), cell);
4545 gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (priv->column), cell);
4547 if (GTK_IS_MENU (priv->popup_widget))
4548 clear_attributes_recurse (priv->popup_widget, cell);
4550 gtk_widget_queue_resize (GTK_WIDGET (combo_box));
4554 reorder_recurse (GtkWidget *menu,
4555 GtkCellRenderer *cell,
4562 list = gtk_container_get_children (GTK_CONTAINER (menu));
4563 for (i = list; i; i = i->next)
4565 child = gtk_bin_get_child (GTK_BIN (i->data));
4566 if (GTK_IS_CELL_LAYOUT (child))
4567 gtk_cell_layout_reorder (GTK_CELL_LAYOUT (child),
4570 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4571 if (submenu != NULL)
4572 reorder_recurse (submenu, cell, position);
4579 gtk_combo_box_cell_layout_reorder (GtkCellLayout *layout,
4580 GtkCellRenderer *cell,
4583 GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
4584 GtkComboBoxPrivate *priv;
4585 ComboCellInfo *info;
4588 priv = combo_box->priv;
4590 info = gtk_combo_box_get_cell_info (combo_box, cell);
4592 g_return_if_fail (info != NULL);
4593 g_return_if_fail (position >= 0);
4595 link = g_slist_find (priv->cells, info);
4597 g_return_if_fail (link != NULL);
4599 priv->cells = g_slist_delete_link (priv->cells, link);
4600 priv->cells = g_slist_insert (priv->cells, info, position);
4602 if (priv->cell_view)
4603 gtk_cell_layout_reorder (GTK_CELL_LAYOUT (priv->cell_view),
4607 gtk_cell_layout_reorder (GTK_CELL_LAYOUT (priv->column),
4610 if (GTK_IS_MENU (priv->popup_widget))
4611 reorder_recurse (priv->popup_widget, cell, position);
4613 gtk_widget_queue_draw (GTK_WIDGET (combo_box));
4621 * gtk_combo_box_new:
4623 * Creates a new empty #GtkComboBox.
4625 * Return value: A new #GtkComboBox.
4630 gtk_combo_box_new (void)
4632 return g_object_new (GTK_TYPE_COMBO_BOX, NULL);
4636 * gtk_combo_box_new_with_model:
4637 * @model: A #GtkTreeModel.
4639 * Creates a new #GtkComboBox with the model initialized to @model.
4641 * Return value: A new #GtkComboBox.
4646 gtk_combo_box_new_with_model (GtkTreeModel *model)
4648 GtkComboBox *combo_box;
4650 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
4652 combo_box = g_object_new (GTK_TYPE_COMBO_BOX, "model", model, NULL);
4654 return GTK_WIDGET (combo_box);
4658 * gtk_combo_box_get_wrap_width:
4659 * @combo_box: A #GtkComboBox
4661 * Returns the wrap width which is used to determine the number of columns
4662 * for the popup menu. If the wrap width is larger than 1, the combo box
4665 * Returns: the wrap width.
4670 gtk_combo_box_get_wrap_width (GtkComboBox *combo_box)
4672 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), -1);
4674 return combo_box->priv->wrap_width;
4678 * gtk_combo_box_set_wrap_width:
4679 * @combo_box: A #GtkComboBox
4680 * @width: Preferred number of columns
4682 * Sets the wrap width of @combo_box to be @width. The wrap width is basically
4683 * the preferred number of columns when you want the popup to be layed out
4689 gtk_combo_box_set_wrap_width (GtkComboBox *combo_box,
4692 GtkComboBoxPrivate *priv;
4694 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4695 g_return_if_fail (width >= 0);
4697 priv = combo_box->priv;
4699 if (width != priv->wrap_width)
4701 priv->wrap_width = width;
4703 gtk_combo_box_check_appearance (combo_box);
4704 gtk_combo_box_relayout (combo_box);
4706 g_object_notify (G_OBJECT (combo_box), "wrap-width");
4711 * gtk_combo_box_get_row_span_column:
4712 * @combo_box: A #GtkComboBox
4714 * Returns the column with row span information for @combo_box.
4716 * Returns: the row span column.
4721 gtk_combo_box_get_row_span_column (GtkComboBox *combo_box)
4723 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), -1);
4725 return combo_box->priv->row_column;
4729 * gtk_combo_box_set_row_span_column:
4730 * @combo_box: A #GtkComboBox.
4731 * @row_span: A column in the model passed during construction.
4733 * Sets the column with row span information for @combo_box to be @row_span.
4734 * The row span column contains integers which indicate how many rows
4735 * an item should span.
4740 gtk_combo_box_set_row_span_column (GtkComboBox *combo_box,
4743 GtkComboBoxPrivate *priv;
4746 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4748 priv = combo_box->priv;
4750 col = gtk_tree_model_get_n_columns (priv->model);
4751 g_return_if_fail (row_span >= -1 && row_span < col);
4753 if (row_span != priv->row_column)
4755 priv->row_column = row_span;
4757 gtk_combo_box_relayout (combo_box);
4759 g_object_notify (G_OBJECT (combo_box), "row-span-column");
4764 * gtk_combo_box_get_column_span_column:
4765 * @combo_box: A #GtkComboBox
4767 * Returns the column with column span information for @combo_box.
4769 * Returns: the column span column.
4774 gtk_combo_box_get_column_span_column (GtkComboBox *combo_box)
4776 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), -1);
4778 return combo_box->priv->col_column;
4782 * gtk_combo_box_set_column_span_column:
4783 * @combo_box: A #GtkComboBox
4784 * @column_span: A column in the model passed during construction
4786 * Sets the column with column span information for @combo_box to be
4787 * @column_span. The column span column contains integers which indicate
4788 * how many columns an item should span.
4793 gtk_combo_box_set_column_span_column (GtkComboBox *combo_box,
4796 GtkComboBoxPrivate *priv;
4799 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4801 priv = combo_box->priv;
4803 col = gtk_tree_model_get_n_columns (priv->model);
4804 g_return_if_fail (column_span >= -1 && column_span < col);
4806 if (column_span != priv->col_column)
4808 priv->col_column = column_span;
4810 gtk_combo_box_relayout (combo_box);
4812 g_object_notify (G_OBJECT (combo_box), "column-span-column");
4817 * gtk_combo_box_get_active:
4818 * @combo_box: A #GtkComboBox
4820 * Returns the index of the currently active item, or -1 if there's no
4821 * active item. If the model is a non-flat treemodel, and the active item
4822 * is not an immediate child of the root of the tree, this function returns
4823 * <literal>gtk_tree_path_get_indices (path)[0]</literal>, where
4824 * <literal>path</literal> is the #GtkTreePath of the active item.
4826 * Return value: An integer which is the index of the currently active item,
4827 * or -1 if there's no active item.
4832 gtk_combo_box_get_active (GtkComboBox *combo_box)
4834 GtkComboBoxPrivate *priv;
4837 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), 0);
4839 priv = combo_box->priv;
4841 if (gtk_tree_row_reference_valid (priv->active_row))
4845 path = gtk_tree_row_reference_get_path (priv->active_row);
4846 result = gtk_tree_path_get_indices (path)[0];
4847 gtk_tree_path_free (path);
4856 * gtk_combo_box_set_active:
4857 * @combo_box: A #GtkComboBox
4858 * @index_: An index in the model passed during construction, or -1 to have
4861 * Sets the active item of @combo_box to be the item at @index.
4866 gtk_combo_box_set_active (GtkComboBox *combo_box,
4869 GtkTreePath *path = NULL;
4870 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4871 g_return_if_fail (index_ >= -1);
4873 if (combo_box->priv->model == NULL)
4875 /* Save index, in case the model is set after the index */
4876 combo_box->priv->active = index_;
4882 path = gtk_tree_path_new_from_indices (index_, -1);
4884 gtk_combo_box_set_active_internal (combo_box, path);
4887 gtk_tree_path_free (path);
4891 gtk_combo_box_set_active_internal (GtkComboBox *combo_box,
4894 GtkComboBoxPrivate *priv = combo_box->priv;
4895 GtkTreePath *active_path;
4898 /* Remember whether the initially active row is valid. */
4899 gboolean is_valid_row_reference = gtk_tree_row_reference_valid (priv->active_row);
4901 if (path && is_valid_row_reference)
4903 active_path = gtk_tree_row_reference_get_path (priv->active_row);
4904 path_cmp = gtk_tree_path_compare (path, active_path);
4905 gtk_tree_path_free (active_path);
4910 if (priv->active_row)
4912 gtk_tree_row_reference_free (priv->active_row);
4913 priv->active_row = NULL;
4918 if (priv->tree_view)
4919 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view)));
4922 GtkMenu *menu = GTK_MENU (priv->popup_widget);
4924 if (GTK_IS_MENU (menu))
4925 gtk_menu_set_active (menu, -1);
4928 if (priv->cell_view)
4929 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (priv->cell_view), NULL);
4932 * Do not emit a "changed" signal when an already invalid selection was
4933 * now set to invalid.
4935 if (!is_valid_row_reference)
4941 gtk_tree_row_reference_new (priv->model, path);
4943 if (priv->tree_view)
4945 gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->tree_view),
4948 else if (GTK_IS_MENU (priv->popup_widget))
4950 /* FIXME handle nested menus better */
4951 gtk_menu_set_active (GTK_MENU (priv->popup_widget),
4952 gtk_tree_path_get_indices (path)[0]);
4955 if (priv->cell_view)
4956 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (priv->cell_view),
4960 g_signal_emit (combo_box, combo_box_signals[CHANGED], 0);
4961 g_object_notify (G_OBJECT (combo_box), "active");
4966 * gtk_combo_box_get_active_iter:
4967 * @combo_box: A #GtkComboBox
4968 * @iter: (out): The uninitialized #GtkTreeIter
4970 * Sets @iter to point to the current active item, if it exists.
4972 * Return value: %TRUE, if @iter was set
4977 gtk_combo_box_get_active_iter (GtkComboBox *combo_box,
4983 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE);
4985 if (!gtk_tree_row_reference_valid (combo_box->priv->active_row))
4988 path = gtk_tree_row_reference_get_path (combo_box->priv->active_row);
4989 result = gtk_tree_model_get_iter (combo_box->priv->model, iter, path);
4990 gtk_tree_path_free (path);
4996 * gtk_combo_box_set_active_iter:
4997 * @combo_box: A #GtkComboBox
4998 * @iter: (allow-none): The #GtkTreeIter, or %NULL
5000 * Sets the current active item to be the one referenced by @iter, or
5001 * unsets the active item if @iter is %NULL.
5006 gtk_combo_box_set_active_iter (GtkComboBox *combo_box,
5009 GtkTreePath *path = NULL;
5011 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5014 path = gtk_tree_model_get_path (gtk_combo_box_get_model (combo_box), iter);
5016 gtk_combo_box_set_active_internal (combo_box, path);
5017 gtk_tree_path_free (path);
5021 * gtk_combo_box_set_model:
5022 * @combo_box: A #GtkComboBox
5023 * @model: (allow-none): A #GtkTreeModel
5025 * Sets the model used by @combo_box to be @model. Will unset a previously set
5026 * model (if applicable). If model is %NULL, then it will unset the model.
5028 * Note that this function does not clear the cell renderers, you have to
5029 * call gtk_cell_layout_clear() yourself if you need to set up different
5030 * cell renderers for the new model.
5035 gtk_combo_box_set_model (GtkComboBox *combo_box,
5036 GtkTreeModel *model)
5038 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5039 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
5041 if (model == combo_box->priv->model)
5044 gtk_combo_box_unset_model (combo_box);
5049 combo_box->priv->model = model;
5050 g_object_ref (combo_box->priv->model);
5052 combo_box->priv->inserted_id =
5053 g_signal_connect (combo_box->priv->model, "row-inserted",
5054 G_CALLBACK (gtk_combo_box_model_row_inserted),
5056 combo_box->priv->deleted_id =
5057 g_signal_connect (combo_box->priv->model, "row-deleted",
5058 G_CALLBACK (gtk_combo_box_model_row_deleted),
5060 combo_box->priv->reordered_id =
5061 g_signal_connect (combo_box->priv->model, "rows-reordered",
5062 G_CALLBACK (gtk_combo_box_model_rows_reordered),
5064 combo_box->priv->changed_id =
5065 g_signal_connect (combo_box->priv->model, "row-changed",
5066 G_CALLBACK (gtk_combo_box_model_row_changed),
5069 if (combo_box->priv->tree_view)
5072 gtk_tree_view_set_model (GTK_TREE_VIEW (combo_box->priv->tree_view),
5073 combo_box->priv->model);
5074 gtk_combo_box_list_popup_resize (combo_box);
5079 if (combo_box->priv->popup_widget)
5080 gtk_combo_box_menu_fill (combo_box);
5084 if (combo_box->priv->cell_view)
5085 gtk_cell_view_set_model (GTK_CELL_VIEW (combo_box->priv->cell_view),
5086 combo_box->priv->model);
5088 if (combo_box->priv->active != -1)
5090 /* If an index was set in advance, apply it now */
5091 gtk_combo_box_set_active (combo_box, combo_box->priv->active);
5092 combo_box->priv->active = -1;
5096 gtk_combo_box_update_sensitivity (combo_box);
5098 g_object_notify (G_OBJECT (combo_box), "model");
5102 * gtk_combo_box_get_model:
5103 * @combo_box: A #GtkComboBox
5105 * Returns the #GtkTreeModel which is acting as data source for @combo_box.
5107 * Return value: (transfer none): A #GtkTreeModel which was passed
5108 * during construction.
5113 gtk_combo_box_get_model (GtkComboBox *combo_box)
5115 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
5117 return combo_box->priv->model;
5121 /* convenience API for simple text combos */
5124 * gtk_combo_box_new_text:
5126 * Convenience function which constructs a new text combo box, which is a
5127 * #GtkComboBox just displaying strings. If you use this function to create
5128 * a text combo box, you should only manipulate its data source with the
5129 * following convenience functions: gtk_combo_box_append_text(),
5130 * gtk_combo_box_insert_text(), gtk_combo_box_prepend_text() and
5131 * gtk_combo_box_remove_text().
5133 * Return value: (transfer none): A new text combo box.
5138 gtk_combo_box_new_text (void)
5140 GtkWidget *combo_box;
5141 GtkCellRenderer *cell;
5142 GtkListStore *store;
5144 store = gtk_list_store_new (1, G_TYPE_STRING);
5145 combo_box = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));
5146 g_object_unref (store);
5148 cell = gtk_cell_renderer_text_new ();
5149 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), cell, TRUE);
5150 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), cell,
5158 * gtk_combo_box_append_text:
5159 * @combo_box: A #GtkComboBox constructed using gtk_combo_box_new_text()
5162 * Appends @string to the list of strings stored in @combo_box. Note that
5163 * you can only use this function with combo boxes constructed with
5164 * gtk_combo_box_new_text().
5169 gtk_combo_box_append_text (GtkComboBox *combo_box,
5173 GtkListStore *store;
5175 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5176 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
5177 g_return_if_fail (gtk_tree_model_get_column_type (combo_box->priv->model, 0)
5179 g_return_if_fail (text != NULL);
5181 store = GTK_LIST_STORE (combo_box->priv->model);
5183 gtk_list_store_append (store, &iter);
5184 gtk_list_store_set (store, &iter, 0, text, -1);
5188 * gtk_combo_box_insert_text:
5189 * @combo_box: A #GtkComboBox constructed using gtk_combo_box_new_text()
5190 * @position: An index to insert @text
5193 * Inserts @string at @position in the list of strings stored in @combo_box.
5194 * Note that you can only use this function with combo boxes constructed
5195 * with gtk_combo_box_new_text().
5200 gtk_combo_box_insert_text (GtkComboBox *combo_box,
5205 GtkListStore *store;
5207 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5208 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
5209 g_return_if_fail (position >= 0);
5210 g_return_if_fail (gtk_tree_model_get_column_type (combo_box->priv->model, 0)
5212 g_return_if_fail (text != NULL);
5214 store = GTK_LIST_STORE (combo_box->priv->model);
5216 gtk_list_store_insert (store, &iter, position);
5217 gtk_list_store_set (store, &iter, 0, text, -1);
5221 * gtk_combo_box_prepend_text:
5222 * @combo_box: A #GtkComboBox constructed with gtk_combo_box_new_text()
5225 * Prepends @string to the list of strings stored in @combo_box. Note that
5226 * you can only use this function with combo boxes constructed with
5227 * gtk_combo_box_new_text().
5232 gtk_combo_box_prepend_text (GtkComboBox *combo_box,
5236 GtkListStore *store;
5238 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5239 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
5240 g_return_if_fail (gtk_tree_model_get_column_type (combo_box->priv->model, 0)
5242 g_return_if_fail (text != NULL);
5244 store = GTK_LIST_STORE (combo_box->priv->model);
5246 gtk_list_store_prepend (store, &iter);
5247 gtk_list_store_set (store, &iter, 0, text, -1);
5251 * gtk_combo_box_remove_text:
5252 * @combo_box: A #GtkComboBox constructed with gtk_combo_box_new_text()
5253 * @position: Index of the item to remove
5255 * Removes the string at @position from @combo_box. Note that you can only use
5256 * this function with combo boxes constructed with gtk_combo_box_new_text().
5261 gtk_combo_box_remove_text (GtkComboBox *combo_box,
5265 GtkListStore *store;
5267 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5268 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
5269 g_return_if_fail (gtk_tree_model_get_column_type (combo_box->priv->model, 0)
5271 g_return_if_fail (position >= 0);
5273 store = GTK_LIST_STORE (combo_box->priv->model);
5275 if (gtk_tree_model_iter_nth_child (combo_box->priv->model, &iter,
5277 gtk_list_store_remove (store, &iter);
5281 * gtk_combo_box_get_active_text:
5282 * @combo_box: A #GtkComboBox constructed with gtk_combo_box_new_text()
5284 * Returns the currently active string in @combo_box or %NULL if none
5285 * is selected. Note that you can only use this function with combo
5286 * boxes constructed with gtk_combo_box_new_text() and with
5287 * #GtkComboBoxEntry<!-- -->s.
5289 * Returns: a newly allocated string containing the currently active text.
5290 * Must be freed with g_free().
5295 gtk_combo_box_get_active_text (GtkComboBox *combo_box)
5297 GtkComboBoxClass *class;
5299 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
5301 class = GTK_COMBO_BOX_GET_CLASS (combo_box);
5303 if (class->get_active_text)
5304 return class->get_active_text (combo_box);
5310 gtk_combo_box_real_get_active_text (GtkComboBox *combo_box)
5315 g_return_val_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model), NULL);
5316 g_return_val_if_fail (gtk_tree_model_get_column_type (combo_box->priv->model, 0)
5317 == G_TYPE_STRING, NULL);
5319 if (gtk_combo_box_get_active_iter (combo_box, &iter))
5320 gtk_tree_model_get (combo_box->priv->model, &iter,
5327 gtk_combo_box_real_move_active (GtkComboBox *combo_box,
5328 GtkScrollType scroll)
5331 GtkTreeIter new_iter;
5332 gboolean active_iter;
5335 if (!combo_box->priv->model)
5337 gtk_widget_error_bell (GTK_WIDGET (combo_box));
5341 active_iter = gtk_combo_box_get_active_iter (combo_box, &iter);
5345 case GTK_SCROLL_STEP_BACKWARD:
5346 case GTK_SCROLL_STEP_UP:
5347 case GTK_SCROLL_STEP_LEFT:
5350 found = tree_prev (combo_box, combo_box->priv->model,
5351 &iter, &new_iter, FALSE);
5354 /* else fall through */
5356 case GTK_SCROLL_PAGE_FORWARD:
5357 case GTK_SCROLL_PAGE_DOWN:
5358 case GTK_SCROLL_PAGE_RIGHT:
5359 case GTK_SCROLL_END:
5360 found = tree_last (combo_box, combo_box->priv->model, &new_iter, FALSE);
5363 case GTK_SCROLL_STEP_FORWARD:
5364 case GTK_SCROLL_STEP_DOWN:
5365 case GTK_SCROLL_STEP_RIGHT:
5368 found = tree_next (combo_box, combo_box->priv->model,
5369 &iter, &new_iter, FALSE);
5372 /* else fall through */
5374 case GTK_SCROLL_PAGE_BACKWARD:
5375 case GTK_SCROLL_PAGE_UP:
5376 case GTK_SCROLL_PAGE_LEFT:
5377 case GTK_SCROLL_START:
5378 found = tree_first (combo_box, combo_box->priv->model, &new_iter, FALSE);
5385 if (found && active_iter)
5387 GtkTreePath *old_path;
5388 GtkTreePath *new_path;
5390 old_path = gtk_tree_model_get_path (combo_box->priv->model, &iter);
5391 new_path = gtk_tree_model_get_path (combo_box->priv->model, &new_iter);
5393 if (gtk_tree_path_compare (old_path, new_path) == 0)
5396 gtk_tree_path_free (old_path);
5397 gtk_tree_path_free (new_path);
5402 gtk_combo_box_set_active_iter (combo_box, &new_iter);
5406 gtk_widget_error_bell (GTK_WIDGET (combo_box));
5411 gtk_combo_box_mnemonic_activate (GtkWidget *widget,
5412 gboolean group_cycling)
5414 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
5416 gtk_widget_grab_focus (combo_box->priv->button);
5422 gtk_combo_box_grab_focus (GtkWidget *widget)
5424 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
5426 gtk_widget_grab_focus (combo_box->priv->button);
5430 gtk_combo_box_destroy (GtkObject *object)
5432 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
5434 if (combo_box->priv->popup_idle_id > 0)
5436 g_source_remove (combo_box->priv->popup_idle_id);
5437 combo_box->priv->popup_idle_id = 0;
5440 gtk_combo_box_popdown (combo_box);
5442 if (combo_box->priv->row_separator_destroy)
5443 combo_box->priv->row_separator_destroy (combo_box->priv->row_separator_data);
5445 combo_box->priv->row_separator_func = NULL;
5446 combo_box->priv->row_separator_data = NULL;
5447 combo_box->priv->row_separator_destroy = NULL;
5449 GTK_OBJECT_CLASS (gtk_combo_box_parent_class)->destroy (object);
5450 combo_box->priv->cell_view = NULL;
5454 gtk_combo_box_dispose(GObject* object)
5456 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
5458 if (GTK_IS_MENU (combo_box->priv->popup_widget))
5460 gtk_combo_box_menu_destroy (combo_box);
5461 gtk_menu_detach (GTK_MENU (combo_box->priv->popup_widget));
5462 combo_box->priv->popup_widget = NULL;
5465 G_OBJECT_CLASS (gtk_combo_box_parent_class)->dispose (object);
5469 gtk_combo_box_finalize (GObject *object)
5471 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
5474 if (GTK_IS_TREE_VIEW (combo_box->priv->tree_view))
5475 gtk_combo_box_list_destroy (combo_box);
5477 if (combo_box->priv->popup_window)
5478 gtk_widget_destroy (combo_box->priv->popup_window);
5480 gtk_combo_box_unset_model (combo_box);
5482 for (i = combo_box->priv->cells; i; i = i->next)
5484 ComboCellInfo *info = (ComboCellInfo *)i->data;
5485 GSList *list = info->attributes;
5488 info->destroy (info->func_data);
5490 while (list && list->next)
5492 g_free (list->data);
5493 list = list->next->next;
5495 g_slist_free (info->attributes);
5497 g_object_unref (info->cell);
5498 g_slice_free (ComboCellInfo, info);
5500 g_slist_free (combo_box->priv->cells);
5502 g_free (combo_box->priv->tearoff_title);
5504 G_OBJECT_CLASS (gtk_combo_box_parent_class)->finalize (object);
5508 gtk_cell_editable_key_press (GtkWidget *widget,
5512 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
5514 if (event->keyval == GDK_KEY_Escape)
5516 g_object_set (combo_box,
5517 "editing-canceled", TRUE,
5519 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (combo_box));
5520 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (combo_box));
5524 else if (event->keyval == GDK_KEY_Return ||
5525 event->keyval == GDK_KEY_ISO_Enter ||
5526 event->keyval == GDK_KEY_KP_Enter)
5528 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (combo_box));
5529 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (combo_box));
5538 popdown_idle (gpointer data)
5540 GtkComboBox *combo_box;
5542 combo_box = GTK_COMBO_BOX (data);
5544 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (combo_box));
5545 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (combo_box));
5547 g_object_unref (combo_box);
5553 popdown_handler (GtkWidget *widget,
5556 gdk_threads_add_idle (popdown_idle, g_object_ref (data));
5560 popup_idle (gpointer data)
5562 GtkComboBox *combo_box;
5564 combo_box = GTK_COMBO_BOX (data);
5566 if (GTK_IS_MENU (combo_box->priv->popup_widget) &&
5567 combo_box->priv->cell_view)
5568 g_signal_connect_object (combo_box->priv->popup_widget,
5569 "unmap", G_CALLBACK (popdown_handler),
5572 /* we unset this if a menu item is activated */
5573 g_object_set (combo_box,
5574 "editing-canceled", TRUE,
5576 gtk_combo_box_popup (combo_box);
5578 combo_box->priv->popup_idle_id = 0;
5579 combo_box->priv->activate_button = 0;
5580 combo_box->priv->activate_time = 0;
5586 gtk_combo_box_start_editing (GtkCellEditable *cell_editable,
5589 GtkComboBox *combo_box = GTK_COMBO_BOX (cell_editable);
5592 combo_box->priv->is_cell_renderer = TRUE;
5594 if (combo_box->priv->cell_view)
5596 g_signal_connect_object (combo_box->priv->button, "key-press-event",
5597 G_CALLBACK (gtk_cell_editable_key_press),
5600 gtk_widget_grab_focus (combo_box->priv->button);
5604 child = gtk_bin_get_child (GTK_BIN (combo_box));
5606 g_signal_connect_object (child, "key-press-event",
5607 G_CALLBACK (gtk_cell_editable_key_press),
5610 gtk_widget_grab_focus (child);
5611 gtk_widget_set_can_focus (combo_box->priv->button, FALSE);
5614 /* we do the immediate popup only for the optionmenu-like
5617 if (combo_box->priv->is_cell_renderer &&
5618 combo_box->priv->cell_view && !combo_box->priv->tree_view)
5620 if (event && event->type == GDK_BUTTON_PRESS)
5622 GdkEventButton *event_button = (GdkEventButton *)event;
5624 combo_box->priv->activate_button = event_button->button;
5625 combo_box->priv->activate_time = event_button->time;
5628 combo_box->priv->popup_idle_id =
5629 gdk_threads_add_idle (popup_idle, combo_box);
5635 * gtk_combo_box_get_add_tearoffs:
5636 * @combo_box: a #GtkComboBox
5638 * Gets the current value of the :add-tearoffs property.
5640 * Return value: the current value of the :add-tearoffs property.
5643 gtk_combo_box_get_add_tearoffs (GtkComboBox *combo_box)
5645 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE);
5647 return combo_box->priv->add_tearoffs;
5651 * gtk_combo_box_set_add_tearoffs:
5652 * @combo_box: a #GtkComboBox
5653 * @add_tearoffs: %TRUE to add tearoff menu items
5655 * Sets whether the popup menu should have a tearoff
5661 gtk_combo_box_set_add_tearoffs (GtkComboBox *combo_box,
5662 gboolean add_tearoffs)
5664 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5666 add_tearoffs = add_tearoffs != FALSE;
5668 if (combo_box->priv->add_tearoffs != add_tearoffs)
5670 combo_box->priv->add_tearoffs = add_tearoffs;
5671 gtk_combo_box_check_appearance (combo_box);
5672 gtk_combo_box_relayout (combo_box);
5673 g_object_notify (G_OBJECT (combo_box), "add-tearoffs");
5678 * gtk_combo_box_get_title:
5679 * @combo_box: a #GtkComboBox
5681 * Gets the current title of the menu in tearoff mode. See
5682 * gtk_combo_box_set_add_tearoffs().
5684 * Returns: the menu's title in tearoff mode. This is an internal copy of the
5685 * string which must not be freed.
5689 G_CONST_RETURN gchar*
5690 gtk_combo_box_get_title (GtkComboBox *combo_box)
5692 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
5694 return combo_box->priv->tearoff_title;
5698 gtk_combo_box_update_title (GtkComboBox *combo_box)
5700 gtk_combo_box_check_appearance (combo_box);
5702 if (combo_box->priv->popup_widget &&
5703 GTK_IS_MENU (combo_box->priv->popup_widget))
5704 gtk_menu_set_title (GTK_MENU (combo_box->priv->popup_widget),
5705 combo_box->priv->tearoff_title);
5709 * gtk_combo_box_set_title:
5710 * @combo_box: a #GtkComboBox
5711 * @title: a title for the menu in tearoff mode
5713 * Sets the menu's title in tearoff mode.
5718 gtk_combo_box_set_title (GtkComboBox *combo_box,
5721 GtkComboBoxPrivate *priv;
5723 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5725 priv = combo_box->priv;
5727 if (strcmp (title ? title : "",
5728 priv->tearoff_title ? priv->tearoff_title : "") != 0)
5730 g_free (priv->tearoff_title);
5731 priv->tearoff_title = g_strdup (title);
5733 gtk_combo_box_update_title (combo_box);
5735 g_object_notify (G_OBJECT (combo_box), "tearoff-title");
5740 * gtk_combo_box_get_popup_accessible:
5741 * @combo_box: a #GtkComboBox
5743 * Gets the accessible object corresponding to the combo box's popup.
5745 * This function is mostly intended for use by accessibility technologies;
5746 * applications should have little use for it.
5748 * Returns: (transfer none): the accessible object corresponding
5749 * to the combo box's popup.
5754 gtk_combo_box_get_popup_accessible (GtkComboBox *combo_box)
5758 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
5760 if (combo_box->priv->popup_widget)
5762 atk_obj = gtk_widget_get_accessible (combo_box->priv->popup_widget);
5770 * gtk_combo_box_get_row_separator_func:
5771 * @combo_box: a #GtkComboBox
5773 * Returns the current row separator function.
5775 * Return value: the current row separator function.
5779 GtkTreeViewRowSeparatorFunc
5780 gtk_combo_box_get_row_separator_func (GtkComboBox *combo_box)
5782 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
5784 return combo_box->priv->row_separator_func;
5788 * gtk_combo_box_set_row_separator_func:
5789 * @combo_box: a #GtkComboBox
5790 * @func: a #GtkTreeViewRowSeparatorFunc
5791 * @data: (allow-none): user data to pass to @func, or %NULL
5792 * @destroy: (allow-none): destroy notifier for @data, or %NULL
5794 * Sets the row separator function, which is used to determine
5795 * whether a row should be drawn as a separator. If the row separator
5796 * function is %NULL, no separators are drawn. This is the default value.
5801 gtk_combo_box_set_row_separator_func (GtkComboBox *combo_box,
5802 GtkTreeViewRowSeparatorFunc func,
5804 GDestroyNotify destroy)
5806 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5808 if (combo_box->priv->row_separator_destroy)
5809 combo_box->priv->row_separator_destroy (combo_box->priv->row_separator_data);
5811 combo_box->priv->row_separator_func = func;
5812 combo_box->priv->row_separator_data = data;
5813 combo_box->priv->row_separator_destroy = destroy;
5815 if (combo_box->priv->tree_view)
5816 gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (combo_box->priv->tree_view),
5819 gtk_combo_box_relayout (combo_box);
5821 gtk_widget_queue_draw (GTK_WIDGET (combo_box));
5825 * gtk_combo_box_set_button_sensitivity:
5826 * @combo_box: a #GtkComboBox
5827 * @sensitivity: specify the sensitivity of the dropdown button
5829 * Sets whether the dropdown button of the combo box should be
5830 * always sensitive (%GTK_SENSITIVITY_ON), never sensitive (%GTK_SENSITIVITY_OFF)
5831 * or only if there is at least one item to display (%GTK_SENSITIVITY_AUTO).
5836 gtk_combo_box_set_button_sensitivity (GtkComboBox *combo_box,
5837 GtkSensitivityType sensitivity)
5839 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5841 if (combo_box->priv->button_sensitivity != sensitivity)
5843 combo_box->priv->button_sensitivity = sensitivity;
5844 gtk_combo_box_update_sensitivity (combo_box);
5846 g_object_notify (G_OBJECT (combo_box), "button-sensitivity");
5851 * gtk_combo_box_get_button_sensitivity:
5852 * @combo_box: a #GtkComboBox
5854 * Returns whether the combo box sets the dropdown button
5855 * sensitive or not when there are no items in the model.
5857 * Return Value: %GTK_SENSITIVITY_ON if the dropdown button
5858 * is sensitive when the model is empty, %GTK_SENSITIVITY_OFF
5859 * if the button is always insensitive or
5860 * %GTK_SENSITIVITY_AUTO if it is only sensitive as long as
5861 * the model has one item to be selected.
5866 gtk_combo_box_get_button_sensitivity (GtkComboBox *combo_box)
5868 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE);
5870 return combo_box->priv->button_sensitivity;
5875 * gtk_combo_box_set_focus_on_click:
5876 * @combo: a #GtkComboBox
5877 * @focus_on_click: whether the combo box grabs focus when clicked
5880 * Sets whether the combo box will grab focus when it is clicked with
5881 * the mouse. Making mouse clicks not grab focus is useful in places
5882 * like toolbars where you don't want the keyboard focus removed from
5883 * the main area of the application.
5888 gtk_combo_box_set_focus_on_click (GtkComboBox *combo_box,
5889 gboolean focus_on_click)
5891 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5893 focus_on_click = focus_on_click != FALSE;
5895 if (combo_box->priv->focus_on_click != focus_on_click)
5897 combo_box->priv->focus_on_click = focus_on_click;
5899 if (combo_box->priv->button)
5900 gtk_button_set_focus_on_click (GTK_BUTTON (combo_box->priv->button),
5903 g_object_notify (G_OBJECT (combo_box), "focus-on-click");
5908 * gtk_combo_box_get_focus_on_click:
5909 * @combo: a #GtkComboBox
5911 * Returns whether the combo box grabs focus when it is clicked
5912 * with the mouse. See gtk_combo_box_set_focus_on_click().
5914 * Return value: %TRUE if the combo box grabs focus when it is
5915 * clicked with the mouse.
5920 gtk_combo_box_get_focus_on_click (GtkComboBox *combo_box)
5922 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE);
5924 return combo_box->priv->focus_on_click;
5929 gtk_combo_box_buildable_custom_tag_start (GtkBuildable *buildable,
5930 GtkBuilder *builder,
5932 const gchar *tagname,
5933 GMarkupParser *parser,
5936 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
5937 tagname, parser, data))
5940 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
5941 tagname, parser, data);
5945 gtk_combo_box_buildable_custom_tag_end (GtkBuildable *buildable,
5946 GtkBuilder *builder,
5948 const gchar *tagname,
5951 if (strcmp (tagname, "attributes") == 0)
5952 _gtk_cell_layout_buildable_custom_tag_end (buildable, builder, child, tagname,
5955 parent_buildable_iface->custom_tag_end (buildable, builder, child, tagname,
5961 gtk_combo_box_size_request_init (GtkSizeRequestIface *iface)
5963 iface->get_width = gtk_combo_box_get_width;
5964 iface->get_height = gtk_combo_box_get_height;
5965 iface->get_height_for_width = gtk_combo_box_get_height_for_width;
5966 iface->get_width_for_height = gtk_combo_box_get_width_for_height;
5970 gtk_combo_box_remeasure (GtkComboBox *combo_box)
5972 GtkComboBoxPrivate *priv = combo_box->priv;
5977 !gtk_tree_model_get_iter_first (priv->model, &iter))
5980 priv->minimum_width = priv->natural_width = 0;
5982 path = gtk_tree_path_new_from_indices (0, -1);
5986 gint row_min = 0, row_nat = 0;
5988 if (priv->cell_view)
5989 gtk_cell_view_get_desired_width_of_row (GTK_CELL_VIEW (priv->cell_view),
5990 path, &row_min, &row_nat);
5992 priv->minimum_width = MAX (priv->minimum_width, row_min);
5993 priv->natural_width = MAX (priv->natural_width, row_nat);
5995 gtk_tree_path_next (path);
5997 while (gtk_tree_model_iter_next (priv->model, &iter));
5999 gtk_tree_path_free (path);
6004 gtk_combo_box_measure_height_for_width (GtkComboBox *combo_box,
6010 GtkComboBoxPrivate *priv = combo_box->priv;
6013 gint child_min, child_nat;
6015 child = gtk_bin_get_child (GTK_BIN (combo_box));
6017 gtk_size_request_get_height_for_width (GTK_SIZE_REQUEST (child), avail_width,
6018 &child_min, &child_nat);
6021 !gtk_tree_model_get_iter_first (priv->model, &iter))
6024 path = gtk_tree_path_new_from_indices (0, -1);
6028 gint row_min = 0, row_nat = 0;
6030 if (priv->cell_view)
6031 gtk_cell_view_get_desired_height_for_width_of_row (GTK_CELL_VIEW (priv->cell_view),
6033 &row_min, &row_nat);
6035 child_min = MAX (child_min, row_min);
6036 child_nat = MAX (child_nat, row_nat);
6038 gtk_tree_path_next (path);
6040 while (gtk_tree_model_iter_next (priv->model, &iter));
6042 gtk_tree_path_free (path);
6047 *min_height = child_min;
6049 *nat_height = child_nat;
6054 gtk_combo_box_get_width (GtkSizeRequest *widget,
6058 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
6059 GtkComboBoxPrivate *priv = combo_box->priv;
6061 gint focus_width, focus_pad;
6062 gint font_size, arrow_size;
6063 PangoContext *context;
6064 PangoFontMetrics *metrics;
6065 PangoFontDescription *font_desc;
6067 gint minimum_width, natural_width;
6068 gint child_min, child_nat;
6070 child = gtk_bin_get_child (GTK_BIN (widget));
6073 gtk_size_request_get_width (GTK_SIZE_REQUEST (child), &child_min, &child_nat);
6074 gtk_combo_box_remeasure (combo_box);
6076 child_min = MAX (child_min, priv->minimum_width);
6077 child_nat = MAX (child_nat, priv->natural_width);
6079 gtk_widget_style_get (GTK_WIDGET (widget),
6080 "focus-line-width", &focus_width,
6081 "focus-padding", &focus_pad,
6082 "arrow-size", &arrow_size,
6085 font_desc = gtk_widget_get_style (child)->font_desc;
6086 context = gtk_widget_get_pango_context (GTK_WIDGET (widget));
6087 metrics = pango_context_get_metrics (context, font_desc,
6088 pango_context_get_language (context));
6089 font_size = PANGO_PIXELS (pango_font_metrics_get_ascent (metrics) +
6090 pango_font_metrics_get_descent (metrics));
6091 pango_font_metrics_unref (metrics);
6093 arrow_size = MAX (arrow_size, font_size);
6095 gtk_widget_set_size_request (priv->arrow, arrow_size, arrow_size);
6097 if (!priv->tree_view)
6101 if (priv->cell_view)
6103 gint sep_width, arrow_width;
6104 gint border_width, xthickness, xpad;
6106 border_width = gtk_container_get_border_width (GTK_CONTAINER (combo_box));
6107 xthickness = gtk_widget_get_style (priv->button)->xthickness;
6109 gtk_size_request_get_width (GTK_SIZE_REQUEST (priv->separator), &sep_width, NULL);
6110 gtk_size_request_get_width (GTK_SIZE_REQUEST (priv->arrow), &arrow_width, NULL);
6112 xpad = 2*(border_width + xthickness + focus_width + focus_pad);
6114 minimum_width = child_min + sep_width + arrow_width + xpad;
6115 natural_width = child_nat + sep_width + arrow_width + xpad;
6119 gint but_width, but_nat_width;
6121 gtk_size_request_get_width (GTK_SIZE_REQUEST (priv->button),
6122 &but_width, &but_nat_width);
6124 minimum_width = child_min + but_width;
6125 natural_width = child_nat + but_nat_width;
6131 gint button_width, button_nat_width;
6133 /* sample + frame */
6134 minimum_width = child_min;
6135 natural_width = child_nat;
6137 minimum_width += 2 * focus_width;
6138 natural_width += 2 * focus_width;
6140 if (priv->cell_view_frame)
6142 if (priv->has_frame)
6144 gint border_width = gtk_container_get_border_width (GTK_CONTAINER (priv->cell_view_frame));
6145 gint xpad = 2 * (border_width + gtk_widget_get_style (GTK_WIDGET (priv->cell_view_frame))->xthickness);
6147 minimum_width += xpad;
6148 natural_width += xpad;
6153 gtk_size_request_get_width (GTK_SIZE_REQUEST (priv->button),
6154 &button_width, &button_nat_width);
6156 minimum_width += button_width;
6157 natural_width += button_nat_width;
6160 if (GTK_SHADOW_NONE != priv->shadow_type)
6162 style = gtk_widget_get_style (GTK_WIDGET (widget));
6164 minimum_width += 2 * style->xthickness;
6165 natural_width += 2 * style->xthickness;
6169 *minimum_size = minimum_width;
6172 *natural_size = natural_width;
6176 gtk_combo_box_get_height (GtkSizeRequest *widget,
6182 /* Combo box is height-for-width only
6183 * (so we always just reserve enough height for the minimum width) */
6184 GTK_SIZE_REQUEST_GET_IFACE (widget)->get_width (widget, &min_width, NULL);
6185 GTK_SIZE_REQUEST_GET_IFACE (widget)->get_height_for_width (widget, min_width, minimum_size, natural_size);
6189 gtk_combo_box_get_width_for_height (GtkSizeRequest *widget,
6194 /* Combo box is height-for-width only
6195 * (so we assume we always reserved enough height for the minimum width) */
6196 GTK_SIZE_REQUEST_GET_IFACE (widget)->get_width (widget, minimum_size, natural_size);
6201 gtk_combo_box_get_height_for_width (GtkSizeRequest *widget,
6206 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
6207 GtkComboBoxPrivate *priv = combo_box->priv;
6209 gint focus_width, focus_pad;
6210 gint min_height, nat_height;
6213 gtk_widget_style_get (GTK_WIDGET (widget),
6214 "focus-line-width", &focus_width,
6215 "focus-padding", &focus_pad,
6220 if (GTK_SHADOW_NONE != priv->shadow_type)
6221 size -= gtk_widget_get_style (GTK_WIDGET (widget))->xthickness;
6223 if (!priv->tree_view)
6226 if (priv->cell_view)
6228 GtkStyle *button_style;
6229 /* calculate x/y padding and separator/arrow size */
6230 gint sep_width, arrow_width, sep_height, arrow_height;
6231 gint border_width, xthickness, ythickness, xpad, ypad;
6233 border_width = gtk_container_get_border_width (GTK_CONTAINER (combo_box));
6234 button_style = gtk_widget_get_style (priv->button);
6236 xthickness = button_style->xthickness;
6237 ythickness = button_style->ythickness;
6239 gtk_size_request_get_width (GTK_SIZE_REQUEST (priv->separator), &sep_width, NULL);
6240 gtk_size_request_get_width (GTK_SIZE_REQUEST (priv->arrow), &arrow_width, NULL);
6241 gtk_size_request_get_height_for_width (GTK_SIZE_REQUEST (priv->separator),
6242 sep_width, &sep_height, NULL);
6243 gtk_size_request_get_height_for_width (GTK_SIZE_REQUEST (priv->arrow),
6244 arrow_width, &arrow_height, NULL);
6246 xpad = 2*(border_width + xthickness + focus_width + focus_pad);
6247 ypad = 2*(border_width + ythickness + focus_width + focus_pad);
6249 size -= sep_width + arrow_width + xpad;
6251 gtk_combo_box_measure_height_for_width (combo_box, size, &min_height, &nat_height);
6253 arrow_height = MAX (arrow_height, sep_height);
6254 min_height = MAX (min_height, arrow_height);
6255 nat_height = MAX (nat_height, arrow_height);
6262 /* there is a custom child widget inside (no priv->cell_view) */
6263 gint but_width, but_height;
6265 gtk_size_request_get_width (GTK_SIZE_REQUEST (priv->button), &but_width, NULL);
6266 gtk_size_request_get_height_for_width (GTK_SIZE_REQUEST (priv->button),
6267 but_width, &but_height, NULL);
6271 gtk_combo_box_measure_height_for_width (combo_box, size, &min_height, &nat_height);
6273 min_height = MAX (min_height, but_height);
6274 nat_height = MAX (nat_height, but_height);
6280 gint but_width, but_height;
6281 gint xpad = 0, ypad = 0;
6283 gtk_size_request_get_width (GTK_SIZE_REQUEST (priv->button), &but_width, NULL);
6284 gtk_size_request_get_height_for_width (GTK_SIZE_REQUEST (priv->button),
6285 but_width, &but_height, NULL);
6287 if (priv->cell_view_frame && priv->has_frame)
6289 GtkStyle *cell_style;
6292 border_width = gtk_container_get_border_width (GTK_CONTAINER (priv->cell_view_frame));
6293 cell_style = gtk_widget_get_style (GTK_WIDGET (priv->cell_view_frame));
6295 xpad = 2 * (border_width + cell_style->xthickness);
6296 ypad = 2 * (border_width + cell_style->ythickness);
6300 size -= 2 * focus_width;
6303 gtk_combo_box_measure_height_for_width (combo_box, size, &min_height, &nat_height);
6305 min_height = MAX (min_height, but_height);
6306 nat_height = MAX (nat_height, but_height);
6312 if (GTK_SHADOW_NONE != priv->shadow_type)
6314 style = gtk_widget_get_style (GTK_WIDGET (widget));
6316 min_height += 2 * style->ythickness;
6317 nat_height += 2 * style->ythickness;
6321 *minimum_size = min_height;
6324 *natural_size = nat_height;