Commit 4490137c authored by Morten Welinder's avatar Morten Welinder

Sheet resize: fix problem with merges.

parent 975d084f
2009-10-11 Morten Welinder <terra@gnome.org>
* src/sheet.c (gnm_sheet_resize_main): Reduce ->cols.max_used and
->rows.max_used as appropriate.
(gnm_sheet_resize): Check for merges. Add new perr argument. All
callers changed.
2009-10-11 Andreas J. Guelzow <aguelzow@pyrshep.ca>
* src/mathfunc.c (random_skew_normal): new
......
......@@ -6,6 +6,9 @@ Andreas:
Jody:
* First steps towards a turnkey win32 build.
Morten:
* Fix sheet-resize vs. merges issue. [#582030]
--------------------------------------------------------------------------
Gnumeric 1.9.14
......
......@@ -926,12 +926,13 @@ oo_extent_sheet_cols (Sheet *sheet, int cols)
{
GOUndo * goundo;
int new_cols, new_rows;
gboolean err;
new_cols = cols;
new_rows = gnm_sheet_get_max_rows (sheet);
gnm_sheet_suggest_size (&new_cols, &new_rows);
goundo = gnm_sheet_resize (sheet, new_cols, new_rows, NULL);
goundo = gnm_sheet_resize (sheet, new_cols, new_rows, NULL, &err);
g_object_unref (G_OBJECT (goundo));
return gnm_sheet_get_max_cols (sheet);
......@@ -1024,12 +1025,13 @@ oo_extent_sheet_rows (Sheet *sheet, int rows)
{
GOUndo * goundo;
int new_cols, new_rows;
gboolean err;
new_cols = gnm_sheet_get_max_cols (sheet);
new_rows = rows;
gnm_sheet_suggest_size (&new_cols, &new_rows);
goundo = gnm_sheet_resize (sheet, new_cols, new_rows, NULL);
goundo = gnm_sheet_resize (sheet, new_cols, new_rows, NULL, &err);
g_object_unref (G_OBJECT (goundo));
return gnm_sheet_get_max_rows (sheet);
......
......@@ -59,6 +59,17 @@ gnm_cmd_context_error_splits_array (GOCmdContext *context,
go_cmd_context_error (context, err);
}
void
gnm_cmd_context_error_splits_merge (GOCmdContext *context,
GnmRange const *merge)
{
GError *err =
g_error_new (gnm_error_array(), 1,
_("Would split merge %s"),
range_as_string (merge));
go_cmd_context_error (context, err);
}
GQuark
gnm_error_array (void)
{
......
......@@ -11,6 +11,8 @@ G_BEGIN_DECLS
void gnm_cmd_context_error_calc (GOCmdContext *cc, char const *msg);
void gnm_cmd_context_error_splits_array (GOCmdContext *cc, char const *cmd,
GnmRange const *array);
void gnm_cmd_context_error_splits_merge (GOCmdContext *cc,
GnmRange const *merge);
GQuark gnm_error_array (void);
GQuark gnm_error_calc (void);
......
......@@ -4794,8 +4794,16 @@ cmd_resize_sheets_redo (GnmCommand *cmd, WorkbookControl *wbc)
for (l = me->sheets; l; l = l->next) {
Sheet *sheet = l->data;
GOUndo *u = gnm_sheet_resize (sheet, me->cols, me->rows, cc);
gboolean err;
GOUndo *u = gnm_sheet_resize (sheet, me->cols, me->rows,
cc, &err);
me->undo = go_undo_combine (me->undo, u);
if (err) {
if (me->undo)
go_undo_undo_with_data (me->undo, cc);
return TRUE;
}
}
return FALSE;
......
......@@ -1119,7 +1119,6 @@ gnm_sheet_resize_main (Sheet *sheet, int cols, int rows,
GOCmdContext *cc, GOUndo **pundo)
{
int old_cols, old_rows;
static gboolean warned = FALSE;
if (pundo) *pundo = NULL;
......@@ -1128,11 +1127,6 @@ gnm_sheet_resize_main (Sheet *sheet, int cols, int rows,
if (old_cols == cols && old_rows == rows)
return;
if (!warned) {
g_warning ("Changing sheet size is experimental.");
warned = TRUE;
}
/* ---------------------------------------- */
/* Remove the columns and rows that will disappear. */
......@@ -1231,7 +1225,10 @@ gnm_sheet_resize_main (Sheet *sheet, int cols, int rows,
/* Actually change the properties. */
sheet->size.max_cols = cols;
sheet->cols.max_used = MIN (sheet->cols.max_used, cols - 1);
sheet->size.max_rows = rows;
sheet->rows.max_used = MIN (sheet->rows.max_used, rows - 1);
if (old_cols != cols)
g_object_notify (G_OBJECT (sheet), "columns");
if (old_rows != rows)
......@@ -1266,15 +1263,41 @@ gnm_sheet_resize_main (Sheet *sheet, int cols, int rows,
}
GOUndo *
gnm_sheet_resize (Sheet *sheet, int cols, int rows, GOCmdContext *cc)
gnm_sheet_resize (Sheet *sheet, int cols, int rows,
GOCmdContext *cc, gboolean *perr)
{
GOUndo *undo = NULL;
g_return_val_if_fail (IS_SHEET (sheet), NULL);
g_return_val_if_fail (gnm_sheet_valid_size (cols, rows), NULL);
if (cols < sheet->size.max_cols || rows < sheet->size.max_rows) {
GSList *overlap, *l;
gboolean bad = FALSE;
GnmRange r;
r.start.col = r.start.row = 0;
r.end.col = MIN (cols, sheet->size.max_cols) - 1;
r.end.row = MIN (rows, sheet->size.max_rows) - 1;
overlap = gnm_sheet_merge_get_overlap (sheet, &r);
for (l = overlap; l && !bad; l = l->next) {
GnmRange const *m = l->data;
if (!range_contained (m, &r)) {
bad = TRUE;
gnm_cmd_context_error_splits_merge (cc, m);
}
}
g_slist_free (overlap);
if (bad) {
*perr = TRUE;
return NULL;
}
}
gnm_sheet_resize_main (sheet, cols, rows, cc, &undo);
*perr = FALSE;
return undo;
}
......
......@@ -132,7 +132,8 @@ void sheet_destroy_contents (Sheet *sheet);
gboolean gnm_sheet_valid_size (int cols, int rows);
void gnm_sheet_suggest_size (int *cols, int *rows);
GOUndo *gnm_sheet_resize (Sheet *sheet, int cols, int rows, GOCmdContext *cc);
GOUndo *gnm_sheet_resize (Sheet *sheet, int cols, int rows,
GOCmdContext *cc, gboolean *perr);
GnmSheetSize const *gnm_sheet_get_size (Sheet const *sheet);
GnmSheetSize const *gnm_sheet_get_size2 (Sheet const *sheet,
......
......@@ -351,6 +351,7 @@ merge_single (Workbook *wb, Workbook *wb2,
int loc = workbook_sheet_count (wb);
GOUndo *undo;
char *sheet_name;
gboolean err;
g_object_ref (sheet);
workbook_sheet_delete (sheet);
......@@ -359,7 +360,7 @@ merge_single (Workbook *wb, Workbook *wb2,
/* Fix names that reference the old workbook */
gnm_sheet_foreach_name (sheet, (GHFunc)cb_fixup_name_wb, wb);
undo = gnm_sheet_resize (sheet, cmax, rmax, cc);
undo = gnm_sheet_resize (sheet, cmax, rmax, cc, &err);
if (undo)
g_object_unref (undo);
......
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