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

Use extra argument.

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

	* src/parser.c (dump_tree): Use extra argument.

	* src/expr.c (function_call_with_values): Use the extra argument
	to symbol_lookup

	* src/func.c (constants_init): Use the extra argument to symbol_install.

	* src/main.c (main): Invoke global_symbol_init.

	* src/symbol.h: Symbol routines now take an extra argument; the
	symboltable they work on.  Now the code can have multiple symbol
	tables (this is required for the cell range name bindings in a
	per-sheet fashion.
parent 3c2796d5
1998-10-27 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/parser.c (dump_tree): Use extra argument.
* src/expr.c (function_call_with_values): Use the extra argument
to symbol_lookup
* src/func.c (constants_init): Use the extra argument to symbol_install.
* src/main.c (main): Invoke global_symbol_init.
* src/symbol.h: Symbol routines now take an extra argument; the
symboltable they work on. Now the code can have multiple symbol
tables (this is required for the cell range name bindings in a
per-sheet fashion.
1998-10-25 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet.c (sheet_set_zoom_factor): Zoom factor should be
applied to to the default styles.
1998-10-27 Daniel Veillard <Daniel.Veillard@w3.org>
* src/xml-io.c: adapted code to the new XML tree format, however
......
1998-10-27 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/parser.c (dump_tree): Use extra argument.
* src/expr.c (function_call_with_values): Use the extra argument
to symbol_lookup
* src/func.c (constants_init): Use the extra argument to symbol_install.
* src/main.c (main): Invoke global_symbol_init.
* src/symbol.h: Symbol routines now take an extra argument; the
symboltable they work on. Now the code can have multiple symbol
tables (this is required for the cell range name bindings in a
per-sheet fashion.
1998-10-25 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet.c (sheet_set_zoom_factor): Zoom factor should be
applied to to the default styles.
1998-10-27 Daniel Veillard <Daniel.Veillard@w3.org>
* src/xml-io.c: adapted code to the new XML tree format, however
......
1998-10-27 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/parser.c (dump_tree): Use extra argument.
* src/expr.c (function_call_with_values): Use the extra argument
to symbol_lookup
* src/func.c (constants_init): Use the extra argument to symbol_install.
* src/main.c (main): Invoke global_symbol_init.
* src/symbol.h: Symbol routines now take an extra argument; the
symboltable they work on. Now the code can have multiple symbol
tables (this is required for the cell range name bindings in a
per-sheet fashion.
1998-10-25 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet.c (sheet_set_zoom_factor): Zoom factor should be
applied to to the default styles.
1998-10-27 Daniel Veillard <Daniel.Veillard@w3.org>
* src/xml-io.c: adapted code to the new XML tree format, however
......
1998-10-27 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/parser.c (dump_tree): Use extra argument.
* src/expr.c (function_call_with_values): Use the extra argument
to symbol_lookup
* src/func.c (constants_init): Use the extra argument to symbol_install.
* src/main.c (main): Invoke global_symbol_init.
* src/symbol.h: Symbol routines now take an extra argument; the
symboltable they work on. Now the code can have multiple symbol
tables (this is required for the cell range name bindings in a
per-sheet fashion.
1998-10-25 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet.c (sheet_set_zoom_factor): Zoom factor should be
applied to to the default styles.
1998-10-27 Daniel Veillard <Daniel.Veillard@w3.org>
* src/xml-io.c: adapted code to the new XML tree format, however
......
......@@ -157,7 +157,7 @@ __register_function (PyObject *m, PyObject *py_args)
fndef->fn = marshal_func;
symbol_install (fndef->name, SYMBOL_FUNCTION, fndef);
symbol_install (global_symbol_table, fndef->name, SYMBOL_FUNCTION, fndef);
Py_INCREF (Py_None);
return Py_None;
......
......@@ -32,7 +32,7 @@ can_unload (PluginData *pd)
{
Symbol *sym;
sym = symbol_lookup ("plusone");
sym = symbol_lookup (global_symbol_table, "plusone");
return sym->ref_count <= 1;
}
......@@ -42,7 +42,7 @@ cleanup_plugin (PluginData *pd)
Symbol *sym;
g_free (pd->title);
sym = symbol_lookup ("plusone");
sym = symbol_lookup (global_symbol_table, "plusone");
if (sym) {
symbol_unref(sym);
}
......
......@@ -40,86 +40,90 @@ static char *help_stat_nvariance = {
};
static FunctionDefinition plugin_functions[] = {
{"stdev", "", "", &help_stat_stdev, stat_stdev, NULL },
{"variance", "", "", &help_stat_variance, stat_variance, NULL },
{"nvariance", "", "", &help_stat_nvariance, stat_nvariance, NULL },
{ NULL, NULL },};
{"stdev", "", "", &help_stat_stdev, stat_stdev, NULL },
{"variance", "", "", &help_stat_variance, stat_variance, NULL },
{"nvariance", "", "", &help_stat_nvariance, stat_nvariance, NULL },
{ NULL, NULL },
};
static int can_unload(PluginData *pd) {
static int
can_unload (PluginData *pd)
{
Symbol *sym;
sym = symbol_lookup("stat_variance");
sym = symbol_lookup (global_symbol_table, "stat_variance");
return sym->ref_count <= 1;
}
int init_plugin (PluginData *pd) {
install_symbols(plugin_functions);
int
init_plugin (PluginData *pd)
{
install_symbols (plugin_functions);
pd->can_unload = can_unload;
pd->cleanup_plugin = cleanup_plugin;
pd->title = g_strdup("Statistics Plugin");
pd->title = g_strdup (_("Statistics Plugin"));
return 0;
}
static void cleanup_plugin (PluginData *pd) {
static void
cleanup_plugin (PluginData *pd)
{
Symbol *sym;
unsigned int i;
g_free (pd->title);
for(i=0;i<(((sizeof(plugin_functions))/(sizeof(FunctionDefinition)))-1);i++) {
sym = symbol_lookup(plugin_functions[i].name);
if (sym)
for (i = 0; i <(((sizeof(plugin_functions))/(sizeof(FunctionDefinition)))-1); i++){
sym = symbol_lookup(global_symbol_table, plugin_functions [i].name);
if (sym)
symbol_unref(sym);
}
}
static Value *stat_variance(void *sheet, GList *expr_node_list, int eval_col,
int eval_row, char **error_string) {
Value *result;
static Value *
stat_variance (void *sheet, GList *expr_node_list, int eval_col,
int eval_row, char **error_string)
{
float undiv;
unsigned int len;
result = g_malloc(sizeof(Value *));
result->type = VALUE_FLOAT;
result->v.v_float = 0.0;
undiv = stat_undivided_variance(sheet, expr_node_list, eval_col,
eval_row, error_string);
len = g_list_length(expr_node_list);
if (len == 1) {
undiv = stat_undivided_variance (sheet, expr_node_list, eval_col,
eval_row, error_string);
len = g_list_length (expr_node_list);
if (len == 1){
*error_string = _("variance - division by 0");
g_free(result);
return NULL;
}
result->v.v_float = undiv / (len - 1);
return result;
return value_float (undiv / (len - 1));
}
static Value *stat_nvariance(void *sheet, GList *expr_node_list, int eval_col,
int eval_row, char **error_string) {
Value *result;
static Value *
stat_nvariance (void *sheet, GList *expr_node_list, int eval_col,
int eval_row, char **error_string)
{
float undiv;
unsigned int len;
result = g_malloc(sizeof(Value *));
result->type = VALUE_FLOAT;
result->v.v_float = 0.0;
undiv = stat_undivided_variance(sheet, expr_node_list, eval_col,
eval_row, error_string);
len = g_list_length(expr_node_list);
result->v.v_float = undiv / len;
return result;
return value_float (undiv / len);
}
float stat_undivided_variance(void *sheet, GList *expr_node_list,
int eval_col, int eval_row,
char **error_string) {
float
stat_undivided_variance (void *sheet, GList *expr_node_list,
int eval_col, int eval_row,
char **error_string)
{
Value *avgV, *tmpval;
GPtrArray *values;
......@@ -142,19 +146,21 @@ float stat_undivided_variance(void *sheet, GList *expr_node_list,
avg = value_get_as_double(avgV);
for(i=0;i<(values->len); i++) {
tmpval = g_ptr_array_index(values, i);
for (i = 0; i < values->len; i++){
tmpval = g_ptr_array_index (values, i);
tmp = tmpval->v.v_float - avg;
tmp *= tmp;
result += tmp;
}
g_free(avgV);
g_free (avgV);
return result;
}
static Value *stat_stdev(void *sheet, GList *expr_node_list, int eval_col, int eval_row, char **error_string) {
static Value *
stat_stdev (void *sheet, GList *expr_node_list, int eval_col, int eval_row, char **error_string)
{
Value *result, *var;
result = g_malloc(sizeof(Value *));
......@@ -172,15 +178,16 @@ static Value *stat_stdev(void *sheet, GList *expr_node_list, int eval_col,
}
int callback_var ( Sheet *sheet, Value *value, char **error_string,
void *closure) {
int
callback_var (Sheet *sheet, Value *value, char **error_string, void *closure)
{
GPtrArray *values = (GPtrArray *) closure;
float tmp;
tmp =value_get_as_double(value);
tmp = value_get_as_double (value);
value->v.v_float = tmp;
value->type = VALUE_FLOAT;
g_ptr_array_add(values, g_memdup(value, sizeof(*value)));
g_ptr_array_add (values, g_memdup (value, sizeof (*value)));
return TRUE;
}
......
/*
* dialog-goto-cell.c: Implements the Define Name dialog box
*
* Author:
* Miguel de Icaza (miguel@gnu.org)
*
*/
#include <config.h>
#include <gnome.h>
#include "gnumeric.h"
#include "gnumeric-util.h"
#include "dialogs.h"
void
dialog_define_names (Workbook *wb)
{
static GtkWidget *dialog;
GtkWidget *l;
GtkCList *clist;
GtkEntry *name, *refers;
if (!dialog){
dialog = gnome_dialog_new (_("Define names"),
GNOME_STOCK_BUTTON_APPLY,
GNOME_STOCK_BUTTON_CLOSE,
_("Add"),
_("Remove"),
NULL);
clist = (GtkCList *) gtk_clist_new (1);
gtk_clist_column_titles_hide (clist);
name = (GtkEntry *) gtk_entry_new ();
refers = (GtkEntry *) gtk_entry_new ();
box = gtk_vbox_new (0, 2);
l = gtk_label_new (_("Names in the workbook"));
gtk_misc_set_alignment (GTK_MISC (l), 0.0, 0.5);
gtk_box_pack_start (GTK_BOX (box), l, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (box), GTK_WIDGET (name), TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (box), GTK_WIDGET (clist), TRUE, TRUE, 0);
l = gtk_label_new (_("Refers to"));
gtk_misc_set_alignment (GTK_MISC (l), 0.0, 0.5);
gtk_box_pack_start (GTK_BOX (box), l, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (box), GTK_WIDGET (refers), TRUE, TRUE, 0);
}
gtk_widget_show_all (dialog);
}
......@@ -9,5 +9,6 @@ void dialog_delete_cells (Sheet *sheet);
void dialog_zoom (Sheet *sheet);
char *dialog_query_load_file (void);
void dialog_about (void);
void dialog_define_names (Workbook *wb);
#endif /* GNUMERIC_DIALOGS_H */
/*
* dialog-goto-cell.c: Implements the Define Name dialog box
*
* Author:
* Miguel de Icaza (miguel@gnu.org)
*
*/
#include <config.h>
#include <gnome.h>
#include "gnumeric.h"
#include "gnumeric-util.h"
#include "dialogs.h"
void
dialog_define_names (Workbook *wb)
{
static GtkWidget *dialog;
GtkWidget *l;
GtkCList *clist;
GtkEntry *name, *refers;
if (!dialog){
dialog = gnome_dialog_new (_("Define names"),
GNOME_STOCK_BUTTON_APPLY,
GNOME_STOCK_BUTTON_CLOSE,
_("Add"),
_("Remove"),
NULL);
clist = (GtkCList *) gtk_clist_new (1);
gtk_clist_column_titles_hide (clist);
name = (GtkEntry *) gtk_entry_new ();
refers = (GtkEntry *) gtk_entry_new ();
box = gtk_vbox_new (0, 2);
l = gtk_label_new (_("Names in the workbook"));
gtk_misc_set_alignment (GTK_MISC (l), 0.0, 0.5);
gtk_box_pack_start (GTK_BOX (box), l, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (box), GTK_WIDGET (name), TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (box), GTK_WIDGET (clist), TRUE, TRUE, 0);
l = gtk_label_new (_("Refers to"));
gtk_misc_set_alignment (GTK_MISC (l), 0.0, 0.5);
gtk_box_pack_start (GTK_BOX (box), l, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (box), GTK_WIDGET (refers), TRUE, TRUE, 0);
}
gtk_widget_show_all (dialog);
}
......@@ -9,5 +9,6 @@ void dialog_delete_cells (Sheet *sheet);
void dialog_zoom (Sheet *sheet);
char *dialog_query_load_file (void);
void dialog_about (void);
void dialog_define_names (Workbook *wb);
#endif /* GNUMERIC_DIALOGS_H */
......@@ -30,7 +30,7 @@ dump_functions (char *filename)
exit (1);
}
g_hash_table_foreach (symbol_hash_table, dump_func_help, NULL);
g_hash_table_foreach (global_symbol_table->hash, dump_func_help, NULL);
fclose (output_file);
}
......@@ -539,7 +539,7 @@ function_call_with_values (Sheet *sheet, char *name, int argc, Value *values[],
g_return_val_if_fail (IS_SHEET (sheet), NULL);
g_return_val_if_fail (name != NULL, NULL);
sym = symbol_lookup (name);
sym = symbol_lookup (global_symbol_table, name);
if (sym == NULL){
*error_string = "Function does not exist";
return NULL;
......
......@@ -143,7 +143,8 @@ install_symbols (FunctionDefinition *functions)
int i;
for (i = 0; functions [i].name; i++){
symbol_install (functions [i].name, SYMBOL_FUNCTION, &functions [i]);
symbol_install (global_symbol_table, functions [i].name,
SYMBOL_FUNCTION, &functions [i]);
}
}
......@@ -177,7 +178,7 @@ constants_init (void)
version->type = VALUE_FLOAT;
version->v.v_float = atof (GNUMERIC_VERSION);
symbol_install ("FALSE", SYMBOL_VALUE, false);
symbol_install ("TRUE", SYMBOL_VALUE, true);
symbol_install ("GNUMERIC_VERSION", SYMBOL_VALUE, version);
symbol_install (global_symbol_table, "FALSE", SYMBOL_VALUE, false);
symbol_install (global_symbol_table, "TRUE", SYMBOL_VALUE, true);
symbol_install (global_symbol_table, "GNUMERIC_VERSION", SYMBOL_VALUE, version);
}
......@@ -307,7 +307,7 @@ set_cursor (ItemBar *item_bar, int pos)
/*
* Returns the GnomeCanvasPoints for a line at position in the
* correct orientation
* correct orientation.
*/
static GnomeCanvasPoints *
item_bar_get_line_points (ItemBar *item_bar, gdouble position)
......@@ -341,6 +341,7 @@ item_bar_start_resize (ItemBar *item_bar, int pos, int pixels)
GnumericSheet *gsheet;
Sheet *sheet;
int division_pos;
double division_pos_d;
sheet = item_bar->sheet_view->sheet;
gsheet = GNUMERIC_SHEET (item_bar->sheet_view->sheet_view);
......@@ -354,9 +355,12 @@ item_bar_start_resize (ItemBar *item_bar, int pos, int pixels)
sheet, gsheet->top_col, pos+1);
}
points = item_bar_get_line_points (item_bar, division_pos);
/* division_pos is in pixels, convert to canvas units */
gnome_canvas_window_to_world (GNOME_CANVAS (gsheet), division_pos, 0, &division_pos_d, NULL);
item_bar->resize_guide_offset = division_pos - pixels;
points = item_bar_get_line_points (item_bar, division_pos_d);
item_bar->resize_guide_offset = division_pos_d - pixels;
item = gnome_canvas_item_new (
group,
......
......@@ -61,7 +61,7 @@ main (int argc, char *argv [])
style_init ();
format_color_init ();
cursors_init ();
symbol_init ();
global_symbol_init ();
constants_init ();
functions_init ();
plugins_init ();
......
......@@ -61,7 +61,7 @@ main (int argc, char *argv [])
style_init ();
format_color_init ();
cursors_init ();
symbol_init ();
global_symbol_init ();
constants_init ();
functions_init ();
plugins_init ();
......
......@@ -136,7 +136,7 @@ sheet_new (Workbook *wb, char *name)
sheet->max_row_used = 0;
sheet->cell_hash = g_hash_table_new (cell_hash, cell_compare);
sheet_style = style_new ();
sheet_style_attach (sheet, 0, 0, SHEET_MAX_COLS-1, SHEET_MAX_ROWS-1, sheet_style);
......@@ -210,9 +210,14 @@ sheet_set_zoom_factor (Sheet *sheet, double factor)
sheet->last_zoom_factor_used = factor;
/* First, the default styles */
sheet_compute_col_row_new_size (sheet, &sheet->default_row_style, NULL);
sheet_compute_col_row_new_size (sheet, &sheet->default_col_style, NULL);
/* Then every column and row */
sheet_foreach_col (sheet, sheet_compute_col_row_new_size, NULL);
sheet_foreach_row (sheet, sheet_compute_col_row_new_size, NULL);
for (l = sheet->sheet_views; l; l = l->next){
SheetView *sheet_view = l->data;
......@@ -240,7 +245,7 @@ sheet_row_new (Sheet *sheet)
g_return_val_if_fail (sheet != NULL, NULL);
g_return_val_if_fail (IS_SHEET (sheet), NULL);
ri = sheet_duplicate_colrow (&sheet->default_row_style);
row_init_span (ri);
......
......@@ -56,6 +56,9 @@ typedef struct {
gboolean have_x_selection;
/* The Symbol table used for naming cell ranges in the workbook */
SymbolTable *symbol_names;
/*
* This is used during the clipboard paste command to pass information
* to the asyncronous paste callback
......@@ -79,50 +82,50 @@ typedef enum {
} SheetModeType;
typedef struct {
int signature;
int signature;
Workbook *workbook;
GList *sheet_views;
Workbook *workbook;
GList *sheet_views;
char *name;
char *name;
GList *style_list; /* The list of styles applied to the sheets */
GList *style_list; /* The list of styles applied to the sheets */
ColRowInfo default_col_style;
GList *cols_info;
ColRowInfo default_col_style;
GList *cols_info;
ColRowInfo default_row_style;
GList *rows_info;
ColRowInfo default_row_style;
GList *rows_info;
GHashTable *cell_hash; /* The cells in hashed format */
GHashTable *cell_hash; /* The cells in hashed format */
GList *selections;
GList *selections;
int max_col_used;
int max_row_used;
int max_col_used;
int max_row_used;
int cursor_col, cursor_row;
/* The list of formulas */
GList *formula_cell_list;
GList *formula_cell_list;
double last_zoom_factor_used;
double last_zoom_factor_used;
/* Objects */
SheetModeType mode; /* Sheet mode */
GList *objects; /* List of objects in the spreadsheet */
GList *coords; /* During creation time: keeps click coordinates */
void *current_object;
GList *objects; /* List of objects in the spreadsheet */