Commit f1eccf84 authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg

new function broken out of wbv_save_to_uri for convenience. This API will

2006-05-09  Jody Goldberg <jody@gnome.org>

	* src/workbook-view.c (wbv_save_to_output) : new function broken out
	  of wbv_save_to_uri for convenience.  This API will change.

	* src/sheet.c
	(sheet_insert_cols) : make reloc_storage arg optionally NULL.
	(sheet_delete_cols) : ditto.
	(sheet_insert_rows) : ditto.
	(sheet_delete_rows) : ditto.
parent 9e69e451
2006-05-09 Jody Goldberg <jody@gnome.org>
* src/workbook-view.c (wbv_save_to_output) : new function broken out
of wbv_save_to_uri for convenience. This API will change.
* src/sheet.c
(sheet_insert_cols) : make reloc_storage arg optionally NULL.
(sheet_delete_cols) : ditto.
(sheet_insert_rows) : ditto.
(sheet_delete_rows) : ditto.
2006-05-08 Morten Welinder <terra@gnome.org>
* src/style.c (style_font_new_simple): Copy font description
......
Gnumeric 1.7.1
Jody:
* Fix ODF sheet name import ('aa''a' == aa'a).
Morten:
* Moved font metrics to goffice.
* Fixed font initialization.
......
2006-05-09 Jody Goldberg <jody@gnome.org>
* openoffice-read.c (oo_cellref_parse) : Eike just posted a newer
definition of how sheet names are encoded.
- only single quotes are allowed
- in quoted names a quote is escaped by doubling it 'aa''a' == aa'a
2006-05-08 Jody Goldberg <jody@gnome.org>
* Release 1.7.0
......
......@@ -568,31 +568,51 @@ static char const *
oo_cellref_parse (GnmCellRef *ref, char const *start, GnmParsePos const *pp)
{
char const *tmp1, *tmp2, *ptr = start;
/* sheet name cannot contain '.' a '\'' or a '\"' */
if (*ptr != '.') {
char *name;
int offset = 0;
char *name, *accum;
if (*ptr == '$') /* ignore abs vs rel sheet name */
ptr++;
tmp1 = strchr (ptr, '.');
if (tmp1 == NULL)
return start;
if ((*ptr == '\'' || *ptr == '\"') && *ptr == tmp1[-1]) {
/* ignore abs vs rel for sheets */
if (*ptr == '$')
ptr++;
tmp1--;
offset = 1;
}
name = g_alloca (tmp1-ptr+1);
strncpy (name, ptr, tmp1-ptr);
name[tmp1-ptr] = 0;
ptr = tmp1 + 1 + offset;
/* From the spec :
* SheetName ::= [^\. ']+ | "'" ([^'] | "''")+ "'" */
if ('\'' == *ptr) {
tmp1 = ++ptr;
two_quotes :
/* missing close paren */
if (NULL == (tmp1 = strchr (tmp1, '\'')))
return start;
/* two in a row is the escape for a single */
if (tmp1[1] == '\'') {
tmp1 += 2;
goto two_quotes;
}
/* If a name is quoted the entire named must be quoted */
if (tmp1[1] != '.')
return start;
accum = name = g_alloca (tmp1-ptr+1);
while (ptr != tmp1)
if ('\'' == (*accum++ = *ptr++))
ptr++;
*accum = '\0';
ptr += 2;
} else {
if (NULL == (tmp1 = strchr (ptr, '.')))
return start;
name = g_alloca (tmp1-ptr+1);
strncpy (name, ptr, tmp1-ptr);
name[tmp1-ptr] = '\0';
ptr = tmp1 + 1;
}
/* OpenCalc does not pre-declare its sheets, but it does have a
* nice unambiguous format. So if we find a name that has not
* been added yet add it. Reorder below.
*/
* been added yet add it. Reorder below. */
ref->sheet = workbook_sheet_by_name (pp->wb, name);
if (ref->sheet == NULL) {
ref->sheet = sheet_new (pp->wb, name);
......
......@@ -3429,6 +3429,7 @@ colrow_move (Sheet *sheet,
sheet_mark_dirty (sheet);
}
/* reloc_storage can be NULL */
static void
sheet_colrow_insdel_finish (GnmExprRelocateInfo const *rinfo, gboolean is_cols,
int pos, int state_start, ColRowStateList *states,
......@@ -3478,6 +3479,7 @@ sheet_colrow_set_collapse (Sheet *sheet, gboolean is_cols, int pos)
}
}
/* reloc_storage can be NULL */
static void
sheet_colrow_insert_finish (GnmExprRelocateInfo const *rinfo, gboolean is_cols,
int pos, int count, ColRowStateList *states,
......@@ -3503,6 +3505,7 @@ sheet_colrow_insert_finish (GnmExprRelocateInfo const *rinfo, gboolean is_cols,
sv_panes_insdel_colrow (sv, is_cols, TRUE, pos, count););
}
/* reloc_storage can be NULL */
static void
sheet_colrow_delete_finish (GnmExprRelocateInfo const *rinfo, gboolean is_cols,
int pos, int count, ColRowStateList *states,
......@@ -3532,7 +3535,8 @@ sheet_colrow_delete_finish (GnmExprRelocateInfo const *rinfo, gboolean is_cols,
* @col : At which position we want to insert
* @count : The number of columns to be inserted
* @states :
* @reloc_storage :
* @reloc_storage : optionally NULL, caller releases result
* with gnm_reloc_undo_release.
* @cc :
**/
gboolean
......@@ -3542,11 +3546,11 @@ sheet_insert_cols (Sheet *sheet,
{
GnmExprRelocateInfo reloc_info;
GnmRange region;
GSList *relocated_exprs;
int i;
g_return_val_if_fail (reloc_storage != NULL, TRUE);
reloc_storage->exprs = NULL;
if (NULL != reloc_storage)
reloc_storage->exprs = NULL;
g_return_val_if_fail (IS_SHEET (sheet), TRUE);
g_return_val_if_fail (count != 0, TRUE);
......@@ -3572,7 +3576,12 @@ sheet_insert_cols (Sheet *sheet,
reloc_info.origin_sheet = reloc_info.target_sheet = sheet;
reloc_info.col_offset = count;
reloc_info.row_offset = 0;
reloc_storage->exprs = dependents_relocate (&reloc_info);
relocated_exprs = dependents_relocate (&reloc_info);
if (NULL != reloc_storage)
reloc_storage->exprs = relocated_exprs;
else
dependents_unrelocate_free (relocated_exprs);
/* 3. Move the columns to their new location (From right to left) */
for (i = sheet->cols.max_used; i >= col ; --i)
......@@ -3591,6 +3600,9 @@ sheet_insert_cols (Sheet *sheet,
* @sheet The sheet
* @col At which position we want to start deleting columns
* @count The number of columns to be deleted
* @reloc_storage : optionally NULL, caller releases result
* with gnm_reloc_undo_release.
* @cc : The command context
*/
gboolean
sheet_delete_cols (Sheet *sheet,
......@@ -3598,11 +3610,11 @@ sheet_delete_cols (Sheet *sheet,
GnmRelocUndo *reloc_storage, GOCmdContext *cc)
{
GnmExprRelocateInfo reloc_info;
GSList *relocated_exprs;
int i;
g_return_val_if_fail (reloc_storage != NULL, TRUE);
reloc_storage->exprs = NULL;
if (NULL != reloc_storage)
reloc_storage->exprs = NULL;
g_return_val_if_fail (IS_SHEET (sheet), TRUE);
g_return_val_if_fail (count != 0, TRUE);
......@@ -3631,15 +3643,22 @@ sheet_delete_cols (Sheet *sheet,
sheet_flag_status_update_range (sheet, &reloc_info.origin);
/* 2. Invalidate references to the cells in the delete columns */
reloc_storage->exprs = dependents_relocate (&reloc_info);
relocated_exprs = dependents_relocate (&reloc_info);
if (NULL != reloc_storage)
reloc_storage->exprs = relocated_exprs;
else
dependents_unrelocate_free (relocated_exprs);
/* 3. Fix references to and from the cells which are moving */
reloc_info.origin.start.col = col+count;
reloc_info.origin.end.col = SHEET_MAX_COLS-1;
reloc_info.col_offset = -count;
reloc_info.row_offset = 0;
reloc_storage->exprs = g_slist_concat (dependents_relocate (&reloc_info),
reloc_storage->exprs);
relocated_exprs = dependents_relocate (&reloc_info);
if (NULL != reloc_storage)
reloc_storage->exprs = g_slist_concat (relocated_exprs, reloc_storage->exprs);
else
dependents_unrelocate_free (relocated_exprs);
/* 4. Move the columns to their new location (from left to right) */
for (i = col + count ; i <= sheet->cols.max_used; ++i)
......@@ -3658,6 +3677,10 @@ sheet_delete_cols (Sheet *sheet,
* @sheet The sheet
* @row At which position we want to insert
* @count The number of rows to be inserted
* @states :
* @reloc_storage : optionally NULL, caller releases result
* with gnm_reloc_undo_release.
* @cc : The command context
*/
gboolean
sheet_insert_rows (Sheet *sheet,
......@@ -3666,11 +3689,11 @@ sheet_insert_rows (Sheet *sheet,
{
GnmExprRelocateInfo reloc_info;
GnmRange region;
GSList *relocated_exprs;
int i;
g_return_val_if_fail (reloc_storage != NULL, TRUE);
reloc_storage->exprs = NULL;
if (NULL != reloc_storage)
reloc_storage->exprs = NULL;
g_return_val_if_fail (IS_SHEET (sheet), TRUE);
g_return_val_if_fail (count != 0, TRUE);
......@@ -3696,7 +3719,9 @@ sheet_insert_rows (Sheet *sheet,
reloc_info.origin_sheet = reloc_info.target_sheet = sheet;
reloc_info.col_offset = 0;
reloc_info.row_offset = count;
reloc_storage->exprs = dependents_relocate (&reloc_info);
relocated_exprs = dependents_relocate (&reloc_info);
if (NULL != reloc_storage)
reloc_storage->exprs = relocated_exprs;
/* 3. Move the rows to their new location (from bottom to top) */
for (i = sheet->rows.max_used; i >= row ; --i)
......@@ -3715,6 +3740,9 @@ sheet_insert_rows (Sheet *sheet,
* @sheet The sheet
* @row At which position we want to start deleting rows
* @count The number of rows to be deleted
* @reloc_storage : optionally NULL, caller releases result
* with gnm_reloc_undo_release.
* @cc : The command context
*/
gboolean
sheet_delete_rows (Sheet *sheet,
......@@ -3722,11 +3750,11 @@ sheet_delete_rows (Sheet *sheet,
GnmRelocUndo *reloc_storage, GOCmdContext *cc)
{
GnmExprRelocateInfo reloc_info;
GSList *relocated_exprs;
int i;
g_return_val_if_fail (reloc_storage != NULL, TRUE);
reloc_storage->exprs = NULL;
if (NULL != reloc_storage)
reloc_storage->exprs = NULL;
g_return_val_if_fail (IS_SHEET (sheet), TRUE);
g_return_val_if_fail (count != 0, TRUE);
......@@ -3755,15 +3783,22 @@ sheet_delete_rows (Sheet *sheet,
sheet_flag_status_update_range (sheet, &reloc_info.origin);
/* 2. Invalidate references to the cells in the delete columns */
reloc_storage->exprs = dependents_relocate (&reloc_info);
relocated_exprs = dependents_relocate (&reloc_info);
if (NULL != reloc_storage)
reloc_storage->exprs = relocated_exprs;
else
dependents_unrelocate_free (relocated_exprs);
/* 3. Fix references to and from the cells which are moving */
reloc_info.origin.start.row = row + count;
reloc_info.origin.end.row = SHEET_MAX_ROWS-1;
reloc_info.col_offset = 0;
reloc_info.row_offset = -count;
reloc_storage->exprs = g_slist_concat (dependents_relocate (&reloc_info),
reloc_storage->exprs);
relocated_exprs = dependents_relocate (&reloc_info);
if (NULL != reloc_storage)
reloc_storage->exprs = g_slist_concat (relocated_exprs, reloc_storage->exprs);
else
dependents_unrelocate_free (relocated_exprs);
/* 4. Move the rows to their new location (from top to bottom) */
for (i = row + count ; i <= sheet->rows.max_used; ++i)
......@@ -3781,7 +3816,8 @@ sheet_delete_rows (Sheet *sheet,
* sheet_move_range :
* @cc :
* @rinfo :
* @reloc_storage : optionally NULL.
* @reloc_storage : optionally NULL, caller releases result
* with gnm_reloc_undo_release.
*
* Move a range as specified in @rinfo report warnings to @cc.
* if @reloc_storage is non NULL, invalidate references to the
......
......@@ -653,48 +653,60 @@ workbook_view_new (Workbook *wb)
return wbv;
}
/**
* wbv_save_to_output :
* @wbv : #WorkbookView
* @fs : #GOFileSaver
* @output : #GsfOutput
* @io_context : #IOContext
*
* NOTE : Temporary api until we get the new output framework.
**/
void
wbv_save_to_output (WorkbookView *wbv, GOFileSaver const *fs,
GsfOutput *output, IOContext *io_context)
{
GError const *err;
char const *msg;
go_file_saver_save (fs, io_context, wbv, output);
/* The plugin convention is unclear */
if (!gsf_output_is_closed (output))
gsf_output_close (output);
if (NULL == (err = gsf_output_error (output)))
return;
if (NULL == (msg = err->message))
msg = _("An unexplained error happened while saving.");
g_printerr (" ==> %s\n", msg);
if (!gnumeric_io_error_occurred (io_context))
go_cmd_context_error_export (GO_CMD_CONTEXT (io_context), msg);
}
static void
wbv_save_to_uri (WorkbookView *wbv, GOFileSaver const *fs,
char const *uri, IOContext *io_context)
{
char *msg = NULL;
char *msg = NULL;
GError *err = NULL;
GsfOutput *output = go_file_create (uri, &err);
if (output == NULL) {
char *str = g_strdup_printf (_("Can't open '%s' for writing: %s"),
uri, err->message);
go_cmd_context_error_export (GO_CMD_CONTEXT (io_context), str);
g_error_free (err);
g_free (str);
return;
}
if (NULL != err) {
msg = g_strdup_printf (_("Can't open '%s' for writing: %s"),
uri, err->message);
g_error_free (err);
} else
msg = g_strdup_printf (_("Can't open '%s' for writing"), uri);
if (output != NULL) {
GError const *save_err;
go_cmd_context_error_export (GO_CMD_CONTEXT (io_context), msg);
g_free (msg);
} else {
g_printerr ("Writing %s\n", uri);
go_file_saver_save (fs, io_context, wbv, output);
if (!gsf_output_is_closed (output))
gsf_output_close (output);
save_err = gsf_output_error (output);
if (save_err) {
msg = g_strdup (save_err->message);
g_printerr (" ==> %s\n", msg);
g_object_unref (output);
} else {
g_object_unref (output);
return;
}
wbv_save_to_output (wbv, fs, output, io_context);
g_object_unref (output);
}
if (msg == NULL)
msg = g_strdup_printf (_("An unexplained error happened while saving %s"),
uri);
if (!gnumeric_io_error_occurred (io_context))
go_cmd_context_error_export (GO_CMD_CONTEXT (io_context), msg);
g_free (msg);
}
/**
......
......@@ -85,6 +85,8 @@ void wb_view_auto_expr_precision (WorkbookView *wbv,
gboolean wb_view_save_as (WorkbookView *wbv, GOFileSaver *fs,
char const *file_name, GOCmdContext *cc);
gboolean wb_view_save (WorkbookView *wbv, GOCmdContext *cc);
void wbv_save_to_output (WorkbookView *wbv, GOFileSaver const *fs,
GsfOutput *output, IOContext *io_context);
gboolean wb_view_sendto (WorkbookView *wbv, GOCmdContext *cc);
WorkbookView *wb_view_new_from_input (GsfInput *input,
......
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