Remove GtkUIManager

This commit is contained in:
Timm Bäder 2016-10-16 19:28:11 +02:00 committed by Benjamin Otte
parent 62b2949fa2
commit d963ede668
15 changed files with 14 additions and 4360 deletions

View File

@ -2091,42 +2091,6 @@ GtkMenuItemPrivate
gtk_menu_item_get_type
</SECTION>
<SECTION>
<FILE>gtkuimanager</FILE>
<TITLE>GtkUIManager</TITLE>
GtkUIManager
gtk_ui_manager_new
gtk_ui_manager_set_add_tearoffs
gtk_ui_manager_get_add_tearoffs
gtk_ui_manager_insert_action_group
gtk_ui_manager_remove_action_group
gtk_ui_manager_get_action_groups
gtk_ui_manager_get_accel_group
gtk_ui_manager_get_widget
gtk_ui_manager_get_toplevels
gtk_ui_manager_get_action
gtk_ui_manager_add_ui_from_resource
gtk_ui_manager_add_ui_from_string
gtk_ui_manager_add_ui_from_file
gtk_ui_manager_new_merge_id
GtkUIManagerItemType
gtk_ui_manager_add_ui
gtk_ui_manager_remove_ui
gtk_ui_manager_get_ui
gtk_ui_manager_ensure_update
<SUBSECTION Standard>
GTK_TYPE_UI_MANAGER
GTK_UI_MANAGER
GTK_UI_MANAGER_CLASS
GTK_IS_UI_MANAGER
GTK_IS_UI_MANAGER_CLASS
GTK_UI_MANAGER_GET_CLASS
GtkUIManagerClass
<SUBSECTION Private>
gtk_ui_manager_get_type
GtkUIManagerPrivate
</SECTION>
<SECTION>
<FILE>gtkmenushell</FILE>
<TITLE>GtkMenuShell</TITLE>

View File

@ -3,8 +3,7 @@ deprecated_h_sources = \
deprecated/gtkactiongroup.h \
deprecated/gtkgradient.h \
deprecated/gtkrecentaction.h \
deprecated/gtksymboliccolor.h \
deprecated/gtkuimanager.h
deprecated/gtksymboliccolor.h
deprecated_private_h_sources = \
deprecated/gtkgradientprivate.h \
@ -15,5 +14,4 @@ deprecated_c_sources = \
deprecated/gtkactiongroup.c \
deprecated/gtkgradient.c \
deprecated/gtkrecentaction.c \
deprecated/gtksymboliccolor.c \
deprecated/gtkuimanager.c
deprecated/gtksymboliccolor.c

File diff suppressed because it is too large Load Diff

View File

