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

Deal with goffice changes.

2007-02-26  Morten Welinder  <terra@gnome.org>

        * */*.c: Deal with goffice changes.

        * src/gnm-format.c (gnm_format_specialize): New function.
        (gnm_format_is_date_for_value): Base on gnm_format_specialize.


svn path=/trunk/; revision=15435
parent a0762b0e
2007-02-26 Morten Welinder <terra@gnome.org>
* */*.c: Deal with goffice changes.
* src/gnm-format.c (gnm_format_specialize): New function.
(gnm_format_is_date_for_value): Base on gnm_format_specialize.
* src/rendered-value.c (gnm_rendered_value_shutdown): Use slice
allocator when available.
......
......@@ -112,7 +112,7 @@ PKG_PROG_PKG_CONFIG(0.18)
dnl *****************************
libspreadsheet_reqs="
libgoffice-0.3 >= 0.3.6
libgoffice-0.3 >= 0.3.7
libgsf-1 >= 1.14.2
libxml-2.0 >= 2.4.12
"
......
......@@ -713,9 +713,9 @@ xl_xml_num_fmt (GsfXMLIn *xin, xmlChar const **attrs)
if (NULL != fmt)
go_format_ref (fmt);
else if (!strcmp (attrs[1], "Fixed"))
fmt = go_format_new_from_XL ("0.00", FALSE);
fmt = go_format_new_from_XL ("0.00");
else
fmt = go_format_new_from_XL (attrs[1], FALSE);
fmt = go_format_new_from_XL (attrs[1]);
gnm_style_set_format (state->style, fmt);
go_format_unref (fmt);
} else
......
......@@ -311,9 +311,8 @@ BC_R(ai)(XLChartHandler const *handle,
GSF_LE_GET_GUINT16 (q->data + 4));
d (2, fputs ("Has Custom number format;\n", stderr););
if (fmt != NULL) {
char *desc = go_format_as_XL (fmt, FALSE);
const char *desc = go_format_as_XL (fmt);
d (2, fprintf (stderr, "Format = '%s';\n", desc););
g_free (desc);
go_format_unref (fmt);
}
......@@ -1121,14 +1120,13 @@ BC_R(ifmt)(XLChartHandler const *handle,
GSF_LE_GET_GUINT16 (q->data));
if (fmt != NULL) {
char *desc = go_format_as_XL (fmt, FALSE);
const char *desc = go_format_as_XL (fmt);
if (s->axis != NULL)
g_object_set (G_OBJECT (s->axis),
"assigned-format-string-XL", desc,
NULL);
d (0, fprintf (stderr, "Format = '%s';\n", desc););
g_free (desc);
go_format_unref (fmt);
}
......
......@@ -224,7 +224,7 @@ excel_wb_get_fmt (GnmXLImporter *importer, unsigned idx)
fprintf (stderr,"Unknown format: 0x%x\n", idx);
if (ans)
return go_format_new_from_XL (ans, FALSE);
return go_format_new_from_XL (ans);
else
return NULL;
}
......
......@@ -2062,7 +2062,7 @@ formats_init (ExcelWriteState *ewb)
if (!fmt || strlen (fmt) == 0)
fmt = "General";
two_way_table_put (ewb->formats.two_way_table,
go_format_new_from_XL (fmt, FALSE),
go_format_new_from_XL (fmt),
FALSE, /* Not unique */
(AfterPutFunc) after_put_format,
"Magic format %d - 0x%x\n");
......@@ -2104,7 +2104,7 @@ excel_write_FORMAT (ExcelWriteState *ewb, int fidx)
guint8 data[64];
GOFormat const *sf = formats_get_format (ewb, fidx);
char *format = go_format_as_XL (sf, FALSE);
const char *format = go_format_as_XL (sf);
d (1, fprintf (stderr, "Writing format 0x%x: %s\n", fidx, format););
......@@ -2118,7 +2118,6 @@ excel_write_FORMAT (ExcelWriteState *ewb, int fidx)
excel_write_string (ewb->bp, (ewb->bp->version >= MS_BIFF_V8)
? STR_TWO_BYTE_LENGTH : STR_ONE_BYTE_LENGTH, format);
ms_biff_put_commit (ewb->bp);
g_free (format);
}
/**
......@@ -2466,30 +2465,28 @@ log_xf_data (ExcelWriteState *ewb, BiffXFData *xfd, int idx)
{
int i;
ExcelWriteFont *f = fonts_get_font (ewb, xfd->font_idx);
/* Formats are saved using the 'C' locale number format */
char * desc = go_format_as_XL (xfd->style_format, FALSE);
const char *desc = go_format_as_XL (xfd->style_format);
fprintf (stderr, "Writing xf 0x%x : font 0x%x (%s), format 0x%x (%s)\n",
g_printerr ("Writing xf 0x%x : font 0x%x (%s), format 0x%x (%s)\n",
idx, xfd->font_idx, excel_font_to_string (f),
xfd->format_idx, desc);
g_free (desc);
fprintf (stderr, " hor align 0x%x, ver align 0x%x, wrap_text %s\n",
g_printerr (" hor align 0x%x, ver align 0x%x, wrap_text %s\n",
xfd->halign, xfd->valign, xfd->wrap_text ? "on" : "off");
fprintf (stderr, " fill fg color idx %d, fill bg color idx %d"
g_printerr (" fill fg color idx %d, fill bg color idx %d"
", pattern (Excel) %d\n",
xfd->pat_foregnd_col, xfd->pat_backgnd_col,
xfd->fill_pattern_idx);
for (i = STYLE_TOP; i < STYLE_ORIENT_MAX; i++) {
if (xfd->border_type[i] != GNM_STYLE_BORDER_NONE) {
fprintf (stderr, " border_type[%d] : 0x%x"
g_printerr (" border_type[%d] : 0x%x"
" border_color[%d] : 0x%x\n",
i, xfd->border_type[i],
i, xfd->border_color[i]);
}
}
fprintf (stderr, " difference bits: 0x%x\n", xfd->differences);
g_printerr (" difference bits: 0x%x\n", xfd->differences);
gnm_style_dump (xfd->mstyle);
}
......@@ -5456,7 +5453,7 @@ extract_gog_object_style (ExcelWriteState *ewb, GogObject *obj)
char *fmt_str;
g_object_get (G_OBJECT (obj), "assigned-format-string-XL", &fmt_str, NULL);
if (fmt_str != NULL) {
GOFormat *fmt = go_format_new_from_XL (fmt_str, FALSE);
GOFormat *fmt = go_format_new_from_XL (fmt_str);
if (!go_format_is_general (fmt))
two_way_table_put (ewb->formats.two_way_table,
(gpointer)fmt, TRUE,
......
......@@ -1104,7 +1104,7 @@ xlsx_get_num_fmt (GsfXMLIn *xin, char const *id)
if (end != id && *end == '\0' &&
i >= 0 && i < (int) G_N_ELEMENTS (std_builtins) &&
std_builtins[i] != NULL) {
res = go_format_new_from_XL (std_builtins[i], FALSE);
res = go_format_new_from_XL (std_builtins[i]);
g_hash_table_replace (state->num_fmts, g_strdup (id), res);
} else
xlsx_warning (xin, _("Undefined number format id '%s'"), id);
......@@ -2339,7 +2339,7 @@ xlsx_style_numfmt (GsfXMLIn *xin, xmlChar const **attrs)
if (NULL != id && NULL != fmt)
g_hash_table_replace (state->num_fmts, g_strdup (id),
go_format_new_from_XL (fmt, FALSE));
go_format_new_from_XL (fmt));
}
enum {
......
......@@ -130,13 +130,13 @@ static GnmValue *
translate_cell_format (GOFormat const *format)
{
int i;
char *fmt;
const char *fmt;
const int translate_table_count = G_N_ELEMENTS (translate_table);
if (format == NULL)
return value_new_string ("G");
fmt = go_format_as_XL (format, FALSE);
fmt = go_format_as_XL (format);
/*
* TODO : What does this do in different locales ??
......@@ -145,7 +145,6 @@ translate_cell_format (GOFormat const *format)
const translate_t *t = &translate_table[i];
if (!g_ascii_strcasecmp (fmt, t->format)) {
g_free (fmt);
return value_new_string (t->output);
}
}
......@@ -158,7 +157,6 @@ translate_cell_format (GOFormat const *format)
* 3. We should add a dash if there are more alternatives.
*/
g_free (fmt);
return value_new_string ("G");
}
......
......@@ -672,14 +672,11 @@ gnumeric_fixed (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
else
g_string_append_c (format, '0');
if (decimals > 0) {
static const char zeros[128 + 1] = ".00000000000000000000000000000000"
"00000000000000000000000000000000"
"00000000000000000000000000000000"
"00000000000000000000000000000000";
g_string_append_len (format, zeros, 1 + (int)decimals);
g_string_append_c (format, '.');
go_string_append_c_n (format, '0', decimals);
}
fmt = go_format_new_from_XL (format->str, FALSE);
fmt = go_format_new_from_XL (format->str);
g_string_free (format, TRUE);
res = format_value (fmt, v, NULL, -1, workbook_date_conv (ei->pos->sheet->workbook));
......@@ -861,6 +858,7 @@ gnumeric_text (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
workbook_date_conv (ei->pos->sheet->workbook);
GString *str;
GOFormatNumberError err;
char *lfmt;
/* Why do we have to do these here? */
if (VALUE_IS_STRING (v)) {
......@@ -870,7 +868,9 @@ gnumeric_text (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
} else if (VALUE_IS_EMPTY (v))
v = value_zero;
fmt = go_format_new_from_XL (value_peek_string (argv[1]), TRUE);
lfmt = go_format_str_delocalize (value_peek_string (argv[1]));
fmt = go_format_new_from_XL (lfmt);
g_free (lfmt);
str = g_string_sized_new (80);
err = format_value_gstring (str, fmt, v, NULL, -1, conv);
if (err) {
......@@ -1110,10 +1110,8 @@ gnumeric_dollar (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
}
g_string_append (fmt_str, "#,##0");
if (decimals > 0) {
int idecs = (int)decimals;
g_string_append_c (fmt_str, '.');
g_string_set_size (fmt_str, fmt_str->len + idecs);
memset (fmt_str->str + fmt_str->len - idecs, '0', idecs);
go_string_append_c_n (fmt_str, '0', (int)decimals);
}
if (!precedes) {
g_string_append (fmt_str, space_sep ? " \"" : "\"");
......@@ -1126,7 +1124,7 @@ gnumeric_dollar (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
g_string_append_len (fmt_str, fmt_str->str, fmt_str->len - 2);
g_string_append_c (fmt_str, ')');
sf = go_format_new_from_XL (fmt_str->str, FALSE);
sf = go_format_new_from_XL (fmt_str->str);
v = value_new_float (number);
s = format_value (sf, v, NULL, -1,
......
......@@ -45,6 +45,7 @@
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
/************************************************************************
......
......@@ -1198,7 +1198,7 @@ oo_date_style_end (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
g_return_if_fail (state->accum_fmt != NULL);
g_hash_table_insert (state->formats, state->fmt_name,
go_format_new_from_XL (state->accum_fmt->str, FALSE));
go_format_new_from_XL (state->accum_fmt->str));
g_string_free (state->accum_fmt, TRUE);
state->accum_fmt = NULL;
state->fmt_name = NULL;
......
......@@ -254,7 +254,7 @@ sylk_rtd_p_parse (SylkReadState *state, char *str)
case 'P' : /* format */
tmp = sylk_parse_string (str+1);
g_ptr_array_add (state->formats,
go_format_new_from_XL (tmp, FALSE));
go_format_new_from_XL (tmp));
g_free (tmp);
break;
......
......@@ -615,7 +615,7 @@ cb_number_format_changed (G_GNUC_UNUSED GtkWidget *widget,
data->format.index);
go_format_unref (sf);
sf = go_format_new_from_XL (fmt, FALSE);
sf = go_format_new_from_XL (fmt);
gtk_label_set_text (GTK_LABEL (w),
go_format_sel_format_classification (sf));
g_ptr_array_index (data->format.formats, data->format.index) =
......@@ -645,7 +645,7 @@ stf_dialog_format_page_prepare (StfDialogData *data)
/* If necessary add new items (non-visual) */
while ((int)data->format.formats->len < data->format.renderdata->colcount)
g_ptr_array_add (data->format.formats,
go_format_new_from_XL (go_format_builtins[0][0], FALSE));
go_format_new_from_XL (go_format_builtins[0][0]));
data->format.manual_change = TRUE;
activate_column (data, 0);
......
......@@ -2,7 +2,7 @@
/* format.c - attempts to emulate excel's number formatting ability.
*
* Copyright (C) 1998 Chris Lahey, Miguel de Icaza
* Copyright (C) 2006 Morten Welinder (terra@gnome.org)
* Copyright (C) 2006-2007 Morten Welinder (terra@gnome.org)
*
* Redid the format parsing routine to make it accept more of the Excel
* formats. The number rendeing code from Chris has not been touched,
......@@ -203,15 +203,14 @@ format_value (GOFormat const *format, GnmValue const *value, GOColor *go_color,
return g_string_free (result, FALSE);
}
int
gnm_format_is_date_for_value (GOFormat const *fmt,
GnmValue const *value)
GOFormat const *
gnm_format_specialize (GOFormat const *fmt, GnmValue const *value)
{
char type;
gnm_float val;
g_return_val_if_fail (fmt != NULL, -1);
g_return_val_if_fail (value != NULL, -1);
g_return_val_if_fail (fmt != NULL, go_format_general ());
g_return_val_if_fail (value != NULL, fmt);
if (VALUE_IS_FLOAT (value)) {
val = value_get_as_float (value);
......@@ -222,11 +221,17 @@ gnm_format_is_date_for_value (GOFormat const *fmt,
type = VALUE_IS_ERROR (value) ? 'E' : 'S';
}
return
#ifdef WITH_LONG_DOUBLE
go_format_is_date_for_valuel
return go_format_specializel (fmt, val, type, NULL);
#else
go_format_is_date_for_value
return go_format_specialize (fmt, val, type, NULL);
#endif
(fmt, val, type);
}
int
gnm_format_is_date_for_value (GOFormat const *fmt,
GnmValue const *value)
{
fmt = gnm_format_specialize (fmt, value);
return go_format_is_date (fmt);
}
......@@ -26,6 +26,9 @@ GOFormatNumberError gnm_format_layout (PangoLayout *result,
GODateConventions const *date_conv,
gboolean unicode_minus);
GOFormat const * gnm_format_specialize (GOFormat const *fmt,
GnmValue const *value);
int gnm_format_is_date_for_value (GOFormat const *fmt,
GnmValue const *value);
......
......@@ -1165,7 +1165,7 @@ gnm_style_set_format_text (GnmStyle *style, char const *format)
* I am not sure people are feeding us only translated formats.
* This entire function should be deleted.
*/
sf = go_format_new_from_XL (format, FALSE);
sf = go_format_new_from_XL (format);
gnm_style_set_format (style, sf);
go_format_unref (sf);
}
......@@ -1694,9 +1694,8 @@ gnm_style_dump (GnmStyle const *style)
if (elem_is_set (style, MSTYLE_FONT_SIZE))
g_printerr ("\tsize %f\n", style->font_detail.size);
if (elem_is_set (style, MSTYLE_FORMAT)) {
char *fmt = go_format_as_XL (style->format, FALSE);
const char *fmt = go_format_as_XL (style->format);
g_printerr ("\tformat '%s'\n", fmt);
g_free (fmt);
}
if (elem_is_set (style, MSTYLE_ALIGN_V))
g_printerr ("\tvalign %hd\n", style->v_align);
......
......@@ -567,7 +567,7 @@ format_match_time (char const *text, gboolean allow_elapsed,
v = value_new_float (time_val);
if (add_format) {
GOFormat *fmt = go_format_new_from_XL (time_format, FALSE);
GOFormat *fmt = go_format_new_from_XL (time_format);
value_set_fmt (v, fmt);
go_format_unref (fmt);
}
......@@ -591,7 +591,7 @@ format_match_datetime (char const *text,
int dig1;
char const *date_format = NULL;
GnmValue *v = NULL;
char *time_format = NULL;
const char *time_format = NULL;
if (lc_time != datetime_locale.lc_time &&
(lc_time == NULL ||
......@@ -747,7 +747,7 @@ format_match_datetime (char const *text,
time_val = value_get_as_float (v);
fmt = VALUE_FMT (v);
if (fmt)
time_format = go_format_as_XL (fmt, FALSE);
time_format = go_format_as_XL (fmt);
value_release (v);
} else
time_val = 0;
......@@ -760,11 +760,10 @@ format_match_datetime (char const *text,
" ",
time_format,
NULL);
fmt = go_format_new_from_XL (format, FALSE);
fmt = go_format_new_from_XL (format);
g_free (format);
g_free (time_format);
} else
fmt = go_format_new_from_XL (date_format, FALSE);
fmt = go_format_new_from_XL (date_format);
value_set_fmt (v, fmt);
go_format_unref (fmt);
}
......@@ -775,7 +774,7 @@ format_match_datetime (char const *text,
static gboolean
hack_month_before_day (GOFormat const *cur_fmt)
{
char *s = go_format_as_XL (cur_fmt, FALSE);
char *s = g_strdup (go_format_as_XL (cur_fmt));
char *p;
char const *pos_m, *pos_d;
gboolean res;
......@@ -798,9 +797,8 @@ hack_month_before_day (GOFormat const *cur_fmt)
static gboolean
hack_prefer_hour (GOFormat const *cur_fmt)
{
char *s = go_format_as_XL (cur_fmt, FALSE);
const char *s = go_format_as_XL (cur_fmt);
gboolean res = (strchr (s, 'h') != NULL);
g_free (s);
return res;
}
......@@ -1164,7 +1162,7 @@ format_match (char const *text, GOFormat *cur_fmt,
case GO_FORMAT_ACCOUNTING: {
GOFormat *fmt =
go_format_new_from_XL
(go_format_builtins[fam][2], FALSE);
(go_format_builtins[fam][2]);
value_set_fmt (v, fmt);
go_format_unref (fmt);
break;
......@@ -1196,7 +1194,7 @@ format_match (char const *text, GOFormat *cur_fmt,
denlen = MIN (denlen, 5);
sprintf (fmtstr, "# %s/%s", qqq - denlen, qqq - denlen);
fmt = go_format_new_from_XL (fmtstr, FALSE);
fmt = go_format_new_from_XL (fmtstr);
value_set_fmt (v, fmt);
go_format_unref (fmt);
return v;
......
......@@ -421,7 +421,7 @@ render_value_with_format (GString *target, char const *number_format, HFRenderIn
GOFormat *format;
/* TODO : Check this assumption. Is it a localized format ?? */
format = go_format_new_from_XL (number_format, FALSE);
format = go_format_new_from_XL (number_format);
format_value_gstring (target, format, info->date_time, NULL, -1, NULL);
go_format_unref (format);
}
......
......@@ -145,7 +145,7 @@ try_auto_date (GnmValue *value, const GOFormat *format,
if (needs_frac_sec)
g_string_append (xlfmt, ".000000");
}
actual = go_format_new_from_XL (xlfmt->str, FALSE);
actual = go_format_new_from_XL (xlfmt->str);
g_string_free (xlfmt, TRUE);
res = format_value (actual, value, NULL, -1, date_conv);
go_format_unref (actual);
......
......@@ -880,7 +880,7 @@ wbcg_edit_start (WorkbookControlGUI *wbcg,
g_string_append_c (fstr, ' ');
guess_time_format (fstr, f - gnm_floor (f));
}
new_fmt = go_format_new_from_XL (fstr->str, FALSE);
new_fmt = go_format_new_from_XL (fstr->str);
g_string_free (fstr, TRUE);
text = format_value (new_fmt, cell->value,
......@@ -903,7 +903,7 @@ wbcg_edit_start (WorkbookControlGUI *wbcg,
GOFormat *new_fmt;
guess_time_format (fstr, f);
new_fmt = go_format_new_from_XL (fstr->str, FALSE);
new_fmt = go_format_new_from_XL (fstr->str);
g_string_free (fstr, TRUE);
text = format_value (new_fmt, cell->value, NULL, -1,
......
......@@ -1173,7 +1173,7 @@ xml_read_cell (XmlParseContext *ctxt, xmlNodePtr tree)
fmt = xmlGetProp (tree, CC2XML ("ValueFormat"));
if (fmt != NULL) {
value_fmt = go_format_new_from_XL (CXML2C (fmt), FALSE);
value_fmt = go_format_new_from_XL (CXML2C (fmt));
xmlFree (fmt);
}
}
......@@ -2011,7 +2011,7 @@ xml_read_clipboard_cell (XmlParseContext *ctxt, xmlNodePtr tree,
fmt = xmlGetProp (tree, CC2XML ("ValueFormat"));
if (fmt != NULL) {
value_fmt = go_format_new_from_XL (CXML2C (fmt), FALSE);
value_fmt = go_format_new_from_XL (CXML2C (fmt));
xmlFree (fmt);
}
}
......
......@@ -1344,7 +1344,7 @@ xml_sax_cell (GsfXMLIn *xin, xmlChar const **attrs)
else if (gnm_xml_attr_int (attrs, "ExprID", &expr_id)) ;
else if (gnm_xml_attr_int (attrs, "ValueType", &value_type)) ;
else if (attr_eq (attrs[0], "ValueFormat"))
value_fmt = go_format_new_from_XL (CXML2C (attrs[1]), FALSE);
value_fmt = go_format_new_from_XL (CXML2C (attrs[1]));
else
unknown_attr (xin, attrs);
}
......
......@@ -384,9 +384,8 @@ xml_write_gnmstyle (GnmOutputXML *state, GnmStyle const *style)
if (gnm_style_is_element_set (style, MSTYLE_COLOR_PATTERN))
gnm_xml_out_add_color (state->output, "PatternColor", gnm_style_get_pattern_color (style));
if (gnm_style_is_element_set (style, MSTYLE_FORMAT)) {
char *fmt = go_format_as_XL (gnm_style_get_format (style), FALSE);
const char *fmt = go_format_as_XL (gnm_style_get_format (style));
gsf_xml_out_add_cstr (state->output, "Format", fmt);
g_free (fmt);
}
if (gnm_style_is_element_set (style, MSTYLE_FONT_NAME) ||
......@@ -725,9 +724,8 @@ xml_write_cell_and_position (GnmOutputXML *state,
if (val != NULL) {
gsf_xml_out_add_int (state->output, "ValueType", val->type);
if (VALUE_FMT (val) != NULL) {
char *fmt = go_format_as_XL (VALUE_FMT (val), FALSE);
const char *fmt = go_format_as_XL (VALUE_FMT (val));
gsf_xml_out_add_cstr (state->output, "ValueFormat", fmt);
g_free (fmt);
}
value_get_as_gstring (val, str, state->exprconv);
} else {
......
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