[goffice] GOFormat: allow red etc. for percentages too.



commit 257e8a72ec227076cf2c2615f5d01b279b9af376
Author: Morten Welinder <terra gnome org>
Date:   Sat May 30 11:51:54 2009 -0400

    GOFormat: allow red etc. for percentages too.
---
 ChangeLog                   |   12 ++++++++++++
 goffice/gtk/go-format-sel.c |   36 +++++++++++++++++++++++++-----------
 goffice/utils/go-format.c   |    8 ++++++--
 goffice/utils/go-format.h   |    4 ++--
 4 files changed, 45 insertions(+), 15 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 8169e7d..26269d0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2009-05-30  Morten Welinder  <terra gnome org>
+
+	* goffice/utils/go-format.c (go_format_generate_str): Handle
+	thousands_sep as well as negative value properties for percentages
+	too.
+
+	* goffice/gtk/go-format-sel.c (fillin_negative_samples): Use
+	smaller sample value for percentages.
+	(cb_decimals_changed, cb_separator_toggle,
+	cb_format_currency_select): Call fillin_negative_samples when we
+	have the F_NEGATIVE widget.
+
 2009-05-30  Andreas J. Guelzow  <aguelzow pyrshep ca>
 
 	* goffice/utils/go-format.h (go_format_odf_style_map): simplify
diff --git a/goffice/gtk/go-format-sel.c b/goffice/gtk/go-format-sel.c
index 737e7b3..aaf6015 100644
--- a/goffice/gtk/go-format-sel.c
+++ b/goffice/gtk/go-format-sel.c
@@ -224,17 +224,27 @@ draw_format_preview (GOFormatSel *gfs, gboolean regen_format)
 static void
 fillin_negative_samples (GOFormatSel *gfs)
 {
-	GOFormatFamily const page = gfs->format.current_type;
 	int i;
 	GtkTreeIter iter;
 	gboolean more;
 	GOFormatDetails details = gfs->format.details;
+	double sample_value;
 	SETUP_LOCALE_SWITCH;
 
-	g_return_if_fail (page == GO_FORMAT_NUMBER || page == GO_FORMAT_CURRENCY);
-
 	START_LOCALE_SWITCH;
 
+	switch (gfs->format.current_type) {
+	case GO_FORMAT_DATE:
+		g_assert_not_reached ();
+		return;
+	case GO_FORMAT_PERCENTAGE:
+		sample_value = -0.123456;
+		break;
+	default:
+		sample_value = -3210.12345678;
+		break;
+	}
+
 	more = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (gfs->format.negative_types.model), &iter);
 	for (i = 0 ; i < 4; i++) {
 		GString *fmtstr = g_string_new (NULL);
@@ -247,7 +257,7 @@ fillin_negative_samples (GOFormatSel *gfs)
 		go_format_generate_str (fmtstr, &details);
 		fmt = go_format_new_from_XL (fmtstr->str);
 		g_string_free (fmtstr, TRUE);
-		buf = go_format_value (fmt, -3210.123456789);
+		buf = go_format_value (fmt, sample_value);
 		go_format_unref (fmt);
 
 		if (!more)
@@ -277,11 +287,10 @@ fillin_negative_samples (GOFormatSel *gfs)
 static void
 cb_decimals_changed (GtkSpinButton *spin, GOFormatSel *gfs)
 {
-	GOFormatFamily const page = gfs->format.current_type;
-
-	gfs->format.details.num_decimals = gtk_spin_button_get_value_as_int (spin);
+	gfs->format.details.num_decimals =
+		gtk_spin_button_get_value_as_int (spin);
 
-	if (page == GO_FORMAT_NUMBER || page == GO_FORMAT_CURRENCY)
+	if (GTK_WIDGET_VISIBLE (gfs->format.widget[F_NEGATIVE]))
 		fillin_negative_samples (gfs);
 
 	draw_format_preview (gfs, TRUE);
@@ -292,7 +301,9 @@ cb_separator_toggle (GtkObject *obj, GOFormatSel *gfs)
 {
 	gfs->format.details.thousands_sep =
 		gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (obj));
-	fillin_negative_samples (gfs);
+
+	if (GTK_WIDGET_VISIBLE (gfs->format.widget[F_NEGATIVE]))
+		fillin_negative_samples (gfs);
 
 	draw_format_preview (gfs, TRUE);
 }
@@ -448,6 +459,10 @@ fmt_dialog_enable_widgets (GOFormatSel *gfs, int page)
 			F_PERCENTAGE_EXPLANATION,
 			F_DECIMAL_LABEL,
 			F_DECIMAL_SPIN,
+			F_SEPARATOR,
+			F_NEGATIVE_LABEL,
+			F_NEGATIVE_SCROLL,
+			F_NEGATIVE,
 			F_MAX_WIDGET
 		},
 		/* Fraction */
@@ -744,8 +759,7 @@ cb_format_currency_select (G_GNUC_UNUSED GtkWidget *ct,
 		}
 	}
 
-	if (gfs->format.current_type == GO_FORMAT_NUMBER ||
-	    gfs->format.current_type == GO_FORMAT_CURRENCY)
+	if (GTK_WIDGET_VISIBLE (gfs->format.widget[F_NEGATIVE]))
 		fillin_negative_samples (gfs);
 
 	draw_format_preview (gfs, TRUE);
diff --git a/goffice/utils/go-format.c b/goffice/utils/go-format.c
index a03a69e..bdf0aa0 100644
--- a/goffice/utils/go-format.c
+++ b/goffice/utils/go-format.c
@@ -5230,8 +5230,12 @@ go_format_generate_str (GString *dst, GOFormatDetails const *details)
 		break;
 	case GO_FORMAT_PERCENTAGE:
 		go_format_generate_number_str
-			(dst, details->num_decimals,
-			 FALSE, FALSE, FALSE, NULL, "%");
+			(dst,
+			 details->num_decimals,
+			 details->thousands_sep,
+			 details->negative_red,
+			 details->negative_paren,
+			 NULL, "%");
 		break;
 	case GO_FORMAT_SCIENTIFIC:
 		go_format_generate_scientific_str
diff --git a/goffice/utils/go-format.h b/goffice/utils/go-format.h
index 57996f6..8595311 100644
--- a/goffice/utils/go-format.h
+++ b/goffice/utils/go-format.h
@@ -83,10 +83,10 @@ typedef struct {
 	/* NUMBER, SCIENTIFIC, CURRENCY, ACCOUNTING, PERCENTAGE: */
 	int num_decimals;
 
-	/* NUMBER, CURRENCY: */
+	/* NUMBER, CURRENCY, PERCENTAGE: */
 	gboolean thousands_sep;
 
-	/* NUMBER, CURRENCY, ACCOUNTING: */
+	/* NUMBER, CURRENCY, ACCOUNTING, PERCENTAGE: */
 	gboolean negative_red;
 	gboolean negative_paren;
 



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