locked cells



Out of curiosity, I tried to see how much is involved to make the statistical analysis tools and random generator honour the lock-state of cells. Attached is a diff containing all the necessary changes (the patch has already been applied to cvs head).

Some observations:

- Workbook protection is a view property rather than a workbook property, ie. 2 views of the same workbook can be open with one view protected the other one not.

- All actions that change the cells should be undoable, ie. go through commands.c. For many actions it may be appropriate to check for lock status only when the action is perfomed (eg the analysis tools). In that case the appropriate check should be in commands.c. For some actions (editing a single cell etc) of course lock problems should be caught when the user strats setting up the action.

- wb_view_is_locked looks like a nice tool but assumes that editing is performed on the current sheet (which for example is not necessarily rue for the analysis tools).

Andreas

--
Prof. Dr. Andreas J. Guelzow
http://www.math.concordia.ab.ca/aguelzow
Index: src/commands.c
===================================================================
RCS file: /cvs/gnome/gnumeric/src/commands.c,v
retrieving revision 1.280
diff -u -r1.280 commands.c
--- src/commands.c      19 May 2002 21:26:12 -0000      1.280
+++ src/commands.c      13 Jun 2002 19:29:34 -0000
@@ -176,6 +176,7 @@
 
 /******************************************************************/
 
+
 /**
  * returns the range name depending on the preference setting
  *
@@ -193,6 +194,47 @@
 }
 
 /**
+ * checks whetehr the cells are effectively locked
+ *
+ * static gboolean cmd_cell_range_is_locked_effective
+ *
+ *
+ * Do not use this function unless the sheet is part of the 
+ * workbook with the given wbcg (otherwise the results may be strange) 
+ *
+ */
+
+static gboolean 
+cmd_cell_range_is_locked_effective (WorkbookControlGUI *wbcg, Sheet *sheet, 
+                                   int start_col, int cols, 
+                                   int start_row, int rows)
+{
+       int i, j;
+       WorkbookView *wbv = wb_control_view (WORKBOOK_CONTROL (wbcg));
+
+       if (wbv->is_protected || sheet->is_protected)
+               for (i = start_row + rows; i-- > start_row;)
+                       for (j = start_col + cols; j-- > start_col;)
+                               if (mstyle_get_content_locked (sheet_style_get (sheet, j, i))) {
+                                       Range range;
+                                       char *text;
+                                       range_init (&range, start_col, start_row, 
+                                                   start_col + cols - 1,
+                                                   start_row + rows - 1);
+                                       text = g_strdup_printf (wbv->is_protected  ? 
+                                _("%s is locked. Unprotect the workbook to enable editing.") : 
+                                _("%s is locked. Unprotect the sheet to enable editing."), 
+                                                               undo_global_range_name (
+                                                                       sheet, &range));
+                                       gnumeric_notice (wbcg, GTK_MESSAGE_ERROR, text);
+                                       /*show warning*/
+                                       g_free (text);
+                                       return TRUE;
+                               }
+       return FALSE;
+}
+
+/**
  * returns the cell position name depending on the preference setting
  *
  * char *cmd_cell_pos_name_utility
@@ -4496,13 +4538,15 @@
                me->row_info = colrow_state_list_destroy (me->row_info);
        me->row_info = dao_get_colrow_state_list (me->dao, FALSE);
 
-       if (me->engine (me->dao, me->specs, TOOL_ENGINE_PREPARE_OUTPUT_RANGE, NULL))
-               return TRUE;
-       if (me->engine (me->dao, me->specs, TOOL_ENGINE_UPDATE_DESCRIPTOR, 
-                       &me->parent.cmd_descriptor))
-               return TRUE;
-       
-       if (me->engine (me->dao, me->specs, TOOL_ENGINE_LAST_VALIDITY_CHECK, &continuity))
+       if (me->engine (me->dao, me->specs, TOOL_ENGINE_PREPARE_OUTPUT_RANGE, NULL)
+           || (me->dao->type != NewWorkbookOutput &&
+               cmd_cell_range_is_locked_effective (WORKBOOK_CONTROL_GUI (wbc), 
+                                                   me->dao->sheet, 
+                                                   me->dao->start_col, me->dao->cols, 
+                                                   me->dao->start_row, me->dao->rows))
+           || me->engine (me->dao, me->specs, TOOL_ENGINE_UPDATE_DESCRIPTOR, 
+                          &me->parent.cmd_descriptor)
+           || me->engine (me->dao, me->specs, TOOL_ENGINE_LAST_VALIDITY_CHECK, &continuity))
                return TRUE;
 
        switch (me->type) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]