diff options
-rw-r--r-- | include/vcl/vclptr.hxx | 22 | ||||
-rw-r--r-- | svtools/source/control/tabbar.cxx | 6 | ||||
-rw-r--r-- | vcl/README.lifecycle | 8 | ||||
-rw-r--r-- | vcl/source/window/window.cxx | 3 |
4 files changed, 31 insertions, 8 deletions
diff --git a/include/vcl/vclptr.hxx b/include/vcl/vclptr.hxx index c75d421583c7..3e0de767dc95 100644 --- a/include/vcl/vclptr.hxx +++ b/include/vcl/vclptr.hxx @@ -81,7 +81,6 @@ namespace vcl { class Window; } template <class reference_type> class VclPtr { - ::rtl::Reference<reference_type> m_rInnerRef; public: @@ -211,7 +210,6 @@ public: return (m_rInnerRef < handle.m_rInnerRef); } - /** Needed to place VclPtr's into STL collection. */ inline bool SAL_CALL operator> (const VclPtr<reference_type> & handle) const @@ -231,20 +229,28 @@ public: : VclPtr<reference_type>() {} - - /** Constructor... + /** Constructor */ inline ScopedVclPtr (reference_type * pBody) : VclPtr<reference_type>(pBody) {} - /** Copy constructor... */ inline ScopedVclPtr (const VclPtr<reference_type> & handle) : VclPtr<reference_type>(handle) {} + /** + Assignment that releases the last reference. + */ + inline ScopedVclPtr<reference_type>& SAL_CALL operator= (reference_type * pBody) + { + VclPtr<reference_type>::disposeAndClear(); + VclPtr<reference_type>::set(pBody); + return *this; + } + /** Up-casting conversion constructor: Copies interface reference. Does not work for up-casts to ambiguous bases. For the special case of @@ -265,7 +271,11 @@ public: { VclPtr<reference_type>::disposeAndClear(); } - +private: + // Most likely we don't want this default copy-construtor. + ScopedVclPtr (const ScopedVclPtr<reference_type> &) SAL_DELETED_FUNCTION; + // And certainly we don't want a default assignment operator. + ScopedVclPtr<reference_type>& SAL_CALL operator= (const ScopedVclPtr<reference_type> &) SAL_DELETED_FUNCTION; }; #endif // INCLUDED_VCL_PTR_HXX diff --git a/svtools/source/control/tabbar.cxx b/svtools/source/control/tabbar.cxx index 9ff0df667646..4a65042a34d5 100644 --- a/svtools/source/control/tabbar.cxx +++ b/svtools/source/control/tabbar.cxx @@ -159,6 +159,7 @@ public: private: void ImplTrack( const Point& rScreenPos ); + virtual void dispose() SAL_OVERRIDE; virtual void MouseButtonDown( const MouseEvent& rMEvt ) SAL_OVERRIDE; virtual void Tracking( const TrackingEvent& rTEvt ) SAL_OVERRIDE; virtual void Paint( const Rectangle& rRect ) SAL_OVERRIDE; @@ -176,6 +177,11 @@ ImplTabSizer::ImplTabSizer( TabBar* pParent, WinBits nWinStyle ) SetSizePixel(Size(7 * nScaleFactor, 0)); } +void ImplTabSizer::dispose() +{ + vcl::Window::dispose(); +} + void ImplTabSizer::ImplTrack( const Point& rScreenPos ) { TabBar* pParent = GetParent(); diff --git a/vcl/README.lifecycle b/vcl/README.lifecycle index 201e212a9c77..1ee7eab7ea6b 100644 --- a/vcl/README.lifecycle +++ b/vcl/README.lifecycle @@ -67,6 +67,14 @@ to lingering pointers to freed objects. 'dispose' methods, in order to provide a minimal initial behavioral change. + As such a VclPtr can have three states: + + VclPtr<PushButton> pButton; + ... + assert (pButton == nullptr || !pButton); // null + assert (pButton && !pButton->IsDisposed()); // alive + assert (pButton && pButton->IsDisposed()); // disposed + ** ScopedVclPtr - making disposes easier While replacing existing code with new, it can be a bit diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx index 2af94700afce..b04bad14da0f 100644 --- a/vcl/source/window/window.cxx +++ b/vcl/source/window/window.cxx @@ -2264,8 +2264,7 @@ vcl::Font Window::GetPointFont() const void Window::Show( bool bVisible, sal_uInt16 nFlags ) { - - if ( mpWindowImpl->mbVisible == bVisible ) + if ( IsDisposed() || mpWindowImpl->mbVisible == bVisible ) return; ImplDelData aDogTag( this ); |