bump product version to 5.0.4.1
[LibreOffice.git] / svx / source / sidebar / ContextChangeEventMultiplexer.cxx
blob58eb5e49049abfb7d30f5bff711134326738114b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "svx/sidebar/ContextChangeEventMultiplexer.hxx"
22 #include <com/sun/star/ui/ContextChangeEventObject.hpp>
23 #include <com/sun/star/ui/XContextChangeEventMultiplexer.hpp>
24 #include <com/sun/star/ui/ContextChangeEventMultiplexer.hpp>
25 #include <com/sun/star/frame/ModuleManager.hpp>
26 #include <comphelper/processfactory.hxx>
27 #include <sfx2/viewsh.hxx>
28 #include <tools/diagnose_ex.h>
30 using namespace css;
31 using namespace css::uno;
34 void ContextChangeEventMultiplexer::NotifyContextChange (
35 const css::uno::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 css::uno::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 css::uno::Reference<css::frame::XFrame>& rxFrame)
70 try
72 const Reference<frame::XModuleManager> xModuleManager =
73 frame::ModuleManager::create( comphelper::getProcessComponentContext() );
74 return xModuleManager->identify(rxFrame);
76 catch (const Exception&)
78 // An exception typically means that a context change is notified
79 // during initialization or destruction of a view.
80 // Ignore it.
82 return ::sfx2::sidebar::EnumContext::GetApplicationName(
83 ::sfx2::sidebar::EnumContext::Application_None);
86 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */