Compare commits

...

1 Commits

Author SHA1 Message Date
Corey Berla
e8c35ac480 inscription: Implement buildable for attributes
This is a copy and paste from gtklabel.
2023-08-23 11:08:16 -07:00

View File

@@ -96,7 +96,13 @@ enum
N_PROPS
};
G_DEFINE_TYPE (GtkInscription, gtk_inscription, GTK_TYPE_WIDGET)
static void gtk_inscription_buildable_interface_init (GtkBuildableIface *iface);
static GtkBuildableIface *buildable_parent_iface = NULL;
G_DEFINE_TYPE_WITH_CODE (GtkInscription, gtk_inscription, GTK_TYPE_WIDGET,
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
gtk_inscription_buildable_interface_init))
static GParamSpec *properties[N_PROPS] = { NULL, };
@@ -236,6 +242,72 @@ gtk_inscription_set_property (GObject *object,
}
}
static const GtkBuildableParser pango_parser =
{
gtk_pango_attribute_start_element,
};
static gboolean
gtk_inscription_buildable_custom_tag_start (GtkBuildable *buildable,
GtkBuilder *builder,
GObject *child,
const char *tagname,
GtkBuildableParser *parser,
gpointer *data)
{
if (buildable_parent_iface->custom_tag_start (buildable, builder, child,
tagname, parser, data))
return TRUE;
if (strcmp (tagname, "attributes") == 0)
{
GtkPangoAttributeParserData *parser_data;
parser_data = g_new0 (GtkPangoAttributeParserData, 1);
parser_data->builder = g_object_ref (builder);
parser_data->object = (GObject *) g_object_ref (buildable);
*parser = pango_parser;
*data = parser_data;
return TRUE;
}
return FALSE;
}
static void
gtk_inscription_buildable_custom_finished (GtkBuildable *buildable,
GtkBuilder *builder,
GObject *child,
const char *tagname,
gpointer user_data)
{
GtkPangoAttributeParserData *data = user_data;
buildable_parent_iface->custom_finished (buildable, builder, child,
tagname, user_data);
if (strcmp (tagname, "attributes") == 0)
{
if (data->attrs)
{
gtk_inscription_set_attributes (GTK_INSCRIPTION (buildable), data->attrs);
pango_attr_list_unref (data->attrs);
}
g_object_unref (data->object);
g_object_unref (data->builder);
g_free (data);
}
}
static void
gtk_inscription_buildable_interface_init (GtkBuildableIface *iface)
{
buildable_parent_iface = g_type_interface_peek_parent (iface);
iface->custom_tag_start = gtk_inscription_buildable_custom_tag_start;
iface->custom_finished = gtk_inscription_buildable_custom_finished;
}
static void
update_pango_alignment (GtkInscription *self)
{