[gtk+/combo-refactor: 47/52] Re-refactored GtkComboBox to not reorder the file.



commit fa9911c74a46f7a20cec60493d07d865fee1944f
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date:   Mon Dec 6 21:30:00 2010 +0900

    Re-refactored GtkComboBox to not reorder the file.
    
    Turns out reordering the file the way I did before put
    me in an unmergable situation, now re-refactored the
    combo and list-mode works again.

 gtk/gtkcombobox.c | 3729 +++++++++++++++++++++++++++--------------------------
 1 files changed, 1927 insertions(+), 1802 deletions(-)
---
diff --git a/gtk/gtkcombobox.c b/gtk/gtkcombobox.c
index 9ed7416..f60ebce 100644
--- a/gtk/gtkcombobox.c
+++ b/gtk/gtkcombobox.c
@@ -19,7 +19,8 @@
 
 #include "config.h"
 #include "gtkcombobox.h"
-
+#include "gtkcellareabox.h"
+#include "gtktreemenu.h"
 #include "gtkarrow.h"
 #include "gtkbindings.h"
 #include "gtkcelllayout.h"
@@ -38,10 +39,7 @@
 #include "gtktreeselection.h"
 #include "gtkvseparator.h"
 #include "gtkwindow.h"
-#include "gtkcellareabox.h"
-#include "gtktreemenu.h"
 #include "gtkprivate.h"
-#include "gtkentryprivate.h"
 
 #include <gdk/gdkkeysyms.h>
 
@@ -53,6 +51,7 @@
 #include "gtkmarshalers.h"
 #include "gtkintl.h"
 
+#include "gtkentryprivate.h"
 #include "gtktreeprivate.h"
 
 
@@ -84,6 +83,78 @@
 
 
 /* WELCOME, to THE house of evil code */
+struct _GtkComboBoxPrivate
+{
+  GtkTreeModel *model;
+
+  GtkCellArea *area;
+
+  gint col_column;
+  gint row_column;
+
+  gint wrap_width;
+  GtkShadowType shadow_type;
+
+  gint active; /* Only temporary */
+  GtkTreeRowReference *active_row;
+
+  GtkWidget *tree_view;
+  GtkTreeViewColumn *column;
+
+  GtkWidget *cell_view;
+  GtkWidget *cell_view_frame;
+
+  GtkWidget *button;
+  GtkWidget *box;
+  GtkWidget *arrow;
+  GtkWidget *separator;
+
+  GtkWidget *popup_widget;
+  GtkWidget *popup_window;
+  GtkWidget *scrolled_window;
+
+  gulong inserted_id;
+  gulong deleted_id;
+  gulong reordered_id;
+  gulong changed_id;
+  guint popup_idle_id;
+  guint activate_button;
+  guint32 activate_time;
+  guint scroll_timer;
+  guint resize_idle_id;
+
+  gint  minimum_width;
+  gint  natural_width;
+
+  /* For "has-entry" specific behavior we track
+   * an automated cell renderer and text column */
+  gint  text_column;
+  GtkCellRenderer *text_renderer;
+
+  gint id_column;
+
+  guint popup_in_progress : 1;
+  guint popup_shown : 1;
+  guint add_tearoffs : 1;
+  guint has_frame : 1;
+  guint is_cell_renderer : 1;
+  guint editing_canceled : 1;
+  guint auto_scroll : 1;
+  guint focus_on_click : 1;
+  guint button_sensitivity : 2;
+  guint has_entry : 1;
+  guint popup_fixed_width : 1;
+
+  GtkTreeViewRowSeparatorFunc row_separator_func;
+  gpointer                    row_separator_data;
+  GDestroyNotify              row_separator_destroy;
+
+  GdkDevice *grab_pointer;
+  GdkDevice *grab_keyboard;
+
+  gchar *tearoff_title;
+};
+
 /* While debugging this evil code, I have learned that
  * there are actually 4 modes to this widget, which can
  * be characterized as follows
@@ -138,12 +209,52 @@
  * 
  */
 
-/* GObjectClass */
+enum {
+  CHANGED,
+  MOVE_ACTIVE,
+  POPUP,
+  POPDOWN,
+  LAST_SIGNAL
+};
+
+enum {
+  PROP_0,
+  PROP_MODEL,
+  PROP_WRAP_WIDTH,
+  PROP_ROW_SPAN_COLUMN,
+  PROP_COLUMN_SPAN_COLUMN,
+  PROP_ACTIVE,
+  PROP_ADD_TEAROFFS,
+  PROP_TEAROFF_TITLE,
+  PROP_HAS_FRAME,
+  PROP_FOCUS_ON_CLICK,
+  PROP_POPUP_SHOWN,
+  PROP_BUTTON_SENSITIVITY,
+  PROP_EDITING_CANCELED,
+  PROP_HAS_ENTRY,
+  PROP_ENTRY_TEXT_COLUMN,
+  PROP_POPUP_FIXED_WIDTH,
+  PROP_ID_COLUMN,
+  PROP_ACTIVE_ID,
+  PROP_CELL_AREA
+};
+
+static guint combo_box_signals[LAST_SIGNAL] = {0,};
+
+#define BONUS_PADDING 4
+#define SCROLL_TIME  100
+
+/* common */
+
+static void     gtk_combo_box_cell_layout_init     (GtkCellLayoutIface *iface);
+static void     gtk_combo_box_cell_editable_init   (GtkCellEditableIface *iface);
 static GObject *gtk_combo_box_constructor          (GType                  type,
 						    guint                  n_construct_properties,
 						    GObjectConstructParam *construct_properties);
 static void     gtk_combo_box_dispose              (GObject          *object);
 static void     gtk_combo_box_finalize             (GObject          *object);
+static void     gtk_combo_box_destroy              (GtkWidget        *widget);
+
 static void     gtk_combo_box_set_property         (GObject         *object,
                                                     guint            prop_id,
                                                     const GValue    *value,
@@ -153,58 +264,19 @@ static void     gtk_combo_box_get_property         (GObject         *object,
                                                     GValue          *value,
                                                     GParamSpec      *spec);
 
-/* GtkWidgetClass */
-static void     gtk_combo_box_destroy                        (GtkWidget           *widget);
-static void     gtk_combo_box_state_changed                  (GtkWidget           *widget,
-							      GtkStateType         previous);
-static void     gtk_combo_box_grab_focus                     (GtkWidget           *widget);
-static void     gtk_combo_box_style_updated                  (GtkWidget           *widget);
-static void     gtk_combo_box_size_allocate                  (GtkWidget           *widget,
-							      GtkAllocation       *allocation);
-static void     gtk_combo_box_get_preferred_width            (GtkWidget           *widget,
-							      gint                *minimum_size,
-							      gint                *natural_size);
-static void     gtk_combo_box_get_preferred_height           (GtkWidget           *widget,
-							      gint                *minimum_size,
-							      gint                *natural_size);
-static void     gtk_combo_box_get_preferred_width_for_height (GtkWidget           *widget,
-							      gint                 avail_size,
-							      gint                *minimum_size,
-							      gint                *natural_size);
-static void     gtk_combo_box_get_preferred_height_for_width (GtkWidget           *widget,
-							      gint                 avail_size,
-							      gint                *minimum_size,
-							      gint                *natural_size);
-static gboolean gtk_combo_box_draw                           (GtkWidget           *widget,
-							      cairo_t             *cr);
-static gboolean gtk_combo_box_scroll_event                   (GtkWidget           *widget,
-							      GdkEventScroll      *event);
-
-/* GtkContainerClass */
+static void     gtk_combo_box_state_changed        (GtkWidget        *widget,
+			                            GtkStateType      previous);
+static void     gtk_combo_box_grab_focus           (GtkWidget       *widget);
+static void     gtk_combo_box_style_updated        (GtkWidget       *widget);
+static void     gtk_combo_box_button_toggled       (GtkWidget       *widget,
+                                                    gpointer         data);
+static void     gtk_combo_box_button_state_flags_changed (GtkWidget     *widget,
+                                                          GtkStateFlags  previous,
+                                                          gpointer       data);
 static void     gtk_combo_box_add                  (GtkContainer    *container,
                                                     GtkWidget       *widget);
 static void     gtk_combo_box_remove               (GtkContainer    *container,
                                                     GtkWidget       *widget);
-static void     gtk_combo_box_forall               (GtkContainer    *container,
-                                                    gboolean         include_internals,
-                                                    GtkCallback      callback,
-                                                    gpointer         callback_data);
-
-/* GtkComboBoxClass (binding handlers) */
-static void     gtk_combo_box_real_move_active     (GtkComboBox      *combo_box,
-                                                    GtkScrollType     scroll);
-static void     gtk_combo_box_real_popup           (GtkComboBox      *combo_box);
-static gboolean gtk_combo_box_real_popdown         (GtkComboBox      *combo_box);
-
-
-/* GtkTreeModel signals */
-static void     gtk_combo_box_model_row_inserted   (GtkTreeModel     *model,
-						    GtkTreePath      *path,
-						    GtkTreeIter      *iter,
-						    gpointer          user_data);
-static void     gtk_combo_box_model_row_deleted    (GtkTreeModel     *model,
-						    GtkTreePath      *path,
-						    gpointer          user_data);
 
 static void     gtk_combo_box_menu_show            (GtkWidget        *menu,
                                                     gpointer          user_data);
@@ -213,19 +285,60 @@ static void     gtk_combo_box_menu_hide            (GtkWidget        *menu,
 
 static void     gtk_combo_box_set_popup_widget     (GtkComboBox      *combo_box,
                                                     GtkWidget        *popup);
+static void     gtk_combo_box_menu_position_below  (GtkMenu          *menu,
+                                                    gint             *x,
+                                                    gint             *y,
+                                                    gint             *push_in,
+                                                    gpointer          user_data);
+static void     gtk_combo_box_menu_position_over   (GtkMenu          *menu,
+                                                    gint             *x,
+                                                    gint             *y,
+                                                    gint             *push_in,
+                                                    gpointer          user_data);
+static void     gtk_combo_box_menu_position        (GtkMenu          *menu,
+                                                    gint             *x,
+                                                    gint             *y,
+                                                    gint             *push_in,
+                                                    gpointer          user_data);
 
 static void     gtk_combo_box_unset_model          (GtkComboBox      *combo_box);
-static void     gtk_combo_box_button_toggled       (GtkWidget       *widget,
-                                                    gpointer         data);
-static void     gtk_combo_box_button_state_changed (GtkWidget       *widget,
-			                            GtkStateType     previous,
-						    gpointer         data);
 
+static void     gtk_combo_box_size_allocate        (GtkWidget        *widget,
+                                                    GtkAllocation    *allocation);
+static void     gtk_combo_box_forall               (GtkContainer     *container,
+                                                    gboolean          include_internals,
+                                                    GtkCallback       callback,
+                                                    gpointer          callback_data);
+static gboolean gtk_combo_box_draw                 (GtkWidget        *widget,
+                                                    cairo_t          *cr);
+static gboolean gtk_combo_box_scroll_event         (GtkWidget        *widget,
+                                                    GdkEventScroll   *event);
 static void     gtk_combo_box_set_active_internal  (GtkComboBox      *combo_box,
 						    GtkTreePath      *path);
 
 static void     gtk_combo_box_check_appearance     (GtkComboBox      *combo_box);
+static void     gtk_combo_box_real_move_active     (GtkComboBox      *combo_box,
+                                                    GtkScrollType     scroll);
+static void     gtk_combo_box_real_popup           (GtkComboBox      *combo_box);
+static gboolean gtk_combo_box_real_popdown         (GtkComboBox      *combo_box);
 
+/* listening to the model */
+static void     gtk_combo_box_model_row_inserted   (GtkTreeModel     *model,
+						    GtkTreePath      *path,
+						    GtkTreeIter      *iter,
+						    gpointer          user_data);
+static void     gtk_combo_box_model_row_deleted    (GtkTreeModel     *model,
+						    GtkTreePath      *path,
+						    gpointer          user_data);
+static void     gtk_combo_box_model_rows_reordered (GtkTreeModel     *model,
+						    GtkTreePath      *path,
+						    GtkTreeIter      *iter,
+						    gint             *new_order,
+						    gpointer          user_data);
+static void     gtk_combo_box_model_row_changed    (GtkTreeModel     *model,
+						    GtkTreePath      *path,
+						    GtkTreeIter      *iter,
+						    gpointer          data);
 static void     gtk_combo_box_model_row_expanded   (GtkTreeModel     *model,
 						    GtkTreePath      *path,
 						    GtkTreeIter      *iter,
@@ -263,19 +376,26 @@ static gboolean gtk_combo_box_list_select_func     (GtkTreeSelection *selection,
 						    gboolean          path_currently_selected,
 						    gpointer          data);
 
+static void     gtk_combo_box_list_row_changed     (GtkTreeModel     *model,
+                                                    GtkTreePath      *path,
+                                                    GtkTreeIter      *iter,
+                                                    gpointer          data);
 static void     gtk_combo_box_list_popup_resize    (GtkComboBox      *combo_box);
 
 /* menu */
 static void     gtk_combo_box_menu_setup           (GtkComboBox      *combo_box,
                                                     gboolean          add_children);
-static void     gtk_combo_box_menu_destroy         (GtkComboBox      *combo_box);
 static void     gtk_combo_box_update_title         (GtkComboBox      *combo_box);
+static void     gtk_combo_box_menu_destroy         (GtkComboBox      *combo_box);
+
+
 static gboolean gtk_combo_box_menu_button_press    (GtkWidget        *widget,
                                                     GdkEventButton   *event,
                                                     gpointer          user_data);
 static void     gtk_combo_box_menu_activate        (GtkWidget        *menu,
 						    const gchar      *path,
 						    GtkComboBox      *combo_box);
+static void     gtk_combo_box_update_sensitivity   (GtkComboBox      *combo_box);
 static gboolean gtk_combo_box_menu_key_press       (GtkWidget        *widget,
 						    GdkEventKey      *event,
 						    gpointer          data);
@@ -283,21 +403,8 @@ static void     gtk_combo_box_menu_popup           (GtkComboBox      *combo_box,
 						    guint             button, 
 						    guint32           activate_time);
 
-static void     gtk_combo_box_menu_position_below  (GtkMenu          *menu,
-                                                    gint             *x,
-                                                    gint             *y,
-                                                    gint             *push_in,
-                                                    gpointer          user_data);
-static void     gtk_combo_box_menu_position_over   (GtkMenu          *menu,
-                                                    gint             *x,
-                                                    gint             *y,
-                                                    gint             *push_in,
-                                                    gpointer          user_data);
-static void     gtk_combo_box_menu_position        (GtkMenu          *menu,
-                                                    gint             *x,
-                                                    gint             *y,
-                                                    gint             *push_in,
-                                                    gpointer          user_data);
+/* cell layout */
+GtkCellArea    *gtk_combo_box_cell_layout_get_area (GtkCellLayout    *cell_layout);
 
 static gboolean gtk_combo_box_mnemonic_activate              (GtkWidget    *widget,
 							      gboolean      group_cycling);
@@ -312,7 +419,11 @@ static void     gtk_combo_box_entry_contents_changed         (GtkEntry        *e
 							      gpointer         user_data);
 static void     gtk_combo_box_entry_active_changed           (GtkComboBox     *combo_box,
 							      gpointer         user_data);
-/* GtkBuildableIface */
+
+
+/* GtkBuildable method implementation */
+static GtkBuildableIface *parent_buildable_iface;
+
 static void     gtk_combo_box_buildable_init                 (GtkBuildableIface *iface);
 static gboolean gtk_combo_box_buildable_custom_tag_start     (GtkBuildable  *buildable,
 							      GtkBuilder    *builder,
@@ -329,126 +440,25 @@ static GObject *gtk_combo_box_buildable_get_internal_child   (GtkBuildable *buil
 							      GtkBuilder   *builder,
 							      const gchar  *childname);
 
-/* GtkCellEditable  */
-static void     gtk_combo_box_cell_editable_init             (GtkCellEditableIface *iface);
+
+/* GtkCellEditable method implementations */
 static void     gtk_combo_box_start_editing                  (GtkCellEditable *cell_editable,
 							      GdkEvent        *event);
 
-/* GtkCellLayoutIface */
-static void     gtk_combo_box_cell_layout_init               (GtkCellLayoutIface *iface);
-static GtkCellArea *gtk_combo_box_cell_layout_get_area       (GtkCellLayout         *layout);
-
-
-struct _GtkComboBoxPrivate
-{
-  GtkTreeModel *model;
-
-  /* The cell area shared with the treeview or treemenu */
-  GtkCellArea *area;
-
-  gint col_column;
-  gint row_column;
-  gint id_column;
-
-  gint wrap_width;
-  GtkShadowType shadow_type;
-
-  gint active; /* Only temporary */
-  GtkTreeRowReference *active_row;
-
-
-  /* The cellview displayed on the button */
-  GtkWidget *cell_view;
-  GtkWidget *cell_view_frame;
-
-  /* The treeview & column for list mode */
-  GtkWidget         *tree_view;
-  GtkTreeViewColumn *column;
-
-  GtkWidget *button;
-  GtkWidget *box;
-  GtkWidget *arrow;
-  GtkWidget *separator;
-
-  GtkWidget *popup_widget;
-  GtkWidget *popup_window;
-  GtkWidget *scrolled_window;
-
-  gulong     inserted_id;
-  gulong     deleted_id;
-  guint      popup_idle_id;
-  guint      activate_button;
-  guint32    activate_time;
-  guint      scroll_timer;
-  guint      resize_idle_id;
-
-  /* For "has-entry" specific behavior we track
-   * an automated cell renderer and text column */
-  gint             text_column;
-  GtkCellRenderer *text_renderer;
-
-  guint in_construction : 1;
-  guint popup_in_progress : 1;
-  guint popup_shown : 1;
-  guint add_tearoffs : 1;
-  guint has_frame : 1;
-  guint is_cell_renderer : 1;
-  guint editing_canceled : 1;
-  guint auto_scroll : 1;
-  guint focus_on_click : 1;
-  guint button_sensitivity : 2;
-  guint has_entry : 1;
-  guint popup_fixed_width : 1;
-
-  GtkTreeViewRowSeparatorFunc row_separator_func;
-  gpointer                    row_separator_data;
-  GDestroyNotify              row_separator_destroy;
-
-  GdkDevice *grab_pointer;
-  GdkDevice *grab_keyboard;
-
-  gchar *tearoff_title;
-};
-
-
-enum {
-  CHANGED,
-  MOVE_ACTIVE,
-  POPUP,
-  POPDOWN,
-  LAST_SIGNAL
-};
-
-enum {
-  PROP_0,
-  PROP_MODEL,
-  PROP_WRAP_WIDTH,
-  PROP_ROW_SPAN_COLUMN,
-  PROP_COLUMN_SPAN_COLUMN,
-  PROP_ACTIVE,
-  PROP_ADD_TEAROFFS,
-  PROP_TEAROFF_TITLE,
-  PROP_HAS_FRAME,
-  PROP_FOCUS_ON_CLICK,
-  PROP_POPUP_SHOWN,
-  PROP_BUTTON_SENSITIVITY,
-  PROP_EDITING_CANCELED,
-  PROP_HAS_ENTRY,
-  PROP_ENTRY_TEXT_COLUMN,
-  PROP_POPUP_FIXED_WIDTH,
-  PROP_ID_COLUMN,
-  PROP_ACTIVE_ID,
-  PROP_CELL_AREA
-};
-
-#define BONUS_PADDING 4
-#define SCROLL_TIME  100
-
-static guint combo_box_signals[LAST_SIGNAL] = {0,};
-
-
-/* GtkBuildable method implementation */
-static GtkBuildableIface *parent_buildable_iface;
+static void     gtk_combo_box_get_preferred_width            (GtkWidget           *widget,
+							      gint                *minimum_size,
+							      gint                *natural_size);
+static void     gtk_combo_box_get_preferred_height           (GtkWidget           *widget,
+							      gint                *minimum_size,
+							      gint                *natural_size);
+static void     gtk_combo_box_get_preferred_width_for_height (GtkWidget             *widget,
+							      gint                   avail_size,
+							      gint                  *minimum_size,
+							      gint                  *natural_size);
+static void     gtk_combo_box_get_preferred_height_for_width (GtkWidget             *widget,
+							      gint                   avail_size,
+							      gint                  *minimum_size,
+							      gint                  *natural_size);
 
 
 G_DEFINE_TYPE_WITH_CODE (GtkComboBox, gtk_combo_box, GTK_TYPE_BIN,
@@ -469,31 +479,31 @@ gtk_combo_box_class_init (GtkComboBoxClass *klass)
   GtkWidgetClass *widget_class;
   GtkBindingSet *binding_set;
 
-  object_class = (GObjectClass *)klass;
-  object_class->constructor = gtk_combo_box_constructor;
-  object_class->dispose = gtk_combo_box_dispose;
-  object_class->finalize = gtk_combo_box_finalize;
-  object_class->set_property = gtk_combo_box_set_property;
-  object_class->get_property = gtk_combo_box_get_property;
+  container_class = (GtkContainerClass *)klass;
+  container_class->forall = gtk_combo_box_forall;
+  container_class->add = gtk_combo_box_add;
+  container_class->remove = gtk_combo_box_remove;
 
   widget_class = (GtkWidgetClass *)klass;
+  widget_class->size_allocate = gtk_combo_box_size_allocate;
   widget_class->draw = gtk_combo_box_draw;
   widget_class->scroll_event = gtk_combo_box_scroll_event;
   widget_class->mnemonic_activate = gtk_combo_box_mnemonic_activate;
   widget_class->grab_focus = gtk_combo_box_grab_focus;
   widget_class->style_updated = gtk_combo_box_style_updated;
   widget_class->state_changed = gtk_combo_box_state_changed;
-  widget_class->size_allocate = gtk_combo_box_size_allocate;
   widget_class->get_preferred_width = gtk_combo_box_get_preferred_width;
   widget_class->get_preferred_height = gtk_combo_box_get_preferred_height;
   widget_class->get_preferred_height_for_width = gtk_combo_box_get_preferred_height_for_width;
   widget_class->get_preferred_width_for_height = gtk_combo_box_get_preferred_width_for_height;
   widget_class->destroy = gtk_combo_box_destroy;
 
-  container_class = (GtkContainerClass *)klass;
-  container_class->forall = gtk_combo_box_forall;
-  container_class->add = gtk_combo_box_add;
-  container_class->remove = gtk_combo_box_remove;
+  object_class = (GObjectClass *)klass;
+  object_class->constructor = gtk_combo_box_constructor;
+  object_class->dispose = gtk_combo_box_dispose;
+  object_class->finalize = gtk_combo_box_finalize;
+  object_class->set_property = gtk_combo_box_set_property;
+  object_class->get_property = gtk_combo_box_get_property;
 
   /* signals */
   /**
@@ -897,20 +907,6 @@ gtk_combo_box_class_init (GtkComboBoxClass *klass)
                                                          P_("The value of the id column "
                                                          "for the active row"),
                                                          NULL, GTK_PARAM_READWRITE));
-   /**
-    * GtkComboBox:cell-area:
-    *
-    * The #GtkCellArea used to layout cell renderers for this combo box.
-    *
-    * Since: 3.0
-    */
-   g_object_class_install_property (object_class,
-                                    PROP_CELL_AREA,
-                                    g_param_spec_object ("cell-area",
-							 P_("Cell Area"),
-							 P_("The GtkCellArea used to layout cells"),
-							 GTK_TYPE_CELL_AREA,
-							 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
 
    /**
     * GtkComboBox:popup-fixed-width:
@@ -930,6 +926,21 @@ gtk_combo_box_class_init (GtkComboBoxClass *klass)
 							  TRUE,
 							  GTK_PARAM_READWRITE));
 
+   /**
+    * GtkComboBox:cell-area:
+    *
+    * The #GtkCellArea used to layout cell renderers for this combo box.
+    *
+    * Since: 3.0
+    */
+   g_object_class_install_property (object_class,
+                                    PROP_CELL_AREA,
+                                    g_param_spec_object ("cell-area",
+							 P_("Cell Area"),
+							 P_("The GtkCellArea used to layout cells"),
+							 GTK_TYPE_CELL_AREA,
+							 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
   gtk_widget_class_install_style_property (widget_class,
                                            g_param_spec_boolean ("appears-as-list",
                                                                  P_("Appears as list"),
@@ -975,6 +986,28 @@ gtk_combo_box_class_init (GtkComboBoxClass *klass)
 }
 
 static void
+gtk_combo_box_buildable_init (GtkBuildableIface *iface)
+{
+  parent_buildable_iface = g_type_interface_peek_parent (iface);
+  iface->add_child = _gtk_cell_layout_buildable_add_child;
+  iface->custom_tag_start = gtk_combo_box_buildable_custom_tag_start;
+  iface->custom_tag_end = gtk_combo_box_buildable_custom_tag_end;
+  iface->get_internal_child = gtk_combo_box_buildable_get_internal_child;
+}
+
+static void
+gtk_combo_box_cell_layout_init (GtkCellLayoutIface *iface)
+{
+  iface->get_area = gtk_combo_box_cell_layout_get_area;
+}
+
+static void
+gtk_combo_box_cell_editable_init (GtkCellEditableIface *iface)
+{
+  iface->start_editing = gtk_combo_box_start_editing;
+}
+
+static void
 gtk_combo_box_init (GtkComboBox *combo_box)
 {
   GtkComboBoxPrivate *priv;
@@ -984,6 +1017,9 @@ gtk_combo_box_init (GtkComboBox *combo_box)
                                                  GtkComboBoxPrivate);
   priv = combo_box->priv;
 
+  priv->minimum_width = 0;
+  priv->natural_width = 0;
+
   priv->wrap_width = 0;
 
   priv->active = -1;
@@ -1007,104 +1043,6 @@ gtk_combo_box_init (GtkComboBox *combo_box)
   priv->id_column = -1;
 }
 
-/******************************************************
- *                    GObjectClass                    *
- ******************************************************/
-static GObject *
-gtk_combo_box_constructor (GType                  type,
-			   guint                  n_construct_properties,
-			   GObjectConstructParam *construct_properties)
-{
-  GObject            *object;
-  GtkComboBox        *combo_box;
-  GtkComboBoxPrivate *priv;
-  GtkStyleContext    *context;
-
-  object = G_OBJECT_CLASS (gtk_combo_box_parent_class)->constructor
-    (type, n_construct_properties, construct_properties);
-
-  combo_box = GTK_COMBO_BOX (object);
-  priv      = combo_box->priv;
-
-  if (!priv->area)
-    {
-      GtkCellArea *area = gtk_cell_area_box_new ();
-
-      priv->area = g_object_ref_sink (area);
-    }
-
-  priv->cell_view = gtk_cell_view_new_with_context (priv->area, NULL);
-  gtk_cell_view_set_fit_model (GTK_CELL_VIEW (priv->cell_view), TRUE);
-  gtk_cell_view_set_model (GTK_CELL_VIEW (priv->cell_view), priv->model);
-  gtk_widget_set_parent (priv->cell_view, GTK_WIDGET (combo_box));
-  _gtk_bin_set_child (GTK_BIN (combo_box), priv->cell_view);
-  gtk_widget_show (priv->cell_view);
-
-  gtk_combo_box_check_appearance (combo_box);
-
-  context = gtk_widget_get_style_context (GTK_WIDGET (combo_box));
-  gtk_style_context_add_class (context, GTK_STYLE_CLASS_BUTTON);
-
-  if (priv->has_entry)
-    {
-      GtkWidget *entry;
-
-      entry = gtk_entry_new ();
-      gtk_widget_show (entry);
-      gtk_container_add (GTK_CONTAINER (combo_box), entry);
-
-      priv->text_renderer = gtk_cell_renderer_text_new ();
-      gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box),
-				  priv->text_renderer, TRUE);
-
-      gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), -1);
-
-      g_signal_connect (combo_box, "changed",
-			G_CALLBACK (gtk_combo_box_entry_active_changed), NULL);
-    }
-
-  return object;
-}
-
-static void
-gtk_combo_box_dispose(GObject* object)
-{
-  GtkComboBox *combo_box = GTK_COMBO_BOX (object);
-
-  if (GTK_IS_MENU (combo_box->priv->popup_widget))
-    {
-      gtk_combo_box_menu_destroy (combo_box);
-      gtk_menu_detach (GTK_MENU (combo_box->priv->popup_widget));
-      combo_box->priv->popup_widget = NULL;
-    }
-
-  if (combo_box->priv->area)
-    {
-      g_object_unref (combo_box->priv->area);
-      combo_box->priv->area = NULL;
-    }
-
-  G_OBJECT_CLASS (gtk_combo_box_parent_class)->dispose (object);
-}
-
-static void
-gtk_combo_box_finalize (GObject *object)
-{
-  GtkComboBox *combo_box = GTK_COMBO_BOX (object);
-  
-  if (GTK_IS_TREE_VIEW (combo_box->priv->tree_view))
-    gtk_combo_box_list_destroy (combo_box);
-
-  if (combo_box->priv->popup_window)
-    gtk_widget_destroy (combo_box->priv->popup_window);
-
-  gtk_combo_box_unset_model (combo_box);
-
-  g_free (combo_box->priv->tearoff_title);
-
-  G_OBJECT_CLASS (gtk_combo_box_parent_class)->finalize (object);
-}
-
 static void
 gtk_combo_box_set_property (GObject      *object,
                             guint         prop_id,
@@ -1304,358 +1242,6 @@ gtk_combo_box_get_property (GObject    *object,
     }
 }
 
-/******************************************************
- *                    GtkWidgetClass                  *
- ******************************************************/
-static gboolean
-gtk_combo_box_draw (GtkWidget *widget,
-                    cairo_t   *cr)
-{
-  GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
-  GtkComboBoxPrivate *priv = combo_box->priv;
-
-  if (priv->shadow_type != GTK_SHADOW_NONE)
-    {
-      GtkStyleContext *context;
-      GtkStateFlags state;
-
-      context = gtk_widget_get_style_context (widget);
-      state = gtk_widget_get_state_flags (widget);
-      gtk_style_context_set_state (context, state);
-
-      gtk_render_background (context, cr, 0, 0,
-                             gtk_widget_get_allocated_width (widget),
-                             gtk_widget_get_allocated_height (widget));
-      gtk_render_frame (context, cr, 0, 0,
-                        gtk_widget_get_allocated_width (widget),
-                        gtk_widget_get_allocated_height (widget));
-    }
-
-  gtk_container_propagate_draw (GTK_CONTAINER (widget),
-				priv->button, cr);
-
-  if (priv->tree_view && priv->cell_view_frame)
-    {
-      gtk_container_propagate_draw (GTK_CONTAINER (widget),
-				    priv->cell_view_frame, cr);
-    }
-
-  gtk_container_propagate_draw (GTK_CONTAINER (widget),
-                                gtk_bin_get_child (GTK_BIN (widget)),
-                                cr);
-
-  return FALSE;
-}
-
-
-typedef struct {
-  GtkComboBox *combo;
-  GtkTreePath *path;
-  GtkTreeIter iter;
-  gboolean found;
-  gboolean set;
-  gboolean visible;
-} SearchData;
-
-static gboolean
-path_visible (GtkTreeView *view,
-	      GtkTreePath *path)
-{
-  GtkRBTree *tree;
-  GtkRBNode *node;
-  
-  /* Note that we rely on the fact that collapsed rows don't have nodes 
-   */
-  return _gtk_tree_view_find_node (view, path, &tree, &node);
-}
-
-static gboolean
-tree_column_row_is_sensitive (GtkComboBox *combo_box,
-			      GtkTreeIter *iter)
-{
-  GtkComboBoxPrivate *priv = combo_box->priv;
-  GList *cells, *list;
-  gboolean sensitive;
-
-  if (!priv->column)
-    return TRUE;
-
-  if (priv->row_separator_func)
-    {
-      if (priv->row_separator_func (priv->model, iter,
-                                    priv->row_separator_data))
-	return FALSE;
-    }
-
-  gtk_tree_view_column_cell_set_cell_data (priv->column,
-					   priv->model,
-					   iter, FALSE, FALSE);
-
-  cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (priv->column));
-
-  sensitive = FALSE;
-  for (list = cells; list; list = list->next)
-    {
-      g_object_get (list->data, "sensitive", &sensitive, NULL);
-      
-      if (sensitive)
-	break;
-    }
-  g_list_free (cells);
-
-  return sensitive;
-}
-
-static gboolean
-tree_next_func (GtkTreeModel *model,
-		GtkTreePath  *path,
-		GtkTreeIter  *iter,
-		gpointer      data)
-{
-  SearchData *search_data = (SearchData *)data;
-
-  if (search_data->found) 
-    {
-      if (!tree_column_row_is_sensitive (search_data->combo, iter))
-	return FALSE;
-      
-      if (search_data->visible &&
-	  !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
-	return FALSE;
-
-      search_data->set = TRUE;
-      search_data->iter = *iter;
-
-      return TRUE;
-    }
- 
-  if (gtk_tree_path_compare (path, search_data->path) == 0)
-    search_data->found = TRUE;
-  
-  return FALSE;
-}
-
-static gboolean
-tree_next (GtkComboBox  *combo,
-	   GtkTreeModel *model,
-	   GtkTreeIter  *iter,
-	   GtkTreeIter  *next,
-	   gboolean      visible)
-{
-  SearchData search_data;
-
-  search_data.combo = combo;
-  search_data.path = gtk_tree_model_get_path (model, iter);
-  search_data.visible = visible;
-  search_data.found = FALSE;
-  search_data.set = FALSE;
-
-  gtk_tree_model_foreach (model, tree_next_func, &search_data);
-  
-  *next = search_data.iter;
-
-  gtk_tree_path_free (search_data.path);
-
-  return search_data.set;
-}
-
-static gboolean
-tree_prev_func (GtkTreeModel *model,
-		GtkTreePath  *path,
-		GtkTreeIter  *iter,
-		gpointer      data)
-{
-  SearchData *search_data = (SearchData *)data;
-
-  if (gtk_tree_path_compare (path, search_data->path) == 0)
-    {
-      search_data->found = TRUE;
-      return TRUE;
-    }
-  
-  if (!tree_column_row_is_sensitive (search_data->combo, iter))
-    return FALSE;
-      
-  if (search_data->visible &&
-      !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
-    return FALSE; 
-  
-  search_data->set = TRUE;
-  search_data->iter = *iter;
-  
-  return FALSE; 
-}
-
-static gboolean
-tree_prev (GtkComboBox  *combo,
-	   GtkTreeModel *model,
-	   GtkTreeIter  *iter,
-	   GtkTreeIter  *prev,
-	   gboolean      visible)
-{
-  SearchData search_data;
-
-  search_data.combo = combo;
-  search_data.path = gtk_tree_model_get_path (model, iter);
-  search_data.visible = visible;
-  search_data.found = FALSE;
-  search_data.set = FALSE;
-
-  gtk_tree_model_foreach (model, tree_prev_func, &search_data);
-  
-  *prev = search_data.iter;
-
-  gtk_tree_path_free (search_data.path);
-
-  return search_data.set;
-}
-
-static gboolean
-tree_last_func (GtkTreeModel *model,
-		GtkTreePath  *path,
-		GtkTreeIter  *iter,
-		gpointer      data)
-{
-  SearchData *search_data = (SearchData *)data;
-
-  if (!tree_column_row_is_sensitive (search_data->combo, iter))
-    return FALSE;
-      
-  /* Note that we rely on the fact that collapsed rows don't have nodes 
-   */
-  if (search_data->visible &&
-      !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
-    return FALSE; 
-  
-  search_data->set = TRUE;
-  search_data->iter = *iter;
-  
-  return FALSE; 
-}
-
-static gboolean
-tree_last (GtkComboBox  *combo,
-	   GtkTreeModel *model,
-	   GtkTreeIter  *last,
-	   gboolean      visible)
-{
-  SearchData search_data;
-
-  search_data.combo = combo;
-  search_data.visible = visible;
-  search_data.set = FALSE;
-
-  gtk_tree_model_foreach (model, tree_last_func, &search_data);
-  
-  *last = search_data.iter;
-
-  return search_data.set;  
-}
-
-
-static gboolean
-tree_first_func (GtkTreeModel *model,
-		 GtkTreePath  *path,
-		 GtkTreeIter  *iter,
-		 gpointer      data)
-{
-  SearchData *search_data = (SearchData *)data;
-
-  if (!tree_column_row_is_sensitive (search_data->combo, iter))
-    return FALSE;
-  
-  if (search_data->visible &&
-      !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
-    return FALSE;
-  
-  search_data->set = TRUE;
-  search_data->iter = *iter;
-  
-  return TRUE;
-}
-
-static gboolean
-tree_first (GtkComboBox  *combo,
-	    GtkTreeModel *model,
-	    GtkTreeIter  *first,
-	    gboolean      visible)
-{
-  SearchData search_data;
-  
-  search_data.combo = combo;
-  search_data.visible = visible;
-  search_data.set = FALSE;
-
-  gtk_tree_model_foreach (model, tree_first_func, &search_data);
-  
-  *first = search_data.iter;
-
-  return search_data.set;  
-}
-
-static gboolean
-gtk_combo_box_scroll_event (GtkWidget          *widget,
-                            GdkEventScroll     *event)
-{
-  GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
-  gboolean found;
-  GtkTreeIter iter;
-  GtkTreeIter new_iter;
-
-  if (!gtk_combo_box_get_active_iter (combo_box, &iter))
-    return TRUE;
-  
-  if (event->direction == GDK_SCROLL_UP)
-    found = tree_prev (combo_box, combo_box->priv->model, 
-		       &iter, &new_iter, FALSE);
-  else
-    found = tree_next (combo_box, combo_box->priv->model, 
-		       &iter, &new_iter, FALSE);
-  
-  if (found)
-    gtk_combo_box_set_active_iter (combo_box, &new_iter);
-
-  return TRUE;
-}
-
-
-static gboolean
-gtk_combo_box_mnemonic_activate (GtkWidget *widget,
-				 gboolean   group_cycling)
-{
-  GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
-
-  if (combo_box->priv->has_entry)
-    {
-      GtkWidget* child;
-
-      child = gtk_bin_get_child (GTK_BIN (combo_box));
-      if (child)
-	gtk_widget_grab_focus (child);
-    }
-  else
-    gtk_widget_grab_focus (combo_box->priv->button);
-
-  return TRUE;
-}
-
-static void
-gtk_combo_box_grab_focus (GtkWidget *widget)
-{
-  GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
-
-  if (combo_box->priv->has_entry)
-    {
-      GtkWidget *child;
-
-      child = gtk_bin_get_child (GTK_BIN (combo_box));
-      if (child)
-	gtk_widget_grab_focus (child);
-    }
-  else
-    gtk_widget_grab_focus (combo_box->priv->button);
-}
-
 static void
 gtk_combo_box_state_changed (GtkWidget    *widget,
 			     GtkStateType  previous)
@@ -1666,8 +1252,8 @@ gtk_combo_box_state_changed (GtkWidget    *widget,
   if (gtk_widget_get_realized (widget))
     {
       if (priv->tree_view && priv->cell_view)
-	{
-	  GtkStyleContext *context;
+        {
+          GtkStyleContext *context;
           GtkStateFlags state;
           GdkRGBA *color;
 
@@ -1680,16 +1266,16 @@ gtk_combo_box_state_changed (GtkWidget    *widget,
 
           gtk_cell_view_set_background_rgba (GTK_CELL_VIEW (priv->cell_view), color);
           gdk_rgba_free (color);
-	}
+        }
     }
 
   gtk_widget_queue_draw (widget);
 }
 
 static void
-gtk_combo_box_button_state_changed (GtkWidget    *widget,
-				    GtkStateType  previous,
-				    gpointer      data)
+gtk_combo_box_button_state_flags_changed (GtkWidget     *widget,
+                                          GtkStateFlags  previous,
+                                          gpointer       data)
 {
   GtkComboBox *combo_box = GTK_COMBO_BOX (data);
   GtkComboBoxPrivate *priv = combo_box->priv;
@@ -1697,14 +1283,9 @@ gtk_combo_box_button_state_changed (GtkWidget    *widget,
   if (gtk_widget_get_realized (widget))
     {
       if (!priv->tree_view && priv->cell_view)
-	{
-	  if ((gtk_widget_get_state (widget) == GTK_STATE_INSENSITIVE) !=
-	      (gtk_widget_get_state (priv->cell_view) == GTK_STATE_INSENSITIVE))
-	    gtk_widget_set_sensitive (priv->cell_view, gtk_widget_get_sensitive (widget));
-	  
-	  gtk_widget_set_state (priv->cell_view, 
-				gtk_widget_get_state (widget));
-	}
+        gtk_widget_set_state_flags (priv->cell_view,
+                                    gtk_widget_get_state_flags (widget),
+                                    TRUE);
     }
 
   gtk_widget_queue_draw (widget);
@@ -1725,12 +1306,12 @@ gtk_combo_box_check_appearance (GtkComboBox *combo_box)
     gtk_widget_style_get (GTK_WIDGET (combo_box),
 			  "appears-as-list", &appears_as_list,
 			  NULL);
-
+  
   if (appears_as_list)
     {
       /* Destroy all the menu mode widgets, if they exist. */
       if (GTK_IS_MENU (priv->popup_widget))
-      	gtk_combo_box_menu_destroy (combo_box);
+	gtk_combo_box_menu_destroy (combo_box);
 
       /* Create the list mode widgets, if they don't already exist. */
       if (!GTK_IS_TREE_VIEW (priv->tree_view))
@@ -1768,10 +1349,12 @@ gtk_combo_box_style_updated (GtkWidget *widget)
 
       context = gtk_widget_get_style_context (widget);
       gtk_style_context_get (context, 0,
-			     "background-color", &color,
-			     NULL);
+                             "background-color", &color,
+                             NULL);
+
+      gtk_cell_view_set_background_rgba (GTK_CELL_VIEW (priv->cell_view),
+                                         color);
 
-      gtk_cell_view_set_background_rgba (GTK_CELL_VIEW (priv->cell_view), color);
       gdk_rgba_free (color);
     }
 
@@ -1783,551 +1366,20 @@ gtk_combo_box_style_updated (GtkWidget *widget)
 }
 
 static void
-gtk_combo_box_destroy (GtkWidget *widget)
-{
-  GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
-
-  if (combo_box->priv->popup_idle_id > 0)
-    {
-      g_source_remove (combo_box->priv->popup_idle_id);
-      combo_box->priv->popup_idle_id = 0;
-    }
-
-  gtk_combo_box_popdown (combo_box);
-
-  if (combo_box->priv->row_separator_destroy)
-    combo_box->priv->row_separator_destroy (combo_box->priv->row_separator_data);
-
-  combo_box->priv->row_separator_func = NULL;
-  combo_box->priv->row_separator_data = NULL;
-  combo_box->priv->row_separator_destroy = NULL;
-
-  GTK_WIDGET_CLASS (gtk_combo_box_parent_class)->destroy (widget);
-  combo_box->priv->cell_view = NULL;
-}
-
-static void
-get_widget_border (GtkWidget *widget,
-		   GtkBorder *border)
-{
-  GtkStyleContext *context;
-  GtkBorder *border_width;
-
-  context = gtk_widget_get_style_context (widget);
-
-  gtk_style_context_get (context,
-                         gtk_widget_get_state_flags (widget),
-                         "border-width", &border_width,
-                         NULL);
-
-  *border = *border_width;
-  gtk_border_free (border_width);
-}
-
-static void     
-gtk_combo_box_get_preferred_width (GtkWidget *widget,
-                                   gint      *minimum_size,
-                                   gint      *natural_size)
-{
-  GtkComboBox           *combo_box = GTK_COMBO_BOX (widget);
-  GtkComboBoxPrivate    *priv = combo_box->priv;
-  gint                   focus_width, focus_pad;
-  gint                   font_size, arrow_size;
-  PangoContext          *context;
-  PangoFontMetrics      *metrics;
-  PangoFontDescription  *font_desc;
-  GtkWidget             *child;
-  gint                   minimum_width = 0, natural_width = 0;
-  gint                   child_min, child_nat;
-  GtkStyleContext       *style_context;
-  GtkStateFlags          state;
-  GtkBorder             *border;
-
-  child = gtk_bin_get_child (GTK_BIN (widget));
- 
-  /* common */
-  gtk_widget_get_preferred_width (child, &child_min, &child_nat);
-
-  gtk_widget_style_get (GTK_WIDGET (widget),
-			"focus-line-width", &focus_width,
-			"focus-padding", &focus_pad,
-			"arrow-size", &arrow_size,
-			NULL);
-
-  style_context = gtk_widget_get_style_context (widget);
-  state = gtk_widget_get_state_flags (widget);
-
-  gtk_style_context_get (style_context, state,
-                         "font", &font_desc,
-			 "border-width", &border,
-                         NULL);
-
-  context = gtk_widget_get_pango_context (GTK_WIDGET (widget));
-  metrics = pango_context_get_metrics (context, font_desc,
-				       pango_context_get_language (context));
-  font_size = PANGO_PIXELS (pango_font_metrics_get_ascent (metrics) +
-			    pango_font_metrics_get_descent (metrics));
-  pango_font_metrics_unref (metrics);
-  pango_font_description_free (font_desc);
-
-  arrow_size = MAX (arrow_size, font_size);
-
-  gtk_widget_set_size_request (priv->arrow, arrow_size, arrow_size);
-
-  if (!priv->tree_view)
-    {
-      /* menu mode */	  
-      if (priv->cell_view)
-        {
-          gint sep_width, arrow_width;
-          gint border_width, xpad;
-	  GtkBorder button_border;
-
-	  border_width = gtk_container_get_border_width (GTK_CONTAINER (combo_box));
-	  get_widget_border (priv->button, &button_border);
-
-          gtk_widget_get_preferred_width (priv->separator, &sep_width, NULL);
-          gtk_widget_get_preferred_width (priv->arrow, &arrow_width, NULL);
-
-	  xpad = 2 * (border_width + focus_width + focus_pad) +
-            button_border.left + button_border.right;
-
-          minimum_width  = child_min + sep_width + arrow_width + xpad;
-          natural_width  = child_nat + sep_width + arrow_width + xpad;
-        }
-      else
-        {
-          gint but_width, but_nat_width;
-
-          gtk_widget_get_preferred_width (priv->button, 
-                                          &but_width, &but_nat_width);
-
-          minimum_width  = child_min + but_width;
-          natural_width  = child_nat + but_nat_width;
-        }
-    }
-  else
-    {
-      /* list mode */
-      gint button_width, button_nat_width;
-
-      /* sample + frame */
-      minimum_width = child_min;
-      natural_width = child_nat;
-
-      minimum_width += 2 * focus_width;
-      natural_width += 2 * focus_width;
-      
-      if (priv->cell_view_frame)
-        {
-	  if (priv->has_frame)
-	    {
-	      gint border_width, xpad;
-              GtkBorder frame_border;
-
-              border_width = gtk_container_get_border_width (GTK_CONTAINER (priv->cell_view_frame));
-              get_widget_border (priv->cell_view_frame, &frame_border);
-              xpad = (2 * border_width) + frame_border.left + frame_border.right;
-
-	      minimum_width  += xpad;
-	      natural_width  += xpad;
-	    }
-        }
-
-      /* the button */
-      gtk_widget_get_preferred_width (priv->button, 
-                                      &button_width, &button_nat_width);
-
-      minimum_width += button_width;
-      natural_width += button_nat_width;
-    }
-
-  minimum_width += border->left + border->right;
-  natural_width += border->left + border->right;
-  gtk_border_free (border);
-
-  if (minimum_size)
-    *minimum_size = minimum_width;
-
-  if (natural_size)
-    *natural_size = natural_width;
-}
-
-static void
-gtk_combo_box_get_preferred_height (GtkWidget *widget,
-                                    gint      *minimum_size,
-                                    gint      *natural_size)
-{ 
-  gint min_width;
-
-  /* Combo box is height-for-width only 
-   * (so we always just reserve enough height for the minimum width) */
-  GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, &min_width, NULL);
-  GTK_WIDGET_GET_CLASS (widget)->get_preferred_height_for_width (widget, min_width, minimum_size, natural_size);
-}
-
-static void
-gtk_combo_box_get_preferred_width_for_height (GtkWidget *widget,
-                                              gint       avail_size,
-                                              gint      *minimum_size,
-                                              gint      *natural_size)
-{
-  /* Combo box is height-for-width only 
-   * (so we assume we always reserved enough height for the minimum width) */
-  GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_size, natural_size);
-}
-
-
-static void
-gtk_combo_box_get_preferred_height_for_width (GtkWidget *widget,
-                                              gint       avail_size,
-                                              gint      *minimum_size,
-                                              gint      *natural_size)
-{
-  GtkComboBox           *combo_box = GTK_COMBO_BOX (widget);
-  GtkComboBoxPrivate    *priv = combo_box->priv;
-  gint                   focus_width, focus_pad;
-  gint                   min_height = 0, nat_height = 0;
-  gint                   size;
-  GtkWidget             *child;
-  GtkBorder              border;
-
-  gtk_widget_style_get (GTK_WIDGET (widget),
-			"focus-line-width", &focus_width,
-			"focus-padding", &focus_pad,
-			NULL);
-
-  child = gtk_bin_get_child (GTK_BIN (widget));
-
-  get_widget_border (widget, &border);
-  size = avail_size - border.left;
-
-  if (!priv->tree_view)
-    {
-      /* menu mode */
-      if (priv->cell_view)
-        {
-	  /* calculate x/y padding and separator/arrow size */
-          gint sep_width, arrow_width, sep_height, arrow_height;
-          gint border_width, xpad, ypad;
-          GtkBorder button_border;
-
-	  border_width = gtk_container_get_border_width (GTK_CONTAINER (combo_box));
-	  get_widget_border (priv->button, &button_border);
-
-          gtk_widget_get_preferred_width (priv->separator, &sep_width, NULL);
-          gtk_widget_get_preferred_width (priv->arrow, &arrow_width, NULL);
-          gtk_widget_get_preferred_height_for_width (priv->separator, 
-                                                     sep_width, &sep_height, NULL);
-          gtk_widget_get_preferred_height_for_width (priv->arrow, 
-                                                     arrow_width, &arrow_height, NULL);
-
-	  xpad = 2 * (border_width + focus_width + focus_pad) +
-	    button_border.left + button_border.right;
-	  ypad = 2 * (border_width + focus_width + focus_pad) +
-	    button_border.top + button_border.bottom;
-
-	  size -= sep_width + arrow_width + xpad;
-
-	  /* Get height-for-width of the child widget, usually a GtkCellArea calculating
-	   * and fitting the whole treemodel */
-	  gtk_widget_get_preferred_height_for_width (child, size, &min_height, &nat_height);
-
-	  arrow_height = MAX (arrow_height, sep_height);
-	  min_height = MAX (min_height, arrow_height);
-	  nat_height = MAX (nat_height, arrow_height);
-
-	  min_height += ypad;
-	  nat_height += ypad;
-        }
-      else
-        {
-	  /* there is a custom child widget inside (no priv->cell_view) */
-          gint but_width, but_height;
-
-          gtk_widget_get_preferred_width (priv->button, &but_width, NULL);
-          gtk_widget_get_preferred_height_for_width (priv->button, 
-                                                     but_width, &but_height, NULL);
-
-	  size -= but_width;
-
-	  /* Get height-for-width of the child widget, usually a GtkCellArea calculating
-	   * and fitting the whole treemodel */
-	  gtk_widget_get_preferred_height_for_width (child, size, &min_height, &nat_height);
-	  
-	  min_height = MAX (min_height, but_height);
-	  nat_height = MAX (nat_height, but_height);
-        }
-    }
-  else
-    {
-      /* list mode */
-      gint but_width, but_height;
-      gint xpad = 0, ypad = 0;
-
-      gtk_widget_get_preferred_width (priv->button, &but_width, NULL);
-      gtk_widget_get_preferred_height_for_width (priv->button, 
-                                                 but_width, &but_height, NULL);
-      
-      if (priv->cell_view_frame && priv->has_frame)
-	{
-	  GtkBorder frame_border;
-	  gint border_width;
-
-          border_width = gtk_container_get_border_width (GTK_CONTAINER (priv->cell_view_frame));
-	  get_widget_border (GTK_WIDGET (priv->cell_view_frame), &frame_border);
-
-	  xpad = (2 * border_width) + border.left + frame_border.right;
-	  ypad = (2 * border_width) + border.top + frame_border.bottom;
-	}
-
-      size -= but_width;
-      size -= 2 * focus_width;
-      size -= xpad;
- 
-      /* Get height-for-width of the child widget, usually a GtkCellArea calculating
-       * and fitting the whole treemodel */
-      gtk_widget_get_preferred_height_for_width (child, size, &min_height, &nat_height);
-
-      min_height = MAX (min_height, but_height);
-      nat_height = MAX (nat_height, but_height);
-
-      min_height += ypad;
-      nat_height += ypad;
-    }
-
-  min_height += border.top + border.bottom;
-  nat_height += border.top + border.bottom;
-
-  if (minimum_size)
-    *minimum_size = min_height;
-
-  if (natural_size)
-    *natural_size = nat_height;
-}
-
-#define GTK_COMBO_BOX_SIZE_ALLOCATE_BUTTON 					\
-  gtk_widget_get_preferred_size (combo_box->priv->button,	                \
-                                 &req, NULL); 					\
-  										\
-  if (is_rtl) 									\
-    child.x = allocation->x + border.right;					\
-  else										\
-    child.x = allocation->x + allocation->width - req.width - border.left;	\
-    										\
-  child.y = allocation->y + border.top;						\
-  child.width = req.width;							\
-  child.height = allocation->height - (border.top + border.bottom);		\
-  child.width = MAX (1, child.width);						\
-  child.height = MAX (1, child.height);						\
-  										\
-  gtk_widget_size_allocate (combo_box->priv->button, &child);
-
-
-static void
-gtk_combo_box_size_allocate (GtkWidget     *widget,
-                             GtkAllocation *allocation)
+gtk_combo_box_button_toggled (GtkWidget *widget,
+                              gpointer   data)
 {
-  GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
-  GtkComboBoxPrivate *priv = combo_box->priv;
-  GtkWidget *child_widget;
-  gint focus_width, focus_pad;
-  GtkAllocation child;
-  GtkRequisition req;
-  gboolean is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
-  GtkBorder border;
-
-  gtk_widget_set_allocation (widget, allocation);
-  child_widget = gtk_bin_get_child (GTK_BIN (widget));
-  get_widget_border (widget, &border);
-
-  gtk_widget_style_get (widget,
-			"focus-line-width", &focus_width,
-			"focus-padding", &focus_pad,
-			NULL);
+  GtkComboBox *combo_box = GTK_COMBO_BOX (data);
 
-  if (!priv->tree_view)
+  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
     {
-      if (priv->cell_view)
-        {
-	  GtkBorder button_border;
-          gint width;
-          guint border_width;
-
-          /* menu mode */
-          allocation->x += border.left;
-          allocation->y += border.top;
-          allocation->width -= border.left + border.right;
-          allocation->height -= border.top + border.bottom;
-
-          gtk_widget_size_allocate (priv->button, allocation);
-
-          /* set some things ready */
-          border_width = gtk_container_get_border_width (GTK_CONTAINER (priv->button));
-	  get_widget_border (priv->button, &button_border);
-
-          child.x = allocation->x;
-          child.y = allocation->y;
-	  width = allocation->width;
-	  child.height = allocation->height;
-
-	  if (!priv->is_cell_renderer)
-	    {
-	      child.x += border_width + button_border.left + focus_width + focus_pad;
-	      child.y += border_width + button_border.top + focus_width + focus_pad;
-	      width -= (2 * (border_width + focus_width + focus_pad)) +
-                button_border.left + button_border.right;
-	      child.height -= (2 * (border_width + focus_width + focus_pad)) +
-                button_border.top + button_border.bottom;
-	    }
-
-          /* handle the children */
-          gtk_widget_get_preferred_size (priv->arrow, &req, NULL);
-          child.width = req.width;
-          if (!is_rtl)
-            child.x += width - req.width;
-	  child.width = MAX (1, child.width);
-	  child.height = MAX (1, child.height);
-          gtk_widget_size_allocate (priv->arrow, &child);
-          if (is_rtl)
-            child.x += req.width;
-          gtk_widget_get_preferred_size (priv->separator, &req, NULL);
-          child.width = req.width;
-          if (!is_rtl)
-            child.x -= req.width;
-	  child.width = MAX (1, child.width);
-	  child.height = MAX (1, child.height);
-          gtk_widget_size_allocate (priv->separator, &child);
-
-          if (is_rtl)
-            {
-              child.x += req.width;
-              child.width = allocation->x + allocation->width 
-                - (border_width + button_border.right + focus_width + focus_pad) 
-		- child.x;
-            }
-          else 
-            {
-              child.width = child.x;
-              child.x = allocation->x 
-		+ border_width + button_border.left + focus_width + focus_pad;
-              child.width -= child.x;
-            }
-
-          if (gtk_widget_get_visible (priv->popup_widget))
-            {
-              gint width, menu_width;
-
-              if (priv->wrap_width == 0)
-                {
-                  GtkAllocation combo_box_allocation;
-
-                  gtk_widget_get_allocation (GTK_WIDGET (combo_box), &combo_box_allocation);
-                  width = combo_box_allocation.width;
-                  gtk_widget_set_size_request (priv->popup_widget, -1, -1);
-
-		  if (combo_box->priv->popup_fixed_width)
-		    gtk_widget_get_preferred_width (priv->popup_widget, &menu_width, NULL);
-		  else
-		    gtk_widget_get_preferred_width (priv->popup_widget, NULL, &menu_width);
-
-                  gtk_widget_set_size_request (priv->popup_widget,
-					       MAX (width, menu_width), -1);
-               }
-
-              /* reposition the menu after giving it a new width */
-              gtk_menu_reposition (GTK_MENU (priv->popup_widget));
-            }
-
-	  child.width = MAX (1, child.width);
-	  child.height = MAX (1, child.height);
-          gtk_widget_size_allocate (child_widget, &child);
-        }
-      else
-        {
-          GTK_COMBO_BOX_SIZE_ALLOCATE_BUTTON
-
-          if (is_rtl)
-            child.x = allocation->x + req.width + border.right;
-          else
-            child.x = allocation->x + border.left;
-          child.y = allocation->y + border.top;
-          child.width = allocation->width - req.width - (border.left + border.right);
-	  child.width = MAX (1, child.width);
-	  child.height = MAX (1, child.height);
-          gtk_widget_size_allocate (child_widget, &child);
-        }
+      if (!combo_box->priv->popup_in_progress)
+        gtk_combo_box_popup (combo_box);
     }
   else
-    {
-      /* list mode */
-      guint border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
-
-      /* button */
-      GTK_COMBO_BOX_SIZE_ALLOCATE_BUTTON
-
-      /* frame */
-      if (is_rtl)
-        child.x = allocation->x + req.width;
-      else
-        child.x = allocation->x;
-
-      child.y = allocation->y;
-      child.width = allocation->width - req.width;
-      child.height = allocation->height;
-
-      if (priv->cell_view_frame)
-        {
-          child.x += border.left + border_width;
-          child.y += border.top + border_width;
-          child.width = MAX (1, child.width - (2 * border_width) - (border.left + border.right));
-          child.height = MAX (1, child.height - (2 * border_width) - (border.top + border.bottom));
-          gtk_widget_size_allocate (priv->cell_view_frame, &child);
-
-          /* the sample */
-          if (priv->has_frame)
-            {
-	      GtkBorder frame_border;
-
-              border_width = gtk_container_get_border_width (GTK_CONTAINER (priv->cell_view_frame));
-	      get_widget_border (priv->cell_view_frame, &frame_border);
-
-              child.x += border_width + frame_border.left;
-              child.y += border_width + frame_border.right;
-              child.width -= (2 * border_width) + frame_border.left + frame_border.right;
-              child.height -= (2 * border_width) + frame_border.top + frame_border.bottom;
-            }
-        }
-      else
-        {
-          child.x += border.left + border_width;
-          child.y += border.top + border_width;
-          child.width -= (2 * border_width) - (border.left + border.right);
-          child.height -= (2 * border_width) - (border.top + border.bottom);
-        }
-
-      if (gtk_widget_get_visible (priv->popup_window))
-        {
-          gint x, y, width, height;
-          gtk_combo_box_list_position (combo_box, &x, &y, &width, &height);
-          gtk_window_move (GTK_WINDOW (priv->popup_window), x, y);
-          gtk_widget_set_size_request (priv->popup_window, width, height);
-        }
-
-      
-      child.width = MAX (1, child.width);
-      child.height = MAX (1, child.height);
-      
-      gtk_widget_size_allocate (child_widget, &child);
-    }
+    gtk_combo_box_popdown (combo_box);
 }
 
-#undef GTK_COMBO_BOX_ALLOCATE_BUTTON
-
-/******************************************************
- *                  GtkContainerClass                 *
- ******************************************************/
-
 static void
 gtk_combo_box_add (GtkContainer *container,
                    GtkWidget    *widget)
@@ -2346,10 +1398,11 @@ gtk_combo_box_add (GtkContainer *container,
   if (priv->cell_view &&
       gtk_widget_get_parent (priv->cell_view))
     {
-      gtk_container_remove (container, priv->cell_view);
+      gtk_widget_unparent (priv->cell_view);
+      _gtk_bin_set_child (GTK_BIN (container), NULL);
       gtk_widget_queue_resize (GTK_WIDGET (container));
     }
-
+  
   gtk_widget_set_parent (widget, GTK_WIDGET (container));
   _gtk_bin_set_child (GTK_BIN (container), widget);
 
@@ -2403,20 +1456,20 @@ gtk_combo_box_remove (GtkContainer *container,
       GtkWidget *child_widget;
 
       child_widget = gtk_bin_get_child (GTK_BIN (container));
-      if (widget && widget == child_widget && GTK_IS_ENTRY (widget))
+      if (widget && widget == child_widget)
 	{
 	  g_signal_handlers_disconnect_by_func (widget,
 						gtk_combo_box_entry_contents_changed,
 						container);
-
-	  _gtk_entry_set_is_cell_renderer (GTK_ENTRY (widget), FALSE);
+          _gtk_entry_set_is_cell_renderer (GTK_ENTRY (widget), FALSE);
 	}
     }
 
   if (widget == priv->cell_view)
     priv->cell_view = NULL;
 
-  GTK_CONTAINER_CLASS (gtk_combo_box_parent_class)->remove (container, widget);
+  gtk_widget_unparent (widget);
+  _gtk_bin_set_child (GTK_BIN (container), NULL);
 
   if (gtk_widget_in_destruction (GTK_WIDGET (combo_box)))
     return;
@@ -2439,15 +1492,16 @@ gtk_combo_box_remove (GtkContainer *container,
 
   if (!priv->cell_view)
     {
-      priv->cell_view = gtk_cell_view_new_with_context (priv->area, NULL);
-      gtk_cell_view_set_fit_model (GTK_CELL_VIEW (priv->cell_view), TRUE);
-
-      GTK_CONTAINER_CLASS (gtk_combo_box_parent_class)->add (container, priv->cell_view);
+      priv->cell_view = gtk_cell_view_new ();
+      gtk_widget_set_parent (priv->cell_view, GTK_WIDGET (container));
+      _gtk_bin_set_child (GTK_BIN (container), priv->cell_view);
       
       gtk_widget_show (priv->cell_view);
-      gtk_cell_view_set_model (GTK_CELL_VIEW (priv->cell_view), priv->model);
+      gtk_cell_view_set_model (GTK_CELL_VIEW (priv->cell_view),
+			       priv->model);
     }
 
+
   if (appears_as_list)
     gtk_combo_box_list_setup (combo_box); 
   else
@@ -2464,205 +1518,6 @@ gtk_combo_box_remove (GtkContainer *container,
 }
 
 static void
-gtk_combo_box_forall (GtkContainer *container,
-                      gboolean      include_internals,
-                      GtkCallback   callback,
-                      gpointer      callback_data)
-{
-  GtkComboBox *combo_box = GTK_COMBO_BOX (container);
-  GtkComboBoxPrivate *priv = combo_box->priv;
-  GtkWidget *child;
-
-  if (include_internals)
-    {
-      if (priv->button)
-	(* callback) (priv->button, callback_data);
-      if (priv->cell_view_frame)
-	(* callback) (priv->cell_view_frame, callback_data);
-    }
-
-  child = gtk_bin_get_child (GTK_BIN (container));
-  if (child)
-    (* callback) (child, callback_data);
-}
-
-
-/******************************************************
- *        GtkComboBoxClass (binding methods)          *
- ******************************************************/
-static void
-gtk_combo_box_real_move_active (GtkComboBox   *combo_box,
-                                GtkScrollType  scroll)
-{
-  GtkTreeIter iter;
-  GtkTreeIter new_iter;
-  gboolean    active_iter;
-  gboolean    found;
-
-  if (!combo_box->priv->model)
-    {
-      gtk_widget_error_bell (GTK_WIDGET (combo_box));
-      return;
-    }
-
-  active_iter = gtk_combo_box_get_active_iter (combo_box, &iter);
-
-  switch (scroll)
-    {
-    case GTK_SCROLL_STEP_BACKWARD:
-    case GTK_SCROLL_STEP_UP:
-    case GTK_SCROLL_STEP_LEFT:
-      if (active_iter)
-        {
-	  found = tree_prev (combo_box, combo_box->priv->model,
-			     &iter, &new_iter, FALSE);
-	  break;
-        }
-      /* else fall through */
-
-    case GTK_SCROLL_PAGE_FORWARD:
-    case GTK_SCROLL_PAGE_DOWN:
-    case GTK_SCROLL_PAGE_RIGHT:
-    case GTK_SCROLL_END:
-      found = tree_last (combo_box, combo_box->priv->model, &new_iter, FALSE);
-      break;
-
-    case GTK_SCROLL_STEP_FORWARD:
-    case GTK_SCROLL_STEP_DOWN:
-    case GTK_SCROLL_STEP_RIGHT:
-      if (active_iter)
-        {
-	  found = tree_next (combo_box, combo_box->priv->model,
-			     &iter, &new_iter, FALSE);
-          break;
-        }
-      /* else fall through */
-
-    case GTK_SCROLL_PAGE_BACKWARD:
-    case GTK_SCROLL_PAGE_UP:
-    case GTK_SCROLL_PAGE_LEFT:
-    case GTK_SCROLL_START:
-      found = tree_first (combo_box, combo_box->priv->model, &new_iter, FALSE);
-      break;
-
-    default:
-      return;
-    }
-
-  if (found && active_iter)
-    {
-      GtkTreePath *old_path;
-      GtkTreePath *new_path;
-
-      old_path = gtk_tree_model_get_path (combo_box->priv->model, &iter);
-      new_path = gtk_tree_model_get_path (combo_box->priv->model, &new_iter);
-
-      if (gtk_tree_path_compare (old_path, new_path) == 0)
-        found = FALSE;
-
-      gtk_tree_path_free (old_path);
-      gtk_tree_path_free (new_path);
-    }
-
-  if (found)
-    {
-      gtk_combo_box_set_active_iter (combo_box, &new_iter);
-    }
-  else
-    {
-      gtk_widget_error_bell (GTK_WIDGET (combo_box));
-    }
-}
-
-static void
-gtk_combo_box_real_popup (GtkComboBox *combo_box)
-{
-  GdkDevice *device;
-
-  device = gtk_get_current_event_device ();
-
-  if (!device)
-    {
-      GdkDeviceManager *device_manager;
-      GdkDisplay *display;
-      GList *devices;
-
-      display = gtk_widget_get_display (GTK_WIDGET (combo_box));
-      device_manager = gdk_display_get_device_manager (display);
-
-      /* No device was set, pick the first master device */
-      devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
-      device = devices->data;
-      g_list_free (devices);
-    }
-
-  gtk_combo_box_popup_for_device (combo_box, device);
-}
-
-static gboolean
-gtk_combo_box_real_popdown (GtkComboBox *combo_box)
-{
-  if (combo_box->priv->popup_shown)
-    {
-      gtk_combo_box_popdown (combo_box);
-      return TRUE;
-    }
-
-  return FALSE;
-}
-
-
-/******************************************************
- *                 GtkTreeModel callbacks             *
- ******************************************************/
-static void
-gtk_combo_box_model_row_inserted (GtkTreeModel     *model,
-				  GtkTreePath      *path,
-				  GtkTreeIter      *iter,
-				  gpointer          user_data)
-{
-  GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
-
-  if (combo_box->priv->tree_view)
-    gtk_combo_box_list_popup_resize (combo_box);
-}
-
-static void
-gtk_combo_box_model_row_deleted (GtkTreeModel     *model,
-				 GtkTreePath      *path,
-				 gpointer          user_data)
-{
-  GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
-  GtkComboBoxPrivate *priv = combo_box->priv;
-
-  if (!gtk_tree_row_reference_valid (priv->active_row))
-    {
-      if (priv->cell_view)
-	gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (priv->cell_view), NULL);
-      g_signal_emit (combo_box, combo_box_signals[CHANGED], 0);
-    }
-  
-  if (priv->tree_view)
-    gtk_combo_box_list_popup_resize (combo_box);
-}
-
-
-static void
-gtk_combo_box_button_toggled (GtkWidget *widget,
-                              gpointer   data)
-{
-  GtkComboBox *combo_box = GTK_COMBO_BOX (data);
-
-  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
-    {
-      if (!combo_box->priv->popup_in_progress)
-        gtk_combo_box_popup (combo_box);
-    }
-  else
-    gtk_combo_box_popdown (combo_box);
-}
-
-static void
 gtk_combo_box_menu_show (GtkWidget *menu,
                          gpointer   user_data)
 {
@@ -2807,6 +1662,24 @@ gtk_combo_box_set_popup_widget (GtkComboBox *combo_box,
 }
 
 static void
+get_widget_border (GtkWidget *widget,
+                   GtkBorder *border)
+{
+  GtkStyleContext *context;
+  GtkBorder *border_width;
+
+  context = gtk_widget_get_style_context (widget);
+
+  gtk_style_context_get (context,
+                         gtk_widget_get_state_flags (widget),
+                         "border-width", &border_width,
+                         NULL);
+
+  *border = *border_width;
+  gtk_border_free (border_width);
+}
+
+static void
 gtk_combo_box_menu_position_below (GtkMenu  *menu,
 				   gint     *x,
 				   gint     *y,
@@ -2822,7 +1695,7 @@ gtk_combo_box_menu_position_below (GtkMenu  *menu,
   gint monitor_num;
   GdkRectangle monitor;
   GtkBorder border;
-  
+
   /* FIXME: is using the size request here broken? */
   child = gtk_bin_get_child (GTK_BIN (combo_box));
 
@@ -2838,7 +1711,6 @@ gtk_combo_box_menu_position_below (GtkMenu  *menu,
 
   gdk_window_get_root_coords (gtk_widget_get_window (child),
                               sx, sy, &sx, &sy);
-
   get_widget_border (GTK_WIDGET (combo_box), &border);
   sx -= border.left;
 
@@ -3024,6 +1896,10 @@ gtk_combo_box_list_position (GtkComboBox *combo_box,
   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
 				  hpolicy, vpolicy);
 
+  /* XXX This set_size_request call is part of the hack outlined below and can 
+   * go away once height-for-width is implemented on treeviews. */
+  gtk_widget_set_size_request (priv->tree_view, -1, -1);
+
   if (combo_box->priv->popup_fixed_width)
     {
       gtk_widget_get_preferred_size (priv->scrolled_window, &popup_req, NULL);
@@ -3037,15 +1913,25 @@ gtk_combo_box_list_position (GtkComboBox *combo_box,
     }
   else
     {
-      /* This code depends on treeviews properly reporting their natural width */
-      gtk_widget_get_preferred_size (priv->scrolled_window, NULL, &popup_req);
-
-      if (popup_req.width > *width)
+      if (priv->natural_width > *width)
 	{
 	  hpolicy = GTK_POLICY_NEVER;
 	  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
 					  hpolicy, vpolicy);
 
+
+	  /* XXX Currently we set the size-request on the internal treeview to be
+	   * the natural width of the cells, this hack can go away once our
+	   * treeview does height-for-width properly (i.e. just adjust *width
+	   * here to be the natural width request of the scrolled-window). 
+	   *
+	   * I can't tell why the magic number 5 is needed here (i.e. without it 
+	   * treeviews are left ellipsizing) , however it this all should be
+	   * removed with height-for-width treeviews.
+	   */
+	  gtk_widget_set_size_request (priv->tree_view, priv->natural_width + 5, -1);
+	  gtk_widget_get_preferred_size (priv->scrolled_window, NULL, &popup_req);
+
 	  *width = popup_req.width;
 	}
     }
@@ -3088,6 +1974,111 @@ gtk_combo_box_list_position (GtkComboBox *combo_box,
     }
 } 
 
+static gboolean
+cell_view_is_sensitive (GtkCellView *cell_view)
+{
+  GList *cells, *list;
+  gboolean sensitive;
+  
+  cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (cell_view));
+
+  sensitive = FALSE;
+  for (list = cells; list; list = list->next)
+    {
+      g_object_get (list->data, "sensitive", &sensitive, NULL);
+      
+      if (sensitive)
+	break;
+    }
+  g_list_free (cells);
+
+  return sensitive;
+}
+
+static gboolean
+tree_column_row_is_sensitive (GtkComboBox *combo_box,
+			      GtkTreeIter *iter)
+{
+  GtkComboBoxPrivate *priv = combo_box->priv;
+  GList *cells, *list;
+  gboolean sensitive;
+
+  if (!priv->column)
+    return TRUE;
+
+  if (priv->row_separator_func)
+    {
+      if (priv->row_separator_func (priv->model, iter,
+                                    priv->row_separator_data))
+	return FALSE;
+    }
+
+  gtk_tree_view_column_cell_set_cell_data (priv->column,
+					   priv->model,
+					   iter, FALSE, FALSE);
+
+  cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (priv->column));
+
+  sensitive = FALSE;
+  for (list = cells; list; list = list->next)
+    {
+      g_object_get (list->data, "sensitive", &sensitive, NULL);
+      
+      if (sensitive)
+	break;
+    }
+  g_list_free (cells);
+
+  return sensitive;
+}
+
+static void
+update_menu_sensitivity (GtkComboBox *combo_box,
+			 GtkWidget   *menu)
+{
+  GtkComboBoxPrivate *priv = combo_box->priv;
+  GList *children, *child;
+  GtkWidget *item, *submenu, *separator;
+  GtkWidget *cell_view;
+  gboolean sensitive;
+
+  if (!priv->model)
+    return;
+
+  children = gtk_container_get_children (GTK_CONTAINER (menu));
+
+  for (child = children; child; child = child->next)
+    {
+      item = GTK_WIDGET (child->data);
+      cell_view = gtk_bin_get_child (GTK_BIN (item));
+
+      if (!GTK_IS_CELL_VIEW (cell_view))
+	continue;
+      
+      submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (item));
+      if (submenu != NULL)
+	{
+	  gtk_widget_set_sensitive (item, TRUE);
+	  update_menu_sensitivity (combo_box, submenu);
+	}
+      else
+	{
+	  sensitive = cell_view_is_sensitive (GTK_CELL_VIEW (cell_view));
+
+	  if (menu != priv->popup_widget && child == children)
+	    {
+	      separator = GTK_WIDGET (child->next->data);
+	      g_object_set (item, "visible", sensitive, NULL);
+	      g_object_set (separator, "visible", sensitive, NULL);
+	    }
+	  else
+	    gtk_widget_set_sensitive (item, sensitive);
+	}
+    }
+
+  g_list_free (children);
+}
+
 static void 
 gtk_combo_box_menu_popup (GtkComboBox *combo_box,
 			  guint        button, 
@@ -3098,6 +2089,8 @@ gtk_combo_box_menu_popup (GtkComboBox *combo_box,
   gint active_item;
   gint width, min_width, nat_width;
   
+  update_menu_sensitivity (combo_box, priv->popup_widget);
+
   active_item = -1;
   if (gtk_tree_row_reference_valid (priv->active_row))
     {
@@ -3164,6 +2157,423 @@ popup_grab_on_window (GdkWindow *window,
   return TRUE;
 }
 
+/**
+ * gtk_combo_box_popup:
+ * @combo_box: a #GtkComboBox
+ * 
+ * Pops up the menu or dropdown list of @combo_box. 
+ *
+ * This function is mostly intended for use by accessibility technologies;
+ * applications should have little use for it.
+ *
+ * Since: 2.4
+ */
+void
+gtk_combo_box_popup (GtkComboBox *combo_box)
+{
+  g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
+
+  g_signal_emit (combo_box, combo_box_signals[POPUP], 0);
+}
+
+/**
+ * gtk_combo_box_popup_for_device:
+ * @combo_box: a #GtkComboBox
+ * @device: a #GdkDevice
+ *
+ * Pops up the menu or dropdown list of @combo_box, the popup window
+ * will be grabbed so only @device and its associated pointer/keyboard
+ * are the only #GdkDevice<!-- -->s able to send events to it.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_combo_box_popup_for_device (GtkComboBox *combo_box,
+                                GdkDevice   *device)
+{
+  GtkComboBoxPrivate *priv = combo_box->priv;
+  gint x, y, width, height;
+  GtkTreePath *path = NULL, *ppath;
+  GtkWidget *toplevel;
+  GdkDevice *keyboard, *pointer;
+  guint32 time;
+
+  g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
+  g_return_if_fail (GDK_IS_DEVICE (device));
+
+  if (!gtk_widget_get_realized (GTK_WIDGET (combo_box)))
+    return;
+
+  if (gtk_widget_get_mapped (priv->popup_widget))
+    return;
+
+  if (priv->grab_pointer && priv->grab_keyboard)
+    return;
+
+  time = gtk_get_current_event_time ();
+
+  if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
+    {
+      keyboard = device;
+      pointer = gdk_device_get_associated_device (device);
+    }
+  else
+    {
+      pointer = device;
+      keyboard = gdk_device_get_associated_device (device);
+    }
+
+  if (GTK_IS_MENU (priv->popup_widget))
+    {
+      gtk_combo_box_menu_popup (combo_box, 
+                                priv->activate_button,
+                                priv->activate_time);
+      return;
+    }
+
+  toplevel = gtk_widget_get_toplevel (GTK_WIDGET (combo_box));
+  if (GTK_IS_WINDOW (toplevel))
+    gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)), 
+				 GTK_WINDOW (priv->popup_window));
+
+  gtk_widget_show_all (priv->scrolled_window);
+  gtk_combo_box_list_position (combo_box, &x, &y, &width, &height);
+  
+  gtk_widget_set_size_request (priv->popup_window, width, height);  
+  gtk_window_move (GTK_WINDOW (priv->popup_window), x, y);
+
+  if (gtk_tree_row_reference_valid (priv->active_row))
+    {
+      path = gtk_tree_row_reference_get_path (priv->active_row);
+      ppath = gtk_tree_path_copy (path);
+      if (gtk_tree_path_up (ppath))
+	gtk_tree_view_expand_to_path (GTK_TREE_VIEW (priv->tree_view),
+				      ppath);
+      gtk_tree_path_free (ppath);
+    }
+  gtk_tree_view_set_hover_expand (GTK_TREE_VIEW (priv->tree_view), 
+				  TRUE);
+  
+  /* popup */
+  gtk_widget_show (priv->popup_window);
+
+  if (path)
+    {
+      gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->tree_view),
+				path, NULL, FALSE);
+      gtk_tree_path_free (path);
+    }
+
+  gtk_widget_grab_focus (priv->popup_window);
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->button),
+                                TRUE);
+
+  if (!gtk_widget_has_focus (priv->tree_view))
+    gtk_widget_grab_focus (priv->tree_view);
+
+  if (!popup_grab_on_window (gtk_widget_get_window (priv->popup_window),
+			     keyboard, pointer, time))
+    {
+      gtk_widget_hide (priv->popup_window);
+      return;
+    }
+
+  gtk_device_grab_add (priv->popup_window, pointer, TRUE);
+  priv->grab_pointer = pointer;
+  priv->grab_keyboard = keyboard;
+}
+
+static void
+gtk_combo_box_real_popup (GtkComboBox *combo_box)
+{
+  GdkDevice *device;
+
+  device = gtk_get_current_event_device ();
+
+  if (!device)
+    {
+      GdkDeviceManager *device_manager;
+      GdkDisplay *display;
+      GList *devices;
+
+      display = gtk_widget_get_display (GTK_WIDGET (combo_box));
+      device_manager = gdk_display_get_device_manager (display);
+
+      /* No device was set, pick the first master device */
+      devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
+      device = devices->data;
+      g_list_free (devices);
+    }
+
+  gtk_combo_box_popup_for_device (combo_box, device);
+}
+
+static gboolean
+gtk_combo_box_real_popdown (GtkComboBox *combo_box)
+{
+  if (combo_box->priv->popup_shown)
+    {
+      gtk_combo_box_popdown (combo_box);
+      return TRUE;
+    }
+
+  return FALSE;
+}
+
+/**
+ * gtk_combo_box_popdown:
+ * @combo_box: a #GtkComboBox
+ * 
+ * Hides the menu or dropdown list of @combo_box.
+ *
+ * This function is mostly intended for use by accessibility technologies;
+ * applications should have little use for it.
+ *
+ * Since: 2.4
+ */
+void
+gtk_combo_box_popdown (GtkComboBox *combo_box)
+{
+  GtkComboBoxPrivate *priv = combo_box->priv;
+
+  g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
+
+  if (GTK_IS_MENU (priv->popup_widget))
+    {
+      gtk_menu_popdown (GTK_MENU (priv->popup_widget));
+      return;
+    }
+
+  if (!gtk_widget_get_realized (GTK_WIDGET (combo_box)))
+    return;
+
+  gtk_device_grab_remove (priv->popup_window, priv->grab_pointer);
+  gtk_widget_hide (priv->popup_window);
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->button),
+                                FALSE);
+
+  priv->grab_pointer = NULL;
+  priv->grab_keyboard = NULL;
+}
+
+#define GTK_COMBO_BOX_SIZE_ALLOCATE_BUTTON 					\
+  gtk_widget_get_preferred_size (combo_box->priv->button,	                \
+                                 &req, NULL); 					\
+  										\
+  if (is_rtl) 									\
+    child.x = allocation->x + border.right;					\
+  else										\
+    child.x = allocation->x + allocation->width - req.width - border.left;	\
+    										\
+  child.y = allocation->y + border.top;						\
+  child.width = req.width;							\
+  child.height = allocation->height - (border.top + border.bottom);		\
+  child.width = MAX (1, child.width);						\
+  child.height = MAX (1, child.height);						\
+  										\
+  gtk_widget_size_allocate (combo_box->priv->button, &child);
+
+
+static void
+gtk_combo_box_size_allocate (GtkWidget     *widget,
+                             GtkAllocation *allocation)
+{
+  GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
+  GtkComboBoxPrivate *priv = combo_box->priv;
+  GtkWidget *child_widget;
+  gint focus_width, focus_pad;
+  GtkAllocation child;
+  GtkRequisition req;
+  gboolean is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
+  GtkBorder border;
+
+  gtk_widget_set_allocation (widget, allocation);
+  child_widget = gtk_bin_get_child (GTK_BIN (widget));
+  get_widget_border (widget, &border);
+
+  gtk_widget_style_get (widget,
+			"focus-line-width", &focus_width,
+			"focus-padding", &focus_pad,
+			NULL);
+
+  if (!priv->tree_view)
+    {
+      if (priv->cell_view)
+        {
+	  GtkBorder button_border;
+          gint width;
+          guint border_width;
+
+          /* menu mode */
+          allocation->x += border.left;
+          allocation->y += border.top;
+          allocation->width -= border.left + border.right;
+          allocation->height -= border.top + border.bottom;
+
+          gtk_widget_size_allocate (priv->button, allocation);
+
+          /* set some things ready */
+          border_width = gtk_container_get_border_width (GTK_CONTAINER (priv->button));
+	  get_widget_border (priv->button, &button_border);
+
+          child.x = allocation->x;
+          child.y = allocation->y;
+	  width = allocation->width;
+	  child.height = allocation->height;
+
+	  if (!priv->is_cell_renderer)
+	    {
+	      child.x += border_width + button_border.left + focus_width + focus_pad;
+	      child.y += border_width + button_border.top + focus_width + focus_pad;
+	      width -= (2 * (border_width + focus_width + focus_pad)) +
+                button_border.left + button_border.right;
+	      child.height -= (2 * (border_width + focus_width + focus_pad)) +
+                button_border.top + button_border.bottom;
+	    }
+
+          /* handle the children */
+          gtk_widget_get_preferred_size (priv->arrow, &req, NULL);
+          child.width = req.width;
+          if (!is_rtl)
+            child.x += width - req.width;
+	  child.width = MAX (1, child.width);
+	  child.height = MAX (1, child.height);
+          gtk_widget_size_allocate (priv->arrow, &child);
+          if (is_rtl)
+            child.x += req.width;
+          gtk_widget_get_preferred_size (priv->separator, &req, NULL);
+          child.width = req.width;
+          if (!is_rtl)
+            child.x -= req.width;
+	  child.width = MAX (1, child.width);
+	  child.height = MAX (1, child.height);
+          gtk_widget_size_allocate (priv->separator, &child);
+
+          if (is_rtl)
+            {
+              child.x += req.width;
+              child.width = allocation->x + allocation->width 
+                - (border_width + button_border.right + focus_width + focus_pad) 
+		- child.x;
+            }
+          else 
+            {
+              child.width = child.x;
+              child.x = allocation->x 
+		+ border_width + button_border.left + focus_width + focus_pad;
+              child.width -= child.x;
+            }
+
+          if (gtk_widget_get_visible (priv->popup_widget))
+            {
+              gint width, menu_width;
+
+              if (priv->wrap_width == 0)
+                {
+                  GtkAllocation combo_box_allocation;
+
+                  gtk_widget_get_allocation (GTK_WIDGET (combo_box), &combo_box_allocation);
+                  width = combo_box_allocation.width;
+                  gtk_widget_set_size_request (priv->popup_widget, -1, -1);
+
+		  if (combo_box->priv->popup_fixed_width)
+		    gtk_widget_get_preferred_width (priv->popup_widget, &menu_width, NULL);
+		  else
+		    gtk_widget_get_preferred_width (priv->popup_widget, NULL, &menu_width);
+
+                  gtk_widget_set_size_request (priv->popup_widget,
+					       MAX (width, menu_width), -1);
+               }
+
+              /* reposition the menu after giving it a new width */
+              gtk_menu_reposition (GTK_MENU (priv->popup_widget));
+            }
+
+	  child.width = MAX (1, child.width);
+	  child.height = MAX (1, child.height);
+          gtk_widget_size_allocate (child_widget, &child);
+        }
+      else
+        {
+          GTK_COMBO_BOX_SIZE_ALLOCATE_BUTTON
+
+          if (is_rtl)
+            child.x = allocation->x + req.width + border.right;
+          else
+            child.x = allocation->x + border.left;
+          child.y = allocation->y + border.top;
+          child.width = allocation->width - req.width - (border.left + border.right);
+	  child.width = MAX (1, child.width);
+	  child.height = MAX (1, child.height);
+          gtk_widget_size_allocate (child_widget, &child);
+        }
+    }
+  else
+    {
+      /* list mode */
+      guint border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
+
+      /* button */
+      GTK_COMBO_BOX_SIZE_ALLOCATE_BUTTON
+
+      /* frame */
+      if (is_rtl)
+        child.x = allocation->x + req.width;
+      else
+        child.x = allocation->x;
+
+      child.y = allocation->y;
+      child.width = allocation->width - req.width;
+      child.height = allocation->height;
+
+      if (priv->cell_view_frame)
+        {
+          child.x += border.left + border_width;
+          child.y += border.top + border_width;
+          child.width = MAX (1, child.width - (2 * border_width) - (border.left + border.right));
+          child.height = MAX (1, child.height - (2 * border_width) - (border.top + border.bottom));
+          gtk_widget_size_allocate (priv->cell_view_frame, &child);
+
+          /* the sample */
+          if (priv->has_frame)
+            {
+	      GtkBorder frame_border;
+
+              border_width = gtk_container_get_border_width (GTK_CONTAINER (priv->cell_view_frame));
+	      get_widget_border (priv->cell_view_frame, &frame_border);
+
+              child.x += border_width + frame_border.left;
+              child.y += border_width + frame_border.right;
+              child.width -= (2 * border_width) + frame_border.left + frame_border.right;
+              child.height -= (2 * border_width) + frame_border.top + frame_border.bottom;
+            }
+        }
+      else
+        {
+          child.x += border.left + border_width;
+          child.y += border.top + border_width;
+          child.width -= (2 * border_width) - (border.left + border.right);
+          child.height -= (2 * border_width) - (border.top + border.bottom);
+        }
+
+      if (gtk_widget_get_visible (priv->popup_window))
+        {
+          gint x, y, width, height;
+          gtk_combo_box_list_position (combo_box, &x, &y, &width, &height);
+          gtk_window_move (GTK_WINDOW (priv->popup_window), x, y);
+          gtk_widget_set_size_request (priv->popup_window, width, height);
+        }
+
+      
+      child.width = MAX (1, child.width);
+      child.height = MAX (1, child.height);
+      
+      gtk_widget_size_allocate (child_widget, &child);
+    }
+}
+
+#undef GTK_COMBO_BOX_ALLOCATE_BUTTON
+
 static void
 gtk_combo_box_unset_model (GtkComboBox *combo_box)
 {
@@ -3175,7 +2585,14 @@ gtk_combo_box_unset_model (GtkComboBox *combo_box)
 				   priv->inserted_id);
       g_signal_handler_disconnect (priv->model,
 				   priv->deleted_id);
+      g_signal_handler_disconnect (priv->model,
+				   priv->reordered_id);
+      g_signal_handler_disconnect (priv->model,
+				   priv->changed_id);
+    }
 
+  if (priv->model)
+    {
       g_object_unref (priv->model);
       priv->model = NULL;
     }
@@ -3190,6 +2607,29 @@ gtk_combo_box_unset_model (GtkComboBox *combo_box)
     gtk_cell_view_set_model (GTK_CELL_VIEW (priv->cell_view), NULL);
 }
 
+static void
+gtk_combo_box_forall (GtkContainer *container,
+                      gboolean      include_internals,
+                      GtkCallback   callback,
+                      gpointer      callback_data)
+{
+  GtkComboBox *combo_box = GTK_COMBO_BOX (container);
+  GtkComboBoxPrivate *priv = combo_box->priv;
+  GtkWidget *child;
+
+  if (include_internals)
+    {
+      if (priv->button)
+	(* callback) (priv->button, callback_data);
+      if (priv->cell_view_frame)
+	(* callback) (priv->cell_view_frame, callback_data);
+    }
+
+  child = gtk_bin_get_child (GTK_BIN (container));
+  if (child)
+    (* callback) (child, callback_data);
+}
+
 static void 
 gtk_combo_box_child_show (GtkWidget *widget,
                           GtkComboBox *combo_box)
@@ -3210,6 +2650,279 @@ gtk_combo_box_child_hide (GtkWidget *widget,
   g_object_notify (G_OBJECT (combo_box), "popup-shown");
 }
 
+static gboolean
+gtk_combo_box_draw (GtkWidget *widget,
+                    cairo_t   *cr)
+{
+  GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
+  GtkComboBoxPrivate *priv = combo_box->priv;
+
+  if (priv->shadow_type != GTK_SHADOW_NONE)
+    {
+      GtkStyleContext *context;
+      GtkStateFlags state;
+
+      context = gtk_widget_get_style_context (widget);
+      state = gtk_widget_get_state_flags (widget);
+      gtk_style_context_set_state (context, state);
+
+      gtk_render_background (context, cr, 0, 0,
+                             gtk_widget_get_allocated_width (widget),
+                             gtk_widget_get_allocated_height (widget));
+      gtk_render_frame (context, cr, 0, 0,
+                        gtk_widget_get_allocated_width (widget),
+                        gtk_widget_get_allocated_height (widget));
+    }
+
+  gtk_container_propagate_draw (GTK_CONTAINER (widget),
+				priv->button, cr);
+
+  if (priv->tree_view && priv->cell_view_frame)
+    {
+      gtk_container_propagate_draw (GTK_CONTAINER (widget),
+				    priv->cell_view_frame, cr);
+    }
+
+  gtk_container_propagate_draw (GTK_CONTAINER (widget),
+                                gtk_bin_get_child (GTK_BIN (widget)),
+                                cr);
+
+  return FALSE;
+}
+
+typedef struct {
+  GtkComboBox *combo;
+  GtkTreePath *path;
+  GtkTreeIter iter;
+  gboolean found;
+  gboolean set;
+  gboolean visible;
+} SearchData;
+
+static gboolean
+path_visible (GtkTreeView *view,
+	      GtkTreePath *path)
+{
+  GtkRBTree *tree;
+  GtkRBNode *node;
+  
+  /* Note that we rely on the fact that collapsed rows don't have nodes 
+   */
+  return _gtk_tree_view_find_node (view, path, &tree, &node);
+}
+
+static gboolean
+tree_next_func (GtkTreeModel *model,
+		GtkTreePath  *path,
+		GtkTreeIter  *iter,
+		gpointer      data)
+{
+  SearchData *search_data = (SearchData *)data;
+
+  if (search_data->found) 
+    {
+      if (!tree_column_row_is_sensitive (search_data->combo, iter))
+	return FALSE;
+      
+      if (search_data->visible &&
+	  !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
+	return FALSE;
+
+      search_data->set = TRUE;
+      search_data->iter = *iter;
+
+      return TRUE;
+    }
+ 
+  if (gtk_tree_path_compare (path, search_data->path) == 0)
+    search_data->found = TRUE;
+  
+  return FALSE;
+}
+
+static gboolean
+tree_next (GtkComboBox  *combo,
+	   GtkTreeModel *model,
+	   GtkTreeIter  *iter,
+	   GtkTreeIter  *next,
+	   gboolean      visible)
+{
+  SearchData search_data;
+
+  search_data.combo = combo;
+  search_data.path = gtk_tree_model_get_path (model, iter);
+  search_data.visible = visible;
+  search_data.found = FALSE;
+  search_data.set = FALSE;
+
+  gtk_tree_model_foreach (model, tree_next_func, &search_data);
+  
+  *next = search_data.iter;
+
+  gtk_tree_path_free (search_data.path);
+
+  return search_data.set;
+}
+
+static gboolean
+tree_prev_func (GtkTreeModel *model,
+		GtkTreePath  *path,
+		GtkTreeIter  *iter,
+		gpointer      data)
+{
+  SearchData *search_data = (SearchData *)data;
+
+  if (gtk_tree_path_compare (path, search_data->path) == 0)
+    {
+      search_data->found = TRUE;
+      return TRUE;
+    }
+  
+  if (!tree_column_row_is_sensitive (search_data->combo, iter))
+    return FALSE;
+      
+  if (search_data->visible &&
+      !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
+    return FALSE; 
+  
+  search_data->set = TRUE;
+  search_data->iter = *iter;
+  
+  return FALSE; 
+}
+
+static gboolean
+tree_prev (GtkComboBox  *combo,
+	   GtkTreeModel *model,
+	   GtkTreeIter  *iter,
+	   GtkTreeIter  *prev,
+	   gboolean      visible)
+{
+  SearchData search_data;
+
+  search_data.combo = combo;
+  search_data.path = gtk_tree_model_get_path (model, iter);
+  search_data.visible = visible;
+  search_data.found = FALSE;
+  search_data.set = FALSE;
+
+  gtk_tree_model_foreach (model, tree_prev_func, &search_data);
+  
+  *prev = search_data.iter;
+
+  gtk_tree_path_free (search_data.path);
+
+  return search_data.set;
+}
+
+static gboolean
+tree_last_func (GtkTreeModel *model,
+		GtkTreePath  *path,
+		GtkTreeIter  *iter,
+		gpointer      data)
+{
+  SearchData *search_data = (SearchData *)data;
+
+  if (!tree_column_row_is_sensitive (search_data->combo, iter))
+    return FALSE;
+      
+  /* Note that we rely on the fact that collapsed rows don't have nodes 
+   */
+  if (search_data->visible &&
+      !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
+    return FALSE; 
+  
+  search_data->set = TRUE;
+  search_data->iter = *iter;
+  
+  return FALSE; 
+}
+
+static gboolean
+tree_last (GtkComboBox  *combo,
+	   GtkTreeModel *model,
+	   GtkTreeIter  *last,
+	   gboolean      visible)
+{
+  SearchData search_data;
+
+  search_data.combo = combo;
+  search_data.visible = visible;
+  search_data.set = FALSE;
+
+  gtk_tree_model_foreach (model, tree_last_func, &search_data);
+  
+  *last = search_data.iter;
+
+  return search_data.set;  
+}
+
+
+static gboolean
+tree_first_func (GtkTreeModel *model,
+		 GtkTreePath  *path,
+		 GtkTreeIter  *iter,
+		 gpointer      data)
+{
+  SearchData *search_data = (SearchData *)data;
+
+  if (!tree_column_row_is_sensitive (search_data->combo, iter))
+    return FALSE;
+  
+  if (search_data->visible &&
+      !path_visible (GTK_TREE_VIEW (search_data->combo->priv->tree_view), path))
+    return FALSE;
+  
+  search_data->set = TRUE;
+  search_data->iter = *iter;
+  
+  return TRUE;
+}
+
+static gboolean
+tree_first (GtkComboBox  *combo,
+	    GtkTreeModel *model,
+	    GtkTreeIter  *first,
+	    gboolean      visible)
+{
+  SearchData search_data;
+  
+  search_data.combo = combo;
+  search_data.visible = visible;
+  search_data.set = FALSE;
+
+  gtk_tree_model_foreach (model, tree_first_func, &search_data);
+  
+  *first = search_data.iter;
+
+  return search_data.set;  
+}
+
+static gboolean
+gtk_combo_box_scroll_event (GtkWidget          *widget,
+                            GdkEventScroll     *event)
+{
+  GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
+  gboolean found;
+  GtkTreeIter iter;
+  GtkTreeIter new_iter;
+
+  if (!gtk_combo_box_get_active_iter (combo_box, &iter))
+    return TRUE;
+  
+  if (event->direction == GDK_SCROLL_UP)
+    found = tree_prev (combo_box, combo_box->priv->model, 
+		       &iter, &new_iter, FALSE);
+  else
+    found = tree_next (combo_box, combo_box->priv->model, 
+		       &iter, &new_iter, FALSE);
+  
+  if (found)
+    gtk_combo_box_set_active_iter (combo_box, &new_iter);
+
+  return TRUE;
+}
+
 /*
  * menu style
  */
@@ -3239,21 +2952,6 @@ gtk_combo_box_header_func (GtkTreeModel      *model,
 }
 
 static void
-gtk_combo_box_menu_activate (GtkWidget   *menu,
-			     const gchar *path,
-			     GtkComboBox *combo_box)
-{
-  GtkTreeIter iter;
-
-  if (gtk_tree_model_get_iter_from_string (combo_box->priv->model, &iter, path))
-    gtk_combo_box_set_active_iter (combo_box, &iter);
-
-  g_object_set (combo_box,
-                "editing-canceled", FALSE,
-                NULL);
-}
-
-static void
 gtk_combo_box_menu_setup (GtkComboBox *combo_box,
                           gboolean     add_children)
 {
@@ -3304,12 +3002,14 @@ gtk_combo_box_menu_setup (GtkComboBox *combo_box,
   g_signal_connect (priv->button, "button-press-event",
                     G_CALLBACK (gtk_combo_box_menu_button_press),
                     combo_box);
-  g_signal_connect (priv->button, "state-changed",
-		    G_CALLBACK (gtk_combo_box_button_state_changed), 
+  g_signal_connect (priv->button, "state-flags-changed",
+		    G_CALLBACK (gtk_combo_box_button_state_flags_changed), 
 		    combo_box);
 
   /* create our funky menu */
   menu = gtk_tree_menu_new_with_area (priv->area);
+  gtk_widget_set_name (menu, "gtk-combobox-popup-menu");
+
   gtk_tree_menu_set_model (GTK_TREE_MENU (menu), priv->model);
 
   gtk_tree_menu_set_wrap_width (GTK_TREE_MENU (menu), priv->wrap_width);
@@ -3351,7 +3051,7 @@ gtk_combo_box_menu_destroy (GtkComboBox *combo_box)
   g_signal_handlers_disconnect_matched (priv->button,
                                         G_SIGNAL_MATCH_DATA,
                                         0, 0, NULL,
-                                        gtk_combo_box_button_state_changed, combo_box);
+                                        gtk_combo_box_button_state_flags_changed, combo_box);
   g_signal_handlers_disconnect_matched (priv->popup_widget,
                                         G_SIGNAL_MATCH_DATA,
                                         0, 0, NULL,
@@ -3395,6 +3095,22 @@ gtk_combo_box_menu_button_press (GtkWidget      *widget,
 }
 
 static void
+gtk_combo_box_menu_activate (GtkWidget   *menu,
+			     const gchar *path,
+			     GtkComboBox *combo_box)
+{
+  GtkTreeIter iter;
+
+  if (gtk_tree_model_get_iter_from_string (combo_box->priv->model, &iter, path))
+    gtk_combo_box_set_active_iter (combo_box, &iter);
+
+  g_object_set (combo_box,
+                "editing-canceled", FALSE,
+                NULL);
+}
+
+
+static void
 gtk_combo_box_update_sensitivity (GtkComboBox *combo_box)
 {
   GtkTreeIter iter;
@@ -3428,6 +3144,75 @@ gtk_combo_box_update_sensitivity (GtkComboBox *combo_box)
     gtk_widget_set_sensitive (combo_box->priv->box, sensitive);
 }
 
+static void
+gtk_combo_box_model_row_inserted (GtkTreeModel     *model,
+				  GtkTreePath      *path,
+				  GtkTreeIter      *iter,
+				  gpointer          user_data)
+{
+  GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
+
+  if (combo_box->priv->tree_view)
+    gtk_combo_box_list_popup_resize (combo_box);
+
+  gtk_combo_box_update_sensitivity (combo_box);
+}
+
+static void
+gtk_combo_box_model_row_deleted (GtkTreeModel     *model,
+				 GtkTreePath      *path,
+				 gpointer          user_data)
+{
+  GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
+  GtkComboBoxPrivate *priv = combo_box->priv;
+
+  if (!gtk_tree_row_reference_valid (priv->active_row))
+    {
+      if (priv->cell_view)
+	gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (priv->cell_view), NULL);
+      g_signal_emit (combo_box, combo_box_signals[CHANGED], 0);
+    }
+  
+  if (priv->tree_view)
+    gtk_combo_box_list_popup_resize (combo_box);
+
+  gtk_combo_box_update_sensitivity (combo_box);
+}
+
+static void
+gtk_combo_box_model_rows_reordered (GtkTreeModel    *model,
+				    GtkTreePath     *path,
+				    GtkTreeIter     *iter,
+				    gint            *new_order,
+				    gpointer         user_data)
+{
+  gtk_tree_row_reference_reordered (G_OBJECT (user_data), path, iter, new_order);
+}
+						    
+static void
+gtk_combo_box_model_row_changed (GtkTreeModel     *model,
+				 GtkTreePath      *path,
+				 GtkTreeIter      *iter,
+				 gpointer          user_data)
+{
+  GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
+  GtkComboBoxPrivate *priv = combo_box->priv;
+  GtkTreePath *active_path;
+
+  /* FIXME this belongs to GtkCellView */
+  if (gtk_tree_row_reference_valid (priv->active_row))
+    {
+      active_path = gtk_tree_row_reference_get_path (priv->active_row);
+      if (gtk_tree_path_compare (path, active_path) == 0 &&
+	  priv->cell_view)
+	gtk_widget_queue_resize (GTK_WIDGET (priv->cell_view));
+      gtk_tree_path_free (active_path);
+    }
+      
+  if (priv->tree_view)
+    gtk_combo_box_list_row_changed (model, path, iter, user_data);
+}
+
 static gboolean
 list_popup_resize_idle (gpointer user_data)
 {
@@ -3469,6 +3254,7 @@ gtk_combo_box_model_row_expanded (GtkTreeModel     *model,
   gtk_combo_box_list_popup_resize (combo_box);
 }
 
+
 /*
  * list style
  */
@@ -3552,10 +3338,11 @@ gtk_combo_box_list_setup (GtkComboBox *combo_box)
   gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (priv->tree_view), 
 					(GtkTreeViewRowSeparatorFunc)gtk_combo_box_row_separator_func,
 					combo_box, NULL);
+
   if (priv->model)
     gtk_tree_view_set_model (GTK_TREE_VIEW (priv->tree_view), priv->model);
     
-  priv->column = gtk_tree_view_column_new ();
+  priv->column = gtk_tree_view_column_new_with_area (priv->area);
   gtk_tree_view_append_column (GTK_TREE_VIEW (priv->tree_view), priv->column);
 
   if (gtk_tree_row_reference_valid (priv->active_row))
@@ -3974,221 +3761,22 @@ gtk_combo_box_list_select_func (GtkTreeSelection *selection,
   return sensitive;
 }
 
-
-/*
- * GtkCellEditable implementation
- */
-
 static void
-gtk_combo_box_cell_editable_init (GtkCellEditableIface *iface)
+gtk_combo_box_list_row_changed (GtkTreeModel *model,
+                                GtkTreePath  *path,
+                                GtkTreeIter  *iter,
+                                gpointer      data)
 {
-  iface->start_editing = gtk_combo_box_start_editing;
-}
-
-static gboolean
-gtk_cell_editable_key_press (GtkWidget   *widget,
-			     GdkEventKey *event,
-			     gpointer     data)
-{
-  GtkComboBox *combo_box = GTK_COMBO_BOX (data);
-
-  if (event->keyval == GDK_KEY_Escape)
-    {
-      g_object_set (combo_box,
-                    "editing-canceled", TRUE,
-                    NULL);
-      gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (combo_box));
-      gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (combo_box));
-      
-      return TRUE;
-    }
-  else if (event->keyval == GDK_KEY_Return ||
-           event->keyval == GDK_KEY_ISO_Enter ||
-           event->keyval == GDK_KEY_KP_Enter)
-    {
-      gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (combo_box));
-      gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (combo_box));
-      
-      return TRUE;
-    }
-
-  return FALSE;
-}
-
-static gboolean
-popdown_idle (gpointer data)
-{
-  GtkComboBox *combo_box;
-
-  combo_box = GTK_COMBO_BOX (data);
-  
-  gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (combo_box));
-  gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (combo_box));
-
-  g_object_unref (combo_box);
-
-  return FALSE;
-}
-
-static void
-popdown_handler (GtkWidget *widget,
-		 gpointer   data)
-{
-  gdk_threads_add_idle (popdown_idle, g_object_ref (data));
-}
-
-static gboolean
-popup_idle (gpointer data)
-{
-  GtkComboBox *combo_box;
-
-  combo_box = GTK_COMBO_BOX (data);
-
-  if (GTK_IS_MENU (combo_box->priv->popup_widget) &&
-      combo_box->priv->cell_view)
-    g_signal_connect_object (combo_box->priv->popup_widget,
-			     "unmap", G_CALLBACK (popdown_handler),
-			     combo_box, 0);
-  
-  /* we unset this if a menu item is activated */
-  g_object_set (combo_box,
-                "editing-canceled", TRUE,
-                NULL);
-  gtk_combo_box_popup (combo_box);
-
-  combo_box->priv->popup_idle_id = 0;
-  combo_box->priv->activate_button = 0;
-  combo_box->priv->activate_time = 0;
-
-  return FALSE;
-}
-
-static void
-gtk_combo_box_start_editing (GtkCellEditable *cell_editable,
-			     GdkEvent        *event)
-{
-  GtkComboBox *combo_box = GTK_COMBO_BOX (cell_editable);
-  GtkWidget *child;
-
-  combo_box->priv->is_cell_renderer = TRUE;
-
-  if (combo_box->priv->cell_view)
-    {
-      g_signal_connect_object (combo_box->priv->button, "key-press-event",
-			       G_CALLBACK (gtk_cell_editable_key_press), 
-			       cell_editable, 0);  
-
-      gtk_widget_grab_focus (combo_box->priv->button);
-    }
-  else
-    {
-      child = gtk_bin_get_child (GTK_BIN (combo_box));
-
-      g_signal_connect_object (child, "key-press-event",
-			       G_CALLBACK (gtk_cell_editable_key_press), 
-			       cell_editable, 0);  
-
-      gtk_widget_grab_focus (child);
-      gtk_widget_set_can_focus (combo_box->priv->button, FALSE);
-    }
-
-  /* we do the immediate popup only for the optionmenu-like 
-   * appearance 
-   */  
-  if (combo_box->priv->is_cell_renderer && 
-      combo_box->priv->cell_view && !combo_box->priv->tree_view)
-    {
-      if (event && event->type == GDK_BUTTON_PRESS)
-        {
-          GdkEventButton *event_button = (GdkEventButton *)event;
-
-          combo_box->priv->activate_button = event_button->button;
-          combo_box->priv->activate_time = event_button->time;
-        }
-
-      combo_box->priv->popup_idle_id = 
-          gdk_threads_add_idle (popup_idle, combo_box);
-    }
+  /* XXX Do nothing ? */
 }
 
-
 /*
  * GtkCellLayout implementation
  */
-
-static void
-gtk_combo_box_cell_layout_init (GtkCellLayoutIface *iface)
-{
-  iface->get_area = gtk_combo_box_cell_layout_get_area;
-}
-
-static GtkCellArea *
-gtk_combo_box_cell_layout_get_area (GtkCellLayout *layout)
+GtkCellArea *
+gtk_combo_box_cell_layout_get_area (GtkCellLayout    *cell_layout)
 {
-  GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
-  GtkComboBoxPrivate *priv;
-
-  priv = combo_box->priv;
-
-  return priv->area;
-}
-
-/*
- * GtkBuildable implementation
- */
-
-static void
-gtk_combo_box_buildable_init (GtkBuildableIface *iface)
-{
-  parent_buildable_iface = g_type_interface_peek_parent (iface);
-  iface->add_child = _gtk_cell_layout_buildable_add_child;
-  iface->custom_tag_start = gtk_combo_box_buildable_custom_tag_start;
-  iface->custom_tag_end = gtk_combo_box_buildable_custom_tag_end;
-  iface->get_internal_child = gtk_combo_box_buildable_get_internal_child;
-}
-
-static gboolean
-gtk_combo_box_buildable_custom_tag_start (GtkBuildable  *buildable,
-					  GtkBuilder    *builder,
-					  GObject       *child,
-					  const gchar   *tagname,
-					  GMarkupParser *parser,
-					  gpointer      *data)
-{
-  if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
-						tagname, parser, data))
-    return TRUE;
-
-  return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
-						      tagname, parser, data);
-}
-
-static void
-gtk_combo_box_buildable_custom_tag_end (GtkBuildable *buildable,
-					GtkBuilder   *builder,
-					GObject      *child,
-					const gchar  *tagname,
-					gpointer     *data)
-{
-  if (_gtk_cell_layout_buildable_custom_tag_end (buildable, builder, child, tagname,
-						 data))
-    return;
-  else
-    parent_buildable_iface->custom_tag_end (buildable, builder, child, tagname,
-					    data);
-}
-
-static GObject *
-gtk_combo_box_buildable_get_internal_child (GtkBuildable *buildable,
-					    GtkBuilder   *builder,
-					    const gchar  *childname)
-{
-  GtkComboBox *combo_box = GTK_COMBO_BOX (buildable);
-
-  if (combo_box->priv->has_entry && strcmp (childname, "entry") == 0)
-    return G_OBJECT (gtk_bin_get_child (GTK_BIN (buildable)));
-
-  return parent_buildable_iface->get_internal_child (buildable, builder, childname);
+  return GTK_COMBO_BOX (cell_layout)->priv->area;
 }
 
 /*
@@ -4367,7 +3955,7 @@ gtk_combo_box_set_row_span_column (GtkComboBox *combo_box,
 
       if (GTK_IS_TREE_MENU (priv->popup_widget))
 	gtk_tree_menu_set_row_span_column (GTK_TREE_MENU (priv->popup_widget), priv->row_column);
- 
+
       g_object_notify (G_OBJECT (combo_box), "row-span-column");
     }
 }
@@ -4672,7 +4260,15 @@ gtk_combo_box_set_model (GtkComboBox  *combo_box,
     g_signal_connect (combo_box->priv->model, "row-deleted",
 		      G_CALLBACK (gtk_combo_box_model_row_deleted),
 		      combo_box);
-
+  combo_box->priv->reordered_id =
+    g_signal_connect (combo_box->priv->model, "rows-reordered",
+		      G_CALLBACK (gtk_combo_box_model_rows_reordered),
+		      combo_box);
+  combo_box->priv->changed_id =
+    g_signal_connect (combo_box->priv->model, "row-changed",
+		      G_CALLBACK (gtk_combo_box_model_row_changed),
+		      combo_box);
+      
   if (combo_box->priv->tree_view)
     {
       /* list mode */
