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

Generated by: LCOV version 1.10