LCOV - code coverage report
Current view: top level - framework/source/uielement - popuptoolbarcontroller.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 152 216 70.4 %
Date: 2015-06-13 12:38:46 Functions: 29 38 76.3 %
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             : #include <com/sun/star/ucb/ContentCreationException.hpp>
      44             : 
      45             : #define UNO_COMMAND_RECENT_FILE_LIST    ".uno:RecentFileList"
      46             : 
      47             : using namespace framework;
      48             : 
      49             : namespace {
      50             : 
      51             : typedef cppu::ImplInheritanceHelper1< svt::ToolboxController,
      52             :                                     css::lang::XServiceInfo >
      53             :                 ToolBarBase;
      54             : 
      55             : class PopupMenuToolbarController : public ToolBarBase
      56             : {
      57             : public:
      58             :     virtual ~PopupMenuToolbarController();
      59             : 
      60             :     // XComponent
      61             :     virtual void SAL_CALL dispose() throw ( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
      62             :     // XInitialization
      63             :     virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) throw (css::uno::Exception, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      64             :     // XToolbarController
      65             :     virtual css::uno::Reference< css::awt::XWindow > SAL_CALL createPopupWindow() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      66             :     // XStatusListener
      67             :     virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) throw ( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
      68             : 
      69             : protected:
      70             :     PopupMenuToolbarController( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
      71             :                                 const OUString &rPopupCommand = OUString() );
      72             :     virtual void functionExecuted( const OUString &rCommand );
      73             :     virtual ToolBoxItemBits getDropDownStyle() const;
      74             :     void createPopupMenuController();
      75             : 
      76             :     css::uno::Reference< css::uno::XComponentContext >      m_xContext;
      77             :     bool                                                m_bHasController;
      78             :     css::uno::Reference< css::awt::XPopupMenu >             m_xPopupMenu;
      79             : 
      80             : private:
      81             :     OUString m_aPopupCommand;
      82             :     css::uno::Reference< css::frame::XUIControllerFactory > m_xPopupMenuFactory;
      83             :     css::uno::Reference< css::frame::XPopupMenuController > m_xPopupMenuController;
      84             : };
      85             : 
      86         709 : PopupMenuToolbarController::PopupMenuToolbarController(
      87             :     const css::uno::Reference< css::uno::XComponentContext >& xContext,
      88             :     const OUString &rPopupCommand )
      89             :     : m_xContext( xContext )
      90             :     , m_bHasController( false )
      91         709 :     , m_aPopupCommand( rPopupCommand )
      92             : {
      93         709 : }
      94             : 
      95         709 : PopupMenuToolbarController::~PopupMenuToolbarController()
      96             : {
      97         709 : }
      98             : 
      99         709 : void SAL_CALL PopupMenuToolbarController::dispose()
     100             : throw ( css::uno::RuntimeException, std::exception )
     101             : {
     102         709 :     svt::ToolboxController::dispose();
     103             : 
     104         709 :     osl::MutexGuard aGuard( m_aMutex );
     105         709 :     if( m_xPopupMenuController.is() )
     106             :     {
     107             :         css::uno::Reference< css::lang::XComponent > xComponent(
     108         606 :             m_xPopupMenuController, css::uno::UNO_QUERY );
     109         606 :         if( xComponent.is() )
     110             :         {
     111             :             try
     112             :             {
     113         606 :                 xComponent->dispose();
     114             :             }
     115           0 :             catch (...)
     116             :             {}
     117             :         }
     118         606 :         m_xPopupMenuController.clear();
     119             :     }
     120             : 
     121         709 :     m_xContext.clear();
     122         709 :     m_xPopupMenuFactory.clear();
     123         709 :     m_xPopupMenu.clear();
     124         709 : }
     125             : 
     126         706 : void SAL_CALL PopupMenuToolbarController::initialize(
     127             :     const css::uno::Sequence< css::uno::Any >& aArguments )
     128             : throw ( css::uno::Exception, css::uno::RuntimeException, std::exception )
     129             : {
     130         706 :     ToolboxController::initialize( aArguments );
     131             : 
     132         706 :     osl::MutexGuard aGuard( m_aMutex );
     133         706 :     if ( !m_aPopupCommand.getLength() )
     134         606 :         m_aPopupCommand = m_aCommandURL;
     135             : 
     136             :     try
     137             :     {
     138             :         m_xPopupMenuFactory.set(
     139         706 :             css::frame::thePopupMenuControllerFactory::get( m_xContext ) );
     140         706 :         m_bHasController = m_xPopupMenuFactory->hasController(
     141         706 :             m_aPopupCommand, getModuleName() );
     142             :     }
     143           0 :     catch (const css::uno::Exception& e)
     144             :     {
     145             :         SAL_INFO( "fwk.uielement", "Caught an exception: " << e.Message );
     146             :     }
     147             : 
     148        1412 :     SolarMutexGuard aSolarLock;
     149        1412 :     VclPtr< ToolBox > pToolBox = static_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ).get() );
     150         706 :     if ( pToolBox )
     151             :     {
     152         706 :         ToolBoxItemBits nCurStyle( pToolBox->GetItemBits( m_nToolBoxId ) );
     153         706 :         ToolBoxItemBits nSetStyle( getDropDownStyle() );
     154             :         pToolBox->SetItemBits( m_nToolBoxId,
     155             :                                m_bHasController ?
     156             :                                     nCurStyle | nSetStyle :
     157         706 :                                     nCurStyle & ~nSetStyle );
     158         706 :     }
     159             : 
     160         706 : }
     161             : 
     162         144 : void SAL_CALL PopupMenuToolbarController::statusChanged( const css::frame::FeatureStateEvent& rEvent )
     163             :     throw ( css::uno::RuntimeException, std::exception )
     164             : {
     165             :     // TODO move to base class
     166             : 
     167         144 :     svt::ToolboxController::statusChanged( rEvent );
     168         144 :     enable( rEvent.IsEnabled );
     169         144 : }
     170             : 
     171             : css::uno::Reference< css::awt::XWindow > SAL_CALL
     172           0 : PopupMenuToolbarController::createPopupWindow()
     173             :     throw ( css::uno::RuntimeException, std::exception )
     174             : {
     175           0 :     css::uno::Reference< css::awt::XWindow > xRet;
     176             : 
     177           0 :     osl::MutexGuard aGuard( m_aMutex );
     178           0 :     if ( !m_bHasController )
     179           0 :         return xRet;
     180             : 
     181           0 :     createPopupMenuController();
     182             : 
     183           0 :     SolarMutexGuard aSolarLock;
     184           0 :     VclPtr< ToolBox > pToolBox = static_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ).get() );
     185           0 :     if ( !pToolBox )
     186           0 :         return xRet;
     187             : 
     188           0 :     pToolBox->SetItemDown( m_nToolBoxId, true );
     189           0 :     WindowAlign eAlign( pToolBox->GetAlign() );
     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 :         ( eAlign == WINDOWALIGN_TOP || eAlign == WINDOWALIGN_BOTTOM ) ?
     194             :             css::awt::PopupMenuDirection::EXECUTE_DOWN :
     195           0 :             css::awt::PopupMenuDirection::EXECUTE_RIGHT );
     196           0 :     pToolBox->SetItemDown( m_nToolBoxId, false );
     197             : 
     198           0 :     if ( nId )
     199           0 :         functionExecuted( m_xPopupMenu->getCommand( nId ) );
     200             : 
     201           0 :     return xRet;
     202             : }
     203             : 
     204           0 : void PopupMenuToolbarController::functionExecuted( const OUString &/*rCommand*/)
     205             : {
     206           0 : }
     207             : 
     208         706 : ToolBoxItemBits PopupMenuToolbarController::getDropDownStyle() const
     209             : {
     210         706 :     return ToolBoxItemBits::DROPDOWN;
     211             : }
     212             : 
     213         606 : void PopupMenuToolbarController::createPopupMenuController()
     214             : {
     215         606 :     if( !m_bHasController )
     216         606 :         return;
     217             : 
     218         606 :     if ( !m_xPopupMenuController.is() )
     219             :     {
     220         606 :         css::uno::Sequence< css::uno::Any > aArgs( 2 );
     221        1212 :         css::beans::PropertyValue aProp;
     222             : 
     223         606 :         aProp.Name = "Frame";
     224         606 :         aProp.Value <<= m_xFrame;
     225         606 :         aArgs[0] <<= aProp;
     226             : 
     227         606 :         aProp.Name = "ModuleIdentifier";
     228         606 :         aProp.Value <<= getModuleName();
     229         606 :         aArgs[1] <<= aProp;
     230             :         try
     231             :         {
     232             :             m_xPopupMenu.set(
     233        1212 :                 m_xContext->getServiceManager()->createInstanceWithContext(
     234         606 :                     "com.sun.star.awt.PopupMenu", m_xContext ),
     235         606 :                         css::uno::UNO_QUERY_THROW );
     236             :             m_xPopupMenuController.set(
     237         606 :                 m_xPopupMenuFactory->createInstanceWithArgumentsAndContext(
     238         606 :                     m_aPopupCommand, aArgs, m_xContext), css::uno::UNO_QUERY_THROW );
     239             : 
     240         606 :             m_xPopupMenuController->setPopupMenu( m_xPopupMenu );
     241             :         }
     242           0 :         catch ( const css::uno::Exception &e )
     243             :         {
     244           0 :             m_xPopupMenu.clear();
     245             :             SAL_INFO( "fwk.uielement", "Caught an exception: " << e.Message );
     246         606 :         }
     247             :     }
     248             : }
     249             : 
     250           2 : 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             :     ToolBoxItemBits getDropDownStyle() const SAL_OVERRIDE;
     264             : };
     265             : 
     266           1 : WizardsToolbarController::WizardsToolbarController(
     267             :     const css::uno::Reference< css::uno::XComponentContext >& xContext )
     268           1 :     : PopupMenuToolbarController( xContext )
     269             : {
     270           1 : }
     271             : 
     272           1 : OUString WizardsToolbarController::getImplementationName()
     273             :     throw (css::uno::RuntimeException)
     274             : {
     275           1 :     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           1 : css::uno::Sequence<OUString> WizardsToolbarController::getSupportedServiceNames()
     285             :     throw (css::uno::RuntimeException)
     286             : {
     287           1 :     css::uno::Sequence< OUString > aRet(1);
     288           1 :     OUString* pArray = aRet.getArray();
     289           1 :     pArray[0] = "com.sun.star.frame.ToolbarController";
     290           1 :     return aRet;
     291             : }
     292             : 
     293           0 : ToolBoxItemBits WizardsToolbarController::getDropDownStyle() const
     294             : {
     295           0 :     return ToolBoxItemBits::DROPDOWNONLY;
     296             : }
     297             : 
     298         202 : 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         101 : OpenToolbarController::OpenToolbarController(
     312             :     const css::uno::Reference< css::uno::XComponentContext >& xContext )
     313         101 :     : PopupMenuToolbarController( xContext, UNO_COMMAND_RECENT_FILE_LIST )
     314             : {
     315         101 : }
     316             : 
     317           1 : OUString OpenToolbarController::getImplementationName()
     318             :     throw (css::uno::RuntimeException)
     319             : {
     320           1 :     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           1 : css::uno::Sequence<OUString> OpenToolbarController::getSupportedServiceNames()
     330             :     throw (css::uno::RuntimeException)
     331             : {
     332           1 :     css::uno::Sequence< OUString > aRet(1);
     333           1 :     OUString* pArray = aRet.getArray();
     334           1 :     pArray[0] = "com.sun.star.frame.ToolbarController";
     335           1 :     return aRet;
     336             : }
     337             : 
     338        1214 : 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         607 : NewToolbarController::NewToolbarController(
     364             :     const css::uno::Reference< css::uno::XComponentContext >& xContext )
     365         607 :     : PopupMenuToolbarController( xContext )
     366             : {
     367         607 : }
     368             : 
     369           1 : OUString NewToolbarController::getImplementationName()
     370             :     throw (css::uno::RuntimeException)
     371             : {
     372           1 :     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           1 : css::uno::Sequence<OUString> NewToolbarController::getSupportedServiceNames()
     382             :     throw (css::uno::RuntimeException)
     383             : {
     384           1 :     css::uno::Sequence< OUString > aRet(1);
     385           1 :     OUString* pArray = aRet.getArray();
     386           1 :     pArray[0] = "com.sun.star.frame.ToolbarController";
     387           1 :     return aRet;
     388             : }
     389             : 
     390         606 : 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         606 :     PopupMenuToolbarController::initialize( aArguments );
     394             : 
     395         606 :     osl::MutexGuard aGuard( m_aMutex );
     396         606 :     createPopupMenuController();
     397         606 : }
     398             : 
     399        1000 : void SAL_CALL NewToolbarController::statusChanged( const css::frame::FeatureStateEvent& rEvent )
     400             :     throw ( css::uno::RuntimeException, std::exception )
     401             : {
     402        1000 :     if ( rEvent.IsEnabled )
     403             :     {
     404        1000 :         OUString aState;
     405        1000 :         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        1000 :             setItemImage( aState );
     411             :         }
     412           0 :         catch (const css::ucb::CommandFailedException&)
     413             :         {
     414             :         }
     415           0 :         catch (const css::ucb::ContentCreationException&)
     416             :         {
     417        1000 :         }
     418             :     }
     419             : 
     420        1000 :     enable( rEvent.IsEnabled );
     421        1000 : }
     422             : 
     423           0 : void SAL_CALL NewToolbarController::execute( sal_Int16 /*KeyModifier*/ )
     424             : throw ( css::uno::RuntimeException, std::exception )
     425             : {
     426           0 :     osl::MutexGuard aGuard( m_aMutex );
     427           0 :     if ( !m_aLastURL.getLength() )
     428           0 :         return;
     429             : 
     430           0 :     OUString aTarget( "_default" );
     431           0 :     if ( m_xPopupMenu.is() )
     432             :     {
     433             :         // TODO investigate how to wrap Get/SetUserValue in css::awt::XMenu
     434           0 :         MenuAttributes* pMenuAttributes( 0 );
     435             :         VCLXPopupMenu*  pTkPopupMenu =
     436           0 :             static_cast<VCLXPopupMenu *>( VCLXMenu::GetImplementation( m_xPopupMenu ) );
     437             : 
     438           0 :         SolarMutexGuard aSolarMutexGuard;
     439             :         PopupMenu* pVCLPopupMenu = pTkPopupMenu ?
     440           0 :             dynamic_cast< PopupMenu * >( pTkPopupMenu->GetMenu() ) : NULL;
     441             : 
     442           0 :         if ( pVCLPopupMenu )
     443             :             pMenuAttributes = reinterpret_cast< MenuAttributes* >(
     444           0 :                 pVCLPopupMenu->GetUserValue( pVCLPopupMenu->GetCurItemId() ) );
     445             : 
     446           0 :         if ( pMenuAttributes )
     447           0 :             aTarget = pMenuAttributes->aTargetFrame;
     448             :     }
     449             : 
     450           0 :     css::uno::Sequence< css::beans::PropertyValue > aArgs( 1 );
     451           0 :     aArgs[0].Name = "Referer";
     452           0 :     aArgs[0].Value <<= OUString( "private:user" );
     453             : 
     454           0 :     dispatchCommand( m_aLastURL, aArgs, aTarget );
     455             : }
     456             : 
     457           0 : void NewToolbarController::functionExecuted( const OUString &rCommand )
     458             : {
     459           0 :     setItemImage( rCommand );
     460           0 : }
     461             : 
     462             : /**
     463             :     it return the existing state of the given URL in the popupmenu of this toolbox control.
     464             : 
     465             :     If the given URL can be located as an action command of one menu item of the
     466             :     popup menu of this control, we return sal_True. Otherwhise we return sal_False.
     467             :     Further we return a fallback URL, in case we have to return sal_False. Because
     468             :     the outside code must select a valid item of the popup menu every time ...
     469             :     and we define it here. By the way this m ethod was written to handle
     470             :     error situations gracefully. E.g. it can be called during creation time
     471             :     but then we have no valid menu. For this case we know another fallback URL.
     472             :     Then we return the private:factory/ URL of the default factory.
     473             : 
     474             :     @param  rPopupMenu
     475             :                 pounts to the popup menu, on which item we try to locate the given URL
     476             :                 Can be NULL! Search will be suppressed then.
     477             : 
     478             :     @param  sURL
     479             :                 the URL for searching
     480             : 
     481             :     @param  sFallback
     482             :                 contains the fallback URL in case we return FALSE
     483             :                 Must point to valid memory!
     484             : 
     485             :     @param  aImage
     486             :                 contains the image of the menu for the URL.
     487             : 
     488             :     @return sal_True - if URL could be located as an item of the popup menu.
     489             :             sal_False - otherwhise.
     490             : */
     491        1000 : static bool Impl_ExistURLInMenu(
     492             :     const css::uno::Reference< css::awt::XPopupMenu > &rPopupMenu,
     493             :     OUString &sURL,
     494             :     OUString &sFallback,
     495             :     Image &aImage )
     496             : {
     497        1000 :     bool bValidFallback( false );
     498        1000 :     sal_uInt16 nCount( 0 );
     499        1000 :     if ( rPopupMenu.is() && ( nCount = rPopupMenu->getItemCount() ) != 0 && sURL.getLength() )
     500             :     {
     501        1731 :         for ( sal_uInt16 n = 0; n < nCount; ++n )
     502             :         {
     503        1731 :             sal_uInt16 nId = rPopupMenu->getItemId( n );
     504        1731 :             OUString aCmd( rPopupMenu->getCommand( nId ) );
     505             : 
     506        1731 :             if ( !bValidFallback && aCmd.getLength() )
     507             :             {
     508         983 :                 sFallback = aCmd;
     509         983 :                 bValidFallback = true;
     510             :             }
     511             : 
     512             :             // match even if the menu command is more detailed
     513             :             // (maybe an additional query) #i28667#
     514        1731 :             if ( aCmd.match( sURL ) )
     515             :             {
     516         983 :                 sURL = aCmd;
     517             :                 const css::uno::Reference< css::graphic::XGraphic > xGraphic(
     518         983 :                     rPopupMenu->getItemImage( nId ) );
     519         983 :                 if ( xGraphic.is() )
     520         983 :                     aImage = Image( xGraphic );
     521         983 :                 return true;
     522             :             }
     523         748 :         }
     524             :     }
     525             : 
     526          17 :     if ( !bValidFallback )
     527             :     {
     528          17 :         OUStringBuffer aBuffer;
     529          17 :         aBuffer.append( "private:factory/" );
     530          17 :         aBuffer.append( SvtModuleOptions().GetDefaultModuleName() );
     531          17 :         sFallback = aBuffer.makeStringAndClear();
     532             :     }
     533             : 
     534          17 :     return false;
     535             : }
     536             : 
     537             : /** We accept URL's here only, which exist as items of our internal popup menu.
     538             :     All other ones will be ignored and a fallback is used.
     539             :  */
     540        1000 : void NewToolbarController::setItemImage( const OUString &rCommand )
     541             : {
     542        1000 :     SolarMutexGuard aSolarLock;
     543        2000 :     VclPtr< ToolBox> pToolBox = static_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ).get() );
     544        1000 :     if ( !pToolBox )
     545           0 :         return;
     546             : 
     547        2000 :     OUString aURL = rCommand;
     548        2000 :     OUString sFallback;
     549        2000 :     Image aMenuImage;
     550             : 
     551        1000 :     bool bValid( Impl_ExistURLInMenu( m_xPopupMenu, aURL, sFallback, aMenuImage ) );
     552        1000 :     if ( !bValid )
     553          17 :         aURL = sFallback;
     554             : 
     555        1000 :     bool bBig = SvtMiscOptions().AreCurrentSymbolsLarge();
     556             : 
     557        2000 :     INetURLObject aURLObj( aURL );
     558        2000 :     Image aImage = SvFileInformationManager::GetImageNoDefault( aURLObj, bBig );
     559        1000 :     if ( !aImage )
     560           0 :         aImage = !!aMenuImage ?
     561             :             aMenuImage :
     562           0 :             SvFileInformationManager::GetImage( aURLObj, bBig );
     563             : 
     564             :     // if everything failed, just use the image associated with the toolbar item command
     565        1000 :     if ( !aImage )
     566           0 :         return;
     567             : 
     568        1000 :     Size aBigSize( pToolBox->GetDefaultImageSize() );
     569        1000 :     if ( bBig && aImage.GetSizePixel() != aBigSize )
     570             :     {
     571           0 :         BitmapEx aScaleBmpEx( aImage.GetBitmapEx() );
     572           0 :         aScaleBmpEx.Scale( aBigSize, BmpScaleFlag::Interpolate );
     573           0 :         pToolBox->SetItemImage( m_nToolBoxId, Image( aScaleBmpEx ) );
     574             :     }
     575             :     else
     576        1000 :         pToolBox->SetItemImage( m_nToolBoxId, aImage );
     577             : 
     578        2000 :     m_aLastURL = aURL;
     579             : }
     580             : 
     581             : }
     582             : 
     583             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     584           1 : org_apache_openoffice_comp_framework_WizardsToolbarController_get_implementation(
     585             :     css::uno::XComponentContext *context,
     586             :     css::uno::Sequence<css::uno::Any> const &)
     587             : {
     588           1 :     return cppu::acquire(new WizardsToolbarController(context));
     589             : }
     590             : 
     591             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     592         101 : org_apache_openoffice_comp_framework_OpenToolbarController_get_implementation(
     593             :     css::uno::XComponentContext *context,
     594             :     css::uno::Sequence<css::uno::Any> const &)
     595             : {
     596         101 :     return cppu::acquire(new OpenToolbarController(context));
     597             : }
     598             : 
     599             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     600         607 : org_apache_openoffice_comp_framework_NewToolbarController_get_implementation(
     601             :     css::uno::XComponentContext *context,
     602             :     css::uno::Sequence<css::uno::Any> const &)
     603             : {
     604         607 :     return cppu::acquire(new NewToolbarController(context));
     605             : }
     606             : 
     607             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11