1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_framework.hxx"
30 #include <uielement/toolbarmanager.hxx>
31 
32 //_________________________________________________________________________________________________________________
33 //	my own includes
34 //_________________________________________________________________________________________________________________
35 
36 
37 #ifndef __FRAMEWORK_UIELEMENT_TOOLBAR_HXX
38 #include <uielement/toolbar.hxx>
39 #endif
40 #ifndef __FRAMEWORK_UIELEMENT_GENERICTOOLBARCONTROLLER_HXX
41 #include <uielement/generictoolbarcontroller.hxx>
42 #endif
43 #include <threadhelp/resetableguard.hxx>
44 #include "services.h"
45 #include "general.h"
46 #include "properties.h"
47 #include <framework/imageproducer.hxx>
48 #include <framework/sfxhelperfunctions.hxx>
49 #include <classes/fwkresid.hxx>
50 #ifndef __FRAMEWORK_CLASES_RESOURCE_HRC_
51 #include <classes/resource.hrc>
52 #endif
53 #include <framework/addonsoptions.hxx>
54 #include <uielement/toolbarmerger.hxx>
55 #include <framework/acceleratorinfo.hxx>
56 
57 //_________________________________________________________________________________________________________________
58 //	interface includes
59 //_________________________________________________________________________________________________________________
60 #include <com/sun/star/ui/ItemType.hpp>
61 #include <com/sun/star/frame/XDispatchProvider.hpp>
62 #include <com/sun/star/beans/XPropertySet.hpp>
63 #include <com/sun/star/awt/XDockableWindow.hpp>
64 #include <com/sun/star/frame/XLayoutManager.hpp>
65 #ifndef _COM_SUN_STAR_UI_XDOCKINGAREA_HPP_
66 #include <com/sun/star/ui/DockingArea.hpp>
67 #endif
68 #include <com/sun/star/graphic/XGraphic.hpp>
69 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
70 #include <com/sun/star/frame/XModuleManager.hpp>
71 #include <com/sun/star/ui/XUIElementSettings.hpp>
72 #include <com/sun/star/ui/XUIConfigurationPersistence.hpp>
73 #include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
74 #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
75 #include <com/sun/star/ui/ImageType.hpp>
76 #include <com/sun/star/ui/UIElementType.hpp>
77 #include <comphelper/sequence.hxx>
78 #include <com/sun/star/frame/status/Visibility.hpp>
79 #include <com/sun/star/lang/DisposedException.hpp>
80 
81 //_________________________________________________________________________________________________________________
82 //	other includes
83 //_________________________________________________________________________________________________________________
84 #include <svtools/imgdef.hxx>
85 #include <svtools/toolboxcontroller.hxx>
86 #include <unotools/cmdoptions.hxx>
87 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
88 #include <toolkit/unohlp.hxx>
89 #endif
90 #include <comphelper/mediadescriptor.hxx>
91 #include <svtools/miscopt.hxx>
92 #include <svl/imageitm.hxx>
93 #include <svtools/framestatuslistener.hxx>
94 #include <vcl/svapp.hxx>
95 #include <vcl/menu.hxx>
96 #include <vcl/syswin.hxx>
97 #include <vcl/taskpanelist.hxx>
98 #include <rtl/logfile.hxx>
99 #include <svtools/menuoptions.hxx>
100 #include <unotools/cmdoptions.hxx>
101 #include <boost/bind.hpp>
102 #include <svtools/acceleratorexecute.hxx>
103 
104 //_________________________________________________________________________________________________________________
105 //	namespaces
106 //_________________________________________________________________________________________________________________
107 
108 using rtl::OUString;
109 
110 using namespace ::com::sun::star::awt;
111 using namespace ::com::sun::star::beans;
112 using namespace ::com::sun::star::uno;
113 using namespace ::com::sun::star::lang;
114 using namespace ::com::sun::star::frame;
115 using namespace ::com::sun::star::graphic;
116 using namespace ::com::sun::star::util;
117 using namespace ::com::sun::star::container;
118 using namespace ::com::sun::star::frame;
119 using namespace ::com::sun::star::ui;
120 using namespace ::com::sun::star;
121 
122 namespace framework
123 {
124 
125 static const char   ITEM_DESCRIPTOR_COMMANDURL[]    = "CommandURL";
126 static const char   ITEM_DESCRIPTOR_HELPURL[]       = "HelpURL";
127 static const char   ITEM_DESCRIPTOR_TOOLTIP[]       = "Tooltip";
128 static const char   ITEM_DESCRIPTOR_CONTAINER[]     = "ItemDescriptorContainer";
129 static const char   ITEM_DESCRIPTOR_LABEL[]         = "Label";
130 static const char   ITEM_DESCRIPTOR_TYPE[]          = "Type";
131 static const char   ITEM_DESCRIPTOR_VISIBLE[]       = "IsVisible";
132 static const char   ITEM_DESCRIPTOR_WIDTH[]         = "Width";
133 static const char   ITEM_DESCRIPTOR_STYLE[]         = "Style";
134 
135 static const sal_Int32 ITEM_DESCRIPTOR_COMMANDURL_LEN  = 10;
136 static const sal_Int32 ITEM_DESCRIPTOR_HELPURL_LEN     = 7;
137 static const sal_Int32 ITEM_DESCRIPTOR_TOOLTIP_LEN     = 7;
138 static const sal_Int32 ITEM_DESCRIPTOR_CONTAINER_LEN   = 23;
139 static const sal_Int32 ITEM_DESCRIPTOR_LABEL_LEN       = 5;
140 static const sal_Int32 ITEM_DESCRIPTOR_TYPE_LEN        = 4;
141 static const sal_Int32 ITEM_DESCRIPTOR_VISIBLE_LEN     = 9;
142 static const sal_Int32 ITEM_DESCRIPTOR_WIDTH_LEN       = 5;
143 static const sal_Int32 ITEM_DESCRIPTOR_STYLE_LEN       = 5;
144 
145 static const char   HELPID_PREFIX[]                 = "helpid:";
146 static const char   HELPID_PREFIX_TESTTOOL[]        = ".HelpId:";
147 //static sal_Int32    HELPID_PREFIX_LENGTH            = 7;
148 static const sal_uInt16 STARTID_CUSTOMIZE_POPUPMENU     = 1000;
149 
150 #define MENUPREFIX "private:resource/menubar/"
151 
152 class ImageOrientationListener : public svt::FrameStatusListener
153 {
154     public:
155         ImageOrientationListener( const Reference< XStatusListener > rReceiver,
156                                   const Reference< XMultiServiceFactory > rServiceManager,
157                                   const Reference< XFrame > rFrame );
158         virtual ~ImageOrientationListener();
159 
160 		virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event ) throw ( ::com::sun::star::uno::RuntimeException );
161 
162     private:
163         Reference< XStatusListener > m_xReceiver;
164 };
165 
166 ImageOrientationListener::ImageOrientationListener(
167     const Reference< XStatusListener > rReceiver,
168     const Reference< XMultiServiceFactory > rServiceManager,
169     const Reference< XFrame > rFrame ) :
170     FrameStatusListener( rServiceManager, rFrame ),
171     m_xReceiver( rReceiver )
172 {
173 }
174 
175 ImageOrientationListener::~ImageOrientationListener()
176 {
177 }
178 
179 void SAL_CALL ImageOrientationListener::statusChanged( const FeatureStateEvent& Event )
180 throw ( RuntimeException )
181 {
182     if ( m_xReceiver.is() )
183         m_xReceiver->statusChanged( Event );
184 }
185 
186 //*****************************************************************************************************************
187 
188 static sal_Int16 getImageTypeFromBools( sal_Bool bBig, sal_Bool bHighContrast )
189 {
190     sal_Int16 n( 0 );
191     if ( bBig )
192         n |= ::com::sun::star::ui::ImageType::SIZE_LARGE;
193     if ( bHighContrast )
194         n |= ::com::sun::star::ui::ImageType::COLOR_HIGHCONTRAST;
195     return n;
196 }
197 
198 static ::com::sun::star::uno::Reference< ::com::sun::star::frame::XLayoutManager > getLayoutManagerFromFrame(
199     ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame )
200 {
201     ::com::sun::star::uno::Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
202 
203     Reference< XPropertySet > xPropSet( rFrame, UNO_QUERY );
204     if ( xPropSet.is() )
205     {
206         try
207         {
208             xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ))) >>= xLayoutManager;
209         }
210         catch ( RuntimeException& )
211         {
212             throw;
213         }
214         catch ( Exception& )
215         {
216         }
217     }
218 
219     return xLayoutManager;
220 }
221 
222 //*****************************************************************************************************************
223 //	XInterface, XTypeProvider, XServiceInfo
224 //*****************************************************************************************************************
225 DEFINE_XINTERFACE_6                     (   ToolBarManager                                                                                              ,
226                                             OWeakObject                                                                                                 ,
227                                             DIRECT_INTERFACE( ::com::sun::star::lang::XTypeProvider                                                     ),
228                                             DIRECT_INTERFACE( ::com::sun::star::lang::XComponent                                                        ),
229 											DIRECT_INTERFACE( ::com::sun::star::frame::XFrameActionListener                                             ),
230                                             DIRECT_INTERFACE( ::com::sun::star::ui::XUIConfigurationListener                                    ),
231                                             DIRECT_INTERFACE( ::com::sun::star::frame::XStatusListener                                                  ),
232 											DERIVED_INTERFACE( ::com::sun::star::lang::XEventListener, ::com::sun::star::frame::XFrameActionListener    )
233 										)
234 
235 DEFINE_XTYPEPROVIDER_6                  (   ToolBarManager		                                    ,
236                                             ::com::sun::star::lang::XTypeProvider		            ,
237                                             ::com::sun::star::lang::XComponent                      ,
238                                             ::com::sun::star::ui::XUIConfigurationListener  ,
239 											::com::sun::star::frame::XFrameActionListener           ,
240                                             ::com::sun::star::frame::XStatusListener                ,
241 											::com::sun::star::lang::XEventListener
242 										)
243 
244 ToolBarManager::ToolBarManager( const Reference< XMultiServiceFactory >& rServiceManager,
245                                 const Reference< XFrame >& rFrame,
246                                 const rtl::OUString& rResourceName,
247                                 ToolBar* pToolBar ) :
248     ThreadHelpBase( &Application::GetSolarMutex() ),
249     OWeakObject(),
250     m_bDisposed( sal_False ),
251     m_bIsHiContrast( pToolBar->GetSettings().GetStyleSettings().GetHighContrastMode() ),
252     m_bSmallSymbols( !SvtMiscOptions().AreCurrentSymbolsLarge() ),
253     m_bModuleIdentified( sal_False ),
254     m_bAddedToTaskPaneList( sal_True ),
255     m_bFrameActionRegistered( sal_False ),
256     m_bUpdateControllers( sal_False ),
257     m_bImageOrientationRegistered( sal_False ),
258     m_bImageMirrored( sal_False ),
259     m_bCanBeCustomized( sal_True ),
260     m_lImageRotation( 0 ),
261     m_pToolBar( pToolBar ),
262     m_aResourceName( rResourceName ),
263     m_xFrame( rFrame ),
264     m_aListenerContainer( m_aLock.getShareableOslMutex() ),
265     m_xServiceManager( rServiceManager ),
266     m_nSymbolsStyle( SvtMiscOptions().GetCurrentSymbolsStyle() ),
267     m_bAcceleratorCfg( sal_False )
268 {
269     Window* pWindow = m_pToolBar;
270     while ( pWindow && !pWindow->IsSystemWindow() )
271         pWindow = pWindow->GetParent();
272 
273     if ( pWindow )
274         ((SystemWindow *)pWindow)->GetTaskPaneList()->AddWindow( m_pToolBar );
275 
276     if ( m_xServiceManager.is() )
277     {
278         m_xToolbarControllerRegistration = Reference< XUIControllerRegistration >(
279                                                     m_xServiceManager->createInstance( SERVICENAME_TOOLBARCONTROLLERFACTORY ),
280                                                 UNO_QUERY );
281 
282         m_xURLTransformer.set( m_xServiceManager->createInstance(
283                                                                 SERVICENAME_URLTRANSFORMER),
284                                                              UNO_QUERY );
285     }
286 
287     m_pToolBar->SetSelectHdl( LINK( this, ToolBarManager, Select) );
288 	m_pToolBar->SetActivateHdl( LINK( this, ToolBarManager, Activate) );
289 	m_pToolBar->SetDeactivateHdl( LINK( this, ToolBarManager, Deactivate) );
290     m_pToolBar->SetClickHdl( LINK( this, ToolBarManager, Click ) );
291     m_pToolBar->SetDropdownClickHdl( LINK( this, ToolBarManager, DropdownClick ) );
292     m_pToolBar->SetDoubleClickHdl( LINK( this, ToolBarManager, DoubleClick ) );
293     m_pToolBar->SetStateChangedHdl( LINK( this, ToolBarManager, StateChanged ) );
294     m_pToolBar->SetDataChangedHdl( LINK( this, ToolBarManager, DataChanged ) );
295     m_pToolBar->SetToolboxButtonSize( m_bSmallSymbols ? TOOLBOX_BUTTONSIZE_SMALL : TOOLBOX_BUTTONSIZE_LARGE );
296 
297     // enables a menu for clipped items and customization
298     SvtCommandOptions aCmdOptions;
299     sal_uInt16 nMenuType = TOOLBOX_MENUTYPE_CLIPPEDITEMS;
300     if ( !aCmdOptions.Lookup( SvtCommandOptions::CMDOPTION_DISABLED, ::rtl::OUString::createFromAscii( "CreateDialog" )))
301          nMenuType |= TOOLBOX_MENUTYPE_CUSTOMIZE;
302 	//added for issue33668 by shizhoubo
303 	m_pToolBar->SetCommandHdl( LINK( this, ToolBarManager, Command ) );
304 	//end
305     m_pToolBar->SetMenuType( nMenuType );
306     m_pToolBar->SetMenuButtonHdl( LINK( this, ToolBarManager, MenuButton ) );
307     m_pToolBar->GetMenu()->SetSelectHdl( LINK( this, ToolBarManager, MenuSelect ) );
308     m_pToolBar->GetMenu()->SetDeactivateHdl( LINK( this, ToolBarManager, MenuDeactivate ) );
309 
310     // set name for testtool, the useful part is after the last '/'
311     sal_Int32 idx = rResourceName.lastIndexOf('/');
312     idx++; // will become 0 if '/' not found: use full string
313     ::rtl::OString  aHelpIdAsString( HELPID_PREFIX_TESTTOOL );
314     ::rtl::OUString  aToolbarName = rResourceName.copy( idx );
315     aHelpIdAsString += rtl::OUStringToOString( aToolbarName, RTL_TEXTENCODING_UTF8 );;
316     m_pToolBar->SetHelpId( aHelpIdAsString );
317 
318 	m_aAsyncUpdateControllersTimer.SetTimeout( 50 );
319 	m_aAsyncUpdateControllersTimer.SetTimeoutHdl( LINK( this, ToolBarManager, AsyncUpdateControllersHdl ) );
320 }
321 
322 ToolBarManager::~ToolBarManager()
323 {
324     OSL_ASSERT( m_pToolBar == 0 );
325     OSL_ASSERT( !m_bAddedToTaskPaneList );
326 }
327 
328 void ToolBarManager::Destroy()
329 {
330     ResetableGuard aGuard( m_aLock );
331     if ( m_bAddedToTaskPaneList )
332     {
333         Window* pWindow = m_pToolBar;
334         while ( pWindow && !pWindow->IsSystemWindow() )
335             pWindow = pWindow->GetParent();
336 
337         if ( pWindow )
338             ((SystemWindow *)pWindow)->GetTaskPaneList()->RemoveWindow( m_pToolBar );
339         m_bAddedToTaskPaneList = sal_False;
340     }
341 
342     // Delete the additional add-ons data
343     for ( sal_uInt16 i = 0; i < m_pToolBar->GetItemCount(); i++ )
344     {
345         sal_uInt16 nItemId = m_pToolBar->GetItemId( i );
346         if ( nItemId > 0 )
347             delete static_cast< AddonsParams* >( m_pToolBar->GetItemData( nItemId ));
348     }
349 
350     // Hide toolbar as lazy delete can destroy the toolbar much later.
351     m_pToolBar->Hide();
352     /* #i99167# removed change for i93173 since there is some weird crash */
353         // #i93173# delete toolbar lazily as we can still be in one of its handlers
354     m_pToolBar->doLazyDelete();
355 
356 	Link aEmpty;
357 	m_pToolBar->SetSelectHdl( aEmpty );
358 	m_pToolBar->SetActivateHdl( aEmpty );
359 	m_pToolBar->SetDeactivateHdl( aEmpty );
360     m_pToolBar->SetClickHdl( aEmpty );
361     m_pToolBar->SetDropdownClickHdl( aEmpty );
362     m_pToolBar->SetDoubleClickHdl( aEmpty );
363     m_pToolBar->SetStateChangedHdl( aEmpty );
364     m_pToolBar->SetDataChangedHdl( aEmpty );
365 
366 //    delete m_pToolBar;
367     m_pToolBar = 0;
368 }
369 
370 ToolBox* ToolBarManager::GetToolBar() const
371 {
372     ResetableGuard aGuard( m_aLock );
373     return m_pToolBar;
374 }
375 
376 void ToolBarManager::CheckAndUpdateImages()
377 {
378     ResetableGuard aGuard( m_aLock );
379     sal_Bool bRefreshImages = sal_False;
380 
381     // Check if high contrast/normal mode have changed
382 	if ( m_pToolBar->GetSettings().GetStyleSettings().GetHighContrastMode() )
383 	{
384 		if ( !m_bIsHiContrast )
385 		{
386             bRefreshImages = sal_True;
387 			m_bIsHiContrast = sal_True;
388 		}
389 	}
390 	else if ( m_bIsHiContrast )
391     {
392         bRefreshImages = sal_True;
393 	    m_bIsHiContrast = sal_False;
394 	}
395 
396     SvtMiscOptions aMiscOptions;
397     bool bCurrentSymbolsSmall = !aMiscOptions.AreCurrentSymbolsLarge();
398     if ( m_bSmallSymbols != bCurrentSymbolsSmall )
399     {
400         bRefreshImages = sal_True;
401         m_bSmallSymbols = bCurrentSymbolsSmall;
402     }
403 
404     sal_Int16 nCurrentSymbolsStyle = aMiscOptions.GetCurrentSymbolsStyle();
405     if ( m_nSymbolsStyle != nCurrentSymbolsStyle )
406     {
407         bRefreshImages = sal_True;
408         m_nSymbolsStyle = nCurrentSymbolsStyle;
409     }
410 
411     // Refresh images if requested
412     if ( bRefreshImages )
413         RefreshImages();
414 }
415 
416 void ToolBarManager::RefreshImages()
417 {
418     ResetableGuard aGuard( m_aLock );
419 
420     sal_Bool  bBigImages( SvtMiscOptions().AreCurrentSymbolsLarge() );
421     for ( sal_uInt16 nPos = 0; nPos < m_pToolBar->GetItemCount(); nPos++ )
422     {
423         sal_uInt16 nId( m_pToolBar->GetItemId( nPos ) );
424 
425         if ( nId > 0 )
426         {
427             ::rtl::OUString aCommandURL = m_pToolBar->GetItemCommand( nId );
428 			Image aImage = GetImageFromURL( m_xFrame, aCommandURL, bBigImages, m_bIsHiContrast );
429 			// Try also to query for add-on images before giving up and use an
430             // empty image.
431 			if ( !aImage )
432 				aImage = QueryAddonsImage( aCommandURL, bBigImages, m_bIsHiContrast );
433 			m_pToolBar->SetItemImage( nId, aImage );
434         }
435     }
436 
437     m_pToolBar->SetToolboxButtonSize( bBigImages ? TOOLBOX_BUTTONSIZE_LARGE : TOOLBOX_BUTTONSIZE_SMALL );
438     ::Size aSize = m_pToolBar->CalcWindowSizePixel();
439     m_pToolBar->SetOutputSizePixel( aSize );
440 }
441 
442 void ToolBarManager::UpdateImageOrientation()
443 {
444     ResetableGuard aGuard( m_aLock );
445 
446     if ( m_xUICommandLabels.is() )
447     {
448         sal_Int32 i;
449         Sequence< rtl::OUString > aSeqMirrorCmd;
450         Sequence< rtl::OUString > aSeqRotateCmd;
451         m_xUICommandLabels->getByName(
452             rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( UICOMMANDDESCRIPTION_NAMEACCESS_COMMANDMIRRORIMAGELIST ))) >>= aSeqMirrorCmd;
453         m_xUICommandLabels->getByName(
454             rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( UICOMMANDDESCRIPTION_NAMEACCESS_COMMANDROTATEIMAGELIST ))) >>= aSeqRotateCmd;
455 
456         CommandToInfoMap::iterator pIter;
457         for ( i = 0; i < aSeqMirrorCmd.getLength(); i++ )
458         {
459             rtl::OUString aMirrorCmd = aSeqMirrorCmd[i];
460             pIter = m_aCommandMap.find( aMirrorCmd );
461             if ( pIter != m_aCommandMap.end() )
462                 pIter->second.bMirrored = sal_True;
463         }
464         for ( i = 0; i < aSeqRotateCmd.getLength(); i++ )
465         {
466             rtl::OUString aRotateCmd = aSeqRotateCmd[i];
467             pIter = m_aCommandMap.find( aRotateCmd );
468             if ( pIter != m_aCommandMap.end() )
469                 pIter->second.bRotated = sal_True;
470         }
471     }
472 
473     for ( sal_uInt16 nPos = 0; nPos < m_pToolBar->GetItemCount(); nPos++ )
474     {
475         sal_uInt16 nId = m_pToolBar->GetItemId( nPos );
476         if ( nId > 0 )
477         {
478             rtl::OUString aCmd = m_pToolBar->GetItemCommand( nId );
479 
480             CommandToInfoMap::const_iterator pIter = m_aCommandMap.find( aCmd );
481             if ( pIter != m_aCommandMap.end() )
482             {
483                 if ( pIter->second.bRotated )
484                 {
485                     m_pToolBar->SetItemImageMirrorMode( nId, sal_False );
486                     m_pToolBar->SetItemImageAngle( nId, m_lImageRotation );
487                 }
488                 if ( pIter->second.bMirrored )
489                     m_pToolBar->SetItemImageMirrorMode( nId, m_bImageMirrored );
490             }
491         }
492     }
493 }
494 
495 void ToolBarManager::UpdateControllers()
496 {
497     RTL_LOGFILE_CONTEXT( aLog, "framework (cd100003) ::ToolBarManager::UpdateControllers" );
498 
499     if ( !m_bUpdateControllers )
500     {
501         m_bUpdateControllers = sal_True;
502         ToolBarControllerMap::iterator pIter = m_aControllerMap.begin();
503 
504         while ( pIter != m_aControllerMap.end() )
505         {
506             try
507             {
508                 Reference< XUpdatable > xUpdatable( pIter->second, UNO_QUERY );
509                 if ( xUpdatable.is() )
510                     xUpdatable->update();
511             }
512             catch ( Exception& )
513             {
514             }
515             ++pIter;
516         }
517     }
518     m_bUpdateControllers = sal_False;
519 }
520 //for update toolbar controller via Support Visible by shizhoubo
521 void ToolBarManager::UpdateController( ::com::sun::star::uno::Reference< ::com::sun::star::frame::XToolbarController > xController)
522 {
523 	RTL_LOGFILE_CONTEXT( aLog, "framework (cd100003) ::ToolBarManager::UpdateControllers" );
524 
525     if ( !m_bUpdateControllers )
526     {
527 		m_bUpdateControllers = sal_True;
528 		try
529         {   if(xController.is())
530 			{
531 				Reference< XUpdatable > xUpdatable( xController, UNO_QUERY );
532 				if ( xUpdatable.is() )
533 					xUpdatable->update();
534 			}
535          }
536          catch ( Exception& )
537          {
538          }
539 
540        /* m_bUpdateControllers = sal_True;
541         ToolBarControllerMap::iterator pIter = m_aControllerMap.begin();
542 
543         while ( pIter != m_aControllerMap.end() )
544         {
545             try
546             {
547                 Reference< XUpdatable > xUpdatable( pIter->second, UNO_QUERY );
548                 if ( xUpdatable.is() )
549                     xUpdatable->update();
550             }
551             catch ( Exception& )
552             {
553             }
554             ++pIter;
555         }*/
556 
557     }
558     m_bUpdateControllers = sal_False;
559 }
560 //end
561 void ToolBarManager::frameAction( const FrameActionEvent& Action )
562 throw ( RuntimeException )
563 {
564     ResetableGuard aGuard( m_aLock );
565     if ( Action.Action == FrameAction_CONTEXT_CHANGED )
566         m_aAsyncUpdateControllersTimer.Start();
567 }
568 
569 void SAL_CALL ToolBarManager::statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event )
570 throw ( ::com::sun::star::uno::RuntimeException )
571 {
572     ResetableGuard aGuard( m_aLock );
573     if ( m_bDisposed )
574         return;
575 
576     if ( Event.FeatureURL.Complete.equalsAscii( ".uno:ImageOrientation" ))
577     {
578         SfxImageItem aItem( 1, 0 );
579         aItem.PutValue( Event.State );
580 
581         m_lImageRotation = aItem.GetRotation();
582         m_bImageMirrored = aItem.IsMirrored();
583         UpdateImageOrientation();
584     }
585 }
586 
587 void SAL_CALL ToolBarManager::disposing( const EventObject& Source ) throw ( RuntimeException )
588 {
589     {
590         ResetableGuard aGuard( m_aLock );
591         if ( m_bDisposed )
592             return;
593     }
594 
595     RemoveControllers();
596 
597 	{
598 	    ResetableGuard aGuard( m_aLock );
599 		if ( m_xDocImageManager.is() )
600         {
601 			try
602 			{
603 				m_xDocImageManager->removeConfigurationListener(
604 					Reference< XUIConfigurationListener >(
605 						static_cast< OWeakObject* >( this ), UNO_QUERY ));
606 			}
607 			catch ( Exception& )
608 			{
609 			}
610 		}
611 
612         if ( m_xModuleImageManager.is() )
613         {
614             try
615             {
616                 m_xModuleImageManager->removeConfigurationListener(
617                     Reference< XUIConfigurationListener >(
618                         static_cast< OWeakObject* >( this ), UNO_QUERY ));
619             }
620             catch ( Exception& )
621             {
622             }
623         }
624 
625         if ( m_xImageOrientationListener.is() )
626         {
627             ImageOrientationListener* pImageOrientation =
628                 (ImageOrientationListener*)m_xImageOrientationListener.get();
629             pImageOrientation->unbindListener();
630             m_xImageOrientationListener.clear();
631         }
632 
633         m_xDocImageManager.clear();
634         m_xModuleImageManager.clear();
635 
636         if ( Source.Source == Reference< XInterface >( m_xFrame, UNO_QUERY ))
637             m_xFrame.clear();
638 
639         m_xServiceManager.clear();
640     }
641 }
642 
643 // XComponent
644 void SAL_CALL ToolBarManager::dispose() throw( RuntimeException )
645 {
646     Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY );
647 
648     EventObject aEvent( xThis );
649     m_aListenerContainer.disposeAndClear( aEvent );
650 
651 	{
652 	    ResetableGuard aGuard( m_aLock );
653 
654         // stop timer to prevent timer events after dispose
655         m_aAsyncUpdateControllersTimer.Stop();
656 
657         RemoveControllers();
658 
659         if ( m_xDocImageManager.is() )
660         {
661             try
662             {
663                 m_xDocImageManager->removeConfigurationListener(
664                     Reference< XUIConfigurationListener >(
665                         static_cast< OWeakObject* >( this ), UNO_QUERY ));
666             }
667             catch ( Exception& )
668             {
669             }
670         }
671         m_xDocImageManager.clear();
672         if ( m_xModuleImageManager.is() )
673         {
674             try
675             {
676                 m_xModuleImageManager->removeConfigurationListener(
677                     Reference< XUIConfigurationListener >(
678                         static_cast< OWeakObject* >( this ), UNO_QUERY ));
679             }
680             catch ( Exception& )
681             {
682             }
683         }
684         m_xModuleImageManager.clear();
685 
686         ImplClearPopupMenu( m_pToolBar );
687 
688         // We have to destroy our toolbar instance now.
689         Destroy();
690 
691         if ( m_bFrameActionRegistered && m_xFrame.is() )
692         {
693             try
694             {
695                 m_xFrame->removeFrameActionListener( Reference< XFrameActionListener >(
696                                                         static_cast< ::cppu::OWeakObject *>( this ), UNO_QUERY ));
697             }
698             catch ( Exception& )
699             {
700             }
701         }
702 
703         if ( m_xImageOrientationListener.is() )
704         {
705             ImageOrientationListener* pImageOrientation =
706                 (ImageOrientationListener*)m_xImageOrientationListener.get();
707             pImageOrientation->unbindListener();
708             m_xImageOrientationListener.clear();
709         }
710 
711         m_xFrame.clear();
712         m_xServiceManager.clear();
713         m_xGlobalAcceleratorManager.clear();
714         m_xModuleAcceleratorManager.clear();
715         m_xDocAcceleratorManager.clear();
716 
717         m_bDisposed = sal_True;
718     }
719 }
720 
721 void SAL_CALL ToolBarManager::addEventListener( const Reference< XEventListener >& xListener ) throw( RuntimeException )
722 {
723     ResetableGuard aGuard( m_aLock );
724 
725 	/* SAFE AREA ----------------------------------------------------------------------------------------------- */
726     if ( m_bDisposed )
727         throw DisposedException();
728 
729     m_aListenerContainer.addInterface( ::getCppuType( ( const Reference< XEventListener >* ) NULL ), xListener );
730 }
731 
732 void SAL_CALL ToolBarManager::removeEventListener( const Reference< XEventListener >& xListener ) throw( RuntimeException )
733 {
734     m_aListenerContainer.removeInterface( ::getCppuType( ( const Reference< XEventListener >* ) NULL ), xListener );
735 }
736 
737 // XUIConfigurationListener
738 void SAL_CALL ToolBarManager::elementInserted( const ::com::sun::star::ui::ConfigurationEvent& Event ) throw (::com::sun::star::uno::RuntimeException)
739 {
740     impl_elementChanged(false,Event);
741 }
742 
743 void SAL_CALL ToolBarManager::elementRemoved( const ::com::sun::star::ui::ConfigurationEvent& Event ) throw (::com::sun::star::uno::RuntimeException)
744 {
745     impl_elementChanged(true,Event);
746 }
747 void ToolBarManager::impl_elementChanged(bool _bRemove,const ::com::sun::star::ui::ConfigurationEvent& Event )
748 {
749     ResetableGuard aGuard( m_aLock );
750 
751 	/* SAFE AREA ----------------------------------------------------------------------------------------------- */
752     if ( m_bDisposed )
753         return;
754 
755     Reference< XNameAccess > xNameAccess;
756     sal_Int16                nImageType = sal_Int16();
757     sal_Int16                nCurrentImageType = getImageTypeFromBools(
758                                                     SvtMiscOptions().AreCurrentSymbolsLarge(),
759                                                     m_bIsHiContrast );
760 
761     if (( Event.aInfo >>= nImageType ) &&
762         ( nImageType == nCurrentImageType ) &&
763         ( Event.Element >>= xNameAccess ))
764     {
765         sal_Int16 nImageInfo( 1 );
766         Reference< XInterface > xIfacDocImgMgr( m_xDocImageManager, UNO_QUERY );
767         if ( xIfacDocImgMgr == Event.Source )
768             nImageInfo = 0;
769 
770         Sequence< rtl::OUString > aSeq = xNameAccess->getElementNames();
771         for ( sal_Int32 i = 0; i < aSeq.getLength(); i++ )
772         {
773             CommandToInfoMap::iterator pIter = m_aCommandMap.find( aSeq[i] );
774             if ( pIter != m_aCommandMap.end() && ( pIter->second.nImageInfo >= nImageInfo ))
775             {
776                 if ( _bRemove )
777                 {
778                     Image aImage;
779                     if (( pIter->second.nImageInfo == 0 ) && ( pIter->second.nImageInfo == nImageInfo ))
780                     {
781                         // Special case: An image from the document image manager has been removed.
782                         // It is possible that we have a image at our module image manager. Before
783                         // we can remove our image we have to ask our module image manager.
784                         Sequence< rtl::OUString > aCmdURLSeq( 1 );
785                         Sequence< Reference< XGraphic > > aGraphicSeq;
786                         aCmdURLSeq[0] = pIter->first;
787                         aGraphicSeq = m_xModuleImageManager->getImages( nImageType, aCmdURLSeq );
788                         aImage = Image( aGraphicSeq[0] );
789                     }
790 
791                     setToolBarImage(aImage,pIter);
792                 } // if ( _bRemove )
793                 else
794                 {
795                     Reference< XGraphic > xGraphic;
796                     if ( xNameAccess->getByName( aSeq[i] ) >>= xGraphic )
797                     {
798                         Image aImage( xGraphic );
799                         setToolBarImage(aImage,pIter);
800                     }
801                     pIter->second.nImageInfo = nImageInfo;
802                 }
803             }
804         }
805     }
806 }
807 void ToolBarManager::setToolBarImage(const Image& _aImage,const CommandToInfoMap::const_iterator& _pIter)
808 {
809     const ::std::vector< sal_uInt16 >& _rIDs = _pIter->second.aIds;
810     m_pToolBar->SetItemImage( _pIter->second.nId, _aImage );
811     ::std::for_each(_rIDs.begin(),_rIDs.end(),::boost::bind(&ToolBar::SetItemImage,m_pToolBar,_1,_aImage));
812 }
813 
814 void SAL_CALL ToolBarManager::elementReplaced( const ::com::sun::star::ui::ConfigurationEvent& Event ) throw (::com::sun::star::uno::RuntimeException)
815 {
816     impl_elementChanged(false,Event);
817 }
818 
819 void ToolBarManager::RemoveControllers()
820 {
821     ResetableGuard aGuard( m_aLock );
822 
823     if ( m_bDisposed )
824         return;
825 
826     m_aSubToolBarControllerMap.clear();
827 
828 
829     // i90033
830     // Remove item window pointers from the toolbar. They were
831     // destroyed by the dispose() at the XComponent. This is needed
832     // as VCL code later tries to access the item window data in certain
833     // dtors where the item window is already invalid!
834     for ( sal_uInt16 i = 0; i < m_pToolBar->GetItemCount(); i++ )
835     {
836         sal_uInt16 nItemId = m_pToolBar->GetItemId( i );
837         if ( nItemId > 0 )
838         {
839             Reference< XComponent > xComponent( m_aControllerMap[ nItemId ], UNO_QUERY );
840             if ( xComponent.is() )
841             {
842                 try
843                 {
844                     xComponent->dispose();
845                 }
846                 catch ( Exception& )
847                 {
848                 }
849             }
850             m_pToolBar->SetItemWindow(nItemId, 0);
851         }
852     }
853     m_aControllerMap.clear();
854 }
855 
856 uno::Sequence< beans::PropertyValue > ToolBarManager::GetPropsForCommand( const ::rtl::OUString& rCmdURL )
857 {
858     Sequence< PropertyValue > aPropSeq;
859 
860     // Retrieve properties for command
861     try
862     {
863         if ( !m_bModuleIdentified )
864         {
865             Reference< XModuleManager > xModuleManager( m_xServiceManager->createInstance( SERVICENAME_MODULEMANAGER ), UNO_QUERY_THROW );
866             Reference< XInterface > xIfac( m_xFrame, UNO_QUERY );
867 
868             m_bModuleIdentified = sal_True;
869             m_aModuleIdentifier = xModuleManager->identify( xIfac );
870 
871             if ( m_aModuleIdentifier.getLength() > 0 )
872             {
873                 Reference< XNameAccess > xNameAccess( m_xServiceManager->createInstance( SERVICENAME_UICOMMANDDESCRIPTION ), UNO_QUERY );
874                 if ( xNameAccess.is() )
875                     xNameAccess->getByName( m_aModuleIdentifier ) >>= m_xUICommandLabels;
876             }
877         }
878 
879         if ( m_xUICommandLabels.is() )
880         {
881             if ( rCmdURL.getLength() > 0 )
882                 m_xUICommandLabels->getByName( rCmdURL ) >>= aPropSeq;
883         }
884     }
885     catch ( Exception& )
886     {
887     }
888 
889     return aPropSeq;
890 }
891 
892 ::rtl::OUString ToolBarManager::RetrieveLabelFromCommand( const ::rtl::OUString& aCmdURL )
893 {
894     ::rtl::OUString aLabel;
895     Sequence< PropertyValue > aPropSeq;
896 
897     // Retrieve popup menu labels
898     aPropSeq = GetPropsForCommand( aCmdURL );
899     for ( sal_Int32 i = 0; i < aPropSeq.getLength(); i++ )
900     {
901         if ( aPropSeq[i].Name.equalsAscii( "Name" ))
902         {
903             aPropSeq[i].Value >>= aLabel;
904             break;
905         }
906     }
907     return aLabel;
908 }
909 
910 sal_Int32 ToolBarManager::RetrievePropertiesFromCommand( const ::rtl::OUString& aCmdURL )
911 {
912     sal_Int32 nProperties(0);
913     Sequence< PropertyValue > aPropSeq;
914 
915     // Retrieve popup menu labels
916     aPropSeq = GetPropsForCommand( aCmdURL );
917     for ( sal_Int32 i = 0; i < aPropSeq.getLength(); i++ )
918     {
919         if ( aPropSeq[i].Name.equalsAscii( "Properties" ))
920         {
921             aPropSeq[i].Value >>= nProperties;
922             break;
923         }
924     }
925     return nProperties;
926 }
927 
928 void ToolBarManager::CreateControllers()
929 {
930     RTL_LOGFILE_CONTEXT( aLog, "framework (cd100003) ::ToolBarManager::CreateControllers" );
931 
932     Reference< XMultiComponentFactory > xToolbarControllerFactory( m_xToolbarControllerRegistration, UNO_QUERY );
933     Reference< XComponentContext > xComponentContext;
934     Reference< XPropertySet > xProps( m_xServiceManager, UNO_QUERY );
935     Reference< XWindow > xToolbarWindow = VCLUnoHelper::GetInterface( m_pToolBar );
936 
937     css::util::URL	    aURL;
938     sal_Bool            bHasDisabledEntries = SvtCommandOptions().HasEntries( SvtCommandOptions::CMDOPTION_DISABLED );
939     SvtCommandOptions   aCmdOptions;
940 
941     if ( xProps.is() )
942         xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))) >>= xComponentContext;
943 
944     for ( sal_uInt16 i = 0; i < m_pToolBar->GetItemCount(); i++ )
945     {
946         sal_uInt16 nId = m_pToolBar->GetItemId( i );
947         if ( nId == 0 )
948             continue;
949 
950         rtl::OUString                aLoadURL( RTL_CONSTASCII_USTRINGPARAM( ".uno:OpenUrl" ));
951         rtl::OUString                aCommandURL( m_pToolBar->GetItemCommand( nId ));
952         sal_Bool                     bInit( sal_True );
953         sal_Bool                     bCreate( sal_True );
954         Reference< XStatusListener > xController;
955         CommandToInfoMap::iterator pCommandIter = m_aCommandMap.find( aCommandURL );
956         sal_Int16 nWidth = ( pCommandIter != m_aCommandMap.end() ? pCommandIter->second.nWidth : 0 );
957 
958         svt::ToolboxController* pController( 0 );
959 
960         if ( bHasDisabledEntries )
961         {
962             aURL.Complete = aCommandURL;
963             m_xURLTransformer->parseStrict( aURL );
964             if ( aCmdOptions.Lookup( SvtCommandOptions::CMDOPTION_DISABLED, aURL.Path ))
965             {
966                 m_aControllerMap[ nId ] = xController;
967                 m_pToolBar->HideItem( nId );
968                 continue;
969             }
970         }
971 
972         if ( m_xToolbarControllerRegistration.is() &&
973              m_xToolbarControllerRegistration->hasController( aCommandURL, m_aModuleIdentifier ))
974         {
975             if ( xToolbarControllerFactory.is() )
976             {
977                 PropertyValue aPropValue;
978                 std::vector< Any > aPropertyVector;
979 
980                 aPropValue.Name     = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ModuleName" ));
981                 aPropValue.Value    <<= m_aModuleIdentifier;
982                 aPropertyVector.push_back( makeAny( aPropValue ));
983                 aPropValue.Name     = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Frame" ));
984                 aPropValue.Value    <<= m_xFrame;
985                 aPropertyVector.push_back( makeAny( aPropValue ));
986                 aPropValue.Name     = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ServiceManager" ));
987                 aPropValue.Value    <<= m_xServiceManager;
988                 aPropertyVector.push_back( makeAny( aPropValue ));
989                 aPropValue.Name     = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ParentWindow" ));
990                 aPropValue.Value    <<= xToolbarWindow;
991                 aPropertyVector.push_back( makeAny( aPropValue ));
992 
993                 if ( nWidth > 0 )
994                 {
995                     aPropValue.Name     = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Width" ));
996                     aPropValue.Value    <<= nWidth;
997                     aPropertyVector.push_back( makeAny( aPropValue ));
998                 }
999 
1000                 Sequence< Any > aArgs( comphelper::containerToSequence( aPropertyVector ));
1001                 xController = Reference< XStatusListener >( xToolbarControllerFactory->createInstanceWithArgumentsAndContext(
1002                                                                 aCommandURL, aArgs, xComponentContext ),
1003                                                             UNO_QUERY );
1004                 bInit = sal_False; // Initialization is done through the factory service
1005             }
1006         }
1007 
1008         if (( aCommandURL == aLoadURL ) && ( !m_pToolBar->IsItemVisible(nId)))
1009             bCreate = sal_False;
1010 
1011         if ( !xController.is() && m_pToolBar && bCreate )
1012         {
1013             pController = CreateToolBoxController( m_xFrame, m_pToolBar, nId, aCommandURL );
1014             if ( !pController )
1015             {
1016                 if ( m_pToolBar->GetItemData( nId ) != 0 )
1017                 {
1018                     // retrieve additional parameters
1019                     ::rtl::OUString aControlType = static_cast< AddonsParams* >( m_pToolBar->GetItemData( nId ))->aControlType;
1020 
1021                     Reference< XStatusListener > xStatusListener(
1022                         ToolBarMerger::CreateController( m_xServiceManager,
1023                                                          m_xFrame,
1024                                                          m_pToolBar,
1025                                                          aCommandURL,
1026                                                          nId,
1027                                                          nWidth,
1028                                                          aControlType ), UNO_QUERY );
1029 
1030                     xController = xStatusListener;
1031                 }
1032                 else
1033                 {
1034                     MenuDescriptionMap::iterator it = m_aMenuMap.find( nId );
1035                     if ( it == m_aMenuMap.end() )
1036                     {
1037                         xController = Reference< XStatusListener >(
1038                             new GenericToolbarController( m_xServiceManager, m_xFrame, m_pToolBar, nId, aCommandURL ));
1039 
1040                         // Accessibility support: Set toggle button role for specific commands
1041                         sal_Int32 nProps = RetrievePropertiesFromCommand( aCommandURL );
1042                         if ( nProps & UICOMMANDDESCRIPTION_PROPERTIES_TOGGLEBUTTON )
1043                             m_pToolBar->SetItemBits( nId, m_pToolBar->GetItemBits( nId ) | TIB_CHECKABLE );
1044                     }
1045                     else
1046                         xController = Reference< XStatusListener >(
1047                             new MenuToolbarController( m_xServiceManager, m_xFrame, m_pToolBar, nId, aCommandURL, m_aModuleIdentifier, m_aMenuMap[ nId ] ));
1048                 }
1049             }
1050             else if ( pController )
1051             {
1052                 xController = Reference< XStatusListener >( static_cast< ::cppu::OWeakObject *>( pController ), UNO_QUERY );
1053             }
1054         }
1055 
1056         // Associate ID and controller to be able to retrieve
1057         // the controller from the ID later.
1058         m_aControllerMap[ nId ] = xController;
1059 
1060         // Fill sub-toolbars into our hash-map
1061         Reference< XSubToolbarController > xSubToolBar( xController, UNO_QUERY );
1062         if ( xSubToolBar.is() && xSubToolBar->opensSubToolbar() )
1063         {
1064             rtl::OUString aSubToolBarName = xSubToolBar->getSubToolbarName();
1065             if ( aSubToolBarName.getLength() != 0 )
1066             {
1067                 SubToolBarToSubToolBarControllerMap::iterator pIter =
1068                     m_aSubToolBarControllerMap.find( aSubToolBarName );
1069                 if ( pIter == m_aSubToolBarControllerMap.end() )
1070                 {
1071                     SubToolBarControllerVector aSubToolBarVector;
1072                     aSubToolBarVector.push_back( xSubToolBar );
1073                     m_aSubToolBarControllerMap.insert(
1074                         SubToolBarToSubToolBarControllerMap::value_type(
1075                             aSubToolBarName, aSubToolBarVector ));
1076                 }
1077                 else
1078                     pIter->second.push_back( xSubToolBar );
1079             }
1080         }
1081 
1082         Reference< XInitialization > xInit( xController, UNO_QUERY );
1083         if ( xInit.is() )
1084         {
1085             if ( bInit )
1086             {
1087                 PropertyValue aPropValue;
1088                 std::vector< Any > aPropertyVector;
1089 
1090                 aPropValue.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Frame" ));
1091                 aPropValue.Value <<= m_xFrame;
1092                 aPropertyVector.push_back( makeAny( aPropValue ));
1093                 aPropValue.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CommandURL" ));
1094                 aPropValue.Value <<= aCommandURL;
1095                 aPropertyVector.push_back( makeAny( aPropValue ));
1096                 aPropValue.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ServiceManager" ));
1097                 aPropValue.Value <<= m_xServiceManager;
1098                 aPropertyVector.push_back( makeAny( aPropValue ));
1099                 aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ParentWindow" ));
1100                 aPropValue.Value <<= xToolbarWindow;
1101                 aPropertyVector.push_back( makeAny( aPropValue ));
1102 				aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ModuleName" ));
1103                 aPropValue.Value <<= m_aModuleIdentifier;
1104                 aPropertyVector.push_back( makeAny( aPropValue ));
1105 
1106                 if ( nWidth > 0 )
1107                 {
1108                     aPropValue.Name     = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Width" ));
1109                     aPropValue.Value    <<= nWidth;
1110                     aPropertyVector.push_back( makeAny( aPropValue ));
1111                 }
1112 
1113                 Sequence< Any > aArgs( comphelper::containerToSequence( aPropertyVector ));
1114                 xInit->initialize( aArgs );
1115 				//for Support Visiblitly by shizhoubo
1116 				if (pController)
1117 				{
1118 				//	rtl::OUString aCommandURL = pController->m_aCommandURL;
1119 					if(aCommandURL == rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:SwitchXFormsDesignMode" )) ||
1120 					   aCommandURL == rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ViewDataSourceBrowser" )) ||
1121 					   aCommandURL == rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ParaLeftToRight" )) ||
1122 					   aCommandURL == rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ParaRightToLeft" ))
1123 					   )
1124 						pController->setFastPropertyValue_NoBroadcast(1,makeAny(sal_True));
1125 				}
1126 
1127 				//end
1128             }
1129 
1130             // Request a item window from the toolbar controller and set it at the VCL toolbar
1131             Reference< XToolbarController > xTbxController( xController, UNO_QUERY );
1132             if ( xTbxController.is() && xToolbarWindow.is() )
1133             {
1134                 Reference< XWindow > xWindow = xTbxController->createItemWindow( xToolbarWindow );
1135                 if ( xWindow.is() )
1136                 {
1137                     Window* pItemWin = VCLUnoHelper::GetWindow( xWindow );
1138                     if ( pItemWin )
1139                     {
1140                         WindowType nType = pItemWin->GetType();
1141                         if ( nType == WINDOW_LISTBOX || nType == WINDOW_MULTILISTBOX || nType == WINDOW_COMBOBOX )
1142                             pItemWin->SetAccessibleName( m_pToolBar->GetItemText( nId ) );
1143 				        m_pToolBar->SetItemWindow( nId, pItemWin );
1144                     }
1145                 }
1146             }
1147         }
1148 		//for update Controller via support visiable state by shizhoubo
1149 		Reference< XPropertySet > xPropSet( xController, UNO_QUERY );
1150 		if ( xPropSet.is() )
1151 		{
1152 			try
1153 			{
1154 				sal_Bool bSupportVisiable = sal_True;
1155 				Any a( xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SupportsVisiable" ))) );
1156 				a >>= bSupportVisiable;
1157 				if ( bSupportVisiable )
1158 				{
1159 					Reference< XToolbarController > xTbxController( xController, UNO_QUERY );
1160 					UpdateController(xTbxController);
1161 				}
1162 			}
1163 			catch ( RuntimeException& )
1164 			{
1165 				throw;
1166 			}
1167 			catch ( Exception& )
1168 			{
1169 			}
1170 		}
1171 		//end
1172 
1173     }
1174 
1175     AddFrameActionListener();
1176     AddImageOrientationListener();
1177 }
1178 
1179 void ToolBarManager::AddFrameActionListener()
1180 {
1181     if ( !m_bFrameActionRegistered && m_xFrame.is() )
1182     {
1183         m_bFrameActionRegistered = sal_True;
1184         m_xFrame->addFrameActionListener( Reference< XFrameActionListener >(
1185                                             static_cast< ::cppu::OWeakObject *>( this ), UNO_QUERY ));
1186     }
1187 }
1188 
1189 void ToolBarManager::AddImageOrientationListener()
1190 {
1191     if ( !m_bImageOrientationRegistered && m_xFrame.is() )
1192     {
1193         m_bImageOrientationRegistered = sal_True;
1194         ImageOrientationListener* pImageOrientation = new ImageOrientationListener(
1195             Reference< XStatusListener >( static_cast< ::cppu::OWeakObject *>( this ), UNO_QUERY ),
1196             m_xServiceManager,
1197             m_xFrame );
1198         m_xImageOrientationListener = Reference< XComponent >( static_cast< ::cppu::OWeakObject *>(
1199                                         pImageOrientation ), UNO_QUERY );
1200         pImageOrientation->addStatusListener(
1201             rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ImageOrientation" )));
1202         pImageOrientation->bindListener();
1203     }
1204 }
1205 
1206 sal_uInt16 ToolBarManager::ConvertStyleToToolboxItemBits( sal_Int32 nStyle )
1207 {
1208     sal_uInt16 nItemBits( 0 );
1209     if ( nStyle & ::com::sun::star::ui::ItemStyle::RADIO_CHECK )
1210         nItemBits |= TIB_RADIOCHECK;
1211     if ( nStyle & ::com::sun::star::ui::ItemStyle::ALIGN_LEFT )
1212         nItemBits |= TIB_LEFT;
1213 	if ( nStyle & ::com::sun::star::ui::ItemStyle::AUTO_SIZE )
1214         nItemBits |= TIB_AUTOSIZE;
1215 	if ( nStyle & ::com::sun::star::ui::ItemStyle::DROP_DOWN )
1216         nItemBits |= TIB_DROPDOWN;
1217 	if ( nStyle & ::com::sun::star::ui::ItemStyle::REPEAT )
1218         nItemBits |= TIB_REPEAT;
1219     if ( nStyle & ::com::sun::star::ui::ItemStyle::DROPDOWN_ONLY )
1220         nItemBits |= TIB_DROPDOWNONLY;
1221     if ( nStyle & ::com::sun::star::ui::ItemStyle::TEXT )
1222         nItemBits |= TIB_TEXT_ONLY;
1223     if ( nStyle & ::com::sun::star::ui::ItemStyle::ICON )
1224         nItemBits |= TIB_ICON_ONLY;
1225 
1226     return nItemBits;
1227 }
1228 
1229 void ToolBarManager::FillToolbar( const Reference< XIndexAccess >& rItemContainer )
1230 {
1231     ::rtl::OString aTbxName = rtl::OUStringToOString( m_aResourceName, RTL_TEXTENCODING_ASCII_US );
1232 
1233     RTL_LOGFILE_CONTEXT( aLog, "framework (cd100003) ::ToolBarManager::FillToolbar" );
1234     RTL_LOGFILE_CONTEXT_TRACE1( aLog, "framework (cd100003) ::ToolBarManager::FillToolbar %s", aTbxName.getStr() );
1235 
1236     ResetableGuard aGuard( m_aLock );
1237 
1238     if ( m_bDisposed )
1239         return;
1240 
1241     sal_uInt16    nId( 1 );
1242     ::rtl::OUString  aHelpIdPrefix( RTL_CONSTASCII_USTRINGPARAM( HELPID_PREFIX ));
1243 
1244     Reference< XModuleManager > xModuleManager( Reference< XModuleManager >(
1245                                                     m_xServiceManager->createInstance( SERVICENAME_MODULEMANAGER ), UNO_QUERY ));
1246     if ( !m_xDocImageManager.is() )
1247     {
1248         Reference< XModel > xModel( GetModelFromFrame() );
1249         if ( xModel.is() )
1250         {
1251             Reference< XUIConfigurationManagerSupplier > xSupplier( xModel, UNO_QUERY );
1252             if ( xSupplier.is() )
1253             {
1254                 m_xDocUICfgMgr.set( xSupplier->getUIConfigurationManager(), UNO_QUERY );
1255                 m_xDocImageManager = Reference< XImageManager >( m_xDocUICfgMgr->getImageManager(), UNO_QUERY );
1256                 m_xDocImageManager->addConfigurationListener(
1257                                         Reference< XUIConfigurationListener >(
1258                                             static_cast< OWeakObject* >( this ), UNO_QUERY ));
1259             }
1260         }
1261     }
1262 
1263     try
1264     {
1265         if ( xModuleManager.is() )
1266             m_aModuleIdentifier = xModuleManager->identify( Reference< XInterface >( m_xFrame, UNO_QUERY ) );
1267     }
1268     catch( Exception& )
1269     {
1270     }
1271 
1272     if ( !m_xModuleImageManager.is() )
1273     {
1274         Reference< XModuleUIConfigurationManagerSupplier > xModuleCfgMgrSupplier( m_xServiceManager->createInstance(
1275                                                                                     SERVICENAME_MODULEUICONFIGURATIONMANAGERSUPPLIER ),
1276                                                                                   UNO_QUERY );
1277         m_xUICfgMgr = xModuleCfgMgrSupplier->getUIConfigurationManager( m_aModuleIdentifier );
1278         m_xModuleImageManager = Reference< XImageManager >( m_xUICfgMgr->getImageManager(), UNO_QUERY );
1279         m_xModuleImageManager->addConfigurationListener( Reference< XUIConfigurationListener >(
1280                                                             static_cast< OWeakObject* >( this ), UNO_QUERY ));
1281     }
1282 
1283     RemoveControllers();
1284 
1285     // reset and fill command map
1286     m_pToolBar->Clear();
1287     m_aControllerMap.clear();
1288     m_aCommandMap.clear();
1289 
1290     m_aMenuMap.clear();
1291 
1292     CommandInfo aCmdInfo;
1293     for ( sal_Int32 n = 0; n < rItemContainer->getCount(); n++ )
1294     {
1295         Sequence< PropertyValue >   aProp;
1296         rtl::OUString               aCommandURL;
1297         rtl::OUString               aLabel;
1298         rtl::OUString               aHelpURL;
1299         rtl::OUString               aTooltip;
1300         sal_uInt16                  nType( ::com::sun::star::ui::ItemType::DEFAULT );
1301         sal_uInt16                  nWidth( 0 );
1302         sal_Bool                    bIsVisible( sal_True );
1303         sal_uInt32                  nStyle( 0 );
1304 
1305         Reference< XIndexAccess >   aMenuDesc;
1306         try
1307         {
1308             if ( rItemContainer->getByIndex( n ) >>= aProp )
1309             {
1310                 for ( int i = 0; i < aProp.getLength(); i++ )
1311                 {
1312                     if ( aProp[i].Name.equalsAsciiL( ITEM_DESCRIPTOR_COMMANDURL, ITEM_DESCRIPTOR_COMMANDURL_LEN ))
1313                     {
1314                         aProp[i].Value >>= aCommandURL;
1315                         if ( aCommandURL.compareToAscii(MENUPREFIX, RTL_CONSTASCII_LENGTH(MENUPREFIX) ) == 0  )
1316                         {
1317                             try
1318                             {
1319                                 Reference< XIndexAccess > xMenuContainer;
1320                                 if ( m_xDocUICfgMgr.is() )
1321                                     xMenuContainer  = m_xDocUICfgMgr->getSettings( aCommandURL, sal_False );
1322                                 if ( !xMenuContainer.is() && m_xUICfgMgr.is() )
1323                                     xMenuContainer = m_xUICfgMgr->getSettings( aCommandURL, sal_False );
1324                                 if ( xMenuContainer.is() && xMenuContainer->getCount() )
1325                                 {
1326                                     Sequence< PropertyValue > aProps;
1327                                     // drop down menu info is currently
1328                                     // the first ( and only ) menu
1329                                     // in the menusettings container
1330                                     xMenuContainer->getByIndex(0) >>= aProps;
1331                                     for ( sal_Int32 index=0; index<aProps.getLength(); ++index )
1332                                     {
1333                                         if ( aProps[ index ].Name.equalsAsciiL( ITEM_DESCRIPTOR_CONTAINER, ITEM_DESCRIPTOR_CONTAINER_LEN ))
1334 
1335                                         {
1336                                             aProps[ index ].Value >>= aMenuDesc;
1337                                             break;
1338                                         }
1339                                     }
1340                                 }
1341                             }
1342                             catch( Exception& )
1343                             {
1344                             }
1345                         }
1346                     }
1347                     else if (  aProp[i].Name.equalsAsciiL( ITEM_DESCRIPTOR_HELPURL, ITEM_DESCRIPTOR_HELPURL_LEN ))
1348                         aProp[i].Value >>= aHelpURL;
1349                     else if (  aProp[i].Name.equalsAsciiL( ITEM_DESCRIPTOR_TOOLTIP, ITEM_DESCRIPTOR_TOOLTIP_LEN ))
1350                         aProp[i].Value >>= aTooltip;
1351                     else if ( aProp[i].Name.equalsAsciiL( ITEM_DESCRIPTOR_LABEL, ITEM_DESCRIPTOR_LABEL_LEN ))
1352                         aProp[i].Value >>= aLabel;
1353                     else if ( aProp[i].Name.equalsAsciiL( ITEM_DESCRIPTOR_TYPE, ITEM_DESCRIPTOR_TYPE_LEN ))
1354                         aProp[i].Value >>= nType;
1355                     else if ( aProp[i].Name.equalsAsciiL( ITEM_DESCRIPTOR_VISIBLE, ITEM_DESCRIPTOR_VISIBLE_LEN ))
1356                         aProp[i].Value >>= bIsVisible;
1357                     else if ( aProp[i].Name.equalsAsciiL( ITEM_DESCRIPTOR_WIDTH, ITEM_DESCRIPTOR_WIDTH_LEN ))
1358                         aProp[i].Value >>= nWidth;
1359                     else if ( aProp[i].Name.equalsAsciiL( ITEM_DESCRIPTOR_STYLE, ITEM_DESCRIPTOR_STYLE_LEN ))
1360                         aProp[i].Value >>= nStyle;
1361                 }
1362 
1363                 if (( nType == ::com::sun::star::ui::ItemType::DEFAULT ) && ( aCommandURL.getLength() > 0 ))
1364                 {
1365                     ::rtl::OUString aString( RetrieveLabelFromCommand( aCommandURL ));
1366 
1367                     sal_uInt16 nItemBits = ConvertStyleToToolboxItemBits( nStyle );
1368                     if ( aMenuDesc.is() )
1369                         m_aMenuMap[ nId ] = aMenuDesc;
1370                     m_pToolBar->InsertItem( nId, aString, nItemBits );
1371                     m_pToolBar->SetItemCommand( nId, aCommandURL );
1372                     if ( aTooltip.getLength() )
1373 					{
1374                         m_pToolBar->SetQuickHelpText( nId, aTooltip );
1375 					}
1376                     else
1377 					{
1378  						::rtl::OUString sQuickHelp( aString );
1379  						::rtl::OUString sShortCut;
1380  						if( RetrieveShortcut( aCommandURL, sShortCut ) )
1381  						{
1382  							sQuickHelp += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " (" ) );
1383  							sQuickHelp += sShortCut;
1384  							sQuickHelp += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ")" ) );
1385  						}
1386 
1387 	                    m_pToolBar->SetQuickHelpText( nId, sQuickHelp );
1388 					}
1389 
1390                     if ( aLabel.getLength() > 0 )
1391 					{
1392                         m_pToolBar->SetItemText( nId, aLabel );
1393 					}
1394                     else
1395 					{
1396                         m_pToolBar->SetItemText( nId, aString );
1397 					}
1398                     m_pToolBar->EnableItem( nId, sal_True );
1399                     m_pToolBar->SetItemState( nId, STATE_NOCHECK );
1400 
1401                     // Fill command map. It stores all our commands and from what
1402                     // image manager we got our image. So we can decide if we have to use an
1403                     // image from a notification message.
1404                     CommandToInfoMap::iterator pIter = m_aCommandMap.find( aCommandURL );
1405                     if ( pIter == m_aCommandMap.end())
1406                     {
1407                         aCmdInfo.nId = nId;
1408                         aCmdInfo.nWidth = nWidth;
1409                         m_aCommandMap.insert( CommandToInfoMap::value_type( aCommandURL, aCmdInfo ));
1410                     }
1411                     else
1412                     {
1413                         pIter->second.aIds.push_back( nId );
1414                     }
1415 
1416                     if ( !bIsVisible )
1417                         m_pToolBar->HideItem( nId );
1418 
1419                     ++nId;
1420                 }
1421                 else if ( nType == ::com::sun::star::ui::ItemType::SEPARATOR_LINE )
1422                 {
1423                     m_pToolBar->InsertSeparator();
1424                 }
1425                 else if ( nType == ::com::sun::star::ui::ItemType::SEPARATOR_SPACE )
1426                 {
1427                     m_pToolBar->InsertSpace();
1428                 }
1429                 else if ( nType == ::com::sun::star::ui::ItemType::SEPARATOR_LINEBREAK )
1430                 {
1431                     m_pToolBar->InsertBreak();
1432                 }
1433             }
1434         }
1435         catch ( ::com::sun::star::lang::IndexOutOfBoundsException& )
1436         {
1437             break;
1438         }
1439     }
1440 
1441     // Support add-on toolbar merging here. Working directly on the toolbar object is much
1442     // simpler and faster.
1443     const sal_uInt16 TOOLBAR_ITEM_STARTID = 1000;
1444 
1445     MergeToolbarInstructionContainer aMergeInstructionContainer;
1446 
1447     // Retrieve the toolbar name from the resource name
1448     ::rtl::OUString aToolbarName( m_aResourceName );
1449     sal_Int32 nIndex = aToolbarName.lastIndexOf( '/' );
1450     if (( nIndex > 0 ) && ( nIndex < aToolbarName.getLength() ))
1451         aToolbarName = aToolbarName.copy( nIndex+1 );
1452 
1453     AddonsOptions().GetMergeToolbarInstructions( aToolbarName, aMergeInstructionContainer );
1454 
1455     if ( !aMergeInstructionContainer.empty() )
1456     {
1457         sal_uInt16 nItemId( TOOLBAR_ITEM_STARTID );
1458         const sal_uInt32 nCount = aMergeInstructionContainer.size();
1459         for ( sal_uInt32 i=0; i < nCount; i++ )
1460         {
1461             MergeToolbarInstruction& rInstruction = aMergeInstructionContainer[i];
1462             if ( ToolBarMerger::IsCorrectContext( rInstruction.aMergeContext, m_aModuleIdentifier ))
1463             {
1464                 ReferenceToolbarPathInfo aRefPoint = ToolBarMerger::FindReferencePoint( m_pToolBar, rInstruction.aMergePoint );
1465 
1466                 // convert the sequence< sequence< propertyvalue > > structure to
1467                 // something we can better handle. A vector with item data
1468                 AddonToolbarItemContainer aItems;
1469                 ToolBarMerger::ConvertSeqSeqToVector( rInstruction.aMergeToolbarItems, aItems );
1470 
1471                 if ( aRefPoint.bResult )
1472                 {
1473                     ToolBarMerger::ProcessMergeOperation( m_xFrame,
1474                                                           m_pToolBar,
1475                                                           aRefPoint.nPos,
1476                                                           nItemId,
1477                                                           m_aCommandMap,
1478                                                           m_aModuleIdentifier,
1479                                                           rInstruction.aMergeCommand,
1480                                                           rInstruction.aMergeCommandParameter,
1481                                                           aItems );
1482                 }
1483                 else
1484                 {
1485                     ToolBarMerger::ProcessMergeFallback( m_xFrame,
1486                                                          m_pToolBar,
1487                                                          aRefPoint.nPos,
1488                                                          nItemId,
1489                                                          m_aCommandMap,
1490                                                          m_aModuleIdentifier,
1491                                                          rInstruction.aMergeCommand,
1492                                                          rInstruction.aMergeFallback,
1493                                                          aItems );
1494                 }
1495             }
1496         }
1497     }
1498 
1499     // Request images for all toolbar items. Must be done before CreateControllers as
1500     // some controllers need access to the image.
1501     RequestImages();
1502 
1503     // Create controllers after we set the images. There are controllers which needs
1504     // an image at the toolbar at creation time!
1505     CreateControllers();
1506 
1507     // Notify controllers that they are now correctly initialized and can start listening
1508     // toolbars that will open in popup mode will be updated immediately to avoid flickering
1509     if( m_pToolBar->WillUsePopupMode() )
1510         UpdateControllers();
1511     else if ( m_pToolBar->IsReallyVisible() )
1512         m_aAsyncUpdateControllersTimer.Start();
1513 
1514     // Try to retrieve UIName from the container property set and set it as the title
1515     // if it is not empty.
1516     Reference< XPropertySet > xPropSet( rItemContainer, UNO_QUERY );
1517     if ( xPropSet.is() )
1518     {
1519         try
1520         {
1521             rtl::OUString aUIName;
1522             xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UIName" ))) >>= aUIName;
1523             if ( aUIName.getLength() > 0 )
1524                 m_pToolBar->SetText( aUIName );
1525         }
1526         catch ( Exception& )
1527         {
1528         }
1529     }
1530 }
1531 
1532 void ToolBarManager::RequestImages()
1533 {
1534     RTL_LOGFILE_CONTEXT( aLog, "framework (cd100003) ::ToolBarManager::RequestImages" );
1535 
1536     // Request images from image manager
1537     Sequence< rtl::OUString > aCmdURLSeq( m_aCommandMap.size() );
1538     Sequence< Reference< XGraphic > > aDocGraphicSeq;
1539     Sequence< Reference< XGraphic > > aModGraphicSeq;
1540 
1541     sal_uInt32 i = 0;
1542     CommandToInfoMap::iterator pIter = m_aCommandMap.begin();
1543     CommandToInfoMap::iterator pEnd = m_aCommandMap.end();
1544     while ( pIter != pEnd )
1545     {
1546         aCmdURLSeq[i++] = pIter->first;
1547         ++pIter;
1548     }
1549 
1550 	sal_Bool  bBigImages( SvtMiscOptions().AreCurrentSymbolsLarge() );
1551     m_bIsHiContrast = m_pToolBar->GetSettings().GetStyleSettings().GetHighContrastMode();
1552     sal_Int16 p = getImageTypeFromBools( SvtMiscOptions().AreCurrentSymbolsLarge(), m_bIsHiContrast );
1553 
1554     if ( m_xDocImageManager.is() )
1555         aDocGraphicSeq = m_xDocImageManager->getImages( p, aCmdURLSeq );
1556     aModGraphicSeq = m_xModuleImageManager->getImages( p, aCmdURLSeq );
1557 
1558     i = 0;
1559     pIter = m_aCommandMap.begin();
1560     while ( pIter != pEnd )
1561     {
1562         rtl::OUString aCommandURL = aCmdURLSeq[i];
1563 
1564         Image aImage;
1565         if ( aDocGraphicSeq.getLength() > 0 )
1566             aImage = Image( aDocGraphicSeq[i] );
1567         if ( !aImage )
1568         {
1569             aImage = Image( aModGraphicSeq[i] );
1570 			// Try also to query for add-on images before giving up and use an
1571             // empty image.
1572             if ( !aImage )
1573 				aImage = QueryAddonsImage( aCmdURLSeq[i], bBigImages, m_bIsHiContrast );
1574 
1575             pIter->second.nImageInfo = 1; // mark image as module based
1576         }
1577         else
1578         {
1579             pIter->second.nImageInfo = 0; // mark image as document based
1580         }
1581         setToolBarImage(aImage,pIter);
1582         ++pIter;
1583         ++i;
1584     }
1585 }
1586 
1587 void ToolBarManager::notifyRegisteredControllers( const rtl::OUString& aUIElementName, const rtl::OUString& aCommand )
1588 {
1589     ResetableGuard aGuard( m_aLock );
1590     if ( !m_aSubToolBarControllerMap.empty() )
1591     {
1592         SubToolBarToSubToolBarControllerMap::const_iterator pIter =
1593             m_aSubToolBarControllerMap.find( aUIElementName );
1594 
1595         if ( pIter != m_aSubToolBarControllerMap.end() )
1596         {
1597             const SubToolBarControllerVector& rSubToolBarVector = pIter->second;
1598             if ( !rSubToolBarVector.empty() )
1599             {
1600                 SubToolBarControllerVector aNotifyVector = rSubToolBarVector;
1601                 aGuard.unlock();
1602 
1603                 const sal_uInt32 nCount = aNotifyVector.size();
1604                 for ( sal_uInt32 i=0; i < nCount; i++ )
1605                 {
1606                     try
1607                     {
1608                         Reference< XSubToolbarController > xController = aNotifyVector[i];
1609                         if ( xController.is() )
1610                             xController->functionSelected( aCommand );
1611                     }
1612                     catch ( RuntimeException& e )
1613                     {
1614                         throw e;
1615                     }
1616                     catch ( Exception& )
1617                     {
1618                     }
1619                 }
1620             }
1621         }
1622     }
1623 }
1624 long ToolBarManager::HandleClick(void ( SAL_CALL XToolbarController::*_pClick )())
1625 {
1626     ResetableGuard aGuard( m_aLock );
1627 
1628     if ( m_bDisposed )
1629         return 1;
1630 
1631     sal_uInt16 nId( m_pToolBar->GetCurItemId() );
1632     ToolBarControllerMap::const_iterator pIter = m_aControllerMap.find( nId );
1633     if ( pIter != m_aControllerMap.end() )
1634     {
1635         Reference< XToolbarController > xController( pIter->second, UNO_QUERY );
1636 
1637         if ( xController.is() )
1638             (xController.get()->*_pClick)( );
1639     } // if ( pIter != m_aControllerMap.end() )
1640     return 1;
1641 }
1642 
1643 IMPL_LINK( ToolBarManager, Click, ToolBox*, EMPTYARG )
1644 {
1645     return HandleClick(&XToolbarController::click);
1646 }
1647 
1648 IMPL_LINK( ToolBarManager, DropdownClick, ToolBox*, EMPTYARG )
1649 {
1650     ResetableGuard aGuard( m_aLock );
1651 
1652     if ( m_bDisposed )
1653         return 1;
1654 
1655     sal_uInt16 nId( m_pToolBar->GetCurItemId() );
1656     ToolBarControllerMap::const_iterator pIter = m_aControllerMap.find( nId );
1657     if ( pIter != m_aControllerMap.end() )
1658     {
1659         Reference< XToolbarController > xController( pIter->second, UNO_QUERY );
1660 
1661         if ( xController.is() )
1662         {
1663             Reference< XWindow > xWin = xController->createPopupWindow();
1664             if ( xWin.is() )
1665                 xWin->setFocus();
1666         }
1667     }
1668     return 1;
1669 }
1670 
1671 IMPL_LINK( ToolBarManager, DoubleClick, ToolBox*, EMPTYARG )
1672 {
1673     return HandleClick(&XToolbarController::doubleClick);
1674 }
1675 
1676 void ToolBarManager::ImplClearPopupMenu( ToolBox *pToolBar )
1677 {
1678     if ( m_bDisposed )
1679         return;
1680 
1681     PopupMenu *pMenu = pToolBar->GetMenu();
1682 
1683     // remove config entries from menu, so we have a clean menu to start with
1684     // remove submenu first
1685     PopupMenu*  pItemMenu = pMenu->GetPopupMenu( 1 );
1686     if( pItemMenu )
1687     {
1688         pItemMenu->Clear();
1689         delete pItemMenu;
1690         pItemMenu = NULL;
1691         pMenu->SetPopupMenu( 1, pItemMenu );
1692     }
1693 
1694     // remove all items that were not added by the toolbar itself
1695     sal_uInt16 i;
1696     for( i=0; i<pMenu->GetItemCount(); )
1697     {
1698         if( pMenu->GetItemId( i ) < TOOLBOX_MENUITEM_START )
1699             pMenu->RemoveItem( i );
1700         else
1701             i++;
1702     }
1703 }
1704 
1705 IMPL_LINK( ToolBarManager, MenuDeactivate, Menu*, pMenu )
1706 {
1707     ResetableGuard aGuard( m_aLock );
1708 
1709     if ( m_bDisposed )
1710         return 1;
1711 
1712     if( pMenu != m_pToolBar->GetMenu() )
1713         return 1;
1714 
1715     ImplClearPopupMenu( m_pToolBar );
1716 
1717     return 0;
1718 }
1719 
1720 Reference< XModel > ToolBarManager::GetModelFromFrame() const
1721 {
1722     Reference< XController > xController = m_xFrame->getController();
1723     Reference< XModel > xModel;
1724     if ( xController.is() )
1725         xModel = xController->getModel();
1726 
1727     return xModel;
1728 }
1729 
1730 sal_Bool ToolBarManager::IsPluginMode() const
1731 {
1732     sal_Bool bPluginMode( sal_False );
1733 
1734     if ( m_xFrame.is() )
1735     {
1736         Reference< XModel > xModel = GetModelFromFrame();
1737         if ( xModel.is() )
1738         {
1739             Sequence< PropertyValue > aSeq = xModel->getArgs();
1740             comphelper::MediaDescriptor aMediaDescriptor( aSeq );
1741             bPluginMode = aMediaDescriptor.getUnpackedValueOrDefault< sal_Bool >(
1742                             comphelper::MediaDescriptor::PROP_VIEWONLY(), sal_False );
1743         }
1744     }
1745 
1746     return bPluginMode;
1747 }
1748 
1749 bool ToolBarManager::MenuItemAllowed( sal_uInt16 ) const
1750 {
1751     return true;
1752 }
1753 
1754 //added for i33668 by shizhoubo : 200804
1755 PopupMenu * ToolBarManager::GetToolBarCustomMeun(ToolBox* pToolBar)
1756 {
1757 	PopupMenu *pMenu = pToolBar->GetMenu();
1758 	// remove all entries before inserting new ones
1759 	ImplClearPopupMenu( pToolBar );
1760 	// No config menu entries if command ".uno:ConfigureDialog" is not enabled
1761 	Reference< XDispatch > xDisp;
1762 	com::sun::star::util::URL aURL;
1763 	if ( m_xFrame.is() )
1764 	{
1765 		Reference< XDispatchProvider > xProv( m_xFrame, UNO_QUERY );
1766         aURL.Complete = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ConfigureDialog" ));
1767 		m_xURLTransformer->parseStrict( aURL );
1768 		if ( xProv.is() )
1769 			xDisp = xProv->queryDispatch( aURL, ::rtl::OUString(), 0 );
1770 
1771         if ( !xDisp.is() || IsPluginMode() )
1772             return 0;
1773     }
1774 
1775 	// popup menu for quick customization
1776     sal_Bool bHideDisabledEntries = !SvtMenuOptions().IsEntryHidingEnabled();
1777     PopupMenu aPopupMenu( FwkResId( POPUPMENU_TOOLBAR_QUICKCUSTOMIZATION ));
1778 
1779 	if ( m_pToolBar->IsCustomize() )
1780 	{
1781         sal_uInt16      nPos( 0 );
1782         PopupMenu*  pItemMenu( aPopupMenu.GetPopupMenu( 1 ));
1783 
1784 		sal_Bool    bIsFloating( sal_False );
1785 
1786         DockingManager* pDockMgr = Window::GetDockingManager();
1787         if ( pDockMgr )
1788             bIsFloating = pDockMgr->IsFloating( m_pToolBar );
1789 
1790         if ( !bIsFloating )
1791         {
1792             aPopupMenu.EnableItem( MENUITEM_TOOLBAR_DOCKTOOLBAR, sal_False );
1793             aPopupMenu.EnableItem( MENUITEM_TOOLBAR_DOCKALLTOOLBAR, sal_False );
1794             Reference< XDockableWindow > xDockable( VCLUnoHelper::GetInterface( m_pToolBar ), UNO_QUERY );
1795             if( xDockable.is() )
1796                 aPopupMenu.CheckItem( MENUITEM_TOOLBAR_LOCKTOOLBARPOSITION, xDockable->isLocked() );
1797         }
1798         else
1799             aPopupMenu.EnableItem( MENUITEM_TOOLBAR_LOCKTOOLBARPOSITION, sal_False );
1800 
1801         if ( !m_bCanBeCustomized )
1802         {
1803             // Non-configurable toolbars should disable configuration menu items
1804             aPopupMenu.EnableItem( MENUITEM_TOOLBAR_VISIBLEBUTTON, sal_False );
1805             aPopupMenu.EnableItem( MENUITEM_TOOLBAR_CUSTOMIZETOOLBAR, sal_False );
1806         }
1807 
1808         // Disable menu item CLOSE if the toolbar has no closer
1809 		//added for issue64028  by shizhoubo
1810         if( !(pToolBar->GetFloatStyle() & WB_CLOSEABLE) )
1811 			aPopupMenu.EnableItem(MENUITEM_TOOLBAR_CLOSE, sal_False);
1812 		//end
1813 
1814 		pItemMenu->SetMenuFlags (pItemMenu->GetMenuFlags () |
1815 								 MENU_FLAG_SHOWCHECKIMAGES);
1816 
1817         for ( nPos = 0; nPos < m_pToolBar->GetItemCount(); ++nPos )
1818 	    {
1819 		    if ( m_pToolBar->GetItemType(nPos) == TOOLBOXITEM_BUTTON )
1820 		    {
1821 			    sal_uInt16 nId = m_pToolBar->GetItemId(nPos);
1822                 ::rtl::OUString aCommandURL = m_pToolBar->GetItemCommand( nId );
1823 				pItemMenu->InsertItem( STARTID_CUSTOMIZE_POPUPMENU+nPos, m_pToolBar->GetItemText( nId ), MIB_CHECKABLE );
1824 				pItemMenu->CheckItem( STARTID_CUSTOMIZE_POPUPMENU+nPos, m_pToolBar->IsItemVisible( nId ) );
1825                 pItemMenu->SetItemCommand( STARTID_CUSTOMIZE_POPUPMENU+nPos, aCommandURL );
1826 				pItemMenu->SetItemImage( STARTID_CUSTOMIZE_POPUPMENU+nPos,
1827                                          GetImageFromURL( m_xFrame,
1828                                                           aCommandURL,
1829                                                           sal_False,
1830                                                           m_bIsHiContrast ));
1831 		    }
1832 		    else
1833 		    {
1834 			    pItemMenu->InsertSeparator();
1835 		    }
1836         }
1837     }
1838 	else
1839 	{
1840 		sal_uInt16 nPos = aPopupMenu.GetItemPos( MENUITEM_TOOLBAR_CUSTOMIZETOOLBAR );
1841         if ( nPos != MENU_ITEM_NOTFOUND )
1842             aPopupMenu.RemoveItem( nPos );
1843 	}
1844 
1845     // copy all menu items to the toolbar menu
1846     if( pMenu->GetItemCount() )
1847         pMenu->InsertSeparator();
1848 
1849     sal_uInt16 i;
1850     for( i=0; i< aPopupMenu.GetItemCount(); i++)
1851     {
1852         sal_uInt16 nId = aPopupMenu.GetItemId( i );
1853         if ( MenuItemAllowed( nId ))
1854             pMenu->CopyItem( aPopupMenu, i, MENU_APPEND );
1855     }
1856 
1857     // set submenu to toolbar menu
1858     if( aPopupMenu.GetPopupMenu( 1 ) )
1859     {
1860         // create an own submenu to avoid auto-delete when resource menu is deleted
1861         PopupMenu *pItemMenu = new PopupMenu();
1862 
1863 		pItemMenu->SetMenuFlags (pItemMenu->GetMenuFlags () |
1864 								 MENU_FLAG_SHOWCHECKIMAGES);
1865 
1866         for( i=0; i< aPopupMenu.GetPopupMenu( 1 )->GetItemCount(); i++)
1867             pItemMenu->CopyItem( *aPopupMenu.GetPopupMenu( 1 ), i, MENU_APPEND );
1868 
1869         pMenu->SetPopupMenu( 1, pItemMenu );
1870     }
1871 
1872     if ( bHideDisabledEntries )
1873         pMenu->RemoveDisabledEntries();
1874 
1875     return pMenu;
1876 }
1877 
1878 // addd for 33668  by shizhoubo
1879 IMPL_LINK( ToolBarManager, Command, CommandEvent*, pCmdEvt )
1880 {
1881 	ResetableGuard aGuard( m_aLock );
1882 
1883 	if ( m_bDisposed )
1884 		return 1;
1885 	if ( pCmdEvt->GetCommand() != COMMAND_CONTEXTMENU )
1886 		return 0;
1887 
1888 	PopupMenu * pMenu = GetToolBarCustomMeun(m_pToolBar);
1889 	if (pMenu)
1890 	{
1891 		// make sure all disabled entries will be shown
1892 		pMenu->SetMenuFlags( pMenu->GetMenuFlags() | MENU_FLAG_ALWAYSSHOWDISABLEDENTRIES );
1893 		::Point aPoint( pCmdEvt->GetMousePosPixel() );
1894 		pMenu->Execute( m_pToolBar, aPoint );
1895 	}
1896 
1897 	return 0;
1898 }
1899 //end
1900 
1901 IMPL_LINK( ToolBarManager, MenuButton, ToolBox*, pToolBar )
1902 {
1903    ResetableGuard aGuard( m_aLock );
1904 
1905     if ( m_bDisposed )
1906         return 1;
1907 	//modify for i33668 by shizhoubo:2008:04
1908 	GetToolBarCustomMeun(pToolBar);
1909 	//end
1910      return 0;
1911  }
1912 
1913 IMPL_LINK( ToolBarManager, MenuSelect, Menu*, pMenu )
1914 {
1915     // We have to hold a reference to ourself as it is possible that we will be disposed and
1916     // our refcount could be zero (destruction) otherwise.
1917     Reference< XInterface > xInterface( static_cast< OWeakObject* >( this ), UNO_QUERY );
1918 
1919     {
1920         // The guard must be in its own context as the we can get destroyed when our
1921         // own xInterface reference get destroyed!
1922         ResetableGuard aGuard( m_aLock );
1923 
1924         if ( m_bDisposed )
1925             return 1;
1926 
1927         switch ( pMenu->GetCurItemId() )
1928         {
1929             case MENUITEM_TOOLBAR_CUSTOMIZETOOLBAR:
1930             {
1931                 Reference< XDispatch > xDisp;
1932                 com::sun::star::util::URL aURL;
1933                 if ( m_xFrame.is() )
1934                 {
1935                     Reference< XDispatchProvider > xProv( m_xFrame, UNO_QUERY );
1936                     aURL.Complete = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ConfigureDialog" ));
1937                     m_xURLTransformer->parseStrict( aURL );
1938                     if ( xProv.is() )
1939                         xDisp = xProv->queryDispatch( aURL, ::rtl::OUString(), 0 );
1940                 }
1941 
1942                 if ( xDisp.is() )
1943 			    {
1944 				    Sequence< PropertyValue > aPropSeq( 1 );
1945 
1946 				    aPropSeq[ 0 ].Name =
1947 					    rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ResourceURL"));
1948 				    aPropSeq[ 0 ].Value <<= m_aResourceName;
1949 
1950                     xDisp->dispatch( aURL, aPropSeq );
1951 			    }
1952                 break;
1953             }
1954 
1955             case MENUITEM_TOOLBAR_DOCKTOOLBAR:
1956             {
1957                 ExecuteInfo* pExecuteInfo = new ExecuteInfo;
1958 
1959                 pExecuteInfo->aToolbarResName = m_aResourceName;
1960                 pExecuteInfo->nCmd            = EXEC_CMD_DOCKTOOLBAR;
1961                 pExecuteInfo->xLayoutManager  = getLayoutManagerFromFrame( m_xFrame );
1962 
1963                 Application::PostUserEvent( STATIC_LINK(0, ToolBarManager, ExecuteHdl_Impl), pExecuteInfo );
1964                 break;
1965             }
1966 
1967             case MENUITEM_TOOLBAR_DOCKALLTOOLBAR:
1968             {
1969                 ExecuteInfo* pExecuteInfo = new ExecuteInfo;
1970 
1971                 pExecuteInfo->aToolbarResName = m_aResourceName;
1972                 pExecuteInfo->nCmd            = EXEC_CMD_DOCKALLTOOLBARS;
1973                 pExecuteInfo->xLayoutManager  = getLayoutManagerFromFrame( m_xFrame );
1974 
1975                 Application::PostUserEvent( STATIC_LINK(0, ToolBarManager, ExecuteHdl_Impl), pExecuteInfo );
1976                 break;
1977             }
1978 
1979             case MENUITEM_TOOLBAR_LOCKTOOLBARPOSITION:
1980             {
1981                 Reference< XLayoutManager > xLayoutManager = getLayoutManagerFromFrame( m_xFrame );
1982                 if ( xLayoutManager.is() )
1983                 {
1984                     Reference< XDockableWindow > xDockable( VCLUnoHelper::GetInterface( m_pToolBar ), UNO_QUERY );
1985 
1986                     if( xDockable->isLocked() )
1987                         xLayoutManager->unlockWindow( m_aResourceName );
1988                     else
1989                         xLayoutManager->lockWindow( m_aResourceName );
1990                 }
1991                 break;
1992             }
1993 
1994             case MENUITEM_TOOLBAR_CLOSE:
1995             {
1996                 ExecuteInfo* pExecuteInfo = new ExecuteInfo;
1997 
1998                 pExecuteInfo->aToolbarResName = m_aResourceName;
1999                 pExecuteInfo->nCmd            = EXEC_CMD_CLOSETOOLBAR;
2000                 pExecuteInfo->xLayoutManager  = getLayoutManagerFromFrame( m_xFrame );
2001                 pExecuteInfo->xWindow         = VCLUnoHelper::GetInterface( m_pToolBar );
2002 
2003                 Application::PostUserEvent( STATIC_LINK(0, ToolBarManager, ExecuteHdl_Impl), pExecuteInfo );
2004             }
2005 
2006             default:
2007             {
2008                 sal_uInt16 nId = pMenu->GetCurItemId();
2009                 if(( nId > 0 ) && ( nId < TOOLBOX_MENUITEM_START ))
2010                 {
2011                     // toggle toolbar button visibility
2012                     rtl::OUString aCommand = pMenu->GetItemCommand( nId );
2013 
2014                     Reference< XLayoutManager > xLayoutManager = getLayoutManagerFromFrame( m_xFrame );
2015                     if ( xLayoutManager.is() )
2016                     {
2017                         Reference< XUIElementSettings > xUIElementSettings( xLayoutManager->getElement( m_aResourceName ), UNO_QUERY );
2018                         if ( xUIElementSettings.is() )
2019                         {
2020                             Reference< XIndexContainer > xItemContainer( xUIElementSettings->getSettings( sal_True ), UNO_QUERY );
2021                             sal_Int32 nCount = xItemContainer->getCount();
2022                             for ( sal_Int32 i = 0; i < nCount; i++ )
2023                             {
2024                                 Sequence< PropertyValue > aProp;
2025                                 sal_Int32                 nVisibleIndex( -1 );
2026                                 rtl::OUString             aCommandURL;
2027                                 sal_Bool                  bVisible( sal_False );
2028 
2029                                 if ( xItemContainer->getByIndex( i ) >>= aProp )
2030                                 {
2031                                     for ( sal_Int32 j = 0; j < aProp.getLength(); j++ )
2032                                     {
2033                                         if ( aProp[j].Name.equalsAscii( ITEM_DESCRIPTOR_COMMANDURL ))
2034                                         {
2035                                             aProp[j].Value >>= aCommandURL;
2036                                         }
2037                                         else if ( aProp[j].Name.equalsAscii( ITEM_DESCRIPTOR_VISIBLE ))
2038                                         {
2039                                             aProp[j].Value >>= bVisible;
2040                                             nVisibleIndex = j;
2041                                         }
2042                                     }
2043 
2044                                     if (( aCommandURL == aCommand ) && ( nVisibleIndex >= 0 ))
2045                                     {
2046                                         // We have found the requested item, toggle the visible flag
2047                                         // and write back the configuration settings to the toolbar
2048                                         aProp[nVisibleIndex].Value = makeAny( !bVisible );
2049                                         try
2050                                         {
2051                                             xItemContainer->replaceByIndex( i, makeAny( aProp ));
2052                                             xUIElementSettings->setSettings( Reference< XIndexAccess >( xItemContainer, UNO_QUERY ));
2053                                             Reference< XPropertySet > xPropSet( xUIElementSettings, UNO_QUERY );
2054                                             if ( xPropSet.is() )
2055                                             {
2056                                                 Reference< XUIConfigurationPersistence > xUICfgMgr;
2057                                                 if (( xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ConfigurationSource" ))) >>= xUICfgMgr ) && ( xUICfgMgr.is() ))
2058                                                     xUICfgMgr->store();
2059                                             }
2060                                         }
2061                                         catch ( Exception& )
2062                                         {
2063                                         }
2064 
2065                                         break;
2066                                     }
2067                                 }
2068                             }
2069                         }
2070                     }
2071                 }
2072                 break;
2073             }
2074         }
2075 
2076         // remove all entries - deactivate is not reliable
2077         // The method checks if we are already disposed and in that case does nothing!
2078         ImplClearPopupMenu( m_pToolBar );
2079     }
2080 
2081     return 1;
2082 }
2083 
2084 IMPL_LINK( ToolBarManager, Select, ToolBox*, EMPTYARG )
2085 {
2086     if ( m_bDisposed )
2087         return 1;
2088 
2089     sal_Int16   nKeyModifier( (sal_Int16)m_pToolBar->GetModifier() );
2090     sal_uInt16      nId( m_pToolBar->GetCurItemId() );
2091 
2092     ToolBarControllerMap::const_iterator pIter = m_aControllerMap.find( nId );
2093     if ( pIter != m_aControllerMap.end() )
2094     {
2095         Reference< XToolbarController > xController( pIter->second, UNO_QUERY );
2096 
2097         if ( xController.is() )
2098             xController->execute( nKeyModifier );
2099     }
2100 
2101     return 1;
2102 }
2103 
2104 IMPL_LINK( ToolBarManager, Highlight, ToolBox*, EMPTYARG )
2105 {
2106     return 1;
2107 }
2108 
2109 IMPL_LINK( ToolBarManager, Activate, ToolBox*, EMPTYARG )
2110 {
2111     return 1;
2112 }
2113 
2114 IMPL_LINK( ToolBarManager, Deactivate, ToolBox*, EMPTYARG )
2115 {
2116     return 1;
2117 }
2118 
2119 IMPL_LINK( ToolBarManager, StateChanged, StateChangedType*, pStateChangedType )
2120 {
2121     if ( m_bDisposed )
2122         return 1;
2123 
2124     if ( *pStateChangedType == STATE_CHANGE_CONTROLBACKGROUND )
2125 	{
2126 		// Check if we need to get new images for normal/high contrast mode
2127 		CheckAndUpdateImages();
2128 	}
2129     else if ( *pStateChangedType == STATE_CHANGE_VISIBLE )
2130     {
2131         if ( m_pToolBar->IsReallyVisible() )
2132             m_aAsyncUpdateControllersTimer.Start();
2133     }
2134     else if ( *pStateChangedType == STATE_CHANGE_INITSHOW )
2135     {
2136         m_aAsyncUpdateControllersTimer.Start();
2137     }
2138     return 1;
2139 }
2140 
2141 IMPL_LINK( ToolBarManager, DataChanged, DataChangedEvent*, pDataChangedEvent  )
2142 {
2143 	if ((( pDataChangedEvent->GetType() == DATACHANGED_SETTINGS	)	||
2144 		(  pDataChangedEvent->GetType() == DATACHANGED_DISPLAY	))	&&
2145         ( pDataChangedEvent->GetFlags() & SETTINGS_STYLE		))
2146 	{
2147 		// Check if we need to get new images for normal/high contrast mode
2148 		CheckAndUpdateImages();
2149 	}
2150 
2151     for ( sal_uInt16 nPos = 0; nPos < m_pToolBar->GetItemCount(); ++nPos )
2152 	{
2153         const sal_uInt16 nId = m_pToolBar->GetItemId(nPos);
2154         Window* pWindow = m_pToolBar->GetItemWindow( nId );
2155         if ( pWindow )
2156         {
2157             const DataChangedEvent& rDCEvt( *pDataChangedEvent );
2158             pWindow->DataChanged( rDCEvt );
2159         }
2160     }
2161 
2162     if ( !m_pToolBar->IsFloatingMode() &&
2163          m_pToolBar->IsVisible() )
2164     {
2165         // Resize toolbar, layout manager is resize listener and will calc
2166         // the layout automatically.
2167         ::Size aSize( m_pToolBar->CalcWindowSizePixel() );
2168         m_pToolBar->SetOutputSizePixel( aSize );
2169     }
2170 
2171     return 1;
2172 }
2173 
2174 IMPL_LINK( ToolBarManager, AsyncUpdateControllersHdl, Timer *, EMPTYARG )
2175 {
2176     // The guard must be in its own context as the we can get destroyed when our
2177     // own xInterface reference get destroyed!
2178     Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY );
2179 
2180     ResetableGuard aGuard( m_aLock );
2181 
2182     if ( m_bDisposed )
2183         return 1;
2184 
2185     // Request to update our controllers
2186     m_aAsyncUpdateControllersTimer.Stop();
2187     UpdateControllers();
2188 
2189     return 0;
2190 }
2191 
2192 IMPL_STATIC_LINK_NOINSTANCE( ToolBarManager, ExecuteHdl_Impl, ExecuteInfo*, pExecuteInfo )
2193 {
2194     try
2195     {
2196         // Asynchronous execution as this can lead to our own destruction!
2197         if (( pExecuteInfo->nCmd == EXEC_CMD_CLOSETOOLBAR ) &&
2198             ( pExecuteInfo->xLayoutManager.is() ) &&
2199             ( pExecuteInfo->xWindow.is() ))
2200         {
2201             // Use docking window close to close the toolbar. The layout manager is
2202             // listener and will react correctly according to the context sensitive
2203             // flag of our toolbar.
2204             Window* pWin = VCLUnoHelper::GetWindow( pExecuteInfo->xWindow );
2205             DockingWindow* pDockWin = dynamic_cast< DockingWindow* >( pWin );
2206             if ( pDockWin )
2207                 pDockWin->Close();
2208         }
2209         else if (( pExecuteInfo->nCmd == EXEC_CMD_DOCKTOOLBAR ) &&
2210                  ( pExecuteInfo->xLayoutManager.is() ))
2211         {
2212             ::com::sun::star::awt::Point aPoint;
2213             aPoint.X = aPoint.Y = SAL_MAX_INT32;
2214             pExecuteInfo->xLayoutManager->dockWindow( pExecuteInfo->aToolbarResName,
2215                                                       DockingArea_DOCKINGAREA_DEFAULT,
2216                                                       aPoint );
2217         }
2218         else if (( pExecuteInfo->nCmd == EXEC_CMD_DOCKALLTOOLBARS ) &&
2219                  ( pExecuteInfo->xLayoutManager.is() ))
2220         {
2221             pExecuteInfo->xLayoutManager->dockAllWindows( UIElementType::TOOLBAR );
2222         }
2223     }
2224     catch ( Exception& )
2225     {
2226     }
2227 
2228     delete pExecuteInfo;
2229     return 0;
2230 }
2231 
2232 Image ToolBarManager::QueryAddonsImage( const ::rtl::OUString& aCommandURL, bool bBigImages, bool bHiContrast )
2233 {
2234     Image aImage = framework::AddonsOptions().GetImageFromURL( aCommandURL, bBigImages, bHiContrast );
2235 	return aImage;
2236 }
2237 
2238 bool ToolBarManager::impl_RetrieveShortcutsFromConfiguration(
2239     const Reference< XAcceleratorConfiguration >& rAccelCfg,
2240     const rtl::OUString& rCommand,
2241 	rtl::OUString& rShortCut )
2242 {
2243     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ToolBarManager::impl_RetrieveShortcutsFromConfiguration" );
2244     if ( rAccelCfg.is() )
2245     {
2246         try
2247         {
2248             com::sun::star::awt::KeyEvent aKeyEvent;
2249 			Sequence< OUString > aCommands(1);
2250 			aCommands[0] = rCommand;
2251 
2252             Sequence< Any > aSeqKeyCode( rAccelCfg->getPreferredKeyEventsForCommandList( aCommands ) );
2253 			if( aSeqKeyCode.getLength() == 1 )
2254 			{
2255 				if ( aSeqKeyCode[0] >>= aKeyEvent )
2256 				{
2257                     rShortCut = svt::AcceleratorExecute::st_AWTKey2VCLKey( aKeyEvent ).GetName();
2258 					return true;
2259 				}
2260 			}
2261         }
2262         catch ( IllegalArgumentException& )
2263         {
2264         }
2265     }
2266 
2267 	return false;
2268 }
2269 
2270 bool ToolBarManager::RetrieveShortcut( const rtl::OUString& rCommandURL, rtl::OUString& rShortCut )
2271 {
2272     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ToolBarManager::RetrieveShortcuts" );
2273     if ( m_bModuleIdentified )
2274     {
2275         Reference< XAcceleratorConfiguration > xDocAccelCfg( m_xDocAcceleratorManager );
2276         Reference< XAcceleratorConfiguration > xModuleAccelCfg( m_xModuleAcceleratorManager );
2277         Reference< XAcceleratorConfiguration > xGlobalAccelCfg( m_xGlobalAcceleratorManager );
2278 
2279         if ( !m_bAcceleratorCfg )
2280         {
2281             // Retrieve references on demand
2282             m_bAcceleratorCfg = sal_True;
2283             if ( !xDocAccelCfg.is() )
2284             {
2285                 Reference< XController > xController = m_xFrame->getController();
2286                 Reference< XModel > xModel;
2287                 if ( xController.is() )
2288                 {
2289                     xModel = xController->getModel();
2290                     if ( xModel.is() )
2291                     {
2292                         Reference< XUIConfigurationManagerSupplier > xSupplier( xModel, UNO_QUERY );
2293                         if ( xSupplier.is() )
2294                         {
2295                             Reference< XUIConfigurationManager > xDocUICfgMgr( xSupplier->getUIConfigurationManager(), UNO_QUERY );
2296                             if ( xDocUICfgMgr.is() )
2297                             {
2298                                 xDocAccelCfg = Reference< XAcceleratorConfiguration >( xDocUICfgMgr->getShortCutManager(), UNO_QUERY );
2299                                 m_xDocAcceleratorManager = xDocAccelCfg;
2300                             }
2301                         }
2302                     }
2303                 }
2304             }
2305 
2306             if ( !xModuleAccelCfg.is() )
2307             {
2308                 Reference< XModuleUIConfigurationManagerSupplier > xModuleCfgMgrSupplier( m_xServiceManager->createInstance(
2309                                                                                             SERVICENAME_MODULEUICONFIGURATIONMANAGERSUPPLIER ),
2310                                                                                         UNO_QUERY );
2311                 try
2312                 {
2313                     Reference< XUIConfigurationManager > xUICfgMgr = xModuleCfgMgrSupplier->getUIConfigurationManager( m_aModuleIdentifier );
2314                     if ( xUICfgMgr.is() )
2315                     {
2316                         xModuleAccelCfg = Reference< XAcceleratorConfiguration >( xUICfgMgr->getShortCutManager(), UNO_QUERY );
2317                         m_xModuleAcceleratorManager = xModuleAccelCfg;
2318                     }
2319                 }
2320                 catch ( RuntimeException& )
2321                 {
2322                     throw;
2323                 }
2324                 catch ( Exception& )
2325                 {
2326                 }
2327             }
2328 
2329             if ( !xGlobalAccelCfg.is() )
2330             {
2331                 xGlobalAccelCfg = Reference< XAcceleratorConfiguration >( m_xServiceManager->createInstance(
2332                                                                             SERVICENAME_GLOBALACCELERATORCONFIGURATION ),
2333                                                                           UNO_QUERY );
2334                 m_xGlobalAcceleratorManager = xGlobalAccelCfg;
2335             }
2336         }
2337 
2338 		bool bFound = false;
2339 
2340         if ( m_xGlobalAcceleratorManager.is() )
2341             bFound  = impl_RetrieveShortcutsFromConfiguration( xGlobalAccelCfg, rCommandURL, rShortCut );
2342         if ( !bFound && m_xModuleAcceleratorManager.is() )
2343             bFound = impl_RetrieveShortcutsFromConfiguration( xModuleAccelCfg, rCommandURL, rShortCut );
2344         if ( !bFound && m_xDocAcceleratorManager.is() )
2345             impl_RetrieveShortcutsFromConfiguration( xGlobalAccelCfg, rCommandURL, rShortCut );
2346 
2347 		if( bFound )
2348 			return true;
2349     }
2350 	return false;
2351 }
2352 
2353 }
2354 
2355 
2356 
2357