Commit f17355a6 authored by Arturo Espinosa's avatar Arturo Espinosa

Ok, fixed cell movement



Ok, fixed cell movement
parent d3e1a06d
1998-08-22 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet.c (sheet_redraw_all): Redraw also the column and row
bars.
(sheet_insert_row): Fix. I was accessing the wrong information.
* src/dialog-insert-cells.c (dialog_insert_cells): Learn to use
GtkCauldroun's way of dealing with radio buttons.
* src/sheet.c (sheet_selection_paste): Now the clipboard fills the
region which is the union of the current selection and the
information in the clipboard.
* src/clipboard.c (clipboard_paste_region): Check the region where
we pasted for possible dependencies, and if so, queue a recalc.
(clipboard_paste_region): It now takes a region to be filled
instead of just using the contents of the clipboard.
* src/eval.c (search_cell_deps): Updated to search on cell ranges
instead of a single cell.
(region_get_dependencies): Get dependencies for a complete
region.
(cell_get_dependencies): Reworked to use new scheme
1998-08-21 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/dialog-insert-cells.c: New file. Handle the insert cells
......
1998-08-22 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet.c (sheet_redraw_all): Redraw also the column and row
bars.
(sheet_insert_row): Fix. I was accessing the wrong information.
* src/dialog-insert-cells.c (dialog_insert_cells): Learn to use
GtkCauldroun's way of dealing with radio buttons.
* src/sheet.c (sheet_selection_paste): Now the clipboard fills the
region which is the union of the current selection and the
information in the clipboard.
* src/clipboard.c (clipboard_paste_region): Check the region where
we pasted for possible dependencies, and if so, queue a recalc.
(clipboard_paste_region): It now takes a region to be filled
instead of just using the contents of the clipboard.
* src/eval.c (search_cell_deps): Updated to search on cell ranges
instead of a single cell.
(region_get_dependencies): Get dependencies for a complete
region.
(cell_get_dependencies): Reworked to use new scheme
1998-08-21 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/dialog-insert-cells.c: New file. Handle the insert cells
......
1998-08-22 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet.c (sheet_redraw_all): Redraw also the column and row
bars.
(sheet_insert_row): Fix. I was accessing the wrong information.
* src/dialog-insert-cells.c (dialog_insert_cells): Learn to use
GtkCauldroun's way of dealing with radio buttons.
* src/sheet.c (sheet_selection_paste): Now the clipboard fills the
region which is the union of the current selection and the
information in the clipboard.
* src/clipboard.c (clipboard_paste_region): Check the region where
we pasted for possible dependencies, and if so, queue a recalc.
(clipboard_paste_region): It now takes a region to be filled
instead of just using the contents of the clipboard.
* src/eval.c (search_cell_deps): Updated to search on cell ranges
instead of a single cell.
(region_get_dependencies): Get dependencies for a complete
region.
(cell_get_dependencies): Reworked to use new scheme
1998-08-21 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/dialog-insert-cells.c: New file. Handle the insert cells
......
1998-08-22 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet.c (sheet_redraw_all): Redraw also the column and row
bars.
(sheet_insert_row): Fix. I was accessing the wrong information.
* src/dialog-insert-cells.c (dialog_insert_cells): Learn to use
GtkCauldroun's way of dealing with radio buttons.
* src/sheet.c (sheet_selection_paste): Now the clipboard fills the
region which is the union of the current selection and the
information in the clipboard.
* src/clipboard.c (clipboard_paste_region): Check the region where
we pasted for possible dependencies, and if so, queue a recalc.
(clipboard_paste_region): It now takes a region to be filled
instead of just using the contents of the clipboard.
* src/eval.c (search_cell_deps): Updated to search on cell ranges
instead of a single cell.
(region_get_dependencies): Get dependencies for a complete
region.
(cell_get_dependencies): Reworked to use new scheme
1998-08-21 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/dialog-insert-cells.c: New file. Handle the insert cells
......
......@@ -186,6 +186,11 @@ PM/pm/p/p "AM", "am", "M" or "a" for the hours between midnight
Implement style regions.
Implement style resolution at cell creation time.
* Selection
Make the selection work by drawing with the invert or the xor
operations instead of drawing and redrawing on top with the text.
* Workbooks:
** Notebook:
......
......@@ -98,11 +98,16 @@ paste_cell (Sheet *dest_sheet, Cell *new_cell, int target_col, int target_row, i
}
void
clipboard_paste_region (CellRegion *region, Sheet *dest_sheet, int dest_col, int dest_row, int paste_flags)
clipboard_paste_region (CellRegion *region, Sheet *dest_sheet,
int dest_col, int dest_row,
int paste_width, int paste_height,
int paste_flags)
{
CellCopyList *l;
GList *deps;
int formulas = 0;
int col, row;
g_return_if_fail (region != NULL);
g_return_if_fail (dest_sheet != NULL);
g_return_if_fail (IS_SHEET (dest_sheet));
......@@ -110,31 +115,56 @@ clipboard_paste_region (CellRegion *region, Sheet *dest_sheet, int dest_col, int
/* Clear the region where we will paste */
sheet_clear_region (dest_sheet,
dest_col, dest_row,
dest_col + region->cols - 1,
dest_row + region->rows - 1);
dest_col + paste_width - 1,
dest_row + paste_height - 1);
/* If no operations are defined, we clear the area */
if (!(paste_flags & PASTE_OP_MASK))
sheet_redraw_cell_region (dest_sheet,
dest_col, dest_row,
dest_col + region->cols - 1,
dest_row + region->rows - 1);
dest_col + paste_width - 1,
dest_row + paste_height - 1);
/* Paste each element */
for (l = region->list; l; l = l->next){
CellCopy *c_copy = l->data;
Cell *new_cell;
int target_col, target_row;
target_col = dest_col + c_copy->col_offset;
target_row = dest_row + c_copy->row_offset;
new_cell = cell_copy (c_copy->cell);
formulas |= paste_cell (dest_sheet, new_cell, target_col, target_row, paste_flags);
for (col = 0; col < paste_width; col += region->cols){
for (row = 0; row < paste_height; row += region->rows){
for (l = region->list; l; l = l->next){
CellCopy *c_copy = l->data;
Cell *new_cell;
int target_col, target_row;
target_col = col + dest_col + c_copy->col_offset;
target_row = row + dest_row + c_copy->row_offset;
if (target_col > dest_col + paste_width - 1)
continue;
if (target_row > dest_row + paste_height - 1)
continue;
new_cell = cell_copy (c_copy->cell);
formulas |= paste_cell (
dest_sheet, new_cell,
target_col, target_row, paste_flags);
}
}
}
deps = region_get_dependencies (
dest_sheet,
dest_col, dest_row,
dest_col + paste_width - 1,
dest_row + paste_height -1);
if (deps){
cell_queue_recalc_list (deps);
formulas = 1;
}
/* Trigger a recompute */
/* Trigger a recompute if required */
if (formulas)
workbook_recalc (dest_sheet->workbook);
}
......
......@@ -25,6 +25,8 @@ void clipboard_paste_region (CellRegion *region,
Sheet *dest_sheet,
int dest_col,
int dest_row,
int paste_width,
int paste_height,
int paste_flags);
void clipboard_release (CellRegion *region);
......
......@@ -286,26 +286,39 @@ cell_drop_dependencies (Cell *cell)
}
typedef struct {
int col;
int row;
int start_col, start_row;
int end_col, end_row;
Sheet *sheet;
GList *list;
} get_dep_closure_t;
static gboolean
intersects (Sheet *sheet, int col, int row, DependencyRange *range)
{
if ((col >= range->start_col) &&
(col <= range->end_col) &&
(row >= range->start_row) &&
(row <= range->end_row) &&
(sheet = range->sheet))
return TRUE;
return FALSE;
}
static void
search_cell_deps (gpointer key, gpointer value, gpointer closure)
{
DependencyRange *range = key;
get_dep_closure_t *c = closure;
Sheet *sheet = c->sheet;
GList *l;
if (!((c->col >= range->start_col) &&
(c->col <= range->end_col) &&
(c->row >= range->start_row) &&
(c->row <= range->end_row) &&
(c->sheet = range->sheet)))
return;
if (!(intersects (sheet, c->start_col, c->start_row, range) ||
intersects (sheet, c->end_col, c->end_row, range) ||
intersects (sheet, c->start_col, c->end_row, range) ||
intersects (sheet, c->end_col, c->start_row, range)))
return;
for (l = range->cell_list; l; l = l->next){
Cell *cell = l->data;
......@@ -313,6 +326,26 @@ search_cell_deps (gpointer key, gpointer value, gpointer closure)
}
}
GList *
region_get_dependencies (Sheet *sheet, int start_col, int start_row, int end_col, int end_row)
{
get_dep_closure_t closure;
if (!dependency_hash)
dependency_hash_init ();
closure.start_col = start_col;
closure.start_row = start_row;
closure.end_col = end_col;
closure.end_row = end_row;
closure.sheet = sheet;
closure.list = NULL;
g_hash_table_foreach (dependency_hash, &search_cell_deps, &closure);
return closure.list;
}
GList *
cell_get_dependencies (Sheet *sheet, int col, int row)
{
......@@ -321,8 +354,10 @@ cell_get_dependencies (Sheet *sheet, int col, int row)
if (!dependency_hash)
dependency_hash_init ();
closure.col = col;
closure.row = row;
closure.start_col = col;
closure.start_row = row;
closure.end_col = col;
closure.end_row = row;
closure.sheet = sheet;
closure.list = NULL;
......
......@@ -31,6 +31,14 @@ void cell_drop_dependencies (Cell *cell);
*/
GList *cell_get_dependencies (Sheet *shet, int col, int row);
/*
* Returns a newly allocated list with Cells inside that
* depends on any values in the range specified
*/
GList *region_get_dependencies (Sheet *sheet,
int start_col, int start_row,
int end_col, int end_row);
/*
* Queue a cell or a list of cells for computation
*/
......
......@@ -12,17 +12,10 @@
#include "gnumeric-util.h"
#include "dialogs.h"
typedef enum {
CMD_SHIFT_CELLS_RIGHT,
CMD_SHIFT_CELLS_DOWN,
CMD_INSERT_ROW,
CMD_INSERT_COL
} CommandType;
void
dialog_insert_cells (Sheet *sheet)
{
CommandType state = CMD_SHIFT_CELLS_RIGHT;
int state [4] = { 1, 0, 0, 0 };
SheetSelection *ss;
char *ret;
int cols, rows;
......@@ -38,36 +31,36 @@ dialog_insert_cells (Sheet *sheet)
GTK_CAULDRON_DIALOG,
"( %[ ( %Rd // %Rd / %Rd // %Rd ) ] / ( %Bqrg || %Bqrg ) )",
_("Insert"),
_("Shift cells right"), &state,
_("Shift cells down"), &state,
_("Insert a row"), &state,
_("Insert a column"), &state,
_("Shift cells right"), &state[0],
_("Shift cells down"), &state[1],
_("Insert a row"), &state[2],
_("Insert a column"), &state[3],
GNOME_STOCK_BUTTON_OK,
GNOME_STOCK_BUTTON_CANCEL);
printf ("return: %s\n", ret);
printf ("return: %s, %d %d %d %d\n", ret, state [0], state [1], state [2], state [3]);
if (strcmp (ret, GNOME_STOCK_BUTTON_CANCEL) == 0)
return;
ss = sheet->selections->data;
cols = ss->end_col - ss->start_col + 1;
rows = ss->end_row - ss->start_row + 1;
switch (state){
case CMD_SHIFT_CELLS_RIGHT:
if (state [0]){
sheet_shift_rows (sheet, ss->start_col, ss->start_row, ss->end_row, cols);
break;
case CMD_SHIFT_CELLS_DOWN:
return;
}
if (state [1]){
sheet_shift_cols (sheet, ss->start_col, ss->end_col, ss->start_row, rows);
break;
case CMD_INSERT_COL:
sheet_insert_col (sheet, ss->start_col, cols);
break;
case CMD_INSERT_ROW:
return;
}
if (state [2]){
sheet_insert_row (sheet, ss->start_row, rows);
break;
return;
}
/* default */
sheet_insert_col (sheet, ss->start_col, cols);
}
......@@ -12,17 +12,10 @@
#include "gnumeric-util.h"
#include "dialogs.h"
typedef enum {
CMD_SHIFT_CELLS_RIGHT,
CMD_SHIFT_CELLS_DOWN,
CMD_INSERT_ROW,
CMD_INSERT_COL
} CommandType;
void
dialog_insert_cells (Sheet *sheet)
{
CommandType state = CMD_SHIFT_CELLS_RIGHT;
int state [4] = { 1, 0, 0, 0 };
SheetSelection *ss;
char *ret;
int cols, rows;
......@@ -38,36 +31,36 @@ dialog_insert_cells (Sheet *sheet)
GTK_CAULDRON_DIALOG,
"( %[ ( %Rd // %Rd / %Rd // %Rd ) ] / ( %Bqrg || %Bqrg ) )",
_("Insert"),
_("Shift cells right"), &state,
_("Shift cells down"), &state,
_("Insert a row"), &state,
_("Insert a column"), &state,
_("Shift cells right"), &state[0],
_("Shift cells down"), &state[1],
_("Insert a row"), &state[2],
_("Insert a column"), &state[3],
GNOME_STOCK_BUTTON_OK,
GNOME_STOCK_BUTTON_CANCEL);
printf ("return: %s\n", ret);
printf ("return: %s, %d %d %d %d\n", ret, state [0], state [1], state [2], state [3]);
if (strcmp (ret, GNOME_STOCK_BUTTON_CANCEL) == 0)
return;
ss = sheet->selections->data;
cols = ss->end_col - ss->start_col + 1;
rows = ss->end_row - ss->start_row + 1;
switch (state){
case CMD_SHIFT_CELLS_RIGHT:
if (state [0]){
sheet_shift_rows (sheet, ss->start_col, ss->start_row, ss->end_row, cols);
break;
case CMD_SHIFT_CELLS_DOWN:
return;
}
if (state [1]){
sheet_shift_cols (sheet, ss->start_col, ss->end_col, ss->start_row, rows);
break;
case CMD_INSERT_COL:
sheet_insert_col (sheet, ss->start_col, cols);
break;
case CMD_INSERT_ROW:
return;
}
if (state [2]){
sheet_insert_row (sheet, ss->start_row, rows);
break;
return;
}
/* default */
sheet_insert_col (sheet, ss->start_col, cols);
}
......@@ -286,26 +286,39 @@ cell_drop_dependencies (Cell *cell)
}
typedef struct {
int col;
int row;
int start_col, start_row;
int end_col, end_row;
Sheet *sheet;
GList *list;
} get_dep_closure_t;
static gboolean
intersects (Sheet *sheet, int col, int row, DependencyRange *range)
{
if ((col >= range->start_col) &&
(col <= range->end_col) &&
(row >= range->start_row) &&
(row <= range->end_row) &&
(sheet = range->sheet))
return TRUE;
return FALSE;
}
static void
search_cell_deps (gpointer key, gpointer value, gpointer closure)
{
DependencyRange *range = key;
get_dep_closure_t *c = closure;
Sheet *sheet = c->sheet;
GList *l;
if (!((c->col >= range->start_col) &&
(c->col <= range->end_col) &&
(c->row >= range->start_row) &&
(c->row <= range->end_row) &&
(c->sheet = range->sheet)))
return;
if (!(intersects (sheet, c->start_col, c->start_row, range) ||
intersects (sheet, c->end_col, c->end_row, range) ||
intersects (sheet, c->start_col, c->end_row, range) ||
intersects (sheet, c->end_col, c->start_row, range)))
return;
for (l = range->cell_list; l; l = l->next){
Cell *cell = l->data;
......@@ -313,6 +326,26 @@ search_cell_deps (gpointer key, gpointer value, gpointer closure)
}
}
GList *
region_get_dependencies (Sheet *sheet, int start_col, int start_row, int end_col, int end_row)
{
get_dep_closure_t closure;
if (!dependency_hash)
dependency_hash_init ();
closure.start_col = start_col;
closure.start_row = start_row;
closure.end_col = end_col;
closure.end_row = end_row;
closure.sheet = sheet;
closure.list = NULL;
g_hash_table_foreach (dependency_hash, &search_cell_deps, &closure);
return closure.list;
}
GList *
cell_get_dependencies (Sheet *sheet, int col, int row)
{
......@@ -321,8 +354,10 @@ cell_get_dependencies (Sheet *sheet, int col, int row)
if (!dependency_hash)
dependency_hash_init ();
closure.col = col;
closure.row = row;
closure.start_col = col;
closure.start_row = row;
closure.end_col = col;
closure.end_row = row;
closure.sheet = sheet;
closure.list = NULL;
......
......@@ -31,6 +31,14 @@ void cell_drop_dependencies (Cell *cell);
*/
GList *cell_get_dependencies (Sheet *shet, int col, int row);
/*
* Returns a newly allocated list with Cells inside that
* depends on any values in the range specified
*/
GList *region_get_dependencies (Sheet *sheet,
int start_col, int start_row,
int end_col, int end_row);
/*
* Queue a cell or a list of cells for computation
*/
......
......@@ -22,6 +22,12 @@ sheet_redraw_all (Sheet *sheet)
gnome_canvas_request_redraw (
GNOME_CANVAS (sheet->sheet_view),
0, 0, INT_MAX, INT_MAX);
gnome_canvas_request_redraw (
GNOME_CANVAS (sheet->col_canvas),
0, 0, INT_MAX, INT_MAX);
gnome_canvas_request_redraw (
GNOME_CANVAS (sheet->row_canvas),
0, 0, INT_MAX, INT_MAX);
}
static void
......@@ -1358,7 +1364,7 @@ sheet_col_get (Sheet *sheet, int pos)
}
/*
* Returns an allocated column: either an existing one, or a fresh copy
* Returns an allocated row: either an existing one, or a fresh copy
*/
ColRowInfo *
sheet_row_get (Sheet *sheet, int pos)
......@@ -1795,8 +1801,9 @@ sheet_selection_cut (Sheet *sheet)
void
sheet_selection_paste (Sheet *sheet, int dest_col, int dest_row, int paste_flags)
{
CellRegion *content;
int end_col, end_row;
SheetSelection *ss;
CellRegion *content;
int end_col, end_row, paste_width, paste_height;
g_return_if_fail (sheet != NULL);
g_return_if_fail (IS_SHEET (sheet));
......@@ -1807,12 +1814,29 @@ sheet_selection_paste (Sheet *sheet, int dest_col, int dest_row, int paste_flags
if (!content)
return;
end_col = dest_col + content->cols - 1;
end_row = dest_row + content->rows - 1;
if (!sheet_verify_selection_simple (sheet, _("Paste")))
return;
clipboard_paste_region (content, sheet, dest_col, dest_row, paste_flags);
sheet_cursor_set (sheet, dest_col, dest_row, end_col, end_row);
ss = sheet->selections->data;
/* Compute the bigger bounding box (selection u clipboard-region) */
if (ss->end_col - ss->start_col + 1 > content->cols)
paste_width = ss->end_col - ss->start_col + 1;
else
paste_width = content->cols;
if (ss->end_row - ss->start_row + 1 > content->rows)
paste_height = ss->end_row - ss->start_row + 1;
else
paste_height = content->rows;
end_col = dest_col + paste_width - 1;
end_row = dest_row + paste_height - 1;
clipboard_paste_region (content, sheet, dest_col, dest_row,
paste_width, paste_height, paste_flags);
sheet_cursor_set (sheet, dest_col, dest_row, end_col, end_row);
sheet_selection_clear_only (sheet);
sheet_selection_append (sheet, dest_col, dest_row);
sheet_selection_extend_to (sheet, end_col, end_row);
......@@ -2018,9 +2042,10 @@ sheet_insert_row (Sheet *sheet, int row, int count)
/* 1. Walk every column, see which cells are out of range */
for (cols = sheet->cols_info; cols; cols = cols->next){
ColRowInfo *ci = cols->data;
GList *cells;
for (cells = cols->data; cells; cells = cells->next){
for (cells = ci->data; cells; cells = cells->next){
Cell *cell = cells->data;
if (cell->row->pos < row)
......
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