summaryrefslogtreecommitdiff
path: root/embeddedobj
diff options
context:
space:
mode:
authorMikhail Voitenko <mav@openoffice.org>2003-11-18 11:47:08 +0000
committerMikhail Voitenko <mav@openoffice.org>2003-11-18 11:47:08 +0000
commit036f1b99e149626d017cdb337e80791ec06904c6 (patch)
tree0665dc26c0202bac039f00ee70b66f0481845b88 /embeddedobj
parent17fe2299375ad4bfa271703378769a2f9a7edd5e (diff)
#112923# use close(false) when possible
Diffstat (limited to 'embeddedobj')
-rw-r--r--embeddedobj/source/commonembedding/embedobj.cxx6
-rw-r--r--embeddedobj/source/commonembedding/miscobj.cxx98
-rw-r--r--embeddedobj/source/general/docholder.cxx63
-rw-r--r--embeddedobj/source/inc/commonembobj.hxx10
-rw-r--r--embeddedobj/source/inc/docholder.hxx10
5 files changed, 115 insertions, 72 deletions
diff --git a/embeddedobj/source/commonembedding/embedobj.cxx b/embeddedobj/source/commonembedding/embedobj.cxx
index 107693b94992..0882a28ed936 100644
--- a/embeddedobj/source/commonembedding/embedobj.cxx
+++ b/embeddedobj/source/commonembedding/embedobj.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: embedobj.cxx,v $
*
- * $Revision: 1.3 $
+ * $Revision: 1.4 $
*
- * last change: $Author: mav $ $Date: 2003-11-14 15:33:20 $
+ * last change: $Author: mav $ $Date: 2003-11-18 12:47:05 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -156,7 +156,7 @@ void OCommonEmbeddedObject::SwitchStateTo_Impl( sal_Int32 nNextState )
if ( nNextState == embed::EmbedStates::EMBED_LOADED )
{
// actually frame should not exist at this point
- m_pDocHolder->CloseDocument();
+ m_pDocHolder->CloseDocument( sal_False, sal_False );
m_nObjectState = nNextState;
}
diff --git a/embeddedobj/source/commonembedding/miscobj.cxx b/embeddedobj/source/commonembedding/miscobj.cxx
index e801706048a0..15f9b0edad48 100644
--- a/embeddedobj/source/commonembedding/miscobj.cxx
+++ b/embeddedobj/source/commonembedding/miscobj.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: miscobj.cxx,v $
*
- * $Revision: 1.4 $
+ * $Revision: 1.5 $
*
- * last change: $Author: mav $ $Date: 2003-11-18 09:03:53 $
+ * last change: $Author: mav $ $Date: 2003-11-18 12:47:06 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -95,6 +95,7 @@ OCommonEmbeddedObject::OCommonEmbeddedObject( const uno::Reference< lang::XMulti
, m_pInterfaceContainer( NULL )
, m_bReadOnly( sal_False )
, m_bDisposed( sal_False )
+, m_bClosed( sal_False )
, m_nObjectState( -1 )
, m_nUpdateMode ( embed::EmbedUpdateModes::EMBED_ALWAYS_UPDATE )
, m_xFactory( xFactory )
@@ -121,6 +122,7 @@ OCommonEmbeddedObject::OCommonEmbeddedObject(
, m_pInterfaceContainer( NULL )
, m_bReadOnly( sal_False )
, m_bDisposed( sal_False )
+, m_bClosed( sal_False )
, m_nObjectState( embed::EmbedStates::EMBED_LOADED )
, m_nUpdateMode ( embed::EmbedUpdateModes::EMBED_ALWAYS_UPDATE )
, m_xFactory( xFactory )
@@ -185,37 +187,33 @@ OCommonEmbeddedObject::~OCommonEmbeddedObject()
{
m_refCount++;
try {
- Dispose();
- } catch( uno::Exception& ) {}
- }
-}
-
-//------------------------------------------------------
-void OCommonEmbeddedObject::Dispose()
-{
- if ( m_pInterfaceContainer )
- {
- lang::EventObject aEvent( (embed::XEmbeddedObject*)this );
- m_pInterfaceContainer->disposeAndClear( aEvent );
+ lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >( this ) );
- delete m_pInterfaceContainer;
- m_pInterfaceContainer = NULL;
- }
+ if ( m_pInterfaceContainer )
+ {
+ m_pInterfaceContainer->disposeAndClear( aSource );
- if ( m_pDocHolder )
- {
- m_pDocHolder->CloseFrame();
- m_pDocHolder->CloseDocument();
- m_pDocHolder->FreeOffice();
+ delete m_pInterfaceContainer;
+ m_pInterfaceContainer = NULL;
+ }
+ } catch( uno::Exception& ) {}
- m_pDocHolder->release();
- m_pDocHolder = NULL;
+ try {
+ if ( m_pDocHolder )
+ {
+ m_pDocHolder->CloseFrame();
+ try {
+ m_pDocHolder->CloseDocument( sal_True, sal_True );
+ } catch ( uno::Exception& ) {}
+ m_pDocHolder->FreeOffice();
+
+ m_pDocHolder->release();
+ m_pDocHolder = NULL;
+ }
+ } catch( uno::Exception& ) {}
}
-
- m_bDisposed = true;
}
-
//------------------------------------------------------
void OCommonEmbeddedObject::PostEvent_Impl( const ::rtl::OUString& aEventName )
{
@@ -388,7 +386,7 @@ void SAL_CALL OCommonEmbeddedObject::close( sal_Bool bDeliverOwnership )
uno::RuntimeException )
{
::osl::MutexGuard aGuard( m_aMutex );
- if ( m_bDisposed )
+ if ( m_bClosed )
throw lang::DisposedException(); // TODO
uno::Reference< uno::XInterface > xSelfHold( static_cast< ::cppu::OWeakObject* >( this ) );
@@ -431,9 +429,45 @@ void SAL_CALL OCommonEmbeddedObject::close( sal_Bool bDeliverOwnership )
}
}
}
+
+ m_pInterfaceContainer->disposeAndClear( aSource );
+
+ delete m_pInterfaceContainer;
+ m_pInterfaceContainer = NULL;
+ }
+
+ m_bDisposed = sal_True; // the object is disposed now for outside
+
+ // it is possible that the document can not be closed, in this case if the argument is false
+ // the exception will be thrown otherwise in addition to exception the object must register itself
+ // as termination listener and listen for document events
+
+ if ( m_pDocHolder )
+ {
+ m_pDocHolder->CloseFrame();
+
+ try {
+ m_pDocHolder->CloseDocument( bDeliverOwnership, bDeliverOwnership );
+ }
+ catch( uno::Exception& )
+ {
+ if ( bDeliverOwnership )
+ {
+ m_pDocHolder->release();
+ m_pDocHolder = NULL;
+ m_bClosed = sal_True;
+ }
+
+ throw;
+ }
+
+ m_pDocHolder->FreeOffice();
+
+ m_pDocHolder->release();
+ m_pDocHolder = NULL;
}
- Dispose();
+ m_bClosed = sal_True; // the closing succeeded
}
//----------------------------------------------
@@ -455,9 +489,6 @@ void SAL_CALL OCommonEmbeddedObject::removeCloseListener( const uno::Reference<
throw (uno::RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
- if ( m_bDisposed )
- throw lang::DisposedException(); // TODO
-
if ( m_pInterfaceContainer )
m_pInterfaceContainer->removeInterface( ::getCppuType( (const uno::Reference< util::XCloseListener >*)0 ),
xListener );
@@ -482,9 +513,6 @@ void SAL_CALL OCommonEmbeddedObject::removeEventListener( const uno::Reference<
throw ( uno::RuntimeException )
{
::osl::MutexGuard aGuard( m_aMutex );
- if ( m_bDisposed )
- throw lang::DisposedException(); // TODO
-
if ( m_pInterfaceContainer )
m_pInterfaceContainer->removeInterface( ::getCppuType( (const uno::Reference< document::XEventListener >*)0 ),
xListener );
diff --git a/embeddedobj/source/general/docholder.cxx b/embeddedobj/source/general/docholder.cxx
index 7481a117e97b..a56398565a86 100644
--- a/embeddedobj/source/general/docholder.cxx
+++ b/embeddedobj/source/general/docholder.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: docholder.cxx,v $
*
- * $Revision: 1.3 $
+ * $Revision: 1.4 $
*
- * last change: $Author: mav $ $Date: 2003-10-29 08:14:39 $
+ * last change: $Author: mav $ $Date: 2003-11-18 12:47:07 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -131,7 +131,8 @@ DocumentHolder::DocumentHolder( const uno::Reference< lang::XMultiServiceFactory
: m_xFactory( xFactory ),
m_pEmbedObj( pEmbObj ),
m_pInterceptor( NULL ),
- m_bReadOnly( sal_False )
+ m_bReadOnly( sal_False ),
+ m_bWaitForClose( sal_False )
{
const ::rtl::OUString aServiceName ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.frame.Desktop" ) );
uno::Reference< frame::XDesktop > xDesktop( m_xFactory->createInstance( aServiceName ), uno::UNO_QUERY );
@@ -145,16 +146,19 @@ DocumentHolder::~DocumentHolder()
CloseFrame();
if ( m_xDocument.is() )
- CloseDocument();
-
- if ( m_xFactory.is() )
- FreeOffice();
+ {
+ try {
+ CloseDocument( sal_True, sal_False );
+ } catch( uno::Exception& ) {}
+ }
if ( m_pInterceptor )
{
m_pInterceptor->DisconnectDocHolder();
m_pInterceptor->release();
}
+
+ FreeOffice();
}
void DocumentHolder::CloseFrame()
@@ -202,18 +206,14 @@ void DocumentHolder::FreeOffice()
{}
}
}
-
- m_xFactory = uno::Reference< lang::XMultiServiceFactory >();
}
}
-void DocumentHolder::CloseDocument()
+void DocumentHolder::CloseDocument( sal_Bool bDeliverOwnership, sal_Bool bWaitForClose )
{
uno::Reference< util::XCloseBroadcaster > xBroadcaster( m_xDocument, uno::UNO_QUERY );
if ( xBroadcaster.is() )
{
- xBroadcaster->removeCloseListener( ( util::XCloseListener* )this );
-
uno::Reference< document::XEventBroadcaster > xEventBroadcaster( m_xDocument, uno::UNO_QUERY );
if ( xEventBroadcaster.is() )
xEventBroadcaster->removeEventListener( ( document::XEventListener* )this );
@@ -221,12 +221,8 @@ void DocumentHolder::CloseDocument()
uno::Reference< util::XCloseable > xCloseable( xBroadcaster, uno::UNO_QUERY );
if ( xCloseable.is() )
{
- try
- {
- xCloseable->close( sal_True );
- }
- catch( uno::Exception& )
- {}
+ m_bWaitForClose = bWaitForClose;
+ xCloseable->close( bDeliverOwnership );
}
}
@@ -276,7 +272,13 @@ uno::Reference< frame::XFrame > DocumentHolder::GetDocFrame()
void DocumentHolder::SetDocument( const uno::Reference< frame::XModel >& xDoc, sal_Bool bReadOnly )
{
if ( m_xDocument.is() )
- CloseDocument();
+ {
+ // May be should be improved
+ try {
+ CloseDocument( sal_True, sal_False );
+ } catch( uno::Exception& )
+ {}
+ }
m_xDocument = xDoc;
m_bReadOnly = bReadOnly;
@@ -522,7 +524,14 @@ void SAL_CALL DocumentHolder::disposing( const com::sun::star::lang::EventObject
throw (::com::sun::star::uno::RuntimeException)
{
if ( m_xDocument.is() && m_xDocument == aSource.Source )
+ {
m_xDocument = uno::Reference< frame::XModel >();
+ if ( m_bWaitForClose )
+ {
+ m_bWaitForClose = sal_False;
+ FreeOffice();
+ }
+ }
if( m_xFrame.is() && m_xFrame == aSource.Source )
m_xFrame = uno::Reference< frame::XFrame >();
@@ -532,20 +541,22 @@ void SAL_CALL DocumentHolder::disposing( const com::sun::star::lang::EventObject
void SAL_CALL DocumentHolder::queryClosing( const lang::EventObject& aSource, sal_Bool bGetsOwnership )
throw (::com::sun::star::util::CloseVetoException, ::com::sun::star::uno::RuntimeException)
{
- if ( m_xDocument.is() && m_xDocument == aSource.Source )
+ if ( m_xDocument.is() && m_xDocument == aSource.Source && m_bWaitForClose )
throw util::CloseVetoException();
}
void SAL_CALL DocumentHolder::notifyClosing( const lang::EventObject& aSource )
throw (::com::sun::star::uno::RuntimeException)
{
- 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 >();
+ if ( m_bWaitForClose )
+ {
+ m_bWaitForClose = sal_False;
+ FreeOffice();
+ }
+ }
if( m_xFrame.is() && m_xFrame == aSource.Source )
m_xFrame = uno::Reference< frame::XFrame >();
@@ -554,7 +565,7 @@ void SAL_CALL DocumentHolder::notifyClosing( const lang::EventObject& aSource )
void SAL_CALL DocumentHolder::queryTermination( const lang::EventObject& aSource )
throw (::com::sun::star::frame::TerminationVetoException, ::com::sun::star::uno::RuntimeException)
{
- if ( m_xDocument.is() )
+ if ( m_bWaitForClose )
throw frame::TerminationVetoException();
}
diff --git a/embeddedobj/source/inc/commonembobj.hxx b/embeddedobj/source/inc/commonembobj.hxx
index bc79aae30482..671d6d98a83a 100644
--- a/embeddedobj/source/inc/commonembobj.hxx
+++ b/embeddedobj/source/inc/commonembobj.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: commonembobj.hxx,v $
*
- * $Revision: 1.5 $
+ * $Revision: 1.6 $
*
- * last change: $Author: mav $ $Date: 2003-11-18 09:03:53 $
+ * last change: $Author: mav $ $Date: 2003-11-18 12:47:08 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -148,7 +148,9 @@ class OCommonEmbeddedObject : public ::com::sun::star::embed::XEmbeddedObject
sal_Bool m_bReadOnly;
- sal_Int32 m_bDisposed;
+ sal_Bool m_bDisposed;
+ sal_Bool m_bClosed;
+
sal_Int32 m_nObjectState;
sal_Int32 m_nUpdateMode;
@@ -189,8 +191,6 @@ class OCommonEmbeddedObject : public ::com::sun::star::embed::XEmbeddedObject
private:
void CommonInit_Impl();
- void Dispose();
-
::rtl::OUString GetDocumentServiceName() { return m_aDocServiceName; }
::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > StoreDocumentToTempStream_Impl();
diff --git a/embeddedobj/source/inc/docholder.hxx b/embeddedobj/source/inc/docholder.hxx
index 3d419fd7b392..2cc5862c08dc 100644
--- a/embeddedobj/source/inc/docholder.hxx
+++ b/embeddedobj/source/inc/docholder.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: docholder.hxx,v $
*
- * $Revision: 1.2 $
+ * $Revision: 1.3 $
*
- * last change: $Author: mav $ $Date: 2003-10-28 16:32:49 $
+ * last change: $Author: mav $ $Date: 2003-11-18 12:47:08 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -114,6 +114,8 @@ private:
sal_Bool m_bReadOnly;
+ sal_Bool m_bWaitForClose;
+
::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > GetDocFrame();
void LoadDocToFrame();
@@ -127,8 +129,10 @@ public:
void SetDocument( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& xDoc, sal_Bool bReadOnly );
+ void LockOffice();
void FreeOffice();
- void CloseDocument();
+
+ void CloseDocument( sal_Bool bDeliverOwnership, sal_Bool bWaitForClose );
void CloseFrame();
void SetTitle(const rtl::OUString& aDocumentName);