update credits
[LibreOffice.git] / svx / source / sidebar / ContextChangeEventMultiplexer.cxx
blob427c37a37d03e0acd32593e7cebed1227b747878
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #include "svx/sidebar/ContextChangeEventMultiplexer.hxx"
21 #include <com/sun/star/ui/ContextChangeEventObject.hpp>
22 #include <com/sun/star/ui/XContextChangeEventMultiplexer.hpp>
23 #include <com/sun/star/ui/ContextChangeEventMultiplexer.hpp>
24 #include <com/sun/star/frame/XModuleManager.hpp>
25 #include <comphelper/processfactory.hxx>
26 #include <comphelper/componentcontext.hxx>
27 #include <sfx2/viewsh.hxx>
28 #include <tools/diagnose_ex.h>
30 using namespace css;
31 using namespace cssu;
34 void ContextChangeEventMultiplexer::NotifyContextChange (
35 const cssu::Reference<css::frame::XController>& rxController,
36 const ::sfx2::sidebar::EnumContext::Context eContext)
38 if (rxController.is() && rxController->getFrame().is())
40 const css::ui::ContextChangeEventObject aEvent(
41 rxController,
42 GetModuleName(rxController->getFrame()),
43 ::sfx2::sidebar::EnumContext::GetContextName(eContext));
45 cssu::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (
46 css::ui::ContextChangeEventMultiplexer::get(
47 ::comphelper::getProcessComponentContext()));
48 if (xMultiplexer.is())
49 xMultiplexer->broadcastContextChangeEvent(aEvent, rxController);
56 void ContextChangeEventMultiplexer::NotifyContextChange (
57 SfxViewShell* pViewShell,
58 const ::sfx2::sidebar::EnumContext::Context eContext)
60 if (pViewShell != NULL)
61 NotifyContextChange(pViewShell->GetController(), eContext);
67 ::rtl::OUString ContextChangeEventMultiplexer::GetModuleName (
68 const cssu::Reference<css::frame::XFrame>& rxFrame)
70 try
72 const ::comphelper::ComponentContext aContext (::comphelper::getProcessServiceFactory());
73 const Reference<frame::XModuleManager> xModuleManager (
74 aContext.createComponent("com.sun.star.frame.ModuleManager" ),
75 UNO_QUERY_THROW );
76 return xModuleManager->identify(rxFrame);
78 catch (const Exception&)
80 // An exception typically means that a context change is notified
81 // during initialization or destruction of a view.
82 // Ignore it.
84 return ::sfx2::sidebar::EnumContext::GetApplicationName(
85 ::sfx2::sidebar::EnumContext::Application_None);