mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-26 13:41:07 +00:00
builder: Make gtk_builder_extend_with_template() work with objects
This will be relevant later when we introduce GtkListItem which is not a GtkWidget.
This commit is contained in:
parent
a44c06b264
commit
db3e225f09
@ -1256,7 +1256,7 @@ gtk_builder_add_objects_from_file (GtkBuilder *builder,
|
||||
/**
|
||||
* gtk_builder_extend_with_template:
|
||||
* @builder: a #GtkBuilder
|
||||
* @widget: the widget that is being extended
|
||||
* @object: the object that is being extended
|
||||
* @template_type: the type that the template is for
|
||||
* @buffer: the string to parse
|
||||
* @length: the length of @buffer (may be -1 if @buffer is nul-terminated)
|
||||
@ -1272,7 +1272,7 @@ gtk_builder_add_objects_from_file (GtkBuilder *builder,
|
||||
*/
|
||||
gboolean
|
||||
gtk_builder_extend_with_template (GtkBuilder *builder,
|
||||
GtkWidget *widget,
|
||||
GObject *object,
|
||||
GType template_type,
|
||||
const gchar *buffer,
|
||||
gssize length,
|
||||
@ -1283,9 +1283,9 @@ gtk_builder_extend_with_template (GtkBuilder *builder,
|
||||
char *filename;
|
||||
|
||||
g_return_val_if_fail (GTK_IS_BUILDER (builder), 0);
|
||||
g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
|
||||
g_return_val_if_fail (G_IS_OBJECT (object), 0);
|
||||
g_return_val_if_fail (g_type_name (template_type) != NULL, 0);
|
||||
g_return_val_if_fail (g_type_is_a (G_OBJECT_TYPE (widget), template_type), 0);
|
||||
g_return_val_if_fail (g_type_is_a (G_OBJECT_TYPE (object), template_type), 0);
|
||||
g_return_val_if_fail (buffer && buffer[0], 0);
|
||||
|
||||
tmp_error = NULL;
|
||||
@ -1297,7 +1297,7 @@ gtk_builder_extend_with_template (GtkBuilder *builder,
|
||||
priv->template_type = template_type;
|
||||
|
||||
filename = g_strconcat ("<", g_type_name (template_type), " template>", NULL);
|
||||
gtk_builder_expose_object (builder, g_type_name (template_type), G_OBJECT (widget));
|
||||
gtk_builder_expose_object (builder, g_type_name (template_type), object);
|
||||
_gtk_builder_parser_parse_buffer (builder, filename,
|
||||
buffer, length,
|
||||
NULL,
|
||||
|
@ -197,7 +197,7 @@ GClosure * gtk_builder_create_closure (GtkBuilder *builder,
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gboolean gtk_builder_extend_with_template (GtkBuilder *builder,
|
||||
GtkWidget *widget,
|
||||
GObject *object,
|
||||
GType template_type,
|
||||
const gchar *buffer,
|
||||
gssize length,
|
||||
|
@ -98,7 +98,7 @@ gtk_builder_list_item_factory_setup (GtkListItemFactory *factory,
|
||||
if (self->scope)
|
||||
gtk_builder_set_scope (builder, self->scope);
|
||||
|
||||
if (!gtk_builder_extend_with_template (builder, GTK_WIDGET (list_item), G_OBJECT_TYPE (list_item),
|
||||
if (!gtk_builder_extend_with_template (builder, G_OBJECT (list_item), G_OBJECT_TYPE (list_item),
|
||||
(const gchar *)g_bytes_get_data (self->bytes, NULL),
|
||||
g_bytes_get_size (self->bytes),
|
||||
&error))
|
||||
|
@ -10959,7 +10959,7 @@ gtk_widget_init_template (GtkWidget *widget)
|
||||
* will validate that the template is created for the correct GType and assert that
|
||||
* there is no infinite recursion.
|
||||
*/
|
||||
if (!gtk_builder_extend_with_template (builder, widget, class_type,
|
||||
if (!gtk_builder_extend_with_template (builder, G_OBJECT (widget), class_type,
|
||||
(const gchar *)g_bytes_get_data (template->data, NULL),
|
||||
g_bytes_get_size (template->data),
|
||||
&error))
|
||||
|
@ -58,7 +58,7 @@ do_validate_template (const gchar *filename,
|
||||
const gchar *parent_name)
|
||||
{
|
||||
GType template_type;
|
||||
GtkWidget *widget;
|
||||
GObject *object;
|
||||
GtkBuilder *builder;
|
||||
GError *error = NULL;
|
||||
gint ret;
|
||||
@ -70,15 +70,15 @@ do_validate_template (const gchar *filename,
|
||||
if (template_type == G_TYPE_INVALID)
|
||||
template_type = make_fake_type (type_name, parent_name);
|
||||
|
||||
widget = g_object_new (template_type, NULL);
|
||||
if (!widget)
|
||||
object = g_object_new (template_type, NULL);
|
||||
if (!object)
|
||||
{
|
||||
g_printerr ("Failed to create an instance of the template type %s\n", type_name);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
builder = gtk_builder_new ();
|
||||
ret = gtk_builder_extend_with_template (builder, widget, template_type, " ", 1, &error);
|
||||
ret = gtk_builder_extend_with_template (builder, object , template_type, " ", 1, &error);
|
||||
if (ret)
|
||||
ret = gtk_builder_add_from_file (builder, filename, &error);
|
||||
g_object_unref (builder);
|
||||
|
Loading…
Reference in New Issue
Block a user