diff options
Diffstat (limited to 'sc/source/ui/unoobj/dapiuno.cxx')
-rw-r--r-- | sc/source/ui/unoobj/dapiuno.cxx | 247 |
1 files changed, 235 insertions, 12 deletions
diff --git a/sc/source/ui/unoobj/dapiuno.cxx b/sc/source/ui/unoobj/dapiuno.cxx index a921d1e125f2..ab94be3052e0 100644 --- a/sc/source/ui/unoobj/dapiuno.cxx +++ b/sc/source/ui/unoobj/dapiuno.cxx @@ -43,15 +43,19 @@ #include "unoguard.hxx" #include "dpobject.hxx" #include "dpshttab.hxx" +#include "dpsdbtab.hxx" #include "dpsave.hxx" #include "dbdocfun.hxx" #include "unonames.hxx" #include "dpgroup.hxx" #include "dpdimsave.hxx" +#include "hints.hxx" + #include <com/sun/star/sheet/XHierarchiesSupplier.hpp> #include <com/sun/star/sheet/XLevelsSupplier.hpp> #include <com/sun/star/sheet/XMembersSupplier.hpp> #include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/sheet/DataImportMode.hpp> #include <com/sun/star/sheet/DataPilotFieldGroupBy.hpp> #include <com/sun/star/sheet/DataPilotFieldFilter.hpp> #include <com/sun/star/sheet/DataPilotOutputRangeType.hpp> @@ -105,9 +109,12 @@ const SfxItemPropertyMapEntry* lcl_GetDataPilotDescriptorBaseMap() {MAP_CHAR_LEN(SC_UNO_COLGRAND), 0, &getBooleanCppuType(), 0, 0 }, {MAP_CHAR_LEN(SC_UNO_DRILLDOWN), 0, &getBooleanCppuType(), 0, 0 }, {MAP_CHAR_LEN(SC_UNO_IGNEMPROWS), 0, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_IMPORTDESC), 0, &getCppuType((uno::Sequence<beans::PropertyValue>*)0), 0, 0 }, {MAP_CHAR_LEN(SC_UNO_RPTEMPTY), 0, &getBooleanCppuType(), 0, 0 }, {MAP_CHAR_LEN(SC_UNO_ROWGRAND), 0, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_SERVICEARG), 0, &getCppuType((uno::Sequence<beans::PropertyValue>*)0), 0, 0 }, {MAP_CHAR_LEN(SC_UNO_SHOWFILT), 0, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_SOURCESERV), 0, &getCppuType((rtl::OUString*)0), 0, 0 }, {0,0,0,0,0,0} }; return aDataPilotDescriptorBaseMap_Impl; @@ -261,8 +268,7 @@ ScDPObject* lcl_GetDPObject( ScDocShell* pDocShell, SCTAB nTab, const String& rN for (USHORT i=0; i<nCount; i++) { ScDPObject* pDPObj = (*pColl)[i]; - if ( pDPObj->IsSheetData() && - pDPObj->GetOutRange().aStart.Tab() == nTab && + if ( pDPObj->GetOutRange().aStart.Tab() == nTab && pDPObj->GetName() == rName ) return pDPObj; } @@ -344,7 +350,7 @@ ScDataPilotTableObj* ScDataPilotTablesObj::GetObjectByIndex_Impl( sal_Int32 nInd for (USHORT i=0; i<nCount; i++) { ScDPObject* pDPObj = (*pColl)[i]; - if ( pDPObj->IsSheetData() && pDPObj->GetOutRange().aStart.Tab() == nTab ) + if ( pDPObj->GetOutRange().aStart.Tab() == nTab ) { if ( nFound == nIndex ) { @@ -496,7 +502,7 @@ sal_Int32 SAL_CALL ScDataPilotTablesObj::getCount() throw(RuntimeException) for (USHORT i=0; i<nCount; i++) { ScDPObject* pDPObj = (*pColl)[i]; - if ( pDPObj->IsSheetData() && pDPObj->GetOutRange().aStart.Tab() == nTab ) + if ( pDPObj->GetOutRange().aStart.Tab() == nTab ) ++nFound; } return nFound; @@ -560,7 +566,7 @@ Sequence<OUString> SAL_CALL ScDataPilotTablesObj::getElementNames() for (i=0; i<nCount; i++) { ScDPObject* pDPObj = (*pColl)[i]; - if ( pDPObj->IsSheetData() && pDPObj->GetOutRange().aStart.Tab() == nTab ) + if ( pDPObj->GetOutRange().aStart.Tab() == nTab ) ++nFound; } @@ -570,7 +576,7 @@ Sequence<OUString> SAL_CALL ScDataPilotTablesObj::getElementNames() for (i=0; i<nCount; i++) { ScDPObject* pDPObj = (*pColl)[i]; - if ( pDPObj->IsSheetData() && pDPObj->GetOutRange().aStart.Tab() == nTab ) + if ( pDPObj->GetOutRange().aStart.Tab() == nTab ) pAry[nPos++] = pDPObj->GetName(); } @@ -598,8 +604,7 @@ sal_Bool SAL_CALL ScDataPilotTablesObj::hasByName( const OUString& aName ) //! allow all data sources!!! ScDPObject* pDPObj = (*pColl)[i]; - if ( pDPObj->IsSheetData() && - pDPObj->GetOutRange().aStart.Tab() == nTab && + if ( pDPObj->GetOutRange().aStart.Tab() == nTab && pDPObj->GetName() == aNamStr ) return TRUE; } @@ -696,11 +701,12 @@ CellRangeAddress SAL_CALL ScDataPilotDescriptorBase::getSourceRange() ScUnoGuard aGuard; ScDPObject* pDPObject(GetDPObject()); - if (!pDPObject || !pDPObject->IsSheetData()) + if (!pDPObject) throw RuntimeException(); CellRangeAddress aRet; - ScUnoConversion::FillApiRange( aRet, pDPObject->GetSheetDesc()->aSourceRange ); + if (pDPObject->IsSheetData()) + ScUnoConversion::FillApiRange( aRet, pDPObject->GetSheetDesc()->aSourceRange ); return aRet; } @@ -818,6 +824,99 @@ void SAL_CALL ScDataPilotDescriptorBase::setPropertyValue( const OUString& aProp { aNewData.SetDrillDown(::cppu::any2bool( aValue )); } + else if ( aNameString.EqualsAscii( SC_UNO_IMPORTDESC ) ) + { + uno::Sequence<beans::PropertyValue> aArgSeq; + if ( aValue >>= aArgSeq ) + { + ScImportSourceDesc aImportDesc; + + const ScImportSourceDesc* pOldDesc = pDPObject->GetImportSourceDesc(); + if (pOldDesc) + aImportDesc = *pOldDesc; + + ScImportParam aParam; + ScImportDescriptor::FillImportParam( aParam, aArgSeq ); + + USHORT nNewType = sheet::DataImportMode_NONE; + if ( aParam.bImport ) + { + if ( aParam.bSql ) + nNewType = sheet::DataImportMode_SQL; + else if ( aParam.nType == ScDbQuery ) + nNewType = sheet::DataImportMode_QUERY; + else + nNewType = sheet::DataImportMode_TABLE; + } + aImportDesc.nType = nNewType; + aImportDesc.aDBName = aParam.aDBName; + aImportDesc.aObject = aParam.aStatement; + aImportDesc.bNative = aParam.bNative; + + pDPObject->SetImportDesc( aImportDesc ); + } + } + else if ( aNameString.EqualsAscii( SC_UNO_SOURCESERV ) ) + { + rtl::OUString aStrVal; + if ( aValue >>= aStrVal ) + { + String aEmpty; + ScDPServiceDesc aServiceDesc(aEmpty, aEmpty, aEmpty, aEmpty, aEmpty); + + const ScDPServiceDesc* pOldDesc = pDPObject->GetDPServiceDesc(); + if (pOldDesc) + aServiceDesc = *pOldDesc; + + aServiceDesc.aServiceName = aStrVal; + + pDPObject->SetServiceData( aServiceDesc ); + } + } + else if ( aNameString.EqualsAscii( SC_UNO_SERVICEARG ) ) + { + uno::Sequence<beans::PropertyValue> aArgSeq; + if ( aValue >>= aArgSeq ) + { + String aEmpty; + ScDPServiceDesc aServiceDesc(aEmpty, aEmpty, aEmpty, aEmpty, aEmpty); + + const ScDPServiceDesc* pOldDesc = pDPObject->GetDPServiceDesc(); + if (pOldDesc) + aServiceDesc = *pOldDesc; + + rtl::OUString aStrVal; + sal_Int32 nArgs = aArgSeq.getLength(); + for (sal_Int32 nArgPos=0; nArgPos<nArgs; ++nArgPos) + { + const beans::PropertyValue& rProp = aArgSeq[nArgPos]; + String aPropName(rProp.Name); + + if (aPropName.EqualsAscii( SC_UNO_SOURCENAME )) + { + if ( rProp.Value >>= aStrVal ) + aServiceDesc.aParSource = aStrVal; + } + else if (aPropName.EqualsAscii( SC_UNO_OBJECTNAME )) + { + if ( rProp.Value >>= aStrVal ) + aServiceDesc.aParName = aStrVal; + } + else if (aPropName.EqualsAscii( SC_UNO_USERNAME )) + { + if ( rProp.Value >>= aStrVal ) + aServiceDesc.aParUser = aStrVal; + } + else if (aPropName.EqualsAscii( SC_UNO_PASSWORD )) + { + if ( rProp.Value >>= aStrVal ) + aServiceDesc.aParPass = aStrVal; + } + } + + pDPObject->SetServiceData( aServiceDesc ); + } + } else throw UnknownPropertyException(); @@ -868,6 +967,63 @@ Any SAL_CALL ScDataPilotDescriptorBase::getPropertyValue( const OUString& aPrope { aRet = ::cppu::bool2any( aNewData.GetDrillDown() ); } + else if ( aNameString.EqualsAscii( SC_UNO_IMPORTDESC ) ) + { + const ScImportSourceDesc* pImportDesc = pDPObject->GetImportSourceDesc(); + if ( pImportDesc ) + { + // fill ScImportParam so ScImportDescriptor::FillProperties can be used + ScImportParam aParam; + aParam.bImport = ( pImportDesc->nType != sheet::DataImportMode_NONE ); + aParam.aDBName = pImportDesc->aDBName; + aParam.aStatement = pImportDesc->aObject; + aParam.bNative = pImportDesc->bNative; + aParam.bSql = ( pImportDesc->nType == sheet::DataImportMode_SQL ); + aParam.nType = static_cast<BYTE>(( pImportDesc->nType == sheet::DataImportMode_QUERY ) ? ScDbQuery : ScDbTable); + + uno::Sequence<beans::PropertyValue> aSeq( ScImportDescriptor::GetPropertyCount() ); + ScImportDescriptor::FillProperties( aSeq, aParam ); + aRet <<= aSeq; + } + else + { + // empty sequence + uno::Sequence<beans::PropertyValue> aEmpty(0); + aRet <<= aEmpty; + } + } + else if ( aNameString.EqualsAscii( SC_UNO_SOURCESERV ) ) + { + rtl::OUString aServiceName; + const ScDPServiceDesc* pServiceDesc = pDPObject->GetDPServiceDesc(); + if (pServiceDesc) + aServiceName = pServiceDesc->aServiceName; + aRet <<= aServiceName; // empty string if no ServiceDesc set + } + else if ( aNameString.EqualsAscii( SC_UNO_SERVICEARG ) ) + { + const ScDPServiceDesc* pServiceDesc = pDPObject->GetDPServiceDesc(); + if (pServiceDesc) + { + uno::Sequence<beans::PropertyValue> aSeq( 4 ); + beans::PropertyValue* pArray = aSeq.getArray(); + pArray[0].Name = rtl::OUString::createFromAscii( SC_UNO_SOURCENAME ); + pArray[0].Value <<= rtl::OUString( pServiceDesc->aParSource ); + pArray[1].Name = rtl::OUString::createFromAscii( SC_UNO_OBJECTNAME ); + pArray[1].Value <<= rtl::OUString( pServiceDesc->aParName ); + pArray[2].Name = rtl::OUString::createFromAscii( SC_UNO_USERNAME ); + pArray[2].Value <<= rtl::OUString( pServiceDesc->aParUser ); + pArray[3].Name = rtl::OUString::createFromAscii( SC_UNO_PASSWORD ); + pArray[3].Value <<= rtl::OUString( pServiceDesc->aParPass ); + aRet <<= aSeq; + } + else + { + // empty sequence + uno::Sequence<beans::PropertyValue> aEmpty(0); + aRet <<= aEmpty; + } + } else throw UnknownPropertyException(); } @@ -966,7 +1122,8 @@ ScDataPilotDescriptorBase* ScDataPilotDescriptorBase::getImplementation( ScDataPilotTableObj::ScDataPilotTableObj(ScDocShell* pDocSh, SCTAB nT, const String& rN) : ScDataPilotDescriptorBase( pDocSh ), nTab( nT ), - aName( rN ) + aName( rN ), + aModifyListeners( 0 ) { } @@ -981,6 +1138,7 @@ Any SAL_CALL ScDataPilotTableObj::queryInterface( const uno::Type& rType ) // we also need to do the same for XDataPilotTable SC_QUERYINTERFACE( XDataPilotTable ) SC_QUERYINTERFACE( XDataPilotTable2 ) + SC_QUERYINTERFACE( XModifyBroadcaster ) return ScDataPilotDescriptorBase::queryInterface( rType ); } @@ -1004,12 +1162,13 @@ Sequence< uno::Type > SAL_CALL ScDataPilotTableObj::getTypes() throw(RuntimeExce sal_Int32 nParentLen = aParentTypes.getLength(); const uno::Type* pParentPtr = aParentTypes.getConstArray(); - aTypes.realloc( nParentLen + 1 ); + aTypes.realloc( nParentLen + 2 ); uno::Type* pPtr = aTypes.getArray(); for (sal_Int32 i = 0; i < nParentLen; ++i) pPtr[ i ] = pParentPtr[ i ]; // parent types first pPtr[ nParentLen ] = getCppuType( (const Reference< XDataPilotTable2 >*)0 ); + pPtr[ nParentLen+1 ] = getCppuType( (const Reference< XModifyBroadcaster >*)0 ); } return aTypes; } @@ -1183,6 +1342,70 @@ CellRangeAddress SAL_CALL ScDataPilotTableObj::getOutputRangeByType( sal_Int32 n return aRet; } +void SAL_CALL ScDataPilotTableObj::addModifyListener( const uno::Reference<util::XModifyListener>& aListener ) + throw (uno::RuntimeException) +{ + ScUnoGuard aGuard; + + uno::Reference<util::XModifyListener> *pObj = new uno::Reference<util::XModifyListener>( aListener ); + aModifyListeners.Insert( pObj, aModifyListeners.Count() ); + + if ( aModifyListeners.Count() == 1 ) + { + acquire(); // don't lose this object (one ref for all listeners) + } +} + +void SAL_CALL ScDataPilotTableObj::removeModifyListener( const uno::Reference<util::XModifyListener>& aListener ) + throw (uno::RuntimeException) +{ + ScUnoGuard aGuard; + + acquire(); // in case the listeners have the last ref - released below + + USHORT nCount = aModifyListeners.Count(); + for ( USHORT n=nCount; n--; ) + { + uno::Reference<util::XModifyListener> *pObj = aModifyListeners[n]; + if ( *pObj == aListener ) + { + aModifyListeners.DeleteAndDestroy( n ); + + if ( aModifyListeners.Count() == 0 ) + { + release(); // release the ref for the listeners + } + + break; + } + } + + release(); // might delete this object +} + +void ScDataPilotTableObj::Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) +{ + if ( rHint.ISA(ScDataPilotModifiedHint) && + static_cast<const ScDataPilotModifiedHint&>(rHint).GetName() == aName ) + { + Refreshed_Impl(); + } + + ScDataPilotDescriptorBase::Notify( rBC, rHint ); +} + +void ScDataPilotTableObj::Refreshed_Impl() +{ + lang::EventObject aEvent; + aEvent.Source.set((cppu::OWeakObject*)this); + + // the EventObject holds a Ref to this object until after the listener calls + + ScDocument* pDoc = GetDocShell()->GetDocument(); + for ( USHORT n=0; n<aModifyListeners.Count(); n++ ) + pDoc->AddUnoListenerCall( *aModifyListeners[n], aEvent ); +} + // ============================================================================ ScDataPilotDescriptor::ScDataPilotDescriptor(ScDocShell* pDocSh) : |