Commit 03975b8e authored by Tristan Van Berkom's avatar Tristan Van Berkom
Browse files

Added GtkBuilder support for "menu" child type of GtkMenuToolButton

parent 1fa28093
......@@ -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.
</para>
<refsect2 id="GtkMenuToolButton-BUILDER-UI">
<title>GtkMenuToolButton as GtkBuildable</title>
<para>
The GtkMenuToolButton implementation of the GtkBuildable interface
supports adding a menu by specifying "menu" as the "type"
attribute of a &lt;child&gt; element.
</para>
<example>
<title>A UI definition fragment with menus</title>
<programlisting><![CDATA[
<object class="GtkMenuToolButton">
<child type="menu">
<object class="GtkMenu"/>
</child>
</object>
]]></programlisting>
</example>
</refsect2>
<!-- ##### SECTION See_Also ##### -->
<para>
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment