LCOV - code coverage report
Current view: top level - chart2/source/controller/main - ShapeToolbarController.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 138 0.0 %
Date: 2014-04-14 Functions: 0 19 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 "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           0 : ShapeToolbarController::ShapeToolbarController( const Reference< uno::XComponentContext >& xContext )
      71             :     :m_pToolbarController( NULL )
      72             :     ,m_nToolBoxId( 1 )
      73           0 :     ,m_nSlotId( 0 )
      74             : {
      75           0 :     osl_atomic_increment( &m_refCount );
      76           0 :     m_xContext = xContext;
      77           0 :     osl_atomic_decrement( &m_refCount );
      78           0 : }
      79             : 
      80           0 : ShapeToolbarController::~ShapeToolbarController()
      81             : {
      82           0 : }
      83             : 
      84             : // ::com::sun::star::uno::XInterface
      85           0 : uno::Any ShapeToolbarController::queryInterface( const uno::Type& rType ) throw (uno::RuntimeException, std::exception)
      86             : {
      87           0 :     uno::Any aReturn = ToolboxController::queryInterface( rType );
      88           0 :     if ( !aReturn.hasValue() )
      89             :     {
      90           0 :         aReturn = ShapeToolbarController_Base::queryInterface( rType );
      91             :     }
      92           0 :     return aReturn;
      93             : }
      94             : 
      95           0 : void ShapeToolbarController::acquire() throw ()
      96             : {
      97           0 :     ToolboxController::acquire();
      98           0 : }
      99             : 
     100           0 : void ShapeToolbarController::release() throw ()
     101             : {
     102           0 :     ToolboxController::release();
     103           0 : }
     104             : 
     105             : // ::com::sun::star::lang::XInitialization
     106           0 : void ShapeToolbarController::initialize( const Sequence< uno::Any >& rArguments ) throw (uno::Exception, uno::RuntimeException, std::exception)
     107             : {
     108           0 :     ToolboxController::initialize( rArguments );
     109           0 :     SolarMutexGuard aSolarMutexGuard;
     110           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     111             : 
     112           0 :     ToolBox* pToolBox = static_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ) );
     113           0 :     if ( pToolBox )
     114             :     {
     115           0 :         const sal_uInt16 nCount = pToolBox->GetItemCount();
     116           0 :         for ( sal_uInt16 nPos = 0; nPos < nCount; ++nPos )
     117             :         {
     118           0 :             const sal_uInt16 nItemId = pToolBox->GetItemId( nPos );
     119           0 :             if ( pToolBox->GetItemCommand( nItemId ) == m_aCommandURL )
     120             :             {
     121           0 :                 m_nToolBoxId = nItemId;
     122           0 :                 break;
     123             :             }
     124             :         }
     125           0 :         if ( m_aCommandURL == ".uno:BasicShapes" )
     126             :         {
     127           0 :             m_aStates.insert( TCommandState::value_type( ".uno:BasicShapes", sal_True ) );
     128           0 :             m_nSlotId = SID_DRAWTBX_CS_BASIC;
     129           0 :             m_pToolbarController = TToolbarHelper::createFromQuery( new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox ) );
     130             :         }
     131           0 :         else if ( m_aCommandURL == ".uno:SymbolShapes" )
     132             :         {
     133           0 :             m_aStates.insert( TCommandState::value_type( ".uno:SymbolShapes", sal_True ) );
     134           0 :             m_nSlotId = SID_DRAWTBX_CS_SYMBOL;
     135           0 :             m_pToolbarController = TToolbarHelper::createFromQuery( new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox ) );
     136             :         }
     137           0 :         else if ( m_aCommandURL == ".uno:ArrowShapes" )
     138             :         {
     139           0 :             m_aStates.insert( TCommandState::value_type( ".uno:ArrowShapes", sal_True ) );
     140           0 :             m_nSlotId = SID_DRAWTBX_CS_ARROW;
     141           0 :             m_pToolbarController = TToolbarHelper::createFromQuery( new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox) );
     142             :         }
     143           0 :         else if ( m_aCommandURL == ".uno:FlowChartShapes" )
     144             :         {
     145           0 :             m_aStates.insert( TCommandState::value_type( ".uno:FlowChartShapes", sal_True ) );
     146           0 :             m_nSlotId = SID_DRAWTBX_CS_FLOWCHART;
     147           0 :             m_pToolbarController = TToolbarHelper::createFromQuery( new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox ) );
     148             :         }
     149           0 :         else if ( m_aCommandURL == ".uno:CalloutShapes" )
     150             :         {
     151           0 :             m_aStates.insert( TCommandState::value_type( ".uno:CalloutShapes", sal_True ) );
     152           0 :             m_nSlotId = SID_DRAWTBX_CS_CALLOUT;
     153           0 :             m_pToolbarController = TToolbarHelper::createFromQuery( new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox ) );
     154             :         }
     155           0 :         else if ( m_aCommandURL == ".uno:StarShapes" )
     156             :         {
     157           0 :             m_aStates.insert( TCommandState::value_type( ".uno:StarShapes" , sal_True ) );
     158           0 :             m_nSlotId = SID_DRAWTBX_CS_STAR;
     159           0 :             m_pToolbarController = TToolbarHelper::createFromQuery( new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox ) );
     160             :         }
     161             : 
     162           0 :         for ( TCommandState::iterator aIter( m_aStates.begin() ); aIter != m_aStates.end(); ++aIter )
     163             :         {
     164           0 :             addStatusListener( aIter->first );
     165             :         }
     166             : 
     167           0 :         if ( m_pToolbarController.is() )
     168             :         {
     169           0 :             m_pToolbarController->initialize( rArguments );
     170             :         }
     171             : 
     172             :         // check if paste special is allowed, when not don't add DROPDOWN
     173           0 :         pToolBox->SetItemBits( m_nToolBoxId, pToolBox->GetItemBits( m_nToolBoxId ) | TIB_DROPDOWN );
     174           0 :     }
     175           0 : }
     176             : 
     177             : // ::com::sun::star::frame::XStatusListener
     178           0 : void ShapeToolbarController::statusChanged( const frame::FeatureStateEvent& Event ) throw ( uno::RuntimeException, std::exception )
     179             : {
     180           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     181           0 :     TCommandState::iterator aFind = m_aStates.find( Event.FeatureURL.Complete );
     182           0 :     if ( aFind != m_aStates.end() )
     183             :     {
     184           0 :         aFind->second = Event.IsEnabled;
     185           0 :         if ( m_pToolbarController.is() )
     186             :         {
     187           0 :             sal_Bool bCheckmark = sal_False;
     188           0 :             ToolBox& rTb = m_pToolbarController->GetToolBox();
     189             : 
     190           0 :             for ( sal_uInt16 i = 0; i < rTb.GetItemCount(); ++i )
     191             :             {
     192           0 :                 sal_uInt16 nId = rTb.GetItemId( i );
     193           0 :                 if ( nId == 0 )
     194             :                 {
     195           0 :                     continue;
     196             :                 }
     197           0 :                 OUString aCmd = rTb.GetItemCommand( nId );
     198           0 :                 if ( aCmd == Event.FeatureURL.Complete )
     199             :                 {
     200           0 :                     rTb.EnableItem( nId, Event.IsEnabled );
     201           0 :                     if ( Event.State >>= bCheckmark )
     202             :                     {
     203           0 :                         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           0 :             }
     215             :         }
     216           0 :     }
     217           0 : }
     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           0 : sal_Bool ShapeToolbarController::opensSubToolbar() throw (uno::RuntimeException, std::exception)
     236             : {
     237           0 :     return ( m_nSlotId == SID_DRAWTBX_CS_BASIC ||
     238           0 :              m_nSlotId == SID_DRAWTBX_CS_SYMBOL ||
     239           0 :              m_nSlotId == SID_DRAWTBX_CS_ARROW ||
     240           0 :              m_nSlotId == SID_DRAWTBX_CS_FLOWCHART ||
     241           0 :              m_nSlotId == SID_DRAWTBX_CS_CALLOUT ||
     242           0 :              m_nSlotId == SID_DRAWTBX_CS_STAR );
     243             : }
     244             : 
     245           0 : OUString ShapeToolbarController::getSubToolbarName() throw (uno::RuntimeException, std::exception)
     246             : {
     247           0 :     SolarMutexGuard aSolarMutexGuard;
     248           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     249           0 :     uno::Reference< frame::XSubToolbarController > xSub( m_pToolbarController.getRef(), uno::UNO_QUERY );
     250           0 :     if ( xSub.is() )
     251             :     {
     252           0 :         return xSub->getSubToolbarName();
     253             :     }
     254           0 :     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