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

Generated by: LCOV version 1.10