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

Markus Mohrhard mmohrhard at kemper.freedesktop.org
Wed May 4 12:26:30 PDT 2011


 sc/inc/datauno.hxx              |   30 ++++++++++
 sc/source/ui/unoobj/datauno.cxx |  115 +++++++++++++++++++++++++++++++++++++---
 2 files changed, 138 insertions(+), 7 deletions(-)

New commits:
commit 76743b2e555bc59b75e6c3d4cf0ef7f27b824630
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Wed May 4 20:12:41 2011 +0200

    add implementation for new uno interface XUnnamedDatabaseRange

diff --git a/sc/inc/datauno.hxx b/sc/inc/datauno.hxx
index 429ca3a..7d43e4f 100644
--- a/sc/inc/datauno.hxx
+++ b/sc/inc/datauno.hxx
@@ -40,6 +40,7 @@
 #include <com/sun/star/sheet/XConsolidationDescriptor.hpp>
 #include <com/sun/star/sheet/XDatabaseRanges.hpp>
 #include <com/sun/star/sheet/XDatabaseRange.hpp>
+#include <com/sun/star/sheet/XUnnamedDatabaseRanges.hpp>
 #include <com/sun/star/sheet/XSubTotalDescriptor.hpp>
 #include <com/sun/star/sheet/XSubTotalField.hpp>
 #include <com/sun/star/lang/XServiceInfo.hpp>
@@ -501,6 +502,8 @@ private:
     String					aName;
     SfxItemPropertySet		aPropSet;
     XDBRefreshListenerArr_Impl aRefreshListeners;
+    bool                    bIsUnnamed;
+    SCTAB                   aTab;
 
 private:
     ScDBData*				GetDBData_Impl() const;
@@ -508,6 +511,7 @@ private:
 
 public:
                             ScDatabaseRangeObj(ScDocShell* pDocSh, const String& rNm);
+                            ScDatabaseRangeObj(ScDocShell* pDocSh, const SCTAB nTab);
     virtual					~ScDatabaseRangeObj();
 
     virtual void			Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
@@ -662,6 +666,32 @@ public:
                                 throw(::com::sun::star::uno::RuntimeException);
 };
 
+class ScUnnamedDatabaseRangesObj : public cppu::WeakImplHelper1<
+                                com::sun::star::sheet::XUnnamedDatabaseRanges>,
+                            public SfxListener
+{
+private:
+    ScDocShell*				pDocShell;
+
+public:
+                            ScUnnamedDatabaseRangesObj(ScDocShell* pDocSh);
+    virtual					~ScUnnamedDatabaseRangesObj();
+
+    virtual void			Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
+
+                            // XUnnamedDatabaseRanges
+    virtual void SAL_CALL setByTable( const ::com::sun::star::table::CellRangeAddress& aRange )
+                                throw(::com::sun::star::uno::RuntimeException,
+                                      ::com::sun::star::lang::IndexOutOfBoundsException );
+    virtual com::sun::star::uno::Any SAL_CALL getByTable( const sal_Int32 nTab )
+                                throw(::com::sun::star::uno::RuntimeException,
+                                ::com::sun::star::lang::IndexOutOfBoundsException,
+                                ::com::sun::star::container::NoSuchElementException );
+    virtual sal_Bool SAL_CALL hasByTable( sal_Int32 nTab )
+                                throw (::com::sun::star::uno::RuntimeException,
+                                ::com::sun::star::lang::IndexOutOfBoundsException);
+};
+
 
 
 #endif
diff --git a/sc/source/ui/unoobj/datauno.cxx b/sc/source/ui/unoobj/datauno.cxx
index 8b79c0b..0138412 100644
--- a/sc/source/ui/unoobj/datauno.cxx
+++ b/sc/source/ui/unoobj/datauno.cxx
@@ -57,6 +57,7 @@
 #include "docsh.hxx"
 #include "dbdocfun.hxx"
 #include "unonames.hxx"
+#include "globalnames.hxx"
 #include "globstr.hrc"
 #include "convuno.hxx"
 #include "hints.hxx"
@@ -1602,7 +1603,18 @@ void ScDataPilotFilterDescriptor::PutData( const ScQueryParam& rParam )
 ScDatabaseRangeObj::ScDatabaseRangeObj(ScDocShell* pDocSh, const String& rNm) :
     pDocShell( pDocSh ),
     aName( rNm ),
-    aPropSet( lcl_GetDBRangePropertyMap() )
+    aPropSet( lcl_GetDBRangePropertyMap() ),
+    bIsUnnamed(false)
+{
+    pDocShell->GetDocument()->AddUnoObject(*this);
+}
+
+ScDatabaseRangeObj::ScDatabaseRangeObj(ScDocShell* pDocSh, const SCTAB nTab) :
+    pDocShell( pDocSh ),
+    aName(RTL_CONSTASCII_USTRINGPARAM(STR_DB_LOCAL_NONAME)),
+    aPropSet( lcl_GetDBRangePropertyMap() ),
+    bIsUnnamed(true),
+    aTab( nTab )
 {
     pDocShell->GetDocument()->AddUnoObject(*this);
 }
