Commit 4a1b760f authored by Miguel de Icaza's avatar Miguel de Icaza Committed by Arturo Espinosa

New function, used to tag a modified cell in a sheet.

1998-10-05  Miguel de Icaza  <miguel@nuclecu.unam.mx>

	* src/cell.c (cell_modified): New function, used to tag a modified
	cell in a sheet.

	* src/fn-math.c (gnumeric_average): Display error on division by
	zero.  Make the code not depend on the types returned by
	gnumeric_sum and gnumeric_count.
	(callback_function_sum): Keep sum as integers as long as
	possible instead of using floating point all the time.
parent 25c40394
1998-10-05 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/cell.c (cell_modified): New function, used to tag a modified
cell in a sheet.
* src/fn-math.c (gnumeric_average): Display error on division by
zero. Make the code not depend on the types returned by
gnumeric_sum and gnumeric_count.
(callback_function_sum): Keep sum as integers as long as
possible instead of using floating point all the time.
1998-10-03 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/fn-math.c (callback_function_sum): Do not try to be smart
......
1998-10-05 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/cell.c (cell_modified): New function, used to tag a modified
cell in a sheet.
* src/fn-math.c (gnumeric_average): Display error on division by
zero. Make the code not depend on the types returned by
gnumeric_sum and gnumeric_count.
(callback_function_sum): Keep sum as integers as long as
possible instead of using floating point all the time.
1998-10-03 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/fn-math.c (callback_function_sum): Do not try to be smart
......
SUBDIRS = intl po macros src plugins
EXTRA_DIST = gnumeric.desktop README
EXTRA_DIST = gnumeric.desktop README HACKING
dist-hook:
mkdir $(distdir)/samples
......
1998-10-05 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/cell.c (cell_modified): New function, used to tag a modified
cell in a sheet.
* src/fn-math.c (gnumeric_average): Display error on division by
zero. Make the code not depend on the types returned by
gnumeric_sum and gnumeric_count.
(callback_function_sum): Keep sum as integers as long as
possible instead of using floating point all the time.
1998-10-03 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/fn-math.c (callback_function_sum): Do not try to be smart
......
1998-10-05 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/cell.c (cell_modified): New function, used to tag a modified
cell in a sheet.
* src/fn-math.c (gnumeric_average): Display error on division by
zero. Make the code not depend on the types returned by
gnumeric_sum and gnumeric_count.
(callback_function_sum): Keep sum as integers as long as
possible instead of using floating point all the time.
1998-10-03 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/fn-math.c (callback_function_sum): Do not try to be smart
......
......@@ -335,18 +335,27 @@ gnumeric_average (void *tsheet, GList *expr_node_list, int eval_col, int eval_ro
{
Value *result;
Value *sum, *count;
double c;
sum = gnumeric_sum (tsheet, expr_node_list, eval_col, eval_row, error_string);
if (!sum)
return NULL;
count = gnumeric_count (tsheet, expr_node_list, eval_col, eval_row, error_string);
if (!count || (count && count->v.v_int == 0)){
if (!count){
value_release (sum);
return NULL;
}
result = value_float (sum->v.v_float / count->v.v_int);
c = value_gets_as_double (count->v);
if (c == 0.0){
*error_string = "Division by zero";
value_release (sum);
return NULL;
}
result = value_float (value_get_as_double (sum->v) / c);
value_release (count);
value_release (sum);
......@@ -995,11 +1004,23 @@ callback_function_sum (Sheet *sheet, Value *value, char **error_string, void *cl
switch (value->type){
case VALUE_INTEGER:
result->v.v_float += value->v.v_int;
if (result->type == VALUE_INTEGER)
result->v.v_int += value->v.v_int;
else
result->v.v_float += value->v.v_int;
break;
case VALUE_FLOAT:
result->v.v_float += value->v.v_float;
if (result->type == VALUE_FLOAT)
result->v.v_float += value->v.v_float;
else {
double v = result->v.v_int;
/* cast to float */
result->type = VALUE_FLOAT;
result->v.v_float = v + value->v.v_float;
}
break;
default:
......@@ -1016,8 +1037,8 @@ gnumeric_sum (void *tsheet, GList *expr_node_list, int eval_col, int eval_row, c
Sheet *sheet = (Sheet *) tsheet;
result = g_new (Value, 1);
result->type = VALUE_FLOAT;
result->v.v_float = 0.0;
result->type = VALUE_INTEGER;
result->v.v_int = 0;
function_iterate_argument_values (sheet, callback_function_sum, result, expr_node_list,
eval_col, eval_row, error_string);
......
......@@ -25,6 +25,12 @@ cell_formula_changed (Cell *cell)
cell_queue_recalc (cell);
}
static inline void
cell_modified (Cell *cell)
{
cell->sheet->modified = TRUE;
}
void
cell_set_formula (Cell *cell, char *text)
{
......@@ -34,6 +40,7 @@ cell_set_formula (Cell *cell, char *text)
g_return_if_fail (cell != NULL);
g_return_if_fail (text != NULL);
cell_modified (cell);
cell->parsed_node = expr_parse_string (&text [1],
cell->col->pos,
cell->row->pos,
......@@ -75,6 +82,8 @@ cell_set_alignment (Cell *cell, int halign, int valign, int orient, int auto_ret
(cell->style->orientation == orient))
return;
cell_modified (cell);
cell_queue_redraw (cell);
cell->style->halign = halign;
......@@ -95,6 +104,8 @@ cell_set_halign (Cell *cell, StyleHAlignFlags halign)
if (((unsigned int)cell->style->halign) == ((unsigned int) halign))
return;
cell_modified (cell);
cell_queue_redraw (cell);
cell->style->halign = halign;
......@@ -108,6 +119,8 @@ cell_set_font_from_style (Cell *cell, StyleFont *style_font)
g_return_if_fail (cell != NULL);
g_return_if_fail (style_font != NULL);
cell_modified (cell);
cell_queue_redraw (cell);
style_font_unref (cell->style->font);
......@@ -140,6 +153,8 @@ cell_set_style (Cell *cell, Style *reference_style)
g_return_if_fail (cell != NULL);
g_return_if_fail (reference_style != NULL);
cell_modified (cell);
cell_queue_redraw (cell);
style_destroy (cell->style);
cell->style = style_duplicate (reference_style);
......@@ -153,6 +168,8 @@ void
cell_set_foreground (Cell *cell, gushort red, gushort green, gushort blue)
{
g_return_if_fail (cell != NULL);
cell_modified (cell);
if (cell->style->valid_flags & STYLE_FORE_COLOR)
style_color_unref (cell->style->fore_color);
......@@ -168,6 +185,8 @@ cell_set_background (Cell *cell, gushort red, gushort green, gushort blue)
{
g_return_if_fail (cell != NULL);
cell_modified (cell);
if (cell->style->valid_flags & STYLE_BACK_COLOR)
style_color_unref (cell->style->back_color);
......@@ -183,6 +202,8 @@ cell_set_pattern (Cell *cell, int pattern)
{
g_return_if_fail (cell != NULL);
cell_modified (cell);
cell->style->valid_flags |= STYLE_PATTERN;
cell->style->pattern = pattern;
......@@ -203,6 +224,8 @@ cell_set_rendered_text (Cell *cell, char *rendered_text)
g_return_if_fail (cell != NULL);
g_return_if_fail (rendered_text != NULL);
cell_modified (cell);
if (cell->text)
string_unref (cell->text);
......@@ -258,6 +281,8 @@ cell_set_text_simple (Cell *cell, char *text)
g_return_if_fail (cell != NULL);
g_return_if_fail (text != NULL);
cell_modified (cell);
/* The value entered */
if (cell->entered_text)
string_unref (cell->entered_text);
......@@ -408,6 +433,8 @@ cell_destroy (Cell *cell)
{
g_return_if_fail (cell != NULL);
cell_modified (cell);
if (cell->parsed_node){
expr_tree_unref (cell->parsed_node);
}
......@@ -494,6 +521,7 @@ cell_set_format_simple (Cell *cell, char *format)
return;
/* Change the format */
cell_modified (cell);
style_format_unref (cell->style->format);
cell->style->format = style_format_new (format);
cell->flags |= CELL_FORMAT_SET;
......@@ -515,6 +543,7 @@ cell_set_format (Cell *cell, char *format)
if (strcmp (format, cell->style->format->format) == 0)
return;
cell_modified (cell);
cell_queue_redraw (cell);
/* Change the format */
......@@ -535,6 +564,8 @@ cell_set_comment (Cell *cell, char *str)
g_return_if_fail (cell != NULL);
g_return_if_fail (str != NULL);
cell_modified (cell);
if (cell->comment){
string_unref (cell->comment);
had_comments = TRUE;
......@@ -566,6 +597,8 @@ cell_formula_relocate (Cell *cell, int target_col, int target_row)
g_return_if_fail (cell->entered_text);
g_return_if_fail (cell->parsed_node);
cell_modified (cell);
string_unref (cell->entered_text);
text = expr_decode_tree (cell->parsed_node, target_col, target_row);
......@@ -590,6 +623,8 @@ cell_make_value (Cell *cell)
g_return_if_fail (cell != NULL);
g_return_if_fail (cell->parsed_node != NULL);
cell_modified (cell);
expr_tree_unref (cell->parsed_node);
cell->parsed_node = NULL;
string_unref (cell->entered_text);
......
......@@ -335,18 +335,27 @@ gnumeric_average (void *tsheet, GList *expr_node_list, int eval_col, int eval_ro
{
Value *result;
Value *sum, *count;
double c;
sum = gnumeric_sum (tsheet, expr_node_list, eval_col, eval_row, error_string);
if (!sum)
return NULL;
count = gnumeric_count (tsheet, expr_node_list, eval_col, eval_row, error_string);
if (!count || (count && count->v.v_int == 0)){
if (!count){
value_release (sum);
return NULL;
}
result = value_float (sum->v.v_float / count->v.v_int);
c = value_gets_as_double (count->v);
if (c == 0.0){
*error_string = "Division by zero";
value_release (sum);
return NULL;
}
result = value_float (value_get_as_double (sum->v) / c);
value_release (count);
value_release (sum);
......@@ -995,11 +1004,23 @@ callback_function_sum (Sheet *sheet, Value *value, char **error_string, void *cl
switch (value->type){
case VALUE_INTEGER:
result->v.v_float += value->v.v_int;
if (result->type == VALUE_INTEGER)
result->v.v_int += value->v.v_int;
else
result->v.v_float += value->v.v_int;
break;
case VALUE_FLOAT:
result->v.v_float += value->v.v_float;
if (result->type == VALUE_FLOAT)
result->v.v_float += value->v.v_float;
else {
double v = result->v.v_int;
/* cast to float */
result->type = VALUE_FLOAT;
result->v.v_float = v + value->v.v_float;
}
break;
default:
......@@ -1016,8 +1037,8 @@ gnumeric_sum (void *tsheet, GList *expr_node_list, int eval_col, int eval_row, c
Sheet *sheet = (Sheet *) tsheet;
result = g_new (Value, 1);
result->type = VALUE_FLOAT;
result->v.v_float = 0.0;
result->type = VALUE_INTEGER;
result->v.v_int = 0;
function_iterate_argument_values (sheet, callback_function_sum, result, expr_node_list,
eval_col, eval_row, error_string);
......
......@@ -335,18 +335,27 @@ gnumeric_average (void *tsheet, GList *expr_node_list, int eval_col, int eval_ro
{
Value *result;
Value *sum, *count;
double c;
sum = gnumeric_sum (tsheet, expr_node_list, eval_col, eval_row, error_string);
if (!sum)
return NULL;
count = gnumeric_count (tsheet, expr_node_list, eval_col, eval_row, error_string);
if (!count || (count && count->v.v_int == 0)){
if (!count){
value_release (sum);
return NULL;
}
result = value_float (sum->v.v_float / count->v.v_int);
c = value_gets_as_double (count->v);
if (c == 0.0){
*error_string = "Division by zero";
value_release (sum);
return NULL;
}
result = value_float (value_get_as_double (sum->v) / c);
value_release (count);
value_release (sum);
......@@ -995,11 +1004,23 @@ callback_function_sum (Sheet *sheet, Value *value, char **error_string, void *cl
switch (value->type){
case VALUE_INTEGER:
result->v.v_float += value->v.v_int;
if (result->type == VALUE_INTEGER)
result->v.v_int += value->v.v_int;
else
result->v.v_float += value->v.v_int;
break;
case VALUE_FLOAT:
result->v.v_float += value->v.v_float;
if (result->type == VALUE_FLOAT)
result->v.v_float += value->v.v_float;
else {
double v = result->v.v_int;
/* cast to float */
result->type = VALUE_FLOAT;
result->v.v_float = v + value->v.v_float;
}
break;
default:
......@@ -1016,8 +1037,8 @@ gnumeric_sum (void *tsheet, GList *expr_node_list, int eval_col, int eval_row, c
Sheet *sheet = (Sheet *) tsheet;
result = g_new (Value, 1);
result->type = VALUE_FLOAT;
result->v.v_float = 0.0;
result->type = VALUE_INTEGER;
result->v.v_int = 0;
function_iterate_argument_values (sheet, callback_function_sum, result, expr_node_list,
eval_col, eval_row, error_string);
......
......@@ -122,6 +122,8 @@ typedef struct {
Cell *editing_cell;
int editing;
gboolean modified;
/* For walking trough a selection */
struct {
SheetSelection *current;
......
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