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

stub so that sheets with graphs don't crash. (gnm_graph_update_bounds) :

2002-09-11  Jody Goldberg <jody@gnome.org>

	* src/gnumeric-graph.c (gnm_graph_new_view) : stub so that sheets with
	  graphs don't crash.
	(gnm_graph_update_bounds) : ditto.

2002-09-11  Jody Goldberg <jody@gnome.org>

	* src/expr.c (gnm_expr_eval) : move support for implicit intersection
	  here.

	* src/func.c (function_call_with_list) : merge the marshalling into
	  here in preparation for supporting implicit iteration.  Fix handling
	  of optional arguments.

2002-09-11  Jody Goldberg <jody@gnome.org>

	Patch from Jiri Jirat <Jiri.Jirat@systinet.com>
	* gnumeric.xsd  : fix schema errors
parent 35889f4c
2002-09-11 Jody Goldberg <jody@gnome.org>
* src/gnumeric-graph.c (gnm_graph_new_view) : stub so that sheets with
graphs don't crash.
(gnm_graph_update_bounds) : ditto.
2002-09-11 Jody Goldberg <jody@gnome.org>
* src/expr.c (gnm_expr_eval) : move support for implicit intersection
here.
* src/func.c (function_call_with_list) : merge the marshalling into
here in preparation for supporting implicit iteration. Fix handling
of optional arguments.
2002-09-11 Jody Goldberg <jody@gnome.org>
Patch from Jiri Jirat <Jiri.Jirat@systinet.com>
* gnumeric.xsd : fix schema errors
2002-09-11 Morten Welinder <terra@diku.dk>
* src/plugin-service.c (plugin_service_ui_activate): Plug leak.
......
......@@ -12,6 +12,8 @@ Jody:
* Fix handling of files named .xml.gz
* Improvements for ExprEntry
* Make autocorrect unicode safe, and port dialog to treeview
* Fix 'address' so that we pass all of the tests
* Fix handling of optional scalar arguments.
Morten:
* Leak plugging.
......
2002-09-11 Jody Goldberg <jody@gnome.org>
* src/gnumeric-graph.c (gnm_graph_new_view) : stub so that sheets with
graphs don't crash.
(gnm_graph_update_bounds) : ditto.
2002-09-11 Jody Goldberg <jody@gnome.org>
* src/expr.c (gnm_expr_eval) : move support for implicit intersection
here.
* src/func.c (function_call_with_list) : merge the marshalling into
here in preparation for supporting implicit iteration. Fix handling
of optional arguments.
2002-09-11 Jody Goldberg <jody@gnome.org>
Patch from Jiri Jirat <Jiri.Jirat@systinet.com>
* gnumeric.xsd : fix schema errors
2002-09-11 Morten Welinder <terra@diku.dk>
* src/plugin-service.c (plugin_service_ui_activate): Plug leak.
......
2002-09-11 Jody Goldberg <jody@gnome.org>
* src/gnumeric-graph.c (gnm_graph_new_view) : stub so that sheets with
graphs don't crash.
(gnm_graph_update_bounds) : ditto.
2002-09-11 Jody Goldberg <jody@gnome.org>
* src/expr.c (gnm_expr_eval) : move support for implicit intersection
here.
* src/func.c (function_call_with_list) : merge the marshalling into
here in preparation for supporting implicit iteration. Fix handling
of optional arguments.
2002-09-11 Jody Goldberg <jody@gnome.org>
Patch from Jiri Jirat <Jiri.Jirat@systinet.com>
* gnumeric.xsd : fix schema errors
2002-09-11 Morten Welinder <terra@diku.dk>
* src/plugin-service.c (plugin_service_ui_activate): Plug leak.
......
......@@ -248,14 +248,14 @@ Function Tokens
There are several function tokens to cover most situations.
f : A floating point (double) value.
f : A floating point (gnm_float) value.
s : A string (char*)
b : A boolean
r : A Range eg. A1:A5 - See 'A'
a : An Array eg. {1,2,3;4,5,6} ( a 3x2 array ) - See 'A'
A : Either an Array or a Range: Use the
value_area set of functions to simplify the code.
see expr.h.
see expr.h. The content of the regions are guaranteed to have been
evaluated.
S : Scalar, anything OTHER than an array or range
? : Any type, the type must be checked from value->type.
| : This designates that the arguments in the token string
......
......@@ -676,7 +676,7 @@
<xsd:complexType name="Cells">
<xsd:sequence>
<xsd:element name="Cell" type="xsd:string" minOccurs="0" maxOccurs="unbounded">
<xsd:element name="Cell" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<!-- expressions are stored as entered, with a leading '='.
Once a shared expression has been defined, subsequent
......@@ -684,8 +684,10 @@
use the "ExprID" attribute to indicate which shared
expression is used, and no Content element is included
-->
<xsd:sequence>
<xsd:element name="Content" type="xsd:string" minOccurs="0" maxOccurs="1"/>
</xsd:sequence>
<!-- Col and Row are sufficient for a cell that is an element of
an array of cells as long as it's not the top left cell
-->
......@@ -722,7 +724,7 @@
<xsd:complexType name="MergedRegions">
<xsd:sequence>
<xsd:element name="Merge" type="xsd:string" minOccurs="0" maxOccurs="unbounded">
<xsd:element name="Merge" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
......@@ -758,11 +760,15 @@
</xsd:simpleType>
<xsd:complexType name="SheetLayout">
<xsd:attribute name="TopLeft" type="xsd:string" use="required"/>
<xsd:element name="FreezePanes" use="optional">
<xsd:sequence>
<xsd:element name="FreezePanes" minOccurs="0" maxOccurs="1">
<xsd:complexType>
<xsd:attribute name="FrozenTopLeft" type="xsd:string" use="required"/>
<xsd:attribute name="UnfrozenTopLeft" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="TopLeft" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:schema>
......@@ -1113,9 +1113,21 @@ Value *
gnm_expr_eval (GnmExpr const *expr, EvalPos const *pos,
GnmExprEvalFlags flags)
{
Value * res = expr_eval_real (expr, pos, flags);
Value *res = expr_eval_real (expr, pos, flags);
if (res == NULL)
if (res != NULL) {
if (!(flags & GNM_EXPR_EVAL_PERMIT_NON_SCALAR)) {
if (res->type == VALUE_CELLRANGE) {
res = value_intersection (res, pos);
if (res == NULL)
return value_new_error (pos, gnumeric_err_VALUE);
} else if (res->type == VALUE_ARRAY) {
res = gnm_expr_array_intersection (res);
if (res == NULL)
return value_new_error (pos, gnumeric_err_VALUE);
}
}
} else
return (flags & GNM_EXPR_EVAL_PERMIT_EMPTY)
? NULL : value_new_int (0);
......
......@@ -108,7 +108,10 @@ function_dump_defs (char const *filename)
for (i = 0; i < ordered->len; i++) {
FunctionDefinition const *fd = g_ptr_array_index (ordered, i);
fprintf (output_file, "%s\n\n", _( *(fd->help) ) );
if (fd->fn_type == FUNCTION_ARGS)
fprintf (output_file, "%s : %s\n",
fd->name,
fd->fn.args.arg_types);
}
g_ptr_array_free (ordered,TRUE);
......@@ -249,8 +252,6 @@ extract_arg_types (FunctionDefinition *def)
def->fn.args.arg_types[i] = 0;
}
static Value *
error_function_no_full_info (FunctionEvalInfo *ei, GnmExprList *expr_node_list)
{
......@@ -645,7 +646,7 @@ function_def_get_arg_type (FunctionDefinition const *fn_def,
**/
char const *
function_def_get_arg_type_string (FunctionDefinition const *fn_def,
int arg_idx)
int arg_idx)
{
switch (function_def_get_arg_type (fn_def, arg_idx)) {
case 'f':
......@@ -656,14 +657,16 @@ function_def_get_arg_type_string (FunctionDefinition const *fn_def,
return _("Boolean");
case 'r':
return _("Cell Range");
case 'a':
return _("Array");
case 'A':
return _("Area");
case 'S':
return _("Scalar");
default:
case '?':
return _("Any");
default:
g_warning ("Unkown arg type");
return "Broken";
}
}
......@@ -714,131 +717,6 @@ function_def_get_arg_name (FunctionDefinition const *fn_def,
/* ------------------------------------------------------------------------- */
static inline Value *
function_marshal_arg (FunctionEvalInfo *ei, GnmExprEvalFlags flags,
GnmExpr *t,
char arg_type,
Value **type_mismatch)
{
Value *v;
*type_mismatch = NULL;
/* Don't dereference 'A1' by accident when all we want is a range */
if (t->any.oper == GNM_EXPR_OP_CELLREF &&
(arg_type == 'A' || arg_type == 'r'))
v = value_new_cellrange (&t->cellref.ref, &t->cellref.ref,
ei->pos->eval.col,
ei->pos->eval.row);
else
/* force scalars whenever we are certain */
v = gnm_expr_eval (t, ei->pos,
((flags & GNM_EXPR_EVAL_PERMIT_NON_SCALAR) ||
arg_type == 'r' || arg_type == 'a' ||
arg_type == 'A' || arg_type == '?')
? GNM_EXPR_EVAL_PERMIT_NON_SCALAR : GNM_EXPR_EVAL_STRICT);
switch (arg_type) {
case 'f':
case 'b':
if (v->type == VALUE_CELLRANGE)
v = value_intersection (v, ei->pos);
else if (v->type == VALUE_ARRAY)
v = gnm_expr_array_intersection (v);
if (v == NULL)
break;
if (v->type == VALUE_STRING) {
Value *newv = format_match_number (value_peek_string (v), NULL);
value_release (v);
v = newv;
break;
}
if (v->type == VALUE_ERROR) {
*type_mismatch = v;
v = NULL;
break;
}
if (v->type != VALUE_INTEGER &&
v->type != VALUE_FLOAT &&
v->type != VALUE_BOOLEAN) {
*type_mismatch = value_new_error (ei->pos,
gnumeric_err_VALUE);
}
break;
case 's':
if (v->type == VALUE_CELLRANGE)
v = value_intersection (v, ei->pos);
else if (v->type == VALUE_ARRAY)
v = gnm_expr_array_intersection (v);
if (v == NULL)
break;
if (v->type == VALUE_ERROR) {
*type_mismatch = v;
v = NULL;
} else if (v->type != VALUE_STRING) {
*type_mismatch = value_new_error (ei->pos,
gnumeric_err_VALUE);
}
break;
case 'r':
if (v->type != VALUE_CELLRANGE) {
*type_mismatch = value_new_error (ei->pos,
gnumeric_err_VALUE);
} else {
cellref_make_abs (&v->v_range.cell.a,
&v->v_range.cell.a,
ei->pos);
cellref_make_abs (&v->v_range.cell.b,
&v->v_range.cell.b,
ei->pos);
}
break;
case 'a':
if (v->type != VALUE_ARRAY) {
*type_mismatch = value_new_error (ei->pos,
gnumeric_err_VALUE);
}
break;
case 'A':
if (v->type != VALUE_ARRAY &&
v->type != VALUE_CELLRANGE) {
*type_mismatch = value_new_error (ei->pos,
gnumeric_err_VALUE);
}
if (v->type == VALUE_CELLRANGE) {
cellref_make_abs (&v->v_range.cell.a,
&v->v_range.cell.a,
ei->pos);
cellref_make_abs (&v->v_range.cell.b,
&v->v_range.cell.b,
ei->pos);
}
break;
case 'S':
if (v->type == VALUE_CELLRANGE)
v = value_intersection (v, ei->pos);
else if (v->type == VALUE_ARRAY)
v = gnm_expr_array_intersection (v);
break;
default :
break;
}
return v;
}
static inline void
free_values (Value **values, int top)
{
......@@ -847,7 +725,6 @@ free_values (Value **values, int top)
for (i = 0; i < top; i++)
if (values [i])
value_release (values [i]);
g_free (values);
}
/**
......@@ -865,9 +742,10 @@ function_call_with_list (FunctionEvalInfo *ei, GnmExprList *l,
GnmExprEvalFlags flags)
{
FunctionDefinition const *fn_def;
int argc, arg;
Value *v = NULL;
Value **values;
int argc, i, optional;
char arg_type;
Value *tmp, **args;
GnmExpr *expr;
g_return_val_if_fail (ei != NULL, NULL);
g_return_val_if_fail (ei->func_call != NULL, NULL);
......@@ -888,31 +766,96 @@ function_call_with_list (FunctionEvalInfo *ei, GnmExprList *l,
_("Invalid number of arguments"));
}
values = g_new (Value *, fn_def->fn.args.max_args);
optional = 0;
args = g_alloca (sizeof (Value *) * fn_def->fn.args.max_args);
for (i = 0; l; l = l->next, ++i) {
arg_type = fn_def->fn.args.arg_types[i];
expr = l->data;
if (i > fn_def->fn.args.min_args)
optional = GNM_EXPR_EVAL_PERMIT_EMPTY;
if (arg_type == 'A' || arg_type == 'r') {
if (expr->any.oper == GNM_EXPR_OP_CELLREF) {
CellRef r;
cellref_make_abs (&r, &expr->cellref.ref, ei->pos);
args[i] = value_new_cellrange_unsafe (&r, &r);
} else {
tmp = args[i] = gnm_expr_eval (expr, ei->pos,
optional | GNM_EXPR_EVAL_PERMIT_NON_SCALAR);
if (tmp->type == VALUE_CELLRANGE) {
cellref_make_abs (&tmp->v_range.cell.a,
&tmp->v_range.cell.a,
ei->pos);
cellref_make_abs (&tmp->v_range.cell.b,
&tmp->v_range.cell.b,
ei->pos);
} else if (tmp->type != VALUE_ARRAY || arg_type != 'A') {
free_values (args, i + 1);
return value_new_error (ei->pos, gnumeric_err_VALUE);
}
}
continue;
}
for (arg = 0; l; l = l->next, ++arg) {
char arg_type;
Value *type_mismatch;
/* force scalars whenever we are certain */
tmp = args[i] = gnm_expr_eval (expr, ei->pos, optional |
((flags & GNM_EXPR_EVAL_PERMIT_NON_SCALAR) || arg_type == '?')
? GNM_EXPR_EVAL_PERMIT_NON_SCALAR : GNM_EXPR_EVAL_STRICT);
arg_type = fn_def->fn.args.arg_types[arg];
/* Optional arguments can be empty */
if (tmp == NULL)
continue;
values[arg] = function_marshal_arg (ei, flags,
l->data, arg_type, &type_mismatch);
switch (arg_type) {
case 'f':
case 'b':
if (tmp->type == VALUE_STRING) {
tmp = format_match_number (value_peek_string (tmp), NULL);
if (tmp == NULL) {
free_values (args, i + 1);
return value_new_error (ei->pos, gnumeric_err_VALUE);
}
value_release (args [i]);
args[i] = tmp;
} else if (tmp->type == VALUE_ERROR) {
free_values (args, i);
return tmp;
}
if (type_mismatch || values[arg] == NULL) {
free_values (values, arg + 1);
if (type_mismatch)
return type_mismatch;
else
if (tmp->type != VALUE_INTEGER &&
tmp->type != VALUE_FLOAT &&
tmp->type != VALUE_BOOLEAN) {
free_values (args, i+1);
return value_new_error (ei->pos, gnumeric_err_VALUE);
}
break;
case 's':
if (tmp->type == VALUE_ERROR) {
free_values (args, i);
return tmp;
} else if (tmp->type != VALUE_STRING) {
free_values (args, i+1);
return value_new_error (ei->pos, gnumeric_err_VALUE);
}
break;
case 'S': /* nothing necessary */
case '?': /* nothing necessary */
break;
default :
g_warning ("Unknown argument type '%c'", arg_type);
break;
}
}
while (arg < fn_def->fn.args.max_args)
values [arg++] = NULL;
v = fn_def->fn.args.func (ei, values);
free_values (values, arg);
return v;
while (i < fn_def->fn.args.max_args)
args [i++] = NULL;
tmp = fn_def->fn.args.func (ei, args);
free_values (args, i);
return tmp;
}
/*
......
......@@ -622,7 +622,7 @@ gnumeric_canvas_new (SheetControlGUI *scg, GnumericPane *pane)
g_return_val_if_fail (IS_SHEET_CONTROL_GUI (scg), NULL);
gcanvas = gtk_type_new (GNUMERIC_CANVAS_TYPE);
gcanvas = g_object_new (GNUMERIC_CANVAS_TYPE, NULL);
gcanvas->simple.scg = scg;
gcanvas->pane = pane;
......
......@@ -45,10 +45,13 @@
#include "dialogs.h"
#include "sheet-control-gui.h"
#include "parse-util.h"
#include "gnumeric-canvas.h"
#include "gnumeric-pane.h"
#include <gsf/gsf-impl-utils.h>
#include <gal/util/e-xml-utils.h>
#include <libxml/parser.h>
#include <libgnomecanvas/gnome-canvas-rect-ellipse.h>
#define DISABLE_DEBUG
#ifndef DISABLE_DEBUG
......@@ -419,7 +422,7 @@ gnm_graph_clear_vectors_internal (GnmGraph *graph, gboolean unsubscribe)
continue;
vector->graph = NULL;
gtk_object_unref (GTK_OBJECT (vector));
g_object_unref (G_OBJECT (vector));
}
g_ptr_array_set_size (graph->vectors, 0);
if (unsubscribe) {
......@@ -518,7 +521,7 @@ gnm_graph_add_vector (GnmGraph *graph, GnmExpr const *expr,
}
}
vector = gtk_type_new (gnm_graph_vector_get_type ());
vector = g_object_new (gnm_graph_vector_get_type (), NULL);
vector->dep.sheet = sheet;
vector->dep.flags = gnm_graph_vector_get_dep_type ();
vector->dep.expression = expr;
......@@ -557,7 +560,7 @@ gnm_graph_add_vector (GnmGraph *graph, GnmExpr const *expr,
vector->type = type;
if ( /* !gnm_graph_vector_corba_init (vector) || */
!gnm_graph_subscribe_vector (graph, vector)) {
gtk_object_unref (GTK_OBJECT (vector));
g_object_unref (G_OBJECT (vector));
vector = NULL;
} else {
d({
......@@ -1018,6 +1021,49 @@ gnm_graph_write_xml (SheetObject const *so,
return FALSE;
}
static GObject *
gnm_graph_new_view (SheetObject *so, SheetControl *sc, gpointer key)
{
GnumericCanvas *gcanvas = ((GnumericPane *)key)->gcanvas;
GnomeCanvasItem *item;
g_return_val_if_fail (gcanvas != NULL, NULL);
gnome_canvas_item_raise_to_top (GNOME_CANVAS_ITEM (gcanvas->sheet_object_group));
item = gnome_canvas_item_new (gcanvas->sheet_object_group,
GNOME_TYPE_CANVAS_RECT,
"fill_color", "white",
"outline_color", "black",
"width_units", 3.,
NULL);
gnm_pane_object_register (so, item);
return G_OBJECT (item);
}
static void
gnm_graph_update_bounds (SheetObject *so, GObject *view)
{
double coords [4];
SheetControlGUI *scg =
SHEET_CONTROL_GUI (sheet_object_view_control (view));
scg_object_view_position (scg, so, coords);
gnome_canvas_item_set (GNOME_CANVAS_ITEM (view),
"x1", MIN (coords [0], coords [2]),
"x2", MAX (coords [0], coords [2]),
"y1", MIN (coords [1], coords [3]),
"y2", MAX (coords [1], coords [3]),
NULL);
if (so->is_visible)
gnome_canvas_item_show (GNOME_CANVAS_ITEM (view));
else
gnome_canvas_item_hide (GNOME_CANVAS_ITEM (view));
}
static void
gnm_graph_class_init (GObjectClass *object_class)
{
......@@ -1027,6 +1073,8 @@ gnm_graph_class_init (GObjectClass *object_class)
object_class->finalize = &gnm_graph_finalize;
sheet_object_class = SHEET_OBJECT_CLASS (object_class);
sheet_object_class->new_view = gnm_graph_new_view;
sheet_object_class->update_bounds = gnm_graph_update_bounds;
sheet_object_class->populate_menu = gnm_graph_populate_menu;
sheet_object_class->user_config = gnm_graph_user_config;
sheet_object_class->read_xml = gnm_graph_read_xml;
......
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