Date: prev next · Thread: first prev next last
2011 Archives by date, by thread · List index


Hi there,

Markus has been working on the easy hack to support one autofilter per
sheet, instead of per document, and it is to a state where it is fairly
usable.  The patch against the current master is attached.

I also would like to confirm that he is submitting this patch under
LGPLv3+/MPL dual license.  Markus, could you give us a quick
confirmation?

We have been working on this on and off to sort out many issues, and I'm
happy to see his work finally coming to fruition.  What I would like to
do from this point on is to give it more intensive testing to weed out
any remaining issues and extra polish, and hopefully get this piece in
for 3.4.

Regards,

Kohei

-- 
Kohei Yoshida, LibreOffice hacker, Calc
<kyoshida@novell.com>
diff --git a/sc/inc/dbcolect.hxx b/sc/inc/dbcolect.hxx
index 859b858..1b40d9e 100644
--- a/sc/inc/dbcolect.hxx
+++ b/sc/inc/dbcolect.hxx
@@ -176,6 +176,13 @@ public:
 
             sal_Bool           IsModified() const                      { return bModified; }
             void               SetModified(sal_Bool bMod)              { bModified = bMod; }
+
+            void       UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos );
+            void       UpdateReference(UpdateRefMode eUpdateRefMode,
+                                SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
+                                SCCOL nCol2, SCROW nRow2, SCTAB nTab2,
+                                SCsCOL nDx, SCsROW nDy, SCsTAB nDz,
+                                ScDocument* pDoc  );
 };
 
 
@@ -206,6 +213,7 @@ public:
     virtual    sal_Bool                IsEqual(ScDataObject* pKey1, ScDataObject* pKey2) const;
             ScDBData*  GetDBAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab, sal_Bool bStartOnly) 
const;
             ScDBData*  GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2) 
const;
+            ScDBData*   GetDBNearCursor(SCCOL nCol, SCROW nRow, SCTAB nTab );
 
     sal_Bool   SearchName( const String& rName, sal_uInt16& rIndex ) const;
 
@@ -213,7 +221,7 @@ public:
     void       UpdateReference(UpdateRefMode eUpdateRefMode,
                                 SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
                                 SCCOL nCol2, SCROW nRow2, SCTAB nTab2,
-                                SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
+                                SCsCOL nDx, SCsROW nDy, SCsTAB nDz);
     void       UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos );
 
     ScDBData* FindIndex(sal_uInt16 nIndex);
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index bec764d..ba341a3 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -525,6 +525,10 @@ public:
     SC_DLLPUBLIC sal_Bool                      GetCodeName( SCTAB nTab, String& rName ) const;
     SC_DLLPUBLIC sal_Bool                   SetCodeName( SCTAB nTab, const String& rName );
     SC_DLLPUBLIC sal_Bool                      GetTable( const String& rName, SCTAB& rTab ) const;
+
+    void            SetAnonymousDBData(SCTAB nTab, ScDBData* pDBData);
+    ScDBData*       GetAnonymousDBData(SCTAB nTab);
+
     SC_DLLPUBLIC inline SCTAB  GetTableCount() const { return nMaxTableNumber; }
     SvNumberFormatterIndexTable* GetFormatExchangeList() const { return pFormatExchangeList; }
 
diff --git a/sc/inc/globalnames.hxx b/sc/inc/globalnames.hxx
new file mode 100644
index 0000000..6fb983a
--- /dev/null
+++ b/sc/inc/globalnames.hxx
@@ -0,0 +1,34 @@
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Initial Developer of the Original Code is
+ *       Markus Mohrhard <markus.mohrhard@googlemail.com>
+ * Portions created by the Initial Developer are Copyright (C) 2010 the
+ * Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s): Kohei Yoshida <kyoshida@novell.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+#ifndef __SC_GLOBALNAMES_HXX__
+#define __SC_GLOBALNAMES_HXX__
+
+#define STR_DB_LOCAL_NONAME  "unnamed"
+#define STR_DB_GLOBAL_NONAME "unnamed"
+
+#endif
diff --git a/sc/inc/rangeutl.hxx b/sc/inc/rangeutl.hxx
index 98490f5..9db1155 100644
--- a/sc/inc/rangeutl.hxx
+++ b/sc/inc/rangeutl.hxx
@@ -304,7 +304,6 @@ public:
 class SC_DLLPUBLIC ScAreaNameIterator
 {
 private:
-    String          aStrNoName;
     ScRangeName*       pRangeName;
     ScRangeName::const_iterator maRNPos;
     ScRangeName::const_iterator maRNEnd;
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 75a2e59..d99cd18 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -38,6 +38,7 @@
 #include "column.hxx"
 #include "sortparam.hxx"
 #include "compressedarray.hxx"
+#include "dbcolect.hxx"
 
 #include <memory>
 #include <set>
@@ -187,6 +188,7 @@ private:
     Color           aTabBgColor;
     sal_uInt16                 nScenarioFlags;
     sal_Bool                   bActiveScenario;
+    ScDBData*       pDBDataNoName;
     mutable ScRangeName* mpRangeName;
     bool            mbPageBreaksValid;
 
@@ -270,6 +272,9 @@ public:
     void               GetName( String& rName ) const;
     void               SetName( const String& rNewName );
 
+    void        SetAnonymousDBData(ScDBData* aDBData);
+    ScDBData*      GetAnonymousDBData();
+
     void               GetCodeName( String& rName ) const {  rName = aCodeName; }
     void               SetCodeName( const String& rNewName ) { aCodeName = rNewName; }
 
@@ -795,6 +800,7 @@ public:
 
     void SetRangeName(ScRangeName* pNew);
     ScRangeName* GetRangeName() const;
+    void        UpdateMoveTab(SCTAB nOldPos,SCTAB nNewPos);
 
 private:
     void               FillSeries( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index e8f9a8c..bb881a0 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -218,6 +218,16 @@ sal_Bool ScDocument::GetTable( const String& rName, SCTAB& rTab ) const
     return false;
 }
 
+ScDBData* ScDocument::GetAnonymousDBData(SCTAB nTab)
+{
+    return pTab[nTab]->GetAnonymousDBData();
+}
+
+void ScDocument::SetAnonymousDBData(SCTAB nTab, ScDBData* pDBData)
+{
+    pTab[nTab]->SetAnonymousDBData(pDBData);
+}
+
 
 bool ScDocument::ValidTabName( const String& rName )
 {
@@ -4843,6 +4853,24 @@ sal_Bool ScDocument::RefreshAutoFilter( SCCOL nStartCol, SCROW nStartRow,
             }
         }
     }
+    if (pTab[nTab])
+        pData = pTab[nTab]->GetAnonymousDBData();
+    else
+        pData=NULL;
+    if (pData)
+    {
+        if (pData->HasAutoFilter())
+        {
+            pData->GetArea( nDBTab, nDBStartCol,nDBStartRow, nDBEndCol,nDBEndRow );
+            if ( nDBTab==nTab && nDBStartRow<=nEndRow && nDBEndRow>=nStartRow &&
+                                    nDBStartCol<=nEndCol && nDBEndCol>=nStartCol )
+            {
+                if (ApplyFlagsTab( nDBStartCol,nDBStartRow, nDBEndCol,nDBStartRow,
+                                    nDBTab, SC_MF_AUTO ))
+                    bChange = sal_True;
+            }
+        }
+    }
     return bChange;
 }
 
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index b36f5e7..c49f286 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -272,6 +272,7 @@ ScTable::ScTable( ScDocument* pDoc, SCTAB nNewTab, const String& rNewName,
     aTabBgColor( COL_AUTO ),
     nScenarioFlags( 0 ),
     bActiveScenario( false ),
+    pDBDataNoName(NULL),
     mpRangeName(NULL),
     mbPageBreaksValid(false)
 {
@@ -341,6 +342,7 @@ ScTable::~ScTable()
     delete pRepeatRowRange;
     delete pScenarioRanges;
     delete mpRangeName;
+    delete pDBDataNoName;
     DestroySortCollator();
 }
 
@@ -1433,6 +1435,8 @@ void ScTable::UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos, SCTAB nTabNo,
 
     if (IsStreamValid())
         SetStreamValid(false);
+   if (pDBDataNoName)
+        pDBDataNoName->UpdateMoveTab(nOldPos, nNewPos);
 }
 
 void ScTable::UpdateCompile( sal_Bool bForceIfNameInUse )
