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 #include <uielement/newmenucontroller.hxx>
27 
28 //_________________________________________________________________________________________________________________
29 //	my own includes
30 //_________________________________________________________________________________________________________________
31 #include <threadhelp/resetableguard.hxx>
32 #include "services.h"
33 #ifndef __FRAMEWORK_CLASSES_RESOURCE_HRC_
34 #include <classes/resource.hrc>
35 #endif
36 #include <classes/fwkresid.hxx>
37 #include <framework/bmkmenu.hxx>
38 #include <framework/imageproducer.hxx>
39 #include <framework/menuconfiguration.hxx>
40 
41 //_________________________________________________________________________________________________________________
42 //	interface includes
43 //_________________________________________________________________________________________________________________
44 #include <com/sun/star/awt/XDevice.hpp>
45 #include <com/sun/star/beans/PropertyValue.hpp>
46 #include <com/sun/star/awt/MenuItemStyle.hpp>
47 #include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
48 #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
49 #include <com/sun/star/frame/XModuleManager.hpp>
50 #include <com/sun/star/container/XNameAccess.hpp>
51 #include <com/sun/star/document/CorruptedFilterConfigurationException.hpp>
52 
53 //_________________________________________________________________________________________________________________
54 //	includes of other projects
55 //_________________________________________________________________________________________________________________
56 #include <vcl/svapp.hxx>
57 #include <vcl/i18nhelp.hxx>
58 #include <tools/urlobj.hxx>
59 #include <rtl/ustrbuf.hxx>
60 #include <cppuhelper/implbase1.hxx>
61 #include <osl/file.hxx>
62 #include <svtools/menuoptions.hxx>
63 #include <svtools/acceleratorexecute.hxx>
64 #include <unotools/moduleoptions.hxx>
65 #include <dispatch/uieventloghelper.hxx>
66 #include <vos/mutex.hxx>
67 
68 //_________________________________________________________________________________________________________________
69 //	Defines
70 //_________________________________________________________________________________________________________________
71 //
72 
73 using namespace com::sun::star::uno;
74 using namespace com::sun::star::lang;
75 using namespace com::sun::star::frame;
76 using namespace com::sun::star::beans;
77 using namespace com::sun::star::util;
78 using namespace com::sun::star::container;
79 using namespace com::sun::star::ui;
80 
81 static const char SFX_REFERER_USER[] = "private:user";
82 
83 namespace framework
84 {
85 
DEFINE_XSERVICEINFO_MULTISERVICE(NewMenuController,OWeakObject,SERVICENAME_POPUPMENUCONTROLLER,IMPLEMENTATIONNAME_NEWMENUCONTROLLER)86 DEFINE_XSERVICEINFO_MULTISERVICE        (   NewMenuController                           ,
87                                             OWeakObject                                 ,
88                                             SERVICENAME_POPUPMENUCONTROLLER		        ,
89 											IMPLEMENTATIONNAME_NEWMENUCONTROLLER
90 										)
91 
92 DEFINE_INIT_SERVICE                     (   NewMenuController, {} )
93 
94 void NewMenuController::setMenuImages( PopupMenu* pPopupMenu, sal_Bool bSetImages, sal_Bool bHiContrast )
95 {
96 	sal_uInt16 nItemCount = pPopupMenu->GetItemCount();
97     Image               aImage;
98     Reference< XFrame > xFrame( m_xFrame );
99 
100     for ( sal_uInt16 i = 0; i < nItemCount; i++ )
101     {
102         sal_uInt16 nItemId = pPopupMenu->GetItemId( sal::static_int_cast<sal_uInt16>( i ));
103         if ( nItemId != 0 )
104         {
105             if ( bSetImages )
106             {
107                 sal_Bool        bImageSet( sal_False );
108 		        ::rtl::OUString aImageId;
109 
110                 AddInfoForId::const_iterator pInfo = m_aAddInfoForItem.find( nItemId );
111                 if ( pInfo != m_aAddInfoForItem.end() )
112 				    aImageId = pInfo->second.aImageId; // Retrieve image id for menu item
113 
114 			    if ( aImageId.getLength() > 0 )
115 			    {
116                     aImage = GetImageFromURL( xFrame, aImageId, sal_False, bHiContrast );
117 				    if ( !!aImage )
118 				    {
119 					    bImageSet = sal_True;
120 					    pPopupMenu->SetItemImage( nItemId, aImage );
121 				    }
122 			    }
123 
124 			    if ( !bImageSet )
125                 {
126                     String aCmd( pPopupMenu->GetItemCommand( nItemId ) );
127                     if ( aCmd.Len() )
128                         aImage = GetImageFromURL( xFrame, aCmd, sal_False, bHiContrast );
129 
130                     if ( !!aImage )
131                         pPopupMenu->SetItemImage( nItemId, aImage );
132                 }
133             }
134             else
135                 pPopupMenu->SetItemImage( nItemId, aImage );
136         }
137     }
138 }
139 
determineAndSetNewDocAccel(PopupMenu * pPopupMenu,const KeyCode & rKeyCode)140 void NewMenuController::determineAndSetNewDocAccel( PopupMenu* pPopupMenu, const KeyCode& rKeyCode )
141 {
142     sal_uInt16        nCount( pPopupMenu->GetItemCount() );
143     sal_uInt16        nId( 0 );
144     sal_Bool      bFound( sal_False );
145     rtl::OUString aCommand;
146 
147     if ( m_aEmptyDocURL.getLength() > 0 )
148     {
149         // Search for the empty document URL
150 
151         for ( sal_uInt32 i = 0; i < sal_uInt32( nCount ); i++ )
152         {
153             nId = pPopupMenu->GetItemId( sal_uInt16( i ));
154             if ( nId != 0 && pPopupMenu->GetItemType( nId ) != MENUITEM_SEPARATOR )
155             {
156                 aCommand = pPopupMenu->GetItemCommand( nId );
157                 if ( aCommand.indexOf( m_aEmptyDocURL ) == 0 )
158                 {
159                     pPopupMenu->SetAccelKey( nId, rKeyCode );
160                     bFound = sal_True;
161                     break;
162                 }
163             }
164         }
165     }
166 
167     if ( !bFound )
168     {
169         // Search for the default module name
170         rtl::OUString aDefaultModuleName( SvtModuleOptions().GetDefaultModuleName() );
171         if ( aDefaultModuleName.getLength() > 0 )
172         {
173             for ( sal_uInt32 i = 0; i < sal_uInt32( nCount ); i++ )
174             {
175                 nId = pPopupMenu->GetItemId( sal_uInt16( i ));
176                 if ( nId != 0 && pPopupMenu->GetItemType( nId ) != MENUITEM_SEPARATOR )
177                 {
178                     aCommand = pPopupMenu->GetItemCommand( nId );
179                     if ( aCommand.indexOf( aDefaultModuleName ) >= 0 )
180                     {
181                         pPopupMenu->SetAccelKey( nId, rKeyCode );
182                         break;
183                     }
184                 }
185             }
186         }
187     }
188 }
189 
setAccelerators(PopupMenu * pPopupMenu)190 void NewMenuController::setAccelerators( PopupMenu* pPopupMenu )
191 {
192     if ( m_bModuleIdentified )
193     {
194         Reference< XAcceleratorConfiguration > xDocAccelCfg( m_xDocAcceleratorManager );
195         Reference< XAcceleratorConfiguration > xModuleAccelCfg( m_xModuleAcceleratorManager );
196         Reference< XAcceleratorConfiguration > xGlobalAccelCfg( m_xGlobalAcceleratorManager );
197 
198         if ( !m_bAcceleratorCfg )
199         {
200             // Retrieve references on demand
201             m_bAcceleratorCfg = sal_True;
202             if ( !xDocAccelCfg.is() )
203             {
204                 Reference< XController > xController = m_xFrame->getController();
205                 Reference< XModel > xModel;
206                 if ( xController.is() )
207                 {
208                     xModel = xController->getModel();
209                     if ( xModel.is() )
210                     {
211                         Reference< XUIConfigurationManagerSupplier > xSupplier( xModel, UNO_QUERY );
212                         if ( xSupplier.is() )
213                         {
214                             Reference< XUIConfigurationManager > xDocUICfgMgr( xSupplier->getUIConfigurationManager(), UNO_QUERY );
215                             if ( xDocUICfgMgr.is() )
216                             {
217                                 xDocAccelCfg = Reference< XAcceleratorConfiguration >( xDocUICfgMgr->getShortCutManager(), UNO_QUERY );
218                                 m_xDocAcceleratorManager = xDocAccelCfg;
219                             }
220                         }
221                     }
222                 }
223             }
224 
225             if ( !xModuleAccelCfg.is() )
226             {
227                 Reference< XModuleUIConfigurationManagerSupplier > xModuleCfgMgrSupplier( m_xServiceManager->createInstance(
228                                                                                             SERVICENAME_MODULEUICONFIGURATIONMANAGERSUPPLIER ),
229                                                                                         UNO_QUERY );
230                 Reference< XUIConfigurationManager > xUICfgMgr = xModuleCfgMgrSupplier->getUIConfigurationManager( m_aModuleIdentifier );
231                 if ( xUICfgMgr.is() )
232                 {
233                     xModuleAccelCfg = Reference< XAcceleratorConfiguration >( xUICfgMgr->getShortCutManager(), UNO_QUERY );
234                     m_xModuleAcceleratorManager = xModuleAccelCfg;
235                 }
236             }
237 
238             if ( !xGlobalAccelCfg.is() )
239             {
240                 xGlobalAccelCfg = Reference< XAcceleratorConfiguration >( m_xServiceManager->createInstance(
241                                                                             SERVICENAME_GLOBALACCELERATORCONFIGURATION ),
242                                                                           UNO_QUERY );
243                 m_xGlobalAcceleratorManager = xGlobalAccelCfg;
244             }
245         }
246 
247         KeyCode                         aEmptyKeyCode;
248         sal_uInt32                      nItemCount( pPopupMenu->GetItemCount() );
249         std::vector< KeyCode >          aMenuShortCuts;
250         std::vector< rtl::OUString >    aCmds;
251         std::vector< sal_uInt32 >       aIds;
252         for ( sal_uInt32 i = 0; i < nItemCount; i++ )
253         {
254             sal_uInt16 nId( pPopupMenu->GetItemId( sal_uInt16( i )));
255             if ( nId & ( pPopupMenu->GetItemType( nId ) != MENUITEM_SEPARATOR ))
256             {
257                 aIds.push_back( nId );
258                 aMenuShortCuts.push_back( aEmptyKeyCode );
259                 aCmds.push_back( pPopupMenu->GetItemCommand( nId ));
260             }
261         }
262 
263         sal_uInt32 nSeqCount( aIds.size() );
264 
265         if ( m_bNewMenu )
266             nSeqCount+=1;
267 
268         Sequence< rtl::OUString > aSeq( nSeqCount );
269 
270         // Add a special command for our "New" menu.
271         if ( m_bNewMenu )
272         {
273             aSeq[nSeqCount-1] = m_aCommandURL;
274             aMenuShortCuts.push_back( aEmptyKeyCode );
275         }
276 
277         const sal_uInt32 nCount = aCmds.size();
278         for ( sal_uInt32 i = 0; i < nCount; i++ )
279             aSeq[i] = aCmds[i];
280 
281         if ( m_xGlobalAcceleratorManager.is() )
282             retrieveShortcutsFromConfiguration( xGlobalAccelCfg, aSeq, aMenuShortCuts );
283         if ( m_xModuleAcceleratorManager.is() )
284             retrieveShortcutsFromConfiguration( xModuleAccelCfg, aSeq, aMenuShortCuts );
285         if ( m_xDocAcceleratorManager.is() )
286             retrieveShortcutsFromConfiguration( xGlobalAccelCfg, aSeq, aMenuShortCuts );
287 
288         const sal_uInt32 nCount2 = aIds.size();
289         for ( sal_uInt32 i = 0; i < nCount2; i++ )
290             pPopupMenu->SetAccelKey( sal_uInt16( aIds[i] ), aMenuShortCuts[i] );
291 
292         // Special handling for "New" menu short-cut should be set at the
293         // document which will be opened using it.
294         if ( m_bNewMenu )
295         {
296             if ( aMenuShortCuts[nSeqCount-1] != aEmptyKeyCode )
297                 determineAndSetNewDocAccel( pPopupMenu, aMenuShortCuts[nSeqCount-1] );
298         }
299     }
300 }
301 
retrieveShortcutsFromConfiguration(const Reference<XAcceleratorConfiguration> & rAccelCfg,const Sequence<rtl::OUString> & rCommands,std::vector<KeyCode> & aMenuShortCuts)302 void NewMenuController::retrieveShortcutsFromConfiguration(
303     const Reference< XAcceleratorConfiguration >& rAccelCfg,
304     const Sequence< rtl::OUString >& rCommands,
305     std::vector< KeyCode >& aMenuShortCuts )
306 {
307     if ( rAccelCfg.is() )
308     {
309         try
310         {
311             com::sun::star::awt::KeyEvent aKeyEvent;
312             Sequence< Any > aSeqKeyCode = rAccelCfg->getPreferredKeyEventsForCommandList( rCommands );
313             for ( sal_Int32 i = 0; i < aSeqKeyCode.getLength(); i++ )
314             {
315                 if ( aSeqKeyCode[i] >>= aKeyEvent )
316                     aMenuShortCuts[i] = svt::AcceleratorExecute::st_AWTKey2VCLKey( aKeyEvent );
317             }
318         }
319         catch ( IllegalArgumentException& )
320         {
321         }
322     }
323 }
324 
NewMenuController(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & xServiceManager)325 NewMenuController::NewMenuController( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager ) :
326 	svt::PopupMenuControllerBase( xServiceManager ),
327     m_bShowImages( sal_True ),
328     m_bHiContrast( sal_False ),
329     m_bNewMenu( sal_False ),
330     m_bModuleIdentified( sal_False ),
331     m_bAcceleratorCfg( sal_False ),
332     m_aTargetFrame( RTL_CONSTASCII_USTRINGPARAM( "_default" ))
333 {
334 }
335 
~NewMenuController()336 NewMenuController::~NewMenuController()
337 {
338 }
339 
340 // private function
fillPopupMenu(Reference<css::awt::XPopupMenu> & rPopupMenu)341 void NewMenuController::fillPopupMenu( Reference< css::awt::XPopupMenu >& rPopupMenu )
342 {
343     VCLXPopupMenu* pPopupMenu    = (VCLXPopupMenu *)VCLXMenu::GetImplementation( rPopupMenu );
344     PopupMenu*     pVCLPopupMenu = 0;
345 
346     vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
347 
348     resetPopupMenu( rPopupMenu );
349     if ( pPopupMenu )
350         pVCLPopupMenu = (PopupMenu *)pPopupMenu->GetMenu();
351 
352     if ( pVCLPopupMenu )
353     {
354         MenuConfiguration aMenuCfg( m_xServiceManager );
355         BmkMenu* pSubMenu( 0 );
356 
357         if ( m_bNewMenu )
358             pSubMenu = (BmkMenu*)aMenuCfg.CreateBookmarkMenu( m_xFrame, BOOKMARK_NEWMENU );
359         else
360             pSubMenu = (BmkMenu*)aMenuCfg.CreateBookmarkMenu( m_xFrame, BOOKMARK_WIZARDMENU );
361 
362         // copy entries as we have to use the provided popup menu
363         *pVCLPopupMenu = *pSubMenu;
364 
365         Image           aImage;
366         AddInfo         aAddInfo;
367 
368         // retrieve additional parameters from bookmark menu and
369         // store it in a hash_map.
370         for ( sal_uInt16 i = 0; i < pSubMenu->GetItemCount(); i++ )
371         {
372 		    sal_uInt16 nItemId = pSubMenu->GetItemId( sal::static_int_cast<sal_uInt16>( i ) );
373             if (( nItemId != 0 ) &&
374                 ( pSubMenu->GetItemType( nItemId ) != MENUITEM_SEPARATOR ))
375             {
376 				MenuConfiguration::Attributes* pBmkAttributes = (MenuConfiguration::Attributes *)(pSubMenu->GetUserValue( nItemId ));
377                 if ( pBmkAttributes != 0 )
378                 {
379                     aAddInfo.aTargetFrame = pBmkAttributes->aTargetFrame;
380                     aAddInfo.aImageId     = pBmkAttributes->aImageId;
381 
382                     m_aAddInfoForItem.insert( AddInfoForId::value_type( nItemId, aAddInfo ));
383                 }
384             }
385         }
386 
387         if ( m_bShowImages )
388             setMenuImages( pVCLPopupMenu, m_bShowImages, m_bHiContrast );
389 
390         delete pSubMenu;
391     }
392 }
393 
394 // XEventListener
disposing(const EventObject &)395 void SAL_CALL NewMenuController::disposing( const EventObject& ) throw ( RuntimeException )
396 {
397     Reference< css::awt::XMenuListener > xHolder(( OWeakObject *)this, UNO_QUERY );
398 
399     osl::MutexGuard aLock( m_aMutex );
400     m_xFrame.clear();
401     m_xDispatch.clear();
402     m_xServiceManager.clear();
403 
404     if ( m_xPopupMenu.is() )
405         m_xPopupMenu->removeMenuListener( Reference< css::awt::XMenuListener >(( OWeakObject *)this, UNO_QUERY ));
406     m_xPopupMenu.clear();
407 }
408 
409 // XStatusListener
statusChanged(const FeatureStateEvent &)410 void SAL_CALL NewMenuController::statusChanged( const FeatureStateEvent& ) throw ( RuntimeException )
411 {
412 }
413 
414 // XMenuListener
itemSelected(const css::awt::MenuEvent & rEvent)415 void SAL_CALL NewMenuController::itemSelected( const css::awt::MenuEvent& rEvent ) throw (RuntimeException)
416 {
417     Reference< css::awt::XPopupMenu > xPopupMenu;
418     Reference< XDispatch >            xDispatch;
419     Reference< XDispatchProvider >    xDispatchProvider;
420     Reference< XMultiServiceFactory > xServiceManager;
421     Reference< XURLTransformer >      xURLTransformer;
422 
423     osl::ClearableMutexGuard aLock( m_aMutex );
424     xPopupMenu          = m_xPopupMenu;
425     xDispatchProvider   = Reference< XDispatchProvider >( m_xFrame, UNO_QUERY );
426     xServiceManager     = m_xServiceManager;
427     xURLTransformer     = m_xURLTransformer;
428     aLock.clear();
429 
430     css::util::URL aTargetURL;
431     Sequence< PropertyValue > aArgsList( 1 );
432 
433     if ( xPopupMenu.is() && xDispatchProvider.is() )
434     {
435         VCLXPopupMenu* pPopupMenu = (VCLXPopupMenu *)VCLXPopupMenu::GetImplementation( xPopupMenu );
436         if ( pPopupMenu )
437         {
438             {
439                 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
440                 PopupMenu* pVCLPopupMenu = (PopupMenu *)pPopupMenu->GetMenu();
441                 aTargetURL.Complete = pVCLPopupMenu->GetItemCommand( rEvent.MenuId );
442             }
443 
444             xURLTransformer->parseStrict( aTargetURL );
445 
446             aArgsList[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Referer" ));
447 	        aArgsList[0].Value = makeAny( ::rtl::OUString::createFromAscii( SFX_REFERER_USER ));
448 
449             rtl::OUString aTargetFrame( m_aTargetFrame );
450             AddInfoForId::const_iterator pItem = m_aAddInfoForItem.find( rEvent.MenuId );
451             if ( pItem != m_aAddInfoForItem.end() )
452                 aTargetFrame = pItem->second.aTargetFrame;
453 
454             xDispatch = xDispatchProvider->queryDispatch( aTargetURL, aTargetFrame, 0 );
455         }
456     }
457 
458     if ( xDispatch.is() )
459     {
460         // Call dispatch asynchronously as we can be destroyed while dispatch is
461         // executed. VCL is not able to survive this as it wants to call listeners
462         // after select!!!
463         NewDocument* pNewDocument = new NewDocument;
464         pNewDocument->xDispatch  = xDispatch;
465         pNewDocument->aTargetURL = aTargetURL;
466         pNewDocument->aArgSeq    = aArgsList;
467         if(::comphelper::UiEventsLogger::isEnabled()) //#i88653#
468             UiEventLogHelper(::rtl::OUString::createFromAscii("NewMenuController")).log(m_xServiceManager, m_xFrame, aTargetURL, aArgsList);
469         Application::PostUserEvent( STATIC_LINK(0, NewMenuController, ExecuteHdl_Impl), pNewDocument );
470     }
471 }
472 
itemActivated(const css::awt::MenuEvent &)473 void SAL_CALL NewMenuController::itemActivated( const css::awt::MenuEvent& ) throw (RuntimeException)
474 {
475     vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
476     if ( m_xFrame.is() && m_xPopupMenu.is() )
477     {
478         VCLXPopupMenu* pPopupMenu = (VCLXPopupMenu *)VCLXPopupMenu::GetImplementation( m_xPopupMenu );
479         if ( pPopupMenu )
480         {
481             const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
482             sal_Bool bShowImages( rSettings.GetUseImagesInMenus() );
483             sal_Bool bHiContrast( rSettings.GetHighContrastMode() );
484 
485             PopupMenu* pVCLPopupMenu = (PopupMenu *)pPopupMenu->GetMenu();
486 
487             if (( m_bShowImages != bShowImages ) ||
488                 ( m_bHiContrast != bHiContrast ))
489             {
490                 m_bShowImages = bShowImages;
491                 m_bHiContrast = bHiContrast;
492 
493                 setMenuImages( pVCLPopupMenu, m_bShowImages, m_bHiContrast );
494             }
495 
496             setAccelerators( pVCLPopupMenu );
497         }
498     }
499 }
500 
501 // XPopupMenuController
impl_setPopupMenu()502 void NewMenuController::impl_setPopupMenu()
503 {
504 
505     if ( m_xPopupMenu.is() )
506         fillPopupMenu( m_xPopupMenu );
507 
508     // Identify module that we are attach to. It's our context that we need to know.
509     Reference< XModuleManager > xModuleManager( m_xServiceManager->createInstance( SERVICENAME_MODULEMANAGER ),UNO_QUERY );
510     if ( xModuleManager.is() )
511     {
512         try
513         {
514             m_aModuleIdentifier = xModuleManager->identify( m_xFrame );
515             m_bModuleIdentified = sal_True;
516 
517             Reference< XNameAccess > xNameAccess( xModuleManager, UNO_QUERY );
518             if (( m_aModuleIdentifier.getLength() > 0 ) && xNameAccess.is() )
519             {
520                 Sequence< PropertyValue > aSeq;
521 
522                 if ( xNameAccess->getByName( m_aModuleIdentifier ) >>= aSeq )
523                 {
524                     for ( sal_Int32 y = 0; y < aSeq.getLength(); y++ )
525                     {
526                         if ( aSeq[y].Name.equalsAscii("ooSetupFactoryEmptyDocumentURL") )
527                         {
528                             aSeq[y].Value >>= m_aEmptyDocURL;
529                             break;
530                         }
531                     }
532                 }
533             }
534         }
535         catch ( RuntimeException& e )
536         {
537             throw e;
538         }
539         catch ( Exception& )
540         {
541         }
542     }
543 }
544 
545 // XInitialization
initialize(const Sequence<Any> & aArguments)546 void SAL_CALL NewMenuController::initialize( const Sequence< Any >& aArguments ) throw ( Exception, RuntimeException )
547 {
548     osl::MutexGuard aLock( m_aMutex );
549 
550     sal_Bool bInitialized( m_bInitialized );
551     if ( !bInitialized )
552     {
553 		svt::PopupMenuControllerBase::initialize( aArguments );
554 
555         if ( m_bInitialized )
556         {
557             const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
558 
559             m_bShowImages   = rSettings.GetUseImagesInMenus();
560             m_bHiContrast   = rSettings.GetHighContrastMode();
561 
562             m_bNewMenu      = m_aCommandURL.equalsAscii( ".uno:AddDirect" );
563         }
564     }
565 }
566 
IMPL_STATIC_LINK_NOINSTANCE(NewMenuController,ExecuteHdl_Impl,NewDocument *,pNewDocument)567 IMPL_STATIC_LINK_NOINSTANCE( NewMenuController, ExecuteHdl_Impl, NewDocument*, pNewDocument )
568 {
569 /*  i62706: Don't catch all exceptions. We hide all problems here and are not able
570             to handle them on higher levels.
571     try
572     {
573 */
574         // Asynchronous execution as this can lead to our own destruction!
575         // Framework can recycle our current frame and the layout manager disposes all user interface
576         // elements if a component gets detached from its frame!
577         pNewDocument->xDispatch->dispatch( pNewDocument->aTargetURL, pNewDocument->aArgSeq );
578 /*
579     }
580     catch (const ::com::sun::star::document::CorruptedFilterConfigurationException& exFilters)
581     {
582         throw exFilters;
583     }
584     catch (const Exception& )
585     {
586     }
587 */
588     delete pNewDocument;
589     return 0;
590 }
591 
592 }
593