]> Pileus Git - ~andy/gtk/commitdiff
Re-refactored GtkComboBox to not reorder the file.
authorTristan Van Berkom <tristan.van.berkom@gmail.com>
Mon, 6 Dec 2010 12:30:00 +0000 (21:30 +0900)
committerTristan Van Berkom <tristan.van.berkom@gmail.com>
Tue, 4 Jan 2011 14:37:12 +0000 (23:37 +0900)
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

index 5f2edf43aa562b03bd458f82ec23b58738601ac5..6d594400d24797f7b7bad9e2c999b6e60a20bb80 100644 (file)
@@ -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"
 #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>
 
@@ -54,6 +52,7 @@
 #include "gtkmarshalers.h"
 #include "gtkintl.h"
 
+#include "gtkentryprivate.h"
 #include "gtktreeprivate.h"
 
 
 
 
 /* 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
  * 
  */
 
-/* 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,
@@ -154,58 +265,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);
@@ -214,19 +286,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,
@@ -264,19 +377,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);
@@ -284,21 +404,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);
@@ -313,7 +420,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,
@@ -330,171 +441,70 @@ 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;
+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);
 
-  gint col_column;
-  gint row_column;
-  gint id_column;
 
-  gint wrap_width;
-  GtkShadowType shadow_type;
+G_DEFINE_TYPE_WITH_CODE (GtkComboBox, gtk_combo_box, GTK_TYPE_BIN,
+                        G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
+                                               gtk_combo_box_cell_layout_init)
+                        G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
+                                               gtk_combo_box_cell_editable_init)
+                        G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
+                                               gtk_combo_box_buildable_init))
 
-  gint active; /* Only temporary */
-  GtkTreeRowReference *active_row;
 
+/* common */
+static void
+gtk_combo_box_class_init (GtkComboBoxClass *klass)
+{
+  GObjectClass *object_class;
+  GtkContainerClass *container_class;
+  GtkWidgetClass *widget_class;
+  GtkBindingSet *binding_set;
 
-  /* The cellview displayed on the button */
-  GtkWidget *cell_view;
-  GtkWidget *cell_view_frame;
+  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;
 
-  /* The treeview & column for list mode */
-  GtkWidget         *tree_view;
-  GtkTreeViewColumn *column;
+  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->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;
 
-  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;
-
-
-G_DEFINE_TYPE_WITH_CODE (GtkComboBox, gtk_combo_box, GTK_TYPE_BIN,
-                        G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
-                                               gtk_combo_box_cell_layout_init)
-                        G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
-                                               gtk_combo_box_cell_editable_init)
-                        G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
-                                               gtk_combo_box_buildable_init))
-
-
-/* common */
-static void
-gtk_combo_box_class_init (GtkComboBoxClass *klass)
-{
-  GObjectClass *object_class;
-  GtkContainerClass *container_class;
-  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;
-
-  widget_class = (GtkWidgetClass *)klass;
-  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 */
   /**
@@ -898,20 +908,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:
@@ -931,6 +927,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)
   g_type_class_add_private (object_class, sizeof (GtkComboBoxPrivate));
 }
 
+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)
 {
@@ -985,6 +1018,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;
@@ -1008,158 +1044,60 @@ 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)
+static void
+gtk_combo_box_set_property (GObject      *object,
+                            guint         prop_id,
+                            const GValue *value,
+                            GParamSpec   *pspec)
 {
-  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;
+  GtkComboBox *combo_box = GTK_COMBO_BOX (object);
+  GtkCellArea *area;
 
-  if (!priv->area)
+  switch (prop_id)
     {
-      GtkCellArea *area = gtk_cell_area_box_new ();
+    case PROP_MODEL:
+      gtk_combo_box_set_model (combo_box, g_value_get_object (value));
+      break;
 
-      priv->area = g_object_ref_sink (area);
-    }
+    case PROP_WRAP_WIDTH:
+      gtk_combo_box_set_wrap_width (combo_box, g_value_get_int (value));
+      break;
 
-  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);
+    case PROP_ROW_SPAN_COLUMN:
+      gtk_combo_box_set_row_span_column (combo_box, g_value_get_int (value));
+      break;
 
-  gtk_combo_box_check_appearance (combo_box);
+    case PROP_COLUMN_SPAN_COLUMN:
+      gtk_combo_box_set_column_span_column (combo_box, g_value_get_int (value));
+      break;
 
-  context = gtk_widget_get_style_context (GTK_WIDGET (combo_box));
-  gtk_style_context_add_class (context, GTK_STYLE_CLASS_BUTTON);
+    case PROP_ACTIVE:
+      gtk_combo_box_set_active (combo_box, g_value_get_int (value));
+      break;
 
-  if (priv->has_entry)
-    {
-      GtkWidget *entry;
+    case PROP_ADD_TEAROFFS:
+      gtk_combo_box_set_add_tearoffs (combo_box, g_value_get_boolean (value));
+      break;
 
-      entry = gtk_entry_new ();
-      gtk_widget_show (entry);
-      gtk_container_add (GTK_CONTAINER (combo_box), entry);
+    case PROP_HAS_FRAME:
+      combo_box->priv->has_frame = g_value_get_boolean (value);
 
-      priv->text_renderer = gtk_cell_renderer_text_new ();
-      gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box),
-                                 priv->text_renderer, TRUE);
+      if (combo_box->priv->has_entry)
+        {
+          GtkWidget *child;
 
-      gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), -1);
+          child = gtk_bin_get_child (GTK_BIN (combo_box));
 
-      g_signal_connect (combo_box, "changed",
-                       G_CALLBACK (gtk_combo_box_entry_active_changed), NULL);
-    }
+          gtk_entry_set_has_frame (GTK_ENTRY (child),
+                                   combo_box->priv->has_frame);
+        }
 
-  return object;
-}
+      break;
 
-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,
-                            const GValue *value,
-                            GParamSpec   *pspec)
-{
-  GtkComboBox *combo_box = GTK_COMBO_BOX (object);
-  GtkCellArea *area;
-
-  switch (prop_id)
-    {
-    case PROP_MODEL:
-      gtk_combo_box_set_model (combo_box, g_value_get_object (value));
-      break;
-
-    case PROP_WRAP_WIDTH:
-      gtk_combo_box_set_wrap_width (combo_box, g_value_get_int (value));
-      break;
-
-    case PROP_ROW_SPAN_COLUMN:
-      gtk_combo_box_set_row_span_column (combo_box, g_value_get_int (value));
-      break;
-
-    case PROP_COLUMN_SPAN_COLUMN:
-      gtk_combo_box_set_column_span_column (combo_box, g_value_get_int (value));
-      break;
-
-    case PROP_ACTIVE:
-      gtk_combo_box_set_active (combo_box, g_value_get_int (value));
-      break;
-
-    case PROP_ADD_TEAROFFS:
-      gtk_combo_box_set_add_tearoffs (combo_box, g_value_get_boolean (value));
-      break;
-
-    case PROP_HAS_FRAME:
-      combo_box->priv->has_frame = g_value_get_boolean (value);
-
-      if (combo_box->priv->has_entry)
-        {
-          GtkWidget *child;
-
-          child = gtk_bin_get_child (GTK_BIN (combo_box));
-
-          gtk_entry_set_has_frame (GTK_ENTRY (child),
-                                   combo_box->priv->has_frame);
-        }
-
-      break;
-
-    case PROP_FOCUS_ON_CLICK:
-      gtk_combo_box_set_focus_on_click (combo_box,
-                                        g_value_get_boolean (value));
-      break;
+    case PROP_FOCUS_ON_CLICK:
+      gtk_combo_box_set_focus_on_click (combo_box,
+                                        g_value_get_boolean (value));
+      break;
 
     case PROP_TEAROFF_TITLE:
       gtk_combo_box_set_title (combo_box, g_value_get_string (value));
@@ -1305,511 +1243,428 @@ gtk_combo_box_get_property (GObject    *object,
     }
 }
 
-/******************************************************
- *                    GtkWidgetClass                  *
- ******************************************************/
-static gboolean
-gtk_combo_box_draw (GtkWidget *widget,
-                    cairo_t   *cr)
+static void
+gtk_combo_box_state_changed (GtkWidget    *widget,
+                            GtkStateType  previous)
 {
   GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
   GtkComboBoxPrivate *priv = combo_box->priv;
 
-  if (priv->shadow_type != GTK_SHADOW_NONE)
+  if (gtk_widget_get_realized (widget))
     {
-      GtkStyleContext *context;
-      GtkStateFlags state;
+      if (priv->tree_view && priv->cell_view)
+        {
+          GtkStyleContext *context;
+          GtkStateFlags state;
+          GdkRGBA *color;
 
-      context = gtk_widget_get_style_context (widget);
-      state = gtk_widget_get_state_flags (widget);
-      gtk_style_context_set_state (context, state);
+          context  = gtk_widget_get_style_context (widget);
+          state = gtk_widget_get_state_flags (widget);
 
-      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_style_context_get (context, state,
+                                 "background-color", &color,
+                                 NULL);
+
+          gtk_cell_view_set_background_rgba (GTK_CELL_VIEW (priv->cell_view), color);
+          gdk_rgba_free (color);
+        }
     }
 
-  gtk_container_propagate_draw (GTK_CONTAINER (widget),
-                               priv->button, cr);
+  gtk_widget_queue_draw (widget);
+}
 
-  if (priv->tree_view && priv->cell_view_frame)
+static void
+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;
+
+  if (gtk_widget_get_realized (widget))
     {
-      gtk_container_propagate_draw (GTK_CONTAINER (widget),
-                                   priv->cell_view_frame, cr);
+      if (!priv->tree_view && priv->cell_view)
+        gtk_widget_set_state_flags (priv->cell_view,
+                                    gtk_widget_get_state_flags (widget),
+                                    TRUE);
     }
 
-  gtk_container_propagate_draw (GTK_CONTAINER (widget),
-                                gtk_bin_get_child (GTK_BIN (widget)),
-                                cr);
-
-  return FALSE;
+  gtk_widget_queue_draw (widget);
 }
 
-
-typedef struct {
-  GtkComboBox *combo;
-  GtkTreePath *path;
-  GtkTreeIter iter;
-  gboolean found;
-  gboolean set;
-  gboolean visible;
-} SearchData;
-
-static gboolean
-path_visible (GtkTreeView *view,
-             GtkTreePath *path)
+static void
+gtk_combo_box_check_appearance (GtkComboBox *combo_box)
 {
-  GtkRBTree *tree;
-  GtkRBNode *node;
-  
-  /* Note that we rely on the fact that collapsed rows don't have nodes 
+  GtkComboBoxPrivate *priv = combo_box->priv;
+  gboolean appears_as_list;
+
+  /* if wrap_width > 0, then we are in grid-mode and forced to use
+   * unix style
    */
-  return _gtk_tree_view_find_node (view, path, &tree, &node);
+  if (priv->wrap_width)
+    appears_as_list = FALSE;
+  else
+    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);
+
+      /* Create the list mode widgets, if they don't already exist. */
+      if (!GTK_IS_TREE_VIEW (priv->tree_view))
+       gtk_combo_box_list_setup (combo_box);
+    }
+  else
+    {
+      /* Destroy all the list mode widgets, if they exist. */
+      if (GTK_IS_TREE_VIEW (priv->tree_view))
+       gtk_combo_box_list_destroy (combo_box);
+
+      /* Create the menu mode widgets, if they don't already exist. */
+      if (!GTK_IS_MENU (priv->popup_widget))
+       gtk_combo_box_menu_setup (combo_box, TRUE);
+    }
+
+  gtk_widget_style_get (GTK_WIDGET (combo_box),
+                       "shadow-type", &priv->shadow_type,
+                       NULL);
 }
 
-static gboolean
-tree_column_row_is_sensitive (GtkComboBox *combo_box,
-                             GtkTreeIter *iter)
+static void
+gtk_combo_box_style_updated (GtkWidget *widget)
 {
+  GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
   GtkComboBoxPrivate *priv = combo_box->priv;
-  GList *cells, *list;
-  gboolean sensitive;
+  GtkWidget *child;
 
-  if (!priv->column)
-    return TRUE;
+  gtk_combo_box_check_appearance (combo_box);
 
-  if (priv->row_separator_func)
+  if (priv->tree_view && priv->cell_view)
     {
-      if (priv->row_separator_func (priv->model, iter,
-                                    priv->row_separator_data))
-       return FALSE;
-    }
+      GtkStyleContext *context;
+      GdkRGBA *color;
 
-  gtk_tree_view_column_cell_set_cell_data (priv->column,
-                                          priv->model,
-                                          iter, FALSE, FALSE);
+      context = gtk_widget_get_style_context (widget);
+      gtk_style_context_get (context, 0,
+                             "background-color", &color,
+                             NULL);
 
-  cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (priv->column));
+      gtk_cell_view_set_background_rgba (GTK_CELL_VIEW (priv->cell_view),
+                                         color);
 
-  sensitive = FALSE;
-  for (list = cells; list; list = list->next)
-    {
-      g_object_get (list->data, "sensitive", &sensitive, NULL);
-      
-      if (sensitive)
-       break;
+      gdk_rgba_free (color);
     }
-  g_list_free (cells);
 
-  return sensitive;
+  child = gtk_bin_get_child (GTK_BIN (combo_box));
+  if (GTK_IS_ENTRY (child))
+    g_object_set (child, "shadow-type",
+                  GTK_SHADOW_NONE == priv->shadow_type ?
+                  GTK_SHADOW_IN : GTK_SHADOW_NONE, NULL);
 }
 
-static gboolean
-tree_next_func (GtkTreeModel *model,
-               GtkTreePath  *path,
-               GtkTreeIter  *iter,
-               gpointer      data)
+static void
+gtk_combo_box_button_toggled (GtkWidget *widget,
+                              gpointer   data)
 {
-  SearchData *search_data = (SearchData *)data;
+  GtkComboBox *combo_box = GTK_COMBO_BOX (data);
 
-  if (search_data->found) 
+  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
     {
-      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 (!combo_box->priv->popup_in_progress)
+        gtk_combo_box_popup (combo_box);
     }
-  if (gtk_tree_path_compare (path, search_data->path) == 0)
-    search_data->found = TRUE;
-  
-  return FALSE;
+  else
+    gtk_combo_box_popdown (combo_box);
 }
 
-static gboolean
-tree_next (GtkComboBox  *combo,
-          GtkTreeModel *model,
-          GtkTreeIter  *iter,
-          GtkTreeIter  *next,
-          gboolean      visible)
+static void
+gtk_combo_box_add (GtkContainer *container,
+                   GtkWidget    *widget)
 {
-  SearchData search_data;
+  GtkComboBox *combo_box = GTK_COMBO_BOX (container);
+  GtkComboBoxPrivate *priv = combo_box->priv;
 
-  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;
+  if (priv->has_entry && !GTK_IS_ENTRY (widget))
+    {
+      g_warning ("Attempting to add a widget with type %s to a GtkComboBox that needs an entry "
+                "(need an instance of GtkEntry or of a subclass)",
+                 G_OBJECT_TYPE_NAME (widget));
+      return;
+    }
 
-  gtk_tree_model_foreach (model, tree_next_func, &search_data);
+  if (priv->cell_view &&
+      gtk_widget_get_parent (priv->cell_view))
+    {
+      gtk_widget_unparent (priv->cell_view);
+      _gtk_bin_set_child (GTK_BIN (container), NULL);
+      gtk_widget_queue_resize (GTK_WIDGET (container));
+    }
   
-  *next = search_data.iter;
+  gtk_widget_set_parent (widget, GTK_WIDGET (container));
+  _gtk_bin_set_child (GTK_BIN (container), widget);
 
-  gtk_tree_path_free (search_data.path);
+  if (priv->cell_view &&
+      widget != priv->cell_view)
+    {
+      /* since the cell_view was unparented, it's gone now */
+      priv->cell_view = NULL;
 
-  return search_data.set;
-}
+      if (!priv->tree_view && priv->separator)
+        {
+          gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (priv->separator)),
+                                priv->separator);
+         priv->separator = NULL;
 
