Commit 1a96d682 authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg
Browse files

Use cmd_clear_selection.


2000-01-15  Jody Goldberg <jgoldberg@home.com>

	* src/workbook.c (clear_{all,formats,comments,content}_cmd) : Use
	  cmd_clear_selection.

	* src/sheet.c (sheet_clear_region) : Merge all types of deletion into
	  this routine and add some bit flags to enable the different types.
	(sheet_clear_region_content) : Delete.
	(sheet_clear_region_comments) : Delete.
	(clear_cell_format) : Delete.
	(sheet_clear_region_formats) : Delete.
	(sheet_move_range) : Adapt to changes in sheet_clear_region.

	* src/selection.c (cb_sheet_selection_clear) : Delete.
	(sheet_selection_clear) : Delete.
	(cb_sheet_selection_clear_content) : Delete.
	(sheet_selection_clear_content) : Delete.
	(sheet_selection_clear_comments) : Delete.
	(sheet_selection_clear_formats) : Delete.
	(selection_get_ranges) : New function split out from selection_apply.
	(selection_apply) : Use selection_get_ranges.

	* src/gnumeric-sheet.c (gnumeric_sheet_key_mode_sheet) : Use
	  cmd_clear_selection.
	* src/item-grid.c (context_clear_cmd) : Ditto.

	* src/corba-sheet.c (Sheet_clear_region) : Adapt to new clear_region
	  calling convention.
	(Sheet_clear_region_content) : Use sheet_clear_region.
	(Sheet_clear_region_comments) : Ditto.
	(Sheet_clear_region_formats) : Ditto.

	* src/commands.c (cmd_ins_del_row_col_{undo,redo}) : Reload the the
	  edit bar just in case.
	(cmd_set_date_time_{undo,redo}) : Ditto.
	(cmd_clear{,_undo,_redo,_destroy}) : Implement.

	* src/clipboard.c (paste_cell) : No need to flag the existance of
	  formulas.
	(paste_cell_flags) : Ditto.
	(do_clipboard_paste_cell_region) : Don't recalc here.
	(x_selection_received) : Recalc here.
	(clipboard_paste_region) : Only use the X selection if the user does
	  not pass in a CellRegion. Only use the clipboard_paste_callback_data
	  if we are going through the X selection.
