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

If there is a selection of columns or rows, change the sizes of all of the

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

	* src/sheet-view.c (sheet_view_row_size_changed,
	sheet_view_col_size_changed): If there is a selection of columns
	or rows, change the sizes of all of the columns.

	* src/sheet.c (sheet_row_get_distance, sheet_col_get_distance):
	optimized to be O(n) instead of O(n^2) using
	(col_row_distance): new routine to compute distances.

	* src/sheet-view.c (sheet_view_redraw_cell_region): Add the
	scrolling offset to the x and y positions to draw properly

	* src/xml-io.c (readXmlSheet): Call sheet_set_zoom_factor to
	initialize the ->pixels field.
parent 1b9a3908
1998-09-17 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet-view.c (sheet_view_row_size_changed,
sheet_view_col_size_changed): If there is a selection of columns
or rows, change the sizes of all of the columns.
* src/sheet.c (sheet_row_get_distance, sheet_col_get_distance):
optimized to be O(n) instead of O(n^2) using
(col_row_distance): new routine to compute distances.
* src/sheet-view.c (sheet_view_redraw_cell_region): Add the
scrolling offset to the x and y positions to draw properly
* src/xml-io.c (readXmlSheet): Call sheet_set_zoom_factor to
initialize the ->pixels field.
* src/expr.h: Valued functions now take a FunctionDefinition *
parameter which points to the definition that was used for this
function. This is required for the python interpreter.
* src/cellspan.c (row_cell_get_displayed_at): row->data might be NULL.
(cell_unregister_span): row->data might be NULL.
......
1998-09-17 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet-view.c (sheet_view_row_size_changed,
sheet_view_col_size_changed): If there is a selection of columns
or rows, change the sizes of all of the columns.
* src/sheet.c (sheet_row_get_distance, sheet_col_get_distance):
optimized to be O(n) instead of O(n^2) using
(col_row_distance): new routine to compute distances.
* src/sheet-view.c (sheet_view_redraw_cell_region): Add the
scrolling offset to the x and y positions to draw properly
* src/xml-io.c (readXmlSheet): Call sheet_set_zoom_factor to
initialize the ->pixels field.
* src/expr.h: Valued functions now take a FunctionDefinition *
parameter which points to the definition that was used for this
function. This is required for the python interpreter.
* src/cellspan.c (row_cell_get_displayed_at): row->data might be NULL.
(cell_unregister_span): row->data might be NULL.
......
1998-09-17 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet-view.c (sheet_view_row_size_changed,
sheet_view_col_size_changed): If there is a selection of columns
or rows, change the sizes of all of the columns.
* src/sheet.c (sheet_row_get_distance, sheet_col_get_distance):
optimized to be O(n) instead of O(n^2) using
(col_row_distance): new routine to compute distances.
* src/sheet-view.c (sheet_view_redraw_cell_region): Add the
scrolling offset to the x and y positions to draw properly
* src/xml-io.c (readXmlSheet): Call sheet_set_zoom_factor to
initialize the ->pixels field.
* src/expr.h: Valued functions now take a FunctionDefinition *
parameter which points to the definition that was used for this
function. This is required for the python interpreter.
* src/cellspan.c (row_cell_get_displayed_at): row->data might be NULL.
(cell_unregister_span): row->data might be NULL.
......
1998-09-17 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet-view.c (sheet_view_row_size_changed,
sheet_view_col_size_changed): If there is a selection of columns
or rows, change the sizes of all of the columns.
* src/sheet.c (sheet_row_get_distance, sheet_col_get_distance):
optimized to be O(n) instead of O(n^2) using
(col_row_distance): new routine to compute distances.
* src/sheet-view.c (sheet_view_redraw_cell_region): Add the
scrolling offset to the x and y positions to draw properly
* src/xml-io.c (readXmlSheet): Call sheet_set_zoom_factor to
initialize the ->pixels field.
* src/expr.h: Valued functions now take a FunctionDefinition *
parameter which points to the definition that was used for this
function. This is required for the python interpreter.
* src/cellspan.c (row_cell_get_displayed_at): row->data might be NULL.
(cell_unregister_span): row->data might be NULL.
......
......@@ -37,11 +37,17 @@ ALL_LINGUAS="es fr ko pt it"
AM_GNU_GETTEXT
AC_LINK_FILES($nls_cv_header_libgt, $nls_cv_header_intl)
dnl
dnl Check for Python
dnl
dnl rats, this is more difficult that I expected
AC_OUTPUT([
Makefile
src/Makefile
plugins/Makefile
plugins/sample/Makefile
plugins/python/Makefile
intl/Makefile
po/Makefile.in
macros/Makefile
......
......@@ -24,7 +24,7 @@ the symbolic names for the arguments (in case our function supports
them, this allows users to specify named paramters); The fourth
parameter links in the help description.
Now, our routine is pretty simple: it will always require 2 arguments
Now, our routine is pretty simple: it will always require two arguments
to be passed, so we can let Gnumeric deal with argument count and we
can let the Gnumeric engine compute the values in the expression for
us. So, for this case we leave the fift parameter set as NULL and set
......@@ -43,7 +43,7 @@ expression, our routine will be invoked, this is how the add2numbers
function signature looks like:
static Value *
add2numbers (Value *argv [], char **error_string)
add2numbers (FunctionDefinition *fn_def, Value *argv [], char **error_string)
{
}
......@@ -53,10 +53,17 @@ Arguments are passed in the argv array and they contain Value
structures (look in gnumeric/src/expr.h for the definition of the
Value structure).
The first parameter, fn_def is a pointer to the FunctionDefinition
structure that was used to define this function. This is normally
ignored, but some functions might want to access this (for example, a
single function callback might implement various functions and can
figure how it was invoked by poking at this value)
Here is the actual implementation:
static Value *
add2numbers (Value *argv [], char **error_string)
add2numbers (FunctionDefinition *fn_def, Value *argv [], char **error_string)
{
Value *result;
float number_a, number_b;
......
SUBDIRS = sample
SUBDIRS = sample
......@@ -23,7 +23,7 @@ static Value *gnumeric_count (void *tsheet, GList *expr_node_list,
char **error_string);
static Value *
gnumeric_abs (Value *argv [], char **error_string)
gnumeric_abs (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
Value *v = g_new (Value, 1);
......@@ -34,7 +34,7 @@ gnumeric_abs (Value *argv [], char **error_string)
}
static Value *
gnumeric_acos (Value *argv [], char **error_string)
gnumeric_acos (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
Value *v;
float_t t;
......@@ -52,7 +52,7 @@ gnumeric_acos (Value *argv [], char **error_string)
}
static Value *
gnumeric_acosh (Value *argv [], char **error_string)
gnumeric_acosh (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
Value *v;
float_t t;
......@@ -208,7 +208,7 @@ gnumeric_and (void *tsheet, GList *expr_node_list, int eval_col, int eval_row, c
}
static Value *
gnumeric_asin (Value *argv [], char **error_string)
gnumeric_asin (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
Value *v;
float_t t;
......@@ -226,7 +226,7 @@ gnumeric_asin (Value *argv [], char **error_string)
}
static Value *
gnumeric_asinh (Value *argv [], char **error_string)
gnumeric_asinh (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
Value *v;
......@@ -238,7 +238,7 @@ gnumeric_asinh (Value *argv [], char **error_string)
}
static Value *
gnumeric_atan (Value *argv [], char **error_string)
gnumeric_atan (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
Value *v = g_new (Value, 1);
......@@ -249,7 +249,7 @@ gnumeric_atan (Value *argv [], char **error_string)
}
static Value *
gnumeric_atanh (Value *argv [], char **error_string)
gnumeric_atanh (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
Value *v = g_new (Value, 1);
float_t t;
......@@ -266,7 +266,7 @@ gnumeric_atanh (Value *argv [], char **error_string)
}
static Value *
gnumeric_atan2 (Value *argv [], char **error_string)
gnumeric_atan2 (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
Value *v = g_new (Value, 1);
......@@ -316,7 +316,7 @@ gnumeric_average (void *tsheet, GList *expr_node_list, int eval_col, int eval_ro
}
static Value *
gnumeric_ceil (Value *argv [], char **error_string)
gnumeric_ceil (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
Value *v = g_new (Value, 1);
......@@ -327,7 +327,7 @@ gnumeric_ceil (Value *argv [], char **error_string)
}
static Value *
gnumeric_bin2dec (Value *argv [], char **error_string)
gnumeric_bin2dec (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
Value *value;
int result, v, n, bit;
......@@ -368,7 +368,7 @@ gnumeric_bin2dec (Value *argv [], char **error_string)
}
static Value *
gnumeric_cos (Value *argv [], char **error_string)
gnumeric_cos (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
Value *v = g_new (Value, 1);
......@@ -379,7 +379,7 @@ gnumeric_cos (Value *argv [], char **error_string)
}
static Value *
gnumeric_cosh (Value *argv [], char **error_string)
gnumeric_cosh (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
Value *v = g_new (Value, 1);
......@@ -426,7 +426,7 @@ gnumeric_count (void *tsheet, GList *expr_node_list, int eval_col, int eval_row,
}
static Value *
gnumeric_degrees (Value *argv [], char **error_string)
gnumeric_degrees (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
Value *v = g_new (Value, 1);
......@@ -437,7 +437,7 @@ gnumeric_degrees (Value *argv [], char **error_string)
}
static Value *
gnumeric_exp (Value *argv [], char **error_string)
gnumeric_exp (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
Value *v = g_new (Value, 1);
......@@ -456,7 +456,7 @@ fact (int n)
}
static Value *
gnumeric_fact (Value *argv [], char **error_string)
gnumeric_fact (struct FunctionDefinition *id, Value *argv [], char **error_string)
{
Value *res;
int i;
......@@ -488,7 +488,7 @@ gnumeric_fact (Value *argv [], char **error_string)
}
static Value *
gnumeric_floor (Value *argv [], char **error_string)
gnumeric_floor (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
Value *v = g_new (Value, 1);
......@@ -499,7 +499,7 @@ gnumeric_floor (Value *argv [], char **error_string)
}
static Value *
gnumeric_int (Value *argv [], char **error_string)
gnumeric_int (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
Value *v = g_new (Value, 1);
float_t t;
......@@ -513,7 +513,7 @@ gnumeric_int (Value *argv [], char **error_string)
}
static Value *
gnumeric_log (Value *argv [], char **error_string)
gnumeric_log (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
Value *v;
float_t t;
......@@ -531,7 +531,7 @@ gnumeric_log (Value *argv [], char **error_string)
}
static Value *
gnumeric_log2 (Value *argv [], char **error_string)
gnumeric_log2 (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
Value *v;
float_t t;
......@@ -549,7 +549,7 @@ gnumeric_log2 (Value *argv [], char **error_string)
}
static Value *
gnumeric_log10 (Value *argv [], char **error_string)
gnumeric_log10 (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
Value *v;
float_t t;
......@@ -727,7 +727,7 @@ gnumeric_or (void *tsheet, GList *expr_node_list, int eval_col, int eval_row, ch
static Value *
gnumeric_radians (Value *argv [], char **error_string)
gnumeric_radians (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
Value *v = g_new (Value, 1);
......@@ -738,7 +738,7 @@ gnumeric_radians (Value *argv [], char **error_string)
}
static Value *
gnumeric_sin (Value *argv [], char **error_string)
gnumeric_sin (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
Value *v = g_new (Value, 1);
......@@ -749,7 +749,7 @@ gnumeric_sin (Value *argv [], char **error_string)
}
static Value *
gnumeric_sinh (Value *argv [], char **error_string)
gnumeric_sinh (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
Value *v = g_new (Value, 1);
......@@ -801,7 +801,7 @@ gnumeric_sum (void *tsheet, GList *expr_node_list, int eval_col, int eval_row, c
}
static Value *
gnumeric_tan (Value *argv [], char **error_string)
gnumeric_tan (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
Value *v = g_new (Value, 1);
......@@ -812,7 +812,7 @@ gnumeric_tan (Value *argv [], char **error_string)
}
static Value *
gnumeric_tanh (Value *argv [], char **error_string)
gnumeric_tanh (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
Value *v = g_new (Value, 1);
......@@ -823,7 +823,7 @@ gnumeric_tanh (Value *argv [], char **error_string)
}
static Value *
gnumeric_pi (Value *argv [], char **error_string)
gnumeric_pi (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
Value *v = g_new (Value, 1);
......
#
# Makefile for the Python Gnumeric plugin.
#
# Where can we find the Gnumeric include files.
#
GNUMERIC_SRC_DIR = $(srcdir)/../../src
#
# Where to install the plugin
#
plugindir = $(libdir)/gnumeric/plugins
CFLAGS += -g -Wall \
-Wshadow -Wpointer-arith \
-Wmissing-prototypes -Wmissing-declarations
plugin_LTLIBRARIES = libpython.la
libpython_la_SOURCES = python.c
INCLUDES = \
-I$(GNUMERIC_SRC_DIR) \
-DGNOMELOCALEDIR=\""$(datadir)/locale"\" \
-I$(includedir) \
$(GNOME_INCLUDEDIR)
libpython_la_LDADD = -l$(PYTHON_LIBS)
\ No newline at end of file
/*
* Rudimentary support for Python in gnumeric.
*/
#include <glib.h>
#include <gnome.h>
#include "../../src/gnumeric.h"
#include "../../src/func.h"
#include "../../src/plugin.h"
#include "Python.h"
PyObject *codeobj = NULL;
static Value *
marshal(Value *argv[], char **error_string)
{
PyObject *args = Py_BuildValue("()");
PyObject *result;
Value *v;
g_print("marshall: activated\n");
result = PyEval_CallObject(codeobj, args);
if (!result)
return NULL;
Py_DECREF(args);
g_print("checking result\n");
v = g_new0(Value, 1);
if (PyInt_Check(result)) {
g_print("marshal: making integer value\n");
v->type = VALUE_INTEGER;
v->v.v_int = (int_t) PyInt_AsLong(result);
} else if (PyFloat_Check(result)) {
g_print("marshal: making float value\n");
v->type = VALUE_FLOAT;
v->v.v_float = (float_t) PyFloat_AsDouble(result);
} else {
PyErr_SetString(PyExc_TypeError, "unexpected return type");
g_free(v);
v = NULL;
}
Py_DECREF(result);
return v;
}
static FunctionDefinition plugin_functions [] = {
{ "plusone", "f", "number", NULL, NULL, marshal },
{ NULL, NULL },
};
static PyObject *
__register_function(PyObject *m, PyObject *args)
{
char *funcname;
if (! PyArg_ParseTuple(args, "sO", &funcname, &codeobj))
return NULL;
g_print("__register_function called (func=%s)\n", funcname);
if (! PyCallable_Check(codeobj)) {
g_print("object is not callable\n");
PyErr_SetString(PyExc_TypeError, "object must be callable");
return NULL;
}
g_print("object is callable\n");
plugin_functions[0].name = g_strdup(funcname);
g_print("installed function name\n");
install_symbols(plugin_functions);
g_print("told gnumeric about the function");
return Py_BuildValue("");
}
static PyMethodDef gnumeric_funcs[] = {
{ "register_function", __register_function, 1 },
{ NULL, NULL },
};
static void
initgnumeric(void)
{
PyImport_AddModule("gnumeric");
Py_InitModule("gnumeric", gnumeric_funcs);
g_print("gnumeric module initialized\n");
}
int
init_plugin(PluginData * pd)
{
PyObject *m, *d, *f;
/* initialize the python interpreter */
g_print("python plugin started\n");
Py_SetProgramName("gnumeric");
Py_Initialize();
/* setup standard functions */
initgnumeric();
if (PyErr_Occurred()) {
PyErr_Print();
return -1;
}
/* plugin stuff */
pd->title = g_strdup("Python Plugin");
/* run the magic python file */
{
char *homedir = getenv("HOME");
char *fname;
FILE *fp;
g_print("running python file\n");
g_warning ("FIXME: This should load a systme installed file");
fname = g_copy_strings(homedir ? homedir : "", "/.gnumeric/main.py", NULL);
fp = fopen(fname, "r");
PyRun_AnyFile(fp, fname);
g_free(fname);
g_print("done running python file\n");
}
return 0;
}
void cleanup_plugin(PluginData *pd)
{
g_free(pd->title);
Py_Finalize();
}
......@@ -408,7 +408,7 @@ eval_funcall (Sheet *sheet, ExprTree *tree, int eval_col, int eval_row, char **e
values [arg] = v;
}
v = fd->fn (values, error_string);
v = fd->fn (fd, values, error_string);
free_list:
for (i = 0; i < arg; i++)
......
......@@ -111,7 +111,8 @@ typedef enum {
* it is up to that routine to do the value computations and range
* processing.
*/
typedef struct {
struct FunctionDefinition {
/* The function name */
char *name;
......@@ -126,8 +127,10 @@ typedef struct {
char **help;
Value *(*expr_fn)(void *sheet, GList *expr_node_list, int eval_col, int eval_row, char **error_string);
Value *(*fn)(Value *argv [], char **error_string);
} FunctionDefinition;
Value *(*fn)(struct FunctionDefinition *func_def, Value *argv [], char **error_string);
};
typedef struct FunctionDefinition FunctionDefinition;
/* For communication with yyparse */
extern char *parser_expr;
......
......@@ -23,7 +23,7 @@ static Value *gnumeric_count (void *tsheet, GList *expr_node_list,
char **error_string);
static Value *
gnumeric_abs (Value *argv [], char **error_string)
gnumeric_abs (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
Value *v = g_new (Value, 1);
......@@ -34,7 +34,7 @@ gnumeric_abs (Value *argv [], char **error_string)
}
static Value *
gnumeric_acos (Value *argv [], char **error_string)
gnumeric_acos (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
Value *v;
float_t t;
......@@ -52,7 +52,7 @@ gnumeric_acos (Value *argv [], char **error_string)
}
static Value *
gnumeric_acosh (Value *argv [], char **error_string)
gnumeric_acosh (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
Value *v;
float_t t;
......@@ -208,7 +208,7 @@ gnumeric_and (void *tsheet, GList *expr_node_list, int eval_col, int eval_row, c
}
static Value *
gnumeric_asin (Value *argv [], char **error_string)
gnumeric_asin (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
Value *v;
float_t t;
......@@ -226,7 +226,7 @@ gnumeric_asin (Value *argv [], char **error_string)
}
static Value *
gnumeric_asinh (Value *argv [], char **error_string)
gnumeric_asinh (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
Value *v;
......@@ -238,7 +238,7 @@ gnumeric_asinh (Value *argv [], char **error_string)
}
static Value *
gnumeric_atan (Value *argv [], char **error_string)
gnumeric_atan (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
Value *v = g_new (Value, 1);
......@@ -249,7 +249,7 @@ gnumeric_atan (Value *argv [], char **error_string)
}
static Value *
gnumeric_atanh (Value *argv [], char **error_string)
gnumeric_atanh (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
Value *v = g_new (Value, 1);
float_t t;
......@@ -266,7 +266,7 @@ gnumeric_atanh (Value *argv [], char **error_string)
}
static Value *
gnumeric_atan2 (Value *argv [], char **error_string)
gnumeric_atan2 (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
Value *v = g_new (Value, 1);
......@@ -316,7 +316,7 @@ gnumeric_average (void *tsheet, GList *expr_node_list, int eval_col, int eval_ro
}
static Value *
gnumeric_ceil (Value *argv [], char **error_string)
gnumeric_ceil (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
Value *v = g_new (Value, 1);
......@@ -327,7 +327,7 @@ gnumeric_ceil (Value *argv [], char **error_string)
}