1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_framework.hxx"
26
27 //_________________________________________________________________________________________________________________
28 // my own includes
29 //_________________________________________________________________________________________________________________
30 #include <dispatch/dispatchinformationprovider.hxx>
31 #include <dispatch/closedispatcher.hxx>
32 #include <threadhelp/readguard.hxx>
33 #include <threadhelp/writeguard.hxx>
34 #include <stdtypes.h>
35 #include <services.h>
36
37 //_________________________________________________________________________________________________________________
38 // interface includes
39 //_________________________________________________________________________________________________________________
40 #include <com/sun/star/frame/CommandGroup.hpp>
41
42 //_________________________________________________________________________________________________________________
43 // includes of other projects
44 //_________________________________________________________________________________________________________________
45 #include <comphelper/sequenceasvector.hxx>
46
47 //_________________________________________________________________________________________________________________
48 // namespace
49 //_________________________________________________________________________________________________________________
50
51 namespace framework{
52
53 namespace css = ::com::sun::star;
54
55 //_________________________________________________________________________________________________________________
56 // declarations
57 //_________________________________________________________________________________________________________________
DEFINE_XINTERFACE_1(DispatchInformationProvider,OWeakObject,DIRECT_INTERFACE (css::frame::XDispatchInformationProvider))58 DEFINE_XINTERFACE_1(DispatchInformationProvider ,
59 OWeakObject ,
60 DIRECT_INTERFACE(css::frame::XDispatchInformationProvider))
61
62 //_________________________________________________________________________________________________________________
63 DispatchInformationProvider::DispatchInformationProvider(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR ,
64 const css::uno::Reference< css::frame::XFrame >& xFrame)
65 : ThreadHelpBase(&Application::GetSolarMutex())
66 , m_xSMGR (xSMGR )
67 , m_xFrame (xFrame )
68 {
69 }
70
71 //_________________________________________________________________________________________________________________
~DispatchInformationProvider()72 DispatchInformationProvider::~DispatchInformationProvider()
73 {
74 }
75
76 //_________________________________________________________________________________________________________________
getSupportedCommandGroups()77 css::uno::Sequence< sal_Int16 > SAL_CALL DispatchInformationProvider::getSupportedCommandGroups()
78 {
79 css::uno::Sequence< css::uno::Reference< css::frame::XDispatchInformationProvider > > lProvider = implts_getAllSubProvider();
80 sal_Int32 c1 = lProvider.getLength();
81 sal_Int32 i1 = 0;
82
83 ::comphelper::SequenceAsVector< sal_Int16 > lGroups;
84
85 for (i1=0; i1<c1; ++i1)
86 {
87 // ignore controller, which doesn't implement the right interface
88 css::uno::Reference< css::frame::XDispatchInformationProvider > xProvider = lProvider[i1];
89 if (!xProvider.is())
90 continue;
91
92 const css::uno::Sequence< sal_Int16 > lProviderGroups = xProvider->getSupportedCommandGroups();
93 sal_Int32 c2 = lProviderGroups.getLength();
94 sal_Int32 i2 = 0;
95 for (i2=0; i2<c2; ++i2)
96 {
97 const sal_Int16& rGroup = lProviderGroups[i2];
98 ::comphelper::SequenceAsVector< sal_Int16 >::const_iterator pGroup = ::std::find(lGroups.begin(), lGroups.end(), rGroup);
99 if (pGroup == lGroups.end())
100 lGroups.push_back(rGroup);
101 }
102 }
103
104 return lGroups.getAsConstList();
105 }
106
107 //_________________________________________________________________________________________________________________
getConfigurableDispatchInformation(sal_Int16 nCommandGroup)108 css::uno::Sequence< css::frame::DispatchInformation > SAL_CALL DispatchInformationProvider::getConfigurableDispatchInformation(sal_Int16 nCommandGroup)
109 {
110 css::uno::Sequence< css::uno::Reference< css::frame::XDispatchInformationProvider > > lProvider = implts_getAllSubProvider();
111 sal_Int32 c1 = lProvider.getLength();
112 sal_Int32 i1 = 0;
113
114 BaseHash< css::frame::DispatchInformation > lInfos;
115
116 for (i1=0; i1<c1; ++i1)
117 {
118 try
119 {
120 // ignore controller, which doesn't implement the right interface
121 css::uno::Reference< css::frame::XDispatchInformationProvider > xProvider = lProvider[i1];
122 if (!xProvider.is())
123 continue;
124
125 const css::uno::Sequence< css::frame::DispatchInformation > lProviderInfos = xProvider->getConfigurableDispatchInformation(nCommandGroup);
126 sal_Int32 c2 = lProviderInfos.getLength();
127 sal_Int32 i2 = 0;
128 for (i2=0; i2<c2; ++i2)
129 {
130 const css::frame::DispatchInformation& rInfo = lProviderInfos[i2];
131 BaseHash< css::frame::DispatchInformation >::const_iterator pInfo = lInfos.find(rInfo.Command);
132 if (pInfo == lInfos.end())
133 lInfos[rInfo.Command] = rInfo;
134 }
135 }
136 catch(const css::uno::RuntimeException& exRun)
137 { throw exRun; }
138 catch(const css::uno::Exception&)
139 { continue; }
140 }
141
142 c1 = (sal_Int32)lInfos.size();
143 i1 = 0;
144
145 css::uno::Sequence< css::frame::DispatchInformation > lReturn(c1);
146 BaseHash< css::frame::DispatchInformation >::const_iterator pStepp ;
147 for ( pStepp = lInfos.begin() ;
148 pStepp != lInfos.end () && i1<c1 ;
149 ++pStepp, ++i1 )
150 {
151 lReturn[i1] = pStepp->second;
152 }
153 return lReturn;
154 }
155
156 //_________________________________________________________________________________________________________________
implts_getAllSubProvider()157 css::uno::Sequence< css::uno::Reference< css::frame::XDispatchInformationProvider > > DispatchInformationProvider::implts_getAllSubProvider()
158 {
159 // SAFE -> ----------------------------------
160 ReadGuard aReadLock(m_aLock);
161 css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR;
162 css::uno::Reference< css::frame::XFrame > xFrame(m_xFrame.get(), css::uno::UNO_QUERY);
163 aReadLock.unlock();
164 // <- SAFE ----------------------------------
165
166 if (!xFrame.is())
167 return css::uno::Sequence< css::uno::Reference< css::frame::XDispatchInformationProvider > >();
168
169 CloseDispatcher* pCloser = new CloseDispatcher(xSMGR, xFrame, ::rtl::OUString::createFromAscii("_self")); // explicit "_self" ... not "" ... see implementation of close dispatcher itself!
170 css::uno::Reference< css::uno::XInterface > xCloser(static_cast< css::frame::XDispatch* >(pCloser), css::uno::UNO_QUERY);
171
172 css::uno::Reference< css::frame::XDispatchInformationProvider > xCloseDispatch(xCloser , css::uno::UNO_QUERY);
173 css::uno::Reference< css::frame::XDispatchInformationProvider > xController (xFrame->getController() , css::uno::UNO_QUERY);
174 css::uno::Reference< css::frame::XDispatchInformationProvider > xAppDispatcher(xSMGR->createInstance(IMPLEMENTATIONNAME_APPDISPATCHPROVIDER), css::uno::UNO_QUERY);
175
176 css::uno::Sequence< css::uno::Reference< css::frame::XDispatchInformationProvider > > lProvider(3);
177 lProvider[0] = xController ;
178 lProvider[1] = xCloseDispatch;
179 lProvider[2] = xAppDispatcher;
180
181 return lProvider;
182 }
183
184 } // namespace framework
185