Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <uielement/menubarwrapper.hxx>
30 : : #include <threadhelp/resetableguard.hxx>
31 : : #include <framework/actiontriggerhelper.hxx>
32 : : #include <services.h>
33 : :
34 : : #include <com/sun/star/lang/XServiceInfo.hpp>
35 : : #include <com/sun/star/beans/XPropertySet.hpp>
36 : : #include <com/sun/star/awt/XSystemDependentMenuPeer.hpp>
37 : : #include <com/sun/star/awt/XMenuBar.hpp>
38 : : #include <com/sun/star/container/XIndexContainer.hpp>
39 : : #include <com/sun/star/container/XNameAccess.hpp>
40 : : #include <com/sun/star/ui/UIElementType.hpp>
41 : : #include <com/sun/star/frame/XModuleManager.hpp>
42 : : #include <com/sun/star/util/URLTransformer.hpp>
43 : :
44 : : #include <comphelper/componentcontext.hxx>
45 : : #include <comphelper/processfactory.hxx>
46 : : #include <tools/solar.h>
47 : : #include <vcl/svapp.hxx>
48 : : #include <rtl/logfile.hxx>
49 : :
50 : : using namespace com::sun::star;
51 : : using namespace com::sun::star::uno;
52 : : using namespace com::sun::star::beans;
53 : : using namespace com::sun::star::frame;
54 : : using namespace com::sun::star::lang;
55 : : using namespace com::sun::star::container;
56 : : using namespace com::sun::star::awt;
57 : : using namespace com::sun::star::util;
58 : : using namespace ::com::sun::star::ui;
59 : :
60 : : namespace framework
61 : : {
62 : :
63 : : //*****************************************************************************************************************
64 : : // XInterface, XTypeProvider
65 : : //*****************************************************************************************************************
66 [ + + ][ + - ]: 43978 : DEFINE_XINTERFACE_11 ( MenuBarWrapper ,
67 : : UIConfigElementWrapperBase ,
68 : : DIRECT_INTERFACE( ::com::sun::star::lang::XTypeProvider ),
69 : : DIRECT_INTERFACE( ::com::sun::star::ui::XUIElement ),
70 : : DIRECT_INTERFACE( ::com::sun::star::ui::XUIElementSettings ),
71 : : DIRECT_INTERFACE( ::com::sun::star::beans::XMultiPropertySet ),
72 : : DIRECT_INTERFACE( ::com::sun::star::beans::XFastPropertySet ),
73 : : DIRECT_INTERFACE( ::com::sun::star::beans::XPropertySet ),
74 : : DIRECT_INTERFACE( ::com::sun::star::lang::XInitialization ),
75 : : DIRECT_INTERFACE( ::com::sun::star::lang::XComponent ),
76 : : DIRECT_INTERFACE( ::com::sun::star::util::XUpdatable ),
77 : : DIRECT_INTERFACE( ::com::sun::star::ui::XUIConfigurationListener ),
78 : : DERIVED_INTERFACE( ::com::sun::star::container::XNameAccess, ::com::sun::star::container::XElementAccess )
79 : : )
80 : :
81 [ # # ][ # # ]: 0 : DEFINE_XTYPEPROVIDER_11 ( MenuBarWrapper ,
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
82 : : ::com::sun::star::lang::XTypeProvider ,
83 : : ::com::sun::star::ui::XUIElement ,
84 : : ::com::sun::star::ui::XUIElementSettings ,
85 : : ::com::sun::star::beans::XMultiPropertySet ,
86 : : ::com::sun::star::beans::XFastPropertySet ,
87 : : ::com::sun::star::beans::XPropertySet ,
88 : : ::com::sun::star::lang::XInitialization ,
89 : : ::com::sun::star::lang::XComponent ,
90 : : ::com::sun::star::util::XUpdatable ,
91 : : ::com::sun::star::ui::XUIConfigurationListener ,
92 : : ::com::sun::star::container::XNameAccess
93 : : )
94 : :
95 : 1713 : MenuBarWrapper::MenuBarWrapper(
96 : : const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& xServiceManager
97 : : )
98 : : : UIConfigElementWrapperBase( UIElementType::MENUBAR,xServiceManager ),
99 [ + - ]: 1713 : m_bRefreshPopupControllerCache( sal_True )
100 : : {
101 : 1713 : }
102 : :
103 [ + - ]: 1622 : MenuBarWrapper::~MenuBarWrapper()
104 : : {
105 [ - + ]: 3244 : }
106 : :
107 : 1618 : void SAL_CALL MenuBarWrapper::dispose() throw (::com::sun::star::uno::RuntimeException)
108 : : {
109 [ + - ]: 1618 : Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY );
110 : :
111 [ + - ]: 1618 : com::sun::star::lang::EventObject aEvent( xThis );
112 [ + - ]: 1618 : m_aListenerContainer.disposeAndClear( aEvent );
113 : :
114 [ + - ]: 1618 : ResetableGuard aLock( m_aLock );
115 : :
116 [ + - ][ + - ]: 1618 : m_xMenuBarManager->dispose();
117 : 1618 : m_xMenuBarManager.clear();
118 : 1618 : m_xConfigSource.clear();
119 : 1618 : m_xConfigData.clear();
120 : :
121 : 1618 : m_xMenuBar.clear();
122 [ + - ][ + - ]: 1618 : m_bDisposed = sal_True;
123 : 1618 : }
124 : :
125 : : // XInitialization
126 : 1713 : void SAL_CALL MenuBarWrapper::initialize( const Sequence< Any >& aArguments ) throw ( Exception, RuntimeException )
127 : : {
128 : : RTL_LOGFILE_CONTEXT( aLog, "framework (cd100003) ::MenuBarWrapper::initialize" );
129 : :
130 [ + - ]: 1713 : ResetableGuard aLock( m_aLock );
131 : :
132 [ - + ]: 1713 : if ( m_bDisposed )
133 [ # # ]: 0 : throw DisposedException();
134 : :
135 [ + - ]: 1713 : if ( !m_bInitialized )
136 : : {
137 : 1713 : rtl::OUString aModuleIdentifier;
138 [ + - ]: 1713 : UIConfigElementWrapperBase::initialize( aArguments );
139 : :
140 [ + - ]: 1713 : Reference< XFrame > xFrame( m_xWeakFrame );
141 [ + + ][ + - ]: 1713 : if ( xFrame.is() && m_xConfigSource.is() )
[ + + ]
142 : : {
143 : : // Create VCL menubar which will be filled with settings data
144 : 1709 : MenuBar* pVCLMenuBar = 0;
145 : 1709 : VCLXMenuBar* pAwtMenuBar = 0;
146 : : {
147 [ + - ]: 1709 : SolarMutexGuard aSolarMutexGuard;
148 [ + - ][ + - ]: 1709 : pVCLMenuBar = new MenuBar();
[ + - ]
149 : : }
150 : :
151 : 1709 : Reference< XModuleManager > xModuleManager;
152 : : xModuleManager = Reference< XModuleManager >(
153 [ + - ]: 1709 : m_xServiceFactory->createInstance(
154 [ + - ][ + - ]: 1709 : SERVICENAME_MODULEMANAGER ), UNO_QUERY_THROW );
[ + - ][ + - ]
[ # # ]
155 : :
156 : : try
157 : : {
158 [ + - ][ + - ]: 1709 : aModuleIdentifier = xModuleManager->identify( xFrame );
159 : : }
160 [ # # ]: 0 : catch( const Exception& )
161 : : {
162 : : }
163 : :
164 : 1709 : Reference< XURLTransformer > xTrans;
165 : : try
166 : : {
167 [ + - ][ + - ]: 1709 : xTrans.set( URLTransformer::create(::comphelper::ComponentContext(m_xServiceFactory).getUNOContext()) );
[ + - ][ + - ]
[ + - ]
168 [ + - ][ + + ]: 1709 : m_xConfigData = m_xConfigSource->getSettings( m_aResourceURL, sal_False );
[ + - ][ - + ]
169 [ + - ]: 1145 : if ( m_xConfigData.is() )
170 : : {
171 : : // Fill menubar with container contents
172 : 1145 : sal_uInt16 nId = 1;
173 [ + - ]: 1145 : MenuBarManager::FillMenuWithConfiguration( nId, pVCLMenuBar, aModuleIdentifier, m_xConfigData, xTrans );
174 : : }
175 : : }
176 [ + - ]: 564 : catch ( const NoSuchElementException& )
177 : : {
178 : : }
179 : :
180 : 1709 : sal_Bool bMenuOnly( sal_False );
181 [ + + ]: 10254 : for ( sal_Int32 n = 0; n < aArguments.getLength(); n++ )
182 : : {
183 : 8545 : PropertyValue aPropValue;
184 [ + - ][ + - ]: 8545 : if ( aArguments[n] >>= aPropValue )
185 : : {
186 [ + + ]: 8545 : if ( aPropValue.Name == "MenuOnly" )
187 : 1709 : aPropValue.Value >>= bMenuOnly;
188 : : }
189 : 8545 : }
190 : :
191 [ + - ]: 1709 : if ( !bMenuOnly )
192 : : {
193 : : // Initialize menubar manager with our vcl menu bar. There are some situations where we only want to get the menu without any
194 : : // interaction which is done by the menu bar manager. This must be requested by a special property called "MenuOnly". Be careful
195 : : // a menu bar created with this property is not fully supported. It must be attached to a real menu bar manager to have full
196 : : // support. This feature is currently used for "Inplace editing"!
197 : 1709 : Reference< XDispatchProvider > xDispatchProvider;
198 : :
199 : : MenuBarManager* pMenuBarManager = new MenuBarManager( m_xServiceFactory,
200 : : xFrame,
201 : : xTrans,
202 : : xDispatchProvider,
203 : : aModuleIdentifier,
204 : : pVCLMenuBar,
205 : : sal_False,
206 [ + - ]: 1709 : sal_True );
207 : :
208 [ + - ][ + - ]: 1709 : m_xMenuBarManager = Reference< XComponent >( static_cast< OWeakObject *>( pMenuBarManager ), UNO_QUERY );
[ + - ]
209 : : }
210 : :
211 : : // Initialize toolkit menu bar implementation to have awt::XMenuBar for data exchange.
212 : : // Don't use this toolkit menu bar or one of its functions. It is only used as a data container!
213 [ + - ]: 1709 : pAwtMenuBar = new VCLXMenuBar( pVCLMenuBar );
214 [ + - ][ + - ]: 1709 : m_xMenuBar = Reference< XMenuBar >( static_cast< OWeakObject *>( pAwtMenuBar ), UNO_QUERY );
[ + - ]
215 : 1713 : }
216 [ + - ]: 1713 : }
217 : 1713 : }
218 : :
219 : : // XUIElementSettings
220 : 12 : void SAL_CALL MenuBarWrapper::updateSettings() throw ( RuntimeException )
221 : : {
222 [ + - ]: 12 : ResetableGuard aLock( m_aLock );
223 : :
224 [ - + ]: 12 : if ( m_bDisposed )
225 [ # # ]: 0 : throw DisposedException();
226 : :
227 [ + - ]: 12 : if ( m_xMenuBarManager.is() )
228 : : {
229 [ + - ][ + - ]: 12 : if ( m_xConfigSource.is() && m_bPersistent )
[ + - ]
230 : : {
231 : : try
232 : : {
233 [ + - ][ + - ]: 12 : MenuBarManager* pMenuBarManager = static_cast< MenuBarManager *>( m_xMenuBarManager.get() );
234 : :
235 [ + - ][ + - ]: 12 : m_xConfigData = m_xConfigSource->getSettings( m_aResourceURL, sal_False );
[ + - ][ # # ]
236 [ + - ]: 12 : if ( m_xConfigData.is() )
237 [ + - ]: 12 : pMenuBarManager->SetItemContainer( m_xConfigData );
238 : : }
239 [ # # ]: 0 : catch ( const NoSuchElementException& )
240 : : {
241 : : }
242 : : }
243 : 0 : else if ( !m_bPersistent )
244 : : {
245 : : // Transient menubar: do nothing
246 : : }
247 [ + - ]: 12 : }
248 : 12 : }
249 : 0 : void MenuBarWrapper::impl_fillNewData()
250 : : {
251 : : // Transient menubar => Fill menubar with new data
252 [ # # ]: 0 : MenuBarManager* pMenuBarManager = static_cast< MenuBarManager *>( m_xMenuBarManager.get() );
253 : :
254 [ # # ]: 0 : if ( pMenuBarManager )
255 : 0 : pMenuBarManager->SetItemContainer( m_xConfigData );
256 : 0 : }
257 : :
258 : :
259 : 0 : void MenuBarWrapper::fillPopupControllerCache()
260 : : {
261 [ # # ]: 0 : if ( m_bRefreshPopupControllerCache )
262 : : {
263 [ # # ]: 0 : MenuBarManager* pMenuBarManager = static_cast< MenuBarManager *>( m_xMenuBarManager.get() );
264 [ # # ]: 0 : if ( pMenuBarManager )
265 : 0 : pMenuBarManager->GetPopupController( m_aPopupControllerCache );
266 [ # # ]: 0 : if ( !m_aPopupControllerCache.empty() )
267 : 0 : m_bRefreshPopupControllerCache = sal_False;
268 : : }
269 : 0 : }
270 : :
271 : : // XElementAccess
272 : 0 : Type SAL_CALL MenuBarWrapper::getElementType()
273 : : throw (::com::sun::star::uno::RuntimeException)
274 : : {
275 : 0 : return ::getCppuType(( Reference< XDispatchProvider >*)0);
276 : : }
277 : :
278 : 0 : ::sal_Bool SAL_CALL MenuBarWrapper::hasElements()
279 : : throw (::com::sun::star::uno::RuntimeException)
280 : : {
281 [ # # ]: 0 : ResetableGuard aLock( m_aLock );
282 : :
283 [ # # ]: 0 : if ( m_bDisposed )
284 [ # # ]: 0 : throw DisposedException();
285 : :
286 [ # # ]: 0 : fillPopupControllerCache();
287 [ # # ]: 0 : return ( !m_aPopupControllerCache.empty() );
288 : : }
289 : :
290 : : // XNameAccess
291 : 0 : Any SAL_CALL MenuBarWrapper::getByName(
292 : : const ::rtl::OUString& aName )
293 : : throw ( container::NoSuchElementException,
294 : : lang::WrappedTargetException,
295 : : uno::RuntimeException)
296 : : {
297 [ # # ]: 0 : ResetableGuard aLock( m_aLock );
298 : :
299 [ # # ]: 0 : if ( m_bDisposed )
300 [ # # ]: 0 : throw DisposedException();
301 : :
302 [ # # ]: 0 : fillPopupControllerCache();
303 : :
304 [ # # ]: 0 : PopupControllerCache::const_iterator pIter = m_aPopupControllerCache.find( aName );
305 [ # # ][ # # ]: 0 : if ( pIter != m_aPopupControllerCache.end() )
306 : : {
307 : 0 : uno::Reference< frame::XDispatchProvider > xDispatchProvider;
308 [ # # ][ # # ]: 0 : xDispatchProvider = pIter->second.m_xDispatchProvider;
[ # # ]
309 [ # # ]: 0 : return uno::makeAny( xDispatchProvider );
310 : : }
311 : : else
312 [ # # ][ # # ]: 0 : throw container::NoSuchElementException();
313 : : }
314 : :
315 : 0 : Sequence< ::rtl::OUString > SAL_CALL MenuBarWrapper::getElementNames()
316 : : throw (::com::sun::star::uno::RuntimeException)
317 : : {
318 [ # # ]: 0 : ResetableGuard aLock( m_aLock );
319 : :
320 [ # # ]: 0 : if ( m_bDisposed )
321 [ # # ]: 0 : throw DisposedException();
322 : :
323 [ # # ]: 0 : fillPopupControllerCache();
324 : :
325 [ # # ]: 0 : Sequence< rtl::OUString > aSeq( m_aPopupControllerCache.size() );
326 : :
327 : 0 : sal_Int32 i( 0 );
328 [ # # ]: 0 : PopupControllerCache::const_iterator pIter = m_aPopupControllerCache.begin();
329 [ # # ][ # # ]: 0 : while ( pIter != m_aPopupControllerCache.end() )
330 : : {
331 [ # # ][ # # ]: 0 : aSeq[i++] = pIter->first;
332 : 0 : ++pIter;
333 : : }
334 : :
335 [ # # ]: 0 : return aSeq;
336 : : }
337 : :
338 : 0 : ::sal_Bool SAL_CALL MenuBarWrapper::hasByName(
339 : : const ::rtl::OUString& aName )
340 : : throw (::com::sun::star::uno::RuntimeException)
341 : : {
342 [ # # ]: 0 : ResetableGuard aLock( m_aLock );
343 : :
344 [ # # ]: 0 : if ( m_bDisposed )
345 [ # # ]: 0 : throw DisposedException();
346 : :
347 [ # # ]: 0 : fillPopupControllerCache();
348 : :
349 [ # # ]: 0 : PopupControllerCache::const_iterator pIter = m_aPopupControllerCache.find( aName );
350 [ # # ][ # # ]: 0 : if ( pIter != m_aPopupControllerCache.end() )
351 : 0 : return sal_True;
352 : : else
353 [ # # ]: 0 : return sal_False;
354 : : }
355 : :
356 : : // XUIElement
357 : 0 : Reference< XInterface > SAL_CALL MenuBarWrapper::getRealInterface() throw ( RuntimeException )
358 : : {
359 [ # # ]: 0 : if ( m_bDisposed )
360 [ # # ]: 0 : throw DisposedException();
361 : :
362 : 0 : return Reference< XInterface >( m_xMenuBarManager, UNO_QUERY );
363 : : }
364 : :
365 : : } // namespace framework
366 : :
367 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|