Commit cec33cc8 authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg

no need to translate the money format. We generate it elsewhere.


2000-09-21  Jody Goldberg <jgoldberg@home.com>

	* src/workbook-format-toolbar.c (workbook_cmd_format_as_money) :
	  no need to translate the money format.  We generate it elsewhere.
	(workbook_cmd_format_as_percent) : ditto.

	* src/formats.c : Most format strings are NOT required to be
	  translated anymore.  We store them internaly in the C locale.
	(currency_date_format_init) : customize the currency symbol, and the
	  day/month order.

	* src/format.c (format_get_currency) : new function.
	(format_month_before_day) : New stub.  How to do this portably.
	(lookup_color_by_name) : new routine.
	(lookup_color) : that was split from here.
	(format_remove_decimal) : Fix a bit.  still broken for fmts with
	  multiple cases.
	(format_value) : no need to translate the format.
	(translate_format_color) : new routine.
	(style_format_delocalize) : new routine.  Add colour support.
	(style_format_new_XL) : split from here.
	(style_format_str_as_XL) : new routine.  Add colour support.
	(style_format_as_XL) : split from here.

2000-09-20  Jody Goldberg <jgoldberg@home.com>

	* src/sheet-object.c (sheet_object_destroy) : If the current object is
	  destroyed switch back to edit mode.
