LCOV - code coverage report
Current view: top level - chart2/source/controller/main - ShapeToolbarController.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 78 140 55.7 %
Date: 2015-06-13 12:38:46 Functions: 12 22 54.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 "ShapeToolbarController.hxx"
      21             : 
      22             : #include <osl/mutex.hxx>
      23             : #include <cppuhelper/supportsservice.hxx>
      24             : #include <vcl/svapp.hxx>
      25             : #include <vcl/toolbox.hxx>
      26             : #include <toolkit/helper/vclunohelper.hxx>
      27             : #include <svx/svxids.hrc>
      28             : #include <svx/tbxcustomshapes.hxx>
      29             : #include <comphelper/propertysequence.hxx>
      30             : 
      31             : using namespace com::sun::star;
      32             : 
      33             : using ::com::sun::star::uno::Reference;
      34             : using ::com::sun::star::uno::Sequence;
      35             : 
      36             : namespace chart
      37             : {
      38             : 
      39           0 : OUString ShapeToolbarController::getImplementationName() throw (uno::RuntimeException, std::exception)
      40             : {
      41           0 :     return getImplementationName_Static();
      42             : }
      43             : 
      44           0 : OUString ShapeToolbarController::getImplementationName_Static() throw (uno::RuntimeException)
      45             : {
      46           0 :     return OUString( "com.sun.star.comp.chart2.ShapeToolbarController" );
      47             : }
      48             : 
      49           0 : Sequence< OUString > ShapeToolbarController::getSupportedServiceNames_Static() throw (uno::RuntimeException)
      50             : {
      51           0 :     Sequence< OUString > aSupported(1);
      52           0 :     aSupported.getArray()[0] = "com.sun.star.chart2.ShapeToolbarController";
      53           0 :     return aSupported;
      54             : }
      55             : 
      56           0 : sal_Bool ShapeToolbarController::supportsService( const OUString& ServiceName ) throw (uno::RuntimeException, std::exception)
      57             : {
      58           0 :     return cppu::supportsService( this, ServiceName );
      59             : }
      60             : 
      61           0 : Sequence< OUString > ShapeToolbarController::getSupportedServiceNames() throw (uno::RuntimeException, std::exception)
      62             : {
      63           0 :     return getSupportedServiceNames_Static();
      64             : }
      65             : 
      66         102 : ShapeToolbarController::ShapeToolbarController( const Reference< uno::XComponentContext >& xContext )
      67             :     :m_pToolbarController( NULL )
      68             :     ,m_nToolBoxId( 1 )
      69         102 :     ,m_nSlotId( 0 )
      70             : {
      71         102 :     osl_atomic_increment( &m_refCount );
      72         102 :     m_xContext = xContext;
      73         102 :     osl_atomic_decrement( &m_refCount );
      74         102 : }
      75             : 
      76         204 : ShapeToolbarController::~ShapeToolbarController()
      77             : {
      78         204 : }
      79             : 
      80             : // ::com::sun::star::uno::XInterface
      81         918 : uno::Any ShapeToolbarController::queryInterface( const uno::Type& rType ) throw (uno::RuntimeException, std::exception)
      82             : {
      83         918 :     uno::Any aReturn = ToolboxController::queryInterface( rType );
      84         918 :     if ( !aReturn.hasValue() )
      85             :     {
      86         102 :         aReturn = ShapeToolbarController_Base::queryInterface( rType );
      87             :     }
      88         918 :     return aReturn;
      89             : }
      90             : 
      91        2346 : void ShapeToolbarController::acquire() throw ()
      92             : {
      93        2346 :     ToolboxController::acquire();
      94        2346 : }
      95             : 
      96        2346 : void ShapeToolbarController::release() throw ()
      97             : {
      98        2346 :     ToolboxController::release();
      99        2346 : }
     100             : 
     101             : // ::com::sun::star::lang::XInitialization
     102         102 : void ShapeToolbarController::initialize( const Sequence< uno::Any >& rArguments ) throw (uno::Exception, uno::RuntimeException, std::exception)
     103             : {
     104         102 :     ToolboxController::initialize( rArguments );
     105         102 :     SolarMutexGuard aSolarMutexGuard;
     106         204 :     ::osl::MutexGuard aGuard( m_aMutex );
     107             : 
     108         204 :     VclPtr< ToolBox > pToolBox = static_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ).get() );
     109         102 :     if ( pToolBox )
     110             :     {
     111         102 :         const sal_uInt16 nCount = pToolBox->GetItemCount();
     112        1377 :         for ( sal_uInt16 nPos = 0; nPos < nCount; ++nPos )
     113             :         {
     114        1377 :             const sal_uInt16 nItemId = pToolBox->GetItemId( nPos );
     115        1377 :             if ( pToolBox->GetItemCommand( nItemId ) == m_aCommandURL )
     116             :             {
     117         102 :                 m_nToolBoxId = nItemId;
     118         102 :                 break;
     119             :             }
     120             :         }
     121         102 :         if ( m_aCommandURL == ".uno:BasicShapes" )
     122             :         {
     123          17 :             m_aStates.insert( TCommandState::value_type( ".uno:BasicShapes", sal_True ) );
     124          17 :             m_nSlotId = SID_DRAWTBX_CS_BASIC;
     125          17 :             m_pToolbarController = new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox );
     126             :         }
     127          85 :         else if ( m_aCommandURL == ".uno:SymbolShapes" )
     128             :         {
     129          17 :             m_aStates.insert( TCommandState::value_type( ".uno:SymbolShapes", sal_True ) );
     130          17 :             m_nSlotId = SID_DRAWTBX_CS_SYMBOL;
     131          17 :             m_pToolbarController = new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox );
     132             :         }
     133          68 :         else if ( m_aCommandURL == ".uno:ArrowShapes" )
     134             :         {
     135          17 :             m_aStates.insert( TCommandState::value_type( ".uno:ArrowShapes", sal_True ) );
     136          17 :             m_nSlotId = SID_DRAWTBX_CS_ARROW;
     137          17 :             m_pToolbarController = new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox);
     138             :         }
     139          51 :         else if ( m_aCommandURL == ".uno:FlowChartShapes" )
     140             :         {
     141          17 :             m_aStates.insert( TCommandState::value_type( ".uno:FlowChartShapes", sal_True ) );
     142          17 :             m_nSlotId = SID_DRAWTBX_CS_FLOWCHART;
     143          17 :             m_pToolbarController = new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox );
     144             :         }
     145          34 :         else if ( m_aCommandURL == ".uno:CalloutShapes" )
     146             :         {
     147          17 :             m_aStates.insert( TCommandState::value_type( ".uno:CalloutShapes", sal_True ) );
     148          17 :             m_nSlotId = SID_DRAWTBX_CS_CALLOUT;
     149          17 :             m_pToolbarController = new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox );
     150             :         }
     151          17 :         else if ( m_aCommandURL == ".uno:StarShapes" )
     152             :         {
     153          17 :             m_aStates.insert( TCommandState::value_type( ".uno:StarShapes" , sal_True ) );
     154          17 :             m_nSlotId = SID_DRAWTBX_CS_STAR;
     155          17 :             m_pToolbarController = new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox );
     156             :         }
     157             : 
     158         204 :         for ( TCommandState::iterator aIter( m_aStates.begin() ); aIter != m_aStates.end(); ++aIter )
     159             :         {
     160         102 :             addStatusListener( aIter->first );
     161             :         }
     162             : 
     163         102 :         if ( m_pToolbarController.is() )
     164             :         {
     165         102 :             m_pToolbarController->initialize( rArguments );
     166             :         }
     167             : 
     168             :         // check if paste special is allowed, when not don't add DROPDOWN
     169         102 :         pToolBox->SetItemBits( m_nToolBoxId, pToolBox->GetItemBits( m_nToolBoxId ) | ToolBoxItemBits::DROPDOWN );
     170         102 :     }
     171         102 : }
     172             : 
     173             : // ::com::sun::star::frame::XStatusListener
     174           0 : void ShapeToolbarController::statusChanged( const frame::FeatureStateEvent& Event ) throw ( uno::RuntimeException, std::exception )
     175             : {
     176           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     177           0 :     TCommandState::iterator aFind = m_aStates.find( Event.FeatureURL.Complete );
     178           0 :     if ( aFind != m_aStates.end() )
     179             :     {
     180           0 :         aFind->second = Event.IsEnabled;
     181           0 :         if ( m_pToolbarController.is() )
     182             :         {
     183           0 :             bool bCheckmark = false;
     184           0 :             ToolBox& rTb = m_pToolbarController->GetToolBox();
     185             : 
     186           0 :             for ( sal_uInt16 i = 0; i < rTb.GetItemCount(); ++i )
     187             :             {
     188           0 :                 sal_uInt16 nId = rTb.GetItemId( i );
     189           0 :                 if ( nId == 0 )
     190             :                 {
     191           0 :                     continue;
     192             :                 }
     193           0 :                 OUString aCmd = rTb.GetItemCommand( nId );
     194           0 :                 if ( aCmd == Event.FeatureURL.Complete )
     195             :                 {
     196           0 :                     rTb.EnableItem( nId, Event.IsEnabled );
     197           0 :                     if ( Event.State >>= bCheckmark )
     198             :                     {
     199           0 :                         rTb.CheckItem( nId, bCheckmark );
     200             :                     }
     201             :                     else
     202             :                     {
     203           0 :                         OUString aItemText;
     204           0 :                         if ( Event.State >>= aItemText )
     205             :                         {
     206           0 :                             rTb.SetItemText( nId, aItemText );
     207           0 :                         }
     208             :                     }
     209             :                 }
     210           0 :             }
     211             :         }
     212           0 :     }
     213           0 : }
     214             : 
     215             : // ::com::sun::star::frame::XToolbarController
     216           0 : Reference< awt::XWindow > ShapeToolbarController::createPopupWindow() throw (uno::RuntimeException, std::exception)
     217             : {
     218           0 :     SolarMutexGuard aSolarMutexGuard;
     219           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     220             : 
     221           0 :     Reference< awt::XWindow > xRet;
     222           0 :     if ( m_pToolbarController.is() )
     223             :     {
     224           0 :         xRet = m_pToolbarController->createPopupWindow();
     225             :     }
     226             : 
     227           0 :     return xRet;
     228             : }
     229             : 
     230           0 : void ShapeToolbarController::execute( sal_Int16 KeyModifier ) throw (uno::RuntimeException, std::exception)
     231             : {
     232             :     auto aArgs(::comphelper::InitPropertySequence({
     233             :         { "KeyModifier", uno::makeAny(KeyModifier) }
     234           0 :     }));
     235           0 :     dispatchCommand( m_aCommandURL, aArgs );
     236           0 : }
     237             : 
     238             : // ::com::sun::star::frame::XSubToolbarController
     239         102 : sal_Bool ShapeToolbarController::opensSubToolbar() throw (uno::RuntimeException, std::exception)
     240             : {
     241         187 :     return ( m_nSlotId == SID_DRAWTBX_CS_BASIC ||
     242         153 :              m_nSlotId == SID_DRAWTBX_CS_SYMBOL ||
     243         119 :              m_nSlotId == SID_DRAWTBX_CS_ARROW ||
     244          85 :              m_nSlotId == SID_DRAWTBX_CS_FLOWCHART ||
     245         153 :              m_nSlotId == SID_DRAWTBX_CS_CALLOUT ||
     246         119 :              m_nSlotId == SID_DRAWTBX_CS_STAR );
     247             : }
     248             : 
     249         102 : OUString ShapeToolbarController::getSubToolbarName() throw (uno::RuntimeException, std::exception)
     250             : {
     251         102 :     SolarMutexGuard aSolarMutexGuard;
     252         204 :     ::osl::MutexGuard aGuard(m_aMutex);
     253         102 :     if ( m_pToolbarController.is() )
     254             :     {
     255         102 :         return m_pToolbarController->getSubToolbarName();
     256             :     }
     257         102 :     return OUString();
     258             : }
     259             : 
     260           0 : void ShapeToolbarController::functionSelected( const OUString& rCommand ) throw (uno::RuntimeException, std::exception)
     261             : {
     262           0 :     SolarMutexGuard aSolarMutexGuard;
     263           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     264           0 :     if ( m_pToolbarController.is() )
     265             :     {
     266           0 :         m_aCommandURL = rCommand;
     267           0 :         m_pToolbarController->functionSelected( rCommand );
     268           0 :     }
     269           0 : }
     270             : 
     271           0 : void ShapeToolbarController::updateImage() throw (uno::RuntimeException, std::exception)
     272             : {
     273           0 :     SolarMutexGuard aSolarMutexGuard;
     274           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     275           0 :     if ( m_pToolbarController.is() )
     276             :     {
     277           0 :         m_pToolbarController->updateImage();
     278           0 :     }
     279           0 : }
     280             : 
     281             : } //  namespace chart
     282             : 
     283             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     284         102 : com_sun_star_comp_chart2_ShapeToolbarController_get_implementation(css::uno::XComponentContext *context,
     285             :                                                                    css::uno::Sequence<css::uno::Any> const &)
     286             : {
     287         102 :     return cppu::acquire(new ::chart::ShapeToolbarController(context));
     288          57 : }
     289             : 
     290             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11