summaryrefslogtreecommitdiff
path: root/sw/source/core/txtnode
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 /sw/source/core/txtnode
parente5e85f2987a27db7efb2b24039b5c1ddf3f5d90e (diff)
refactor ModelToViewHelper, should have unchanged results
Change-Id: Ib57f0d6f9491d12ffacada5ec0ae8bc68874c25b
Diffstat (limited to 'sw/source/core/txtnode')
-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
3 files changed, 33 insertions, 57 deletions
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 )
{