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

When decoding a tree, include the argument separator. Also, loop properly

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

	* src/expr.c (do_expr_decode_tree): When decoding a tree, include
	the argument separator.  Also, loop properly trough the arguments
	being decoded.

	(function_call_with_values, function_def_call_with_values): New
	functions: these ones are for the plugins so that a plugin can
	invoke other functions in Gnumeric.

	* src/fn-date.c (gnumeric_now): The serial number returned by
	NOW() should be relative to 1900/1/1, not year zero.

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

	* src/expr.c (eval_expr): Fix the way we computed expressions.

	* src/eval.c (cell_eval): Maintain a CELL_ERROR flag to know if
	the value is NULL due to an error or to the cell not being
	evaluated.

	* src/expr.c (funcion_call_with_values): Add a routine to allow
	plugins to call other functions defined in Gnumeric.

	* src/style.c: Handle the pattern property of the styles.

	* src/style.h: Pattern style is now just a 4 bit quantity, instead
	of a RefCounted structure.

	* src/plugin.c: Include gnumeric-util.h
parent 11c14828
1998-09-21 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/expr.c (do_expr_decode_tree): When decoding a tree, include
the argument separator. Also, loop properly trough the arguments
being decoded.
(function_call_with_values, function_def_call_with_values): New
functions: these ones are for the plugins so that a plugin can
invoke other functions in Gnumeric.
* src/fn-date.c (gnumeric_now): The serial number returned by
NOW() should be relative to 1900/1/1, not year zero.
1998-09-20 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/expr.c (eval_expr): Fix the way we computed expressions.
* src/eval.c (cell_eval): Maintain a CELL_ERROR flag to know if
the value is NULL due to an error or to the cell not being
evaluated.
* src/expr.c (funcion_call_with_values): Add a routine to allow
plugins to call other functions defined in Gnumeric.
* src/style.c: Handle the pattern property of the styles.
* src/style.h: Pattern style is now just a 4 bit quantity, instead
of a RefCounted structure.
* src/plugin.c: Include gnumeric-util.h
1998-09-19 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/item-cursor.c (item_cursor_do_drop): Use button-1 to select
......
1998-09-21 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/expr.c (do_expr_decode_tree): When decoding a tree, include
the argument separator. Also, loop properly trough the arguments
being decoded.
(function_call_with_values, function_def_call_with_values): New
functions: these ones are for the plugins so that a plugin can
invoke other functions in Gnumeric.
* src/fn-date.c (gnumeric_now): The serial number returned by
NOW() should be relative to 1900/1/1, not year zero.
1998-09-20 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/expr.c (eval_expr): Fix the way we computed expressions.
* src/eval.c (cell_eval): Maintain a CELL_ERROR flag to know if
the value is NULL due to an error or to the cell not being
evaluated.
* src/expr.c (funcion_call_with_values): Add a routine to allow
plugins to call other functions defined in Gnumeric.
* src/style.c: Handle the pattern property of the styles.
* src/style.h: Pattern style is now just a 4 bit quantity, instead
of a RefCounted structure.
* src/plugin.c: Include gnumeric-util.h
1998-09-19 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/item-cursor.c (item_cursor_do_drop): Use button-1 to select
......
1998-09-21 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/expr.c (do_expr_decode_tree): When decoding a tree, include
the argument separator. Also, loop properly trough the arguments
being decoded.
(function_call_with_values, function_def_call_with_values): New
functions: these ones are for the plugins so that a plugin can
invoke other functions in Gnumeric.
* src/fn-date.c (gnumeric_now): The serial number returned by
NOW() should be relative to 1900/1/1, not year zero.
1998-09-20 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/expr.c (eval_expr): Fix the way we computed expressions.
* src/eval.c (cell_eval): Maintain a CELL_ERROR flag to know if
the value is NULL due to an error or to the cell not being
evaluated.
* src/expr.c (funcion_call_with_values): Add a routine to allow
plugins to call other functions defined in Gnumeric.
* src/style.c: Handle the pattern property of the styles.
* src/style.h: Pattern style is now just a 4 bit quantity, instead
of a RefCounted structure.
* src/plugin.c: Include gnumeric-util.h
1998-09-19 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/item-cursor.c (item_cursor_do_drop): Use button-1 to select
......
1998-09-21 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/expr.c (do_expr_decode_tree): When decoding a tree, include
the argument separator. Also, loop properly trough the arguments
being decoded.
(function_call_with_values, function_def_call_with_values): New
functions: these ones are for the plugins so that a plugin can
invoke other functions in Gnumeric.
* src/fn-date.c (gnumeric_now): The serial number returned by
NOW() should be relative to 1900/1/1, not year zero.
1998-09-20 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/expr.c (eval_expr): Fix the way we computed expressions.
* src/eval.c (cell_eval): Maintain a CELL_ERROR flag to know if
the value is NULL due to an error or to the cell not being
evaluated.
* src/expr.c (funcion_call_with_values): Add a routine to allow
plugins to call other functions defined in Gnumeric.
* src/style.c: Handle the pattern property of the styles.
* src/style.h: Pattern style is now just a 4 bit quantity, instead
of a RefCounted structure.
* src/plugin.c: Include gnumeric-util.h
1998-09-19 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/item-cursor.c (item_cursor_do_drop): Use button-1 to select
......
......@@ -89,4 +89,8 @@ documentation for these:
- If you drag a selection with button 3 instead of button one
there is no default action, rather, a menu pops up with
a list of possibel options on actions to perform.
\ No newline at end of file
a list of possibel options on actions to perform.
- Gnumeric distinguishes regular text from formulas by preceding
formulas with an equal sign. So to enter an expression you have
to enter for example: =1+2.
\ No newline at end of file
......@@ -2,6 +2,14 @@
GNOME Spread Sheet task list
* BUGS
A1: numero
B1: =EXP(A1) -> loop
=YEAR(NOW())
.33 -> scientific format anade un leading - -> segv
* Autofill
Finish implementation
......
......@@ -113,7 +113,8 @@ gnumeric_now (FunctionDefinition *fd, Value *argv [], char **error_string)
v->type = VALUE_FLOAT;
v->v.v_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)/DAY_SECONDS);
((tm->tm_hour * 3600 + tm->tm_min * 60 + tm->tm_sec)/DAY_SECONDS) -
calc_days (1900, 1, 1);
return v;
}
......
......@@ -835,16 +835,6 @@ cell_draw (Cell *cell, void *sv, GdkGC *gc, GdkDrawable *drawable, int x1, int y
halign = cell_get_horizontal_align (cell);
text = CELL_TEXT_GET (cell);
if (cell->style->valid_flags & STYLE_BACK_COLOR)
gdk_gc_set_background (gc, &cell->style->back_color->color);
if (cell->render_color)
gdk_gc_set_foreground (gc, &cell->render_color->color);
else {
if (cell->style->valid_flags & STYLE_FORE_COLOR)
gdk_gc_set_foreground (gc, &cell->style->fore_color->color);
}
/* if a number overflows, do special drawing */
if (width < cell->width && cell_is_number (cell)){
draw_overflow (drawable, gc, font, x1 + cell->col->margin_a, y1, text_base,
......@@ -870,7 +860,6 @@ cell_draw (Cell *cell, void *sv, GdkGC *gc, GdkDrawable *drawable, int x1, int y
rect.height = cell->height;
rect.width = cell->width;
gdk_gc_set_clip_rectangle (gc, &rect);
printf ("Cliping to: %d %d %d %d\n", x1, y1, cell->height, cell->width);
switch (style->valign){
case VALIGN_TOP:
......
......@@ -21,6 +21,7 @@ typedef struct {
#define COL_INTERNAL_WIDTH(col) ((col)->pixels - ((col)->margin_b + (col)->margin_a))
#define ROW_INTERNAL_HEIGHT(row) ((row)->pixels - ((row)->margin_b + (row)->margin_a))
#define CELL_ERROR 1
typedef struct {
void *sheet;
......
......@@ -17,7 +17,7 @@ static GHashTable *dependency_hash;
void
cell_eval (Cell *cell)
{
char *error_msg;
char *error_msg = NULL;
Value *v;
g_return_if_fail (cell != NULL);
......@@ -33,9 +33,11 @@ cell_eval (Cell *cell)
if (v == NULL){
cell_set_rendered_text (cell, error_msg);
cell->value = NULL;
cell->flags |= CELL_ERROR;
} else {
cell->value = v;
cell_render_value (cell);
cell->flags &= ~CELL_ERROR;
}
cell_calc_dimensions (cell);
......
......@@ -17,7 +17,7 @@ static GHashTable *dependency_hash;
void
cell_eval (Cell *cell)
{
char *error_msg;
char *error_msg = NULL;
Value *v;
g_return_if_fail (cell != NULL);
......@@ -33,9 +33,11 @@ cell_eval (Cell *cell)
if (v == NULL){
cell_set_rendered_text (cell, error_msg);
cell->value = NULL;
cell->flags |= CELL_ERROR;
} else {
cell->value = v;
cell_render_value (cell);
cell->flags &= ~CELL_ERROR;
}
cell_calc_dimensions (cell);
......
......@@ -6,6 +6,7 @@
#include "expr.h"
#include "eval.h"
#include "format.h"
#include "func.h"
char *parser_expr;
ParseErr parser_error;
......@@ -419,6 +420,77 @@ eval_funcall (Sheet *sheet, ExprTree *tree, int eval_col, int eval_row, char **e
return v;
}
Value *
function_def_call_with_values (Sheet *sheet, FunctionDefinition *fd, int argc,
Value *values [], char **error_string)
{
Value *retval;
if (fd->expr_fn){
/*
* If function deals with ExprNodes, create some
* temporary ExprNodes with constants.
*/
ExprTree *tree = NULL;
GList *l = NULL;
int i;
if (argc){
tree = g_new (ExprTree, argc);
for (i = 0; i < argc; i++){
tree [i].oper = OP_CONSTANT;
tree [i].ref_count = 1;
tree [i].u.constant = values [i];
l = g_list_append (l, &(tree[i]));
}
}
retval = fd->expr_fn (sheet, l, 0, 0, error_string);
if (tree){
g_free (tree);
g_list_free (l);
}
} else
retval = fd->fn (fd, values, error_string);
return retval;
}
/*
* Use this to invoke a register function: the only drawback is that
* you have to compute/expand all of the values to use this
*/
Value *
function_call_with_values (Sheet *sheet, char *name, int argc, Value *values[], char **error_string)
{
FunctionDefinition *fd;
Value *retval;
Symbol *sym;
g_return_val_if_fail (sheet != NULL, NULL);
g_return_val_if_fail (IS_SHEET (sheet), NULL);
g_return_val_if_fail (name != NULL, NULL);
sym = symbol_lookup (name);
if (sym->type != SYMBOL_FUNCTION){
*error_string = "Calling non-function";
return NULL;
}
fd = sym->data;
symbol_ref (sym);
retval = function_def_call_with_values (sheet, fd, argc, values, error_string);
symbol_unref (sym);
return retval;
}
typedef enum {
IS_EQUAL,
IS_LESS,
......@@ -740,11 +812,13 @@ eval_expr (void *asheet, ExprTree *tree, int eval_col, int eval_row, char **erro
cell = sheet_cell_get (sheet, col, row);
if (cell){
if (cell->parsed_node && cell->generation != sheet->workbook->generation){
if (cell->generation != sheet->workbook->generation){
cell->generation = sheet->workbook->generation;
cell_eval (cell);
}
if (cell->parsed_node)
cell_eval (cell);
}
if (cell->value)
return eval_cell_value (sheet, cell->value);
}
......@@ -892,20 +966,23 @@ do_expr_decode_tree (ExprTree *tree, int col, int row, Operation parent_op)
args = g_malloc (sizeof (char *) * argc);
i = 0;
for (l = arg_list; l; l = l->next){
for (l = arg_list; l; l = l->next, i++){
ExprTree *t = l->data;
args [i] = do_expr_decode_tree (t, col, row, OP_CONSTANT);
len += strlen (args [i]) + 1;
}
len++;
sum = g_malloc (len + 1);
sum = g_malloc (len + 2);
i = 0;
sum [0] = 0;
for (l = arg_list; l; l = l->next)
for (l = arg_list; l; l = l->next, i++){
strcat (sum, args [i]);
if (l->next)
strcat (sum, ",");
}
res = g_copy_strings (
fd->name, "(", sum, ")", NULL);
......
......@@ -70,9 +70,6 @@ typedef struct {
struct ExprTree {
Operation oper;
/*
* The reference count is only used by the toplevel tree.
*/
int ref_count;
union {
Value *constant;
......
......@@ -113,7 +113,8 @@ gnumeric_now (FunctionDefinition *fd, Value *argv [], char **error_string)
v->type = VALUE_FLOAT;
v->v.v_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)/DAY_SECONDS);
((tm->tm_hour * 3600 + tm->tm_min * 60 + tm->tm_sec)/DAY_SECONDS) -
calc_days (1900, 1, 1);
return v;
}
......
......@@ -38,6 +38,22 @@ function_iterate_argument_values (Sheet *sheet,
char **error_string);
/*
* function_call_with_values
*
*/
Value *function_call_with_values (Sheet *sheet,
char *name,
int argc,
Value *values [],
char **error_string);
Value *function_def_call_with_values (Sheet *sheet,
FunctionDefinition *fd,
int argc,
Value *values [],
char **error_string);
void install_symbols (FunctionDefinition *functions);
#endif /* GNUMERIC_FUNC_H */
......
......@@ -113,7 +113,8 @@ gnumeric_now (FunctionDefinition *fd, Value *argv [], char **error_string)
v->type = VALUE_FLOAT;
v->v.v_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)/DAY_SECONDS);
((tm->tm_hour * 3600 + tm->tm_min * 60 + tm->tm_sec)/DAY_SECONDS) -
calc_days (1900, 1, 1);
return v;
}
......
......@@ -191,16 +191,34 @@ item_grid_draw_cell (GdkDrawable *drawable, ItemGrid *item_grid, Cell *cell, int
GdkGC *gc = item_grid->gc;
int count;
#if 0
/* Debugging code for testing the stipples */
gdk_gc_set_stipple (gc, GNUMERIC_SHEET (canvas)->patterns [col % 8]);
gdk_gc_set_foreground (gc, &gs_black);
gdk_gc_set_background (gc, &gs_white);
gdk_gc_set_fill (gc, GDK_STIPPLED);
#endif
/* setup foreground */
gdk_gc_set_foreground (gc, &item_grid->default_color);
if (cell->render_color)
gdk_gc_set_foreground (gc, &cell->render_color->color);
else {
if (cell->style->valid_flags & STYLE_FORE_COLOR)
gdk_gc_set_foreground (gc, &cell->style->fore_color->color);
}
if (cell->style->valid_flags & STYLE_BACK_COLOR)
gdk_gc_set_background (gc, &cell->style->back_color->color);
if ((cell->style->valid_flags & STYLE_PATTERN) && cell->style->pattern){
GnomeCanvasItem *item = GNOME_CANVAS_ITEM (item_grid);
int p = cell->style->pattern - 1;
gdk_gc_set_stipple (gc, GNUMERIC_SHEET (item->canvas)->patterns [p]);
gdk_gc_set_fill (gc, GDK_STIPPLED);
gdk_draw_rectangle (drawable, gc, TRUE,
x1, y1,
cell->col->pixels,
cell->row->pixels);
} else {
gdk_gc_set_fill (gc, GDK_SOLID);
gdk_gc_set_stipple (gc, NULL);
}
count = cell_draw (cell, item_grid->sheet_view, gc, drawable, x1, y1);
return count;
}
......
......@@ -9,28 +9,28 @@ static char * cursor_cross_xpm[] = {
" ",
" ",
" ",
" ......... ",
" .+++++++.. ",
" .+++++++.. ",
" .+++++++.. ",
" .+++++++.. ",
" .+++++++.. ",
" .......+++++++........ ",
" .+++++++++++++++++++.. ",
" .+++++++++++++++++++.. ",
" .+++++++++++++++++++.. ",
" .+++++++++++++++++++.. ",
" .+++++++++++++++++++.. ",
" .+++++++++++++++++++.. ",
" .+++++++++++++++++++.. ",
" .......+++++++........ ",
" ......+++++++........ ",
" .+++++++.. ",
" .+++++++.. ",
" .+++++++.. ",
" .+++++++.. ",
" .......... ",
" ......... ",
" ",
" ",
" ....... ",
" .+++++.. ",
" .+++++.. ",
" .+++++.. ",
" .+++++.. ",
" ......+++++...... ",
" .+++++++++++++++.. ",
" .+++++++++++++++.. ",
" .+++++++++++++++.. ",
" .+++++++++++++++.. ",
" .+++++++++++++++.. ",
" ......+++++....... ",
" .+++++....... ",
" .+++++.. ",
" .+++++.. ",
" .+++++.. ",
" ........ ",
" ....... ",
" ",
" ",
" ",
" ",
" ",
......
......@@ -12,6 +12,7 @@
#include <gnome.h>
#include <string.h>
#include "gnumeric.h"
#include "gnumeric-util.h"
#include "plugin.h"
GList *plugin_list = NULL;
......
......@@ -238,7 +238,7 @@ style_new (void)
style->halign = HALIGN_GENERAL;
style->valign = VALIGN_CENTER;
style->orientation = ORIENT_HORIZ;
return style;
}
......@@ -275,7 +275,7 @@ style_destroy (Style *style)
if (style->valid_flags & STYLE_BACK_COLOR)
if (style->back_color)
style_color_unref (style->back_color);
g_free (style);
}
......@@ -457,4 +457,10 @@ style_merge_to (Style *target, Style *source)
if (target->back_color)
style_color_ref (target->back_color);
}
if (!(target->valid_flags & STYLE_PATTERN))
if (source->valid_flags & STYLE_PATTERN){
target->valid_flags |= STYLE_PATTERN;
target->pattern = source->pattern;
}
}
......@@ -46,11 +46,6 @@ typedef struct {
GdkColor bottom_color;
} StyleBorder;
typedef struct {
int ref_count;
int pattern;
} StyleShade;
typedef struct {
int ref_count;
GdkColor color;
......@@ -81,28 +76,29 @@ typedef enum {
ORIENT_VERT_VERT_TEXT2 = 8
} StyleOrientation;
#define STYLE_FORMAT 1
#define STYLE_FONT 2
#define STYLE_BORDER 4
#define STYLE_SHADING 8
#define STYLE_ALIGN 16
#define STYLE_FORE_COLOR 32
#define STYLE_BACK_COLOR 64
#define STYLE_FORMAT 1
#define STYLE_FONT 2
#define STYLE_BORDER 4
#define STYLE_PATTERN 8
#define STYLE_ALIGN 16
#define STYLE_FORE_COLOR 32
#define STYLE_BACK_COLOR 64
#define STYLE_MAXIMUM 128
/* Define all of the styles we actually know about */
#define STYLE_ALL (STYLE_FORMAT | STYLE_FONT | STYLE_BORDER | STYLE_ALIGN | \
STYLE_FORE_COLOR | STYLE_BACK_COLOR)
STYLE_PATTERN | STYLE_FORE_COLOR | STYLE_BACK_COLOR)
typedef struct {
StyleFormat *format;
StyleFont *font;
StyleBorder *border;
StyleShade *shading;
StyleColor *fore_color;
StyleColor *back_color;
unsigned int halign:6;
unsigned int pattern:4;
unsigned int valign:4;
unsigned int halign:6;
unsigned int orientation:4;
unsigned int fit_in_cell:1;
......
......@@ -839,8 +839,8 @@ static xmlNodePtr writeXmlStyle(parseXmlContextPtr ctxt, Style *style) {
if ((style->halign == 0) && (style->valign == 0) &&
(style->orientation ==0) && (style->format == NULL) &&
(style->font == NULL) && (style->border == NULL) &&
(style->shading == NULL)) return(NULL);
(style->font == NULL) && (style->border == NULL))
return(NULL);
cur = xmlNewNode(ctxt->ns, "Style", NULL);
xmlSetIntValue(cur, "HAlign", style->halign);
......@@ -869,8 +869,8 @@ static xmlNodePtr writeXmlStyle(parseXmlContextPtr ctxt, Style *style) {
child = writeXmlStyleBorder(ctxt, style->border);
if (child) xmlAddChild(cur, child);
}
if (style->shading != NULL) {
sprintf(str, "%d", style->shading->pattern);
if (style->valid_flags & STYLE_PATTERN != NULL) {
sprintf(str, "%d", style->pattern);
xmlNewChild(cur, ctxt->ns, "Shade", str);
}
return(cur);
......
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