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