sc/inc/globstr.hrc               |    4 +++-
 sc/source/core/data/attarray.cxx |   34 ++++++++++++++++++++++++++++++++++
 sc/source/core/data/fillinfo.cxx |   21 ++++++++++++++++-----
 sc/source/core/data/table2.cxx   |    3 ++-
 sc/source/ui/src/globstr.src     |    4 ++++
 sc/source/ui/view/cellsh1.cxx    |   12 ++++++++++++
 6 files changed, 71 insertions(+), 7 deletions(-)

New commits:
commit 24712398aa28b5a612a9a2bdeecd51d3eb9535e8
Author: Markus Mohrhard <markus.mohrh...@googlemail.com>
Date:   Thu Sep 6 18:52:12 2012 +0200

    handle protection in conditional formats correctly, fdo#51636
    
    Change-Id: I81d7369218ae8e361f15d811952a8f690a32df96

diff --git a/sc/source/core/data/attarray.cxx b/sc/source/core/data/attarray.cxx
index 6cf487f..bcba4de 100644
--- a/sc/source/core/data/attarray.cxx
+++ b/sc/source/core/data/attarray.cxx
@@ -1189,7 +1189,41 @@ bool ScAttrArray::HasAttrib( SCROW nRow1, SCROW nRow2, 
sal_uInt16 nMask ) const
         {
             const ScProtectionAttr* pProtect =
                     (const ScProtectionAttr*) &pPattern->GetItem( 
ATTR_PROTECTION );
+            bool bFoundTemp = false;
             if ( pProtect->GetProtection() || pProtect->GetHideCell() )
+                bFoundTemp = true;
+
+            const SfxUInt32Item* pConditional =
+                    (const SfxUInt32Item*) &pPattern->GetItem( 
ATTR_CONDITIONAL );
+            if ( pConditional->GetValue() != 0 )
+            {
+                SCROW nRowStartCond = std::max<SCROW>( nRow1, i ? 
pData[i-1].nRow + 1: 0 );
+                SCROW nRowEndCond = std::min<SCROW>( nRow2, pData[i].nRow );
+                bool bFoundCond = false;
+                for(SCROW nRowCond = nRowStartCond; nRowCond <= nRowEndCond && 
!bFoundCond; ++nRowCond)
+                {
+                    const SfxItemSet* pSet = pDocument->GetCondResult( nCol, 
nRowCond, nTab );
+
+                    const SfxPoolItem* pItem;
+                    if( pSet && pSet->GetItemState( ATTR_PROTECTION, true, 
&pItem ) == SFX_ITEM_SET )
+                    {
+                        const ScProtectionAttr* pCondProtect = 
static_cast<const ScProtectionAttr*>(pItem);
+                        if( pCondProtect->GetProtection() || 
pProtect->GetHideCell() )
+                            bFoundCond = true;
+                    }
+                    else
+                    {
+                        // well it is not true that we found one
+                        // but existing one + cell where conditional
+                        // formatting does not remove it
+                        // => we have a protected cell
+                        bFoundCond = true;
+                    }
+                }
+                bFoundTemp = bFoundCond;
+            }
+
+            if(bFoundTemp)
                 bFound = true;
         }
         if ( nMask & HASATTR_ROTATE )
diff --git a/sc/source/core/data/fillinfo.cxx b/sc/source/core/data/fillinfo.cxx
index 743aa26..1ee5a51 100644
--- a/sc/source/core/data/fillinfo.cxx
+++ b/sc/source/core/data/fillinfo.cxx
@@ -533,11 +533,6 @@ void ScDocument::FillInfo( ScTableInfo& rTabInfo, SCCOL 
nX1, SCROW nY1, SCCOL nX
                                     pThisRowInfo->bEmptyBack = false;
                                 }
 
-                                if (bHidden || ( bFormulaMode && bHideFormula 
&& pInfo->pCell
-                                                    && 
pInfo->pCell->GetCellType()
-                                                        == CELLTYPE_FORMULA ))
-                                    pInfo->bEmptyCellText = true;
-
                                 if ( pCondForm )
                                 {
                                     ScCondFormatData aData = 
pCondForm->GetData( pInfo->pCell,
@@ -551,6 +546,17 @@ void ScDocument::FillInfo( ScTableInfo& rTabInfo, SCCOL 
nX1, SCROW nY1, SCCOL nX
                                             //! Style-Sets cachen !!!
                                             pInfo->pConditionSet = 
&pStyleSheet->GetItemSet();
                                             bAnyCondition = true;
+
+                                            // we need to check already here 
for protected cells
+                                            const SfxPoolItem* pItem;
+                                            if ( bTabProtect && 
pInfo->pConditionSet->GetItemState( ATTR_PROTECTION, true, &pItem ) == 
SFX_ITEM_SET )
+                                            {
+                                                const ScProtectionAttr* 
pProtAttr = static_cast<const ScProtectionAttr*>(pItem);
+                                                bHidden = 
pProtAttr->GetHideCell();
+                                                bHideFormula = 
pProtAttr->GetHideFormula();
+
+                                            }
+
                                         }
                                         // if style is not there, treat like 
no condition
                                     }
@@ -565,6 +571,11 @@ void ScDocument::FillInfo( ScTableInfo& rTabInfo, SCCOL 
nX1, SCROW nY1, SCCOL nX
                                     }
                                 }
 
