diff options
author | Xisco Fauli <anistenis@gmail.com> | 2016-06-15 19:34:52 +0200 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2016-06-16 06:53:57 +0000 |
commit | 2d2ef979c2feb8cd70a1dbc3f47cf7f86a5d39ea (patch) | |
tree | 93b4cdea56bd00cd677cea05485f922620e00098 /svtools | |
parent | dad8d71f4a73b64e534c1977e09e54905b8e27e8 (diff) |
tdf#89329: use shared_ptr for pImpl in menuoptions
Change-Id: I93ece349dc15ea9af00c661ac34fed80a57ea3d2
Reviewed-on: https://gerrit.libreoffice.org/26318
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'svtools')
-rw-r--r-- | svtools/source/config/menuoptions.cxx | 64 |
1 files changed, 11 insertions, 53 deletions
diff --git a/svtools/source/config/menuoptions.cxx b/svtools/source/config/menuoptions.cxx index fc64447642a2..be735a618ec2 100644 --- a/svtools/source/config/menuoptions.cxx +++ b/svtools/source/config/menuoptions.cxx @@ -17,7 +17,6 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ - #include <svtools/menuoptions.hxx> #include <unotools/configmgr.hxx> #include <unotools/configitem.hxx> @@ -31,10 +30,8 @@ #include <list> - // namespaces - using namespace ::utl ; using namespace ::osl ; using namespace ::com::sun::star::uno ; @@ -58,37 +55,29 @@ using namespace ::com::sun::star::uno ; #include <tools/link.hxx> - // private declarations! - class SvtMenuOptions_Impl : public ConfigItem { // private member - private: bool m_bDontHideDisabledEntries ; /// cache "DontHideDisabledEntries" of Menu section bool m_bFollowMouse ; /// cache "FollowMouse" of Menu section TriState m_eMenuIcons ; /// cache "MenuIcons" of Menu section - // public methods - public: - // constructor / destructor - SvtMenuOptions_Impl(); virtual ~SvtMenuOptions_Impl(); // override methods of baseclass - /*-**************************************************************************************************** @short called for notify of configmanager @descr These method is called from the ConfigManager before application ends or from the @@ -104,7 +93,6 @@ class SvtMenuOptions_Impl : public ConfigItem // public interface - /*-**************************************************************************************************** @short access method to get internal values @descr These methods give us a chance to regulate access to our internal values. @@ -124,10 +112,8 @@ class SvtMenuOptions_Impl : public ConfigItem // tdf#93451: don't Commit() here, it's too early } - // private methods - private: virtual void ImplCommit() override; @@ -142,7 +128,6 @@ class SvtMenuOptions_Impl : public ConfigItem static Sequence< OUString > impl_GetPropertyNames(); }; - // constructor SvtMenuOptions_Impl::SvtMenuOptions_Impl() @@ -215,7 +200,6 @@ SvtMenuOptions_Impl::SvtMenuOptions_Impl() EnableNotification( seqNames ); } - // destructor SvtMenuOptions_Impl::~SvtMenuOptions_Impl() @@ -223,7 +207,6 @@ SvtMenuOptions_Impl::~SvtMenuOptions_Impl() assert(!IsModified()); // should have been committed } - // public method void SvtMenuOptions_Impl::Notify( const Sequence< OUString >& seqPropertyNames ) @@ -276,7 +259,6 @@ void SvtMenuOptions_Impl::Notify( const Sequence< OUString >& seqPropertyNames ) m_eMenuIcons = bSystemMenuIcons ? TRISTATE_INDET : static_cast<TriState>(bMenuIcons); } - // public method void SvtMenuOptions_Impl::ImplCommit() @@ -315,7 +297,6 @@ void SvtMenuOptions_Impl::ImplCommit() PutProperties( seqNames, seqValues ); } - // private method Sequence< OUString > SvtMenuOptions_Impl::impl_GetPropertyNames() @@ -334,77 +315,54 @@ Sequence< OUString > SvtMenuOptions_Impl::impl_GetPropertyNames() return seqPropertyNames; } -// initialize static member -// DON'T DO IT IN YOUR HEADER! -// see definition for further information - -SvtMenuOptions_Impl* SvtMenuOptions::m_pDataContainer = nullptr ; -sal_Int32 SvtMenuOptions::m_nRefCount = 0 ; - - -// constructor +std::weak_ptr<SvtMenuOptions_Impl> m_pMenuOptions; SvtMenuOptions::SvtMenuOptions() { // Global access, must be guarded (multithreading!). MutexGuard aGuard( GetOwnStaticMutex() ); - // Increase our refcount ... - ++m_nRefCount; - // ... and initialize our data container only if it not already! - if( m_pDataContainer == nullptr ) - { - m_pDataContainer = new SvtMenuOptions_Impl(); + m_pImpl = m_pMenuOptions.lock(); + if( !m_pImpl ) + { + m_pImpl = std::make_shared<SvtMenuOptions_Impl>(); + m_pMenuOptions = m_pImpl; svtools::ItemHolder2::holdConfigItem(E_MENUOPTIONS); } } - -// destructor - SvtMenuOptions::~SvtMenuOptions() { // Global access, must be guarded (multithreading!) MutexGuard aGuard( GetOwnStaticMutex() ); - // Decrease our refcount. - --m_nRefCount; - // If last instance was deleted ... - // we must destroy our static data container! - if( m_nRefCount <= 0 ) - { - delete m_pDataContainer; - m_pDataContainer = nullptr; - } -} + m_pImpl.reset(); +} // public method bool SvtMenuOptions::IsEntryHidingEnabled() const { MutexGuard aGuard( GetOwnStaticMutex() ); - return m_pDataContainer->IsEntryHidingEnabled(); + return m_pImpl->IsEntryHidingEnabled(); } - // public method TriState SvtMenuOptions::GetMenuIconsState() const { MutexGuard aGuard( GetOwnStaticMutex() ); - return m_pDataContainer->GetMenuIconsState(); + return m_pImpl->GetMenuIconsState(); } - // public method void SvtMenuOptions::SetMenuIconsState(TriState eState) { MutexGuard aGuard( GetOwnStaticMutex() ); - m_pDataContainer->SetMenuIconsState(eState); + m_pImpl->SetMenuIconsState(eState); } - // private method Mutex& SvtMenuOptions::GetOwnStaticMutex() |