summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2009-04-18 01:23:20 -0400
committerMatthias Clasen <mclasen@redhat.com>2009-04-18 01:23:20 -0400
commitcedc4415b4d49371a70b869c13219d1177568469 (patch)
tree0d077ddbd470bf11e2c8158030419d3997117a23
parent24fde41c854450cbe8428ba78501e15f7cdc1c29 (diff)
downloadgdk-pixbuf-cedc4415b4d49371a70b869c13219d1177568469.tar.gz
Add a GtkBuildable implementation to GtkAssistant
Expose the action area as internal child, and support child properties.
-rw-r--r--docs/reference/gtk/tmpl/gtkassistant.sgml10
-rw-r--r--docs/reference/gtk/tmpl/gtkbuilder.sgml91
-rw-r--r--gtk/gtkassistant.c102
3 files changed, 141 insertions, 62 deletions
diff --git a/docs/reference/gtk/tmpl/gtkassistant.sgml b/docs/reference/gtk/tmpl/gtkassistant.sgml
index c92101439..ab00eee54 100644
--- a/docs/reference/gtk/tmpl/gtkassistant.sgml
+++ b/docs/reference/gtk/tmpl/gtkassistant.sgml
@@ -10,6 +10,16 @@ A #GtkAssistant is a widget used to represent a generally complex
operation splitted in several steps, guiding the user through its pages
and controlling the page flow to collect the necessary data.
</para>
+<refsect2 id="GtkAssistant-BUILDER-UI"><title>GtkAssistant as GtkBuildable</title>
+<para>
+The GtkAssistant implementation of the GtkBuildable interface exposes the
+@action_area as internal children with the name "action_area".
+</para>
+<para>
+To add pages to an assistant in GtkBuilder, simply add it as a &lt;child&gt;
+to the GtkAssistant object, and set its child properties as necessary.
+</para>
+</refsect2>
<!-- ##### SECTION See_Also ##### -->
<para>
diff --git a/docs/reference/gtk/tmpl/gtkbuilder.sgml b/docs/reference/gtk/tmpl/gtkbuilder.sgml
index 09ee015f9..fe10530f8 100644
--- a/docs/reference/gtk/tmpl/gtkbuilder.sgml
+++ b/docs/reference/gtk/tmpl/gtkbuilder.sgml
@@ -7,46 +7,46 @@ Build an interface from an XML UI definition
<!-- ##### SECTION Long_Description ##### -->
<para>
A GtkBuilder is an auxiliary object that reads textual descriptions
-of a user interface and instantiates the described objects. To pass a
-description to a GtkBuilder, call gtk_builder_add_from_file() or
+of a user interface and instantiates the described objects. To pass a
+description to a GtkBuilder, call gtk_builder_add_from_file() or
gtk_builder_add_from_string(). These functions can be called multiple
-times; the builder merges the content of all descriptions.
+times; the builder merges the content of all descriptions.
</para>
<para>
A GtkBuilder holds a reference to all objects that it has constructed
-and drops these references when it is finalized. This finalization can
-cause the destruction of non-widget objects or widgets which are not
-contained in a toplevel window. For toplevel windows constructed by a
-builder, it is the responsibility of the user to call gtk_widget_destroy()
+and drops these references when it is finalized. This finalization can
+cause the destruction of non-widget objects or widgets which are not
+contained in a toplevel window. For toplevel windows constructed by a
+builder, it is the responsibility of the user to call gtk_widget_destroy()
to get rid of them and all the widgets they contain.
</para>
<para>
The functions gtk_builder_get_object() and gtk_builder_get_objects()
-can be used to access the widgets in the interface by the names assigned
+can be used to access the widgets in the interface by the names assigned
to them inside the UI description. Toplevel windows returned by these
functions will stay around until the user explicitly destroys them
-with gtk_widget_destroy(). Other widgets will either be part of a
+with gtk_widget_destroy(). Other widgets will either be part of a
larger hierarchy constructed by the builder (in which case you should
-not have to worry about their lifecycle), or without a parent, in which
-case they have to be added to some container to make use of them.
+not have to worry about their lifecycle), or without a parent, in which
+case they have to be added to some container to make use of them.
Non-widget objects need to be reffed with g_object_ref() to keep them
beyond the lifespan of the builder.
</para>
<para>
-The function gtk_builder_connect_signals() and variants thereof can be
-used to connect handlers to the named signals in the description.
+The function gtk_builder_connect_signals() and variants thereof can be
+used to connect handlers to the named signals in the description.
</para>
<refsect2 id="BUILDER-UI"><title>GtkBuilder UI Definitions</title>
<para>
-GtkBuilder parses textual descriptions of user interfaces which
-are specified in an XML format which can be roughly described
-by the DTD below. We refer to these descriptions as
+GtkBuilder parses textual descriptions of user interfaces which
+are specified in an XML format which can be roughly described
+by the DTD below. We refer to these descriptions as
<firstterm>GtkBuilder UI definitions</firstterm> or just
<firstterm>UI definitions</firstterm> if the context is clear.
-Do not confuse GtkBuilder UI Definitions with
-<link linkend="XML-UI">GtkUIManager UI Definitions</link>,
-which are more limited in scope.
+Do not confuse GtkBuilder UI Definitions with
+<link linkend="XML-UI">GtkUIManager UI Definitions</link>,
+which are more limited in scope.
</para>
<para>
<programlisting><![CDATA[
@@ -65,7 +65,7 @@ which are more limited in scope.
<!ATTLIST requires lib #REQUIRED
version #REQUIRED >
<!ATTLIST property name #REQUIRED
- translatable #IMPLIED
+ translatable #IMPLIED
comments #IMPLIED
context #IMPLIED >
<!ATTLIST signal name #REQUIRED
@@ -93,7 +93,7 @@ or columns in a tree model). A &lt;child&gt; element contains
an &lt;object&gt; element which describes the child object.
The target toolkit version(s) are described by &lt;requires&gt;
elements, the "lib" attribute specifies the widget library in
-question (currently the only supported value is "gtk+") and the "version"
+question (currently the only supported value is "gtk+") and the "version"
attribute specifies the target version in the form "&lt;major&gt;.&lt;minor&gt;".
The builder will error out if the version requirements are not met.
</para>
@@ -101,28 +101,28 @@ The builder will error out if the version requirements are not met.
Typically, the specific kind of object represented by an
&lt;object&gt; element is specified by the "class" attribute.
If the type has not been loaded yet, GTK+ tries to find the
-<function>_get_type()</function> from the class name by applying
+<function>_get_type()</function> from the class name by applying
heuristics. This works in most cases, but if necessary, it is
-possible to specify the name of the <function>_get_type()</function>
-explictly with the "type-func" attribute. As a special case,
+possible to specify the name of the <function>_get_type()</function>
+explictly with the "type-func" attribute. As a special case,
GtkBuilder allows to use an object that has been constructed
by a #GtkUIManager in another part of the UI definition by
specifying the id of the #GtkUIManager in the "constructor"
attribute and the name of the object in the "id" attribute.
</para>
<para>
-Objects must be given a name with the "id" attribute, which
-allows the application to retrieve them from the builder with
-gtk_builder_get_object(). An id is also necessary to use the
+Objects must be given a name with the "id" attribute, which
+allows the application to retrieve them from the builder with
+gtk_builder_get_object(). An id is also necessary to use the
object as property value in other parts of the UI definition.
</para>
<para>
Setting properties of objects is pretty straightforward with
the &lt;property&gt; element: the "name" attribute specifies
-the name of the property, and the content of the element
-specifies the value. If the "translatable" attribute is
+the name of the property, and the content of the element
+specifies the value. If the "translatable" attribute is
set to a true value, GTK+ uses gettext() (or dgettext() if
-the builder has a translation domain set) to find a translation
+the builder has a translation domain set) to find a translation
for the value. This happens before the value is parsed, so
it can be used for properties of any type, but it is probably
most useful for string properties. It is also possible to
@@ -134,16 +134,16 @@ GtkBuilder can parse textual representations for the most
common property types: characters, strings, integers, floating-point
numbers, booleans (strings like "TRUE", "t", "yes", "y", "1" are
interpreted as %TRUE, strings like "FALSE, "f", "no", "n", "0" are
-interpreted as %FALSE), enumerations (can be specified by their
-name, nick or integer value), flags (can be specified by their name,
-nick, integer value, optionally combined with "|", e.g.
-"GTK_VISIBLE|GTK_REALIZED") and colors (in a format understood by
-gdk_color_parse()). Objects can be referred to by their name.
+interpreted as %FALSE), enumerations (can be specified by their
+name, nick or integer value), flags (can be specified by their name,
+nick, integer value, optionally combined with "|", e.g.
+"GTK_VISIBLE|GTK_REALIZED") and colors (in a format understood by
+gdk_color_parse()). Objects can be referred to by their name.
Pixbufs can be specified as a filename of an image file to load.
-In general, GtkBuilder allows forward references to objects &mdash;
+In general, GtkBuilder allows forward references to objects &mdash;
an object doesn't have to constructed before it can be referred to.
The exception to this rule is that an object has to be constructed
-before it can be used as the value of a construct-only property.
+before it can be used as the value of a construct-only property.
</para>
<para>
Signal handlers are set up with the &lt;signal&gt; element.
@@ -152,25 +152,25 @@ The "name" attribute specifies the name of the signal, and the
By default, GTK+ tries to find the handler using g_module_symbol(),
but this can be changed by passing a custom #GtkBuilderConnectFunc
to gtk_builder_connect_signals_full(). The remaining attributes,
-"after", "swapped" and "object", have the same meaning as the
+"after", "swapped" and "object", have the same meaning as the
corresponding parameters of the g_signal_connect_object() or
g_signal_connect_data() functions. A "last_modification_time" attribute
is also allowed, but it does not have a meaning to the builder.
</para>
<para>
Sometimes it is necessary to refer to widgets which have implicitly
-been constructed by GTK+ as part of a composite widget, to set
-properties on them or to add further children (e.g. the @vbox
+been constructed by GTK+ as part of a composite widget, to set
+properties on them or to add further children (e.g. the @vbox
of a #GtkDialog). This can be achieved by setting the "internal-child"
propery of the &lt;child&gt; element to a true value. Note that
GtkBuilder still requires an &lt;object&gt; element for the internal
child, even if it has already been constructed.
</para>
<para>
-A number of widgets have different places where a child can be
+A number of widgets have different places where a child can be
added (e.g. tabs vs. page content in notebooks). This can be reflected
in a UI definition by specifying the "type" attribute on a &lt;child&gt;
-The possible values for the "type" attribute are described in
+The possible values for the "type" attribute are described in
the sections describing the widget-specific portions of UI definitions.
</para>
<example>
@@ -205,11 +205,11 @@ their own XML DTD fragments for filling in the ANY placeholders
in the DTD above. Note that a custom element in a &lt;child&gt;
element gets parsed by the custom tag handler of the parent
object, while a custom element in an &lt;object&gt; element
-gets parsed by the custom tag handler of the object.
+gets parsed by the custom tag handler of the object.
</para>
<para>
These XML fragments are explained in the documentation of the
-respective objects, see
+respective objects, see
<link linkend="GtkWidget-BUILDER-UI">GtkWidget</link>,
<link linkend="GtkLabel-BUILDER-UI">GtkLabel</link>,
<link linkend="GtkWindow-BUILDER-UI">GtkWindow</link>,
@@ -228,7 +228,8 @@ respective objects, see
<link linkend="GtkTreeView-BUILDER-UI">GtkTreeView</link>,
<link linkend="GtkUIManager-BUILDER-UI">GtkUIManager</link>,
<link linkend="GtkActionGroup-BUILDER-UI">GtkActionGroup</link>.
-<link linkend="GtkMenuItem-BUILDER-UI">GtkMenuItem</link>.
+<link linkend="GtkMenuItem-BUILDER-UI">GtkMenuItem</link>,
+<link linkend="GtkAssistant-BUILDER-UI">GtkAssistant</link>.
</para>
</refsect2>
diff --git a/gtk/gtkassistant.c b/gtk/gtkassistant.c
index e469b5a28..317e3cdd9 100644
--- a/gtk/gtkassistant.c
+++ b/gtk/gtkassistant.c
@@ -40,6 +40,7 @@
#include "gtkintl.h"
#include "gtkprivate.h"
+#include "gtkbuildable.h"
#include "gtkalias.h"
@@ -119,6 +120,23 @@ static void gtk_assistant_get_child_property (GtkContainer *container,
static AtkObject *gtk_assistant_get_accessible (GtkWidget *widget);
+static void gtk_assistant_buildable_interface_init (GtkBuildableIface *iface);
+static GObject *gtk_assistant_buildable_get_internal_child (GtkBuildable *buildable,
+ GtkBuilder *builder,
+ const gchar *childname);
+static gboolean gtk_assistant_buildable_custom_tag_start (GtkBuildable *buildable,
+ GtkBuilder *builder,
+ GObject *child,
+ const gchar *tagname,
+ GMarkupParser *parser,
+ gpointer *data);
+static void gtk_assistant_buildable_custom_finished (GtkBuildable *buildable,
+ GtkBuilder *builder,
+ GObject *child,
+ const gchar *tagname,
+ gpointer user_data);
+
+
enum
{
CHILD_PROP_0,
@@ -141,7 +159,9 @@ enum
static guint signals [LAST_SIGNAL] = { 0 };
-G_DEFINE_TYPE (GtkAssistant, gtk_assistant, GTK_TYPE_WINDOW)
+G_DEFINE_TYPE_WITH_CODE (GtkAssistant, gtk_assistant, GTK_TYPE_WINDOW,
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
+ gtk_assistant_buildable_interface_init))
static void
@@ -197,8 +217,8 @@ gtk_assistant_class_init (GtkAssistantClass *class)
* @assistant: the #GtkAssistant
* @page: the current page
*
- * The ::prepared signal is emitted when a new page is set as the assistant's
- * current page, before making the new page visible. A handler for this signal
+ * The ::prepared signal is emitted when a new page is set as the assistant's
+ * current page, before making the new page visible. A handler for this signal
* can do any preparation which are necessary before showing @page.
*
* Since: 2.10
@@ -2233,7 +2253,7 @@ gtk_assistant_accessible_ref_child (AtkObject *accessible,
GtkWidget *widget, *child;
gint n_pages;
AtkObject *obj;
- gchar *title;
+ const gchar *title;
widget = GTK_ACCESSIBLE (accessible)->widget;
if (!widget)
@@ -2290,15 +2310,15 @@ gtk_assistant_accessible_get_type (void)
GType derived_type;
GTypeQuery query;
GType derived_atk_type;
-
+
derived_type = g_type_parent (GTK_TYPE_ASSISTANT);
factory = atk_registry_get_factory (atk_get_default_registry (),
derived_type);
derived_atk_type = atk_object_factory_get_accessible_type (factory);
g_type_query (derived_atk_type, &query);
-
- type = g_type_register_static_simple (derived_atk_type,
- I_("GtkAssistantAccessible"),
+
+ type = g_type_register_static_simple (derived_atk_type,
+ I_("GtkAssistantAccessible"),
query.class_size,
(GClassInitFunc) gtk_assistant_accessible_class_init,
query.instance_size,
@@ -2315,9 +2335,9 @@ gtk_assistant_accessible_new (GObject *obj)
g_return_val_if_fail (GTK_IS_ASSISTANT (obj), NULL);
- accessible = g_object_new (gtk_assistant_accessible_get_type (), NULL);
+ accessible = g_object_new (gtk_assistant_accessible_get_type (), NULL);
atk_object_initialize (accessible, obj);
-
+
return accessible;
}
@@ -2345,16 +2365,16 @@ gtk_assistant_accessible_factory_get_type (void)
{
static GType type = 0;
- if (!type)
+ if (!type)
{
- type = g_type_register_static_simple (ATK_TYPE_OBJECT_FACTORY,
+ type = g_type_register_static_simple (ATK_TYPE_OBJECT_FACTORY,
I_("GtkAssistantAccessibleFactory"),
sizeof (AtkObjectFactoryClass),
(GClassInitFunc) gtk_assistant_accessible_factory_class_init,
sizeof (AtkObjectFactory),
NULL, 0);
}
-
+
return type;
}
@@ -2363,12 +2383,12 @@ gtk_assistant_get_accessible (GtkWidget *widget)
{
static gboolean first_time = TRUE;
- if (first_time)
+ if (first_time)
{
AtkObjectFactory *factory;
AtkRegistry *registry;
- GType derived_type;
- GType derived_atk_type;
+ GType derived_type;
+ GType derived_atk_type;
/*
* Figure out whether accessibility is enabled by looking at the
@@ -2383,7 +2403,7 @@ gtk_assistant_get_accessible (GtkWidget *widget)
derived_atk_type = atk_object_factory_get_accessible_type (factory);
if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
{
- atk_registry_set_factory_type (registry,
+ atk_registry_set_factory_type (registry,
GTK_TYPE_ASSISTANT,
gtk_assistant_accessible_factory_get_type ());
}
@@ -2394,5 +2414,53 @@ gtk_assistant_get_accessible (GtkWidget *widget)
}
+static GtkBuildableIface *parent_buildable_iface;
+
+static void
+gtk_assistant_buildable_interface_init (GtkBuildableIface *iface)
+{
+ parent_buildable_iface = g_type_interface_peek_parent (iface);
+ iface->get_internal_child = gtk_assistant_buildable_get_internal_child;
+ iface->custom_tag_start = gtk_assistant_buildable_custom_tag_start;
+ iface->custom_finished = gtk_assistant_buildable_custom_finished;
+}
+
+static GObject *
+gtk_assistant_buildable_get_internal_child (GtkBuildable *buildable,
+ GtkBuilder *builder,
+ const gchar *childname)
+{
+ if (strcmp (childname, "action_area") == 0)
+ return G_OBJECT (GTK_ASSISTANT (buildable)->priv->action_area);
+
+ return parent_buildable_iface->get_internal_child (buildable,
+ builder,
+ childname);
+}
+
+gboolean
+gtk_assistant_buildable_custom_tag_start (GtkBuildable *buildable,
+ GtkBuilder *builder,
+ GObject *child,
+ const gchar *tagname,
+ GMarkupParser *parser,
+ gpointer *data)
+{
+ return parent_buildable_iface->custom_tag_start (buildable, builder, child,
+ tagname, parser, data);
+}
+
+static void
+gtk_assistant_buildable_custom_finished (GtkBuildable *buildable,
+ GtkBuilder *builder,
+ GObject *child,
+ const gchar *tagname,
+ gpointer user_data)
+{
+ parent_buildable_iface->custom_finished (buildable, builder, child,
+ tagname, user_data);
+}
+
+
#define __GTK_ASSISTANT_C__
#include "gtkaliasdef.c"