-static gboolean
-tree_prev_func (GtkTreeModel *model,
-               GtkTreePath  *path,
-               GtkTreeIter  *iter,
-               gpointer      data)
-{
-  SearchData *search_data = (SearchData *)data;
+          gtk_widget_queue_resize (GTK_WIDGET (container));
+        }
+      else if (priv->cell_view_frame)
+        {
+          gtk_widget_unparent (priv->cell_view_frame);
+          priv->cell_view_frame = NULL;
+          priv->box = NULL;
+        }
+    }
 
-  if (gtk_tree_path_compare (path, search_data->path) == 0)
+  if (priv->has_entry)
     {
-      search_data->found = TRUE;
-      return TRUE;
+      /* this flag is a hack to tell the entry to fill its allocation.
+       */
+      _gtk_entry_set_is_cell_renderer (GTK_ENTRY (widget), TRUE);
+
+      g_signal_connect (widget, "changed",
+                       G_CALLBACK (gtk_combo_box_entry_contents_changed),
+                       combo_box);
+
+      gtk_entry_set_has_frame (GTK_ENTRY (widget), priv->has_frame);
     }
-  
-  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)
+static void
+gtk_combo_box_remove (GtkContainer *container,
+                     GtkWidget    *widget)
 {
-  SearchData search_data;
+  GtkComboBox *combo_box = GTK_COMBO_BOX (container);
+  GtkComboBoxPrivate *priv = combo_box->priv;
+  GtkTreePath *path;
+  gboolean appears_as_list;
 
-  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;
+  if (priv->has_entry)
+    {
+      GtkWidget *child_widget;
 
-  gtk_tree_model_foreach (model, tree_prev_func, &search_data);
-  
-  *prev = search_data.iter;
+      child_widget = gtk_bin_get_child (GTK_BIN (container));
+      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_tree_path_free (search_data.path);
+  if (widget == priv->cell_view)
+    priv->cell_view = NULL;
 
-  return search_data.set;
-}
+  gtk_widget_unparent (widget);
+  _gtk_bin_set_child (GTK_BIN (container), NULL);
 
-static gboolean
-tree_last_func (GtkTreeModel *model,
-               GtkTreePath  *path,
-               GtkTreeIter  *iter,
-               gpointer      data)
-{
-  SearchData *search_data = (SearchData *)data;
+  if (gtk_widget_in_destruction (GTK_WIDGET (combo_box)))
+    return;
 
-  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;
+  gtk_widget_queue_resize (GTK_WIDGET (container));
+
+  if (!priv->tree_view)
+    appears_as_list = FALSE;
+  else
+    appears_as_list = TRUE;
   
-  return FALSE; 
-}
+  if (appears_as_list)
+    gtk_combo_box_list_destroy (combo_box);
+  else if (GTK_IS_MENU (priv->popup_widget))
+    {
+      gtk_combo_box_menu_destroy (combo_box);
+      gtk_menu_detach (GTK_MENU (priv->popup_widget));
+      priv->popup_widget = NULL;
+    }
 
-static gboolean
-tree_last (GtkComboBox  *combo,
-          GtkTreeModel *model,
-          GtkTreeIter  *last,
-          gboolean      visible)
-{
-  SearchData search_data;
+  if (!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);
+    }
 
-  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;
+  if (appears_as_list)
+    gtk_combo_box_list_setup (combo_box); 
+  else
+    gtk_combo_box_menu_setup (combo_box, TRUE);
 
-  return search_data.set;  
+  if (gtk_tree_row_reference_valid (priv->active_row))
+    {
+      path = gtk_tree_row_reference_get_path (priv->active_row);
+      gtk_combo_box_set_active_internal (combo_box, path);
+      gtk_tree_path_free (path);
+    }
+  else
+    gtk_combo_box_set_active_internal (combo_box, NULL);
 }
 
-
-static gboolean
-tree_first_func (GtkTreeModel *model,
-                GtkTreePath  *path,
-                GtkTreeIter  *iter,
-                gpointer      data)
+static void
+gtk_combo_box_menu_show (GtkWidget *menu,
+                         gpointer   user_data)
 {
-  SearchData *search_data = (SearchData *)data;
+  GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
+  GtkComboBoxPrivate *priv = combo_box->priv;
 
-  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;
+  gtk_combo_box_child_show (menu, user_data);
+
+  priv->popup_in_progress = TRUE;
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->button),
+                                TRUE);
+  priv->popup_in_progress = FALSE;
 }
 
-static gboolean
-tree_first (GtkComboBox  *combo,
-           GtkTreeModel *model,
-           GtkTreeIter  *first,
-           gboolean      visible)
+static void
+gtk_combo_box_menu_hide (GtkWidget *menu,
+                         gpointer   user_data)
 {
-  SearchData search_data;
-  
-  search_data.combo = combo;
-  search_data.visible = visible;
-  search_data.set = FALSE;
+  GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
 
-  gtk_tree_model_foreach (model, tree_first_func, &search_data);
-  
-  *first = search_data.iter;
+  gtk_combo_box_child_hide (menu,user_data);
 
-  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;
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
+                                FALSE);
 }
 
 static void
-gtk_combo_box_grab_focus (GtkWidget *widget)
+gtk_combo_box_detacher (GtkWidget *widget,
+                       GtkMenu   *menu)
 {
   GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
+  GtkComboBoxPrivate *priv = combo_box->priv;
 
-  if (combo_box->priv->has_entry)
-    {
-      GtkWidget *child;
+  g_return_if_fail (priv->popup_widget == (GtkWidget *) menu);
 
-      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);
+  g_signal_handlers_disconnect_by_func (menu->toplevel,
+                                       gtk_combo_box_menu_show,
+                                       combo_box);
+  g_signal_handlers_disconnect_by_func (menu->toplevel,
+                                       gtk_combo_box_menu_hide,
+                                       combo_box);
+  
+  priv->popup_widget = NULL;
 }
 
 static void
-gtk_combo_box_state_changed (GtkWidget    *widget,
-                            GtkStateType  previous)
+gtk_combo_box_set_popup_widget (GtkComboBox *combo_box,
+                                GtkWidget   *popup)
 {
-  GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
   GtkComboBoxPrivate *priv = combo_box->priv;
 
-  if (gtk_widget_get_realized (widget))
+  if (GTK_IS_MENU (priv->popup_widget))
     {
-      if (priv->tree_view && priv->cell_view)
-       {
-         GtkStyleContext *context;
-          GtkStateFlags state;
-          GdkRGBA *color;
-
-          context  = gtk_widget_get_style_context (widget);
-          state = gtk_widget_get_state_flags (widget);
-
-          gtk_style_context_get (context, state,
-                                 "background-color", &color,
-                                 NULL);
-
-          gtk_cell_view_set_background_rgba (GTK_CELL_VIEW (priv->cell_view), color);
-          gdk_rgba_free (color);
-       }
+      gtk_menu_detach (GTK_MENU (priv->popup_widget));
+      priv->popup_widget = NULL;
     }
-
-  gtk_widget_queue_draw (widget);
-}
-
-static void
-gtk_combo_box_button_state_changed (GtkWidget    *widget,
-                                   GtkStateType  previous,
-                                   gpointer      data)
-{
-  GtkComboBox *combo_box = GTK_COMBO_BOX (data);
-  GtkComboBoxPrivate *priv = combo_box->priv;
-
-  if (gtk_widget_get_realized (widget))
+  else if (priv->popup_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_container_remove (GTK_CONTAINER (priv->scrolled_window),
+                            priv->popup_widget);
+      g_object_unref (priv->popup_widget);
+      priv->popup_widget = NULL;
     }
 
-  gtk_widget_queue_draw (widget);
-}
-
-static void
-gtk_combo_box_check_appearance (GtkComboBox *combo_box)
-{
-  GtkComboBoxPrivate *priv = combo_box->priv;
-  gboolean appears_as_list;
+  if (GTK_IS_MENU (popup))
+    {
+      if (priv->popup_window)
+        {
+          gtk_widget_destroy (priv->popup_window);
+          priv->popup_window = NULL;
+        }
 
-  /* if wrap_width > 0, then we are in grid-mode and forced to use
-   * unix style
-   */
-  if (priv->wrap_width)
-    appears_as_list = FALSE;
-  else
-    gtk_widget_style_get (GTK_WIDGET (combo_box),
-                         "appears-as-list", &appears_as_list,
-                         NULL);
+      priv->popup_widget = popup;
 
-  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);
+      /* 
+       * Note that we connect to show/hide on the toplevel, not the
+       * menu itself, since the menu is not shown/hidden when it is
+       * popped up while torn-off.
+       */
+      g_signal_connect (GTK_MENU (popup)->toplevel, "show",
+                        G_CALLBACK (gtk_combo_box_menu_show), combo_box);
+      g_signal_connect (GTK_MENU (popup)->toplevel, "hide",
+                        G_CALLBACK (gtk_combo_box_menu_hide), combo_box);
 
-      /* Create the list mode widgets, if they don't already exist. */
-      if (!GTK_IS_TREE_VIEW (priv->tree_view))
-       gtk_combo_box_list_setup (combo_box);
+      gtk_menu_attach_to_widget (GTK_MENU (popup),
+                                GTK_WIDGET (combo_box),
+                                gtk_combo_box_detacher);
     }
   else
     {
-      /* Destroy all the list mode widgets, if they exist. */
-      if (GTK_IS_TREE_VIEW (priv->tree_view))
-       gtk_combo_box_list_destroy (combo_box);
-
-      /* Create the menu mode widgets, if they don't already exist. */
-      if (!GTK_IS_MENU (priv->popup_widget))
-       gtk_combo_box_menu_setup (combo_box, TRUE);
-    }
-
-  gtk_widget_style_get (GTK_WIDGET (combo_box),
-                       "shadow-type", &priv->shadow_type,
-                       NULL);
-}
-
-static void
-gtk_combo_box_style_updated (GtkWidget *widget)
-{
-  GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
-  GtkComboBoxPrivate *priv = combo_box->priv;
-  GtkWidget *child;
+      if (!priv->popup_window)
+        {
+         GtkWidget *toplevel;
+         
+          priv->popup_window = gtk_window_new (GTK_WINDOW_POPUP);
+          gtk_widget_set_name (priv->popup_window, "gtk-combobox-popup-window");
 
-  gtk_combo_box_check_appearance (combo_box);
+         gtk_window_set_type_hint (GTK_WINDOW (priv->popup_window),
+                                   GDK_WINDOW_TYPE_HINT_COMBO);
 
-  if (priv->tree_view && priv->cell_view)
-    {
-      GtkStyleContext *context;
-      GdkRGBA *color;
+         g_signal_connect (GTK_WINDOW (priv->popup_window),"show",
+                           G_CALLBACK (gtk_combo_box_child_show),
+                           combo_box);
+         g_signal_connect (GTK_WINDOW (priv->popup_window),"hide",
+                           G_CALLBACK (gtk_combo_box_child_hide),
+                           combo_box);
+         
+         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_window_set_transient_for (GTK_WINDOW (priv->popup_window),
+                                           GTK_WINDOW (toplevel));
+           }
 
-      context = gtk_widget_get_style_context (widget);
-      gtk_style_context_get (context, 0,
-                            "background-color", &color,
-                            NULL);
+         gtk_window_set_resizable (GTK_WINDOW (priv->popup_window), FALSE);
+          gtk_window_set_screen (GTK_WINDOW (priv->popup_window),
+                                 gtk_widget_get_screen (GTK_WIDGET (combo_box)));
 
-      gtk_cell_view_set_background_rgba (GTK_CELL_VIEW (priv->cell_view), color);
-      gdk_rgba_free (color);
-    }
+         priv->scrolled_window = gtk_scrolled_window_new (NULL, NULL);
+         
+         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
+                                         GTK_POLICY_NEVER,
+                                         GTK_POLICY_NEVER);
+         gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (priv->scrolled_window),
+                                              GTK_SHADOW_IN);
 
-  child = gtk_bin_get_child (GTK_BIN (combo_box));
-  if (GTK_IS_ENTRY (child))
-    g_object_set (child, "shadow-type",
-                  GTK_SHADOW_NONE == priv->shadow_type ?
-                  GTK_SHADOW_IN : GTK_SHADOW_NONE, NULL);
-}
+          gtk_widget_show (priv->scrolled_window);
+         
+         gtk_container_add (GTK_CONTAINER (priv->popup_window),
+                            priv->scrolled_window);
+        }
 
-static void
-gtk_combo_box_destroy (GtkWidget *widget)
-{
-  GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
+      gtk_container_add (GTK_CONTAINER (priv->scrolled_window),
+                         popup);
 
-  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_widget_show (popup);
+      g_object_ref (popup);
+      priv->popup_widget = popup;
     }
