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

Generated by: LCOV version 1.10