diff options
-rw-r--r-- | connectivity/source/drivers/calc/CConnection.cxx | 10 | ||||
-rw-r--r-- | connectivity/source/inc/calc/CConnection.hxx | 10 | ||||
-rw-r--r-- | include/unotools/closeveto.hxx | 3 | ||||
-rw-r--r-- | unotools/source/misc/closeveto.cxx | 14 |
4 files changed, 25 insertions, 12 deletions
diff --git a/connectivity/source/drivers/calc/CConnection.cxx b/connectivity/source/drivers/calc/CConnection.cxx index eb94e10ef6d8..71a3c9748ffa 100644 --- a/connectivity/source/drivers/calc/CConnection.cxx +++ b/connectivity/source/drivers/calc/CConnection.cxx @@ -31,6 +31,7 @@ #include "calc/CPreparedStatement.hxx" #include "calc/CStatement.hxx" #include <unotools/pathoptions.hxx> +#include <unotools/closeveto.hxx> #include <connectivity/dbexception.hxx> #include <cppuhelper/exc_hlp.hxx> #include <comphelper/processfactory.hxx> @@ -165,13 +166,17 @@ Reference< XSpreadsheetDocument> OCalcConnection::acquireDoc() ::dbtools::throwGenericSQLException( sError, *this, aErrorDetails ); } osl_atomic_increment(&m_nDocCount); + m_pCloseListener.reset(new utl::CloseVeto(m_xDoc, true)); return m_xDoc; } void OCalcConnection::releaseDoc() { if ( osl_atomic_decrement(&m_nDocCount) == 0 ) - ::comphelper::disposeComponent( m_xDoc ); + { + m_pCloseListener.reset(); // dispose m_xDoc + m_xDoc.clear(); + } } void OCalcConnection::disposing() @@ -179,7 +184,8 @@ void OCalcConnection::disposing() ::osl::MutexGuard aGuard(m_aMutex); m_nDocCount = 0; - ::comphelper::disposeComponent( m_xDoc ); + m_pCloseListener.reset(); // dispose m_xDoc + m_xDoc.clear(); OConnection::disposing(); } diff --git a/connectivity/source/inc/calc/CConnection.hxx b/connectivity/source/inc/calc/CConnection.hxx index cda44ef9ccee..0171ac4b0098 100644 --- a/connectivity/source/inc/calc/CConnection.hxx +++ b/connectivity/source/inc/calc/CConnection.hxx @@ -23,9 +23,11 @@ #include "file/FConnection.hxx" #include <com/sun/star/uno/DeploymentException.hpp> -namespace com { namespace sun { namespace star { namespace sheet { - class XSpreadsheetDocument; -} } } } +namespace com { namespace sun { namespace star { + namespace sheet { class XSpreadsheetDocument; } +} } } + +namespace utl { class CloseVeto; } namespace connectivity @@ -37,6 +39,8 @@ namespace connectivity { // the spreadsheet document: ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheetDocument > m_xDoc; + /// close listener that vetoes so nobody disposes m_xDoc + ::std::unique_ptr< ::utl::CloseVeto> m_pCloseListener; OUString m_sPassword; OUString m_aFileName; oslInterlockedCount m_nDocCount; diff --git a/include/unotools/closeveto.hxx b/include/unotools/closeveto.hxx index 1079c3597341..fe5521618a71 100644 --- a/include/unotools/closeveto.hxx +++ b/include/unotools/closeveto.hxx @@ -38,7 +38,8 @@ namespace utl class UNOTOOLS_DLLPUBLIC CloseVeto { public: - CloseVeto( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& i_closeable ); + CloseVeto( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& i_closeable, + bool bHasOwnership = false); ~CloseVeto(); private: diff --git a/unotools/source/misc/closeveto.cxx b/unotools/source/misc/closeveto.cxx index 290a18cb715f..b33ef2902df9 100644 --- a/unotools/source/misc/closeveto.cxx +++ b/unotools/source/misc/closeveto.cxx @@ -51,8 +51,8 @@ namespace utl class CloseListener_Impl : public CloseListener_Base { public: - CloseListener_Impl() - :m_bHasOwnership( false ) + CloseListener_Impl(bool const bHasOwnership) + : m_bHasOwnership(bHasOwnership) { } @@ -107,12 +107,13 @@ namespace utl namespace { - void lcl_init( CloseVeto_Data& i_data, const Reference< XInterface >& i_closeable ) + void lcl_init( CloseVeto_Data& i_data, const Reference< XInterface >& i_closeable, + bool const hasOwnership) { i_data.xCloseable.set( i_closeable, UNO_QUERY ); ENSURE_OR_RETURN_VOID( i_data.xCloseable.is(), "CloseVeto: the component is not closeable!" ); - i_data.pListener = new CloseListener_Impl; + i_data.pListener = new CloseListener_Impl(hasOwnership); i_data.xCloseable->addCloseListener( i_data.pListener.get() ); } @@ -138,10 +139,11 @@ namespace utl } //= CloseVeto - CloseVeto::CloseVeto( const Reference< XInterface >& i_closeable ) + CloseVeto::CloseVeto(const Reference< XInterface >& i_closeable, + bool const hasOwnership) : m_xData(new CloseVeto_Data) { - lcl_init(*m_xData, i_closeable); + lcl_init(*m_xData, i_closeable, hasOwnership); } CloseVeto::~CloseVeto() |