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