@@ -1636,12 +1648,19 @@ ScDBData* ScDatabaseRangeObj::GetDBData_Impl() const
     ScDBData* pRet = NULL;
     if (pDocShell)
     {
-        ScDBCollection* pNames = pDocShell->GetDocument()->GetDBCollection();
-        if (pNames)
+        if (bIsUnnamed)
         {
-            sal_uInt16 nPos = 0;
-            if (pNames->SearchName( aName, nPos ))
-                pRet = (*pNames)[nPos];
+            pRet = pDocShell->GetDocument()->GetAnonymousDBData(aTab);
+        }
+        else
+        {
+            ScDBCollection* pNames = pDocShell->GetDocument()->GetDBCollection();
+            if (pNames)
+            {
+                sal_uInt16 nPos = 0;
+                if (pNames->SearchName( aName, nPos ))
+                    pRet = (*pNames)[nPos];
+            }
         }
     }
     return pRet;
@@ -2074,7 +2093,7 @@ uno::Any SAL_CALL ScDatabaseRangeObj::getPropertyValue( const rtl::OUString& aPr
         {
             //	all database ranges except "unnamed" are user defined
             ScUnoHelpFunctions::SetBoolInAny( aRet,
-                        ( pData->GetName() != ScGlobal::GetRscString(STR_DB_NONAME) ) );
+                        ( pData->GetName() != String(RTL_CONSTASCII_USTRINGPARAM(STR_DB_LOCAL_NONAME))  ) );
         }
         else if ( aString.EqualsAscii( SC_UNO_LINKDISPBIT ) )
         {
@@ -2349,8 +2368,90 @@ sal_Bool SAL_CALL ScDatabaseRangesObj::hasByName( const rtl::OUString& aName )
 
 //------------------------------------------------------------------------
 
+ScUnnamedDatabaseRangesObj::ScUnnamedDatabaseRangesObj(ScDocShell* pDocSh) :
+    pDocShell( pDocSh )
+{
+    pDocShell->GetDocument()->AddUnoObject(*this);
+}
+
+ScUnnamedDatabaseRangesObj::~ScUnnamedDatabaseRangesObj()
+{
+    if (pDocShell)
+        pDocShell->GetDocument()->RemoveUnoObject(*this);
+}
+
+void ScUnnamedDatabaseRangesObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
+{
+    //	Referenz-Update interessiert hier nicht
+
+    if ( rHint.ISA( SfxSimpleHint ) &&
+            ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
+    {
+        pDocShell = NULL;		// ungueltig geworden
+    }
+}
+
+// XUnnamedDatabaseRanges
+
+void ScUnnamedDatabaseRangesObj::setByTable( const table::CellRangeAddress& aRange )
+                                throw( uno::RuntimeException,
+                                        lang::IndexOutOfBoundsException )
+{
+    SolarMutexGuard aGuard;
+    bool bDone = false;
+    if (pDocShell)
+    {
+        if ( pDocShell->GetDocument()->GetTableCount() >= aRange.Sheet )
+            throw lang::IndexOutOfBoundsException();
 
+        ScDBDocFunc aFunc(*pDocShell);
+        String aString(RTL_CONSTASCII_USTRINGPARAM(STR_DB_LOCAL_NONAME));
+        ScRange aUnnamedRange( (SCCOL)aRange.StartColumn, (SCROW)aRange.StartRow, aRange.Sheet,
+                            (SCCOL)aRange.EndColumn,   (SCROW)aRange.EndRow,   aRange.Sheet );
+        bDone = aFunc.AddDBRange( aString, aUnnamedRange, sal_True );
+    }
+    if (!bDone)
+        throw uno::RuntimeException();		// no other exceptions specified
+}
 
+uno::Any ScUnnamedDatabaseRangesObj::getByTable( const sal_Int32 nTab )
+                                throw(uno::RuntimeException,
+                                    lang::IndexOutOfBoundsException,
+                                    container::NoSuchElementException)
+{
+    SolarMutexGuard aGuard;
+    if (pDocShell)
+    {
+        if ( pDocShell->GetDocument()->GetTableCount() >= nTab )
+            throw lang::IndexOutOfBoundsException();
+        uno::Reference<sheet::XDatabaseRange> xRange( new ScDatabaseRangeObj(pDocShell, (SCTAB) nTab) );
+        if (xRange.is())
+            return uno::makeAny(xRange);
+        else
+            throw container::NoSuchElementException();
+    }
+    else
+        throw uno::RuntimeException();
+}
+
+sal_Bool ScUnnamedDatabaseRangesObj::hasByTable( sal_Int32 nTab )
+                                    throw (uno::RuntimeException,
+                                        lang::IndexOutOfBoundsException)
+{
+    SolarMutexGuard aGuard;
+    if (pDocShell)
+    {
+         if (pDocShell->GetDocument()->GetTableCount() >= nTab)
+            throw lang::IndexOutOfBoundsException();
+        if (pDocShell->GetDocument()->GetAnonymousDBData((SCTAB) nTab))
+            return true;
+        return false;
+    }
+    else
+        return false;
+}
+
+//------------------------------------------------------------------------
 
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list