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

Markus Mohrhard mmohrhard at kemper.freedesktop.org
Wed Oct 26 08:01:48 PDT 2011


 sc/inc/nameuno.hxx                |   47 ++++++++
 sc/inc/unowids.hxx                |    3 
 sc/source/ui/docshell/docfunc.cxx |   34 ++++--
 sc/source/ui/inc/docfunc.hxx      |    6 -
 sc/source/ui/inc/undocell.hxx     |    4 
 sc/source/ui/undo/undocell.cxx    |   19 ++-
 sc/source/ui/unoobj/cellsuno.cxx  |    8 +
 sc/source/ui/unoobj/docuno.cxx    |    2 
 sc/source/ui/unoobj/nameuno.cxx   |  202 +++++++++++++++++++++++++++++---------
 sc/source/ui/unoobj/targuno.cxx   |    2 
 10 files changed, 257 insertions(+), 70 deletions(-)

New commits:
commit 7fe4fa13c1f82524bd7b1f526adb851c67e1706f
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Wed Oct 26 15:26:43 2011 +0200

    add uno part for local range names
    
    you can now use e.g. thisComponent.sheets(0).namedRanges

diff --git a/sc/inc/nameuno.hxx b/sc/inc/nameuno.hxx
index 5ba41a9..9d7ca93 100644
--- a/sc/inc/nameuno.hxx
+++ b/sc/inc/nameuno.hxx
@@ -50,9 +50,11 @@
 #include <cppuhelper/implbase6.hxx>
 
 class ScDocShell;
+class ScRangeName;
 class ScRangeData;
 class ScTokenArray;
 class ScNamedRangesObj;
+class ScTableSheetObj;
 
 class ScNamedRangeObj : public ::cppu::WeakImplHelper6<
                             ::com::sun::star::sheet::XNamedRange,
@@ -67,6 +69,7 @@ private:
     ScNamedRangesObj*       mpParent;
     ScDocShell*             pDocShell;
     String                  aName;
+    ScTableSheetObj*        mpSheet;
 
 private:
     ScRangeData*            GetRangeData_Impl();
@@ -74,9 +77,10 @@ private:
                                         const ScTokenArray* pNewTokens, const String* pNewContent,
                                         const ScAddress* pNewPos, const sal_uInt16* pNewType,
                                         const formula::FormulaGrammar::Grammar eGrammar );
+    SCTAB                   GetTab_Impl();
 
 public:
-                            ScNamedRangeObj(ScNamedRangesObj* pParent, ScDocShell* pDocSh, const String& rNm);
+                            ScNamedRangeObj(ScNamedRangesObj* pParent, ScDocShell* pDocSh, const String& rNm, ScTableSheetObj* pSheet = NULL);
     virtual                 ~ScNamedRangeObj();
 
     virtual void            Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
@@ -184,17 +188,21 @@ class ScNamedRangesObj : public ::cppu::WeakImplHelper6<
                         public SfxListener
 {
 private:
-    ScDocShell*             pDocShell;
 
      // if true, adding new name or modifying existing one will set the
      // document 'modified' and broadcast the change.  We turn this off during
      // import.
     sal_Bool                mbModifyAndBroadcast;
 
-    ScNamedRangeObj*        GetObjectByIndex_Impl(sal_uInt16 nIndex);
-    ScNamedRangeObj*        GetObjectByName_Impl(const ::rtl::OUString& aName);
+    virtual ScNamedRangeObj* GetObjectByIndex_Impl(sal_uInt16 nIndex) = 0;
+    virtual ScNamedRangeObj* GetObjectByName_Impl(const ::rtl::OUString& aName) = 0;
+
+    virtual ScRangeName*    GetRangeName_Impl() = 0;
+    virtual SCTAB           GetTab_Impl() = 0;
 
 protected:
+
+    ScDocShell*             pDocShell;
     /** called from the XActionLockable interface methods on initial locking */
     virtual void            lock();
 
@@ -304,6 +312,37 @@ public:
                                 throw(::com::sun::star::uno::RuntimeException);
 };
 
