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, write to the
22 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 * Boston, MA 02111-1307, USA.
28 * @Short_Description: A GtkMenu automatically created from a #GtkTreeModel
31 * The #GtkTreeMenu is used to display a drop-down menu allowing selection
32 * of every row in the model and is used by the #GtkComboBox for its drop-down
38 #include "gtktreemenu.h"
39 #include "gtkmarshalers.h"
40 #include "gtkmenuitem.h"
41 #include "gtkseparatormenuitem.h"
42 #include "gtkcellareabox.h"
43 #include "gtkcellareacontext.h"
44 #include "gtkcelllayout.h"
45 #include "gtkcellview.h"
46 #include "gtkmenushellprivate.h"
47 #include "gtkprivate.h"
49 #undef GTK_DISABLE_DEPRECATED
50 #include "gtktearoffmenuitem.h"
53 static GObject *gtk_tree_menu_constructor (GType type,
54 guint n_construct_properties,
55 GObjectConstructParam *construct_properties);
56 static void gtk_tree_menu_dispose (GObject *object);
57 static void gtk_tree_menu_finalize (GObject *object);
58 static void gtk_tree_menu_set_property (GObject *object,
62 static void gtk_tree_menu_get_property (GObject *object,
68 static void gtk_tree_menu_get_preferred_width (GtkWidget *widget,
71 static void gtk_tree_menu_get_preferred_height (GtkWidget *widget,
75 /* GtkCellLayoutIface */
76 static void gtk_tree_menu_cell_layout_init (GtkCellLayoutIface *iface);
77 static GtkCellArea *gtk_tree_menu_cell_layout_get_area (GtkCellLayout *layout);
80 /* TreeModel/DrawingArea callbacks and building menus/submenus */
81 static inline void rebuild_menu (GtkTreeMenu *menu);
82 static gboolean menu_occupied (GtkTreeMenu *menu,
87 static void relayout_item (GtkTreeMenu *menu,
91 static void gtk_tree_menu_populate (GtkTreeMenu *menu);
92 static GtkWidget *gtk_tree_menu_create_item (GtkTreeMenu *menu,
94 gboolean header_item);
95 static void gtk_tree_menu_create_submenu (GtkTreeMenu *menu,
98 static void gtk_tree_menu_set_area (GtkTreeMenu *menu,
100 static GtkWidget *gtk_tree_menu_get_path_item (GtkTreeMenu *menu,
102 static gboolean gtk_tree_menu_path_in_menu (GtkTreeMenu *menu,
104 gboolean *header_item);
105 static void row_inserted_cb (GtkTreeModel *model,
109 static void row_deleted_cb (GtkTreeModel *model,
112 static void row_reordered_cb (GtkTreeModel *model,
117 static void row_changed_cb (GtkTreeModel *model,
121 static void context_size_changed_cb (GtkCellAreaContext *context,
124 static void area_apply_attributes_cb (GtkCellArea *area,
125 GtkTreeModel *tree_model,
127 gboolean is_expander,
128 gboolean is_expanded,
130 static void item_activated_cb (GtkMenuItem *item,
132 static void submenu_activated_cb (GtkTreeMenu *submenu,
135 static void gtk_tree_menu_set_model_internal (GtkTreeMenu *menu,
136 GtkTreeModel *model);
140 struct _GtkTreeMenuPrivate
142 /* TreeModel and parent for this menu */
144 GtkTreeRowReference *root;
146 /* CellArea and context for this menu */
148 GtkCellAreaContext *context;
151 gulong size_changed_id;
152 gulong apply_attributes_id;
153 gulong row_inserted_id;
154 gulong row_deleted_id;
155 gulong row_reordered_id;
156 gulong row_changed_id;
164 guint32 menu_with_header : 1;
168 GtkTreeViewRowSeparatorFunc row_separator_func;
169 gpointer row_separator_data;
170 GDestroyNotify row_separator_destroy;
172 /* Submenu headers */
173 GtkTreeMenuHeaderFunc header_func;
174 gpointer header_data;
175 GDestroyNotify header_destroy;
190 SIGNAL_MENU_ACTIVATE,
194 static guint tree_menu_signals[N_SIGNALS] = { 0 };
195 static GQuark tree_menu_path_quark = 0;
197 G_DEFINE_TYPE_WITH_CODE (GtkTreeMenu, _gtk_tree_menu, GTK_TYPE_MENU,
198 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
199 gtk_tree_menu_cell_layout_init));
202 _gtk_tree_menu_init (GtkTreeMenu *menu)
204 GtkTreeMenuPrivate *priv;
206 menu->priv = G_TYPE_INSTANCE_GET_PRIVATE (menu,
214 priv->context = NULL;
216 priv->size_changed_id = 0;
217 priv->row_inserted_id = 0;
218 priv->row_deleted_id = 0;
219 priv->row_reordered_id = 0;
220 priv->row_changed_id = 0;
222 priv->wrap_width = 0;
223 priv->row_span_col = -1;
224 priv->col_span_col = -1;
226 priv->menu_with_header = FALSE;
227 priv->tearoff = FALSE;
229 priv->row_separator_func = NULL;
230 priv->row_separator_data = NULL;
231 priv->row_separator_destroy = NULL;
233 priv->header_func = NULL;
234 priv->header_data = NULL;
235 priv->header_destroy = NULL;
237 gtk_menu_set_reserve_toggle_size (GTK_MENU (menu), FALSE);
241 _gtk_tree_menu_class_init (GtkTreeMenuClass *class)
243 GObjectClass *object_class = G_OBJECT_CLASS (class);
244 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
246 tree_menu_path_quark = g_quark_from_static_string ("gtk-tree-menu-path");
248 object_class->constructor = gtk_tree_menu_constructor;
249 object_class->dispose = gtk_tree_menu_dispose;
250 object_class->finalize = gtk_tree_menu_finalize;
251 object_class->set_property = gtk_tree_menu_set_property;
252 object_class->get_property = gtk_tree_menu_get_property;
254 widget_class->get_preferred_width = gtk_tree_menu_get_preferred_width;
255 widget_class->get_preferred_height = gtk_tree_menu_get_preferred_height;
258 * GtkTreeMenu::menu-activate:
259 * @menu: a #GtkTreeMenu
260 * @path: the #GtkTreePath string for the item which was activated
261 * @user_data: the user data
263 * This signal is emitted to notify that a menu item in the #GtkTreeMenu
264 * was activated and provides the path string from the #GtkTreeModel
265 * to specify which row was selected.
269 tree_menu_signals[SIGNAL_MENU_ACTIVATE] =
270 g_signal_new (I_("menu-activate"),
271 G_OBJECT_CLASS_TYPE (object_class),
273 0, /* No class closure here */
275 _gtk_marshal_VOID__STRING,
276 G_TYPE_NONE, 1, G_TYPE_STRING);
281 * The #GtkTreeModel from which the menu is constructed.
285 g_object_class_install_property (object_class,
287 g_param_spec_object ("model",
288 P_("TreeMenu model"),
289 P_("The model for the tree menu"),
291 GTK_PARAM_READWRITE));
296 * The #GtkTreePath that is the root for this menu, or %NULL.
298 * The #GtkTreeMenu recursively creates submenus for #GtkTreeModel
299 * rows that have children and the "root" for each menu is provided
300 * by the parent menu.
302 * If you dont provide a root for the #GtkTreeMenu then the whole
303 * model will be added to the menu. Specifying a root allows you
304 * to build a menu for a given #GtkTreePath and its children.
308 g_object_class_install_property (object_class,
310 g_param_spec_boxed ("root",
311 P_("TreeMenu root row"),
312 P_("The TreeMenu will display children of the "
315 GTK_PARAM_READWRITE));
318 * GtkTreeMenu:cell-area:
320 * The #GtkCellArea used to render cells in the menu items.
322 * You can provide a different cell area at object construction
323 * time, otherwise the #GtkTreeMenu will use a #GtkCellAreaBox.
327 g_object_class_install_property (object_class,
329 g_param_spec_object ("cell-area",
331 P_("The GtkCellArea used to layout cells"),
333 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
336 * GtkTreeMenu:tearoff:
338 * Specifies whether this menu comes with a leading tearoff menu item
342 g_object_class_install_property (object_class,
344 g_param_spec_boolean ("tearoff",
346 P_("Whether the menu has a tearoff item"),
348 GTK_PARAM_READWRITE));
351 * GtkTreeMenu:wrap-width:
353 * If wrap-width is set to a positive value, the list will be
354 * displayed in multiple columns, the number of columns is
355 * determined by wrap-width.
359 g_object_class_install_property (object_class,
361 g_param_spec_int ("wrap-width",
363 P_("Wrap width for laying out items in a grid"),
367 GTK_PARAM_READWRITE));
370 * GtkTreeMenu:row-span-column:
372 * If this is set to a non-negative value, it must be the index of a column
373 * of type %G_TYPE_INT in the model.
375 * The values of that column are used to determine how many rows a value in
376 * the list will span. Therefore, the values in the model column pointed to
377 * by this property must be greater than zero and not larger than wrap-width.
381 g_object_class_install_property (object_class,
383 g_param_spec_int ("row-span-column",
384 P_("Row span column"),
385 P_("TreeModel column containing the row span values"),
389 GTK_PARAM_READWRITE));
392 * GtkTreeMenu:column-span-column:
394 * If this is set to a non-negative value, it must be the index of a column
395 * of type %G_TYPE_INT in the model.
397 * The values of that column are used to determine how many columns a value
398 * in the list will span.
402 g_object_class_install_property (object_class,
404 g_param_spec_int ("column-span-column",
405 P_("Column span column"),
406 P_("TreeModel column containing the column span values"),
410 GTK_PARAM_READWRITE));
412 g_type_class_add_private (object_class, sizeof (GtkTreeMenuPrivate));
415 /****************************************************************
417 ****************************************************************/
419 gtk_tree_menu_constructor (GType type,
420 guint n_construct_properties,
421 GObjectConstructParam *construct_properties)
425 GtkTreeMenuPrivate *priv;
427 object = G_OBJECT_CLASS (_gtk_tree_menu_parent_class)->constructor
428 (type, n_construct_properties, construct_properties);
430 menu = GTK_TREE_MENU (object);
435 GtkCellArea *area = gtk_cell_area_box_new ();
437 gtk_tree_menu_set_area (menu, area);
440 priv->context = gtk_cell_area_create_context (priv->area);
442 priv->size_changed_id =
443 g_signal_connect (priv->context, "notify",
444 G_CALLBACK (context_size_changed_cb), menu);
450 gtk_tree_menu_dispose (GObject *object)
453 GtkTreeMenuPrivate *priv;
455 menu = GTK_TREE_MENU (object);
458 _gtk_tree_menu_set_model (menu, NULL);
459 gtk_tree_menu_set_area (menu, NULL);
463 /* Disconnect signals */
464 g_signal_handler_disconnect (priv->context, priv->size_changed_id);
466 g_object_unref (priv->context);
467 priv->context = NULL;
468 priv->size_changed_id = 0;
471 G_OBJECT_CLASS (_gtk_tree_menu_parent_class)->dispose (object);
475 gtk_tree_menu_finalize (GObject *object)
478 GtkTreeMenuPrivate *priv;
480 menu = GTK_TREE_MENU (object);
483 _gtk_tree_menu_set_row_separator_func (menu, NULL, NULL, NULL);
484 _gtk_tree_menu_set_header_func (menu, NULL, NULL, NULL);
487 gtk_tree_row_reference_free (priv->root);
489 G_OBJECT_CLASS (_gtk_tree_menu_parent_class)->finalize (object);
493 gtk_tree_menu_set_property (GObject *object,
498 GtkTreeMenu *menu = GTK_TREE_MENU (object);
503 _gtk_tree_menu_set_model (menu, g_value_get_object (value));
507 _gtk_tree_menu_set_root (menu, g_value_get_boxed (value));
511 /* Construct-only, can only be assigned once */
512 gtk_tree_menu_set_area (menu, (GtkCellArea *)g_value_get_object (value));
516 _gtk_tree_menu_set_tearoff (menu, g_value_get_boolean (value));
519 case PROP_WRAP_WIDTH:
520 _gtk_tree_menu_set_wrap_width (menu, g_value_get_int (value));
523 case PROP_ROW_SPAN_COL:
524 _gtk_tree_menu_set_row_span_column (menu, g_value_get_int (value));
527 case PROP_COL_SPAN_COL:
528 _gtk_tree_menu_set_column_span_column (menu, g_value_get_int (value));
532 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
538 gtk_tree_menu_get_property (GObject *object,
543 GtkTreeMenu *menu = GTK_TREE_MENU (object);
544 GtkTreeMenuPrivate *priv = menu->priv;
549 g_value_set_object (value, priv->model);
553 g_value_set_boxed (value, priv->root);
557 g_value_set_object (value, priv->area);
561 g_value_set_boolean (value, priv->tearoff);
565 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
570 /****************************************************************
572 ****************************************************************/
574 /* We tell all the menu items to reserve space for the submenu
575 * indicator if there is at least one submenu, this way we ensure
576 * that every internal cell area gets allocated the
577 * same width (and requested height for the same appropriate width).
580 sync_reserve_submenu_size (GtkTreeMenu *menu)
583 gboolean has_submenu = FALSE;
585 children = gtk_container_get_children (GTK_CONTAINER (menu));
586 for (l = children; l; l = l->next)
588 GtkMenuItem *item = l->data;
590 if (gtk_menu_item_get_submenu (item) != NULL)
597 for (l = children; l; l = l->next)
599 GtkMenuItem *item = l->data;
601 gtk_menu_item_set_reserve_indicator (item, has_submenu);
604 g_list_free (children);
608 gtk_tree_menu_get_preferred_width (GtkWidget *widget,
612 GtkTreeMenu *menu = GTK_TREE_MENU (widget);
613 GtkTreeMenuPrivate *priv = menu->priv;
615 /* We leave the requesting work up to the cellviews which operate in the same
616 * context, reserving space for the submenu indicator if any of the items have
617 * submenus ensures that every cellview will receive the same allocated width.
619 * Since GtkMenu does hieght-for-width correctly, we know that the width of
620 * every cell will be requested before the height-for-widths are requested.
622 g_signal_handler_block (priv->context, priv->size_changed_id);
624 sync_reserve_submenu_size (menu);
626 GTK_WIDGET_CLASS (_gtk_tree_menu_parent_class)->get_preferred_width (widget, minimum_size, natural_size);
628 g_signal_handler_unblock (priv->context, priv->size_changed_id);
632 gtk_tree_menu_get_preferred_height (GtkWidget *widget,
636 GtkTreeMenu *menu = GTK_TREE_MENU (widget);
637 GtkTreeMenuPrivate *priv = menu->priv;
639 g_signal_handler_block (priv->context, priv->size_changed_id);
641 sync_reserve_submenu_size (menu);
643 GTK_WIDGET_CLASS (_gtk_tree_menu_parent_class)->get_preferred_height (widget, minimum_size, natural_size);
645 g_signal_handler_unblock (priv->context, priv->size_changed_id);
648 /****************************************************************
649 * GtkCellLayoutIface *
650 ****************************************************************/
652 gtk_tree_menu_cell_layout_init (GtkCellLayoutIface *iface)
654 iface->get_area = gtk_tree_menu_cell_layout_get_area;
658 gtk_tree_menu_cell_layout_get_area (GtkCellLayout *layout)
660 GtkTreeMenu *menu = GTK_TREE_MENU (layout);
661 GtkTreeMenuPrivate *priv = menu->priv;
667 /****************************************************************
668 * TreeModel callbacks/populating menus *
669 ****************************************************************/
671 gtk_tree_menu_get_path_item (GtkTreeMenu *menu,
674 GtkWidget *item = NULL;
677 children = gtk_container_get_children (GTK_CONTAINER (menu));
679 for (l = children; item == NULL && l != NULL; l = l->next)
681 GtkWidget *child = l->data;
682 GtkTreePath *path = NULL;
684 if (GTK_IS_SEPARATOR_MENU_ITEM (child))
686 GtkTreeRowReference *row =
687 g_object_get_qdata (G_OBJECT (child), tree_menu_path_quark);
691 path = gtk_tree_row_reference_get_path (row);
694 /* Return any first child where its row-reference became invalid,
695 * this is because row-references get null paths before we recieve
696 * the "row-deleted" signal.
701 else if (!GTK_IS_TEAROFF_MENU_ITEM (child))
703 GtkWidget *view = gtk_bin_get_child (GTK_BIN (child));
705 /* It's always a cellview */
706 if (GTK_IS_CELL_VIEW (view))
707 path = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (view));
710 /* Return any first child where its row-reference became invalid,
711 * this is because row-references get null paths before we recieve
712 * the "row-deleted" signal.
719 if (gtk_tree_path_compare (search, path) == 0)
722 gtk_tree_path_free (path);
726 g_list_free (children);
732 gtk_tree_menu_path_in_menu (GtkTreeMenu *menu,
734 gboolean *header_item)
736 GtkTreeMenuPrivate *priv = menu->priv;
737 gboolean in_menu = FALSE;
738 gboolean is_header = FALSE;
740 /* Check if the is in root of the model */
741 if (gtk_tree_path_get_depth (path) == 1 && !priv->root)
743 /* If we are a submenu, compare the parent path */
746 GtkTreePath *root_path = gtk_tree_row_reference_get_path (priv->root);
747 GtkTreePath *search_path = gtk_tree_path_copy (path);
751 if (priv->menu_with_header &&
752 gtk_tree_path_compare (root_path, search_path) == 0)
757 else if (gtk_tree_path_get_depth (search_path) > 1)
759 gtk_tree_path_up (search_path);
761 if (gtk_tree_path_compare (root_path, search_path) == 0)
765 gtk_tree_path_free (root_path);
766 gtk_tree_path_free (search_path);
770 *header_item = is_header;
776 gtk_tree_menu_path_needs_submenu (GtkTreeMenu *menu,
779 GtkWidget *item = NULL;
781 GtkTreePath *parent_path;
783 if (gtk_tree_path_get_depth (search) <= 1)
786 parent_path = gtk_tree_path_copy (search);
787 gtk_tree_path_up (parent_path);
789 children = gtk_container_get_children (GTK_CONTAINER (menu));
791 for (l = children; item == NULL && l != NULL; l = l->next)
793 GtkWidget *child = l->data;
794 GtkTreePath *path = NULL;
796 /* Separators dont get submenus, if it already has a submenu then let
797 * the submenu handle inserted rows */
798 if (!GTK_IS_SEPARATOR_MENU_ITEM (child) &&
799 !gtk_menu_item_get_submenu (GTK_MENU_ITEM (child)))
801 GtkWidget *view = gtk_bin_get_child (GTK_BIN (child));
803 /* It's always a cellview */
804 if (GTK_IS_CELL_VIEW (view))
805 path = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (view));
810 if (gtk_tree_path_compare (parent_path, path) == 0)
813 gtk_tree_path_free (path);
817 g_list_free (children);
818 gtk_tree_path_free (parent_path);
824 find_empty_submenu (GtkTreeMenu *menu)
826 GtkTreeMenuPrivate *priv = menu->priv;
828 GtkWidget *submenu = NULL;
830 children = gtk_container_get_children (GTK_CONTAINER (menu));
832 for (l = children; submenu == NULL && l != NULL; l = l->next)
834 GtkWidget *child = l->data;
835 GtkTreePath *path = NULL;
838 /* Separators dont get submenus, if it already has a submenu then let
839 * the submenu handle inserted rows */
840 if (!GTK_IS_SEPARATOR_MENU_ITEM (child) && !GTK_IS_TEAROFF_MENU_ITEM (child))
842 GtkWidget *view = gtk_bin_get_child (GTK_BIN (child));
844 /* It's always a cellview */
845 if (GTK_IS_CELL_VIEW (view))
846 path = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (view));
851 if (gtk_tree_model_get_iter (priv->model, &iter, path) &&
852 !gtk_tree_model_iter_has_child (priv->model, &iter))
853 submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (child));
855 gtk_tree_path_free (path);
859 g_list_free (children);
865 row_inserted_cb (GtkTreeModel *model,
870 GtkTreeMenuPrivate *priv = menu->priv;
871 gint *indices, index, depth;
874 /* If the iter should be in this menu then go ahead and insert it */
875 if (gtk_tree_menu_path_in_menu (menu, path, NULL))
877 if (priv->wrap_width > 0)
881 /* Get the index of the path for this depth */
882 indices = gtk_tree_path_get_indices (path);
883 depth = gtk_tree_path_get_depth (path);
884 index = indices[depth -1];
886 /* Menus with a header include a menuitem for its root node
887 * and a separator menu item */
888 if (priv->menu_with_header)
891 /* Index after the tearoff item for the root menu if
892 * there is a tearoff item
894 if (priv->root == NULL && priv->tearoff)
897 item = gtk_tree_menu_create_item (menu, iter, FALSE);
898 gtk_menu_shell_insert (GTK_MENU_SHELL (menu), item, index);
900 /* Resize everything */
901 gtk_cell_area_context_reset (menu->priv->context);
906 /* Create submenus for iters if we need to */
907 item = gtk_tree_menu_path_needs_submenu (menu, path);
910 GtkTreePath *item_path = gtk_tree_path_copy (path);
912 gtk_tree_path_up (item_path);
913 gtk_tree_menu_create_submenu (menu, item, item_path);
914 gtk_tree_path_free (item_path);
920 row_deleted_cb (GtkTreeModel *model,
924 GtkTreeMenuPrivate *priv = menu->priv;
927 /* If it's the header item we leave it to the parent menu
928 * to remove us from its menu
930 item = gtk_tree_menu_get_path_item (menu, path);
934 if (priv->wrap_width > 0)
938 /* Get rid of the deleted item */
939 gtk_widget_destroy (item);
941 /* Resize everything */
942 gtk_cell_area_context_reset (menu->priv->context);
947 /* It's up to the parent menu to destroy a child menu that becomes empty
948 * since the topmost menu belongs to the user and is allowed to have no contents */
949 GtkWidget *submenu = find_empty_submenu (menu);
951 gtk_widget_destroy (submenu);
956 row_reordered_cb (GtkTreeModel *model,
962 GtkTreeMenuPrivate *priv = menu->priv;
963 gboolean this_menu = FALSE;
965 if (gtk_tree_path_get_depth (path) == 0 && !priv->root)
969 GtkTreePath *root_path =
970 gtk_tree_row_reference_get_path (priv->root);
972 if (gtk_tree_path_compare (root_path, path) == 0)
975 gtk_tree_path_free (root_path);
983 menu_item_position (GtkTreeMenu *menu,
989 children = gtk_container_get_children (GTK_CONTAINER (menu));
990 for (position = 0, l = children; l; position++, l = l->next)
992 GtkWidget *iitem = l->data;
998 g_list_free (children);
1004 row_changed_cb (GtkTreeModel *model,
1009 GtkTreeMenuPrivate *priv = menu->priv;
1010 gboolean is_separator = FALSE;
1011 gboolean has_header = FALSE;
1014 item = gtk_tree_menu_get_path_item (menu, path);
1018 GtkTreePath *root_path =
1019 gtk_tree_row_reference_get_path (priv->root);
1021 if (root_path && gtk_tree_path_compare (root_path, path) == 0)
1023 if (priv->header_func)
1025 priv->header_func (priv->model, iter, priv->header_data);
1027 if (has_header && !item)
1029 item = gtk_separator_menu_item_new ();
1030 gtk_widget_show (item);
1031 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
1033 item = gtk_tree_menu_create_item (menu, iter, TRUE);
1034 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
1036 priv->menu_with_header = TRUE;
1038 else if (!has_header && item)
1040 /* Destroy the header item and then the following separator */
1041 gtk_widget_destroy (item);
1042 gtk_widget_destroy (GTK_MENU_SHELL (menu)->priv->children->data);
1044 priv->menu_with_header = FALSE;
1047 gtk_tree_path_free (root_path);
1053 if (priv->wrap_width > 0)
1054 /* Ugly, we need to rebuild the menu here if
1055 * the row-span/row-column values change
1057 rebuild_menu (menu);
1060 if (priv->row_separator_func)
1062 priv->row_separator_func (model, iter,
1063 priv->row_separator_data);
1066 if (is_separator != GTK_IS_SEPARATOR_MENU_ITEM (item))
1068 gint position = menu_item_position (menu, item);
1070 gtk_widget_destroy (item);
1071 item = gtk_tree_menu_create_item (menu, iter, FALSE);
1072 gtk_menu_shell_insert (GTK_MENU_SHELL (menu), item, position);
1079 context_size_changed_cb (GtkCellAreaContext *context,
1083 if (!strcmp (pspec->name, "minimum-width") ||
1084 !strcmp (pspec->name, "natural-width") ||
1085 !strcmp (pspec->name, "minimum-height") ||
1086 !strcmp (pspec->name, "natural-height"))
1087 gtk_widget_queue_resize (menu);
1091 area_is_sensitive (GtkCellArea *area)
1093 GList *cells, *list;
1094 gboolean sensitive = FALSE;
1096 cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (area));
1098 for (list = cells; list; list = list->next)
1100 g_object_get (list->data, "sensitive", &sensitive, NULL);
1105 g_list_free (cells);
1111 area_apply_attributes_cb (GtkCellArea *area,
1112 GtkTreeModel *tree_model,
1114 gboolean is_expander,
1115 gboolean is_expanded,
1118 /* If the menu for this iter has a submenu */
1119 GtkTreeMenuPrivate *priv = menu->priv;
1125 path = gtk_tree_model_get_path (tree_model, iter);
1127 if (gtk_tree_menu_path_in_menu (menu, path, &is_header))
1129 item = gtk_tree_menu_get_path_item (menu, path);
1131 /* If there is no submenu, go ahead and update item sensitivity,
1132 * items with submenus are always sensitive */
1133 if (item && !gtk_menu_item_get_submenu (GTK_MENU_ITEM (item)))
1135 sensitive = area_is_sensitive (priv->area);
1137 gtk_widget_set_sensitive (item, sensitive);
1141 /* For header items we need to set the sensitivity
1142 * of the following separator item
1144 if (GTK_MENU_SHELL (menu)->priv->children &&
1145 GTK_MENU_SHELL (menu)->priv->children->next)
1147 GtkWidget *separator =
1148 GTK_MENU_SHELL (menu)->priv->children->next->data;
1150 gtk_widget_set_sensitive (separator, sensitive);
1156 gtk_tree_path_free (path);
1160 gtk_tree_menu_set_area (GtkTreeMenu *menu,
1163 GtkTreeMenuPrivate *priv = menu->priv;
1167 g_signal_handler_disconnect (priv->area,
1168 priv->apply_attributes_id);
1169 priv->apply_attributes_id = 0;
1171 g_object_unref (priv->area);
1178 g_object_ref_sink (priv->area);
1180 priv->apply_attributes_id =
1181 g_signal_connect (priv->area, "apply-attributes",
1182 G_CALLBACK (area_apply_attributes_cb), menu);
1187 menu_occupied (GtkTreeMenu *menu,
1191 guint bottom_attach)
1195 for (i = GTK_MENU_SHELL (menu)->priv->children; i; i = i->next)
1199 gtk_container_child_get (GTK_CONTAINER (menu),
1203 "bottom-attach", &b,
1207 /* look if this item intersects with the given coordinates */
1208 if (right_attach > l && left_attach < r && bottom_attach > t && top_attach < b)
1216 relayout_item (GtkTreeMenu *menu,
1221 GtkTreeMenuPrivate *priv = menu->priv;
1222 gint current_col = 0, current_row = 0;
1223 gint rows = 1, cols = 1;
1225 if (priv->col_span_col == -1 &&
1226 priv->row_span_col == -1 &&
1229 gtk_container_child_get (GTK_CONTAINER (menu), prev,
1230 "right-attach", ¤t_col,
1231 "top-attach", ¤t_row,
1233 if (current_col + cols > priv->wrap_width)
1241 if (priv->col_span_col != -1)
1242 gtk_tree_model_get (priv->model, iter,
1243 priv->col_span_col, &cols,
1245 if (priv->row_span_col != -1)
1246 gtk_tree_model_get (priv->model, iter,
1247 priv->row_span_col, &rows,
1252 if (current_col + cols > priv->wrap_width)
1258 if (!menu_occupied (menu,
1259 current_col, current_col + cols,
1260 current_row, current_row + rows))
1267 /* set attach props */
1268 gtk_menu_attach (GTK_MENU (menu), item,
1269 current_col, current_col + cols,
1270 current_row, current_row + rows);
1274 gtk_tree_menu_create_submenu (GtkTreeMenu *menu,
1278 GtkTreeMenuPrivate *priv = menu->priv;
1282 view = gtk_bin_get_child (GTK_BIN (item));
1283 gtk_cell_view_set_draw_sensitive (GTK_CELL_VIEW (view), TRUE);
1285 submenu = _gtk_tree_menu_new_with_area (priv->area);
1287 _gtk_tree_menu_set_row_separator_func (GTK_TREE_MENU (submenu),
1288 priv->row_separator_func,
1289 priv->row_separator_data,
1290 priv->row_separator_destroy);
1291 _gtk_tree_menu_set_header_func (GTK_TREE_MENU (submenu),
1294 priv->header_destroy);
1296 _gtk_tree_menu_set_wrap_width (GTK_TREE_MENU (submenu), priv->wrap_width);
1297 _gtk_tree_menu_set_row_span_column (GTK_TREE_MENU (submenu), priv->row_span_col);
1298 _gtk_tree_menu_set_column_span_column (GTK_TREE_MENU (submenu), priv->col_span_col);
1300 gtk_tree_menu_set_model_internal (GTK_TREE_MENU (submenu), priv->model);
1301 _gtk_tree_menu_set_root (GTK_TREE_MENU (submenu), path);
1302 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
1304 g_signal_connect (submenu, "menu-activate",
1305 G_CALLBACK (submenu_activated_cb), menu);
1309 gtk_tree_menu_create_item (GtkTreeMenu *menu,
1311 gboolean header_item)
1313 GtkTreeMenuPrivate *priv = menu->priv;
1314 GtkWidget *item, *view;
1316 gboolean is_separator = FALSE;
1318 path = gtk_tree_model_get_path (priv->model, iter);
1320 if (priv->row_separator_func)
1322 priv->row_separator_func (priv->model, iter,
1323 priv->row_separator_data);
1327 item = gtk_separator_menu_item_new ();
1328 gtk_widget_show (item);
1330 g_object_set_qdata_full (G_OBJECT (item),
1331 tree_menu_path_quark,
1332 gtk_tree_row_reference_new (priv->model, path),
1333 (GDestroyNotify)gtk_tree_row_reference_free);
1337 view = gtk_cell_view_new_with_context (priv->area, priv->context);
1338 item = gtk_menu_item_new ();
1339 gtk_widget_show (view);
1340 gtk_widget_show (item);
1342 gtk_cell_view_set_model (GTK_CELL_VIEW (view), priv->model);
1343 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (view), path);
1345 gtk_widget_show (view);
1346 gtk_container_add (GTK_CONTAINER (item), view);
1348 g_signal_connect (item, "activate", G_CALLBACK (item_activated_cb), menu);
1350 /* Add a GtkTreeMenu submenu to render the children of this row */
1351 if (header_item == FALSE &&
1352 gtk_tree_model_iter_has_child (priv->model, iter))
1353 gtk_tree_menu_create_submenu (menu, item, path);
1356 gtk_tree_path_free (path);
1362 rebuild_menu (GtkTreeMenu *menu)
1364 GtkTreeMenuPrivate *priv = menu->priv;
1366 /* Destroy all the menu items */
1367 gtk_container_foreach (GTK_CONTAINER (menu),
1368 (GtkCallback) gtk_widget_destroy, NULL);
1372 gtk_tree_menu_populate (menu);
1377 gtk_tree_menu_populate (GtkTreeMenu *menu)
1379 GtkTreeMenuPrivate *priv = menu->priv;
1380 GtkTreePath *path = NULL;
1383 gboolean valid = FALSE;
1384 GtkWidget *menu_item, *prev = NULL;
1390 path = gtk_tree_row_reference_get_path (priv->root);
1394 if (gtk_tree_model_get_iter (priv->model, &parent, path))
1396 valid = gtk_tree_model_iter_children (priv->model, &iter, &parent);
1398 if (priv->header_func &&
1399 priv->header_func (priv->model, &parent, priv->header_data))
1401 /* Add a submenu header for rows which desire one, used for
1402 * combo boxes to allow all rows to be activatable/selectable
1404 menu_item = gtk_tree_menu_create_item (menu, &parent, TRUE);
1405 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
1407 menu_item = gtk_separator_menu_item_new ();
1408 gtk_widget_show (menu_item);
1409 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
1412 priv->menu_with_header = TRUE;
1415 gtk_tree_path_free (path);
1419 /* Tearoff menu items only go in the root menu */
1422 menu_item = gtk_tearoff_menu_item_new ();
1423 gtk_widget_show (menu_item);
1425 if (priv->wrap_width > 0)
1426 gtk_menu_attach (GTK_MENU (menu), menu_item, 0, priv->wrap_width, 0, 1);
1428 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
1433 valid = gtk_tree_model_iter_children (priv->model, &iter, NULL);
1436 /* Create a menu item for every row at the current depth, add a GtkTreeMenu
1437 * submenu for iters/items that have children */
1440 menu_item = gtk_tree_menu_create_item (menu, &iter, FALSE);
1442 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
1444 if (priv->wrap_width > 0)
1445 relayout_item (menu, menu_item, &iter, prev);
1448 valid = gtk_tree_model_iter_next (priv->model, &iter);
1453 item_activated_cb (GtkMenuItem *item,
1460 /* Only activate leafs, not parents */
1461 if (!gtk_menu_item_get_submenu (item))
1463 view = GTK_CELL_VIEW (gtk_bin_get_child (GTK_BIN (item)));
1464 path = gtk_cell_view_get_displayed_row (view);
1465 path_str = gtk_tree_path_to_string (path);
1467 g_signal_emit (menu, tree_menu_signals[SIGNAL_MENU_ACTIVATE], 0, path_str);
1470 gtk_tree_path_free (path);
1475 submenu_activated_cb (GtkTreeMenu *submenu,
1479 g_signal_emit (menu, tree_menu_signals[SIGNAL_MENU_ACTIVATE], 0, path);
1482 /* Sets the model without rebuilding the menu, prevents
1483 * infinite recursion while building submenus (we wait
1484 * until the root is set and then build the menu) */
1486 gtk_tree_menu_set_model_internal (GtkTreeMenu *menu,
1487 GtkTreeModel *model)
1489 GtkTreeMenuPrivate *priv;
1493 if (priv->model != model)
1497 /* Disconnect signals */
1498 g_signal_handler_disconnect (priv->model,
1499 priv->row_inserted_id);
1500 g_signal_handler_disconnect (priv->model,
1501 priv->row_deleted_id);
1502 g_signal_handler_disconnect (priv->model,
1503 priv->row_reordered_id);
1504 g_signal_handler_disconnect (priv->model,
1505 priv->row_changed_id);
1506 priv->row_inserted_id = 0;
1507 priv->row_deleted_id = 0;
1508 priv->row_reordered_id = 0;
1509 priv->row_changed_id = 0;
1511 g_object_unref (priv->model);
1514 priv->model = model;
1518 g_object_ref (priv->model);
1520 /* Connect signals */
1521 priv->row_inserted_id = g_signal_connect (priv->model, "row-inserted",
1522 G_CALLBACK (row_inserted_cb), menu);
1523 priv->row_deleted_id = g_signal_connect (priv->model, "row-deleted",
1524 G_CALLBACK (row_deleted_cb), menu);
1525 priv->row_reordered_id = g_signal_connect (priv->model, "rows-reordered",
1526 G_CALLBACK (row_reordered_cb), menu);
1527 priv->row_changed_id = g_signal_connect (priv->model, "row-changed",
1528 G_CALLBACK (row_changed_cb), menu);
1533 /****************************************************************
1535 ****************************************************************/
1538 * _gtk_tree_menu_new:
1540 * Creates a new #GtkTreeMenu.
1542 * Return value: A newly created #GtkTreeMenu with no model or root.
1547 _gtk_tree_menu_new (void)
1549 return (GtkWidget *)g_object_new (GTK_TYPE_TREE_MENU, NULL);
1553 * _gtk_tree_menu_new_with_area:
1554 * @area: the #GtkCellArea to use to render cells in the menu
1556 * Creates a new #GtkTreeMenu using @area to render its cells.
1558 * Return value: A newly created #GtkTreeMenu with no model or root.
1563 _gtk_tree_menu_new_with_area (GtkCellArea *area)
1565 return (GtkWidget *)g_object_new (GTK_TYPE_TREE_MENU,
1571 * _gtk_tree_menu_new_full:
1572 * @area: (allow-none): the #GtkCellArea to use to render cells in the menu, or %NULL.
1573 * @model: (allow-none): the #GtkTreeModel to build the menu heirarchy from, or %NULL.
1574 * @root: (allow-none): the #GtkTreePath indicating the root row for this menu, or %NULL.
1576 * Creates a new #GtkTreeMenu hierarchy from the provided @model and @root using @area to render its cells.
1578 * Return value: A newly created #GtkTreeMenu.
1583 _gtk_tree_menu_new_full (GtkCellArea *area,
1584 GtkTreeModel *model,
1587 return (GtkWidget *)g_object_new (GTK_TYPE_TREE_MENU,
1595 * _gtk_tree_menu_set_model:
1596 * @menu: a #GtkTreeMenu
1597 * @model: (allow-none): the #GtkTreeModel to build the menu hierarchy from, or %NULL.
1599 * Sets @model to be used to build the menu heirarhcy.
1604 _gtk_tree_menu_set_model (GtkTreeMenu *menu,
1605 GtkTreeModel *model)
1607 g_return_if_fail (GTK_IS_TREE_MENU (menu));
1608 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
1610 gtk_tree_menu_set_model_internal (menu, model);
1612 rebuild_menu (menu);
1616 * _gtk_tree_menu_get_model:
1617 * @menu: a #GtkTreeMenu
1619 * Gets the @model currently used for the menu heirarhcy.
1621 * Return value: (transfer none): the #GtkTreeModel which is used
1622 * for @menu's hierarchy.
1627 _gtk_tree_menu_get_model (GtkTreeMenu *menu)
1629 GtkTreeMenuPrivate *priv;
1631 g_return_val_if_fail (GTK_IS_TREE_MENU (menu), NULL);
1639 * _gtk_tree_menu_set_root:
1640 * @menu: a #GtkTreeMenu
1641 * @path: (allow-none): the #GtkTreePath which is the root of @menu, or %NULL.
1643 * Sets the root of a @menu's hierarchy to be @path. @menu must already
1644 * have a model set and @path must point to a valid path inside the model.
1649 _gtk_tree_menu_set_root (GtkTreeMenu *menu,
1652 GtkTreeMenuPrivate *priv;
1654 g_return_if_fail (GTK_IS_TREE_MENU (menu));
1655 g_return_if_fail (menu->priv->model != NULL || path == NULL);
1660 gtk_tree_row_reference_free (priv->root);
1663 priv->root = gtk_tree_row_reference_new (priv->model, path);
1667 rebuild_menu (menu);
1671 * _gtk_tree_menu_get_root:
1672 * @menu: a #GtkTreeMenu
1674 * Gets the @root path for @menu's hierarchy, or returns %NULL if @menu
1675 * has no model or is building a heirarchy for the entire model. *
1677 * Return value: (transfer full) (allow-none): A newly created #GtkTreePath
1678 * pointing to the root of @menu which must be freed with gtk_tree_path_free().
1683 _gtk_tree_menu_get_root (GtkTreeMenu *menu)
1685 GtkTreeMenuPrivate *priv;
1687 g_return_val_if_fail (GTK_IS_TREE_MENU (menu), NULL);
1692 return gtk_tree_row_reference_get_path (priv->root);
1698 * _gtk_tree_menu_get_tearoff:
1699 * @menu: a #GtkTreeMenu
1701 * Gets whether this menu is build with a leading tearoff menu item.
1703 * Return value: %TRUE if the menu has a tearoff item.
1708 _gtk_tree_menu_get_tearoff (GtkTreeMenu *menu)
1710 GtkTreeMenuPrivate *priv;
1712 g_return_val_if_fail (GTK_IS_TREE_MENU (menu), FALSE);
1716 return priv->tearoff;
1720 * _gtk_tree_menu_set_tearoff:
1721 * @menu: a #GtkTreeMenu
1722 * @tearoff: whether the menu should have a leading tearoff menu item.
1724 * Sets whether this menu has a leading tearoff menu item.
1729 _gtk_tree_menu_set_tearoff (GtkTreeMenu *menu,
1732 GtkTreeMenuPrivate *priv;
1734 g_return_if_fail (GTK_IS_TREE_MENU (menu));
1738 if (priv->tearoff != tearoff)
1740 priv->tearoff = tearoff;
1742 rebuild_menu (menu);
1744 g_object_notify (G_OBJECT (menu), "tearoff");
1749 * _gtk_tree_menu_get_wrap_width:
1750 * @menu: a #GtkTreeMenu
1752 * Gets the wrap width which is used to determine the number of columns
1753 * for @menu. If the wrap width is larger than 1, @menu is in table mode.
1755 * Return value: the wrap width.
1760 _gtk_tree_menu_get_wrap_width (GtkTreeMenu *menu)
1762 GtkTreeMenuPrivate *priv;
1764 g_return_val_if_fail (GTK_IS_TREE_MENU (menu), FALSE);
1768 return priv->wrap_width;
1772 * _gtk_tree_menu_set_wrap_width:
1773 * @menu: a #GtkTreeMenu
1774 * @width: the wrap width
1776 * Sets the wrap width which is used to determine the number of columns
1777 * for @menu. If the wrap width is larger than 1, @menu is in table mode.
1782 _gtk_tree_menu_set_wrap_width (GtkTreeMenu *menu,
1785 GtkTreeMenuPrivate *priv;
1787 g_return_if_fail (GTK_IS_TREE_MENU (menu));
1788 g_return_if_fail (width >= 0);
1792 if (priv->wrap_width != width)
1794 priv->wrap_width = width;
1796 rebuild_menu (menu);
1798 g_object_notify (G_OBJECT (menu), "wrap-width");
1803 * _gtk_tree_menu_get_row_span_column:
1804 * @menu: a #GtkTreeMenu
1806 * Gets the column with row span information for @menu.
1807 * The row span column contains integers which indicate how many rows
1808 * a menu item should span.
1810 * Return value: the column in @menu's model containing row span information, or -1.
1815 _gtk_tree_menu_get_row_span_column (GtkTreeMenu *menu)
1817 GtkTreeMenuPrivate *priv;
1819 g_return_val_if_fail (GTK_IS_TREE_MENU (menu), FALSE);
1823 return priv->row_span_col;
1827 * _gtk_tree_menu_set_row_span_column:
1828 * @menu: a #GtkTreeMenu
1829 * @row_span: the column in the model to fetch the row span for a given menu item.
1831 * Sets the column with row span information for @menu to be @row_span.
1832 * The row span column contains integers which indicate how many rows
1833 * a menu item should span.
1838 _gtk_tree_menu_set_row_span_column (GtkTreeMenu *menu,
1841 GtkTreeMenuPrivate *priv;
1843 g_return_if_fail (GTK_IS_TREE_MENU (menu));
1847 if (priv->row_span_col != row_span)
1849 priv->row_span_col = row_span;
1851 if (priv->wrap_width > 0)
1852 rebuild_menu (menu);
1854 g_object_notify (G_OBJECT (menu), "row-span-column");
1859 * _gtk_tree_menu_get_column_span_column:
1860 * @menu: a #GtkTreeMenu
1862 * Gets the column with column span information for @menu.
1863 * The column span column contains integers which indicate how many columns
1864 * a menu item should span.
1866 * Return value: the column in @menu's model containing column span information, or -1.
1871 _gtk_tree_menu_get_column_span_column (GtkTreeMenu *menu)
1873 GtkTreeMenuPrivate *priv;
1875 g_return_val_if_fail (GTK_IS_TREE_MENU (menu), FALSE);
1879 return priv->col_span_col;
1883 * _gtk_tree_menu_set_column_span_column:
1884 * @menu: a #GtkTreeMenu
1885 * @column_span: the column in the model to fetch the column span for a given menu item.
1887 * Sets the column with column span information for @menu to be @column_span.
1888 * The column span column contains integers which indicate how many columns
1889 * a menu item should span.
1894 _gtk_tree_menu_set_column_span_column (GtkTreeMenu *menu,
1897 GtkTreeMenuPrivate *priv;
1899 g_return_if_fail (GTK_IS_TREE_MENU (menu));
1903 if (priv->col_span_col != column_span)
1905 priv->col_span_col = column_span;
1907 if (priv->wrap_width > 0)
1908 rebuild_menu (menu);
1910 g_object_notify (G_OBJECT (menu), "column-span-column");
1915 * _gtk_tree_menu_get_row_separator_func:
1916 * @menu: a #GtkTreeMenu
1918 * Gets the current #GtkTreeViewRowSeparatorFunc separator function.
1920 * Return value: the current row separator function.
1924 GtkTreeViewRowSeparatorFunc
1925 _gtk_tree_menu_get_row_separator_func (GtkTreeMenu *menu)
1927 GtkTreeMenuPrivate *priv;
1929 g_return_val_if_fail (GTK_IS_TREE_MENU (menu), NULL);
1933 return priv->row_separator_func;
1937 * _gtk_tree_menu_set_row_separator_func:
1938 * @menu: a #GtkTreeMenu
1939 * @func: (allow-none): a #GtkTreeViewRowSeparatorFunc, or %NULL to unset the separator function.
1940 * @data: (allow-none): user data to pass to @func, or %NULL
1941 * @destroy: (allow-none): destroy notifier for @data, or %NULL
1943 * Sets the row separator function, which is used to determine
1944 * whether a row should be drawn as a separator. If the row separator
1945 * function is %NULL, no separators are drawn. This is the default value.
1950 _gtk_tree_menu_set_row_separator_func (GtkTreeMenu *menu,
1951 GtkTreeViewRowSeparatorFunc func,
1953 GDestroyNotify destroy)
1955 GtkTreeMenuPrivate *priv;
1957 g_return_if_fail (GTK_IS_TREE_MENU (menu));
1961 if (priv->row_separator_destroy)
1962 priv->row_separator_destroy (priv->row_separator_data);
1964 priv->row_separator_func = func;
1965 priv->row_separator_data = data;
1966 priv->row_separator_destroy = destroy;
1968 rebuild_menu (menu);
1972 * _gtk_tree_menu_get_header_func:
1973 * @menu: a #GtkTreeMenu
1975 * Gets the current #GtkTreeMenuHeaderFunc header function.
1977 * Return value: the current header function.
1981 GtkTreeMenuHeaderFunc
1982 _gtk_tree_menu_get_header_func (GtkTreeMenu *menu)
1984 GtkTreeMenuPrivate *priv;
1986 g_return_val_if_fail (GTK_IS_TREE_MENU (menu), NULL);
1990 return priv->header_func;
1994 * _gtk_tree_menu_set_header_func:
1995 * @menu: a #GtkTreeMenu
1996 * @func: (allow-none): a #GtkTreeMenuHeaderFunc, or %NULL to unset the header function.
1997 * @data: (allow-none): user data to pass to @func, or %NULL
1998 * @destroy: (allow-none): destroy notifier for @data, or %NULL
2000 * Sets the header function, which is used to determine
2001 * whether a row width children should contain a leading header
2002 * menu item to allow that row to be selectable as an independant
2003 * menu item. If the header function is %NULL, no rows with children
2004 * have menu items which can be activated as leafs.
2005 * This is the default value.
2010 _gtk_tree_menu_set_header_func (GtkTreeMenu *menu,
2011 GtkTreeMenuHeaderFunc func,
2013 GDestroyNotify destroy)
2015 GtkTreeMenuPrivate *priv;
2017 g_return_if_fail (GTK_IS_TREE_MENU (menu));
2021 if (priv->header_destroy)
2022 priv->header_destroy (priv->header_data);
2024 priv->header_func = func;
2025 priv->header_data = data;
2026 priv->header_destroy = destroy;
2028 rebuild_menu (menu);