LCOV - code coverage report
Current view: top level - framework/source/uielement - popuptoolbarcontroller.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 125 213 58.7 %
Date: 2014-04-11 Functions: 19 38 50.0 %
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 <cppuhelper/implbase1.hxx>
      21             : #include <cppuhelper/supportsservice.hxx>
      22             : #include <comphelper/processfactory.hxx>
      23             : #include <framework/menuconfiguration.hxx>
      24             : #include <rtl/ref.hxx>
      25             : #include <svtools/imagemgr.hxx>
      26             : #include <svtools/miscopt.hxx>
      27             : #include <svtools/toolboxcontroller.hxx>
      28             : #include <toolkit/awt/vclxmenu.hxx>
      29             : #include <toolkit/helper/vclunohelper.hxx>
      30             : #include <tools/urlobj.hxx>
      31             : #include <unotools/moduleoptions.hxx>
      32             : #include <vcl/svapp.hxx>
      33             : #include <vcl/toolbox.hxx>
      34             : 
      35             : #include <com/sun/star/awt/PopupMenuDirection.hpp>
      36             : #include <com/sun/star/awt/XPopupMenu.hpp>
      37             : #include <com/sun/star/frame/thePopupMenuControllerFactory.hpp>
      38             : #include <com/sun/star/frame/XDispatchProvider.hpp>
      39             : #include <com/sun/star/frame/XPopupMenuController.hpp>
      40             : #include <com/sun/star/frame/XUIControllerFactory.hpp>
      41             : #include <com/sun/star/lang/XServiceInfo.hpp>
      42             : #include <com/sun/star/ucb/CommandFailedException.hpp>
      43             : 
      44             : #define UNO_COMMAND_RECENT_FILE_LIST    ".uno:RecentFileList"
      45             : 
      46             : using namespace framework;
      47             : 
      48             : namespace {
      49             : 
      50             : typedef cppu::ImplInheritanceHelper1< svt::ToolboxController,
      51             :                                     css::lang::XServiceInfo >
      52             :                 ToolBarBase;
      53             : 
      54             : class PopupMenuToolbarController : public ToolBarBase
      55             : {
      56             : public:
      57             :     virtual ~PopupMenuToolbarController();
      58             : 
      59             :     // XComponent
      60             :     virtual void SAL_CALL dispose() throw ( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
      61             :     // XInitialization
      62             :     virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) throw (css::uno::Exception, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      63             :     // XToolbarController
      64             :     virtual css::uno::Reference< css::awt::XWindow > SAL_CALL createPopupWindow() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      65             :     // XStatusListener
      66             :     virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) throw ( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
      67             : 
      68             : protected:
      69             :     PopupMenuToolbarController( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
      70             :                                 const OUString &rPopupCommand = OUString() );
      71             :     virtual void functionExecuted( const OUString &rCommand );
      72             :     virtual sal_uInt16 getDropDownStyle() const;
      73             :     void createPopupMenuController();
      74             : 
      75             :     css::uno::Reference< css::uno::XComponentContext >      m_xContext;
      76             :     bool                                                m_bHasController;
      77             :     css::uno::Reference< css::awt::XPopupMenu >             m_xPopupMenu;
      78             : 
      79             : private:
      80             :     OUString m_aPopupCommand;
      81             :     css::uno::Reference< css::frame::XUIControllerFactory > m_xPopupMenuFactory;
      82             :     css::uno::Reference< css::frame::XPopupMenuController > m_xPopupMenuController;
      83             : };
      84             : 
      85         780 : PopupMenuToolbarController::PopupMenuToolbarController(
      86             :     const css::uno::Reference< css::uno::XComponentContext >& xContext,
      87             :     const OUString &rPopupCommand )
      88             :     : m_xContext( xContext )
      89             :     , m_bHasController( false )
      90         780 :     , m_aPopupCommand( rPopupCommand )
      91             : {
      92         780 : }
      93             : 
      94         780 : PopupMenuToolbarController::~PopupMenuToolbarController()
      95             : {
      96         780 : }
      97             : 
      98         780 : void SAL_CALL PopupMenuToolbarController::dispose()
      99             : throw ( css::uno::RuntimeException, std::exception )
     100             : {
     101         780 :     svt::ToolboxController::dispose();
     102             : 
     103         780 :     osl::MutexGuard aGuard( m_aMutex );
     104         780 :     if( m_xPopupMenuController.is() )
     105             :     {
     106             :         css::uno::Reference< css::lang::XComponent > xComponent(
     107         675 :             m_xPopupMenuController, css::uno::UNO_QUERY );
     108         675 :         if( xComponent.is() )
     109             :         {
     110             :             try
     111             :             {
     112         675 :                 xComponent->dispose();
     113             :             }
     114           0 :             catch (...)
     115             :             {}
     116             :         }
     117         675 :         m_xPopupMenuController.clear();
     118             :     }
     119             : 
     120         780 :     m_xContext.clear();
     121         780 :     m_xPopupMenuFactory.clear();
     122         780 :     m_xPopupMenu.clear();
     123         780 : }
     124             : 
     125         780 : void SAL_CALL PopupMenuToolbarController::initialize(
     126             :     const css::uno::Sequence< css::uno::Any >& aArguments )
     127             : throw ( css::uno::Exception, css::uno::RuntimeException, std::exception )
     128             : {
     129         780 :     ToolboxController::initialize( aArguments );
     130             : 
     131         780 :     osl::MutexGuard aGuard( m_aMutex );
     132         780 :     if ( !m_aPopupCommand.getLength() )
     133         675 :         m_aPopupCommand = m_aCommandURL;
     134             : 
     135             :     try
     136             :     {
     137             :         m_xPopupMenuFactory.set(
     138         780 :             css::frame::thePopupMenuControllerFactory::get( m_xContext ) );
     139         780 :         m_bHasController = m_xPopupMenuFactory->hasController(
     140         780 :             m_aPopupCommand, getModuleName() );
     141             :     }
     142           0 :     catch (const css::uno::Exception& e)
     143             :     {
     144             :         OSL_TRACE( "PopupMenuToolbarController - caught an exception! %s",
     145             :                    rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
     146             :         (void) e;
     147             :     }
     148             : 
     149        1560 :     SolarMutexGuard aSolarLock;
     150         780 :     ToolBox* pToolBox = static_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ) );
     151         780 :     if ( pToolBox )
     152             :     {
     153         780 :         ToolBoxItemBits nCurStyle( pToolBox->GetItemBits( m_nToolBoxId ) );
     154         780 :         ToolBoxItemBits nSetStyle( getDropDownStyle() );
     155             :         pToolBox->SetItemBits( m_nToolBoxId,
     156             :                                m_bHasController ?
     157             :                                     nCurStyle | nSetStyle :
     158         780 :                                     nCurStyle & ~nSetStyle );
     159         780 :     }
     160             : 
     161         780 : }
     162             : 
     163         141 : void SAL_CALL PopupMenuToolbarController::statusChanged( const css::frame::FeatureStateEvent& rEvent )
     164             :     throw ( css::uno::RuntimeException, std::exception )
     165             : {
     166             :     // TODO move to base class
     167             : 
     168         141 :     svt::ToolboxController::statusChanged( rEvent );
     169         141 :     enable( rEvent.IsEnabled );
     170         141 : }
     171             : 
     172             : css::uno::Reference< css::awt::XWindow > SAL_CALL
     173           0 : PopupMenuToolbarController::createPopupWindow()
     174             :     throw ( css::uno::RuntimeException, std::exception )
     175             : {
     176           0 :     css::uno::Reference< css::awt::XWindow > xRet;
     177             : 
     178           0 :     osl::MutexGuard aGuard( m_aMutex );
     179           0 :     if ( !m_bHasController )
     180           0 :         return xRet;
     181             : 
     182           0 :     createPopupMenuController();
     183             : 
     184           0 :     SolarMutexGuard aSolarLock;
     185           0 :     ToolBox* pToolBox = static_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ) );
     186           0 :     if ( !pToolBox )
     187           0 :         return xRet;
     188             : 
     189           0 :     pToolBox->SetItemDown( m_nToolBoxId, true );
     190           0 :     sal_uInt16 nId = m_xPopupMenu->execute(
     191             :         css::uno::Reference< css::awt::XWindowPeer >( getParent(), css::uno::UNO_QUERY ),
     192           0 :         VCLUnoHelper::ConvertToAWTRect( pToolBox->GetItemRect( m_nToolBoxId ) ),
     193           0 :         css::awt::PopupMenuDirection::EXECUTE_DEFAULT );
     194           0 :     pToolBox->SetItemDown( m_nToolBoxId, false );
     195             : 
     196           0 :     if ( nId )
     197           0 :         functionExecuted( m_xPopupMenu->getCommand( nId ) );
     198             : 
     199           0 :     return xRet;
     200             : }
     201             : 
     202           0 : void PopupMenuToolbarController::functionExecuted( const OUString &/*rCommand*/)
     203             : {
     204           0 : }
     205             : 
     206         780 : sal_uInt16 PopupMenuToolbarController::getDropDownStyle() const
     207             : {
     208         780 :     return TIB_DROPDOWN;
     209             : }
     210             : 
     211         675 : void PopupMenuToolbarController::createPopupMenuController()
     212             : {
     213         675 :     if( !m_bHasController )
     214         675 :         return;
     215             : 
     216         675 :     if ( !m_xPopupMenuController.is() )
     217             :     {
     218         675 :         css::uno::Sequence< css::uno::Any > aArgs( 2 );
     219        1350 :         css::beans::PropertyValue aProp;
     220             : 
     221         675 :         aProp.Name = "Frame";
     222         675 :         aProp.Value <<= m_xFrame;
     223         675 :         aArgs[0] <<= aProp;
     224             : 
     225         675 :         aProp.Name = "ModuleIdentifier";
     226         675 :         aProp.Value <<= getModuleName();
     227         675 :         aArgs[1] <<= aProp;
     228             :         try
     229             :         {
     230             :             m_xPopupMenu.set(
     231        1350 :                 m_xContext->getServiceManager()->createInstanceWithContext(
     232         675 :                     "com.sun.star.awt.PopupMenu", m_xContext ),
     233         675 :                         css::uno::UNO_QUERY_THROW );
     234             :             m_xPopupMenuController.set(
     235         675 :                 m_xPopupMenuFactory->createInstanceWithArgumentsAndContext(
     236         675 :                     m_aPopupCommand, aArgs, m_xContext), css::uno::UNO_QUERY_THROW );
     237             : 
     238         675 :             m_xPopupMenuController->setPopupMenu( m_xPopupMenu );
     239             :         }
     240           0 :         catch ( const css::uno::Exception &e )
     241             :         {
     242           0 :             m_xPopupMenu.clear();
     243             :             OSL_TRACE( "PopupMenuToolbarController - caught an exception! %s",
     244             :                        OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
     245             :             (void) e;
     246         675 :         }
     247             :     }
     248             : }
     249             : 
     250           0 : class WizardsToolbarController : public PopupMenuToolbarController
     251             : {
     252             : public:
     253             :     WizardsToolbarController( const css::uno::Reference< css::uno::XComponentContext >& rxContext );
     254             : 
     255             :     // XServiceInfo
     256             :     virtual OUString SAL_CALL getImplementationName() throw (css::uno::RuntimeException) SAL_OVERRIDE;
     257             : 
     258             :     virtual sal_Bool SAL_CALL supportsService(OUString const & rServiceName) throw (css::uno::RuntimeException) SAL_OVERRIDE;
     259             : 
     260             :     virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() throw (css::uno::RuntimeException) SAL_OVERRIDE;
     261             : 
     262             : private:
     263             :     sal_uInt16 getDropDownStyle() const SAL_OVERRIDE;
     264             : };
     265             : 
     266           0 : WizardsToolbarController::WizardsToolbarController(
     267             :     const css::uno::Reference< css::uno::XComponentContext >& xContext )
     268           0 :     : PopupMenuToolbarController( xContext )
     269             : {
     270           0 : }
     271             : 
     272           0 : OUString WizardsToolbarController::getImplementationName()
     273             :     throw (css::uno::RuntimeException)
     274             : {
     275           0 :     return OUString("org.apache.openoffice.comp.framework.WizardsToolbarController");
     276             : }
     277             : 
     278           0 : sal_Bool WizardsToolbarController::supportsService(OUString const & rServiceName)
     279             :     throw (css::uno::RuntimeException)
     280             : {
     281           0 :     return cppu::supportsService( this, rServiceName );
     282             : }
     283             : 
     284           0 : css::uno::Sequence<OUString> WizardsToolbarController::getSupportedServiceNames()
     285             :     throw (css::uno::RuntimeException)
     286             : {
     287           0 :     css::uno::Sequence< OUString > aRet(1);
     288           0 :     OUString* pArray = aRet.getArray();
     289           0 :     pArray[0] = "com.sun.star.frame.ToolbarController";
     290           0 :     return aRet;
     291             : }
     292             : 
     293           0 : sal_uInt16 WizardsToolbarController::getDropDownStyle() const
     294             : {
     295           0 :     return TIB_DROPDOWNONLY;
     296             : }
     297             : 
     298         210 : class OpenToolbarController : public PopupMenuToolbarController
     299             : {
     300             : public:
     301             :     OpenToolbarController( const css::uno::Reference< css::uno::XComponentContext >& rxContext );
     302             : 
     303             :     // XServiceInfo
     304             :     virtual OUString SAL_CALL getImplementationName() throw (css::uno::RuntimeException) SAL_OVERRIDE;
     305             : 
     306             :     virtual sal_Bool SAL_CALL supportsService(OUString const & rServiceName) throw (css::uno::RuntimeException) SAL_OVERRIDE;
     307             : 
     308             :     virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() throw (css::uno::RuntimeException) SAL_OVERRIDE;
     309             : };
     310             : 
     311         105 : OpenToolbarController::OpenToolbarController(
     312             :     const css::uno::Reference< css::uno::XComponentContext >& xContext )
     313         105 :     : PopupMenuToolbarController( xContext, UNO_COMMAND_RECENT_FILE_LIST )
     314             : {
     315         105 : }
     316             : 
     317           0 : OUString OpenToolbarController::getImplementationName()
     318             :     throw (css::uno::RuntimeException)
     319             : {
     320           0 :     return OUString("org.apache.openoffice.comp.framework.OpenToolbarController");
     321             : }
     322             : 
     323           0 : sal_Bool OpenToolbarController::supportsService(OUString const & rServiceName)
     324             :     throw (css::uno::RuntimeException)
     325             : {
     326           0 :     return cppu::supportsService( this, rServiceName );
     327             : }
     328             : 
     329           0 : css::uno::Sequence<OUString> OpenToolbarController::getSupportedServiceNames()
     330             :     throw (css::uno::RuntimeException)
     331             : {
     332           0 :     css::uno::Sequence< OUString > aRet(1);
     333           0 :     OUString* pArray = aRet.getArray();
     334           0 :     pArray[0] = "com.sun.star.frame.ToolbarController";
     335           0 :     return aRet;
     336             : }
     337             : 
     338        1350 : class NewToolbarController : public PopupMenuToolbarController
     339             : {
     340             : public:
     341             :     NewToolbarController( const css::uno::Reference< css::uno::XComponentContext >& rxContext );
     342             : 
     343             :     // XServiceInfo
     344             :     OUString SAL_CALL getImplementationName()
     345             :         throw (css::uno::RuntimeException) SAL_OVERRIDE;
     346             : 
     347             :     virtual sal_Bool SAL_CALL supportsService(OUString const & rServiceName) throw (css::uno::RuntimeException) SAL_OVERRIDE;
     348             : 
     349             :     css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames()
     350             :         throw (css::uno::RuntimeException) SAL_OVERRIDE;
     351             : 
     352             :     void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) throw (css::uno::Exception, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     353             : 
     354             : private:
     355             :     void functionExecuted( const OUString &rCommand ) SAL_OVERRIDE;
     356             :     void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) throw ( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     357             :     void SAL_CALL execute( sal_Int16 KeyModifier ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     358             :     void setItemImage( const OUString &rCommand );
     359             : 
     360             :     OUString m_aLastURL;
     361             : };
     362             : 
     363         675 : NewToolbarController::NewToolbarController(
     364             :     const css::uno::Reference< css::uno::XComponentContext >& xContext )
     365         675 :     : PopupMenuToolbarController( xContext )
     366             : {
     367         675 : }
     368             : 
     369           0 : OUString NewToolbarController::getImplementationName()
     370             :     throw (css::uno::RuntimeException)
     371             : {
     372           0 :     return OUString("org.apache.openoffice.comp.framework.NewToolbarController");
     373             : }
     374             : 
     375           0 : sal_Bool NewToolbarController::supportsService(OUString const & rServiceName)
     376             :     throw (css::uno::RuntimeException)
     377             : {
     378           0 :     return cppu::supportsService( this, rServiceName );
     379             : }
     380             : 
     381           0 : css::uno::Sequence<OUString> NewToolbarController::getSupportedServiceNames()
     382             :     throw (css::uno::RuntimeException)
     383             : {
     384           0 :     css::uno::Sequence< OUString > aRet(1);
     385           0 :     OUString* pArray = aRet.getArray();
     386           0 :     pArray[0] = "com.sun.star.frame.ToolbarController";
     387           0 :     return aRet;
     388             : }
     389             : 
     390         675 : void SAL_CALL NewToolbarController::initialize( const css::uno::Sequence< css::uno::Any >& aArguments )
     391             : throw ( css::uno::Exception, css::uno::RuntimeException, std::exception )
     392             : {
     393         675 :     PopupMenuToolbarController::initialize( aArguments );
     394             : 
     395         675 :     osl::MutexGuard aGuard( m_aMutex );
     396         675 :     createPopupMenuController();
     397         675 : }
     398             : 
     399         994 : void SAL_CALL NewToolbarController::statusChanged( const css::frame::FeatureStateEvent& rEvent )
     400             :     throw ( css::uno::RuntimeException, std::exception )
     401             : {
     402         994 :     if ( rEvent.IsEnabled )
     403             :     {
     404         994 :         OUString aState;
     405         994 :         rEvent.State >>= aState;
     406             :         try
     407             :         {
     408             :             // set the image even if the state is not a string
     409             :             // this will set the image of the default module
     410         994 :             setItemImage( aState );
     411             :         }
     412           0 :         catch (const css::ucb::CommandFailedException&)
     413             :         {
     414         994 :         }
     415             :     }
     416             : 
     417         994 :     enable( rEvent.IsEnabled );
     418         994 : }
     419             : 
     420           0 : void SAL_CALL NewToolbarController::execute( sal_Int16 /*KeyModifier*/ )
     421             : throw ( css::uno::RuntimeException, std::exception )
     422             : {
     423           0 :     osl::MutexGuard aGuard( m_aMutex );
     424           0 :     if ( !m_aLastURL.getLength() )
     425           0 :         return;
     426             : 
     427           0 :     OUString aTarget( "_default" );
     428           0 :     if ( m_xPopupMenu.is() )
     429             :     {
     430             :         // TODO investigate how to wrap Get/SetUserValue in css::awt::XMenu
     431           0 :         MenuConfiguration::Attributes* pMenuAttributes( 0 );
     432             :         VCLXPopupMenu*  pTkPopupMenu =
     433           0 :             ( VCLXPopupMenu * ) VCLXMenu::GetImplementation( m_xPopupMenu );
     434             : 
     435           0 :         SolarMutexGuard aSolarMutexGuard;
     436           0 :         PopupMenu* pVCLPopupMenu = dynamic_cast< PopupMenu * >( pTkPopupMenu->GetMenu() );
     437           0 :         if ( pVCLPopupMenu )
     438             :             pMenuAttributes = reinterpret_cast< MenuConfiguration::Attributes* >(
     439           0 :                 pVCLPopupMenu->GetUserValue( pVCLPopupMenu->GetCurItemId() ) );
     440             : 
     441           0 :         if ( pMenuAttributes )
     442           0 :             aTarget = pMenuAttributes->aTargetFrame;
     443             :     }
     444             : 
     445           0 :     css::uno::Sequence< css::beans::PropertyValue > aArgs( 1 );
     446           0 :     aArgs[0].Name = "Referer";
     447           0 :     aArgs[0].Value <<= OUString( "private:user" );
     448             : 
     449           0 :     dispatchCommand( m_aLastURL, aArgs, aTarget );
     450             : }
     451             : 
     452           0 : void NewToolbarController::functionExecuted( const OUString &rCommand )
     453             : {
     454           0 :     setItemImage( rCommand );
     455           0 : }
     456             : 
     457             : /**
     458             :     it return the existing state of the given URL in the popupmenu of this toolbox control.
     459             : 
     460             :     If the given URL can be located as an action command of one menu item of the
     461             :     popup menu of this control, we return sal_True. Otherwhise we return sal_False.
     462             :     Further we return a fallback URL, in case we have to return sal_False. Because
     463             :     the outside code must select a valid item of the popup menu everytime ...
     464             :     and we define it here. By the way this m ethod was written to handle
     465             :     error situations gracefully. E.g. it can be called during creation time
     466             :     but then we have no valid menu. For this case we know another fallback URL.
     467             :     Then we return the private:factory/ URL of the default factory.
     468             : 
     469             :     @param  rPopupMenu
     470             :                 pounts to the popup menu, on which item we try to locate the given URL
     471             :                 Can be NULL! Search will be supressed then.
     472             : 
     473             :     @param  sURL
     474             :                 the URL for searching
     475             : 
     476             :     @param  sFallback
     477             :                 contains the fallback URL in case we return FALSE
     478             :                 Must point to valid memory!
     479             : 
     480             :     @param  aImage
     481             :                 contains the image of the menu for the URL.
     482             : 
     483             :     @return sal_True - if URL could be located as an item of the popup menu.
     484             :             sal_False - otherwhise.
     485             : */
     486         994 : static bool Impl_ExistURLInMenu(
     487             :     const css::uno::Reference< css::awt::XPopupMenu > &rPopupMenu,
     488             :     OUString &sURL,
     489             :     OUString &sFallback,
     490             :     Image &aImage )
     491             : {
     492         994 :     bool bValidFallback( false );
     493         994 :     sal_uInt16 nCount( 0 );
     494         994 :     if ( rPopupMenu.is() && ( nCount = rPopupMenu->getItemCount() ) != 0 && sURL.getLength() )
     495             :     {
     496        1672 :         for ( sal_uInt16 n = 0; n < nCount; ++n )
     497             :         {
     498        1672 :             sal_uInt16 nId = rPopupMenu->getItemId( n );
     499        1672 :             OUString aCmd( rPopupMenu->getCommand( nId ) );
     500             : 
     501        1672 :             if ( !bValidFallback && aCmd.getLength() )
     502             :             {
     503         977 :                 sFallback = aCmd;
     504         977 :                 bValidFallback = true;
     505             :             }
     506             : 
     507             :             // match even if the menu command is more detailed
     508             :             // (maybe an additional query) #i28667#
     509        1672 :             if ( aCmd.match( sURL ) )
     510             :             {
     511         977 :                 sURL = aCmd;
     512             :                 const css::uno::Reference< css::graphic::XGraphic > xGraphic(
     513         977 :                     rPopupMenu->getItemImage( nId ) );
     514         977 :                 if ( xGraphic.is() )
     515         977 :                     aImage = Image( xGraphic );
     516         977 :                 return true;
     517             :             }
     518         695 :         }
     519             :     }
     520             : 
     521          17 :     if ( !bValidFallback )
     522             :     {
     523          17 :         OUStringBuffer aBuffer;
     524          17 :         aBuffer.append( "private:factory/" );
     525          17 :         aBuffer.append( SvtModuleOptions().GetDefaultModuleName() );
     526          17 :         sFallback = aBuffer.makeStringAndClear();
     527             :     }
     528             : 
     529          17 :     return false;
     530             : }
     531             : 
     532             : /** We accept URL's here only, which exist as items of our internal popup menu.
     533             :     All other ones will be ignored and a fallback is used.
     534             :  */
     535         994 : void NewToolbarController::setItemImage( const OUString &rCommand )
     536             : {
     537         994 :     SolarMutexGuard aSolarLock;
     538         994 :     ToolBox* pToolBox = static_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ) );
     539         994 :     if ( !pToolBox )
     540           0 :         return;
     541             : 
     542        1988 :     OUString aURL = rCommand;
     543        1988 :     OUString sFallback;
     544        1988 :     Image aMenuImage;
     545             : 
     546         994 :     bool bValid( Impl_ExistURLInMenu( m_xPopupMenu, aURL, sFallback, aMenuImage ) );
     547         994 :     if ( !bValid )
     548          17 :         aURL = sFallback;
     549             : 
     550         994 :     bool bBig = SvtMiscOptions().AreCurrentSymbolsLarge();
     551             : 
     552        1988 :     INetURLObject aURLObj( aURL );
     553        1988 :     Image aImage = SvFileInformationManager::GetImageNoDefault( aURLObj, bBig );
     554         994 :     if ( !aImage )
     555           0 :         aImage = !!aMenuImage ?
     556             :             aMenuImage :
     557           0 :             SvFileInformationManager::GetImage( aURLObj, bBig );
     558             : 
     559             :     // if everything failed, just use the image associated with the toolbar item command
     560         994 :     if ( !aImage )
     561           0 :         return;
     562             : 
     563         994 :     Size aBigSize( pToolBox->GetDefaultImageSize() );
     564         994 :     if ( bBig && aImage.GetSizePixel() != aBigSize )
     565             :     {
     566           0 :         BitmapEx aScaleBmpEx( aImage.GetBitmapEx() );
     567           0 :         aScaleBmpEx.Scale( aBigSize, BMP_SCALE_INTERPOLATE );
     568           0 :         pToolBox->SetItemImage( m_nToolBoxId, Image( aScaleBmpEx ) );
     569             :     }
     570             :     else
     571         994 :         pToolBox->SetItemImage( m_nToolBoxId, aImage );
     572             : 
     573        1988 :     m_aLastURL = aURL;
     574             : }
     575             : 
     576             : }
     577             : 
     578             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     579           0 : org_apache_openoffice_comp_framework_WizardsToolbarController_get_implementation(
     580             :     css::uno::XComponentContext *context,
     581             :     css::uno::Sequence<css::uno::Any> const &)
     582             : {
     583           0 :     return cppu::acquire(new WizardsToolbarController(context));
     584             : }
     585             : 
     586             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     587         105 : org_apache_openoffice_comp_framework_OpenToolbarController_get_implementation(
     588             :     css::uno::XComponentContext *context,
     589             :     css::uno::Sequence<css::uno::Any> const &)
     590             : {
     591         105 :     return cppu::acquire(new OpenToolbarController(context));
     592             : }
     593             : 
     594             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     595         675 : org_apache_openoffice_comp_framework_NewToolbarController_get_implementation(
     596             :     css::uno::XComponentContext *context,
     597             :     css::uno::Sequence<css::uno::Any> const &)
     598             : {
     599         675 :     return cppu::acquire(new NewToolbarController(context));
     600             : }
     601             : 
     602             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10