summaryrefslogtreecommitdiff
path: root/sd/source/core
diff options
context:
space:
mode:
authorDavid Tardon <dtardon@redhat.com>2013-01-17 15:01:32 +0100
committerThorsten Behrens <tbehrens@suse.com>2013-01-23 20:44:49 +0100
commitf9e83484ad766fe02589daaf00d46dee63c55d43 (patch)
tree9a994be40720607db46869b553e89a69c982504d /sd/source/core
parentfbdd9b181e59a0510fc5e7dcb56fac8e0dc6bb8f (diff)
rhbz#760765 copy custom styles on copy & paste
Change-Id: Icaacf3bc1a02a017692432aec36aba06d3f5dde5 Signed-off-by: Thorsten Behrens <tbehrens@suse.com>
Diffstat (limited to 'sd/source/core')
-rw-r--r--sd/source/core/drawdoc3.cxx49
-rw-r--r--sd/source/core/stlpool.cxx18
-rw-r--r--sd/source/core/stlsheet.cxx16
3 files changed, 74 insertions, 9 deletions
diff --git a/sd/source/core/drawdoc3.cxx b/sd/source/core/drawdoc3.cxx
index 9909623385a3..e2d7039b0781 100644
--- a/sd/source/core/drawdoc3.cxx
+++ b/sd/source/core/drawdoc3.cxx
@@ -357,6 +357,26 @@ sal_Bool SdDrawDocument::InsertBookmark(
return bOK;
}
+namespace
+{
+
+void
+lcl_removeUnusedStyles(SfxStyleSheetBasePool* const pStyleSheetPool, SdStyleSheetVector& rStyles)
+{
+ SdStyleSheetVector aUsedStyles;
+ aUsedStyles.reserve(rStyles.size());
+ for (SdStyleSheetVector::const_iterator aIt(rStyles.begin()), aLast(rStyles.end()); aIt != aLast; ++aIt)
+ {
+ if ((*aIt)->IsUsed())
+ aUsedStyles.push_back(*aIt);
+ else
+ pStyleSheetPool->Remove((*aIt).get());
+ }
+ rStyles = aUsedStyles;
+}
+
+}
+
sal_Bool SdDrawDocument::InsertBookmarkAsPage(
const std::vector<rtl::OUString> &rBookmarkList,
std::vector<rtl::OUString> *pExchangeList, // Liste der zu verwendenen Namen
@@ -484,8 +504,8 @@ sal_Bool SdDrawDocument::InsertBookmarkAsPage(
/**************************************************************************
* Die tatsaechlich benoetigten Vorlagen kopieren
**************************************************************************/
- SdStyleSheetPool* pBookmarkStyleSheetPool =
- (SdStyleSheetPool*) pBookmarkDoc->GetStyleSheetPool();
+ SdStyleSheetPool* pBookmarkStyleSheetPool = dynamic_cast<SdStyleSheetPool*>(pBookmarkDoc->GetStyleSheetPool());
+ SdStyleSheetPool* pStyleSheetPool = dynamic_cast<SdStyleSheetPool*>(GetStyleSheetPool());
// Wenn Vorlagen kopiert werden muessen, dann muessen auch die
// MasterPages kopiert werden!
@@ -498,7 +518,7 @@ sal_Bool SdDrawDocument::InsertBookmarkAsPage(
SdStyleSheetVector aCreatedStyles;
String layoutName = *pIter;
- ((SdStyleSheetPool*)GetStyleSheetPool())->CopyLayoutSheets(layoutName, *pBookmarkStyleSheetPool,aCreatedStyles);
+ pStyleSheetPool->CopyLayoutSheets(layoutName, *pBookmarkStyleSheetPool,aCreatedStyles);
if(!aCreatedStyles.empty())
{
@@ -510,6 +530,18 @@ sal_Bool SdDrawDocument::InsertBookmarkAsPage(
}
}
+ // Copy styles. This unconditionally copies all styles, even those
+ // that are not used in any of the inserted pages. The unused styles
+ // are then removed at the end of the function, where we also create
+ // undo records for the inserted styles.
+ SdStyleSheetVector aNewGraphicStyles;
+ pStyleSheetPool->CopyGraphicSheets(*pBookmarkStyleSheetPool, aNewGraphicStyles);
+ SdStyleSheetVector aNewCellStyles;
+ pStyleSheetPool->CopyCellSheets(*pBookmarkStyleSheetPool, aNewCellStyles);
+
+ // TODO handle undo of table styles too
+ pStyleSheetPool->CopyTableStyles(*pBookmarkStyleSheetPool);
+
/**************************************************************************
* Dokument einfuegen
**************************************************************************/
@@ -910,6 +942,17 @@ sal_Bool SdDrawDocument::InsertBookmarkAsPage(
// Make absolutely sure no double masterpages are there
RemoveUnnecessaryMasterPages(NULL, sal_True, sal_True);
+ // remove copied styles not used on any inserted page and create
+ // undo records
+ // WARNING: SdMoveStyleSheetsUndoAction clears the passed list of
+ // styles, so it cannot be used after this point
+ lcl_removeUnusedStyles(GetStyleSheetPool(), aNewGraphicStyles);
+ if (!aNewGraphicStyles.empty() && pUndoMgr)
+ pUndoMgr->AddUndoAction(new SdMoveStyleSheetsUndoAction(this, aNewGraphicStyles, sal_True));
+ lcl_removeUnusedStyles(GetStyleSheetPool(), aNewCellStyles);
+ if (!aNewCellStyles.empty() && pUndoMgr)
+ pUndoMgr->AddUndoAction(new SdMoveStyleSheetsUndoAction(this, aNewCellStyles, sal_True));
+
if( bUndo )
EndUndo();
pUndoMgr->LeaveListAction();
diff --git a/sd/source/core/stlpool.cxx b/sd/source/core/stlpool.cxx
index 078a64dc57b7..cfe6c82a54bc 100644
--- a/sd/source/core/stlpool.cxx
+++ b/sd/source/core/stlpool.cxx
@@ -582,8 +582,24 @@ void SdStyleSheetPool::CopyTableStyles(SdStyleSheetPool& rSourcePool)
}
}
+void SdStyleSheetPool::CopyGraphicSheets(SdStyleSheetPool& rSourcePool, SdStyleSheetVector& rCreatedSheets)
+{
+ CopySheets( rSourcePool, SD_STYLE_FAMILY_GRAPHICS, rCreatedSheets );
+}
+
+void SdStyleSheetPool::CopyCellSheets(SdStyleSheetPool& rSourcePool, SdStyleSheetVector& rCreatedSheets)
+{
+ CopySheets( rSourcePool, SD_STYLE_FAMILY_CELL, rCreatedSheets );
+}
+
void SdStyleSheetPool::CopySheets(SdStyleSheetPool& rSourcePool, SfxStyleFamily eFamily )
{
+ SdStyleSheetVector aTmpSheets;
+ CopySheets(rSourcePool, eFamily, aTmpSheets);
+}
+
+void SdStyleSheetPool::CopySheets(SdStyleSheetPool& rSourcePool, SfxStyleFamily eFamily, SdStyleSheetVector& rCreatedSheets)
+{
String aHelpFile;
sal_uInt32 nCount = rSourcePool.aStyles.size();
@@ -610,6 +626,8 @@ void SdStyleSheetPool::CopySheets(SdStyleSheetPool& rSourcePool, SfxStyleFamily
xNewSheet->SetHelpId( aHelpFile, xSheet->GetHelpId( aHelpFile ) );
xNewSheet->GetItemSet().Put( xSheet->GetItemSet() );
+
+ rCreatedSheets.push_back( SdStyleSheetRef( static_cast< SdStyleSheet* >( xNewSheet.get() ) ) );
}
}
}
diff --git a/sd/source/core/stlsheet.cxx b/sd/source/core/stlsheet.cxx
index ecd84d74b302..f0137390efc5 100644
--- a/sd/source/core/stlsheet.cxx
+++ b/sd/source/core/stlsheet.cxx
@@ -35,6 +35,7 @@
#include <svl/smplhint.hxx>
#include <svl/itemset.hxx>
+#include <svx/sdr/properties/attributeproperties.hxx>
#include <svx/xflbmtit.hxx>
#include <svx/xflbstit.hxx>
#include <editeng/bulitem.hxx>
@@ -349,13 +350,16 @@ bool SdStyleSheet::IsUsed() const
continue;
// NULL-Pointer ist im Listener-Array erlaubt
- if (pListener && pListener->ISA(SdrAttrObj))
+ if (pListener)
{
- bResult = ((SdrAttrObj*)pListener)->IsInserted();
- }
- else if (pListener && pListener->ISA(SfxStyleSheet))
- {
- bResult = ((SfxStyleSheet*)pListener)->IsUsed();
+ if (pListener->ISA(sdr::properties::AttributeProperties))
+ {
+ bResult = true;
+ }
+ else if (pListener->ISA(SfxStyleSheet))
+ {
+ bResult = ((SfxStyleSheet*)pListener)->IsUsed();
+ }
}
if (bResult)
break;