-
-  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)
+                   GtkBorder *border)
 {
   GtkStyleContext *context;
   GtkBorder *border_width;
@@ -1825,754 +1680,608 @@ get_widget_border (GtkWidget *widget,
   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;
+static void
+gtk_combo_box_menu_position_below (GtkMenu  *menu,
+                                  gint     *x,
+                                  gint     *y,
+                                  gint     *push_in,
+                                  gpointer  user_data)
+{
+  GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
+  GtkAllocation child_allocation;
+  gint sx, sy;
+  GtkWidget *child;
+  GtkRequisition req;
+  GdkScreen *screen;
+  gint monitor_num;
+  GdkRectangle monitor;
+  GtkBorder border;
 
-  child = gtk_bin_get_child (GTK_BIN (widget));
-  /* common */
-  gtk_widget_get_preferred_width (child, &child_min, &child_nat);
+  /* FIXME: is using the size request here broken? */
+  child = gtk_bin_get_child (GTK_BIN (combo_box));
 
-  gtk_widget_style_get (GTK_WIDGET (widget),
-                       "focus-line-width", &focus_width,
-                       "focus-padding", &focus_pad,
-                       "arrow-size", &arrow_size,
-                       NULL);
+  sx = sy = 0;
 
-  style_context = gtk_widget_get_style_context (widget);
-  state = gtk_widget_get_state_flags (widget);
+  gtk_widget_get_allocation (child, &child_allocation);
 
-  gtk_style_context_get (style_context, state,
-                         "font", &font_desc,
-                        "border-width", &border,
-                         NULL);
+  if (!gtk_widget_get_has_window (child))
+    {
+      sx += child_allocation.x;
+      sy += child_allocation.y;
+    }
 
-  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);
+  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;
 
-  arrow_size = MAX (arrow_size, font_size);
+  if (combo_box->priv->popup_fixed_width)
+    gtk_widget_get_preferred_size (GTK_WIDGET (menu), &req, NULL);
+  else
+    gtk_widget_get_preferred_size (GTK_WIDGET (menu), NULL, &req);
 
-  gtk_widget_set_size_request (priv->arrow, arrow_size, arrow_size);
+  if (gtk_widget_get_direction (GTK_WIDGET (combo_box)) == GTK_TEXT_DIR_LTR)
+    *x = sx;
+  else
+    *x = sx + child_allocation.width - req.width;
+  *y = sy;
 
-  if (!priv->tree_view)
-    {
-      /* menu mode */    
-      if (priv->cell_view)
-        {
-          gint sep_width, arrow_width;
-          gint border_width, xpad;
-         GtkBorder button_border;
+  screen = gtk_widget_get_screen (GTK_WIDGET (combo_box));
+  monitor_num = gdk_screen_get_monitor_at_window (screen, 
+                                                  gtk_widget_get_window (GTK_WIDGET (combo_box)));
+  gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
+  
+  if (*x < monitor.x)
+    *x = monitor.x;
+  else if (*x + req.width > monitor.x + monitor.width)
+    *x = monitor.x + monitor.width - req.width;
+  
+  if (monitor.y + monitor.height - *y - child_allocation.height >= req.height)
+    *y += child_allocation.height;
+  else if (*y - monitor.y >= req.height)
+    *y -= req.height;
+  else if (monitor.y + monitor.height - *y - child_allocation.height > *y - monitor.y)
+    *y += child_allocation.height;
+  else
+    *y -= req.height;
 
-         border_width = gtk_container_get_border_width (GTK_CONTAINER (combo_box));
-         get_widget_border (priv->button, &button_border);
+   *push_in = FALSE;
+}
 
-          gtk_widget_get_preferred_width (priv->separator, &sep_width, NULL);
-          gtk_widget_get_preferred_width (priv->arrow, &arrow_width, NULL);
+static void
+gtk_combo_box_menu_position_over (GtkMenu  *menu,
+                                 gint     *x,
+                                 gint     *y,
+                                 gboolean *push_in,
+                                 gpointer  user_data)
+{
+  GtkComboBox    *combo_box;
+  GtkWidget      *active;
+  GtkWidget      *child;
+  GtkWidget      *widget;
+  GtkAllocation   allocation;
+  GtkAllocation   child_allocation;
+  GList          *children;
+  gint            screen_width;
+  gint            menu_xpos;
+  gint            menu_ypos;
+  gint            menu_width;
 
-         xpad = 2 * (border_width + focus_width + focus_pad) +
-            button_border.left + button_border.right;
+  combo_box = GTK_COMBO_BOX (user_data);
+  widget = GTK_WIDGET (combo_box);
 
-          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;
+  active = gtk_menu_get_active (GTK_MENU (combo_box->priv->popup_widget));
 
-          gtk_widget_get_preferred_width (priv->button, 
-                                          &but_width, &but_nat_width);
+  gtk_widget_get_allocation (widget, &allocation);
 
-          minimum_width  = child_min + but_width;
-          natural_width  = child_nat + but_nat_width;
-        }
-    }
+  menu_xpos = allocation.x;
+  menu_ypos = allocation.y + allocation.height / 2 - 2;
+
+  if (combo_box->priv->popup_fixed_width)
+    gtk_widget_get_preferred_width (GTK_WIDGET (menu), &menu_width, NULL);
   else
-    {
-      /* list mode */
-      gint button_width, button_nat_width;
+    gtk_widget_get_preferred_width (GTK_WIDGET (menu), NULL, &menu_width);
 
-      /* sample + frame */
-      minimum_width = child_min;
-      natural_width = child_nat;
+  if (active != NULL)
+    {
+      gtk_widget_get_allocation (active, &child_allocation);
+      menu_ypos -= child_allocation.height / 2;
+    }
 
-      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;
+  children = GTK_MENU_SHELL (combo_box->priv->popup_widget)->children;
+  while (children)
+    {
+      child = children->data;
 
-              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 (active == child)
+       break;
 
-             minimum_width  += xpad;
-             natural_width  += xpad;
-           }
-        }
+      if (gtk_widget_get_visible (child))
+       {
+         gtk_widget_get_allocation (child, &child_allocation);
 
-      /* the button */
-      gtk_widget_get_preferred_width (priv->button, 
-                                      &button_width, &button_nat_width);
+         menu_ypos -= child_allocation.height;
+       }
 
-      minimum_width += button_width;
-      natural_width += button_nat_width;
+      children = children->next;
     }
 
-  minimum_width += border->left + border->right;
-  natural_width += border->left + border->right;
-  gtk_border_free (border);
+  if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
+    menu_xpos = menu_xpos + allocation.width - menu_width;
 
-  if (minimum_size)
-    *minimum_size = minimum_width;
+  gdk_window_get_root_coords (gtk_widget_get_window (widget),
+                              menu_xpos, menu_ypos,
+                             &menu_xpos, &menu_ypos);
 
-  if (natural_size)
-    *natural_size = natural_width;
-}
+  /* Clamp the position on screen */
+  screen_width = gdk_screen_get_width (gtk_widget_get_screen (widget));
+  
+  if (menu_xpos < 0)
+    menu_xpos = 0;
+  else if ((menu_xpos + menu_width) > screen_width)
+    menu_xpos -= ((menu_xpos + menu_width) - screen_width);
 
-static void
-gtk_combo_box_get_preferred_height (GtkWidget *widget,
-                                    gint      *minimum_size,
-                                    gint      *natural_size)
-{ 
-  gint min_width;
+  *x = menu_xpos;
+  *y = menu_ypos;
 
-  /* 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);
+  *push_in = TRUE;
 }
 
 static void
-gtk_combo_box_get_preferred_width_for_height (GtkWidget *widget,
-                                              gint       avail_size,
-                                              gint      *minimum_size,
-                                              gint      *natural_size)
+gtk_combo_box_menu_position (GtkMenu  *menu,
+                            gint     *x,
+                            gint     *y,
+                            gint     *push_in,
+                            gpointer  user_data)
 {
-  /* 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);
-}
+  GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
+  GtkComboBoxPrivate *priv = combo_box->priv;
+  GtkWidget *menu_item;
 
+  if (priv->wrap_width > 0 || priv->cell_view == NULL) 
+    gtk_combo_box_menu_position_below (menu, x, y, push_in, user_data);
+  else
+    {
+      /* FIXME handle nested menus better */
+      menu_item = gtk_menu_get_active (GTK_MENU (priv->popup_widget));
+      if (menu_item)
+       gtk_menu_shell_select_item (GTK_MENU_SHELL (priv->popup_widget), 
+                                   menu_item);
 
-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);
+      gtk_combo_box_menu_position_over (menu, x, y, push_in, user_data);
+    }
 
-  child = gtk_bin_get_child (GTK_BIN (widget));
+  if (!gtk_widget_get_visible (GTK_MENU (priv->popup_widget)->toplevel))
+    gtk_window_set_type_hint (GTK_WINDOW (GTK_MENU (priv->popup_widget)->toplevel),
+                              GDK_WINDOW_TYPE_HINT_COMBO);
+}
 
-  get_widget_border (widget, &border);
-  size = avail_size - border.left;
+static void
+gtk_combo_box_list_position (GtkComboBox *combo_box, 
+                            gint        *x, 
+                            gint        *y, 
+                            gint        *width,
+                            gint        *height)
+{
+  GtkComboBoxPrivate *priv = combo_box->priv;
+  GtkAllocation allocation;
+  GdkScreen *screen;
+  gint monitor_num;
+  GdkRectangle monitor;
+  GtkRequisition popup_req;
+  GtkPolicyType hpolicy, vpolicy;
+  GdkWindow *window;
 
-  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;
+  /* under windows, the drop down list is as wide as the combo box itself.
+     see bug #340204 */
+  GtkWidget *widget = GTK_WIDGET (combo_box);
 
-         border_width = gtk_container_get_border_width (GTK_CONTAINER (combo_box));
-         get_widget_border (priv->button, &button_border);
+  *x = *y = 0;
 
-          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);
+  gtk_widget_get_allocation (widget, &allocation);
 
-         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;
+  if (!gtk_widget_get_has_window (widget))
+    {
+      *x += allocation.x;
+      *y += allocation.y;
+    }
 
-         size -= sep_width + arrow_width + xpad;
+  window = gtk_widget_get_window (widget);
 
-         /* 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);
+  gdk_window_get_root_coords (gtk_widget_get_window (widget),
+                              *x, *y, x, y);
 
-         arrow_height = MAX (arrow_height, sep_height);
-         min_height = MAX (min_height, arrow_height);
-         nat_height = MAX (nat_height, arrow_height);
+  *width = allocation.width;
 
-         min_height += ypad;
-         nat_height += ypad;
-        }
-      else
-        {
-         /* there is a custom child widget inside (no priv->cell_view) */
-          gint but_width, but_height;
+  hpolicy = vpolicy = GTK_POLICY_NEVER;
+  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
+                                 hpolicy, vpolicy);
 
-          gtk_widget_get_preferred_width (priv->button, &but_width, NULL);
-          gtk_widget_get_preferred_height_for_width (priv->button, 
-                                                     but_width, &but_height, NULL);
+  /* 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);
 
-         size -= but_width;
+  if (combo_box->priv->popup_fixed_width)
+    {
+      gtk_widget_get_preferred_size (priv->scrolled_window, &popup_req, NULL);
 
-         /* 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);
-        }
+      if (popup_req.width > *width)
+       {
+         hpolicy = GTK_POLICY_ALWAYS;
+         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
+                                         hpolicy, vpolicy);
+       }
     }
   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)
+      if (priv->natural_width > *width)
        {
-         GtkBorder frame_border;
-         gint border_width;
+         hpolicy = GTK_POLICY_NEVER;
+         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
+                                         hpolicy, vpolicy);
 
-          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;
+         /* 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;
        }
+    }
 
-      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);
+  *height = popup_req.height;
 
-      min_height = MAX (min_height, but_height);
-      nat_height = MAX (nat_height, but_height);
+  screen = gtk_widget_get_screen (GTK_WIDGET (combo_box));
+  monitor_num = gdk_screen_get_monitor_at_window (screen, window);
+  gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
 
-      min_height += ypad;
-      nat_height += ypad;
-    }
+  if (gtk_widget_get_direction (GTK_WIDGET (combo_box)) == GTK_TEXT_DIR_RTL)
+    *x = *x + allocation.width - *width;
 
-  min_height += border.top + border.bottom;
-  nat_height += border.top + border.bottom;
+  if (*x < monitor.x)
+    *x = monitor.x;
+  else if (*x + *width > monitor.x + monitor.width)
+    *x = monitor.x + monitor.width - *width;
+  
+  if (*y + allocation.height + *height <= monitor.y + monitor.height)
+    *y += allocation.height;
+  else if (*y - *height >= monitor.y)
+    *y -= *height;
+  else if (monitor.y + monitor.height - (*y + allocation.height) > *y - monitor.y)
+    {
+      *y += allocation.height;
+      *height = monitor.y + monitor.height - *y;
+    }
+  else 
+    {
+      *height = *y - monitor.y;
+      *y = monitor.y;
+    }
 
-  if (minimum_size)
-    *minimum_size = min_height;
+  if (popup_req.height > *height)
+    {
+      vpolicy = GTK_POLICY_ALWAYS;
+      
+      gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
+                                     hpolicy, vpolicy);
+    }
+} 
 
-  if (natural_size)
-    *natural_size = nat_height;
-}
+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));
 
-#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);
+  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
-gtk_combo_box_size_allocate (GtkWidget     *widget,
-                             GtkAllocation *allocation)
+static gboolean
+tree_column_row_is_sensitive (GtkComboBox *combo_box,
+                             GtkTreeIter *iter)
 {
-  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);
+  GList *cells, *list;
+  gboolean sensitive;
 
-  gtk_widget_style_get (widget,
-                       "focus-line-width", &focus_width,
-                       "focus-padding", &focus_pad,
-                       NULL);
+  if (!priv->column)
+    return TRUE;
 
-  if (!priv->tree_view)
+  if (priv->row_separator_func)
     {
-      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;
+      if (priv->row_separator_func (priv->model, iter,
+                                    priv->row_separator_data))
+       return FALSE;
+    }
 
-          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));
-            }
+  gtk_tree_view_column_cell_set_cell_data (priv->column,
+                                          priv->model,
+                                          iter, FALSE, FALSE);
 
-         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
+  cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (priv->column));
 
-          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
+  sensitive = FALSE;
+  for (list = cells; list; list = list->next)
     {
-      /* 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);
+      g_object_get (list->data, "sensitive", &sensitive, NULL);
       
-      gtk_widget_size_allocate (child_widget, &child);
+      if (sensitive)
+       break;
     }
-}
-
-#undef GTK_COMBO_BOX_ALLOCATE_BUTTON
+  g_list_free (cells);
 
-/******************************************************
- *                  GtkContainerClass                 *
- ******************************************************/
+  return sensitive;
+}
 
 static void
-gtk_combo_box_add (GtkContainer *container,
-                   GtkWidget    *widget)
+update_menu_sensitivity (GtkComboBox *combo_box,
+                        GtkWidget   *menu)
 {
-  GtkComboBox *combo_box = GTK_COMBO_BOX (container);
   GtkComboBoxPrivate *priv = combo_box->priv;
+  GList *children, *child;
+  GtkWidget *item, *submenu, *separator;
+  GtkWidget *cell_view;
+  gboolean sensitive;
 
-  if (priv->has_entry && !GTK_IS_ENTRY (widget))
-    {
-      g_warning ("Attempting to add a widget with type %s to a GtkComboBox that needs an entry "
-                "(need an instance of GtkEntry or of a subclass)",
-                 G_OBJECT_TYPE_NAME (widget));
-      return;
-    }
-
-  if (priv->cell_view &&
-      gtk_widget_get_parent (priv->cell_view))
-    {
-      gtk_container_remove (container, priv->cell_view);
-      gtk_widget_queue_resize (GTK_WIDGET (container));
-    }
-
-  gtk_widget_set_parent (widget, GTK_WIDGET (container));
-  _gtk_bin_set_child (GTK_BIN (container), widget);
-
-  if (priv->cell_view &&
-      widget != priv->cell_view)
-    {
-      /* since the cell_view was unparented, it's gone now */
-      priv->cell_view = NULL;
-
-      if (!priv->tree_view && priv->separator)
-        {
-          gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (priv->separator)),
-                                priv->separator);
-         priv->separator = NULL;
-
-          gtk_widget_queue_resize (GTK_WIDGET (container));
-        }
-      else if (priv->cell_view_frame)
-        {
-          gtk_widget_unparent (priv->cell_view_frame);
-          priv->cell_view_frame = NULL;
-          priv->box = NULL;
-        }
-    }
-
-  if (priv->has_entry)
-    {
-      /* this flag is a hack to tell the entry to fill its allocation.
-       */
-      _gtk_entry_set_is_cell_renderer (GTK_ENTRY (widget), TRUE);
-
-      g_signal_connect (widget, "changed",
-                       G_CALLBACK (gtk_combo_box_entry_contents_changed),
-                       combo_box);
-
-      gtk_entry_set_has_frame (GTK_ENTRY (widget), priv->has_frame);
-    }
-}
+  if (!priv->model)
+    return;
 
-static void
-gtk_combo_box_remove (GtkContainer *container,
-                     GtkWidget    *widget)
-{
-  GtkComboBox *combo_box = GTK_COMBO_BOX (container);
-  GtkComboBoxPrivate *priv = combo_box->priv;
-  GtkTreePath *path;
-  gboolean appears_as_list;
+  children = gtk_container_get_children (GTK_CONTAINER (menu));
 
-  if (priv->has_entry)
+  for (child = children; child; child = child->next)
     {
-      GtkWidget *child_widget;
+      item = GTK_WIDGET (child->data);
+      cell_view = gtk_bin_get_child (GTK_BIN (item));
 
-      child_widget = gtk_bin_get_child (GTK_BIN (container));
-      if (widget && widget == child_widget && GTK_IS_ENTRY (widget))
+      if (!GTK_IS_CELL_VIEW (cell_view))
+       continue;
+      
+      submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (item));
+      if (submenu != NULL)
        {
-         g_signal_handlers_disconnect_by_func (widget,
-                                               gtk_combo_box_entry_contents_changed,
-                                               container);
+         gtk_widget_set_sensitive (item, TRUE);
+         update_menu_sensitivity (combo_box, submenu);
+       }
+      else
+       {
+         sensitive = cell_view_is_sensitive (GTK_CELL_VIEW (cell_view));
 
-         _gtk_entry_set_is_cell_renderer (GTK_ENTRY (widget), FALSE);
+         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);
        }
     }
 
-  if (widget == priv->cell_view)
-    priv->cell_view = NULL;
-
-  GTK_CONTAINER_CLASS (gtk_combo_box_parent_class)->remove (container, widget);
-
-  if (gtk_widget_in_destruction (GTK_WIDGET (combo_box)))
-    return;
-
-  gtk_widget_queue_resize (GTK_WIDGET (container));
+  g_list_free (children);
+}
 