@@ -4700,6 +4296,8 @@ gtk_combo_box_set_model (GtkComboBox  *combo_box,
     }
 
 out:
+  gtk_combo_box_update_sensitivity (combo_box);
+
   g_object_notify (G_OBJECT (combo_box), "model");
 }
 
@@ -4723,6 +4321,151 @@ gtk_combo_box_get_model (GtkComboBox *combo_box)
 }
 
 static void
+gtk_combo_box_real_move_active (GtkComboBox   *combo_box,
+                                GtkScrollType  scroll)
+{
+  GtkTreeIter iter;
+  GtkTreeIter new_iter;
+  gboolean    active_iter;
+  gboolean    found;
+
+  if (!combo_box->priv->model)
+    {
+      gtk_widget_error_bell (GTK_WIDGET (combo_box));
+      return;
+    }
+
+  active_iter = gtk_combo_box_get_active_iter (combo_box, &iter);
+
+  switch (scroll)
+    {
+    case GTK_SCROLL_STEP_BACKWARD:
+    case GTK_SCROLL_STEP_UP:
+    case GTK_SCROLL_STEP_LEFT:
+      if (active_iter)
+        {
+	  found = tree_prev (combo_box, combo_box->priv->model,
+			     &iter, &new_iter, FALSE);
+	  break;
+        }
+      /* else fall through */
+
+    case GTK_SCROLL_PAGE_FORWARD:
+    case GTK_SCROLL_PAGE_DOWN:
+    case GTK_SCROLL_PAGE_RIGHT:
+    case GTK_SCROLL_END:
+      found = tree_last (combo_box, combo_box->priv->model, &new_iter, FALSE);
+      break;
+
+    case GTK_SCROLL_STEP_FORWARD:
+    case GTK_SCROLL_STEP_DOWN:
+    case GTK_SCROLL_STEP_RIGHT:
+      if (active_iter)
+        {
+	  found = tree_next (combo_box, combo_box->priv->model,
+			     &iter, &new_iter, FALSE);
+          break;
+        }
+      /* else fall through */
+
+    case GTK_SCROLL_PAGE_BACKWARD:
+    case GTK_SCROLL_PAGE_UP:
+    case GTK_SCROLL_PAGE_LEFT:
+    case GTK_SCROLL_START:
+      found = tree_first (combo_box, combo_box->priv->model, &new_iter, FALSE);
+      break;
+
+    default:
+      return;
+    }
+
+  if (found && active_iter)
+    {
+      GtkTreePath *old_path;
+      GtkTreePath *new_path;
+
+      old_path = gtk_tree_model_get_path (combo_box->priv->model, &iter);
+      new_path = gtk_tree_model_get_path (combo_box->priv->model, &new_iter);
+
+      if (gtk_tree_path_compare (old_path, new_path) == 0)
+        found = FALSE;
+
+      gtk_tree_path_free (old_path);
+      gtk_tree_path_free (new_path);
+    }
+
+  if (found)
+    {
+      gtk_combo_box_set_active_iter (combo_box, &new_iter);
+    }
+  else
+    {
+      gtk_widget_error_bell (GTK_WIDGET (combo_box));
+    }
+}
+
+static gboolean
+gtk_combo_box_mnemonic_activate (GtkWidget *widget,
+				 gboolean   group_cycling)
+{
+  GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
+
+  if (combo_box->priv->has_entry)
+    {
+      GtkWidget* child;
+
+      child = gtk_bin_get_child (GTK_BIN (combo_box));
+      if (child)
+	gtk_widget_grab_focus (child);
+    }
+  else
+    gtk_widget_grab_focus (combo_box->priv->button);
+
+  return TRUE;
+}
+
+static void
+gtk_combo_box_grab_focus (GtkWidget *widget)
+{
+  GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
+
+  if (combo_box->priv->has_entry)
+    {
+      GtkWidget *child;
+
+      child = gtk_bin_get_child (GTK_BIN (combo_box));
+      if (child)
+	gtk_widget_grab_focus (child);
+    }
+  else
+    gtk_widget_grab_focus (combo_box->priv->button);
+}
+
+static void
+gtk_combo_box_destroy (GtkWidget *widget)
+{
+  GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
+
+  if (combo_box->priv->popup_idle_id > 0)
+    {
+      g_source_remove (combo_box->priv->popup_idle_id);
+      combo_box->priv->popup_idle_id = 0;
+    }
+
+  gtk_combo_box_popdown (combo_box);
+
+  if (combo_box->priv->row_separator_destroy)
+    combo_box->priv->row_separator_destroy (combo_box->priv->row_separator_data);
+
+  combo_box->priv->row_separator_func = NULL;
+  combo_box->priv->row_separator_data = NULL;
+  combo_box->priv->row_separator_destroy = NULL;
+
+  GTK_WIDGET_CLASS (gtk_combo_box_parent_class)->destroy (widget);
+  combo_box->priv->cell_view = NULL;
+}
+
+static void
 gtk_combo_box_entry_contents_changed (GtkEntry *entry,
                                       gpointer  user_data)
 {
@@ -4773,6 +4516,232 @@ gtk_combo_box_entry_active_changed (GtkComboBox *combo_box,
     }
 }
 