+                                if (bHidden || ( bFormulaMode && bHideFormula 
&& pInfo->pCell
+                                                    && 
pInfo->pCell->GetCellType()
+                                                        == CELLTYPE_FORMULA ))
+                                    pInfo->bEmptyCellText = true;
+
                                 ++nArrY;
                             }
                             else if (bRowHidden && nLastHiddenRow >= 0)
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index afb9c6b..48cff65 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -1909,7 +1909,8 @@ bool ScTable::IsBlockEditable( SCCOL nCol1, SCROW nRow1, 
SCCOL nCol2,
         bIsEditable = false;
     else if ( IsProtected() && !pDocument->IsScenario(nTab) )
     {
-        if((bIsEditable = !HasAttrib( nCol1, nRow1, nCol2, nRow2, 
HASATTR_PROTECTED )) != false)
+        bIsEditable = !HasAttrib( nCol1, nRow1, nCol2, nRow2, 
HASATTR_PROTECTED );
+        if(bIsEditable)
         {
             // If Sheet is protected and cells are not protected then
             // check the active scenario protect flag if this range is
commit 8ebc294b5bbcbfe27db3718453fbfcf129329b90
Author: Markus Mohrhard <markus.mohrh...@googlemail.com>
Date:   Thu Sep 6 17:02:44 2012 +0200

    no conditional format changes i protected sheets, related fdo#51636
    
    Change-Id: I228ca76c34e3e18ea4d4f2197db20222319ebbd0

diff --git a/sc/inc/globstr.hrc b/sc/inc/globstr.hrc
index 0694946..42d8c1e 100644
--- a/sc/inc/globstr.hrc
+++ b/sc/inc/globstr.hrc
@@ -600,7 +600,9 @@
 #define STR_COND_UNIQUE             475
 #define STR_COND_DUPLICATE          476
 
-#define STR_COUNT                   477
+#define STR_ERR_CONDFORMAT_PROTECTED 477
+
+#define STR_COUNT                   478
 
 
 #endif
diff --git a/sc/source/ui/src/globstr.src b/sc/source/ui/src/globstr.src
index 0b25b8c..a58f5b6 100644
--- a/sc/source/ui/src/globstr.src
+++ b/sc/source/ui/src/globstr.src
@@ -1895,5 +1895,9 @@ Resource RID_GLOBSTR
     {
         Text [ en-US ] = "Formula is";
     };
+    String STR_ERR_CONDFORMAT_PROTECTED
+    {
+        Text [ en-US ] = "Conditional Formats can not be created, deleted or 
changed in protected sheets!";
+    };
 };
 
diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx
index 90e3dfe..c7f0ef8 100644
--- a/sc/source/ui/view/cellsh1.cxx
+++ b/sc/source/ui/view/cellsh1.cxx
@@ -2044,6 +2044,12 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
                 pData->GetMarkData().FillRangeListWithMarks(&aRangeList, 
false);
                 ScDocument* pDoc = pData->GetDocument();
 
+                if(pDoc->IsTabProtected(pData->GetTabNo()))
+                {
+                    pTabViewShell->ErrorMessage( STR_ERR_CONDFORMAT_PROTECTED 
);
+                    break;
+                }
+
                 ScAddress aPos(pData->GetCurX(), pData->GetCurY(), 
pData->GetTabNo());
                 if(aRangeList.empty())
                 {
@@ -2084,6 +2090,12 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
                 pData->GetMarkData().FillRangeListWithMarks(&aRangeList, 
false);
                 ScDocument* pDoc = pData->GetDocument();
 
+                if(pDoc->IsTabProtected(pData->GetTabNo()))
+                {
+                    pTabViewShell->ErrorMessage( STR_ERR_CONDFORMAT_PROTECTED 
);
+                    break;
+                }
+
                 ScAddress aPos(pData->GetCurX(), pData->GetCurY(), 
pData->GetTabNo());
                 if(aRangeList.empty())
                 {
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to