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