Kaydet (Commit) 02f2d886 authored tarafından Miklos Vajna's avatar Miklos Vajna

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
üst 11c94c17
......@@ -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
......
......@@ -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: */
......@@ -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);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment