LCOV - code coverage report
Current view: top level - chart2/source/controller/main - ShapeToolbarController.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 104 138 75.4 %
Date: 2014-04-11 Functions: 13 19 68.4 %
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          23 : OUString ShapeToolbarController::getImplementationName_Static() throw (uno::RuntimeException)
      44             : {
      45          23 :     return OUString( "com.sun.star.comp.chart2.ShapeToolbarController" );
      46             : }
      47             : 
      48           2 : Sequence< OUString > ShapeToolbarController::getSupportedServiceNames_Static() throw (uno::RuntimeException)
      49             : {
      50           2 :     Sequence< OUString > aSupported(1);
      51           2 :     aSupported.getArray()[0] = "com.sun.star.chart2.ShapeToolbarController";
      52           2 :     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         102 : Reference< uno::XInterface > ShapeToolbarController::create( const Reference< uno::XComponentContext >& xContext )
      66             : {
      67         102 :     return * new ShapeToolbarController( xContext );
      68             : }
      69             : 
      70         102 : ShapeToolbarController::ShapeToolbarController( const Reference< uno::XComponentContext >& xContext )
      71             :     :m_pToolbarController( NULL )
      72             :     ,m_nToolBoxId( 1 )
      73         102 :     ,m_nSlotId( 0 )
      74             : {
      75         102 :     osl_atomic_increment( &m_refCount );
      76         102 :     m_xContext = xContext;
      77         102 :     osl_atomic_decrement( &m_refCount );
      78         102 : }
      79             : 
      80         204 : ShapeToolbarController::~ShapeToolbarController()
      81             : {
      82         204 : }
      83             : 
      84             : // ::com::sun::star::uno::XInterface
      85        1122 : uno::Any ShapeToolbarController::queryInterface( const uno::Type& rType ) throw (uno::RuntimeException, std::exception)
      86             : {
      87        1122 :     uno::Any aReturn = ToolboxController::queryInterface( rType );
      88        1122 :     if ( !aReturn.hasValue() )
      89             :     {
      90         102 :         aReturn = ShapeToolbarController_Base::queryInterface( rType );
      91             :     }
      92        1122 :     return aReturn;
      93             : }
      94             : 
      95        3162 : void ShapeToolbarController::acquire() throw ()
      96             : {
      97        3162 :     ToolboxController::acquire();
      98        3162 : }
      99             : 
     100        3162 : void ShapeToolbarController::release() throw ()
     101             : {
     102        3162 :     ToolboxController::release();
     103        3162 : }
     104             : 
     105             : // ::com::sun::star::lang::XInitialization
     106         102 : void ShapeToolbarController::initialize( const Sequence< uno::Any >& rArguments ) throw (uno::Exception, uno::RuntimeException, std::exception)
     107             : {
     108         102 :     ToolboxController::initialize( rArguments );
     109         102 :     SolarMutexGuard aSolarMutexGuard;
     110         204 :     ::osl::MutexGuard aGuard( m_aMutex );
     111             : 
     112         102 :     ToolBox* pToolBox = static_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ) );
     113         102 :     if ( pToolBox )
     114             :     {
     115         102 :         const sal_uInt16 nCount = pToolBox->GetItemCount();
     116        1377 :         for ( sal_uInt16 nPos = 0; nPos < nCount; ++nPos )
     117             :         {
     118        1377 :             const sal_uInt16 nItemId = pToolBox->GetItemId( nPos );
     119        1377 :             if ( pToolBox->GetItemCommand( nItemId ) == m_aCommandURL )
     120             :             {
     121         102 :                 m_nToolBoxId = nItemId;
     122         102 :                 break;
     123             :             }
     124             :         }
     125         102 :         if ( m_aCommandURL == ".uno:BasicShapes" )
     126             :         {
     127          17 :             m_aStates.insert( TCommandState::value_type( ".uno:BasicShapes", sal_True ) );
     128          17 :             m_nSlotId = SID_DRAWTBX_CS_BASIC;
     129          17 :             m_pToolbarController = TToolbarHelper::createFromQuery( new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox ) );
     130             :         }
     131          85 :         else if ( m_aCommandURL == ".uno:SymbolShapes" )
     132             :         {
     133          17 :             m_aStates.insert( TCommandState::value_type( ".uno:SymbolShapes", sal_True ) );
     134          17 :             m_nSlotId = SID_DRAWTBX_CS_SYMBOL;
     135          17 :             m_pToolbarController = TToolbarHelper::createFromQuery( new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox ) );
     136             :         }
     137          68 :         else if ( m_aCommandURL == ".uno:ArrowShapes" )
     138             :         {
     139          17 :             m_aStates.insert( TCommandState::value_type( ".uno:ArrowShapes", sal_True ) );
     140          17 :             m_nSlotId = SID_DRAWTBX_CS_ARROW;
     141          17 :             m_pToolbarController = TToolbarHelper::createFromQuery( new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox) );
     142             :         }
     143          51 :         else if ( m_aCommandURL == ".uno:FlowChartShapes" )
     144             :         {
     145          17 :             m_aStates.insert( TCommandState::value_type( ".uno:FlowChartShapes", sal_True ) );
     146          17 :             m_nSlotId = SID_DRAWTBX_CS_FLOWCHART;
     147          17 :             m_pToolbarController = TToolbarHelper::createFromQuery( new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox ) );
     148             :         }
     149          34 :         else if ( m_aCommandURL == ".uno:CalloutShapes" )
     150             :         {
     151          17 :             m_aStates.insert( TCommandState::value_type( ".uno:CalloutShapes", sal_True ) );
     152          17 :             m_nSlotId = SID_DRAWTBX_CS_CALLOUT;
     153          17 :             m_pToolbarController = TToolbarHelper::createFromQuery( new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox ) );
     154             :         }
     155          17 :         else if ( m_aCommandURL == ".uno:StarShapes" )
     156             :         {
     157          17 :             m_aStates.insert( TCommandState::value_type( ".uno:StarShapes" , sal_True ) );
     158          17 :             m_nSlotId = SID_DRAWTBX_CS_STAR;
     159          17 :             m_pToolbarController = TToolbarHelper::createFromQuery( new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox ) );
     160             :         }
     161             : 
     162         204 :         for ( TCommandState::iterator aIter( m_aStates.begin() ); aIter != m_aStates.end(); ++aIter )
     163             :         {
     164         102 :             addStatusListener( aIter->first );
     165             :         }
     166             : 
     167         102 :         if ( m_pToolbarController.is() )
     168             :         {
     169         102 :             m_pToolbarController->initialize( rArguments );
     170             :         }
     171             : 
     172             :         // check if paste special is allowed, when not don't add DROPDOWN
     173         102 :         pToolBox->SetItemBits( m_nToolBoxId, pToolBox->GetItemBits( m_nToolBoxId ) | TIB_DROPDOWN );
     174         102 :     }
     175         102 : }
     176             : 
     177             : // ::com::sun::star::frame::XStatusListener
     178         102 : void ShapeToolbarController::statusChanged( const frame::FeatureStateEvent& Event ) throw ( uno::RuntimeException, std::exception )
     179             : {
     180         102 :     ::osl::MutexGuard aGuard( m_aMutex );
     181         102 :     TCommandState::iterator aFind = m_aStates.find( Event.FeatureURL.Complete );
     182         102 :     if ( aFind != m_aStates.end() )
     183             :     {
     184         102 :         aFind->second = Event.IsEnabled;
     185         102 :         if ( m_pToolbarController.is() )
     186             :         {
     187         102 :             sal_Bool bCheckmark = sal_False;
     188         102 :             ToolBox& rTb = m_pToolbarController->GetToolBox();
     189             : 
     190        1734 :             for ( sal_uInt16 i = 0; i < rTb.GetItemCount(); ++i )
     191             :             {
     192        1632 :                 sal_uInt16 nId = rTb.GetItemId( i );
     193        1632 :                 if ( nId == 0 )
     194             :                 {
     195         204 :                     continue;
     196             :                 }
     197        1428 :                 OUString aCmd = rTb.GetItemCommand( nId );
     198        1428 :                 if ( aCmd == Event.FeatureURL.Complete )
     199             :                 {
     200         102 :                     rTb.EnableItem( nId, Event.IsEnabled );
     201         102 :                     if ( Event.State >>= bCheckmark )
     202             :                     {
     203         102 :                         rTb.CheckItem( nId, bCheckmark );
     204             :                     }
     205             :                     else
     206             :                     {
     207           0 :                         OUString aItemText;
     208           0 :                         if ( Event.State >>= aItemText )
     209             :                         {
     210           0 :                             rTb.SetItemText( nId, aItemText );
     211           0 :                         }
     212             :                     }
     213             :                 }
     214        1428 :             }
     215             :         }
     216         102 :     }
     217         102 : }
     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.getRef()->createPopupWindow();
     229             :     }
     230             : 
     231           0 :     return xRet;
     232             : }
     233             : 
     234             : // ::com::sun::star::frame::XSubToolbarController
     235         102 : sal_Bool ShapeToolbarController::opensSubToolbar() throw (uno::RuntimeException, std::exception)
     236             : {
     237         187 :     return ( m_nSlotId == SID_DRAWTBX_CS_BASIC ||
     238         153 :              m_nSlotId == SID_DRAWTBX_CS_SYMBOL ||
     239         119 :              m_nSlotId == SID_DRAWTBX_CS_ARROW ||
     240          85 :              m_nSlotId == SID_DRAWTBX_CS_FLOWCHART ||
     241         153 :              m_nSlotId == SID_DRAWTBX_CS_CALLOUT ||
     242         119 :              m_nSlotId == SID_DRAWTBX_CS_STAR );
     243             : }
     244             : 
     245         102 : OUString ShapeToolbarController::getSubToolbarName() throw (uno::RuntimeException, std::exception)
     246             : {
     247         102 :     SolarMutexGuard aSolarMutexGuard;
     248         204 :     ::osl::MutexGuard aGuard(m_aMutex);
     249         204 :     uno::Reference< frame::XSubToolbarController > xSub( m_pToolbarController.getRef(), uno::UNO_QUERY );
     250         102 :     if ( xSub.is() )
     251             :     {
     252         102 :         return xSub->getSubToolbarName();
     253             :     }
     254         102 :     return OUString();
     255             : }
     256             : 
     257           0 : void ShapeToolbarController::functionSelected( const OUString& rCommand ) throw (uno::RuntimeException, std::exception)
     258             : {
     259           0 :     SolarMutexGuard aSolarMutexGuard;
     260           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     261             : 
     262           0 :     uno::Reference< frame::XSubToolbarController > xSub( m_pToolbarController.getRef(), uno::UNO_QUERY );
     263           0 :     if ( xSub.is() )
     264             :     {
     265           0 :         m_aCommandURL = rCommand;
     266           0 :         xSub->functionSelected( rCommand );
     267           0 :     }
     268           0 : }
     269             : 
     270           0 : void ShapeToolbarController::updateImage() throw (uno::RuntimeException, std::exception)
     271             : {
     272           0 :     SolarMutexGuard aSolarMutexGuard;
     273           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     274             : 
     275           0 :     uno::Reference< frame::XSubToolbarController > xSub( m_pToolbarController.getRef(), uno::UNO_QUERY );
     276           0 :     if ( xSub.is() )
     277             :     {
     278           0 :         xSub->updateImage();
     279           0 :     }
     280           0 : }
     281             : 
     282             : } //  namespace chart
     283             : 
     284             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10