+static GObject *
+gtk_combo_box_constructor (GType                  type,
+			   guint                  n_construct_properties,
+			   GObjectConstructParam *construct_properties)
+{
+  GObject            *object;
+  GtkComboBox        *combo_box;
+  GtkComboBoxPrivate *priv;
+  GtkStyleContext    *context;
+
+  object = G_OBJECT_CLASS (gtk_combo_box_parent_class)->constructor
+    (type, n_construct_properties, construct_properties);
+
+  combo_box = GTK_COMBO_BOX (object);
+  priv      = combo_box->priv;
+
+  if (!priv->area)
+    {
+      GtkCellArea *area = gtk_cell_area_box_new ();
+
+      priv->area = g_object_ref_sink (area);
+    }
+
+  priv->cell_view = gtk_cell_view_new_with_context (priv->area, NULL);
+  gtk_cell_view_set_fit_model (GTK_CELL_VIEW (priv->cell_view), TRUE);
+  gtk_cell_view_set_model (GTK_CELL_VIEW (priv->cell_view), priv->model);
+  gtk_widget_set_parent (priv->cell_view, GTK_WIDGET (combo_box));
+  _gtk_bin_set_child (GTK_BIN (combo_box), priv->cell_view);
+  gtk_widget_show (priv->cell_view);
+
+  gtk_combo_box_check_appearance (combo_box);
+
+  context = gtk_widget_get_style_context (GTK_WIDGET (combo_box));
+  gtk_style_context_add_class (context, GTK_STYLE_CLASS_BUTTON);
+
+  if (priv->has_entry)
+    {
+      GtkWidget *entry;
+
+      entry = gtk_entry_new ();
+      gtk_widget_show (entry);
+      gtk_container_add (GTK_CONTAINER (combo_box), entry);
+
+      priv->text_renderer = gtk_cell_renderer_text_new ();
+      gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box),
+				  priv->text_renderer, TRUE);
+
+      gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), -1);
+
+      g_signal_connect (combo_box, "changed",
+			G_CALLBACK (gtk_combo_box_entry_active_changed), NULL);
+    }
+
+  return object;
+}
+
+
+static void
+gtk_combo_box_dispose(GObject* object)
+{
+  GtkComboBox *combo_box = GTK_COMBO_BOX (object);
+
+  if (GTK_IS_MENU (combo_box->priv->popup_widget))
+    {
+      gtk_combo_box_menu_destroy (combo_box);
+      gtk_menu_detach (GTK_MENU (combo_box->priv->popup_widget));
+      combo_box->priv->popup_widget = NULL;
+    }
+
+  if (combo_box->priv->area)
+    {
+      g_object_unref (combo_box->priv->area);
+      combo_box->priv->area = NULL;
+    }
+
+  if (GTK_IS_TREE_VIEW (combo_box->priv->tree_view))
+    gtk_combo_box_list_destroy (combo_box);
+
+  if (combo_box->priv->popup_window)
+    {
+      gtk_widget_destroy (combo_box->priv->popup_window);
+      combo_box->priv->popup_window = NULL;
+    }
+
+  gtk_combo_box_unset_model (combo_box);
+
+  G_OBJECT_CLASS (gtk_combo_box_parent_class)->dispose (object);
+}
+
+static void
+gtk_combo_box_finalize (GObject *object)
+{
+  GtkComboBox *combo_box = GTK_COMBO_BOX (object);
+
+  g_free (combo_box->priv->tearoff_title);
+
+  G_OBJECT_CLASS (gtk_combo_box_parent_class)->finalize (object);
+}
+
+static gboolean
+gtk_cell_editable_key_press (GtkWidget   *widget,
+			     GdkEventKey *event,
+			     gpointer     data)
+{
+  GtkComboBox *combo_box = GTK_COMBO_BOX (data);
+
+  if (event->keyval == GDK_KEY_Escape)
+    {
+      g_object_set (combo_box,
+                    "editing-canceled", TRUE,
+                    NULL);
+      gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (combo_box));
+      gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (combo_box));
+      
+      return TRUE;
+    }
+  else if (event->keyval == GDK_KEY_Return ||
+           event->keyval == GDK_KEY_ISO_Enter ||
+           event->keyval == GDK_KEY_KP_Enter)
+    {
+      gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (combo_box));
+      gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (combo_box));
+      
+      return TRUE;
+    }
+
+  return FALSE;
+}
+
+static gboolean
+popdown_idle (gpointer data)
+{
+  GtkComboBox *combo_box;
+
+  combo_box = GTK_COMBO_BOX (data);
+  
+  gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (combo_box));
+  gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (combo_box));
+
+  g_object_unref (combo_box);
+
+  return FALSE;
+}
+
+static void
+popdown_handler (GtkWidget *widget,
+		 gpointer   data)
+{
+  gdk_threads_add_idle (popdown_idle, g_object_ref (data));
+}
+
+static gboolean
+popup_idle (gpointer data)
+{
+  GtkComboBox *combo_box;
+
+  combo_box = GTK_COMBO_BOX (data);
+
+  if (GTK_IS_MENU (combo_box->priv->popup_widget) &&
+      combo_box->priv->cell_view)
+    g_signal_connect_object (combo_box->priv->popup_widget,
+			     "unmap", G_CALLBACK (popdown_handler),
+			     combo_box, 0);
+  
+  /* we unset this if a menu item is activated */
+  g_object_set (combo_box,
+                "editing-canceled", TRUE,
+                NULL);
+  gtk_combo_box_popup (combo_box);
+
+  combo_box->priv->popup_idle_id = 0;
+  combo_box->priv->activate_button = 0;
+  combo_box->priv->activate_time = 0;
+
+  return FALSE;
+}
+
+static void
+gtk_combo_box_start_editing (GtkCellEditable *cell_editable,
+			     GdkEvent        *event)
+{
+  GtkComboBox *combo_box = GTK_COMBO_BOX (cell_editable);
+  GtkWidget *child;
+
+  combo_box->priv->is_cell_renderer = TRUE;
+
+  if (combo_box->priv->cell_view)
+    {
+      g_signal_connect_object (combo_box->priv->button, "key-press-event",
+			       G_CALLBACK (gtk_cell_editable_key_press), 
+			       cell_editable, 0);  
+
+      gtk_widget_grab_focus (combo_box->priv->button);
+    }
+  else
+    {
+      child = gtk_bin_get_child (GTK_BIN (combo_box));
+
+      g_signal_connect_object (child, "key-press-event",
+			       G_CALLBACK (gtk_cell_editable_key_press), 
+			       cell_editable, 0);  
+
+      gtk_widget_grab_focus (child);
+      gtk_widget_set_can_focus (combo_box->priv->button, FALSE);
+    }
+
+  /* we do the immediate popup only for the optionmenu-like 
+   * appearance 
+   */  
+  if (combo_box->priv->is_cell_renderer && 
+      combo_box->priv->cell_view && !combo_box->priv->tree_view)
+    {
+      if (event && event->type == GDK_BUTTON_PRESS)
+        {
+          GdkEventButton *event_button = (GdkEventButton *)event;
+
+          combo_box->priv->activate_button = event_button->button;
+          combo_box->priv->activate_time = event_button->time;
+        }
+
+      combo_box->priv->popup_idle_id = 
+          gdk_threads_add_idle (popup_idle, combo_box);
+    }
+}
+
+
 /**
  * gtk_combo_box_get_add_tearoffs:
  * @combo_box: a #GtkComboBox
@@ -4810,15 +4779,7 @@ gtk_combo_box_set_add_tearoffs (GtkComboBox *combo_box,
   if (combo_box->priv->add_tearoffs != add_tearoffs)
     {
       combo_box->priv->add_tearoffs = add_tearoffs;
-
-      if (GTK_IS_TREE_MENU (combo_box->priv->popup_widget))
-	{
-	  /* menu mode */
-	  gtk_tree_menu_set_tearoff (GTK_TREE_MENU (combo_box->priv->popup_widget), 
-				     combo_box->priv->add_tearoffs);
-	  /* XXX Resize ?? */
-	}
-
+      gtk_combo_box_check_appearance (combo_box);
       g_object_notify (G_OBJECT (combo_box), "add-tearoffs");
     }
 }
