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