+class ScGlobalNamedRangesObj: public ScNamedRangesObj
+{
+private:
+
+    virtual ScNamedRangeObj* GetObjectByIndex_Impl(sal_uInt16 nIndex);
+    virtual ScNamedRangeObj* GetObjectByName_Impl(const ::rtl::OUString& aName);
+
+    virtual ScRangeName*    GetRangeName_Impl();
+    virtual SCTAB           GetTab_Impl();
+
+public:
+                            ScGlobalNamedRangesObj(ScDocShell* pDocSh);
+    virtual                 ~ScGlobalNamedRangesObj();
+};
+
+class ScLocalNamedRangesObj: public ScNamedRangesObj
+{
+private:
+
+    virtual ScNamedRangeObj* GetObjectByIndex_Impl(sal_uInt16 nIndex);
+    virtual ScNamedRangeObj* GetObjectByName_Impl(const ::rtl::OUString& aName);
+
+    virtual ScRangeName*    GetRangeName_Impl();
+    virtual SCTAB           GetTab_Impl();
+
+    ScTableSheetObj* mpSheet;
+public:
+                            ScLocalNamedRangesObj(ScDocShell* pDocSh, ScTableSheetObj* pSheet);
+    virtual                 ~ScLocalNamedRangesObj();
+};
+
 
 class ScLabelRangeObj : public ::cppu::WeakImplHelper2<
                             ::com::sun::star::sheet::XLabelRange,
diff --git a/sc/inc/unowids.hxx b/sc/inc/unowids.hxx
index af860fd..0a87081 100644
--- a/sc/inc/unowids.hxx
+++ b/sc/inc/unowids.hxx
@@ -80,7 +80,8 @@
 #define SC_WID_UNO_ABSNAME          ( SC_WID_UNO_START + 39 )
 #define SC_WID_UNO_CODENAME         ( SC_WID_UNO_START + 40 )
 #define SC_WID_UNO_TABCOLOR         ( SC_WID_UNO_START + 41 )
-#define SC_WID_UNO_END              ( SC_WID_UNO_START + 41 )
+#define SC_WID_UNO_NAMES            ( SC_WID_UNO_START + 42 )
+#define SC_WID_UNO_END              ( SC_WID_UNO_START + 42 )
 
 
 inline sal_Bool IsScUnoWid( sal_uInt16 nWid )
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx
index b2d0536..f218b8b 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -4478,7 +4478,7 @@ bool ScDocFunc::UnmergeCells( const ScCellMergeOption& rOption, sal_Bool bRecord
 
 bool ScDocFunc::ModifyRangeNames( const ScRangeName& rNewRanges, SCTAB nTab )
 {
-    return SetNewRangeNames( new ScRangeName(rNewRanges), nTab );
+    return SetNewRangeNames( new ScRangeName(rNewRanges), true, nTab );
 }
 
 void ScDocFunc::ModifyAllRangeNames( const ScRangeName* pGlobal, const ScRangeName::TabNameCopyMap& rTabs )
@@ -4625,7 +4625,7 @@ void ScDocFunc::CreateOneName( ScRangeName& rList,
     }
 }
 
