[gtk+] Fixed GtkCellLayout to parse <cell-packing> property text accumulatively.
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Fixed GtkCellLayout to parse <cell-packing> property text accumulatively.
- Date: Wed, 26 Jan 2011 14:48:01 +0000 (UTC)
commit e7354bd3f3cd7068fa660442a591ddd11facb54e
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date: Wed Jan 26 22:19:41 2011 +0900
Fixed GtkCellLayout to parse <cell-packing> property text accumulatively.
gtk/gtkcelllayout.c | 79 +++++++++++++++++++++++++++++++--------------------
1 files changed, 48 insertions(+), 31 deletions(-)
---
diff --git a/gtk/gtkcelllayout.c b/gtk/gtkcelllayout.c
index d56747c..7291a4b 100644
--- a/gtk/gtkcelllayout.c
+++ b/gtk/gtkcelllayout.c
@@ -693,6 +693,7 @@ typedef struct {
GtkBuilder *builder;
GtkCellLayout *cell_layout;
GtkCellRenderer *renderer;
+ GString *string;
gchar *cell_prop_name;
gchar *context;
gboolean translatable;
@@ -743,53 +744,65 @@ cell_packing_text_element (GMarkupParseContext *context,
GError **error)
{
CellPackingSubParserData *parser_data = (CellPackingSubParserData*)user_data;
- GtkCellArea *area;
- gchar* value;
- if (!parser_data->cell_prop_name)
- return;
+ if (parser_data->cell_prop_name)
+ g_string_append_len (parser_data->string, text, text_len);
+}
- if (parser_data->translatable && text_len)
- {
- const gchar* domain;
- domain = gtk_builder_get_translation_domain (parser_data->builder);
+static void
+cell_packing_end_element (GMarkupParseContext *context,
+ const gchar *element_name,
+ gpointer user_data,
+ GError **error)
+{
+ CellPackingSubParserData *parser_data = (CellPackingSubParserData*)user_data;
+ GtkCellArea *area;
- value = _gtk_builder_parser_translate (domain,
- parser_data->context,
- text);
- }
- else
+ /* Append the translated strings */
+ if (parser_data->string->len)
{
- value = g_strdup (text);
- }
-
- area = gtk_cell_layout_get_area (parser_data->cell_layout);
+ area = gtk_cell_layout_get_area (parser_data->cell_layout);
- if (!area)
- {
- g_warning ("%s does not have an internal GtkCellArea class and cannot apply child cell properties",
- g_type_name (G_OBJECT_TYPE (parser_data->cell_layout)));
- return;
+ if (area)
+ {
+ if (parser_data->translatable)
+ {
+ gchar *translated;
+ const gchar* domain;
+
+ domain = gtk_builder_get_translation_domain (parser_data->builder);
+
+ translated = _gtk_builder_parser_translate (domain,
+ parser_data->context,
+ parser_data->string->str);
+ g_string_set_size (parser_data->string, 0);
+ g_string_append (parser_data->string, translated);
+ }
+
+ gtk_cell_layout_buildable_set_cell_property (area,
+ parser_data->builder,
+ parser_data->renderer,
+ parser_data->cell_prop_name,
+ parser_data->string->str);
+ }
+ else
+ g_warning ("%s does not have an internal GtkCellArea class and cannot apply child cell properties",
+ g_type_name (G_OBJECT_TYPE (parser_data->cell_layout)));
}
- gtk_cell_layout_buildable_set_cell_property (area,
- parser_data->builder,
- parser_data->renderer,
- parser_data->cell_prop_name,
- value);
-
+ g_string_set_size (parser_data->string, 0);
g_free (parser_data->cell_prop_name);
g_free (parser_data->context);
- g_free (value);
parser_data->cell_prop_name = NULL;
parser_data->context = NULL;
parser_data->translatable = FALSE;
}
+
static const GMarkupParser cell_packing_parser =
{
cell_packing_start_element,
- NULL,
+ cell_packing_end_element,
cell_packing_text_element,
};
@@ -821,6 +834,7 @@ _gtk_cell_layout_buildable_custom_tag_start (GtkBuildable *buildable,
else if (strcmp (tagname, "cell-packing") == 0)
{
packing_data = g_slice_new0 (CellPackingSubParserData);
+ packing_data->string = g_string_new ("");
packing_data->builder = builder;
packing_data->cell_layout = GTK_CELL_LAYOUT (buildable);
packing_data->renderer = GTK_CELL_RENDERER (child);
@@ -841,6 +855,7 @@ _gtk_cell_layout_buildable_custom_tag_end (GtkBuildable *buildable,
gpointer *data)
{
AttributesSubParserData *attr_data;
+ CellPackingSubParserData *packing_data;
if (strcmp (tagname, "attributes") == 0)
{
@@ -851,7 +866,9 @@ _gtk_cell_layout_buildable_custom_tag_end (GtkBuildable *buildable,
}
else if (strcmp (tagname, "cell-packing") == 0)
{
- g_slice_free (CellPackingSubParserData, (gpointer)data);
+ packing_data = (CellPackingSubParserData *)data;
+ g_string_free (packing_data->string, TRUE);
+ g_slice_free (CellPackingSubParserData, packing_data);
return TRUE;
}
return FALSE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]