diff options
-rw-r--r-- | include/unotools/fontoptions.hxx | 24 | ||||
-rw-r--r-- | unotools/source/config/fontoptions.cxx | 39 |
2 files changed, 13 insertions, 50 deletions
diff --git a/include/unotools/fontoptions.hxx b/include/unotools/fontoptions.hxx index 51e349fdc159..82e98d06505a 100644 --- a/include/unotools/fontoptions.hxx +++ b/include/unotools/fontoptions.hxx @@ -24,6 +24,7 @@ #include <osl/mutex.hxx> #include <rtl/ustring.hxx> #include <unotools/options.hxx> +#include <memory> /*-************************************************************************************************************ @short forward declaration to our private date container implementation @@ -42,17 +43,6 @@ class SvtFontOptions_Impl; class SAL_WARN_UNUSED UNOTOOLS_DLLPUBLIC SvtFontOptions : public utl::detail::Options { public: - /*-**************************************************************************************************** - @short standard constructor and destructor - @descr This will initialize an instance with default values. - We implement these class with a refcount mechanism! Every instance of this class increase it - at create and decrease it at delete time - but all instances use the same data container! - He is implemented as a static member ... - - @seealso member m_nRefCount - @seealso member m_pDataContainer - *//*-*****************************************************************************************************/ - SvtFontOptions(); virtual ~SvtFontOptions(); @@ -87,17 +77,7 @@ class SAL_WARN_UNUSED UNOTOOLS_DLLPUBLIC SvtFontOptions : public utl::detail::Op UNOTOOLS_DLLPRIVATE static ::osl::Mutex& impl_GetOwnStaticMutex(); private: - - /*Attention - - Don't initialize these static members in these headers! - a) Double defined symbols will be detected ... - b) and unresolved externals exist at linking time. - Do it in your source only. - */ - - static SvtFontOptions_Impl* m_pDataContainer; - static sal_Int32 m_nRefCount; + std::shared_ptr<SvtFontOptions_Impl> m_pImpl; }; // class SvtFontOptions diff --git a/unotools/source/config/fontoptions.cxx b/unotools/source/config/fontoptions.cxx index 9214987a4506..4aa7732e7135 100644 --- a/unotools/source/config/fontoptions.cxx +++ b/unotools/source/config/fontoptions.cxx @@ -243,45 +243,28 @@ Sequence< OUString > SvtFontOptions_Impl::impl_GetPropertyNames() return seqPropertyNames; } -// initialize static member -// DON'T DO IT IN YOUR HEADER! -// see definition for further information - -SvtFontOptions_Impl* SvtFontOptions::m_pDataContainer = nullptr; -sal_Int32 SvtFontOptions::m_nRefCount = 0; - -// constructor +std::weak_ptr<SvtFontOptions_Impl> m_pFontOptions; SvtFontOptions::SvtFontOptions() { // Global access, must be guarded (multithreading!). MutexGuard aGuard( impl_GetOwnStaticMutex() ); - // Increase our refcount ... - ++m_nRefCount; - // ... and initialize our data container only if it not already exist! - if( m_pDataContainer == nullptr ) - { - m_pDataContainer = new SvtFontOptions_Impl; + m_pImpl = m_pFontOptions.lock(); + if( !m_pImpl ) + { + m_pImpl = std::make_shared<SvtFontOptions_Impl>(); + m_pFontOptions = m_pImpl; ItemHolder1::holdConfigItem(E_FONTOPTIONS); } } -// destructor - SvtFontOptions::~SvtFontOptions() { // Global access, must be guarded (multithreading!) MutexGuard aGuard( impl_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 @@ -289,7 +272,7 @@ SvtFontOptions::~SvtFontOptions() bool SvtFontOptions::IsFontHistoryEnabled() const { MutexGuard aGuard( impl_GetOwnStaticMutex() ); - return m_pDataContainer->IsFontHistoryEnabled(); + return m_pImpl->IsFontHistoryEnabled(); } // public method @@ -297,7 +280,7 @@ bool SvtFontOptions::IsFontHistoryEnabled() const bool SvtFontOptions::IsFontWYSIWYGEnabled() const { MutexGuard aGuard( impl_GetOwnStaticMutex() ); - return m_pDataContainer->IsFontWYSIWYGEnabled(); + return m_pImpl->IsFontWYSIWYGEnabled(); } // public method @@ -305,7 +288,7 @@ bool SvtFontOptions::IsFontWYSIWYGEnabled() const void SvtFontOptions::EnableFontWYSIWYG( bool bState ) { MutexGuard aGuard( impl_GetOwnStaticMutex() ); - m_pDataContainer->EnableFontWYSIWYG( bState ); + m_pImpl->EnableFontWYSIWYG( bState ); } namespace |