3 * Copyright (C) 2010 Openismus GmbH
6 * Tristan Van Berkom <tristanvb@openismus.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
26 * @Short_Description: A GtkMenu automatically created from a #GtkTreeModel
29 * The #GtkTreeMenu is used to display a drop-down menu allowing selection
30 * of every row in the model and is used by the #GtkComboBox for its drop-down
36 #include "gtktreemenu.h"
37 #include "gtkmarshalers.h"
38 #include "gtkmenuitem.h"
39 #include "gtktearoffmenuitem.h"
40 #include "gtkseparatormenuitem.h"
41 #include "gtkcellareabox.h"
42 #include "gtkcellareacontext.h"
43 #include "gtkcelllayout.h"
44 #include "gtkcellview.h"
45 #include "gtkprivate.h"
49 static GObject *gtk_tree_menu_constructor (GType type,
50 guint n_construct_properties,
51 GObjectConstructParam *construct_properties);
52 static void gtk_tree_menu_dispose (GObject *object);
53 static void gtk_tree_menu_finalize (GObject *object);
54 static void gtk_tree_menu_set_property (GObject *object,
58 static void gtk_tree_menu_get_property (GObject *object,
64 static void gtk_tree_menu_get_preferred_width (GtkWidget *widget,
67 static void gtk_tree_menu_get_preferred_height (GtkWidget *widget,
71 /* GtkCellLayoutIface */
72 static void gtk_tree_menu_cell_layout_init (GtkCellLayoutIface *iface);
73 static GtkCellArea *gtk_tree_menu_cell_layout_get_area (GtkCellLayout *layout);
76 /* TreeModel/DrawingArea callbacks and building menus/submenus */
77 static inline void rebuild_menu (GtkTreeMenu *menu);
78 static gboolean menu_occupied (GtkTreeMenu *menu,
83 static void relayout_item (GtkTreeMenu *menu,
87 static void gtk_tree_menu_populate (GtkTreeMenu *menu);
88 static GtkWidget *gtk_tree_menu_create_item (GtkTreeMenu *menu,
90 gboolean header_item);
91 static void gtk_tree_menu_create_submenu (GtkTreeMenu *menu,
94 static void gtk_tree_menu_set_area (GtkTreeMenu *menu,
96 static GtkWidget *gtk_tree_menu_get_path_item (GtkTreeMenu *menu,
98 static gboolean gtk_tree_menu_path_in_menu (GtkTreeMenu *menu,
100 gboolean *header_item);
101 static void row_inserted_cb (GtkTreeModel *model,
105 static void row_deleted_cb (GtkTreeModel *model,
108 static void row_reordered_cb (GtkTreeModel *model,
113 static void row_changed_cb (GtkTreeModel *model,
117 static void context_size_changed_cb (GtkCellAreaContext *context,
120 static void area_apply_attributes_cb (GtkCellArea *area,
121 GtkTreeModel *tree_model,
123 gboolean is_expander,
124 gboolean is_expanded,
126 static void item_activated_cb (GtkMenuItem *item,
128 static void submenu_activated_cb (GtkTreeMenu *submenu,
131 static void gtk_tree_menu_set_model_internal (GtkTreeMenu *menu,
132 GtkTreeModel *model);
136 struct _GtkTreeMenuPrivate
138 /* TreeModel and parent for this menu */
140 GtkTreeRowReference *root;
142 /* CellArea and context for this menu */
144 GtkCellAreaContext *context;
147 gulong size_changed_id;
148 gulong apply_attributes_id;
149 gulong row_inserted_id;
150 gulong row_deleted_id;
151 gulong row_reordered_id;
152 gulong row_changed_id;
160 guint32 menu_with_header : 1;
164 GtkTreeViewRowSeparatorFunc row_separator_func;
165 gpointer row_separator_data;
166 GDestroyNotify row_separator_destroy;
168 /* Submenu headers */
169 GtkTreeMenuHeaderFunc header_func;
170 gpointer header_data;
171 GDestroyNotify header_destroy;
186 SIGNAL_MENU_ACTIVATE,
190 static guint tree_menu_signals[N_SIGNALS] = { 0 };
191 static GQuark tree_menu_path_quark = 0;
193 G_DEFINE_TYPE_WITH_CODE (GtkTreeMenu, gtk_tree_menu, GTK_TYPE_MENU,
194 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
195 gtk_tree_menu_cell_layout_init));
198 gtk_tree_menu_init (GtkTreeMenu *menu)
200 GtkTreeMenuPrivate *priv;
202 menu->priv = G_TYPE_INSTANCE_GET_PRIVATE (menu,
210 priv->context = NULL;
212 priv->size_changed_id = 0;
213 priv->row_inserted_id = 0;
214 priv->row_deleted_id = 0;
215 priv->row_reordered_id = 0;
216 priv->row_changed_id = 0;
218 priv->wrap_width = 0;
219 priv->row_span_col = -1;
220 priv->col_span_col = -1;
222 priv->menu_with_header = FALSE;
223 priv->tearoff = FALSE;
225 priv->row_separator_func = NULL;
226 priv->row_separator_data = NULL;
227 priv->row_separator_destroy = NULL;
229 priv->header_func = NULL;
230 priv->header_data = NULL;
231 priv->header_destroy = NULL;
233 gtk_menu_set_reserve_toggle_size (GTK_MENU (menu), FALSE);
237 gtk_tree_menu_class_init (GtkTreeMenuClass *class)
239 GObjectClass *object_class = G_OBJECT_CLASS (class);
240 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
242 tree_menu_path_quark = g_quark_from_static_string ("gtk-tree-menu-path");
244 object_class->constructor = gtk_tree_menu_constructor;
245 object_class->dispose = gtk_tree_menu_dispose;
246 object_class->finalize = gtk_tree_menu_finalize;
247 object_class->set_property = gtk_tree_menu_set_property;
248 object_class->get_property = gtk_tree_menu_get_property;
250 widget_class->get_preferred_width = gtk_tree_menu_get_preferred_width;
251 widget_class->get_preferred_height = gtk_tree_menu_get_preferred_height;
254 * GtkTreeMenu::menu-activate:
255 * @menu: a #GtkTreeMenu
256 * @path: the #GtkTreePath string for the item which was activated
257 * @user_data: the user data
259 * This signal is emitted to notify that a menu item in the #GtkTreeMenu
260 * was activated and provides the path string from the #GtkTreeModel
261 * to specify which row was selected.
265 tree_menu_signals[SIGNAL_MENU_ACTIVATE] =
266 g_signal_new (I_("menu-activate"),
267 G_OBJECT_CLASS_TYPE (object_class),
269 0, /* No class closure here */
271 _gtk_marshal_VOID__STRING,
272 G_TYPE_NONE, 1, G_TYPE_STRING);
277 * The #GtkTreeModel from which the menu is constructed.
281 g_object_class_install_property (object_class,
283 g_param_spec_object ("model",
284 P_("TreeMenu model"),
285 P_("The model for the tree menu"),
287 GTK_PARAM_READWRITE));
292 * The #GtkTreePath that is the root for this menu, or %NULL.
294 * The #GtkTreeMenu recursively creates submenus for #GtkTreeModel
295 * rows that have children and the "root" for each menu is provided
296 * by the parent menu.
298 * If you dont provide a root for the #GtkTreeMenu then the whole
299 * model will be added to the menu. Specifying a root allows you
300 * to build a menu for a given #GtkTreePath and it's children.
304 g_object_class_install_property (object_class,
306 g_param_spec_boxed ("root",
307 P_("TreeMenu root row"),
308 P_("The TreeMenu will display children of the "
311 GTK_PARAM_READWRITE));
314 * GtkTreeMenu:cell-area:
316 * The #GtkCellArea used to render cells in the menu items.
318 * You can provide a different cell area at object construction
319 * time, otherwise the #GtkTreeMenu will use a #GtkCellAreaBox.
323 g_object_class_install_property (object_class,
325 g_param_spec_object ("cell-area",
327 P_("The GtkCellArea used to layout cells"),
329 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
332 * GtkTreeMenu:tearoff:
334 * Specifies whether this menu comes with a leading tearoff menu item
338 g_object_class_install_property (object_class,
340 g_param_spec_boolean ("tearoff",
342 P_("Whether the menu has a tearoff item"),
344 GTK_PARAM_READWRITE));
347 * GtkTreeMenu:wrap-width:
349 * If wrap-width is set to a positive value, the list will be
350 * displayed in multiple columns, the number of columns is
351 * determined by wrap-width.
355 g_object_class_install_property (object_class,
357 g_param_spec_int ("wrap-width",
359 P_("Wrap width for laying out items in a grid"),
363 GTK_PARAM_READWRITE));
366 * GtkTreeMenu:row-span-column:
368 * If this is set to a non-negative value, it must be the index of a column
369 * of type %G_TYPE_INT in the model.
371 * The values of that column are used to determine how many rows a value in
372 * the list will span. Therefore, the values in the model column pointed to
373 * by this property must be greater than zero and not larger than wrap-width.
377 g_object_class_install_property (object_class,
379 g_param_spec_int ("row-span-column",
380 P_("Row span column"),
381 P_("TreeModel column containing the row span values"),
385 GTK_PARAM_READWRITE));
388 * GtkTreeMenu:column-span-column:
390 * If this is set to a non-negative value, it must be the index of a column
391 * of type %G_TYPE_INT in the model.
393 * The values of that column are used to determine how many columns a value
394 * in the list will span.
398 g_object_class_install_property (object_class,
400 g_param_spec_int ("column-span-column",
401 P_("Column span column"),
402 P_("TreeModel column containing the column span values"),
406 GTK_PARAM_READWRITE));
408 g_type_class_add_private (object_class, sizeof (GtkTreeMenuPrivate));
411 /****************************************************************
413 ****************************************************************/
415 gtk_tree_menu_constructor (GType type,
416 guint n_construct_properties,
417 GObjectConstructParam *construct_properties)
421 GtkTreeMenuPrivate *priv;
423 object = G_OBJECT_CLASS (gtk_tree_menu_parent_class)->constructor
424 (type, n_construct_properties, construct_properties);
426 menu = GTK_TREE_MENU (object);
431 GtkCellArea *area = gtk_cell_area_box_new ();
433 gtk_tree_menu_set_area (menu, area);
436 priv->context = gtk_cell_area_create_context (priv->area);
438 priv->size_changed_id =
439 g_signal_connect (priv->context, "notify",
440 G_CALLBACK (context_size_changed_cb), menu);
446 gtk_tree_menu_dispose (GObject *object)
449 GtkTreeMenuPrivate *priv;
451 menu = GTK_TREE_MENU (object);
454 gtk_tree_menu_set_model (menu, NULL);
455 gtk_tree_menu_set_area (menu, NULL);
459 /* Disconnect signals */
460 g_signal_handler_disconnect (priv->context, priv->size_changed_id);
462 g_object_unref (priv->context);
463 priv->context = NULL;
464 priv->size_changed_id = 0;
467 G_OBJECT_CLASS (gtk_tree_menu_parent_class)->dispose (object);
471 gtk_tree_menu_finalize (GObject *object)
474 GtkTreeMenuPrivate *priv;
476 menu = GTK_TREE_MENU (object);
479 gtk_tree_menu_set_row_separator_func (menu, NULL, NULL, NULL);
480 gtk_tree_menu_set_header_func (menu, NULL, NULL, NULL);
483 gtk_tree_row_reference_free (priv->root);
485 G_OBJECT_CLASS (gtk_tree_menu_parent_class)->finalize (object);
489 gtk_tree_menu_set_property (GObject *object,
494 GtkTreeMenu *menu = GTK_TREE_MENU (object);
499 gtk_tree_menu_set_model (menu, g_value_get_object (value));
503 gtk_tree_menu_set_root (menu, g_value_get_boxed (value));
507 /* Construct-only, can only be assigned once */
508 gtk_tree_menu_set_area (menu, (GtkCellArea *)g_value_get_object (value));
512 gtk_tree_menu_set_tearoff (menu, g_value_get_boolean (value));
515 case PROP_WRAP_WIDTH:
516 gtk_tree_menu_set_wrap_width (menu, g_value_get_int (value));
519 case PROP_ROW_SPAN_COL:
520 gtk_tree_menu_set_row_span_column (menu, g_value_get_int (value));
523 case PROP_COL_SPAN_COL:
524 gtk_tree_menu_set_column_span_column (menu, g_value_get_int (value));
528 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
534 gtk_tree_menu_get_property (GObject *object,
539 GtkTreeMenu *menu = GTK_TREE_MENU (object);
540 GtkTreeMenuPrivate *priv = menu->priv;
545 g_value_set_object (value, priv->model);
549 g_value_set_boxed (value, priv->root);
553 g_value_set_object (value, priv->area);
557 g_value_set_boolean (value, priv->tearoff);
561 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
566 /****************************************************************
568 ****************************************************************/
570 /* We tell all the menu items to reserve space for the submenu
571 * indicator if there is at least one submenu, this way we ensure
572 * that every internal cell area gets allocated the
573 * same width (and requested height for the same appropriate width).
576 sync_reserve_submenu_size (GtkTreeMenu *menu)
579 gboolean has_submenu = FALSE;
581 children = gtk_container_get_children (GTK_CONTAINER (menu));
582 for (l = children; l; l = l->next)
584 GtkMenuItem *item = l->data;
586 if (gtk_menu_item_get_submenu (item) != NULL)
593 for (l = children; l; l = l->next)
595 GtkMenuItem *item = l->data;
597 gtk_menu_item_set_reserve_indicator (item, has_submenu);
600 g_list_free (children);
604 gtk_tree_menu_get_preferred_width (GtkWidget *widget,
608 GtkTreeMenu *menu = GTK_TREE_MENU (widget);
609 GtkTreeMenuPrivate *priv = menu->priv;
611 /* We leave the requesting work up to the cellviews which operate in the same
612 * context, reserving space for the submenu indicator if any of the items have
613 * submenus ensures that every cellview will receive the same allocated width.
615 * Since GtkMenu does hieght-for-width correctly, we know that the width of
616 * every cell will be requested before the height-for-widths are requested.
618 g_signal_handler_block (priv->context, priv->size_changed_id);
620 sync_reserve_submenu_size (menu);
622 GTK_WIDGET_CLASS (gtk_tree_menu_parent_class)->get_preferred_width (widget, minimum_size, natural_size);
624 g_signal_handler_unblock (priv->context, priv->size_changed_id);
628 gtk_tree_menu_get_preferred_height (GtkWidget *widget,
632 GtkTreeMenu *menu = GTK_TREE_MENU (widget);
633 GtkTreeMenuPrivate *priv = menu->priv;
635 g_signal_handler_block (priv->context, priv->size_changed_id);
637 sync_reserve_submenu_size (menu);
639 GTK_WIDGET_CLASS (gtk_tree_menu_parent_class)->get_preferred_height (widget, minimum_size, natural_size);
641 g_signal_handler_unblock (priv->context, priv->size_changed_id);
644 /****************************************************************
645 * GtkCellLayoutIface *
646 ****************************************************************/
648 gtk_tree_menu_cell_layout_init (GtkCellLayoutIface *iface)
650 iface->get_area = gtk_tree_menu_cell_layout_get_area;
654 gtk_tree_menu_cell_layout_get_area (GtkCellLayout *layout)
656 GtkTreeMenu *menu = GTK_TREE_MENU (layout);
657 GtkTreeMenuPrivate *priv = menu->priv;
663 /****************************************************************
664 * TreeModel callbacks/populating menus *
665 ****************************************************************/
667 gtk_tree_menu_get_path_item (GtkTreeMenu *menu,
670 GtkWidget *item = NULL;
673 children = gtk_container_get_children (GTK_CONTAINER (menu));
675 for (l = children; item == NULL && l != NULL; l = l->next)
677 GtkWidget *child = l->data;
678 GtkTreePath *path = NULL;
680 if (GTK_IS_SEPARATOR_MENU_ITEM (child))
682 GtkTreeRowReference *row =
683 g_object_get_qdata (G_OBJECT (child), tree_menu_path_quark);
687 path = gtk_tree_row_reference_get_path (row);
690 /* Return any first child where it's row-reference became invalid,
691 * this is because row-references get null paths before we recieve
692 * the "row-deleted" signal.
697 else if (!GTK_IS_TEAROFF_MENU_ITEM (child))
699 GtkWidget *view = gtk_bin_get_child (GTK_BIN (child));
701 /* It's always a cellview */
702 if (GTK_IS_CELL_VIEW (view))
703 path = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (view));
706 /* Return any first child where it's row-reference became invalid,
707 * this is because row-references get null paths before we recieve
708 * the "row-deleted" signal.
715 if (gtk_tree_path_compare (search, path) == 0)
718 gtk_tree_path_free (path);
722 g_list_free (children);
728 gtk_tree_menu_path_in_menu (GtkTreeMenu *menu,
730 gboolean *header_item)
732 GtkTreeMenuPrivate *priv = menu->priv;
733 gboolean in_menu = FALSE;
734 gboolean is_header = FALSE;
736 /* Check if the is in root of the model */
737 if (gtk_tree_path_get_depth (path) == 1)
742 /* If we are a submenu, compare the parent path */
743 else if (priv->root && gtk_tree_path_get_depth (path) > 1)
745 GtkTreePath *root_path = gtk_tree_row_reference_get_path (priv->root);
746 GtkTreePath *parent_path = gtk_tree_path_copy (path);
748 gtk_tree_path_up (parent_path);
752 if (gtk_tree_path_compare (root_path, parent_path) == 0)
755 if (!in_menu && priv->menu_with_header &&
756 gtk_tree_path_compare (root_path, path) == 0)
762 gtk_tree_path_free (root_path);
763 gtk_tree_path_free (parent_path);
767 *header_item = is_header;
773 gtk_tree_menu_path_needs_submenu (GtkTreeMenu *menu,
776 GtkWidget *item = NULL;
778 GtkTreePath *parent_path;
780 if (gtk_tree_path_get_depth (search) <= 1)
783 parent_path = gtk_tree_path_copy (search);
784 gtk_tree_path_up (parent_path);
786 children = gtk_container_get_children (GTK_CONTAINER (menu));
788 for (l = children; item == NULL && l != NULL; l = l->next)
790 GtkWidget *child = l->data;
791 GtkTreePath *path = NULL;
793 /* Separators dont get submenus, if it already has a submenu then let
794 * the submenu handle inserted rows */
795 if (!GTK_IS_SEPARATOR_MENU_ITEM (child) &&
796 !gtk_menu_item_get_submenu (GTK_MENU_ITEM (child)))
798 GtkWidget *view = gtk_bin_get_child (GTK_BIN (child));
800 /* It's always a cellview */
801 if (GTK_IS_CELL_VIEW (view))
802 path = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (view));
807 if (gtk_tree_path_compare (parent_path, path) == 0)
810 gtk_tree_path_free (path);
814 g_list_free (children);
815 gtk_tree_path_free (parent_path);
821 find_empty_submenu (GtkTreeMenu *menu)
823 GtkTreeMenuPrivate *priv = menu->priv;
825 GtkWidget *submenu = NULL;
827 children = gtk_container_get_children (GTK_CONTAINER (menu));
829 for (l = children; submenu == NULL && l != NULL; l = l->next)
831 GtkWidget *child = l->data;
832 GtkTreePath *path = NULL;
835 /* Separators dont get submenus, if it already has a submenu then let
836 * the submenu handle inserted rows */
837 if (!GTK_IS_SEPARATOR_MENU_ITEM (child) && !GTK_IS_TEAROFF_MENU_ITEM (child))
839 GtkWidget *view = gtk_bin_get_child (GTK_BIN (child));
841 /* It's always a cellview */
842 if (GTK_IS_CELL_VIEW (view))
843 path = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (view));
848 if (gtk_tree_model_get_iter (priv->model, &iter, path) &&
849 !gtk_tree_model_iter_has_child (priv->model, &iter))
850 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (child));
852 gtk_tree_path_free (path);
856 g_list_free (children);
862 row_inserted_cb (GtkTreeModel *model,
867 GtkTreeMenuPrivate *priv = menu->priv;
868 gint *indices, index, depth;
871 /* If the iter should be in this menu then go ahead and insert it */
872 if (gtk_tree_menu_path_in_menu (menu, path, NULL))
874 if (priv->wrap_width > 0)
878 /* Get the index of the path for this depth */
879 indices = gtk_tree_path_get_indices (path);
880 depth = gtk_tree_path_get_depth (path);
881 index = indices[depth -1];
883 /* Menus with a header include a menuitem for it's root node
884 * and a separator menu item */
885 if (priv->menu_with_header)
888 /* Index after the tearoff item for the root menu if
889 * there is a tearoff item
891 if (priv->root == NULL && priv->tearoff)
894 item = gtk_tree_menu_create_item (menu, iter, FALSE);
895 gtk_menu_shell_insert (GTK_MENU_SHELL (menu), item, index);
897 /* Resize everything */
898 gtk_cell_area_context_reset (menu->priv->context);
903 /* Create submenus for iters if we need to */
904 item = gtk_tree_menu_path_needs_submenu (menu, path);
907 GtkTreePath *item_path = gtk_tree_path_copy (path);
909 gtk_tree_path_up (item_path);
910 gtk_tree_menu_create_submenu (menu, item, item_path);
911 gtk_tree_path_free (item_path);
917 row_deleted_cb (GtkTreeModel *model,
921 GtkTreeMenuPrivate *priv = menu->priv;
924 /* If it's the header item we leave it to the parent menu
925 * to remove us from its menu
927 item = gtk_tree_menu_get_path_item (menu, path);
931 if (priv->wrap_width > 0)
935 /* Get rid of the deleted item */
936 gtk_widget_destroy (item);
938 /* Resize everything */
939 gtk_cell_area_context_reset (menu->priv->context);
944 /* It's up to the parent menu to destroy a child menu that becomes empty
945 * since the topmost menu belongs to the user and is allowed to have no contents */
946 GtkWidget *submenu = find_empty_submenu (menu);
948 gtk_widget_destroy (submenu);
953 row_reordered_cb (GtkTreeModel *model,
959 GtkTreeMenuPrivate *priv = menu->priv;
960 gboolean this_menu = FALSE;
962 if (path == NULL && priv->root == NULL)
966 GtkTreePath *root_path =
967 gtk_tree_row_reference_get_path (priv->root);
969 if (gtk_tree_path_compare (root_path, path) == 0)
972 gtk_tree_path_free (root_path);
980 menu_item_position (GtkTreeMenu *menu,
986 children = gtk_container_get_children (GTK_CONTAINER (menu));
987 for (position = 0, l = children; l; position++, l = l->next)
989 GtkWidget *iitem = l->data;
995 g_list_free (children);
1001 row_changed_cb (GtkTreeModel *model,
1006 GtkTreeMenuPrivate *priv = menu->priv;
1007 gboolean is_separator = FALSE;
1008 gboolean has_header = FALSE;
1011 item = gtk_tree_menu_get_path_item (menu, path);
1015 GtkTreePath *root_path =
1016 gtk_tree_row_reference_get_path (priv->root);
1018 if (root_path && gtk_tree_path_compare (root_path, path) == 0)
1020 if (priv->header_func)
1022 priv->header_func (priv->model, iter, priv->header_data);
1024 if (has_header && !item)
1026 item = gtk_separator_menu_item_new ();
1027 gtk_widget_show (item);
1028 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
1030 item = gtk_tree_menu_create_item (menu, iter, TRUE);
1031 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
1033 priv->menu_with_header = TRUE;
1035 else if (!has_header && item)
1037 /* Destroy the header item and then the following separator */
1038 gtk_widget_destroy (item);
1039 gtk_widget_destroy (GTK_MENU_SHELL (menu)->children->data);
1041 priv->menu_with_header = FALSE;
1044 gtk_tree_path_free (root_path);
1050 if (priv->wrap_width > 0)
1051 /* Ugly, we need to rebuild the menu here if
1052 * the row-span/row-column values change
1054 rebuild_menu (menu);
1057 if (priv->row_separator_func)
1059 priv->row_separator_func (model, iter,
1060 priv->row_separator_data);
1063 if (is_separator != GTK_IS_SEPARATOR_MENU_ITEM (item))
1065 gint position = menu_item_position (menu, item);
1067 gtk_widget_destroy (item);
1068 item = gtk_tree_menu_create_item (menu, iter, FALSE);
1069 gtk_menu_shell_insert (GTK_MENU_SHELL (menu), item, position);
1076 context_size_changed_cb (GtkCellAreaContext *context,
1080 if (!strcmp (pspec->name, "minimum-width") ||
1081 !strcmp (pspec->name, "natural-width") ||
1082 !strcmp (pspec->name, "minimum-height") ||
1083 !strcmp (pspec->name, "natural-height"))
1084 gtk_widget_queue_resize (menu);
1088 area_is_sensitive (GtkCellArea *area)
1090 GList *cells, *list;
1091 gboolean sensitive = FALSE;
1093 cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (area));
1095 for (list = cells; list; list = list->next)
1097 g_object_get (list->data, "sensitive", &sensitive, NULL);
1102 g_list_free (cells);
1108 area_apply_attributes_cb (GtkCellArea *area,
1109 GtkTreeModel *tree_model,
1111 gboolean is_expander,
1112 gboolean is_expanded,
1115 /* If the menu for this iter has a submenu */
1116 GtkTreeMenuPrivate *priv = menu->priv;
1122 path = gtk_tree_model_get_path (tree_model, iter);
1124 if (gtk_tree_menu_path_in_menu (menu, path, &is_header))
1126 item = gtk_tree_menu_get_path_item (menu, path);
1128 /* If there is no submenu, go ahead and update item sensitivity,
1129 * items with submenus are always sensitive */
1130 if (item && !gtk_menu_item_get_submenu (GTK_MENU_ITEM (item)))
1132 sensitive = area_is_sensitive (priv->area);
1134 gtk_widget_set_sensitive (item, sensitive);
1138 /* For header items we need to set the sensitivity
1139 * of the following separator item
1141 if (GTK_MENU_SHELL (menu)->children &&
1142 GTK_MENU_SHELL (menu)->children->next)
1144 GtkWidget *separator =
1145 GTK_MENU_SHELL (menu)->children->next->data;
1147 gtk_widget_set_sensitive (separator, sensitive);
1153 gtk_tree_path_free (path);
1157 gtk_tree_menu_set_area (GtkTreeMenu *menu,
1160 GtkTreeMenuPrivate *priv = menu->priv;
1164 g_signal_handler_disconnect (priv->area,
1165 priv->apply_attributes_id);
1166 priv->apply_attributes_id = 0;
1168 g_object_unref (priv->area);
1175 g_object_ref_sink (priv->area);
1177 priv->apply_attributes_id =
1178 g_signal_connect (priv->area, "apply-attributes",
1179 G_CALLBACK (area_apply_attributes_cb), menu);
1184 menu_occupied (GtkTreeMenu *menu,
1188 guint bottom_attach)
1192 for (i = GTK_MENU_SHELL (menu)->children; i; i = i->next)
1196 gtk_container_child_get (GTK_CONTAINER (menu),
1200 "bottom-attach", &b,
1204 /* look if this item intersects with the given coordinates */
1205 if (right_attach > l && left_attach < r && bottom_attach > t && top_attach < b)
1213 relayout_item (GtkTreeMenu *menu,
1218 GtkTreeMenuPrivate *priv = menu->priv;
1219 gint current_col = 0, current_row = 0;
1220 gint rows = 1, cols = 1;
1222 if (priv->col_span_col == -1 &&
1223 priv->row_span_col == -1 &&
1226 gtk_container_child_get (GTK_CONTAINER (menu), prev,
1227 "right-attach", ¤t_col,
1228 "top-attach", ¤t_row,
1230 if (current_col + cols > priv->wrap_width)
1238 if (priv->col_span_col != -1)
1239 gtk_tree_model_get (priv->model, iter,
1240 priv->col_span_col, &cols,
1242 if (priv->row_span_col != -1)
1243 gtk_tree_model_get (priv->model, iter,
1244 priv->row_span_col, &rows,
1249 if (current_col + cols > priv->wrap_width)
1255 if (!menu_occupied (menu,
1256 current_col, current_col + cols,
1257 current_row, current_row + rows))
1264 /* set attach props */
1265 gtk_menu_attach (GTK_MENU (menu), item,
1266 current_col, current_col + cols,
1267 current_row, current_row + rows);
1271 gtk_tree_menu_create_submenu (GtkTreeMenu *menu,
1275 GtkTreeMenuPrivate *priv = menu->priv;
1279 view = gtk_bin_get_child (GTK_BIN (item));
1280 gtk_cell_view_set_draw_sensitive (GTK_CELL_VIEW (view), TRUE);
1282 submenu = gtk_tree_menu_new_with_area (priv->area);
1284 gtk_tree_menu_set_row_separator_func (GTK_TREE_MENU (submenu),
1285 priv->row_separator_func,
1286 priv->row_separator_data,
1287 priv->row_separator_destroy);
1288 gtk_tree_menu_set_header_func (GTK_TREE_MENU (submenu),
1291 priv->header_destroy);
1293 gtk_tree_menu_set_wrap_width (GTK_TREE_MENU (submenu), priv->wrap_width);
1294 gtk_tree_menu_set_row_span_column (GTK_TREE_MENU (submenu), priv->row_span_col);
1295 gtk_tree_menu_set_column_span_column (GTK_TREE_MENU (submenu), priv->col_span_col);
1297 gtk_tree_menu_set_model_internal (GTK_TREE_MENU (submenu), priv->model);
1298 gtk_tree_menu_set_root (GTK_TREE_MENU (submenu), path);
1299 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
1301 g_signal_connect (submenu, "menu-activate",
1302 G_CALLBACK (submenu_activated_cb), menu);
1306 gtk_tree_menu_create_item (GtkTreeMenu *menu,
1308 gboolean header_item)
1310 GtkTreeMenuPrivate *priv = menu->priv;
1311 GtkWidget *item, *view;
1313 gboolean is_separator = FALSE;
1315 path = gtk_tree_model_get_path (priv->model, iter);
1317 if (priv->row_separator_func)
1319 priv->row_separator_func (priv->model, iter,
1320 priv->row_separator_data);
1324 item = gtk_separator_menu_item_new ();
1325 gtk_widget_show (item);
1327 g_object_set_qdata_full (G_OBJECT (item),
1328 tree_menu_path_quark,
1329 gtk_tree_row_reference_new (priv->model, path),
1330 (GDestroyNotify)gtk_tree_row_reference_free);
1334 view = gtk_cell_view_new_with_context (priv->area, priv->context);
1335 item = gtk_menu_item_new ();
1336 gtk_widget_show (view);
1337 gtk_widget_show (item);
1339 gtk_cell_view_set_model (GTK_CELL_VIEW (view), priv->model);
1340 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (view), path);
1342 gtk_widget_show (view);
1343 gtk_container_add (GTK_CONTAINER (item), view);
1345 g_signal_connect (item, "activate", G_CALLBACK (item_activated_cb), menu);
1347 /* Add a GtkTreeMenu submenu to render the children of this row */
1348 if (header_item == FALSE &&
1349 gtk_tree_model_iter_has_child (priv->model, iter))
1350 gtk_tree_menu_create_submenu (menu, item, path);
1353 gtk_tree_path_free (path);
1359 rebuild_menu (GtkTreeMenu *menu)
1361 GtkTreeMenuPrivate *priv = menu->priv;
1363 /* Destroy all the menu items */
1364 gtk_container_foreach (GTK_CONTAINER (menu),
1365 (GtkCallback) gtk_widget_destroy, NULL);
1369 gtk_tree_menu_populate (menu);
1374 gtk_tree_menu_populate (GtkTreeMenu *menu)
1376 GtkTreeMenuPrivate *priv = menu->priv;
1377 GtkTreePath *path = NULL;
1380 gboolean valid = FALSE;
1381 GtkWidget *menu_item, *prev = NULL;
1387 path = gtk_tree_row_reference_get_path (priv->root);
1391 if (gtk_tree_model_get_iter (priv->model, &parent, path))
1393 valid = gtk_tree_model_iter_children (priv->model, &iter, &parent);
1395 if (priv->header_func &&
1396 priv->header_func (priv->model, &parent, priv->header_data))
1398 /* Add a submenu header for rows which desire one, used for
1399 * combo boxes to allow all rows to be activatable/selectable
1401 menu_item = gtk_tree_menu_create_item (menu, &parent, TRUE);
1402 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
1404 menu_item = gtk_separator_menu_item_new ();
1405 gtk_widget_show (menu_item);
1406 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
1409 priv->menu_with_header = TRUE;
1412 gtk_tree_path_free (path);
1416 /* Tearoff menu items only go in the root menu */
1419 menu_item = gtk_tearoff_menu_item_new ();
1420 gtk_widget_show (menu_item);
1422 if (priv->wrap_width > 0)
1423 gtk_menu_attach (GTK_MENU (menu), menu_item, 0, priv->wrap_width, 0, 1);
1425 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
1430 valid = gtk_tree_model_iter_children (priv->model, &iter, NULL);
1433 /* Create a menu item for every row at the current depth, add a GtkTreeMenu
1434 * submenu for iters/items that have children */
1437 menu_item = gtk_tree_menu_create_item (menu, &iter, FALSE);
1439 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
1441 if (priv->wrap_width > 0)
1442 relayout_item (menu, menu_item, &iter, prev);
1445 valid = gtk_tree_model_iter_next (priv->model, &iter);
1450 item_activated_cb (GtkMenuItem *item,
1457 /* Only activate leafs, not parents */
1458 if (!gtk_menu_item_get_submenu (item))
1460 view = GTK_CELL_VIEW (gtk_bin_get_child (GTK_BIN (item)));
1461 path = gtk_cell_view_get_displayed_row (view);
1462 path_str = gtk_tree_path_to_string (path);
1464 g_signal_emit (menu, tree_menu_signals[SIGNAL_MENU_ACTIVATE], 0, path_str);
1467 gtk_tree_path_free (path);
1472 submenu_activated_cb (GtkTreeMenu *submenu,
1476 g_signal_emit (menu, tree_menu_signals[SIGNAL_MENU_ACTIVATE], 0, path);
1479 /* Sets the model without rebuilding the menu, prevents
1480 * infinite recursion while building submenus (we wait
1481 * until the root is set and then build the menu) */
1483 gtk_tree_menu_set_model_internal (GtkTreeMenu *menu,
1484 GtkTreeModel *model)
1486 GtkTreeMenuPrivate *priv;
1490 if (priv->model != model)
1494 /* Disconnect signals */
1495 g_signal_handler_disconnect (priv->model,
1496 priv->row_inserted_id);
1497 g_signal_handler_disconnect (priv->model,
1498 priv->row_deleted_id);
1499 g_signal_handler_disconnect (priv->model,
1500 priv->row_reordered_id);
1501 g_signal_handler_disconnect (priv->model,
1502 priv->row_changed_id);
1503 priv->row_inserted_id = 0;
1504 priv->row_deleted_id = 0;
1505 priv->row_reordered_id = 0;
1506 priv->row_changed_id = 0;
1508 g_object_unref (priv->model);
1511 priv->model = model;
1515 g_object_ref (priv->model);
1517 /* Connect signals */
1518 priv->row_inserted_id = g_signal_connect (priv->model, "row-inserted",
1519 G_CALLBACK (row_inserted_cb), menu);
1520 priv->row_deleted_id = g_signal_connect (priv->model, "row-deleted",
1521 G_CALLBACK (row_deleted_cb), menu);
1522 priv->row_reordered_id = g_signal_connect (priv->model, "rows-reordered",
1523 G_CALLBACK (row_reordered_cb), menu);
1524 priv->row_changed_id = g_signal_connect (priv->model, "row-changed",
1525 G_CALLBACK (row_changed_cb), menu);
1530 /****************************************************************
1532 ****************************************************************/
1535 * gtk_tree_menu_new:
1537 * Creates a new #GtkTreeMenu.
1539 * Return value: A newly created #GtkTreeMenu with no model or root.
1544 gtk_tree_menu_new (void)
1546 return (GtkWidget *)g_object_new (GTK_TYPE_TREE_MENU, NULL);
1550 * gtk_tree_menu_new_with_area:
1551 * @area: the #GtkCellArea to use to render cells in the menu
1553 * Creates a new #GtkTreeMenu using @area to render it's cells.
1555 * Return value: A newly created #GtkTreeMenu with no model or root.
1560 gtk_tree_menu_new_with_area (GtkCellArea *area)
1562 return (GtkWidget *)g_object_new (GTK_TYPE_TREE_MENU,
1568 * gtk_tree_menu_new_full:
1569 * @area: (allow-none): the #GtkCellArea to use to render cells in the menu, or %NULL.
1570 * @model: (allow-none): the #GtkTreeModel to build the menu heirarchy from, or %NULL.
1571 * @root: (allow-none): the #GtkTreePath indicating the root row for this menu, or %NULL.
1573 * Creates a new #GtkTreeMenu hierarchy from the provided @model and @root using @area to render it's cells.
1575 * Return value: A newly created #GtkTreeMenu.
1580 gtk_tree_menu_new_full (GtkCellArea *area,
1581 GtkTreeModel *model,
1584 return (GtkWidget *)g_object_new (GTK_TYPE_TREE_MENU,
1592 * gtk_tree_menu_set_model:
1593 * @menu: a #GtkTreeMenu
1594 * @model: (allow-none): the #GtkTreeModel to build the menu hierarchy from, or %NULL.
1596 * Sets @model to be used to build the menu heirarhcy.
1601 gtk_tree_menu_set_model (GtkTreeMenu *menu,
1602 GtkTreeModel *model)
1604 g_return_if_fail (GTK_IS_TREE_MENU (menu));
1605 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
1607 gtk_tree_menu_set_model_internal (menu, model);
1609 rebuild_menu (menu);
1613 * gtk_tree_menu_get_model:
1614 * @menu: a #GtkTreeMenu
1616 * Gets the @model currently used for the menu heirarhcy.
1618 * Return value: (transfer none): the #GtkTreeModel which is used
1619 * for @menu's hierarchy.
1624 gtk_tree_menu_get_model (GtkTreeMenu *menu)
1626 GtkTreeMenuPrivate *priv;
1628 g_return_val_if_fail (GTK_IS_TREE_MENU (menu), NULL);
1636 * gtk_tree_menu_set_root:
1637 * @menu: a #GtkTreeMenu
1638 * @path: (allow-none): the #GtkTreePath which is the root of @menu, or %NULL.
1640 * Sets the root of a @menu's hierarchy to be @path. @menu must already
1641 * have a model set and @path must point to a valid path inside the model.
1646 gtk_tree_menu_set_root (GtkTreeMenu *menu,
1649 GtkTreeMenuPrivate *priv;
1651 g_return_if_fail (GTK_IS_TREE_MENU (menu));
1652 g_return_if_fail (menu->priv->model != NULL || path == NULL);
1657 gtk_tree_row_reference_free (priv->root);
1660 priv->root = gtk_tree_row_reference_new (priv->model, path);
1664 rebuild_menu (menu);
1668 * gtk_tree_menu_get_root:
1669 * @menu: a #GtkTreeMenu
1671 * Gets the @root path for @menu's hierarchy, or returns %NULL if @menu
1672 * has no model or is building a heirarchy for the entire model. *
1674 * Return value: (transfer full) (allow-none): A newly created #GtkTreePath
1675 * pointing to the root of @menu which must be freed with gtk_tree_path_free().
1680 gtk_tree_menu_get_root (GtkTreeMenu *menu)
1682 GtkTreeMenuPrivate *priv;
1684 g_return_val_if_fail (GTK_IS_TREE_MENU (menu), NULL);
1689 return gtk_tree_row_reference_get_path (priv->root);
1695 * gtk_tree_menu_get_tearoff:
1696 * @menu: a #GtkTreeMenu
1698 * Gets whether this menu is build with a leading tearoff menu item.
1700 * Return value: %TRUE if the menu has a tearoff item.
1705 gtk_tree_menu_get_tearoff (GtkTreeMenu *menu)
1707 GtkTreeMenuPrivate *priv;
1709 g_return_val_if_fail (GTK_IS_TREE_MENU (menu), FALSE);
1713 return priv->tearoff;
1717 * gtk_tree_menu_set_tearoff:
1718 * @menu: a #GtkTreeMenu
1719 * @tearoff: whether the menu should have a leading tearoff menu item.
1721 * Sets whether this menu has a leading tearoff menu item.
1726 gtk_tree_menu_set_tearoff (GtkTreeMenu *menu,
1729 GtkTreeMenuPrivate *priv;
1731 g_return_if_fail (GTK_IS_TREE_MENU (menu));
1735 if (priv->tearoff != tearoff)
1737 priv->tearoff = tearoff;
1739 rebuild_menu (menu);
1741 g_object_notify (G_OBJECT (menu), "tearoff");
1746 * gtk_tree_menu_get_wrap_width:
1747 * @menu: a #GtkTreeMenu
1749 * Gets the wrap width which is used to determine the number of columns
1750 * for @menu. If the wrap width is larger than 1, @menu is in table mode.
1752 * Return value: the wrap width.
1757 gtk_tree_menu_get_wrap_width (GtkTreeMenu *menu)
1759 GtkTreeMenuPrivate *priv;
1761 g_return_val_if_fail (GTK_IS_TREE_MENU (menu), FALSE);
1765 return priv->wrap_width;
1769 * gtk_tree_menu_set_wrap_width:
1770 * @menu: a #GtkTreeMenu
1771 * @width: the wrap width
1773 * Sets the wrap width which is used to determine the number of columns
1774 * for @menu. If the wrap width is larger than 1, @menu is in table mode.
1779 gtk_tree_menu_set_wrap_width (GtkTreeMenu *menu,
1782 GtkTreeMenuPrivate *priv;
1784 g_return_if_fail (GTK_IS_TREE_MENU (menu));
1785 g_return_if_fail (width >= 0);
1789 if (priv->wrap_width != width)
1791 priv->wrap_width = width;
1793 rebuild_menu (menu);
1795 g_object_notify (G_OBJECT (menu), "wrap-width");
1800 * gtk_tree_menu_get_row_span_column:
1801 * @menu: a #GtkTreeMenu
1803 * Gets the column with row span information for @menu.
1804 * The row span column contains integers which indicate how many rows
1805 * a menu item should span.
1807 * Return value: the column in @menu's model containing row span information, or -1.
1812 gtk_tree_menu_get_row_span_column (GtkTreeMenu *menu)
1814 GtkTreeMenuPrivate *priv;
1816 g_return_val_if_fail (GTK_IS_TREE_MENU (menu), FALSE);
1820 return priv->row_span_col;
1824 * gtk_tree_menu_set_row_span_column:
1825 * @menu: a #GtkTreeMenu
1826 * @row_span: the column in the model to fetch the row span for a given menu item.
1828 * Sets the column with row span information for @menu to be @row_span.
1829 * The row span column contains integers which indicate how many rows
1830 * a menu item should span.
1835 gtk_tree_menu_set_row_span_column (GtkTreeMenu *menu,
1838 GtkTreeMenuPrivate *priv;
1840 g_return_if_fail (GTK_IS_TREE_MENU (menu));
1844 if (priv->row_span_col != row_span)
1846 priv->row_span_col = row_span;
1848 if (priv->wrap_width > 0)
1849 rebuild_menu (menu);
1851 g_object_notify (G_OBJECT (menu), "row-span-column");
1856 * gtk_tree_menu_get_column_span_column:
1857 * @menu: a #GtkTreeMenu
1859 * Gets the column with column span information for @menu.
1860 * The column span column contains integers which indicate how many columns
1861 * a menu item should span.
1863 * Return value: the column in @menu's model containing column span information, or -1.
1868 gtk_tree_menu_get_column_span_column (GtkTreeMenu *menu)
1870 GtkTreeMenuPrivate *priv;
1872 g_return_val_if_fail (GTK_IS_TREE_MENU (menu), FALSE);
1876 return priv->col_span_col;
1880 * gtk_tree_menu_set_column_span_column:
1881 * @menu: a #GtkTreeMenu
1882 * @column_span: the column in the model to fetch the column span for a given menu item.
1884 * Sets the column with column span information for @menu to be @column_span.
1885 * The column span column contains integers which indicate how many columns
1886 * a menu item should span.
1891 gtk_tree_menu_set_column_span_column (GtkTreeMenu *menu,
1894 GtkTreeMenuPrivate *priv;
1896 g_return_if_fail (GTK_IS_TREE_MENU (menu));
1900 if (priv->col_span_col != column_span)
1902 priv->col_span_col = column_span;
1904 if (priv->wrap_width > 0)
1905 rebuild_menu (menu);
1907 g_object_notify (G_OBJECT (menu), "column-span-column");
1912 * gtk_tree_menu_get_row_separator_func:
1913 * @menu: a #GtkTreeMenu
1915 * Gets the current #GtkTreeViewRowSeparatorFunc separator function.
1917 * Return value: the current row separator function.
1921 GtkTreeViewRowSeparatorFunc
1922 gtk_tree_menu_get_row_separator_func (GtkTreeMenu *menu)
1924 GtkTreeMenuPrivate *priv;
1926 g_return_val_if_fail (GTK_IS_TREE_MENU (menu), NULL);
1930 return priv->row_separator_func;
1934 * gtk_tree_menu_set_row_separator_func:
1935 * @menu: a #GtkTreeMenu
1936 * @func: (allow-none): a #GtkTreeViewRowSeparatorFunc, or %NULL to unset the separator function.
1937 * @data: (allow-none): user data to pass to @func, or %NULL
1938 * @destroy: (allow-none): destroy notifier for @data, or %NULL
1940 * Sets the row separator function, which is used to determine
1941 * whether a row should be drawn as a separator. If the row separator
1942 * function is %NULL, no separators are drawn. This is the default value.
1947 gtk_tree_menu_set_row_separator_func (GtkTreeMenu *menu,
1948 GtkTreeViewRowSeparatorFunc func,
1950 GDestroyNotify destroy)
1952 GtkTreeMenuPrivate *priv;
1954 g_return_if_fail (GTK_IS_TREE_MENU (menu));
1958 if (priv->row_separator_destroy)
1959 priv->row_separator_destroy (priv->row_separator_data);
1961 priv->row_separator_func = func;
1962 priv->row_separator_data = data;
1963 priv->row_separator_destroy = destroy;
1965 rebuild_menu (menu);
1969 * gtk_tree_menu_get_header_func:
1970 * @menu: a #GtkTreeMenu
1972 * Gets the current #GtkTreeMenuHeaderFunc header function.
1974 * Return value: the current header function.
1978 GtkTreeMenuHeaderFunc
1979 gtk_tree_menu_get_header_func (GtkTreeMenu *menu)
1981 GtkTreeMenuPrivate *priv;
1983 g_return_val_if_fail (GTK_IS_TREE_MENU (menu), NULL);
1987 return priv->header_func;
1991 * gtk_tree_menu_set_header_func:
1992 * @menu: a #GtkTreeMenu
1993 * @func: (allow-none): a #GtkTreeMenuHeaderFunc, or %NULL to unset the header function.
1994 * @data: (allow-none): user data to pass to @func, or %NULL
1995 * @destroy: (allow-none): destroy notifier for @data, or %NULL
1997 * Sets the header function, which is used to determine
1998 * whether a row width children should contain a leading header
1999 * menu item to allow that row to be selectable as an independant
2000 * menu item. If the header function is %NULL, no rows with children
2001 * have menu items which can be activated as leafs.
2002 * This is the default value.
2007 gtk_tree_menu_set_header_func (GtkTreeMenu *menu,
2008 GtkTreeMenuHeaderFunc func,
2010 GDestroyNotify destroy)
2012 GtkTreeMenuPrivate *priv;
2014 g_return_if_fail (GTK_IS_TREE_MENU (menu));
2018 if (priv->header_destroy)
2019 priv->header_destroy (priv->header_data);
2021 priv->header_func = func;
2022 priv->header_data = data;
2023 priv->header_destroy = destroy;
2025 rebuild_menu (menu);