Commit 718822fb authored by Jakub Jelinek's avatar Jakub Jelinek Committed by Arturo Espinosa

New functions. (item_grid_event): If x or y is out of canvas bounds, do

1998-10-13  Jakub Jelinek  <jj@ultra.penguin.cz>

	* src/item-grid.c (item_grid_stop_sliding,
	item_grid_sliding_callback, item_grid_start_sliding):
	New functions.
	(item_grid_event): If x or y is out of canvas bounds,
	do sliding for both cell and formula selection.
	For button release from formula selection, make cell
	being edited visible afterwards.
	(item_grid_button_1): If not extending selection with
	shift, make cursor cell visible.

	* src/gnumeric-sheet.c (move_cursor,
	gnumeric_sheet_key_mode_sheet): Make cursor cell visible.

	* src/sheet.c (sheet_select_all): Make home visible.
	(sheet_make_cell_visible): New function.
	(sheet_cursor_move, sheet_cursor_set): Don't make cursor
	visible, caller has to do it himself if desired.

	* src/sheet.h (sheet_make_cell_visible): New prototype.

	* src/workbook.c (workbook_parse_and_jump): Make cursor
	cell visible.
parent b6008a1f
1998-10-13 Jakub Jelinek <jj@ultra.penguin.cz>
* src/item-grid.c (item_grid_stop_sliding,
item_grid_sliding_callback, item_grid_start_sliding):
New functions.
(item_grid_event): If x or y is out of canvas bounds,
do sliding for both cell and formula selection.
For button release from formula selection, make cell
being edited visible afterwards.
(item_grid_button_1): If not extending selection with
shift, make cursor cell visible.
* src/gnumeric-sheet.c (move_cursor,
gnumeric_sheet_key_mode_sheet): Make cursor cell visible.
* src/sheet.c (sheet_select_all): Make home visible.
(sheet_make_cell_visible): New function.
(sheet_cursor_move, sheet_cursor_set): Don't make cursor
visible, caller has to do it himself if desired.
* src/sheet.h (sheet_make_cell_visible): New prototype.
* src/workbook.c (workbook_parse_and_jump): Make cursor
cell visible.
1998-10-13 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/utils.c (col_name): It is amazing the number of times I
......
1998-10-13 Jakub Jelinek <jj@ultra.penguin.cz>
* src/item-grid.c (item_grid_stop_sliding,
item_grid_sliding_callback, item_grid_start_sliding):
New functions.
(item_grid_event): If x or y is out of canvas bounds,
do sliding for both cell and formula selection.
For button release from formula selection, make cell
being edited visible afterwards.
(item_grid_button_1): If not extending selection with
shift, make cursor cell visible.
* src/gnumeric-sheet.c (move_cursor,
gnumeric_sheet_key_mode_sheet): Make cursor cell visible.
* src/sheet.c (sheet_select_all): Make home visible.
(sheet_make_cell_visible): New function.
(sheet_cursor_move, sheet_cursor_set): Don't make cursor
visible, caller has to do it himself if desired.
* src/sheet.h (sheet_make_cell_visible): New prototype.
* src/workbook.c (workbook_parse_and_jump): Make cursor
cell visible.
1998-10-13 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/utils.c (col_name): It is amazing the number of times I
......
1998-10-13 Jakub Jelinek <jj@ultra.penguin.cz>
* src/item-grid.c (item_grid_stop_sliding,
item_grid_sliding_callback, item_grid_start_sliding):
New functions.
(item_grid_event): If x or y is out of canvas bounds,
do sliding for both cell and formula selection.
For button release from formula selection, make cell
being edited visible afterwards.
(item_grid_button_1): If not extending selection with
shift, make cursor cell visible.
* src/gnumeric-sheet.c (move_cursor,
gnumeric_sheet_key_mode_sheet): Make cursor cell visible.
* src/sheet.c (sheet_select_all): Make home visible.
(sheet_make_cell_visible): New function.
(sheet_cursor_move, sheet_cursor_set): Don't make cursor
visible, caller has to do it himself if desired.
* src/sheet.h (sheet_make_cell_visible): New prototype.
* src/workbook.c (workbook_parse_and_jump): Make cursor
cell visible.
1998-10-13 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/utils.c (col_name): It is amazing the number of times I
......
1998-10-13 Jakub Jelinek <jj@ultra.penguin.cz>
* src/item-grid.c (item_grid_stop_sliding,
item_grid_sliding_callback, item_grid_start_sliding):
New functions.
(item_grid_event): If x or y is out of canvas bounds,
do sliding for both cell and formula selection.
For button release from formula selection, make cell
being edited visible afterwards.
(item_grid_button_1): If not extending selection with
shift, make cursor cell visible.
* src/gnumeric-sheet.c (move_cursor,
gnumeric_sheet_key_mode_sheet): Make cursor cell visible.
* src/sheet.c (sheet_select_all): Make home visible.
(sheet_make_cell_visible): New function.
(sheet_cursor_move, sheet_cursor_set): Don't make cursor
visible, caller has to do it himself if desired.
* src/sheet.h (sheet_make_cell_visible): New prototype.
* src/workbook.c (workbook_parse_and_jump): Make cursor
cell visible.
1998-10-13 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/utils.c (col_name): It is amazing the number of times I
......
......@@ -112,7 +112,7 @@ gnumeric_sheet_cursor_set (GnumericSheet *gsheet, int col, int row)
*
* Set the current selection to cover the inclusive area delimited by
* start_col, start_row, end_col and end_row. The actual cursor is
* placed at start_col, start_row
* placed at base_col, base_row
*/
void
gnumeric_sheet_set_selection (GnumericSheet *gsheet, SheetSelection *ss)
......@@ -146,6 +146,7 @@ move_cursor (GnumericSheet *gsheet, int col, int row, gboolean clear_selection)
if (clear_selection)
sheet_selection_reset_only (sheet);
sheet_make_cell_visible (sheet, col, row);
sheet_cursor_set (sheet, col, row, col, row, col, row);
if (clear_selection)
......@@ -686,6 +687,7 @@ gnumeric_sheet_key_mode_sheet (GnumericSheet *gsheet, GdkEventKey *event)
case GDK_Home:
if ((event->state & GDK_CONTROL_MASK) != 0){
sheet_make_cell_visible (sheet, 0, 0);
sheet_cursor_move (sheet, 0, 0);
break;
} else
......
......@@ -112,7 +112,7 @@ gnumeric_sheet_cursor_set (GnumericSheet *gsheet, int col, int row)
*
* Set the current selection to cover the inclusive area delimited by
* start_col, start_row, end_col and end_row. The actual cursor is
* placed at start_col, start_row
* placed at base_col, base_row
*/
void
gnumeric_sheet_set_selection (GnumericSheet *gsheet, SheetSelection *ss)
......@@ -146,6 +146,7 @@ move_cursor (GnumericSheet *gsheet, int col, int row, gboolean clear_selection)
if (clear_selection)
sheet_selection_reset_only (sheet);
sheet_make_cell_visible (sheet, col, row);
sheet_cursor_set (sheet, col, row, col, row, col, row);
if (clear_selection)
......@@ -686,6 +687,7 @@ gnumeric_sheet_key_mode_sheet (GnumericSheet *gsheet, GdkEventKey *event)
case GDK_Home:
if ((event->state & GDK_CONTROL_MASK) != 0){
sheet_make_cell_visible (sheet, 0, 0);
sheet_cursor_move (sheet, 0, 0);
break;
} else
......
......@@ -712,10 +712,10 @@ item_cursor_autofill_event (GnomeCanvasItem *item, GdkEvent *event)
col = item_grid_find_col (item_cursor->item_grid, x, NULL);
row = item_grid_find_row (item_cursor->item_grid, y, NULL);
if (col < item_cursor->base_col)
if (col < item_cursor->base_col || col > SHEET_MAX_COLS-1)
col = item_cursor->base_col;
if (row < item_cursor->base_row)
if (row < item_cursor->base_row || row > SHEET_MAX_ROWS-1)
row = item_cursor->base_row;
if ((item_cursor->base_x - x) > (item_cursor->base_y - y)){
......
......@@ -605,8 +605,10 @@ item_grid_button_1 (Sheet *sheet, GdkEvent *event, ItemGrid *item_grid, int col,
*/
sheet_accept_pending_input (sheet);
if (!(event->button.state & GDK_SHIFT_MASK))
if (!(event->button.state & GDK_SHIFT_MASK)) {
sheet_make_cell_visible (sheet, col, row);
sheet_cursor_move (sheet, col, row);
}
if (!(event->button.state & (GDK_CONTROL_MASK|GDK_SHIFT_MASK)))
sheet_selection_reset_only (sheet);
......@@ -626,6 +628,116 @@ item_grid_button_1 (Sheet *sheet, GdkEvent *event, ItemGrid *item_grid, int col,
return 1;
}
static void
item_grid_stop_sliding (ItemGrid *item_grid)
{
if (item_grid->sliding == -1)
return;
gtk_timeout_remove (item_grid->sliding);
item_grid->sliding = -1;
}
static void
item_grid_sliding_callback (GnomeCanvasItem *item)
{
GnomeCanvas *canvas = item->canvas;
ItemGrid *item_grid = ITEM_GRID (item);
GnumericSheet *gsheet = GNUMERIC_SHEET (canvas);
int change = 0;
int col, row;
col = item_grid->sliding_col;
row = item_grid->sliding_row;
if (item_grid->sliding_x < 0){
if (gsheet->top_col){
change = 1;
if (item_grid->sliding_x >= -8)
col = 1;
else if (item_grid->sliding_x >= -16)
col = 10;
else
col = 50;
col = gsheet->top_col - col;
if (col < 0)
col = 0;
} else
col = 0;
}
if (item_grid->sliding_x > 0){
if (gsheet->last_full_col < SHEET_MAX_COLS-1){
change = 1;
if (item_grid->sliding_x <= 7)
col = 1;
else if (item_grid->sliding_x <= 14)
col = 10;
else
col = 50;
col = gsheet->last_visible_col + col;
if (col >= SHEET_MAX_COLS)
col = SHEET_MAX_COLS-1;
} else
col = SHEET_MAX_COLS-1;
}
if (item_grid->sliding_y < 0){
if (gsheet->top_row){
change = 1;
if (item_grid->sliding_y >= -8)
row = 1;
else if (item_grid->sliding_y >= -16)
row = 25;
else if (item_grid->sliding_y >= -64)
row = 250;
else
row = 1000;
row = gsheet->top_row - row;
if (row < 0)
row = 0;
} else
row = 0;
}
if (item_grid->sliding_y > 0){
if (gsheet->last_full_row < SHEET_MAX_ROWS-1){
change = 1;
if (item_grid->sliding_y <= 8)
row = 1;
else if (item_grid->sliding_y <= 16)
row = 25;
else if (item_grid->sliding_y <= 64)
row = 250;
else
row = 1000;
row = gsheet->last_visible_row + row;
if (row >= SHEET_MAX_ROWS)
row = SHEET_MAX_ROWS-1;
} else
row = SHEET_MAX_ROWS-1;
}
if (!change)
item_grid_stop_sliding (item_grid);
else {
if (item_grid->selecting == ITEM_GRID_SELECTING_CELL_RANGE)
sheet_selection_extend_to (item_grid->sheet, col, row);
else if (item_grid->selecting == ITEM_GRID_SELECTING_FORMULA_RANGE)
gnumeric_sheet_selection_extend (gsheet, col, row);
gnumeric_sheet_make_cell_visible (gsheet, col, row);
}
}
static void
item_grid_start_sliding (GnomeCanvasItem *item)
{
ItemGrid *item_grid = ITEM_GRID (item);
item_grid->sliding = gtk_timeout_add (
300, (GtkFunction)(item_grid_sliding_callback),
item);
}
/*
* Handle the selection
*/
......@@ -654,10 +766,13 @@ item_grid_event (GnomeCanvasItem *item, GdkEvent *event)
}
case GDK_BUTTON_RELEASE:
item_grid_stop_sliding (item_grid);
if (event->button.button == 1){
if (item_grid->selecting == ITEM_GRID_SELECTING_FORMULA_RANGE)
sheet_make_cell_visible (sheet, sheet->cursor_col, sheet->cursor_row);
item_grid->selecting = ITEM_GRID_NO_SELECTION;
gnome_canvas_item_ungrab (item, event->button.time);
return 1;
}
break;
......@@ -665,35 +780,83 @@ item_grid_event (GnomeCanvasItem *item, GdkEvent *event)
case GDK_MOTION_NOTIFY:
convert (canvas, event->motion.x, event->motion.y, &x, &y);
if (x < 0 || y < 0)
gnome_canvas_get_scroll_offsets (canvas, &col, &row);
if (x < col || y < row || x >= col + canvas->width || y >= row + canvas->height){
int dx = 0, dy = 0;
if (item_grid->selecting == ITEM_GRID_NO_SELECTION)
return 1;
if (x < col)
dx = x - col;
else if (x >= col + canvas->width)
dx = x - canvas->width - col;
if (y < row)
dy = y - row;
else if (y >= row + canvas->height)
dy = y - canvas->height - row;
if ((!dx || (dx < 0 && !gsheet->top_col) ||
(dx >= 0 && gsheet->last_full_col == SHEET_MAX_COLS-1)) &&
(!dy || (dy < 0 && !gsheet->top_row) ||
(dy >= 0 && gsheet->last_full_row == SHEET_MAX_ROWS-1))){
item_grid_stop_sliding (item_grid);
return 1;
}
item_grid->sliding_x = dx;
item_grid->sliding_y = dy;
if (!dx){
item_grid->sliding_col = item_grid_find_col (item_grid, x, NULL);
if (item_grid->sliding_col >= SHEET_MAX_COLS)
item_grid->sliding_col = SHEET_MAX_COLS-1;
}
if (!dy){
item_grid->sliding_row = item_grid_find_row (item_grid, y, NULL);
if (item_grid->sliding_row >= SHEET_MAX_ROWS)
item_grid->sliding_row = SHEET_MAX_ROWS-1;
}
if (item_grid->sliding != -1)
return 1;
item_grid_sliding_callback (item);
item_grid_start_sliding (item);
return 1;
}
item_grid_stop_sliding (item_grid);
col = item_grid_find_col (item_grid, x, NULL);
row = item_grid_find_row (item_grid, y, NULL);
if (item_grid->selecting == ITEM_GRID_NO_SELECTION)
return 1;
if (col > SHEET_MAX_COLS-1)
col = SHEET_MAX_COLS-1;
if (row > SHEET_MAX_ROWS-1)
row = SHEET_MAX_ROWS-1;
if (item_grid->selecting == ITEM_GRID_SELECTING_FORMULA_RANGE){
gnumeric_sheet_selection_extend (gsheet, col, row);
return 1;
}
if (item_grid->selecting == ITEM_GRID_NO_SELECTION)
return 1;
if (event->motion.x < 0)
event->motion.x = 0;
if (event->motion.y < 0)
event->motion.y = 0;
if (col > SHEET_MAX_COLS-1)
col = SHEET_MAX_COLS-1;
if (row > SHEET_MAX_ROWS-1)
row = SHEET_MAX_ROWS-1;
sheet_selection_extend_to (sheet, col, row);
return 1;
case GDK_BUTTON_PRESS:
sheet_set_mode_type (sheet, SHEET_MODE_SHEET);
item_grid_stop_sliding (item_grid);
convert (canvas, event->button.x, event->button.y, &x, &y);
col = item_grid_find_col (item_grid, x, NULL);
......@@ -733,6 +896,7 @@ item_grid_init (ItemGrid *item_grid)
item_grid->top_offset = 0;
item_grid->left_offset = 0;
item_grid->selecting = ITEM_GRID_NO_SELECTION;
item_grid->sliding = -1;
}
static void
......
......@@ -1023,6 +1023,7 @@ sheet_select_all (Sheet *sheet)
g_return_if_fail (IS_SHEET (sheet));
sheet_selection_reset_only (sheet);
sheet_make_cell_visible (sheet, 0, 0);
sheet_cursor_move (sheet, 0, 0);
sheet_selection_append_range (sheet, 0, 0, 0, 0,
SHEET_MAX_COLS-1, SHEET_MAX_ROWS-1);
......@@ -2895,6 +2896,21 @@ sheet_style_compute (Sheet *sheet, int col, int row, int *non_default)
return style_new ();
}
void
sheet_make_cell_visible (Sheet *sheet, int col, int row)
{
GList *l;
g_return_if_fail (sheet != NULL);
g_return_if_fail (IS_SHEET (sheet));
for (l = sheet->sheet_views; l; l = l->next){
GnumericSheet *gsheet = GNUMERIC_SHEET_VIEW (l->data);
gnumeric_sheet_make_cell_visible (gsheet, col, row);
}
}
void
sheet_cursor_move (Sheet *sheet, int col, int row)
{
......@@ -2912,7 +2928,6 @@ sheet_cursor_move (Sheet *sheet, int col, int row)
GnumericSheet *gsheet = GNUMERIC_SHEET_VIEW (l->data);
gnumeric_sheet_cursor_set (gsheet, col, row);
gnumeric_sheet_make_cell_visible (gsheet, col, row);
gnumeric_sheet_set_cursor_bounds (gsheet, col, row, col, row);
}
sheet_load_cell_val (sheet);
......@@ -2928,16 +2943,21 @@ sheet_cursor_set (Sheet *sheet, int base_col, int base_row, int start_col, int s
g_return_if_fail (start_col <= end_col);
g_return_if_fail (start_row <= end_row);
sheet_cursor_move (sheet, base_col, base_row);
sheet_accept_pending_input (sheet);
sheet->cursor_col = base_col;
sheet->cursor_row = base_row;
for (l = sheet->sheet_views; l; l = l->next){
GnumericSheet *gsheet = GNUMERIC_SHEET_VIEW (l->data);
gnumeric_sheet_cursor_set (gsheet, base_col, base_row);
gnumeric_sheet_set_cursor_bounds (
gsheet,
start_col, start_row,
end_col, end_row);
}
sheet_load_cell_val (sheet);
}
void
......
......@@ -153,6 +153,7 @@ void sheet_cursor_set (Sheet *sheet,
int start_col, int start_row,
int end_col, int end_row);
void sheet_cursor_move (Sheet *sheet, int col, int row);
void sheet_make_cell_visible (Sheet *sheet, int col, int row);
/* Selection management */
void sheet_select_all (Sheet *sheet);
......
......@@ -815,7 +815,8 @@ workbook_parse_and_jump (Workbook *wb, char *text)
gnumeric_notice (_("Row number out of range"));
return FALSE;
}
sheet_make_cell_visible (sheet, col, row);
sheet_cursor_move (sheet, col, row);
return TRUE;
}
......
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