-sal_Bool ScDocFunc::CreateNames( const ScRange& rRange, sal_uInt16 nFlags, sal_Bool bApi )
+sal_Bool ScDocFunc::CreateNames( const ScRange& rRange, sal_uInt16 nFlags, sal_Bool bApi, SCTAB aTab )
 {
     if (!nFlags)
         return false;       // war nix
@@ -4651,7 +4651,12 @@ sal_Bool ScDocFunc::CreateNames( const ScRange& rRange, sal_uInt16 nFlags, sal_B
     if (bValid)
     {
         ScDocument* pDoc = rDocShell.GetDocument();
-        ScRangeName* pNames = pDoc->GetRangeName();
+        ScRangeName* pNames;
+        if (aTab >=0)
+            pNames = pDoc->GetRangeName(nTab);
+        else
+            pNames = pDoc->GetRangeName();
+
         if (!pNames)
             return false;   // soll nicht sein
         ScRangeName aNewRanges( *pNames );
@@ -4701,7 +4706,7 @@ sal_Bool ScDocFunc::CreateNames( const ScRange& rRange, sal_uInt16 nFlags, sal_B
         if ( bBottom && bRight )
             CreateOneName( aNewRanges, nEndCol,nEndRow,nTab, nContX1,nContY1,nContX2,nContY2, bCancel, bApi );
 
-        bDone = ModifyRangeNames( aNewRanges );
+        bDone = ModifyRangeNames( aNewRanges, aTab );
 
         aModificator.SetDocumentModified();
         SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_AREAS_CHANGED ) );
diff --git a/sc/source/ui/inc/docfunc.hxx b/sc/source/ui/inc/docfunc.hxx
index 70d83c6..ec5925a 100644
--- a/sc/source/ui/inc/docfunc.hxx
+++ b/sc/source/ui/inc/docfunc.hxx
@@ -196,7 +196,7 @@ public:
      */
     void            ModifyAllRangeNames( const ScRangeName* pGlobal, const ScRangeName::TabNameCopyMap& rTabs );
 
-    sal_Bool            CreateNames( const ScRange& rRange, sal_uInt16 nFlags, sal_Bool bApi );
+    sal_Bool            CreateNames( const ScRange& rRange, sal_uInt16 nFlags, sal_Bool bApi, SCTAB nTab = -1 ); // -1 for global range names
     sal_Bool            InsertNameList( const ScAddress& rStartPos, sal_Bool bApi );
 
     sal_Bool            InsertAreaLink( const String& rFile, const String& rFilter,
diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx
index 2450ee8..748b3c0 100644
--- a/sc/source/ui/unoobj/cellsuno.cxx
+++ b/sc/source/ui/unoobj/cellsuno.cxx
@@ -85,6 +85,7 @@
 #include "miscuno.hxx"
 #include "convuno.hxx"
 #include "srchuno.hxx"
+#include "nameuno.hxx"
 #include "targuno.hxx"
 #include "tokenuno.hxx"
 #include "eventuno.hxx"
@@ -785,6 +786,7 @@ const SfxItemPropertySet* lcl_GetSheetPropertySet()
         {MAP_CHAR_LEN(SC_UNONAME_WRITING),  ATTR_WRITINGDIR,    &getCppuType((sal_Int16*)0),            0, 0 },
         {MAP_CHAR_LEN(SC_UNONAME_TABCOLOR), SC_WID_UNO_TABCOLOR, &getCppuType((sal_Int32*)0), 0, 0 },
         {MAP_CHAR_LEN(SC_UNO_CODENAME),        SC_WID_UNO_CODENAME, &getCppuType(static_cast< const rtl::OUString * >(0)),    0, 0},
+        {MAP_CHAR_LEN(SC_UNO_NAMEDRANGES), SC_WID_UNO_NAMES, &getCppuType((uno::Reference<sheet::XNamedRanges>*)0), 0, 0 },
         {0,0,0,0,0,0}
     };
     static SfxItemPropertySet aSheetPropertySet( aSheetPropertyMap_Impl );
@@ -8526,7 +8528,11 @@ void ScTableSheetObj::GetOnePropertyValue( const SfxItemPropertySimpleEntry* pEn
         ScDocument* pDoc = pDocSh->GetDocument();
         SCTAB nTab = GetTab_Impl();
 
-        if ( pEntry->nWID == SC_WID_UNO_PAGESTL )
+        if ( pEntry->nWID == SC_WID_UNO_NAMES )
+        {
+            rAny <<= uno::Reference<sheet::XNamedRanges>(new ScLocalNamedRangesObj(pDocSh, this));
+        }
+        else if ( pEntry->nWID == SC_WID_UNO_PAGESTL )
         {
             rAny <<= rtl::OUString( ScStyleNameConversion::DisplayToProgrammaticName(
                                 pDoc->GetPageStyle( nTab ), SFX_STYLE_FAMILY_PAGE ) );
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index df949d8..4d4d588 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -1775,7 +1775,7 @@ uno::Any SAL_CALL ScModelObj::getPropertyValue( const rtl::OUString& aPropertyNa
         }
         else if ( aString.EqualsAscii( SC_UNO_NAMEDRANGES ) )
         {
-            aRet <<= uno::Reference<sheet::XNamedRanges>(new ScNamedRangesObj( pDocShell ));
+            aRet <<= uno::Reference<sheet::XNamedRanges>(new ScGlobalNamedRangesObj( pDocShell ));
         }
         else if ( aString.EqualsAscii( SC_UNO_DATABASERNG ) )
         {
diff --git a/sc/source/ui/unoobj/nameuno.cxx b/sc/source/ui/unoobj/nameuno.cxx
index aed6576..3726eb7 100644
--- a/sc/source/ui/unoobj/nameuno.cxx
+++ b/sc/source/ui/unoobj/nameuno.cxx
@@ -99,10 +99,11 @@ bool lcl_UserVisibleName(const ScRangeData& rData)
     return !rData.HasType(RT_DATABASE) && !rData.HasType(RT_SHARED);
 }
 
-ScNamedRangeObj::ScNamedRangeObj(ScNamedRangesObj* pParent, ScDocShell* pDocSh, const String& rNm) :
+ScNamedRangeObj::ScNamedRangeObj(ScNamedRangesObj* pParent, ScDocShell* pDocSh, const String& rNm, ScTableSheetObj* pSheet) :
     mpParent(pParent),
     pDocShell( pDocSh ),
-    aName( rNm )
+    aName( rNm ),
+    mpSheet( pSheet )
 {
     pDocShell->GetDocument()->AddUnoObject(*this);
 }
@@ -128,7 +129,12 @@ ScRangeData* ScNamedRangeObj::GetRangeData_Impl()
     ScRangeData* pRet = NULL;
     if (pDocShell)
     {
-        ScRangeName* pNames = pDocShell->GetDocument()->GetRangeName();
+        ScRangeName* pNames;
+        SCTAB nTab = GetTab_Impl();
+        if (nTab >= 0)
+            pNames = pDocShell->GetDocument()->GetRangeName(nTab);
+        else
+            pNames = pDocShell->GetDocument()->GetRangeName();
         if (pNames)
         {
             pRet = pNames->findByName(aName);
@@ -139,6 +145,21 @@ ScRangeData* ScNamedRangeObj::GetRangeData_Impl()
     return pRet;
 }
 
+SCTAB ScNamedRangeObj::GetTab_Impl()
+{
+    if (mpSheet)
+    {
+        if (!pDocShell)
+            return -2;
+        ScDocument* pDoc = pDocShell->GetDocument();
+        SCTAB nTab;
+        pDoc->GetTable(mpSheet->getName(), nTab);
+        return nTab;
+    }
+    else
+        return -1;//global range name
+}
+
 // sheet::XNamedRange
 
 void ScNamedRangeObj::Modify_Impl( const String* pNewName, const ScTokenArray* pNewTokens, const String* pNewContent,
@@ -149,7 +170,12 @@ void ScNamedRangeObj::Modify_Impl( const String* pNewName, const ScTokenArray* p
         return;
 
     ScDocument* pDoc = pDocShell->GetDocument();
-    ScRangeName* pNames = pDoc->GetRangeName();
+    ScRangeName* pNames;
+    SCTAB nTab = GetTab_Impl();
+    if (nTab >= 0)
+        pNames = pDoc->GetRangeName(nTab);
+    else
+        pNames = pDoc->GetRangeName();
     if (!pNames)
         return;
 
@@ -188,7 +214,7 @@ void ScNamedRangeObj::Modify_Impl( const String* pNewName, const ScTokenArray* p
     if (pNewRanges->insert(pNew))
     {
         ScDocFunc aFunc(*pDocShell);
-        aFunc.SetNewRangeNames(pNewRanges, mpParent->IsModifyAndBroadcast());
+        aFunc.SetNewRangeNames(pNewRanges, mpParent->IsModifyAndBroadcast(), nTab);
 
         aName = aInsName;   //! broadcast?
     }
@@ -481,8 +507,8 @@ ScNamedRangeObj* ScNamedRangeObj::getImplementation( const uno::Reference<uno::X
 //------------------------------------------------------------------------
 
 ScNamedRangesObj::ScNamedRangesObj(ScDocShell* pDocSh) :
-    pDocShell( pDocSh ),
-    mbModifyAndBroadcast(true)
+    mbModifyAndBroadcast(true),
+    pDocShell( pDocSh )
 {
     pDocShell->GetDocument()->AddUnoObject(*this);
 }
@@ -511,36 +537,6 @@ bool ScNamedRangesObj::IsModifyAndBroadcast() const
 
 // sheet::XNamedRanges
 
-ScNamedRangeObj* ScNamedRangesObj::GetObjectByIndex_Impl(sal_uInt16 nIndex)
-{
-    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)
-    {
-        if (lcl_UserVisibleName(*itr))
-        {
-            if (nPos == nIndex)
-                return new ScNamedRangeObj(this, pDocShell, itr->GetName());
-        }
-        ++nPos;
-    }
-    return NULL;
-}
-
-ScNamedRangeObj* ScNamedRangesObj::GetObjectByName_Impl(const rtl::OUString& aName)
-{
-    if ( pDocShell && hasByName(aName) )
-        return new ScNamedRangeObj(this, pDocShell, String(aName));
-    return NULL;
-}
-
 void SAL_CALL ScNamedRangesObj::addNewByName( const rtl::OUString& aName,
         const rtl::OUString& aContent, const table::CellAddress& aPosition,
         sal_Int32 nUnoType ) throw(uno::RuntimeException)
@@ -558,7 +554,7 @@ void SAL_CALL ScNamedRangesObj::addNewByName( const rtl::OUString& aName,
     if (pDocShell)
     {
         ScDocument* pDoc = pDocShell->GetDocument();
-        ScRangeName* pNames = pDoc->GetRangeName();
+        ScRangeName* pNames = GetRangeName_Impl();
         if (pNames && !pNames->findByName(aName))
         {
             ScRangeName* pNewRanges = new ScRangeName( *pNames );
@@ -568,7 +564,7 @@ void SAL_CALL ScNamedRangesObj::addNewByName( const rtl::OUString& aName,
             if ( pNewRanges->insert(pNew) )
             {
                 ScDocFunc aFunc(*pDocShell);
-                aFunc.SetNewRangeNames(pNewRanges, mbModifyAndBroadcast);
+                aFunc.SetNewRangeNames(pNewRanges, mbModifyAndBroadcast, GetTab_Impl());
                 bDone = true;
             }
             else
@@ -606,7 +602,7 @@ void SAL_CALL ScNamedRangesObj::addNewFromTitles( const table::CellRangeAddress&
     if (nFlags)
     {
         ScDocFunc aFunc(*pDocShell);
-        aFunc.CreateNames( aRange, nFlags, sal_True );
+        aFunc.CreateNames( aRange, nFlags, sal_True, GetTab_Impl() );
     }
 }
 
@@ -617,7 +613,7 @@ void SAL_CALL ScNamedRangesObj::removeByName( const rtl::OUString& aName )
     bool bDone = false;
     if (pDocShell)
     {
-        ScRangeName* pNames = pDocShell->GetDocument()->GetRangeName();
+        ScRangeName* pNames = GetRangeName_Impl();
         if (pNames)
         {
             const ScRangeData* pData = pNames->findByName(aName);
@@ -626,7 +622,7 @@ void SAL_CALL ScNamedRangesObj::removeByName( const rtl::OUString& aName )
                 ScRangeName* pNewRanges = new ScRangeName(*pNames);
                 pNewRanges->erase(*pData);
                 ScDocFunc aFunc(*pDocShell);
-                aFunc.SetNewRangeNames( pNewRanges, mbModifyAndBroadcast);
+                aFunc.SetNewRangeNames( pNewRanges, mbModifyAndBroadcast, GetTab_Impl());
                 bDone = true;
             }
         }
@@ -665,7 +661,7 @@ sal_Int32 SAL_CALL ScNamedRangesObj::getCount() throw(uno::RuntimeException)
     long nRet = 0;
     if (pDocShell)
     {
-        ScRangeName* pNames = pDocShell->GetDocument()->GetRangeName();
+        ScRangeName* pNames = GetRangeName_Impl();
         if (pNames)
         {
             ScRangeName::const_iterator itr = pNames->begin(), itrEnd = pNames->end();
@@ -754,7 +750,7 @@ uno::Sequence<rtl::OUString> SAL_CALL ScNamedRangesObj::getElementNames()
     SolarMutexGuard aGuard;
     if (pDocShell)
     {
-        ScRangeName* pNames = pDocShell->GetDocument()->GetRangeName();
+        ScRangeName* pNames = GetRangeName_Impl();
         if (pNames)
         {
             long nVisCount = getCount();            // Namen mit lcl_UserVisibleName
@@ -779,7 +775,7 @@ sal_Bool SAL_CALL ScNamedRangesObj::hasByName( const rtl::OUString& aName )
     SolarMutexGuard aGuard;
     if (pDocShell)
     {
-        ScRangeName* pNames = pDocShell->GetDocument()->GetRangeName();
+        ScRangeName* pNames = GetRangeName_Impl();
         if (pNames)
         {
             const ScRangeData* pData = pNames->findByName(aName);
@@ -873,6 +869,122 @@ sal_Int16 ScNamedRangesObj::resetActionLocks() throw(uno::RuntimeException)
 
 //------------------------------------------------------------------------
 
+ScGlobalNamedRangesObj::ScGlobalNamedRangesObj(ScDocShell* pDocSh)
+    : ScNamedRangesObj(pDocSh)
+{
+
+}
+
+ScGlobalNamedRangesObj::~ScGlobalNamedRangesObj()
+{
+
+}
+
+ScNamedRangeObj* ScGlobalNamedRangesObj::GetObjectByIndex_Impl(sal_uInt16 nIndex)
+{
+    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)
+    {
+        if (lcl_UserVisibleName(*itr))
+        {
+            if (nPos == nIndex)
+                return new ScNamedRangeObj(this, pDocShell, itr->GetName());
+        }
+        ++nPos;
+    }
+    return NULL;
+}
+
+ScNamedRangeObj* ScGlobalNamedRangesObj::GetObjectByName_Impl(const ::rtl::OUString& aName)
+{
+    if ( pDocShell && hasByName(aName) )
+        return new ScNamedRangeObj(this, pDocShell, String(aName));
+    return NULL;
+}
+
+ScRangeName* ScGlobalNamedRangesObj::GetRangeName_Impl()
+{
+    return pDocShell->GetDocument()->GetRangeName();
+}
+
+SCTAB ScGlobalNamedRangesObj::GetTab_Impl()
+{
+    return -1;
+}
+
+//------------------------------------------------------------------------
+
+ScLocalNamedRangesObj::ScLocalNamedRangesObj( ScDocShell* pDocSh, ScTableSheetObj* pSheet )
+    : ScNamedRangesObj(pDocSh),
+    mpSheet(pSheet)
+{
+
+}
+
+ScLocalNamedRangesObj::~ScLocalNamedRangesObj()
+{
+
+}
+
+ScNamedRangeObj* ScLocalNamedRangesObj::GetObjectByName_Impl(const ::rtl::OUString& aName)
+{
+    if ( pDocShell && hasByName( aName ) )
+        return new ScNamedRangeObj( this, pDocShell, String(aName), mpSheet);
+    return NULL;
+
+}
+
+ScNamedRangeObj* ScLocalNamedRangesObj::GetObjectByIndex_Impl( sal_uInt16 nIndex )
+{
+    if (!pDocShell)
+        return NULL;
+
+    rtl::OUString aName = mpSheet->getName();
+    ScDocument* pDoc = pDocShell->GetDocument();
+    SCTAB nTab;
+    pDoc->GetTable( aName, nTab );
+
+    ScRangeName* pNames = pDoc->GetRangeName( nTab );
+    if (!pNames)
+        return NULL;
+
+    ScRangeName::const_iterator itr = pNames->begin(), itrEnd = pNames->end();
+    sal_uInt16 nPos = 0;
+    for (; itr != itrEnd; ++itr)
+    {
+        if (lcl_UserVisibleName(*itr))
+        {
+            if (nPos == nIndex)
+                return new ScNamedRangeObj(this, pDocShell, itr->GetName(), mpSheet);
+        }
+        ++nPos;
+    }
+    return NULL;
+}
+
+ScRangeName* ScLocalNamedRangesObj::GetRangeName_Impl()
+{
+    SCTAB nTab = GetTab_Impl();
+    return pDocShell->GetDocument()->GetRangeName( nTab );
+}
+
+SCTAB ScLocalNamedRangesObj::GetTab_Impl()
+{
+    SCTAB nTab;
+    pDocShell->GetDocument()->GetTable(mpSheet->getName(), nTab);
+    return nTab;
+}
+
+//------------------------------------------------------------------------
+
 ScLabelRangeObj::ScLabelRangeObj(ScDocShell* pDocSh, sal_Bool bCol, const ScRange& rR) :
     pDocShell( pDocSh ),
     bColumn( bCol ),
diff --git a/sc/source/ui/unoobj/targuno.cxx b/sc/source/ui/unoobj/targuno.cxx
index 498f326..40de12c 100644
--- a/sc/source/ui/unoobj/targuno.cxx
+++ b/sc/source/ui/unoobj/targuno.cxx
@@ -187,7 +187,7 @@ uno::Reference< container::XNameAccess > SAL_CALL  ScLinkTargetTypeObj::getLinks
                 xCollection.set(new ScTableSheetsObj(pDocShell));
                 break;
             case SC_LINKTARGETTYPE_RANGENAME:
-                xCollection.set(new ScNamedRangesObj(pDocShell));
+                xCollection.set(new ScGlobalNamedRangesObj(pDocShell));
                 break;
             case SC_LINKTARGETTYPE_DBAREA:
                 xCollection.set(new ScDatabaseRangesObj(pDocShell));
commit 5fbdd7bf0994f43ad4783f7ff574e11642321016
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Wed Oct 26 01:00:05 2011 +0200

    add local range names to ScDocFunc

diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx
index e484fcd..b2d0536 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -4476,9 +4476,9 @@ bool ScDocFunc::UnmergeCells( const ScCellMergeOption& rOption, sal_Bool bRecord
 
 //------------------------------------------------------------------------
 
-bool ScDocFunc::ModifyRangeNames( const ScRangeName& rNewRanges )
+bool ScDocFunc::ModifyRangeNames( const ScRangeName& rNewRanges, SCTAB nTab )
 {
-    return SetNewRangeNames( new ScRangeName(rNewRanges) );
+    return SetNewRangeNames( new ScRangeName(rNewRanges), nTab );
 }
 
 void ScDocFunc::ModifyAllRangeNames( const ScRangeName* pGlobal, const ScRangeName::TabNameCopyMap& rTabs )
@@ -4509,7 +4509,7 @@ void ScDocFunc::ModifyAllRangeNames( const ScRangeName* pGlobal, const ScRangeNa
     SFX_APP()->Broadcast(SfxSimpleHint(SC_HINT_AREAS_CHANGED));
 }
 
-bool ScDocFunc::SetNewRangeNames( ScRangeName* pNewRanges, bool bModifyDoc )     // takes ownership of pNewRanges
+bool ScDocFunc::SetNewRangeNames( ScRangeName* pNewRanges, bool bModifyDoc, SCTAB nTab )     // takes ownership of pNewRanges
 {
     ScDocShellModificator aModificator( rDocShell );
 
@@ -4519,11 +4519,19 @@ bool ScDocFunc::SetNewRangeNames( ScRangeName* pNewRanges, bool bModifyDoc )
 
     if (bUndo)
     {
-        ScRangeName* pOld = pDoc->GetRangeName();
+        ScRangeName* pOld;
+        if (nTab >=0)
+        {
+            pOld = pDoc->GetRangeName(nTab);
+        }
+        else
+        {
+            pOld = pDoc->GetRangeName();
+        }
         ScRangeName* pUndoRanges = new ScRangeName(*pOld);
         ScRangeName* pRedoRanges = new ScRangeName(*pNewRanges);
         rDocShell.GetUndoManager()->AddUndoAction(
-            new ScUndoRangeNames( &rDocShell, pUndoRanges, pRedoRanges ) );
+            new ScUndoRangeNames( &rDocShell, pUndoRanges, pRedoRanges, nTab ) );
     }
 
     // #i55926# While loading XML, formula cells only have a single string token,
@@ -4533,7 +4541,10 @@ bool ScDocFunc::SetNewRangeNames( ScRangeName* pNewRanges, bool bModifyDoc )
 
     if ( bCompile )
         pDoc->CompileNameFormula( sal_True );   // CreateFormulaString
-    pDoc->SetRangeName( pNewRanges );       // takes ownership
+    if (nTab >= 0)
+        pDoc->SetRangeName( nTab, pNewRanges ); // takes ownership
+    else
+        pDoc->SetRangeName( pNewRanges );       // takes ownership
     if ( bCompile )
         pDoc->CompileNameFormula( false );  // CompileFormulaString
 
diff --git a/sc/source/ui/inc/docfunc.hxx b/sc/source/ui/inc/docfunc.hxx
index c54e0c1..70d83c6 100644
--- a/sc/source/ui/inc/docfunc.hxx
+++ b/sc/source/ui/inc/docfunc.hxx
@@ -182,8 +182,8 @@ public:
     sal_Bool            UnmergeCells( const ScRange& rRange, sal_Bool bRecord, sal_Bool bApi );
     bool            UnmergeCells( const ScCellMergeOption& rOption, sal_Bool bRecord, sal_Bool bApi );
 
-    bool            SetNewRangeNames( ScRangeName* pNewRanges, bool bModifyDoc = true );     // takes ownership of pNewRanges
-    bool            ModifyRangeNames( const ScRangeName& rNewRanges );
+    bool            SetNewRangeNames( ScRangeName* pNewRanges, bool bModifyDoc = true, SCTAB nTab = -1 );     // takes ownership of pNewRanges //nTab = -1 for local range names
+    bool            ModifyRangeNames( const ScRangeName& rNewRanges, SCTAB nTab = -1 );
 
     /**
      * Modify all range names, global scope names as well as sheet local ones,
commit 05d40c33b0d3e8d33912ad2b43ae8e31c6a1e443
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Wed Oct 26 00:59:34 2011 +0200

    add local range names to undo

diff --git a/sc/source/ui/inc/undocell.hxx b/sc/source/ui/inc/undocell.hxx
index 2ab9ab1..3ff3127 100644
--- a/sc/source/ui/inc/undocell.hxx
+++ b/sc/source/ui/inc/undocell.hxx
@@ -352,8 +352,9 @@ class ScUndoRangeNames: public ScSimpleUndo
 {
 public:
                     TYPEINFO();
+                    //use nTab = -1 for global range names
                     ScUndoRangeNames( ScDocShell* pNewDocShell,
-                                        ScRangeName* pOld, ScRangeName* pNew );
+                                        ScRangeName* pOld, ScRangeName* pNew , SCTAB nTab = -1);
     virtual         ~ScUndoRangeNames();
 
     virtual void    Undo();
@@ -366,6 +367,7 @@ public:
 private:
     ScRangeName*    pOldRanges;
     ScRangeName*    pNewRanges;
+    SCTAB           mnTab;
 
     void            DoChange( sal_Bool bUndo );
 };
diff --git a/sc/source/ui/undo/undocell.cxx b/sc/source/ui/undo/undocell.cxx
index fa98ed4..a4c6c6d 100644
--- a/sc/source/ui/undo/undocell.cxx
+++ b/sc/source/ui/undo/undocell.cxx
@@ -1084,10 +1084,11 @@ sal_Bool ScUndoDetective::CanRepeat(SfxRepeatTarget& /* rTarget */) const
 //
 
 ScUndoRangeNames::ScUndoRangeNames( ScDocShell* pNewDocShell,
-                                    ScRangeName* pOld, ScRangeName* pNew ) :
+                                    ScRangeName* pOld, ScRangeName* pNew, SCTAB nTab ) :
     ScSimpleUndo( pNewDocShell ),
     pOldRanges  ( pOld ),
-    pNewRanges  ( pNew )
+    pNewRanges  ( pNew ),
+    mnTab       ( nTab )
 {
 }
 
@@ -1108,9 +1109,19 @@ void ScUndoRangeNames::DoChange( sal_Bool bUndo )
     pDoc->CompileNameFormula( sal_True );   // CreateFormulaString
 
     if ( bUndo )
-        pDoc->SetRangeName( new ScRangeName( *pOldRanges ) );
+    {
+        if (mnTab >= 0)
+            pDoc->SetRangeName( mnTab, new ScRangeName( *pOldRanges ) );
+        else
+            pDoc->SetRangeName( new ScRangeName( *pOldRanges ) );
+    }
     else
-        pDoc->SetRangeName( new ScRangeName( *pNewRanges ) );
+    {
+        if (mnTab >= 0)
+            pDoc->SetRangeName( mnTab, new ScRangeName( *pNewRanges ) );
+        else
+            pDoc->SetRangeName( new ScRangeName( *pNewRanges ) );
+    }
 
     pDoc->CompileNameFormula( false );  // CompileFormulaString
 


More information about the Libreoffice-commits mailing list