@@ -5201,166 +5162,330 @@ gtk_combo_box_get_focus_on_click (GtkComboBox *combo_box)
 }
 
 
-/**
- * gtk_combo_box_popup:
- * @combo_box: a #GtkComboBox
- * 
- * Pops up the menu or dropdown list of @combo_box. 
- *
- * This function is mostly intended for use by accessibility technologies;
- * applications should have little use for it.
- *
- * Since: 2.4
- */
-void
-gtk_combo_box_popup (GtkComboBox *combo_box)
+static gboolean
+gtk_combo_box_buildable_custom_tag_start (GtkBuildable  *buildable,
+					  GtkBuilder    *builder,
+					  GObject       *child,
+					  const gchar   *tagname,
+					  GMarkupParser *parser,
+					  gpointer      *data)
 {
-  g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
+  if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
+						tagname, parser, data))
+    return TRUE;
 
-  g_signal_emit (combo_box, combo_box_signals[POPUP], 0);
+  return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
+						      tagname, parser, data);
 }
 
-/**
- * gtk_combo_box_popup_for_device:
- * @combo_box: a #GtkComboBox
- * @device: a #GdkDevice
- *
- * Pops up the menu or dropdown list of @combo_box, the popup window
- * will be grabbed so only @device and its associated pointer/keyboard
- * are the only #GdkDevice<!-- -->s able to send events to it.
- *
- * Since: 3.0
- **/
-void
-gtk_combo_box_popup_for_device (GtkComboBox *combo_box,
-                                GdkDevice   *device)
+static void
+gtk_combo_box_buildable_custom_tag_end (GtkBuildable *buildable,
+					GtkBuilder   *builder,
+					GObject      *child,
+					const gchar  *tagname,
+					gpointer     *data)
 {
-  GtkComboBoxPrivate *priv = combo_box->priv;
-  gint x, y, width, height;
-  GtkTreePath *path = NULL, *ppath;
-  GtkWidget *toplevel;
-  GdkDevice *keyboard, *pointer;
-  guint32 time;
+  if (strcmp (tagname, "attributes") == 0)
+    _gtk_cell_layout_buildable_custom_tag_end (buildable, builder, child, tagname,
+					       data);
+  else
+    parent_buildable_iface->custom_tag_end (buildable, builder, child, tagname,
+					    data);
+}
 
-  g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
-  g_return_if_fail (GDK_IS_DEVICE (device));
+static GObject *
+gtk_combo_box_buildable_get_internal_child (GtkBuildable *buildable,
+					    GtkBuilder   *builder,
+					    const gchar  *childname)
+{
+  GtkComboBox *combo_box = GTK_COMBO_BOX (buildable);
 
-  if (!gtk_widget_get_realized (GTK_WIDGET (combo_box)))
-    return;
+  if (combo_box->priv->has_entry && strcmp (childname, "entry") == 0)
+    return G_OBJECT (gtk_bin_get_child (GTK_BIN (buildable)));
 
-  if (gtk_widget_get_mapped (priv->popup_widget))
-    return;
+  return parent_buildable_iface->get_internal_child (buildable, builder, childname);
+}
 
-  if (priv->grab_pointer && priv->grab_keyboard)
-    return;
+static void     
+gtk_combo_box_get_preferred_width (GtkWidget *widget,
+                                   gint      *minimum_size,
+                                   gint      *natural_size)
+{
+  GtkComboBox           *combo_box = GTK_COMBO_BOX (widget);
+  GtkComboBoxPrivate    *priv = combo_box->priv;
+  gint                   focus_width, focus_pad;
+  gint                   font_size, arrow_size;
+  PangoContext          *context;
+  PangoFontMetrics      *metrics;
+  PangoFontDescription  *font_desc;
+  GtkWidget             *child;
+  gint                   minimum_width = 0, natural_width = 0;
+  gint                   child_min, child_nat;
+  GtkStyleContext       *style_context;
+  GtkStateFlags          state;
+  GtkBorder             *border;
 
-  time = gtk_get_current_event_time ();
+  child = gtk_bin_get_child (GTK_BIN (widget));
+ 
+  /* common */
+  gtk_widget_get_preferred_width (child, &child_min, &child_nat);
 
-  if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
+  gtk_widget_style_get (GTK_WIDGET (widget),
+			"focus-line-width", &focus_width,
+			"focus-padding", &focus_pad,
+			"arrow-size", &arrow_size,
+			NULL);
+
+  style_context = gtk_widget_get_style_context (widget);
+  state = gtk_widget_get_state_flags (widget);
+
+  gtk_style_context_get (style_context, state,
+                         "font", &font_desc,
+			 "border-width", &border,
+                         NULL);
+
+  context = gtk_widget_get_pango_context (GTK_WIDGET (widget));
+  metrics = pango_context_get_metrics (context, font_desc,
+				       pango_context_get_language (context));
+  font_size = PANGO_PIXELS (pango_font_metrics_get_ascent (metrics) +
+			    pango_font_metrics_get_descent (metrics));
+  pango_font_metrics_unref (metrics);
+  pango_font_description_free (font_desc);
+
+  arrow_size = MAX (arrow_size, font_size);
+
+  gtk_widget_set_size_request (priv->arrow, arrow_size, arrow_size);
+
+  if (!priv->tree_view)
     {
-      keyboard = device;
-      pointer = gdk_device_get_associated_device (device);
+      /* menu mode */	  
+      if (priv->cell_view)
+        {
+          gint sep_width, arrow_width;
+          gint border_width, xpad;
+	  GtkBorder button_border;
+
+	  border_width = gtk_container_get_border_width (GTK_CONTAINER (combo_box));
+	  get_widget_border (priv->button, &button_border);
+
+          gtk_widget_get_preferred_width (priv->separator, &sep_width, NULL);
+          gtk_widget_get_preferred_width (priv->arrow, &arrow_width, NULL);
+
+	  xpad = 2 * (border_width + focus_width + focus_pad) +
+            button_border.left + button_border.right;
+
+          minimum_width  = child_min + sep_width + arrow_width + xpad;
+          natural_width  = child_nat + sep_width + arrow_width + xpad;
+        }
+      else
+        {
+          gint but_width, but_nat_width;
+
+          gtk_widget_get_preferred_width (priv->button, 
+                                          &but_width, &but_nat_width);
+
+          minimum_width  = child_min + but_width;
+          natural_width  = child_nat + but_nat_width;
+        }
     }
   else
     {
-      pointer = device;
-      keyboard = gdk_device_get_associated_device (device);
-    }
+      /* list mode */
+      gint button_width, button_nat_width;
 
-  if (GTK_IS_MENU (priv->popup_widget))
-    {
-      gtk_combo_box_menu_popup (combo_box, 
-                                priv->activate_button,
-                                priv->activate_time);
-      return;
-    }
+      /* sample + frame */
+      minimum_width = child_min;
+      natural_width = child_nat;
 
-  toplevel = gtk_widget_get_toplevel (GTK_WIDGET (combo_box));
-  if (GTK_IS_WINDOW (toplevel))
-    gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)), 
-				 GTK_WINDOW (priv->popup_window));
+      minimum_width += 2 * focus_width;
+      natural_width += 2 * focus_width;
+      
+      if (priv->cell_view_frame)
+        {
+	  if (priv->has_frame)
+	    {
+	      gint border_width, xpad;
+              GtkBorder frame_border;
 
-  gtk_widget_show_all (priv->scrolled_window);
-  gtk_combo_box_list_position (combo_box, &x, &y, &width, &height);
-  
-  gtk_widget_set_size_request (priv->popup_window, width, height);  
-  gtk_window_move (GTK_WINDOW (priv->popup_window), x, y);
+              border_width = gtk_container_get_border_width (GTK_CONTAINER (priv->cell_view_frame));
+              get_widget_border (priv->cell_view_frame, &frame_border);
+              xpad = (2 * border_width) + frame_border.left + frame_border.right;
 
-  if (gtk_tree_row_reference_valid (priv->active_row))
-    {
-      path = gtk_tree_row_reference_get_path (priv->active_row);
-      ppath = gtk_tree_path_copy (path);
-      if (gtk_tree_path_up (ppath))
-	gtk_tree_view_expand_to_path (GTK_TREE_VIEW (priv->tree_view),
-				      ppath);
-      gtk_tree_path_free (ppath);
-    }
-  gtk_tree_view_set_hover_expand (GTK_TREE_VIEW (priv->tree_view), 
-				  TRUE);
-  
-  /* popup */
-  gtk_widget_show (priv->popup_window);
+	      minimum_width  += xpad;
+	      natural_width  += xpad;
+	    }
+        }
 
