Coverage Report

Created: 2026-05-16 09:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/framework/source/dispatch/dispatchinformationprovider.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 <dispatch/dispatchinformationprovider.hxx>
21
#include <dispatch/closedispatcher.hxx>
22
23
#include <com/sun/star/frame/AppDispatchProvider.hpp>
24
25
#include <comphelper/sequence.hxx>
26
27
#include <unordered_map>
28
#include <utility>
29
30
namespace framework{
31
32
DispatchInformationProvider::DispatchInformationProvider(css::uno::Reference< css::uno::XComponentContext >  xContext ,
33
                                                         const css::uno::Reference< css::frame::XFrame >&          xFrame)
34
8.36k
    : m_xContext    (std::move(xContext                     ))
35
8.36k
    , m_xFrame      (xFrame                       )
36
8.36k
{
37
8.36k
}
38
39
DispatchInformationProvider::~DispatchInformationProvider()
40
4.02k
{
41
4.02k
}
42
43
css::uno::Sequence< sal_Int16 > SAL_CALL DispatchInformationProvider::getSupportedCommandGroups()
44
0
{
45
0
    css::uno::Sequence< css::uno::Reference< css::frame::XDispatchInformationProvider > > lProvider = implts_getAllSubProvider();
46
0
    sal_Int32                                                                             c1        = lProvider.getLength();
47
0
    sal_Int32                                                                             i1        = 0;
48
49
0
    ::std::vector< sal_Int16 > lGroups;
50
51
0
    for (i1=0; i1<c1; ++i1)
52
0
    {
53
        // ignore controller, which doesn't implement the right interface
54
0
        const css::uno::Reference< css::frame::XDispatchInformationProvider >& xProvider = lProvider[i1];
55
0
        if (!xProvider.is())
56
0
            continue;
57
58
0
        const css::uno::Sequence< sal_Int16 > lProviderGroups = xProvider->getSupportedCommandGroups();
59
0
        sal_Int32                             c2              = lProviderGroups.getLength();
60
0
        sal_Int32                             i2              = 0;
61
0
        for (i2=0; i2<c2; ++i2)
62
0
        {
63
0
            const sal_Int16&                           rGroup = lProviderGroups[i2];
64
0
            ::std::vector< sal_Int16 >::const_iterator pGroup =
65
0
                            ::std::find(lGroups.begin(), lGroups.end(), rGroup);
66
0
            if (pGroup == lGroups.end())
67
0
                lGroups.push_back(rGroup);
68
0
        }
69
0
    }
70
71
0
    return ::comphelper::containerToSequence(lGroups);
72
0
}
73
74
css::uno::Sequence< css::frame::DispatchInformation > SAL_CALL DispatchInformationProvider::getConfigurableDispatchInformation(sal_Int16 nCommandGroup)
75
0
{
76
0
    css::uno::Sequence< css::uno::Reference< css::frame::XDispatchInformationProvider > > lProvider = implts_getAllSubProvider();
77
0
    sal_Int32                                                                             c1        = lProvider.getLength();
78
0
    sal_Int32                                                                             i1        = 0;
79
80
0
    std::unordered_map<OUString, css::frame::DispatchInformation> lInfos;
81
82
0
    for (i1=0; i1<c1; ++i1)
83
0
    {
84
0
        try
85
0
        {
86
            // ignore controller, which doesn't implement the right interface
87
0
            const css::uno::Reference< css::frame::XDispatchInformationProvider >& xProvider = lProvider[i1];
88
0
            if (!xProvider.is())
89
0
                continue;
90
91
0
            const css::uno::Sequence< css::frame::DispatchInformation > lProviderInfos = xProvider->getConfigurableDispatchInformation(nCommandGroup);
92
0
            sal_Int32                                                   c2             = lProviderInfos.getLength();
93
0
            sal_Int32                                                   i2             = 0;
94
0
            for (i2=0; i2<c2; ++i2)
95
0
            {
96
0
                const css::frame::DispatchInformation& rInfo = lProviderInfos[i2];
97
0
                auto pInfo = lInfos.find(rInfo.Command);
98
0
                if (pInfo == lInfos.end())
99
0
                    lInfos[rInfo.Command] = rInfo;
100
0
            }
101
0
        }
102
0
        catch(const css::uno::RuntimeException&)
103
0
            { throw; }
104
0
        catch(const css::uno::Exception&)
105
0
            { continue; }
106
0
    }
107
108
0
    return comphelper::mapValuesToSequence(lInfos);
109
0
}
110
111
css::uno::Sequence< css::uno::Reference< css::frame::XDispatchInformationProvider > > DispatchInformationProvider::implts_getAllSubProvider()
112
0
{
113
0
    css::uno::Reference< css::frame::XFrame > xFrame(m_xFrame);
114
0
    if (!xFrame.is())
115
0
        return css::uno::Sequence< css::uno::Reference< css::frame::XDispatchInformationProvider > >();
116
117
0
    rtl::Reference<CloseDispatcher> xCloser = new CloseDispatcher(m_xContext, xFrame, u"_self"); // explicit "_self" ... not "" ... see implementation of close dispatcher itself!
118
119
0
    css::uno::Reference< css::frame::XDispatchInformationProvider > xController   (xFrame->getController()                                      , css::uno::UNO_QUERY);
120
0
    css::uno::Reference< css::frame::XDispatchInformationProvider > xAppDispatcher = css::frame::AppDispatchProvider::create(m_xContext);
121
0
    css::uno::Sequence< css::uno::Reference< css::frame::XDispatchInformationProvider > > lProvider{
122
0
        xController, xCloser, xAppDispatcher
123
0
    };
124
125
0
    return lProvider;
126
0
}
127
128
} // namespace framework
129
130
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */