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/toolbarsmenucontroller.hxx>
30 : :
31 : : #include <algorithm>
32 : :
33 : : #include <threadhelp/resetableguard.hxx>
34 : : #include "services.h"
35 : : #include <classes/resource.hrc>
36 : : #include <classes/fwkresid.hxx>
37 : : #include <uiconfiguration/windowstateconfiguration.hxx>
38 : : #include <framework/imageproducer.hxx>
39 : : #include <framework/sfxhelperfunctions.hxx>
40 : :
41 : : #include <com/sun/star/awt/XDevice.hpp>
42 : : #include <com/sun/star/beans/PropertyValue.hpp>
43 : : #include <com/sun/star/awt/MenuItemStyle.hpp>
44 : : #include <com/sun/star/frame/XDispatchProvider.hpp>
45 : : #include <com/sun/star/container/XNameContainer.hpp>
46 : : #include <com/sun/star/beans/XPropertySet.hpp>
47 : : #include <com/sun/star/frame/XLayoutManager.hpp>
48 : : #include <com/sun/star/ui/XUIElementSettings.hpp>
49 : : #include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
50 : : #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
51 : : #include <com/sun/star/ui/UIElementType.hpp>
52 : :
53 : : #include <vcl/menu.hxx>
54 : : #include <vcl/svapp.hxx>
55 : : #include <vcl/i18nhelp.hxx>
56 : : #include <vcl/image.hxx>
57 : : #include <rtl/ustrbuf.hxx>
58 : : #include <toolkit/unohlp.hxx>
59 : : #include <vcl/window.hxx>
60 : : #include <svtools/menuoptions.hxx>
61 : : #include <unotools/cmdoptions.hxx>
62 : : #include <rtl/logfile.hxx>
63 : : #include <svtools/miscopt.hxx>
64 : :
65 : : //_________________________________________________________________________________________________________________
66 : : // Defines
67 : : //_________________________________________________________________________________________________________________
68 : :
69 : : using namespace ::com::sun::star;
70 : : using namespace ::com::sun::star::uno;
71 : : using namespace ::com::sun::star::lang;
72 : : using namespace ::com::sun::star::frame;
73 : : using namespace ::com::sun::star::beans;
74 : : using namespace ::com::sun::star::util;
75 : : using namespace ::com::sun::star::container;
76 : : using namespace ::com::sun::star::frame;
77 : : using namespace ::com::sun::star::ui;
78 : :
79 : : static const char CONFIGURE_TOOLBARS_CMD[] = "ConfigureDialog";
80 : : static const char CONFIGURE_TOOLBARS[] = ".uno:ConfigureDialog";
81 : : static const char CMD_COLORBAR[] = ".uno:ColorControl";
82 : : static const char CMD_FORMULABAR[] = ".uno:InsertFormula";
83 : : static const char CMD_INPUTLINEBAR[] = ".uno:InputLineVisible";
84 : : static const char CMD_RESTOREVISIBILITY[] = ".cmd:RestoreVisibility";
85 : : static const char ITEM_DESCRIPTOR_RESOURCEURL[] = "ResourceURL";
86 : : static const char ITEM_DESCRIPTOR_UINAME[] = "UIName";
87 : : static const char STATIC_PRIVATE_TB_RESOURCE[] = "private:resource/toolbar/";
88 : :
89 : : static const char STATIC_CMD_PART[] = ".uno:AvailableToolbars?Toolbar:string=";
90 : : static const char STATIC_INTERNAL_CMD_PART[] = ".cmd:";
91 : :
92 : : namespace framework
93 : : {
94 : :
95 : : typedef boost::unordered_map< rtl::OUString, rtl::OUString, OUStringHashCode, ::std::equal_to< ::rtl::OUString > > ToolbarHashMap;
96 : :
97 : 594 : struct ToolBarEntry
98 : : {
99 : : rtl::OUString aUIName;
100 : : rtl::OUString aCommand;
101 : : sal_Bool bVisible;
102 : : sal_Bool bContextSensitive;
103 : : const CollatorWrapper* pCollatorWrapper;
104 : : };
105 : :
106 : 238 : sal_Bool CompareToolBarEntry( const ToolBarEntry& aOne, const ToolBarEntry& aTwo )
107 : : {
108 : 238 : sal_Int32 nComp = aOne.pCollatorWrapper->compareString( aOne.aUIName, aTwo.aUIName );
109 : :
110 [ + + ]: 238 : if ( nComp < 0 )
111 : 148 : return sal_True;
112 : : else
113 : 238 : return sal_False;
114 : : }
115 : :
116 : 2 : Reference< XLayoutManager > getLayoutManagerFromFrame( const Reference< XFrame >& rFrame )
117 : : {
118 [ + - ]: 2 : Reference< XPropertySet > xPropSet( rFrame, UNO_QUERY );
119 : 2 : Reference< XLayoutManager > xLayoutManager;
120 : :
121 : : try
122 : : {
123 [ + - ][ + - ]: 2 : xPropSet->getPropertyValue( rtl::OUString( "LayoutManager" )) >>= xLayoutManager;
[ # # ][ + - ]
124 : : }
125 [ # # ]: 0 : catch ( const UnknownPropertyException& )
126 : : {
127 : : }
128 : :
129 : 2 : return xLayoutManager;
130 : : }
131 : :
132 : 20 : struct ToolBarInfo
133 : : {
134 : : rtl::OUString aToolBarResName;
135 : : rtl::OUString aToolBarUIName;
136 : : };
137 : :
138 [ + - ][ + - ]: 48 : DEFINE_XSERVICEINFO_MULTISERVICE ( ToolbarsMenuController ,
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ # # ]
[ # # ]
139 : : OWeakObject ,
140 : : SERVICENAME_POPUPMENUCONTROLLER ,
141 : : IMPLEMENTATIONNAME_TOOLBARSMENUCONTROLLER
142 : : )
143 : :
144 : 6 : DEFINE_INIT_SERVICE ( ToolbarsMenuController, {} )
145 : :
146 : 6 : ToolbarsMenuController::ToolbarsMenuController( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager ) :
147 : : svt::PopupMenuControllerBase( xServiceManager ),
148 : : m_aPropUIName( "UIName" ),
149 : : m_aPropResourceURL( "ResourceURL" ),
150 : : m_bModuleIdentified( sal_False ),
151 : : m_bResetActive( sal_False ),
152 [ + - ][ + - ]: 6 : m_aIntlWrapper( xServiceManager, Application::GetSettings().GetLocale() )
[ + - ][ + - ]
153 : : {
154 : 6 : }
155 : :
156 [ + - ]: 6 : ToolbarsMenuController::~ToolbarsMenuController()
157 : : {
158 [ - + ]: 12 : }
159 : :
160 : 6 : void ToolbarsMenuController::addCommand(
161 : : Reference< css::awt::XPopupMenu >& rPopupMenu, const rtl::OUString& rCommandURL, const rtl::OUString& rLabel )
162 : : {
163 [ + - ][ + - ]: 6 : sal_uInt16 nItemId = m_xPopupMenu->getItemCount()+1;
164 : :
165 : 6 : rtl::OUString aLabel;
166 [ + + ]: 6 : if ( rLabel.isEmpty() )
167 [ + - ]: 4 : aLabel = getUINameFromCommand( rCommandURL );
168 : : else
169 : 2 : aLabel = rLabel;
170 : :
171 [ + - ][ + - ]: 6 : rPopupMenu->insertItem( nItemId, aLabel, 0, nItemId );
172 [ + - ]: 6 : Reference< awt::XMenuExtended > xMenuExtended( m_xPopupMenu, UNO_QUERY );
173 [ + - ][ + - ]: 6 : xMenuExtended->setCommand( nItemId, rCommandURL );
174 : :
175 : 6 : bool bInternal = ( rCommandURL.indexOf( STATIC_INTERNAL_CMD_PART ) == 0);
176 [ + + ]: 6 : if ( !bInternal )
177 : : {
178 [ + - ][ - + ]: 4 : if ( !getDispatchFromCommandURL( rCommandURL ).is() )
179 [ # # ][ # # ]: 0 : m_xPopupMenu->enableItem( nItemId, sal_False );
180 : : }
181 : :
182 [ + - ]: 6 : SolarMutexGuard aSolarMutexGuard;
183 : :
184 [ + - ]: 6 : Image aImage;
185 [ + - ]: 6 : const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
186 : :
187 [ + - ][ + - ]: 6 : if ( rSettings.GetUseImagesInMenus() )
188 [ + - ][ + - ]: 6 : aImage = GetImageFromURL( m_xFrame, rCommandURL, false );
[ + - ]
189 : :
190 : 6 : VCLXPopupMenu* pPopupMenu = (VCLXPopupMenu *)VCLXPopupMenu::GetImplementation( rPopupMenu );
191 [ + - ]: 6 : if ( pPopupMenu )
192 : : {
193 : 6 : PopupMenu* pVCLPopupMenu = (PopupMenu *)pPopupMenu->GetMenu();
194 [ + + ]: 6 : if ( !!aImage )
195 [ + - ]: 2 : pVCLPopupMenu->SetItemImage( nItemId, aImage );
196 : : }
197 : :
198 [ + - ][ + - ]: 6 : m_aCommandVector.push_back( rCommandURL );
[ + - ]
199 : 6 : }
200 : :
201 : 4 : Reference< XDispatch > ToolbarsMenuController::getDispatchFromCommandURL( const rtl::OUString& rCommandURL )
202 : : {
203 : 4 : URL aTargetURL;
204 [ + - ]: 4 : Sequence<PropertyValue> aArgs;
205 : 4 : Reference< XURLTransformer > xURLTransformer;
206 : 4 : Reference< XFrame > xFrame;
207 : :
208 : : {
209 [ + - ]: 4 : SolarMutexGuard aSolarMutexGuard;
210 [ + - ]: 4 : xURLTransformer = m_xURLTransformer;
211 [ + - ][ + - ]: 4 : xFrame = m_xFrame;
212 : : }
213 : :
214 : 4 : aTargetURL.Complete = rCommandURL;
215 [ + - ][ + - ]: 4 : xURLTransformer->parseStrict( aTargetURL );
216 [ + - ]: 4 : Reference< XDispatchProvider > xDispatchProvider( xFrame, UNO_QUERY );
217 [ + - ]: 4 : if ( xDispatchProvider.is() )
218 [ + - ][ + - ]: 4 : return xDispatchProvider->queryDispatch( aTargetURL, ::rtl::OUString(), 0 );
219 : : else
220 [ + - ]: 4 : return Reference< XDispatch >();
221 : : }
222 : :
223 : : // private function
224 : 4 : rtl::OUString ToolbarsMenuController::getUINameFromCommand( const rtl::OUString& rCommandURL )
225 : : {
226 : 4 : rtl::OUString aLabel;
227 : :
228 [ + - ]: 4 : if ( !m_bModuleIdentified )
229 : : {
230 : : try
231 : : {
232 [ + - ][ + - ]: 4 : Reference< XModuleManager > xModuleManager( m_xServiceManager->createInstance( SERVICENAME_MODULEMANAGER ), UNO_QUERY_THROW );
[ + - ][ + - ]
233 [ + - ][ + - ]: 4 : m_aModuleIdentifier = xModuleManager->identify( m_xFrame );
234 [ + - ]: 4 : Reference< XNameAccess > xNameAccess( m_xServiceManager->createInstance(
235 : 4 : SERVICENAME_UICOMMANDDESCRIPTION ),
236 [ + - ][ + - ]: 4 : UNO_QUERY );
[ + - ]
237 [ + - ][ + - ]: 4 : xNameAccess->getByName( m_aModuleIdentifier ) >>= m_xUICommandDescription;
[ # # ][ + - ]
238 : : }
239 [ # # ]: 0 : catch ( const Exception& )
240 : : {
241 : : }
242 : : }
243 : :
244 [ + - ]: 4 : if ( m_xUICommandDescription.is() )
245 : : {
246 : : try
247 : : {
248 [ + - ]: 4 : Sequence< PropertyValue > aPropSeq;
249 : 4 : rtl::OUString aStr;
250 [ + - ][ + - ]: 4 : if ( m_xUICommandDescription->getByName( rCommandURL ) >>= aPropSeq )
[ + - ][ + - ]
251 : : {
252 [ + - ]: 8 : for ( sal_Int32 i = 0; i < aPropSeq.getLength(); i++ )
253 : : {
254 [ + - ][ + - ]: 4 : if ( aPropSeq[i].Name == "Label" )
255 : : {
256 [ + - ]: 4 : aPropSeq[i].Value >>= aStr;
257 : 4 : break;
258 : : }
259 : : }
260 : : }
261 [ + - ][ # # ]: 4 : aLabel = aStr;
262 : : }
263 [ # # ]: 0 : catch ( const Exception& )
264 : : {
265 : : }
266 : : }
267 : :
268 : 4 : return aLabel;
269 : : }
270 : :
271 : 6 : static void fillHashMap( const Sequence< Sequence< ::com::sun::star::beans::PropertyValue > >& rSeqToolBars,
272 : : ToolbarHashMap& rHashMap )
273 : : {
274 [ + + ]: 86 : for ( sal_Int32 i = 0; i < rSeqToolBars.getLength(); i++ )
275 : : {
276 : 80 : rtl::OUString aResourceURL;
277 : 80 : rtl::OUString aUIName;
278 : 80 : const PropertyValue* pProperties = rSeqToolBars[i].getConstArray();
279 [ + + ]: 240 : for ( sal_Int32 j = 0; j < rSeqToolBars[i].getLength(); j++ )
280 : : {
281 [ + + ]: 160 : if ( pProperties[j].Name.equalsAscii( ITEM_DESCRIPTOR_RESOURCEURL) )
282 : 80 : pProperties[j].Value >>= aResourceURL;
283 [ + - ]: 80 : else if ( pProperties[j].Name.equalsAscii( ITEM_DESCRIPTOR_UINAME) )
284 : 80 : pProperties[j].Value >>= aUIName;
285 : : }
286 : :
287 [ + - + + ]: 240 : if ( !aResourceURL.isEmpty() &&
[ + + ]
288 [ + - ][ + - ]: 160 : rHashMap.find( aResourceURL ) == rHashMap.end() )
[ + - ][ + - ]
[ # # # # ]
289 [ + - ]: 76 : rHashMap.insert( ToolbarHashMap::value_type( aResourceURL, aUIName ));
290 : 80 : }
291 : 6 : }
292 : :
293 : : // private function
294 : 2 : Sequence< Sequence< com::sun::star::beans::PropertyValue > > ToolbarsMenuController::getLayoutManagerToolbars( const Reference< ::com::sun::star::frame::XLayoutManager >& rLayoutManager )
295 : : {
296 [ + - ]: 2 : std::vector< ToolBarInfo > aToolBarArray;
297 [ + - ][ + - ]: 2 : Sequence< Reference< XUIElement > > aUIElements = rLayoutManager->getElements();
298 [ + + ]: 10 : for ( sal_Int32 i = 0; i < aUIElements.getLength(); i++ )
299 : : {
300 [ + - ]: 8 : Reference< XUIElement > xUIElement( aUIElements[i] );
301 [ + - ][ + - ]: 8 : Reference< XPropertySet > xPropSet( aUIElements[i], UNO_QUERY );
302 [ + - ][ + - ]: 8 : if ( xPropSet.is() && xUIElement.is() )
[ + - ]
303 : : {
304 : : try
305 : : {
306 : 8 : rtl::OUString aResName;
307 : 8 : sal_Int16 nType( -1 );
308 [ + - ][ + - ]: 8 : xPropSet->getPropertyValue( rtl::OUString( "Type" )) >>= nType;
309 [ + - ][ + - ]: 8 : xPropSet->getPropertyValue( rtl::OUString( "ResourceURL" )) >>= aResName;
310 : :
311 [ + + ]: 12 : if (( nType == ::com::sun::star::ui::UIElementType::TOOLBAR ) &&
[ + + + - ]
312 : 4 : !aResName.isEmpty() )
313 : : {
314 : 4 : ToolBarInfo aToolBarInfo;
315 : :
316 : 4 : aToolBarInfo.aToolBarResName = aResName;
317 : :
318 [ + - ]: 4 : SolarMutexGuard aGuard;
319 [ + - ][ + - ]: 4 : Reference< css::awt::XWindow > xWindow( xUIElement->getRealInterface(), UNO_QUERY );
[ + - ]
320 [ + - ]: 4 : Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
321 [ + - ]: 4 : if ( pWindow )
322 [ + - ][ + - ]: 4 : aToolBarInfo.aToolBarUIName = pWindow->GetText();
[ + - ]
323 : :
324 [ + - ][ + - ]: 4 : aToolBarArray.push_back( aToolBarInfo );
325 [ # # ]: 8 : }
326 : : }
327 [ # # ]: 0 : catch ( const Exception& )
328 : : {
329 : : }
330 : : }
331 : 8 : }
332 : :
333 [ + - ]: 2 : Sequence< com::sun::star::beans::PropertyValue > aTbSeq( 2 );
334 [ + - ]: 2 : aTbSeq[0].Name = m_aPropUIName;
335 [ + - ]: 2 : aTbSeq[1].Name = m_aPropResourceURL;
336 : :
337 [ + - ]: 2 : Sequence< Sequence< com::sun::star::beans::PropertyValue > > aSeq( aToolBarArray.size() );
338 : 2 : const sal_uInt32 nCount = aToolBarArray.size();
339 [ + + ]: 6 : for ( sal_uInt32 i = 0; i < nCount; i++ )
340 : : {
341 [ + - ][ + - ]: 4 : aTbSeq[0].Value <<= aToolBarArray[i].aToolBarUIName;
342 [ + - ][ + - ]: 4 : aTbSeq[1].Value <<= aToolBarArray[i].aToolBarResName;
343 [ + - ][ + - ]: 4 : aSeq[i] = aTbSeq;
344 : : }
345 : :
346 [ + - ][ + - ]: 2 : return aSeq;
347 : : }
348 : :
349 : 0 : sal_Bool ToolbarsMenuController::isContextSensitiveToolbarNonVisible()
350 : : {
351 : 0 : return m_bResetActive;
352 : : }
353 : :
354 : 2 : void ToolbarsMenuController::fillPopupMenu( Reference< css::awt::XPopupMenu >& rPopupMenu )
355 : : {
356 [ + - ][ + - ]: 2 : if( SvtMiscOptions().DisableUICustomization() )
[ + - ][ + - ]
357 : 2 : return;
358 : :
359 [ + - ]: 2 : SolarMutexGuard aSolarMutexGuard;
360 [ + - ]: 2 : resetPopupMenu( rPopupMenu );
361 : :
362 : 2 : m_aCommandVector.clear();
363 : :
364 : : // Retrieve layout manager for additional information
365 : 2 : rtl::OUString aEmptyString;
366 [ + - ]: 2 : Reference< awt::XMenuExtended > xMenuExtended( rPopupMenu, UNO_QUERY );
367 [ + - ]: 2 : Reference< XLayoutManager > xLayoutManager( getLayoutManagerFromFrame( m_xFrame ));
368 : :
369 : 2 : m_bResetActive = sal_False;
370 [ + - ]: 2 : if ( xLayoutManager.is() )
371 : : {
372 [ + - ]: 2 : ToolbarHashMap aToolbarHashMap;
373 : :
374 [ + - ]: 2 : if ( m_xDocCfgMgr.is() )
375 : : {
376 : : Sequence< Sequence< com::sun::star::beans::PropertyValue > > aSeqDocToolBars =
377 [ + - ][ + - ]: 2 : m_xDocCfgMgr->getUIElementsInfo( UIElementType::TOOLBAR );
378 [ + - ][ + - ]: 2 : fillHashMap( aSeqDocToolBars, aToolbarHashMap );
379 : : }
380 : :
381 [ + - ]: 2 : if ( m_xModuleCfgMgr.is() )
382 : : {
383 : : Sequence< Sequence< com::sun::star::beans::PropertyValue > > aSeqToolBars =
384 [ + - ][ + - ]: 2 : m_xModuleCfgMgr->getUIElementsInfo( UIElementType::TOOLBAR );
385 [ + - ][ + - ]: 2 : fillHashMap( aSeqToolBars, aToolbarHashMap );
386 : : }
387 : :
388 [ + - ]: 2 : std::vector< ToolBarEntry > aSortedTbs;
389 : 2 : rtl::OUString aStaticCmdPart( STATIC_CMD_PART );
390 : :
391 [ + - ]: 2 : Sequence< Sequence< com::sun::star::beans::PropertyValue > > aSeqFrameToolBars = getLayoutManagerToolbars( xLayoutManager );
392 [ + - ]: 2 : fillHashMap( aSeqFrameToolBars, aToolbarHashMap );
393 : :
394 [ + - ]: 2 : ToolbarHashMap::const_iterator pIter = aToolbarHashMap.begin();
395 [ + - ][ + + ]: 78 : while ( pIter != aToolbarHashMap.end() )
396 : : {
397 [ + - ]: 76 : rtl::OUString aUIName = pIter->second;
398 : 76 : sal_Bool bHideFromMenu( sal_False );
399 : 76 : sal_Bool bContextSensitive( sal_False );
400 : 76 : sal_Bool bVisible( sal_False );
401 [ + - ]: 152 : if ( aUIName.isEmpty() &&
[ + - + - ]
402 : 76 : m_xPersistentWindowState.is() )
403 : : {
404 : : try
405 : : {
406 [ + - ]: 76 : Sequence< PropertyValue > aWindowState;
407 [ + - ][ + - ]: 76 : Any a( m_xPersistentWindowState->getByName( pIter->first ));
[ + - ]
408 : :
409 [ + - ][ + - ]: 76 : if ( a >>= aWindowState )
410 : : {
411 [ + + ]: 928 : for ( sal_Int32 i = 0; i < aWindowState.getLength(); i++ )
412 : : {
413 [ + - ][ + + ]: 852 : if ( aWindowState[i].Name.equalsAscii( WINDOWSTATE_PROPERTY_UINAME ))
414 [ + - ]: 76 : aWindowState[i].Value >>= aUIName;
415 [ + - ][ + + ]: 776 : else if ( aWindowState[i].Name.equalsAscii( WINDOWSTATE_PROPERTY_HIDEFROMENU ))
416 [ + - ]: 76 : aWindowState[i].Value >>= bHideFromMenu;
417 [ + - ][ + + ]: 700 : else if ( aWindowState[i].Name.equalsAscii( WINDOWSTATE_PROPERTY_CONTEXT ))
418 [ + - ]: 76 : aWindowState[i].Value >>= bContextSensitive;
419 [ + - ][ + + ]: 624 : else if ( aWindowState[i].Name.equalsAscii( WINDOWSTATE_PROPERTY_VISIBLE ))
420 [ + - ]: 76 : aWindowState[i].Value >>= bVisible;
421 : : }
422 [ + - ][ # # ]: 76 : }
423 : : }
424 [ # # ]: 0 : catch ( const Exception& )
425 : : {
426 : : }
427 : :
428 : : // Check if we have to enable/disable "Reset" menu item
429 [ + + ][ + + ]: 76 : if ( bContextSensitive && !bVisible )
430 : 2 : m_bResetActive = sal_True;
431 : :
432 : : }
433 : :
434 [ + - ][ + + ]: 76 : if ( !aUIName.isEmpty() && !bHideFromMenu )
[ + + ]
435 : : {
436 : 44 : ToolBarEntry aTbEntry;
437 : 44 : aTbEntry.aUIName = aUIName;
438 [ + - ]: 44 : aTbEntry.aCommand = pIter->first;
439 [ + - ][ + - ]: 44 : aTbEntry.bVisible = xLayoutManager->isElementVisible( pIter->first );
[ + - ]
440 : 44 : aTbEntry.bContextSensitive = bContextSensitive;
441 [ + - ]: 44 : aTbEntry.pCollatorWrapper = m_aIntlWrapper.getCaseCollator();
442 [ + - ]: 44 : aSortedTbs.push_back( aTbEntry );
443 : : }
444 : 76 : ++pIter;
445 : 76 : }
446 : :
447 : : // sort toolbars
448 [ + - ]: 2 : std::sort( aSortedTbs.begin(), aSortedTbs.end(), CompareToolBarEntry );
449 : :
450 : 2 : sal_Int16 nIndex( 1 );
451 : 2 : const sal_uInt32 nCount = aSortedTbs.size();
452 [ + + ]: 46 : for ( sal_uInt32 i = 0; i < nCount; i++ )
453 : : {
454 [ + - ][ + - ]: 44 : sal_uInt16 nItemCount = m_xPopupMenu->getItemCount();
455 [ + - ][ + - ]: 44 : m_xPopupMenu->insertItem( nIndex, aSortedTbs[i].aUIName, css::awt::MenuItemStyle::CHECKABLE, nItemCount );
456 [ + + ]: 44 : if ( aSortedTbs[i].bVisible )
457 [ + - ][ + - ]: 4 : m_xPopupMenu->checkItem( nIndex, sal_True );
458 : :
459 : : {
460 [ + - ]: 44 : SolarMutexGuard aGuard;
461 : 44 : VCLXPopupMenu* pXPopupMenu = (VCLXPopupMenu *)VCLXMenu::GetImplementation( m_xPopupMenu );
462 : 44 : PopupMenu* pVCLPopupMenu = (PopupMenu *)pXPopupMenu->GetMenu();
463 : :
464 [ + - ][ + - ]: 44 : pVCLPopupMenu->SetUserValue( nIndex, sal_uIntPtr( aSortedTbs[i].bContextSensitive ? 1L : 0L ));
[ + + ]
465 : : }
466 : :
467 : : // use VCL popup menu pointer to set vital information that are not part of the awt implementation
468 [ + - ]: 44 : rtl::OUStringBuffer aStrBuf( aStaticCmdPart );
469 : :
470 : 44 : sal_Int32 n = aSortedTbs[i].aCommand.lastIndexOf( '/' );
471 [ + - ][ + - ]: 44 : if (( n > 0 ) && (( n+1 ) < aSortedTbs[i].aCommand.getLength() ))
[ + - ]
472 [ + - ]: 44 : aStrBuf.append( aSortedTbs[i].aCommand.copy( n+1 ));
473 : :
474 [ + - ]: 44 : rtl::OUString aCmd( aStrBuf.makeStringAndClear() );
475 : :
476 : : // Store complete uno-command so it can also be dispatched. This is necessary to support
477 : : // the test tool!
478 [ + - ][ + - ]: 44 : xMenuExtended->setCommand( nIndex, aCmd );
479 : 44 : ++nIndex;
480 : 44 : }
481 : :
482 : : // Create commands for non-toolbars
483 [ - + # # : 2 : if ( m_aModuleIdentifier.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.text.TextDocument" ) ) ||
# # # # #
# # # ]
[ + - ]
484 : 0 : m_aModuleIdentifier.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.text.WebDocument" ) ) ||
485 : 0 : m_aModuleIdentifier.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.text.GlobalDocument" ) ) ||
486 : 0 : m_aModuleIdentifier.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.drawing.DrawingDocument" ) ) ||
487 : 0 : m_aModuleIdentifier.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.presentation.PresentationDocument" ) ) ||
488 : 0 : m_aModuleIdentifier.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.sheet.SpreadsheetDocument" ) ))
489 : : {
490 [ + - - + ]: 4 : if ( m_aModuleIdentifier.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.drawing.DrawingDocument" ) ) ||
[ - + ]
491 : 2 : m_aModuleIdentifier.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.presentation.PresentationDocument" ) ))
492 [ # # ]: 0 : addCommand( m_xPopupMenu, rtl::OUString( CMD_COLORBAR ), aEmptyString );
493 [ - + ]: 2 : else if ( m_aModuleIdentifier == "com.sun.star.sheet.SpreadsheetDocument" )
494 [ # # ]: 0 : addCommand( m_xPopupMenu, rtl::OUString( CMD_INPUTLINEBAR ), aEmptyString );
495 : : else
496 [ + - ]: 2 : addCommand( m_xPopupMenu, rtl::OUString( CMD_FORMULABAR ), aEmptyString );
497 : : }
498 : :
499 : 2 : sal_Bool bAddCommand( sal_True );
500 [ + - ]: 2 : SvtCommandOptions aCmdOptions;
501 : 2 : rtl::OUString aConfigureToolbar( CONFIGURE_TOOLBARS );
502 : :
503 [ - + ][ + - ]: 2 : if ( aCmdOptions.HasEntries( SvtCommandOptions::CMDOPTION_DISABLED ))
504 : : {
505 [ # # ]: 0 : if ( aCmdOptions.Lookup( SvtCommandOptions::CMDOPTION_DISABLED,
506 [ # # ]: 0 : rtl::OUString( CONFIGURE_TOOLBARS_CMD )))
507 : 0 : bAddCommand = sal_False;
508 : : }
509 : :
510 [ + - ]: 2 : if ( bAddCommand )
511 : : {
512 : : // Create command for configure
513 [ + - ][ + - ]: 2 : if ( m_xPopupMenu->getItemCount() > 0 )
[ + - ]
514 : : {
515 [ + - ][ + - ]: 2 : sal_uInt16 nItemCount = m_xPopupMenu->getItemCount();
516 [ + - ][ + - ]: 2 : m_xPopupMenu->insertSeparator( nItemCount+1 );
517 : : }
518 : :
519 [ + - ]: 2 : addCommand( m_xPopupMenu, aConfigureToolbar, aEmptyString );
520 : : }
521 : :
522 : : // Add separator if no configure has been added
523 [ - + ]: 2 : if ( !bAddCommand )
524 : : {
525 : : // Create command for configure
526 [ # # ][ # # ]: 0 : if ( m_xPopupMenu->getItemCount() > 0 )
[ # # ]
527 : : {
528 [ # # ][ # # ]: 0 : sal_uInt16 nItemCount = m_xPopupMenu->getItemCount();
529 [ # # ][ # # ]: 0 : m_xPopupMenu->insertSeparator( nItemCount+1 );
530 : : }
531 : : }
532 : :
533 [ + - ][ + - ]: 2 : String aLabelStr = String( FwkResId( STR_RESTORE_TOOLBARS ));
534 : 2 : rtl::OUString aRestoreCmd( CMD_RESTOREVISIBILITY );
535 [ + - ][ + - ]: 2 : addCommand( m_xPopupMenu, aRestoreCmd, aLabelStr );
[ + - ][ + - ]
[ + - ][ + - ]
536 [ + - ]: 2 : }
537 : : }
538 : :
539 : : // XEventListener
540 : 2 : void SAL_CALL ToolbarsMenuController::disposing( const EventObject& ) throw ( RuntimeException )
541 : : {
542 [ + - ]: 2 : Reference< css::awt::XMenuListener > xHolder(( OWeakObject *)this, UNO_QUERY );
543 : :
544 [ + - ]: 2 : osl::MutexGuard aLock( m_aMutex );
545 : 2 : m_xFrame.clear();
546 : 2 : m_xDispatch.clear();
547 : 2 : m_xDocCfgMgr.clear();
548 : 2 : m_xModuleCfgMgr.clear();
549 : 2 : m_xServiceManager.clear();
550 : :
551 [ + - ]: 2 : if ( m_xPopupMenu.is() )
552 [ + - ][ + - ]: 2 : m_xPopupMenu->removeMenuListener( Reference< css::awt::XMenuListener >(( OWeakObject *)this, UNO_QUERY ));
[ + - ]
553 [ + - ]: 2 : m_xPopupMenu.clear();
554 : 2 : }
555 : :
556 : : // XStatusListener
557 : 2 : void SAL_CALL ToolbarsMenuController::statusChanged( const FeatureStateEvent& Event ) throw ( RuntimeException )
558 : : {
559 : 2 : rtl::OUString aFeatureURL( Event.FeatureURL.Complete );
560 : :
561 : : // All other status events will be processed here
562 : 2 : sal_Bool bSetCheckmark = sal_False;
563 : 2 : sal_Bool bCheckmark = sal_False;
564 : :
565 [ + - ]: 2 : osl::ClearableMutexGuard aLock( m_aMutex );
566 : 2 : Reference< css::awt::XPopupMenu > xPopupMenu( m_xPopupMenu );
567 [ + - ]: 2 : aLock.clear();
568 : :
569 [ - + ]: 2 : if ( xPopupMenu.is() )
570 : : {
571 [ # # ]: 0 : SolarMutexGuard aGuard;
572 : 0 : VCLXPopupMenu* pXPopupMenu = (VCLXPopupMenu *)VCLXMenu::GetImplementation( xPopupMenu );
573 : 0 : PopupMenu* pVCLPopupMenu = (PopupMenu *)pXPopupMenu->GetMenu();
574 : :
575 [ # # ][ # # ]: 0 : for ( sal_uInt16 i = 0; i < pVCLPopupMenu->GetItemCount(); i++ )
576 : : {
577 [ # # ]: 0 : sal_uInt16 nId = pVCLPopupMenu->GetItemId( i );
578 [ # # ]: 0 : if ( nId == 0 )
579 : 0 : continue;
580 : :
581 [ # # ][ # # ]: 0 : rtl::OUString aCmd = pVCLPopupMenu->GetItemCommand( nId );
582 [ # # ]: 0 : if ( aCmd == aFeatureURL )
583 : : {
584 : : // Enable/disable item
585 [ # # ]: 0 : pVCLPopupMenu->EnableItem( nId, Event.IsEnabled );
586 : :
587 : : // Checkmark
588 [ # # ]: 0 : if ( Event.State >>= bCheckmark )
589 : 0 : bSetCheckmark = sal_True;
590 : :
591 [ # # ]: 0 : if ( bSetCheckmark )
592 [ # # ]: 0 : pVCLPopupMenu->CheckItem( nId, bCheckmark );
593 : : else
594 : : {
595 : 0 : rtl::OUString aItemText;
596 : :
597 [ # # ]: 0 : if ( Event.State >>= aItemText )
598 [ # # ][ # # ]: 0 : pVCLPopupMenu->SetItemText( nId, aItemText );
[ # # ]
599 : : }
600 : : }
601 [ # # ]: 0 : }
602 [ + - ]: 2 : }
603 : 2 : }
604 : :
605 : : // XMenuListener
606 : 0 : void SAL_CALL ToolbarsMenuController::select( const css::awt::MenuEvent& rEvent ) throw (RuntimeException)
607 : : {
608 : 0 : Reference< css::awt::XPopupMenu > xPopupMenu;
609 : 0 : Reference< XMultiServiceFactory > xServiceManager;
610 : 0 : Reference< XURLTransformer > xURLTransformer;
611 : 0 : Reference< XFrame > xFrame;
612 : 0 : Reference< XNameAccess > xPersistentWindowState;
613 : :
614 [ # # ]: 0 : osl::ClearableMutexGuard aLock( m_aMutex );
615 [ # # ]: 0 : xPopupMenu = m_xPopupMenu;
616 [ # # ]: 0 : xServiceManager = m_xServiceManager;
617 [ # # ]: 0 : xURLTransformer = m_xURLTransformer;
618 [ # # ]: 0 : xFrame = m_xFrame;
619 [ # # ]: 0 : xPersistentWindowState = m_xPersistentWindowState;
620 [ # # ]: 0 : aLock.clear();
621 : :
622 [ # # ]: 0 : if ( xPopupMenu.is() )
623 : : {
624 : 0 : VCLXPopupMenu* pPopupMenu = (VCLXPopupMenu *)VCLXPopupMenu::GetImplementation( xPopupMenu );
625 [ # # ]: 0 : if ( pPopupMenu )
626 : : {
627 [ # # ]: 0 : SolarMutexGuard aSolarMutexGuard;
628 : 0 : PopupMenu* pVCLPopupMenu = (PopupMenu *)pPopupMenu->GetMenu();
629 : :
630 [ # # ][ # # ]: 0 : rtl::OUString aCmd( pVCLPopupMenu->GetItemCommand( rEvent.MenuId ));
631 [ # # ]: 0 : if ( aCmd.indexOf( STATIC_INTERNAL_CMD_PART ) == 0 )
632 : : {
633 : : // Command to restore the visibility of all context sensitive toolbars
634 [ # # ]: 0 : Reference< XNameReplace > xNameReplace( xPersistentWindowState, UNO_QUERY );
635 [ # # ][ # # ]: 0 : if ( xPersistentWindowState.is() && xNameReplace.is() )
[ # # ]
636 : : {
637 : : try
638 : : {
639 [ # # ][ # # ]: 0 : Sequence< rtl::OUString > aElementNames = xPersistentWindowState->getElementNames();
640 : 0 : sal_Int32 nCount = aElementNames.getLength();
641 : 0 : bool bRefreshToolbars( false );
642 : :
643 [ # # ]: 0 : for ( sal_Int32 i = 0; i < nCount; i++ )
644 : : {
645 : : try
646 : : {
647 [ # # ]: 0 : rtl::OUString aElementName = aElementNames[i];
648 [ # # ]: 0 : Sequence< PropertyValue > aWindowState;
649 : :
650 [ # # ][ # # ]: 0 : if ( xPersistentWindowState->getByName( aElementName ) >>= aWindowState )
[ # # ][ # # ]
651 : : {
652 : 0 : sal_Bool bVisible( sal_False );
653 : 0 : sal_Bool bContextSensitive( sal_False );
654 : 0 : sal_Int32 nVisibleIndex( -1 );
655 [ # # ]: 0 : for ( sal_Int32 j = 0; j < aWindowState.getLength(); j++ )
656 : : {
657 [ # # ][ # # ]: 0 : if ( aWindowState[j].Name.equalsAscii( WINDOWSTATE_PROPERTY_VISIBLE ))
658 : : {
659 [ # # ]: 0 : aWindowState[j].Value >>= bVisible;
660 : 0 : nVisibleIndex = j;
661 : : }
662 [ # # ][ # # ]: 0 : else if ( aWindowState[j].Name.equalsAscii( WINDOWSTATE_PROPERTY_CONTEXT ))
663 [ # # ]: 0 : aWindowState[j].Value >>= bContextSensitive;
664 : : }
665 : :
666 [ # # ][ # # ]: 0 : if ( !bVisible && bContextSensitive && nVisibleIndex >= 0 )
[ # # ]
667 : : {
668 : : // Default is: Every context sensitive toolbar is visible
669 [ # # ][ # # ]: 0 : aWindowState[nVisibleIndex].Value <<= sal_True;
670 [ # # ][ # # ]: 0 : xNameReplace->replaceByName( aElementName, makeAny( aWindowState ));
[ # # ]
671 : 0 : bRefreshToolbars = true;
672 : : }
673 [ # # ][ # # ]: 0 : }
674 : : }
675 [ # # ]: 0 : catch ( const NoSuchElementException& )
676 : : {
677 : : }
678 : : }
679 : :
680 [ # # ]: 0 : if ( bRefreshToolbars )
681 : : {
682 [ # # ]: 0 : Reference< XLayoutManager > xLayoutManager( getLayoutManagerFromFrame( xFrame ));
683 [ # # ]: 0 : if ( xLayoutManager.is() )
684 : : {
685 [ # # ]: 0 : Reference< XPropertySet > xPropSet( xLayoutManager, UNO_QUERY );
686 [ # # ]: 0 : if ( xPropSet.is() )
687 : : {
688 : : try
689 : : {
690 [ # # ][ # # ]: 0 : xPropSet->setPropertyValue( rtl::OUString( "RefreshContextToolbarVisibility" ), makeAny( sal_True ));
[ # # ]
[ # # # ]
691 : : }
692 [ # # ]: 0 : catch ( const RuntimeException& )
693 : : {
694 : : }
695 [ # # ]: 0 : catch ( const Exception& )
696 : : {
697 : : }
698 : 0 : }
699 : : }
700 [ # # ]: 0 : RefreshToolbars( xFrame );
701 [ # # ]: 0 : }
702 : : }
703 [ # # # ]: 0 : catch ( const RuntimeException& )
704 : : {
705 : 0 : throw;
706 : : }
707 [ # # ]: 0 : catch ( const Exception& )
708 : : {
709 : : }
710 : 0 : }
711 : : }
712 [ # # ]: 0 : else if ( aCmd.indexOf( STATIC_CMD_PART ) < 0 )
713 : : {
714 : 0 : URL aTargetURL;
715 [ # # ]: 0 : Sequence<PropertyValue> aArgs;
716 : :
717 : 0 : aTargetURL.Complete = aCmd;
718 [ # # ][ # # ]: 0 : xURLTransformer->parseStrict( aTargetURL );
719 [ # # ]: 0 : Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY );
720 [ # # ]: 0 : if ( xDispatchProvider.is() )
721 : : {
722 [ # # ]: 0 : Reference< XDispatch > xDispatch = xDispatchProvider->queryDispatch(
723 [ # # ]: 0 : aTargetURL, ::rtl::OUString(), 0 );
724 : :
725 [ # # ][ # # ]: 0 : ExecuteInfo* pExecuteInfo = new ExecuteInfo;
726 [ # # ]: 0 : pExecuteInfo->xDispatch = xDispatch;
727 : 0 : pExecuteInfo->aTargetURL = aTargetURL;
728 [ # # ]: 0 : pExecuteInfo->aArgs = aArgs;
729 [ # # ][ # # ]: 0 : Application::PostUserEvent( STATIC_LINK(0, ToolbarsMenuController, ExecuteHdl_Impl), pExecuteInfo );
730 [ # # ]: 0 : }
731 : : }
732 : : else
733 : : {
734 [ # # ]: 0 : Reference< XLayoutManager > xLayoutManager( getLayoutManagerFromFrame( xFrame ));
735 [ # # ]: 0 : if ( xLayoutManager.is() )
736 : : {
737 : : // Extract toolbar name from the combined uno-command.
738 : 0 : sal_Int32 nIndex = aCmd.indexOf( '=' );
739 [ # # ][ # # ]: 0 : if (( nIndex > 0 ) && (( nIndex+1 ) < aCmd.getLength() ))
[ # # ]
740 : : {
741 [ # # ][ # # ]: 0 : rtl::OUStringBuffer aBuf( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STATIC_PRIVATE_TB_RESOURCE )));
742 [ # # ]: 0 : aBuf.append( aCmd.copy( nIndex+1 ));
743 : :
744 [ # # ]: 0 : sal_Bool bShow( !pVCLPopupMenu->IsItemChecked( rEvent.MenuId ));
745 [ # # ]: 0 : rtl::OUString aToolBarResName( aBuf.makeStringAndClear() );
746 [ # # ]: 0 : if ( bShow )
747 : : {
748 [ # # ][ # # ]: 0 : xLayoutManager->createElement( aToolBarResName );
749 [ # # ][ # # ]: 0 : xLayoutManager->showElement( aToolBarResName );
750 : : }
751 : : else
752 : : {
753 : : // closing means:
754 : : // hide and destroy element
755 [ # # ][ # # ]: 0 : xLayoutManager->hideElement( aToolBarResName );
756 [ # # ][ # # ]: 0 : xLayoutManager->destroyElement( aToolBarResName );
757 : 0 : }
758 : : }
759 : 0 : }
760 [ # # ]: 0 : }
761 : : }
762 [ # # ]: 0 : }
763 : 0 : }
764 : :
765 : 0 : void SAL_CALL ToolbarsMenuController::activate( const css::awt::MenuEvent& ) throw (RuntimeException)
766 : : {
767 [ # # ]: 0 : std::vector< rtl::OUString > aCmdVector;
768 [ # # ]: 0 : Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY );
769 : 0 : Reference< XURLTransformer > xURLTransformer( m_xURLTransformer );
770 : : {
771 [ # # ]: 0 : osl::MutexGuard aLock( m_aMutex );
772 [ # # ]: 0 : fillPopupMenu( m_xPopupMenu );
773 [ # # ][ # # ]: 0 : aCmdVector = m_aCommandVector;
774 : : }
775 : :
776 : : // Update status for all commands inside our toolbars popup menu
777 : 0 : const sal_uInt32 nCount = aCmdVector.size();
778 [ # # ]: 0 : for ( sal_uInt32 i = 0; i < nCount; i++ )
779 : : {
780 : 0 : bool bInternal = ( aCmdVector[i].indexOf( STATIC_INTERNAL_CMD_PART ) == 0);
781 : :
782 [ # # ]: 0 : if ( !bInternal )
783 : : {
784 : 0 : URL aTargetURL;
785 : 0 : aTargetURL.Complete = aCmdVector[i];
786 [ # # ][ # # ]: 0 : xURLTransformer->parseStrict( aTargetURL );
787 [ # # ][ # # ]: 0 : Reference< XDispatch > xDispatch = xDispatchProvider->queryDispatch( aTargetURL, ::rtl::OUString(), 0 );
788 [ # # ]: 0 : if ( xDispatch.is() )
789 : : {
790 [ # # ][ # # ]: 0 : xDispatch->addStatusListener( (static_cast< XStatusListener* >(this)), aTargetURL );
[ # # ]
791 [ # # ][ # # ]: 0 : xDispatch->removeStatusListener( (static_cast< XStatusListener* >(this)), aTargetURL );
[ # # ]
792 : 0 : }
793 : : }
794 [ # # ]: 0 : else if ( aCmdVector[i].equalsAscii( CMD_RESTOREVISIBILITY ))
795 : : {
796 : : // Special code to determine the enable/disable state of this command
797 [ # # ]: 0 : FeatureStateEvent aFeatureStateEvent;
798 : 0 : aFeatureStateEvent.FeatureURL.Complete = aCmdVector[i];
799 : 0 : aFeatureStateEvent.IsEnabled = isContextSensitiveToolbarNonVisible();
800 [ # # ][ # # ]: 0 : statusChanged( aFeatureStateEvent );
801 : : }
802 : 0 : }
803 : 0 : }
804 : :
805 : : // XPopupMenuController
806 : 4 : void SAL_CALL ToolbarsMenuController::setPopupMenu( const Reference< css::awt::XPopupMenu >& xPopupMenu ) throw ( RuntimeException )
807 : : {
808 [ + - ]: 4 : osl::MutexGuard aLock( m_aMutex );
809 : :
810 [ + - ]: 4 : throwIfDisposed();
811 : :
812 [ + + ][ + - ]: 4 : if ( m_xFrame.is() && !m_xPopupMenu.is() )
[ + + ]
813 : : {
814 : : // Create popup menu on demand
815 [ + - ]: 2 : SolarMutexGuard aSolarMutexGuard;
816 : :
817 [ + - ]: 2 : m_xPopupMenu = xPopupMenu;
818 [ + - ][ + - ]: 2 : m_xPopupMenu->addMenuListener( Reference< css::awt::XMenuListener >( (OWeakObject*)this, UNO_QUERY ));
[ + - ]
819 [ + - ][ + - ]: 2 : fillPopupMenu( m_xPopupMenu );
820 [ + - ]: 4 : }
821 : 4 : }
822 : :
823 : : // XInitialization
824 : 4 : void SAL_CALL ToolbarsMenuController::initialize( const Sequence< Any >& aArguments ) throw ( Exception, RuntimeException )
825 : : {
826 [ + - ]: 4 : osl::MutexGuard aLock( m_aMutex );
827 : 4 : sal_Bool bInitalized( m_bInitialized );
828 [ + - ]: 4 : if ( !bInitalized )
829 : : {
830 [ + - ]: 4 : svt::PopupMenuControllerBase::initialize(aArguments);
831 : :
832 [ + + ]: 4 : if ( m_bInitialized )
833 : : {
834 [ + - ]: 2 : Reference< XModuleManager > xModuleManager( m_xServiceManager->createInstance(
835 : 2 : SERVICENAME_MODULEMANAGER ),
836 [ + - ][ + - ]: 2 : UNO_QUERY );
[ + - ]
837 [ + - ]: 2 : Reference< XNameAccess > xPersistentWindowStateSupplier( m_xServiceManager->createInstance(
838 : 2 : SERVICENAME_WINDOWSTATECONFIGURATION ),
839 [ + - ][ + - ]: 2 : UNO_QUERY );
[ + - ]
840 : :
841 : : // Retrieve persistent window state reference for our module
842 [ + - ][ + - ]: 2 : if ( xPersistentWindowStateSupplier.is() && xModuleManager.is() )
[ + - ]
843 : : {
844 : 2 : rtl::OUString aModuleIdentifier;
845 : : try
846 : : {
847 [ + - ][ + - ]: 2 : aModuleIdentifier = xModuleManager->identify( m_xFrame );
848 [ + - ][ + - ]: 2 : xPersistentWindowStateSupplier->getByName( aModuleIdentifier ) >>= m_xPersistentWindowState;
[ + - ]
849 : :
850 : 2 : Reference< XModuleUIConfigurationManagerSupplier > xModuleCfgSupplier;
851 [ + - ]: 2 : if ( m_xServiceManager.is() )
852 : : xModuleCfgSupplier = Reference< XModuleUIConfigurationManagerSupplier >(
853 [ + - ][ + - ]: 2 : m_xServiceManager->createInstance( SERVICENAME_MODULEUICONFIGURATIONMANAGERSUPPLIER ), UNO_QUERY );
[ + - ][ + - ]
[ + - ]
854 [ + - ][ + - ]: 2 : m_xModuleCfgMgr = xModuleCfgSupplier->getUIConfigurationManager( aModuleIdentifier );
[ + - ]
855 : :
856 [ + - ][ + - ]: 2 : Reference< XController > xController = m_xFrame->getController();
857 : 2 : Reference< XModel > xModel;
858 [ + - ]: 2 : if ( xController.is() )
859 [ + - ][ + - ]: 2 : xModel = xController->getModel();
[ + - ]
860 [ + - ]: 2 : if ( xModel.is() )
861 : : {
862 [ + - ]: 2 : Reference< XUIConfigurationManagerSupplier > xUIConfigurationManagerSupplier( xModel, UNO_QUERY );
863 [ + - ]: 2 : if ( xUIConfigurationManagerSupplier.is() )
864 [ + - ][ + - ]: 2 : m_xDocCfgMgr = xUIConfigurationManagerSupplier->getUIConfigurationManager();
[ + - ]
865 : : }
866 [ # # ]: 2 : m_aModuleIdentifier = aModuleIdentifier;
867 : : }
868 [ # # ]: 0 : catch ( const Exception& )
869 : : {
870 : 2 : }
871 : 2 : }
872 : : }
873 [ + - ]: 4 : }
874 : 4 : }
875 : :
876 : 0 : IMPL_STATIC_LINK_NOINSTANCE( ToolbarsMenuController, ExecuteHdl_Impl, ExecuteInfo*, pExecuteInfo )
877 : : {
878 : : try
879 : : {
880 : : // Asynchronous execution as this can lead to our own destruction!
881 : : // Framework can recycle our current frame and the layout manager disposes all user interface
882 : : // elements if a component gets detached from its frame!
883 [ # # ]: 0 : if ( pExecuteInfo->xDispatch.is() )
884 : : {
885 [ # # ][ # # ]: 0 : pExecuteInfo->xDispatch->dispatch( pExecuteInfo->aTargetURL, pExecuteInfo->aArgs );
886 : : }
887 : : }
888 : 0 : catch ( const Exception& )
889 : : {
890 : : }
891 : :
892 [ # # ]: 0 : delete pExecuteInfo;
893 [ # # ]: 0 : return 0;
894 : : }
895 : :
896 : : }
897 : :
898 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|