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

Generated by: LCOV version 1.10