LCOV - code coverage report
Current view: top level - libreoffice/chart2/source/controller/main - ShapeToolbarController.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 2 133 1.5 %
Date: 2012-12-17 Functions: 1 19 5.3 %
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 : ::rtl::OUString ShapeToolbarController::getImplementationName() throw (uno::RuntimeException)
      43             : {
      44           0 :     return getImplementationName_Static();
      45             : }
      46             : 
      47           2 : ::rtl::OUString ShapeToolbarController::getImplementationName_Static() throw (uno::RuntimeException)
      48             : {
      49           2 :     return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.ShapeToolbarController" ) );
      50             : }
      51             : 
      52           0 : Sequence< ::rtl::OUString > ShapeToolbarController::getSupportedServiceNames_Static() throw (uno::RuntimeException)
      53             : {
      54           0 :     Sequence< ::rtl::OUString > aSupported(1);
      55           0 :     aSupported.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.ShapeToolbarController" ) );
      56           0 :     return aSupported;
      57             : }
      58             : 
      59           0 : ::sal_Bool ShapeToolbarController::supportsService( const ::rtl::OUString& ServiceName ) throw (uno::RuntimeException)
      60             : {
      61           0 :     return ::comphelper::existsValue( ServiceName, getSupportedServiceNames_Static() );
      62             : }
      63             : 
      64           0 : Sequence< ::rtl::OUString> ShapeToolbarController::getSupportedServiceNames() throw (uno::RuntimeException)
      65             : {
      66           0 :     return getSupportedServiceNames_Static();
      67             : }
      68             : 
      69           0 : Reference< uno::XInterface > ShapeToolbarController::create( const Reference< uno::XComponentContext >& xContext )
      70             : {
      71           0 :     return *( new ShapeToolbarController( Reference< lang::XMultiServiceFactory >( xContext->getServiceManager(), uno::UNO_QUERY ) ) );
      72             : }
      73             : 
      74           0 : ShapeToolbarController::ShapeToolbarController( const Reference< lang::XMultiServiceFactory >& rxFact )
      75             :     :m_pToolbarController( NULL )
      76             :     ,m_nToolBoxId( 1 )
      77           0 :     ,m_nSlotId( 0 )
      78             : {
      79           0 :     osl_atomic_increment( &m_refCount );
      80           0 :     m_xServiceManager = rxFact;
      81           0 :     osl_atomic_decrement( &m_refCount );
      82           0 : }
      83             : 
      84           0 : ShapeToolbarController::~ShapeToolbarController()
      85             : {
      86           0 : }
      87             : 
      88             : // ::com::sun::star::uno::XInterface
      89           0 : uno::Any ShapeToolbarController::queryInterface( const uno::Type& rType ) throw (uno::RuntimeException)
      90             : {
      91           0 :     uno::Any aReturn = ToolboxController::queryInterface( rType );
      92           0 :     if ( !aReturn.hasValue() )
      93             :     {
      94           0 :         aReturn = ShapeToolbarController_Base::queryInterface( rType );
      95             :     }
      96           0 :     return aReturn;
      97             : }
      98             : 
      99           0 : void ShapeToolbarController::acquire() throw ()
     100             : {
     101           0 :     ToolboxController::acquire();
     102           0 : }
     103             : 
     104           0 : void ShapeToolbarController::release() throw ()
     105             : {
     106           0 :     ToolboxController::release();
     107           0 : }
     108             : 
     109             : // ::com::sun::star::lang::XInitialization
     110           0 : void ShapeToolbarController::initialize( const Sequence< uno::Any >& rArguments ) throw (uno::Exception, uno::RuntimeException)
     111             : {
     112           0 :     ToolboxController::initialize( rArguments );
     113           0 :     SolarMutexGuard aSolarMutexGuard;
     114           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     115             : 
     116           0 :     ToolBox* pToolBox = static_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ) );
     117           0 :     if ( pToolBox )
     118             :     {
     119           0 :         const sal_uInt16 nCount = pToolBox->GetItemCount();
     120           0 :         for ( sal_uInt16 nPos = 0; nPos < nCount; ++nPos )
     121             :         {
     122           0 :             const sal_uInt16 nItemId = pToolBox->GetItemId( nPos );
     123           0 :             if ( pToolBox->GetItemCommand( nItemId ) == String( m_aCommandURL ) )
     124             :             {
     125           0 :                 m_nToolBoxId = nItemId;
     126           0 :                 break;
     127             :             }
     128             :         }
     129           0 :         if ( m_aCommandURL == ".uno:BasicShapes" )
     130             :         {
     131           0 :             m_aStates.insert( TCommandState::value_type( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:BasicShapes" ) ), sal_True ) );
     132           0 :             m_nSlotId = SID_DRAWTBX_CS_BASIC;
     133           0 :             m_pToolbarController = TToolbarHelper::createFromQuery( new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox ) );
     134             :         }
     135           0 :         else if ( m_aCommandURL == ".uno:SymbolShapes" )
     136             :         {
     137           0 :             m_aStates.insert( TCommandState::value_type( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:SymbolShapes" ) ), sal_True ) );
     138           0 :             m_nSlotId = SID_DRAWTBX_CS_SYMBOL;
     139           0 :             m_pToolbarController = TToolbarHelper::createFromQuery( new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox ) );
     140             :         }
     141           0 :         else if ( m_aCommandURL == ".uno:ArrowShapes" )
     142             :         {
     143           0 :             m_aStates.insert( TCommandState::value_type( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ArrowShapes" ) ), sal_True ) );
     144           0 :             m_nSlotId = SID_DRAWTBX_CS_ARROW;
     145           0 :             m_pToolbarController = TToolbarHelper::createFromQuery( new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox) );
     146             :         }
     147           0 :         else if ( m_aCommandURL == ".uno:FlowChartShapes" )
     148             :         {
     149           0 :             m_aStates.insert( TCommandState::value_type( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:FlowChartShapes" ) ), sal_True ) );
     150           0 :             m_nSlotId = SID_DRAWTBX_CS_FLOWCHART;
     151           0 :             m_pToolbarController = TToolbarHelper::createFromQuery( new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox ) );
     152             :         }
     153           0 :         else if ( m_aCommandURL == ".uno:CalloutShapes" )
     154             :         {
     155           0 :             m_aStates.insert( TCommandState::value_type( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:CalloutShapes" ) ), sal_True ) );
     156           0 :             m_nSlotId = SID_DRAWTBX_CS_CALLOUT;
     157           0 :             m_pToolbarController = TToolbarHelper::createFromQuery( new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox ) );
     158             :         }
     159           0 :         else if ( m_aCommandURL == ".uno:StarShapes" )
     160             :         {
     161           0 :             m_aStates.insert( TCommandState::value_type( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:StarShapes" ) ), sal_True ) );
     162           0 :             m_nSlotId = SID_DRAWTBX_CS_STAR;
     163           0 :             m_pToolbarController = TToolbarHelper::createFromQuery( new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox ) );
     164             :         }
     165             : 
     166           0 :         for ( TCommandState::iterator aIter( m_aStates.begin() ); aIter != m_aStates.end(); ++aIter )
     167             :         {
     168           0 :             addStatusListener( aIter->first );
     169             :         }
     170             : 
     171           0 :         if ( m_pToolbarController.is() )
     172             :         {
     173           0 :             m_pToolbarController->initialize( rArguments );
     174             :         }
     175             : 
     176             :         // check if paste special is allowed, when not don't add DROPDOWN
     177           0 :         pToolBox->SetItemBits( m_nToolBoxId, pToolBox->GetItemBits( m_nToolBoxId ) | TIB_DROPDOWN );
     178           0 :     }
     179           0 : }
     180             : 
     181             : // ::com::sun::star::frame::XStatusListener
     182           0 : void ShapeToolbarController::statusChanged( const frame::FeatureStateEvent& Event ) throw ( uno::RuntimeException )
     183             : {
     184           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     185           0 :     TCommandState::iterator aFind = m_aStates.find( Event.FeatureURL.Complete );
     186           0 :     if ( aFind != m_aStates.end() )
     187             :     {
     188           0 :         aFind->second = Event.IsEnabled;
     189           0 :         if ( m_pToolbarController.is() )
     190             :         {
     191           0 :             sal_Bool bCheckmark = sal_False;
     192           0 :             ToolBox& rTb = m_pToolbarController->GetToolBox();
     193             : 
     194           0 :             for ( sal_uInt16 i = 0; i < rTb.GetItemCount(); ++i )
     195             :             {
     196           0 :                 sal_uInt16 nId = rTb.GetItemId( i );
     197           0 :                 if ( nId == 0 )
     198             :                 {
     199           0 :                     continue;
     200             :                 }
     201           0 :                 ::rtl::OUString aCmd = rTb.GetItemCommand( nId );
     202           0 :                 if ( aCmd == Event.FeatureURL.Complete )
     203             :                 {
     204           0 :                     rTb.EnableItem( nId, Event.IsEnabled );
     205           0 :                     if ( Event.State >>= bCheckmark )
     206             :                     {
     207           0 :                         rTb.CheckItem( nId, bCheckmark );
     208             :                     }
     209             :                     else
     210             :                     {
     211           0 :                         ::rtl::OUString aItemText;
     212           0 :                         if ( Event.State >>= aItemText )
     213             :                         {
     214           0 :                             rTb.SetItemText( nId, aItemText );
     215           0 :                         }
     216             :                     }
     217             :                 }
     218           0 :             }
     219             :         }
     220           0 :     }
     221           0 : }
     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           0 : ::sal_Bool ShapeToolbarController::opensSubToolbar() throw (uno::RuntimeException)
     240             : {
     241             :     return ( m_nSlotId == SID_DRAWTBX_CS_BASIC ||
     242             :              m_nSlotId == SID_DRAWTBX_CS_SYMBOL ||
     243             :              m_nSlotId == SID_DRAWTBX_CS_ARROW ||
     244             :              m_nSlotId == SID_DRAWTBX_CS_FLOWCHART ||
     245             :              m_nSlotId == SID_DRAWTBX_CS_CALLOUT ||
     246           0 :              m_nSlotId == SID_DRAWTBX_CS_STAR );
     247             : }
     248             : 
     249           0 : ::rtl::OUString ShapeToolbarController::getSubToolbarName() throw (uno::RuntimeException)
     250             : {
     251           0 :     SolarMutexGuard aSolarMutexGuard;
     252           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     253           0 :     uno::Reference< frame::XSubToolbarController > xSub( m_pToolbarController.getRef(), uno::UNO_QUERY );
     254           0 :     if ( xSub.is() )
     255             :     {
     256           0 :         return xSub->getSubToolbarName();
     257             :     }
     258           0 :     return ::rtl::OUString();
     259             : }
     260             : 
     261           0 : void ShapeToolbarController::functionSelected( const ::rtl::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             : } //  namespace chart
     288             : //.............................................................................
     289             : 
     290             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10