[gnumeric] Use formatting attributes whenever we format numbers. [#584380][#651561]



commit 08425f650007af21ce96c6889110e71ba46e3731
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Mon Aug 1 21:53:25 2011 -0600

    Use formatting attributes whenever we format numbers. [#584380][#651561]
    
    2011-08-01 Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* configure.in: Disable GTK depreciation check
    	* src/cell-draw.c (cell_calc_layout): use gnm_rendered_value_get_color
    	* src/cell.c (gnm_cell_get_render_color): ditto
    	* src/gnm-format.c (gnm_format_layout): drop argument and change all
    	callers
    	(format_value_gstring): ditto
    	(format_value): ditto
    	(format_value_layout): new
    	* src/gnm-format.h (gnm_format_layout): drop argument and change all
    	callers
    	(format_value_gstring): ditto
    	(format_value): ditto
    	(format_value_layout): new
    	* src/rendered-value.c (gnm_rendered_value_new): include foreground
    	color in attributes list
    	(colour_selector_cb): new
    	(colour_from_layout): new
    	* src/widgets/gnm-format-sel.c (cb_generate_preview): use attributes
    	* src/workbook-view.c (wb_view_auto_expr_recalc): use
    	format_value_layout

 ChangeLog                                 |   27 ++++++++++++
 NEWS                                      |    4 ++
 configure.in                              |    2 +-
 plugins/excel/xlsx-write-pivot.c          |    6 +-
 plugins/fn-string/functions.c             |    6 +-
 plugins/openoffice/openoffice-write.c     |    6 +-
 src/cell-draw.c                           |    2 +-
 src/cell.c                                |    4 +-
 src/clipboard.c                           |    2 +-
 src/dialogs/dialog-function-select.c      |    5 +-
 src/dialogs/dialog-goal-seek.c            |    2 +-
 src/gnm-datetime.c                        |    2 +-
 src/gnm-format.c                          |   52 ++++++++++++++++------
 src/gnm-format.h                          |    9 +++-
 src/go-data-cache.c                       |    2 +-
 src/graph.c                               |    2 +-
 src/gui-util.c                            |    8 ++--
 src/print-info.c                          |    2 +-
 src/rendered-value.c                      |   66 +++++++++++++++++++++--------
 src/rendered-value.h                      |    4 +-
 src/sheet-autofill.c                      |    6 +-
 src/sheet-filter.c                        |    4 +-
 src/sheet-object-widget.c                 |    2 +-
 src/stf-export.c                          |    4 +-
 src/stf.c                                 |    2 +-
 src/tools/tabulate.c                      |    2 +-
 src/wbc-gtk-actions.c                     |    4 +-
 src/wbc-gtk-edit.c                        |    6 +-
 src/widgets/gnm-filter-combo-view.c       |    2 +-
 src/widgets/gnm-format-sel.c              |   29 ++++++++++--
 src/widgets/gnm-sheet-slicer-combo-view.c |    2 +-
 src/widgets/gnm-validation-combo-view.c   |    2 +-
 src/widgets/gnumeric-expr-entry.c         |    6 +-
 src/widgets/gnumeric-text-view.c          |    7 ---
 src/workbook-view.c                       |   43 +++++++++++--------
 35 files changed, 221 insertions(+), 113 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 8ecfd19..87db20a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,30 @@
+2011-08-01 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* configure.in: Disable GTK depreciation check
+	* src/cell-draw.c (cell_calc_layout): use gnm_rendered_value_get_color
+	* src/cell.c (gnm_cell_get_render_color): ditto
+	* src/gnm-format.c (gnm_format_layout): drop argument and change all
+	callers
+	(format_value_gstring): ditto
+	(format_value): ditto
+	(format_value_layout): new
+	* src/gnm-format.h (gnm_format_layout): drop argument and change all
+	callers
+	(format_value_gstring): ditto
+	(format_value): ditto
+	(format_value_layout): new
+	* src/rendered-value.c (gnm_rendered_value_new): include foreground
+	color in attributes list
+	(colour_selector_cb): new
+	(colour_from_layout): new
+	* src/widgets/gnm-format-sel.c (cb_generate_preview): use attributes
+	* src/workbook-view.c (wb_view_auto_expr_recalc): use 
+	format_value_layout
+
+2011-08-01  Morten Welinder <terra gnome org>
+
+	* Branch to 1.11.0
+
 2011-07-31  Morten Welinder <terra gnome org>
 
 	* configure.in: Post-release bump.
diff --git a/NEWS b/NEWS
index 9e4eed8..fa1b57c 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,9 @@
 Gnumeric 1.11.0
 
+Andreas: 
+	* Use formatting attributes whenever we format numbers. 
+	[#584380][#651561] 
+
 --------------------------------------------------------------------------
 Gnumeric 1.10.17
 
diff --git a/configure.in b/configure.in
index e7f63de..4d31f7a 100644
--- a/configure.in
+++ b/configure.in
@@ -271,7 +271,7 @@ fi
 AC_SUBST(GNUMERIC_PLUGIN_LDFLAGS)
 
 dnl disable for in stable release, enable for development series
-if test $gnumeric_devel = yes; then
+if test XXX$gnumeric_devel = yes; then
     CFLAGS="$CFLAGS -DG_DISABLE_DEPRECATED"
     CFLAGS="$CFLAGS -DPANGO_DISABLE_DEPRECATED"
     if test "x$gnumeric_with_gtk" = xtrue; then
diff --git a/plugins/excel/xlsx-write-pivot.c b/plugins/excel/xlsx-write-pivot.c
index 08bce83..64a98f6 100644
--- a/plugins/excel/xlsx-write-pivot.c
+++ b/plugins/excel/xlsx-write-pivot.c
@@ -54,7 +54,7 @@ xlsx_write_pivot_val (XLSXWriteState *state, GsfXMLOut *xml,
 	case VALUE_FLOAT: {
 		GOFormat const *fmt = go_val_get_fmt (v);
 		if (NULL != fmt && go_format_is_date (fmt)) {
-			char *d = format_value (state->date_fmt, v, NULL, -1, workbook_date_conv (state->base.wb));
+			char *d = format_value (state->date_fmt, v, -1, workbook_date_conv (state->base.wb));
 			gsf_xml_out_start_element (xml, "d");
 			gsf_xml_out_add_cstr_unchecked (xml, "v", d);
 			gsf_xml_out_end_element (xml);
@@ -183,7 +183,7 @@ xlsx_write_date (XLSXWriteState *state, GsfXMLOut *xml,
 		 char const *id, gnm_float v)
 {
 	GOVal *tmp = go_val_new_float (v);
-	char *d = format_value (state->date_fmt, tmp, NULL, -1, workbook_date_conv (state->base.wb));
+	char *d = format_value (state->date_fmt, tmp, -1, workbook_date_conv (state->base.wb));
 	gsf_xml_out_add_cstr_unchecked (xml, id, d);
 	g_free (d);
 	go_val_free (tmp);
@@ -277,7 +277,7 @@ xlsx_write_pivot_cache_definition (XLSXWriteState *state, GsfOutfile *wb_part,
 					       go_val_as_float (cache->refreshed_on), -1);
 		else {
 			GOFormat const *format = go_format_new_from_XL ("yyyy-mm-dd\"T\"hh:mm:ss");
-			gchar *date = format_value (format, cache->refreshed_on, NULL, -1, NULL);
+			gchar *date = format_value (format, cache->refreshed_on, -1, NULL);
 			gsf_xml_out_add_cstr_unchecked (xml, "refreshedDateIso", date);
 			g_free (date);
 			go_format_unref (format);
diff --git a/plugins/fn-string/functions.c b/plugins/fn-string/functions.c
index c659409..7012598 100644
--- a/plugins/fn-string/functions.c
+++ b/plugins/fn-string/functions.c
@@ -733,7 +733,7 @@ gnumeric_fixed (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
 	fmt = go_format_new_from_XL (format->str);
 	g_string_free (format, TRUE);
 
-	res = format_value (fmt, v, NULL, -1,
+	res = format_value (fmt, v, -1,
 			    workbook_date_conv (ei->pos->sheet->workbook));
 
 	go_format_unref (fmt);
@@ -949,7 +949,7 @@ gnumeric_text (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
 		GOFormatNumberError err;
 
 		g_free (lfmt);
-		err = format_value_gstring (str, fmt, v, NULL, -1, conv);
+		err = format_value_gstring (str, fmt, v, -1, conv);
 		if (err) {
 			g_string_free (str, TRUE);
 			res = value_new_error_VALUE (ei->pos);
@@ -1241,7 +1241,7 @@ gnumeric_dollar (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
 	sf = go_format_new_from_XL (fmt_str->str);
 
 	v = value_new_float (number);
-	s = format_value (sf, v, NULL, -1,
+	s = format_value (sf, v, -1,
 			  workbook_date_conv (ei->pos->sheet->workbook));
 	value_release (v);
 	go_format_unref (sf);
diff --git a/plugins/openoffice/openoffice-write.c b/plugins/openoffice/openoffice-write.c
index a3b209e..b409cdd 100644
--- a/plugins/openoffice/openoffice-write.c
+++ b/plugins/openoffice/openoffice-write.c
@@ -3022,12 +3022,12 @@ odf_write_cell (GnmOOExport *state, GnmCell *cell, GnmRange const *merge_range,
 				if (f == gnm_floor (f)) {
 					gsf_xml_out_add_cstr_unchecked (state->xml,
 									OFFICE "value-type", "date");
-					str = format_value (state->date_fmt, cell->value, NULL, -1, workbook_date_conv (state->wb));
+					str = format_value (state->date_fmt, cell->value, -1, workbook_date_conv (state->wb));
 					gsf_xml_out_add_cstr (state->xml, OFFICE "date-value", str);
 				} else {
 					gsf_xml_out_add_cstr_unchecked (state->xml,
 									OFFICE "value-type", "date");
-					str = format_value (state->date_long_fmt, cell->value, NULL, -1, workbook_date_conv (state->wb));
+					str = format_value (state->date_long_fmt, cell->value, -1, workbook_date_conv (state->wb));
 					gsf_xml_out_add_cstr (state->xml, OFFICE "date-value", str);
 				}
 				g_free (str);
@@ -3035,7 +3035,7 @@ odf_write_cell (GnmOOExport *state, GnmCell *cell, GnmRange const *merge_range,
 				char *str;
 				gsf_xml_out_add_cstr_unchecked (state->xml,
 								OFFICE "value-type", "time");
-				str = format_value (state->time_fmt, cell->value, NULL, -1, workbook_date_conv (state->wb));
+				str = format_value (state->time_fmt, cell->value, -1, workbook_date_conv (state->wb));
 				gsf_xml_out_add_cstr (state->xml, OFFICE "time-value", str);
 				g_free (str);
 			} else {
diff --git a/src/cell-draw.c b/src/cell-draw.c
index 71dd09e..a67d5a6 100644
--- a/src/cell-draw.c
+++ b/src/cell-draw.c
@@ -238,7 +238,7 @@ cell_calc_layout (GnmCell const *cell, GnmRenderedValue *rv, int y_direction,
 			 rv->layout_natural_width, rv->layout_natural_height);
 #endif
 
-	*res_color = rv->go_fore_color;
+	*res_color = gnm_rendered_value_get_color (rv);
 	*res_x = rect_x + hoffset;
 	*res_y = text_base;
 
diff --git a/src/cell.c b/src/cell.c
index ca0ce1a..9a84b3e 100644
--- a/src/cell.c
+++ b/src/cell.c
@@ -611,7 +611,7 @@ gnm_cell_get_render_color (GnmCell const *cell)
 
 	rv = gnm_cell_fetch_rendered_value (cell, TRUE);
 
-	return rv->go_fore_color;
+	return gnm_rendered_value_get_color (rv);
 }
 
 /**
@@ -669,7 +669,7 @@ gnm_cell_get_entered_text (GnmCell const *cell)
 			return g_strconcat ("\'", tmp, NULL);
 		} else {
 			GOFormat const *fmt = gnm_cell_get_format (cell);
-			return format_value (fmt, v, NULL, -1,	date_conv);
+			return format_value (fmt, v, -1, date_conv);
 		}
 	}
 
diff --git a/src/clipboard.c b/src/clipboard.c
index 184b809..de9ad60 100644
--- a/src/clipboard.c
+++ b/src/clipboard.c
@@ -1022,7 +1022,7 @@ cellregion_to_string (GnmCellRegion const *cr,
 					fmt = VALUE_FMT (cc->val);
 
 				format_value_gstring (line, fmt, cc->val,
-						      NULL, -1, date_conv);
+						      -1, date_conv);
 			}
 			if (++col <= extent.end.col)
 				g_string_append_c (line, '\t');
diff --git a/src/dialogs/dialog-function-select.c b/src/dialogs/dialog-function-select.c
index a283027..80259bd 100644
--- a/src/dialogs/dialog-function-select.c
+++ b/src/dialogs/dialog-function-select.c
@@ -655,8 +655,9 @@ make_expr_example (Sheet *sheet, const char *text, gboolean localized)
 		GnmValue *val = gnm_expr_top_eval
 			(texpr, &ep, GNM_EXPR_EVAL_PERMIT_NON_SCALAR);
 		GOFormat const *format = auto_style_format_suggest (texpr, &ep);
-		char *vtxt = format_value(format, val, NULL, -1,
-					  workbook_date_conv (sheet->workbook));
+		char *vtxt = format_value (format, val, -1,
+					   workbook_date_conv 
+					   (sheet->workbook));
 
 		go_format_unref (format);
 		gnm_expr_top_unref (texpr);
diff --git a/src/dialogs/dialog-goal-seek.c b/src/dialogs/dialog-goal-seek.c
index 678b4b1..6306895 100644
--- a/src/dialogs/dialog-goal-seek.c
+++ b/src/dialogs/dialog-goal-seek.c
@@ -413,7 +413,7 @@ cb_dialog_apply_clicked (G_GNUC_UNUSED GtkWidget *button,
 		GOFormat *format = go_format_general ();
 		GnmValue *error_value = value_new_float (state->target_value -
 						      value_get_as_float (state->set_cell->value));
-		char *target_str = format_value (format, error_value, NULL, -1,
+		char *target_str = format_value (format, error_value, -1,
 						 workbook_date_conv (state->wb));
 		gtk_label_set_text (GTK_LABEL (state->target_value_label), target_str);
 		g_free (target_str);
diff --git a/src/gnm-datetime.c b/src/gnm-datetime.c
index c517563..7ab4495 100644
--- a/src/gnm-datetime.c
+++ b/src/gnm-datetime.c
@@ -45,7 +45,7 @@ gnm_datetime_allow_negative (void)
 		GnmValue *v = value_new_int (-42);
 		GODateConventions const *conv =
 			go_date_conv_from_str ("Lotus:1900");
-		char *text = format_value (fmt, v, NULL, -1, conv);
+		char *text = format_value (fmt, v, -1, conv);
 
 		allow = (strcmp (text, "1899-11-19") == 0);
 
diff --git a/src/gnm-format.c b/src/gnm-format.c
index 1edd304..43b4346 100644
--- a/src/gnm-format.c
+++ b/src/gnm-format.c
@@ -83,7 +83,7 @@ format_value_common (PangoLayout *layout, GString *str,
 		     const GOFormatMeasure measure,
 		     const GOFontMetrics *metrics,
 		     GOFormat const *format,
-		     GnmValue const *value, GOColor *go_color,
+		     GnmValue const *value,
 		     int col_width,
 		     GODateConventions const *date_conv,
 		     gboolean unicode_minus)
@@ -142,9 +142,9 @@ format_value_common (PangoLayout *layout, GString *str,
 	}
 	err = gnm_format_value_gstring (layout, str, measure, metrics,
 					format,
-					val, type, sval,
-					go_color,
+					val, type, sval, NULL,
 					col_width, date_conv, unicode_minus);
+	
 	g_free (sval_free);
 
 	switch (err) {
@@ -167,7 +167,7 @@ GOFormatNumberError
 gnm_format_layout (PangoLayout *layout,
 		   GOFontMetrics *metrics,
 		   GOFormat const *format,
-		   GnmValue const *value, GOColor *go_color,
+		   GnmValue const *value,
 		   int col_width,
 		   GODateConventions const *date_conv,
 		   gboolean unicode_minus)
@@ -179,7 +179,7 @@ gnm_format_layout (PangoLayout *layout,
 				   go_format_measure_pango,
 				   metrics,
 				   format,
-				   value, go_color,
+				   value,
 				   col_width, date_conv, unicode_minus);
 
 	g_string_free (tmp_str, TRUE);
@@ -192,18 +192,17 @@ gnm_format_layout (PangoLayout *layout,
  * @str : append the result here.
  * @format : #GOFormat.
  * @value : #GnmValue to convert
- * @go_color : return the #GOColor to use
  * col_width : optional
  * @date_conv : #GODateConventions.
  *
  **/
 GOFormatNumberError
-format_value_gstring (GString *str, GOFormat const *format,
-		      GnmValue const *value, GOColor *go_color,
+format_value_gstring (GString *str, 
+		      GOFormat const *format,
+		      GnmValue const *value,
 		      int col_width,
 		      GODateConventions const *date_conv)
 {
-	gboolean unicode_minus = FALSE;
 	GString *tmp_str = str->len ? g_string_sized_new (100) : NULL;
 	GOFormatNumberError err;
 
@@ -211,24 +210,49 @@ format_value_gstring (GString *str, GOFormat const *format,
 				   go_format_measure_strlen,
 				   go_font_metrics_unit,
 				   format,
-				   value, go_color,
-				   col_width, date_conv, unicode_minus);
+				   value,
+				   col_width, date_conv, FALSE);
 
 	if (tmp_str) {
 		if (!err)
 			go_string_append_gstring (str, tmp_str);
 		g_string_free (tmp_str, TRUE);
 	}
-
+	
 	return err;
 }
 
+/**
+ * format_value_layout :
+ * @layout
+ * @format : #GOFormat.
+ * @value : #GnmValue to convert
+ * col_width : optional
+ * @date_conv : #GODateConventions.
+ *
+ **/
+GOFormatNumberError
+format_value_layout (PangoLayout *layout, 
+		     GOFormat const *format,
+		     GnmValue const *value,
+		     int col_width,
+		     GODateConventions const *date_conv)
+{
+	return format_value_common (layout, NULL,
+				    go_format_measure_strlen,
+				    go_font_metrics_unit,
+				    format, value,
+				    col_width, date_conv, FALSE);
+}
+
+
 gchar *
-format_value (GOFormat const *format, GnmValue const *value, GOColor *go_color,
+format_value (GOFormat const *format,
+	      GnmValue const *value,
 	      int col_width, GODateConventions const *date_conv)
 {
 	GString *result = g_string_sized_new (20);
-	format_value_gstring (result, format, value, go_color,
+	format_value_gstring (result, format, value,
 			      col_width, date_conv);
 	return g_string_free (result, FALSE);
 }
diff --git a/src/gnm-format.h b/src/gnm-format.h
index 21dd538..00a07b5 100644
--- a/src/gnm-format.h
+++ b/src/gnm-format.h
@@ -9,22 +9,25 @@
 G_BEGIN_DECLS
 
 char  *format_value	    (GOFormat const *format,
-			     GnmValue const *value, GOColor *go_color,
+			     GnmValue const *value,
 			     int col_width,
 			     GODateConventions const *date_conv);
 
 GOFormatNumberError format_value_gstring (GString *result,
 					  GOFormat const *format,
 					  GnmValue const *value,
-					  GOColor *go_color,
 					  int col_width,
 					  GODateConventions const *date_conv);
+GOFormatNumberError format_value_layout (PangoLayout *result,
+					 GOFormat const *format,
+					 GnmValue const *value,
+					 int col_width,
+					 GODateConventions const *date_conv);
 
 GOFormatNumberError gnm_format_layout    (PangoLayout *result,
 					  GOFontMetrics *metrics,
 					  GOFormat const *format,
 					  GnmValue const *value,
-					  GOColor *go_color,
 					  int col_width,
 					  GODateConventions const *date_conv,
 					  gboolean unicode_minus);
diff --git a/src/go-data-cache.c b/src/go-data-cache.c
index d3facff..1adc02f 100644
--- a/src/go-data-cache.c
+++ b/src/go-data-cache.c
@@ -304,7 +304,7 @@ go_data_cache_dump_value (GOVal const *v)
 		GOFormat const *fmt = go_val_get_fmt (v);
 
 		if (NULL != fmt) {
-			char *str = format_value (fmt, v, NULL, -1, NULL);
+			char *str = format_value (fmt, v, -1, NULL);
 			g_print ("'%s'", str);
 			g_free (str);
 		} else
diff --git a/src/graph.c b/src/graph.c
index 4f2e6b2..03bcc73 100644
--- a/src/graph.c
+++ b/src/graph.c
@@ -109,7 +109,7 @@ render_val (GnmValue const *v, int i, int j,
 	} else if (v->type == VALUE_ARRAY)
 		v = value_area_get_x_y (v, i, j, ep);
 
-	return format_value (fmt, v, NULL, -1, date_conv);
+	return format_value (fmt, v, -1, date_conv);
 }
 
 /* ------------------------------------------------------------------------- */
diff --git a/src/gui-util.c b/src/gui-util.c
index 78e67db..795348a 100644
--- a/src/gui-util.c
+++ b/src/gui-util.c
@@ -1075,7 +1075,7 @@ entry_to_float_with_format (GtkEntry *entry, gnm_float *the_float,
 
 	*the_float = value_get_as_float (value);
 	if (update) {
-		char *tmp = format_value (format, value, NULL, 16, NULL);
+		char *tmp = format_value (format, value, 16, NULL);
 		gtk_entry_set_text (entry, tmp);
 		g_free (tmp);
 	}
@@ -1110,7 +1110,7 @@ entry_to_int (GtkEntry *entry, gint *the_int, gboolean update)
 	}
 
 	if (update) {
-		char *tmp = format_value (NULL, value, NULL, 16, NULL);
+		char *tmp = format_value (NULL, value, 16, NULL);
 		gtk_entry_set_text (entry, tmp);
 		g_free (tmp);
 	}
@@ -1129,7 +1129,7 @@ void
 float_to_entry (GtkEntry *entry, gnm_float the_float)
 {
 	GnmValue *val = value_new_float (the_float);
-	char *text = format_value (NULL, val, NULL, 16, NULL);
+	char *text = format_value (NULL, val, 16, NULL);
 	value_release(val);
 	if (text != NULL) {
 		gtk_entry_set_text (entry, text);
@@ -1148,7 +1148,7 @@ void
 int_to_entry (GtkEntry *entry, gint the_int)
 {
 	GnmValue *val  = value_new_int (the_int);
-	char *text = format_value (NULL, val, NULL, 16, NULL);
+	char *text = format_value (NULL, val, 16, NULL);
 	value_release(val);
 	if (text != NULL) {
 		gtk_entry_set_text (entry, text);
diff --git a/src/print-info.c b/src/print-info.c
index 4d86f38..0d6eefd 100644
--- a/src/print-info.c
+++ b/src/print-info.c
@@ -521,7 +521,7 @@ render_timestamp_with_format (GString *target, char const *number_format, HFRend
 	/* TODO : Check this assumption.  Is it a localized format? */
 	format = go_format_new_from_XL (number_format);
 	format_value_gstring (target, format, info->date_time,
-			      NULL, -1, info->date_conv);
+			      -1, info->date_conv);
 	go_format_unref (format);
 }
 
diff --git a/src/rendered-value.c b/src/rendered-value.c
index aa53db0..eaf5c3b 100644
--- a/src/rendered-value.c
+++ b/src/rendered-value.c
@@ -1,4 +1,4 @@
-/* vim: set sw=8: */
+/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 
 /*
  * rendered-value.c: Management & utility routines for formated
@@ -162,7 +162,6 @@ gnm_rendered_value_remeasure (GnmRenderedValue *rv)
 				       &rv->layout_natural_height);
 }
 
-
 /**
  * gnm_rendered_value_new:
  * @cell:   The cell
@@ -179,7 +178,6 @@ gnm_rendered_value_new (GnmCell const *cell,
 			double zoom)
 {
 	GnmRenderedValue	*res;
-	GOColor		 fore;
 	PangoLayout     *layout;
 	PangoAttrList   *attrs;
 	int              rotation;
@@ -188,6 +186,7 @@ gnm_rendered_value_new (GnmCell const *cell,
 	GnmStyle const *mstyle;
 	PangoDirection dir;
 	char const *text;
+	PangoAttribute *attr;
 
 	g_return_val_if_fail (cell != NULL, NULL);
 
@@ -284,6 +283,14 @@ gnm_rendered_value_new (GnmCell const *cell,
 			pango_attr_list_unref (orig);
 		}
 	}
+
+	/* Add foreground color.  */
+	attr = go_color_to_pango 
+		((gnm_style_get_font_color (mstyle))->go_color, TRUE);
+	attr->start_index = 0;
+	attr->end_index = G_MAXUINT;
+	pango_attr_list_insert_before (attrs, attr);
+
 	pango_layout_set_attributes (res->layout, attrs);
 	pango_attr_list_unref (attrs);
 
@@ -326,11 +333,9 @@ gnm_rendered_value_new (GnmCell const *cell,
 			g_string_append_c (out.accum, '}');
 		pango_layout_set_text (layout, out.accum->str, out.accum->len);
 		g_string_free (out.accum, TRUE);
-		fore = 0;
 		res->might_overflow = FALSE;
 	} else if (sheet->hide_zero && gnm_cell_is_zero (cell)) {
 		pango_layout_set_text (layout, "", 0);
-		fore = 0;
 		res->might_overflow = FALSE;
 	} else {
 		int col_width = -1;
@@ -377,7 +382,7 @@ gnm_rendered_value_new (GnmCell const *cell,
 
 		err = gnm_format_layout (layout, font->go.metrics, format,
 					 cell->value,
-					 &fore, col_width, date_conv, TRUE);
+					 col_width, date_conv, TRUE);
 
 		switch (err) {
 		case GO_FORMAT_NUMBER_DATE_ERROR:
@@ -439,18 +444,6 @@ gnm_rendered_value_new (GnmCell const *cell,
 	}
 			 /* ---------------------------------------- */
 
-	/*
-	 * We store the foreground color separately because
-	 * 1. It is [used to be?] slow to store it as an attribute, see
-	 *    http://bugzilla.gnome.org/show_bug.cgi?id=105322
-	 * 2. This way we get to share the attribute list.
-	 */
-	if (0 == fore) {
-		GnmColor const *c = gnm_style_get_font_color (mstyle);
-		res->go_fore_color = c->go_color;
-	} else
-		res->go_fore_color = fore;
-
 	gnm_rendered_value_remeasure (res);
 
 	return res;
@@ -533,6 +526,43 @@ gnm_rendered_value_get_text (GnmRenderedValue const *rv)
 	return pango_layout_get_text (rv->layout);
 }
 
+static gboolean
+colour_selector_cb (PangoAttribute *attribute, PangoColor *color)
+{
+	if (attribute->start_index == 0 && 
+	    PANGO_ATTR_FOREGROUND == attribute->klass->type) {
+		*color = ((PangoAttrColor *)(attribute))->color;
+		return FALSE;
+	}
+	return FALSE;
+}
+
+static GOColor
+colour_from_layout (PangoLayout *layout)
+{
+	PangoAttrList *attrs = pango_layout_get_attributes (layout), 
+		*fattrs;
+	PangoColor c;
+
+	if (go_pango_attr_list_is_empty (attrs))
+		return 0;
+
+	fattrs = pango_attr_list_filter 
+		(attrs, (PangoAttrFilterFunc)colour_selector_cb, &c);
+
+	if (fattrs == NULL)
+		return 0;
+	pango_attr_list_unref (fattrs);
+
+	return GO_COLOR_FROM_RGBA (c.red, c.green, c.blue, 0xff);
+}
+
+GOColor 
+gnm_rendered_value_get_color (GnmRenderedValue const * rv)
+{
+	return colour_from_layout (rv->layout);
+}
+
 /* ------------------------------------------------------------------------- */
 
 static gboolean
diff --git a/src/rendered-value.h b/src/rendered-value.h
index 51a0646..bac1501 100644
--- a/src/rendered-value.h
+++ b/src/rendered-value.h
@@ -16,8 +16,6 @@ struct _GnmRenderedValue {
 	/* In pixels:  */
 	guint16 indent_left, indent_right;
 
-	GOColor go_fore_color;
-
 	guint effective_halign : 8;
 	guint effective_valign : 5;
 	guint variable_width : 1;   /* result depends on the width of cell */
@@ -53,6 +51,8 @@ void              gnm_rendered_value_remeasure (GnmRenderedValue *rv);
 /* Return the value as a single string without format infomation.  */
 char const *gnm_rendered_value_get_text (GnmRenderedValue const * rv);
 
+GOColor gnm_rendered_value_get_color (GnmRenderedValue const * rv);
+
 /* ------------------------------------------------------------------------- */
 
 struct _GnmRenderedValueCollection {
diff --git a/src/sheet-autofill.c b/src/sheet-autofill.c
index abea9dd..d0b1771 100644
--- a/src/sheet-autofill.c
+++ b/src/sheet-autofill.c
@@ -217,7 +217,7 @@ afa_hint (AutoFiller *af, GnmCellPos *pos, int n)
 {
 	AutoFillerArithmetic *afa = (AutoFillerArithmetic *)af;
 	GnmValue *v = afa_compute (afa, n);
-	char *res = format_value (NULL, v, NULL, -1, afa->dateconv);
+	char *res = format_value (NULL, v, -1, afa->dateconv);
 	value_release (v);
 	return res;
 }
@@ -627,7 +627,7 @@ afm_hint (AutoFiller *af, GnmCellPos *pos, int n)
 	char *res = NULL;
 
 	if (v) {
-		res = format_value (NULL, v, NULL, -1, afm->dateconv);
+		res = format_value (NULL, v, -1, afm->dateconv);
 		value_release (v);
 	}
 
@@ -904,7 +904,7 @@ afc_set_cell_hint (AutoFiller *af, GnmCell *cell, GnmCellPos const *pos,
 			GODateConventions const *dateconv =
 				workbook_date_conv (sheet->workbook);
 			GOFormat const *format = gnm_cell_get_format (src);
-			return format_value (format, src->value, NULL, -1,
+			return format_value (format, src->value, -1,
 					     dateconv);
 		}
 	} else {
diff --git a/src/sheet-filter.c b/src/sheet-filter.c
index ecb9afa..82d2f0b 100644
--- a/src/sheet-filter.c
+++ b/src/sheet-filter.c
@@ -173,7 +173,7 @@ filter_cell_contents (GnmCell *cell)
 	GOFormat const *format = gnm_cell_get_format (cell);
 	GODateConventions const *date_conv =
 		workbook_date_conv (cell->base.sheet->workbook);
-	return format_value (format, cell->value, NULL, -1, date_conv);
+	return format_value (format, cell->value, -1, date_conv);
 }
 
 static gboolean
@@ -210,7 +210,7 @@ filter_expr_eval (GnmFilterOp op, GnmValue const *src, GORegexp const *regexp,
 	if (VALUE_IS_STRING (target) && VALUE_IS_NUMBER (src)) {
 		GODateConventions const *date_conv =
 			workbook_date_conv (cell->base.sheet->workbook);
-		char *str = format_value (NULL, src, NULL, -1, date_conv);
+		char *str = format_value (NULL, src, -1, date_conv);
 		fake_val = value_new_string_nocopy (str);
 		src = fake_val;
 	}
diff --git a/src/sheet-object-widget.c b/src/sheet-object-widget.c
index 9d6b654..0bc28bc 100644
--- a/src/sheet-object-widget.c
+++ b/src/sheet-object-widget.c
@@ -3392,7 +3392,7 @@ cb_collect (GnmValueIter const *iter, GtkListStore *model)
 	if (NULL != iter->v) {
 		GOFormat const *fmt = (NULL != iter->cell_iter)
 			? gnm_cell_get_format (iter->cell_iter->cell) : NULL;
-		char *label = format_value (fmt, iter->v, NULL, -1, NULL);
+		char *label = format_value (fmt, iter->v, -1, NULL);
 		gtk_list_store_set (model, &list_iter, 0, label, -1);
 		g_free (label);
 	} else
diff --git a/src/stf-export.c b/src/stf-export.c
index 93dbff0..8785fac 100644
--- a/src/stf-export.c
+++ b/src/stf-export.c
@@ -155,7 +155,7 @@ try_auto_float (GnmValue *value, const GOFormat *format,
 	if (is_date || is_time > 0)
 		return NULL;
 
-	return format_value (go_format_general (), value, NULL, -1, date_conv);
+	return format_value (go_format_general (), value, -1, date_conv);
 }
 
 
@@ -209,7 +209,7 @@ try_auto_date (GnmValue *value, const GOFormat *format,
 	}
 	actual = go_format_new_from_XL (xlfmt->str);
 	g_string_free (xlfmt, TRUE);
-	res = format_value (actual, value, NULL, -1, date_conv);
+	res = format_value (actual, value, -1, date_conv);
 	go_format_unref (actual);
 
 	return res;
diff --git a/src/stf.c b/src/stf.c
index 74752a5..2c90cbe 100644
--- a/src/stf.c
+++ b/src/stf.c
@@ -301,7 +301,7 @@ cb_get_content (GnmCellIter const *iter, GsfOutput *buf)
 			tmp = gnm_expr_top_as_string (cell->base.texpr,
 				&iter->pp, iter->pp.sheet->convs);
 		else if (VALUE_FMT (cell->value) != NULL)
-			tmp = format_value (NULL, cell->value, NULL, -1,
+			tmp = format_value (NULL, cell->value, -1,
 				workbook_date_conv (iter->pp.wb));
 		else
 			tmp = value_get_as_string (cell->value);
diff --git a/src/tools/tabulate.c b/src/tools/tabulate.c
index a028124..8da887c 100644
--- a/src/tools/tabulate.c
+++ b/src/tools/tabulate.c
@@ -120,7 +120,7 @@ do_tabulation (WorkbookControl *wbc,
 		sheets = g_new (Sheet *, counts[dim]);
 		for (i = 0; i < counts[dim]; i++) {
 			GnmValue *v = value_new_float (val);
-			char *base_name = format_value (sf, v, NULL, -1,
+			char *base_name = format_value (sf, v, -1,
 						workbook_date_conv (wb));
 			char *unique_name =
 				workbook_sheet_get_free_name (wb,
diff --git a/src/wbc-gtk-actions.c b/src/wbc-gtk-actions.c
index 43a53a6..b5b5c40 100644
--- a/src/wbc-gtk-actions.c
+++ b/src/wbc-gtk-actions.c
@@ -820,13 +820,13 @@ insert_date_time_common (WBCGtk *wbcg, gboolean do_date, gboolean do_time)
 
 		if (do_date) {
 			GOFormat *fmt = gnm_format_for_date_editing (cell);
-			dtxt = format_value (fmt, v, NULL, -1, date_conv);
+			dtxt = format_value (fmt, v, -1, date_conv);
 			go_format_unref (fmt);
 		}
 
 		if (do_time) {
 			GOFormat const *fmt = go_format_default_time ();
-			ttxt = format_value (fmt, v, NULL, -1, date_conv);
+			ttxt = format_value (fmt, v, -1, date_conv);
 		}
 
 		if (do_date && do_time) {
diff --git a/src/wbc-gtk-edit.c b/src/wbc-gtk-edit.c
index 364765b..70fd46f 100644
--- a/src/wbc-gtk-edit.c
+++ b/src/wbc-gtk-edit.c
@@ -1036,12 +1036,12 @@ wbcg_edit_start (WBCGtk *wbcg,
 				}
 
 				text = format_value (new_fmt, cell->value,
-						     NULL, -1, date_conv);
+						     -1, date_conv);
 				if (!text || text[0] == 0) {
 					g_free (text);
 					text = format_value (go_format_general (),
 							     cell->value,
-							     NULL, -1,
+							     -1,
 							     date_conv);
 				}
 				set_text = TRUE;
@@ -1052,7 +1052,7 @@ wbcg_edit_start (WBCGtk *wbcg,
 			case GO_FORMAT_TIME: {
 				GOFormat *new_fmt = guess_time_format (NULL, f);
 
-				text = format_value (new_fmt, cell->value, NULL, -1,
+				text = format_value (new_fmt, cell->value, -1,
 						     workbook_date_conv (sv->sheet->workbook));
 				set_text = TRUE;
 				go_format_unref (new_fmt);
diff --git a/src/widgets/gnm-filter-combo-view.c b/src/widgets/gnm-filter-combo-view.c
index 9157a51..47da1cd 100644
--- a/src/widgets/gnm-filter-combo-view.c
+++ b/src/widgets/gnm-filter-combo-view.c
@@ -125,7 +125,7 @@ cb_collect_content (GnmCellIter const *iter, UniqueCollection *uc)
 		GnmValue const *v   = cell->value;
 		g_hash_table_replace (uc->hash,
 			value_dup (v),
-			format_value (fmt, v, NULL, -1, uc->date_conv));
+			format_value (fmt, v, -1, uc->date_conv));
 	}
 
 	return NULL;
diff --git a/src/widgets/gnm-format-sel.c b/src/widgets/gnm-format-sel.c
index 536e94e..e3fdfda 100644
--- a/src/widgets/gnm-format-sel.c
+++ b/src/widgets/gnm-format-sel.c
@@ -21,18 +21,37 @@
 #include "gnm-format-sel.h"
 #include "src/value.h"
 #include "src/gnm-format.h"
+#include "src/style-font.h"
 
 static char *
-cb_generate_preview (GOFormatSel *gfs, GOColor *c)
+cb_generate_preview (GOFormatSel *gfs, PangoAttrList **attrs)
 {
 	GnmValue const *v = g_object_get_data (G_OBJECT (gfs), "value");
-	GOFormat const *fmt = go_format_sel_get_fmt (gfs);
 
 	if (NULL == v)
 		return NULL;
-	if (go_format_is_general (fmt) && VALUE_FMT (v) != NULL)
-		fmt = VALUE_FMT (v);
-	return format_value (fmt, v, c, -1, go_format_sel_get_dateconv (gfs));
+	else {
+		GOFormat const *fmt = go_format_sel_get_fmt (gfs);
+		PangoContext *context = gnm_pango_context_get ();
+		PangoLayout *layout = pango_layout_new (context);
+		char *str;
+		GOFormatNumberError err;
+
+		if (go_format_is_general (fmt) && VALUE_FMT (v) != NULL)
+			fmt = VALUE_FMT (v);
+		err = format_value_layout (layout, fmt, v, -1, 
+					   go_format_sel_get_dateconv (gfs));
+		if (err) {
+			str = NULL;
+			*attrs = NULL;
+		} else {
+			str = g_strdup (pango_layout_get_text (layout));
+			*attrs = pango_attr_list_ref (pango_layout_get_attributes (layout));
+		}
+		g_object_unref (layout);
+		g_object_unref (context);
+		return str;
+	}
 }
 
 GtkWidget *
diff --git a/src/widgets/gnm-sheet-slicer-combo-view.c b/src/widgets/gnm-sheet-slicer-combo-view.c
index 3982f5e..a1dc1e2 100644
--- a/src/widgets/gnm-sheet-slicer-combo-view.c
+++ b/src/widgets/gnm-sheet-slicer-combo-view.c
@@ -114,7 +114,7 @@ sscombo_create_list (SheetObject *so,
 		gtk_list_store_append (model, &iter);
 		if (VALUE_IS_EMPTY(v))
 			g_string_assign (str, _("<Blank>"));
-		else if (GO_FORMAT_NUMBER_OK != format_value_gstring (str, NULL, v, NULL, -1, dconv))
+		else if (GO_FORMAT_NUMBER_OK != format_value_gstring (str, NULL, v, -1, dconv))
 			g_string_assign (str, "<ERROR>");
 		gtk_list_store_set (model, &iter, 0, TRUE, 1, str->str, -1);
 		g_string_truncate (str, 0);
diff --git a/src/widgets/gnm-validation-combo-view.c b/src/widgets/gnm-validation-combo-view.c
index 9976bf5..90bccbf 100644
--- a/src/widgets/gnm-validation-combo-view.c
+++ b/src/widgets/gnm-validation-combo-view.c
@@ -77,7 +77,7 @@ cb_collect_unique (GnmValueIter const *iter, UniqueCollection *uc)
 		? gnm_cell_get_format (iter->cell_iter->cell) : NULL;
 	g_hash_table_replace (uc->hash,
 		value_dup (iter->v),
-		format_value (fmt, iter->v, NULL, -1, uc->date_conv));
+		format_value (fmt, iter->v, -1, uc->date_conv));
 	return NULL;
 }
 
diff --git a/src/widgets/gnumeric-expr-entry.c b/src/widgets/gnumeric-expr-entry.c
index 3246769..b38452f 100644
--- a/src/widgets/gnumeric-expr-entry.c
+++ b/src/widgets/gnumeric-expr-entry.c
@@ -1487,7 +1487,7 @@ gee_set_value_double (GogDataEditor *editor, double val,
 {
 	GnmExprEntry *gee = GNM_EXPR_ENTRY (editor);
 	GnmValue *v = value_new_float (val);
-	char *txt = format_value (gee->constant_format, v, NULL, -1, date_conv);
+	char *txt = format_value (gee->constant_format, v, -1, date_conv);
 
 	value_release (v);
 
@@ -1521,7 +1521,7 @@ gee_data_editor_set_format (GogDataEditor *deditor, GOFormat const *fmt)
 
 	if (v && VALUE_IS_FLOAT (v)) {
 		char *txt = format_value (gee->constant_format, v,
-					  NULL, -1, date_conv);
+					  -1, date_conv);
 		gtk_entry_set_text (gee->entry, txt);
 		g_free (txt);
 	}
@@ -2503,7 +2503,7 @@ gnm_expr_entry_parse (GnmExprEntry *gee, GnmParsePos const *pp,
 			GODateConventions const *date_conv =
 				workbook_date_conv (gee->sheet->workbook);
 			GnmExprTop const *texpr = gnm_expr_top_new_constant (v);
-			char *str = format_value (gee->constant_format, v, NULL, -1, date_conv);
+			char *str = format_value (gee->constant_format, v, -1, date_conv);
 			if (gee_debug)
 				g_printerr ("Setting entry text: [%s]\n", str);
 			gtk_entry_set_text (gee->entry, str);
diff --git a/src/widgets/gnumeric-text-view.c b/src/widgets/gnumeric-text-view.c
index b8542b2..40a591e 100644
--- a/src/widgets/gnumeric-text-view.c
+++ b/src/widgets/gnumeric-text-view.c
@@ -421,13 +421,6 @@ GSF_CLASS (GnmTextView, gnm_text_view,
 
 /**
  * gnm_text_view_new:
- * @wbcg : #WBCGtk non-NULL
- * @with_icon : append a rollup icon to the end of the entry
- *
- * Creates a new #GnmTextView, which is an entry widget with support
- * for range selections.
- * The entry is created with default flag settings which are suitable for use
- * in many dialogs, but see #gnm_text_view_set_flags.
  *
  * Return value: a new #GnmTextView.
  **/
diff --git a/src/workbook-view.c b/src/workbook-view.c
index 089e4b6..3ee529c 100644
--- a/src/workbook-view.c
+++ b/src/workbook-view.c
@@ -30,6 +30,7 @@
 #include "sheet-view.h"
 #include "sheet-merge.h"
 #include "sheet-style.h"
+#include "style-font.h"
 #include "gnm-format.h"
 #include "func.h"
 #include "expr.h"
@@ -518,7 +519,7 @@ wb_view_auto_expr_recalc (WorkbookView *wbv)
 		GString *str = g_string_new (wbv->auto_expr_descr);
 		GOFormat const *format = NULL;
 		GOFormat const *tmp_format = NULL;
-		PangoAttrList *attrs;
+		PangoAttrList *attrs = NULL;
 
 		g_string_append_c (str, '=');
 		if (!wbv->auto_expr_use_max_precision) {
@@ -529,26 +530,32 @@ wb_view_auto_expr_recalc (WorkbookView *wbv)
 		}
 
 		if (format) {
-			GOColor color;
-			PangoAttribute *attr;
+			PangoContext *context = gnm_pango_context_get ();
+			PangoLayout *layout = pango_layout_new (context);
+			PangoAttrList *atl;
 			gsize old_len = str->len;
-
-			format_value_gstring (str, format, v, &color,
-					      /* Note that we created a label large enough for */
-					      /* "Sumerage=-012345678901234" */
-					      25 - g_utf8_strlen (str->str, -1),
-					      workbook_date_conv (wb_view_get_workbook (wbv)));
+			GOFormatNumberError err =
+				format_value_layout (layout, format, v,
+						     /* Note that we created a label large enough for */
+						     /* "Sumerage=-012345678901234" */
+						     25 - g_utf8_strlen (str->str, -1),
+						     workbook_date_conv (wb_view_get_workbook (wbv)));
 			go_format_unref (tmp_format);
-
-			attrs = pango_attr_list_new ();
-			attr = go_color_to_pango (color, TRUE);
-			attr->start_index = old_len;
-			attr->end_index = str->len;
-			pango_attr_list_insert (attrs, attr);
-		} else {
+			if (!err) {
+				g_string_append (str, pango_layout_get_text (layout));
+				/* We need to shift the attribute list  */
+				atl = pango_attr_list_ref (pango_layout_get_attributes (layout));
+				attrs = pango_attr_list_new ();
+				pango_attr_list_splice 
+					(attrs, atl, old_len, 
+					 str->len - old_len);
+				pango_attr_list_unref (atl);
+			} else 
+				g_string_append (str,  "Internal ERROR!");
+			g_object_unref (layout);
+			g_object_unref (context);
+		} else
 			g_string_append (str, value_peek_string (v));
-			attrs = NULL;
-		}
 
 		g_object_set (wbv,
 			      "auto-expr-text", str->str,



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