-  if (!priv->tree_view)
-    appears_as_list = FALSE;
-  else
-    appears_as_list = TRUE;
+static void 
+gtk_combo_box_menu_popup (GtkComboBox *combo_box,
+                         guint        button, 
+                         guint32      activate_time)
+{
+  GtkComboBoxPrivate *priv = combo_box->priv;
+  GtkTreePath *path;
+  gint active_item;
+  gint width, min_width, nat_width;
   
-  if (appears_as_list)
-    gtk_combo_box_list_destroy (combo_box);
-  else if (GTK_IS_MENU (priv->popup_widget))
+  update_menu_sensitivity (combo_box, priv->popup_widget);
+
+  active_item = -1;
+  if (gtk_tree_row_reference_valid (priv->active_row))
     {
-      gtk_combo_box_menu_destroy (combo_box);
-      gtk_menu_detach (GTK_MENU (priv->popup_widget));
-      priv->popup_widget = NULL;
+      path = gtk_tree_row_reference_get_path (priv->active_row);
+      active_item = gtk_tree_path_get_indices (path)[0];
+      gtk_tree_path_free (path);
+      
+      if (priv->add_tearoffs)
+       active_item++;
     }
 
-  if (!priv->cell_view)
+  /* FIXME handle nested menus better */
+  gtk_menu_set_active (GTK_MENU (priv->popup_widget), active_item);
+  
+  if (priv->wrap_width == 0)
     {
-      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);
+      GtkAllocation allocation;
 
-      GTK_CONTAINER_CLASS (gtk_combo_box_parent_class)->add (container, priv->cell_view);
-      
-      gtk_widget_show (priv->cell_view);
-      gtk_cell_view_set_model (GTK_CELL_VIEW (priv->cell_view), priv->model);
-    }
+      gtk_widget_get_allocation (GTK_WIDGET (combo_box), &allocation);
+      width = allocation.width;
+      gtk_widget_set_size_request (priv->popup_widget, -1, -1);
+      gtk_widget_get_preferred_width (priv->popup_widget, &min_width, &nat_width);
 
-  if (appears_as_list)
-    gtk_combo_box_list_setup (combo_box); 
-  else
-    gtk_combo_box_menu_setup (combo_box, TRUE);
+      if (combo_box->priv->popup_fixed_width)
+       width = MAX (width, min_width);
+      else
+       width = MAX (width, nat_width);
 
-  if (gtk_tree_row_reference_valid (priv->active_row))
-    {
-      path = gtk_tree_row_reference_get_path (priv->active_row);
-      gtk_combo_box_set_active_internal (combo_box, path);
-      gtk_tree_path_free (path);
+      gtk_widget_set_size_request (priv->popup_widget, width, -1);
     }
-  else
-    gtk_combo_box_set_active_internal (combo_box, NULL);
+  
+  gtk_menu_popup (GTK_MENU (priv->popup_widget),
+                 NULL, NULL,
+                 gtk_combo_box_menu_position, combo_box,
+                 button, activate_time);
 }
 
-static void
-gtk_combo_box_forall (GtkContainer *container,
-                      gboolean      include_internals,
-                      GtkCallback   callback,
-                      gpointer      callback_data)
+static gboolean
+popup_grab_on_window (GdkWindow *window,
+                      GdkDevice *keyboard,
+                      GdkDevice *pointer,
+                     guint32    activate_time)
 {
-  GtkComboBox *combo_box = GTK_COMBO_BOX (container);
-  GtkComboBoxPrivate *priv = combo_box->priv;
-  GtkWidget *child;
+  if (keyboard &&
+      gdk_device_grab (keyboard, window,
+                       GDK_OWNERSHIP_WINDOW, TRUE,
+                       GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
+                       NULL, activate_time) != GDK_GRAB_SUCCESS)
+    return FALSE;
 
-  if (include_internals)
+  if (pointer &&
+      gdk_device_grab (pointer, window,
+                       GDK_OWNERSHIP_WINDOW, TRUE,
+                       GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
+                       GDK_POINTER_MOTION_MASK,
+                       NULL, activate_time) != GDK_GRAB_SUCCESS)
     {
-      if (priv->button)
-       (* callback) (priv->button, callback_data);
-      if (priv->cell_view_frame)
-       (* callback) (priv->cell_view_frame, callback_data);
+      if (keyboard)
+        gdk_device_ungrab (keyboard, activate_time);
+
+      return FALSE;
     }
 
-  child = gtk_bin_get_child (GTK_BIN (container));
-  if (child)
-    (* callback) (child, callback_data);
+  return TRUE;
 }
 
-
-/******************************************************
- *        GtkComboBoxClass (binding methods)          *
- ******************************************************/
-static void
-gtk_combo_box_real_move_active (GtkComboBox   *combo_box,
-                                GtkScrollType  scroll)
+/**
+ * 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)
 {
-  GtkTreeIter iter;
-  GtkTreeIter new_iter;
-  gboolean    active_iter;
-  gboolean    found;
+  g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
 
-  if (!combo_box->priv->model)
-    {
-      gtk_widget_error_bell (GTK_WIDGET (combo_box));
-      return;
-    }
+  g_signal_emit (combo_box, combo_box_signals[POPUP], 0);
+}
 
-  active_iter = gtk_combo_box_get_active_iter (combo_box, &iter);
+/**
+ * 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;
 
-  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 */
+  g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
+  g_return_if_fail (GDK_IS_DEVICE (device));
 
-    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;
+  if (!gtk_widget_get_realized (GTK_WIDGET (combo_box)))
+    return;
 
-    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 */
+  if (gtk_widget_get_mapped (priv->popup_widget))
+    return;
 
-    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;
+  if (priv->grab_pointer && priv->grab_keyboard)
+    return;
 
-    default:
-      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 (found && active_iter)
+  if (GTK_IS_MENU (priv->popup_widget))
     {
-      GtkTreePath *old_path;
-      GtkTreePath *new_path;
+      gtk_combo_box_menu_popup (combo_box, 
+                                priv->activate_button,
+                                priv->activate_time);
+      return;
+    }
 
-      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);
+  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));
 
-      if (gtk_tree_path_compare (old_path, new_path) == 0)
-        found = FALSE;
+  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);
 
-      gtk_tree_path_free (old_path);
-      gtk_tree_path_free (new_path);
+  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 (found)
+  if (path)
     {
-      gtk_combo_box_set_active_iter (combo_box, &new_iter);
+      gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->tree_view),
+                               path, NULL, FALSE);
+      gtk_tree_path_free (path);
     }
-  else
+
+  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_error_bell (GTK_WIDGET (combo_box));
+      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
@@ -2612,602 +2321,607 @@ gtk_combo_box_real_popdown (GtkComboBox *combo_box)
   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)
+/**
+ * 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)
 {
-  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);
+  g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
 
-  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
+  if (GTK_IS_MENU (priv->popup_widget))
     {
-      if (!combo_box->priv->popup_in_progress)
-        gtk_combo_box_popup (combo_box);
+      gtk_menu_popdown (GTK_MENU (priv->popup_widget));
+      return;
     }
-  else
-    gtk_combo_box_popdown (combo_box);
-}
-
-static void
-gtk_combo_box_menu_show (GtkWidget *menu,
-                         gpointer   user_data)
-{
-  GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
-  GtkComboBoxPrivate *priv = combo_box->priv;
 
-  gtk_combo_box_child_show (menu, user_data);
+  if (!gtk_widget_get_realized (GTK_WIDGET (combo_box)))
+    return;
 
-  priv->popup_in_progress = TRUE;
+  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),
-                                TRUE);
-  priv->popup_in_progress = FALSE;
-}
+                                FALSE);
 
-static void
-gtk_combo_box_menu_hide (GtkWidget *menu,
-                         gpointer   user_data)
-{
-  GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
+  priv->grab_pointer = NULL;
+  priv->grab_keyboard = NULL;
+}
 
-  gtk_combo_box_child_hide (menu,user_data);
+#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);
 
-  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
-                                FALSE);
-}
 
 static void
-gtk_combo_box_detacher (GtkWidget *widget,
-                       GtkMenu   *menu)
+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;
 
-  g_return_if_fail (priv->popup_widget == (GtkWidget *) menu);
-
-  g_signal_handlers_disconnect_by_func (menu->toplevel,
-                                       gtk_combo_box_menu_show,
-                                       combo_box);
-  g_signal_handlers_disconnect_by_func (menu->toplevel,
-                                       gtk_combo_box_menu_hide,
-                                       combo_box);
-  
-  priv->popup_widget = NULL;
-}
-
-static void
-gtk_combo_box_set_popup_widget (GtkComboBox *combo_box,
-                                GtkWidget   *popup)
-{
-  GtkComboBoxPrivate *priv = combo_box->priv;
+  gtk_widget_set_allocation (widget, allocation);
+  child_widget = gtk_bin_get_child (GTK_BIN (widget));
+  get_widget_border (widget, &border);
 
-  if (GTK_IS_MENU (priv->popup_widget))
-    {
-      gtk_menu_detach (GTK_MENU (priv->popup_widget));
-      priv->popup_widget = NULL;
-    }
-  else if (priv->popup_widget)
-    {
-      gtk_container_remove (GTK_CONTAINER (priv->scrolled_window),
-                            priv->popup_widget);
-      g_object_unref (priv->popup_widget);
-      priv->popup_widget = NULL;
-    }
+  gtk_widget_style_get (widget,
+                       "focus-line-width", &focus_width,
+                       "focus-padding", &focus_pad,
+                       NULL);
 
-  if (GTK_IS_MENU (popup))
+  if (!priv->tree_view)
     {
-      if (priv->popup_window)
+      if (priv->cell_view)
         {
-          gtk_widget_destroy (priv->popup_window);
-          priv->popup_window = NULL;
-        }
+         GtkBorder button_border;
+          gint width;
+          guint border_width;
 
-      priv->popup_widget = popup;
+          /* menu mode */
+          allocation->x += border.left;
+          allocation->y += border.top;
+          allocation->width -= border.left + border.right;
+          allocation->height -= border.top + border.bottom;
 
-      /* 
-       * Note that we connect to show/hide on the toplevel, not the
-       * menu itself, since the menu is not shown/hidden when it is
-       * popped up while torn-off.
-       */
-      g_signal_connect (GTK_MENU (popup)->toplevel, "show",
-                        G_CALLBACK (gtk_combo_box_menu_show), combo_box);
-      g_signal_connect (GTK_MENU (popup)->toplevel, "hide",
-                        G_CALLBACK (gtk_combo_box_menu_hide), combo_box);
+          gtk_widget_size_allocate (priv->button, allocation);
 
-      gtk_menu_attach_to_widget (GTK_MENU (popup),
-                                GTK_WIDGET (combo_box),
-                                gtk_combo_box_detacher);
-    }
-  else
-    {
-      if (!priv->popup_window)
-        {
-         GtkWidget *toplevel;
-         
-          priv->popup_window = gtk_window_new (GTK_WINDOW_POPUP);
-          gtk_widget_set_name (priv->popup_window, "gtk-combobox-popup-window");
+          /* set some things ready */
+          border_width = gtk_container_get_border_width (GTK_CONTAINER (priv->button));
+         get_widget_border (priv->button, &button_border);
 
-         gtk_window_set_type_hint (GTK_WINDOW (priv->popup_window),
-                                   GDK_WINDOW_TYPE_HINT_COMBO);
+          child.x = allocation->x;
+          child.y = allocation->y;
+         width = allocation->width;
+         child.height = allocation->height;
 
-         g_signal_connect (GTK_WINDOW (priv->popup_window),"show",
-                           G_CALLBACK (gtk_combo_box_child_show),
-                           combo_box);
-         g_signal_connect (GTK_WINDOW (priv->popup_window),"hide",
-                           G_CALLBACK (gtk_combo_box_child_hide),
-                           combo_box);
-         
-         toplevel = gtk_widget_get_toplevel (GTK_WIDGET (combo_box));
-         if (GTK_IS_WINDOW (toplevel))
+         if (!priv->is_cell_renderer)
            {
-             gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)), 
-                                          GTK_WINDOW (priv->popup_window));
-             gtk_window_set_transient_for (GTK_WINDOW (priv->popup_window),
-                                           GTK_WINDOW (toplevel));
+             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;
            }
 
-         gtk_window_set_resizable (GTK_WINDOW (priv->popup_window), FALSE);
-          gtk_window_set_screen (GTK_WINDOW (priv->popup_window),
-                                 gtk_widget_get_screen (GTK_WIDGET (combo_box)));
+          /* 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);
 
-         priv->scrolled_window = gtk_scrolled_window_new (NULL, NULL);
-         
-         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
-                                         GTK_POLICY_NEVER,
-                                         GTK_POLICY_NEVER);
-         gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (priv->scrolled_window),
-                                              GTK_SHADOW_IN);
+          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;
+            }
 
-          gtk_widget_show (priv->scrolled_window);
-         
-         gtk_container_add (GTK_CONTAINER (priv->popup_window),
-                            priv->scrolled_window);
-        }
+          if (gtk_widget_get_visible (priv->popup_widget))
+            {
+              gint width, menu_width;
 
-      gtk_container_add (GTK_CONTAINER (priv->scrolled_window),
-                         popup);
+              if (priv->wrap_width == 0)
+                {
+                  GtkAllocation combo_box_allocation;
 
-      gtk_widget_show (popup);
-      g_object_ref (popup);
-      priv->popup_widget = popup;
-    }
-}
+                  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);
 
-static void
-gtk_combo_box_menu_position_below (GtkMenu  *menu,
-                                  gint     *x,
-                                  gint     *y,
-                                  gint     *push_in,
-                                  gpointer  user_data)
-{
-  GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
-  GtkAllocation child_allocation;
-  gint sx, sy;
-  GtkWidget *child;
-  GtkRequisition req;
-  GdkScreen *screen;
-  gint monitor_num;
-  GdkRectangle monitor;
-  GtkBorder border;
-  
-  /* FIXME: is using the size request here broken? */
-  child = gtk_bin_get_child (GTK_BIN (combo_box));
+                 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);
 
-  sx = sy = 0;
+                  gtk_widget_set_size_request (priv->popup_widget,
+                                              MAX (width, menu_width), -1);
+               }
 
-  gtk_widget_get_allocation (child, &child_allocation);
+              /* reposition the menu after giving it a new width */
+              gtk_menu_reposition (GTK_MENU (priv->popup_widget));
+            }
 
-  if (!gtk_widget_get_has_window (child))
-    {
-      sx += child_allocation.x;
-      sy += child_allocation.y;
-    }
+         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
 
-  gdk_window_get_root_coords (gtk_widget_get_window (child),
-                              sx, sy, &sx, &sy);
+          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));
 
-  get_widget_border (GTK_WIDGET (combo_box), &border);
-  sx -= border.left;
+      /* button */
+      GTK_COMBO_BOX_SIZE_ALLOCATE_BUTTON
 
-  if (combo_box->priv->popup_fixed_width)
-    gtk_widget_get_preferred_size (GTK_WIDGET (menu), &req, NULL);
-  else
-    gtk_widget_get_preferred_size (GTK_WIDGET (menu), NULL, &req);
+      /* frame */
+      if (is_rtl)
+        child.x = allocation->x + req.width;
+      else
+        child.x = allocation->x;
 
-  if (gtk_widget_get_direction (GTK_WIDGET (combo_box)) == GTK_TEXT_DIR_LTR)
-    *x = sx;
-  else
-    *x = sx + child_allocation.width - req.width;
-  *y = sy;
+      child.y = allocation->y;
+      child.width = allocation->width - req.width;
+      child.height = allocation->height;
 
-  screen = gtk_widget_get_screen (GTK_WIDGET (combo_box));
-  monitor_num = gdk_screen_get_monitor_at_window (screen, 
-                                                  gtk_widget_get_window (GTK_WIDGET (combo_box)));
-  gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
-  
-  if (*x < monitor.x)
-    *x = monitor.x;
-  else if (*x + req.width > monitor.x + monitor.width)
-    *x = monitor.x + monitor.width - req.width;
-  
-  if (monitor.y + monitor.height - *y - child_allocation.height >= req.height)
-    *y += child_allocation.height;
-  else if (*y - monitor.y >= req.height)
-    *y -= req.height;
-  else if (monitor.y + monitor.height - *y - child_allocation.height > *y - monitor.y)
-    *y += child_allocation.height;
-  else
-    *y -= req.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);
 