-  if (path)
-    {
-      gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->tree_view),
-				path, NULL, FALSE);
-      gtk_tree_path_free (path);
+      /* the button */
+      gtk_widget_get_preferred_width (priv->button, 
+                                      &button_width, &button_nat_width);
+
+      minimum_width += button_width;
+      natural_width += button_nat_width;
     }
 
-  gtk_widget_grab_focus (priv->popup_window);
-  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->button),
-                                TRUE);
+  minimum_width += border->left + border->right;
+  natural_width += border->left + border->right;
+  gtk_border_free (border);
 
-  if (!gtk_widget_has_focus (priv->tree_view))
-    gtk_widget_grab_focus (priv->tree_view);
+  if (minimum_size)
+    *minimum_size = minimum_width;
 
-  if (!popup_grab_on_window (gtk_widget_get_window (priv->popup_window),
-			     keyboard, pointer, time))
-    {
-      gtk_widget_hide (priv->popup_window);
-      return;
-    }
+  if (natural_size)
+    *natural_size = natural_width;
+}
 
-  gtk_device_grab_add (priv->popup_window, pointer, TRUE);
-  priv->grab_pointer = pointer;
-  priv->grab_keyboard = keyboard;
+static void
+gtk_combo_box_get_preferred_height (GtkWidget *widget,
+                                    gint      *minimum_size,
+                                    gint      *natural_size)
+{ 
+  gint min_width;
+
+  /* Combo box is height-for-width only 
+   * (so we always just reserve enough height for the minimum width) */
+  GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, &min_width, NULL);
+  GTK_WIDGET_GET_CLASS (widget)->get_preferred_height_for_width (widget, min_width, minimum_size, natural_size);
 }
 
