Kaydet (Commit) 0ab6b1fc authored tarafından Michael Stahl's avatar Michael Stahl

sw: shove 2 global variables into SwHyphIter

Change-Id: I0cb6112b0353a5fd0b4dd571d65f2d656e39ba74
üst 655248f1
...@@ -22,12 +22,15 @@ ...@@ -22,12 +22,15 @@
#include <i18nlangtag/lang.h> #include <i18nlangtag/lang.h>
#include <tools/solar.h> #include <tools/solar.h>
#include <tools/gen.hxx> #include <tools/gen.hxx>
#include <limits.h>
#include <com/sun/star/linguistic2/XSpellAlternatives.hpp> #include <com/sun/star/linguistic2/XSpellAlternatives.hpp>
#include <com/sun/star/linguistic2/XSpellChecker1.hpp> #include <com/sun/star/linguistic2/XSpellChecker1.hpp>
#include <com/sun/star/linguistic2/XHyphenatedWord.hpp> #include <com/sun/star/linguistic2/XHyphenatedWord.hpp>
#include <functional>
#include <limits.h>
class SwTextFrm;
class SwTextNode; class SwTextNode;
class SwIndex; class SwIndex;
namespace vcl { class Font; } namespace vcl { class Font; }
...@@ -152,6 +155,14 @@ public: ...@@ -152,6 +155,14 @@ public:
} }
}; };
namespace sw {
SwTextFrm *
SwHyphIterCacheLastTxtFrm(SwTextNode *, std::function<SwTextFrm * ()>);
}
#endif #endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -155,11 +155,16 @@ public: ...@@ -155,11 +155,16 @@ public:
class SwHyphIter : public SwLinguIter class SwHyphIter : public SwLinguIter
{ {
// With that we save a GetFrm() in Hyphenate //TODO: does it actually matter?
const SwTextNode *m_pLastNode;
SwTextFrm *m_pLastFrm;
friend SwTextFrm * sw::SwHyphIterCacheLastTxtFrm(SwTextNode *, std::function<SwTextFrm * ()>);
bool bOldIdle; bool bOldIdle;
static void DelSoftHyph( SwPaM &rPam ); static void DelSoftHyph( SwPaM &rPam );
public: public:
SwHyphIter() : bOldIdle(false) {} SwHyphIter() : m_pLastNode(nullptr), m_pLastFrm(nullptr), bOldIdle(false) {}
void Start( SwEditShell *pSh, SwDocPositions eStart, SwDocPositions eEnd ); void Start( SwEditShell *pSh, SwDocPositions eStart, SwDocPositions eEnd );
void End(); void End();
...@@ -177,11 +182,6 @@ static SwSpellIter* g_pSpellIter = nullptr; ...@@ -177,11 +182,6 @@ static SwSpellIter* g_pSpellIter = nullptr;
static SwConvIter* g_pConvIter = nullptr; static SwConvIter* g_pConvIter = nullptr;
static SwHyphIter* g_pHyphIter = nullptr; static SwHyphIter* g_pHyphIter = nullptr;
// With that we save a GetFrm() in Hyphenate.
// Caution: There are external declaration to these pointers in txtedt.cxx!
const SwTextNode *pLinguNode;
SwTextFrm *pLinguFrm;
SwLinguIter::SwLinguIter() SwLinguIter::SwLinguIter()
: pSh(nullptr) : pSh(nullptr)
, pStart(nullptr) , pStart(nullptr)
...@@ -249,9 +249,6 @@ void SwLinguIter::_Start( SwEditShell *pShell, SwDocPositions eStart, ...@@ -249,9 +249,6 @@ void SwLinguIter::_Start( SwEditShell *pShell, SwDocPositions eStart,
} }
pCrsr->SetMark(); pCrsr->SetMark();
pLinguFrm = nullptr;
pLinguNode = nullptr;
} }
void SwLinguIter::_End(bool bRestoreSelection) void SwLinguIter::_End(bool bRestoreSelection)
...@@ -572,6 +569,23 @@ void SwHyphIter::InsertSoftHyph( const sal_Int32 nHyphPos ) ...@@ -572,6 +569,23 @@ void SwHyphIter::InsertSoftHyph( const sal_Int32 nHyphPos )
pCrsr->SetMark(); pCrsr->SetMark();
} }
namespace sw {
SwTextFrm *
SwHyphIterCacheLastTxtFrm(SwTextNode *const pNode,
std::function<SwTextFrm * ()> const create)
{
assert(g_pHyphIter);
if (pNode != g_pHyphIter->m_pLastNode || !g_pHyphIter->m_pLastFrm)
{
g_pHyphIter->m_pLastNode = pNode;
g_pHyphIter->m_pLastFrm = create();
}
return g_pHyphIter->m_pLastFrm;
}
}
bool SwEditShell::HasLastSentenceGotGrammarChecked() bool SwEditShell::HasLastSentenceGotGrammarChecked()
{ {
bool bTextWasGrammarChecked = false; bool bTextWasGrammarChecked = false;
......
...@@ -1618,12 +1618,12 @@ bool SwTextNode::Hyphenate( SwInterHyphInfo &rHyphInf ) ...@@ -1618,12 +1618,12 @@ bool SwTextNode::Hyphenate( SwInterHyphInfo &rHyphInf )
return false; return false;
} }
if( pLinguNode != this ) SwTextFrm *pFrm = ::sw::SwHyphIterCacheLastTxtFrm(this,
{ [&rHyphInf, this]() {
pLinguNode = this; return static_cast<SwTextFrm*>(this->getLayoutFrm(
pLinguFrm = static_cast<SwTextFrm*>(getLayoutFrm( GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout(), rHyphInf.GetCrsrPos() )); this->GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout(),
} rHyphInf.GetCrsrPos()));
SwTextFrm *pFrm = pLinguFrm; });
if( pFrm ) if( pFrm )
pFrm = &(pFrm->GetFrmAtOfst( rHyphInf.nStart )); pFrm = &(pFrm->GetFrmAtOfst( rHyphInf.nStart ));
else else
......
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