diff options
-rw-r--r-- | sc/inc/cell.hxx | 2 | ||||
-rw-r--r-- | sc/inc/column.hxx | 2 | ||||
-rw-r--r-- | sc/inc/document.hxx | 2 | ||||
-rw-r--r-- | sc/inc/rangenam.hxx | 12 | ||||
-rw-r--r-- | sc/inc/table.hxx | 2 | ||||
-rw-r--r-- | sc/source/core/data/cell2.cxx | 6 | ||||
-rw-r--r-- | sc/source/core/data/column.cxx | 2 | ||||
-rw-r--r-- | sc/source/core/data/documen2.cxx | 58 | ||||
-rw-r--r-- | sc/source/core/data/documen3.cxx | 14 | ||||
-rw-r--r-- | sc/source/core/data/document.cxx | 13 | ||||
-rw-r--r-- | sc/source/core/data/table1.cxx | 2 | ||||
-rw-r--r-- | sc/source/core/tool/rangenam.cxx | 42 | ||||
-rw-r--r-- | sc/source/filter/excel/xename.cxx | 6 | ||||
-rw-r--r-- | sc/source/ui/docshell/docfunc.cxx | 22 | ||||
-rw-r--r-- | sc/source/ui/miscdlgs/namepast.cxx | 22 | ||||
-rw-r--r-- | sc/source/ui/namedlg/namedlg.cxx | 38 | ||||
-rw-r--r-- | sc/source/ui/undo/undoblk3.cxx | 46 | ||||
-rw-r--r-- | sc/source/ui/unoobj/nameuno.cxx | 39 | ||||
-rw-r--r-- | sc/source/ui/vba/vbarange.cxx | 18 | ||||
-rw-r--r-- | sc/source/ui/view/cellsh1.cxx | 16 |
20 files changed, 182 insertions, 182 deletions
diff --git a/sc/inc/cell.hxx b/sc/inc/cell.hxx index 297d9015d6d3..904aa3189acb 100644 --- a/sc/inc/cell.hxx +++ b/sc/inc/cell.hxx @@ -459,7 +459,7 @@ public: void UpdateRenameTab(SCTAB nTable, const String& rName); BOOL TestTabRefAbs(SCTAB nTable); void UpdateCompile( BOOL bForceIfNameInUse = FALSE ); - BOOL IsRangeNameInUse(USHORT nIndex) const; + BOOL IsRangeNameInUse(size_t nIndex) const; void FindRangeNamesInUse(std::set<USHORT>& rIndexes) const; void ReplaceRangeNamesInUse( const ScRangeData::IndexMap& rMap ); BOOL IsSubTotal() const { return bSubTotal; } diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx index e4febf65179d..3c2da566e552 100644 --- a/sc/inc/column.hxx +++ b/sc/inc/column.hxx @@ -299,7 +299,7 @@ public: void UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY ); void SetTabNo(SCTAB nNewTab); - bool IsRangeNameInUse(SCROW nRow1, SCROW nRow2, sal_uInt16 nIndex) const; + bool IsRangeNameInUse(SCROW nRow1, SCROW nRow2, size_t nIndex) const; void FindRangeNamesInUse(SCROW nRow1, SCROW nRow2, std::set<sal_uInt16>& rIndexes) const; void ReplaceRangeNamesInUse( SCROW nRow1, SCROW nRow2, const ScRangeData::IndexMap& rMap ); diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index ae8ef78ce9d7..e30ab421e88f 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -1479,7 +1479,7 @@ public: VirtualDevice* GetVirtualDevice_100th_mm(); SC_DLLPUBLIC OutputDevice* GetRefDevice(); // WYSIWYG: Printer, otherwise VirtualDevice... - void EraseNonUsedSharedNames(USHORT nLevel); + void EraseNonUsedSharedNames(); BOOL GetNextSpellingCell(SCCOL& nCol, SCROW& nRow, SCTAB nTab, BOOL bInSel, const ScMarkData& rMark) const; diff --git a/sc/inc/rangenam.hxx b/sc/inc/rangenam.hxx index 21150a237ea1..292faa429365 100644 --- a/sc/inc/rangenam.hxx +++ b/sc/inc/rangenam.hxx @@ -192,17 +192,17 @@ private: sal_uInt16 mnSharedMaxIndex; public: typedef DataType::const_iterator const_iterator; + typedef DataType::iterator iterator; ScRangeName(ScDocument* pDoc = NULL); ScRangeName(const ScRangeName& r); - SC_DLLPUBLIC ScRangeData* operator[](sal_uInt16 nIndex); - SC_DLLPUBLIC const ScRangeData* operator[](sal_uInt16 nIndex) const; SC_DLLPUBLIC const ScRangeData* GetRangeAtBlock(const ScRange& rRange) const; SC_DLLPUBLIC ScRangeData* findByName(const rtl::OUString& rName); SC_DLLPUBLIC const ScRangeData* findByName(const rtl::OUString& rName) const; ScRangeData* findByUpperName(const rtl::OUString& rName); const ScRangeData* findByUpperName(const rtl::OUString& rName) const; + bool getIndex(const ScRangeData& rData, size_t& rIndex) const; void UpdateReference(UpdateRefMode eUpdateRefMode, const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz); void UpdateTabRef(SCTAB nTable, sal_uInt16 nFlag, SCTAB nNewTable = 0); @@ -212,12 +212,16 @@ public: sal_uInt16 GetSharedMaxIndex(); void SetSharedMaxIndex(sal_uInt16 nInd); - const_iterator begin() const; - const_iterator end() const; + SC_DLLPUBLIC const_iterator begin() const; + SC_DLLPUBLIC const_iterator end() const; + SC_DLLPUBLIC iterator begin(); + SC_DLLPUBLIC iterator end(); SC_DLLPUBLIC size_t size() const; bool empty() const; + SC_DLLPUBLIC bool insert(ScRangeData* p); SC_DLLPUBLIC bool Insert(ScRangeData* p); void erase(const ScRangeData& r); + void erase(const iterator& itr); void clear(); bool operator== (const ScRangeName& r) const; }; diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index 3b799a7301b5..d58944950be2 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -479,7 +479,7 @@ public: void UpdateCompile( BOOL bForceIfNameInUse = FALSE ); void SetTabNo(SCTAB nNewTab); BOOL IsRangeNameInUse(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, - USHORT nIndex) const; + size_t nIndex) const; void FindRangeNamesInUse(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, std::set<USHORT>& rIndexes) const; void ReplaceRangeNamesInUse(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, diff --git a/sc/source/core/data/cell2.cxx b/sc/source/core/data/cell2.cxx index a5cd0d7e9fc2..3a7f22808efc 100644 --- a/sc/source/core/data/cell2.cxx +++ b/sc/source/core/data/cell2.cxx @@ -1508,13 +1508,13 @@ void ScFormulaCell::UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY StartListeningTo( pDocument ); // Listener wie vorher } -BOOL lcl_IsRangeNameInUse(USHORT nIndex, ScTokenArray* pCode, ScRangeName* pNames) +BOOL lcl_IsRangeNameInUse(size_t nIndex, ScTokenArray* pCode, ScRangeName* pNames) { for (FormulaToken* p = pCode->First(); p; p = pCode->Next()) { if (p->GetOpCode() == ocName) { - if (p->GetIndex() == nIndex) + if (p->GetIndex() == static_cast<USHORT>(nIndex)) return TRUE; else { @@ -1529,7 +1529,7 @@ BOOL lcl_IsRangeNameInUse(USHORT nIndex, ScTokenArray* pCode, ScRangeName* pName return FALSE; } -BOOL ScFormulaCell::IsRangeNameInUse(USHORT nIndex) const +BOOL ScFormulaCell::IsRangeNameInUse(size_t nIndex) const { return lcl_IsRangeNameInUse( nIndex, pCode, pDocument->GetRangeName() ); } diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx index de0e8ed5cb22..286ed8fc2f9b 100644 --- a/sc/source/core/data/column.cxx +++ b/sc/source/core/data/column.cxx @@ -1841,7 +1841,7 @@ void ScColumn::SetTabNo(SCTAB nNewTab) } -bool ScColumn::IsRangeNameInUse(SCROW nRow1, SCROW nRow2, sal_uInt16 nIndex) const +bool ScColumn::IsRangeNameInUse(SCROW nRow1, SCROW nRow2, size_t nIndex) const { bool bInUse = false; if (pItems) diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx index eedbd5434e0d..04b81d918213 100644 --- a/sc/source/core/data/documen2.cxx +++ b/sc/source/core/data/documen2.cxx @@ -962,6 +962,8 @@ ULONG ScDocument::TransferTab( ScDocument* pSrcDoc, SCTAB nSrcPos, if ( !bResultsOnly ) { +#if NEW_RANGE_NAME +#else BOOL bNamesLost = FALSE; size_t nSrcRangeNames = pSrcDoc->pRangeName->size(); // array containing range names which might need update of indices @@ -1058,6 +1060,7 @@ ULONG ScDocument::TransferTab( ScDocument* pSrcDoc, SCTAB nSrcPos, // message: duplicate names } pTab[nDestPos]->CompileAll(); +#endif } SetNoListening( FALSE ); @@ -1127,35 +1130,42 @@ void ScDocument::SetError( SCCOL nCol, SCROW nRow, SCTAB nTab, const USHORT nErr pTab[nTab]->SetError( nCol, nRow, nError ); } -void ScDocument::EraseNonUsedSharedNames(USHORT nLevel) +namespace { + +bool eraseUnusedSharedName(ScRangeName* pRangeName, ScTable* pTab[]) { -#if NEW_RANGE_NAME -#else - for (size_t i = 0; i < pRangeName->size(); i++) + ScRangeName::const_iterator itr = pRangeName->begin(), itrEnd = pRangeName->end(); + for (; itr != itrEnd; ++itr) { - ScRangeData* pRangeData = (*pRangeName)[i]; - if (pRangeData && pRangeData->HasType(RT_SHARED)) + if (!itr->HasType(RT_SHARED)) + continue; + + size_t nIndex; + if (!pRangeName->getIndex(*itr, nIndex)) + // index not found. + continue; + + bool bInUse = false; + for (SCTAB j = 0; !bInUse && (j <= MAXTAB); ++j) { - String aName; - pRangeData->GetName(aName); - aName.Erase(0, 6); // !!! vgl. Table4, FillFormula !! - USHORT nInd = (USHORT) aName.ToInt32(); - if (nInd <= nLevel) - { - USHORT nIndex = pRangeData->GetIndex(); - BOOL bInUse = FALSE; - for (SCTAB j = 0; !bInUse && (j <= MAXTAB); j++) - { - if (pTab[j]) - bInUse = pTab[j]->IsRangeNameInUse(0, 0, MAXCOL-1, MAXROW-1, - nIndex); - } - if (!bInUse) - pRangeName->AtFree(i); - } + if (pTab[j]) + bInUse = pTab[j]->IsRangeNameInUse(0, 0, MAXCOL-1, MAXROW-1, nIndex); + } + if (!bInUse) + { + pRangeName->erase(itr); + return true; } } -#endif + return false; +} + +} + +void ScDocument::EraseNonUsedSharedNames() +{ + while (eraseUnusedSharedName(pRangeName, pTab)) + ; } // ---------------------------------------------------------------------------- diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx index 9ee61b635f8b..fdc99683bcca 100644 --- a/sc/source/core/data/documen3.cxx +++ b/sc/source/core/data/documen3.cxx @@ -1403,16 +1403,12 @@ BOOL ScDocument::GetFormulaEntries( TypedScStrCollection& rStrings ) if ( pRangeName ) { - size_t nRangeCount = pRangeName->size(); - for ( size_t i = 0; i < nRangeCount; i++ ) + ScRangeName::const_iterator itr = pRangeName->begin(), itrEnd = pRangeName->end(); + for (; itr != itrEnd; ++itr) { - ScRangeData* pData = (*pRangeName)[i]; - if (pData) - { - TypedStrData* pNew = new TypedStrData( pData->GetName(), 0.0, SC_STRTYPE_NAMES ); - if ( !rStrings.Insert(pNew) ) - delete pNew; - } + TypedStrData* pNew = new TypedStrData(itr->GetName(), 0.0, SC_STRTYPE_NAMES); + if (!rStrings.Insert(pNew)) + delete pNew; } } diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx index c7afd2682b39..222930028a5c 100644 --- a/sc/source/core/data/document.cxx +++ b/sc/source/core/data/document.cxx @@ -1707,18 +1707,15 @@ void ScDocument::TransposeClip( ScDocument* pTransClip, USHORT nFlags, BOOL bAsL // Bereiche uebernehmen pTransClip->pRangeName->clear(); -#if NEW_RANGE_NAME -#else - for (USHORT i = 0; i < pRangeName->GetCount(); i++) //! DB-Bereiche Pivot-Bereiche auch !!! + ScRangeName::const_iterator itr = pRangeName->begin(), itrEnd = pRangeName->end(); + for (; itr != itrEnd; ++itr) { - USHORT nIndex = ((ScRangeData*)((*pRangeName)[i]))->GetIndex(); - ScRangeData* pData = new ScRangeData(*((*pRangeName)[i])); - if (!pTransClip->pRangeName->Insert(pData)) + ScRangeData* pData = new ScRangeData(*itr); + if (!pTransClip->pRangeName->insert(pData)) delete pData; else - pData->SetIndex(nIndex); + pData->SetIndex(0); } -#endif // The data diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx index b950b9bc75f8..2903be085cb6 100644 --- a/sc/source/core/data/table1.cxx +++ b/sc/source/core/data/table1.cxx @@ -1446,7 +1446,7 @@ void ScTable::SetTabNo(SCTAB nNewTab) } BOOL ScTable::IsRangeNameInUse(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, - USHORT nIndex) const + size_t nIndex) const { BOOL bInUse = FALSE; for (SCCOL i = nCol1; !bInUse && (i <= nCol2) && (ValidCol(i)); i++) diff --git a/sc/source/core/tool/rangenam.cxx b/sc/source/core/tool/rangenam.cxx index 60661ca3fad6..d4929fb98fdb 100644 --- a/sc/source/core/tool/rangenam.cxx +++ b/sc/source/core/tool/rangenam.cxx @@ -669,16 +669,6 @@ ScRangeName::ScRangeName(ScDocument* pDoc) : ScRangeName::ScRangeName(const ScRangeName& r) : maData(r.maData), mpDoc(r.mpDoc) {} -ScRangeData* ScRangeName::operator[](sal_uInt16 nIndex) -{ - return NULL; -} - -const ScRangeData* ScRangeName::operator[](sal_uInt16 nIndex) const -{ - return NULL; -} - const ScRangeData* ScRangeName::GetRangeAtBlock(const ScRange& rRange) const { DataType::const_iterator itr = maData.begin(), itrEnd = maData.end(); @@ -727,6 +717,16 @@ ScRangeData* ScRangeName::findByUpperName(const OUString& rName) return NULL; } +bool ScRangeName::getIndex(const ScRangeData& rData, size_t& rIndex) const +{ + DataType::const_iterator itr = maData.find(rData); + if (itr == maData.end()) + return false; + + rIndex = std::distance(maData.begin(), itr); + return true; +} + const ScRangeData* ScRangeName::findByUpperName(const OUString& rName) const { DataType::const_iterator itr = maData.begin(), itrEnd = maData.end(); @@ -797,6 +797,16 @@ ScRangeName::const_iterator ScRangeName::end() const return maData.end(); } +ScRangeName::iterator ScRangeName::begin() +{ + return maData.begin(); +} + +ScRangeName::iterator ScRangeName::end() +{ + return maData.end(); +} + size_t ScRangeName::size() const { return maData.size(); @@ -807,7 +817,7 @@ bool ScRangeName::empty() const return maData.empty(); } -bool ScRangeName::Insert(ScRangeData* p) +bool ScRangeName::insert(ScRangeData* p) { if (!p) return false; @@ -816,11 +826,21 @@ bool ScRangeName::Insert(ScRangeData* p) return r.second; } +bool ScRangeName::Insert(ScRangeData* p) +{ + return insert(p); +} + void ScRangeName::erase(const ScRangeData& r) { maData.erase(r); } +void ScRangeName::erase(const iterator& itr) +{ + maData.erase(itr); +} + void ScRangeName::clear() { maData.clear(); diff --git a/sc/source/filter/excel/xename.cxx b/sc/source/filter/excel/xename.cxx index 33c917271358..035a84bcf0a0 100644 --- a/sc/source/filter/excel/xename.cxx +++ b/sc/source/filter/excel/xename.cxx @@ -672,6 +672,12 @@ void XclExpNameManagerImpl::CreateBuiltInNames() void XclExpNameManagerImpl::CreateUserNames() { #if NEW_RANGE_NAME + const ScRangeName& rNamedRanges = GetNamedRanges(); + ScRangeName::const_iterator itr = rNamedRanges.begin(), itrEnd = rNamedRanges.end(); + for (; itr != itrEnd; ++itr) + { + // TODO: re-implement maNameMap to map name to excel index. + } #else const ScRangeName& rNamedRanges = GetNamedRanges(); for( USHORT nNameIdx = 0, nNameCount = rNamedRanges.GetCount(); nNameIdx < nNameCount; ++nNameIdx ) diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index ea2722675ee8..5add28194215 100644 --- a/sc/source/ui/docshell/docfunc.cxx +++ b/sc/source/ui/docshell/docfunc.cxx @@ -4691,17 +4691,13 @@ BOOL ScDocFunc::InsertNameList( const ScAddress& rStartPos, BOOL bApi ) ScRangeName* pList = pDoc->GetRangeName(); USHORT nValidCount = 0; - USHORT i; - USHORT nCount = pList->size(); -#if NEW_RANGE_NAME -#else - for (i=0; i<nCount; i++) + ScRangeName::iterator itrBeg = pList->begin(), itrEnd = pList->end(); + for (ScRangeName::iterator itr = itrBeg; itr != itrEnd; ++itr) { - ScRangeData* pData = (*pList)[i]; - if ( !pData->HasType( RT_DATABASE ) && !pData->HasType( RT_SHARED ) ) + const ScRangeData& r = *itr; + if (r.HasType(RT_DATABASE && !r.HasType(RT_SHARED))) ++nValidCount; } -#endif if (nValidCount) { @@ -4725,11 +4721,11 @@ BOOL ScDocFunc::InsertNameList( const ScAddress& rStartPos, BOOL bApi ) ScRangeData** ppSortArray = new ScRangeData* [ nValidCount ]; USHORT j = 0; - for (i=0; i<nCount; i++) + for (ScRangeName::iterator itr = itrBeg; itr != itrEnd; ++itr) { - ScRangeData* pData = (*pList)[i]; - if ( !pData->HasType( RT_DATABASE ) && !pData->HasType( RT_SHARED ) ) - ppSortArray[j++] = pData; + ScRangeData& r = *itr; + if (!r.HasType(RT_DATABASE) && !r.HasType(RT_SHARED)) + ppSortArray[j++] = &r; } #ifndef ICC qsort( (void*)ppSortArray, nValidCount, sizeof(ScRangeData*), @@ -4772,7 +4768,7 @@ BOOL ScDocFunc::InsertNameList( const ScAddress& rStartPos, BOOL bApi ) if (!AdjustRowHeight(ScRange(0,nStartRow,nTab,MAXCOL,nEndRow,nTab))) rDocShell.PostPaint( nStartCol,nStartRow,nTab, nEndCol,nEndRow,nTab, PAINT_GRID ); -//! rDocShell.UpdateOle(GetViewData()); + aModificator.SetDocumentModified(); bDone = TRUE; } diff --git a/sc/source/ui/miscdlgs/namepast.cxx b/sc/source/ui/miscdlgs/namepast.cxx index e9c2bb416051..ea17b22bd4f2 100644 --- a/sc/source/ui/miscdlgs/namepast.cxx +++ b/sc/source/ui/miscdlgs/namepast.cxx @@ -60,26 +60,12 @@ ScNamePasteDlg::ScNamePasteDlg( Window * pParent, const ScRangeName* pList, BOOL aNameList.SetSelectHdl( LINK( this,ScNamePasteDlg,ListSelHdl) ); aNameList.SetDoubleClickHdl( LINK( this,ScNamePasteDlg,ListDblClickHdl) ); -#if NEW_RANGE_NAME -#else - USHORT nCnt = pList->GetCount(); - String aText; - - for( USHORT i=0 ; i<nCnt ; i++ ) + ScRangeName::const_iterator itr = pList->begin(), itrEnd = pList->end(); + for (; itr != itrEnd; ++itr) { - const ScRangeData* pData = (*pList)[ i ]; - - if( pData ) - { - if ( !pData->HasType( RT_DATABASE ) - && !pData->HasType( RT_SHARED ) ) - { - pData->GetName( aText ); - aNameList.InsertEntry( aText ); - } - } + if (!itr->HasType(RT_DATABASE) && !itr->HasType(RT_SHARED)) + aNameList.InsertEntry(itr->GetName()); } -#endif ListSelHdl( &aNameList ); diff --git a/sc/source/ui/namedlg/namedlg.cxx b/sc/source/ui/namedlg/namedlg.cxx index 7af7ef822ca3..b3b90a352910 100644 --- a/sc/source/ui/namedlg/namedlg.cxx +++ b/sc/source/ui/namedlg/namedlg.cxx @@ -314,47 +314,31 @@ void ScNameDlg::UpdateChecks() void ScNameDlg::UpdateNames() { -#if NEW_RANGE_NAME -#else - USHORT nRangeCount = aLocalRangeName.GetCount(); - aEdName.SetUpdateMode( FALSE ); - //----------------------------------------------------------- USHORT nNamePos = aEdName.GetTopEntry(); aEdName.Clear(); aEdAssign.SetText( EMPTY_STRING ); - if ( nRangeCount > 0 ) - { - ScRangeData* pRangeData = NULL; - String aString; - - for ( USHORT i=0; i<nRangeCount; i++ ) - { - pRangeData = (ScRangeData*)(aLocalRangeName.At( i )); - if ( pRangeData ) - { - if ( !pRangeData->HasType( RT_DATABASE ) - && !pRangeData->HasType( RT_SHARED ) ) - { - pRangeData->GetName( aString ); - aEdName.InsertEntry( aString ); - } - } - } - } - else + if (aLocalRangeName.empty()) { aBtnAdd.SetText( aStrAdd ); aBtnAdd.Disable(); aBtnRemove.Disable(); } - //----------------------------------------------------------- + else + { + ScRangeName::const_iterator itr = aLocalRangeName.begin(), itrEnd = aLocalRangeName.end(); + for (; itr != itrEnd; ++itr) + { + if (!itr->HasType(RT_DATABASE) && !itr->HasType(RT_SHARED)) + aEdName.InsertEntry(itr->GetName()); + } + } + aEdName.SetUpdateMode( TRUE ); aEdName.SetTopEntry(nNamePos); aEdName.Invalidate(); -#endif } diff --git a/sc/source/ui/undo/undoblk3.cxx b/sc/source/ui/undo/undoblk3.cxx index dc351ab7569c..f5b766b17a7d 100644 --- a/sc/source/ui/undo/undoblk3.cxx +++ b/sc/source/ui/undo/undoblk3.cxx @@ -629,7 +629,7 @@ ScUndoAutoFill::ScUndoAutoFill( ScDocShell* pNewDocShell, ScUndoAutoFill::~ScUndoAutoFill() { - pDocShell->GetDocument()->EraseNonUsedSharedNames(nMaxSharedIndex); + pDocShell->GetDocument()->EraseNonUsedSharedNames(); delete pUndoDoc; } @@ -652,8 +652,25 @@ void ScUndoAutoFill::SetChangeTrack() nStartChangeAction = nEndChangeAction = 0; } +namespace { -//---------------------------------------------------------------------------- +bool eraseNameContaining(ScRangeName& rNames, const rtl::OUString& rCriteria) +{ + ScRangeName::iterator itr = rNames.begin(), itrEnd = rNames.end(); + for (; itr != itrEnd; ++itr) + { + rtl::OUString aRName = itr->GetName(); + if (aRName.indexOf(rCriteria) >= 0) + { + // Criteria found. Erase this. + rNames.erase(itr); + return true; + } + } + return false; +} + +} void ScUndoAutoFill::Undo() { @@ -693,24 +710,17 @@ void ScUndoAutoFill::Undo() aName += String::CreateFromInt32(nMaxSharedIndex); aName += '_'; ScRangeName* pRangeName = pDoc->GetRangeName(); - BOOL bHasFound = FALSE; -#if NEW_RANGE_NAME -#else - for (USHORT i = 0; i < pRangeName->GetCount(); i++) + bool bHasFound = false; + // Remove all range names that contain ___SC_... + while (true) { - ScRangeData* pRangeData = (*pRangeName)[i]; - if (pRangeData) - { - String aRName; - pRangeData->GetName(aRName); - if (aRName.Search(aName) != STRING_NOTFOUND) - { - pRangeName->AtFree(i); - bHasFound = TRUE; - } - } + bool bErased = eraseNameContaining(*pRangeName, aName); + if (bErased) + bHasFound = true; + else + break; } -#endif + if (bHasFound) pRangeName->SetSharedMaxIndex(pRangeName->GetSharedMaxIndex()-1); diff --git a/sc/source/ui/unoobj/nameuno.cxx b/sc/source/ui/unoobj/nameuno.cxx index f77c9e6c900f..6d10ae67110c 100644 --- a/sc/source/ui/unoobj/nameuno.cxx +++ b/sc/source/ui/unoobj/nameuno.cxx @@ -99,6 +99,13 @@ sal_Bool lcl_UserVisibleName( const ScRangeData* pData ) return ( pData && !pData->HasType( RT_DATABASE ) && !pData->HasType( RT_SHARED ) ); } +bool lcl_UserVisibleName( const ScRangeData& rData ) +{ + //! als Methode an ScRangeData + + return !rData.HasType(RT_DATABASE) && !rData.HasType(RT_SHARED); +} + //------------------------------------------------------------------------ ScNamedRangeObj::ScNamedRangeObj(ScNamedRangesObj* pParent, ScDocShell* pDocSh, const String& rNm) : @@ -521,27 +528,23 @@ bool ScNamedRangesObj::IsModifyAndBroadcast() const ScNamedRangeObj* ScNamedRangesObj::GetObjectByIndex_Impl(sal_uInt16 nIndex) { - if (pDocShell) + if (!pDocShell) + return NULL; + + ScRangeName* pNames = pDocShell->GetDocument()->GetRangeName(); + if (!pNames) + return NULL; + + ScRangeName::const_iterator itr = pNames->begin(), itrEnd = pNames->end(); + sal_uInt16 nPos = 0; + for (; itr != itrEnd; ++itr) { - ScRangeName* pNames = pDocShell->GetDocument()->GetRangeName(); - if (pNames) + if (lcl_UserVisibleName(*itr)) { -#if NEW_RANGE_NAME -#else - sal_uInt16 nCount = pNames->GetCount(); - sal_uInt16 nPos = 0; - for (sal_uInt16 i=0; i<nCount; i++) - { - ScRangeData* pData = (*pNames)[i]; - if (lcl_UserVisibleName(pData)) // interne weglassen - { - if ( nPos == nIndex ) - return new ScNamedRangeObj(this, pDocShell, pData->GetName()); - ++nPos; - } - } -#endif + if (nPos == nIndex) + return new ScNamedRangeObj(this, pDocShell, itr->GetName()); } + ++nPos; } return NULL; } diff --git a/sc/source/ui/vba/vbarange.cxx b/sc/source/ui/vba/vbarange.cxx index b3c498d41e37..3dd34ca7854e 100644 --- a/sc/source/ui/vba/vbarange.cxx +++ b/sc/source/ui/vba/vbarange.cxx @@ -6002,7 +6002,6 @@ uno::Any SAL_CALL ScVbaRange::AdvancedFilter( sal_Int32 Action, const uno::Any& // CriteriaRange String aBuiltInCriteria; // Excel Built-In Filter Criteria. - ScRangeData* pData = NULL; table::CellRangeAddress refParentAddr; uno::Any aCriteriaRange = CriteriaRange; formula::FormulaGrammar::AddressConvention aConv = formula::FormulaGrammar::CONV_XL_A1; @@ -6016,19 +6015,18 @@ uno::Any SAL_CALL ScVbaRange::AdvancedFilter( sal_Int32 Action, const uno::Any& { // Get Excel BuiltIn Filter Criteria. ScRangeName* pRangeNames = pDoc->GetRangeName(); -#if NEW_RANGE_NAME -#else - const USHORT nCount = pRangeNames ? pRangeNames->GetCount() : 0; - for ( USHORT index = 0; index < nCount; index++ ) + if (pRangeNames) { - pData = ( ScRangeData* )( pRangeNames->At( index ) ); - if ( pData && pData->HasType( RT_CRITERIA ) ) + ScRangeName::const_iterator itr = pRangeNames->begin(), itrEnd = pRangeNames->end(); + for (; itr != itrEnd; ++itr) { - pData->GetSymbol( aBuiltInCriteria, formula::FormulaGrammar::GRAM_NATIVE_XL_A1 ); - break; + if (itr->HasType(RT_CRITERIA)) + { + itr->GetSymbol( aBuiltInCriteria, formula::FormulaGrammar::GRAM_NATIVE_XL_A1 ); + break; + } } } -#endif aCriteriaRange = aBuiltInCriteria.Len() > 0 ? uno::makeAny( rtl::OUString( aBuiltInCriteria ) ) : aCriteriaRange; } if ( aCriteriaRange.hasValue() ) diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx index cd080d49802f..059d27fa2649 100644 --- a/sc/source/ui/view/cellsh1.cxx +++ b/sc/source/ui/view/cellsh1.cxx @@ -2161,19 +2161,9 @@ void ScCellShell::ExecuteDataPilotDialog() ScRangeName* pRangeName = pDoc->GetRangeName(); if (pRangeName) { -#if NEW_RANGE_NAME -#else - USHORT n = pRangeName->GetCount(); - for (USHORT i = 0; i < n; ++i) - { - ScRangeData* p = (*pRangeName)[i]; - if (!p) - // This shouldn't happen, but just in case.... - continue; - - pTypeDlg->AppendNamedRange(p->GetName()); - } -#endif + ScRangeName::const_iterator itr = pRangeName->begin(), itrEnd = pRangeName->end(); + for (; itr != itrEnd; ++itr) + pTypeDlg->AppendNamedRange(itr->GetName()); } DBG_ASSERT(pTypeDlg, "Dialog create fail!"); |