summaryrefslogtreecommitdiffstats
path: root/sw
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2014-06-13 09:29:12 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2014-06-13 10:58:17 +0200
commit02f2d886c897a286b875f9053052061fe0b357fd (patch)
treebca0958a8ee192f9e1563fdfdf57bd9bf629d9cb /sw
parentSwDoc::DelLayoutFmt: don't delete content of a draw format (diff)
downloadcore-02f2d886c897a286b875f9053052061fe0b357fd.tar.gz
core-02f2d886c897a286b875f9053052061fe0b357fd.zip
SwDoc::CopyFlyInFlyImpl: factor out textbox code into SwTextBoxHelper
Also, let the new SwTextBoxHelper::restoreLinks() restore also the RES_CNTNT of the *old* draw formats, not only the link between the new draw and fly formats. This allows properly preserving the link between draw and fly formats, when they are in the header (and so copied in and out variously). Change-Id: I101ff06533e2ea27abea8bed171ed69c9649ebe8
Diffstat (limited to 'sw')
-rw-r--r--sw/inc/textboxhelper.hxx17
-rw-r--r--sw/source/core/doc/textboxhelper.cxx43
-rw-r--r--sw/source/core/docnode/ndcopy.cxx28
3 files changed, 65 insertions, 23 deletions
diff --git a/sw/inc/textboxhelper.hxx b/sw/inc/textboxhelper.hxx
index 2bb791f31c0d..50024e14c086 100644
--- a/sw/inc/textboxhelper.hxx
+++ b/sw/inc/textboxhelper.hxx
@@ -11,6 +11,9 @@
#define INCLUDED_SW_INC_TEXTBOXHELPER_HXX
#include <list>
+#include <map>
+#include <set>
+#include <vector>
#include <com/sun/star/drawing/XShape.hpp>
#include <com/sun/star/uno/Any.h>
@@ -21,8 +24,11 @@
class SdrPage;
class SwFrmFmt;
+class SwFrmFmts;
+class SwFmtCntnt;
class SwDoc;
class Rectangle;
+class _ZSortFly;
/**
* A TextBox is a TextFrame, that is tied to a drawinglayer shape.
@@ -33,6 +39,10 @@ class Rectangle;
class SW_DLLPUBLIC SwTextBoxHelper
{
public:
+ /// Maps a draw format to a fly format.
+ typedef std::map<const SwFrmFmt*, const SwFrmFmt*> SavedLink;
+ /// Maps a draw format to content.
+ typedef std::map<const SwFrmFmt*, SwFmtCntnt> SavedContent;
/// Create a TextBox for a shape.
static void create(SwFrmFmt* pShape);
/// Destroy a TextBox for a shape.
@@ -57,6 +67,13 @@ public:
static sal_Int32 getCount(SdrPage* pPage, std::list<SwFrmFmt*>& rTextBoxes);
/// Get a shape by index, excluding TextBoxes.
static css::uno::Any getByIndex(SdrPage* pPage, sal_Int32 nIndex, std::list<SwFrmFmt*>& rTextBoxes) throw(css::lang::IndexOutOfBoundsException);
+
+ /// Saves the current shape -> textbox links in a map, so they can be restored later.
+ static void saveLinks(const SwFrmFmts& rFormats, std::map<const SwFrmFmt*, const SwFrmFmt*>& rLinks);
+ /// Reset the shape -> textbox link on the shape, and save it to the map, so it can be restored later.
+ static void resetLink(SwFrmFmt* pShape, std::map<const SwFrmFmt*, SwFmtCntnt>& rOldContent);
+ /// Undo the effect of saveLinks() + individual resetLink() calls.
+ static void restoreLinks(std::set<_ZSortFly>& rOld, std::vector<SwFrmFmt*>& rNew, SavedLink& rSavedLinks, SavedContent& rResetContent);
};
#endif // INCLUDED_SW_INC_TEXTBOXHELPER_HXX
diff --git a/sw/source/core/doc/textboxhelper.cxx b/sw/source/core/doc/textboxhelper.cxx
index 598d4b8da640..eac7e57799e0 100644
--- a/sw/source/core/doc/textboxhelper.cxx
+++ b/sw/source/core/doc/textboxhelper.cxx
@@ -21,6 +21,7 @@
#include <unomid.h>
#include <unoprnms.hxx>
#include <dflyobj.hxx>
+#include <mvsave.hxx>
#include <editeng/unoprnms.hxx>
#include <svx/svdoashp.hxx>
@@ -371,4 +372,46 @@ void SwTextBoxHelper::syncProperty(SwFrmFmt* pShape, sal_uInt16 nWID, sal_uInt8
}
}
+void SwTextBoxHelper::saveLinks(const SwFrmFmts& rFormats, std::map<const SwFrmFmt*, const SwFrmFmt*>& rLinks)
+{
+ for (size_t i = 0; i < rFormats.size(); ++i)
+ {
+ SwFrmFmt* pFmt = rFormats[i];
+ if (pFmt->Which() != RES_DRAWFRMFMT)
+ continue;
+ if (SwFrmFmt* pTextBox = findTextBox(pFmt))
+ rLinks[pFmt] = pTextBox;
+ }
+}
+
+void SwTextBoxHelper::resetLink(SwFrmFmt* pShape, std::map<const SwFrmFmt*, SwFmtCntnt>& rMap)
+{
+ if (pShape->Which() == RES_DRAWFRMFMT)
+ {
+ if (pShape->GetCntnt().GetCntntIdx())
+ rMap.insert(std::make_pair(pShape, pShape->GetCntnt()));
+ pShape->ResetFmtAttr(RES_CNTNT);
+ }
+}
+
+void SwTextBoxHelper::restoreLinks(std::set<_ZSortFly>& rOld, std::vector<SwFrmFmt*>& rNew, SavedLink& rSavedLinks, SavedContent& rOldContent)
+{
+ size_t i = 0;
+ for (std::set<_ZSortFly>::iterator aSetIt = rOld.begin(); aSetIt != rOld.end(); ++aSetIt, ++i)
+ {
+ SavedLink::iterator aTextBoxIt = rSavedLinks.find(aSetIt->GetFmt());
+ if (aTextBoxIt != rSavedLinks.end())
+ {
+ size_t j = 0;
+ for (std::set<_ZSortFly>::iterator aSetJt = rOld.begin(); aSetJt != rOld.end(); ++aSetJt, ++j)
+ {
+ if (aSetJt->GetFmt() == aTextBoxIt->second)
+ rNew[i]->SetFmtAttr(rNew[j]->GetCntnt());
+ }
+ }
+ if (rOldContent.find(aSetIt->GetFmt()) != rOldContent.end())
+ const_cast<SwFrmFmt*>(aSetIt->GetFmt())->SetFmtAttr(rOldContent[aSetIt->GetFmt()]);
+ }
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/docnode/ndcopy.cxx b/sw/source/core/docnode/ndcopy.cxx
index 270e2c9b986d..fd9f0137e907 100644
--- a/sw/source/core/docnode/ndcopy.cxx
+++ b/sw/source/core/docnode/ndcopy.cxx
@@ -1415,17 +1415,9 @@ void SwDoc::CopyFlyInFlyImpl(
::std::set< _ZSortFly > aSet;
sal_uInt16 nArrLen = GetSpzFrmFmts()->size();
- // Old textbox -> old shape map.
- std::map<const SwFrmFmt*, const SwFrmFmt*> aOldTextBoxes;
-
- for (size_t i = 0; i < GetSpzFrmFmts()->size(); ++i)
- {
- SwFrmFmt* pFmt = (*GetSpzFrmFmts())[i];
- if (pFmt->Which() != RES_DRAWFRMFMT)
- continue;
- if (SwFrmFmt* pTextBox = SwTextBoxHelper::findTextBox(pFmt))
- aOldTextBoxes[pTextBox] = pFmt;
- }
+ SwTextBoxHelper::SavedLink aOldTextBoxes;
+ SwTextBoxHelper::saveLinks(*GetSpzFrmFmts(), aOldTextBoxes);
+ SwTextBoxHelper::SavedContent aOldContent;
for ( sal_uInt16 n = 0; n < nArrLen; ++n )
{
@@ -1491,8 +1483,7 @@ void SwDoc::CopyFlyInFlyImpl(
{
// Make sure draw formats don't refer to content, so that such
// content can be removed without problems.
- if (pFmt->Which() == RES_DRAWFRMFMT)
- pFmt->ResetFmtAttr(RES_CNTNT);
+ SwTextBoxHelper::resetLink(pFmt, aOldContent);
aSet.insert( _ZSortFly( pFmt, pAnchor, nArrLen + aSet.size() ));
}
}
@@ -1649,16 +1640,7 @@ void SwDoc::CopyFlyInFlyImpl(
// Re-create content property of draw formats, knowing how old shapes
// were paired with old fly formats (aOldTextBoxes) and that aSet is
// parallel with aVecSwFrmFmt.
- size_t i = 0;
- for (std::set<_ZSortFly>::iterator aSetIt = aSet.begin(); aSetIt != aSet.end(); ++aSetIt, ++i)
- {
- std::map<const SwFrmFmt*, const SwFrmFmt*>::iterator aDrawIt = aOldTextBoxes.find(aSetIt->GetFmt());
- if (aDrawIt != aOldTextBoxes.end())
- {
- size_t nDrawIndex = std::distance(aOldTextBoxes.begin(), aDrawIt);
- aVecSwFrmFmt[nDrawIndex]->SetFmtAttr(aVecSwFrmFmt[i]->GetCntnt());
- }
- }
+ SwTextBoxHelper::restoreLinks(aSet, aVecSwFrmFmt, aOldTextBoxes, aOldContent);
}
}