2010-11-18 08:33:23 +00:00
|
|
|
|
/* gtktreemenu.c
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2010 Openismus GmbH
|
|
|
|
|
*
|
|
|
|
|
* Authors:
|
|
|
|
|
* Tristan Van Berkom <tristanvb@openismus.com>
|
|
|
|
|
*
|
2010-12-30 08:35:44 +00:00
|
|
|
|
* Based on some GtkComboBox menu code by Kristian Rietveld <kris@gtk.org>
|
|
|
|
|
*
|
2010-11-18 08:33:23 +00:00
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Library General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2010-11-18 08:33:23 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2011-01-06 13:23:18 +00:00
|
|
|
|
/*
|
2010-12-03 09:28:54 +00:00
|
|
|
|
* SECTION:gtktreemenu
|
|
|
|
|
* @Short_Description: A GtkMenu automatically created from a #GtkTreeModel
|
|
|
|
|
* @Title: GtkTreeMenu
|
|
|
|
|
*
|
2011-01-04 15:14:25 +00:00
|
|
|
|
* The #GtkTreeMenu is used to display a drop-down menu allowing selection
|
2010-12-03 09:28:54 +00:00
|
|
|
|
* of every row in the model and is used by the #GtkComboBox for its drop-down
|
|
|
|
|
* menu.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-11-18 08:33:23 +00:00
|
|
|
|
#include "config.h"
|
|
|
|
|
#include "gtkintl.h"
|
|
|
|
|
#include "gtktreemenu.h"
|
2010-11-20 07:32:24 +00:00
|
|
|
|
#include "gtkmarshalers.h"
|
2010-11-18 08:33:23 +00:00
|
|
|
|
#include "gtkmenuitem.h"
|
|
|
|
|
#include "gtkseparatormenuitem.h"
|
|
|
|
|
#include "gtkcellareabox.h"
|
|
|
|
|
#include "gtkcellareacontext.h"
|
|
|
|
|
#include "gtkcelllayout.h"
|
|
|
|
|
#include "gtkcellview.h"
|
2010-12-30 08:28:26 +00:00
|
|
|
|
#include "gtkmenushellprivate.h"
|
2010-11-18 08:33:23 +00:00
|
|
|
|
#include "gtkprivate.h"
|
|
|
|
|
|
|
|
|
|
/* GObjectClass */
|
2014-06-26 22:22:42 +00:00
|
|
|
|
static void gtk_tree_menu_constructed (GObject *object);
|
2010-11-18 08:33:23 +00:00
|
|
|
|
static void gtk_tree_menu_dispose (GObject *object);
|
|
|
|
|
static void gtk_tree_menu_finalize (GObject *object);
|
|
|
|
|
static void gtk_tree_menu_set_property (GObject *object,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
guint prop_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec);
|
2010-11-18 08:33:23 +00:00
|
|
|
|
static void gtk_tree_menu_get_property (GObject *object,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
guint prop_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec);
|
2010-11-18 08:33:23 +00:00
|
|
|
|
|
|
|
|
|
/* GtkWidgetClass */
|
2016-10-22 14:06:14 +00:00
|
|
|
|
static void gtk_tree_menu_measure (GtkWidget *widget,
|
|
|
|
|
GtkOrientation orientation,
|
|
|
|
|
int for_size,
|
|
|
|
|
int *minimum,
|
|
|
|
|
int *natural,
|
|
|
|
|
int *minimum_baseline,
|
|
|
|
|
int *natural_baseline);
|
2010-11-18 08:33:23 +00:00
|
|
|
|
|
|
|
|
|
/* GtkCellLayoutIface */
|
|
|
|
|
static void gtk_tree_menu_cell_layout_init (GtkCellLayoutIface *iface);
|
|
|
|
|
static GtkCellArea *gtk_tree_menu_cell_layout_get_area (GtkCellLayout *layout);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* TreeModel/DrawingArea callbacks and building menus/submenus */
|
2010-11-23 06:48:14 +00:00
|
|
|
|
static inline void rebuild_menu (GtkTreeMenu *menu);
|
2010-11-22 06:53:19 +00:00
|
|
|
|
static void gtk_tree_menu_populate (GtkTreeMenu *menu);
|
2010-11-18 08:33:23 +00:00
|
|
|
|
static GtkWidget *gtk_tree_menu_create_item (GtkTreeMenu *menu,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
gboolean header_item);
|
2010-11-24 11:00:10 +00:00
|
|
|
|
static void gtk_tree_menu_create_submenu (GtkTreeMenu *menu,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
GtkWidget *item,
|
|
|
|
|
GtkTreePath *path);
|
2010-11-22 06:53:19 +00:00
|
|
|
|
static void gtk_tree_menu_set_area (GtkTreeMenu *menu,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
GtkCellArea *area);
|
2010-11-22 06:53:19 +00:00
|
|
|
|
static GtkWidget *gtk_tree_menu_get_path_item (GtkTreeMenu *menu,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
GtkTreePath *path);
|
2010-11-24 04:49:12 +00:00
|
|
|
|
static gboolean gtk_tree_menu_path_in_menu (GtkTreeMenu *menu,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
GtkTreePath *path,
|
|
|
|
|
gboolean *header_item);
|
2010-11-23 06:48:14 +00:00
|
|
|
|
static void row_inserted_cb (GtkTreeModel *model,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
GtkTreePath *path,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
GtkTreeMenu *menu);
|
2010-11-23 06:48:14 +00:00
|
|
|
|
static void row_deleted_cb (GtkTreeModel *model,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
GtkTreePath *path,
|
|
|
|
|
GtkTreeMenu *menu);
|
2010-11-23 06:48:14 +00:00
|
|
|
|
static void row_reordered_cb (GtkTreeModel *model,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
GtkTreePath *path,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
gint *new_order,
|
|
|
|
|
GtkTreeMenu *menu);
|
2010-11-23 06:48:14 +00:00
|
|
|
|
static void row_changed_cb (GtkTreeModel *model,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
GtkTreePath *path,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
GtkTreeMenu *menu);
|
2010-11-22 06:53:19 +00:00
|
|
|
|
static void context_size_changed_cb (GtkCellAreaContext *context,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
GParamSpec *pspec,
|
|
|
|
|
GtkWidget *menu);
|
2010-11-24 04:49:12 +00:00
|
|
|
|
static void area_apply_attributes_cb (GtkCellArea *area,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
GtkTreeModel *tree_model,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
gboolean is_expander,
|
|
|
|
|
gboolean is_expanded,
|
|
|
|
|
GtkTreeMenu *menu);
|
2010-11-22 06:53:19 +00:00
|
|
|
|
static void item_activated_cb (GtkMenuItem *item,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
GtkTreeMenu *menu);
|
2010-11-22 06:53:19 +00:00
|
|
|
|
static void submenu_activated_cb (GtkTreeMenu *submenu,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
const gchar *path,
|
|
|
|
|
GtkTreeMenu *menu);
|
2010-11-24 09:14:36 +00:00
|
|
|
|
static void gtk_tree_menu_set_model_internal (GtkTreeMenu *menu,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
GtkTreeModel *model);
|
2010-11-18 08:33:23 +00:00
|
|
|
|
|
2010-11-23 06:48:14 +00:00
|
|
|
|
|
|
|
|
|
|
2010-11-18 08:33:23 +00:00
|
|
|
|
struct _GtkTreeMenuPrivate
|
|
|
|
|
{
|
|
|
|
|
/* TreeModel and parent for this menu */
|
|
|
|
|
GtkTreeModel *model;
|
|
|
|
|
GtkTreeRowReference *root;
|
|
|
|
|
|
|
|
|
|
/* CellArea and context for this menu */
|
|
|
|
|
GtkCellArea *area;
|
|
|
|
|
GtkCellAreaContext *context;
|
2011-01-04 15:14:25 +00:00
|
|
|
|
|
2010-11-18 08:33:23 +00:00
|
|
|
|
/* Signals */
|
|
|
|
|
gulong size_changed_id;
|
2010-11-24 04:49:12 +00:00
|
|
|
|
gulong apply_attributes_id;
|
2010-11-22 06:53:19 +00:00
|
|
|
|
gulong row_inserted_id;
|
|
|
|
|
gulong row_deleted_id;
|
|
|
|
|
gulong row_reordered_id;
|
2010-11-23 06:48:14 +00:00
|
|
|
|
gulong row_changed_id;
|
|
|
|
|
|
|
|
|
|
/* Flags */
|
|
|
|
|
guint32 menu_with_header : 1;
|
2010-11-18 08:33:23 +00:00
|
|
|
|
|
|
|
|
|
/* Row separators */
|
|
|
|
|
GtkTreeViewRowSeparatorFunc row_separator_func;
|
|
|
|
|
gpointer row_separator_data;
|
|
|
|
|
GDestroyNotify row_separator_destroy;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
PROP_0,
|
|
|
|
|
PROP_MODEL,
|
|
|
|
|
PROP_ROOT,
|
2019-01-24 04:20:22 +00:00
|
|
|
|
PROP_CELL_AREA
|
2010-11-18 08:33:23 +00:00
|
|
|
|
};
|
|
|
|
|
|
2010-11-20 07:32:24 +00:00
|
|
|
|
enum {
|
|
|
|
|
SIGNAL_MENU_ACTIVATE,
|
|
|
|
|
N_SIGNALS
|
|
|
|
|
};
|
|
|
|
|
|
2010-11-22 06:53:19 +00:00
|
|
|
|
static guint tree_menu_signals[N_SIGNALS] = { 0 };
|
|
|
|
|
static GQuark tree_menu_path_quark = 0;
|
2010-11-20 07:32:24 +00:00
|
|
|
|
|
2010-12-15 08:17:45 +00:00
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkTreeMenu, _gtk_tree_menu, GTK_TYPE_MENU,
|
2013-06-27 19:02:52 +00:00
|
|
|
|
G_ADD_PRIVATE (GtkTreeMenu)
|
2011-01-04 15:14:25 +00:00
|
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
|
|
|
|
|
gtk_tree_menu_cell_layout_init));
|
2010-11-18 08:33:23 +00:00
|
|
|
|
|
|
|
|
|
static void
|
2010-12-15 08:17:45 +00:00
|
|
|
|
_gtk_tree_menu_init (GtkTreeMenu *menu)
|
2010-11-18 08:33:23 +00:00
|
|
|
|
{
|
2013-06-27 19:02:52 +00:00
|
|
|
|
menu->priv = _gtk_tree_menu_get_instance_private (menu);
|
2010-11-23 06:48:14 +00:00
|
|
|
|
|
2010-11-19 04:30:30 +00:00
|
|
|
|
gtk_menu_set_reserve_toggle_size (GTK_MENU (menu), FALSE);
|
2010-11-18 08:33:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-01-04 15:14:25 +00:00
|
|
|
|
static void
|
2010-12-15 08:17:45 +00:00
|
|
|
|
_gtk_tree_menu_class_init (GtkTreeMenuClass *class)
|
2010-11-18 08:33:23 +00:00
|
|
|
|
{
|
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
|
|
|
|
|
|
2010-11-22 06:53:19 +00:00
|
|
|
|
tree_menu_path_quark = g_quark_from_static_string ("gtk-tree-menu-path");
|
|
|
|
|
|
2014-06-26 22:22:42 +00:00
|
|
|
|
object_class->constructed = gtk_tree_menu_constructed;
|
2010-11-18 08:33:23 +00:00
|
|
|
|
object_class->dispose = gtk_tree_menu_dispose;
|
|
|
|
|
object_class->finalize = gtk_tree_menu_finalize;
|
|
|
|
|
object_class->set_property = gtk_tree_menu_set_property;
|
|
|
|
|
object_class->get_property = gtk_tree_menu_get_property;
|
|
|
|
|
|
2016-10-22 14:06:14 +00:00
|
|
|
|
widget_class->measure = gtk_tree_menu_measure;
|
2010-11-18 08:33:23 +00:00
|
|
|
|
|
2011-01-06 13:23:18 +00:00
|
|
|
|
/*
|
2010-12-03 09:28:54 +00:00
|
|
|
|
* GtkTreeMenu::menu-activate:
|
|
|
|
|
* @menu: a #GtkTreeMenu
|
|
|
|
|
* @path: the #GtkTreePath string for the item which was activated
|
|
|
|
|
* @user_data: the user data
|
|
|
|
|
*
|
|
|
|
|
* This signal is emitted to notify that a menu item in the #GtkTreeMenu
|
|
|
|
|
* was activated and provides the path string from the #GtkTreeModel
|
|
|
|
|
* to specify which row was selected.
|
|
|
|
|
*/
|
2010-11-20 07:32:24 +00:00
|
|
|
|
tree_menu_signals[SIGNAL_MENU_ACTIVATE] =
|
|
|
|
|
g_signal_new (I_("menu-activate"),
|
2011-01-04 15:14:25 +00:00
|
|
|
|
G_OBJECT_CLASS_TYPE (object_class),
|
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
|
0, /* No class closure here */
|
|
|
|
|
NULL, NULL,
|
2016-08-29 14:00:17 +00:00
|
|
|
|
NULL,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
G_TYPE_NONE, 1, G_TYPE_STRING);
|
2010-11-20 07:32:24 +00:00
|
|
|
|
|
2011-01-06 13:23:18 +00:00
|
|
|
|
/*
|
2010-12-03 09:28:54 +00:00
|
|
|
|
* GtkTreeMenu:model:
|
|
|
|
|
*
|
|
|
|
|
* The #GtkTreeModel from which the menu is constructed.
|
|
|
|
|
*/
|
2010-11-18 08:33:23 +00:00
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
|
PROP_MODEL,
|
|
|
|
|
g_param_spec_object ("model",
|
|
|
|
|
P_("TreeMenu model"),
|
|
|
|
|
P_("The model for the tree menu"),
|
|
|
|
|
GTK_TYPE_TREE_MODEL,
|
|
|
|
|
GTK_PARAM_READWRITE));
|
|
|
|
|
|
2011-01-06 13:23:18 +00:00
|
|
|
|
/*
|
2010-12-03 09:28:54 +00:00
|
|
|
|
* GtkTreeMenu:root:
|
|
|
|
|
*
|
|
|
|
|
* The #GtkTreePath that is the root for this menu, or %NULL.
|
|
|
|
|
*
|
|
|
|
|
* The #GtkTreeMenu recursively creates submenus for #GtkTreeModel
|
|
|
|
|
* rows that have children and the "root" for each menu is provided
|
|
|
|
|
* by the parent menu.
|
|
|
|
|
*
|
|
|
|
|
* If you dont provide a root for the #GtkTreeMenu then the whole
|
|
|
|
|
* model will be added to the menu. Specifying a root allows you
|
2011-02-23 09:26:21 +00:00
|
|
|
|
* to build a menu for a given #GtkTreePath and its children.
|
2010-12-03 09:28:54 +00:00
|
|
|
|
*/
|
2010-11-18 08:33:23 +00:00
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
|
PROP_ROOT,
|
|
|
|
|
g_param_spec_boxed ("root",
|
2011-01-04 15:14:25 +00:00
|
|
|
|
P_("TreeMenu root row"),
|
|
|
|
|
P_("The TreeMenu will display children of the "
|
|
|
|
|
"specified root"),
|
|
|
|
|
GTK_TYPE_TREE_PATH,
|
|
|
|
|
GTK_PARAM_READWRITE));
|
2010-11-18 08:33:23 +00:00
|
|
|
|
|
2011-01-06 13:23:18 +00:00
|
|
|
|
/*
|
2010-12-03 09:28:54 +00:00
|
|
|
|
* GtkTreeMenu:cell-area:
|
|
|
|
|
*
|
|
|
|
|
* The #GtkCellArea used to render cells in the menu items.
|
|
|
|
|
*
|
|
|
|
|
* You can provide a different cell area at object construction
|
|
|
|
|
* time, otherwise the #GtkTreeMenu will use a #GtkCellAreaBox.
|
|
|
|
|
*/
|
2010-11-23 06:48:14 +00:00
|
|
|
|
g_object_class_install_property (object_class,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
PROP_CELL_AREA,
|
|
|
|
|
g_param_spec_object ("cell-area",
|
|
|
|
|
P_("Cell Area"),
|
|
|
|
|
P_("The GtkCellArea used to layout cells"),
|
|
|
|
|
GTK_TYPE_CELL_AREA,
|
|
|
|
|
GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
2010-11-18 08:33:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/****************************************************************
|
|
|
|
|
* GObjectClass *
|
|
|
|
|
****************************************************************/
|
2014-06-26 22:22:42 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_tree_menu_constructed (GObject *object)
|
2010-11-18 08:33:23 +00:00
|
|
|
|
{
|
2014-06-26 22:22:42 +00:00
|
|
|
|
GtkTreeMenu *menu = GTK_TREE_MENU (object);
|
|
|
|
|
GtkTreeMenuPrivate *priv = menu->priv;
|
2010-11-18 08:33:23 +00:00
|
|
|
|
|
2014-06-26 22:22:42 +00:00
|
|
|
|
G_OBJECT_CLASS (_gtk_tree_menu_parent_class)->constructed (object);
|
2010-11-18 08:33:23 +00:00
|
|
|
|
|
|
|
|
|
if (!priv->area)
|
|
|
|
|
{
|
|
|
|
|
GtkCellArea *area = gtk_cell_area_box_new ();
|
|
|
|
|
|
|
|
|
|
gtk_tree_menu_set_area (menu, area);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
priv->context = gtk_cell_area_create_context (priv->area);
|
2010-11-24 04:49:12 +00:00
|
|
|
|
|
2011-01-04 15:14:25 +00:00
|
|
|
|
priv->size_changed_id =
|
2010-11-18 08:33:23 +00:00
|
|
|
|
g_signal_connect (priv->context, "notify",
|
2011-01-04 15:14:25 +00:00
|
|
|
|
G_CALLBACK (context_size_changed_cb), menu);
|
2010-11-18 08:33:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_tree_menu_dispose (GObject *object)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeMenu *menu;
|
|
|
|
|
GtkTreeMenuPrivate *priv;
|
|
|
|
|
|
|
|
|
|
menu = GTK_TREE_MENU (object);
|
|
|
|
|
priv = menu->priv;
|
|
|
|
|
|
2010-12-15 08:17:45 +00:00
|
|
|
|
_gtk_tree_menu_set_model (menu, NULL);
|
2010-11-18 08:33:23 +00:00
|
|
|
|
gtk_tree_menu_set_area (menu, NULL);
|
|
|
|
|
|
|
|
|
|
if (priv->context)
|
|
|
|
|
{
|
|
|
|
|
/* Disconnect signals */
|
|
|
|
|
g_signal_handler_disconnect (priv->context, priv->size_changed_id);
|
|
|
|
|
|
|
|
|
|
g_object_unref (priv->context);
|
|
|
|
|
priv->context = NULL;
|
|
|
|
|
priv->size_changed_id = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-15 08:17:45 +00:00
|
|
|
|
G_OBJECT_CLASS (_gtk_tree_menu_parent_class)->dispose (object);
|
2010-11-18 08:33:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_tree_menu_finalize (GObject *object)
|
|
|
|
|
{
|
2010-11-20 07:32:24 +00:00
|
|
|
|
GtkTreeMenu *menu;
|
|
|
|
|
GtkTreeMenuPrivate *priv;
|
|
|
|
|
|
|
|
|
|
menu = GTK_TREE_MENU (object);
|
|
|
|
|
priv = menu->priv;
|
|
|
|
|
|
2010-12-15 08:17:45 +00:00
|
|
|
|
_gtk_tree_menu_set_row_separator_func (menu, NULL, NULL, NULL);
|
2010-11-20 07:32:24 +00:00
|
|
|
|
|
2011-01-04 15:14:25 +00:00
|
|
|
|
if (priv->root)
|
2010-11-20 07:32:24 +00:00
|
|
|
|
gtk_tree_row_reference_free (priv->root);
|
2010-11-18 08:33:23 +00:00
|
|
|
|
|
2010-12-15 08:17:45 +00:00
|
|
|
|
G_OBJECT_CLASS (_gtk_tree_menu_parent_class)->finalize (object);
|
2010-11-18 08:33:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_tree_menu_set_property (GObject *object,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
guint prop_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
2010-11-18 08:33:23 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeMenu *menu = GTK_TREE_MENU (object);
|
|
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
|
{
|
|
|
|
|
case PROP_MODEL:
|
2010-12-15 08:17:45 +00:00
|
|
|
|
_gtk_tree_menu_set_model (menu, g_value_get_object (value));
|
2010-11-18 08:33:23 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PROP_ROOT:
|
2010-12-15 08:17:45 +00:00
|
|
|
|
_gtk_tree_menu_set_root (menu, g_value_get_boxed (value));
|
2010-11-18 08:33:23 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PROP_CELL_AREA:
|
|
|
|
|
/* Construct-only, can only be assigned once */
|
|
|
|
|
gtk_tree_menu_set_area (menu, (GtkCellArea *)g_value_get_object (value));
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_tree_menu_get_property (GObject *object,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
guint prop_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
2010-11-18 08:33:23 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeMenu *menu = GTK_TREE_MENU (object);
|
|
|
|
|
GtkTreeMenuPrivate *priv = menu->priv;
|
|
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
|
{
|
2010-11-23 03:11:52 +00:00
|
|
|
|
case PROP_MODEL:
|
|
|
|
|
g_value_set_object (value, priv->model);
|
|
|
|
|
break;
|
2011-01-04 15:14:25 +00:00
|
|
|
|
|
2010-11-23 03:11:52 +00:00
|
|
|
|
case PROP_ROOT:
|
|
|
|
|
g_value_set_boxed (value, priv->root);
|
|
|
|
|
break;
|
2011-01-04 15:14:25 +00:00
|
|
|
|
|
2010-11-23 03:11:52 +00:00
|
|
|
|
case PROP_CELL_AREA:
|
|
|
|
|
g_value_set_object (value, priv->area);
|
|
|
|
|
break;
|
2010-11-18 08:33:23 +00:00
|
|
|
|
|
2010-11-23 03:11:52 +00:00
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
2010-11-18 08:33:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/****************************************************************
|
|
|
|
|
* GtkWidgetClass *
|
|
|
|
|
****************************************************************/
|
|
|
|
|
|
|
|
|
|
/* We tell all the menu items to reserve space for the submenu
|
|
|
|
|
* indicator if there is at least one submenu, this way we ensure
|
|
|
|
|
* that every internal cell area gets allocated the
|
|
|
|
|
* same width (and requested height for the same appropriate width).
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
sync_reserve_submenu_size (GtkTreeMenu *menu)
|
|
|
|
|
{
|
|
|
|
|
GList *children, *l;
|
|
|
|
|
gboolean has_submenu = FALSE;
|
|
|
|
|
|
|
|
|
|
children = gtk_container_get_children (GTK_CONTAINER (menu));
|
|
|
|
|
for (l = children; l; l = l->next)
|
|
|
|
|
{
|
|
|
|
|
GtkMenuItem *item = l->data;
|
|
|
|
|
|
|
|
|
|
if (gtk_menu_item_get_submenu (item) != NULL)
|
2011-01-04 15:14:25 +00:00
|
|
|
|
{
|
|
|
|
|
has_submenu = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2010-11-18 08:33:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (l = children; l; l = l->next)
|
|
|
|
|
{
|
|
|
|
|
GtkMenuItem *item = l->data;
|
|
|
|
|
|
|
|
|
|
gtk_menu_item_set_reserve_indicator (item, has_submenu);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_list_free (children);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2016-10-22 14:06:14 +00:00
|
|
|
|
gtk_tree_menu_measure (GtkWidget *widget,
|
|
|
|
|
GtkOrientation orientation,
|
|
|
|
|
int for_size,
|
|
|
|
|
int *minimum,
|
|
|
|
|
int *natural,
|
|
|
|
|
int *minimum_baseline,
|
|
|
|
|
int *natural_baseline)
|
2010-11-18 08:33:23 +00:00
|
|
|
|
{
|
2016-10-22 14:06:14 +00:00
|
|
|
|
GtkTreeMenu *menu = GTK_TREE_MENU (widget);
|
2013-11-21 15:24:27 +00:00
|
|
|
|
GtkTreeMenuPrivate *priv = menu->priv;
|
|
|
|
|
|
|
|
|
|
/* We leave the requesting work up to the cellviews which operate in the same
|
|
|
|
|
* context, reserving space for the submenu indicator if any of the items have
|
|
|
|
|
* submenus ensures that every cellview will receive the same allocated width.
|
|
|
|
|
*
|
|
|
|
|
* Since GtkMenu does hieght-for-width correctly, we know that the width of
|
|
|
|
|
* every cell will be requested before the height-for-widths are requested.
|
|
|
|
|
*/
|
|
|
|
|
g_signal_handler_block (priv->context, priv->size_changed_id);
|
|
|
|
|
|
|
|
|
|
sync_reserve_submenu_size (menu);
|
|
|
|
|
|
2016-10-22 14:06:14 +00:00
|
|
|
|
GTK_WIDGET_CLASS (_gtk_tree_menu_parent_class)->measure (widget,
|
|
|
|
|
orientation,
|
|
|
|
|
for_size,
|
|
|
|
|
minimum, natural,
|
|
|
|
|
minimum_baseline, natural_baseline);
|
2013-11-21 15:24:27 +00:00
|
|
|
|
|
|
|
|
|
g_signal_handler_unblock (priv->context, priv->size_changed_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-11-18 08:33:23 +00:00
|
|
|
|
/****************************************************************
|
|
|
|
|
* GtkCellLayoutIface *
|
|
|
|
|
****************************************************************/
|
|
|
|
|
static void
|
|
|
|
|
gtk_tree_menu_cell_layout_init (GtkCellLayoutIface *iface)
|
|
|
|
|
{
|
2010-11-22 07:32:18 +00:00
|
|
|
|
iface->get_area = gtk_tree_menu_cell_layout_get_area;
|
2010-11-18 08:33:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GtkCellArea *
|
|
|
|
|
gtk_tree_menu_cell_layout_get_area (GtkCellLayout *layout)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeMenu *menu = GTK_TREE_MENU (layout);
|
|
|
|
|
GtkTreeMenuPrivate *priv = menu->priv;
|
|
|
|
|
|
|
|
|
|
return priv->area;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************
|
|
|
|
|
* TreeModel callbacks/populating menus *
|
|
|
|
|
****************************************************************/
|
2010-11-22 06:53:19 +00:00
|
|
|
|
static GtkWidget *
|
|
|
|
|
gtk_tree_menu_get_path_item (GtkTreeMenu *menu,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
GtkTreePath *search)
|
2010-11-22 06:53:19 +00:00
|
|
|
|
{
|
|
|
|
|
GtkWidget *item = NULL;
|
|
|
|
|
GList *children, *l;
|
|
|
|
|
|
|
|
|
|
children = gtk_container_get_children (GTK_CONTAINER (menu));
|
|
|
|
|
|
|
|
|
|
for (l = children; item == NULL && l != NULL; l = l->next)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *child = l->data;
|
|
|
|
|
GtkTreePath *path = NULL;
|
|
|
|
|
|
|
|
|
|
if (GTK_IS_SEPARATOR_MENU_ITEM (child))
|
2011-01-04 15:14:25 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeRowReference *row =
|
|
|
|
|
g_object_get_qdata (G_OBJECT (child), tree_menu_path_quark);
|
|
|
|
|
|
|
|
|
|
if (row)
|
|
|
|
|
{
|
|
|
|
|
path = gtk_tree_row_reference_get_path (row);
|
|
|
|
|
|
|
|
|
|
if (!path)
|
2011-02-23 09:26:21 +00:00
|
|
|
|
/* Return any first child where its row-reference became invalid,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
* this is because row-references get null paths before we recieve
|
|
|
|
|
* the "row-deleted" signal.
|
|
|
|
|
*/
|
|
|
|
|
item = child;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-05 01:09:20 +00:00
|
|
|
|
else
|
2011-01-04 15:14:25 +00:00
|
|
|
|
{
|
|
|
|
|
GtkWidget *view = gtk_bin_get_child (GTK_BIN (child));
|
2010-11-22 06:53:19 +00:00
|
|
|
|
|
2011-01-04 15:14:25 +00:00
|
|
|
|
/* It's always a cellview */
|
|
|
|
|
if (GTK_IS_CELL_VIEW (view))
|
|
|
|
|
path = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (view));
|
2010-11-24 11:00:10 +00:00
|
|
|
|
|
2011-01-04 15:14:25 +00:00
|
|
|
|
if (!path)
|
2011-02-23 09:26:21 +00:00
|
|
|
|
/* Return any first child where its row-reference became invalid,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
* this is because row-references get null paths before we recieve
|
|
|
|
|
* the "row-deleted" signal.
|
|
|
|
|
*/
|
|
|
|
|
item = child;
|
|
|
|
|
}
|
2010-11-22 06:53:19 +00:00
|
|
|
|
|
|
|
|
|
if (path)
|
2011-01-04 15:14:25 +00:00
|
|
|
|
{
|
|
|
|
|
if (gtk_tree_path_compare (search, path) == 0)
|
|
|
|
|
item = child;
|
2010-11-22 06:53:19 +00:00
|
|
|
|
|
2011-01-04 15:14:25 +00:00
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
}
|
2010-11-22 06:53:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_list_free (children);
|
|
|
|
|
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-24 04:49:12 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
gtk_tree_menu_path_in_menu (GtkTreeMenu *menu,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
GtkTreePath *path,
|
|
|
|
|
gboolean *header_item)
|
2010-11-22 06:53:19 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeMenuPrivate *priv = menu->priv;
|
2010-11-24 04:49:12 +00:00
|
|
|
|
gboolean in_menu = FALSE;
|
|
|
|
|
gboolean is_header = FALSE;
|
2010-11-22 06:53:19 +00:00
|
|
|
|
|
2010-11-24 04:49:12 +00:00
|
|
|
|
/* Check if the is in root of the model */
|
2010-12-08 13:30:22 +00:00
|
|
|
|
if (gtk_tree_path_get_depth (path) == 1 && !priv->root)
|
|
|
|
|
in_menu = TRUE;
|
2010-11-24 04:49:12 +00:00
|
|
|
|
/* If we are a submenu, compare the parent path */
|
2010-12-08 13:30:22 +00:00
|
|
|
|
else if (priv->root)
|
2010-11-22 06:53:19 +00:00
|
|
|
|
{
|
2010-11-24 11:00:10 +00:00
|
|
|
|
GtkTreePath *root_path = gtk_tree_row_reference_get_path (priv->root);
|
2010-12-08 13:30:22 +00:00
|
|
|
|
GtkTreePath *search_path = gtk_tree_path_copy (path);
|
2010-11-22 06:53:19 +00:00
|
|
|
|
|
2010-11-24 12:40:33 +00:00
|
|
|
|
if (root_path)
|
2011-01-04 15:14:25 +00:00
|
|
|
|
{
|
|
|
|
|
if (priv->menu_with_header &&
|
|
|
|
|
gtk_tree_path_compare (root_path, search_path) == 0)
|
|
|
|
|
{
|
|
|
|
|
in_menu = TRUE;
|
|
|
|
|
is_header = TRUE;
|
|
|
|
|
}
|
|
|
|
|
else if (gtk_tree_path_get_depth (search_path) > 1)
|
|
|
|
|
{
|
|
|
|
|
gtk_tree_path_up (search_path);
|
|
|
|
|
|
|
|
|
|
if (gtk_tree_path_compare (root_path, search_path) == 0)
|
|
|
|
|
in_menu = TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-11-22 06:53:19 +00:00
|
|
|
|
gtk_tree_path_free (root_path);
|
2010-12-08 13:30:22 +00:00
|
|
|
|
gtk_tree_path_free (search_path);
|
2010-11-22 06:53:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-11-24 04:49:12 +00:00
|
|
|
|
if (header_item)
|
|
|
|
|
*header_item = is_header;
|
|
|
|
|
|
|
|
|
|
return in_menu;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-24 11:00:10 +00:00
|
|
|
|
static GtkWidget *
|
2011-01-04 15:14:25 +00:00
|
|
|
|
gtk_tree_menu_path_needs_submenu (GtkTreeMenu *menu,
|
|
|
|
|
GtkTreePath *search)
|
2010-11-24 11:00:10 +00:00
|
|
|
|
{
|
|
|
|
|
GtkWidget *item = NULL;
|
|
|
|
|
GList *children, *l;
|
|
|
|
|
GtkTreePath *parent_path;
|
|
|
|
|
|
|
|
|
|
if (gtk_tree_path_get_depth (search) <= 1)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
parent_path = gtk_tree_path_copy (search);
|
|
|
|
|
gtk_tree_path_up (parent_path);
|
|
|
|
|
|
|
|
|
|
children = gtk_container_get_children (GTK_CONTAINER (menu));
|
|
|
|
|
|
|
|
|
|
for (l = children; item == NULL && l != NULL; l = l->next)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *child = l->data;
|
|
|
|
|
GtkTreePath *path = NULL;
|
|
|
|
|
|
|
|
|
|
/* Separators dont get submenus, if it already has a submenu then let
|
|
|
|
|
* the submenu handle inserted rows */
|
2011-01-04 15:14:25 +00:00
|
|
|
|
if (!GTK_IS_SEPARATOR_MENU_ITEM (child) &&
|
|
|
|
|
!gtk_menu_item_get_submenu (GTK_MENU_ITEM (child)))
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *view = gtk_bin_get_child (GTK_BIN (child));
|
2010-11-24 11:00:10 +00:00
|
|
|
|
|
2011-01-04 15:14:25 +00:00
|
|
|
|
/* It's always a cellview */
|
|
|
|
|
if (GTK_IS_CELL_VIEW (view))
|
|
|
|
|
path = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (view));
|
|
|
|
|
}
|
2010-11-24 11:00:10 +00:00
|
|
|
|
|
|
|
|
|
if (path)
|
2011-01-04 15:14:25 +00:00
|
|
|
|
{
|
|
|
|
|
if (gtk_tree_path_compare (parent_path, path) == 0)
|
|
|
|
|
item = child;
|
2010-11-24 11:00:10 +00:00
|
|
|
|
|
2011-01-04 15:14:25 +00:00
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
}
|
2010-11-24 11:00:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_list_free (children);
|
|
|
|
|
gtk_tree_path_free (parent_path);
|
|
|
|
|
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-24 12:40:33 +00:00
|
|
|
|
static GtkWidget *
|
|
|
|
|
find_empty_submenu (GtkTreeMenu *menu)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeMenuPrivate *priv = menu->priv;
|
|
|
|
|
GList *children, *l;
|
|
|
|
|
GtkWidget *submenu = NULL;
|
|
|
|
|
|
|
|
|
|
children = gtk_container_get_children (GTK_CONTAINER (menu));
|
|
|
|
|
|
|
|
|
|
for (l = children; submenu == NULL && l != NULL; l = l->next)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *child = l->data;
|
|
|
|
|
GtkTreePath *path = NULL;
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
|
|
/* Separators dont get submenus, if it already has a submenu then let
|
|
|
|
|
* the submenu handle inserted rows */
|
2016-09-05 01:09:20 +00:00
|
|
|
|
if (!GTK_IS_SEPARATOR_MENU_ITEM (child))
|
2011-01-04 15:14:25 +00:00
|
|
|
|
{
|
|
|
|
|
GtkWidget *view = gtk_bin_get_child (GTK_BIN (child));
|
2010-11-24 12:40:33 +00:00
|
|
|
|
|
2011-01-04 15:14:25 +00:00
|
|
|
|
/* It's always a cellview */
|
|
|
|
|
if (GTK_IS_CELL_VIEW (view))
|
|
|
|
|
path = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (view));
|
|
|
|
|
}
|
2010-11-24 12:40:33 +00:00
|
|
|
|
|
|
|
|
|
if (path)
|
2011-01-04 15:14:25 +00:00
|
|
|
|
{
|
|
|
|
|
if (gtk_tree_model_get_iter (priv->model, &iter, path) &&
|
|
|
|
|
!gtk_tree_model_iter_has_child (priv->model, &iter))
|
|
|
|
|
submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (child));
|
2010-11-24 12:40:33 +00:00
|
|
|
|
|
2011-01-04 15:14:25 +00:00
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
}
|
2010-11-24 12:40:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_list_free (children);
|
|
|
|
|
|
|
|
|
|
return submenu;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-24 04:49:12 +00:00
|
|
|
|
static void
|
|
|
|
|
row_inserted_cb (GtkTreeModel *model,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
GtkTreePath *path,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
GtkTreeMenu *menu)
|
2010-11-24 04:49:12 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeMenuPrivate *priv = menu->priv;
|
|
|
|
|
gint *indices, index, depth;
|
2010-11-24 11:00:10 +00:00
|
|
|
|
GtkWidget *item;
|
2010-11-24 04:49:12 +00:00
|
|
|
|
|
2010-11-22 06:53:19 +00:00
|
|
|
|
/* If the iter should be in this menu then go ahead and insert it */
|
2010-11-24 04:49:12 +00:00
|
|
|
|
if (gtk_tree_menu_path_in_menu (menu, path, NULL))
|
2010-11-22 06:53:19 +00:00
|
|
|
|
{
|
2019-01-24 04:20:22 +00:00
|
|
|
|
/* Get the index of the path for this depth */
|
|
|
|
|
indices = gtk_tree_path_get_indices (path);
|
|
|
|
|
depth = gtk_tree_path_get_depth (path);
|
|
|
|
|
index = indices[depth -1];
|
2011-01-04 15:14:25 +00:00
|
|
|
|
|
2019-01-24 04:20:22 +00:00
|
|
|
|
/* Menus with a header include a menuitem for its root node
|
|
|
|
|
* and a separator menu item */
|
|
|
|
|
if (priv->menu_with_header)
|
|
|
|
|
index += 2;
|
2011-01-04 15:14:25 +00:00
|
|
|
|
|
2019-01-24 04:20:22 +00:00
|
|
|
|
item = gtk_tree_menu_create_item (menu, iter, FALSE);
|
|
|
|
|
gtk_menu_shell_insert (GTK_MENU_SHELL (menu), item, index);
|
2011-01-04 15:14:25 +00:00
|
|
|
|
|
2019-01-24 04:20:22 +00:00
|
|
|
|
/* Resize everything */
|
|
|
|
|
gtk_cell_area_context_reset (menu->priv->context);
|
2010-11-22 06:53:19 +00:00
|
|
|
|
}
|
2010-11-24 11:00:10 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Create submenus for iters if we need to */
|
|
|
|
|
item = gtk_tree_menu_path_needs_submenu (menu, path);
|
|
|
|
|
if (item)
|
2011-01-04 15:14:25 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreePath *item_path = gtk_tree_path_copy (path);
|
2010-11-24 11:00:10 +00:00
|
|
|
|
|
2011-01-04 15:14:25 +00:00
|
|
|
|
gtk_tree_path_up (item_path);
|
|
|
|
|
gtk_tree_menu_create_submenu (menu, item, item_path);
|
|
|
|
|
gtk_tree_path_free (item_path);
|
|
|
|
|
}
|
2010-11-24 11:00:10 +00:00
|
|
|
|
}
|
2010-11-22 06:53:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
row_deleted_cb (GtkTreeModel *model,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
GtkTreePath *path,
|
|
|
|
|
GtkTreeMenu *menu)
|
2010-11-22 06:53:19 +00:00
|
|
|
|
{
|
|
|
|
|
GtkWidget *item;
|
|
|
|
|
|
2011-01-04 15:14:25 +00:00
|
|
|
|
/* If it's the header item we leave it to the parent menu
|
2010-11-24 04:49:12 +00:00
|
|
|
|
* to remove us from its menu
|
|
|
|
|
*/
|
2010-11-24 11:00:10 +00:00
|
|
|
|
item = gtk_tree_menu_get_path_item (menu, path);
|
|
|
|
|
|
|
|
|
|
if (item)
|
2010-11-22 06:53:19 +00:00
|
|
|
|
{
|
2019-01-24 04:20:22 +00:00
|
|
|
|
/* Get rid of the deleted item */
|
|
|
|
|
gtk_widget_destroy (item);
|
2011-01-04 15:14:25 +00:00
|
|
|
|
|
2019-01-24 04:20:22 +00:00
|
|
|
|
/* Resize everything */
|
|
|
|
|
gtk_cell_area_context_reset (menu->priv->context);
|
2010-11-22 06:53:19 +00:00
|
|
|
|
}
|
2011-01-04 15:14:25 +00:00
|
|
|
|
else
|
2010-11-24 12:40:33 +00:00
|
|
|
|
{
|
|
|
|
|
/* It's up to the parent menu to destroy a child menu that becomes empty
|
|
|
|
|
* since the topmost menu belongs to the user and is allowed to have no contents */
|
|
|
|
|
GtkWidget *submenu = find_empty_submenu (menu);
|
|
|
|
|
if (submenu)
|
2011-01-04 15:14:25 +00:00
|
|
|
|
gtk_widget_destroy (submenu);
|
2010-11-24 12:40:33 +00:00
|
|
|
|
}
|
2010-11-22 06:53:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
row_reordered_cb (GtkTreeModel *model,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
GtkTreePath *path,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
gint *new_order,
|
|
|
|
|
GtkTreeMenu *menu)
|
2010-11-22 06:53:19 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeMenuPrivate *priv = menu->priv;
|
|
|
|
|
gboolean this_menu = FALSE;
|
|
|
|
|
|
2011-01-18 15:41:35 +00:00
|
|
|
|
if (gtk_tree_path_get_depth (path) == 0 && !priv->root)
|
2010-11-22 06:53:19 +00:00
|
|
|
|
this_menu = TRUE;
|
|
|
|
|
else if (priv->root)
|
|
|
|
|
{
|
|
|
|
|
GtkTreePath *root_path =
|
2011-01-04 15:14:25 +00:00
|
|
|
|
gtk_tree_row_reference_get_path (priv->root);
|
2010-11-22 06:53:19 +00:00
|
|
|
|
|
|
|
|
|
if (gtk_tree_path_compare (root_path, path) == 0)
|
2011-01-04 15:14:25 +00:00
|
|
|
|
this_menu = TRUE;
|
2010-11-22 06:53:19 +00:00
|
|
|
|
|
|
|
|
|
gtk_tree_path_free (root_path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this_menu)
|
2010-11-23 06:48:14 +00:00
|
|
|
|
rebuild_menu (menu);
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-04 15:14:25 +00:00
|
|
|
|
static gint
|
2010-11-23 06:48:14 +00:00
|
|
|
|
menu_item_position (GtkTreeMenu *menu,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
GtkWidget *item)
|
2010-11-23 06:48:14 +00:00
|
|
|
|
{
|
2018-10-20 14:19:11 +00:00
|
|
|
|
GList *children;
|
2010-11-23 06:48:14 +00:00
|
|
|
|
gint position;
|
|
|
|
|
|
|
|
|
|
children = gtk_container_get_children (GTK_CONTAINER (menu));
|
2018-10-20 14:19:11 +00:00
|
|
|
|
position = g_list_index (children, item);
|
2010-11-23 06:48:14 +00:00
|
|
|
|
g_list_free (children);
|
|
|
|
|
|
|
|
|
|
return position;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
row_changed_cb (GtkTreeModel *model,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
GtkTreePath *path,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
GtkTreeMenu *menu)
|
2010-11-23 06:48:14 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeMenuPrivate *priv = menu->priv;
|
|
|
|
|
gboolean is_separator = FALSE;
|
|
|
|
|
GtkWidget *item;
|
2019-05-31 03:20:50 +00:00
|
|
|
|
GList *children;
|
2010-11-23 06:48:14 +00:00
|
|
|
|
|
|
|
|
|
item = gtk_tree_menu_get_path_item (menu, path);
|
|
|
|
|
|
|
|
|
|
if (priv->root)
|
2010-11-22 06:53:19 +00:00
|
|
|
|
{
|
2010-11-23 06:48:14 +00:00
|
|
|
|
GtkTreePath *root_path =
|
2011-01-04 15:14:25 +00:00
|
|
|
|
gtk_tree_row_reference_get_path (priv->root);
|
|
|
|
|
|
2010-11-24 09:14:36 +00:00
|
|
|
|
if (root_path && gtk_tree_path_compare (root_path, path) == 0)
|
2011-01-04 15:14:25 +00:00
|
|
|
|
{
|
2015-07-18 03:16:07 +00:00
|
|
|
|
if (item)
|
2011-01-04 15:14:25 +00:00
|
|
|
|
{
|
|
|
|
|
/* Destroy the header item and then the following separator */
|
|
|
|
|
gtk_widget_destroy (item);
|
2019-05-31 03:20:50 +00:00
|
|
|
|
children = gtk_menu_shell_get_items (GTK_MENU_SHELL (menu));
|
|
|
|
|
gtk_widget_destroy (children->data);
|
|
|
|
|
g_list_free (children);
|
2011-01-04 15:14:25 +00:00
|
|
|
|
|
|
|
|
|
priv->menu_with_header = FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gtk_tree_path_free (root_path);
|
|
|
|
|
}
|
2010-11-23 06:48:14 +00:00
|
|
|
|
}
|
2011-01-04 15:14:25 +00:00
|
|
|
|
|
2010-11-23 06:48:14 +00:00
|
|
|
|
if (item)
|
|
|
|
|
{
|
2019-01-24 04:20:22 +00:00
|
|
|
|
if (priv->row_separator_func)
|
|
|
|
|
is_separator = priv->row_separator_func (model, iter, priv->row_separator_data);
|
2011-01-04 15:14:25 +00:00
|
|
|
|
|
2019-01-24 04:20:22 +00:00
|
|
|
|
if (is_separator != GTK_IS_SEPARATOR_MENU_ITEM (item))
|
|
|
|
|
{
|
|
|
|
|
gint position = menu_item_position (menu, item);
|
2011-01-04 15:14:25 +00:00
|
|
|
|
|
2019-01-24 04:20:22 +00:00
|
|
|
|
gtk_widget_destroy (item);
|
|
|
|
|
item = gtk_tree_menu_create_item (menu, iter, FALSE);
|
|
|
|
|
gtk_menu_shell_insert (GTK_MENU_SHELL (menu), item, position);
|
2011-01-04 15:14:25 +00:00
|
|
|
|
}
|
2010-11-22 06:53:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-18 08:33:23 +00:00
|
|
|
|
static void
|
|
|
|
|
context_size_changed_cb (GtkCellAreaContext *context,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
GParamSpec *pspec,
|
|
|
|
|
GtkWidget *menu)
|
2010-11-18 08:33:23 +00:00
|
|
|
|
{
|
|
|
|
|
if (!strcmp (pspec->name, "minimum-width") ||
|
|
|
|
|
!strcmp (pspec->name, "natural-width") ||
|
|
|
|
|
!strcmp (pspec->name, "minimum-height") ||
|
|
|
|
|
!strcmp (pspec->name, "natural-height"))
|
2010-11-20 07:32:24 +00:00
|
|
|
|
gtk_widget_queue_resize (menu);
|
2010-11-18 08:33:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-11-24 04:49:12 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
area_is_sensitive (GtkCellArea *area)
|
|
|
|
|
{
|
|
|
|
|
GList *cells, *list;
|
|
|
|
|
gboolean sensitive = FALSE;
|
2011-01-04 15:14:25 +00:00
|
|
|
|
|
2010-11-24 04:49:12 +00:00
|
|
|
|
cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (area));
|
|
|
|
|
|
|
|
|
|
for (list = cells; list; list = list->next)
|
|
|
|
|
{
|
|
|
|
|
g_object_get (list->data, "sensitive", &sensitive, NULL);
|
2011-01-04 15:14:25 +00:00
|
|
|
|
|
2010-11-24 04:49:12 +00:00
|
|
|
|
if (sensitive)
|
2011-01-04 15:14:25 +00:00
|
|
|
|
break;
|
2010-11-24 04:49:12 +00:00
|
|
|
|
}
|
|
|
|
|
g_list_free (cells);
|
|
|
|
|
|
|
|
|
|
return sensitive;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
area_apply_attributes_cb (GtkCellArea *area,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
GtkTreeModel *tree_model,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
gboolean is_expander,
|
|
|
|
|
gboolean is_expanded,
|
|
|
|
|
GtkTreeMenu *menu)
|
2010-11-24 04:49:12 +00:00
|
|
|
|
{
|
|
|
|
|
/* If the menu for this iter has a submenu */
|
|
|
|
|
GtkTreeMenuPrivate *priv = menu->priv;
|
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
GtkWidget *item;
|
|
|
|
|
gboolean is_header;
|
|
|
|
|
gboolean sensitive;
|
2019-05-31 03:20:50 +00:00
|
|
|
|
GList *children;
|
2010-11-24 04:49:12 +00:00
|
|
|
|
|
|
|
|
|
path = gtk_tree_model_get_path (tree_model, iter);
|
|
|
|
|
|
|
|
|
|
if (gtk_tree_menu_path_in_menu (menu, path, &is_header))
|
|
|
|
|
{
|
|
|
|
|
item = gtk_tree_menu_get_path_item (menu, path);
|
|
|
|
|
|
|
|
|
|
/* If there is no submenu, go ahead and update item sensitivity,
|
|
|
|
|
* items with submenus are always sensitive */
|
2010-11-24 09:14:36 +00:00
|
|
|
|
if (item && !gtk_menu_item_get_submenu (GTK_MENU_ITEM (item)))
|
2011-01-04 15:14:25 +00:00
|
|
|
|
{
|
|
|
|
|
sensitive = area_is_sensitive (priv->area);
|
|
|
|
|
|
|
|
|
|
gtk_widget_set_sensitive (item, sensitive);
|
|
|
|
|
|
|
|
|
|
if (is_header)
|
|
|
|
|
{
|
|
|
|
|
/* For header items we need to set the sensitivity
|
|
|
|
|
* of the following separator item
|
|
|
|
|
*/
|
2019-05-31 03:20:50 +00:00
|
|
|
|
children = gtk_menu_shell_get_items (GTK_MENU_SHELL (menu));
|
|
|
|
|
if (children && children->next)
|
2011-01-04 15:14:25 +00:00
|
|
|
|
{
|
2019-05-31 03:20:50 +00:00
|
|
|
|
GtkWidget *separator = children->next->data;
|
2011-01-04 15:14:25 +00:00
|
|
|
|
|
|
|
|
|
gtk_widget_set_sensitive (separator, sensitive);
|
|
|
|
|
}
|
2019-05-31 03:20:50 +00:00
|
|
|
|
g_list_free (children);
|
2011-01-04 15:14:25 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2010-11-24 04:49:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-18 08:33:23 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_tree_menu_set_area (GtkTreeMenu *menu,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
GtkCellArea *area)
|
2010-11-18 08:33:23 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeMenuPrivate *priv = menu->priv;
|
|
|
|
|
|
|
|
|
|
if (priv->area)
|
2010-11-24 04:49:12 +00:00
|
|
|
|
{
|
|
|
|
|
g_signal_handler_disconnect (priv->area,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
priv->apply_attributes_id);
|
2010-11-24 04:49:12 +00:00
|
|
|
|
priv->apply_attributes_id = 0;
|
|
|
|
|
|
|
|
|
|
g_object_unref (priv->area);
|
|
|
|
|
}
|
2010-11-18 08:33:23 +00:00
|
|
|
|
|
|
|
|
|
priv->area = area;
|
|
|
|
|
|
|
|
|
|
if (priv->area)
|
2010-11-24 04:49:12 +00:00
|
|
|
|
{
|
|
|
|
|
g_object_ref_sink (priv->area);
|
|
|
|
|
|
|
|
|
|
priv->apply_attributes_id =
|
2011-01-04 15:14:25 +00:00
|
|
|
|
g_signal_connect (priv->area, "apply-attributes",
|
|
|
|
|
G_CALLBACK (area_apply_attributes_cb), menu);
|
2010-11-24 04:49:12 +00:00
|
|
|
|
}
|
2010-11-18 08:33:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-11-24 11:00:10 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_tree_menu_create_submenu (GtkTreeMenu *menu,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
GtkWidget *item,
|
|
|
|
|
GtkTreePath *path)
|
2010-11-24 11:00:10 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeMenuPrivate *priv = menu->priv;
|
|
|
|
|
GtkWidget *view;
|
|
|
|
|
GtkWidget *submenu;
|
|
|
|
|
|
|
|
|
|
view = gtk_bin_get_child (GTK_BIN (item));
|
|
|
|
|
gtk_cell_view_set_draw_sensitive (GTK_CELL_VIEW (view), TRUE);
|
|
|
|
|
|
2010-12-15 08:17:45 +00:00
|
|
|
|
submenu = _gtk_tree_menu_new_with_area (priv->area);
|
2010-11-24 11:00:10 +00:00
|
|
|
|
|
2011-01-04 15:14:25 +00:00
|
|
|
|
_gtk_tree_menu_set_row_separator_func (GTK_TREE_MENU (submenu),
|
|
|
|
|
priv->row_separator_func,
|
|
|
|
|
priv->row_separator_data,
|
|
|
|
|
priv->row_separator_destroy);
|
2010-11-24 11:00:10 +00:00
|
|
|
|
|
|
|
|
|
gtk_tree_menu_set_model_internal (GTK_TREE_MENU (submenu), priv->model);
|
2010-12-15 08:17:45 +00:00
|
|
|
|
_gtk_tree_menu_set_root (GTK_TREE_MENU (submenu), path);
|
2010-11-24 11:00:10 +00:00
|
|
|
|
gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
|
2011-01-04 15:14:25 +00:00
|
|
|
|
|
|
|
|
|
g_signal_connect (submenu, "menu-activate",
|
|
|
|
|
G_CALLBACK (submenu_activated_cb), menu);
|
2010-11-24 11:00:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-11-18 08:33:23 +00:00
|
|
|
|
static GtkWidget *
|
|
|
|
|
gtk_tree_menu_create_item (GtkTreeMenu *menu,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
gboolean header_item)
|
2010-11-18 08:33:23 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeMenuPrivate *priv = menu->priv;
|
|
|
|
|
GtkWidget *item, *view;
|
|
|
|
|
GtkTreePath *path;
|
2010-11-22 06:53:19 +00:00
|
|
|
|
gboolean is_separator = FALSE;
|
2010-11-18 08:33:23 +00:00
|
|
|
|
|
|
|
|
|
path = gtk_tree_model_get_path (priv->model, iter);
|
|
|
|
|
|
2010-11-22 06:53:19 +00:00
|
|
|
|
if (priv->row_separator_func)
|
2011-01-04 15:14:25 +00:00
|
|
|
|
is_separator =
|
2010-11-22 06:53:19 +00:00
|
|
|
|
priv->row_separator_func (priv->model, iter,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
priv->row_separator_data);
|
2010-11-18 08:33:23 +00:00
|
|
|
|
|
2010-11-22 06:53:19 +00:00
|
|
|
|
if (is_separator)
|
|
|
|
|
{
|
|
|
|
|
item = gtk_separator_menu_item_new ();
|
2010-11-18 08:33:23 +00:00
|
|
|
|
|
2010-11-22 06:53:19 +00:00
|
|
|
|
g_object_set_qdata_full (G_OBJECT (item),
|
2011-01-04 15:14:25 +00:00
|
|
|
|
tree_menu_path_quark,
|
|
|
|
|
gtk_tree_row_reference_new (priv->model, path),
|
|
|
|
|
(GDestroyNotify)gtk_tree_row_reference_free);
|
2010-11-22 06:53:19 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
view = gtk_cell_view_new_with_context (priv->area, priv->context);
|
|
|
|
|
item = gtk_menu_item_new ();
|
2011-01-04 15:14:25 +00:00
|
|
|
|
|
2010-11-22 06:53:19 +00:00
|
|
|
|
gtk_cell_view_set_model (GTK_CELL_VIEW (view), priv->model);
|
|
|
|
|
gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (view), path);
|
2011-01-04 15:14:25 +00:00
|
|
|
|
|
2010-11-22 06:53:19 +00:00
|
|
|
|
gtk_container_add (GTK_CONTAINER (item), view);
|
2011-01-04 15:14:25 +00:00
|
|
|
|
|
2010-11-22 06:53:19 +00:00
|
|
|
|
g_signal_connect (item, "activate", G_CALLBACK (item_activated_cb), menu);
|
|
|
|
|
|
|
|
|
|
/* Add a GtkTreeMenu submenu to render the children of this row */
|
|
|
|
|
if (header_item == FALSE &&
|
2011-01-04 15:14:25 +00:00
|
|
|
|
gtk_tree_model_iter_has_child (priv->model, iter))
|
|
|
|
|
gtk_tree_menu_create_submenu (menu, item, path);
|
2010-11-22 06:53:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
2010-11-20 07:32:24 +00:00
|
|
|
|
|
2010-11-18 08:33:23 +00:00
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-04 15:14:25 +00:00
|
|
|
|
static inline void
|
2010-11-23 06:48:14 +00:00
|
|
|
|
rebuild_menu (GtkTreeMenu *menu)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeMenuPrivate *priv = menu->priv;
|
|
|
|
|
|
|
|
|
|
/* Destroy all the menu items */
|
2011-01-04 15:14:25 +00:00
|
|
|
|
gtk_container_foreach (GTK_CONTAINER (menu),
|
|
|
|
|
(GtkCallback) gtk_widget_destroy, NULL);
|
|
|
|
|
|
2010-11-23 06:48:14 +00:00
|
|
|
|
/* Populate */
|
|
|
|
|
if (priv->model)
|
|
|
|
|
gtk_tree_menu_populate (menu);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-11-18 08:33:23 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_tree_menu_populate (GtkTreeMenu *menu)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeMenuPrivate *priv = menu->priv;
|
|
|
|
|
GtkTreePath *path = NULL;
|
|
|
|
|
GtkTreeIter parent;
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
gboolean valid = FALSE;
|
2019-01-24 04:20:22 +00:00
|
|
|
|
GtkWidget *menu_item;
|
2010-11-18 08:33:23 +00:00
|
|
|
|
|
|
|
|
|
if (!priv->model)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (priv->root)
|
|
|
|
|
path = gtk_tree_row_reference_get_path (priv->root);
|
|
|
|
|
|
|
|
|
|
if (path)
|
|
|
|
|
{
|
|
|
|
|
if (gtk_tree_model_get_iter (priv->model, &parent, path))
|
2015-07-18 03:16:07 +00:00
|
|
|
|
valid = gtk_tree_model_iter_children (priv->model, &iter, &parent);
|
2011-01-04 15:14:25 +00:00
|
|
|
|
|
2010-11-18 08:33:23 +00:00
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
}
|
|
|
|
|
else
|
2010-11-23 03:11:52 +00:00
|
|
|
|
{
|
|
|
|
|
valid = gtk_tree_model_iter_children (priv->model, &iter, NULL);
|
|
|
|
|
}
|
2010-11-18 08:33:23 +00:00
|
|
|
|
|
|
|
|
|
/* Create a menu item for every row at the current depth, add a GtkTreeMenu
|
|
|
|
|
* submenu for iters/items that have children */
|
|
|
|
|
while (valid)
|
|
|
|
|
{
|
2010-11-22 06:53:19 +00:00
|
|
|
|
menu_item = gtk_tree_menu_create_item (menu, &iter, FALSE);
|
2010-11-23 06:48:14 +00:00
|
|
|
|
|
2010-11-18 08:33:23 +00:00
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
|
|
|
|
|
|
|
|
|
|
valid = gtk_tree_model_iter_next (priv->model, &iter);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-20 07:32:24 +00:00
|
|
|
|
static void
|
|
|
|
|
item_activated_cb (GtkMenuItem *item,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
GtkTreeMenu *menu)
|
2010-11-20 07:32:24 +00:00
|
|
|
|
{
|
|
|
|
|
GtkCellView *view;
|
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
gchar *path_str;
|
|
|
|
|
|
|
|
|
|
/* Only activate leafs, not parents */
|
|
|
|
|
if (!gtk_menu_item_get_submenu (item))
|
|
|
|
|
{
|
|
|
|
|
view = GTK_CELL_VIEW (gtk_bin_get_child (GTK_BIN (item)));
|
|
|
|
|
path = gtk_cell_view_get_displayed_row (view);
|
|
|
|
|
path_str = gtk_tree_path_to_string (path);
|
2011-01-04 15:14:25 +00:00
|
|
|
|
|
2010-11-20 07:32:24 +00:00
|
|
|
|
g_signal_emit (menu, tree_menu_signals[SIGNAL_MENU_ACTIVATE], 0, path_str);
|
2011-01-04 15:14:25 +00:00
|
|
|
|
|
2010-11-20 07:32:24 +00:00
|
|
|
|
g_free (path_str);
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
submenu_activated_cb (GtkTreeMenu *submenu,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
const gchar *path,
|
|
|
|
|
GtkTreeMenu *menu)
|
2010-11-20 07:32:24 +00:00
|
|
|
|
{
|
|
|
|
|
g_signal_emit (menu, tree_menu_signals[SIGNAL_MENU_ACTIVATE], 0, path);
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-24 09:14:36 +00:00
|
|
|
|
/* Sets the model without rebuilding the menu, prevents
|
|
|
|
|
* infinite recursion while building submenus (we wait
|
|
|
|
|
* until the root is set and then build the menu) */
|
|
|
|
|
static void
|
|
|
|
|
gtk_tree_menu_set_model_internal (GtkTreeMenu *menu,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
GtkTreeModel *model)
|
2010-11-18 08:33:23 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeMenuPrivate *priv;
|
|
|
|
|
|
|
|
|
|
priv = menu->priv;
|
|
|
|
|
|
|
|
|
|
if (priv->model != model)
|
|
|
|
|
{
|
|
|
|
|
if (priv->model)
|
2011-01-04 15:14:25 +00:00
|
|
|
|
{
|
|
|
|
|
/* Disconnect signals */
|
|
|
|
|
g_signal_handler_disconnect (priv->model,
|
|
|
|
|
priv->row_inserted_id);
|
|
|
|
|
g_signal_handler_disconnect (priv->model,
|
|
|
|
|
priv->row_deleted_id);
|
|
|
|
|
g_signal_handler_disconnect (priv->model,
|
|
|
|
|
priv->row_reordered_id);
|
|
|
|
|
g_signal_handler_disconnect (priv->model,
|
|
|
|
|
priv->row_changed_id);
|
|
|
|
|
priv->row_inserted_id = 0;
|
|
|
|
|
priv->row_deleted_id = 0;
|
|
|
|
|
priv->row_reordered_id = 0;
|
|
|
|
|
priv->row_changed_id = 0;
|
|
|
|
|
|
|
|
|
|
g_object_unref (priv->model);
|
|
|
|
|
}
|
2010-11-18 08:33:23 +00:00
|
|
|
|
|
|
|
|
|
priv->model = model;
|
|
|
|
|
|
|
|
|
|
if (priv->model)
|
2011-01-04 15:14:25 +00:00
|
|
|
|
{
|
|
|
|
|
g_object_ref (priv->model);
|
|
|
|
|
|
|
|
|
|
/* Connect signals */
|
|
|
|
|
priv->row_inserted_id = g_signal_connect (priv->model, "row-inserted",
|
|
|
|
|
G_CALLBACK (row_inserted_cb), menu);
|
|
|
|
|
priv->row_deleted_id = g_signal_connect (priv->model, "row-deleted",
|
|
|
|
|
G_CALLBACK (row_deleted_cb), menu);
|
|
|
|
|
priv->row_reordered_id = g_signal_connect (priv->model, "rows-reordered",
|
|
|
|
|
G_CALLBACK (row_reordered_cb), menu);
|
|
|
|
|
priv->row_changed_id = g_signal_connect (priv->model, "row-changed",
|
|
|
|
|
G_CALLBACK (row_changed_cb), menu);
|
|
|
|
|
}
|
2010-11-18 08:33:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-24 09:14:36 +00:00
|
|
|
|
/****************************************************************
|
|
|
|
|
* API *
|
|
|
|
|
****************************************************************/
|
2010-12-03 09:28:54 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2010-12-15 08:17:45 +00:00
|
|
|
|
* _gtk_tree_menu_new:
|
2010-12-03 09:28:54 +00:00
|
|
|
|
*
|
|
|
|
|
* Creates a new #GtkTreeMenu.
|
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: A newly created #GtkTreeMenu with no model or root.
|
2010-12-03 09:28:54 +00:00
|
|
|
|
*/
|
2010-11-24 09:14:36 +00:00
|
|
|
|
GtkWidget *
|
2010-12-15 08:17:45 +00:00
|
|
|
|
_gtk_tree_menu_new (void)
|
2010-11-24 09:14:36 +00:00
|
|
|
|
{
|
|
|
|
|
return (GtkWidget *)g_object_new (GTK_TYPE_TREE_MENU, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-06 13:23:18 +00:00
|
|
|
|
/*
|
2010-12-15 08:17:45 +00:00
|
|
|
|
* _gtk_tree_menu_new_with_area:
|
2010-12-03 09:28:54 +00:00
|
|
|
|
* @area: the #GtkCellArea to use to render cells in the menu
|
|
|
|
|
*
|
2011-02-23 09:26:21 +00:00
|
|
|
|
* Creates a new #GtkTreeMenu using @area to render its cells.
|
2010-12-03 09:28:54 +00:00
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: A newly created #GtkTreeMenu with no model or root.
|
2010-12-03 09:28:54 +00:00
|
|
|
|
*/
|
2010-11-24 09:14:36 +00:00
|
|
|
|
GtkWidget *
|
2010-12-15 08:17:45 +00:00
|
|
|
|
_gtk_tree_menu_new_with_area (GtkCellArea *area)
|
2010-11-24 09:14:36 +00:00
|
|
|
|
{
|
2011-01-04 15:14:25 +00:00
|
|
|
|
return (GtkWidget *)g_object_new (GTK_TYPE_TREE_MENU,
|
|
|
|
|
"cell-area", area,
|
|
|
|
|
NULL);
|
2010-11-24 09:14:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-01-06 13:23:18 +00:00
|
|
|
|
/*
|
2010-12-15 08:17:45 +00:00
|
|
|
|
* _gtk_tree_menu_new_full:
|
2010-12-03 09:28:54 +00:00
|
|
|
|
* @area: (allow-none): the #GtkCellArea to use to render cells in the menu, or %NULL.
|
2019-08-25 12:52:24 +00:00
|
|
|
|
* @model: (allow-none): the #GtkTreeModel to build the menu hierarchy from, or %NULL.
|
2010-12-03 09:28:54 +00:00
|
|
|
|
* @root: (allow-none): the #GtkTreePath indicating the root row for this menu, or %NULL.
|
|
|
|
|
*
|
2011-02-23 09:26:21 +00:00
|
|
|
|
* Creates a new #GtkTreeMenu hierarchy from the provided @model and @root using @area to render its cells.
|
2010-12-03 09:28:54 +00:00
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: A newly created #GtkTreeMenu.
|
2010-12-03 09:28:54 +00:00
|
|
|
|
*/
|
2010-11-24 09:14:36 +00:00
|
|
|
|
GtkWidget *
|
2010-12-15 08:17:45 +00:00
|
|
|
|
_gtk_tree_menu_new_full (GtkCellArea *area,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
GtkTreeModel *model,
|
|
|
|
|
GtkTreePath *root)
|
2010-11-24 09:14:36 +00:00
|
|
|
|
{
|
2011-01-04 15:14:25 +00:00
|
|
|
|
return (GtkWidget *)g_object_new (GTK_TYPE_TREE_MENU,
|
|
|
|
|
"cell-area", area,
|
|
|
|
|
"model", model,
|
|
|
|
|
"root", root,
|
|
|
|
|
NULL);
|
2010-11-24 09:14:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-01-06 13:23:18 +00:00
|
|
|
|
/*
|
2010-12-15 08:17:45 +00:00
|
|
|
|
* _gtk_tree_menu_set_model:
|
2010-12-03 09:28:54 +00:00
|
|
|
|
* @menu: a #GtkTreeMenu
|
|
|
|
|
* @model: (allow-none): the #GtkTreeModel to build the menu hierarchy from, or %NULL.
|
|
|
|
|
*
|
2019-08-25 12:52:24 +00:00
|
|
|
|
* Sets @model to be used to build the menu hierarhcy.
|
2010-12-03 09:28:54 +00:00
|
|
|
|
*/
|
2010-11-24 09:14:36 +00:00
|
|
|
|
void
|
2010-12-15 08:17:45 +00:00
|
|
|
|
_gtk_tree_menu_set_model (GtkTreeMenu *menu,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
GtkTreeModel *model)
|
2010-11-24 09:14:36 +00:00
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_TREE_MENU (menu));
|
|
|
|
|
g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
|
|
|
|
|
|
|
|
|
|
gtk_tree_menu_set_model_internal (menu, model);
|
|
|
|
|
|
|
|
|
|
rebuild_menu (menu);
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-06 13:23:18 +00:00
|
|
|
|
/*
|
2010-12-15 08:17:45 +00:00
|
|
|
|
* _gtk_tree_menu_get_model:
|
2010-12-03 09:28:54 +00:00
|
|
|
|
* @menu: a #GtkTreeMenu
|
|
|
|
|
*
|
2019-08-25 12:52:24 +00:00
|
|
|
|
* Gets the @model currently used for the menu hierarhcy.
|
2010-12-03 09:28:54 +00:00
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: (transfer none): the #GtkTreeModel which is used
|
2014-02-07 18:01:26 +00:00
|
|
|
|
* for @menu’s hierarchy.
|
2010-12-03 09:28:54 +00:00
|
|
|
|
*/
|
2010-11-18 08:33:23 +00:00
|
|
|
|
GtkTreeModel *
|
2010-12-15 08:17:45 +00:00
|
|
|
|
_gtk_tree_menu_get_model (GtkTreeMenu *menu)
|
2010-11-18 08:33:23 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeMenuPrivate *priv;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_MENU (menu), NULL);
|
|
|
|
|
|
|
|
|
|
priv = menu->priv;
|
|
|
|
|
|
|
|
|
|
return priv->model;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-06 13:23:18 +00:00
|
|
|
|
/*
|
2010-12-15 08:17:45 +00:00
|
|
|
|
* _gtk_tree_menu_set_root:
|
2010-12-03 09:28:54 +00:00
|
|
|
|
* @menu: a #GtkTreeMenu
|
2010-12-03 09:44:23 +00:00
|
|
|
|
* @path: (allow-none): the #GtkTreePath which is the root of @menu, or %NULL.
|
2010-12-03 09:28:54 +00:00
|
|
|
|
*
|
2014-02-07 18:01:26 +00:00
|
|
|
|
* Sets the root of a @menu’s hierarchy to be @path. @menu must already
|
2010-12-03 09:44:23 +00:00
|
|
|
|
* have a model set and @path must point to a valid path inside the model.
|
2010-12-03 09:28:54 +00:00
|
|
|
|
*/
|
2010-11-18 08:33:23 +00:00
|
|
|
|
void
|
2011-01-18 02:55:13 +00:00
|
|
|
|
_gtk_tree_menu_set_root (GtkTreeMenu *menu,
|
|
|
|
|
GtkTreePath *path)
|
2010-11-18 08:33:23 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeMenuPrivate *priv;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_TREE_MENU (menu));
|
2010-11-19 04:30:30 +00:00
|
|
|
|
g_return_if_fail (menu->priv->model != NULL || path == NULL);
|
2010-11-18 08:33:23 +00:00
|
|
|
|
|
|
|
|
|
priv = menu->priv;
|
|
|
|
|
|
2011-01-04 15:14:25 +00:00
|
|
|
|
if (priv->root)
|
2010-11-18 08:33:23 +00:00
|
|
|
|
gtk_tree_row_reference_free (priv->root);
|
|
|
|
|
|
|
|
|
|
if (path)
|
|
|
|
|
priv->root = gtk_tree_row_reference_new (priv->model, path);
|
|
|
|
|
else
|
|
|
|
|
priv->root = NULL;
|
|
|
|
|
|
2010-11-23 06:48:14 +00:00
|
|
|
|
rebuild_menu (menu);
|
2010-11-18 08:33:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-01-06 13:23:18 +00:00
|
|
|
|
/*
|
2010-12-15 08:17:45 +00:00
|
|
|
|
* _gtk_tree_menu_get_root:
|
2010-12-03 09:28:54 +00:00
|
|
|
|
* @menu: a #GtkTreeMenu
|
|
|
|
|
*
|
2014-02-07 18:01:26 +00:00
|
|
|
|
* Gets the @root path for @menu’s hierarchy, or returns %NULL if @menu
|
2019-08-25 12:52:24 +00:00
|
|
|
|
* has no model or is building a hierarchy for the entire model. *
|
2010-12-03 09:28:54 +00:00
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: (transfer full) (allow-none): A newly created #GtkTreePath
|
2010-12-03 09:28:54 +00:00
|
|
|
|
* pointing to the root of @menu which must be freed with gtk_tree_path_free().
|
|
|
|
|
*/
|
2010-11-18 08:33:23 +00:00
|
|
|
|
GtkTreePath *
|
2010-12-15 08:17:45 +00:00
|
|
|
|
_gtk_tree_menu_get_root (GtkTreeMenu *menu)
|
2010-11-18 08:33:23 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeMenuPrivate *priv;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_MENU (menu), NULL);
|
|
|
|
|
|
|
|
|
|
priv = menu->priv;
|
|
|
|
|
|
|
|
|
|
if (priv->root)
|
|
|
|
|
return gtk_tree_row_reference_get_path (priv->root);
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-06 13:23:18 +00:00
|
|
|
|
/*
|
2010-12-15 08:17:45 +00:00
|
|
|
|
* _gtk_tree_menu_get_row_separator_func:
|
2010-12-03 09:28:54 +00:00
|
|
|
|
* @menu: a #GtkTreeMenu
|
2011-01-06 13:23:18 +00:00
|
|
|
|
*
|
2010-12-03 09:28:54 +00:00
|
|
|
|
* Gets the current #GtkTreeViewRowSeparatorFunc separator function.
|
2011-01-06 13:23:18 +00:00
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: the current row separator function.
|
2010-12-03 09:28:54 +00:00
|
|
|
|
*/
|
2010-11-23 06:48:14 +00:00
|
|
|
|
GtkTreeViewRowSeparatorFunc
|
2010-12-15 08:17:45 +00:00
|
|
|
|
_gtk_tree_menu_get_row_separator_func (GtkTreeMenu *menu)
|
2010-11-23 06:48:14 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeMenuPrivate *priv;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_MENU (menu), NULL);
|
|
|
|
|
|
|
|
|
|
priv = menu->priv;
|
|
|
|
|
|
|
|
|
|
return priv->row_separator_func;
|
|
|
|
|
}
|
2010-11-23 03:11:52 +00:00
|
|
|
|
|
2011-01-06 13:23:18 +00:00
|
|
|
|
/*
|
2010-12-15 08:17:45 +00:00
|
|
|
|
* _gtk_tree_menu_set_row_separator_func:
|
2010-12-03 09:28:54 +00:00
|
|
|
|
* @menu: a #GtkTreeMenu
|
|
|
|
|
* @func: (allow-none): a #GtkTreeViewRowSeparatorFunc, or %NULL to unset the separator function.
|
|
|
|
|
* @data: (allow-none): user data to pass to @func, or %NULL
|
|
|
|
|
* @destroy: (allow-none): destroy notifier for @data, or %NULL
|
2011-01-06 13:23:18 +00:00
|
|
|
|
*
|
2010-12-03 09:28:54 +00:00
|
|
|
|
* Sets the row separator function, which is used to determine
|
|
|
|
|
* whether a row should be drawn as a separator. If the row separator
|
|
|
|
|
* function is %NULL, no separators are drawn. This is the default value.
|
|
|
|
|
*/
|
2010-11-18 08:33:23 +00:00
|
|
|
|
void
|
2010-12-15 08:17:45 +00:00
|
|
|
|
_gtk_tree_menu_set_row_separator_func (GtkTreeMenu *menu,
|
2011-01-04 15:14:25 +00:00
|
|
|
|
GtkTreeViewRowSeparatorFunc func,
|
|
|
|
|
gpointer data,
|
|
|
|
|
GDestroyNotify destroy)
|
2010-11-18 08:33:23 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeMenuPrivate *priv;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_TREE_MENU (menu));
|
|
|
|
|
|
|
|
|
|
priv = menu->priv;
|
|
|
|
|
|
|
|
|
|
if (priv->row_separator_destroy)
|
|
|
|
|
priv->row_separator_destroy (priv->row_separator_data);
|
|
|
|
|
|
|
|
|
|
priv->row_separator_func = func;
|
|
|
|
|
priv->row_separator_data = data;
|
|
|
|
|
priv->row_separator_destroy = destroy;
|
2010-11-20 07:32:24 +00:00
|
|
|
|
|
2010-11-23 06:48:14 +00:00
|
|
|
|
rebuild_menu (menu);
|
2010-11-18 08:33:23 +00:00
|
|
|
|
}
|