summaryrefslogtreecommitdiff
path: root/framework
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2015-07-13 18:54:17 +0200
committerMichael Stahl <mstahl@redhat.com>2015-07-14 11:50:44 +0200
commit9be8c4f21200aeec5b334d9536b3b7a0b72c24fa (patch)
tree43df9f096d1c16a397e56460d458406d1b9cece3 /framework
parenta792aa2c48490e43f7460c7418048d32dc891a62 (diff)
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
Diffstat (limited to 'framework')
-rw-r--r--framework/inc/helper/mischelper.hxx12
-rw-r--r--framework/source/fwe/classes/sfxhelperfunctions.cxx10
-rw-r--r--framework/source/fwi/helper/mischelper.cxx15
-rw-r--r--framework/source/services/ContextChangeEventMultiplexer.cxx47
4 files changed, 83 insertions, 1 deletions
diff --git a/framework/inc/helper/mischelper.hxx b/framework/inc/helper/mischelper.hxx
index 6aa0015ade49..7f45aa6d8a6e 100644
--- a/framework/inc/helper/mischelper.hxx
+++ b/framework/inc/helper/mischelper.hxx
@@ -28,6 +28,7 @@
#include <com/sun/star/container/XContainerListener.hpp>
#include <com/sun/star/frame/XFrame.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
+#include <com/sun/star/ui/XContextChangeEventListener.hpp>
#include <cppuhelper/implbase1.hxx>
@@ -36,6 +37,7 @@
#include <rtl/ustring.hxx>
#include <fwidllapi.h>
+#include <functional>
#include <set>
namespace framework
@@ -304,6 +306,16 @@ class WeakDocumentEventListener : public ::cppu::WeakImplHelper1<com::sun::star:
}
};
+FWI_DLLPUBLIC css::uno::Reference<css::ui::XContextChangeEventListener>
+GetFirstListenerWith_Impl(
+ css::uno::Reference<css::uno::XInterface> const& xEventFocus,
+ std::function<bool (css::uno::Reference<css::ui::XContextChangeEventListener> const&)> const& rPredicate);
+
+FWI_DLLPUBLIC extern auto (*g_pGetMultiplexerListener)(
+ css::uno::Reference<css::uno::XInterface> const&,
+ std::function<bool (css::uno::Reference<css::ui::XContextChangeEventListener> const&)> const&)
+ -> css::uno::Reference<css::ui::XContextChangeEventListener>;
+
} // namespace framework
#endif // INCLUDED_FRAMEWORK_INC_HELPER_MISCHELPER_HXX
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 <framework/sfxhelperfunctions.hxx>
+#include <framework/ContextChangeEventMultiplexerTunnel.hxx>
+#include <helper/mischelper.hxx>
#include <tools/diagnose_ex.h>
@@ -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<ui::XContextChangeEventListener> GetFirstListenerWith(
+ uno::Reference<uno::XInterface> const& xEventFocus,
+ std::function<bool (uno::Reference<ui::XContextChangeEventListener> 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<uno::XInterface> const&,
+ std::function<bool (uno::Reference<ui::XContextChangeEventListener> const&)> const&)
+ -> uno::Reference<ui::XContextChangeEventListener> = nullptr;
+
+uno::Reference<ui::XContextChangeEventListener>
+GetFirstListenerWith_Impl(
+ uno::Reference<uno::XInterface> const& xEventFocus,
+ std::function<bool (uno::Reference<ui::XContextChangeEventListener> 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 <helper/mischelper.hxx>
+
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/lang/XEventListener.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
@@ -88,7 +90,6 @@ public:
const css::lang::EventObject& rEvent)
throw (cssu::RuntimeException, std::exception) SAL_OVERRIDE;
-private:
typedef ::std::vector<cssu::Reference<css::ui::XContextChangeEventListener> > ListenerContainer;
class FocusDescriptor
{
@@ -362,6 +363,50 @@ struct Singleton:
}
+namespace framework {
+
+// right now we assume there's one matching listener
+uno::Reference<ui::XContextChangeEventListener> GetFirstListenerWith_ImplImpl(
+ uno::Reference<uno::XInterface> const& xEventFocus,
+ std::function<bool (uno::Reference<ui::XContextChangeEventListener> const&)> const& rPredicate)
+{
+ assert(xEventFocus.is()); // in current usage it's a bug if the XController is null here
+ uno::Reference<ui::XContextChangeEventListener> xRet;
+
+ ContextChangeEventMultiplexer *const pMultiplexer(
+ dynamic_cast<ContextChangeEventMultiplexer *>(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 *,