#include "config.h"
#include "gtkcombobox.h"
-
+#include "gtkcellareabox.h"
+#include "gtktreemenu.h"
#include "gtkarrow.h"
#include "gtkbindings.h"
#include "gtkcelllayout.h"
#include "gtkhbox.h"
#include "gtkliststore.h"
#include "gtkmain.h"
-#include "gtkmenu.h"
+#include "gtkmenuprivate.h"
+#include "gtkmenushellprivate.h"
#include "gtkscrolledwindow.h"
#include "gtkseparatormenuitem.h"
#include "gtktearoffmenuitem.h"
#include "gtkmarshalers.h"
#include "gtkintl.h"
+#include "gtkentryprivate.h"
#include "gtktreeprivate.h"
/* WELCOME, to THE house of evil code */
-
-typedef struct _ComboCellInfo ComboCellInfo;
-struct _ComboCellInfo
-{
- GtkCellRenderer *cell;
- GSList *attributes;
-
- GtkCellLayoutDataFunc func;
- gpointer func_data;
- GDestroyNotify destroy;
-
- guint expand : 1;
- guint pack : 1;
-};
-
-
struct _GtkComboBoxPrivate
{
GtkTreeModel *model;
+ GtkCellArea *area;
+
gint col_column;
gint row_column;
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;
- GSList *cells;
+ gint id_column;
guint popup_in_progress : 1;
guint popup_shown : 1;
PROP_EDITING_CANCELED,
PROP_HAS_ENTRY,
PROP_ENTRY_TEXT_COLUMN,
- PROP_POPUP_FIXED_WIDTH
+ PROP_POPUP_FIXED_WIDTH,
+ PROP_ID_COLUMN,
+ PROP_ACTIVE_ID,
+ PROP_CELL_AREA
};
static guint combo_box_signals[LAST_SIGNAL] = {0,};
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_set (GtkWidget *widget,
- GtkStyle *previous);
+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_changed (GtkWidget *widget,
- GtkStateType previous,
- 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 ComboCellInfo *gtk_combo_box_get_cell_info (GtkComboBox *combo_box,
- GtkCellRenderer *cell);
-
static void gtk_combo_box_menu_show (GtkWidget *menu,
gpointer user_data);
static void gtk_combo_box_menu_hide (GtkWidget *menu,
gint *push_in,
gpointer user_data);
-static void gtk_combo_box_update_requested_width(GtkComboBox *combo_box,
- GtkTreePath *path);
-static void gtk_combo_box_remeasure (GtkComboBox *combo_box);
-
static void gtk_combo_box_unset_model (GtkComboBox *combo_box);
static void gtk_combo_box_size_allocate (GtkWidget *widget,
/* menu */
static void gtk_combo_box_menu_setup (GtkComboBox *combo_box,
gboolean add_children);
-static void gtk_combo_box_menu_fill (GtkComboBox *combo_box);
-static void gtk_combo_box_menu_fill_level (GtkComboBox *combo_box,
- GtkWidget *menu,
- GtkTreeIter *iter);
static void gtk_combo_box_update_title (GtkComboBox *combo_box);
static void gtk_combo_box_menu_destroy (GtkComboBox *combo_box);
-static void gtk_combo_box_relayout_item (GtkComboBox *combo_box,
- GtkWidget *item,
- GtkTreeIter *iter,
- GtkWidget *last);
-static void gtk_combo_box_relayout (GtkComboBox *combo_box);
static gboolean gtk_combo_box_menu_button_press (GtkWidget *widget,
GdkEventButton *event,
gpointer user_data);
-static void gtk_combo_box_menu_item_activate (GtkWidget *item,
- 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 void gtk_combo_box_menu_row_inserted (GtkTreeModel *model,
- GtkTreePath *path,
- GtkTreeIter *iter,
- gpointer user_data);
-static void gtk_combo_box_menu_row_deleted (GtkTreeModel *model,
- GtkTreePath *path,
- gpointer user_data);
-static void gtk_combo_box_menu_rows_reordered (GtkTreeModel *model,
- GtkTreePath *path,
- GtkTreeIter *iter,
- gint *new_order,
- gpointer user_data);
-static void gtk_combo_box_menu_row_changed (GtkTreeModel *model,
- GtkTreePath *path,
- GtkTreeIter *iter,
- gpointer data);
static gboolean gtk_combo_box_menu_key_press (GtkWidget *widget,
GdkEventKey *event,
gpointer data);
static void gtk_combo_box_menu_popup (GtkComboBox *combo_box,
guint button,
guint32 activate_time);
-static GtkWidget *gtk_cell_view_menu_item_new (GtkComboBox *combo_box,
- GtkTreeModel *model,
- GtkTreeIter *iter);
/* cell layout */
-static void gtk_combo_box_cell_layout_pack_start (GtkCellLayout *layout,
- GtkCellRenderer *cell,
- gboolean expand);
-static void gtk_combo_box_cell_layout_pack_end (GtkCellLayout *layout,
- GtkCellRenderer *cell,
- gboolean expand);
-static GList *gtk_combo_box_cell_layout_get_cells (GtkCellLayout *layout);
-static void gtk_combo_box_cell_layout_clear (GtkCellLayout *layout);
-static void gtk_combo_box_cell_layout_add_attribute (GtkCellLayout *layout,
- GtkCellRenderer *cell,
- const gchar *attribute,
- gint column);
-static void gtk_combo_box_cell_layout_set_cell_data_func (GtkCellLayout *layout,
- GtkCellRenderer *cell,
- GtkCellLayoutDataFunc func,
- gpointer func_data,
- GDestroyNotify destroy);
-static void gtk_combo_box_cell_layout_clear_attributes (GtkCellLayout *layout,
- GtkCellRenderer *cell);
-static void gtk_combo_box_cell_layout_reorder (GtkCellLayout *layout,
- GtkCellRenderer *cell,
- gint position);
+GtkCellArea *gtk_combo_box_cell_layout_get_area (GtkCellLayout *cell_layout);
+
static gboolean gtk_combo_box_mnemonic_activate (GtkWidget *widget,
gboolean group_cycling);
-static void gtk_combo_box_sync_cells (GtkComboBox *combo_box,
- GtkCellLayout *cell_layout);
-static void combo_cell_data_func (GtkCellLayout *cell_layout,
- GtkCellRenderer *cell,
- GtkTreeModel *tree_model,
- GtkTreeIter *iter,
- gpointer data);
static void gtk_combo_box_child_show (GtkWidget *widget,
GtkComboBox *combo_box);
static void gtk_combo_box_child_hide (GtkWidget *widget,
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_set = gtk_combo_box_style_set;
+ 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;
-1, G_MAXINT, -1,
GTK_PARAM_READWRITE));
+ /**
+ * GtkComboBox:id-column:
+ *
+ * The column in the combo box's model that provides string
+ * IDs for the values in the model, if != -1.
+ *
+ * Since: 3.0
+ */
+ g_object_class_install_property (object_class,
+ PROP_ID_COLUMN,
+ g_param_spec_int ("id-column",
+ P_("ID Column"),
+ P_("The column in the combo box's model that provides "
+ "string IDs for the values in the model"),
+ -1, G_MAXINT, -1,
+ GTK_PARAM_READWRITE));
+
+ /**
+ * GtkComboBox:active-id:
+ *
+ * The value of the ID column of the active row.
+ *
+ * Since: 3.0
+ */
+ g_object_class_install_property (object_class,
+ PROP_ACTIVE_ID,
+ g_param_spec_string ("active-id",
+ P_("Active id"),
+ P_("The value of the id column "
+ "for the active row"),
+ NULL, GTK_PARAM_READWRITE));
+
/**
* GtkComboBox:popup-fixed-width:
*
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"),
static void
gtk_combo_box_cell_layout_init (GtkCellLayoutIface *iface)
{
- iface->pack_start = gtk_combo_box_cell_layout_pack_start;
- iface->pack_end = gtk_combo_box_cell_layout_pack_end;
- iface->get_cells = gtk_combo_box_cell_layout_get_cells;
- iface->clear = gtk_combo_box_cell_layout_clear;
- iface->add_attribute = gtk_combo_box_cell_layout_add_attribute;
- iface->set_cell_data_func = gtk_combo_box_cell_layout_set_cell_data_func;
- iface->clear_attributes = gtk_combo_box_cell_layout_clear_attributes;
- iface->reorder = gtk_combo_box_cell_layout_reorder;
+ iface->get_area = gtk_combo_box_cell_layout_get_area;
}
static void
GtkComboBoxPrivate);
priv = combo_box->priv;
- priv->cell_view = gtk_cell_view_new ();
- 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);
-
- priv->minimum_width = 0;
- priv->natural_width = 0;
-
priv->wrap_width = 0;
priv->active = -1;
priv->text_column = -1;
priv->text_renderer = NULL;
-
- gtk_combo_box_check_appearance (combo_box);
+ priv->id_column = -1;
}
static void
GParamSpec *pspec)
{
GtkComboBox *combo_box = GTK_COMBO_BOX (object);
+ GtkCellArea *area;
switch (prop_id)
{
gtk_combo_box_set_entry_text_column (combo_box, g_value_get_int (value));
break;
+ case PROP_ID_COLUMN:
+ gtk_combo_box_set_id_column (combo_box, g_value_get_int (value));
+ break;
+
+ case PROP_ACTIVE_ID:
+ gtk_combo_box_set_active_id (combo_box, g_value_get_string (value));
+ break;
+
+ case PROP_CELL_AREA:
+ /* Construct-only, can only be assigned once */
+ area = g_value_get_object (value);
+
+ if (area)
+ combo_box->priv->area = g_object_ref_sink (area);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
g_value_set_int (value, priv->text_column);
break;
+ case PROP_ID_COLUMN:
+ g_value_set_int (value, priv->id_column);
+ break;
+
+ case PROP_ACTIVE_ID:
+ g_value_set_string (value, gtk_combo_box_get_active_id (combo_box));
+ break;
+
+ case PROP_CELL_AREA:
+ g_value_set_object (value, priv->area);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
if (gtk_widget_get_realized (widget))
{
if (priv->tree_view && priv->cell_view)
- gtk_cell_view_set_background_color (GTK_CELL_VIEW (priv->cell_view),
- >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
+ {
+ 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_widget_queue_draw (widget);
}
static void
-gtk_combo_box_button_state_changed (GtkWidget *widget,
- GtkStateType previous,
- gpointer data)
+gtk_combo_box_button_state_flags_changed (GtkWidget *widget,
+ GtkStateFlags previous,
+ gpointer data)
{
GtkComboBox *combo_box = GTK_COMBO_BOX (data);
GtkComboBoxPrivate *priv = combo_box->priv;
if (gtk_widget_get_realized (widget))
{
if (!priv->tree_view && priv->cell_view)
- {
- if ((gtk_widget_get_state (widget) == GTK_STATE_INSENSITIVE) !=
- (gtk_widget_get_state (priv->cell_view) == GTK_STATE_INSENSITIVE))
- gtk_widget_set_sensitive (priv->cell_view, gtk_widget_get_sensitive (widget));
-
- gtk_widget_set_state (priv->cell_view,
- gtk_widget_get_state (widget));
- }
+ gtk_widget_set_state_flags (priv->cell_view,
+ gtk_widget_get_state_flags (widget),
+ TRUE);
}
gtk_widget_queue_draw (widget);
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. */
}
static void
-gtk_combo_box_style_set (GtkWidget *widget,
- GtkStyle *previous)
+gtk_combo_box_style_updated (GtkWidget *widget)
{
GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
GtkComboBoxPrivate *priv = combo_box->priv;
gtk_combo_box_check_appearance (combo_box);
if (priv->tree_view && priv->cell_view)
- gtk_cell_view_set_background_color (GTK_CELL_VIEW (priv->cell_view),
- >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
+ {
+ GtkStyleContext *context;
+ GdkRGBA *color;
+
+ context = gtk_widget_get_style_context (widget);
+ gtk_style_context_get (context, 0,
+ "background-color", &color,
+ NULL);
+
+ gtk_cell_view_set_background_rgba (GTK_CELL_VIEW (priv->cell_view),
+ color);
+
+ gdk_rgba_free (color);
+ }
child = gtk_bin_get_child (GTK_BIN (combo_box));
if (GTK_IS_ENTRY (child))
{
/* this flag is a hack to tell the entry to fill its allocation.
*/
- GTK_ENTRY (widget)->is_cell_renderer = TRUE;
+ _gtk_entry_set_is_cell_renderer (GTK_ENTRY (widget), TRUE);
g_signal_connect (widget, "changed",
G_CALLBACK (gtk_combo_box_entry_contents_changed),
g_signal_handlers_disconnect_by_func (widget,
gtk_combo_box_entry_contents_changed,
container);
- GTK_ENTRY (widget)->is_cell_renderer = FALSE;
+ _gtk_entry_set_is_cell_renderer (GTK_ENTRY (widget), FALSE);
}
}
gtk_widget_show (priv->cell_view);
gtk_cell_view_set_model (GTK_CELL_VIEW (priv->cell_view),
priv->model);
- gtk_combo_box_sync_cells (combo_box, GTK_CELL_LAYOUT (priv->cell_view));
}
gtk_combo_box_set_active_internal (combo_box, NULL);
}
-static ComboCellInfo *
-gtk_combo_box_get_cell_info (GtkComboBox *combo_box,
- GtkCellRenderer *cell)
-{
- GSList *i;
-
- for (i = combo_box->priv->cells; i; i = i->next)
- {
- ComboCellInfo *info = (ComboCellInfo *)i->data;
-
- if (info && info->cell == cell)
- return info;
- }
-
- return NULL;
-}
-
static void
gtk_combo_box_menu_show (GtkWidget *menu,
gpointer user_data)
g_return_if_fail (priv->popup_widget == (GtkWidget *) menu);
- g_signal_handlers_disconnect_by_func (menu->toplevel,
+ g_signal_handlers_disconnect_by_func (menu->priv->toplevel,
gtk_combo_box_menu_show,
combo_box);
- g_signal_handlers_disconnect_by_func (menu->toplevel,
+ g_signal_handlers_disconnect_by_func (menu->priv->toplevel,
gtk_combo_box_menu_hide,
combo_box);
* 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_signal_connect (GTK_MENU (popup)->priv->toplevel, "show",
G_CALLBACK (gtk_combo_box_menu_show), combo_box);
- g_signal_connect (GTK_MENU (popup)->toplevel, "hide",
+ g_signal_connect (GTK_MENU (popup)->priv->toplevel, "hide",
G_CALLBACK (gtk_combo_box_menu_hide), combo_box);
gtk_menu_attach_to_widget (GTK_MENU (popup),
}
}
+static void
+get_widget_border (GtkWidget *widget,
+ GtkBorder *border)
+{
+ GtkStyleContext *context;
+ GtkBorder *border_width;
+
+ context = gtk_widget_get_style_context (widget);
+
+ gtk_style_context_get (context,
+ gtk_widget_get_state_flags (widget),
+ "border-width", &border_width,
+ NULL);
+
+ *border = *border_width;
+ gtk_border_free (border_width);
+}
+
static void
gtk_combo_box_menu_position_below (GtkMenu *menu,
gint *x,
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));
gdk_window_get_root_coords (gtk_widget_get_window (child),
sx, sy, &sx, &sy);
-
- if (GTK_SHADOW_NONE != combo_box->priv->shadow_type)
- sx -= gtk_widget_get_style (GTK_WIDGET (combo_box))->xthickness;
+ get_widget_border (GTK_WIDGET (combo_box), &border);
+ sx -= border.left;
if (combo_box->priv->popup_fixed_width)
gtk_widget_get_preferred_size (GTK_WIDGET (menu), &req, NULL);
menu_ypos -= child_allocation.height / 2;
}
- children = GTK_MENU_SHELL (combo_box->priv->popup_widget)->children;
+ children = GTK_MENU_SHELL (combo_box->priv->popup_widget)->priv->children;
while (children)
{
child = children->data;
gtk_combo_box_menu_position_over (menu, x, y, push_in, user_data);
}
- if (!gtk_widget_get_visible (GTK_MENU (priv->popup_widget)->toplevel))
- gtk_window_set_type_hint (GTK_WINDOW (GTK_MENU (priv->popup_widget)->toplevel),
+ if (!gtk_widget_get_visible (GTK_MENU (priv->popup_widget)->priv->toplevel))
+ gtk_window_set_type_hint (GTK_WINDOW (GTK_MENU (priv->popup_widget)->priv->toplevel),
GDK_WINDOW_TYPE_HINT_COMBO);
}
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
hpolicy, vpolicy);
- /* XXX This set_size_request call is part of the hack outlined below and can
- * go away once height-for-width is implemented on treeviews. */
- gtk_widget_set_size_request (priv->tree_view, -1, -1);
-
if (combo_box->priv->popup_fixed_width)
{
gtk_widget_get_preferred_size (priv->scrolled_window, &popup_req, NULL);
}
else
{
- gtk_combo_box_remeasure (combo_box);
+ /* XXX This code depends on treeviews properly reporting their natural width
+ * list-mode menus won't fill up to their natural width until then */
+ gtk_widget_get_preferred_size (priv->scrolled_window, NULL, &popup_req);
- if (priv->natural_width > *width)
+ if (popup_req.width > *width)
{
hpolicy = GTK_POLICY_NEVER;
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
hpolicy, vpolicy);
-
- /* XXX Currently we set the size-request on the internal treeview to be
- * the natural width of the cells, this hack can go away once our
- * treeview does height-for-width properly (i.e. just adjust *width
- * here to be the natural width request of the scrolled-window).
- *
- * I can't tell why the magic number 5 is needed here (i.e. without it
- * treeviews are left ellipsizing) , however it this all should be
- * removed with height-for-width treeviews.
- */
- gtk_widget_set_size_request (priv->tree_view, priv->natural_width + 5, -1);
- gtk_widget_get_preferred_size (priv->scrolled_window, NULL, &popup_req);
-
*width = popup_req.width;
}
}
time = gtk_get_current_event_time ();
- if (device->source == GDK_SOURCE_KEYBOARD)
+ if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
{
keyboard = device;
pointer = gdk_device_get_associated_device (device);
priv->grab_keyboard = NULL;
}
-static void
-gtk_combo_box_update_requested_width (GtkComboBox *combo_box,
- GtkTreePath *path)
-{
- GtkComboBoxPrivate *priv = combo_box->priv;
- gint padding, min_width, nat_width;
-
- if (priv->cell_view)
- gtk_widget_style_get (priv->cell_view,
- "focus-line-width", &padding,
- NULL);
- else
- padding = 0;
-
- /* add some pixels for good measure */
- padding += BONUS_PADDING;
-
- if (priv->cell_view)
- gtk_cell_view_get_desired_width_of_row (GTK_CELL_VIEW (priv->cell_view),
- path, &min_width, &nat_width);
- else
- min_width = nat_width = 0;
-
- min_width += padding;
- nat_width += padding;
-
- if (min_width > priv->minimum_width || nat_width > priv->natural_width)
- {
- priv->minimum_width = MAX (priv->minimum_width, min_width);
- priv->natural_width = MAX (priv->natural_width, nat_width);
-
- if (priv->cell_view)
- {
- gtk_widget_set_size_request (priv->cell_view, min_width, -1);
- gtk_widget_queue_resize (priv->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 + shadow_width; \
+ child.x = allocation->x + border.right; \
else \
- child.x = allocation->x + allocation->width - req.width - shadow_width; \
+ child.x = allocation->x + allocation->width - req.width - border.left; \
\
- child.y = allocation->y + shadow_height; \
+ child.y = allocation->y + border.top; \
child.width = req.width; \
- child.height = allocation->height - 2 * shadow_height; \
+ child.height = allocation->height - (border.top + border.bottom); \
child.width = MAX (1, child.width); \
child.height = MAX (1, child.height); \
\
gtk_widget_size_allocate (combo_box->priv->button, &child);
+
static void
gtk_combo_box_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
GtkComboBoxPrivate *priv = combo_box->priv;
GtkWidget *child_widget;
- gint shadow_width, shadow_height;
gint focus_width, focus_pad;
GtkAllocation child;
GtkRequisition req;
- GtkStyle *style;
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);
- style = gtk_widget_get_style (widget);
gtk_widget_style_get (widget,
"focus-line-width", &focus_width,
"focus-padding", &focus_pad,
NULL);
- if (GTK_SHADOW_NONE != priv->shadow_type)
- {
- shadow_width = style->xthickness;
- shadow_height = style->ythickness;
- }
- else
- {
- shadow_width = 0;
- shadow_height = 0;
- }
-
if (!priv->tree_view)
{
if (priv->cell_view)
{
- gint xthickness, ythickness;
+ GtkBorder button_border;
gint width;
guint border_width;
/* menu mode */
- allocation->x += shadow_width;
- allocation->y += shadow_height;
- allocation->width -= 2 * shadow_width;
- allocation->height -= 2 * shadow_height;
+ allocation->x += border.left;
+ allocation->y += border.top;
+ allocation->width -= border.left + border.right;
+ allocation->height -= border.top + border.bottom;
gtk_widget_size_allocate (priv->button, allocation);
/* set some things ready */
border_width = gtk_container_get_border_width (GTK_CONTAINER (priv->button));
- style = gtk_widget_get_style (priv->button);
- xthickness = style->xthickness;
- ythickness = style->ythickness;
+ get_widget_border (priv->button, &button_border);
child.x = allocation->x;
child.y = allocation->y;
if (!priv->is_cell_renderer)
{
- child.x += border_width + xthickness + focus_width + focus_pad;
- child.y += border_width + ythickness + focus_width + focus_pad;
- width -= 2 * (child.x - allocation->x);
- child.height -= 2 * (child.y - allocation->y);
+ 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;
{
child.x += req.width;
child.width = allocation->x + allocation->width
- - (border_width + xthickness + focus_width + focus_pad)
+ - (border_width + button_border.right + focus_width + focus_pad)
- child.x;
}
else
{
child.width = child.x;
child.x = allocation->x
- + border_width + xthickness + focus_width + focus_pad;
+ + border_width + button_border.left + focus_width + focus_pad;
child.width -= child.x;
}
GTK_COMBO_BOX_SIZE_ALLOCATE_BUTTON
if (is_rtl)
- child.x = allocation->x + req.width + shadow_width;
+ child.x = allocation->x + req.width + border.right;
else
- child.x = allocation->x + shadow_width;
- child.y = allocation->y + shadow_height;
- child.width = allocation->width - req.width - 2 * shadow_width;
+ 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 */
-
- /* Combobox thickness + border-width */
guint border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
- int delta_x = shadow_width + border_width;
- int delta_y = shadow_height + border_width;
/* button */
GTK_COMBO_BOX_SIZE_ALLOCATE_BUTTON
if (priv->cell_view_frame)
{
- child.x += delta_x;
- child.y += delta_y;
- child.width = MAX (1, child.width - delta_x * 2);
- child.height = MAX (1, child.height - delta_y * 2);
+ 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));
- style = gtk_widget_get_style (priv->cell_view_frame);
- delta_x = border_width + style->xthickness;
- delta_y = border_width + style->ythickness;
-
- child.x += delta_x;
- child.y += delta_y;
- child.width -= delta_x * 2;
- child.height -= delta_y * 2;
+ 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 += delta_x;
- child.y += delta_y;
- child.width -= delta_x * 2;
- child.height -= delta_y * 2;
+ 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))
priv->changed_id);
}
- /* menu mode */
- if (!priv->tree_view)
- {
- if (priv->popup_widget)
- gtk_container_foreach (GTK_CONTAINER (priv->popup_widget),
- (GtkCallback)gtk_widget_destroy, NULL);
- }
-
if (priv->model)
{
g_object_unref (priv->model);
if (priv->shadow_type != GTK_SHADOW_NONE)
{
- gtk_paint_shadow (gtk_widget_get_style (widget),
- cr,
- GTK_STATE_NORMAL, priv->shadow_type,
- widget, "combobox",
- 0, 0,
+ GtkStyleContext *context;
+ GtkStateFlags state;
+
+ context = gtk_widget_get_style_context (widget);
+ state = gtk_widget_get_state_flags (widget);
+ gtk_style_context_set_state (context, state);
+
+ gtk_render_background (context, cr, 0, 0,
+ gtk_widget_get_allocated_width (widget),
+ gtk_widget_get_allocated_height (widget));
+ gtk_render_frame (context, cr, 0, 0,
gtk_widget_get_allocated_width (widget),
gtk_widget_get_allocated_height (widget));
}
* menu style
*/
-static void
-gtk_combo_box_sync_cells (GtkComboBox *combo_box,
- GtkCellLayout *cell_layout)
+static gboolean
+gtk_combo_box_row_separator_func (GtkTreeModel *model,
+ GtkTreeIter *iter,
+ GtkComboBox *combo)
{
- GtkComboBoxPrivate *priv = combo_box->priv;
- GSList *k;
+ GtkComboBoxPrivate *priv = combo->priv;
- for (k = priv->cells; k; k = k->next)
- {
- GSList *j;
- ComboCellInfo *info = (ComboCellInfo *)k->data;
-
- if (info->pack == GTK_PACK_START)
- gtk_cell_layout_pack_start (cell_layout,
- info->cell, info->expand);
- else if (info->pack == GTK_PACK_END)
- gtk_cell_layout_pack_end (cell_layout,
- info->cell, info->expand);
+ if (priv->row_separator_func)
+ return priv->row_separator_func (model, iter, priv->row_separator_data);
- gtk_cell_layout_set_cell_data_func (cell_layout,
- info->cell,
- combo_cell_data_func, info, NULL);
+ return FALSE;
+}
- for (j = info->attributes; j; j = j->next->next)
- {
- gtk_cell_layout_add_attribute (cell_layout,
- info->cell,
- j->data,
- GPOINTER_TO_INT (j->next->data));
- }
- }
+static gboolean
+gtk_combo_box_header_func (GtkTreeModel *model,
+ GtkTreeIter *iter,
+ GtkComboBox *combo)
+{
+ /* Every submenu has a selectable header, however we
+ * can expose a method to make that configurable by
+ * the user (like row_separator_func is done) */
+ return TRUE;
}
static void
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_menu_new ();
+ menu = _gtk_tree_menu_new_with_area (priv->area);
gtk_widget_set_name (menu, "gtk-combobox-popup-menu");
- gtk_menu_set_reserve_toggle_size (GTK_MENU (menu), FALSE);
-
- g_signal_connect (menu, "key-press-event",
- G_CALLBACK (gtk_combo_box_menu_key_press), combo_box);
- gtk_combo_box_set_popup_widget (combo_box, menu);
-
- /* add items */
- if (add_children)
- gtk_combo_box_menu_fill (combo_box);
-
- /* the column is needed in tree_column_row_is_sensitive() */
- priv->column = gtk_tree_view_column_new ();
- g_object_ref_sink (priv->column);
- gtk_combo_box_sync_cells (combo_box, GTK_CELL_LAYOUT (priv->column));
-
- gtk_combo_box_update_title (combo_box);
- gtk_combo_box_update_sensitivity (combo_box);
-}
-
-static void
-gtk_combo_box_menu_fill (GtkComboBox *combo_box)
-{
- GtkComboBoxPrivate *priv = combo_box->priv;
- GtkWidget *menu;
-
- if (!priv->model)
- return;
-
- menu = priv->popup_widget;
- if (priv->add_tearoffs)
- {
- GtkWidget *tearoff = gtk_tearoff_menu_item_new ();
+ _gtk_tree_menu_set_model (GTK_TREE_MENU (menu), priv->model);
- gtk_widget_show (tearoff);
-
- if (priv->wrap_width)
- gtk_menu_attach (GTK_MENU (menu), tearoff, 0, priv->wrap_width, 0, 1);
- else
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), tearoff);
- }
-
- gtk_combo_box_menu_fill_level (combo_box, menu, NULL);
-}
+ _gtk_tree_menu_set_wrap_width (GTK_TREE_MENU (menu), priv->wrap_width);
+ _gtk_tree_menu_set_row_span_column (GTK_TREE_MENU (menu), priv->row_column);
+ _gtk_tree_menu_set_column_span_column (GTK_TREE_MENU (menu), priv->col_column);
+ _gtk_tree_menu_set_tearoff (GTK_TREE_MENU (menu),
+ combo_box->priv->add_tearoffs);
-static GtkWidget *
-gtk_cell_view_menu_item_new (GtkComboBox *combo_box,
- GtkTreeModel *model,
- GtkTreeIter *iter)
-{
- GtkWidget *cell_view;
- GtkWidget *item;
- GtkTreePath *path;
- GtkRequisition req;
+ g_signal_connect (menu, "menu-activate",
+ G_CALLBACK (gtk_combo_box_menu_activate), combo_box);
- cell_view = gtk_cell_view_new ();
- item = gtk_menu_item_new ();
- gtk_container_add (GTK_CONTAINER (item), cell_view);
+ /* Chain our row_separator_func through */
+ _gtk_tree_menu_set_row_separator_func (GTK_TREE_MENU (menu),
+ (GtkTreeViewRowSeparatorFunc)gtk_combo_box_row_separator_func,
+ combo_box, NULL);
- gtk_cell_view_set_model (GTK_CELL_VIEW (cell_view), model);
- path = gtk_tree_model_get_path (model, iter);
- gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (cell_view), path);
- gtk_tree_path_free (path);
+ _gtk_tree_menu_set_header_func (GTK_TREE_MENU (menu),
+ (GtkTreeMenuHeaderFunc)gtk_combo_box_header_func,
+ combo_box, NULL);
- gtk_combo_box_sync_cells (combo_box, GTK_CELL_LAYOUT (cell_view));
- gtk_widget_get_preferred_size (cell_view, &req, NULL);
- gtk_widget_show (cell_view);
-
- return item;
-}
-
-static void
-gtk_combo_box_menu_fill_level (GtkComboBox *combo_box,
- GtkWidget *menu,
- GtkTreeIter *parent)
-{
- GtkComboBoxPrivate *priv = combo_box->priv;
- GtkTreeModel *model = priv->model;
- GtkWidget *item, *submenu, *subitem, *separator;
- GtkTreeIter iter;
- gboolean is_separator;
- gint i, n_children;
- GtkWidget *last;
- GtkTreePath *path;
-
- n_children = gtk_tree_model_iter_n_children (model, parent);
+ gtk_widget_set_name (menu, "gtk-combobox-popup-menu");
- last = NULL;
- for (i = 0; i < n_children; i++)
- {
- gtk_tree_model_iter_nth_child (model, &iter, parent, i);
+ g_signal_connect (menu, "key-press-event",
+ G_CALLBACK (gtk_combo_box_menu_key_press), combo_box);
+ gtk_combo_box_set_popup_widget (combo_box, menu);
- if (priv->row_separator_func)
- is_separator = priv->row_separator_func (priv->model, &iter,
- priv->row_separator_data);
- else
- is_separator = FALSE;
-
- if (is_separator)
- {
- item = gtk_separator_menu_item_new ();
- path = gtk_tree_model_get_path (model, &iter);
- g_object_set_data_full (G_OBJECT (item),
- I_("gtk-combo-box-item-path"),
- gtk_tree_row_reference_new (model, path),
- (GDestroyNotify)gtk_tree_row_reference_free);
- gtk_tree_path_free (path);
- }
- else
- {
- item = gtk_cell_view_menu_item_new (combo_box, model, &iter);
- if (gtk_tree_model_iter_has_child (model, &iter))
- {
- submenu = gtk_menu_new ();
- gtk_menu_set_reserve_toggle_size (GTK_MENU (submenu), FALSE);
- gtk_widget_show (submenu);
- gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
-
- /* Ugly - since menus can only activate leafs, we have to
- * duplicate the item inside the submenu.
- */
- subitem = gtk_cell_view_menu_item_new (combo_box, model, &iter);
- separator = gtk_separator_menu_item_new ();
- gtk_widget_show (subitem);
- gtk_widget_show (separator);
- g_signal_connect (subitem, "activate",
- G_CALLBACK (gtk_combo_box_menu_item_activate),
- combo_box);
- gtk_menu_shell_append (GTK_MENU_SHELL (submenu), subitem);
- gtk_menu_shell_append (GTK_MENU_SHELL (submenu), separator);
-
- gtk_combo_box_menu_fill_level (combo_box, submenu, &iter);
- }
- g_signal_connect (item, "activate",
- G_CALLBACK (gtk_combo_box_menu_item_activate),
- combo_box);
- }
-
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
- if (priv->wrap_width && menu == priv->popup_widget)
- gtk_combo_box_relayout_item (combo_box, item, &iter, last);
- gtk_widget_show (item);
-
- last = item;
- }
+ gtk_combo_box_update_title (combo_box);
}
static void
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,
+ gtk_combo_box_menu_activate, combo_box);
/* unparent will remove our latest ref */
gtk_widget_unparent (priv->button);
-
+
priv->box = NULL;
priv->button = NULL;
priv->arrow = NULL;
priv->separator = NULL;
- g_object_unref (priv->column);
priv->column = NULL;
/* changing the popup window will unref the menu and the children */
}
-/*
- * grid
- */
-
+/* callbacks */
static gboolean
-menu_occupied (GtkMenu *menu,
- guint left_attach,
- guint right_attach,
- guint top_attach,
- guint bottom_attach)
+gtk_combo_box_menu_button_press (GtkWidget *widget,
+ GdkEventButton *event,
+ gpointer user_data)
{
- GList *i;
+ GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
+ GtkComboBoxPrivate *priv = combo_box->priv;
- for (i = GTK_MENU_SHELL (menu)->children; i; i = i->next)
+ if (GTK_IS_MENU (priv->popup_widget) &&
+ event->type == GDK_BUTTON_PRESS && event->button == 1)
{
- guint l, r, b, t;
-
- gtk_container_child_get (GTK_CONTAINER (menu),
- i->data,
- "left-attach", &l,
- "right-attach", &r,
- "bottom-attach", &b,
- "top-attach", &t,
- NULL);
-
- /* look if this item intersects with the given coordinates */
- if (right_attach > l && left_attach < r && bottom_attach > t && top_attach < b)
- return TRUE;
+ if (priv->focus_on_click &&
+ !gtk_widget_has_focus (priv->button))
+ gtk_widget_grab_focus (priv->button);
+
+ gtk_combo_box_menu_popup (combo_box, event->button, event->time);
+
+ return TRUE;
}
return FALSE;
}
static void
-gtk_combo_box_relayout_item (GtkComboBox *combo_box,
- GtkWidget *item,
- GtkTreeIter *iter,
- GtkWidget *last)
+gtk_combo_box_menu_activate (GtkWidget *menu,
+ const gchar *path,
+ GtkComboBox *combo_box)
{
- GtkComboBoxPrivate *priv = combo_box->priv;
- gint current_col = 0, current_row = 0;
- gint rows = 1, cols = 1;
- GtkWidget *menu = priv->popup_widget;
+ GtkTreeIter iter;
- if (!GTK_IS_MENU_SHELL (menu))
- return;
-
- if (priv->col_column == -1 &&
- priv->row_column == -1 &&
- last)
- {
- gtk_container_child_get (GTK_CONTAINER (menu),
- last,
- "right-attach", ¤t_col,
- "top-attach", ¤t_row,
- NULL);
- if (current_col + cols > priv->wrap_width)
- {
- current_col = 0;
- current_row++;
- }
- }
- else
- {
- if (priv->col_column != -1)
- gtk_tree_model_get (priv->model, iter,
- priv->col_column, &cols,
- -1);
- if (priv->row_column != -1)
- gtk_tree_model_get (priv->model, iter,
- priv->row_column, &rows,
- -1);
-
- while (1)
- {
- if (current_col + cols > priv->wrap_width)
- {
- current_col = 0;
- current_row++;
- }
-
- if (!menu_occupied (GTK_MENU (menu),
- current_col, current_col + cols,
- current_row, current_row + rows))
- break;
-
- current_col++;
- }
- }
-
- /* set attach props */
- gtk_menu_attach (GTK_MENU (menu), item,
- current_col, current_col + cols,
- current_row, current_row + rows);
-}
-
-static void
-gtk_combo_box_relayout (GtkComboBox *combo_box)
-{
- GList *list, *j;
- GtkWidget *menu;
-
- menu = combo_box->priv->popup_widget;
-
- /* do nothing unless we are in menu style and realized */
- if (combo_box->priv->tree_view || !GTK_IS_MENU_SHELL (menu))
- return;
-
- list = gtk_container_get_children (GTK_CONTAINER (menu));
-
- for (j = g_list_last (list); j; j = j->prev)
- gtk_container_remove (GTK_CONTAINER (menu), j->data);
-
- gtk_combo_box_menu_fill (combo_box);
-
- g_list_free (list);
-}
-
-/* callbacks */
-static gboolean
-gtk_combo_box_menu_button_press (GtkWidget *widget,
- GdkEventButton *event,
- gpointer user_data)
-{
- GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
- GtkComboBoxPrivate *priv = combo_box->priv;
-
- if (GTK_IS_MENU (priv->popup_widget) &&
- event->type == GDK_BUTTON_PRESS && event->button == 1)
- {
- if (priv->focus_on_click &&
- !gtk_widget_has_focus (priv->button))
- gtk_widget_grab_focus (priv->button);
-
- gtk_combo_box_menu_popup (combo_box, event->button, event->time);
-
- return TRUE;
- }
-
- return FALSE;
-}
-
-static void
-gtk_combo_box_menu_item_activate (GtkWidget *item,
- gpointer user_data)
-{
- GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
- GtkWidget *cell_view;
- GtkTreePath *path;
- GtkTreeIter iter;
-
- cell_view = gtk_bin_get_child (GTK_BIN (item));
-
- g_return_if_fail (GTK_IS_CELL_VIEW (cell_view));
-
- path = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (cell_view));
-
- if (gtk_tree_model_get_iter (combo_box->priv->model, &iter, path))
- {
- if (gtk_menu_item_get_submenu (GTK_MENU_ITEM (item)) == NULL)
- gtk_combo_box_set_active_iter (combo_box, &iter);
- }
-
- gtk_tree_path_free (path);
-
- g_object_set (combo_box,
- "editing-canceled", FALSE,
- NULL);
-}
-
-static void
-gtk_combo_box_update_sensitivity (GtkComboBox *combo_box)
-{
- GtkTreeIter iter;
- gboolean sensitive = TRUE; /* fool code checkers */
-
- if (!combo_box->priv->button)
+ if (gtk_tree_model_get_iter_from_string (combo_box->priv->model, &iter, path))
+ gtk_combo_box_set_active_iter (combo_box, &iter);
+
+ g_object_set (combo_box,
+ "editing-canceled", FALSE,
+ NULL);
+}
+
+
+static void
+gtk_combo_box_update_sensitivity (GtkComboBox *combo_box)
+{
+ GtkTreeIter iter;
+ gboolean sensitive = TRUE; /* fool code checkers */
+
+ if (!combo_box->priv->button)
return;
switch (combo_box->priv->button_sensitivity)
if (combo_box->priv->tree_view)
gtk_combo_box_list_popup_resize (combo_box);
- else
- gtk_combo_box_menu_row_inserted (model, path, iter, user_data);
gtk_combo_box_update_sensitivity (combo_box);
}
if (priv->tree_view)
gtk_combo_box_list_popup_resize (combo_box);
- else
- gtk_combo_box_menu_row_deleted (model, path, user_data);
gtk_combo_box_update_sensitivity (combo_box);
}
gint *new_order,
gpointer user_data)
{
- GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
-
gtk_tree_row_reference_reordered (G_OBJECT (user_data), path, iter, new_order);
-
- if (!combo_box->priv->tree_view)
- gtk_combo_box_menu_rows_reordered (model, path, iter, new_order, user_data);
}
static void
if (priv->tree_view)
gtk_combo_box_list_row_changed (model, path, iter, user_data);
- else
- gtk_combo_box_menu_row_changed (model, path, iter, user_data);
}
static gboolean
}
-static GtkWidget *
-find_menu_by_path (GtkWidget *menu,
- GtkTreePath *path,
- gboolean skip_first)
-{
- GList *i, *list;
- GtkWidget *child;
- GtkWidget *item;
- GtkWidget *submenu;
- GtkTreeRowReference *mref;
- GtkTreePath *mpath;
- gboolean skip;
-
- list = gtk_container_get_children (GTK_CONTAINER (menu));
- skip = skip_first;
- item = NULL;
- for (i = list; i; i = i->next)
- {
- child = gtk_bin_get_child (i->data);
- if (GTK_IS_SEPARATOR_MENU_ITEM (i->data))
- {
- mref = g_object_get_data (G_OBJECT (i->data), "gtk-combo-box-item-path");
- if (!mref)
- continue;
- else if (!gtk_tree_row_reference_valid (mref))
- mpath = NULL;
- else
- mpath = gtk_tree_row_reference_get_path (mref);
- }
- else if (GTK_IS_CELL_VIEW (child))
- {
- if (skip)
- {
- skip = FALSE;
- continue;
- }
-
- mpath = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (child));
- }
- else
- continue;
-
- /* this case is necessary, since the row reference of
- * the cell view may already be updated after a deletion
- */
- if (!mpath)
- {
- item = i->data;
- break;
- }
- if (gtk_tree_path_compare (mpath, path) == 0)
- {
- gtk_tree_path_free (mpath);
- item = i->data;
- break;
- }
- if (gtk_tree_path_is_ancestor (mpath, path))
- {
- submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
- if (submenu != NULL)
- {
- gtk_tree_path_free (mpath);
- item = find_menu_by_path (submenu, path, TRUE);
- break;
- }
- }
- gtk_tree_path_free (mpath);
- }
-
- g_list_free (list);
-
- return item;
-}
-
-#if 0
-static void
-dump_menu_tree (GtkWidget *menu,
- gint level)
-{
- GList *i, *list;
- GtkWidget *submenu;
- GtkTreePath *path;
-
- list = gtk_container_get_children (GTK_CONTAINER (menu));
- for (i = list; i; i = i->next)
- {
- if (GTK_IS_CELL_VIEW (GTK_BIN (i->data)->child))
- {
- path = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (GTK_BIN (i->data)->child));
- g_print ("%*s%s\n", 2 * level, " ", gtk_tree_path_to_string (path));
- gtk_tree_path_free (path);
-
- submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
- if (submenu != NULL)
- dump_menu_tree (submenu, level + 1);
- }
- }
-
- g_list_free (list);
-}
-#endif
-
-static void
-gtk_combo_box_menu_row_inserted (GtkTreeModel *model,
- GtkTreePath *path,
- GtkTreeIter *iter,
- gpointer user_data)
-{
- GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
- GtkComboBoxPrivate *priv = combo_box->priv;
- GtkWidget *parent;
- GtkWidget *item, *menu, *separator;
- GtkTreePath *ppath;
- GtkTreeIter piter;
- gint depth, pos;
- gboolean is_separator;
-
- if (!priv->popup_widget)
- return;
-
- depth = gtk_tree_path_get_depth (path);
- pos = gtk_tree_path_get_indices (path)[depth - 1];
- if (depth > 1)
- {
- ppath = gtk_tree_path_copy (path);
- gtk_tree_path_up (ppath);
- parent = find_menu_by_path (priv->popup_widget, ppath, FALSE);
- gtk_tree_path_free (ppath);
-
- menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (parent));
- if (!menu)
- {
- menu = gtk_menu_new ();
- gtk_menu_set_reserve_toggle_size (GTK_MENU (menu), FALSE);
- gtk_widget_show (menu);
- gtk_menu_item_set_submenu (GTK_MENU_ITEM (parent), menu);
-
- /* Ugly - since menus can only activate leaves, we have to
- * duplicate the item inside the submenu.
- */
- gtk_tree_model_iter_parent (model, &piter, iter);
- item = gtk_cell_view_menu_item_new (combo_box, model, &piter);
- separator = gtk_separator_menu_item_new ();
- g_signal_connect (item, "activate",
- G_CALLBACK (gtk_combo_box_menu_item_activate),
- combo_box);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), separator);
- if (cell_view_is_sensitive (GTK_CELL_VIEW (gtk_bin_get_child (GTK_BIN (item)))))
- {
- gtk_widget_show (item);
- gtk_widget_show (separator);
- }
- }
- pos += 2;
- }
- else
- {
- menu = priv->popup_widget;
- if (priv->add_tearoffs)
- pos += 1;
- }
-
- if (priv->row_separator_func)
- is_separator = priv->row_separator_func (model, iter,
- priv->row_separator_data);
- else
- is_separator = FALSE;
-
- if (is_separator)
- {
- item = gtk_separator_menu_item_new ();
- g_object_set_data_full (G_OBJECT (item),
- I_("gtk-combo-box-item-path"),
- gtk_tree_row_reference_new (model, path),
- (GDestroyNotify)gtk_tree_row_reference_free);
- }
- else
- {
- item = gtk_cell_view_menu_item_new (combo_box, model, iter);
-
- g_signal_connect (item, "activate",
- G_CALLBACK (gtk_combo_box_menu_item_activate),
- combo_box);
- }
-
- gtk_widget_show (item);
- gtk_menu_shell_insert (GTK_MENU_SHELL (menu), item, pos);
-}
-
-static void
-gtk_combo_box_menu_row_deleted (GtkTreeModel *model,
- GtkTreePath *path,
- gpointer user_data)
-{
- GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
- GtkComboBoxPrivate *priv = combo_box->priv;
- GtkWidget *menu;
- GtkWidget *item;
-
- if (!priv->popup_widget)
- return;
-
- item = find_menu_by_path (priv->popup_widget, path, FALSE);
- menu = gtk_widget_get_parent (item);
- gtk_container_remove (GTK_CONTAINER (menu), item);
-
- if (gtk_tree_path_get_depth (path) > 1)
- {
- GtkTreePath *parent_path;
- GtkTreeIter iter;
- GtkWidget *parent;
-
- parent_path = gtk_tree_path_copy (path);
- gtk_tree_path_up (parent_path);
- gtk_tree_model_get_iter (model, &iter, parent_path);
-
- if (!gtk_tree_model_iter_has_child (model, &iter))
- {
- parent = find_menu_by_path (priv->popup_widget,
- parent_path, FALSE);
- gtk_menu_item_set_submenu (GTK_MENU_ITEM (parent), NULL);
- }
- }
-}
-
-static void
-gtk_combo_box_menu_rows_reordered (GtkTreeModel *model,
- GtkTreePath *path,
- GtkTreeIter *iter,
- gint *new_order,
- gpointer user_data)
-{
- GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
-
- gtk_combo_box_relayout (combo_box);
-}
-
-static void
-gtk_combo_box_menu_row_changed (GtkTreeModel *model,
- GtkTreePath *path,
- GtkTreeIter *iter,
- gpointer user_data)
-{
- GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
- GtkComboBoxPrivate *priv = combo_box->priv;
- GtkWidget *item;
- gboolean is_separator;
-
- if (!priv->popup_widget)
- return;
-
- item = find_menu_by_path (priv->popup_widget, path, FALSE);
-
- if (priv->row_separator_func)
- is_separator = priv->row_separator_func (model, iter,
- priv->row_separator_data);
- else
- is_separator = FALSE;
-
- if (is_separator != GTK_IS_SEPARATOR_MENU_ITEM (item))
- {
- gtk_combo_box_menu_row_deleted (model, path, combo_box);
- gtk_combo_box_menu_row_inserted (model, path, iter, combo_box);
- }
-
- if (priv->wrap_width &&
- gtk_widget_get_parent (item) == priv->popup_widget)
- {
- GtkWidget *pitem = NULL;
- GtkTreePath *prev;
-
- prev = gtk_tree_path_copy (path);
-
- if (gtk_tree_path_prev (prev))
- pitem = find_menu_by_path (priv->popup_widget, prev, FALSE);
-
- gtk_tree_path_free (prev);
-
- /* unattach item so gtk_combo_box_relayout_item() won't spuriously
- move it */
- gtk_container_child_set (GTK_CONTAINER (priv->popup_widget),
- item,
- "left-attach", -1,
- "right-attach", -1,
- "top-attach", -1,
- "bottom-attach", -1,
- NULL);
-
- gtk_combo_box_relayout_item (combo_box, item, iter, pitem);
- }
-
- gtk_combo_box_update_requested_width (combo_box, path);
-}
-
/*
* list style
*/
{
GtkComboBoxPrivate *priv = combo_box->priv;
GtkTreeSelection *sel;
- GtkStyle *style;
GtkWidget *child;
GtkWidget *widget = GTK_WIDGET (combo_box);
if (priv->cell_view)
{
- style = gtk_widget_get_style (widget);
- gtk_cell_view_set_background_color (GTK_CELL_VIEW (priv->cell_view),
- &style->base[gtk_widget_get_state (widget)]);
+ 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);
priv->box = gtk_event_box_new ();
gtk_event_box_set_visible_window (GTK_EVENT_BOX (priv->box),
FALSE);
gtk_tree_view_set_hover_selection (GTK_TREE_VIEW (priv->tree_view),
TRUE);
- if (priv->row_separator_func)
- gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (priv->tree_view),
- priv->row_separator_func,
- priv->row_separator_data,
- NULL);
+
+ 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);
- /* sync up */
- gtk_combo_box_sync_cells (combo_box,
- GTK_CELL_LAYOUT (priv->column));
-
if (gtk_tree_row_reference_valid (priv->active_row))
{
GtkTreePath *path;
gboolean path_currently_selected,
gpointer data)
{
- GList *list;
+ GList *list, *columns;
gboolean sensitive = FALSE;
- for (list = selection->tree_view->priv->columns; list && !sensitive; list = list->next)
+ columns = gtk_tree_view_get_columns (gtk_tree_selection_get_tree_view (selection));
+
+ for (list = columns; list && !sensitive; list = list->next)
{
GList *cells, *cell;
gboolean cell_sensitive, cell_visible;
GtkTreeIter iter;
GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN (list->data);
- if (!column->visible)
+ if (!gtk_tree_view_column_get_visible (column))
continue;
gtk_tree_model_get_iter (model, &iter, path);
gtk_tree_view_column_cell_set_cell_data (column, model, &iter,
FALSE, FALSE);
- cell = cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (column));
- while (cell)
- {
- g_object_get (cell->data,
- "sensitive", &cell_sensitive,
- "visible", &cell_visible,
- NULL);
-
- if (cell_visible && cell_sensitive)
- break;
-
- cell = cell->next;
- }
- g_list_free (cells);
-
- sensitive = cell_sensitive;
- }
-
- return sensitive;
-}
-
-static void
-gtk_combo_box_list_row_changed (GtkTreeModel *model,
- GtkTreePath *path,
- GtkTreeIter *iter,
- gpointer data)
-{
- GtkComboBox *combo_box = GTK_COMBO_BOX (data);
-
- gtk_combo_box_update_requested_width (combo_box, path);
-}
-
-/*
- * GtkCellLayout implementation
- */
-
-static void
-pack_start_recurse (GtkWidget *menu,
- GtkCellRenderer *cell,
- gboolean expand)
-{
- GList *i, *list;
- GtkWidget *child;
- GtkWidget *submenu;
-
- list = gtk_container_get_children (GTK_CONTAINER (menu));
- for (i = list; i; i = i->next)
- {
- child = gtk_bin_get_child (GTK_BIN (i->data));
- if (GTK_IS_CELL_LAYOUT (child))
- gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (child),
- cell, expand);
-
- submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
- if (submenu != NULL)
- pack_start_recurse (submenu, cell, expand);
- }
-
- g_list_free (list);
-}
-
-static void
-gtk_combo_box_cell_layout_pack_start (GtkCellLayout *layout,
- GtkCellRenderer *cell,
- gboolean expand)
-{
- GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
- ComboCellInfo *info;
- GtkComboBoxPrivate *priv;
-
- priv = combo_box->priv;
-
- g_object_ref_sink (cell);
-
- info = g_slice_new0 (ComboCellInfo);
- info->cell = cell;
- info->expand = expand;
- info->pack = GTK_PACK_START;
-
- priv->cells = g_slist_append (priv->cells, info);
-
- if (priv->cell_view)
- {
- gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (priv->cell_view),
- cell, expand);
-
- }
-
- if (priv->column)
- gtk_tree_view_column_pack_start (priv->column, cell, expand);
-
- if (GTK_IS_MENU (priv->popup_widget))
- pack_start_recurse (priv->popup_widget, cell, expand);
-}
-
-static void
-pack_end_recurse (GtkWidget *menu,
- GtkCellRenderer *cell,
- gboolean expand)
-{
- GList *i, *list;
- GtkWidget *child;
- GtkWidget *submenu;
-
- list = gtk_container_get_children (GTK_CONTAINER (menu));
- for (i = list; i; i = i->next)
- {
- child = gtk_bin_get_child (GTK_BIN (i->data));
- if (GTK_IS_CELL_LAYOUT (child))
- gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (child),
- cell, expand);
-
- submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
- if (submenu != NULL)
- pack_end_recurse (submenu, cell, expand);
- }
-
- g_list_free (list);
-}
-
-static void
-gtk_combo_box_cell_layout_pack_end (GtkCellLayout *layout,
- GtkCellRenderer *cell,
- gboolean expand)
-{
- GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
- ComboCellInfo *info;
- GtkComboBoxPrivate *priv;
-
- priv = combo_box->priv;
-
- g_object_ref_sink (cell);
-
- info = g_slice_new0 (ComboCellInfo);
- info->cell = cell;
- info->expand = expand;
- info->pack = GTK_PACK_END;
-
- priv->cells = g_slist_append (priv->cells, info);
-
- if (priv->cell_view)
- gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (priv->cell_view),
- cell, expand);
-
- if (priv->column)
- gtk_tree_view_column_pack_end (priv->column, cell, expand);
-
- if (GTK_IS_MENU (priv->popup_widget))
- pack_end_recurse (priv->popup_widget, cell, expand);
-}
-
-static GList *
-gtk_combo_box_cell_layout_get_cells (GtkCellLayout *layout)
-{
- GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
- GSList *list;
- GList *retval = NULL;
-
- for (list = combo_box->priv->cells; list; list = list->next)
- {
- ComboCellInfo *info = (ComboCellInfo *)list->data;
-
- retval = g_list_prepend (retval, info->cell);
- }
-
- return g_list_reverse (retval);
-}
-
-static void
-clear_recurse (GtkWidget *menu)
-{
- GList *i, *list;
- GtkWidget *child;
- GtkWidget *submenu;
-
- list = gtk_container_get_children (GTK_CONTAINER (menu));
- for (i = list; i; i = i->next)
- {
- child = gtk_bin_get_child (GTK_BIN (i->data));
- if (GTK_IS_CELL_LAYOUT (child))
- gtk_cell_layout_clear (GTK_CELL_LAYOUT (child));
-
- submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
- if (submenu != NULL)
- clear_recurse (submenu);
- }
-
- g_list_free (list);
-}
-
-static void
-gtk_combo_box_cell_layout_clear (GtkCellLayout *layout)
-{
- GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
- GtkComboBoxPrivate *priv = combo_box->priv;
- GSList *i;
-
- if (priv->cell_view)
- gtk_cell_layout_clear (GTK_CELL_LAYOUT (priv->cell_view));
-
- if (priv->column)
- gtk_tree_view_column_clear (priv->column);
-
- for (i = priv->cells; i; i = i->next)
- {
- ComboCellInfo *info = (ComboCellInfo *)i->data;
-
- gtk_combo_box_cell_layout_clear_attributes (layout, info->cell);
- g_object_unref (info->cell);
- g_slice_free (ComboCellInfo, info);
- i->data = NULL;
- }
- g_slist_free (priv->cells);
- priv->cells = NULL;
-
- if (GTK_IS_MENU (priv->popup_widget))
- clear_recurse (priv->popup_widget);
-}
-
-static void
-add_attribute_recurse (GtkWidget *menu,
- GtkCellRenderer *cell,
- const gchar *attribute,
- gint column)
-{
- GList *i, *list;
- GtkWidget *child;
- GtkWidget *submenu;
-
- list = gtk_container_get_children (GTK_CONTAINER (menu));
- for (i = list; i; i = i->next)
- {
- child = gtk_bin_get_child (GTK_BIN (i->data));
- if (GTK_IS_CELL_LAYOUT (child))
- gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (child),
- cell, attribute, column);
-
- submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
- if (submenu != NULL)
- add_attribute_recurse (submenu, cell, attribute, column);
- }
-
- g_list_free (list);
-}
-
-static void
-gtk_combo_box_cell_layout_add_attribute (GtkCellLayout *layout,
- GtkCellRenderer *cell,
- const gchar *attribute,
- gint column)
-{
- GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
- ComboCellInfo *info;
-
- info = gtk_combo_box_get_cell_info (combo_box, cell);
- g_return_if_fail (info != NULL);
-
- info->attributes = g_slist_prepend (info->attributes,
- GINT_TO_POINTER (column));
- info->attributes = g_slist_prepend (info->attributes,
- g_strdup (attribute));
-
- if (combo_box->priv->cell_view)
- gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo_box->priv->cell_view),
- cell, attribute, column);
-
- if (combo_box->priv->column)
- gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo_box->priv->column),
- cell, attribute, column);
-
- if (GTK_IS_MENU (combo_box->priv->popup_widget))
- add_attribute_recurse (combo_box->priv->popup_widget, cell, attribute, column);
- gtk_widget_queue_resize (GTK_WIDGET (combo_box));
-}
-
-static void
-combo_cell_data_func (GtkCellLayout *cell_layout,
- GtkCellRenderer *cell,
- GtkTreeModel *tree_model,
- GtkTreeIter *iter,
- gpointer data)
-{
- ComboCellInfo *info = (ComboCellInfo *)data;
- GtkWidget *parent = NULL;
-
- if (!info->func)
- return;
-
- info->func (cell_layout, cell, tree_model, iter, info->func_data);
-
- if (GTK_IS_WIDGET (cell_layout))
- parent = gtk_widget_get_parent (GTK_WIDGET (cell_layout));
-
- if (GTK_IS_MENU_ITEM (parent) &&
- gtk_menu_item_get_submenu (GTK_MENU_ITEM (parent)))
- g_object_set (cell, "sensitive", TRUE, NULL);
-}
-
-
-static void
-set_cell_data_func_recurse (GtkWidget *menu,
- GtkCellRenderer *cell,
- ComboCellInfo *info)
-{
- GList *i, *list;
- GtkWidget *submenu;
- GtkWidget *cell_view;
-
- list = gtk_container_get_children (GTK_CONTAINER (menu));
- for (i = list; i; i = i->next)
- {
- cell_view = gtk_bin_get_child (GTK_BIN (i->data));
- if (GTK_IS_CELL_LAYOUT (cell_view))
- {
- /* Override sensitivity for inner nodes; we don't
- * want menuitems with submenus to appear insensitive
- */
- gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (cell_view),
- cell,
- combo_cell_data_func,
- info, NULL);
- submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
- if (submenu != NULL)
- set_cell_data_func_recurse (submenu, cell, info);
- }
- }
-
- g_list_free (list);
-}
-
-static void
-gtk_combo_box_cell_layout_set_cell_data_func (GtkCellLayout *layout,
- GtkCellRenderer *cell,
- GtkCellLayoutDataFunc func,
- gpointer func_data,
- GDestroyNotify destroy)
-{
- GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
- GtkComboBoxPrivate *priv = combo_box->priv;
- ComboCellInfo *info;
-
- info = gtk_combo_box_get_cell_info (combo_box, cell);
- g_return_if_fail (info != NULL);
-
- if (info->destroy)
- {
- GDestroyNotify d = info->destroy;
-
- info->destroy = NULL;
- d (info->func_data);
- }
-
- info->func = func;
- info->func_data = func_data;
- info->destroy = destroy;
-
- if (priv->cell_view)
- gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (priv->cell_view), cell, func, func_data, NULL);
-
- if (priv->column)
- gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (priv->column), cell, func, func_data, NULL);
-
- if (GTK_IS_MENU (priv->popup_widget))
- set_cell_data_func_recurse (priv->popup_widget, cell, info);
-
- gtk_widget_queue_resize (GTK_WIDGET (combo_box));
-}
-
-static void
-clear_attributes_recurse (GtkWidget *menu,
- GtkCellRenderer *cell)
-{
- GList *i, *list;
- GtkWidget *submenu;
- GtkWidget *child;
-
- list = gtk_container_get_children (GTK_CONTAINER (menu));
- for (i = list; i; i = i->next)
- {
- child = gtk_bin_get_child (GTK_BIN (i->data));
- if (GTK_IS_CELL_LAYOUT (child))
- gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (child), cell);
-
- submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
- if (submenu != NULL)
- clear_attributes_recurse (submenu, cell);
- }
-
- g_list_free (list);
-}
-
-static void
-gtk_combo_box_cell_layout_clear_attributes (GtkCellLayout *layout,
- GtkCellRenderer *cell)
-{
- GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
- GtkComboBoxPrivate *priv;
- ComboCellInfo *info;
- GSList *list;
-
- priv = combo_box->priv;
-
- info = gtk_combo_box_get_cell_info (combo_box, cell);
- g_return_if_fail (info != NULL);
-
- list = info->attributes;
- while (list && list->next)
- {
- g_free (list->data);
- list = list->next->next;
- }
- g_slist_free (info->attributes);
- info->attributes = NULL;
-
- if (priv->cell_view)
- gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (priv->cell_view), cell);
-
- if (priv->column)
- gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (priv->column), cell);
-
- if (GTK_IS_MENU (priv->popup_widget))
- clear_attributes_recurse (priv->popup_widget, cell);
-
- gtk_widget_queue_resize (GTK_WIDGET (combo_box));
-}
-
-static void
-reorder_recurse (GtkWidget *menu,
- GtkCellRenderer *cell,
- gint position)
-{
- GList *i, *list;
- GtkWidget *child;
- GtkWidget *submenu;
-
- list = gtk_container_get_children (GTK_CONTAINER (menu));
- for (i = list; i; i = i->next)
- {
- child = gtk_bin_get_child (GTK_BIN (i->data));
- if (GTK_IS_CELL_LAYOUT (child))
- gtk_cell_layout_reorder (GTK_CELL_LAYOUT (child),
- cell, position);
-
- submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (i->data));
- if (submenu != NULL)
- reorder_recurse (submenu, cell, position);
- }
-
- g_list_free (list);
-}
-
-static void
-gtk_combo_box_cell_layout_reorder (GtkCellLayout *layout,
- GtkCellRenderer *cell,
- gint position)
-{
- GtkComboBox *combo_box = GTK_COMBO_BOX (layout);
- GtkComboBoxPrivate *priv;
- ComboCellInfo *info;
- GSList *link;
-
- priv = combo_box->priv;
-
- info = gtk_combo_box_get_cell_info (combo_box, cell);
-
- g_return_if_fail (info != NULL);
- g_return_if_fail (position >= 0);
+ cell = cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (column));
+ while (cell)
+ {
+ g_object_get (cell->data,
+ "sensitive", &cell_sensitive,
+ "visible", &cell_visible,
+ NULL);
- link = g_slist_find (priv->cells, info);
+ if (cell_visible && cell_sensitive)
+ break;
- g_return_if_fail (link != NULL);
+ cell = cell->next;
+ }
+ g_list_free (cells);
- priv->cells = g_slist_delete_link (priv->cells, link);
- priv->cells = g_slist_insert (priv->cells, info, position);
+ sensitive = cell_sensitive;
+ }
- if (priv->cell_view)
- gtk_cell_layout_reorder (GTK_CELL_LAYOUT (priv->cell_view),
- cell, position);
+ g_list_free (columns);
- if (priv->column)
- gtk_cell_layout_reorder (GTK_CELL_LAYOUT (priv->column),
- cell, position);
+ return sensitive;
+}
- if (GTK_IS_MENU (priv->popup_widget))
- reorder_recurse (priv->popup_widget, cell, position);
+static void
+gtk_combo_box_list_row_changed (GtkTreeModel *model,
+ GtkTreePath *path,
+ GtkTreeIter *iter,
+ gpointer data)
+{
+ /* XXX Do nothing ? */
+}
- gtk_widget_queue_draw (GTK_WIDGET (combo_box));
+/*
+ * GtkCellLayout implementation
+ */
+GtkCellArea *
+gtk_combo_box_cell_layout_get_area (GtkCellLayout *cell_layout)
+{
+ return GTK_COMBO_BOX (cell_layout)->priv->area;
}
/*
return g_object_new (GTK_TYPE_COMBO_BOX, NULL);
}
+/**
+ * gtk_combo_box_new_with_area:
+ * @area: the #GtkCellArea to use to layout cell renderers
+ *
+ * Creates a new empty #GtkComboBox using @area to layout cells.
+ *
+ * Return value: A new #GtkComboBox.
+ */
+GtkWidget *
+gtk_combo_box_new_with_area (GtkCellArea *area)
+{
+ return g_object_new (GTK_TYPE_COMBO_BOX, "cell-area", area, NULL);
+}
+
+/**
+ * gtk_combo_box_new_with_area_and_entry:
+ * @area: the #GtkCellArea to use to layout cell renderers
+ *
+ * Creates a new empty #GtkComboBox with an entry.
+ *
+ * The new combo box will use @area to layout cells.
+ *
+ * Return value: A new #GtkComboBox.
+ */
+GtkWidget *
+gtk_combo_box_new_with_area_and_entry (GtkCellArea *area)
+{
+ return g_object_new (GTK_TYPE_COMBO_BOX,
+ "has-entry", TRUE,
+ "cell-area", area,
+ NULL);
+}
+
+
/**
* gtk_combo_box_new_with_entry:
*
/**
* 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.
priv->wrap_width = width;
gtk_combo_box_check_appearance (combo_box);
- gtk_combo_box_relayout (combo_box);
+
+ 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");
}
if (row_span != priv->row_column)
{
priv->row_column = row_span;
-
- gtk_combo_box_relayout (combo_box);
-
+
+ if (GTK_IS_TREE_MENU (priv->popup_widget))
+ _gtk_tree_menu_set_row_span_column (GTK_TREE_MENU (priv->popup_widget), priv->row_column);
+
g_object_notify (G_OBJECT (combo_box), "row-span-column");
}
}
if (column_span != priv->col_column)
{
priv->col_column = column_span;
-
- gtk_combo_box_relayout (combo_box);
+ 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");
}
}
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");
}
combo_box->priv->model);
gtk_combo_box_list_popup_resize (combo_box);
}
- else
+
+ if (GTK_IS_TREE_MENU (combo_box->priv->popup_widget))
{
/* menu mode */
- if (combo_box->priv->popup_widget)
- gtk_combo_box_menu_fill (combo_box);
-
+ _gtk_tree_menu_set_model (GTK_TREE_MENU (combo_box->priv->popup_widget),
+ combo_box->priv->model);
}
if (combo_box->priv->cell_view)
GObject *object;
GtkComboBox *combo_box;
GtkComboBoxPrivate *priv;
+ GtkStyleContext *context;
object = G_OBJECT_CLASS (gtk_combo_box_parent_class)->constructor
(type, n_construct_properties, construct_properties);
combo_box = GTK_COMBO_BOX (object);
priv = combo_box->priv;
+ if (!priv->area)
+ {
+ GtkCellArea *area = gtk_cell_area_box_new ();
+
+ priv->area = g_object_ref_sink (area);
+ }
+
+ priv->cell_view = gtk_cell_view_new_with_context (priv->area, NULL);
+ gtk_cell_view_set_fit_model (GTK_CELL_VIEW (priv->cell_view), TRUE);
+ gtk_cell_view_set_model (GTK_CELL_VIEW (priv->cell_view), priv->model);
+ gtk_widget_set_parent (priv->cell_view, GTK_WIDGET (combo_box));
+ _gtk_bin_set_child (GTK_BIN (combo_box), priv->cell_view);
+ gtk_widget_show (priv->cell_view);
+
+ gtk_combo_box_check_appearance (combo_box);
+
+ context = gtk_widget_get_style_context (GTK_WIDGET (combo_box));
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_BUTTON);
+
if (priv->has_entry)
{
GtkWidget *entry;
combo_box->priv->popup_widget = NULL;
}
- G_OBJECT_CLASS (gtk_combo_box_parent_class)->dispose (object);
-}
+ if (combo_box->priv->area)
+ {
+ g_object_unref (combo_box->priv->area);
+ combo_box->priv->area = NULL;
+ }
-static void
-gtk_combo_box_finalize (GObject *object)
-{
- GtkComboBox *combo_box = GTK_COMBO_BOX (object);
- GSList *i;
-
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);
-
- for (i = combo_box->priv->cells; i; i = i->next)
{
- ComboCellInfo *info = (ComboCellInfo *)i->data;
- GSList *list = info->attributes;
+ gtk_widget_destroy (combo_box->priv->popup_window);
+ combo_box->priv->popup_window = NULL;
+ }
- if (info->destroy)
- info->destroy (info->func_data);
+ gtk_combo_box_unset_model (combo_box);
- while (list && list->next)
- {
- g_free (list->data);
- list = list->next->next;
- }
- g_slist_free (info->attributes);
+ G_OBJECT_CLASS (gtk_combo_box_parent_class)->dispose (object);
+}
- g_object_unref (info->cell);
- g_slice_free (ComboCellInfo, info);
- }
- g_slist_free (combo_box->priv->cells);
+static void
+gtk_combo_box_finalize (GObject *object)
+{
+ GtkComboBox *combo_box = GTK_COMBO_BOX (object);
- g_free (combo_box->priv->tearoff_title);
+ g_free (combo_box->priv->tearoff_title);
- G_OBJECT_CLASS (gtk_combo_box_parent_class)->finalize (object);
+ G_OBJECT_CLASS (gtk_combo_box_parent_class)->finalize (object);
}
-
static gboolean
gtk_cell_editable_key_press (GtkWidget *widget,
GdkEventKey *event,
{
combo_box->priv->add_tearoffs = add_tearoffs;
gtk_combo_box_check_appearance (combo_box);
- gtk_combo_box_relayout (combo_box);
+
+ if (GTK_IS_TREE_MENU (combo_box->priv->popup_widget))
+ _gtk_tree_menu_set_tearoff (GTK_TREE_MENU (combo_box->priv->popup_widget),
+ combo_box->priv->add_tearoffs);
+
g_object_notify (G_OBJECT (combo_box), "add-tearoffs");
}
}
combo_box->priv->row_separator_data = data;
combo_box->priv->row_separator_destroy = destroy;
+ /* Provoke the underlying treeview/menu to rebuild themselves with the new separator func */
if (combo_box->priv->tree_view)
- gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (combo_box->priv->tree_view),
- func, data, NULL);
+ {
+ gtk_tree_view_set_model (GTK_TREE_VIEW (combo_box->priv->tree_view), NULL);
+ gtk_tree_view_set_model (GTK_TREE_VIEW (combo_box->priv->tree_view), combo_box->priv->model);
+ }
- gtk_combo_box_relayout (combo_box);
+ if (GTK_IS_TREE_MENU (combo_box->priv->popup_widget))
+ {
+ _gtk_tree_menu_set_model (GTK_TREE_MENU (combo_box->priv->popup_widget), NULL);
+ _gtk_tree_menu_set_model (GTK_TREE_MENU (combo_box->priv->popup_widget), combo_box->priv->model);
+ }
gtk_widget_queue_draw (GTK_WIDGET (combo_box));
}
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);
+ if (!_gtk_cell_layout_buildable_custom_tag_end (buildable, builder, child, tagname, data))
+ parent_buildable_iface->custom_tag_end (buildable, builder, child, tagname, data);
}
static GObject *
return parent_buildable_iface->get_internal_child (buildable, builder, childname);
}
-static void
-gtk_combo_box_remeasure (GtkComboBox *combo_box)
-{
- GtkComboBoxPrivate *priv = combo_box->priv;
- GtkTreeIter iter;
- GtkTreePath *path;
-
- if (!priv->model ||
- !gtk_tree_model_get_iter_first (priv->model, &iter))
- return;
-
- priv->minimum_width = priv->natural_width = 0;
-
- path = gtk_tree_path_new_from_indices (0, -1);
-
- do
- {
- gint row_min = 0, row_nat = 0;
-
- if (priv->cell_view)
- gtk_cell_view_get_desired_width_of_row (GTK_CELL_VIEW (priv->cell_view),
- path, &row_min, &row_nat);
-
- priv->minimum_width = MAX (priv->minimum_width, row_min);
- priv->natural_width = MAX (priv->natural_width, row_nat);
-
- gtk_tree_path_next (path);
- }
- while (gtk_tree_model_iter_next (priv->model, &iter));
-
- gtk_tree_path_free (path);
-}
-
-
-static void
-gtk_combo_box_measure_height_for_width (GtkComboBox *combo_box,
- gint avail_width,
- gint *min_height,
- gint *nat_height)
-{
- GtkWidget *child;
- GtkComboBoxPrivate *priv = combo_box->priv;
- GtkTreeIter iter;
- GtkTreePath *path;
- gint child_min, child_nat;
-
- child = gtk_bin_get_child (GTK_BIN (combo_box));
-
- gtk_widget_get_preferred_height_for_width (child, avail_width,
- &child_min, &child_nat);
-
- if (!priv->model ||
- !gtk_tree_model_get_iter_first (priv->model, &iter))
- goto out;
-
- path = gtk_tree_path_new_from_indices (0, -1);
-
- do
- {
- gint row_min = 0, row_nat = 0;
-
- if (priv->cell_view)
- gtk_cell_view_get_desired_height_for_width_of_row (GTK_CELL_VIEW (priv->cell_view),
- path, avail_width,
- &row_min, &row_nat);
-
- child_min = MAX (child_min, row_min);
- child_nat = MAX (child_nat, row_nat);
-
- gtk_tree_path_next (path);
- }
- while (gtk_tree_model_iter_next (priv->model, &iter));
-
- gtk_tree_path_free (path);
-
- out:
-
- if (min_height)
- *min_height = child_min;
- if (nat_height)
- *nat_height = child_nat;
-}
-
-
static void
gtk_combo_box_get_preferred_width (GtkWidget *widget,
gint *minimum_size,
{
GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
GtkComboBoxPrivate *priv = combo_box->priv;
- GtkStyle *style;
gint focus_width, focus_pad;
gint font_size, arrow_size;
PangoContext *context;
PangoFontMetrics *metrics;
PangoFontDescription *font_desc;
GtkWidget *child;
- gint minimum_width, natural_width;
+ 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_combo_box_remeasure (combo_box);
-
- child_min = MAX (child_min, priv->minimum_width);
- child_nat = MAX (child_nat, priv->natural_width);
gtk_widget_style_get (GTK_WIDGET (widget),
"focus-line-width", &focus_width,
"arrow-size", &arrow_size,
NULL);
- font_desc = gtk_widget_get_style (child)->font_desc;
+ 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);
if (!priv->tree_view)
{
- /* menu mode */
-
+ /* menu mode */
if (priv->cell_view)
{
gint sep_width, arrow_width;
- gint border_width, xthickness, xpad;
+ gint border_width, xpad;
+ GtkBorder button_border;
border_width = gtk_container_get_border_width (GTK_CONTAINER (combo_box));
- xthickness = gtk_widget_get_style (priv->button)->xthickness;
+ 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 + xthickness + focus_width + focus_pad);
+ 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;
{
if (priv->has_frame)
{
- gint border_width = gtk_container_get_border_width (GTK_CONTAINER (priv->cell_view_frame));
- gint xpad = 2 * (border_width + gtk_widget_get_style (GTK_WIDGET (priv->cell_view_frame))->xthickness);
+ 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;
natural_width += button_nat_width;
}
- if (GTK_SHADOW_NONE != priv->shadow_type)
- {
- style = gtk_widget_get_style (GTK_WIDGET (widget));
-
- minimum_width += 2 * style->xthickness;
- natural_width += 2 * style->xthickness;
- }
+ minimum_width += border->left + border->right;
+ natural_width += border->left + border->right;
+ gtk_border_free (border);
if (minimum_size)
*minimum_size = minimum_width;
{
GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
GtkComboBoxPrivate *priv = combo_box->priv;
- GtkStyle *style;
gint focus_width, focus_pad;
- gint min_height, nat_height;
+ 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);
- size = avail_size;
+ child = gtk_bin_get_child (GTK_BIN (widget));
- if (GTK_SHADOW_NONE != priv->shadow_type)
- size -= gtk_widget_get_style (GTK_WIDGET (widget))->xthickness;
+ get_widget_border (widget, &border);
+ size = avail_size - border.left;
if (!priv->tree_view)
{
/* menu mode */
if (priv->cell_view)
{
- GtkStyle *button_style;
/* calculate x/y padding and separator/arrow size */
gint sep_width, arrow_width, sep_height, arrow_height;
- gint border_width, xthickness, ythickness, xpad, ypad;
+ gint border_width, xpad, ypad;
+ GtkBorder button_border;
border_width = gtk_container_get_border_width (GTK_CONTAINER (combo_box));
- button_style = gtk_widget_get_style (priv->button);
-
- xthickness = button_style->xthickness;
- ythickness = button_style->ythickness;
+ get_widget_border (priv->button, &button_border);
gtk_widget_get_preferred_width (priv->separator, &sep_width, NULL);
gtk_widget_get_preferred_width (priv->arrow, &arrow_width, NULL);
gtk_widget_get_preferred_height_for_width (priv->arrow,
arrow_width, &arrow_height, NULL);
- xpad = 2*(border_width + xthickness + focus_width + focus_pad);
- ypad = 2*(border_width + ythickness + focus_width + focus_pad);
+ xpad = 2 * (border_width + focus_width + focus_pad) +
+ button_border.left + button_border.right;
+ ypad = 2 * (border_width + focus_width + focus_pad) +
+ button_border.top + button_border.bottom;
size -= sep_width + arrow_width + xpad;
- gtk_combo_box_measure_height_for_width (combo_box, size, &min_height, &nat_height);
+ /* Get height-for-width of the child widget, usually a GtkCellArea calculating
+ * and fitting the whole treemodel */
+ gtk_widget_get_preferred_height_for_width (child, size, &min_height, &nat_height);
arrow_height = MAX (arrow_height, sep_height);
min_height = MAX (min_height, arrow_height);
size -= but_width;
- gtk_combo_box_measure_height_for_width (combo_box, size, &min_height, &nat_height);
+ /* 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 (priv->cell_view_frame && priv->has_frame)
{
- GtkStyle *cell_style;
+ GtkBorder frame_border;
gint border_width;
border_width = gtk_container_get_border_width (GTK_CONTAINER (priv->cell_view_frame));
- cell_style = gtk_widget_get_style (GTK_WIDGET (priv->cell_view_frame));
+ get_widget_border (GTK_WIDGET (priv->cell_view_frame), &frame_border);
- xpad = 2 * (border_width + cell_style->xthickness);
- ypad = 2 * (border_width + cell_style->ythickness);
+ xpad = (2 * border_width) + border.left + frame_border.right;
+ ypad = (2 * border_width) + border.top + frame_border.bottom;
}
size -= but_width;
size -= 2 * focus_width;
size -= xpad;
-
- gtk_combo_box_measure_height_for_width (combo_box, size, &min_height, &nat_height);
+
+ /* 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);
nat_height += ypad;
}
- if (GTK_SHADOW_NONE != priv->shadow_type)
- {
- style = gtk_widget_get_style (GTK_WIDGET (widget));
-
- min_height += 2 * style->ythickness;
- nat_height += 2 * style->ythickness;
- }
+ min_height += border.top + border.bottom;
+ nat_height += border.top + border.bottom;
if (minimum_size)
*minimum_size = min_height;
if (natural_size)
*natural_size = nat_height;
}
+
+/**
+ * gtk_combo_box_set_id_column:
+ * @combo_box: A #GtkComboBox
+ * @id_column: A column in @model to get string IDs for values from
+ *
+ * Sets the model column which @combo_box should use to get string IDs
+ * for values from. The column @id_column in the model of @combo_box
+ * must be of type %G_TYPE_STRING.
+ *
+ * Since: 3.0
+ */
+void
+gtk_combo_box_set_id_column (GtkComboBox *combo_box,
+ gint id_column)
+{
+ GtkComboBoxPrivate *priv = combo_box->priv;
+ GtkTreeModel *model;
+
+ g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
+
+ if (id_column != priv->id_column)
+ {
+ model = gtk_combo_box_get_model (combo_box);
+
+ g_return_if_fail (id_column >= 0);
+ g_return_if_fail (model == NULL ||
+ id_column < gtk_tree_model_get_n_columns (model));
+
+ priv->id_column = id_column;
+
+ g_object_notify (G_OBJECT (combo_box), "id-column");
+ g_object_notify (G_OBJECT (combo_box), "active-id");
+ }
+}
+
+/**
+ * gtk_combo_box_get_id_column:
+ * @combo_box: A #GtkComboBox
+ *
+ * Returns the column which @combo_box is using to get string IDs
+ * for values from.
+ *
+ * Return value: A column in the data source model of @combo_box.
+ *
+ * Since: 3.0
+ */
+gint
+gtk_combo_box_get_id_column (GtkComboBox *combo_box)
+{
+ g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), 0);
+
+ return combo_box->priv->id_column;
+}
+
+/**
+ * gtk_combo_box_get_active_id:
+ * @combo_box: a #GtkComboBox
+ *
+ * Returns the ID of the active row of @combo_box. This value is taken
+ * from the active row and the column specified by the 'id-column'
+ * property of @combo_box (see gtk_combo_box_set_id_column()).
+ *
+ * The returned value is an interned string which means that you can
+ * compare the pointer by value to other interned strings and that you
+ * must not free it.
+ *
+ * If the 'id-column' property of @combo_box is not set or if no row is
+ * selected then %NULL is returned.
+ *
+ * Return value: the ID of the active row, or %NULL
+ *
+ * Since: 3.0
+ **/
+const gchar *
+gtk_combo_box_get_active_id (GtkComboBox *combo_box)
+{
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ gint column;
+
+ g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), 0);
+
+ column = combo_box->priv->id_column;
+
+ if (column < 0)
+ return NULL;
+
+ model = gtk_combo_box_get_model (combo_box);
+ g_return_val_if_fail (gtk_tree_model_get_column_type (model, column) ==
+ G_TYPE_STRING, NULL);
+
+ if (gtk_combo_box_get_active_iter (combo_box, &iter))
+ {
+ const gchar *interned;
+ gchar *id;
+
+ gtk_tree_model_get (model, &iter, column, &id, -1);
+ interned = g_intern_string (id);
+ g_free (id);
+
+ return interned;
+ }
+
+ return NULL;
+}
+
+/**
+ * gtk_combo_box_set_active_id:
+ * @combo_box: a #GtkComboBox
+ * @active_id: the ID of the row to select
+ *
+ * Changes the active row of @combo_box to the one that has an ID equal to @id.
+ *
+ * If the 'id-column' property of @combo_box is unset or if no row has
+ * the given ID then nothing happens.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_combo_box_set_active_id (GtkComboBox *combo_box,
+ const gchar *active_id)
+{
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ gint column;
+
+ g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
+
+ column = combo_box->priv->id_column;
+
+ if (column < 0)
+ return;
+
+ model = gtk_combo_box_get_model (combo_box);
+ g_return_if_fail (gtk_tree_model_get_column_type (model, column) ==
+ G_TYPE_STRING);
+
+ if (gtk_tree_model_get_iter_first (model, &iter))
+ do {
+ gboolean match;
+ gchar *id;
+
+ gtk_tree_model_get (model, &iter, column, &id, -1);
+ match = strcmp (id, active_id) == 0;
+ g_free (id);
+
+ if (match)
+ {
+ gtk_combo_box_set_active_iter (combo_box, &iter);
+ break;
+ }
+ } while (gtk_tree_model_iter_next (model, &iter));
+}