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

New routine. Abstracts the paste operation. (clipboard_paste_region): Now

1999-03-11  Miguel de Icaza  <miguel@nuclecu.unam.mx>

	* src/clipboard.c (sheet_paste_selection): New routine.  Abstracts
	the paste operation.
	(clipboard_paste_region): Now it uses a clipboard with the active
	X selection instead of defaulting to "request clipboard from X"
	(this is only for inter-workbook copy-paste).

	* src/sheet.c (find_workbook_with_clipboard): Tries to find a
	workbook with clipboard information.  Probably the clipboard
	should be global to all Gnumeric.

	* src/render-ascii.c (cell_region_render_ascii): Free the
	information after we have used it, not before.

	* src/expr.c (eval_expr): Handle new-born recursive references.
parent dc83d6a0
1999-03-11 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/clipboard.c (sheet_paste_selection): New routine. Abstracts
the paste operation.
(clipboard_paste_region): Now it uses a clipboard with the active
X selection instead of defaulting to "request clipboard from X"
(this is only for inter-workbook copy-paste).
* src/sheet.c (find_workbook_with_clipboard): Tries to find a
workbook with clipboard information. Probably the clipboard
should be global to all Gnumeric.
* src/render-ascii.c (cell_region_render_ascii): Free the
information after we have used it, not before.
* src/expr.c (eval_expr): Handle new-born recursive references.
1999-03-11 Michael Meeks <michael@imaginator.com>
* src/fn-math.c (gnumeric_power): Implemented.
......
1999-03-11 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/clipboard.c (sheet_paste_selection): New routine. Abstracts
the paste operation.
(clipboard_paste_region): Now it uses a clipboard with the active
X selection instead of defaulting to "request clipboard from X"
(this is only for inter-workbook copy-paste).
* src/sheet.c (find_workbook_with_clipboard): Tries to find a
workbook with clipboard information. Probably the clipboard
should be global to all Gnumeric.
* src/render-ascii.c (cell_region_render_ascii): Free the
information after we have used it, not before.
* src/expr.c (eval_expr): Handle new-born recursive references.
1999-03-11 Michael Meeks <michael@imaginator.com>
* src/fn-math.c (gnumeric_power): Implemented.
......
1999-03-11 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/clipboard.c (sheet_paste_selection): New routine. Abstracts
the paste operation.
(clipboard_paste_region): Now it uses a clipboard with the active
X selection instead of defaulting to "request clipboard from X"
(this is only for inter-workbook copy-paste).
* src/sheet.c (find_workbook_with_clipboard): Tries to find a
workbook with clipboard information. Probably the clipboard
should be global to all Gnumeric.
* src/render-ascii.c (cell_region_render_ascii): Free the
information after we have used it, not before.
* src/expr.c (eval_expr): Handle new-born recursive references.
1999-03-11 Michael Meeks <michael@imaginator.com>
* src/fn-math.c (gnumeric_power): Implemented.
......
1999-03-11 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/clipboard.c (sheet_paste_selection): New routine. Abstracts
the paste operation.
(clipboard_paste_region): Now it uses a clipboard with the active
X selection instead of defaulting to "request clipboard from X"
(this is only for inter-workbook copy-paste).
* src/sheet.c (find_workbook_with_clipboard): Tries to find a
workbook with clipboard information. Probably the clipboard
should be global to all Gnumeric.
* src/render-ascii.c (cell_region_render_ascii): Free the
information after we have used it, not before.
* src/expr.c (eval_expr): Handle new-born recursive references.
1999-03-11 Michael Meeks <michael@imaginator.com>
* src/fn-math.c (gnumeric_power): Implemented.
......
......@@ -1607,9 +1607,10 @@ cell_get_text (Cell *cell)
g_return_val_if_fail (cell != NULL, NULL);
if (cell->parsed_node){
if (cell->parsed_node && cell->sheet){
Sheet *sheet;
char *func, *ret;
func = expr_decode_tree (cell->parsed_node, cell->sheet, cell->col->pos, cell->row->pos);
ret = g_strconcat ("=", func, NULL);
g_free (func);
......
......@@ -246,31 +246,15 @@ x_selection_to_cell_region (char *data, int len)
}
/**
* x_selection_received:
* sheet_paste_selection:
*
* Invoked when the selection has been received by our application.
* This is triggered by a call we do to gtk_selection_convert.
*/
static void
x_selection_received (GtkWidget *widget, GtkSelectionData *sel, guint time, gpointer data)
sheet_paste_selection (Sheet *sheet, CellRegion *content, SheetSelection *ss, clipboard_paste_closure_t *pc)
{
SheetSelection *ss;
Workbook *wb = data;
clipboard_paste_closure_t *pc = wb->clipboard_paste_callback_data;
CellRegion *content;
int paste_height, paste_width;
int end_col, end_row;
ss = pc->dest_sheet->selections->data;
/* Did X provide any selection? */
if (sel->length < 0){
content = pc->region;
if (!content)
return;
} else
content = x_selection_to_cell_region (sel->data, sel->length);
/* 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;
......@@ -287,7 +271,7 @@ x_selection_received (GtkWidget *widget, GtkSelectionData *sel, guint time, gpoi
/* Do the actual paste operation */
do_clipboard_paste_cell_region (
content, pc->dest_sheet,
content, sheet,
pc->dest_col, pc->dest_row,
paste_width, paste_height,
pc->paste_flags);
......@@ -301,6 +285,34 @@ x_selection_received (GtkWidget *widget, GtkSelectionData *sel, guint time, gpoi
sheet_selection_append (pc->dest_sheet, pc->dest_col, pc->dest_row);
sheet_selection_extend_to (pc->dest_sheet, end_col, end_row);
}
/**
* x_selection_received:
*
* Invoked when the selection has been received by our application.
* This is triggered by a call we do to gtk_selection_convert.
*/
static void
x_selection_received (GtkWidget *widget, GtkSelectionData *sel, guint time, gpointer data)
{
SheetSelection *ss;
Workbook *wb = data;
clipboard_paste_closure_t *pc = wb->clipboard_paste_callback_data;
CellRegion *content;
ss = pc->dest_sheet->selections->data;
/* Did X provide any selection? */
if (sel->length < 0){
content = pc->region;
if (!content)
return;
} else
content = x_selection_to_cell_region (sel->data, sel->length);
sheet_paste_selection (pc->dest_sheet, content, ss, pc);
/* Release the resources we used */
if (sel->length >= 0)
clipboard_release (content);
......@@ -439,6 +451,27 @@ clipboard_copy_cell_range (Sheet *sheet, int start_col, int start_row, int end_c
return c.r;
}
static gboolean
workbook_selection_locator (Workbook *wb, gpointer data)
{
Workbook **target = data;
if (wb->have_x_selection)
*target = wb;
return TRUE;
}
static Workbook *
find_local_workbook_with_selection (void)
{
Workbook *result = NULL;
workbook_foreach (workbook_selection_locator, &result);
return result;
}
/**
* clipboard_paste_region:
* @region: A cell region
......@@ -456,6 +489,7 @@ clipboard_paste_region (CellRegion *region, Sheet *dest_sheet,
int paste_flags, guint32 time)
{
clipboard_paste_closure_t *data;
Workbook *workbook_holding_selection;
g_return_if_fail (dest_sheet != NULL);
g_return_if_fail (IS_SHEET (dest_sheet));
......@@ -488,12 +522,17 @@ clipboard_paste_region (CellRegion *region, Sheet *dest_sheet,
* to paste from in this case (instead of the simplistic text
* we get from X
*/
if (dest_sheet->workbook->have_x_selection){
GtkSelectionData sel;
sel.length = -1;
x_selection_received (dest_sheet->workbook->toplevel, &sel,
0, dest_sheet->workbook);
workbook_holding_selection = find_local_workbook_with_selection ();
if (workbook_holding_selection && region){
CellRegion *content;
content = region;
sheet_paste_selection (dest_sheet, content, dest_sheet->selections->data, data);
workbook_holding_selection->clipboard_paste_callback_data = NULL;
g_free (data);
return;
}
......
......@@ -938,7 +938,10 @@ eval_expr (void *asheet, ExprTree *tree, int eval_col, int eval_row, char **erro
if (cell->value)
return eval_cell_value (sheet, cell->value);
else {
*error_string = cell->text->str;
if (cell->text)
*error_string = cell->text->str;
else
*error_string = _("Reference to newborn cell");
return NULL;
}
}
......
......@@ -41,7 +41,6 @@ cell_region_render_ascii (CellRegion *cr)
v = g_strdup (c_copy->u.text);
data [c_copy->row_offset][c_copy->col_offset] = v;
g_free (v);
}
all = g_string_new (NULL);
......@@ -50,8 +49,10 @@ cell_region_render_ascii (CellRegion *cr)
g_string_assign (line, "");
for (col = 0; col < cr->cols; col++){
if (data [row][col])
if (data [row][col]){
g_string_append (line, data [row][col]);
g_free (data [row][col]);
}
g_string_append_c (line, '\t');
}
g_string_append (all, line->str);
......
......@@ -2494,6 +2494,32 @@ sheet_selection_cut (Sheet *sheet)
return TRUE;
}
static gboolean
find_a_clipboard (Workbook *wb, gpointer data)
{
CellRegion **cr = data;
if (wb->clipboard_contents){
*cr = wb->clipboard_contents;
return FALSE;
}
return TRUE;
}
static CellRegion *
find_workbook_with_clipboard (Sheet *sheet)
{
CellRegion *cr = NULL;
if (sheet->workbook->clipboard_contents)
return sheet->workbook->clipboard_contents;
workbook_foreach (find_a_clipboard, &cr);
return cr;
}
void
sheet_selection_paste (Sheet *sheet, int dest_col, int dest_row, int paste_flags, guint32 time)
{
......@@ -2503,7 +2529,7 @@ sheet_selection_paste (Sheet *sheet, int dest_col, int dest_row, int paste_flags
g_return_if_fail (IS_SHEET (sheet));
g_return_if_fail (sheet->selections);
content = sheet->workbook->clipboard_contents;
content = find_workbook_with_clipboard (sheet);
if (content)
if (!sheet_verify_selection_simple (sheet, _("Paste")))
......
......@@ -391,6 +391,11 @@ void workbook_recalc_all (Workbook *wb);
*/
void workbook_realized (Workbook *, GdkWindow *);
typedef gboolean (*WorkbookCallback)(Workbook *, gpointer data);
void workbook_foreach (WorkbookCallback cback,
gpointer data);
/*
* Feedback routines
*/
......
......@@ -1870,3 +1870,16 @@ workbook_set_filename (Workbook *wb, const char *name)
workbook_set_title (wb, g_basename (name));
}
void
workbook_foreach (WorkbookCallback cback, gpointer data)
{
GList *l;
for (l = workbook_list; l ; l = l->next){
Workbook *wb = l->data;
if (!(*cback)(wb, data))
return;
}
}
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