Commit 629daef1 authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg
Browse files

Remove 'entered_text' foolishness.

2000-11-05  Jody Goldberg <jgoldberg@home.com>

	* src/sheet.c (cb_set_cell_content) : Use cell_set_value.
	(sheet_range_set_text) : remove need for entered_text.

	* src/xml-io.c (xml_read_cell) : Remove 'General' hack.

	* src/dialogs/dialog-cell-format.c (draw_format_preview) : remove
	  entered_text.

	* src/rendered-value.c (rendered_value_new_ext) : No need for
	  entered_text.  Use format_value in place of value_as_string.

	* src/format.c (format_value) : No need for entered_text.
	  Be careful to always set the colour.  This may need to be tuned
	  if we enter '$10' and use a display format of @ what should be
	  displayed ?  10 or $10 ?  We may need to pass in the parse format.

	* src/cell.c (cell_cleanout) : Remove entered_text.
	(cell_copy) : Ditto.
	(cell_set_text) : Ditto.
	(cell_set_value) : Ditto, do not render value here.
	(cell_set_text_and_value) : Delete.
	(cell_set_expr_and_value) : Remove entered_text, and add format
	  argument.
	(cell_set_expr_internal) : No need to manually unref the old expr.
	  That was already done in cleanout.
	(cell_make_value) : remove entered_text.

	* src/rendered-value.c (cell_get_entered_text) : Use the stored parse
	  format and format_value to regenerate the entered text from a value.
parent 26aa4962
2000-11-05 Jody Goldberg <jgoldberg@home.com>
* src/sheet.c (cb_set_cell_content) : Use cell_set_value.
(sheet_range_set_text) : remove need for entered_text.
* src/xml-io.c (xml_read_cell) : Remove 'General' hack.
* src/dialogs/dialog-cell-format.c (draw_format_preview) : remove
entered_text.
* src/rendered-value.c (rendered_value_new_ext) : No need for
entered_text. Use format_value in place of value_as_string.
* src/format.c (format_value) : No need for entered_text.
Be careful to always set the colour. This may need to be tuned
if we enter '$10' and use a display format of @ what should be
displayed ? 10 or $10 ? We may need to pass in the parse format.
* src/cell.c (cell_cleanout) : Remove entered_text.
(cell_copy) : Ditto.
(cell_set_text) : Ditto.
(cell_set_value) : Ditto, do not render value here.
(cell_set_text_and_value) : Delete.
(cell_set_expr_and_value) : Remove entered_text, and add format
argument.
(cell_set_expr_internal) : No need to manually unref the old expr.
That was already done in cleanout.
(cell_make_value) : remove entered_text.
* src/rendered-value.c (cell_get_entered_text) : Use the stored parse
format and format_value to regenerate the entered text from a value.
2000-11-04 Jody Goldberg <jgoldberg@home.com>
* src/sheet-view.c (sheet_view_{col,row}_size_changed) : Only resize
......
2000-11-05 Jody Goldberg <jgoldberg@home.com>
* src/sheet.c (cb_set_cell_content) : Use cell_set_value.
(sheet_range_set_text) : remove need for entered_text.
* src/xml-io.c (xml_read_cell) : Remove 'General' hack.
* src/dialogs/dialog-cell-format.c (draw_format_preview) : remove
entered_text.
* src/rendered-value.c (rendered_value_new_ext) : No need for
entered_text. Use format_value in place of value_as_string.
* src/format.c (format_value) : No need for entered_text.
Be careful to always set the colour. This may need to be tuned
if we enter '$10' and use a display format of @ what should be
displayed ? 10 or $10 ? We may need to pass in the parse format.
* src/cell.c (cell_cleanout) : Remove entered_text.
(cell_copy) : Ditto.
(cell_set_text) : Ditto.
(cell_set_value) : Ditto, do not render value here.
(cell_set_text_and_value) : Delete.
(cell_set_expr_and_value) : Remove entered_text, and add format
argument.
(cell_set_expr_internal) : No need to manually unref the old expr.
That was already done in cleanout.
(cell_make_value) : remove entered_text.
* src/rendered-value.c (cell_get_entered_text) : Use the stored parse
format and format_value to regenerate the entered text from a value.
2000-11-04 Jody Goldberg <jgoldberg@home.com>
* src/sheet-view.c (sheet_view_{col,row}_size_changed) : Only resize
......
2000-11-05 Jody Goldberg <jgoldberg@home.com>
* src/sheet.c (cb_set_cell_content) : Use cell_set_value.
(sheet_range_set_text) : remove need for entered_text.
* src/xml-io.c (xml_read_cell) : Remove 'General' hack.
* src/dialogs/dialog-cell-format.c (draw_format_preview) : remove
entered_text.
* src/rendered-value.c (rendered_value_new_ext) : No need for
entered_text. Use format_value in place of value_as_string.
* src/format.c (format_value) : No need for entered_text.
Be careful to always set the colour. This may need to be tuned
if we enter '$10' and use a display format of @ what should be
displayed ? 10 or $10 ? We may need to pass in the parse format.
* src/cell.c (cell_cleanout) : Remove entered_text.
(cell_copy) : Ditto.
(cell_set_text) : Ditto.
(cell_set_value) : Ditto, do not render value here.
(cell_set_text_and_value) : Delete.
(cell_set_expr_and_value) : Remove entered_text, and add format
argument.
(cell_set_expr_internal) : No need to manually unref the old expr.
That was already done in cleanout.
(cell_make_value) : remove entered_text.
* src/rendered-value.c (cell_get_entered_text) : Use the stored parse
format and format_value to regenerate the entered text from a value.
2000-11-04 Jody Goldberg <jgoldberg@home.com>
* src/sheet-view.c (sheet_view_{col,row}_size_changed) : Only resize
......
2000-11-05 Jody Goldberg <jgoldberg@home.com>
* src/sheet.c (cb_set_cell_content) : Use cell_set_value.
(sheet_range_set_text) : remove need for entered_text.
* src/xml-io.c (xml_read_cell) : Remove 'General' hack.
* src/dialogs/dialog-cell-format.c (draw_format_preview) : remove
entered_text.
* src/rendered-value.c (rendered_value_new_ext) : No need for
entered_text. Use format_value in place of value_as_string.
* src/format.c (format_value) : No need for entered_text.
Be careful to always set the colour. This may need to be tuned
if we enter '$10' and use a display format of @ what should be
displayed ? 10 or $10 ? We may need to pass in the parse format.
* src/cell.c (cell_cleanout) : Remove entered_text.
(cell_copy) : Ditto.
(cell_set_text) : Ditto.
(cell_set_value) : Ditto, do not render value here.
(cell_set_text_and_value) : Delete.
(cell_set_expr_and_value) : Remove entered_text, and add format
argument.
(cell_set_expr_internal) : No need to manually unref the old expr.
That was already done in cleanout.
(cell_make_value) : remove entered_text.
* src/rendered-value.c (cell_get_entered_text) : Use the stored parse
format and format_value to regenerate the entered text from a value.
2000-11-04 Jody Goldberg <jgoldberg@home.com>
* src/sheet-view.c (sheet_view_{col,row}_size_changed) : Only resize
......
2000-11-05 Jody Goldberg <jgoldberg@home.com>
* src/sheet.c (cb_set_cell_content) : Use cell_set_value.
(sheet_range_set_text) : remove need for entered_text.
* src/xml-io.c (xml_read_cell) : Remove 'General' hack.
* src/dialogs/dialog-cell-format.c (draw_format_preview) : remove
entered_text.
* src/rendered-value.c (rendered_value_new_ext) : No need for
entered_text. Use format_value in place of value_as_string.
* src/format.c (format_value) : No need for entered_text.
Be careful to always set the colour. This may need to be tuned
if we enter '$10' and use a display format of @ what should be
displayed ? 10 or $10 ? We may need to pass in the parse format.
* src/cell.c (cell_cleanout) : Remove entered_text.
(cell_copy) : Ditto.
(cell_set_text) : Ditto.
(cell_set_value) : Ditto, do not render value here.
(cell_set_text_and_value) : Delete.
(cell_set_expr_and_value) : Remove entered_text, and add format
argument.
(cell_set_expr_internal) : No need to manually unref the old expr.
That was already done in cleanout.
(cell_make_value) : remove entered_text.
* src/rendered-value.c (cell_get_entered_text) : Use the stored parse
format and format_value to regenerate the entered text from a value.
2000-11-04 Jody Goldberg <jgoldberg@home.com>
* src/sheet-view.c (sheet_view_{col,row}_size_changed) : Only resize
......
......@@ -766,7 +766,7 @@ gnumeric_text (FunctionEvalInfo *ei, Value **args)
if (ok) {
char *str = format_value (format,
(tmp != NULL) ? tmp : arg,
NULL, NULL, -1);
NULL, -1);
res = value_new_string (str);
g_free (str);
} else
......
......@@ -2,6 +2,7 @@
* cell.c: Cell management of the Gnumeric spreadsheet.
*
* Author:
* Jdy Goldberg 2000 (jgoldberg@home.com)
* Miguel de Icaza 1998, 1999 (miguel@kernel.org)
*/
#include "config.h"
......@@ -42,8 +43,8 @@ cell_dirty (Cell *cell)
* Empty a cell's
* - value.
* - rendered_value.
* - entered_text/expression.
* - optional format.
* - expression.
* - parse format.
*
* Clears the flags to
* - not queued for recalc.
......@@ -65,9 +66,6 @@ cell_cleanout (Cell *cell)
dependent_unlink (CELL_TO_DEP (cell), &cell->pos);
expr_tree_unref (cell->base.expression);
cell->base.expression = NULL;
} else if (cell->entered_text) {
string_unref (cell->entered_text);
cell->entered_text = NULL;
}
if (cell->value) {
......@@ -113,8 +111,6 @@ cell_copy (Cell const *cell)
/* now copy properly the rest */
if (cell_has_expr (new_cell))
expr_tree_ref (new_cell->base.expression);
else
string_ref (new_cell->entered_text);
new_cell->rendered_value = NULL;
......@@ -281,12 +277,12 @@ cell_relocate (Cell *cell, ExprRewriteInfo *rwinfo)
/****************************************************************************/
/*
* cell_set_text : Stores the supplied text as the entered_text, then parses it
* for storage as a value or expression. It marks the sheet as dirty.
* cell_set_text : Parses the supplied text for storage as a value or
* expression. It marks the sheet as dirty.
*
* If the text is an expression it IS queued for recalc.
* the format prefered by the expression is stored for later use.
* If the text is a value it is rendered but spans are not calculated.
* If the text is a value it is NOT rendered and spans are NOT calculated.
* the format that matched the text is stored for later use.
*
* WARNING : This is an internal routine that does not queue redraws,
......@@ -315,7 +311,6 @@ cell_set_text (Cell *cell, char const *text)
cell->base.flags &= ~CELL_HAS_EXPRESSION;
cell->value = val;
cell->entered_text = string_get (text);
cell->format = format;
cell_render_value (cell);
} else { /* String was an expression */
......@@ -326,40 +321,6 @@ cell_set_text (Cell *cell, char const *text)
cell_dirty (cell);
}
/*
* cell_set_text_and_value : Stores the supplied text as the entered_text, then
* stores (WITHOUT COPYING) the supplied value.
* It marks the sheet as dirty. The text is NOT parsed.
*
* The cell is rendered but spans are not calculated.
* If an optional format is supplied it is stored for later use.
*
* WARNING : This is an internal routine that does not queue redraws,
* does not auto-resize, and does not calculate spans.
*
* NOTE : This DOES check for array partitioning.
*/
void
cell_set_text_and_value (Cell *cell, String *text,
Value *v, StyleFormat *opt_fmt)
{
g_return_if_fail (cell);
g_return_if_fail (text);
g_return_if_fail (v);
g_return_if_fail (!cell_is_partial_array (cell));
if (opt_fmt != NULL)
style_format_ref (opt_fmt);
cell_dirty (cell);
cell_cleanout (cell);
cell->format = opt_fmt;
cell->entered_text = string_ref (text);
cell->value = v;
cell_render_value (cell);
}
/*
* cell_assign_value : Stores (WITHOUT COPYING) the supplied value.
* no changes are made to the expression or entered text. This
......@@ -411,10 +372,6 @@ cell_assign_value (Cell *cell, Value *v, StyleFormat *opt_fmt)
* user has assigned a non-std format. We need to improve the parser to handle
* all formats that exist within the workbook.
*
* FIXME FIXME FIXME : This is being called from other locales. however, we
* may be in the C locale while importing. Hence the rendered version of the
* entered_text is in C rather than the used selected locale.
*
* NOTE : This DOES check for array partitioning.
*/
void
......@@ -430,46 +387,10 @@ cell_set_value (Cell *cell, Value *v, StyleFormat *opt_fmt)
cell_dirty (cell);
cell_cleanout (cell);
/* TODO : It would be nice to standardize on NULL == General */
cell->format = (opt_fmt == NULL || style_format_is_general (opt_fmt))
? NULL : opt_fmt;
cell->value = v;
cell_render_value (cell);
#if 1
/* Be careful that a value passes as a string stays a string */
if (v->type == VALUE_STRING) {
/* TODO : add new string routine to avoid the extra copy */
char *tmp = g_strconcat ("\'", v->v_str.val->str, NULL);
cell->entered_text = string_get (tmp);
g_free (tmp);
} else if (opt_fmt) {
/* If available use the supplied format */
cell->entered_text = string_get_nocopy (
format_value (opt_fmt, v, NULL, NULL, -1));
} else {
/* Fall back on using the format applied to the cell.
* re-render using the assigned format to handle width
* dependent formats.
*/
MStyle *mstyle = cell_get_mstyle (cell);
StyleFormat *format = mstyle_get_format (mstyle);
cell->entered_text = string_get_nocopy (
format_value (format, v, NULL, NULL, -1));
mstyle_unref (mstyle);
}
#else
/* TODO : use this version when we have converted all callers to pass
* in a parse format.
* Gnumeric's xml format is smart enough to store the parse format
* that generated the value. Other file formats (XL) are not as smart.
* as a result we need to guess.
*/
/* Be careful that a value passes as a string stays a string */
cell->entered_text = string_get_nocopy ((v->type == VALUE_STRING)
? g_strconcat ("\'", v->v_str.val->str, NULL)
/* If available use the supplied format, else use General */
: format_value (opt_fmt?opt_fmt:"General", v, NULL, NULL, -1));
#endif
}
/*
......@@ -480,16 +401,15 @@ cell_set_value (Cell *cell, Value *v, StyleFormat *opt_fmt)
*
* If an optional format is supplied it is stored for later use.
*
* The cell is rendered but spans are not calculated, the cell is NOT marked for
* recalc.
*
* WARNING : This is an internal routine that does not queue redraws,
* does not auto-resize, and does not calculate spans.
* does not auto-resize, does not calculate spans, and does
* not render the value.
*
* NOTE : This DOES check for array partitioning.
*/
void
cell_set_expr_and_value (Cell *cell, ExprTree *expr, Value *v)
cell_set_expr_and_value (Cell *cell, ExprTree *expr, Value *v,
StyleFormat *opt_fmt)
{
g_return_if_fail (cell != NULL);
g_return_if_fail (expr != NULL);
......@@ -497,19 +417,17 @@ cell_set_expr_and_value (Cell *cell, ExprTree *expr, Value *v)
/* Repeat after me. Ref before unref. */
expr_tree_ref (expr);
if (opt_fmt != NULL)
style_format_ref (opt_fmt);
cell_dirty (cell);
cell_cleanout (cell);
cell->format = opt_fmt;
cell->base.expression = expr;
cell->base.flags |= CELL_HAS_EXPRESSION;
dependent_link (CELL_TO_DEP (cell), &cell->pos);
#if 0
/* TODO : Should we add this for consistancy ? */
cell->format = fmt;
#endif
cell->value = v;
cell_render_value (cell);
}
/**
......@@ -528,17 +446,13 @@ cell_set_expr_and_value (Cell *cell, ExprTree *expr, Value *v)
static void
cell_set_expr_internal (Cell *cell, ExprTree *expr, StyleFormat *opt_fmt)
{
expr_tree_ref (expr);
if (opt_fmt != NULL)
style_format_ref (opt_fmt);
expr_tree_ref (expr);
cell_dirty (cell);
cell_cleanout (cell);
if (cell->base.expression)
expr_tree_unref (cell->base.expression);
cell->format = opt_fmt;
cell->base.expression = expr;
cell->base.flags |= CELL_HAS_EXPRESSION;
......@@ -840,8 +754,5 @@ cell_make_value (Cell *cell)
if (cell->rendered_value == NULL)
cell_render_value (cell);
g_return_if_fail (cell->rendered_value != NULL);
cell->entered_text = string_ref (cell->rendered_value->rendered_text);
cell_dirty (cell);
}
......@@ -7,7 +7,7 @@
typedef enum {
/* MUST BE > 0xffff for dependent */
/* Cell has an expression rather than entered_text */
/* Cell has an expression (Can we use base.expr == NULL ?)*/
CELL_HAS_EXPRESSION = 0x10000,
/* Cell is linked into the sheet */
......@@ -29,11 +29,13 @@ struct _Cell {
Value *value; /* computed or entered (Must be non NULL) */
RenderedValue *rendered_value;
/* Only applies if the region has format general */
StyleFormat *format; /* Prefered format to render value */
/* DEPRECATED : this field will be removed shortly */
String *entered_text; /* Text as entered by the user. */
/*
* For exprs = The prefered output format
* For values = format that parsed the input
* also used to regenerate the entered
* text for editing.
*/
StyleFormat *format;
CellComment *comment;
};
......@@ -65,20 +67,18 @@ gboolean cell_is_partial_array (Cell const * cell);
/**
* Utilities to assign the contents of a cell
*/
void cell_set_text (Cell *cell, char const *text);
void cell_set_text_and_value (Cell *cell, String *text,
Value *v, StyleFormat *opt_fmt);
void cell_assign_value (Cell *cell, Value *v, StyleFormat *opt_fmt);
void cell_set_value (Cell *cell,
Value *v, StyleFormat *opt_fmt);
void cell_set_expr_and_value (Cell *cell, ExprTree *expr, Value *v);
void cell_set_expr (Cell *cell, ExprTree *formula,
void cell_set_text (Cell *c, char const *text);
void cell_assign_value (Cell *c, Value *v, StyleFormat *fmt);
void cell_set_value (Cell *c, Value *v, StyleFormat *fmt);
void cell_set_expr_and_value (Cell *c, ExprTree *expr, Value *v,
StyleFormat *opt_fmt);
void cell_set_expr (Cell *c, ExprTree *expr,
StyleFormat *opt_fmt);
void cell_set_expr_unsafe (Cell *cell, ExprTree *expr,
StyleFormat *opt_fmt);
void cell_set_array_formula (Sheet *sheet, int rowa, int cola,
int rowb, int colb,
ExprTree *formula,
ExprTree *expr,
gboolean queue_recalc);
/**
......
......@@ -93,7 +93,6 @@ typedef struct _FormatState
Sheet *sheet;
MStyle *style, *result;
Value *value;
char const *sample_rendered_text;
int selection_mask;
gboolean enable_edit;
......@@ -493,9 +492,8 @@ draw_format_preview (FormatState *state)
if (sf == NULL)
return;
if (state->sample_rendered_text) {
preview = format_value (sf, state->value, &preview_color,
state->sample_rendered_text, -1);
if (state->value) {
preview = format_value (sf, state->value, &preview_color, -1);
if (strlen (preview) > FORMAT_PREVIEW_MAX)
strcpy (&preview [FORMAT_PREVIEW_MAX - 5], " ...");
......@@ -1940,10 +1938,6 @@ static gboolean
cb_fmt_dialog_dialog_destroy (GtkObject *w, FormatState *state)
{
g_free ((char *)state->format.spec);
if (state->sample_rendered_text != NULL) {
g_free ((char *)state->sample_rendered_text);
state->sample_rendered_text = NULL;
}
mstyle_unref (state->style);
mstyle_unref (state->result);
gtk_object_unref (GTK_OBJECT (state->gui));
......@@ -2291,9 +2285,6 @@ dialog_cell_format (WorkbookControlGUI *wbcg, Sheet *sheet, FormatDialogPosition
state->gui = gui;
state->sheet = sheet;
state->value = sample_val;
state->sample_rendered_text = edit_cell
? cell_get_rendered_text (edit_cell)
: NULL;
state->style = mstyle;
state->result = mstyle_new ();
state->selection_mask = 0;
......
......@@ -493,7 +493,7 @@ stf_preview_format_line (RenderData_t *renderdata, GSList *data, int colcount)
sf = g_ptr_array_index (renderdata->colformats, col);
celltext = format_value (sf, value, &color, iterator->data, -1);
celltext = format_value (sf, value, &color, -1);
value_release (value);
......
......@@ -1525,70 +1525,65 @@ fmt_general_int (int val, int col_width)
*/
gchar *
format_value (StyleFormat *format, const Value *value, StyleColor **color,
char const *entered_text, float col_width)
float col_width)
{
char *v = NULL;
StyleFormatEntry entry;
gboolean is_general = FALSE;
GList *list;
g_return_val_if_fail (value != NULL, "<ERROR>");
if (color)
*color = NULL;
/* get format */
for (list = format->entries; list; list = g_list_next (list))
if (check_valid (list->data, value))
break;
if (list)
entry = *(StyleFormatEntry *)(list->data);
else
entry.format = format->format;
/* Try to parse a color specification */
if (entry.format [0] == '['){
char *end = strchr (entry.format, ']');
g_return_val_if_fail (value != NULL, "<ERROR>");
if (end) {
char first_after_bracket = entry.format [1];
if (format) {
/* get format */
for (list = format->entries; list; list = g_list_next (list))
if (check_valid (list->data, value))
break;
/*
* Special [h*], [m*], [*s] is using for
* and [$*] are for currencies.
* measuring times, not for specifying colors.
*/
if (!(first_after_bracket == 'h' ||
first_after_bracket == 's' ||
first_after_bracket == 'm' ||
first_after_bracket == '$')){
if (color)
*color = lookup_color (&entry.format [1], end);
entry.format = end+1;
if (list)
entry = *(StyleFormatEntry *)(list->data);
else
entry.format = format->format;
/* Try to parse a color specification */
if (entry.format [0] == '['){
char *end = strchr (entry.format, ']');
if (end) {
char first_after_bracket = entry.format [1];
/*
* Special [h*], [m*], [*s] is using for
* and [$*] are for currencies.
* measuring times, not for specifying colors.
*/
if (!(first_after_bracket == 'h' ||
first_after_bracket == 's' ||
first_after_bracket == 'm' ||
first_after_bracket == '$')){
if (color)
*color = lookup_color (&entry.format [1], end);
entry.format = end+1;
}
}
}
}
/* Empty formats should be ignored */
if (entry.format [0] == '\0')
return g_strdup ("");
/* Formatting a value as a text returns the entered text */
if (strcmp (entry.format, "@") == 0) {
if (value->type == VALUE_STRING)
return g_strdup (value->v_str.val->str);
if (entered_text != NULL)
return g_strdup (entered_text);
/* Empty formats should be ignored */
if (entry.format [0] == '\0')
return g_strdup ("");
/* FIXME : What does it mean to format a value as text
* without specifying the entered text ??
* use General as a failsafe */
is_general = TRUE;