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