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

changes to the classification interface. It will continue to evolve.

2002-02-06  Jody Goldberg <jody@gnome.org>

	* src/sheet-autofill.c (autofill_create_fill_items) : changes to the
	classification interface.  It will continue to evolve.

	* src/formats.c (cell_format_classify) : change the signature.  In the
	  future this should really be split.  This routine is
	  1) stupid
	  2) wrong
	  It is really only useful in the context of the format dialog.
	  however, our desire to call it elsewhere indicates what the new
	  format engine should make easiliy accessible.

	* src/expr.c (expr_eval_real) : quick and easy support for autoformat
	  style formating for percent operator.  Just a quick test to see how
	  hard it would be, and it wasn't.

	* src/auto-format.c : Convert to StyleFormat.  Nothing actually uses
	  this anymore but I have not merged its logic into the eval structure
	  yet.

	* src/format-template.c (format_template_check_valid) : warning
	  suppression.

	* src/format.c (style_format_general) : new.
	(style_format_default_date) : new.
	(style_format_default_time) : new.
	(style_format_default_percentage) : new.
	(style_format_default_money) : new.

	* src/cell.c (cell_get_format) : finish the conversion.
parent ba9839f5
2002-02-06 Jody Goldberg <jody@gnome.org>
* src/sheet-autofill.c (autofill_create_fill_items) : changes to the
classification interface. It will continue to evolve.
* src/formats.c (cell_format_classify) : change the signature. In the
future this should really be split. This routine is
1) stupid
2) wrong
It is really only useful in the context of the format dialog.
however, our desire to call it elsewhere indicates what the new
format engine should make easiliy accessible.
* src/expr.c (expr_eval_real) : quick and easy support for autoformat
style formating for percent operator. Just a quick test to see how
hard it would be, and it wasn't.
* src/auto-format.c : Convert to StyleFormat. Nothing actually uses
this anymore but I have not merged its logic into the eval structure
yet.
* src/format-template.c (format_template_check_valid) : warning
suppression.
* src/format.c (style_format_general) : new.
(style_format_default_date) : new.
(style_format_default_time) : new.
(style_format_default_percentage) : new.
(style_format_default_money) : new.
* src/cell.c (cell_get_format) : finish the conversion.
2002-02-05 Jon K Hellan <hellan@acm.org>
* src/style-color.c (style_color_new_uninterned): New
......
......@@ -29,6 +29,7 @@ Jody:
* Crash importing 3d references to external workbooks.
* move libole2 req into excel plugin, and make it optional.
* guruify autoformat dialog, and update autoformat code.
* move format from cell -> value.
Jon Kåre:
* More correct import of "automatic" colors from Excel
......
2002-02-06 Jody Goldberg <jody@gnome.org>
* src/sheet-autofill.c (autofill_create_fill_items) : changes to the
classification interface. It will continue to evolve.
* src/formats.c (cell_format_classify) : change the signature. In the
future this should really be split. This routine is
1) stupid
2) wrong
It is really only useful in the context of the format dialog.
however, our desire to call it elsewhere indicates what the new
format engine should make easiliy accessible.
* src/expr.c (expr_eval_real) : quick and easy support for autoformat
style formating for percent operator. Just a quick test to see how
hard it would be, and it wasn't.
* src/auto-format.c : Convert to StyleFormat. Nothing actually uses
this anymore but I have not merged its logic into the eval structure
yet.
* src/format-template.c (format_template_check_valid) : warning
suppression.
* src/format.c (style_format_general) : new.
(style_format_default_date) : new.
(style_format_default_time) : new.
(style_format_default_percentage) : new.
(style_format_default_money) : new.
* src/cell.c (cell_get_format) : finish the conversion.
2002-02-05 Jon K Hellan <hellan@acm.org>
* src/style-color.c (style_color_new_uninterned): New
......
2002-02-06 Jody Goldberg <jody@gnome.org>
* src/sheet-autofill.c (autofill_create_fill_items) : changes to the
classification interface. It will continue to evolve.
* src/formats.c (cell_format_classify) : change the signature. In the
future this should really be split. This routine is
1) stupid
2) wrong
It is really only useful in the context of the format dialog.
however, our desire to call it elsewhere indicates what the new
format engine should make easiliy accessible.
* src/expr.c (expr_eval_real) : quick and easy support for autoformat
style formating for percent operator. Just a quick test to see how
hard it would be, and it wasn't.
* src/auto-format.c : Convert to StyleFormat. Nothing actually uses
this anymore but I have not merged its logic into the eval structure
yet.
* src/format-template.c (format_template_check_valid) : warning
suppression.
* src/format.c (style_format_general) : new.
(style_format_default_date) : new.
(style_format_default_time) : new.
(style_format_default_percentage) : new.
(style_format_default_money) : new.
* src/cell.c (cell_get_format) : finish the conversion.
2002-02-05 Jon K Hellan <hellan@acm.org>
* src/style-color.c (style_color_new_uninterned): New
......
......@@ -172,11 +172,9 @@ retrieve_format_info (Sheet *sheet, int col, int row)
{
MStyle *mstyle = sheet_style_get (sheet, col, row);
StyleFormat *format = mstyle_get_format (mstyle);
char *fmt = style_format_as_XL (format, FALSE);
FormatCharacteristics info;
cell_format_classify (fmt, &info);
g_free (fmt);
cell_format_classify (format, &info);
return info;
}
......
......@@ -495,7 +495,6 @@ latex2e_write_multicolumn_cell (FILE *fp, const Cell *cell, const int num_merged
StyleColor *textColor;
gushort r,g,b;
gboolean wrap = FALSE;
char *cell_format_str;
FormatCharacteristics cell_format_characteristic;
FormatFamily cell_format_family;
int merge_width = 0;
......@@ -653,9 +652,8 @@ latex2e_write_multicolumn_cell (FILE *fp, const Cell *cell, const int num_merged
fprintf (fp, "\\textit{");
cell_format_str = cell_get_format (cell);
cell_format_family = cell_format_classify (cell_format_str, &cell_format_characteristic);
g_free (cell_format_str);
cell_format_family = cell_format_classify (cell_get_format (cell),
&cell_format_characteristic);
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)
......
......@@ -207,10 +207,7 @@ xbase_field_new (XBfile *file)
} else
field->pos = 0;
if (field->type == 'D')
field->fmt = style_format_new_XL (cell_formats [FMT_DATE][0], FALSE);
else
field->fmt = NULL;
field->fmt = (field->type == 'D') ? style_format_default_date () : NULL;
return field; /* FIXME: use more of buf if needed ? */
}
......
......@@ -100,9 +100,9 @@ auto_format_function_result (FunctionDefinition *fd, AutoFormatTypes res)
static AutoFormatTypes do_af_suggest_list (ExprList *list,
EvalPos const *epos,
char **explicit);
StyleFormat **explicit);
struct cb_af_suggest { AutoFormatTypes typ; char **explicit; };
struct cb_af_suggest { AutoFormatTypes typ; StyleFormat **explicit; };
static Value *
cb_af_suggest (Sheet *sheet, int col, int row, Cell *cell, void *_data)
......@@ -118,7 +118,7 @@ cb_af_suggest (Sheet *sheet, int col, int row, Cell *cell, void *_data)
}
static AutoFormatTypes
do_af_suggest (const ExprTree *expr, const EvalPos *epos, char **explicit)
do_af_suggest (ExprTree const *expr, const EvalPos *epos, StyleFormat **explicit)
{
switch (expr->any.oper) {
case OPER_EQUAL:
......@@ -144,7 +144,7 @@ do_af_suggest (const ExprTree *expr, const EvalPos *epos, char **explicit)
case OPER_SUB: {
AutoFormatTypes typ1, typ2;
char *explicit1 = NULL, *explicit2 = NULL;
StyleFormat *explicit1 = NULL, *explicit2 = NULL;
typ1 = do_af_suggest (expr->binary.value_a, epos, &explicit1);
typ2 = do_af_suggest (expr->binary.value_b, epos, &explicit2);
......@@ -153,10 +153,8 @@ do_af_suggest (const ExprTree *expr, const EvalPos *epos, char **explicit)
return AF_UNITLESS;
else if (typ1 != AF_UNKNOWN && typ1 != AF_UNITLESS) {
*explicit = explicit1;
g_free (explicit2);
return typ1;
} else {
g_free (explicit1);
*explicit = explicit2;
return typ2;
}
......@@ -259,7 +257,7 @@ do_af_suggest (const ExprTree *expr, const EvalPos *epos, char **explicit)
}
static AutoFormatTypes
do_af_suggest_list (ExprList *list, const EvalPos *epos, char **explicit)
do_af_suggest_list (ExprList *list, const EvalPos *epos, StyleFormat **explicit)
{
AutoFormatTypes typ = AF_UNKNOWN;
while (list && (typ == AF_UNKNOWN || typ == AF_UNITLESS)) {
......@@ -272,9 +270,9 @@ do_af_suggest_list (ExprList *list, const EvalPos *epos, char **explicit)
/* ------------------------------------------------------------------------- */
static char *
auto_format_suggest (const ExprTree *expr, const EvalPos *epos)
auto_format_suggest (ExprTree const *expr, EvalPos const *epos)
{
char *explicit = NULL;
StyleFormat *explicit = NULL;
g_return_val_if_fail (expr != NULL, NULL);
g_return_val_if_fail (epos != NULL, NULL);
......@@ -283,24 +281,20 @@ auto_format_suggest (const ExprTree *expr, const EvalPos *epos)
case AF_EXPLICIT:
break;
case AF_DATE:
/* FIXME: any better idea? */
explicit = g_strdup (cell_formats[FMT_DATE][0]);
case AF_DATE: /* FIXME: any better idea? */
explicit = style_format_default_date ();
break;
case AF_TIME:
/* FIXME: any better idea? */
explicit = g_strdup (cell_formats[FMT_TIME][0]);
case AF_TIME: /* FIXME: any better idea? */
explicit = style_format_default_time ();
break;
case AF_PERCENT:
/* FIXME: any better idea? */
explicit = g_strdup (cell_formats[FMT_PERCENT][1]);
case AF_PERCENT: /* FIXME: any better idea? */
explicit = style_format_default_percentage ();
break;
case AF_MONETARY:
/* FIXME: any better idea? */
explicit = g_strdup (cell_formats[FMT_CURRENCY][3]);
case AF_MONETARY: /* FIXME: any better idea? */
explicit = style_format_default_money ();
break;
case AF_FIRST_ARG_FORMAT:
......
......@@ -665,24 +665,22 @@ cell_get_mstyle (Cell const *cell)
* Get the display format. If the assigned format is General,
* the format of the value will be used.
*/
char *
StyleFormat *
cell_get_format (Cell const *cell)
{
char *result = NULL;
StyleFormat const *fmt;
g_return_val_if_fail (cell != NULL, g_strdup ("General"));
g_return_val_if_fail (cell != NULL, style_format_general ());
fmt = mstyle_get_format (cell_get_mstyle (cell));
g_return_val_if_fail (fmt != NULL, g_strdup ("General"));
g_return_val_if_fail (fmt != NULL, style_format_general ());
if (style_format_is_general (fmt) &&
cell->value != NULL && VALUE_FMT (cell->value))
fmt = VALUE_FMT (cell->value);
#warning make this a StyleFormat
return style_format_as_XL (fmt, FALSE);
return fmt;
}
/*
......
......@@ -80,7 +80,7 @@ void cell_convert_expr_to_value (Cell *cell);
* Manipulate Cell attributes
*/
MStyle *cell_get_mstyle (Cell const *cell);
char * cell_get_format (Cell const *cell);
StyleFormat *cell_get_format (Cell const *cell);
void cell_set_format (Cell *cell, char const *format);
void cell_render_value (Cell *cell, gboolean dynamic_width);
......
......@@ -764,8 +764,15 @@ expr_eval_real (ExprTree const *expr, EvalPos const *pos,
res = value_new_float (-a->v_float.val);
else
res = value_new_bool (!a->v_float.val);
} else
if (VALUE_FMT (a) != NULL) {
VALUE_FMT (res) = VALUE_FMT (a);
style_format_ref (VALUE_FMT (res));
}
} else {
res = value_new_float (value_get_as_float (a) * .01);
VALUE_FMT (res) = style_format_default_percentage ();
style_format_ref (VALUE_FMT (res));
}
value_release (a);
return res;
......
......@@ -1203,11 +1203,13 @@ cb_format_sheet_style (FormatTemplate *ft, Range *r, MStyle *mstyle, Sheet *shee
* @cc : where to report errors
*
* check to see if the @regions are able to contain the support template @ft.
* Returns TRUE if ok, else FALSE. Will report an error to @cc if it is
* supplied.
*/
gboolean
format_template_check_valid (FormatTemplate *ft, GSList *regions, CommandContext *cc)
{
g_return_if_fail (cc != NULL);
g_return_val_if_fail (cc != NULL, FALSE);
for (; regions != NULL ; regions = regions->next)
if (!format_template_range_check (ft, regions->data, cc))
......
......@@ -34,6 +34,7 @@
#include "mathfunc.h"
#include "str.h"
#include "number-match.h"
#include "formats.h"
#include <libgnome/gnome-i18n.h>
#include <locale.h>
......@@ -1885,3 +1886,47 @@ style_format_is_text (StyleFormat const *sf)
{
return 0 == strcmp (sf->format, "@");
}
StyleFormat *
style_format_general (void)
{
static StyleFormat *fmt = NULL;
if (fmt == NULL)
fmt = style_format_new_XL (cell_formats[FMT_GENERAL][0], FALSE);
return fmt;
}
StyleFormat *
style_format_default_date (void)
{
static StyleFormat *fmt = NULL;
if (fmt == NULL)
fmt = style_format_new_XL (cell_formats[FMT_DATE][0], FALSE);
return fmt;
}
StyleFormat *
style_format_default_time (void)
{
static StyleFormat *fmt = NULL;
if (fmt == NULL)
fmt = style_format_new_XL (cell_formats[FMT_TIME][0], FALSE);
return fmt;
}
StyleFormat *
style_format_default_percentage (void)
{
static StyleFormat *fmt = NULL;
if (fmt == NULL)
fmt = style_format_new_XL (cell_formats[FMT_PERCENT][1], FALSE);
return fmt;
}
StyleFormat *
style_format_default_money (void)
{
static StyleFormat *fmt = NULL;
if (fmt == NULL)
fmt = style_format_new_XL (cell_formats[FMT_CURRENCY][3], FALSE);
return fmt;
}
......@@ -27,6 +27,12 @@ void style_format_unref (StyleFormat *sf);
gboolean style_format_is_general (StyleFormat const *sf);
gboolean style_format_is_text (StyleFormat const *sf);
StyleFormat *style_format_general (void);
StyleFormat *style_format_default_date (void);
StyleFormat *style_format_default_time (void);
StyleFormat *style_format_default_percentage (void);
StyleFormat *style_format_default_money (void);
void format_destroy (StyleFormat *format);
char *format_value (StyleFormat const *format, Value const *value, StyleColor **color,
float col_width);
......
......@@ -578,8 +578,9 @@ cell_format_is_number (char const * const fmt, FormatCharacteristics *info)
}
FormatFamily
cell_format_classify (char const * const fmt, FormatCharacteristics *info)
cell_format_classify (StyleFormat const *sf, FormatCharacteristics *info)
{
char const *fmt = sf->format;
FormatFamily res;
int i;
......@@ -591,6 +592,8 @@ cell_format_classify (char const * const fmt, FormatCharacteristics *info)
info->num_decimals = 2;
info->negative_fmt = 0;
info->currency_symbol_index = 1; /* '$' */
info->date_has_days = FALSE;
info->date_has_months = FALSE;
/* Can we parse it ? */
if ((res = cell_format_is_number (fmt, info)) != FMT_UNKNOWN)
......
......@@ -31,9 +31,11 @@ typedef struct
gint negative_fmt; /* 0 - 3 */
gint currency_symbol_index;
gint list_element;
gboolean date_has_days : 1;
gboolean date_has_months : 1;
} FormatCharacteristics;
FormatFamily cell_format_classify (char const * const fmt, FormatCharacteristics *info);
FormatFamily cell_format_classify (StyleFormat const *fmt, FormatCharacteristics *info);
/* Indexed by FormatCharacteristics */
extern char const * const * const cell_formats [];
......
......@@ -172,11 +172,9 @@ retrieve_format_info (Sheet *sheet, int col, int row)
{
MStyle *mstyle = sheet_style_get (sheet, col, row);
StyleFormat *format = mstyle_get_format (mstyle);
char *fmt = style_format_as_XL (format, FALSE);
FormatCharacteristics info;
cell_format_classify (fmt, &info);
g_free (fmt);
cell_format_classify (format, &info);
return info;
}
......
......@@ -674,14 +674,13 @@ gnm_graph_add_vector (GnmGraph *graph, ExprTree *expr,
vector->value->type == VALUE_CELLRANGE) {
Range r;
Sheet *start_sheet, *end_sheet;
char *fmt;
StyleFormat *fmt;
FormatCharacteristics info;
FormatFamily family;
value_cellrange_normalize (&ep, vector->value, &start_sheet, &end_sheet, &r);
fmt = cell_get_format (sheet_cell_get (start_sheet, r.start.col, r.start.row));
family = cell_format_classify (fmt, &info);
g_free (fmt);
if (family == FMT_DATE)
type = GNM_VECTOR_DATE;
} else
......
......@@ -302,28 +302,14 @@ fill_item_new (Sheet *sheet, int col, int row)
value_type = VALUE_TYPE (value);
if (value_type == VALUE_INTEGER || value_type == VALUE_FLOAT) {
FillType fill = FILL_NUMBER;
FormatCharacteristics info;
/* Use display format to recognize iteration types */
char *fmt = cell_get_format (cell);
if (fmt != NULL) {
FormatCharacteristics info;
FormatFamily family = cell_format_classify (fmt, &info);
/* FIXME : We need better format classification that this.
* the XL format is crap. redo it.
*/
if (family == FMT_DATE)
fill = (str_contains (fmt, 'd') || str_contains (fmt, 'D'))
? FILL_DAYS
: ((str_contains (fmt, 'm') || str_contains (fmt, 'M'))
? FILL_MONTHS : FILL_YEARS);
g_free (fmt);
}
fi->type = fill;
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
? FILL_DAYS
: info.date_has_months ? FILL_MONTHS : FILL_YEARS;
return fi;
}
......
......@@ -178,7 +178,8 @@ sort_permute (WorkbookControl *context, SortData *data, const int *perm, int len
PasteTarget pt;
pt.sheet = data->sheet;
pt.paste_flags = PASTE_FORMATS | PASTE_CONTENT | PASTE_EXPR_RELOCATE;
#warning adding the flag causes 59144, why did I add it in the first place ?
pt.paste_flags = PASTE_FORMATS | PASTE_CONTENT; /* | PASTE_EXPR_RELOCATE; */
#ifdef DEBUG_SORT
fprintf (stderr, "Permutation:");
......
......@@ -1941,10 +1941,8 @@ static void
cb_insert_current_date (GtkWidget *widget, WorkbookControlGUI *wbcg)
{
Value *v = value_new_int (datetime_timet_to_serial (time (NULL)));
StyleFormat *fmt = style_format_new_XL (cell_formats[FMT_DATE][0], TRUE);
char *txt = format_value (fmt, v, NULL, -1);
char *txt = format_value (style_format_default_date (), v, NULL, -1);
value_release (v);
style_format_unref (fmt);
wbcg_edit_start (wbcg, FALSE, FALSE);
wbcg_edit_line_set (WORKBOOK_CONTROL (wbcg), txt);
g_free (txt);
......@@ -1954,10 +1952,8 @@ static void
cb_insert_current_time (GtkWidget *widget, WorkbookControlGUI *wbcg)
{
Value *v = value_new_float (datetime_timet_to_seconds (time (NULL)) / (24.0 * 60 * 60));
StyleFormat *fmt = style_format_new_XL (cell_formats[FMT_TIME][0], TRUE);
char *txt = format_value (fmt, v, NULL, -1);
char *txt = format_value (style_format_default_time (), v, NULL, -1);
value_release (v);
style_format_unref (fmt);
wbcg_edit_start (wbcg, FALSE, FALSE);
wbcg_edit_line_set (WORKBOOK_CONTROL (wbcg), txt);
g_free (txt);
......
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