2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #include <uielement/toolbarmanager.hxx>
21 #include <uielement/generictoolbarcontroller.hxx>
24 #include "properties.h"
25 #include <framework/imageproducer.hxx>
26 #include <framework/sfxhelperfunctions.hxx>
27 #include <classes/fwkresid.hxx>
28 #include <classes/resource.hrc>
29 #include <framework/addonsoptions.hxx>
30 #include <uielement/toolbarmerger.hxx>
32 #include <com/sun/star/ui/ItemType.hpp>
33 #include <com/sun/star/frame/XDispatchProvider.hpp>
34 #include <com/sun/star/frame/theUICommandDescription.hpp>
35 #include <com/sun/star/beans/XPropertySet.hpp>
36 #include <com/sun/star/awt/XDockableWindow.hpp>
37 #include <com/sun/star/frame/XLayoutManager.hpp>
38 #include <com/sun/star/ui/DockingArea.hpp>
39 #include <com/sun/star/graphic/XGraphic.hpp>
40 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
41 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
42 #include <com/sun/star/frame/ModuleManager.hpp>
43 #include <com/sun/star/frame/theToolbarControllerFactory.hpp>
44 #include <com/sun/star/ui/GlobalAcceleratorConfiguration.hpp>
45 #include <com/sun/star/ui/XUIElementSettings.hpp>
46 #include <com/sun/star/ui/XUIConfigurationPersistence.hpp>
47 #include <com/sun/star/ui/theModuleUIConfigurationManagerSupplier.hpp>
48 #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
49 #include <com/sun/star/ui/ImageType.hpp>
50 #include <com/sun/star/ui/UIElementType.hpp>
51 #include <comphelper/sequence.hxx>
52 #include <com/sun/star/frame/status/Visibility.hpp>
53 #include <com/sun/star/lang/DisposedException.hpp>
54 #include <com/sun/star/util/URLTransformer.hpp>
56 #include <svtools/imgdef.hxx>
57 #include <svtools/toolboxcontroller.hxx>
58 #include <unotools/cmdoptions.hxx>
59 #include <toolkit/helper/vclunohelper.hxx>
60 #include <unotools/mediadescriptor.hxx>
61 #include <comphelper/processfactory.hxx>
62 #include <svtools/miscopt.hxx>
63 #include <svl/imageitm.hxx>
64 #include <svtools/framestatuslistener.hxx>
65 #include <vcl/svapp.hxx>
66 #include <vcl/menu.hxx>
67 #include <vcl/syswin.hxx>
68 #include <vcl/taskpanelist.hxx>
69 #include <vcl/toolbox.hxx>
70 #include <vcl/settings.hxx>
72 #include <svtools/menuoptions.hxx>
73 #include <boost/bind.hpp>
74 #include <svtools/acceleratorexecute.hxx>
78 using namespace ::com::sun::star::awt
;
79 using namespace ::com::sun::star::beans
;
80 using namespace ::com::sun::star::uno
;
81 using namespace ::com::sun::star::lang
;
82 using namespace ::com::sun::star::frame
;
83 using namespace ::com::sun::star::graphic
;
84 using namespace ::com::sun::star::util
;
85 using namespace ::com::sun::star::container
;
86 using namespace ::com::sun::star::ui
;
87 using namespace ::com::sun::star
;
92 static const char ITEM_DESCRIPTOR_COMMANDURL
[] = "CommandURL";
93 static const char ITEM_DESCRIPTOR_HELPURL
[] = "HelpURL";
94 static const char ITEM_DESCRIPTOR_TOOLTIP
[] = "Tooltip";
95 static const char ITEM_DESCRIPTOR_CONTAINER
[] = "ItemDescriptorContainer";
96 static const char ITEM_DESCRIPTOR_LABEL
[] = "Label";
97 static const char ITEM_DESCRIPTOR_TYPE
[] = "Type";
98 static const char ITEM_DESCRIPTOR_VISIBLE
[] = "IsVisible";
99 static const char ITEM_DESCRIPTOR_WIDTH
[] = "Width";
100 static const char ITEM_DESCRIPTOR_STYLE
[] = "Style";
102 static const char MENUPREFIX
[] = "private:resource/menubar/";
104 static const char HELPID_PREFIX_TESTTOOL
[] = ".HelpId:";
106 static const sal_uInt16 STARTID_CUSTOMIZE_POPUPMENU
= 1000;
108 class ImageOrientationListener
: public svt::FrameStatusListener
111 ImageOrientationListener( const Reference
< XStatusListener
>& rReceiver
,
112 const Reference
< XComponentContext
>& rxContext
,
113 const Reference
< XFrame
>& rFrame
);
114 virtual ~ImageOrientationListener();
116 virtual void SAL_CALL
statusChanged( const ::com::sun::star::frame::FeatureStateEvent
& Event
) throw ( ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
119 Reference
< XStatusListener
> m_xReceiver
;
122 ImageOrientationListener::ImageOrientationListener(
123 const Reference
< XStatusListener
>& rReceiver
,
124 const Reference
< XComponentContext
>& rxContext
,
125 const Reference
< XFrame
>& rFrame
) :
126 FrameStatusListener( rxContext
, rFrame
),
127 m_xReceiver( rReceiver
)
131 ImageOrientationListener::~ImageOrientationListener()
135 void SAL_CALL
ImageOrientationListener::statusChanged( const FeatureStateEvent
& Event
)
136 throw ( RuntimeException
, std::exception
)
138 if ( m_xReceiver
.is() )
139 m_xReceiver
->statusChanged( Event
);
142 static sal_Int16
getImageTypeFromBools( bool bBig
)
146 n
|= ::com::sun::star::ui::ImageType::SIZE_LARGE
;
150 static ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XLayoutManager
> getLayoutManagerFromFrame(
151 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XFrame
>& rFrame
)
153 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XLayoutManager
> xLayoutManager
;
155 Reference
< XPropertySet
> xPropSet( rFrame
, UNO_QUERY
);
160 xPropSet
->getPropertyValue("LayoutManager") >>= xLayoutManager
;
162 catch (const RuntimeException
&)
166 catch (const Exception
&)
171 return xLayoutManager
;
174 // XInterface, XTypeProvider, XServiceInfo
176 ToolBarManager::ToolBarManager( const Reference
< XComponentContext
>& rxContext
,
177 const Reference
< XFrame
>& rFrame
,
178 const OUString
& rResourceName
,
179 ToolBox
* pToolBar
) :
180 m_bDisposed( false ),
181 m_bSmallSymbols( !SvtMiscOptions().AreCurrentSymbolsLarge() ),
182 m_bModuleIdentified( false ),
183 m_bAddedToTaskPaneList( true ),
184 m_bFrameActionRegistered( false ),
185 m_bUpdateControllers( false ),
186 m_bImageOrientationRegistered( false ),
187 m_bImageMirrored( false ),
188 m_lImageRotation( 0 ),
189 m_pToolBar( pToolBar
),
190 m_aResourceName( rResourceName
),
192 m_aListenerContainer( m_mutex
),
193 m_xContext( rxContext
),
194 m_sIconTheme( SvtMiscOptions().GetIconTheme() ),
195 m_bAcceleratorCfg( false )
197 OSL_ASSERT( m_xContext
.is() );
199 vcl::Window
* pWindow
= m_pToolBar
;
200 while ( pWindow
&& !pWindow
->IsSystemWindow() )
201 pWindow
= pWindow
->GetParent();
204 static_cast<SystemWindow
*>(pWindow
)->GetTaskPaneList()->AddWindow( m_pToolBar
);
206 m_xToolbarControllerFactory
= frame::theToolbarControllerFactory::get( m_xContext
);
207 m_xURLTransformer
= URLTransformer::create( m_xContext
);
209 m_pToolBar
->SetSelectHdl( LINK( this, ToolBarManager
, Select
) );
210 m_pToolBar
->SetActivateHdl( LINK( this, ToolBarManager
, Activate
) );
211 m_pToolBar
->SetDeactivateHdl( LINK( this, ToolBarManager
, Deactivate
) );
212 m_pToolBar
->SetClickHdl( LINK( this, ToolBarManager
, Click
) );
213 m_pToolBar
->SetDropdownClickHdl( LINK( this, ToolBarManager
, DropdownClick
) );
214 m_pToolBar
->SetDoubleClickHdl( LINK( this, ToolBarManager
, DoubleClick
) );
215 m_pToolBar
->SetStateChangedHdl( LINK( this, ToolBarManager
, StateChanged
) );
216 m_pToolBar
->SetDataChangedHdl( LINK( this, ToolBarManager
, DataChanged
) );
217 m_pToolBar
->SetToolboxButtonSize( m_bSmallSymbols
? TOOLBOX_BUTTONSIZE_SMALL
: TOOLBOX_BUTTONSIZE_LARGE
);
219 // enables a menu for clipped items and customization
220 SvtCommandOptions aCmdOptions
;
221 sal_uInt16 nMenuType
= TOOLBOX_MENUTYPE_CLIPPEDITEMS
;
222 if ( !aCmdOptions
.Lookup( SvtCommandOptions::CMDOPTION_DISABLED
, OUString("CreateDialog")))
223 nMenuType
|= TOOLBOX_MENUTYPE_CUSTOMIZE
;
225 m_pToolBar
->SetCommandHdl( LINK( this, ToolBarManager
, Command
) );
226 m_pToolBar
->SetMenuType( nMenuType
);
227 m_pToolBar
->SetMenuButtonHdl( LINK( this, ToolBarManager
, MenuButton
) );
229 // set name for testtool, the useful part is after the last '/'
230 sal_Int32 idx
= rResourceName
.lastIndexOf('/');
231 idx
++; // will become 0 if '/' not found: use full string
232 OString
aHelpIdAsString( HELPID_PREFIX_TESTTOOL
);
233 OUString aToolbarName
= rResourceName
.copy( idx
);
234 aHelpIdAsString
+= OUStringToOString( aToolbarName
, RTL_TEXTENCODING_UTF8
);;
235 m_pToolBar
->SetHelpId( aHelpIdAsString
);
237 m_aAsyncUpdateControllersTimer
.SetTimeout( 50 );
238 m_aAsyncUpdateControllersTimer
.SetTimeoutHdl( LINK( this, ToolBarManager
, AsyncUpdateControllersHdl
) );
240 SvtMiscOptions().AddListenerLink( LINK( this, ToolBarManager
, MiscOptionsChanged
) );
243 ToolBarManager::~ToolBarManager()
245 assert(!m_aAsyncUpdateControllersTimer
.IsActive());
246 OSL_ASSERT( !m_pToolBar
);
247 OSL_ASSERT( !m_bAddedToTaskPaneList
);
250 void ToolBarManager::Destroy()
252 OSL_ASSERT( m_pToolBar
!= nullptr );
254 if ( m_bAddedToTaskPaneList
)
256 vcl::Window
* pWindow
= m_pToolBar
;
257 while ( pWindow
&& !pWindow
->IsSystemWindow() )
258 pWindow
= pWindow
->GetParent();
261 static_cast<SystemWindow
*>(pWindow
)->GetTaskPaneList()->RemoveWindow( m_pToolBar
);
262 m_bAddedToTaskPaneList
= false;
265 // Delete the additional add-ons data
266 for ( sal_uInt16 i
= 0; i
< m_pToolBar
->GetItemCount(); i
++ )
268 sal_uInt16 nItemId
= m_pToolBar
->GetItemId( i
);
270 delete static_cast< AddonsParams
* >( m_pToolBar
->GetItemData( nItemId
));
273 // Hide toolbar as lazy delete can destroy the toolbar much later.
275 /* #i99167# removed change for i93173 since there is some weird crash */
276 // #i93173# delete toolbar lazily as we can still be in one of its handlers
277 m_pToolBar
->doLazyDelete();
279 m_pToolBar
->SetSelectHdl( Link
<ToolBox
*, void>() );
280 m_pToolBar
->SetActivateHdl( Link
<ToolBox
*, void>() );
281 m_pToolBar
->SetDeactivateHdl( Link
<ToolBox
*, void>() );
282 m_pToolBar
->SetClickHdl( Link
<ToolBox
*, void>() );
283 m_pToolBar
->SetDropdownClickHdl( Link
<ToolBox
*, void>() );
284 m_pToolBar
->SetDoubleClickHdl( Link
<ToolBox
*, void>() );
285 m_pToolBar
->SetStateChangedHdl( Link
<StateChangedType
const *, void>() );
286 m_pToolBar
->SetDataChangedHdl( Link
<DataChangedEvent
const *, void>() );
287 m_pToolBar
->SetCommandHdl( Link
<CommandEvent
const *, void>() );
291 SvtMiscOptions().RemoveListenerLink( LINK( this, ToolBarManager
, MiscOptionsChanged
) );
294 ToolBox
* ToolBarManager::GetToolBar() const
300 void ToolBarManager::CheckAndUpdateImages()
303 bool bRefreshImages
= false;
305 SvtMiscOptions aMiscOptions
;
306 bool bCurrentSymbolsSmall
= !aMiscOptions
.AreCurrentSymbolsLarge();
307 if ( m_bSmallSymbols
!= bCurrentSymbolsSmall
)
309 bRefreshImages
= true;
310 m_bSmallSymbols
= bCurrentSymbolsSmall
;
313 const OUString
& sCurrentIconTheme
= aMiscOptions
.GetIconTheme();
314 if ( m_sIconTheme
!= sCurrentIconTheme
)
316 bRefreshImages
= true;
317 m_sIconTheme
= sCurrentIconTheme
;
320 // Refresh images if requested
321 if ( bRefreshImages
)
325 void ToolBarManager::RefreshImages()
329 bool bBigImages( SvtMiscOptions().AreCurrentSymbolsLarge() );
330 for ( sal_uInt16 nPos
= 0; nPos
< m_pToolBar
->GetItemCount(); nPos
++ )
332 sal_uInt16
nId( m_pToolBar
->GetItemId( nPos
) );
336 OUString aCommandURL
= m_pToolBar
->GetItemCommand( nId
);
337 Image aImage
= GetImageFromURL( m_xFrame
, aCommandURL
, bBigImages
);
338 // Try also to query for add-on images before giving up and use an
341 aImage
= QueryAddonsImage( aCommandURL
, bBigImages
);
342 m_pToolBar
->SetItemImage( nId
, aImage
);
346 m_pToolBar
->SetToolboxButtonSize( bBigImages
? TOOLBOX_BUTTONSIZE_LARGE
: TOOLBOX_BUTTONSIZE_SMALL
);
347 ::Size aSize
= m_pToolBar
->CalcWindowSizePixel();
348 m_pToolBar
->SetOutputSizePixel( aSize
);
351 void ToolBarManager::UpdateImageOrientation()
355 if ( m_xUICommandLabels
.is() )
358 Sequence
< OUString
> aSeqMirrorCmd
;
359 Sequence
< OUString
> aSeqRotateCmd
;
360 m_xUICommandLabels
->getByName(
361 OUString( UICOMMANDDESCRIPTION_NAMEACCESS_COMMANDMIRRORIMAGELIST
)) >>= aSeqMirrorCmd
;
362 m_xUICommandLabels
->getByName(
363 OUString( UICOMMANDDESCRIPTION_NAMEACCESS_COMMANDROTATEIMAGELIST
)) >>= aSeqRotateCmd
;
365 CommandToInfoMap::iterator pIter
;
366 for ( i
= 0; i
< aSeqMirrorCmd
.getLength(); i
++ )
368 OUString aMirrorCmd
= aSeqMirrorCmd
[i
];
369 pIter
= m_aCommandMap
.find( aMirrorCmd
);
370 if ( pIter
!= m_aCommandMap
.end() )
371 pIter
->second
.bMirrored
= true;
373 for ( i
= 0; i
< aSeqRotateCmd
.getLength(); i
++ )
375 OUString aRotateCmd
= aSeqRotateCmd
[i
];
376 pIter
= m_aCommandMap
.find( aRotateCmd
);
377 if ( pIter
!= m_aCommandMap
.end() )
378 pIter
->second
.bRotated
= true;
382 for ( sal_uInt16 nPos
= 0; nPos
< m_pToolBar
->GetItemCount(); nPos
++ )
384 sal_uInt16 nId
= m_pToolBar
->GetItemId( nPos
);
387 OUString aCmd
= m_pToolBar
->GetItemCommand( nId
);
389 CommandToInfoMap::const_iterator pIter
= m_aCommandMap
.find( aCmd
);
390 if ( pIter
!= m_aCommandMap
.end() )
392 if ( pIter
->second
.bRotated
)
394 m_pToolBar
->SetItemImageMirrorMode( nId
, false );
395 m_pToolBar
->SetItemImageAngle( nId
, m_lImageRotation
);
397 if ( pIter
->second
.bMirrored
)
399 m_pToolBar
->SetItemImageMirrorMode( nId
, m_bImageMirrored
);
406 void ToolBarManager::UpdateControllers()
409 if( SvtMiscOptions().DisableUICustomization() )
412 Reference
< XLayoutManager
> xLayoutManager
;
413 Reference
< XPropertySet
> xFramePropSet( m_xFrame
, UNO_QUERY
);
414 if ( xFramePropSet
.is() )
415 a
= xFramePropSet
->getPropertyValue("LayoutManager");
416 a
>>= xLayoutManager
;
417 Reference
< XDockableWindow
> xDockable( VCLUnoHelper::GetInterface( m_pToolBar
), UNO_QUERY
);
418 if ( xLayoutManager
.is() && xDockable
.is() )
420 ::com::sun::star::awt::Point aPoint
;
421 aPoint
.X
= aPoint
.Y
= SAL_MAX_INT32
;
422 xLayoutManager
->dockWindow( m_aResourceName
, DockingArea_DOCKINGAREA_DEFAULT
, aPoint
);
423 xLayoutManager
->lockWindow( m_aResourceName
);
427 if ( !m_bUpdateControllers
)
429 m_bUpdateControllers
= true;
430 ToolBarControllerMap::iterator pIter
= m_aControllerMap
.begin();
432 while ( pIter
!= m_aControllerMap
.end() )
436 Reference
< XUpdatable
> xUpdatable( pIter
->second
, UNO_QUERY
);
437 if ( xUpdatable
.is() )
438 xUpdatable
->update();
440 catch (const Exception
&)
446 m_bUpdateControllers
= false;
449 //for update toolbar controller via Support Visible
450 void ToolBarManager::UpdateController( ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XToolbarController
> xController
)
453 if ( !m_bUpdateControllers
)
455 m_bUpdateControllers
= true;
457 { if(xController
.is())
459 Reference
< XUpdatable
> xUpdatable( xController
, UNO_QUERY
);
460 if ( xUpdatable
.is() )
461 xUpdatable
->update();
464 catch (const Exception
&)
469 m_bUpdateControllers
= false;
472 void ToolBarManager::frameAction( const FrameActionEvent
& Action
)
473 throw ( RuntimeException
, std::exception
)
476 if ( Action
.Action
== FrameAction_CONTEXT_CHANGED
)
478 m_aAsyncUpdateControllersTimer
.Start();
482 void SAL_CALL
ToolBarManager::statusChanged( const ::com::sun::star::frame::FeatureStateEvent
& Event
)
483 throw ( ::com::sun::star::uno::RuntimeException
, std::exception
)
489 if ( Event
.FeatureURL
.Complete
== ".uno:ImageOrientation" )
491 SfxImageItem
aItem( 1, 0 );
492 aItem
.PutValue( Event
.State
);
494 m_lImageRotation
= aItem
.GetRotation();
495 m_bImageMirrored
= aItem
.IsMirrored();
496 UpdateImageOrientation();
500 void SAL_CALL
ToolBarManager::disposing( const EventObject
& Source
) throw ( RuntimeException
, std::exception
)
512 if ( m_xDocImageManager
.is() )
516 m_xDocImageManager
->removeConfigurationListener(
517 Reference
< XUIConfigurationListener
>(
518 static_cast< OWeakObject
* >( this ), UNO_QUERY
));
520 catch (const Exception
&)
525 if ( m_xModuleImageManager
.is() )
529 m_xModuleImageManager
->removeConfigurationListener(
530 Reference
< XUIConfigurationListener
>(
531 static_cast< OWeakObject
* >( this ), UNO_QUERY
));
533 catch (const Exception
&)
538 if ( m_xImageOrientationListener
.is() )
540 ImageOrientationListener
* pImageOrientation
=
541 static_cast<ImageOrientationListener
*>(m_xImageOrientationListener
.get());
542 pImageOrientation
->unbindListener();
543 m_xImageOrientationListener
.clear();
546 m_xDocImageManager
.clear();
547 m_xModuleImageManager
.clear();
549 if ( Source
.Source
== Reference
< XInterface
>( m_xFrame
, UNO_QUERY
))
557 void SAL_CALL
ToolBarManager::dispose() throw( RuntimeException
, std::exception
)
559 Reference
< XComponent
> xThis( static_cast< OWeakObject
* >(this), UNO_QUERY
);
561 EventObject
aEvent( xThis
);
562 m_aListenerContainer
.disposeAndClear( aEvent
);
569 if ( m_xDocImageManager
.is() )
573 m_xDocImageManager
->removeConfigurationListener(
574 Reference
< XUIConfigurationListener
>(
575 static_cast< OWeakObject
* >( this ), UNO_QUERY
));
577 catch (const Exception
&)
581 m_xDocImageManager
.clear();
582 if ( m_xModuleImageManager
.is() )
586 m_xModuleImageManager
->removeConfigurationListener(
587 Reference
< XUIConfigurationListener
>(
588 static_cast< OWeakObject
* >( this ), UNO_QUERY
));
590 catch (const Exception
&)
594 m_xModuleImageManager
.clear();
596 ImplClearPopupMenu( m_pToolBar
);
598 // We have to destroy our toolbar instance now.
602 if ( m_bFrameActionRegistered
&& m_xFrame
.is() )
606 m_xFrame
->removeFrameActionListener( Reference
< XFrameActionListener
>(
607 static_cast< ::cppu::OWeakObject
*>( this ), UNO_QUERY
));
609 catch (const Exception
&)
614 if ( m_xImageOrientationListener
.is() )
616 ImageOrientationListener
* pImageOrientation
=
617 static_cast<ImageOrientationListener
*>(m_xImageOrientationListener
.get());
618 pImageOrientation
->unbindListener();
619 m_xImageOrientationListener
.clear();
624 Reference
< XComponent
> xCompGAM( m_xGlobalAcceleratorManager
, UNO_QUERY
);
627 m_xGlobalAcceleratorManager
.clear();
628 m_xModuleAcceleratorManager
.clear();
629 m_xDocAcceleratorManager
.clear();
631 // stop timer to prevent timer events after dispose
632 // do it last because other calls could restart timer in StateChanged()
633 m_aAsyncUpdateControllersTimer
.Stop();
639 void SAL_CALL
ToolBarManager::addEventListener( const Reference
< XEventListener
>& xListener
) throw( RuntimeException
, std::exception
)
643 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
645 throw DisposedException();
647 m_aListenerContainer
.addInterface( cppu::UnoType
<XEventListener
>::get(), xListener
);
650 void SAL_CALL
ToolBarManager::removeEventListener( const Reference
< XEventListener
>& xListener
) throw( RuntimeException
, std::exception
)
652 m_aListenerContainer
.removeInterface( cppu::UnoType
<XEventListener
>::get(), xListener
);
655 // XUIConfigurationListener
656 void SAL_CALL
ToolBarManager::elementInserted( const ::com::sun::star::ui::ConfigurationEvent
& Event
) throw (::com::sun::star::uno::RuntimeException
, std::exception
)
658 impl_elementChanged(false,Event
);
661 void SAL_CALL
ToolBarManager::elementRemoved( const ::com::sun::star::ui::ConfigurationEvent
& Event
) throw (::com::sun::star::uno::RuntimeException
, std::exception
)
663 impl_elementChanged(true,Event
);
665 void ToolBarManager::impl_elementChanged(bool _bRemove
,const ::com::sun::star::ui::ConfigurationEvent
& Event
)
669 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
673 Reference
< XNameAccess
> xNameAccess
;
674 sal_Int16 nImageType
= sal_Int16();
675 sal_Int16 nCurrentImageType
= getImageTypeFromBools(
676 SvtMiscOptions().AreCurrentSymbolsLarge()
679 if (( Event
.aInfo
>>= nImageType
) &&
680 ( nImageType
== nCurrentImageType
) &&
681 ( Event
.Element
>>= xNameAccess
))
683 sal_Int16
nImageInfo( 1 );
684 Reference
< XInterface
> xIfacDocImgMgr( m_xDocImageManager
, UNO_QUERY
);
685 if ( xIfacDocImgMgr
== Event
.Source
)
688 Sequence
< OUString
> aSeq
= xNameAccess
->getElementNames();
689 for ( sal_Int32 i
= 0; i
< aSeq
.getLength(); i
++ )
691 CommandToInfoMap::iterator pIter
= m_aCommandMap
.find( aSeq
[i
] );
692 if ( pIter
!= m_aCommandMap
.end() && ( pIter
->second
.nImageInfo
>= nImageInfo
))
697 if (( pIter
->second
.nImageInfo
== 0 ) && ( pIter
->second
.nImageInfo
== nImageInfo
))
699 // Special case: An image from the document image manager has been removed.
700 // It is possible that we have a image at our module image manager. Before
701 // we can remove our image we have to ask our module image manager.
702 Sequence
< OUString
> aCmdURLSeq( 1 );
703 Sequence
< Reference
< XGraphic
> > aGraphicSeq
;
704 aCmdURLSeq
[0] = pIter
->first
;
705 aGraphicSeq
= m_xModuleImageManager
->getImages( nImageType
, aCmdURLSeq
);
706 aImage
= Image( aGraphicSeq
[0] );
709 setToolBarImage(aImage
,pIter
);
713 Reference
< XGraphic
> xGraphic
;
714 if ( xNameAccess
->getByName( aSeq
[i
] ) >>= xGraphic
)
716 Image
aImage( xGraphic
);
717 setToolBarImage(aImage
,pIter
);
719 pIter
->second
.nImageInfo
= nImageInfo
;
725 void ToolBarManager::setToolBarImage(const Image
& _aImage
,const CommandToInfoMap::const_iterator
& _pIter
)
727 const ::std::vector
< sal_uInt16
>& _rIDs
= _pIter
->second
.aIds
;
728 m_pToolBar
->SetItemImage( _pIter
->second
.nId
, _aImage
);
729 ::std::for_each(_rIDs
.begin(),_rIDs
.end(),::boost::bind(&ToolBox::SetItemImage
,m_pToolBar
.get(),_1
,_aImage
));
732 void SAL_CALL
ToolBarManager::elementReplaced( const ::com::sun::star::ui::ConfigurationEvent
& Event
) throw (::com::sun::star::uno::RuntimeException
, std::exception
)
734 impl_elementChanged(false,Event
);
737 void ToolBarManager::RemoveControllers()
744 m_aSubToolBarControllerMap
.clear();
747 // Remove item window pointers from the toolbar. They were
748 // destroyed by the dispose() at the XComponent. This is needed
749 // as VCL code later tries to access the item window data in certain
750 // dtors where the item window is already invalid!
751 for ( sal_uInt16 i
= 0; i
< m_pToolBar
->GetItemCount(); i
++ )
753 sal_uInt16 nItemId
= m_pToolBar
->GetItemId( i
);
756 Reference
< XComponent
> xComponent( m_aControllerMap
[ nItemId
], UNO_QUERY
);
757 if ( xComponent
.is() )
761 xComponent
->dispose();
763 catch (const Exception
&)
767 m_pToolBar
->SetItemWindow(nItemId
, 0);
770 m_aControllerMap
.clear();
773 uno::Sequence
< beans::PropertyValue
> ToolBarManager::GetPropsForCommand( const OUString
& rCmdURL
)
775 Sequence
< PropertyValue
> aPropSeq
;
777 // Retrieve properties for command
780 if ( !m_bModuleIdentified
)
782 Reference
< XModuleManager2
> xModuleManager
= ModuleManager::create( m_xContext
);
783 Reference
< XInterface
> xIfac( m_xFrame
, UNO_QUERY
);
785 m_bModuleIdentified
= true;
786 m_aModuleIdentifier
= xModuleManager
->identify( xIfac
);
788 if ( !m_aModuleIdentifier
.isEmpty() )
790 Reference
< XNameAccess
> xNameAccess
= frame::theUICommandDescription::get( m_xContext
);
791 xNameAccess
->getByName( m_aModuleIdentifier
) >>= m_xUICommandLabels
;
795 if ( m_xUICommandLabels
.is() )
797 if ( !rCmdURL
.isEmpty() )
798 m_xUICommandLabels
->getByName( rCmdURL
) >>= aPropSeq
;
801 catch (const Exception
&)
808 OUString
ToolBarManager::RetrieveLabelFromCommand( const OUString
& aCmdURL
)
811 Sequence
< PropertyValue
> aPropSeq
;
813 // Retrieve popup menu labels
814 aPropSeq
= GetPropsForCommand( aCmdURL
);
815 for ( sal_Int32 i
= 0; i
< aPropSeq
.getLength(); i
++ )
817 if ( aPropSeq
[i
].Name
== "Name" )
819 aPropSeq
[i
].Value
>>= aLabel
;
826 sal_Int32
ToolBarManager::RetrievePropertiesFromCommand( const OUString
& aCmdURL
)
828 sal_Int32
nProperties(0);
829 Sequence
< PropertyValue
> aPropSeq
;
831 // Retrieve popup menu labels
832 aPropSeq
= GetPropsForCommand( aCmdURL
);
833 for ( sal_Int32 i
= 0; i
< aPropSeq
.getLength(); i
++ )
835 if ( aPropSeq
[i
].Name
== "Properties" )
837 aPropSeq
[i
].Value
>>= nProperties
;
844 void ToolBarManager::CreateControllers()
847 Reference
< XWindow
> xToolbarWindow
= VCLUnoHelper::GetInterface( m_pToolBar
);
850 bool bHasDisabledEntries
= SvtCommandOptions().HasEntries( SvtCommandOptions::CMDOPTION_DISABLED
);
851 SvtCommandOptions aCmdOptions
;
853 for ( sal_uInt16 i
= 0; i
< m_pToolBar
->GetItemCount(); i
++ )
855 sal_uInt16 nId
= m_pToolBar
->GetItemId( i
);
859 OUString
aLoadURL( ".uno:OpenUrl" );
860 OUString
aCommandURL( m_pToolBar
->GetItemCommand( nId
));
862 bool bCreate( true );
863 Reference
< XStatusListener
> xController
;
864 CommandToInfoMap::iterator pCommandIter
= m_aCommandMap
.find( aCommandURL
);
865 sal_Int16 nWidth
= ( pCommandIter
!= m_aCommandMap
.end() ? pCommandIter
->second
.nWidth
: 0 );
867 svt::ToolboxController
* pController( 0 );
869 if ( bHasDisabledEntries
)
871 aURL
.Complete
= aCommandURL
;
872 m_xURLTransformer
->parseStrict( aURL
);
873 if ( aCmdOptions
.Lookup( SvtCommandOptions::CMDOPTION_DISABLED
, aURL
.Path
))
875 m_aControllerMap
[ nId
] = xController
;
876 m_pToolBar
->HideItem( nId
);
881 if ( m_xToolbarControllerFactory
.is() &&
882 m_xToolbarControllerFactory
->hasController( aCommandURL
, m_aModuleIdentifier
))
884 PropertyValue aPropValue
;
885 std::vector
< Any
> aPropertyVector
;
887 aPropValue
.Name
= "ModuleIdentifier";
888 aPropValue
.Value
<<= m_aModuleIdentifier
;
889 aPropertyVector
.push_back( makeAny( aPropValue
));
890 aPropValue
.Name
= "Frame";
891 aPropValue
.Value
<<= m_xFrame
;
892 aPropertyVector
.push_back( makeAny( aPropValue
));
893 aPropValue
.Name
= "ServiceManager";
894 Reference
<XMultiServiceFactory
> xMSF(m_xContext
->getServiceManager(), UNO_QUERY_THROW
);
895 aPropValue
.Value
<<= xMSF
;
896 aPropertyVector
.push_back( makeAny( aPropValue
));
897 aPropValue
.Name
= "ParentWindow";
898 aPropValue
.Value
<<= xToolbarWindow
;
899 aPropertyVector
.push_back( makeAny( aPropValue
));
900 aPropValue
.Name
= "Identifier";
901 aPropValue
.Value
= uno::makeAny( nId
);
902 aPropertyVector
.push_back( uno::makeAny( aPropValue
) );
906 aPropValue
.Name
= "Width";
907 aPropValue
.Value
<<= nWidth
;
908 aPropertyVector
.push_back( makeAny( aPropValue
));
911 Sequence
< Any
> aArgs( comphelper::containerToSequence( aPropertyVector
));
912 xController
= Reference
< XStatusListener
>( m_xToolbarControllerFactory
->createInstanceWithArgumentsAndContext(
913 aCommandURL
, aArgs
, m_xContext
),
915 bInit
= false; // Initialization is done through the factory service
918 if (( aCommandURL
== aLoadURL
) && ( !m_pToolBar
->IsItemVisible(nId
)))
921 if ( !xController
.is() && bCreate
)
923 pController
= CreateToolBoxController( m_xFrame
, m_pToolBar
, nId
, aCommandURL
);
926 if ( m_pToolBar
->GetItemData( nId
) != 0 )
928 // retrieve additional parameters
929 OUString aControlType
= static_cast< AddonsParams
* >( m_pToolBar
->GetItemData( nId
))->aControlType
;
931 Reference
< XStatusListener
> xStatusListener(
932 ToolBarMerger::CreateController( m_xContext
,
938 aControlType
), UNO_QUERY
);
940 xController
= xStatusListener
;
944 MenuDescriptionMap::iterator it
= m_aMenuMap
.find( nId
);
945 if ( it
== m_aMenuMap
.end() )
947 xController
= Reference
< XStatusListener
>(
948 new GenericToolbarController( m_xContext
, m_xFrame
, m_pToolBar
, nId
, aCommandURL
));
950 // Accessibility support: Set toggle button role for specific commands
951 sal_Int32 nProps
= RetrievePropertiesFromCommand( aCommandURL
);
952 if ( nProps
& UICOMMANDDESCRIPTION_PROPERTIES_TOGGLEBUTTON
)
953 m_pToolBar
->SetItemBits( nId
, m_pToolBar
->GetItemBits( nId
) | ToolBoxItemBits::CHECKABLE
);
956 xController
= Reference
< XStatusListener
>(
957 new MenuToolbarController( m_xContext
, m_xFrame
, m_pToolBar
, nId
, aCommandURL
, m_aModuleIdentifier
, m_aMenuMap
[ nId
] ));
960 else if ( pController
)
962 xController
= Reference
< XStatusListener
>( static_cast< ::cppu::OWeakObject
*>( pController
), UNO_QUERY
);
966 // Associate ID and controller to be able to retrieve
967 // the controller from the ID later.
968 m_aControllerMap
[ nId
] = xController
;
970 // Fill sub-toolbars into our hash-map
971 Reference
< XSubToolbarController
> xSubToolBar( xController
, UNO_QUERY
);
972 if ( xSubToolBar
.is() && xSubToolBar
->opensSubToolbar() )
974 OUString aSubToolBarName
= xSubToolBar
->getSubToolbarName();
975 if ( !aSubToolBarName
.isEmpty() )
977 SubToolBarToSubToolBarControllerMap::iterator pIter
=
978 m_aSubToolBarControllerMap
.find( aSubToolBarName
);
979 if ( pIter
== m_aSubToolBarControllerMap
.end() )
981 SubToolBarControllerVector aSubToolBarVector
;
982 aSubToolBarVector
.push_back( xSubToolBar
);
983 m_aSubToolBarControllerMap
.insert(
984 SubToolBarToSubToolBarControllerMap::value_type(
985 aSubToolBarName
, aSubToolBarVector
));
988 pIter
->second
.push_back( xSubToolBar
);
992 Reference
< XInitialization
> xInit( xController
, UNO_QUERY
);
997 PropertyValue aPropValue
;
998 std::vector
< Any
> aPropertyVector
;
1000 aPropValue
.Name
= "Frame";
1001 aPropValue
.Value
<<= m_xFrame
;
1002 aPropertyVector
.push_back( makeAny( aPropValue
));
1003 aPropValue
.Name
= "CommandURL";
1004 aPropValue
.Value
<<= aCommandURL
;
1005 aPropertyVector
.push_back( makeAny( aPropValue
));
1006 aPropValue
.Name
= "ServiceManager";
1007 Reference
<XMultiServiceFactory
> xMSF(m_xContext
->getServiceManager(), UNO_QUERY_THROW
);
1008 aPropValue
.Value
<<= xMSF
;
1009 aPropertyVector
.push_back( makeAny( aPropValue
));
1010 aPropValue
.Name
= "ParentWindow";
1011 aPropValue
.Value
<<= xToolbarWindow
;
1012 aPropertyVector
.push_back( makeAny( aPropValue
));
1013 aPropValue
.Name
= "ModuleIdentifier";
1014 aPropValue
.Value
<<= m_aModuleIdentifier
;
1015 aPropertyVector
.push_back( makeAny( aPropValue
));
1016 aPropValue
.Name
= "Identifier";
1017 aPropValue
.Value
= uno::makeAny( nId
);
1018 aPropertyVector
.push_back( uno::makeAny( aPropValue
) );
1022 aPropValue
.Name
= "Width";
1023 aPropValue
.Value
<<= nWidth
;
1024 aPropertyVector
.push_back( makeAny( aPropValue
));
1027 Sequence
< Any
> aArgs( comphelper::containerToSequence( aPropertyVector
));
1028 xInit
->initialize( aArgs
);
1032 if(aCommandURL
== ".uno:SwitchXFormsDesignMode" ||
1033 aCommandURL
== ".uno:ViewDataSourceBrowser" ||
1034 aCommandURL
== ".uno:ParaLeftToRight" ||
1035 aCommandURL
== ".uno:ParaRightToLeft"
1037 pController
->setFastPropertyValue_NoBroadcast(1,makeAny(sal_True
));
1041 // Request a item window from the toolbar controller and set it at the VCL toolbar
1042 Reference
< XToolbarController
> xTbxController( xController
, UNO_QUERY
);
1043 if ( xTbxController
.is() && xToolbarWindow
.is() )
1045 Reference
< XWindow
> xWindow
= xTbxController
->createItemWindow( xToolbarWindow
);
1048 vcl::Window
* pItemWin
= VCLUnoHelper::GetWindow( xWindow
);
1051 WindowType nType
= pItemWin
->GetType();
1052 if ( nType
== WINDOW_LISTBOX
|| nType
== WINDOW_MULTILISTBOX
|| nType
== WINDOW_COMBOBOX
)
1053 pItemWin
->SetAccessibleName( m_pToolBar
->GetItemText( nId
) );
1054 m_pToolBar
->SetItemWindow( nId
, pItemWin
);
1060 //for update Controller via support visiable state
1061 Reference
< XPropertySet
> xPropSet( xController
, UNO_QUERY
);
1062 if ( xPropSet
.is() )
1066 bool bSupportVisible
= true;
1067 Any
a( xPropSet
->getPropertyValue("SupportsVisible") );
1068 a
>>= bSupportVisible
;
1069 if (bSupportVisible
)
1071 Reference
< XToolbarController
> xTbxController( xController
, UNO_QUERY
);
1072 UpdateController(xTbxController
);
1075 catch (const RuntimeException
&)
1079 catch (const Exception
&)
1085 AddFrameActionListener();
1086 AddImageOrientationListener();
1089 void ToolBarManager::AddFrameActionListener()
1091 if ( !m_bFrameActionRegistered
&& m_xFrame
.is() )
1093 m_bFrameActionRegistered
= true;
1094 m_xFrame
->addFrameActionListener( Reference
< XFrameActionListener
>(
1095 static_cast< ::cppu::OWeakObject
*>( this ), UNO_QUERY
));
1099 void ToolBarManager::AddImageOrientationListener()
1101 if ( !m_bImageOrientationRegistered
&& m_xFrame
.is() )
1103 m_bImageOrientationRegistered
= true;
1104 ImageOrientationListener
* pImageOrientation
= new ImageOrientationListener(
1105 Reference
< XStatusListener
>( static_cast< ::cppu::OWeakObject
*>( this ), UNO_QUERY
),
1108 m_xImageOrientationListener
= Reference
< XComponent
>( static_cast< ::cppu::OWeakObject
*>(
1109 pImageOrientation
), UNO_QUERY
);
1110 pImageOrientation
->addStatusListener(
1111 OUString( ".uno:ImageOrientation" ));
1112 pImageOrientation
->bindListener();
1116 ToolBoxItemBits
ToolBarManager::ConvertStyleToToolboxItemBits( sal_Int32 nStyle
)
1118 ToolBoxItemBits
nItemBits( ToolBoxItemBits::NONE
);
1119 if ( nStyle
& ::com::sun::star::ui::ItemStyle::RADIO_CHECK
)
1120 nItemBits
|= ToolBoxItemBits::RADIOCHECK
;
1121 if ( nStyle
& ::com::sun::star::ui::ItemStyle::ALIGN_LEFT
)
1122 nItemBits
|= ToolBoxItemBits::LEFT
;
1123 if ( nStyle
& ::com::sun::star::ui::ItemStyle::AUTO_SIZE
)
1124 nItemBits
|= ToolBoxItemBits::AUTOSIZE
;
1125 if ( nStyle
& ::com::sun::star::ui::ItemStyle::DROP_DOWN
)
1126 nItemBits
|= ToolBoxItemBits::DROPDOWN
;
1127 if ( nStyle
& ::com::sun::star::ui::ItemStyle::REPEAT
)
1128 nItemBits
|= ToolBoxItemBits::REPEAT
;
1129 if ( nStyle
& ::com::sun::star::ui::ItemStyle::DROPDOWN_ONLY
)
1130 nItemBits
|= ToolBoxItemBits::DROPDOWNONLY
;
1131 if ( nStyle
& ::com::sun::star::ui::ItemStyle::TEXT
)
1132 nItemBits
|= ToolBoxItemBits::TEXT_ONLY
;
1133 if ( nStyle
& ::com::sun::star::ui::ItemStyle::ICON
)
1134 nItemBits
|= ToolBoxItemBits::ICON_ONLY
;
1139 void ToolBarManager::FillToolbar( const Reference
< XIndexAccess
>& rItemContainer
)
1141 OString aTbxName
= OUStringToOString( m_aResourceName
, RTL_TEXTENCODING_ASCII_US
);
1142 SAL_INFO( "fwk.uielement", "framework (cd100003) ::ToolBarManager::FillToolbar " << aTbxName
.getStr() );
1149 sal_uInt16
nId( 1 );
1151 Reference
< XModuleManager2
> xModuleManager
= ModuleManager::create( m_xContext
);
1152 if ( !m_xDocImageManager
.is() )
1154 Reference
< XModel
> xModel( GetModelFromFrame() );
1157 Reference
< XUIConfigurationManagerSupplier
> xSupplier( xModel
, UNO_QUERY
);
1158 if ( xSupplier
.is() )
1160 m_xDocUICfgMgr
.set( xSupplier
->getUIConfigurationManager(), UNO_QUERY
);
1161 m_xDocImageManager
= Reference
< XImageManager
>( m_xDocUICfgMgr
->getImageManager(), UNO_QUERY
);
1162 m_xDocImageManager
->addConfigurationListener(
1163 Reference
< XUIConfigurationListener
>(
1164 static_cast< OWeakObject
* >( this ), UNO_QUERY
));
1171 m_aModuleIdentifier
= xModuleManager
->identify( Reference
< XInterface
>( m_xFrame
, UNO_QUERY
) );
1173 catch (const Exception
&)
1177 if ( !m_xModuleImageManager
.is() )
1179 Reference
< XModuleUIConfigurationManagerSupplier
> xModuleCfgMgrSupplier
=
1180 theModuleUIConfigurationManagerSupplier::get( m_xContext
);
1181 m_xUICfgMgr
= xModuleCfgMgrSupplier
->getUIConfigurationManager( m_aModuleIdentifier
);
1182 m_xModuleImageManager
= Reference
< XImageManager
>( m_xUICfgMgr
->getImageManager(), UNO_QUERY
);
1183 m_xModuleImageManager
->addConfigurationListener( Reference
< XUIConfigurationListener
>(
1184 static_cast< OWeakObject
* >( this ), UNO_QUERY
));
1187 RemoveControllers();
1189 // reset and fill command map
1190 m_pToolBar
->Clear();
1191 m_aControllerMap
.clear();
1192 m_aCommandMap
.clear();
1196 CommandInfo aCmdInfo
;
1197 for ( sal_Int32 n
= 0; n
< rItemContainer
->getCount(); n
++ )
1199 Sequence
< PropertyValue
> aProp
;
1200 OUString aCommandURL
;
1204 sal_uInt16
nType( ::com::sun::star::ui::ItemType::DEFAULT
);
1205 sal_uInt16
nWidth( 0 );
1206 sal_uInt32
nStyle( 0 );
1208 Reference
< XIndexAccess
> aMenuDesc
;
1211 if ( rItemContainer
->getByIndex( n
) >>= aProp
)
1213 bool bIsVisible( true );
1214 for ( int i
= 0; i
< aProp
.getLength(); i
++ )
1216 if ( aProp
[i
].Name
== ITEM_DESCRIPTOR_COMMANDURL
)
1218 aProp
[i
].Value
>>= aCommandURL
;
1219 if ( aCommandURL
.startsWith(MENUPREFIX
) )
1223 Reference
< XIndexAccess
> xMenuContainer
;
1224 if ( m_xDocUICfgMgr
.is() &&
1225 m_xDocUICfgMgr
->hasSettings( aCommandURL
) )
1226 xMenuContainer
= m_xDocUICfgMgr
->getSettings( aCommandURL
, sal_False
);
1227 if ( !xMenuContainer
.is() &&
1229 m_xUICfgMgr
->hasSettings( aCommandURL
) )
1230 xMenuContainer
= m_xUICfgMgr
->getSettings( aCommandURL
, sal_False
);
1231 if ( xMenuContainer
.is() && xMenuContainer
->getCount() )
1233 Sequence
< PropertyValue
> aProps
;
1234 // drop down menu info is currently
1235 // the first ( and only ) menu
1236 // in the menusettings container
1237 xMenuContainer
->getByIndex(0) >>= aProps
;
1238 for ( sal_Int32 index
=0; index
<aProps
.getLength(); ++index
)
1240 if ( aProps
[ index
].Name
== ITEM_DESCRIPTOR_CONTAINER
)
1243 aProps
[ index
].Value
>>= aMenuDesc
;
1249 catch (const Exception
&)
1254 else if ( aProp
[i
].Name
== ITEM_DESCRIPTOR_HELPURL
)
1255 aProp
[i
].Value
>>= aHelpURL
;
1256 else if ( aProp
[i
].Name
== ITEM_DESCRIPTOR_TOOLTIP
)
1257 aProp
[i
].Value
>>= aTooltip
;
1258 else if ( aProp
[i
].Name
== ITEM_DESCRIPTOR_LABEL
)
1259 aProp
[i
].Value
>>= aLabel
;
1260 else if ( aProp
[i
].Name
== ITEM_DESCRIPTOR_TYPE
)
1261 aProp
[i
].Value
>>= nType
;
1262 else if ( aProp
[i
].Name
== ITEM_DESCRIPTOR_VISIBLE
)
1263 aProp
[i
].Value
>>= bIsVisible
;
1264 else if ( aProp
[i
].Name
== ITEM_DESCRIPTOR_WIDTH
)
1265 aProp
[i
].Value
>>= nWidth
;
1266 else if ( aProp
[i
].Name
== ITEM_DESCRIPTOR_STYLE
)
1267 aProp
[i
].Value
>>= nStyle
;
1270 if (( nType
== ::com::sun::star::ui::ItemType::DEFAULT
) && !aCommandURL
.isEmpty() )
1272 OUString
aString( RetrieveLabelFromCommand( aCommandURL
));
1274 ToolBoxItemBits nItemBits
= ConvertStyleToToolboxItemBits( nStyle
);
1275 if ( aMenuDesc
.is() )
1277 m_aMenuMap
[ nId
] = aMenuDesc
;
1278 nItemBits
|= ToolBoxItemBits::DROPDOWNONLY
;
1280 m_pToolBar
->InsertItem( nId
, aString
, nItemBits
);
1281 m_pToolBar
->SetItemCommand( nId
, aCommandURL
);
1282 OUString
sQuickHelp( aString
);
1283 // Use custom tooltip if available
1284 if ( !aTooltip
.isEmpty() )
1285 sQuickHelp
= aTooltip
;
1287 if( RetrieveShortcut( aCommandURL
, sShortCut
) )
1290 sQuickHelp
+= sShortCut
;
1293 m_pToolBar
->SetQuickHelpText( nId
, sQuickHelp
);
1295 if ( !aLabel
.isEmpty() )
1297 m_pToolBar
->SetItemText( nId
, aLabel
);
1301 m_pToolBar
->SetItemText( nId
, aString
);
1303 m_pToolBar
->EnableItem( nId
, true );
1304 m_pToolBar
->SetItemState( nId
, TRISTATE_FALSE
);
1306 // Fill command map. It stores all our commands and from what
1307 // image manager we got our image. So we can decide if we have to use an
1308 // image from a notification message.
1309 CommandToInfoMap::iterator pIter
= m_aCommandMap
.find( aCommandURL
);
1310 if ( pIter
== m_aCommandMap
.end())
1313 aCmdInfo
.nWidth
= nWidth
;
1314 const CommandToInfoMap::value_type
aValue( aCommandURL
, aCmdInfo
);
1315 m_aCommandMap
.insert( aValue
);
1319 pIter
->second
.aIds
.push_back( nId
);
1323 m_pToolBar
->HideItem( nId
);
1327 else if ( nType
== ::com::sun::star::ui::ItemType::SEPARATOR_LINE
)
1329 m_pToolBar
->InsertSeparator();
1331 else if ( nType
== ::com::sun::star::ui::ItemType::SEPARATOR_SPACE
)
1333 m_pToolBar
->InsertSpace();
1335 else if ( nType
== ::com::sun::star::ui::ItemType::SEPARATOR_LINEBREAK
)
1337 m_pToolBar
->InsertBreak();
1341 catch (const ::com::sun::star::lang::IndexOutOfBoundsException
&)
1347 // Support add-on toolbar merging here. Working directly on the toolbar object is much
1348 // simpler and faster.
1349 const sal_uInt16 TOOLBAR_ITEM_STARTID
= 1000;
1351 MergeToolbarInstructionContainer aMergeInstructionContainer
;
1353 // Retrieve the toolbar name from the resource name
1354 OUString
aToolbarName( m_aResourceName
);
1355 sal_Int32 nIndex
= aToolbarName
.lastIndexOf( '/' );
1356 if (( nIndex
> 0 ) && ( nIndex
< aToolbarName
.getLength() ))
1357 aToolbarName
= aToolbarName
.copy( nIndex
+1 );
1359 AddonsOptions().GetMergeToolbarInstructions( aToolbarName
, aMergeInstructionContainer
);
1361 if ( !aMergeInstructionContainer
.empty() )
1363 sal_uInt16
nItemId( TOOLBAR_ITEM_STARTID
);
1364 const sal_uInt32 nCount
= aMergeInstructionContainer
.size();
1365 for ( sal_uInt32 i
=0; i
< nCount
; i
++ )
1367 MergeToolbarInstruction
& rInstruction
= aMergeInstructionContainer
[i
];
1368 if ( ToolBarMerger::IsCorrectContext( rInstruction
.aMergeContext
, m_aModuleIdentifier
))
1370 ReferenceToolbarPathInfo aRefPoint
= ToolBarMerger::FindReferencePoint( m_pToolBar
, rInstruction
.aMergePoint
);
1372 // convert the sequence< sequence< propertyvalue > > structure to
1373 // something we can better handle. A vector with item data
1374 AddonToolbarItemContainer aItems
;
1375 ToolBarMerger::ConvertSeqSeqToVector( rInstruction
.aMergeToolbarItems
, aItems
);
1377 if ( aRefPoint
.bResult
)
1379 ToolBarMerger::ProcessMergeOperation( m_xFrame
,
1384 m_aModuleIdentifier
,
1385 rInstruction
.aMergeCommand
,
1386 rInstruction
.aMergeCommandParameter
,
1391 ToolBarMerger::ProcessMergeFallback( m_xFrame
,
1396 m_aModuleIdentifier
,
1397 rInstruction
.aMergeCommand
,
1398 rInstruction
.aMergeFallback
,
1405 // Request images for all toolbar items. Must be done before CreateControllers as
1406 // some controllers need access to the image.
1409 // Create controllers after we set the images. There are controllers which needs
1410 // an image at the toolbar at creation time!
1411 CreateControllers();
1413 // Notify controllers that they are now correctly initialized and can start listening
1414 // toolbars that will open in popup mode will be updated immediately to avoid flickering
1415 if( m_pToolBar
->WillUsePopupMode() )
1416 UpdateControllers();
1417 else if ( m_pToolBar
->IsReallyVisible() )
1419 m_aAsyncUpdateControllersTimer
.Start();
1422 // Try to retrieve UIName from the container property set and set it as the title
1423 // if it is not empty.
1424 Reference
< XPropertySet
> xPropSet( rItemContainer
, UNO_QUERY
);
1425 if ( xPropSet
.is() )
1430 xPropSet
->getPropertyValue("UIName") >>= aUIName
;
1431 if ( !aUIName
.isEmpty() )
1432 m_pToolBar
->SetText( aUIName
);
1434 catch (const Exception
&)
1440 void ToolBarManager::RequestImages()
1443 // Request images from image manager
1444 Sequence
< OUString
> aCmdURLSeq( m_aCommandMap
.size() );
1445 Sequence
< Reference
< XGraphic
> > aDocGraphicSeq
;
1446 Sequence
< Reference
< XGraphic
> > aModGraphicSeq
;
1449 CommandToInfoMap::iterator pIter
= m_aCommandMap
.begin();
1450 CommandToInfoMap::iterator pEnd
= m_aCommandMap
.end();
1451 while ( pIter
!= pEnd
)
1453 aCmdURLSeq
[i
++] = pIter
->first
;
1457 bool bBigImages( SvtMiscOptions().AreCurrentSymbolsLarge() );
1458 sal_Int16 p
= getImageTypeFromBools( SvtMiscOptions().AreCurrentSymbolsLarge() );
1460 if ( m_xDocImageManager
.is() )
1461 aDocGraphicSeq
= m_xDocImageManager
->getImages( p
, aCmdURLSeq
);
1462 aModGraphicSeq
= m_xModuleImageManager
->getImages( p
, aCmdURLSeq
);
1465 pIter
= m_aCommandMap
.begin();
1466 while ( pIter
!= pEnd
)
1469 if ( aDocGraphicSeq
.getLength() > 0 )
1470 aImage
= Image( aDocGraphicSeq
[i
] );
1473 aImage
= Image( aModGraphicSeq
[i
] );
1474 // Try also to query for add-on images before giving up and use an
1477 aImage
= QueryAddonsImage( aCmdURLSeq
[i
], bBigImages
);
1479 pIter
->second
.nImageInfo
= 1; // mark image as module based
1483 pIter
->second
.nImageInfo
= 0; // mark image as document based
1485 setToolBarImage(aImage
,pIter
);
1491 void ToolBarManager::notifyRegisteredControllers( const OUString
& aUIElementName
, const OUString
& aCommand
)
1493 SolarMutexClearableGuard aGuard
;
1494 if ( !m_aSubToolBarControllerMap
.empty() )
1496 SubToolBarToSubToolBarControllerMap::const_iterator pIter
=
1497 m_aSubToolBarControllerMap
.find( aUIElementName
);
1499 if ( pIter
!= m_aSubToolBarControllerMap
.end() )
1501 const SubToolBarControllerVector
& rSubToolBarVector
= pIter
->second
;
1502 if ( !rSubToolBarVector
.empty() )
1504 SubToolBarControllerVector aNotifyVector
= rSubToolBarVector
;
1507 const sal_uInt32 nCount
= aNotifyVector
.size();
1508 for ( sal_uInt32 i
=0; i
< nCount
; i
++ )
1512 Reference
< XSubToolbarController
> xController
= aNotifyVector
[i
];
1513 if ( xController
.is() )
1514 xController
->functionSelected( aCommand
);
1516 catch (const RuntimeException
&)
1520 catch (const Exception
&)
1528 long ToolBarManager::HandleClick(void ( SAL_CALL
XToolbarController::*_pClick
)())
1535 sal_uInt16
nId( m_pToolBar
->GetCurItemId() );
1536 ToolBarControllerMap::const_iterator pIter
= m_aControllerMap
.find( nId
);
1537 if ( pIter
!= m_aControllerMap
.end() )
1539 Reference
< XToolbarController
> xController( pIter
->second
, UNO_QUERY
);
1541 if ( xController
.is() )
1542 (xController
.get()->*_pClick
)( );
1543 } // if ( pIter != m_aControllerMap.end() )
1547 IMPL_LINK_NOARG_TYPED(ToolBarManager
, Click
, ToolBox
*, void)
1549 HandleClick(&XToolbarController::click
);
1552 IMPL_LINK_NOARG_TYPED(ToolBarManager
, DropdownClick
, ToolBox
*, void)
1559 sal_uInt16
nId( m_pToolBar
->GetCurItemId() );
1560 ToolBarControllerMap::const_iterator pIter
= m_aControllerMap
.find( nId
);
1561 if ( pIter
!= m_aControllerMap
.end() )
1563 Reference
< XToolbarController
> xController( pIter
->second
, UNO_QUERY
);
1565 if ( xController
.is() )
1567 Reference
< XWindow
> xWin
= xController
->createPopupWindow();
1574 IMPL_LINK_NOARG_TYPED(ToolBarManager
, DoubleClick
, ToolBox
*, void)
1576 HandleClick(&XToolbarController::doubleClick
);
1579 void ToolBarManager::ImplClearPopupMenu( ToolBox
*pToolBar
)
1584 ::PopupMenu
*pMenu
= pToolBar
->GetMenu();
1586 // remove config entries from menu, so we have a clean menu to start with
1587 // remove submenu first
1588 ::PopupMenu
* pItemMenu
= pMenu
->GetPopupMenu( 1 );
1594 pMenu
->SetPopupMenu( 1, pItemMenu
);
1597 // remove all items that were not added by the toolbar itself
1599 for( i
=0; i
<pMenu
->GetItemCount(); )
1601 if( pMenu
->GetItemId( i
) < TOOLBOX_MENUITEM_START
1602 && pMenu
->GetItemId( i
) != 0 ) // Don't remove separators (Id == 0)
1603 pMenu
->RemoveItem( i
);
1609 IMPL_LINK_TYPED( ToolBarManager
, MenuDeactivate
, Menu
*, pMenu
, bool )
1616 if( pMenu
!= m_pToolBar
->GetMenu() )
1619 ImplClearPopupMenu( m_pToolBar
);
1624 Reference
< XModel
> ToolBarManager::GetModelFromFrame() const
1626 Reference
< XController
> xController
= m_xFrame
->getController();
1627 Reference
< XModel
> xModel
;
1628 if ( xController
.is() )
1629 xModel
= xController
->getModel();
1634 bool ToolBarManager::IsPluginMode() const
1636 bool bPluginMode( false );
1638 if ( m_xFrame
.is() )
1640 Reference
< XModel
> xModel
= GetModelFromFrame();
1643 Sequence
< PropertyValue
> aSeq
= xModel
->getArgs();
1644 utl::MediaDescriptor
aMediaDescriptor( aSeq
);
1645 bPluginMode
= aMediaDescriptor
.getUnpackedValueOrDefault(
1646 utl::MediaDescriptor::PROP_VIEWONLY(), false );
1653 bool ToolBarManager::MenuItemAllowed( sal_uInt16
) const
1658 ::PopupMenu
* ToolBarManager::GetToolBarCustomMenu(ToolBox
* pToolBar
)
1660 // update the list of hidden tool items first
1661 pToolBar
->UpdateCustomMenu();
1663 ::PopupMenu
*pMenu
= pToolBar
->GetMenu();
1664 // remove all entries before inserting new ones
1665 ImplClearPopupMenu( pToolBar
);
1666 // No config menu entries if command ".uno:ConfigureDialog" is not enabled
1667 Reference
< XDispatch
> xDisp
;
1668 com::sun::star::util::URL aURL
;
1669 if ( m_xFrame
.is() )
1671 Reference
< XDispatchProvider
> xProv( m_xFrame
, UNO_QUERY
);
1672 aURL
.Complete
= ".uno:ConfigureDialog";
1673 m_xURLTransformer
->parseStrict( aURL
);
1675 xDisp
= xProv
->queryDispatch( aURL
, OUString(), 0 );
1677 if ( !xDisp
.is() || IsPluginMode() )
1681 // popup menu for quick customization
1682 bool bHideDisabledEntries
= !SvtMenuOptions().IsEntryHidingEnabled();
1683 ::PopupMenu
aQuickCustomizationMenu( FwkResId( POPUPMENU_TOOLBAR_QUICKCUSTOMIZATION
));
1685 if ( m_pToolBar
->IsCustomize() )
1687 sal_uInt16
nPos( 0 );
1688 ::PopupMenu
* pVisibleItemsPopupMenu( aQuickCustomizationMenu
.GetPopupMenu( 1 ));
1690 bool bIsFloating( false );
1692 DockingManager
* pDockMgr
= vcl::Window::GetDockingManager();
1694 bIsFloating
= pDockMgr
->IsFloating( m_pToolBar
);
1698 aQuickCustomizationMenu
.EnableItem( MENUITEM_TOOLBAR_DOCKTOOLBAR
, false );
1699 aQuickCustomizationMenu
.EnableItem( MENUITEM_TOOLBAR_DOCKALLTOOLBAR
, false );
1700 Reference
< XDockableWindow
> xDockable( VCLUnoHelper::GetInterface( m_pToolBar
), UNO_QUERY
);
1701 if( xDockable
.is() )
1702 aQuickCustomizationMenu
.CheckItem( MENUITEM_TOOLBAR_LOCKTOOLBARPOSITION
, xDockable
->isLocked() );
1705 aQuickCustomizationMenu
.EnableItem( MENUITEM_TOOLBAR_LOCKTOOLBARPOSITION
, false );
1707 if ( SvtMiscOptions().DisableUICustomization() )
1709 aQuickCustomizationMenu
.EnableItem( MENUITEM_TOOLBAR_VISIBLEBUTTON
, false );
1710 aQuickCustomizationMenu
.EnableItem( MENUITEM_TOOLBAR_CUSTOMIZETOOLBAR
, false );
1711 aQuickCustomizationMenu
.EnableItem( MENUITEM_TOOLBAR_LOCKTOOLBARPOSITION
, false );
1714 // Disable menu item CLOSE if the toolbar has no closer
1715 if( !(pToolBar
->GetFloatStyle() & WB_CLOSEABLE
) )
1716 aQuickCustomizationMenu
.EnableItem(MENUITEM_TOOLBAR_CLOSE
, false);
1718 // Temporary stores a Command --> Url map to update contextual menu with the
1719 // correct icons. The popup icons are by default the same as those in the
1720 // toolbar. They are not correct for contextual popup menu.
1721 std::map
< OUString
, Image
> commandToImage
;
1723 // Go through all toolbar items and add them to the context menu
1724 for ( nPos
= 0; nPos
< m_pToolBar
->GetItemCount(); ++nPos
)
1726 if ( m_pToolBar
->GetItemType(nPos
) == ToolBoxItemType::BUTTON
)
1728 sal_uInt16 nId
= m_pToolBar
->GetItemId(nPos
);
1729 OUString aCommandURL
= m_pToolBar
->GetItemCommand( nId
);
1730 pVisibleItemsPopupMenu
->InsertItem( STARTID_CUSTOMIZE_POPUPMENU
+nPos
, m_pToolBar
->GetItemText( nId
), MenuItemBits::CHECKABLE
);
1731 pVisibleItemsPopupMenu
->CheckItem( STARTID_CUSTOMIZE_POPUPMENU
+nPos
, m_pToolBar
->IsItemVisible( nId
) );
1732 pVisibleItemsPopupMenu
->SetItemCommand( STARTID_CUSTOMIZE_POPUPMENU
+nPos
, aCommandURL
);
1733 Image
aImage( GetImageFromURL( m_xFrame
, aCommandURL
, false ) );
1734 commandToImage
[aCommandURL
] = aImage
;
1735 pVisibleItemsPopupMenu
->SetItemImage( STARTID_CUSTOMIZE_POPUPMENU
+nPos
, aImage
);
1739 pVisibleItemsPopupMenu
->InsertSeparator();
1743 // Now we go through all the contextual menu to update the icons
1744 std::map
< OUString
, Image
>::iterator it
;
1745 for ( nPos
= 0; nPos
< pMenu
->GetItemCount(); ++nPos
)
1747 sal_uInt16 nId
= pMenu
->GetItemId( nPos
);
1748 OUString cmdUrl
= pMenu
->GetItemCommand( nId
);
1749 it
= commandToImage
.find( cmdUrl
);
1750 if (it
!= commandToImage
.end()) {
1751 pMenu
->SetItemImage( nId
, it
->second
);
1757 sal_uInt16 nPos
= aQuickCustomizationMenu
.GetItemPos( MENUITEM_TOOLBAR_CUSTOMIZETOOLBAR
);
1758 if ( nPos
!= MENU_ITEM_NOTFOUND
)
1759 aQuickCustomizationMenu
.RemoveItem( nPos
);
1762 // copy all menu items 'Visible buttons, Customize toolbar, Dock toolbar,
1763 // Dock all Toolbars) from the loaded resource into the toolbar menu
1764 if( pMenu
->GetItemCount() )
1765 pMenu
->InsertSeparator();
1768 for( i
=0; i
< aQuickCustomizationMenu
.GetItemCount(); i
++)
1770 sal_uInt16 nId
= aQuickCustomizationMenu
.GetItemId( i
);
1771 if ( MenuItemAllowed( nId
))
1772 pMenu
->CopyItem( aQuickCustomizationMenu
, i
, MENU_APPEND
);
1775 // set submenu to toolbar menu
1776 if( aQuickCustomizationMenu
.GetPopupMenu( 1 ) )
1778 // create an own submenu to avoid auto-delete when resource menu is deleted
1779 ::PopupMenu
*pItemMenu
= new ::PopupMenu();
1781 for( i
=0; i
< aQuickCustomizationMenu
.GetPopupMenu( 1 )->GetItemCount(); i
++)
1782 pItemMenu
->CopyItem( *aQuickCustomizationMenu
.GetPopupMenu( 1 ), i
, MENU_APPEND
);
1784 pMenu
->SetPopupMenu( 1, pItemMenu
);
1787 // Set the title of the menu
1788 pMenu
->SetText( pToolBar
->GetText() );
1790 if ( bHideDisabledEntries
)
1791 pMenu
->RemoveDisabledEntries();
1796 IMPL_LINK_TYPED( ToolBarManager
, Command
, CommandEvent
const *, pCmdEvt
, void )
1802 if ( pCmdEvt
->GetCommand() != CommandEventId::ContextMenu
)
1805 ::PopupMenu
* pMenu
= GetToolBarCustomMenu(m_pToolBar
);
1808 // We only want to handle events for the context menu, but not events
1809 // on the toolbars overflow menu, hence we should only receive events
1810 // from the toolbox menu when we are actually showing it as our context
1811 // menu (the same menu retrieved with GetMenu() is reused for both the
1812 // overflow and context menus). If we set these Hdls permanently rather
1813 // than just when the context menu is showing, then events are duplicated
1814 // when the menu is being used as an overflow menu.
1815 Menu
*pManagerMenu
= m_pToolBar
->GetMenu();
1816 pManagerMenu
->SetSelectHdl( LINK( this, ToolBarManager
, MenuSelect
) );
1817 pManagerMenu
->SetDeactivateHdl( LINK( this, ToolBarManager
, MenuDeactivate
) );
1819 // make sure all disabled entries will be shown
1820 pMenu
->SetMenuFlags( pMenu
->GetMenuFlags() | MenuFlags::AlwaysShowDisabledEntries
);
1821 ::Point
aPoint( pCmdEvt
->GetMousePosPixel() );
1822 pMenu
->Execute( m_pToolBar
, aPoint
);
1824 //fdo#86820 We may have been disposed and so have a NULL m_pToolBar by
1825 //executing a menu entry, e.g. inserting a chart replaces the toolbars
1826 pManagerMenu
= m_bDisposed
? NULL
: m_pToolBar
->GetMenu();
1829 // Unlink our listeners again -- see above for why.
1830 pManagerMenu
->SetSelectHdl( Link
<>() );
1831 pManagerMenu
->SetDeactivateHdl( Link
<Menu
*, bool>() );
1836 IMPL_LINK_TYPED( ToolBarManager
, MenuButton
, ToolBox
*, pToolBar
, void )
1843 pToolBar
->UpdateCustomMenu();
1844 // remove all entries that do not come from the toolbar itself (fdo#38276)
1845 ImplClearPopupMenu( pToolBar
);
1848 IMPL_LINK( ToolBarManager
, MenuSelect
, Menu
*, pMenu
)
1850 // We have to hold a reference to ourself as it is possible that we will be disposed and
1851 // our refcount could be zero (destruction) otherwise.
1852 Reference
< XInterface
> xInterface( static_cast< OWeakObject
* >( this ), UNO_QUERY
);
1855 // The guard must be in its own context as the we can get destroyed when our
1856 // own xInterface reference get destroyed!
1862 switch ( pMenu
->GetCurItemId() )
1864 case MENUITEM_TOOLBAR_CUSTOMIZETOOLBAR
:
1866 Reference
< XDispatch
> xDisp
;
1867 com::sun::star::util::URL aURL
;
1868 if ( m_xFrame
.is() )
1870 Reference
< XDispatchProvider
> xProv( m_xFrame
, UNO_QUERY
);
1871 aURL
.Complete
= ".uno:ConfigureDialog";
1872 m_xURLTransformer
->parseStrict( aURL
);
1874 xDisp
= xProv
->queryDispatch( aURL
, OUString(), 0 );
1879 Sequence
< PropertyValue
> aPropSeq( 1 );
1881 aPropSeq
[ 0 ].Name
= "ResourceURL";
1882 aPropSeq
[ 0 ].Value
<<= m_aResourceName
;
1884 xDisp
->dispatch( aURL
, aPropSeq
);
1889 case MENUITEM_TOOLBAR_DOCKTOOLBAR
:
1891 ExecuteInfo
* pExecuteInfo
= new ExecuteInfo
;
1893 pExecuteInfo
->aToolbarResName
= m_aResourceName
;
1894 pExecuteInfo
->nCmd
= EXEC_CMD_DOCKTOOLBAR
;
1895 pExecuteInfo
->xLayoutManager
= getLayoutManagerFromFrame( m_xFrame
);
1897 Application::PostUserEvent( LINK(0, ToolBarManager
, ExecuteHdl_Impl
), pExecuteInfo
);
1901 case MENUITEM_TOOLBAR_DOCKALLTOOLBAR
:
1903 ExecuteInfo
* pExecuteInfo
= new ExecuteInfo
;
1905 pExecuteInfo
->aToolbarResName
= m_aResourceName
;
1906 pExecuteInfo
->nCmd
= EXEC_CMD_DOCKALLTOOLBARS
;
1907 pExecuteInfo
->xLayoutManager
= getLayoutManagerFromFrame( m_xFrame
);
1909 Application::PostUserEvent( LINK(0, ToolBarManager
, ExecuteHdl_Impl
), pExecuteInfo
);
1913 case MENUITEM_TOOLBAR_LOCKTOOLBARPOSITION
:
1915 Reference
< XLayoutManager
> xLayoutManager
= getLayoutManagerFromFrame( m_xFrame
);
1916 if ( xLayoutManager
.is() )
1918 Reference
< XDockableWindow
> xDockable( VCLUnoHelper::GetInterface( m_pToolBar
), UNO_QUERY
);
1920 if( xDockable
->isLocked() )
1921 xLayoutManager
->unlockWindow( m_aResourceName
);
1923 xLayoutManager
->lockWindow( m_aResourceName
);
1928 case MENUITEM_TOOLBAR_CLOSE
:
1930 ExecuteInfo
* pExecuteInfo
= new ExecuteInfo
;
1932 pExecuteInfo
->aToolbarResName
= m_aResourceName
;
1933 pExecuteInfo
->nCmd
= EXEC_CMD_CLOSETOOLBAR
;
1934 pExecuteInfo
->xLayoutManager
= getLayoutManagerFromFrame( m_xFrame
);
1935 pExecuteInfo
->xWindow
= VCLUnoHelper::GetInterface( m_pToolBar
);
1937 Application::PostUserEvent( LINK(0, ToolBarManager
, ExecuteHdl_Impl
), pExecuteInfo
);
1943 sal_uInt16 nId
= pMenu
->GetCurItemId();
1944 if(( nId
> 0 ) && ( nId
< TOOLBOX_MENUITEM_START
))
1945 // Items in the "enable/disable" sub-menu
1947 // toggle toolbar button visibility
1948 OUString aCommand
= pMenu
->GetItemCommand( nId
);
1950 Reference
< XLayoutManager
> xLayoutManager
= getLayoutManagerFromFrame( m_xFrame
);
1951 if ( xLayoutManager
.is() )
1953 Reference
< XUIElementSettings
> xUIElementSettings( xLayoutManager
->getElement( m_aResourceName
), UNO_QUERY
);
1954 if ( xUIElementSettings
.is() )
1956 Reference
< XIndexContainer
> xItemContainer( xUIElementSettings
->getSettings( sal_True
), UNO_QUERY
);
1957 sal_Int32 nCount
= xItemContainer
->getCount();
1958 for ( sal_Int32 i
= 0; i
< nCount
; i
++ )
1960 Sequence
< PropertyValue
> aProp
;
1961 sal_Int32
nVisibleIndex( -1 );
1962 OUString aCommandURL
;
1963 bool bVisible( false );
1965 if ( xItemContainer
->getByIndex( i
) >>= aProp
)
1967 for ( sal_Int32 j
= 0; j
< aProp
.getLength(); j
++ )
1969 if ( aProp
[j
].Name
== ITEM_DESCRIPTOR_COMMANDURL
)
1971 aProp
[j
].Value
>>= aCommandURL
;
1973 else if ( aProp
[j
].Name
== ITEM_DESCRIPTOR_VISIBLE
)
1975 aProp
[j
].Value
>>= bVisible
;
1980 if (( aCommandURL
== aCommand
) && ( nVisibleIndex
>= 0 ))
1982 // We have found the requested item, toggle the visible flag
1983 // and write back the configuration settings to the toolbar
1984 aProp
[nVisibleIndex
].Value
= makeAny( !bVisible
);
1987 xItemContainer
->replaceByIndex( i
, makeAny( aProp
));
1988 xUIElementSettings
->setSettings( xItemContainer
);
1989 Reference
< XPropertySet
> xPropSet( xUIElementSettings
, UNO_QUERY
);
1990 if ( xPropSet
.is() )
1992 Reference
< XUIConfigurationPersistence
> xUICfgMgr
;
1993 if (( xPropSet
->getPropertyValue("ConfigurationSource") >>= xUICfgMgr
) && ( xUICfgMgr
.is() ))
1997 catch (const Exception
&)
2009 // The list of "hidden items", i.e. items which are disabled on
2010 // the toolbar hence shown in the context menu for easier access,
2011 // which are managed by the owning toolbar.
2013 m_pToolBar
->TriggerItem( pMenu
->GetCurItemId()
2014 - TOOLBOX_MENUITEM_START
);
2020 // remove all entries - deactivate is not reliable
2021 // The method checks if we are already disposed and in that case does nothing!
2022 ImplClearPopupMenu( m_pToolBar
);
2028 IMPL_LINK_NOARG_TYPED(ToolBarManager
, Select
, ToolBox
*, void)
2033 sal_Int16
nKeyModifier( (sal_Int16
)m_pToolBar
->GetModifier() );
2034 sal_uInt16
nId( m_pToolBar
->GetCurItemId() );
2036 ToolBarControllerMap::const_iterator pIter
= m_aControllerMap
.find( nId
);
2037 if ( pIter
!= m_aControllerMap
.end() )
2039 Reference
< XToolbarController
> xController( pIter
->second
, UNO_QUERY
);
2041 if ( xController
.is() )
2042 xController
->execute( nKeyModifier
);
2046 IMPL_LINK_NOARG_TYPED(ToolBarManager
, Activate
, ToolBox
*, void)
2049 IMPL_LINK_NOARG_TYPED(ToolBarManager
, Deactivate
, ToolBox
*, void)
2052 IMPL_LINK_TYPED( ToolBarManager
, StateChanged
, StateChangedType
const *, pStateChangedType
, void )
2057 if ( *pStateChangedType
== StateChangedType::ControlBackground
)
2059 CheckAndUpdateImages();
2061 else if ( *pStateChangedType
== StateChangedType::Visible
)
2063 if ( m_pToolBar
->IsReallyVisible() )
2065 m_aAsyncUpdateControllersTimer
.Start();
2068 else if ( *pStateChangedType
== StateChangedType::InitShow
)
2070 m_aAsyncUpdateControllersTimer
.Start();
2074 IMPL_LINK_TYPED( ToolBarManager
, DataChanged
, DataChangedEvent
const *, pDataChangedEvent
, void )
2076 if ((( pDataChangedEvent
->GetType() == DataChangedEventType::SETTINGS
) ||
2077 ( pDataChangedEvent
->GetType() == DataChangedEventType::DISPLAY
)) &&
2078 ( pDataChangedEvent
->GetFlags() & AllSettingsFlags::STYLE
))
2080 CheckAndUpdateImages();
2083 for ( sal_uInt16 nPos
= 0; nPos
< m_pToolBar
->GetItemCount(); ++nPos
)
2085 const sal_uInt16 nId
= m_pToolBar
->GetItemId(nPos
);
2086 vcl::Window
* pWindow
= m_pToolBar
->GetItemWindow( nId
);
2089 const DataChangedEvent
& rDCEvt( *pDataChangedEvent
);
2090 pWindow
->DataChanged( rDCEvt
);
2094 if ( !m_pToolBar
->IsFloatingMode() &&
2095 m_pToolBar
->IsVisible() )
2097 // Resize toolbar, layout manager is resize listener and will calc
2098 // the layout automatically.
2099 ::Size
aSize( m_pToolBar
->CalcWindowSizePixel() );
2100 m_pToolBar
->SetOutputSizePixel( aSize
);
2104 IMPL_LINK_NOARG(ToolBarManager
, MiscOptionsChanged
)
2106 CheckAndUpdateImages();
2110 IMPL_LINK_NOARG_TYPED(ToolBarManager
, AsyncUpdateControllersHdl
, Timer
*, void)
2112 // The guard must be in its own context as the we can get destroyed when our
2113 // own xInterface reference get destroyed!
2114 Reference
< XComponent
> xThis( static_cast< OWeakObject
* >(this), UNO_QUERY
);
2121 // Request to update our controllers
2122 m_aAsyncUpdateControllersTimer
.Stop();
2123 UpdateControllers();
2126 IMPL_STATIC_LINK( ToolBarManager
, ExecuteHdl_Impl
, ExecuteInfo
*, pExecuteInfo
)
2130 // Asynchronous execution as this can lead to our own destruction!
2131 if (( pExecuteInfo
->nCmd
== EXEC_CMD_CLOSETOOLBAR
) &&
2132 ( pExecuteInfo
->xLayoutManager
.is() ) &&
2133 ( pExecuteInfo
->xWindow
.is() ))
2135 // Use docking window close to close the toolbar. The toolbar layout manager is
2136 // listener and will react correctly according to the context sensitive
2137 // flag of our toolbar.
2138 vcl::Window
* pWin
= VCLUnoHelper::GetWindow( pExecuteInfo
->xWindow
);
2139 DockingWindow
* pDockWin
= dynamic_cast< DockingWindow
* >( pWin
);
2143 else if (( pExecuteInfo
->nCmd
== EXEC_CMD_DOCKTOOLBAR
) &&
2144 ( pExecuteInfo
->xLayoutManager
.is() ))
2146 ::com::sun::star::awt::Point aPoint
;
2147 aPoint
.X
= aPoint
.Y
= SAL_MAX_INT32
;
2148 pExecuteInfo
->xLayoutManager
->dockWindow( pExecuteInfo
->aToolbarResName
,
2149 DockingArea_DOCKINGAREA_DEFAULT
,
2152 else if (( pExecuteInfo
->nCmd
== EXEC_CMD_DOCKALLTOOLBARS
) &&
2153 ( pExecuteInfo
->xLayoutManager
.is() ))
2155 pExecuteInfo
->xLayoutManager
->dockAllWindows( UIElementType::TOOLBAR
);
2158 catch (const Exception
&)
2162 delete pExecuteInfo
;
2166 Image
ToolBarManager::QueryAddonsImage( const OUString
& aCommandURL
, bool bBigImages
)
2168 Image aImage
= framework::AddonsOptions().GetImageFromURL( aCommandURL
, bBigImages
);
2172 bool ToolBarManager::impl_RetrieveShortcutsFromConfiguration(
2173 const Reference
< XAcceleratorConfiguration
>& rAccelCfg
,
2174 const OUString
& rCommand
,
2175 OUString
& rShortCut
)
2177 if ( rAccelCfg
.is() )
2181 com::sun::star::awt::KeyEvent aKeyEvent
;
2182 Sequence
< OUString
> aCommands(1);
2183 aCommands
[0] = rCommand
;
2185 Sequence
< Any
> aSeqKeyCode( rAccelCfg
->getPreferredKeyEventsForCommandList( aCommands
) );
2186 if( aSeqKeyCode
.getLength() == 1 )
2188 if ( aSeqKeyCode
[0] >>= aKeyEvent
)
2190 rShortCut
= svt::AcceleratorExecute::st_AWTKey2VCLKey( aKeyEvent
).GetName();
2195 catch (const IllegalArgumentException
&)
2203 bool ToolBarManager::RetrieveShortcut( const OUString
& rCommandURL
, OUString
& rShortCut
)
2205 if ( m_bModuleIdentified
)
2207 Reference
< XAcceleratorConfiguration
> xDocAccelCfg( m_xDocAcceleratorManager
);
2208 Reference
< XAcceleratorConfiguration
> xModuleAccelCfg( m_xModuleAcceleratorManager
);
2209 Reference
< XAcceleratorConfiguration
> xGlobalAccelCfg( m_xGlobalAcceleratorManager
);
2211 if ( !m_bAcceleratorCfg
)
2213 // Retrieve references on demand
2214 m_bAcceleratorCfg
= true;
2215 if ( !xDocAccelCfg
.is() )
2217 Reference
< XController
> xController
= m_xFrame
->getController();
2218 Reference
< XModel
> xModel
;
2219 if ( xController
.is() )
2221 xModel
= xController
->getModel();
2224 Reference
< XUIConfigurationManagerSupplier
> xSupplier( xModel
, UNO_QUERY
);
2225 if ( xSupplier
.is() )
2227 Reference
< XUIConfigurationManager
> xDocUICfgMgr( xSupplier
->getUIConfigurationManager(), UNO_QUERY
);
2228 if ( xDocUICfgMgr
.is() )
2230 xDocAccelCfg
= xDocUICfgMgr
->getShortCutManager();
2231 m_xDocAcceleratorManager
= xDocAccelCfg
;
2238 if ( !xModuleAccelCfg
.is() )
2240 Reference
< XModuleUIConfigurationManagerSupplier
> xModuleCfgMgrSupplier
=
2241 theModuleUIConfigurationManagerSupplier::get( m_xContext
);
2244 Reference
< XUIConfigurationManager
> xUICfgMgr
= xModuleCfgMgrSupplier
->getUIConfigurationManager( m_aModuleIdentifier
);
2245 if ( xUICfgMgr
.is() )
2247 xModuleAccelCfg
= xUICfgMgr
->getShortCutManager();
2248 m_xModuleAcceleratorManager
= xModuleAccelCfg
;
2251 catch (const RuntimeException
&)
2255 catch (const Exception
&)
2260 if ( !xGlobalAccelCfg
.is() ) try
2262 xGlobalAccelCfg
= GlobalAcceleratorConfiguration::create( m_xContext
);
2263 m_xGlobalAcceleratorManager
= xGlobalAccelCfg
;
2265 catch ( const css::uno::DeploymentException
& )
2267 SAL_WARN("fwk.uielement", "GlobalAcceleratorConfiguration"
2268 " not available. This should happen only on mobile platforms.");
2272 bool bFound
= false;
2274 if ( m_xGlobalAcceleratorManager
.is() )
2275 bFound
= impl_RetrieveShortcutsFromConfiguration( xGlobalAccelCfg
, rCommandURL
, rShortCut
);
2276 if ( !bFound
&& m_xModuleAcceleratorManager
.is() )
2277 bFound
= impl_RetrieveShortcutsFromConfiguration( xModuleAccelCfg
, rCommandURL
, rShortCut
);
2278 if ( !bFound
&& m_xDocAcceleratorManager
.is() )
2279 impl_RetrieveShortcutsFromConfiguration( xGlobalAccelCfg
, rCommandURL
, rShortCut
);
2289 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */