merge the formfield patch from ooo-build
[ooovba.git] / framework / source / uielement / toolbarmanager.cxx
bloba231703e591f8013837a97004ed18f809e3e8b28
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: toolbarmanager.cxx,v $
10 * $Revision: 1.42 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_framework.hxx"
33 #include <uielement/toolbarmanager.hxx>
35 //_________________________________________________________________________________________________________________
36 // my own includes
37 //_________________________________________________________________________________________________________________
40 #ifndef __FRAMEWORK_UIELEMENT_TOOLBAR_HXX
41 #include <uielement/toolbar.hxx>
42 #endif
43 #ifndef __FRAMEWORK_UIELEMENT_GENERICTOOLBARCONTROLLER_HXX
44 #include <uielement/generictoolbarcontroller.hxx>
45 #endif
46 #include <threadhelp/resetableguard.hxx>
47 #include "services.h"
48 #include "general.h"
49 #include "properties.h"
50 #include <helper/imageproducer.hxx>
51 #include <classes/sfxhelperfunctions.hxx>
52 #include <classes/fwkresid.hxx>
53 #ifndef __FRAMEWORK_CLASES_RESOURCE_HRC_
54 #include <classes/resource.hrc>
55 #endif
56 #include <classes/addonsoptions.hxx>
57 #include <uielement/toolbarmerger.hxx>
59 //_________________________________________________________________________________________________________________
60 // interface includes
61 //_________________________________________________________________________________________________________________
62 #include <com/sun/star/ui/ItemType.hpp>
63 #include <com/sun/star/frame/XDispatchProvider.hpp>
64 #include <com/sun/star/beans/XPropertySet.hpp>
65 #include <com/sun/star/awt/XDockableWindow.hpp>
66 #include <com/sun/star/frame/XLayoutManager.hpp>
67 #ifndef _COM_SUN_STAR_UI_XDOCKINGAREA_HPP_
68 #include <com/sun/star/ui/DockingArea.hpp>
69 #endif
70 #include <com/sun/star/graphic/XGraphic.hpp>
71 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
72 #include <com/sun/star/frame/XModuleManager.hpp>
73 #include <com/sun/star/ui/XUIElementSettings.hpp>
74 #include <com/sun/star/ui/XUIConfigurationPersistence.hpp>
75 #include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
76 #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
77 #include <com/sun/star/ui/ImageType.hpp>
78 #include <com/sun/star/ui/UIElementType.hpp>
79 #include <comphelper/sequence.hxx>
80 #include <com/sun/star/frame/status/Visibility.hpp>
82 //_________________________________________________________________________________________________________________
83 // other includes
84 //_________________________________________________________________________________________________________________
85 #include <svtools/imgdef.hxx>
86 #include <svtools/toolboxcontroller.hxx>
87 #include <svtools/cmdoptions.hxx>
88 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
89 #include <toolkit/unohlp.hxx>
90 #endif
91 #include <comphelper/mediadescriptor.hxx>
92 #include <svtools/miscopt.hxx>
93 #include <svtools/imageitm.hxx>
94 #include <svtools/framestatuslistener.hxx>
95 #include <vcl/svapp.hxx>
96 #include <vcl/menu.hxx>
97 #include <vcl/syswin.hxx>
98 #include <vcl/taskpanelist.hxx>
99 #include <rtl/logfile.hxx>
100 #include <svtools/menuoptions.hxx>
101 #include <svtools/cmdoptions.hxx>
102 #include <boost/bind.hpp>
104 //_________________________________________________________________________________________________________________
105 // namespaces
106 //_________________________________________________________________________________________________________________
108 using namespace ::com::sun::star::awt;
109 using namespace ::com::sun::star::beans;
110 using namespace ::com::sun::star::uno;
111 using namespace ::com::sun::star::lang;
112 using namespace ::com::sun::star::frame;
113 using namespace ::com::sun::star::graphic;
114 using namespace ::com::sun::star::util;
115 using namespace ::com::sun::star::container;
116 using namespace ::com::sun::star::frame;
117 using namespace ::com::sun::star::ui;
119 namespace framework
122 static const char ITEM_DESCRIPTOR_COMMANDURL[] = "CommandURL";
123 static const char ITEM_DESCRIPTOR_HELPURL[] = "HelpURL";
124 static const char ITEM_DESCRIPTOR_TOOLTIP[] = "Tooltip";
125 static const char ITEM_DESCRIPTOR_CONTAINER[] = "ItemDescriptorContainer";
126 static const char ITEM_DESCRIPTOR_LABEL[] = "Label";
127 static const char ITEM_DESCRIPTOR_TYPE[] = "Type";
128 static const char ITEM_DESCRIPTOR_VISIBLE[] = "IsVisible";
129 static const char ITEM_DESCRIPTOR_WIDTH[] = "Width";
130 static const char ITEM_DESCRIPTOR_STYLE[] = "Style";
132 static const sal_Int32 ITEM_DESCRIPTOR_COMMANDURL_LEN = 10;
133 static const sal_Int32 ITEM_DESCRIPTOR_HELPURL_LEN = 7;
134 static const sal_Int32 ITEM_DESCRIPTOR_TOOLTIP_LEN = 7;
135 static const sal_Int32 ITEM_DESCRIPTOR_CONTAINER_LEN = 23;
136 static const sal_Int32 ITEM_DESCRIPTOR_LABEL_LEN = 5;
137 static const sal_Int32 ITEM_DESCRIPTOR_TYPE_LEN = 4;
138 static const sal_Int32 ITEM_DESCRIPTOR_VISIBLE_LEN = 9;
139 static const sal_Int32 ITEM_DESCRIPTOR_WIDTH_LEN = 5;
140 static const sal_Int32 ITEM_DESCRIPTOR_STYLE_LEN = 5;
142 static const char HELPID_PREFIX[] = "helpid:";
143 static const char HELPID_PREFIX_TESTTOOL[] = ".HelpId:";
144 //static sal_Int32 HELPID_PREFIX_LENGTH = 7;
145 static const USHORT STARTID_CUSTOMIZE_POPUPMENU = 1000;
148 class ImageOrientationListener : public svt::FrameStatusListener
150 public:
151 ImageOrientationListener( const Reference< XStatusListener > rReceiver,
152 const Reference< XMultiServiceFactory > rServiceManager,
153 const Reference< XFrame > rFrame );
154 virtual ~ImageOrientationListener();
156 virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event ) throw ( ::com::sun::star::uno::RuntimeException );
158 private:
159 Reference< XStatusListener > m_xReceiver;
162 ImageOrientationListener::ImageOrientationListener(
163 const Reference< XStatusListener > rReceiver,
164 const Reference< XMultiServiceFactory > rServiceManager,
165 const Reference< XFrame > rFrame ) :
166 FrameStatusListener( rServiceManager, rFrame ),
167 m_xReceiver( rReceiver )
171 ImageOrientationListener::~ImageOrientationListener()
175 void SAL_CALL ImageOrientationListener::statusChanged( const FeatureStateEvent& Event )
176 throw ( RuntimeException )
178 if ( m_xReceiver.is() )
179 m_xReceiver->statusChanged( Event );
182 //*****************************************************************************************************************
184 static sal_Int16 getImageTypeFromBools( sal_Bool bBig, sal_Bool bHighContrast )
186 sal_Int16 n( 0 );
187 if ( bBig )
188 n |= ::com::sun::star::ui::ImageType::SIZE_LARGE;
189 if ( bHighContrast )
190 n |= ::com::sun::star::ui::ImageType::COLOR_HIGHCONTRAST;
191 return n;
194 static ::com::sun::star::uno::Reference< ::com::sun::star::frame::XLayoutManager > getLayoutManagerFromFrame(
195 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame )
197 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
199 Reference< XPropertySet > xPropSet( rFrame, UNO_QUERY );
200 if ( xPropSet.is() )
204 xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ))) >>= xLayoutManager;
206 catch ( RuntimeException& )
208 throw;
210 catch ( Exception& )
215 return xLayoutManager;
218 //*****************************************************************************************************************
219 // XInterface, XTypeProvider, XServiceInfo
220 //*****************************************************************************************************************
221 DEFINE_XINTERFACE_6 ( ToolBarManager ,
222 OWeakObject ,
223 DIRECT_INTERFACE( ::com::sun::star::lang::XTypeProvider ),
224 DIRECT_INTERFACE( ::com::sun::star::lang::XComponent ),
225 DIRECT_INTERFACE( ::com::sun::star::frame::XFrameActionListener ),
226 DIRECT_INTERFACE( ::com::sun::star::ui::XUIConfigurationListener ),
227 DIRECT_INTERFACE( ::com::sun::star::frame::XStatusListener ),
228 DERIVED_INTERFACE( ::com::sun::star::lang::XEventListener, ::com::sun::star::frame::XFrameActionListener )
231 DEFINE_XTYPEPROVIDER_6 ( ToolBarManager ,
232 ::com::sun::star::lang::XTypeProvider ,
233 ::com::sun::star::lang::XComponent ,
234 ::com::sun::star::ui::XUIConfigurationListener ,
235 ::com::sun::star::frame::XFrameActionListener ,
236 ::com::sun::star::frame::XStatusListener ,
237 ::com::sun::star::lang::XEventListener
240 ToolBarManager::ToolBarManager( const Reference< XMultiServiceFactory >& rServiceManager,
241 const Reference< XFrame >& rFrame,
242 const rtl::OUString& rResourceName,
243 ToolBar* pToolBar ) :
244 ThreadHelpBase( &Application::GetSolarMutex() ),
245 OWeakObject(),
246 m_bDisposed( sal_False ),
247 m_bIsHiContrast( pToolBar->GetSettings().GetStyleSettings().GetHighContrastMode() ),
248 m_bSmallSymbols( !SvtMiscOptions().AreCurrentSymbolsLarge() ),
249 m_bModuleIdentified( sal_False ),
250 m_bAddedToTaskPaneList( sal_True ),
251 m_bFrameActionRegistered( sal_False ),
252 m_bUpdateControllers( sal_False ),
253 m_bImageOrientationRegistered( sal_False ),
254 m_bImageMirrored( sal_False ),
255 m_bCanBeCustomized( !SvtMiscOptions().DisableUICustomization() ),
256 m_lImageRotation( 0 ),
257 m_pToolBar( pToolBar ),
258 m_aResourceName( rResourceName ),
259 m_xFrame( rFrame ),
260 m_aListenerContainer( m_aLock.getShareableOslMutex() ),
261 m_xServiceManager( rServiceManager ),
262 m_nSymbolsStyle( SvtMiscOptions().GetCurrentSymbolsStyle() )
264 Window* pWindow = m_pToolBar;
265 while ( pWindow && !pWindow->IsSystemWindow() )
266 pWindow = pWindow->GetParent();
268 if ( pWindow )
269 ((SystemWindow *)pWindow)->GetTaskPaneList()->AddWindow( m_pToolBar );
271 if ( m_xServiceManager.is() )
273 m_xToolbarControllerRegistration = Reference< XUIControllerRegistration >(
274 m_xServiceManager->createInstance( SERVICENAME_TOOLBARCONTROLLERFACTORY ),
275 UNO_QUERY );
277 m_xURLTransformer.set( m_xServiceManager->createInstance(
278 SERVICENAME_URLTRANSFORMER),
279 UNO_QUERY );
282 m_pToolBar->SetSelectHdl( LINK( this, ToolBarManager, Select) );
283 m_pToolBar->SetActivateHdl( LINK( this, ToolBarManager, Activate) );
284 m_pToolBar->SetDeactivateHdl( LINK( this, ToolBarManager, Deactivate) );
285 m_pToolBar->SetClickHdl( LINK( this, ToolBarManager, Click ) );
286 m_pToolBar->SetDropdownClickHdl( LINK( this, ToolBarManager, DropdownClick ) );
287 m_pToolBar->SetDoubleClickHdl( LINK( this, ToolBarManager, DoubleClick ) );
288 m_pToolBar->SetStateChangedHdl( LINK( this, ToolBarManager, StateChanged ) );
289 m_pToolBar->SetDataChangedHdl( LINK( this, ToolBarManager, DataChanged ) );
290 m_pToolBar->SetToolboxButtonSize( m_bSmallSymbols ? TOOLBOX_BUTTONSIZE_SMALL : TOOLBOX_BUTTONSIZE_LARGE );
292 // enables a menu for clipped items and customization
293 SvtCommandOptions aCmdOptions;
294 USHORT nMenuType = TOOLBOX_MENUTYPE_CLIPPEDITEMS;
295 if ( !aCmdOptions.Lookup( SvtCommandOptions::CMDOPTION_DISABLED, ::rtl::OUString::createFromAscii( "CreateDialog" )))
296 nMenuType |= TOOLBOX_MENUTYPE_CUSTOMIZE;
297 //added for issue33668 by shizhoubo
298 m_pToolBar->SetCommandHdl( LINK( this, ToolBarManager, Command ) );
299 //end
300 m_pToolBar->SetMenuType( nMenuType );
301 m_pToolBar->SetMenuButtonHdl( LINK( this, ToolBarManager, MenuButton ) );
302 m_pToolBar->GetMenu()->SetSelectHdl( LINK( this, ToolBarManager, MenuSelect ) );
303 m_pToolBar->GetMenu()->SetDeactivateHdl( LINK( this, ToolBarManager, MenuDeactivate ) );
305 // set name for testtool, the useful part is after the last '/'
306 sal_Int32 idx = rResourceName.lastIndexOf('/');
307 idx++; // will become 0 if '/' not found: use full string
308 ::rtl::OUString aHelpIdAsString( RTL_CONSTASCII_USTRINGPARAM( HELPID_PREFIX_TESTTOOL ));
309 ::rtl::OUString aToolbarName = rResourceName.copy( idx );
310 aHelpIdAsString += aToolbarName;
311 m_pToolBar->SetSmartHelpId( SmartId( aHelpIdAsString ) );
313 m_aAsyncUpdateControllersTimer.SetTimeout( 50 );
314 m_aAsyncUpdateControllersTimer.SetTimeoutHdl( LINK( this, ToolBarManager, AsyncUpdateControllersHdl ) );
317 ToolBarManager::~ToolBarManager()
319 OSL_ASSERT( m_pToolBar == 0 );
320 OSL_ASSERT( !m_bAddedToTaskPaneList );
323 void ToolBarManager::Destroy()
325 ResetableGuard aGuard( m_aLock );
326 if ( m_bAddedToTaskPaneList )
328 Window* pWindow = m_pToolBar;
329 while ( pWindow && !pWindow->IsSystemWindow() )
330 pWindow = pWindow->GetParent();
332 if ( pWindow )
333 ((SystemWindow *)pWindow)->GetTaskPaneList()->RemoveWindow( m_pToolBar );
334 m_bAddedToTaskPaneList = sal_False;
337 // Delete the additional add-ons data
338 for ( sal_uInt16 i = 0; i < m_pToolBar->GetItemCount(); i++ )
340 sal_uInt16 nItemId = m_pToolBar->GetItemId( i );
341 if ( nItemId > 0 )
342 delete static_cast< AddonsParams* >( m_pToolBar->GetItemData( nItemId ));
345 /* #i99167# removed change for i93173 since there is some weird crash */
346 // #i93173# delete toolbar lazily as we can still be in one of its handlers
347 m_pToolBar->doLazyDelete();
349 Link aEmpty;
350 m_pToolBar->SetSelectHdl( aEmpty );
351 m_pToolBar->SetActivateHdl( aEmpty );
352 m_pToolBar->SetDeactivateHdl( aEmpty );
353 m_pToolBar->SetClickHdl( aEmpty );
354 m_pToolBar->SetDropdownClickHdl( aEmpty );
355 m_pToolBar->SetDoubleClickHdl( aEmpty );
356 m_pToolBar->SetStateChangedHdl( aEmpty );
357 m_pToolBar->SetDataChangedHdl( aEmpty );
359 // delete m_pToolBar;
360 m_pToolBar = 0;
363 ToolBox* ToolBarManager::GetToolBar() const
365 ResetableGuard aGuard( m_aLock );
366 return m_pToolBar;
369 void ToolBarManager::CheckAndUpdateImages()
371 ResetableGuard aGuard( m_aLock );
372 sal_Bool bRefreshImages = sal_False;
374 // Check if high contrast/normal mode have changed
375 if ( m_pToolBar->GetSettings().GetStyleSettings().GetHighContrastMode() )
377 if ( !m_bIsHiContrast )
379 bRefreshImages = TRUE;
380 m_bIsHiContrast = sal_True;
383 else if ( m_bIsHiContrast )
385 bRefreshImages = sal_True;
386 m_bIsHiContrast = sal_False;
389 SvtMiscOptions aMiscOptions;
390 bool bCurrentSymbolsSmall = !aMiscOptions.AreCurrentSymbolsLarge();
391 if ( m_bSmallSymbols != bCurrentSymbolsSmall )
393 bRefreshImages = sal_True;
394 m_bSmallSymbols = bCurrentSymbolsSmall;
397 sal_Int16 nCurrentSymbolsStyle = aMiscOptions.GetCurrentSymbolsStyle();
398 if ( m_nSymbolsStyle != nCurrentSymbolsStyle )
400 bRefreshImages = sal_True;
401 m_nSymbolsStyle = nCurrentSymbolsStyle;
404 // Refresh images if requested
405 if ( bRefreshImages )
406 RefreshImages();
409 void ToolBarManager::RefreshImages()
411 ResetableGuard aGuard( m_aLock );
413 sal_Bool bBigImages( SvtMiscOptions().AreCurrentSymbolsLarge() );
414 for ( USHORT nPos = 0; nPos < m_pToolBar->GetItemCount(); nPos++ )
416 USHORT nId( m_pToolBar->GetItemId( nPos ) );
418 if ( nId > 0 )
420 ::rtl::OUString aCommandURL = m_pToolBar->GetItemCommand( nId );
421 Image aImage = GetImageFromURL( m_xFrame, aCommandURL, bBigImages, m_bIsHiContrast );
422 // Try also to query for add-on images before giving up and use an
423 // empty image.
424 if ( !aImage )
425 aImage = QueryAddonsImage( aCommandURL, bBigImages, m_bIsHiContrast );
426 m_pToolBar->SetItemImage( nId, aImage );
430 m_pToolBar->SetToolboxButtonSize( bBigImages ? TOOLBOX_BUTTONSIZE_LARGE : TOOLBOX_BUTTONSIZE_SMALL );
431 ::Size aSize = m_pToolBar->CalcWindowSizePixel();
432 m_pToolBar->SetOutputSizePixel( aSize );
435 void ToolBarManager::UpdateImageOrientation()
437 ResetableGuard aGuard( m_aLock );
439 if ( m_xUICommandLabels.is() )
441 sal_Int32 i;
442 Sequence< rtl::OUString > aSeqMirrorCmd;
443 Sequence< rtl::OUString > aSeqRotateCmd;
444 m_xUICommandLabels->getByName(
445 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( UICOMMANDDESCRIPTION_NAMEACCESS_COMMANDMIRRORIMAGELIST ))) >>= aSeqMirrorCmd;
446 m_xUICommandLabels->getByName(
447 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( UICOMMANDDESCRIPTION_NAMEACCESS_COMMANDROTATEIMAGELIST ))) >>= aSeqRotateCmd;
449 CommandToInfoMap::iterator pIter;
450 for ( i = 0; i < aSeqMirrorCmd.getLength(); i++ )
452 rtl::OUString aMirrorCmd = aSeqMirrorCmd[i];
453 pIter = m_aCommandMap.find( aMirrorCmd );
454 if ( pIter != m_aCommandMap.end() )
455 pIter->second.bMirrored = sal_True;
457 for ( i = 0; i < aSeqRotateCmd.getLength(); i++ )
459 rtl::OUString aRotateCmd = aSeqRotateCmd[i];
460 pIter = m_aCommandMap.find( aRotateCmd );
461 if ( pIter != m_aCommandMap.end() )
462 pIter->second.bRotated = sal_True;
466 for ( USHORT nPos = 0; nPos < m_pToolBar->GetItemCount(); nPos++ )
468 USHORT nId = m_pToolBar->GetItemId( nPos );
469 if ( nId > 0 )
471 rtl::OUString aCmd = m_pToolBar->GetItemCommand( nId );
473 CommandToInfoMap::const_iterator pIter = m_aCommandMap.find( aCmd );
474 if ( pIter != m_aCommandMap.end() )
476 if ( pIter->second.bRotated )
478 m_pToolBar->SetItemImageMirrorMode( nId, FALSE );
479 m_pToolBar->SetItemImageAngle( nId, m_lImageRotation );
481 if ( pIter->second.bMirrored )
482 m_pToolBar->SetItemImageMirrorMode( nId, m_bImageMirrored );
488 void ToolBarManager::UpdateControllers()
490 RTL_LOGFILE_CONTEXT( aLog, "framework (cd100003) ::ToolBarManager::UpdateControllers" );
492 if( !m_bCanBeCustomized )
494 Any a;
495 Reference< XLayoutManager > xLayoutManager;
496 Reference< XPropertySet > xFramePropSet( m_xFrame, UNO_QUERY );
497 if ( xFramePropSet.is() )
498 a = xFramePropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" )));
499 a >>= xLayoutManager;
500 Reference< XDockableWindow > xDockable( VCLUnoHelper::GetInterface( m_pToolBar ), UNO_QUERY );
501 if ( xLayoutManager.is() && xDockable.is() )
503 ::com::sun::star::awt::Point aPoint;
504 aPoint.X = aPoint.Y = LONG_MAX;
505 xLayoutManager->dockWindow( m_aResourceName, DockingArea_DOCKINGAREA_DEFAULT, aPoint );
506 xLayoutManager->lockWindow( m_aResourceName );
510 if ( !m_bUpdateControllers )
512 m_bUpdateControllers = sal_True;
513 ToolBarControllerMap::iterator pIter = m_aControllerMap.begin();
515 while ( pIter != m_aControllerMap.end() )
519 Reference< XUpdatable > xUpdatable( pIter->second, UNO_QUERY );
520 if ( xUpdatable.is() )
521 xUpdatable->update();
523 catch ( Exception& )
526 ++pIter;
529 m_bUpdateControllers = sal_False;
532 void ToolBarManager::frameAction( const FrameActionEvent& Action )
533 throw ( RuntimeException )
535 ResetableGuard aGuard( m_aLock );
536 if ( Action.Action == FrameAction_CONTEXT_CHANGED )
537 m_aAsyncUpdateControllersTimer.Start();
540 void SAL_CALL ToolBarManager::statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event )
541 throw ( ::com::sun::star::uno::RuntimeException )
543 ResetableGuard aGuard( m_aLock );
544 if ( m_bDisposed )
545 return;
547 if ( Event.FeatureURL.Complete.equalsAscii( ".uno:ImageOrientation" ))
549 SfxImageItem aItem( 1, 0 );
550 aItem.PutValue( Event.State );
552 m_lImageRotation = aItem.GetRotation();
553 m_bImageMirrored = aItem.IsMirrored();
554 UpdateImageOrientation();
558 void SAL_CALL ToolBarManager::disposing( const EventObject& Source ) throw ( RuntimeException )
561 ResetableGuard aGuard( m_aLock );
562 if ( m_bDisposed )
563 return;
566 RemoveControllers();
569 ResetableGuard aGuard( m_aLock );
570 if ( m_xDocImageManager.is() )
574 m_xDocImageManager->removeConfigurationListener(
575 Reference< XUIConfigurationListener >(
576 static_cast< OWeakObject* >( this ), UNO_QUERY ));
578 catch ( Exception& )
583 if ( m_xModuleImageManager.is() )
587 m_xModuleImageManager->removeConfigurationListener(
588 Reference< XUIConfigurationListener >(
589 static_cast< OWeakObject* >( this ), UNO_QUERY ));
591 catch ( Exception& )
596 if ( m_xImageOrientationListener.is() )
598 ImageOrientationListener* pImageOrientation =
599 (ImageOrientationListener*)m_xImageOrientationListener.get();
600 pImageOrientation->unbindListener();
601 m_xImageOrientationListener.clear();
604 m_xDocImageManager.clear();
605 m_xModuleImageManager.clear();
607 if ( Source.Source == Reference< XInterface >( m_xFrame, UNO_QUERY ))
608 m_xFrame.clear();
610 m_xServiceManager.clear();
614 // XComponent
615 void SAL_CALL ToolBarManager::dispose() throw( RuntimeException )
617 Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY );
619 EventObject aEvent( xThis );
620 m_aListenerContainer.disposeAndClear( aEvent );
623 ResetableGuard aGuard( m_aLock );
625 // stop timer to prevent timer events after dispose
626 m_aAsyncUpdateControllersTimer.Stop();
628 RemoveControllers();
630 if ( m_xDocImageManager.is() )
634 m_xDocImageManager->removeConfigurationListener(
635 Reference< XUIConfigurationListener >(
636 static_cast< OWeakObject* >( this ), UNO_QUERY ));
638 catch ( Exception& )
642 m_xDocImageManager.clear();
643 if ( m_xModuleImageManager.is() )
647 m_xModuleImageManager->removeConfigurationListener(
648 Reference< XUIConfigurationListener >(
649 static_cast< OWeakObject* >( this ), UNO_QUERY ));
651 catch ( Exception& )
655 m_xModuleImageManager.clear();
657 ImplClearPopupMenu( m_pToolBar );
659 // We have to destroy our toolbar instance now.
660 Destroy();
662 if ( m_bFrameActionRegistered && m_xFrame.is() )
666 m_xFrame->removeFrameActionListener( Reference< XFrameActionListener >(
667 static_cast< ::cppu::OWeakObject *>( this ), UNO_QUERY ));
669 catch ( Exception& )
674 if ( m_xImageOrientationListener.is() )
676 ImageOrientationListener* pImageOrientation =
677 (ImageOrientationListener*)m_xImageOrientationListener.get();
678 pImageOrientation->unbindListener();
679 m_xImageOrientationListener.clear();
682 m_xFrame.clear();
683 m_xServiceManager.clear();
685 m_bDisposed = sal_True;
689 void SAL_CALL ToolBarManager::addEventListener( const Reference< XEventListener >& xListener ) throw( RuntimeException )
691 ResetableGuard aGuard( m_aLock );
693 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
694 if ( m_bDisposed )
695 throw DisposedException();
697 m_aListenerContainer.addInterface( ::getCppuType( ( const Reference< XEventListener >* ) NULL ), xListener );
700 void SAL_CALL ToolBarManager::removeEventListener( const Reference< XEventListener >& xListener ) throw( RuntimeException )
702 m_aListenerContainer.removeInterface( ::getCppuType( ( const Reference< XEventListener >* ) NULL ), xListener );
705 // XUIConfigurationListener
706 void SAL_CALL ToolBarManager::elementInserted( const ::com::sun::star::ui::ConfigurationEvent& Event ) throw (::com::sun::star::uno::RuntimeException)
708 impl_elementChanged(false,Event);
711 void SAL_CALL ToolBarManager::elementRemoved( const ::com::sun::star::ui::ConfigurationEvent& Event ) throw (::com::sun::star::uno::RuntimeException)
713 impl_elementChanged(true,Event);
715 void ToolBarManager::impl_elementChanged(bool _bRemove,const ::com::sun::star::ui::ConfigurationEvent& Event )
717 ResetableGuard aGuard( m_aLock );
719 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
720 if ( m_bDisposed )
721 return;
723 Reference< XNameAccess > xNameAccess;
724 sal_Int16 nImageType = sal_Int16();
725 sal_Int16 nCurrentImageType = getImageTypeFromBools(
726 SvtMiscOptions().AreCurrentSymbolsLarge(),
727 m_bIsHiContrast );
729 if (( Event.aInfo >>= nImageType ) &&
730 ( nImageType == nCurrentImageType ) &&
731 ( Event.Element >>= xNameAccess ))
733 sal_Int16 nImageInfo( 1 );
734 Reference< XInterface > xIfacDocImgMgr( m_xDocImageManager, UNO_QUERY );
735 if ( xIfacDocImgMgr == Event.Source )
736 nImageInfo = 0;
738 Sequence< rtl::OUString > aSeq = xNameAccess->getElementNames();
739 for ( sal_Int32 i = 0; i < aSeq.getLength(); i++ )
741 CommandToInfoMap::iterator pIter = m_aCommandMap.find( aSeq[i] );
742 if ( pIter != m_aCommandMap.end() && ( pIter->second.nImageInfo >= nImageInfo ))
744 if ( _bRemove )
746 Image aImage;
747 if (( pIter->second.nImageInfo == 0 ) && ( pIter->second.nImageInfo == nImageInfo ))
749 // Special case: An image from the document image manager has been removed.
750 // It is possible that we have a image at our module image manager. Before
751 // we can remove our image we have to ask our module image manager.
752 Sequence< rtl::OUString > aCmdURLSeq( 1 );
753 Sequence< Reference< XGraphic > > aGraphicSeq;
754 aCmdURLSeq[0] = pIter->first;
755 aGraphicSeq = m_xModuleImageManager->getImages( nImageType, aCmdURLSeq );
756 aImage = Image( aGraphicSeq[0] );
759 setToolBarImage(aImage,pIter);
760 } // if ( _bRemove )
761 else
763 Reference< XGraphic > xGraphic;
764 if ( xNameAccess->getByName( aSeq[i] ) >>= xGraphic )
766 Image aImage( xGraphic );
767 setToolBarImage(aImage,pIter);
769 pIter->second.nImageInfo = nImageInfo;
775 void ToolBarManager::setToolBarImage(const Image& _aImage,const CommandToInfoMap::const_iterator& _pIter)
777 const ::std::vector< USHORT >& _rIDs = _pIter->second.aIds;
778 m_pToolBar->SetItemImage( _pIter->second.nId, _aImage );
779 ::std::for_each(_rIDs.begin(),_rIDs.end(),::boost::bind(&ToolBar::SetItemImage,m_pToolBar,_1,_aImage));
782 void SAL_CALL ToolBarManager::elementReplaced( const ::com::sun::star::ui::ConfigurationEvent& Event ) throw (::com::sun::star::uno::RuntimeException)
784 impl_elementChanged(false,Event);
787 void ToolBarManager::RemoveControllers()
789 ResetableGuard aGuard( m_aLock );
791 if ( m_bDisposed )
792 return;
794 m_aSubToolBarControllerMap.clear();
797 // i90033
798 // Remove item window pointers from the toolbar. They were
799 // destroyed by the dispose() at the XComponent. This is needed
800 // as VCL code later tries to access the item window data in certain
801 // dtors where the item window is already invalid!
802 for ( sal_uInt16 i = 0; i < m_pToolBar->GetItemCount(); i++ )
804 sal_uInt16 nItemId = m_pToolBar->GetItemId( i );
805 if ( nItemId > 0 )
807 Reference< XComponent > xComponent( m_aControllerMap[ nItemId ], UNO_QUERY );
808 if ( xComponent.is() )
812 xComponent->dispose();
814 catch ( Exception& )
818 m_pToolBar->SetItemWindow(nItemId, 0);
821 m_aControllerMap.clear();
824 ::rtl::OUString ToolBarManager::RetrieveLabelFromCommand( const ::rtl::OUString& aCmdURL )
826 ::rtl::OUString aLabel;
828 // Retrieve popup menu labels
829 if ( !m_bModuleIdentified )
831 Reference< XModuleManager > xModuleManager( m_xServiceManager->createInstance( SERVICENAME_MODULEMANAGER ), UNO_QUERY_THROW );
832 Reference< XInterface > xIfac( m_xFrame, UNO_QUERY );
835 m_bModuleIdentified = sal_True;
836 m_aModuleIdentifier = xModuleManager->identify( xIfac );
838 if ( m_aModuleIdentifier.getLength() > 0 )
840 Reference< XNameAccess > xNameAccess( m_xServiceManager->createInstance( SERVICENAME_UICOMMANDDESCRIPTION ), UNO_QUERY );
841 if ( xNameAccess.is() )
843 xNameAccess->getByName( m_aModuleIdentifier ) >>= m_xUICommandLabels;
847 catch ( Exception& )
852 if ( m_xUICommandLabels.is() )
856 if ( aCmdURL.getLength() > 0 )
858 rtl::OUString aStr;
859 Sequence< PropertyValue > aPropSeq;
860 if ( m_xUICommandLabels->getByName( aCmdURL ) >>= aPropSeq )
862 for ( sal_Int32 i = 0; i < aPropSeq.getLength(); i++ )
864 if ( aPropSeq[i].Name.equalsAscii( "Name" ))
866 aPropSeq[i].Value >>= aStr;
867 break;
871 aLabel = aStr;
874 catch ( com::sun::star::uno::Exception& )
879 return aLabel;
882 void ToolBarManager::CreateControllers()
884 RTL_LOGFILE_CONTEXT( aLog, "framework (cd100003) ::ToolBarManager::CreateControllers" );
886 Reference< XMultiComponentFactory > xToolbarControllerFactory( m_xToolbarControllerRegistration, UNO_QUERY );
887 Reference< XComponentContext > xComponentContext;
888 Reference< XPropertySet > xProps( m_xServiceManager, UNO_QUERY );
889 Reference< XWindow > xToolbarWindow = VCLUnoHelper::GetInterface( m_pToolBar );
891 css::util::URL aURL;
892 sal_Bool bHasDisabledEntries = SvtCommandOptions().HasEntries( SvtCommandOptions::CMDOPTION_DISABLED );
893 SvtCommandOptions aCmdOptions;
895 if ( xProps.is() )
896 xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))) >>= xComponentContext;
898 for ( USHORT i = 0; i < m_pToolBar->GetItemCount(); i++ )
900 USHORT nId = m_pToolBar->GetItemId( i );
901 if ( nId == 0 )
902 continue;
904 sal_Int16 nWidth( sal_Int16( m_pToolBar->GetHelpId( nId )));
905 rtl::OUString aLoadURL( RTL_CONSTASCII_USTRINGPARAM( ".uno:OpenUrl" ));
906 rtl::OUString aCommandURL( m_pToolBar->GetItemCommand( nId ));
907 sal_Bool bInit( sal_True );
908 sal_Bool bCreate( sal_True );
909 Reference< XStatusListener > xController;
911 svt::ToolboxController* pController( 0 );
913 m_pToolBar->SetHelpId( nId, 0 ); // reset value again
914 if ( bHasDisabledEntries )
916 aURL.Complete = aCommandURL;
917 m_xURLTransformer->parseStrict( aURL );
918 if ( aCmdOptions.Lookup( SvtCommandOptions::CMDOPTION_DISABLED, aURL.Path ))
920 m_aControllerMap[ nId ] = xController;
921 m_pToolBar->HideItem( nId );
922 continue;
926 if ( m_xToolbarControllerRegistration.is() &&
927 m_xToolbarControllerRegistration->hasController( aCommandURL, m_aModuleIdentifier ))
929 if ( xToolbarControllerFactory.is() )
931 PropertyValue aPropValue;
932 std::vector< Any > aPropertyVector;
934 aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ModuleName" ));
935 aPropValue.Value <<= m_aModuleIdentifier;
936 aPropertyVector.push_back( makeAny( aPropValue ));
937 aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Frame" ));
938 aPropValue.Value <<= m_xFrame;
939 aPropertyVector.push_back( makeAny( aPropValue ));
940 aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ServiceManager" ));
941 aPropValue.Value <<= m_xServiceManager;
942 aPropertyVector.push_back( makeAny( aPropValue ));
943 aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ParentWindow" ));
944 aPropValue.Value <<= xToolbarWindow;
945 aPropertyVector.push_back( makeAny( aPropValue ));
947 if ( nWidth > 0 )
949 aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Width" ));
950 aPropValue.Value <<= nWidth;
951 aPropertyVector.push_back( makeAny( aPropValue ));
954 Sequence< Any > aArgs( comphelper::containerToSequence( aPropertyVector ));
955 xController = Reference< XStatusListener >( xToolbarControllerFactory->createInstanceWithArgumentsAndContext(
956 aCommandURL, aArgs, xComponentContext ),
957 UNO_QUERY );
958 bInit = sal_False; // Initialization is done through the factory service
962 if (( aCommandURL == aLoadURL ) && ( !m_pToolBar->IsItemVisible(nId)))
963 bCreate = sal_False;
965 if ( !xController.is() && m_pToolBar && bCreate )
967 pController = CreateToolBoxController( m_xFrame, m_pToolBar, nId, aCommandURL );
968 if ( !pController )
970 if ( m_pToolBar->GetItemData( nId ) != 0 )
972 // retrieve additional parameters
973 ::rtl::OUString aControlType = static_cast< AddonsParams* >( m_pToolBar->GetItemData( nId ))->aControlType;
975 Reference< XStatusListener > xStatusListener(
976 ToolBarMerger::CreateController( m_xServiceManager,
977 m_xFrame,
978 m_pToolBar,
979 aCommandURL,
980 nId,
981 nWidth,
982 aControlType ), UNO_QUERY );
984 xController = xStatusListener;
986 else
988 MenuDescriptionMap::iterator it = m_aMenuMap.find( nId );
989 if ( it == m_aMenuMap.end() )
990 xController = Reference< XStatusListener >(
991 new GenericToolbarController( m_xServiceManager, m_xFrame, m_pToolBar, nId, aCommandURL ));
992 else
993 xController = Reference< XStatusListener >(
994 new MenuToolbarController( m_xServiceManager, m_xFrame, m_pToolBar, nId, aCommandURL, m_aModuleIdentifier, m_aMenuMap[ nId ] ));
997 else if ( pController )
999 xController = Reference< XStatusListener >( static_cast< ::cppu::OWeakObject *>( pController ), UNO_QUERY );
1003 // Associate ID and controller to be able to retrieve
1004 // the controller from the ID later.
1005 m_aControllerMap[ nId ] = xController;
1007 // Fill sub-toolbars into our hash-map
1008 Reference< XSubToolbarController > xSubToolBar( xController, UNO_QUERY );
1009 if ( xSubToolBar.is() && xSubToolBar->opensSubToolbar() )
1011 rtl::OUString aSubToolBarName = xSubToolBar->getSubToolbarName();
1012 if ( aSubToolBarName.getLength() != 0 )
1014 SubToolBarToSubToolBarControllerMap::iterator pIter =
1015 m_aSubToolBarControllerMap.find( aSubToolBarName );
1016 if ( pIter == m_aSubToolBarControllerMap.end() )
1018 SubToolBarControllerVector aSubToolBarVector;
1019 aSubToolBarVector.push_back( xSubToolBar );
1020 m_aSubToolBarControllerMap.insert(
1021 SubToolBarToSubToolBarControllerMap::value_type(
1022 aSubToolBarName, aSubToolBarVector ));
1024 else
1025 pIter->second.push_back( xSubToolBar );
1029 Reference< XInitialization > xInit( xController, UNO_QUERY );
1030 if ( xInit.is() )
1032 if ( bInit )
1034 PropertyValue aPropValue;
1035 std::vector< Any > aPropertyVector;
1037 aPropValue.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Frame" ));
1038 aPropValue.Value <<= m_xFrame;
1039 aPropertyVector.push_back( makeAny( aPropValue ));
1040 aPropValue.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CommandURL" ));
1041 aPropValue.Value <<= aCommandURL;
1042 aPropertyVector.push_back( makeAny( aPropValue ));
1043 aPropValue.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ServiceManager" ));
1044 aPropValue.Value <<= m_xServiceManager;
1045 aPropertyVector.push_back( makeAny( aPropValue ));
1046 aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ParentWindow" ));
1047 aPropValue.Value <<= xToolbarWindow;
1048 aPropertyVector.push_back( makeAny( aPropValue ));
1049 if ( nWidth > 0 )
1051 aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Width" ));
1052 aPropValue.Value <<= nWidth;
1053 aPropertyVector.push_back( makeAny( aPropValue ));
1056 Sequence< Any > aArgs( comphelper::containerToSequence( aPropertyVector ));
1057 xInit->initialize( aArgs );
1060 // Request a item window from the toolbar controller and set it at the VCL toolbar
1061 Reference< XToolbarController > xTbxController( xController, UNO_QUERY );
1062 if ( xTbxController.is() && xToolbarWindow.is() )
1064 Reference< XWindow > xWindow = xTbxController->createItemWindow( xToolbarWindow );
1065 if ( xWindow.is() )
1067 Window* pItemWin = VCLUnoHelper::GetWindow( xWindow );
1068 if ( pItemWin )
1070 WindowType nType = pItemWin->GetType();
1071 if ( nType == WINDOW_LISTBOX || nType == WINDOW_MULTILISTBOX || nType == WINDOW_COMBOBOX )
1072 pItemWin->SetAccessibleName( m_pToolBar->GetItemText( nId ) );
1073 m_pToolBar->SetItemWindow( nId, pItemWin );
1080 AddFrameActionListener();
1081 AddImageOrientationListener();
1084 void ToolBarManager::AddFrameActionListener()
1086 if ( !m_bFrameActionRegistered && m_xFrame.is() )
1088 m_bFrameActionRegistered = sal_True;
1089 m_xFrame->addFrameActionListener( Reference< XFrameActionListener >(
1090 static_cast< ::cppu::OWeakObject *>( this ), UNO_QUERY ));
1094 void ToolBarManager::AddImageOrientationListener()
1096 if ( !m_bImageOrientationRegistered && m_xFrame.is() )
1098 m_bImageOrientationRegistered = sal_True;
1099 ImageOrientationListener* pImageOrientation = new ImageOrientationListener(
1100 Reference< XStatusListener >( static_cast< ::cppu::OWeakObject *>( this ), UNO_QUERY ),
1101 m_xServiceManager,
1102 m_xFrame );
1103 m_xImageOrientationListener = Reference< XComponent >( static_cast< ::cppu::OWeakObject *>(
1104 pImageOrientation ), UNO_QUERY );
1105 pImageOrientation->addStatusListener(
1106 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ImageOrientation" )));
1107 pImageOrientation->bindListener();
1111 sal_uInt16 ToolBarManager::ConvertStyleToToolboxItemBits( sal_Int32 nStyle )
1113 sal_uInt16 nItemBits( 0 );
1114 if ( nStyle & ::com::sun::star::ui::ItemStyle::RADIO_CHECK )
1115 nItemBits |= TIB_RADIOCHECK;
1116 if ( nStyle & ::com::sun::star::ui::ItemStyle::ALIGN_LEFT )
1117 nItemBits |= TIB_LEFT;
1118 if ( nStyle & ::com::sun::star::ui::ItemStyle::AUTO_SIZE )
1119 nItemBits |= TIB_AUTOSIZE;
1120 if ( nStyle & ::com::sun::star::ui::ItemStyle::DROP_DOWN )
1121 nItemBits |= TIB_DROPDOWN;
1122 if ( nStyle & ::com::sun::star::ui::ItemStyle::REPEAT )
1123 nItemBits |= TIB_REPEAT;
1124 if ( nStyle & ::com::sun::star::ui::ItemStyle::DROPDOWN_ONLY )
1125 nItemBits |= TIB_DROPDOWNONLY;
1126 if ( nStyle & ::com::sun::star::ui::ItemStyle::TEXT )
1127 nItemBits |= TIB_TEXT_ONLY;
1128 if ( nStyle & ::com::sun::star::ui::ItemStyle::ICON )
1129 nItemBits |= TIB_ICON_ONLY;
1131 return nItemBits;
1134 void ToolBarManager::FillToolbar( const Reference< XIndexAccess >& rItemContainer )
1136 ::rtl::OString aTbxName = rtl::OUStringToOString( m_aResourceName, RTL_TEXTENCODING_ASCII_US );
1138 RTL_LOGFILE_CONTEXT( aLog, "framework (cd100003) ::ToolBarManager::FillToolbar" );
1139 RTL_LOGFILE_CONTEXT_TRACE1( aLog, "framework (cd100003) ::ToolBarManager::FillToolbar %s", aTbxName.getStr() );
1141 ResetableGuard aGuard( m_aLock );
1143 if ( m_bDisposed )
1144 return;
1146 USHORT nId( 1 );
1147 ::rtl::OUString aHelpIdPrefix( RTL_CONSTASCII_USTRINGPARAM( HELPID_PREFIX ));
1149 Reference< XModuleManager > xModuleManager( Reference< XModuleManager >(
1150 m_xServiceManager->createInstance( SERVICENAME_MODULEMANAGER ), UNO_QUERY ));
1151 if ( !m_xDocImageManager.is() )
1153 Reference< XModel > xModel( GetModelFromFrame() );
1154 if ( xModel.is() )
1156 Reference< XUIConfigurationManagerSupplier > xSupplier( xModel, UNO_QUERY );
1157 if ( xSupplier.is() )
1159 Reference< XUIConfigurationManager > xDocUICfgMgr( xSupplier->getUIConfigurationManager(), UNO_QUERY );
1160 m_xDocImageManager = Reference< XImageManager >( xDocUICfgMgr->getImageManager(), UNO_QUERY );
1161 m_xDocImageManager->addConfigurationListener(
1162 Reference< XUIConfigurationListener >(
1163 static_cast< OWeakObject* >( this ), UNO_QUERY ));
1170 if ( xModuleManager.is() )
1171 m_aModuleIdentifier = xModuleManager->identify( Reference< XInterface >( m_xFrame, UNO_QUERY ) );
1173 catch( Exception& )
1177 if ( !m_xModuleImageManager.is() )
1179 Reference< XModuleUIConfigurationManagerSupplier > xModuleCfgMgrSupplier( m_xServiceManager->createInstance(
1180 SERVICENAME_MODULEUICONFIGURATIONMANAGERSUPPLIER ),
1181 UNO_QUERY );
1182 Reference< XUIConfigurationManager > xUICfgMgr = xModuleCfgMgrSupplier->getUIConfigurationManager( m_aModuleIdentifier );
1183 m_xModuleImageManager = Reference< XImageManager >( xUICfgMgr->getImageManager(), UNO_QUERY );
1184 m_xModuleImageManager->addConfigurationListener( Reference< XUIConfigurationListener >(
1185 static_cast< OWeakObject* >( this ), UNO_QUERY ));
1188 RemoveControllers();
1190 // reset and fill command map
1191 m_pToolBar->Clear();
1192 m_aControllerMap.clear();
1193 m_aCommandMap.clear();
1195 m_aMenuMap.clear();
1197 CommandInfo aCmdInfo;
1198 for ( sal_Int32 n = 0; n < rItemContainer->getCount(); n++ )
1200 Sequence< PropertyValue > aProp;
1201 rtl::OUString aCommandURL;
1202 rtl::OUString aLabel;
1203 rtl::OUString aHelpURL;
1204 rtl::OUString aTooltip;
1205 sal_uInt16 nType( ::com::sun::star::ui::ItemType::DEFAULT );
1206 sal_uInt16 nWidth( 0 );
1207 sal_Bool bIsVisible( sal_True );
1208 sal_uInt32 nStyle( 0 );
1210 Reference< XIndexAccess > aMenuDesc;
1213 if ( rItemContainer->getByIndex( n ) >>= aProp )
1215 for ( int i = 0; i < aProp.getLength(); i++ )
1217 if ( aProp[i].Name.equalsAsciiL( ITEM_DESCRIPTOR_COMMANDURL, ITEM_DESCRIPTOR_COMMANDURL_LEN ))
1218 aProp[i].Value >>= aCommandURL;
1219 else if ( aProp[i].Name.equalsAsciiL( ITEM_DESCRIPTOR_HELPURL, ITEM_DESCRIPTOR_HELPURL_LEN ))
1220 aProp[i].Value >>= aHelpURL;
1221 else if ( aProp[i].Name.equalsAsciiL( ITEM_DESCRIPTOR_TOOLTIP, ITEM_DESCRIPTOR_TOOLTIP_LEN ))
1222 aProp[i].Value >>= aTooltip;
1223 else if ( aProp[i].Name.equalsAsciiL( ITEM_DESCRIPTOR_LABEL, ITEM_DESCRIPTOR_LABEL_LEN ))
1224 aProp[i].Value >>= aLabel;
1225 else if ( aProp[i].Name.equalsAsciiL( ITEM_DESCRIPTOR_TYPE, ITEM_DESCRIPTOR_TYPE_LEN ))
1226 aProp[i].Value >>= nType;
1227 else if ( aProp[i].Name.equalsAsciiL( ITEM_DESCRIPTOR_VISIBLE, ITEM_DESCRIPTOR_VISIBLE_LEN ))
1228 aProp[i].Value >>= bIsVisible;
1229 else if ( aProp[i].Name.equalsAsciiL( ITEM_DESCRIPTOR_WIDTH, ITEM_DESCRIPTOR_WIDTH_LEN ))
1230 aProp[i].Value >>= nWidth;
1231 else if ( aProp[i].Name.equalsAsciiL( ITEM_DESCRIPTOR_STYLE, ITEM_DESCRIPTOR_STYLE_LEN ))
1232 aProp[i].Value >>= nStyle;
1233 else if ( aProp[i].Name.equalsAsciiL( ITEM_DESCRIPTOR_CONTAINER, ITEM_DESCRIPTOR_CONTAINER_LEN ))
1234 aProp[i].Value >>= aMenuDesc;
1237 if (( nType == ::com::sun::star::ui::ItemType::DEFAULT ) && ( aCommandURL.getLength() > 0 ))
1239 ::rtl::OUString aString( RetrieveLabelFromCommand( aCommandURL ));
1241 sal_uInt16 nItemBits = ConvertStyleToToolboxItemBits( nStyle );
1242 if ( aMenuDesc.is() )
1243 m_aMenuMap[ nId ] = aMenuDesc;
1244 m_pToolBar->InsertItem( nId, aString, nItemBits );
1245 m_pToolBar->SetItemCommand( nId, aCommandURL );
1246 if ( aTooltip.getLength() )
1247 m_pToolBar->SetQuickHelpText( nId, aTooltip );
1248 else
1249 m_pToolBar->SetQuickHelpText( nId, aString );
1250 if ( aLabel.getLength() > 0 )
1251 m_pToolBar->SetItemText( nId, aLabel );
1252 else
1253 m_pToolBar->SetItemText( nId, aString );
1254 m_pToolBar->EnableItem( nId, sal_True );
1255 m_pToolBar->SetItemState( nId, STATE_NOCHECK );
1257 // Fill command map. It stores all our commands and from what
1258 // image manager we got our image. So we can decide if we have to use an
1259 // image from a notification message.
1260 CommandToInfoMap::iterator pIter = m_aCommandMap.find( aCommandURL );
1261 if ( pIter == m_aCommandMap.end())
1263 aCmdInfo.nId = nId;
1264 m_aCommandMap.insert( CommandToInfoMap::value_type( aCommandURL, aCmdInfo ));
1266 else
1268 pIter->second.aIds.push_back( nId );
1271 // Add additional information for the controller to the obsolete help id
1272 m_pToolBar->SetHelpId( ULONG( nWidth ));
1274 if ( !bIsVisible )
1275 m_pToolBar->HideItem( nId );
1277 ++nId;
1279 else if ( nType == ::com::sun::star::ui::ItemType::SEPARATOR_LINE )
1281 m_pToolBar->InsertSeparator();
1283 else if ( nType == ::com::sun::star::ui::ItemType::SEPARATOR_SPACE )
1285 m_pToolBar->InsertSpace();
1287 else if ( nType == ::com::sun::star::ui::ItemType::SEPARATOR_LINEBREAK )
1289 m_pToolBar->InsertBreak();
1293 catch ( ::com::sun::star::lang::IndexOutOfBoundsException& )
1295 break;
1299 // Support add-on toolbar merging here. Working directly on the toolbar object is much
1300 // simpler and faster.
1301 const sal_uInt16 TOOLBAR_ITEM_STARTID = 1000;
1303 MergeToolbarInstructionContainer aMergeInstructionContainer;
1305 // Retrieve the toolbar name from the resource name
1306 ::rtl::OUString aToolbarName( m_aResourceName );
1307 sal_Int32 nIndex = aToolbarName.lastIndexOf( '/' );
1308 if (( nIndex > 0 ) && ( nIndex < aToolbarName.getLength() ))
1309 aToolbarName = aToolbarName.copy( nIndex+1 );
1311 AddonsOptions().GetMergeToolbarInstructions( aToolbarName, aMergeInstructionContainer );
1313 if ( !aMergeInstructionContainer.empty() )
1315 sal_uInt16 nItemId( TOOLBAR_ITEM_STARTID );
1316 const sal_uInt32 nCount = aMergeInstructionContainer.size();
1317 for ( sal_uInt32 i=0; i < nCount; i++ )
1319 MergeToolbarInstruction& rInstruction = aMergeInstructionContainer[i];
1320 if ( ToolBarMerger::IsCorrectContext( rInstruction.aMergeContext, m_aModuleIdentifier ))
1322 ReferenceToolbarPathInfo aRefPoint = ToolBarMerger::FindReferencePoint( m_pToolBar, rInstruction.aMergePoint );
1324 // convert the sequence< sequence< propertyvalue > > structure to
1325 // something we can better handle. A vector with item data
1326 AddonToolbarItemContainer aItems;
1327 ToolBarMerger::ConvertSeqSeqToVector( rInstruction.aMergeToolbarItems, aItems );
1329 if ( aRefPoint.bResult )
1331 ToolBarMerger::ProcessMergeOperation( m_xFrame,
1332 m_pToolBar,
1333 aRefPoint.nPos,
1334 nItemId,
1335 m_aCommandMap,
1336 m_aModuleIdentifier,
1337 rInstruction.aMergeCommand,
1338 rInstruction.aMergeCommandParameter,
1339 aItems );
1341 else
1343 ToolBarMerger::ProcessMergeFallback( m_xFrame,
1344 m_pToolBar,
1345 aRefPoint.nPos,
1346 nItemId,
1347 m_aCommandMap,
1348 m_aModuleIdentifier,
1349 rInstruction.aMergeCommand,
1350 rInstruction.aMergeFallback,
1351 aItems );
1357 // Request images for all toolbar items. Must be done before CreateControllers as
1358 // some controllers need access to the image.
1359 RequestImages();
1361 // Create controllers after we set the images. There are controllers which needs
1362 // an image at the toolbar at creation time!
1363 CreateControllers();
1365 // Notify controllers that they are now correctly initialized and can start listening
1366 // toolbars that will open in popup mode will be updated immediately to avoid flickering
1367 if( m_pToolBar->WillUsePopupMode() )
1368 UpdateControllers();
1369 else if ( m_pToolBar->IsReallyVisible() )
1370 m_aAsyncUpdateControllersTimer.Start();
1372 // Try to retrieve UIName from the container property set and set it as the title
1373 // if it is not empty.
1374 Reference< XPropertySet > xPropSet( rItemContainer, UNO_QUERY );
1375 if ( xPropSet.is() )
1379 rtl::OUString aUIName;
1380 xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UIName" ))) >>= aUIName;
1381 if ( aUIName.getLength() > 0 )
1382 m_pToolBar->SetText( aUIName );
1384 catch ( Exception& )
1390 void ToolBarManager::RequestImages()
1392 RTL_LOGFILE_CONTEXT( aLog, "framework (cd100003) ::ToolBarManager::RequestImages" );
1394 // Request images from image manager
1395 Sequence< rtl::OUString > aCmdURLSeq( m_aCommandMap.size() );
1396 Sequence< Reference< XGraphic > > aDocGraphicSeq;
1397 Sequence< Reference< XGraphic > > aModGraphicSeq;
1399 sal_uInt32 i = 0;
1400 CommandToInfoMap::iterator pIter = m_aCommandMap.begin();
1401 CommandToInfoMap::iterator pEnd = m_aCommandMap.end();
1402 while ( pIter != pEnd )
1404 aCmdURLSeq[i++] = pIter->first;
1405 ++pIter;
1408 sal_Bool bBigImages( SvtMiscOptions().AreCurrentSymbolsLarge() );
1409 m_bIsHiContrast = m_pToolBar->GetSettings().GetStyleSettings().GetHighContrastMode();
1410 sal_Int16 p = getImageTypeFromBools( SvtMiscOptions().AreCurrentSymbolsLarge(), m_bIsHiContrast );
1412 if ( m_xDocImageManager.is() )
1413 aDocGraphicSeq = m_xDocImageManager->getImages( p, aCmdURLSeq );
1414 aModGraphicSeq = m_xModuleImageManager->getImages( p, aCmdURLSeq );
1416 i = 0;
1417 pIter = m_aCommandMap.begin();
1418 while ( pIter != pEnd )
1420 rtl::OUString aCommandURL = aCmdURLSeq[i];
1422 Image aImage;
1423 if ( aDocGraphicSeq.getLength() > 0 )
1424 aImage = Image( aDocGraphicSeq[i] );
1425 if ( !aImage )
1427 aImage = Image( aModGraphicSeq[i] );
1428 // Try also to query for add-on images before giving up and use an
1429 // empty image.
1430 if ( !aImage )
1431 aImage = QueryAddonsImage( aCmdURLSeq[i], bBigImages, m_bIsHiContrast );
1433 pIter->second.nImageInfo = 1; // mark image as module based
1435 else
1437 pIter->second.nImageInfo = 0; // mark image as document based
1439 setToolBarImage(aImage,pIter);
1440 ++pIter;
1441 ++i;
1445 void ToolBarManager::notifyRegisteredControllers( const rtl::OUString& aUIElementName, const rtl::OUString& aCommand )
1447 ResetableGuard aGuard( m_aLock );
1448 if ( !m_aSubToolBarControllerMap.empty() )
1450 SubToolBarToSubToolBarControllerMap::const_iterator pIter =
1451 m_aSubToolBarControllerMap.find( aUIElementName );
1453 if ( pIter != m_aSubToolBarControllerMap.end() )
1455 const SubToolBarControllerVector& rSubToolBarVector = pIter->second;
1456 if ( !rSubToolBarVector.empty() )
1458 SubToolBarControllerVector aNotifyVector = rSubToolBarVector;
1459 aGuard.unlock();
1461 const sal_uInt32 nCount = aNotifyVector.size();
1462 for ( sal_uInt32 i=0; i < nCount; i++ )
1466 Reference< XSubToolbarController > xController = aNotifyVector[i];
1467 if ( xController.is() )
1468 xController->functionSelected( aCommand );
1470 catch ( RuntimeException& e )
1472 throw e;
1474 catch ( Exception& )
1482 long ToolBarManager::HandleClick(void ( SAL_CALL XToolbarController::*_pClick )())
1484 ResetableGuard aGuard( m_aLock );
1486 if ( m_bDisposed )
1487 return 1;
1489 USHORT nId( m_pToolBar->GetCurItemId() );
1490 ToolBarControllerMap::const_iterator pIter = m_aControllerMap.find( nId );
1491 if ( pIter != m_aControllerMap.end() )
1493 Reference< XToolbarController > xController( pIter->second, UNO_QUERY );
1495 if ( xController.is() )
1496 (xController.get()->*_pClick)( );
1497 } // if ( pIter != m_aControllerMap.end() )
1498 return 1;
1501 IMPL_LINK( ToolBarManager, Click, ToolBox*, EMPTYARG )
1503 return HandleClick(&XToolbarController::click);
1506 IMPL_LINK( ToolBarManager, DropdownClick, ToolBox*, EMPTYARG )
1508 ResetableGuard aGuard( m_aLock );
1510 if ( m_bDisposed )
1511 return 1;
1513 USHORT nId( m_pToolBar->GetCurItemId() );
1514 ToolBarControllerMap::const_iterator pIter = m_aControllerMap.find( nId );
1515 if ( pIter != m_aControllerMap.end() )
1517 Reference< XToolbarController > xController( pIter->second, UNO_QUERY );
1519 if ( xController.is() )
1520 xController->createPopupWindow();
1522 return 1;
1525 IMPL_LINK( ToolBarManager, DoubleClick, ToolBox*, EMPTYARG )
1527 return HandleClick(&XToolbarController::doubleClick);
1530 void ToolBarManager::ImplClearPopupMenu( ToolBox *pToolBar )
1532 if ( m_bDisposed )
1533 return;
1535 PopupMenu *pMenu = pToolBar->GetMenu();
1537 // remove config entries from menu, so we have a clean menu to start with
1538 // remove submenu first
1539 PopupMenu* pItemMenu = pMenu->GetPopupMenu( 1 );
1540 if( pItemMenu )
1542 pItemMenu->Clear();
1543 delete pItemMenu;
1544 pItemMenu = NULL;
1545 pMenu->SetPopupMenu( 1, pItemMenu );
1548 // remove all items that were not added by the toolbar itself
1549 USHORT i;
1550 for( i=0; i<pMenu->GetItemCount(); )
1552 if( pMenu->GetItemId( i ) < TOOLBOX_MENUITEM_START )
1553 pMenu->RemoveItem( i );
1554 else
1555 i++;
1559 IMPL_LINK( ToolBarManager, MenuDeactivate, Menu*, pMenu )
1561 ResetableGuard aGuard( m_aLock );
1563 if ( m_bDisposed )
1564 return 1;
1566 if( pMenu != m_pToolBar->GetMenu() )
1567 return 1;
1569 ImplClearPopupMenu( m_pToolBar );
1571 return 0;
1574 Reference< XModel > ToolBarManager::GetModelFromFrame() const
1576 Reference< XController > xController = m_xFrame->getController();
1577 Reference< XModel > xModel;
1578 if ( xController.is() )
1579 xModel = xController->getModel();
1581 return xModel;
1584 sal_Bool ToolBarManager::IsPluginMode() const
1586 sal_Bool bPluginMode( sal_False );
1588 if ( m_xFrame.is() )
1590 Reference< XModel > xModel = GetModelFromFrame();
1591 if ( xModel.is() )
1593 Sequence< PropertyValue > aSeq = xModel->getArgs();
1594 comphelper::MediaDescriptor aMediaDescriptor( aSeq );
1595 bPluginMode = aMediaDescriptor.getUnpackedValueOrDefault< sal_Bool >(
1596 comphelper::MediaDescriptor::PROP_VIEWONLY(), sal_False );
1600 return bPluginMode;
1603 bool ToolBarManager::MenuItemAllowed( sal_uInt16 ) const
1605 return true;
1608 //added for i33668 by shizhoubo : 200804
1609 PopupMenu * ToolBarManager::GetToolBarCustomMeun(ToolBox* pToolBar)
1611 PopupMenu *pMenu = pToolBar->GetMenu();
1612 // remove all entries before inserting new ones
1613 ImplClearPopupMenu( pToolBar );
1614 // No config menu entries if command ".uno:ConfigureDialog" is not enabled
1615 Reference< XDispatch > xDisp;
1616 com::sun::star::util::URL aURL;
1617 if ( m_xFrame.is() )
1619 Reference< XDispatchProvider > xProv( m_xFrame, UNO_QUERY );
1620 aURL.Complete = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ConfigureDialog" ));
1621 m_xURLTransformer->parseStrict( aURL );
1622 if ( xProv.is() )
1623 xDisp = xProv->queryDispatch( aURL, ::rtl::OUString(), 0 );
1625 if ( !xDisp.is() || IsPluginMode() )
1626 return 0;
1629 // popup menu for quick customization
1630 sal_Bool bHideDisabledEntries = !SvtMenuOptions().IsEntryHidingEnabled();
1631 PopupMenu aPopupMenu( FwkResId( POPUPMENU_TOOLBAR_QUICKCUSTOMIZATION ));
1633 if ( m_pToolBar->IsCustomize() )
1635 USHORT nPos( 0 );
1636 PopupMenu* pItemMenu( aPopupMenu.GetPopupMenu( 1 ));
1638 sal_Bool bIsFloating( sal_False );
1640 DockingManager* pDockMgr = Window::GetDockingManager();
1641 if ( pDockMgr )
1642 bIsFloating = pDockMgr->IsFloating( m_pToolBar );
1644 if ( !bIsFloating )
1646 aPopupMenu.EnableItem( MENUITEM_TOOLBAR_DOCKTOOLBAR, sal_False );
1647 aPopupMenu.EnableItem( MENUITEM_TOOLBAR_DOCKALLTOOLBAR, sal_False );
1648 Reference< XDockableWindow > xDockable( VCLUnoHelper::GetInterface( m_pToolBar ), UNO_QUERY );
1649 if( xDockable.is() )
1650 aPopupMenu.CheckItem( MENUITEM_TOOLBAR_LOCKTOOLBARPOSITION, xDockable->isLocked() );
1652 else
1653 aPopupMenu.EnableItem( MENUITEM_TOOLBAR_LOCKTOOLBARPOSITION, sal_False );
1655 if ( !m_bCanBeCustomized )
1657 // Non-configurable toolbars should disable configuration menu items
1658 aPopupMenu.EnableItem( MENUITEM_TOOLBAR_VISIBLEBUTTON, sal_False );
1659 aPopupMenu.EnableItem( MENUITEM_TOOLBAR_CUSTOMIZETOOLBAR, sal_False );
1660 aPopupMenu.EnableItem( MENUITEM_TOOLBAR_LOCKTOOLBARPOSITION, sal_False );
1663 // Disable menu item CLOSE if the toolbar has no closer
1664 //added for issue64028 by shizhoubo
1665 if( !(pToolBar->GetFloatStyle() & WB_CLOSEABLE) )
1666 aPopupMenu.EnableItem(MENUITEM_TOOLBAR_CLOSE, sal_False);
1667 //end
1669 pItemMenu->SetMenuFlags (pItemMenu->GetMenuFlags () |
1670 MENU_FLAG_SHOWCHECKIMAGES);
1672 for ( nPos = 0; nPos < m_pToolBar->GetItemCount(); ++nPos )
1674 if ( m_pToolBar->GetItemType(nPos) == TOOLBOXITEM_BUTTON )
1676 USHORT nId = m_pToolBar->GetItemId(nPos);
1677 ::rtl::OUString aCommandURL = m_pToolBar->GetItemCommand( nId );
1678 pItemMenu->InsertItem( STARTID_CUSTOMIZE_POPUPMENU+nPos, m_pToolBar->GetItemText( nId ), MIB_CHECKABLE );
1679 pItemMenu->CheckItem( STARTID_CUSTOMIZE_POPUPMENU+nPos, m_pToolBar->IsItemVisible( nId ) );
1680 pItemMenu->SetItemCommand( STARTID_CUSTOMIZE_POPUPMENU+nPos, aCommandURL );
1681 pItemMenu->SetItemImage( STARTID_CUSTOMIZE_POPUPMENU+nPos,
1682 GetImageFromURL( m_xFrame,
1683 aCommandURL,
1684 sal_False,
1685 m_bIsHiContrast ));
1687 else
1689 pItemMenu->InsertSeparator();
1693 else
1695 USHORT nPos = aPopupMenu.GetItemPos( MENUITEM_TOOLBAR_CUSTOMIZETOOLBAR );
1696 if ( nPos != MENU_ITEM_NOTFOUND )
1697 aPopupMenu.RemoveItem( nPos );
1700 // copy all menu items to the toolbar menu
1701 if( pMenu->GetItemCount() )
1702 pMenu->InsertSeparator();
1704 USHORT i;
1705 for( i=0; i< aPopupMenu.GetItemCount(); i++)
1707 sal_uInt16 nId = aPopupMenu.GetItemId( i );
1708 if ( MenuItemAllowed( nId ))
1709 pMenu->CopyItem( aPopupMenu, i, MENU_APPEND );
1712 // set submenu to toolbar menu
1713 if( aPopupMenu.GetPopupMenu( 1 ) )
1715 // create an own submenu to avoid auto-delete when resource menu is deleted
1716 PopupMenu *pItemMenu = new PopupMenu();
1718 pItemMenu->SetMenuFlags (pItemMenu->GetMenuFlags () |
1719 MENU_FLAG_SHOWCHECKIMAGES);
1721 for( i=0; i< aPopupMenu.GetPopupMenu( 1 )->GetItemCount(); i++)
1722 pItemMenu->CopyItem( *aPopupMenu.GetPopupMenu( 1 ), i, MENU_APPEND );
1724 pMenu->SetPopupMenu( 1, pItemMenu );
1727 if ( bHideDisabledEntries )
1728 pMenu->RemoveDisabledEntries();
1730 return pMenu;
1733 // addd for 33668 by shizhoubo
1734 IMPL_LINK( ToolBarManager, Command, CommandEvent*, pCmdEvt )
1736 ResetableGuard aGuard( m_aLock );
1738 if ( m_bDisposed )
1739 return 1;
1740 if ( pCmdEvt->GetCommand() != COMMAND_CONTEXTMENU )
1741 return 0;
1743 PopupMenu * pMenu = GetToolBarCustomMeun(m_pToolBar);
1744 if (pMenu)
1746 // make sure all disabled entries will be shown
1747 pMenu->SetMenuFlags( pMenu->GetMenuFlags() | MENU_FLAG_ALWAYSSHOWDISABLEDENTRIES );
1748 ::Point aPoint( pCmdEvt->GetMousePosPixel() );
1749 pMenu->Execute( m_pToolBar, aPoint );
1752 return 0;
1754 //end
1756 IMPL_LINK( ToolBarManager, MenuButton, ToolBox*, pToolBar )
1758 ResetableGuard aGuard( m_aLock );
1760 if ( m_bDisposed )
1761 return 1;
1762 //modify for i33668 by shizhoubo:2008:04
1763 GetToolBarCustomMeun(pToolBar);
1764 //end
1765 return 0;
1768 IMPL_LINK( ToolBarManager, MenuSelect, Menu*, pMenu )
1770 // We have to hold a reference to ourself as it is possible that we will be disposed and
1771 // our refcount could be zero (destruction) otherwise.
1772 Reference< XInterface > xInterface( static_cast< OWeakObject* >( this ), UNO_QUERY );
1775 // The guard must be in its own context as the we can get destroyed when our
1776 // own xInterface reference get destroyed!
1777 ResetableGuard aGuard( m_aLock );
1779 if ( m_bDisposed )
1780 return 1;
1782 switch ( pMenu->GetCurItemId() )
1784 case MENUITEM_TOOLBAR_CUSTOMIZETOOLBAR:
1786 Reference< XDispatch > xDisp;
1787 com::sun::star::util::URL aURL;
1788 if ( m_xFrame.is() )
1790 Reference< XDispatchProvider > xProv( m_xFrame, UNO_QUERY );
1791 aURL.Complete = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ConfigureDialog" ));
1792 m_xURLTransformer->parseStrict( aURL );
1793 if ( xProv.is() )
1794 xDisp = xProv->queryDispatch( aURL, ::rtl::OUString(), 0 );
1797 if ( xDisp.is() )
1799 Sequence< PropertyValue > aPropSeq( 1 );
1801 aPropSeq[ 0 ].Name =
1802 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ResourceURL"));
1803 aPropSeq[ 0 ].Value <<= m_aResourceName;
1805 xDisp->dispatch( aURL, aPropSeq );
1807 break;
1810 case MENUITEM_TOOLBAR_DOCKTOOLBAR:
1812 ExecuteInfo* pExecuteInfo = new ExecuteInfo;
1814 pExecuteInfo->aToolbarResName = m_aResourceName;
1815 pExecuteInfo->nCmd = EXEC_CMD_DOCKTOOLBAR;
1816 pExecuteInfo->xLayoutManager = getLayoutManagerFromFrame( m_xFrame );
1818 Application::PostUserEvent( STATIC_LINK(0, ToolBarManager, ExecuteHdl_Impl), pExecuteInfo );
1819 break;
1822 case MENUITEM_TOOLBAR_DOCKALLTOOLBAR:
1824 ExecuteInfo* pExecuteInfo = new ExecuteInfo;
1826 pExecuteInfo->aToolbarResName = m_aResourceName;
1827 pExecuteInfo->nCmd = EXEC_CMD_DOCKALLTOOLBARS;
1828 pExecuteInfo->xLayoutManager = getLayoutManagerFromFrame( m_xFrame );
1830 Application::PostUserEvent( STATIC_LINK(0, ToolBarManager, ExecuteHdl_Impl), pExecuteInfo );
1831 break;
1834 case MENUITEM_TOOLBAR_LOCKTOOLBARPOSITION:
1836 Reference< XLayoutManager > xLayoutManager = getLayoutManagerFromFrame( m_xFrame );
1837 if ( xLayoutManager.is() )
1839 Reference< XDockableWindow > xDockable( VCLUnoHelper::GetInterface( m_pToolBar ), UNO_QUERY );
1841 if( xDockable->isLocked() )
1842 xLayoutManager->unlockWindow( m_aResourceName );
1843 else
1844 xLayoutManager->lockWindow( m_aResourceName );
1846 break;
1849 case MENUITEM_TOOLBAR_CLOSE:
1851 ExecuteInfo* pExecuteInfo = new ExecuteInfo;
1853 pExecuteInfo->aToolbarResName = m_aResourceName;
1854 pExecuteInfo->nCmd = EXEC_CMD_CLOSETOOLBAR;
1855 pExecuteInfo->xLayoutManager = getLayoutManagerFromFrame( m_xFrame );
1856 pExecuteInfo->xWindow = VCLUnoHelper::GetInterface( m_pToolBar );
1858 Application::PostUserEvent( STATIC_LINK(0, ToolBarManager, ExecuteHdl_Impl), pExecuteInfo );
1861 default:
1863 USHORT nId = pMenu->GetCurItemId();
1864 if(( nId > 0 ) && ( nId < TOOLBOX_MENUITEM_START ))
1866 // toggle toolbar button visibility
1867 rtl::OUString aCommand = pMenu->GetItemCommand( nId );
1869 Reference< XLayoutManager > xLayoutManager = getLayoutManagerFromFrame( m_xFrame );
1870 if ( xLayoutManager.is() )
1872 Reference< XUIElementSettings > xUIElementSettings( xLayoutManager->getElement( m_aResourceName ), UNO_QUERY );
1873 if ( xUIElementSettings.is() )
1875 Reference< XIndexContainer > xItemContainer( xUIElementSettings->getSettings( sal_True ), UNO_QUERY );
1876 sal_Int32 nCount = xItemContainer->getCount();
1877 for ( sal_Int32 i = 0; i < nCount; i++ )
1879 Sequence< PropertyValue > aProp;
1880 sal_Int32 nVisibleIndex( -1 );
1881 rtl::OUString aCommandURL;
1882 sal_Bool bVisible( sal_False );
1884 if ( xItemContainer->getByIndex( i ) >>= aProp )
1886 for ( sal_Int32 j = 0; j < aProp.getLength(); j++ )
1888 if ( aProp[j].Name.equalsAscii( ITEM_DESCRIPTOR_COMMANDURL ))
1890 aProp[j].Value >>= aCommandURL;
1892 else if ( aProp[j].Name.equalsAscii( ITEM_DESCRIPTOR_VISIBLE ))
1894 aProp[j].Value >>= bVisible;
1895 nVisibleIndex = j;
1899 if (( aCommandURL == aCommand ) && ( nVisibleIndex >= 0 ))
1901 // We have found the requested item, toggle the visible flag
1902 // and write back the configuration settings to the toolbar
1903 aProp[nVisibleIndex].Value = makeAny( !bVisible );
1906 xItemContainer->replaceByIndex( i, makeAny( aProp ));
1907 xUIElementSettings->setSettings( Reference< XIndexAccess >( xItemContainer, UNO_QUERY ));
1908 Reference< XPropertySet > xPropSet( xUIElementSettings, UNO_QUERY );
1909 if ( xPropSet.is() )
1911 Reference< XUIConfigurationPersistence > xUICfgMgr;
1912 if (( xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ConfigurationSource" ))) >>= xUICfgMgr ) && ( xUICfgMgr.is() ))
1913 xUICfgMgr->store();
1916 catch ( Exception& )
1920 break;
1927 break;
1931 // remove all entries - deactivate is not reliable
1932 // The method checks if we are already disposed and in that case does nothing!
1933 ImplClearPopupMenu( m_pToolBar );
1936 return 1;
1939 IMPL_LINK( ToolBarManager, Select, ToolBox*, EMPTYARG )
1941 if ( m_bDisposed )
1942 return 1;
1944 sal_Int16 nKeyModifier( (sal_Int16)m_pToolBar->GetModifier() );
1945 USHORT nId( m_pToolBar->GetCurItemId() );
1947 ToolBarControllerMap::const_iterator pIter = m_aControllerMap.find( nId );
1948 if ( pIter != m_aControllerMap.end() )
1950 Reference< XToolbarController > xController( pIter->second, UNO_QUERY );
1952 if ( xController.is() )
1953 xController->execute( nKeyModifier );
1956 return 1;
1959 IMPL_LINK( ToolBarManager, Highlight, ToolBox*, EMPTYARG )
1961 return 1;
1964 IMPL_LINK( ToolBarManager, Activate, ToolBox*, EMPTYARG )
1966 return 1;
1969 IMPL_LINK( ToolBarManager, Deactivate, ToolBox*, EMPTYARG )
1971 return 1;
1974 IMPL_LINK( ToolBarManager, StateChanged, StateChangedType*, pStateChangedType )
1976 if ( m_bDisposed )
1977 return 1;
1979 if ( *pStateChangedType == STATE_CHANGE_CONTROLBACKGROUND )
1981 // Check if we need to get new images for normal/high contrast mode
1982 CheckAndUpdateImages();
1984 else if ( *pStateChangedType == STATE_CHANGE_VISIBLE )
1986 if ( m_pToolBar->IsReallyVisible() )
1987 m_aAsyncUpdateControllersTimer.Start();
1989 else if ( *pStateChangedType == STATE_CHANGE_INITSHOW )
1991 m_aAsyncUpdateControllersTimer.Start();
1993 return 1;
1996 IMPL_LINK( ToolBarManager, DataChanged, DataChangedEvent*, pDataChangedEvent )
1998 if ((( pDataChangedEvent->GetType() == DATACHANGED_SETTINGS ) ||
1999 ( pDataChangedEvent->GetType() == DATACHANGED_DISPLAY )) &&
2000 ( pDataChangedEvent->GetFlags() & SETTINGS_STYLE ))
2002 // Check if we need to get new images for normal/high contrast mode
2003 CheckAndUpdateImages();
2006 for ( USHORT nPos = 0; nPos < m_pToolBar->GetItemCount(); ++nPos )
2008 const USHORT nId = m_pToolBar->GetItemId(nPos);
2009 Window* pWindow = m_pToolBar->GetItemWindow( nId );
2010 if ( pWindow )
2012 const DataChangedEvent& rDCEvt( *pDataChangedEvent );
2013 pWindow->DataChanged( rDCEvt );
2017 if ( !m_pToolBar->IsFloatingMode() &&
2018 m_pToolBar->IsVisible() )
2020 // Resize toolbar, layout manager is resize listener and will calc
2021 // the layout automatically.
2022 ::Size aSize( m_pToolBar->CalcWindowSizePixel() );
2023 m_pToolBar->SetOutputSizePixel( aSize );
2026 return 1;
2029 IMPL_LINK( ToolBarManager, AsyncUpdateControllersHdl, Timer *, EMPTYARG )
2031 // The guard must be in its own context as the we can get destroyed when our
2032 // own xInterface reference get destroyed!
2033 Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY );
2035 ResetableGuard aGuard( m_aLock );
2037 if ( m_bDisposed )
2038 return 1;
2040 // Request to update our controllers
2041 m_aAsyncUpdateControllersTimer.Stop();
2042 UpdateControllers();
2044 return 0;
2047 IMPL_STATIC_LINK_NOINSTANCE( ToolBarManager, ExecuteHdl_Impl, ExecuteInfo*, pExecuteInfo )
2051 // Asynchronous execution as this can lead to our own destruction!
2052 if (( pExecuteInfo->nCmd == EXEC_CMD_CLOSETOOLBAR ) &&
2053 ( pExecuteInfo->xLayoutManager.is() ) &&
2054 ( pExecuteInfo->xWindow.is() ))
2056 // Use docking window close to close the toolbar. The layout manager is
2057 // listener and will react correctly according to the context sensitive
2058 // flag of our toolbar.
2059 Window* pWin = VCLUnoHelper::GetWindow( pExecuteInfo->xWindow );
2060 DockingWindow* pDockWin = dynamic_cast< DockingWindow* >( pWin );
2061 if ( pDockWin )
2062 pDockWin->Close();
2064 else if (( pExecuteInfo->nCmd == EXEC_CMD_DOCKTOOLBAR ) &&
2065 ( pExecuteInfo->xLayoutManager.is() ))
2067 ::com::sun::star::awt::Point aPoint;
2068 aPoint.X = aPoint.Y = SAL_MAX_INT32;
2069 pExecuteInfo->xLayoutManager->dockWindow( pExecuteInfo->aToolbarResName,
2070 DockingArea_DOCKINGAREA_DEFAULT,
2071 aPoint );
2073 else if (( pExecuteInfo->nCmd == EXEC_CMD_DOCKALLTOOLBARS ) &&
2074 ( pExecuteInfo->xLayoutManager.is() ))
2076 pExecuteInfo->xLayoutManager->dockAllWindows( UIElementType::TOOLBAR );
2079 catch ( Exception& )
2083 delete pExecuteInfo;
2084 return 0;
2087 Image ToolBarManager::QueryAddonsImage( const ::rtl::OUString& aCommandURL, bool bBigImages, bool bHiContrast )
2089 Image aImage = framework::AddonsOptions().GetImageFromURL( aCommandURL, bBigImages, bHiContrast );
2090 return aImage;