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 throw (css::uno::RuntimeException)
79 {
80 css::uno::Sequence< css::uno::Reference< css::frame::XDispatchInformationProvider > > lProvider = implts_getAllSubProvider();
81 sal_Int32 c1 = lProvider.getLength();
82 sal_Int32 i1 = 0;
83
84 ::comphelper::SequenceAsVector< sal_Int16 > lGroups;
85
86 for (i1=0; i1<c1; ++i1)
87 {
88 // ignore controller, which doesn't implement the right interface
89 css::uno::Reference< css::frame::XDispatchInformationProvider > xProvider = lProvider[i1];
90 if (!xProvider.is())
91 continue;
92
93 const css::uno::Sequence< sal_Int16 > lProviderGroups = xProvider->getSupportedCommandGroups();
94 sal_Int32 c2 = lProviderGroups.getLength();
95 sal_Int32 i2 = 0;
96 for (i2=0; i2<c2; ++i2)
97 {
98 const sal_Int16& rGroup = lProviderGroups[i2];
99 ::comphelper::SequenceAsVector< sal_Int16 >::const_iterator pGroup = ::std::find(lGroups.begin(), lGroups.end(), rGroup);
100 if (pGroup == lGroups.end())
101 lGroups.push_back(rGroup);
102 }
103 }
104
105 return lGroups.getAsConstList();
106 }
107
108 //_________________________________________________________________________________________________________________
getConfigurableDispatchInformation(sal_Int16 nCommandGroup)109 css::uno::Sequence< css::frame::DispatchInformation > SAL_CALL DispatchInformationProvider::getConfigurableDispatchInformation(sal_Int16 nCommandGroup)
110 throw (css::uno::RuntimeException)
111 {
112 css::uno::Sequence< css::uno::Reference< css::frame::XDispatchInformationProvider > > lProvider = implts_getAllSubProvider();
113 sal_Int32 c1 = lProvider.getLength();
114 sal_Int32 i1 = 0;
115
116 BaseHash< css::frame::DispatchInformation > lInfos;
117
118 for (i1=0; i1<c1; ++i1)
119 {
120 try
121 {
122 // ignore controller, which doesn't implement the right interface
123 css::uno::Reference< css::frame::XDispatchInformationProvider > xProvider = lProvider[i1];
124 if (!xProvider.is())
125 continue;
126
127 const css::uno::Sequence< css::frame::DispatchInformation > lProviderInfos = xProvider->getConfigurableDispatchInformation(nCommandGroup);
128 sal_Int32 c2 = lProviderInfos.getLength();
129 sal_Int32 i2 = 0;
130 for (i2=0; i2<c2; ++i2)
131 {
132 const css::frame::DispatchInformation& rInfo = lProviderInfos[i2];
133 BaseHash< css::frame::DispatchInformation >::const_iterator pInfo = lInfos.find(rInfo.Command);
134 if (pInfo == lInfos.end())
135 lInfos[rInfo.Command] = rInfo;
136 }
137 }
138 catch(const css::uno::RuntimeException& exRun)
139 { throw exRun; }
140 catch(const css::uno::Exception&)
141 { continue; }
142 }
143
144 c1 = (sal_Int32)lInfos.size();
145 i1 = 0;
146
147 css::uno::Sequence< css::frame::DispatchInformation > lReturn(c1);
148 BaseHash< css::frame::DispatchInformation >::const_iterator pStepp ;
149 for ( pStepp = lInfos.begin() ;
150 pStepp != lInfos.end () && i1<c1 ;
151 ++pStepp, ++i1 )
152 {
153 lReturn[i1] = pStepp->second;
154 }
155 return lReturn;
156 }
157
158 //_________________________________________________________________________________________________________________
implts_getAllSubProvider()159 css::uno::Sequence< css::uno::Reference< css::frame::XDispatchInformationProvider > > DispatchInformationProvider::implts_getAllSubProvider()
160 {
161 // SAFE -> ----------------------------------
162 ReadGuard aReadLock(m_aLock);
163 css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR;
164 css::uno::Reference< css::frame::XFrame > xFrame(m_xFrame.get(), css::uno::UNO_QUERY);
165 aReadLock.unlock();
166 // <- SAFE ----------------------------------
167
168 if (!xFrame.is())
169 return css::uno::Sequence< css::uno::Reference< css::frame::XDispatchInformationProvider > >();
170
171 CloseDispatcher* pCloser = new CloseDispatcher(xSMGR, xFrame, ::rtl::OUString::createFromAscii("_self")); // explicit "_self" ... not "" ... see implementation of close dispatcher itself!
172 css::uno::Reference< css::uno::XInterface > xCloser(static_cast< css::frame::XDispatch* >(pCloser), css::uno::UNO_QUERY);
173
174 css::uno::Reference< css::frame::XDispatchInformationProvider > xCloseDispatch(xCloser , css::uno::UNO_QUERY);
175 css::uno::Reference< css::frame::XDispatchInformationProvider > xController (xFrame->getController() , css::uno::UNO_QUERY);
176 css::uno::Reference< css::frame::XDispatchInformationProvider > xAppDispatcher(xSMGR->createInstance(IMPLEMENTATIONNAME_APPDISPATCHPROVIDER), css::uno::UNO_QUERY);
177
178 css::uno::Sequence< css::uno::Reference< css::frame::XDispatchInformationProvider > > lProvider(3);
179 lProvider[0] = xController ;
180 lProvider[1] = xCloseDispatch;
181 lProvider[2] = xAppDispatcher;
182
183 return lProvider;
184 }
185
186 } // namespace framework
187