From 9be8c4f21200aeec5b334d9536b3b7a0b72c24fa Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Mon, 13 Jul 2015 18:54:17 +0200 Subject: sfx2: remove the global SidebarController::maSidebarControllerContainer This global was crashing on exit, unsurprising as it contains UNO services that reference VCL objects. It turns out that there is already a UNO singleton framework::ContextChangeEventMultiplexer that effectively contains this mapping already, so try to hook that up without creating a public API of it, which is made quite a bit harder by framework's inexplicable multitude of libraries. Change-Id: I4baf67b42c630191fa8879d650eeb62520c331a5 --- .../source/fwe/classes/sfxhelperfunctions.cxx | 10 +++++ framework/source/fwi/helper/mischelper.cxx | 15 +++++++ .../services/ContextChangeEventMultiplexer.cxx | 47 +++++++++++++++++++++- 3 files changed, 71 insertions(+), 1 deletion(-) (limited to 'framework/source') diff --git a/framework/source/fwe/classes/sfxhelperfunctions.cxx b/framework/source/fwe/classes/sfxhelperfunctions.cxx index a1f0826a23f8..c04105ce2f5d 100644 --- a/framework/source/fwe/classes/sfxhelperfunctions.cxx +++ b/framework/source/fwe/classes/sfxhelperfunctions.cxx @@ -18,6 +18,8 @@ */ #include +#include +#include #include @@ -163,6 +165,14 @@ void SAL_CALL ActivateToolPanel( const ::com::sun::star::uno::Reference< ::com:: (*pActivator)( i_rFrame, i_rPanelURL ); } +using namespace ::com::sun::star; +uno::Reference GetFirstListenerWith( + uno::Reference const& xEventFocus, + std::function const&)> const& rPredicate) +{ + return GetFirstListenerWith_Impl(xEventFocus, rPredicate); +} + } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/framework/source/fwi/helper/mischelper.cxx b/framework/source/fwi/helper/mischelper.cxx index 5b1e15fa1e89..06cc06131f29 100644 --- a/framework/source/fwi/helper/mischelper.cxx +++ b/framework/source/fwi/helper/mischelper.cxx @@ -212,6 +212,21 @@ void FillLangItems( std::set< OUString > &rLangItems, } } +auto (*g_pGetMultiplexerListener)( + uno::Reference const&, + std::function const&)> const&) + -> uno::Reference = nullptr; + +uno::Reference +GetFirstListenerWith_Impl( + uno::Reference const& xEventFocus, + std::function const&)> const& rPredicate) +{ + assert(g_pGetMultiplexerListener != nullptr); // should not be called too early, nor too late + return g_pGetMultiplexerListener(xEventFocus, rPredicate); +} + + } // namespace framework /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/framework/source/services/ContextChangeEventMultiplexer.cxx b/framework/source/services/ContextChangeEventMultiplexer.cxx index 6fe88eeebd89..d672704c23c7 100644 --- a/framework/source/services/ContextChangeEventMultiplexer.cxx +++ b/framework/source/services/ContextChangeEventMultiplexer.cxx @@ -17,6 +17,8 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include + #include #include #include @@ -88,7 +90,6 @@ public: const css::lang::EventObject& rEvent) throw (cssu::RuntimeException, std::exception) SAL_OVERRIDE; -private: typedef ::std::vector > ListenerContainer; class FocusDescriptor { @@ -362,6 +363,50 @@ struct Singleton: } +namespace framework { + +// right now we assume there's one matching listener +uno::Reference GetFirstListenerWith_ImplImpl( + uno::Reference const& xEventFocus, + std::function const&)> const& rPredicate) +{ + assert(xEventFocus.is()); // in current usage it's a bug if the XController is null here + uno::Reference xRet; + + ContextChangeEventMultiplexer *const pMultiplexer( + dynamic_cast(Singleton::get().instance.get())); + assert(pMultiplexer); + + ContextChangeEventMultiplexer::FocusDescriptor const*const pFocusDescriptor( + pMultiplexer->GetFocusDescriptor(xEventFocus, false)); + if (!pFocusDescriptor) + return xRet; + + for (auto & xListener : pFocusDescriptor->maListeners) + { + if (rPredicate(xListener)) + { + assert(!xRet.is()); // generalize this if it is used for more than 1:1 mapping? + xRet = xListener; + } + } + return xRet; +} + +namespace { + +struct Hook +{ + Hook() { g_pGetMultiplexerListener = &GetFirstListenerWith_ImplImpl; } + ~Hook() { g_pGetMultiplexerListener = nullptr; } +}; + +static Hook g_hook; + +} + +} + extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL org_apache_openoffice_comp_framework_ContextChangeEventMultiplexer_get_implementation( css::uno::XComponentContext *, -- cgit