summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjoern Michaelsen <bjoern.michaelsen@libreoffice.org>2018-02-08 03:44:22 +0100
committerBjoern Michaelsen <bjoern.michaelsen@libreoffice.org>2018-02-08 03:44:38 +0100
commitc91b4422eb57e3eaab07d1a3a2f3fc29341b4fd3 (patch)
treeb691c2887d90f261d21e054c9eb5b34343f0a984
parent86ef25b38786b366413221a71b27f227670c1b65 (diff)
LinkAnchorSearch: use proper message passing
Change-Id: I33a2c2bff684b681758b1cabca5df9c600419f21
-rw-r--r--sw/inc/ddefld.hxx12
-rw-r--r--sw/inc/swbaslnk.hxx2
-rw-r--r--sw/source/core/fields/ddefld.cxx18
-rw-r--r--sw/source/core/txtnode/atrfld.cxx13
4 files changed, 31 insertions, 14 deletions
diff --git a/sw/inc/ddefld.hxx b/sw/inc/ddefld.hxx
index a583f247a966..aab4e8f3774f 100644
--- a/sw/inc/ddefld.hxx
+++ b/sw/inc/ddefld.hxx
@@ -20,11 +20,23 @@
#define INCLUDED_SW_INC_DDEFLD_HXX
#include <sfx2/lnkbase.hxx>
+#include <svl/hint.hxx>
#include "swdllapi.h"
#include "fldbas.hxx"
class SwDoc;
+namespace sw
+{
+ struct LinkAnchorSearchHint final : public SfxHint
+ {
+ SwNodes& m_rNodes;
+ const SwNode*& m_rpFoundNode;
+ LinkAnchorSearchHint(SwNodes& rNodes, const SwNode*& rpFoundNode) : m_rNodes(rNodes), m_rpFoundNode(rpFoundNode) {};
+ virtual ~LinkAnchorSearchHint() override;
+ };
+}
+
// FieldType for DDE
class SW_DLLPUBLIC SwDDEFieldType : public SwFieldType
{
diff --git a/sw/inc/swbaslnk.hxx b/sw/inc/swbaslnk.hxx
index 539f430ddee2..23752aad9fa0 100644
--- a/sw/inc/swbaslnk.hxx
+++ b/sw/inc/swbaslnk.hxx
@@ -24,6 +24,8 @@
class SwNode;
class SwContentNode;
+
+
class SwBaseLink : public ::sfx2::SvBaseLink
{
SwContentNode* m_pContentNode;
diff --git a/sw/source/core/fields/ddefld.cxx b/sw/source/core/fields/ddefld.cxx
index d9c9993dcdd5..61165b6fe1ce 100644
--- a/sw/source/core/fields/ddefld.cxx
+++ b/sw/source/core/fields/ddefld.cxx
@@ -168,27 +168,23 @@ void SwIntrnlRefLink::Closed()
SvBaseLink::Closed();
}
+sw::LinkAnchorSearchHint::~LinkAnchorSearchHint() {};
+
const SwNode* SwIntrnlRefLink::GetAnchor() const
{
// here, any anchor of the normal NodesArray should be sufficient
const SwNode* pNd = nullptr;
- SwIterator<SwClient,SwFieldType> aIter(rFieldType);
- for(SwClient* pLast = aIter.First(); pLast; pLast = aIter.Next())
+ SwIterator<SwDepend,SwFieldType> aIter(rFieldType);
+ for(SwDepend* pLast = aIter.First(); pLast; pLast = aIter.Next())
{
// a DDE table or a DDE field attribute in the text
- if( dynamic_cast<const SwFormatField *>(pLast) == nullptr)
- {
- SwDepend* pDep = static_cast<SwDepend*>(pLast);
- SwDDETable* pDDETable = static_cast<SwDDETable*>(pDep->GetToTell());
- pNd = pDDETable->GetTabSortBoxes()[0]->GetSttNd();
- }
- else if( static_cast<SwFormatField*>(pLast)->GetTextField() )
- pNd = static_cast<SwFormatField*>(pLast)->GetTextField()->GetpTextNode();
-
+ SwDDETable* pDDETable = static_cast<SwDDETable*>(pLast->GetToTell());
+ pNd = pDDETable->GetTabSortBoxes()[0]->GetSttNd();
if( pNd && &rFieldType.GetDoc()->GetNodes() == &pNd->GetNodes() )
break;
pNd = nullptr;
}
+ rFieldType.CallSwClientNotify(sw::LinkAnchorSearchHint(rFieldType.GetDoc()->GetNodes(), pNd));
return pNd;
}
diff --git a/sw/source/core/txtnode/atrfld.cxx b/sw/source/core/txtnode/atrfld.cxx
index f8d55ef5c02b..0759bc335f13 100644
--- a/sw/source/core/txtnode/atrfld.cxx
+++ b/sw/source/core/txtnode/atrfld.cxx
@@ -213,11 +213,10 @@ void SwFormatField::SwClientNotify( const SwModify& rModify, const SfxHint& rHin
if( !mpTextField )
return;
- const SwFieldHint* pHint = dynamic_cast<const SwFieldHint*>( &rHint );
- if ( pHint )
+ if (const SwFieldHint* pFieldHint = dynamic_cast<const SwFieldHint*>( &rHint ))
{
// replace field content by text
- SwPaM* pPaM = pHint->GetPaM();
+ SwPaM* pPaM = pFieldHint->GetPaM();
SwDoc* pDoc = pPaM->GetDoc();
const SwTextNode& rTextNode = mpTextField->GetTextNode();
pPaM->GetPoint()->nNode = rTextNode;
@@ -229,6 +228,14 @@ void SwFormatField::SwClientNotify( const SwModify& rModify, const SfxHint& rHin
pDoc->getIDocumentContentOperations().DeleteRange( *pPaM );
pDoc->getIDocumentContentOperations().InsertString( *pPaM, aEntry );
}
+ else if(const sw::LinkAnchorSearchHint* pAnchorHint = dynamic_cast<const sw::LinkAnchorSearchHint*>(&rHint))
+ {
+ if(pAnchorHint->m_rpFoundNode || !GetTextField())
+ return;
+ const auto pNode = GetTextField()->GetpTextNode();
+ if(pNode && &pNode->GetNodes() == &pAnchorHint->m_rNodes)
+ pAnchorHint->m_rpFoundNode = pNode;
+ }
}
void SwFormatField::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew )