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