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