[goffice] GOFormat: New function go_format_generate_accounting_str.
- From: Morten Welinder <mortenw src gnome org>
- To: svn-commits-list gnome org
- Subject: [goffice] GOFormat: New function go_format_generate_accounting_str.
- Date: Wed, 27 May 2009 21:51:52 -0400 (EDT)
commit 893e0508c7352da8981241bd31e8a83858bc0a4e
Author: Morten Welinder <welinder anemone home>
Date: Wed May 27 21:51:30 2009 -0400
GOFormat: New function go_format_generate_accounting_str.
---
ChangeLog | 7 ++--
goffice/gtk/go-format-sel.c | 58 ++--------------------------------
goffice/utils/go-format.c | 72 +++++++++++++++++++++++++++++++++++++++++++
goffice/utils/go-format.h | 17 ++++++----
4 files changed, 89 insertions(+), 65 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index e99d89c..73f4d48 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,14 +3,15 @@
* goffice/gtk/go-format-sel.c (generate_number): Simplify using
go_format_generate_number_str.
(generate_accounting, generate_format): Use
- go_format_generate_number_str and
- go_format_generate_scientific_str.
+ go_format_generate_number_str, go_format_generate_scientific_str,
+ and go_format_generate_accounting_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): New functions.
+ go_format_generate_scientific_str, go_format_generate_accounting_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 aba13fc..b7d6e57 100644
--- a/goffice/gtk/go-format-sel.c
+++ b/goffice/gtk/go-format-sel.c
@@ -214,58 +214,6 @@ generate_number (GString *dst,
if (postfix) g_string_free (postfix, TRUE);
}
-static void
-generate_accounting (GString *dst,
- int num_decimals,
- int symbol)
-{
- GString *num = g_string_new (NULL);
- GString *sym = g_string_new (NULL);
- GString *q = g_string_new (NULL);
-
- gboolean precedes = go_format_currencies[symbol].precedes;
- gboolean has_space = go_format_currencies[symbol].has_space;
- const char *symstr = go_format_currencies[symbol].symbol;
- const char *quote = symstr[0] != '[' ? "\"" : "";
-
- go_format_generate_number_str (num, num_decimals, TRUE,
- FALSE, FALSE, NULL, NULL);
- go_string_append_c_n (q, '?', num_decimals);
-
- if (precedes) {
- g_string_append (sym, quote);
- g_string_append (sym, symstr);
- g_string_append (sym, quote);
- g_string_append (sym, "* ");
- if (has_space) g_string_append_c (sym, ' ');
-
- g_string_append_printf
- (dst,
- "_(%s%s_);_(%s(%s);_(%s\"-\"%s_);_(@_)",
- sym->str, num->str,
- sym->str, num->str,
- sym->str, q->str);
- } else {
- g_string_append (sym, "* ");
- if (has_space) g_string_append_c (sym, ' ');
- g_string_append (sym, quote);
- g_string_append (sym, symstr);
- g_string_append (sym, quote);
-
- g_string_append_printf
- (dst,
- "_(%s%s_);_((%s)%s;_(\"-\"%s%s_);_(@_)",
- num->str, sym->str,
- num->str, sym->str,
- q->str, sym->str);
- }
-
- g_string_free (num, TRUE);
- g_string_free (q, TRUE);
- g_string_free (sym, TRUE);
-}
-
-
static char *
generate_format (GOFormatSel *gfs, GOFormatFamily page)
{
@@ -295,9 +243,9 @@ generate_format (GOFormatSel *gfs, GOFormatFamily page)
gfs->format.negative_paren);
break;
case GO_FORMAT_ACCOUNTING:
- generate_accounting (fmt,
- gfs->format.num_decimals,
- gfs->format.currency_index);
+ go_format_generate_accounting_str
+ (fmt, gfs->format.num_decimals,
+ go_format_currencies + gfs->format.currency_index);
break;
case GO_FORMAT_PERCENTAGE:
go_format_generate_number_str
diff --git a/goffice/utils/go-format.c b/goffice/utils/go-format.c
index cc80a15..136918f 100644
--- a/goffice/utils/go-format.c
+++ b/goffice/utils/go-format.c
@@ -4912,6 +4912,11 @@ go_format_default_accounting (void)
* @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.
+ * @prefix: optional string to place before number part of the format
+ * @postfix: optional string to place after number part of the format
+ *
+ * Generates a format string for a number format with the given
+ * parameters and appends it to @dst.
**/
void
go_format_generate_number_str (GString *dst,
@@ -4965,6 +4970,9 @@ go_format_generate_number_str (GString *dst,
* @exponent_step: pick exponent divisible by them. Typically 1 or 3.
* @use_markup: if true, use pango markup for exponent.
* @simplify_mantissa: if true, avoid pointless "1*" mantissas.
+ *
+ * Generates a format string for a scientific format with the given
+ * parameters and appends it to @dst.
**/
void
go_format_generate_scientific_str (GString *dst,
@@ -4989,7 +4997,71 @@ go_format_generate_scientific_str (GString *dst,
else
g_string_append (dst, "E+00");
}
+#endif
+#ifdef DEFINE_COMMON
+/**
+ * go_format_generate_accounting_str:
+ * @dst: GString to append format string to.
+ * @num_decimals: number of decimals.
+ * @currency: optional currency descriptor.
+ *
+ * Generates a format string for an accounting format with the given
+ * parameters and appends it to @dst.
+ **/
+void
+go_format_generate_accounting_str (GString *dst,
+ int num_decimals,
+ GOFormatCurrency const *currency)
+{
+ GString *num = g_string_new (NULL);
+ GString *sym = g_string_new (NULL);
+ GString *q = g_string_new (NULL);
+ const char *symstr;
+ const char *quote;
+
+ if (!currency)
+ currency = &go_format_currencies[0];
+
+ symstr = currency->symbol;
+ quote = symstr[0] != '[' ? "\"" : "";
+
+ go_format_generate_number_str (num, num_decimals, TRUE,
+ FALSE, FALSE, NULL, NULL);
+ go_string_append_c_n (q, '?', num_decimals);
+
+ if (currency->precedes) {
+ g_string_append (sym, quote);
+ g_string_append (sym, symstr);
+ g_string_append (sym, quote);
+ g_string_append (sym, "* ");
+ if (currency->has_space) g_string_append_c (sym, ' ');
+
+ g_string_append_printf
+ (dst,
+ "_(%s%s_);_(%s(%s);_(%s\"-\"%s_);_(@_)",
+ sym->str, num->str,
+ sym->str, num->str,
+ sym->str, q->str);
+ } else {
+ g_string_append (sym, "* ");
+ if (currency->has_space) g_string_append_c (sym, ' ');
+ g_string_append (sym, quote);
+ g_string_append (sym, symstr);
+ g_string_append (sym, quote);
+
+ g_string_append_printf
+ (dst,
+ "_(%s%s_);_((%s)%s;_(\"-\"%s%s_);_(@_)",
+ num->str, sym->str,
+ num->str, sym->str,
+ q->str, sym->str);
+ }
+
+ g_string_free (num, TRUE);
+ g_string_free (q, TRUE);
+ g_string_free (sym, TRUE);
+}
#endif
/********************* GOFormat ODF Support ***********************/
diff --git a/goffice/utils/go-format.h b/goffice/utils/go-format.h
index 9e8e4a2..dfe9722 100644
--- a/goffice/utils/go-format.h
+++ b/goffice/utils/go-format.h
@@ -69,6 +69,13 @@ typedef enum {
GO_FORMAT_NUMBER_DATE_ERROR
} GOFormatNumberError;
+typedef struct {
+ gchar const *symbol;
+ gchar const *description;
+ gboolean precedes;
+ gboolean has_space;
+} GOFormatCurrency;
+
/*************************************************************************/
typedef int (*GOFormatMeasure) (const GString *str, PangoLayout *layout);
@@ -118,6 +125,9 @@ void go_format_generate_scientific_str (GString *dst,
int exponent_step,
gboolean use_markup,
gboolean simplify_mantissa);
+void go_format_generate_accounting_str (GString *dst,
+ int num_decimals,
+ GOFormatCurrency const *currency);
char *go_format_str_localize (char const *str);
char *go_format_str_delocalize (char const *str);
@@ -196,13 +206,6 @@ gboolean go_format_output_to_odf (GsfXMLOut *xout, GOFormat const *fmt,
/*************************************************************************/
-typedef struct {
- gchar const *symbol;
- gchar const *description;
- gboolean precedes;
- gboolean has_space;
-} GOFormatCurrency;
-
/* Indexed by GOFormatFamily */
GO_VAR_DECL char const * const * const go_format_builtins [];
GO_VAR_DECL GOFormatCurrency const go_format_currencies [];
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]