[Libreoffice-commits] core.git: sw/inc sw/source

Bjoern Michaelsen bjoern.michaelsen at canonical.com
Thu May 19 18:51:56 UTC 2016


 sw/inc/swtable.hxx                  |   15 ++++++---------
 sw/source/core/doc/tblcpy.cxx       |    4 ++--
 sw/source/core/doc/tblrwcl.cxx      |   28 ++++++++++++++--------------
 sw/source/core/fields/cellfml.cxx   |    2 +-
 sw/source/core/frmedt/tblsel.cxx    |   11 ++++-------
 sw/source/core/table/swnewtable.cxx |    2 +-
 sw/source/core/table/swtable.cxx    |    8 +++-----
 sw/source/filter/ww8/wrtw8nds.cxx   |    2 +-
 sw/source/filter/ww8/ww8atr.cxx     |    2 +-
 sw/source/ui/vba/vbatablehelper.cxx |    5 +----
 10 files changed, 34 insertions(+), 45 deletions(-)

New commits:
commit a4ae9b147d0a83b811836757e9634a884260cee8
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Thu May 19 16:15:53 2016 +0200

    tdf#75757: remove inheritance on vector (SwTableBoxes)
    
    - move SwTableBoxes::GetPos(..) up to SwTableLine::GetBoxPos(..)
    - SwTableBoxes is empty over plain vector then, make it an alias
    
    Change-Id: I72420d4fe1042a713d3e82f3df66f18ccbfca3f6
    Reviewed-on: https://gerrit.libreoffice.org/25166
    Reviewed-by: Björn Michaelsen <bjoern.michaelsen at canonical.com>
    Tested-by: Björn Michaelsen <bjoern.michaelsen at canonical.com>

diff --git a/sw/inc/swtable.hxx b/sw/inc/swtable.hxx
index 37d488c..16c8fd4 100644
--- a/sw/inc/swtable.hxx
+++ b/sw/inc/swtable.hxx
@@ -75,15 +75,7 @@ public:
     }
 };
 
-class SwTableBoxes : public std::vector<SwTableBox*> {
-public:
-    // return USHRT_MAX if not found, else index of position
-    sal_uInt16 GetPos(const SwTableBox* pBox) const
-    {
-        const_iterator it = std::find(begin(), end(), pBox);
-        return it == end() ? USHRT_MAX : it - begin();
-    }
-};
+using SwTableBoxes = std::vector<SwTableBox*>;
 
 // Save content-bearing box-pointers additionally in a sorted array
 // (for calculation in table).
@@ -355,6 +347,11 @@ public:
 
           SwTableBoxes &GetTabBoxes() { return m_aBoxes; }
     const SwTableBoxes &GetTabBoxes() const { return m_aBoxes; }
+    sal_uInt16 GetBoxPos(const SwTableBox* pBox) const
+    {
+        SwTableBoxes::const_iterator it = std::find(m_aBoxes.begin(), m_aBoxes.end(), pBox);
+        return it == m_aBoxes.end() ? USHRT_MAX : it - m_aBoxes.begin();
+    }
 
           SwTableBox *GetUpper() { return m_pUpper; }
     const SwTableBox *GetUpper() const { return m_pUpper; }
