[Libreoffice-commits] core.git: Branch 'feature/vclref' - include/vcl svtools/source vcl/README.lifecycle vcl/source
Michael Meeks
michael.meeks at collabora.com
Fri Mar 20 10:56:05 PDT 2015
include/vcl/vclptr.hxx | 22 ++++++++++++++++------
svtools/source/control/tabbar.cxx | 5 +++++
vcl/README.lifecycle | 8 ++++++++
vcl/source/window/window.cxx | 3 +--
4 files changed, 30 insertions(+), 8 deletions(-)
New commits:
commit f750d9e12501ad0929cf2f5eab645780e94a54c4
Author: Michael Meeks <michael.meeks at collabora.com>
Date: Fri Mar 20 17:24:08 2015 +0000
ScopedVclPtr: needs an = operator to make life flow.
Without this, assigning to a ScopedVclPtr instance thus:
pScopedVclPtr = new Foo();
constructed a new intermediate ScopedVCLPtr, used a default assignment
operator, unhelpfully disposing the new Foo before it could make it to
pScopedVclPtr => add operator, and hide problematic constructors.
Change-Id: Icc0da962938bf115eac0c24a6a76cfeb66ddf23a
diff --git a/include/vcl/vclptr.hxx b/include/vcl/vclptr.hxx
index c75d421..3e0de76 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 d8bf0b6..1425273 100644
--- a/svtools/source/control/tabbar.cxx
+++ b/svtools/source/control/tabbar.cxx
@@ -153,6 +153,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;
@@ -172,6 +173,10 @@ ImplTabSizer::ImplTabSizer( TabBar* pParent, WinBits nWinStyle )
SetSizePixel(Size(7 * nScaleFactor, 0));
}
+void ImplTabSizer::dispose()
+{
+ vcl::Window::dispose();
+}
void ImplTabSizer::ImplTrack( const Point& rScreenPos )
diff --git a/vcl/README.lifecycle b/vcl/README.lifecycle
index 201e212..1ee7eab 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 d1d2acb..510482f 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 );
More information about the Libreoffice-commits
mailing list