-   *push_in = FALSE;
-}
+          /* the sample */
+          if (priv->has_frame)
+            {
+             GtkBorder frame_border;
 
-static void
-gtk_combo_box_menu_position_over (GtkMenu  *menu,
-                                 gint     *x,
-                                 gint     *y,
-                                 gboolean *push_in,
-                                 gpointer  user_data)
-{
-  GtkComboBox    *combo_box;
-  GtkWidget      *active;
-  GtkWidget      *child;
-  GtkWidget      *widget;
-  GtkAllocation   allocation;
-  GtkAllocation   child_allocation;
-  GList          *children;
-  gint            screen_width;
-  gint            menu_xpos;
-  gint            menu_ypos;
-  gint            menu_width;
+              border_width = gtk_container_get_border_width (GTK_CONTAINER (priv->cell_view_frame));
+             get_widget_border (priv->cell_view_frame, &frame_border);
 
-  combo_box = GTK_COMBO_BOX (user_data);
-  widget = GTK_WIDGET (combo_box);
+              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);
+        }
 
-  active = gtk_menu_get_active (GTK_MENU (combo_box->priv->popup_widget));
+      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);
+        }
 
-  gtk_widget_get_allocation (widget, &allocation);
+      
+      child.width = MAX (1, child.width);
+      child.height = MAX (1, child.height);
+      
+      gtk_widget_size_allocate (child_widget, &child);
+    }
+}
 
-  menu_xpos = allocation.x;
-  menu_ypos = allocation.y + allocation.height / 2 - 2;
+#undef GTK_COMBO_BOX_ALLOCATE_BUTTON
 
-  if (combo_box->priv->popup_fixed_width)
-    gtk_widget_get_preferred_width (GTK_WIDGET (menu), &menu_width, NULL);
-  else
-    gtk_widget_get_preferred_width (GTK_WIDGET (menu), NULL, &menu_width);
+static void
+gtk_combo_box_unset_model (GtkComboBox *combo_box)
+{
+  GtkComboBoxPrivate *priv = combo_box->priv;
 
-  if (active != NULL)
+  if (priv->model)
     {
-      gtk_widget_get_allocation (active, &child_allocation);
-      menu_ypos -= child_allocation.height / 2;
+      g_signal_handler_disconnect (priv->model,
+                                  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);
     }
 
-  children = GTK_MENU_SHELL (combo_box->priv->popup_widget)->children;
-  while (children)
+  if (priv->model)
     {
-      child = children->data;
-
-      if (active == child)
-       break;
-
-      if (gtk_widget_get_visible (child))
-       {
-         gtk_widget_get_allocation (child, &child_allocation);
-
-         menu_ypos -= child_allocation.height;
-       }
-
-      children = children->next;
+      g_object_unref (priv->model);
+      priv->model = NULL;
     }
 
-  if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
-    menu_xpos = menu_xpos + allocation.width - menu_width;
+  if (priv->active_row)
+    {
+      gtk_tree_row_reference_free (priv->active_row);
+      priv->active_row = NULL;
+    }
 
-  gdk_window_get_root_coords (gtk_widget_get_window (widget),
-                              menu_xpos, menu_ypos,
-                             &menu_xpos, &menu_ypos);
+  if (priv->cell_view)
+    gtk_cell_view_set_model (GTK_CELL_VIEW (priv->cell_view), NULL);
+}
 
-  /* Clamp the position on screen */
-  screen_width = gdk_screen_get_width (gtk_widget_get_screen (widget));
-  
-  if (menu_xpos < 0)
-    menu_xpos = 0;
-  else if ((menu_xpos + menu_width) > screen_width)
-    menu_xpos -= ((menu_xpos + menu_width) - screen_width);
+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;
 
-  *x = menu_xpos;
-  *y = menu_ypos;
+  if (include_internals)
+    {
+      if (priv->button)
+       (* callback) (priv->button, callback_data);
+      if (priv->cell_view_frame)
+       (* callback) (priv->cell_view_frame, callback_data);
+    }
 
-  *push_in = TRUE;
+  child = gtk_bin_get_child (GTK_BIN (container));
+  if (child)
+    (* callback) (child, callback_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_child_show (GtkWidget *widget,
+                          GtkComboBox *combo_box)
 {
-  GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
   GtkComboBoxPrivate *priv = combo_box->priv;
-  GtkWidget *menu_item;
 
-  if (priv->wrap_width > 0 || priv->cell_view == NULL) 
-    gtk_combo_box_menu_position_below (menu, x, y, push_in, user_data);
-  else
-    {
-      /* FIXME handle nested menus better */
-      menu_item = gtk_menu_get_active (GTK_MENU (priv->popup_widget));
-      if (menu_item)
-       gtk_menu_shell_select_item (GTK_MENU_SHELL (priv->popup_widget), 
-                                   menu_item);
+  priv->popup_shown = TRUE;
+  g_object_notify (G_OBJECT (combo_box), "popup-shown");
+}
 
-      gtk_combo_box_menu_position_over (menu, x, y, push_in, user_data);
-    }
+static void 
+gtk_combo_box_child_hide (GtkWidget *widget,
+                          GtkComboBox *combo_box)
+{
+  GtkComboBoxPrivate *priv = combo_box->priv;
 
-  if (!gtk_widget_get_visible (GTK_MENU (priv->popup_widget)->toplevel))
-    gtk_window_set_type_hint (GTK_WINDOW (GTK_MENU (priv->popup_widget)->toplevel),
-                              GDK_WINDOW_TYPE_HINT_COMBO);
+  priv->popup_shown = FALSE;
+  g_object_notify (G_OBJECT (combo_box), "popup-shown");
 }
 
-static void
-gtk_combo_box_list_position (GtkComboBox *combo_box, 
-                            gint        *x, 
-                            gint        *y, 
-                            gint        *width,
-                            gint        *height)
+static gboolean
+gtk_combo_box_draw (GtkWidget *widget,
+                    cairo_t   *cr)
 {
+  GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
   GtkComboBoxPrivate *priv = combo_box->priv;
-  GtkAllocation allocation;
-  GdkScreen *screen;
-  gint monitor_num;
-  GdkRectangle monitor;
-  GtkRequisition popup_req;
-  GtkPolicyType hpolicy, vpolicy;
-  GdkWindow *window;
 
-  /* under windows, the drop down list is as wide as the combo box itself.
-     see bug #340204 */
-  GtkWidget *widget = GTK_WIDGET (combo_box);
+  if (priv->shadow_type != GTK_SHADOW_NONE)
+    {
+      GtkStyleContext *context;
+      GtkStateFlags state;
 
-  *x = *y = 0;
+      context = gtk_widget_get_style_context (widget);
+      state = gtk_widget_get_state_flags (widget);
+      gtk_style_context_set_state (context, state);
 
-  gtk_widget_get_allocation (widget, &allocation);
+      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));
+    }
 
-  if (!gtk_widget_get_has_window (widget))
+  gtk_container_propagate_draw (GTK_CONTAINER (widget),
+                               priv->button, cr);
+
+  if (priv->tree_view && priv->cell_view_frame)
     {
-      *x += allocation.x;
-      *y += allocation.y;
+      gtk_container_propagate_draw (GTK_CONTAINER (widget),
+                                   priv->cell_view_frame, cr);
     }
 
-  window = gtk_widget_get_window (widget);
+  gtk_container_propagate_draw (GTK_CONTAINER (widget),
+                                gtk_bin_get_child (GTK_BIN (widget)),
+                                cr);
 
-  gdk_window_get_root_coords (gtk_widget_get_window (widget),
-                              *x, *y, x, y);
+  return FALSE;
+}
 
-  *width = allocation.width;
+typedef struct {
+  GtkComboBox *combo;
+  GtkTreePath *path;
+  GtkTreeIter iter;
+  gboolean found;
+  gboolean set;
+  gboolean visible;
+} SearchData;
 
-  hpolicy = vpolicy = GTK_POLICY_NEVER;
-  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
-                                 hpolicy, vpolicy);
+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);
+}
 
-  if (combo_box->priv->popup_fixed_width)
-    {
-      gtk_widget_get_preferred_size (priv->scrolled_window, &popup_req, NULL);
+static gboolean
+tree_next_func (GtkTreeModel *model,
+               GtkTreePath  *path,
+               GtkTreeIter  *iter,
+               gpointer      data)
+{
+  SearchData *search_data = (SearchData *)data;
 
-      if (popup_req.width > *width)
-       {
-         hpolicy = GTK_POLICY_ALWAYS;
-         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
-                                         hpolicy, vpolicy);
-       }
-    }
-  else
+  if (search_data->found) 
     {
-      /* This code depends on treeviews properly reporting their natural width */
-      gtk_widget_get_preferred_size (priv->scrolled_window, NULL, &popup_req);
+      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;
 
-      if (popup_req.width > *width)
-       {
-         hpolicy = GTK_POLICY_NEVER;
-         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
-                                         hpolicy, vpolicy);
+      search_data->set = TRUE;
+      search_data->iter = *iter;
 
-         *width = popup_req.width;
-       }
+      return TRUE;
     }
+  if (gtk_tree_path_compare (path, search_data->path) == 0)
+    search_data->found = TRUE;
+  
+  return FALSE;
+}
 
-  *height = popup_req.height;
-
-  screen = gtk_widget_get_screen (GTK_WIDGET (combo_box));
-  monitor_num = gdk_screen_get_monitor_at_window (screen, window);
-  gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
+static gboolean
+tree_next (GtkComboBox  *combo,
+          GtkTreeModel *model,
+          GtkTreeIter  *iter,
+          GtkTreeIter  *next,
+          gboolean      visible)
+{
+  SearchData search_data;
 
-  if (gtk_widget_get_direction (GTK_WIDGET (combo_box)) == GTK_TEXT_DIR_RTL)
-    *x = *x + allocation.width - *width;
+  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;
 
-  if (*x < monitor.x)
-    *x = monitor.x;
-  else if (*x + *width > monitor.x + monitor.width)
-    *x = monitor.x + monitor.width - *width;
+  gtk_tree_model_foreach (model, tree_next_func, &search_data);
   
-  if (*y + allocation.height + *height <= monitor.y + monitor.height)
-    *y += allocation.height;
-  else if (*y - *height >= monitor.y)
-    *y -= *height;
-  else if (monitor.y + monitor.height - (*y + allocation.height) > *y - monitor.y)
-    {
-      *y += allocation.height;
-      *height = monitor.y + monitor.height - *y;
-    }
-  else 
-    {
-      *height = *y - monitor.y;
-      *y = monitor.y;
-    }
+  *next = search_data.iter;
 
-  if (popup_req.height > *height)
-    {
-      vpolicy = GTK_POLICY_ALWAYS;
-      
-      gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
-                                     hpolicy, vpolicy);
-    }
-} 
+  gtk_tree_path_free (search_data.path);
 
-static void 
-gtk_combo_box_menu_popup (GtkComboBox *combo_box,
-                         guint        button, 
-                         guint32      activate_time)
+  return search_data.set;
+}
+
+static gboolean
+tree_prev_func (GtkTreeModel *model,
+               GtkTreePath  *path,
+               GtkTreeIter  *iter,
+               gpointer      data)
 {
-  GtkComboBoxPrivate *priv = combo_box->priv;
-  GtkTreePath *path;
-  gint active_item;
-  gint width, min_width, nat_width;
-  
-  active_item = -1;
-  if (gtk_tree_row_reference_valid (priv->active_row))
+  SearchData *search_data = (SearchData *)data;
+
+  if (gtk_tree_path_compare (path, search_data->path) == 0)
     {
-      path = gtk_tree_row_reference_get_path (priv->active_row);
-      active_item = gtk_tree_path_get_indices (path)[0];
-      gtk_tree_path_free (path);
-      
-      if (priv->add_tearoffs)
-       active_item++;
+      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;
 
-  /* FIXME handle nested menus better */
-  gtk_menu_set_active (GTK_MENU (priv->popup_widget), active_item);
+  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);
   
-  if (priv->wrap_width == 0)
-    {
-      GtkAllocation allocation;
+  *prev = search_data.iter;
 
-      gtk_widget_get_allocation (GTK_WIDGET (combo_box), &allocation);
-      width = allocation.width;
-      gtk_widget_set_size_request (priv->popup_widget, -1, -1);
-      gtk_widget_get_preferred_width (priv->popup_widget, &min_width, &nat_width);
+  gtk_tree_path_free (search_data.path);
 
-      if (combo_box->priv->popup_fixed_width)
-       width = MAX (width, min_width);
-      else
-       width = MAX (width, nat_width);
+  return search_data.set;
+}
 
-      gtk_widget_set_size_request (priv->popup_widget, width, -1);
-    }
+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; 
   
-  gtk_menu_popup (GTK_MENU (priv->popup_widget),
-                 NULL, NULL,
-                 gtk_combo_box_menu_position, combo_box,
-                 button, activate_time);
+  search_data->set = TRUE;
+  search_data->iter = *iter;
+  
+  return FALSE; 
 }
 
 static gboolean
-popup_grab_on_window (GdkWindow *window,
-                      GdkDevice *keyboard,
-                      GdkDevice *pointer,
-                     guint32    activate_time)
+tree_last (GtkComboBox  *combo,
+          GtkTreeModel *model,
+          GtkTreeIter  *last,
+          gboolean      visible)
 {
-  if (keyboard &&
-      gdk_device_grab (keyboard, window,
-                       GDK_OWNERSHIP_WINDOW, TRUE,
-                       GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
-                       NULL, activate_time) != GDK_GRAB_SUCCESS)
-    return FALSE;
+  SearchData search_data;
 
-  if (pointer &&
-      gdk_device_grab (pointer, window,
-                       GDK_OWNERSHIP_WINDOW, TRUE,
-                       GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
-                       GDK_POINTER_MOTION_MASK,
-                       NULL, activate_time) != GDK_GRAB_SUCCESS)
-    {
-      if (keyboard)
-        gdk_device_ungrab (keyboard, activate_time);
+  search_data.combo = combo;
+  search_data.visible = visible;
+  search_data.set = FALSE;
 
-      return FALSE;
-    }
+  gtk_tree_model_foreach (model, tree_last_func, &search_data);
+  
+  *last = search_data.iter;
 
-  return TRUE;
+  return search_data.set;  
 }
 