-/**
- * gtk_combo_box_popdown:
- * @combo_box: a #GtkComboBox
- * 
- * Hides the menu or dropdown list of @combo_box.
- *
- * This function is mostly intended for use by accessibility technologies;
- * applications should have little use for it.
- *
- * Since: 2.4
- */
-void
-gtk_combo_box_popdown (GtkComboBox *combo_box)
+static void
+gtk_combo_box_get_preferred_width_for_height (GtkWidget *widget,
+                                              gint       avail_size,
+                                              gint      *minimum_size,
+                                              gint      *natural_size)
 {
-  GtkComboBoxPrivate *priv = combo_box->priv;
+  /* Combo box is height-for-width only 
+   * (so we assume we always reserved enough height for the minimum width) */
+  GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_size, natural_size);
+}
 
-  g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
 
-  if (GTK_IS_MENU (priv->popup_widget))
+static void
+gtk_combo_box_get_preferred_height_for_width (GtkWidget *widget,
+                                              gint       avail_size,
+                                              gint      *minimum_size,
+                                              gint      *natural_size)
+{
+  GtkComboBox           *combo_box = GTK_COMBO_BOX (widget);
+  GtkComboBoxPrivate    *priv = combo_box->priv;
+  gint                   focus_width, focus_pad;
+  gint                   min_height = 0, nat_height = 0;
+  gint                   size;
+  GtkWidget             *child;
+  GtkBorder              border;
+
+  gtk_widget_style_get (GTK_WIDGET (widget),
+			"focus-line-width", &focus_width,
+			"focus-padding", &focus_pad,
+			NULL);
+
+  child = gtk_bin_get_child (GTK_BIN (widget));
+
+  get_widget_border (widget, &border);
+  size = avail_size - border.left;
+
+  if (!priv->tree_view)
     {
-      gtk_menu_popdown (GTK_MENU (priv->popup_widget));
-      return;
+      /* menu mode */
+      if (priv->cell_view)
+        {
+	  /* calculate x/y padding and separator/arrow size */
+          gint sep_width, arrow_width, sep_height, arrow_height;
+          gint border_width, xpad, ypad;
+          GtkBorder button_border;
+
+	  border_width = gtk_container_get_border_width (GTK_CONTAINER (combo_box));
+	  get_widget_border (priv->button, &button_border);
+
+          gtk_widget_get_preferred_width (priv->separator, &sep_width, NULL);
+          gtk_widget_get_preferred_width (priv->arrow, &arrow_width, NULL);
+          gtk_widget_get_preferred_height_for_width (priv->separator, 
+                                                     sep_width, &sep_height, NULL);
+          gtk_widget_get_preferred_height_for_width (priv->arrow, 
+                                                     arrow_width, &arrow_height, NULL);
+
+	  xpad = 2 * (border_width + focus_width + focus_pad) +
+	    button_border.left + button_border.right;
+	  ypad = 2 * (border_width + focus_width + focus_pad) +
+	    button_border.top + button_border.bottom;
+
+	  size -= sep_width + arrow_width + xpad;
+
+	  /* Get height-for-width of the child widget, usually a GtkCellArea calculating
+	   * and fitting the whole treemodel */
+	  gtk_widget_get_preferred_height_for_width (child, size, &min_height, &nat_height);
+
+	  arrow_height = MAX (arrow_height, sep_height);
+	  min_height = MAX (min_height, arrow_height);
+	  nat_height = MAX (nat_height, arrow_height);
+
+	  min_height += ypad;
+	  nat_height += ypad;
+        }
+      else
+        {
+	  /* there is a custom child widget inside (no priv->cell_view) */
+          gint but_width, but_height;
+
+          gtk_widget_get_preferred_width (priv->button, &but_width, NULL);
+          gtk_widget_get_preferred_height_for_width (priv->button, 
+                                                     but_width, &but_height, NULL);
+
+	  size -= but_width;
+
+	  /* Get height-for-width of the child widget, usually a GtkCellArea calculating
+	   * and fitting the whole treemodel */
+	  gtk_widget_get_preferred_height_for_width (child, size, &min_height, &nat_height);
+	  
+	  min_height = MAX (min_height, but_height);
+	  nat_height = MAX (nat_height, but_height);
+        }
     }
+  else
+    {
+      /* list mode */
+      gint but_width, but_height;
+      gint xpad = 0, ypad = 0;
 
-  if (!gtk_widget_get_realized (GTK_WIDGET (combo_box)))
-    return;
+      gtk_widget_get_preferred_width (priv->button, &but_width, NULL);
+      gtk_widget_get_preferred_height_for_width (priv->button, 
+                                                 but_width, &but_height, NULL);
+      
+      if (priv->cell_view_frame && priv->has_frame)
+	{
+	  GtkBorder frame_border;
+	  gint border_width;
 
-  gtk_device_grab_remove (priv->popup_window, priv->grab_pointer);
-  gtk_widget_hide (priv->popup_window);
-  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->button),
-                                FALSE);
+          border_width = gtk_container_get_border_width (GTK_CONTAINER (priv->cell_view_frame));
+	  get_widget_border (GTK_WIDGET (priv->cell_view_frame), &frame_border);
 
-  priv->grab_pointer = NULL;
-  priv->grab_keyboard = NULL;
+	  xpad = (2 * border_width) + border.left + frame_border.right;
+	  ypad = (2 * border_width) + border.top + frame_border.bottom;
+	}
+
+      size -= but_width;
+      size -= 2 * focus_width;
+      size -= xpad;
+ 
+      /* Get height-for-width of the child widget, usually a GtkCellArea calculating
+       * and fitting the whole treemodel */
+      gtk_widget_get_preferred_height_for_width (child, size, &min_height, &nat_height);
+
+      min_height = MAX (min_height, but_height);
+      nat_height = MAX (nat_height, but_height);
+
+      min_height += ypad;
+      nat_height += ypad;
+    }
+
+  min_height += border.top + border.bottom;
+  nat_height += border.top + border.bottom;
+
+  if (minimum_size)
+    *minimum_size = min_height;
+
+  if (natural_size)
+    *natural_size = nat_height;
 }
 
 /**



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]