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 && !priv->root)
739 /* If we are a submenu, compare the parent path */
742 GtkTreePath *root_path = gtk_tree_row_reference_get_path (priv->root);
743 GtkTreePath *search_path = gtk_tree_path_copy (path);
747 if (priv->menu_with_header &&
748 gtk_tree_path_compare (root_path, search_path) == 0)
753 else if (gtk_tree_path_get_depth (search_path) > 1)
755 gtk_tree_path_up (search_path);
757 if (gtk_tree_path_compare (root_path, search_path) == 0)
761 gtk_tree_path_free (root_path);
762 gtk_tree_path_free (search_path);
766 *header_item = is_header;
772 gtk_tree_menu_path_needs_submenu (GtkTreeMenu *menu,
775 GtkWidget *item = NULL;
777 GtkTreePath *parent_path;
779 if (gtk_tree_path_get_depth (search) <= 1)
782 parent_path = gtk_tree_path_copy (search);
783 gtk_tree_path_up (parent_path);
785 children = gtk_container_get_children (GTK_CONTAINER (menu));
787 for (l = children; item == NULL && l != NULL; l = l->next)
789 GtkWidget *child = l->data;
790 GtkTreePath *path = NULL;
792 /* Separators dont get submenus, if it already has a submenu then let
793 * the submenu handle inserted rows */
794 if (!GTK_IS_SEPARATOR_MENU_ITEM (child) &&
795 !gtk_menu_item_get_submenu (GTK_MENU_ITEM (child)))
797 GtkWidget *view = gtk_bin_get_child (GTK_BIN (child));
799 /* It's always a cellview */
800 if (GTK_IS_CELL_VIEW (view))
801 path = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (view));
806 if (gtk_tree_path_compare (parent_path, path) == 0)
809 gtk_tree_path_free (path);
813 g_list_free (children);
814 gtk_tree_path_free (parent_path);
820 find_empty_submenu (GtkTreeMenu *menu)
822 GtkTreeMenuPrivate *priv = menu->priv;
824 GtkWidget *submenu = NULL;
826 children = gtk_container_get_children (GTK_CONTAINER (menu));
828 for (l = children; submenu == NULL && l != NULL; l = l->next)
830 GtkWidget *child = l->data;
831 GtkTreePath *path = NULL;
834 /* Separators dont get submenus, if it already has a submenu then let
835 * the submenu handle inserted rows */
836 if (!GTK_IS_SEPARATOR_MENU_ITEM (child) && !GTK_IS_TEAROFF_MENU_ITEM (child))
838 GtkWidget *view = gtk_bin_get_child (GTK_BIN (child));
840 /* It's always a cellview */
841 if (GTK_IS_CELL_VIEW (view))
842 path = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (view));
847 if (gtk_tree_model_get_iter (priv->model, &iter, path) &&
848 !gtk_tree_model_iter_has_child (priv->model, &iter))
849 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (child));
851 gtk_tree_path_free (path);
855 g_list_free (children);
861 row_inserted_cb (GtkTreeModel *model,
866 GtkTreeMenuPrivate *priv = menu->priv;
867 gint *indices, index, depth;
870 /* If the iter should be in this menu then go ahead and insert it */
871 if (gtk_tree_menu_path_in_menu (menu, path, NULL))
873 if (priv->wrap_width > 0)
877 /* Get the index of the path for this depth */
878 indices = gtk_tree_path_get_indices (path);
879 depth = gtk_tree_path_get_depth (path);
880 index = indices[depth -1];
882 /* Menus with a header include a menuitem for it's root node
883 * and a separator menu item */
884 if (priv->menu_with_header)
887 /* Index after the tearoff item for the root menu if
888 * there is a tearoff item
890 if (priv->root == NULL && priv->tearoff)
893 item = gtk_tree_menu_create_item (menu, iter, FALSE);
894 gtk_menu_shell_insert (GTK_MENU_SHELL (menu), item, index);
896 /* Resize everything */
897 gtk_cell_area_context_reset (menu->priv->context);
902 /* Create submenus for iters if we need to */
903 item = gtk_tree_menu_path_needs_submenu (menu, path);
906 GtkTreePath *item_path = gtk_tree_path_copy (path);
908 gtk_tree_path_up (item_path);
909 gtk_tree_menu_create_submenu (menu, item, item_path);
910 gtk_tree_path_free (item_path);
916 row_deleted_cb (GtkTreeModel *model,
920 GtkTreeMenuPrivate *priv = menu->priv;
923 /* If it's the header item we leave it to the parent menu
924 * to remove us from its menu
926 item = gtk_tree_menu_get_path_item (menu, path);
930 if (priv->wrap_width > 0)
934 /* Get rid of the deleted item */
935 gtk_widget_destroy (item);
937 /* Resize everything */
938 gtk_cell_area_context_reset (menu->priv->context);
943 /* It's up to the parent menu to destroy a child menu that becomes empty
944 * since the topmost menu belongs to the user and is allowed to have no contents */
945 GtkWidget *submenu = find_empty_submenu (menu);
947 gtk_widget_destroy (submenu);
952 row_reordered_cb (GtkTreeModel *model,
958 GtkTreeMenuPrivate *priv = menu->priv;
959 gboolean this_menu = FALSE;
961 if (path == NULL && priv->root == NULL)
965 GtkTreePath *root_path =
966 gtk_tree_row_reference_get_path (priv->root);
968 if (gtk_tree_path_compare (root_path, path) == 0)
971 gtk_tree_path_free (root_path);
979 menu_item_position (GtkTreeMenu *menu,
985 children = gtk_container_get_children (GTK_CONTAINER (menu));
986 for (position = 0, l = children; l; position++, l = l->next)
988 GtkWidget *iitem = l->data;
994 g_list_free (children);
1000 row_changed_cb (GtkTreeModel *model,
1005 GtkTreeMenuPrivate *priv = menu->priv;
1006 gboolean is_separator = FALSE;
1007 gboolean has_header = FALSE;
1010 item = gtk_tree_menu_get_path_item (menu, path);
1014 GtkTreePath *root_path =
1015 gtk_tree_row_reference_get_path (priv->root);
1017 if (root_path && gtk_tree_path_compare (root_path, path) == 0)
1019 if (priv->header_func)
1021 priv->header_func (priv->model, iter, priv->header_data);
1023 if (has_header && !item)
1025 item = gtk_separator_menu_item_new ();
1026 gtk_widget_show (item);
1027 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
1029 item = gtk_tree_menu_create_item (menu, iter, TRUE);
1030 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
1032 priv->menu_with_header = TRUE;
1034 else if (!has_header && item)
1036 /* Destroy the header item and then the following separator */
1037 gtk_widget_destroy (item);
1038 gtk_widget_destroy (GTK_MENU_SHELL (menu)->children->data);
1040 priv->menu_with_header = FALSE;
1043 gtk_tree_path_free (root_path);
1049 if (priv->wrap_width > 0)
1050 /* Ugly, we need to rebuild the menu here if
1051 * the row-span/row-column values change
1053 rebuild_menu (menu);
1056 if (priv->row_separator_func)
1058 priv->row_separator_func (model, iter,
1059 priv->row_separator_data);
1062 if (is_separator != GTK_IS_SEPARATOR_MENU_ITEM (item))
1064 gint position = menu_item_position (menu, item);
1066 gtk_widget_destroy (item);
1067 item = gtk_tree_menu_create_item (menu, iter, FALSE);
1068 gtk_menu_shell_insert (GTK_MENU_SHELL (menu), item, position);
1075 context_size_changed_cb (GtkCellAreaContext *context,
1079 if (!strcmp (pspec->name, "minimum-width") ||
1080 !strcmp (pspec->name, "natural-width") ||
1081 !strcmp (pspec->name, "minimum-height") ||
1082 !strcmp (pspec->name, "natural-height"))
1083 gtk_widget_queue_resize (menu);
1087 area_is_sensitive (GtkCellArea *area)
1089 GList *cells, *list;
1090 gboolean sensitive = FALSE;
1092 cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (area));
1094 for (list = cells; list; list = list->next)
1096 g_object_get (list->data, "sensitive", &sensitive, NULL);
1101 g_list_free (cells);
1107 area_apply_attributes_cb (GtkCellArea *area,
1108 GtkTreeModel *tree_model,
1110 gboolean is_expander,
1111 gboolean is_expanded,
1114 /* If the menu for this iter has a submenu */
1115 GtkTreeMenuPrivate *priv = menu->priv;
1121 path = gtk_tree_model_get_path (tree_model, iter);
1123 if (gtk_tree_menu_path_in_menu (menu, path, &is_header))
1125 item = gtk_tree_menu_get_path_item (menu, path);
1127 /* If there is no submenu, go ahead and update item sensitivity,
1128 * items with submenus are always sensitive */
1129 if (item && !gtk_menu_item_get_submenu (GTK_MENU_ITEM (item)))
1131 sensitive = area_is_sensitive (priv->area);
1133 gtk_widget_set_sensitive (item, sensitive);
1137 /* For header items we need to set the sensitivity
1138 * of the following separator item
1140 if (GTK_MENU_SHELL (menu)->children &&
1141 GTK_MENU_SHELL (menu)->children->next)
1143 GtkWidget *separator =
1144 GTK_MENU_SHELL (menu)->children->next->data;
1146 gtk_widget_set_sensitive (separator, sensitive);
1152 gtk_tree_path_free (path);
1156 gtk_tree_menu_set_area (GtkTreeMenu *menu,
1159 GtkTreeMenuPrivate *priv = menu->priv;
1163 g_signal_handler_disconnect (priv->area,
1164 priv->apply_attributes_id);
1165 priv->apply_attributes_id = 0;
1167 g_object_unref (priv->area);
1174 g_object_ref_sink (priv->area);
1176 priv->apply_attributes_id =
1177 g_signal_connect (priv->area, "apply-attributes",
1178 G_CALLBACK (area_apply_attributes_cb), menu);
1183 menu_occupied (GtkTreeMenu *menu,
1187 guint bottom_attach)
1191 for (i = GTK_MENU_SHELL (menu)->children; i; i = i->next)
1195 gtk_container_child_get (GTK_CONTAINER (menu),
1199 "bottom-attach", &b,
1203 /* look if this item intersects with the given coordinates */
1204 if (right_attach > l && left_attach < r && bottom_attach > t && top_attach < b)
1212 relayout_item (GtkTreeMenu *menu,
1217 GtkTreeMenuPrivate *priv = menu->priv;
1218 gint current_col = 0, current_row = 0;
1219 gint rows = 1, cols = 1;
1221 if (priv->col_span_col == -1 &&
1222 priv->row_span_col == -1 &&
1225 gtk_container_child_get (GTK_CONTAINER (menu), prev,
1226 "right-attach", ¤t_col,
1227 "top-attach", ¤t_row,
1229 if (current_col + cols > priv->wrap_width)
1237 if (priv->col_span_col != -1)
1238 gtk_tree_model_get (priv->model, iter,
1239 priv->col_span_col, &cols,
1241 if (priv->row_span_col != -1)
1242 gtk_tree_model_get (priv->model, iter,
1243 priv->row_span_col, &rows,
1248 if (current_col + cols > priv->wrap_width)
1254 if (!menu_occupied (menu,
1255 current_col, current_col + cols,
1256 current_row, current_row + rows))
1263 /* set attach props */
1264 gtk_menu_attach (GTK_MENU (menu), item,
1265 current_col, current_col + cols,
1266 current_row, current_row + rows);
1270 gtk_tree_menu_create_submenu (GtkTreeMenu *menu,
1274 GtkTreeMenuPrivate *priv = menu->priv;
1278 view = gtk_bin_get_child (GTK_BIN (item));
1279 gtk_cell_view_set_draw_sensitive (GTK_CELL_VIEW (view), TRUE);
1281 submenu = gtk_tree_menu_new_with_area (priv->area);
1283 gtk_tree_menu_set_row_separator_func (GTK_TREE_MENU (submenu),
1284 priv->row_separator_func,
1285 priv->row_separator_data,
1286 priv->row_separator_destroy);
1287 gtk_tree_menu_set_header_func (GTK_TREE_MENU (submenu),
1290 priv->header_destroy);
1292 gtk_tree_menu_set_wrap_width (GTK_TREE_MENU (submenu), priv->wrap_width);
1293 gtk_tree_menu_set_row_span_column (GTK_TREE_MENU (submenu), priv->row_span_col);
1294 gtk_tree_menu_set_column_span_column (GTK_TREE_MENU (submenu), priv->col_span_col);
1296 gtk_tree_menu_set_model_internal (GTK_TREE_MENU (submenu), priv->model);
1297 gtk_tree_menu_set_root (GTK_TREE_MENU (submenu), path);
1298 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
1300 g_signal_connect (submenu, "menu-activate",
1301 G_CALLBACK (submenu_activated_cb), menu);
1305 gtk_tree_menu_create_item (GtkTreeMenu *menu,
1307 gboolean header_item)
1309 GtkTreeMenuPrivate *priv = menu->priv;
1310 GtkWidget *item, *view;
1312 gboolean is_separator = FALSE;
1314 path = gtk_tree_model_get_path (priv->model, iter);
1316 if (priv->row_separator_func)
1318 priv->row_separator_func (priv->model, iter,
1319 priv->row_separator_data);
1323 item = gtk_separator_menu_item_new ();
1324 gtk_widget_show (item);
1326 g_object_set_qdata_full (G_OBJECT (item),
1327 tree_menu_path_quark,
1328 gtk_tree_row_reference_new (priv->model, path),
1329 (GDestroyNotify)gtk_tree_row_reference_free);
1333 view = gtk_cell_view_new_with_context (priv->area, priv->context);
1334 item = gtk_menu_item_new ();
1335 gtk_widget_show (view);
1336 gtk_widget_show (item);
1338 gtk_cell_view_set_model (GTK_CELL_VIEW (view), priv->model);
1339 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (view), path);
1341 gtk_widget_show (view);
1342 gtk_container_add (GTK_CONTAINER (item), view);
1344 g_signal_connect (item, "activate", G_CALLBACK (item_activated_cb), menu);
1346 /* Add a GtkTreeMenu submenu to render the children of this row */
1347 if (header_item == FALSE &&
1348 gtk_tree_model_iter_has_child (priv->model, iter))
1349 gtk_tree_menu_create_submenu (menu, item, path);
1352 gtk_tree_path_free (path);
1358 rebuild_menu (GtkTreeMenu *menu)
1360 GtkTreeMenuPrivate *priv = menu->priv;
1362 /* Destroy all the menu items */
1363 gtk_container_foreach (GTK_CONTAINER (menu),
1364 (GtkCallback) gtk_widget_destroy, NULL);
1368 gtk_tree_menu_populate (menu);
1373 gtk_tree_menu_populate (GtkTreeMenu *menu)
1375 GtkTreeMenuPrivate *priv = menu->priv;
1376 GtkTreePath *path = NULL;
1379 gboolean valid = FALSE;
1380 GtkWidget *menu_item, *prev = NULL;
1386 path = gtk_tree_row_reference_get_path (priv->root);
1390 if (gtk_tree_model_get_iter (priv->model, &parent, path))
1392 valid = gtk_tree_model_iter_children (priv->model, &iter, &parent);
1394 if (priv->header_func &&
1395 priv->header_func (priv->model, &parent, priv->header_data))
1397 /* Add a submenu header for rows which desire one, used for
1398 * combo boxes to allow all rows to be activatable/selectable
1400 menu_item = gtk_tree_menu_create_item (menu, &parent, TRUE);
1401 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
1403 menu_item = gtk_separator_menu_item_new ();
1404 gtk_widget_show (menu_item);
1405 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
1408 priv->menu_with_header = TRUE;
1411 gtk_tree_path_free (path);
1415 /* Tearoff menu items only go in the root menu */
1418 menu_item = gtk_tearoff_menu_item_new ();
1419 gtk_widget_show (menu_item);
1421 if (priv->wrap_width > 0)
1422 gtk_menu_attach (GTK_MENU (menu), menu_item, 0, priv->wrap_width, 0, 1);
1424 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
1429 valid = gtk_tree_model_iter_children (priv->model, &iter, NULL);
1432 /* Create a menu item for every row at the current depth, add a GtkTreeMenu
1433 * submenu for iters/items that have children */
1436 menu_item = gtk_tree_menu_create_item (menu, &iter, FALSE);
1438 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
1440 if (priv->wrap_width > 0)
1441 relayout_item (menu, menu_item, &iter, prev);
1444 valid = gtk_tree_model_iter_next (priv->model, &iter);
1449 item_activated_cb (GtkMenuItem *item,
1456 /* Only activate leafs, not parents */
1457 if (!gtk_menu_item_get_submenu (item))
1459 view = GTK_CELL_VIEW (gtk_bin_get_child (GTK_BIN (item)));
1460 path = gtk_cell_view_get_displayed_row (view);
1461 path_str = gtk_tree_path_to_string (path);
1463 g_signal_emit (menu, tree_menu_signals[SIGNAL_MENU_ACTIVATE], 0, path_str);
1466 gtk_tree_path_free (path);
1471 submenu_activated_cb (GtkTreeMenu *submenu,
1475 g_signal_emit (menu, tree_menu_signals[SIGNAL_MENU_ACTIVATE], 0, path);
1478 /* Sets the model without rebuilding the menu, prevents
1479 * infinite recursion while building submenus (we wait
1480 * until the root is set and then build the menu) */
1482 gtk_tree_menu_set_model_internal (GtkTreeMenu *menu,
1483 GtkTreeModel *model)
1485 GtkTreeMenuPrivate *priv;
1489 if (priv->model != model)
1493 /* Disconnect signals */
1494 g_signal_handler_disconnect (priv->model,
1495 priv->row_inserted_id);
1496 g_signal_handler_disconnect (priv->model,
1497 priv->row_deleted_id);
1498 g_signal_handler_disconnect (priv->model,
1499 priv->row_reordered_id);
1500 g_signal_handler_disconnect (priv->model,
1501 priv->row_changed_id);
1502 priv->row_inserted_id = 0;
1503 priv->row_deleted_id = 0;
1504 priv->row_reordered_id = 0;
1505 priv->row_changed_id = 0;
1507 g_object_unref (priv->model);
1510 priv->model = model;
1514 g_object_ref (priv->model);
1516 /* Connect signals */
1517 priv->row_inserted_id = g_signal_connect (priv->model, "row-inserted",
1518 G_CALLBACK (row_inserted_cb), menu);
1519 priv->row_deleted_id = g_signal_connect (priv->model, "row-deleted",
1520 G_CALLBACK (row_deleted_cb), menu);
1521 priv->row_reordered_id = g_signal_connect (priv->model, "rows-reordered",
1522 G_CALLBACK (row_reordered_cb), menu);
1523 priv->row_changed_id = g_signal_connect (priv->model, "row-changed",
1524 G_CALLBACK (row_changed_cb), menu);
1529 /****************************************************************
1531 ****************************************************************/
1534 * gtk_tree_menu_new:
1536 * Creates a new #GtkTreeMenu.
1538 * Return value: A newly created #GtkTreeMenu with no model or root.
1543 gtk_tree_menu_new (void)
1545 return (GtkWidget *)g_object_new (GTK_TYPE_TREE_MENU, NULL);
1549 * gtk_tree_menu_new_with_area:
1550 * @area: the #GtkCellArea to use to render cells in the menu
1552 * Creates a new #GtkTreeMenu using @area to render it's cells.
1554 * Return value: A newly created #GtkTreeMenu with no model or root.
1559 gtk_tree_menu_new_with_area (GtkCellArea *area)
1561 return (GtkWidget *)g_object_new (GTK_TYPE_TREE_MENU,
1567 * gtk_tree_menu_new_full:
1568 * @area: (allow-none): the #GtkCellArea to use to render cells in the menu, or %NULL.
1569 * @model: (allow-none): the #GtkTreeModel to build the menu heirarchy from, or %NULL.
1570 * @root: (allow-none): the #GtkTreePath indicating the root row for this menu, or %NULL.
1572 * Creates a new #GtkTreeMenu hierarchy from the provided @model and @root using @area to render it's cells.
1574 * Return value: A newly created #GtkTreeMenu.
1579 gtk_tree_menu_new_full (GtkCellArea *area,
1580 GtkTreeModel *model,
1583 return (GtkWidget *)g_object_new (GTK_TYPE_TREE_MENU,
1591 * gtk_tree_menu_set_model:
1592 * @menu: a #GtkTreeMenu
1593 * @model: (allow-none): the #GtkTreeModel to build the menu hierarchy from, or %NULL.
1595 * Sets @model to be used to build the menu heirarhcy.
1600 gtk_tree_menu_set_model (GtkTreeMenu *menu,
1601 GtkTreeModel *model)
1603 g_return_if_fail (GTK_IS_TREE_MENU (menu));
1604 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
1606 gtk_tree_menu_set_model_internal (menu, model);
1608 rebuild_menu (menu);
1612 * gtk_tree_menu_get_model:
1613 * @menu: a #GtkTreeMenu
1615 * Gets the @model currently used for the menu heirarhcy.
1617 * Return value: (transfer none): the #GtkTreeModel which is used
1618 * for @menu's hierarchy.
1623 gtk_tree_menu_get_model (GtkTreeMenu *menu)
1625 GtkTreeMenuPrivate *priv;
1627 g_return_val_if_fail (GTK_IS_TREE_MENU (menu), NULL);
1635 * gtk_tree_menu_set_root:
1636 * @menu: a #GtkTreeMenu
1637 * @path: (allow-none): the #GtkTreePath which is the root of @menu, or %NULL.
1639 * Sets the root of a @menu's hierarchy to be @path. @menu must already
1640 * have a model set and @path must point to a valid path inside the model.
1645 gtk_tree_menu_set_root (GtkTreeMenu *menu,
1648 GtkTreeMenuPrivate *priv;
1650 g_return_if_fail (GTK_IS_TREE_MENU (menu));
1651 g_return_if_fail (menu->priv->model != NULL || path == NULL);
1656 gtk_tree_row_reference_free (priv->root);
1659 priv->root = gtk_tree_row_reference_new (priv->model, path);
1663 rebuild_menu (menu);
1667 * gtk_tree_menu_get_root:
1668 * @menu: a #GtkTreeMenu
1670 * Gets the @root path for @menu's hierarchy, or returns %NULL if @menu
1671 * has no model or is building a heirarchy for the entire model. *
1673 * Return value: (transfer full) (allow-none): A newly created #GtkTreePath
1674 * pointing to the root of @menu which must be freed with gtk_tree_path_free().
1679 gtk_tree_menu_get_root (GtkTreeMenu *menu)
1681 GtkTreeMenuPrivate *priv;
1683 g_return_val_if_fail (GTK_IS_TREE_MENU (menu), NULL);
1688 return gtk_tree_row_reference_get_path (priv->root);
1694 * gtk_tree_menu_get_tearoff:
1695 * @menu: a #GtkTreeMenu
1697 * Gets whether this menu is build with a leading tearoff menu item.
1699 * Return value: %TRUE if the menu has a tearoff item.
1704 gtk_tree_menu_get_tearoff (GtkTreeMenu *menu)
1706 GtkTreeMenuPrivate *priv;
1708 g_return_val_if_fail (GTK_IS_TREE_MENU (menu), FALSE);
1712 return priv->tearoff;
1716 * gtk_tree_menu_set_tearoff:
1717 * @menu: a #GtkTreeMenu
1718 * @tearoff: whether the menu should have a leading tearoff menu item.
1720 * Sets whether this menu has a leading tearoff menu item.
1725 gtk_tree_menu_set_tearoff (GtkTreeMenu *menu,
1728 GtkTreeMenuPrivate *priv;
1730 g_return_if_fail (GTK_IS_TREE_MENU (menu));
1734 if (priv->tearoff != tearoff)
1736 priv->tearoff = tearoff;
1738 rebuild_menu (menu);
1740 g_object_notify (G_OBJECT (menu), "tearoff");
1745 * gtk_tree_menu_get_wrap_width:
1746 * @menu: a #GtkTreeMenu
1748 * Gets the wrap width which is used to determine the number of columns
1749 * for @menu. If the wrap width is larger than 1, @menu is in table mode.
1751 * Return value: the wrap width.
1756 gtk_tree_menu_get_wrap_width (GtkTreeMenu *menu)
1758 GtkTreeMenuPrivate *priv;
1760 g_return_val_if_fail (GTK_IS_TREE_MENU (menu), FALSE);
1764 return priv->wrap_width;
1768 * gtk_tree_menu_set_wrap_width:
1769 * @menu: a #GtkTreeMenu
1770 * @width: the wrap width
1772 * Sets the wrap width which is used to determine the number of columns
1773 * for @menu. If the wrap width is larger than 1, @menu is in table mode.
1778 gtk_tree_menu_set_wrap_width (GtkTreeMenu *menu,
1781 GtkTreeMenuPrivate *priv;
1783 g_return_if_fail (GTK_IS_TREE_MENU (menu));
1784 g_return_if_fail (width >= 0);
1788 if (priv->wrap_width != width)
1790 priv->wrap_width = width;
1792 rebuild_menu (menu);
1794 g_object_notify (G_OBJECT (menu), "wrap-width");
1799 * gtk_tree_menu_get_row_span_column:
1800 * @menu: a #GtkTreeMenu
1802 * Gets the column with row span information for @menu.
1803 * The row span column contains integers which indicate how many rows
1804 * a menu item should span.
1806 * Return value: the column in @menu's model containing row span information, or -1.
1811 gtk_tree_menu_get_row_span_column (GtkTreeMenu *menu)
1813 GtkTreeMenuPrivate *priv;
1815 g_return_val_if_fail (GTK_IS_TREE_MENU (menu), FALSE);
1819 return priv->row_span_col;
1823 * gtk_tree_menu_set_row_span_column:
1824 * @menu: a #GtkTreeMenu
1825 * @row_span: the column in the model to fetch the row span for a given menu item.
1827 * Sets the column with row span information for @menu to be @row_span.
1828 * The row span column contains integers which indicate how many rows
1829 * a menu item should span.
1834 gtk_tree_menu_set_row_span_column (GtkTreeMenu *menu,
1837 GtkTreeMenuPrivate *priv;
1839 g_return_if_fail (GTK_IS_TREE_MENU (menu));
1843 if (priv->row_span_col != row_span)
1845 priv->row_span_col = row_span;
1847 if (priv->wrap_width > 0)
1848 rebuild_menu (menu);
1850 g_object_notify (G_OBJECT (menu), "row-span-column");
1855 * gtk_tree_menu_get_column_span_column:
1856 * @menu: a #GtkTreeMenu
1858 * Gets the column with column span information for @menu.
1859 * The column span column contains integers which indicate how many columns
1860 * a menu item should span.
1862 * Return value: the column in @menu's model containing column span information, or -1.
1867 gtk_tree_menu_get_column_span_column (GtkTreeMenu *menu)
1869 GtkTreeMenuPrivate *priv;
1871 g_return_val_if_fail (GTK_IS_TREE_MENU (menu), FALSE);
1875 return priv->col_span_col;
1879 * gtk_tree_menu_set_column_span_column:
1880 * @menu: a #GtkTreeMenu
1881 * @column_span: the column in the model to fetch the column span for a given menu item.
1883 * Sets the column with column span information for @menu to be @column_span.
1884 * The column span column contains integers which indicate how many columns
1885 * a menu item should span.
1890 gtk_tree_menu_set_column_span_column (GtkTreeMenu *menu,
1893 GtkTreeMenuPrivate *priv;
1895 g_return_if_fail (GTK_IS_TREE_MENU (menu));
1899 if (priv->col_span_col != column_span)
1901 priv->col_span_col = column_span;
1903 if (priv->wrap_width > 0)
1904 rebuild_menu (menu);
1906 g_object_notify (G_OBJECT (menu), "column-span-column");
1911 * gtk_tree_menu_get_row_separator_func:
1912 * @menu: a #GtkTreeMenu
1914 * Gets the current #GtkTreeViewRowSeparatorFunc separator function.
1916 * Return value: the current row separator function.
1920 GtkTreeViewRowSeparatorFunc
1921 gtk_tree_menu_get_row_separator_func (GtkTreeMenu *menu)
1923 GtkTreeMenuPrivate *priv;
1925 g_return_val_if_fail (GTK_IS_TREE_MENU (menu), NULL);
1929 return priv->row_separator_func;
1933 * gtk_tree_menu_set_row_separator_func:
1934 * @menu: a #GtkTreeMenu
1935 * @func: (allow-none): a #GtkTreeViewRowSeparatorFunc, or %NULL to unset the separator function.
1936 * @data: (allow-none): user data to pass to @func, or %NULL
1937 * @destroy: (allow-none): destroy notifier for @data, or %NULL
1939 * Sets the row separator function, which is used to determine
1940 * whether a row should be drawn as a separator. If the row separator
1941 * function is %NULL, no separators are drawn. This is the default value.
1946 gtk_tree_menu_set_row_separator_func (GtkTreeMenu *menu,
1947 GtkTreeViewRowSeparatorFunc func,
1949 GDestroyNotify destroy)
1951 GtkTreeMenuPrivate *priv;
1953 g_return_if_fail (GTK_IS_TREE_MENU (menu));
1957 if (priv->row_separator_destroy)
1958 priv->row_separator_destroy (priv->row_separator_data);
1960 priv->row_separator_func = func;
1961 priv->row_separator_data = data;
1962 priv->row_separator_destroy = destroy;
1964 rebuild_menu (menu);
1968 * gtk_tree_menu_get_header_func:
1969 * @menu: a #GtkTreeMenu
1971 * Gets the current #GtkTreeMenuHeaderFunc header function.
1973 * Return value: the current header function.
1977 GtkTreeMenuHeaderFunc
1978 gtk_tree_menu_get_header_func (GtkTreeMenu *menu)
1980 GtkTreeMenuPrivate *priv;
1982 g_return_val_if_fail (GTK_IS_TREE_MENU (menu), NULL);
1986 return priv->header_func;
1990 * gtk_tree_menu_set_header_func:
1991 * @menu: a #GtkTreeMenu
1992 * @func: (allow-none): a #GtkTreeMenuHeaderFunc, or %NULL to unset the header function.
1993 * @data: (allow-none): user data to pass to @func, or %NULL
1994 * @destroy: (allow-none): destroy notifier for @data, or %NULL
1996 * Sets the header function, which is used to determine
1997 * whether a row width children should contain a leading header
1998 * menu item to allow that row to be selectable as an independant
1999 * menu item. If the header function is %NULL, no rows with children
2000 * have menu items which can be activated as leafs.
2001 * This is the default value.
2006 gtk_tree_menu_set_header_func (GtkTreeMenu *menu,
2007 GtkTreeMenuHeaderFunc func,
2009 GDestroyNotify destroy)
2011 GtkTreeMenuPrivate *priv;
2013 g_return_if_fail (GTK_IS_TREE_MENU (menu));
2017 if (priv->header_destroy)
2018 priv->header_destroy (priv->header_data);
2020 priv->header_func = func;
2021 priv->header_data = data;
2022 priv->header_destroy = destroy;
2024 rebuild_menu (menu);