-static void
-gtk_combo_box_unset_model (GtkComboBox *combo_box)
-{
-  GtkComboBoxPrivate *priv = combo_box->priv;
-
-  if (priv->model)
-    {
-      g_signal_handler_disconnect (priv->model,
-                                  priv->inserted_id);
-      g_signal_handler_disconnect (priv->model,
-                                  priv->deleted_id);
-
-      g_object_unref (priv->model);
-      priv->model = NULL;
-    }
 
-  if (priv->active_row)
-    {
-      gtk_tree_row_reference_free (priv->active_row);
-      priv->active_row = NULL;
-    }
+static gboolean
+tree_first_func (GtkTreeModel *model,
+                GtkTreePath  *path,
+                GtkTreeIter  *iter,
+                gpointer      data)
+{
+  SearchData *search_data = (SearchData *)data;
 
-  if (priv->cell_view)
-    gtk_cell_view_set_model (GTK_CELL_VIEW (priv->cell_view), NULL);
+  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 void 
-gtk_combo_box_child_show (GtkWidget *widget,
-                          GtkComboBox *combo_box)
+static gboolean
+tree_first (GtkComboBox  *combo,
+           GtkTreeModel *model,
+           GtkTreeIter  *first,
+           gboolean      visible)
 {
-  GtkComboBoxPrivate *priv = combo_box->priv;
+  SearchData search_data;
+  
+  search_data.combo = combo;
+  search_data.visible = visible;
+  search_data.set = FALSE;
 
-  priv->popup_shown = TRUE;
-  g_object_notify (G_OBJECT (combo_box), "popup-shown");
+  gtk_tree_model_foreach (model, tree_first_func, &search_data);
+  
+  *first = search_data.iter;
+
+  return search_data.set;  
 }
 
-static void 
-gtk_combo_box_child_hide (GtkWidget *widget,
-                          GtkComboBox *combo_box)
+static gboolean
+gtk_combo_box_scroll_event (GtkWidget          *widget,
+                            GdkEventScroll     *event)
 {
-  GtkComboBoxPrivate *priv = combo_box->priv;
+  GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
+  gboolean found;
+  GtkTreeIter iter;
+  GtkTreeIter new_iter;
 
-  priv->popup_shown = FALSE;
-  g_object_notify (G_OBJECT (combo_box), "popup-shown");
+  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;
 }
 
 /*
@@ -3238,21 +2952,6 @@ gtk_combo_box_header_func (GtkTreeModel      *model,
   return TRUE;
 }
 
-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 +3003,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 +3052,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,
@@ -3394,6 +3095,22 @@ gtk_combo_box_menu_button_press (GtkWidget      *widget,
   return FALSE;
 }
 
+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)
 {
@@ -3420,12 +3137,81 @@ gtk_combo_box_update_sensitivity (GtkComboBox *combo_box)
         break;
     }
 
-  gtk_widget_set_sensitive (combo_box->priv->button, sensitive);
+  gtk_widget_set_sensitive (combo_box->priv->button, sensitive);
+
+  /* In list-mode, we also need to update sensitivity of the event box */
+  if (GTK_IS_TREE_VIEW (combo_box->priv->tree_view)
+      && combo_box->priv->cell_view)
+    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;
 
-  /* In list-mode, we also need to update sensitivity of the event box */
-  if (GTK_IS_TREE_VIEW (combo_box->priv->tree_view)
-      && combo_box->priv->cell_view)
-    gtk_widget_set_sensitive (combo_box->priv->box, sensitive);
+  /* 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
@@ -3469,6 +3255,7 @@ gtk_combo_box_model_row_expanded (GtkTreeModel     *model,
   gtk_combo_box_list_popup_resize (combo_box);
 }
 
+
 /*
  * list style
  */
@@ -3552,10 +3339,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,805 +3762,987 @@ gtk_combo_box_list_select_func (GtkTreeSelection *selection,
   return sensitive;
 }
 
+static void
+gtk_combo_box_list_row_changed (GtkTreeModel *model,
+                                GtkTreePath  *path,
+                                GtkTreeIter  *iter,
+                                gpointer      data)
+{
+  /* XXX Do nothing ? */
+}
 
 /*
- * GtkCellEditable implementation
+ * GtkCellLayout implementation
  */
-
-static void
-gtk_combo_box_cell_editable_init (GtkCellEditableIface *iface)
+GtkCellArea *
+gtk_combo_box_cell_layout_get_area (GtkCellLayout    *cell_layout)
 {
-  iface->start_editing = gtk_combo_box_start_editing;
+  return GTK_COMBO_BOX (cell_layout)->priv->area;
 }
 
-static gboolean
-gtk_cell_editable_key_press (GtkWidget   *widget,
-                            GdkEventKey *event,
-                            gpointer     data)
-{
-  GtkComboBox *combo_box = GTK_COMBO_BOX (data);
+/*
+ * public API
+ */
 
-  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;
-    }
+/**
+ * gtk_combo_box_new:
+ *
+ * Creates a new empty #GtkComboBox.
+ *
+ * Return value: A new #GtkComboBox.
+ *
+ * Since: 2.4
+ */
+GtkWidget *
+gtk_combo_box_new (void)
+{
+  return g_object_new (GTK_TYPE_COMBO_BOX, NULL);
+}
 
-  return FALSE;
+/**
+ * gtk_combo_box_new_with_entry:
+ *
+ * Creates a new empty #GtkComboBox with an entry.
+ *
+ * Return value: A new #GtkComboBox.
+ */
+GtkWidget *
+gtk_combo_box_new_with_entry (void)
+{
+  return g_object_new (GTK_TYPE_COMBO_BOX, "has-entry", TRUE, NULL);
 }
 
-static gboolean
-popdown_idle (gpointer data)
+/**
+ * gtk_combo_box_new_with_model:
+ * @model: A #GtkTreeModel.
+ *
+ * Creates a new #GtkComboBox with the model initialized to @model.
+ *
+ * Return value: A new #GtkComboBox.
+ *
+ * Since: 2.4
+ */
+GtkWidget *
+gtk_combo_box_new_with_model (GtkTreeModel *model)
 {
   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_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
 
-  g_object_unref (combo_box);
+  combo_box = g_object_new (GTK_TYPE_COMBO_BOX, "model", model, NULL);
 
-  return FALSE;
+  return GTK_WIDGET (combo_box);
 }
 
-static void
-popdown_handler (GtkWidget *widget,
-                gpointer   data)
+/**
+ * gtk_combo_box_new_with_model_and_entry:
+ * @model: A #GtkTreeModel
+ *
+ * Creates a new empty #GtkComboBox with an entry
+ * and with the model initialized to @model.
+ *
+ * Return value: A new #GtkComboBox
+ */
+GtkWidget *
+gtk_combo_box_new_with_model_and_entry (GtkTreeModel *model)
 {
-  gdk_threads_add_idle (popdown_idle, g_object_ref (data));
+  return g_object_new (GTK_TYPE_COMBO_BOX,
+                       "has-entry", TRUE,
+                       "model", model,
+                       NULL);
 }
 
-static gboolean
-popup_idle (gpointer data)
+/**
+ * gtk_combo_box_get_wrap_width:
+ * @combo_box: A #GtkComboBox
+ *
+ * Returns the wrap width which is used to determine the number of columns 
+ * for the popup menu. If the wrap width is larger than 1, the combo box 
+ * is in table mode.
+ *
+ * Returns: the wrap width.
+ *
+ * Since: 2.6
+ */
+gint
+gtk_combo_box_get_wrap_width (GtkComboBox *combo_box)
 {
-  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;
+  g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), -1);
 
-  return FALSE;
+  return combo_box->priv->wrap_width;
 }
 
-static void
-gtk_combo_box_start_editing (GtkCellEditable *cell_editable,
-                            GdkEvent        *event)
+/**
+ * gtk_combo_box_set_wrap_width:
+ * @combo_box: A #GtkComboBox
+ * @width: Preferred number of columns
+ *
+ * Sets the wrap width of @combo_box to be @width. The wrap width is basically
+ * the preferred number of columns when you want the popup to be layed out
+ * in a table.
+ *
+ * Since: 2.4
+ */
+void
+gtk_combo_box_set_wrap_width (GtkComboBox *combo_box,
+                              gint         width)
 {
-  GtkComboBox *combo_box = GTK_COMBO_BOX (cell_editable);
-  GtkWidget *child;
+  GtkComboBoxPrivate *priv;
 
-  combo_box->priv->is_cell_renderer = TRUE;
+  g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
+  g_return_if_fail (width >= 0);
 
-  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);  
+  priv = combo_box->priv;
 
-      gtk_widget_grab_focus (combo_box->priv->button);
-    }
-  else
+  if (width != priv->wrap_width)
     {
-      child = gtk_bin_get_child (GTK_BIN (combo_box));
+      priv->wrap_width = width;
 
-      g_signal_connect_object (child, "key-press-event",
-                              G_CALLBACK (gtk_cell_editable_key_press), 
-                              cell_editable, 0);  
+      gtk_combo_box_check_appearance (combo_box);
 
-      gtk_widget_grab_focus (child);
-      gtk_widget_set_can_focus (combo_box->priv->button, FALSE);
+      if (GTK_IS_TREE_MENU (priv->popup_widget))
+       gtk_tree_menu_set_wrap_width (GTK_TREE_MENU (priv->popup_widget), priv->wrap_width);
+      
+      g_object_notify (G_OBJECT (combo_box), "wrap-width");
     }
+}
 
-  /* 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)
+/**
+ * gtk_combo_box_get_row_span_column:
+ * @combo_box: A #GtkComboBox
+ *
+ * Returns the column with row span information for @combo_box.
+ *
+ * Returns: the row span column.
+ *
+ * Since: 2.6
+ */
+gint
+gtk_combo_box_get_row_span_column (GtkComboBox *combo_box)
+{
+  g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), -1);
+
+  return combo_box->priv->row_column;
+}
+
+/**
+ * gtk_combo_box_set_row_span_column:
+ * @combo_box: A #GtkComboBox.
+ * @row_span: A column in the model passed during construction.
+ *
+ * Sets the column with row span information for @combo_box to be @row_span.
+ * The row span column contains integers which indicate how many rows
+ * an item should span.
+ *
+ * Since: 2.4
+ */
+void
+gtk_combo_box_set_row_span_column (GtkComboBox *combo_box,
+                                   gint         row_span)
+{
+  GtkComboBoxPrivate *priv;
+  gint col;
+
+  g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
+
+  priv = combo_box->priv;
+
+  col = gtk_tree_model_get_n_columns (priv->model);
+  g_return_if_fail (row_span >= -1 && row_span < col);
+
+  if (row_span != priv->row_column)
     {
-      if (event && event->type == GDK_BUTTON_PRESS)
-        {
-          GdkEventButton *event_button = (GdkEventButton *)event;
+      priv->row_column = row_span;
 
-          combo_box->priv->activate_button = event_button->button;
-          combo_box->priv->activate_time = event_button->time;
-        }
+      if (GTK_IS_TREE_MENU (priv->popup_widget))
+       gtk_tree_menu_set_row_span_column (GTK_TREE_MENU (priv->popup_widget), priv->row_column);
 
-      combo_box->priv->popup_idle_id = 
-          gdk_threads_add_idle (popup_idle, combo_box);
+      g_object_notify (G_OBJECT (combo_box), "row-span-column");
     }
 }
 
-
-/*
- * GtkCellLayout implementation
+/**
+ * gtk_combo_box_get_column_span_column:
+ * @combo_box: A #GtkComboBox
+ *
+ * Returns the column with column span information for @combo_box.
+ *
+ * Returns: the column span column.
+ *
+ * Since: 2.6
  */
-
-static void
-gtk_combo_box_cell_layout_init (GtkCellLayoutIface *iface)
+gint
+gtk_combo_box_get_column_span_column (GtkComboBox *combo_box)
 {
-  iface->get_area = gtk_combo_box_cell_layout_get_area;
+  g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), -1);
+
+  return combo_box->priv->col_column;
 }
 
-static GtkCellArea *
-gtk_combo_box_cell_layout_get_area (GtkCellLayout *layout)
+/**
+ * gtk_combo_box_set_column_span_column:
+ * @combo_box: A #GtkComboBox
+ * @column_span: A column in the model passed during construction
+ *
+ * Sets the column with column span information for @combo_box to be
+ * @column_span. The column span column contains integers which indicate
+ * how many columns an item should span.
+ *
+ * Since: 2.4
+ */
+void
+gtk_combo_box_set_column_span_column (GtkComboBox *combo_box,
+                                      gint         column_span)
 {
-  GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
   GtkComboBoxPrivate *priv;
+  gint col;
+
+  g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
 
   priv = combo_box->priv;
 
-  return priv->area;
-}
+  col = gtk_tree_model_get_n_columns (priv->model);
+  g_return_if_fail (column_span >= -1 && column_span < col);
 
-/*
- * GtkBuildable implementation
- */
+  if (column_span != priv->col_column)
+    {
+      priv->col_column = column_span;
 
-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;
+      if (GTK_IS_TREE_MENU (priv->popup_widget))
+       gtk_tree_menu_set_column_span_column (GTK_TREE_MENU (priv->popup_widget), priv->col_column);
+      
+      g_object_notify (G_OBJECT (combo_box), "column-span-column");
+    }
 }
 
-static gboolean
-gtk_combo_box_buildable_custom_tag_start (GtkBuildable  *buildable,
-                                         GtkBuilder    *builder,
-                                         GObject       *child,
-                                         const gchar   *tagname,
-                                         GMarkupParser *parser,
-                                         gpointer      *data)
+/**
+ * gtk_combo_box_get_active:
+ * @combo_box: A #GtkComboBox
+ *
+ * Returns the index of the currently active item, or -1 if there's no
+ * active item. If the model is a non-flat treemodel, and the active item 
+ * is not an immediate child of the root of the tree, this function returns 
+ * <literal>gtk_tree_path_get_indices (path)[0]</literal>, where 
+ * <literal>path</literal> is the #GtkTreePath of the active item.
+ *
+ * Return value: An integer which is the index of the currently active item, 
+ *     or -1 if there's no active item.
+ *
+ * Since: 2.4
+ */
+gint
+gtk_combo_box_get_active (GtkComboBox *combo_box)
 {
-  if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
-                                               tagname, parser, data))
-    return TRUE;
+  GtkComboBoxPrivate *priv;
+  gint result;
 
-  return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
-                                                     tagname, parser, data);
-}
+  g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), 0);
 
-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);
-}
+  priv = combo_box->priv;
 
-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_tree_row_reference_valid (priv->active_row))
+    {
+      GtkTreePath *path;
 
-  if (combo_box->priv->has_entry && strcmp (childname, "entry") == 0)
-    return G_OBJECT (gtk_bin_get_child (GTK_BIN (buildable)));
+      path = gtk_tree_row_reference_get_path (priv->active_row);      
+      result = gtk_tree_path_get_indices (path)[0];
+      gtk_tree_path_free (path);
+    }
+  else
+    result = -1;
 
-  return parent_buildable_iface->get_internal_child (buildable, builder, childname);
+  return result;
 }
 
-/*
- * public API
- */
-
 /**
- * gtk_combo_box_new:
- *
- * Creates a new empty #GtkComboBox.
+ * gtk_combo_box_set_active:
+ * @combo_box: A #GtkComboBox
+ * @index_: An index in the model passed during construction, or -1 to have
+ * no active item
  *
- * Return value: A new #GtkComboBox.
+ * Sets the active item of @combo_box to be the item at @index.
  *
  * Since: 2.4
  */
-GtkWidget *
-gtk_combo_box_new (void)
+void
+gtk_combo_box_set_active (GtkComboBox *combo_box,
+                          gint         index_)
 {
-  return g_object_new (GTK_TYPE_COMBO_BOX, NULL);
+  GtkTreePath *path = NULL;
+  g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
+  g_return_if_fail (index_ >= -1);
+
+  if (combo_box->priv->model == NULL)
+    {
+      /* Save index, in case the model is set after the index */
+      combo_box->priv->active = index_;
+      if (index_ != -1)
+        return;
+    }
+
+  if (index_ != -1)
+    path = gtk_tree_path_new_from_indices (index_, -1);
+   
+  gtk_combo_box_set_active_internal (combo_box, path);
+
+  if (path)
+    gtk_tree_path_free (path);
 }
 
