From 31dd58428a9e06786996bba902cf1748d4a52c00 Mon Sep 17 00:00:00 2001 From: Morten Welinder Date: Tue, 14 Mar 2006 02:30:42 +0000 Subject: [PATCH] Write protection flags. Store falg. (excel_read_workbook_PROTECT): New 2006-03-13 Morten Welinder * ms-excel-write.c (write_sheet_head): Write protection flags. * ms-excel-read.c (excel_read_sheet_PROTECT): Store falg. (excel_read_workbook_PROTECT): New function. (excel_read_workbook): Read protection flags. Patch from Klokan Petr Pridal. [#330129] --- NEWS | 1 + plugins/excel/ChangeLog | 8 ++++++++ plugins/excel/ms-excel-read.c | 30 +++++++++++++++++++++++------- plugins/excel/ms-excel-write.c | 8 +++++++- 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/NEWS b/NEWS index e9b661056..2f625a5a3 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,7 @@ Gnumeric 1.6.3 Klokan Pridal: * Implement xml saving/loading of "protected" attribute. [#334257] + * Implement xls saving/loading of "protected" attribute. [#330129] Morten: * Fix printing issue when sheet is zoomed. [#332932] diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog index a4e567054..10b7dbe48 100644 --- a/plugins/excel/ChangeLog +++ b/plugins/excel/ChangeLog @@ -1,3 +1,11 @@ +2006-03-13 Morten Welinder + + * ms-excel-write.c (write_sheet_head): Write protection flags. + * ms-excel-read.c (excel_read_sheet_PROTECT): Store falg. + (excel_read_workbook_PROTECT): New function. + (excel_read_workbook): Read protection flags. + Patch from Klokan Petr Pridal. [#330129] + 2006-03-10 Jody Goldberg * ms-formula-read.c (excel_parse_formula) : back port handling of diff --git a/plugins/excel/ms-excel-read.c b/plugins/excel/ms-excel-read.c index d00248e8f..e91e85bc7 100644 --- a/plugins/excel/ms-excel-read.c +++ b/plugins/excel/ms-excel-read.c @@ -4199,19 +4199,35 @@ sheet_container (ExcelReadSheet *esheet) } static gboolean -excel_read_PROTECT (BiffQuery *q, char const *obj_type) +excel_read_sheet_PROTECT (BiffQuery *q, ExcelReadSheet *esheet) { - /* TODO: Use this information when gnumeric supports protection */ gboolean is_protected = TRUE; /* MS Docs fail to mention that in some stream this * record can have size zero. I assume the in that * case its existence is the flag. */ - if (q->length > 0) + if (q->length >= 2) is_protected = (1 == GSF_LE_GET_GUINT16 (q->data)); - d (1,if (is_protected) fprintf (stderr,"%s is protected\n", obj_type);); + esheet->sheet->is_protected = is_protected; + + return is_protected; +} + +static gboolean +excel_read_workbook_PROTECT (BiffQuery *q, WorkbookView *wb_view) +{ + gboolean is_protected = TRUE; + + /* MS Docs fail to mention that in some stream this + * record can have size zero. I assume the in that + * case its existence is the flag. + */ + if (q->length >= 2) + is_protected = (1 == GSF_LE_GET_GUINT16 (q->data)); + + wb_view->is_protected = is_protected; return is_protected; } @@ -5547,7 +5563,8 @@ excel_read_sheet (BiffQuery *q, GnmXLImporter *importer, case BIFF_REFMODE: excel_read_REFMODE (q, esheet); break; case BIFF_DELTA: excel_read_DELTA (q, importer); break; case BIFF_ITERATION: excel_read_ITERATION (q, importer); break; - case BIFF_PROTECT: excel_read_PROTECT (q, "Sheet"); break; + case BIFF_OBJPROTECT: + case BIFF_PROTECT: excel_read_sheet_PROTECT (q, esheet); break; case BIFF_PASSWORD: if (q->length == 2) { @@ -5633,7 +5650,6 @@ excel_read_sheet (BiffQuery *q, GnmXLImporter *importer, case BIFF_SAVERECALC: break; case BIFF_TAB_COLOR: excel_read_TAB_COLOR (q, esheet); break; - case BIFF_OBJPROTECT: excel_read_PROTECT (q, "Sheet"); break; case BIFF_COLINFO: excel_read_COLINFO (q, esheet); break; case BIFF_RK: @@ -6082,7 +6098,7 @@ excel_read_workbook (IOContext *context, WorkbookView *wb_view, GsfInput *input, case BIFF_OBJPROTECT: case BIFF_PROTECT: - excel_read_PROTECT (q, "Workbook"); + excel_read_workbook_PROTECT (q, wb_view); break; case BIFF_PASSWORD: diff --git a/plugins/excel/ms-excel-write.c b/plugins/excel/ms-excel-write.c index dc1fca469..d7e903bd2 100644 --- a/plugins/excel/ms-excel-write.c +++ b/plugins/excel/ms-excel-write.c @@ -4077,6 +4077,12 @@ write_sheet_head (BiffPut *bp, ExcelWriteSheet *esheet) * to make our lives easier */ excel_write_externsheets_v7 (esheet->ewb); } + if (sheet->is_protected) { + ms_biff_put_2byte (bp, BIFF_PROTECT, 1 ); + ms_biff_put_2byte (bp, BIFF_OBJPROTECT, 1); + ms_biff_put_2byte (bp, BIFF_SCENPROTECT, 1); + ms_biff_put_2byte (bp, BIFF_PASSWORD, 0); + } excel_write_DEFCOLWIDTH (bp, esheet); excel_write_colinfos (bp, esheet); excel_write_AUTOFILTERINFO (bp, esheet); @@ -5191,7 +5197,7 @@ excel_write_workbook (ExcelWriteState *ewb) } ms_biff_put_2byte (ewb->bp, BIFF_WINDOWPROTECT, 0); - ms_biff_put_2byte (ewb->bp, BIFF_PROTECT, 0); + ms_biff_put_2byte (ewb->bp, BIFF_PROTECT, ewb->gnum_wb_view->is_protected ? 1 : 0); ms_biff_put_2byte (ewb->bp, BIFF_PASSWORD, 0); if (bp->version >= MS_BIFF_V8) { -- GitLab