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