sw/inc/splargs.hxx                |   36 ++++++++++++++++--------------------
 sw/source/core/doc/docedt.cxx     |   27 +++++++++++----------------
 sw/source/core/txtnode/txtedt.cxx |   28 ++++++++++++----------------
 sw/source/uibase/lingu/hhcwrp.cxx |   18 +++++++-----------
 4 files changed, 46 insertions(+), 63 deletions(-)

New commits:
commit 3521cf575c1cede6b60318ddb561fc9184c8c16d
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Thu Sep 15 19:56:03 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Fri Sep 16 10:01:03 2022 +0200

    use SwPosition in SwArgsBase
    
    as part of the process of hiding the internals of SwPosition
    
    Change-Id: I3fb116fb9ce56ba5c6efb5c4954eb4a93a7fe722
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140033
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/inc/splargs.hxx b/sw/inc/splargs.hxx
index ba5574a15549..a4ec4f0a6c36 100644
--- a/sw/inc/splargs.hxx
+++ b/sw/inc/splargs.hxx
@@ -28,6 +28,7 @@
 #include <functional>
 #include <utility>
 
+struct SwPosition;
 class SwTextFrame;
 class SwTextNode;
 class SwContentIndex;
@@ -36,26 +37,21 @@ namespace com::sun::star::linguistic2 { class 
XHyphenatedWord; }
 
 struct SwArgsBase     // used for text conversion (Hangul/Hanja, ...)
 {
-    SwTextNode     *pStartNode;
-    SwContentIndex *pStartIdx;
-    SwTextNode     *pEndNode;
-    SwContentIndex *pEndIdx;
-
-    SwArgsBase(
-            SwTextNode* pStart, SwContentIndex& rStart,
-            SwTextNode* pEnd, SwContentIndex& rEnd )
-        : pStartNode( pStart ), pStartIdx( &rStart ),
-          pEndNode( pEnd ), pEndIdx( &rEnd )
+    SwPosition *pStartPos; // these both both point to SwTextNode
+    SwPosition *pEndPos;
+
+    SwArgsBase(SwPosition& rStart, SwPosition& rEnd )
+        : pStartPos( &rStart ), pEndPos( &rEnd )
         {}
 
-    void SetStart(SwTextNode* pStart, SwContentIndex& rStart )
+    void SetStart(SwPosition& rStart )
     {
-        pStartNode = pStart;    pStartIdx = &rStart ;
+        pStartPos = &rStart;
     }
 
-    void SetEnd( SwTextNode* pEnd, SwContentIndex& rEnd  )
+    void SetEnd( SwPosition& rEnd  )
     {
-        pEndNode = pEnd;        pEndIdx = &rEnd ;
+        pEndPos = &rEnd ;
     }
 };
 
@@ -73,9 +69,9 @@ struct SwConversionArgs : SwArgsBase
     bool            bAllowImplicitChangesForNotConvertibleText;
 
     SwConversionArgs( LanguageType nLang,
-            SwTextNode* pStart, SwContentIndex& rStart,
-            SwTextNode* pEnd, SwContentIndex& rEnd )
-        : SwArgsBase( pStart, rStart, pEnd, rEnd ),
+            SwPosition& rStart,
+            SwPosition& rEnd )
+        : SwArgsBase( rStart, rEnd ),
           nConvSrcLang( nLang ),
           nConvTextLang( LANGUAGE_NONE ),
           nConvTargetLang( LANGUAGE_NONE ),
@@ -93,10 +89,10 @@ struct SwSpellArgs : SwArgsBase
     bool bIsGrammarCheck;
 
     SwSpellArgs(css::uno::Reference< css::linguistic2::XSpellChecker1 > 
xSplChk,
-            SwTextNode* pStart, SwContentIndex& rStart,
-            SwTextNode* pEnd, SwContentIndex& rEnd,
+            SwPosition& rStart,
+            SwPosition& rEnd,
             bool bGrammar )
-        :   SwArgsBase( pStart, rStart, pEnd, rEnd ),
+        :   SwArgsBase( rStart, rEnd ),
             xSpeller(std::move( xSplChk )),
             bIsGrammarCheck( bGrammar )
         {}
diff --git a/sw/source/core/doc/docedt.cxx b/sw/source/core/doc/docedt.cxx
index 2b097eca37cb..6a209530b428 100644
--- a/sw/source/core/doc/docedt.cxx
+++ b/sw/source/core/doc/docedt.cxx
@@ -525,14 +525,11 @@ uno::Any SwDoc::Spell( SwPaM& rPaM,
     std::unique_ptr<SwSpellArgs> pSpellArgs;
     if (pConvArgs)
     {
-        pConvArgs->SetStart(pSttPos->GetNode().GetTextNode(), 
pSttPos->nContent);
-        pConvArgs->SetEnd(  pEndPos->GetNode().GetTextNode(), 
pEndPos->nContent );
+        pConvArgs->SetStart(*pSttPos);
+        pConvArgs->SetEnd(*pEndPos);
     }
     else
-        pSpellArgs.reset(new SwSpellArgs( xSpeller,
-                            pSttPos->GetNode().GetTextNode(), 
pSttPos->nContent,
-                            pEndPos->GetNode().GetTextNode(), 
pEndPos->nContent,
-                            bGrammarCheck ));
+        pSpellArgs.reset(new SwSpellArgs( xSpeller, *pSttPos, *pEndPos, 
bGrammarCheck ));
 
     SwNodeOffset nCurrNd = pSttPos->GetNodeIndex();
     SwNodeOffset nEndNd = pEndPos->GetNodeIndex();
@@ -578,7 +575,7 @@ uno::Any SwDoc::Spell( SwPaM& rPaM,
                         sal_Int32 nEndGrammarCheck = 0;
                         if( pSpellArgs && pSpellArgs->bIsGrammarCheck)
                         {
-                            nBeginGrammarCheck = pSpellArgs->pStartNode == pNd 
?  pSpellArgs->pStartIdx->GetIndex() : 0;
+                            nBeginGrammarCheck = 
&pSpellArgs->pStartPos->GetNode() == pNd ?  
pSpellArgs->pStartPos->GetContentIndex() : 0;
                             // if grammar checking starts inside of a sentence 
the start position has to be adjusted
                             if( nBeginGrammarCheck )
                             {
@@ -592,8 +589,8 @@ uno::Any SwDoc::Spell( SwPaM& rPaM,
                                     nBeginGrammarCheck = 
aCursor.GetPoint()->GetContentIndex();
                                 }
                             }
-                            nEndGrammarCheck = (pSpellArgs->pEndNode == pNd)
-                                ? pSpellArgs->pEndIdx->GetIndex()
+                            nEndGrammarCheck = 
(&pSpellArgs->pEndPos->GetNode() == pNd)
+                                ? pSpellArgs->pEndPos->GetContentIndex()
                                 : pNd->GetTextNode()
                                     ->GetText().getLength();
                         }
@@ -607,9 +604,9 @@ uno::Any SwDoc::Spell( SwPaM& rPaM,
                             pEndPos->nNode = nCurrNd;
                             nCurrNd = nEndNd;
                             if( pSpellArgs )
-                                nSpellErrorPosition = 
pSpellArgs->pStartIdx->GetIndex() > pSpellArgs->pEndIdx->GetIndex() ?
-                                            pSpellArgs->pEndIdx->GetIndex() :
-                                            pSpellArgs->pStartIdx->GetIndex();
+                                nSpellErrorPosition = 
pSpellArgs->pStartPos->GetContentIndex() > 
pSpellArgs->pEndPos->GetContentIndex() ?
+                                            
pSpellArgs->pEndPos->GetContentIndex() :
+                                            
pSpellArgs->pStartPos->GetContentIndex();
                         }
 
                         if( pSpellArgs && pSpellArgs->bIsGrammarCheck )
@@ -654,10 +651,8 @@ uno::Any SwDoc::Spell( SwPaM& rPaM,
                                     nCurrNd = pNd->GetIndex();
                                     pSttPos->nNode = nCurrNd;
                                     pEndPos->nNode = nCurrNd;
-                                    pSpellArgs->pStartNode = 
pNd->GetTextNode();
-                                    pSpellArgs->pEndNode = pNd->GetTextNode();
-                                    
pSpellArgs->pStartIdx->Assign(pNd->GetTextNode(), 
aConversionMap.ConvertToModelPosition( rError.nErrorStart ).mnPos );
-                                    
pSpellArgs->pEndIdx->Assign(pNd->GetTextNode(), 
aConversionMap.ConvertToModelPosition( rError.nErrorStart + rError.nErrorLength 
).mnPos );
+                                    
pSpellArgs->pStartPos->Assign(*pNd->GetTextNode(), 
aConversionMap.ConvertToModelPosition( rError.nErrorStart ).mnPos );
+                                    
pSpellArgs->pEndPos->Assign(*pNd->GetTextNode(), 
aConversionMap.ConvertToModelPosition( rError.nErrorStart + rError.nErrorLength 
).mnPos );
                                     nCurrNd = nEndNd;
                                 }
                             }
diff --git a/sw/source/core/txtnode/txtedt.cxx 
b/sw/source/core/txtnode/txtedt.cxx
index c22601e99a8a..90bca7705239 100644
--- a/sw/source/core/txtnode/txtedt.cxx
+++ b/sw/source/core/txtnode/txtedt.cxx
@@ -962,13 +962,13 @@ bool SwTextNode::Spell(SwSpellArgs* pArgs)
         m_Text = buf.makeStringAndClear();
     }
 
