diff options
-rw-r--r-- | compilerplugins/clang/badstatics.cxx | 7 | ||||
-rw-r--r-- | vcl/source/window/window.cxx | 37 |
2 files changed, 28 insertions, 16 deletions
diff --git a/compilerplugins/clang/badstatics.cxx b/compilerplugins/clang/badstatics.cxx index 17cbb0d8e2ba..bf3f4be4b66f 100644 --- a/compilerplugins/clang/badstatics.cxx +++ b/compilerplugins/clang/badstatics.cxx @@ -202,6 +202,7 @@ public: || name == "m_aUncommitedRegistrations" // sw/source/uibase/dbui/dbmgr.cxx || (loplugin::DeclCheck(pVarDecl).Var("aAllListeners") .Class("ScAddInListener").GlobalNamespace()) // not owning + || name == "s_pLOKWindowsMap" // LOK only, guarded by assert, and LOK never tries to perform a VCL cleanup ) // these variables appear unproblematic { return true; @@ -213,12 +214,6 @@ public: { return true; } - //TODO: Ignore for now to unbreak the build post - // d516c5c9819dcd7dc6dded2f8f9d9e44061b23c0 "lokdialog: Move the LOKWindowId <-> - // VclPtr<Window> mapping to Window": - if (name == "sLOKWindows") { // vcl/source/window/window.cxx - return true; - } // ignore pointers, nothing happens to them on shutdown QualType const pCanonical(pVarDecl->getType().getUnqualifiedType().getCanonicalType()); if (pCanonical->isPointerType()) { diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx index f93ee26e901e..747368bf6524 100644 --- a/vcl/source/window/window.cxx +++ b/vcl/source/window/window.cxx @@ -84,12 +84,6 @@ using namespace ::com::sun::star::datatransfer::dnd; namespace vcl { -/// Counter to be able to have unique id's for each window. -static vcl::LOKWindowId sLastLOKWindowId = 1; - -/// Map to remember the LOKWindowId <-> Window binding. -static std::map<vcl::LOKWindowId, VclPtr<vcl::Window>> sLOKWindows; - Window::Window( WindowType nType ) : mpWindowImpl(new WindowImpl( nType )) { @@ -3158,24 +3152,47 @@ void Window::SetComponentInterface( Reference< css::awt::XWindowPeer > const & x pWrapper->SetWindowInterface( this, xIFace ); } +typedef std::map<vcl::LOKWindowId, VclPtr<vcl::Window>> LOKWindowsMap; + +namespace { + +LOKWindowsMap& GetLOKWindowsMap() +{ + // never use this in the desktop case + assert(comphelper::LibreOfficeKit::isActive()); + + // Map to remember the LOKWindowId <-> Window binding. + static std::unique_ptr<LOKWindowsMap> s_pLOKWindowsMap; + + if (!s_pLOKWindowsMap) + s_pLOKWindowsMap.reset(new LOKWindowsMap); + + return *s_pLOKWindowsMap.get(); +} + +} + void Window::SetLOKNotifier(const vcl::ILibreOfficeKitNotifier* pNotifier) { // don't allow setting this twice assert(mpWindowImpl->mpLOKNotifier == nullptr); assert(pNotifier); + // Counter to be able to have unique id's for each window. + static vcl::LOKWindowId sLastLOKWindowId = 1; + // assign the LOK window id assert(mpWindowImpl->mnLOKWindowId == 0); mpWindowImpl->mnLOKWindowId = sLastLOKWindowId++; - sLOKWindows.insert(std::map<vcl::LOKWindowId, VclPtr<vcl::Window>>::value_type(mpWindowImpl->mnLOKWindowId, this)); + GetLOKWindowsMap().insert(std::map<vcl::LOKWindowId, VclPtr<vcl::Window>>::value_type(mpWindowImpl->mnLOKWindowId, this)); mpWindowImpl->mpLOKNotifier = pNotifier; } VclPtr<Window> Window::FindLOKWindow(vcl::LOKWindowId nWindowId) { - const auto it = sLOKWindows.find(nWindowId); - if (it != sLOKWindows.end()) + const auto it = GetLOKWindowsMap().find(nWindowId); + if (it != GetLOKWindowsMap().end()) return it->second; return VclPtr<Window>(); @@ -3185,7 +3202,7 @@ void Window::ReleaseLOKNotifier() { // unregister the LOK window binding if (mpWindowImpl->mnLOKWindowId > 0) - sLOKWindows.erase(mpWindowImpl->mnLOKWindowId); + GetLOKWindowsMap().erase(mpWindowImpl->mnLOKWindowId); mpWindowImpl->mpLOKNotifier = nullptr; mpWindowImpl->mnLOKWindowId = 0; |