Kaydet (Commit) bc139dde authored tarafından Michael Meeks's avatar Michael Meeks

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
üst 06f4760e
......@@ -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.
......
......@@ -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 );
......
......@@ -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 );
......
......@@ -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()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment