[gnumeric] 2009-04-23 Morten Welinder <terra gnome org>
- From: Morten Welinder <mortenw src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnumeric] 2009-04-23 Morten Welinder <terra gnome org>
- Date: Thu, 23 Apr 2009 19:02:29 -0400 (EDT)
commit f1615dfbc752ff0f669521e7b3bfb798cb02df8f
Author: Morten Welinder <terra gnome org>
Date: Thu Apr 23 19:03:14 2009 -0400
2009-04-23 Morten Welinder <terra gnome org>
* src/sheet.c (gnm_sheet_resize_main): Resize styles too.
(gnm_sheet_constructor): Check row count sanity here.
* src/sheet-style.c (sheet_style_init): Not here.
(sheet_style_resize): New function.
(sheet_style_init_size): Split from sheet_style_init.
---
ChangeLog | 7 ++++
src/sheet-style.c | 88 +++++++++++++++++++++++++++++++++--------------------
src/sheet-style.h | 1 +
src/sheet.c | 17 +++++++++-
4 files changed, 79 insertions(+), 34 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 897d995..f6ba8fc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2009-04-23 Morten Welinder <terra gnome org>
+ * src/sheet.c (gnm_sheet_resize_main): Resize styles too.
+ (gnm_sheet_constructor): Check row count sanity here.
+
+ * src/sheet-style.c (sheet_style_init): Not here.
+ (sheet_style_resize): New function.
+ (sheet_style_init_size): Split from sheet_style_init.
+
* src/commands.c (cmd_insert_rows, cmd_insert_cols): Simplify and
fix plural.
(cmd_ins_del_colrow): Simplify.
diff --git a/src/sheet-style.c b/src/sheet-style.c
index df79c45..eb433ab 100644
--- a/src/sheet-style.c
+++ b/src/sheet-style.c
@@ -438,37 +438,27 @@ cell_tile_matrix_set (CellTile *t, GnmRange const *indic, ReplacementStyle *rs)
/****************************************************************************/
-void
-sheet_style_init (Sheet *sheet)
+static void
+sheet_style_init_size (Sheet *sheet, int cols, int rows)
{
GnmStyle *default_style;
- int l = 0, w = TILE_SIZE_COL, h = TILE_SIZE_ROW;
-
- /* some simple sanity checks */
- g_return_if_fail (IS_SHEET (sheet));
- g_assert (gnm_sheet_get_max_cols (sheet) <= GNM_MAX_COLS);
- g_assert (gnm_sheet_get_max_rows (sheet) <= GNM_MAX_ROWS);
+ int lc = 0, lr = 0, w = TILE_SIZE_COL, h = TILE_SIZE_ROW;
- while (w < gnm_sheet_get_max_cols (sheet)) {
+ while (w < cols) {
w *= TILE_SIZE_COL;
- sheet->tile_top_level++;
- }
- while (h < gnm_sheet_get_max_rows (sheet)) {
- h *= TILE_SIZE_ROW;
- l++;
+ lc++;
}
- if (l > sheet->tile_top_level)
- sheet->tile_top_level = l;
- h = TILE_SIZE_ROW;
- w = TILE_SIZE_COL;
- for (l = 0 ; l < sheet->tile_top_level; l++) {
+ while (h < rows) {
h *= TILE_SIZE_ROW;
- w *= TILE_SIZE_COL;
+ lr++;
}
- sheet->max_height = h / TILE_SIZE_ROW;
- sheet->max_width = w / TILE_SIZE_COL;
- sheet->partial_row = sheet->max_rows != h;
- sheet->partial_col = sheet->max_cols != w;
+ sheet->tile_top_level = MAX (lc, lr);
+
+ sheet->max_height = tile_heights[sheet->tile_top_level];
+ sheet->max_width = tile_widths[sheet->tile_top_level];
+
+ sheet->partial_row = (rows != sheet->max_height * TILE_SIZE_ROW);
+ sheet->partial_col = (cols != sheet->max_width * TILE_SIZE_COL);
#if USE_TILE_POOLS
if (tile_pool_users++ == 0) {
@@ -496,15 +486,6 @@ sheet_style_init (Sheet *sheet)
}
#endif
- if (GNM_MAX_COLS > 364238) {
- /* Oh, yeah? */
- g_warning (_("This is a special version of Gnumeric. It has been compiled\n"
- "with support for a very large number of columns. Access to the\n"
- "column named TRUE may conflict with the constant of the same\n"
- "name. Expect weirdness."));
- }
-
-
sheet->style_data = g_new (GnmSheetStyleData, 1);
sheet->style_data->style_hash =
g_hash_table_new (gnm_style_hash, (GCompareFunc) gnm_style_equal);
@@ -531,6 +512,47 @@ sheet_style_init (Sheet *sheet)
TILE_SIMPLE);
}
+void
+sheet_style_init (Sheet *sheet)
+{
+ int cols = gnm_sheet_get_max_cols (sheet);
+ int rows = gnm_sheet_get_max_rows (sheet);
+ sheet_style_init_size (sheet, cols, rows);
+}
+
+void
+sheet_style_resize (Sheet *sheet, int cols, int rows)
+{
+ GnmStyleList *styles, *l;
+ int old_cols = gnm_sheet_get_max_cols (sheet);
+ int old_rows = gnm_sheet_get_max_rows (sheet);
+ GnmRange save_range, new_full;
+
+ /* Save the style for the surviving area. */
+ range_init (&save_range, 0, 0,
+ MIN (cols, old_cols), MIN (rows, old_rows));
+ styles = sheet_style_get_list (sheet, &save_range);
+
+ /* Build new empty structures. */
+ sheet_style_shutdown (sheet);
+ sheet_style_init_size (sheet, cols, rows);
+
+ /* Reapply styles. */
+ range_init (&new_full, 0, 0, cols, rows);
+ for (l = styles; l; l = l->next) {
+ GnmStyleRegion const *sr = l->data;
+ GnmRange const *r = &sr->range;
+ GnmStyle *style = sr->style;
+ GnmRange newr;
+ if (range_intersection (&newr, r, &new_full)) {
+ gnm_style_ref (style);
+ sheet_style_apply_range (sheet, &newr, style);
+ }
+ }
+
+ style_list_free (styles);
+}
+
static gboolean
cb_unlink (void *key, void *value, void *user)
{
diff --git a/src/sheet-style.h b/src/sheet-style.h
index 621dd18..5917233 100644
--- a/src/sheet-style.h
+++ b/src/sheet-style.h
@@ -62,6 +62,7 @@ void sheet_style_foreach (Sheet const *sheet,
gpointer user_data);
void sheet_style_init (Sheet *sheet);
+void sheet_style_resize (Sheet *sheet, int cols, int rows);
void sheet_style_shutdown (Sheet *sheet);
void sheet_style_set_auto_pattern_color (Sheet *sheet,
diff --git a/src/sheet.c b/src/sheet.c
index 78aa8dc..b8d86ed 100644
--- a/src/sheet.c
+++ b/src/sheet.c
@@ -634,7 +634,17 @@ gnm_sheet_constructor (GType type,
{
GObject *obj;
Sheet *sheet;
-
+ static gboolean warned = FALSE;
+
+ if (GNM_MAX_COLS > 364238 && !warned) {
+ /* Oh, yeah? */
+ g_warning (_("This is a special version of Gnumeric. It has been compiled\n"
+ "with support for a very large number of columns. Access to the\n"
+ "column named TRUE may conflict with the constant of the same\n"
+ "name. Expect weirdness."));
+ warned = TRUE;
+ }
+
obj = parent_class->constructor (type, n_construct_properties,
construct_params);
sheet = SHEET (obj);
@@ -1169,6 +1179,11 @@ gnm_sheet_resize_main (Sheet *sheet, int cols, int rows,
}
/* ---------------------------------------- */
+ /* Resize the styles. */
+
+ sheet_style_resize (sheet, cols, rows);
+
+ /* ---------------------------------------- */
/* Actually change the properties. */
sheet->max_cols = cols;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]