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

Today:



Today:

	- Row insertion works.

	- Dialog box for adding various things (equivalent to
	  excel's Insert/Cells dialog box, any similarities
	  with Excel are accidental).

	- Plus the usual exciting features you would expect.

Miguel

1998-08-21  Miguel de Icaza  <miguel@nuclecu.unam.mx>

	* src/dialog-insert-cells.c: New file.  Handle the insert cells
	dialog box.  This uses GtkCauldron for the first time.  That
	routine is soooo cool!

	* src/sheet.c (sheet_cell_remove): Remove the memory used by the
	key in the hashtable as well.
	(sheet_insert_col): new routine used to insert columns in the
	spreadsheet, it is pretty elaborate.
	(sheet_col_destroy, sheet_row_destroy): New routine used by the
	column-overflow logic in the insertion routines.
	(sheet_cell_add): Only attach a style to a cell if it does not
	have any yet.
	(sheet_move_row): New routine: shifts a row a number of columns.
	(sheet_verify_selection_simple): New routine for warnging about
	the multiple-selections case.  In the future it should provide a
	help context.
	(sheet_insert_row): Implement this new routine.

	* src/clipboard.c (paste_cell): Simplify.

	* src/cell.c (cell_make_value, cell_formula_relocate): New routines
	based on the code that was done for the clipboard.  Now they are
	used in other places as well.  cell_make_value actually fixes a
	potential bug that caused formulas to reappear magically on
	paste-values commands (never hit the bug, but it was there, I
	swear to god).
