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