Commit ef54b95e authored by Miguel de Icaza's avatar Miguel de Icaza Committed by Arturo Espinosa
Browse files

Changed the formatting of it to be like the rest of Gnumeric.

1998-09-29  Miguel de Icaza  <miguel@nuclecu.unam.mx>

	* src/xml-io.c: Changed the formatting of it to be like the rest
	of Gnumeric.

	* src/fn-math.c, src/fn-date.c: Simplify routines to use
	value_float and value_int.

	* src/expr.c (value_float, value_int): New utility functions to
	create values of type integer and float.

	* src/sheet.c (sheet_set_text): Use the matching engine on entered text

	* src/cell.c (cell_set_text_simple): New function.  Does not queue
	cell computations nor queue any redraws
	(cell_content_changed): New function: Queues recomputations for
	cells that depend on the contents of the argument.
	(cell_set_format_simple): New routine, like cell_set_format but
	does not render the value nor queues a redraw.

	* src/xml-io.c: Use workbook_recalc_all instead of workbook_recalc

	* src/fn-math.c (gnumeric_log10, gnumeric_log, gnumeric_log2):
	Range check fix was wrong.  The valid range does not include
	zero.  Thanks to Morten Welinder for noticing this.
	(gnumeric_cosh): Call cosh, not cos.
	Reordered this file to have the help always before the function
	that defines it.
	(callback_function_or): Bug fix: any non-zero value is considered
	to be TRUE.
	(gnumeric_fact): Use exp (lgamma (n+1)) to compute large
	factorials (this only applies to factorials over 40).

	* src/about.c (dialog_about): Stop using gnome_dialog_set_modal.