@@ -1807,4 +1811,17 @@ SCROW ScTable::VisibleDataCellIterator::getRow() const
     return mnCurRow;
 }
 
+void ScTable::SetAnonymousDBData(ScDBData* aDBData)
+{
+    //don't delete old dbdata, will still be used by undo/redo
+    if (!(rtl::OUString(aDBData->GetName()) == 
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("unnamed"))))
+        OSL_FAIL("Falscher Name für lokale DB");
+    pDBDataNoName = aDBData;
+}
+
+ScDBData* ScTable::GetAnonymousDBData()
+{
+    return pDBDataNoName;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index 7d6a41e..b59270d 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -472,6 +472,8 @@ void ScTable::CopyToClip(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
 
         pTable->CopyColHidden(*this, 0, nCol2);
         pTable->CopyColFiltered(*this, 0, nCol2);
+        if (pDBDataNoName)
+            pTable->SetAnonymousDBData(new ScDBData(*pDBDataNoName));
 
         if (pRowFlags && pTable->pRowFlags && mpRowHeights && pTable->mpRowHeights)
         {
@@ -759,6 +761,8 @@ void ScTable::CopyToTable(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
     if (!bColRowFlags)         // Spaltenbreiten/Zeilenhoehen/Flags
         return;
 
+    if (pDBDataNoName)
+        pDestTab->SetAnonymousDBData(new ScDBData(*pDBDataNoName));
     // Charts muessen beim Ein-/Ausblenden angepasst werden
     ScChartListenerCollection* pCharts = pDestTab->pDocument->GetChartListenerCollection();
 
diff --git a/sc/source/core/tool/dbcolect.cxx b/sc/source/core/tool/dbcolect.cxx
index 95beb37..9294e58 100644
--- a/sc/source/core/tool/dbcolect.cxx
+++ b/sc/source/core/tool/dbcolect.cxx
@@ -35,6 +35,7 @@
 
 #include "dbcolect.hxx"
 #include "global.hxx"
+#include "globalnames.hxx"
 #include "refupdat.hxx"
 #include "rechead.hxx"
 #include "document.hxx"
@@ -579,7 +580,79 @@ ScDataObject*      ScDBData::Clone() const
     return new ScDBData(*this);
 }
 
+void ScDBData::UpdateMoveTab(SCTAB nOldPos, SCTAB nNewPos)
+{
+        ScRange aRange;
+        GetArea( aRange );
+        SCTAB nTab = aRange.aStart.Tab();                              // hat nur eine Tabelle
+
+        //     anpassen wie die aktuelle Tabelle bei ScTablesHint (tabvwsh5.cxx)
+
+        if ( nTab == nOldPos )                                                 // verschobene 
Tabelle
+            nTab = nNewPos;
+        else if ( nOldPos < nNewPos )                                  // nach hinten verschoben
+        {
+            if ( nTab > nOldPos && nTab <= nNewPos )   // nachrueckender Bereich
+                --nTab;
+        }
+        else                                                                                   // 
nach vorne verschoben
+        {
+            if ( nTab >= nNewPos && nTab < nOldPos )   // nachrueckender Bereich
+                ++nTab;
+        }
+
+        sal_Bool bChanged = ( nTab != aRange.aStart.Tab() );
+        if (bChanged)
+            SetArea( nTab, aRange.aStart.Col(), aRange.aStart.Row(),
+                                    aRange.aEnd.Col(),aRange.aEnd .Row() );
+
+        //     MoveTo ist nicht noetig, wenn nur die Tabelle geaendert ist
+
+        SetModified(bChanged);
+
+}
+
+void ScDBData::UpdateReference(UpdateRefMode eUpdateRefMode,
+                                SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
+                                SCCOL nCol2, SCROW nRow2, SCTAB nTab2,
+                                SCsCOL nDx, SCsROW nDy, SCsTAB nDz,
+                                ScDocument* pDoc )
+{
+    SCCOL theCol1;
+    SCROW theRow1;
+    SCTAB theTab1;
+    SCCOL theCol2;
+    SCROW theRow2;
+    SCTAB theTab2;
+    GetArea( theTab1, theCol1, theRow1, theCol2, theRow2 );
+    theTab2 = theTab1;
+
+    sal_Bool bDoUpdate = ScRefUpdate::Update( pDoc, eUpdateRefMode,
+                                            nCol1,nRow1,nTab1, nCol2,nRow2,nTab2, nDx,nDy,nDz,
+                                            theCol1,theRow1,theTab1, theCol2,theRow2,theTab2 ) != 
UR_NOTHING;
+    if (bDoUpdate)
+        MoveTo( theTab1, theCol1, theRow1, theCol2, theRow2 );
+
+    ScRange aRangeAdvSource;
+    if ( GetAdvancedQuerySource(aRangeAdvSource) )
+    {
+        aRangeAdvSource.GetVars( theCol1,theRow1,theTab1, theCol2,theRow2,theTab2 );
+        if ( ScRefUpdate::Update( pDoc, eUpdateRefMode,
+                                    nCol1,nRow1,nTab1, nCol2,nRow2,nTab2, nDx,nDy,nDz,
+                                    theCol1,theRow1,theTab1, theCol2,theRow2,theTab2 ) )
+        {
+            aRangeAdvSource.aStart.Set( theCol1,theRow1,theTab1 );
+            aRangeAdvSource.aEnd.Set( theCol2,theRow2,theTab2 );
+            SetAdvancedQuerySource( &aRangeAdvSource );
 
+            bDoUpdate = sal_True;              // DBData is modified
+        }
+    }
+
+    SetModified(bDoUpdate);
+
+    //!                Testen, ob mitten aus dem Bereich geloescht/eingefuegt wurde !!!
+}
 //---------------------------------------------------------------------------------------
 //     Compare zum Sortieren
 
@@ -599,46 +672,46 @@ sal_Bool ScDBCollection::IsEqual(ScDataObject* pKey1, ScDataObject* pKey2) 
const
 
 ScDBData* ScDBCollection::GetDBAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab, sal_Bool bStartOnly) 
const
 {
-    ScDBData* pNoNameData = NULL;
+    ScDBData* pNoNameData = pDoc->GetAnonymousDBData(nTab);
     if (pItems)
     {
-        const String& rNoName = ScGlobal::GetRscString( STR_DB_NONAME );
-
         for (sal_uInt16 i = 0; i < nCount; i++)
+        {
             if (((ScDBData*)pItems[i])->IsDBAtCursor(nCol, nRow, nTab, bStartOnly))
             {
                 ScDBData* pDB = (ScDBData*)pItems[i];
-                if ( pDB->GetName() == rNoName )
-                    pNoNameData = pDB;
-                else
-                    return pDB;
+                return pDB; //return AnonymousDBData only if nothing else was found
             }
+        }    
     }
-    return pNoNameData;                                // "unbenannt" nur zurueck, wenn sonst 
nichts gefunden
+    if (pNoNameData)
+        if (pNoNameData->IsDBAtCursor(nCol,nRow,nTab,bStartOnly))
+            return pNoNameData;
+    return NULL;
 }
 
 ScDBData* ScDBCollection::GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW 
nRow2) const
 {
-    ScDBData* pNoNameData = NULL;
+    ScDBData* pNoNameData = pDoc->GetAnonymousDBData(nTab);
     if (pItems)
     {
-        const String& rNoName = ScGlobal::GetRscString( STR_DB_NONAME );
-
         for (sal_uInt16 i = 0; i < nCount; i++)
             if (((ScDBData*)pItems[i])->IsDBAtArea(nTab, nCol1, nRow1, nCol2, nRow2))
             {
                 ScDBData* pDB = (ScDBData*)pItems[i];
-                if ( pDB->GetName() == rNoName )
-                    pNoNameData = pDB;
-                else
-                    return pDB;
+                return pDB; //return AnonymousDBData only if nothing else was found
             }
     }
-    return pNoNameData;                                // "unbenannt" nur zurueck, wenn sonst 
nichts gefunden
+    if (pNoNameData)
+        if (pNoNameData->IsDBAtArea(nTab, nCol1, nRow1, nCol2, nRow2))
+            return pNoNameData;
+    return NULL;       
 }
 
 sal_Bool ScDBCollection::SearchName( const String& rName, sal_uInt16& rIndex ) const
 {
+    if (rtl::OUString(rName)==rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(STR_DB_LOCAL_NONAME)))
+        DBG_ASSERT(false,"search for noname string");
     ScDBData aDataObj( rName, 0,0,0,0,0 );
     return Search( &aDataObj, rIndex );
 }
