Commit e6744ab5 authored by Morten Welinder's avatar Morten Welinder Committed by Morten Welinder

Use precomputed family. Ditto.

2003-07-15  Morten Welinder  <terra@gnome.org>

	* src/auto-format.c (is_date): Use precomputed family.
	* src/sheet-autofill.c (fill_item_new): Ditto.

	* src/formats.c (cell_format_classify): Don't use
	style_format_is_general since this function must work early.

	* src/format.h (struct _StyleFormat): Add family and family_info
	members.

	* src/format.c (style_format_new_XL): Init family stuff.
	(style_format_is_general, style_format_is_text): Make these
	macros.
parent 6c49e3c7
......@@ -321,14 +321,6 @@ Pending Patches
22) Add dirty flags to workbook too, adding a sheet should
make workbook dirty not the new sheet.
23) gconf.
23.1) Check for errors (DONE)
23.2) double check that we update on remote changes
23.3) see if schema is installed
23.4) Move the pref storage into app and compartmentalize
the use of gconf.
23.5) update the preference structure on local changes
24) Plugins
24.1) enhance gobject service to do delayed load (DONE)
24.2) pluginize paste types
......@@ -367,13 +359,18 @@ Pending Patches
25.28) plugins/xbase (DONE 20030408 MW)
25.29) plugins/xml_sax (DONE 20030408 MW)
26) Format characterization
26.1) Add characterization (units) to StyleFormat
27) audit all of the export plugins to handle utf8
27.1) latex exporter (DONE 20030611 AJG)
27.2) html exporter
29) gconf.
29.1) Check for errors (DONE)
29.2) double check that we update on remote changes
29.3) see if schema is installed
29.4) Move the pref storage into app and compartmentalize
the use of gconf.
29.5) update the preference structure on local changes
1.2 Targets
-----------
- insert cut
......@@ -583,6 +580,8 @@ Finished
23) Bonobo component (DONE)
23.1) Install it in libexec (DONE)
23.2) Investigate warnings (DONE)
26) Format characterization (DONE)
26.1) Add characterization (units) to StyleFormat (DONE)
28) Finish Function Coverage (DONE)
28.1) Convert the code from sc to use our date routines (DONE)
28.2) ODDFPRICE (test fails) (DONE)
......@@ -591,4 +590,3 @@ Finished
28.5) ODDLYIELD (test fails) (DONE)
28.6) YIELDDISC (basis 1 seems different) (DONE)
28.7) YEARFRAC (DONE)
2003-07-15 Morten Welinder <terra@gnome.org>
* src/auto-format.c (is_date): Use precomputed family.
* src/sheet-autofill.c (fill_item_new): Ditto.
* src/formats.c (cell_format_classify): Don't use
style_format_is_general since this function must work early.
* src/format.h (struct _StyleFormat): Add family and family_info
members.
* src/format.c (style_format_new_XL): Init family stuff.
(style_format_is_general, style_format_is_text): Make these
macros.
2003-07-15 Morten Welinder <terra@gnome.org>
* src/format.h: Suck in formats.h and remove that file. All
......
2003-07-15 Morten Welinder <terra@gnome.org>
* src/auto-format.c (is_date): Use precomputed family.
* src/sheet-autofill.c (fill_item_new): Ditto.
* src/formats.c (cell_format_classify): Don't use
style_format_is_general since this function must work early.
* src/format.h (struct _StyleFormat): Add family and family_info
members.
* src/format.c (style_format_new_XL): Init family stuff.
(style_format_is_general, style_format_is_text): Make these
macros.
2003-07-15 Morten Welinder <terra@gnome.org>
* src/format.h: Suck in formats.h and remove that file. All
......
2003-07-15 Morten Welinder <terra@gnome.org>
* src/auto-format.c (is_date): Use precomputed family.
* src/sheet-autofill.c (fill_item_new): Ditto.
* src/formats.c (cell_format_classify): Don't use
style_format_is_general since this function must work early.
* src/format.h (struct _StyleFormat): Add family and family_info
members.
* src/format.c (style_format_new_XL): Init family stuff.
(style_format_is_general, style_format_is_text): Make these
macros.
2003-07-15 Morten Welinder <terra@gnome.org>
* src/format.h: Suck in formats.h and remove that file. All
......
2003-07-15 Morten Welinder <terra@gnome.org>
* functions.c (retrieve_format_info): Use precomputed family_info.
2003-06-23 Andreas J. Guelzow <aguelzow@taliesin.ca>
* functions.c: spelling fixes
......
......@@ -155,11 +155,7 @@ retrieve_format_info (Sheet *sheet, int col, int row)
{
MStyle *mstyle = sheet_style_get (sheet, col, row);
StyleFormat *format = mstyle_get_format (mstyle);
FormatCharacteristics info;
cell_format_classify (format, &info);
return info;
return format->family_info;
}
/* TODO : turn this into a range based routine */
......
2003-07-15 Morten Welinder <terra@gnome.org>
* latex.c (latex2e_write_multicolumn_cell): Use precomputed
family.
2003-07-06 Jon K Hellan <hellan@acm.org>
* html_read.c (is_elt_type, starts_inferred_table,
......
......@@ -686,7 +686,6 @@ latex2e_write_multicolumn_cell (GsfOutput *output, Cell *cell, int num_merged_co
char * rendered_string;
gushort r,g,b;
gboolean wrap = FALSE;
FormatCharacteristics cell_format_characteristic;
FormatFamily cell_format_family;
int merge_width = 0;
StyleBorderType left_border = STYLE_BORDER_NONE;
......@@ -854,8 +853,7 @@ latex2e_write_multicolumn_cell (GsfOutput *output, Cell *cell, int num_merged_co
gsf_output_printf (output, "\\textit{");
cell_format_family = cell_format_classify (cell_get_format (cell),
&cell_format_characteristic);
cell_format_family = cell_get_format (cell)->family;
if (cell_format_family == FMT_NUMBER || cell_format_family == FMT_CURRENCY ||
cell_format_family == FMT_PERCENT || cell_format_family == FMT_FRACTION ||
cell_format_family == FMT_SCIENCE){
......
......@@ -82,16 +82,9 @@ cb_af_suggest (G_GNUC_UNUSED Sheet *sheet,
static gboolean
is_date (GnmFuncFlags typ, StyleFormat *explicit)
{
switch (typ) {
case GNM_FUNC_AUTO_DATE: return TRUE;
default: return FALSE;
case AF_EXPLICIT: {
FormatCharacteristics info;
return (cell_format_classify (explicit, &info) == FMT_DATE);
}
}
return (typ == GNM_FUNC_AUTO_DATE ||
(typ == AF_EXPLICIT &&
explicit->family == FMT_DATE));
}
static GnmFuncFlags
......
......@@ -899,21 +899,23 @@ find_decimal_char (char const *str)
/* An helper function which modify the number of decimals displayed
* and recreate the format string by calling the good function */
static StyleFormat *
reformat_decimals (FormatCharacteristics *fc,
reformat_decimals (const FormatCharacteristics *fc,
void (*format_function) (GString *res, FormatCharacteristics const * fmt),
int step)
{
GString *res;
StyleFormat *sf;
FormatCharacteristics fc_copy;
/* Be sure that the number of decimals displayed will remain correct */
if ((fc->num_decimals+step > 30) || (fc->num_decimals+step <0))
return NULL;
fc->num_decimals += step;
fc_copy = *fc;
fc_copy.num_decimals += step;
/* Regenerate the format with the good function */
res = g_string_new (NULL);
(*format_function) (res, fc);
(*format_function) (res, &fc_copy);
sf = style_format_new_XL (res->str, FALSE);
g_string_free (res, TRUE);
......@@ -934,24 +936,21 @@ format_remove_decimal (StyleFormat const *fmt)
char *ret, *p;
char const *tmp;
char const *format_string = fmt->format;
FormatFamily ff;
FormatCharacteristics fc;
StyleFormat *sf;
/* First try to classify the format so we can regenerate it */
ff = cell_format_classify (fmt, &fc);
switch (ff) {
switch (fmt->family) {
case FMT_NUMBER:
case FMT_CURRENCY:
return reformat_decimals (&fc, &style_format_number, -1);
return reformat_decimals (&fmt->family_info, &style_format_number, -1);
case FMT_ACCOUNT:
return reformat_decimals (&fc, &style_format_account, -1);
return reformat_decimals (&fmt->family_info, &style_format_account, -1);
case FMT_PERCENT:
return reformat_decimals (&fc, &style_format_percent, -1);
return reformat_decimals (&fmt->family_info, &style_format_percent, -1);
case FMT_SCIENCE:
return reformat_decimals (&fc, &style_format_science, -1);
case FMT_FRACTION:
return reformat_decimals (&fmt->family_info, &style_format_science, -1);
case FMT_FRACTION: {
FormatCharacteristics fc = fmt->family_info;
if (fc.fraction_denominator >= 2) {
if (fc.fraction_denominator > 2 &&
((fc.fraction_denominator & (fc.fraction_denominator - 1)) == 0))
......@@ -970,6 +969,7 @@ format_remove_decimal (StyleFormat const *fmt)
return NULL;
return reformat_decimals (&fc, &style_format_fraction, -1);
}
}
case FMT_TIME:
/* FIXME: we might have decimals on seconds part. */
......@@ -992,7 +992,7 @@ format_remove_decimal (StyleFormat const *fmt)
* We need to look at the number of decimals in the current value
* and use that as a base.
*/
if (strcmp (format_string, "General") == 0)
if (style_format_is_general (fmt))
format_string = "0.########";
tmp = find_decimal_char (format_string);
......@@ -1033,24 +1033,20 @@ format_add_decimal (StyleFormat const *fmt)
char const *post = NULL;
char *res;
char const *format_string = fmt->format;
FormatFamily ff;
FormatCharacteristics fc;
StyleFormat *sf;
/* First try to classify the format so we can regenerate it */
ff = cell_format_classify (fmt, &fc);
switch (ff) {
switch (fmt->family) {
case FMT_NUMBER:
case FMT_CURRENCY:
return reformat_decimals (&fc, &style_format_number, +1);
return reformat_decimals (&fmt->family_info, &style_format_number, +1);
case FMT_ACCOUNT:
return reformat_decimals (&fc, &style_format_account, +1);
return reformat_decimals (&fmt->family_info, &style_format_account, +1);
case FMT_PERCENT:
return reformat_decimals (&fc, &style_format_percent, +1);
return reformat_decimals (&fmt->family_info, &style_format_percent, +1);
case FMT_SCIENCE:
return reformat_decimals (&fc, &style_format_science, +1);
case FMT_FRACTION:
return reformat_decimals (&fmt->family_info, &style_format_science, +1);
case FMT_FRACTION: {
FormatCharacteristics fc = fmt->family_info;
if (fc.fraction_denominator >= 2) {
if (fc.fraction_denominator <= INT_MAX / 2 &&
((fc.fraction_denominator & (fc.fraction_denominator - 1)) == 0))
......@@ -1069,6 +1065,7 @@ format_add_decimal (StyleFormat const *fmt)
return NULL;
return reformat_decimals (&fc, &style_format_fraction, +1);
}
}
case FMT_TIME:
/* FIXME: we might have decimals on seconds part. */
......@@ -1085,7 +1082,7 @@ format_add_decimal (StyleFormat const *fmt)
/* Use the old code for more special formats to try to add a
decimal */
if (strcmp (format_string, "General") == 0) {
if (style_format_is_general (fmt)) {
format_string = "0";
pre = format_string + 1;
post = pre;
......@@ -1133,16 +1130,14 @@ format_add_decimal (StyleFormat const *fmt)
StyleFormat *
format_toggle_thousands (StyleFormat const *fmt)
{
FormatFamily ff;
FormatCharacteristics fc;
GString *newformat;
StyleFormat *sf;
/* First try to classify the format so we can regenerate it */
ff = cell_format_classify (fmt, &fc);
fc = fmt->family_info;
fc.thousands_sep = !fc.thousands_sep;
switch (ff) {
switch (fmt->family) {
case FMT_NUMBER:
case FMT_CURRENCY:
newformat = g_string_new (NULL);
......@@ -1994,7 +1989,7 @@ style_format_new_XL (char const *descriptor_string, gboolean delocalize)
g_warning ("Invalid format descriptor string, using General");
descriptor_string = "General";
} else if (delocalize)
desc_copy = descriptor_string = style_format_delocalize (descriptor_string);
descriptor_string = desc_copy = style_format_delocalize (descriptor_string);
format = (StyleFormat *) g_hash_table_lookup (style_format_hash, descriptor_string);
......@@ -2004,8 +1999,10 @@ style_format_new_XL (char const *descriptor_string, gboolean delocalize)
format->entries = NULL;
format->regexp_str = NULL;
format->match_tags = NULL;
if (strcmp ("General", format->format))
format->family = cell_format_classify (format, &format->family_info);
if (!style_format_is_general (format))
format_compile (format);
g_hash_table_insert (style_format_hash, format->format, format);
}
format->ref_count++;
......@@ -2162,30 +2159,6 @@ style_format_unref (StyleFormat *sf)
g_free (sf);
}
/**
* style_format_is_general :
* @sf : the format to check
*
* A small utility to check whether a format is 'General'
*/
gboolean
style_format_is_general (StyleFormat const *sf)
{
return 0 == strcmp (sf->format, "General");
}
/**
* style_format_is_general :
* @sf : the format to check
*
* A small utility to check whether a format is 'General'
*/
gboolean
style_format_is_text (StyleFormat const *sf)
{
return 0 == strcmp (sf->format, "@");
}
StyleFormat *
style_format_general (void)
{
......
......@@ -41,12 +41,14 @@ typedef struct {
} FormatCharacteristics;
struct _StyleFormat {
int ref_count;
char *format;
GSList *entries; /* Of type StyleFormatEntry. */
char *regexp_str;
GByteArray *match_tags;
gnumeric_regex_t regexp;
int ref_count;
char *format;
GSList *entries; /* Of type StyleFormatEntry. */
char *regexp_str;
GByteArray *match_tags;
gnumeric_regex_t regexp;
FormatFamily family;
FormatCharacteristics family_info;
};
char *style_format_delocalize (char const *descriptor_string);
......@@ -59,8 +61,6 @@ char *style_format_str_as_XL (char const *descriptor_string,
void style_format_ref (StyleFormat *sf);
void style_format_unref (StyleFormat *sf);
gboolean style_format_is_general (StyleFormat const *sf);
gboolean style_format_is_text (StyleFormat const *sf);
gboolean style_format_equal (StyleFormat const *a, StyleFormat const *b);
StyleFormat *style_format_general (void);
......@@ -69,6 +69,9 @@ StyleFormat *style_format_default_time (void);
StyleFormat *style_format_default_percentage (void);
StyleFormat *style_format_default_money (void);
#define style_format_is_general(sf) ((sf)->family == FMT_GENERAL)
#define style_format_is_text(sf) ((sf)->family == FMT_TEXT)
char *format_value (StyleFormat const *format, Value const *value, StyleColor **color,
double col_width, GnmDateConventions const *date_conv);
void format_value_gstring (GString *result, StyleFormat const *format,
......
......@@ -194,7 +194,6 @@ currency_date_format_init (void)
char const *curr = format_get_currency (&precedes, &space_sep);
char *pre, *post, *pre_rep, *post_rep;
int err;
static gboolean first_time = TRUE;
/* Compile the regexps for format classification */
......@@ -345,33 +344,6 @@ currency_date_format_init (void)
cell_format_time [4] = "m/d/yy h:mm";
}
if (first_time) {
#if 0
int i;
for (i = 0; cell_formats[i] != NULL ; ++i) {
int j = 0;
char const * const * elem = cell_formats[i];
for (; elem[j] ; ++j) {
FormatCharacteristics info;
StyleFormat *sf =
style_format_new_XL (elem[j], FALSE);
FormatFamily fam =
cell_format_classify (sf, &info);
if (fam != (FormatFamily)i) {
g_print ("%d %d %s\n",
i, fam,
elem[j]);
}
style_format_unref (sf);
}
}
#endif
first_time = FALSE;
}
}
void
......@@ -683,7 +655,6 @@ cell_format_is_number (char const * const fmt, FormatCharacteristics *info)
/* FMT_PERCENT or FMT_SCIENCE ? */
if (gnumeric_regexec (&re_percent_science, fmt, G_N_ELEMENTS (match), match, 0) == 0) {
info->num_decimals = 0;
if (match[1].rm_eo != -1)
info->num_decimals = match[1].rm_eo -
......@@ -697,7 +668,6 @@ cell_format_is_number (char const * const fmt, FormatCharacteristics *info)
/* FMT_ACCOUNT */
if (gnumeric_regexec (&re_account, fmt, G_N_ELEMENTS (match), match, 0) == 0) {
info->num_decimals = 0;
if (match[5].rm_eo != -1)
info->num_decimals = match[5].rm_eo -
......@@ -771,7 +741,8 @@ cell_format_classify (StyleFormat const *sf, FormatCharacteristics *info)
info->date_has_months = FALSE;
info->fraction_denominator = 0;
if (style_format_is_general (sf))
/* Note: ->family is not yet ready. */
if (strcmp (sf->format, cell_format_general[0]) == 0)
return FMT_GENERAL;
/* Can we parse it ? */
......@@ -791,9 +762,9 @@ cell_format_classify (StyleFormat const *sf, FormatCharacteristics *info)
switch (i) {
case FMT_DATE:
info->date_has_days =
(NULL != g_utf8_strchr(elem[j],-1,'d'));
(NULL != g_utf8_strchr (elem[j],-1,'d'));
info->date_has_months =
(NULL != g_utf8_strchr(elem[j],-1,'m'));
(NULL != g_utf8_strchr (elem[j],-1,'m'));
break;
default:
break;
......
......@@ -303,14 +303,14 @@ fill_item_new (Sheet *sheet, int col, int row)
value_type = VALUE_TYPE (value);
if (value_type == VALUE_INTEGER || value_type == VALUE_FLOAT) {
FormatCharacteristics info;
const StyleFormat *sf = cell_get_format (cell);
fi->type = FILL_NUMBER;
fi->v.value = value;
if (FMT_DATE == cell_format_classify (cell_get_format (cell), &info))
fi->type = info.date_has_days
if (sf->family == FMT_DATE)
fi->type = sf->family_info.date_has_days
? FILL_DAYS
: info.date_has_months ? FILL_MONTHS : FILL_YEARS;
: sf->family_info.date_has_months ? FILL_MONTHS : FILL_YEARS;
return fi;
}
......
2003-07-15 Morten Welinder <terra@gnome.org>
* widget-format-selector.c (set_format_category_menu_from_style):
Use precomputed family.
2003-07-02 Jody Goldberg <jody@gnome.org>
* widget-font-selector.c : remove gnome-print include
......
......@@ -533,11 +533,10 @@ fmt_dialog_enable_widgets (NumberFormatSelector *nfs, int page)
/* Set the default format if appropriate */
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 (nfs->format.spec, &info))
list_elem = info.list_element;
if (page == nfs->format.spec->family)
list_elem = nfs->format.spec->family_info.list_element;
tmp = style_format_str_as_XL (cell_formats[page][list_elem], TRUE);
gtk_entry_set_text (GTK_ENTRY (nfs->format.widget[F_ENTRY]), tmp);
......@@ -765,12 +764,11 @@ static void
set_format_category_menu_from_style (NumberFormatSelector *nfs)
{
int page;
FormatCharacteristics info;
g_return_if_fail (IS_NUMBER_FORMAT_SELECTOR (nfs));
/* Attempt to extract general parameters from the current format */
if ((page = cell_format_classify (nfs->format.spec, &info)) < 0)
if ((page = nfs->format.spec->family) < 0)
page = 11; /* Default to custom */
set_format_category (nfs, page);
......@@ -862,7 +860,6 @@ nfs_init (NumberFormatSelector *nfs)
char const *name;
int i;
int page;
FormatCharacteristics info;
GtkWidget *toplevel;
GtkWidget *old_parent;
......@@ -889,13 +886,11 @@ nfs_init (NumberFormatSelector *nfs)
* all widgets are already hidden. */
nfs->format.current_type = -1;
cell_format_classify (nfs->format.spec, &info);
/* Even if the format was not recognized it has set intelligent defaults */
nfs->format.use_separator = info.thousands_sep;
nfs->format.num_decimals = info.num_decimals;
nfs->format.negative_format = info.negative_fmt;
nfs->format.currency_index = info.currency_symbol_index;
nfs->format.use_separator = nfs->format.spec->family_info.thousands_sep;
nfs->format.num_decimals = nfs->format.spec->family_info.num_decimals;
nfs->format.negative_format = nfs->format.spec->family_info.negative_fmt;
nfs->format.currency_index = nfs->format.spec->family_info.currency_symbol_index;
nfs->format.preview_box = glade_xml_get_widget (nfs->gui, "preview_box");
nfs->format.preview = GTK_TEXT_VIEW (glade_xml_get_widget (nfs->gui, "preview"));
......@@ -1027,7 +1022,7 @@ nfs_init (NumberFormatSelector *nfs)
/* Connect signal for format menu */
set_format_category_menu_from_style (nfs);
if ((page = cell_format_classify (nfs->format.spec, &info)) < 0)
if ((page = nfs->format.spec->family) < 0)
page = 11; /* Default to custom */
fmt_dialog_enable_widgets (nfs, page);
......@@ -1104,7 +1099,6 @@ number_format_selector_set_style_format (NumberFormatSelector *nfs,
StyleFormat *style_format)
{
GnmComboText *combo;
FormatCharacteristics info;
g_return_if_fail (IS_NUMBER_FORMAT_SELECTOR (nfs));
g_return_if_fail (style_format != NULL);
......@@ -1115,12 +1109,10 @@ number_format_selector_set_style_format (NumberFormatSelector *nfs,
nfs->format.spec = style_format;
cell_format_classify (nfs->format.spec, &info);
nfs->format.use_separator = info.thousands_sep;
nfs->format.num_decimals = info.num_decimals;
nfs->format.negative_format = info.negative_fmt;
nfs->format.currency_index = info.currency_symbol_index;
nfs->format.use_separator = style_format->family_info.thousands_sep;
nfs->format.num_decimals = style_format->family_info.num_decimals;
nfs->format.negative_format = style_format->family_info.negative_fmt;
nfs->format.currency_index = style_format->family_info.currency_symbol_index;
combo = GNM_COMBO_TEXT (nfs->format.widget[F_SYMBOL]);
gnm_combo_text_set_text
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment