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