diff --git a/sw/source/core/doc/tblcpy.cxx b/sw/source/core/doc/tblcpy.cxx
index 41e44f1..5bb7565 100644
--- a/sw/source/core/doc/tblcpy.cxx
+++ b/sw/source/core/doc/tblcpy.cxx
@@ -857,7 +857,7 @@ bool SwTable::InsTable( const SwTable& rCpyTable, const SwSelBoxes& rSelBoxes,
                 SwTableLine* pLastLn = GetTabLines().back();
 
                 SwTableBox* pSttBox = pFLine->GetBoxes()[0]->GetBox();
-                const SwTableBoxes::size_type nSttBox = pFLine->GetLine()->GetTabBoxes().GetPos( pSttBox );
+                const SwTableBoxes::size_type nSttBox = pFLine->GetLine()->GetBoxPos( pSttBox );
                 for( SwTableLines::size_type n = rCpyTable.GetTabLines().size() - nNewLns;
                         n < rCpyTable.GetTabLines().size(); ++n )
                 {
@@ -901,7 +901,7 @@ bool SwTable::InsTable( const SwTable& rCpyTable, const SwSelBoxes& rSelBoxes,
             pFLine = aFndBox.GetLines()[ nLn % nFndCnt ].get();
             SwTableLine* pLine = pFLine->GetLine();
             SwTableBox* pSttBox = pFLine->GetBoxes()[0]->GetBox();
-            const SwTableBoxes::size_type nSttBox = pLine->GetTabBoxes().GetPos( pSttBox );
+            const SwTableBoxes::size_type nSttBox = pLine->GetBoxPos( pSttBox );
             if( nLn >= nFndCnt )
             {
                 // We have more rows in the ClipBoard than we have selected
diff --git a/sw/source/core/doc/tblrwcl.cxx b/sw/source/core/doc/tblrwcl.cxx
index 566457e..c719389 100644
--- a/sw/source/core/doc/tblrwcl.cxx
+++ b/sw/source/core/doc/tblrwcl.cxx
@@ -468,7 +468,7 @@ static void lcl_InsCol( FndLine_* pFndLn, CpyPara& rCpyPara, sal_uInt16 nCpyCnt,
         rCpyPara.pInsLine = pFndLn->GetLine();
         SwTableBox* pBox = pFndLn->GetBoxes()[ bBehind ?
                     pFndLn->GetBoxes().size()-1 : 0 ]->GetBox();
-        rCpyPara.nInsPos = pFndLn->GetLine()->GetTabBoxes().GetPos( pBox );
+        rCpyPara.nInsPos = pFndLn->GetLine()->GetBoxPos( pBox );
         if( bBehind )
             ++rCpyPara.nInsPos;
 
@@ -702,7 +702,7 @@ void DeleteBox_( SwTable& rTable, SwTableBox* pBox, SwUndo* pUndo,
                 pBox->GetFrameFormat()->GetFrameSize().GetWidth() : 0;
         SwTableLine* pLine = pBox->GetUpper();
         SwTableBoxes& rTableBoxes = pLine->GetTabBoxes();
-        sal_uInt16 nDelPos = rTableBoxes.GetPos( pBox );
+        sal_uInt16 nDelPos = pLine->GetBoxPos( pBox );
         SwTableBox* pUpperBox = pBox->GetUpper()->GetUpper();
 
         // Special treatment for the border:
@@ -912,7 +912,7 @@ lcl_SaveUpperLowerBorder( SwTable& rTable, const SwTableBox& rBox,
     const SwTableLine* pLine = rBox.GetUpper();
     const SwTableBoxes& rTableBoxes = pLine->GetTabBoxes();
     const SwTableBox* pUpperBox = &rBox;
-    sal_uInt16 nDelPos = rTableBoxes.GetPos( pUpperBox );
+    sal_uInt16 nDelPos = pLine->GetBoxPos( pUpperBox );
     pUpperBox = rBox.GetUpper()->GetUpper();
     const SvxBoxItem& rBoxItem = rBox.GetFrameFormat()->GetBox();
 
@@ -1105,7 +1105,7 @@ bool SwTable::OldSplitRow( SwDoc* pDoc, const SwSelBoxes& rBoxes, sal_uInt16 nCn
                              (nCnt + 1) );
 
         SwTableBox* pNewBox = new SwTableBox( pFrameFormat, nCnt, pInsLine );
-        sal_uInt16 nBoxPos = pInsLine->GetTabBoxes().GetPos( pSelBox );
+        sal_uInt16 nBoxPos = pInsLine->GetBoxPos( pSelBox );
         pInsLine->GetTabBoxes()[nBoxPos] = pNewBox; // overwrite old one
 
         // Delete background/border attribute
@@ -1226,7 +1226,7 @@ bool SwTable::SplitCol( SwDoc* pDoc, const SwSelBoxes& rBoxes, sal_uInt16 nCnt )
 
         // Then split the nCnt Box up into nCnt Boxes
         SwTableLine* pInsLine = pSelBox->GetUpper();
-        sal_uInt16 nBoxPos = pInsLine->GetTabBoxes().GetPos( pSelBox );
+        sal_uInt16 nBoxPos = pInsLine->GetBoxPos( pSelBox );
 
         // Find the Frame Format in the Frame Format Array
         SwTableBoxFormat* pLastBoxFormat;
@@ -1402,12 +1402,12 @@ static void lcl_Merge_MoveBox(FndBox_ & rFndBox, InsULPara *const pULPara)
         if( pULPara->bUL )  // Left ?
         {
             // if there are Boxes before it, move them
-            if( 0 != ( nPos = pBoxes->GetPos( pFndTableBox ) ) )
+            if( 0 != ( nPos = pFndTableBox->GetUpper()->GetBoxPos( pFndTableBox ) ) )
                 lcl_CpyBoxes( 0, nPos, *pBoxes, pULPara->pInsLine );
         }
         else                // Right
             // if there are Boxes behind it, move them
-            if( (nPos = pBoxes->GetPos( pFndTableBox )) +1 < (sal_uInt16)pBoxes->size() )
+            if( (nPos = pFndTableBox->GetUpper()->GetBoxPos( pFndTableBox )) +1 < (sal_uInt16)pBoxes->size() )
             {
                 nInsPos = pULPara->pInsLine->GetTabBoxes().size();
                 lcl_CpyBoxes( nPos+1, pBoxes->size(),
@@ -1465,8 +1465,8 @@ static void lcl_Merge_MoveLine(FndLine_& rFndLine, InsULPara *const pULPara)
 
         SwTableBox* pLBx = rFndLine.GetBoxes().front()->GetBox();
         SwTableBox* pRBx = rFndLine.GetBoxes().back()->GetBox();
-        sal_uInt16 nLeft = pFndLn->GetTabBoxes().GetPos( pLBx );
-        sal_uInt16 nRight = pFndLn->GetTabBoxes().GetPos( pRBx );
+        sal_uInt16 nLeft = pFndLn->GetBoxPos( pLBx );
+        sal_uInt16 nRight = pFndLn->GetBoxPos( pRBx );
 
         if( !nLeft || nRight == pFndLn->GetTabBoxes().size() )
         {
@@ -2216,7 +2216,7 @@ SwTableBox* SwTableLine::FindNextBox( const SwTable& rTable,
     SwTableBox* pBox;
     sal_uInt16 nFndPos;
     if( !GetTabBoxes().empty() && pSrchBox &&
-        USHRT_MAX != ( nFndPos = GetTabBoxes().GetPos( pSrchBox )) &&
+        USHRT_MAX != ( nFndPos = GetBoxPos( pSrchBox )) &&
         nFndPos + 1 != (sal_uInt16)GetTabBoxes().size() )
     {
         pBox = GetTabBoxes()[ nFndPos + 1 ];
@@ -2264,7 +2264,7 @@ SwTableBox* SwTableLine::FindPreviousBox( const SwTable& rTable,
     SwTableBox* pBox;
     sal_uInt16 nFndPos;
     if( !GetTabBoxes().empty() && pSrchBox &&
-        USHRT_MAX != ( nFndPos = GetTabBoxes().GetPos( pSrchBox )) &&
+        USHRT_MAX != ( nFndPos = GetBoxPos( pSrchBox )) &&
         nFndPos )
     {
         pBox = GetTabBoxes()[ nFndPos - 1 ];
@@ -2354,7 +2354,7 @@ static SwTwips lcl_GetDistance( SwTableBox* pBox, bool bLeft )
     SwTableLine* pLine;
     while( pBox && nullptr != ( pLine = pBox->GetUpper() ) )
     {
-        sal_uInt16 nStt = 0, nPos = pLine->GetTabBoxes().GetPos( pBox );
+        sal_uInt16 nStt = 0, nPos = pLine->GetBoxPos( pBox );
 
         if( bFirst && !bLeft )
             ++nPos;
@@ -2767,7 +2767,7 @@ static bool lcl_InsOtherBox( SwTableLine* pLine, CR_SetBoxWidth& rParam,
                         while( !nBoxPos && pTmpBox->GetUpper()->GetUpper() )
                         {
                             pTmpBox = pTmpBox->GetUpper()->GetUpper();
-                            nBoxPos = pTmpBox->GetUpper()->GetTabBoxes().GetPos( pTmpBox );
+                            nBoxPos = pTmpBox->GetUpper()->GetBoxPos( pTmpBox );
                         }
                         nTmpWidth = pTmpBox->GetFrameFormat()->GetFrameSize().GetWidth();
                     }
@@ -3760,7 +3760,7 @@ bool SwTable::SetColWidth( SwTableBox& rAktBox, sal_uInt16 eType,
             SwTableLine* pLine = rAktBox.GetUpper();
             while( pLine->GetUpper() )
             {
-                const SwTableBoxes::size_type nPos = pLine->GetTabBoxes().GetPos( pBox );
+                const SwTableBoxes::size_type nPos = pLine->GetBoxPos( pBox );
                 if( bLeft ? nPos != 0 : nPos + 1 != pLine->GetTabBoxes().size() )
                     break;
 
diff --git a/sw/source/core/fields/cellfml.cxx b/sw/source/core/fields/cellfml.cxx
index a2f4d50..bbb33f9 100644
--- a/sw/source/core/fields/cellfml.cxx
+++ b/sw/source/core/fields/cellfml.cxx
@@ -776,7 +776,7 @@ static const SwTableBox* lcl_RelToBox( const SwTable& rTable,
             pBox = pLine->GetUpper();
             pLine = pBox->GetUpper();
         }
-        sal_uInt16 nSttBox = pLine->GetTabBoxes().GetPos( pBox );
+        sal_uInt16 nSttBox = pLine->GetBoxPos( pBox );
         sal_uInt16 nSttLine = rTable.GetTabLines().GetPos( pLine );
 
         const sal_Int32 nBoxOffset = lcl_GetLongBoxNum( sGetName ) + nSttBox;
diff --git a/sw/source/core/frmedt/tblsel.cxx b/sw/source/core/frmedt/tblsel.cxx
index 16a9531..e07b72e 100644
--- a/sw/source/core/frmedt/tblsel.cxx
+++ b/sw/source/core/frmedt/tblsel.cxx
@@ -968,8 +968,7 @@ void GetMergeSel( const SwPaM& rPam, SwSelBoxes& rBoxes,
                         {
                             if( ( rUnion.Right() + COLFUZZY ) < pCell->Frame().Right() )
                             {
-                                sal_uInt16 nInsPos = pBox->GetUpper()->
-                                                    GetTabBoxes().GetPos( pBox )+1;
+                                sal_uInt16 nInsPos = pBox->GetUpper()->GetBoxPos( pBox )+1;
                                 lcl_InsTableBox( pTableNd, pDoc, pBox, nInsPos );
                                 pBox->ClaimFrameFormat();
                                 SwFormatFrameSize aNew(
@@ -1009,8 +1008,7 @@ void GetMergeSel( const SwPaM& rPam, SwSelBoxes& rBoxes,
                         else if( ( rUnion.Left() - COLFUZZY ) >= pCell->Frame().Left() &&
                                 ( rUnion.Right() + COLFUZZY ) < pCell->Frame().Right() )
                         {
-                            sal_uInt16 nInsPos = pBox->GetUpper()->GetTabBoxes().GetPos(
-                                            pBox )+1;
+                            sal_uInt16 nInsPos = pBox->GetUpper()->GetBoxPos( pBox )+1;
                             lcl_InsTableBox( pTableNd, pDoc, pBox, nInsPos, 2 );
                             pBox->ClaimFrameFormat();
                             SwFormatFrameSize aNew(
@@ -1066,8 +1064,7 @@ void GetMergeSel( const SwPaM& rPam, SwSelBoxes& rBoxes,
                                  ( pCell->Frame().Left() + COLFUZZY ) < rUnion.Left() )
                         {
                             // then we should insert a new box and adjust the widths
-                            sal_uInt16 nInsPos = pBox->GetUpper()->GetTabBoxes().GetPos(
-                                            pBox )+1;
+                            sal_uInt16 nInsPos = pBox->GetUpper()->GetBoxPos( pBox )+1;
                             lcl_InsTableBox( pTableNd, pDoc, pBox, nInsPos );
 
                             SwFormatFrameSize aNew(pBox->GetFrameFormat()->GetFrameSize() );
@@ -1301,7 +1298,7 @@ void GetMergeSel( const SwPaM& rPam, SwSelBoxes& rBoxes,
     {
         SwTableBox* pTmpBox = rBoxes[0];
         SwTableLine* pInsLine = pTmpBox->GetUpper();
-        sal_uInt16 nInsPos = pInsLine->GetTabBoxes().GetPos( pTmpBox );
+        sal_uInt16 nInsPos = pInsLine->GetBoxPos( pTmpBox );
 
         lcl_InsTableBox( pTableNd, pDoc, pTmpBox, nInsPos );
         (*ppMergeBox) = pInsLine->GetTabBoxes()[ nInsPos ];
diff --git a/sw/source/core/table/swnewtable.cxx b/sw/source/core/table/swnewtable.cxx
index 2f4038e..a456fdc 100644
--- a/sw/source/core/table/swnewtable.cxx
+++ b/sw/source/core/table/swnewtable.cxx
@@ -616,7 +616,7 @@ static long lcl_InsertPosition( SwTable &rTable, std::vector<sal_uInt16>& rInsPo
         SwTableLine* pLine = pBox->GetUpper();
         long nWidth = rBoxes[j]->GetFrameFormat()->GetFrameSize().GetWidth();
         nAddWidth += nWidth;
-        sal_uInt16 nCurrBox = pLine->GetTabBoxes().GetPos( pBox );
+        sal_uInt16 nCurrBox = pLine->GetBoxPos( pBox );
         sal_uInt16 nCurrLine = rTable.GetTabLines().GetPos( pLine );
         OSL_ENSURE( nCurrLine != USHRT_MAX, "Time to say Good-Bye.." );
         if( rInsPos[ nCurrLine ] == USHRT_MAX )
diff --git a/sw/source/core/table/swtable.cxx b/sw/source/core/table/swtable.cxx
index 3f997d7..3360692 100644
--- a/sw/source/core/table/swtable.cxx
+++ b/sw/source/core/table/swtable.cxx
@@ -736,8 +736,8 @@ static void lcl_ProcessBoxSet( SwTableBox *pBox, Parm &rParm )
 
         if( pBox->getRowSpan() == 1 )
         {
+            const sal_uInt16 nPos = pBox->GetUpper()->GetBoxPos( pBox );
             SwTableBoxes& rTableBoxes = pBox->GetUpper()->GetTabBoxes();
-            const sal_uInt16 nPos = rTableBoxes.GetPos( pBox );
             if( nPos && rTableBoxes[ nPos - 1 ]->getRowSpan() != 1 )
                 nLeftDiff = 0;
             if( nPos + 1 < (sal_uInt16)rTableBoxes.size() &&
@@ -1827,14 +1827,13 @@ Point SwTableBox::GetCoordinates() const
     sal_uInt16 nX, nY;
     const SwTableBox* pBox = this;
     do {
-        const SwTableBoxes* pBoxes = &pBox->GetUpper()->GetTabBoxes();
         const SwTableLine* pLine = pBox->GetUpper();
         // at the first level?
         const SwTableLines* pLines = pLine->GetUpper()
                 ? &pLine->GetUpper()->GetTabLines() : &rTable.GetTabLines();
 
         nY = pLines->GetPos( pLine ) + 1 ;
-        nX = pBoxes->GetPos( pBox ) + 1 ;
+        nX = pBox->GetUpper()->GetBoxPos( pBox ) + 1;
         pBox = pLine->GetUpper();
     } while( pBox );
     return Point( nX, nY );
@@ -1853,7 +1852,6 @@ OUString SwTableBox::GetName() const
     OUString sNm, sTmp;
     const SwTableBox* pBox = this;
     do {
-        const SwTableBoxes* pBoxes = &pBox->GetUpper()->GetTabBoxes();
         const SwTableLine* pLine = pBox->GetUpper();
         // at the first level?
         const SwTableLines* pLines = pLine->GetUpper()
@@ -1865,7 +1863,7 @@ OUString SwTableBox::GetName() const
         else
             sNm = sTmp;
 
-        sTmp = OUString::number(( nPos = pBoxes->GetPos( pBox )) + 1 );
+        sTmp = OUString::number(( nPos = pBox->GetUpper()->GetBoxPos( pBox )) + 1 );
         if( nullptr != ( pBox = pLine->GetUpper()) )
             sNm = sTmp + "." + sNm;
         else
diff --git a/sw/source/filter/ww8/wrtw8nds.cxx b/sw/source/filter/ww8/wrtw8nds.cxx
index 3152878..cb57189 100644
--- a/sw/source/filter/ww8/wrtw8nds.cxx
+++ b/sw/source/filter/ww8/wrtw8nds.cxx
@@ -2698,7 +2698,7 @@ void MSWordExportBase::OutputTextNode( const SwTextNode& rNode )
                     if ( pLine && !pLine->GetUpper() )
                     {
                         // check if box is first in that line:
-                        if ( 0 == pLine->GetTabBoxes().GetPos( pBox ) && pBox->GetSttNd() )
+                        if ( 0 == pLine->GetBoxPos( pBox ) && pBox->GetSttNd() )
                         {
                             // check if paragraph is first in that line:
                             if ( 1 == ( rNode.GetIndex() - pBox->GetSttNd()->GetIndex() ) )
diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx
index 5cd5297..ebd51df 100644
--- a/sw/source/filter/ww8/ww8atr.cxx
+++ b/sw/source/filter/ww8/ww8atr.cxx
@@ -464,7 +464,7 @@ void MSWordExportBase::OutputSectionBreaks( const SfxItemSet *pSet, const SwNode
                     if ( pLine && !pLine->GetUpper() )
                     {
                         // check if box is not first in that line:
-                        if ( 0 < pLine->GetTabBoxes().GetPos( pBox ) && pBox->GetSttNd() )
+                        if ( 0 < pLine->GetBoxPos( pBox ) && pBox->GetSttNd() )
                         {
                             bRemoveHardBreakInsideTable = true;
                         }
diff --git a/sw/source/ui/vba/vbatablehelper.cxx b/sw/source/ui/vba/vbatablehelper.cxx
index 7ba020d..62b81ae 100644
--- a/sw/source/ui/vba/vbatablehelper.cxx
+++ b/sw/source/ui/vba/vbatablehelper.cxx
@@ -87,13 +87,10 @@ sal_Int32 SwVbaTableHelper::getTabRowIndex( const OUString& rCellName ) throw (u
 
 sal_Int32 SwVbaTableHelper::getTabColIndex( const OUString& rCellName ) throw (uno::RuntimeException)
 {
-    sal_Int32 nRet = 0;
     const SwTableBox* pBox = pTable->GetTableBox( rCellName );
     if( !pBox )
         throw uno::RuntimeException();
-    const SwTableBoxes* pBoxes = &pBox->GetUpper()->GetTabBoxes();
-    nRet = pBoxes->GetPos( pBox );
-    return nRet;
+    return pBox->GetUpper()->GetBoxPos( pBox );
 }
 
 OUString SwVbaTableHelper::getColumnStr( sal_Int32 nCol )


More information about the Libreoffice-commits mailing list