parent ac0d937f
......@@ -6,8 +6,6 @@ Release Critical
----------------
- Fix relocation undo to handle Dependents rather than Cell.
- Evaluate (i.e., eliminate) all instances of "foo == TRUE" in the code.
They're too error prone for comfort.
Post 0.57 Changes
......@@ -40,7 +38,6 @@ Long term breakage
rather than inserting before the current sheet.
- formats with AM/PM need to be internationalized.
- We need to generate the date formats depending on locale.
- Changing an expression name that is in use does not recalc, or regen depends
correctly.
......@@ -89,6 +86,7 @@ Long term breakage
to handle shaped objects.
- Parser : The single character '%' is parsed as an expression '0%'
Dialogs
-------
- Use color combos in format dialog.
......
2000-09-21 Jody Goldberg <jgoldberg@home.com>
* src/workbook-format-toolbar.c (workbook_cmd_format_as_money) :
no need to translate the money format. We generate it elsewhere.
(workbook_cmd_format_as_percent) : ditto.
* src/formats.c : Most format strings are NOT required to be
translated anymore. We store them internaly in the C locale.
(currency_date_format_init) : customize the currency symbol, and the
day/month order.
* src/format.c (format_get_currency) : new function.
(format_month_before_day) : New stub. How to do this portably.
(lookup_color_by_name) : new routine.
(lookup_color) : that was split from here.
(format_remove_decimal) : Fix a bit. still broken for fmts with
multiple cases.
(format_value) : no need to translate the format.
(translate_format_color) : new routine.
(style_format_delocalize) : new routine. Add colour support.
(style_format_new_XL) : split from here.
(style_format_str_as_XL) : new routine. Add colour support.
(style_format_as_XL) : split from here.
2000-09-20 Jody Goldberg <jgoldberg@home.com>
* src/sheet-object.c (sheet_object_destroy) : If the current object is
destroyed switch back to edit mode.
* src/workbook-edit.c (workbook_start_editing_at_cursor) : We always
create an in canvas edit item, but sometimes we jump the focus to
the status line.
......
2000-09-21 Jody Goldberg <jgoldberg@home.com>
* src/workbook-format-toolbar.c (workbook_cmd_format_as_money) :
no need to translate the money format. We generate it elsewhere.
(workbook_cmd_format_as_percent) : ditto.
* src/formats.c : Most format strings are NOT required to be
translated anymore. We store them internaly in the C locale.
(currency_date_format_init) : customize the currency symbol, and the
day/month order.
* src/format.c (format_get_currency) : new function.
(format_month_before_day) : New stub. How to do this portably.
(lookup_color_by_name) : new routine.
(lookup_color) : that was split from here.
(format_remove_decimal) : Fix a bit. still broken for fmts with
multiple cases.
(format_value) : no need to translate the format.
(translate_format_color) : new routine.
(style_format_delocalize) : new routine. Add colour support.
(style_format_new_XL) : split from here.
(style_format_str_as_XL) : new routine. Add colour support.
(style_format_as_XL) : split from here.
2000-09-20 Jody Goldberg <jgoldberg@home.com>
* src/sheet-object.c (sheet_object_destroy) : If the current object is
destroyed switch back to edit mode.
* src/workbook-edit.c (workbook_start_editing_at_cursor) : We always
create an in canvas edit item, but sometimes we jump the focus to
the status line.
......
2000-09-21 Jody Goldberg <jgoldberg@home.com>
* src/workbook-format-toolbar.c (workbook_cmd_format_as_money) :
no need to translate the money format. We generate it elsewhere.
(workbook_cmd_format_as_percent) : ditto.
* src/formats.c : Most format strings are NOT required to be
translated anymore. We store them internaly in the C locale.
(currency_date_format_init) : customize the currency symbol, and the
day/month order.
* src/format.c (format_get_currency) : new function.
(format_month_before_day) : New stub. How to do this portably.
(lookup_color_by_name) : new routine.
(lookup_color) : that was split from here.
(format_remove_decimal) : Fix a bit. still broken for fmts with
multiple cases.
(format_value) : no need to translate the format.
(translate_format_color) : new routine.
(style_format_delocalize) : new routine. Add colour support.
(style_format_new_XL) : split from here.
(style_format_str_as_XL) : new routine. Add colour support.
(style_format_as_XL) : split from here.
2000-09-20 Jody Goldberg <jgoldberg@home.com>
* src/sheet-object.c (sheet_object_destroy) : If the current object is
destroyed switch back to edit mode.
* src/workbook-edit.c (workbook_start_editing_at_cursor) : We always
create an in canvas edit item, but sometimes we jump the focus to
the status line.
......
2000-09-21 Jody Goldberg <jgoldberg@home.com>
* src/workbook-format-toolbar.c (workbook_cmd_format_as_money) :
no need to translate the money format. We generate it elsewhere.
(workbook_cmd_format_as_percent) : ditto.
* src/formats.c : Most format strings are NOT required to be
translated anymore. We store them internaly in the C locale.
(currency_date_format_init) : customize the currency symbol, and the
day/month order.
* src/format.c (format_get_currency) : new function.
(format_month_before_day) : New stub. How to do this portably.
(lookup_color_by_name) : new routine.
(lookup_color) : that was split from here.
(format_remove_decimal) : Fix a bit. still broken for fmts with
multiple cases.
(format_value) : no need to translate the format.
(translate_format_color) : new routine.
(style_format_delocalize) : new routine. Add colour support.
(style_format_new_XL) : split from here.
(style_format_str_as_XL) : new routine. Add colour support.
(style_format_as_XL) : split from here.
2000-09-20 Jody Goldberg <jgoldberg@home.com>
* src/sheet-object.c (sheet_object_destroy) : If the current object is
destroyed switch back to edit mode.
* src/workbook-edit.c (workbook_start_editing_at_cursor) : We always
create an in canvas edit item, but sometimes we jump the focus to
the status line.
......
2000-09-21 Jody Goldberg <jgoldberg@home.com>
* src/workbook-format-toolbar.c (workbook_cmd_format_as_money) :
no need to translate the money format. We generate it elsewhere.
(workbook_cmd_format_as_percent) : ditto.
* src/formats.c : Most format strings are NOT required to be
translated anymore. We store them internaly in the C locale.
(currency_date_format_init) : customize the currency symbol, and the
day/month order.
* src/format.c (format_get_currency) : new function.
(format_month_before_day) : New stub. How to do this portably.
(lookup_color_by_name) : new routine.
(lookup_color) : that was split from here.
(format_remove_decimal) : Fix a bit. still broken for fmts with
multiple cases.
(format_value) : no need to translate the format.
(translate_format_color) : new routine.
(style_format_delocalize) : new routine. Add colour support.
(style_format_new_XL) : split from here.
(style_format_str_as_XL) : new routine. Add colour support.
(style_format_as_XL) : split from here.
2000-09-20 Jody Goldberg <jgoldberg@home.com>
* src/sheet-object.c (sheet_object_destroy) : If the current object is
destroyed switch back to edit mode.
* src/workbook-edit.c (workbook_start_editing_at_cursor) : We always
create an in canvas edit item, but sometimes we jump the focus to
the status line.
......
2000-09-21 Jody Goldberg <jgoldberg@home.com>
* src/workbook-format-toolbar.c (workbook_cmd_format_as_money) :
no need to translate the money format. We generate it elsewhere.
(workbook_cmd_format_as_percent) : ditto.
* src/formats.c : Most format strings are NOT required to be
translated anymore. We store them internaly in the C locale.
(currency_date_format_init) : customize the currency symbol, and the
day/month order.
* src/format.c (format_get_currency) : new function.
(format_month_before_day) : New stub. How to do this portably.
(lookup_color_by_name) : new routine.
(lookup_color) : that was split from here.
(format_remove_decimal) : Fix a bit. still broken for fmts with
multiple cases.
(format_value) : no need to translate the format.
(translate_format_color) : new routine.
(style_format_delocalize) : new routine. Add colour support.
(style_format_new_XL) : split from here.
(style_format_str_as_XL) : new routine. Add colour support.
(style_format_as_XL) : split from here.
2000-09-20 Jody Goldberg <jgoldberg@home.com>
* src/sheet-object.c (sheet_object_destroy) : If the current object is
destroyed switch back to edit mode.
* src/workbook-edit.c (workbook_start_editing_at_cursor) : We always
create an in canvas edit item, but sometimes we jump the focus to
the status line.
......
2000-09-21 Jody Goldberg <jgoldberg@home.com>
* src/workbook-format-toolbar.c (workbook_cmd_format_as_money) :
no need to translate the money format. We generate it elsewhere.
(workbook_cmd_format_as_percent) : ditto.
* src/formats.c : Most format strings are NOT required to be
translated anymore. We store them internaly in the C locale.
(currency_date_format_init) : customize the currency symbol, and the
day/month order.
* src/format.c (format_get_currency) : new function.
(format_month_before_day) : New stub. How to do this portably.
(lookup_color_by_name) : new routine.
(lookup_color) : that was split from here.
(format_remove_decimal) : Fix a bit. still broken for fmts with
multiple cases.
(format_value) : no need to translate the format.
(translate_format_color) : new routine.
(style_format_delocalize) : new routine. Add colour support.
(style_format_new_XL) : split from here.
(style_format_str_as_XL) : new routine. Add colour support.
(style_format_as_XL) : split from here.
2000-09-20 Jody Goldberg <jgoldberg@home.com>
* src/sheet-object.c (sheet_object_destroy) : If the current object is
destroyed switch back to edit mode.
* src/workbook-edit.c (workbook_start_editing_at_cursor) : We always
create an in canvas edit item, but sometimes we jump the focus to
the status line.
......
2000-09-20 Jody Goldberg <jgoldberg@home.com>
* dialog-cell-format.c (fillin_negative_samples) : Use locale specific
decimal and thousand seperator in the negative preview.
* dialog-graph-guru.c (get_selector_control) : Hande idl name changes.
(cb_create_series_from_range) : Be smart about col/row headers.
......
......@@ -462,9 +462,12 @@ draw_format_preview (FormatState *state)
break;
};
if (new_format->len > 0)
if (new_format->len > 0) {
char *tmp = style_format_str_as_XL (new_format->str, TRUE);
gtk_entry_set_text (GTK_ENTRY (state->format.widget[F_ENTRY]),
new_format->str);
tmp);
g_free (tmp);
}
g_string_free (new_format, TRUE);
......@@ -513,17 +516,17 @@ fillin_negative_samples (FormatState *state, int const page)
int const n = 30 - state->format.num_decimals;
char const *space = "", *currency;
char const *decimal = "";
char const *thousand_sep = "";
char decimal[2] = { '\0', '\0' } ;
char thousand_sep[2] = { '\0', '\0' } ;
GtkCList *cl;
char buf[50];
int i;
if (state->format.use_separator)
thousand_sep = ",";
thousand_sep[0] = format_get_thousand ();
if (state->format.num_decimals > 0)
decimal = ".";
decimal[0] = format_get_decimal ();
g_return_if_fail (page == 1 || page == 2);
g_return_if_fail (state->format.num_decimals <= 30);
......@@ -585,11 +588,12 @@ fmt_dialog_init_fmt_list (GtkCList *cl, char const * const *formats,
{
int j;
for (j = 0; formats [j]; ++j) {
gchar *t [1];
for (j = 0; formats[j]; ++j) {
gchar *t[1];
t [0] = _(formats [j]);
t [0] = style_format_str_as_XL (formats[j], TRUE);
gtk_clist_append (cl, t);
g_free (t[0]);
/* CHECK : Do we really want to be case insensitive ? */
if (!g_strcasecmp (formats[j], cur_format))
......@@ -645,11 +649,13 @@ fmt_dialog_enable_widgets (FormatState *state, int page)
if (page == FMT_GENERAL || page == FMT_ACCOUNT || page == FMT_FRACTION || page == FMT_TEXT) {
FormatCharacteristics info;
int list_elem = 0;
char *tmp;
if (page == cell_format_classify (state->format.spec, &info))
list_elem = info.list_element;
gtk_entry_set_text (GTK_ENTRY (state->format.widget[F_ENTRY]),
cell_formats[page][list_elem]);
tmp = style_format_str_as_XL (cell_formats[page][list_elem], TRUE);
gtk_entry_set_text (GTK_ENTRY (state->format.widget[F_ENTRY]), tmp);
g_free (tmp);
}
state->format.current_type = page;
......@@ -694,10 +700,11 @@ fmt_dialog_enable_widgets (FormatState *state, int page)
* It should be easy. All that is needed is a way to differentiate
* the std formats and the custom formats in the StyleFormat hash.
*/
if (page == 11 && select == -1)
gtk_entry_set_text (GTK_ENTRY (state->format.widget[F_ENTRY]),
(gchar *)state->format.spec);
else if (select < 0)
if (page == 11 && select == -1) {
char *tmp = style_format_str_as_XL ((gchar *)state->format.spec, TRUE);
gtk_entry_set_text (GTK_ENTRY (state->format.widget[F_ENTRY]), tmp);
g_free (tmp);
} else if (select < 0)
select = 0;
if (select >= 0)
......@@ -726,18 +733,22 @@ static void
cb_format_entry (GtkEditable *w, FormatState *state)
{
gchar const *tmp = gtk_entry_get_text (GTK_ENTRY (w));
char *fmt = style_format_delocalize (tmp);
/* If the format didn't change don't react */
if (!g_strcasecmp (state->format.spec, tmp))
if (!g_strcasecmp (state->format.spec, fmt)) {
g_free (fmt);
return;
}
if (state->enable_edit) {
g_free ((char *)state->format.spec);
state->format.spec = g_strdup (tmp);
state->format.spec = fmt;
mstyle_set_format_text (state->result, state->format.spec);
fmt_dialog_changed (state);
draw_format_preview (state);
}
} else
g_free (fmt);
}
static void
......
......@@ -81,6 +81,24 @@ format_get_thousand (void)
return '.';
}
char const *
format_get_currency (void)
{
if (lc == NULL)
lc = localeconv ();
if (lc->currency_symbol == NULL || *lc->currency_symbol == '\0')
return "$";
return lc->currency_symbol;
}
gboolean
format_month_before_day (void)
{
/* FIXME */
return TRUE;
}
/* Use comma as the arg seperator unless the decimal point is a
* comma, in which case use a semi-colon
*/
......@@ -490,7 +508,7 @@ format_destroy (StyleFormat *format)
format->entries = NULL;
}
static struct {
static struct FormatColor {
char *name;
StyleColor *color;
} format_colors [] = {
......@@ -530,20 +548,32 @@ format_color_shutdown (void)
style_color_unref (format_colors [i].color);
}
static StyleColor *
lookup_color (const char *str, const char *end)
static struct FormatColor const *
lookup_color_by_name (const char *str, const char *end,
gboolean const translate)
{
int i, len;
len = end - str;
for (i = 0; format_colors [i].name; i++){
char const *pre = format_colors [i].name;
char const *post = _(pre);
if ((g_strncasecmp (pre, str, len) == 0 && pre[len] == 0) ||
(pre != post && g_strncasecmp (post, str, len) == 0 && post[len] == 0)) {
style_color_ref (format_colors [i].color);
return format_colors [i].color;
}
for (i = 0; format_colors [i].name; i++) {
char const *name = format_colors [i].name;
if (translate)
name = _(name);
if (0 == g_strncasecmp (name, str, len) && name [len] == '\0')
return format_colors + i;
}
return NULL;
}
static StyleColor *
lookup_color (const char *str, const char *end)
{
struct FormatColor const *color = lookup_color_by_name (str, end, FALSE);
if (color != NULL) {
style_color_ref (color->color);
return color->color;
}
return NULL;
}
......@@ -887,7 +917,8 @@ format_remove_decimal (StyleFormat const *fmt)
if (!tmp)
return NULL;
ret = p = g_strdup (tmp);
ret = g_strdup (format_string);
p = ret + (tmp - format_string);
/* If there is more than 1 thing after the decimal place
* leave the decimal.
......@@ -1399,7 +1430,7 @@ format_value (StyleFormat *format, const Value *value, StyleColor **color,
if (entry.format [0] == '['){
char *end = strchr (entry.format, ']');
if (end){
if (end) {
char first_after_bracket = entry.format [1];
/*
......@@ -1458,7 +1489,7 @@ format_value (StyleFormat *format, const Value *value, StyleColor **color,
if (floor (value->v_float.val) == value->v_float.val)
entry.format = "0";
else
entry.format = _("0.0########");
entry.format = "0.0########";
}
v = format_number (value->v_float.val, &entry);
} else
......@@ -1515,59 +1546,95 @@ number_format_shutdown (void)
/****************************************************************************/
/**
* style_format_new_XL :
*/
StyleFormat *
style_format_new_XL (const char *descriptor_string, gboolean delocalize)
static char *
translate_format_color (GString *res, char const *ptr, gboolean translate_to_en)
{
StyleFormat *format;
char *internal_string = NULL;
char *end;
struct FormatColor const *color;
g_string_append_c (res, '[');
/*
* Special [h*], [m*], [*s] is using for
* and [$*] are for currencies.
* measuring times, not for specifying colors.
*/
if (ptr[1] == 'h' || ptr[1] == 's' || ptr[1] == 'm' || ptr[1] == '$')
return NULL;
end = strchr (ptr, ']');
if (end == NULL)
return NULL;
color = lookup_color_by_name (ptr, end, translate_to_en);
if (color != NULL) {
g_string_append (res, translate_to_en
? _(color->name)
: color->name);
g_string_append_c (res, ']');
return end;
}
return NULL;
}
char *
style_format_delocalize (const char *descriptor_string)
{
g_return_val_if_fail (descriptor_string != NULL, NULL);
if (delocalize) {
if (!strcmp (descriptor_string, _("General")))
descriptor_string = "General";
else {
char const thousands_sep = format_get_thousand ();
char const decimal = format_get_decimal ();
char const *ptr = descriptor_string;
GString *res = g_string_sized_new (strlen (ptr));
for ( ; *ptr ; ++ptr)
if (*ptr == decimal)
g_string_append_c (res, '.');
else if (*ptr == thousands_sep)
g_string_append_c (res, ',');
else if (*ptr == '\\')
switch (*ptr) {
case '.' : g_string_append_c (res, decimal);
break;
case ',' : g_string_append_c (res, thousands_sep);
break;
case '\"' : do {
g_string_append_c (res, *ptr++);
} while (*ptr && *ptr != '\"');
if (*ptr)
g_string_append_c (res, *ptr);
break;
case '\\' : g_string_append_c (res, '\\');
if (ptr [1] != '\0') {
g_string_append_c (res, ptr[1]);
++ptr;
}
break;
default : g_string_append_c (res, *ptr);
};
internal_string = g_strdup (res->str);
descriptor_string = internal_string;
if (strcmp (descriptor_string, _("General"))) {
char const thousands_sep = format_get_thousand ();
char const decimal = format_get_decimal ();
char const *ptr = descriptor_string;
GString *res = g_string_sized_new (strlen (ptr));
for ( ; *ptr ; ++ptr)
if (*ptr == decimal)
g_string_append_c (res, '.');
else if (*ptr == thousands_sep)
g_string_append_c (res, ',');
else if (*ptr == '\\') {
switch (*ptr) {
case '.' : g_string_append_c (res, decimal);
break;
case ',' : g_string_append_c (res, thousands_sep);
break;
case '\"' : do {
g_string_append_c (res, *ptr++);
} while (*ptr && *ptr != '\"');
if (*ptr)
g_string_append_c (res, *ptr);
break;
case '\\' : g_string_append_c (res, '\\');
if (ptr [1] != '\0') {
g_string_append_c (res, ptr[1]);
++ptr;
}
break;
default : g_string_append_c (res, *ptr);
};
} else
g_string_append_c (res, *ptr);
{
char *tmp = g_strdup (res->str);
g_string_free (res, TRUE);
return tmp;
}
}
} else
return g_strdup ("General");
}
StyleFormat *
style_format_new_XL (const char *descriptor_string, gboolean delocalize)
{
StyleFormat *format;
if (delocalize)
descriptor_string = style_format_delocalize (descriptor_string);
format = (StyleFormat *) g_hash_table_lookup (style_format_hash, descriptor_string);
......@@ -1580,24 +1647,25 @@ style_format_new_XL (const char *descriptor_string, gboolean delocalize)
}
format->ref_count++;
if (internal_string)
g_free (internal_string);
if (delocalize)
g_free ((char *)descriptor_string);
return format;
}
/**
* style_format_as_XL :
* style_format_str_as_XL
*
* The caller is responsible for freeing the resulting string.
*/
char *
style_format_as_XL (StyleFormat const *fmt, gboolean localized)
style_format_str_as_XL (char const *ptr, gboolean localized)
{
char const *ptr;
g_return_val_if_fail (fmt != NULL, g_strdup (_("General")));
if (localized) {
g_return_val_if_fail (ptr != NULL, g_strdup (_("General")));
} else {
g_return_val_if_fail (ptr != NULL, g_strdup ("General"));
}
ptr = fmt->format;
if (!localized)
return g_strdup (ptr);
......@@ -1643,6 +1711,12 @@ style_format_as_XL (StyleFormat const *fmt, gboolean localized)
++ptr;
}
break;
case '[' : tmp = translate_format_color (res, ptr, FALSE);
if (tmp != NULL)
ptr = tmp;
break;
default : if (*ptr == decimal || *ptr == thousands_sep)
g_string_append_c (res, '\\');
g_string_append_c (res, *ptr);
......@@ -1654,6 +1728,18 @@ style_format_as_XL (StyleFormat const *fmt, gboolean localized)
}
}
char *
style_format_as_XL (StyleFormat const *fmt, gboolean localized)
{
if (localized) {
g_return_val_if_fail (fmt != NULL, g_strdup (_("General")));
} else {
g_return_val_if_fail (fmt != NULL, g_strdup ("General"));
}
return style_format_str_as_XL (fmt->format, localized);
}
void
style_format_ref (StyleFormat *sf)
{
......
......@@ -3,10 +3,13 @@
#include "gnumeric.h"
char *style_format_delocalize (const char *descriptor_string);
StyleFormat *style_format_new_XL (const char *descriptor_string,
gboolean delocalize);
char *style_format_as_XL (StyleFormat const *fmt,
gboolean localized);
char *style_format_str_as_XL (const char *descriptor_string,
gboolean localized);
void style_format_ref (StyleFormat *sf);
void style_format_unref (StyleFormat *sf);
......@@ -24,11 +27,13 @@ char *format_add_decimal (StyleFormat const *fmt);
char *format_remove_decimal (StyleFormat const *fmt);
/* Locale support routines */
char const *gnumeric_setlocale (int category, char const *val);
char format_get_arg_sep (void);
char format_get_col_sep (void);
char format_get_thousand (void);
char format_get_decimal (void);
char const *gnumeric_setlocale (int category, char const *val);
char const *format_get_currency (void);
gboolean format_month_before_day (void);
char format_get_arg_sep (void);
char format_get_col_sep (void);
char format_get_thousand (void);
char format_get_decimal (void);
void number_format_init (void);
void number_format_shutdown (void);
......
......@@ -15,116 +15,120 @@
/* The various formats */
static char const * const
cell_format_general [] = {
N_("General"),
"General",
NULL
};
static char const * const
cell_format_numbers [] = {
N_("0"),
N_("0.00"),
N_("#,##0"),
N_("#,##0.00"),
N_("#,##0_);(#,##0)"),
N_("#,##0_);[Red](#,##0)"),