-/**
- * gtk_combo_box_new_with_entry:
- *
- * Creates a new empty #GtkComboBox with an entry.
- *
- * Return value: A new #GtkComboBox.
- */
-GtkWidget *
-gtk_combo_box_new_with_entry (void)
+static void
+gtk_combo_box_set_active_internal (GtkComboBox *combo_box,
+                                  GtkTreePath *path)
 {
-  return g_object_new (GTK_TYPE_COMBO_BOX, "has-entry", TRUE, NULL);
+  GtkComboBoxPrivate *priv = combo_box->priv;
+  GtkTreePath *active_path;
+  gint path_cmp;
+
+  /* Remember whether the initially active row is valid. */
+  gboolean is_valid_row_reference = gtk_tree_row_reference_valid (priv->active_row);
+
+  if (path && is_valid_row_reference)
+    {
+      active_path = gtk_tree_row_reference_get_path (priv->active_row);
+      path_cmp = gtk_tree_path_compare (path, active_path);
+      gtk_tree_path_free (active_path);
+      if (path_cmp == 0)
+       return;
+    }
+
+  if (priv->active_row)
+    {
+      gtk_tree_row_reference_free (priv->active_row);
+      priv->active_row = NULL;
+    }
+  
+  if (!path)
+    {
+      if (priv->tree_view)
+        gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view)));
+      else
+        {
+          GtkMenu *menu = GTK_MENU (priv->popup_widget);
+
+          if (GTK_IS_MENU (menu))
+            gtk_menu_set_active (menu, -1);
+        }
+
+      if (priv->cell_view)
+        gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (priv->cell_view), NULL);
+
+      /*
+       *  Do not emit a "changed" signal when an already invalid selection was
+       *  now set to invalid.
+       */
+      if (!is_valid_row_reference)
+        return;
+    }
+  else
+    {
+      priv->active_row = 
+       gtk_tree_row_reference_new (priv->model, path);
+
+      if (priv->tree_view)
+       {
+         gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->tree_view), 
+                                   path, NULL, FALSE);
+       }
+      else if (GTK_IS_MENU (priv->popup_widget))
+        {
+         /* FIXME handle nested menus better */
+         gtk_menu_set_active (GTK_MENU (priv->popup_widget), 
+                              gtk_tree_path_get_indices (path)[0]);
+        }
+
+      if (priv->cell_view)
+       gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (priv->cell_view), 
+                                        path);
+    }
+
+  g_signal_emit (combo_box, combo_box_signals[CHANGED], 0);
+  g_object_notify (G_OBJECT (combo_box), "active");
+  if (combo_box->priv->id_column >= 0)
+    g_object_notify (G_OBJECT (combo_box), "active-id");
 }
 
+
 /**
- * gtk_combo_box_new_with_model:
- * @model: A #GtkTreeModel.
- *
- * Creates a new #GtkComboBox with the model initialized to @model.
- *
- * Return value: A new #GtkComboBox.
+ * gtk_combo_box_get_active_iter:
+ * @combo_box: A #GtkComboBox
+ * @iter: (out): The uninitialized #GtkTreeIter
+ * 
+ * Sets @iter to point to the current active item, if it exists.
+ * 
+ * Return value: %TRUE, if @iter was set
  *
  * Since: 2.4
  */
-GtkWidget *
-gtk_combo_box_new_with_model (GtkTreeModel *model)
+gboolean
+gtk_combo_box_get_active_iter (GtkComboBox     *combo_box,
+                               GtkTreeIter     *iter)
 {
-  GtkComboBox *combo_box;
+  GtkTreePath *path;
+  gboolean result;
 
-  g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
+  g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE);
 
-  combo_box = g_object_new (GTK_TYPE_COMBO_BOX, "model", model, NULL);
+  if (!gtk_tree_row_reference_valid (combo_box->priv->active_row))
+    return FALSE;
 
-  return GTK_WIDGET (combo_box);
-}
+  path = gtk_tree_row_reference_get_path (combo_box->priv->active_row);
+  result = gtk_tree_model_get_iter (combo_box->priv->model, iter, path);
+  gtk_tree_path_free (path);
 
-/**
- * gtk_combo_box_new_with_model_and_entry:
- * @model: A #GtkTreeModel
- *
- * Creates a new empty #GtkComboBox with an entry
- * and with the model initialized to @model.
- *
- * Return value: A new #GtkComboBox
- */
-GtkWidget *
-gtk_combo_box_new_with_model_and_entry (GtkTreeModel *model)
-{
-  return g_object_new (GTK_TYPE_COMBO_BOX,
-                       "has-entry", TRUE,
-                       "model", model,
-                       NULL);
+  return result;
 }
 
 /**
- * gtk_combo_box_get_wrap_width:
+ * gtk_combo_box_set_active_iter:
  * @combo_box: A #GtkComboBox
- *
- * Returns the wrap width which is used to determine the number of columns 
- * for the popup menu. If the wrap width is larger than 1, the combo box 
- * is in table mode.
- *
- * Returns: the wrap width.
- *
- * Since: 2.6
+ * @iter: (allow-none): The #GtkTreeIter, or %NULL
+ * 
+ * Sets the current active item to be the one referenced by @iter, or
+ * unsets the active item if @iter is %NULL.
+ * 
+ * Since: 2.4
  */
-gint
-gtk_combo_box_get_wrap_width (GtkComboBox *combo_box)
+void
+gtk_combo_box_set_active_iter (GtkComboBox     *combo_box,
+                               GtkTreeIter     *iter)
 {
-  g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), -1);
+  GtkTreePath *path = NULL;
 
-  return combo_box->priv->wrap_width;
+  g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
+
+  if (iter)
+    path = gtk_tree_model_get_path (gtk_combo_box_get_model (combo_box), iter);
+
+  gtk_combo_box_set_active_internal (combo_box, path);
+  gtk_tree_path_free (path);
 }
 
 /**
- * gtk_combo_box_set_wrap_width:
+ * gtk_combo_box_set_model:
  * @combo_box: A #GtkComboBox
- * @width: Preferred number of columns
+ * @model: (allow-none): A #GtkTreeModel
  *
- * Sets the wrap width of @combo_box to be @width. The wrap width is basically
- * the preferred number of columns when you want the popup to be layed out
- * in a table.
+ * Sets the model used by @combo_box to be @model. Will unset a previously set
+ * model (if applicable). If model is %NULL, then it will unset the model.
+ *
+ * Note that this function does not clear the cell renderers, you have to 
+ * call gtk_cell_layout_clear() yourself if you need to set up different 
+ * cell renderers for the new model.
  *
  * Since: 2.4
  */
 void
-gtk_combo_box_set_wrap_width (GtkComboBox *combo_box,
-                              gint         width)
+gtk_combo_box_set_model (GtkComboBox  *combo_box,
+                         GtkTreeModel *model)
 {
-  GtkComboBoxPrivate *priv;
-
   g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
-  g_return_if_fail (width >= 0);
+  g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
 
-  priv = combo_box->priv;
+  if (model == combo_box->priv->model)
+    return;
+  
+  gtk_combo_box_unset_model (combo_box);
 
-  if (width != priv->wrap_width)
-    {
-      priv->wrap_width = width;
+  if (model == NULL)
+    goto out;
 
-      gtk_combo_box_check_appearance (combo_box);
+  combo_box->priv->model = model;
+  g_object_ref (combo_box->priv->model);
 
-      if (GTK_IS_TREE_MENU (priv->popup_widget))
-       gtk_tree_menu_set_wrap_width (GTK_TREE_MENU (priv->popup_widget), priv->wrap_width);
+  combo_box->priv->inserted_id =
+    g_signal_connect (combo_box->priv->model, "row-inserted",
+                     G_CALLBACK (gtk_combo_box_model_row_inserted),
+                     combo_box);
+  combo_box->priv->deleted_id =
+    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);
       
-      g_object_notify (G_OBJECT (combo_box), "wrap-width");
+  if (combo_box->priv->tree_view)
+    {
+      /* list mode */
+      gtk_tree_view_set_model (GTK_TREE_VIEW (combo_box->priv->tree_view),
+                               combo_box->priv->model);
+      gtk_combo_box_list_popup_resize (combo_box);
+    }
+
+  if (GTK_IS_TREE_MENU (combo_box->priv->popup_widget))
+    {
+      /* menu mode */
+      gtk_tree_menu_set_model (GTK_TREE_MENU (combo_box->priv->popup_widget), 
+                              combo_box->priv->model);
+    }
+
+  if (combo_box->priv->cell_view)
+    gtk_cell_view_set_model (GTK_CELL_VIEW (combo_box->priv->cell_view),
+                             combo_box->priv->model);
+
+  if (combo_box->priv->active != -1)
+    {
+      /* If an index was set in advance, apply it now */
+      gtk_combo_box_set_active (combo_box, combo_box->priv->active);
+      combo_box->priv->active = -1;
     }
+
+out:
+  gtk_combo_box_update_sensitivity (combo_box);
+
+  g_object_notify (G_OBJECT (combo_box), "model");
 }
 
 /**
- * gtk_combo_box_get_row_span_column:
+ * gtk_combo_box_get_model:
  * @combo_box: A #GtkComboBox
  *
- * Returns the column with row span information for @combo_box.
+ * Returns the #GtkTreeModel which is acting as data source for @combo_box.
  *
- * Returns: the row span column.
+ * Return value: (transfer none): A #GtkTreeModel which was passed
+ *     during construction.
  *
- * Since: 2.6
+ * Since: 2.4
  */
-gint
-gtk_combo_box_get_row_span_column (GtkComboBox *combo_box)
+GtkTreeModel *
+gtk_combo_box_get_model (GtkComboBox *combo_box)
 {
-  g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), -1);
+  g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
 
-  return combo_box->priv->row_column;
+  return combo_box->priv->model;
 }
 
-/**
- * gtk_combo_box_set_row_span_column:
- * @combo_box: A #GtkComboBox.
- * @row_span: A column in the model passed during construction.
- *
- * Sets the column with row span information for @combo_box to be @row_span.
- * The row span column contains integers which indicate how many rows
- * an item should span.
- *
- * Since: 2.4
- */
-void
-gtk_combo_box_set_row_span_column (GtkComboBox *combo_box,
-                                   gint         row_span)
+static void
+gtk_combo_box_real_move_active (GtkComboBox   *combo_box,
+                                GtkScrollType  scroll)
 {
-  GtkComboBoxPrivate *priv;
-  gint col;
+  GtkTreeIter iter;
+  GtkTreeIter new_iter;
+  gboolean    active_iter;
+  gboolean    found;
 
-  g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
+  if (!combo_box->priv->model)
+    {
+      gtk_widget_error_bell (GTK_WIDGET (combo_box));
+      return;
+    }
 
-  priv = combo_box->priv;
+  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;
 
-  col = gtk_tree_model_get_n_columns (priv->model);
-  g_return_if_fail (row_span >= -1 && row_span < col);
+      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 (row_span != priv->row_column)
-    {
-      priv->row_column = row_span;
+      if (gtk_tree_path_compare (old_path, new_path) == 0)
+        found = FALSE;
 
-      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");
+      gtk_tree_path_free (old_path);
+      gtk_tree_path_free (new_path);
     }
-}
-
-/**
- * gtk_combo_box_get_column_span_column:
- * @combo_box: A #GtkComboBox
- *
- * Returns the column with column span information for @combo_box.
- *
- * Returns: the column span column.
- *
- * Since: 2.6
- */
-gint
-gtk_combo_box_get_column_span_column (GtkComboBox *combo_box)
-{
-  g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), -1);
 
-  return combo_box->priv->col_column;
+  if (found)
+    {
+      gtk_combo_box_set_active_iter (combo_box, &new_iter);
+    }
+  else
+    {
+      gtk_widget_error_bell (GTK_WIDGET (combo_box));
+    }
 }
 
-/**
- * gtk_combo_box_set_column_span_column:
- * @combo_box: A #GtkComboBox
- * @column_span: A column in the model passed during construction
- *
- * Sets the column with column span information for @combo_box to be
- * @column_span. The column span column contains integers which indicate
- * how many columns an item should span.
- *
- * Since: 2.4
- */
-void
-gtk_combo_box_set_column_span_column (GtkComboBox *combo_box,
-                                      gint         column_span)
+static gboolean
+gtk_combo_box_mnemonic_activate (GtkWidget *widget,
+                                gboolean   group_cycling)
 {
-  GtkComboBoxPrivate *priv;
-  gint col;
-
-  g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
-
-  priv = combo_box->priv;
-
-  col = gtk_tree_model_get_n_columns (priv->model);
-  g_return_if_fail (column_span >= -1 && column_span < col);
+  GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
 
-  if (column_span != priv->col_column)
+  if (combo_box->priv->has_entry)
     {
-      priv->col_column = column_span;
+      GtkWidget* child;
 
-      if (GTK_IS_TREE_MENU (priv->popup_widget))
-       gtk_tree_menu_set_column_span_column (GTK_TREE_MENU (priv->popup_widget), priv->col_column);
-      
-      g_object_notify (G_OBJECT (combo_box), "column-span-column");
+      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;
 }
 
-/**
- * gtk_combo_box_get_active:
- * @combo_box: A #GtkComboBox
- *
- * Returns the index of the currently active item, or -1 if there's no
- * active item. If the model is a non-flat treemodel, and the active item 
- * is not an immediate child of the root of the tree, this function returns 
- * <literal>gtk_tree_path_get_indices (path)[0]</literal>, where 
- * <literal>path</literal> is the #GtkTreePath of the active item.
- *
- * Return value: An integer which is the index of the currently active item, 
- *     or -1 if there's no active item.
- *
- * Since: 2.4
- */
-gint
-gtk_combo_box_get_active (GtkComboBox *combo_box)
+static void
+gtk_combo_box_grab_focus (GtkWidget *widget)
 {
-  GtkComboBoxPrivate *priv;
-  gint result;
-
-  g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), 0);
-
-  priv = combo_box->priv;
+  GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
 
-  if (gtk_tree_row_reference_valid (priv->active_row))
+  if (combo_box->priv->has_entry)
     {
-      GtkTreePath *path;
+      GtkWidget *child;
 
-      path = gtk_tree_row_reference_get_path (priv->active_row);      
-      result = gtk_tree_path_get_indices (path)[0];
-      gtk_tree_path_free (path);
+      child = gtk_bin_get_child (GTK_BIN (combo_box));
+      if (child)
+       gtk_widget_grab_focus (child);
     }
   else
-    result = -1;
-
-  return result;
+    gtk_widget_grab_focus (combo_box->priv->button);
 }
 
-/**
- * gtk_combo_box_set_active:
- * @combo_box: A #GtkComboBox
- * @index_: An index in the model passed during construction, or -1 to have
- * no active item
- *
- * Sets the active item of @combo_box to be the item at @index.
- *
- * Since: 2.4
- */
-void
-gtk_combo_box_set_active (GtkComboBox *combo_box,
-                          gint         index_)
+static void
+gtk_combo_box_destroy (GtkWidget *widget)
 {
-  GtkTreePath *path = NULL;
-  g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
-  g_return_if_fail (index_ >= -1);
+  GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
 
-  if (combo_box->priv->model == NULL)
+  if (combo_box->priv->popup_idle_id > 0)
     {
-      /* Save index, in case the model is set after the index */
-      combo_box->priv->active = index_;
-      if (index_ != -1)
-        return;
+      g_source_remove (combo_box->priv->popup_idle_id);
+      combo_box->priv->popup_idle_id = 0;
     }
 
-  if (index_ != -1)
-    path = gtk_tree_path_new_from_indices (index_, -1);
-   
-  gtk_combo_box_set_active_internal (combo_box, path);
+  gtk_combo_box_popdown (combo_box);
 
-  if (path)
-    gtk_tree_path_free (path);
+  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_set_active_internal (GtkComboBox *combo_box,
-                                  GtkTreePath *path)
+gtk_combo_box_entry_contents_changed (GtkEntry *entry,
+                                      gpointer  user_data)
 {
-  GtkComboBoxPrivate *priv = combo_box->priv;
-  GtkTreePath *active_path;
-  gint path_cmp;
+  GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
 
-  /* Remember whether the initially active row is valid. */
-  gboolean is_valid_row_reference = gtk_tree_row_reference_valid (priv->active_row);
+  /*
+   *  Fixes regression reported in bug #574059. The old functionality relied on
+   *  bug #572478.  As a bugfix, we now emit the "changed" signal ourselves
+   *  when the selection was already set to -1.
+   */
+  if (gtk_combo_box_get_active(combo_box) == -1)
+    g_signal_emit_by_name (combo_box, "changed");
+  else
+    gtk_combo_box_set_active (combo_box, -1);
+}
 
-  if (path && is_valid_row_reference)
+static void
+gtk_combo_box_entry_active_changed (GtkComboBox *combo_box,
+                                    gpointer     user_data)
+{
+  GtkComboBoxPrivate *priv = combo_box->priv;
+  GtkTreeModel *model;
+  GtkTreeIter iter;
+
+  if (gtk_combo_box_get_active_iter (combo_box, &iter))
     {
-      active_path = gtk_tree_row_reference_get_path (priv->active_row);
-      path_cmp = gtk_tree_path_compare (path, active_path);
-      gtk_tree_path_free (active_path);
-      if (path_cmp == 0)
-       return;
+      GtkEntry *entry = GTK_ENTRY (gtk_bin_get_child (GTK_BIN (combo_box)));
+
+      if (entry)
+       {
+          GValue value = {0,};
+
+         g_signal_handlers_block_by_func (entry,
+                                          gtk_combo_box_entry_contents_changed,
+                                          combo_box);
+
+         model = gtk_combo_box_get_model (combo_box);
+
+          gtk_tree_model_get_value (model, &iter,
+                                    priv->text_column, &value);
+          g_object_set_property (G_OBJECT (entry), "text", &value);
+          g_value_unset (&value);
+
+         g_signal_handlers_unblock_by_func (entry,
+                                            gtk_combo_box_entry_contents_changed,
+                                            combo_box);
+       }
     }
+}
 
-  if (priv->active_row)
+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)
     {
-      gtk_tree_row_reference_free (priv->active_row);
-      priv->active_row = NULL;
+      GtkCellArea *area = gtk_cell_area_box_new ();
+
+      priv->area = g_object_ref_sink (area);
     }
-  
-  if (!path)
-    {
-      if (priv->tree_view)
-        gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view)));
-      else
-        {
-          GtkMenu *menu = GTK_MENU (priv->popup_widget);
 
-          if (GTK_IS_MENU (menu))
-            gtk_menu_set_active (menu, -1);
-        }
+  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);
 
-      if (priv->cell_view)
-        gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (priv->cell_view), NULL);
+  context = gtk_widget_get_style_context (GTK_WIDGET (combo_box));
+  gtk_style_context_add_class (context, GTK_STYLE_CLASS_BUTTON);
 
-      /*
-       *  Do not emit a "changed" signal when an already invalid selection was
-       *  now set to invalid.
-       */
-      if (!is_valid_row_reference)
-        return;
-    }
-  else
+  if (priv->has_entry)
     {
-      priv->active_row = 
-       gtk_tree_row_reference_new (priv->model, path);
+      GtkWidget *entry;
 
-      if (priv->tree_view)
-       {
-         gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->tree_view), 
-                                   path, NULL, FALSE);
-       }
-      else if (GTK_IS_MENU (priv->popup_widget))
-        {
-         /* FIXME handle nested menus better */
-         gtk_menu_set_active (GTK_MENU (priv->popup_widget), 
-                              gtk_tree_path_get_indices (path)[0]);
-        }
+      entry = gtk_entry_new ();
+      gtk_widget_show (entry);
+      gtk_container_add (GTK_CONTAINER (combo_box), entry);
 
-      if (priv->cell_view)
-       gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (priv->cell_view), 
-                                        path);
+      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);
     }
 
-  g_signal_emit (combo_box, combo_box_signals[CHANGED], 0);
-  g_object_notify (G_OBJECT (combo_box), "active");
-  if (combo_box->priv->id_column >= 0)
-    g_object_notify (G_OBJECT (combo_box), "active-id");
+  return object;
 }
 
 
-/**
- * gtk_combo_box_get_active_iter:
- * @combo_box: A #GtkComboBox
- * @iter: (out): The uninitialized #GtkTreeIter
- * 
- * Sets @iter to point to the current active item, if it exists.
- * 
- * Return value: %TRUE, if @iter was set
- *
- * Since: 2.4
- */
-gboolean
-gtk_combo_box_get_active_iter (GtkComboBox     *combo_box,
-                               GtkTreeIter     *iter)
+static void
+gtk_combo_box_dispose(GObject* object)
 {
-  GtkTreePath *path;
-  gboolean result;
-
-  g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE);
-
-  if (!gtk_tree_row_reference_valid (combo_box->priv->active_row))
-    return FALSE;
+  GtkComboBox *combo_box = GTK_COMBO_BOX (object);
 
-  path = gtk_tree_row_reference_get_path (combo_box->priv->active_row);
-  result = gtk_tree_model_get_iter (combo_box->priv->model, iter, path);
-  gtk_tree_path_free (path);
+  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;
+    }
 
-  return result;
-}
+  if (combo_box->priv->area)
+    {
+      g_object_unref (combo_box->priv->area);
+      combo_box->priv->area = NULL;
+    }
 
-/**
- * gtk_combo_box_set_active_iter:
- * @combo_box: A #GtkComboBox
- * @iter: (allow-none): The #GtkTreeIter, or %NULL
- * 
- * Sets the current active item to be the one referenced by @iter, or
- * unsets the active item if @iter is %NULL.
- * 
- * Since: 2.4
- */
-void
-gtk_combo_box_set_active_iter (GtkComboBox     *combo_box,
-                               GtkTreeIter     *iter)
-{
-  GtkTreePath *path = NULL;
+  if (GTK_IS_TREE_VIEW (combo_box->priv->tree_view))
+    gtk_combo_box_list_destroy (combo_box);
 
-  g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
+  if (combo_box->priv->popup_window)
+    {
+      gtk_widget_destroy (combo_box->priv->popup_window);
+      combo_box->priv->popup_window = NULL;
+    }
 
-  if (iter)
-    path = gtk_tree_model_get_path (gtk_combo_box_get_model (combo_box), iter);
+  gtk_combo_box_unset_model (combo_box);
 
-  gtk_combo_box_set_active_internal (combo_box, path);
-  gtk_tree_path_free (path);
+  G_OBJECT_CLASS (gtk_combo_box_parent_class)->dispose (object);
 }
 
-/**
- * gtk_combo_box_set_model:
- * @combo_box: A #GtkComboBox
- * @model: (allow-none): A #GtkTreeModel
- *
- * Sets the model used by @combo_box to be @model. Will unset a previously set
- * model (if applicable). If model is %NULL, then it will unset the model.
- *
- * Note that this function does not clear the cell renderers, you have to 
- * call gtk_cell_layout_clear() yourself if you need to set up different 
- * cell renderers for the new model.
- *
- * Since: 2.4
- */
-void
-gtk_combo_box_set_model (GtkComboBox  *combo_box,
-                         GtkTreeModel *model)
+static void
+gtk_combo_box_finalize (GObject *object)
 {
-  g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
-  g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
-
-  if (model == combo_box->priv->model)
-    return;
-  
-  gtk_combo_box_unset_model (combo_box);
+  GtkComboBox *combo_box = GTK_COMBO_BOX (object);
 
-  if (model == NULL)
-    goto out;
+  g_free (combo_box->priv->tearoff_title);
 
-  combo_box->priv->model = model;
-  g_object_ref (combo_box->priv->model);
+  G_OBJECT_CLASS (gtk_combo_box_parent_class)->finalize (object);
+}
 
-  combo_box->priv->inserted_id =
-    g_signal_connect (combo_box->priv->model, "row-inserted",
-                     G_CALLBACK (gtk_combo_box_model_row_inserted),
-                     combo_box);
-  combo_box->priv->deleted_id =
-    g_signal_connect (combo_box->priv->model, "row-deleted",
-                     G_CALLBACK (gtk_combo_box_model_row_deleted),
-                     combo_box);
+static gboolean
+gtk_cell_editable_key_press (GtkWidget   *widget,
+                            GdkEventKey *event,
+                            gpointer     data)
+{
+  GtkComboBox *combo_box = GTK_COMBO_BOX (data);
 
-  if (combo_box->priv->tree_view)
+  if (event->keyval == GDK_KEY_Escape)
     {
-      /* list mode */
-      gtk_tree_view_set_model (GTK_TREE_VIEW (combo_box->priv->tree_view),
-                               combo_box->priv->model);
-      gtk_combo_box_list_popup_resize (combo_box);
+      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;
     }
-
-  if (GTK_IS_TREE_MENU (combo_box->priv->popup_widget))
+  else if (event->keyval == GDK_KEY_Return ||
+           event->keyval == GDK_KEY_ISO_Enter ||
+           event->keyval == GDK_KEY_KP_Enter)
     {
-      /* menu mode */
-      gtk_tree_menu_set_model (GTK_TREE_MENU (combo_box->priv->popup_widget), 
-                              combo_box->priv->model);
+      gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (combo_box));
+      gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (combo_box));
+      
+      return TRUE;
     }
 
-  if (combo_box->priv->cell_view)
-    gtk_cell_view_set_model (GTK_CELL_VIEW (combo_box->priv->cell_view),
-                             combo_box->priv->model);
+  return FALSE;
+}
 
-  if (combo_box->priv->active != -1)
-    {
-      /* If an index was set in advance, apply it now */
-      gtk_combo_box_set_active (combo_box, combo_box->priv->active);
-      combo_box->priv->active = -1;
-    }
+static gboolean
+popdown_idle (gpointer data)
+{
+  GtkComboBox *combo_box;
 
-out:
-  g_object_notify (G_OBJECT (combo_box), "model");
+  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;
 }
 
-/**
- * gtk_combo_box_get_model:
- * @combo_box: A #GtkComboBox
- *
- * Returns the #GtkTreeModel which is acting as data source for @combo_box.
- *
- * Return value: (transfer none): A #GtkTreeModel which was passed
- *     during construction.
- *
- * Since: 2.4
- */
-GtkTreeModel *
-gtk_combo_box_get_model (GtkComboBox *combo_box)
+static void
+popdown_handler (GtkWidget *widget,
+                gpointer   data)
 {
-  g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
+  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);
 
-  return combo_box->priv->model;
+  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_entry_contents_changed (GtkEntry *entry,
-                                      gpointer  user_data)
+gtk_combo_box_start_editing (GtkCellEditable *cell_editable,
+                            GdkEvent        *event)
 {
-  GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
+  GtkComboBox *combo_box = GTK_COMBO_BOX (cell_editable);
+  GtkWidget *child;
 
-  /*
-   *  Fixes regression reported in bug #574059. The old functionality relied on
-   *  bug #572478.  As a bugfix, we now emit the "changed" signal ourselves
-   *  when the selection was already set to -1.
-   */
-  if (gtk_combo_box_get_active(combo_box) == -1)
-    g_signal_emit_by_name (combo_box, "changed");
-  else
-    gtk_combo_box_set_active (combo_box, -1);
-}
+  combo_box->priv->is_cell_renderer = TRUE;
 
-static void
-gtk_combo_box_entry_active_changed (GtkComboBox *combo_box,
-                                    gpointer     user_data)
-{
-  GtkComboBoxPrivate *priv = combo_box->priv;
-  GtkTreeModel *model;
-  GtkTreeIter iter;
+  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);  
 
-  if (gtk_combo_box_get_active_iter (combo_box, &iter))
+      gtk_widget_grab_focus (combo_box->priv->button);
+    }
+  else
     {
-      GtkEntry *entry = GTK_ENTRY (gtk_bin_get_child (GTK_BIN (combo_box)));
+      child = gtk_bin_get_child (GTK_BIN (combo_box));
 
-      if (entry)
-       {
-          GValue value = {0,};
+      g_signal_connect_object (child, "key-press-event",
+                              G_CALLBACK (gtk_cell_editable_key_press), 
+                              cell_editable, 0);  
 
-         g_signal_handlers_block_by_func (entry,
-                                          gtk_combo_box_entry_contents_changed,
-                                          combo_box);
+      gtk_widget_grab_focus (child);
+      gtk_widget_set_can_focus (combo_box->priv->button, FALSE);
+    }
 
-         model = gtk_combo_box_get_model (combo_box);
+  /* 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;
 
-          gtk_tree_model_get_value (model, &iter,
-                                    priv->text_column, &value);
-          g_object_set_property (G_OBJECT (entry), "text", &value);
-          g_value_unset (&value);
+          combo_box->priv->activate_button = event_button->button;
+          combo_box->priv->activate_time = event_button->time;
+        }
 
-         g_signal_handlers_unblock_by_func (entry,
-                                            gtk_combo_box_entry_contents_changed,
-                                            combo_box);
-       }
+      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 +4780,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 +5163,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)
-{
-  g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
-
-  g_signal_emit (combo_box, combo_box_signals[POPUP], 0);
+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 (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);
+}
+
+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);
+}
+
+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);
 }
 
-/**
- * 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_get_preferred_width_for_height (GtkWidget *widget,
+                                              gint       avail_size,
+                                              gint      *minimum_size,
+                                              gint      *natural_size)
 {
-  GtkComboBoxPrivate *priv = combo_box->priv;
-  gint x, y, width, height;
-  GtkTreePath *path = NULL, *ppath;
-  GtkWidget *toplevel;
-  GdkDevice *keyboard, *pointer;
-  guint32 time;
+  /* 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));
-  g_return_if_fail (GDK_IS_DEVICE (device));
 
-  if (!gtk_widget_get_realized (GTK_WIDGET (combo_box)))
-    return;
+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;
 
-  if (gtk_widget_get_mapped (priv->popup_widget))
-    return;
+  gtk_widget_style_get (GTK_WIDGET (widget),
+                       "focus-line-width", &focus_width,
+                       "focus-padding", &focus_pad,
+                       NULL);
 
-  if (priv->grab_pointer && priv->grab_keyboard)
-    return;
+  child = gtk_bin_get_child (GTK_BIN (widget));
 
-  time = gtk_get_current_event_time ();
+  get_widget_border (widget, &border);
+  size = avail_size - border.left;
 
-  if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
-    {
-      keyboard = device;
-      pointer = gdk_device_get_associated_device (device);
-    }
-  else
+  if (!priv->tree_view)
     {
-      pointer = device;
-      keyboard = gdk_device_get_associated_device (device);
-    }
+      /* 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;
 
-  if (GTK_IS_MENU (priv->popup_widget))
-    {
-      gtk_combo_box_menu_popup (combo_box, 
-                                priv->activate_button,
-                                priv->activate_time);
-      return;
-    }
+         border_width = gtk_container_get_border_width (GTK_CONTAINER (combo_box));
+         get_widget_border (priv->button, &button_border);
 
-  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_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);
 
-  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);
+         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;
 
-  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);
+         size -= sep_width + arrow_width + xpad;
 
-  if (path)
-    {
-      gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->tree_view),
-                               path, NULL, FALSE);
-      gtk_tree_path_free (path);
-    }
+         /* 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);
 
-  gtk_widget_grab_focus (priv->popup_window);
-  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->button),
-                                TRUE);
+         arrow_height = MAX (arrow_height, sep_height);
+         min_height = MAX (min_height, arrow_height);
+         nat_height = MAX (nat_height, arrow_height);
 
-  if (!gtk_widget_has_focus (priv->tree_view))
-    gtk_widget_grab_focus (priv->tree_view);
+         min_height += ypad;
+         nat_height += ypad;
+        }
+      else
+        {
+         /* there is a custom child widget inside (no priv->cell_view) */
+          gint but_width, but_height;
 
-  if (!popup_grab_on_window (gtk_widget_get_window (priv->popup_window),
-                            keyboard, pointer, time))
-    {
-      gtk_widget_hide (priv->popup_window);
-      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);
+
+         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_device_grab_add (priv->popup_window, pointer, TRUE);
-  priv->grab_pointer = pointer;
-  priv->grab_keyboard = keyboard;
-}
+      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_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;
+          border_width = gtk_container_get_border_width (GTK_CONTAINER (priv->cell_view_frame));
+         get_widget_border (GTK_WIDGET (priv->cell_view_frame), &frame_border);
 
-  g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
+         xpad = (2 * border_width) + border.left + frame_border.right;
+         ypad = (2 * border_width) + border.top + frame_border.bottom;
+       }
 
-  if (GTK_IS_MENU (priv->popup_widget))
-    {
-      gtk_menu_popdown (GTK_MENU (priv->popup_widget));
-      return;
+      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;
     }
 
-  if (!gtk_widget_get_realized (GTK_WIDGET (combo_box)))
-    return;
+  min_height += border.top + border.bottom;
+  nat_height += border.top + border.bottom;
 
-  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);
+  if (minimum_size)
+    *minimum_size = min_height;
 
-  priv->grab_pointer = NULL;
-  priv->grab_keyboard = NULL;
+  if (natural_size)
+    *natural_size = nat_height;
 }
 
 /**