Commit 3b7fc8cd authored by Tristan Van Berkom's avatar Tristan Van Berkom

Add Composite Child machinery and APIs to GtkWidget

This commit implements the needed machinery for GtkWidget
to build it's composite content from GtkBuilder XML and
adds the following API:

  o gtk_widget_init_template()

    An api to be called in instance initializers of any
    GtkWidget subclass that uses template XML to build it's components.

  o gtk_widget_class_set_template()

    API to associate GtkBuilder XML to a given GtkWidget subclass

  o gtk_widget_class_automate_child()

    API to declare an object built by GtkBuilder to be associated
    with an instance structure offset and automatically set.

 o gtk_widget_get_automated_child()

   API for bindings to fetch a child declared to be automated by
   gtk_widget_class_automate_child(), for the case where bindings
   do not generate GObjects under the hood and cannot use structure
   offsets to resolve composite object pointers.

 o gtk_widget_class_declare_callback[s]()

   Declare static functions to be used in signal callbacks from
   a given class's template XML

 o gtk_widget_class_set_connect_func()

   API for bindings to override the signal connection machinery
   for a given GtkWidget derived class.
parent 64b87824
...@@ -5385,6 +5385,18 @@ gtk_widget_set_vexpand_set ...@@ -5385,6 +5385,18 @@ gtk_widget_set_vexpand_set
gtk_widget_queue_compute_expand gtk_widget_queue_compute_expand
gtk_widget_compute_expand gtk_widget_compute_expand
<SUBSECTION Templates>
gtk_widget_init_template
gtk_widget_class_set_template
gtk_widget_class_set_template_from_resource
gtk_widget_get_automated_child
gtk_widget_class_bind_child
gtk_widget_class_bind_child_internal
gtk_widget_class_automate_child
gtk_widget_class_bind_callback
gtk_widget_class_declare_callback
gtk_widget_class_set_connect_func
<SUBSECTION Standard> <SUBSECTION Standard>
GTK_WIDGET GTK_WIDGET
GTK_IS_WIDGET GTK_IS_WIDGET
......
...@@ -3691,6 +3691,8 @@ gtk_widget_add_tick_callback ...@@ -3691,6 +3691,8 @@ gtk_widget_add_tick_callback
gtk_widget_can_activate_accel gtk_widget_can_activate_accel
gtk_widget_child_focus gtk_widget_child_focus
gtk_widget_child_notify gtk_widget_child_notify
gtk_widget_class_automate_child
gtk_widget_class_declare_callback
gtk_widget_class_find_style_property gtk_widget_class_find_style_property
gtk_widget_class_install_style_property gtk_widget_class_install_style_property
gtk_widget_class_install_style_property_parser gtk_widget_class_install_style_property_parser
...@@ -3698,6 +3700,9 @@ gtk_widget_class_list_style_properties ...@@ -3698,6 +3700,9 @@ gtk_widget_class_list_style_properties
gtk_widget_class_path gtk_widget_class_path
gtk_widget_class_set_accessible_role gtk_widget_class_set_accessible_role
gtk_widget_class_set_accessible_type gtk_widget_class_set_accessible_type
gtk_widget_class_set_signal_connect_func
gtk_widget_class_set_template
gtk_widget_class_set_template_from_resource
gtk_widget_compute_expand gtk_widget_compute_expand
gtk_widget_create_pango_context gtk_widget_create_pango_context
gtk_widget_create_pango_layout gtk_widget_create_pango_layout
...@@ -3715,6 +3720,7 @@ gtk_widget_get_allocated_width ...@@ -3715,6 +3720,7 @@ gtk_widget_get_allocated_width
gtk_widget_get_allocation gtk_widget_get_allocation
gtk_widget_get_ancestor gtk_widget_get_ancestor
gtk_widget_get_app_paintable gtk_widget_get_app_paintable
gtk_widget_get_automated_child
gtk_widget_get_can_default gtk_widget_get_can_default
gtk_widget_get_can_focus gtk_widget_get_can_focus
gtk_widget_get_child_requisition gtk_widget_get_child_requisition
...@@ -3792,6 +3798,7 @@ gtk_widget_help_type_get_type ...@@ -3792,6 +3798,7 @@ gtk_widget_help_type_get_type
gtk_widget_hide gtk_widget_hide
gtk_widget_hide_on_delete gtk_widget_hide_on_delete
gtk_widget_in_destruction gtk_widget_in_destruction
gtk_widget_init_template
gtk_widget_input_shape_combine_region gtk_widget_input_shape_combine_region
gtk_widget_intersect gtk_widget_intersect
gtk_widget_is_ancestor gtk_widget_is_ancestor
......
...@@ -216,6 +216,10 @@ ...@@ -216,6 +216,10 @@
* <link linkend="GtkFileFilter-BUILDER-UI">GtkFileFilter</link>, * <link linkend="GtkFileFilter-BUILDER-UI">GtkFileFilter</link>,
* <link linkend="GtkTextTagTable-BUILDER-UI">GtkTextTagTable</link>. * <link linkend="GtkTextTagTable-BUILDER-UI">GtkTextTagTable</link>.
* </para> * </para>
* <para>
* Additionally, since 3.10 a special &lt;template&gt; tag has been added to the format
* allowing one to <link linkend="GtkWidget-BUILDER-TEMPLATES">define a widget class's components</link>.
* </para>
* </refsect2> * </refsect2>
* <refsect2> * <refsect2>
* <title>Embedding other XML</title> * <title>Embedding other XML</title>
......
...@@ -36,7 +36,6 @@ G_BEGIN_DECLS ...@@ -36,7 +36,6 @@ G_BEGIN_DECLS
#define GTK_BUILDER_ERROR (gtk_builder_error_quark ()) #define GTK_BUILDER_ERROR (gtk_builder_error_quark ())
typedef struct _GtkBuilder GtkBuilder;
typedef struct _GtkBuilderClass GtkBuilderClass; typedef struct _GtkBuilderClass GtkBuilderClass;
typedef struct _GtkBuilderPrivate GtkBuilderPrivate; typedef struct _GtkBuilderPrivate GtkBuilderPrivate;
...@@ -108,14 +107,6 @@ struct _GtkBuilderClass ...@@ -108,14 +107,6 @@ struct _GtkBuilderClass
void (*_gtk_reserved8) (void); void (*_gtk_reserved8) (void);
}; };
typedef void (*GtkBuilderConnectFunc) (GtkBuilder *builder,
GObject *object,
const gchar *signal_name,
const gchar *handler_name,
GObject *connect_object,
GConnectFlags flags,
gpointer user_data);
GType gtk_builder_get_type (void) G_GNUC_CONST; GType gtk_builder_get_type (void) G_GNUC_CONST;
GtkBuilder* gtk_builder_new (void); GtkBuilder* gtk_builder_new (void);
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
G_BEGIN_DECLS G_BEGIN_DECLS
typedef struct _GtkAdjustment GtkAdjustment; typedef struct _GtkAdjustment GtkAdjustment;
typedef struct _GtkBuilder GtkBuilder;
typedef struct _GtkClipboard GtkClipboard; typedef struct _GtkClipboard GtkClipboard;
typedef struct _GtkIconSet GtkIconSet; typedef struct _GtkIconSet GtkIconSet;
typedef struct _GtkIconSource GtkIconSource; typedef struct _GtkIconSource GtkIconSource;
...@@ -51,6 +52,14 @@ typedef gboolean (*GtkRcPropertyParser) (const GParamSpec *pspec, ...@@ -51,6 +52,14 @@ typedef gboolean (*GtkRcPropertyParser) (const GParamSpec *pspec,
const GString *rc_string, const GString *rc_string,
GValue *property_value); GValue *property_value);
typedef void (*GtkBuilderConnectFunc) (GtkBuilder *builder,
GObject *object,
const gchar *signal_name,
const gchar *handler_name,
GObject *connect_object,
GConnectFlags flags,
gpointer user_data);
G_END_DECLS G_END_DECLS
#endif /* __GTK_TYPES_H__ */ #endif /* __GTK_TYPES_H__ */
This diff is collapsed.
...@@ -943,6 +943,79 @@ GDK_AVAILABLE_IN_3_8 ...@@ -943,6 +943,79 @@ GDK_AVAILABLE_IN_3_8
void gtk_widget_remove_tick_callback (GtkWidget *widget, void gtk_widget_remove_tick_callback (GtkWidget *widget,
guint id); guint id);
/**
* gtk_widget_class_bind_callback:
* @widget_class: a #GtkWidgetClass
* @callback: the callback symbol
*
* Shorthand for gtk_widget_class_declare_callback(), adds a symbol
* by it's own name to the @widget_class.
*
* Since: 3.10
*/
#define gtk_widget_class_bind_callback(widget_class, callback) \
gtk_widget_class_declare_callback (GTK_WIDGET_CLASS (widget_class), \
#callback, G_CALLBACK(callback))
/**
* gtk_widget_class_bind_child:
* @widget_class: a #GtkWidgetClass
* @private_data_type: the type of this widget class's instance private data
* @member_name: name of the instance private member on @private_data_type
*
* Shorthand for gtk_widget_class_automate_child(). This macro assumes that
* the @member_name is the name of the component instance to lookup as specified
* in the composite template.
*
* Since: 3.10
*/
#define gtk_widget_class_bind_child(widget_class, private_data_type, member_name) \
gtk_widget_class_automate_child (widget_class, #member_name, FALSE, \
G_STRUCT_OFFSET (private_data_type, member_name))
/**
* gtk_widget_class_bind_child_internal:
* @widget_class: a #GtkWidgetClass
* @private_data_type: the type name of this widget class's instance private data
* @member_name: name of the instance private member on @private_data_type
*
* Shorthand for gtk_widget_class_automate_child(). Essentially the same as
* gtk_widget_class_bind_child() except that it will export the child as
* an internal child.
*
* Since: 3.10
*/
#define gtk_widget_class_bind_child_internal(widget_class, private_data_type, member_name) \
gtk_widget_class_automate_child (widget_class, #member_name, TRUE, \
G_STRUCT_OFFSET (private_data_type, member_name))
GDK_AVAILABLE_IN_3_10
void gtk_widget_init_template (GtkWidget *widget);
GDK_AVAILABLE_IN_3_10
GObject *gtk_widget_get_automated_child (GtkWidget *widget,
GType widget_type,
const gchar *name);
GDK_AVAILABLE_IN_3_10
void gtk_widget_class_set_template (GtkWidgetClass *widget_class,
GBytes *template_bytes);
GDK_AVAILABLE_IN_3_10
void gtk_widget_class_set_template_from_resource (GtkWidgetClass *widget_class,
const gchar *resource_name);
GDK_AVAILABLE_IN_3_10
void gtk_widget_class_declare_callback (GtkWidgetClass *widget_class,
const gchar *callback_name,
GCallback callback_symbol);
GDK_AVAILABLE_IN_3_10
void gtk_widget_class_set_connect_func (GtkWidgetClass *widget_class,
GtkBuilderConnectFunc connect_func,
gpointer connect_data,
GDestroyNotify connect_data_destroy);
GDK_AVAILABLE_IN_3_10
void gtk_widget_class_automate_child (GtkWidgetClass *widget_class,
const gchar *name,
gboolean internal_child,
gssize struct_offset);
G_END_DECLS G_END_DECLS
#endif /* __GTK_WIDGET_H__ */ #endif /* __GTK_WIDGET_H__ */
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