diff options
author | Mikhail Voitenko <mav@openoffice.org> | 2003-03-12 14:38:00 +0000 |
---|---|---|
committer | Mikhail Voitenko <mav@openoffice.org> | 2003-03-12 14:38:00 +0000 |
commit | 8c0eb7d4b5072d3c69d3c6552e2ae92732d71558 (patch) | |
tree | 38770b41110e7e3c5e9df66b6d9a3482750297d8 /embedserv/source | |
parent | 4ed31202a053a7b41871c7ac246dd1cf4a3d7f49 (diff) |
#i2822# lock the document
Diffstat (limited to 'embedserv/source')
-rw-r--r-- | embedserv/source/embed/docholder.cxx | 145 | ||||
-rwxr-xr-x | embedserv/source/embed/ed_idataobj.cxx | 6 | ||||
-rwxr-xr-x | embedserv/source/embed/ed_ipersiststr.cxx | 62 | ||||
-rwxr-xr-x | embedserv/source/embed/makefile.mk | 6 | ||||
-rw-r--r-- | embedserv/source/inc/docholder.hxx | 100 | ||||
-rwxr-xr-x | embedserv/source/inc/embeddoc.hxx | 9 |
6 files changed, 280 insertions, 48 deletions
diff --git a/embedserv/source/embed/docholder.cxx b/embedserv/source/embed/docholder.cxx new file mode 100644 index 000000000000..8e91d4a1c631 --- /dev/null +++ b/embedserv/source/embed/docholder.cxx @@ -0,0 +1,145 @@ +/************************************************************************* + * + * $RCSfile: docholder.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: mav $ $Date: 2003-03-12 15:37:57 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include "docholder.hxx" + +#ifndef _COM_SUN_STAR_UTIL_XCLOSEBROADCASTER_HPP_ +#include <com/sun/star/util/XCloseBroadcaster.hpp> +#endif +#ifndef _COM_SUN_STAR_UTIL_XCLOSEABLE_HPP_ +#include <com/sun/star/util/XCloseAble.hpp> +#endif +#ifndef _COM_SUN_STAR_FRAME_XMODEL_HPP_ +#include <com/sun/star/frame/XModel.hpp> +#endif + + +using namespace ::com::sun::star; + +// add mutex locking ??? + +DocumentHolder::DocumentHolder() +{ +} + +DocumentHolder::~DocumentHolder() +{ + if ( m_xDocument.is() ) + CloseDocument(); +} + +void DocumentHolder::CloseDocument() +{ + uno::Reference< util::XCloseBroadcaster > xBroadcaster( m_xDocument, uno::UNO_QUERY ); + if ( xBroadcaster.is() ) + { + xBroadcaster->removeCloseListener( (util::XCloseListener*)this ); + + uno::Reference< util::XCloseable > xCloseable( xBroadcaster, uno::UNO_QUERY ); + if ( xCloseable.is() ) + { + try + { + xCloseable->close( sal_True ); + } + catch( uno::Exception& ) + {} + } + } + + m_xDocument = uno::Reference< frame::XModel >(); +} + +void DocumentHolder::SetDocument( const uno::Reference< frame::XModel >& xDoc ) +{ + if ( m_xDocument.is() ) + CloseDocument(); + + m_xDocument = xDoc; + uno::Reference< util::XCloseBroadcaster > xBroadcaster( m_xDocument, uno::UNO_QUERY ); + if ( xBroadcaster.is() ) + xBroadcaster->addCloseListener( (util::XCloseListener*)this ); +} + +void SAL_CALL DocumentHolder::disposing( const com::sun::star::lang::EventObject& aSource ) +{ + if ( m_xDocument.is() && m_xDocument == aSource.Source ) + m_xDocument = uno::Reference< frame::XModel >(); +} + +void SAL_CALL DocumentHolder::queryClosing( const lang::EventObject& aSource, sal_Bool bGetsOwnership ) + throw( util::CloseVetoException ) +{ + if ( m_xDocument.is() && m_xDocument == aSource.Source ) + throw util::CloseVetoException(); +} + +void SAL_CALL DocumentHolder::notifyClosing( const lang::EventObject& aSource ) +{ + uno::Reference< util::XCloseBroadcaster > xEventBroadcaster( aSource.Source, uno::UNO_QUERY ); + + if ( xEventBroadcaster.is() ) + xEventBroadcaster->removeCloseListener( (util::XCloseListener*)this ); + + if ( m_xDocument.is() && m_xDocument == aSource.Source ) + m_xDocument = uno::Reference< frame::XModel >(); +} + diff --git a/embedserv/source/embed/ed_idataobj.cxx b/embedserv/source/embed/ed_idataobj.cxx index 9944e7f9b672..3ed8ead5fadd 100755 --- a/embedserv/source/embed/ed_idataobj.cxx +++ b/embedserv/source/embed/ed_idataobj.cxx @@ -2,9 +2,9 @@ * * $RCSfile: ed_idataobj.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: mav $ $Date: 2003-03-10 16:08:37 $ + * last change: $Author: mav $ $Date: 2003-03-12 15:37:57 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -102,7 +102,7 @@ sal_uInt64 EmbedDocument_Impl::getMetaFileHandle_Impl( sal_Bool isEnhMeta ) { sal_uInt64 pResult = NULL; - uno::Reference< datatransfer::XTransferable > xTransferable( m_xDocument, uno::UNO_QUERY ); + uno::Reference< datatransfer::XTransferable > xTransferable( m_pDocHolder->GetDocument(), uno::UNO_QUERY ); if ( xTransferable.is() ) { uno::Sequence< sal_Int8 > aMetaBuffer; diff --git a/embedserv/source/embed/ed_ipersiststr.cxx b/embedserv/source/embed/ed_ipersiststr.cxx index e52eaeea64c3..6d63f89c633f 100755 --- a/embedserv/source/embed/ed_ipersiststr.cxx +++ b/embedserv/source/embed/ed_ipersiststr.cxx @@ -2,9 +2,9 @@ * * $RCSfile: ed_ipersiststr.cxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: mav $ $Date: 2003-03-11 13:03:46 $ + * last change: $Author: mav $ $Date: 2003-03-12 15:37:57 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -226,20 +226,14 @@ EmbedDocument_Impl::EmbedDocument_Impl( const uno::Reference< lang::XMultiServic , m_bIsDirty( sal_False ) , m_nAdviseNum( 0 ) { + m_pDocHolder = new DocumentHolder(); + m_pDocHolder->acquire(); } EmbedDocument_Impl::~EmbedDocument_Impl() { - if ( m_xDocument.is() ) - { - uno::Reference< lang::XComponent > xComponent( m_xDocument, uno::UNO_QUERY ); - - OSL_ENSURE( xComponent.is(), "Can not dispose created model!\n" ); - if ( xComponent.is() ) - xComponent->dispose(); - - m_xDocument = uno::Reference< frame::XModel >(); - } + m_pDocHolder->CloseDocument(); + m_pDocHolder->release(); } uno::Sequence< beans::PropertyValue > EmbedDocument_Impl::fillArgsForLoading_Impl( uno::Reference< io::XInputStream > xStream, DWORD nStreamMode ) @@ -372,7 +366,7 @@ STDMETHODIMP EmbedDocument_Impl::InitNew( IStorage *pStg ) { HRESULT hr = CO_E_ALREADYINITIALIZED; - if ( !m_xDocument.is() ) + if ( !m_pDocHolder->GetDocument().is() ) { STATSTG aStat; @@ -384,12 +378,14 @@ STDMETHODIMP EmbedDocument_Impl::InitNew( IStorage *pStg ) hr = E_FAIL; if ( m_xFactory.is() && pStg ) { - m_xDocument = uno::Reference< frame::XModel >( + uno::Reference< frame::XModel > aDocument( m_xFactory->createInstance( getServiceNameFromGUID_Impl( &m_guid ) ), uno::UNO_QUERY ); - if ( m_xDocument.is() ) + if ( aDocument.is() ) { - uno::Reference< frame::XLoadable > xLoadable( m_xDocument, uno::UNO_QUERY ); + m_pDocHolder->SetDocument( aDocument ); + + uno::Reference< frame::XLoadable > xLoadable( m_pDocHolder->GetDocument(), uno::UNO_QUERY ); if( xLoadable.is() ) { try @@ -432,15 +428,7 @@ STDMETHODIMP EmbedDocument_Impl::InitNew( IStorage *pStg ) } if ( hr != S_OK ) - { - uno::Reference< lang::XComponent > xComponent( m_xDocument, uno::UNO_QUERY ); - - OSL_ENSURE( xComponent.is(), "Can not dispose created model!\n" ); - if ( xComponent.is() ) - xComponent->dispose(); - - m_xDocument = uno::Reference< frame::XModel >(); - } + m_pDocHolder->CloseDocument(); } } } @@ -451,7 +439,7 @@ STDMETHODIMP EmbedDocument_Impl::InitNew( IStorage *pStg ) STDMETHODIMP EmbedDocument_Impl::Load( IStorage *pStg ) { - if ( m_xDocument.is() ) + if ( m_pDocHolder->GetDocument().is() ) return CO_E_ALREADYINITIALIZED; if ( !m_xFactory.is() || !pStg ) @@ -476,12 +464,14 @@ STDMETHODIMP EmbedDocument_Impl::Load( IStorage *pStg ) uno::Reference < io::XInputStream > xTempIn = createTempXInStreamFromIStream( m_xFactory, m_pOwnStream ); if ( xTempIn.is() ) { - m_xDocument = uno::Reference< frame::XModel >( + uno::Reference< frame::XModel > aDocument( m_xFactory->createInstance( getServiceNameFromGUID_Impl( &m_guid ) ), uno::UNO_QUERY ); - if ( m_xDocument.is() ) + if ( aDocument.is() ) { - uno::Reference< frame::XLoadable > xLoadable( m_xDocument, uno::UNO_QUERY ); + m_pDocHolder->SetDocument( aDocument ); + + uno::Reference< frame::XLoadable > xLoadable( m_pDocHolder->GetDocument(), uno::UNO_QUERY ); if( xLoadable.is() ) { try @@ -496,15 +486,7 @@ STDMETHODIMP EmbedDocument_Impl::Load( IStorage *pStg ) } if ( FAILED( hr ) ) - { - uno::Reference< lang::XComponent > xComponent( m_xDocument, uno::UNO_QUERY ); - - OSL_ENSURE( xComponent.is(), "Can not dispose created model!\n" ); - if ( xComponent.is() ) - xComponent->dispose(); - - m_xDocument = uno::Reference< frame::XModel >(); - } + m_pDocHolder->CloseDocument(); } } @@ -523,7 +505,7 @@ STDMETHODIMP EmbedDocument_Impl::Load( IStorage *pStg ) STDMETHODIMP EmbedDocument_Impl::Save( IStorage *pStgSave, BOOL fSameAsLoad ) { - if ( !m_xDocument.is() || !m_xFactory.is() || !pStgSave || !m_pOwnStream ) + if ( !m_pDocHolder->GetDocument().is() || !m_xFactory.is() || !pStgSave || !m_pOwnStream ) return E_FAIL; CComPtr< IStream > pTargetStream; @@ -558,7 +540,7 @@ STDMETHODIMP EmbedDocument_Impl::Save( IStorage *pStgSave, BOOL fSameAsLoad ) if ( xTempOut.is() ) { - uno::Reference< frame::XStorable > xStorable( m_xDocument, uno::UNO_QUERY ); + uno::Reference< frame::XStorable > xStorable( m_pDocHolder->GetDocument(), uno::UNO_QUERY ); if( xStorable.is() ) { try diff --git a/embedserv/source/embed/makefile.mk b/embedserv/source/embed/makefile.mk index 399ae29027b4..d0bff12f72dd 100755 --- a/embedserv/source/embed/makefile.mk +++ b/embedserv/source/embed/makefile.mk @@ -2,9 +2,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.1 $ +# $Revision: 1.2 $ # -# last change: $Author: mav $ $Date: 2003-03-05 15:50:09 $ +# last change: $Author: mav $ $Date: 2003-03-12 15:37:58 $ # # The Contents of this file are made available subject to the terms of # either of the following licenses @@ -83,6 +83,7 @@ INCPRE+= $(SOLARINCDIR)$/external$/atl SLOFILES = \ $(SLO)$/register.obj \ $(SLO)$/servprov.obj \ + $(SLO)$/docholder.obj \ $(SLO)$/ed_ipersiststr.obj \ $(SLO)$/ed_idataobj.obj \ $(SLO)$/ed_ioleobject.obj \ @@ -91,6 +92,7 @@ SLOFILES = \ EXCEPTIONSFILES= \ $(SLO)$/register.obj \ + $(SLO)$/docholder.obj \ $(SLO)$/ed_ipersiststr.obj \ $(SLO)$/ed_idataobj.obj diff --git a/embedserv/source/inc/docholder.hxx b/embedserv/source/inc/docholder.hxx new file mode 100644 index 000000000000..c1efb278a093 --- /dev/null +++ b/embedserv/source/inc/docholder.hxx @@ -0,0 +1,100 @@ +/************************************************************************* + * + * $RCSfile: docholder.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: mav $ $Date: 2003-03-12 15:37:59 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _DOCHOLDER_HXX_ +#define _DOCHOLDER_HXX_ + +#include "common.h" + +#ifndef _COM_SUN_STAR_UTIL_XCLOSELISTENER_HPP_ +#include <com/sun/star/util/XCloseListener.hpp> +#endif +#ifndef _CPPUHELPER_IMPLBASE1_HXX_ +#include <cppuhelper/implbase1.hxx> +#endif + +class DocumentHolder : public ::cppu::WeakImplHelper1< ::com::sun::star::util::XCloseListener > +{ + ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > m_xDocument; + +public: + + DocumentHolder(); + ~DocumentHolder(); + + void SetDocument( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& xDoc ); + void CloseDocument(); + + ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > GetDocument() { return m_xDocument; } + +// XEventListener + virtual void SAL_CALL disposing( const com::sun::star::lang::EventObject& aSource ); + +// XCloseListener + virtual void SAL_CALL queryClosing( const com::sun::star::lang::EventObject& aSource, sal_Bool bGetsOwnership ) + throw( ::com::sun::star::util::CloseVetoException ); + + virtual void SAL_CALL notifyClosing( const com::sun::star::lang::EventObject& aSource ); + +}; + +#endif + diff --git a/embedserv/source/inc/embeddoc.hxx b/embedserv/source/inc/embeddoc.hxx index dea017aff9a6..d80ee0ffc7c9 100755 --- a/embedserv/source/inc/embeddoc.hxx +++ b/embedserv/source/inc/embeddoc.hxx @@ -2,9 +2,9 @@ * * $RCSfile: embeddoc.hxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: mav $ $Date: 2003-03-10 16:04:11 $ + * last change: $Author: mav $ $Date: 2003-03-12 15:38:00 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -74,6 +74,8 @@ #include <com/sun/star/uno/SEQUENCE.h> #endif +#include "docholder.hxx" + typedef ::std::hash_map< DWORD, IAdviseSink* > AdviseSinkHashMap; typedef ::std::hash_map< DWORD, IAdviseSink* >::iterator AdviseSinkHashMapIterator; @@ -153,7 +155,8 @@ protected: oslInterlockedCount m_refCount; ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xFactory; - ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > m_xDocument; + + DocumentHolder* m_pDocHolder; CComPtr< IStorage > m_pMasterStorage; CComPtr< IStream > m_pOwnStream; |