[Libreoffice-commits] .: sc/inc sc/source

Joseph Powers jpowers at kemper.freedesktop.org
Fri Dec 10 05:55:37 PST 2010


 sc/inc/nameuno.hxx                   |    4 
 sc/inc/rangelst.hxx                  |   48 ++--
 sc/source/core/data/documen3.cxx     |   43 ++--
 sc/source/core/tool/compiler.cxx     |   42 ++--
 sc/source/core/tool/rangelst.cxx     |  359 ++++++++++++++++++++---------------
 sc/source/filter/excel/xecontent.cxx |   19 -
 sc/source/ui/miscdlgs/crnrdlg.cxx    |    8 
 sc/source/ui/unoobj/nameuno.cxx      |   14 -
 8 files changed, 306 insertions(+), 231 deletions(-)

New commits:
commit bbd8580ba94a50590d0c02985024e55def2d1100
Author: Joseph Powers <jpowers27 at cox.net>
Date:   Thu Dec 9 22:21:29 2010 -0800

    Remove DECLARE_LIST( ScRangePairList )

diff --git a/sc/inc/nameuno.hxx b/sc/inc/nameuno.hxx
index f691c9f..ea72e38 100644
--- a/sc/inc/nameuno.hxx
+++ b/sc/inc/nameuno.hxx
@@ -2,7 +2,7 @@
 /*************************************************************************
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- * 
+ *
  * Copyright 2000, 2010 Oracle and/or its affiliates.
  *
  * OpenOffice.org - a multi-platform office productivity suite
@@ -355,7 +355,7 @@ private:
     ScDocShell*				pDocShell;
     sal_Bool					bColumn;
 
-    ScLabelRangeObj*		GetObjectByIndex_Impl(sal_uInt16 nIndex);
+    ScLabelRangeObj*		GetObjectByIndex_Impl(size_t nIndex);
 
 public:
                             ScLabelRangesObj(ScDocShell* pDocSh, sal_Bool bCol);
diff --git a/sc/inc/rangelst.hxx b/sc/inc/rangelst.hxx
index ebc957e..620921b 100644
--- a/sc/inc/rangelst.hxx
+++ b/sc/inc/rangelst.hxx
@@ -2,7 +2,7 @@
 /*************************************************************************
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- * 
+ *
  * Copyright 2000, 2010 Oracle and/or its affiliates.
  *
  * OpenOffice.org - a multi-platform office productivity suite
@@ -47,7 +47,7 @@ public:
     void			Append( const ScRange& rRange )
                     {
                         ScRangePtr pR = new ScRange( rRange );
-                        push_back( pR );
+                        maRanges.push_back( pR );
                     }
 
     USHORT			Parse( const String&, ScDocument* = NULL,
@@ -99,29 +99,35 @@ SV_DECL_IMPL_REF( ScRangeList );
 
 // RangePairList: erster Range (aRange[0]) eigentlicher Range, zweiter
 // Range (aRange[1]) Daten zu diesem Range, z.B. Rows eines ColName
-DECLARE_LIST( ScRangePairListBase, ScRangePair* )
-class ScRangePairList : public ScRangePairListBase, public SvRefBase
+class ScRangePairList : public SvRefBase
 {
-private:
-    using ScRangePairListBase::operator==;
-
 public:
-    virtual 		~ScRangePairList();
-    ScRangePairList*	Clone() const;
-    void			Append( const ScRangePair& rRangePair )
-                    {
-                        ScRangePair* pR = new ScRangePair( rRangePair );
-                        Insert( pR, LIST_APPEND );
-                    }
-    void			Join( const ScRangePair&, BOOL bIsInList = FALSE );
-    BOOL 			UpdateReference( UpdateRefMode, ScDocument*,
+    virtual             ~ScRangePairList();
+    ScRangePairList*    Clone() const;
+    void                Append( const ScRangePair& rRangePair )
+                        {
+                            ScRangePair* pR = new ScRangePair( rRangePair );
+                            maPairs.push_back( pR );
+                        }
+    void			    Join( const ScRangePair&, bool bIsInList = false );
+    bool                UpdateReference( UpdateRefMode, ScDocument*,
                                     const ScRange& rWhere,
                                     SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
-    void            DeleteOnTab( SCTAB nTab );
-    ScRangePair*	Find( const ScAddress& ) const;
-    ScRangePair*	Find( const ScRange& ) const;
-    ScRangePair**	CreateNameSortedArray( ULONG& nCount, ScDocument* ) const;
-    BOOL			operator==( const ScRangePairList& ) const;
+    void                DeleteOnTab( SCTAB nTab );
+    ScRangePair*        Find( const ScAddress& ) const;
+    ScRangePair*        Find( const ScRange& ) const;
+    ScRangePair**       CreateNameSortedArray( size_t& nCount, ScDocument* ) const;
+    bool                operator==( const ScRangePairList& ) const;
+
+    ScRangePair*        Remove(size_t nPos);
+    ScRangePair*        Remove(ScRangePair* pAdr);
+
+    size_t              size() const;
+    ScRangePair*        at( size_t idx );
+    const ScRangePair*  operator[](size_t idx) const;
+
+private:
+    ::std::vector< ScRangePair* > maPairs;
 };
 SV_DECL_IMPL_REF( ScRangePairList );
 
diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx
index 8b8a1b0..af972c0 100644
--- a/sc/source/core/data/documen3.cxx
+++ b/sc/source/core/data/documen3.cxx
@@ -2,7 +2,7 @@
 /*************************************************************************
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- * 
+ *
  * Copyright 2000, 2010 Oracle and/or its affiliates.
  *
  * OpenOffice.org - a multi-platform office productivity suite
@@ -1443,16 +1443,14 @@ BOOL ScDocument::GetDataEntries( SCCOL nCol, SCROW nRow, SCTAB nTab,
 
 BOOL ScDocument::GetFormulaEntries( TypedScStrCollection& rStrings )
 {
-    USHORT i;
-
     //
     //	Bereichsnamen
     //
 
     if ( pRangeName )
     {
-        USHORT nRangeCount = pRangeName->GetCount();
-        for ( i=0; i<nRangeCount; i++ )
+        sal_uInt16 nRangeCount = pRangeName->GetCount();
+        for ( sal_uInt16 i = 0; i < nRangeCount; i++ )
         {
             ScRangeData* pData = (*pRangeName)[i];
             if (pData)
@@ -1470,8 +1468,8 @@ BOOL ScDocument::GetFormulaEntries( TypedScStrCollection& rStrings )
 
     if ( pDBCollection )
     {
-        USHORT nDBCount = pDBCollection->GetCount();
-        for ( i=0; i<nDBCount; i++ )
+        sal_uInt16 nDBCount = pDBCollection->GetCount();
+        for ( sal_uInt16 i=0; i<nDBCount; i++ )
         {
             ScDBData* pData = (*pDBCollection)[i];
             if (pData)
@@ -1492,10 +1490,11 @@ BOOL ScDocument::GetFormulaEntries( TypedScStrCollection& rStrings )
     pLists[1] = GetRowNameRanges();
     for (USHORT nListNo=0; nListNo<2; nListNo++)
     {
-        ScRangePairList* pList = pLists[nListNo];
+        ScRangePairList* pList = pLists[ nListNo ];
         if (pList)
-            for ( ScRangePair* pPair = pList->First(); pPair; pPair = pList->Next() )
+            for ( size_t i = 0, nPairs = pList->size(); i < nPairs; ++i )
             {
+                ScRangePair* pPair = pList->at( i );
                 ScRange aRange = pPair->GetRange(0);
                 ScCellIterator aIter( this, aRange );
                 for ( ScBaseCell* pCell = aIter.GetFirst(); pCell; pCell = aIter.GetNext() )
@@ -1565,7 +1564,7 @@ void ScDocument::ResetEmbedded()
 }
 
 
-/** Similar to ScViewData::AddPixelsWhile(), but add height twips and only 
+/** Similar to ScViewData::AddPixelsWhile(), but add height twips and only
     while result is less than nStopTwips.
     @return TRUE if advanced at least one row.
  */
@@ -1722,7 +1721,7 @@ void lcl_SnapVer( ScTable* pTable, long& rVal, SCROW& rStartRow )
         SCROW nLastRow;
         if (pTable->RowHidden(i, NULL, &nLastRow))
         {
-            i = nLastRow;    
+            i = nLastRow;
             continue;
         }
 
@@ -1735,7 +1734,7 @@ void lcl_SnapVer( ScTable* pTable, long& rVal, SCROW& rStartRow )
         }
         else
         {
-            bFound = true;    
+            bFound = true;
             break;
         }
     }
@@ -2037,7 +2036,7 @@ void ScDocument::DecSizeRecalcLevel( SCTAB nTab, bool bUpdateNoteCaptionPos )
 
 // Wang Xu Ming -- 2009-8-17
 // DataPilot Migration - Cache&&Performance
-ScDPTableDataCache* ScDocument::GetDPObjectCache( long nID ) 
+ScDPTableDataCache* ScDocument::GetDPObjectCache( long nID )
 {
     for ( std::list<ScDPTableDataCache*>::iterator iter = m_listDPObjectsCaches.begin(); iter!=m_listDPObjectsCaches.end(); ++iter )
     { //
@@ -2047,7 +2046,7 @@ ScDPTableDataCache* ScDocument::GetDPObjectCache( long nID )
     return NULL;
 }
 
-ScDPTableDataCache* ScDocument::GetUsedDPObjectCache ( ScRange rRange ) 
+ScDPTableDataCache* ScDocument::GetUsedDPObjectCache ( ScRange rRange )
 {
     ScDPTableDataCache* pCache = NULL;
     USHORT nCount = GetDPCollection()->GetCount();
@@ -2067,7 +2066,7 @@ ScDPTableDataCache* ScDocument::GetUsedDPObjectCache ( ScRange rRange )
 }
 
 long ScDocument::AddDPObjectCache( ScDPTableDataCache* pData )
-{ 
+{
     if ( pData->GetId() < 0 )
     { //create a id for it
         pData->SetId( GetNewDPObjectCacheId() );
@@ -2102,10 +2101,10 @@ long ScDocument::GetNewDPObjectCacheId()
 void ScDocument::RemoveDPObjectCache( long nID )
 {
     for ( std::list<ScDPTableDataCache*>::iterator iter = m_listDPObjectsCaches.begin(); iter!=m_listDPObjectsCaches.end(); ++iter )
-    { 
+    {
         if ( nID == (*iter)->GetId() )
         {
-            ScDPTableDataCache* pCache = *iter; 
+            ScDPTableDataCache* pCache = *iter;
             m_listDPObjectsCaches.erase( iter );
             delete pCache;
             break;
@@ -2115,9 +2114,9 @@ void ScDocument::RemoveDPObjectCache( long nID )
 }
 
 void ScDocument::RemoveUnusedDPObjectCaches()
-{ 
+{
     for ( std::list<ScDPTableDataCache*>::iterator iter = m_listDPObjectsCaches.begin(); iter!=m_listDPObjectsCaches.end(); ++iter )
-    { 
+    {
         long  nID = (*iter)->GetId();
         USHORT nCount = GetDPCollection()->GetCount();
         USHORT i ;
@@ -2128,7 +2127,7 @@ void ScDocument::RemoveUnusedDPObjectCaches()
         }
         if ( i == nCount )
         {
-            ScDPTableDataCache* pCache = *iter; 
+            ScDPTableDataCache* pCache = *iter;
             m_listDPObjectsCaches.erase( iter );
             delete pCache;
             continue;
@@ -2139,10 +2138,10 @@ void ScDocument::RemoveUnusedDPObjectCaches()
 void ScDocument::GetUsedDPObjectCache( std::list<ScDPTableDataCache*>& usedlist )
 {
     for ( std::list<ScDPTableDataCache*>::iterator iter = m_listDPObjectsCaches.begin(); iter!=m_listDPObjectsCaches.end(); ++iter )
-    { 
+    {
         long  nID = (*iter)->GetId();
         USHORT nCount = GetDPCollection()->GetCount();
-        USHORT i=0; 
+        USHORT i=0;
         for ( i=0; i<nCount; i++)
             if ( nID ==  (*pDPCollection)[i]->GetCacheId() )
                 break;
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index 8171d23..f9da403 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -2,7 +2,7 @@
 /*************************************************************************
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- * 
+ *
  * Copyright 2000, 2010 Oracle and/or its affiliates.
  *
  * OpenOffice.org - a multi-platform office productivity suite
@@ -2485,7 +2485,7 @@ Label_MaskStateMachine:
     }
     if (mnRangeOpPosInSymbol >= 0 && mnRangeOpPosInSymbol == (pSym-1) - &cSymbol[0])
     {
-        // This is a trailing range operator, which is nonsense. Will be caught 
+        // This is a trailing range operator, which is nonsense. Will be caught
         // in next round.
         mnRangeOpPosInSymbol = -1;
         *--pSym = 0;
@@ -2522,10 +2522,10 @@ BOOL ScCompiler::IsOpCode( const String& rName, bool bInArray )
     }
     else if (mxSymbols->isODFF())
     {
-        // ODFF names that are not written in the current mapping but to be 
-        // recognized. New names will be written in a future relase, then 
-        // exchange (!) with the names in 
-        // formula/source/core/resource/core_resource.src to be able to still 
+        // ODFF names that are not written in the current mapping but to be
+        // recognized. New names will be written in a future relase, then
+        // exchange (!) with the names in
+        // formula/source/core/resource/core_resource.src to be able to still
         // read the old names as well.
         struct FunctionName
         {
@@ -2903,7 +2903,7 @@ BOOL ScCompiler::IsReference( const String& rName )
     {
         if (IsDoubleReference( rName))
             return true;
-        // Now try with a symbol up to the range operator, rewind source 
+        // Now try with a symbol up to the range operator, rewind source
         // position.
         sal_Int32 nLen = mnRangeOpPosInSymbol;
         while (cSymbol[++nLen])
@@ -2916,8 +2916,8 @@ BOOL ScCompiler::IsReference( const String& rName )
     }
     else
     {
-        // Special treatment for the 'E:\[doc]Sheet1:Sheet3'!D5 Excel sickness, 
-        // mnRangeOpPosInSymbol did not catch the range operator as it is 
+        // Special treatment for the 'E:\[doc]Sheet1:Sheet3'!D5 Excel sickness,
+        // mnRangeOpPosInSymbol did not catch the range operator as it is
         // within a quoted name.
         switch (pConv->meConv)
         {
@@ -2948,9 +2948,9 @@ BOOL ScCompiler::IsMacro( const String& rName )
     else
         pObj = pSfxApp->GetBasic();
 
-    // ODFF recommends to store user-defined functions prefixed with "USER.", 
-    // use only unprefixed name if encountered. BASIC doesn't allow '.' in a 
-    // function name so a function "USER.FOO" could not exist, and macro check 
+    // ODFF recommends to store user-defined functions prefixed with "USER.",
+    // use only unprefixed name if encountered. BASIC doesn't allow '.' in a
+    // function name so a function "USER.FOO" could not exist, and macro check
     // is assigned the lowest priority in function name check.
     if (FormulaGrammar::isODFF( GetGrammar()) && aName.EqualsIgnoreCaseAscii( "USER.", 0, 5))
         aName.Erase( 0, 5);
@@ -3066,8 +3066,9 @@ BOOL ScCompiler::IsColRowName( const String& rName )
                 pRL = pDoc->GetColNameRanges();
             else
                 pRL = pDoc->GetRowNameRanges();
-            for ( ScRangePair* pR = pRL->First(); pR && !bInList; pR = pRL->Next() )
+            for ( size_t iPair = 0, nPairs = pRL->size(); iPair < nPairs && !bInList; ++iPair )
             {
+                ScRangePair* pR = pRL->at( iPair );
                 const ScRange& rNameRange = pR->GetRange(0);
                 if ( jThisTab && !(rNameRange.aStart.Tab() <= nThisTab &&
                         nThisTab <= rNameRange.aEnd.Tab()) )
@@ -3550,7 +3551,7 @@ inline bool lcl_UpperAsciiOrI18n( String& rUpper, const String& rOrg, FormulaGra
 {
     if (FormulaGrammar::isODFF( eGrammar ))
     {
-        // ODFF has a defined set of English function names, avoid i18n 
+        // ODFF has a defined set of English function names, avoid i18n
         // overhead.
         rUpper = rOrg;
         rUpper.ToUpperAscii();
@@ -3711,8 +3712,8 @@ BOOL ScCompiler::NextNewToken( bool bInArray )
         return false;
     }
 
-    // Provide single token information and continue. Do not set an error, that 
-    // would prematurely end compilation. Simple unknown names are handled by 
+    // Provide single token information and continue. Do not set an error, that
+    // would prematurely end compilation. Simple unknown names are handled by
     // the interpreter.
     ScGlobal::pCharClass->toLower( aUpper );
     ScRawToken aToken;
@@ -5262,8 +5263,9 @@ BOOL ScCompiler::HandleSingleRef()
     ScRangePairList* pRL = (bColName ?
         pDoc->GetColNameRanges() : pDoc->GetRowNameRanges());
     ScRange aRange;
-    for ( ScRangePair* pR = pRL->First(); pR; pR = pRL->Next() )
+    for ( size_t i = 0, nPairs = pRL->size(); i < nPairs; ++i )
     {
+        ScRangePair* pR = pRL->at( i );
         if ( pR->GetRange(0).In( aLook ) )
         {
             bInList = bValidName = TRUE;
@@ -5308,8 +5310,9 @@ BOOL ScCompiler::HandleSingleRef()
                         nMaxRow = nMyRow - 1;
                     }
                 }
-                for ( ScRangePair* pR = pRL->First(); pR; pR = pRL->Next() )
+                for ( size_t i = 0, nPairs = pRL->size(); i < nPairs; ++i )
                 {   // next defined ColNameRange below limits row
+                    ScRangePair* pR = pRL->at( i );
                     const ScRange& rRange = pR->GetRange(1);
                     if ( rRange.aStart.Col() <= nCol && nCol <= rRange.aEnd.Col() )
                     {   // identical column range
@@ -5340,8 +5343,9 @@ BOOL ScCompiler::HandleSingleRef()
                         nMaxCol = nMyCol - 1;
                     }
                 }
-                for ( ScRangePair* pR = pRL->First(); pR; pR = pRL->Next() )
+                for ( size_t i = 0, nPairs = pRL->size(); i < nPairs; ++i )
                 {   // next defined RowNameRange to the right limits column
+                    ScRangePair* pR = pRL->at( i );
                     const ScRange& rRange = pR->GetRange(1);
                     if ( rRange.aStart.Row() <= nRow && nRow <= rRange.aEnd.Row() )
                     {   // identical row range
diff --git a/sc/source/core/tool/rangelst.cxx b/sc/source/core/tool/rangelst.cxx
index d828665..c11595f 100644
--- a/sc/source/core/tool/rangelst.cxx
+++ b/sc/source/core/tool/rangelst.cxx
@@ -455,148 +455,99 @@ void ScRangeList::push_back(ScRange* p)
     maRanges.push_back(p);
 }
 
-// === ScRangePairList ====================================================
+// === ScRangePairList ========================================================
 
+namespace {
+
+struct DeletePair : public ::std::unary_function<void, ScRangePair*>
+{
+    void operator() (ScRangePair* p)
+    {
+        delete p;
+    }
+};
+
+}
+
+//-----------------------------------------------------------------------------
 ScRangePairList::~ScRangePairList()
 {
-    for ( ScRangePair* pR = First(); pR; pR = Next() )
-        delete pR;
+    for_each( maPairs.begin(), maPairs.end(), DeletePair() );
+    maPairs.clear();
 }
 
+//-----------------------------------------------------------------------------
+ScRangePair* ScRangePairList::Remove(size_t nPos)
+{
+    if (maPairs.size() <= nPos)
+        // Out-of-bound condition.  Bail out.
+        return NULL;
+
+    vector<ScRangePair*>::iterator itr = maPairs.begin();
+    advance(itr, nPos);
+    ScRangePair* p = *itr;
+    maPairs.erase(itr);
+    return p;
+}
 
-void ScRangePairList::Join( const ScRangePair& r, BOOL bIsInList )
+//-----------------------------------------------------------------------------
+ScRangePair* ScRangePairList::Remove( ScRangePair* Adr)
 {
-    if ( !Count() )
-    {
-        Append( r );
-        return ;
-    }
-    const ScRange& r1 = r.GetRange(0);
-    const ScRange& r2 = r.GetRange(1);
-    SCCOL nCol1 = r1.aStart.Col();
-    SCROW nRow1 = r1.aStart.Row();
-    SCTAB nTab1 = r1.aStart.Tab();
-    SCCOL nCol2 = r1.aEnd.Col();
-    SCROW nRow2 = r1.aEnd.Row();
-    SCTAB nTab2 = r1.aEnd.Tab();
-    ScRangePair* pOver = (ScRangePair*) &r;		// fies aber wahr wenn bInList
-    ULONG nOldPos = 0;
-    if ( bIsInList )
-    {	// merken um ggbf. zu loeschen bzw. wiederherzustellen
-        nOldPos = GetPos( pOver );
-    }
-    BOOL bJoinedInput = FALSE;
-    for ( ScRangePair* p = First(); p && pOver; p = Next() )
+    ScRangePair* p = NULL;
+
+    if (Adr == NULL) return NULL;
+
+    for ( vector<ScRangePair*>::iterator itr = maPairs.begin(); itr < maPairs.end(); ++itr )
     {
-        if ( p == pOver )
-            continue;			// derselbe, weiter mit dem naechsten
-        BOOL bJoined = FALSE;
-        ScRange& rp1 = p->GetRange(0);
-        ScRange& rp2 = p->GetRange(1);
-        if ( rp2 == r2 )
-        {	// nur wenn Range2 gleich ist
-            if ( rp1.In( r1 ) )
-            {	// RangePair r in RangePair p enthalten oder identisch
-                if ( bIsInList )
-                    bJoined = TRUE;		// weg mit RangePair r
-                else
-                {	// das war's dann
-                    bJoinedInput = TRUE;	// nicht anhaengen
-                    break;	// for
-                }
-            }
-            else if ( r1.In( rp1 ) )
-            {	// RangePair p in RangePair r enthalten, r zum neuen RangePair machen
-                *p = r;
-                bJoined = TRUE;
-            }
-        }
-        if ( !bJoined && rp1.aStart.Tab() == nTab1 && rp1.aEnd.Tab() == nTab2
-          && rp2.aStart.Tab() == r2.aStart.Tab()
-          && rp2.aEnd.Tab() == r2.aEnd.Tab() )
-        {	// 2D, Range2 muss genauso nebeneinander liegen wie Range1
-            if ( rp1.aStart.Col() == nCol1 && rp1.aEnd.Col() == nCol2
-              && rp2.aStart.Col() == r2.aStart.Col()
-              && rp2.aEnd.Col() == r2.aEnd.Col() )
-            {
-                if ( rp1.aStart.Row() == nRow2+1
-                  && rp2.aStart.Row() == r2.aEnd.Row()+1 )
-                {	// oben
-                    rp1.aStart.SetRow( nRow1 );
-                    rp2.aStart.SetRow( r2.aStart.Row() );
-                    bJoined = TRUE;
-                }
-                else if ( rp1.aEnd.Row() == nRow1-1
-                  && rp2.aEnd.Row() == r2.aStart.Row()-1 )
-                {	// unten
-                    rp1.aEnd.SetRow( nRow2 );
-                    rp2.aEnd.SetRow( r2.aEnd.Row() );
-                    bJoined = TRUE;
-                }
-            }
-            else if ( rp1.aStart.Row() == nRow1 && rp1.aEnd.Row() == nRow2
-              && rp2.aStart.Row() == r2.aStart.Row()
-              && rp2.aEnd.Row() == r2.aEnd.Row() )
-            {
-                if ( rp1.aStart.Col() == nCol2+1
-                  && rp2.aStart.Col() == r2.aEnd.Col()+1 )
-                {	// links
-                    rp1.aStart.SetCol( nCol1 );
-                    rp2.aStart.SetCol( r2.aStart.Col() );
-                    bJoined = TRUE;
-                }
-                else if ( rp1.aEnd.Col() == nCol1-1
-                  && rp2.aEnd.Col() == r2.aEnd.Col()-1 )
-                {	// rechts
-                    rp1.aEnd.SetCol( nCol2 );
-                    rp2.aEnd.SetCol( r2.aEnd.Col() );
-                    bJoined = TRUE;
-                }
-            }
-        }
-        if ( bJoined )
+        if ( Adr == (p = *itr) )
         {
-            if ( bIsInList )
-            {	// innerhalb der Liste RangePair loeschen
-                Remove( nOldPos );
-                delete pOver;
-                pOver = NULL;
-                if ( nOldPos )
-                    nOldPos--;			// Seek richtig aufsetzen
-            }
-            bJoinedInput = TRUE;
-            Join( *p, TRUE );			// rekursiv!
+            maPairs.erase( itr );
+            break;
         }
     }
-    if ( bIsInList )
-        Seek( nOldPos );
-    else if ( !bJoinedInput )
-        Append( r );
+    return p;
 }
 
-
-BOOL ScRangePairList::operator==( const ScRangePairList& r ) const
+//-----------------------------------------------------------------------------
+bool ScRangePairList::operator==( const ScRangePairList& r ) const
 {
     if ( this == &r )
-        return TRUE;				// identische Referenz
-    if ( Count() != r.Count() )
-        return FALSE;
-    ULONG nCnt = Count();
-    for ( ULONG nIdx = 0; nIdx < nCnt; nIdx++ )
+        return true;				// identische Referenz
+    if ( maPairs.size() != r.size() )
+        return false;
+    for ( size_t nIdx = 0, nCnt = maPairs.size(); nIdx < nCnt; ++nIdx )
     {
-        if ( *GetObject( nIdx ) != *r.GetObject( nIdx ) )
-            return FALSE;			// auch andere Reihenfolge ist ungleich
+        if ( *maPairs[ nIdx ] != *r[ nIdx ] )
+            return false;			// auch andere Reihenfolge ist ungleich
     }
-    return TRUE;
+    return true;
+}
+
+//-----------------------------------------------------------------------------
+const ScRangePair* ScRangePairList::operator [](size_t idx) const
+{
+    return maPairs[idx];
 }
 
+//-----------------------------------------------------------------------------
+size_t ScRangePairList::size() const
+{
+    return maPairs.size();
+}
+
+//-----------------------------------------------------------------------------
+ScRangePair* ScRangePairList::at( size_t idx )
+{
+    return maPairs.at( idx );
+}
 
-BOOL ScRangePairList::UpdateReference( UpdateRefMode eUpdateRefMode,
+//-----------------------------------------------------------------------------
+bool ScRangePairList::UpdateReference( UpdateRefMode eUpdateRefMode,
                                     ScDocument* pDoc, const ScRange& rWhere,
                                     SCsCOL nDx, SCsROW nDy, SCsTAB nDz )
 {
-    BOOL bChanged = FALSE;
-    if ( Count() )
+    bool bChanged = false;
+    if ( !maPairs.empty() )
     {
         SCCOL nCol1;
         SCROW nRow1;
@@ -605,8 +556,9 @@ BOOL ScRangePairList::UpdateReference( UpdateRefMode eUpdateRefMode,
         SCROW nRow2;
         SCTAB nTab2;
         rWhere.GetVars( nCol1, nRow1, nTab1, nCol2, nRow2, nTab2 );
-        for ( ScRangePair* pR = First(); pR; pR = Next() )
+        for ( size_t i = 0, nPairs = maPairs.size(); i < nPairs; ++i )
         {
+            ScRangePair* pR = maPairs[ i ];
             for ( USHORT j=0; j<2; j++ )
             {
                 ScRange& rRange = pR->GetRange(j);
@@ -623,7 +575,7 @@ BOOL ScRangePairList::UpdateReference( UpdateRefMode eUpdateRefMode,
                         theCol1, theRow1, theTab1, theCol2, theRow2, theTab2 )
                         != UR_NOTHING )
                 {
-                    bChanged = TRUE;
+                    bChanged = true;
                     rRange.aStart.Set( theCol1, theRow1, theTab1 );
                     rRange.aEnd.Set( theCol2, theRow2, theTab2 );
                 }
@@ -633,48 +585,45 @@ BOOL ScRangePairList::UpdateReference( UpdateRefMode eUpdateRefMode,
     return bChanged;
 }
 
-
+//-----------------------------------------------------------------------------
+// Delete entries that have the labels (first range) on nTab
 void ScRangePairList::DeleteOnTab( SCTAB nTab )
 {
-    // Delete entries that have the labels (first range) on nTab
-
-    ULONG nListCount = Count();
-    ULONG nPos = 0;
+    size_t nListCount = maPairs.size();
+    size_t nPos = 0;
     while ( nPos < nListCount )
     {
-        ScRangePair* pR = GetObject( nPos );
+        ScRangePair* pR = maPairs[  nPos ];
         ScRange aRange = pR->GetRange(0);
         if ( aRange.aStart.Tab() == nTab && aRange.aEnd.Tab() == nTab )
         {
             Remove( nPos );
             delete pR;
-            nListCount = Count();
+            nListCount = maPairs.size();
         }
         else
             ++nPos;
     }
 }
 
-
+//-----------------------------------------------------------------------------
 ScRangePair* ScRangePairList::Find( const ScAddress& rAdr ) const
 {
-    ULONG nListCount = Count();
-    for ( ULONG j = 0; j < nListCount; j++ )
+    for ( size_t j = 0, nListCount = maPairs.size(); j < nListCount; j++ )
     {
-        ScRangePair* pR = GetObject( j );
+        ScRangePair* pR = maPairs[ j ];
         if ( pR->GetRange(0).In( rAdr ) )
             return pR;
     }
     return NULL;
 }
 
-
+//-----------------------------------------------------------------------------
 ScRangePair* ScRangePairList::Find( const ScRange& rRange ) const
 {
-    ULONG nListCount = Count();
-    for ( ULONG j = 0; j < nListCount; j++ )
+    for ( size_t j = 0, nListCount = maPairs.size(); j < nListCount; j++ )
     {
-        ScRangePair* pR = GetObject( j );
+        ScRangePair* pR = maPairs[ j ];
         if ( pR->GetRange(0) == rRange )
             return pR;
     }
@@ -682,25 +631,25 @@ ScRangePair* ScRangePairList::Find( const ScRange& rRange ) const
 }
 
 
+//-----------------------------------------------------------------------------
 ScRangePairList* ScRangePairList::Clone() const
 {
     ScRangePairList* pNew = new ScRangePairList;
-    ULONG nListCount = Count();
-    for ( ULONG j = 0; j < nListCount; j++ )
+    for ( size_t j = 0, nListCount = maPairs.size(); j < nListCount; j++ )
     {
-        pNew->Append( *GetObject( j ) );
+        pNew->Append( *maPairs[ j ] );
     }
     return pNew;
 }
 
-
+//-----------------------------------------------------------------------------
 struct ScRangePairNameSort
 {
     ScRangePair*	pPair;
     ScDocument*		pDoc;
 };
 
-
+//-----------------------------------------------------------------------------
 extern "C" int
 #ifdef WNT
 __cdecl
@@ -779,11 +728,130 @@ ScRangePairList_QsortNameCompare( const void* p1, const void* p2 )
     return 0; // just in case
 }
 
+//-----------------------------------------------------------------------------
+void ScRangePairList::Join( const ScRangePair& r, bool bIsInList )
+{
+    if ( maPairs.empty() )
+    {
+        Append( r );
+        return ;
+    }
+    const ScRange& r1 = r.GetRange(0);
+    const ScRange& r2 = r.GetRange(1);
+    SCCOL nCol1 = r1.aStart.Col();
+    SCROW nRow1 = r1.aStart.Row();
+    SCTAB nTab1 = r1.aStart.Tab();
+    SCCOL nCol2 = r1.aEnd.Col();
+    SCROW nRow2 = r1.aEnd.Row();
+    SCTAB nTab2 = r1.aEnd.Tab();
+    ScRangePair* pOver = (ScRangePair*) &r;		// fies aber wahr wenn bInList
+    size_t nOldPos = 0;
+    if ( bIsInList )
+    {
+        // Find the current position of this range.
+        for ( size_t i = 0, nPairs = maPairs.size(); i < nPairs; ++i )
+        {
+            if ( maPairs[i] == pOver )
+            {
+                nOldPos = i;
+                break;
+            }
+        }
+    }
+    bool bJoinedInput = false;
+
+    for ( size_t i = 0, nPairs = maPairs.size(); i < nPairs && pOver; ++i )
+    {
+        ScRangePair* p = maPairs[ i ];
+        if ( p == pOver )
+            continue;			// derselbe, weiter mit dem naechsten
+        bool bJoined = false;
+        ScRange& rp1 = p->GetRange(0);
+        ScRange& rp2 = p->GetRange(1);
+        if ( rp2 == r2 )
+        {	// nur wenn Range2 gleich ist
+            if ( rp1.In( r1 ) )
+            {	// RangePair r in RangePair p enthalten oder identisch
+                if ( bIsInList )
+                    bJoined = true;		// weg mit RangePair r
+                else
+                {	// das war's dann
+                    bJoinedInput = true;	// nicht anhaengen
+                    break;	// for
+                }
+            }
+            else if ( r1.In( rp1 ) )
+            {	// RangePair p in RangePair r enthalten, r zum neuen RangePair machen
+                *p = r;
+                bJoined = true;
+            }
+        }
+        if ( !bJoined && rp1.aStart.Tab() == nTab1 && rp1.aEnd.Tab() == nTab2
+          && rp2.aStart.Tab() == r2.aStart.Tab()
+          && rp2.aEnd.Tab() == r2.aEnd.Tab() )
+        {	// 2D, Range2 muss genauso nebeneinander liegen wie Range1
+            if ( rp1.aStart.Col() == nCol1 && rp1.aEnd.Col() == nCol2
+              && rp2.aStart.Col() == r2.aStart.Col()
+              && rp2.aEnd.Col() == r2.aEnd.Col() )
+            {
+                if ( rp1.aStart.Row() == nRow2+1
+                  && rp2.aStart.Row() == r2.aEnd.Row()+1 )
+                {	// oben
+                    rp1.aStart.SetRow( nRow1 );
+                    rp2.aStart.SetRow( r2.aStart.Row() );
+                    bJoined = true;
+                }
+                else if ( rp1.aEnd.Row() == nRow1-1
+                  && rp2.aEnd.Row() == r2.aStart.Row()-1 )
+                {	// unten
+                    rp1.aEnd.SetRow( nRow2 );
+                    rp2.aEnd.SetRow( r2.aEnd.Row() );
+                    bJoined = true;
+                }
+            }
+            else if ( rp1.aStart.Row() == nRow1 && rp1.aEnd.Row() == nRow2
+              && rp2.aStart.Row() == r2.aStart.Row()
+              && rp2.aEnd.Row() == r2.aEnd.Row() )
+            {
+                if ( rp1.aStart.Col() == nCol2+1
+                  && rp2.aStart.Col() == r2.aEnd.Col()+1 )
+                {	// links
+                    rp1.aStart.SetCol( nCol1 );
+                    rp2.aStart.SetCol( r2.aStart.Col() );
+                    bJoined = true;
+                }
+                else if ( rp1.aEnd.Col() == nCol1-1
+                  && rp2.aEnd.Col() == r2.aEnd.Col()-1 )
+                {	// rechts
+                    rp1.aEnd.SetCol( nCol2 );
+                    rp2.aEnd.SetCol( r2.aEnd.Col() );
+                    bJoined = true;
+                }
+            }
+        }
+        if ( bJoined )
+        {
+            if ( bIsInList )
+            {	// innerhalb der Liste RangePair loeschen
+                Remove( nOldPos );
+                delete pOver;
+                pOver = NULL;
+                if ( nOldPos )
+                    nOldPos--;			// Seek richtig aufsetzen
+            }
+            bJoinedInput = true;
+            Join( *p, true );			// rekursiv!
+        }
+    }
+    if ( !bIsInList && !bJoinedInput )
+        Append( r );
+}
 
-ScRangePair** ScRangePairList::CreateNameSortedArray( ULONG& nListCount,
+//-----------------------------------------------------------------------------
+ScRangePair** ScRangePairList::CreateNameSortedArray( size_t& nListCount,
         ScDocument* pDoc ) const
 {
-    nListCount = Count();
+    nListCount = maPairs.size();
     DBG_ASSERT( nListCount * sizeof(ScRangePairNameSort) <= (size_t)~0x1F,
         "ScRangePairList::CreateNameSortedArray nListCount * sizeof(ScRangePairNameSort) > (size_t)~0x1F" );
     ScRangePairNameSort* pSortArray = (ScRangePairNameSort*)
@@ -791,7 +859,7 @@ ScRangePair** ScRangePairList::CreateNameSortedArray( ULONG& nListCount,
     ULONG j;
     for ( j=0; j < nListCount; j++ )
     {
-        pSortArray[j].pPair = GetObject( j );
+        pSortArray[j].pPair = maPairs[ j ];
         pSortArray[j].pDoc = pDoc;
     }
 #if !(defined(ICC ) && defined(OS2))
@@ -808,7 +876,4 @@ ScRangePair** ScRangePairList::CreateNameSortedArray( ULONG& nListCount,
     return ppSortArray;
 }
 
-
-
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/excel/xecontent.cxx b/sc/source/filter/excel/xecontent.cxx
index b46466e..0464bad 100644
--- a/sc/source/filter/excel/xecontent.cxx
+++ b/sc/source/filter/excel/xecontent.cxx
@@ -2,7 +2,7 @@
 /*************************************************************************
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- * 
+ *
  * Copyright 2000, 2010 Oracle and/or its affiliates.
  *
  * OpenOffice.org - a multi-platform office productivity suite
@@ -262,7 +262,7 @@ void XclExpSstImpl::SaveXml( XclExpXmlStream& rStrm )
     if( maStringList.empty() )
         return;
 
-    sax_fastparser::FSHelperPtr pSst = rStrm.CreateOutputStream( 
+    sax_fastparser::FSHelperPtr pSst = rStrm.CreateOutputStream(
             OUString(RTL_CONSTASCII_USTRINGPARAM( "xl/sharedStrings.xml") ),
             OUString(RTL_CONSTASCII_USTRINGPARAM( "sharedStrings.xml" )),
             rStrm.GetCurrentStream()->getOutputStream(),
@@ -271,7 +271,7 @@ void XclExpSstImpl::SaveXml( XclExpXmlStream& rStrm )
     rStrm.PushStream( pSst );
 
     pSst->startElement( XML_sst,
-            XML_xmlns, "http://schemas.openxmlformats.org/spreadsheetml/2006/main", 
+            XML_xmlns, "http://schemas.openxmlformats.org/spreadsheetml/2006/main",
             XML_count, OString::valueOf( (sal_Int32) mnTotal ).getStr(),
             XML_uniqueCount, OString::valueOf( (sal_Int32) mnSize ).getStr(),
             FSEND );
@@ -562,8 +562,8 @@ void XclExpHyperlink::SaveXml( XclExpXmlStream& rStrm )
             FSNS( XML_r, XML_id ),  sId.getLength()
                                        ? XclXmlUtils::ToOString( sId ).getStr()
                                        : NULL,
-            XML_location,           mxTextMark.get() != NULL 
-                                        ? XclXmlUtils::ToOString( *mxTextMark ).getStr() 
+            XML_location,           mxTextMark.get() != NULL
+                                        ? XclXmlUtils::ToOString( *mxTextMark ).getStr()
                                         : NULL,
             // OOXTODO: XML_tooltip,    from record HLinkTooltip 800h wzTooltip
             XML_display,            XclXmlUtils::ToOString( *mxRepr ).getStr(),
@@ -592,8 +592,9 @@ XclExpLabelranges::XclExpLabelranges( const XclExpRoot& rRoot ) :
 void XclExpLabelranges::FillRangeList( ScRangeList& rScRanges,
         ScRangePairListRef xLabelRangesRef, SCTAB nScTab )
 {
-    for( const ScRangePair* pRangePair = xLabelRangesRef->First(); pRangePair; pRangePair = xLabelRangesRef->Next() )
+    for ( size_t i = 0, nPairs = xLabelRangesRef->size(); i < nPairs; ++i )
     {
+        ScRangePair* pRangePair = xLabelRangesRef->at( i );
         const ScRange& rScRange = pRangePair->GetRange( 0 );
         if( rScRange.aStart.Tab() == nScTab )
             rScRanges.Append( rScRange );
@@ -892,7 +893,7 @@ void XclExpCondfmt::SaveXml( XclExpXmlStream& rStrm )
 {
     if( !IsValid() )
         return;
-    
+
     sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
     rWorksheet->startElement( XML_conditionalFormatting,
             XML_sqref, XclXmlUtils::ToOString( msSeqRef ).getStr(),
@@ -1181,7 +1182,7 @@ void XclExpDV::SaveXml( XclExpXmlStream& rStrm )
     rWorksheet->startElement( XML_dataValidation,
             XML_allowBlank,         XclXmlUtils::ToPsz( ::get_flag( mnFlags, EXC_DV_IGNOREBLANK ) ),
             XML_error,              XESTRING_TO_PSZ( maErrorText ),
-            // OOXTODO: XML_errorStyle, 
+            // OOXTODO: XML_errorStyle,
             XML_errorTitle,         XESTRING_TO_PSZ( maErrorTitle ),
             // OOXTODO: XML_imeMode,
             XML_operator,           lcl_GetOperatorType( mnFlags ),
@@ -1256,7 +1257,7 @@ void XclExpDval::SaveXml( XclExpXmlStream& rStrm )
         return;
 
     sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
-    rWorksheet->startElement( XML_dataValidations, 
+    rWorksheet->startElement( XML_dataValidations,
             XML_count, OString::valueOf( (sal_Int32) maDVList.GetSize() ).getStr(),
             // OOXTODO: XML_disablePrompts,
             // OOXTODO: XML_xWindow,
diff --git a/sc/source/ui/miscdlgs/crnrdlg.cxx b/sc/source/ui/miscdlgs/crnrdlg.cxx
index 0ba1bf1..ccb84b0 100644
--- a/sc/source/ui/miscdlgs/crnrdlg.cxx
+++ b/sc/source/ui/miscdlgs/crnrdlg.cxx
@@ -2,7 +2,7 @@
 /*************************************************************************
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- * 
+ *
  * Copyright 2000, 2010 Oracle and/or its affiliates.
  *
  * OpenOffice.org - a multi-platform office productivity suite
@@ -506,7 +506,7 @@ void ScColRowNameRangesDlg::UpdateNames()
     aRangeMap.clear();
     aEdAssign.SetText( EMPTY_STRING );
 
-    ULONG nCount, j;
+    size_t nCount, j;
     USHORT nPos; //@008 Hilfsvariable q eingefuegt
 
     SCCOL nCol1;	//@008 04.09.97
@@ -526,7 +526,7 @@ void ScColRowNameRangesDlg::UpdateNames()
     aString += strDelim;
     nPos = aLbRange.InsertEntry( aString );
     aLbRange.SetEntryData( nPos, (void*)nEntryDataDelim );
-    if ( (nCount = xColNameRanges->Count()) > 0 )
+    if ( (nCount = xColNameRanges->size()) > 0 )
     {
         ScRangePair** ppSortArray = xColNameRanges->CreateNameSortedArray(
             nCount, pDoc );
@@ -573,7 +573,7 @@ void ScColRowNameRangesDlg::UpdateNames()
     aString += strDelim;
     nPos = aLbRange.InsertEntry( aString );
     aLbRange.SetEntryData( nPos, (void*)nEntryDataDelim );
-    if ( (nCount = xRowNameRanges->Count()) > 0 )
+    if ( (nCount = xRowNameRanges->size()) > 0 )
     {
         ScRangePair** ppSortArray = xRowNameRanges->CreateNameSortedArray(
             nCount, pDoc );
diff --git a/sc/source/ui/unoobj/nameuno.cxx b/sc/source/ui/unoobj/nameuno.cxx
index e890d24..7a5ffe1 100644
--- a/sc/source/ui/unoobj/nameuno.cxx
+++ b/sc/source/ui/unoobj/nameuno.cxx
@@ -2,7 +2,7 @@
 /*************************************************************************
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- * 
+ *
  * Copyright 2000, 2010 Oracle and/or its affiliates.
  *
  * OpenOffice.org - a multi-platform office productivity suite
@@ -1042,15 +1042,15 @@ void ScLabelRangesObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
 
 // sheet::XLabelRanges
 
-ScLabelRangeObj* ScLabelRangesObj::GetObjectByIndex_Impl(sal_uInt16 nIndex)
+ScLabelRangeObj* ScLabelRangesObj::GetObjectByIndex_Impl(size_t nIndex)
 {
     if (pDocShell)
     {
         ScDocument* pDoc = pDocShell->GetDocument();
         ScRangePairList* pList = bColumn ? pDoc->GetColNameRanges() : pDoc->GetRowNameRanges();
-        if ( pList && nIndex < pList->Count() )
+        if ( pList && nIndex < pList->size() )
         {
-            ScRangePair* pData = pList->GetObject(nIndex);
+            ScRangePair* pData = pList->at( nIndex );
             if (pData)
                 return new ScLabelRangeObj( pDocShell, bColumn, pData->GetRange(0) );
         }
@@ -1101,11 +1101,11 @@ void SAL_CALL ScLabelRangesObj::removeByIndex( sal_Int32 nIndex )
         ScDocument* pDoc = pDocShell->GetDocument();
         ScRangePairList* pOldList = bColumn ? pDoc->GetColNameRanges() : pDoc->GetRowNameRanges();
 
-        if ( pOldList && nIndex >= 0 && nIndex < (sal_Int32)pOldList->Count() )
+        if ( pOldList && nIndex >= 0 && nIndex < (sal_Int32)pOldList->size() )
         {
             ScRangePairListRef xNewList(pOldList->Clone());
 
-            ScRangePair* pEntry = xNewList->GetObject( nIndex );
+            ScRangePair* pEntry = xNewList->at( nIndex );
             if (pEntry)
             {
                 xNewList->Remove( pEntry );
@@ -1148,7 +1148,7 @@ sal_Int32 SAL_CALL ScLabelRangesObj::getCount() throw(uno::RuntimeException)
         ScDocument* pDoc = pDocShell->GetDocument();
         ScRangePairList* pList = bColumn ? pDoc->GetColNameRanges() : pDoc->GetRowNameRanges();
         if (pList)
-            return pList->Count();
+            return pList->size();
     }
     return 0;
 }


More information about the Libreoffice-commits mailing list