summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2016-07-22 17:59:28 +0200
committerJan-Marek Glogowski <glogow@fbihome.de>2016-08-29 13:13:15 +0200
commitf7f5d27066b696ac4e33246d3794bde8058e8622 (patch)
treefe1533b830a8204bdb1ca2770ab9d446ab15cc4a
parent0bcc5b3daebeb2a7d2b5ba132af4745cc6c78cd0 (diff)
Add convenience function getOtherTextBoxFormat
Since we already have isTextBox to identify a text box, this just adds a call to SwFrameFormat::GetOtherTextBoxFormat() to actually return the corresponding SwFrameFormat. This gets rid off all the remaining occurences of the SwFrameFormat / Textbox sets and maps. Change-Id: Id5f05a1ff71e604658e7d8a0d0825f5671335b3f
-rw-r--r--sw/inc/textboxhelper.hxx10
-rw-r--r--sw/source/core/doc/DocumentLayoutManager.cxx2
-rw-r--r--sw/source/core/doc/textboxhelper.cxx64
-rw-r--r--sw/source/core/draw/dview.cxx2
-rw-r--r--sw/source/core/frmedt/feshview.cxx8
-rw-r--r--sw/source/core/layout/fly.cxx5
-rw-r--r--sw/source/core/text/porfly.cxx2
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.cxx4
-rw-r--r--sw/source/filter/ww8/rtfsdrexport.cxx5
-rw-r--r--sw/source/filter/ww8/rtfsdrexport.hxx3
-rw-r--r--sw/source/uibase/docvw/edtwin.cxx11
11 files changed, 58 insertions, 58 deletions
diff --git a/sw/inc/textboxhelper.hxx b/sw/inc/textboxhelper.hxx
index eb94bbc1d194..98983bad9f42 100644
--- a/sw/inc/textboxhelper.hxx
+++ b/sw/inc/textboxhelper.hxx
@@ -62,7 +62,17 @@ public:
/// Similar to syncProperty(), but used by the internal API (e.g. for UI purposes).
static void syncFlyFrameAttr(SwFrameFormat& rShape, SfxItemSet& rSet);
+ /**
+ * If we have an associated TextFrame, then return that.
+ *
+ * @param nType Expected frame format type.
+ * Valid types are RES_DRAWFRMFMT and RES_FLYFRMFMT.
+ *
+ * @see isTextBox
+ */
+ static SwFrameFormat* getOtherTextBoxFormat(const SwFrameFormat* pFormat, sal_uInt16 nType);
/// If we have an associated TextFrame, then return that.
+ static SwFrameFormat* getOtherTextBoxFormat(css::uno::Reference<css::drawing::XShape> xShape);
static SwFrameFormat* findTextBox(const SwFrameFormat* pShape);
static SwFrameFormat* findTextBox(const css::uno::Reference<css::drawing::XShape>& xShape);
/// Return the textbox rectangle of a draw shape (in twips).
diff --git a/sw/source/core/doc/DocumentLayoutManager.cxx b/sw/source/core/doc/DocumentLayoutManager.cxx
index 5fc0d4cc7483..254a4ee14ba7 100644
--- a/sw/source/core/doc/DocumentLayoutManager.cxx
+++ b/sw/source/core/doc/DocumentLayoutManager.cxx
@@ -494,7 +494,7 @@ SwFrameFormat *DocumentLayoutManager::CopyLayoutFormat(
pDest->MakeFrames();
// If the draw format has a TextBox, then copy its fly format as well.
- if (SwFrameFormat* pSourceTextBox = SwTextBoxHelper::findTextBox(&rSource))
+ if (SwFrameFormat* pSourceTextBox = SwTextBoxHelper::getOtherTextBoxFormat(&rSource, RES_DRAWFRMFMT))
{
SwFormatAnchor boxAnchor(rNewAnchor);
if (FLY_AS_CHAR == boxAnchor.GetAnchorId())
diff --git a/sw/source/core/doc/textboxhelper.cxx b/sw/source/core/doc/textboxhelper.cxx
index b1803661da25..5049f10e1954 100644
--- a/sw/source/core/doc/textboxhelper.cxx
+++ b/sw/source/core/doc/textboxhelper.cxx
@@ -115,7 +115,7 @@ void SwTextBoxHelper::destroy(SwFrameFormat* pShape)
// If a TextBox was enabled previously
if (pShape->GetAttrSet().HasItem(RES_CNTNT))
{
- SwFrameFormat* pFormat = findTextBox(pShape);
+ SwFrameFormat* pFormat = pShape->GetOtherTextBoxFormat();
// Unlink the TextBox's text range from the original shape.
pShape->ResetFormatAttr(RES_CNTNT);
@@ -129,7 +129,6 @@ void SwTextBoxHelper::destroy(SwFrameFormat* pShape)
std::set<const SwFrameFormat*> SwTextBoxHelper::findTextBoxes(const SwDoc* pDoc)
{
std::set<const SwFrameFormat*> aTextBoxes;
- std::map<SwNodeIndex, const SwFrameFormat*> aFlyFormats, aDrawFormats;
const SwFrameFormats& rSpzFrameFormats = *pDoc->GetSpzFrameFormats();
for (const SwFrameFormat* pFormat : rSpzFrameFormats)
@@ -139,22 +138,8 @@ std::set<const SwFrameFormat*> SwTextBoxHelper::findTextBoxes(const SwDoc* pDoc)
if (!pFormat->GetAttrSet().HasItem(RES_CNTNT) || !pFormat->GetContent().GetContentIdx())
continue;
- const SwNodeIndex& rIndex = *pFormat->GetContent().GetContentIdx();
-
- if (pFormat->Which() == RES_FLYFRMFMT)
- {
- if (aDrawFormats.find(rIndex) != aDrawFormats.end())
- aTextBoxes.insert(pFormat);
- else
- aFlyFormats[rIndex] = pFormat;
- }
- else if (pFormat->Which() == RES_DRAWFRMFMT)
- {
- if (aFlyFormats.find(rIndex) != aFlyFormats.end())
- aTextBoxes.insert(aFlyFormats[rIndex]);
- else
- aDrawFormats[rIndex] = pFormat;
- }
+ if (pFormat->Which() == RES_FLYFRMFMT && nullptr != pFormat->GetOtherTextBoxFormat())
+ aTextBoxes.insert(pFormat);
}
return aTextBoxes;
@@ -197,7 +182,7 @@ std::set<const SwFrameFormat*> SwTextBoxHelper::findTextBoxes(const SwNode& rNod
{
for (SwAnchoredObject* pAnchoredObject : *pSortedObjs)
{
- SwFrameFormat* pTextBox = findTextBox(&pAnchoredObject->GetFrameFormat());
+ SwFrameFormat* pTextBox = getOtherTextBoxFormat(&pAnchoredObject->GetFrameFormat(), RES_DRAWFRMFMT);
if (pTextBox)
aRet.insert(pTextBox);
}
@@ -217,7 +202,7 @@ std::map<SwFrameFormat*, SwFrameFormat*> SwTextBoxHelper::findShapes(const SwDoc
const SwFrameFormats& rSpzFrameFormats = *pDoc->GetSpzFrameFormats();
for (SwFrameFormat* pFormat : rSpzFrameFormats)
{
- SwFrameFormat* pTextBox = findTextBox(pFormat);
+ SwFrameFormat* pTextBox = getOtherTextBoxFormat(pFormat, RES_DRAWFRMFMT);
if (pTextBox)
aRet[pTextBox] = pFormat;
}
@@ -303,11 +288,26 @@ sal_Int32 SwTextBoxHelper::getOrdNum(const SdrObject* pObject)
void SwTextBoxHelper::getShapeWrapThrough(const SwFrameFormat* pTextBox, bool& rWrapThrough)
{
- std::map<SwFrameFormat*, SwFrameFormat*> aMap = findShapes(pTextBox->GetDoc());
- auto it = aMap.find(const_cast<SwFrameFormat*>(pTextBox));
- if (it != aMap.end())
- // pTextBox is indeed a TextBox, it->second is its shape.
- rWrapThrough = it->second->GetSurround().GetSurround() == SURROUND_THROUGHT;
+ SwFrameFormat *pShape = SwTextBoxHelper::getOtherTextBoxFormat(pTextBox, RES_FLYFRMFMT);
+ if (pShape)
+ rWrapThrough = pShape->GetSurround().GetSurround() == SURROUND_THROUGHT;
+}
+
+SwFrameFormat* SwTextBoxHelper::getOtherTextBoxFormat(const SwFrameFormat* pFormat, sal_uInt16 nType)
+{
+ if (!isTextBox(pFormat, nType))
+ return nullptr;
+ return pFormat->GetOtherTextBoxFormat();
+}
+
+SwFrameFormat* SwTextBoxHelper::getOtherTextBoxFormat(uno::Reference<drawing::XShape> xShape)
+{
+ SwXShape* pShape = dynamic_cast<SwXShape*>(xShape.get());
+ if (!pShape)
+ return nullptr;
+
+ SwFrameFormat *pFormat = pShape->GetFrameFormat();
+ return getOtherTextBoxFormat(pFormat, RES_DRAWFRMFMT);
}
SwFrameFormat* SwTextBoxHelper::findTextBox(const uno::Reference<drawing::XShape>& xShape)
@@ -345,7 +345,7 @@ SwFrameFormat* SwTextBoxHelper::findTextBox(const SwFrameFormat* pShape)
template < typename T >
void lcl_queryInterface(SwFrameFormat* pShape, uno::Any& rAny)
{
- if (SwFrameFormat* pFormat = SwTextBoxHelper::findTextBox(pShape))
+ if (SwFrameFormat* pFormat = SwTextBoxHelper::getOtherTextBoxFormat(pShape, RES_DRAWFRMFMT))
{
uno::Reference<T> const xInterface(
SwXTextFrame::CreateXTextFrame(*pFormat->GetDoc(), pFormat),
@@ -423,7 +423,7 @@ void SwTextBoxHelper::syncProperty(SwFrameFormat* pShape, const OUString& rPrope
syncProperty(pShape, RES_VERT_ORIENT, MID_VERTORIENT_POSITION, uno::makeAny(static_cast<sal_Int32>(convertTwipToMm100(aRectangle.Top()))));
}
- if (SwFrameFormat* pFormat = findTextBox(pShape))
+ if (SwFrameFormat* pFormat = getOtherTextBoxFormat(pShape, RES_DRAWFRMFMT))
{
comphelper::SequenceAsHashMap aCustomShapeGeometry(rValue);
// That would be the btLr text direction which we don't support at a frame level, so do it at a character level.
@@ -457,7 +457,7 @@ void SwTextBoxHelper::getProperty(SwFrameFormat* pShape, sal_uInt16 nWID, sal_uI
nMemberId &= ~CONVERT_TWIPS;
- if (SwFrameFormat* pFormat = findTextBox(pShape))
+ if (SwFrameFormat* pFormat = getOtherTextBoxFormat(pShape, RES_DRAWFRMFMT))
{
if (nWID == RES_CHAIN)
{
@@ -487,7 +487,7 @@ void SwTextBoxHelper::syncProperty(SwFrameFormat* pShape, sal_uInt16 nWID, sal_u
uno::Any aValue(rValue);
nMemberId &= ~CONVERT_TWIPS;
- if (SwFrameFormat* pFormat = findTextBox(pShape))
+ if (SwFrameFormat* pFormat = getOtherTextBoxFormat(pShape, RES_DRAWFRMFMT))
{
OUString aPropertyName;
bool bAdjustX = false;
@@ -628,9 +628,7 @@ void SwTextBoxHelper::saveLinks(const SwFrameFormats& rFormats, std::map<const S
for (std::size_t i = 0; i < rFormats.size(); ++i)
{
const SwFrameFormat* pFormat = rFormats[i];
- if (pFormat->Which() != RES_DRAWFRMFMT)
- continue;
- if (SwFrameFormat* pTextBox = findTextBox(pFormat))
+ if (SwFrameFormat* pTextBox = getOtherTextBoxFormat(pFormat, RES_DRAWFRMFMT))
rLinks[pFormat] = pTextBox;
}
}
@@ -667,7 +665,7 @@ void SwTextBoxHelper::restoreLinks(std::set<ZSortFly>& rOld, std::vector<SwFrame
void SwTextBoxHelper::syncFlyFrameAttr(SwFrameFormat& rShape, SfxItemSet& rSet)
{
- if (SwFrameFormat* pFormat = findTextBox(&rShape))
+ if (SwFrameFormat* pFormat = getOtherTextBoxFormat(&rShape, RES_DRAWFRMFMT))
{
SfxItemSet aTextBoxSet(pFormat->GetDoc()->GetAttrPool(), aFrameFormatSetRange);
diff --git a/sw/source/core/draw/dview.cxx b/sw/source/core/draw/dview.cxx
index 13c5f0c20e36..763652fbee27 100644
--- a/sw/source/core/draw/dview.cxx
+++ b/sw/source/core/draw/dview.cxx
@@ -948,7 +948,7 @@ void SwDrawView::DeleteMarked()
SdrObject *pObject = rMarkList.GetMark(i)->GetMarkedSdrObj();
SwDrawContact* pDrawContact = static_cast<SwDrawContact*>(GetUserCall(pObject));
SwFrameFormat* pFormat = pDrawContact->GetFormat();
- if (SwFrameFormat* pTextBox = SwTextBoxHelper::findTextBox(pFormat))
+ if (SwFrameFormat* pTextBox = SwTextBoxHelper::getOtherTextBoxFormat(pFormat, RES_DRAWFRMFMT))
aTextBoxesToDelete.push_back(pTextBox);
}
diff --git a/sw/source/core/frmedt/feshview.cxx b/sw/source/core/frmedt/feshview.cxx
index 7d4b170b7637..66302da6e940 100644
--- a/sw/source/core/frmedt/feshview.cxx
+++ b/sw/source/core/frmedt/feshview.cxx
@@ -235,15 +235,13 @@ bool SwFEShell::SelectObj( const Point& rPt, sal_uInt8 nFlag, SdrObject *pObj )
if (!(nFlag & SW_ALLOW_TEXTBOX))
{
// If the fly frame is a textbox of a shape, then select the shape instead.
- std::map<SwFrameFormat*, SwFrameFormat*> aTextBoxShapes = SwTextBoxHelper::findShapes(mpDoc);
for (size_t i = 0; i < rMrkList.GetMarkCount(); ++i)
{
SdrObject* pObject = rMrkList.GetMark(i)->GetMarkedSdrObj();
- SwContact* pDrawContact = GetUserCall(pObject);
- SwFrameFormat* pFormat = pDrawContact->GetFormat();
- if (aTextBoxShapes.find(pFormat) != aTextBoxShapes.end())
+ SwFrameFormat* pFormat = GetUserCall(pObject)->GetFormat();
+ if (SwFrameFormat* pShapeFormat = SwTextBoxHelper::getOtherTextBoxFormat(pFormat, RES_FLYFRMFMT))
{
- SdrObject* pShape = aTextBoxShapes[pFormat]->FindSdrObject();
+ SdrObject* pShape = pShapeFormat->FindSdrObject();
pDView->UnmarkAll();
pDView->MarkObj(pShape, Imp()->GetPageView(), bAddSelect, bEnterGroup);
break;
diff --git a/sw/source/core/layout/fly.cxx b/sw/source/core/layout/fly.cxx
index 0eff50c862eb..310bf43472dd 100644
--- a/sw/source/core/layout/fly.cxx
+++ b/sw/source/core/layout/fly.cxx
@@ -1288,11 +1288,10 @@ void SwFlyFrame::Format( vcl::RenderContext* /*pRenderContext*/, const SwBorderA
}
mbValidSize = true;
- std::map<SwFrameFormat*, SwFrameFormat*> aShapes = SwTextBoxHelper::findShapes(GetFormat()->GetDoc());
- if (aShapes.find(GetFormat()) != aShapes.end())
+ if (SwFrameFormat* pShapeFormat = SwTextBoxHelper::getOtherTextBoxFormat(GetFormat(), RES_FLYFRMFMT))
{
// This fly is a textbox of a draw shape.
- SdrObject* pShape = aShapes[GetFormat()]->FindSdrObject();
+ SdrObject* pShape = pShapeFormat->FindSdrObject();
if (SdrObjCustomShape* pCustomShape = dynamic_cast<SdrObjCustomShape*>( pShape) )
{
// The shape is a customshape: then inform it about the calculated fly size.
diff --git a/sw/source/core/text/porfly.cxx b/sw/source/core/text/porfly.cxx
index e38e99ddbd87..5903566d0bfc 100644
--- a/sw/source/core/text/porfly.cxx
+++ b/sw/source/core/text/porfly.cxx
@@ -359,7 +359,7 @@ void SwFlyCntPortion::SetBase( const SwTextFrame& rFrame, const Point &rBase,
if (rAnchor.GetAnchorId() == FLY_AS_CHAR)
{
// This is an inline draw shape, see if it has a textbox.
- SwFrameFormat* pTextBox = SwTextBoxHelper::findTextBox(pShape);
+ SwFrameFormat* pTextBox = SwTextBoxHelper::getOtherTextBoxFormat(pShape, RES_DRAWFRMFMT);
if (pTextBox)
{
// It has, so look up its text rectangle, and adjust the position
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index d12977e3f16e..ee0ad84e2a57 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -5142,7 +5142,7 @@ void DocxAttributeOutput::WriteTextBox(uno::Reference<drawing::XShape> xShape)
DocxTableExportContext aTableExportContext;
pushToTableExportContext(aTableExportContext);
- SwFrameFormat* pTextBox = SwTextBoxHelper::findTextBox(xShape);
+ SwFrameFormat* pTextBox = SwTextBoxHelper::getOtherTextBoxFormat(xShape);
const SwPosition* pAnchor = pTextBox->GetAnchor().GetContentAnchor();
ww8::Frame aFrame(*pTextBox, *pAnchor);
m_rExport.SdrExporter().writeDMLTextFrame(&aFrame, m_anchorId++, /*bTextBoxOnly=*/true);
@@ -5155,7 +5155,7 @@ void DocxAttributeOutput::WriteVMLTextBox(uno::Reference<drawing::XShape> xShape
DocxTableExportContext aTableExportContext;
pushToTableExportContext(aTableExportContext);
- SwFrameFormat* pTextBox = SwTextBoxHelper::findTextBox(xShape);
+ SwFrameFormat* pTextBox = SwTextBoxHelper::getOtherTextBoxFormat(xShape);
const SwPosition* pAnchor = pTextBox->GetAnchor().GetContentAnchor();
ww8::Frame aFrame(*pTextBox, *pAnchor);
m_rExport.SdrExporter().writeVMLTextFrame(&aFrame, /*bTextBoxOnly=*/true);
diff --git a/sw/source/filter/ww8/rtfsdrexport.cxx b/sw/source/filter/ww8/rtfsdrexport.cxx
index d7a050666ade..ccaf68876dfa 100644
--- a/sw/source/filter/ww8/rtfsdrexport.cxx
+++ b/sw/source/filter/ww8/rtfsdrexport.cxx
@@ -39,8 +39,7 @@ RtfSdrExport::RtfSdrExport(RtfExport& rExport)
m_nShapeType(ESCHER_ShpInst_Nil),
m_nShapeFlags(0) ,
m_aShapeStyle(200),
- m_pShapeTypeWritten(new bool[ ESCHER_ShpInst_COUNT ]),
- m_aTextBoxes(SwTextBoxHelper::findTextBoxes(m_rExport.m_pDoc))
+ m_pShapeTypeWritten(new bool[ ESCHER_ShpInst_COUNT ])
{
mnGroupLevel = 1;
memset(m_pShapeTypeWritten, 0, ESCHER_ShpInst_COUNT * sizeof(bool));
@@ -514,7 +513,7 @@ sal_Int32 RtfSdrExport::StartShape()
const SwFrameFormat* pShape = FindFrameFormat(m_pSdrObject);
if (pShape)
{
- if (SwFrameFormat* pTextBox = SwTextBoxHelper::findTextBox(pShape))
+ if (SwFrameFormat* pTextBox = SwTextBoxHelper::getOtherTextBoxFormat(pShape, RES_DRAWFRMFMT))
{
ww8::Frame* pFrame = nullptr;
for (auto& rFrame : m_rExport.m_aFrames)
diff --git a/sw/source/filter/ww8/rtfsdrexport.hxx b/sw/source/filter/ww8/rtfsdrexport.hxx
index a5b32733908c..f62d09346b6c 100644
--- a/sw/source/filter/ww8/rtfsdrexport.hxx
+++ b/sw/source/filter/ww8/rtfsdrexport.hxx
@@ -56,9 +56,6 @@ class RtfSdrExport : public EscherEx
/// Remember which shape types we had already written.
bool* m_pShapeTypeWritten;
- /// List of TextBoxes in this document: they are exported as part of their shape, never alone.
- std::set<const SwFrameFormat*> m_aTextBoxes;
-
public:
explicit RtfSdrExport(RtfExport& rExport);
virtual ~RtfSdrExport();
diff --git a/sw/source/uibase/docvw/edtwin.cxx b/sw/source/uibase/docvw/edtwin.cxx
index 37e41b1aaa2d..4990f5c2e346 100644
--- a/sw/source/uibase/docvw/edtwin.cxx
+++ b/sw/source/uibase/docvw/edtwin.cxx
@@ -204,7 +204,7 @@ static bool lcl_goIntoTextBox(SwEditWin& rEditWin, SwWrtShell& rSh)
{
SdrObject* pSdrObject = rSh.GetDrawView()->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj();
SwFrameFormat* pObjectFormat = ::FindFrameFormat(pSdrObject);
- if (SwFrameFormat* pTextBoxFormat = SwTextBoxHelper::findTextBox(pObjectFormat))
+ if (SwFrameFormat* pTextBoxFormat = SwTextBoxHelper::getOtherTextBoxFormat(pObjectFormat, RES_DRAWFRMFMT))
{
SdrObject* pTextBox = pTextBoxFormat->FindRealSdrObject();
SdrView* pSdrView = rSh.GetDrawView();
@@ -4391,10 +4391,9 @@ void SwEditWin::MouseButtonUp(const MouseEvent& rMEvt)
SdrPageView* pPV;
if (pSdrView && pSdrView->PickObj(aDocPos, pSdrView->getHitTolLog(), pObj, pPV, SdrSearchOptions::ALSOONMASTER ))
{
- std::map<SwFrameFormat*, SwFrameFormat*> aTextBoxShapes = SwTextBoxHelper::findShapes(rSh.GetDoc());
- auto pDrawContact = GetUserCall(pObj);
- SwFrameFormat* pFormat = pDrawContact->GetFormat();
- if (aTextBoxShapes.find(pFormat) == aTextBoxShapes.end())
+ SwFrameFormat* pFormat = GetUserCall(pObj)->GetFormat();
+ SwFrameFormat* pShapeFormat = SwTextBoxHelper::getOtherTextBoxFormat(pFormat, RES_FLYFRMFMT);
+ if (!pShapeFormat)
{
pSdrView->UnmarkAllObj();
pSdrView->MarkObj(pObj,pPV);
@@ -4402,7 +4401,7 @@ void SwEditWin::MouseButtonUp(const MouseEvent& rMEvt)
else
{
// If the fly frame is a textbox of a shape, then select the shape instead.
- SdrObject* pShape = aTextBoxShapes[pFormat]->FindSdrObject();
+ SdrObject* pShape = pShapeFormat->FindSdrObject();
pSdrView->UnmarkAllObj();
pSdrView->MarkObj(pShape, pPV);
}