Coverage Report

Created: 2025-12-31 10:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/sidebar/ContextChangeEventMultiplexer.cxx
Line
Count
Source
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/lok.hxx>
27
#include <comphelper/processfactory.hxx>
28
#include <sfx2/lokhelper.hxx>
29
#include <sfx2/viewsh.hxx>
30
31
using namespace css;
32
using namespace css::uno;
33
34
35
void ContextChangeEventMultiplexer::NotifyContextChange (
36
    const css::uno::Reference<css::frame::XController>& rxController,
37
    const vcl::EnumContext::Context eContext)
38
0
{
39
0
    if (!(rxController.is() && rxController->getFrame().is()))
40
0
        return;
41
42
0
    const css::ui::ContextChangeEventObject aEvent(
43
0
        rxController,
44
0
        GetModuleName(rxController->getFrame()),
45
0
        vcl::EnumContext::GetContextName(eContext));
46
47
0
    css::uno::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (
48
0
        css::ui::ContextChangeEventMultiplexer::get(
49
0
            ::comphelper::getProcessComponentContext()));
50
0
    if (xMultiplexer.is())
51
0
        xMultiplexer->broadcastContextChangeEvent(aEvent, rxController);
52
53
    // notify the LOK too after all the change have taken effect.
54
0
    if (comphelper::LibreOfficeKit::isActive())
55
0
    {
56
0
        SfxLokHelper::notifyContextChange(aEvent);
57
0
    }
58
0
}
59
60
61
void ContextChangeEventMultiplexer::NotifyContextChange (
62
    const SfxViewShell* pViewShell,
63
    const vcl::EnumContext::Context eContext)
64
0
{
65
0
    if (pViewShell != nullptr)
66
0
        NotifyContextChange(pViewShell->GetController(), eContext);
67
0
}
68
69
70
OUString ContextChangeEventMultiplexer::GetModuleName (
71
    const css::uno::Reference<css::frame::XFrame>& rxFrame)
72
0
{
73
0
    try
74
0
    {
75
0
        const Reference<frame::XModuleManager> xModuleManager =
76
0
            frame::ModuleManager::create( comphelper::getProcessComponentContext() );
77
0
        return xModuleManager->identify(rxFrame);
78
0
    }
79
0
    catch (const Exception&)
80
0
    {
81
        // An exception typically means that a context change is notified
82
        // during initialization or destruction of a view.
83
        // Ignore it.
84
0
    }
85
0
    return vcl::EnumContext::GetApplicationName(
86
0
        vcl::EnumContext::Application::NONE);
87
0
}
88
89
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */