[gnumeric] ODF: import/export tab colors via foreign attributes



commit 0a262383fb4122a428da5e5d706ceb8040b61a42
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Fri Sep 3 16:15:06 2010 -0600

    ODF: import/export tab colors via foreign attributes
    
    2010-09-03  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* openoffice-read.c (OOSheetStyle): add tab colors
    	(oo_table_start): handle tab colors
    	(oo_style_prop_table): ditto
    	* openoffice-write.c (odf_write_table_style): write tab colors (as
    	  foreign elements)
    	(table_style_name): give each table its own style.

 plugins/openoffice/ChangeLog          |    9 +++++
 plugins/openoffice/openoffice-read.c  |   53 ++++++++++++++++++++++++++++++++-
 plugins/openoffice/openoffice-write.c |   15 +++++++--
 3 files changed, 73 insertions(+), 4 deletions(-)
---
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index 930c73a..3f70937 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,5 +1,14 @@
 2010-09-03  Andreas J. Guelzow <aguelzow pyrshep ca>
 
+	* openoffice-read.c (OOSheetStyle): add tab colors
+	(oo_table_start): handle tab colors
+	(oo_style_prop_table): ditto
+	* openoffice-write.c (odf_write_table_style): write tab colors (as
+	  foreign elements)
+	(table_style_name): give each table its own style.
+	
+2010-09-03  Andreas J. Guelzow <aguelzow pyrshep ca>
+
 	* openoffice-read.c (odf_apply_style_props): stroke-color attribute 
 	  added
 	(od_style_prop_chart): ditto
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index 67fcb6e..5ee9acd 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -242,6 +242,10 @@ typedef struct {
 typedef struct {
 	GnmSheetVisibility visibility;
 	gboolean is_rtl;
+	gboolean tab_color_set;
+	GOColor tab_color;
+	gboolean tab_text_color_set;
+	GOColor tab_text_color;
 } OOSheetStyle;
 
 typedef enum {
@@ -1282,11 +1286,33 @@ oo_table_start (GsfXMLIn *xin, xmlChar const **attrs)
 	
 	if (style_name != NULL) {
 		OOSheetStyle const *style = g_hash_table_lookup (state->styles.sheet, style_name);
-		if (style)
+		if (style) {
 			g_object_set (state->pos.sheet,
 				      "visibility", style->visibility,
 				      "text-is-rtl", style->is_rtl,
 				      NULL);
+			if (style->tab_color_set) {
+				GnmColor *color 
+					= style_color_new_go (style->tab_color);
+				g_object_set 
+					(state->pos.sheet,
+					 "tab-background",
+					 color,
+					 NULL);
+				style_color_unref (color);
+			}
+			if (style->tab_text_color_set){
+				GnmColor *color 
+					= style_color_new_go 
+					(style->tab_text_color);
+				g_object_set 
+					(state->pos.sheet,
+					 "tab-foreground",
+					 color,
+					 NULL);
+				style_color_unref (color);
+			}
+		}
 		g_free (style_name);
 	}
 	if (state->default_style.rows != NULL)
@@ -3604,6 +3630,31 @@ oo_style_prop_table (GsfXMLIn *xin, xmlChar const **attrs)
 				style->visibility = GNM_SHEET_VISIBILITY_HIDDEN;
 		} else if (oo_attr_enum (xin, attrs, OO_NS_STYLE, "writing-mode", modes, &tmp_i))
 			style->is_rtl = tmp_i;
+		else if (gsf_xml_in_namecmp (xin, CXML2C (attrs[0]), 
+					       OO_GNUM_NS_EXT, "tab-color")) {
+			GdkColor gdk_color;
+			if (gdk_color_parse (CXML2C (attrs[1]), &gdk_color)) {
+				style->tab_color 
+					= GO_COLOR_FROM_GDK (gdk_color);
+				style->tab_color_set = TRUE;
+			} else
+				oo_warning (xin, _("Unable to parse "
+						   "tab color \'%s\'"), 
+					    CXML2C (attrs[1]));			
+		} else if (gsf_xml_in_namecmp (xin, CXML2C (attrs[0]), 
+					       OO_GNUM_NS_EXT, 
+					       "tab-text-color")) {
+			GdkColor gdk_color;
+			if (gdk_color_parse (CXML2C (attrs[1]), &gdk_color)) {
+				style->tab_text_color 
+					= GO_COLOR_FROM_GDK (gdk_color);
+				style->tab_text_color_set = TRUE;
+			} else
+				oo_warning (xin, _("Unable to parse tab "
+						   "text color \'%s\'"), 
+					    CXML2C (attrs[1]));
+		}
+
 }
 
 static gboolean
diff --git a/plugins/openoffice/openoffice-write.c b/plugins/openoffice/openoffice-write.c
index f6327d9..180faec 100644
--- a/plugins/openoffice/openoffice-write.c
+++ b/plugins/openoffice/openoffice-write.c
@@ -572,6 +572,17 @@ odf_write_table_style (GnmOOExport *state,
 		sheet->visibility == GNM_SHEET_VISIBILITY_VISIBLE);
 	gsf_xml_out_add_cstr_unchecked (state->xml, STYLE "writing-mode",
 		sheet->text_is_rtl ? "rl-tb" : "lr-tb");
+	if (state->with_extension) {
+		if (sheet->tab_color && !sheet->tab_color->is_auto) {
+			gnm_xml_out_add_hex_color (state->xml, GNMSTYLE "tab-color",
+						   sheet->tab_color, 1);
+		}
+		if (sheet->tab_text_color && !sheet->tab_text_color->is_auto) {
+			gnm_xml_out_add_hex_color (state->xml, 
+						   GNMSTYLE "tab-text-color",
+						   sheet->tab_text_color, 1);
+		}
+	}
 	gsf_xml_out_end_element (state->xml); /* </style:table-properties> */
 
 	gsf_xml_out_end_element (state->xml); /* </style:style> */
@@ -580,9 +591,7 @@ odf_write_table_style (GnmOOExport *state,
 static char *
 table_style_name (Sheet const *sheet)
 {
-	return g_strdup_printf ("ta-%c-%s",
-		(sheet->visibility == GNM_SHEET_VISIBILITY_VISIBLE) ? 'v' : 'h',
-		sheet->text_is_rtl ? "rl" : "lr");
+	return g_strdup_printf ("ta-%p", sheet);
 }
 
 static gchar*



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]