@@ -668,40 +741,25 @@ void ScDBCollection::UpdateReference(UpdateRefMode eUpdateRefMode,
 {
     for (sal_uInt16 i=0; i<nCount; i++)
     {
-        SCCOL theCol1;
-        SCROW theRow1;
-        SCTAB theTab1;
-        SCCOL theCol2;
-        SCROW theRow2;
-        SCTAB theTab2;
-        ((ScDBData*)pItems[i])->GetArea( theTab1, theCol1, theRow1, theCol2, theRow2 );
-        theTab2 = theTab1;
-
-        sal_Bool bDoUpdate = ScRefUpdate::Update( pDoc, eUpdateRefMode,
-                                                nCol1,nRow1,nTab1, nCol2,nRow2,nTab2, nDx,nDy,nDz,
-                                                theCol1,theRow1,theTab1, theCol2,theRow2,theTab2 ) 
!= UR_NOTHING;
-        if (bDoUpdate)
-            ((ScDBData*)pItems[i])->MoveTo( theTab1, theCol1, theRow1, theCol2, theRow2 );
-
-        ScRange aAdvSource;
-        if ( ((ScDBData*)pItems[i])->GetAdvancedQuerySource(aAdvSource) )
+        ((ScDBData*)pItems[i])->UpdateReference(eUpdateRefMode,
+                                                nCol1, nRow1, nTab1,
+                                                nCol2, nRow2, nTab2,
+                                                nDx, nDy, nDz, pDoc);
+    }
+    ScDBData* pData = pDoc->GetAnonymousDBData(nTab1);
+    if (pData)
+    {
+        if (nTab1==nTab2&&nDz==0)
         {
-            aAdvSource.GetVars( theCol1,theRow1,theTab1, theCol2,theRow2,theTab2 );
-            if ( ScRefUpdate::Update( pDoc, eUpdateRefMode,
-                                        nCol1,nRow1,nTab1, nCol2,nRow2,nTab2, nDx,nDy,nDz,
-                                        theCol1,theRow1,theTab1, theCol2,theRow2,theTab2 ) )
-            {
-                aAdvSource.aStart.Set( theCol1,theRow1,theTab1 );
-                aAdvSource.aEnd.Set( theCol2,theRow2,theTab2 );
-                ((ScDBData*)pItems[i])->SetAdvancedQuerySource( &aAdvSource );
-
-                bDoUpdate = sal_True;          // DBData is modified
-            }
+            pData->UpdateReference(eUpdateRefMode,
+                                                nCol1, nRow1, nTab1,
+                                                nCol2, nRow2, nTab2,
+                                                nDx, nDy, nDz, pDoc);
+        }
+        else
+        {
+            //this will perhabs break undo
         }
-
-        ((ScDBData*)pItems[i])->SetModified(bDoUpdate);
-
-        //!            Testen, ob mitten aus dem Bereich geloescht/eingefuegt wurde !!!
     }
 }
 
@@ -712,34 +770,8 @@ void ScDBCollection::UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos )
 
     for (sal_uInt16 i=0; i<nCount; i++)
     {
-        ScRange aRange;
         ScDBData* pData = (ScDBData*)pItems[i];
-        pData->GetArea( aRange );
-        SCTAB nTab = aRange.aStart.Tab();                              // hat nur eine Tabelle
-
-        //     anpassen wie die aktuelle Tabelle bei ScTablesHint (tabvwsh5.cxx)
-
-        if ( nTab == nOldPos )                                                 // verschobene 
Tabelle
-            nTab = nNewPos;
-        else if ( nOldPos < nNewPos )                                  // nach hinten verschoben
-        {
-            if ( nTab > nOldPos && nTab <= nNewPos )   // nachrueckender Bereich
-                --nTab;
-        }
-        else                                                                                   // 
nach vorne verschoben
-        {
-            if ( nTab >= nNewPos && nTab < nOldPos )   // nachrueckender Bereich
-                ++nTab;
-        }
-
-        sal_Bool bChanged = ( nTab != aRange.aStart.Tab() );
-        if (bChanged)
-            pData->SetArea( nTab, aRange.aStart.Col(), aRange.aStart.Row(),
-                                    aRange.aEnd.Col(),aRange.aEnd .Row() );
-
-        //     MoveTo ist nicht noetig, wenn nur die Tabelle geaendert ist
-
-        pData->SetModified(bChanged);
+        pData->UpdateMoveTab(nOldPos, nNewPos);
     }
 }
 
@@ -770,7 +802,32 @@ sal_Bool ScDBCollection::Insert(ScDataObject* pScDataObject)
     return bInserted;
 }
 
-
+ScDBData* ScDBCollection::GetDBNearCursor(SCCOL nCol, SCROW nRow, SCTAB nTab )
+{
+    ScDBData* pNearData = NULL;
+    SCTAB nAreaTab;
+    SCCOL nStartCol, nEndCol;
+    SCROW nStartRow, nEndRow;
+    for (sal_uInt16 i = 0; i < nCount; i++)
+    {
+        ScDBData* pDB = (ScDBData*)pItems[i];
+        pDB->GetArea( nAreaTab, nStartCol, nStartRow, nEndCol, nEndRow );
+        if ( nTab == nAreaTab && nCol+1 >= nStartCol && nCol <= nEndCol+1 &&
+                                 nRow+1 >= nStartRow && nRow <= nEndRow+1 )
+        {
+            if ( nCol < nStartCol || nCol > nEndCol || nRow < nStartRow || nRow > nEndRow )
+            {
+                if (!pNearData)
+                    pNearData = pDB;   // ersten angrenzenden Bereich merken
+            }
+            else
+                return pDB;                            // nicht "unbenannt" und Cursor steht 
wirklich drin
+        }
+    }
+    if (pNearData)
+        return pNearData;                              // angrenzender, wenn nichts direkt 
getroffen
+    return pDoc->GetAnonymousDBData(nTab);                                     // "unbenannt" nur 
zurueck, wenn sonst nichts gefunden
+}
 
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/tool/rangeutl.cxx b/sc/source/core/tool/rangeutl.cxx
index dbb074f..72bd8d6 100644
--- a/sc/source/core/tool/rangeutl.cxx
+++ b/sc/source/core/tool/rangeutl.cxx
@@ -1037,7 +1037,6 @@ sal_Bool ScArea::operator==( const ScArea& r ) const
 //------------------------------------------------------------------------
 
 ScAreaNameIterator::ScAreaNameIterator( ScDocument* pDoc ) :
-    aStrNoName(ScGlobal::GetRscString(STR_DB_NONAME)),
     pRangeName(pDoc->GetRangeName()),
     pDBCollection(pDoc->GetDBCollection()),
     bFirstPass(true),
@@ -1079,12 +1078,9 @@ sal_Bool ScAreaNameIterator::Next( String& rName, ScRange& rRange )
             if ( pDBCollection && nPos < pDBCollection->GetCount() )
             {
                 ScDBData* pData = (*pDBCollection)[nPos++];
-                if (pData && pData->GetName() != aStrNoName)
-                {
-                    pData->GetArea( rRange );
-                    rName = pData->GetName();
-                    return sal_True;                                                   // gefunden
-                }
+                pData->GetArea( rRange );
+                rName = pData->GetName();
+                return sal_True;                                                       // gefunden
             }
             else
                 return false;                                                          // gibt 
nichts mehr
diff --git a/sc/source/filter/xml/XMLExportDatabaseRanges.cxx 
b/sc/source/filter/xml/XMLExportDatabaseRanges.cxx
index 4d9ef16..6b099f2 100644
--- a/sc/source/filter/xml/XMLExportDatabaseRanges.cxx
+++ b/sc/source/filter/xml/XMLExportDatabaseRanges.cxx
@@ -44,6 +44,7 @@
 #include "dbcolect.hxx"
 #include "document.hxx"
 #include "globstr.hrc"
