diff options
Diffstat (limited to 'sfx2/source/doc/sfxbasemodel.cxx')
-rw-r--r-- | sfx2/source/doc/sfxbasemodel.cxx | 197 |
1 files changed, 129 insertions, 68 deletions
diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx index ee449d15b419..d24a95332b58 100644 --- a/sfx2/source/doc/sfxbasemodel.cxx +++ b/sfx2/source/doc/sfxbasemodel.cxx @@ -102,7 +102,7 @@ //________________________________________________________________________________________________________ #include <sfx2/sfxbasecontroller.hxx> -#include "viewfac.hxx" +#include "sfx2/viewfac.hxx" #include "workwin.hxx" #include <sfx2/signaturestate.hxx> #include <sfx2/sfxuno.hxx> @@ -114,7 +114,7 @@ #include <sfx2/request.hxx> #include <sfx2/objuno.hxx> #include <sfx2/printer.hxx> -#include <basmgr.hxx> +#include <sfx2/basmgr.hxx> #include <sfx2/event.hxx> #include <eventsupplier.hxx> #include <sfx2/evntconf.hxx> @@ -125,12 +125,12 @@ #include <sfx2/docfac.hxx> #include <sfx2/fcontnr.hxx> #include "sfx2/docstoragemodifylistener.hxx" -#include "brokenpackageint.hxx" +#include "sfx2/brokenpackageint.hxx" #include "graphhelp.hxx" #include <sfx2/msgpool.hxx> #include <sfx2/DocumentMetadataAccess.hxx> -#include <sfxresid.hxx> +#include <sfx2/sfxresid.hxx> //________________________________________________________________________________________________________ // const @@ -980,6 +980,8 @@ sal_Bool SAL_CALL SfxBaseModel::attachResource( const ::rtl::OUString& aArgs.remove( "InputStream" ); aArgs.remove( "URL" ); aArgs.remove( "Frame" ); + aArgs.remove( "Password" ); + aArgs.remove( "EncryptionData" ); // TODO/LATER: all the parameters that are accepted by ItemSet of the DocShell must be removed here @@ -1633,6 +1635,11 @@ void SAL_CALL SfxBaseModel::storeAsURL( const ::rtl::OUString& uno::Sequence< beans::PropertyValue > aSequence ; TransformItems( SID_OPENDOC, *m_pData->m_pObjectShell->GetMedium()->GetItemSet(), aSequence ); attachResource( rURL, aSequence ); + +#if OSL_DEBUG_LEVEL > 0 + SFX_ITEMSET_ARG( m_pData->m_pObjectShell->GetMedium()->GetItemSet(), pPasswdItem, SfxStringItem, SID_PASSWORD, sal_False); + OSL_ENSURE( !pPasswdItem, "There should be no Password property in the document MediaDescriptor!" ); +#endif } } @@ -1798,10 +1805,9 @@ void SAL_CALL SfxBaseModel::load( const uno::Sequence< beans::PropertyValue >& SFX_ITEMSET_ARG( pMedium->GetItemSet(), pRepairItem, SfxBoolItem, SID_REPAIRPACKAGE, FALSE ); if ( !pRepairItem || !pRepairItem->GetValue() ) { - RequestPackageReparation* pRequest = new RequestPackageReparation( aDocName ); - com::sun::star::uno::Reference< com::sun::star::task::XInteractionRequest > xRequest ( pRequest ); - xHandler->handle( xRequest ); - if( pRequest->isApproved() ) + RequestPackageReparation aRequest( aDocName ); + xHandler->handle( aRequest.GetRequest() ); + if( aRequest.isApproved() ) { // broken package: try second loading and allow repair pMedium->GetItemSet()->Put( SfxBoolItem( SID_REPAIRPACKAGE, sal_True ) ); @@ -1821,9 +1827,8 @@ void SAL_CALL SfxBaseModel::load( const uno::Sequence< beans::PropertyValue >& if ( nError == ERRCODE_IO_BROKENPACKAGE ) { // repair either not allowed or not successful - NotifyBrokenPackage* pNotifyRequest = new NotifyBrokenPackage( aDocName ); - com::sun::star::uno::Reference< com::sun::star::task::XInteractionRequest > xRequest ( pNotifyRequest ); - xHandler->handle( xRequest ); + NotifyBrokenPackage aRequest( aDocName ); + xHandler->handle( aRequest.GetRequest() ); } } } @@ -1891,6 +1896,11 @@ void SAL_CALL SfxBaseModel::load( const uno::Sequence< beans::PropertyValue >& SFX_ITEMSET_ARG( pMedium->GetItemSet(), pHidItem, SfxBoolItem, SID_HIDDEN, sal_False); if ( pHidItem ) bHidden = pHidItem->GetValue(); + +#if OSL_DEBUG_LEVEL > 0 + SFX_ITEMSET_ARG( pMedium->GetItemSet(), pPasswdItem, SfxStringItem, SID_PASSWORD, sal_False); + OSL_ENSURE( !pPasswdItem, "There should be no Password property in the document MediaDescriptor!" ); +#endif // !TODO: will be done by Framework! pMedium->SetUpdatePickList( !bHidden ); } @@ -2373,6 +2383,32 @@ void SAL_CALL SfxBaseModel::removeEventListener( const uno::Reference< XDOCEVENT m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< XDOCEVENTLISTENER >*)0), aListener ); } +//-------------------------------------------------------------------------------------------------------- +// XDocumentEventBroadcaster +//-------------------------------------------------------------------------------------------------------- +// --------------------------------- +void SAL_CALL SfxBaseModel::addDocumentEventListener( const uno::Reference< document::XDocumentEventListener >& aListener ) + throw ( uno::RuntimeException ) +{ + SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING ); + m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< document::XDocumentEventListener >*)0), aListener ); +} + +// --------------------------------- +void SAL_CALL SfxBaseModel::removeDocumentEventListener( const uno::Reference< document::XDocumentEventListener >& aListener ) + throw ( uno::RuntimeException ) +{ + SfxModelGuard aGuard( *this ); + m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< document::XDocumentEventListener >*)0), aListener ); +} + +// --------------------------------- +void SAL_CALL SfxBaseModel::notifyDocumentEvent( const ::rtl::OUString&, const uno::Reference< frame::XController2 >&, const uno::Any& ) + throw ( lang::IllegalArgumentException, lang::NoSupportException, uno::RuntimeException ) +{ + throw lang::NoSupportException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SfxBaseModel controlls all the sent notifications itself!" ) ), uno::Reference< uno::XInterface >() ); +} + //________________________________________________________________________________________________________ // SfxListener //________________________________________________________________________________________________________ @@ -2516,7 +2552,9 @@ void SfxBaseModel::Notify( SfxBroadcaster& rBC , break; } - postEvent_Impl( pNamedHint->GetEventName() ); + + SfxViewEventHint* pViewHint = PTR_CAST( SfxViewEventHint, &rHint ); + postEvent_Impl( pNamedHint->GetEventName(), pViewHint ? pViewHint->GetController() : uno::Reference< frame::XController2 >() ); } if ( pSimpleHint ) @@ -2670,49 +2708,41 @@ void SfxBaseModel::impl_store( const ::rtl::OUString& sURL aArgHash.erase( aFilterString ); aArgHash.erase( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) ) ); - // if the password is changed SaveAs should be done - // no password for encrypted document is also a change here - sal_Bool bPassChanged = sal_False; - - ::comphelper::SequenceAsHashMap::iterator aNewPassIter - = aArgHash.find( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Password" ) ) ); - SFX_ITEMSET_ARG( pMedium->GetItemSet(), pPasswordItem, SfxStringItem, SID_PASSWORD, sal_False ); - if ( pPasswordItem && aNewPassIter != aArgHash.end() ) + try { - ::rtl::OUString aNewPass; - aNewPassIter->second >>= aNewPass; - bPassChanged = !aNewPass.equals( pPasswordItem->GetValue() ); + storeSelf( aArgHash.getAsConstPropertyValueList() ); + bSaved = sal_True; } - else if ( pPasswordItem || aNewPassIter != aArgHash.end() ) - bPassChanged = sal_True; - - if ( !bPassChanged ) + catch( const lang::IllegalArgumentException& ) { - try + // some additional arguments do not allow to use saving, SaveAs should be done + // but only for normal documents, the shared documents would be overwritten in this case + // that would mean an information loss + // TODO/LATER: need a new interaction for this case + if ( m_pData->m_pObjectShell->IsDocShared() ) { - storeSelf( aArgHash.getAsConstPropertyValueList() ); - bSaved = sal_True; - } - catch( const lang::IllegalArgumentException& ) - { - // some additional arguments do not allow to use saving, SaveAs should be done - // but only for normal documents, the shared documents would be overwritten in this case - // that would mean an information loss - // TODO/LATER: need a new interaction for this case - if ( m_pData->m_pObjectShell->IsDocShared() ) + m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't store shared document!" ) ) ); + m_pData->m_pObjectShell->StoreLog(); + + uno::Sequence< beans::NamedValue > aNewEncryptionData = aArgHash.getUnpackedValueOrDefault( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EncryptionData" ) ), uno::Sequence< beans::NamedValue >() ); + if ( !aNewEncryptionData.getLength() ) { - m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't store shared document!" ) ) ); - m_pData->m_pObjectShell->StoreLog(); + ::rtl::OUString aNewPassword = aArgHash.getUnpackedValueOrDefault( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Password" ) ), ::rtl::OUString() ); + aNewEncryptionData = ::comphelper::OStorageHelper::CreatePackageEncryptionData( aNewPassword ); + } + uno::Sequence< beans::NamedValue > aOldEncryptionData; + GetEncryptionData_Impl( pMedium->GetItemSet(), aOldEncryptionData ); + + if ( !aOldEncryptionData.getLength() && !aNewEncryptionData.getLength() ) throw; + else + { + // if the password is changed a special error should be used in case of shared document + throw task::ErrorCodeIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Cant change password for shared document." ) ), uno::Reference< uno::XInterface >(), ERRCODE_SFX_SHARED_NOPASSWORDCHANGE ); } } } - else if ( m_pData->m_pObjectShell->IsDocShared() ) - { - // if the password is changed a special error should be used in case of shared document - throw task::ErrorCodeIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Cant change password for shared document." ) ), uno::Reference< uno::XInterface >(), ERRCODE_SFX_SHARED_NOPASSWORDCHANGE ); - } } } } @@ -2869,8 +2899,32 @@ void SfxBaseModel::impl_store( const ::rtl::OUString& sURL } //******************************************************************************************************** +namespace { +template< typename ListenerT, typename EventT > +class NotifySingleListenerIgnoreRE +{ +private: + typedef void ( SAL_CALL ListenerT::*NotificationMethod )( const EventT& ); + NotificationMethod m_pMethod; + const EventT& m_rEvent; +public: + NotifySingleListenerIgnoreRE( NotificationMethod method, const EventT& event ) : m_pMethod( method ), m_rEvent( event ) { } -void SfxBaseModel::postEvent_Impl( ::rtl::OUString aName ) + void operator()( const uno::Reference<ListenerT>& listener ) const + { + try + { + (listener.get()->*m_pMethod)( m_rEvent ); + } + catch( uno::RuntimeException& ) + { + // this exception is ignored to avoid problems with invalid listeners, the listener should be probably thrown away in future + } + } +}; +} // anonymous namespace + +void SfxBaseModel::postEvent_Impl( const ::rtl::OUString& aName, const uno::Reference< frame::XController2 >& xController ) { // object already disposed? if ( impl_isDisposed() ) @@ -2880,34 +2934,41 @@ void SfxBaseModel::postEvent_Impl( ::rtl::OUString aName ) if (!aName.getLength()) return; - ::cppu::OInterfaceContainerHelper* pIC = m_pData->m_aInterfaceContainer.getContainer( - ::getCppuType((const uno::Reference< XDOCEVENTLISTENER >*)0) ); - if( pIC ) + ::cppu::OInterfaceContainerHelper* pIC = + m_pData->m_aInterfaceContainer.getContainer( ::getCppuType( (const uno::Reference< document::XDocumentEventListener >*)0 ) ); + if ( pIC ) + { +#ifdef DBG_UTIL + ByteString aTmp( "SfxDocumentEvent: " ); + aTmp += ByteString( String(aName), RTL_TEXTENCODING_UTF8 ); + DBG_TRACE( aTmp.GetBuffer() ); +#endif + document::DocumentEvent aDocumentEvent( (frame::XModel*)this, aName, xController, uno::Any() ); + + pIC->forEach< document::XDocumentEventListener, NotifySingleListenerIgnoreRE< document::XDocumentEventListener, document::DocumentEvent > >( + NotifySingleListenerIgnoreRE< document::XDocumentEventListener, document::DocumentEvent >( + &document::XDocumentEventListener::documentEventOccured, + aDocumentEvent ) ); + } + + pIC = m_pData->m_aInterfaceContainer.getContainer( ::getCppuType( (const uno::Reference< document::XEventListener >*)0 ) ); + if ( pIC ) { #ifdef DBG_UTIL - ByteString aTmp( "SfxEvent: "); + ByteString aTmp( "SfxEvent: " ); aTmp += ByteString( String(aName), RTL_TEXTENCODING_UTF8 ); DBG_TRACE( aTmp.GetBuffer() ); #endif - document::EventObject aEvent( (frame::XModel *)this, aName ); - ::cppu::OInterfaceContainerHelper aIC( m_aMutex ); - uno::Sequence < uno::Reference < uno::XInterface > > aElements = pIC->getElements(); - for ( sal_Int32 nElem=0; nElem<aElements.getLength(); nElem++ ) - aIC.addInterface( aElements[nElem] ); - ::cppu::OInterfaceIteratorHelper aIt( aIC ); - while( aIt.hasMoreElements() ) - { - try - { - ((XDOCEVENTLISTENER *)aIt.next())->notifyEvent( aEvent ); - } - catch( uno::RuntimeException& ) - { - aIt.remove(); - } - } + + document::EventObject aEvent( (frame::XModel*)this, aName ); + + pIC->forEach< document::XEventListener, NotifySingleListenerIgnoreRE< document::XEventListener, document::EventObject > >( + NotifySingleListenerIgnoreRE< document::XEventListener, document::EventObject >( + &document::XEventListener::notifyEvent, + aEvent ) ); } + } uno::Reference < container::XIndexAccess > SAL_CALL SfxBaseModel::getViewData() throw(::com::sun::star::uno::RuntimeException) @@ -3284,7 +3345,7 @@ uno::Reference< ui::XUIConfigurationManager > SAL_CALL SfxBaseModel::getUIConfig uno::Reference< lang::XMultiServiceFactory > xServiceMgr( ::comphelper::getProcessServiceFactory() ); uno::Sequence< uno::Reference< container::XIndexContainer > > rToolbars; - sal_Bool bImported = UIConfigurationImporterOOo1x::ImportCustomToolbars( + sal_Bool bImported = framework::UIConfigurationImporterOOo1x::ImportCustomToolbars( xNewUIConfMan, rToolbars, xServiceMgr, xOOo1ConfigStorage ); if ( bImported ) { |