From 03975b8e7439bc124a0d4ad3bdaa7f2af1765abb Mon Sep 17 00:00:00 2001 From: Tristan Van Berkom Date: Sun, 9 Jan 2011 13:10:40 +0900 Subject: [PATCH] Added GtkBuilder support for "menu" child type of GtkMenuToolButton --- .../reference/gtk/tmpl/gtkmenutoolbutton.sgml | 18 ++++++++++ gtk/gtkmenutoolbutton.c | 33 ++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/docs/reference/gtk/tmpl/gtkmenutoolbutton.sgml b/docs/reference/gtk/tmpl/gtkmenutoolbutton.sgml index c56eab0d76..5326d02498 100644 --- a/docs/reference/gtk/tmpl/gtkmenutoolbutton.sgml +++ b/docs/reference/gtk/tmpl/gtkmenutoolbutton.sgml @@ -16,6 +16,24 @@ A GtkToolItem containing a button with an additional dropdown menu #GtkMenuToolButton. Use gtk_menu_tool_button_new_from_stock() to create a new #GtkMenuToolButton containing a stock item. + +GtkMenuToolButton as GtkBuildable + +The GtkMenuToolButton implementation of the GtkBuildable interface +supports adding a menu by specifying "menu" as the "type" +attribute of a <child> element. + + +A UI definition fragment with menus + + + + + +]]> + + diff --git a/gtk/gtkmenutoolbutton.c b/gtk/gtkmenutoolbutton.c index f657805d70..e63d795317 100644 --- a/gtk/gtkmenutoolbutton.c +++ b/gtk/gtkmenutoolbutton.c @@ -30,6 +30,7 @@ #include "gtkmenu.h" #include "gtkmain.h" #include "gtksizerequest.h" +#include "gtkbuildable.h" #include "gtkprivate.h" #include "gtkintl.h" @@ -49,6 +50,12 @@ static void gtk_menu_tool_button_destroy (GtkWidget *widget); static int menu_deactivate_cb (GtkMenuShell *menu_shell, GtkMenuToolButton *button); +static void gtk_menu_tool_button_buildable_interface_init (GtkBuildableIface *iface); +static void gtk_menu_tool_button_buildable_add_child (GtkBuildable *buildable, + GtkBuilder *builder, + GObject *child, + const gchar *type); + enum { SHOW_MENU, @@ -63,7 +70,11 @@ enum static gint signals[LAST_SIGNAL]; -G_DEFINE_TYPE (GtkMenuToolButton, gtk_menu_tool_button, GTK_TYPE_TOOL_BUTTON) +static GtkBuildableIface *parent_buildable_iface; + +G_DEFINE_TYPE_WITH_CODE (GtkMenuToolButton, gtk_menu_tool_button, GTK_TYPE_TOOL_BUTTON, + G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, + gtk_menu_tool_button_buildable_interface_init)) static void gtk_menu_tool_button_construct_contents (GtkMenuToolButton *button) @@ -453,6 +464,26 @@ gtk_menu_tool_button_destroy (GtkWidget *widget) GTK_WIDGET_CLASS (gtk_menu_tool_button_parent_class)->destroy (widget); } +static void +gtk_menu_tool_button_buildable_add_child (GtkBuildable *buildable, + GtkBuilder *builder, + GObject *child, + const gchar *type) +{ + if (type && strcmp (type, "menu") == 0) + gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (buildable), + GTK_WIDGET (child)); + else + parent_buildable_iface->add_child (buildable, builder, child, type); +} + +static void +gtk_menu_tool_button_buildable_interface_init (GtkBuildableIface *iface) +{ + parent_buildable_iface = g_type_interface_peek_parent (iface); + iface->add_child = gtk_menu_tool_button_buildable_add_child; +} + /** * gtk_menu_tool_button_new: * @icon_widget: (allow-none): a widget that will be used as icon widget, or %NULL