summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2012-07-20 16:11:08 +0100
committerCaolán McNamara <caolanm@redhat.com>2012-07-26 16:38:05 +0100
commit331e4d03a70900bc390b376f4073d0efd868b919 (patch)
treef4bd121485872447062e30001758670d9700aa85
parente5e85f2987a27db7efb2b24039b5c1ddf3f5d90e (diff)
refactor ModelToViewHelper, should have unchanged results
Change-Id: Ib57f0d6f9491d12ffacada5ec0ae8bc68874c25b
-rw-r--r--sw/inc/modeltoviewhelper.hxx33
-rw-r--r--sw/inc/ndtxt.hxx3
-rw-r--r--sw/inc/swscanner.hxx4
-rw-r--r--sw/inc/unoflatpara.hxx2
-rw-r--r--sw/inc/unotextmarkup.hxx7
-rw-r--r--sw/qa/core/swdoc-test.cxx2
-rw-r--r--sw/source/core/doc/docedt.cxx22
-rw-r--r--sw/source/core/edit/edlingu.cxx19
-rw-r--r--sw/source/core/text/porlay.cxx2
-rw-r--r--sw/source/core/txtnode/modeltoviewhelper.cxx21
-rw-r--r--sw/source/core/txtnode/ndtxt.cxx28
-rw-r--r--sw/source/core/txtnode/txtedt.cxx41
-rw-r--r--sw/source/core/unocore/unoflatpara.cxx25
-rw-r--r--sw/source/core/unocore/unotextmarkup.cxx29
14 files changed, 104 insertions, 134 deletions
diff --git a/sw/inc/modeltoviewhelper.hxx b/sw/inc/modeltoviewhelper.hxx
index a1ee88e3965a..c7a80c5b4278 100644
--- a/sw/inc/modeltoviewhelper.hxx
+++ b/sw/inc/modeltoviewhelper.hxx
@@ -20,10 +20,12 @@
#ifndef _MODELTOVIEWHELPER_HXX
#define _MODELTOVIEWHELPER_HXX
+#include <rtl/ustring.hxx>
#include <sal/types.h>
-
#include <vector>
+class SwTxtNode;
+
/** Some helpers for converting model strings to view strings.
A paragraph string does not have its fields expanded, i.e., they are
@@ -33,7 +35,7 @@
helper functions are provided to convert model positions to view positions
and vice versa.
*/
-namespace ModelToViewHelper
+class ModelToViewHelper
{
/** For each field in the model string, there is an entry in the conversion
map. The first value of the ConversionMapEntry points to the field
@@ -44,6 +46,12 @@ namespace ModelToViewHelper
typedef std::pair< sal_uInt32 , sal_uInt32 > ConversionMapEntry;
typedef std::vector< ConversionMapEntry > ConversionMap;
+ ConversionMap m_aMap;
+
+ rtl::OUString m_aRetText;
+
+public:
+
/** This struct defines a position in the model string.
The 'main' position is given by mnPos. If there's a field located at
@@ -59,12 +67,10 @@ namespace ModelToViewHelper
ModelPosition() : mnPos(0), mnSubPos(0), mbIsField(false) {}
};
- /** Converts a model position into a view position
+ ModelToViewHelper(const SwTxtNode &rNode);
+ ModelToViewHelper() {} //pass through filter, view == model
- @param pMap
- pMap is the conversion map required for the calculation. If pMap is
- 0, no conversion takes place, i.e., it is assumed that the model
- string is identical to the view string.
+ /** Converts a model position into a view position
@param nPos
nPos denotes a position in the model string which should be
@@ -77,15 +83,10 @@ namespace ModelToViewHelper
nPos is behind the last entry in the conversion map) nPos will
be returned.
*/
- sal_uInt32 ConvertToViewPosition( const ConversionMap* pMap, sal_uInt32 nModelPos );
+ sal_uInt32 ConvertToViewPosition( sal_uInt32 nModelPos ) const;
/** Converts a view position into a model position
- @param pMap
- pMap is the conversion map required for the calculation. If pMap is
- 0, no conversion takes place, i.e., it is assumed that the model
- string is identical to the view string.
-
@param nPos
nPos denotes a position in the view string which should be
converted.
@@ -97,8 +98,10 @@ namespace ModelToViewHelper
model position with mnPos = nPos and mnIsField = false will be
returned.
*/
- ModelPosition ConvertToModelPosition( const ConversionMap* pMap, sal_uInt32 nViewPos );
-}
+ ModelPosition ConvertToModelPosition( sal_uInt32 nViewPos ) const;
+
+ rtl::OUString getViewText() const { return m_aRetText; }
+};
#endif
diff --git a/sw/inc/ndtxt.hxx b/sw/inc/ndtxt.hxx
index 83b3e2f35a4a..39565cf4a6fd 100644
--- a/sw/inc/ndtxt.hxx
+++ b/sw/inc/ndtxt.hxx
@@ -699,9 +699,6 @@ public:
sal_Bool bWithNum = sal_False, sal_Bool bWithFtn = sal_True,
sal_Bool bReplaceTabsWithSpaces = sal_False ) const;
- const ModelToViewHelper::ConversionMap*
- BuildConversionMap( rtl::OUString& rExpandText ) const;
-
XubString GetRedlineTxt( xub_StrLen nIdx = 0,
xub_StrLen nLen = STRING_LEN,
sal_Bool bExpandFlds = sal_False,
diff --git a/sw/inc/swscanner.hxx b/sw/inc/swscanner.hxx
index 3c059950ddb4..f657f238c2ca 100644
--- a/sw/inc/swscanner.hxx
+++ b/sw/inc/swscanner.hxx
@@ -45,7 +45,7 @@ class SwScanner
const SwTxtNode& rNode;
const rtl::OUString aText;
const LanguageType* pLanguage;
- const ModelToViewHelper::ConversionMap* pConversionMap;
+ const ModelToViewHelper& rConversionMap;
sal_Int32 nStartPos;
sal_Int32 nEndPos;
sal_Int32 nBegin;
@@ -57,7 +57,7 @@ class SwScanner
public:
SwScanner( const SwTxtNode& rNd, const rtl::OUString& rTxt,
const LanguageType* pLang,
- const ModelToViewHelper::ConversionMap* pConvMap,
+ const ModelToViewHelper& rConvMap,
sal_uInt16 nWordType,
sal_Int32 nStart, sal_Int32 nEnde, sal_Bool bClip = sal_False );
diff --git a/sw/inc/unoflatpara.hxx b/sw/inc/unoflatpara.hxx
index b728dcdd32e3..310ff80cd7af 100644
--- a/sw/inc/unoflatpara.hxx
+++ b/sw/inc/unoflatpara.hxx
@@ -52,7 +52,7 @@ class SwXFlatParagraph:
public SwXTextMarkup
{
public:
- SwXFlatParagraph( SwTxtNode& rTxtNode, rtl::OUString aExpandText, const ModelToViewHelper::ConversionMap* pConversionMap );
+ SwXFlatParagraph( SwTxtNode& rTxtNode, rtl::OUString aExpandText, const ModelToViewHelper& rConversionMap );
virtual ~SwXFlatParagraph();
virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType ) throw(::com::sun::star::uno::RuntimeException);
diff --git a/sw/inc/unotextmarkup.hxx b/sw/inc/unotextmarkup.hxx
index d918b8d6cb13..de7aa158399c 100644
--- a/sw/inc/unotextmarkup.hxx
+++ b/sw/inc/unotextmarkup.hxx
@@ -47,7 +47,7 @@ class SwXTextMarkup:
public SwClient
{
public:
- SwXTextMarkup( SwTxtNode& rTxtNode, const ModelToViewHelper::ConversionMap* pConversionMap );
+ SwXTextMarkup( SwTxtNode& rTxtNode, const ModelToViewHelper& rConversionMap );
virtual ~SwXTextMarkup();
// ::com::sun::star::text::XTextMarkup:
@@ -63,11 +63,10 @@ private:
protected:
//SwClient
- virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew);
+ virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew);
SwTxtNode* mpTxtNode;
- const ModelToViewHelper::ConversionMap* mpConversionMap;
-
+ const ModelToViewHelper maConversionMap;
};
diff --git a/sw/qa/core/swdoc-test.cxx b/sw/qa/core/swdoc-test.cxx
index ae4926697fed..e47b7d18ecd3 100644
--- a/sw/qa/core/swdoc-test.cxx
+++ b/sw/qa/core/swdoc-test.cxx
@@ -238,7 +238,7 @@ void SwDocTest::testSwScanner()
{
SwScanner aScanner(*pTxtNode,
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Hello World")),
- 0, 0, i18n::WordType::DICTIONARY_WORD, 0,
+ 0, ModelToViewHelper(), i18n::WordType::DICTIONARY_WORD, 0,
RTL_CONSTASCII_LENGTH("Hello World"));
bool bFirstOk = aScanner.NextWord();
diff --git a/sw/source/core/doc/docedt.cxx b/sw/source/core/doc/docedt.cxx
index d33c9dca8256..11517ca9726f 100644
--- a/sw/source/core/doc/docedt.cxx
+++ b/sw/source/core/doc/docedt.cxx
@@ -1824,7 +1824,7 @@ bool SwDoc::DeleteRange( SwPaM & rPam )
void lcl_syncGrammarError( SwTxtNode &rTxtNode, linguistic2::ProofreadingResult& rResult,
- xub_StrLen /*nBeginGrammarCheck*/, const ModelToViewHelper::ConversionMap* pConversionMap )
+ xub_StrLen /*nBeginGrammarCheck*/, const ModelToViewHelper &rConversionMap )
{
if( rTxtNode.IsGrammarCheckDirty() )
return;
@@ -1836,8 +1836,8 @@ void lcl_syncGrammarError( SwTxtNode &rTxtNode, linguistic2::ProofreadingResult&
for( i = 0; i < rResult.aErrors.getLength(); ++i )
{
const linguistic2::SingleProofreadingError &rError = rResult.aErrors[i];
- xub_StrLen nStart = (xub_StrLen)ModelToViewHelper::ConvertToModelPosition( pConversionMap, rError.nErrorStart ).mnPos;
- xub_StrLen nEnd = (xub_StrLen)ModelToViewHelper::ConvertToModelPosition( pConversionMap, rError.nErrorStart + rError.nErrorLength ).mnPos;
+ xub_StrLen nStart = (xub_StrLen)rConversionMap.ConvertToModelPosition( rError.nErrorStart ).mnPos;
+ xub_StrLen nEnd = (xub_StrLen)rConversionMap.ConvertToModelPosition( rError.nErrorStart + rError.nErrorLength ).mnPos;
if( i != j )
pArray[j] = pArray[i];
if( pWrong->LookForEntry( nStart, nEnd ) )
@@ -1955,22 +1955,22 @@ uno::Any SwDoc::Spell( SwPaM& rPaM,
String aText( ((SwTxtNode*)pNd)->GetTxt().Copy( nBeginGrammarCheck, nEndGrammarCheck - nBeginGrammarCheck ) );
uno::Reference< lang::XComponent > xDoc( ((SwDocShell*)GetDocShell())->GetBaseModel(), uno::UNO_QUERY );
// Expand the string:
- rtl::OUString aExpandText;
- const ModelToViewHelper::ConversionMap* pConversionMap =
- ((SwTxtNode*)pNd)->BuildConversionMap( aExpandText );
+ const ModelToViewHelper aConversionMap(*(SwTxtNode*)pNd);
+ rtl::OUString aExpandText = aConversionMap.getViewText();
+
// get XFlatParagraph to use...
- uno::Reference< text::XFlatParagraph > xFlatPara = new SwXFlatParagraph( *((SwTxtNode*)pNd), aExpandText, pConversionMap );
+ uno::Reference< text::XFlatParagraph > xFlatPara = new SwXFlatParagraph( *((SwTxtNode*)pNd), aExpandText, aConversionMap );
// get error position of cursor in XFlatParagraph
linguistic2::ProofreadingResult aResult;
sal_Int32 nGrammarErrors;
do
{
- ModelToViewHelper::ConvertToViewPosition( pConversionMap, nBeginGrammarCheck );
+ aConversionMap.ConvertToViewPosition( nBeginGrammarCheck );
aResult = xGCIterator->checkSentenceAtPosition(
xDoc, xFlatPara, aExpandText, lang::Locale(), nBeginGrammarCheck, -1, -1 );
- lcl_syncGrammarError( *((SwTxtNode*)pNd), aResult, nBeginGrammarCheck, pConversionMap );
+ lcl_syncGrammarError( *((SwTxtNode*)pNd), aResult, nBeginGrammarCheck, aConversionMap );
// get suggestions to use for the specific error position
nGrammarErrors = aResult.aErrors.getLength();
@@ -1992,8 +1992,8 @@ uno::Any SwDoc::Spell( SwPaM& rPaM,
pEndPos->nNode = nCurrNd;
pSpellArgs->pStartNode = ((SwTxtNode*)pNd);
pSpellArgs->pEndNode = ((SwTxtNode*)pNd);
- pSpellArgs->pStartIdx->Assign(((SwTxtNode*)pNd), (xub_StrLen)ModelToViewHelper::ConvertToModelPosition( pConversionMap, rError.nErrorStart ).mnPos );
- pSpellArgs->pEndIdx->Assign(((SwTxtNode*)pNd), (xub_StrLen)ModelToViewHelper::ConvertToModelPosition( pConversionMap, rError.nErrorStart + rError.nErrorLength ).mnPos );
+ pSpellArgs->pStartIdx->Assign(((SwTxtNode*)pNd), (xub_StrLen)aConversionMap.ConvertToModelPosition( rError.nErrorStart ).mnPos );
+ pSpellArgs->pEndIdx->Assign(((SwTxtNode*)pNd), (xub_StrLen)aConversionMap.ConvertToModelPosition( rError.nErrorStart + rError.nErrorLength ).mnPos );
nCurrNd = nEndNd;
}
}
diff --git a/sw/source/core/edit/edlingu.cxx b/sw/source/core/edit/edlingu.cxx
index ffe27d3c3236..c002d56a5dca 100644
--- a/sw/source/core/edit/edlingu.cxx
+++ b/sw/source/core/edit/edlingu.cxx
@@ -1131,17 +1131,16 @@ bool SwEditShell::GetGrammarCorrection(
uno::Reference< lang::XComponent > xDoc( pDoc->GetDocShell()->GetBaseModel(), uno::UNO_QUERY );
// Expand the string:
- rtl::OUString aExpandText;
- const ModelToViewHelper::ConversionMap* pConversionMap =
- pNode->BuildConversionMap( aExpandText );
+ const ModelToViewHelper aConversionMap(*pNode);
+ rtl::OUString aExpandText = aConversionMap.getViewText();
// get XFlatParagraph to use...
- uno::Reference< text::XFlatParagraph > xFlatPara = new SwXFlatParagraph( *pNode, aExpandText, pConversionMap );
+ uno::Reference< text::XFlatParagraph > xFlatPara = new SwXFlatParagraph( *pNode, aExpandText, aConversionMap );
// get error position of cursor in XFlatParagraph
- rErrorPosInText = ModelToViewHelper::ConvertToViewPosition( pConversionMap, nBegin );
+ rErrorPosInText = aConversionMap.ConvertToViewPosition( nBegin );
- sal_Int32 nStartOfSentence = ModelToViewHelper::ConvertToViewPosition( pConversionMap, pWrong->getSentenceStart( nBegin ) );
- sal_Int32 nEndOfSentence = ModelToViewHelper::ConvertToViewPosition( pConversionMap, pWrong->getSentenceEnd( nBegin ) );
+ sal_Int32 nStartOfSentence = aConversionMap.ConvertToViewPosition( pWrong->getSentenceStart( nBegin ) );
+ sal_Int32 nEndOfSentence = aConversionMap.ConvertToViewPosition( pWrong->getSentenceEnd( nBegin ) );
if( nEndOfSentence == STRING_LEN )
{
nEndOfSentence = aExpandText.getLength();
@@ -1601,9 +1600,9 @@ bool SwSpellIter::SpellSentence(::svx::SpellPortions& rPortions, bool bIsGrammar
pMySh->GoEndSentence();
if( bGrammarErrorFound )
{
- rtl::OUString aExpandText;
- const ModelToViewHelper::ConversionMap* pConversionMap = ((SwTxtNode*)pCrsr->GetNode())->BuildConversionMap( aExpandText );
- xub_StrLen nSentenceEnd = (xub_StrLen)ModelToViewHelper::ConvertToViewPosition( pConversionMap, aGrammarResult.nBehindEndOfSentencePosition );
+ const ModelToViewHelper aConversionMap(*(SwTxtNode*)pCrsr->GetNode());
+ rtl::OUString aExpandText = aConversionMap.getViewText();
+ xub_StrLen nSentenceEnd = (xub_StrLen)aConversionMap.ConvertToViewPosition( aGrammarResult.nBehindEndOfSentencePosition );
// remove trailing space
if( aExpandText[nSentenceEnd - 1] == ' ' )
--nSentenceEnd;
diff --git a/sw/source/core/text/porlay.cxx b/sw/source/core/text/porlay.cxx
index 9ab7bbe4851b..c464d2452581 100644
--- a/sw/source/core/text/porlay.cxx
+++ b/sw/source/core/text/porlay.cxx
@@ -989,7 +989,7 @@ void SwScriptInfo::InitScriptInfo( const SwTxtNode& rNode, sal_Bool bRTL )
// we search for connecting opportunities (kashida)
else if ( bAdjustBlock && i18n::ScriptType::COMPLEX == nScript )
{
- SwScanner aScanner( rNode, rNode.GetTxt(), 0, 0,
+ SwScanner aScanner( rNode, rNode.GetTxt(), 0, ModelToViewHelper(),
i18n::WordType::DICTIONARY_WORD,
nLastKashida, nChg );
diff --git a/sw/source/core/txtnode/modeltoviewhelper.cxx b/sw/source/core/txtnode/modeltoviewhelper.cxx
index 7f33324b04cf..861583dab70b 100644
--- a/sw/source/core/txtnode/modeltoviewhelper.cxx
+++ b/sw/source/core/txtnode/modeltoviewhelper.cxx
@@ -19,21 +19,15 @@
#include <modeltoviewhelper.hxx>
-namespace ModelToViewHelper
-{
-
/** Converts a model position into a view position
*/
-sal_uInt32 ConvertToViewPosition( const ConversionMap* pMap, sal_uInt32 nModelPos )
+sal_uInt32 ModelToViewHelper::ConvertToViewPosition( sal_uInt32 nModelPos ) const
{
sal_uInt32 nRet = nModelPos;
- if ( !pMap )
- return nRet;
-
// Search for entry after nPos:
ConversionMap::const_iterator aIter;
- for ( aIter = pMap->begin(); aIter != pMap->end(); ++aIter )
+ for ( aIter = m_aMap.begin(); aIter != m_aMap.end(); ++aIter )
{
if ( (*aIter).first >= nModelPos )
{
@@ -52,17 +46,14 @@ sal_uInt32 ConvertToViewPosition( const ConversionMap* pMap, sal_uInt32 nModelPo
/** Converts a view position into a model position
*/
-ModelPosition ConvertToModelPosition( const ConversionMap* pMap, sal_uInt32 nViewPos )
+ModelToViewHelper::ModelPosition ModelToViewHelper::ConvertToModelPosition( sal_uInt32 nViewPos ) const
{
ModelPosition aRet;
aRet.mnPos = nViewPos;
- if ( !pMap )
- return aRet;
-
// Search for entry after nPos:
ConversionMap::const_iterator aIter;
- for ( aIter = pMap->begin(); aIter != pMap->end(); ++aIter )
+ for ( aIter = m_aMap.begin(); aIter != m_aMap.end(); ++aIter )
{
if ( (*aIter).second > nViewPos )
{
@@ -70,7 +61,7 @@ ModelPosition ConvertToModelPosition( const ConversionMap* pMap, sal_uInt32 nVie
const sal_uInt32 nPosExpand = (*aIter).second;
// If nViewPos is in front of first field, we are finished.
- if ( aIter == pMap->begin() )
+ if ( aIter == m_aMap.begin() )
break;
--aIter;
@@ -107,6 +98,4 @@ ModelPosition ConvertToModelPosition( const ConversionMap* pMap, sal_uInt32 nVie
return aRet;
}
-} // namespace ModelToViewStringConverter end
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx
index b9664806b867..3a26191da9d6 100644
--- a/sw/source/core/txtnode/ndtxt.cxx
+++ b/sw/source/core/txtnode/ndtxt.cxx
@@ -3092,14 +3092,12 @@ sal_Bool SwTxtNode::GetExpandTxt( SwTxtNode& rDestNd, const SwIndex* pDestIdx,
return sal_True;
}
-const ModelToViewHelper::ConversionMap*
- SwTxtNode::BuildConversionMap( rtl::OUString& rRetText ) const
+ModelToViewHelper::ModelToViewHelper(const SwTxtNode &rNode)
{
- const rtl::OUString& rNodeText = GetTxt();
- rRetText = rNodeText;
- ModelToViewHelper::ConversionMap* pConversionMap = 0;
+ const rtl::OUString& rNodeText = rNode.GetTxt();
+ m_aRetText = rNodeText;
- const SwpHints* pSwpHints2 = GetpSwpHints();
+ const SwpHints* pSwpHints2 = rNode.GetpSwpHints();
xub_StrLen nPos = 0;
for ( sal_uInt16 i = 0; pSwpHints2 && i < pSwpHints2->Count(); ++i )
@@ -3121,7 +3119,7 @@ const ModelToViewHelper::ConversionMap*
{
bReplace = true;
const SwFmtFtn& rFtn = static_cast<SwTxtFtn const*>(pAttr)->GetFtn();
- const SwDoc *pDoc = GetDoc();
+ const SwDoc *pDoc = rNode.GetDoc();
aExpand = rFtn.GetViewNumStr(*pDoc);
nFieldPos = *pAttr->GetStart();
}
@@ -3137,22 +3135,14 @@ const ModelToViewHelper::ConversionMap*
if (bReplace)
{
- rRetText = rRetText.replaceAt( nPos + nFieldPos, 1, aExpand );
- if ( !pConversionMap )
- pConversionMap = new ModelToViewHelper::ConversionMap;
- pConversionMap->push_back(
- ModelToViewHelper::ConversionMapEntry(
- nFieldPos, nPos + nFieldPos ) );
+ m_aRetText = m_aRetText.replaceAt( nPos + nFieldPos, 1, aExpand );
+ m_aMap.push_back( ConversionMapEntry( nFieldPos, nPos + nFieldPos ) );
nPos += ( aExpand.getLength() - 1 );
}
}
- if ( pConversionMap && pConversionMap->size() )
- pConversionMap->push_back(
- ModelToViewHelper::ConversionMapEntry(
- rNodeText.getLength()+1, rRetText.getLength()+1 ) );
-
- return pConversionMap;
+ if ( !m_aMap.empty() )
+ m_aMap.push_back( ConversionMapEntry( rNodeText.getLength()+1, m_aRetText.getLength()+1 ) );
}
XubString SwTxtNode::GetRedlineTxt( xub_StrLen nIdx, xub_StrLen nLen,
diff --git a/sw/source/core/txtnode/txtedt.cxx b/sw/source/core/txtnode/txtedt.cxx
index 9f18fc7401e0..0e4e44778928 100644
--- a/sw/source/core/txtnode/txtedt.cxx
+++ b/sw/source/core/txtnode/txtedt.cxx
@@ -660,9 +660,9 @@ XubString SwTxtNode::GetCurWord( xub_StrLen nPos ) const
}
SwScanner::SwScanner( const SwTxtNode& rNd, const rtl::OUString& rTxt,
- const LanguageType* pLang, const ModelToViewHelper::ConversionMap* pConvMap,
+ const LanguageType* pLang, const ModelToViewHelper& rConvMap,
sal_uInt16 nType, sal_Int32 nStart, sal_Int32 nEnde, sal_Bool bClp )
- : rNode( rNd ), aText( rTxt), pLanguage( pLang ), pConversionMap( pConvMap ), nLen( 0 ), nWordType( nType ), bClip( bClp )
+ : rNode( rNd ), aText( rTxt), pLanguage( pLang ), rConversionMap( rConvMap ), nLen( 0 ), nWordType( nType ), bClip( bClp )
{
OSL_ENSURE( !aText.isEmpty(), "SwScanner: EmptyString" );
nStartPos = nBegin = nStart;
@@ -674,7 +674,7 @@ SwScanner::SwScanner( const SwTxtNode& rNd, const rtl::OUString& rTxt,
}
else
{
- ModelToViewHelper::ModelPosition aModelBeginPos = ModelToViewHelper::ConvertToModelPosition( pConversionMap, nBegin );
+ ModelToViewHelper::ModelPosition aModelBeginPos = rConversionMap.ConvertToModelPosition( nBegin );
const sal_Int32 nModelBeginPos = aModelBeginPos.mnPos;
aCurrLang = rNd.GetLang( nModelBeginPos );
}
@@ -736,7 +736,7 @@ sal_Bool SwScanner::NextWord()
if ( !pLanguage )
{
const sal_uInt16 nNextScriptType = pBreakIt->GetBreakIter()->getScriptType( aText, nBegin );
- ModelToViewHelper::ModelPosition aModelBeginPos = ModelToViewHelper::ConvertToModelPosition( pConversionMap, nBegin );
+ ModelToViewHelper::ModelPosition aModelBeginPos = rConversionMap.ConvertToModelPosition( nBegin );
const sal_Int32 nBeginModelPos = aModelBeginPos.mnPos;
aCurrLang = rNode.GetLang( nBeginModelPos, 1, nNextScriptType );
}
@@ -915,7 +915,7 @@ sal_uInt16 SwTxtNode::Spell(SwSpellArgs* pArgs)
// In case 2. we pass the wrong list to the scanned, because only
// the words in the wrong list have to be checked
- SwScanner aScanner( *this, m_Text, 0, 0,
+ SwScanner aScanner( *this, m_Text, 0, ModelToViewHelper(),
WordType::DICTIONARY_WORD,
nBegin, nEnd );
while( !pArgs->xSpellAlt.is() && aScanner.NextWord() )
@@ -1223,7 +1223,7 @@ SwRect SwTxtFrm::_AutoSpell( const SwCntntNode* pActNode, const SwViewOption& rV
uno::Reference< XSpellChecker1 > xSpell( ::GetSpellChecker() );
SwDoc* pDoc = pNode->GetDoc();
- SwScanner aScanner( *pNode, pNode->GetTxt(), 0, 0,
+ SwScanner aScanner( *pNode, pNode->GetTxt(), 0, ModelToViewHelper(),
WordType::DICTIONARY_WORD, nBegin, nEnd);
while( aScanner.NextWord() )
@@ -1373,13 +1373,12 @@ SwRect SwTxtFrm::SmartTagScan( SwCntntNode* /*pActNode*/, xub_StrLen /*nActPos*/
if ( nBegin < nEnd )
{
// Expand the string:
- rtl::OUString aExpandText;
- const ModelToViewHelper::ConversionMap* pConversionMap =
- pNode->BuildConversionMap( aExpandText );
+ const ModelToViewHelper aConversionMap(*pNode);
+ rtl::OUString aExpandText = aConversionMap.getViewText();
// Ownership ov ConversionMap is passed to SwXTextMarkup object!
Reference< com::sun::star::text::XTextMarkup > xTextMarkup =
- new SwXTextMarkup( *pNode, pConversionMap );
+ new SwXTextMarkup( *pNode, aConversionMap );
Reference< ::com::sun::star::frame::XController > xController = pNode->GetDoc()->GetDocShell()->GetController();
@@ -1395,8 +1394,8 @@ SwRect SwTxtFrm::SmartTagScan( SwCntntNode* /*pActNode*/, xub_StrLen /*nActPos*/
const com::sun::star::lang::Locale aLocale = pBreakIt->GetLocale( nLang );
nLangEnd = Min( nEnd, aIter.GetChgPos() );
- const sal_uInt32 nExpandBegin = ModelToViewHelper::ConvertToViewPosition( pConversionMap, nLangBegin );
- const sal_uInt32 nExpandEnd = ModelToViewHelper::ConvertToViewPosition( pConversionMap, nLangEnd );
+ const sal_uInt32 nExpandBegin = aConversionMap.ConvertToViewPosition( nLangBegin );
+ const sal_uInt32 nExpandEnd = aConversionMap.ConvertToViewPosition( nLangEnd );
rSmartTagMgr.Recognize( aExpandText, xTextMarkup, xController, aLocale, nExpandBegin, nExpandEnd - nExpandBegin );
@@ -1458,7 +1457,7 @@ void SwTxtFrm::CollectAutoCmplWrds( SwCntntNode* pActNode, xub_StrLen nActPos )
if( nBegin < nEnd )
{
sal_uInt16 nCnt = 200;
- SwScanner aScanner( *pNode, pNode->GetTxt(), 0, 0,
+ SwScanner aScanner( *pNode, pNode->GetTxt(), 0, ModelToViewHelper(),
WordType::DICTIONARY_WORD, nBegin, nEnd );
while( aScanner.NextWord() )
{
@@ -1861,13 +1860,13 @@ void SwTxtNode::CountWords( SwDocStat& rStat,
return;
}
- // expand text into pConversionMap for scanner
- rtl::OUString aExpandText;
- const ModelToViewHelper::ConversionMap* pConversionMap = BuildConversionMap( aExpandText );
+ // expand text into aConversionMap for scanner
+ const ModelToViewHelper aConversionMap(*this);
+ rtl::OUString aExpandText = aConversionMap.getViewText();
// map start and end points onto the ConversionMap
- const sal_uInt32 nExpandBegin = ModelToViewHelper::ConvertToViewPosition( pConversionMap, nStt );
- const sal_uInt32 nExpandEnd = ModelToViewHelper::ConvertToViewPosition( pConversionMap, nEnd );
+ const sal_uInt32 nExpandBegin = aConversionMap.ConvertToViewPosition( nStt );
+ const sal_uInt32 nExpandEnd = aConversionMap.ConvertToViewPosition( nEnd );
if ( aExpandText.isEmpty() )
{
@@ -1894,7 +1893,7 @@ void SwTxtNode::CountWords( SwDocStat& rStat,
if( pBreakIt->GetBreakIter().is() )
{
// zero is NULL for pLanguage -----------v last param = true for clipping
- SwScanner aScanner( *this, aExpandText, 0, pConversionMap, i18n::WordType::WORD_COUNT,
+ SwScanner aScanner( *this, aExpandText, 0, aConversionMap, i18n::WordType::WORD_COUNT,
nExpandBegin, nExpandEnd, true );
// used to filter out scanner returning almost empty strings (len=1; unichar=0x0001)
@@ -1931,7 +1930,7 @@ void SwTxtNode::CountWords( SwDocStat& rStat,
{
LanguageType aLanguage = GetLang( 0 );
- SwScanner aScanner( *this, aNumString, &aLanguage, 0,
+ SwScanner aScanner( *this, aNumString, &aLanguage, ModelToViewHelper(),
i18n::WordType::WORD_COUNT, 0, nNumStringLen, true );
while ( aScanner.NextWord() )
@@ -1953,8 +1952,6 @@ void SwTxtNode::CountWords( SwDocStat& rStat,
}
}
- delete pConversionMap;
-
// If counting the whole para then update cached values and mark clean
if ( isCountAll )
{
diff --git a/sw/source/core/unocore/unoflatpara.cxx b/sw/source/core/unocore/unoflatpara.cxx
index c59056001d3c..1652f9c48d54 100644
--- a/sw/source/core/unocore/unoflatpara.cxx
+++ b/sw/source/core/unocore/unoflatpara.cxx
@@ -59,8 +59,8 @@ using namespace ::com::sun::star;
* SwXFlatParagraph
******************************************************************************/
-SwXFlatParagraph::SwXFlatParagraph( SwTxtNode& rTxtNode, rtl::OUString aExpandText, const ModelToViewHelper::ConversionMap* pMap ) :
- SwXTextMarkup( rTxtNode, pMap ),
+SwXFlatParagraph::SwXFlatParagraph( SwTxtNode& rTxtNode, rtl::OUString aExpandText, const ModelToViewHelper& rMap ) :
+ SwXTextMarkup( rTxtNode, rMap ),
maExpandText( aExpandText )
{
}
@@ -416,11 +416,10 @@ uno::Reference< text::XFlatParagraph > SwXFlatParagraphIterator::getNextPara()
if ( pRet )
{
// Expand the string:
- rtl::OUString aExpandText;
- const ModelToViewHelper::ConversionMap* pConversionMap =
- pRet->BuildConversionMap( aExpandText );
+ const ModelToViewHelper aConversionMap(*pRet);
+ rtl::OUString aExpandText = aConversionMap.getViewText();
- xRet = new SwXFlatParagraph( *pRet, aExpandText, pConversionMap );
+ xRet = new SwXFlatParagraph( *pRet, aExpandText, aConversionMap );
// keep hard references...
m_aFlatParaList.insert( xRet );
}
@@ -469,11 +468,10 @@ uno::Reference< text::XFlatParagraph > SwXFlatParagraphIterator::getParaAfter(co
if ( pNextTxtNode )
{
// Expand the string:
- rtl::OUString aExpandText;
- const ModelToViewHelper::ConversionMap* pConversionMap =
- pNextTxtNode->BuildConversionMap( aExpandText );
+ const ModelToViewHelper aConversionMap(*pNextTxtNode);
+ rtl::OUString aExpandText = aConversionMap.getViewText();
- xRet = new SwXFlatParagraph( *pNextTxtNode, aExpandText, pConversionMap );
+ xRet = new SwXFlatParagraph( *pNextTxtNode, aExpandText, aConversionMap );
// keep hard references...
m_aFlatParaList.insert( xRet );
}
@@ -516,11 +514,10 @@ uno::Reference< text::XFlatParagraph > SwXFlatParagraphIterator::getParaBefore(c
if ( pPrevTxtNode )
{
// Expand the string:
- rtl::OUString aExpandText;
- const ModelToViewHelper::ConversionMap* pConversionMap =
- pPrevTxtNode->BuildConversionMap( aExpandText );
+ const ModelToViewHelper aConversionMap(*pPrevTxtNode);
+ rtl::OUString aExpandText = aConversionMap.getViewText();
- xRet = new SwXFlatParagraph( *pPrevTxtNode, aExpandText, pConversionMap );
+ xRet = new SwXFlatParagraph( *pPrevTxtNode, aExpandText, aConversionMap );
// keep hard references...
m_aFlatParaList.insert( xRet );
}
diff --git a/sw/source/core/unocore/unotextmarkup.cxx b/sw/source/core/unocore/unotextmarkup.cxx
index 80d410e7bde5..a7cddad07a85 100644
--- a/sw/source/core/unocore/unotextmarkup.cxx
+++ b/sw/source/core/unocore/unotextmarkup.cxx
@@ -44,8 +44,8 @@ using namespace ::com::sun::star;
/*
* SwXTextMarkup
*/
-SwXTextMarkup::SwXTextMarkup( SwTxtNode& rTxtNode, const ModelToViewHelper::ConversionMap* pMap )
- : mpTxtNode( &rTxtNode ), mpConversionMap( pMap )
+SwXTextMarkup::SwXTextMarkup( SwTxtNode& rTxtNode, const ModelToViewHelper& rMap )
+ : mpTxtNode( &rTxtNode ), maConversionMap( rMap )
{
// FME 2007-07-16 #i79641# SwXTextMarkup is allowed to be removed ...
SetIsAllowedToBeRemovedInModifyCall(true);
@@ -54,7 +54,6 @@ SwXTextMarkup::SwXTextMarkup( SwTxtNode& rTxtNode, const ModelToViewHelper::Conv
SwXTextMarkup::~SwXTextMarkup()
{
- delete mpConversionMap;
}
uno::Reference< container::XStringKeyMap > SAL_CALL SwXTextMarkup::getMarkupInfoContainer() throw (uno::RuntimeException)
@@ -133,9 +132,9 @@ void SAL_CALL SwXTextMarkup::commitTextMarkup(
const ModelToViewHelper::ModelPosition aStartPos =
- ModelToViewHelper::ConvertToModelPosition( mpConversionMap, nStart );
+ maConversionMap.ConvertToModelPosition( nStart );
const ModelToViewHelper::ModelPosition aEndPos =
- ModelToViewHelper::ConvertToModelPosition( mpConversionMap, nStart + nLength - 1);
+ maConversionMap.ConvertToModelPosition( nStart + nLength - 1);
const bool bStartInField = aStartPos.mbIsField;
const bool bEndInField = aEndPos.mbIsField;
@@ -181,8 +180,8 @@ void SAL_CALL SwXTextMarkup::commitTextMarkup(
pSubList = new SwGrammarMarkUp();
pWList->InsertSubList( nFieldPosModel, 1, nInsertPos, pSubList );
}
- const sal_uInt32 nTmpStart = ModelToViewHelper::ConvertToViewPosition( mpConversionMap, aStartPos.mnPos );
- const sal_uInt32 nTmpLen = ModelToViewHelper::ConvertToViewPosition( mpConversionMap, aStartPos.mnPos + 1 )
+ const sal_uInt32 nTmpStart = maConversionMap.ConvertToViewPosition( aStartPos.mnPos );
+ const sal_uInt32 nTmpLen = maConversionMap.ConvertToViewPosition( aStartPos.mnPos + 1 )
- nTmpStart - aStartPos.mnSubPos;
if( nTmpLen > 0 )
{
@@ -233,7 +232,7 @@ void SAL_CALL SwXTextMarkup::commitTextMarkup(
void lcl_commitGrammarMarkUp(
- const ModelToViewHelper::ConversionMap* pConversionMap,
+ const ModelToViewHelper& rConversionMap,
SwGrammarMarkUp* pWList,
::sal_Int32 nType,
const ::rtl::OUString & rIdentifier,
@@ -243,9 +242,9 @@ void lcl_commitGrammarMarkUp(
{
OSL_ENSURE( nType == text::TextMarkupType::PROOFREADING || nType == text::TextMarkupType::SENTENCE, "Wrong mark-up type" );
const ModelToViewHelper::ModelPosition aStartPos =
- ModelToViewHelper::ConvertToModelPosition( pConversionMap, nStart );
+ rConversionMap.ConvertToModelPosition( nStart );
const ModelToViewHelper::ModelPosition aEndPos =
- ModelToViewHelper::ConvertToModelPosition( pConversionMap, nStart + nLength - 1);
+ rConversionMap.ConvertToModelPosition( nStart + nLength - 1);
const bool bStartInField = aStartPos.mbIsField;
const bool bEndInField = aEndPos.mbIsField;
@@ -288,8 +287,8 @@ void lcl_commitGrammarMarkUp(
pSubList = new SwGrammarMarkUp();
pWList->InsertSubList( nFieldPosModel, 1, nInsertPos, pSubList );
}
- const sal_uInt32 nTmpStart = ModelToViewHelper::ConvertToViewPosition( pConversionMap, aStartPos.mnPos );
- const sal_uInt32 nTmpLen = ModelToViewHelper::ConvertToViewPosition( pConversionMap, aStartPos.mnPos + 1 )
+ const sal_uInt32 nTmpStart = rConversionMap.ConvertToViewPosition( aStartPos.mnPos );
+ const sal_uInt32 nTmpLen = rConversionMap.ConvertToViewPosition( aStartPos.mnPos + 1 )
- nTmpStart - aStartPos.mnSubPos;
if( nTmpLen > 0 )
pSubList->Insert( rIdentifier, xMarkupInfoContainer,
@@ -391,7 +390,7 @@ throw (lang::IllegalArgumentException, uno::RuntimeException)
if( pWList->GetBeginInv() < STRING_LEN )
{
const ModelToViewHelper::ModelPosition aSentenceEnd =
- ModelToViewHelper::ConvertToModelPosition( mpConversionMap,
+ maConversionMap.ConvertToModelPosition(
pMarkups[nSentenceMarkUpIndex].nOffset + pMarkups[nSentenceMarkUpIndex].nLength );
bAcceptGrammarError = (xub_StrLen)aSentenceEnd.mnPos > pWList->GetBeginInv();
pWList->ClearGrammarList( (xub_StrLen)aSentenceEnd.mnPos );
@@ -402,7 +401,7 @@ throw (lang::IllegalArgumentException, uno::RuntimeException)
for( i = 0; i < nLen; ++i )
{
const text::TextMarkupDescriptor &rDesc = pMarkups[i];
- lcl_commitGrammarMarkUp( mpConversionMap, pWList, rDesc.nType,
+ lcl_commitGrammarMarkUp( maConversionMap, pWList, rDesc.nType,
rDesc.aIdentifier, rDesc.nOffset, rDesc.nLength, rDesc.xMarkupInfoContainer );
}
}
@@ -411,7 +410,7 @@ throw (lang::IllegalArgumentException, uno::RuntimeException)
bRepaint = false;
i = nSentenceMarkUpIndex;
const text::TextMarkupDescriptor &rDesc = pMarkups[i];
- lcl_commitGrammarMarkUp( mpConversionMap, pWList, rDesc.nType,
+ lcl_commitGrammarMarkUp( maConversionMap, pWList, rDesc.nType,
rDesc.aIdentifier, rDesc.nOffset, rDesc.nLength, rDesc.xMarkupInfoContainer );
}