-    sal_Int32 nBegin = ( pArgs->pStartNode != this )
+    sal_Int32 nBegin = ( &pArgs->pStartPos->GetNode() != this )
         ? 0
-        : pArgs->pStartIdx->GetIndex();
+        : pArgs->pStartPos->GetContentIndex();
 
-    sal_Int32 nEnd = ( pArgs->pEndNode != this )
+    sal_Int32 nEnd = ( &pArgs->pEndPos->GetNode() != this )
             ? m_Text.getLength()
-            : pArgs->pEndIdx->GetIndex();
+            : pArgs->pEndPos->GetContentIndex();
 
     pArgs->xSpellAlt = nullptr;
 
@@ -1061,10 +1061,8 @@ bool SwTextNode::Spell(SwSpellArgs* pArgs)
                         while (pChar && *pChar-- == CH_TXTATR_INWORD)
                             ++nRight;
 
-                        pArgs->pStartNode = this;
-                        pArgs->pEndNode = this;
-                        pArgs->pStartIdx->Assign(this, aScanner.GetEnd() - 
nRight );
-                        pArgs->pEndIdx->Assign(this, aScanner.GetBegin() + 
nLeft );
+                        pArgs->pStartPos->Assign(*this, aScanner.GetEnd() - 
nRight );
+                        pArgs->pEndPos->Assign(*this, aScanner.GetBegin() + 
nLeft );
                     }
                 }
             }
@@ -1115,12 +1113,12 @@ bool SwTextNode::Convert( SwConversionArgs &rArgs )
     // get range of text within node to be converted
     // (either all the text or the text within the selection
     // when the conversion was started)
-    const sal_Int32 nTextBegin = ( rArgs.pStartNode == this )
-        ? std::min(rArgs.pStartIdx->GetIndex(), m_Text.getLength())
+    const sal_Int32 nTextBegin = ( &rArgs.pStartPos->GetNode() == this )
+        ? std::min(rArgs.pStartPos->GetContentIndex(), m_Text.getLength())
         : 0;
 
-    const sal_Int32 nTextEnd = ( rArgs.pEndNode == this )
-        ?  std::min(rArgs.pEndIdx->GetIndex(), m_Text.getLength())
+    const sal_Int32 nTextEnd = ( &rArgs.pEndPos->GetNode() == this )
+        ?  std::min(rArgs.pEndPos->GetContentIndex(), m_Text.getLength())
         :  m_Text.getLength();
 
     rArgs.aConvText.clear();
