[Libreoffice-commits] core.git: Branch 'feature/vclref' - include/vcl vcl/source
Michael Meeks
michael.meeks at collabora.com
Sat Mar 14 15:11:57 PDT 2015
include/vcl/outdev.hxx | 30 +++++++++++++++++++++++++++++-
include/vcl/window.hxx | 19 -------------------
vcl/source/outdev/outdev.cxx | 19 +++++++++++++++++++
vcl/source/window/window.cxx | 17 +++--------------
4 files changed, 51 insertions(+), 34 deletions(-)
New commits:
commit a66896819678367f4e13c08a14b74cddccd13097
Author: Michael Meeks <michael.meeks at collabora.com>
Date: Sat Mar 14 22:16:11 2015 +0000
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
diff --git a/include/vcl/outdev.hxx b/include/vcl/outdev.hxx
index 23abb00..c94b76f 100644
--- a/include/vcl/outdev.hxx
+++ b/include/vcl/outdev.hxx
@@ -259,6 +259,26 @@ class VCL_DLLPUBLIC OutputDevice: private boost::noncopyable
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:
mutable SalGraphics* mpGraphics; ///< Graphics context to draw on
mutable OutputDevice* mpPrevGraphics; ///< Previous output device in list
@@ -345,6 +365,7 @@ private:
mutable bool mbTextSpecial : 1;
mutable bool mbRefPoint : 1;
mutable bool mbEnableRTL : 1;
+ mutable bool mbDisposed : 1;
/** @name Initialization and accessor functions
*/
@@ -352,10 +373,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 67ebe60..5f0be55 100644
--- a/include/vcl/window.hxx
+++ b/include/vcl/window.hxx
@@ -405,8 +405,6 @@ private:
// OutputDevice
::OutputDevice* mpOutputDevice;
- mutable int mnRefCnt; // reference count
-
#ifdef DBG_UTIL
friend const char* ::ImplDbgCheckWindow( const void* pObj );
#endif
@@ -485,27 +483,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 const_cast<Window*>(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 82b80c3..7436b10 100644
--- a/vcl/source/outdev/outdev.cxx
+++ b/vcl/source/outdev/outdev.cxx
@@ -181,7 +181,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 423dd0e..3b6f3e7 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()
More information about the Libreoffice-commits
mailing list