Commit ba7fbc1f authored by Arturo Espinosa's avatar Arturo Espinosa

Lots of changes during the weekend:



Lots of changes during the weekend:

	- New style management code:  All styles are now managed by
	  regions on a sheet (the default region, is attached to the
	  complete sheet).

	- Styles can now be partial: Only some parts of the style
	  might be valid (this is very important).

	- Insert column/Insert row/Shift rows has been fixed and
	  it now computes properly the dependencies on any
	  data change.

	- Linking/unlinking formulas now takes care also of
	  adding/removing the dependencies of the cell.

Miguel.
parent f17355a6
1998-08-23 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet.c
* src/dialog-cell-format.c (apply_align_format): Actually store
the style selection on the computed style.
* src/eval.c (intersects): Write in terms of range_contains.
* src/utils.c (range_contains): New utility routine.
* src/style.c (style_destroy): It now allow
(style_merge_to): Implement new routine for gradually compute the
full value of a style.
(style_duplicate): Make the routine duplicate only
the valid fields, not all of them.
(style_destory): account for the fact that now we might have
non-complete styles.
(sheet_style_compute): Make it fully functional.
* src/sheet.c (sheet_cell_formula_link,
sheet_cell_formula_unlink): Now we maintain the dependencies at
formula link/unlink time
(sheet_shift_row, shift_insert_col, shift_insert_row): Compute the
dependencies for any changed cells and recalculate.
(sheet_style_attach): Implement.
(sheet_destroy): Destroy the column and row information.
* src/item-grid.c (context_insert_cmd): Use the
dialog_insert_cells instead of the dummy test code we had before.
* src/workbook.c (insert_cols_cmd, insert_rows_cmd): Implement.
1998-08-22 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet.c (sheet_redraw_all): Redraw also the column and row
bars.
(sheet_insert_row): Fix. I was accessing the wrong information.
(sheet_insert_row): Fix. I was accessing the wrong information;
Fix, on the row selection code;
(sheet_cell_add): Recompute the dimensions properly of the cell
after insertion (this is to fit the use of this routine in a new
context).
(sheet_shift_row): Fix the
* src/dialog-insert-cells.c (dialog_insert_cells): Learn to use
GtkCauldroun's way of dealing with radio buttons.
......
1998-08-23 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet.c
* src/dialog-cell-format.c (apply_align_format): Actually store
the style selection on the computed style.
* src/eval.c (intersects): Write in terms of range_contains.
* src/utils.c (range_contains): New utility routine.
* src/style.c (style_destroy): It now allow
(style_merge_to): Implement new routine for gradually compute the
full value of a style.
(style_duplicate): Make the routine duplicate only
the valid fields, not all of them.
(style_destory): account for the fact that now we might have
non-complete styles.
(sheet_style_compute): Make it fully functional.
* src/sheet.c (sheet_cell_formula_link,
sheet_cell_formula_unlink): Now we maintain the dependencies at
formula link/unlink time
(sheet_shift_row, shift_insert_col, shift_insert_row): Compute the
dependencies for any changed cells and recalculate.
(sheet_style_attach): Implement.
(sheet_destroy): Destroy the column and row information.
* src/item-grid.c (context_insert_cmd): Use the
dialog_insert_cells instead of the dummy test code we had before.
* src/workbook.c (insert_cols_cmd, insert_rows_cmd): Implement.
1998-08-22 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet.c (sheet_redraw_all): Redraw also the column and row
bars.
(sheet_insert_row): Fix. I was accessing the wrong information.
(sheet_insert_row): Fix. I was accessing the wrong information;
Fix, on the row selection code;
(sheet_cell_add): Recompute the dimensions properly of the cell
after insertion (this is to fit the use of this routine in a new
context).
(sheet_shift_row): Fix the
* src/dialog-insert-cells.c (dialog_insert_cells): Learn to use
GtkCauldroun's way of dealing with radio buttons.
......
1998-08-23 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet.c
* src/dialog-cell-format.c (apply_align_format): Actually store
the style selection on the computed style.
* src/eval.c (intersects): Write in terms of range_contains.
* src/utils.c (range_contains): New utility routine.
* src/style.c (style_destroy): It now allow
(style_merge_to): Implement new routine for gradually compute the
full value of a style.
(style_duplicate): Make the routine duplicate only
the valid fields, not all of them.
(style_destory): account for the fact that now we might have
non-complete styles.
(sheet_style_compute): Make it fully functional.
* src/sheet.c (sheet_cell_formula_link,
sheet_cell_formula_unlink): Now we maintain the dependencies at
formula link/unlink time
(sheet_shift_row, shift_insert_col, shift_insert_row): Compute the
dependencies for any changed cells and recalculate.
(sheet_style_attach): Implement.
(sheet_destroy): Destroy the column and row information.
* src/item-grid.c (context_insert_cmd): Use the
dialog_insert_cells instead of the dummy test code we had before.
* src/workbook.c (insert_cols_cmd, insert_rows_cmd): Implement.
1998-08-22 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet.c (sheet_redraw_all): Redraw also the column and row
bars.
(sheet_insert_row): Fix. I was accessing the wrong information.
(sheet_insert_row): Fix. I was accessing the wrong information;
Fix, on the row selection code;
(sheet_cell_add): Recompute the dimensions properly of the cell
after insertion (this is to fit the use of this routine in a new
context).
(sheet_shift_row): Fix the
* src/dialog-insert-cells.c (dialog_insert_cells): Learn to use
GtkCauldroun's way of dealing with radio buttons.
......
1998-08-23 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet.c
* src/dialog-cell-format.c (apply_align_format): Actually store
the style selection on the computed style.
* src/eval.c (intersects): Write in terms of range_contains.
* src/utils.c (range_contains): New utility routine.
* src/style.c (style_destroy): It now allow
(style_merge_to): Implement new routine for gradually compute the
full value of a style.
(style_duplicate): Make the routine duplicate only
the valid fields, not all of them.
(style_destory): account for the fact that now we might have
non-complete styles.
(sheet_style_compute): Make it fully functional.
* src/sheet.c (sheet_cell_formula_link,
sheet_cell_formula_unlink): Now we maintain the dependencies at
formula link/unlink time
(sheet_shift_row, shift_insert_col, shift_insert_row): Compute the
dependencies for any changed cells and recalculate.
(sheet_style_attach): Implement.
(sheet_destroy): Destroy the column and row information.
* src/item-grid.c (context_insert_cmd): Use the
dialog_insert_cells instead of the dummy test code we had before.
* src/workbook.c (insert_cols_cmd, insert_rows_cmd): Implement.
1998-08-22 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet.c (sheet_redraw_all): Redraw also the column and row
bars.
(sheet_insert_row): Fix. I was accessing the wrong information.
(sheet_insert_row): Fix. I was accessing the wrong information;
Fix, on the row selection code;
(sheet_cell_add): Recompute the dimensions properly of the cell
after insertion (this is to fit the use of this routine in a new
context).
(sheet_shift_row): Fix the
* src/dialog-insert-cells.c (dialog_insert_cells): Learn to use
GtkCauldroun's way of dealing with radio buttons.
......
......@@ -10,7 +10,6 @@ cell_formula_changed (Cell *cell)
g_return_if_fail (cell != NULL);
sheet_cell_formula_link (cell);
cell_add_dependencies (cell);
cell_queue_recalc (cell);
}
......@@ -76,14 +75,17 @@ cell_calc_dimensions (Cell *cell)
GdkFont *font;
g_return_if_fail (cell != NULL);
if (cell->text){
rendered_text = CELL_TEXT_GET (cell);
font = cell->style->font->font;
rendered_text = CELL_TEXT_GET (cell);
font = cell->style->font->font;
cell->width = cell->col->margin_a + cell->col->margin_b +
gdk_text_width (font, rendered_text, strlen (rendered_text));
cell->height = font->ascent + font->descent;
cell->width = cell->col->margin_a + cell->col->margin_b +
gdk_text_width (font, rendered_text, strlen (rendered_text));
cell->height = font->ascent + font->descent;
} else
cell->width = cell->col->margin_a + cell->col->margin_b;
}
/*
......@@ -141,7 +143,6 @@ cell_set_text (Cell *cell, char *text)
cell->entered_text = string_get (text);
if (cell->parsed_node){
cell_drop_dependencies (cell);
sheet_cell_formula_unlink (cell);
expr_tree_unref (cell->parsed_node);
......
......@@ -11,7 +11,6 @@ typedef struct {
typedef struct {
int pos; /* the column or row number */
Style *style; /* if existant, this row style */
/* The height */
int units; /* In units */
......
......@@ -57,13 +57,13 @@ dependency_equal (gconstpointer v, gconstpointer v2)
if (r1->sheet != r2->sheet)
return 0;
if (r1->start_col != r2->start_col)
if (r1->range.start_col != r2->range.start_col)
return 0;
if (r1->start_row != r2->start_row)
if (r1->range.start_row != r2->range.start_row)
return 0;
if (r1->end_col != r2->end_col)
if (r1->range.end_col != r2->range.end_col)
return 0;
if (r1->end_row != r2->end_row)
if (r1->range.end_row != r2->range.end_row)
return 0;
return 1;
......@@ -77,8 +77,8 @@ dependency_hash_func (gconstpointer v)
{
const DependencyRange *r = v;
return ((((r->start_row << 8) + r->end_row) << 8) +
(r->start_col << 8) + (r->end_col));
return ((((r->range.start_row << 8) + r->range.end_row) << 8) +
(r->range.start_col << 8) + (r->range.end_col));
}
/*
......@@ -104,8 +104,8 @@ add_cell_range_deps (Cell *cell, CellRef *a, CellRef *b)
int row = cell->row->pos;
/* Convert to absolute cordinates */
cell_get_abs_col_row (a, col, row, &range.start_col, &range.start_row);
cell_get_abs_col_row (b, col, row, &range.end_col, &range.end_row);
cell_get_abs_col_row (a, col, row, &range.range.start_col, &range.range.start_row);
cell_get_abs_col_row (b, col, row, &range.range.end_col, &range.range.end_row);
range.ref_count = 0;
range.sheet = cell->sheet;
......@@ -265,7 +265,8 @@ void
cell_drop_dependencies (Cell *cell)
{
g_return_if_fail (cell != NULL);
g_return_if_fail (cell->parsed_node != NULL);
if (!dependency_hash)
return;
......@@ -286,6 +287,7 @@ cell_drop_dependencies (Cell *cell)
}
typedef struct {
Range range;
int start_col, start_row;
int end_col, end_row;
Sheet *sheet;
......@@ -295,11 +297,7 @@ typedef struct {
static gboolean
intersects (Sheet *sheet, int col, int row, DependencyRange *range)
{
if ((col >= range->start_col) &&
(col <= range->end_col) &&
(row >= range->start_row) &&
(row <= range->end_row) &&
(sheet = range->sheet))
if (range_contains (&range->range, col, row) && (sheet = range->sheet))
return TRUE;
return FALSE;
......@@ -334,10 +332,10 @@ region_get_dependencies (Sheet *sheet, int start_col, int start_row, int end_col
if (!dependency_hash)
dependency_hash_init ();
closure.start_col = start_col;
closure.start_row = start_row;
closure.end_col = end_col;
closure.end_row = end_row;
closure.range.start_col = start_col;
closure.range.start_row = start_row;
closure.range.end_col = end_col;
closure.range.end_row = end_row;
closure.sheet = sheet;
closure.list = NULL;
......
......@@ -11,10 +11,9 @@
typedef struct {
int ref_count;
Sheet *sheet;
int start_col, start_row;
int end_col, end_row;
Range range;
Sheet *sheet;
/* The list of cells that depend on this range */
GList *cell_list;
} DependencyRange;
......
......@@ -512,6 +512,9 @@ apply_align_format (Style *style, Sheet *sheet, CellList *cells)
cell_set_alignment (cell, halign, valign, ORIENT_HORIZ);
}
style->halign = halign;
style->valign = valign;
style->orientation = ORIENT_HORIZ;
style->valid_flags |= STYLE_ALIGN;
}
......
......@@ -38,7 +38,6 @@ dialog_insert_cells (Sheet *sheet)
GNOME_STOCK_BUTTON_OK,
GNOME_STOCK_BUTTON_CANCEL);
printf ("return: %s, %d %d %d %d\n", ret, state [0], state [1], state [2], state [3]);
if (strcmp (ret, GNOME_STOCK_BUTTON_CANCEL) == 0)
return;
......
......@@ -512,6 +512,9 @@ apply_align_format (Style *style, Sheet *sheet, CellList *cells)
cell_set_alignment (cell, halign, valign, ORIENT_HORIZ);
}
style->halign = halign;
style->valign = valign;
style->orientation = ORIENT_HORIZ;
style->valid_flags |= STYLE_ALIGN;
}
......
......@@ -38,7 +38,6 @@ dialog_insert_cells (Sheet *sheet)
GNOME_STOCK_BUTTON_OK,
GNOME_STOCK_BUTTON_CANCEL);
printf ("return: %s, %d %d %d %d\n", ret, state [0], state [1], state [2], state [3]);
if (strcmp (ret, GNOME_STOCK_BUTTON_CANCEL) == 0)
return;
......
......@@ -57,13 +57,13 @@ dependency_equal (gconstpointer v, gconstpointer v2)
if (r1->sheet != r2->sheet)
return 0;
if (r1->start_col != r2->start_col)
if (r1->range.start_col != r2->range.start_col)
return 0;
if (r1->start_row != r2->start_row)
if (r1->range.start_row != r2->range.start_row)
return 0;
if (r1->end_col != r2->end_col)
if (r1->range.end_col != r2->range.end_col)
return 0;
if (r1->end_row != r2->end_row)
if (r1->range.end_row != r2->range.end_row)
return 0;
return 1;
......@@ -77,8 +77,8 @@ dependency_hash_func (gconstpointer v)
{
const DependencyRange *r = v;
return ((((r->start_row << 8) + r->end_row) << 8) +
(r->start_col << 8) + (r->end_col));
return ((((r->range.start_row << 8) + r->range.end_row) << 8) +
(r->range.start_col << 8) + (r->range.end_col));
}
/*
......@@ -104,8 +104,8 @@ add_cell_range_deps (Cell *cell, CellRef *a, CellRef *b)
int row = cell->row->pos;
/* Convert to absolute cordinates */
cell_get_abs_col_row (a, col, row, &range.start_col, &range.start_row);
cell_get_abs_col_row (b, col, row, &range.end_col, &range.end_row);
cell_get_abs_col_row (a, col, row, &range.range.start_col, &range.range.start_row);
cell_get_abs_col_row (b, col, row, &range.range.end_col, &range.range.end_row);
range.ref_count = 0;
range.sheet = cell->sheet;
......@@ -265,7 +265,8 @@ void
cell_drop_dependencies (Cell *cell)
{
g_return_if_fail (cell != NULL);
g_return_if_fail (cell->parsed_node != NULL);
if (!dependency_hash)
return;
......@@ -286,6 +287,7 @@ cell_drop_dependencies (Cell *cell)
}
typedef struct {
Range range;
int start_col, start_row;
int end_col, end_row;
Sheet *sheet;
......@@ -295,11 +297,7 @@ typedef struct {
static gboolean
intersects (Sheet *sheet, int col, int row, DependencyRange *range)
{
if ((col >= range->start_col) &&
(col <= range->end_col) &&
(row >= range->start_row) &&
(row <= range->end_row) &&
(sheet = range->sheet))
if (range_contains (&range->range, col, row) && (sheet = range->sheet))
return TRUE;
return FALSE;
......@@ -334,10 +332,10 @@ region_get_dependencies (Sheet *sheet, int start_col, int start_row, int end_col
if (!dependency_hash)
dependency_hash_init ();
closure.start_col = start_col;
closure.start_row = start_row;
closure.end_col = end_col;
closure.end_row = end_row;
closure.range.start_col = start_col;
closure.range.start_row = start_row;
closure.range.end_col = end_col;
closure.range.end_row = end_row;
closure.sheet = sheet;
closure.list = NULL;
......
......@@ -11,10 +11,9 @@
typedef struct {
int ref_count;
Sheet *sheet;
int start_col, start_row;
int end_col, end_row;
Range range;
Sheet *sheet;
/* The list of cells that depend on this range */
GList *cell_list;
} DependencyRange;
......
......@@ -681,7 +681,6 @@ gnumeric_sheet_realize (GtkWidget *widget)
if (GTK_WIDGET_CLASS (sheet_parent_class)->realize)
(*GTK_WIDGET_CLASS (sheet_parent_class)->realize)(widget);
/* MIGUEL: look at this */
gdk_window_set_back_pixmap (GTK_LAYOUT (widget)->bin_window, NULL, FALSE);
}
......
......@@ -681,7 +681,6 @@ gnumeric_sheet_realize (GtkWidget *widget)
if (GTK_WIDGET_CLASS (sheet_parent_class)->realize)
(*GTK_WIDGET_CLASS (sheet_parent_class)->realize)(widget);
/* MIGUEL: look at this */
gdk_window_set_back_pixmap (GTK_LAYOUT (widget)->bin_window, NULL, FALSE);
}
......
......@@ -103,3 +103,15 @@ run_popup_menu (GdkEvent *event, char **strings)
return i;
}
gboolean
range_contains (Range *range, int col, int row)
{
if ((col >= range->start_col) &&
(col <= range->end_col) &&
(row >= range->start_row) &&
(row <= range->end_row))
return TRUE;
return FALSE;
}
......@@ -103,3 +103,15 @@ run_popup_menu (GdkEvent *event, char **strings)
return i;
}
gboolean
range_contains (Range *range, int col, int row)
{
if ((col >= range->start_col) &&
(col <= range->end_col) &&
(row >= range->start_row) &&
(row <= range->end_row))
return TRUE;
return FALSE;
}
......@@ -155,4 +155,3 @@ parse_cell_name (char *cell_str, int *col, int *row)
return TRUE;
}
......@@ -211,6 +211,11 @@ item_grid_draw_cell (GdkDrawable *drawable, ItemGrid *item_grid,
}
#endif
/*
* General Alignement is a special case: it means
* left alignment for text and right alignment for
* numbers
*/
halign = style->halign;
if (halign == HALIGN_GENERAL && cell->value){
......@@ -461,8 +466,7 @@ context_paste_special_cmd (GtkWidget *widget, ItemGrid *item_grid)
static void
context_insert_cmd (GtkWidget *widget, ItemGrid *item_grid)
{
g_warning ("TEST CODE: Manually inserting 2 columns at column 1\n");
sheet_insert_col (item_grid->sheet, 1, 2);
dialog_insert_cells (item_grid->sheet);
context_destroy_menu (widget);
}
......
......@@ -12,6 +12,7 @@
#include "gnumeric-sheet.h"
#include "utils.h"
#include "gnumeric-util.h"
#include "eval.h"
static void sheet_selection_col_extend_to (Sheet *sheet, int col);
static void sheet_selection_row_extend_to (Sheet *sheet, int row);
......@@ -35,7 +36,6 @@ sheet_init_default_styles (Sheet *sheet)
{
/* The default column style */
sheet->default_col_style.pos = -1;
sheet->default_col_style.style = style_new ();
sheet->default_col_style.units = 80;
sheet->default_col_style.pixels = 0;
sheet->default_col_style.margin_a = 1;
......@@ -45,7 +45,6 @@ sheet_init_default_styles (Sheet *sheet)
/* The default row style */
sheet->default_row_style.pos = -1;
sheet->default_row_style.style = style_new ();
sheet->default_row_style.units = 20;
sheet->default_row_style.pixels = 0;
sheet->default_row_style.margin_a = 1;
......@@ -80,7 +79,6 @@ sheet_init_dummy_stuff (Sheet *sheet)
static void
canvas_bar_realized (GtkWidget *widget, gpointer data)
{
/* MIGUEL: look at this */
gdk_window_set_back_pixmap (GTK_LAYOUT (widget)->bin_window, NULL, FALSE);
}
......@@ -211,6 +209,7 @@ sheet_new (Workbook *wb, char *name)
int rows_shown, cols_shown;
GtkWidget *select_all;
Sheet *sheet;
Style *sheet_style;
rows_shown = cols_shown = 40;
......@@ -224,6 +223,10 @@ sheet_new (Workbook *wb, char *name)
sheet->max_row_used = rows_shown;
sheet->cell_hash = g_hash_table_new (cell_hash, cell_compare);
sheet_style = style_new ();
sheet_style_attach (sheet, 0, 0, SHEET_MAX_COLS-1, SHEET_MAX_ROWS-1, sheet_style);
sheet_init_default_styles (sheet);
/* Dummy initialization */
......@@ -312,25 +315,6 @@ cell_hash_free_key (gpointer key, gpointer value, gpointer user_data)
{
g_free (key);
}
void
sheet_destroy (Sheet *sheet)
{
g_assert (sheet != NULL);
g_return_if_fail (IS_SHEET (sheet));
sheet_selection_clear (sheet);
g_free (sheet->name);
style_destroy (sheet->default_row_style.style);
style_destroy (sheet->default_col_style.style);
g_hash_table_foreach (sheet->cell_hash, cell_hash_free_key, NULL);
gtk_widget_destroy (sheet->toplevel);
sheet->signature = 0;
g_free (sheet);
}
void
sheet_foreach_col (Sheet *sheet, sheet_col_row_callback callback, void *user_data)
......@@ -408,8 +392,6 @@ sheet_duplicate_colrow (ColRowInfo *original)
*info = *original;
info->style = style_duplicate (original->style);
return info;
}
......@@ -1524,21 +1506,6 @@ sheet_cell_foreach_range (Sheet *sheet, int only_existing,
return TRUE;
}
Style *
sheet_style_compute (Sheet *sheet, int col, int row)
{
g_return_val_if_fail (sheet != NULL, NULL);
g_return_val_if_fail (IS_SHEET (sheet), NULL);
/* FIXME: This should compute the style based on the
* story of the styles applied to the worksheet, the
* sheet, the column and the row and return that.
*
* for now, we just return the col style
*/
return style_duplicate (sheet_col_get_info (sheet, col)->style);
}
static gint
CRowSort (gconstpointer a, gconstpointer b)