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 popup_shown : 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
195 PROP_ROW_SPAN_COLUMN,
196 PROP_COLUMN_SPAN_COLUMN,
205 static GtkBinClass *parent_class = NULL;
206 static guint combo_box_signals[LAST_SIGNAL] = {0,};
208 #define BONUS_PADDING 4
209 #define SCROLL_TIME 100
213 static void gtk_combo_box_class_init (GtkComboBoxClass *klass);
214 static void gtk_combo_box_cell_layout_init (GtkCellLayoutIface *iface);
215 static void gtk_combo_box_cell_editable_init (GtkCellEditableIface *iface);
216 static void gtk_combo_box_init (GtkComboBox *combo_box);
217 static void gtk_combo_box_finalize (GObject *object);
218 static void gtk_combo_box_destroy (GtkObject *object);
220 static void gtk_combo_box_set_property (GObject *object,
224 static void gtk_combo_box_get_property (GObject *object,
229 static void gtk_combo_box_state_changed (GtkWidget *widget,
230 GtkStateType previous);
231 static void gtk_combo_box_grab_focus (GtkWidget *widget);
232 static void gtk_combo_box_style_set (GtkWidget *widget,
234 static void gtk_combo_box_button_toggled (GtkWidget *widget,
236 static void gtk_combo_box_button_state_changed (GtkWidget *widget,
237 GtkStateType previous,
239 static void gtk_combo_box_add (GtkContainer *container,
241 static void gtk_combo_box_remove (GtkContainer *container,
244 static ComboCellInfo *gtk_combo_box_get_cell_info (GtkComboBox *combo_box,
245 GtkCellRenderer *cell);
247 static void gtk_combo_box_menu_show (GtkWidget *menu,
249 static void gtk_combo_box_menu_hide (GtkWidget *menu,
252 static void gtk_combo_box_set_popup_widget (GtkComboBox *combo_box,
254 static void gtk_combo_box_menu_position_below (GtkMenu *menu,
259 static void gtk_combo_box_menu_position_over (GtkMenu *menu,
264 static void gtk_combo_box_menu_position (GtkMenu *menu,
270 static gint gtk_combo_box_calc_requested_width (GtkComboBox *combo_box,
272 static void gtk_combo_box_remeasure (GtkComboBox *combo_box);
274 static void gtk_combo_box_unset_model (GtkComboBox *combo_box);
276 static void gtk_combo_box_size_request (GtkWidget *widget,
277 GtkRequisition *requisition);
278 static void gtk_combo_box_size_allocate (GtkWidget *widget,
279 GtkAllocation *allocation);
280 static void gtk_combo_box_forall (GtkContainer *container,
281 gboolean include_internals,
282 GtkCallback callback,
283 gpointer callback_data);
284 static gboolean gtk_combo_box_expose_event (GtkWidget *widget,
285 GdkEventExpose *event);
286 static gboolean gtk_combo_box_scroll_event (GtkWidget *widget,
287 GdkEventScroll *event);
288 static void gtk_combo_box_set_active_internal (GtkComboBox *combo_box,
290 static gboolean gtk_combo_box_key_press (GtkWidget *widget,
294 static void gtk_combo_box_check_appearance (GtkComboBox *combo_box);
295 static gchar * gtk_combo_box_real_get_active_text (GtkComboBox *combo_box);
297 /* listening to the model */
298 static void gtk_combo_box_model_row_inserted (GtkTreeModel *model,
302 static void gtk_combo_box_model_row_deleted (GtkTreeModel *model,
305 static void gtk_combo_box_model_rows_reordered (GtkTreeModel *model,
310 static void gtk_combo_box_model_row_changed (GtkTreeModel *model,
314 static void gtk_combo_box_model_row_expanded (GtkTreeModel *model,
320 static void gtk_combo_box_list_position (GtkComboBox *combo_box,
325 static void gtk_combo_box_list_setup (GtkComboBox *combo_box);
326 static void gtk_combo_box_list_destroy (GtkComboBox *combo_box);
328 static gboolean gtk_combo_box_list_button_released (GtkWidget *widget,
329 GdkEventButton *event,
331 static gboolean gtk_combo_box_list_key_press (GtkWidget *widget,
334 static gboolean gtk_combo_box_list_enter_notify (GtkWidget *widget,
335 GdkEventCrossing *event,
337 static void gtk_combo_box_list_auto_scroll (GtkComboBox *combo,
340 static gboolean gtk_combo_box_list_scroll_timeout (GtkComboBox *combo);
341 static gboolean gtk_combo_box_list_button_pressed (GtkWidget *widget,
342 GdkEventButton *event,
345 static void gtk_combo_box_list_row_changed (GtkTreeModel *model,
349 static void gtk_combo_box_list_popup_resize (GtkComboBox *combo_box);
352 static void gtk_combo_box_menu_setup (GtkComboBox *combo_box,
353 gboolean add_children);
354 static void gtk_combo_box_menu_fill (GtkComboBox *combo_box);
355 static void gtk_combo_box_menu_fill_level (GtkComboBox *combo_box,
358 static void gtk_combo_box_update_title (GtkComboBox *combo_box);
359 static void gtk_combo_box_menu_destroy (GtkComboBox *combo_box);
361 static void gtk_combo_box_relayout_item (GtkComboBox *combo_box,
365 static void gtk_combo_box_relayout (GtkComboBox *combo_box);
367 static gboolean gtk_combo_box_menu_button_press (GtkWidget *widget,
368 GdkEventButton *event,
370 static void gtk_combo_box_menu_item_activate (GtkWidget *item,
372 static void gtk_combo_box_menu_row_inserted (GtkTreeModel *model,
376 static void gtk_combo_box_menu_row_deleted (GtkTreeModel *model,
379 static void gtk_combo_box_menu_rows_reordered (GtkTreeModel *model,
384 static void gtk_combo_box_menu_row_changed (GtkTreeModel *model,
388 static gboolean gtk_combo_box_menu_key_press (GtkWidget *widget,
391 static void gtk_combo_box_menu_popup (GtkComboBox *combo_box,
393 guint32 activate_time);
394 static GtkWidget *gtk_cell_view_menu_item_new (GtkComboBox *combo_box,
399 static void gtk_combo_box_cell_layout_pack_start (GtkCellLayout *layout,
400 GtkCellRenderer *cell,
402 static void gtk_combo_box_cell_layout_pack_end (GtkCellLayout *layout,
403 GtkCellRenderer *cell,
405 static void gtk_combo_box_cell_layout_clear (GtkCellLayout *layout);
406 static void gtk_combo_box_cell_layout_add_attribute (GtkCellLayout *layout,
407 GtkCellRenderer *cell,
408 const gchar *attribute,
410 static void gtk_combo_box_cell_layout_set_cell_data_func (GtkCellLayout *layout,
411 GtkCellRenderer *cell,
412 GtkCellLayoutDataFunc func,
414 GDestroyNotify destroy);
415 static void gtk_combo_box_cell_layout_clear_attributes (GtkCellLayout *layout,
416 GtkCellRenderer *cell);
417 static void gtk_combo_box_cell_layout_reorder (GtkCellLayout *layout,
418 GtkCellRenderer *cell,
420 static gboolean gtk_combo_box_mnemonic_activate (GtkWidget *widget,
421 gboolean group_cycling);
423 static void gtk_combo_box_sync_cells (GtkComboBox *combo_box,
424 GtkCellLayout *cell_layout);
425 static void combo_cell_data_func (GtkCellLayout *cell_layout,
426 GtkCellRenderer *cell,
427 GtkTreeModel *tree_model,
430 static void gtk_combo_box_child_show (GtkWidget *widget,
431 GtkComboBox *combo_box);
432 static void gtk_combo_box_child_hide (GtkWidget *widget,
433 GtkComboBox *combo_box);
436 /* GtkCellEditable method implementations */
437 static void gtk_combo_box_start_editing (GtkCellEditable *cell_editable,
442 gtk_combo_box_get_type (void)
444 static GType combo_box_type = 0;
448 static const GTypeInfo combo_box_info =
450 sizeof (GtkComboBoxClass),
451 NULL, /* base_init */
452 NULL, /* base_finalize */
453 (GClassInitFunc) gtk_combo_box_class_init,
454 NULL, /* class_finalize */
455 NULL, /* class_data */
456 sizeof (GtkComboBox),
458 (GInstanceInitFunc) gtk_combo_box_init
461 static const GInterfaceInfo cell_layout_info =
463 (GInterfaceInitFunc) gtk_combo_box_cell_layout_init,
468 static const GInterfaceInfo cell_editable_info =
470 (GInterfaceInitFunc) gtk_combo_box_cell_editable_init,
475 combo_box_type = g_type_register_static (GTK_TYPE_BIN,
480 g_type_add_interface_static (combo_box_type,
481 GTK_TYPE_CELL_LAYOUT,
485 g_type_add_interface_static (combo_box_type,
486 GTK_TYPE_CELL_EDITABLE,
487 &cell_editable_info);
492 return combo_box_type;
497 gtk_combo_box_class_init (GtkComboBoxClass *klass)
499 GObjectClass *object_class;
500 GtkObjectClass *gtk_object_class;
501 GtkContainerClass *container_class;
502 GtkWidgetClass *widget_class;
504 klass->get_active_text = gtk_combo_box_real_get_active_text;
506 container_class = (GtkContainerClass *)klass;
507 container_class->forall = gtk_combo_box_forall;
508 container_class->add = gtk_combo_box_add;
509 container_class->remove = gtk_combo_box_remove;
511 widget_class = (GtkWidgetClass *)klass;
512 widget_class->size_allocate = gtk_combo_box_size_allocate;
513 widget_class->size_request = gtk_combo_box_size_request;
514 widget_class->expose_event = gtk_combo_box_expose_event;
515 widget_class->scroll_event = gtk_combo_box_scroll_event;
516 widget_class->mnemonic_activate = gtk_combo_box_mnemonic_activate;
517 widget_class->grab_focus = gtk_combo_box_grab_focus;
518 widget_class->style_set = gtk_combo_box_style_set;
519 widget_class->state_changed = gtk_combo_box_state_changed;
521 gtk_object_class = (GtkObjectClass *)klass;
522 gtk_object_class->destroy = gtk_combo_box_destroy;
524 object_class = (GObjectClass *)klass;
525 object_class->finalize = gtk_combo_box_finalize;
526 object_class->set_property = gtk_combo_box_set_property;
527 object_class->get_property = gtk_combo_box_get_property;
529 parent_class = g_type_class_peek_parent (klass);
533 * GtkComboBox::changed:
534 * @widget: the object which received the signal
536 * The changed signal is emitted when the active
537 * item is changed. The can be due to the user selecting
538 * a different item from the list, or due to a
539 * call to gtk_combo_box_set_active_iter().
540 * It will also be emitted while typing into a GtkComboBoxEntry,
541 * as well as when selecting an item from the GtkComboBoxEntry's list.
545 combo_box_signals[CHANGED] =
546 g_signal_new (I_("changed"),
547 G_OBJECT_CLASS_TYPE (klass),
549 G_STRUCT_OFFSET (GtkComboBoxClass, changed),
551 g_cclosure_marshal_VOID__VOID,
558 * The model from which the combo box takes the values shown
563 g_object_class_install_property (object_class,
565 g_param_spec_object ("model",
566 P_("ComboBox model"),
567 P_("The model for the combo box"),
569 GTK_PARAM_READWRITE));
572 * GtkComboBox:wrap-width:
574 * If wrap-width is set to a positive value, the list will be
575 * displayed in multiple columns, the number of columns is
576 * determined by wrap-width.
580 g_object_class_install_property (object_class,
582 g_param_spec_int ("wrap-width",
584 P_("Wrap width for laying out the items in a grid"),
588 GTK_PARAM_READWRITE));
592 * GtkComboBox:row-span-column:
594 * If this is set to a non-negative value, it must be the index of a column
595 * of type %G_TYPE_INT in the model.
597 * The values of that column are used to determine how many rows a value
598 * in the list will span. Therefore, the values in the model column pointed
599 * to by this property must be greater than zero and not larger than wrap-width.
603 g_object_class_install_property (object_class,
604 PROP_ROW_SPAN_COLUMN,
605 g_param_spec_int ("row-span-column",
606 P_("Row span column"),
607 P_("TreeModel column containing the row span values"),
611 GTK_PARAM_READWRITE));
615 * GtkComboBox:column-span-column:
617 * If this is set to a non-negative value, it must be the index of a column
618 * of type %G_TYPE_INT in the model.
620 * The values of that column are used to determine how many columns a value
621 * in the list will span.
625 g_object_class_install_property (object_class,
626 PROP_COLUMN_SPAN_COLUMN,
627 g_param_spec_int ("column-span-column",
628 P_("Column span column"),
629 P_("TreeModel column containing the column span values"),
633 GTK_PARAM_READWRITE));
637 * GtkComboBox:active:
639 * The item which is currently active. If the model is a non-flat treemodel,
640 * and the active item is not an immediate child of the root of the tree,
641 * this property has the value <literal>gtk_tree_path_get_indices (path)[0]</literal>,
642 * where <literal>path</literal> is the #GtkTreePath of the active item.
646 g_object_class_install_property (object_class,
648 g_param_spec_int ("active",
650 P_("The item which is currently active"),
654 GTK_PARAM_READWRITE));
657 * GtkComboBox:add-tearoffs:
659 * The add-tearoffs property controls whether generated menus
660 * have tearoff menu items.
662 * Note that this only affects menu style combo boxes.
666 g_object_class_install_property (object_class,
668 g_param_spec_boolean ("add-tearoffs",
669 P_("Add tearoffs to menus"),
670 P_("Whether dropdowns should have a tearoff menu item"),
672 GTK_PARAM_READWRITE));
675 * GtkComboBox:has-frame:
677 * The has-frame property controls whether a frame
678 * is drawn around the entry.
682 g_object_class_install_property (object_class,
684 g_param_spec_boolean ("has-frame",
686 P_("Whether the combo box draws a frame around the child"),
688 GTK_PARAM_READWRITE));
690 g_object_class_install_property (object_class,
692 g_param_spec_boolean ("focus-on-click",
693 P_("Focus on click"),
694 P_("Whether the combo box grabs focus when it is clicked with the mouse"),
696 GTK_PARAM_READWRITE));
699 * GtkComboBox:tearoff-title:
701 * A title that may be displayed by the window manager
702 * when the popup is torn-off.
706 g_object_class_install_property (object_class,
708 g_param_spec_string ("tearoff-title",
710 P_("A title that may be displayed by the window manager when the popup is torn-off"),
712 GTK_PARAM_READWRITE));
716 * GtkComboBox:popup-shown:
718 * Whether the combo boxes dropdown is popped up.
719 * Note that this property is mainly useful, because
720 * it allows you to connect to notify::popup-shown.
724 g_object_class_install_property (object_class,
726 g_param_spec_boolean ("popup-shown",
728 P_("Whether the combo's dropdown is shown"),
730 GTK_PARAM_READABLE));
732 gtk_widget_class_install_style_property (widget_class,
733 g_param_spec_boolean ("appears-as-list",
734 P_("Appears as list"),
735 P_("Whether dropdowns should look like lists rather than menus"),
737 GTK_PARAM_READABLE));
739 g_type_class_add_private (object_class, sizeof (GtkComboBoxPrivate));
743 gtk_combo_box_cell_layout_init (GtkCellLayoutIface *iface)
745 iface->pack_start = gtk_combo_box_cell_layout_pack_start;
746 iface->pack_end = gtk_combo_box_cell_layout_pack_end;
747 iface->clear = gtk_combo_box_cell_layout_clear;
748 iface->add_attribute = gtk_combo_box_cell_layout_add_attribute;
749 iface->set_cell_data_func = gtk_combo_box_cell_layout_set_cell_data_func;
750 iface->clear_attributes = gtk_combo_box_cell_layout_clear_attributes;
751 iface->reorder = gtk_combo_box_cell_layout_reorder;
755 gtk_combo_box_cell_editable_init (GtkCellEditableIface *iface)
757 iface->start_editing = gtk_combo_box_start_editing;
761 gtk_combo_box_init (GtkComboBox *combo_box)
763 combo_box->priv = GTK_COMBO_BOX_GET_PRIVATE (combo_box);
765 combo_box->priv->cell_view = gtk_cell_view_new ();
766 gtk_widget_set_parent (combo_box->priv->cell_view, GTK_WIDGET (combo_box));
767 GTK_BIN (combo_box)->child = combo_box->priv->cell_view;
768 gtk_widget_show (combo_box->priv->cell_view);
770 combo_box->priv->width = 0;
771 combo_box->priv->wrap_width = 0;
773 combo_box->priv->active_row = NULL;
774 combo_box->priv->col_column = -1;
775 combo_box->priv->row_column = -1;
777 combo_box->priv->popup_shown = FALSE;
778 combo_box->priv->add_tearoffs = FALSE;
779 combo_box->priv->has_frame = TRUE;
780 combo_box->priv->is_cell_renderer = FALSE;
781 combo_box->priv->editing_canceled = FALSE;
782 combo_box->priv->auto_scroll = FALSE;
783 combo_box->priv->focus_on_click = TRUE;
785 gtk_combo_box_check_appearance (combo_box);
789 gtk_combo_box_set_property (GObject *object,
794 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
799 gtk_combo_box_set_model (combo_box, g_value_get_object (value));
802 case PROP_WRAP_WIDTH:
803 gtk_combo_box_set_wrap_width (combo_box, g_value_get_int (value));
806 case PROP_ROW_SPAN_COLUMN:
807 gtk_combo_box_set_row_span_column (combo_box, g_value_get_int (value));
810 case PROP_COLUMN_SPAN_COLUMN:
811 gtk_combo_box_set_column_span_column (combo_box, g_value_get_int (value));
815 gtk_combo_box_set_active (combo_box, g_value_get_int (value));
818 case PROP_ADD_TEAROFFS:
819 gtk_combo_box_set_add_tearoffs (combo_box, g_value_get_boolean (value));
823 combo_box->priv->has_frame = g_value_get_boolean (value);
826 case PROP_FOCUS_ON_CLICK:
827 gtk_combo_box_set_focus_on_click (combo_box,
828 g_value_get_boolean (value));
831 case PROP_TEAROFF_TITLE:
832 gtk_combo_box_set_title (combo_box, g_value_get_string (value));
835 case PROP_POPUP_SHOWN:
836 if (g_value_get_boolean (value))
838 gtk_combo_box_popup (combo_box);
842 gtk_combo_box_popdown (combo_box);
852 gtk_combo_box_get_property (GObject *object,
857 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
862 g_value_set_object (value, combo_box->priv->model);
865 case PROP_WRAP_WIDTH:
866 g_value_set_int (value, combo_box->priv->wrap_width);
869 case PROP_ROW_SPAN_COLUMN:
870 g_value_set_int (value, combo_box->priv->row_column);
873 case PROP_COLUMN_SPAN_COLUMN:
874 g_value_set_int (value, combo_box->priv->col_column);
878 g_value_set_int (value, gtk_combo_box_get_active (combo_box));
881 case PROP_ADD_TEAROFFS:
882 g_value_set_boolean (value, gtk_combo_box_get_add_tearoffs (combo_box));
886 g_value_set_boolean (value, combo_box->priv->has_frame);
889 case PROP_FOCUS_ON_CLICK:
890 g_value_set_boolean (value, combo_box->priv->focus_on_click);
893 case PROP_TEAROFF_TITLE:
894 g_value_set_string (value, gtk_combo_box_get_title (combo_box));
897 case PROP_POPUP_SHOWN:
898 g_value_set_boolean (value, combo_box->priv->popup_shown);
902 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
908 gtk_combo_box_state_changed (GtkWidget *widget,
909 GtkStateType previous)
911 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
913 if (GTK_WIDGET_REALIZED (widget))
915 if (combo_box->priv->tree_view && combo_box->priv->cell_view)
916 gtk_cell_view_set_background_color (GTK_CELL_VIEW (combo_box->priv->cell_view),
917 &widget->style->base[GTK_WIDGET_STATE (widget)]);
920 gtk_widget_queue_draw (widget);
924 gtk_combo_box_button_state_changed (GtkWidget *widget,
925 GtkStateType previous,
928 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
930 if (GTK_WIDGET_REALIZED (widget))
932 if (!combo_box->priv->tree_view && combo_box->priv->cell_view)
934 if ((GTK_WIDGET_STATE (widget) == GTK_STATE_INSENSITIVE) !=
935 (GTK_WIDGET_STATE (combo_box->priv->cell_view) == GTK_STATE_INSENSITIVE))
936 gtk_widget_set_sensitive (combo_box->priv->cell_view, GTK_WIDGET_SENSITIVE (widget));
938 gtk_widget_set_state (combo_box->priv->cell_view,
939 GTK_WIDGET_STATE (widget));
944 gtk_widget_queue_draw (widget);
948 gtk_combo_box_check_appearance (GtkComboBox *combo_box)
950 gboolean appears_as_list;
952 /* if wrap_width > 0, then we are in grid-mode and forced to use
955 if (combo_box->priv->wrap_width)
956 appears_as_list = FALSE;
958 gtk_widget_style_get (GTK_WIDGET (combo_box),
959 "appears-as-list", &appears_as_list,
964 /* Destroy all the menu mode widgets, if they exist. */
965 if (GTK_IS_MENU (combo_box->priv->popup_widget))
966 gtk_combo_box_menu_destroy (combo_box);
968 /* Create the list mode widgets, if they don't already exist. */
969 if (!GTK_IS_TREE_VIEW (combo_box->priv->tree_view))
970 gtk_combo_box_list_setup (combo_box);
974 /* Destroy all the list mode widgets, if they exist. */
975 if (GTK_IS_TREE_VIEW (combo_box->priv->tree_view))
976 gtk_combo_box_list_destroy (combo_box);
978 /* Create the menu mode widgets, if they don't already exist. */
979 if (!GTK_IS_MENU (combo_box->priv->popup_widget))
980 gtk_combo_box_menu_setup (combo_box, TRUE);
985 gtk_combo_box_style_set (GtkWidget *widget,
988 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
990 gtk_combo_box_check_appearance (combo_box);
992 if (combo_box->priv->tree_view && combo_box->priv->cell_view)
993 gtk_cell_view_set_background_color (GTK_CELL_VIEW (combo_box->priv->cell_view),
994 &widget->style->base[GTK_WIDGET_STATE (widget)]);
998 gtk_combo_box_button_toggled (GtkWidget *widget,
1001 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
1003 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
1005 if (!combo_box->priv->popup_in_progress)
1006 gtk_combo_box_popup (combo_box);
1009 gtk_combo_box_popdown (combo_box);
1013 gtk_combo_box_add (GtkContainer *container,
1016 GtkComboBox *combo_box = GTK_COMBO_BOX (container);
1018 if (combo_box->priv->cell_view && combo_box->priv->cell_view->parent)
1020 gtk_widget_unparent (combo_box->priv->cell_view);
1021 GTK_BIN (container)->child = NULL;
1022 gtk_widget_queue_resize (GTK_WIDGET (container));
1025 gtk_widget_set_parent (widget, GTK_WIDGET (container));
1026 GTK_BIN (container)->child = widget;
1028 if (combo_box->priv->cell_view &&
1029 widget != combo_box->priv->cell_view)
1031 /* since the cell_view was unparented, it's gone now */
1032 combo_box->priv->cell_view = NULL;
1034 if (!combo_box->priv->tree_view && combo_box->priv->separator)
1036 gtk_container_remove (GTK_CONTAINER (combo_box->priv->separator->parent),
1037 combo_box->priv->separator);
1038 combo_box->priv->separator = NULL;
1040 gtk_widget_queue_resize (GTK_WIDGET (container));
1042 else if (combo_box->priv->cell_view_frame)
1044 gtk_widget_unparent (combo_box->priv->cell_view_frame);
1045 combo_box->priv->cell_view_frame = NULL;
1046 combo_box->priv->box = NULL;
1052 gtk_combo_box_remove (GtkContainer *container,
1055 GtkComboBox *combo_box = GTK_COMBO_BOX (container);
1057 gboolean appears_as_list;
1059 gtk_widget_unparent (widget);
1060 GTK_BIN (container)->child = NULL;
1062 if (GTK_OBJECT_FLAGS (combo_box) & GTK_IN_DESTRUCTION)
1065 gtk_widget_queue_resize (GTK_WIDGET (container));
1067 if (!combo_box->priv->tree_view)
1068 appears_as_list = FALSE;
1070 appears_as_list = TRUE;
1072 if (appears_as_list)
1073 gtk_combo_box_list_destroy (combo_box);
1074 else if (GTK_IS_MENU (combo_box->priv->popup_widget))
1076 gtk_combo_box_menu_destroy (combo_box);
1077 gtk_menu_detach (GTK_MENU (combo_box->priv->popup_widget));
1078 combo_box->priv->popup_widget = NULL;
1081 if (!combo_box->priv->cell_view)
1083 combo_box->priv->cell_view = gtk_cell_view_new ();
1084 gtk_widget_set_parent (combo_box->priv->cell_view, GTK_WIDGET (container));
1085 GTK_BIN (container)->child = combo_box->priv->cell_view;
1087 gtk_widget_show (combo_box->priv->cell_view);
1088 gtk_cell_view_set_model (GTK_CELL_VIEW (combo_box->priv->cell_view),
1089 combo_box->priv->model);
1090 gtk_combo_box_sync_cells (combo_box, GTK_CELL_LAYOUT (combo_box->priv->cell_view));
1094 if (appears_as_list)
1095 gtk_combo_box_list_setup (combo_box);
1097 gtk_combo_box_menu_setup (combo_box, TRUE);
1099 if (gtk_tree_row_reference_valid (combo_box->priv->active_row))
1101 path = gtk_tree_row_reference_get_path (combo_box->priv->active_row);
1102 gtk_combo_box_set_active_internal (combo_box, path);
1103 gtk_tree_path_free (path);
1106 gtk_combo_box_set_active_internal (combo_box, NULL);
1109 static ComboCellInfo *
1110 gtk_combo_box_get_cell_info (GtkComboBox *combo_box,
1111 GtkCellRenderer *cell)
1115 for (i = combo_box->priv->cells; i; i = i->next)
1117 ComboCellInfo *info = (ComboCellInfo *)i->data;
1119 if (info && info->cell == cell)
1127 gtk_combo_box_menu_show (GtkWidget *menu,
1130 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
1132 gtk_combo_box_child_show (menu, user_data);
1134 combo_box->priv->popup_in_progress = TRUE;
1135 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
1137 combo_box->priv->popup_in_progress = FALSE;
1141 gtk_combo_box_menu_hide (GtkWidget *menu,
1144 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
1146 gtk_combo_box_child_hide(menu,user_data);
1148 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
1153 gtk_combo_box_detacher (GtkWidget *widget,
1156 GtkComboBox *combo_box;
1158 g_return_if_fail (GTK_IS_COMBO_BOX (widget));
1160 combo_box = GTK_COMBO_BOX (widget);
1161 g_return_if_fail (combo_box->priv->popup_widget == (GtkWidget*) menu);
1163 g_signal_handlers_disconnect_by_func (menu->toplevel,
1164 gtk_combo_box_menu_show,
1166 g_signal_handlers_disconnect_by_func (menu->toplevel,
1167 gtk_combo_box_menu_hide,
1170 combo_box->priv->popup_widget = NULL;
1174 gtk_combo_box_set_popup_widget (GtkComboBox *combo_box,
1177 if (GTK_IS_MENU (combo_box->priv->popup_widget))
1179 gtk_menu_detach (GTK_MENU (combo_box->priv->popup_widget));
1180 combo_box->priv->popup_widget = NULL;
1182 else if (combo_box->priv->popup_widget)
1184 gtk_container_remove (GTK_CONTAINER (combo_box->priv->popup_frame),
1185 combo_box->priv->popup_widget);
1186 g_object_unref (combo_box->priv->popup_widget);
1187 combo_box->priv->popup_widget = NULL;
1190 if (GTK_IS_MENU (popup))
1192 if (combo_box->priv->popup_window)
1194 gtk_widget_destroy (combo_box->priv->popup_window);
1195 combo_box->priv->popup_window = NULL;
1196 combo_box->priv->popup_frame = NULL;
1199 combo_box->priv->popup_widget = popup;
1202 * Note that we connect to show/hide on the toplevel, not the
1203 * menu itself, since the menu is not shown/hidden when it is
1204 * popped up while torn-off.
1206 g_signal_connect (GTK_MENU (popup)->toplevel, "show",
1207 G_CALLBACK (gtk_combo_box_menu_show), combo_box);
1208 g_signal_connect (GTK_MENU (popup)->toplevel, "hide",
1209 G_CALLBACK (gtk_combo_box_menu_hide), combo_box);
1211 gtk_menu_attach_to_widget (GTK_MENU (popup),
1212 GTK_WIDGET (combo_box),
1213 gtk_combo_box_detacher);
1217 if (!combo_box->priv->popup_window)
1219 GtkWidget *toplevel;
1221 combo_box->priv->popup_window = gtk_window_new (GTK_WINDOW_POPUP);
1223 g_signal_connect (GTK_WINDOW(combo_box->priv->popup_window),"show",
1224 G_CALLBACK (gtk_combo_box_child_show),
1226 g_signal_connect (GTK_WINDOW(combo_box->priv->popup_window),"hide",
1227 G_CALLBACK (gtk_combo_box_child_hide),
1230 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (combo_box));
1231 if (GTK_IS_WINDOW (toplevel))
1232 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
1233 GTK_WINDOW (combo_box->priv->popup_window));
1235 gtk_window_set_resizable (GTK_WINDOW (combo_box->priv->popup_window), FALSE);
1236 gtk_window_set_screen (GTK_WINDOW (combo_box->priv->popup_window),
1237 gtk_widget_get_screen (GTK_WIDGET (combo_box)));
1239 combo_box->priv->popup_frame = gtk_frame_new (NULL);
1240 gtk_frame_set_shadow_type (GTK_FRAME (combo_box->priv->popup_frame),
1241 GTK_SHADOW_ETCHED_IN);
1242 gtk_container_add (GTK_CONTAINER (combo_box->priv->popup_window),
1243 combo_box->priv->popup_frame);
1245 gtk_widget_show (combo_box->priv->popup_frame);
1247 combo_box->priv->scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1249 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (combo_box->priv->scrolled_window),
1252 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (combo_box->priv->scrolled_window),
1255 gtk_widget_show (combo_box->priv->scrolled_window);
1257 gtk_container_add (GTK_CONTAINER (combo_box->priv->popup_frame),
1258 combo_box->priv->scrolled_window);
1261 gtk_container_add (GTK_CONTAINER (combo_box->priv->scrolled_window),
1264 gtk_widget_show (popup);
1265 g_object_ref (popup);
1266 combo_box->priv->popup_widget = popup;
1271 gtk_combo_box_menu_position_below (GtkMenu *menu,
1277 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
1283 GdkRectangle monitor;
1285 /* FIXME: is using the size request here broken? */
1286 child = GTK_BIN (combo_box)->child;
1288 gdk_window_get_origin (child->window, &sx, &sy);
1290 if (GTK_WIDGET_NO_WINDOW (child))
1292 sx += child->allocation.x;
1293 sy += child->allocation.y;
1296 gtk_widget_size_request (GTK_WIDGET (menu), &req);
1298 if (gtk_widget_get_direction (GTK_WIDGET (combo_box)) == GTK_TEXT_DIR_LTR)
1301 *x = sx + child->allocation.width - req.width;
1304 screen = gtk_widget_get_screen (GTK_WIDGET (combo_box));
1305 monitor_num = gdk_screen_get_monitor_at_window (screen,
1306 GTK_WIDGET (combo_box)->window);
1307 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
1311 else if (*x + req.width > monitor.x + monitor.width)
1312 *x = monitor.x + monitor.width - req.width;
1314 if (monitor.y + monitor.height - *y - child->allocation.height >= req.height)
1315 *y += child->allocation.height;
1316 else if (*y - monitor.y >= req.height)
1318 else if (monitor.y + monitor.height - *y - child->allocation.height > *y - monitor.y)
1319 *y += child->allocation.height;
1327 gtk_combo_box_menu_position_over (GtkMenu *menu,
1333 GtkComboBox *combo_box;
1337 GtkRequisition requisition;
1344 g_return_if_fail (GTK_IS_COMBO_BOX (user_data));
1346 combo_box = GTK_COMBO_BOX (user_data);
1347 widget = GTK_WIDGET (combo_box);
1349 gtk_widget_get_child_requisition (GTK_WIDGET (menu), &requisition);
1350 menu_width = requisition.width;
1352 active = gtk_menu_get_active (GTK_MENU (combo_box->priv->popup_widget));
1353 gdk_window_get_origin (widget->window, &menu_xpos, &menu_ypos);
1355 menu_xpos += widget->allocation.x;
1356 menu_ypos += widget->allocation.y + widget->allocation.height / 2 - 2;
1360 gtk_widget_get_child_requisition (active, &requisition);
1361 menu_ypos -= requisition.height / 2;
1364 children = GTK_MENU_SHELL (combo_box->priv->popup_widget)->children;
1367 child = children->data;
1369 if (active == child)
1372 if (GTK_WIDGET_VISIBLE (child))
1374 gtk_widget_get_child_requisition (child, &requisition);
1375 menu_ypos -= requisition.height;
1378 children = children->next;
1381 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1382 menu_xpos = menu_xpos + widget->allocation.width - menu_width;
1384 /* Clamp the position on screen */
1385 screen_width = gdk_screen_get_width (gtk_widget_get_screen (widget));
1389 else if ((menu_xpos + menu_width) > screen_width)
1390 menu_xpos -= ((menu_xpos + menu_width) - screen_width);
1399 gtk_combo_box_menu_position (GtkMenu *menu,
1405 GtkComboBox *combo_box;
1406 GtkWidget *menu_item;
1408 combo_box = GTK_COMBO_BOX (user_data);
1410 if (combo_box->priv->wrap_width > 0 || combo_box->priv->cell_view == NULL)
1411 gtk_combo_box_menu_position_below (menu, x, y, push_in, user_data);
1414 /* FIXME handle nested menus better */
1415 menu_item = gtk_menu_get_active (GTK_MENU (combo_box->priv->popup_widget));
1417 gtk_menu_shell_select_item (GTK_MENU_SHELL (combo_box->priv->popup_widget),
1420 gtk_combo_box_menu_position_over (menu, x, y, push_in, user_data);
1426 gtk_combo_box_list_position (GtkComboBox *combo_box,
1435 GdkRectangle monitor;
1436 GtkRequisition popup_req;
1437 GtkPolicyType hpolicy, vpolicy;
1439 sample = GTK_BIN (combo_box)->child;
1441 gdk_window_get_origin (sample->window, x, y);
1443 if (GTK_WIDGET_NO_WINDOW (sample))
1445 *x += sample->allocation.x;
1446 *y += sample->allocation.y;
1449 *width = sample->allocation.width;
1451 if (combo_box->priv->cell_view_frame && combo_box->priv->has_frame)
1453 *x -= GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
1454 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->xthickness;
1455 *width += 2 * (GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
1456 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->xthickness);
1459 hpolicy = vpolicy = GTK_POLICY_NEVER;
1460 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (combo_box->priv->scrolled_window),
1462 gtk_widget_size_request (combo_box->priv->popup_frame, &popup_req);
1464 if (popup_req.width > *width)
1466 hpolicy = GTK_POLICY_ALWAYS;
1467 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (combo_box->priv->scrolled_window),
1469 gtk_widget_size_request (combo_box->priv->popup_frame, &popup_req);
1472 *height = popup_req.height;
1474 screen = gtk_widget_get_screen (GTK_WIDGET (combo_box));
1475 monitor_num = gdk_screen_get_monitor_at_window (screen,
1476 GTK_WIDGET (combo_box)->window);
1477 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
1481 else if (*x + *width > monitor.x + monitor.width)
1482 *x = monitor.x + monitor.width - *width;
1484 if (*y + sample->allocation.height + *height <= monitor.y + monitor.height)
1485 *y += sample->allocation.height;
1486 else if (*y - *height >= monitor.y)
1488 else if (monitor.y + monitor.height - (*y + sample->allocation.height) > *y - monitor.y)
1490 *y += sample->allocation.height;
1491 *height = monitor.y + monitor.height - *y;
1495 *height = *y - monitor.y;
1499 if (popup_req.height > *height)
1501 vpolicy = GTK_POLICY_ALWAYS;
1503 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (combo_box->priv->scrolled_window),
1509 cell_view_is_sensitive (GtkCellView *cell_view)
1511 GList *cells, *list;
1514 cells = gtk_cell_view_get_cell_renderers (cell_view);
1520 g_object_get (list->data, "sensitive", &sensitive, NULL);
1527 g_list_free (cells);
1533 tree_column_row_is_sensitive (GtkComboBox *combo_box,
1536 GList *cells, *list;
1539 if (!combo_box->priv->column)
1542 if (combo_box->priv->row_separator_func)
1544 if ((*combo_box->priv->row_separator_func) (combo_box->priv->model, iter,
1545 combo_box->priv->row_separator_data))
1549 gtk_tree_view_column_cell_set_cell_data (combo_box->priv->column,
1550 combo_box->priv->model,
1551 iter, FALSE, FALSE);
1553 cells = gtk_tree_view_column_get_cell_renderers (combo_box->priv->column);
1559 g_object_get (list->data, "sensitive", &sensitive, NULL);
1566 g_list_free (cells);
1572 update_menu_sensitivity (GtkComboBox *combo_box,
1575 GList *children, *child;
1576 GtkWidget *item, *submenu, *separator;
1577 GtkWidget *cell_view;
1580 if (!combo_box->priv->model)
1583 children = gtk_container_get_children (GTK_CONTAINER (menu));
1585 for (child = children; child; child = child->next)
1587 item = GTK_WIDGET (child->data);
1588 cell_view = GTK_BIN (item)->child;
1590 if (!GTK_IS_CELL_VIEW (cell_view))
1593 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (item));
1594 if (submenu != NULL)
1596 gtk_widget_set_sensitive (item, TRUE);
1597 update_menu_sensitivity (combo_box, submenu);
1601 sensitive = cell_view_is_sensitive (GTK_CELL_VIEW (cell_view));
1603 if (menu != combo_box->priv->popup_widget && child == children)
1605 separator = GTK_WIDGET (child->next->data);
1606 g_object_set (item, "visible", sensitive, NULL);
1607 g_object_set (separator, "visible", sensitive, NULL);
1610 gtk_widget_set_sensitive (item, sensitive);
1614 g_list_free (children);
1618 gtk_combo_box_menu_popup (GtkComboBox *combo_box,
1620 guint32 activate_time)
1624 GtkRequisition requisition;
1627 update_menu_sensitivity (combo_box, combo_box->priv->popup_widget);
1630 if (gtk_tree_row_reference_valid (combo_box->priv->active_row))
1632 path = gtk_tree_row_reference_get_path (combo_box->priv->active_row);
1633 active_item = gtk_tree_path_get_indices (path)[0];
1634 gtk_tree_path_free (path);
1636 if (combo_box->priv->add_tearoffs)
1640 /* FIXME handle nested menus better */
1641 gtk_menu_set_active (GTK_MENU (combo_box->priv->popup_widget), active_item);
1643 if (combo_box->priv->wrap_width == 0)
1645 width = GTK_WIDGET (combo_box)->allocation.width;
1646 gtk_widget_set_size_request (combo_box->priv->popup_widget, -1, -1);
1647 gtk_widget_size_request (combo_box->priv->popup_widget, &requisition);
1649 gtk_widget_set_size_request (combo_box->priv->popup_widget,
1650 MAX (width, requisition.width), -1);
1653 gtk_menu_popup (GTK_MENU (combo_box->priv->popup_widget),
1655 gtk_combo_box_menu_position, combo_box,
1656 button, activate_time);
1660 popup_grab_on_window (GdkWindow *window,
1661 guint32 activate_time,
1662 gboolean grab_keyboard)
1664 if ((gdk_pointer_grab (window, TRUE,
1665 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
1666 GDK_POINTER_MOTION_MASK,
1667 NULL, NULL, activate_time) == 0))
1669 if (!grab_keyboard ||
1670 gdk_keyboard_grab (window, TRUE,
1671 activate_time) == 0)
1675 gdk_display_pointer_ungrab (gdk_drawable_get_display (window),
1685 * gtk_combo_box_popup:
1686 * @combo_box: a #GtkComboBox
1688 * Pops up the menu or dropdown list of @combo_box.
1690 * This function is mostly intended for use by accessibility technologies;
1691 * applications should have little use for it.
1696 gtk_combo_box_popup (GtkComboBox *combo_box)
1698 gint x, y, width, height;
1699 GtkTreePath *path, *ppath;
1700 GtkWidget *toplevel;
1702 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
1704 if (!GTK_WIDGET_REALIZED (combo_box))
1707 if (GTK_WIDGET_MAPPED (combo_box->priv->popup_widget))
1710 if (GTK_IS_MENU (combo_box->priv->popup_widget))
1712 gtk_combo_box_menu_popup (combo_box, 0, 0);
1716 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (combo_box));
1717 if (GTK_IS_WINDOW (toplevel))
1718 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
1719 GTK_WINDOW (combo_box->priv->popup_window));
1721 gtk_widget_show_all (combo_box->priv->popup_frame);
1722 gtk_combo_box_list_position (combo_box, &x, &y, &width, &height);
1724 gtk_widget_set_size_request (combo_box->priv->popup_window, width, height);
1725 gtk_window_move (GTK_WINDOW (combo_box->priv->popup_window), x, y);
1727 if (gtk_tree_row_reference_valid (combo_box->priv->active_row))
1729 path = gtk_tree_row_reference_get_path (combo_box->priv->active_row);
1730 ppath = gtk_tree_path_copy (path);
1731 if (gtk_tree_path_up (ppath))
1732 gtk_tree_view_expand_to_path (GTK_TREE_VIEW (combo_box->priv->tree_view),
1734 gtk_tree_view_set_cursor (GTK_TREE_VIEW (combo_box->priv->tree_view),
1736 gtk_tree_path_free (path);
1737 gtk_tree_path_free (ppath);
1739 gtk_tree_view_set_hover_expand (GTK_TREE_VIEW (combo_box->priv->tree_view),
1743 gtk_widget_show (combo_box->priv->popup_window);
1745 gtk_widget_grab_focus (combo_box->priv->popup_window);
1746 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
1749 if (!GTK_WIDGET_HAS_FOCUS (combo_box->priv->tree_view))
1750 gtk_widget_grab_focus (combo_box->priv->tree_view);
1752 if (!popup_grab_on_window (combo_box->priv->popup_window->window,
1753 GDK_CURRENT_TIME, TRUE))
1755 gtk_widget_hide (combo_box->priv->popup_window);
1759 gtk_grab_add (combo_box->priv->popup_window);
1763 * gtk_combo_box_popdown:
1764 * @combo_box: a #GtkComboBox
1766 * Hides the menu or dropdown list of @combo_box.
1768 * This function is mostly intended for use by accessibility technologies;
1769 * applications should have little use for it.
1774 gtk_combo_box_popdown (GtkComboBox *combo_box)
1776 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
1778 if (GTK_IS_MENU (combo_box->priv->popup_widget))
1780 gtk_menu_popdown (GTK_MENU (combo_box->priv->popup_widget));
1784 if (!GTK_WIDGET_REALIZED (GTK_WIDGET (combo_box)))
1787 gtk_grab_remove (combo_box->priv->popup_window);
1788 gtk_widget_hide_all (combo_box->priv->popup_window);
1789 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
1794 gtk_combo_box_calc_requested_width (GtkComboBox *combo_box,
1800 if (combo_box->priv->cell_view)
1801 gtk_widget_style_get (combo_box->priv->cell_view,
1802 "focus-line-width", &padding,
1807 /* add some pixels for good measure */
1808 padding += BONUS_PADDING;
1810 if (combo_box->priv->cell_view)
1811 gtk_cell_view_get_size_of_row (GTK_CELL_VIEW (combo_box->priv->cell_view),
1816 return req.width + padding;
1820 gtk_combo_box_remeasure (GtkComboBox *combo_box)
1825 if (!combo_box->priv->model ||
1826 !gtk_tree_model_get_iter_first (combo_box->priv->model, &iter))
1829 combo_box->priv->width = 0;
1831 path = gtk_tree_path_new_from_indices (0, -1);
1837 if (combo_box->priv->cell_view)
1838 gtk_cell_view_get_size_of_row (GTK_CELL_VIEW (combo_box->priv->cell_view),
1843 combo_box->priv->width = MAX (combo_box->priv->width, req.width);
1845 gtk_tree_path_next (path);
1847 while (gtk_tree_model_iter_next (combo_box->priv->model, &iter));
1849 gtk_tree_path_free (path);
1853 gtk_combo_box_size_request (GtkWidget *widget,
1854 GtkRequisition *requisition)
1857 gint focus_width, focus_pad;
1858 GtkRequisition bin_req;
1860 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
1863 gtk_widget_size_request (GTK_BIN (widget)->child, &bin_req);
1864 gtk_combo_box_remeasure (combo_box);
1865 bin_req.width = MAX (bin_req.width, combo_box->priv->width);
1867 gtk_widget_style_get (GTK_WIDGET (widget),
1868 "focus-line-width", &focus_width,
1869 "focus-padding", &focus_pad,
1872 if (!combo_box->priv->tree_view)
1876 if (combo_box->priv->cell_view)
1878 GtkRequisition button_req, sep_req, arrow_req;
1879 gint border_width, xthickness, ythickness;
1881 gtk_widget_size_request (combo_box->priv->button, &button_req);
1882 border_width = GTK_CONTAINER (combo_box)->border_width;
1883 xthickness = combo_box->priv->button->style->xthickness;
1884 ythickness = combo_box->priv->button->style->ythickness;
1886 bin_req.width = MAX (bin_req.width, combo_box->priv->width);
1888 gtk_widget_size_request (combo_box->priv->separator, &sep_req);
1889 gtk_widget_size_request (combo_box->priv->arrow, &arrow_req);
1891 height = MAX (sep_req.height, arrow_req.height);
1892 height = MAX (height, bin_req.height);
1894 width = bin_req.width + sep_req.width + arrow_req.width;
1896 height += 2*(border_width + ythickness + focus_width + focus_pad);
1897 width += 2*(border_width + xthickness + focus_width + focus_pad);
1899 requisition->width = width;
1900 requisition->height = height;
1904 GtkRequisition but_req;
1906 gtk_widget_size_request (combo_box->priv->button, &but_req);
1908 requisition->width = bin_req.width + but_req.width;
1909 requisition->height = MAX (bin_req.height, but_req.height);
1915 GtkRequisition button_req, frame_req;
1917 /* sample + frame */
1918 *requisition = bin_req;
1920 requisition->width += 2 * focus_width;
1922 if (combo_box->priv->cell_view_frame)
1924 gtk_widget_size_request (combo_box->priv->cell_view_frame, &frame_req);
1925 if (combo_box->priv->has_frame)
1927 requisition->width += 2 *
1928 (GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
1929 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->xthickness);
1930 requisition->height += 2 *
1931 (GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
1932 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->ythickness);
1937 gtk_widget_size_request (combo_box->priv->button, &button_req);
1939 requisition->height = MAX (requisition->height, button_req.height);
1940 requisition->width += button_req.width;
1945 gtk_combo_box_size_allocate (GtkWidget *widget,
1946 GtkAllocation *allocation)
1948 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
1949 gint focus_width, focus_pad;
1950 GtkAllocation child;
1952 gboolean is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
1954 widget->allocation = *allocation;
1956 gtk_widget_style_get (GTK_WIDGET (widget),
1957 "focus-line-width", &focus_width,
1958 "focus-padding", &focus_pad,
1961 if (!combo_box->priv->tree_view)
1963 if (combo_box->priv->cell_view)
1965 gint border_width, xthickness, ythickness;
1969 gtk_widget_size_allocate (combo_box->priv->button, allocation);
1971 /* set some things ready */
1972 border_width = GTK_CONTAINER (combo_box->priv->button)->border_width;
1973 xthickness = combo_box->priv->button->style->xthickness;
1974 ythickness = combo_box->priv->button->style->ythickness;
1976 child.x = allocation->x;
1977 child.y = allocation->y;
1978 width = allocation->width;
1979 child.height = allocation->height;
1981 if (!combo_box->priv->is_cell_renderer)
1983 child.x += border_width + xthickness + focus_width + focus_pad;
1984 child.y += border_width + ythickness + focus_width + focus_pad;
1985 width -= 2 * (child.x - allocation->x);
1986 child.height -= 2 * (child.y - allocation->y);
1990 /* handle the children */
1991 gtk_widget_size_request (combo_box->priv->arrow, &req);
1992 child.width = req.width;
1994 child.x += width - req.width;
1995 child.width = MAX (1, child.width);
1996 child.height = MAX (1, child.height);
1997 gtk_widget_size_allocate (combo_box->priv->arrow, &child);
1999 child.x += req.width;
2000 gtk_widget_size_request (combo_box->priv->separator, &req);
2001 child.width = req.width;
2003 child.x -= req.width;
2004 child.width = MAX (1, child.width);
2005 child.height = MAX (1, child.height);
2006 gtk_widget_size_allocate (combo_box->priv->separator, &child);
2010 child.x += req.width;
2011 child.width = allocation->x + allocation->width
2012 - (border_width + xthickness + focus_width + focus_pad)
2017 child.width = child.x;
2018 child.x = allocation->x
2019 + border_width + xthickness + focus_width + focus_pad;
2020 child.width -= child.x;
2023 child.width = MAX (1, child.width);
2024 child.height = MAX (1, child.height);
2025 gtk_widget_size_allocate (GTK_BIN (widget)->child, &child);
2029 gtk_widget_size_request (combo_box->priv->button, &req);
2031 child.x = allocation->x;
2033 child.x = allocation->x + allocation->width - req.width;
2034 child.y = allocation->y;
2035 child.width = req.width;
2036 child.height = allocation->height;
2037 child.width = MAX (1, child.width);
2038 child.height = MAX (1, child.height);
2039 gtk_widget_size_allocate (combo_box->priv->button, &child);
2042 child.x = allocation->x + req.width;
2044 child.x = allocation->x;
2045 child.y = allocation->y;
2046 child.width = allocation->width - req.width;
2047 child.width = MAX (1, child.width);
2048 child.height = MAX (1, child.height);
2049 gtk_widget_size_allocate (GTK_BIN (widget)->child, &child);
2057 gtk_widget_size_request (combo_box->priv->button, &req);
2059 child.x = allocation->x;
2061 child.x = allocation->x + allocation->width - req.width;
2062 child.y = allocation->y;
2063 child.width = req.width;
2064 child.height = allocation->height;
2065 child.width = MAX (1, child.width);
2066 child.height = MAX (1, child.height);
2067 gtk_widget_size_allocate (combo_box->priv->button, &child);
2071 child.x = allocation->x + req.width;
2073 child.x = allocation->x;
2074 child.y = allocation->y;
2075 child.width = allocation->width - req.width;
2076 child.height = allocation->height;
2078 if (combo_box->priv->cell_view_frame)
2080 child.width = MAX (1, child.width);
2081 child.height = MAX (1, child.height);
2082 gtk_widget_size_allocate (combo_box->priv->cell_view_frame, &child);
2085 if (combo_box->priv->has_frame)
2088 GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
2089 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->xthickness;
2091 GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
2092 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->ythickness;
2093 child.width -= 2 * (
2094 GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
2095 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->xthickness);
2096 child.height -= 2 * (
2097 GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
2098 GTK_WIDGET (combo_box->priv->cell_view_frame)->style->ythickness);
2102 child.width = MAX (1, child.width);
2103 child.height = MAX (1, child.height);
2104 gtk_widget_size_allocate (GTK_BIN (combo_box)->child, &child);
2109 gtk_combo_box_unset_model (GtkComboBox *combo_box)
2111 if (combo_box->priv->model)
2113 g_signal_handler_disconnect (combo_box->priv->model,
2114 combo_box->priv->inserted_id);
2115 g_signal_handler_disconnect (combo_box->priv->model,
2116 combo_box->priv->deleted_id);
2117 g_signal_handler_disconnect (combo_box->priv->model,
2118 combo_box->priv->reordered_id);
2119 g_signal_handler_disconnect (combo_box->priv->model,
2120 combo_box->priv->changed_id);
2124 if (!combo_box->priv->tree_view)
2126 if (combo_box->priv->popup_widget)
2127 gtk_container_foreach (GTK_CONTAINER (combo_box->priv->popup_widget),
2128 (GtkCallback)gtk_widget_destroy, NULL);
2131 if (combo_box->priv->model)
2133 g_object_unref (combo_box->priv->model);
2134 combo_box->priv->model = NULL;
2137 if (combo_box->priv->active_row)
2139 gtk_tree_row_reference_free (combo_box->priv->active_row);
2140 combo_box->priv->active_row = NULL;
2143 if (combo_box->priv->cell_view)
2144 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (combo_box->priv->cell_view), NULL);
2148 gtk_combo_box_forall (GtkContainer *container,
2149 gboolean include_internals,
2150 GtkCallback callback,
2151 gpointer callback_data)
2153 GtkComboBox *combo_box = GTK_COMBO_BOX (container);
2155 if (include_internals)
2157 if (combo_box->priv->button)
2158 (* callback) (combo_box->priv->button, callback_data);
2159 if (combo_box->priv->cell_view_frame)
2160 (* callback) (combo_box->priv->cell_view_frame, callback_data);
2163 if (GTK_BIN (container)->child)
2164 (* callback) (GTK_BIN (container)->child, callback_data);
2168 gtk_combo_box_child_show (GtkWidget *widget,
2169 GtkComboBox *combo_box)
2171 GtkComboBoxPrivate *priv = combo_box->priv;
2173 priv->popup_shown = TRUE;
2174 g_object_notify (G_OBJECT (combo_box), "popup-shown");
2178 gtk_combo_box_child_hide (GtkWidget *widget,
2179 GtkComboBox *combo_box)
2181 GtkComboBoxPrivate *priv = combo_box->priv;
2183 priv->popup_shown = FALSE;
2184 g_object_notify (G_OBJECT (combo_box), "popup-shown");
2188 gtk_combo_box_expose_event (GtkWidget *widget,
2189 GdkEventExpose *event)
2191 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
2193 if (!combo_box->priv->tree_view)
2195 gtk_container_propagate_expose (GTK_CONTAINER (widget),
2196 combo_box->priv->button, event);
2200 gtk_container_propagate_expose (GTK_CONTAINER (widget),
2201 combo_box->priv->button, event);
2203 if (combo_box->priv->cell_view_frame)
2204 gtk_container_propagate_expose (GTK_CONTAINER (widget),
2205 combo_box->priv->cell_view_frame, event);
2208 gtk_container_propagate_expose (GTK_CONTAINER (widget),
2209 GTK_BIN (widget)->child, event);
2224 path_visible (GtkTreeView *view,
2230 /* Note that we rely on the fact that collapsed rows don't have nodes
2232 return _gtk_tree_view_find_node (view, path, &tree, &node);
2236 tree_next_func (GtkTreeModel *model,
2241 SearchData *search_data = (SearchData *)data;
2243 if (search_data->found)
2245 if (!tree_column_row_is_sensitive (search_data->combo, iter))
2248 if (search_data->visible &&
2249 !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
2252 search_data->set = TRUE;
2253 search_data->iter = *iter;
2258 if (gtk_tree_path_compare (path, search_data->path) == 0)
2259 search_data->found = TRUE;
2265 tree_next (GtkComboBox *combo,
2266 GtkTreeModel *model,
2271 SearchData search_data;
2273 search_data.combo = combo;
2274 search_data.path = gtk_tree_model_get_path (model, iter);
2275 search_data.visible = visible;
2276 search_data.found = FALSE;
2277 search_data.set = FALSE;
2279 gtk_tree_model_foreach (model, tree_next_func, &search_data);
2281 *next = search_data.iter;
2283 gtk_tree_path_free (search_data.path);
2285 return search_data.set;
2289 tree_prev_func (GtkTreeModel *model,
2294 SearchData *search_data = (SearchData *)data;
2296 if (gtk_tree_path_compare (path, search_data->path) == 0)
2298 search_data->found = TRUE;
2302 if (!tree_column_row_is_sensitive (search_data->combo, iter))
2305 if (search_data->visible &&
2306 !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
2309 search_data->set = TRUE;
2310 search_data->iter = *iter;
2316 tree_prev (GtkComboBox *combo,
2317 GtkTreeModel *model,
2322 SearchData search_data;
2324 search_data.combo = combo;
2325 search_data.path = gtk_tree_model_get_path (model, iter);
2326 search_data.visible = visible;
2327 search_data.found = FALSE;
2328 search_data.set = FALSE;
2330 gtk_tree_model_foreach (model, tree_prev_func, &search_data);
2332 *prev = search_data.iter;
2334 gtk_tree_path_free (search_data.path);
2336 return search_data.set;
2340 tree_last_func (GtkTreeModel *model,
2345 SearchData *search_data = (SearchData *)data;
2347 if (!tree_column_row_is_sensitive (search_data->combo, iter))
2350 /* Note that we rely on the fact that collapsed rows don't have nodes
2352 if (search_data->visible &&
2353 !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
2356 search_data->set = TRUE;
2357 search_data->iter = *iter;
2363 tree_last (GtkComboBox *combo,
2364 GtkTreeModel *model,
2368 SearchData search_data;
2370 search_data.combo = combo;
2371 search_data.visible = visible;
2372 search_data.set = FALSE;
2374 gtk_tree_model_foreach (model, tree_last_func, &search_data);
2376 *last = search_data.iter;
2378 return search_data.set;
2383 tree_first_func (GtkTreeModel *model,
2388 SearchData *search_data = (SearchData *)data;
2390 if (!tree_column_row_is_sensitive (search_data->combo, iter))
2393 if (search_data->visible &&
2394 !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
2397 search_data->set = TRUE;
2398 search_data->iter = *iter;
2404 tree_first (GtkComboBox *combo,
2405 GtkTreeModel *model,
2409 SearchData search_data;
2411 search_data.combo = combo;
2412 search_data.visible = visible;
2413 search_data.set = FALSE;
2415 gtk_tree_model_foreach (model, tree_first_func, &search_data);
2417 *first = search_data.iter;
2419 return search_data.set;
2423 gtk_combo_box_scroll_event (GtkWidget *widget,
2424 GdkEventScroll *event)
2426 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
2429 GtkTreeIter new_iter;
2431 if (!gtk_combo_box_get_active_iter (combo_box, &iter))
2434 if (event->direction == GDK_SCROLL_UP)
2435 found = tree_prev (combo_box, combo_box->priv->model,
2436 &iter, &new_iter, FALSE);
2438 found = tree_next (combo_box, combo_box->priv->model,
2439 &iter, &new_iter, FALSE);
2442 gtk_combo_box_set_active_iter (combo_box, &new_iter);
2452 gtk_combo_box_sync_cells (GtkComboBox *combo_box,
2453 GtkCellLayout *cell_layout)
2457 for (k = combo_box->priv->cells; k; k = k->next)
2460 ComboCellInfo *info = (ComboCellInfo *)k->data;
2462 if (info->pack == GTK_PACK_START)
2463 gtk_cell_layout_pack_start (cell_layout,
2464 info->cell, info->expand);
2465 else if (info->pack == GTK_PACK_END)
2466 gtk_cell_layout_pack_end (cell_layout,
2467 info->cell, info->expand);
2469 gtk_cell_layout_set_cell_data_func (cell_layout,
2471 combo_cell_data_func, info, NULL);
2473 for (j = info->attributes; j; j = j->next->next)
2475 gtk_cell_layout_add_attribute (cell_layout,
2478 GPOINTER_TO_INT (j->next->data));
2484 gtk_combo_box_menu_setup (GtkComboBox *combo_box,
2485 gboolean add_children)
2489 if (combo_box->priv->cell_view)
2491 combo_box->priv->button = gtk_toggle_button_new ();
2492 gtk_button_set_focus_on_click (GTK_BUTTON (combo_box->priv->button),
2493 combo_box->priv->focus_on_click);
2495 g_signal_connect (combo_box->priv->button, "toggled",
2496 G_CALLBACK (gtk_combo_box_button_toggled), combo_box);
2497 g_signal_connect_after (combo_box->priv->button,
2499 G_CALLBACK (gtk_combo_box_key_press), combo_box);
2500 gtk_widget_set_parent (combo_box->priv->button,
2501 GTK_BIN (combo_box)->child->parent);
2503 combo_box->priv->box = gtk_hbox_new (FALSE, 0);
2504 gtk_container_add (GTK_CONTAINER (combo_box->priv->button),
2505 combo_box->priv->box);
2507 combo_box->priv->separator = gtk_vseparator_new ();
2508 gtk_container_add (GTK_CONTAINER (combo_box->priv->box),
2509 combo_box->priv->separator);
2511 combo_box->priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
2512 gtk_container_add (GTK_CONTAINER (combo_box->priv->box),
2513 combo_box->priv->arrow);
2515 gtk_widget_show_all (combo_box->priv->button);
2519 combo_box->priv->button = gtk_toggle_button_new ();
2520 gtk_button_set_focus_on_click (GTK_BUTTON (combo_box->priv->button),
2521 combo_box->priv->focus_on_click);
2523 g_signal_connect (combo_box->priv->button, "toggled",
2524 G_CALLBACK (gtk_combo_box_button_toggled), combo_box);
2525 g_signal_connect_after (combo_box, "key_press_event",
2526 G_CALLBACK (gtk_combo_box_key_press), combo_box);
2527 gtk_widget_set_parent (combo_box->priv->button,
2528 GTK_BIN (combo_box)->child->parent);
2530 combo_box->priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
2531 gtk_container_add (GTK_CONTAINER (combo_box->priv->button),
2532 combo_box->priv->arrow);
2533 gtk_widget_show_all (combo_box->priv->button);
2536 g_signal_connect (combo_box->priv->button, "button_press_event",
2537 G_CALLBACK (gtk_combo_box_menu_button_press),
2539 g_signal_connect (combo_box->priv->button, "state_changed",
2540 G_CALLBACK (gtk_combo_box_button_state_changed),
2543 /* create our funky menu */
2544 menu = gtk_menu_new ();
2545 g_signal_connect (menu, "key_press_event",
2546 G_CALLBACK (gtk_combo_box_menu_key_press), combo_box);
2547 gtk_combo_box_set_popup_widget (combo_box, menu);
2551 gtk_combo_box_menu_fill (combo_box);
2553 /* the column is needed in tree_column_row_is_sensitive() */
2554 combo_box->priv->column = gtk_tree_view_column_new ();
2555 g_object_ref_sink (combo_box->priv->column);
2556 gtk_combo_box_sync_cells (combo_box,
2557 GTK_CELL_LAYOUT (combo_box->priv->column));
2559 gtk_combo_box_update_title (combo_box);
2563 gtk_combo_box_menu_fill (GtkComboBox *combo_box)
2567 if (!combo_box->priv->model)
2570 menu = combo_box->priv->popup_widget;
2572 if (combo_box->priv->add_tearoffs)
2574 GtkWidget *tearoff = gtk_tearoff_menu_item_new ();
2576 gtk_widget_show (tearoff);
2578 if (combo_box->priv->wrap_width)
2579 gtk_menu_attach (GTK_MENU (menu), tearoff,
2580 0, combo_box->priv->wrap_width, 0, 1);
2582 gtk_menu_shell_append (GTK_MENU_SHELL (menu), tearoff);
2585 gtk_combo_box_menu_fill_level (combo_box, menu, NULL);
2589 gtk_cell_view_menu_item_new (GtkComboBox *combo_box,
2590 GtkTreeModel *model,
2593 GtkWidget *cell_view;
2598 cell_view = gtk_cell_view_new ();
2599 gtk_cell_view_set_model (GTK_CELL_VIEW (cell_view), model);
2600 path = gtk_tree_model_get_path (model, iter);
2601 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (cell_view), path);
2602 gtk_tree_path_free (path);
2604 gtk_combo_box_sync_cells (combo_box, GTK_CELL_LAYOUT (cell_view));
2605 gtk_widget_size_request (cell_view, &req);
2606 gtk_widget_show (cell_view);
2608 item = gtk_menu_item_new ();
2609 gtk_container_add (GTK_CONTAINER (item), cell_view);
2615 gtk_combo_box_menu_fill_level (GtkComboBox *combo_box,
2617 GtkTreeIter *parent)
2619 GtkTreeModel *model = combo_box->priv->model;
2620 GtkWidget *item, *submenu, *subitem, *separator;
2622 gboolean is_separator;
2627 n_children = gtk_tree_model_iter_n_children (model, parent);
2630 for (i = 0; i < n_children; i++)
2632 gtk_tree_model_iter_nth_child (model, &iter, parent, i);
2634 if (combo_box->priv->row_separator_func)
2635 is_separator = (*combo_box->priv->row_separator_func) (combo_box->priv->model, &iter,
2636 combo_box->priv->row_separator_data);
2638 is_separator = FALSE;
2642 item = gtk_separator_menu_item_new ();
2643 path = gtk_tree_model_get_path (model, &iter);
2644 g_object_set_data_full (G_OBJECT (item),
2645 I_("gtk-combo-box-item-path"),
2646 gtk_tree_row_reference_new (model, path),
2647 (GDestroyNotify)gtk_tree_row_reference_free);
2648 gtk_tree_path_free (path);
2652 item = gtk_cell_view_menu_item_new (combo_box, model, &iter);
2653 if (gtk_tree_model_iter_has_child (model, &iter))
2655 submenu = gtk_menu_new ();
2656 gtk_widget_show (submenu);
2657 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
2659 /* Ugly - since menus can only activate leafs, we have to
2660 * duplicate the item inside the submenu.
2662 subitem = gtk_cell_view_menu_item_new (combo_box, model, &iter);
2663 separator = gtk_separator_menu_item_new ();
2664 gtk_widget_show (subitem);
2665 gtk_widget_show (separator);
2666 g_signal_connect (subitem, "activate",
2667 G_CALLBACK (gtk_combo_box_menu_item_activate),
2669 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), subitem);
2670 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), separator);
2672 gtk_combo_box_menu_fill_level (combo_box, submenu, &iter);
2675 g_signal_connect (item, "activate",
2676 G_CALLBACK (gtk_combo_box_menu_item_activate),
2680 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
2681 if (combo_box->priv->wrap_width && menu == combo_box->priv->popup_widget)
2682 gtk_combo_box_relayout_item (combo_box, item, &iter, last);
2683 gtk_widget_show (item);
2690 gtk_combo_box_menu_destroy (GtkComboBox *combo_box)
2692 g_signal_handlers_disconnect_matched (combo_box->priv->button,
2693 G_SIGNAL_MATCH_DATA,
2695 gtk_combo_box_menu_button_press, NULL);
2696 g_signal_handlers_disconnect_matched (combo_box->priv->button,
2697 G_SIGNAL_MATCH_DATA,
2699 gtk_combo_box_button_state_changed, combo_box);
2701 /* unparent will remove our latest ref */
2702 gtk_widget_unparent (combo_box->priv->button);
2704 combo_box->priv->box = NULL;
2705 combo_box->priv->button = NULL;
2706 combo_box->priv->arrow = NULL;
2707 combo_box->priv->separator = NULL;
2709 g_object_unref (combo_box->priv->column);
2710 combo_box->priv->column = NULL;
2712 /* changing the popup window will unref the menu and the children */
2720 menu_occupied (GtkMenu *menu,
2724 guint bottom_attach)
2728 for (i = GTK_MENU_SHELL (menu)->children; i; i = i->next)
2732 gtk_container_child_get (GTK_CONTAINER (menu),
2736 "bottom-attach", &b,
2740 /* look if this item intersects with the given coordinates */
2741 if (right_attach > l && left_attach < r && bottom_attach > t && top_attach < b)
2749 gtk_combo_box_relayout_item (GtkComboBox *combo_box,
2754 gint current_col = 0, current_row = 0;
2755 gint rows = 1, cols = 1;
2756 GtkWidget *menu = combo_box->priv->popup_widget;
2758 if (!GTK_IS_MENU_SHELL (menu))
2761 if (combo_box->priv->col_column == -1 &&
2762 combo_box->priv->row_column == -1 &&
2765 gtk_container_child_get (GTK_CONTAINER (menu),
2767 "right_attach", ¤t_col,
2768 "top_attach", ¤t_row,
2770 if (current_col + cols > combo_box->priv->wrap_width)
2778 if (combo_box->priv->col_column != -1)
2779 gtk_tree_model_get (combo_box->priv->model, iter,
2780 combo_box->priv->col_column, &cols,
2782 if (combo_box->priv->row_column != -1)
2783 gtk_tree_model_get (combo_box->priv->model, iter,
2784 combo_box->priv->row_column, &rows,
2789 if (current_col + cols > combo_box->priv->wrap_width)
2795 if (!menu_occupied (GTK_MENU (menu),
2796 current_col, current_col + cols,
2797 current_row, current_row + rows))
2804 /* set attach props */
2805 gtk_menu_attach (GTK_MENU (menu), item,
2806 current_col, current_col + cols,
2807 current_row, current_row + rows);
2811 gtk_combo_box_relayout (GtkComboBox *combo_box)
2816 menu = combo_box->priv->popup_widget;
2818 /* do nothing unless we are in menu style and realized */
2819 if (combo_box->priv->tree_view || !GTK_IS_MENU_SHELL (menu))
2822 list = gtk_container_get_children (GTK_CONTAINER (menu));
2824 for (j = g_list_last (list); j; j = j->prev)
2825 gtk_container_remove (GTK_CONTAINER (menu), j->data);
2827 gtk_combo_box_menu_fill (combo_box);
2834 gtk_combo_box_menu_button_press (GtkWidget *widget,
2835 GdkEventButton *event,
2838 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2840 if (GTK_IS_MENU (combo_box->priv->popup_widget) &&
2841 event->type == GDK_BUTTON_PRESS && event->button == 1)
2843 if (combo_box->priv->focus_on_click &&
2844 !GTK_WIDGET_HAS_FOCUS (combo_box->priv->button))
2845 gtk_widget_grab_focus (combo_box->priv->button);
2847 gtk_combo_box_menu_popup (combo_box, event->button, event->time);
2856 gtk_combo_box_menu_item_activate (GtkWidget *item,
2859 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2860 GtkWidget *cell_view;
2864 cell_view = GTK_BIN (item)->child;
2866 g_return_if_fail (GTK_IS_CELL_VIEW (cell_view));
2868 path = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (cell_view));
2870 if (gtk_tree_model_get_iter (combo_box->priv->model, &iter, path))
2871 gtk_combo_box_set_active_iter (combo_box, &iter);
2873 gtk_tree_path_free (path);
2875 combo_box->priv->editing_canceled = FALSE;
2879 gtk_combo_box_model_row_inserted (GtkTreeModel *model,
2884 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2886 if (combo_box->priv->tree_view)
2887 gtk_combo_box_list_popup_resize (combo_box);
2889 gtk_combo_box_menu_row_inserted (model, path, iter, user_data);
2893 gtk_combo_box_model_row_deleted (GtkTreeModel *model,
2897 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2899 if (combo_box->priv->cell_view)
2901 if (!gtk_tree_row_reference_valid (combo_box->priv->active_row))
2902 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (combo_box->priv->cell_view), NULL);
2905 if (combo_box->priv->tree_view)
2906 gtk_combo_box_list_popup_resize (combo_box);
2908 gtk_combo_box_menu_row_deleted (model, path, user_data);
2912 gtk_combo_box_model_rows_reordered (GtkTreeModel *model,
2918 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2920 gtk_tree_row_reference_reordered (G_OBJECT (user_data), path, iter, new_order);
2922 if (!combo_box->priv->tree_view)
2923 gtk_combo_box_menu_rows_reordered (model, path, iter, new_order, user_data);
2927 gtk_combo_box_model_row_changed (GtkTreeModel *model,
2932 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2933 GtkTreePath *active_path;
2935 /* FIXME this belongs to GtkCellView */
2936 if (gtk_tree_row_reference_valid (combo_box->priv->active_row))
2938 active_path = gtk_tree_row_reference_get_path (combo_box->priv->active_row);
2939 if (gtk_tree_path_compare (path, active_path) == 0 &&
2940 combo_box->priv->cell_view)
2941 gtk_widget_queue_resize (GTK_WIDGET (combo_box->priv->cell_view));
2942 gtk_tree_path_free (active_path);
2945 if (combo_box->priv->tree_view)
2946 gtk_combo_box_list_row_changed (model, path, iter, user_data);
2948 gtk_combo_box_menu_row_changed (model, path, iter, user_data);
2952 list_popup_resize_idle (gpointer user_data)
2954 GtkComboBox *combo_box;
2955 gint x, y, width, height;
2957 GDK_THREADS_ENTER ();
2959 combo_box = GTK_COMBO_BOX (user_data);
2961 if (combo_box->priv->tree_view &&
2962 GTK_WIDGET_MAPPED (combo_box->priv->popup_window))
2964 gtk_combo_box_list_position (combo_box, &x, &y, &width, &height);
2966 gtk_widget_set_size_request (combo_box->priv->popup_window, width, height);
2967 gtk_window_move (GTK_WINDOW (combo_box->priv->popup_window), x, y);
2970 combo_box->priv->resize_idle_id = 0;
2972 GDK_THREADS_LEAVE ();
2978 gtk_combo_box_list_popup_resize (GtkComboBox *combo_box)
2980 if (!combo_box->priv->resize_idle_id)
2981 combo_box->priv->resize_idle_id =
2982 g_idle_add (list_popup_resize_idle, combo_box);
2986 gtk_combo_box_model_row_expanded (GtkTreeModel *model,
2991 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
2993 gtk_combo_box_list_popup_resize (combo_box);
2998 find_menu_by_path (GtkWidget *menu,
3000 gboolean skip_first)
3005 GtkTreeRowReference *mref;
3009 list = gtk_container_get_children (GTK_CONTAINER (menu));
3012 for (i = list; i; i = i->next)
3014 if (GTK_IS_SEPARATOR_MENU_ITEM (i->data))
3016 mref = g_object_get_data (G_OBJECT (i->data), "gtk-combo-box-item-path");
3019 else if (!gtk_tree_row_reference_valid (mref))
3022 mpath = gtk_tree_row_reference_get_path (mref);
3024 else if (GTK_IS_CELL_VIEW (GTK_BIN (i->data)->child))
3032 mpath = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (GTK_BIN (i->data)->child));
3037 /* this case is necessary, since the row reference of
3038 * the cell view may already be updated after a deletion
3045 if (gtk_tree_path_compare (mpath, path) == 0)
3047 gtk_tree_path_free (mpath);
3051 if (gtk_tree_path_is_ancestor (mpath, path))
3053 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
3054 if (submenu != NULL)
3056 gtk_tree_path_free (mpath);
3057 item = find_menu_by_path (submenu, path, TRUE);
3061 gtk_tree_path_free (mpath);
3071 dump_menu_tree (GtkWidget *menu,
3078 list = gtk_container_get_children (GTK_CONTAINER (menu));
3079 for (i = list; i; i = i->next)
3081 if (GTK_IS_CELL_VIEW (GTK_BIN (i->data)->child))
3083 path = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (GTK_BIN (i->data)->child));
3084 g_print ("%*s%s\n", 2 * level, " ", gtk_tree_path_to_string (path));
3085 gtk_tree_path_free (path);
3087 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
3088 if (submenu != NULL)
3089 dump_menu_tree (submenu, level + 1);
3098 gtk_combo_box_menu_row_inserted (GtkTreeModel *model,
3104 GtkWidget *item, *menu, *separator;
3105 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3109 gboolean is_separator;
3111 if (!combo_box->priv->popup_widget)
3114 depth = gtk_tree_path_get_depth (path);
3115 pos = gtk_tree_path_get_indices (path)[depth - 1];
3118 ppath = gtk_tree_path_copy (path);
3119 gtk_tree_path_up (ppath);
3120 parent = find_menu_by_path (combo_box->priv->popup_widget, ppath, FALSE);
3121 gtk_tree_path_free (ppath);
3123 menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (parent));
3126 menu = gtk_menu_new ();
3127 gtk_widget_show (menu);
3128 gtk_menu_item_set_submenu (GTK_MENU_ITEM (parent), menu);
3130 /* Ugly - since menus can only activate leaves, we have to
3131 * duplicate the item inside the submenu.
3133 gtk_tree_model_iter_parent (model, &piter, iter);
3134 item = gtk_cell_view_menu_item_new (combo_box, model, &piter);
3135 separator = gtk_separator_menu_item_new ();
3136 g_signal_connect (item, "activate",
3137 G_CALLBACK (gtk_combo_box_menu_item_activate),
3139 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
3140 gtk_menu_shell_append (GTK_MENU_SHELL (menu), separator);
3141 if (cell_view_is_sensitive (GTK_CELL_VIEW (GTK_BIN (item)->child)))
3143 gtk_widget_show (item);
3144 gtk_widget_show (separator);
3151 menu = combo_box->priv->popup_widget;
3152 if (combo_box->priv->add_tearoffs)
3156 if (combo_box->priv->row_separator_func)
3157 is_separator = (*combo_box->priv->row_separator_func) (model, iter,
3158 combo_box->priv->row_separator_data);
3160 is_separator = FALSE;
3164 item = gtk_separator_menu_item_new ();
3165 g_object_set_data_full (G_OBJECT (item),
3166 I_("gtk-combo-box-item-path"),
3167 gtk_tree_row_reference_new (model, path),
3168 (GDestroyNotify)gtk_tree_row_reference_free);
3172 item = gtk_cell_view_menu_item_new (combo_box, model, iter);
3174 g_signal_connect (item, "activate",
3175 G_CALLBACK (gtk_combo_box_menu_item_activate),
3179 gtk_widget_show (item);
3180 gtk_menu_shell_insert (GTK_MENU_SHELL (menu), item, pos);
3184 gtk_combo_box_menu_row_deleted (GtkTreeModel *model,
3188 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3192 if (!combo_box->priv->popup_widget)
3195 item = find_menu_by_path (combo_box->priv->popup_widget, path, FALSE);
3196 menu = gtk_widget_get_parent (item);
3197 gtk_container_remove (GTK_CONTAINER (menu), item);
3201 gtk_combo_box_menu_rows_reordered (GtkTreeModel *model,
3207 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3209 gtk_combo_box_relayout (combo_box);
3213 gtk_combo_box_menu_row_changed (GtkTreeModel *model,
3218 GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
3221 gboolean is_separator;
3223 if (!combo_box->priv->popup_widget)
3226 item = find_menu_by_path (combo_box->priv->popup_widget, path, FALSE);
3228 if (combo_box->priv->row_separator_func)
3229 is_separator = (*combo_box->priv->row_separator_func) (model, iter,
3230 combo_box->priv->row_separator_data);
3232 is_separator = FALSE;
3234 if (is_separator != GTK_IS_SEPARATOR_MENU_ITEM (item))
3236 gtk_combo_box_menu_row_deleted (model, path, combo_box);
3237 gtk_combo_box_menu_row_inserted (model, path, iter, combo_box);
3240 if (combo_box->priv->wrap_width
3241 && item->parent == combo_box->priv->popup_widget)
3243 GtkWidget *pitem = NULL;
3246 prev = gtk_tree_path_copy (path);
3248 if (gtk_tree_path_prev (prev))
3249 pitem = find_menu_by_path (combo_box->priv->popup_widget, prev, FALSE);
3251 gtk_tree_path_free (prev);
3253 /* unattach item so gtk_combo_box_relayout_item() won't spuriously
3255 gtk_container_child_set (GTK_CONTAINER (combo_box->priv->popup_widget),
3260 "bottom-attach", -1,
3263 gtk_combo_box_relayout_item (combo_box, item, iter, pitem);
3266 width = gtk_combo_box_calc_requested_width (combo_box, path);
3268 if (width > combo_box->priv->width)
3270 if (combo_box->priv->cell_view)
3272 gtk_widget_set_size_request (combo_box->priv->cell_view, width, -1);
3273 gtk_widget_queue_resize (combo_box->priv->cell_view);
3275 combo_box->priv->width = width;
3284 gtk_combo_box_list_setup (GtkComboBox *combo_box)
3286 GtkTreeSelection *sel;
3288 combo_box->priv->button = gtk_toggle_button_new ();
3289 gtk_widget_set_parent (combo_box->priv->button,
3290 GTK_BIN (combo_box)->child->parent);
3291 g_signal_connect (combo_box->priv->button, "button_press_event",
3292 G_CALLBACK (gtk_combo_box_list_button_pressed), combo_box);
3293 g_signal_connect (combo_box->priv->button, "toggled",
3294 G_CALLBACK (gtk_combo_box_button_toggled), combo_box);
3295 g_signal_connect_after (combo_box, "key_press_event",
3296 G_CALLBACK (gtk_combo_box_key_press), combo_box);
3298 combo_box->priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
3299 gtk_container_add (GTK_CONTAINER (combo_box->priv->button),
3300 combo_box->priv->arrow);
3301 combo_box->priv->separator = NULL;
3302 gtk_widget_show_all (combo_box->priv->button);
3304 if (combo_box->priv->cell_view)
3306 gtk_cell_view_set_background_color (GTK_CELL_VIEW (combo_box->priv->cell_view),
3307 >K_WIDGET (combo_box)->style->base[GTK_WIDGET_STATE (combo_box)]);
3309 combo_box->priv->box = gtk_event_box_new ();
3310 gtk_event_box_set_visible_window (GTK_EVENT_BOX (combo_box->priv->box),
3313 if (combo_box->priv->has_frame)
3315 combo_box->priv->cell_view_frame = gtk_frame_new (NULL);
3316 gtk_frame_set_shadow_type (GTK_FRAME (combo_box->priv->cell_view_frame),
3321 combo_box->priv->cell_view_frame = gtk_event_box_new ();
3322 gtk_event_box_set_visible_window (GTK_EVENT_BOX (combo_box->priv->cell_view_frame),
3326 gtk_widget_set_parent (combo_box->priv->cell_view_frame,
3327 GTK_BIN (combo_box)->child->parent);
3328 gtk_container_add (GTK_CONTAINER (combo_box->priv->cell_view_frame),
3329 combo_box->priv->box);
3330 gtk_widget_show_all (combo_box->priv->cell_view_frame);
3332 g_signal_connect (combo_box->priv->box, "button_press_event",
3333 G_CALLBACK (gtk_combo_box_list_button_pressed),
3337 combo_box->priv->tree_view = gtk_tree_view_new ();
3338 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (combo_box->priv->tree_view));
3339 gtk_tree_selection_set_mode (sel, GTK_SELECTION_BROWSE);
3340 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (combo_box->priv->tree_view),
3342 gtk_tree_view_set_hover_selection (GTK_TREE_VIEW (combo_box->priv->tree_view),
3344 if (combo_box->priv->row_separator_func)
3345 gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (combo_box->priv->tree_view),
3346 combo_box->priv->row_separator_func,
3347 combo_box->priv->row_separator_data,
3349 if (combo_box->priv->model)
3350 gtk_tree_view_set_model (GTK_TREE_VIEW (combo_box->priv->tree_view),
3351 combo_box->priv->model);
3353 combo_box->priv->column = gtk_tree_view_column_new ();
3354 gtk_tree_view_append_column (GTK_TREE_VIEW (combo_box->priv->tree_view),
3355 combo_box->priv->column);
3358 gtk_combo_box_sync_cells (combo_box,
3359 GTK_CELL_LAYOUT (combo_box->priv->column));
3361 if (gtk_tree_row_reference_valid (combo_box->priv->active_row))
3365 path = gtk_tree_row_reference_get_path (combo_box->priv->active_row);
3366 gtk_tree_view_set_cursor (GTK_TREE_VIEW (combo_box->priv->tree_view),
3368 gtk_tree_path_free (path);
3371 /* set sample/popup widgets */
3372 gtk_combo_box_set_popup_widget (combo_box, combo_box->priv->tree_view);
3374 g_signal_connect (combo_box->priv->tree_view, "key_press_event",
3375 G_CALLBACK (gtk_combo_box_list_key_press),
3377 g_signal_connect (combo_box->priv->tree_view, "enter_notify_event",
3378 G_CALLBACK (gtk_combo_box_list_enter_notify),
3380 g_signal_connect (combo_box->priv->tree_view, "row_expanded",
3381 G_CALLBACK (gtk_combo_box_model_row_expanded),
3383 g_signal_connect (combo_box->priv->tree_view, "row_collapsed",
3384 G_CALLBACK (gtk_combo_box_model_row_expanded),
3386 g_signal_connect (combo_box->priv->popup_window, "button_press_event",
3387 G_CALLBACK (gtk_combo_box_list_button_pressed),
3389 g_signal_connect (combo_box->priv->popup_window, "button_release_event",
3390 G_CALLBACK (gtk_combo_box_list_button_released),
3393 gtk_widget_show (combo_box->priv->tree_view);
3397 gtk_combo_box_list_destroy (GtkComboBox *combo_box)
3399 /* disconnect signals */
3400 g_signal_handlers_disconnect_matched (combo_box->priv->tree_view,
3401 G_SIGNAL_MATCH_DATA,
3402 0, 0, NULL, NULL, combo_box);
3403 g_signal_handlers_disconnect_matched (combo_box->priv->button,
3404 G_SIGNAL_MATCH_DATA,
3406 gtk_combo_box_list_button_pressed,
3408 g_signal_handlers_disconnect_matched (combo_box->priv->popup_window,
3409 G_SIGNAL_MATCH_DATA,
3411 gtk_combo_box_list_button_pressed,
3413 g_signal_handlers_disconnect_matched (combo_box->priv->popup_window,
3414 G_SIGNAL_MATCH_DATA,
3416 gtk_combo_box_list_button_released,
3419 g_signal_handlers_disconnect_matched (combo_box->priv->popup_window,
3420 G_SIGNAL_MATCH_DATA,
3422 gtk_combo_box_child_show,
3425 g_signal_handlers_disconnect_matched (combo_box->priv->popup_window,
3426 G_SIGNAL_MATCH_DATA,
3428 gtk_combo_box_child_hide,
3431 if (combo_box->priv->box)
3432 g_signal_handlers_disconnect_matched (combo_box->priv->box,
3433 G_SIGNAL_MATCH_DATA,
3435 gtk_combo_box_list_button_pressed,
3438 /* destroy things (unparent will kill the latest ref from us)
3439 * last unref on button will destroy the arrow
3441 gtk_widget_unparent (combo_box->priv->button);
3442 combo_box->priv->button = NULL;
3443 combo_box->priv->arrow = NULL;
3445 if (combo_box->priv->cell_view)
3447 g_object_set (combo_box->priv->cell_view,
3448 "background-set", FALSE,
3452 if (combo_box->priv->cell_view_frame)
3454 gtk_widget_unparent (combo_box->priv->cell_view_frame);
3455 combo_box->priv->cell_view_frame = NULL;
3456 combo_box->priv->box = NULL;
3459 if (combo_box->priv->scroll_timer)
3461 g_source_remove (combo_box->priv->scroll_timer);
3462 combo_box->priv->scroll_timer = 0;
3465 if (combo_box->priv->resize_idle_id)
3467 g_source_remove (combo_box->priv->resize_idle_id);
3468 combo_box->priv->resize_idle_id = 0;
3471 gtk_widget_destroy (combo_box->priv->tree_view);
3473 combo_box->priv->tree_view = NULL;
3474 combo_box->priv->popup_widget = NULL;
3480 gtk_combo_box_list_button_pressed (GtkWidget *widget,
3481 GdkEventButton *event,
3484 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3486 GtkWidget *ewidget = gtk_get_event_widget ((GdkEvent *)event);
3488 if (ewidget == combo_box->priv->popup_window)
3491 if ((ewidget != combo_box->priv->button && ewidget != combo_box->priv->box) ||
3492 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (combo_box->priv->button)))
3495 if (combo_box->priv->focus_on_click &&
3496 !GTK_WIDGET_HAS_FOCUS (combo_box->priv->button))
3497 gtk_widget_grab_focus (combo_box->priv->button);
3499 gtk_combo_box_popup (combo_box);
3501 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
3504 combo_box->priv->auto_scroll = FALSE;
3505 if (combo_box->priv->scroll_timer == 0)
3506 combo_box->priv->scroll_timer = g_timeout_add (SCROLL_TIME,
3507 (GSourceFunc) gtk_combo_box_list_scroll_timeout,
3510 combo_box->priv->popup_in_progress = TRUE;
3516 gtk_combo_box_list_button_released (GtkWidget *widget,
3517 GdkEventButton *event,
3521 GtkTreePath *path = NULL;
3524 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3526 gboolean popup_in_progress = FALSE;
3528 GtkWidget *ewidget = gtk_get_event_widget ((GdkEvent *)event);
3530 if (combo_box->priv->popup_in_progress)
3532 popup_in_progress = TRUE;
3533 combo_box->priv->popup_in_progress = FALSE;
3536 gtk_tree_view_set_hover_expand (GTK_TREE_VIEW (combo_box->priv->tree_view),
3538 if (combo_box->priv->scroll_timer)
3540 g_source_remove (combo_box->priv->scroll_timer);
3541 combo_box->priv->scroll_timer = 0;
3544 if (ewidget != combo_box->priv->tree_view)
3546 if ((ewidget == combo_box->priv->button ||
3547 ewidget == combo_box->priv->box) &&
3548 !popup_in_progress &&
3549 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (combo_box->priv->button)))
3551 gtk_combo_box_popdown (combo_box);
3555 /* released outside treeview */
3556 if (ewidget != combo_box->priv->button &&
3557 ewidget != combo_box->priv->box)
3559 gtk_combo_box_popdown (combo_box);
3567 /* select something cool */
3568 ret = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (combo_box->priv->tree_view),
3574 return TRUE; /* clicked outside window? */
3576 gtk_tree_model_get_iter (combo_box->priv->model, &iter, path);
3577 gtk_tree_path_free (path);
3579 gtk_combo_box_popdown (combo_box);
3581 if (tree_column_row_is_sensitive (combo_box, &iter))
3582 gtk_combo_box_set_active_iter (combo_box, &iter);
3588 gtk_combo_box_key_press (GtkWidget *widget,
3592 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3593 guint state = event->state & gtk_accelerator_get_default_mod_mask ();
3596 GtkTreeIter new_iter;
3598 if (combo_box->priv->model == NULL)
3601 if ((event->keyval == GDK_Down || event->keyval == GDK_KP_Down) &&
3602 state == GDK_MOD1_MASK)
3604 gtk_combo_box_popup (combo_box);
3612 switch (event->keyval)
3616 if (gtk_combo_box_get_active_iter (combo_box, &iter))
3618 found = tree_next (combo_box, combo_box->priv->model,
3619 &iter, &new_iter, FALSE);
3622 /* else fall through */
3624 case GDK_KP_Page_Up:
3627 found = tree_first (combo_box, combo_box->priv->model, &new_iter, FALSE);
3632 if (gtk_combo_box_get_active_iter (combo_box, &iter))
3634 found = tree_prev (combo_box, combo_box->priv->model,
3635 &iter, &new_iter, FALSE);
3638 /* else fall through */
3640 case GDK_KP_Page_Down:
3643 found = tree_last (combo_box, combo_box->priv->model, &new_iter, FALSE);
3650 gtk_combo_box_set_active_iter (combo_box, &new_iter);
3656 gtk_combo_box_menu_key_press (GtkWidget *widget,
3660 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3661 guint state = event->state & gtk_accelerator_get_default_mod_mask ();
3663 if ((event->keyval == GDK_Up || event->keyval == GDK_KP_Up) &&
3664 state == GDK_MOD1_MASK)
3666 gtk_combo_box_popdown (combo_box);
3675 gtk_combo_box_list_key_press (GtkWidget *widget,
3679 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3681 guint state = event->state & gtk_accelerator_get_default_mod_mask ();
3683 if (event->keyval == GDK_Escape ||
3684 ((event->keyval == GDK_Up || event->keyval == GDK_KP_Up) &&
3685 state == GDK_MOD1_MASK))
3687 gtk_combo_box_popdown (combo_box);
3689 /* reset active item -- this is incredibly lame and ugly */
3690 if (gtk_combo_box_get_active_iter (combo_box, &iter))
3691 gtk_combo_box_set_active_iter (combo_box, &iter);
3696 if (event->keyval == GDK_Return || event->keyval == GDK_KP_Enter ||
3697 event->keyval == GDK_space || event->keyval == GDK_KP_Space)
3700 GtkTreeModel *model = NULL;
3702 gtk_combo_box_popdown (combo_box);
3704 if (combo_box->priv->model)
3706 GtkTreeSelection *sel;
3708 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (combo_box->priv->tree_view));
3710 if (gtk_tree_selection_get_selected (sel, &model, &iter))
3711 gtk_combo_box_set_active_iter (combo_box, &iter);
3721 gtk_combo_box_list_auto_scroll (GtkComboBox *combo_box,
3725 GtkWidget *tree_view = combo_box->priv->tree_view;
3729 adj = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (combo_box->priv->scrolled_window));
3730 if (adj && adj->upper - adj->lower > adj->page_size)
3732 if (x <= tree_view->allocation.x &&
3733 adj->lower < adj->value)
3735 value = adj->value - (tree_view->allocation.x - x + 1);
3736 gtk_adjustment_set_value (adj, CLAMP (value, adj->lower, adj->upper - adj->page_size));
3738 else if (x >= tree_view->allocation.x + tree_view->allocation.width &&
3739 adj->upper - adj->page_size > adj->value)
3741 value = adj->value + (x - tree_view->allocation.x - tree_view->allocation.width + 1);
3742 gtk_adjustment_set_value (adj, CLAMP (value, 0.0, adj->upper - adj->page_size));
3746 adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (combo_box->priv->scrolled_window));
3747 if (adj && adj->upper - adj->lower > adj->page_size)
3749 if (y <= tree_view->allocation.y &&
3750 adj->lower < adj->value)
3752 value = adj->value - (tree_view->allocation.y - y + 1);
3753 gtk_adjustment_set_value (adj, CLAMP (value, adj->lower, adj->upper - adj->page_size));
3755 else if (y >= tree_view->allocation.height &&
3756 adj->upper - adj->page_size > adj->value)
3758 value = adj->value + (y - tree_view->allocation.height + 1);
3759 gtk_adjustment_set_value (adj, CLAMP (value, 0.0, adj->upper - adj->page_size));
3765 gtk_combo_box_list_scroll_timeout (GtkComboBox *combo_box)
3769 GDK_THREADS_ENTER ();
3771 if (combo_box->priv->auto_scroll)
3773 gdk_window_get_pointer (combo_box->priv->tree_view->window,
3775 gtk_combo_box_list_auto_scroll (combo_box, x, y);
3778 GDK_THREADS_LEAVE ();
3784 gtk_combo_box_list_enter_notify (GtkWidget *widget,
3785 GdkEventCrossing *event,
3788 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3790 combo_box->priv->auto_scroll = TRUE;
3797 gtk_combo_box_list_row_changed (GtkTreeModel *model,
3802 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
3805 width = gtk_combo_box_calc_requested_width (combo_box, path);
3807 if (width > combo_box->priv->width)
3809 if (combo_box->priv->cell_view)
3811 gtk_widget_set_size_request (combo_box->priv->cell_view, width, -1);
3812 gtk_widget_queue_resize (combo_box->priv->cell_view);
3814 combo_box->priv->width = width;
3819 * GtkCellLayout implementation
3823 pack_start_recurse (GtkWidget *menu,
3824 GtkCellRenderer *cell,
3830 list = gtk_container_get_children (GTK_CONTAINER (menu));
3831 for (i = list; i; i = i->next)
3833 if (GTK_IS_CELL_LAYOUT (GTK_BIN (i->data)->child))
3834 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (GTK_BIN (i->data)->child),
3837 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
3838 if (submenu != NULL)
3839 pack_start_recurse (submenu, cell, expand);
3846 gtk_combo_box_cell_layout_pack_start (GtkCellLayout *layout,
3847 GtkCellRenderer *cell,
3850 ComboCellInfo *info;
3851 GtkComboBox *combo_box;
3853 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
3854 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
3856 combo_box = GTK_COMBO_BOX (layout);
3858 g_object_ref_sink (cell);
3860 info = g_new0 (ComboCellInfo, 1);
3862 info->expand = expand;
3863 info->pack = GTK_PACK_START;
3865 combo_box->priv->cells = g_slist_append (combo_box->priv->cells, info);
3867 if (combo_box->priv->cell_view)
3868 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box->priv->cell_view),
3871 if (combo_box->priv->column)
3872 gtk_tree_view_column_pack_start (combo_box->priv->column, cell, expand);
3874 if (GTK_IS_MENU (combo_box->priv->popup_widget))
3875 pack_start_recurse (combo_box->priv->popup_widget, cell, expand);
3879 pack_end_recurse (GtkWidget *menu,
3880 GtkCellRenderer *cell,
3886 list = gtk_container_get_children (GTK_CONTAINER (menu));
3887 for (i = list; i; i = i->next)
3889 if (GTK_IS_CELL_LAYOUT (GTK_BIN (i->data)->child))
3890 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (GTK_BIN (i->data)->child),
3893 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
3894 if (submenu != NULL)
3895 pack_end_recurse (submenu, cell, expand);
3902 gtk_combo_box_cell_layout_pack_end (GtkCellLayout *layout,
3903 GtkCellRenderer *cell,
3906 ComboCellInfo *info;
3907 GtkComboBox *combo_box;
3909 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
3910 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
3912 combo_box = GTK_COMBO_BOX (layout);
3914 g_object_ref_sink (cell);
3916 info = g_new0 (ComboCellInfo, 1);
3918 info->expand = expand;
3919 info->pack = GTK_PACK_END;
3921 combo_box->priv->cells = g_slist_append (combo_box->priv->cells, info);
3923 if (combo_box->priv->cell_view)
3924 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (combo_box->priv->cell_view),
3927 if (combo_box->priv->column)
3928 gtk_tree_view_column_pack_end (combo_box->priv->column, cell, expand);
3930 if (GTK_IS_MENU (combo_box->priv->popup_widget))
3931 pack_end_recurse (combo_box->priv->popup_widget, cell, expand);
3935 clear_recurse (GtkWidget *menu)
3940 list = gtk_container_get_children (GTK_CONTAINER (menu));
3941 for (i = list; i; i = i->next)
3943 if (GTK_IS_CELL_LAYOUT (GTK_BIN (i->data)->child))
3944 gtk_cell_layout_clear (GTK_CELL_LAYOUT (GTK_BIN (i->data)->child));
3946 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
3947 if (submenu != NULL)
3948 clear_recurse (submenu);
3955 gtk_combo_box_cell_layout_clear (GtkCellLayout *layout)
3957 GtkComboBox *combo_box;
3960 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
3962 combo_box = GTK_COMBO_BOX (layout);
3964 if (combo_box->priv->cell_view)
3965 gtk_cell_layout_clear (GTK_CELL_LAYOUT (combo_box->priv->cell_view));
3967 if (combo_box->priv->column)
3968 gtk_tree_view_column_clear (combo_box->priv->column);
3970 for (i = combo_box->priv->cells; i; i = i->next)
3972 ComboCellInfo *info = (ComboCellInfo *)i->data;
3974 gtk_combo_box_cell_layout_clear_attributes (layout, info->cell);
3975 g_object_unref (info->cell);
3979 g_slist_free (combo_box->priv->cells);
3980 combo_box->priv->cells = NULL;
3982 if (GTK_IS_MENU (combo_box->priv->popup_widget))
3983 clear_recurse (combo_box->priv->popup_widget);
3987 add_attribute_recurse (GtkWidget *menu,
3988 GtkCellRenderer *cell,
3989 const gchar *attribute,
3995 list = gtk_container_get_children (GTK_CONTAINER (menu));
3996 for (i = list; i; i = i->next)
3998 if (GTK_IS_CELL_LAYOUT (GTK_BIN (i->data)->child))
3999 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (GTK_BIN (i->data)->child),
4000 cell, attribute, column);
4002 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4003 if (submenu != NULL)
4004 add_attribute_recurse (submenu, cell, attribute, column);
4011 gtk_combo_box_cell_layout_add_attribute (GtkCellLayout *layout,
4012 GtkCellRenderer *cell,
4013 const gchar *attribute,
4016 ComboCellInfo *info;
4017 GtkComboBox *combo_box;
4019 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
4020 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4022 combo_box = GTK_COMBO_BOX (layout);
4024 info = gtk_combo_box_get_cell_info (combo_box, cell);
4026 info->attributes = g_slist_prepend (info->attributes,
4027 GINT_TO_POINTER (column));
4028 info->attributes = g_slist_prepend (info->attributes,
4029 g_strdup (attribute));
4031 if (combo_box->priv->cell_view)
4032 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo_box->priv->cell_view),
4033 cell, attribute, column);
4035 if (combo_box->priv->column)
4036 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo_box->priv->column),
4037 cell, attribute, column);
4039 if (GTK_IS_MENU (combo_box->priv->popup_widget))
4040 add_attribute_recurse (combo_box->priv->popup_widget, cell, attribute, column);
4041 gtk_widget_queue_resize (GTK_WIDGET (combo_box));
4045 combo_cell_data_func (GtkCellLayout *cell_layout,
4046 GtkCellRenderer *cell,
4047 GtkTreeModel *tree_model,
4051 ComboCellInfo *info = (ComboCellInfo *)data;
4052 GtkWidget *parent = NULL;
4057 (*info->func) (cell_layout, cell, tree_model, iter, info->func_data);
4059 if (GTK_IS_WIDGET (cell_layout))
4060 parent = gtk_widget_get_parent (GTK_WIDGET (cell_layout));
4062 if (GTK_IS_MENU_ITEM (parent) &&
4063 gtk_menu_item_get_submenu (GTK_MENU_ITEM (parent)))
4064 g_object_set (cell, "sensitive", TRUE, NULL);
4069 set_cell_data_func_recurse (GtkWidget *menu,
4070 GtkCellRenderer *cell,
4071 ComboCellInfo *info)
4075 GtkWidget *cell_view;
4077 list = gtk_container_get_children (GTK_CONTAINER (menu));
4078 for (i = list; i; i = i->next)
4080 cell_view = GTK_BIN (i->data)->child;
4081 if (GTK_IS_CELL_LAYOUT (cell_view))
4083 /* Override sensitivity for inner nodes; we don't
4084 * want menuitems with submenus to appear insensitive
4086 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (cell_view),
4088 combo_cell_data_func,
4090 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4091 if (submenu != NULL)
4092 set_cell_data_func_recurse (submenu, cell, info);
4100 gtk_combo_box_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4101 GtkCellRenderer *cell,
4102 GtkCellLayoutDataFunc func,
4104 GDestroyNotify destroy)
4106 ComboCellInfo *info;
4107 GtkComboBox *combo_box;
4109 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
4111 combo_box = GTK_COMBO_BOX (layout);
4113 info = gtk_combo_box_get_cell_info (combo_box, cell);
4114 g_return_if_fail (info != NULL);
4118 GDestroyNotify d = info->destroy;
4120 info->destroy = NULL;
4121 d (info->func_data);
4125 info->func_data = func_data;
4126 info->destroy = destroy;
4128 if (combo_box->priv->cell_view)
4129 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo_box->priv->cell_view), cell, func, func_data, NULL);
4131 if (combo_box->priv->column)
4132 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo_box->priv->column), cell, func, func_data, NULL);
4134 if (GTK_IS_MENU (combo_box->priv->popup_widget))
4135 set_cell_data_func_recurse (combo_box->priv->popup_widget, cell, info);
4137 gtk_widget_queue_resize (GTK_WIDGET (combo_box));
4141 clear_attributes_recurse (GtkWidget *menu,
4142 GtkCellRenderer *cell)
4147 list = gtk_container_get_children (GTK_CONTAINER (menu));
4148 for (i = list; i; i = i->next)
4150 if (GTK_IS_CELL_LAYOUT (GTK_BIN (i->data)->child))
4151 gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (GTK_BIN (i->data)->child),
4154 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4155 if (submenu != NULL)
4156 clear_attributes_recurse (submenu, cell);
4163 gtk_combo_box_cell_layout_clear_attributes (GtkCellLayout *layout,
4164 GtkCellRenderer *cell)
4166 ComboCellInfo *info;
4167 GtkComboBox *combo_box;
4170 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
4171 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4173 combo_box = GTK_COMBO_BOX (layout);
4175 info = gtk_combo_box_get_cell_info (combo_box, cell);
4176 g_return_if_fail (info != NULL);
4178 list = info->attributes;
4179 while (list && list->next)
4181 g_free (list->data);
4182 list = list->next->next;
4184 g_slist_free (info->attributes);
4185 info->attributes = NULL;
4187 if (combo_box->priv->cell_view)
4188 gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (combo_box->priv->cell_view), cell);
4190 if (combo_box->priv->column)
4191 gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (combo_box->priv->column), cell);
4193 if (GTK_IS_MENU (combo_box->priv->popup_widget))
4194 clear_attributes_recurse (combo_box->priv->popup_widget, cell);
4196 gtk_widget_queue_resize (GTK_WIDGET (combo_box));
4200 reorder_recurse (GtkWidget *menu,
4201 GtkCellRenderer *cell,
4207 list = gtk_container_get_children (GTK_CONTAINER (menu));
4208 for (i = list; i; i = i->next)
4210 if (GTK_IS_CELL_LAYOUT (GTK_BIN (i->data)->child))
4211 gtk_cell_layout_reorder (GTK_CELL_LAYOUT (GTK_BIN (i->data)->child),
4214 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
4215 if (submenu != NULL)
4216 reorder_recurse (submenu, cell, position);
4223 gtk_combo_box_cell_layout_reorder (GtkCellLayout *layout,
4224 GtkCellRenderer *cell,
4227 ComboCellInfo *info;
4228 GtkComboBox *combo_box;
4231 g_return_if_fail (GTK_IS_COMBO_BOX (layout));
4232 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4234 combo_box = GTK_COMBO_BOX (layout);
4236 info = gtk_combo_box_get_cell_info (combo_box, cell);
4238 g_return_if_fail (info != NULL);
4239 g_return_if_fail (position >= 0);
4241 link = g_slist_find (combo_box->priv->cells, info);
4243 g_return_if_fail (link != NULL);
4245 combo_box->priv->cells = g_slist_remove_link (combo_box->priv->cells, link);
4246 combo_box->priv->cells = g_slist_insert (combo_box->priv->cells, info,
4249 if (combo_box->priv->cell_view)
4250 gtk_cell_layout_reorder (GTK_CELL_LAYOUT (combo_box->priv->cell_view),
4253 if (combo_box->priv->column)
4254 gtk_cell_layout_reorder (GTK_CELL_LAYOUT (combo_box->priv->column),
4257 if (GTK_IS_MENU (combo_box->priv->popup_widget))
4258 reorder_recurse (combo_box->priv->popup_widget, cell, position);
4260 gtk_widget_queue_draw (GTK_WIDGET (combo_box));
4268 * gtk_combo_box_new:
4270 * Creates a new empty #GtkComboBox.
4272 * Return value: A new #GtkComboBox.
4277 gtk_combo_box_new (void)
4279 return g_object_new (GTK_TYPE_COMBO_BOX, NULL);
4283 * gtk_combo_box_new_with_model:
4284 * @model: A #GtkTreeModel.
4286 * Creates a new #GtkComboBox with the model initialized to @model.
4288 * Return value: A new #GtkComboBox.
4293 gtk_combo_box_new_with_model (GtkTreeModel *model)
4295 GtkComboBox *combo_box;
4297 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
4299 combo_box = g_object_new (GTK_TYPE_COMBO_BOX, "model", model, NULL);
4301 return GTK_WIDGET (combo_box);
4305 * gtk_combo_box_get_wrap_width:
4306 * @combo_box: A #GtkComboBox.
4308 * Returns the wrap width which is used to determine the number
4309 * of columns for the popup menu. If the wrap width is larger than
4310 * 1, the combo box is in table mode.
4312 * Returns: the wrap width.
4317 gtk_combo_box_get_wrap_width (GtkComboBox *combo_box)
4319 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), -1);
4321 return combo_box->priv->wrap_width;
4325 * gtk_combo_box_set_wrap_width:
4326 * @combo_box: A #GtkComboBox.
4327 * @width: Preferred number of columns.
4329 * Sets the wrap width of @combo_box to be @width. The wrap width is basically
4330 * the preferred number of columns when you want the popup to be layed out
4336 gtk_combo_box_set_wrap_width (GtkComboBox *combo_box,
4339 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4340 g_return_if_fail (width >= 0);
4342 if (width != combo_box->priv->wrap_width)
4344 combo_box->priv->wrap_width = width;
4346 gtk_combo_box_check_appearance (combo_box);
4347 gtk_combo_box_relayout (combo_box);
4349 g_object_notify (G_OBJECT (combo_box), "wrap-width");
4354 * gtk_combo_box_get_row_span_column:
4355 * @combo_box: A #GtkComboBox.
4357 * Returns the column with row span information for @combo_box.
4359 * Returns: the row span column.
4364 gtk_combo_box_get_row_span_column (GtkComboBox *combo_box)
4366 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), -1);
4368 return combo_box->priv->row_column;
4372 * gtk_combo_box_set_row_span_column:
4373 * @combo_box: A #GtkComboBox.
4374 * @row_span: A column in the model passed during construction.
4376 * Sets the column with row span information for @combo_box to be @row_span.
4377 * The row span column contains integers which indicate how many rows
4378 * an item should span.
4383 gtk_combo_box_set_row_span_column (GtkComboBox *combo_box,
4388 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4390 col = gtk_tree_model_get_n_columns (combo_box->priv->model);
4391 g_return_if_fail (row_span >= -1 && row_span < col);
4393 if (row_span != combo_box->priv->row_column)
4395 combo_box->priv->row_column = row_span;
4397 gtk_combo_box_relayout (combo_box);
4399 g_object_notify (G_OBJECT (combo_box), "row-span-column");
4404 * gtk_combo_box_get_column_span_column:
4405 * @combo_box: A #GtkComboBox.
4407 * Returns the column with column span information for @combo_box.
4409 * Returns: the column span column.
4414 gtk_combo_box_get_column_span_column (GtkComboBox *combo_box)
4416 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), -1);
4418 return combo_box->priv->col_column;
4422 * gtk_combo_box_set_column_span_column:
4423 * @combo_box: A #GtkComboBox.
4424 * @column_span: A column in the model passed during construction.
4426 * Sets the column with column span information for @combo_box to be
4427 * @column_span. The column span column contains integers which indicate
4428 * how many columns an item should span.
4433 gtk_combo_box_set_column_span_column (GtkComboBox *combo_box,
4438 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4440 col = gtk_tree_model_get_n_columns (combo_box->priv->model);
4441 g_return_if_fail (column_span >= -1 && column_span < col);
4443 if (column_span != combo_box->priv->col_column)
4445 combo_box->priv->col_column = column_span;
4447 gtk_combo_box_relayout (combo_box);
4449 g_object_notify (G_OBJECT (combo_box), "column-span-column");
4454 * gtk_combo_box_get_active:
4455 * @combo_box: A #GtkComboBox.
4457 * Returns the index of the currently active item, or -1 if there's no
4458 * active item. If the model is a non-flat treemodel, and the active item
4459 * is not an immediate child of the root of the tree, this function returns
4460 * <literal>gtk_tree_path_get_indices (path)[0]</literal>, where
4461 * <literal>path</literal> is the #GtkTreePath of the active item.
4463 * Return value: An integer which is the index of the currently active item, or
4464 * -1 if there's no active item.
4469 gtk_combo_box_get_active (GtkComboBox *combo_box)
4472 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), 0);
4474 if (gtk_tree_row_reference_valid (combo_box->priv->active_row))
4478 path = gtk_tree_row_reference_get_path (combo_box->priv->active_row);
4479 result = gtk_tree_path_get_indices (path)[0];
4480 gtk_tree_path_free (path);
4489 * gtk_combo_box_set_active:
4490 * @combo_box: A #GtkComboBox.
4491 * @index_: An index in the model passed during construction, or -1 to have
4494 * Sets the active item of @combo_box to be the item at @index.
4499 gtk_combo_box_set_active (GtkComboBox *combo_box,
4502 GtkTreePath *path = NULL;
4503 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4504 g_return_if_fail (index_ >= -1);
4507 path = gtk_tree_path_new_from_indices (index_, -1);
4509 gtk_combo_box_set_active_internal (combo_box, path);
4512 gtk_tree_path_free (path);
4516 gtk_combo_box_set_active_internal (GtkComboBox *combo_box,
4519 GtkTreePath *active_path;
4522 if (path && gtk_tree_row_reference_valid (combo_box->priv->active_row))
4524 active_path = gtk_tree_row_reference_get_path (combo_box->priv->active_row);
4525 path_cmp = gtk_tree_path_compare (path, active_path);
4526 gtk_tree_path_free (active_path);
4531 if (combo_box->priv->active_row)
4533 gtk_tree_row_reference_free (combo_box->priv->active_row);
4534 combo_box->priv->active_row = NULL;
4539 if (combo_box->priv->tree_view)
4540 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (combo_box->priv->tree_view)));
4543 GtkMenu *menu = GTK_MENU (combo_box->priv->popup_widget);
4545 if (GTK_IS_MENU (menu))
4546 gtk_menu_set_active (menu, -1);
4549 if (combo_box->priv->cell_view)
4550 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (combo_box->priv->cell_view), NULL);
4554 combo_box->priv->active_row =
4555 gtk_tree_row_reference_new (combo_box->priv->model, path);
4557 if (combo_box->priv->tree_view)
4559 gtk_tree_view_set_cursor (GTK_TREE_VIEW (combo_box->priv->tree_view),
4562 else if (GTK_IS_MENU (combo_box->priv->popup_widget))
4564 /* FIXME handle nested menus better */
4565 gtk_menu_set_active (GTK_MENU (combo_box->priv->popup_widget),
4566 gtk_tree_path_get_indices (path)[0]);
4569 if (combo_box->priv->cell_view)
4570 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (combo_box->priv->cell_view),
4574 g_signal_emit (combo_box, combo_box_signals[CHANGED], 0);
4575 g_object_notify (G_OBJECT (combo_box), "active");
4580 * gtk_combo_box_get_active_iter:
4581 * @combo_box: A #GtkComboBox
4582 * @iter: The uninitialized #GtkTreeIter.
4584 * Sets @iter to point to the current active item, if it exists.
4586 * Return value: %TRUE, if @iter was set
4591 gtk_combo_box_get_active_iter (GtkComboBox *combo_box,
4597 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE);
4599 if (!gtk_tree_row_reference_valid (combo_box->priv->active_row))
4602 path = gtk_tree_row_reference_get_path (combo_box->priv->active_row);
4603 result = gtk_tree_model_get_iter (combo_box->priv->model, iter, path);
4604 gtk_tree_path_free (path);
4610 * gtk_combo_box_set_active_iter:
4611 * @combo_box: A #GtkComboBox
4612 * @iter: The #GtkTreeIter.
4614 * Sets the current active item to be the one referenced by @iter.
4615 * @iter must correspond to a path of depth one.
4620 gtk_combo_box_set_active_iter (GtkComboBox *combo_box,
4625 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4627 path = gtk_tree_model_get_path (gtk_combo_box_get_model (combo_box), iter);
4628 gtk_combo_box_set_active_internal (combo_box, path);
4629 gtk_tree_path_free (path);
4633 * gtk_combo_box_set_model:
4634 * @combo_box: A #GtkComboBox.
4635 * @model: A #GtkTreeModel.
4637 * Sets the model used by @combo_box to be @model. Will unset a previously set
4638 * model (if applicable). If model is %NULL, then it will unset the model.
4640 * Note that this function does not clear the cell renderers, you have to
4641 * call gtk_combo_box_cell_layout_clear() yourself if you need to set up
4642 * different cell renderers for the new model.
4647 gtk_combo_box_set_model (GtkComboBox *combo_box,
4648 GtkTreeModel *model)
4650 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4654 gtk_combo_box_unset_model (combo_box);
4658 g_return_if_fail (GTK_IS_TREE_MODEL (model));
4660 if (model == combo_box->priv->model)
4663 if (combo_box->priv->model)
4664 gtk_combo_box_unset_model (combo_box);
4666 combo_box->priv->model = model;
4667 g_object_ref (combo_box->priv->model);
4669 combo_box->priv->inserted_id =
4670 g_signal_connect (combo_box->priv->model, "row_inserted",
4671 G_CALLBACK (gtk_combo_box_model_row_inserted),
4673 combo_box->priv->deleted_id =
4674 g_signal_connect (combo_box->priv->model, "row_deleted",
4675 G_CALLBACK (gtk_combo_box_model_row_deleted),
4677 combo_box->priv->reordered_id =
4678 g_signal_connect (combo_box->priv->model, "rows_reordered",
4679 G_CALLBACK (gtk_combo_box_model_rows_reordered),
4681 combo_box->priv->changed_id =
4682 g_signal_connect (combo_box->priv->model, "row_changed",
4683 G_CALLBACK (gtk_combo_box_model_row_changed),
4686 if (combo_box->priv->tree_view)
4689 gtk_tree_view_set_model (GTK_TREE_VIEW (combo_box->priv->tree_view),
4690 combo_box->priv->model);
4691 gtk_combo_box_list_popup_resize (combo_box);
4696 if (combo_box->priv->popup_widget)
4697 gtk_combo_box_menu_fill (combo_box);
4701 if (combo_box->priv->cell_view)
4702 gtk_cell_view_set_model (GTK_CELL_VIEW (combo_box->priv->cell_view),
4703 combo_box->priv->model);
4707 * gtk_combo_box_get_model
4708 * @combo_box: A #GtkComboBox.
4710 * Returns the #GtkTreeModel which is acting as data source for @combo_box.
4712 * Return value: A #GtkTreeModel which was passed during construction.
4717 gtk_combo_box_get_model (GtkComboBox *combo_box)
4719 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
4721 return combo_box->priv->model;
4725 /* convenience API for simple text combos */
4728 * gtk_combo_box_new_text:
4730 * Convenience function which constructs a new text combo box, which is a
4731 * #GtkComboBox just displaying strings. If you use this function to create
4732 * a text combo box, you should only manipulate its data source with the
4733 * following convenience functions: gtk_combo_box_append_text(),
4734 * gtk_combo_box_insert_text(), gtk_combo_box_prepend_text() and
4735 * gtk_combo_box_remove_text().
4737 * Return value: A new text combo box.
4742 gtk_combo_box_new_text (void)
4744 GtkWidget *combo_box;
4745 GtkCellRenderer *cell;
4746 GtkListStore *store;
4748 store = gtk_list_store_new (1, G_TYPE_STRING);
4749 combo_box = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));
4750 g_object_unref (store);
4752 cell = gtk_cell_renderer_text_new ();
4753 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), cell, TRUE);
4754 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), cell,
4762 * gtk_combo_box_append_text:
4763 * @combo_box: A #GtkComboBox constructed using gtk_combo_box_new_text().
4766 * Appends @string to the list of strings stored in @combo_box. Note that
4767 * you can only use this function with combo boxes constructed with
4768 * gtk_combo_box_new_text().
4773 gtk_combo_box_append_text (GtkComboBox *combo_box,
4777 GtkListStore *store;
4779 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4780 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
4781 g_return_if_fail (text != NULL);
4783 store = GTK_LIST_STORE (combo_box->priv->model);
4785 gtk_list_store_append (store, &iter);
4786 gtk_list_store_set (store, &iter, 0, text, -1);
4790 * gtk_combo_box_insert_text:
4791 * @combo_box: A #GtkComboBox constructed using gtk_combo_box_new_text().
4792 * @position: An index to insert @text.
4795 * Inserts @string at @position in the list of strings stored in @combo_box.
4796 * Note that you can only use this function with combo boxes constructed
4797 * with gtk_combo_box_new_text().
4802 gtk_combo_box_insert_text (GtkComboBox *combo_box,
4807 GtkListStore *store;
4809 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4810 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
4811 g_return_if_fail (position >= 0);
4812 g_return_if_fail (text != NULL);
4814 store = GTK_LIST_STORE (combo_box->priv->model);
4816 gtk_list_store_insert (store, &iter, position);
4817 gtk_list_store_set (store, &iter, 0, text, -1);
4821 * gtk_combo_box_prepend_text:
4822 * @combo_box: A #GtkComboBox constructed with gtk_combo_box_new_text().
4825 * Prepends @string to the list of strings stored in @combo_box. Note that
4826 * you can only use this function with combo boxes constructed with
4827 * gtk_combo_box_new_text().
4832 gtk_combo_box_prepend_text (GtkComboBox *combo_box,
4836 GtkListStore *store;
4838 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4839 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
4840 g_return_if_fail (text != NULL);
4842 store = GTK_LIST_STORE (combo_box->priv->model);
4844 gtk_list_store_prepend (store, &iter);
4845 gtk_list_store_set (store, &iter, 0, text, -1);
4849 * gtk_combo_box_remove_text:
4850 * @combo_box: A #GtkComboBox constructed with gtk_combo_box_new_text().
4851 * @position: Index of the item to remove.
4853 * Removes the string at @position from @combo_box. Note that you can only use
4854 * this function with combo boxes constructed with gtk_combo_box_new_text().
4859 gtk_combo_box_remove_text (GtkComboBox *combo_box,
4863 GtkListStore *store;
4865 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
4866 g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
4867 g_return_if_fail (position >= 0);
4869 store = GTK_LIST_STORE (combo_box->priv->model);
4871 if (gtk_tree_model_iter_nth_child (combo_box->priv->model, &iter,
4873 gtk_list_store_remove (store, &iter);
4877 * gtk_combo_box_get_active_text:
4878 * @combo_box: A #GtkComboBox constructed with gtk_combo_box_new_text().
4880 * Returns the currently active string in @combo_box or %NULL if none
4881 * is selected. Note that you can only use this function with combo
4882 * boxes constructed with gtk_combo_box_new_text() and with
4883 * #GtkComboBoxEntry<!-- -->s.
4885 * Returns: a newly allocated string containing the currently active text.
4890 gtk_combo_box_get_active_text (GtkComboBox *combo_box)
4892 GtkComboBoxClass *class;
4894 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
4896 class = GTK_COMBO_BOX_GET_CLASS (combo_box);
4898 if (class->get_active_text)
4899 return (* class->get_active_text) (combo_box);
4905 gtk_combo_box_real_get_active_text (GtkComboBox *combo_box)
4910 g_return_val_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model), NULL);
4912 if (gtk_combo_box_get_active_iter (combo_box, &iter))
4913 gtk_tree_model_get (combo_box->priv->model, &iter,
4920 gtk_combo_box_mnemonic_activate (GtkWidget *widget,
4921 gboolean group_cycling)
4923 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
4925 gtk_widget_grab_focus (combo_box->priv->button);
4931 gtk_combo_box_grab_focus (GtkWidget *widget)
4933 GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
4935 gtk_widget_grab_focus (combo_box->priv->button);
4939 gtk_combo_box_destroy (GtkObject *object)
4941 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
4943 if (combo_box->priv->popup_idle_id > 0)
4945 g_source_remove (combo_box->priv->popup_idle_id);
4946 combo_box->priv->popup_idle_id = 0;
4949 gtk_combo_box_popdown (combo_box);
4951 if (combo_box->priv->row_separator_destroy)
4952 (* combo_box->priv->row_separator_destroy) (combo_box->priv->row_separator_data);
4954 combo_box->priv->row_separator_func = NULL;
4955 combo_box->priv->row_separator_data = NULL;
4956 combo_box->priv->row_separator_destroy = NULL;
4958 GTK_OBJECT_CLASS (parent_class)->destroy (object);
4959 combo_box->priv->cell_view = NULL;
4963 gtk_combo_box_finalize (GObject *object)
4965 GtkComboBox *combo_box = GTK_COMBO_BOX (object);
4968 if (GTK_IS_MENU (combo_box->priv->popup_widget))
4970 gtk_combo_box_menu_destroy (combo_box);
4971 gtk_menu_detach (GTK_MENU (combo_box->priv->popup_widget));
4972 combo_box->priv->popup_widget = NULL;
4975 if (GTK_IS_TREE_VIEW (combo_box->priv->tree_view))
4976 gtk_combo_box_list_destroy (combo_box);
4978 if (combo_box->priv->popup_window)
4979 gtk_widget_destroy (combo_box->priv->popup_window);
4981 gtk_combo_box_unset_model (combo_box);
4983 for (i = combo_box->priv->cells; i; i = i->next)
4985 ComboCellInfo *info = (ComboCellInfo *)i->data;
4986 GSList *list = info->attributes;
4989 info->destroy (info->func_data);
4991 while (list && list->next)
4993 g_free (list->data);
4994 list = list->next->next;
4996 g_slist_free (info->attributes);
4998 g_object_unref (info->cell);
5001 g_slist_free (combo_box->priv->cells);
5003 G_OBJECT_CLASS (parent_class)->finalize (object);
5007 gtk_cell_editable_key_press (GtkWidget *widget,
5011 GtkComboBox *combo_box = GTK_COMBO_BOX (data);
5013 if (event->keyval == GDK_Escape)
5015 combo_box->priv->editing_canceled = TRUE;
5017 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (combo_box));
5018 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (combo_box));
5022 else if (event->keyval == GDK_Return)
5024 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (combo_box));
5025 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (combo_box));
5034 popdown_idle (gpointer data)
5036 GtkComboBox *combo_box;
5038 GDK_THREADS_ENTER ();
5040 combo_box = GTK_COMBO_BOX (data);
5042 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (combo_box));
5043 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (combo_box));
5045 g_object_unref (combo_box);
5047 GDK_THREADS_LEAVE ();
5053 popdown_handler (GtkWidget *widget,
5056 g_idle_add (popdown_idle, g_object_ref (data));
5060 popup_idle (gpointer data)
5062 GtkComboBox *combo_box;
5064 GDK_THREADS_ENTER ();
5066 combo_box = GTK_COMBO_BOX (data);
5068 if (GTK_IS_MENU (combo_box->priv->popup_widget) &&
5069 combo_box->priv->cell_view)
5070 g_signal_connect_object (combo_box->priv->popup_widget,
5071 "unmap", G_CALLBACK (popdown_handler),
5074 /* we unset this if a menu item is activated */
5075 combo_box->priv->editing_canceled = TRUE;
5076 gtk_combo_box_popup (combo_box);
5078 combo_box->priv->popup_idle_id = 0;
5080 GDK_THREADS_LEAVE ();
5086 gtk_combo_box_start_editing (GtkCellEditable *cell_editable,
5089 GtkComboBox *combo_box = GTK_COMBO_BOX (cell_editable);
5091 combo_box->priv->is_cell_renderer = TRUE;
5093 if (combo_box->priv->cell_view)
5095 g_signal_connect_object (combo_box->priv->button, "key_press_event",
5096 G_CALLBACK (gtk_cell_editable_key_press),
5099 gtk_widget_grab_focus (combo_box->priv->button);
5103 g_signal_connect_object (GTK_BIN (combo_box)->child, "key_press_event",
5104 G_CALLBACK (gtk_cell_editable_key_press),
5107 gtk_widget_grab_focus (GTK_WIDGET (GTK_BIN (combo_box)->child));
5108 GTK_WIDGET_UNSET_FLAGS (combo_box->priv->button, GTK_CAN_FOCUS);
5111 /* we do the immediate popup only for the optionmenu-like
5114 if (combo_box->priv->is_cell_renderer &&
5115 combo_box->priv->cell_view && !combo_box->priv->tree_view)
5116 combo_box->priv->popup_idle_id = g_idle_add (popup_idle, combo_box);
5121 * gtk_combo_box_get_add_tearoffs:
5122 * @combo_box: a #GtkComboBox
5124 * Gets the current value of the :add-tearoffs property.
5126 * Return value: the current value of the :add-tearoffs property.
5129 gtk_combo_box_get_add_tearoffs (GtkComboBox *combo_box)
5131 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE);
5133 return combo_box->priv->add_tearoffs;
5137 * gtk_combo_box_set_add_tearoffs:
5138 * @combo_box: a #GtkComboBox
5139 * @add_tearoffs: %TRUE to add tearoff menu items
5141 * Sets whether the popup menu should have a tearoff
5147 gtk_combo_box_set_add_tearoffs (GtkComboBox *combo_box,
5148 gboolean add_tearoffs)
5150 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5152 add_tearoffs = add_tearoffs != FALSE;
5154 if (combo_box->priv->add_tearoffs != add_tearoffs)
5156 combo_box->priv->add_tearoffs = add_tearoffs;
5157 gtk_combo_box_check_appearance (combo_box);
5158 gtk_combo_box_relayout (combo_box);
5159 g_object_notify (G_OBJECT (combo_box), "add-tearoffs");
5164 * gtk_combo_box_get_title:
5165 * @combo_box: a #GtkComboBox
5167 * Gets the current title of the menu in tearoff mode. See
5168 * gtk_combo_box_set_add_tearoffs().
5170 * Returns: the menu's title in tearoff mode. This is an internal copy of the
5171 * string which must not be freed.
5175 G_CONST_RETURN gchar*
5176 gtk_combo_box_get_title (GtkComboBox *combo_box)
5178 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
5180 return combo_box->priv->tearoff_title;
5184 gtk_combo_box_update_title (GtkComboBox *combo_box)
5186 gtk_combo_box_check_appearance (combo_box);
5188 if (combo_box->priv->popup_widget &&
5189 GTK_IS_MENU (combo_box->priv->popup_widget))
5190 gtk_menu_set_title (GTK_MENU (combo_box->priv->popup_widget),
5191 combo_box->priv->tearoff_title);
5195 * gtk_combo_box_set_title:
5196 * @combo_box: a #GtkComboBox
5197 * @title: a title for the menu in tearoff mode.
5199 * Sets the menu's title in tearoff mode.
5204 gtk_combo_box_set_title (GtkComboBox *combo_box,
5207 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5209 if (strcmp (title ? title : "",
5210 combo_box->priv->tearoff_title ? combo_box->priv->tearoff_title : "") != 0)
5212 g_free (combo_box->priv->tearoff_title);
5213 combo_box->priv->tearoff_title = g_strdup (title);
5215 gtk_combo_box_update_title (combo_box);
5217 g_object_notify (G_OBJECT (combo_box), "tearoff-title");
5222 _gtk_combo_box_editing_canceled (GtkComboBox *combo_box)
5224 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), TRUE);
5226 return combo_box->priv->editing_canceled;
5230 * gtk_combo_box_get_popup_accessible:
5231 * @combo_box: a #GtkComboBox
5233 * Gets the accessible object corresponding to the combo box's popup.
5235 * This function is mostly intended for use by accessibility technologies;
5236 * applications should have little use for it.
5238 * Returns: the accessible object corresponding to the combo box's popup.
5243 gtk_combo_box_get_popup_accessible (GtkComboBox *combo_box)
5247 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
5249 if (combo_box->priv->popup_widget)
5251 atk_obj = gtk_widget_get_accessible (combo_box->priv->popup_widget);
5259 * gtk_combo_box_get_row_separator_func:
5260 * @combo_box: a #GtkComboBox
5262 * Returns the current row separator function.
5264 * Return value: the current row separator function.
5268 GtkTreeViewRowSeparatorFunc
5269 gtk_combo_box_get_row_separator_func (GtkComboBox *combo_box)
5271 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
5273 return combo_box->priv->row_separator_func;
5277 * gtk_combo_box_set_row_separator_func:
5278 * @combo_box: a #GtkComboBox
5279 * @func: a #GtkTreeViewRowSeparatorFunc
5280 * @data: user data to pass to @func, or %NULL
5281 * @destroy: destroy notifier for @data, or %NULL
5283 * Sets the row separator function, which is used to determine
5284 * whether a row should be drawn as a separator. If the row separator
5285 * function is %NULL, no separators are drawn. This is the default value.
5290 gtk_combo_box_set_row_separator_func (GtkComboBox *combo_box,
5291 GtkTreeViewRowSeparatorFunc func,
5293 GtkDestroyNotify destroy)
5295 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5297 if (combo_box->priv->row_separator_destroy)
5298 (* combo_box->priv->row_separator_destroy) (combo_box->priv->row_separator_data);
5300 combo_box->priv->row_separator_func = func;
5301 combo_box->priv->row_separator_data = data;
5302 combo_box->priv->row_separator_destroy = destroy;
5304 if (combo_box->priv->tree_view)
5305 gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (combo_box->priv->tree_view),
5308 gtk_combo_box_relayout (combo_box);
5310 gtk_widget_queue_draw (GTK_WIDGET (combo_box));
5315 * gtk_combo_box_set_focus_on_click:
5316 * @combo: a #GtkComboBox
5317 * @focus_on_click: whether the combo box grabs focus when clicked
5320 * Sets whether the combo box will grab focus when it is clicked with
5321 * the mouse. Making mouse clicks not grab focus is useful in places
5322 * like toolbars where you don't want the keyboard focus removed from
5323 * the main area of the application.
5328 gtk_combo_box_set_focus_on_click (GtkComboBox *combo_box,
5329 gboolean focus_on_click)
5331 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
5333 focus_on_click = focus_on_click != FALSE;
5335 if (combo_box->priv->focus_on_click != focus_on_click)
5337 combo_box->priv->focus_on_click = focus_on_click;
5339 if (combo_box->priv->button)
5340 gtk_button_set_focus_on_click (GTK_BUTTON (combo_box->priv->button),
5343 g_object_notify (G_OBJECT (combo_box), "focus-on-click");
5348 * gtk_combo_box_get_focus_on_click:
5349 * @combo: a #GtkComboBox
5351 * Returns whether the combo box grabs focus when it is clicked
5352 * with the mouse. See gtk_combo_box_set_focus_on_click().
5354 * Return value: %TRUE if the combo box grabs focus when it is
5355 * clicked with the mouse.
5360 gtk_combo_box_get_focus_on_click (GtkComboBox *combo_box)
5362 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE);
5364 return combo_box->priv->focus_on_click;
5368 #define __GTK_COMBO_BOX_C__
5369 #include "gtkaliasdef.c"