Commit a30e70c3 authored by Arturo Espinosa's avatar Arturo Espinosa

Weee! Regular strings are now treated as values (so they can be used in



Weee!  Regular strings are now treated as values (so they
can be used in cell expressions).  This means you can actually
start typing expressions and they will actually make sense
(note that no recalc is yet supported).

The code to do interactive selections is there, but for some
reason the cursor is not paying much attention to me.

This feature lets you select a cell for an expression if you
type in a formula in the spreadsheet (just type '=' and use
the arrow keys to see my buggy code).
parent a77a36a4
1998-07-25 Miguel de Icaza <miguel@redhat.com>
* src/item-cursor.c (item_cursor_draw): Minimal code to support
the anted-cursor. There is a bug, I just dont know where :-)
* src/gnumeric-sheet.c (gnumeric_sheet_key): Added support for
selecting cell values with the cursor keys.
(start_cell_selection): Starts the interactive selection of a cell
(stop_cell_selection): Stops the interactive selection of a cell.
(selection_remove_selection_string): Removes the text that has
been inserted into the text line for selection purposes.
(selection_insert_selection_string): Updates the entry with the
contents of the selection range.
(selection_expand_vertical, selection_expand_horizontal): Expands
the selection.
* src/item-cursor.h (item_cursor_set_bounds): Change prototype to
reflect actual argument names. I was a victim of my own lazyness.
* src/gnumeric-sheet.c (move_cursor_vertical, move_cursor,
move_cursor_horizontal): Renamed to allow formatting in 80
columns.
* src/utils.c (cell_name): New routine. Renders a cell name.
* src/sheet.h (IS_SHEET): Added a signature to Sheet strucutres
and a signature to test with.
* src/symbol.c (symbol_ref_string): New function: it makes sure a
symbol exists: it either increases the refcount for an existing
string, or creates it.
1998-07-24 Miguel de Icaza <miguel@redhat.com>
* src/workbook.c (workbook_get_current_sheet): New function.
* src/sheet.c (cell_set_formula): New function. Loads a cell with
a formula.
* src/parser.y (eval_value_string): New routine to return a string
representation of a Value *. This should use the format.c that
Chris is working on, but we need Chris to commit his changes ;-).
For now it uses %d and %g.
* src/numbers.h: Compatibility functions to make the code work
with or without GMP.
* src/gnumeric-sheet.c (gnumeric_sheet_set_current_value): Sets
the value to whatever happens to be on the input line.
* src/expr.c (eval_cast_to_float): New function: casts a value to
float.
(eval_cell_value): new function.
(eval_node_value): evaluates the expression tree.
* src/cell.h: Keep the computed value as well.
Sat Jul 25 14:10:23 1998 Tom Tromey <tromey@cygnus.com>
* src/Makefile.am (test_parser_LDADD): Added INTLLIBS.
......
1998-07-25 Miguel de Icaza <miguel@redhat.com>
* src/item-cursor.c (item_cursor_draw): Minimal code to support
the anted-cursor. There is a bug, I just dont know where :-)
* src/gnumeric-sheet.c (gnumeric_sheet_key): Added support for
selecting cell values with the cursor keys.
(start_cell_selection): Starts the interactive selection of a cell
(stop_cell_selection): Stops the interactive selection of a cell.
(selection_remove_selection_string): Removes the text that has
been inserted into the text line for selection purposes.
(selection_insert_selection_string): Updates the entry with the
contents of the selection range.
(selection_expand_vertical, selection_expand_horizontal): Expands
the selection.
* src/item-cursor.h (item_cursor_set_bounds): Change prototype to
reflect actual argument names. I was a victim of my own lazyness.
* src/gnumeric-sheet.c (move_cursor_vertical, move_cursor,
move_cursor_horizontal): Renamed to allow formatting in 80
columns.
* src/utils.c (cell_name): New routine. Renders a cell name.
* src/sheet.h (IS_SHEET): Added a signature to Sheet strucutres
and a signature to test with.
* src/symbol.c (symbol_ref_string): New function: it makes sure a
symbol exists: it either increases the refcount for an existing
string, or creates it.
1998-07-24 Miguel de Icaza <miguel@redhat.com>
* src/workbook.c (workbook_get_current_sheet): New function.
* src/sheet.c (cell_set_formula): New function. Loads a cell with
a formula.
* src/parser.y (eval_value_string): New routine to return a string
representation of a Value *. This should use the format.c that
Chris is working on, but we need Chris to commit his changes ;-).
For now it uses %d and %g.
* src/numbers.h: Compatibility functions to make the code work
with or without GMP.
* src/gnumeric-sheet.c (gnumeric_sheet_set_current_value): Sets
the value to whatever happens to be on the input line.
* src/expr.c (eval_cast_to_float): New function: casts a value to
float.
(eval_cell_value): new function.
(eval_node_value): evaluates the expression tree.
* src/cell.h: Keep the computed value as well.
Sat Jul 25 14:10:23 1998 Tom Tromey <tromey@cygnus.com>
* src/Makefile.am (test_parser_LDADD): Added INTLLIBS.
......
1998-07-25 Miguel de Icaza <miguel@redhat.com>
* src/item-cursor.c (item_cursor_draw): Minimal code to support
the anted-cursor. There is a bug, I just dont know where :-)
* src/gnumeric-sheet.c (gnumeric_sheet_key): Added support for
selecting cell values with the cursor keys.
(start_cell_selection): Starts the interactive selection of a cell
(stop_cell_selection): Stops the interactive selection of a cell.
(selection_remove_selection_string): Removes the text that has
been inserted into the text line for selection purposes.
(selection_insert_selection_string): Updates the entry with the
contents of the selection range.
(selection_expand_vertical, selection_expand_horizontal): Expands
the selection.
* src/item-cursor.h (item_cursor_set_bounds): Change prototype to
reflect actual argument names. I was a victim of my own lazyness.
* src/gnumeric-sheet.c (move_cursor_vertical, move_cursor,
move_cursor_horizontal): Renamed to allow formatting in 80
columns.
* src/utils.c (cell_name): New routine. Renders a cell name.
* src/sheet.h (IS_SHEET): Added a signature to Sheet strucutres
and a signature to test with.
* src/symbol.c (symbol_ref_string): New function: it makes sure a
symbol exists: it either increases the refcount for an existing
string, or creates it.
1998-07-24 Miguel de Icaza <miguel@redhat.com>
* src/workbook.c (workbook_get_current_sheet): New function.
* src/sheet.c (cell_set_formula): New function. Loads a cell with
a formula.
* src/parser.y (eval_value_string): New routine to return a string
representation of a Value *. This should use the format.c that
Chris is working on, but we need Chris to commit his changes ;-).
For now it uses %d and %g.
* src/numbers.h: Compatibility functions to make the code work
with or without GMP.
* src/gnumeric-sheet.c (gnumeric_sheet_set_current_value): Sets
the value to whatever happens to be on the input line.
* src/expr.c (eval_cast_to_float): New function: casts a value to
float.
(eval_cell_value): new function.
(eval_node_value): evaluates the expression tree.
* src/cell.h: Keep the computed value as well.
Sat Jul 25 14:10:23 1998 Tom Tromey <tromey@cygnus.com>
* src/Makefile.am (test_parser_LDADD): Added INTLLIBS.
......
1998-07-25 Miguel de Icaza <miguel@redhat.com>
* src/item-cursor.c (item_cursor_draw): Minimal code to support
the anted-cursor. There is a bug, I just dont know where :-)
* src/gnumeric-sheet.c (gnumeric_sheet_key): Added support for
selecting cell values with the cursor keys.
(start_cell_selection): Starts the interactive selection of a cell
(stop_cell_selection): Stops the interactive selection of a cell.
(selection_remove_selection_string): Removes the text that has
been inserted into the text line for selection purposes.
(selection_insert_selection_string): Updates the entry with the
contents of the selection range.
(selection_expand_vertical, selection_expand_horizontal): Expands
the selection.
* src/item-cursor.h (item_cursor_set_bounds): Change prototype to
reflect actual argument names. I was a victim of my own lazyness.
* src/gnumeric-sheet.c (move_cursor_vertical, move_cursor,
move_cursor_horizontal): Renamed to allow formatting in 80
columns.
* src/utils.c (cell_name): New routine. Renders a cell name.
* src/sheet.h (IS_SHEET): Added a signature to Sheet strucutres
and a signature to test with.
* src/symbol.c (symbol_ref_string): New function: it makes sure a
symbol exists: it either increases the refcount for an existing
string, or creates it.
1998-07-24 Miguel de Icaza <miguel@redhat.com>
* src/workbook.c (workbook_get_current_sheet): New function.
* src/sheet.c (cell_set_formula): New function. Loads a cell with
a formula.
* src/parser.y (eval_value_string): New routine to return a string
representation of a Value *. This should use the format.c that
Chris is working on, but we need Chris to commit his changes ;-).
For now it uses %d and %g.
* src/numbers.h: Compatibility functions to make the code work
with or without GMP.
* src/gnumeric-sheet.c (gnumeric_sheet_set_current_value): Sets
the value to whatever happens to be on the input line.
* src/expr.c (eval_cast_to_float): New function: casts a value to
float.
(eval_cell_value): new function.
(eval_node_value): evaluates the expression tree.
* src/cell.h: Keep the computed value as well.
Sat Jul 25 14:10:23 1998 Tom Tromey <tromey@cygnus.com>
* src/Makefile.am (test_parser_LDADD): Added INTLLIBS.
......
......@@ -49,7 +49,7 @@ typedef struct {
int flags;
} Cell;
#define CELL_TEXT_GET(cell) ((cell)->text ? cell->text : cell->entered_text)
#define CELL_IS_FORMULA(cell) (cell->entered_text [0] == '=')
#endif /* GNUMERIC_CELL_H */
......
......@@ -11,6 +11,7 @@
#include <gnome.h>
#include <gdk/gdkkeysyms.h>
#include <gdk/gdkx.h>
#include <string.h>
#include "gnumeric.h"
#include "gnumeric-sheet.h"
......@@ -158,7 +159,7 @@ start_editing_at_cursor (GnumericSheet *sheet, GtkWidget *entry)
}
/*
* gnumeric_sheet_move_cursor:
* move_cursor:
* @Sheet: The sheet where the cursor is located
* @col: The new column for the cursor.
* @row: The new row for the cursor.
......@@ -168,7 +169,7 @@ start_editing_at_cursor (GnumericSheet *sheet, GtkWidget *entry)
* cursor.
*/
static void
gnumeric_sheet_move_cursor (GnumericSheet *sheet, int col, int row)
move_cursor (GnumericSheet *sheet, int col, int row)
{
ItemCursor *item_cursor = sheet->item_cursor;
......@@ -180,14 +181,14 @@ gnumeric_sheet_move_cursor (GnumericSheet *sheet, int col, int row)
}
/*
* gnumeric_sheet_move_cursor_horizontal:
* move_cursor_horizontal:
* @Sheet: The sheet name
* @count: number of units to move the cursor horizontally
*
* Moves the cursor count columns
*/
static void
gnumeric_sheet_move_cursor_horizontal (GnumericSheet *sheet, int count)
move_cursor_horizontal (GnumericSheet *sheet, int count)
{
int new_left;
......@@ -204,18 +205,18 @@ gnumeric_sheet_move_cursor_horizontal (GnumericSheet *sheet, int count)
if (new_left < 0)
new_left = 0;
gnumeric_sheet_move_cursor (sheet, new_left, sheet->cursor_row);
move_cursor (sheet, new_left, sheet->cursor_row);
}
/*
* gnumeric_sheet_move_cursor_vertical:
* move_cursor_vertical:
* @Sheet: The sheet name
* @count: number of units to move the cursor vertically
*
* Moves the cursor count rows
*/
static void
gnumeric_sheet_move_cursor_vertical (GnumericSheet *sheet, int count)
move_cursor_vertical (GnumericSheet *sheet, int count)
{
int new_top;
......@@ -229,21 +230,237 @@ gnumeric_sheet_move_cursor_vertical (GnumericSheet *sheet, int count)
return;
}
gnumeric_sheet_move_cursor (sheet, sheet->cursor_col, new_top);
move_cursor (sheet, sheet->cursor_col, new_top);
}
static void
gnumeric_sheet_move_horizontal_selection (GnumericSheet *gsheet, int count)
move_horizontal_selection (GnumericSheet *gsheet, int count)
{
sheet_selection_extend_horizontal (gsheet->sheet, count);
}
static void
gnumeric_sheet_move_vertical_selection (GnumericSheet *gsheet, int count)
move_vertical_selection (GnumericSheet *gsheet, int count)
{
sheet_selection_extend_vertical (gsheet->sheet, count);
}
/*
* gnumeric_sheet_can_move_cursor
* @gsheet: the object
*
* Returns true if the cursor keys should be used to select
* a cell range (if the cursor is in a spot in the expression
* where it makes sense to have a cell reference), false if not.
*/
static int
gnumeric_sheet_can_move_cursor (GnumericSheet *gsheet)
{
GtkEntry *entry = GTK_ENTRY (gsheet->entry);
int cursor_pos = GTK_EDITABLE (entry)->current_pos;
if (gsheet->selecting_cell)
return TRUE;
if (entry->text [0] != '=')
return FALSE;
if (cursor_pos == 0)
return FALSE;
switch (entry->text [cursor_pos-1]){
case '=': case '-': case '*': case '/': case '^':
case '+': case '&': case '(': case '%': case '!':
return TRUE;
}
return FALSE;
}
static void
start_cell_selection (GnumericSheet *gsheet)
{
GnomeCanvas *canvas = GNOME_CANVAS (gsheet);
GnomeCanvasGroup *group = GNOME_CANVAS_GROUP (canvas->root);
g_return_if_fail (gsheet->selecting_cell == FALSE);
gsheet->selecting_cell = TRUE;
gsheet->selection = ITEM_CURSOR (gnome_canvas_item_new (
group,
item_cursor_get_type (),
"Sheet", gsheet->sheet,
"Grid", gsheet->item_grid,
"Style", ITEM_CURSOR_ANTED, NULL));
gsheet->sel_cursor_pos = GTK_EDITABLE (gsheet->entry)->current_pos;
gsheet->sel_text_len = 0;
}
static void
stop_cell_selection (GnumericSheet *gsheet)
{
if (!gsheet->selecting_cell)
return;
gsheet->selecting_cell = FALSE;
gtk_object_destroy (GTK_OBJECT (gsheet->selection));
gsheet->selection = NULL;
}
static void
selection_remove_selection_string (GnumericSheet *gsheet)
{
gtk_editable_delete_text (GTK_EDITABLE (gsheet->entry),
gsheet->sel_cursor_pos,
gsheet->sel_cursor_pos+gsheet->sel_text_len);
}
static void
selection_insert_selection_string (GnumericSheet *gsheet)
{
ItemCursor *sel = gsheet->selection;
char buffer [20];
int pos;
/* Get the new selection string */
strcpy (buffer, cell_name (sel->start_col, sel->start_row));
if (!(sel->start_col == sel->end_col && sel->start_row == sel->end_row)){
strcat (buffer, ":");
strcat (buffer, cell_name (sel->end_col, sel->end_row));
}
gsheet->sel_text_len = strlen (buffer);
pos = gsheet->sel_cursor_pos;
gtk_editable_insert_text (GTK_EDITABLE (gsheet->entry),
buffer, strlen (buffer),
&pos);
/* Set the cursor at the end. It looks nicer */
gtk_editable_set_position (GTK_EDITABLE (gsheet->entry),
gsheet->sel_cursor_pos +
gsheet->sel_text_len);
}
static void
selection_cursor_move_horizontal (GnumericSheet *gsheet, int dir)
{
ItemCursor *ic;
g_return_if_fail (dir == -1 || dir == 1);
if (!gsheet->selecting_cell)
start_cell_selection (gsheet);
ic = gsheet->selection;
if (dir == -1){
if (ic->start_col == 0)
return;
} else {
if (ic->end_col + 1 > (SHEET_MAX_COLS-1))
return;
}
selection_remove_selection_string (gsheet);
item_cursor_set_bounds (ic,
ic->start_col + dir,
ic->start_row,
ic->end_col + dir,
ic->end_row);
selection_insert_selection_string (gsheet);
}
static void
selection_cursor_move_vertical (GnumericSheet *gsheet, int dir)
{
ItemCursor *ic;
g_return_if_fail (dir == -1 || dir == 1);
if (!gsheet->selecting_cell)
start_cell_selection (gsheet);
ic = gsheet->selection;
if (dir == -1){
if (ic->start_row == 0)
return;
} else {
if (ic->end_row + 1 > (SHEET_MAX_ROWS-1))
return;
}
if (!gsheet->selecting_cell)
start_cell_selection (gsheet);
item_cursor_set_bounds (ic,
ic->start_col, ic->start_row + dir,
ic->end_col, ic->end_row + dir);
selection_remove_selection_string (gsheet);
selection_insert_selection_string (gsheet);
}
static void
selection_expand_horizontal (GnumericSheet *gsheet, int dir)
{
ItemCursor *ic;
g_return_if_fail (dir == -1 || dir == 1);
if (!gsheet->selecting_cell){
selection_cursor_move_vertical (gsheet, dir);
return;
}
ic = gsheet->selection;
if (dir == -1){
if (ic->start_col == 0)
return;
} else {
if (ic->end_col == SHEET_MAX_COLS-1)
return;
}
selection_remove_selection_string (gsheet);
item_cursor_set_bounds (ic,
ic->start_col + (dir == -1 ? dir : 0),
ic->start_row,
ic->end_col + (dir == 1 ? dir : 0),
ic->end_row);
selection_insert_selection_string (gsheet);
}
static void
selection_expand_vertical (GnumericSheet *gsheet, int dir)
{
ItemCursor *ic;
g_return_if_fail (dir == -1 || dir == 1);
if (!gsheet->selecting_cell){
selection_cursor_move_vertical (gsheet, dir);
return;
}
ic = gsheet->selection;
if (dir == -1){
if (ic->start_row == 0)
return;
} else {
if (ic->end_row == SHEET_MAX_ROWS-1)
return;
}
selection_remove_selection_string (gsheet);
item_cursor_set_bounds (ic,
ic->start_col,
ic->start_row + (dir == -1 ? dir : 0),
ic->end_col,
ic->end_row + (dir == 1 ? dir : 0));
selection_insert_selection_string (gsheet);
}
/*
* key press event handler for the gnumeric sheet
*/
static gint
gnumeric_sheet_key (GtkWidget *widget, GdkEventKey *event)
{
......@@ -251,14 +468,26 @@ gnumeric_sheet_key (GtkWidget *widget, GdkEventKey *event)
Workbook *wb = sheet->sheet->parent_workbook;
void (*movefn_horizontal) (GnumericSheet *, int);
void (*movefn_vertical) (GnumericSheet *, int);
int cursor_move = gnumeric_sheet_can_move_cursor (sheet);
printf ("%d\n", cursor_move);
if ((event->state & GDK_SHIFT_MASK) != 0){
movefn_horizontal = gnumeric_sheet_move_horizontal_selection;
movefn_vertical = gnumeric_sheet_move_vertical_selection;
if (cursor_move){
printf ("Selection exand!\n");
movefn_horizontal = selection_expand_horizontal;
movefn_vertical = selection_expand_vertical;
} else {
movefn_horizontal = move_horizontal_selection;
movefn_vertical = move_vertical_selection;
}
} else {
movefn_horizontal = gnumeric_sheet_move_cursor_horizontal;
movefn_vertical = gnumeric_sheet_move_cursor_vertical;
if (cursor_move){
movefn_horizontal = selection_cursor_move_horizontal;
movefn_vertical = selection_cursor_move_vertical;
} else {
movefn_horizontal = move_cursor_horizontal;
movefn_vertical = move_cursor_vertical;
}
}
switch (event->keyval){
......@@ -279,7 +508,7 @@ gnumeric_sheet_key (GtkWidget *widget, GdkEventKey *event)
break;
case GDK_Return:
gnumeric_sheet_move_cursor (sheet, sheet->cursor_col, sheet->cursor_row);
move_cursor (sheet, sheet->cursor_col, sheet->cursor_row);
break;
case GDK_F2:
......@@ -291,7 +520,8 @@ gnumeric_sheet_key (GtkWidget *widget, GdkEventKey *event)
if (event->keyval >= 0x20 && event->keyval <= 0xff)
start_editing_at_cursor (sheet, wb->ea_input);
}
stop_cell_selection (sheet);
/* Forward the keystroke to the input line */
gtk_widget_event (sheet->entry, (GdkEvent *) event);
......
......@@ -25,9 +25,18 @@ typedef struct {
ItemCursor *item_cursor;
ItemBar *item_bar_col;
ItemEdit *item_editor;
/* This flag keeps track of a cell selector
* (ie, when the user uses the cursor keys
* to select a cell for an expression).
*/
int selecting_cell;
int sel_cursor_pos;
int sel_text_len;
ItemCursor *selection;
} GnumericSheet;
GtkType gnumeric_sheet_get_type (void);
GtkType gnumeric_sheet_get_type (void);
GtkWidget *gnumeric_sheet_new (Sheet *sheet);
void gnumeric_sheet_set_selection (GnumericSheet *sheet, SheetSelection *ss);
......
......@@ -11,6 +11,7 @@
#include <gnome.h>
#include <gdk/gdkkeysyms.h>
#include <gdk/gdkx.h>
#include <string.h>
#include "gnumeric.h"
#include "gnumeric-sheet.h"
......@@ -158,7 +159,7 @@ start_editing_at_cursor (GnumericSheet *sheet, GtkWidget *entry)
}
/*
* gnumeric_sheet_move_cursor:
* move_cursor:
* @Sheet: The sheet where the cursor is located
* @col: The new column for the cursor.
* @row: The new row for the cursor.
......@@ -168,7 +169,7 @@ start_editing_at_cursor (GnumericSheet *sheet, GtkWidget *entry)
* cursor.
*/
static void
gnumeric_sheet_move_cursor (GnumericSheet *sheet, int col, int row)
move_cursor (GnumericSheet *sheet, int col, int row)
{
ItemCursor *item_cursor = sheet->item_cursor;
......@@ -180,14 +181,14 @@ gnumeric_sheet_move_cursor (GnumericSheet *sheet, int col, int row)
}