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

Cells from the clipboard do not have a Sheet parameter attached.

1998-10-06  Miguel de Icaza  <miguel@nuclecu.unam.mx>

	* src/cell.c (cell_modified): Cells from the clipboard do not have
	a Sheet parameter attached.

	* src/sheet.c (sheet_cell_add): Check the computed style:  if the
	computed style includes a format, then turn on the cell flag for
	format is set to avoid the auto guess of cell content.
	(sheet_style_compute): Now can return the flags of the style that
	were not part of the default style.

	* src/file.c (dialog_query_load_file, workbook_save_as): Put the
	window close to the mouse.

	* src/workbook.c (sheet_check_dirty, workbook_close): Do not
	cancel without warning the user if the workbook has changed.
	(workbook_new, workbook_can_close, workbook_window_destroy,
	quit_cmd, close_cmd): Reorganized the code to suit the new code to
	prevent inadvertent quits.
parent 3ceff682
1998-10-06 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/cell.c (cell_modified): Cells from the clipboard do not have
a Sheet parameter attached.
* src/sheet.c (sheet_cell_add): Check the computed style: if the
computed style includes a format, then turn on the cell flag for
format is set to avoid the auto guess of cell content.
(sheet_style_compute): Now can return the flags of the style that
were not part of the default style.
* src/file.c (dialog_query_load_file, workbook_save_as): Put the
window close to the mouse.
* src/workbook.c (sheet_check_dirty, workbook_close): Do not
cancel without warning the user if the workbook has changed.
(workbook_new, workbook_can_close, workbook_window_destroy,
quit_cmd, close_cmd): Reorganized the code to suit the new code to
prevent inadvertent quits.
1998-10-06 Adrian Likins <adrian@gimp.or>
* doc/images/*.gif: gifs for documenting the button bar
......
1998-10-06 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/cell.c (cell_modified): Cells from the clipboard do not have
a Sheet parameter attached.
* src/sheet.c (sheet_cell_add): Check the computed style: if the
computed style includes a format, then turn on the cell flag for
format is set to avoid the auto guess of cell content.
(sheet_style_compute): Now can return the flags of the style that
were not part of the default style.
* src/file.c (dialog_query_load_file, workbook_save_as): Put the
window close to the mouse.
* src/workbook.c (sheet_check_dirty, workbook_close): Do not
cancel without warning the user if the workbook has changed.
(workbook_new, workbook_can_close, workbook_window_destroy,
quit_cmd, close_cmd): Reorganized the code to suit the new code to
prevent inadvertent quits.
1998-10-06 Adrian Likins <adrian@gimp.or>
* doc/images/*.gif: gifs for documenting the button bar
......
......@@ -16,7 +16,7 @@ modify the sources directly on the CVS repository, please keep those
things in mind. Specifically, this means:
- Make sure your code does not generate warnings at all.
- Please follow the code style in Gnumeric.
- Please follow the coding style used Gnumeric.
The Gnumeric coding style.
--------------------------
......@@ -62,7 +62,10 @@ modular chunks (as detailed by Linus).
- Do not submit code that is just a temporary workaround for a
full fledged feature. Ie, dont submit a quick hack at
"search text" which is not designed to be expanded upon. I
do not want to maintain half done features.
do not want to maintain limited features.
Better submit an implementation has been designed to be
expanded, enhanced, even if it is not completely finished.
- It is more important to be correct than to be fast.
......@@ -73,7 +76,7 @@ modular chunks (as detailed by Linus).
- It is more important to keep the code maintainable and
readable than to be fast. If you have a great idea about
optimizing the code, make sure it is implemented cleanly,
that there is a clean and maintainable way to do it:
that there is a clean and maintainable way to do it:
- Fast code that is difficult to maintain has no place in
Gnumeric and will be dropped.
......
1998-10-06 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/cell.c (cell_modified): Cells from the clipboard do not have
a Sheet parameter attached.
* src/sheet.c (sheet_cell_add): Check the computed style: if the
computed style includes a format, then turn on the cell flag for
format is set to avoid the auto guess of cell content.
(sheet_style_compute): Now can return the flags of the style that
were not part of the default style.
* src/file.c (dialog_query_load_file, workbook_save_as): Put the
window close to the mouse.
* src/workbook.c (sheet_check_dirty, workbook_close): Do not
cancel without warning the user if the workbook has changed.
(workbook_new, workbook_can_close, workbook_window_destroy,
quit_cmd, close_cmd): Reorganized the code to suit the new code to
prevent inadvertent quits.
1998-10-06 Adrian Likins <adrian@gimp.or>
* doc/images/*.gif: gifs for documenting the button bar
......
1998-10-06 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/cell.c (cell_modified): Cells from the clipboard do not have
a Sheet parameter attached.
* src/sheet.c (sheet_cell_add): Check the computed style: if the
computed style includes a format, then turn on the cell flag for
format is set to avoid the auto guess of cell content.
(sheet_style_compute): Now can return the flags of the style that
were not part of the default style.
* src/file.c (dialog_query_load_file, workbook_save_as): Put the
window close to the mouse.
* src/workbook.c (sheet_check_dirty, workbook_close): Do not
cancel without warning the user if the workbook has changed.
(workbook_new, workbook_can_close, workbook_window_destroy,
quit_cmd, close_cmd): Reorganized the code to suit the new code to
prevent inadvertent quits.
1998-10-06 Adrian Likins <adrian@gimp.or>
* doc/images/*.gif: gifs for documenting the button bar
......
......@@ -2,9 +2,6 @@
GNOME Spread Sheet task list
* Modified status
We need to keep track of modifications to the workbook.
* Number formatting
......
......@@ -1022,6 +1022,9 @@ callback_function_sum (Sheet *sheet, Value *value, char **error_string, void *cl
result->v.v_float = v + value->v.v_float;
}
break;
case VALUE_STRING:
break;
default:
g_warning ("Unknown VALUE type in callback_function_sum");
......
......@@ -29,8 +29,10 @@ static inline void
cell_modified (Cell *cell)
{
Sheet *sheet = cell->sheet;
sheet->modified = TRUE;
/* Cells from the clipboard do not have a sheet attached */
if (sheet)
sheet->modified = TRUE;
}
void
......
......@@ -34,6 +34,7 @@ workbook_save_as (Workbook *wb)
GTK_SIGNAL_FUNC (set_ok), &accepted);
gtk_signal_connect (GTK_OBJECT (fsel->cancel_button), "clicked",
GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
gtk_window_position (GTK_WINDOW (fsel), GTK_WIN_POS_MOUSE);
/* Run the dialog */
gtk_widget_show (GTK_WIDGET (fsel));
......@@ -79,6 +80,7 @@ dialog_query_load_file (void)
GTK_SIGNAL_FUNC (set_ok), &accepted);
gtk_signal_connect (GTK_OBJECT (fsel->cancel_button), "clicked",
GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
gtk_window_position (GTK_WINDOW (fsel), GTK_WIN_POS_MOUSE);
/* Run the dialog */
gtk_widget_show (GTK_WIDGET (fsel));
......
......@@ -1022,6 +1022,9 @@ callback_function_sum (Sheet *sheet, Value *value, char **error_string, void *cl
result->v.v_float = v + value->v.v_float;
}
break;
case VALUE_STRING:
break;
default:
g_warning ("Unknown VALUE type in callback_function_sum");
......
......@@ -691,6 +691,9 @@ split_time (gdouble number)
calc_new_date (&tm.tm_year, &tm.tm_mon, &tm.tm_mday, number-1.0);
tm.tm_wday = day_of_week (tm.tm_year, tm.tm_mon, tm.tm_mday);
if (tm.tm_wday == 7)
tm.tm_wday = 0;
/* printf ("Year: %d Month: %d, Day: %d\n", tm.tm_year, tm.tm_mon, tm.tm_mday); */
tm.tm_mon--;
......
......@@ -1022,6 +1022,9 @@ callback_function_sum (Sheet *sheet, Value *value, char **error_string, void *cl
result->v.v_float = v + value->v.v_float;
}
break;
case VALUE_STRING:
break;
default:
g_warning ("Unknown VALUE type in callback_function_sum");
......
......@@ -133,11 +133,13 @@ item_edit_reconfigure (GnomeCanvasItem *item)
item->x2 = x + w;
item->y2 = y + h;
gnome_canvas_group_child_bounds (GNOME_CANVAS_GROUP (item->parent), item);
gnome_canvas_group_child_bounds (
GNOME_CANVAS_GROUP (item->parent), item);
if (item_edit->style)
style_destroy (item_edit->style);
item_edit->style = sheet_style_compute (item_edit->sheet, item_edit->col, item_edit->row);
item_edit->style = sheet_style_compute (
item_edit->sheet, item_edit->col, item_edit->row, NULL);
}
/*
......
......@@ -242,17 +242,34 @@ sheet_view_col_size_changed (ItemBar *item_bar, int col, int width, SheetView *s
{
Sheet *sheet = sheet_view->sheet;
GList *l;
gboolean size_change_selected = FALSE;
if (sheet_is_all_selected (sheet))
sheet_col_info_set_width (sheet, &sheet->default_col_style, width);
else {
for (l = sheet->cols_info; l; l = l->next){
ColRowInfo *ci = l->data;
if (ci->selected) {
if (ci->pos == col) {
size_change_selected = TRUE;
break;
}
}
}
for (l = sheet->cols_info; l; l = l->next){
ColRowInfo *ci = l->data;
if (ci->selected)
sheet_col_set_width (sheet, ci->pos, width);
if (size_change_selected) {
for (l = sheet->cols_info; l; l = l->next){
ColRowInfo *ci = l->data;
if (ci->selected)
sheet_col_set_width (sheet, ci->pos, width);
}
} else {
sheet_col_set_width (sheet, col, width);
}
}
sheet_col_set_width (sheet, col, width);
gnumeric_sheet_compute_visible_ranges (GNUMERIC_SHEET (sheet_view->sheet_view));
}
......@@ -280,17 +297,32 @@ sheet_view_row_size_changed (ItemBar *item_bar, int row, int height, SheetView *
{
Sheet *sheet = sheet_view->sheet;
GList *l;
gboolean size_change_selected = FALSE;
if (sheet_is_all_selected (sheet))
sheet_row_info_set_height (sheet, &sheet->default_row_style, height, TRUE);
for (l = sheet->rows_info; l; l = l->next){
ColRowInfo *ri = l->data;
if (ri->selected)
sheet_row_set_height (sheet, ri->pos, height, TRUE);
else {
for (l = sheet->rows_info; l; l = l->next){
ColRowInfo *ri = l->data;
if (ri->selected) {
if (ri->pos == row) {
size_change_selected = TRUE;
break;
}
}
}
if (size_change_selected) {
for (l = sheet->rows_info; l; l = l->next){
ColRowInfo *ri = l->data;
if (ri->selected)
sheet_row_set_height (sheet, ri->pos, height, TRUE);
}
} else {
sheet_row_set_height (sheet, row, height, TRUE);
}
}
sheet_row_set_height (sheet, row, height, TRUE);
gnumeric_sheet_compute_visible_ranges (GNUMERIC_SHEET (sheet_view->sheet_view));
}
......
......@@ -33,8 +33,12 @@ window_to_world (GnomeCanvas *canvas, gdouble *x, gdouble *y)
#define DISPLAY_X1(canvas) (GNOME_CANVAS (canvas)->layout.xoffset)
#define DISPLAY_Y1(canvas) (GNOME_CANVAS (canvas)->layout.yoffset)
*x = canvas->scroll_x1 + (*x + DISPLAY_X1 (canvas) - canvas->zoom_xofs) / canvas->pixels_per_unit;
*y = canvas->scroll_y1 + (*y + DISPLAY_Y1 (canvas) - canvas->zoom_yofs) / canvas->pixels_per_unit;
*x = canvas->scroll_x1 +
(*x + DISPLAY_X1 (canvas) - canvas->zoom_xofs) /
canvas->pixels_per_unit;
*y = canvas->scroll_y1 +
(*y + DISPLAY_Y1 (canvas) - canvas->zoom_yofs) /
canvas->pixels_per_unit;
}
static void
......@@ -129,7 +133,10 @@ sheet_object_create_filled (Sheet *sheet, int type,
* Creates a line object
*/
SheetObject *
sheet_object_create_line (Sheet *sheet, int is_arrow, double x1, double y1, double x2, double y2, char *color, int w)
sheet_object_create_line (Sheet *sheet, int is_arrow,
double x1, double y1,
double x2, double y2,
char *color, int w)
{
SheetObject *so;
......@@ -477,6 +484,8 @@ sheet_finish_object_creation (Sheet *sheet, SheetObject *o)
sheet_set_mode_type (sheet, SHEET_MODE_OBJECT_SELECTED);
sheet_release_coords (sheet);
sheet->modified = TRUE;
/* Disconnect the signal handlers for object creation */
for (l = sheet->sheet_views; l; l = l->next){
......@@ -631,6 +640,8 @@ sheet_object_destroy (SheetObject *object)
sheet->objects = g_list_remove (sheet->objects, object);
sheet->modified = TRUE;
g_free (object);
}
......
......@@ -242,17 +242,34 @@ sheet_view_col_size_changed (ItemBar *item_bar, int col, int width, SheetView *s
{
Sheet *sheet = sheet_view->sheet;
GList *l;
gboolean size_change_selected = FALSE;
if (sheet_is_all_selected (sheet))
sheet_col_info_set_width (sheet, &sheet->default_col_style, width);
else {
for (l = sheet->cols_info; l; l = l->next){
ColRowInfo *ci = l->data;
if (ci->selected) {
if (ci->pos == col) {
size_change_selected = TRUE;
break;
}
}
}
for (l = sheet->cols_info; l; l = l->next){
ColRowInfo *ci = l->data;
if (ci->selected)
sheet_col_set_width (sheet, ci->pos, width);
if (size_change_selected) {
for (l = sheet->cols_info; l; l = l->next){
ColRowInfo *ci = l->data;
if (ci->selected)
sheet_col_set_width (sheet, ci->pos, width);
}
} else {
sheet_col_set_width (sheet, col, width);
}
}
sheet_col_set_width (sheet, col, width);
gnumeric_sheet_compute_visible_ranges (GNUMERIC_SHEET (sheet_view->sheet_view));
}
......@@ -280,17 +297,32 @@ sheet_view_row_size_changed (ItemBar *item_bar, int row, int height, SheetView *
{
Sheet *sheet = sheet_view->sheet;
GList *l;
gboolean size_change_selected = FALSE;
if (sheet_is_all_selected (sheet))
sheet_row_info_set_height (sheet, &sheet->default_row_style, height, TRUE);
for (l = sheet->rows_info; l; l = l->next){
ColRowInfo *ri = l->data;
if (ri->selected)
sheet_row_set_height (sheet, ri->pos, height, TRUE);
else {
for (l = sheet->rows_info; l; l = l->next){
ColRowInfo *ri = l->data;
if (ri->selected) {
if (ri->pos == row) {
size_change_selected = TRUE;
break;
}
}
}
if (size_change_selected) {
for (l = sheet->rows_info; l; l = l->next){
ColRowInfo *ri = l->data;
if (ri->selected)
sheet_row_set_height (sheet, ri->pos, height, TRUE);
}
} else {
sheet_row_set_height (sheet, row, height, TRUE);
}
}
sheet_row_set_height (sheet, row, height, TRUE);
gnumeric_sheet_compute_visible_ranges (GNUMERIC_SHEET (sheet_view->sheet_view));
}
......
......@@ -831,7 +831,7 @@ sheet_update_controls (Sheet *sheet)
SheetSelection *ss = sheet->selections->data;
Style *style;
style = sheet_style_compute (sheet, ss->start_col, ss->start_row);
style = sheet_style_compute (sheet, ss->start_col, ss->start_row, NULL);
bold_first = style->font->hint_is_bold;
italic_first = style->font->hint_is_italic;
style_destroy (style);
......@@ -1868,9 +1868,14 @@ sheet_cell_add (Sheet *sheet, Cell *cell, int col, int row)
cell->col = sheet_col_get (sheet, col);
cell->row = sheet_row_get (sheet, row);
if (!cell->style)
cell->style = sheet_style_compute (sheet, col, row);
if (!cell->style){
int flags;
cell->style = sheet_style_compute (sheet, col, row, &flags);
if (flags & STYLE_FORMAT)
cell->flags |= CELL_FORMAT_SET;
}
cell_calc_dimensions (cell);
sheet_cell_add_to_hash (sheet, cell);
......@@ -2884,8 +2889,17 @@ sheet_style_attach (Sheet *sheet, int start_col, int start_row, int end_col, int
sheet->style_list = g_list_prepend (sheet->style_list, sr);
}
/*
* sheet_style_compute
* @sheet: Which sheet we are looking up
* @col: column
* @row: row
* @non_default: A pointer where we store the attributes
* the cell has which are not part of the
* default style.
*/
Style *
sheet_style_compute (Sheet *sheet, int col, int row)
sheet_style_compute (Sheet *sheet, int col, int row, int *non_default)
{
GList *l;
Style *style;
......@@ -2898,11 +2912,22 @@ sheet_style_compute (Sheet *sheet, int col, int row)
/* Look in the styles applied to the sheet */
for (l = sheet->style_list; l; l = l->next){
StyleRegion *sr = l->data;
int is_default_style = l->next == NULL;
int flags;
flags = style->valid_flags;
if (range_contains (&sr->range, col, row)){
style_merge_to (style, sr->style);
if (style->valid_flags == STYLE_ALL)
if (style->valid_flags == STYLE_ALL){
if (non_default){
if (!is_default_style)
*non_default = STYLE_ALL;
else
*non_default = flags;
}
return style;
}
}
}
......
......@@ -257,7 +257,9 @@ void sheet_col_set_selection (Sheet *sheet,
void sheet_row_set_selection (Sheet *sheet,
ColRowInfo *ri, int value);
Style *sheet_style_compute (Sheet *sheet, int col, int row);
Style *sheet_style_compute (Sheet *sheet,
int col, int row,
int *non_default_style_flags);
/* Redraw */
void sheet_compute_visible_ranges (Sheet *sheet);
......
......@@ -28,6 +28,8 @@
Workbook *current_workbook;
static int workbook_count;
static GList *workbook_list = NULL;
static void
new_cmd (void)
{
......@@ -142,8 +144,6 @@ change_selection_font (Workbook *wb, int idx, char *new[])
}
}
/* FIXME: Should attach the bold style here to the cell range */
g_list_free (cells);
}
......@@ -210,15 +210,137 @@ create_ellipse_cmd (GtkWidget *widget, Workbook *wb)
}
static void
quit_cmd (void)
workbook_do_destroy (Workbook *wb)
{
if (wb->filename)
g_free (wb->filename);
g_list_free (wb->eval_queue);
if (wb->auto_expr){
expr_tree_unref (wb->auto_expr);
string_unref (wb->auto_expr_desc);
}
workbook_list = g_list_remove (workbook_list, wb);
workbook_count--;
if (workbook_count == 0)
gtk_main_quit ();
}
void
workbook_destroy (Workbook *wb)
{
gtk_main_quit ();
gtk_widget_destroy (wb->toplevel);
}
static void
workbook_widget_destroy (GtkWidget *widget, Workbook *wb)
{
workbook_do_destroy (wb);
}
typedef enum {
CLOSE_DENY,
CLOSE_ALLOW,
CLOSE_RECHECK
} CloseAction;
static void
sheet_check_dirty (gpointer key, gpointer value, gpointer user_data)
{
Sheet *sheet = value;
GtkWidget *d, *l;
int *allow_close = user_data;
int button;
char *f, *s;
if (!sheet->modified)
return;
if (*allow_close != CLOSE_ALLOW)
return;
d = gnome_dialog_new (
_("Warning"),
GNOME_STOCK_BUTTON_YES,
GNOME_STOCK_BUTTON_NO,
GNOME_STOCK_BUTTON_CANCEL,
NULL);
if (sheet->workbook->filename)
f = g_basename (sheet->workbook->filename);
else
f = "";
s = g_copy_strings (_("Workbook "), f,
_(" has unsaved changes, save them?"),
NULL);
l = gtk_label_new (s);
gtk_widget_show (l);
g_free (s);
gtk_box_pack_start (GTK_BOX (GNOME_DIALOG(d)->vbox), l, TRUE, TRUE, 0);
gtk_window_position (GTK_WINDOW (d), GTK_WIN_POS_MOUSE);
button = gnome_dialog_run (GNOME_DIALOG (d));
if (button == -1 || button == 2){
*allow_close = CLOSE_DENY;
} else if (button == 0){
workbook_save (sheet->workbook);
*allow_close = CLOSE_RECHECK;
}
gtk_widget_destroy (d);
}
static int
workbook_can_close (Workbook *wb)
{
CloseAction allow_close;
do {
allow_close = CLOSE_ALLOW;
g_hash_table_foreach (wb->sheets, sheet_check_dirty,
&allow_close);
} while (allow_close == CLOSE_RECHECK);
g_assert (allow_close == CLOSE_ALLOW || allow_close == CLOSE_DENY);
return allow_close == CLOSE_ALLOW;
}
static void
close_cmd (GtkWidget *widget, Workbook *wb)
{
workbook_destroy (wb);
if (workbook_can_close (wb))
workbook_destroy (wb);
}
static void
quit_cmd (void)
{
GList *l, *n = NULL;
/*
* Duplicate the list as the workbook_list is modified during
* workbook destruction
*/
for (l = workbook_list; l; l = l->next)
n = g_list_prepend (n, l->data);
for (l = n; l; l = l->next){
Workbook *wb = l->data;
if (workbook_can_close (wb))
workbook_destroy (wb);
}
g_list_free (n);
}
static void
......@@ -926,29 +1048,6 @@ workbook_set_focus (GtkWindow *window, GtkWidget *focus, Workbook *wb)
workbook_focus_current_sheet (wb);
}
void
workbook_destroy (Workbook *wb)
{
if (wb->filename)
g_free (wb->filename);
g_list_free (wb->eval_queue);
gtk_widget_destroy (wb->toplevel);
if (wb->auto_expr){
expr_tree_unref (wb->auto_expr);
string_unref (wb->auto_expr_desc);
}
}
static void
workbook_close (void)
{
workbook_count--;
if (workbook_count == 0)
gtk_main_quit ();
}
/*
* Sets up the workbook.
* Right now it is adding some decorations to the window,
......@@ -985,15 +1084,22 @@ workbook_new (void)
gtk_signal_connect (
GTK_OBJECT (wb->toplevel), "destroy",
GTK_SIGNAL_FUNC (workbook_close), wb);
GTK_SIGNAL_FUNC (workbook_widget_destroy), wb);
/* clipboard setup */
x_clipboard_bind_workbook (wb);
/* delete_event */
gtk_signal_connect (
GTK_OBJECT (wb->toplevel), "delete_event",
GTK_SIGNAL_FUNC (workbook_can_close), wb);
/* Set the default operation to be performed over selections */
workbook_set_auto_expr (wb, "SUM", "SUM(SELECTION())");
workbook_count++;
workbook_list = g_list_prepend (workbook_list, wb);
gtk_widget_show_all (wb->table);
return wb;
......
......@@ -582,6 +582,8 @@ Sheet *gnumericReadXmlSheet (const char *filename)
g_hash_table_destroy (ctxt.nameTable);
xmlFreeDoc (res);
sheet->modified = FALSE;
return sheet;
}
......@@ -625,6 +627,7 @@ gnumericWriteXmlSheet (Sheet * sheet, const char *filename)
xmlSetDocCompressMode (xml, 9);
ret = xmlSaveFile (filename, xml);
xmlFreeDoc (xml);
sheet->modified = FALSE;
if (ret < 0)
return -1;
return 0;
......@@ -1380,6 +1383,7 @@ writeXmlSheet (parseXmlContextPtr ctxt, Sheet *sheet)
cells = xmlNewChild (cur, ctxt->ns, "Cells", NULL);
ctxt->parent = cells;
g_hash_table_foreach (sheet->cell_hash, writeXmlCellTo, ctxt);
sheet->modified = 0;
return cur;
}
......