Commit 0551a214 authored by Miguel de Icaza's avatar Miguel de Icaza Committed by Arturo Espinosa
Browse files

Allow the lists to include an asterisk to be able to distinguish between



1998-09-28  Miguel de Icaza  <miguel@nuclecu.unam.mx>

	* src/sheet-autofill.c (matches_list): Allow the lists to include
	an asterisk to be able to distinguish between abbreviations and
	full descriptions.

	* src/clipboard.c (x_selection_to_cell_region): New routine.
	Creates a CellRegion of type text based on the selection provided
	by X.
	(paste_cell_flags): New function, decoupled from
	do_clipboard_paste_cell_region.   Handles new type in CellCopy.

	* src/sheet.c (sheet_selection_paste): Simplified as most of the
	work is now

	* src/clipboard.c (x_selection_received): Perform the paste
	operation, moved most of the logic from sheet.c.  This does both
	internal paste and paste from the X selection (and everything
	works the way the user expects it to behave).
parent 79a88b7c
1998-09-28 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet-autofill.c (matches_list): Allow the lists to include
an asterisk to be able to distinguish between abbreviations and
full descriptions.
* src/clipboard.c (x_selection_to_cell_region): New routine.
Creates a CellRegion of type text based on the selection provided
by X.
(paste_cell_flags): New function, decoupled from
do_clipboard_paste_cell_region. Handles new type in CellCopy.
* src/sheet.c (sheet_selection_paste): Simplified as most of the
work is now
* src/clipboard.c (x_selection_received): Perform the paste
operation, moved most of the logic from sheet.c. This does both
internal paste and paste from the X selection (and everything
works the way the user expects it to behave).
1998-09-27 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/cell.h: Cell Copys now can contain both Cells or plain
text.
* src/expr.c (function_call_with_values): Check the return value
from symbol_lookup.
1998-09-27 Miguel de Icaza <miguel@nuclecu.unam.mx>
* plugins/python/python.c (marshal_func): Our scheduled
indentation changes.
* plugins/python/gnumeric_startup.py: Sample file that gets loaded
when the Module is loaded.
1998-09-27 Raja R Harinath <harinath@cs.umn.edu>
* configure.in (GNOME_COMPILE_WARNINGS): New check.
......@@ -31,6 +67,9 @@
1998-09-26 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet-object.c (sheet_view_object_realize): Swap coordinates
before passing to the canvas item.
* plugins/python/python.c (init_plugin): Use the system
installation directory to load the python scripts.
......
1998-09-28 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet-autofill.c (matches_list): Allow the lists to include
an asterisk to be able to distinguish between abbreviations and
full descriptions.
* src/clipboard.c (x_selection_to_cell_region): New routine.
Creates a CellRegion of type text based on the selection provided
by X.
(paste_cell_flags): New function, decoupled from
do_clipboard_paste_cell_region. Handles new type in CellCopy.
* src/sheet.c (sheet_selection_paste): Simplified as most of the
work is now
* src/clipboard.c (x_selection_received): Perform the paste
operation, moved most of the logic from sheet.c. This does both
internal paste and paste from the X selection (and everything
works the way the user expects it to behave).
1998-09-27 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/cell.h: Cell Copys now can contain both Cells or plain
text.
* src/expr.c (function_call_with_values): Check the return value
from symbol_lookup.
1998-09-27 Miguel de Icaza <miguel@nuclecu.unam.mx>
* plugins/python/python.c (marshal_func): Our scheduled
indentation changes.
* plugins/python/gnumeric_startup.py: Sample file that gets loaded
when the Module is loaded.
1998-09-27 Raja R Harinath <harinath@cs.umn.edu>
* configure.in (GNOME_COMPILE_WARNINGS): New check.
......@@ -31,6 +67,9 @@
1998-09-26 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet-object.c (sheet_view_object_realize): Swap coordinates
before passing to the canvas item.
* plugins/python/python.c (init_plugin): Use the system
installation directory to load the python scripts.
......
1998-09-28 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet-autofill.c (matches_list): Allow the lists to include
an asterisk to be able to distinguish between abbreviations and
full descriptions.
* src/clipboard.c (x_selection_to_cell_region): New routine.
Creates a CellRegion of type text based on the selection provided
by X.
(paste_cell_flags): New function, decoupled from
do_clipboard_paste_cell_region. Handles new type in CellCopy.
* src/sheet.c (sheet_selection_paste): Simplified as most of the
work is now
* src/clipboard.c (x_selection_received): Perform the paste
operation, moved most of the logic from sheet.c. This does both
internal paste and paste from the X selection (and everything
works the way the user expects it to behave).
1998-09-27 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/cell.h: Cell Copys now can contain both Cells or plain
text.
* src/expr.c (function_call_with_values): Check the return value
from symbol_lookup.
1998-09-27 Miguel de Icaza <miguel@nuclecu.unam.mx>
* plugins/python/python.c (marshal_func): Our scheduled
indentation changes.
* plugins/python/gnumeric_startup.py: Sample file that gets loaded
when the Module is loaded.
1998-09-27 Raja R Harinath <harinath@cs.umn.edu>
* configure.in (GNOME_COMPILE_WARNINGS): New check.
......@@ -31,6 +67,9 @@
1998-09-26 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet-object.c (sheet_view_object_realize): Swap coordinates
before passing to the canvas item.
* plugins/python/python.c (init_plugin): Use the system
installation directory to load the python scripts.
......
1998-09-28 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet-autofill.c (matches_list): Allow the lists to include
an asterisk to be able to distinguish between abbreviations and
full descriptions.
* src/clipboard.c (x_selection_to_cell_region): New routine.
Creates a CellRegion of type text based on the selection provided
by X.
(paste_cell_flags): New function, decoupled from
do_clipboard_paste_cell_region. Handles new type in CellCopy.
* src/sheet.c (sheet_selection_paste): Simplified as most of the
work is now
* src/clipboard.c (x_selection_received): Perform the paste
operation, moved most of the logic from sheet.c. This does both
internal paste and paste from the X selection (and everything
works the way the user expects it to behave).
1998-09-27 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/cell.h: Cell Copys now can contain both Cells or plain
text.
* src/expr.c (function_call_with_values): Check the return value
from symbol_lookup.
1998-09-27 Miguel de Icaza <miguel@nuclecu.unam.mx>
* plugins/python/python.c (marshal_func): Our scheduled
indentation changes.
* plugins/python/gnumeric_startup.py: Sample file that gets loaded
when the Module is loaded.
1998-09-27 Raja R Harinath <harinath@cs.umn.edu>
* configure.in (GNOME_COMPILE_WARNINGS): New check.
......@@ -31,6 +67,9 @@
1998-09-26 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet-object.c (sheet_view_object_realize): Swap coordinates
before passing to the canvas item.
* plugins/python/python.c (init_plugin): Use the system
installation directory to load the python scripts.
......
......@@ -4,6 +4,9 @@ GNOME Spread Sheet task list
* Sheet
* Auditing
Write the sheet auditing code.
* EDITION
** Object Clipboard
......
......@@ -84,7 +84,7 @@ cell_set_halign (Cell *cell, StyleHAlignFlags halign)
{
g_return_if_fail (cell != NULL);
if (cell->style->halign == (unsigned int) halign)
if (((unsigned int)cell->style->halign) == ((unsigned int) halign))
return;
cell_queue_redraw (cell);
......
......@@ -52,15 +52,24 @@ typedef GList CellList;
#define CELL_TEXT_GET(cell) ((cell)->text ? cell->text->str : cell->entered_text->str)
#define CELL_IS_FORMULA(cell) (cell->entered_text->str [0] == '=')
typedef enum {
CELL_COPY_TYPE_CELL,
CELL_COPY_TYPE_TEXT,
} CellCopyType;
typedef struct {
int col_offset, row_offset; /* Position of the cell */
Cell *cell;
int col_offset, row_offset; /* Position of the cell */
int type;
union {
Cell *cell;
char *text;
} u;
} CellCopy;
typedef GList CellCopyList;
typedef struct {
int cols, rows;
int cols, rows;
CellCopyList *list;
} CellRegion;
......
......@@ -7,6 +7,8 @@
*/
#include <config.h>
#include <gnome.h>
#include <locale.h>
#include <string.h>
#include "gnumeric.h"
#include "gnumeric-util.h"
#include "clipboard.h"
......@@ -14,16 +16,274 @@
#include "render-ascii.h"
/*
* x_selection_clear:
* Callback information.
*
* Callback for the "we lost the X selection" signal
* Passed trough the workbook structure.
*/
static gint
x_selection_clear (GtkWidget *widget, GdkEventSelection *event, Workbook *wb)
typedef struct {
Sheet *dest_sheet;
CellRegion *region;
int dest_col, dest_row;
int paste_flags;
} clipboard_paste_closure_t;
/*
* Pastes a cell in the spreadsheet
*/
static int
paste_cell (Sheet *dest_sheet, Cell *new_cell, int target_col, int target_row, int paste_flags)
{
wb->have_x_selection = FALSE;
sheet_cell_add (dest_sheet, new_cell, target_col, target_row);
if (!(paste_flags & PASTE_FORMULAS)){
if (new_cell->parsed_node){
expr_tree_unref (new_cell->parsed_node);
new_cell->parsed_node = NULL;
}
}
if (new_cell->parsed_node){
if (paste_flags & PASTE_FORMULAS)
cell_formula_relocate (new_cell, target_col, target_row);
else
cell_make_value (new_cell);
}
return TRUE;
cell_render_value (new_cell);
if (!(paste_flags & PASTE_FORMULAS)){
string_unref (new_cell->entered_text);
new_cell->entered_text = string_ref (new_cell->text);
}
sheet_redraw_cell_region (dest_sheet,
target_col, target_row,
target_col, target_row);
return new_cell->parsed_node != 0;
}
static int
paste_cell_flags (Sheet *dest_sheet, int target_col, int target_row,
CellCopy *c_copy, int paste_flags)
{
if (!(paste_flags & (PASTE_FORMULAS | PASTE_VALUES))){
Cell *cell;
cell = sheet_cell_get (dest_sheet,
target_col,
target_row);
if (cell && c_copy->u.cell)
cell_set_style (cell, c_copy->u.cell->style);
} else {
Cell *new_cell;
if (c_copy->type == CELL_COPY_TYPE_CELL){
new_cell = cell_copy (c_copy->u.cell);
return paste_cell (
dest_sheet, new_cell,
target_col, target_row, paste_flags);
} else {
new_cell = sheet_cell_new (dest_sheet,
target_col, target_row);
cell_set_text (new_cell, c_copy->u.text);
}
}
return 0;
}
/*
* do_clipboard_paste_cell_region:
*
* region: a Cell Region that contains information to be pasted
* dest_col: initial column where cell pasting takes place
* dest_row: initial row where cell pasting takes place
* paste_width: boundary for pasting (in columns)
* paste_height: boundar for pasting (in rows)
* paste_flags: controls what gets pasted (see clipboard.h for details
*/
static void
do_clipboard_paste_cell_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;
/* clear the region where we will paste */
if (paste_flags & (PASTE_VALUES | PASTE_FORMULAS))
sheet_clear_region (dest_sheet,
dest_col, dest_row,
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 + paste_width - 1,
dest_row + paste_height - 1);
/* Paste each element */
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;
formulas |= paste_cell_flags (
dest_sheet, target_col, target_row,
c_copy, 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 if required */
if (formulas)
workbook_recalc (dest_sheet->workbook);
}
/*
* Creates a CellRegion based on the X selection
*
* We use \t, ; and "," as cell separators
* \n is a line separator
*/
static CellRegion *
x_selection_to_cell_region (char *data, int len)
{
CellRegion *cr;
int cols = 0, cur_col = 0;
int rows = 0;
GList *list = NULL;
char *p = data;
for (;len; len--, p++){
if (*p == '\t' || *p == ';' || *p == ',' || *p == '\n'){
CellCopy *c_copy;
char *text;
if (p != data){
text = g_malloc (p-data);
text = strncpy (text, data, p-data-1);
text [p-data-1] = 0;
c_copy = g_new (CellCopy, 1);
c_copy->type = CELL_COPY_TYPE_TEXT;
c_copy->col_offset = cur_col;
c_copy->row_offset = rows;
c_copy->u.text = text;
list = g_list_prepend (list, c_copy);
}
if (*p == '\n')
rows++;
else {
if (cur_col > cols)
cols = cur_col;
cur_col++;
}
data = p;
}
}
/* Return the CellRegion */
cr = g_new (CellRegion, 1);
cr->list = list;
cr->cols = cols;
cr->rows = rows;
return cr;
}
/*
* 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, gpointer data)
{
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;
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;
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 = pc->dest_col + paste_width - 1;
end_row = pc->dest_row + paste_height - 1;
/* Do the actual paste operation */
do_clipboard_paste_cell_region (
content, pc->dest_sheet,
pc->dest_col, pc->dest_row,
paste_width, paste_height,
pc->paste_flags);
sheet_cursor_set (pc->dest_sheet,
pc->dest_col, pc->dest_row,
end_col, end_row);
sheet_selection_reset_only (pc->dest_sheet);
sheet_selection_append (pc->dest_sheet, pc->dest_col, pc->dest_row);
sheet_selection_extend_to (pc->dest_sheet, end_col, end_row);
/* Release the resources we used */
if (sel->length < 0)
clipboard_release (content);
/* Remove our used resources */
g_free (wb->clipboard_paste_callback_data);
wb->clipboard_paste_callback_data = NULL;
}
/*
......@@ -47,20 +307,16 @@ x_selection_handler (GtkWidget *widget, GtkSelectionData *selection_data, gpoint
}
/*
* x_selection_received
* x_selection_clear:
*
* Invoked when the selection has been received by our application.
* This is triggered by a call we do to gtk_selection_convert.
* Callback for the "we lost the X selection" signal
*/
static void
x_selection_received (GtkWidget *widget, GtkSelectionData *sel, gpointer data)
static gint
x_selection_clear (GtkWidget *widget, GdkEventSelection *event, Workbook *wb)
{
Workbook *wb = data;
wb->have_x_selection = FALSE;
/* Did X provide any selection? */
if (sel->length < 0){
}
return TRUE;
}
/*
......@@ -92,7 +348,7 @@ x_clipboard_bind_workbook (Workbook *wb)
* This routine exports a CellRegion to the X selection
*/
static void
clipboard_export_cell_region (Workbook *wb, CellRegion *region)
clipboard_export_cell_region (Workbook *wb)
{
wb->have_x_selection = gtk_selection_owner_set (
current_workbook->toplevel,
......@@ -113,14 +369,15 @@ clipboard_append_cell (Sheet *sheet, int col, int row, Cell *cell, void *user_da
copy = g_new (CellCopy, 1);
copy->cell = cell_copy (cell);
copy->type = CELL_COPY_TYPE_CELL;
copy->u.cell = cell_copy (cell);
copy->col_offset = col - c->base_col;
copy->row_offset = row - c->base_row;
/* Now clear the traces and dependencies on the copied Cell */
copy->cell->col = NULL;
copy->cell->row = NULL;
copy->cell->sheet = NULL;
copy->u.cell->col = NULL;
copy->u.cell->row = NULL;
copy->u.cell->sheet = NULL;
c->r->list = g_list_prepend (c->r->list, copy);
......@@ -153,126 +410,65 @@ clipboard_copy_cell_range (Sheet *sheet, int start_col, int start_row, int end_c
sheet, 1, start_col, start_row, end_col, end_row,
clipboard_append_cell, &c);
clipboard_export_cell_region (sheet->workbook, c.r);
clipboard_export_cell_region (sheet->workbook);
return c.r;
}
static int
paste_cell (Sheet *dest_sheet, Cell *new_cell, int target_col, int target_row, int paste_flags)
{
sheet_cell_add (dest_sheet, new_cell, target_col, target_row);
if (!(paste_flags & PASTE_FORMULAS)){
if (new_cell->parsed_node){
expr_tree_unref (new_cell->parsed_node);
new_cell->parsed_node = NULL;
}
}
if (new_cell->parsed_node){
if (paste_flags & PASTE_FORMULAS)
cell_formula_relocate (new_cell, target_col, target_row);
else
cell_make_value (new_cell);
}
cell_render_value (new_cell);
if (!(paste_flags & PASTE_FORMULAS)){
string_unref (new_cell->entered_text);
new_cell->entered_text = string_ref (new_cell->text);
}
sheet_redraw_cell_region (dest_sheet,
target_col, target_row,
target_col, target_row);
return new_cell->parsed_node != 0;
}
/*