summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kyoshida@novell.com>2011-03-05 02:55:07 -0500
committerKohei Yoshida <kyoshida@novell.com>2011-03-05 15:21:08 -0500
commit4af2fdbb9adc87193196146ea0a81fa3a48e253b (patch)
treec25e35426d895f333fdca278b700f160ee3a4dd7
parent1a92b2d9a40071c5a86f4f7c6aa405ca5affe433 (diff)
Reverted on index handling of range name objects.
-rw-r--r--sc/inc/document.hxx2
-rw-r--r--sc/inc/rangenam.hxx3
-rw-r--r--sc/source/core/data/documen2.cxx16
-rw-r--r--sc/source/core/data/document.cxx3
-rw-r--r--sc/source/core/tool/rangenam.cxx37
-rw-r--r--sc/source/ui/undo/undoblk3.cxx2
6 files changed, 35 insertions, 28 deletions
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index e30ab421e88f..ae8ef78ce9d7 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();
+ void EraseNonUsedSharedNames(USHORT nLevel);
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 361b6a51b90a..3e733f40ec8e 100644
--- a/sc/inc/rangenam.hxx
+++ b/sc/inc/rangenam.hxx
@@ -203,13 +203,12 @@ public:
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);
void UpdateTranspose(const ScRange& rSource, const ScAddress& rDest);
void UpdateGrow(const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY);
- SC_DLLPUBLIC ScRangeData* FindIndex(size_t i);
+ SC_DLLPUBLIC ScRangeData* FindIndex(USHORT i);
sal_uInt16 GetSharedMaxIndex();
void SetSharedMaxIndex(sal_uInt16 nInd);
diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx
index 04b81d918213..8a14e93f6dec 100644
--- a/sc/source/core/data/documen2.cxx
+++ b/sc/source/core/data/documen2.cxx
@@ -1132,7 +1132,7 @@ void ScDocument::SetError( SCCOL nCol, SCROW nRow, SCTAB nTab, const USHORT nErr
namespace {
-bool eraseUnusedSharedName(ScRangeName* pRangeName, ScTable* pTab[])
+bool eraseUnusedSharedName(ScRangeName* pRangeName, ScTable* pTab[], USHORT nLevel)
{
ScRangeName::const_iterator itr = pRangeName->begin(), itrEnd = pRangeName->end();
for (; itr != itrEnd; ++itr)
@@ -1140,11 +1140,15 @@ bool eraseUnusedSharedName(ScRangeName* pRangeName, ScTable* pTab[])
if (!itr->HasType(RT_SHARED))
continue;
- size_t nIndex;
- if (!pRangeName->getIndex(*itr, nIndex))
- // index not found.
+ String aName;
+ itr->GetName(aName);
+ aName.Erase(0, 6); // !!! vgl. Table4, FillFormula !!
+ USHORT nInd = static_cast<USHORT>(aName.ToInt32());
+ if (nInd > nLevel)
continue;
+ USHORT nIndex = itr->GetIndex();
+
bool bInUse = false;
for (SCTAB j = 0; !bInUse && (j <= MAXTAB); ++j)
{
@@ -1162,9 +1166,9 @@ bool eraseUnusedSharedName(ScRangeName* pRangeName, ScTable* pTab[])
}
-void ScDocument::EraseNonUsedSharedNames()
+void ScDocument::EraseNonUsedSharedNames(USHORT nLevel)
{
- while (eraseUnusedSharedName(pRangeName, pTab))
+ while (eraseUnusedSharedName(pRangeName, pTab, nLevel))
;
}
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 222930028a5c..00b1420eb275 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -1710,11 +1710,12 @@ void ScDocument::TransposeClip( ScDocument* pTransClip, USHORT nFlags, BOOL bAsL
ScRangeName::const_iterator itr = pRangeName->begin(), itrEnd = pRangeName->end();
for (; itr != itrEnd; ++itr)
{
+ USHORT nIndex = itr->GetIndex();
ScRangeData* pData = new ScRangeData(*itr);
if (!pTransClip->pRangeName->insert(pData))
delete pData;
else
- pData->SetIndex(0);
+ pData->SetIndex(nIndex);
}
// The data
diff --git a/sc/source/core/tool/rangenam.cxx b/sc/source/core/tool/rangenam.cxx
index c05105e64ba0..800a376b2462 100644
--- a/sc/source/core/tool/rangenam.cxx
+++ b/sc/source/core/tool/rangenam.cxx
@@ -724,16 +724,6 @@ 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();
@@ -774,14 +764,13 @@ void ScRangeName::UpdateGrow(const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY)
itr->UpdateGrow(rArea, nGrowX, nGrowY);
}
-ScRangeData* ScRangeName::FindIndex(size_t i)
+ScRangeData* ScRangeName::FindIndex(USHORT i)
{
- if (i >= maData.size())
- return NULL;
-
- DataType::iterator itr = maData.begin();
- ::std::advance(itr, i);
- return &(*itr);
+ DataType::iterator itr = maData.begin(), itrEnd = maData.end();
+ for (; itr != itrEnd; ++itr)
+ if (itr->GetIndex() == i)
+ return &(*itr);
+ return NULL;
}
sal_uInt16 ScRangeName::GetSharedMaxIndex()
@@ -829,6 +818,20 @@ bool ScRangeName::insert(ScRangeData* p)
if (!p)
return false;
+ if (!p->GetIndex())
+ {
+ // Assign a new index. An index must be unique.
+ USHORT nHigh = 0;
+ DataType::const_iterator itr = maData.begin(), itrEnd = maData.end();
+ for (; itr != itrEnd; ++itr)
+ {
+ USHORT n = itr->GetIndex();
+ if (n > nHigh)
+ nHigh = n;
+ }
+ p->SetIndex(nHigh + 1);
+ }
+
pair<DataType::iterator, bool> r = maData.insert(p);
return r.second;
}
diff --git a/sc/source/ui/undo/undoblk3.cxx b/sc/source/ui/undo/undoblk3.cxx
index f5b766b17a7d..eb3987ff42d9 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();
+ pDocShell->GetDocument()->EraseNonUsedSharedNames(nMaxSharedIndex);
delete pUndoDoc;
}