Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "svx/sidebar/ContextChangeEventMultiplexer.hxx"
21 :
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>
29 :
30 : using namespace css;
31 : using namespace css::uno;
32 :
33 :
34 1013 : void ContextChangeEventMultiplexer::NotifyContextChange (
35 : const css::uno::Reference<css::frame::XController>& rxController,
36 : const ::sfx2::sidebar::EnumContext::Context eContext)
37 : {
38 1013 : if (rxController.is() && rxController->getFrame().is())
39 : {
40 : const css::ui::ContextChangeEventObject aEvent(
41 : rxController,
42 886 : GetModuleName(rxController->getFrame()),
43 1772 : ::sfx2::sidebar::EnumContext::GetContextName(eContext));
44 :
45 : css::uno::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (
46 : css::ui::ContextChangeEventMultiplexer::get(
47 1772 : ::comphelper::getProcessComponentContext()));
48 886 : if (xMultiplexer.is())
49 1772 : xMultiplexer->broadcastContextChangeEvent(aEvent, rxController);
50 : }
51 1013 : }
52 :
53 :
54 :
55 :
56 342 : void ContextChangeEventMultiplexer::NotifyContextChange (
57 : SfxViewShell* pViewShell,
58 : const ::sfx2::sidebar::EnumContext::Context eContext)
59 : {
60 342 : if (pViewShell != NULL)
61 342 : NotifyContextChange(pViewShell->GetController(), eContext);
62 342 : }
63 :
64 :
65 :
66 :
67 886 : ::rtl::OUString ContextChangeEventMultiplexer::GetModuleName (
68 : const css::uno::Reference<css::frame::XFrame>& rxFrame)
69 : {
70 : try
71 : {
72 : const Reference<frame::XModuleManager> xModuleManager =
73 886 : frame::ModuleManager::create( comphelper::getProcessComponentContext() );
74 1015 : return xModuleManager->identify(rxFrame);
75 : }
76 129 : catch (const Exception&)
77 : {
78 : // An exception typically means that a context change is notified
79 : // during initialization or destruction of a view.
80 : // Ignore it.
81 : }
82 : return ::sfx2::sidebar::EnumContext::GetApplicationName(
83 129 : ::sfx2::sidebar::EnumContext::Application_None);
84 390 : }
85 :
86 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|