[goffice] GOFormat: add go_format_generate_currency_str.
- From: Morten Welinder <mortenw src gnome org>
- To: svn-commits-list gnome org
- Subject: [goffice] GOFormat: add go_format_generate_currency_str.
- Date: Wed, 27 May 2009 22:24:02 -0400 (EDT)
commit d30f55d5542d19c5cbb3ae6cdc159143f8a7f32e
Author: Morten Welinder <terra gnome org>
Date: Wed May 27 22:23:33 2009 -0400
GOFormat: add go_format_generate_currency_str.
---
ChangeLog | 8 +++--
goffice/gtk/go-format-sel.c | 74 ++++++++++++------------------------------
goffice/utils/go-format.c | 59 ++++++++++++++++++++++++++++++++++
goffice/utils/go-format.h | 7 ++++
4 files changed, 92 insertions(+), 56 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 73f4d48..7883361 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,14 +4,16 @@
go_format_generate_number_str.
(generate_accounting, generate_format): Use
go_format_generate_number_str, go_format_generate_scientific_str,
- and go_format_generate_accounting_str.
+ go_format_generate_accounting_str, and
+ go_format_generate_currency_str.
(fillin_negative_samples): Select using iterator, not path.
(nfs_init): Split negative_type into negative_red and
negative_paren in the negative-types model.
* goffice/utils/go-format.c (go_format_generate_number_str,
- go_format_generate_scientific_str, go_format_generate_accounting_str):
- New functions.
+ go_format_generate_scientific_str,
+ go_format_generate_accounting_str,
+ go_format_generate_currency_str): New functions.
2009-05-27 Andreas J. Guelzow <aguelzow pyrshep ca>
diff --git a/goffice/gtk/go-format-sel.c b/goffice/gtk/go-format-sel.c
index b7d6e57..b1cab88 100644
--- a/goffice/gtk/go-format-sel.c
+++ b/goffice/gtk/go-format-sel.c
@@ -172,48 +172,6 @@ static guint go_format_sel_signals [LAST_SIGNAL] = { 0 };
static void format_entry_set_text (GOFormatSel *gfs, const gchar *text);
-static void
-generate_number (GString *dst,
- int num_decimals,
- gboolean thousands_sep,
- int symbol,
- gboolean force_quoted,
- gboolean negative_red, gboolean negative_paren)
-{
- GString *prefix = NULL;
- GString *postfix = NULL;
-
- if (symbol != 0) {
- gboolean precedes = go_format_currencies[symbol].precedes;
- gboolean has_space = go_format_currencies[symbol].has_space;
- const char *symstr = go_format_currencies[symbol].symbol;
- gboolean extra_quotes = (force_quoted && symstr[0] != '"');
-
- if (precedes) {
- prefix = g_string_new (NULL);
- if (extra_quotes) g_string_append_c (prefix, '"');
- g_string_append (prefix, symstr);
- if (extra_quotes) g_string_append_c (prefix, '"');
- if (has_space) g_string_append_c (prefix, ' ');
- } else {
- postfix = g_string_new (NULL);
- if (has_space)
- g_string_append_c (postfix, ' ');
- if (extra_quotes) g_string_append_c (postfix, '"');
- g_string_append (postfix, symstr);
- if (extra_quotes) g_string_append_c (postfix, '"');
- }
- }
-
- go_format_generate_number_str (dst, num_decimals, thousands_sep,
- negative_red, negative_paren,
- prefix ? prefix->str : NULL,
- postfix ? postfix->str : NULL);
-
- if (prefix) g_string_free (prefix, TRUE);
- if (postfix) g_string_free (postfix, TRUE);
-}
-
static char *
generate_format (GOFormatSel *gfs, GOFormatFamily page)
{
@@ -234,13 +192,14 @@ generate_format (GOFormatSel *gfs, GOFormatFamily page)
NULL, NULL);
break;
case GO_FORMAT_CURRENCY:
- generate_number (fmt,
- gfs->format.num_decimals,
- gfs->format.use_separator,
- gfs->format.currency_index,
- gfs->format.force_quoted,
- gfs->format.negative_red,
- gfs->format.negative_paren);
+ go_format_generate_currency_str
+ (fmt,
+ gfs->format.num_decimals,
+ gfs->format.use_separator,
+ gfs->format.negative_red,
+ gfs->format.negative_paren,
+ go_format_currencies + gfs->format.currency_index,
+ gfs->format.force_quoted);
break;
case GO_FORMAT_ACCOUNTING:
go_format_generate_accounting_str
@@ -340,12 +299,21 @@ fillin_negative_samples (GOFormatSel *gfs)
gboolean negative_red = (i & 1) != 0;
gboolean negative_paren = (i & 2) != 0;
- generate_number (fmtstr,
+ if (page == GO_FORMAT_NUMBER)
+ go_format_generate_number_str
+ (fmtstr, gfs->format.num_decimals,
+ gfs->format.use_separator,
+ negative_red, negative_paren,
+ NULL, NULL);
+ else
+ go_format_generate_currency_str
+ (fmtstr,
gfs->format.num_decimals,
gfs->format.use_separator,
- page == GO_FORMAT_NUMBER ? 0 : gfs->format.currency_index,
- gfs->format.force_quoted,
- negative_red, negative_paren);
+ negative_red, negative_paren,
+ go_format_currencies + gfs->format.currency_index,
+ gfs->format.force_quoted);
+
fmt = go_format_new_from_XL (fmtstr->str);
g_string_free (fmtstr, TRUE);
buf = go_format_value (fmt, -3210.123456789);
diff --git a/goffice/utils/go-format.c b/goffice/utils/go-format.c
index 136918f..18d7bba 100644
--- a/goffice/utils/go-format.c
+++ b/goffice/utils/go-format.c
@@ -5064,6 +5064,65 @@ go_format_generate_accounting_str (GString *dst,
}
#endif
+#ifdef DEFINE_COMMON
+/**
+ * go_format_generate_currency_str:
+ * @dst: GString to append format string to.
+ * @num_decimals: number of decimals.
+ * @thousands_sep: if true, use a thousands separator.
+ * @negative_red: if true, make negative values red.
+ * @negative_paren: if true, enclose negative values in parentheses.
+ * @currency: currency descriptor.
+ * @force_quoted: if true, make sure the currency symbol is quoted.
+ *
+ * Generates a format string for a currency format with the given
+ * parameters and appends it to @dst.
+ **/
+void
+go_format_generate_currency_str (GString *dst,
+ int num_decimals,
+ gboolean thousands_sep,
+ gboolean negative_red,
+ gboolean negative_paren,
+ GOFormatCurrency const *currency,
+ gboolean force_quoted)
+{
+ GString *prefix = NULL;
+ GString *postfix = NULL;
+ gboolean extra_quotes;
+
+ if (!currency)
+ currency = &go_format_currencies[0];
+
+ extra_quotes = (force_quoted &&
+ currency->symbol[0] != '"' &&
+ currency->symbol[0] != 0);
+
+ if (currency->precedes) {
+ prefix = g_string_new (NULL);
+ if (extra_quotes) g_string_append_c (prefix, '"');
+ g_string_append (prefix, currency->symbol);
+ if (extra_quotes) g_string_append_c (prefix, '"');
+ if (currency->has_space) g_string_append_c (prefix, ' ');
+ } else {
+ postfix = g_string_new (NULL);
+ if (currency->has_space)
+ g_string_append_c (postfix, ' ');
+ if (extra_quotes) g_string_append_c (postfix, '"');
+ g_string_append (postfix, currency->symbol);
+ if (extra_quotes) g_string_append_c (postfix, '"');
+ }
+
+ go_format_generate_number_str (dst, num_decimals, thousands_sep,
+ negative_red, negative_paren,
+ prefix ? prefix->str : NULL,
+ postfix ? postfix->str : NULL);
+
+ if (prefix) g_string_free (prefix, TRUE);
+ if (postfix) g_string_free (postfix, TRUE);
+}
+#endif
+
/********************* GOFormat ODF Support ***********************/
#define STYLE "style:"
diff --git a/goffice/utils/go-format.h b/goffice/utils/go-format.h
index dfe9722..a0bdd14 100644
--- a/goffice/utils/go-format.h
+++ b/goffice/utils/go-format.h
@@ -128,6 +128,13 @@ void go_format_generate_scientific_str (GString *dst,
void go_format_generate_accounting_str (GString *dst,
int num_decimals,
GOFormatCurrency const *currency);
+void go_format_generate_currency_str (GString *dst,
+ int num_decimals,
+ gboolean thousands_sep,
+ gboolean negative_red,
+ gboolean negative_paren,
+ GOFormatCurrency const *currency,
+ gboolean force_quoted);
char *go_format_str_localize (char const *str);
char *go_format_str_delocalize (char const *str);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]