3 * Copyright (C) 2010 Openismus GmbH
6 * Tristan Van Berkom <tristanvb@openismus.com>
8 * Based on some GtkComboBox menu code by Kristian Rietveld <kris@gtk.org>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Library General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Library General Public License for more details.
20 * You should have received a copy of the GNU Library General Public
21 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
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 "gtkseparatormenuitem.h"
40 #include "gtkcellareabox.h"
41 #include "gtkcellareacontext.h"
42 #include "gtkcelllayout.h"
43 #include "gtkcellview.h"
44 #include "gtkmenushellprivate.h"
45 #include "gtkprivate.h"
47 #include "deprecated/gtktearoffmenuitem.h"
50 static GObject *gtk_tree_menu_constructor (GType type,
51 guint n_construct_properties,
52 GObjectConstructParam *construct_properties);
53 static void gtk_tree_menu_dispose (GObject *object);
54 static void gtk_tree_menu_finalize (GObject *object);
55 static void gtk_tree_menu_set_property (GObject *object,
59 static void gtk_tree_menu_get_property (GObject *object,
65 static void gtk_tree_menu_get_preferred_width (GtkWidget *widget,
68 static void gtk_tree_menu_get_preferred_height (GtkWidget *widget,
72 /* GtkCellLayoutIface */
73 static void gtk_tree_menu_cell_layout_init (GtkCellLayoutIface *iface);
74 static GtkCellArea *gtk_tree_menu_cell_layout_get_area (GtkCellLayout *layout);
77 /* TreeModel/DrawingArea callbacks and building menus/submenus */
78 static inline void rebuild_menu (GtkTreeMenu *menu);
79 static gboolean menu_occupied (GtkTreeMenu *menu,
84 static void relayout_item (GtkTreeMenu *menu,
88 static void gtk_tree_menu_populate (GtkTreeMenu *menu);
89 static GtkWidget *gtk_tree_menu_create_item (GtkTreeMenu *menu,
91 gboolean header_item);
92 static void gtk_tree_menu_create_submenu (GtkTreeMenu *menu,
95 static void gtk_tree_menu_set_area (GtkTreeMenu *menu,
97 static GtkWidget *gtk_tree_menu_get_path_item (GtkTreeMenu *menu,
99 static gboolean gtk_tree_menu_path_in_menu (GtkTreeMenu *menu,
101 gboolean *header_item);
102 static void row_inserted_cb (GtkTreeModel *model,
106 static void row_deleted_cb (GtkTreeModel *model,
109 static void row_reordered_cb (GtkTreeModel *model,
114 static void row_changed_cb (GtkTreeModel *model,
118 static void context_size_changed_cb (GtkCellAreaContext *context,
121 static void area_apply_attributes_cb (GtkCellArea *area,
122 GtkTreeModel *tree_model,
124 gboolean is_expander,
125 gboolean is_expanded,
127 static void item_activated_cb (GtkMenuItem *item,
129 static void submenu_activated_cb (GtkTreeMenu *submenu,
132 static void gtk_tree_menu_set_model_internal (GtkTreeMenu *menu,
133 GtkTreeModel *model);
137 struct _GtkTreeMenuPrivate
139 /* TreeModel and parent for this menu */
141 GtkTreeRowReference *root;
143 /* CellArea and context for this menu */
145 GtkCellAreaContext *context;
148 gulong size_changed_id;
149 gulong apply_attributes_id;
150 gulong row_inserted_id;
151 gulong row_deleted_id;
152 gulong row_reordered_id;
153 gulong row_changed_id;
161 guint32 menu_with_header : 1;
165 GtkTreeViewRowSeparatorFunc row_separator_func;
166 gpointer row_separator_data;
167 GDestroyNotify row_separator_destroy;
169 /* Submenu headers */
170 GtkTreeMenuHeaderFunc header_func;
171 gpointer header_data;
172 GDestroyNotify header_destroy;
187 SIGNAL_MENU_ACTIVATE,
191 static guint tree_menu_signals[N_SIGNALS] = { 0 };
192 static GQuark tree_menu_path_quark = 0;
194 G_DEFINE_TYPE_WITH_CODE (GtkTreeMenu, _gtk_tree_menu, GTK_TYPE_MENU,
195 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
196 gtk_tree_menu_cell_layout_init));
199 _gtk_tree_menu_init (GtkTreeMenu *menu)
201 GtkTreeMenuPrivate *priv;
203 menu->priv = G_TYPE_INSTANCE_GET_PRIVATE (menu,
211 priv->context = NULL;
213 priv->size_changed_id = 0;
214 priv->row_inserted_id = 0;
215 priv->row_deleted_id = 0;
216 priv->row_reordered_id = 0;
217 priv->row_changed_id = 0;
219 priv->wrap_width = 0;
220 priv->row_span_col = -1;
221 priv->col_span_col = -1;
223 priv->menu_with_header = FALSE;
224 priv->tearoff = FALSE;
226 priv->row_separator_func = NULL;
227 priv->row_separator_data = NULL;
228 priv->row_separator_destroy = NULL;
230 priv->header_func = NULL;
231 priv->header_data = NULL;
232 priv->header_destroy = NULL;
234 gtk_menu_set_reserve_toggle_size (GTK_MENU (menu), FALSE);
238 _gtk_tree_menu_class_init (GtkTreeMenuClass *class)
240 GObjectClass *object_class = G_OBJECT_CLASS (class);
241 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
243 tree_menu_path_quark = g_quark_from_static_string ("gtk-tree-menu-path");
245 object_class->constructor = gtk_tree_menu_constructor;
246 object_class->dispose = gtk_tree_menu_dispose;
247 object_class->finalize = gtk_tree_menu_finalize;
248 object_class->set_property = gtk_tree_menu_set_property;
249 object_class->get_property = gtk_tree_menu_get_property;
251 widget_class->get_preferred_width = gtk_tree_menu_get_preferred_width;
252 widget_class->get_preferred_height = gtk_tree_menu_get_preferred_height;
255 * GtkTreeMenu::menu-activate:
256 * @menu: a #GtkTreeMenu
257 * @path: the #GtkTreePath string for the item which was activated
258 * @user_data: the user data
260 * This signal is emitted to notify that a menu item in the #GtkTreeMenu
261 * was activated and provides the path string from the #GtkTreeModel
262 * to specify which row was selected.
266 tree_menu_signals[SIGNAL_MENU_ACTIVATE] =
267 g_signal_new (I_("menu-activate"),
268 G_OBJECT_CLASS_TYPE (object_class),
270 0, /* No class closure here */
272 _gtk_marshal_VOID__STRING,
273 G_TYPE_NONE, 1, G_TYPE_STRING);
278 * The #GtkTreeModel from which the menu is constructed.
282 g_object_class_install_property (object_class,
284 g_param_spec_object ("model",
285 P_("TreeMenu model"),
286 P_("The model for the tree menu"),
288 GTK_PARAM_READWRITE));
293 * The #GtkTreePath that is the root for this menu, or %NULL.
295 * The #GtkTreeMenu recursively creates submenus for #GtkTreeModel
296 * rows that have children and the "root" for each menu is provided
297 * by the parent menu.
299 * If you dont provide a root for the #GtkTreeMenu then the whole
300 * model will be added to the menu. Specifying a root allows you
301 * to build a menu for a given #GtkTreePath and its children.
305 g_object_class_install_property (object_class,
307 g_param_spec_boxed ("root",
308 P_("TreeMenu root row"),
309 P_("The TreeMenu will display children of the "
312 GTK_PARAM_READWRITE));
315 * GtkTreeMenu:cell-area:
317 * The #GtkCellArea used to render cells in the menu items.
319 * You can provide a different cell area at object construction
320 * time, otherwise the #GtkTreeMenu will use a #GtkCellAreaBox.
324 g_object_class_install_property (object_class,
326 g_param_spec_object ("cell-area",
328 P_("The GtkCellArea used to layout cells"),
330 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
333 * GtkTreeMenu:tearoff:
335 * Specifies whether this menu comes with a leading tearoff menu item
339 g_object_class_install_property (object_class,
341 g_param_spec_boolean ("tearoff",
343 P_("Whether the menu has a tearoff item"),
345 GTK_PARAM_READWRITE));
348 * GtkTreeMenu:wrap-width:
350 * If wrap-width is set to a positive value, the list will be
351 * displayed in multiple columns, the number of columns is
352 * determined by wrap-width.
356 g_object_class_install_property (object_class,
358 g_param_spec_int ("wrap-width",
360 P_("Wrap width for laying out items in a grid"),
364 GTK_PARAM_READWRITE));
367 * GtkTreeMenu:row-span-column:
369 * If this is set to a non-negative value, it must be the index of a column
370 * of type %G_TYPE_INT in the model.
372 * The values of that column are used to determine how many rows a value in
373 * the list will span. Therefore, the values in the model column pointed to
374 * by this property must be greater than zero and not larger than wrap-width.
378 g_object_class_install_property (object_class,
380 g_param_spec_int ("row-span-column",
381 P_("Row span column"),
382 P_("TreeModel column containing the row span values"),
386 GTK_PARAM_READWRITE));
389 * GtkTreeMenu:column-span-column:
391 * If this is set to a non-negative value, it must be the index of a column
392 * of type %G_TYPE_INT in the model.
394 * The values of that column are used to determine how many columns a value
395 * in the list will span.
399 g_object_class_install_property (object_class,
401 g_param_spec_int ("column-span-column",
402 P_("Column span column"),
403 P_("TreeModel column containing the column span values"),
407 GTK_PARAM_READWRITE));
409 g_type_class_add_private (object_class, sizeof (GtkTreeMenuPrivate));
412 /****************************************************************
414 ****************************************************************/
416 gtk_tree_menu_constructor (GType type,
417 guint n_construct_properties,
418 GObjectConstructParam *construct_properties)
422 GtkTreeMenuPrivate *priv;
424 object = G_OBJECT_CLASS (_gtk_tree_menu_parent_class)->constructor
425 (type, n_construct_properties, construct_properties);
427 menu = GTK_TREE_MENU (object);
432 GtkCellArea *area = gtk_cell_area_box_new ();
434 gtk_tree_menu_set_area (menu, area);
437 priv->context = gtk_cell_area_create_context (priv->area);
439 priv->size_changed_id =
440 g_signal_connect (priv->context, "notify",
441 G_CALLBACK (context_size_changed_cb), menu);
447 gtk_tree_menu_dispose (GObject *object)
450 GtkTreeMenuPrivate *priv;
452 menu = GTK_TREE_MENU (object);
455 _gtk_tree_menu_set_model (menu, NULL);
456 gtk_tree_menu_set_area (menu, NULL);
460 /* Disconnect signals */
461 g_signal_handler_disconnect (priv->context, priv->size_changed_id);
463 g_object_unref (priv->context);
464 priv->context = NULL;
465 priv->size_changed_id = 0;
468 G_OBJECT_CLASS (_gtk_tree_menu_parent_class)->dispose (object);
472 gtk_tree_menu_finalize (GObject *object)
475 GtkTreeMenuPrivate *priv;
477 menu = GTK_TREE_MENU (object);
480 _gtk_tree_menu_set_row_separator_func (menu, NULL, NULL, NULL);
481 _gtk_tree_menu_set_header_func (menu, NULL, NULL, NULL);
484 gtk_tree_row_reference_free (priv->root);
486 G_OBJECT_CLASS (_gtk_tree_menu_parent_class)->finalize (object);
490 gtk_tree_menu_set_property (GObject *object,
495 GtkTreeMenu *menu = GTK_TREE_MENU (object);
500 _gtk_tree_menu_set_model (menu, g_value_get_object (value));
504 _gtk_tree_menu_set_root (menu, g_value_get_boxed (value));
508 /* Construct-only, can only be assigned once */
509 gtk_tree_menu_set_area (menu, (GtkCellArea *)g_value_get_object (value));
513 _gtk_tree_menu_set_tearoff (menu, g_value_get_boolean (value));
516 case PROP_WRAP_WIDTH:
517 _gtk_tree_menu_set_wrap_width (menu, g_value_get_int (value));
520 case PROP_ROW_SPAN_COL:
521 _gtk_tree_menu_set_row_span_column (menu, g_value_get_int (value));
524 case PROP_COL_SPAN_COL:
525 _gtk_tree_menu_set_column_span_column (menu, g_value_get_int (value));
529 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
535 gtk_tree_menu_get_property (GObject *object,
540 GtkTreeMenu *menu = GTK_TREE_MENU (object);
541 GtkTreeMenuPrivate *priv = menu->priv;
546 g_value_set_object (value, priv->model);
550 g_value_set_boxed (value, priv->root);
554 g_value_set_object (value, priv->area);
558 g_value_set_boolean (value, priv->tearoff);
562 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
567 /****************************************************************
569 ****************************************************************/
571 /* We tell all the menu items to reserve space for the submenu
572 * indicator if there is at least one submenu, this way we ensure
573 * that every internal cell area gets allocated the
574 * same width (and requested height for the same appropriate width).
577 sync_reserve_submenu_size (GtkTreeMenu *menu)
580 gboolean has_submenu = FALSE;
582 children = gtk_container_get_children (GTK_CONTAINER (menu));
583 for (l = children; l; l = l->next)
585 GtkMenuItem *item = l->data;
587 if (gtk_menu_item_get_submenu (item) != NULL)
594 for (l = children; l; l = l->next)
596 GtkMenuItem *item = l->data;
598 gtk_menu_item_set_reserve_indicator (item, has_submenu);
601 g_list_free (children);
605 gtk_tree_menu_get_preferred_width (GtkWidget *widget,
609 GtkTreeMenu *menu = GTK_TREE_MENU (widget);
610 GtkTreeMenuPrivate *priv = menu->priv;
612 /* We leave the requesting work up to the cellviews which operate in the same
613 * context, reserving space for the submenu indicator if any of the items have
614 * submenus ensures that every cellview will receive the same allocated width.
616 * Since GtkMenu does hieght-for-width correctly, we know that the width of
617 * every cell will be requested before the height-for-widths are requested.
619 g_signal_handler_block (priv->context, priv->size_changed_id);
621 sync_reserve_submenu_size (menu);
623 GTK_WIDGET_CLASS (_gtk_tree_menu_parent_class)->get_preferred_width (widget, minimum_size, natural_size);
625 g_signal_handler_unblock (priv->context, priv->size_changed_id);
629 gtk_tree_menu_get_preferred_height (GtkWidget *widget,
633 GtkTreeMenu *menu = GTK_TREE_MENU (widget);
634 GtkTreeMenuPrivate *priv = menu->priv;
636 g_signal_handler_block (priv->context, priv->size_changed_id);
638 sync_reserve_submenu_size (menu);
640 GTK_WIDGET_CLASS (_gtk_tree_menu_parent_class)->get_preferred_height (widget, minimum_size, natural_size);
642 g_signal_handler_unblock (priv->context, priv->size_changed_id);
645 /****************************************************************
646 * GtkCellLayoutIface *
647 ****************************************************************/
649 gtk_tree_menu_cell_layout_init (GtkCellLayoutIface *iface)
651 iface->get_area = gtk_tree_menu_cell_layout_get_area;
655 gtk_tree_menu_cell_layout_get_area (GtkCellLayout *layout)
657 GtkTreeMenu *menu = GTK_TREE_MENU (layout);
658 GtkTreeMenuPrivate *priv = menu->priv;
664 /****************************************************************
665 * TreeModel callbacks/populating menus *
666 ****************************************************************/
668 gtk_tree_menu_get_path_item (GtkTreeMenu *menu,
671 GtkWidget *item = NULL;
674 children = gtk_container_get_children (GTK_CONTAINER (menu));
676 for (l = children; item == NULL && l != NULL; l = l->next)
678 GtkWidget *child = l->data;
679 GtkTreePath *path = NULL;
681 if (GTK_IS_SEPARATOR_MENU_ITEM (child))
683 GtkTreeRowReference *row =
684 g_object_get_qdata (G_OBJECT (child), tree_menu_path_quark);
688 path = gtk_tree_row_reference_get_path (row);
691 /* Return any first child where its row-reference became invalid,
692 * this is because row-references get null paths before we recieve
693 * the "row-deleted" signal.
698 else if (!GTK_IS_TEAROFF_MENU_ITEM (child))
700 GtkWidget *view = gtk_bin_get_child (GTK_BIN (child));
702 /* It's always a cellview */
703 if (GTK_IS_CELL_VIEW (view))
704 path = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (view));
707 /* Return any first child where its row-reference became invalid,
708 * this is because row-references get null paths before we recieve
709 * the "row-deleted" signal.
716 if (gtk_tree_path_compare (search, path) == 0)
719 gtk_tree_path_free (path);
723 g_list_free (children);
729 gtk_tree_menu_path_in_menu (GtkTreeMenu *menu,
731 gboolean *header_item)
733 GtkTreeMenuPrivate *priv = menu->priv;
734 gboolean in_menu = FALSE;
735 gboolean is_header = FALSE;
737 /* Check if the is in root of the model */
738 if (gtk_tree_path_get_depth (path) == 1 && !priv->root)
740 /* If we are a submenu, compare the parent path */
743 GtkTreePath *root_path = gtk_tree_row_reference_get_path (priv->root);
744 GtkTreePath *search_path = gtk_tree_path_copy (path);
748 if (priv->menu_with_header &&
749 gtk_tree_path_compare (root_path, search_path) == 0)
754 else if (gtk_tree_path_get_depth (search_path) > 1)
756 gtk_tree_path_up (search_path);
758 if (gtk_tree_path_compare (root_path, search_path) == 0)
762 gtk_tree_path_free (root_path);
763 gtk_tree_path_free (search_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 its 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 (gtk_tree_path_get_depth (path) == 0 && !priv->root)
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)->priv->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)->priv->children &&
1142 GTK_MENU_SHELL (menu)->priv->children->next)
1144 GtkWidget *separator =
1145 GTK_MENU_SHELL (menu)->priv->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)->priv->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 its 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 its 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);