+#include "globalnames.hxx"
 #include "XMLExportSharedData.hxx"
 #include "rangeutl.hxx"
 #include "subtotalparam.hxx"
@@ -591,17 +592,26 @@ void ScXMLExportDatabaseRanges::WriteDatabaseRanges(const 
com::sun::star::uno::R
                         uno::Reference <sheet::XDatabaseRange> 
xDatabaseRange(xDatabaseRanges->getByName(sDatabaseRangeName), uno::UNO_QUERY);
                         if (xDatabaseRange.is())
                         {
-                            rtl::OUString sOUUnbenannt (ScGlobal::GetRscString(STR_DB_NONAME));
-                            if (sOUUnbenannt != sDatabaseRangeName)
-                                rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_NAME, 
sDatabaseRangeName);
+                            rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_NAME, 
sDatabaseRangeName);
                             table::CellRangeAddress aRangeAddress(xDatabaseRange->getDataArea());
                             rtl::OUString sOUAddress;
                             ScRangeStringConverter::GetStringFromRange( sOUAddress, aRangeAddress, 
pDoc, ::formula::FormulaGrammar::CONV_OOO );
                             rExport.AddAttribute (XML_NAMESPACE_TABLE, XML_TARGET_RANGE_ADDRESS, 
sOUAddress);
                             ScDBCollection* pDBCollection = pDoc->GetDBCollection();
-                            sal_uInt16 nIndex;
-                            pDBCollection->SearchName(sDatabaseRangeName, nIndex);
-                            ScDBData* pDBData = (*pDBCollection)[nIndex];
+
+                            ScDBData* pDBData= NULL;
+                            if 
(sDatabaseRangeName.match(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(STR_DB_LOCAL_NONAME))))
+                            {
+                                rtl::OUString aDBNoName = 
sDatabaseRangeName.replaceAt(0,rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(STR_DB_LOCAL_NONAME)).getLength(),rtl::OUString());
+                                SCTAB nTab = aDBNoName.toInt32();;
+                                pDBData=pDoc->GetAnonymousDBData(nTab);
+                            }
+                            else
+                            {
+                                sal_uInt16 nIndex;
+                                pDBCollection->SearchName(sDatabaseRangeName, nIndex);
+                                pDBData = (*pDBCollection)[nIndex];
+                            }
                             if (pDBData->HasImportSelection())
                                 rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_IS_SELECTION, 
XML_TRUE);
                             if (pDBData->HasAutoFilter())
diff --git a/sc/source/filter/xml/xmldrani.cxx b/sc/source/filter/xml/xmldrani.cxx
index 9bf45a5..aff95e5 100644
--- a/sc/source/filter/xml/xmldrani.cxx
+++ b/sc/source/filter/xml/xmldrani.cxx
@@ -39,6 +39,7 @@
 #include "xmlsorti.hxx"
 #include "document.hxx"
 #include "globstr.hrc"
+#include "globalnames.hxx"
 #include "docuno.hxx"
 #include "dbcolect.hxx"
 #include "datauno.hxx"
@@ -121,7 +122,7 @@ ScXMLDatabaseRangeContext::ScXMLDatabaseRangeContext( ScXMLImport& rImport,
                                       const ::com::sun::star::uno::Reference<
                                       ::com::sun::star::xml::sax::XAttributeList>& xAttrList) :
     SvXMLImportContext( rImport, nPrfx, rLName ),
-    sDatabaseRangeName(ScGlobal::GetRscString(STR_DB_NONAME)),
+    sDatabaseRangeName(RTL_CONSTASCII_USTRINGPARAM(STR_DB_LOCAL_NONAME)),
     aSortSequence(),
     eOrientation(table::TableOrientation_ROWS),
     nRefresh(0),
@@ -344,10 +345,31 @@ void ScXMLDatabaseRangeContext::EndElement()
                                 else if (aImportDescriptor[i].Name == 
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_ISNATIVE)))
                                     aImportDescriptor[i].Value <<= bNative;
                             }
+                            ScDBData* pDBData = NULL;
                             ScDBCollection* pDBCollection = pDoc->GetDBCollection();
-                            sal_uInt16 nIndex;
-                            pDBCollection->SearchName(sDatabaseRangeName, nIndex);
-                            ScDBData* pDBData = (*pDBCollection)[nIndex];
+                            rtl::OUString 
aLocalNoName(RTL_CONSTASCII_USTRINGPARAM(STR_DB_LOCAL_NONAME));
+                            rtl::OUString 
aGlobalNoName(RTL_CONSTASCII_USTRINGPARAM(STR_DB_GLOBAL_NONAME));
+                            if 
(sDatabaseRangeName.match(aLocalNoName)||sDatabaseRangeName==aGlobalNoName)
+                            {
+                                SCTAB nTab = 0;
+                                if (sDatabaseRangeName==aGlobalNoName)//convert old global 
anonymous db ranges to new sheet local ones
+                                {
+                                    nTab = static_cast<SCTAB> (aCellRangeAddress.Sheet);
+                                }
+                                else
+                                {
+                                    rtl::OUString aDBNoName(sDatabaseRangeName);
+                                    aDBNoName = 
aDBNoName.replaceAt(0,aLocalNoName.getLength(),rtl::OUString());
+                                    nTab = aDBNoName.toInt32();
+                                }
+                                pDBData = pDoc->GetAnonymousDBData(nTab);
+                            }
+                            else
+                            {
+                                sal_uInt16 nIndex;
+                                pDBCollection->SearchName(sDatabaseRangeName, nIndex);
+                                pDBData = (*pDBCollection)[nIndex];
+                            }
                             pDBData->SetImportSelection(bIsSelection);
                             pDBData->SetAutoFilter(bAutoFilter);
                             if (bAutoFilter)
diff --git a/sc/source/ui/dbgui/dbnamdlg.cxx b/sc/source/ui/dbgui/dbnamdlg.cxx
index 381d658..94bbc92 100644
--- a/sc/source/ui/dbgui/dbnamdlg.cxx
+++ b/sc/source/ui/dbgui/dbnamdlg.cxx
@@ -43,6 +43,7 @@
 #include "globstr.hrc"
 #include "dbnamdlg.hrc"
 #include "rangenam.hxx"                // IsNameValid
+#include "globalnames.hxx"
 
 #define _DBNAMDLG_CXX
 #include "dbnamdlg.hxx"
@@ -165,7 +166,7 @@ ScDbNameDlg::ScDbNameDlg( SfxBindings* pB, SfxChildWindow* pCW, Window* pParent,
 
         aStrAdd                        ( ScResId( STR_ADD ) ),
         aStrModify             ( ScResId( STR_MODIFY ) ),
-        aStrNoName             ( ScGlobal::GetRscString(STR_DB_NONAME) ),
+        aStrNoName             ( RTL_CONSTASCII_USTRINGPARAM(STR_DB_LOCAL_NONAME)),
         aStrInvalid            ( ScResId( STR_DB_INVALID ) ),
         //
         pViewData              ( ptrViewData ),
@@ -272,7 +273,7 @@ void ScDbNameDlg::Init()
                     && (rEnd.Col()   == nCol2) && (rEnd.Row()   == nRow2 ) )
                 {
                     pDBData->GetName( theDbName );
-                    if ( theDbName != aStrNoName )
+                    if (theDbName!=aStrNoName )
                         aEdName.SetText( theDbName );
                     else
                         aEdName.SetText( EMPTY_STRING );
@@ -384,7 +385,7 @@ void ScDbNameDlg::UpdateNames()
             if ( pDbData )
             {
                 pDbData->GetName( aString );
-                if ( aString != aStrNoName )
+                if (aString!=aStrNoName )
                     aEdName.InsertEntry( aString );
             }
         }
diff --git a/sc/source/ui/dbgui/foptmgr.cxx b/sc/source/ui/dbgui/foptmgr.cxx
index ba56e44..cb1bbb9 100644
--- a/sc/source/ui/dbgui/foptmgr.cxx
+++ b/sc/source/ui/dbgui/foptmgr.cxx
@@ -111,6 +111,7 @@ ScFilterOptionsMgr::~ScFilterOptionsMgr()
 
 void ScFilterOptionsMgr::Init()
 {
+//moggi:TODO
     DBG_ASSERT( pViewData && pDoc, "Init failed :-/" );
 
     rLbCopyPos.SetSelectHdl     ( LINK( this, ScFilterOptionsMgr, LbPosSelHdl ) );
@@ -191,7 +192,7 @@ void ScFilterOptionsMgr::Init()
                 rBtnHeader.Check( pDBData->HasHeader() );
                 pDBData->GetName( theDbName );
 
-                if ( theDbName != rStrNoName )
+                if ( theDbName!=rStrNoName )
                 {
                     rBtnHeader.Disable();
                 }
diff --git a/sc/source/ui/dbgui/pfiltdlg.cxx b/sc/source/ui/dbgui/pfiltdlg.cxx
index 799fa04..9f59d42 100644
--- a/sc/source/ui/dbgui/pfiltdlg.cxx
+++ b/sc/source/ui/dbgui/pfiltdlg.cxx
@@ -43,6 +43,7 @@
 #include "document.hxx"
 #include "uiitems.hxx"
 #include "global.hxx"
+#include "globalnames.hxx"
 #include "dbcolect.hxx"
 #include "scresid.hxx"
 
@@ -90,7 +91,6 @@ ScPivotFilterDlg::ScPivotFilterDlg( Window*                           pParent,
         aBtnHelp               ( this, ScResId( BTN_HELP ) ),
         aBtnMore               ( this, ScResId( BTN_MORE ) ),
         aStrUndefined  ( ScResId( SCSTR_UNDEFINED ) ),
-        aStrNoName             ( ScGlobal::GetRscString(STR_DB_NONAME) ),
         aStrNone               ( ScResId( SCSTR_NONE ) ),
         aStrEmpty              ( ScResId( SCSTR_EMPTY ) ),
         aStrNotEmpty   ( ScResId( SCSTR_NOTEMPTY ) ),
@@ -175,7 +175,7 @@ void ScPivotFilterDlg::Init( const SfxItemSet& rArgSet )
                                                 nSrcTab ) );
         ScDBCollection*        pDBColl         = pDoc->GetDBCollection();
         String                 theDbArea;
-        String                 theDbName       = aStrNoName;
+        String                 theDbName       = 
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(STR_DB_LOCAL_NONAME));
 
         /*
          * Ueberpruefen, ob es sich bei dem uebergebenen
diff --git a/sc/source/ui/dbgui/tpsort.cxx b/sc/source/ui/dbgui/tpsort.cxx
index 364bdbf..2450abb 100644
--- a/sc/source/ui/dbgui/tpsort.cxx
+++ b/sc/source/ui/dbgui/tpsort.cxx
@@ -43,6 +43,7 @@
 #include "viewdata.hxx"
 #include "document.hxx"
 #include "global.hxx"
+#include "globalnames.hxx"
 #include "dbcolect.hxx"
 #include "userlist.hxx"
 #include "rangeutl.hxx"
@@ -582,7 +583,6 @@ ScTabPageSortOptions::ScTabPageSortOptions( Window*                         
pParent,
         aStrRowLabel   ( ScResId( STR_ROW_LABEL ) ),
         aStrColLabel   ( ScResId( STR_COL_LABEL ) ),
         aStrUndefined  ( ScResId( SCSTR_UNDEFINED ) ),
-        aStrNoName             ( ScGlobal::GetRscString(STR_DB_NONAME) ),
         //
         nWhichSort             ( rArgSet.GetPool()->GetWhich( SID_SORT ) ),
         rSortData              ( ((const ScSortItem&)
@@ -648,8 +648,8 @@ void ScTabPageSortOptions::Init()
         String                 theArea;
         ScDBCollection* pDBColl        = pDoc->GetDBCollection();
         String                 theDbArea;
-        String                 theDbName       = aStrNoName;
         const SCTAB    nCurTab         = pViewData->GetTabNo();
+        String                 theDbName       = 
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(STR_DB_LOCAL_NONAME));
         const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
 
         aLbOutPos.Clear();
diff --git a/sc/source/ui/docshell/dbdocfun.cxx b/sc/source/ui/docshell/dbdocfun.cxx
index c325c59..2173320 100644
--- a/sc/source/ui/docshell/dbdocfun.cxx
+++ b/sc/source/ui/docshell/dbdocfun.cxx
@@ -46,6 +46,7 @@
 #include "docsh.hxx"
 #include "docfunc.hxx"
 #include "globstr.hrc"
+#include "globalnames.hxx"
 #include "tabvwsh.hxx"
 #include "patattr.hxx"
 #include "rangenam.hxx"
@@ -82,10 +83,18 @@ sal_Bool ScDBDocFunc::AddDBRange( const String& rName, const ScRange& rRange, sa
     // so CompileDBFormula would never find any name (index) tokens, and would
     // unnecessarily loop through all cells.
     sal_Bool bCompile = !pDoc->IsImportingXML();
-
+    sal_Bool bOk;
     if ( bCompile )
         pDoc->CompileDBFormula( sal_True );     // CreateFormulaString
-    sal_Bool bOk = pDocColl->Insert( pNew );
+    if (rtl::OUString(rName)==rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(STR_DB_LOCAL_NONAME)))
+    {
+        pDoc->SetAnonymousDBData(rRange.aStart.Tab() , pNew);
+        bOk = true;
+    }
+    else
+    {
+        bOk = pDocColl->Insert( pNew );
+    }
     if ( bCompile )
         pDoc->CompileDBFormula( false );    // CompileFormulaString
 
@@ -200,13 +209,23 @@ sal_Bool ScDBDocFunc::ModifyDBData( const ScDBData& rNewData, sal_Bool /* 
bApi *
     ScDBCollection* pDocColl = pDoc->GetDBCollection();
     sal_Bool bUndo (pDoc->IsUndoEnabled());
 
-    sal_uInt16 nPos = 0;
-    if (pDocColl->SearchName( rNewData.GetName(), nPos ))
+    ScDBData* pData = NULL;
+    if 
(rtl::OUString(rNewData.GetName())==rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(STR_DB_LOCAL_NONAME)))
+    {
+        ScRange aRange;
+        rNewData.GetArea(aRange);
+        SCTAB nTab = aRange.aStart.Tab();
+        pData = pDoc->GetAnonymousDBData(nTab);
+    }
+    else
+    {
+        sal_uInt16 nPos = 0;
+        if (pDocColl->SearchName( rNewData.GetName(), nPos ))
+            pData = (*pDocColl)[nPos];
+    }
+    if (pData)
     {
         ScDocShellModificator aModificator( rDocShell );
-
-        ScDBData* pData = (*pDocColl)[nPos];
-
         ScRange aOldRange, aNewRange;
         pData->GetArea(aOldRange);
         rNewData.GetArea(aNewRange);
diff --git a/sc/source/ui/docshell/docsh5.cxx b/sc/source/ui/docshell/docsh5.cxx
index c1edfa8..2e64109 100644
--- a/sc/source/ui/docshell/docsh5.cxx
+++ b/sc/source/ui/docshell/docsh5.cxx
@@ -50,6 +50,7 @@
 #include "docsh.hxx"
 #include "global.hxx"
 #include "globstr.hrc"
+#include "globalnames.hxx"
 #include "undodat.hxx"
 #include "undotab.hxx"
 #include "undoblk.hxx"
@@ -130,43 +131,6 @@ void ScDocShell::DBAreaDeleted( SCTAB nTab, SCCOL nX1, SCROW nY1, SCCOL nX2, 
SCR
     aDocument.BroadcastUno( SfxSimpleHint( SFX_HINT_DATACHANGED ) );
 }
 
-ScDBData* lcl_GetDBNearCursor( ScDBCollection* pColl, SCCOL nCol, SCROW nRow, SCTAB nTab )
-{
-    //!        nach document/dbcolect verschieben
-
-    if (!pColl)
-        return NULL;
-
-    ScDBData* pNoNameData = NULL;
-    ScDBData* pNearData = NULL;
-    sal_uInt16 nCount = pColl->GetCount();
-    String aNoName = ScGlobal::GetRscString( STR_DB_NONAME );
-    SCTAB nAreaTab;
-    SCCOL nStartCol, nEndCol;
-    SCROW nStartRow, nEndRow;
-    for (sal_uInt16 i = 0; i < nCount; i++)
-    {
-        ScDBData* pDB = (*pColl)[i];
-        pDB->GetArea( nAreaTab, nStartCol, nStartRow, nEndCol, nEndRow );
-        if ( nTab == nAreaTab && nCol+1 >= nStartCol && nCol <= nEndCol+1 &&
-                                 nRow+1 >= nStartRow && nRow <= nEndRow+1 )
-        {
-            if ( pDB->GetName() == aNoName )
-                pNoNameData = pDB;
-            else if ( nCol < nStartCol || nCol > nEndCol || nRow < nStartRow || nRow > nEndRow )
-            {
-                if (!pNearData)
-                    pNearData = pDB;   // ersten angrenzenden Bereich merken
-            }
-            else
-                return pDB;                            // nicht "unbenannt" und Cursor steht 
wirklich drin
-        }
-    }
-    if (pNearData)
-        return pNearData;                              // angrenzender, wenn nichts direkt 
getroffen
-    return pNoNameData;                                        // "unbenannt" nur zurueck, wenn 
sonst nichts gefunden
-}
-
 ScDBData* ScDocShell::GetDBData( const ScRange& rMarked, ScGetDBMode eMode, ScGetDBSelection eSel )
 {
     SCCOL nCol = rMarked.aStart.Col();
@@ -179,14 +143,13 @@ ScDBData* ScDocShell::GetDBData( const ScRange& rMarked, ScGetDBMode eMode, 
ScGe
     SCCOL nEndCol = rMarked.aEnd.Col();
     SCROW nEndRow = rMarked.aEnd.Row();
     SCTAB nEndTab = rMarked.aEnd.Tab();
-
     // Nicht einfach GetDBAtCursor: Der zusammenhaengende Datenbereich
     // fuer "unbenannt" (GetDataArea) kann neben dem Cursor legen, also muss auch ein
     // benannter DB-Bereich dort gesucht werden.
-
+    ScDBCollection* pColl = aDocument.GetDBCollection();
     ScDBData* pData = aDocument.GetDBAtArea( nTab, nStartCol, nStartRow, nEndCol, nEndRow );
-    if (!pData)
-        pData = lcl_GetDBNearCursor( aDocument.GetDBCollection(), nCol, nRow, nTab );
+    if (!pData && pColl)
+        pData = pColl->GetDBNearCursor(nCol, nRow, nTab );
 
     sal_Bool bSelected = ( eSel == SC_DBSEL_FORCE_MARK ||
             (rMarked.aStart != rMarked.aEnd && eSel != SC_DBSEL_ROW_DOWN) );
@@ -203,7 +166,7 @@ ScDBData* ScDocShell::GetDBData( const ScRange& rMarked, ScGetDBMode eMode, ScGe
         SCCOL nOldCol2;
         SCROW nOldRow2;
         pData->GetArea( nDummy, nOldCol1,nOldRow1, nOldCol2,nOldRow2 );
-        sal_Bool bIsNoName = ( pData->GetName() == ScGlobal::GetRscString( STR_DB_NONAME ) );
+        sal_Bool bIsNoName = ( rtl::OUString(pData->GetName()) == 
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(STR_DB_LOCAL_NONAME)) );
 
         if (!bSelected)
         {
@@ -282,13 +245,9 @@ ScDBData* ScDocShell::GetDBData( const ScRange& rMarked, ScGetDBMode eMode, 
ScGe
 
         sal_Bool bHasHeader = aDocument.HasColHeader( nStartCol,nStartRow, nEndCol,nEndRow, nTab );
 
-        ScDBData* pNoNameData;
-        sal_uInt16 nNoNameIndex;
-        ScDBCollection* pColl = aDocument.GetDBCollection();
-        if ( eMode != SC_DB_IMPORT &&
-                pColl->SearchName( ScGlobal::GetRscString( STR_DB_NONAME ), nNoNameIndex ) )
+        ScDBData* pNoNameData = aDocument.GetAnonymousDBData(nTab);
+        if ( eMode != SC_DB_IMPORT && pNoNameData)
         {
-            pNoNameData = (*pColl)[nNoNameIndex];
 
             if ( !pOldAutoDBRange )
             {
@@ -334,13 +293,21 @@ ScDBData* ScDocShell::GetDBData( const ScRange& rMarked, ScGetDBMode eMode, 
ScGe
                     aNewName += String::CreateFromInt32( nCount );
                 }
                 while (pColl->SearchName( aNewName, nDummy ));
+                pNoNameData = new ScDBData( aNewName, nTab,
+                                nStartCol,nStartRow, nEndCol,nEndRow,
+                                sal_True, bHasHeader );
+                pColl->Insert( pNoNameData );
             }
             else
-                aNewName = ScGlobal::GetRscString( STR_DB_NONAME );
-            pNoNameData = new ScDBData( aNewName, nTab,
+            {
+                aNewName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(STR_DB_LOCAL_NONAME));
+                pNoNameData = new ScDBData(aNewName , nTab,
                                 nStartCol,nStartRow, nEndCol,nEndRow,
                                 sal_True, bHasHeader );
-            pColl->Insert( pNoNameData );
+                aDocument.SetAnonymousDBData(nTab, pNoNameData);
+            }
+
+ 
 
             if ( pUndoColl )
             {
@@ -372,23 +339,22 @@ ScDBData* ScDocShell::GetOldAutoDBRange()
 void ScDocShell::CancelAutoDBRange()
 {
     // called when dialog is cancelled
+//moggi:TODO
     if ( pOldAutoDBRange )
     {
-        sal_uInt16 nNoNameIndex;
-        ScDBCollection* pColl = aDocument.GetDBCollection();
-        if ( pColl->SearchName( ScGlobal::GetRscString( STR_DB_NONAME ), nNoNameIndex ) )
+        SCTAB nTab = GetCurTab();
+        ScDBData* pDBData = aDocument.GetAnonymousDBData(nTab);
+        if ( pDBData )
         {
-            ScDBData* pNoNameData = (*pColl)[nNoNameIndex];
-
             SCCOL nRangeX1;
             SCROW nRangeY1;
             SCCOL nRangeX2;
             SCROW nRangeY2;
             SCTAB nRangeTab;
-            pNoNameData->GetArea( nRangeTab, nRangeX1, nRangeY1, nRangeX2, nRangeY2 );
+            pDBData->GetArea( nRangeTab, nRangeX1, nRangeY1, nRangeX2, nRangeY2 );
             DBAreaDeleted( nRangeTab, nRangeX1, nRangeY1, nRangeX2, nRangeY2 );
 
-            *pNoNameData = *pOldAutoDBRange;    // restore old settings
+            *pDBData = *pOldAutoDBRange;    // restore old settings
 
             if ( pOldAutoDBRange->HasAutoFilter() )
             {
@@ -507,8 +473,7 @@ String lcl_GetAreaName( ScDocument* pDoc, ScArea* pArea )
     if (pData)
     {
         pData->GetName( aName );
-        if ( aName != ScGlobal::GetRscString( STR_DB_NONAME ) )
-            bOk = sal_True;
+        bOk = sal_True;
     }
 
     if (!bOk)
diff --git a/sc/source/ui/inc/pfiltdlg.hxx b/sc/source/ui/inc/pfiltdlg.hxx
index df2f245..c6dc564 100644
--- a/sc/source/ui/inc/pfiltdlg.hxx
+++ b/sc/source/ui/inc/pfiltdlg.hxx
@@ -90,7 +90,6 @@ private:
     HelpButton         aBtnHelp;
     MoreButton         aBtnMore;
     const String       aStrUndefined;
-    const String       aStrNoName;
     const String       aStrNone;
     const String       aStrEmpty;
     const String       aStrNotEmpty;
diff --git a/sc/source/ui/inc/tpsort.hxx b/sc/source/ui/inc/tpsort.hxx
index bc67272..a6fca08 100644
--- a/sc/source/ui/inc/tpsort.hxx
+++ b/sc/source/ui/inc/tpsort.hxx
@@ -188,7 +188,6 @@ private:
     LocalizedString aStrRowLabel;
     LocalizedString aStrColLabel;
     LocalizedString aStrUndefined;
-    String              aStrNoName;
     String              aStrAreaLabel;
 
     const sal_uInt16           nWhichSort;
diff --git a/sc/source/ui/inc/undobase.hxx b/sc/source/ui/inc/undobase.hxx
index 6924284..1196eee 100644
--- a/sc/source/ui/inc/undobase.hxx
+++ b/sc/source/ui/inc/undobase.hxx
@@ -101,6 +101,7 @@ protected:
 
 class ScDBFuncUndo: public ScSimpleUndo
 {
+protected:
     ScDBData*       pAutoDBRange;
     ScRange         aOriginalRange;
     SdrUndoAction*  mpDrawUndo;
diff --git a/sc/source/ui/navipi/content.cxx b/sc/source/ui/navipi/content.cxx
index 8dcbd2a..8fc3dca 100644
--- a/sc/source/ui/navipi/content.cxx
+++ b/sc/source/ui/navipi/content.cxx
@@ -708,13 +708,11 @@ void ScContentTree::GetDbNames()
     sal_uInt16 nCount = pDbNames->GetCount();
     if ( nCount > 0 )
     {
-        String aStrNoName( ScGlobal::GetRscString(STR_DB_NONAME) );
         for ( sal_uInt16 i=0; i<nCount; i++ )
         {
             ScDBData* pData = (*pDbNames)[i];
             String aStrName = pData->GetName();
-            if ( aStrName != aStrNoName )
-                InsertContent( SC_CONTENT_DBAREA, aStrName );
+            InsertContent( SC_CONTENT_DBAREA, aStrName );
         }
     }
 }
diff --git a/sc/source/ui/undo/undobase.cxx b/sc/source/ui/undo/undobase.cxx
index 5196359..cac4075 100644
--- a/sc/source/ui/undo/undobase.cxx
+++ b/sc/source/ui/undo/undobase.cxx
@@ -371,13 +371,11 @@ void ScDBFuncUndo::EndUndo()
 
     if ( pAutoDBRange )
     {
-        sal_uInt16 nNoNameIndex;
         ScDocument* pDoc = pDocShell->GetDocument();
-        ScDBCollection* pColl = pDoc->GetDBCollection();
-        if ( pColl->SearchName( ScGlobal::GetRscString( STR_DB_NONAME ), nNoNameIndex ) )
+        SCTAB nTab = pDoc->GetVisibleTab();
+        ScDBData* pNoNameData = pDoc->GetAnonymousDBData(nTab);
+        if (pNoNameData )
         {
-            ScDBData* pNoNameData = (*pColl)[nNoNameIndex];
-
             SCCOL nRangeX1;
             SCROW nRangeY1;
             SCCOL nRangeX2;
@@ -406,12 +404,10 @@ void ScDBFuncUndo::BeginRedo()
     {
         // move the database range to this function's position again (see ScDocShell::GetDBData)
 
-        sal_uInt16 nNoNameIndex;
         ScDocument* pDoc = pDocShell->GetDocument();
-        ScDBCollection* pColl = pDoc->GetDBCollection();
-        if ( pColl->SearchName( ScGlobal::GetRscString( STR_DB_NONAME ), nNoNameIndex ) )
+        ScDBData* pNoNameData = pDoc->GetAnonymousDBData(aOriginalRange.aStart.Tab());
+        if ( pNoNameData )
         {
-            ScDBData* pNoNameData = (*pColl)[nNoNameIndex];
 
             SCCOL nRangeX1;
             SCROW nRangeY1;
diff --git a/sc/source/ui/undo/undodat.cxx b/sc/source/ui/undo/undodat.cxx
index bdb6363..8b8f56d 100644
--- a/sc/source/ui/undo/undodat.cxx
+++ b/sc/source/ui/undo/undodat.cxx
@@ -45,6 +45,7 @@
 #include "pivot.hxx"
 #include "globstr.hrc"
 #include "global.hxx"
+#include "globalnames.hxx"
 #include "target.hxx"
 #include "chartarr.hxx"
 #include "dbdocfun.hxx"
@@ -1111,10 +1112,22 @@ void ScUndoAutoFilter::DoChange( sal_Bool bUndo )
 
     sal_uInt16 nIndex;
     ScDocument* pDoc = pDocShell->GetDocument();
-    ScDBCollection* pColl = pDoc->GetDBCollection();
-    if ( pColl->SearchName( aDBName, nIndex ) )
+    ScDBData* pDBData=NULL;
+    if (rtl::OUString(aDBName) == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(STR_DB_LOCAL_NONAME)))
+    {
+        SCTAB nTab = aOriginalRange.aStart.Tab();
+        pDBData = pDoc->GetAnonymousDBData(nTab);
+    }
+    else
+    {
+        ScDBCollection* pColl = pDoc->GetDBCollection();
+        if (pColl->SearchName( aDBName, nIndex ))
+            pDBData = (*pColl)[nIndex];
+    }
+
+
+    if ( pDBData )
     {
-        ScDBData* pDBData = (*pColl)[nIndex];
         pDBData->SetAutoFilter( bNewFilter );
 
         SCCOL nRangeX1;
diff --git a/sc/source/ui/undo/undoutil.cxx b/sc/source/ui/undo/undoutil.cxx
index 0e22e25..93d9c3f 100644
--- a/sc/source/ui/undo/undoutil.cxx
+++ b/sc/source/ui/undo/undoutil.cxx
@@ -42,6 +42,7 @@
 #include "document.hxx"
 #include "dbcolect.hxx"
 #include "globstr.hrc"
+#include "globalnames.hxx"
 #include "global.hxx"
 
 void ScUndoUtil::MarkSimpleBlock( ScDocShell* pDocShell,
@@ -98,22 +99,18 @@ ScDBData* ScUndoUtil::GetOldDBData( ScDBData* pUndoData, ScDocument* pDoc, SCTAB
         {
             String aName;
             pUndoData->GetName( aName );
-            if ( aName == ScGlobal::GetRscString( STR_DB_NONAME ) )
+            if ( rtl::OUString(aName) == 
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(STR_DB_LOCAL_NONAME) ) )
                 bWasTemp = sal_True;
         }
         DBG_ASSERT(bWasTemp, "Undo: didn't find database range");
         (void)bWasTemp;
-
-        sal_uInt16 nIndex;
-        ScDBCollection* pColl = pDoc->GetDBCollection();
-        if (pColl->SearchName( ScGlobal::GetRscString( STR_DB_NONAME ), nIndex ))
-            pRet = (*pColl)[nIndex];
-        else
+        pRet = pDoc->GetAnonymousDBData(nTab);
+        if (!pRet)
         {
-            pRet = new ScDBData( ScGlobal::GetRscString( STR_DB_NONAME ), nTab,
+            pRet = new ScDBData( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(STR_DB_LOCAL_NONAME)), 
nTab,
                                 nCol1,nRow1, nCol2,nRow2, sal_True,
                                 pDoc->HasColHeader( nCol1,nRow1,nCol2,nRow2,nTab ) );
-            pColl->Insert( pRet );
+            pDoc->SetAnonymousDBData(nTab,pRet);
         }
     }
 
diff --git a/sc/source/ui/unoobj/datauno.cxx b/sc/source/ui/unoobj/datauno.cxx
index b1c4b4c..15d186a 100644
--- a/sc/source/ui/unoobj/datauno.cxx
+++ b/sc/source/ui/unoobj/datauno.cxx
@@ -1636,6 +1636,15 @@ ScDBData* ScDatabaseRangeObj::GetDBData_Impl() const
     ScDBData* pRet = NULL;
     if (pDocShell)
     {
+        ScDocument* pDoc = pDocShell->GetDocument();
+        if (rtl::OUString(aName).match(ScGlobal::GetRscString(STR_DB_NONAME)))
+        {
+            rtl::OUString aDBNoName(aName);
+            aDBNoName = 
aDBNoName.replaceAt(0,rtl::OUString(ScGlobal::GetRscString(STR_DB_NONAME)).getLength(),rtl::OUString());
+            SCTAB nTab = aDBNoName.toInt32();
+            if (pDoc->GetAnonymousDBData(nTab))
+                return pDoc->GetAnonymousDBData(nTab);
+        }
         ScDBCollection* pNames = pDocShell->GetDocument()->GetDBCollection();
         if (pNames)
         {
@@ -2184,9 +2193,29 @@ ScDatabaseRangeObj* ScDatabaseRangesObj::GetObjectByIndex_Impl(sal_uInt16 
nIndex
 {
     if (pDocShell)
     {
-        ScDBCollection* pNames = pDocShell->GetDocument()->GetDBCollection();
+        ScDocument* pDoc = pDocShell->GetDocument();
+        ScDBCollection* pNames = pDoc->GetDBCollection();
         if (pNames && nIndex < pNames->GetCount())
             return new ScDatabaseRangeObj( pDocShell, (*pNames)[nIndex]->GetName() );
+        else
+        {
+            sal_uInt16 nCount = 0;
+            if (pNames)
+                nCount = pNames->GetCount();
+            for (SCTAB nTab = 0; nTab < pDoc->GetTableCount(); ++nTab)
+            {
+                if (pDoc->GetAnonymousDBData(nTab))
+                {
+                    if (nIndex==nCount)
+                    {
+                        rtl::OUStringBuffer aBuffer(ScGlobal::GetRscString( STR_DB_NONAME ));
+                        aBuffer.append(nTab);
+                        return new ScDatabaseRangeObj( pDocShell, aBuffer.makeStringAndClear());
+                    }
+                    ++nCount;
+                }
+            }
+        }
     }
     return NULL;
 }
@@ -2210,12 +2239,28 @@ void SAL_CALL ScDatabaseRangesObj::addNewByName( const rtl::OUString& aName,
     sal_Bool bDone = false;
     if (pDocShell)
     {
-        ScDBDocFunc aFunc(*pDocShell);
-
-        String aString(aName);
-        ScRange aNameRange( (SCCOL)aRange.StartColumn, (SCROW)aRange.StartRow, aRange.Sheet,
-                            (SCCOL)aRange.EndColumn,   (SCROW)aRange.EndRow,   aRange.Sheet );
-        bDone = aFunc.AddDBRange( aString, aNameRange, sal_True );
+        //moggi
+        if (aName.match(ScGlobal::GetRscString( STR_DB_NONAME )))
+        {
+                rtl::OUString aDBNoName(aName);
+                aDBNoName = 
aDBNoName.replaceAt(0,rtl::OUString(ScGlobal::GetRscString(STR_DB_NONAME)).getLength(),rtl::OUString());
+                SCTAB nTab = aDBNoName.toInt32();
+                String aNewName = ScGlobal::GetRscString( STR_DB_NONAME );
+                ScDBData* pNoNameData = new ScDBData(aNewName , nTab,
+                                (SCCOL)aRange.StartColumn,(SCROW)aRange.StartRow,
+                                (SCCOL)aRange.EndColumn,(SCROW)aRange.EndRow,
+                                sal_True, true );//moggi
+                pDocShell->GetDocument()->SetAnonymousDBData(nTab,pNoNameData);
+                bDone = true;
+        }
+        else
+        {
+            ScDBDocFunc aFunc(*pDocShell);
+            String aString(aName);
+            ScRange aNameRange( (SCCOL)aRange.StartColumn, (SCROW)aRange.StartRow, aRange.Sheet,
+                                (SCCOL)aRange.EndColumn,   (SCROW)aRange.EndRow,   aRange.Sheet );
+            bDone = aFunc.AddDBRange( aString, aNameRange, sal_True );
+        }
     }
     if (!bDone)
         throw uno::RuntimeException();         // no other exceptions specified
@@ -2255,9 +2300,17 @@ sal_Int32 SAL_CALL ScDatabaseRangesObj::getCount() 
throw(uno::RuntimeException)
 
     if (pDocShell)
     {
-        ScDBCollection* pNames = pDocShell->GetDocument()->GetDBCollection();
+        sal_Int32 nCountAnonymousDBData;
+        ScDocument* pDoc = pDocShell->GetDocument();
+        for (SCTAB nTab=0; nTab<pDoc->GetTableCount();nTab++)
+        {
+            if (pDoc->GetAnonymousDBData(nTab))
+                ++nCountAnonymousDBData;
+        }
+        ScDBCollection* pNames = pDoc->GetDBCollection();
         if (pNames)
-            return pNames->GetCount();
+            return pNames->GetCount() + nCountAnonymousDBData ;
+        return nCountAnonymousDBData;
     }
     return 0;
 }
@@ -2310,16 +2363,36 @@ uno::Sequence<rtl::OUString> SAL_CALL ScDatabaseRangesObj::getElementNames()
 
     if (pDocShell)
     {
-        ScDBCollection* pNames = pDocShell->GetDocument()->GetDBCollection();
+        ScDocument* pDoc = pDocShell->GetDocument();
+        sal_uInt16 nCountAnonymousDBData=0;
+        for (SCTAB nTab=0; nTab<pDoc->GetTableCount();nTab++)
+        {
+            if (pDoc->GetAnonymousDBData(nTab))
+                nCountAnonymousDBData++;
+        }
+        ScDBCollection* pNames = pDoc->GetDBCollection();
+        sal_uInt16 nCountDBData = 0;
         if (pNames)
         {
-            sal_uInt16 nCount = pNames->GetCount();
+            nCountDBData = pNames->GetCount();
             String aName;
-            uno::Sequence<rtl::OUString> aSeq(nCount);
+            uno::Sequence<rtl::OUString> aSeq(nCountDBData + nCountAnonymousDBData);
             rtl::OUString* pAry = aSeq.getArray();
-            for (sal_uInt16 i=0; i<nCount; i++)
+            for (sal_uInt16 i=0; i<nCountDBData; i++)
+            {
                 pAry[i] = (*pNames)[i]->GetName();
-
+            }
+            for (SCTAB nTab=0;nTab<pDoc->GetTableCount();nTab++)
+            {
+                sal_uInt16 i =0;
+                if (pDoc->GetAnonymousDBData(nTab))
+                {
+                    rtl::OUStringBuffer aStrBuffer(ScGlobal::GetRscString( STR_DB_NONAME ));
+                    aStrBuffer.append(nTab);
+                    pAry[nCountDBData+i]=aStrBuffer.makeStringAndClear();
+                    i++;
+                }
+            }
             return aSeq;
         }
     }
@@ -2335,7 +2408,18 @@ sal_Bool SAL_CALL ScDatabaseRangesObj::hasByName( const rtl::OUString& aName 
)
 
     if (pDocShell)
     {
-        ScDBCollection* pNames = pDocShell->GetDocument()->GetDBCollection();
+        ScDocument* pDoc = pDocShell->GetDocument();
+        if (aName.match(ScGlobal::GetRscString(STR_DB_NONAME)))
+        {
+            rtl::OUString aDBNoName(aName);
+            aDBNoName = 
aDBNoName.replaceAt(0,rtl::OUString(ScGlobal::GetRscString(STR_DB_NONAME)).getLength(),rtl::OUString());
+            SCTAB nTab = aDBNoName.toInt32();
+            if (pDoc->GetAnonymousDBData(nTab))
+                return sal_True;
+            else
+                return sal_False;
+        }
+        ScDBCollection* pNames = pDoc->GetDBCollection();
         if (pNames)
         {
             String aString(aName);
diff --git a/sc/source/ui/view/cellsh2.cxx b/sc/source/ui/view/cellsh2.cxx
index 9a2b520..a85c15e 100644
--- a/sc/source/ui/view/cellsh2.cxx
+++ b/sc/source/ui/view/cellsh2.cxx
@@ -56,6 +56,7 @@
 #include "sc.hrc"
 #include "globstr.hrc"
 #include "global.hxx"
+#include "globalnames.hxx"
 #include "scmod.hxx"
 #include "docsh.hxx"
 #include "document.hxx"
@@ -722,7 +723,7 @@ void ScCellShell::ExecuteDB( SfxRequest& rReq )
 
                     if ( pDBCol )
                     {
-                        const String   aStrNoName( ScGlobal::GetRscString(STR_DB_NONAME) );
+                        const String   aStrNoName( 
RTL_CONSTASCII_USTRINGPARAM(STR_DB_LOCAL_NONAME) );
                         List                   aList;
                         sal_uInt16                     nDBCount = pDBCol->GetCount();
                         ScDBData*              pDbData  = NULL;
@@ -736,7 +737,7 @@ void ScCellShell::ExecuteDB( SfxRequest& rReq )
                                 pDBName = new String;
                                 pDbData->GetName( *pDBName );
 
-                                if ( *pDBName != aStrNoName )
+                                if ( *pDBName!=aStrNoName )
                                     aList.Insert( pDBName );
                                 else
                                     DELETEZ(pDBName);

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.