summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@collabora.com>2015-03-14 22:16:11 +0000
committerMichael Meeks <michael.meeks@collabora.com>2015-04-10 11:03:10 +0100
commitbc139dde60a25a7ccb60446c7cb8475ab794bfdc (patch)
treef1107a965bc332f73d23e5fb650cb3e3421e0117
parent06f4760e3451601b3f43a72c4f1c5c4233c3f61a (diff)
vclptr: move down impl. to OutputDevice
Ultimately we will want to ref-count & VclPtr OutputDevice instances separately from Window - but for now merge. This helps fix the amazing lifecycle foo in toolkit/ Change-Id: If40ee9f645c87aff08815926205e908205bdd67a
-rw-r--r--include/vcl/outdev.hxx30
-rw-r--r--include/vcl/window.hxx19
-rw-r--r--vcl/source/outdev/outdev.cxx19
-rw-r--r--vcl/source/window/window.cxx17
4 files changed, 51 insertions, 34 deletions
diff --git a/include/vcl/outdev.hxx b/include/vcl/outdev.hxx
index 4cf24545c928..e53fc65a982e 100644
--- a/include/vcl/outdev.hxx
+++ b/include/vcl/outdev.hxx
@@ -263,6 +263,26 @@ class VCL_DLLPUBLIC OutputDevice
friend class vcl::PDFWriterImpl;
friend void ImplHandleResize( vcl::Window* pWindow, long nNewWidth, long nNewHeight );
+ // All of this will need to be replicated in Window
+ // or a shared base-class as/when we can break the
+ // OutputDevice -> Window inheritance.
+private:
+ mutable int mnRefCnt; // reference count
+
+ template<typename T> friend class ::rtl::Reference;
+ template<typename T> friend class ::VclPtr;
+
+ inline void acquire() const
+ {
+ mnRefCnt++;
+ }
+
+ inline void release() const
+ {
+ if (!--mnRefCnt)
+ delete const_cast<OutputDevice*>(this);
+ }
+
private:
OutputDevice(const OutputDevice&) SAL_DELETED_FUNCTION;
OutputDevice& operator=(const OutputDevice&) SAL_DELETED_FUNCTION;
@@ -352,6 +372,7 @@ private:
mutable bool mbTextSpecial : 1;
mutable bool mbRefPoint : 1;
mutable bool mbEnableRTL : 1;
+ mutable bool mbDisposed : 1;
/** @name Initialization and accessor functions
*/
@@ -359,10 +380,17 @@ private:
protected:
OutputDevice();
-
public:
virtual ~OutputDevice();
+protected:
+ /// release all references to other objects.
+ virtual void dispose();
+
+public:
+ /// call the dispose() method if we have not already been disposed.
+ void disposeOnce();
+
public:
/** Get the graphic context that the output device uses to draw on.
diff --git a/include/vcl/window.hxx b/include/vcl/window.hxx
index 8744c29cfa32..663d7dddf5d0 100644
--- a/include/vcl/window.hxx
+++ b/include/vcl/window.hxx
@@ -420,8 +420,6 @@ private:
// OutputDevice
::OutputDevice* mpOutputDevice;
- mutable int mnRefCnt; // reference count
-
#ifdef DBG_UTIL
friend const char* ::ImplDbgCheckWindow( const void* pObj );
#endif
@@ -500,27 +498,10 @@ public:
SAL_DLLPRIVATE static void ImplCalcSymbolRect( Rectangle& rRect );
-private:
- template<typename T> friend class ::rtl::Reference;
- template<typename T> friend class ::VclPtr;
-
- inline void acquire() const
- {
- mnRefCnt++;
- }
-
- inline void release() const
- {
- if (!--mnRefCnt)
- delete this;
- }
-
protected:
/** This is intended to be used to clear any locally held references to other Window-subclass objects */
virtual void dispose();
- /* call the dispose() method if we have not already been disposed */
- void disposeOnce();
SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle, SystemParentData* pSystemParentData );
diff --git a/vcl/source/outdev/outdev.cxx b/vcl/source/outdev/outdev.cxx
index 372eb23bc8f4..5d59ee104029 100644
--- a/vcl/source/outdev/outdev.cxx
+++ b/vcl/source/outdev/outdev.cxx
@@ -183,7 +183,26 @@ OutputDevice::OutputDevice() :
OutputDevice::~OutputDevice()
{
+ disposeOnce();
+}
+
+void OutputDevice::disposeOnce()
+{
+ if ( mbDisposed )
+ return;
+ mbDisposed = true;
+ // catch badness where our OutputDevice sub-class was not
+ // wrapped safely in a VclPtr cosily.
+ assert( mnRefCnt > 0 );
+
+ // hold a ref in case something unusual happens during dispose.
+ VclPtr<OutputDevice> aRef(this);
+ dispose();
+}
+
+void OutputDevice::dispose()
+{
if ( GetUnoGraphicsList() )
{
UnoWrapperBase* pWrapper = Application::GetUnoWrapper( false );
diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx
index d2177e44ce34..31f537c285d3 100644
--- a/vcl/source/window/window.cxx
+++ b/vcl/source/window/window.cxx
@@ -137,23 +137,10 @@ bool Window::IsDisposed() const
return !mpWindowImpl;
}
-void Window::disposeOnce()
+void Window::dispose()
{
- if (!mpWindowImpl || mpWindowImpl->mbInDispose)
- return;
mpWindowImpl->mbInDispose = true;
- // catch badness where our Window was not wrapped safely
- // in a VclPtr cosily.
- assert( mnRefCnt>0 );
-
- // hold a ref in case something silly happens during dispose.
- VclPtr<Window> aRef(this);
- dispose();
-}
-
-void Window::dispose()
-{
assert( mpWindowImpl && mpWindowImpl->mbInDispose ); // should only be called from disposeOnce()
assert( !mpWindowImpl->mpParent ||
!mpWindowImpl->mpParent->IsDisposed() ||
@@ -585,6 +572,8 @@ void Window::dispose()
// should be the last statements
delete mpWindowImpl; mpWindowImpl = NULL;
+
+ OutputDevice::dispose();
}
Window::~Window()