summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sc/source/ui/docshell/docfunc.cxx65
-rw-r--r--sc/source/ui/inc/docfunc.hxx9
-rw-r--r--sc/source/ui/view/cellsh1.cxx3
3 files changed, 71 insertions, 6 deletions
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx
index 41fdfe6cccec..72dbd69f1331 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -5059,6 +5059,30 @@ sal_Bool ScDocFunc::InsertAreaLink( const String& rFile, const String& rFilter,
return sal_True;
}
+namespace {
+
+void RemoveCondFormatAttributes(ScDocument* pDoc, const ScConditionalFormat* pFormat)
+{
+ const ScRangeList& rRangeList = pFormat->GetRange();
+
+ ScPatternAttr aPattern( pDoc->GetPool() );
+ aPattern.GetItemSet().Put( SfxUInt32Item( ATTR_CONDITIONAL, 0 ) );
+ ScMarkData aMarkData;
+ aMarkData.MarkFromRangeList(rRangeList, true);
+ pDoc->ApplySelectionPattern( aPattern , aMarkData );
+}
+
+void SetConditionalFormatAttributes(ScDocument* pDoc, const ScRangeList& rRanges, sal_uLong nIndex)
+{
+ ScPatternAttr aPattern( pDoc->GetPool() );
+ aPattern.GetItemSet().Put( SfxUInt32Item( ATTR_CONDITIONAL, nIndex ) );
+ ScMarkData aMarkData;
+ aMarkData.MarkFromRangeList(rRanges, true);
+ pDoc->ApplySelectionPattern( aPattern , aMarkData );
+}
+
+}
+
void ScDocFunc::ReplaceConditionalFormat( sal_uLong nOldFormat, ScConditionalFormat* pFormat, SCTAB nTab, const ScRangeList& rRanges )
{
ScDocShellModificator aModificator(rDocShell);
@@ -5068,6 +5092,12 @@ void ScDocFunc::ReplaceConditionalFormat( sal_uLong nOldFormat, ScConditionalFor
if(nOldFormat)
{
+ ScConditionalFormat* pOldFormat = pDoc->GetCondFormList(nTab)->GetFormat(nOldFormat);
+ if(pOldFormat)
+ {
+ RemoveCondFormatAttributes(pDoc, pOldFormat);
+ }
+
pDoc->DeleteConditionalFormat(nOldFormat, nTab);
pDoc->SetStreamValid(nTab, false);
}
@@ -5075,11 +5105,7 @@ void ScDocFunc::ReplaceConditionalFormat( sal_uLong nOldFormat, ScConditionalFor
{
sal_uLong nIndex = pDoc->AddCondFormat(pFormat, nTab);
- ScPatternAttr aPattern( pDoc->GetPool() );
- aPattern.GetItemSet().Put( SfxUInt32Item( ATTR_CONDITIONAL, nIndex ) );
- ScMarkData aMarkData;
- aMarkData.MarkFromRangeList(rRanges, true);
- pDoc->ApplySelectionPattern( aPattern , aMarkData );
+ SetConditionalFormatAttributes(pDoc, rRanges, nIndex);
size_t n = rRanges.size();
for(size_t i = 0; i < n; ++i)
pFormat->DoRepaint(rRanges[i]);
@@ -5089,6 +5115,35 @@ void ScDocFunc::ReplaceConditionalFormat( sal_uLong nOldFormat, ScConditionalFor
SFX_APP()->Broadcast(SfxSimpleHint(SC_HINT_AREAS_CHANGED));
}
+void ScDocFunc::SetConditionalFormatList( ScConditionalFormatList* pList, SCTAB nTab )
+{
+ ScDocShellModificator aModificator(rDocShell);
+ ScDocument* pDoc = rDocShell.GetDocument();
+ if(pDoc->IsTabProtected(nTab))
+ return;
+
+ // first remove all old entries
+ ScConditionalFormatList* pOldList = pDoc->GetCondFormList(nTab);
+ for(ScConditionalFormatList::const_iterator itr = pOldList->begin(), itrEnd = pOldList->end(); itr != itrEnd; ++itr)
+ {
+ RemoveCondFormatAttributes(pDoc, &(*itr));
+ }
+
+ // then set new entries
+ for(ScConditionalFormatList::iterator itr = pList->begin(); itr != pList->end(); ++itr)
+ {
+ sal_uLong nIndex = itr->GetKey();
+ const ScRangeList& rRange = itr->GetRange();
+ SetConditionalFormatAttributes(pDoc, rRange, nIndex);
+ }
+
+ pDoc->SetCondFormList(pList, nTab);
+
+ pDoc->SetStreamValid(nTab, false);
+ aModificator.SetDocumentModified();
+ SFX_APP()->Broadcast(SfxSimpleHint(SC_HINT_AREAS_CHANGED));
+}
+
void ScDocFunc::EnterListAction( sal_uInt16 nNameResId )
{
String aUndo( ScGlobal::GetRscString( nNameResId ) );
diff --git a/sc/source/ui/inc/docfunc.hxx b/sc/source/ui/inc/docfunc.hxx
index 8d87bd98e8b0..3c9d64d8a255 100644
--- a/sc/source/ui/inc/docfunc.hxx
+++ b/sc/source/ui/inc/docfunc.hxx
@@ -53,6 +53,7 @@ struct ScTabOpParam;
class ScTableProtection;
struct ScCellMergeOption;
class ScConditionalFormat;
+class ScConditionalFormatList;
// ---------------------------------------------------------------------------
@@ -212,6 +213,14 @@ public:
* @param pFormat if NULL only delete an old format
*/
virtual void ReplaceConditionalFormat( sal_uLong nOldIndex, ScConditionalFormat* pFormat, SCTAB nTab, const ScRangeList& rRanges );
+
+ /**
+ * Sets or replaces the conditional format list of a table
+ *
+ * @param pList the new ScConditionalFormatList, method takes ownership
+ * @param nTab the tab to which the conditional format list belongs
+ */
+ virtual void SetConditionalFormatList( ScConditionalFormatList* pList, SCTAB nTab );
};
class ScDocFuncDirect : public ScDocFunc
diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx
index bd8f75acd89f..a5b739e24648 100644
--- a/sc/source/ui/view/cellsh1.cxx
+++ b/sc/source/ui/view/cellsh1.cxx
@@ -2100,7 +2100,8 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
AbstractScCondFormatManagerDlg* pDlg = pFact->CreateScCondFormatMgrDlg( pTabViewShell->GetDialogParent(), pDoc, pList, aPos, RID_SCDLG_COND_FORMAT_MANAGER);
if(pDlg->Execute() == RET_OK)
{
- pDoc->SetCondFormList(pDlg->GetConditionalFormatList(), aPos.Tab());
+ ScConditionalFormatList* pCondFormatList = pDlg->GetConditionalFormatList();
+ pData->GetDocShell()->GetDocFunc().SetConditionalFormatList(pCondFormatList, aPos.Tab());
}
delete pDlg;
}