parent 30b26e6c
2000-01-15 Jody Goldberg <jgoldberg@home.com>
* src/workbook.c (clear_{all,formats,comments,content}_cmd) : Use
cmd_clear_selection.
* src/sheet.c (sheet_clear_region) : Merge all types of deletion into
this routine and add some bit flags to enable the different types.
(sheet_clear_region_content) : Delete.
(sheet_clear_region_comments) : Delete.
(clear_cell_format) : Delete.
(sheet_clear_region_formats) : Delete.
(sheet_move_range) : Adapt to changes in sheet_clear_region.
* src/selection.c (cb_sheet_selection_clear) : Delete.
(sheet_selection_clear) : Delete.
(cb_sheet_selection_clear_content) : Delete.
(sheet_selection_clear_content) : Delete.
(sheet_selection_clear_comments) : Delete.
(sheet_selection_clear_formats) : Delete.
(selection_get_ranges) : New function split out from selection_apply.
(selection_apply) : Use selection_get_ranges.
* src/gnumeric-sheet.c (gnumeric_sheet_key_mode_sheet) : Use
cmd_clear_selection.
* src/item-grid.c (context_clear_cmd) : Ditto.
* src/corba-sheet.c (Sheet_clear_region) : Adapt to new clear_region
calling convention.
(Sheet_clear_region_content) : Use sheet_clear_region.
(Sheet_clear_region_comments) : Ditto.
(Sheet_clear_region_formats) : Ditto.
* src/commands.c (cmd_ins_del_row_col_{undo,redo}) : Reload the the
edit bar just in case.
(cmd_set_date_time_{undo,redo}) : Ditto.
(cmd_clear{,_undo,_redo,_destroy}) : Implement.
* src/clipboard.c (paste_cell) : No need to flag the existance of
formulas.
(paste_cell_flags) : Ditto.
(do_clipboard_paste_cell_region) : Don't recalc here.
(x_selection_received) : Recalc here.
(clipboard_paste_region) : Only use the X selection if the user does
not pass in a CellRegion. Only use the clipboard_paste_callback_data
if we are going through the X selection.
2000-01-15 Morten Welinder <terra@diku.dk>
* src/cell.c (cell_set_formula): Set the "Pending recomputation"
......
2000-01-15 Jody Goldberg <jgoldberg@home.com>
* src/workbook.c (clear_{all,formats,comments,content}_cmd) : Use
cmd_clear_selection.
* src/sheet.c (sheet_clear_region) : Merge all types of deletion into
this routine and add some bit flags to enable the different types.
(sheet_clear_region_content) : Delete.
(sheet_clear_region_comments) : Delete.
(clear_cell_format) : Delete.
(sheet_clear_region_formats) : Delete.
(sheet_move_range) : Adapt to changes in sheet_clear_region.
* src/selection.c (cb_sheet_selection_clear) : Delete.
(sheet_selection_clear) : Delete.
(cb_sheet_selection_clear_content) : Delete.
(sheet_selection_clear_content) : Delete.
(sheet_selection_clear_comments) : Delete.
(sheet_selection_clear_formats) : Delete.
(selection_get_ranges) : New function split out from selection_apply.
(selection_apply) : Use selection_get_ranges.
* src/gnumeric-sheet.c (gnumeric_sheet_key_mode_sheet) : Use
cmd_clear_selection.
* src/item-grid.c (context_clear_cmd) : Ditto.
* src/corba-sheet.c (Sheet_clear_region) : Adapt to new clear_region
calling convention.
(Sheet_clear_region_content) : Use sheet_clear_region.
(Sheet_clear_region_comments) : Ditto.
(Sheet_clear_region_formats) : Ditto.
* src/commands.c (cmd_ins_del_row_col_{undo,redo}) : Reload the the
edit bar just in case.
(cmd_set_date_time_{undo,redo}) : Ditto.
(cmd_clear{,_undo,_redo,_destroy}) : Implement.
* src/clipboard.c (paste_cell) : No need to flag the existance of
formulas.
(paste_cell_flags) : Ditto.
(do_clipboard_paste_cell_region) : Don't recalc here.
(x_selection_received) : Recalc here.
(clipboard_paste_region) : Only use the X selection if the user does
not pass in a CellRegion. Only use the clipboard_paste_callback_data
if we are going through the X selection.
2000-01-15 Morten Welinder <terra@diku.dk>
* src/cell.c (cell_set_formula): Set the "Pending recomputation"
......
......@@ -13,6 +13,7 @@
#include "workbook-view.h"
#include "utils.h"
#include "clipboard.h"
#include "selection.h"
/*
* NOTE : This is a work in progress
......@@ -475,6 +476,7 @@ cmd_ins_del_row_col_undo (GnumericCommand *cmd, CommandContext *context)
workbook_recalc (me->sheet->workbook);
sheet_redraw_all (me->sheet);
sheet_load_cell_val (me->sheet);
return trouble;
}
......@@ -522,6 +524,7 @@ cmd_ins_del_row_col_redo (GnumericCommand *cmd, CommandContext *context)
workbook_recalc (me->sheet->workbook);
sheet_redraw_all (me->sheet);
sheet_load_cell_val (me->sheet);
return trouble;
}
......@@ -635,6 +638,12 @@ cmd_delete_rows (CommandContext *context,
typedef struct
{
GnumericCommand parent;
int clear_flags;
int paste_flags;
Sheet *sheet;
GSList *old_content;
GSList *selection;
} CmdClear;
GNUMERIC_MAKE_COMMAND (CmdClear, cmd_clear);
......@@ -643,10 +652,31 @@ static gboolean
cmd_clear_undo (GnumericCommand *cmd, CommandContext *context)
{
CmdClear *me = CMD_CLEAR(cmd);
GSList *ranges;
g_return_val_if_fail (me != NULL, TRUE);
g_return_val_if_fail (me->selection != NULL, TRUE);
g_return_val_if_fail (me->old_content != NULL, TRUE);
for (ranges = me->selection; ranges != NULL ; ranges = ranges->next) {
Range const * const r = ranges->data;
CellRegion * c;
g_return_val_if_fail (me->old_content != NULL, TRUE);
c = me->old_content->data;
clipboard_paste_region (context, c, me->sheet,
r->start.col, r->start.row,
me->paste_flags,
GDK_CURRENT_TIME);
clipboard_release (c);
me->old_content = g_slist_remove (me->old_content, c);
}
g_return_val_if_fail (me->old_content == NULL, TRUE);
workbook_recalc (me->sheet->workbook);
sheet_load_cell_val (me->sheet);
/* FIXME : Fill in */
return FALSE;
}
......@@ -654,29 +684,87 @@ static gboolean
cmd_clear_redo (GnumericCommand *cmd, CommandContext *context)
{
CmdClear *me = CMD_CLEAR(cmd);
GSList *l;
g_return_val_if_fail (me != NULL, TRUE);
g_return_val_if_fail (me->selection != NULL, TRUE);
g_return_val_if_fail (me->old_content == NULL, TRUE);
for (l = me->selection ; l != NULL ; l = l->next) {
Range const * const r = l->data;
me->old_content =
g_slist_prepend (me->old_content,
clipboard_copy_cell_range (me->sheet,
r->start.col, r->start.row,
r->end.col, r->end.row));
sheet_clear_region (context, me->sheet,
r->start.col, r->start.row,
r->end.col, r->end.row,
me->clear_flags);
}
workbook_recalc (me->sheet->workbook);
sheet_load_cell_val (me->sheet);
/* FIXME : Fill in */
return FALSE;
}
static void
cmd_clear_destroy (GtkObject *cmd)
{
#if 0
CmdClear *me = CMD_CLEAR(cmd);
#endif
/* FIXME : Fill in */
if (me->old_content != NULL) {
GSList *l;
for (l = me->old_content ; l != NULL ; l = g_slist_remove (l, l->data))
clipboard_release (l->data);
me->old_content = NULL;
}
if (me->selection != NULL) {
GSList *l;
for (l = me->selection ; l != NULL ; l = g_slist_remove (l, l->data))
g_free (l->data);
me->selection = NULL;
}
gnumeric_command_destroy (cmd);
}
#if 0
gboolean
cmd_clear (CommandContext *context,
cmd_clear_selection (CommandContext *context, Sheet *sheet, int const clear_flags)
{
return FALSE;
GtkObject *obj;
CmdClear *me;
gboolean trouble;
g_return_val_if_fail (sheet != NULL, TRUE);
obj = gtk_type_new (CMD_CLEAR_TYPE);
me = CMD_CLEAR (obj);
/* Store the specs for the object */
me->sheet = sheet;
me->clear_flags = clear_flags;
me->old_content = NULL;
me->selection = selection_get_ranges (sheet, FALSE /* No intersection */);
me->paste_flags = 0;
if (clear_flags & CLEAR_VALUES)
me->paste_flags |= PASTE_VALUES | PASTE_FORMULAS;
if (clear_flags & CLEAR_FORMATS)
me->paste_flags |= PASTE_FORMATS;
if (clear_flags & CLEAR_COMMENTS)
g_warning ("Deleted comments can not be restored yet");
/* TODO : Something more descriptive ? maybe the range name */
me->parent.cmd_descriptor = g_strdup (_("Clear"));
trouble = cmd_clear_redo (GNUMERIC_COMMAND(me), context);
/* Register the command object */
return command_push_undo (sheet->workbook, obj, trouble);
}
#endif
/******************************************************************/
......@@ -969,6 +1057,7 @@ cmd_set_date_time_undo (GnumericCommand *cmd, CommandContext *context)
} else
cell_set_value (cell, value_new_empty ());
sheet_load_cell_val (me->pos.sheet);
return FALSE;
}
......@@ -1025,6 +1114,8 @@ cmd_set_date_time_redo (GnumericCommand *cmd, CommandContext *context)
cell_set_value (cell, v);
cell_set_format (cell, prefered_format+1);
workbook_recalc (me->pos.sheet->workbook);
sheet_load_cell_val (me->pos.sheet);
return FALSE;
}
static void
......
......@@ -36,4 +36,6 @@ gboolean cmd_paste_cut (CommandContext *context,
gboolean cmd_rename_sheet (CommandContext *context, Workbook *wb,
const char *old_name, const char *new_name);
gboolean cmd_clear_selection (CommandContext *context, Sheet *sheet, int const clear_flags);
#endif /* GNUMERIC_COMMAND_CONTEXT_H */
......@@ -218,7 +218,7 @@ Sheet_clear_region (PortableServer_Servant servant,
sheet_clear_region (
command_context_corba (sheet->workbook),
sheet, start_col, start_row,
end_col, end_row, TRUE);
end_col, end_row, CLEAR_VALUES|CLEAR_FORMATS|CLEAR_COMMENTS);
}
static void
......@@ -230,9 +230,11 @@ Sheet_clear_region_content (PortableServer_Servant servant,
Sheet *sheet = sheet_from_servant (servant);
verify_region (start_col, start_row, end_col, end_row);
sheet_clear_region_content (
command_context_corba (sheet->workbook), sheet,
start_col, start_row, end_col, end_row);
sheet_clear_region (
command_context_corba (sheet->workbook),
sheet, start_col, start_row,
end_col, end_row, CLEAR_VALUES|CLEAR_COMMENTS);
}
static void
......@@ -244,7 +246,11 @@ Sheet_clear_region_comments (PortableServer_Servant servant,
Sheet *sheet = sheet_from_servant (servant);
verify_region (start_col, start_row, end_col, end_row);
sheet_clear_region_comments (sheet, start_col, start_row, end_col, end_row, NULL);
sheet_clear_region (
command_context_corba (sheet->workbook),
sheet, start_col, start_row,
end_col, end_row, CLEAR_COMMENTS);
}
static void
......@@ -256,7 +262,11 @@ Sheet_clear_region_formats (PortableServer_Servant servant,
Sheet *sheet = sheet_from_servant (servant);
verify_region (start_col, start_row, end_col, end_row);
sheet_clear_region_formats (sheet, start_col, start_row, end_col, end_row, NULL);
sheet_clear_region (
command_context_corba (sheet->workbook),
sheet, start_col, start_row,
end_col, end_row, CLEAR_FORMATS);
}
static void
......
......@@ -787,7 +787,7 @@ gnumeric_sheet_key_mode_sheet (GnumericSheet *gsheet, GdkEventKey *event)
case GDK_KP_Delete:
case GDK_Delete:
sheet_selection_clear_content (workbook_command_context_gui (wb), sheet);
cmd_clear_selection (workbook_command_context_gui (wb), sheet, CLEAR_VALUES);
break;
case GDK_KP_Enter:
......
......@@ -787,7 +787,7 @@ gnumeric_sheet_key_mode_sheet (GnumericSheet *gsheet, GdkEventKey *event)
case GDK_KP_Delete:
case GDK_Delete:
sheet_selection_clear_content (workbook_command_context_gui (wb), sheet);
cmd_clear_selection (workbook_command_context_gui (wb), sheet, CLEAR_VALUES);
break;
case GDK_KP_Enter:
......
......@@ -23,6 +23,7 @@
#include "workbook-cmd-format.h"
#include "pattern.h"
#include "workbook-view.h"
#include "commands.h"
static GnomeCanvasItemClass *item_grid_parent_class;
......@@ -577,7 +578,7 @@ context_delete_cmd (GtkWidget *widget, Sheet *sheet)
static void
context_clear_cmd (GtkWidget *widget, Sheet *sheet)
{
sheet_selection_clear_content (workbook_command_context_gui (sheet->workbook), sheet);
cmd_clear_selection (workbook_command_context_gui (sheet->workbook), sheet, CLEAR_VALUES);
context_destroy_menu (widget);
}
......
......@@ -684,8 +684,8 @@ sheet_selection_paste (CommandContext *context, Sheet *sheet,
area = application_clipboard_area_get ();
content = application_clipboard_contents_get ();
/* If contents are null this was a cut */
if (content == NULL && area != NULL) {
/* Pasting a Cut */
ExprRelocateInfo rinfo;
Sheet * src_sheet = application_clipboard_sheet_get ();
Range const *sel = selection_first_range (sheet, FALSE);
......@@ -721,117 +721,27 @@ sheet_selection_paste (CommandContext *context, Sheet *sheet,
sheet_move_range (NULL, &rinfo);
sheet_selection_move (&rinfo);
application_clipboard_clear ();
} else
} else {
/* Pasting a Copy or from the X selection */
clipboard_paste_region (context, content,
sheet, dest_col, dest_row,
paste_flags, time);
}
static void
cb_sheet_selection_clear (Sheet *sheet,
int start_col, int start_row,
int end_col, int end_row,
void *context)
{
sheet_clear_region (context, sheet, start_col, start_row,
end_col, end_row, TRUE);
}
/**
* sheet_selection_clear:
* @sheet: The sheet where we operate
*
* Removes the contents and styles.
**/
void
sheet_selection_clear (CommandContext *context, Sheet *sheet)
{
selection_apply (sheet, &cb_sheet_selection_clear, TRUE, NULL);
}
static void
cb_sheet_selection_clear_content (Sheet *sheet,
int start_col, int start_row,
int end_col, int end_row,
void *context)
{
sheet_clear_region_content (context, sheet,
start_col, start_row,
end_col, end_row);
}
/**
* sheet_selection_clear_content:
* @sheet: The sheet where we operate
*
* Removes the contents of all the cells in the current selection.
**/
void
sheet_selection_clear_content (CommandContext *context, Sheet *sheet)
{
selection_apply (sheet, &cb_sheet_selection_clear_content,
TRUE, context);
sheet_load_cell_val(sheet);
}
/**
* sheet_selection_clear_comments:
* @sheet: The sheet where we operate
*
* Removes all of the comments on the range of selected cells.
**/
void
sheet_selection_clear_comments (CommandContext *context, Sheet *sheet)
{
selection_apply (sheet, &sheet_clear_region_comments, TRUE, NULL);
}
/**
* sheet_selection_clear_formats:
* @sheet: The sheet where we operate
*
* Removes all formating
**/
void
sheet_selection_clear_formats (CommandContext *context, Sheet *sheet)
{
selection_apply (sheet, &sheet_clear_region_formats, TRUE, NULL);
workbook_recalc (sheet->workbook);
}
}
/**
* selection_apply:
* selection_get_ranges:
* @sheet: the sheet.
* @func: The function to apply.
* @allow_intersection : Call the routine for the non-intersecting subregions.
* @closure : A parameter to pass to each invocation of @func.
*
* Applies the specified function for all ranges in the selection. Optionally
* select whether to use the high level potentially over lapped ranges, rather
* than the smaller system created non-intersection regions.
* @allow_intersection : Divide the selection into nonoverlappign subranges.
*/
void
selection_apply (Sheet *sheet, SelectionApplyFunc const func,
gboolean allow_intersection,
void * closure)
GSList *
selection_get_ranges (Sheet * sheet, gboolean const allow_intersection)
{
GList *l;
GList *l;
GSList *proposed = NULL;
g_return_if_fail (sheet != NULL);
g_return_if_fail (IS_SHEET (sheet));
if (allow_intersection) {
for (l = sheet->selections; l != NULL; l = l->next) {
SheetSelection const *ss = l->data;
(*func) (sheet,
ss->user.start.col, ss->user.start.row,
ss->user.end.col, ss->user.end.row,
closure);
}
return;
}
#undef DEBUG_SELECTION
#ifdef DEBUG_SELECTION
fprintf (stderr, "============================\n");
......@@ -1090,20 +1000,57 @@ selection_apply (Sheet *sheet, SelectionApplyFunc const func,
proposed = (b != NULL) ? g_slist_prepend (clear, b) : clear;
}
while (proposed != NULL) {
/* pop the 1st element off the list */
Range *r = proposed->data;
proposed = g_slist_remove (proposed, r);
return proposed;
}
/**
* selection_apply:
* @sheet: the sheet.
* @func: The function to apply.
* @allow_intersection : Call the routine for the non-intersecting subregions.
* @closure : A parameter to pass to each invocation of @func.
*
* Applies the specified function for all ranges in the selection. Optionally
* select whether to use the high level potentially over lapped ranges, rather
* than the smaller system created non-intersection regions.
*/
void
selection_apply (Sheet *sheet, SelectionApplyFunc const func,
gboolean allow_intersection,
void * closure)
{
GList *l;
GSList *proposed = NULL;
g_return_if_fail (sheet != NULL);
g_return_if_fail (IS_SHEET (sheet));
if (allow_intersection) {
for (l = sheet->selections; l != NULL; l = l->next) {
SheetSelection const *ss = l->data;
(*func) (sheet,
ss->user.start.col, ss->user.start.row,
ss->user.end.col, ss->user.end.row,
closure);
}
} else {
proposed = selection_get_ranges (sheet, allow_intersection);
while (proposed != NULL) {
/* pop the 1st element off the list */
Range *r = proposed->data;
proposed = g_slist_remove (proposed, r);
#ifdef DEBUG_SELECTION
range_dump (r);
range_dump (r);
#endif
(*func) (sheet,
r->start.col, r->start.row,
r->end.col, r->end.row,
closure);
g_free (r);
(*func) (sheet,
r->start.col, r->start.row,
r->end.col, r->end.row,
closure);
g_free (r);
}
}
}
......
......@@ -23,10 +23,6 @@ void sheet_cell_list_free (CellList *cell_list);
char *sheet_selection_to_string (Sheet *sheet, gboolean include_sheet_name_prefix);
/* Operations on the selection */
void sheet_selection_clear (CommandContext *context, Sheet *sheet);
void sheet_selection_clear_content (CommandContext *context, Sheet *sheet);
void sheet_selection_clear_comments (CommandContext *context, Sheet *sheet);
void sheet_selection_clear_formats (CommandContext *context, Sheet *sheet);
void sheet_selection_height_update (Sheet *sheet);
/* Cut/Copy/Paste on the workbook selection */
......@@ -58,6 +54,7 @@ typedef void (*SelectionApplyFunc) (Sheet *sheet,
void selection_apply (Sheet *sheet, SelectionApplyFunc const func,
gboolean allow_intersection,
void *closure);
GSList * selection_get_ranges (Sheet * sheet, gboolean const allow_intersection);
/* export the selection */
CellList *selection_to_list (Sheet *sheet, gboolean allow_intersection);
......
......@@ -2513,6 +2513,7 @@ sheet_destroy (Sheet *sheet)
g_free (sheet);
}
/*****************************************************************************/
struct sheet_clear_region_callback_data
{
......@@ -2555,141 +2556,82 @@ assemble_clear_cell_list (Sheet *sheet, int col, int row, Cell *cell,
return NULL;
}
static Value *
cb_clear_cell_comments (Sheet *sheet, int col, int row, Cell *cell, void *user_data)
{
cell_comment_destroy (cell);
return NULL;
}
/**
* sheet_clear_region:
*
* Clears are region of cells
*
* @clearStyles : If this is TRUE then styles are erased.
* @clear_flags : If this is TRUE then styles are erased.
*
* We assemble a list of cells to destroy, since we will be making changes
* to the structure being manipulated by the sheet_cell_foreach_range routine
*/
void
sheet_clear_region (CommandContext *context, Sheet *sheet,
int start_col, int start_row, int end_col, int end_row,
gboolean const clearStyles)