1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <dispatch/dispatchinformationprovider.hxx>
21 #include <dispatch/closedispatcher.hxx>
23 #include <com/sun/star/frame/AppDispatchProvider.hpp>
25 #include <comphelper/sequence.hxx>
27 #include <unordered_map>
32 DispatchInformationProvider::DispatchInformationProvider(css::uno::Reference
< css::uno::XComponentContext
> xContext
,
33 const css::uno::Reference
< css::frame::XFrame
>& xFrame
)
34 : m_xContext (std::move(xContext
))
39 DispatchInformationProvider::~DispatchInformationProvider()
43 css::uno::Sequence
< sal_Int16
> SAL_CALL
DispatchInformationProvider::getSupportedCommandGroups()
45 css::uno::Sequence
< css::uno::Reference
< css::frame::XDispatchInformationProvider
> > lProvider
= implts_getAllSubProvider();
46 sal_Int32 c1
= lProvider
.getLength();
49 ::std::vector
< sal_Int16
> lGroups
;
51 for (i1
=0; i1
<c1
; ++i1
)
53 // ignore controller, which doesn't implement the right interface
54 const css::uno::Reference
< css::frame::XDispatchInformationProvider
>& xProvider
= lProvider
[i1
];
58 const css::uno::Sequence
< sal_Int16
> lProviderGroups
= xProvider
->getSupportedCommandGroups();
59 sal_Int32 c2
= lProviderGroups
.getLength();
61 for (i2
=0; i2
<c2
; ++i2
)
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
);
71 return ::comphelper::containerToSequence(lGroups
);
74 css::uno::Sequence
< css::frame::DispatchInformation
> SAL_CALL
DispatchInformationProvider::getConfigurableDispatchInformation(sal_Int16 nCommandGroup
)
76 css::uno::Sequence
< css::uno::Reference
< css::frame::XDispatchInformationProvider
> > lProvider
= implts_getAllSubProvider();
77 sal_Int32 c1
= lProvider
.getLength();
80 std::unordered_map
<OUString
, css::frame::DispatchInformation
> lInfos
;
82 for (i1
=0; i1
<c1
; ++i1
)
86 // ignore controller, which doesn't implement the right interface
87 const css::uno::Reference
< css::frame::XDispatchInformationProvider
>& xProvider
= lProvider
[i1
];
91 const css::uno::Sequence
< css::frame::DispatchInformation
> lProviderInfos
= xProvider
->getConfigurableDispatchInformation(nCommandGroup
);
92 sal_Int32 c2
= lProviderInfos
.getLength();
94 for (i2
=0; i2
<c2
; ++i2
)
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
;
102 catch(const css::uno::RuntimeException
&)
104 catch(const css::uno::Exception
&)
108 return comphelper::mapValuesToSequence(lInfos
);
111 css::uno::Sequence
< css::uno::Reference
< css::frame::XDispatchInformationProvider
> > DispatchInformationProvider::implts_getAllSubProvider()
113 css::uno::Reference
< css::frame::XFrame
> xFrame(m_xFrame
);
115 return css::uno::Sequence
< css::uno::Reference
< css::frame::XDispatchInformationProvider
> >();
117 rtl::Reference
<CloseDispatcher
> xCloser
= new CloseDispatcher(m_xContext
, xFrame
, u
"_self"); // explicit "_self" ... not "" ... see implementation of close dispatcher itself!
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
128 } // namespace framework
130 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */