-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);