2 * Copyright (C) 2002, 2003 Kristian Rietveld <kris@gtk.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 #include "gtkcombobox.h"
24 #include "gtkbindings.h"
25 #include "gtkcelllayout.h"
26 #include "gtkcellrenderertext.h"
27 #include "gtkcellview.h"
28 #include "gtkeventbox.h"
31 #include "gtkliststore.h"
34 #include "gtkscrolledwindow.h"
35 #include "gtkseparatormenuitem.h"
36 #include "gtktearoffmenuitem.h"
37 #include "gtktogglebutton.h"
38 #include "gtktreeselection.h"
39 #include "gtkvseparator.h"
40 #include "gtkwindow.h"
41 #include "gtkprivate.h"
42 #include "gtkmarshal.h"
44 #include <gdk/gdkkeysyms.h>
46 #include <gobject/gvaluecollector.h>
51 #include "gtkmarshalers.h"
54 #include "gtktreeprivate.h"
57 /* WELCOME, to THE house of evil code */
59 typedef struct _ComboCellInfo ComboCellInfo;
62 GtkCellRenderer *cell;
65 GtkCellLayoutDataFunc func;
67 GDestroyNotify destroy;
73 #define GTK_COMBO_BOX_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_COMBO_BOX, GtkComboBoxPrivate))
75 struct _GtkComboBoxPrivate
83 GtkShadowType shadow_type;
85 GtkTreeRowReference *active_row;
88 GtkTreeViewColumn *column;
91 GtkWidget *cell_view_frame;
98 GtkWidget *popup_widget;
99 GtkWidget *popup_window;
100 GtkWidget *scrolled_window;
107 guint activate_button;
108 guint32 activate_time;
110 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;
125 GtkTreeViewRowSeparatorFunc row_separator_func;
126 gpointer row_separator_data;
127 GtkDestroyNotify row_separator_destroy;
129 gchar *tearoff_title;
132 /* While debugging this evil code, I have learned that
133 * there are actually 4 modes to this widget, which can
134 * be characterized as follows
136 * 1) menu mode, no child added
139 * cell_view -> GtkCellView, regular child
140 * cell_view_frame -> NULL
141 * button -> GtkToggleButton set_parent to combo
142 * arrow -> GtkArrow set_parent to button
143 * separator -> GtkVSepator set_parent to button
144 * popup_widget -> GtkMenu
145 * popup_window -> NULL
146 * scrolled_window -> NULL
148 * 2) menu mode, child added
152 * cell_view_frame -> NULL
153 * button -> GtkToggleButton set_parent to combo
154 * arrow -> GtkArrow, child of button
156 * popup_widget -> GtkMenu
157 * popup_window -> NULL
158 * scrolled_window -> NULL
160 * 3) list mode, no child added
162 * tree_view -> GtkTreeView, child of scrolled_window
163 * cell_view -> GtkCellView, regular child
164 * cell_view_frame -> GtkFrame, set parent to combo
165 * button -> GtkToggleButton, set_parent to combo
166 * arrow -> GtkArrow, child of button
168 * popup_widget -> tree_view
169 * popup_window -> GtkWindow
170 * scrolled_window -> GtkScrolledWindow, child of popup_window
172 * 4) list mode, child added
174 * tree_view -> GtkTreeView, child of scrolled_window
176 * cell_view_frame -> NULL
177 * button -> GtkToggleButton, set_parent to combo
178 * arrow -> GtkArrow, child of button
180 * popup_widget -> tree_view
181 * popup_window -> GtkWindow
182 * scrolled_window -> GtkScrolledWindow, child of popup_window
198 PROP_ROW_SPAN_COLUMN,
199 PROP_COLUMN_SPAN_COLUMN,
208 static guint combo_box_signals[LAST_SIGNAL] = {0,};
210 #define BONUS_PADDING 4
211 #define SCROLL_TIME 100
215 static void gtk_combo_box_cell_layout_init (GtkCellLayoutIface *iface);
216 static void gtk_combo_box_cell_editable_init (GtkCellEditableIface *iface);
217 static void gtk_combo_box_dispose (GObject *object);
218 static void gtk_combo_box_finalize (GObject *object);
219 static void gtk_combo_box_destroy (GtkObject *object);
221 static void gtk_combo_box_set_property (GObject *object,
225 static void gtk_combo_box_get_property (GObject *object,
230 static void gtk_combo_box_state_changed (GtkWidget *widget,
231 GtkStateType previous);
232 static void gtk_combo_box_grab_focus (GtkWidget *widget);
233 static void gtk_combo_box_style_set (GtkWidget *widget,
235 static void gtk_combo_box_button_toggled (GtkWidget *widget,
237 static void gtk_combo_box_button_state_changed (GtkWidget *widget,
238 GtkStateType previous,
240 static void gtk_combo_box_add (GtkContainer *container,
242 static void gtk_combo_box_remove (GtkContainer *container,
245 static ComboCellInfo *gtk_combo_box_get_cell_info (GtkComboBox *combo_box,
246 GtkCellRenderer *cell);
248 static void gtk_combo_box_menu_show (GtkWidget *menu,
250 static void gtk_combo_box_menu_hide (GtkWidget *menu,
253 static void gtk_combo_box_set_popup_widget (GtkComboBox *combo_box,
255 static void gtk_combo_box_menu_position_below (GtkMenu *menu,
260 static void gtk_combo_box_menu_position_over (GtkMenu *menu,
265 static void gtk_combo_box_menu_position (GtkMenu *menu,
271 static gint gtk_combo_box_calc_requested_width (GtkComboBox *combo_box,
273 static void gtk_combo_box_remeasure (GtkComboBox *combo_box);
275 static void gtk_combo_box_unset_model (GtkComboBox *combo_box);
277 static void gtk_combo_box_size_request (GtkWidget *widget,
278 GtkRequisition *requisition);
279 static void gtk_combo_box_size_allocate (GtkWidget *widget,
280 GtkAllocation *allocation);
281 static void gtk_combo_box_forall (GtkContainer *container,
282 gboolean include_internals,
283 GtkCallback callback,
284 gpointer callback_data);
285 static gboolean gtk_combo_box_expose_event (GtkWidget *widget,
286 GdkEventExpose *event);
287 static gboolean gtk_combo_box_scroll_event (GtkWidget *widget,
288 GdkEventScroll *event);
289 static void gtk_combo_box_set_active_internal (GtkComboBox *combo_box,
292 static void gtk_combo_box_check_appearance (GtkComboBox *combo_box);
293 static gchar * gtk_combo_box_real_get_active_text (GtkComboBox *combo_box);
294 static void gtk_combo_box_real_move_active (GtkComboBox *combo_box,
295 GtkScrollType scroll);
296 static void gtk_combo_box_real_popup (GtkComboBox *combo_box);
297 static gboolean gtk_combo_box_real_popdown (GtkComboBox *combo_box);
299 /* listening to the model */
300 static void gtk_combo_box_model_row_inserted (GtkTreeModel *model,
304 static void gtk_combo_box_model_row_deleted (GtkTreeModel *model,
307 static void gtk_combo_box_model_rows_reordered (GtkTreeModel *model,
312 static void gtk_combo_box_model_row_changed (GtkTreeModel *model,
316 static void gtk_combo_box_model_row_expanded (GtkTreeModel *model,
322 static void gtk_combo_box_list_position (GtkComboBox *combo_box,
327 static void gtk_combo_box_list_setup (GtkComboBox *combo_box);
328 static void gtk_combo_box_list_destroy (GtkComboBox *combo_box);
330 static gboolean gtk_combo_box_list_button_released (GtkWidget *widget,
331 GdkEventButton *event,
333 static gboolean gtk_combo_box_list_key_press (GtkWidget *widget,
336 static gboolean gtk_combo_box_list_enter_notify (GtkWidget *widget,
337 GdkEventCrossing *event,
339 static void gtk_combo_box_list_auto_scroll (GtkComboBox *combo,
342 static gboolean gtk_combo_box_list_scroll_timeout (GtkComboBox *combo);
343 static gboolean gtk_combo_box_list_button_pressed (GtkWidget *widget,
344 GdkEventButton *event,
347 static gboolean gtk_combo_box_list_select_func (GtkTreeSelection *selection,
350 gboolean path_currently_selected,
353 static void gtk_combo_box_list_row_changed (GtkTreeModel *model,
357 static void gtk_combo_box_list_popup_resize (GtkComboBox *combo_box);
360 static void gtk_combo_box_menu_setup (GtkComboBox *combo_box,
361 gboolean add_children);
362 static void gtk_combo_box_menu_fill (GtkComboBox *combo_box);
363 static void gtk_combo_box_menu_fill_level (GtkComboBox *combo_box,
366 static void gtk_combo_box_update_title (GtkComboBox *combo_box);
367 static void gtk_combo_box_menu_destroy (GtkComboBox *combo_box);
369 static void gtk_combo_box_relayout_item (GtkComboBox *combo_box,
373 static void gtk_combo_box_relayout (GtkComboBox *combo_box);
375 static gboolean gtk_combo_box_menu_button_press (GtkWidget *widget,
376 GdkEventButton *event,
378 static void gtk_combo_box_menu_item_activate (GtkWidget *item,
380 static void gtk_combo_box_menu_row_inserted (GtkTreeModel *model,
384 static void gtk_combo_box_menu_row_deleted (GtkTreeModel *model,
387 static void gtk_combo_box_menu_rows_reordered (GtkTreeModel *model,
392 static void gtk_combo_box_menu_row_changed (GtkTreeModel *model,
396 static gboolean gtk_combo_box_menu_key_press (GtkWidget *widget,
399 static void gtk_combo_box_menu_popup (GtkComboBox *combo_box,
401 guint32 activate_time);
402 static GtkWidget *gtk_cell_view_menu_item_new (GtkComboBox *combo_box,
407 static void gtk_combo_box_cell_layout_pack_start (GtkCellLayout *layout,
408 GtkCellRenderer *cell,
410 static void gtk_combo_box_cell_layout_pack_end (GtkCellLayout *layout,
411 GtkCellRenderer *cell,
413 static GList *gtk_combo_box_cell_layout_get_cells (GtkCellLayout *layout);
414 static void gtk_combo_box_cell_layout_clear (GtkCellLayout *layout);
415 static void gtk_combo_box_cell_layout_add_attribute (GtkCellLayout *layout,
416 GtkCellRenderer *cell,
417 const gchar *attribute,
419 static void gtk_combo_box_cell_layout_set_cell_data_func (GtkCellLayout *layout,
420 GtkCellRenderer *cell,
421 GtkCellLayoutDataFunc func,
423 GDestroyNotify destroy);
424 static void gtk_combo_box_cell_layout_clear_attributes (GtkCellLayout *layout,
425 GtkCellRenderer *cell);
426 static void gtk_combo_box_cell_layout_reorder (GtkCellLayout *layout,
427 GtkCellRenderer *cell,
429 static gboolean gtk_combo_box_mnemonic_activate (GtkWidget *widget,
430 gboolean group_cycling);
432 static void gtk_combo_box_sync_cells (GtkComboBox *combo_box,
433 GtkCellLayout *cell_layout);
434 static void combo_cell_data_func (GtkCellLayout *cell_layout,
435 GtkCellRenderer *cell,
436 GtkTreeModel *tree_model,
439 static void gtk_combo_box_child_show (GtkWidget *widget,
440 GtkComboBox *combo_box);
441 static void gtk_combo_box_child_hide (GtkWidget *widget,
442 GtkComboBox *combo_box);
444 /* GtkBuildable method implementation */
445 static GtkBuildableIface *parent_buildable_iface;
447 static void gtk_combo_box_buildable_init (GtkBuildableIface *iface);
448 static gboolean gtk_combo_box_buildable_custom_tag_start (GtkBuildable *buildable,
451 const gchar *tagname,
452 GMarkupParser *parser,
454 static void gtk_combo_box_buildable_custom_tag_end (GtkBuildable *buildable,
457 const gchar *tagname,
460 /* GtkCellEditable method implementations */
461 static void gtk_combo_box_start_editing (GtkCellEditable *cell_editable,
465 G_DEFINE_TYPE_WITH_CODE (GtkComboBox, gtk_combo_box, GTK_TYPE_BIN,
466 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
467 gtk_combo_box_cell_layout_init)
468 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
469 gtk_combo_box_cell_editable_init)
470 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
471 gtk_combo_box_buildable_init))
476 gtk_combo_box_class_init (GtkComboBoxClass *klass)
478 GObjectClass *object_class;
479 GtkObjectClass *gtk_object_class;
480 GtkContainerClass *container_class;
481 GtkWidgetClass *widget_class;
482 GtkBindingSet *binding_set;
484 klass->get_active_text = gtk_combo_box_real_get_active_text;
486 container_class = (GtkContainerClass *)klass;
487 container_class->forall = gtk_combo_box_forall;
488 container_class->add = gtk_combo_box_add;
489 container_class->remove = gtk_combo_box_remove;
491 widget_class = (GtkWidgetClass *)klass;
492 widget_class->size_allocate = gtk_combo_box_size_allocate;
493 widget_class->size_request = gtk_combo_box_size_request;
494 widget_class->expose_event = gtk_combo_box_expose_event;
495 widget_class->scroll_event = gtk_combo_box_scroll_event;
496 widget_class->mnemonic_activate = gtk_combo_box_mnemonic_activate;
497 widget_class->grab_focus = gtk_combo_box_grab_focus;
498 widget_class->style_set = gtk_combo_box_style_set;
499 widget_class->state_changed = gtk_combo_box_state_changed;
501 gtk_object_class = (GtkObjectClass *)klass;
502 gtk_object_class->destroy = gtk_combo_box_destroy;
504 object_class = (GObjectClass *)klass;
505 object_class->dispose = gtk_combo_box_dispose;
506 object_class->finalize = gtk_combo_box_finalize;
507 object_class->set_property = gtk_combo_box_set_property;
508 object_class->get_property = gtk_combo_box_get_property;
512 * GtkComboBox::changed:
513 * @widget: the object which received the signal
515 * The changed signal is emitted when the active
516 * item is changed. The can be due to the user selecting
517 * a different item from the list, or due to a
518 * call to gtk_combo_box_set_active_iter().
519 * It will also be emitted while typing into a GtkComboBoxEntry,
520 * as well as when selecting an item from the GtkComboBoxEntry's list.
524 combo_box_signals[CHANGED] =
525 g_signal_new (I_("changed"),
526 G_OBJECT_CLASS_TYPE (klass),
528 G_STRUCT_OFFSET (GtkComboBoxClass, changed),
530 g_cclosure_marshal_VOID__VOID,
533 * GtkComboBox::move-active:
534 * @widget: the object that received the signal
535 * @scroll_type: a #GtkScrollType
537 * The ::move-active signal is a
538 * <link linkend="keybinding-signals">keybinding signal</link>
539 * which gets emitted to move the active selection.
543 combo_box_signals[MOVE_ACTIVE] =
544 _gtk_binding_signal_new (I_("move-active"),
545 G_OBJECT_CLASS_TYPE (klass),
546 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
547 G_CALLBACK (gtk_combo_box_real_move_active),
549 g_cclosure_marshal_VOID__ENUM,
551 GTK_TYPE_SCROLL_TYPE);
554 * GtkComboBox::popup:
555 * @widget: the object that received the signal
557 * The ::popup signal is a
558 * <link linkend="keybinding-signals">keybinding signal</link>
559 * which gets emitted to popup the combo box list.
561 * The default binding for this signal is Alt+Down.
565 combo_box_signals[POPUP] =
566 _gtk_binding_signal_new (I_("popup"),
567 G_OBJECT_CLASS_TYPE (klass),
568 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
569 G_CALLBACK (gtk_combo_box_real_popup),
571 g_cclosure_marshal_VOID__VOID,
574 * GtkComboBox::popdown:
575 * @button: the object which received the signal
577 * The ::popdown signal is a
578 * <link linkend="keybinding-signals">keybinding signal</link>
579 * which gets emitted to popdown the combo box list.
581 * The default bindings for this signal are Alt+Up and Escape.
585 combo_box_signals[POPDOWN] =
586 _gtk_binding_signal_new (I_("popdown"),
587 G_OBJECT_CLASS_TYPE (klass),
588 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
589 G_CALLBACK (gtk_combo_box_real_popdown),
591 gtk_marshal_BOOLEAN__VOID,
595 binding_set = gtk_binding_set_by_class (widget_class);
597 gtk_binding_entry_add_signal (binding_set, GDK_Down, GDK_MOD1_MASK,
599 gtk_binding_entry_add_signal (binding_set, GDK_KP_Down, GDK_MOD1_MASK,
602 gtk_binding_entry_add_signal (binding_set, GDK_Up, GDK_MOD1_MASK,
604 gtk_binding_entry_add_signal (binding_set, GDK_KP_Up, GDK_MOD1_MASK,
606 gtk_binding_entry_add_signal (binding_set, GDK_Escape, 0,
609 gtk_binding_entry_add_signal (binding_set, GDK_Up, 0,
611 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_UP);
612 gtk_binding_entry_add_signal (binding_set, GDK_KP_Up, 0,
614 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_UP);
615 gtk_binding_entry_add_signal (binding_set, GDK_Page_Up, 0,
617 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_PAGE_UP);
618 gtk_binding_entry_add_signal (binding_set, GDK_KP_Page_Up, 0,
620 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_PAGE_UP);
621 gtk_binding_entry_add_signal (binding_set, GDK_Home, 0,
623 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_START);
624 gtk_binding_entry_add_signal (binding_set, GDK_KP_Home, 0,
626 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_START);
628 gtk_binding_entry_add_signal (binding_set, GDK_Down, 0,
630 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_DOWN);
631 gtk_binding_entry_add_signal (binding_set, GDK_KP_Down, 0,
633 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_DOWN);
634 gtk_binding_entry_add_signal (binding_set, GDK_Page_Down, 0,
636 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_PAGE_DOWN);
637 gtk_binding_entry_add_signal (binding_set, GDK_KP_Page_Down, 0,
639 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_PAGE_DOWN);
640 gtk_binding_entry_add_signal (binding_set, GDK_End, 0,
642 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_END);
643 gtk_binding_entry_add_signal (binding_set, GDK_KP_End, 0,
645 GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_END);
651 * The model from which the combo box takes the values shown
656 g_object_class_install_property (object_class,
658 g_param_spec_object ("model",
659 P_("ComboBox model"),
660 P_("The model for the combo box"),
662 GTK_PARAM_READWRITE));
665 * GtkComboBox:wrap-width:
667 * If wrap-width is set to a positive value, the list will be
668 * displayed in multiple columns, the number of columns is
669 * determined by wrap-width.
673 g_object_class_install_property (object_class,
675 g_param_spec_int ("wrap-width",
677 P_("Wrap width for laying out the items in a grid"),
681 GTK_PARAM_READWRITE));
685 * GtkComboBox:row-span-column:
687 * If this is set to a non-negative value, it must be the index of a column
688 * of type %G_TYPE_INT in the model.
690 * The values of that column are used to determine how many rows a value in
691 * the list will span. Therefore, the values in the model column pointed to
692 * by this property must be greater than zero and not larger than wrap-width.
696 g_object_class_install_property (object_class,
697 PROP_ROW_SPAN_COLUMN,
698 g_param_spec_int ("row-span-column",
699 P_("Row span column"),
700 P_("TreeModel column containing the row span values"),
704 GTK_PARAM_READWRITE));
708 * GtkComboBox:column-span-column:
710 * If this is set to a non-negative value, it must be the index of a column
711 * of type %G_TYPE_INT in the model.
713 * The values of that column are used to determine how many columns a value
714 * in the list will span.
718 g_object_class_install_property (object_class,
719 PROP_COLUMN_SPAN_COLUMN,
720 g_param_spec_int ("column-span-column",
721 P_("Column span column"),
722 P_("TreeModel column containing the column span values"),
726 GTK_PARAM_READWRITE));
730 * GtkComboBox:active:
732 * The item which is currently active. If the model is a non-flat treemodel,
733 * and the active item is not an immediate child of the root of the tree,
734 * this property has the value
735 * <literal>gtk_tree_path_get_indices (path)[0]</literal>,
736 * where <literal>path</literal> is the #GtkTreePath of the active item.
740 g_object_class_install_property (object_class,
742 g_param_spec_int ("active",
744 P_("The item which is currently active"),
748 GTK_PARAM_READWRITE));
751 * GtkComboBox:add-tearoffs:
753 * The add-tearoffs property controls whether generated menus
754 * have tearoff menu items.
756 * Note that this only affects menu style combo boxes.
760 g_object_class_install_property (object_class,
762 g_param_spec_boolean ("add-tearoffs",
763 P_("Add tearoffs to menus"),
764 P_("Whether dropdowns should have a tearoff menu item"),
766 GTK_PARAM_READWRITE));
769 * GtkComboBox:has-frame:
771 * The has-frame property controls whether a frame
772 * is drawn around the entry.
776 g_object_class_install_property (object_class,
778 g_param_spec_boolean ("has-frame",
780 P_("Whether the combo box draws a frame around the child"),
782 GTK_PARAM_READWRITE));
784 g_object_class_install_property (object_class,
786 g_param_spec_boolean ("focus-on-click",
787 P_("Focus on click"),
788 P_("Whether the combo box grabs focus when it is clicked with the mouse"),
790 GTK_PARAM_READWRITE));
793 * GtkComboBox:tearoff-title:
795 * A title that may be displayed by the window manager
796 * when the popup is torn-off.
800 g_object_class_install_property (object_class,
802 g_param_spec_string ("tearoff-title",
804 P_("A title that may be displayed by the window manager when the popup is torn-off"),
806 GTK_PARAM_READWRITE));
810 * GtkComboBox:popup-shown:
812 * Whether the combo boxes dropdown is popped up.
813 * Note that this property is mainly useful, because
814 * it allows you to connect to notify::popup-shown.
818 g_object_class_install_property (object_class,
820 g_param_spec_boolean ("popup-shown",
822 P_("Whether the combo's dropdown is shown"),
824 GTK_PARAM_READABLE));
826 gtk_widget_class_install_style_property (widget_class,
827 g_param_spec_boolean ("appears-as-list",
828 P_("Appears as list"),
829 P_("Whether dropdowns should look like lists rather than menus"),
831 GTK_PARAM_READABLE));
834 * GtkComboBox:arrow-size:
836 * Sets the minimum size of the arrow in the combo box. Note
837 * that the arrow size is coupled to the font size, so in case
838 * a larger font is used, the arrow will be larger than set
843 gtk_widget_class_install_style_property (widget_class,
844 g_param_spec_int ("arrow-size",
846 P_("The minimum size of the arrow in the combo box"),
850 GTK_PARAM_READABLE));
853 * GtkComboBox:shadow-type:
855 * Which kind of shadow to draw around the combo box.
859 gtk_widget_class_install_style_property (widget_class,
860 g_param_spec_enum ("shadow-type",
862 P_("Which kind of shadow to draw around the combo box"),
863 GTK_TYPE_SHADOW_TYPE,
865 GTK_PARAM_READABLE));
867 g_type_class_add_private (object_class, sizeof (GtkComboBoxPrivate));
871 gtk_combo_box_buildable_init (GtkBuildableIface *iface)
873 parent_buildable_iface = g_type_interface_peek_parent (iface);
874 iface->add_child = _gtk_cell_layout_buildable_add_child;
875 iface->custom_tag_start = gtk_combo_box_buildable_custom_tag_start;
876 iface->custom_tag_end = gtk_combo_box_buildable_custom_tag_end;
880 gtk_combo_box_cell_layout_init (GtkCellLayoutIface *iface)
882 iface->pack_start = gtk_combo_box_cell_layout_pack_start;
883 iface->pack_end = gtk_combo_box_cell_layout_pack_end;
884 iface->get_cells = gtk_combo_box_cell_layout_get_cells;
885 iface->clear = gtk_combo_box_cell_layout_clear;
886 iface->add_attribute = gtk_combo_box_cell_layout_add_attribute;
887 iface->set_cell_data_func = gtk_combo_box_cell_layout_set_cell_data_func;
888 iface->clear_attributes = gtk_combo_box_cell_layout_clear_attributes;
889 iface->reorder = gtk_combo_box_cell_layout_reorder;
893 gtk_combo_box_cell_editable_init (GtkCellEditableIface *iface)
895 iface->start_editing = gtk_combo_box_start_editing;
899 gtk_combo_box_init (GtkComboBox *combo_box)
901 GtkComboBoxPrivate *priv = GTK_COMBO_BOX_GET_PRIVATE (combo_box);
903 priv->cell_view = gtk_cell_view_new ();
904 gtk_widget_set_parent (priv->cell_view, GTK_WIDGET (combo_box));
905 GTK_BIN (combo_box)->child = priv->cell_view;
906 gtk_widget_show (priv->cell_view);
910 priv->wrap_width = 0;
912 priv->active_row = NULL;
913 priv->col_column = -1;
914 priv->row_column = -1;
916 priv->popup_shown = FALSE;
917 priv->add_tearoffs = FALSE;
918 priv->has_frame = TRUE;
919 priv->is_cell_renderer = FALSE;
920 priv->editing_canceled = FALSE;
921 priv->auto_scroll = FALSE;
922 priv->focus_on_click = TRUE;
924 combo_box->priv = priv;
926 gtk_combo_box_check_appearance (combo_box);
930 gtk_combo_box_set_property (GObject *object,
935 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
940 gtk_combo_box_set_model (combo_box, g_value_get_object (value));
943 case PROP_WRAP_WIDTH:
944 gtk_combo_box_set_wrap_width (combo_box, g_value_get_int (value));
947 case PROP_ROW_SPAN_COLUMN:
948 gtk_combo_box_set_row_span_column (combo_box, g_value_get_int (value));
951 case PROP_COLUMN_SPAN_COLUMN:
952 gtk_combo_box_set_column_span_column (combo_box, g_value_get_int (value));
956 gtk_combo_box_set_active (combo_box, g_value_get_int (value));
959 case PROP_ADD_TEAROFFS:
960 gtk_combo_box_set_add_tearoffs (combo_box, g_value_get_boolean (value));
964 combo_box->priv->has_frame = g_value_get_boolean (value);
967 case PROP_FOCUS_ON_CLICK:
968 gtk_combo_box_set_focus_on_click (combo_box,
969 g_value_get_boolean (value));
972 case PROP_TEAROFF_TITLE:
973 gtk_combo_box_set_title (combo_box, g_value_get_string (value));
976 case PROP_POPUP_SHOWN:
977 if (g_value_get_boolean (value))
978 gtk_combo_box_popup (combo_box);
980 gtk_combo_box_popdown (combo_box);
984 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
990 gtk_combo_box_get_property (GObject *object,
995 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
1000 g_value_set_object (value, combo_box->priv->model);
1003 case PROP_WRAP_WIDTH:
1004 g_value_set_int (value, combo_box->priv->wrap_width);
1007 case PROP_ROW_SPAN_COLUMN:
1008 g_value_set_int (value, combo_box->priv->row_column);
1011 case PROP_COLUMN_SPAN_COLUMN:
1012 g_value_set_int (value, combo_box->priv->col_column);
1016 g_value_set_int (value, gtk_combo_box_get_active (combo_box));
1019 case PROP_ADD_TEAROFFS:
1020 g_value_set_boolean (value, gtk_combo_box_get_add_tearoffs (combo_box));
1023 case PROP_HAS_FRAME:
1024 g_value_set_boolean (value, combo_box->priv->has_frame);
1027 case PROP_FOCUS_ON_CLICK:
1028 g_value_set_boolean (value, combo_box->priv->focus_on_click);
1031 case PROP_TEAROFF_TITLE:
1032 g_value_set_string (value, gtk_combo_box_get_title (combo_box));
1035 case PROP_POPUP_SHOWN:
1036 g_value_set_boolean (value, combo_box->priv->popup_shown);
1040 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1046 gtk_combo_box_state_changed (GtkWidget *widget,
1047 GtkStateType previous)
1049 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
1050 GtkComboBoxPrivate *priv = combo_box->priv;
1052 if (GTK_WIDGET_REALIZED (widget))
1054 if (priv->tree_view && priv->cell_view)
1055 gtk_cell_view_set_background_color (GTK_CELL_VIEW (priv->cell_view),
1056 &widget->style->base[GTK_WIDGET_STATE (widget)]);
1059 gtk_widget_queue_draw (widget);
1063 gtk_combo_box_button_state_changed (GtkWidget *widget,
1064 GtkStateType previous,
1067 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
1068 GtkComboBoxPrivate *priv = combo_box->priv;
1070 if (GTK_WIDGET_REALIZED (widget))
1072 if (!priv->tree_view && priv->cell_view)
1074 if ((GTK_WIDGET_STATE (widget) == GTK_STATE_INSENSITIVE) !=
1075 (GTK_WIDGET_STATE (priv->cell_view) == GTK_STATE_INSENSITIVE))
1076 gtk_widget_set_sensitive (priv->cell_view, GTK_WIDGET_SENSITIVE (widget));
1078 gtk_widget_set_state (priv->cell_view,
1079 GTK_WIDGET_STATE (widget));
1083 gtk_widget_queue_draw (widget);
1087 gtk_combo_box_check_appearance (GtkComboBox *combo_box)
1089 GtkComboBoxPrivate *priv = combo_box->priv;
1090 gboolean appears_as_list;
1092 /* if wrap_width > 0, then we are in grid-mode and forced to use
1095 if (priv->wrap_width)
1096 appears_as_list = FALSE;
1098 gtk_widget_style_get (GTK_WIDGET (combo_box),
1099 "appears-as-list", &appears_as_list,
1102 if (appears_as_list)
1104 /* Destroy all the menu mode widgets, if they exist. */
1105 if (GTK_IS_MENU (priv->popup_widget))
1106 gtk_combo_box_menu_destroy (combo_box);
1108 /* Create the list mode widgets, if they don't already exist. */
1109 if (!GTK_IS_TREE_VIEW (priv->tree_view))
1110 gtk_combo_box_list_setup (combo_box);
1114 /* Destroy all the list mode widgets, if they exist. */
1115 if (GTK_IS_TREE_VIEW (priv->tree_view))
1116 gtk_combo_box_list_destroy (combo_box);
1118 /* Create the menu mode widgets, if they don't already exist. */
1119 if (!GTK_IS_MENU (priv->popup_widget))
1120 gtk_combo_box_menu_setup (combo_box, TRUE);
1123 gtk_widget_style_get (GTK_WIDGET (combo_box),
1124 "shadow-type", &priv->shadow_type,
1129 gtk_combo_box_style_set (GtkWidget *widget,
1132 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
1133 GtkComboBoxPrivate *priv = combo_box->priv;
1135 gtk_combo_box_check_appearance (combo_box);
1137 if (priv->tree_view && priv->cell_view)
1138 gtk_cell_view_set_background_color (GTK_CELL_VIEW (priv->cell_view),
1139 &widget->style->base[GTK_WIDGET_STATE (widget)]);
1141 if (GTK_IS_ENTRY (GTK_BIN (combo_box)->child))
1142 g_object_set (GTK_BIN (combo_box)->child, "shadow-type",
1143 GTK_SHADOW_NONE == priv->shadow_type ?
1144 GTK_SHADOW_IN : GTK_SHADOW_NONE, NULL);
1148 gtk_combo_box_button_toggled (GtkWidget *widget,
1151 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
1153 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
1155 if (!combo_box->priv->popup_in_progress)
1156 gtk_combo_box_popup (combo_box);
1159 gtk_combo_box_popdown (combo_box);
1163 gtk_combo_box_add (GtkContainer *container,
1166 GtkComboBox *combo_box = GTK_COMBO_BOX (container);
1167 GtkComboBoxPrivate *priv = combo_box->priv;
1169 if (priv->cell_view && priv->cell_view->parent)
1171 gtk_widget_unparent (priv->cell_view);
1172 GTK_BIN (container)->child = NULL;
1173 gtk_widget_queue_resize (GTK_WIDGET (container));
1176 gtk_widget_set_parent (widget, GTK_WIDGET (container));
1177 GTK_BIN (container)->child = widget;
1179 if (priv->cell_view &&
1180 widget != priv->cell_view)
1182 /* since the cell_view was unparented, it's gone now */
1183 priv->cell_view = NULL;
1185 if (!priv->tree_view && priv->separator)
1187 gtk_container_remove (GTK_CONTAINER (priv->separator->parent),
1189 priv->separator = NULL;
1191 gtk_widget_queue_resize (GTK_WIDGET (container));
1193 else if (priv->cell_view_frame)
1195 gtk_widget_unparent (priv->cell_view_frame);
1196 priv->cell_view_frame = NULL;
1203 gtk_combo_box_remove (GtkContainer *container,
1206 GtkComboBox *combo_box = GTK_COMBO_BOX (container);
1207 GtkComboBoxPrivate *priv = combo_box->priv;
1209 gboolean appears_as_list;
1211 if (widget == priv->cell_view)
1212 priv->cell_view = NULL;
1214 gtk_widget_unparent (widget);
1215 GTK_BIN (container)->child = NULL;
1217 if (GTK_OBJECT_FLAGS (combo_box) & GTK_IN_DESTRUCTION)
1220 gtk_widget_queue_resize (GTK_WIDGET (container));
1222 if (!priv->tree_view)
1223 appears_as_list = FALSE;
1225 appears_as_list = TRUE;
1227 if (appears_as_list)
1228 gtk_combo_box_list_destroy (combo_box);
1229 else if (GTK_IS_MENU (priv->popup_widget))
1231 gtk_combo_box_menu_destroy (combo_box);
1232 gtk_menu_detach (GTK_MENU (priv->popup_widget));
1233 priv->popup_widget = NULL;
1236 if (!priv->cell_view)
1238 priv->cell_view = gtk_cell_view_new ();
1239 gtk_widget_set_parent (priv->cell_view, GTK_WIDGET (container));
1240 GTK_BIN (container)->child = priv->cell_view;
1242 gtk_widget_show (priv->cell_view);
1243 gtk_cell_view_set_model (GTK_CELL_VIEW (priv->cell_view),
1245 gtk_combo_box_sync_cells (combo_box, GTK_CELL_LAYOUT (priv->cell_view));
1249 if (appears_as_list)
1250 gtk_combo_box_list_setup (combo_box);
1252 gtk_combo_box_menu_setup (combo_box, TRUE);
1254 if (gtk_tree_row_reference_valid (priv->active_row))
1256 path = gtk_tree_row_reference_get_path (priv->active_row);
1257 gtk_combo_box_set_active_internal (combo_box, path);
1258 gtk_tree_path_free (path);
1261 gtk_combo_box_set_active_internal (combo_box, NULL);
1264 static ComboCellInfo *
1265 gtk_combo_box_get_cell_info (GtkComboBox *combo_box,
1266 GtkCellRenderer *cell)
1270 for (i = combo_box->priv->cells; i; i = i->next)
1272 ComboCellInfo *info = (ComboCellInfo *)i->data;
1274 if (info && info->cell == cell)
1282 gtk_combo_box_menu_show (GtkWidget *menu,
1285 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
1286 GtkComboBoxPrivate *priv = combo_box->priv;
1288 gtk_combo_box_child_show (menu, user_data);
1290 priv->popup_in_progress = TRUE;
1291 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->button),
1293 priv->popup_in_progress = FALSE;
1297 gtk_combo_box_menu_hide (GtkWidget *menu,
1300 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
1302 gtk_combo_box_child_hide (menu,user_data);
1304 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
1309 gtk_combo_box_detacher (GtkWidget *widget,
1312 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
1313 GtkComboBoxPrivate *priv = combo_box->priv;
1315 g_return_if_fail (priv->popup_widget == (GtkWidget *) menu);
1317 g_signal_handlers_disconnect_by_func (menu->toplevel,
1318 gtk_combo_box_menu_show,
1320 g_signal_handlers_disconnect_by_func (menu->toplevel,
1321 gtk_combo_box_menu_hide,
1324 priv->popup_widget = NULL;
1328 gtk_combo_box_set_popup_widget (GtkComboBox *combo_box,
1331 GtkComboBoxPrivate *priv = combo_box->priv;
1333 if (GTK_IS_MENU (priv->popup_widget))
1335 gtk_menu_detach (GTK_MENU (priv->popup_widget));
1336 priv->popup_widget = NULL;
1338 else if (priv->popup_widget)
1340 gtk_container_remove (GTK_CONTAINER (priv->scrolled_window),
1341 priv->popup_widget);
1342 g_object_unref (priv->popup_widget);
1343 priv->popup_widget = NULL;
1346 if (GTK_IS_MENU (popup))
1348 if (priv->popup_window)
1350 gtk_widget_destroy (priv->popup_window);
1351 priv->popup_window = NULL;
1354 priv->popup_widget = popup;
1357 * Note that we connect to show/hide on the toplevel, not the
1358 * menu itself, since the menu is not shown/hidden when it is
1359 * popped up while torn-off.
1361 g_signal_connect (GTK_MENU (popup)->toplevel, "show",
1362 G_CALLBACK (gtk_combo_box_menu_show), combo_box);
1363 g_signal_connect (GTK_MENU (popup)->toplevel, "hide",
1364 G_CALLBACK (gtk_combo_box_menu_hide), combo_box);
1366 gtk_menu_attach_to_widget (GTK_MENU (popup),
1367 GTK_WIDGET (combo_box),
1368 gtk_combo_box_detacher);
1372 if (!priv->popup_window)
1374 GtkWidget *toplevel;
1376 priv->popup_window = gtk_window_new (GTK_WINDOW_POPUP);
1377 gtk_widget_set_name (priv->popup_window, "gtk-combobox-popup-window");
1379 gtk_window_set_type_hint (GTK_WINDOW (priv->popup_window),
1380 GDK_WINDOW_TYPE_HINT_COMBO);
1382 g_signal_connect (GTK_WINDOW (priv->popup_window),"show",
1383 G_CALLBACK (gtk_combo_box_child_show),
1385 g_signal_connect (GTK_WINDOW (priv->popup_window),"hide",
1386 G_CALLBACK (gtk_combo_box_child_hide),
1389 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (combo_box));
1390 if (GTK_IS_WINDOW (toplevel))
1392 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
1393 GTK_WINDOW (priv->popup_window));
1394 gtk_window_set_transient_for (GTK_WINDOW (priv->popup_window),
1395 GTK_WINDOW (toplevel));
1398 gtk_window_set_resizable (GTK_WINDOW (priv->popup_window), FALSE);
1399 gtk_window_set_screen (GTK_WINDOW (priv->popup_window),
1400 gtk_widget_get_screen (GTK_WIDGET (combo_box)));
1402 priv->scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1404 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
1407 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (priv->scrolled_window),
1410 gtk_widget_show (priv->scrolled_window);
1412 gtk_container_add (GTK_CONTAINER (priv->popup_window),
1413 priv->scrolled_window);
1416 gtk_container_add (GTK_CONTAINER (priv->scrolled_window),
1419 gtk_widget_show (popup);
1420 g_object_ref (popup);
1421 priv->popup_widget = popup;
1426 gtk_combo_box_menu_position_below (GtkMenu *menu,
1432 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
1438 GdkRectangle monitor;
1440 /* FIXME: is using the size request here broken? */
1441 child = GTK_BIN (combo_box)->child;
1443 gdk_window_get_origin (child->window, &sx, &sy);
1445 if (GTK_WIDGET_NO_WINDOW (child))
1447 sx += child->allocation.x;
1448 sy += child->allocation.y;
1451 if (GTK_SHADOW_NONE != combo_box->priv->shadow_type)
1452 sx -= GTK_WIDGET (combo_box)->style->xthickness;
1454 gtk_widget_size_request (GTK_WIDGET (menu), &req);
1456 if (gtk_widget_get_direction (GTK_WIDGET (combo_box)) == GTK_TEXT_DIR_LTR)
1459 *x = sx + child->allocation.width - req.width;
1462 screen = gtk_widget_get_screen (GTK_WIDGET (combo_box));
1463 monitor_num = gdk_screen_get_monitor_at_window (screen,
1464 GTK_WIDGET (combo_box)->window);
1465 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
1469 else if (*x + req.width > monitor.x + monitor.width)
1470 *x = monitor.x + monitor.width - req.width;
1472 if (monitor.y + monitor.height - *y - child->allocation.height >= req.height)
1473 *y += child->allocation.height;
1474 else if (*y - monitor.y >= req.height)
1476 else if (monitor.y + monitor.height - *y - child->allocation.height > *y - monitor.y)
1477 *y += child->allocation.height;
1485 gtk_combo_box_menu_position_over (GtkMenu *menu,
1491 GtkComboBox *combo_box;
1495 GtkRequisition requisition;
1502 combo_box = GTK_COMBO_BOX (user_data);
1503 widget = GTK_WIDGET (combo_box);
1505 gtk_widget_get_child_requisition (GTK_WIDGET (menu), &requisition);
1506 menu_width = requisition.width;
1508 active = gtk_menu_get_active (GTK_MENU (combo_box->priv->popup_widget));
1509 gdk_window_get_origin (widget->window, &menu_xpos, &menu_ypos);
1511 menu_xpos += widget->allocation.x;
1512 menu_ypos += widget->allocation.y + widget->allocation.height / 2 - 2;
1516 gtk_widget_get_child_requisition (active, &requisition);
1517 menu_ypos -= requisition.height / 2;
1520 children = GTK_MENU_SHELL (combo_box->priv->popup_widget)->children;
1523 child = children->data;
1525 if (active == child)
1528 if (GTK_WIDGET_VISIBLE (child))
1530 gtk_widget_get_child_requisition (child, &requisition);
1531 menu_ypos -= requisition.height;
1534 children = children->next;
1537 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1538 menu_xpos = menu_xpos + widget->allocation.width - menu_width;
1540 /* Clamp the position on screen */
1541 screen_width = gdk_screen_get_width (gtk_widget_get_screen (widget));
1545 else if ((menu_xpos + menu_width) > screen_width)
1546 menu_xpos -= ((menu_xpos + menu_width) - screen_width);
1555 gtk_combo_box_menu_position (GtkMenu *menu,
1561 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
1562 GtkComboBoxPrivate *priv = combo_box->priv;
1563 GtkWidget *menu_item;
1566 if (priv->wrap_width > 0 || priv->cell_view == NULL)
1567 gtk_combo_box_menu_position_below (menu, x, y, push_in, user_data);
1570 /* FIXME handle nested menus better */
1571 menu_item = gtk_menu_get_active (GTK_MENU (priv->popup_widget));
1573 gtk_menu_shell_select_item (GTK_MENU_SHELL (priv->popup_widget),
1576 gtk_combo_box_menu_position_over (menu, x, y, push_in, user_data);
1579 gtk_window_set_type_hint (GTK_MENU (priv->popup_widget)->toplevel,
1580 GDK_WINDOW_TYPE_HINT_COMBO);
1584 gtk_combo_box_list_position (GtkComboBox *combo_box,
1590 GtkComboBoxPrivate *priv = combo_box->priv;
1593 GdkRectangle monitor;
1594 GtkRequisition popup_req;
1595 GtkPolicyType hpolicy, vpolicy;
1597 /* under windows, the drop down list is as wide as the combo box itself.
1599 GtkWidget *sample = GTK_WIDGET (combo_box);
1601 gdk_window_get_origin (sample->window, x, y);
1603 if (GTK_WIDGET_NO_WINDOW (sample))
1605 *x += sample->allocation.x;
1606 *y += sample->allocation.y;
1609 *width = sample->allocation.width;
1611 hpolicy = vpolicy = GTK_POLICY_NEVER;
1612 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
1614 gtk_widget_size_request (priv->scrolled_window, &popup_req);
1616 if (popup_req.width > *width)
1618 hpolicy = GTK_POLICY_ALWAYS;
1619 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
1621 gtk_widget_size_request (priv->scrolled_window, &popup_req);
1624 *height = popup_req.height;
1626 screen = gtk_widget_get_screen (GTK_WIDGET (combo_box));
1627 monitor_num = gdk_screen_get_monitor_at_window (screen,
1628 GTK_WIDGET (combo_box)->window);
1629 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
1633 else if (*x + *width > monitor.x + monitor.width)
1634 *x = monitor.x + monitor.width - *width;
1636 if (*y + sample->allocation.height + *height <= monitor.y + monitor.height)
1637 *y += sample->allocation.height;
1638 else if (*y - *height >= monitor.y)
1640 else if (monitor.y + monitor.height - (*y + sample->allocation.height) > *y - monitor.y)
1642 *y += sample->allocation.height;
1643 *height = monitor.y + monitor.height - *y;
1647 *height = *y - monitor.y;
1651 if (popup_req.height > *height)
1653 vpolicy = GTK_POLICY_ALWAYS;
1655 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
1661 cell_view_is_sensitive (GtkCellView *cell_view)
1663 GList *cells, *list;
1666 cells = gtk_cell_view_get_cell_renderers (cell_view);
1669 for (list = cells; list; list = list->next)
1671 g_object_get (list->data, "sensitive", &sensitive, NULL);
1676 g_list_free (cells);
1682 tree_column_row_is_sensitive (GtkComboBox *combo_box,
1685 GtkComboBoxPrivate *priv = combo_box->priv;
1686 GList *cells, *list;
1692 if (priv->row_separator_func)
1694 if ((*priv->row_separator_func) (priv->model, iter,
1695 priv->row_separator_data))
1699 gtk_tree_view_column_cell_set_cell_data (priv->column,
1701 iter, FALSE, FALSE);
1703 cells = gtk_tree_view_column_get_cell_renderers (priv->column);
1706 for (list = cells; list; list = list->next)
1708 g_object_get (list->data, "sensitive", &sensitive, NULL);
1713 g_list_free (cells);
1719 update_menu_sensitivity (GtkComboBox *combo_box,
1722 GtkComboBoxPrivate *priv = combo_box->priv;
1723 GList *children, *child;
1724 GtkWidget *item, *submenu, *separator;
1725 GtkWidget *cell_view;
1731 children = gtk_container_get_children (GTK_CONTAINER (menu));
1733 for (child = children; child; child = child->next)
1735 item = GTK_WIDGET (child->data);
1736 cell_view = GTK_BIN (item)->child;
1738 if (!GTK_IS_CELL_VIEW (cell_view))
1741 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (item));
1742 if (submenu != NULL)
1744 gtk_widget_set_sensitive (item, TRUE);
1745 update_menu_sensitivity (combo_box, submenu);
1749 sensitive = cell_view_is_sensitive (GTK_CELL_VIEW (cell_view));
1751 if (menu != priv->popup_widget && child == children)
1753 separator = GTK_WIDGET (child->next->data);
1754 g_object_set (item, "visible", sensitive, NULL);
1755 g_object_set (separator, "visible", sensitive, NULL);
1758 gtk_widget_set_sensitive (item, sensitive);
1762 g_list_free (children);
1766 gtk_combo_box_menu_popup (GtkComboBox *combo_box,
1768 guint32 activate_time)
1770 GtkComboBoxPrivate *priv = combo_box->priv;
1773 GtkRequisition requisition;
1776 update_menu_sensitivity (combo_box, priv->popup_widget);
1779 if (gtk_tree_row_reference_valid (priv->active_row))
1781 path = gtk_tree_row_reference_get_path (priv->active_row);
1782 active_item = gtk_tree_path_get_indices (path)[0];
1783 gtk_tree_path_free (path);
1785 if (priv->add_tearoffs)
1789 /* FIXME handle nested menus better */
1790 gtk_menu_set_active (GTK_MENU (priv->popup_widget), active_item);
1792 if (priv->wrap_width == 0)
1794 width = GTK_WIDGET (combo_box)->allocation.width;
1795 gtk_widget_set_size_request (priv->popup_widget, -1, -1);
1796 gtk_widget_size_request (priv->popup_widget, &requisition);
1798 gtk_widget_set_size_request (priv->popup_widget,
1799 MAX (width, requisition.width), -1);
1802 gtk_menu_popup (GTK_MENU (priv->popup_widget),
1804 gtk_combo_box_menu_position, combo_box,
1805 button, activate_time);
1809 popup_grab_on_window (GdkWindow *window,
1810 guint32 activate_time,
1811 gboolean grab_keyboard)
1813 if ((gdk_pointer_grab (window, TRUE,
1814 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
1815 GDK_POINTER_MOTION_MASK,
1816 NULL, NULL, activate_time) == 0))
1818 if (!grab_keyboard ||
1819 gdk_keyboard_grab (window, TRUE,
1820 activate_time) == 0)
1824 gdk_display_pointer_ungrab (gdk_drawable_get_display (window),
1834 * gtk_combo_box_popup:
1835 * @combo_box: a #GtkComboBox
1837 * Pops up the menu or dropdown list of @combo_box.
1839 * This function is mostly intended for use by accessibility technologies;
1840 * applications should have little use for it.
1845 gtk_combo_box_popup (GtkComboBox *combo_box)
1847 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
1849 g_signal_emit (combo_box, combo_box_signals[POPUP], 0);
1853 gtk_combo_box_real_popup (GtkComboBox *combo_box)
1855 GtkComboBoxPrivate *priv = combo_box->priv;
1856 gint x, y, width, height;
1857 GtkTreePath *path = NULL, *ppath;
1858 GtkWidget *toplevel;
1860 if (!GTK_WIDGET_REALIZED (combo_box))
1863 if (GTK_WIDGET_MAPPED (priv->popup_widget))
1866 if (GTK_IS_MENU (priv->popup_widget))
1868 gtk_combo_box_menu_popup (combo_box,
1869 priv->activate_button,
1870 priv->activate_time);
1874 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (combo_box));
1875 if (GTK_IS_WINDOW (toplevel))
1876 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
1877 GTK_WINDOW (priv->popup_window));
1879 gtk_widget_show_all (priv->scrolled_window);
1880 gtk_combo_box_list_position (combo_box, &x, &y, &width, &height);
1882 gtk_widget_set_size_request (priv->popup_window, width, height);
1883 gtk_window_move (GTK_WINDOW (priv->popup_window), x, y);
1885 if (gtk_tree_row_reference_valid (priv->active_row))
1887 path = gtk_tree_row_reference_get_path (priv->active_row);
1888 ppath = gtk_tree_path_copy (path);
1889 if (gtk_tree_path_up (ppath))
1890 gtk_tree_view_expand_to_path (GTK_TREE_VIEW (priv->tree_view),
1892 gtk_tree_path_free (ppath);
1894 gtk_tree_view_set_hover_expand (GTK_TREE_VIEW (priv->tree_view),
1898 gtk_widget_show (priv->popup_window);
1902 gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->tree_view),
1904 gtk_tree_path_free (path);
1907 gtk_widget_grab_focus (priv->popup_window);
1908 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->button),
1911 if (!GTK_WIDGET_HAS_FOCUS (priv->tree_view))
1912 gtk_widget_grab_focus (priv->tree_view);
1914 if (!popup_grab_on_window (priv->popup_window->window,
1915 GDK_CURRENT_TIME, TRUE))
1917 gtk_widget_hide (priv->popup_window);
1921 gtk_grab_add (priv->popup_window);
1925 gtk_combo_box_real_popdown (GtkComboBox *combo_box)
1927 if (combo_box->priv->popup_shown)
1929 gtk_combo_box_popdown (combo_box);
1937 * gtk_combo_box_popdown:
1938 * @combo_box: a #GtkComboBox
1940 * Hides the menu or dropdown list of @combo_box.
1942 * This function is mostly intended for use by accessibility technologies;
1943 * applications should have little use for it.
1948 gtk_combo_box_popdown (GtkComboBox *combo_box)
1950 GtkComboBoxPrivate *priv = combo_box->priv;
1952 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
1954 if (GTK_IS_MENU (priv->popup_widget))
1956 gtk_menu_popdown (GTK_MENU (priv->popup_widget));
1960 if (!GTK_WIDGET_REALIZED (GTK_WIDGET (combo_box)))
1963 gtk_grab_remove (priv->popup_window);
1964 gtk_widget_hide_all (priv->popup_window);
1965 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->button),
1970 gtk_combo_box_calc_requested_width (GtkComboBox *combo_box,
1973 GtkComboBoxPrivate *priv = combo_box->priv;
1977 if (priv->cell_view)
1978 gtk_widget_style_get (priv->cell_view,
1979 "focus-line-width", &padding,
1984 /* add some pixels for good measure */
1985 padding += BONUS_PADDING;
1987 if (priv->cell_view)
1988 gtk_cell_view_get_size_of_row (GTK_CELL_VIEW (priv->cell_view),
1993 return req.width + padding;
1997 gtk_combo_box_remeasure (GtkComboBox *combo_box)
1999 GtkComboBoxPrivate *priv = combo_box->priv;
2004 !gtk_tree_model_get_iter_first (priv->model, &iter))
2010 path = gtk_tree_path_new_from_indices (0, -1);
2016 if (priv->cell_view)
2017 gtk_cell_view_get_size_of_row (GTK_CELL_VIEW (priv->cell_view),
2025 priv->width = MAX (priv->width, req.width);
2026 priv->height = MAX (priv->height, req.height);
2028 gtk_tree_path_next (path);
2030 while (gtk_tree_model_iter_next (priv->model, &iter));
2032 gtk_tree_path_free (path);
2036 gtk_combo_box_size_request (GtkWidget *widget,
2037 GtkRequisition *requisition)
2040 gint focus_width, focus_pad;
2043 GtkRequisition bin_req;
2044 PangoContext *context;
2045 PangoFontMetrics *metrics;
2046 PangoFontDescription *font_desc;
2048 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
2049 GtkComboBoxPrivate *priv = combo_box->priv;
2052 gtk_widget_size_request (GTK_BIN (widget)->child, &bin_req);
2053 gtk_combo_box_remeasure (combo_box);
2054 bin_req.width = MAX (bin_req.width, priv->width);
2055 bin_req.height = MAX (bin_req.height, priv->height);
2057 gtk_widget_style_get (GTK_WIDGET (widget),
2058 "focus-line-width", &focus_width,
2059 "focus-padding", &focus_pad,
2060 "arrow-size", &arrow_size,
2063 font_desc = GTK_BIN (widget)->child->style->font_desc;
2064 context = gtk_widget_get_pango_context (widget);
2065 metrics = pango_context_get_metrics (context, font_desc,
2066 pango_context_get_language (context));
2067 font_size = PANGO_PIXELS (pango_font_metrics_get_ascent (metrics) +
2068 pango_font_metrics_get_descent (metrics));
2069 pango_font_metrics_unref (metrics);
2071 arrow_size = MAX (arrow_size, font_size);
2073 gtk_widget_set_size_request (priv->arrow, arrow_size, arrow_size);
2075 if (!priv->tree_view)
2079 if (priv->cell_view)
2081 GtkRequisition button_req, sep_req, arrow_req;
2082 gint border_width, xthickness, ythickness;
2084 gtk_widget_size_request (priv->button, &button_req);
2085 border_width = GTK_CONTAINER (combo_box)->border_width;
2086 xthickness = priv->button->style->xthickness;
2087 ythickness = priv->button->style->ythickness;
2089 bin_req.width = MAX (bin_req.width, priv->width);
2090 bin_req.height = MAX (bin_req.height, priv->height);
2092 gtk_widget_size_request (priv->separator, &sep_req);
2093 gtk_widget_size_request (priv->arrow, &arrow_req);
2095 height = MAX (sep_req.height, arrow_req.height);
2096 height = MAX (height, bin_req.height);
2098 width = bin_req.width + sep_req.width + arrow_req.width;
2100 height += 2*(border_width + ythickness + focus_width + focus_pad);
2101 width += 2*(border_width + xthickness + focus_width + focus_pad);
2103 requisition->width = width;
2104 requisition->height = height;
2108 GtkRequisition but_req;
2110 gtk_widget_size_request (priv->button, &but_req);
2112 requisition->width = bin_req.width + but_req.width;
2113 requisition->height = MAX (bin_req.height, but_req.height);
2119 GtkRequisition button_req, frame_req;
2121 /* sample + frame */
2122 *requisition = bin_req;
2124 requisition->width += 2 * focus_width;
2126 if (priv->cell_view_frame)
2128 gtk_widget_size_request (priv->cell_view_frame, &frame_req);
2129 if (priv->has_frame)
2131 requisition->width += 2 *
2132 (GTK_CONTAINER (priv->cell_view_frame)->border_width +
2133 GTK_WIDGET (priv->cell_view_frame)->style->xthickness);
2134 requisition->height += 2 *
2135 (GTK_CONTAINER (priv->cell_view_frame)->border_width +
2136 GTK_WIDGET (priv->cell_view_frame)->style->ythickness);
2141 gtk_widget_size_request (priv->button, &button_req);
2143 requisition->height = MAX (requisition->height, button_req.height);
2144 requisition->width += button_req.width;
2147 if (GTK_SHADOW_NONE != priv->shadow_type)
2149 requisition->height += 2 * widget->style->ythickness;
2150 requisition->width += 2 * widget->style->xthickness;
2154 #define GTK_COMBO_BOX_SIZE_ALLOCATE_BUTTON \
2155 gtk_widget_size_request (combo_box->priv->button, &req); \
2158 child.x = allocation->x + shadow_width; \
2160 child.x = allocation->x + allocation->width - req.width - shadow_width; \
2162 child.y = allocation->y + shadow_height; \
2163 child.width = req.width; \
2164 child.height = allocation->height - 2 * shadow_height; \
2165 child.width = MAX (1, child.width); \
2166 child.height = MAX (1, child.height); \
2168 gtk_widget_size_allocate (combo_box->priv->button, &child);
2171 gtk_combo_box_size_allocate (GtkWidget *widget,
2172 GtkAllocation *allocation)
2174 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
2175 GtkComboBoxPrivate *priv = combo_box->priv;
2176 gint shadow_width, shadow_height;
2177 gint focus_width, focus_pad;
2178 GtkAllocation child;
2180 gboolean is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2182 widget->allocation = *allocation;
2184 gtk_widget_style_get (GTK_WIDGET (widget),
2185 "focus-line-width", &focus_width,
2186 "focus-padding", &focus_pad,
2189 if (GTK_SHADOW_NONE != priv->shadow_type)
2191 shadow_width = widget->style->xthickness;
2192 shadow_height = widget->style->ythickness;
2200 if (!priv->tree_view)
2202 if (priv->cell_view)
2204 gint border_width, xthickness, ythickness;
2208 allocation->x += shadow_width;
2209 allocation->y += shadow_height;
2210 allocation->width -= 2 * shadow_width;
2211 allocation->height -= 2 * shadow_height;
2213 gtk_widget_size_allocate (priv->button, allocation);
2215 /* set some things ready */
2216 border_width = GTK_CONTAINER (priv->button)->border_width;
2217 xthickness = priv->button->style->xthickness;
2218 ythickness = priv->button->style->ythickness;
2220 child.x = allocation->x;
2221 child.y = allocation->y;
2222 width = allocation->width;
2223 child.height = allocation->height;
2225 if (!priv->is_cell_renderer)
2227 child.x += border_width + xthickness + focus_width + focus_pad;
2228 child.y += border_width + ythickness + focus_width + focus_pad;
2229 width -= 2 * (child.x - allocation->x);
2230 child.height -= 2 * (child.y - allocation->y);
2234 /* handle the children */
2235 gtk_widget_size_request (priv->arrow, &req);
2236 child.width = req.width;
2238 child.x += width - req.width;
2239 child.width = MAX (1, child.width);
2240 child.height = MAX (1, child.height);
2241 gtk_widget_size_allocate (priv->arrow, &child);
2243 child.x += req.width;
2244 gtk_widget_size_request (priv->separator, &req);
2245 child.width = req.width;
2247 child.x -= req.width;
2248 child.width = MAX (1, child.width);
2249 child.height = MAX (1, child.height);
2250 gtk_widget_size_allocate (priv->separator, &child);
2254 child.x += req.width;
2255 child.width = allocation->x + allocation->width
2256 - (border_width + xthickness + focus_width + focus_pad)
2261 child.width = child.x;
2262 child.x = allocation->x
2263 + border_width + xthickness + focus_width + focus_pad;
2264 child.width -= child.x;
2267 child.width = MAX (1, child.width);
2268 child.height = MAX (1, child.height);
2269 gtk_widget_size_allocate (GTK_BIN (widget)->child, &child);
2273 GTK_COMBO_BOX_SIZE_ALLOCATE_BUTTON
2276 child.x = allocation->x + req.width + shadow_width;
2278 child.x = allocation->x + shadow_width;
2279 child.y = allocation->y + shadow_height;
2280 child.width = allocation->width - req.width - 2 * shadow_width;
2281 child.width = MAX (1, child.width);
2282 child.height = MAX (1, child.height);
2283 gtk_widget_size_allocate (GTK_BIN (widget)->child, &child);
2290 /* Combobox thickness + border-width */
2291 int delta_x = shadow_width + GTK_CONTAINER (widget)->border_width;
2292 int delta_y = shadow_height + GTK_CONTAINER (widget)->border_width;
2295 GTK_COMBO_BOX_SIZE_ALLOCATE_BUTTON
2299 child.x = allocation->x + req.width;
2301 child.x = allocation->x;
2303 child.y = allocation->y;
2304 child.width = allocation->width - req.width;
2305 child.height = allocation->height;
2307 if (priv->cell_view_frame)
2311 child.width = MAX (1, child.width - delta_x * 2);
2312 child.height = MAX (1, child.height - delta_y * 2);
2313 gtk_widget_size_allocate (priv->cell_view_frame, &child);
2316 if (priv->has_frame)
2318 delta_x = GTK_CONTAINER (priv->cell_view_frame)->border_width +
2319 GTK_WIDGET (priv->cell_view_frame)->style->xthickness;
2320 delta_y = GTK_CONTAINER (priv->cell_view_frame)->border_width +
2321 GTK_WIDGET (priv->cell_view_frame)->style->ythickness;
2325 child.width -= delta_x * 2;
2326 child.height -= delta_y * 2;
2333 child.width -= delta_x * 2;
2334 child.height -= delta_y * 2;
2337 child.width = MAX (1, child.width);
2338 child.height = MAX (1, child.height);
2340 gtk_widget_size_allocate (GTK_BIN (combo_box)->child, &child);
2344 #undef GTK_COMBO_BOX_ALLOCATE_BUTTON
2347 gtk_combo_box_unset_model (GtkComboBox *combo_box)
2349 GtkComboBoxPrivate *priv = combo_box->priv;
2353 g_signal_handler_disconnect (priv->model,
2355 g_signal_handler_disconnect (priv->model,
2357 g_signal_handler_disconnect (priv->model,
2358 priv->reordered_id);
2359 g_signal_handler_disconnect (priv->model,
2364 if (!priv->tree_view)
2366 if (priv->popup_widget)
2367 gtk_container_foreach (GTK_CONTAINER (priv->popup_widget),
2368 (GtkCallback)gtk_widget_destroy, NULL);
2373 g_object_unref (priv->model);
2377 if (priv->active_row)
2379 gtk_tree_row_reference_free (priv->active_row);
2380 priv->active_row = NULL;
2383 if (priv->cell_view)
2384 gtk_cell_view_set_model (GTK_CELL_VIEW (priv->cell_view), NULL);
2388 gtk_combo_box_forall (GtkContainer *container,
2389 gboolean include_internals,
2390 GtkCallback callback,
2391 gpointer callback_data)
2393 GtkComboBox *combo_box = GTK_COMBO_BOX (container);
2394 GtkComboBoxPrivate *priv = combo_box->priv;
2396 if (include_internals)
2399 (* callback) (priv->button, callback_data);
2400 if (priv->cell_view_frame)
2401 (* callback) (priv->cell_view_frame, callback_data);
2404 if (GTK_BIN (container)->child)
2405 (* callback) (GTK_BIN (container)->child, callback_data);
2409 gtk_combo_box_child_show (GtkWidget *widget,
2410 GtkComboBox *combo_box)
2412 GtkComboBoxPrivate *priv = combo_box->priv;
2414 priv->popup_shown = TRUE;
2415 g_object_notify (G_OBJECT (combo_box), "popup-shown");
2419 gtk_combo_box_child_hide (GtkWidget *widget,
2420 GtkComboBox *combo_box)
2422 GtkComboBoxPrivate *priv = combo_box->priv;
2424 priv->popup_shown = FALSE;
2425 g_object_notify (G_OBJECT (combo_box), "popup-shown");
2429 gtk_combo_box_expose_event (GtkWidget *widget,
2430 GdkEventExpose *event)
2432 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
2433 GtkComboBoxPrivate *priv = combo_box->priv;
2435 if (GTK_WIDGET_DRAWABLE (widget) &&
2436 GTK_SHADOW_NONE != priv->shadow_type)
2438 gtk_paint_shadow (widget->style, widget->window,
2439 GTK_STATE_NORMAL, priv->shadow_type,
2440 NULL, widget, "combobox",
2441 widget->allocation.x, widget->allocation.y,
2442 widget->allocation.width, widget->allocation.height);
2445 gtk_container_propagate_expose (GTK_CONTAINER (widget),
2446 priv->button, event);
2448 if (priv->tree_view && priv->cell_view_frame)
2450 gtk_container_propagate_expose (GTK_CONTAINER (widget),
2451 priv->cell_view_frame, event);
2454 gtk_container_propagate_expose (GTK_CONTAINER (widget),
2455 GTK_BIN (widget)->child, event);
2470 path_visible (GtkTreeView *view,
2476 /* Note that we rely on the fact that collapsed rows don't have nodes
2478 return _gtk_tree_view_find_node (view, path, &tree, &node);
2482 tree_next_func (GtkTreeModel *model,
2487 SearchData *search_data = (SearchData *)data;
2489 if (search_data->found)
2491 if (!tree_column_row_is_sensitive (search_data->combo, iter))
2494 if (search_data->visible &&
2495 !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
2498 search_data->set = TRUE;
2499 search_data->iter = *iter;
2504 if (gtk_tree_path_compare (path, search_data->path) == 0)
2505 search_data->found = TRUE;
2511 tree_next (GtkComboBox *combo,
2512 GtkTreeModel *model,
2517 SearchData search_data;
2519 search_data.combo = combo;
2520 search_data.path = gtk_tree_model_get_path (model, iter);
2521 search_data.visible = visible;
2522 search_data.found = FALSE;
2523 search_data.set = FALSE;
2525 gtk_tree_model_foreach (model, tree_next_func, &search_data);
2527 *next = search_data.iter;
2529 gtk_tree_path_free (search_data.path);
2531 return search_data.set;
2535 tree_prev_func (GtkTreeModel *model,
2540 SearchData *search_data = (SearchData *)data;
2542 if (gtk_tree_path_compare (path, search_data->path) == 0)
2544 search_data->found = TRUE;
2548 if (!tree_column_row_is_sensitive (search_data->combo, iter))
2551 if (search_data->visible &&
2552 !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
2555 search_data->set = TRUE;
2556 search_data->iter = *iter;
2562 tree_prev (GtkComboBox *combo,
2563 GtkTreeModel *model,
2568 SearchData search_data;
2570 search_data.combo = combo;
2571 search_data.path = gtk_tree_model_get_path (model, iter);
2572 search_data.visible = visible;
2573 search_data.found = FALSE;
2574 search_data.set = FALSE;
2576 gtk_tree_model_foreach (model, tree_prev_func, &search_data);
2578 *prev = search_data.iter;
2580 gtk_tree_path_free (search_data.path);
2582 return search_data.set;
2586 tree_last_func (GtkTreeModel *model,
2591 SearchData *search_data = (SearchData *)data;
2593 if (!tree_column_row_is_sensitive (search_data->combo, iter))
2596 /* Note that we rely on the fact that collapsed rows don't have nodes
2598 if (search_data->visible &&
2599 !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
2602 search_data->set = TRUE;
2603 search_data->iter = *iter;
2609 tree_last (GtkComboBox *combo,
2610 GtkTreeModel *model,
2614 SearchData search_data;
2616 search_data.combo = combo;
2617 search_data.visible = visible;
2618 search_data.set = FALSE;
2620 gtk_tree_model_foreach (model, tree_last_func, &search_data);
2622 *last = search_data.iter;
2624 return search_data.set;
2629 tree_first_func (GtkTreeModel *model,
2634 SearchData *search_data = (SearchData *)data;
2636 if (!tree_column_row_is_sensitive (search_data->combo, iter))
2639 if (search_data->visible &&
2640 !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
2643 search_data->set = TRUE;
2644 search_data->iter = *iter;
2650 tree_first (GtkComboBox *combo,
2651 GtkTreeModel *model,
2655 SearchData search_data;
2657 search_data.combo = combo;
2658 search_data.visible = visible;
2659 search_data.set = FALSE;
2661 gtk_tree_model_foreach (model, tree_first_func, &search_data);
2663 *first = search_data.iter;
2665 return search_data.set;
2669 gtk_combo_box_scroll_event (GtkWidget *widget,
2670 GdkEventScroll *event)
2672 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
2675 GtkTreeIter new_iter;
2677 if (!gtk_combo_box_get_active_iter (combo_box, &iter))
2680 if (event->direction == GDK_SCROLL_UP)
2681 found = tree_prev (combo_box, combo_box->priv->model,
2682 &iter, &new_iter, FALSE);
2684 found = tree_next (combo_box, combo_box->priv->model,
2685 &iter, &new_iter, FALSE);
2688 gtk_combo_box_set_active_iter (combo_box, &new_iter);
2698 gtk_combo_box_sync_cells (GtkComboBox *combo_box,
2699 GtkCellLayout *cell_layout)
2701 GtkComboBoxPrivate *priv = combo_box->priv;
2704 for (k = priv->cells; k; k = k->next)
2707 ComboCellInfo *info = (ComboCellInfo *)k->data;
2709 if (info->pack == GTK_PACK_START)
2710 gtk_cell_layout_pack_start (cell_layout,
2711 info->cell, info->expand);
2712 else if (info->pack == GTK_PACK_END)
2713 gtk_cell_layout_pack_end (cell_layout,
2714 info->cell, info->expand);
2716 gtk_cell_layout_set_cell_data_func (cell_layout,
2718 combo_cell_data_func, info, NULL);
2720 for (j = info->attributes; j; j = j->next->next)
2722 gtk_cell_layout_add_attribute (cell_layout,
2725 GPOINTER_TO_INT (j->next->data));
2731 gtk_combo_box_menu_setup (GtkComboBox *combo_box,
2732 gboolean add_children)
2734 GtkComboBoxPrivate *priv = combo_box->priv;
2737 if (priv->cell_view)
2739 priv->button = gtk_toggle_button_new ();
2740 gtk_button_set_focus_on_click (GTK_BUTTON (priv->button),
2741 priv->focus_on_click);
2743 g_signal_connect (priv->button, "toggled",
2744 G_CALLBACK (gtk_combo_box_button_toggled), combo_box);
2745 gtk_widget_set_parent (priv->button,
2746 GTK_BIN (combo_box)->child->parent);
2748 priv->box = gtk_hbox_new (FALSE, 0);
2749 gtk_container_add (GTK_CONTAINER (priv->button), priv->box);
2751 priv->separator = gtk_vseparator_new ();
2752 gtk_container_add (GTK_CONTAINER (priv->box), priv->separator);
2754 priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
2755 gtk_container_add (GTK_CONTAINER (priv->box), priv->arrow);
2757 gtk_widget_show_all (priv->button);
2761 priv->button = gtk_toggle_button_new ();
2762 gtk_button_set_focus_on_click (GTK_BUTTON (priv->button),
2763 priv->focus_on_click);
2765 g_signal_connect (priv->button, "toggled",
2766 G_CALLBACK (gtk_combo_box_button_toggled), combo_box);
2767 gtk_widget_set_parent (priv->button,
2768 GTK_BIN (combo_box)->child->parent);
2770 priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
2771 gtk_container_add (GTK_CONTAINER (priv->button), priv->arrow);
2772 gtk_widget_show_all (priv->button);
2775 g_signal_connect (priv->button, "button_press_event",
2776 G_CALLBACK (gtk_combo_box_menu_button_press),
2778 g_signal_connect (priv->button, "state_changed",
2779 G_CALLBACK (gtk_combo_box_button_state_changed),
2782 /* create our funky menu */
2783 menu = gtk_menu_new ();
2784 gtk_widget_set_name (menu, "gtk-combobox-popup-menu");
2786 g_signal_connect (menu, "key_press_event",
2787 G_CALLBACK (gtk_combo_box_menu_key_press), combo_box);
2788 gtk_combo_box_set_popup_widget (combo_box, menu);
2792 gtk_combo_box_menu_fill (combo_box);
2794 /* the column is needed in tree_column_row_is_sensitive() */
2795 priv->column = gtk_tree_view_column_new ();
2796 g_object_ref_sink (priv->column);
2797 gtk_combo_box_sync_cells (combo_box, GTK_CELL_LAYOUT (priv->column));
2799 gtk_combo_box_update_title (combo_box);
2803 gtk_combo_box_menu_fill (GtkComboBox *combo_box)
2805 GtkComboBoxPrivate *priv = combo_box->priv;
2811 menu = priv->popup_widget;
2813 if (priv->add_tearoffs)
2815 GtkWidget *tearoff = gtk_tearoff_menu_item_new ();
2817 gtk_widget_show (tearoff);
2819 if (priv->wrap_width)
2820 gtk_menu_attach (GTK_MENU (menu), tearoff, 0, priv->wrap_width, 0, 1);
2822 gtk_menu_shell_append (GTK_MENU_SHELL (menu), tearoff);
2825 gtk_combo_box_menu_fill_level (combo_box, menu, NULL);
2829 gtk_cell_view_menu_item_new (GtkComboBox *combo_box,
2830 GtkTreeModel *model,
2833 GtkWidget *cell_view;
2838 cell_view = gtk_cell_view_new ();
2839 item = gtk_menu_item_new ();
2840 gtk_container_add (GTK_CONTAINER (item), cell_view);
2842 gtk_cell_view_set_model (GTK_CELL_VIEW (cell_view), model);
2843 path = gtk_tree_model_get_path (model, iter);
2844 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (cell_view), path);
2845 gtk_tree_path_free (path);
2847 gtk_combo_box_sync_cells (combo_box, GTK_CELL_LAYOUT (cell_view));
2848 gtk_widget_size_request (cell_view, &req);
2849 gtk_widget_show (cell_view);
2855 gtk_combo_box_menu_fill_level (GtkComboBox *combo_box,
2857 GtkTreeIter *parent)
2859 GtkComboBoxPrivate *priv = combo_box->priv;
2860 GtkTreeModel *model = priv->model;
2861 GtkWidget *item, *submenu, *subitem, *separator;
2863 gboolean is_separator;
2868 n_children = gtk_tree_model_iter_n_children (model, parent);
2871 for (i = 0; i < n_children; i++)
2873 gtk_tree_model_iter_nth_child (model, &iter, parent, i);
2875 if (priv->row_separator_func)
2876 is_separator = (*priv->row_separator_func) (priv->model, &iter,
2877 priv->row_separator_data);
2879 is_separator = FALSE;
2883 item = gtk_separator_menu_item_new ();
2884 path = gtk_tree_model_get_path (model, &iter);
2885 g_object_set_data_full (G_OBJECT (item),
2886 I_("gtk-combo-box-item-path"),
2887 gtk_tree_row_reference_new (model, path),
2888 (GDestroyNotify)gtk_tree_row_reference_free);
2889 gtk_tree_path_free (path);
2893 item = gtk_cell_view_menu_item_new (combo_box, model, &iter);
2894 if (gtk_tree_model_iter_has_child (model, &iter))
2896 submenu = gtk_menu_new ();
2897 gtk_widget_show (submenu);
2898 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
2900 /* Ugly - since menus can only activate leafs, we have to
2901 * duplicate the item inside the submenu.
2903 subitem = gtk_cell_view_menu_item_new (combo_box, model, &iter);
2904 separator = gtk_separator_menu_item_new ();
2905 gtk_widget_show (subitem);
2906 gtk_widget_show (separator);
2907 g_signal_connect (subitem, "activate",
2908 G_CALLBACK (gtk_combo_box_menu_item_activate),
2910 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), subitem);
2911 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), separator);
2913 gtk_combo_box_menu_fill_level (combo_box, submenu, &iter);
2915 g_signal_connect (item, "activate",
2916 G_CALLBACK (gtk_combo_box_menu_item_activate),
2920 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
2921 if (priv->wrap_width && menu == priv->popup_widget)
2922 gtk_combo_box_relayout_item (combo_box, item, &iter, last);
2923 gtk_widget_show (item);
2930 gtk_combo_box_menu_destroy (GtkComboBox *combo_box)
2932 GtkComboBoxPrivate *priv = combo_box->priv;
2934 g_signal_handlers_disconnect_matched (priv->button,
2935 G_SIGNAL_MATCH_DATA,
2937 gtk_combo_box_menu_button_press, NULL);
2938 g_signal_handlers_disconnect_matched (priv->button,
2939 G_SIGNAL_MATCH_DATA,
2941 gtk_combo_box_button_state_changed, combo_box);
2943 /* unparent will remove our latest ref */
2944 gtk_widget_unparent (priv->button);
2947 priv->button = NULL;
2949 priv->separator = NULL;
2951 g_object_unref (priv->column);
2952 priv->column = NULL;
2954 /* changing the popup window will unref the menu and the children */
2962 menu_occupied (GtkMenu *menu,
2966 guint bottom_attach)
2970 for (i = GTK_MENU_SHELL (menu)->children; i; i = i->next)
2974 gtk_container_child_get (GTK_CONTAINER (menu),
2978 "bottom-attach", &b,
2982 /* look if this item intersects with the given coordinates */
2983 if (right_attach > l && left_attach < r && bottom_attach > t && top_attach < b)
2991 gtk_combo_box_relayout_item (GtkComboBox *combo_box,
2996 GtkComboBoxPrivate *priv = combo_box->priv;
2997 gint current_col = 0, current_row = 0;
2998 gint rows = 1, cols = 1;
2999 GtkWidget *menu = priv->popup_widget;
3001 if (!GTK_IS_MENU_SHELL (menu))
3004 if (priv->col_column == -1 &&
3005 priv->row_column == -1 &&
3008 gtk_container_child_get (GTK_CONTAINER (menu),
3010 "right-attach", ¤t_col,
3011 "top-attach", ¤t_row,
3013 if (current_col + cols > priv->wrap_width)
3021 if (priv->col_column != -1)
3022 gtk_tree_model_get (priv->model, iter,
3023 priv->col_column, &cols,
3025 if (priv->row_column != -1)
3026 gtk_tree_model_get (priv->model, iter,
3027 priv->row_column, &rows,
3032 if (current_col + cols > priv->wrap_width)
3038 if (!menu_occupied (GTK_MENU (menu),
3039 current_col, current_col + cols,
3040 current_row, current_row + rows))
3047 /* set attach props */
3048 gtk_menu_attach (GTK_MENU (menu), item,
3049 current_col, current_col + cols,
3050 current_row, current_row + rows);
3054 gtk_combo_box_relayout (GtkComboBox *combo_box)
3059 menu = combo_box->priv->popup_widget;
3061 /* do nothing unless we are in menu style and realized */
3062 if (combo_box->priv->tree_view || !GTK_IS_MENU_SHELL (menu))
3065 list = gtk_container_get_children (GTK_CONTAINER (menu));
3067 for (j = g_list_last (list); j; j = j->prev)
3068 gtk_container_remove (GTK_CONTAINER (menu), j->data);
3070 gtk_combo_box_menu_fill (combo_box);
3077 gtk_combo_box_menu_button_press (GtkWidget *widget,
3078 GdkEventButton *event,
3081 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3082 GtkComboBoxPrivate *priv = combo_box->priv;
3084 if (GTK_IS_MENU (priv->popup_widget) &&
3085 event->type == GDK_BUTTON_PRESS && event->button == 1)
3087 if (priv->focus_on_click &&
3088 !GTK_WIDGET_HAS_FOCUS (priv->button))
3089 gtk_widget_grab_focus (priv->button);
3091 gtk_combo_box_menu_popup (combo_box, event->button, event->time);
3100 gtk_combo_box_menu_item_activate (GtkWidget *item,
3103 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3104 GtkWidget *cell_view;
3108 cell_view = GTK_BIN (item)->child;
3110 g_return_if_fail (GTK_IS_CELL_VIEW (cell_view));
3112 path = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (cell_view));
3114 if (gtk_tree_model_get_iter (combo_box->priv->model, &iter, path))
3116 if (gtk_menu_item_get_submenu (GTK_MENU_ITEM (item)) == NULL)
3117 gtk_combo_box_set_active_iter (combo_box, &iter);
3120 gtk_tree_path_free (path);
3122 combo_box->priv->editing_canceled = FALSE;
3126 gtk_combo_box_model_row_inserted (GtkTreeModel *model,
3131 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3133 if (combo_box->priv->tree_view)
3134 gtk_combo_box_list_popup_resize (combo_box);
3136 gtk_combo_box_menu_row_inserted (model, path, iter, user_data);
3140 gtk_combo_box_model_row_deleted (GtkTreeModel *model,
3144 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3145 GtkComboBoxPrivate *priv = combo_box->priv;
3147 if (!gtk_tree_row_reference_valid (priv->active_row))
3149 if (priv->cell_view)
3150 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (priv->cell_view), NULL);
3151 g_signal_emit (combo_box, combo_box_signals[CHANGED], 0);
3154 if (priv->tree_view)
3155 gtk_combo_box_list_popup_resize (combo_box);
3157 gtk_combo_box_menu_row_deleted (model, path, user_data);
3161 gtk_combo_box_model_rows_reordered (GtkTreeModel *model,
3167 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3169 gtk_tree_row_reference_reordered (G_OBJECT (user_data), path, iter, new_order);
3171 if (!combo_box->priv->tree_view)
3172 gtk_combo_box_menu_rows_reordered (model, path, iter, new_order, user_data);
3176 gtk_combo_box_model_row_changed (GtkTreeModel *model,
3181 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3182 GtkComboBoxPrivate *priv = combo_box->priv;
3183 GtkTreePath *active_path;
3185 /* FIXME this belongs to GtkCellView */
3186 if (gtk_tree_row_reference_valid (priv->active_row))
3188 active_path = gtk_tree_row_reference_get_path (priv->active_row);
3189 if (gtk_tree_path_compare (path, active_path) == 0 &&
3191 gtk_widget_queue_resize (GTK_WIDGET (priv->cell_view));
3192 gtk_tree_path_free (active_path);
3195 if (priv->tree_view)
3196 gtk_combo_box_list_row_changed (model, path, iter, user_data);
3198 gtk_combo_box_menu_row_changed (model, path, iter, user_data);
3202 list_popup_resize_idle (gpointer user_data)
3204 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3205 GtkComboBoxPrivate *priv = combo_box->priv;
3206 gint x, y, width, height;
3208 if (priv->tree_view && GTK_WIDGET_MAPPED (priv->popup_window))
3210 gtk_combo_box_list_position (combo_box, &x, &y, &width, &height);
3212 gtk_widget_set_size_request (priv->popup_window, width, height);
3213 gtk_window_move (GTK_WINDOW (priv->popup_window), x, y);
3216 priv->resize_idle_id = 0;
3222 gtk_combo_box_list_popup_resize (GtkComboBox *combo_box)
3224 GtkComboBoxPrivate *priv = combo_box->priv;
3226 if (!priv->resize_idle_id)
3227 priv->resize_idle_id =
3228 gdk_threads_add_idle (list_popup_resize_idle, combo_box);
3232 gtk_combo_box_model_row_expanded (GtkTreeModel *model,
3237 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3239 gtk_combo_box_list_popup_resize (combo_box);
3244 find_menu_by_path (GtkWidget *menu,
3246 gboolean skip_first)
3251 GtkTreeRowReference *mref;
3255 list = gtk_container_get_children (GTK_CONTAINER (menu));
3258 for (i = list; i; i = i->next)
3260 if (GTK_IS_SEPARATOR_MENU_ITEM (i->data))
3262 mref = g_object_get_data (G_OBJECT (i->data), "gtk-combo-box-item-path");
3265 else if (!gtk_tree_row_reference_valid (mref))
3268 mpath = gtk_tree_row_reference_get_path (mref);
3270 else if (GTK_IS_CELL_VIEW (GTK_BIN (i->data)->child))
3278 mpath = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (GTK_BIN (i->data)->child));
3283 /* this case is necessary, since the row reference of
3284 * the cell view may already be updated after a deletion
3291 if (gtk_tree_path_compare (mpath, path) == 0)
3293 gtk_tree_path_free (mpath);
3297 if (gtk_tree_path_is_ancestor (mpath, path))
3299 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
3300 if (submenu != NULL)
3302 gtk_tree_path_free (mpath);
3303 item = find_menu_by_path (submenu, path, TRUE);
3307 gtk_tree_path_free (mpath);
3317 dump_menu_tree (GtkWidget *menu,
3324 list = gtk_container_get_children (GTK_CONTAINER (menu));
3325 for (i = list; i; i = i->next)
3327 if (GTK_IS_CELL_VIEW (GTK_BIN (i->data)->child))
3329 path = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (GTK_BIN (i->data)->child));
3330 g_print ("%*s%s\n", 2 * level, " ", gtk_tree_path_to_string (path));
3331 gtk_tree_path_free (path);
3333 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
3334 if (submenu != NULL)
3335 dump_menu_tree (submenu, level + 1);
3344 gtk_combo_box_menu_row_inserted (GtkTreeModel *model,
3349 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3350 GtkComboBoxPrivate *priv = combo_box->priv;
3352 GtkWidget *item, *menu, *separator;
3356 gboolean is_separator;
3358 if (!priv->popup_widget)
3361 depth = gtk_tree_path_get_depth (path);
3362 pos = gtk_tree_path_get_indices (path)[depth - 1];
3365 ppath = gtk_tree_path_copy (path);
3366 gtk_tree_path_up (ppath);
3367 parent = find_menu_by_path (priv->popup_widget, ppath, FALSE);
3368 gtk_tree_path_free (ppath);
3370 menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (parent));
3373 menu = gtk_menu_new ();
3374 gtk_widget_show (menu);
3375 gtk_menu_item_set_submenu (GTK_MENU_ITEM (parent), menu);
3377 /* Ugly - since menus can only activate leaves, we have to
3378 * duplicate the item inside the submenu.
3380 gtk_tree_model_iter_parent (model, &piter, iter);
3381 item = gtk_cell_view_menu_item_new (combo_box, model, &piter);
3382 separator = gtk_separator_menu_item_new ();
3383 g_signal_connect (item, "activate",
3384 G_CALLBACK (gtk_combo_box_menu_item_activate),
3386 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
3387 gtk_menu_shell_append (GTK_MENU_SHELL (menu), separator);
3388 if (cell_view_is_sensitive (GTK_CELL_VIEW (GTK_BIN (item)->child)))
3390 gtk_widget_show (item);
3391 gtk_widget_show (separator);
3398 menu = priv->popup_widget;
3399 if (priv->add_tearoffs)
3403 if (priv->row_separator_func)
3404 is_separator = (*priv->row_separator_func) (model, iter,
3405 priv->row_separator_data);
3407 is_separator = FALSE;
3411 item = gtk_separator_menu_item_new ();
3412 g_object_set_data_full (G_OBJECT (item),
3413 I_("gtk-combo-box-item-path"),
3414 gtk_tree_row_reference_new (model, path),
3415 (GDestroyNotify)gtk_tree_row_reference_free);
3419 item = gtk_cell_view_menu_item_new (combo_box, model, iter);
3421 g_signal_connect (item, "activate",
3422 G_CALLBACK (gtk_combo_box_menu_item_activate),
3426 gtk_widget_show (item);
3427 gtk_menu_shell_insert (GTK_MENU_SHELL (menu), item, pos);
3431 gtk_combo_box_menu_row_deleted (GtkTreeModel *model,
3435 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3436 GtkComboBoxPrivate *priv = combo_box->priv;
3440 if (!priv->popup_widget)
3443 item = find_menu_by_path (priv->popup_widget, path, FALSE);
3444 menu = gtk_widget_get_parent (item);
3445 gtk_container_remove (GTK_CONTAINER (menu), item);
3447 if (gtk_tree_path_get_depth (path) > 1)
3449 GtkTreePath *parent_path;
3453 parent_path = gtk_tree_path_copy (path);
3454 gtk_tree_path_up (parent_path);
3455 gtk_tree_model_get_iter (model, &iter, parent_path);
3457 if (!gtk_tree_model_iter_has_child (model, &iter))
3459 parent = find_menu_by_path (priv->popup_widget,
3460 parent_path, FALSE);
3461 gtk_menu_item_set_submenu (GTK_MENU_ITEM (parent), NULL);
3467 gtk_combo_box_menu_rows_reordered (GtkTreeModel *model,
3473 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3475 gtk_combo_box_relayout (combo_box);
3479 gtk_combo_box_menu_row_changed (GtkTreeModel *model,
3484 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3485 GtkComboBoxPrivate *priv = combo_box->priv;
3488 gboolean is_separator;
3490 if (!priv->popup_widget)
3493 item = find_menu_by_path (priv->popup_widget, path, FALSE);
3495 if (priv->row_separator_func)
3496 is_separator = (*priv->row_separator_func) (model, iter,
3497 priv->row_separator_data);
3499 is_separator = FALSE;
3501 if (is_separator != GTK_IS_SEPARATOR_MENU_ITEM (item))
3503 gtk_combo_box_menu_row_deleted (model, path, combo_box);
3504 gtk_combo_box_menu_row_inserted (model, path, iter, combo_box);
3507 if (priv->wrap_width && item->parent == priv->popup_widget)
3509 GtkWidget *pitem = NULL;
3512 prev = gtk_tree_path_copy (path);
3514 if (gtk_tree_path_prev (prev))
3515 pitem = find_menu_by_path (priv->popup_widget, prev, FALSE);
3517 gtk_tree_path_free (prev);
3519 /* unattach item so gtk_combo_box_relayout_item() won't spuriously
3521 gtk_container_child_set (GTK_CONTAINER (priv->popup_widget),
3526 "bottom-attach", -1,
3529 gtk_combo_box_relayout_item (combo_box, item, iter, pitem);
3532 width = gtk_combo_box_calc_requested_width (combo_box, path);
3534 if (width > priv->width)
3536 if (priv->cell_view)
3538 gtk_widget_set_size_request (priv->cell_view, width, -1);
3539 gtk_widget_queue_resize (priv->cell_view);
3541 priv->width = width;
3550 gtk_combo_box_list_setup (GtkComboBox *combo_box)
3552 GtkComboBoxPrivate *priv = combo_box->priv;
3553 GtkTreeSelection *sel;
3555 priv->button = gtk_toggle_button_new ();
3556 gtk_widget_set_parent (priv->button,
3557 GTK_BIN (combo_box)->child->parent);
3558 g_signal_connect (priv->button, "button_press_event",
3559 G_CALLBACK (gtk_combo_box_list_button_pressed), combo_box);
3560 g_signal_connect (priv->button, "toggled",
3561 G_CALLBACK (gtk_combo_box_button_toggled), combo_box);
3563 priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
3564 gtk_container_add (GTK_CONTAINER (priv->button), priv->arrow);
3565 priv->separator = NULL;
3566 gtk_widget_show_all (priv->button);
3568 if (priv->cell_view)
3570 gtk_cell_view_set_background_color (GTK_CELL_VIEW (priv->cell_view),
3571 >K_WIDGET (combo_box)->style->base[GTK_WIDGET_STATE (combo_box)]);
3573 priv->box = gtk_event_box_new ();
3574 gtk_event_box_set_visible_window (GTK_EVENT_BOX (priv->box),
3577 if (priv->has_frame)
3579 priv->cell_view_frame = gtk_frame_new (NULL);
3580 gtk_frame_set_shadow_type (GTK_FRAME (priv->cell_view_frame),
3585 combo_box->priv->cell_view_frame = gtk_event_box_new ();
3586 gtk_event_box_set_visible_window (GTK_EVENT_BOX (combo_box->priv->cell_view_frame),
3590 gtk_widget_set_parent (priv->cell_view_frame,
3591 GTK_BIN (combo_box)->child->parent);
3592 gtk_container_add (GTK_CONTAINER (priv->cell_view_frame), priv->box);
3593 gtk_widget_show_all (priv->cell_view_frame);
3595 g_signal_connect (priv->box, "button_press_event",
3596 G_CALLBACK (gtk_combo_box_list_button_pressed),
3600 priv->tree_view = gtk_tree_view_new ();
3601 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view));
3602 gtk_tree_selection_set_mode (sel, GTK_SELECTION_BROWSE);
3603 gtk_tree_selection_set_select_function (sel,
3604 gtk_combo_box_list_select_func,
3606 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->tree_view),
3608 gtk_tree_view_set_hover_selection (GTK_TREE_VIEW (priv->tree_view),
3610 if (priv->row_separator_func)
3611 gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (priv->tree_view),
3612 priv->row_separator_func,
3613 priv->row_separator_data,
3616 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->tree_view), priv->model);
3618 priv->column = gtk_tree_view_column_new ();
3619 gtk_tree_view_append_column (GTK_TREE_VIEW (priv->tree_view), priv->column);
3622 gtk_combo_box_sync_cells (combo_box,
3623 GTK_CELL_LAYOUT (priv->column));
3625 if (gtk_tree_row_reference_valid (priv->active_row))
3629 path = gtk_tree_row_reference_get_path (priv->active_row);
3630 gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->tree_view),
3632 gtk_tree_path_free (path);
3635 /* set sample/popup widgets */
3636 gtk_combo_box_set_popup_widget (combo_box, priv->tree_view);
3638 g_signal_connect (priv->tree_view, "key_press_event",
3639 G_CALLBACK (gtk_combo_box_list_key_press),
3641 g_signal_connect (priv->tree_view, "enter_notify_event",
3642 G_CALLBACK (gtk_combo_box_list_enter_notify),
3644 g_signal_connect (priv->tree_view, "row_expanded",
3645 G_CALLBACK (gtk_combo_box_model_row_expanded),
3647 g_signal_connect (priv->tree_view, "row_collapsed",
3648 G_CALLBACK (gtk_combo_box_model_row_expanded),
3650 g_signal_connect (priv->popup_window, "button_press_event",
3651 G_CALLBACK (gtk_combo_box_list_button_pressed),
3653 g_signal_connect (priv->popup_window, "button_release_event",
3654 G_CALLBACK (gtk_combo_box_list_button_released),
3657 gtk_widget_show (priv->tree_view);
3661 gtk_combo_box_list_destroy (GtkComboBox *combo_box)
3663 GtkComboBoxPrivate *priv = combo_box->priv;
3665 /* disconnect signals */
3666 g_signal_handlers_disconnect_matched (priv->tree_view,
3667 G_SIGNAL_MATCH_DATA,
3668 0, 0, NULL, NULL, combo_box);
3669 g_signal_handlers_disconnect_matched (priv->button,
3670 G_SIGNAL_MATCH_DATA,
3672 gtk_combo_box_list_button_pressed,
3674 g_signal_handlers_disconnect_matched (priv->popup_window,
3675 G_SIGNAL_MATCH_DATA,
3677 gtk_combo_box_list_button_pressed,
3679 g_signal_handlers_disconnect_matched (priv->popup_window,
3680 G_SIGNAL_MATCH_DATA,
3682 gtk_combo_box_list_button_released,
3685 g_signal_handlers_disconnect_matched (priv->popup_window,
3686 G_SIGNAL_MATCH_DATA,
3688 gtk_combo_box_child_show,
3691 g_signal_handlers_disconnect_matched (priv->popup_window,
3692 G_SIGNAL_MATCH_DATA,
3694 gtk_combo_box_child_hide,
3698 g_signal_handlers_disconnect_matched (priv->box,
3699 G_SIGNAL_MATCH_DATA,
3701 gtk_combo_box_list_button_pressed,
3704 /* destroy things (unparent will kill the latest ref from us)
3705 * last unref on button will destroy the arrow
3707 gtk_widget_unparent (priv->button);
3708 priv->button = NULL;
3711 if (priv->cell_view)
3713 g_object_set (priv->cell_view,
3714 "background-set", FALSE,
3718 if (priv->cell_view_frame)
3720 gtk_widget_unparent (priv->cell_view_frame);
3721 priv->cell_view_frame = NULL;
3725 if (priv->scroll_timer)
3727 g_source_remove (priv->scroll_timer);
3728 priv->scroll_timer = 0;
3731 if (priv->resize_idle_id)
3733 g_source_remove (priv->resize_idle_id);
3734 priv->resize_idle_id = 0;
3737 gtk_widget_destroy (priv->tree_view);
3739 priv->tree_view = NULL;
3740 if (priv->popup_widget)
3742 g_object_unref (priv->popup_widget);
3743 priv->popup_widget = NULL;
3750 gtk_combo_box_list_button_pressed (GtkWidget *widget,
3751 GdkEventButton *event,
3754 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3755 GtkComboBoxPrivate *priv = combo_box->priv;
3757 GtkWidget *ewidget = gtk_get_event_widget ((GdkEvent *)event);
3759 if (ewidget == priv->popup_window)
3762 if ((ewidget != priv->button && ewidget != priv->box) ||
3763 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->button)))
3766 if (priv->focus_on_click &&
3767 !GTK_WIDGET_HAS_FOCUS (priv->button))
3768 gtk_widget_grab_focus (priv->button);
3770 gtk_combo_box_popup (combo_box);
3772 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->button), TRUE);
3774 priv->auto_scroll = FALSE;
3775 if (priv->scroll_timer == 0)
3776 priv->scroll_timer = gdk_threads_add_timeout (SCROLL_TIME,
3777 (GSourceFunc) gtk_combo_box_list_scroll_timeout,
3780 priv->popup_in_progress = TRUE;
3786 gtk_combo_box_list_button_released (GtkWidget *widget,
3787 GdkEventButton *event,
3791 GtkTreePath *path = NULL;
3794 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3795 GtkComboBoxPrivate *priv = combo_box->priv;
3797 gboolean popup_in_progress = FALSE;
3799 GtkWidget *ewidget = gtk_get_event_widget ((GdkEvent *)event);
3801 if (priv->popup_in_progress)
3803 popup_in_progress = TRUE;
3804 priv->popup_in_progress = FALSE;
3807 gtk_tree_view_set_hover_expand (GTK_TREE_VIEW (priv->tree_view),
3809 if (priv->scroll_timer)
3811 g_source_remove (priv->scroll_timer);
3812 priv->scroll_timer = 0;
3815 if (ewidget != priv->tree_view)
3817 if ((ewidget == priv->button ||
3818 ewidget == priv->box) &&
3819 !popup_in_progress &&
3820 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->button)))
3822 gtk_combo_box_popdown (combo_box);
3826 /* released outside treeview */
3827 if (ewidget != priv->button && ewidget != priv->box)
3829 gtk_combo_box_popdown (combo_box);
3837 /* select something cool */
3838 ret = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (priv->tree_view),
3844 return TRUE; /* clicked outside window? */
3846 gtk_tree_model_get_iter (priv->model, &iter, path);
3847 gtk_tree_path_free (path);
3849 gtk_combo_box_popdown (combo_box);
3851 if (tree_column_row_is_sensitive (combo_box, &iter))
3852 gtk_combo_box_set_active_iter (combo_box, &iter);
3858 gtk_combo_box_menu_key_press (GtkWidget *widget,
3862 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3864 if (!gtk_bindings_activate_event (GTK_OBJECT (widget), event))
3866 /* The menu hasn't managed the
3867 * event, forward it to the combobox
3869 gtk_bindings_activate_event (GTK_OBJECT (combo_box), event);
3876 gtk_combo_box_list_key_press (GtkWidget *widget,
3880 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3883 if (event->keyval == GDK_Return || event->keyval == GDK_ISO_Enter || event->keyval == GDK_KP_Enter ||
3884 event->keyval == GDK_space || event->keyval == GDK_KP_Space)
3886 GtkTreeModel *model = NULL;
3888 gtk_combo_box_popdown (combo_box);
3890 if (combo_box->priv->model)
3892 GtkTreeSelection *sel;
3894 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (combo_box->priv->tree_view));
3896 if (gtk_tree_selection_get_selected (sel, &model, &iter))
3897 gtk_combo_box_set_active_iter (combo_box, &iter);
3903 if (!gtk_bindings_activate_event (GTK_OBJECT (widget), event))
3905 /* The list hasn't managed the
3906 * event, forward it to the combobox
3908 gtk_bindings_activate_event (GTK_OBJECT (combo_box), event);
3915 gtk_combo_box_list_auto_scroll (GtkComboBox *combo_box,
3919 GtkWidget *tree_view = combo_box->priv->tree_view;
3923 adj = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (combo_box->priv->scrolled_window));
3924 if (adj && adj->upper - adj->lower > adj->page_size)
3926 if (x <= tree_view->allocation.x &&
3927 adj->lower < adj->value)
3929 value = adj->value - (tree_view->allocation.x - x + 1);
3930 gtk_adjustment_set_value (adj, CLAMP (value, adj->lower, adj->upper - adj->page_size));
3932 else if (x >= tree_view->allocation.x + tree_view->allocation.width &&
3933 adj->upper - adj->page_size > adj->value)
3935 value = adj->value + (x - tree_view->allocation.x - tree_view->allocation.width + 1);
3936 gtk_adjustment_set_value (adj, CLAMP (value, 0.0, adj->upper - adj->page_size));
3940 adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (combo_box->priv->scrolled_window));
3941 if (adj && adj->upper - adj->lower > adj->page_size)
3943 if (y <= tree_view->allocation.y &&
3944 adj->lower < adj->value)
3946 value = adj->value - (tree_view->allocation.y - y + 1);
3947 gtk_adjustment_set_value (adj, CLAMP (value, adj->lower, adj->upper - adj->page_size));
3949 else if (y >= tree_view->allocation.height &&
3950 adj->upper - adj->page_size > adj->value)
3952 value = adj->value + (y - tree_view->allocation.height + 1);
3953 gtk_adjustment_set_value (adj, CLAMP (value, 0.0, adj->upper - adj->page_size));
3959 gtk_combo_box_list_scroll_timeout (GtkComboBox *combo_box)
3961 GtkComboBoxPrivate *priv = combo_box->priv;
3964 if (priv->auto_scroll)
3966 gdk_window_get_pointer (priv->tree_view->window, &x, &y, NULL);
3967 gtk_combo_box_list_auto_scroll (combo_box, x, y);
3974 gtk_combo_box_list_enter_notify (GtkWidget *widget,
3975 GdkEventCrossing *event,
3978 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3980 combo_box->priv->auto_scroll = TRUE;
3986 gtk_combo_box_list_select_func (GtkTreeSelection *selection,
3987 GtkTreeModel *model,
3989 gboolean path_currently_selected,
3993 gboolean sensitive = FALSE;
3995 for (list = selection->tree_view->priv->columns; list && !sensitive; list = list->next)
3997 GList *cells, *cell;
3998 gboolean cell_sensitive, cell_visible;
4000 GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN (list->data);
4002 if (!column->visible)
4005 gtk_tree_model_get_iter (model, &iter, path);
4006 gtk_tree_view_column_cell_set_cell_data (column, model, &iter,
4009 cell = cells = gtk_tree_view_column_get_cell_renderers (column);
4012 g_object_get (cell->data,
4013 "sensitive", &cell_sensitive,
4014 "visible", &cell_visible,
4017 if (cell_visible && cell_sensitive)
4022 g_list_free (cells);
4024 sensitive = cell_sensitive;
4031 gtk_combo_box_list_row_changed (GtkTreeModel *model,
4036 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
4037 GtkComboBoxPrivate *priv = combo_box->priv;
4040 width = gtk_combo_box_calc_requested_width (combo_box, path);
4042 if (width > priv->width)
4044 if (priv->cell_view)
4046 gtk_widget_set_size_request (priv->cell_view, width, -1);
4047 gtk_widget_queue_resize (priv->cell_view);
4049 priv->width = width;
4054 * GtkCellLayout implementation
4058 pack_start_recurse (GtkWidget *menu,
4059 GtkCellRenderer *cell,
4065 list = gtk_container_get_children (GTK_CONTAINER (menu));
4066 for (i = list; i; i = i->next)
4068 if (GTK_IS_CELL_LAYOUT (GTK_BIN (i->data)->child))
4069 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (GTK_BIN (i->data)->child),
4072 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4073 if (submenu != NULL)
4074 pack_start_recurse (submenu, cell, expand);
4081 gtk_combo_box_cell_layout_pack_start (GtkCellLayout *layout,
4082 GtkCellRenderer *cell,
4085 GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
4086 ComboCellInfo *info;
4087 GtkComboBoxPrivate *priv;
4089 priv = combo_box->priv;
4091 g_object_ref_sink (cell);
4093 info = g_new0 (ComboCellInfo, 1);
4095 info->expand = expand;
4096 info->pack = GTK_PACK_START;
4098 priv->cells = g_slist_append (priv->cells, info);
4100 if (priv->cell_view)
4101 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (priv->cell_view),
4105 gtk_tree_view_column_pack_start (priv->column, cell, expand);
4107 if (GTK_IS_MENU (priv->popup_widget))
4108 pack_start_recurse (priv->popup_widget, cell, expand);
4112 pack_end_recurse (GtkWidget *menu,
4113 GtkCellRenderer *cell,
4119 list = gtk_container_get_children (GTK_CONTAINER (menu));
4120 for (i = list; i; i = i->next)
4122 if (GTK_IS_CELL_LAYOUT (GTK_BIN (i->data)->child))
4123 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (GTK_BIN (i->data)->child),
4126 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4127 if (submenu != NULL)
4128 pack_end_recurse (submenu, cell, expand);
4135 gtk_combo_box_cell_layout_pack_end (GtkCellLayout *layout,
4136 GtkCellRenderer *cell,
4139 GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
4140 ComboCellInfo *info;
4141 GtkComboBoxPrivate *priv;
4143 priv = combo_box->priv;
4145 g_object_ref_sink (cell);
4147 info = g_new0 (ComboCellInfo, 1);
4149 info->expand = expand;
4150 info->pack = GTK_PACK_END;
4152 priv->cells = g_slist_append (priv->cells, info);
4154 if (priv->cell_view)
4155 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (priv->cell_view),
4159 gtk_tree_view_column_pack_end (priv->column, cell, expand);
4161 if (GTK_IS_MENU (priv->popup_widget))
4162 pack_end_recurse (priv->popup_widget, cell, expand);
4166 gtk_combo_box_cell_layout_get_cells (GtkCellLayout *layout)
4168 GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
4170 GList *retval = NULL;
4172 for (list = combo_box->priv->cells; list; list = list->next)
4174 ComboCellInfo *info = (ComboCellInfo *)list->data;
4176 retval = g_list_prepend (retval, info->cell);
4179 return g_list_reverse (retval);
4183 clear_recurse (GtkWidget *menu)
4188 list = gtk_container_get_children (GTK_CONTAINER (menu));
4189 for (i = list; i; i = i->next)
4191 if (GTK_IS_CELL_LAYOUT (GTK_BIN (i->data)->child))
4192 gtk_cell_layout_clear (GTK_CELL_LAYOUT (GTK_BIN (i->data)->child));
4194 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4195 if (submenu != NULL)
4196 clear_recurse (submenu);
4203 gtk_combo_box_cell_layout_clear (GtkCellLayout *layout)
4205 GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
4206 GtkComboBoxPrivate *priv = combo_box->priv;
4209 if (priv->cell_view)
4210 gtk_cell_layout_clear (GTK_CELL_LAYOUT (priv->cell_view));
4213 gtk_tree_view_column_clear (priv->column);
4215 for (i = priv->cells; i; i = i->next)
4217 ComboCellInfo *info = (ComboCellInfo *)i->data;
4219 gtk_combo_box_cell_layout_clear_attributes (layout, info->cell);
4220 g_object_unref (info->cell);
4224 g_slist_free (priv->cells);
4227 if (GTK_IS_MENU (priv->popup_widget))
4228 clear_recurse (priv->popup_widget);
4232 add_attribute_recurse (GtkWidget *menu,
4233 GtkCellRenderer *cell,
4234 const gchar *attribute,
4240 list = gtk_container_get_children (GTK_CONTAINER (menu));
4241 for (i = list; i; i = i->next)
4243 if (GTK_IS_CELL_LAYOUT (GTK_BIN (i->data)->child))
4244 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (GTK_BIN (i->data)->child),
4245 cell, attribute, column);
4247 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4248 if (submenu != NULL)
4249 add_attribute_recurse (submenu, cell, attribute, column);
4256 gtk_combo_box_cell_layout_add_attribute (GtkCellLayout *layout,
4257 GtkCellRenderer *cell,
4258 const gchar *attribute,
4261 GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
4262 ComboCellInfo *info;
4264 info = gtk_combo_box_get_cell_info (combo_box, cell);
4265 g_return_if_fail (info != NULL);
4267 info->attributes = g_slist_prepend (info->attributes,
4268 GINT_TO_POINTER (column));
4269 info->attributes = g_slist_prepend (info->attributes,
4270 g_strdup (attribute));
4272 if (combo_box->priv->cell_view)
4273 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo_box->priv->cell_view),
4274 cell, attribute, column);
4276 if (combo_box->priv->column)
4277 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo_box->priv->column),
4278 cell, attribute, column);
4280 if (GTK_IS_MENU (combo_box->priv->popup_widget))
4281 add_attribute_recurse (combo_box->priv->popup_widget, cell, attribute, column);
4282 gtk_widget_queue_resize (GTK_WIDGET (combo_box));
4286 combo_cell_data_func (GtkCellLayout *cell_layout,
4287 GtkCellRenderer *cell,
4288 GtkTreeModel *tree_model,
4292 ComboCellInfo *info = (ComboCellInfo *)data;
4293 GtkWidget *parent = NULL;
4298 (*info->func) (cell_layout, cell, tree_model, iter, info->func_data);
4300 if (GTK_IS_WIDGET (cell_layout))
4301 parent = gtk_widget_get_parent (GTK_WIDGET (cell_layout));
4303 if (GTK_IS_MENU_ITEM (parent) &&
4304 gtk_menu_item_get_submenu (GTK_MENU_ITEM (parent)))
4305 g_object_set (cell, "sensitive", TRUE, NULL);
4310 set_cell_data_func_recurse (GtkWidget *menu,
4311 GtkCellRenderer *cell,
4312 ComboCellInfo *info)
4316 GtkWidget *cell_view;
4318 list = gtk_container_get_children (GTK_CONTAINER (menu));
4319 for (i = list; i; i = i->next)
4321 cell_view = GTK_BIN (i->data)->child;
4322 if (GTK_IS_CELL_LAYOUT (cell_view))
4324 /* Override sensitivity for inner nodes; we don't
4325 * want menuitems with submenus to appear insensitive
4327 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (cell_view),
4329 combo_cell_data_func,
4331 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4332 if (submenu != NULL)
4333 set_cell_data_func_recurse (submenu, cell, info);
4341 gtk_combo_box_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4342 GtkCellRenderer *cell,
4343 GtkCellLayoutDataFunc func,
4345 GDestroyNotify destroy)
4347 GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
4348 GtkComboBoxPrivate *priv = combo_box->priv;
4349 ComboCellInfo *info;
4351 info = gtk_combo_box_get_cell_info (combo_box, cell);
4352 g_return_if_fail (info != NULL);
4356 GDestroyNotify d = info->destroy;
4358 info->destroy = NULL;
4359 d (info->func_data);
4363 info->func_data = func_data;
4364 info->destroy = destroy;
4366 if (priv->cell_view)
4367 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (priv->cell_view), cell, func, func_data, NULL);
4370 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (priv->column), cell, func, func_data, NULL);
4372 if (GTK_IS_MENU (priv->popup_widget))
4373 set_cell_data_func_recurse (priv->popup_widget, cell, info);
4375 gtk_widget_queue_resize (GTK_WIDGET (combo_box));
4379 clear_attributes_recurse (GtkWidget *menu,
4380 GtkCellRenderer *cell)
4385 list = gtk_container_get_children (GTK_CONTAINER (menu));
4386 for (i = list; i; i = i->next)
4388 if (GTK_IS_CELL_LAYOUT (GTK_BIN (i->data)->child))
4389 gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (GTK_BIN (i->data)->child),
4392 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4393 if (submenu != NULL)
4394 clear_attributes_recurse (submenu, cell);
4401 gtk_combo_box_cell_layout_clear_attributes (GtkCellLayout *layout,
4402 GtkCellRenderer *cell)
4404 GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
4405 GtkComboBoxPrivate *priv;
4406 ComboCellInfo *info;
4409 priv = combo_box->priv;
4411 info = gtk_combo_box_get_cell_info (combo_box, cell);
4412 g_return_if_fail (info != NULL);
4414 list = info->attributes;
4415 while (list && list->next)
4417 g_free (list->data);
4418 list = list->next->next;
4420 g_slist_free (info->attributes);
4421 info->attributes = NULL;
4423 if (priv->cell_view)
4424 gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (priv->cell_view), cell);
4427 gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (priv->column), cell);
4429 if (GTK_IS_MENU (priv->popup_widget))
4430 clear_attributes_recurse (priv->popup_widget, cell);
4432 gtk_widget_queue_resize (GTK_WIDGET (combo_box));
4436 reorder_recurse (GtkWidget *menu,
4437 GtkCellRenderer *cell,
4443 list = gtk_container_get_children (GTK_CONTAINER (menu));
4444 for (i = list; i; i = i->next)
4446 if (GTK_IS_CELL_LAYOUT (GTK_BIN (i->data)->child))
4447 gtk_cell_layout_reorder (GTK_CELL_LAYOUT (GTK_BIN (i->data)->child),
4450 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4451 if (submenu != NULL)
4452 reorder_recurse (submenu, cell, position);
4459 gtk_combo_box_cell_layout_reorder (GtkCellLayout *layout,
4460 GtkCellRenderer *cell,
4463 GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
4464 GtkComboBoxPrivate *priv;
4465 ComboCellInfo *info;
4468 priv = combo_box->priv;
4470 info = gtk_combo_box_get_cell_info (combo_box, cell);
4472 g_return_if_fail (info != NULL);
4473 g_return_if_fail (position >= 0);
4475 link = g_slist_find (priv->cells, info);
4477 g_return_if_fail (link != NULL);
4479 priv->cells = g_slist_delete_link (priv->cells, link);
4480 priv->cells = g_slist_insert (priv->cells, info, position);
4482 if (priv->cell_view)
4483 gtk_cell_layout_reorder (GTK_CELL_LAYOUT (priv->cell_view),
4487 gtk_cell_layout_reorder (GTK_CELL_LAYOUT (priv->column),
4490 if (GTK_IS_MENU (priv->popup_widget))
4491 reorder_recurse (priv->popup_widget, cell, position);
4493 gtk_widget_queue_draw (GTK_WIDGET (combo_box));
4501 * gtk_combo_box_new:
4503 * Creates a new empty #GtkComboBox.
4505 * Return value: A new #GtkComboBox.
4510 gtk_combo_box_new (void)
4512 return g_object_new (GTK_TYPE_COMBO_BOX, NULL);
4516 * gtk_combo_box_new_with_model:
4517 * @model: A #GtkTreeModel.
4519 * Creates a new #GtkComboBox with the model initialized to @model.
4521 * Return value: A new #GtkComboBox.
4526 gtk_combo_box_new_with_model (GtkTreeModel *model)
4528 GtkComboBox *combo_box;
4530 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
4532 combo_box = g_object_new (GTK_TYPE_COMBO_BOX, "model", model, NULL);
4534 return GTK_WIDGET (combo_box);
4538 * gtk_combo_box_get_wrap_width:
4539 * @combo_box: A #GtkComboBox
4541 * Returns the wrap width which is used to determine the number of columns
4542 * for the popup menu. If the wrap width is larger than 1, the combo box
4545 * Returns: the wrap width.
4550 gtk_combo_box_get_wrap_width (GtkComboBox *combo_box)
4552 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), -1);
4554 return combo_box->priv->wrap_width;
4558 * gtk_combo_box_set_wrap_width:
4559 * @combo_box: A #GtkComboBox
4560 * @width: Preferred number of columns
4562 * Sets the wrap width of @combo_box to be @width. The wrap width is basically
4563 * the preferred number of columns when you want the popup to be layed out
4569 gtk_combo_box_set_wrap_width (GtkComboBox *combo_box,
4572 GtkComboBoxPrivate *priv;
4574 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4575 g_return_if_fail (width >= 0);
4577 priv = combo_box->priv;
4579 if (width != priv->wrap_width)
4581 priv->wrap_width = width;
4583 gtk_combo_box_check_appearance (combo_box);
4584 gtk_combo_box_relayout (combo_box);
4586 g_object_notify (G_OBJECT (combo_box), "wrap-width");
4591 * gtk_combo_box_get_row_span_column:
4592 * @combo_box: A #GtkComboBox
4594 * Returns the column with row span information for @combo_box.
4596 * Returns: the row span column.
4601 gtk_combo_box_get_row_span_column (GtkComboBox *combo_box)
4603 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), -1);
4605 return combo_box->priv->row_column;
4609 * gtk_combo_box_set_row_span_column:
4610 * @combo_box: A #GtkComboBox.
4611 * @row_span: A column in the model passed during construction.
4613 * Sets the column with row span information for @combo_box to be @row_span.
4614 * The row span column contains integers which indicate how many rows
4615 * an item should span.
4620 gtk_combo_box_set_row_span_column (GtkComboBox *combo_box,
4623 GtkComboBoxPrivate *priv;
4626 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4628 priv = combo_box->priv;
4630 col = gtk_tree_model_get_n_columns (priv->model);
4631 g_return_if_fail (row_span >= -1 && row_span < col);
4633 if (row_span != priv->row_column)
4635 priv->row_column = row_span;
4637 gtk_combo_box_relayout (combo_box);
4639 g_object_notify (G_OBJECT (combo_box), "row-span-column");
4644 * gtk_combo_box_get_column_span_column:
4645 * @combo_box: A #GtkComboBox
4647 * Returns the column with column span information for @combo_box.
4649 * Returns: the column span column.
4654 gtk_combo_box_get_column_span_column (GtkComboBox *combo_box)
4656 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), -1);
4658 return combo_box->priv->col_column;
4662 * gtk_combo_box_set_column_span_column:
4663 * @combo_box: A #GtkComboBox
4664 * @column_span: A column in the model passed during construction
4666 * Sets the column with column span information for @combo_box to be
4667 * @column_span. The column span column contains integers which indicate
4668 * how many columns an item should span.
4673 gtk_combo_box_set_column_span_column (GtkComboBox *combo_box,
4676 GtkComboBoxPrivate *priv;
4679 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4681 priv = combo_box->priv;
4683 col = gtk_tree_model_get_n_columns (priv->model);
4684 g_return_if_fail (column_span >= -1 && column_span < col);
4686 if (column_span != priv->col_column)
4688 priv->col_column = column_span;
4690 gtk_combo_box_relayout (combo_box);
4692 g_object_notify (G_OBJECT (combo_box), "column-span-column");
4697 * gtk_combo_box_get_active:
4698 * @combo_box: A #GtkComboBox
4700 * Returns the index of the currently active item, or -1 if there's no
4701 * active item. If the model is a non-flat treemodel, and the active item
4702 * is not an immediate child of the root of the tree, this function returns
4703 * <literal>gtk_tree_path_get_indices (path)[0]</literal>, where
4704 * <literal>path</literal> is the #GtkTreePath of the active item.
4706 * Return value: An integer which is the index of the currently active item,
4707 * or -1 if there's no active item.
4712 gtk_combo_box_get_active (GtkComboBox *combo_box)
4714 GtkComboBoxPrivate *priv;
4717 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), 0);
4719 priv = combo_box->priv;
4721 if (gtk_tree_row_reference_valid (priv->active_row))
4725 path = gtk_tree_row_reference_get_path (priv->active_row);
4726 result = gtk_tree_path_get_indices (path)[0];
4727 gtk_tree_path_free (path);
4736 * gtk_combo_box_set_active:
4737 * @combo_box: A #GtkComboBox
4738 * @index_: An index in the model passed during construction, or -1 to have
4741 * Sets the active item of @combo_box to be the item at @index.
4746 gtk_combo_box_set_active (GtkComboBox *combo_box,
4749 GtkTreePath *path = NULL;
4750 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4751 g_return_if_fail (index_ >= -1);
4754 path = gtk_tree_path_new_from_indices (index_, -1);
4756 gtk_combo_box_set_active_internal (combo_box, path);
4759 gtk_tree_path_free (path);
4763 gtk_combo_box_set_active_internal (GtkComboBox *combo_box,
4766 GtkComboBoxPrivate *priv = combo_box->priv;
4767 GtkTreePath *active_path;
4770 if (path && gtk_tree_row_reference_valid (priv->active_row))
4772 active_path = gtk_tree_row_reference_get_path (priv->active_row);
4773 path_cmp = gtk_tree_path_compare (path, active_path);
4774 gtk_tree_path_free (active_path);
4779 if (priv->active_row)
4781 gtk_tree_row_reference_free (priv->active_row);
4782 priv->active_row = NULL;
4787 if (priv->tree_view)
4788 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view)));
4791 GtkMenu *menu = GTK_MENU (priv->popup_widget);
4793 if (GTK_IS_MENU (menu))
4794 gtk_menu_set_active (menu, -1);
4797 if (priv->cell_view)
4798 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (priv->cell_view), NULL);
4803 gtk_tree_row_reference_new (priv->model, path);
4805 if (priv->tree_view)
4807 gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->tree_view),
4810 else if (GTK_IS_MENU (priv->popup_widget))
4812 /* FIXME handle nested menus better */
4813 gtk_menu_set_active (GTK_MENU (priv->popup_widget),
4814 gtk_tree_path_get_indices (path)[0]);
4817 if (priv->cell_view)
4818 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (priv->cell_view),
4822 g_signal_emit (combo_box, combo_box_signals[CHANGED], 0);
4823 g_object_notify (G_OBJECT (combo_box), "active");
4828 * gtk_combo_box_get_active_iter:
4829 * @combo_box: A #GtkComboBox
4830 * @iter: The uninitialized #GtkTreeIter
4832 * Sets @iter to point to the current active item, if it exists.
4834 * Return value: %TRUE, if @iter was set
4839 gtk_combo_box_get_active_iter (GtkComboBox *combo_box,
4845 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE);
4847 if (!gtk_tree_row_reference_valid (combo_box->priv->active_row))
4850 path = gtk_tree_row_reference_get_path (combo_box->priv->active_row);
4851 result = gtk_tree_model_get_iter (combo_box->priv->model, iter, path);
4852 gtk_tree_path_free (path);
4858 * gtk_combo_box_set_active_iter:
4859 * @combo_box: A #GtkComboBox
4860 * @iter: The #GtkTreeIter
4862 * Sets the current active item to be the one referenced by @iter.
4863 * @iter must correspond to a path of depth one.
4868 gtk_combo_box_set_active_iter (GtkComboBox *combo_box,
4873 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4875 path = gtk_tree_model_get_path (gtk_combo_box_get_model (combo_box), iter);
4876 gtk_combo_box_set_active_internal (combo_box, path);
4877 gtk_tree_path_free (path);
4881 * gtk_combo_box_set_model:
4882 * @combo_box: A #GtkComboBox
4883 * @model: A #GtkTreeModel
4885 * Sets the model used by @combo_box to be @model. Will unset a previously set
4886 * model (if applicable). If model is %NULL, then it will unset the model.
4888 * Note that this function does not clear the cell renderers, you have to
4889 * call gtk_cell_layout_clear() yourself if you need to set up different
4890 * cell renderers for the new model.
4895 gtk_combo_box_set_model (GtkComboBox *combo_box,
4896 GtkTreeModel *model)
4898 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4899 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
4901 if (model == combo_box->priv->model)
4904 gtk_combo_box_unset_model (combo_box);
4909 combo_box->priv->model = model;
4910 g_object_ref (combo_box->priv->model);
4912 combo_box->priv->inserted_id =
4913 g_signal_connect (combo_box->priv->model, "row_inserted",
4914 G_CALLBACK (gtk_combo_box_model_row_inserted),
4916 combo_box->priv->deleted_id =
4917 g_signal_connect (combo_box->priv->model, "row_deleted",
4918 G_CALLBACK (gtk_combo_box_model_row_deleted),
4920 combo_box->priv->reordered_id =
4921 g_signal_connect (combo_box->priv->model, "rows_reordered",
4922 G_CALLBACK (gtk_combo_box_model_rows_reordered),
4924 combo_box->priv->changed_id =
4925 g_signal_connect (combo_box->priv->model, "row_changed",
4926 G_CALLBACK (gtk_combo_box_model_row_changed),
4929 if (combo_box->priv->tree_view)
4932 gtk_tree_view_set_model (GTK_TREE_VIEW (combo_box->priv->tree_view),
4933 combo_box->priv->model);
4934 gtk_combo_box_list_popup_resize (combo_box);
4939 if (combo_box->priv->popup_widget)
4940 gtk_combo_box_menu_fill (combo_box);
4944 if (combo_box->priv->cell_view)
4945 gtk_cell_view_set_model (GTK_CELL_VIEW (combo_box->priv->cell_view),
4946 combo_box->priv->model);
4949 g_object_notify (G_OBJECT (combo_box), "model");
4953 * gtk_combo_box_get_model
4954 * @combo_box: A #GtkComboBox
4956 * Returns the #GtkTreeModel which is acting as data source for @combo_box.
4958 * Return value: A #GtkTreeModel which was passed during construction.
4963 gtk_combo_box_get_model (GtkComboBox *combo_box)
4965 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
4967 return combo_box->priv->model;
4971 /* convenience API for simple text combos */
4974 * gtk_combo_box_new_text:
4976 * Convenience function which constructs a new text combo box, which is a
4977 * #GtkComboBox just displaying strings. If you use this function to create
4978 * a text combo box, you should only manipulate its data source with the
4979 * following convenience functions: gtk_combo_box_append_text(),
4980 * gtk_combo_box_insert_text(), gtk_combo_box_prepend_text() and
4981 * gtk_combo_box_remove_text().
4983 * Return value: A new text combo box.
4988 gtk_combo_box_new_text (void)
4990 GtkWidget *combo_box;
4991 GtkCellRenderer *cell;
4992 GtkListStore *store;
4994 store = gtk_list_store_new (1, G_TYPE_STRING);
4995 combo_box = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));
4996 g_object_unref (store);
4998 cell = gtk_cell_renderer_text_new ();
4999 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), cell, TRUE);
5000 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), cell,
5008 * gtk_combo_box_append_text:
5009 * @combo_box: A #GtkComboBox constructed using gtk_combo_box_new_text()
5012 * Appends @string to the list of strings stored in @combo_box. Note that
5013 * you can only use this function with combo boxes constructed with
5014 * gtk_combo_box_new_text().
5019 gtk_combo_box_append_text (GtkComboBox *combo_box,
5023 GtkListStore *store;
5025 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5026 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
5027 g_return_if_fail (text != NULL);
5029 store = GTK_LIST_STORE (combo_box->priv->model);
5031 gtk_list_store_append (store, &iter);
5032 gtk_list_store_set (store, &iter, 0, text, -1);
5036 * gtk_combo_box_insert_text:
5037 * @combo_box: A #GtkComboBox constructed using gtk_combo_box_new_text()
5038 * @position: An index to insert @text
5041 * Inserts @string at @position in the list of strings stored in @combo_box.
5042 * Note that you can only use this function with combo boxes constructed
5043 * with gtk_combo_box_new_text().
5048 gtk_combo_box_insert_text (GtkComboBox *combo_box,
5053 GtkListStore *store;
5055 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5056 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
5057 g_return_if_fail (position >= 0);
5058 g_return_if_fail (text != NULL);
5060 store = GTK_LIST_STORE (combo_box->priv->model);
5062 gtk_list_store_insert (store, &iter, position);
5063 gtk_list_store_set (store, &iter, 0, text, -1);
5067 * gtk_combo_box_prepend_text:
5068 * @combo_box: A #GtkComboBox constructed with gtk_combo_box_new_text()
5071 * Prepends @string to the list of strings stored in @combo_box. Note that
5072 * you can only use this function with combo boxes constructed with
5073 * gtk_combo_box_new_text().
5078 gtk_combo_box_prepend_text (GtkComboBox *combo_box,
5082 GtkListStore *store;
5084 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5085 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
5086 g_return_if_fail (text != NULL);
5088 store = GTK_LIST_STORE (combo_box->priv->model);
5090 gtk_list_store_prepend (store, &iter);
5091 gtk_list_store_set (store, &iter, 0, text, -1);
5095 * gtk_combo_box_remove_text:
5096 * @combo_box: A #GtkComboBox constructed with gtk_combo_box_new_text()
5097 * @position: Index of the item to remove
5099 * Removes the string at @position from @combo_box. Note that you can only use
5100 * this function with combo boxes constructed with gtk_combo_box_new_text().
5105 gtk_combo_box_remove_text (GtkComboBox *combo_box,
5109 GtkListStore *store;
5111 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5112 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
5113 g_return_if_fail (position >= 0);
5115 store = GTK_LIST_STORE (combo_box->priv->model);
5117 if (gtk_tree_model_iter_nth_child (combo_box->priv->model, &iter,
5119 gtk_list_store_remove (store, &iter);
5123 * gtk_combo_box_get_active_text:
5124 * @combo_box: A #GtkComboBox constructed with gtk_combo_box_new_text()
5126 * Returns the currently active string in @combo_box or %NULL if none
5127 * is selected. Note that you can only use this function with combo
5128 * boxes constructed with gtk_combo_box_new_text() and with
5129 * #GtkComboBoxEntry<!-- -->s.
5131 * Returns: a newly allocated string containing the currently active text.
5136 gtk_combo_box_get_active_text (GtkComboBox *combo_box)
5138 GtkComboBoxClass *class;
5140 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
5142 class = GTK_COMBO_BOX_GET_CLASS (combo_box);
5144 if (class->get_active_text)
5145 return (* class->get_active_text) (combo_box);
5151 gtk_combo_box_real_get_active_text (GtkComboBox *combo_box)
5156 g_return_val_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model), NULL);
5158 if (gtk_combo_box_get_active_iter (combo_box, &iter))
5159 gtk_tree_model_get (combo_box->priv->model, &iter,
5166 gtk_combo_box_real_move_active (GtkComboBox *combo_box,
5167 GtkScrollType scroll)
5170 GtkTreeIter new_iter;
5171 gboolean active_iter;
5174 if (!combo_box->priv->model)
5176 gtk_widget_error_bell (GTK_WIDGET (combo_box));
5180 active_iter = gtk_combo_box_get_active_iter (combo_box, &iter);
5184 case GTK_SCROLL_STEP_BACKWARD:
5185 case GTK_SCROLL_STEP_UP:
5186 case GTK_SCROLL_STEP_LEFT:
5189 found = tree_prev (combo_box, combo_box->priv->model,
5190 &iter, &new_iter, FALSE);
5193 /* else fall through */
5195 case GTK_SCROLL_PAGE_FORWARD:
5196 case GTK_SCROLL_PAGE_DOWN:
5197 case GTK_SCROLL_PAGE_RIGHT:
5198 case GTK_SCROLL_END:
5199 found = tree_last (combo_box, combo_box->priv->model, &new_iter, FALSE);
5202 case GTK_SCROLL_STEP_FORWARD:
5203 case GTK_SCROLL_STEP_DOWN:
5204 case GTK_SCROLL_STEP_RIGHT:
5207 found = tree_next (combo_box, combo_box->priv->model,
5208 &iter, &new_iter, FALSE);
5211 /* else fall through */
5213 case GTK_SCROLL_PAGE_BACKWARD:
5214 case GTK_SCROLL_PAGE_UP:
5215 case GTK_SCROLL_PAGE_LEFT:
5216 case GTK_SCROLL_START:
5217 found = tree_first (combo_box, combo_box->priv->model, &new_iter, FALSE);
5224 if (found && active_iter)
5226 GtkTreePath *old_path;
5227 GtkTreePath *new_path;
5229 old_path = gtk_tree_model_get_path (combo_box->priv->model, &iter);
5230 new_path = gtk_tree_model_get_path (combo_box->priv->model, &new_iter);
5232 if (gtk_tree_path_compare (old_path, new_path) == 0)
5235 gtk_tree_path_free (old_path);
5236 gtk_tree_path_free (new_path);
5241 gtk_combo_box_set_active_iter (combo_box, &new_iter);
5245 gtk_widget_error_bell (GTK_WIDGET (combo_box));
5250 gtk_combo_box_mnemonic_activate (GtkWidget *widget,
5251 gboolean group_cycling)
5253 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
5255 gtk_widget_grab_focus (combo_box->priv->button);
5261 gtk_combo_box_grab_focus (GtkWidget *widget)
5263 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
5265 gtk_widget_grab_focus (combo_box->priv->button);
5269 gtk_combo_box_destroy (GtkObject *object)
5271 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
5273 if (combo_box->priv->popup_idle_id > 0)
5275 g_source_remove (combo_box->priv->popup_idle_id);
5276 combo_box->priv->popup_idle_id = 0;
5279 gtk_combo_box_popdown (combo_box);
5281 if (combo_box->priv->row_separator_destroy)
5282 (* combo_box->priv->row_separator_destroy) (combo_box->priv->row_separator_data);
5284 combo_box->priv->row_separator_func = NULL;
5285 combo_box->priv->row_separator_data = NULL;
5286 combo_box->priv->row_separator_destroy = NULL;
5288 GTK_OBJECT_CLASS (gtk_combo_box_parent_class)->destroy (object);
5289 combo_box->priv->cell_view = NULL;
5293 gtk_combo_box_dispose(GObject* object)
5295 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
5297 if (GTK_IS_MENU (combo_box->priv->popup_widget))
5299 gtk_combo_box_menu_destroy (combo_box);
5300 gtk_menu_detach (GTK_MENU (combo_box->priv->popup_widget));
5301 combo_box->priv->popup_widget = NULL;
5304 G_OBJECT_CLASS (gtk_combo_box_parent_class)->dispose (object);
5308 gtk_combo_box_finalize (GObject *object)
5310 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
5313 if (GTK_IS_TREE_VIEW (combo_box->priv->tree_view))
5314 gtk_combo_box_list_destroy (combo_box);
5316 if (combo_box->priv->popup_window)
5317 gtk_widget_destroy (combo_box->priv->popup_window);
5319 gtk_combo_box_unset_model (combo_box);
5321 for (i = combo_box->priv->cells; i; i = i->next)
5323 ComboCellInfo *info = (ComboCellInfo *)i->data;
5324 GSList *list = info->attributes;
5327 info->destroy (info->func_data);
5329 while (list && list->next)
5331 g_free (list->data);
5332 list = list->next->next;
5334 g_slist_free (info->attributes);
5336 g_object_unref (info->cell);
5339 g_slist_free (combo_box->priv->cells);
5341 g_free (combo_box->priv->tearoff_title);
5343 G_OBJECT_CLASS (gtk_combo_box_parent_class)->finalize (object);
5347 gtk_cell_editable_key_press (GtkWidget *widget,
5351 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
5353 if (event->keyval == GDK_Escape)
5355 combo_box->priv->editing_canceled = TRUE;
5357 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (combo_box));
5358 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (combo_box));
5362 else if (event->keyval == GDK_Return ||
5363 event->keyval == GDK_ISO_Enter ||
5364 event->keyval == GDK_KP_Enter)
5366 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (combo_box));
5367 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (combo_box));
5376 popdown_idle (gpointer data)
5378 GtkComboBox *combo_box;
5380 combo_box = GTK_COMBO_BOX (data);
5382 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (combo_box));
5383 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (combo_box));
5385 g_object_unref (combo_box);
5391 popdown_handler (GtkWidget *widget,
5394 gdk_threads_add_idle (popdown_idle, g_object_ref (data));
5398 popup_idle (gpointer data)
5400 GtkComboBox *combo_box;
5402 combo_box = GTK_COMBO_BOX (data);
5404 if (GTK_IS_MENU (combo_box->priv->popup_widget) &&
5405 combo_box->priv->cell_view)
5406 g_signal_connect_object (combo_box->priv->popup_widget,
5407 "unmap", G_CALLBACK (popdown_handler),
5410 /* we unset this if a menu item is activated */
5411 combo_box->priv->editing_canceled = TRUE;
5412 gtk_combo_box_popup (combo_box);
5414 combo_box->priv->popup_idle_id = 0;
5415 combo_box->priv->activate_button = 0;
5416 combo_box->priv->activate_time = 0;
5422 gtk_combo_box_start_editing (GtkCellEditable *cell_editable,
5425 GtkComboBox *combo_box = GTK_COMBO_BOX (cell_editable);
5427 combo_box->priv->is_cell_renderer = TRUE;
5429 if (combo_box->priv->cell_view)
5431 g_signal_connect_object (combo_box->priv->button, "key_press_event",
5432 G_CALLBACK (gtk_cell_editable_key_press),
5435 gtk_widget_grab_focus (combo_box->priv->button);
5439 g_signal_connect_object (GTK_BIN (combo_box)->child, "key_press_event",
5440 G_CALLBACK (gtk_cell_editable_key_press),
5443 gtk_widget_grab_focus (GTK_WIDGET (GTK_BIN (combo_box)->child));
5444 GTK_WIDGET_UNSET_FLAGS (combo_box->priv->button, GTK_CAN_FOCUS);
5447 /* we do the immediate popup only for the optionmenu-like
5450 if (combo_box->priv->is_cell_renderer &&
5451 combo_box->priv->cell_view && !combo_box->priv->tree_view)
5453 if (event && event->type == GDK_BUTTON_PRESS)
5455 GdkEventButton *event_button = (GdkEventButton *)event;
5457 combo_box->priv->activate_button = event_button->button;
5458 combo_box->priv->activate_time = event_button->time;
5461 combo_box->priv->popup_idle_id =
5462 gdk_threads_add_idle (popup_idle, combo_box);
5468 * gtk_combo_box_get_add_tearoffs:
5469 * @combo_box: a #GtkComboBox
5471 * Gets the current value of the :add-tearoffs property.
5473 * Return value: the current value of the :add-tearoffs property.
5476 gtk_combo_box_get_add_tearoffs (GtkComboBox *combo_box)
5478 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE);
5480 return combo_box->priv->add_tearoffs;
5484 * gtk_combo_box_set_add_tearoffs:
5485 * @combo_box: a #GtkComboBox
5486 * @add_tearoffs: %TRUE to add tearoff menu items
5488 * Sets whether the popup menu should have a tearoff
5494 gtk_combo_box_set_add_tearoffs (GtkComboBox *combo_box,
5495 gboolean add_tearoffs)
5497 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5499 add_tearoffs = add_tearoffs != FALSE;
5501 if (combo_box->priv->add_tearoffs != add_tearoffs)
5503 combo_box->priv->add_tearoffs = add_tearoffs;
5504 gtk_combo_box_check_appearance (combo_box);
5505 gtk_combo_box_relayout (combo_box);
5506 g_object_notify (G_OBJECT (combo_box), "add-tearoffs");
5511 * gtk_combo_box_get_title:
5512 * @combo_box: a #GtkComboBox
5514 * Gets the current title of the menu in tearoff mode. See
5515 * gtk_combo_box_set_add_tearoffs().
5517 * Returns: the menu's title in tearoff mode. This is an internal copy of the
5518 * string which must not be freed.
5522 G_CONST_RETURN gchar*
5523 gtk_combo_box_get_title (GtkComboBox *combo_box)
5525 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
5527 return combo_box->priv->tearoff_title;
5531 gtk_combo_box_update_title (GtkComboBox *combo_box)
5533 gtk_combo_box_check_appearance (combo_box);
5535 if (combo_box->priv->popup_widget &&
5536 GTK_IS_MENU (combo_box->priv->popup_widget))
5537 gtk_menu_set_title (GTK_MENU (combo_box->priv->popup_widget),
5538 combo_box->priv->tearoff_title);
5542 * gtk_combo_box_set_title:
5543 * @combo_box: a #GtkComboBox
5544 * @title: a title for the menu in tearoff mode
5546 * Sets the menu's title in tearoff mode.
5551 gtk_combo_box_set_title (GtkComboBox *combo_box,
5554 GtkComboBoxPrivate *priv;
5556 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5558 priv = combo_box->priv;
5560 if (strcmp (title ? title : "",
5561 priv->tearoff_title ? priv->tearoff_title : "") != 0)
5563 g_free (priv->tearoff_title);
5564 priv->tearoff_title = g_strdup (title);
5566 gtk_combo_box_update_title (combo_box);
5568 g_object_notify (G_OBJECT (combo_box), "tearoff-title");
5573 _gtk_combo_box_editing_canceled (GtkComboBox *combo_box)
5575 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), TRUE);
5577 return combo_box->priv->editing_canceled;
5581 * gtk_combo_box_get_popup_accessible:
5582 * @combo_box: a #GtkComboBox
5584 * Gets the accessible object corresponding to the combo box's popup.
5586 * This function is mostly intended for use by accessibility technologies;
5587 * applications should have little use for it.
5589 * Returns: the accessible object corresponding to the combo box's popup.
5594 gtk_combo_box_get_popup_accessible (GtkComboBox *combo_box)
5598 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
5600 if (combo_box->priv->popup_widget)
5602 atk_obj = gtk_widget_get_accessible (combo_box->priv->popup_widget);
5610 * gtk_combo_box_get_row_separator_func:
5611 * @combo_box: a #GtkComboBox
5613 * Returns the current row separator function.
5615 * Return value: the current row separator function.
5619 GtkTreeViewRowSeparatorFunc
5620 gtk_combo_box_get_row_separator_func (GtkComboBox *combo_box)
5622 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
5624 return combo_box->priv->row_separator_func;
5628 * gtk_combo_box_set_row_separator_func:
5629 * @combo_box: a #GtkComboBox
5630 * @func: a #GtkTreeViewRowSeparatorFunc
5631 * @data: user data to pass to @func, or %NULL
5632 * @destroy: destroy notifier for @data, or %NULL
5634 * Sets the row separator function, which is used to determine
5635 * whether a row should be drawn as a separator. If the row separator
5636 * function is %NULL, no separators are drawn. This is the default value.
5641 gtk_combo_box_set_row_separator_func (GtkComboBox *combo_box,
5642 GtkTreeViewRowSeparatorFunc func,
5644 GtkDestroyNotify destroy)
5646 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5648 if (combo_box->priv->row_separator_destroy)
5649 (* combo_box->priv->row_separator_destroy) (combo_box->priv->row_separator_data);
5651 combo_box->priv->row_separator_func = func;
5652 combo_box->priv->row_separator_data = data;
5653 combo_box->priv->row_separator_destroy = destroy;
5655 if (combo_box->priv->tree_view)
5656 gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (combo_box->priv->tree_view),
5659 gtk_combo_box_relayout (combo_box);
5661 gtk_widget_queue_draw (GTK_WIDGET (combo_box));
5666 * gtk_combo_box_set_focus_on_click:
5667 * @combo: a #GtkComboBox
5668 * @focus_on_click: whether the combo box grabs focus when clicked
5671 * Sets whether the combo box will grab focus when it is clicked with
5672 * the mouse. Making mouse clicks not grab focus is useful in places
5673 * like toolbars where you don't want the keyboard focus removed from
5674 * the main area of the application.
5679 gtk_combo_box_set_focus_on_click (GtkComboBox *combo_box,
5680 gboolean focus_on_click)
5682 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5684 focus_on_click = focus_on_click != FALSE;
5686 if (combo_box->priv->focus_on_click != focus_on_click)
5688 combo_box->priv->focus_on_click = focus_on_click;
5690 if (combo_box->priv->button)
5691 gtk_button_set_focus_on_click (GTK_BUTTON (combo_box->priv->button),
5694 g_object_notify (G_OBJECT (combo_box), "focus-on-click");
5699 * gtk_combo_box_get_focus_on_click:
5700 * @combo: a #GtkComboBox
5702 * Returns whether the combo box grabs focus when it is clicked
5703 * with the mouse. See gtk_combo_box_set_focus_on_click().
5705 * Return value: %TRUE if the combo box grabs focus when it is
5706 * clicked with the mouse.
5711 gtk_combo_box_get_focus_on_click (GtkComboBox *combo_box)
5713 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE);
5715 return combo_box->priv->focus_on_click;
5720 gtk_combo_box_buildable_custom_tag_start (GtkBuildable *buildable,
5721 GtkBuilder *builder,
5723 const gchar *tagname,
5724 GMarkupParser *parser,
5727 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
5728 tagname, parser, data))
5731 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
5732 tagname, parser, data);
5736 gtk_combo_box_buildable_custom_tag_end (GtkBuildable *buildable,
5737 GtkBuilder *builder,
5739 const gchar *tagname,
5742 if (strcmp (tagname, "attributes") == 0)
5743 _gtk_cell_layout_buildable_custom_tag_end (buildable, builder, child, tagname,
5746 parent_buildable_iface->custom_tag_end (buildable, builder, child, tagname,
5750 #define __GTK_COMBO_BOX_C__
5751 #include "gtkaliasdef.c"