summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2014-10-27 14:02:38 +0200
committerNoel Grandin <noel@peralex.com>2014-10-29 09:36:17 +0200
commitbacee60a5920585feeff58840357aa7ac33e50a7 (patch)
tree75da30b17723f95d35e47e4794dd6c3537833fc1 /include
parent7344923ffdf751646396b38af6a23be93b53a06a (diff)
ref-counting vcl::Window subclasses
Points of discussion -------------------- (*) where in the Window destructor should dispose() be called? It's a seriously large method. (*) we're going to need similar typedefs and declarations for every single sub-class of vcl::Window, I assume that I will need to create a macro to make it less verbose. TODO ---- Update clang plugin to verify that: (a) dispose() methods always call their superclass dispose() (b) dispose() methods don't forget to clear any references owned by that class. Change-Id: I873d5d5166f811e2f65e49327cc98862559fcf30
Diffstat (limited to 'include')
-rw-r--r--include/svtools/valueset.hxx3
-rw-r--r--include/vcl/button.hxx2
-rw-r--r--include/vcl/layout.hxx26
-rw-r--r--include/vcl/scrbar.hxx2
-rw-r--r--include/vcl/window.hxx20
5 files changed, 39 insertions, 14 deletions
diff --git a/include/svtools/valueset.hxx b/include/svtools/valueset.hxx
index e82a4b4ce353..4ddc64db36e4 100644
--- a/include/svtools/valueset.hxx
+++ b/include/svtools/valueset.hxx
@@ -177,7 +177,6 @@ to be set (before Show) with SetStyle().
*************************************************************************/
typedef std::vector<ValueSetItem*> ValueItemList;
-typedef boost::scoped_ptr<ScrollBar> ScrollBarPtr;
typedef boost::scoped_ptr<ValueSetItem> ValueSetItemPtr;
// - ValueSet types -
@@ -202,7 +201,7 @@ private:
Timer maTimer;
ValueItemList mItemList;
ValueSetItemPtr mpNoneItem;
- ScrollBarPtr mpScrollBar;
+ boost::scoped_ptr<ScrollBar> mpScrollBar;
Rectangle maNoneItemRect;
Rectangle maItemListRect;
long mnItemWidth;
diff --git a/include/vcl/button.hxx b/include/vcl/button.hxx
index 6c9384cdd5c5..9f5142aebf3a 100644
--- a/include/vcl/button.hxx
+++ b/include/vcl/button.hxx
@@ -566,6 +566,8 @@ public:
virtual void KeyInput( const KeyEvent& rKEvt ) SAL_OVERRIDE;
};
+typedef rtl::Reference<DisclosureButton> DisclosureButtonPtr;
+
#endif // INCLUDED_VCL_BUTTON_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/vcl/layout.hxx b/include/vcl/layout.hxx
index 0eed7cb6f723..88f1887750a8 100644
--- a/include/vcl/layout.hxx
+++ b/include/vcl/layout.hxx
@@ -513,29 +513,29 @@ public:
VclExpander(vcl::Window *pParent)
: VclBin(pParent)
, m_bResizeTopLevel(true)
- , m_aDisclosureButton(this)
+ , m_pDisclosureButton(new DisclosureButton(this))
{
- m_aDisclosureButton.SetToggleHdl(LINK(this, VclExpander, ClickHdl));
- m_aDisclosureButton.Show();
+ m_pDisclosureButton->SetToggleHdl(LINK(this, VclExpander, ClickHdl));
+ m_pDisclosureButton->Show();
}
virtual vcl::Window *get_child() SAL_OVERRIDE;
virtual const vcl::Window *get_child() const SAL_OVERRIDE;
virtual bool set_property(const OString &rKey, const OString &rValue) SAL_OVERRIDE;
bool get_expanded() const
{
- return m_aDisclosureButton.IsChecked();
+ return m_pDisclosureButton->IsChecked();
}
void set_expanded(bool bExpanded)
{
- m_aDisclosureButton.Check(bExpanded);
+ m_pDisclosureButton->Check(bExpanded);
}
void set_label(const OUString& rLabel)
{
- m_aDisclosureButton.SetText(rLabel);
+ m_pDisclosureButton->SetText(rLabel);
}
OUString get_label() const
{
- return m_aDisclosureButton.GetText();
+ return m_pDisclosureButton->GetText();
}
virtual void StateChanged(StateChangedType nType) SAL_OVERRIDE;
void SetExpandedHdl( const Link& rLink ) { maExpandedHdl = rLink; }
@@ -543,9 +543,10 @@ public:
protected:
virtual Size calculateRequisition() const SAL_OVERRIDE;
virtual void setAllocation(const Size &rAllocation) SAL_OVERRIDE;
+ void dispose() SAL_OVERRIDE { m_pDisclosureButton.clear(); VclBin::dispose(); }
private:
bool m_bResizeTopLevel;
- DisclosureButton m_aDisclosureButton;
+ DisclosureButtonPtr m_pDisclosureButton;
Link maExpandedHdl;
DECL_DLLPRIVATE_LINK(ClickHdl, DisclosureButton* pBtn);
};
@@ -557,8 +558,8 @@ public:
virtual vcl::Window *get_child() SAL_OVERRIDE;
virtual const vcl::Window *get_child() const SAL_OVERRIDE;
virtual bool set_property(const OString &rKey, const OString &rValue) SAL_OVERRIDE;
- ScrollBar& getVertScrollBar() { return m_aVScroll; }
- ScrollBar& getHorzScrollBar() { return m_aHScroll; }
+ ScrollBar& getVertScrollBar() { return *m_pVScroll.get(); }
+ ScrollBar& getHorzScrollBar() { return *m_pHScroll.get(); }
Size getVisibleChildSize() const;
//set to true to disable the built-in scrolling callbacks to allow the user
//to override it
@@ -569,10 +570,11 @@ protected:
DECL_LINK(ScrollBarHdl, void *);
void InitScrollBars(const Size &rRequest);
virtual bool Notify(NotifyEvent& rNEvt) SAL_OVERRIDE;
+ void dispose() SAL_OVERRIDE { m_pVScroll.clear(); m_pHScroll.clear(); VclBin::dispose(); }
private:
bool m_bUserManagedScrolling;
- ScrollBar m_aVScroll;
- ScrollBar m_aHScroll;
+ ScrollBarPtr m_pVScroll;
+ ScrollBarPtr m_pHScroll;
ScrollBarBox m_aScrollBarBox;
};
diff --git a/include/vcl/scrbar.hxx b/include/vcl/scrbar.hxx
index 65bbca0dc2fe..db0a673842d7 100644
--- a/include/vcl/scrbar.hxx
+++ b/include/vcl/scrbar.hxx
@@ -141,6 +141,8 @@ public:
virtual Size GetOptimalSize() const SAL_OVERRIDE;
};
+typedef rtl::Reference<ScrollBar> ScrollBarPtr;
+
// - ScrollBarBox -
diff --git a/include/vcl/window.hxx b/include/vcl/window.hxx
index 44ab2c0b5ae9..ec51588f16d1 100644
--- a/include/vcl/window.hxx
+++ b/include/vcl/window.hxx
@@ -36,6 +36,7 @@
#include <vcl/region.hxx>
#include <vcl/salnativewidgets.hxx>
#include <rtl/ustring.hxx>
+#include <rtl/ref.hxx>
#include <cppuhelper/weakref.hxx>
#include <com/sun/star/uno/Reference.hxx>
#include <boost/shared_ptr.hpp>
@@ -399,6 +400,8 @@ private:
// OutputDevice
::OutputDevice* mpOutputDevice;
+ mutable int mnRefCnt; // reference count
+
#ifdef DBG_UTIL
friend const char* ::ImplDbgCheckWindow( const void* pObj );
#endif
@@ -478,8 +481,25 @@ public:
SAL_DLLPRIVATE static void ImplCalcSymbolRect( Rectangle& rRect );
+private:
+ template<typename T> friend class ::rtl::Reference;
+
+ 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() {}
+
SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle, SystemParentData* pSystemParentData );
SAL_DLLPRIVATE Point ImplOutputToFrame( const Point& rPos );