@ -1,185 +0,0 @@
/*
* GTK - The GIMP Toolkit
* Copyright (C) 1998, 1999 Red Hat, Inc.
* All rights reserved.
*
* 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
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Author: James Henstridge <james@daa.com.au>
*
* Modified by the GTK+ Team and others 2003. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#ifndef __GTK_UI_MANAGER_H__
#define __GTK_UI_MANAGER_H__
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
#error "Only <gtk/gtk.h> can be included directly."
#endif
#include <gtk/gtkaccelgroup.h>
#include <gtk/gtkwidget.h>
#include <gtk/deprecated/gtkaction.h>
#include <gtk/deprecated/gtkactiongroup.h>
G_BEGIN_DECLS
#define GTK_TYPE_UI_MANAGER (gtk_ui_manager_get_type ())
#define GTK_UI_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_UI_MANAGER, GtkUIManager))
#define GTK_UI_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_UI_MANAGER, GtkUIManagerClass))
#define GTK_IS_UI_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_UI_MANAGER))
#define GTK_IS_UI_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_UI_MANAGER))
#define GTK_UI_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GTK_TYPE_UI_MANAGER, GtkUIManagerClass))
typedef struct _GtkUIManager GtkUIManager;
typedef struct _GtkUIManagerClass GtkUIManagerClass;
typedef struct _GtkUIManagerPrivate GtkUIManagerPrivate;
struct _GtkUIManager {
GObject parent;
/*< private >*/
GtkUIManagerPrivate *private_data;
};
struct _GtkUIManagerClass {
GObjectClass parent_class;
/* Signals */
void (* add_widget) (GtkUIManager *manager,
GtkWidget *widget);
void (* actions_changed) (GtkUIManager *manager);
void (* connect_proxy) (GtkUIManager *manager,
GtkAction *action,
GtkWidget *proxy);
void (* disconnect_proxy) (GtkUIManager *manager,
GtkAction *action,
GtkWidget *proxy);
void (* pre_activate) (GtkUIManager *manager,
GtkAction *action);
void (* post_activate) (GtkUIManager *manager,
GtkAction *action);
/* Virtual functions */
GtkWidget * (* get_widget) (GtkUIManager *manager,
const gchar *path);
GtkAction * (* get_action) (GtkUIManager *manager,
const gchar *path);
/* Padding for future expansion */
void (*_gtk_reserved1) (void);
void (*_gtk_reserved2) (void);
void (*_gtk_reserved3) (void);
void (*_gtk_reserved4) (void);
};
/**
* GtkUIManagerItemType:
* @GTK_UI_MANAGER_AUTO: Pick the type of the UI element according to context.
* @GTK_UI_MANAGER_MENUBAR: Create a menubar.
* @GTK_UI_MANAGER_MENU: Create a menu.
* @GTK_UI_MANAGER_TOOLBAR: Create a toolbar.
* @GTK_UI_MANAGER_PLACEHOLDER: Insert a placeholder.
* @GTK_UI_MANAGER_POPUP: Create a popup menu.
* @GTK_UI_MANAGER_MENUITEM: Create a menuitem.
* @GTK_UI_MANAGER_TOOLITEM: Create a toolitem.
* @GTK_UI_MANAGER_SEPARATOR: Create a separator.
* @GTK_UI_MANAGER_ACCELERATOR: Install an accelerator.
* @GTK_UI_MANAGER_POPUP_WITH_ACCELS: Same as %GTK_UI_MANAGER_POPUP, but the
* actions accelerators are shown.
*
* These enumeration values are used by gtk_ui_manager_add_ui() to determine
* what UI element to create.
*
* Deprecated: 3.10
*/
typedef enum {
GTK_UI_MANAGER_AUTO = 0,
GTK_UI_MANAGER_MENUBAR = 1 << 0,
GTK_UI_MANAGER_MENU = 1 << 1,
GTK_UI_MANAGER_TOOLBAR = 1 << 2,
GTK_UI_MANAGER_PLACEHOLDER = 1 << 3,
GTK_UI_MANAGER_POPUP = 1 << 4,
GTK_UI_MANAGER_MENUITEM = 1 << 5,
GTK_UI_MANAGER_TOOLITEM = 1 << 6,
GTK_UI_MANAGER_SEPARATOR = 1 << 7,
GTK_UI_MANAGER_ACCELERATOR = 1 << 8,
GTK_UI_MANAGER_POPUP_WITH_ACCELS = 1 << 9
} GtkUIManagerItemType;
GDK_DEPRECATED_IN_3_10
GType gtk_ui_manager_get_type (void) G_GNUC_CONST;
GDK_DEPRECATED_IN_3_10
GtkUIManager *gtk_ui_manager_new (void);
GDK_DEPRECATED_IN_3_10
void gtk_ui_manager_insert_action_group (GtkUIManager *manager,
GtkActionGroup *action_group,
gint pos);
GDK_DEPRECATED_IN_3_10
void gtk_ui_manager_remove_action_group (GtkUIManager *manager,
GtkActionGroup *action_group);
GDK_DEPRECATED_IN_3_10
GList *gtk_ui_manager_get_action_groups (GtkUIManager *manager);
GDK_DEPRECATED_IN_3_10
GtkAccelGroup *gtk_ui_manager_get_accel_group (GtkUIManager *manager);
GDK_DEPRECATED_IN_3_10
GtkWidget *gtk_ui_manager_get_widget (GtkUIManager *manager,
const gchar *path);
GDK_DEPRECATED_IN_3_10
GSList *gtk_ui_manager_get_toplevels (GtkUIManager *manager,
GtkUIManagerItemType types);
GDK_DEPRECATED_IN_3_10
GtkAction *gtk_ui_manager_get_action (GtkUIManager *manager,
const gchar *path);
GDK_DEPRECATED_IN_3_10
guint gtk_ui_manager_add_ui_from_string (GtkUIManager *manager,
const gchar *buffer,
gssize length,
GError **error);
GDK_DEPRECATED_IN_3_10
guint gtk_ui_manager_add_ui_from_file (GtkUIManager *manager,
const gchar *filename,
GError **error);
GDK_DEPRECATED_IN_3_10
guint gtk_ui_manager_add_ui_from_resource(GtkUIManager *manager,
const gchar *resource_path,
GError **error);
GDK_DEPRECATED_IN_3_10
void gtk_ui_manager_add_ui (GtkUIManager *manager,
guint merge_id,
const gchar *path,
const gchar *name,
const gchar *action,
GtkUIManagerItemType type,
gboolean top);
GDK_DEPRECATED_IN_3_10
void gtk_ui_manager_remove_ui (GtkUIManager *manager,
guint merge_id);
GDK_DEPRECATED_IN_3_10
gchar *gtk_ui_manager_get_ui (GtkUIManager *manager);
GDK_DEPRECATED_IN_3_10
void gtk_ui_manager_ensure_update (GtkUIManager *manager);
GDK_DEPRECATED_IN_3_10
guint gtk_ui_manager_new_merge_id (GtkUIManager *manager);
G_END_DECLS
#endif /* __GTK_UI_MANAGER_H__ */

View File

@ -249,7 +249,6 @@
#include <gtk/deprecated/gtkgradient.h>
#include <gtk/deprecated/gtkrecentaction.h>
#include <gtk/deprecated/gtksymboliccolor.h>
#include <gtk/deprecated/gtkuimanager.h>
#endif /* GTK_DISABLE_DEPRECATED */
#include <gtk/gtk-autocleanups.h>

View File

@ -44,10 +44,7 @@
*
* A #GtkAccelGroup represents a group of keyboard accelerators,
* typically attached to a toplevel #GtkWindow (with
* gtk_window_add_accel_group()). Usually you wont need to create a
* #GtkAccelGroup directly; instead, when using #GtkUIManager, GTK+
* automatically sets up the accelerators for your menus in the ui
* managers #GtkAccelGroup.
* gtk_window_add_accel_group()).
*
* Note that accelerators are different from
* mnemonics. Accelerators are shortcuts for

View File

@ -41,11 +41,11 @@
* SECTION:gtkaccelmap
* @Short_description: Loadable keyboard accelerator specifications
* @Title: Accelerator Maps
* @See_also: #GtkAccelGroup, #GtkAccelKey, #GtkUIManager, gtk_widget_set_accel_path(), gtk_menu_item_set_accel_path()
* @See_also: #GtkAccelGroup, #GtkAccelKey, gtk_widget_set_accel_path(), gtk_menu_item_set_accel_path()
*
* Accelerator maps are used to define runtime configurable accelerators.
* Functions for manipulating them are are usually used by higher level
* convenience mechanisms like #GtkUIManager and are thus considered
* convenience mechanisms and are thus considered
* low-level. Youll want to use them if youre manually creating menus that
* should have user-configurable accelerators.
*

