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/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_
86*b63233d8Sdamjan #include <toolkit/helper/vclunohelper.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 
AddonsToolBarManager(const Reference<XMultiServiceFactory> & rServiceManager,const Reference<XFrame> & rFrame,const rtl::OUString & rResourceName,ToolBar * pToolBar)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 
~AddonsToolBarManager()137cdf0e10cSrcweir AddonsToolBarManager::~AddonsToolBarManager()
138cdf0e10cSrcweir {
139cdf0e10cSrcweir }
140cdf0e10cSrcweir 
IsCorrectContext(const::rtl::OUString & rModuleIdentifier,const::rtl::OUString & aContextList)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 
RetrieveImage(Reference<com::sun::star::frame::XFrame> & rFrame,const rtl::OUString & aImageId,const rtl::OUString & aURL,sal_Bool bBigImage,sal_Bool bHiContrast)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
dispose()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 
MenuItemAllowed(sal_uInt16 nId) const207cdf0e10cSrcweir 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 
RefreshImages()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 
FillToolbar(const Sequence<Sequence<PropertyValue>> & rAddonToolbar)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< XComponentContext > xComponentContext;
266cdf0e10cSrcweir     Reference< XPropertySet > xProps( m_xServiceManager, UNO_QUERY );
267cdf0e10cSrcweir 
268cdf0e10cSrcweir     if ( xProps.is() )
269cdf0e10cSrcweir         xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))) >>= xComponentContext;
270cdf0e10cSrcweir 
271cdf0e10cSrcweir     sal_uInt32  nElements( 0 );
272cdf0e10cSrcweir     sal_Bool    bAppendSeparator( sal_False );
273cdf0e10cSrcweir     Reference< XWindow > xToolbarWindow = VCLUnoHelper::GetInterface( m_pToolBar );
274cdf0e10cSrcweir 	for ( sal_uInt32 n = 0; n < (sal_uInt32)rAddonToolbar.getLength(); n++ )
275cdf0e10cSrcweir 	{
276cdf0e10cSrcweir 		rtl::OUString	aValueName;
277cdf0e10cSrcweir 
278cdf0e10cSrcweir 		rtl::OUString	aURL;
279cdf0e10cSrcweir 		rtl::OUString	aTitle;
280cdf0e10cSrcweir 		rtl::OUString	aImageId;
281cdf0e10cSrcweir 		rtl::OUString	aContext;
282cdf0e10cSrcweir 		rtl::OUString	aTarget;
283cdf0e10cSrcweir         rtl::OUString   aControlType;
284cdf0e10cSrcweir         sal_uInt16      nWidth( 0 );
285cdf0e10cSrcweir 
286cdf0e10cSrcweir 		const Sequence< PropertyValue >& rSeq = rAddonToolbar[n];
287cdf0e10cSrcweir 
288cdf0e10cSrcweir         ToolBarMerger::ConvertSequenceToValues( rSeq, aURL, aTitle, aImageId, aTarget, aContext, aControlType, nWidth );
289cdf0e10cSrcweir 
290cdf0e10cSrcweir 		if ( IsCorrectContext( aModuleIdentifier, aContext ))
291cdf0e10cSrcweir 		{
292cdf0e10cSrcweir 			if ( aURL.equalsAsciiL( TOOLBOXITEM_SEPARATOR_STR, TOOLBOXITEM_SEPARATOR_STR_LEN ))
293cdf0e10cSrcweir 			{
294cdf0e10cSrcweir 				sal_uInt16 nCount = m_pToolBar->GetItemCount();
295cdf0e10cSrcweir 				if ( nCount > 0 && ( m_pToolBar->GetItemType( nCount-1 ) != TOOLBOXITEM_SEPARATOR ) && nElements > 0 )
296cdf0e10cSrcweir 				{
297cdf0e10cSrcweir                     nElements = 0;
298cdf0e10cSrcweir 					m_pToolBar->InsertSeparator();
299cdf0e10cSrcweir 				}
300cdf0e10cSrcweir 			}
301cdf0e10cSrcweir 			else
302cdf0e10cSrcweir 			{
303cdf0e10cSrcweir                 sal_uInt16 nCount = m_pToolBar->GetItemCount();
304cdf0e10cSrcweir 			    if ( bAppendSeparator && nCount > 0 && ( m_pToolBar->GetItemType( nCount-1 ) != TOOLBOXITEM_SEPARATOR ))
305cdf0e10cSrcweir 				{
306cdf0e10cSrcweir 				    // We have to append a separator first if the last item is not a separator
307cdf0e10cSrcweir 				    m_pToolBar->InsertSeparator();
308cdf0e10cSrcweir 			    }
309cdf0e10cSrcweir 				bAppendSeparator = sal_False;
310cdf0e10cSrcweir 
311cdf0e10cSrcweir 				m_pToolBar->InsertItem( nId, aTitle );
312cdf0e10cSrcweir 
313cdf0e10cSrcweir 				Image aImage = RetrieveImage( m_xFrame, aImageId, aURL, !m_bSmallSymbols, m_bIsHiContrast );
314cdf0e10cSrcweir 				if ( !!aImage )
315cdf0e10cSrcweir 					m_pToolBar->SetItemImage( nId, aImage );
316cdf0e10cSrcweir 
317cdf0e10cSrcweir 				// Create TbRuntimeItemData to hold additional information we will need in the future
318cdf0e10cSrcweir 				AddonsParams* pRuntimeItemData = new AddonsParams;
319cdf0e10cSrcweir 				pRuntimeItemData->aImageId	= aImageId;
320cdf0e10cSrcweir 				pRuntimeItemData->aTarget	= aTarget;
321cdf0e10cSrcweir 				m_pToolBar->SetItemData( nId, pRuntimeItemData );
322cdf0e10cSrcweir 				m_pToolBar->SetItemCommand( nId, aURL );
323cdf0e10cSrcweir 
324cdf0e10cSrcweir                 Reference< XStatusListener > xController;
325cdf0e10cSrcweir 
326cdf0e10cSrcweir                 sal_Bool bMustBeInit( sal_True );
327cdf0e10cSrcweir 
328cdf0e10cSrcweir                 // Support external toolbar controller for add-ons!
329dccf82beSAriel Constenla-Haile                 if ( m_xToolbarControllerFactory.is() &&
330dccf82beSAriel Constenla-Haile                      m_xToolbarControllerFactory->hasController( aURL, m_aModuleIdentifier ))
331cdf0e10cSrcweir                 {
332dccf82beSAriel Constenla-Haile                     Sequence< Any > aArgs(5);
333dccf82beSAriel Constenla-Haile                     PropertyValue   aPropValue;
334dccf82beSAriel Constenla-Haile 
335dccf82beSAriel Constenla-Haile                     aPropValue.Name     = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ModuleIdentifier" ));
336dccf82beSAriel Constenla-Haile                     aPropValue.Value    <<= m_aModuleIdentifier;
337dccf82beSAriel Constenla-Haile                     aArgs[0] <<= aPropValue;
338dccf82beSAriel Constenla-Haile                     aPropValue.Name     = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Frame" ));
339dccf82beSAriel Constenla-Haile                     aPropValue.Value    <<= m_xFrame;
340dccf82beSAriel Constenla-Haile                     aArgs[1] <<= aPropValue;
341dccf82beSAriel Constenla-Haile                     aPropValue.Name     = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ServiceManager" ));
342dccf82beSAriel Constenla-Haile                     aPropValue.Value    <<= m_xServiceManager;
343dccf82beSAriel Constenla-Haile                     aArgs[2] <<= aPropValue;
344dccf82beSAriel Constenla-Haile                     aPropValue.Name     = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ParentWindow" ));
345dccf82beSAriel Constenla-Haile                     aPropValue.Value    <<= xToolbarWindow;
346dccf82beSAriel Constenla-Haile                     aArgs[3] <<= aPropValue;
347dccf82beSAriel Constenla-Haile                     aPropValue.Name     = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ItemId" ));
348dccf82beSAriel Constenla-Haile                     aPropValue.Value    = makeAny( sal_Int32( nId ));
349dccf82beSAriel Constenla-Haile                     aArgs[4] <<= aPropValue;
350dccf82beSAriel Constenla-Haile 
351dccf82beSAriel Constenla-Haile                     try
352dccf82beSAriel Constenla-Haile                     {
353dccf82beSAriel Constenla-Haile                         xController = Reference< XStatusListener >( m_xToolbarControllerFactory->createInstanceWithArgumentsAndContext(
354dccf82beSAriel Constenla-Haile                                                                         aURL, aArgs, xComponentContext ),
355dccf82beSAriel Constenla-Haile                                                                     UNO_QUERY );
356dccf82beSAriel Constenla-Haile                     }
357dccf82beSAriel Constenla-Haile                     catch ( uno::Exception& )
358cdf0e10cSrcweir                     {
359cdf0e10cSrcweir                     }
360dccf82beSAriel Constenla-Haile                     bMustBeInit = sal_False; // factory called init already!
361cdf0e10cSrcweir                 }
362cdf0e10cSrcweir                 else
363cdf0e10cSrcweir                 {
364cdf0e10cSrcweir                     ::cppu::OWeakObject* pController = 0;
365cdf0e10cSrcweir 
366cdf0e10cSrcweir                     pController = ToolBarMerger::CreateController( m_xServiceManager, m_xFrame, m_pToolBar, aURL, nId, nWidth, aControlType );
367cdf0e10cSrcweir                     xController = Reference< XStatusListener >( pController, UNO_QUERY );
368cdf0e10cSrcweir                 }
369cdf0e10cSrcweir 
370cdf0e10cSrcweir                 // insert controller to the map
371cdf0e10cSrcweir                 m_aControllerMap[nId] = xController;
372cdf0e10cSrcweir 
373cdf0e10cSrcweir                 Reference< XInitialization > xInit( xController, UNO_QUERY );
374cdf0e10cSrcweir                 if ( xInit.is() && bMustBeInit )
375cdf0e10cSrcweir                 {
376cdf0e10cSrcweir                     PropertyValue aPropValue;
377cdf0e10cSrcweir                     Sequence< Any > aArgs( 3 );
378cdf0e10cSrcweir                     aPropValue.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Frame" ));
379cdf0e10cSrcweir                     aPropValue.Value <<= m_xFrame;
380cdf0e10cSrcweir                     aArgs[0] <<= aPropValue;
381cdf0e10cSrcweir                     aPropValue.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CommandURL" ));
382cdf0e10cSrcweir                     aPropValue.Value <<= aURL;
383cdf0e10cSrcweir                     aArgs[1] <<= aPropValue;
384cdf0e10cSrcweir                     aPropValue.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ServiceManager" ));
385cdf0e10cSrcweir                     aPropValue.Value <<= m_xServiceManager;
386cdf0e10cSrcweir                     aArgs[2] <<= aPropValue;
387cdf0e10cSrcweir                     try
388cdf0e10cSrcweir                     {
389cdf0e10cSrcweir                         xInit->initialize( aArgs );
390cdf0e10cSrcweir                     }
391cdf0e10cSrcweir                     catch ( uno::Exception& )
392cdf0e10cSrcweir                     {
393cdf0e10cSrcweir                     }
394cdf0e10cSrcweir                 }
395cdf0e10cSrcweir 
396cdf0e10cSrcweir                 // Request a item window from the toolbar controller and set it at the VCL toolbar
397cdf0e10cSrcweir                 Reference< XToolbarController > xTbxController( xController, UNO_QUERY );
398cdf0e10cSrcweir                 if ( xTbxController.is() && xToolbarWindow.is() )
399cdf0e10cSrcweir                 {
400cdf0e10cSrcweir                     Reference< XWindow > xWindow = xTbxController->createItemWindow( xToolbarWindow );
401cdf0e10cSrcweir                     if ( xWindow.is() )
402cdf0e10cSrcweir                     {
403cdf0e10cSrcweir                         Window* pItemWin = VCLUnoHelper::GetWindow( xWindow );
404cdf0e10cSrcweir                         if ( pItemWin )
405cdf0e10cSrcweir                         {
406cdf0e10cSrcweir                             WindowType nType = pItemWin->GetType();
407cdf0e10cSrcweir                             if ( nType == WINDOW_LISTBOX || nType == WINDOW_MULTILISTBOX || nType == WINDOW_COMBOBOX )
408cdf0e10cSrcweir                                 pItemWin->SetAccessibleName( m_pToolBar->GetItemText( nId ) );
409cdf0e10cSrcweir 				            m_pToolBar->SetItemWindow( nId, pItemWin );
410cdf0e10cSrcweir                         }
411cdf0e10cSrcweir                     }
412cdf0e10cSrcweir                 }
413cdf0e10cSrcweir 
414cdf0e10cSrcweir                 // Notify controller implementation to its listeners. Controller is now useable from outside.
415cdf0e10cSrcweir                 Reference< XUpdatable > xUpdatable( xController, UNO_QUERY );
416cdf0e10cSrcweir                 if ( xUpdatable.is() )
417cdf0e10cSrcweir                 {
418cdf0e10cSrcweir                     try
419cdf0e10cSrcweir                     {
420cdf0e10cSrcweir                         xUpdatable->update();
421cdf0e10cSrcweir                     }
422cdf0e10cSrcweir                     catch ( uno::Exception& )
423cdf0e10cSrcweir                     {
424cdf0e10cSrcweir                     }
425cdf0e10cSrcweir                 }
426cdf0e10cSrcweir 
427cdf0e10cSrcweir                 ++nId;
428cdf0e10cSrcweir 				++nElements;
429cdf0e10cSrcweir 			}
430cdf0e10cSrcweir 		}
431cdf0e10cSrcweir 	}
432cdf0e10cSrcweir 
433cdf0e10cSrcweir     AddFrameActionListener();
434cdf0e10cSrcweir }
435cdf0e10cSrcweir 
IMPL_LINK(AddonsToolBarManager,Click,ToolBox *,EMPTYARG)436cdf0e10cSrcweir IMPL_LINK( AddonsToolBarManager, Click, ToolBox*, EMPTYARG )
437cdf0e10cSrcweir {
438cdf0e10cSrcweir     if ( m_bDisposed )
439cdf0e10cSrcweir         return 1;
440cdf0e10cSrcweir 
441cdf0e10cSrcweir     sal_uInt16 nId( m_pToolBar->GetCurItemId() );
442cdf0e10cSrcweir     ToolBarControllerMap::const_iterator pIter = m_aControllerMap.find( nId );
443cdf0e10cSrcweir     if ( pIter != m_aControllerMap.end() )
444cdf0e10cSrcweir     {
445cdf0e10cSrcweir         Reference< XToolbarController > xController( pIter->second, UNO_QUERY );
446cdf0e10cSrcweir 
447cdf0e10cSrcweir         if ( xController.is() )
448cdf0e10cSrcweir             xController->click();
449cdf0e10cSrcweir     }
450cdf0e10cSrcweir 
451cdf0e10cSrcweir     return 1;
452cdf0e10cSrcweir }
453cdf0e10cSrcweir 
IMPL_LINK(AddonsToolBarManager,DoubleClick,ToolBox *,EMPTYARG)454cdf0e10cSrcweir IMPL_LINK( AddonsToolBarManager, DoubleClick, ToolBox*, EMPTYARG )
455cdf0e10cSrcweir {
456cdf0e10cSrcweir     if ( m_bDisposed )
457cdf0e10cSrcweir         return 1;
458cdf0e10cSrcweir 
459cdf0e10cSrcweir     sal_uInt16 nId( m_pToolBar->GetCurItemId() );
460cdf0e10cSrcweir     ToolBarControllerMap::const_iterator pIter = m_aControllerMap.find( nId );
461cdf0e10cSrcweir     if ( pIter != m_aControllerMap.end() )
462cdf0e10cSrcweir     {
463cdf0e10cSrcweir         Reference< XToolbarController > xController( pIter->second, UNO_QUERY );
464cdf0e10cSrcweir 
465cdf0e10cSrcweir         if ( xController.is() )
466cdf0e10cSrcweir             xController->doubleClick();
467cdf0e10cSrcweir     }
468cdf0e10cSrcweir 
469cdf0e10cSrcweir     return 1;
470cdf0e10cSrcweir }
471cdf0e10cSrcweir 
IMPL_LINK(AddonsToolBarManager,Command,CommandEvent *,EMPTYARG)472cdf0e10cSrcweir IMPL_LINK( AddonsToolBarManager, Command, CommandEvent*, EMPTYARG )
473cdf0e10cSrcweir {
474cdf0e10cSrcweir     ResetableGuard aGuard( m_aLock );
475cdf0e10cSrcweir 
476cdf0e10cSrcweir     if ( m_bDisposed )
477cdf0e10cSrcweir         return 1;
478cdf0e10cSrcweir 
479cdf0e10cSrcweir     return 0;
480cdf0e10cSrcweir }
481cdf0e10cSrcweir 
IMPL_LINK(AddonsToolBarManager,Select,ToolBox *,EMPTYARG)482cdf0e10cSrcweir IMPL_LINK( AddonsToolBarManager, Select, ToolBox*, EMPTYARG )
483cdf0e10cSrcweir {
484cdf0e10cSrcweir     if ( m_bDisposed )
485cdf0e10cSrcweir         return 1;
486cdf0e10cSrcweir 
487cdf0e10cSrcweir     sal_Int16   nKeyModifier( (sal_Int16)m_pToolBar->GetModifier() );
488cdf0e10cSrcweir     sal_uInt16      nId( m_pToolBar->GetCurItemId() );
489cdf0e10cSrcweir     ToolBarControllerMap::const_iterator pIter = m_aControllerMap.find( nId );
490cdf0e10cSrcweir     if ( pIter != m_aControllerMap.end() )
491cdf0e10cSrcweir     {
492cdf0e10cSrcweir         Reference< XToolbarController > xController( pIter->second, UNO_QUERY );
493cdf0e10cSrcweir 
494cdf0e10cSrcweir         if ( xController.is() )
495cdf0e10cSrcweir             xController->execute( nKeyModifier );
496cdf0e10cSrcweir     }
497cdf0e10cSrcweir 
498cdf0e10cSrcweir     return 1;
499cdf0e10cSrcweir }
500cdf0e10cSrcweir 
IMPL_LINK(AddonsToolBarManager,Highlight,ToolBox *,EMPTYARG)501cdf0e10cSrcweir IMPL_LINK( AddonsToolBarManager, Highlight, ToolBox*, EMPTYARG )
502cdf0e10cSrcweir {
503cdf0e10cSrcweir     return 1;
504cdf0e10cSrcweir }
505cdf0e10cSrcweir 
IMPL_LINK(AddonsToolBarManager,Activate,ToolBox *,EMPTYARG)506cdf0e10cSrcweir IMPL_LINK( AddonsToolBarManager, Activate, ToolBox*, EMPTYARG )
507cdf0e10cSrcweir {
508cdf0e10cSrcweir     return 1;
509cdf0e10cSrcweir }
510cdf0e10cSrcweir 
IMPL_LINK(AddonsToolBarManager,Deactivate,ToolBox *,EMPTYARG)511cdf0e10cSrcweir IMPL_LINK( AddonsToolBarManager, Deactivate, ToolBox*, EMPTYARG )
512cdf0e10cSrcweir {
513cdf0e10cSrcweir     return 1;
514cdf0e10cSrcweir }
515cdf0e10cSrcweir 
IMPL_LINK(AddonsToolBarManager,StateChanged,StateChangedType *,pStateChangedType)516cdf0e10cSrcweir IMPL_LINK( AddonsToolBarManager, StateChanged, StateChangedType*, pStateChangedType )
517cdf0e10cSrcweir {
518cdf0e10cSrcweir 	if ( *pStateChangedType == STATE_CHANGE_CONTROLBACKGROUND )
519cdf0e10cSrcweir 	{
520cdf0e10cSrcweir 		// Check if we need to get new images for normal/high contrast mode
521cdf0e10cSrcweir 		CheckAndUpdateImages();
522cdf0e10cSrcweir 	}
523cdf0e10cSrcweir     return 1;
524cdf0e10cSrcweir }
525cdf0e10cSrcweir 
IMPL_LINK(AddonsToolBarManager,DataChanged,DataChangedEvent *,pDataChangedEvent)526cdf0e10cSrcweir IMPL_LINK( AddonsToolBarManager, DataChanged, DataChangedEvent*, pDataChangedEvent  )
527cdf0e10cSrcweir {
528cdf0e10cSrcweir 	if ((( pDataChangedEvent->GetType() == DATACHANGED_SETTINGS	)	||
529cdf0e10cSrcweir 		(  pDataChangedEvent->GetType() == DATACHANGED_DISPLAY	))	&&
530cdf0e10cSrcweir         ( pDataChangedEvent->GetFlags() & SETTINGS_STYLE		))
531cdf0e10cSrcweir 	{
532cdf0e10cSrcweir 		// Check if we need to get new images for normal/high contrast mode
533cdf0e10cSrcweir 		CheckAndUpdateImages();
534cdf0e10cSrcweir 	}
535cdf0e10cSrcweir 
536cdf0e10cSrcweir     for ( sal_uInt16 nPos = 0; nPos < m_pToolBar->GetItemCount(); ++nPos )
537cdf0e10cSrcweir 	{
538cdf0e10cSrcweir         const sal_uInt16 nId = m_pToolBar->GetItemId(nPos);
539cdf0e10cSrcweir         Window* pWindow = m_pToolBar->GetItemWindow( nId );
540cdf0e10cSrcweir         if ( pWindow )
541cdf0e10cSrcweir         {
542cdf0e10cSrcweir             const DataChangedEvent& rDCEvt( *pDataChangedEvent );
543cdf0e10cSrcweir             pWindow->DataChanged( rDCEvt );
544cdf0e10cSrcweir         }
545cdf0e10cSrcweir     }
546cdf0e10cSrcweir 
547cdf0e10cSrcweir     return 1;
548cdf0e10cSrcweir }
549cdf0e10cSrcweir 
550cdf0e10cSrcweir }
551cdf0e10cSrcweir 
552