1*6d739b60SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*6d739b60SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*6d739b60SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*6d739b60SAndrew Rist  * distributed with this work for additional information
6*6d739b60SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*6d739b60SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*6d739b60SAndrew Rist  * "License"); you may not use this file except in compliance
9*6d739b60SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*6d739b60SAndrew Rist  *
11*6d739b60SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*6d739b60SAndrew Rist  *
13*6d739b60SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*6d739b60SAndrew Rist  * software distributed under the License is distributed on an
15*6d739b60SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*6d739b60SAndrew Rist  * KIND, either express or implied.  See the License for the
17*6d739b60SAndrew Rist  * specific language governing permissions and limitations
18*6d739b60SAndrew Rist  * under the License.
19*6d739b60SAndrew Rist  *
20*6d739b60SAndrew Rist  *************************************************************/
21*6d739b60SAndrew Rist 
22*6d739b60SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_framework.hxx"
26cdf0e10cSrcweir #include <uielement/addonstoolbarmanager.hxx>
27cdf0e10cSrcweir #include <uielement/toolbarmerger.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir //_________________________________________________________________________________________________________________
30cdf0e10cSrcweir //	my own includes
31cdf0e10cSrcweir //_________________________________________________________________________________________________________________
32cdf0e10cSrcweir 
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #ifndef __FRAMEWORK_UIELEMENT_TOOLBAR_HXX
35cdf0e10cSrcweir #include <uielement/toolbar.hxx>
36cdf0e10cSrcweir #endif
37cdf0e10cSrcweir #ifndef __FRAMEWORK_UIELEMENT_GENERICTOOLBARCONTROLLER_HXX
38cdf0e10cSrcweir #include <uielement/generictoolbarcontroller.hxx>
39cdf0e10cSrcweir #endif
40cdf0e10cSrcweir #include <threadhelp/resetableguard.hxx>
41cdf0e10cSrcweir #include "services.h"
42cdf0e10cSrcweir #include <framework/imageproducer.hxx>
43cdf0e10cSrcweir #include <framework/sfxhelperfunctions.hxx>
44cdf0e10cSrcweir #include <classes/fwkresid.hxx>
45cdf0e10cSrcweir #ifndef __FRAMEWORK_CLASES_RESOURCE_HRC_
46cdf0e10cSrcweir #include <classes/resource.hrc>
47cdf0e10cSrcweir #endif
48cdf0e10cSrcweir #include <framework/addonsoptions.hxx>
49cdf0e10cSrcweir #ifndef __FRAMEWORK_UIELEMENT_COMBOBOXTOOLBARCONTROLLER_HXX
50cdf0e10cSrcweir #include <uielement/comboboxtoolbarcontroller.hxx>
51cdf0e10cSrcweir #endif
52cdf0e10cSrcweir #ifndef __FRAMEWORK_UIELEMENT_IMAGEBUTTONTOOLBARCONTROLLER_HXX
53cdf0e10cSrcweir #include <uielement/imagebuttontoolbarcontroller.hxx>
54cdf0e10cSrcweir #endif
55cdf0e10cSrcweir #ifndef __FRAMEWORK_UIELEMENT_TOGGLEBUTTONTOOLBARCONTROLLER_HXX
56cdf0e10cSrcweir #include <uielement/togglebuttontoolbarcontroller.hxx>
57cdf0e10cSrcweir #endif
58cdf0e10cSrcweir #include <uielement/buttontoolbarcontroller.hxx>
59cdf0e10cSrcweir #include <uielement/spinfieldtoolbarcontroller.hxx>
60cdf0e10cSrcweir #include <uielement/edittoolbarcontroller.hxx>
61cdf0e10cSrcweir #include <uielement/dropdownboxtoolbarcontroller.hxx>
62cdf0e10cSrcweir #include <uielement/toolbarmerger.hxx>
63cdf0e10cSrcweir 
64cdf0e10cSrcweir //_________________________________________________________________________________________________________________
65cdf0e10cSrcweir //	interface includes
66cdf0e10cSrcweir //_________________________________________________________________________________________________________________
67cdf0e10cSrcweir #include <com/sun/star/ui/ItemType.hpp>
68cdf0e10cSrcweir #include <com/sun/star/frame/XToolbarController.hpp>
69cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp>
70cdf0e10cSrcweir #ifndef _COM_SUN_STAR_BEANS_XLAYOUTMANAGER_HPP_
71cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
72cdf0e10cSrcweir #endif
73cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
74cdf0e10cSrcweir #include <com/sun/star/frame/XLayoutManager.hpp>
75cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UI_XDOCKINGAREA_HPP_
76cdf0e10cSrcweir #include <com/sun/star/ui/DockingArea.hpp>
77cdf0e10cSrcweir #endif
78cdf0e10cSrcweir #include <com/sun/star/lang/XMultiComponentFactory.hpp>
79cdf0e10cSrcweir 
80cdf0e10cSrcweir //_________________________________________________________________________________________________________________
81cdf0e10cSrcweir //	other includes
82cdf0e10cSrcweir //_________________________________________________________________________________________________________________
83cdf0e10cSrcweir #include <svtools/imgdef.hxx>
84cdf0e10cSrcweir #include <svtools/toolboxcontroller.hxx>
85cdf0e10cSrcweir #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
86cdf0e10cSrcweir #include <toolkit/unohlp.hxx>
87cdf0e10cSrcweir #endif
88cdf0e10cSrcweir 
89cdf0e10cSrcweir #include <svtools/miscopt.hxx>
90cdf0e10cSrcweir #include <vcl/svapp.hxx>
91cdf0e10cSrcweir #include <vcl/menu.hxx>
92cdf0e10cSrcweir #include <vcl/syswin.hxx>
93cdf0e10cSrcweir #include <vcl/taskpanelist.hxx>
94cdf0e10cSrcweir 
95cdf0e10cSrcweir //_________________________________________________________________________________________________________________
96cdf0e10cSrcweir //	namespaces
97cdf0e10cSrcweir //_________________________________________________________________________________________________________________
98cdf0e10cSrcweir 
99cdf0e10cSrcweir using namespace ::com::sun::star;
100cdf0e10cSrcweir using namespace ::com::sun::star::awt;
101cdf0e10cSrcweir using namespace ::com::sun::star::beans;
102cdf0e10cSrcweir using namespace ::com::sun::star::uno;
103cdf0e10cSrcweir using namespace ::com::sun::star::lang;
104cdf0e10cSrcweir using namespace ::com::sun::star::frame;
105cdf0e10cSrcweir using namespace ::com::sun::star::util;
106cdf0e10cSrcweir using namespace ::com::sun::star::container;
107cdf0e10cSrcweir using namespace ::com::sun::star::frame;
108cdf0e10cSrcweir using namespace ::com::sun::star::ui;
109cdf0e10cSrcweir 
110cdf0e10cSrcweir namespace framework
111cdf0e10cSrcweir {
112cdf0e10cSrcweir 
113cdf0e10cSrcweir static const char   TOOLBOXITEM_SEPARATOR_STR[] = "private:separator";
114cdf0e10cSrcweir static const sal_uInt16 TOOLBOXITEM_SEPARATOR_STR_LEN = sizeof( TOOLBOXITEM_SEPARATOR_STR )-1;
115cdf0e10cSrcweir 
116cdf0e10cSrcweir AddonsToolBarManager::AddonsToolBarManager( const Reference< XMultiServiceFactory >& rServiceManager,
117cdf0e10cSrcweir                                 const Reference< XFrame >& rFrame,
118cdf0e10cSrcweir                                 const rtl::OUString& rResourceName,
119cdf0e10cSrcweir                                 ToolBar* pToolBar ) :
120cdf0e10cSrcweir     ToolBarManager( rServiceManager, rFrame, rResourceName, pToolBar )
121cdf0e10cSrcweir {
122cdf0e10cSrcweir     // Configuration data is retrieved from non-writable configuration layer. Therefor we
123cdf0e10cSrcweir     // must disable some menu entries.
124cdf0e10cSrcweir     m_bCanBeCustomized = sal_False;
125cdf0e10cSrcweir 
126cdf0e10cSrcweir     m_pToolBar->SetMenuType( TOOLBOX_MENUTYPE_CLIPPEDITEMS );
127cdf0e10cSrcweir     m_pToolBar->SetSelectHdl( LINK( this, AddonsToolBarManager, Select) );
128cdf0e10cSrcweir 	m_pToolBar->SetActivateHdl( LINK( this, AddonsToolBarManager, Activate) );
129cdf0e10cSrcweir 	m_pToolBar->SetDeactivateHdl( LINK( this, AddonsToolBarManager, Deactivate) );
130cdf0e10cSrcweir     m_pToolBar->SetClickHdl( LINK( this, AddonsToolBarManager, Click ) );
131cdf0e10cSrcweir     m_pToolBar->SetDoubleClickHdl( LINK( this, AddonsToolBarManager, DoubleClick ) );
132cdf0e10cSrcweir     m_pToolBar->SetCommandHdl( LINK( this, AddonsToolBarManager, Command ) );
133cdf0e10cSrcweir     m_pToolBar->SetStateChangedHdl( LINK( this, AddonsToolBarManager, StateChanged ) );
134cdf0e10cSrcweir     m_pToolBar->SetDataChangedHdl( LINK( this, AddonsToolBarManager, DataChanged ) );
135cdf0e10cSrcweir }
136cdf0e10cSrcweir 
137cdf0e10cSrcweir AddonsToolBarManager::~AddonsToolBarManager()
138cdf0e10cSrcweir {
139cdf0e10cSrcweir }
140cdf0e10cSrcweir 
141cdf0e10cSrcweir static sal_Bool IsCorrectContext( const ::rtl::OUString& rModuleIdentifier, const ::rtl::OUString& aContextList )
142cdf0e10cSrcweir {
143cdf0e10cSrcweir     if ( aContextList.getLength() == 0 )
144cdf0e10cSrcweir         return sal_True;
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     if ( rModuleIdentifier.getLength() > 0 )
147cdf0e10cSrcweir 	{
148cdf0e10cSrcweir         sal_Int32 nIndex = aContextList.indexOf( rModuleIdentifier );
149cdf0e10cSrcweir         return ( nIndex >= 0 );
150cdf0e10cSrcweir 	}
151cdf0e10cSrcweir 
152cdf0e10cSrcweir 	return sal_False;
153cdf0e10cSrcweir }
154cdf0e10cSrcweir 
155cdf0e10cSrcweir static Image RetrieveImage( Reference< com::sun::star::frame::XFrame >& rFrame,
156cdf0e10cSrcweir 						    const rtl::OUString& aImageId,
157cdf0e10cSrcweir 							const rtl::OUString& aURL,
158cdf0e10cSrcweir 							sal_Bool bBigImage,
159cdf0e10cSrcweir 							sal_Bool bHiContrast )
160cdf0e10cSrcweir {
161cdf0e10cSrcweir 	Image aImage;
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 	if ( aImageId.getLength() > 0 )
164cdf0e10cSrcweir 	{
165cdf0e10cSrcweir 		aImage = framework::AddonsOptions().GetImageFromURL( aImageId, bBigImage, bHiContrast );
166cdf0e10cSrcweir 		if ( !!aImage )
167cdf0e10cSrcweir 			return aImage;
168cdf0e10cSrcweir         else
169cdf0e10cSrcweir             aImage = GetImageFromURL( rFrame, aImageId, bBigImage, bHiContrast );
170cdf0e10cSrcweir 		if ( !!aImage )
171cdf0e10cSrcweir 			return aImage;
172cdf0e10cSrcweir 	}
173cdf0e10cSrcweir 
174cdf0e10cSrcweir     aImage = framework::AddonsOptions().GetImageFromURL( aURL, bBigImage, bHiContrast );
175cdf0e10cSrcweir 	if ( !aImage )
176cdf0e10cSrcweir 		aImage = GetImageFromURL( rFrame, aImageId, bBigImage, bHiContrast );
177cdf0e10cSrcweir 
178cdf0e10cSrcweir 	return aImage;
179cdf0e10cSrcweir }
180cdf0e10cSrcweir 
181cdf0e10cSrcweir // XComponent
182cdf0e10cSrcweir void SAL_CALL AddonsToolBarManager::dispose() throw( RuntimeException )
183cdf0e10cSrcweir {
184cdf0e10cSrcweir     Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY );
185cdf0e10cSrcweir 
186cdf0e10cSrcweir     {
187cdf0e10cSrcweir         // Remove addon specific data from toolbar items.
188cdf0e10cSrcweir         ResetableGuard aGuard( m_aLock );
189cdf0e10cSrcweir         for ( sal_uInt16 n = 0; n < m_pToolBar->GetItemCount(); n++ )
190cdf0e10cSrcweir         {
191cdf0e10cSrcweir             sal_uInt16 nId( m_pToolBar->GetItemId( n ) );
192cdf0e10cSrcweir 
193cdf0e10cSrcweir             if ( nId > 0 )
194cdf0e10cSrcweir             {
195cdf0e10cSrcweir 		        AddonsParams* pRuntimeItemData = (AddonsParams*)m_pToolBar->GetItemData( nId );
196cdf0e10cSrcweir                 if ( pRuntimeItemData )
197cdf0e10cSrcweir                     delete pRuntimeItemData;
198cdf0e10cSrcweir                 m_pToolBar->SetItemData( nId, NULL );
199cdf0e10cSrcweir             }
200cdf0e10cSrcweir         }
201cdf0e10cSrcweir     }
202cdf0e10cSrcweir 
203cdf0e10cSrcweir     // Base class will destroy our m_pToolBar member
204cdf0e10cSrcweir     ToolBarManager::dispose();
205cdf0e10cSrcweir }
206cdf0e10cSrcweir 
207cdf0e10cSrcweir bool AddonsToolBarManager::MenuItemAllowed( sal_uInt16 nId ) const
208cdf0e10cSrcweir {
209cdf0e10cSrcweir     if (( nId == MENUITEM_TOOLBAR_VISIBLEBUTTON ) ||
210cdf0e10cSrcweir         ( nId == MENUITEM_TOOLBAR_CUSTOMIZETOOLBAR ))
211cdf0e10cSrcweir         return false;
212cdf0e10cSrcweir     else
213cdf0e10cSrcweir         return true;
214cdf0e10cSrcweir }
215cdf0e10cSrcweir 
216cdf0e10cSrcweir void AddonsToolBarManager::RefreshImages()
217cdf0e10cSrcweir {
218cdf0e10cSrcweir     sal_Bool  bBigImages( SvtMiscOptions().AreCurrentSymbolsLarge() );
219cdf0e10cSrcweir     for ( sal_uInt16 nPos = 0; nPos < m_pToolBar->GetItemCount(); nPos++ )
220cdf0e10cSrcweir     {
221cdf0e10cSrcweir         sal_uInt16 nId( m_pToolBar->GetItemId( nPos ) );
222cdf0e10cSrcweir 
223cdf0e10cSrcweir         if ( nId > 0 )
224cdf0e10cSrcweir         {
225cdf0e10cSrcweir             ::rtl::OUString aCommandURL = m_pToolBar->GetItemCommand( nId );
226cdf0e10cSrcweir             ::rtl::OUString aImageId;
227cdf0e10cSrcweir             AddonsParams* pRuntimeItemData = (AddonsParams*)m_pToolBar->GetItemData( nId );
228cdf0e10cSrcweir             if ( pRuntimeItemData )
229cdf0e10cSrcweir                 aImageId  = pRuntimeItemData->aImageId;
230cdf0e10cSrcweir 
231cdf0e10cSrcweir             m_pToolBar->SetItemImage( nId, RetrieveImage( m_xFrame,
232cdf0e10cSrcweir                                                           aImageId,
233cdf0e10cSrcweir                                                           aCommandURL,
234cdf0e10cSrcweir                                                           bBigImages,
235cdf0e10cSrcweir                                                           m_bIsHiContrast ));
236cdf0e10cSrcweir         }
237cdf0e10cSrcweir     }
238cdf0e10cSrcweir }
239cdf0e10cSrcweir 
240cdf0e10cSrcweir void AddonsToolBarManager::FillToolbar( const Sequence< Sequence< PropertyValue > >& rAddonToolbar )
241cdf0e10cSrcweir {
242cdf0e10cSrcweir     ResetableGuard aGuard( m_aLock );
243cdf0e10cSrcweir 
244cdf0e10cSrcweir     if ( m_bDisposed )
245cdf0e10cSrcweir         return;
246cdf0e10cSrcweir 
247cdf0e10cSrcweir     sal_uInt16    nId( 1 );
248cdf0e10cSrcweir 
249cdf0e10cSrcweir     RemoveControllers();
250cdf0e10cSrcweir 
251cdf0e10cSrcweir     m_pToolBar->Clear();
252cdf0e10cSrcweir     m_aControllerMap.clear();
253cdf0e10cSrcweir 
254cdf0e10cSrcweir     ::rtl::OUString aModuleIdentifier;
255cdf0e10cSrcweir     try
256cdf0e10cSrcweir     {
257cdf0e10cSrcweir         Reference< XModuleManager > xModuleManager(
258cdf0e10cSrcweir             m_xServiceManager->createInstance( SERVICENAME_MODULEMANAGER ), UNO_QUERY_THROW );
259cdf0e10cSrcweir         aModuleIdentifier = xModuleManager->identify( m_xFrame );
260cdf0e10cSrcweir     }
261cdf0e10cSrcweir     catch ( Exception& )
262cdf0e10cSrcweir     {
263cdf0e10cSrcweir     }
264cdf0e10cSrcweir 
265cdf0e10cSrcweir     Reference< XMultiComponentFactory > xToolbarControllerFactory( m_xToolbarControllerRegistration, UNO_QUERY );
266cdf0e10cSrcweir     Reference< XComponentContext > xComponentContext;
267cdf0e10cSrcweir     Reference< XPropertySet > xProps( m_xServiceManager, UNO_QUERY );
268cdf0e10cSrcweir 
269cdf0e10cSrcweir     if ( xProps.is() )
270cdf0e10cSrcweir         xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))) >>= xComponentContext;
271cdf0e10cSrcweir 
272cdf0e10cSrcweir     sal_uInt32  nElements( 0 );
273cdf0e10cSrcweir     sal_Bool    bAppendSeparator( sal_False );
274cdf0e10cSrcweir     Reference< XWindow > xToolbarWindow = VCLUnoHelper::GetInterface( m_pToolBar );
275cdf0e10cSrcweir 	for ( sal_uInt32 n = 0; n < (sal_uInt32)rAddonToolbar.getLength(); n++ )
276cdf0e10cSrcweir 	{
277cdf0e10cSrcweir 		rtl::OUString	aValueName;
278cdf0e10cSrcweir 
279cdf0e10cSrcweir 		rtl::OUString	aURL;
280cdf0e10cSrcweir 		rtl::OUString	aTitle;
281cdf0e10cSrcweir 		rtl::OUString	aImageId;
282cdf0e10cSrcweir 		rtl::OUString	aContext;
283cdf0e10cSrcweir 		rtl::OUString	aTarget;
284cdf0e10cSrcweir         rtl::OUString   aControlType;
285cdf0e10cSrcweir         sal_uInt16      nWidth( 0 );
286cdf0e10cSrcweir 
287cdf0e10cSrcweir 		const Sequence< PropertyValue >& rSeq = rAddonToolbar[n];
288cdf0e10cSrcweir 
289cdf0e10cSrcweir         ToolBarMerger::ConvertSequenceToValues( rSeq, aURL, aTitle, aImageId, aTarget, aContext, aControlType, nWidth );
290cdf0e10cSrcweir 
291cdf0e10cSrcweir 		if ( IsCorrectContext( aModuleIdentifier, aContext ))
292cdf0e10cSrcweir 		{
293cdf0e10cSrcweir 			if ( aURL.equalsAsciiL( TOOLBOXITEM_SEPARATOR_STR, TOOLBOXITEM_SEPARATOR_STR_LEN ))
294cdf0e10cSrcweir 			{
295cdf0e10cSrcweir 				sal_uInt16 nCount = m_pToolBar->GetItemCount();
296cdf0e10cSrcweir 				if ( nCount > 0 && ( m_pToolBar->GetItemType( nCount-1 ) != TOOLBOXITEM_SEPARATOR ) && nElements > 0 )
297cdf0e10cSrcweir 				{
298cdf0e10cSrcweir                     nElements = 0;
299cdf0e10cSrcweir 					m_pToolBar->InsertSeparator();
300cdf0e10cSrcweir 				}
301cdf0e10cSrcweir 			}
302cdf0e10cSrcweir 			else
303cdf0e10cSrcweir 			{
304cdf0e10cSrcweir                 sal_uInt16 nCount = m_pToolBar->GetItemCount();
305cdf0e10cSrcweir 			    if ( bAppendSeparator && nCount > 0 && ( m_pToolBar->GetItemType( nCount-1 ) != TOOLBOXITEM_SEPARATOR ))
306cdf0e10cSrcweir 				{
307cdf0e10cSrcweir 				    // We have to append a separator first if the last item is not a separator
308cdf0e10cSrcweir 				    m_pToolBar->InsertSeparator();
309cdf0e10cSrcweir 			    }
310cdf0e10cSrcweir 				bAppendSeparator = sal_False;
311cdf0e10cSrcweir 
312cdf0e10cSrcweir 				m_pToolBar->InsertItem( nId, aTitle );
313cdf0e10cSrcweir 
314cdf0e10cSrcweir 				Image aImage = RetrieveImage( m_xFrame, aImageId, aURL, !m_bSmallSymbols, m_bIsHiContrast );
315cdf0e10cSrcweir 				if ( !!aImage )
316cdf0e10cSrcweir 					m_pToolBar->SetItemImage( nId, aImage );
317cdf0e10cSrcweir 
318cdf0e10cSrcweir 				// Create TbRuntimeItemData to hold additional information we will need in the future
319cdf0e10cSrcweir 				AddonsParams* pRuntimeItemData = new AddonsParams;
320cdf0e10cSrcweir 				pRuntimeItemData->aImageId	= aImageId;
321cdf0e10cSrcweir 				pRuntimeItemData->aTarget	= aTarget;
322cdf0e10cSrcweir 				m_pToolBar->SetItemData( nId, pRuntimeItemData );
323cdf0e10cSrcweir 				m_pToolBar->SetItemCommand( nId, aURL );
324cdf0e10cSrcweir 
325cdf0e10cSrcweir                 Reference< XStatusListener > xController;
326cdf0e10cSrcweir 
327cdf0e10cSrcweir                 sal_Bool bMustBeInit( sal_True );
328cdf0e10cSrcweir 
329cdf0e10cSrcweir                 // Support external toolbar controller for add-ons!
330cdf0e10cSrcweir                 if ( m_xToolbarControllerRegistration.is() &&
331cdf0e10cSrcweir                      m_xToolbarControllerRegistration->hasController( aURL, m_aModuleIdentifier ))
332cdf0e10cSrcweir                 {
333cdf0e10cSrcweir                     if ( xToolbarControllerFactory.is() )
334cdf0e10cSrcweir                     {
335cdf0e10cSrcweir                         Sequence< Any > aArgs(5);
336cdf0e10cSrcweir                         PropertyValue   aPropValue;
337cdf0e10cSrcweir 
338cdf0e10cSrcweir                         aPropValue.Name     = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ModuleName" ));
339cdf0e10cSrcweir                         aPropValue.Value    <<= m_aModuleIdentifier;
340cdf0e10cSrcweir                         aArgs[0] <<= aPropValue;
341cdf0e10cSrcweir                         aPropValue.Name     = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Frame" ));
342cdf0e10cSrcweir                         aPropValue.Value    <<= m_xFrame;
343cdf0e10cSrcweir                         aArgs[1] <<= aPropValue;
344cdf0e10cSrcweir                         aPropValue.Name     = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ServiceManager" ));
345cdf0e10cSrcweir                         aPropValue.Value    <<= m_xServiceManager;
346cdf0e10cSrcweir                         aArgs[2] <<= aPropValue;
347cdf0e10cSrcweir                         aPropValue.Name     = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ParentWindow" ));
348cdf0e10cSrcweir                         aPropValue.Value    <<= xToolbarWindow;
349cdf0e10cSrcweir                         aArgs[3] <<= aPropValue;
350cdf0e10cSrcweir                         aPropValue.Name     = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ItemId" ));
351cdf0e10cSrcweir                         aPropValue.Value    = makeAny( sal_Int32( nId ));
352cdf0e10cSrcweir                         aArgs[4] <<= aPropValue;
353cdf0e10cSrcweir 
354cdf0e10cSrcweir                         try
355cdf0e10cSrcweir                         {
356cdf0e10cSrcweir                             xController = Reference< XStatusListener >( xToolbarControllerFactory->createInstanceWithArgumentsAndContext(
357cdf0e10cSrcweir                                                                             aURL, aArgs, xComponentContext ),
358cdf0e10cSrcweir                                                                         UNO_QUERY );
359cdf0e10cSrcweir                         }
360cdf0e10cSrcweir                         catch ( uno::Exception& )
361cdf0e10cSrcweir                         {
362cdf0e10cSrcweir                         }
363cdf0e10cSrcweir                         bMustBeInit = sal_False; // factory called init already!
364cdf0e10cSrcweir                     }
365cdf0e10cSrcweir                 }
366cdf0e10cSrcweir                 else
367cdf0e10cSrcweir                 {
368cdf0e10cSrcweir                     ::cppu::OWeakObject* pController = 0;
369cdf0e10cSrcweir 
370cdf0e10cSrcweir                     pController = ToolBarMerger::CreateController( m_xServiceManager, m_xFrame, m_pToolBar, aURL, nId, nWidth, aControlType );
371cdf0e10cSrcweir                     xController = Reference< XStatusListener >( pController, UNO_QUERY );
372cdf0e10cSrcweir                 }
373cdf0e10cSrcweir 
374cdf0e10cSrcweir                 // insert controller to the map
375cdf0e10cSrcweir                 m_aControllerMap[nId] = xController;
376cdf0e10cSrcweir 
377cdf0e10cSrcweir                 Reference< XInitialization > xInit( xController, UNO_QUERY );
378cdf0e10cSrcweir                 if ( xInit.is() && bMustBeInit )
379cdf0e10cSrcweir                 {
380cdf0e10cSrcweir                     PropertyValue aPropValue;
381cdf0e10cSrcweir                     Sequence< Any > aArgs( 3 );
382cdf0e10cSrcweir                     aPropValue.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Frame" ));
383cdf0e10cSrcweir                     aPropValue.Value <<= m_xFrame;
384cdf0e10cSrcweir                     aArgs[0] <<= aPropValue;
385cdf0e10cSrcweir                     aPropValue.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CommandURL" ));
386cdf0e10cSrcweir                     aPropValue.Value <<= aURL;
387cdf0e10cSrcweir                     aArgs[1] <<= aPropValue;
388cdf0e10cSrcweir                     aPropValue.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ServiceManager" ));
389cdf0e10cSrcweir                     aPropValue.Value <<= m_xServiceManager;
390cdf0e10cSrcweir                     aArgs[2] <<= aPropValue;
391cdf0e10cSrcweir                     try
392cdf0e10cSrcweir                     {
393cdf0e10cSrcweir                         xInit->initialize( aArgs );
394cdf0e10cSrcweir                     }
395cdf0e10cSrcweir                     catch ( uno::Exception& )
396cdf0e10cSrcweir                     {
397cdf0e10cSrcweir                     }
398cdf0e10cSrcweir                 }
399cdf0e10cSrcweir 
400cdf0e10cSrcweir                 // Request a item window from the toolbar controller and set it at the VCL toolbar
401cdf0e10cSrcweir                 Reference< XToolbarController > xTbxController( xController, UNO_QUERY );
402cdf0e10cSrcweir                 if ( xTbxController.is() && xToolbarWindow.is() )
403cdf0e10cSrcweir                 {
404cdf0e10cSrcweir                     Reference< XWindow > xWindow = xTbxController->createItemWindow( xToolbarWindow );
405cdf0e10cSrcweir                     if ( xWindow.is() )
406cdf0e10cSrcweir                     {
407cdf0e10cSrcweir                         Window* pItemWin = VCLUnoHelper::GetWindow( xWindow );
408cdf0e10cSrcweir                         if ( pItemWin )
409cdf0e10cSrcweir                         {
410cdf0e10cSrcweir                             WindowType nType = pItemWin->GetType();
411cdf0e10cSrcweir                             if ( nType == WINDOW_LISTBOX || nType == WINDOW_MULTILISTBOX || nType == WINDOW_COMBOBOX )
412cdf0e10cSrcweir                                 pItemWin->SetAccessibleName( m_pToolBar->GetItemText( nId ) );
413cdf0e10cSrcweir 				            m_pToolBar->SetItemWindow( nId, pItemWin );
414cdf0e10cSrcweir                         }
415cdf0e10cSrcweir                     }
416cdf0e10cSrcweir                 }
417cdf0e10cSrcweir 
418cdf0e10cSrcweir                 // Notify controller implementation to its listeners. Controller is now useable from outside.
419cdf0e10cSrcweir                 Reference< XUpdatable > xUpdatable( xController, UNO_QUERY );
420cdf0e10cSrcweir                 if ( xUpdatable.is() )
421cdf0e10cSrcweir                 {
422cdf0e10cSrcweir                     try
423cdf0e10cSrcweir                     {
424cdf0e10cSrcweir                         xUpdatable->update();
425cdf0e10cSrcweir                     }
426cdf0e10cSrcweir                     catch ( uno::Exception& )
427cdf0e10cSrcweir                     {
428cdf0e10cSrcweir                     }
429cdf0e10cSrcweir                 }
430cdf0e10cSrcweir 
431cdf0e10cSrcweir                 ++nId;
432cdf0e10cSrcweir 				++nElements;
433cdf0e10cSrcweir 			}
434cdf0e10cSrcweir 		}
435cdf0e10cSrcweir 	}
436cdf0e10cSrcweir 
437cdf0e10cSrcweir     AddFrameActionListener();
438cdf0e10cSrcweir }
439cdf0e10cSrcweir 
440cdf0e10cSrcweir IMPL_LINK( AddonsToolBarManager, Click, ToolBox*, EMPTYARG )
441cdf0e10cSrcweir {
442cdf0e10cSrcweir     if ( m_bDisposed )
443cdf0e10cSrcweir         return 1;
444cdf0e10cSrcweir 
445cdf0e10cSrcweir     sal_uInt16 nId( m_pToolBar->GetCurItemId() );
446cdf0e10cSrcweir     ToolBarControllerMap::const_iterator pIter = m_aControllerMap.find( nId );
447cdf0e10cSrcweir     if ( pIter != m_aControllerMap.end() )
448cdf0e10cSrcweir     {
449cdf0e10cSrcweir         Reference< XToolbarController > xController( pIter->second, UNO_QUERY );
450cdf0e10cSrcweir 
451cdf0e10cSrcweir         if ( xController.is() )
452cdf0e10cSrcweir             xController->click();
453cdf0e10cSrcweir     }
454cdf0e10cSrcweir 
455cdf0e10cSrcweir     return 1;
456cdf0e10cSrcweir }
457cdf0e10cSrcweir 
458cdf0e10cSrcweir IMPL_LINK( AddonsToolBarManager, DoubleClick, ToolBox*, EMPTYARG )
459cdf0e10cSrcweir {
460cdf0e10cSrcweir     if ( m_bDisposed )
461cdf0e10cSrcweir         return 1;
462cdf0e10cSrcweir 
463cdf0e10cSrcweir     sal_uInt16 nId( m_pToolBar->GetCurItemId() );
464cdf0e10cSrcweir     ToolBarControllerMap::const_iterator pIter = m_aControllerMap.find( nId );
465cdf0e10cSrcweir     if ( pIter != m_aControllerMap.end() )
466cdf0e10cSrcweir     {
467cdf0e10cSrcweir         Reference< XToolbarController > xController( pIter->second, UNO_QUERY );
468cdf0e10cSrcweir 
469cdf0e10cSrcweir         if ( xController.is() )
470cdf0e10cSrcweir             xController->doubleClick();
471cdf0e10cSrcweir     }
472cdf0e10cSrcweir 
473cdf0e10cSrcweir     return 1;
474cdf0e10cSrcweir }
475cdf0e10cSrcweir 
476cdf0e10cSrcweir IMPL_LINK( AddonsToolBarManager, Command, CommandEvent*, EMPTYARG )
477cdf0e10cSrcweir {
478cdf0e10cSrcweir     ResetableGuard aGuard( m_aLock );
479cdf0e10cSrcweir 
480cdf0e10cSrcweir     if ( m_bDisposed )
481cdf0e10cSrcweir         return 1;
482cdf0e10cSrcweir 
483cdf0e10cSrcweir     return 0;
484cdf0e10cSrcweir }
485cdf0e10cSrcweir 
486cdf0e10cSrcweir IMPL_LINK( AddonsToolBarManager, Select, ToolBox*, EMPTYARG )
487cdf0e10cSrcweir {
488cdf0e10cSrcweir     if ( m_bDisposed )
489cdf0e10cSrcweir         return 1;
490cdf0e10cSrcweir 
491cdf0e10cSrcweir     sal_Int16   nKeyModifier( (sal_Int16)m_pToolBar->GetModifier() );
492cdf0e10cSrcweir     sal_uInt16      nId( m_pToolBar->GetCurItemId() );
493cdf0e10cSrcweir     ToolBarControllerMap::const_iterator pIter = m_aControllerMap.find( nId );
494cdf0e10cSrcweir     if ( pIter != m_aControllerMap.end() )
495cdf0e10cSrcweir     {
496cdf0e10cSrcweir         Reference< XToolbarController > xController( pIter->second, UNO_QUERY );
497cdf0e10cSrcweir 
498cdf0e10cSrcweir         if ( xController.is() )
499cdf0e10cSrcweir             xController->execute( nKeyModifier );
500cdf0e10cSrcweir     }
501cdf0e10cSrcweir 
502cdf0e10cSrcweir     return 1;
503cdf0e10cSrcweir }
504cdf0e10cSrcweir 
505cdf0e10cSrcweir IMPL_LINK( AddonsToolBarManager, Highlight, ToolBox*, EMPTYARG )
506cdf0e10cSrcweir {
507cdf0e10cSrcweir     return 1;
508cdf0e10cSrcweir }
509cdf0e10cSrcweir 
510cdf0e10cSrcweir IMPL_LINK( AddonsToolBarManager, Activate, ToolBox*, EMPTYARG )
511cdf0e10cSrcweir {
512cdf0e10cSrcweir     return 1;
513cdf0e10cSrcweir }
514cdf0e10cSrcweir 
515cdf0e10cSrcweir IMPL_LINK( AddonsToolBarManager, Deactivate, ToolBox*, EMPTYARG )
516cdf0e10cSrcweir {
517cdf0e10cSrcweir     return 1;
518cdf0e10cSrcweir }
519cdf0e10cSrcweir 
520cdf0e10cSrcweir IMPL_LINK( AddonsToolBarManager, StateChanged, StateChangedType*, pStateChangedType )
521cdf0e10cSrcweir {
522cdf0e10cSrcweir 	if ( *pStateChangedType == STATE_CHANGE_CONTROLBACKGROUND )
523cdf0e10cSrcweir 	{
524cdf0e10cSrcweir 		// Check if we need to get new images for normal/high contrast mode
525cdf0e10cSrcweir 		CheckAndUpdateImages();
526cdf0e10cSrcweir 	}
527cdf0e10cSrcweir     return 1;
528cdf0e10cSrcweir }
529cdf0e10cSrcweir 
530cdf0e10cSrcweir IMPL_LINK( AddonsToolBarManager, DataChanged, DataChangedEvent*, pDataChangedEvent  )
531cdf0e10cSrcweir {
532cdf0e10cSrcweir 	if ((( pDataChangedEvent->GetType() == DATACHANGED_SETTINGS	)	||
533cdf0e10cSrcweir 		(  pDataChangedEvent->GetType() == DATACHANGED_DISPLAY	))	&&
534cdf0e10cSrcweir         ( pDataChangedEvent->GetFlags() & SETTINGS_STYLE		))
535cdf0e10cSrcweir 	{
536cdf0e10cSrcweir 		// Check if we need to get new images for normal/high contrast mode
537cdf0e10cSrcweir 		CheckAndUpdateImages();
538cdf0e10cSrcweir 	}
539cdf0e10cSrcweir 
540cdf0e10cSrcweir     for ( sal_uInt16 nPos = 0; nPos < m_pToolBar->GetItemCount(); ++nPos )
541cdf0e10cSrcweir 	{
542cdf0e10cSrcweir         const sal_uInt16 nId = m_pToolBar->GetItemId(nPos);
543cdf0e10cSrcweir         Window* pWindow = m_pToolBar->GetItemWindow( nId );
544cdf0e10cSrcweir         if ( pWindow )
545cdf0e10cSrcweir         {
546cdf0e10cSrcweir             const DataChangedEvent& rDCEvt( *pDataChangedEvent );
547cdf0e10cSrcweir             pWindow->DataChanged( rDCEvt );
548cdf0e10cSrcweir         }
549cdf0e10cSrcweir     }
550cdf0e10cSrcweir 
551cdf0e10cSrcweir     return 1;
552cdf0e10cSrcweir }
553cdf0e10cSrcweir 
554cdf0e10cSrcweir }
555cdf0e10cSrcweir 
556