diff options
author | Bjoern Michaelsen <bjoern.michaelsen@canonical.com> | 2017-03-09 03:20:19 +0100 |
---|---|---|
committer | Björn Michaelsen <bjoern.michaelsen@canonical.com> | 2017-03-10 13:00:49 +0000 |
commit | c54bb4a9f76a11561a7f4010382dbe46c0d2ef2a (patch) | |
tree | 2339cfad20a154da33d49bc55b148e99ce8096b6 /editeng | |
parent | 1a044b25c279236d9f67847ec6ad426d8c5aac13 (diff) |
tdf#99352: create editeng::SharedVclRessources
- instead of keeping vcl resources in a rtl::Static
- these are shared owned by all EditEngines
- they let go of them when disposed
- thus, this should prevent VclPtrs to leak beyond dispose()
Change-Id: Ic6198c19d0ff9c09ecdea377d07807f08711d6a0
Reviewed-on: https://gerrit.libreoffice.org/34986
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Björn Michaelsen <bjoern.michaelsen@canonical.com>
Diffstat (limited to 'editeng')
-rw-r--r-- | editeng/source/editeng/eerdll.cxx | 34 | ||||
-rw-r--r-- | editeng/source/editeng/eerdll2.hxx | 16 | ||||
-rw-r--r-- | editeng/source/editeng/impedit.hxx | 2 | ||||
-rw-r--r-- | editeng/source/editeng/impedit2.cxx | 4 |
4 files changed, 42 insertions, 14 deletions
diff --git a/editeng/source/editeng/eerdll.cxx b/editeng/source/editeng/eerdll.cxx index 09b990930d82..a73d7eb3d7b0 100644 --- a/editeng/source/editeng/eerdll.cxx +++ b/editeng/source/editeng/eerdll.cxx @@ -85,11 +85,8 @@ EditDLL& EditDLL::Get() } GlobalEditData::GlobalEditData() : - ppDefItems(nullptr), - mpVirDev(VclPtr<VirtualDevice>::Create()) -{ - mpVirDev->SetMapMode(MapUnit::MapTwip); -} + ppDefItems(nullptr) +{ } GlobalEditData::~GlobalEditData() { @@ -197,11 +194,6 @@ uno::Reference< linguistic2::XLanguageGuessing > const & GlobalEditData::GetLang return xLanguageGuesser; } -VclPtr<VirtualDevice> GlobalEditData::GetStdVirtualDevice() -{ - return mpVirDev; -} - EditResId::EditResId(sal_uInt16 nId) : ResId(nId, *EditDLL::GetResMgr()) { @@ -225,4 +217,26 @@ ResMgr* EditDLL::GetResMgr() return pResMgr; } + +editeng::SharedVclResources::SharedVclResources() + : m_pVirDev(VclPtr<VirtualDevice>::Create()) +{ + m_pVirDev->SetMapMode(MapUnit::MapTwip); +} + +editeng::SharedVclResources::~SharedVclResources() + { m_pVirDev.disposeAndClear(); } + +VclPtr<VirtualDevice> editeng::SharedVclResources::GetVirtualDevice() + { return m_pVirDev; } + +std::shared_ptr<editeng::SharedVclResources> EditDLL::GetSharedVclResources() +{ + SolarMutexGuard g; + auto pLocked(pSharedVcl.lock()); + if(!pLocked) + pSharedVcl = pLocked = std::shared_ptr<editeng::SharedVclResources>(new editeng::SharedVclResources()); + return pLocked; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/editeng/source/editeng/eerdll2.hxx b/editeng/source/editeng/eerdll2.hxx index 32c7c40bbd68..75bfb2131ae7 100644 --- a/editeng/source/editeng/eerdll2.hxx +++ b/editeng/source/editeng/eerdll2.hxx @@ -27,6 +27,19 @@ class SfxPoolItem; class VirtualDevice; +namespace editeng +{ + class SharedVclResources + { + private: + VclPtr<VirtualDevice> m_pVirDev; + public: + SharedVclResources(); + ~SharedVclResources(); + VclPtr<VirtualDevice> GetVirtualDevice(); + }; +} + class GlobalEditData { private: @@ -34,7 +47,6 @@ private: std::vector<SfxPoolItem*>* ppDefItems; rtl::Reference<SvxForbiddenCharactersTable> xForbiddenCharsTable; - VclPtr<VirtualDevice> mpVirDev; public: GlobalEditData(); @@ -45,8 +57,6 @@ public: rtl::Reference<SvxForbiddenCharactersTable> const & GetForbiddenCharsTable(); void SetForbiddenCharsTable( rtl::Reference<SvxForbiddenCharactersTable> const & xForbiddenChars ) { xForbiddenCharsTable = xForbiddenChars; } css::uno::Reference< css::linguistic2::XLanguageGuessing > const & GetLanguageGuesser(); - - VclPtr<VirtualDevice> GetStdVirtualDevice(); }; #endif // INCLUDED_EDITENG_SOURCE_EDITENG_EERDLL2_HXX diff --git a/editeng/source/editeng/impedit.hxx b/editeng/source/editeng/impedit.hxx index 106221f3b195..e8d2cead0532 100644 --- a/editeng/source/editeng/impedit.hxx +++ b/editeng/source/editeng/impedit.hxx @@ -19,6 +19,7 @@ #ifndef INCLUDED_EDITENG_SOURCE_EDITENG_IMPEDIT_HXX #define INCLUDED_EDITENG_SOURCE_EDITENG_IMPEDIT_HXX +#include <eerdll2.hxx> #include <editdoc.hxx> #include <editsel.hxx> #include <editundo.hxx> @@ -397,6 +398,7 @@ class ImpEditEngine : public SfxListener typedef EditEngine::ViewsType ViewsType; private: + std::shared_ptr<editeng::SharedVclResources> pSharedVCL; // Data ... diff --git a/editeng/source/editeng/impedit2.cxx b/editeng/source/editeng/impedit2.cxx index 3338111fc206..506477fdb611 100644 --- a/editeng/source/editeng/impedit2.cxx +++ b/editeng/source/editeng/impedit2.cxx @@ -84,6 +84,7 @@ static sal_uInt16 lcl_CalcExtraSpace( ParaPortion*, const SvxLineSpacingItem& rL } ImpEditEngine::ImpEditEngine( EditEngine* pEE, SfxItemPool* pItemPool ) : + pSharedVCL(EditDLL::Get().GetSharedVclResources()), aPaperSize( 0x7FFFFFFF, 0x7FFFFFFF ), aMinAutoPaperSize( 0x0, 0x0 ), aMaxAutoPaperSize( 0x7FFFFFFF, 0x7FFFFFFF ), @@ -175,6 +176,7 @@ void ImpEditEngine::Dispose() EndListening(*pApp); pVirtDev.disposeAndClear(); mpOwnDev.disposeAndClear(); + pSharedVCL.reset(); } ImpEditEngine::~ImpEditEngine() @@ -204,7 +206,7 @@ void ImpEditEngine::SetRefDevice( OutputDevice* pRef ) if (pRef) pRefDev = pRef; else - pRefDev = EditDLL::Get().GetGlobalData()->GetStdVirtualDevice(); + pRefDev = pSharedVCL->GetVirtualDevice(); nOnePixelInRef = (sal_uInt16)pRefDev->PixelToLogic( Size( 1, 0 ) ).Width(); |