diff options
author | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2011-05-05 17:59:58 +0200 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2011-05-08 19:45:47 +0200 |
commit | 75c3b913d8c78a980294f4e7085aec8cf507bd43 (patch) | |
tree | 330482801de00f55372dfa88bb92d8a0d6e70414 /sc | |
parent | ae79bad31b380addff6ec9ec8b39cf19eb993992 (diff) |
use sheet local db data in ScVbaRange::Autofilter
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/unonames.hxx | 1 | ||||
-rw-r--r-- | sc/source/ui/docshell/dbdocfun.cxx | 19 | ||||
-rw-r--r-- | sc/source/ui/inc/dbdocfun.hxx | 2 | ||||
-rw-r--r-- | sc/source/ui/unoobj/datauno.cxx | 2 | ||||
-rw-r--r-- | sc/source/ui/unoobj/docuno.cxx | 5 | ||||
-rw-r--r-- | sc/source/ui/vba/excelvbahelper.cxx | 43 | ||||
-rw-r--r-- | sc/source/ui/vba/excelvbahelper.hxx | 4 | ||||
-rw-r--r-- | sc/source/ui/vba/vbarange.cxx | 29 |
8 files changed, 53 insertions, 52 deletions
diff --git a/sc/inc/unonames.hxx b/sc/inc/unonames.hxx index 5fb6edaf592d..7bc50f1af812 100644 --- a/sc/inc/unonames.hxx +++ b/sc/inc/unonames.hxx @@ -48,6 +48,7 @@ #define SC_UNO_EXTERNALDOCLINKS "ExternalDocLinks" #define SC_UNO_COLLABELRNG "ColumnLabelRanges" #define SC_UNO_DATABASERNG "DatabaseRanges" +#define SC_UNO_UNNAMEDDBRNG "UnnamedDatabaseRanges" #define SC_UNO_NAMEDRANGES "NamedRanges" #define SC_UNO_ROWLABELRNG "RowLabelRanges" #define SC_UNO_SHEETLINKS "SheetLinks" diff --git a/sc/source/ui/docshell/dbdocfun.cxx b/sc/source/ui/docshell/dbdocfun.cxx index 8991706293a1..8fde7e29e57a 100644 --- a/sc/source/ui/docshell/dbdocfun.cxx +++ b/sc/source/ui/docshell/dbdocfun.cxx @@ -255,7 +255,7 @@ sal_Bool ScDBDocFunc::ModifyDBData( const ScDBData& rNewData, sal_Bool /* bApi * // ----------------------------------------------------------------- -sal_Bool ScDBDocFunc::RepeatDB( const String& rDBName, sal_Bool bRecord, sal_Bool bApi ) +sal_Bool ScDBDocFunc::RepeatDB( const String& rDBName, sal_Bool bRecord, sal_Bool bApi, bool bIsUnnamed, SCTAB aTab ) { //! auch fuer ScDBFunc::RepeatDB benutzen! @@ -263,12 +263,21 @@ sal_Bool ScDBDocFunc::RepeatDB( const String& rDBName, sal_Bool bRecord, sal_Boo ScDocument* pDoc = rDocShell.GetDocument(); if (bRecord && !pDoc->IsUndoEnabled()) bRecord = false; - ScDBCollection* pColl = pDoc->GetDBCollection(); - sal_uInt16 nIndex; - if ( pColl && pColl->SearchName( rDBName, nIndex ) ) + ScDBData* pDBData = NULL; + if (bIsUnnamed) { - ScDBData* pDBData = (*pColl)[nIndex]; + pDBData = pDoc->GetAnonymousDBData( aTab ); + } + else + { + sal_uInt16 nIndex; + ScDBCollection* pColl = pDoc->GetDBCollection(); + if ( pColl && pColl->SearchName( rDBName, nIndex ) ) + pDBData = (*pColl)[nIndex]; + } + if ( pDBData ) + { ScQueryParam aQueryParam; pDBData->GetQueryParam( aQueryParam ); sal_Bool bQuery = aQueryParam.GetEntry(0).bDoQuery; diff --git a/sc/source/ui/inc/dbdocfun.hxx b/sc/source/ui/inc/dbdocfun.hxx index 132eb9a3750b..11b2ce27ef62 100644 --- a/sc/source/ui/inc/dbdocfun.hxx +++ b/sc/source/ui/inc/dbdocfun.hxx @@ -114,7 +114,7 @@ public: sal_Bool RenameDBRange( const String& rOld, const String& rNew, sal_Bool bApi ); sal_Bool ModifyDBData( const ScDBData& rNewData, sal_Bool bApi ); // Name unveraendert - sal_Bool RepeatDB( const String& rDBName, sal_Bool bRecord, sal_Bool bApi ); + sal_Bool RepeatDB( const String& rDBName, sal_Bool bRecord, sal_Bool bApi, bool bIsUnnamed=false, SCTAB aTab = 0); sal_Bool DataPilotUpdate( ScDPObject* pOldObj, const ScDPObject* pNewObj, sal_Bool bRecord, sal_Bool bApi, sal_Bool bAllowMove = false ); diff --git a/sc/source/ui/unoobj/datauno.cxx b/sc/source/ui/unoobj/datauno.cxx index 20610d9add47..e85742369e3e 100644 --- a/sc/source/ui/unoobj/datauno.cxx +++ b/sc/source/ui/unoobj/datauno.cxx @@ -1903,7 +1903,7 @@ void SAL_CALL ScDatabaseRangeObj::refresh() throw(uno::RuntimeException) // interne Operationen (sort, query, subtotal) nur, wenn kein Fehler if (bContinue) - aFunc.RepeatDB( pData->GetName(), sal_True, sal_True ); + aFunc.RepeatDB( pData->GetName(), true, true, bIsUnnamed, aTab ); } } diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx index 06d4ce212237..4a22857fb02d 100644 --- a/sc/source/ui/unoobj/docuno.cxx +++ b/sc/source/ui/unoobj/docuno.cxx @@ -56,6 +56,7 @@ #include <com/sun/star/util/Date.hpp> #include <com/sun/star/sheet/XNamedRanges.hpp> #include <com/sun/star/sheet/XLabelRanges.hpp> +#include <com/sun/star/sheet/XUnnamedDatabaseRanges.hpp> #include <com/sun/star/i18n/XForbiddenCharacters.hpp> #include <com/sun/star/script/XLibraryContainer.hpp> #include <com/sun/star/lang/XInitialization.hpp> @@ -1780,6 +1781,10 @@ uno::Any SAL_CALL ScModelObj::getPropertyValue( const rtl::OUString& aPropertyNa { aRet <<= uno::Reference<sheet::XDatabaseRanges>(new ScDatabaseRangesObj( pDocShell )); } + else if ( aString.EqualsAscii( SC_UNO_UNNAMEDDBRNG ) ) + { + aRet <<= uno::Reference<sheet::XUnnamedDatabaseRanges>(new ScUnnamedDatabaseRangesObj(pDocShell)); + } else if ( aString.EqualsAscii( SC_UNO_COLLABELRNG ) ) { aRet <<= uno::Reference<sheet::XLabelRanges>(new ScLabelRangesObj( pDocShell, sal_True )); diff --git a/sc/source/ui/vba/excelvbahelper.cxx b/sc/source/ui/vba/excelvbahelper.cxx index 4f49aab539c4..e7a1c74e9aa9 100644 --- a/sc/source/ui/vba/excelvbahelper.cxx +++ b/sc/source/ui/vba/excelvbahelper.cxx @@ -59,36 +59,33 @@ GetDataBaseRanges( ScDocShell* pShell ) throw ( uno::RuntimeException ) return xDBRanges; } +uno::Reference< sheet::XUnnamedDatabaseRanges > +GetUnnamedDataBaseRanges( ScDocShell* pShell ) throw ( uno::RuntimeException ) +{ + uno::Reference< frame::XModel > xModel; + if ( pShell ) + xModel.set( pShell->GetModel(), uno::UNO_QUERY_THROW ); + uno::Reference< beans::XPropertySet > xModelProps( xModel, uno::UNO_QUERY_THROW ); + uno::Reference< sheet::XUnnamedDatabaseRanges > xUnnamedDBRanges( xModelProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("UnnamedDatabaseRanges") ) ), uno::UNO_QUERY_THROW ); + return xUnnamedDBRanges; +} + // returns the XDatabaseRange for the autofilter on sheet (nSheet) // also populates sName with the name of range uno::Reference< sheet::XDatabaseRange > -GetAutoFiltRange( ScDocShell* pShell, sal_Int16 nSheet, rtl::OUString& sName ) throw ( uno::RuntimeException ) +GetAutoFiltRange( ScDocShell* pShell, sal_Int16 nSheet ) throw ( uno::RuntimeException ) { - uno::Reference< container::XIndexAccess > xIndexAccess( GetDataBaseRanges( pShell ), uno::UNO_QUERY_THROW ); + uno::Reference< sheet::XUnnamedDatabaseRanges > xUnnamedDBRanges( GetUnnamedDataBaseRanges( pShell ), uno::UNO_QUERY_THROW ); uno::Reference< sheet::XDatabaseRange > xDataBaseRange; - table::CellRangeAddress dbAddress; - for ( sal_Int32 index=0; index < xIndexAccess->getCount(); ++index ) + if (xUnnamedDBRanges->hasByTable( nSheet ) ) { - uno::Reference< sheet::XDatabaseRange > xDBRange( xIndexAccess->getByIndex( index ), uno::UNO_QUERY_THROW ); - uno::Reference< container::XNamed > xNamed( xDBRange, uno::UNO_QUERY_THROW ); - // autofilters work weirdly with openoffice, unnamed is the default - // named range which is used to create an autofilter, but - // its also possible that another name could be used - // this also causes problems when an autofilter is created on - // another sheet - // ( but.. you can use any named range ) - dbAddress = xDBRange->getDataArea(); - if ( dbAddress.Sheet == nSheet ) + uno::Reference< sheet::XDatabaseRange > xDBRange( xUnnamedDBRanges->getByTable( nSheet ) , uno::UNO_QUERY_THROW ); + sal_Bool bHasAuto = false; + uno::Reference< beans::XPropertySet > xProps( xDBRange, uno::UNO_QUERY_THROW ); + xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("AutoFilter") ) ) >>= bHasAuto; + if ( bHasAuto ) { - sal_Bool bHasAuto = false; - uno::Reference< beans::XPropertySet > xProps( xDBRange, uno::UNO_QUERY_THROW ); - xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("AutoFilter") ) ) >>= bHasAuto; - if ( bHasAuto ) - { - sName = xNamed->getName(); - xDataBaseRange=xDBRange; - break; - } + xDataBaseRange=xDBRange; } } return xDataBaseRange; diff --git a/sc/source/ui/vba/excelvbahelper.hxx b/sc/source/ui/vba/excelvbahelper.hxx index 4534cb1dd918..13594b74e2b7 100644 --- a/sc/source/ui/vba/excelvbahelper.hxx +++ b/sc/source/ui/vba/excelvbahelper.hxx @@ -32,6 +32,7 @@ #include "docsh.hxx" #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/table/XCellRange.hpp> #include <com/sun/star/sheet/XSheetCellRangeContainer.hpp> #include <com/sun/star/sheet/XSpreadsheet.hpp> @@ -63,8 +64,9 @@ formula::FormulaGrammar::Grammar GetFormulaGrammar( ScDocument* pDoc, const ScAd void CompileExcelFormulaToODF( ScDocument* pDoc, const String& rOldFormula, String& rNewFormula ); void CompileODFFormulaToExcel( ScDocument* pDoc, const String& rOldFormula, String& rNewFormula, const formula::FormulaGrammar::Grammar eGrammar ); css::uno::Reference< css::sheet::XDatabaseRanges > GetDataBaseRanges( ScDocShell* pShell ) throw ( css::uno::RuntimeException ); +css::uno::Reference< css::sheet::XUnnamedDatabaseRanges > GetUnnamedDataBaseRanges( ScDocShell* pShell ) throw ( css::uno::RuntimeException ); -css::uno::Reference< css::sheet::XDatabaseRange > GetAutoFiltRange( ScDocShell* pShell, sal_Int16 nSheet, rtl::OUString& sName ) throw ( css::uno::RuntimeException ); +css::uno::Reference< css::sheet::XDatabaseRange > GetAutoFiltRange( ScDocShell* pShell, sal_Int16 nSheet ) throw ( css::uno::RuntimeException ); css::uno::Reference< ooo::vba::XHelperInterface > getUnoSheetModuleObj( const css::uno::Reference< css::sheet::XSpreadsheet >& xSheet ) throw ( css::uno::RuntimeException ); css::uno::Reference< ooo::vba::XHelperInterface > getUnoSheetModuleObj( const css::uno::Reference< css::sheet::XSheetCellRangeContainer >& xRanges ) throw ( css::uno::RuntimeException ); css::uno::Reference< ooo::vba::XHelperInterface > getUnoSheetModuleObj( const css::uno::Reference< css::table::XCellRange >& xRange ) throw ( css::uno::RuntimeException ); diff --git a/sc/source/ui/vba/vbarange.cxx b/sc/source/ui/vba/vbarange.cxx index fb09894ffeff..c538fe88e977 100644 --- a/sc/source/ui/vba/vbarange.cxx +++ b/sc/source/ui/vba/vbarange.cxx @@ -39,6 +39,7 @@ #include <com/sun/star/script/vba/XVBAEventProcessor.hpp> #include <com/sun/star/sheet/XDatabaseRange.hpp> #include <com/sun/star/sheet/XDatabaseRanges.hpp> +#include <com/sun/star/sheet/XUnnamedDatabaseRanges.hpp> #include <com/sun/star/sheet/XGoalSeek.hpp> #include <com/sun/star/sheet/XSheetOperation.hpp> #include <com/sun/star/sheet/CellFlags.hpp> @@ -4334,20 +4335,10 @@ ScVbaRange::ApplicationRange( const uno::Reference< uno::XComponentContext >& xC // Helper functions for AutoFilter ScDBData* lcl_GetDBData_Impl( ScDocShell* pDocShell, sal_Int16 nSheet ) { - rtl::OUString sName; - excel::GetAutoFiltRange( pDocShell, nSheet, sName ); - OSL_TRACE("lcl_GetDBData_Impl got autofilter range %s for sheet %d", - rtl::OUStringToOString( sName, RTL_TEXTENCODING_UTF8 ).getStr() , nSheet ); ScDBData* pRet = NULL; if (pDocShell) { - ScDBCollection* pNames = pDocShell->GetDocument()->GetDBCollection(); - if (pNames) - { - sal_uInt16 nPos = 0; - if (pNames->SearchName( sName , nPos )) - pRet = (*pNames)[nPos]; - } + pRet = pDocShell->GetDocument()->GetAnonymousDBData(nSheet); } return pRet; } @@ -4501,8 +4492,7 @@ ScVbaRange::AutoFilter( const uno::Any& Field, const uno::Any& Criteria1, const sal_Int16 nSheet = thisAddress.Sheet; ScDocShell* pShell = getScDocShell(); sal_Bool bHasAuto = false; - rtl::OUString sAutofiltRangeName; - uno::Reference< sheet::XDatabaseRange > xDataBaseRange = excel::GetAutoFiltRange( pShell, nSheet, sAutofiltRangeName ); + uno::Reference< sheet::XDatabaseRange > xDataBaseRange = excel::GetAutoFiltRange( pShell, nSheet ); if ( xDataBaseRange.is() ) bHasAuto = true; @@ -4549,16 +4539,13 @@ ScVbaRange::AutoFilter( const uno::Any& Field, const uno::Any& Criteria1, const } } - uno::Reference< sheet::XDatabaseRanges > xDBRanges = excel::GetDataBaseRanges( pShell ); + uno::Reference< sheet::XUnnamedDatabaseRanges > xDBRanges = excel::GetUnnamedDataBaseRanges( pShell ); if ( xDBRanges.is() ) { - rtl::OUString sGenName( RTL_CONSTASCII_USTRINGPARAM("VBA_Autofilter_") ); - sGenName += rtl::OUString::valueOf( static_cast< sal_Int32 >( nSheet ) ); - OSL_TRACE("Going to add new autofilter range.. name %s", - rtl::OUStringToOString( sGenName, RTL_TEXTENCODING_UTF8 ).getStr() , nSheet ); - if ( !xDBRanges->hasByName( sGenName ) ) - xDBRanges->addNewByName( sGenName, autoFiltAddress ); - xDataBaseRange.set( xDBRanges->getByName( sGenName ), uno::UNO_QUERY_THROW ); + OSL_TRACE("Going to add new autofilter range.. sheet %i", nSheet ); + if ( !xDBRanges->hasByTable( nSheet ) ) + xDBRanges->setByTable( autoFiltAddress ); + xDataBaseRange.set( xDBRanges->getByTable(nSheet ), uno::UNO_QUERY_THROW ); } if ( !xDataBaseRange.is() ) throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Failed to find the autofilter placeholder range" ) ), uno::Reference< uno::XInterface >() ); |