LCOV - code coverage report
Current view: top level - libreoffice/framework/source/uielement - toolbarmanager.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 620 1133 54.7 %
Date: 2012-12-17 Functions: 43 83 51.8 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10