LCOV - code coverage report
Current view: top level - framework/source/uielement - popuptoolbarcontroller.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 128 217 59.0 %
Date: 2014-11-03 Functions: 21 40 52.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <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        1770 : PopupMenuToolbarController::PopupMenuToolbarController(
      87             :     const css::uno::Reference< css::uno::XComponentContext >& xContext,
      88             :     const OUString &rPopupCommand )
      89             :     : m_xContext( xContext )
      90             :     , m_bHasController( false )
      91        1770 :     , m_aPopupCommand( rPopupCommand )
      92             : {
      93        1770 : }
      94             : 
      95        1770 : PopupMenuToolbarController::~PopupMenuToolbarController()
      96             : {
      97        1770 : }
      98             : 
      99        1770 : void SAL_CALL PopupMenuToolbarController::dispose()
     100             : throw ( css::uno::RuntimeException, std::exception )
     101             : {
     102        1770 :     svt::ToolboxController::dispose();
     103             : 
     104        1770 :     osl::MutexGuard aGuard( m_aMutex );
     105        1770 :     if( m_xPopupMenuController.is() )
     106             :     {
     107             :         css::uno::Reference< css::lang::XComponent > xComponent(
     108        1494 :             m_xPopupMenuController, css::uno::UNO_QUERY );
     109        1494 :         if( xComponent.is() )
     110             :         {
     111             :             try
     112             :             {
     113        1494 :                 xComponent->dispose();
     114             :             }
     115           0 :             catch (...)
     116             :             {}
     117             :         }
     118        1494 :         m_xPopupMenuController.clear();
     119             :     }
     120             : 
     121        1770 :     m_xContext.clear();
     122        1770 :     m_xPopupMenuFactory.clear();
     123        1770 :     m_xPopupMenu.clear();
     124        1770 : }
     125             : 
     126        1770 : 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        1770 :     ToolboxController::initialize( aArguments );
     131             : 
     132        1770 :     osl::MutexGuard aGuard( m_aMutex );
     133        1770 :     if ( !m_aPopupCommand.getLength() )
     134        1500 :         m_aPopupCommand = m_aCommandURL;
     135             : 
     136             :     try
     137             :     {
     138             :         m_xPopupMenuFactory.set(
     139        1770 :             css::frame::thePopupMenuControllerFactory::get( m_xContext ) );
     140        1770 :         m_bHasController = m_xPopupMenuFactory->hasController(
     141        1770 :             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        3540 :     SolarMutexGuard aSolarLock;
     149        1770 :     ToolBox* pToolBox = static_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ) );
     150        1770 :     if ( pToolBox )
     151             :     {
     152        1770 :         ToolBoxItemBits nCurStyle( pToolBox->GetItemBits( m_nToolBoxId ) );
     153        1770 :         ToolBoxItemBits nSetStyle( getDropDownStyle() );
     154             :         pToolBox->SetItemBits( m_nToolBoxId,
     155             :                                m_bHasController ?
     156             :                                     nCurStyle | nSetStyle :
     157        1770 :                                     nCurStyle & ~nSetStyle );
     158        1770 :     }
     159             : 
     160        1770 : }
     161             : 
     162         162 : 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         162 :     svt::ToolboxController::statusChanged( rEvent );
     168         162 :     enable( rEvent.IsEnabled );
     169         162 : }
     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 :     ToolBox* pToolBox = static_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ) );
     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        1770 : ToolBoxItemBits PopupMenuToolbarController::getDropDownStyle() const
     209             : {
     210        1770 :     return ToolBoxItemBits::DROPDOWN;
     211             : }
     212             : 
     213        1500 : void PopupMenuToolbarController::createPopupMenuController()
     214             : {
     215        1500 :     if( !m_bHasController )
     216        1500 :         return;
     217             : 
     218        1500 :     if ( !m_xPopupMenuController.is() )
     219             :     {
     220        1500 :         css::uno::Sequence< css::uno::Any > aArgs( 2 );
     221        3000 :         css::beans::PropertyValue aProp;
     222             : 
     223        1500 :         aProp.Name = "Frame";
     224        1500 :         aProp.Value <<= m_xFrame;
     225        1500 :         aArgs[0] <<= aProp;
     226             : 
     227        1500 :         aProp.Name = "ModuleIdentifier";
     228        1500 :         aProp.Value <<= getModuleName();
     229        1500 :         aArgs[1] <<= aProp;
     230             :         try
     231             :         {
     232             :             m_xPopupMenu.set(
     233        3000 :                 m_xContext->getServiceManager()->createInstanceWithContext(
     234        1500 :                     "com.sun.star.awt.PopupMenu", m_xContext ),
     235        1500 :                         css::uno::UNO_QUERY_THROW );
     236             :             m_xPopupMenuController.set(
     237        1500 :                 m_xPopupMenuFactory->createInstanceWithArgumentsAndContext(
     238        1506 :                     m_aPopupCommand, aArgs, m_xContext), css::uno::UNO_QUERY_THROW );
     239             : 
     240        1494 :             m_xPopupMenuController->setPopupMenu( m_xPopupMenu );
     241             :         }
     242           6 :         catch ( const css::uno::Exception &e )
     243             :         {
     244           6 :             m_xPopupMenu.clear();
     245             :             SAL_INFO( "fwk.uielement", "Caught an exception: " << e.Message );
     246        1500 :         }
     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             :     ToolBoxItemBits 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 : ToolBoxItemBits WizardsToolbarController::getDropDownStyle() const
     294             : {
     295           0 :     return ToolBoxItemBits::DROPDOWNONLY;
     296             : }
     297             : 
     298         540 : 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         270 : OpenToolbarController::OpenToolbarController(
     312             :     const css::uno::Reference< css::uno::XComponentContext >& xContext )
     313         270 :     : PopupMenuToolbarController( xContext, UNO_COMMAND_RECENT_FILE_LIST )
     314             : {
     315         270 : }
     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        3000 : 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        1500 : NewToolbarController::NewToolbarController(
     364             :     const css::uno::Reference< css::uno::XComponentContext >& xContext )
     365        1500 :     : PopupMenuToolbarController( xContext )
     366             : {
     367        1500 : }
     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        1500 : 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        1500 :     PopupMenuToolbarController::initialize( aArguments );
     394             : 
     395        1500 :     osl::MutexGuard aGuard( m_aMutex );
     396        1500 :     createPopupMenuController();
     397        1500 : }
     398             : 
     399        1369 : void SAL_CALL NewToolbarController::statusChanged( const css::frame::FeatureStateEvent& rEvent )
     400             :     throw ( css::uno::RuntimeException, std::exception )
     401             : {
     402        1369 :     if ( rEvent.IsEnabled )
     403             :     {
     404        1369 :         OUString aState;
     405        1369 :         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        1369 :             setItemImage( aState );
     411             :         }
     412           0 :         catch (const css::ucb::CommandFailedException&)
     413             :         {
     414             :         }
     415           0 :         catch (const css::ucb::ContentCreationException&)
     416             :         {
     417        1369 :         }
     418             :     }
     419             : 
     420        1369 :     enable( rEvent.IsEnabled );
     421        1369 : }
     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 :         MenuConfiguration::Attributes* 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           0 :         if ( pVCLPopupMenu )
     442             :             pMenuAttributes = reinterpret_cast< MenuConfiguration::Attributes* >(
     443           0 :                 pVCLPopupMenu->GetUserValue( pVCLPopupMenu->GetCurItemId() ) );
     444             : 
     445           0 :         if ( pMenuAttributes )
     446           0 :             aTarget = pMenuAttributes->aTargetFrame;
     447             :     }
     448             : 
     449           0 :     css::uno::Sequence< css::beans::PropertyValue > aArgs( 1 );
     450           0 :     aArgs[0].Name = "Referer";
     451           0 :     aArgs[0].Value <<= OUString( "private:user" );
     452             : 
     453           0 :     dispatchCommand( m_aLastURL, aArgs, aTarget );
     454             : }
     455             : 
     456           0 : void NewToolbarController::functionExecuted( const OUString &rCommand )
     457             : {
     458           0 :     setItemImage( rCommand );
     459           0 : }
     460             : 
     461             : /**
     462             :     it return the existing state of the given URL in the popupmenu of this toolbox control.
     463             : 
     464             :     If the given URL can be located as an action command of one menu item of the
     465             :     popup menu of this control, we return sal_True. Otherwhise we return sal_False.
     466             :     Further we return a fallback URL, in case we have to return sal_False. Because
     467             :     the outside code must select a valid item of the popup menu every time ...
     468             :     and we define it here. By the way this m ethod was written to handle
     469             :     error situations gracefully. E.g. it can be called during creation time
     470             :     but then we have no valid menu. For this case we know another fallback URL.
     471             :     Then we return the private:factory/ URL of the default factory.
     472             : 
     473             :     @param  rPopupMenu
     474             :                 pounts to the popup menu, on which item we try to locate the given URL
     475             :                 Can be NULL! Search will be suppressed then.
     476             : 
     477             :     @param  sURL
     478             :                 the URL for searching
     479             : 
     480             :     @param  sFallback
     481             :                 contains the fallback URL in case we return FALSE
     482             :                 Must point to valid memory!
     483             : 
     484             :     @param  aImage
     485             :                 contains the image of the menu for the URL.
     486             : 
     487             :     @return sal_True - if URL could be located as an item of the popup menu.
     488             :             sal_False - otherwhise.
     489             : */
     490        1369 : static bool Impl_ExistURLInMenu(
     491             :     const css::uno::Reference< css::awt::XPopupMenu > &rPopupMenu,
     492             :     OUString &sURL,
     493             :     OUString &sFallback,
     494             :     Image &aImage )
     495             : {
     496        1369 :     bool bValidFallback( false );
     497        1369 :     sal_uInt16 nCount( 0 );
     498        1369 :     if ( rPopupMenu.is() && ( nCount = rPopupMenu->getItemCount() ) != 0 && sURL.getLength() )
     499             :     {
     500        2049 :         for ( sal_uInt16 n = 0; n < nCount; ++n )
     501             :         {
     502        2049 :             sal_uInt16 nId = rPopupMenu->getItemId( n );
     503        2049 :             OUString aCmd( rPopupMenu->getCommand( nId ) );
     504             : 
     505        2049 :             if ( !bValidFallback && aCmd.getLength() )
     506             :             {
     507        1336 :                 sFallback = aCmd;
     508        1336 :                 bValidFallback = true;
     509             :             }
     510             : 
     511             :             // match even if the menu command is more detailed
     512             :             // (maybe an additional query) #i28667#
     513        2049 :             if ( aCmd.match( sURL ) )
     514             :             {
     515        1336 :                 sURL = aCmd;
     516             :                 const css::uno::Reference< css::graphic::XGraphic > xGraphic(
     517        1336 :                     rPopupMenu->getItemImage( nId ) );
     518        1336 :                 if ( xGraphic.is() )
     519        1336 :                     aImage = Image( xGraphic );
     520        1336 :                 return true;
     521             :             }
     522         713 :         }
     523             :     }
     524             : 
     525          33 :     if ( !bValidFallback )
     526             :     {
     527          33 :         OUStringBuffer aBuffer;
     528          33 :         aBuffer.append( "private:factory/" );
     529          33 :         aBuffer.append( SvtModuleOptions().GetDefaultModuleName() );
     530          33 :         sFallback = aBuffer.makeStringAndClear();
     531             :     }
     532             : 
     533          33 :     return false;
     534             : }
     535             : 
     536             : /** We accept URL's here only, which exist as items of our internal popup menu.
     537             :     All other ones will be ignored and a fallback is used.
     538             :  */
     539        1369 : void NewToolbarController::setItemImage( const OUString &rCommand )
     540             : {
     541        1369 :     SolarMutexGuard aSolarLock;
     542        1369 :     ToolBox* pToolBox = static_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ) );
     543        1369 :     if ( !pToolBox )
     544           0 :         return;
     545             : 
     546        2738 :     OUString aURL = rCommand;
     547        2738 :     OUString sFallback;
     548        2738 :     Image aMenuImage;
     549             : 
     550        1369 :     bool bValid( Impl_ExistURLInMenu( m_xPopupMenu, aURL, sFallback, aMenuImage ) );
     551        1369 :     if ( !bValid )
     552          33 :         aURL = sFallback;
     553             : 
     554        1369 :     bool bBig = SvtMiscOptions().AreCurrentSymbolsLarge();
     555             : 
     556        2738 :     INetURLObject aURLObj( aURL );
     557        2738 :     Image aImage = SvFileInformationManager::GetImageNoDefault( aURLObj, bBig );
     558        1369 :     if ( !aImage )
     559           0 :         aImage = !!aMenuImage ?
     560             :             aMenuImage :
     561           0 :             SvFileInformationManager::GetImage( aURLObj, bBig );
     562             : 
     563             :     // if everything failed, just use the image associated with the toolbar item command
     564        1369 :     if ( !aImage )
     565           0 :         return;
     566             : 
     567        1369 :     Size aBigSize( pToolBox->GetDefaultImageSize() );
     568        1369 :     if ( bBig && aImage.GetSizePixel() != aBigSize )
     569             :     {
     570           0 :         BitmapEx aScaleBmpEx( aImage.GetBitmapEx() );
     571           0 :         aScaleBmpEx.Scale( aBigSize, BMP_SCALE_INTERPOLATE );
     572           0 :         pToolBox->SetItemImage( m_nToolBoxId, Image( aScaleBmpEx ) );
     573             :     }
     574             :     else
     575        1369 :         pToolBox->SetItemImage( m_nToolBoxId, aImage );
     576             : 
     577        2738 :     m_aLastURL = aURL;
     578             : }
     579             : 
     580             : }
     581             : 
     582             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     583           0 : org_apache_openoffice_comp_framework_WizardsToolbarController_get_implementation(
     584             :     css::uno::XComponentContext *context,
     585             :     css::uno::Sequence<css::uno::Any> const &)
     586             : {
     587           0 :     return cppu::acquire(new WizardsToolbarController(context));
     588             : }
     589             : 
     590             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     591         270 : org_apache_openoffice_comp_framework_OpenToolbarController_get_implementation(
     592             :     css::uno::XComponentContext *context,
     593             :     css::uno::Sequence<css::uno::Any> const &)
     594             : {
     595         270 :     return cppu::acquire(new OpenToolbarController(context));
     596             : }
     597             : 
     598             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     599        1500 : org_apache_openoffice_comp_framework_NewToolbarController_get_implementation(
     600             :     css::uno::XComponentContext *context,
     601             :     css::uno::Sequence<css::uno::Any> const &)
     602             : {
     603        1500 :     return cppu::acquire(new NewToolbarController(context));
     604         951 : }
     605             : 
     606             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10