[Libreoffice-commits] .: sw/source

Nigel Hawkins nhawkins at kemper.freedesktop.org
Wed Feb 16 08:14:20 PST 2011


 sw/source/filter/xml/xmltbli.cxx |  104 ++++++++++++++++++---------------------
 sw/source/filter/xml/xmltbli.hxx |   12 +++-
 2 files changed, 58 insertions(+), 58 deletions(-)

New commits:
commit 02aab4b20b301fc2f527ddccbee7d86637982d2c
Author: Nigel Hawkins <n.hawkins at gmx.com>
Date:   Wed Feb 9 17:48:17 2011 +0000

    Remove some SvArray use in SwXMLTableContext

diff --git a/sw/source/filter/xml/xmltbli.cxx b/sw/source/filter/xml/xmltbli.cxx
index a088ffe..b45cc5d 100644
--- a/sw/source/filter/xml/xmltbli.cxx
+++ b/sw/source/filter/xml/xmltbli.cxx
@@ -1533,15 +1533,14 @@ void SwXMLTableContext::InsertColumn( sal_Int32 nWidth2, sal_Bool bRelWidth2,
         nWidth2 = MINLAY;
     else if( nWidth2 > USHRT_MAX )
         nWidth2 = USHRT_MAX;
-    aColumnWidths.Insert( (sal_uInt16)nWidth2, aColumnWidths.Count() );
-    aColumnRelWidths.Insert( bRelWidth2, aColumnRelWidths.Count() );
+    aColumnWidths.push_back( ColumnWidthInfo(nWidth2, bRelWidth2) );
     if( (pDfltCellStyleName && pDfltCellStyleName->getLength() > 0) ||
         pColumnDefaultCellStyleNames )
     {
         if( !pColumnDefaultCellStyleNames )
         {
             pColumnDefaultCellStyleNames = new SvStringsDtor;
-            sal_uInt16 nCount = aColumnRelWidths.Count() - 1;
+            ULONG nCount = aColumnWidths.size() - 1;
             while( nCount-- )
                 pColumnDefaultCellStyleNames->Insert( new String,
                     pColumnDefaultCellStyleNames->Count() );
@@ -1557,12 +1556,12 @@ sal_Int32 SwXMLTableContext::GetColumnWidth( sal_uInt32 nCol,
                                              sal_uInt32 nColSpan ) const
 {
     sal_uInt32 nLast = nCol+nColSpan;
-    if( nLast > aColumnWidths.Count() )
-        nLast = aColumnWidths.Count();
+    if( nLast > aColumnWidths.size() )
+        nLast = aColumnWidths.size();
 
     sal_Int32 nWidth2 = 0L;
-    for( sal_uInt16 i=(sal_uInt16)nCol; i < nLast; i++ )
-        nWidth2 += aColumnWidths[i];
+    for( sal_uInt32 i=nCol; i < nLast; ++i )
+        nWidth2 += aColumnWidths[i].width;
 
     return nWidth2;
 }
@@ -1643,8 +1642,7 @@ void SwXMLTableContext::InsertCell( const OUString& rStyleName,
     {
         for( i=GetColumnCount(); i<nColsReq; i++ )
         {
-            aColumnWidths.Insert( MINLAY, aColumnWidths.Count() );
-            aColumnRelWidths.Insert( sal_True, aColumnRelWidths.Count() );
+            aColumnWidths.push_back( ColumnWidthInfo(MINLAY, sal_True) );
         }
         // adjust columns in *all* rows, if columns must be inserted
         for( i=0; i<pRows->Count(); i++ )
@@ -2405,7 +2403,7 @@ SwTableLine *SwXMLTableContext::MakeTableLine( SwTableBox *pUpper,
 void SwXMLTableContext::_MakeTable( SwTableBox *pBox )
 {
     // fix column widths
-    sal_uInt32 i;
+    std::vector<ColumnWidthInfo>::iterator colIter;
     sal_uInt32 nCols = GetColumnCount();
 
     // If there are empty rows (because of some row span of previous rows)
@@ -2415,14 +2413,14 @@ void SwXMLTableContext::_MakeTable( SwTableBox *pBox )
     {
         SwXMLTableRow_Impl *pPrevRow = (*pRows)[(sal_uInt16)nCurRow-1U];
         SwXMLTableCell_Impl *pCell;
-        for( i=0UL; i<nCols; i++ )
+        for( ULONG i = 0; i < aColumnWidths.size(); ++i )
         {
             if( ( pCell=pPrevRow->GetCell(i), pCell->GetRowSpan() > 1UL ) )
             {
                 FixRowSpan( nCurRow-1UL, i, 1UL );
             }
         }
-        for( i=(sal_uInt32)pRows->Count()-1UL; i>=nCurRow; i-- )
+        for( ULONG i = pRows->Count()-1UL; i>=nCurRow; --i )
             pRows->DeleteAndDestroy( (sal_uInt16)i );
     }
 
@@ -2432,28 +2430,27 @@ void SwXMLTableContext::_MakeTable( SwTableBox *pBox )
         InsertCell( aStyleName2, 1U, nCols, InsertTableSection() );
     }
 
-    // TODO: Do we have to keep both values, the realtive and the absolute
+    // TODO: Do we have to keep both values, the relative and the absolute
     // width?
     sal_Int32 nAbsWidth = 0L;
     sal_Int32 nMinAbsColWidth = 0L;
     sal_Int32 nRelWidth = 0L;
     sal_Int32 nMinRelColWidth = 0L;
     sal_uInt32 nRelCols = 0UL;
-    for( i=0U; i < nCols; i++ )
+    for( colIter = aColumnWidths.begin(); colIter < aColumnWidths.end(); ++colIter)
     {
-        sal_Int32 nColWidth = aColumnWidths[(sal_uInt16)i];
-        if( aColumnRelWidths[(sal_uInt16)i] )
+        if( colIter->isRelative )
         {
-            nRelWidth += nColWidth;
-            if( 0L == nMinRelColWidth || nColWidth < nMinRelColWidth )
-                nMinRelColWidth = nColWidth;
+            nRelWidth += colIter->width;
+            if( 0L == nMinRelColWidth || colIter->width < nMinRelColWidth )
+                nMinRelColWidth = colIter->width;
             nRelCols++;
         }
         else
         {
-            nAbsWidth += nColWidth;
-            if( 0L == nMinAbsColWidth || nColWidth < nMinAbsColWidth )
-                nMinAbsColWidth = nColWidth;
+            nAbsWidth += colIter->width;
+            if( 0L == nMinAbsColWidth || colIter->width < nMinAbsColWidth )
+                nMinAbsColWidth = colIter->width;
         }
     }
     sal_uInt32 nAbsCols = nCols - nRelCols;
@@ -2472,13 +2469,13 @@ void SwXMLTableContext::_MakeTable( SwTableBox *pBox )
             if( 0L == nMinRelColWidth )
                 nMinRelColWidth = nMinAbsColWidth;
 
-            for( i=0UL; nAbsCols > 0UL && i < nCols; i++ )
+            for( colIter = aColumnWidths.begin(); nAbsCols > 0UL && colIter < aColumnWidths.end(); ++colIter)
             {
-                if( !aColumnRelWidths[(sal_uInt16)i] )
+                if( !colIter->isRelative )
                 {
-                    sal_Int32 nRelCol = (aColumnWidths[(sal_uInt16)i] * nMinRelColWidth) /
-                                   nMinAbsColWidth;
-                    aColumnWidths.Replace( (sal_uInt16)nRelCol, (sal_uInt16)i );
+                    sal_Int32 nRelCol = ( colIter->width * nMinRelColWidth) / nMinAbsColWidth;
+                    colIter->width = nRelCol;
+                    colIter->isRelative = true;
                     nRelWidth += nRelCol;
                     nAbsCols--;
                 }
@@ -2498,14 +2495,13 @@ void SwXMLTableContext::_MakeTable( SwTableBox *pBox )
         {
             double n = (double)nWidth / (double)nRelWidth;
             nRelWidth = 0L;
-            for( i=0U; i < nCols-1UL; i++ )
+            for( colIter = aColumnWidths.begin(); colIter < aColumnWidths.end() - 1; ++colIter)
             {
-                sal_Int32 nW = (sal_Int32)(aColumnWidths[(sal_uInt16)i] * n);
-                aColumnWidths.Replace( (sal_uInt16)nW, (sal_uInt16)i );
+                sal_Int32 nW = (sal_Int32)( colIter->width * n);
+                colIter->width = (USHORT)nW;
                 nRelWidth += nW;
             }
-            aColumnWidths.Replace( (sal_uInt16)(nWidth-nRelWidth),
-                                   (sal_uInt16)nCols-1U );
+            aColumnWidths.back().width = (nWidth-nRelWidth);
         }
     }
     else
@@ -2553,9 +2549,9 @@ void SwXMLTableContext::_MakeTable( SwTableBox *pBox )
             // Otherwise, if there is enouth space for every column, every
             // column gets this space.
 
-            for( i=0UL; nRelCols > 0UL && i < nCols; i++ )
+            for( colIter = aColumnWidths.begin(); nRelCols > 0UL && colIter < aColumnWidths.end(); ++colIter )
             {
-                if( aColumnRelWidths[(sal_uInt16)i] )
+                if( colIter->isRelative )
                 {
                     sal_Int32 nAbsCol;
                     if( 1UL == nRelCols )
@@ -2572,18 +2568,17 @@ void SwXMLTableContext::_MakeTable( SwTableBox *pBox )
                         }
                         else if( bMinExtra )
                         {
-                            sal_Int32 nExtraRelCol =
-                                aColumnWidths[(sal_uInt16)i] - nMinRelColWidth;
+                            sal_Int32 nExtraRelCol = colIter->width - nMinRelColWidth;
                             nAbsCol = MINLAY + (nExtraRelCol * nExtraAbs) /
                                                  nExtraRel;
                         }
                         else
                         {
-                            nAbsCol = (aColumnWidths[(sal_uInt16)i] * nAbsForRelWidth) /
-                                      nRelWidth;
+                            nAbsCol = ( colIter->width * nAbsForRelWidth) / nRelWidth;
                         }
                     }
-                    aColumnWidths.Replace( (sal_uInt16)nAbsCol, (sal_uInt16)i );
+                    colIter->width = nAbsCol;
+                    colIter->isRelative = false;
                     nAbsForRelWidth -= nAbsCol;
                     nAbsWidth += nAbsCol;
                     nRelCols--;
@@ -2595,39 +2590,38 @@ void SwXMLTableContext::_MakeTable( SwTableBox *pBox )
         {
             if( nAbsWidth < nWidth )
             {
-                // If the table's width is larger than the absolute column widths,
-                // every column get some extra width.
+                // If the table's width is larger than the sum of the absolute
+                // column widths, every column get some extra width.
                 sal_Int32 nExtraAbs = nWidth - nAbsWidth;
-                sal_Int32 nAbsLastCol =
-                        aColumnWidths[(sal_uInt16)nCols-1U] + nExtraAbs;
-                for( i=0UL; i < nCols-1UL; i++ )
+                sal_Int32 nAbsLastCol = aColumnWidths.back().width + nExtraAbs;
+                for( colIter = aColumnWidths.begin(); colIter < aColumnWidths.end()-1UL; ++colIter )
                 {
-                    sal_Int32 nAbsCol = aColumnWidths[(sal_uInt16)i];
+                    sal_Int32 nAbsCol = colIter->width;
                     sal_Int32 nExtraAbsCol = (nAbsCol * nExtraAbs) /
                                              nAbsWidth;
                     nAbsCol += nExtraAbsCol;
-                    aColumnWidths.Replace( (sal_uInt16)nAbsCol, (sal_uInt16)i );
+                    colIter->width = nAbsCol;
                     nAbsLastCol -= nExtraAbsCol;
                 }
-                aColumnWidths.Replace( (sal_uInt16)nAbsLastCol, (sal_uInt16)nCols-1U );
+                aColumnWidths.back().width = nAbsLastCol;
             }
             else if( nAbsWidth > nWidth )
             {
-                // If the table's width is smaller than the absolute column
-                // widths, every column gets the minimum width plus some extra
-                // width.
+                // If the table's width is smaller than the sum of the absolute
+                // column widths, every column needs to shrink.
+                // Every column gets the minimum width plus some extra width.
                 sal_Int32 nExtraAbs = nWidth - (nCols * MINLAY);
                 sal_Int32 nAbsLastCol = MINLAY + nExtraAbs;
-                for( i=0UL; i < nCols-1UL; i++ )
+                for( colIter = aColumnWidths.begin(); colIter < aColumnWidths.end()-1UL; ++colIter )
                 {
-                    sal_Int32 nAbsCol = aColumnWidths[(sal_uInt16)i];
+                    sal_Int32 nAbsCol = colIter->width;
                     sal_Int32 nExtraAbsCol = (nAbsCol * nExtraAbs) /
                                              nAbsWidth;
                     nAbsCol = MINLAY + nExtraAbsCol;
-                    aColumnWidths.Replace( (sal_uInt16)nAbsCol, (sal_uInt16)i );
+                    colIter->width = nAbsCol;
                     nAbsLastCol -= nExtraAbsCol;
                 }
-                aColumnWidths.Replace( (sal_uInt16)nAbsLastCol, (sal_uInt16)nCols-1U );
+                aColumnWidths.back().width = nAbsLastCol;
             }
         }
     }
@@ -2638,7 +2632,7 @@ void SwXMLTableContext::_MakeTable( SwTableBox *pBox )
 
     sal_uInt32 nStartRow = 0UL;
     sal_uInt32 nRows = pRows->Count();
-    for( i=0UL; i<nRows; i++ )
+    for(sal_uInt32 i=0UL; i<nRows; ++i )
     {
         // Could we split the table behind the current line?
         sal_Bool bSplit = sal_True;
diff --git a/sw/source/filter/xml/xmltbli.hxx b/sw/source/filter/xml/xmltbli.hxx
index 32622dc..9ad4970 100644
--- a/sw/source/filter/xml/xmltbli.hxx
+++ b/sw/source/filter/xml/xmltbli.hxx
@@ -33,6 +33,7 @@
 
 // STL include
 #include <boost/unordered_map.hpp>
+#include <vector>
 
 #if !defined(_SVSTDARR_USHORTS_DECL) || !defined(_SVSTDARR_BOOLS_DECL) || !defined(_SVSTDARR_STRINGSDTOR_DECL)
 #define _SVSTDARR_USHORTS
@@ -68,8 +69,13 @@ class SwXMLTableContext : public XMLTextTableContext
     /// NB: this contains the xml:id only if this table is a subtable!
     ::rtl::OUString     mXmlId;
 
-    SvUShorts			aColumnWidths;
-    SvBools				aColumnRelWidths;
+    //! Holds basic information about a column's width.
+    struct ColumnWidthInfo {
+        USHORT width;      //!< Column width (absolute or relative).
+        bool   isRelative; //!< True for a relative width, false for absolute.
+        inline ColumnWidthInfo(USHORT wdth, bool isRel) : width(wdth), isRelative(isRel) {};
+    };
+    std::vector<ColumnWidthInfo> aColumnWidths;
     SvStringsDtor		*pColumnDefaultCellStyleNames;
 
     ::com::sun::star::uno::Reference <
@@ -210,7 +216,7 @@ inline SwXMLTableContext *SwXMLTableContext::GetParentTable() const
 
 inline sal_uInt32 SwXMLTableContext::GetColumnCount() const
 {
-    return aColumnWidths.Count();
+    return aColumnWidths.size();
 }
 
 inline const SwStartNode *SwXMLTableContext::GetLastStartNode() const


More information about the Libreoffice-commits mailing list