Attached are a pair of patches (for 1.0.4 and 1.1.x) which implement the 'locked' cell format property. The current implementation is not bullet-proof: you can currently modify a 'locked' cell by using Ctrl-Enter or autofill --- but I believe Excel has these bugs, too. The patch ungreys the existing 'Workbook locked' checkbox in Format->Cells->Protection and also adds an equivalent option to Format->Workbook->Protection (where I believe the option logically belongs). When the workbook is protected, locked cells are greyed out. If this patch is accepted, my intent is to then continue and make locked cells more modification-proof (patching into autofill, etc), and add more options to the Format->Workbook->Protection dialog to en/disable greying out locked cells, allow the 'can't edit locked cells' dialog to be changed to a beep (in cases where the dialog would intrude on data entry), etc. But I figured I'd get the core functionality in first. The patch, file by file: * plugins/excel/ms-excel-write.c (build_xf_data): change a comment to indicate that we do, now, implement locked cells. * src/cell-draw.c (cell_draw): grey out locked cells when drawn with the workbook protected. Added an extra parameter to indicate whether the workbook is protected, as the cell_draw function can't access the Workbook object with the parameters it is given. * src/cell-draw.h (cell_draw): modify the prototype as per above. * src/gnumeric-canvas.c (gnm_canvas_key_mode_sheet): don't put us in edit mode if wbcg_edit_start indicates the cell is locked. * src/item-grid.c (item_grid_draw_merged_range, item_grid_draw): pass new 'workbook protected' parameter to cell_draw. * src/preview-grid.c (preview_grid_draw): ditto. Cells are never greyed out in preview grids. * src/workbook-control-gui.c (cb_prefs_update): call sheet_adjust_preferences with 'redraw' set to TRUE as cells may be newly greyed-out, requiring a refresh. * src/workbook-control-gui.c (cb_autosum, cb_autofunction): handle case where wbcg_edit_start returns FALSE indicating that cell is locked. * src/workbook-control-gui.c (wbcg_locked_msg, workbook_control_gui_ctor_class): * src/workbook-control-priv.h: * src/workbook-control.c (wb_control_locked_msg): * src/workbook-control.h: virtual method to put up error dialog when we attempt to edit a locked cell. Based on wb_control_validation_msg. * src/workbook-edit.c (wbcg_edit_start): this function now returns a boolean which indicates whether the 'edit_start' attempt succeeded. Check cell properties to return FALSE if the cell is locked. * src/workbook-edit.h (wbcg_edit_start): modify the prototype as per above. * src/workbook-view.c (wb_view_set_arg, wb_view_get_arg, workbook_view_init, workbook_view_class_init): *** 1.0.4 BRANCH *** add new ARG_VIEW_PROTECTED argument to the WorkbookView gtk object, with appropriate getters/setters. * src/workbook-view.c (wb_view_set_attribute, workbook_view_init): *** 1.1.x BRANCH *** Remove ARG_VIEW_* enumeration, which isn't used after Gnome2 port. Add WorkbookView::protected attribute, and initialize it to FALSE. * src/workbook-view.h: add 'protected' field to WorkbookView struct. This is TRUE iff the workbook is locked. * src/xml-io.c (xml_write_wbv_attributes): *** 1.1.x BRANCH *** Read/write the new 'protected' workbook view attribute. [offtopic: i must say the pre-gnome2 code was cleaner, in that the xml code was more modular and didn't have to contain intimate details aboue the WorkbookView struct. On the 1.0.4 branch I didn't have to modify xml-io.c at all to get my new workbookview attribute properly saved to/loaded from disk.] * src/dialogs/cell-format.glade: The 'worksheet protected' checkbox shouldn't be greyed-out anymore. * src/dialogs/dialog-cell-format.c (cb_protection_sheet_protected_toggle, fmt_dialog_init_protection_page, cb_fmt_dialog_dialog_buttons): connect up the 'worksheet protected' button in the Format->Cells->Protection dialog. Update worksheet object when toggled and mark that the dialog's changed. The screen will eventually get updated by the sheet_update() call in cb_fmt_dialog_dialog_buttons. * src/dialogs/dialog-workbook-attr.c src/dialogs/workbook-attr.glade: Add Format->Worksheet->Protection dialog. Enjoy! --scott non-violent protest pending C4 SLBM UKUSA SDI MI6 Delta Force Semtex anthrax class struggle Marxist agent Sudan munitions Waco, Texas bomb ( http://lesser-magoo.lcs.mit.edu/~cananian )
Attachment:
patch-HEAD-cvs.locked
Description: Patch for 1.1.x branch
Attachment:
patch-1.0.4-cvs.locked
Description: Patch for 1.0.4 branch