parent 9d81be03
1998-08-21 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/dialog-insert-cells.c: New file. Handle the insert cells
dialog box. This uses GtkCauldron for the first time. That
routine is soooo cool!
* src/sheet.c (sheet_cell_remove): Remove the memory used by the
key in the hashtable as well.
(sheet_insert_col): new routine used to insert columns in the
......@@ -9,6 +13,10 @@
(sheet_cell_add): Only attach a style to a cell if it does not
have any yet.
(sheet_move_row): New routine: shifts a row a number of columns.
(sheet_verify_selection_simple): New routine for warnging about
the multiple-selections case. In the future it should provide a
help context.
(sheet_insert_row): Implement this new routine.
* src/clipboard.c (paste_cell): Simplify.
......
1998-08-21 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/dialog-insert-cells.c: New file. Handle the insert cells
dialog box. This uses GtkCauldron for the first time. That
routine is soooo cool!
* src/sheet.c (sheet_cell_remove): Remove the memory used by the
key in the hashtable as well.
(sheet_insert_col): new routine used to insert columns in the
......@@ -9,6 +13,10 @@
(sheet_cell_add): Only attach a style to a cell if it does not
have any yet.
(sheet_move_row): New routine: shifts a row a number of columns.
(sheet_verify_selection_simple): New routine for warnging about
the multiple-selections case. In the future it should provide a
help context.
(sheet_insert_row): Implement this new routine.
* src/clipboard.c (paste_cell): Simplify.
......
1998-08-21 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/dialog-insert-cells.c: New file. Handle the insert cells
dialog box. This uses GtkCauldron for the first time. That
routine is soooo cool!
* src/sheet.c (sheet_cell_remove): Remove the memory used by the
key in the hashtable as well.
(sheet_insert_col): new routine used to insert columns in the
......@@ -9,6 +13,10 @@
(sheet_cell_add): Only attach a style to a cell if it does not
have any yet.
(sheet_move_row): New routine: shifts a row a number of columns.
(sheet_verify_selection_simple): New routine for warnging about
the multiple-selections case. In the future it should provide a
help context.
(sheet_insert_row): Implement this new routine.
* src/clipboard.c (paste_cell): Simplify.
......
1998-08-21 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/dialog-insert-cells.c: New file. Handle the insert cells
dialog box. This uses GtkCauldron for the first time. That
routine is soooo cool!
* src/sheet.c (sheet_cell_remove): Remove the memory used by the
key in the hashtable as well.
(sheet_insert_col): new routine used to insert columns in the
......@@ -9,6 +13,10 @@
(sheet_cell_add): Only attach a style to a cell if it does not
have any yet.
(sheet_move_row): New routine: shifts a row a number of columns.
(sheet_verify_selection_simple): New routine for warnging about
the multiple-selections case. In the future it should provide a
help context.
(sheet_insert_row): Implement this new routine.
* src/clipboard.c (paste_cell): Simplify.
......
......@@ -19,6 +19,7 @@ GNUMERIC_BASE_SOURCES = \
clipboard.h \
dialog-cell-format.c \
dialog-goto-cell.c \
dialog-insert-cells.c \
dialog-paste-special.c \
dialogs.h \
eval.c \
......
......@@ -4,5 +4,6 @@
void dialog_goto_cell (Workbook *wb);
void dialog_cell_format (Sheet *sheet);
int dialog_paste_special (void);
void dialog_insert_cells (Sheet *sheet);
#endif
......@@ -4,5 +4,6 @@
void dialog_goto_cell (Workbook *wb);
void dialog_cell_format (Sheet *sheet);
int dialog_paste_special (void);
void dialog_insert_cells (Sheet *sheet);
#endif
......@@ -1621,6 +1621,22 @@ sheet_cell_remove_internal (Sheet *sheet, Cell *cell)
cell->col->data = g_list_remove (cell->col->data, cell);
}
/*
* Removes all of the cells from CELL_LIST point on.
*/
static void
sheet_cell_remove_to_eot (Sheet *sheet, GList *cell_list)
{
while (cell_list){
Cell *cell = cell_list->data;
if (cell->parsed_node)
sheet_cell_formula_unlink (cell);
sheet_cell_remove_from_hash (sheet, cell);
cell_destroy (cell);
}
}
void
sheet_cell_remove (Sheet *sheet, Cell *cell)
......@@ -1664,6 +1680,7 @@ sheet_col_destroy (Sheet *sheet, ColRowInfo *ci)
Cell *cell = l->data;
sheet_cell_remove_internal (sheet, cell);
cell_destroy (cell);
}
sheet->cols_info = g_list_remove (sheet->cols_info, ci);
......@@ -1714,6 +1731,23 @@ sheet_clear_region (Sheet *sheet, int start_col, int start_row, int end_col, int
g_list_free (destroyable_cells);
}
gboolean
sheet_verify_selection_simple (Sheet *sheet, char *command_name)
{
char *msg;
if (g_list_length (sheet->selections) == 1)
return TRUE;
msg = g_copy_strings (
"The command `", command_name,
"' can not be performed with multiple selections", NULL);
gnumeric_notice (msg);
g_free (msg);
return FALSE;
}
gboolean
sheet_selection_copy (Sheet *sheet)
{
......@@ -1721,11 +1755,9 @@ sheet_selection_copy (Sheet *sheet)
g_return_val_if_fail (sheet != NULL, FALSE);
g_return_val_if_fail (IS_SHEET (sheet), FALSE);
g_return_val_if_fail (sheet->selections, FALSE);
if (g_list_length (sheet->selections) != 1){
gnumeric_notice (_("Can not copy non-contiguous selections"));
if (!sheet_verify_selection_simple (sheet, "copy"))
return FALSE;
}
ss = sheet->selections->data;
......@@ -1748,11 +1780,9 @@ sheet_selection_cut (Sheet *sheet)
g_return_val_if_fail (sheet != NULL, FALSE);
g_return_val_if_fail (IS_SHEET (sheet), FALSE);
g_return_val_if_fail (sheet->selections, FALSE);
if (g_list_length (sheet->selections) != 1){
gnumeric_notice (_("Can not cut non-contiguous selections"));
if (!sheet_verify_selection_simple (sheet, "cut"))
return FALSE;
}
ss = sheet->selections->data;
......@@ -1978,9 +2008,73 @@ sheet_shift_rows (Sheet *sheet, int col, int start_row, int end_row, int count)
void
sheet_insert_row (Sheet *sheet, int row, int count)
{
GList *cell_store, *cols, *l, *rows;
g_return_if_fail (sheet != NULL);
g_return_if_fail (IS_SHEET (sheet));
g_return_if_fail (count != 0);
cell_store = NULL;
/* 1. Walk every column, see which cells are out of range */
for (cols = sheet->cols_info; cols; cols = cols->next){
GList *cells;
for (cells = cols->data; cells; cells = cells->next){
Cell *cell = cells->data;
if (cell->row->pos < row)
continue;
/* If the new position is out of range, destroy the cell */
if (cell->row->pos + count > SHEET_MAX_ROWS-1){
sheet_cell_remove_to_eot (sheet, cells);
/* Remove any trace of the tail that just got deleted */
if (cells->prev)
cells->prev->next = NULL;
g_list_free (cells);
break;
}
/* At this point we now we can move the cell safely */
sheet_cell_remove_from_hash (sheet, cell);
/* Keep track of it */
cell_store = g_list_prepend (cell_store, cell);
}
}
/* 2. Relocate the row information pointers, destroy overflowed rows */
for (rows = sheet->rows_info; rows; rows = rows->next){
ColRowInfo *ri = rows->data;
if (ri->pos < row)
continue;
if (ri->pos + count > SHEET_MAX_ROWS-1){
sheet_row_destroy (sheet, ri);
continue;
}
ri->pos += count;
}
/* 3. Put back the moved cells in their new spot */
for (l = cell_store; l; l = l->next){
Cell *cell = l->data;
sheet_cell_add_to_hash (sheet, cell);
if (cell->parsed_node)
cell_formula_relocate (cell, cell->col->pos, cell->row->pos);
}
g_list_free (cell_store);
/* 4. Redraw everything */
sheet_redraw_all (sheet);
}
/*
......@@ -1998,6 +2092,31 @@ sheet_shift_col (Sheet *sheet, int col, int row, int count)
g_return_if_fail (sheet != NULL);
g_return_if_fail (IS_SHEET (sheet));
g_return_if_fail (count != 0);
g_warning ("sheet_shift_col is not yet implemented\n");
}
/*
* sheet_shift_cols
* @sheet the sheet
* @start_col first column
* @end_col end column
* @row first row where the shifting takes place.
* @count numbers of rows to shift. a negative numbers will
* delete count rows, positive number will insert
* count rows.
*/
void
sheet_shift_cols (Sheet *sheet, int start_col, int end_col, int row, int count)
{
int i;
g_return_if_fail (sheet != NULL);
g_return_if_fail (IS_SHEET (sheet));
g_return_if_fail (count != 0);
for (i = start_col; i <= end_col; i++)
sheet_shift_col (sheet, i, row, count);
}
void
......
......@@ -138,6 +138,8 @@ void sheet_selection_extend_horizontal (Sheet *sheet, int count);
void sheet_selection_extend_vertical (Sheet *sheet, int count);
int sheet_selection_is_cell_selected (Sheet *sheet, int col, int row);
gboolean sheet_verify_selection_simple (Sheet *sheet, char *command_name);
/* Cell management */
Cell *sheet_cell_new (Sheet *sheet, int col, int row);
void sheet_cell_add (Sheet *sheet, Cell *cell,
......@@ -208,6 +210,10 @@ void sheet_insert_row (Sheet *sheet, int row, int count);
void sheet_shift_row (Sheet *sheet, int col, int row, int count);
void sheet_shift_rows (Sheet *sheet, int col,
int start_row, int end_row, int count);
void sheet_shift_col (Sheet *sheet, int col, int row, int count);
void sheet_shift_cols (Sheet *sheet,
int start_col, int end_col,
int row, int count);
void sheet_style_attach (Sheet *sheet,
int start_col, int start_row,
......
......@@ -77,6 +77,27 @@ goto_cell_cmd (GtkWidget *widget, Workbook *wb)
dialog_goto_cell (wb);
}
static void
insert_cells_cmd (GtkWidget *widget, Workbook *wb)
{
Sheet *sheet;
sheet = workbook_get_current_sheet (wb);
dialog_insert_cells (sheet);
}
static void
insert_cols_cmd (GtkWidget *widget, Workbook *wb)
{
g_warning ("insert_cols is not yet implemented\n");
}
static void
insert_rows_cmd (GtkWidget *widget, Workbook *wb)
{
g_warning ("insert_rows is not yet implemented\n");
}
static void
format_cells_cmd (GtkWidget *widget, Workbook *wb)
{
......@@ -109,15 +130,27 @@ static GnomeUIInfo workbook_menu_edit [] = {
GNOMEUIINFO_END
};
static GnomeUIInfo workbook_menu_insert [] = {
{ GNOME_APP_UI_ITEM, N_("Cells..."), NULL, insert_cells_cmd },
#if 0
{ GNOME_APP_UI_ITEM, N_("Rows"), NULL, insert_rows_cmd },
{ GNOME_APP_UI_ITEM, N_("Columns"), NULL, insert_cols_cmd },
#endif
GNOMEUIINFO_SEPARATOR,
GNOMEUIINFO_END
};
static GnomeUIInfo workbook_menu_format [] = {
{ GNOME_APP_UI_ITEM, N_("Cells.."), NULL, format_cells_cmd, NULL, NULL,
0, 0, GDK_1, GDK_CONTROL_MASK },
GNOMEUIINFO_END
};
static GnomeUIInfo workbook_menu [] = {
{ GNOME_APP_UI_SUBTREE, N_("File"), NULL, &workbook_menu_file },
{ GNOME_APP_UI_SUBTREE, N_("Edit"), NULL, &workbook_menu_edit },
{ GNOME_APP_UI_SUBTREE, N_("Insert"), NULL, &workbook_menu_insert },
{ GNOME_APP_UI_SUBTREE, N_("Format"), NULL, &workbook_menu_format },
GNOMEUIINFO_END
};
......
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