diff options
author | Noel Grandin <noel@peralex.com> | 2014-12-04 13:50:21 +0200 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2015-04-09 19:48:04 +0100 |
commit | b72c6feba87bd8707f39902a3066ba476188cb1d (patch) | |
tree | 94791632f79f14214ec7518d18a35ab822676178 /include | |
parent | d6398719abecfca60db37637490e602222992dc2 (diff) |
manage VCL widgets using rtl::Reference
Change-Id: Ie95790cbaa5d459c8e849d7333098d857d31ed0a
Diffstat (limited to 'include')
-rw-r--r-- | include/vcl/button.hxx | 12 | ||||
-rw-r--r-- | include/vcl/fixed.hxx | 4 | ||||
-rw-r--r-- | include/vcl/group.hxx | 2 | ||||
-rw-r--r-- | include/vcl/imgctrl.hxx | 2 | ||||
-rw-r--r-- | include/vcl/layout.hxx | 4 | ||||
-rw-r--r-- | include/vcl/lstbox.hxx | 1 | ||||
-rw-r--r-- | include/vcl/menubtn.hxx | 2 | ||||
-rw-r--r-- | include/vcl/scrbar.hxx | 2 | ||||
-rw-r--r-- | include/vcl/vclref.hxx | 87 | ||||
-rw-r--r-- | include/vcl/window.hxx | 5 |
10 files changed, 115 insertions, 6 deletions
diff --git a/include/vcl/button.hxx b/include/vcl/button.hxx index 1a100c0f83dd..8cc6fe2d14b5 100644 --- a/include/vcl/button.hxx +++ b/include/vcl/button.hxx @@ -28,7 +28,7 @@ #include <vcl/bitmap.hxx> #include <vcl/salnativewidgets.hxx> #include <rsc/rsc-vcl-shared-types.hxx> - +#include <vcl/vclref.hxx> #include <vector> class UserDrawEvent; @@ -200,6 +200,8 @@ public: virtual bool set_property(const OString &rKey, const OString &rValue) SAL_OVERRIDE; }; +typedef VclReference<PushButton> PushButtonPtr; + inline void PushButton::Check( bool bCheck ) { SetState( (bCheck) ? TRISTATE_TRUE : TRISTATE_FALSE ); @@ -226,6 +228,7 @@ public: virtual void Click() SAL_OVERRIDE; }; +typedef VclReference<OKButton> OKButtonPtr; class VCL_DLLPUBLIC CancelButton : public PushButton { @@ -243,6 +246,8 @@ public: virtual void Click() SAL_OVERRIDE; }; +typedef VclReference<CancelButton> CancelButtonPtr; + class VCL_DLLPUBLIC CloseButton : public CancelButton { public: @@ -270,6 +275,7 @@ public: virtual void Click() SAL_OVERRIDE; }; +typedef VclReference<HelpButton> HelpButtonPtr; // - RadioButton - class VCL_DLLPUBLIC RadioButton : public Button @@ -493,6 +499,8 @@ public: virtual bool set_property(const OString &rKey, const OString &rValue) SAL_OVERRIDE; }; +typedef VclReference<CheckBox> CheckBoxPtr; + inline void CheckBox::Check( bool bCheck ) { SetState( (bCheck) ? TRISTATE_TRUE : TRISTATE_FALSE ); @@ -553,7 +561,7 @@ public: virtual void KeyInput( const KeyEvent& rKEvt ) SAL_OVERRIDE; }; -typedef rtl::Reference<DisclosureButton> DisclosureButtonPtr; +typedef VclReference<DisclosureButton> DisclosureButtonPtr; #endif // INCLUDED_VCL_BUTTON_HXX diff --git a/include/vcl/fixed.hxx b/include/vcl/fixed.hxx index 109cecfe812d..30bbd95eea70 100644 --- a/include/vcl/fixed.hxx +++ b/include/vcl/fixed.hxx @@ -82,6 +82,8 @@ public: vcl::Window* get_mnemonic_widget() const { return m_pMnemonicWindow; } }; +typedef VclReference<FixedText> FixedTextPtr; + class VCL_DLLPUBLIC SelectableFixedText : public Edit { public: @@ -124,6 +126,8 @@ public: virtual Size GetOptimalSize() const SAL_OVERRIDE; }; +typedef VclReference<FixedLine> FixedLinePtr; + // - FixedBitmap - class VCL_DLLPUBLIC FixedBitmap : public Control { diff --git a/include/vcl/group.hxx b/include/vcl/group.hxx index 9e7b933fe228..3d6c2a47462a 100644 --- a/include/vcl/group.hxx +++ b/include/vcl/group.hxx @@ -55,6 +55,8 @@ public: virtual void DataChanged( const DataChangedEvent& rDCEvt ) SAL_OVERRIDE; }; +typedef VclReference<GroupBox> GroupBoxPtr; + #endif // INCLUDED_VCL_GROUP_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/imgctrl.hxx b/include/vcl/imgctrl.hxx index 753ad9f126d2..8ec454a2a690 100644 --- a/include/vcl/imgctrl.hxx +++ b/include/vcl/imgctrl.hxx @@ -51,6 +51,8 @@ protected: void ImplDraw( OutputDevice& rDev, sal_uLong nDrawFlags, const Point& rPos, const Size& rSize ) const; }; +typedef VclReference<ImageControl> ImageControlPtr; + #endif // INCLUDED_VCL_IMGCTRL_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/layout.hxx b/include/vcl/layout.hxx index 24ad21732d4c..e2893de2fef5 100644 --- a/include/vcl/layout.hxx +++ b/include/vcl/layout.hxx @@ -544,7 +544,7 @@ 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(); } + void dispose() SAL_OVERRIDE { m_pDisclosureButton.disposeAndClear(); VclBin::dispose(); } private: bool m_bResizeTopLevel; DisclosureButtonPtr m_pDisclosureButton; @@ -571,7 +571,7 @@ 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(); } + void dispose() SAL_OVERRIDE { m_pVScroll.disposeAndClear(); m_pHScroll.disposeAndClear(); VclBin::dispose(); } private: bool m_bUserManagedScrolling; ScrollBarPtr m_pVScroll; diff --git a/include/vcl/lstbox.hxx b/include/vcl/lstbox.hxx index 29d219920844..3e53ab997918 100644 --- a/include/vcl/lstbox.hxx +++ b/include/vcl/lstbox.hxx @@ -239,6 +239,7 @@ public: void EnableQuickSelection( const bool& b ); }; +typedef VclReference<ListBox> ListBoxPtr; // - MultiListBox - diff --git a/include/vcl/menubtn.hxx b/include/vcl/menubtn.hxx index 41e03c6462f9..9159a6d8033e 100644 --- a/include/vcl/menubtn.hxx +++ b/include/vcl/menubtn.hxx @@ -82,6 +82,8 @@ public: const Link& GetSelectHdl() const { return maSelectHdl; } }; +typedef VclReference<MenuButton> MenuButtonPtr; + #endif // INCLUDED_VCL_MENUBTN_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/scrbar.hxx b/include/vcl/scrbar.hxx index da949dfdf8d2..6255db3b78c8 100644 --- a/include/vcl/scrbar.hxx +++ b/include/vcl/scrbar.hxx @@ -141,7 +141,7 @@ public: virtual Size GetOptimalSize() const SAL_OVERRIDE; }; -typedef rtl::Reference<ScrollBar> ScrollBarPtr; +typedef VclReference<ScrollBar> ScrollBarPtr; // - ScrollBarBox - diff --git a/include/vcl/vclref.hxx b/include/vcl/vclref.hxx new file mode 100644 index 000000000000..ddbff3e8fdea --- /dev/null +++ b/include/vcl/vclref.hxx @@ -0,0 +1,87 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_VCL_REFERENCE_HXX +#define INCLUDED_VCL_REFERENCE_HXX + +#include <rtl/ref.hxx> + +/** + * A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for references to vcl::Window subclasses. + * @param reference_type must be a subclass of vcl::Window + */ +template <class reference_type> +class VclReference +{ + + ::rtl::Reference<reference_type> m_rInnerRef; + +public: + /** Constructor... + */ + inline VclReference() + : m_rInnerRef() + {} + + + /** Constructor... + */ + inline VclReference (reference_type * pBody) + : m_rInnerRef(pBody) + {} + + + /** Copy constructor... + */ + inline VclReference (const VclReference<reference_type> & handle) + : m_rInnerRef (handle) + {} + + + /** Get the body. Can be used instead of operator->(). + I.e. handle->someBodyOp() and handle.get()->someBodyOp() + are the same. + */ + inline reference_type * SAL_CALL get() const + { + return m_rInnerRef.get(); + } + + /** Probably most common used: handle->someBodyOp(). + */ + inline reference_type * SAL_CALL operator->() const + { + return m_rInnerRef.get(); + } + + inline void disposeAndClear() + { + // hold it alive for the lifetime of this method + ::rtl::Reference<reference_type> aTmp(m_rInnerRef); + m_rInnerRef.clear(); // we should use some 'swap' method ideally ;-) + assert(aTmp.get()); + if (aTmp.get()) + aTmp->dispose(); + } + +}; // class VclReference + +#endif // INCLUDED_VCL_REFERENCE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/window.hxx b/include/vcl/window.hxx index bc20cbe7550b..189f15b231df 100644 --- a/include/vcl/window.hxx +++ b/include/vcl/window.hxx @@ -119,6 +119,8 @@ namespace vcl { namespace svt { class PopupWindowControllerImpl; } +template<class T> class VclReference; + // - WindowTypes - @@ -497,6 +499,7 @@ public: private: template<typename T> friend class ::rtl::Reference; + template<typename T> friend class ::VclReference; inline void acquire() const { @@ -512,7 +515,7 @@ private: protected: /** This is intended to be used to clear any locally held references to other Window-subclass objects */ - virtual void dispose() {} + virtual void dispose(); SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle, SystemParentData* pSystemParentData ); |