2 * Copyright (C) 2002, 2003 Kristian Rietveld <kris@gtk.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 #include "gtkcombobox.h"
24 #include "gtkbindings.h"
25 #include "gtkcelllayout.h"
26 #include "gtkcellrenderertext.h"
27 #include "gtkcellview.h"
28 #include "gtkeventbox.h"
31 #include "gtkliststore.h"
34 #include "gtkscrolledwindow.h"
35 #include "gtkseparatormenuitem.h"
36 #include "gtktearoffmenuitem.h"
37 #include "gtktogglebutton.h"
38 #include "gtktreeselection.h"
39 #include "gtkvseparator.h"
40 #include "gtkwindow.h"
41 #include "gtkprivate.h"
43 #include <gdk/gdkkeysyms.h>
45 #include <gobject/gvaluecollector.h>
50 #include "gtkmarshalers.h"
53 #include "gtktreeprivate.h"
56 /* WELCOME, to THE house of evil code */
58 typedef struct _ComboCellInfo ComboCellInfo;
61 GtkCellRenderer *cell;
64 GtkCellLayoutDataFunc func;
66 GDestroyNotify destroy;
72 #define GTK_COMBO_BOX_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_COMBO_BOX, GtkComboBoxPrivate))
74 struct _GtkComboBoxPrivate
83 GtkTreeRowReference *active_row;
86 GtkTreeViewColumn *column;
89 GtkWidget *cell_view_frame;
96 GtkWidget *popup_widget;
97 GtkWidget *popup_window;
98 GtkWidget *popup_frame;
99 GtkWidget *scrolled_window;
107 guint resize_idle_id;
112 guint popup_in_progress : 1;
113 guint destroying : 1;
114 guint add_tearoffs : 1;
116 guint is_cell_renderer : 1;
117 guint editing_canceled : 1;
118 guint auto_scroll : 1;
119 guint focus_on_click : 1;
121 GtkTreeViewRowSeparatorFunc row_separator_func;
122 gpointer row_separator_data;
123 GtkDestroyNotify row_separator_destroy;
125 gchar *tearoff_title;
128 /* While debugging this evil code, I have learned that
129 * there are actually 4 modes to this widget, which can
130 * be characterized as follows
132 * 1) menu mode, no child added
135 * cell_view -> GtkCellView, regular child
136 * cell_view_frame -> NULL
137 * button -> GtkToggleButton set_parent to combo
138 * arrow -> GtkArrow set_parent to button
139 * separator -> GtkVSepator set_parent to button
140 * popup_widget -> GtkMenu
141 * popup_window -> NULL
142 * popup_frame -> NULL
143 * scrolled_window -> NULL
145 * 2) menu mode, child added
149 * cell_view_frame -> NULL
150 * button -> GtkToggleButton set_parent to combo
151 * arrow -> GtkArrow, child of button
153 * popup_widget -> GtkMenu
154 * popup_window -> NULL
155 * popup_frame -> NULL
156 * scrolled_window -> NULL
158 * 3) list mode, no child added
160 * tree_view -> GtkTreeView, child of popup_frame
161 * cell_view -> GtkCellView, regular child
162 * cell_view_frame -> GtkFrame, set parent to combo
163 * button -> GtkToggleButton, set_parent to combo
164 * arrow -> GtkArrow, child of button
166 * popup_widget -> tree_view
167 * popup_window -> GtkWindow
168 * popup_frame -> GtkFrame, child of popup_window
169 * scrolled_window -> GtkScrolledWindow, child of popup_frame
171 * 4) list mode, child added
173 * tree_view -> GtkTreeView, child of popup_frame
175 * cell_view_frame -> NULL
176 * button -> GtkToggleButton, set_parent to combo
177 * arrow -> GtkArrow, child of button
179 * popup_widget -> tree_view
180 * popup_window -> GtkWindow
181 * popup_frame -> GtkFrame, child of popup_window
182 * scrolled_window -> GtkScrolledWindow, child of popup_frame
197 PROP_ROW_SPAN_COLUMN,
198 PROP_COLUMN_SPAN_COLUMN,
206 static GtkBinClass *parent_class = NULL;
207 static guint combo_box_signals[LAST_SIGNAL] = {0,};
209 #define BONUS_PADDING 4
210 #define SCROLL_TIME 100
214 static void gtk_combo_box_class_init (GtkComboBoxClass *klass);
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_init (GtkComboBox *combo_box);
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,
291 static gboolean gtk_combo_box_key_press (GtkWidget *widget,
295 static void gtk_combo_box_check_appearance (GtkComboBox *combo_box);
296 static gchar * gtk_combo_box_real_get_active_text (GtkComboBox *combo_box);
298 /* listening to the model */
299 static void gtk_combo_box_model_row_inserted (GtkTreeModel *model,
303 static void gtk_combo_box_model_row_deleted (GtkTreeModel *model,
306 static void gtk_combo_box_model_rows_reordered (GtkTreeModel *model,
311 static void gtk_combo_box_model_row_changed (GtkTreeModel *model,
315 static void gtk_combo_box_model_row_expanded (GtkTreeModel *model,
321 static void gtk_combo_box_list_position (GtkComboBox *combo_box,
326 static void gtk_combo_box_list_setup (GtkComboBox *combo_box);
327 static void gtk_combo_box_list_destroy (GtkComboBox *combo_box);
329 static gboolean gtk_combo_box_list_button_released (GtkWidget *widget,
330 GdkEventButton *event,
332 static gboolean gtk_combo_box_list_key_press (GtkWidget *widget,
335 static gboolean gtk_combo_box_list_enter_notify (GtkWidget *widget,
336 GdkEventCrossing *event,
338 static void gtk_combo_box_list_auto_scroll (GtkComboBox *combo,
341 static gboolean gtk_combo_box_list_scroll_timeout (GtkComboBox *combo);
342 static gboolean gtk_combo_box_list_button_pressed (GtkWidget *widget,
343 GdkEventButton *event,
346 static void gtk_combo_box_list_row_changed (GtkTreeModel *model,
350 static void gtk_combo_box_list_popup_resize (GtkComboBox *combo_box);
353 static void gtk_combo_box_menu_setup (GtkComboBox *combo_box,
354 gboolean add_children);
355 static void gtk_combo_box_menu_fill (GtkComboBox *combo_box);
356 static void gtk_combo_box_menu_fill_level (GtkComboBox *combo_box,
359 static void gtk_combo_box_update_title (GtkComboBox *combo_box);
360 static void gtk_combo_box_menu_destroy (GtkComboBox *combo_box);
362 static void gtk_combo_box_relayout_item (GtkComboBox *combo_box,
366 static void gtk_combo_box_relayout (GtkComboBox *combo_box);
368 static gboolean gtk_combo_box_menu_button_press (GtkWidget *widget,
369 GdkEventButton *event,
371 static void gtk_combo_box_menu_item_activate (GtkWidget *item,
373 static void gtk_combo_box_menu_row_inserted (GtkTreeModel *model,
377 static void gtk_combo_box_menu_row_deleted (GtkTreeModel *model,
380 static void gtk_combo_box_menu_rows_reordered (GtkTreeModel *model,
385 static void gtk_combo_box_menu_row_changed (GtkTreeModel *model,
389 static gboolean gtk_combo_box_menu_key_press (GtkWidget *widget,
392 static void gtk_combo_box_menu_popup (GtkComboBox *combo_box,
394 guint32 activate_time);
395 static GtkWidget *gtk_cell_view_menu_item_new (GtkComboBox *combo_box,
400 static void gtk_combo_box_cell_layout_pack_start (GtkCellLayout *layout,
401 GtkCellRenderer *cell,
403 static void gtk_combo_box_cell_layout_pack_end (GtkCellLayout *layout,
404 GtkCellRenderer *cell,
406 static void gtk_combo_box_cell_layout_clear (GtkCellLayout *layout);
407 static void gtk_combo_box_cell_layout_add_attribute (GtkCellLayout *layout,
408 GtkCellRenderer *cell,
409 const gchar *attribute,
411 static void gtk_combo_box_cell_layout_set_cell_data_func (GtkCellLayout *layout,
412 GtkCellRenderer *cell,
413 GtkCellLayoutDataFunc func,
415 GDestroyNotify destroy);
416 static void gtk_combo_box_cell_layout_clear_attributes (GtkCellLayout *layout,
417 GtkCellRenderer *cell);
418 static void gtk_combo_box_cell_layout_reorder (GtkCellLayout *layout,
419 GtkCellRenderer *cell,
421 static gboolean gtk_combo_box_mnemonic_activate (GtkWidget *widget,
422 gboolean group_cycling);
424 static void gtk_combo_box_sync_cells (GtkComboBox *combo_box,
425 GtkCellLayout *cell_layout);
426 static void combo_cell_data_func (GtkCellLayout *cell_layout,
427 GtkCellRenderer *cell,
428 GtkTreeModel *tree_model,
431 static void gtk_combo_box_child_show (GtkWidget *widget,
433 static void gtk_combo_box_child_hide (GtkWidget *widget,
437 /* GtkCellEditable method implementations */
438 static void gtk_combo_box_start_editing (GtkCellEditable *cell_editable,
443 gtk_combo_box_get_type (void)
445 static GType combo_box_type = 0;
449 static const GTypeInfo combo_box_info =
451 sizeof (GtkComboBoxClass),
452 NULL, /* base_init */
453 NULL, /* base_finalize */
454 (GClassInitFunc) gtk_combo_box_class_init,
455 NULL, /* class_finalize */
456 NULL, /* class_data */
457 sizeof (GtkComboBox),
459 (GInstanceInitFunc) gtk_combo_box_init
462 static const GInterfaceInfo cell_layout_info =
464 (GInterfaceInitFunc) gtk_combo_box_cell_layout_init,
469 static const GInterfaceInfo cell_editable_info =
471 (GInterfaceInitFunc) gtk_combo_box_cell_editable_init,
476 combo_box_type = g_type_register_static (GTK_TYPE_BIN,
481 g_type_add_interface_static (combo_box_type,
482 GTK_TYPE_CELL_LAYOUT,
486 g_type_add_interface_static (combo_box_type,
487 GTK_TYPE_CELL_EDITABLE,
488 &cell_editable_info);
493 return combo_box_type;
498 gtk_combo_box_class_init (GtkComboBoxClass *klass)
500 GObjectClass *object_class;
501 GtkObjectClass *gtk_object_class;
502 GtkContainerClass *container_class;
503 GtkWidgetClass *widget_class;
505 klass->get_active_text = gtk_combo_box_real_get_active_text;
507 container_class = (GtkContainerClass *)klass;
508 container_class->forall = gtk_combo_box_forall;
509 container_class->add = gtk_combo_box_add;
510 container_class->remove = gtk_combo_box_remove;
512 widget_class = (GtkWidgetClass *)klass;
513 widget_class->size_allocate = gtk_combo_box_size_allocate;
514 widget_class->size_request = gtk_combo_box_size_request;
515 widget_class->expose_event = gtk_combo_box_expose_event;
516 widget_class->scroll_event = gtk_combo_box_scroll_event;
517 widget_class->mnemonic_activate = gtk_combo_box_mnemonic_activate;
518 widget_class->grab_focus = gtk_combo_box_grab_focus;
519 widget_class->style_set = gtk_combo_box_style_set;
520 widget_class->state_changed = gtk_combo_box_state_changed;
522 gtk_object_class = (GtkObjectClass *)klass;
523 gtk_object_class->destroy = gtk_combo_box_destroy;
525 object_class = (GObjectClass *)klass;
526 object_class->finalize = gtk_combo_box_finalize;
527 object_class->set_property = gtk_combo_box_set_property;
528 object_class->get_property = gtk_combo_box_get_property;
530 parent_class = g_type_class_peek_parent (klass);
534 * GtkComboBox::changed:
535 * @widget: the object which received the signal
537 * The changed signal is emitted when the active
538 * item is changed. The can be due to the user selecting
539 * a different item from the list, or due to a
540 * call to gtk_combo_box_set_active_iter().
541 * It will also be emitted while typing into a GtkComboBoxEntry,
542 * as well as when selecting an item from the GtkComboBoxEntry's list.
546 combo_box_signals[CHANGED] =
547 g_signal_new (I_("changed"),
548 G_OBJECT_CLASS_TYPE (klass),
550 G_STRUCT_OFFSET (GtkComboBoxClass, changed),
552 g_cclosure_marshal_VOID__VOID,
555 combo_box_signals[POPUP_SHOW] =
556 g_signal_new ("popup-show",
557 G_OBJECT_CLASS_TYPE (klass),
561 g_cclosure_marshal_VOID__VOID,
564 combo_box_signals[POPUP_HIDE] =
565 g_signal_new ("popup-hide",
566 G_OBJECT_CLASS_TYPE (klass),
570 g_cclosure_marshal_VOID__VOID,
578 * The model from which the combo box takes the values shown
583 g_object_class_install_property (object_class,
585 g_param_spec_object ("model",
586 P_("ComboBox model"),
587 P_("The model for the combo box"),
589 GTK_PARAM_READWRITE));
592 * GtkComboBox:wrap-width:
594 * If wrap-width is set to a positive value, the list will be
595 * displayed in multiple columns, the number of columns is
596 * determined by wrap-width.
600 g_object_class_install_property (object_class,
602 g_param_spec_int ("wrap-width",
604 P_("Wrap width for laying out the items in a grid"),
608 GTK_PARAM_READWRITE));
612 * GtkComboBox:row-span-column:
614 * If this is set to a non-negative value, it must be the index of a column
615 * of type %G_TYPE_INT in the model.
617 * The values of that column are used to determine how many rows a value
618 * in the list will span. Therefore, the values in the model column pointed
619 * to by this property must be greater than zero and not larger than wrap-width.
623 g_object_class_install_property (object_class,
624 PROP_ROW_SPAN_COLUMN,
625 g_param_spec_int ("row-span-column",
626 P_("Row span column"),
627 P_("TreeModel column containing the row span values"),
631 GTK_PARAM_READWRITE));
635 * GtkComboBox:column-span-column:
637 * If this is set to a non-negative value, it must be the index of a column
638 * of type %G_TYPE_INT in the model.
640 * The values of that column are used to determine how many columns a value
641 * in the list will span.
645 g_object_class_install_property (object_class,
646 PROP_COLUMN_SPAN_COLUMN,
647 g_param_spec_int ("column-span-column",
648 P_("Column span column"),
649 P_("TreeModel column containing the column span values"),
653 GTK_PARAM_READWRITE));
657 * GtkComboBox:active:
659 * The item which is currently active. If the model is a non-flat treemodel,
660 * and the active item is not an immediate child of the root of the tree,
661 * this property has the value <literal>gtk_tree_path_get_indices (path)[0]</literal>,
662 * where <literal>path</literal> is the #GtkTreePath of the active item.
666 g_object_class_install_property (object_class,
668 g_param_spec_int ("active",
670 P_("The item which is currently active"),
674 GTK_PARAM_READWRITE));
677 * GtkComboBox:add-tearoffs:
679 * The add-tearoffs property controls whether generated menus
680 * have tearoff menu items.
682 * Note that this only affects menu style combo boxes.
686 g_object_class_install_property (object_class,
688 g_param_spec_boolean ("add-tearoffs",
689 P_("Add tearoffs to menus"),
690 P_("Whether dropdowns should have a tearoff menu item"),
692 GTK_PARAM_READWRITE));
695 * GtkComboBox:has-frame:
697 * The has-frame property controls whether a frame
698 * is drawn around the entry.
702 g_object_class_install_property (object_class,
704 g_param_spec_boolean ("has-frame",
706 P_("Whether the combo box draws a frame around the child"),
708 GTK_PARAM_READWRITE));
710 g_object_class_install_property (object_class,
712 g_param_spec_boolean ("focus-on-click",
713 P_("Focus on click"),
714 P_("Whether the combo box grabs focus when it is clicked with the mouse"),
716 GTK_PARAM_READWRITE));
719 * GtkComboBox:tearoff-title:
721 * A title that may be displayed by the window manager
722 * when the popup is torn-off.
726 g_object_class_install_property (object_class,
728 g_param_spec_string ("tearoff-title",
730 P_("A title that may be displayed by the window manager when the popup is torn-off"),
732 GTK_PARAM_READWRITE));
735 gtk_widget_class_install_style_property (widget_class,
736 g_param_spec_boolean ("appears-as-list",
737 P_("Appears as list"),
738 P_("Whether dropdowns should look like lists rather than menus"),
740 GTK_PARAM_READABLE));
742 g_type_class_add_private (object_class, sizeof (GtkComboBoxPrivate));
746 gtk_combo_box_cell_layout_init (GtkCellLayoutIface *iface)
748 iface->pack_start = gtk_combo_box_cell_layout_pack_start;
749 iface->pack_end = gtk_combo_box_cell_layout_pack_end;
750 iface->clear = gtk_combo_box_cell_layout_clear;
751 iface->add_attribute = gtk_combo_box_cell_layout_add_attribute;
752 iface->set_cell_data_func = gtk_combo_box_cell_layout_set_cell_data_func;
753 iface->clear_attributes = gtk_combo_box_cell_layout_clear_attributes;
754 iface->reorder = gtk_combo_box_cell_layout_reorder;
758 gtk_combo_box_cell_editable_init (GtkCellEditableIface *iface)
760 iface->start_editing = gtk_combo_box_start_editing;
764 gtk_combo_box_init (GtkComboBox *combo_box)
766 combo_box->priv = GTK_COMBO_BOX_GET_PRIVATE (combo_box);
768 combo_box->priv->cell_view = gtk_cell_view_new ();
769 gtk_widget_set_parent (combo_box->priv->cell_view, GTK_WIDGET (combo_box));
770 GTK_BIN (combo_box)->child = combo_box->priv->cell_view;
771 gtk_widget_show (combo_box->priv->cell_view);
773 combo_box->priv->width = 0;
774 combo_box->priv->wrap_width = 0;
776 combo_box->priv->active_row = NULL;
777 combo_box->priv->col_column = -1;
778 combo_box->priv->row_column = -1;
780 combo_box->priv->add_tearoffs = FALSE;
781 combo_box->priv->has_frame = TRUE;
782 combo_box->priv->is_cell_renderer = FALSE;
783 combo_box->priv->editing_canceled = FALSE;
784 combo_box->priv->auto_scroll = FALSE;
785 combo_box->priv->focus_on_click = TRUE;
787 gtk_combo_box_check_appearance (combo_box);
791 gtk_combo_box_set_property (GObject *object,
796 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
801 gtk_combo_box_set_model (combo_box, g_value_get_object (value));
804 case PROP_WRAP_WIDTH:
805 gtk_combo_box_set_wrap_width (combo_box, g_value_get_int (value));
808 case PROP_ROW_SPAN_COLUMN:
809 gtk_combo_box_set_row_span_column (combo_box, g_value_get_int (value));
812 case PROP_COLUMN_SPAN_COLUMN:
813 gtk_combo_box_set_column_span_column (combo_box, g_value_get_int (value));
817 gtk_combo_box_set_active (combo_box, g_value_get_int (value));
820 case PROP_ADD_TEAROFFS:
821 gtk_combo_box_set_add_tearoffs (combo_box, g_value_get_boolean (value));
825 combo_box->priv->has_frame = g_value_get_boolean (value);
828 case PROP_FOCUS_ON_CLICK:
829 gtk_combo_box_set_focus_on_click (combo_box,
830 g_value_get_boolean (value));
833 case PROP_TEAROFF_TITLE:
834 gtk_combo_box_set_title (combo_box, g_value_get_string (value));
843 gtk_combo_box_get_property (GObject *object,
848 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
853 g_value_set_object (value, combo_box->priv->model);
856 case PROP_WRAP_WIDTH:
857 g_value_set_int (value, combo_box->priv->wrap_width);
860 case PROP_ROW_SPAN_COLUMN:
861 g_value_set_int (value, combo_box->priv->row_column);
864 case PROP_COLUMN_SPAN_COLUMN:
865 g_value_set_int (value, combo_box->priv->col_column);
869 g_value_set_int (value, gtk_combo_box_get_active (combo_box));
872 case PROP_ADD_TEAROFFS:
873 g_value_set_boolean (value, gtk_combo_box_get_add_tearoffs (combo_box));
877 g_value_set_boolean (value, combo_box->priv->has_frame);
880 case PROP_FOCUS_ON_CLICK:
881 g_value_set_boolean (value, combo_box->priv->focus_on_click);
884 case PROP_TEAROFF_TITLE:
885 g_value_set_string (value, gtk_combo_box_get_title (combo_box));
889 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
895 gtk_combo_box_state_changed (GtkWidget *widget,
896 GtkStateType previous)
898 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
900 if (GTK_WIDGET_REALIZED (widget))
902 if (combo_box->priv->tree_view && combo_box->priv->cell_view)
903 gtk_cell_view_set_background_color (GTK_CELL_VIEW (combo_box->priv->cell_view),
904 &widget->style->base[GTK_WIDGET_STATE (widget)]);
907 gtk_widget_queue_draw (widget);
911 gtk_combo_box_button_state_changed (GtkWidget *widget,
912 GtkStateType previous,
915 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
917 if (GTK_WIDGET_REALIZED (widget))
919 if (!combo_box->priv->tree_view && combo_box->priv->cell_view)
921 if ((GTK_WIDGET_STATE (widget) == GTK_STATE_INSENSITIVE) !=
922 (GTK_WIDGET_STATE (combo_box->priv->cell_view) == GTK_STATE_INSENSITIVE))
923 gtk_widget_set_sensitive (combo_box->priv->cell_view, GTK_WIDGET_SENSITIVE (widget));
925 gtk_widget_set_state (combo_box->priv->cell_view,
926 GTK_WIDGET_STATE (widget));
931 gtk_widget_queue_draw (widget);
935 gtk_combo_box_check_appearance (GtkComboBox *combo_box)
937 gboolean appears_as_list;
939 /* if wrap_width > 0, then we are in grid-mode and forced to use
942 if (combo_box->priv->wrap_width)
943 appears_as_list = FALSE;
945 gtk_widget_style_get (GTK_WIDGET (combo_box),
946 "appears-as-list", &appears_as_list,
951 /* Destroy all the menu mode widgets, if they exist. */
952 if (GTK_IS_MENU (combo_box->priv->popup_widget))
953 gtk_combo_box_menu_destroy (combo_box);
955 /* Create the list mode widgets, if they don't already exist. */
956 if (!GTK_IS_TREE_VIEW (combo_box->priv->tree_view))
957 gtk_combo_box_list_setup (combo_box);
961 /* Destroy all the list mode widgets, if they exist. */
962 if (GTK_IS_TREE_VIEW (combo_box->priv->tree_view))
963 gtk_combo_box_list_destroy (combo_box);
965 /* Create the menu mode widgets, if they don't already exist. */
966 if (!GTK_IS_MENU (combo_box->priv->popup_widget))
967 gtk_combo_box_menu_setup (combo_box, TRUE);
972 gtk_combo_box_style_set (GtkWidget *widget,
975 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
977 gtk_combo_box_check_appearance (combo_box);
979 if (combo_box->priv->tree_view && combo_box->priv->cell_view)
980 gtk_cell_view_set_background_color (GTK_CELL_VIEW (combo_box->priv->cell_view),
981 &widget->style->base[GTK_WIDGET_STATE (widget)]);
985 gtk_combo_box_button_toggled (GtkWidget *widget,
988 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
990 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
992 if (!combo_box->priv->popup_in_progress)
993 gtk_combo_box_popup (combo_box);
996 gtk_combo_box_popdown (combo_box);
1000 gtk_combo_box_add (GtkContainer *container,
1003 GtkComboBox *combo_box = GTK_COMBO_BOX (container);
1005 if (combo_box->priv->cell_view && combo_box->priv->cell_view->parent)
1007 gtk_widget_unparent (combo_box->priv->cell_view);
1008 GTK_BIN (container)->child = NULL;
1009 gtk_widget_queue_resize (GTK_WIDGET (container));
1012 gtk_widget_set_parent (widget, GTK_WIDGET (container));
1013 GTK_BIN (container)->child = widget;
1015 if (combo_box->priv->cell_view &&
1016 widget != combo_box->priv->cell_view)
1018 /* since the cell_view was unparented, it's gone now */
1019 combo_box->priv->cell_view = NULL;
1021 if (!combo_box->priv->tree_view && combo_box->priv->separator)
1023 gtk_container_remove (GTK_CONTAINER (combo_box->priv->separator->parent),
1024 combo_box->priv->separator);
1025 combo_box->priv->separator = NULL;
1027 gtk_widget_queue_resize (GTK_WIDGET (container));
1029 else if (combo_box->priv->cell_view_frame)
1031 gtk_widget_unparent (combo_box->priv->cell_view_frame);
1032 combo_box->priv->cell_view_frame = NULL;
1033 combo_box->priv->box = NULL;
1039 gtk_combo_box_remove (GtkContainer *container,
1042 GtkComboBox *combo_box = GTK_COMBO_BOX (container);
1044 gboolean appears_as_list;
1046 gtk_widget_unparent (widget);
1047 GTK_BIN (container)->child = NULL;
1049 if (combo_box->priv->destroying)
1052 gtk_widget_queue_resize (GTK_WIDGET (container));
1054 if (!combo_box->priv->tree_view)
1055 appears_as_list = FALSE;
1057 appears_as_list = TRUE;
1059 if (appears_as_list)
1060 gtk_combo_box_list_destroy (combo_box);
1061 else if (GTK_IS_MENU (combo_box->priv->popup_widget))
1063 gtk_combo_box_menu_destroy (combo_box);
1064 gtk_menu_detach (GTK_MENU (combo_box->priv->popup_widget));
1065 combo_box->priv->popup_widget = NULL;
1068 if (!combo_box->priv->cell_view)
1070 combo_box->priv->cell_view = gtk_cell_view_new ();
1071 gtk_widget_set_parent (combo_box->priv->cell_view, GTK_WIDGET (container));
1072 GTK_BIN (container)->child = combo_box->priv->cell_view;
1074 gtk_widget_show (combo_box->priv->cell_view);
1075 gtk_cell_view_set_model (GTK_CELL_VIEW (combo_box->priv->cell_view),
1076 combo_box->priv->model);
1077 gtk_combo_box_sync_cells (combo_box, GTK_CELL_LAYOUT (combo_box->priv->cell_view));
1081 if (appears_as_list)
1082 gtk_combo_box_list_setup (combo_box);
1084 gtk_combo_box_menu_setup (combo_box, TRUE);
1086 if (gtk_tree_row_reference_valid (combo_box->priv->active_row))
1088 path = gtk_tree_row_reference_get_path (combo_box->priv->active_row);
1089 gtk_combo_box_set_active_internal (combo_box, path);
1090 gtk_tree_path_free (path);
1093 gtk_combo_box_set_active_internal (combo_box, NULL);
1096 static ComboCellInfo *
1097 gtk_combo_box_get_cell_info (GtkComboBox *combo_box,
1098 GtkCellRenderer *cell)
1102 for (i = combo_box->priv->cells; i; i = i->next)
1104 ComboCellInfo *info = (ComboCellInfo *)i->data;
1106 if (info && info->cell == cell)
1114 gtk_combo_box_menu_show (GtkWidget *menu,
1117 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
1119 gtk_combo_box_child_show (menu, user_data);
1121 combo_box->priv->popup_in_progress = TRUE;
1122 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
1124 combo_box->priv->popup_in_progress = FALSE;
1128 gtk_combo_box_menu_hide (GtkWidget *menu,
1131 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
1133 gtk_combo_box_child_hide(menu,user_data);
1135 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
1140 gtk_combo_box_detacher (GtkWidget *widget,
1143 GtkComboBox *combo_box;
1145 g_return_if_fail (GTK_IS_COMBO_BOX (widget));
1147 combo_box = GTK_COMBO_BOX (widget);
1148 g_return_if_fail (combo_box->priv->popup_widget == (GtkWidget*) menu);
1150 g_signal_handlers_disconnect_by_func (menu->toplevel,
1151 gtk_combo_box_menu_show,
1153 g_signal_handlers_disconnect_by_func (menu->toplevel,
1154 gtk_combo_box_menu_hide,
1157 combo_box->priv->popup_widget = NULL;
1161 gtk_combo_box_set_popup_widget (GtkComboBox *combo_box,
1164 if (GTK_IS_MENU (combo_box->priv->popup_widget))
1166 gtk_menu_detach (GTK_MENU (combo_box->priv->popup_widget));
1167 combo_box->priv->popup_widget = NULL;
1169 else if (combo_box->priv->popup_widget)
1171 gtk_container_remove (GTK_CONTAINER (combo_box->priv->popup_frame),
1172 combo_box->priv->popup_widget);
1173 g_object_unref (combo_box->priv->popup_widget);
1174 combo_box->priv->popup_widget = NULL;
1177 if (GTK_IS_MENU (popup))
1179 if (combo_box->priv->popup_window)
1181 gtk_widget_destroy (combo_box->priv->popup_window);
1182 combo_box->priv->popup_window = NULL;
1183 combo_box->priv->popup_frame = NULL;
1186 combo_box->priv->popup_widget = popup;
1189 * Note that we connect to show/hide on the toplevel, not the
1190 * menu itself, since the menu is not shown/hidden when it is
1191 * popped up while torn-off.
1193 g_signal_connect (GTK_MENU (popup)->toplevel, "show",
1194 G_CALLBACK (gtk_combo_box_menu_show), combo_box);
1195 g_signal_connect (GTK_MENU (popup)->toplevel, "hide",
1196 G_CALLBACK (gtk_combo_box_menu_hide), combo_box);
1198 gtk_menu_attach_to_widget (GTK_MENU (popup),
1199 GTK_WIDGET (combo_box),
1200 gtk_combo_box_detacher);
1204 if (!combo_box->priv->popup_window)
1206 GtkWidget *toplevel;
1208 combo_box->priv->popup_window = gtk_window_new (GTK_WINDOW_POPUP);
1210 g_signal_connect (GTK_WINDOW(combo_box->priv->popup_window),"show",
1211 G_CALLBACK (gtk_combo_box_child_show),
1213 g_signal_connect (GTK_WINDOW(combo_box->priv->popup_window),"hide",
1214 G_CALLBACK (gtk_combo_box_child_hide),
1217 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (combo_box));
1218 if (GTK_IS_WINDOW (toplevel))
1219 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
1220 GTK_WINDOW (combo_box->priv->popup_window));
1222 gtk_window_set_resizable (GTK_WINDOW (combo_box->priv->popup_window), FALSE);
1223 gtk_window_set_screen (GTK_WINDOW (combo_box->priv->popup_window),
1224 gtk_widget_get_screen (GTK_WIDGET (combo_box)));
1226 combo_box->priv->popup_frame = gtk_frame_new (NULL);
1227 gtk_frame_set_shadow_type (GTK_FRAME (combo_box->priv->popup_frame),
1228 GTK_SHADOW_ETCHED_IN);
1229 gtk_container_add (GTK_CONTAINER (combo_box->priv->popup_window),
1230 combo_box->priv->popup_frame);
1232 gtk_widget_show (combo_box->priv->popup_frame);
1234 combo_box->priv->scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1236 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (combo_box->priv->scrolled_window),
1239 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (combo_box->priv->scrolled_window),
1242 gtk_widget_show (combo_box->priv->scrolled_window);
1244 gtk_container_add (GTK_CONTAINER (combo_box->priv->popup_frame),
1245 combo_box->priv->scrolled_window);
1248 gtk_container_add (GTK_CONTAINER (combo_box->priv->scrolled_window),
1251 gtk_widget_show (popup);
1252 g_object_ref (popup);
1253 combo_box->priv->popup_widget = popup;
1258 gtk_combo_box_menu_position_below (GtkMenu *menu,
1264 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
1270 GdkRectangle monitor;
1272 /* FIXME: is using the size request here broken? */
1273 child = GTK_BIN (combo_box)->child;
1275 gdk_window_get_origin (child->window, &sx, &sy);
1277 if (GTK_WIDGET_NO_WINDOW (child))
1279 sx += child->allocation.x;
1280 sy += child->allocation.y;
1283 gtk_widget_size_request (GTK_WIDGET (menu), &req);
1285 if (gtk_widget_get_direction (GTK_WIDGET (combo_box)) == GTK_TEXT_DIR_LTR)
1288 *x = sx + child->allocation.width - req.width;
1291 screen = gtk_widget_get_screen (GTK_WIDGET (combo_box));
1292 monitor_num = gdk_screen_get_monitor_at_window (screen,
1293 GTK_WIDGET (combo_box)->window);
1294 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
1298 else if (*x + req.width > monitor.x + monitor.width)
1299 *x = monitor.x + monitor.width - req.width;
1301 if (monitor.y + monitor.height - *y - child->allocation.height >= req.height)
1302 *y += child->allocation.height;
1303 else if (*y - monitor.y >= req.height)
1305 else if (monitor.y + monitor.height - *y - child->allocation.height > *y - monitor.y)
1306 *y += child->allocation.height;
1314 gtk_combo_box_menu_position_over (GtkMenu *menu,
1320 GtkComboBox *combo_box;
1324 GtkRequisition requisition;
1331 g_return_if_fail (GTK_IS_COMBO_BOX (user_data));
1333 combo_box = GTK_COMBO_BOX (user_data);
1334 widget = GTK_WIDGET (combo_box);
1336 gtk_widget_get_child_requisition (GTK_WIDGET (menu), &requisition);
1337 menu_width = requisition.width;
1339 active = gtk_menu_get_active (GTK_MENU (combo_box->priv->popup_widget));
1340 gdk_window_get_origin (widget->window, &menu_xpos, &menu_ypos);
1342 menu_xpos += widget->allocation.x;
1343 menu_ypos += widget->allocation.y + widget->allocation.height / 2 - 2;
1347 gtk_widget_get_child_requisition (active, &requisition);
1348 menu_ypos -= requisition.height / 2;
1351 children = GTK_MENU_SHELL (combo_box->priv->popup_widget)->children;
1354 child = children->data;
1356 if (active == child)
1359 if (GTK_WIDGET_VISIBLE (child))
1361 gtk_widget_get_child_requisition (child, &requisition);
1362 menu_ypos -= requisition.height;
1365 children = children->next;
1368 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1369 menu_xpos = menu_xpos + widget->allocation.width - menu_width;
1371 /* Clamp the position on screen */
1372 screen_width = gdk_screen_get_width (gtk_widget_get_screen (widget));
1376 else if ((menu_xpos + menu_width) > screen_width)
1377 menu_xpos -= ((menu_xpos + menu_width) - screen_width);
1386 gtk_combo_box_menu_position (GtkMenu *menu,
1392 GtkComboBox *combo_box;
1393 GtkWidget *menu_item;
1395 combo_box = GTK_COMBO_BOX (user_data);
1397 if (combo_box->priv->wrap_width > 0 || combo_box->priv->cell_view == NULL)
1398 gtk_combo_box_menu_position_below (menu, x, y, push_in, user_data);
1401 /* FIXME handle nested menus better */
1402 menu_item = gtk_menu_get_active (GTK_MENU (combo_box->priv->popup_widget));
1404 gtk_menu_shell_select_item (GTK_MENU_SHELL (combo_box->priv->popup_widget),
1407 gtk_combo_box_menu_position_over (menu, x, y, push_in, user_data);
1413 gtk_combo_box_list_position (GtkComboBox *combo_box,
1422 GdkRectangle monitor;
1423 GtkRequisition popup_req;
1424 GtkPolicyType hpolicy, vpolicy;
1426 sample = GTK_BIN (combo_box)->child;
1428 gdk_window_get_origin (sample->window, x, y);
1430 if (GTK_WIDGET_NO_WINDOW (sample))
1432 *x += sample->allocation.x;
1433 *y += sample->allocation.y;
1436 *width = sample->allocation.width;
1438 if (combo_box->priv->cell_view_frame && combo_box->priv->has_frame)
1440 *x -= GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
1441 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->xthickness;
1442 *width += 2 * (GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
1443 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->xthickness);
1446 hpolicy = vpolicy = GTK_POLICY_NEVER;
1447 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (combo_box->priv->scrolled_window),
1449 gtk_widget_size_request (combo_box->priv->popup_frame, &popup_req);
1451 if (popup_req.width > *width)
1453 hpolicy = GTK_POLICY_ALWAYS;
1454 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (combo_box->priv->scrolled_window),
1456 gtk_widget_size_request (combo_box->priv->popup_frame, &popup_req);
1459 *height = popup_req.height;
1461 screen = gtk_widget_get_screen (GTK_WIDGET (combo_box));
1462 monitor_num = gdk_screen_get_monitor_at_window (screen,
1463 GTK_WIDGET (combo_box)->window);
1464 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
1468 else if (*x + *width > monitor.x + monitor.width)
1469 *x = monitor.x + monitor.width - *width;
1471 if (*y + sample->allocation.height + *height <= monitor.y + monitor.height)
1472 *y += sample->allocation.height;
1473 else if (*y - *height >= monitor.y)
1475 else if (monitor.y + monitor.height - (*y + sample->allocation.height) > *y - monitor.y)
1477 *y += sample->allocation.height;
1478 *height = monitor.y + monitor.height - *y;
1482 *height = *y - monitor.y;
1486 if (popup_req.height > *height)
1488 vpolicy = GTK_POLICY_ALWAYS;
1490 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (combo_box->priv->scrolled_window),
1496 cell_view_is_sensitive (GtkCellView *cell_view)
1498 GList *cells, *list;
1501 cells = gtk_cell_view_get_cell_renderers (cell_view);
1507 g_object_get (list->data, "sensitive", &sensitive, NULL);
1514 g_list_free (cells);
1520 tree_column_row_is_sensitive (GtkComboBox *combo_box,
1523 GList *cells, *list;
1526 if (!combo_box->priv->column)
1529 if (combo_box->priv->row_separator_func)
1531 if ((*combo_box->priv->row_separator_func) (combo_box->priv->model, iter,
1532 combo_box->priv->row_separator_data))
1536 gtk_tree_view_column_cell_set_cell_data (combo_box->priv->column,
1537 combo_box->priv->model,
1538 iter, FALSE, FALSE);
1540 cells = gtk_tree_view_column_get_cell_renderers (combo_box->priv->column);
1546 g_object_get (list->data, "sensitive", &sensitive, NULL);
1553 g_list_free (cells);
1559 update_menu_sensitivity (GtkComboBox *combo_box,
1562 GList *children, *child;
1563 GtkWidget *item, *submenu, *separator;
1564 GtkWidget *cell_view;
1567 if (!combo_box->priv->model)
1570 children = gtk_container_get_children (GTK_CONTAINER (menu));
1572 for (child = children; child; child = child->next)
1574 item = GTK_WIDGET (child->data);
1575 cell_view = GTK_BIN (item)->child;
1577 if (!GTK_IS_CELL_VIEW (cell_view))
1580 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (item));
1581 if (submenu != NULL)
1583 gtk_widget_set_sensitive (item, TRUE);
1584 update_menu_sensitivity (combo_box, submenu);
1588 sensitive = cell_view_is_sensitive (GTK_CELL_VIEW (cell_view));
1590 if (menu != combo_box->priv->popup_widget && child == children)
1592 separator = GTK_WIDGET (child->next->data);
1593 g_object_set (item, "visible", sensitive, NULL);
1594 g_object_set (separator, "visible", sensitive, NULL);
1597 gtk_widget_set_sensitive (item, sensitive);
1601 g_list_free (children);
1605 gtk_combo_box_menu_popup (GtkComboBox *combo_box,
1607 guint32 activate_time)
1611 GtkRequisition requisition;
1614 update_menu_sensitivity (combo_box, combo_box->priv->popup_widget);
1617 if (gtk_tree_row_reference_valid (combo_box->priv->active_row))
1619 path = gtk_tree_row_reference_get_path (combo_box->priv->active_row);
1620 active_item = gtk_tree_path_get_indices (path)[0];
1621 gtk_tree_path_free (path);
1623 if (combo_box->priv->add_tearoffs)
1627 /* FIXME handle nested menus better */
1628 gtk_menu_set_active (GTK_MENU (combo_box->priv->popup_widget), active_item);
1630 if (combo_box->priv->wrap_width == 0)
1632 width = GTK_WIDGET (combo_box)->allocation.width;
1633 gtk_widget_set_size_request (combo_box->priv->popup_widget, -1, -1);
1634 gtk_widget_size_request (combo_box->priv->popup_widget, &requisition);
1636 gtk_widget_set_size_request (combo_box->priv->popup_widget,
1637 MAX (width, requisition.width), -1);
1640 gtk_menu_popup (GTK_MENU (combo_box->priv->popup_widget),
1642 gtk_combo_box_menu_position, combo_box,
1643 button, activate_time);
1647 popup_grab_on_window (GdkWindow *window,
1648 guint32 activate_time,
1649 gboolean grab_keyboard)
1651 if ((gdk_pointer_grab (window, TRUE,
1652 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
1653 GDK_POINTER_MOTION_MASK,
1654 NULL, NULL, activate_time) == 0))
1656 if (!grab_keyboard ||
1657 gdk_keyboard_grab (window, TRUE,
1658 activate_time) == 0)
1662 gdk_display_pointer_ungrab (gdk_drawable_get_display (window),
1672 * gtk_combo_box_popup:
1673 * @combo_box: a #GtkComboBox
1675 * Pops up the menu or dropdown list of @combo_box.
1677 * This function is mostly intended for use by accessibility technologies;
1678 * applications should have little use for it.
1683 gtk_combo_box_popup (GtkComboBox *combo_box)
1685 gint x, y, width, height;
1686 GtkTreePath *path, *ppath;
1687 GtkWidget *toplevel;
1689 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
1691 if (!GTK_WIDGET_REALIZED (combo_box))
1694 if (GTK_WIDGET_MAPPED (combo_box->priv->popup_widget))
1697 if (GTK_IS_MENU (combo_box->priv->popup_widget))
1699 gtk_combo_box_menu_popup (combo_box, 0, 0);
1703 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (combo_box));
1704 if (GTK_IS_WINDOW (toplevel))
1705 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
1706 GTK_WINDOW (combo_box->priv->popup_window));
1708 gtk_widget_show_all (combo_box->priv->popup_frame);
1709 gtk_combo_box_list_position (combo_box, &x, &y, &width, &height);
1711 gtk_widget_set_size_request (combo_box->priv->popup_window, width, height);
1712 gtk_window_move (GTK_WINDOW (combo_box->priv->popup_window), x, y);
1714 if (gtk_tree_row_reference_valid (combo_box->priv->active_row))
1716 path = gtk_tree_row_reference_get_path (combo_box->priv->active_row);
1717 ppath = gtk_tree_path_copy (path);
1718 if (gtk_tree_path_up (ppath))
1719 gtk_tree_view_expand_to_path (GTK_TREE_VIEW (combo_box->priv->tree_view),
1721 gtk_tree_view_set_cursor (GTK_TREE_VIEW (combo_box->priv->tree_view),
1723 gtk_tree_path_free (path);
1724 gtk_tree_path_free (ppath);
1726 gtk_tree_view_set_hover_expand (GTK_TREE_VIEW (combo_box->priv->tree_view),
1730 gtk_widget_show (combo_box->priv->popup_window);
1732 gtk_widget_grab_focus (combo_box->priv->popup_window);
1733 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
1736 if (!GTK_WIDGET_HAS_FOCUS (combo_box->priv->tree_view))
1737 gtk_widget_grab_focus (combo_box->priv->tree_view);
1739 if (!popup_grab_on_window (combo_box->priv->popup_window->window,
1740 GDK_CURRENT_TIME, TRUE))
1742 gtk_widget_hide (combo_box->priv->popup_window);
1746 gtk_grab_add (combo_box->priv->popup_window);
1750 * gtk_combo_box_popdown:
1751 * @combo_box: a #GtkComboBox
1753 * Hides the menu or dropdown list of @combo_box.
1755 * This function is mostly intended for use by accessibility technologies;
1756 * applications should have little use for it.
1761 gtk_combo_box_popdown (GtkComboBox *combo_box)
1763 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
1765 if (GTK_IS_MENU (combo_box->priv->popup_widget))
1767 gtk_menu_popdown (GTK_MENU (combo_box->priv->popup_widget));
1771 if (!GTK_WIDGET_REALIZED (GTK_WIDGET (combo_box)))
1774 gtk_grab_remove (combo_box->priv->popup_window);
1775 gtk_widget_hide_all (combo_box->priv->popup_window);
1776 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
1781 gtk_combo_box_calc_requested_width (GtkComboBox *combo_box,
1787 if (combo_box->priv->cell_view)
1788 gtk_widget_style_get (combo_box->priv->cell_view,
1789 "focus-line-width", &padding,
1794 /* add some pixels for good measure */
1795 padding += BONUS_PADDING;
1797 if (combo_box->priv->cell_view)
1798 gtk_cell_view_get_size_of_row (GTK_CELL_VIEW (combo_box->priv->cell_view),
1803 return req.width + padding;
1807 gtk_combo_box_remeasure (GtkComboBox *combo_box)
1812 if (!combo_box->priv->model ||
1813 !gtk_tree_model_get_iter_first (combo_box->priv->model, &iter))
1816 combo_box->priv->width = 0;
1818 path = gtk_tree_path_new_from_indices (0, -1);
1824 if (combo_box->priv->cell_view)
1825 gtk_cell_view_get_size_of_row (GTK_CELL_VIEW (combo_box->priv->cell_view),
1830 combo_box->priv->width = MAX (combo_box->priv->width, req.width);
1832 gtk_tree_path_next (path);
1834 while (gtk_tree_model_iter_next (combo_box->priv->model, &iter));
1836 gtk_tree_path_free (path);
1840 gtk_combo_box_size_request (GtkWidget *widget,
1841 GtkRequisition *requisition)
1844 gint focus_width, focus_pad;
1845 GtkRequisition bin_req;
1847 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
1850 gtk_widget_size_request (GTK_BIN (widget)->child, &bin_req);
1851 gtk_combo_box_remeasure (combo_box);
1852 bin_req.width = MAX (bin_req.width, combo_box->priv->width);
1854 gtk_widget_style_get (GTK_WIDGET (widget),
1855 "focus-line-width", &focus_width,
1856 "focus-padding", &focus_pad,
1859 if (!combo_box->priv->tree_view)
1863 if (combo_box->priv->cell_view)
1865 GtkRequisition button_req, sep_req, arrow_req;
1866 gint border_width, xthickness, ythickness;
1868 gtk_widget_size_request (combo_box->priv->button, &button_req);
1869 border_width = GTK_CONTAINER (combo_box)->border_width;
1870 xthickness = combo_box->priv->button->style->xthickness;
1871 ythickness = combo_box->priv->button->style->ythickness;
1873 bin_req.width = MAX (bin_req.width, combo_box->priv->width);
1875 gtk_widget_size_request (combo_box->priv->separator, &sep_req);
1876 gtk_widget_size_request (combo_box->priv->arrow, &arrow_req);
1878 height = MAX (sep_req.height, arrow_req.height);
1879 height = MAX (height, bin_req.height);
1881 width = bin_req.width + sep_req.width + arrow_req.width;
1883 height += 2*(border_width + ythickness + focus_width + focus_pad);
1884 width += 2*(border_width + xthickness + focus_width + focus_pad);
1886 requisition->width = width;
1887 requisition->height = height;
1891 GtkRequisition but_req;
1893 gtk_widget_size_request (combo_box->priv->button, &but_req);
1895 requisition->width = bin_req.width + but_req.width;
1896 requisition->height = MAX (bin_req.height, but_req.height);
1902 GtkRequisition button_req, frame_req;
1904 /* sample + frame */
1905 *requisition = bin_req;
1907 requisition->width += 2 * focus_width;
1909 if (combo_box->priv->cell_view_frame)
1911 gtk_widget_size_request (combo_box->priv->cell_view_frame, &frame_req);
1912 if (combo_box->priv->has_frame)
1914 requisition->width += 2 *
1915 (GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
1916 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->xthickness);
1917 requisition->height += 2 *
1918 (GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
1919 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->ythickness);
1924 gtk_widget_size_request (combo_box->priv->button, &button_req);
1926 requisition->height = MAX (requisition->height, button_req.height);
1927 requisition->width += button_req.width;
1932 gtk_combo_box_size_allocate (GtkWidget *widget,
1933 GtkAllocation *allocation)
1935 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
1936 gint focus_width, focus_pad;
1937 GtkAllocation child;
1939 gboolean is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
1941 widget->allocation = *allocation;
1943 gtk_widget_style_get (GTK_WIDGET (widget),
1944 "focus-line-width", &focus_width,
1945 "focus-padding", &focus_pad,
1948 if (!combo_box->priv->tree_view)
1950 if (combo_box->priv->cell_view)
1952 gint border_width, xthickness, ythickness;
1956 gtk_widget_size_allocate (combo_box->priv->button, allocation);
1958 /* set some things ready */
1959 border_width = GTK_CONTAINER (combo_box->priv->button)->border_width;
1960 xthickness = combo_box->priv->button->style->xthickness;
1961 ythickness = combo_box->priv->button->style->ythickness;
1963 child.x = allocation->x;
1964 child.y = allocation->y;
1965 width = allocation->width;
1966 child.height = allocation->height;
1968 if (!combo_box->priv->is_cell_renderer)
1970 child.x += border_width + xthickness + focus_width + focus_pad;
1971 child.y += border_width + ythickness + focus_width + focus_pad;
1972 width -= 2 * (child.x - allocation->x);
1973 child.height -= 2 * (child.y - allocation->y);
1977 /* handle the children */
1978 gtk_widget_size_request (combo_box->priv->arrow, &req);
1979 child.width = req.width;
1981 child.x += width - req.width;
1982 child.width = MAX (1, child.width);
1983 child.height = MAX (1, child.height);
1984 gtk_widget_size_allocate (combo_box->priv->arrow, &child);
1986 child.x += req.width;
1987 gtk_widget_size_request (combo_box->priv->separator, &req);
1988 child.width = req.width;
1990 child.x -= req.width;
1991 child.width = MAX (1, child.width);
1992 child.height = MAX (1, child.height);
1993 gtk_widget_size_allocate (combo_box->priv->separator, &child);
1997 child.x += req.width;
1998 child.width = allocation->x + allocation->width
1999 - (border_width + xthickness + focus_width + focus_pad)
2004 child.width = child.x;
2005 child.x = allocation->x
2006 + border_width + xthickness + focus_width + focus_pad;
2007 child.width -= child.x;
2010 child.width = MAX (1, child.width);
2011 child.height = MAX (1, child.height);
2012 gtk_widget_size_allocate (GTK_BIN (widget)->child, &child);
2016 gtk_widget_size_request (combo_box->priv->button, &req);
2018 child.x = allocation->x;
2020 child.x = allocation->x + allocation->width - req.width;
2021 child.y = allocation->y;
2022 child.width = req.width;
2023 child.height = allocation->height;
2024 child.width = MAX (1, child.width);
2025 child.height = MAX (1, child.height);
2026 gtk_widget_size_allocate (combo_box->priv->button, &child);
2029 child.x = allocation->x + req.width;
2031 child.x = allocation->x;
2032 child.y = allocation->y;
2033 child.width = allocation->width - req.width;
2034 child.width = MAX (1, child.width);
2035 child.height = MAX (1, child.height);
2036 gtk_widget_size_allocate (GTK_BIN (widget)->child, &child);
2044 gtk_widget_size_request (combo_box->priv->button, &req);
2046 child.x = allocation->x;
2048 child.x = allocation->x + allocation->width - req.width;
2049 child.y = allocation->y;
2050 child.width = req.width;
2051 child.height = allocation->height;
2052 child.width = MAX (1, child.width);
2053 child.height = MAX (1, child.height);
2054 gtk_widget_size_allocate (combo_box->priv->button, &child);
2058 child.x = allocation->x + req.width;
2060 child.x = allocation->x;
2061 child.y = allocation->y;
2062 child.width = allocation->width - req.width;
2063 child.height = allocation->height;
2065 if (combo_box->priv->cell_view_frame)
2067 child.width = MAX (1, child.width);
2068 child.height = MAX (1, child.height);
2069 gtk_widget_size_allocate (combo_box->priv->cell_view_frame, &child);
2072 if (combo_box->priv->has_frame)
2075 GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
2076 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->xthickness;
2078 GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
2079 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->ythickness;
2080 child.width -= 2 * (
2081 GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
2082 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->xthickness);
2083 child.height -= 2 * (
2084 GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
2085 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->ythickness);
2089 child.width = MAX (1, child.width);
2090 child.height = MAX (1, child.height);
2091 gtk_widget_size_allocate (GTK_BIN (combo_box)->child, &child);
2096 gtk_combo_box_unset_model (GtkComboBox *combo_box)
2098 if (combo_box->priv->model)
2100 g_signal_handler_disconnect (combo_box->priv->model,
2101 combo_box->priv->inserted_id);
2102 g_signal_handler_disconnect (combo_box->priv->model,
2103 combo_box->priv->deleted_id);
2104 g_signal_handler_disconnect (combo_box->priv->model,
2105 combo_box->priv->reordered_id);
2106 g_signal_handler_disconnect (combo_box->priv->model,
2107 combo_box->priv->changed_id);
2111 if (!combo_box->priv->tree_view)
2113 if (combo_box->priv->popup_widget)
2114 gtk_container_foreach (GTK_CONTAINER (combo_box->priv->popup_widget),
2115 (GtkCallback)gtk_widget_destroy, NULL);
2118 if (combo_box->priv->model)
2120 g_object_unref (combo_box->priv->model);
2121 combo_box->priv->model = NULL;
2124 if (combo_box->priv->active_row)
2126 gtk_tree_row_reference_free (combo_box->priv->active_row);
2127 combo_box->priv->active_row = NULL;
2130 if (combo_box->priv->cell_view)
2131 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (combo_box->priv->cell_view), NULL);
2135 gtk_combo_box_forall (GtkContainer *container,
2136 gboolean include_internals,
2137 GtkCallback callback,
2138 gpointer callback_data)
2140 GtkComboBox *combo_box = GTK_COMBO_BOX (container);
2142 if (include_internals)
2144 if (combo_box->priv->button)
2145 (* callback) (combo_box->priv->button, callback_data);
2146 if (combo_box->priv->cell_view_frame)
2147 (* callback) (combo_box->priv->cell_view_frame, callback_data);
2150 if (GTK_BIN (container)->child)
2151 (* callback) (GTK_BIN (container)->child, callback_data);
2155 gtk_combo_box_child_show (GtkWidget *widget,
2158 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2159 g_signal_emit (combo_box, combo_box_signals[POPUP_SHOW], 0);
2163 gtk_combo_box_child_hide (GtkWidget *widget,
2166 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2167 g_signal_emit (combo_box, combo_box_signals[POPUP_HIDE], 0);
2171 gtk_combo_box_expose_event (GtkWidget *widget,
2172 GdkEventExpose *event)
2174 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
2176 if (!combo_box->priv->tree_view)
2178 gtk_container_propagate_expose (GTK_CONTAINER (widget),
2179 combo_box->priv->button, event);
2183 gtk_container_propagate_expose (GTK_CONTAINER (widget),
2184 combo_box->priv->button, event);
2186 if (combo_box->priv->cell_view_frame)
2187 gtk_container_propagate_expose (GTK_CONTAINER (widget),
2188 combo_box->priv->cell_view_frame, event);
2191 gtk_container_propagate_expose (GTK_CONTAINER (widget),
2192 GTK_BIN (widget)->child, event);
2207 path_visible (GtkTreeView *view,
2213 /* Note that we rely on the fact that collapsed rows don't have nodes
2215 return _gtk_tree_view_find_node (view, path, &tree, &node);
2219 tree_next_func (GtkTreeModel *model,
2224 SearchData *search_data = (SearchData *)data;
2226 if (search_data->found)
2228 if (!tree_column_row_is_sensitive (search_data->combo, iter))
2231 if (search_data->visible &&
2232 !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
2235 search_data->set = TRUE;
2236 search_data->iter = *iter;
2241 if (gtk_tree_path_compare (path, search_data->path) == 0)
2242 search_data->found = TRUE;
2248 tree_next (GtkComboBox *combo,
2249 GtkTreeModel *model,
2254 SearchData search_data;
2256 search_data.combo = combo;
2257 search_data.path = gtk_tree_model_get_path (model, iter);
2258 search_data.visible = visible;
2259 search_data.found = FALSE;
2260 search_data.set = FALSE;
2262 gtk_tree_model_foreach (model, tree_next_func, &search_data);
2264 *next = search_data.iter;
2266 gtk_tree_path_free (search_data.path);
2268 return search_data.set;
2272 tree_prev_func (GtkTreeModel *model,
2277 SearchData *search_data = (SearchData *)data;
2279 if (gtk_tree_path_compare (path, search_data->path) == 0)
2281 search_data->found = TRUE;
2285 if (!tree_column_row_is_sensitive (search_data->combo, iter))
2288 if (search_data->visible &&
2289 !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
2292 search_data->set = TRUE;
2293 search_data->iter = *iter;
2299 tree_prev (GtkComboBox *combo,
2300 GtkTreeModel *model,
2305 SearchData search_data;
2307 search_data.combo = combo;
2308 search_data.path = gtk_tree_model_get_path (model, iter);
2309 search_data.visible = visible;
2310 search_data.found = FALSE;
2311 search_data.set = FALSE;
2313 gtk_tree_model_foreach (model, tree_prev_func, &search_data);
2315 *prev = search_data.iter;
2317 gtk_tree_path_free (search_data.path);
2319 return search_data.set;
2323 tree_last_func (GtkTreeModel *model,
2328 SearchData *search_data = (SearchData *)data;
2330 if (!tree_column_row_is_sensitive (search_data->combo, iter))
2333 /* Note that we rely on the fact that collapsed rows don't have nodes
2335 if (search_data->visible &&
2336 !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
2339 search_data->set = TRUE;
2340 search_data->iter = *iter;
2346 tree_last (GtkComboBox *combo,
2347 GtkTreeModel *model,
2351 SearchData search_data;
2353 search_data.combo = combo;
2354 search_data.visible = visible;
2355 search_data.set = FALSE;
2357 gtk_tree_model_foreach (model, tree_last_func, &search_data);
2359 *last = search_data.iter;
2361 return search_data.set;
2366 tree_first_func (GtkTreeModel *model,
2371 SearchData *search_data = (SearchData *)data;
2373 if (!tree_column_row_is_sensitive (search_data->combo, iter))
2376 if (search_data->visible &&
2377 !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
2380 search_data->set = TRUE;
2381 search_data->iter = *iter;
2387 tree_first (GtkComboBox *combo,
2388 GtkTreeModel *model,
2392 SearchData search_data;
2394 search_data.combo = combo;
2395 search_data.visible = visible;
2396 search_data.set = FALSE;
2398 gtk_tree_model_foreach (model, tree_first_func, &search_data);
2400 *first = search_data.iter;
2402 return search_data.set;
2406 gtk_combo_box_scroll_event (GtkWidget *widget,
2407 GdkEventScroll *event)
2409 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
2412 GtkTreeIter new_iter;
2414 if (!gtk_combo_box_get_active_iter (combo_box, &iter))
2417 if (event->direction == GDK_SCROLL_UP)
2418 found = tree_prev (combo_box, combo_box->priv->model,
2419 &iter, &new_iter, FALSE);
2421 found = tree_next (combo_box, combo_box->priv->model,
2422 &iter, &new_iter, FALSE);
2425 gtk_combo_box_set_active_iter (combo_box, &new_iter);
2435 gtk_combo_box_sync_cells (GtkComboBox *combo_box,
2436 GtkCellLayout *cell_layout)
2440 for (k = combo_box->priv->cells; k; k = k->next)
2443 ComboCellInfo *info = (ComboCellInfo *)k->data;
2445 if (info->pack == GTK_PACK_START)
2446 gtk_cell_layout_pack_start (cell_layout,
2447 info->cell, info->expand);
2448 else if (info->pack == GTK_PACK_END)
2449 gtk_cell_layout_pack_end (cell_layout,
2450 info->cell, info->expand);
2452 gtk_cell_layout_set_cell_data_func (cell_layout,
2454 combo_cell_data_func, info, NULL);
2456 for (j = info->attributes; j; j = j->next->next)
2458 gtk_cell_layout_add_attribute (cell_layout,
2461 GPOINTER_TO_INT (j->next->data));
2467 gtk_combo_box_menu_setup (GtkComboBox *combo_box,
2468 gboolean add_children)
2472 if (combo_box->priv->cell_view)
2474 combo_box->priv->button = gtk_toggle_button_new ();
2475 gtk_button_set_focus_on_click (GTK_BUTTON (combo_box->priv->button),
2476 combo_box->priv->focus_on_click);
2478 g_signal_connect (combo_box->priv->button, "toggled",
2479 G_CALLBACK (gtk_combo_box_button_toggled), combo_box);
2480 g_signal_connect_after (combo_box->priv->button,
2482 G_CALLBACK (gtk_combo_box_key_press), combo_box);
2483 gtk_widget_set_parent (combo_box->priv->button,
2484 GTK_BIN (combo_box)->child->parent);
2486 combo_box->priv->box = gtk_hbox_new (FALSE, 0);
2487 gtk_container_add (GTK_CONTAINER (combo_box->priv->button),
2488 combo_box->priv->box);
2490 combo_box->priv->separator = gtk_vseparator_new ();
2491 gtk_container_add (GTK_CONTAINER (combo_box->priv->box),
2492 combo_box->priv->separator);
2494 combo_box->priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
2495 gtk_container_add (GTK_CONTAINER (combo_box->priv->box),
2496 combo_box->priv->arrow);
2498 gtk_widget_show_all (combo_box->priv->button);
2502 combo_box->priv->button = gtk_toggle_button_new ();
2503 gtk_button_set_focus_on_click (GTK_BUTTON (combo_box->priv->button),
2504 combo_box->priv->focus_on_click);
2506 g_signal_connect (combo_box->priv->button, "toggled",
2507 G_CALLBACK (gtk_combo_box_button_toggled), combo_box);
2508 g_signal_connect_after (combo_box, "key_press_event",
2509 G_CALLBACK (gtk_combo_box_key_press), combo_box);
2510 gtk_widget_set_parent (combo_box->priv->button,
2511 GTK_BIN (combo_box)->child->parent);
2513 combo_box->priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
2514 gtk_container_add (GTK_CONTAINER (combo_box->priv->button),
2515 combo_box->priv->arrow);
2516 gtk_widget_show_all (combo_box->priv->button);
2519 g_signal_connect (combo_box->priv->button, "button_press_event",
2520 G_CALLBACK (gtk_combo_box_menu_button_press),
2522 g_signal_connect (combo_box->priv->button, "state_changed",
2523 G_CALLBACK (gtk_combo_box_button_state_changed),
2526 /* create our funky menu */
2527 menu = gtk_menu_new ();
2528 g_signal_connect (menu, "key_press_event",
2529 G_CALLBACK (gtk_combo_box_menu_key_press), combo_box);
2530 gtk_combo_box_set_popup_widget (combo_box, menu);
2534 gtk_combo_box_menu_fill (combo_box);
2536 /* the column is needed in tree_column_row_is_sensitive() */
2537 combo_box->priv->column = gtk_tree_view_column_new ();
2538 g_object_ref_sink (combo_box->priv->column);
2539 gtk_combo_box_sync_cells (combo_box,
2540 GTK_CELL_LAYOUT (combo_box->priv->column));
2542 gtk_combo_box_update_title (combo_box);
2546 gtk_combo_box_menu_fill (GtkComboBox *combo_box)
2550 if (!combo_box->priv->model)
2553 menu = combo_box->priv->popup_widget;
2555 if (combo_box->priv->add_tearoffs)
2557 GtkWidget *tearoff = gtk_tearoff_menu_item_new ();
2559 gtk_widget_show (tearoff);
2561 if (combo_box->priv->wrap_width)
2562 gtk_menu_attach (GTK_MENU (menu), tearoff,
2563 0, combo_box->priv->wrap_width, 0, 1);
2565 gtk_menu_shell_append (GTK_MENU_SHELL (menu), tearoff);
2568 gtk_combo_box_menu_fill_level (combo_box, menu, NULL);
2572 gtk_cell_view_menu_item_new (GtkComboBox *combo_box,
2573 GtkTreeModel *model,
2576 GtkWidget *cell_view;
2581 cell_view = gtk_cell_view_new ();
2582 gtk_cell_view_set_model (GTK_CELL_VIEW (cell_view), model);
2583 path = gtk_tree_model_get_path (model, iter);
2584 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (cell_view), path);
2585 gtk_tree_path_free (path);
2587 gtk_combo_box_sync_cells (combo_box, GTK_CELL_LAYOUT (cell_view));
2588 gtk_widget_size_request (cell_view, &req);
2589 gtk_widget_show (cell_view);
2591 item = gtk_menu_item_new ();
2592 gtk_container_add (GTK_CONTAINER (item), cell_view);
2598 gtk_combo_box_menu_fill_level (GtkComboBox *combo_box,
2600 GtkTreeIter *parent)
2602 GtkTreeModel *model = combo_box->priv->model;
2603 GtkWidget *item, *submenu, *subitem, *separator;
2605 gboolean is_separator;
2610 n_children = gtk_tree_model_iter_n_children (model, parent);
2613 for (i = 0; i < n_children; i++)
2615 gtk_tree_model_iter_nth_child (model, &iter, parent, i);
2617 if (combo_box->priv->row_separator_func)
2618 is_separator = (*combo_box->priv->row_separator_func) (combo_box->priv->model, &iter,
2619 combo_box->priv->row_separator_data);
2621 is_separator = FALSE;
2625 item = gtk_separator_menu_item_new ();
2626 path = gtk_tree_model_get_path (model, &iter);
2627 g_object_set_data_full (G_OBJECT (item),
2628 I_("gtk-combo-box-item-path"),
2629 gtk_tree_row_reference_new (model, path),
2630 (GDestroyNotify)gtk_tree_row_reference_free);
2631 gtk_tree_path_free (path);
2635 item = gtk_cell_view_menu_item_new (combo_box, model, &iter);
2636 if (gtk_tree_model_iter_has_child (model, &iter))
2638 submenu = gtk_menu_new ();
2639 gtk_widget_show (submenu);
2640 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
2642 /* Ugly - since menus can only activate leafs, we have to
2643 * duplicate the item inside the submenu.
2645 subitem = gtk_cell_view_menu_item_new (combo_box, model, &iter);
2646 separator = gtk_separator_menu_item_new ();
2647 gtk_widget_show (subitem);
2648 gtk_widget_show (separator);
2649 g_signal_connect (subitem, "activate",
2650 G_CALLBACK (gtk_combo_box_menu_item_activate),
2652 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), subitem);
2653 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), separator);
2655 gtk_combo_box_menu_fill_level (combo_box, submenu, &iter);
2658 g_signal_connect (item, "activate",
2659 G_CALLBACK (gtk_combo_box_menu_item_activate),
2663 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
2664 if (combo_box->priv->wrap_width && menu == combo_box->priv->popup_widget)
2665 gtk_combo_box_relayout_item (combo_box, item, &iter, last);
2666 gtk_widget_show (item);
2673 gtk_combo_box_menu_destroy (GtkComboBox *combo_box)
2675 g_signal_handlers_disconnect_matched (combo_box->priv->button,
2676 G_SIGNAL_MATCH_DATA,
2678 gtk_combo_box_menu_button_press, NULL);
2679 g_signal_handlers_disconnect_matched (combo_box->priv->button,
2680 G_SIGNAL_MATCH_DATA,
2682 gtk_combo_box_button_state_changed, combo_box);
2684 /* unparent will remove our latest ref */
2685 gtk_widget_unparent (combo_box->priv->button);
2687 combo_box->priv->box = NULL;
2688 combo_box->priv->button = NULL;
2689 combo_box->priv->arrow = NULL;
2690 combo_box->priv->separator = NULL;
2692 g_object_unref (combo_box->priv->column);
2693 combo_box->priv->column = NULL;
2695 /* changing the popup window will unref the menu and the children */
2703 menu_occupied (GtkMenu *menu,
2707 guint bottom_attach)
2711 for (i = GTK_MENU_SHELL (menu)->children; i; i = i->next)
2715 gtk_container_child_get (GTK_CONTAINER (menu),
2719 "bottom-attach", &b,
2723 /* look if this item intersects with the given coordinates */
2724 if (right_attach > l && left_attach < r && bottom_attach > t && top_attach < b)
2732 gtk_combo_box_relayout_item (GtkComboBox *combo_box,
2737 gint current_col = 0, current_row = 0;
2738 gint rows = 1, cols = 1;
2739 GtkWidget *menu = combo_box->priv->popup_widget;
2741 if (!GTK_IS_MENU_SHELL (menu))
2744 if (combo_box->priv->col_column == -1 &&
2745 combo_box->priv->row_column == -1 &&
2748 gtk_container_child_get (GTK_CONTAINER (menu),
2750 "right_attach", ¤t_col,
2751 "top_attach", ¤t_row,
2753 if (current_col + cols > combo_box->priv->wrap_width)
2761 if (combo_box->priv->col_column != -1)
2762 gtk_tree_model_get (combo_box->priv->model, iter,
2763 combo_box->priv->col_column, &cols,
2765 if (combo_box->priv->row_column != -1)
2766 gtk_tree_model_get (combo_box->priv->model, iter,
2767 combo_box->priv->row_column, &rows,
2772 if (current_col + cols > combo_box->priv->wrap_width)
2778 if (!menu_occupied (GTK_MENU (menu),
2779 current_col, current_col + cols,
2780 current_row, current_row + rows))
2787 /* set attach props */
2788 gtk_menu_attach (GTK_MENU (menu), item,
2789 current_col, current_col + cols,
2790 current_row, current_row + rows);
2794 gtk_combo_box_relayout (GtkComboBox *combo_box)
2799 menu = combo_box->priv->popup_widget;
2801 /* do nothing unless we are in menu style and realized */
2802 if (combo_box->priv->tree_view || !GTK_IS_MENU_SHELL (menu))
2805 list = gtk_container_get_children (GTK_CONTAINER (menu));
2807 for (j = g_list_last (list); j; j = j->prev)
2808 gtk_container_remove (GTK_CONTAINER (menu), j->data);
2810 gtk_combo_box_menu_fill (combo_box);
2817 gtk_combo_box_menu_button_press (GtkWidget *widget,
2818 GdkEventButton *event,
2821 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2823 if (GTK_IS_MENU (combo_box->priv->popup_widget) &&
2824 event->type == GDK_BUTTON_PRESS && event->button == 1)
2826 if (combo_box->priv->focus_on_click &&
2827 !GTK_WIDGET_HAS_FOCUS (combo_box->priv->button))
2828 gtk_widget_grab_focus (combo_box->priv->button);
2830 gtk_combo_box_menu_popup (combo_box, event->button, event->time);
2839 gtk_combo_box_menu_item_activate (GtkWidget *item,
2842 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2843 GtkWidget *cell_view;
2847 cell_view = GTK_BIN (item)->child;
2849 g_return_if_fail (GTK_IS_CELL_VIEW (cell_view));
2851 path = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (cell_view));
2853 if (gtk_tree_model_get_iter (combo_box->priv->model, &iter, path))
2854 gtk_combo_box_set_active_iter (combo_box, &iter);
2856 gtk_tree_path_free (path);
2858 combo_box->priv->editing_canceled = FALSE;
2862 gtk_combo_box_model_row_inserted (GtkTreeModel *model,
2867 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2869 if (combo_box->priv->tree_view)
2870 gtk_combo_box_list_popup_resize (combo_box);
2872 gtk_combo_box_menu_row_inserted (model, path, iter, user_data);
2876 gtk_combo_box_model_row_deleted (GtkTreeModel *model,
2880 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2882 if (combo_box->priv->cell_view)
2884 if (!gtk_tree_row_reference_valid (combo_box->priv->active_row))
2885 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (combo_box->priv->cell_view), NULL);
2888 if (combo_box->priv->tree_view)
2889 gtk_combo_box_list_popup_resize (combo_box);
2891 gtk_combo_box_menu_row_deleted (model, path, user_data);
2895 gtk_combo_box_model_rows_reordered (GtkTreeModel *model,
2901 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2903 gtk_tree_row_reference_reordered (G_OBJECT (user_data), path, iter, new_order);
2905 if (!combo_box->priv->tree_view)
2906 gtk_combo_box_menu_rows_reordered (model, path, iter, new_order, user_data);
2910 gtk_combo_box_model_row_changed (GtkTreeModel *model,
2915 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2916 GtkTreePath *active_path;
2918 /* FIXME this belongs to GtkCellView */
2919 if (gtk_tree_row_reference_valid (combo_box->priv->active_row))
2921 active_path = gtk_tree_row_reference_get_path (combo_box->priv->active_row);
2922 if (gtk_tree_path_compare (path, active_path) == 0 &&
2923 combo_box->priv->cell_view)
2924 gtk_widget_queue_resize (GTK_WIDGET (combo_box->priv->cell_view));
2925 gtk_tree_path_free (active_path);
2928 if (combo_box->priv->tree_view)
2929 gtk_combo_box_list_row_changed (model, path, iter, user_data);
2931 gtk_combo_box_menu_row_changed (model, path, iter, user_data);
2935 list_popup_resize_idle (gpointer user_data)
2937 GtkComboBox *combo_box;
2938 gint x, y, width, height;
2940 GDK_THREADS_ENTER ();
2942 combo_box = GTK_COMBO_BOX (user_data);
2944 if (combo_box->priv->tree_view &&
2945 GTK_WIDGET_MAPPED (combo_box->priv->popup_window))
2947 gtk_combo_box_list_position (combo_box, &x, &y, &width, &height);
2949 gtk_widget_set_size_request (combo_box->priv->popup_window, width, height);
2950 gtk_window_move (GTK_WINDOW (combo_box->priv->popup_window), x, y);
2953 combo_box->priv->resize_idle_id = 0;
2955 GDK_THREADS_LEAVE ();
2961 gtk_combo_box_list_popup_resize (GtkComboBox *combo_box)
2963 if (!combo_box->priv->resize_idle_id)
2964 combo_box->priv->resize_idle_id =
2965 g_idle_add (list_popup_resize_idle, combo_box);
2969 gtk_combo_box_model_row_expanded (GtkTreeModel *model,
2974 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2976 gtk_combo_box_list_popup_resize (combo_box);
2981 find_menu_by_path (GtkWidget *menu,
2983 gboolean skip_first)
2988 GtkTreeRowReference *mref;
2992 list = gtk_container_get_children (GTK_CONTAINER (menu));
2995 for (i = list; i; i = i->next)
2997 if (GTK_IS_SEPARATOR_MENU_ITEM (i->data))
2999 mref = g_object_get_data (G_OBJECT (i->data), "gtk-combo-box-item-path");
3002 else if (!gtk_tree_row_reference_valid (mref))
3005 mpath = gtk_tree_row_reference_get_path (mref);
3007 else if (GTK_IS_CELL_VIEW (GTK_BIN (i->data)->child))
3015 mpath = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (GTK_BIN (i->data)->child));
3020 /* this case is necessary, since the row reference of
3021 * the cell view may already be updated after a deletion
3028 if (gtk_tree_path_compare (mpath, path) == 0)
3030 gtk_tree_path_free (mpath);
3034 if (gtk_tree_path_is_ancestor (mpath, path))
3036 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
3037 if (submenu != NULL)
3039 gtk_tree_path_free (mpath);
3040 item = find_menu_by_path (submenu, path, TRUE);
3044 gtk_tree_path_free (mpath);
3054 dump_menu_tree (GtkWidget *menu,
3061 list = gtk_container_get_children (GTK_CONTAINER (menu));
3062 for (i = list; i; i = i->next)
3064 if (GTK_IS_CELL_VIEW (GTK_BIN (i->data)->child))
3066 path = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (GTK_BIN (i->data)->child));
3067 g_print ("%*s%s\n", 2 * level, " ", gtk_tree_path_to_string (path));
3068 gtk_tree_path_free (path);
3070 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
3071 if (submenu != NULL)
3072 dump_menu_tree (submenu, level + 1);
3081 gtk_combo_box_menu_row_inserted (GtkTreeModel *model,
3087 GtkWidget *item, *menu, *separator;
3088 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3092 gboolean is_separator;
3094 if (!combo_box->priv->popup_widget)
3097 depth = gtk_tree_path_get_depth (path);
3098 pos = gtk_tree_path_get_indices (path)[depth - 1];
3101 ppath = gtk_tree_path_copy (path);
3102 gtk_tree_path_up (ppath);
3103 parent = find_menu_by_path (combo_box->priv->popup_widget, ppath, FALSE);
3104 gtk_tree_path_free (ppath);
3106 menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (parent));
3109 menu = gtk_menu_new ();
3110 gtk_widget_show (menu);
3111 gtk_menu_item_set_submenu (GTK_MENU_ITEM (parent), menu);
3113 /* Ugly - since menus can only activate leaves, we have to
3114 * duplicate the item inside the submenu.
3116 gtk_tree_model_iter_parent (model, &piter, iter);
3117 item = gtk_cell_view_menu_item_new (combo_box, model, &piter);
3118 separator = gtk_separator_menu_item_new ();
3119 g_signal_connect (item, "activate",
3120 G_CALLBACK (gtk_combo_box_menu_item_activate),
3122 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
3123 gtk_menu_shell_append (GTK_MENU_SHELL (menu), separator);
3124 if (cell_view_is_sensitive (GTK_CELL_VIEW (GTK_BIN (item)->child)))
3126 gtk_widget_show (item);
3127 gtk_widget_show (separator);
3134 menu = combo_box->priv->popup_widget;
3135 if (combo_box->priv->add_tearoffs)
3139 if (combo_box->priv->row_separator_func)
3140 is_separator = (*combo_box->priv->row_separator_func) (model, iter,
3141 combo_box->priv->row_separator_data);
3143 is_separator = FALSE;
3147 item = gtk_separator_menu_item_new ();
3148 g_object_set_data_full (G_OBJECT (item),
3149 I_("gtk-combo-box-item-path"),
3150 gtk_tree_row_reference_new (model, path),
3151 (GDestroyNotify)gtk_tree_row_reference_free);
3155 item = gtk_cell_view_menu_item_new (combo_box, model, iter);
3157 g_signal_connect (item, "activate",
3158 G_CALLBACK (gtk_combo_box_menu_item_activate),
3162 gtk_widget_show (item);
3163 gtk_menu_shell_insert (GTK_MENU_SHELL (menu), item, pos);
3167 gtk_combo_box_menu_row_deleted (GtkTreeModel *model,
3171 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3175 if (!combo_box->priv->popup_widget)
3178 item = find_menu_by_path (combo_box->priv->popup_widget, path, FALSE);
3179 menu = gtk_widget_get_parent (item);
3180 gtk_container_remove (GTK_CONTAINER (menu), item);
3184 gtk_combo_box_menu_rows_reordered (GtkTreeModel *model,
3190 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3192 gtk_combo_box_relayout (combo_box);
3196 gtk_combo_box_menu_row_changed (GtkTreeModel *model,
3201 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3204 gboolean is_separator;
3206 if (!combo_box->priv->popup_widget)
3209 item = find_menu_by_path (combo_box->priv->popup_widget, path, FALSE);
3211 if (combo_box->priv->row_separator_func)
3212 is_separator = (*combo_box->priv->row_separator_func) (model, iter,
3213 combo_box->priv->row_separator_data);
3215 is_separator = FALSE;
3217 if (is_separator != GTK_IS_SEPARATOR_MENU_ITEM (item))
3219 gtk_combo_box_menu_row_deleted (model, path, combo_box);
3220 gtk_combo_box_menu_row_inserted (model, path, iter, combo_box);
3223 if (combo_box->priv->wrap_width
3224 && item->parent == combo_box->priv->popup_widget)
3226 GtkWidget *pitem = NULL;
3229 prev = gtk_tree_path_copy (path);
3231 if (gtk_tree_path_prev (prev))
3232 pitem = find_menu_by_path (combo_box->priv->popup_widget, prev, FALSE);
3234 gtk_tree_path_free (prev);
3236 /* unattach item so gtk_combo_box_relayout_item() won't spuriously
3238 gtk_container_child_set (GTK_CONTAINER (combo_box->priv->popup_widget),
3243 "bottom-attach", -1,
3246 gtk_combo_box_relayout_item (combo_box, item, iter, pitem);
3249 width = gtk_combo_box_calc_requested_width (combo_box, path);
3251 if (width > combo_box->priv->width)
3253 if (combo_box->priv->cell_view)
3255 gtk_widget_set_size_request (combo_box->priv->cell_view, width, -1);
3256 gtk_widget_queue_resize (combo_box->priv->cell_view);
3258 combo_box->priv->width = width;
3267 gtk_combo_box_list_setup (GtkComboBox *combo_box)
3269 GtkTreeSelection *sel;
3271 combo_box->priv->button = gtk_toggle_button_new ();
3272 gtk_widget_set_parent (combo_box->priv->button,
3273 GTK_BIN (combo_box)->child->parent);
3274 g_signal_connect (combo_box->priv->button, "button_press_event",
3275 G_CALLBACK (gtk_combo_box_list_button_pressed), combo_box);
3276 g_signal_connect (combo_box->priv->button, "toggled",
3277 G_CALLBACK (gtk_combo_box_button_toggled), combo_box);
3278 g_signal_connect_after (combo_box, "key_press_event",
3279 G_CALLBACK (gtk_combo_box_key_press), combo_box);
3281 combo_box->priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
3282 gtk_container_add (GTK_CONTAINER (combo_box->priv->button),
3283 combo_box->priv->arrow);
3284 combo_box->priv->separator = NULL;
3285 gtk_widget_show_all (combo_box->priv->button);
3287 if (combo_box->priv->cell_view)
3289 gtk_cell_view_set_background_color (GTK_CELL_VIEW (combo_box->priv->cell_view),
3290 >K_WIDGET (combo_box)->style->base[GTK_WIDGET_STATE (combo_box)]);
3292 combo_box->priv->box = gtk_event_box_new ();
3293 gtk_event_box_set_visible_window (GTK_EVENT_BOX (combo_box->priv->box),
3296 if (combo_box->priv->has_frame)
3298 combo_box->priv->cell_view_frame = gtk_frame_new (NULL);
3299 gtk_frame_set_shadow_type (GTK_FRAME (combo_box->priv->cell_view_frame),
3304 combo_box->priv->cell_view_frame = gtk_event_box_new ();
3305 gtk_event_box_set_visible_window (GTK_EVENT_BOX (combo_box->priv->cell_view_frame),
3309 gtk_widget_set_parent (combo_box->priv->cell_view_frame,
3310 GTK_BIN (combo_box)->child->parent);
3311 gtk_container_add (GTK_CONTAINER (combo_box->priv->cell_view_frame),
3312 combo_box->priv->box);
3313 gtk_widget_show_all (combo_box->priv->cell_view_frame);
3315 g_signal_connect (combo_box->priv->box, "button_press_event",
3316 G_CALLBACK (gtk_combo_box_list_button_pressed),
3320 combo_box->priv->tree_view = gtk_tree_view_new ();
3321 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (combo_box->priv->tree_view));
3322 gtk_tree_selection_set_mode (sel, GTK_SELECTION_BROWSE);
3323 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (combo_box->priv->tree_view),
3325 gtk_tree_view_set_hover_selection (GTK_TREE_VIEW (combo_box->priv->tree_view),
3327 if (combo_box->priv->row_separator_func)
3328 gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (combo_box->priv->tree_view),
3329 combo_box->priv->row_separator_func,
3330 combo_box->priv->row_separator_data,
3332 if (combo_box->priv->model)
3333 gtk_tree_view_set_model (GTK_TREE_VIEW (combo_box->priv->tree_view),
3334 combo_box->priv->model);
3336 combo_box->priv->column = gtk_tree_view_column_new ();
3337 gtk_tree_view_append_column (GTK_TREE_VIEW (combo_box->priv->tree_view),
3338 combo_box->priv->column);
3341 gtk_combo_box_sync_cells (combo_box,
3342 GTK_CELL_LAYOUT (combo_box->priv->column));
3344 if (gtk_tree_row_reference_valid (combo_box->priv->active_row))
3348 path = gtk_tree_row_reference_get_path (combo_box->priv->active_row);
3349 gtk_tree_view_set_cursor (GTK_TREE_VIEW (combo_box->priv->tree_view),
3351 gtk_tree_path_free (path);
3354 /* set sample/popup widgets */
3355 gtk_combo_box_set_popup_widget (combo_box, combo_box->priv->tree_view);
3357 g_signal_connect (combo_box->priv->tree_view, "key_press_event",
3358 G_CALLBACK (gtk_combo_box_list_key_press),
3360 g_signal_connect (combo_box->priv->tree_view, "enter_notify_event",
3361 G_CALLBACK (gtk_combo_box_list_enter_notify),
3363 g_signal_connect (combo_box->priv->tree_view, "row_expanded",
3364 G_CALLBACK (gtk_combo_box_model_row_expanded),
3366 g_signal_connect (combo_box->priv->tree_view, "row_collapsed",
3367 G_CALLBACK (gtk_combo_box_model_row_expanded),
3369 g_signal_connect (combo_box->priv->popup_window, "button_press_event",
3370 G_CALLBACK (gtk_combo_box_list_button_pressed),
3372 g_signal_connect (combo_box->priv->popup_window, "button_release_event",
3373 G_CALLBACK (gtk_combo_box_list_button_released),
3376 gtk_widget_show (combo_box->priv->tree_view);
3380 gtk_combo_box_list_destroy (GtkComboBox *combo_box)
3382 /* disconnect signals */
3383 g_signal_handlers_disconnect_matched (combo_box->priv->tree_view,
3384 G_SIGNAL_MATCH_DATA,
3385 0, 0, NULL, NULL, combo_box);
3386 g_signal_handlers_disconnect_matched (combo_box->priv->button,
3387 G_SIGNAL_MATCH_DATA,
3389 gtk_combo_box_list_button_pressed,
3391 g_signal_handlers_disconnect_matched (combo_box->priv->popup_window,
3392 G_SIGNAL_MATCH_DATA,
3394 gtk_combo_box_list_button_pressed,
3396 g_signal_handlers_disconnect_matched (combo_box->priv->popup_window,
3397 G_SIGNAL_MATCH_DATA,
3399 gtk_combo_box_list_button_released,
3402 g_signal_handlers_disconnect_matched (combo_box->priv->popup_window,
3403 G_SIGNAL_MATCH_DATA,
3405 gtk_combo_box_child_show,
3408 g_signal_handlers_disconnect_matched (combo_box->priv->popup_window,
3409 G_SIGNAL_MATCH_DATA,
3411 gtk_combo_box_child_hide,
3414 if (combo_box->priv->box)
3415 g_signal_handlers_disconnect_matched (combo_box->priv->box,
3416 G_SIGNAL_MATCH_DATA,
3418 gtk_combo_box_list_button_pressed,
3421 /* destroy things (unparent will kill the latest ref from us)
3422 * last unref on button will destroy the arrow
3424 gtk_widget_unparent (combo_box->priv->button);
3425 combo_box->priv->button = NULL;
3426 combo_box->priv->arrow = NULL;
3428 if (combo_box->priv->cell_view)
3430 g_object_set (combo_box->priv->cell_view,
3431 "background-set", FALSE,
3435 if (combo_box->priv->cell_view_frame)
3437 gtk_widget_unparent (combo_box->priv->cell_view_frame);
3438 combo_box->priv->cell_view_frame = NULL;
3439 combo_box->priv->box = NULL;
3442 if (combo_box->priv->scroll_timer)
3444 g_source_remove (combo_box->priv->scroll_timer);
3445 combo_box->priv->scroll_timer = 0;
3448 if (combo_box->priv->resize_idle_id)
3450 g_source_remove (combo_box->priv->resize_idle_id);
3451 combo_box->priv->resize_idle_id = 0;
3454 gtk_widget_destroy (combo_box->priv->tree_view);
3456 combo_box->priv->tree_view = NULL;
3457 combo_box->priv->popup_widget = NULL;
3463 gtk_combo_box_list_button_pressed (GtkWidget *widget,
3464 GdkEventButton *event,
3467 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3469 GtkWidget *ewidget = gtk_get_event_widget ((GdkEvent *)event);
3471 if (ewidget == combo_box->priv->popup_window)
3474 if ((ewidget != combo_box->priv->button && ewidget != combo_box->priv->box) ||
3475 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (combo_box->priv->button)))
3478 if (combo_box->priv->focus_on_click &&
3479 !GTK_WIDGET_HAS_FOCUS (combo_box->priv->button))
3480 gtk_widget_grab_focus (combo_box->priv->button);
3482 gtk_combo_box_popup (combo_box);
3484 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
3487 combo_box->priv->auto_scroll = FALSE;
3488 if (combo_box->priv->scroll_timer == 0)
3489 combo_box->priv->scroll_timer = g_timeout_add (SCROLL_TIME,
3490 (GSourceFunc) gtk_combo_box_list_scroll_timeout,
3493 combo_box->priv->popup_in_progress = TRUE;
3499 gtk_combo_box_list_button_released (GtkWidget *widget,
3500 GdkEventButton *event,
3504 GtkTreePath *path = NULL;
3507 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3509 gboolean popup_in_progress = FALSE;
3511 GtkWidget *ewidget = gtk_get_event_widget ((GdkEvent *)event);
3513 if (combo_box->priv->popup_in_progress)
3515 popup_in_progress = TRUE;
3516 combo_box->priv->popup_in_progress = FALSE;
3519 gtk_tree_view_set_hover_expand (GTK_TREE_VIEW (combo_box->priv->tree_view),
3521 if (combo_box->priv->scroll_timer)
3523 g_source_remove (combo_box->priv->scroll_timer);
3524 combo_box->priv->scroll_timer = 0;
3527 if (ewidget != combo_box->priv->tree_view)
3529 if ((ewidget == combo_box->priv->button ||
3530 ewidget == combo_box->priv->box) &&
3531 !popup_in_progress &&
3532 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (combo_box->priv->button)))
3534 gtk_combo_box_popdown (combo_box);
3538 /* released outside treeview */
3539 if (ewidget != combo_box->priv->button &&
3540 ewidget != combo_box->priv->box)
3542 gtk_combo_box_popdown (combo_box);
3550 /* select something cool */
3551 ret = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (combo_box->priv->tree_view),
3557 return TRUE; /* clicked outside window? */
3559 gtk_tree_model_get_iter (combo_box->priv->model, &iter, path);
3560 gtk_tree_path_free (path);
3562 if (tree_column_row_is_sensitive (combo_box, &iter))
3563 gtk_combo_box_set_active_iter (combo_box, &iter);
3565 gtk_combo_box_popdown (combo_box);
3571 gtk_combo_box_key_press (GtkWidget *widget,
3575 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3576 guint state = event->state & gtk_accelerator_get_default_mod_mask ();
3579 GtkTreeIter new_iter;
3581 if (combo_box->priv->model == NULL)
3584 if ((event->keyval == GDK_Down || event->keyval == GDK_KP_Down) &&
3585 state == GDK_MOD1_MASK)
3587 gtk_combo_box_popup (combo_box);
3595 switch (event->keyval)
3599 if (gtk_combo_box_get_active_iter (combo_box, &iter))
3601 found = tree_next (combo_box, combo_box->priv->model,
3602 &iter, &new_iter, FALSE);
3605 /* else fall through */
3607 case GDK_KP_Page_Up:
3610 found = tree_first (combo_box, combo_box->priv->model, &new_iter, FALSE);
3615 if (gtk_combo_box_get_active_iter (combo_box, &iter))
3617 found = tree_prev (combo_box, combo_box->priv->model,
3618 &iter, &new_iter, FALSE);
3621 /* else fall through */
3623 case GDK_KP_Page_Down:
3626 found = tree_last (combo_box, combo_box->priv->model, &new_iter, FALSE);
3633 gtk_combo_box_set_active_iter (combo_box, &new_iter);
3639 gtk_combo_box_menu_key_press (GtkWidget *widget,
3643 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3644 guint state = event->state & gtk_accelerator_get_default_mod_mask ();
3646 if ((event->keyval == GDK_Up || event->keyval == GDK_KP_Up) &&
3647 state == GDK_MOD1_MASK)
3649 gtk_combo_box_popdown (combo_box);
3658 gtk_combo_box_list_key_press (GtkWidget *widget,
3662 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3664 guint state = event->state & gtk_accelerator_get_default_mod_mask ();
3666 if (event->keyval == GDK_Escape ||
3667 ((event->keyval == GDK_Up || event->keyval == GDK_KP_Up) &&
3668 state == GDK_MOD1_MASK))
3670 /* reset active item -- this is incredibly lame and ugly */
3671 if (gtk_combo_box_get_active_iter (combo_box, &iter))
3672 gtk_combo_box_set_active_iter (combo_box, &iter);
3674 gtk_combo_box_popdown (combo_box);
3679 if (event->keyval == GDK_Return || event->keyval == GDK_KP_Enter ||
3680 event->keyval == GDK_space || event->keyval == GDK_KP_Space)
3683 GtkTreeModel *model = NULL;
3685 if (combo_box->priv->model)
3687 GtkTreeSelection *sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (combo_box->priv->tree_view));
3689 if (gtk_tree_selection_get_selected (sel, &model, &iter))
3690 gtk_combo_box_set_active_iter (combo_box, &iter);
3693 gtk_combo_box_popdown (combo_box);
3702 gtk_combo_box_list_auto_scroll (GtkComboBox *combo_box,
3706 GtkWidget *tree_view = combo_box->priv->tree_view;
3710 adj = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (combo_box->priv->scrolled_window));
3711 if (adj && adj->upper - adj->lower > adj->page_size)
3713 if (x <= tree_view->allocation.x &&
3714 adj->lower < adj->value)
3716 value = adj->value - (tree_view->allocation.x - x + 1);
3717 gtk_adjustment_set_value (adj, CLAMP (value, adj->lower, adj->upper - adj->page_size));
3719 else if (x >= tree_view->allocation.x + tree_view->allocation.width &&
3720 adj->upper - adj->page_size > adj->value)
3722 value = adj->value + (x - tree_view->allocation.x - tree_view->allocation.width + 1);
3723 gtk_adjustment_set_value (adj, CLAMP (value, 0.0, adj->upper - adj->page_size));
3727 adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (combo_box->priv->scrolled_window));
3728 if (adj && adj->upper - adj->lower > adj->page_size)
3730 if (y <= tree_view->allocation.y &&
3731 adj->lower < adj->value)
3733 value = adj->value - (tree_view->allocation.y - y + 1);
3734 gtk_adjustment_set_value (adj, CLAMP (value, adj->lower, adj->upper - adj->page_size));
3736 else if (y >= tree_view->allocation.height &&
3737 adj->upper - adj->page_size > adj->value)
3739 value = adj->value + (y - tree_view->allocation.height + 1);
3740 gtk_adjustment_set_value (adj, CLAMP (value, 0.0, adj->upper - adj->page_size));
3746 gtk_combo_box_list_scroll_timeout (GtkComboBox *combo_box)
3750 GDK_THREADS_ENTER ();
3752 if (combo_box->priv->auto_scroll)
3754 gdk_window_get_pointer (combo_box->priv->tree_view->window,
3756 gtk_combo_box_list_auto_scroll (combo_box, x, y);
3759 GDK_THREADS_LEAVE ();
3765 gtk_combo_box_list_enter_notify (GtkWidget *widget,
3766 GdkEventCrossing *event,
3769 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3771 combo_box->priv->auto_scroll = TRUE;
3778 gtk_combo_box_list_row_changed (GtkTreeModel *model,
3783 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3786 width = gtk_combo_box_calc_requested_width (combo_box, path);
3788 if (width > combo_box->priv->width)
3790 if (combo_box->priv->cell_view)
3792 gtk_widget_set_size_request (combo_box->priv->cell_view, width, -1);
3793 gtk_widget_queue_resize (combo_box->priv->cell_view);
3795 combo_box->priv->width = width;
3800 * GtkCellLayout implementation
3804 pack_start_recurse (GtkWidget *menu,
3805 GtkCellRenderer *cell,
3811 list = gtk_container_get_children (GTK_CONTAINER (menu));
3812 for (i = list; i; i = i->next)
3814 if (GTK_IS_CELL_LAYOUT (GTK_BIN (i->data)->child))
3815 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (GTK_BIN (i->data)->child),
3818 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
3819 if (submenu != NULL)
3820 pack_start_recurse (submenu, cell, expand);
3827 gtk_combo_box_cell_layout_pack_start (GtkCellLayout *layout,
3828 GtkCellRenderer *cell,
3831 ComboCellInfo *info;
3832 GtkComboBox *combo_box;
3834 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
3835 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
3837 combo_box = GTK_COMBO_BOX (layout);
3839 g_object_ref_sink (cell);
3841 info = g_new0 (ComboCellInfo, 1);
3843 info->expand = expand;
3844 info->pack = GTK_PACK_START;
3846 combo_box->priv->cells = g_slist_append (combo_box->priv->cells, info);
3848 if (combo_box->priv->cell_view)
3849 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box->priv->cell_view),
3852 if (combo_box->priv->column)
3853 gtk_tree_view_column_pack_start (combo_box->priv->column, cell, expand);
3855 if (GTK_IS_MENU (combo_box->priv->popup_widget))
3856 pack_start_recurse (combo_box->priv->popup_widget, cell, expand);
3860 pack_end_recurse (GtkWidget *menu,
3861 GtkCellRenderer *cell,
3867 list = gtk_container_get_children (GTK_CONTAINER (menu));
3868 for (i = list; i; i = i->next)
3870 if (GTK_IS_CELL_LAYOUT (GTK_BIN (i->data)->child))
3871 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (GTK_BIN (i->data)->child),
3874 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
3875 if (submenu != NULL)
3876 pack_end_recurse (submenu, cell, expand);
3883 gtk_combo_box_cell_layout_pack_end (GtkCellLayout *layout,
3884 GtkCellRenderer *cell,
3887 ComboCellInfo *info;
3888 GtkComboBox *combo_box;
3890 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
3891 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
3893 combo_box = GTK_COMBO_BOX (layout);
3895 g_object_ref_sink (cell);
3897 info = g_new0 (ComboCellInfo, 1);
3899 info->expand = expand;
3900 info->pack = GTK_PACK_END;
3902 combo_box->priv->cells = g_slist_append (combo_box->priv->cells, info);
3904 if (combo_box->priv->cell_view)
3905 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (combo_box->priv->cell_view),
3908 if (combo_box->priv->column)
3909 gtk_tree_view_column_pack_end (combo_box->priv->column, cell, expand);
3911 if (GTK_IS_MENU (combo_box->priv->popup_widget))
3912 pack_end_recurse (combo_box->priv->popup_widget, cell, expand);
3916 clear_recurse (GtkWidget *menu)
3921 list = gtk_container_get_children (GTK_CONTAINER (menu));
3922 for (i = list; i; i = i->next)
3924 if (GTK_IS_CELL_LAYOUT (GTK_BIN (i->data)->child))
3925 gtk_cell_layout_clear (GTK_CELL_LAYOUT (GTK_BIN (i->data)->child));
3927 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
3928 if (submenu != NULL)
3929 clear_recurse (submenu);
3936 gtk_combo_box_cell_layout_clear (GtkCellLayout *layout)
3938 GtkComboBox *combo_box;
3941 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
3943 combo_box = GTK_COMBO_BOX (layout);
3945 if (combo_box->priv->cell_view)
3946 gtk_cell_layout_clear (GTK_CELL_LAYOUT (combo_box->priv->cell_view));
3948 if (combo_box->priv->column)
3949 gtk_tree_view_column_clear (combo_box->priv->column);
3951 for (i = combo_box->priv->cells; i; i = i->next)
3953 ComboCellInfo *info = (ComboCellInfo *)i->data;
3955 gtk_combo_box_cell_layout_clear_attributes (layout, info->cell);
3956 g_object_unref (info->cell);
3960 g_slist_free (combo_box->priv->cells);
3961 combo_box->priv->cells = NULL;
3963 if (GTK_IS_MENU (combo_box->priv->popup_widget))
3964 clear_recurse (combo_box->priv->popup_widget);
3968 add_attribute_recurse (GtkWidget *menu,
3969 GtkCellRenderer *cell,
3970 const gchar *attribute,
3976 list = gtk_container_get_children (GTK_CONTAINER (menu));
3977 for (i = list; i; i = i->next)
3979 if (GTK_IS_CELL_LAYOUT (GTK_BIN (i->data)->child))
3980 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (GTK_BIN (i->data)->child),
3981 cell, attribute, column);
3983 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
3984 if (submenu != NULL)
3985 add_attribute_recurse (submenu, cell, attribute, column);
3992 gtk_combo_box_cell_layout_add_attribute (GtkCellLayout *layout,
3993 GtkCellRenderer *cell,
3994 const gchar *attribute,
3997 ComboCellInfo *info;
3998 GtkComboBox *combo_box;
4000 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
4001 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4003 combo_box = GTK_COMBO_BOX (layout);
4005 info = gtk_combo_box_get_cell_info (combo_box, cell);
4007 info->attributes = g_slist_prepend (info->attributes,
4008 GINT_TO_POINTER (column));
4009 info->attributes = g_slist_prepend (info->attributes,
4010 g_strdup (attribute));
4012 if (combo_box->priv->cell_view)
4013 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo_box->priv->cell_view),
4014 cell, attribute, column);
4016 if (combo_box->priv->column)
4017 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo_box->priv->column),
4018 cell, attribute, column);
4020 if (GTK_IS_MENU (combo_box->priv->popup_widget))
4021 add_attribute_recurse (combo_box->priv->popup_widget, cell, attribute, column);
4022 gtk_widget_queue_resize (GTK_WIDGET (combo_box));
4026 combo_cell_data_func (GtkCellLayout *cell_layout,
4027 GtkCellRenderer *cell,
4028 GtkTreeModel *tree_model,
4032 ComboCellInfo *info = (ComboCellInfo *)data;
4033 GtkWidget *parent = NULL;
4038 (*info->func) (cell_layout, cell, tree_model, iter, info->func_data);
4040 if (GTK_IS_WIDGET (cell_layout))
4041 parent = gtk_widget_get_parent (GTK_WIDGET (cell_layout));
4043 if (GTK_IS_MENU_ITEM (parent) &&
4044 gtk_menu_item_get_submenu (GTK_MENU_ITEM (parent)))
4045 g_object_set (cell, "sensitive", TRUE, NULL);
4050 set_cell_data_func_recurse (GtkWidget *menu,
4051 GtkCellRenderer *cell,
4052 ComboCellInfo *info)
4056 GtkWidget *cell_view;
4058 list = gtk_container_get_children (GTK_CONTAINER (menu));
4059 for (i = list; i; i = i->next)
4061 cell_view = GTK_BIN (i->data)->child;
4062 if (GTK_IS_CELL_LAYOUT (cell_view))
4064 /* Override sensitivity for inner nodes; we don't
4065 * want menuitems with submenus to appear insensitive
4067 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (cell_view),
4069 combo_cell_data_func,
4071 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4072 if (submenu != NULL)
4073 set_cell_data_func_recurse (submenu, cell, info);
4081 gtk_combo_box_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4082 GtkCellRenderer *cell,
4083 GtkCellLayoutDataFunc func,
4085 GDestroyNotify destroy)
4087 ComboCellInfo *info;
4088 GtkComboBox *combo_box;
4090 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
4092 combo_box = GTK_COMBO_BOX (layout);
4094 info = gtk_combo_box_get_cell_info (combo_box, cell);
4095 g_return_if_fail (info != NULL);
4099 GDestroyNotify d = info->destroy;
4101 info->destroy = NULL;
4102 d (info->func_data);
4106 info->func_data = func_data;
4107 info->destroy = destroy;
4109 if (combo_box->priv->cell_view)
4110 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo_box->priv->cell_view), cell, func, func_data, NULL);
4112 if (combo_box->priv->column)
4113 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo_box->priv->column), cell, func, func_data, NULL);
4115 if (GTK_IS_MENU (combo_box->priv->popup_widget))
4116 set_cell_data_func_recurse (combo_box->priv->popup_widget, cell, info);
4118 gtk_widget_queue_resize (GTK_WIDGET (combo_box));
4122 clear_attributes_recurse (GtkWidget *menu,
4123 GtkCellRenderer *cell)
4128 list = gtk_container_get_children (GTK_CONTAINER (menu));
4129 for (i = list; i; i = i->next)
4131 if (GTK_IS_CELL_LAYOUT (GTK_BIN (i->data)->child))
4132 gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (GTK_BIN (i->data)->child),
4135 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4136 if (submenu != NULL)
4137 clear_attributes_recurse (submenu, cell);
4144 gtk_combo_box_cell_layout_clear_attributes (GtkCellLayout *layout,
4145 GtkCellRenderer *cell)
4147 ComboCellInfo *info;
4148 GtkComboBox *combo_box;
4151 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
4152 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4154 combo_box = GTK_COMBO_BOX (layout);
4156 info = gtk_combo_box_get_cell_info (combo_box, cell);
4157 g_return_if_fail (info != NULL);
4159 list = info->attributes;
4160 while (list && list->next)
4162 g_free (list->data);
4163 list = list->next->next;
4165 g_slist_free (info->attributes);
4166 info->attributes = NULL;
4168 if (combo_box->priv->cell_view)
4169 gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (combo_box->priv->cell_view), cell);
4171 if (combo_box->priv->column)
4172 gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (combo_box->priv->column), cell);
4174 if (GTK_IS_MENU (combo_box->priv->popup_widget))
4175 clear_attributes_recurse (combo_box->priv->popup_widget, cell);
4177 gtk_widget_queue_resize (GTK_WIDGET (combo_box));
4181 reorder_recurse (GtkWidget *menu,
4182 GtkCellRenderer *cell,
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_reorder (GTK_CELL_LAYOUT (GTK_BIN (i->data)->child),
4195 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4196 if (submenu != NULL)
4197 reorder_recurse (submenu, cell, position);
4204 gtk_combo_box_cell_layout_reorder (GtkCellLayout *layout,
4205 GtkCellRenderer *cell,
4208 ComboCellInfo *info;
4209 GtkComboBox *combo_box;
4212 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
4213 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4215 combo_box = GTK_COMBO_BOX (layout);
4217 info = gtk_combo_box_get_cell_info (combo_box, cell);
4219 g_return_if_fail (info != NULL);
4220 g_return_if_fail (position >= 0);
4222 link = g_slist_find (combo_box->priv->cells, info);
4224 g_return_if_fail (link != NULL);
4226 combo_box->priv->cells = g_slist_remove_link (combo_box->priv->cells, link);
4227 combo_box->priv->cells = g_slist_insert (combo_box->priv->cells, info,
4230 if (combo_box->priv->cell_view)
4231 gtk_cell_layout_reorder (GTK_CELL_LAYOUT (combo_box->priv->cell_view),
4234 if (combo_box->priv->column)
4235 gtk_cell_layout_reorder (GTK_CELL_LAYOUT (combo_box->priv->column),
4238 if (GTK_IS_MENU (combo_box->priv->popup_widget))
4239 reorder_recurse (combo_box->priv->popup_widget, cell, position);
4241 gtk_widget_queue_draw (GTK_WIDGET (combo_box));
4249 * gtk_combo_box_new:
4251 * Creates a new empty #GtkComboBox.
4253 * Return value: A new #GtkComboBox.
4258 gtk_combo_box_new (void)
4260 return g_object_new (GTK_TYPE_COMBO_BOX, NULL);
4264 * gtk_combo_box_new_with_model:
4265 * @model: A #GtkTreeModel.
4267 * Creates a new #GtkComboBox with the model initialized to @model.
4269 * Return value: A new #GtkComboBox.
4274 gtk_combo_box_new_with_model (GtkTreeModel *model)
4276 GtkComboBox *combo_box;
4278 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
4280 combo_box = g_object_new (GTK_TYPE_COMBO_BOX, "model", model, NULL);
4282 return GTK_WIDGET (combo_box);
4286 * gtk_combo_box_get_wrap_width:
4287 * @combo_box: A #GtkComboBox.
4289 * Returns the wrap width which is used to determine the number
4290 * of columns for the popup menu. If the wrap width is larger than
4291 * 1, the combo box is in table mode.
4293 * Returns: the wrap width.
4298 gtk_combo_box_get_wrap_width (GtkComboBox *combo_box)
4300 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), -1);
4302 return combo_box->priv->wrap_width;
4306 * gtk_combo_box_set_wrap_width:
4307 * @combo_box: A #GtkComboBox.
4308 * @width: Preferred number of columns.
4310 * Sets the wrap width of @combo_box to be @width. The wrap width is basically
4311 * the preferred number of columns when you want the popup to be layed out
4317 gtk_combo_box_set_wrap_width (GtkComboBox *combo_box,
4320 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4321 g_return_if_fail (width >= 0);
4323 if (width != combo_box->priv->wrap_width)
4325 combo_box->priv->wrap_width = width;
4327 gtk_combo_box_check_appearance (combo_box);
4328 gtk_combo_box_relayout (combo_box);
4330 g_object_notify (G_OBJECT (combo_box), "wrap-width");
4335 * gtk_combo_box_get_row_span_column:
4336 * @combo_box: A #GtkComboBox.
4338 * Returns the column with row span information for @combo_box.
4340 * Returns: the row span column.
4345 gtk_combo_box_get_row_span_column (GtkComboBox *combo_box)
4347 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), -1);
4349 return combo_box->priv->row_column;
4353 * gtk_combo_box_set_row_span_column:
4354 * @combo_box: A #GtkComboBox.
4355 * @row_span: A column in the model passed during construction.
4357 * Sets the column with row span information for @combo_box to be @row_span.
4358 * The row span column contains integers which indicate how many rows
4359 * an item should span.
4364 gtk_combo_box_set_row_span_column (GtkComboBox *combo_box,
4369 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4371 col = gtk_tree_model_get_n_columns (combo_box->priv->model);
4372 g_return_if_fail (row_span >= -1 && row_span < col);
4374 if (row_span != combo_box->priv->row_column)
4376 combo_box->priv->row_column = row_span;
4378 gtk_combo_box_relayout (combo_box);
4380 g_object_notify (G_OBJECT (combo_box), "row-span-column");
4385 * gtk_combo_box_get_column_span_column:
4386 * @combo_box: A #GtkComboBox.
4388 * Returns the column with column span information for @combo_box.
4390 * Returns: the column span column.
4395 gtk_combo_box_get_column_span_column (GtkComboBox *combo_box)
4397 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), -1);
4399 return combo_box->priv->col_column;
4403 * gtk_combo_box_set_column_span_column:
4404 * @combo_box: A #GtkComboBox.
4405 * @column_span: A column in the model passed during construction.
4407 * Sets the column with column span information for @combo_box to be
4408 * @column_span. The column span column contains integers which indicate
4409 * how many columns an item should span.
4414 gtk_combo_box_set_column_span_column (GtkComboBox *combo_box,
4419 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4421 col = gtk_tree_model_get_n_columns (combo_box->priv->model);
4422 g_return_if_fail (column_span >= -1 && column_span < col);
4424 if (column_span != combo_box->priv->col_column)
4426 combo_box->priv->col_column = column_span;
4428 gtk_combo_box_relayout (combo_box);
4430 g_object_notify (G_OBJECT (combo_box), "column-span-column");
4435 * gtk_combo_box_get_active:
4436 * @combo_box: A #GtkComboBox.
4438 * Returns the index of the currently active item, or -1 if there's no
4439 * active item. If the model is a non-flat treemodel, and the active item
4440 * is not an immediate child of the root of the tree, this function returns
4441 * <literal>gtk_tree_path_get_indices (path)[0]</literal>, where
4442 * <literal>path</literal> is the #GtkTreePath of the active item.
4444 * Return value: An integer which is the index of the currently active item, or
4445 * -1 if there's no active item.
4450 gtk_combo_box_get_active (GtkComboBox *combo_box)
4453 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), 0);
4455 if (gtk_tree_row_reference_valid (combo_box->priv->active_row))
4459 path = gtk_tree_row_reference_get_path (combo_box->priv->active_row);
4460 result = gtk_tree_path_get_indices (path)[0];
4461 gtk_tree_path_free (path);
4470 * gtk_combo_box_set_active:
4471 * @combo_box: A #GtkComboBox.
4472 * @index_: An index in the model passed during construction, or -1 to have
4475 * Sets the active item of @combo_box to be the item at @index.
4480 gtk_combo_box_set_active (GtkComboBox *combo_box,
4483 GtkTreePath *path = NULL;
4484 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4485 g_return_if_fail (index_ >= -1);
4488 path = gtk_tree_path_new_from_indices (index_, -1);
4490 gtk_combo_box_set_active_internal (combo_box, path);
4493 gtk_tree_path_free (path);
4497 gtk_combo_box_set_active_internal (GtkComboBox *combo_box,
4500 GtkTreePath *active_path;
4503 if (path && gtk_tree_row_reference_valid (combo_box->priv->active_row))
4505 active_path = gtk_tree_row_reference_get_path (combo_box->priv->active_row);
4506 path_cmp = gtk_tree_path_compare (path, active_path);
4507 gtk_tree_path_free (active_path);
4512 if (combo_box->priv->active_row)
4514 gtk_tree_row_reference_free (combo_box->priv->active_row);
4515 combo_box->priv->active_row = NULL;
4520 if (combo_box->priv->tree_view)
4521 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (combo_box->priv->tree_view)));
4524 GtkMenu *menu = GTK_MENU (combo_box->priv->popup_widget);
4526 if (GTK_IS_MENU (menu))
4527 gtk_menu_set_active (menu, -1);
4530 if (combo_box->priv->cell_view)
4531 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (combo_box->priv->cell_view), NULL);
4535 combo_box->priv->active_row =
4536 gtk_tree_row_reference_new (combo_box->priv->model, path);
4538 if (combo_box->priv->tree_view)
4540 gtk_tree_view_set_cursor (GTK_TREE_VIEW (combo_box->priv->tree_view),
4543 else if (GTK_IS_MENU (combo_box->priv->popup_widget))
4545 /* FIXME handle nested menus better */
4546 gtk_menu_set_active (GTK_MENU (combo_box->priv->popup_widget),
4547 gtk_tree_path_get_indices (path)[0]);
4550 if (combo_box->priv->cell_view)
4551 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (combo_box->priv->cell_view),
4555 g_signal_emit (combo_box, combo_box_signals[CHANGED], 0);
4556 g_object_notify (G_OBJECT (combo_box), "active");
4561 * gtk_combo_box_get_active_iter:
4562 * @combo_box: A #GtkComboBox
4563 * @iter: The uninitialized #GtkTreeIter.
4565 * Sets @iter to point to the current active item, if it exists.
4567 * Return value: %TRUE, if @iter was set
4572 gtk_combo_box_get_active_iter (GtkComboBox *combo_box,
4578 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE);
4580 if (!gtk_tree_row_reference_valid (combo_box->priv->active_row))
4583 path = gtk_tree_row_reference_get_path (combo_box->priv->active_row);
4584 result = gtk_tree_model_get_iter (combo_box->priv->model, iter, path);
4585 gtk_tree_path_free (path);
4591 * gtk_combo_box_set_active_iter:
4592 * @combo_box: A #GtkComboBox
4593 * @iter: The #GtkTreeIter.
4595 * Sets the current active item to be the one referenced by @iter.
4596 * @iter must correspond to a path of depth one.
4601 gtk_combo_box_set_active_iter (GtkComboBox *combo_box,
4606 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4608 path = gtk_tree_model_get_path (gtk_combo_box_get_model (combo_box), iter);
4609 gtk_combo_box_set_active_internal (combo_box, path);
4610 gtk_tree_path_free (path);
4614 * gtk_combo_box_set_model:
4615 * @combo_box: A #GtkComboBox.
4616 * @model: A #GtkTreeModel.
4618 * Sets the model used by @combo_box to be @model. Will unset a previously set
4619 * model (if applicable). If model is %NULL, then it will unset the model.
4621 * Note that this function does not clear the cell renderers, you have to
4622 * call gtk_combo_box_cell_layout_clear() yourself if you need to set up
4623 * different cell renderers for the new model.
4628 gtk_combo_box_set_model (GtkComboBox *combo_box,
4629 GtkTreeModel *model)
4631 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4635 gtk_combo_box_unset_model (combo_box);
4639 g_return_if_fail (GTK_IS_TREE_MODEL (model));
4641 if (model == combo_box->priv->model)
4644 if (combo_box->priv->model)
4645 gtk_combo_box_unset_model (combo_box);
4647 combo_box->priv->model = model;
4648 g_object_ref (combo_box->priv->model);
4650 combo_box->priv->inserted_id =
4651 g_signal_connect (combo_box->priv->model, "row_inserted",
4652 G_CALLBACK (gtk_combo_box_model_row_inserted),
4654 combo_box->priv->deleted_id =
4655 g_signal_connect (combo_box->priv->model, "row_deleted",
4656 G_CALLBACK (gtk_combo_box_model_row_deleted),
4658 combo_box->priv->reordered_id =
4659 g_signal_connect (combo_box->priv->model, "rows_reordered",
4660 G_CALLBACK (gtk_combo_box_model_rows_reordered),
4662 combo_box->priv->changed_id =
4663 g_signal_connect (combo_box->priv->model, "row_changed",
4664 G_CALLBACK (gtk_combo_box_model_row_changed),
4667 if (combo_box->priv->tree_view)
4670 gtk_tree_view_set_model (GTK_TREE_VIEW (combo_box->priv->tree_view),
4671 combo_box->priv->model);
4672 gtk_combo_box_list_popup_resize (combo_box);
4677 if (combo_box->priv->popup_widget)
4678 gtk_combo_box_menu_fill (combo_box);
4682 if (combo_box->priv->cell_view)
4683 gtk_cell_view_set_model (GTK_CELL_VIEW (combo_box->priv->cell_view),
4684 combo_box->priv->model);
4688 * gtk_combo_box_get_model
4689 * @combo_box: A #GtkComboBox.
4691 * Returns the #GtkTreeModel which is acting as data source for @combo_box.
4693 * Return value: A #GtkTreeModel which was passed during construction.
4698 gtk_combo_box_get_model (GtkComboBox *combo_box)
4700 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
4702 return combo_box->priv->model;
4706 /* convenience API for simple text combos */
4709 * gtk_combo_box_new_text:
4711 * Convenience function which constructs a new text combo box, which is a
4712 * #GtkComboBox just displaying strings. If you use this function to create
4713 * a text combo box, you should only manipulate its data source with the
4714 * following convenience functions: gtk_combo_box_append_text(),
4715 * gtk_combo_box_insert_text(), gtk_combo_box_prepend_text() and
4716 * gtk_combo_box_remove_text().
4718 * Return value: A new text combo box.
4723 gtk_combo_box_new_text (void)
4725 GtkWidget *combo_box;
4726 GtkCellRenderer *cell;
4727 GtkListStore *store;
4729 store = gtk_list_store_new (1, G_TYPE_STRING);
4730 combo_box = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));
4731 g_object_unref (store);
4733 cell = gtk_cell_renderer_text_new ();
4734 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), cell, TRUE);
4735 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), cell,
4743 * gtk_combo_box_append_text:
4744 * @combo_box: A #GtkComboBox constructed using gtk_combo_box_new_text().
4747 * Appends @string to the list of strings stored in @combo_box. Note that
4748 * you can only use this function with combo boxes constructed with
4749 * gtk_combo_box_new_text().
4754 gtk_combo_box_append_text (GtkComboBox *combo_box,
4758 GtkListStore *store;
4760 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4761 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
4762 g_return_if_fail (text != NULL);
4764 store = GTK_LIST_STORE (combo_box->priv->model);
4766 gtk_list_store_append (store, &iter);
4767 gtk_list_store_set (store, &iter, 0, text, -1);
4771 * gtk_combo_box_insert_text:
4772 * @combo_box: A #GtkComboBox constructed using gtk_combo_box_new_text().
4773 * @position: An index to insert @text.
4776 * Inserts @string at @position in the list of strings stored in @combo_box.
4777 * Note that you can only use this function with combo boxes constructed
4778 * with gtk_combo_box_new_text().
4783 gtk_combo_box_insert_text (GtkComboBox *combo_box,
4788 GtkListStore *store;
4790 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4791 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
4792 g_return_if_fail (position >= 0);
4793 g_return_if_fail (text != NULL);
4795 store = GTK_LIST_STORE (combo_box->priv->model);
4797 gtk_list_store_insert (store, &iter, position);
4798 gtk_list_store_set (store, &iter, 0, text, -1);
4802 * gtk_combo_box_prepend_text:
4803 * @combo_box: A #GtkComboBox constructed with gtk_combo_box_new_text().
4806 * Prepends @string to the list of strings stored in @combo_box. Note that
4807 * you can only use this function with combo boxes constructed with
4808 * gtk_combo_box_new_text().
4813 gtk_combo_box_prepend_text (GtkComboBox *combo_box,
4817 GtkListStore *store;
4819 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4820 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
4821 g_return_if_fail (text != NULL);
4823 store = GTK_LIST_STORE (combo_box->priv->model);
4825 gtk_list_store_prepend (store, &iter);
4826 gtk_list_store_set (store, &iter, 0, text, -1);
4830 * gtk_combo_box_remove_text:
4831 * @combo_box: A #GtkComboBox constructed with gtk_combo_box_new_text().
4832 * @position: Index of the item to remove.
4834 * Removes the string at @position from @combo_box. Note that you can only use
4835 * this function with combo boxes constructed with gtk_combo_box_new_text().
4840 gtk_combo_box_remove_text (GtkComboBox *combo_box,
4844 GtkListStore *store;
4846 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4847 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
4848 g_return_if_fail (position >= 0);
4850 store = GTK_LIST_STORE (combo_box->priv->model);
4852 if (gtk_tree_model_iter_nth_child (combo_box->priv->model, &iter,
4854 gtk_list_store_remove (store, &iter);
4858 * gtk_combo_box_get_active_text:
4859 * @combo_box: A #GtkComboBox constructed with gtk_combo_box_new_text().
4861 * Returns the currently active string in @combo_box or %NULL if none
4862 * is selected. Note that you can only use this function with combo
4863 * boxes constructed with gtk_combo_box_new_text() and with
4864 * #GtkComboBoxEntry<!-- -->s.
4866 * Returns: a newly allocated string containing the currently active text.
4871 gtk_combo_box_get_active_text (GtkComboBox *combo_box)
4873 GtkComboBoxClass *class;
4875 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
4877 class = GTK_COMBO_BOX_GET_CLASS (combo_box);
4879 if (class->get_active_text)
4880 return (* class->get_active_text) (combo_box);
4886 gtk_combo_box_real_get_active_text (GtkComboBox *combo_box)
4891 g_return_val_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model), NULL);
4893 if (gtk_combo_box_get_active_iter (combo_box, &iter))
4894 gtk_tree_model_get (combo_box->priv->model, &iter,
4901 gtk_combo_box_mnemonic_activate (GtkWidget *widget,
4902 gboolean group_cycling)
4904 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
4906 gtk_widget_grab_focus (combo_box->priv->button);
4912 gtk_combo_box_grab_focus (GtkWidget *widget)
4914 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
4916 gtk_widget_grab_focus (combo_box->priv->button);
4920 gtk_combo_box_destroy (GtkObject *object)
4922 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
4924 if (combo_box->priv->popup_idle_id > 0)
4926 g_source_remove (combo_box->priv->popup_idle_id);
4927 combo_box->priv->popup_idle_id = 0;
4930 gtk_combo_box_popdown (combo_box);
4932 if (combo_box->priv->row_separator_destroy)
4933 (* combo_box->priv->row_separator_destroy) (combo_box->priv->row_separator_data);
4935 combo_box->priv->row_separator_func = NULL;
4936 combo_box->priv->row_separator_data = NULL;
4937 combo_box->priv->row_separator_destroy = NULL;
4939 combo_box->priv->destroying = 1;
4941 GTK_OBJECT_CLASS (parent_class)->destroy (object);
4942 combo_box->priv->cell_view = NULL;
4944 combo_box->priv->destroying = 0;
4948 gtk_combo_box_finalize (GObject *object)
4950 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
4953 if (GTK_IS_MENU (combo_box->priv->popup_widget))
4955 gtk_combo_box_menu_destroy (combo_box);
4956 gtk_menu_detach (GTK_MENU (combo_box->priv->popup_widget));
4957 combo_box->priv->popup_widget = NULL;
4960 if (GTK_IS_TREE_VIEW (combo_box->priv->tree_view))
4961 gtk_combo_box_list_destroy (combo_box);
4963 if (combo_box->priv->popup_window)
4964 gtk_widget_destroy (combo_box->priv->popup_window);
4966 gtk_combo_box_unset_model (combo_box);
4968 for (i = combo_box->priv->cells; i; i = i->next)
4970 ComboCellInfo *info = (ComboCellInfo *)i->data;
4971 GSList *list = info->attributes;
4974 info->destroy (info->func_data);
4976 while (list && list->next)
4978 g_free (list->data);
4979 list = list->next->next;
4981 g_slist_free (info->attributes);
4983 g_object_unref (info->cell);
4986 g_slist_free (combo_box->priv->cells);
4988 G_OBJECT_CLASS (parent_class)->finalize (object);
4992 gtk_cell_editable_key_press (GtkWidget *widget,
4996 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
4998 if (event->keyval == GDK_Escape)
5000 combo_box->priv->editing_canceled = TRUE;
5002 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (combo_box));
5003 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (combo_box));
5007 else if (event->keyval == GDK_Return)
5009 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (combo_box));
5010 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (combo_box));
5019 popdown_idle (gpointer data)
5021 GtkComboBox *combo_box;
5023 GDK_THREADS_ENTER ();
5025 combo_box = GTK_COMBO_BOX (data);
5027 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (combo_box));
5028 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (combo_box));
5030 g_object_unref (combo_box);
5032 GDK_THREADS_LEAVE ();
5038 popdown_handler (GtkWidget *widget,
5041 g_idle_add (popdown_idle, g_object_ref (data));
5045 popup_idle (gpointer data)
5047 GtkComboBox *combo_box;
5049 GDK_THREADS_ENTER ();
5051 combo_box = GTK_COMBO_BOX (data);
5053 if (GTK_IS_MENU (combo_box->priv->popup_widget) &&
5054 combo_box->priv->cell_view)
5055 g_signal_connect_object (combo_box->priv->popup_widget,
5056 "unmap", G_CALLBACK (popdown_handler),
5059 /* we unset this if a menu item is activated */
5060 combo_box->priv->editing_canceled = TRUE;
5061 gtk_combo_box_popup (combo_box);
5063 combo_box->priv->popup_idle_id = 0;
5065 GDK_THREADS_LEAVE ();
5071 gtk_combo_box_start_editing (GtkCellEditable *cell_editable,
5074 GtkComboBox *combo_box = GTK_COMBO_BOX (cell_editable);
5076 combo_box->priv->is_cell_renderer = TRUE;
5078 if (combo_box->priv->cell_view)
5080 g_signal_connect_object (combo_box->priv->button, "key_press_event",
5081 G_CALLBACK (gtk_cell_editable_key_press),
5084 gtk_widget_grab_focus (combo_box->priv->button);
5088 g_signal_connect_object (GTK_BIN (combo_box)->child, "key_press_event",
5089 G_CALLBACK (gtk_cell_editable_key_press),
5092 gtk_widget_grab_focus (GTK_WIDGET (GTK_BIN (combo_box)->child));
5093 GTK_WIDGET_UNSET_FLAGS (combo_box->priv->button, GTK_CAN_FOCUS);
5096 /* we do the immediate popup only for the optionmenu-like
5099 if (combo_box->priv->is_cell_renderer &&
5100 combo_box->priv->cell_view && !combo_box->priv->tree_view)
5101 combo_box->priv->popup_idle_id = g_idle_add (popup_idle, combo_box);
5106 * gtk_combo_box_get_add_tearoffs:
5107 * @combo_box: a #GtkComboBox
5109 * Gets the current value of the :add-tearoffs property.
5111 * Return value: the current value of the :add-tearoffs property.
5114 gtk_combo_box_get_add_tearoffs (GtkComboBox *combo_box)
5116 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE);
5118 return combo_box->priv->add_tearoffs;
5122 * gtk_combo_box_set_add_tearoffs:
5123 * @combo_box: a #GtkComboBox
5124 * @add_tearoffs: %TRUE to add tearoff menu items
5126 * Sets whether the popup menu should have a tearoff
5132 gtk_combo_box_set_add_tearoffs (GtkComboBox *combo_box,
5133 gboolean add_tearoffs)
5135 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5137 add_tearoffs = add_tearoffs != FALSE;
5139 if (combo_box->priv->add_tearoffs != add_tearoffs)
5141 combo_box->priv->add_tearoffs = add_tearoffs;
5142 gtk_combo_box_check_appearance (combo_box);
5143 gtk_combo_box_relayout (combo_box);
5144 g_object_notify (G_OBJECT (combo_box), "add-tearoffs");
5149 * gtk_combo_box_get_title:
5150 * @combo_box: a #GtkComboBox
5152 * Gets the current title of the menu in tearoff mode. See
5153 * gtk_combo_box_set_add_tearoffs().
5155 * Returns: the menu's title in tearoff mode. This is an internal copy of the
5156 * string which must not be freed.
5160 G_CONST_RETURN gchar*
5161 gtk_combo_box_get_title (GtkComboBox *combo_box)
5163 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
5165 return combo_box->priv->tearoff_title;
5169 gtk_combo_box_update_title (GtkComboBox *combo_box)
5171 gtk_combo_box_check_appearance (combo_box);
5173 if (combo_box->priv->popup_widget &&
5174 GTK_IS_MENU (combo_box->priv->popup_widget))
5175 gtk_menu_set_title (GTK_MENU (combo_box->priv->popup_widget),
5176 combo_box->priv->tearoff_title);
5180 * gtk_combo_box_set_title:
5181 * @combo_box: a #GtkComboBox
5182 * @title: a title for the menu in tearoff mode.
5184 * Sets the menu's title in tearoff mode.
5189 gtk_combo_box_set_title (GtkComboBox *combo_box,
5192 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5194 if (strcmp (title ? title : "",
5195 combo_box->priv->tearoff_title ? combo_box->priv->tearoff_title : "") != 0)
5197 g_free (combo_box->priv->tearoff_title);
5198 combo_box->priv->tearoff_title = g_strdup (title);
5200 gtk_combo_box_update_title (combo_box);
5202 g_object_notify (G_OBJECT (combo_box), "tearoff-title");
5207 _gtk_combo_box_editing_canceled (GtkComboBox *combo_box)
5209 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), TRUE);
5211 return combo_box->priv->editing_canceled;
5215 * gtk_combo_box_get_popup_accessible:
5216 * @combo_box: a #GtkComboBox
5218 * Gets the accessible object corresponding to the combo box's popup.
5220 * This function is mostly intended for use by accessibility technologies;
5221 * applications should have little use for it.
5223 * Returns: the accessible object corresponding to the combo box's popup.
5228 gtk_combo_box_get_popup_accessible (GtkComboBox *combo_box)
5232 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
5234 if (combo_box->priv->popup_widget)
5236 atk_obj = gtk_widget_get_accessible (combo_box->priv->popup_widget);
5244 * gtk_combo_box_get_row_separator_func:
5245 * @combo_box: a #GtkComboBox
5247 * Returns the current row separator function.
5249 * Return value: the current row separator function.
5253 GtkTreeViewRowSeparatorFunc
5254 gtk_combo_box_get_row_separator_func (GtkComboBox *combo_box)
5256 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
5258 return combo_box->priv->row_separator_func;
5262 * gtk_combo_box_set_row_separator_func:
5263 * @combo_box: a #GtkComboBox
5264 * @func: a #GtkTreeViewRowSeparatorFunc
5265 * @data: user data to pass to @func, or %NULL
5266 * @destroy: destroy notifier for @data, or %NULL
5268 * Sets the row separator function, which is used to determine
5269 * whether a row should be drawn as a separator. If the row separator
5270 * function is %NULL, no separators are drawn. This is the default value.
5275 gtk_combo_box_set_row_separator_func (GtkComboBox *combo_box,
5276 GtkTreeViewRowSeparatorFunc func,
5278 GtkDestroyNotify destroy)
5280 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5282 if (combo_box->priv->row_separator_destroy)
5283 (* combo_box->priv->row_separator_destroy) (combo_box->priv->row_separator_data);
5285 combo_box->priv->row_separator_func = func;
5286 combo_box->priv->row_separator_data = data;
5287 combo_box->priv->row_separator_destroy = destroy;
5289 if (combo_box->priv->tree_view)
5290 gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (combo_box->priv->tree_view),
5293 gtk_combo_box_relayout (combo_box);
5295 gtk_widget_queue_draw (GTK_WIDGET (combo_box));
5300 * gtk_combo_box_set_focus_on_click:
5301 * @combo: a #GtkComboBox
5302 * @focus_on_click: whether the combo box grabs focus when clicked
5305 * Sets whether the combo box will grab focus when it is clicked with
5306 * the mouse. Making mouse clicks not grab focus is useful in places
5307 * like toolbars where you don't want the keyboard focus removed from
5308 * the main area of the application.
5313 gtk_combo_box_set_focus_on_click (GtkComboBox *combo_box,
5314 gboolean focus_on_click)
5316 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5318 focus_on_click = focus_on_click != FALSE;
5320 if (combo_box->priv->focus_on_click != focus_on_click)
5322 combo_box->priv->focus_on_click = focus_on_click;
5324 if (combo_box->priv->button)
5325 gtk_button_set_focus_on_click (GTK_BUTTON (combo_box->priv->button),
5328 g_object_notify (G_OBJECT (combo_box), "focus-on-click");
5333 * gtk_combo_box_get_focus_on_click:
5334 * @combo: a #GtkComboBox
5336 * Returns whether the combo box grabs focus when it is clicked
5337 * with the mouse. See gtk_combo_box_set_focus_on_click().
5339 * Return value: %TRUE if the combo box grabs focus when it is
5340 * clicked with the mouse.
5345 gtk_combo_box_get_focus_on_click (GtkComboBox *combo_box)
5347 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE);
5349 return combo_box->priv->focus_on_click;
5353 #define __GTK_COMBO_BOX_C__
5354 #include "gtkaliasdef.c"