summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
Diffstat (limited to 'vcl')
-rw-r--r--vcl/inc/vcl/lazydelete.hxx34
-rw-r--r--vcl/source/window/window.cxx13
2 files changed, 42 insertions, 5 deletions
diff --git a/vcl/inc/vcl/lazydelete.hxx b/vcl/inc/vcl/lazydelete.hxx
index 4176d5b4454f..ab39147d03de 100644
--- a/vcl/inc/vcl/lazydelete.hxx
+++ b/vcl/inc/vcl/lazydelete.hxx
@@ -39,6 +39,8 @@
#include <stdio.h>
#endif
+#include <com/sun/star/lang/XComponent.hpp>
+
namespace vcl
{
/* Helpers for lazy object deletion
@@ -256,6 +258,38 @@ namespace vcl
// ownership is transfered !
T* set( T* i_pNew ) { T* pOld = m_pT; m_pT = i_pNew; return pOld; }
};
+
+ /** Similar to DeleteOnDeinit, the DeleteUnoReferenceOnDeinit
+ template class makes sure that a static UNO object is disposed
+ and released at the right time.
+
+ Use like
+ static DeleteUnoReferenceOnDeinit<lang::XMultiServiceFactory>
+ xStaticFactory (<create factory object>);
+ Reference<lang::XMultiServiceFactory> xFactory (xStaticFactory.get());
+ if (xFactory.is())
+ <do something with xFactory>
+ */
+ template <typename I>
+ class DeleteUnoReferenceOnDeinit : public ::vcl::DeleteOnDeinitBase
+ {
+ ::com::sun::star::uno::Reference<I> m_xI;
+ virtual void doCleanup() { set(NULL); }
+ public:
+ DeleteUnoReferenceOnDeinit(const ::com::sun::star::uno::Reference<I>& r_xI ) : m_xI( r_xI ) {
+ addDeinitContainer( this ); }
+ virtual ~DeleteUnoReferenceOnDeinit() {}
+
+ ::com::sun::star::uno::Reference<I> get (void) { return m_xI; }
+
+ void set (const ::com::sun::star::uno::Reference<I>& r_xNew )
+ {
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent> xComponent (m_xI, UNO_QUERY);
+ m_xI.clear();
+ if (xComponent.is())
+ xComponent->dispose();
+ }
+ };
}
#endif
diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx
index 77da205131ea..a1941bc5a1f6 100644
--- a/vcl/source/window/window.cxx
+++ b/vcl/source/window/window.cxx
@@ -9702,11 +9702,14 @@ Reference< rendering::XCanvas > Window::ImplGetCanvas( const Size& rFullscreenSi
// =========================================
if ( xFactory.is() )
{
- static Reference<lang::XMultiServiceFactory> xCanvasFactory(
- xFactory->createInstance(
- OUString( RTL_CONSTASCII_USTRINGPARAM(
- "com.sun.star."
- "rendering.CanvasFactory") ) ), UNO_QUERY );
+ static ::vcl::DeleteUnoReferenceOnDeinit<XMultiServiceFactory> xStaticCanvasFactory(
+ Reference<XMultiServiceFactory>(
+ xFactory->createInstance(
+ OUString( RTL_CONSTASCII_USTRINGPARAM(
+ "com.sun.star.rendering.CanvasFactory") ) ),
+ UNO_QUERY ));
+ uno::Reference<XMultiServiceFactory> xCanvasFactory(xStaticCanvasFactory.get());
+
if(xCanvasFactory.is())
{
#ifdef WNT