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/menubarmanager.hxx>
30 : : #include <framework/menuconfiguration.hxx>
31 : : #include <framework/bmkmenu.hxx>
32 : : #include <framework/addonmenu.hxx>
33 : : #include <framework/imageproducer.hxx>
34 : : #include <threadhelp/resetableguard.hxx>
35 : : #include "framework/addonsoptions.hxx"
36 : : #include <classes/fwkresid.hxx>
37 : : #include <classes/menumanager.hxx>
38 : : #include <helper/mischelper.hxx>
39 : : #include <framework/menuextensionsupplier.hxx>
40 : : #include <classes/resource.hrc>
41 : : #include <services.h>
42 : :
43 : : #include <com/sun/star/frame/XDispatch.hpp>
44 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
45 : : #include <com/sun/star/lang/DisposedException.hpp>
46 : : #include <com/sun/star/beans/XPropertySet.hpp>
47 : : #include <com/sun/star/frame/XFramesSupplier.hpp>
48 : : #include <com/sun/star/frame/XDesktop.hpp>
49 : : #include <com/sun/star/container/XEnumeration.hpp>
50 : : #include <com/sun/star/util/XStringWidth.hpp>
51 : : #include <com/sun/star/uno/XComponentContext.hpp>
52 : : #include <com/sun/star/lang/XMultiComponentFactory.hpp>
53 : : #include <com/sun/star/frame/XPopupMenuController.hpp>
54 : : #include <com/sun/star/frame/XUIControllerRegistration.hpp>
55 : : #include <com/sun/star/lang/SystemDependent.hpp>
56 : : #include <com/sun/star/ui/ItemType.hpp>
57 : : #include <com/sun/star/ui/ImageType.hpp>
58 : : #include <com/sun/star/container/XNameAccess.hpp>
59 : : #include <com/sun/star/frame/XModuleManager.hpp>
60 : : #include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
61 : : #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
62 : : #include <com/sun/star/ui/ItemStyle.hpp>
63 : : #include <com/sun/star/frame/status/Visibility.hpp>
64 : : #include <com/sun/star/util/URLTransformer.hpp>
65 : :
66 : : #include <comphelper/componentcontext.hxx>
67 : : #include <comphelper/processfactory.hxx>
68 : : #include <comphelper/extract.hxx>
69 : : #include <svtools/menuoptions.hxx>
70 : : #include <unotools/historyoptions.hxx>
71 : : #include <unotools/pathoptions.hxx>
72 : : #include <unotools/cmdoptions.hxx>
73 : : #include <unotools/localfilehelper.hxx>
74 : : #include <toolkit/unohlp.hxx>
75 : : #include <vcl/svapp.hxx>
76 : : #include <vcl/window.hxx>
77 : : #include <osl/mutex.hxx>
78 : : #include <vcl/svapp.hxx>
79 : : #include <osl/file.hxx>
80 : : #include <cppuhelper/implbase1.hxx>
81 : : #include <svtools/acceleratorexecute.hxx>
82 : : #include <rtl/logfile.hxx>
83 : : #include "svtools/miscopt.hxx"
84 : : #include <framework/addonmenu.hxx>
85 : : #include <uielement/menubarmerger.hxx>
86 : :
87 : : // Be careful removing this "bad" construct. There are serious problems
88 : : // with #define STRICT and including windows.h. Changing this needs some
89 : : // redesign on other projects, too. Especially sal/main.h which defines
90 : : // HINSTANCE depending on STRCIT!!!!!!!!!!!!!!!
91 : : struct SystemMenuData
92 : : {
93 : : unsigned long nSize;
94 : : long hMenu;
95 : : };
96 : :
97 : : using namespace ::cppu;
98 : : using namespace ::com::sun::star;
99 : : using namespace ::com::sun::star::uno;
100 : : using namespace ::com::sun::star::util;
101 : : using namespace ::com::sun::star::beans;
102 : : using namespace ::com::sun::star::frame;
103 : : using namespace ::com::sun::star::container;
104 : : using namespace ::com::sun::star::lang;
105 : : using namespace ::com::sun::star::frame;
106 : : using namespace ::com::sun::star::ui;
107 : :
108 : : static const char ITEM_DESCRIPTOR_COMMANDURL[] = "CommandURL";
109 : : static const char ITEM_DESCRIPTOR_HELPURL[] = "HelpURL";
110 : : static const char ITEM_DESCRIPTOR_CONTAINER[] = "ItemDescriptorContainer";
111 : : static const char ITEM_DESCRIPTOR_LABEL[] = "Label";
112 : : static const char ITEM_DESCRIPTOR_TYPE[] = "Type";
113 : : static const char ITEM_DESCRIPTOR_MODULEIDENTIFIER[] = "ModuleIdentifier";
114 : : static const char ITEM_DESCRIPTOR_DISPATCHPROVIDER[] = "DispatchProvider";
115 : : static const char ITEM_DESCRIPTOR_STYLE[] = "Style";
116 : : static const char ITEM_DESCRIPTOR_ISVISIBLE[] = "IsVisible";
117 : : static const char ITEM_DESCRIPTOR_ENABLED[] = "Enabled";
118 : :
119 : : static const sal_Int32 LEN_DESCRIPTOR_COMMANDURL = 10;
120 : : static const sal_Int32 LEN_DESCRIPTOR_HELPURL = 7;
121 : : static const sal_Int32 LEN_DESCRIPTOR_CONTAINER = 23;
122 : : static const sal_Int32 LEN_DESCRIPTOR_LABEL = 5;
123 : : static const sal_Int32 LEN_DESCRIPTOR_TYPE = 4;
124 : : static const sal_Int32 LEN_DESCRIPTOR_MODULEIDENTIFIER = 16;
125 : : static const sal_Int32 LEN_DESCRIPTOR_DISPATCHPROVIDER = 16;
126 : : static const sal_Int32 LEN_DESCRIPTOR_STYLE = 5;
127 : : static const sal_Int32 LEN_DESCRIPTOR_ISVISIBLE = 9;
128 : : static const sal_Int32 LEN_DESCRIPTOR_ENABLED = 7;
129 : :
130 : : const sal_uInt16 ADDONMENU_MERGE_ITEMID_START = 1500;
131 : :
132 : : class StringLength : public ::cppu::WeakImplHelper1< ::com::sun::star::util::XStringWidth >
133 : : {
134 : : public:
135 : : StringLength() {}
136 [ # # ]: 0 : virtual ~StringLength() {}
137 : :
138 : : // XStringWidth
139 : 0 : sal_Int32 SAL_CALL queryStringWidth( const ::rtl::OUString& aString )
140 : : throw (RuntimeException)
141 : : {
142 : 0 : return aString.getLength();
143 : : }
144 : : };
145 : :
146 : : namespace framework
147 : : {
148 : :
149 : : // special menu ids/command ids for dynamic popup menus
150 : : #define SID_SFX_START 5000
151 : : #define SID_NEWDOCDIRECT (SID_SFX_START + 537)
152 : : #define SID_AUTOPILOTMENU (SID_SFX_START + 1381)
153 : : #define SID_PICKLIST (SID_SFX_START + 510)
154 : : #define SID_MDIWINDOWLIST (SID_SFX_START + 610)
155 : : #define SID_ADDONLIST (SID_SFX_START + 1677)
156 : : #define SID_HELPMENU (SID_SFX_START + 410)
157 : :
158 : : #define SFX_REFERER_USER "private:user"
159 : :
160 : : #define aCmdHelpIndex ".uno:HelpIndex"
161 : : #define aCmdToolsMenu ".uno:ToolsMenu"
162 : : #define aCmdHelpMenu ".uno:HelpMenu"
163 : : #define aSlotHelpMenu "slot:5410"
164 : :
165 : : #define aSpecialWindowMenu "window"
166 : : #define aSlotSpecialWindowMenu "slot:5610"
167 : : #define aSlotSpecialToolsMenu "slot:6677"
168 : :
169 : : // special uno commands for window list
170 : : #define aSpecialWindowCommand ".uno:WindowList"
171 : :
172 : 0 : static sal_Int16 getImageTypeFromBools( sal_Bool bBig )
173 : : {
174 : 0 : sal_Int16 n( 0 );
175 [ # # ]: 0 : if ( bBig )
176 : 0 : n |= ::com::sun::star::ui::ImageType::SIZE_LARGE;
177 : 0 : return n;
178 : : }
179 : :
180 : 43387 : MenuBarManager::MenuBarManager(
181 : : const Reference< XMultiServiceFactory >& xServiceFactory,
182 : : const Reference< XFrame >& rFrame,
183 : : const Reference< XURLTransformer >& _xURLTransformer,
184 : : const Reference< XDispatchProvider >& rDispatchProvider,
185 : : const rtl::OUString& rModuleIdentifier,
186 : : Menu* pMenu, sal_Bool bDelete, sal_Bool bDeleteChildren )
187 [ + - ]: 43387 : : ThreadHelpBase( &Application::GetSolarMutex() ), OWeakObject()
188 : : , m_bDisposed( sal_False )
189 : : , m_bRetrieveImages( sal_False )
190 : : , m_bAcceleratorCfg( sal_False )
191 : : , m_bModuleIdentified( sal_False )
192 [ + - ]: 43387 : , m_aListenerContainer( m_aLock.getShareableOslMutex() )
193 : : , mxServiceFactory(xServiceFactory)
194 : : , m_xURLTransformer(_xURLTransformer)
195 [ + - ][ + - ]: 130161 : , m_nSymbolsStyle( SvtMiscOptions().GetCurrentSymbolsStyle() )
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
196 : : {
197 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::MenuBarManager" );
198 : : m_xPopupMenuControllerRegistration = Reference< ::com::sun::star::frame::XUIControllerRegistration >(
199 [ + - ]: 43387 : getServiceFactory()->createInstance( rtl::OUString( "com.sun.star.frame.PopupMenuControllerFactory" )),
200 [ + - ][ + - ]: 43387 : UNO_QUERY );
[ + - ]
201 [ + - ]: 43387 : FillMenuManager( pMenu, rFrame, rDispatchProvider, rModuleIdentifier, bDelete, bDeleteChildren );
202 : 43387 : }
203 : :
204 : 0 : MenuBarManager::MenuBarManager(
205 : : const Reference< XMultiServiceFactory >& xServiceFactory,
206 : : const Reference< XFrame >& rFrame,
207 : : const Reference< XURLTransformer >& _xURLTransformer,
208 : : AddonMenu* pAddonMenu,
209 : : sal_Bool bDelete,
210 : : sal_Bool bDeleteChildren )
211 [ # # ]: 0 : : ThreadHelpBase( &Application::GetSolarMutex() )
212 : : , OWeakObject()
213 : : , m_bDisposed( sal_False )
214 : : , m_bRetrieveImages( sal_True )
215 : : , m_bAcceleratorCfg( sal_False )
216 : : , m_bModuleIdentified( sal_False )
217 [ # # ]: 0 : , m_aListenerContainer( m_aLock.getShareableOslMutex() )
218 : : , mxServiceFactory(xServiceFactory)
219 : : , m_xURLTransformer(_xURLTransformer)
220 [ # # ][ # # ]: 0 : , m_nSymbolsStyle( SvtMiscOptions().GetCurrentSymbolsStyle() )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
221 : : {
222 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::MenuBarManager" );
223 [ # # ]: 0 : Init(rFrame,pAddonMenu,bDelete,bDeleteChildren);
224 : 0 : }
225 : :
226 : 0 : MenuBarManager::MenuBarManager(
227 : : const Reference< XMultiServiceFactory >& xServiceFactory,
228 : : const Reference< XFrame >& rFrame,
229 : : const Reference< XURLTransformer >& _xURLTransformer,
230 : : AddonPopupMenu* pAddonPopupMenu,
231 : : sal_Bool bDelete,
232 : : sal_Bool bDeleteChildren )
233 [ # # ]: 0 : : ThreadHelpBase( &Application::GetSolarMutex() )
234 : : , OWeakObject()
235 : : , m_bDisposed( sal_False )
236 : : , m_bRetrieveImages( sal_True )
237 : : , m_bAcceleratorCfg( sal_False )
238 : : , m_bModuleIdentified( sal_False )
239 [ # # ]: 0 : , m_aListenerContainer( m_aLock.getShareableOslMutex() )
240 : : , mxServiceFactory(xServiceFactory)
241 : : , m_xURLTransformer(_xURLTransformer)
242 [ # # ][ # # ]: 0 : , m_nSymbolsStyle( SvtMiscOptions().GetCurrentSymbolsStyle() )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
243 : : {
244 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::MenuBarManager" );
245 [ # # ]: 0 : Init(rFrame,pAddonPopupMenu,bDelete,bDeleteChildren,true);
246 : 0 : }
247 : :
248 : 396704 : Any SAL_CALL MenuBarManager::queryInterface( const Type & rType ) throw ( RuntimeException )
249 : : {
250 : : Any a = ::cppu::queryInterface(
251 : : rType ,
252 : : (static_cast< ::com::sun::star::frame::XStatusListener* >(this)),
253 : : (static_cast< ::com::sun::star::frame::XFrameActionListener* >(this)),
254 : : (static_cast< ::com::sun::star::ui::XUIConfigurationListener* >(this)),
255 : : (static_cast< XEventListener* >((XStatusListener *)this)),
256 : : (static_cast< XComponent* >(this)),
257 [ + - ]: 396704 : (static_cast< ::com::sun::star::awt::XSystemDependentMenuPeer* >(this)));
258 : :
259 [ + + ]: 396704 : if ( a.hasValue() )
260 : 386716 : return a;
261 : :
262 [ + - ]: 396704 : return OWeakObject::queryInterface( rType );
263 : : }
264 : :
265 : :
266 : 3697448 : void SAL_CALL MenuBarManager::acquire() throw()
267 : : {
268 : 3697448 : OWeakObject::acquire();
269 : 3697448 : }
270 : :
271 : :
272 : 3697266 : void SAL_CALL MenuBarManager::release() throw()
273 : : {
274 : 3697266 : OWeakObject::release();
275 : 3697266 : }
276 : :
277 : :
278 : 0 : Any SAL_CALL MenuBarManager::getMenuHandle( const Sequence< sal_Int8 >& /*ProcessId*/, sal_Int16 SystemType ) throw (RuntimeException)
279 : : {
280 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::getMenuHandle" );
281 [ # # ]: 0 : ResetableGuard aGuard( m_aLock );
282 : :
283 [ # # ]: 0 : if ( m_bDisposed )
284 [ # # ]: 0 : throw com::sun::star::lang::DisposedException();
285 : :
286 : 0 : Any a;
287 : :
288 [ # # ]: 0 : if ( m_pVCLMenu )
289 : : {
290 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
291 : :
292 : : SystemMenuData aSystemMenuData;
293 : 0 : aSystemMenuData.nSize = sizeof( SystemMenuData );
294 : :
295 [ # # ]: 0 : m_pVCLMenu->GetSystemMenuData( &aSystemMenuData );
296 : : #ifdef QUARTZ
297 : : if( SystemType == SystemDependent::SYSTEM_MAC )
298 : : {
299 : : }
300 : : #elif (defined WNT)
301 : : if( SystemType == SystemDependent::SYSTEM_WIN32 )
302 : : {
303 : : a <<= (long) aSystemMenuData.hMenu;
304 : : }
305 : : #elif (defined UNX)
306 : : if( SystemType == SystemDependent::SYSTEM_XWINDOW )
307 : : {
308 [ # # ]: 0 : }
309 : : #endif
310 : : }
311 : :
312 [ # # ]: 0 : return a;
313 : : }
314 : :
315 [ + - ][ + - ]: 43296 : MenuBarManager::~MenuBarManager()
[ + - ][ + - ]
316 : : {
317 : : // stop asynchronous settings timer
318 : 43296 : m_xDeferedItemContainer.clear();
319 [ + - ]: 43296 : m_aAsyncSettingsTimer.Stop();
320 : :
321 : : DBG_ASSERT( OWeakObject::m_refCount == 0, "Who wants to delete an object with refcount > 0!" );
322 [ - + ]: 86592 : }
323 : :
324 : 43296 : void MenuBarManager::Destroy()
325 : : {
326 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::Destroy" );
327 [ + - ]: 43296 : SolarMutexGuard aGuard;
328 : :
329 [ + - ]: 43296 : if ( !m_bDisposed )
330 : : {
331 : : // stop asynchronous settings timer and
332 : : // release defered item container reference
333 [ + - ]: 43296 : m_aAsyncSettingsTimer.Stop();
334 : 43296 : m_xDeferedItemContainer.clear();
335 [ + - ]: 43296 : RemoveListener();
336 : :
337 : 43296 : std::vector< MenuItemHandler* >::iterator p;
338 [ + - ][ + + ]: 377430 : for ( p = m_aMenuItemHandlerVector.begin(); p != m_aMenuItemHandlerVector.end(); ++p )
339 : : {
340 : 334134 : MenuItemHandler* pItemHandler = *p;
341 : 334134 : pItemHandler->xMenuItemDispatch.clear();
342 : 334134 : pItemHandler->xSubMenuManager.clear();
343 : 334134 : pItemHandler->xPopupMenu.clear();
344 [ + - ][ + - ]: 334134 : delete pItemHandler;
345 : : }
346 : 43296 : m_aMenuItemHandlerVector.clear();
347 : :
348 [ + + ]: 43296 : if ( m_bDeleteMenu )
349 : : {
350 [ + - ][ + - ]: 41676 : delete m_pVCLMenu;
351 : 43296 : m_pVCLMenu = 0;
352 : : }
353 [ + - ]: 43296 : }
354 : 43296 : }
355 : :
356 : : // XComponent
357 : 43296 : void SAL_CALL MenuBarManager::dispose() throw( RuntimeException )
358 : : {
359 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::dispose" );
360 [ + - ]: 43296 : Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY );
361 : :
362 [ + - ]: 43296 : EventObject aEvent( xThis );
363 [ + - ]: 43296 : m_aListenerContainer.disposeAndClear( aEvent );
364 : :
365 : : {
366 [ + - ]: 43296 : ResetableGuard aGuard( m_aLock );
367 [ + - ]: 43296 : Destroy();
368 : 43296 : m_bDisposed = sal_True;
369 : :
370 [ + + ]: 43296 : if ( m_xDocImageManager.is() )
371 : : {
372 : : try
373 : : {
374 [ + - ]: 43246 : m_xDocImageManager->removeConfigurationListener(
375 : : Reference< XUIConfigurationListener >(
376 [ + - ][ + - ]: 43246 : static_cast< OWeakObject* >( this ), UNO_QUERY ));
[ # # ]
377 : : }
378 [ # # ]: 0 : catch ( const Exception& )
379 : : {
380 : : }
381 : : }
382 [ + - ]: 43296 : if ( m_xModuleImageManager.is() )
383 : : {
384 : : try
385 : : {
386 [ + - ]: 43296 : m_xModuleImageManager->removeConfigurationListener(
387 : : Reference< XUIConfigurationListener >(
388 [ + - ][ + - ]: 43296 : static_cast< OWeakObject* >( this ), UNO_QUERY ));
[ # # ]
389 : : }
390 [ # # ]: 0 : catch ( const Exception& )
391 : : {
392 : : }
393 : : }
394 : 43296 : m_xDocImageManager.clear();
395 : 43296 : m_xModuleImageManager.clear();
396 : 43296 : m_xGlobalAcceleratorManager.clear();
397 : 43296 : m_xModuleAcceleratorManager.clear();
398 : 43296 : m_xDocAcceleratorManager.clear();
399 : 43296 : m_xUICommandLabels.clear();
400 : 43296 : m_xPopupMenuControllerRegistration.clear();
401 [ + - ]: 43296 : mxServiceFactory.clear();
402 [ + - ]: 43296 : }
403 : 43296 : }
404 : :
405 : 0 : void SAL_CALL MenuBarManager::addEventListener( const Reference< XEventListener >& xListener ) throw( RuntimeException )
406 : : {
407 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::addEventListener" );
408 [ # # ]: 0 : ResetableGuard aGuard( m_aLock );
409 : :
410 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
411 [ # # ]: 0 : if ( m_bDisposed )
412 [ # # ]: 0 : throw DisposedException();
413 : :
414 [ # # ][ # # ]: 0 : m_aListenerContainer.addInterface( ::getCppuType( ( const Reference< XEventListener >* ) NULL ), xListener );
[ # # ]
415 : 0 : }
416 : :
417 : 0 : void SAL_CALL MenuBarManager::removeEventListener( const Reference< XEventListener >& xListener ) throw( RuntimeException )
418 : : {
419 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::removeEventListener" );
420 [ # # ]: 0 : ResetableGuard aGuard( m_aLock );
421 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
422 [ # # ][ # # ]: 0 : m_aListenerContainer.removeInterface( ::getCppuType( ( const Reference< XEventListener >* ) NULL ), xListener );
[ # # ]
423 : 0 : }
424 : :
425 : 0 : void SAL_CALL MenuBarManager::elementInserted( const ::com::sun::star::ui::ConfigurationEvent& Event )
426 : : throw (RuntimeException)
427 : : {
428 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::elementInserted" );
429 [ # # ]: 0 : ResetableGuard aGuard( m_aLock );
430 : :
431 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
432 [ # # ]: 0 : if ( m_bDisposed )
433 : 0 : return;
434 : :
435 : 0 : sal_Int16 nImageType = sal_Int16();
436 : 0 : sal_Int16 nCurrentImageType = getImageTypeFromBools( sal_False );
437 [ # # ][ # # ]: 0 : if (( Event.aInfo >>= nImageType ) &&
[ # # ]
438 : : ( nImageType == nCurrentImageType ))
439 [ # # ][ # # ]: 0 : RequestImages();
[ # # ]
440 : : }
441 : :
442 : 0 : void SAL_CALL MenuBarManager::elementRemoved( const ::com::sun::star::ui::ConfigurationEvent& Event )
443 : : throw (RuntimeException)
444 : : {
445 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::elementRemoved" );
446 : 0 : elementInserted(Event);
447 : 0 : }
448 : :
449 : 0 : void SAL_CALL MenuBarManager::elementReplaced( const ::com::sun::star::ui::ConfigurationEvent& Event )
450 : : throw (RuntimeException)
451 : : {
452 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::elementReplaced" );
453 : 0 : elementInserted(Event);
454 : 0 : }
455 : :
456 : : // XFrameActionListener
457 : 123168 : void SAL_CALL MenuBarManager::frameAction( const FrameActionEvent& Action )
458 : : throw ( RuntimeException )
459 : : {
460 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::frameAction" );
461 [ + - ]: 123168 : ResetableGuard aGuard( m_aLock );
462 : :
463 [ - + ]: 123168 : if ( m_bDisposed )
464 [ # # ]: 0 : throw com::sun::star::lang::DisposedException();
465 : :
466 [ - + ]: 123168 : if ( Action.Action == FrameAction_CONTEXT_CHANGED )
467 : : {
468 : 0 : std::vector< MenuItemHandler* >::iterator p;
469 [ # # ][ # # ]: 0 : for ( p = m_aMenuItemHandlerVector.begin(); p != m_aMenuItemHandlerVector.end(); ++p )
470 : : {
471 : : // Clear dispatch reference as we will requery it later o
472 : 0 : MenuItemHandler* pItemHandler = *p;
473 : 0 : pItemHandler->xMenuItemDispatch.clear();
474 : : }
475 [ + - ]: 123168 : }
476 : 123168 : }
477 : :
478 : : // XStatusListener
479 : 300 : void SAL_CALL MenuBarManager::statusChanged( const FeatureStateEvent& Event )
480 : : throw ( RuntimeException )
481 : : {
482 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::statusChanged" );
483 : 300 : ::rtl::OUString aFeatureURL = Event.FeatureURL.Complete;
484 : :
485 [ + - ]: 300 : SolarMutexGuard aSolarGuard;
486 : : {
487 [ + - ]: 300 : ResetableGuard aGuard( m_aLock );
488 : :
489 [ - + ]: 300 : if ( m_bDisposed )
490 : 300 : return;
491 : :
492 : : // We have to check all menu entries as there can be identical entries in a popup menu.
493 : 300 : std::vector< MenuItemHandler* >::iterator p;
494 [ + - ][ + + ]: 7080 : for ( p = m_aMenuItemHandlerVector.begin(); p != m_aMenuItemHandlerVector.end(); ++p )
495 : : {
496 : 6780 : MenuItemHandler* pMenuItemHandler = *p;
497 [ + + ]: 6780 : if ( pMenuItemHandler->aMenuItemURL == aFeatureURL )
498 : : {
499 : 300 : sal_Bool bCheckmark( sal_False );
500 [ + - ]: 300 : sal_Bool bMenuItemEnabled( m_pVCLMenu->IsItemEnabled( pMenuItemHandler->nItemId ));
501 : 300 : sal_Bool bEnabledItem( Event.IsEnabled );
502 : 300 : rtl::OUString aItemText;
503 : 300 : status::Visibility aVisibilityStatus;
504 : :
505 : : #ifdef UNIX
506 : : //enable some slots hardly, because UNIX clipboard does not notify all changes
507 : : // Can be removed if follow up task will be fixed directly within applications.
508 : : // Note: PasteSpecial is handled specifically by calc
509 [ + + ]: 590 : if ( pMenuItemHandler->aMenuItemURL == ".uno:Paste"
[ + + - + ]
510 : 290 : || pMenuItemHandler->aMenuItemURL == ".uno:PasteClipboard" ) // special for draw/impress
511 : 10 : bEnabledItem = sal_True;
512 : : #endif
513 : :
514 : : // Enable/disable item
515 [ + + ]: 300 : if ( bEnabledItem != bMenuItemEnabled )
516 [ + - ]: 62 : m_pVCLMenu->EnableItem( pMenuItemHandler->nItemId, bEnabledItem );
517 : :
518 [ + + ]: 300 : if ( Event.State >>= bCheckmark )
519 : : {
520 : : // Checkmark or RadioButton
521 [ + - ]: 92 : m_pVCLMenu->ShowItem( pMenuItemHandler->nItemId, sal_True );
522 [ + - ]: 92 : m_pVCLMenu->CheckItem( pMenuItemHandler->nItemId, bCheckmark );
523 : :
524 [ + - ]: 92 : MenuItemBits nBits = m_pVCLMenu->GetItemBits( pMenuItemHandler->nItemId );
525 : : //If not already designated RadioButton set as CheckMark
526 [ + + ]: 92 : if (!(nBits & MIB_RADIOCHECK))
527 [ + - ]: 80 : m_pVCLMenu->SetItemBits( pMenuItemHandler->nItemId, nBits | MIB_CHECKABLE );
528 : : }
529 [ - + ]: 208 : else if ( Event.State >>= aItemText )
530 : : {
531 : : // Replacement for place holders
532 [ # # ]: 0 : if ( aItemText.matchAsciiL( "($1)", 4 ))
533 : : {
534 [ # # ][ # # ]: 0 : String aResStr = String( FwkResId( STR_UPDATEDOC ));
535 [ # # ]: 0 : rtl::OUString aTmp( aResStr );
536 : 0 : aTmp += rtl::OUString( " " );
537 : 0 : aTmp += aItemText.copy( 4 );
538 [ # # ]: 0 : aItemText = aTmp;
539 : : }
540 [ # # ]: 0 : else if ( aItemText.matchAsciiL( "($2)", 4 ))
541 : : {
542 [ # # ][ # # ]: 0 : String aResStr = String( FwkResId( STR_CLOSEDOC_ANDRETURN ));
543 [ # # ]: 0 : rtl::OUString aTmp( aResStr );
544 : 0 : aTmp += aItemText.copy( 4 );
545 [ # # ]: 0 : aItemText = aTmp;
546 : : }
547 [ # # ]: 0 : else if ( aItemText.matchAsciiL( "($3)", 4 ))
548 : : {
549 [ # # ][ # # ]: 0 : String aResStr = String( FwkResId( STR_SAVECOPYDOC ));
550 [ # # ]: 0 : rtl::OUString aTmp( aResStr );
551 : 0 : aTmp += aItemText.copy( 4 );
552 [ # # ]: 0 : aItemText = aTmp;
553 : : }
554 : :
555 [ # # ]: 0 : m_pVCLMenu->ShowItem( pMenuItemHandler->nItemId, sal_True );
556 [ # # ][ # # ]: 0 : m_pVCLMenu->SetItemText( pMenuItemHandler->nItemId, aItemText );
[ # # ]
557 : : }
558 [ + - ][ + + ]: 208 : else if ( Event.State >>= aVisibilityStatus )
559 : : {
560 : : // Visibility
561 [ + - ]: 6 : m_pVCLMenu->ShowItem( pMenuItemHandler->nItemId, aVisibilityStatus.bVisible );
562 : : }
563 : : else
564 [ + - ]: 300 : m_pVCLMenu->ShowItem( pMenuItemHandler->nItemId, sal_True );
565 : : }
566 : :
567 [ - + ]: 6780 : if ( Event.Requery )
568 : : {
569 : : // Release dispatch object - will be requeried on the next activate!
570 : 0 : pMenuItemHandler->xMenuItemDispatch.clear();
571 : : }
572 [ + - ][ + - ]: 300 : }
573 [ + - ][ - + ]: 300 : }
[ + - ]
574 : : }
575 : :
576 : : // Helper to retrieve own structure from item ID
577 : 0 : MenuBarManager::MenuItemHandler* MenuBarManager::GetMenuItemHandler( sal_uInt16 nItemId )
578 : : {
579 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::GetMenuItemHandler" );
580 [ # # ]: 0 : ResetableGuard aGuard( m_aLock );
581 : :
582 : 0 : std::vector< MenuItemHandler* >::iterator p;
583 [ # # ][ # # ]: 0 : for ( p = m_aMenuItemHandlerVector.begin(); p != m_aMenuItemHandlerVector.end(); ++p )
584 : : {
585 : 0 : MenuItemHandler* pItemHandler = *p;
586 [ # # ]: 0 : if ( pItemHandler->nItemId == nItemId )
587 : 0 : return pItemHandler;
588 : : }
589 : :
590 [ # # ]: 0 : return 0;
591 : : }
592 : :
593 : : // Helper to set request images flag
594 : 0 : void MenuBarManager::RequestImages()
595 : : {
596 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::RequestImages" );
597 : :
598 : 0 : m_bRetrieveImages = sal_True;
599 : 0 : const sal_uInt32 nCount = m_aMenuItemHandlerVector.size();
600 [ # # ]: 0 : for ( sal_uInt32 i = 0; i < nCount; ++i )
601 : : {
602 : 0 : MenuItemHandler* pItemHandler = m_aMenuItemHandlerVector[i];
603 [ # # ]: 0 : if ( pItemHandler->xSubMenuManager.is() )
604 : : {
605 : 0 : MenuBarManager* pMenuBarManager = (MenuBarManager*)(pItemHandler->xSubMenuManager.get());
606 : 0 : pMenuBarManager->RequestImages();
607 : : }
608 : : }
609 : 0 : }
610 : :
611 : : // Helper to reset objects to prepare shutdown
612 : 43310 : void MenuBarManager::RemoveListener()
613 : : {
614 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::RemoveListener" );
615 [ + - ]: 43310 : ResetableGuard aGuard( m_aLock );
616 : :
617 : : // Check service manager reference. Remove listener can be called due
618 : : // to a disposing call from the frame and therefore we already removed
619 : : // our listeners and release the service manager reference!
620 : 43310 : Reference< XMultiServiceFactory > xServiceManager = getServiceFactory();
621 [ + - ]: 43310 : if ( xServiceManager.is() )
622 : : {
623 : 43310 : std::vector< MenuItemHandler* >::iterator p;
624 [ + - ][ + + ]: 377558 : for ( p = m_aMenuItemHandlerVector.begin(); p != m_aMenuItemHandlerVector.end(); ++p )
625 : : {
626 : 334248 : MenuItemHandler* pItemHandler = *p;
627 [ + + ]: 334248 : if ( pItemHandler->xMenuItemDispatch.is() )
628 : : {
629 : 124 : URL aTargetURL;
630 : 124 : aTargetURL.Complete = pItemHandler->aMenuItemURL;
631 [ + - ][ + - ]: 124 : m_xURLTransformer->parseStrict( aTargetURL );
632 : :
633 [ + - ]: 124 : pItemHandler->xMenuItemDispatch->removeStatusListener(
634 [ + - ][ + - ]: 124 : static_cast< XStatusListener* >( this ), aTargetURL );
635 : : }
636 : :
637 : 334248 : pItemHandler->xMenuItemDispatch.clear();
638 [ + + ]: 334248 : if ( pItemHandler->xPopupMenu.is() )
639 : : {
640 : : {
641 : : // Remove popup menu from menu structure
642 [ + - ]: 10788 : SolarMutexGuard aGuard2;
643 [ + - ][ + - ]: 10788 : m_pVCLMenu->SetPopupMenu( pItemHandler->nItemId, 0 );
644 : : }
645 : :
646 [ + - ]: 10788 : Reference< com::sun::star::lang::XEventListener > xEventListener( pItemHandler->xPopupMenuController, UNO_QUERY );
647 [ + + ]: 10788 : if ( xEventListener.is() )
648 : : {
649 [ + - ]: 6 : EventObject aEventObject;
650 [ + - ]: 6 : aEventObject.Source = (OWeakObject *)this;
651 [ + - ][ + - ]: 6 : xEventListener->disposing( aEventObject );
[ + - ]
652 : : }
653 : :
654 : : // We now provide a popup menu controller to external code.
655 : : // Therefore the life-time must be explicitly handled via
656 : : // dispose!!
657 : : try
658 : : {
659 [ + - ]: 10788 : Reference< XComponent > xComponent( pItemHandler->xPopupMenuController, UNO_QUERY );
660 [ + + ]: 10788 : if ( xComponent.is() )
661 [ + - ][ + - ]: 10788 : xComponent->dispose();
662 : : }
663 [ # # # ]: 0 : catch ( const RuntimeException& )
664 : : {
665 : 0 : throw;
666 : : }
667 [ # # ]: 0 : catch ( const Exception& )
668 : : {
669 : : }
670 : :
671 : : // Release references to controller and popup menu
672 : 10788 : pItemHandler->xPopupMenuController.clear();
673 : 10788 : pItemHandler->xPopupMenu.clear();
674 : : }
675 : :
676 [ + - ]: 334248 : Reference< XComponent > xComponent( pItemHandler->xSubMenuManager, UNO_QUERY );
677 [ + + ]: 334248 : if ( xComponent.is() )
678 [ + - ][ + - ]: 41676 : xComponent->dispose();
679 : 334248 : }
680 : : }
681 : :
682 : : try
683 : : {
684 [ + - ]: 43310 : if ( m_xFrame.is() )
685 [ + - ]: 43310 : m_xFrame->removeFrameActionListener( Reference< XFrameActionListener >(
686 [ + - ][ + - ]: 43310 : static_cast< OWeakObject* >( this ), UNO_QUERY ));
[ # # ]
687 : : }
688 [ # # ]: 0 : catch ( const Exception& )
689 : : {
690 : : }
691 : :
692 [ + - ][ + - ]: 43310 : m_xFrame = 0;
693 : 43310 : }
694 : :
695 : 91 : void SAL_CALL MenuBarManager::disposing( const EventObject& Source ) throw ( RuntimeException )
696 : : {
697 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::disposing(evt)" );
698 : 91 : MenuItemHandler* pMenuItemDisposing = NULL;
699 : :
700 [ + - ]: 91 : ResetableGuard aGuard( m_aLock );
701 : :
702 : 91 : std::vector< MenuItemHandler* >::iterator p;
703 [ + - ][ - + ]: 91 : for ( p = m_aMenuItemHandlerVector.begin(); p != m_aMenuItemHandlerVector.end(); ++p )
704 : : {
705 : 0 : MenuItemHandler* pMenuItemHandler = *p;
706 [ # # ][ # # ]: 0 : if ( pMenuItemHandler->xMenuItemDispatch.is() &&
[ # # ]
707 [ # # ]: 0 : pMenuItemHandler->xMenuItemDispatch == Source.Source )
708 : : {
709 : : // disposing called from menu item dispatcher, remove listener
710 : 0 : pMenuItemDisposing = pMenuItemHandler;
711 : 0 : break;
712 : : }
713 : : }
714 : :
715 [ - + ]: 91 : if ( pMenuItemDisposing )
716 : : {
717 : : // Release references to the dispatch object
718 : 0 : URL aTargetURL;
719 : 0 : aTargetURL.Complete = pMenuItemDisposing->aMenuItemURL;
720 : :
721 : : // Check reference of service manager before we use it. Reference could
722 : : // be cleared due to RemoveListener call!
723 : 0 : Reference< XMultiServiceFactory > xServiceManager( getServiceFactory() );
724 [ # # ]: 0 : if ( xServiceManager.is() )
725 : : {
726 [ # # ][ # # ]: 0 : m_xURLTransformer->parseStrict( aTargetURL );
727 : :
728 [ # # ]: 0 : pMenuItemDisposing->xMenuItemDispatch->removeStatusListener(
729 [ # # ][ # # ]: 0 : static_cast< XStatusListener* >( this ), aTargetURL );
730 [ # # ]: 0 : pMenuItemDisposing->xMenuItemDispatch = Reference< XDispatch >();
731 [ # # ]: 0 : if ( pMenuItemDisposing->xPopupMenu.is() )
732 : : {
733 [ # # ]: 0 : Reference< com::sun::star::lang::XEventListener > xEventListener( pMenuItemDisposing->xPopupMenuController, UNO_QUERY );
734 [ # # ]: 0 : if ( xEventListener.is() )
735 [ # # ][ # # ]: 0 : xEventListener->disposing( Source );
736 : :
737 : : {
738 : : // Remove popup menu from menu structure as we release our reference to
739 : : // the controller.
740 [ # # ]: 0 : SolarMutexGuard aGuard2;
741 [ # # ][ # # ]: 0 : m_pVCLMenu->SetPopupMenu( pMenuItemDisposing->nItemId, 0 );
742 : : }
743 : :
744 : 0 : pMenuItemDisposing->xPopupMenuController.clear();
745 : 0 : pMenuItemDisposing->xPopupMenu.clear();
746 : : }
747 : : }
748 : 91 : return;
749 : : }
750 [ + - ][ - + ]: 91 : else if ( Source.Source == m_xFrame )
751 : : {
752 : : // Our frame gets disposed. We have to remove all our listeners
753 [ # # ]: 0 : RemoveListener();
754 : : }
755 [ + - ][ + - ]: 91 : else if ( Source.Source == Reference< XInterface >( m_xDocImageManager, UNO_QUERY ))
[ - + ]
756 : 0 : m_xDocImageManager.clear();
757 [ + - ][ + - ]: 91 : else if ( Source.Source == Reference< XInterface >( m_xModuleImageManager, UNO_QUERY ))
[ + - ]
758 [ + - ][ + - ]: 91 : m_xModuleImageManager.clear();
759 : : }
760 : :
761 : :
762 : 1159 : void MenuBarManager::CheckAndAddMenuExtension( Menu* pMenu )
763 : : {
764 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::CheckAndAddMenuExtension" );
765 : :
766 : : // retrieve menu extension item
767 [ + - ]: 1159 : MenuExtensionItem aMenuItem( GetMenuExtension() );
768 [ - + # # ]: 1159 : if (( !aMenuItem.aURL.isEmpty() ) &&
[ - + ]
769 : 0 : ( !aMenuItem.aLabel.isEmpty() ))
770 : : {
771 : : // remove all old window list entries from menu
772 : 0 : sal_uInt16 nNewItemId( 0 );
773 : 0 : sal_uInt16 nInsertPos( MENU_APPEND );
774 : 0 : sal_uInt16 nBeforePos( MENU_APPEND );
775 [ # # ]: 0 : String aCommandBefore( rtl::OUString(".uno:About"));
776 [ # # ][ # # ]: 0 : for ( sal_uInt16 n = 0; n < pMenu->GetItemCount(); n++ )
777 : : {
778 [ # # ]: 0 : sal_uInt16 nItemId = pMenu->GetItemId( n );
779 [ # # ]: 0 : nNewItemId = std::max( nItemId, nNewItemId );
780 [ # # ][ # # ]: 0 : if ( pMenu->GetItemCommand( nItemId ) == aCommandBefore )
[ # # ]
781 : 0 : nBeforePos = n;
782 : : }
783 : 0 : ++nNewItemId;
784 : :
785 [ # # ]: 0 : if ( nBeforePos != MENU_APPEND )
786 : 0 : nInsertPos = nBeforePos;
787 : :
788 [ # # ][ # # ]: 0 : pMenu->InsertItem( nNewItemId, aMenuItem.aLabel, 0, nInsertPos );
[ # # ]
789 [ # # ][ # # ]: 0 : pMenu->SetItemCommand( nNewItemId, aMenuItem.aURL );
[ # # ][ # # ]
790 [ + - ]: 1159 : }
791 : 1159 : }
792 : :
793 : 11128 : static void lcl_CheckForChildren(Menu* pMenu, sal_uInt16 nItemId)
794 : : {
795 [ + + ]: 11128 : if (PopupMenu* pThisPopup = pMenu->GetPopupMenu( nItemId ))
796 : 11010 : pMenu->EnableItem( nItemId, pThisPopup->GetItemCount() ? true : false );
797 : 11128 : }
798 : :
799 : : //_________________________________________________________________________________________________________________
800 : : // vcl handler
801 : : //_________________________________________________________________________________________________________________
802 : :
803 : 36 : IMPL_LINK( MenuBarManager, Activate, Menu *, pMenu )
804 : : {
805 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::Activate" );
806 [ + - ]: 36 : if ( pMenu == m_pVCLMenu )
807 : : {
808 : : // set/unset hiding disabled menu entries
809 [ + - ][ + - ]: 36 : sal_Bool bDontHide = SvtMenuOptions().IsEntryHidingEnabled();
[ + - ]
810 [ + - ]: 36 : const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
811 [ + - ]: 36 : sal_Bool bShowMenuImages = rSettings.GetUseImagesInMenus();
812 [ + - ][ + - ]: 36 : sal_Bool bHasDisabledEntries = SvtCommandOptions().HasEntries( SvtCommandOptions::CMDOPTION_DISABLED );
[ + - ]
813 : :
814 [ + - ]: 36 : ResetableGuard aGuard( m_aLock );
815 : :
816 : 36 : sal_uInt16 nFlag = pMenu->GetMenuFlags();
817 [ + - ]: 36 : if ( bDontHide )
818 : 36 : nFlag &= ~MENU_FLAG_HIDEDISABLEDENTRIES;
819 : : else
820 : 0 : nFlag |= MENU_FLAG_HIDEDISABLEDENTRIES;
821 : 36 : pMenu->SetMenuFlags( nFlag );
822 : :
823 [ - + ]: 36 : if ( m_bActive )
824 : 0 : return 0;
825 : :
826 : 36 : m_bActive = sal_True;
827 : :
828 : 36 : ::rtl::OUString aMenuCommand( m_aMenuItemCommand );
829 [ + - ][ - + ]: 36 : if ( m_aMenuItemCommand == aSpecialWindowMenu || m_aMenuItemCommand == aSlotSpecialWindowMenu || aMenuCommand == aSpecialWindowCommand )
[ - + ][ + - ]
830 [ # # ]: 0 : MenuManager::UpdateSpecialWindowMenu( pMenu,getServiceFactory(),m_aLock );
831 : :
832 : : // Check if some modes have changed so we have to update our menu images
833 [ + - ][ + - ]: 36 : sal_Int16 nSymbolsStyle = SvtMiscOptions().GetCurrentSymbolsStyle();
[ + - ]
834 : :
835 [ + + ][ + - ]: 36 : if ( m_bRetrieveImages ||
[ - + ]
836 : : bShowMenuImages != m_bShowMenuImages ||
837 : : nSymbolsStyle != m_nSymbolsStyle )
838 : : {
839 : 6 : m_bShowMenuImages = bShowMenuImages;
840 : 6 : m_bRetrieveImages = sal_False;
841 : 6 : m_nSymbolsStyle = nSymbolsStyle;
842 [ + - ]: 6 : MenuManager::FillMenuImages( m_xFrame, pMenu, bShowMenuImages );
843 : : }
844 : :
845 : : // Try to map commands to labels
846 [ + - ][ + + ]: 632 : for ( sal_uInt16 nPos = 0; nPos < pMenu->GetItemCount(); nPos++ )
847 : : {
848 [ + - ]: 596 : sal_uInt16 nItemId = pMenu->GetItemId( nPos );
849 [ + - ]: 1724 : if (( pMenu->GetItemType( nPos ) != MENUITEM_SEPARATOR ) &&
[ + + + + ]
[ + + ]
850 [ + - ][ + + ]: 1128 : ( pMenu->GetItemText( nItemId ).Len() == 0 ))
[ + - ][ # # ]
851 : : {
852 [ + - ][ + - ]: 134 : String aCommand = pMenu->GetItemCommand( nItemId );
853 [ + - ]: 134 : if ( aCommand.Len() > 0 )
854 [ + - ][ + - ]: 134 : pMenu->SetItemText( nItemId, RetrieveLabelFromCommand( aCommand ));
[ + - ][ + - ]
855 : : }
856 : : }
857 : :
858 : : // Try to set accelerator keys
859 : : {
860 [ + - ]: 36 : RetrieveShortcuts( m_aMenuItemHandlerVector );
861 : 36 : std::vector< MenuItemHandler* >::iterator p;
862 [ + - ][ + + ]: 568 : for ( p = m_aMenuItemHandlerVector.begin(); p != m_aMenuItemHandlerVector.end(); ++p )
863 : : {
864 : 532 : MenuItemHandler* pMenuItemHandler = *p;
865 : :
866 : : // Set key code, workaround for hard-coded shortcut F1 mapped to .uno:HelpIndex
867 : : // Only non-popup menu items can have a short-cut
868 [ - + ]: 532 : if ( pMenuItemHandler->aMenuItemURL == aCmdHelpIndex )
869 : : {
870 : 0 : KeyCode aKeyCode( KEY_F1 );
871 [ # # ]: 0 : pMenu->SetAccelKey( pMenuItemHandler->nItemId, aKeyCode );
872 : : }
873 [ + - ][ + + ]: 532 : else if ( pMenu->GetPopupMenu( pMenuItemHandler->nItemId ) == 0 )
874 [ + - ]: 310 : pMenu->SetAccelKey( pMenuItemHandler->nItemId, pMenuItemHandler->aKeyCode );
875 : : }
876 : : }
877 : :
878 : 36 : URL aTargetURL;
879 : :
880 : : // Use provided dispatch provider => fallback to frame as dispatch provider
881 : 36 : Reference< XDispatchProvider > xDispatchProvider;
882 [ - + ]: 36 : if ( m_xDispatchProvider.is() )
883 [ # # ]: 0 : xDispatchProvider = m_xDispatchProvider;
884 : : else
885 [ + - ][ + - ]: 36 : xDispatchProvider = Reference< XDispatchProvider >( m_xFrame, UNO_QUERY );
886 : :
887 [ + - ]: 36 : if ( xDispatchProvider.is() )
888 : : {
889 : 36 : KeyCode aEmptyKeyCode;
890 [ + - ]: 36 : SvtCommandOptions aCmdOptions;
891 : 36 : std::vector< MenuItemHandler* >::iterator p;
892 [ + - ][ + + ]: 568 : for ( p = m_aMenuItemHandlerVector.begin(); p != m_aMenuItemHandlerVector.end(); ++p )
893 : : {
894 : 532 : MenuItemHandler* pMenuItemHandler = *p;
895 [ + - ]: 532 : if ( pMenuItemHandler )
896 : : {
897 [ + + + + ]: 862 : if ( !pMenuItemHandler->xMenuItemDispatch.is() &&
[ + + ]
898 : 330 : !pMenuItemHandler->xSubMenuManager.is() )
899 : : {
900 : : // There is no dispatch mechanism for the special window list menu items,
901 : : // because they are handled directly through XFrame->activate!!!
902 : : // Don't update dispatches for special file menu items.
903 [ - + ]: 124 : if ( !(( pMenuItemHandler->nItemId >= START_ITEMID_WINDOWLIST &&
904 [ # # ]: 0 : pMenuItemHandler->nItemId < END_ITEMID_WINDOWLIST )))
905 : : {
906 : 124 : Reference< XDispatch > xMenuItemDispatch;
907 : :
908 [ + - ][ + - ]: 124 : ::rtl::OUString aItemCommand = pMenu->GetItemCommand( pMenuItemHandler->nItemId );
909 [ - + ]: 124 : if ( aItemCommand.isEmpty() )
910 : : {
911 : 0 : aItemCommand = ::rtl::OUString( "slot:" );
912 : 0 : aItemCommand += ::rtl::OUString::valueOf( (sal_Int32)pMenuItemHandler->nItemId );
913 [ # # ][ # # ]: 0 : pMenu->SetItemCommand( pMenuItemHandler->nItemId, aItemCommand );
[ # # ]
914 : : }
915 : :
916 : 124 : aTargetURL.Complete = aItemCommand;
917 : :
918 [ + - ][ + - ]: 124 : m_xURLTransformer->parseStrict( aTargetURL );
919 : :
920 [ - + ]: 124 : if ( bHasDisabledEntries )
921 : : {
922 [ # # ][ # # ]: 0 : if ( aCmdOptions.Lookup( SvtCommandOptions::CMDOPTION_DISABLED, aTargetURL.Path ))
923 [ # # ]: 0 : pMenu->HideItem( pMenuItemHandler->nItemId );
924 : : }
925 : :
926 [ - + ]: 124 : if ( m_bIsBookmarkMenu )
927 [ # # ][ # # ]: 0 : xMenuItemDispatch = xDispatchProvider->queryDispatch( aTargetURL, pMenuItemHandler->aTargetFrame, 0 );
[ # # ]
928 : : else
929 [ + - ][ + - ]: 124 : xMenuItemDispatch = xDispatchProvider->queryDispatch( aTargetURL, ::rtl::OUString(), 0 );
[ + - ]
930 : :
931 : 124 : sal_Bool bPopupMenu( sal_False );
932 [ + - ][ + + ]: 372 : if ( !pMenuItemHandler->xPopupMenuController.is() &&
[ + + ]
933 [ + - ][ + - ]: 248 : m_xPopupMenuControllerRegistration->hasController( aItemCommand, rtl::OUString() ))
[ + - ][ # # ]
934 : : {
935 [ + - ]: 6 : bPopupMenu = CreatePopupMenuController( pMenuItemHandler );
936 : : }
937 [ - + ]: 118 : else if ( pMenuItemHandler->xPopupMenuController.is() )
938 : : {
939 : : // Force update of popup menu
940 [ # # ][ # # ]: 0 : pMenuItemHandler->xPopupMenuController->updatePopupMenu();
941 : 0 : bPopupMenu = sal_True;
942 [ # # ][ # # ]: 0 : if (PopupMenu* pThisPopup = pMenu->GetPopupMenu( pMenuItemHandler->nItemId ))
943 [ # # ][ # # ]: 0 : pMenu->EnableItem( pMenuItemHandler->nItemId, pThisPopup->GetItemCount() ? true : false );
944 : : }
945 : :
946 [ + - ]: 124 : lcl_CheckForChildren(pMenu, pMenuItemHandler->nItemId);
947 : :
948 [ + - ]: 124 : if ( xMenuItemDispatch.is() )
949 : : {
950 [ + - ]: 124 : pMenuItemHandler->xMenuItemDispatch = xMenuItemDispatch;
951 : 124 : pMenuItemHandler->aMenuItemURL = aTargetURL.Complete;
952 : :
953 [ + + ]: 124 : if ( !bPopupMenu )
954 : : {
955 : : // We need only an update to reflect the current state
956 [ + - ][ + - ]: 118 : xMenuItemDispatch->addStatusListener( static_cast< XStatusListener* >( this ), aTargetURL );
[ + - ]
957 [ + - ][ + - ]: 118 : xMenuItemDispatch->removeStatusListener( static_cast< XStatusListener* >( this ), aTargetURL );
[ + - ]
958 : : }
959 : : }
960 [ # # ]: 0 : else if ( !bPopupMenu )
961 [ # # ]: 124 : pMenu->EnableItem( pMenuItemHandler->nItemId, sal_False );
962 : : }
963 : : }
964 [ + + ]: 408 : else if ( pMenuItemHandler->xPopupMenuController.is() )
965 : : {
966 : : // Force update of popup menu
967 [ + - ][ + - ]: 10 : pMenuItemHandler->xPopupMenuController->updatePopupMenu();
968 [ + - ]: 10 : lcl_CheckForChildren(pMenu, pMenuItemHandler->nItemId);
969 : : }
970 [ + + ]: 398 : else if ( pMenuItemHandler->xMenuItemDispatch.is() )
971 : : {
972 : : // We need an update to reflect the current state
973 : : try
974 : : {
975 : 192 : aTargetURL.Complete = pMenuItemHandler->aMenuItemURL;
976 [ + - ][ + - ]: 192 : m_xURLTransformer->parseStrict( aTargetURL );
977 : :
978 [ + - ]: 192 : pMenuItemHandler->xMenuItemDispatch->addStatusListener(
979 [ + - ][ + - ]: 192 : static_cast< XStatusListener* >( this ), aTargetURL );
980 [ + - ]: 192 : pMenuItemHandler->xMenuItemDispatch->removeStatusListener(
981 [ + - ][ + - ]: 192 : static_cast< XStatusListener* >( this ), aTargetURL );
[ # # ]
982 : : }
983 [ # # ]: 0 : catch ( const Exception& )
984 : : {
985 : : }
986 : : }
987 [ + - ]: 206 : else if ( pMenuItemHandler->xSubMenuManager.is() )
988 [ + - ]: 206 : lcl_CheckForChildren(pMenu, pMenuItemHandler->nItemId);
989 : : }
990 [ + - ]: 36 : }
991 [ + - ][ + - ]: 36 : }
992 : : }
993 : :
994 : 36 : return 1;
995 : : }
996 : :
997 : :
998 : 48 : IMPL_LINK( MenuBarManager, Deactivate, Menu *, pMenu )
999 : : {
1000 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::Deactivate" );
1001 [ + - ]: 48 : if ( pMenu == m_pVCLMenu )
1002 : : {
1003 : 48 : m_bActive = sal_False;
1004 [ + + ][ - + ]: 48 : if ( pMenu->IsMenuBar() && m_xDeferedItemContainer.is() )
[ - + ]
1005 : : {
1006 : : // Start timer to handle settings asynchronous
1007 : : // Changing the menu inside this handler leads to
1008 : : // a crash under X!
1009 : 0 : m_aAsyncSettingsTimer.SetTimeoutHdl(LINK(this, MenuBarManager, AsyncSettingsHdl));
1010 : 0 : m_aAsyncSettingsTimer.SetTimeout(10);
1011 : 0 : m_aAsyncSettingsTimer.Start();
1012 : : }
1013 : : }
1014 : :
1015 : 48 : return 1;
1016 : : }
1017 : :
1018 : 0 : IMPL_LINK( MenuBarManager, AsyncSettingsHdl, Timer*,)
1019 : : {
1020 [ # # ]: 0 : SolarMutexGuard aGuard;
1021 : : Reference< XInterface > xSelfHold(
1022 [ # # ]: 0 : static_cast< ::cppu::OWeakObject* >( this ), UNO_QUERY_THROW );
1023 : :
1024 [ # # ]: 0 : m_aAsyncSettingsTimer.Stop();
1025 [ # # ][ # # ]: 0 : if ( !m_bActive && m_xDeferedItemContainer.is() )
[ # # ]
1026 : : {
1027 [ # # ]: 0 : SetItemContainer( m_xDeferedItemContainer );
1028 : 0 : m_xDeferedItemContainer.clear();
1029 : : }
1030 : :
1031 [ # # ]: 0 : return 0;
1032 : : }
1033 : :
1034 : 0 : IMPL_LINK( MenuBarManager, Select, Menu *, pMenu )
1035 : : {
1036 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::Select" );
1037 : 0 : URL aTargetURL;
1038 [ # # ]: 0 : Sequence<PropertyValue> aArgs;
1039 : 0 : Reference< XDispatch > xDispatch;
1040 : :
1041 : : {
1042 [ # # ]: 0 : ResetableGuard aGuard( m_aLock );
1043 : :
1044 [ # # ]: 0 : sal_uInt16 nCurItemId = pMenu->GetCurItemId();
1045 [ # # ]: 0 : sal_uInt16 nCurPos = pMenu->GetItemPos( nCurItemId );
1046 [ # # ][ # # ]: 0 : if ( pMenu == m_pVCLMenu &&
[ # # ]
1047 [ # # ]: 0 : pMenu->GetItemType( nCurPos ) != MENUITEM_SEPARATOR )
1048 : : {
1049 [ # # ][ # # ]: 0 : if ( nCurItemId >= START_ITEMID_WINDOWLIST &&
1050 : : nCurItemId <= END_ITEMID_WINDOWLIST )
1051 : : {
1052 : : // window list menu item selected
1053 : :
1054 [ # # ][ # # ]: 0 : Reference< XFramesSupplier > xDesktop( getServiceFactory()->createInstance( SERVICENAME_DESKTOP ), UNO_QUERY );
[ # # ][ # # ]
1055 : :
1056 [ # # ]: 0 : if ( xDesktop.is() )
1057 : : {
1058 : 0 : sal_uInt16 nTaskId = START_ITEMID_WINDOWLIST;
1059 [ # # ][ # # ]: 0 : Reference< XIndexAccess > xList( xDesktop->getFrames(), UNO_QUERY );
[ # # ]
1060 [ # # ][ # # ]: 0 : sal_Int32 nCount = xList->getCount();
1061 [ # # ]: 0 : for ( sal_Int32 i=0; i<nCount; ++i )
1062 : : {
1063 : 0 : Reference< XFrame > xFrame;
1064 [ # # ][ # # ]: 0 : xList->getByIndex(i) >>= xFrame;
[ # # ]
1065 [ # # ][ # # ]: 0 : if ( xFrame.is() && nTaskId == nCurItemId )
[ # # ]
1066 : : {
1067 [ # # ][ # # ]: 0 : Window* pWin = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
[ # # ]
1068 [ # # ]: 0 : pWin->GrabFocus();
1069 [ # # ]: 0 : pWin->ToTop( TOTOP_RESTOREWHENMIN );
1070 : : break;
1071 : : }
1072 : :
1073 [ # # ]: 0 : nTaskId++;
1074 : 0 : }
1075 : 0 : }
1076 : : }
1077 : : else
1078 : : {
1079 [ # # ]: 0 : MenuItemHandler* pMenuItemHandler = GetMenuItemHandler( nCurItemId );
1080 [ # # ][ # # ]: 0 : if ( pMenuItemHandler && pMenuItemHandler->xMenuItemDispatch.is() )
[ # # ]
1081 : : {
1082 : 0 : aTargetURL.Complete = pMenuItemHandler->aMenuItemURL;
1083 [ # # ][ # # ]: 0 : m_xURLTransformer->parseStrict( aTargetURL );
1084 : :
1085 [ # # ]: 0 : if ( m_bIsBookmarkMenu )
1086 : : {
1087 : : // bookmark menu item selected
1088 [ # # ]: 0 : aArgs.realloc( 1 );
1089 [ # # ]: 0 : aArgs[0].Name = ::rtl::OUString( "Referer" );
1090 [ # # ][ # # ]: 0 : aArgs[0].Value <<= ::rtl::OUString( SFX_REFERER_USER );
1091 : : }
1092 : :
1093 [ # # ]: 0 : xDispatch = pMenuItemHandler->xMenuItemDispatch;
1094 : : }
1095 : : }
1096 [ # # ]: 0 : }
1097 : : }
1098 : :
1099 [ # # ]: 0 : if ( xDispatch.is() )
1100 : : {
1101 [ # # ]: 0 : const sal_uInt32 nRef = Application::ReleaseSolarMutex();
1102 [ # # ][ # # ]: 0 : xDispatch->dispatch( aTargetURL, aArgs );
1103 [ # # ]: 0 : Application::AcquireSolarMutex( nRef );
1104 : : }
1105 : :
1106 [ # # ]: 0 : return 1;
1107 : : }
1108 : :
1109 : :
1110 : 52 : IMPL_LINK_NOARG(MenuBarManager, Highlight)
1111 : : {
1112 : 52 : return 0;
1113 : : }
1114 : :
1115 : 0 : sal_Bool MenuBarManager::MustBeHidden( PopupMenu* pPopupMenu, const Reference< XURLTransformer >& rTransformer )
1116 : : {
1117 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::MustBeHidden" );
1118 [ # # ]: 0 : if ( pPopupMenu )
1119 : : {
1120 : 0 : URL aTargetURL;
1121 [ # # ]: 0 : SvtCommandOptions aCmdOptions;
1122 : :
1123 [ # # ]: 0 : sal_uInt16 nCount = pPopupMenu->GetItemCount();
1124 : 0 : sal_uInt16 nHideCount( 0 );
1125 : :
1126 [ # # ]: 0 : for ( sal_uInt16 i = 0; i < nCount; i++ )
1127 : : {
1128 [ # # ]: 0 : sal_uInt16 nId = pPopupMenu->GetItemId( i );
1129 [ # # ]: 0 : if ( nId > 0 )
1130 : : {
1131 [ # # ]: 0 : PopupMenu* pSubPopupMenu = pPopupMenu->GetPopupMenu( nId );
1132 [ # # ]: 0 : if ( pSubPopupMenu )
1133 : : {
1134 [ # # ][ # # ]: 0 : if ( MustBeHidden( pSubPopupMenu, rTransformer ))
1135 : : {
1136 [ # # ]: 0 : pPopupMenu->HideItem( nId );
1137 : 0 : ++nHideCount;
1138 : : }
1139 : : }
1140 : : else
1141 : : {
1142 [ # # ][ # # ]: 0 : aTargetURL.Complete = pPopupMenu->GetItemCommand( nId );
1143 [ # # ][ # # ]: 0 : rTransformer->parseStrict( aTargetURL );
1144 : :
1145 [ # # ][ # # ]: 0 : if ( aCmdOptions.Lookup( SvtCommandOptions::CMDOPTION_DISABLED, aTargetURL.Path ))
1146 : 0 : ++nHideCount;
1147 : : }
1148 : : }
1149 : : else
1150 : 0 : ++nHideCount;
1151 : : }
1152 : :
1153 [ # # ]: 0 : return ( nCount == nHideCount );
1154 : : }
1155 : :
1156 : 0 : return sal_True;
1157 : : }
1158 : 10489 : String MenuBarManager::RetrieveLabelFromCommand( const String& aCmdURL )
1159 : : {
1160 [ + - ][ + - ]: 10489 : return framework::RetrieveLabelFromCommand(aCmdURL,mxServiceFactory,m_xUICommandLabels,m_xFrame,m_aModuleIdentifier,m_bModuleIdentified,"Label");
1161 : : }
1162 : :
1163 : :
1164 : :
1165 : 6 : sal_Bool MenuBarManager::CreatePopupMenuController( MenuItemHandler* pMenuItemHandler )
1166 : : {
1167 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::CreatePopupMenuController" );
1168 : 6 : rtl::OUString aItemCommand( pMenuItemHandler->aMenuItemURL );
1169 : :
1170 : : // Try instanciate a popup menu controller. It is stored in the menu item handler.
1171 [ + - ]: 6 : Reference< XMultiComponentFactory > xPopupMenuControllerFactory( m_xPopupMenuControllerRegistration, UNO_QUERY );
1172 [ + - ]: 6 : if ( xPopupMenuControllerFactory.is() )
1173 : : {
1174 [ + - ]: 6 : Sequence< Any > aSeq( 2 );
1175 : 6 : PropertyValue aPropValue;
1176 : :
1177 : 6 : aPropValue.Name = rtl::OUString( "ModuleName" );
1178 [ + - ]: 6 : aPropValue.Value <<= m_aModuleIdentifier;
1179 [ + - ][ + - ]: 6 : aSeq[0] <<= aPropValue;
1180 : 6 : aPropValue.Name = rtl::OUString( "Frame" );
1181 [ + - ]: 6 : aPropValue.Value <<= m_xFrame;
1182 [ + - ][ + - ]: 6 : aSeq[1] <<= aPropValue;
1183 : :
1184 : 6 : Reference< XComponentContext > xComponentContext;
1185 [ + - ]: 6 : Reference< XPropertySet > xProps( getServiceFactory(), UNO_QUERY );
1186 : :
1187 [ + - ]: 6 : xProps->getPropertyValue( rtl::OUString( "DefaultContext" )) >>=
1188 [ + - ][ + - ]: 6 : xComponentContext;
1189 : :
1190 : : Reference< XPopupMenuController > xPopupMenuController(
1191 [ + - ]: 6 : xPopupMenuControllerFactory->createInstanceWithArgumentsAndContext(
1192 : : aItemCommand,
1193 : : aSeq,
1194 : 6 : xComponentContext ),
1195 [ + - ][ + - ]: 6 : UNO_QUERY );
1196 : :
1197 [ + - ]: 6 : if ( xPopupMenuController.is() )
1198 : : {
1199 : : // Provide our awt popup menu to the popup menu controller
1200 [ + - ]: 6 : pMenuItemHandler->xPopupMenuController = xPopupMenuController;
1201 [ + - ][ + - ]: 6 : xPopupMenuController->setPopupMenu( pMenuItemHandler->xPopupMenu );
1202 : 6 : return sal_True;
1203 [ + - ][ + - ]: 6 : }
[ + - ][ + - ]
[ + - ][ - + ]
1204 : : }
1205 : :
1206 : 6 : return sal_False;
1207 : : }
1208 : :
1209 : 43401 : void MenuBarManager::FillMenuManager( Menu* pMenu, const Reference< XFrame >& rFrame, const Reference< XDispatchProvider >& rDispatchProvider, const rtl::OUString& rModuleIdentifier, sal_Bool bDelete, sal_Bool bDeleteChildren )
1210 : : {
1211 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::FillMenuManager" );
1212 [ + - ]: 43401 : m_xFrame = rFrame;
1213 : 43401 : m_bActive = sal_False;
1214 : 43401 : m_bDeleteMenu = bDelete;
1215 : 43401 : m_bDeleteChildren = bDeleteChildren;
1216 : 43401 : m_pVCLMenu = pMenu;
1217 : 43401 : m_bInitialized = sal_False;
1218 : 43401 : m_bIsBookmarkMenu = sal_False;
1219 [ + - ]: 43401 : m_xDispatchProvider = rDispatchProvider;
1220 : :
1221 [ + - ]: 43401 : const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
1222 [ + - ]: 43401 : m_bShowMenuImages = rSettings.GetUseImagesInMenus();
1223 : 43401 : m_bRetrieveImages = sal_False;
1224 : :
1225 [ + - ]: 43401 : sal_Int32 nAddonsURLPrefixLength = ADDONSPOPUPMENU_URL_PREFIX.getLength();
1226 : :
1227 : : // Add root as ui configuration listener
1228 [ + - ]: 43401 : RetrieveImageManagers();
1229 : :
1230 [ + + ][ + - ]: 43401 : if ( pMenu->IsMenuBar() && rFrame.is() )
[ + + ]
1231 : : {
1232 : : // First merge all addon popup menus into our structure
1233 : 1725 : sal_uInt16 nPos = 0;
1234 [ + - ][ + + ]: 10921 : for ( nPos = 0; nPos < pMenu->GetItemCount(); nPos++ )
1235 : : {
1236 [ + - ]: 9196 : sal_uInt16 nItemId = pMenu->GetItemId( nPos );
1237 [ + - ][ + - ]: 9196 : ::rtl::OUString aCommand = pMenu->GetItemCommand( nItemId );
1238 [ + - ][ + + ]: 9196 : if ( nItemId == SID_MDIWINDOWLIST || aCommand == aSpecialWindowCommand)
[ + + ]
1239 : : {
1240 : : // Retrieve addon popup menus and add them to our menu bar
1241 : 1159 : Reference< com::sun::star::frame::XModel > xModel;
1242 [ + - ][ + - ]: 1159 : Reference< com::sun::star::frame::XController > xController( rFrame->getController(), UNO_QUERY );
[ + - ]
1243 [ + - ]: 1159 : if ( xController.is() )
1244 [ + - ][ + - ]: 1159 : xModel = Reference< com::sun::star::frame::XModel >( xController->getModel(), UNO_QUERY );
[ + - ][ + - ]
1245 [ + - ]: 1159 : framework::AddonMenuManager::MergeAddonPopupMenus( rFrame, xModel, nPos, (MenuBar *)pMenu );
1246 : 9196 : break;
1247 : : }
1248 [ + + ]: 9196 : }
1249 : :
1250 : : // Merge the Add-Ons help menu items into the Office help menu
1251 [ + - ]: 1725 : framework::AddonMenuManager::MergeAddonHelpMenu( rFrame, (MenuBar *)pMenu );
1252 : : }
1253 : :
1254 [ + - ]: 43401 : String aEmpty;
1255 [ + - ][ + - ]: 43401 : sal_Bool bAccessibilityEnabled( Application::GetSettings().GetMiscSettings().GetEnableATToolSupport() );
1256 [ + - ]: 43401 : sal_uInt16 nItemCount = pMenu->GetItemCount();
1257 : 43401 : ::rtl::OUString aItemCommand;
1258 [ + - ]: 43401 : m_aMenuItemHandlerVector.reserve(nItemCount);
1259 [ + + ]: 436094 : for ( sal_uInt16 i = 0; i < nItemCount; i++ )
1260 : : {
1261 [ + - ]: 392693 : sal_uInt16 nItemId = FillItemCommand(aItemCommand,pMenu, i );
1262 : :
1263 : : // Set module identifier when provided from outside
1264 [ + - ]: 392693 : if ( !rModuleIdentifier.isEmpty() )
1265 : : {
1266 : 392693 : m_aModuleIdentifier = rModuleIdentifier;
1267 : 392693 : m_bModuleIdentified = sal_True;
1268 : : }
1269 : :
1270 [ + + ]: 795747 : if (( pMenu->IsMenuBar() || bAccessibilityEnabled ) &&
[ - + + + ]
[ + + ]
1271 [ + - ][ + + ]: 403054 : ( pMenu->GetItemText( nItemId ).Len() == 0 ))
[ + - ][ # # ]
1272 : : {
1273 [ + - ]: 10355 : if ( !aItemCommand.isEmpty() )
1274 [ + - ][ + - ]: 10355 : pMenu->SetItemText( nItemId, RetrieveLabelFromCommand( aItemCommand ));
[ + - ][ + - ]
[ + - ]
1275 : : }
1276 : :
1277 : 392693 : Reference< XDispatch > xDispatch;
1278 : 392693 : Reference< XStatusListener > xStatusListener;
1279 [ + - ]: 392693 : PopupMenu* pPopup = pMenu->GetPopupMenu( nItemId );
1280 : 392693 : bool bItemShowMenuImages = m_bShowMenuImages;
1281 : : // overwrite the show icons on menu option?
1282 [ - + ]: 392693 : if (!bItemShowMenuImages)
1283 : : {
1284 [ # # ]: 0 : MenuItemBits nBits = pMenu->GetItemBits( nItemId );
1285 : 0 : bItemShowMenuImages = ( ( nBits & MIB_ICON ) == MIB_ICON );
1286 : : }
1287 [ + + ]: 392693 : if ( pPopup )
1288 : : {
1289 : : // Retrieve module identifier from Help Command entry
1290 : 42835 : rtl::OUString aModuleIdentifier( rModuleIdentifier );
1291 [ + - ][ + - ]: 42835 : if ( pMenu->GetHelpCommand( nItemId ).Len() > 0 )
1292 : : {
1293 [ + - ][ + - ]: 42835 : aModuleIdentifier = pMenu->GetHelpCommand( nItemId );
1294 [ + - ]: 42835 : pMenu->SetHelpCommand( nItemId, aEmpty );
1295 : : }
1296 : :
1297 [ + - ][ + + ]: 129664 : if ( m_xPopupMenuControllerRegistration.is() &&
[ + - ][ + + ]
1298 [ + - ]: 42835 : pPopup->GetItemCount() == 0 &&
1299 [ + - ][ + - ]: 43994 : m_xPopupMenuControllerRegistration->hasController( aItemCommand, rtl::OUString() )
[ + + ][ # # ]
1300 : : )
1301 : : {
1302 : : // Check if we have to create a popup menu for a uno based popup menu controller.
1303 : : // We have to set an empty popup menu into our menu structure so the controller also
1304 : : // works with inplace OLE. Remove old dummy popup menu!
1305 [ + - ][ + - ]: 1159 : MenuItemHandler* pItemHandler = new MenuItemHandler( nItemId, xStatusListener, xDispatch );
1306 [ + - ]: 1159 : VCLXPopupMenu* pVCLXPopupMenu = new VCLXPopupMenu;
1307 : 1159 : PopupMenu* pNewPopupMenu = (PopupMenu *)pVCLXPopupMenu->GetMenu();
1308 [ + - ]: 1159 : pMenu->SetPopupMenu( nItemId, pNewPopupMenu );
1309 [ + - ][ + - ]: 1159 : pItemHandler->xPopupMenu = Reference< com::sun::star::awt::XPopupMenu >( (OWeakObject *)pVCLXPopupMenu, UNO_QUERY );
[ + - ]
1310 : 1159 : pItemHandler->aMenuItemURL = aItemCommand;
1311 [ + - ]: 1159 : m_aMenuItemHandlerVector.push_back( pItemHandler );
1312 [ + - ][ + - ]: 1159 : delete pPopup;
1313 : :
1314 [ - + ]: 1159 : if ( bAccessibilityEnabled )
1315 : : {
1316 [ # # ][ # # ]: 0 : if ( CreatePopupMenuController( pItemHandler ))
1317 [ # # ][ # # ]: 0 : pItemHandler->xPopupMenuController->updatePopupMenu();
1318 : : }
1319 [ + - ]: 1159 : lcl_CheckForChildren(pMenu, nItemId);
1320 : : }
1321 [ + + - + ]: 92699 : else if (( aItemCommand.getLength() > nAddonsURLPrefixLength ) &&
[ - + ]
1322 [ + - ][ + + ]: 51023 : ( aItemCommand.indexOf( ADDONSPOPUPMENU_URL_PREFIX ) == 0 ))
[ # # ]
1323 : : {
1324 : : // A special addon popup menu, must be created with a different ctor
1325 [ # # ]: 0 : MenuBarManager* pSubMenuManager = new MenuBarManager( getServiceFactory(), m_xFrame, m_xURLTransformer,(AddonPopupMenu *)pPopup, bDeleteChildren, bDeleteChildren );
1326 [ # # ]: 0 : AddMenu(pSubMenuManager,aItemCommand,nItemId);
1327 : : }
1328 : : else
1329 : : {
1330 : 41676 : Reference< XDispatchProvider > xPopupMenuDispatchProvider( rDispatchProvider );
1331 : :
1332 : : // Retrieve possible attributes struct
1333 [ + - ]: 41676 : MenuConfiguration::Attributes* pAttributes = (MenuConfiguration::Attributes *)(pMenu->GetUserValue( nItemId ));
1334 [ + + ]: 41676 : if ( pAttributes )
1335 [ + - ][ + - ]: 30 : xPopupMenuDispatchProvider = pAttributes->xDispatchProvider;
1336 : :
1337 : : // Check if this is the help menu. Add menu item if needed
1338 [ + - ][ + - ]: 41676 : if ( nItemId == SID_HELPMENU || aItemCommand == aSlotHelpMenu || aItemCommand == aCmdHelpMenu )
[ + + ][ + + ]
1339 : : {
1340 : : // Check if this is the help menu. Add menu item if needed
1341 [ + - ]: 1159 : CheckAndAddMenuExtension( pPopup );
1342 : : }
1343 [ + - ][ + - ]: 41676 : else if (( nItemId == SID_ADDONLIST || aItemCommand == aSlotSpecialToolsMenu || aItemCommand == aCmdToolsMenu ) &&
[ + + ][ - + ]
[ - + ]
1344 [ + - ]: 1159 : AddonMenuManager::HasAddonMenuElements() )
1345 : : {
1346 : : // Create addon popup menu if there exist elements and this is the tools popup menu
1347 [ # # ]: 0 : AddonMenu* pSubMenu = AddonMenuManager::CreateAddonMenu( rFrame );
1348 [ # # ][ # # ]: 0 : if ( pSubMenu && ( pSubMenu->GetItemCount() > 0 ))
[ # # ][ # # ]
1349 : : {
1350 : 0 : sal_uInt16 nCount = 0;
1351 [ # # ][ # # ]: 0 : if ( pPopup->GetItemType( nCount-1 ) != MENUITEM_SEPARATOR )
1352 [ # # ]: 0 : pPopup->InsertSeparator();
1353 : :
1354 : : // Use resource to load popup menu title
1355 [ # # ][ # # ]: 0 : String aAddonsStrRes = String( FwkResId( STR_MENU_ADDONS ));
1356 [ # # ]: 0 : pPopup->InsertItem( ITEMID_ADDONLIST, aAddonsStrRes );
1357 [ # # ]: 0 : pPopup->SetPopupMenu( ITEMID_ADDONLIST, pSubMenu );
1358 : :
1359 : : // Set item command for popup menu to enable it for GetImageFromURL
1360 : 0 : const ::rtl::OUString aSlotString( "slot:" );
1361 : 0 : ::rtl::OUString aNewItemCommand( aSlotString );
1362 : 0 : aNewItemCommand += ::rtl::OUString::valueOf( (sal_Int32)ITEMID_ADDONLIST );
1363 [ # # ][ # # ]: 0 : pPopup->SetItemCommand( ITEMID_ADDONLIST, aNewItemCommand );
[ # # ][ # # ]
1364 : : }
1365 : : else
1366 [ # # ][ # # ]: 0 : delete pSubMenu;
1367 : : }
1368 : :
1369 [ - + ]: 41676 : if ( nItemId == ITEMID_ADDONLIST )
1370 : : {
1371 [ # # ]: 0 : AddonMenu* pSubMenu = dynamic_cast< AddonMenu* >( pPopup );
1372 [ # # ]: 0 : if ( pSubMenu )
1373 : : {
1374 [ # # ]: 0 : MenuBarManager* pSubMenuManager = new MenuBarManager( getServiceFactory(), m_xFrame, m_xURLTransformer,pSubMenu, sal_True, sal_False );
1375 [ # # ]: 0 : AddMenu(pSubMenuManager,aItemCommand,nItemId);
1376 : 0 : pSubMenuManager->m_aMenuItemCommand = ::rtl::OUString();
1377 : :
1378 : : // Set image for the addon popup menu item
1379 [ # # ][ # # ]: 0 : if ( bItemShowMenuImages && !pPopup->GetItemImage( ITEMID_ADDONLIST ))
[ # # ][ # # ]
[ # # # # ]
[ # # ]
1380 : : {
1381 : 0 : Reference< XFrame > xTemp( rFrame );
1382 [ # # ]: 0 : Image aImage = GetImageFromURL( xTemp, aItemCommand, false );
1383 [ # # ]: 0 : if ( !!aImage )
1384 [ # # ][ # # ]: 0 : pPopup->SetItemImage( ITEMID_ADDONLIST, aImage );
1385 : : }
1386 : : }
1387 : : }
1388 : : else
1389 : : {
1390 [ + - ]: 41676 : MenuBarManager* pSubMenuMgr = new MenuBarManager( getServiceFactory(), rFrame, m_xURLTransformer,rDispatchProvider, aModuleIdentifier, pPopup, bDeleteChildren, bDeleteChildren );
1391 [ + - ]: 41676 : AddMenu(pSubMenuMgr,aItemCommand,nItemId);
1392 : 41676 : }
1393 : 42835 : }
1394 : : }
1395 [ + - ][ + + ]: 349858 : else if ( pMenu->GetItemType( i ) != MENUITEM_SEPARATOR )
1396 : : {
1397 [ + - ]: 291413 : if ( bItemShowMenuImages )
1398 : : {
1399 [ - + ]: 291413 : if ( AddonMenuManager::IsAddonMenuId( nItemId ))
1400 : : {
1401 : : // Add-Ons uses images from different places
1402 [ # # ]: 0 : Image aImage;
1403 : 0 : rtl::OUString aImageId;
1404 : :
1405 : : MenuConfiguration::Attributes* pMenuAttributes =
1406 [ # # ]: 0 : (MenuConfiguration::Attributes*)pMenu->GetUserValue( nItemId );
1407 : :
1408 [ # # ][ # # ]: 0 : if ( pMenuAttributes && !pMenuAttributes->aImageId.isEmpty() )
[ # # ]
1409 : : {
1410 : : // Retrieve image id from menu attributes
1411 [ # # ][ # # ]: 0 : aImage = GetImageFromURL( m_xFrame, aImageId, false );
[ # # ]
1412 : : }
1413 : :
1414 [ # # ]: 0 : if ( !aImage )
1415 : : {
1416 [ # # ][ # # ]: 0 : aImage = GetImageFromURL( m_xFrame, aItemCommand, false );
[ # # ]
1417 [ # # ]: 0 : if ( !aImage )
1418 [ # # ][ # # ]: 0 : aImage = AddonsOptions().GetImageFromURL( aItemCommand, false );
[ # # ][ # # ]
[ # # ]
1419 : : }
1420 : :
1421 [ # # ]: 0 : if ( !!aImage )
1422 [ # # ]: 0 : pMenu->SetItemImage( nItemId, aImage );
1423 : : else
1424 [ # # ]: 0 : m_bRetrieveImages = sal_True;
1425 : : }
1426 : 291413 : m_bRetrieveImages = sal_True;
1427 : : }
1428 : :
1429 [ + - ][ + - ]: 291413 : MenuItemHandler* pItemHandler = new MenuItemHandler( nItemId, xStatusListener, xDispatch );
1430 : 291413 : pItemHandler->aMenuItemURL = aItemCommand;
1431 : :
1432 [ + + ][ + + ]: 874239 : if ( m_xPopupMenuControllerRegistration.is() &&
[ + - ]
1433 [ + - ][ + - ]: 582826 : m_xPopupMenuControllerRegistration->hasController( aItemCommand, rtl::OUString() ))
[ + - ][ # # ]
1434 : : {
1435 : : // Check if we have to create a popup menu for a uno based popup menu controller.
1436 : : // We have to set an empty popup menu into our menu structure so the controller also
1437 : : // works with inplace OLE.
1438 [ + - ]: 9629 : VCLXPopupMenu* pVCLXPopupMenu = new VCLXPopupMenu;
1439 : 9629 : PopupMenu* pPopupMenu = (PopupMenu *)pVCLXPopupMenu->GetMenu();
1440 [ + - ]: 9629 : pMenu->SetPopupMenu( pItemHandler->nItemId, pPopupMenu );
1441 [ + - ][ + - ]: 9629 : pItemHandler->xPopupMenu = Reference< com::sun::star::awt::XPopupMenu >( (OWeakObject *)pVCLXPopupMenu, UNO_QUERY );
[ + - ]
1442 : :
1443 [ # # ][ # # ]: 9629 : if ( bAccessibilityEnabled && CreatePopupMenuController( pItemHandler ) )
[ - + ][ - + ]
1444 : : {
1445 [ # # ][ # # ]: 0 : pItemHandler->xPopupMenuController->updatePopupMenu();
1446 : : }
1447 : :
1448 [ + - ]: 9629 : lcl_CheckForChildren(pMenu, pItemHandler->nItemId);
1449 : : }
1450 : :
1451 [ + - ]: 291413 : m_aMenuItemHandlerVector.push_back( pItemHandler );
1452 : : }
1453 : 392693 : }
1454 : :
1455 [ - + ]: 43401 : if ( bAccessibilityEnabled )
1456 : : {
1457 [ # # ]: 0 : RetrieveShortcuts( m_aMenuItemHandlerVector );
1458 : 0 : std::vector< MenuItemHandler* >::iterator p;
1459 [ # # ][ # # ]: 0 : for ( p = m_aMenuItemHandlerVector.begin(); p != m_aMenuItemHandlerVector.end(); ++p )
1460 : : {
1461 : 0 : MenuItemHandler* pMenuItemHandler = *p;
1462 : :
1463 : : // Set key code, workaround for hard-coded shortcut F1 mapped to .uno:HelpIndex
1464 : : // Only non-popup menu items can have a short-cut
1465 [ # # ]: 0 : if ( pMenuItemHandler->aMenuItemURL == aCmdHelpIndex )
1466 : : {
1467 : 0 : KeyCode aKeyCode( KEY_F1 );
1468 [ # # ]: 0 : pMenu->SetAccelKey( pMenuItemHandler->nItemId, aKeyCode );
1469 : : }
1470 [ # # ][ # # ]: 0 : else if ( pMenu->GetPopupMenu( pMenuItemHandler->nItemId ) == 0 )
1471 [ # # ]: 0 : pMenu->SetAccelKey( pMenuItemHandler->nItemId, pMenuItemHandler->aKeyCode );
1472 : : }
1473 : : }
1474 : :
1475 [ + - ][ + - ]: 43401 : SetHdl();
1476 : 43401 : }
1477 : :
1478 : 108 : void MenuBarManager::impl_RetrieveShortcutsFromConfiguration(
1479 : : const Reference< XAcceleratorConfiguration >& rAccelCfg,
1480 : : const Sequence< rtl::OUString >& rCommands,
1481 : : std::vector< MenuItemHandler* >& aMenuShortCuts )
1482 : : {
1483 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::impl_RetrieveShortcutsFromConfiguration" );
1484 [ + - ]: 108 : if ( rAccelCfg.is() )
1485 : : {
1486 : : try
1487 : : {
1488 [ + - ]: 108 : com::sun::star::awt::KeyEvent aKeyEvent;
1489 [ + - ][ + - ]: 108 : Sequence< Any > aSeqKeyCode = rAccelCfg->getPreferredKeyEventsForCommandList( rCommands );
1490 [ + + ]: 1704 : for ( sal_Int32 i = 0; i < aSeqKeyCode.getLength(); i++ )
1491 : : {
1492 [ + - ][ + - ]: 1596 : if ( aSeqKeyCode[i] >>= aKeyEvent )
[ - + ]
1493 [ # # ][ # # ]: 0 : aMenuShortCuts[i]->aKeyCode = svt::AcceleratorExecute::st_AWTKey2VCLKey( aKeyEvent );
1494 [ + - ][ + - ]: 108 : }
[ # # ]
1495 : : }
1496 : 0 : catch ( const IllegalArgumentException& )
1497 : : {
1498 : : }
1499 : : }
1500 : 108 : }
1501 : :
1502 : 36 : void MenuBarManager::RetrieveShortcuts( std::vector< MenuItemHandler* >& aMenuShortCuts )
1503 : : {
1504 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::RetrieveShortcuts" );
1505 [ - + ]: 36 : if ( !m_bModuleIdentified )
1506 : : {
1507 : 0 : m_bModuleIdentified = sal_True;
1508 : 0 : Reference< XModuleManager > xModuleManager;
1509 [ # # ][ # # ]: 0 : xModuleManager = Reference< XModuleManager >( getServiceFactory()->createInstance( SERVICENAME_MODULEMANAGER ), UNO_QUERY_THROW );
[ # # ][ # # ]
[ # # ][ # # ]
1510 : :
1511 : : try
1512 : : {
1513 [ # # ][ # # ]: 0 : m_aModuleIdentifier = xModuleManager->identify( m_xFrame );
1514 : : }
1515 [ # # ]: 0 : catch( const Exception& )
1516 : : {
1517 : 0 : }
1518 : : }
1519 : :
1520 [ + - ]: 36 : if ( m_bModuleIdentified )
1521 : : {
1522 : 36 : Reference< XAcceleratorConfiguration > xDocAccelCfg( m_xDocAcceleratorManager );
1523 : 36 : Reference< XAcceleratorConfiguration > xModuleAccelCfg( m_xModuleAcceleratorManager );
1524 : 36 : Reference< XAcceleratorConfiguration > xGlobalAccelCfg( m_xGlobalAcceleratorManager );
1525 : :
1526 [ + + ]: 36 : if ( !m_bAcceleratorCfg )
1527 : : {
1528 : : // Retrieve references on demand
1529 : 10 : m_bAcceleratorCfg = sal_True;
1530 [ + - ]: 10 : if ( !xDocAccelCfg.is() )
1531 : : {
1532 [ + - ][ + - ]: 10 : Reference< XController > xController = m_xFrame->getController();
1533 : 10 : Reference< XModel > xModel;
1534 [ + - ]: 10 : if ( xController.is() )
1535 : : {
1536 [ + - ][ + - ]: 10 : xModel = xController->getModel();
[ + - ]
1537 [ + - ]: 10 : if ( xModel.is() )
1538 : : {
1539 [ + - ]: 10 : Reference< XUIConfigurationManagerSupplier > xSupplier( xModel, UNO_QUERY );
1540 [ + - ]: 10 : if ( xSupplier.is() )
1541 : : {
1542 [ + - ][ + - ]: 10 : Reference< XUIConfigurationManager > xDocUICfgMgr( xSupplier->getUIConfigurationManager(), UNO_QUERY );
[ + - ]
1543 [ + - ]: 10 : if ( xDocUICfgMgr.is() )
1544 : : {
1545 [ + - ][ + - ]: 10 : xDocAccelCfg = Reference< XAcceleratorConfiguration >( xDocUICfgMgr->getShortCutManager(), UNO_QUERY );
[ + - ][ + - ]
1546 [ + - ]: 10 : m_xDocAcceleratorManager = xDocAccelCfg;
1547 : 10 : }
1548 : 10 : }
1549 : : }
1550 : 10 : }
1551 : : }
1552 : :
1553 [ + - ]: 10 : if ( !xModuleAccelCfg.is() )
1554 : : {
1555 [ + - ]: 10 : Reference< XModuleUIConfigurationManagerSupplier > xModuleCfgMgrSupplier( getServiceFactory()->createInstance(
1556 : 10 : SERVICENAME_MODULEUICONFIGURATIONMANAGERSUPPLIER ),
1557 [ + - ][ + - ]: 10 : UNO_QUERY );
[ + - ]
1558 : : try
1559 : : {
1560 [ + - ][ + - ]: 10 : Reference< XUIConfigurationManager > xUICfgMgr = xModuleCfgMgrSupplier->getUIConfigurationManager( m_aModuleIdentifier );
1561 [ + - ]: 10 : if ( xUICfgMgr.is() )
1562 : : {
1563 [ + - ][ + - ]: 10 : xModuleAccelCfg = Reference< XAcceleratorConfiguration >( xUICfgMgr->getShortCutManager(), UNO_QUERY );
[ + - ][ + - ]
1564 [ + - ]: 10 : m_xModuleAcceleratorManager = xModuleAccelCfg;
1565 : 10 : }
1566 : : }
1567 [ # # # ]: 0 : catch ( const RuntimeException& )
1568 : : {
1569 : 0 : throw;
1570 : : }
1571 [ # # ]: 0 : catch ( const Exception& )
1572 : : {
1573 : 10 : }
1574 : : }
1575 : :
1576 [ + - ]: 10 : if ( !xGlobalAccelCfg.is() )
1577 : : {
1578 [ + - ]: 10 : xGlobalAccelCfg = Reference< XAcceleratorConfiguration >( getServiceFactory()->createInstance(
1579 : 10 : SERVICENAME_GLOBALACCELERATORCONFIGURATION ),
1580 [ + - ][ + - ]: 10 : UNO_QUERY );
[ + - ][ + - ]
1581 [ + - ]: 10 : m_xGlobalAcceleratorManager = xGlobalAccelCfg;
1582 : : }
1583 : : }
1584 : :
1585 : 36 : KeyCode aEmptyKeyCode;
1586 [ + - ]: 36 : Sequence< rtl::OUString > aSeq( aMenuShortCuts.size() );
1587 : 36 : const sal_uInt32 nCount = aMenuShortCuts.size();
1588 [ + + ]: 568 : for ( sal_uInt32 i = 0; i < nCount; ++i )
1589 : : {
1590 [ + - ]: 532 : aSeq[i] = aMenuShortCuts[i]->aMenuItemURL;
1591 [ + - ]: 532 : aMenuShortCuts[i]->aKeyCode = aEmptyKeyCode;
1592 : : }
1593 : :
1594 [ + - ]: 36 : if ( m_xGlobalAcceleratorManager.is() )
1595 [ + - ]: 36 : impl_RetrieveShortcutsFromConfiguration( xGlobalAccelCfg, aSeq, aMenuShortCuts );
1596 [ + - ]: 36 : if ( m_xModuleAcceleratorManager.is() )
1597 [ + - ]: 36 : impl_RetrieveShortcutsFromConfiguration( xModuleAccelCfg, aSeq, aMenuShortCuts );
1598 [ + - ]: 36 : if ( m_xDocAcceleratorManager.is() )
1599 [ + - ][ + - ]: 36 : impl_RetrieveShortcutsFromConfiguration( xDocAccelCfg, aSeq, aMenuShortCuts );
1600 : : }
1601 : 36 : }
1602 : :
1603 : 43401 : void MenuBarManager::RetrieveImageManagers()
1604 : : {
1605 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::RetrieveImageManagers" );
1606 [ + + ]: 43401 : if ( !m_xDocImageManager.is() )
1607 : : {
1608 [ + - ][ + - ]: 43389 : Reference< XController > xController = m_xFrame->getController();
1609 : 43389 : Reference< XModel > xModel;
1610 [ + - ]: 43389 : if ( xController.is() )
1611 : : {
1612 [ + - ][ + - ]: 43389 : xModel = xController->getModel();
[ + - ]
1613 [ + + ]: 43389 : if ( xModel.is() )
1614 : : {
1615 [ + - ]: 43371 : Reference< XUIConfigurationManagerSupplier > xSupplier( xModel, UNO_QUERY );
1616 [ + + ]: 43371 : if ( xSupplier.is() )
1617 : : {
1618 [ + - ][ + - ]: 43337 : Reference< XUIConfigurationManager > xDocUICfgMgr( xSupplier->getUIConfigurationManager(), UNO_QUERY );
[ + - ]
1619 [ + - ][ + - ]: 43337 : m_xDocImageManager = Reference< XImageManager >( xDocUICfgMgr->getImageManager(), UNO_QUERY );
[ + - ][ + - ]
1620 [ + - ]: 43337 : m_xDocImageManager->addConfigurationListener(
1621 : : Reference< XUIConfigurationListener >(
1622 [ + - ][ + - ]: 43337 : static_cast< OWeakObject* >( this ), UNO_QUERY ));
1623 : 43371 : }
1624 : : }
1625 : 43389 : }
1626 : : }
1627 : :
1628 : 43401 : Reference< XModuleManager > xModuleManager;
1629 [ + + ]: 43401 : if ( m_aModuleIdentifier.isEmpty() )
1630 [ + - ][ + - ]: 43387 : xModuleManager.set( getServiceFactory()->createInstance( SERVICENAME_MODULEMANAGER ), UNO_QUERY_THROW );
[ + - ][ + - ]
1631 : :
1632 : : try
1633 : : {
1634 [ + + ]: 43401 : if ( xModuleManager.is() )
1635 [ + - ][ + - ]: 43387 : m_aModuleIdentifier = xModuleManager->identify( Reference< XInterface >( m_xFrame, UNO_QUERY ) );
[ + - ][ # # ]
1636 : : }
1637 [ # # ]: 0 : catch( const Exception& )
1638 : : {
1639 : : }
1640 : :
1641 [ + + ]: 43401 : if ( !m_xModuleImageManager.is() )
1642 : : {
1643 [ + - ]: 43387 : Reference< XModuleUIConfigurationManagerSupplier > xModuleCfgMgrSupplier( getServiceFactory()->createInstance(
1644 : 43387 : SERVICENAME_MODULEUICONFIGURATIONMANAGERSUPPLIER ),
1645 [ + - ][ + - ]: 43387 : UNO_QUERY );
[ + - ]
1646 [ + - ][ + - ]: 43387 : Reference< XUIConfigurationManager > xUICfgMgr = xModuleCfgMgrSupplier->getUIConfigurationManager( m_aModuleIdentifier );
1647 [ + - ][ + - ]: 43387 : m_xModuleImageManager.set( xUICfgMgr->getImageManager(), UNO_QUERY );
[ + - ]
1648 [ + - ]: 43387 : m_xModuleImageManager->addConfigurationListener( Reference< XUIConfigurationListener >(
1649 [ + - ][ + - ]: 43387 : static_cast< OWeakObject* >( this ), UNO_QUERY ));
1650 : 43401 : }
1651 : 43401 : }
1652 : :
1653 : 1159 : void MenuBarManager::FillMenuWithConfiguration(
1654 : : sal_uInt16& nId,
1655 : : Menu* pMenu,
1656 : : const ::rtl::OUString& rModuleIdentifier,
1657 : : const Reference< XIndexAccess >& rItemContainer,
1658 : : const Reference< XURLTransformer >& rTransformer )
1659 : : {
1660 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::FillMenuWithConfiguration" );
1661 : 1159 : Reference< XDispatchProvider > xEmptyDispatchProvider;
1662 [ + - ]: 1159 : MenuBarManager::FillMenu( nId, pMenu, rModuleIdentifier, rItemContainer, xEmptyDispatchProvider );
1663 : :
1664 : : // Merge add-on menu entries into the menu bar
1665 : : MenuBarManager::MergeAddonMenus( static_cast< Menu* >( pMenu ),
1666 [ + - ][ + - ]: 2318 : AddonsOptions().GetMergeMenuInstructions(),
[ + - ]
1667 [ + - ]: 1159 : rModuleIdentifier );
1668 : :
1669 [ + - ][ + - ]: 1159 : sal_Bool bHasDisabledEntries = SvtCommandOptions().HasEntries( SvtCommandOptions::CMDOPTION_DISABLED );
[ + - ]
1670 [ - + ]: 1159 : if ( bHasDisabledEntries )
1671 : : {
1672 [ # # ]: 0 : sal_uInt16 nCount = pMenu->GetItemCount();
1673 [ # # ]: 0 : for ( sal_uInt16 i = 0; i < nCount; i++ )
1674 : : {
1675 [ # # ]: 0 : sal_uInt16 nID = pMenu->GetItemId( i );
1676 [ # # ]: 0 : if ( nID > 0 )
1677 : : {
1678 [ # # ]: 0 : PopupMenu* pPopupMenu = pMenu->GetPopupMenu( nID );
1679 [ # # ]: 0 : if ( pPopupMenu )
1680 : : {
1681 [ # # ][ # # ]: 0 : if ( MustBeHidden( pPopupMenu, rTransformer ))
1682 [ # # ]: 0 : pMenu->HideItem( nId );
1683 : : }
1684 : : }
1685 : : }
1686 : 1159 : }
1687 : 1159 : }
1688 : :
1689 : 43994 : void MenuBarManager::FillMenu(
1690 : : sal_uInt16& nId,
1691 : : Menu* pMenu,
1692 : : const rtl::OUString& rModuleIdentifier,
1693 : : const Reference< XIndexAccess >& rItemContainer,
1694 : : const Reference< XDispatchProvider >& rDispatchProvider )
1695 : : {
1696 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::FillMenu" );
1697 : : // Fill menu bar with container contents
1698 [ + + ]: 436635 : for ( sal_Int32 n = 0; n < rItemContainer->getCount(); n++ )
1699 : : {
1700 [ + - ]: 392641 : Sequence< PropertyValue > aProp;
1701 : 392641 : rtl::OUString aCommandURL;
1702 : 392641 : rtl::OUString aLabel;
1703 : 392641 : rtl::OUString aHelpURL;
1704 : 392641 : rtl::OUString aModuleIdentifier( rModuleIdentifier );
1705 : 392641 : sal_Bool bShow(sal_True);
1706 : 392641 : sal_Bool bEnabled(sal_True);
1707 : 392641 : sal_uInt16 nType = 0;
1708 : 392641 : Reference< XIndexAccess > xIndexContainer;
1709 : 392641 : Reference< XDispatchProvider > xDispatchProvider( rDispatchProvider );
1710 : 392641 : sal_Int16 nStyle = 0;
1711 : : try
1712 : : {
1713 [ + - ][ + - ]: 392641 : if ( rItemContainer->getByIndex( n ) >>= aProp )
[ + - ][ + - ]
1714 : : {
1715 [ + + ]: 2456382 : for ( int i = 0; i < aProp.getLength(); i++ )
1716 : : {
1717 [ + - ]: 2063741 : rtl::OUString aPropName = aProp[i].Name;
1718 [ + + ]: 2063741 : if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_COMMANDURL, LEN_DESCRIPTOR_COMMANDURL ))
1719 [ + - ]: 334222 : aProp[i].Value >>= aCommandURL;
1720 [ + + ]: 1729519 : else if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_HELPURL, LEN_DESCRIPTOR_HELPURL ))
1721 [ + - ]: 334210 : aProp[i].Value >>= aHelpURL;
1722 [ + + ]: 1395309 : else if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_CONTAINER, LEN_DESCRIPTOR_CONTAINER ))
1723 [ + - ][ + - ]: 334216 : aProp[i].Value >>= xIndexContainer;
1724 [ + + ]: 1061093 : else if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_LABEL, LEN_DESCRIPTOR_LABEL ))
1725 [ + - ]: 334222 : aProp[i].Value >>= aLabel;
1726 [ + + ]: 726871 : else if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_TYPE, LEN_DESCRIPTOR_TYPE ))
1727 [ + - ]: 392641 : aProp[i].Value >>= nType;
1728 [ + + ]: 334230 : else if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_MODULEIDENTIFIER, LEN_DESCRIPTOR_MODULEIDENTIFIER ))
1729 [ + - ]: 4 : aProp[i].Value >>= aModuleIdentifier;
1730 [ + + ]: 334226 : else if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_DISPATCHPROVIDER, LEN_DESCRIPTOR_DISPATCHPROVIDER ))
1731 [ + - ][ + - ]: 16 : aProp[i].Value >>= xDispatchProvider;
1732 [ + - ][ + - ]: 334210 : else if ( aProp[i].Name.equalsAsciiL( ITEM_DESCRIPTOR_STYLE, LEN_DESCRIPTOR_STYLE ))
1733 [ + - ]: 334210 : aProp[i].Value >>= nStyle;
1734 [ # # ][ # # ]: 0 : else if ( aProp[i].Name.equalsAsciiL( ITEM_DESCRIPTOR_ISVISIBLE, LEN_DESCRIPTOR_ISVISIBLE ))
1735 [ # # ]: 0 : aProp[i].Value >>= bShow;
1736 [ # # ][ # # ]: 0 : else if ( aProp[i].Name.equalsAsciiL( ITEM_DESCRIPTOR_ENABLED, LEN_DESCRIPTOR_ENABLED ))
1737 [ # # ]: 0 : aProp[i].Value >>= bEnabled;
1738 : 2063741 : }
1739 : :
1740 [ + + ]: 392641 : if ( nType == ::com::sun::star::ui::ItemType::DEFAULT )
1741 : : {
1742 [ + - ][ + - ]: 334222 : pMenu->InsertItem( nId, aLabel );
[ + - ]
1743 [ + - ][ + - ]: 334222 : pMenu->SetItemCommand( nId, aCommandURL );
[ + - ]
1744 : :
1745 [ + + ]: 334222 : if ( nStyle )
1746 : : {
1747 [ + - ]: 13478 : MenuItemBits nBits = pMenu->GetItemBits( nId );
1748 [ - + ]: 13478 : if ( nStyle & ::com::sun::star::ui::ItemStyle::ICON )
1749 : 0 : nBits |= MIB_ICON;
1750 [ - + ]: 13478 : if ( nStyle & ::com::sun::star::ui::ItemStyle::TEXT )
1751 : 0 : nBits |= MIB_TEXT;
1752 [ + - ]: 13478 : if ( nStyle & ::com::sun::star::ui::ItemStyle::RADIO_CHECK )
1753 : 13478 : nBits |= MIB_RADIOCHECK;
1754 [ + - ]: 13478 : pMenu->SetItemBits( nId, nBits );
1755 : : }
1756 : :
1757 [ - + ]: 334222 : if ( !bShow )
1758 [ # # ]: 0 : pMenu->HideItem( nId );
1759 : :
1760 [ - + ]: 334222 : if ( !bEnabled)
1761 [ # # ]: 0 : pMenu->EnableItem( nId, sal_False );
1762 : :
1763 [ + + ]: 334222 : if ( xIndexContainer.is() )
1764 : : {
1765 [ + - ][ + - ]: 42835 : PopupMenu* pNewPopupMenu = new PopupMenu;
1766 [ + - ]: 42835 : pMenu->SetPopupMenu( nId, pNewPopupMenu );
1767 : :
1768 [ + + ]: 42835 : if ( xDispatchProvider.is() )
1769 : : {
1770 : : // Use attributes struct to transport special dispatch provider
1771 [ + - ][ + - ]: 32 : MenuConfiguration::Attributes* pAttributes = new MenuConfiguration::Attributes;
1772 [ + - ]: 32 : pAttributes->xDispatchProvider = xDispatchProvider;
1773 [ + - ]: 32 : pMenu->SetUserValue( nId, (sal_uIntPtr)( pAttributes ));
1774 : : }
1775 : :
1776 : : // Use help command to transport module identifier
1777 [ + - ]: 42835 : if ( !aModuleIdentifier.isEmpty() )
1778 [ + - ][ + - ]: 42835 : pMenu->SetHelpCommand( nId, aModuleIdentifier );
[ + - ][ # # ]
1779 : :
1780 : 42835 : ++nId;
1781 [ + - ]: 42835 : FillMenu( nId, pNewPopupMenu, aModuleIdentifier, xIndexContainer, xDispatchProvider );
1782 : : }
1783 : : else
1784 : 291387 : ++nId;
1785 : : }
1786 : : else
1787 : : {
1788 [ + - ]: 58419 : pMenu->InsertSeparator();
1789 : 392641 : ++nId;
1790 : : }
1791 : : }
1792 : : }
1793 [ # # ]: 0 : catch ( const IndexOutOfBoundsException& )
1794 : : {
1795 : : break;
1796 : : }
1797 [ - + ][ - + ]: 392641 : }
[ - + ][ - + ]
[ - + ][ - + ]
[ + - ][ + - ]
1798 : 43994 : }
1799 : :
1800 : 1159 : void MenuBarManager::MergeAddonMenus(
1801 : : Menu* pMenuBar,
1802 : : const MergeMenuInstructionContainer& aMergeInstructionContainer,
1803 : : const ::rtl::OUString& rModuleIdentifier )
1804 : : {
1805 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::MergeAddonMenus" );
1806 : : // set start value for the item ID for the new addon menu items
1807 : 1159 : sal_uInt16 nItemId = ADDONMENU_MERGE_ITEMID_START;
1808 : :
1809 : 1159 : const sal_uInt32 nCount = aMergeInstructionContainer.size();
1810 [ + + ]: 2318 : for ( sal_uInt32 i = 0; i < nCount; i++ )
1811 : : {
1812 [ + - ]: 1159 : const MergeMenuInstruction& rMergeInstruction = aMergeInstructionContainer[i];
1813 : :
1814 [ + - ][ + + ]: 1159 : if ( MenuBarMerger::IsCorrectContext( rMergeInstruction.aMergeContext, rModuleIdentifier ))
1815 : : {
1816 [ + - ]: 26 : ::std::vector< ::rtl::OUString > aMergePath;
1817 : :
1818 : : // retrieve the merge path from the merge point string
1819 [ + - ]: 26 : MenuBarMerger::RetrieveReferencePath( rMergeInstruction.aMergePoint, aMergePath );
1820 : :
1821 : : // convert the sequence/sequence property value to a more convenient vector<>
1822 [ + - ]: 26 : AddonMenuContainer aMergeMenuItems;
1823 [ + - ]: 26 : MenuBarMerger::GetSubMenu( rMergeInstruction.aMergeMenu, aMergeMenuItems );
1824 : :
1825 : : // try to find the reference point for our merge operation
1826 : 26 : Menu* pMenu = pMenuBar;
1827 [ + - ]: 26 : ReferencePathInfo aResult = MenuBarMerger::FindReferencePath( aMergePath, pMenu );
1828 : :
1829 [ + - ]: 26 : if ( aResult.eResult == RP_OK )
1830 : : {
1831 : : // normal merge operation
1832 : : MenuBarMerger::ProcessMergeOperation( aResult.pPopupMenu,
1833 : : aResult.nPos,
1834 : : nItemId,
1835 : : rMergeInstruction.aMergeCommand,
1836 : : rMergeInstruction.aMergeCommandParameter,
1837 : : rModuleIdentifier,
1838 [ + - ]: 26 : aMergeMenuItems );
1839 : : }
1840 : : else
1841 : : {
1842 : : // fallback
1843 : : MenuBarMerger::ProcessFallbackOperation( aResult,
1844 : : nItemId,
1845 : : rMergeInstruction.aMergeCommand,
1846 : : rMergeInstruction.aMergeFallback,
1847 : : aMergePath,
1848 : : rModuleIdentifier,
1849 [ # # ]: 0 : aMergeMenuItems );
1850 : 26 : }
1851 : : }
1852 : : }
1853 : 1159 : }
1854 : :
1855 : 14 : void MenuBarManager::SetItemContainer( const Reference< XIndexAccess >& rItemContainer )
1856 : : {
1857 : : RTL_LOGFILE_CONTEXT( aLog, "framework (cd100003) ::MenuBarManager::SetItemContainer" );
1858 : :
1859 [ + - ]: 14 : ResetableGuard aGuard( m_aLock );
1860 : :
1861 : 14 : Reference< XFrame > xFrame = m_xFrame;
1862 : :
1863 [ + + ]: 14 : if ( !m_bModuleIdentified )
1864 : : {
1865 : 2 : m_bModuleIdentified = sal_True;
1866 : 2 : Reference< XModuleManager > xModuleManager;
1867 [ + - ][ + - ]: 2 : xModuleManager = Reference< XModuleManager >( getServiceFactory()->createInstance( SERVICENAME_MODULEMANAGER ), UNO_QUERY_THROW );
[ + - ][ + - ]
[ # # ][ + - ]
1868 : :
1869 : : try
1870 : : {
1871 [ + - ][ + - ]: 2 : m_aModuleIdentifier = xModuleManager->identify( xFrame );
1872 : : }
1873 [ # # ]: 0 : catch( const Exception& )
1874 : : {
1875 : 2 : }
1876 : : }
1877 : :
1878 : : // Clear MenuBarManager structures
1879 : : {
1880 [ + - ]: 14 : SolarMutexGuard aSolarMutexGuard;
1881 : :
1882 : : // Check active state as we cannot change our VCL menu during activation by the user
1883 [ - + ]: 14 : if ( m_bActive )
1884 : : {
1885 [ # # ]: 0 : m_xDeferedItemContainer = rItemContainer;
1886 : 14 : return;
1887 : : }
1888 : :
1889 [ + - ]: 14 : RemoveListener();
1890 : 14 : std::vector< MenuItemHandler* >::iterator p;
1891 [ + - ][ + + ]: 128 : for ( p = m_aMenuItemHandlerVector.begin(); p != m_aMenuItemHandlerVector.end(); ++p )
1892 : : {
1893 : 114 : MenuItemHandler* pItemHandler = *p;
1894 : 114 : pItemHandler->xMenuItemDispatch.clear();
1895 : 114 : pItemHandler->xSubMenuManager.clear();
1896 [ + - ][ + - ]: 114 : delete pItemHandler;
1897 : : }
1898 : 14 : m_aMenuItemHandlerVector.clear();
1899 : :
1900 : : // Remove top-level parts
1901 [ + - ]: 14 : m_pVCLMenu->Clear();
1902 : :
1903 : 14 : sal_uInt16 nId = 1;
1904 : :
1905 : : // Fill menu bar with container contents
1906 [ + - ]: 14 : FillMenuWithConfiguration( nId, (Menu *)m_pVCLMenu, m_aModuleIdentifier, rItemContainer, m_xURLTransformer );
1907 : :
1908 : : // Refill menu manager again
1909 : 14 : Reference< XDispatchProvider > xDispatchProvider;
1910 [ + - ]: 14 : FillMenuManager( m_pVCLMenu, xFrame, xDispatchProvider, m_aModuleIdentifier, sal_False, sal_True );
1911 : :
1912 : : // add itself as frame action listener
1913 [ + - ][ + - ]: 14 : m_xFrame->addFrameActionListener( Reference< XFrameActionListener >( static_cast< OWeakObject* >( this ), UNO_QUERY ));
[ + - ][ + - ]
[ + - ]
1914 [ - + ][ + - ]: 14 : }
[ + - ]
1915 : : }
1916 : :
1917 : 0 : void MenuBarManager::GetPopupController( PopupControllerCache& rPopupController )
1918 : : {
1919 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::GetPopupController" );
1920 : :
1921 [ # # ]: 0 : SolarMutexGuard aSolarMutexGuard;
1922 : :
1923 : 0 : std::vector< MenuItemHandler* >::iterator p;
1924 [ # # ][ # # ]: 0 : for ( p = m_aMenuItemHandlerVector.begin(); p != m_aMenuItemHandlerVector.end(); ++p )
1925 : : {
1926 : 0 : MenuItemHandler* pItemHandler = *p;
1927 [ # # ]: 0 : if ( pItemHandler->xPopupMenuController.is() )
1928 : : {
1929 [ # # ]: 0 : Reference< XDispatchProvider > xDispatchProvider( pItemHandler->xPopupMenuController, UNO_QUERY );
1930 : :
1931 [ # # ]: 0 : PopupControllerEntry aPopupControllerEntry;
1932 [ # # ]: 0 : aPopupControllerEntry.m_xDispatchProvider = xDispatchProvider;
1933 : :
1934 : : // Just use the main part of the URL for popup menu controllers
1935 : 0 : sal_Int32 nQueryPart( 0 );
1936 : 0 : sal_Int32 nSchemePart( 0 );
1937 : 0 : rtl::OUString aMainURL( "vnd.sun.star.popup:" );
1938 : 0 : rtl::OUString aMenuURL( pItemHandler->aMenuItemURL );
1939 : :
1940 : 0 : nSchemePart = aMenuURL.indexOf( ':' );
1941 [ # # ]: 0 : if (( nSchemePart > 0 ) &&
[ # # # # ]
1942 : 0 : ( aMenuURL.getLength() > ( nSchemePart+1 )))
1943 : : {
1944 : 0 : nQueryPart = aMenuURL.indexOf( '?', nSchemePart );
1945 [ # # ]: 0 : if ( nQueryPart > 0 )
1946 : 0 : aMainURL += aMenuURL.copy( nSchemePart, nQueryPart-nSchemePart );
1947 [ # # ]: 0 : else if ( nQueryPart == -1 )
1948 : 0 : aMainURL += aMenuURL.copy( nSchemePart+1 );
1949 : :
1950 : : rPopupController.insert( PopupControllerCache::value_type(
1951 [ # # ][ # # ]: 0 : aMainURL, aPopupControllerEntry ));
[ # # ]
1952 [ # # ]: 0 : }
1953 : : }
1954 [ # # ]: 0 : if ( pItemHandler->xSubMenuManager.is() )
1955 : : {
1956 [ # # ]: 0 : MenuBarManager* pMenuBarManager = (MenuBarManager*)(pItemHandler->xSubMenuManager.get());
1957 [ # # ]: 0 : if ( pMenuBarManager )
1958 [ # # ]: 0 : pMenuBarManager->GetPopupController( rPopupController );
1959 : : }
1960 [ # # ]: 0 : }
1961 : 0 : }
1962 : :
1963 : 215175 : const Reference< XMultiServiceFactory >& MenuBarManager::getServiceFactory()
1964 : : {
1965 : 215175 : return mxServiceFactory;
1966 : : }
1967 : :
1968 : 41676 : void MenuBarManager::AddMenu(MenuBarManager* pSubMenuManager,const ::rtl::OUString& _sItemCommand,sal_uInt16 _nItemId)
1969 : : {
1970 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::AddMenu" );
1971 [ + - ][ + - ]: 41676 : Reference< XStatusListener > xSubMenuManager( static_cast< OWeakObject *>( pSubMenuManager ), UNO_QUERY );
1972 [ + - ][ + - ]: 41676 : m_xFrame->addFrameActionListener( Reference< XFrameActionListener >( xSubMenuManager, UNO_QUERY ));
[ + - ]
1973 : :
1974 : : // store menu item command as we later have to know which menu is active (see Activate handler)
1975 : 41676 : pSubMenuManager->m_aMenuItemCommand = _sItemCommand;
1976 : 41676 : Reference< XDispatch > xDispatch;
1977 : : MenuItemHandler* pMenuItemHandler = new MenuItemHandler(
1978 : : _nItemId,
1979 : : xSubMenuManager,
1980 [ + - ][ + - ]: 41676 : xDispatch );
1981 : 41676 : pMenuItemHandler->aMenuItemURL = _sItemCommand;
1982 [ + - ]: 41676 : m_aMenuItemHandlerVector.push_back( pMenuItemHandler );
1983 : 41676 : }
1984 : :
1985 : 392693 : sal_uInt16 MenuBarManager::FillItemCommand(::rtl::OUString& _rItemCommand,Menu* _pMenu,sal_uInt16 _nIndex) const
1986 : : {
1987 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::FillItemCommand" );
1988 : 392693 : sal_uInt16 nItemId = _pMenu->GetItemId( _nIndex );
1989 : :
1990 : 392693 : _rItemCommand = _pMenu->GetItemCommand( nItemId );
1991 [ + + ]: 392693 : if ( _rItemCommand.isEmpty() )
1992 : : {
1993 [ + + ][ + - ]: 23708 : const static ::rtl::OUString aSlotString( "slot:" );
1994 : 23708 : _rItemCommand = aSlotString;
1995 : 23708 : _rItemCommand += ::rtl::OUString::valueOf( (sal_Int32)nItemId );
1996 [ + - ]: 23708 : _pMenu->SetItemCommand( nItemId, _rItemCommand );
1997 : : }
1998 : 392693 : return nItemId;
1999 : : }
2000 : 0 : void MenuBarManager::Init(const Reference< XFrame >& rFrame,AddonMenu* pAddonMenu,sal_Bool bDelete,sal_Bool bDeleteChildren,bool _bHandlePopUp)
2001 : : {
2002 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::Init" );
2003 : 0 : m_bActive = sal_False;
2004 : 0 : m_bDeleteMenu = bDelete;
2005 : 0 : m_bDeleteChildren = bDeleteChildren;
2006 : 0 : m_pVCLMenu = pAddonMenu;
2007 [ # # ]: 0 : m_xFrame = rFrame;
2008 : 0 : m_bInitialized = sal_False;
2009 : 0 : m_bIsBookmarkMenu = sal_True;
2010 : :
2011 : 0 : rtl::OUString aModuleIdentifier;
2012 : : m_xPopupMenuControllerRegistration = Reference< ::com::sun::star::frame::XUIControllerRegistration >(
2013 [ # # ]: 0 : getServiceFactory()->createInstance( rtl::OUString( "com.sun.star.frame.PopupMenuControllerFactory" )),
2014 [ # # ][ # # ]: 0 : UNO_QUERY );
[ # # ]
2015 : :
2016 : 0 : Reference< XStatusListener > xStatusListener;
2017 : 0 : Reference< XDispatch > xDispatch;
2018 [ # # ]: 0 : sal_uInt16 nItemCount = pAddonMenu->GetItemCount();
2019 : 0 : ::rtl::OUString aItemCommand;
2020 [ # # ]: 0 : m_aMenuItemHandlerVector.reserve(nItemCount);
2021 [ # # ]: 0 : for ( sal_uInt16 i = 0; i < nItemCount; i++ )
2022 : : {
2023 [ # # ]: 0 : sal_uInt16 nItemId = FillItemCommand(aItemCommand,pAddonMenu, i );
2024 : :
2025 [ # # ]: 0 : PopupMenu* pPopupMenu = pAddonMenu->GetPopupMenu( nItemId );
2026 [ # # ]: 0 : if ( pPopupMenu )
2027 : : {
2028 : 0 : Reference< XDispatchProvider > xDispatchProvider;
2029 [ # # ][ # # ]: 0 : MenuBarManager* pSubMenuManager = new MenuBarManager( getServiceFactory(), rFrame, m_xURLTransformer,xDispatchProvider, aModuleIdentifier, pPopupMenu, _bHandlePopUp ? sal_False : bDeleteChildren, _bHandlePopUp ? sal_False : bDeleteChildren );
[ # # ]
2030 : :
2031 [ # # ][ # # ]: 0 : Reference< XStatusListener > xSubMenuManager( static_cast< OWeakObject *>( pSubMenuManager ), UNO_QUERY );
2032 : :
2033 : : // store menu item command as we later have to know which menu is active (see Acivate handler)
2034 : 0 : pSubMenuManager->m_aMenuItemCommand = aItemCommand;
2035 : :
2036 : : MenuItemHandler* pMenuItemHandler = new MenuItemHandler(
2037 : : nItemId,
2038 : : xSubMenuManager,
2039 [ # # ][ # # ]: 0 : xDispatch );
2040 [ # # ]: 0 : m_aMenuItemHandlerVector.push_back( pMenuItemHandler );
2041 : : }
2042 : : else
2043 : : {
2044 [ # # ][ # # ]: 0 : if ( pAddonMenu->GetItemType( i ) != MENUITEM_SEPARATOR )
2045 : : {
2046 [ # # ]: 0 : MenuConfiguration::Attributes* pAddonAttributes = (MenuConfiguration::Attributes *)(pAddonMenu->GetUserValue( nItemId ));
2047 [ # # ][ # # ]: 0 : MenuItemHandler* pMenuItemHandler = new MenuItemHandler( nItemId, xStatusListener, xDispatch );
2048 : :
2049 [ # # ]: 0 : if ( pAddonAttributes )
2050 : : {
2051 : : // read additional attributes from attributes struct and AddonMenu implementation will delete all attributes itself!!
2052 : 0 : pMenuItemHandler->aTargetFrame = pAddonAttributes->aTargetFrame;
2053 : : }
2054 : :
2055 : 0 : pMenuItemHandler->aMenuItemURL = aItemCommand;
2056 [ # # ]: 0 : if ( _bHandlePopUp )
2057 : : {
2058 : : // Check if we have to create a popup menu for a uno based popup menu controller.
2059 : : // We have to set an empty popup menu into our menu structure so the controller also
2060 : : // works with inplace OLE.
2061 [ # # ][ # # ]: 0 : if ( m_xPopupMenuControllerRegistration.is() &&
[ # # ]
2062 [ # # ][ # # ]: 0 : m_xPopupMenuControllerRegistration->hasController( aItemCommand, rtl::OUString() ))
[ # # ][ # # ]
2063 : : {
2064 [ # # ]: 0 : VCLXPopupMenu* pVCLXPopupMenu = new VCLXPopupMenu;
2065 : 0 : PopupMenu* pCtlPopupMenu = (PopupMenu *)pVCLXPopupMenu->GetMenu();
2066 [ # # ]: 0 : pAddonMenu->SetPopupMenu( pMenuItemHandler->nItemId, pCtlPopupMenu );
2067 [ # # ][ # # ]: 0 : pMenuItemHandler->xPopupMenu = Reference< com::sun::star::awt::XPopupMenu >( (OWeakObject *)pVCLXPopupMenu, UNO_QUERY );
[ # # ]
2068 : :
2069 : : }
2070 : : }
2071 [ # # ]: 0 : m_aMenuItemHandlerVector.push_back( pMenuItemHandler );
2072 : : }
2073 : : }
2074 : : }
2075 : :
2076 [ # # ]: 0 : SetHdl();
2077 : 0 : }
2078 : :
2079 : 43401 : void MenuBarManager::SetHdl()
2080 : : {
2081 : 43401 : m_pVCLMenu->SetHighlightHdl( LINK( this, MenuBarManager, Highlight ));
2082 : 43401 : m_pVCLMenu->SetActivateHdl( LINK( this, MenuBarManager, Activate ));
2083 : 43401 : m_pVCLMenu->SetDeactivateHdl( LINK( this, MenuBarManager, Deactivate ));
2084 : 43401 : m_pVCLMenu->SetSelectHdl( LINK( this, MenuBarManager, Select ));
2085 : :
2086 [ # # ][ - + ]: 43401 : if ( !m_xURLTransformer.is() && mxServiceFactory.is() )
[ - + ]
2087 : : m_xURLTransformer.set(
2088 : : URLTransformer::create(
2089 [ # # ][ # # ]: 0 : ::comphelper::ComponentContext(mxServiceFactory).getUNOContext()) );
[ # # ]
2090 : 43401 : }
2091 : :
2092 : : }
2093 : :
2094 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|