LCOV - code coverage report
Current view: top level - framework/source/uielement - buttontoolbarcontroller.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 121 0.0 %
Date: 2014-04-11 Functions: 0 18 0.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 "uielement/buttontoolbarcontroller.hxx"
      21             : 
      22             : #include <com/sun/star/util/URLTransformer.hpp>
      23             : #include <com/sun/star/util/XURLTransformer.hpp>
      24             : #include <com/sun/star/frame/XDispatchProvider.hpp>
      25             : #include <com/sun/star/beans/PropertyValue.hpp>
      26             : #include <com/sun/star/lang/DisposedException.hpp>
      27             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      28             : #include "com/sun/star/util/XMacroExpander.hpp"
      29             : #include "com/sun/star/uno/XComponentContext.hpp"
      30             : #include "com/sun/star/beans/XPropertySet.hpp"
      31             : 
      32             : #include <rtl/uri.hxx>
      33             : #include <osl/mutex.hxx>
      34             : #include <comphelper/processfactory.hxx>
      35             : #include <unotools/ucbstreamhelper.hxx>
      36             : #include <vcl/svapp.hxx>
      37             : #include <vcl/mnemonic.hxx>
      38             : #include <vcl/window.hxx>
      39             : #include <vcl/graph.hxx>
      40             : #include <vcl/bitmap.hxx>
      41             : #include <vcl/graphicfilter.hxx>
      42             : #include <vcl/toolbox.hxx>
      43             : #include <svtools/miscopt.hxx>
      44             : 
      45             : using namespace ::com::sun::star;
      46             : using namespace ::com::sun::star::awt;
      47             : using namespace ::com::sun::star::uno;
      48             : using namespace ::com::sun::star::beans;
      49             : using namespace ::com::sun::star::lang;
      50             : using namespace ::com::sun::star::frame;
      51             : using namespace ::com::sun::star::util;
      52             : 
      53             : namespace framework
      54             : {
      55             : 
      56           0 : ButtonToolbarController::ButtonToolbarController(
      57             :     const uno::Reference< uno::XComponentContext >& rxContext,
      58             :     ToolBox*                                            pToolBar,
      59             :     const OUString&                                aCommand ) :
      60             :     cppu::OWeakObject(),
      61             :     m_bInitialized( false ),
      62             :     m_bDisposed( false ),
      63             :     m_aCommandURL( aCommand ),
      64             :     m_xContext( rxContext ),
      65           0 :     m_pToolbar( pToolBar )
      66             : {
      67           0 : }
      68             : 
      69           0 : ButtonToolbarController::~ButtonToolbarController()
      70             : {
      71           0 : }
      72             : 
      73             :         // XInterface
      74           0 : uno::Any SAL_CALL ButtonToolbarController::queryInterface( const uno::Type& rType )
      75             : throw (::com::sun::star::uno::RuntimeException, std::exception)
      76             : {
      77             :     Any a = ::cppu::queryInterface(
      78             :                 rType ,
      79             :                 static_cast< frame::XStatusListener* >( this ),
      80             :                 static_cast< frame::XToolbarController* >( this ),
      81             :                 static_cast< lang::XInitialization* >( this ),
      82             :                 static_cast< lang::XComponent* >( this ),
      83           0 :                 static_cast< util::XUpdatable* >( this ));
      84             : 
      85           0 :     if ( a.hasValue() )
      86           0 :         return a;
      87             : 
      88           0 :     return cppu::OWeakObject::queryInterface( rType );
      89             : }
      90             : 
      91           0 : void SAL_CALL ButtonToolbarController::acquire() throw ()
      92             : {
      93           0 :     cppu::OWeakObject::acquire();
      94           0 : }
      95             : 
      96           0 : void SAL_CALL ButtonToolbarController::release() throw ()
      97             : {
      98           0 :     cppu::OWeakObject::release();
      99           0 : }
     100             : 
     101             : // XInitialization
     102           0 : void SAL_CALL ButtonToolbarController::initialize(
     103             :     const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments )
     104             : throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException, std::exception)
     105             : {
     106           0 :     bool bInitialized( true );
     107             : 
     108             :     {
     109           0 :         SolarMutexGuard aSolarMutexGuard;
     110             : 
     111           0 :         if ( m_bDisposed )
     112           0 :             throw DisposedException();
     113             : 
     114           0 :         bInitialized = m_bInitialized;
     115             :     }
     116             : 
     117           0 :     if ( !bInitialized )
     118             :     {
     119           0 :         SolarMutexGuard aSolarMutexGuard;
     120           0 :         m_bInitialized = true;
     121             : 
     122           0 :         PropertyValue aPropValue;
     123           0 :         for ( int i = 0; i < aArguments.getLength(); i++ )
     124             :         {
     125           0 :             if ( aArguments[i] >>= aPropValue )
     126             :             {
     127           0 :                 if ( aPropValue.Name == "Frame" )
     128           0 :                     m_xFrame.set(aPropValue.Value,UNO_QUERY);
     129           0 :                 else if ( aPropValue.Name == "CommandURL" )
     130           0 :                     aPropValue.Value >>= m_aCommandURL;
     131           0 :                 else if ( aPropValue.Name == "ServiceManager" )
     132             :                 {
     133           0 :                     Reference<XMultiServiceFactory> xServiceManager(aPropValue.Value,UNO_QUERY);
     134           0 :                     m_xContext = comphelper::getComponentContext(xServiceManager);
     135             :                 }
     136             :             }
     137           0 :         }
     138             :     }
     139           0 : }
     140             : 
     141             : // XComponent
     142           0 : void SAL_CALL ButtonToolbarController::dispose() throw (::com::sun::star::uno::RuntimeException, std::exception)
     143             : {
     144           0 :     Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY );
     145             : 
     146             :     {
     147           0 :         SolarMutexGuard aSolarMutexGuard;
     148           0 :         if ( m_bDisposed )
     149           0 :             throw DisposedException();
     150             : 
     151           0 :         m_xContext.clear();
     152           0 :         m_xURLTransformer.clear();
     153           0 :         m_xFrame.clear();
     154           0 :         m_pToolbar = 0;
     155           0 :         m_bDisposed = true;
     156           0 :     }
     157           0 : }
     158             : 
     159           0 : void SAL_CALL ButtonToolbarController::addEventListener(
     160             :     const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& )
     161             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     162             : {
     163             :     // do nothing
     164           0 : }
     165             : 
     166           0 : void SAL_CALL ButtonToolbarController::removeEventListener(
     167             :     const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& )
     168             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     169             : {
     170             :     // do nothing
     171           0 : }
     172             : 
     173             : // XUpdatable
     174           0 : void SAL_CALL ButtonToolbarController::update()
     175             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     176             : {
     177           0 :     SolarMutexGuard aSolarMutexGuard;
     178           0 :     if ( m_bDisposed )
     179           0 :         throw DisposedException();
     180           0 : }
     181             : 
     182             : // XEventListener
     183           0 : void SAL_CALL ButtonToolbarController::disposing(
     184             :     const com::sun::star::lang::EventObject& Source )
     185             : throw ( ::com::sun::star::uno::RuntimeException, std::exception )
     186             : {
     187           0 :     uno::Reference< uno::XInterface > xSource( Source.Source );
     188             : 
     189           0 :     SolarMutexGuard aSolarMutexGuard;
     190             : 
     191           0 :     if ( m_bDisposed )
     192           0 :         return;
     193             : 
     194           0 :     uno::Reference< uno::XInterface > xIfac( m_xFrame, uno::UNO_QUERY );
     195           0 :     if ( xIfac == xSource )
     196           0 :         m_xFrame.clear();
     197             : }
     198             : 
     199           0 : void SAL_CALL ButtonToolbarController::statusChanged( const ::com::sun::star::frame::FeatureStateEvent& )
     200             : throw ( ::com::sun::star::uno::RuntimeException, std::exception )
     201             : {
     202             :     // do nothing
     203           0 :     if ( m_bDisposed )
     204           0 :         throw DisposedException();
     205           0 : }
     206             : 
     207             : // XToolbarController
     208           0 : void SAL_CALL ButtonToolbarController::execute( sal_Int16 KeyModifier )
     209             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     210             : {
     211           0 :     uno::Reference< frame::XDispatch >      xDispatch;
     212           0 :     uno::Reference< frame::XFrame >         xFrame;
     213           0 :     uno::Reference< util::XURLTransformer > xURLTransformer;
     214           0 :     OUString                           aCommandURL;
     215           0 :     ::com::sun::star::util::URL             aTargetURL;
     216             : 
     217             :     {
     218           0 :         SolarMutexGuard aSolarMutexGuard;
     219             : 
     220           0 :         if ( m_bDisposed )
     221           0 :             throw DisposedException();
     222             : 
     223           0 :         if ( m_bInitialized &&
     224           0 :              m_xFrame.is() &&
     225           0 :              m_xContext.is() &&
     226           0 :              !m_aCommandURL.isEmpty() )
     227             :         {
     228           0 :             if ( !m_xURLTransformer.is() )
     229             :             {
     230           0 :                 m_xURLTransformer = util::URLTransformer::create( m_xContext );
     231             :             }
     232             : 
     233           0 :             xFrame          = m_xFrame;
     234           0 :             aCommandURL     = m_aCommandURL;
     235           0 :             xURLTransformer = m_xURLTransformer;
     236           0 :         }
     237             :     }
     238             : 
     239           0 :     uno::Reference< frame::XDispatchProvider > xDispatchProvider( xFrame, uno::UNO_QUERY );
     240           0 :     if ( xDispatchProvider.is() )
     241             :     {
     242           0 :         aTargetURL.Complete = aCommandURL;
     243           0 :         xURLTransformer->parseStrict( aTargetURL );
     244           0 :         xDispatch = xDispatchProvider->queryDispatch( aTargetURL, OUString(), 0 );
     245             :     }
     246             : 
     247           0 :     if ( xDispatch.is() )
     248             :     {
     249             :         try
     250             :         {
     251           0 :             Sequence<PropertyValue>   aArgs( 1 );
     252             : 
     253             :             // Provide key modifier information to dispatch function
     254           0 :             aArgs[0].Name   = "KeyModifier";
     255           0 :             aArgs[0].Value  <<= KeyModifier;
     256             : 
     257           0 :             xDispatch->dispatch( aTargetURL, aArgs );
     258             :         }
     259           0 :         catch ( const DisposedException& )
     260             :         {
     261             :         }
     262           0 :     }
     263           0 : }
     264             : 
     265           0 : void SAL_CALL ButtonToolbarController::click()
     266             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     267             : {
     268           0 :     SolarMutexGuard aSolarMutexGuard;
     269             : 
     270           0 :     if ( m_bDisposed )
     271           0 :         throw DisposedException();
     272             : 
     273           0 :     sal_Int16   nKeyModifier( (sal_Int16)m_pToolbar->GetModifier() );
     274           0 :     execute( nKeyModifier );
     275           0 : }
     276             : 
     277           0 : void SAL_CALL ButtonToolbarController::doubleClick()
     278             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     279             : {
     280             :     // do nothing
     281           0 :     if ( m_bDisposed )
     282           0 :         throw DisposedException();
     283           0 : }
     284             : 
     285           0 : uno::Reference< awt::XWindow > SAL_CALL ButtonToolbarController::createPopupWindow()
     286             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     287             : {
     288           0 :     if ( m_bDisposed )
     289           0 :         throw DisposedException();
     290             : 
     291           0 :     return uno::Reference< awt::XWindow >();
     292             : }
     293             : 
     294           0 : uno::Reference< awt::XWindow > SAL_CALL ButtonToolbarController::createItemWindow(
     295             :     const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& )
     296             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     297             : {
     298           0 :     if ( m_bDisposed )
     299           0 :         throw DisposedException();
     300             : 
     301           0 :     return uno::Reference< awt::XWindow >();
     302             : }
     303             : 
     304             : } // namespace
     305             : 
     306             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10