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

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
üst d1091fd5
......@@ -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
......
......@@ -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();
......
......@@ -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
......
......@@ -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 );
......
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