View File

@ -57,8 +57,8 @@ typedef struct _GtkBuildableIface GtkBuildableIface;
* (i.e. setting the #GtkWidget:visible property) until the whole interface
* is created.
* @construct_child: Constructs a child of a buildable that has been
* specified as constructor in the UI definition. #GtkUIManager implements
* this to reference to a widget created in a <ui> tag which is outside
* specified as constructor in the UI definition. This can be used to
* reference a widget created in a <ui> tag which is outside
* of the normal GtkBuilder UI definition hierarchy. A reference to the
* constructed object is returned and becomes owned by the caller.
* @custom_tag_start: Implement this if the buildable needs to parse

View File

@ -6229,11 +6229,9 @@ destroy_accel_path (gpointer data)
* to be saved for future use. (See gtk_accel_map_save().)
*
* This function is a low level function that would most likely
* be used by a menu creation system like #GtkUIManager. If you
* use #GtkUIManager, setting up accelerator paths will be done
* automatically.
* be used by a menu creation system.
*
* Even when you you arent using #GtkUIManager, if you only want to
* If you only want to
* set up accelerators on menu items gtk_menu_item_set_accel_path()
* provides a somewhat more convenient interface.
*
@ -13578,7 +13576,7 @@ gtk_widget_get_no_show_all (GtkWidget *widget)
* calls to gtk_widget_show_all() will affect this widget.
*
* This is mostly for use in constructing widget hierarchies with externally
* controlled visibility, see #GtkUIManager.
* controlled visibility.
*
* Since: 2.4
**/

View File

@ -124,7 +124,6 @@ noinst_PROGRAMS = $(TEST_PROGS) \
testverticalcells \
treestoretest \
testxinerama \
testmerge \
testactions \
testgrouping \
testtooltips \
@ -250,7 +249,6 @@ testtreesort_DEPENDENCIES = $(DEPS)
testverticalcells_DEPENDENCIES = $(DEPS)
treestoretest_DEPENDENCIES = $(TEST_DEPS)
testxinerama_DEPENDENCIES = $(TEST_DEPS)
testmerge_DEPENDENCIES = $(TEST_DEPS)
testactions_DEPENDENCIES = $(TEST_DEPS)
testgrouping_DEPENDENCIES = $(TEST_DEPS)
testtooltips_DEPENDENCIES = $(TEST_DEPS)
@ -374,9 +372,6 @@ testprint_SOURCES = \
testspinbutton_SOURCES = \
testspinbutton.c
testmerge_SOURCES = \
testmerge.c
testactions_SOURCES = \
testactions.c
@ -510,9 +505,6 @@ EXTRA_DIST += \
check-y.xpm \
check-n.xpm \
test.xpm \
merge-1.ui \
merge-2.ui \
merge-3.ui \
gnome-textfile.png \
testsplitheaders.ui \
makefile.msc \

View File

@ -181,156 +181,13 @@ static const gchar *ui_info =
" <menuitem name=\"poppaste\" action=\"paste\" />\n"
" </popup>\n";
static void
add_widget (GtkUIManager *merge,
GtkWidget *widget,
GtkContainer *container)
{
gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE);
gtk_widget_show (widget);
if (GTK_IS_TOOLBAR (widget))
{
toolbar = GTK_TOOLBAR (widget);
gtk_toolbar_set_show_arrow (toolbar, TRUE);
}
}
static guint ui_id = 0;
static GtkActionGroup *dag = NULL;
static void
ensure_update (GtkUIManager *manager)
{
GTimer *timer;
double seconds;
gulong microsecs;
timer = g_timer_new ();
g_timer_start (timer);
gtk_ui_manager_ensure_update (manager);
g_timer_stop (timer);
seconds = g_timer_elapsed (timer, &microsecs);
g_timer_destroy (timer);
g_print ("Time: %fs\n", seconds);
}
static void
add_cb (GtkWidget *button,
GtkUIManager *manager)
{
GtkWidget *spinbutton;
GtkAction *action;
int i, num;
char *name, *label;
if (ui_id != 0 || dag != NULL)
return;
spinbutton = g_object_get_data (G_OBJECT (button), "spinbutton");
num = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (spinbutton));
dag = gtk_action_group_new ("DynamicActions");
gtk_ui_manager_insert_action_group (manager, dag, 0);
ui_id = gtk_ui_manager_new_merge_id (manager);
for (i = 0; i < num; i++)
{
name = g_strdup_printf ("DynAction%u", i);
label = g_strdup_printf ("Dynamic Item %d", i);
action = g_object_new (GTK_TYPE_ACTION,
"name", name,
"label", label,
NULL);
gtk_action_group_add_action (dag, action);
g_object_unref (action);
gtk_ui_manager_add_ui (manager, ui_id, "/menubar/DynamicMenu",
name, name,
GTK_UI_MANAGER_MENUITEM, FALSE);
}
ensure_update (manager);
}
static void
remove_cb (GtkWidget *button,
GtkUIManager *manager)
{
if (ui_id == 0 || dag == NULL)
return;
gtk_ui_manager_remove_ui (manager, ui_id);
ensure_update (manager);
ui_id = 0;
gtk_ui_manager_remove_action_group (manager, dag);
g_object_unref (dag);
dag = NULL;
}
static void
create_window (GtkActionGroup *action_group)
{
GtkUIManager *merge;
GtkWidget *window;
GtkWidget *box;
GtkWidget *hbox, *spinbutton, *button;
GError *error = NULL;
merge = gtk_ui_manager_new ();
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size (GTK_WINDOW (window), -1, -1);
gtk_window_set_title (GTK_WINDOW (window), "Action Test");
g_signal_connect_swapped (window, "destroy", G_CALLBACK (g_object_unref), merge);
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add (GTK_CONTAINER (window), box);
gtk_widget_show (box);
gtk_ui_manager_insert_action_group (merge, action_group, 0);
g_signal_connect (merge, "add_widget", G_CALLBACK (add_widget), box);
gtk_window_add_accel_group (GTK_WINDOW (window),
gtk_ui_manager_get_accel_group (merge));
if (!gtk_ui_manager_add_ui_from_string (merge, ui_info, -1, &error))
{
g_message ("building menus failed: %s", error->message);
g_error_free (error);
}
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_box_pack_end (GTK_BOX (box), hbox, FALSE, FALSE);
gtk_widget_show (hbox);
spinbutton = gtk_spin_button_new_with_range (100, 10000, 100);
gtk_box_pack_start (GTK_BOX (hbox), spinbutton, FALSE, FALSE);
gtk_widget_show (spinbutton);
button = gtk_button_new_with_label ("Add");
gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE);
gtk_widget_show (button);
g_object_set_data (G_OBJECT (button), "spinbutton", spinbutton);
g_signal_connect (button, "clicked", G_CALLBACK (add_cb), merge);
button = gtk_button_new_with_label ("Remove");
gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE);
gtk_widget_show (button);
g_signal_connect (button, "clicked", G_CALLBACK (remove_cb), merge);
gtk_widget_show (window);
}
}
int
main (int argc, char **argv)
@ -362,21 +219,6 @@ main (int argc, char **argv)
gtk_main ();
#ifdef DEBUG_UI_MANAGER
{
GList *action;
for (action = gtk_action_group_list_actions (action_group);
action;
action = action->next)
{
GtkAction *a = action->data;
g_print ("action %s ref count %d\n",
gtk_action_get_name (a), G_OBJECT (a)->ref_count);
}
}
#endif
g_object_unref (action);
g_object_unref (action_group);

View File

@ -1,678 +0,0 @@
/* testmerge.c
* Copyright (C) 2003 James Henstridge
*
* 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
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <stdio.h>
#include <string.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#define GDK_DISABLE_DEPRECATION_WARNINGS
#include <gtk/gtk.h>
#ifndef STDOUT_FILENO
#define STDOUT_FILENO 1
#endif
struct { const gchar *filename; guint merge_id; } merge_ids[] = {
{ "merge-1.ui", 0 },
{ "merge-2.ui", 0 },
{ "merge-3.ui", 0 }
};
static void
dump_tree (GtkWidget *button,
GtkUIManager *merge)
{
gchar *dump;
dump = gtk_ui_manager_get_ui (merge);
g_message ("%s", dump);
g_free (dump);
}
static void
dump_accels (void)
{
gtk_accel_map_save_fd (STDOUT_FILENO);
}
static void
print_toplevel (GtkWidget *widget, gpointer user_data)
{
g_print ("%s\n", G_OBJECT_TYPE_NAME (widget));
}
static void
dump_toplevels (GtkWidget *button,
GtkUIManager *merge)
{
GSList *toplevels;
toplevels = gtk_ui_manager_get_toplevels (merge,
GTK_UI_MANAGER_MENUBAR |
GTK_UI_MANAGER_TOOLBAR |
GTK_UI_MANAGER_POPUP);
g_slist_foreach (toplevels, (GFunc) print_toplevel, NULL);
g_slist_free (toplevels);
}
static gint
delayed_toggle_dynamic (GtkUIManager *merge)
{
GtkAction *dyn;
static GtkActionGroup *dynamic = NULL;
static guint merge_id = 0;
if (!dynamic)
{
dynamic = gtk_action_group_new ("dynamic");
gtk_ui_manager_insert_action_group (merge, dynamic, 0);
dyn = g_object_new (GTK_TYPE_ACTION,
"name", "dyn1",
"label", "Dynamic action 1",
"stock_id", NULL,
NULL);
gtk_action_group_add_action (dynamic, dyn);
dyn = g_object_new (GTK_TYPE_ACTION,
"name", "dyn2",
"label", "Dynamic action 2",
"stock_id", NULL,
NULL);
gtk_action_group_add_action (dynamic, dyn);
}
if (merge_id == 0)
{
merge_id = gtk_ui_manager_new_merge_id (merge);
gtk_ui_manager_add_ui (merge, merge_id, "/toolbar1/ToolbarPlaceholder",
"dyn1", "dyn1", 0, 0);
gtk_ui_manager_add_ui (merge, merge_id, "/toolbar1/ToolbarPlaceholder",
"dynsep", NULL, GTK_UI_MANAGER_SEPARATOR, 0);
gtk_ui_manager_add_ui (merge, merge_id, "/toolbar1/ToolbarPlaceholder",
"dyn2", "dyn2", 0, 0);
gtk_ui_manager_add_ui (merge, merge_id, "/menubar/EditMenu",
"dyn1menu", "dyn1", GTK_UI_MANAGER_MENU, 0);
gtk_ui_manager_add_ui (merge, merge_id, "/menubar/EditMenu/dyn1menu",
"dyn1", "dyn1", GTK_UI_MANAGER_MENUITEM, 0);
gtk_ui_manager_add_ui (merge, merge_id, "/menubar/EditMenu/dyn1menu/dyn1",
"dyn2", "dyn2", GTK_UI_MANAGER_AUTO, FALSE);
}
else
{
gtk_ui_manager_remove_ui (merge, merge_id);
merge_id = 0;
}
return FALSE;
}
static void
toggle_dynamic (GtkWidget *button,
GtkUIManager *merge)
{
gdk_threads_add_timeout (2000, (GSourceFunc)delayed_toggle_dynamic, merge);
}
static void
activate_action (GtkAction *action)
{
const gchar *name = gtk_action_get_name (action);
const gchar *typename = G_OBJECT_TYPE_NAME (action);
g_message ("Action %s (type=%s) activated", name, typename);
}
static GtkActionEntry entries[] = {
{ "FileMenuAction", NULL, "_File" },
{ "EditMenuAction", NULL, "_Edit" },
{ "HelpMenuAction", NULL, "_Help" },
{ "JustifyMenuAction", NULL, "_Justify" },
{ "EmptyMenu1Action", NULL, "Empty 1" },
{ "EmptyMenu2Action", NULL, "Empty 2" },
{ "Test", NULL, "Test" },
{ "QuitAction", NULL, NULL, "<control>q", "Quit", G_CALLBACK (gtk_main_quit) },
{ "NewAction", NULL, NULL, "<control>n", "Create something", G_CALLBACK (activate_action) },
{ "New2Action", NULL, NULL, "<control>m", "Create something else", G_CALLBACK (activate_action) },
{ "OpenAction", NULL, NULL, NULL, "Open it", G_CALLBACK (activate_action) },
{ "CutAction", NULL, NULL, "<control>x", "Knive", G_CALLBACK (activate_action) },
{ "CopyAction", NULL, NULL, "<control>c", "Copy", G_CALLBACK (activate_action) },
{ "PasteAction", NULL, NULL, "<control>v", "Paste", G_CALLBACK (activate_action) },
{ "AboutAction", NULL, "_About", NULL, "About", G_CALLBACK (activate_action) },
};
static guint n_entries = G_N_ELEMENTS (entries);
enum {
JUSTIFY_LEFT,
JUSTIFY_CENTER,
JUSTIFY_RIGHT,
JUSTIFY_FILL
};
static void
add_widget (GtkUIManager *merge,
GtkWidget *widget,
GtkBox *box)
{
gtk_box_pack_start (box, widget, FALSE, FALSE);
gtk_widget_show (widget);
}
static void
toggle_merge (GtkWidget *button,
GtkUIManager *merge)
{
gint mergenum;
mergenum = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button), "mergenum"));
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
{
GError *err = NULL;
g_message ("merging %s", merge_ids[mergenum].filename);
merge_ids[mergenum].merge_id =
gtk_ui_manager_add_ui_from_file (merge, merge_ids[mergenum].filename, &err);
if (err != NULL)
{
GtkWidget *dialog;
dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_widget_get_toplevel (button)),
0, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK,
"could not merge %s: %s", merge_ids[mergenum].filename,
err->message);
g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL);
gtk_widget_show (dialog);
g_clear_error (&err);
}
}
else
{
g_message ("unmerging %s (merge_id=%u)", merge_ids[mergenum].filename,
merge_ids[mergenum].merge_id);
gtk_ui_manager_remove_ui (merge, merge_ids[mergenum].merge_id);
}
}
static void
set_name_func (GtkTreeViewColumn *tree_column,
GtkCellRenderer *cell,
GtkTreeModel *tree_model,
GtkTreeIter *iter,
gpointer data)
{
GtkAction *action;
char *name;
gtk_tree_model_get (tree_model, iter, 0, &action, -1);
g_object_get (action, "name", &name, NULL);
g_object_set (cell, "text", name, NULL);
g_free (name);
g_object_unref (action);
}
static void
set_sensitive_func (GtkTreeViewColumn *tree_column,
GtkCellRenderer *cell,
GtkTreeModel *tree_model,
GtkTreeIter *iter,
gpointer data)
{
GtkAction *action;
gboolean sensitive;
gtk_tree_model_get (tree_model, iter, 0, &action, -1);
g_object_get (action, "sensitive", &sensitive, NULL);
g_object_set (cell, "active", sensitive, NULL);
g_object_unref (action);
}
static void
set_visible_func (GtkTreeViewColumn *tree_column,
GtkCellRenderer *cell,
GtkTreeModel *tree_model,
GtkTreeIter *iter,
gpointer data)
{
GtkAction *action;
gboolean visible;
gtk_tree_model_get (tree_model, iter, 0, &action, -1);
g_object_get (action, "visible", &visible, NULL);
g_object_set (cell, "active", visible, NULL);
g_object_unref (action);
}
static void
sensitivity_toggled (GtkCellRendererToggle *cell,
const gchar *path_str,
GtkTreeModel *model)
{
GtkTreePath *path;
GtkTreeIter iter;
GtkAction *action;
gboolean sensitive;
path = gtk_tree_path_new_from_string (path_str);
gtk_tree_model_get_iter (model, &iter, path);
gtk_tree_model_get (model, &iter, 0, &action, -1);
g_object_get (action, "sensitive", &sensitive, NULL);
g_object_set (action, "sensitive", !sensitive, NULL);
gtk_tree_model_row_changed (model, path, &iter);
gtk_tree_path_free (path);
}
static void
visibility_toggled (GtkCellRendererToggle *cell,
const gchar *path_str,
GtkTreeModel *model)
{
GtkTreePath *path;
GtkTreeIter iter;
GtkAction *action;
gboolean visible;
path = gtk_tree_path_new_from_string (path_str);
gtk_tree_model_get_iter (model, &iter, path);
gtk_tree_model_get (model, &iter, 0, &action, -1);
g_object_get (action, "visible", &visible, NULL);
g_object_set (action, "visible", !visible, NULL);
gtk_tree_model_row_changed (model, path, &iter);
gtk_tree_path_free (path);
}
static gint
iter_compare_func (GtkTreeModel *model,
GtkTreeIter *a,
GtkTreeIter *b,
gpointer user_data)
{
GValue a_value = G_VALUE_INIT, b_value = G_VALUE_INIT;
GtkAction *a_action, *b_action;
const gchar *a_name, *b_name;
gint retval = 0;
gtk_tree_model_get_value (model, a, 0, &a_value);
gtk_tree_model_get_value (model, b, 0, &b_value);
a_action = GTK_ACTION (g_value_get_object (&a_value));
b_action = GTK_ACTION (g_value_get_object (&b_value));
a_name = gtk_action_get_name (a_action);
b_name = gtk_action_get_name (b_action);
if (a_name == NULL && b_name == NULL)
retval = 0;
else if (a_name == NULL)
retval = -1;
else if (b_name == NULL)
retval = 1;
else
retval = strcmp (a_name, b_name);
g_value_unset (&b_value);
g_value_unset (&a_value);
return retval;
}
static GtkWidget *
create_tree_view (GtkUIManager *merge)
{
GtkWidget *tree_view, *sw;
GtkListStore *store;
GList *p;
GtkCellRenderer *cell;
store = gtk_list_store_new (1, GTK_TYPE_ACTION);
gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (store), 0,
iter_compare_func, NULL, NULL);
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), 0,
GTK_SORT_ASCENDING);
for (p = gtk_ui_manager_get_action_groups (merge); p; p = p->next)
{
GList *actions, *l;
actions = gtk_action_group_list_actions (p->data);
for (l = actions; l; l = l->next)
{
GtkTreeIter iter;
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter, 0, l->data, -1);
}
g_list_free (actions);
}
tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
g_object_unref (store);
gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (tree_view),
-1, "Action",
gtk_cell_renderer_text_new (),
set_name_func, NULL, NULL);
gtk_tree_view_column_set_sort_column_id (gtk_tree_view_get_column (GTK_TREE_VIEW (tree_view), 0), 0);
cell = gtk_cell_renderer_toggle_new ();
g_signal_connect (cell, "toggled", G_CALLBACK (sensitivity_toggled), store);
gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (tree_view),
-1, "Sensitive",
cell,
set_sensitive_func, NULL, NULL);
cell = gtk_cell_renderer_toggle_new ();
g_signal_connect (cell, "toggled", G_CALLBACK (visibility_toggled), store);
gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (tree_view),
-1, "Visible",
cell,
set_visible_func, NULL, NULL);
sw = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
gtk_container_add (GTK_CONTAINER (sw), tree_view);
return sw;
}
static gboolean
area_press (GtkWidget *drawing_area,
GdkEventButton *event,
GtkUIManager *merge)
{
gtk_widget_grab_focus (drawing_area);
if (gdk_event_triggers_context_menu ((GdkEvent *) event) &&
event->type == GDK_BUTTON_PRESS)
{
GtkWidget *menu = gtk_ui_manager_get_widget (merge, "/FileMenu");
if (GTK_IS_MENU (menu))
{
gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
NULL, drawing_area,
3, event->time);
return TRUE;
}
}
return FALSE;
}
static void
activate_path (GtkWidget *button,
GtkUIManager *merge)
{
GtkAction *action = gtk_ui_manager_get_action (merge,
"/menubar/HelpMenu/About");
if (action)
gtk_action_activate (action);
else
g_message ("no action found");
}
typedef struct _ActionStatus ActionStatus;
struct _ActionStatus {
GtkAction *action;
GtkWidget *statusbar;
};
static void
action_status_destroy (gpointer data)
{
ActionStatus *action_status = data;
g_object_unref (action_status->action);
g_object_unref (action_status->statusbar);
g_free (action_status);
}
static void
set_tip (GtkWidget *widget)
{
ActionStatus *data;
gchar *tooltip;
data = g_object_get_data (G_OBJECT (widget), "action-status");
if (data)
{
g_object_get (data->action, "tooltip", &tooltip, NULL);
gtk_statusbar_push (GTK_STATUSBAR (data->statusbar), 0,
tooltip ? tooltip : "");
g_free (tooltip);
}
}
static void
unset_tip (GtkWidget *widget)
{
ActionStatus *data;
data = g_object_get_data (G_OBJECT (widget), "action-status");
if (data)
gtk_statusbar_pop (GTK_STATUSBAR (data->statusbar), 0);
}
static void
connect_proxy (GtkUIManager *merge,
GtkAction *action,
GtkWidget *proxy,
GtkWidget *statusbar)
{
if (GTK_IS_MENU_ITEM (proxy))
{
ActionStatus *data;
data = g_object_get_data (G_OBJECT (proxy), "action-status");
if (data)
{
g_object_unref (data->action);
g_object_unref (data->statusbar);
data->action = g_object_ref (action);
data->statusbar = g_object_ref (statusbar);
}
else
{
data = g_new0 (ActionStatus, 1);
data->action = g_object_ref (action);
data->statusbar = g_object_ref (statusbar);
g_object_set_data_full (G_OBJECT (proxy), "action-status",
data, action_status_destroy);
g_signal_connect (proxy, "select", G_CALLBACK (set_tip), NULL);
g_signal_connect (proxy, "deselect", G_CALLBACK (unset_tip), NULL);
}
}
}
int
main (int argc, char **argv)
{
GtkActionGroup *action_group;
GtkAction *action;
GtkUIManager *merge;
GtkWidget *window, *grid, *frame, *menu_box, *vbox, *view;
GtkWidget *button, *area, *statusbar;
GtkWidget *box;
gint i;
gtk_init (&argc, &argv);
action_group = gtk_action_group_new ("TestActions");
gtk_action_group_add_actions (action_group,
entries, n_entries,
NULL);
action = gtk_action_group_get_action (action_group, "EmptyMenu1Action");
g_object_set (action, "hide_if_empty", FALSE, NULL);
action = gtk_action_group_get_action (action_group, "EmptyMenu2Action");
g_object_set (action, "hide_if_empty", TRUE, NULL);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size (GTK_WINDOW (window), -1, 400);
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
grid = gtk_grid_new ();
gtk_grid_set_row_spacing (GTK_GRID (grid), 2);
gtk_grid_set_column_spacing (GTK_GRID (grid), 2);
gtk_container_add (GTK_CONTAINER (window), grid);
frame = gtk_frame_new ("Menus and Toolbars");
gtk_grid_attach (GTK_GRID (grid), frame, 0, 1, 2, 1);
menu_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add (GTK_CONTAINER (frame), menu_box);
statusbar = gtk_statusbar_new ();
gtk_box_pack_end (GTK_BOX (menu_box), statusbar, FALSE, FALSE);
area = gtk_drawing_area_new ();
gtk_widget_set_events (area, GDK_BUTTON_PRESS_MASK);
gtk_widget_set_size_request (area, -1, 40);
gtk_box_pack_end (GTK_BOX (menu_box), area, FALSE, FALSE);
gtk_widget_show (area);
button = gtk_button_new ();
gtk_box_pack_end (GTK_BOX (menu_box), button, FALSE, FALSE);
gtk_widget_show (button);
button = gtk_check_button_new ();
gtk_box_pack_end (GTK_BOX (menu_box), button, FALSE, FALSE);
gtk_widget_show (button);
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
gtk_box_pack_end (GTK_BOX (menu_box), box, FALSE, FALSE);
gtk_container_add (GTK_CONTAINER (box), gtk_label_new ("Bold:"));
button = gtk_switch_new ();
gtk_container_add (GTK_CONTAINER (box), button);
gtk_widget_show_all (box);
merge = gtk_ui_manager_new ();
g_signal_connect (merge, "connect-proxy", G_CALLBACK (connect_proxy), statusbar);
g_signal_connect (area, "button_press_event", G_CALLBACK (area_press), merge);
gtk_ui_manager_insert_action_group (merge, action_group, 0);
g_signal_connect (merge, "add_widget", G_CALLBACK (add_widget), menu_box);
gtk_window_add_accel_group (GTK_WINDOW (window),
gtk_ui_manager_get_accel_group (merge));
frame = gtk_frame_new ("UI Files");
gtk_widget_set_vexpand (frame, TRUE);
gtk_grid_attach (GTK_GRID (grid), frame, 0, 0, 1, 1);
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
gtk_container_add (GTK_CONTAINER (frame), vbox);
for (i = 0; i < G_N_ELEMENTS (merge_ids); i++)
{
button = gtk_check_button_new_with_label (merge_ids[i].filename);
g_object_set_data (G_OBJECT (button), "mergenum", GINT_TO_POINTER (i));
g_signal_connect (button, "toggled", G_CALLBACK (toggle_merge), merge);
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
}
button = gtk_check_button_new_with_label ("Dynamic");
g_signal_connect (button, "clicked", G_CALLBACK (toggle_dynamic), merge);
gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE);
button = gtk_button_new_with_label ("Activate path");
g_signal_connect (button, "clicked", G_CALLBACK (activate_path), merge);
gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE);
button = gtk_button_new_with_label ("Dump Tree");
g_signal_connect (button, "clicked", G_CALLBACK (dump_tree), merge);
gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE);
button = gtk_button_new_with_label ("Dump Toplevels");
g_signal_connect (button, "clicked", G_CALLBACK (dump_toplevels), merge);
gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE);
button = gtk_button_new_with_label ("Dump Accels");
g_signal_connect (button, "clicked", G_CALLBACK (dump_accels), NULL);
gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE);
view = create_tree_view (merge);
gtk_widget_set_hexpand (view, TRUE);
gtk_widget_set_vexpand (view, TRUE);
gtk_grid_attach (GTK_GRID (grid), view, 1, 0, 1, 1);
gtk_widget_show_all (window);
gtk_main ();
#ifdef DEBUG_UI_MANAGER
{
GList *action;
g_print ("\n> before unreffing the ui manager <\n");
for (action = gtk_action_group_list_actions (action_group);
action;
action = action->next)
{
GtkAction *a = action->data;
g_print (" action %s ref count %d\n",
gtk_action_get_name (a), G_OBJECT (a)->ref_count);
}
}
#endif
g_object_unref (merge);
#ifdef DEBUG_UI_MANAGER
{
GList *action;
g_print ("\n> after unreffing the ui manager <\n");
for (action = gtk_action_group_list_actions (action_group);
action;
action = action->next)
{
GtkAction *a = action->data;
g_print (" action %s ref count %d\n",
gtk_action_get_name (a), G_OBJECT (a)->ref_count);
}
}
#endif
g_object_unref (action_group);
return 0;
}

View File

@ -60,12 +60,6 @@ menu_item_label_notify_count (ActionTest *fixture,
g_signal_connect (item, "notify::label",
G_CALLBACK (notify_count_emmisions), &emmisions);
g_assert_cmpuint (emmisions, ==, 1);
gtk_action_set_label (fixture->action, "new label");
g_assert_cmpuint (emmisions, ==, 2);
g_object_unref (item);
}

View File

@ -301,73 +301,6 @@ test_connect_signals (void)
g_object_unref (builder);
}
static void
test_uimanager_simple (void)
{
GtkBuilder *builder;
GObject *window, *uimgr, *menubar;
GObject *menu, *label;
GList *children;
const gchar buffer[] =
"<interface>"
" <object class=\"GtkUIManager\" id=\"uimgr1\"/>"
"</interface>";
const gchar buffer2[] =
"<interface>"
" <object class=\"GtkUIManager\" id=\"uimgr1\">"
" <child>"
" <object class=\"GtkActionGroup\" id=\"ag1\">"
" <child>"
" <object class=\"GtkAction\" id=\"file\">"
" <property name=\"label\">_File</property>"
" </object>"
" <accelerator key=\"n\" modifiers=\"GDK_CONTROL_MASK\"/>"
" </child>"
" </object>"
" </child>"
" <ui>"
" <menubar name=\"menubar1\">"
" <menu action=\"file\">"
" </menu>"
" </menubar>"
" </ui>"
" </object>"
" <object class=\"GtkWindow\" id=\"window1\">"
" <child>"
" <object class=\"GtkMenuBar\" id=\"menubar1\" constructor=\"uimgr1\"/>"
" </child>"
" </object>"
"</interface>";
builder = builder_new_from_string (buffer, -1, NULL);
uimgr = gtk_builder_get_object (builder, "uimgr1");
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
g_assert (GTK_IS_UI_MANAGER (uimgr));
G_GNUC_END_IGNORE_DEPRECATIONS;
g_object_unref (builder);
builder = builder_new_from_string (buffer2, -1, NULL);
menubar = gtk_builder_get_object (builder, "menubar1");
g_assert (GTK_IS_MENU_BAR (menubar));
children = gtk_container_get_children (GTK_CONTAINER (menubar));
menu = children->data;
g_assert (GTK_IS_MENU_ITEM (menu));
g_assert (strcmp (gtk_widget_get_name (GTK_WIDGET (menu)), "file") == 0);
g_list_free (children);
label = G_OBJECT (gtk_bin_get_child (GTK_BIN (menu)));
g_assert (GTK_IS_LABEL (label));
g_assert (strcmp (gtk_label_get_text (GTK_LABEL (label)), "File") == 0);
window = gtk_builder_get_object (builder, "window1");
gtk_widget_destroy (GTK_WIDGET (window));
g_object_unref (builder);
}
static void
test_domain (void)
{
@ -741,7 +674,6 @@ test_types (void)
" <object class=\"GtkTreeView\" id=\"treeview\"/>"
" <object class=\"GtkViewport\" id=\"viewport\"/>"
" <object class=\"GtkWindow\" id=\"window\"/>"
" <object class=\"GtkUIManager\" id=\"uimanager\"/>"
"</interface>";
const gchar buffer2[] =
"<interface>"
@ -1991,7 +1923,6 @@ test_add_objects (void)
GError *error;
gint ret;
GObject *obj;
GtkUIManager *manager;
GtkWidget *menubar;
GObject *menu, *label;
GList *children;
@ -2034,7 +1965,7 @@ test_add_objects (void)
"<interface/>";
const gchar buffer2[] =
"<interface>"
" <object class=\"GtkUIManager\" id=\"uimgr1\">"
" <object class=\"GtkLabel\" id=\"uimgr1\">"
" <child>"
" <object class=\"GtkActionGroup\" id=\"ag1\">"
" <child>"
@ -2092,7 +2023,7 @@ test_add_objects (void)
ret = gtk_builder_add_objects_from_string (builder, buffer2, -1, objects3, &error);
g_assert (ret);
obj = gtk_builder_get_object (builder, "uimgr1");
g_assert (GTK_IS_UI_MANAGER (obj));
g_assert (GTK_IS_LABEL (obj));
obj = gtk_builder_get_object (builder, "file");
g_assert (GTK_IS_ACTION (obj));
obj = gtk_builder_get_object (builder, "menubar1");
@ -2119,12 +2050,6 @@ test_add_objects (void)
ret = gtk_builder_add_objects_from_string (builder, buffer2, -1, objects4, &error);
g_assert (ret);
obj = gtk_builder_get_object (builder, "uimgr1");
g_assert (GTK_IS_UI_MANAGER (obj));
manager = GTK_UI_MANAGER (obj);
obj = gtk_builder_get_object (builder, "file");
g_assert (GTK_IS_ACTION (obj));
menubar = gtk_ui_manager_get_widget (manager, "/menubar1");
g_assert (GTK_IS_MENU_BAR (menubar));
children = gtk_container_get_children (GTK_CONTAINER (menubar));
menu = children->data;
@ -2844,7 +2769,6 @@ main (int argc, char **argv)
g_test_add_func ("/Builder/Notebook", test_notebook);
g_test_add_func ("/Builder/Domain", test_domain);
g_test_add_func ("/Builder/Signal Autoconnect", test_connect_signals);
g_test_add_func ("/Builder/UIManager Simple", test_uimanager_simple);
g_test_add_func ("/Builder/Spin Button", test_spin_button);
g_test_add_func ("/Builder/SizeGroup", test_sizegroup);
g_test_add_func ("/Builder/ListStore", test_list_store);

View File

@ -362,8 +362,7 @@ test_type (gconstpointer data)
/* Deprecated, not getting fixed */
if (g_str_equal (g_type_name (type), "GtkColorSelection") ||
g_str_equal (g_type_name (type), "GtkNumerableIcon") ||
g_str_equal (g_type_name (type), "GtkUIManager"))
g_str_equal (g_type_name (type), "GtkNumerableIcon"))
return;
/* These can't be freely constructed/destroyed */