xref: /AOO41X/main/framework/source/dispatch/dispatchinformationprovider.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_framework.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
32*cdf0e10cSrcweir //	my own includes
33*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
34*cdf0e10cSrcweir #include <dispatch/dispatchinformationprovider.hxx>
35*cdf0e10cSrcweir #include <dispatch/closedispatcher.hxx>
36*cdf0e10cSrcweir #include <threadhelp/readguard.hxx>
37*cdf0e10cSrcweir #include <threadhelp/writeguard.hxx>
38*cdf0e10cSrcweir #include <stdtypes.h>
39*cdf0e10cSrcweir #include <services.h>
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
42*cdf0e10cSrcweir //	interface includes
43*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
44*cdf0e10cSrcweir #include <com/sun/star/frame/CommandGroup.hpp>
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
47*cdf0e10cSrcweir //	includes of other projects
48*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
49*cdf0e10cSrcweir #include <comphelper/sequenceasvector.hxx>
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
52*cdf0e10cSrcweir //	namespace
53*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir namespace framework{
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir namespace css = ::com::sun::star;
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
60*cdf0e10cSrcweir //	declarations
61*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
62*cdf0e10cSrcweir DEFINE_XINTERFACE_1(DispatchInformationProvider                               ,
63*cdf0e10cSrcweir                     OWeakObject                                               ,
64*cdf0e10cSrcweir                     DIRECT_INTERFACE(css::frame::XDispatchInformationProvider))
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
67*cdf0e10cSrcweir DispatchInformationProvider::DispatchInformationProvider(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR ,
68*cdf0e10cSrcweir                                                          const css::uno::Reference< css::frame::XFrame >&              xFrame)
69*cdf0e10cSrcweir     : ThreadHelpBase(&Application::GetSolarMutex())
70*cdf0e10cSrcweir     , m_xSMGR       (xSMGR                        )
71*cdf0e10cSrcweir     , m_xFrame      (xFrame                       )
72*cdf0e10cSrcweir {
73*cdf0e10cSrcweir }
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
76*cdf0e10cSrcweir DispatchInformationProvider::~DispatchInformationProvider()
77*cdf0e10cSrcweir {
78*cdf0e10cSrcweir }
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
81*cdf0e10cSrcweir css::uno::Sequence< sal_Int16 > SAL_CALL DispatchInformationProvider::getSupportedCommandGroups()
82*cdf0e10cSrcweir     throw (css::uno::RuntimeException)
83*cdf0e10cSrcweir {
84*cdf0e10cSrcweir     css::uno::Sequence< css::uno::Reference< css::frame::XDispatchInformationProvider > > lProvider = implts_getAllSubProvider();
85*cdf0e10cSrcweir     sal_Int32                                                                             c1        = lProvider.getLength();
86*cdf0e10cSrcweir     sal_Int32                                                                             i1        = 0;
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir     ::comphelper::SequenceAsVector< sal_Int16 > lGroups;
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir     for (i1=0; i1<c1; ++i1)
91*cdf0e10cSrcweir     {
92*cdf0e10cSrcweir         // ignore controller, which doesnt implement the right interface
93*cdf0e10cSrcweir         css::uno::Reference< css::frame::XDispatchInformationProvider > xProvider = lProvider[i1];
94*cdf0e10cSrcweir         if (!xProvider.is())
95*cdf0e10cSrcweir             continue;
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir         const css::uno::Sequence< sal_Int16 > lProviderGroups = xProvider->getSupportedCommandGroups();
98*cdf0e10cSrcweir               sal_Int32                       c2              = lProviderGroups.getLength();
99*cdf0e10cSrcweir               sal_Int32                       i2              = 0;
100*cdf0e10cSrcweir         for (i2=0; i2<c2; ++i2)
101*cdf0e10cSrcweir         {
102*cdf0e10cSrcweir             const sal_Int16&                                                  rGroup = lProviderGroups[i2];
103*cdf0e10cSrcweir                   ::comphelper::SequenceAsVector< sal_Int16 >::const_iterator pGroup = ::std::find(lGroups.begin(), lGroups.end(), rGroup);
104*cdf0e10cSrcweir             if (pGroup == lGroups.end())
105*cdf0e10cSrcweir                 lGroups.push_back(rGroup);
106*cdf0e10cSrcweir         }
107*cdf0e10cSrcweir     }
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir     return lGroups.getAsConstList();
110*cdf0e10cSrcweir }
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
113*cdf0e10cSrcweir css::uno::Sequence< css::frame::DispatchInformation > SAL_CALL DispatchInformationProvider::getConfigurableDispatchInformation(sal_Int16 nCommandGroup)
114*cdf0e10cSrcweir     throw (css::uno::RuntimeException)
115*cdf0e10cSrcweir {
116*cdf0e10cSrcweir     css::uno::Sequence< css::uno::Reference< css::frame::XDispatchInformationProvider > > lProvider = implts_getAllSubProvider();
117*cdf0e10cSrcweir     sal_Int32                                                                             c1        = lProvider.getLength();
118*cdf0e10cSrcweir     sal_Int32                                                                             i1        = 0;
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir     BaseHash< css::frame::DispatchInformation > lInfos;
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir     for (i1=0; i1<c1; ++i1)
123*cdf0e10cSrcweir     {
124*cdf0e10cSrcweir         try
125*cdf0e10cSrcweir         {
126*cdf0e10cSrcweir             // ignore controller, which doesnt implement the right interface
127*cdf0e10cSrcweir             css::uno::Reference< css::frame::XDispatchInformationProvider > xProvider = lProvider[i1];
128*cdf0e10cSrcweir             if (!xProvider.is())
129*cdf0e10cSrcweir                 continue;
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir             const css::uno::Sequence< css::frame::DispatchInformation > lProviderInfos = xProvider->getConfigurableDispatchInformation(nCommandGroup);
132*cdf0e10cSrcweir                   sal_Int32                                             c2             = lProviderInfos.getLength();
133*cdf0e10cSrcweir                   sal_Int32                                             i2             = 0;
134*cdf0e10cSrcweir             for (i2=0; i2<c2; ++i2)
135*cdf0e10cSrcweir             {
136*cdf0e10cSrcweir                 const css::frame::DispatchInformation&                            rInfo = lProviderInfos[i2];
137*cdf0e10cSrcweir                       BaseHash< css::frame::DispatchInformation >::const_iterator pInfo = lInfos.find(rInfo.Command);
138*cdf0e10cSrcweir                 if (pInfo == lInfos.end())
139*cdf0e10cSrcweir                     lInfos[rInfo.Command] = rInfo;
140*cdf0e10cSrcweir             }
141*cdf0e10cSrcweir         }
142*cdf0e10cSrcweir         catch(const css::uno::RuntimeException& exRun)
143*cdf0e10cSrcweir             { throw exRun; }
144*cdf0e10cSrcweir         catch(const css::uno::Exception&)
145*cdf0e10cSrcweir             { continue; }
146*cdf0e10cSrcweir     }
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir     c1 = (sal_Int32)lInfos.size();
149*cdf0e10cSrcweir     i1 = 0;
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir     css::uno::Sequence< css::frame::DispatchInformation >       lReturn(c1);
152*cdf0e10cSrcweir     BaseHash< css::frame::DispatchInformation >::const_iterator pStepp ;
153*cdf0e10cSrcweir     for (  pStepp  = lInfos.begin()          ;
154*cdf0e10cSrcweir            pStepp != lInfos.end  () && i1<c1 ;
155*cdf0e10cSrcweir          ++pStepp, ++i1                      )
156*cdf0e10cSrcweir     {
157*cdf0e10cSrcweir         lReturn[i1] = pStepp->second;
158*cdf0e10cSrcweir     }
159*cdf0e10cSrcweir     return lReturn;
160*cdf0e10cSrcweir }
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
163*cdf0e10cSrcweir css::uno::Sequence< css::uno::Reference< css::frame::XDispatchInformationProvider > > DispatchInformationProvider::implts_getAllSubProvider()
164*cdf0e10cSrcweir {
165*cdf0e10cSrcweir     // SAFE -> ----------------------------------
166*cdf0e10cSrcweir     ReadGuard aReadLock(m_aLock);
167*cdf0e10cSrcweir     css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR;
168*cdf0e10cSrcweir     css::uno::Reference< css::frame::XFrame >              xFrame(m_xFrame.get(), css::uno::UNO_QUERY);
169*cdf0e10cSrcweir     aReadLock.unlock();
170*cdf0e10cSrcweir     // <- SAFE ----------------------------------
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir     if (!xFrame.is())
173*cdf0e10cSrcweir         return css::uno::Sequence< css::uno::Reference< css::frame::XDispatchInformationProvider > >();
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir     CloseDispatcher* pCloser = new CloseDispatcher(xSMGR, xFrame, ::rtl::OUString::createFromAscii("_self")); // explicit "_self" ... not "" ... see implementation of close dispatcher itself!
176*cdf0e10cSrcweir     css::uno::Reference< css::uno::XInterface > xCloser(static_cast< css::frame::XDispatch* >(pCloser), css::uno::UNO_QUERY);
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir     css::uno::Reference< css::frame::XDispatchInformationProvider > xCloseDispatch(xCloser                                                      , css::uno::UNO_QUERY);
179*cdf0e10cSrcweir     css::uno::Reference< css::frame::XDispatchInformationProvider > xController   (xFrame->getController()                                      , css::uno::UNO_QUERY);
180*cdf0e10cSrcweir     css::uno::Reference< css::frame::XDispatchInformationProvider > xAppDispatcher(xSMGR->createInstance(IMPLEMENTATIONNAME_APPDISPATCHPROVIDER), css::uno::UNO_QUERY);
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir     css::uno::Sequence< css::uno::Reference< css::frame::XDispatchInformationProvider > > lProvider(3);
183*cdf0e10cSrcweir     lProvider[0] = xController   ;
184*cdf0e10cSrcweir     lProvider[1] = xCloseDispatch;
185*cdf0e10cSrcweir     lProvider[2] = xAppDispatcher;
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir     return lProvider;
188*cdf0e10cSrcweir }
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir } // namespace framework
191