@@ -1229,11 +1227,9 @@ bool SwTextNode::Convert( SwConversionArgs &rArgs )
         rArgs.nConvTextLang = nLangFound;
 
         // position where to start looking in next iteration (after current 
ends)
-        rArgs.pStartNode = this;
-        rArgs.pStartIdx->Assign(this, nBegin + nLen );
+        rArgs.pStartPos->Assign(*this, nBegin + nLen );
         // end position (when we have travelled over the whole document)
-        rArgs.pEndNode = this;
-        rArgs.pEndIdx->Assign(this, nBegin );
+        rArgs.pEndPos->Assign(*this, nBegin );
     }
 
     // restore original text
diff --git a/sw/source/uibase/lingu/hhcwrp.cxx 
b/sw/source/uibase/lingu/hhcwrp.cxx
index 142399ed30c9..0838fdf37e4c 100644
--- a/sw/source/uibase/lingu/hhcwrp.cxx
+++ b/sw/source/uibase/lingu/hhcwrp.cxx
@@ -510,9 +510,7 @@ void SwHHCWrapper::Convert()
         if (pSttPos->GetNode().IsTextNode() &&
             pEndPos->GetNode().IsTextNode())
         {
-            m_pConvArgs.reset( new SwConversionArgs( GetSourceLanguage(),
-                            pSttPos->GetNode().GetTextNode(), 
pSttPos->nContent,
-                            pEndPos->GetNode().GetTextNode(), 
pEndPos->nContent ) );
+            m_pConvArgs.reset( new SwConversionArgs( GetSourceLanguage(), 
*pSttPos, *pEndPos ) );
         }
         else    // we are not in the text (maybe a graphic or OLE object is 
selected) let's start from the top
         {
@@ -526,13 +524,11 @@ void SwHHCWrapper::Convert()
             // just in case we check anyway...
             if (!pTextNode || !pTextNode->IsTextNode())
                 return;
-            m_pConvArgs.reset( new SwConversionArgs( GetSourceLanguage(),
-                            pTextNode, pSttPos->nContent,
-                            pTextNode, pSttPos->nContent ) );
+            m_pConvArgs.reset( new SwConversionArgs( GetSourceLanguage(), 
*pSttPos, *pSttPos ) );
         }
-        OSL_ENSURE( m_pConvArgs->pStartNode && 
m_pConvArgs->pStartNode->IsTextNode(),
+        OSL_ENSURE( m_pConvArgs->pStartPos && 
m_pConvArgs->pStartPos->GetNode().IsTextNode(),
                 "failed to get proper start text node" );
-        OSL_ENSURE( m_pConvArgs->pEndNode && 
m_pConvArgs->pEndNode->IsTextNode(),
+        OSL_ENSURE( m_pConvArgs->pEndPos && 
m_pConvArgs->pEndPos->GetNode().IsTextNode(),
                 "failed to get proper end text node" );
 
         // chinese conversion specific settings
@@ -564,8 +560,8 @@ void SwHHCWrapper::Convert()
                 nStartIdx = 0;
             else
             {
-                OUString aText( m_pConvArgs->pStartNode->GetText() );
-                const sal_Int32 nPos = m_pConvArgs->pStartIdx->GetIndex();
+                OUString aText( 
m_pConvArgs->pStartPos->GetNode().GetTextNode()->GetText() );
+                const sal_Int32 nPos = 
m_pConvArgs->pStartPos->GetContentIndex();
                 Boundary aBoundary( g_pBreakIt->GetBreakIter()->
                         getWordBoundary( aText, nPos, g_pBreakIt->GetLocale( 
m_pConvArgs->nConvSrcLang ),
                                 WordType::DICTIONARY_WORD, true ) );
@@ -579,7 +575,7 @@ void SwHHCWrapper::Convert()
             }
 
             if (nStartIdx != -1)
-                *m_pConvArgs->pStartIdx = nStartIdx;
+                m_pConvArgs->pStartPos->SetContent( nStartIdx );
         }
     }
 

Reply via email to