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/ui/XUIElementSettings.hpp> 68 #include <com/sun/star/ui/XUIConfigurationPersistence.hpp> 69 #include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp> 70 #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp> 71 #include <com/sun/star/ui/ImageType.hpp> 72 #include <com/sun/star/ui/UIElementType.hpp> 73 #include <comphelper/sequence.hxx> 74 #include <com/sun/star/frame/status/Visibility.hpp> 75 #include <com/sun/star/lang/DisposedException.hpp> 76 77 //_________________________________________________________________________________________________________________ 78 // other includes 79 //_________________________________________________________________________________________________________________ 80 #include <svtools/imgdef.hxx> 81 #include <svtools/toolboxcontroller.hxx> 82 #include <unotools/cmdoptions.hxx> 83 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_ 84 #include <toolkit/unohlp.hxx> 85 #endif 86 #include <comphelper/mediadescriptor.hxx> 87 #include <svtools/miscopt.hxx> 88 #include <svl/imageitm.hxx> 89 #include <svtools/framestatuslistener.hxx> 90 #include <vcl/svapp.hxx> 91 #include <vcl/menu.hxx> 92 #include <vcl/syswin.hxx> 93 #include <vcl/taskpanelist.hxx> 94 #include <rtl/logfile.hxx> 95 #include <svtools/menuoptions.hxx> 96 #include <unotools/cmdoptions.hxx> 97 #include <boost/bind.hpp> 98 #include <svtools/acceleratorexecute.hxx> 99 100 //_________________________________________________________________________________________________________________ 101 // namespaces 102 //_________________________________________________________________________________________________________________ 103 104 using rtl::OUString; 105 106 using namespace ::com::sun::star::awt; 107 using namespace ::com::sun::star::beans; 108 using namespace ::com::sun::star::uno; 109 using namespace ::com::sun::star::lang; 110 using namespace ::com::sun::star::frame; 111 using namespace ::com::sun::star::graphic; 112 using namespace ::com::sun::star::util; 113 using namespace ::com::sun::star::container; 114 using namespace ::com::sun::star::frame; 115 using namespace ::com::sun::star::ui; 116 using namespace ::com::sun::star; 117 118 namespace framework 119 { 120 121 static const char ITEM_DESCRIPTOR_COMMANDURL[] = "CommandURL"; 122 static const char ITEM_DESCRIPTOR_HELPURL[] = "HelpURL"; 123 static const char ITEM_DESCRIPTOR_TOOLTIP[] = "Tooltip"; 124 static const char ITEM_DESCRIPTOR_CONTAINER[] = "ItemDescriptorContainer"; 125 static const char ITEM_DESCRIPTOR_LABEL[] = "Label"; 126 static const char ITEM_DESCRIPTOR_TYPE[] = "Type"; 127 static const char ITEM_DESCRIPTOR_VISIBLE[] = "IsVisible"; 128 static const char ITEM_DESCRIPTOR_WIDTH[] = "Width"; 129 static const char ITEM_DESCRIPTOR_STYLE[] = "Style"; 130 131 static const sal_Int32 ITEM_DESCRIPTOR_COMMANDURL_LEN = 10; 132 static const sal_Int32 ITEM_DESCRIPTOR_HELPURL_LEN = 7; 133 static const sal_Int32 ITEM_DESCRIPTOR_TOOLTIP_LEN = 7; 134 static const sal_Int32 ITEM_DESCRIPTOR_CONTAINER_LEN = 23; 135 static const sal_Int32 ITEM_DESCRIPTOR_LABEL_LEN = 5; 136 static const sal_Int32 ITEM_DESCRIPTOR_TYPE_LEN = 4; 137 static const sal_Int32 ITEM_DESCRIPTOR_VISIBLE_LEN = 9; 138 static const sal_Int32 ITEM_DESCRIPTOR_WIDTH_LEN = 5; 139 static const sal_Int32 ITEM_DESCRIPTOR_STYLE_LEN = 5; 140 141 static const char HELPID_PREFIX[] = "helpid:"; 142 static const char HELPID_PREFIX_TESTTOOL[] = ".HelpId:"; 143 //static sal_Int32 HELPID_PREFIX_LENGTH = 7; 144 static const sal_uInt16 STARTID_CUSTOMIZE_POPUPMENU = 1000; 145 146 #define MENUPREFIX "private:resource/menubar/" 147 148 class ImageOrientationListener : public svt::FrameStatusListener 149 { 150 public: 151 ImageOrientationListener( const Reference< XStatusListener > rReceiver, 152 const Reference< XMultiServiceFactory > rServiceManager, 153 const Reference< XFrame > rFrame ); 154 virtual ~ImageOrientationListener(); 155 156 virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event ) throw ( ::com::sun::star::uno::RuntimeException ); 157 158 private: 159 Reference< XStatusListener > m_xReceiver; 160 }; 161 162 ImageOrientationListener::ImageOrientationListener( 163 const Reference< XStatusListener > rReceiver, 164 const Reference< XMultiServiceFactory > rServiceManager, 165 const Reference< XFrame > rFrame ) : 166 FrameStatusListener( rServiceManager, rFrame ), 167 m_xReceiver( rReceiver ) 168 { 169 } 170 171 ImageOrientationListener::~ImageOrientationListener() 172 { 173 } 174 175 void SAL_CALL ImageOrientationListener::statusChanged( const FeatureStateEvent& Event ) 176 throw ( RuntimeException ) 177 { 178 if ( m_xReceiver.is() ) 179 m_xReceiver->statusChanged( Event ); 180 } 181 182 //***************************************************************************************************************** 183 184 static sal_Int16 getImageTypeFromBools( sal_Bool bBig, sal_Bool bHighContrast ) 185 { 186 sal_Int16 n( 0 ); 187 if ( bBig ) 188 n |= ::com::sun::star::ui::ImageType::SIZE_LARGE; 189 if ( bHighContrast ) 190 n |= ::com::sun::star::ui::ImageType::COLOR_HIGHCONTRAST; 191 return n; 192 } 193 194 static ::com::sun::star::uno::Reference< ::com::sun::star::frame::XLayoutManager > getLayoutManagerFromFrame( 195 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame ) 196 { 197 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager; 198 199 Reference< XPropertySet > xPropSet( rFrame, UNO_QUERY ); 200 if ( xPropSet.is() ) 201 { 202 try 203 { 204 xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ))) >>= xLayoutManager; 205 } 206 catch ( RuntimeException& ) 207 { 208 throw; 209 } 210 catch ( Exception& ) 211 { 212 } 213 } 214 215 return xLayoutManager; 216 } 217 218 //***************************************************************************************************************** 219 // XInterface, XTypeProvider, XServiceInfo 220 //***************************************************************************************************************** 221 DEFINE_XINTERFACE_6 ( ToolBarManager , 222 OWeakObject , 223 DIRECT_INTERFACE( ::com::sun::star::lang::XTypeProvider ), 224 DIRECT_INTERFACE( ::com::sun::star::lang::XComponent ), 225 DIRECT_INTERFACE( ::com::sun::star::frame::XFrameActionListener ), 226 DIRECT_INTERFACE( ::com::sun::star::ui::XUIConfigurationListener ), 227 DIRECT_INTERFACE( ::com::sun::star::frame::XStatusListener ), 228 DERIVED_INTERFACE( ::com::sun::star::lang::XEventListener, ::com::sun::star::frame::XFrameActionListener ) 229 ) 230 231 DEFINE_XTYPEPROVIDER_6 ( ToolBarManager , 232 ::com::sun::star::lang::XTypeProvider , 233 ::com::sun::star::lang::XComponent , 234 ::com::sun::star::ui::XUIConfigurationListener , 235 ::com::sun::star::frame::XFrameActionListener , 236 ::com::sun::star::frame::XStatusListener , 237 ::com::sun::star::lang::XEventListener 238 ) 239 240 ToolBarManager::ToolBarManager( const Reference< XMultiServiceFactory >& rServiceManager, 241 const Reference< XFrame >& rFrame, 242 const rtl::OUString& rResourceName, 243 ToolBar* pToolBar ) : 244 ThreadHelpBase( &Application::GetSolarMutex() ), 245 OWeakObject(), 246 m_bDisposed( sal_False ), 247 m_bIsHiContrast( pToolBar->GetSettings().GetStyleSettings().GetHighContrastMode() ), 248 m_bSmallSymbols( !SvtMiscOptions().AreCurrentSymbolsLarge() ), 249 m_bModuleIdentified( sal_False ), 250 m_bAddedToTaskPaneList( sal_True ), 251 m_bFrameActionRegistered( sal_False ), 252 m_bUpdateControllers( sal_False ), 253 m_bImageOrientationRegistered( sal_False ), 254 m_bImageMirrored( sal_False ), 255 m_bCanBeCustomized( sal_True ), 256 m_lImageRotation( 0 ), 257 m_pToolBar( pToolBar ), 258 m_aResourceName( rResourceName ), 259 m_xFrame( rFrame ), 260 m_aListenerContainer( m_aLock.getShareableOslMutex() ), 261 m_xServiceManager( rServiceManager ), 262 m_nSymbolsStyle( SvtMiscOptions().GetCurrentSymbolsStyle() ), 263 m_bAcceleratorCfg( sal_False ) 264 { 265 Window* pWindow = m_pToolBar; 266 while ( pWindow && !pWindow->IsSystemWindow() ) 267 pWindow = pWindow->GetParent(); 268 269 if ( pWindow ) 270 ((SystemWindow *)pWindow)->GetTaskPaneList()->AddWindow( m_pToolBar ); 271 272 if ( m_xServiceManager.is() ) 273 { 274 m_xToolbarControllerRegistration = Reference< XUIControllerRegistration >( 275 m_xServiceManager->createInstance( SERVICENAME_TOOLBARCONTROLLERFACTORY ), 276 UNO_QUERY ); 277 278 m_xURLTransformer.set( m_xServiceManager->createInstance( 279 SERVICENAME_URLTRANSFORMER), 280 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 318 ToolBarManager::~ToolBarManager() 319 { 320 OSL_ASSERT( m_pToolBar == 0 ); 321 OSL_ASSERT( !m_bAddedToTaskPaneList ); 322 } 323 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 366 ToolBox* ToolBarManager::GetToolBar() const 367 { 368 ResetableGuard aGuard( m_aLock ); 369 return m_pToolBar; 370 } 371 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 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 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 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 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 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 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 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 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 m_xGlobalAcceleratorManager.clear(); 710 m_xModuleAcceleratorManager.clear(); 711 m_xDocAcceleratorManager.clear(); 712 713 m_bDisposed = sal_True; 714 } 715 } 716 717 void SAL_CALL ToolBarManager::addEventListener( const Reference< XEventListener >& xListener ) throw( RuntimeException ) 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 728 void SAL_CALL ToolBarManager::removeEventListener( const Reference< XEventListener >& xListener ) throw( RuntimeException ) 729 { 730 m_aListenerContainer.removeInterface( ::getCppuType( ( const Reference< XEventListener >* ) NULL ), xListener ); 731 } 732 733 // XUIConfigurationListener 734 void SAL_CALL ToolBarManager::elementInserted( const ::com::sun::star::ui::ConfigurationEvent& Event ) throw (::com::sun::star::uno::RuntimeException) 735 { 736 impl_elementChanged(false,Event); 737 } 738 739 void SAL_CALL ToolBarManager::elementRemoved( const ::com::sun::star::ui::ConfigurationEvent& Event ) throw (::com::sun::star::uno::RuntimeException) 740 { 741 impl_elementChanged(true,Event); 742 } 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 } 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 810 void SAL_CALL ToolBarManager::elementReplaced( const ::com::sun::star::ui::ConfigurationEvent& Event ) throw (::com::sun::star::uno::RuntimeException) 811 { 812 impl_elementChanged(false,Event); 813 } 814 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 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 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 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 924 void ToolBarManager::CreateControllers() 925 { 926 RTL_LOGFILE_CONTEXT( aLog, "framework (cd100003) ::ToolBarManager::CreateControllers" ); 927 928 Reference< XMultiComponentFactory > xToolbarControllerFactory( m_xToolbarControllerRegistration, UNO_QUERY ); 929 Reference< XComponentContext > xComponentContext; 930 Reference< XPropertySet > xProps( m_xServiceManager, UNO_QUERY ); 931 Reference< XWindow > xToolbarWindow = VCLUnoHelper::GetInterface( m_pToolBar ); 932 933 css::util::URL aURL; 934 sal_Bool bHasDisabledEntries = SvtCommandOptions().HasEntries( SvtCommandOptions::CMDOPTION_DISABLED ); 935 SvtCommandOptions aCmdOptions; 936 937 if ( xProps.is() ) 938 xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))) >>= xComponentContext; 939 940 for ( sal_uInt16 i = 0; i < m_pToolBar->GetItemCount(); i++ ) 941 { 942 sal_uInt16 nId = m_pToolBar->GetItemId( i ); 943 if ( nId == 0 ) 944 continue; 945 946 rtl::OUString aLoadURL( RTL_CONSTASCII_USTRINGPARAM( ".uno:OpenUrl" )); 947 rtl::OUString aCommandURL( m_pToolBar->GetItemCommand( nId )); 948 sal_Bool bInit( sal_True ); 949 sal_Bool bCreate( sal_True ); 950 Reference< XStatusListener > xController; 951 CommandToInfoMap::iterator pCommandIter = m_aCommandMap.find( aCommandURL ); 952 sal_Int16 nWidth = ( pCommandIter != m_aCommandMap.end() ? pCommandIter->second.nWidth : 0 ); 953 954 svt::ToolboxController* pController( 0 ); 955 956 if ( bHasDisabledEntries ) 957 { 958 aURL.Complete = aCommandURL; 959 m_xURLTransformer->parseStrict( aURL ); 960 if ( aCmdOptions.Lookup( SvtCommandOptions::CMDOPTION_DISABLED, aURL.Path )) 961 { 962 m_aControllerMap[ nId ] = xController; 963 m_pToolBar->HideItem( nId ); 964 continue; 965 } 966 } 967 968 if ( m_xToolbarControllerRegistration.is() && 969 m_xToolbarControllerRegistration->hasController( aCommandURL, m_aModuleIdentifier )) 970 { 971 if ( xToolbarControllerFactory.is() ) 972 { 973 PropertyValue aPropValue; 974 std::vector< Any > aPropertyVector; 975 976 aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ModuleName" )); 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 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 >( xToolbarControllerFactory->createInstanceWithArgumentsAndContext( 998 aCommandURL, aArgs, xComponentContext ), 999 UNO_QUERY ); 1000 bInit = sal_False; // Initialization is done through the factory service 1001 } 1002 } 1003 1004 if (( aCommandURL == aLoadURL ) && ( !m_pToolBar->IsItemVisible(nId))) 1005 bCreate = sal_False; 1006 1007 if ( !xController.is() && m_pToolBar && bCreate ) 1008 { 1009 pController = CreateToolBoxController( m_xFrame, m_pToolBar, nId, aCommandURL ); 1010 if ( !pController ) 1011 { 1012 if ( m_pToolBar->GetItemData( nId ) != 0 ) 1013 { 1014 // retrieve additional parameters 1015 ::rtl::OUString aControlType = static_cast< AddonsParams* >( m_pToolBar->GetItemData( nId ))->aControlType; 1016 1017 Reference< XStatusListener > xStatusListener( 1018 ToolBarMerger::CreateController( m_xServiceManager, 1019 m_xFrame, 1020 m_pToolBar, 1021 aCommandURL, 1022 nId, 1023 nWidth, 1024 aControlType ), UNO_QUERY ); 1025 1026 xController = xStatusListener; 1027 } 1028 else 1029 { 1030 MenuDescriptionMap::iterator it = m_aMenuMap.find( nId ); 1031 if ( it == m_aMenuMap.end() ) 1032 { 1033 xController = Reference< XStatusListener >( 1034 new GenericToolbarController( m_xServiceManager, m_xFrame, m_pToolBar, nId, aCommandURL )); 1035 1036 // Accessibility support: Set toggle button role for specific commands 1037 sal_Int32 nProps = RetrievePropertiesFromCommand( aCommandURL ); 1038 if ( nProps & UICOMMANDDESCRIPTION_PROPERTIES_TOGGLEBUTTON ) 1039 m_pToolBar->SetItemBits( nId, m_pToolBar->GetItemBits( nId ) | TIB_CHECKABLE ); 1040 } 1041 else 1042 xController = Reference< XStatusListener >( 1043 new MenuToolbarController( m_xServiceManager, m_xFrame, m_pToolBar, nId, aCommandURL, m_aModuleIdentifier, m_aMenuMap[ nId ] )); 1044 } 1045 } 1046 else if ( pController ) 1047 { 1048 xController = Reference< XStatusListener >( static_cast< ::cppu::OWeakObject *>( pController ), UNO_QUERY ); 1049 } 1050 } 1051 1052 // Associate ID and controller to be able to retrieve 1053 // the controller from the ID later. 1054 m_aControllerMap[ nId ] = xController; 1055 1056 // Fill sub-toolbars into our hash-map 1057 Reference< XSubToolbarController > xSubToolBar( xController, UNO_QUERY ); 1058 if ( xSubToolBar.is() && xSubToolBar->opensSubToolbar() ) 1059 { 1060 rtl::OUString aSubToolBarName = xSubToolBar->getSubToolbarName(); 1061 if ( aSubToolBarName.getLength() != 0 ) 1062 { 1063 SubToolBarToSubToolBarControllerMap::iterator pIter = 1064 m_aSubToolBarControllerMap.find( aSubToolBarName ); 1065 if ( pIter == m_aSubToolBarControllerMap.end() ) 1066 { 1067 SubToolBarControllerVector aSubToolBarVector; 1068 aSubToolBarVector.push_back( xSubToolBar ); 1069 m_aSubToolBarControllerMap.insert( 1070 SubToolBarToSubToolBarControllerMap::value_type( 1071 aSubToolBarName, aSubToolBarVector )); 1072 } 1073 else 1074 pIter->second.push_back( xSubToolBar ); 1075 } 1076 } 1077 1078 Reference< XInitialization > xInit( xController, UNO_QUERY ); 1079 if ( xInit.is() ) 1080 { 1081 if ( bInit ) 1082 { 1083 PropertyValue aPropValue; 1084 std::vector< Any > aPropertyVector; 1085 1086 aPropValue.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Frame" )); 1087 aPropValue.Value <<= m_xFrame; 1088 aPropertyVector.push_back( makeAny( aPropValue )); 1089 aPropValue.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CommandURL" )); 1090 aPropValue.Value <<= aCommandURL; 1091 aPropertyVector.push_back( makeAny( aPropValue )); 1092 aPropValue.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ServiceManager" )); 1093 aPropValue.Value <<= m_xServiceManager; 1094 aPropertyVector.push_back( makeAny( aPropValue )); 1095 aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ParentWindow" )); 1096 aPropValue.Value <<= xToolbarWindow; 1097 aPropertyVector.push_back( makeAny( aPropValue )); 1098 aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ModuleName" )); 1099 aPropValue.Value <<= m_aModuleIdentifier; 1100 aPropertyVector.push_back( makeAny( aPropValue )); 1101 1102 if ( nWidth > 0 ) 1103 { 1104 aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Width" )); 1105 aPropValue.Value <<= nWidth; 1106 aPropertyVector.push_back( makeAny( aPropValue )); 1107 } 1108 1109 Sequence< Any > aArgs( comphelper::containerToSequence( aPropertyVector )); 1110 xInit->initialize( aArgs ); 1111 //for Support Visiblitly by shizhoubo 1112 if (pController) 1113 { 1114 // rtl::OUString aCommandURL = pController->m_aCommandURL; 1115 if(aCommandURL == rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:SwitchXFormsDesignMode" )) || 1116 aCommandURL == rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ViewDataSourceBrowser" )) || 1117 aCommandURL == rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ParaLeftToRight" )) || 1118 aCommandURL == rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ParaRightToLeft" )) 1119 ) 1120 pController->setFastPropertyValue_NoBroadcast(1,makeAny(sal_True)); 1121 } 1122 1123 //end 1124 } 1125 1126 // Request a item window from the toolbar controller and set it at the VCL toolbar 1127 Reference< XToolbarController > xTbxController( xController, UNO_QUERY ); 1128 if ( xTbxController.is() && xToolbarWindow.is() ) 1129 { 1130 Reference< XWindow > xWindow = xTbxController->createItemWindow( xToolbarWindow ); 1131 if ( xWindow.is() ) 1132 { 1133 Window* pItemWin = VCLUnoHelper::GetWindow( xWindow ); 1134 if ( pItemWin ) 1135 { 1136 WindowType nType = pItemWin->GetType(); 1137 if ( nType == WINDOW_LISTBOX || nType == WINDOW_MULTILISTBOX || nType == WINDOW_COMBOBOX ) 1138 pItemWin->SetAccessibleName( m_pToolBar->GetItemText( nId ) ); 1139 m_pToolBar->SetItemWindow( nId, pItemWin ); 1140 } 1141 } 1142 } 1143 } 1144 //for update Controller via support visiable state by shizhoubo 1145 Reference< XPropertySet > xPropSet( xController, UNO_QUERY ); 1146 if ( xPropSet.is() ) 1147 { 1148 try 1149 { 1150 sal_Bool bSupportVisiable = sal_True; 1151 Any a( xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SupportsVisiable" ))) ); 1152 a >>= bSupportVisiable; 1153 if ( bSupportVisiable ) 1154 { 1155 Reference< XToolbarController > xTbxController( xController, UNO_QUERY ); 1156 UpdateController(xTbxController); 1157 } 1158 } 1159 catch ( RuntimeException& ) 1160 { 1161 throw; 1162 } 1163 catch ( Exception& ) 1164 { 1165 } 1166 } 1167 //end 1168 1169 } 1170 1171 AddFrameActionListener(); 1172 AddImageOrientationListener(); 1173 } 1174 1175 void ToolBarManager::AddFrameActionListener() 1176 { 1177 if ( !m_bFrameActionRegistered && m_xFrame.is() ) 1178 { 1179 m_bFrameActionRegistered = sal_True; 1180 m_xFrame->addFrameActionListener( Reference< XFrameActionListener >( 1181 static_cast< ::cppu::OWeakObject *>( this ), UNO_QUERY )); 1182 } 1183 } 1184 1185 void ToolBarManager::AddImageOrientationListener() 1186 { 1187 if ( !m_bImageOrientationRegistered && m_xFrame.is() ) 1188 { 1189 m_bImageOrientationRegistered = sal_True; 1190 ImageOrientationListener* pImageOrientation = new ImageOrientationListener( 1191 Reference< XStatusListener >( static_cast< ::cppu::OWeakObject *>( this ), UNO_QUERY ), 1192 m_xServiceManager, 1193 m_xFrame ); 1194 m_xImageOrientationListener = Reference< XComponent >( static_cast< ::cppu::OWeakObject *>( 1195 pImageOrientation ), UNO_QUERY ); 1196 pImageOrientation->addStatusListener( 1197 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ImageOrientation" ))); 1198 pImageOrientation->bindListener(); 1199 } 1200 } 1201 1202 sal_uInt16 ToolBarManager::ConvertStyleToToolboxItemBits( sal_Int32 nStyle ) 1203 { 1204 sal_uInt16 nItemBits( 0 ); 1205 if ( nStyle & ::com::sun::star::ui::ItemStyle::RADIO_CHECK ) 1206 nItemBits |= TIB_RADIOCHECK; 1207 if ( nStyle & ::com::sun::star::ui::ItemStyle::ALIGN_LEFT ) 1208 nItemBits |= TIB_LEFT; 1209 if ( nStyle & ::com::sun::star::ui::ItemStyle::AUTO_SIZE ) 1210 nItemBits |= TIB_AUTOSIZE; 1211 if ( nStyle & ::com::sun::star::ui::ItemStyle::DROP_DOWN ) 1212 nItemBits |= TIB_DROPDOWN; 1213 if ( nStyle & ::com::sun::star::ui::ItemStyle::REPEAT ) 1214 nItemBits |= TIB_REPEAT; 1215 if ( nStyle & ::com::sun::star::ui::ItemStyle::DROPDOWN_ONLY ) 1216 nItemBits |= TIB_DROPDOWNONLY; 1217 if ( nStyle & ::com::sun::star::ui::ItemStyle::TEXT ) 1218 nItemBits |= TIB_TEXT_ONLY; 1219 if ( nStyle & ::com::sun::star::ui::ItemStyle::ICON ) 1220 nItemBits |= TIB_ICON_ONLY; 1221 1222 return nItemBits; 1223 } 1224 1225 void ToolBarManager::FillToolbar( const Reference< XIndexAccess >& rItemContainer ) 1226 { 1227 ::rtl::OString aTbxName = rtl::OUStringToOString( m_aResourceName, RTL_TEXTENCODING_ASCII_US ); 1228 1229 RTL_LOGFILE_CONTEXT( aLog, "framework (cd100003) ::ToolBarManager::FillToolbar" ); 1230 RTL_LOGFILE_CONTEXT_TRACE1( aLog, "framework (cd100003) ::ToolBarManager::FillToolbar %s", aTbxName.getStr() ); 1231 1232 ResetableGuard aGuard( m_aLock ); 1233 1234 if ( m_bDisposed ) 1235 return; 1236 1237 sal_uInt16 nId( 1 ); 1238 ::rtl::OUString aHelpIdPrefix( RTL_CONSTASCII_USTRINGPARAM( HELPID_PREFIX )); 1239 1240 Reference< XModuleManager > xModuleManager( Reference< XModuleManager >( 1241 m_xServiceManager->createInstance( SERVICENAME_MODULEMANAGER ), UNO_QUERY )); 1242 if ( !m_xDocImageManager.is() ) 1243 { 1244 Reference< XModel > xModel( GetModelFromFrame() ); 1245 if ( xModel.is() ) 1246 { 1247 Reference< XUIConfigurationManagerSupplier > xSupplier( xModel, UNO_QUERY ); 1248 if ( xSupplier.is() ) 1249 { 1250 m_xDocUICfgMgr.set( xSupplier->getUIConfigurationManager(), UNO_QUERY ); 1251 m_xDocImageManager = Reference< XImageManager >( m_xDocUICfgMgr->getImageManager(), UNO_QUERY ); 1252 m_xDocImageManager->addConfigurationListener( 1253 Reference< XUIConfigurationListener >( 1254 static_cast< OWeakObject* >( this ), UNO_QUERY )); 1255 } 1256 } 1257 } 1258 1259 try 1260 { 1261 if ( xModuleManager.is() ) 1262 m_aModuleIdentifier = xModuleManager->identify( Reference< XInterface >( m_xFrame, UNO_QUERY ) ); 1263 } 1264 catch( Exception& ) 1265 { 1266 } 1267 1268 if ( !m_xModuleImageManager.is() ) 1269 { 1270 Reference< XModuleUIConfigurationManagerSupplier > xModuleCfgMgrSupplier( m_xServiceManager->createInstance( 1271 SERVICENAME_MODULEUICONFIGURATIONMANAGERSUPPLIER ), 1272 UNO_QUERY ); 1273 m_xUICfgMgr = xModuleCfgMgrSupplier->getUIConfigurationManager( m_aModuleIdentifier ); 1274 m_xModuleImageManager = Reference< XImageManager >( m_xUICfgMgr->getImageManager(), UNO_QUERY ); 1275 m_xModuleImageManager->addConfigurationListener( Reference< XUIConfigurationListener >( 1276 static_cast< OWeakObject* >( this ), UNO_QUERY )); 1277 } 1278 1279 RemoveControllers(); 1280 1281 // reset and fill command map 1282 m_pToolBar->Clear(); 1283 m_aControllerMap.clear(); 1284 m_aCommandMap.clear(); 1285 1286 m_aMenuMap.clear(); 1287 1288 CommandInfo aCmdInfo; 1289 for ( sal_Int32 n = 0; n < rItemContainer->getCount(); n++ ) 1290 { 1291 Sequence< PropertyValue > aProp; 1292 rtl::OUString aCommandURL; 1293 rtl::OUString aLabel; 1294 rtl::OUString aHelpURL; 1295 rtl::OUString aTooltip; 1296 sal_uInt16 nType( ::com::sun::star::ui::ItemType::DEFAULT ); 1297 sal_uInt16 nWidth( 0 ); 1298 sal_Bool bIsVisible( sal_True ); 1299 sal_uInt32 nStyle( 0 ); 1300 1301 Reference< XIndexAccess > aMenuDesc; 1302 try 1303 { 1304 if ( rItemContainer->getByIndex( n ) >>= aProp ) 1305 { 1306 for ( int i = 0; i < aProp.getLength(); i++ ) 1307 { 1308 if ( aProp[i].Name.equalsAsciiL( ITEM_DESCRIPTOR_COMMANDURL, ITEM_DESCRIPTOR_COMMANDURL_LEN )) 1309 { 1310 aProp[i].Value >>= aCommandURL; 1311 if ( aCommandURL.compareToAscii(MENUPREFIX, RTL_CONSTASCII_LENGTH(MENUPREFIX) ) == 0 ) 1312 { 1313 try 1314 { 1315 Reference< XIndexAccess > xMenuContainer; 1316 if ( m_xDocUICfgMgr.is() ) 1317 xMenuContainer = m_xDocUICfgMgr->getSettings( aCommandURL, sal_False ); 1318 if ( !xMenuContainer.is() && m_xUICfgMgr.is() ) 1319 xMenuContainer = m_xUICfgMgr->getSettings( aCommandURL, sal_False ); 1320 if ( xMenuContainer.is() && xMenuContainer->getCount() ) 1321 { 1322 Sequence< PropertyValue > aProps; 1323 // drop down menu info is currently 1324 // the first ( and only ) menu 1325 // in the menusettings container 1326 xMenuContainer->getByIndex(0) >>= aProps; 1327 for ( sal_Int32 index=0; index<aProps.getLength(); ++index ) 1328 { 1329 if ( aProps[ index ].Name.equalsAsciiL( ITEM_DESCRIPTOR_CONTAINER, ITEM_DESCRIPTOR_CONTAINER_LEN )) 1330 1331 { 1332 aProps[ index ].Value >>= aMenuDesc; 1333 break; 1334 } 1335 } 1336 } 1337 } 1338 catch( Exception& ) 1339 { 1340 } 1341 } 1342 } 1343 else if ( aProp[i].Name.equalsAsciiL( ITEM_DESCRIPTOR_HELPURL, ITEM_DESCRIPTOR_HELPURL_LEN )) 1344 aProp[i].Value >>= aHelpURL; 1345 else if ( aProp[i].Name.equalsAsciiL( ITEM_DESCRIPTOR_TOOLTIP, ITEM_DESCRIPTOR_TOOLTIP_LEN )) 1346 aProp[i].Value >>= aTooltip; 1347 else if ( aProp[i].Name.equalsAsciiL( ITEM_DESCRIPTOR_LABEL, ITEM_DESCRIPTOR_LABEL_LEN )) 1348 aProp[i].Value >>= aLabel; 1349 else if ( aProp[i].Name.equalsAsciiL( ITEM_DESCRIPTOR_TYPE, ITEM_DESCRIPTOR_TYPE_LEN )) 1350 aProp[i].Value >>= nType; 1351 else if ( aProp[i].Name.equalsAsciiL( ITEM_DESCRIPTOR_VISIBLE, ITEM_DESCRIPTOR_VISIBLE_LEN )) 1352 aProp[i].Value >>= bIsVisible; 1353 else if ( aProp[i].Name.equalsAsciiL( ITEM_DESCRIPTOR_WIDTH, ITEM_DESCRIPTOR_WIDTH_LEN )) 1354 aProp[i].Value >>= nWidth; 1355 else if ( aProp[i].Name.equalsAsciiL( ITEM_DESCRIPTOR_STYLE, ITEM_DESCRIPTOR_STYLE_LEN )) 1356 aProp[i].Value >>= nStyle; 1357 } 1358 1359 if (( nType == ::com::sun::star::ui::ItemType::DEFAULT ) && ( aCommandURL.getLength() > 0 )) 1360 { 1361 ::rtl::OUString aString( RetrieveLabelFromCommand( aCommandURL )); 1362 1363 sal_uInt16 nItemBits = ConvertStyleToToolboxItemBits( nStyle ); 1364 if ( aMenuDesc.is() ) 1365 m_aMenuMap[ nId ] = aMenuDesc; 1366 m_pToolBar->InsertItem( nId, aString, nItemBits ); 1367 m_pToolBar->SetItemCommand( nId, aCommandURL ); 1368 if ( aTooltip.getLength() ) 1369 { 1370 m_pToolBar->SetQuickHelpText( nId, aTooltip ); 1371 } 1372 else 1373 { 1374 ::rtl::OUString sQuickHelp( aString ); 1375 ::rtl::OUString sShortCut; 1376 if( RetrieveShortcut( aCommandURL, sShortCut ) ) 1377 { 1378 sQuickHelp += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " (" ) ); 1379 sQuickHelp += sShortCut; 1380 sQuickHelp += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ")" ) ); 1381 } 1382 1383 m_pToolBar->SetQuickHelpText( nId, sQuickHelp ); 1384 } 1385 1386 if ( aLabel.getLength() > 0 ) 1387 { 1388 m_pToolBar->SetItemText( nId, aLabel ); 1389 } 1390 else 1391 { 1392 m_pToolBar->SetItemText( nId, aString ); 1393 } 1394 m_pToolBar->EnableItem( nId, sal_True ); 1395 m_pToolBar->SetItemState( nId, STATE_NOCHECK ); 1396 1397 // Fill command map. It stores all our commands and from what 1398 // image manager we got our image. So we can decide if we have to use an 1399 // image from a notification message. 1400 CommandToInfoMap::iterator pIter = m_aCommandMap.find( aCommandURL ); 1401 if ( pIter == m_aCommandMap.end()) 1402 { 1403 aCmdInfo.nId = nId; 1404 aCmdInfo.nWidth = nWidth; 1405 m_aCommandMap.insert( CommandToInfoMap::value_type( aCommandURL, aCmdInfo )); 1406 } 1407 else 1408 { 1409 pIter->second.aIds.push_back( nId ); 1410 } 1411 1412 if ( !bIsVisible ) 1413 m_pToolBar->HideItem( nId ); 1414 1415 ++nId; 1416 } 1417 else if ( nType == ::com::sun::star::ui::ItemType::SEPARATOR_LINE ) 1418 { 1419 m_pToolBar->InsertSeparator(); 1420 } 1421 else if ( nType == ::com::sun::star::ui::ItemType::SEPARATOR_SPACE ) 1422 { 1423 m_pToolBar->InsertSpace(); 1424 } 1425 else if ( nType == ::com::sun::star::ui::ItemType::SEPARATOR_LINEBREAK ) 1426 { 1427 m_pToolBar->InsertBreak(); 1428 } 1429 } 1430 } 1431 catch ( ::com::sun::star::lang::IndexOutOfBoundsException& ) 1432 { 1433 break; 1434 } 1435 } 1436 1437 // Support add-on toolbar merging here. Working directly on the toolbar object is much 1438 // simpler and faster. 1439 const sal_uInt16 TOOLBAR_ITEM_STARTID = 1000; 1440 1441 MergeToolbarInstructionContainer aMergeInstructionContainer; 1442 1443 // Retrieve the toolbar name from the resource name 1444 ::rtl::OUString aToolbarName( m_aResourceName ); 1445 sal_Int32 nIndex = aToolbarName.lastIndexOf( '/' ); 1446 if (( nIndex > 0 ) && ( nIndex < aToolbarName.getLength() )) 1447 aToolbarName = aToolbarName.copy( nIndex+1 ); 1448 1449 AddonsOptions().GetMergeToolbarInstructions( aToolbarName, aMergeInstructionContainer ); 1450 1451 if ( !aMergeInstructionContainer.empty() ) 1452 { 1453 sal_uInt16 nItemId( TOOLBAR_ITEM_STARTID ); 1454 const sal_uInt32 nCount = aMergeInstructionContainer.size(); 1455 for ( sal_uInt32 i=0; i < nCount; i++ ) 1456 { 1457 MergeToolbarInstruction& rInstruction = aMergeInstructionContainer[i]; 1458 if ( ToolBarMerger::IsCorrectContext( rInstruction.aMergeContext, m_aModuleIdentifier )) 1459 { 1460 ReferenceToolbarPathInfo aRefPoint = ToolBarMerger::FindReferencePoint( m_pToolBar, rInstruction.aMergePoint ); 1461 1462 // convert the sequence< sequence< propertyvalue > > structure to 1463 // something we can better handle. A vector with item data 1464 AddonToolbarItemContainer aItems; 1465 ToolBarMerger::ConvertSeqSeqToVector( rInstruction.aMergeToolbarItems, aItems ); 1466 1467 if ( aRefPoint.bResult ) 1468 { 1469 ToolBarMerger::ProcessMergeOperation( m_xFrame, 1470 m_pToolBar, 1471 aRefPoint.nPos, 1472 nItemId, 1473 m_aCommandMap, 1474 m_aModuleIdentifier, 1475 rInstruction.aMergeCommand, 1476 rInstruction.aMergeCommandParameter, 1477 aItems ); 1478 } 1479 else 1480 { 1481 ToolBarMerger::ProcessMergeFallback( m_xFrame, 1482 m_pToolBar, 1483 aRefPoint.nPos, 1484 nItemId, 1485 m_aCommandMap, 1486 m_aModuleIdentifier, 1487 rInstruction.aMergeCommand, 1488 rInstruction.aMergeFallback, 1489 aItems ); 1490 } 1491 } 1492 } 1493 } 1494 1495 // Request images for all toolbar items. Must be done before CreateControllers as 1496 // some controllers need access to the image. 1497 RequestImages(); 1498 1499 // Create controllers after we set the images. There are controllers which needs 1500 // an image at the toolbar at creation time! 1501 CreateControllers(); 1502 1503 // Notify controllers that they are now correctly initialized and can start listening 1504 // toolbars that will open in popup mode will be updated immediately to avoid flickering 1505 if( m_pToolBar->WillUsePopupMode() ) 1506 UpdateControllers(); 1507 else if ( m_pToolBar->IsReallyVisible() ) 1508 m_aAsyncUpdateControllersTimer.Start(); 1509 1510 // Try to retrieve UIName from the container property set and set it as the title 1511 // if it is not empty. 1512 Reference< XPropertySet > xPropSet( rItemContainer, UNO_QUERY ); 1513 if ( xPropSet.is() ) 1514 { 1515 try 1516 { 1517 rtl::OUString aUIName; 1518 xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UIName" ))) >>= aUIName; 1519 if ( aUIName.getLength() > 0 ) 1520 m_pToolBar->SetText( aUIName ); 1521 } 1522 catch ( Exception& ) 1523 { 1524 } 1525 } 1526 } 1527 1528 void ToolBarManager::RequestImages() 1529 { 1530 RTL_LOGFILE_CONTEXT( aLog, "framework (cd100003) ::ToolBarManager::RequestImages" ); 1531 1532 // Request images from image manager 1533 Sequence< rtl::OUString > aCmdURLSeq( m_aCommandMap.size() ); 1534 Sequence< Reference< XGraphic > > aDocGraphicSeq; 1535 Sequence< Reference< XGraphic > > aModGraphicSeq; 1536 1537 sal_uInt32 i = 0; 1538 CommandToInfoMap::iterator pIter = m_aCommandMap.begin(); 1539 CommandToInfoMap::iterator pEnd = m_aCommandMap.end(); 1540 while ( pIter != pEnd ) 1541 { 1542 aCmdURLSeq[i++] = pIter->first; 1543 ++pIter; 1544 } 1545 1546 sal_Bool bBigImages( SvtMiscOptions().AreCurrentSymbolsLarge() ); 1547 m_bIsHiContrast = m_pToolBar->GetSettings().GetStyleSettings().GetHighContrastMode(); 1548 sal_Int16 p = getImageTypeFromBools( SvtMiscOptions().AreCurrentSymbolsLarge(), m_bIsHiContrast ); 1549 1550 if ( m_xDocImageManager.is() ) 1551 aDocGraphicSeq = m_xDocImageManager->getImages( p, aCmdURLSeq ); 1552 aModGraphicSeq = m_xModuleImageManager->getImages( p, aCmdURLSeq ); 1553 1554 i = 0; 1555 pIter = m_aCommandMap.begin(); 1556 while ( pIter != pEnd ) 1557 { 1558 rtl::OUString aCommandURL = aCmdURLSeq[i]; 1559 1560 Image aImage; 1561 if ( aDocGraphicSeq.getLength() > 0 ) 1562 aImage = Image( aDocGraphicSeq[i] ); 1563 if ( !aImage ) 1564 { 1565 aImage = Image( aModGraphicSeq[i] ); 1566 // Try also to query for add-on images before giving up and use an 1567 // empty image. 1568 if ( !aImage ) 1569 aImage = QueryAddonsImage( aCmdURLSeq[i], bBigImages, m_bIsHiContrast ); 1570 1571 pIter->second.nImageInfo = 1; // mark image as module based 1572 } 1573 else 1574 { 1575 pIter->second.nImageInfo = 0; // mark image as document based 1576 } 1577 setToolBarImage(aImage,pIter); 1578 ++pIter; 1579 ++i; 1580 } 1581 } 1582 1583 void ToolBarManager::notifyRegisteredControllers( const rtl::OUString& aUIElementName, const rtl::OUString& aCommand ) 1584 { 1585 ResetableGuard aGuard( m_aLock ); 1586 if ( !m_aSubToolBarControllerMap.empty() ) 1587 { 1588 SubToolBarToSubToolBarControllerMap::const_iterator pIter = 1589 m_aSubToolBarControllerMap.find( aUIElementName ); 1590 1591 if ( pIter != m_aSubToolBarControllerMap.end() ) 1592 { 1593 const SubToolBarControllerVector& rSubToolBarVector = pIter->second; 1594 if ( !rSubToolBarVector.empty() ) 1595 { 1596 SubToolBarControllerVector aNotifyVector = rSubToolBarVector; 1597 aGuard.unlock(); 1598 1599 const sal_uInt32 nCount = aNotifyVector.size(); 1600 for ( sal_uInt32 i=0; i < nCount; i++ ) 1601 { 1602 try 1603 { 1604 Reference< XSubToolbarController > xController = aNotifyVector[i]; 1605 if ( xController.is() ) 1606 xController->functionSelected( aCommand ); 1607 } 1608 catch ( RuntimeException& e ) 1609 { 1610 throw e; 1611 } 1612 catch ( Exception& ) 1613 { 1614 } 1615 } 1616 } 1617 } 1618 } 1619 } 1620 long ToolBarManager::HandleClick(void ( SAL_CALL XToolbarController::*_pClick )()) 1621 { 1622 ResetableGuard aGuard( m_aLock ); 1623 1624 if ( m_bDisposed ) 1625 return 1; 1626 1627 sal_uInt16 nId( m_pToolBar->GetCurItemId() ); 1628 ToolBarControllerMap::const_iterator pIter = m_aControllerMap.find( nId ); 1629 if ( pIter != m_aControllerMap.end() ) 1630 { 1631 Reference< XToolbarController > xController( pIter->second, UNO_QUERY ); 1632 1633 if ( xController.is() ) 1634 (xController.get()->*_pClick)( ); 1635 } // if ( pIter != m_aControllerMap.end() ) 1636 return 1; 1637 } 1638 1639 IMPL_LINK( ToolBarManager, Click, ToolBox*, EMPTYARG ) 1640 { 1641 return HandleClick(&XToolbarController::click); 1642 } 1643 1644 IMPL_LINK( ToolBarManager, DropdownClick, ToolBox*, EMPTYARG ) 1645 { 1646 ResetableGuard aGuard( m_aLock ); 1647 1648 if ( m_bDisposed ) 1649 return 1; 1650 1651 sal_uInt16 nId( m_pToolBar->GetCurItemId() ); 1652 ToolBarControllerMap::const_iterator pIter = m_aControllerMap.find( nId ); 1653 if ( pIter != m_aControllerMap.end() ) 1654 { 1655 Reference< XToolbarController > xController( pIter->second, UNO_QUERY ); 1656 1657 if ( xController.is() ) 1658 { 1659 Reference< XWindow > xWin = xController->createPopupWindow(); 1660 if ( xWin.is() ) 1661 xWin->setFocus(); 1662 } 1663 } 1664 return 1; 1665 } 1666 1667 IMPL_LINK( ToolBarManager, DoubleClick, ToolBox*, EMPTYARG ) 1668 { 1669 return HandleClick(&XToolbarController::doubleClick); 1670 } 1671 1672 void ToolBarManager::ImplClearPopupMenu( ToolBox *pToolBar ) 1673 { 1674 if ( m_bDisposed ) 1675 return; 1676 1677 PopupMenu *pMenu = pToolBar->GetMenu(); 1678 1679 // remove config entries from menu, so we have a clean menu to start with 1680 // remove submenu first 1681 PopupMenu* pItemMenu = pMenu->GetPopupMenu( 1 ); 1682 if( pItemMenu ) 1683 { 1684 pItemMenu->Clear(); 1685 delete pItemMenu; 1686 pItemMenu = NULL; 1687 pMenu->SetPopupMenu( 1, pItemMenu ); 1688 } 1689 1690 // remove all items that were not added by the toolbar itself 1691 sal_uInt16 i; 1692 for( i=0; i<pMenu->GetItemCount(); ) 1693 { 1694 if( pMenu->GetItemId( i ) < TOOLBOX_MENUITEM_START ) 1695 pMenu->RemoveItem( i ); 1696 else 1697 i++; 1698 } 1699 } 1700 1701 IMPL_LINK( ToolBarManager, MenuDeactivate, Menu*, pMenu ) 1702 { 1703 ResetableGuard aGuard( m_aLock ); 1704 1705 if ( m_bDisposed ) 1706 return 1; 1707 1708 if( pMenu != m_pToolBar->GetMenu() ) 1709 return 1; 1710 1711 ImplClearPopupMenu( m_pToolBar ); 1712 1713 return 0; 1714 } 1715 1716 Reference< XModel > ToolBarManager::GetModelFromFrame() const 1717 { 1718 Reference< XController > xController = m_xFrame->getController(); 1719 Reference< XModel > xModel; 1720 if ( xController.is() ) 1721 xModel = xController->getModel(); 1722 1723 return xModel; 1724 } 1725 1726 sal_Bool ToolBarManager::IsPluginMode() const 1727 { 1728 sal_Bool bPluginMode( sal_False ); 1729 1730 if ( m_xFrame.is() ) 1731 { 1732 Reference< XModel > xModel = GetModelFromFrame(); 1733 if ( xModel.is() ) 1734 { 1735 Sequence< PropertyValue > aSeq = xModel->getArgs(); 1736 comphelper::MediaDescriptor aMediaDescriptor( aSeq ); 1737 bPluginMode = aMediaDescriptor.getUnpackedValueOrDefault< sal_Bool >( 1738 comphelper::MediaDescriptor::PROP_VIEWONLY(), sal_False ); 1739 } 1740 } 1741 1742 return bPluginMode; 1743 } 1744 1745 bool ToolBarManager::MenuItemAllowed( sal_uInt16 ) const 1746 { 1747 return true; 1748 } 1749 1750 //added for i33668 by shizhoubo : 200804 1751 PopupMenu * ToolBarManager::GetToolBarCustomMeun(ToolBox* pToolBar) 1752 { 1753 PopupMenu *pMenu = pToolBar->GetMenu(); 1754 // remove all entries before inserting new ones 1755 ImplClearPopupMenu( pToolBar ); 1756 // No config menu entries if command ".uno:ConfigureDialog" is not enabled 1757 Reference< XDispatch > xDisp; 1758 com::sun::star::util::URL aURL; 1759 if ( m_xFrame.is() ) 1760 { 1761 Reference< XDispatchProvider > xProv( m_xFrame, UNO_QUERY ); 1762 aURL.Complete = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ConfigureDialog" )); 1763 m_xURLTransformer->parseStrict( aURL ); 1764 if ( xProv.is() ) 1765 xDisp = xProv->queryDispatch( aURL, ::rtl::OUString(), 0 ); 1766 1767 if ( !xDisp.is() || IsPluginMode() ) 1768 return 0; 1769 } 1770 1771 // popup menu for quick customization 1772 sal_Bool bHideDisabledEntries = !SvtMenuOptions().IsEntryHidingEnabled(); 1773 PopupMenu aPopupMenu( FwkResId( POPUPMENU_TOOLBAR_QUICKCUSTOMIZATION )); 1774 1775 if ( m_pToolBar->IsCustomize() ) 1776 { 1777 sal_uInt16 nPos( 0 ); 1778 PopupMenu* pItemMenu( aPopupMenu.GetPopupMenu( 1 )); 1779 1780 sal_Bool bIsFloating( sal_False ); 1781 1782 DockingManager* pDockMgr = Window::GetDockingManager(); 1783 if ( pDockMgr ) 1784 bIsFloating = pDockMgr->IsFloating( m_pToolBar ); 1785 1786 if ( !bIsFloating ) 1787 { 1788 aPopupMenu.EnableItem( MENUITEM_TOOLBAR_DOCKTOOLBAR, sal_False ); 1789 aPopupMenu.EnableItem( MENUITEM_TOOLBAR_DOCKALLTOOLBAR, sal_False ); 1790 Reference< XDockableWindow > xDockable( VCLUnoHelper::GetInterface( m_pToolBar ), UNO_QUERY ); 1791 if( xDockable.is() ) 1792 aPopupMenu.CheckItem( MENUITEM_TOOLBAR_LOCKTOOLBARPOSITION, xDockable->isLocked() ); 1793 } 1794 else 1795 aPopupMenu.EnableItem( MENUITEM_TOOLBAR_LOCKTOOLBARPOSITION, sal_False ); 1796 1797 if ( !m_bCanBeCustomized ) 1798 { 1799 // Non-configurable toolbars should disable configuration menu items 1800 aPopupMenu.EnableItem( MENUITEM_TOOLBAR_VISIBLEBUTTON, sal_False ); 1801 aPopupMenu.EnableItem( MENUITEM_TOOLBAR_CUSTOMIZETOOLBAR, sal_False ); 1802 } 1803 1804 // Disable menu item CLOSE if the toolbar has no closer 1805 //added for issue64028 by shizhoubo 1806 if( !(pToolBar->GetFloatStyle() & WB_CLOSEABLE) ) 1807 aPopupMenu.EnableItem(MENUITEM_TOOLBAR_CLOSE, sal_False); 1808 //end 1809 1810 pItemMenu->SetMenuFlags (pItemMenu->GetMenuFlags () | 1811 MENU_FLAG_SHOWCHECKIMAGES); 1812 1813 for ( nPos = 0; nPos < m_pToolBar->GetItemCount(); ++nPos ) 1814 { 1815 if ( m_pToolBar->GetItemType(nPos) == TOOLBOXITEM_BUTTON ) 1816 { 1817 sal_uInt16 nId = m_pToolBar->GetItemId(nPos); 1818 ::rtl::OUString aCommandURL = m_pToolBar->GetItemCommand( nId ); 1819 pItemMenu->InsertItem( STARTID_CUSTOMIZE_POPUPMENU+nPos, m_pToolBar->GetItemText( nId ), MIB_CHECKABLE ); 1820 pItemMenu->CheckItem( STARTID_CUSTOMIZE_POPUPMENU+nPos, m_pToolBar->IsItemVisible( nId ) ); 1821 pItemMenu->SetItemCommand( STARTID_CUSTOMIZE_POPUPMENU+nPos, aCommandURL ); 1822 pItemMenu->SetItemImage( STARTID_CUSTOMIZE_POPUPMENU+nPos, 1823 GetImageFromURL( m_xFrame, 1824 aCommandURL, 1825 sal_False, 1826 m_bIsHiContrast )); 1827 } 1828 else 1829 { 1830 pItemMenu->InsertSeparator(); 1831 } 1832 } 1833 } 1834 else 1835 { 1836 sal_uInt16 nPos = aPopupMenu.GetItemPos( MENUITEM_TOOLBAR_CUSTOMIZETOOLBAR ); 1837 if ( nPos != MENU_ITEM_NOTFOUND ) 1838 aPopupMenu.RemoveItem( nPos ); 1839 } 1840 1841 // copy all menu items to the toolbar menu 1842 if( pMenu->GetItemCount() ) 1843 pMenu->InsertSeparator(); 1844 1845 sal_uInt16 i; 1846 for( i=0; i< aPopupMenu.GetItemCount(); i++) 1847 { 1848 sal_uInt16 nId = aPopupMenu.GetItemId( i ); 1849 if ( MenuItemAllowed( nId )) 1850 pMenu->CopyItem( aPopupMenu, i, MENU_APPEND ); 1851 } 1852 1853 // set submenu to toolbar menu 1854 if( aPopupMenu.GetPopupMenu( 1 ) ) 1855 { 1856 // create an own submenu to avoid auto-delete when resource menu is deleted 1857 PopupMenu *pItemMenu = new PopupMenu(); 1858 1859 pItemMenu->SetMenuFlags (pItemMenu->GetMenuFlags () | 1860 MENU_FLAG_SHOWCHECKIMAGES); 1861 1862 for( i=0; i< aPopupMenu.GetPopupMenu( 1 )->GetItemCount(); i++) 1863 pItemMenu->CopyItem( *aPopupMenu.GetPopupMenu( 1 ), i, MENU_APPEND ); 1864 1865 pMenu->SetPopupMenu( 1, pItemMenu ); 1866 } 1867 1868 if ( bHideDisabledEntries ) 1869 pMenu->RemoveDisabledEntries(); 1870 1871 return pMenu; 1872 } 1873 1874 // addd for 33668 by shizhoubo 1875 IMPL_LINK( ToolBarManager, Command, CommandEvent*, pCmdEvt ) 1876 { 1877 ResetableGuard aGuard( m_aLock ); 1878 1879 if ( m_bDisposed ) 1880 return 1; 1881 if ( pCmdEvt->GetCommand() != COMMAND_CONTEXTMENU ) 1882 return 0; 1883 1884 PopupMenu * pMenu = GetToolBarCustomMeun(m_pToolBar); 1885 if (pMenu) 1886 { 1887 // make sure all disabled entries will be shown 1888 pMenu->SetMenuFlags( pMenu->GetMenuFlags() | MENU_FLAG_ALWAYSSHOWDISABLEDENTRIES ); 1889 ::Point aPoint( pCmdEvt->GetMousePosPixel() ); 1890 pMenu->Execute( m_pToolBar, aPoint ); 1891 } 1892 1893 return 0; 1894 } 1895 //end 1896 1897 IMPL_LINK( ToolBarManager, MenuButton, ToolBox*, pToolBar ) 1898 { 1899 ResetableGuard aGuard( m_aLock ); 1900 1901 if ( m_bDisposed ) 1902 return 1; 1903 //modify for i33668 by shizhoubo:2008:04 1904 GetToolBarCustomMeun(pToolBar); 1905 //end 1906 return 0; 1907 } 1908 1909 IMPL_LINK( ToolBarManager, MenuSelect, Menu*, pMenu ) 1910 { 1911 // We have to hold a reference to ourself as it is possible that we will be disposed and 1912 // our refcount could be zero (destruction) otherwise. 1913 Reference< XInterface > xInterface( static_cast< OWeakObject* >( this ), UNO_QUERY ); 1914 1915 { 1916 // The guard must be in its own context as the we can get destroyed when our 1917 // own xInterface reference get destroyed! 1918 ResetableGuard aGuard( m_aLock ); 1919 1920 if ( m_bDisposed ) 1921 return 1; 1922 1923 switch ( pMenu->GetCurItemId() ) 1924 { 1925 case MENUITEM_TOOLBAR_CUSTOMIZETOOLBAR: 1926 { 1927 Reference< XDispatch > xDisp; 1928 com::sun::star::util::URL aURL; 1929 if ( m_xFrame.is() ) 1930 { 1931 Reference< XDispatchProvider > xProv( m_xFrame, UNO_QUERY ); 1932 aURL.Complete = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ConfigureDialog" )); 1933 m_xURLTransformer->parseStrict( aURL ); 1934 if ( xProv.is() ) 1935 xDisp = xProv->queryDispatch( aURL, ::rtl::OUString(), 0 ); 1936 } 1937 1938 if ( xDisp.is() ) 1939 { 1940 Sequence< PropertyValue > aPropSeq( 1 ); 1941 1942 aPropSeq[ 0 ].Name = 1943 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ResourceURL")); 1944 aPropSeq[ 0 ].Value <<= m_aResourceName; 1945 1946 xDisp->dispatch( aURL, aPropSeq ); 1947 } 1948 break; 1949 } 1950 1951 case MENUITEM_TOOLBAR_DOCKTOOLBAR: 1952 { 1953 ExecuteInfo* pExecuteInfo = new ExecuteInfo; 1954 1955 pExecuteInfo->aToolbarResName = m_aResourceName; 1956 pExecuteInfo->nCmd = EXEC_CMD_DOCKTOOLBAR; 1957 pExecuteInfo->xLayoutManager = getLayoutManagerFromFrame( m_xFrame ); 1958 1959 Application::PostUserEvent( STATIC_LINK(0, ToolBarManager, ExecuteHdl_Impl), pExecuteInfo ); 1960 break; 1961 } 1962 1963 case MENUITEM_TOOLBAR_DOCKALLTOOLBAR: 1964 { 1965 ExecuteInfo* pExecuteInfo = new ExecuteInfo; 1966 1967 pExecuteInfo->aToolbarResName = m_aResourceName; 1968 pExecuteInfo->nCmd = EXEC_CMD_DOCKALLTOOLBARS; 1969 pExecuteInfo->xLayoutManager = getLayoutManagerFromFrame( m_xFrame ); 1970 1971 Application::PostUserEvent( STATIC_LINK(0, ToolBarManager, ExecuteHdl_Impl), pExecuteInfo ); 1972 break; 1973 } 1974 1975 case MENUITEM_TOOLBAR_LOCKTOOLBARPOSITION: 1976 { 1977 Reference< XLayoutManager > xLayoutManager = getLayoutManagerFromFrame( m_xFrame ); 1978 if ( xLayoutManager.is() ) 1979 { 1980 Reference< XDockableWindow > xDockable( VCLUnoHelper::GetInterface( m_pToolBar ), UNO_QUERY ); 1981 1982 if( xDockable->isLocked() ) 1983 xLayoutManager->unlockWindow( m_aResourceName ); 1984 else 1985 xLayoutManager->lockWindow( m_aResourceName ); 1986 } 1987 break; 1988 } 1989 1990 case MENUITEM_TOOLBAR_CLOSE: 1991 { 1992 ExecuteInfo* pExecuteInfo = new ExecuteInfo; 1993 1994 pExecuteInfo->aToolbarResName = m_aResourceName; 1995 pExecuteInfo->nCmd = EXEC_CMD_CLOSETOOLBAR; 1996 pExecuteInfo->xLayoutManager = getLayoutManagerFromFrame( m_xFrame ); 1997 pExecuteInfo->xWindow = VCLUnoHelper::GetInterface( m_pToolBar ); 1998 1999 Application::PostUserEvent( STATIC_LINK(0, ToolBarManager, ExecuteHdl_Impl), pExecuteInfo ); 2000 } 2001 2002 default: 2003 { 2004 sal_uInt16 nId = pMenu->GetCurItemId(); 2005 if(( nId > 0 ) && ( nId < TOOLBOX_MENUITEM_START )) 2006 { 2007 // toggle toolbar button visibility 2008 rtl::OUString aCommand = pMenu->GetItemCommand( nId ); 2009 2010 Reference< XLayoutManager > xLayoutManager = getLayoutManagerFromFrame( m_xFrame ); 2011 if ( xLayoutManager.is() ) 2012 { 2013 Reference< XUIElementSettings > xUIElementSettings( xLayoutManager->getElement( m_aResourceName ), UNO_QUERY ); 2014 if ( xUIElementSettings.is() ) 2015 { 2016 Reference< XIndexContainer > xItemContainer( xUIElementSettings->getSettings( sal_True ), UNO_QUERY ); 2017 sal_Int32 nCount = xItemContainer->getCount(); 2018 for ( sal_Int32 i = 0; i < nCount; i++ ) 2019 { 2020 Sequence< PropertyValue > aProp; 2021 sal_Int32 nVisibleIndex( -1 ); 2022 rtl::OUString aCommandURL; 2023 sal_Bool bVisible( sal_False ); 2024 2025 if ( xItemContainer->getByIndex( i ) >>= aProp ) 2026 { 2027 for ( sal_Int32 j = 0; j < aProp.getLength(); j++ ) 2028 { 2029 if ( aProp[j].Name.equalsAscii( ITEM_DESCRIPTOR_COMMANDURL )) 2030 { 2031 aProp[j].Value >>= aCommandURL; 2032 } 2033 else if ( aProp[j].Name.equalsAscii( ITEM_DESCRIPTOR_VISIBLE )) 2034 { 2035 aProp[j].Value >>= bVisible; 2036 nVisibleIndex = j; 2037 } 2038 } 2039 2040 if (( aCommandURL == aCommand ) && ( nVisibleIndex >= 0 )) 2041 { 2042 // We have found the requested item, toggle the visible flag 2043 // and write back the configuration settings to the toolbar 2044 aProp[nVisibleIndex].Value = makeAny( !bVisible ); 2045 try 2046 { 2047 xItemContainer->replaceByIndex( i, makeAny( aProp )); 2048 xUIElementSettings->setSettings( Reference< XIndexAccess >( xItemContainer, UNO_QUERY )); 2049 Reference< XPropertySet > xPropSet( xUIElementSettings, UNO_QUERY ); 2050 if ( xPropSet.is() ) 2051 { 2052 Reference< XUIConfigurationPersistence > xUICfgMgr; 2053 if (( xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ConfigurationSource" ))) >>= xUICfgMgr ) && ( xUICfgMgr.is() )) 2054 xUICfgMgr->store(); 2055 } 2056 } 2057 catch ( Exception& ) 2058 { 2059 } 2060 2061 break; 2062 } 2063 } 2064 } 2065 } 2066 } 2067 } 2068 break; 2069 } 2070 } 2071 2072 // remove all entries - deactivate is not reliable 2073 // The method checks if we are already disposed and in that case does nothing! 2074 ImplClearPopupMenu( m_pToolBar ); 2075 } 2076 2077 return 1; 2078 } 2079 2080 IMPL_LINK( ToolBarManager, Select, ToolBox*, EMPTYARG ) 2081 { 2082 if ( m_bDisposed ) 2083 return 1; 2084 2085 sal_Int16 nKeyModifier( (sal_Int16)m_pToolBar->GetModifier() ); 2086 sal_uInt16 nId( m_pToolBar->GetCurItemId() ); 2087 2088 ToolBarControllerMap::const_iterator pIter = m_aControllerMap.find( nId ); 2089 if ( pIter != m_aControllerMap.end() ) 2090 { 2091 Reference< XToolbarController > xController( pIter->second, UNO_QUERY ); 2092 2093 if ( xController.is() ) 2094 xController->execute( nKeyModifier ); 2095 } 2096 2097 return 1; 2098 } 2099 2100 IMPL_LINK( ToolBarManager, Highlight, ToolBox*, EMPTYARG ) 2101 { 2102 return 1; 2103 } 2104 2105 IMPL_LINK( ToolBarManager, Activate, ToolBox*, EMPTYARG ) 2106 { 2107 return 1; 2108 } 2109 2110 IMPL_LINK( ToolBarManager, Deactivate, ToolBox*, EMPTYARG ) 2111 { 2112 return 1; 2113 } 2114 2115 IMPL_LINK( ToolBarManager, StateChanged, StateChangedType*, pStateChangedType ) 2116 { 2117 if ( m_bDisposed ) 2118 return 1; 2119 2120 if ( *pStateChangedType == STATE_CHANGE_CONTROLBACKGROUND ) 2121 { 2122 // Check if we need to get new images for normal/high contrast mode 2123 CheckAndUpdateImages(); 2124 } 2125 else if ( *pStateChangedType == STATE_CHANGE_VISIBLE ) 2126 { 2127 if ( m_pToolBar->IsReallyVisible() ) 2128 m_aAsyncUpdateControllersTimer.Start(); 2129 } 2130 else if ( *pStateChangedType == STATE_CHANGE_INITSHOW ) 2131 { 2132 m_aAsyncUpdateControllersTimer.Start(); 2133 } 2134 return 1; 2135 } 2136 2137 IMPL_LINK( ToolBarManager, DataChanged, DataChangedEvent*, pDataChangedEvent ) 2138 { 2139 if ((( pDataChangedEvent->GetType() == DATACHANGED_SETTINGS ) || 2140 ( pDataChangedEvent->GetType() == DATACHANGED_DISPLAY )) && 2141 ( pDataChangedEvent->GetFlags() & SETTINGS_STYLE )) 2142 { 2143 // Check if we need to get new images for normal/high contrast mode 2144 CheckAndUpdateImages(); 2145 } 2146 2147 for ( sal_uInt16 nPos = 0; nPos < m_pToolBar->GetItemCount(); ++nPos ) 2148 { 2149 const sal_uInt16 nId = m_pToolBar->GetItemId(nPos); 2150 Window* pWindow = m_pToolBar->GetItemWindow( nId ); 2151 if ( pWindow ) 2152 { 2153 const DataChangedEvent& rDCEvt( *pDataChangedEvent ); 2154 pWindow->DataChanged( rDCEvt ); 2155 } 2156 } 2157 2158 if ( !m_pToolBar->IsFloatingMode() && 2159 m_pToolBar->IsVisible() ) 2160 { 2161 // Resize toolbar, layout manager is resize listener and will calc 2162 // the layout automatically. 2163 ::Size aSize( m_pToolBar->CalcWindowSizePixel() ); 2164 m_pToolBar->SetOutputSizePixel( aSize ); 2165 } 2166 2167 return 1; 2168 } 2169 2170 IMPL_LINK( ToolBarManager, AsyncUpdateControllersHdl, Timer *, EMPTYARG ) 2171 { 2172 // The guard must be in its own context as the we can get destroyed when our 2173 // own xInterface reference get destroyed! 2174 Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY ); 2175 2176 ResetableGuard aGuard( m_aLock ); 2177 2178 if ( m_bDisposed ) 2179 return 1; 2180 2181 // Request to update our controllers 2182 m_aAsyncUpdateControllersTimer.Stop(); 2183 UpdateControllers(); 2184 2185 return 0; 2186 } 2187 2188 IMPL_STATIC_LINK_NOINSTANCE( ToolBarManager, ExecuteHdl_Impl, ExecuteInfo*, pExecuteInfo ) 2189 { 2190 try 2191 { 2192 // Asynchronous execution as this can lead to our own destruction! 2193 if (( pExecuteInfo->nCmd == EXEC_CMD_CLOSETOOLBAR ) && 2194 ( pExecuteInfo->xLayoutManager.is() ) && 2195 ( pExecuteInfo->xWindow.is() )) 2196 { 2197 // Use docking window close to close the toolbar. The layout manager is 2198 // listener and will react correctly according to the context sensitive 2199 // flag of our toolbar. 2200 Window* pWin = VCLUnoHelper::GetWindow( pExecuteInfo->xWindow ); 2201 DockingWindow* pDockWin = dynamic_cast< DockingWindow* >( pWin ); 2202 if ( pDockWin ) 2203 pDockWin->Close(); 2204 } 2205 else if (( pExecuteInfo->nCmd == EXEC_CMD_DOCKTOOLBAR ) && 2206 ( pExecuteInfo->xLayoutManager.is() )) 2207 { 2208 ::com::sun::star::awt::Point aPoint; 2209 aPoint.X = aPoint.Y = SAL_MAX_INT32; 2210 pExecuteInfo->xLayoutManager->dockWindow( pExecuteInfo->aToolbarResName, 2211 DockingArea_DOCKINGAREA_DEFAULT, 2212 aPoint ); 2213 } 2214 else if (( pExecuteInfo->nCmd == EXEC_CMD_DOCKALLTOOLBARS ) && 2215 ( pExecuteInfo->xLayoutManager.is() )) 2216 { 2217 pExecuteInfo->xLayoutManager->dockAllWindows( UIElementType::TOOLBAR ); 2218 } 2219 } 2220 catch ( Exception& ) 2221 { 2222 } 2223 2224 delete pExecuteInfo; 2225 return 0; 2226 } 2227 2228 Image ToolBarManager::QueryAddonsImage( const ::rtl::OUString& aCommandURL, bool bBigImages, bool bHiContrast ) 2229 { 2230 Image aImage = framework::AddonsOptions().GetImageFromURL( aCommandURL, bBigImages, bHiContrast ); 2231 return aImage; 2232 } 2233 2234 bool ToolBarManager::impl_RetrieveShortcutsFromConfiguration( 2235 const Reference< XAcceleratorConfiguration >& rAccelCfg, 2236 const rtl::OUString& rCommand, 2237 rtl::OUString& rShortCut ) 2238 { 2239 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ToolBarManager::impl_RetrieveShortcutsFromConfiguration" ); 2240 if ( rAccelCfg.is() ) 2241 { 2242 try 2243 { 2244 com::sun::star::awt::KeyEvent aKeyEvent; 2245 Sequence< OUString > aCommands(1); 2246 aCommands[0] = rCommand; 2247 2248 Sequence< Any > aSeqKeyCode( rAccelCfg->getPreferredKeyEventsForCommandList( aCommands ) ); 2249 if( aSeqKeyCode.getLength() == 1 ) 2250 { 2251 if ( aSeqKeyCode[0] >>= aKeyEvent ) 2252 { 2253 rShortCut = svt::AcceleratorExecute::st_AWTKey2VCLKey( aKeyEvent ).GetName(); 2254 return true; 2255 } 2256 } 2257 } 2258 catch ( IllegalArgumentException& ) 2259 { 2260 } 2261 } 2262 2263 return false; 2264 } 2265 2266 bool ToolBarManager::RetrieveShortcut( const rtl::OUString& rCommandURL, rtl::OUString& rShortCut ) 2267 { 2268 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ToolBarManager::RetrieveShortcuts" ); 2269 if ( m_bModuleIdentified ) 2270 { 2271 Reference< XAcceleratorConfiguration > xDocAccelCfg( m_xDocAcceleratorManager ); 2272 Reference< XAcceleratorConfiguration > xModuleAccelCfg( m_xModuleAcceleratorManager ); 2273 Reference< XAcceleratorConfiguration > xGlobalAccelCfg( m_xGlobalAcceleratorManager ); 2274 2275 if ( !m_bAcceleratorCfg ) 2276 { 2277 // Retrieve references on demand 2278 m_bAcceleratorCfg = sal_True; 2279 if ( !xDocAccelCfg.is() ) 2280 { 2281 Reference< XController > xController = m_xFrame->getController(); 2282 Reference< XModel > xModel; 2283 if ( xController.is() ) 2284 { 2285 xModel = xController->getModel(); 2286 if ( xModel.is() ) 2287 { 2288 Reference< XUIConfigurationManagerSupplier > xSupplier( xModel, UNO_QUERY ); 2289 if ( xSupplier.is() ) 2290 { 2291 Reference< XUIConfigurationManager > xDocUICfgMgr( xSupplier->getUIConfigurationManager(), UNO_QUERY ); 2292 if ( xDocUICfgMgr.is() ) 2293 { 2294 xDocAccelCfg = Reference< XAcceleratorConfiguration >( xDocUICfgMgr->getShortCutManager(), UNO_QUERY ); 2295 m_xDocAcceleratorManager = xDocAccelCfg; 2296 } 2297 } 2298 } 2299 } 2300 } 2301 2302 if ( !xModuleAccelCfg.is() ) 2303 { 2304 Reference< XModuleUIConfigurationManagerSupplier > xModuleCfgMgrSupplier( m_xServiceManager->createInstance( 2305 SERVICENAME_MODULEUICONFIGURATIONMANAGERSUPPLIER ), 2306 UNO_QUERY ); 2307 try 2308 { 2309 Reference< XUIConfigurationManager > xUICfgMgr = xModuleCfgMgrSupplier->getUIConfigurationManager( m_aModuleIdentifier ); 2310 if ( xUICfgMgr.is() ) 2311 { 2312 xModuleAccelCfg = Reference< XAcceleratorConfiguration >( xUICfgMgr->getShortCutManager(), UNO_QUERY ); 2313 m_xModuleAcceleratorManager = xModuleAccelCfg; 2314 } 2315 } 2316 catch ( RuntimeException& ) 2317 { 2318 throw; 2319 } 2320 catch ( Exception& ) 2321 { 2322 } 2323 } 2324 2325 if ( !xGlobalAccelCfg.is() ) 2326 { 2327 xGlobalAccelCfg = Reference< XAcceleratorConfiguration >( m_xServiceManager->createInstance( 2328 SERVICENAME_GLOBALACCELERATORCONFIGURATION ), 2329 UNO_QUERY ); 2330 m_xGlobalAcceleratorManager = xGlobalAccelCfg; 2331 } 2332 } 2333 2334 bool bFound = false; 2335 2336 if ( m_xGlobalAcceleratorManager.is() ) 2337 bFound = impl_RetrieveShortcutsFromConfiguration( xGlobalAccelCfg, rCommandURL, rShortCut ); 2338 if ( !bFound && m_xModuleAcceleratorManager.is() ) 2339 bFound = impl_RetrieveShortcutsFromConfiguration( xModuleAccelCfg, rCommandURL, rShortCut ); 2340 if ( !bFound && m_xDocAcceleratorManager.is() ) 2341 impl_RetrieveShortcutsFromConfiguration( xGlobalAccelCfg, rCommandURL, rShortCut ); 2342 2343 if( bFound ) 2344 return true; 2345 } 2346 return false; 2347 } 2348 2349 } 2350 2351 2352 2353