parent 94b39045
1998-09-29 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/xml-io.c: Changed the formatting of it to be like the rest
of Gnumeric.
* src/fn-math.c, src/fn-date.c: Simplify routines to use
value_float and value_int.
* src/expr.c (value_float, value_int): New utility functions to
create values of type integer and float.
* src/sheet.c (sheet_set_text): Use the matching engine on entered text
* src/cell.c (cell_set_text_simple): New function. Does not queue
cell computations nor queue any redraws
(cell_content_changed): New function: Queues recomputations for
cells that depend on the contents of the argument.
(cell_set_format_simple): New routine, like cell_set_format but
does not render the value nor queues a redraw.
* src/xml-io.c: Use workbook_recalc_all instead of workbook_recalc
* src/fn-math.c (gnumeric_log10, gnumeric_log, gnumeric_log2):
Range check fix was wrong. The valid range does not include
zero. Thanks to Morten Welinder for noticing this.
(gnumeric_cosh): Call cosh, not cos.
Reordered this file to have the help always before the function
that defines it.
(callback_function_or): Bug fix: any non-zero value is considered
to be TRUE.
(gnumeric_fact): Use exp (lgamma (n+1)) to compute large
factorials (this only applies to factorials over 40).
* src/about.c (dialog_about): Stop using gnome_dialog_set_modal.
1998-09-29 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/number-match.c (format_create_regexp): Small bug fix. I was
......
1998-09-29 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/xml-io.c: Changed the formatting of it to be like the rest
of Gnumeric.
* src/fn-math.c, src/fn-date.c: Simplify routines to use
value_float and value_int.
* src/expr.c (value_float, value_int): New utility functions to
create values of type integer and float.
* src/sheet.c (sheet_set_text): Use the matching engine on entered text
* src/cell.c (cell_set_text_simple): New function. Does not queue
cell computations nor queue any redraws
(cell_content_changed): New function: Queues recomputations for
cells that depend on the contents of the argument.
(cell_set_format_simple): New routine, like cell_set_format but
does not render the value nor queues a redraw.
* src/xml-io.c: Use workbook_recalc_all instead of workbook_recalc
* src/fn-math.c (gnumeric_log10, gnumeric_log, gnumeric_log2):
Range check fix was wrong. The valid range does not include
zero. Thanks to Morten Welinder for noticing this.
(gnumeric_cosh): Call cosh, not cos.
Reordered this file to have the help always before the function
that defines it.
(callback_function_or): Bug fix: any non-zero value is considered
to be TRUE.
(gnumeric_fact): Use exp (lgamma (n+1)) to compute large
factorials (this only applies to factorials over 40).
* src/about.c (dialog_about): Stop using gnome_dialog_set_modal.
1998-09-29 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/number-match.c (format_create_regexp): Small bug fix. I was
......
1998-09-29 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/xml-io.c: Changed the formatting of it to be like the rest
of Gnumeric.
* src/fn-math.c, src/fn-date.c: Simplify routines to use
value_float and value_int.
* src/expr.c (value_float, value_int): New utility functions to
create values of type integer and float.
* src/sheet.c (sheet_set_text): Use the matching engine on entered text
* src/cell.c (cell_set_text_simple): New function. Does not queue
cell computations nor queue any redraws
(cell_content_changed): New function: Queues recomputations for
cells that depend on the contents of the argument.
(cell_set_format_simple): New routine, like cell_set_format but
does not render the value nor queues a redraw.
* src/xml-io.c: Use workbook_recalc_all instead of workbook_recalc
* src/fn-math.c (gnumeric_log10, gnumeric_log, gnumeric_log2):
Range check fix was wrong. The valid range does not include
zero. Thanks to Morten Welinder for noticing this.
(gnumeric_cosh): Call cosh, not cos.
Reordered this file to have the help always before the function
that defines it.
(callback_function_or): Bug fix: any non-zero value is considered
to be TRUE.
(gnumeric_fact): Use exp (lgamma (n+1)) to compute large
factorials (this only applies to factorials over 40).
* src/about.c (dialog_about): Stop using gnome_dialog_set_modal.
1998-09-29 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/number-match.c (format_create_regexp): Small bug fix. I was
......
1998-09-29 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/xml-io.c: Changed the formatting of it to be like the rest
of Gnumeric.
* src/fn-math.c, src/fn-date.c: Simplify routines to use
value_float and value_int.
* src/expr.c (value_float, value_int): New utility functions to
create values of type integer and float.
* src/sheet.c (sheet_set_text): Use the matching engine on entered text
* src/cell.c (cell_set_text_simple): New function. Does not queue
cell computations nor queue any redraws
(cell_content_changed): New function: Queues recomputations for
cells that depend on the contents of the argument.
(cell_set_format_simple): New routine, like cell_set_format but
does not render the value nor queues a redraw.
* src/xml-io.c: Use workbook_recalc_all instead of workbook_recalc
* src/fn-math.c (gnumeric_log10, gnumeric_log, gnumeric_log2):
Range check fix was wrong. The valid range does not include
zero. Thanks to Morten Welinder for noticing this.
(gnumeric_cosh): Call cosh, not cos.
Reordered this file to have the help always before the function
that defines it.
(callback_function_or): Bug fix: any non-zero value is considered
to be TRUE.
(gnumeric_fact): Use exp (lgamma (n+1)) to compute large
factorials (this only applies to factorials over 40).
* src/about.c (dialog_about): Stop using gnome_dialog_set_modal.
1998-09-29 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/number-match.c (format_create_regexp): Small bug fix. I was
......
......@@ -96,6 +96,30 @@ add2numbers (FunctionDefinition *fn_def, Value *argv [], char **error_string)
return NULL;
}
result = value_float (number_a + number_b);
return result;
}
Note that the typechecking is done in the routine itself, it is not
done by the upper layers. If there is an error during the function
processing, *error_string should be set to the error message
describing what went wrong and the NULL value should be returned.
Return values and Strings.
--------------------------
There are a couple of utility functions provided by Gnumeric to create
Values: these are value_float and value_int, they take respectively
a double and an integer as their first parameter.
Other value types have to be created manually (there is no utility
function yet). Sometimes you might want to do something more complex,
so you might want as well create the Value yourself even if the result
is a float or an integer (for performance reasons, reuse reasons, or
the way your procedure is used), you can use this code snippet to
create a Value Float as well:
/*
* the line below is equivalent to:
* result = (Value *) malloc (sizeof (Value));
......@@ -103,15 +127,24 @@ add2numbers (FunctionDefinition *fn_def, Value *argv [], char **error_string)
*/
result = g_new (Value, 1);
result->type = VALUE_FLOAT;
result->v.v_float = number_a + number_b;
result->v.v_float = your_number
return result;
}
Values of type string are created like this:
Value *value_string;
value_string = g_new (Value, 1);
v->v.str = string_get ("String");
Notice that the field "v.str" is of type (String *) not of type char
*. Strings unlike char * are read-only structures, you should under
no circustance modify the value returned by string_get. They are
designed to be shared between various Gnumeric components, so they
keep a reference count.
When you are done with a String, you should call the string_unref
routine on the String.
Note that the typechecking is done in the routine itself, it is not
done by the upper layers. If there is an error during the function
processing, *error_string should be set to the error message
describing what went wrong and the NULL value should be returned.
Functions with a variable number of arguments
---------------------------------------------
......
......@@ -34,7 +34,7 @@ static char *help_date = {
static Value *
gnumeric_date (struct FunctionDefinition *fd, Value *argv [], char **error_string)
{
Value *v = g_new (Value, 1);
Value *v;
int year, month, day;
year = value_get_as_double (argv [0]);
......@@ -50,10 +50,9 @@ gnumeric_date (struct FunctionDefinition *fd, Value *argv [], char **error_strin
}
day = month_length [leap (year)][month] - day;
}
v->type = VALUE_INTEGER;
v->v.v_int =
v = value_int (
calc_days (year, month, day) -
calc_days (1900, 1, 1) + 1;
calc_days (1900, 1, 1) + 1);
return v;
}
......@@ -74,14 +73,13 @@ static char *help_today = {
static Value *
gnumeric_today (FunctionDefinition *fd, Value *argv [], char **error_string)
{
Value *v = g_new (Value, 1);
Value *v;
time_t t = time (NULL);
struct tm *tm = localtime (&t);
v->type = VALUE_INTEGER;
v->v.v_int =
v = value_int (
calc_days (tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday) -
calc_days (1900, 1, 1) + 1;
calc_days (1900, 1, 1) + 1);
return v;
}
......@@ -110,15 +108,14 @@ static char *help_now = {
static Value *
gnumeric_now (FunctionDefinition *fd, Value *argv [], char **error_string)
{
Value *v = g_new (Value, 1);
Value *v;
time_t t = time (NULL);
struct tm *tm = localtime (&t);
v->type = VALUE_FLOAT;
v->v.v_float =
v = value_float (
calc_days (tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday) +
((tm->tm_hour * 3600 + tm->tm_min * 60 + tm->tm_sec)/(double)DAY_SECONDS) -
calc_days (1900, 1, 1) + 1;
calc_days (1900, 1, 1) + 1);
return v;
}
......@@ -138,15 +135,14 @@ static char *help_time = {
static Value *
gnumeric_time (FunctionDefinition *fd, Value *argv [], char **error_string)
{
Value *v = g_new (Value, 1);
Value *v;
float_t hours, minutes, seconds;
hours = value_get_as_double (argv [0]);
minutes = value_get_as_double (argv [1]);
seconds = value_get_as_double (argv [2]);
v->type = VALUE_FLOAT;
v->v.v_float = (hours * 3600 + minutes * 60 + seconds) / DAY_SECONDS;
v = value_float ((hours * 3600 + minutes * 60 + seconds) / DAY_SECONDS);
return v;
}
......
This diff is collapsed.
......@@ -35,7 +35,7 @@ dialog_about (void)
_("The GNOME spreadsheet.\n"
"http://www.gnome.org/gnumeric"),
NULL);
gnome_dialog_set_modal (GNOME_DIALOG (about));
gtk_window_set_modal (GTK_WINDOW (about), TRUE);
gnome_dialog_set_close (GNOME_DIALOG (about), TRUE);
gtk_widget_show (about);
}
......
......@@ -236,16 +236,25 @@ cell_render_value (Cell *cell)
g_free (str);
}
/*
* Sets the text for a cell:
*
* This is kind of an internal function and should be only called by
* routines that know what they are doing. These are the important
* differences from cell_set_text:
*
* - It does not queue redraws (so you have to queue the redraw yourself
* or queue a full redraw).
*
* - It does not queue any recomputations. You have to queue the recompute
* yourself.
*/
void
cell_set_text (Cell *cell, char *text)
cell_set_text_simple (Cell *cell, char *text)
{
GList *deps;
g_return_if_fail (cell != NULL);
g_return_if_fail (text != NULL);
cell_queue_redraw (cell);
/* The value entered */
if (cell->entered_text)
string_unref (cell->entered_text);
......@@ -262,7 +271,7 @@ cell_set_text (Cell *cell, char *text)
expr_tree_unref (cell->parsed_node);
cell->parsed_node = NULL;
}
if (text [0] == '='){
cell_set_formula (cell, text);
} else {
......@@ -313,12 +322,48 @@ cell_set_text (Cell *cell, char *text)
cell_render_value (cell);
}
}
/*
* cell_content_changed:
*
* Call this routine if you modify the contents of a cell
* to trigger a recompute on any dependencies
*/
void
cell_content_changed (Cell *cell)
{
GList *deps;
g_return_if_fail (cell != NULL);
/* Queue all of the dependencies for this cell */
deps = cell_get_dependencies (cell->sheet,
cell->col->pos,
cell->row->pos);
if (deps)
cell_queue_recalc_list (deps);
}
/*
* cell_set_text
*
* Changes the content of a cell
*/
void
cell_set_text (Cell *cell, char *text)
{
GList *deps;
g_return_if_fail (cell != NULL);
g_return_if_fail (text != NULL);
cell_queue_redraw (cell);
cell_set_text_simple (cell, text);
cell_content_changed (cell);
cell_queue_redraw (cell);
}
......@@ -420,11 +465,34 @@ cell_queue_redraw (Cell *cell)
cell->col->pos, cell->row->pos);
}
/*
* cell_set_format_simple:
*
* This routine is similar to cell_set_format, but it does not queue
* any redraws, nor expects the cell to have a value.
*
* Make sure you queue a draw in the future for this cell.
*/
void
cell_set_format_simple (Cell *cell, char *format)
{
g_return_if_fail (cell != NULL);
g_return_if_fail (format != NULL);
if (strcmp (format, cell->style->format->format) == 0)
return;
/* Change the format */
style_format_unref (cell->style->format);
cell->style->format = style_format_new (format);
}
void
cell_set_format (Cell *cell, char *format)
{
g_return_if_fail (cell != NULL);
g_return_if_fail (format != NULL);
g_return_if_fail (cell->value);
if (strcmp (format, cell->style->format->format) == 0)
return;
......
......@@ -76,8 +76,11 @@ typedef struct {
char *value_format (Value *value, StyleFormat *format, char **color);
void cell_set_text (Cell *cell, char *text);
void cell_set_text_simple (Cell *cell, char *text);
void cell_content_changed (Cell *cell);
void cell_set_formula (Cell *cell, char *text);
void cell_set_format (Cell *cell, char *format);
void cell_set_format_simple (Cell *cell, char *format);
void cell_set_font (Cell *cell, char *font_name);
void cell_set_style (Cell *cell, Style *reference_style);
void cell_set_font_from_style (Cell *cell, StyleFont *style_font);
......
......@@ -35,7 +35,7 @@ dialog_about (void)
_("The GNOME spreadsheet.\n"
"http://www.gnome.org/gnumeric"),
NULL);
gnome_dialog_set_modal (GNOME_DIALOG (about));
gtk_window_set_modal (GTK_WINDOW (about), TRUE);
gnome_dialog_set_close (GNOME_DIALOG (about), TRUE);
gtk_widget_show (about);
}
......
......@@ -276,6 +276,28 @@ value_duplicate (Value *value)
return new_value;
}
Value *
value_float (float_t f)
{
Value *v = g_new (Value, 1);
v->type = VALUE_FLOAT;
v->v.v_float = f;
return v;
}
Value *
value_int (int i)
{
Value *v = g_new (Value, 1);
v->type = VALUE_INTEGER;
v->v.v_int = i;
return v;
}
/*
* Casts a value to float if it is integer, and returns
* a new Value * if required
......@@ -289,7 +311,7 @@ value_cast_to_float (Value *v)
if (v->type == VALUE_FLOAT)
return v;
newv = g_new (Value, 1);
newv->type = VALUE_FLOAT;
mpf_set_z (newv->v.v_float, v->v.v_int);
......
......@@ -160,6 +160,9 @@ void value_dump (Value *value);
char *value_string (Value *value);
Value *value_duplicate (Value *value);
Value *value_float (float_t f);
Value *value_int (int i);
int yyparse (void);
/* Setup of the symbol table */
......
......@@ -34,7 +34,7 @@ static char *help_date = {
static Value *
gnumeric_date (struct FunctionDefinition *fd, Value *argv [], char **error_string)
{
Value *v = g_new (Value, 1);
Value *v;
int year, month, day;
year = value_get_as_double (argv [0]);
......@@ -50,10 +50,9 @@ gnumeric_date (struct FunctionDefinition *fd, Value *argv [], char **error_strin
}
day = month_length [leap (year)][month] - day;
}
v->type = VALUE_INTEGER;
v->v.v_int =
v = value_int (
calc_days (year, month, day) -
calc_days (1900, 1, 1) + 1;
calc_days (1900, 1, 1) + 1);
return v;
}
......@@ -74,14 +73,13 @@ static char *help_today = {
static Value *
gnumeric_today (FunctionDefinition *fd, Value *argv [], char **error_string)
{
Value *v = g_new (Value, 1);
Value *v;
time_t t = time (NULL);
struct tm *tm = localtime (&t);
v->type = VALUE_INTEGER;
v->v.v_int =
v = value_int (
calc_days (tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday) -
calc_days (1900, 1, 1) + 1;
calc_days (1900, 1, 1) + 1);
return v;
}
......@@ -110,15 +108,14 @@ static char *help_now = {
static Value *
gnumeric_now (FunctionDefinition *fd, Value *argv [], char **error_string)
{
Value *v = g_new (Value, 1);
Value *v;
time_t t = time (NULL);
struct tm *tm = localtime (&t);
v->type = VALUE_FLOAT;
v->v.v_float =
v = value_float (
calc_days (tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday) +
((tm->tm_hour * 3600 + tm->tm_min * 60 + tm->tm_sec)/(double)DAY_SECONDS) -
calc_days (1900, 1, 1) + 1;
calc_days (1900, 1, 1) + 1);
return v;
}
......@@ -138,15 +135,14 @@ static char *help_time = {
static Value *
gnumeric_time (FunctionDefinition *fd, Value *argv [], char **error_string)
{
Value *v = g_new (Value, 1);
Value *v;
float_t hours, minutes, seconds;
hours = value_get_as_double (argv [0]);
minutes = value_get_as_double (argv [1]);
seconds = value_get_as_double (argv [2]);
v->type = VALUE_FLOAT;
v->v.v_float = (hours * 3600 + minutes * 60 + seconds) / DAY_SECONDS;
v = value_float ((hours * 3600 + minutes * 60 + seconds) / DAY_SECONDS);
return v;
}
......
This diff is collapsed.
......@@ -34,7 +34,7 @@ static char *help_date = {
static Value *
gnumeric_date (struct FunctionDefinition *fd, Value *argv [], char **error_string)
{
Value *v = g_new (Value, 1);
Value *v;
int year, month, day;
year = value_get_as_double (argv [0]);
......@@ -50,10 +50,9 @@ gnumeric_date (struct FunctionDefinition *fd, Value *argv [], char **error_strin
}
day = month_length [leap (year)][month] - day;
}
v->type = VALUE_INTEGER;
v->v.v_int =
v = value_int (
calc_days (year, month, day) -
calc_days (1900, 1, 1) + 1;
calc_days (1900, 1, 1) + 1);
return v;
}
......@@ -74,14 +73,13 @@ static char *help_today = {
static Value *
gnumeric_today (FunctionDefinition *fd, Value *argv [], char **error_string)
{
Value *v = g_new (Value, 1);
Value *v;
time_t t = time (NULL);
struct tm *tm = localtime (&t);
v->type = VALUE_INTEGER;
v->v.v_int =
v = value_int (
calc_days (tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday) -
calc_days (1900, 1, 1) + 1;
calc_days (1900, 1, 1) + 1);
return v;
}
......@@ -110,15 +108,14 @@ static char *help_now = {
static Value *
gnumeric_now (FunctionDefinition *fd, Value *argv [], char **error_string)
{
Value *v = g_new (Value, 1);
Value *v;
time_t t = time (NULL);