LCOV - code coverage report
Current view: top level - reportdesign/source/ui/misc - toolboxcontroller.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 3 161 1.9 %
Date: 2015-06-13 12:38:46 Functions: 3 23 13.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             : #include "toolboxcontroller.hxx"
      20             : #include <com/sun/star/ui/ImageType.hpp>
      21             : #include <com/sun/star/frame/XDispatchProvider.hpp>
      22             : #include <com/sun/star/beans/PropertyValue.hpp>
      23             : #include <toolkit/helper/vclunohelper.hxx>
      24             : #include <vcl/menu.hxx>
      25             : #include <com/sun/star/ui/XUIConfigurationManager.hpp>
      26             : #include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
      27             : #include <com/sun/star/ui/XImageManager.hpp>
      28             : #include <com/sun/star/graphic/XGraphic.hpp>
      29             : #include <com/sun/star/util/Color.hpp>
      30             : #include <vcl/svapp.hxx>
      31             : #include <vcl/toolbox.hxx>
      32             : #include <svtools/miscopt.hxx>
      33             : #include <unotools/moduleoptions.hxx>
      34             : #include <svtools/menuoptions.hxx>
      35             : #include <osl/mutex.hxx>
      36             : #include <svx/svxids.hrc>
      37             : #define ITEMID_FONT         3
      38             : #include <editeng/fontitem.hxx>
      39             : #include <editeng/fhgtitem.hxx>
      40             : #include <svx/tbcontrl.hxx>
      41             : #include <editeng/colritem.hxx>
      42             : #include <svx/tbxcustomshapes.hxx>
      43             : 
      44             : #include <cppuhelper/supportsservice.hxx>
      45             : 
      46             : namespace rptui
      47             : {
      48             :     using namespace svt;
      49             :     using namespace com::sun::star;
      50             :     using namespace com::sun::star::uno;
      51             :     using namespace com::sun::star::beans;
      52             :     using namespace com::sun::star::lang;
      53             :     using namespace frame;
      54             :     using namespace util;
      55             :     using namespace ui;
      56             : 
      57           0 : OUString SAL_CALL OToolboxController::getImplementationName() throw( RuntimeException, std::exception )
      58             : {
      59           0 :     return getImplementationName_Static();
      60             : }
      61             : 
      62             : 
      63           4 : OUString OToolboxController::getImplementationName_Static() throw( RuntimeException )
      64             : {
      65           4 :     return OUString("com.sun.star.report.comp.ReportToolboxController");
      66             : }
      67             : 
      68           0 : Sequence< OUString> OToolboxController::getSupportedServiceNames_Static() throw( RuntimeException )
      69             : {
      70           0 :     Sequence< OUString> aSupported(1);
      71           0 :     aSupported[0] = "com.sun.star.report.ReportToolboxController";
      72           0 :     return aSupported;
      73             : }
      74             : 
      75           0 : sal_Bool SAL_CALL OToolboxController::supportsService( const OUString& ServiceName ) throw (uno::RuntimeException, std::exception)
      76             : {
      77           0 :     return cppu::supportsService(this, ServiceName);
      78             : }
      79             : 
      80           0 : Sequence< OUString> SAL_CALL OToolboxController::getSupportedServiceNames() throw(RuntimeException, std::exception)
      81             : {
      82           0 :     return getSupportedServiceNames_Static();
      83             : }
      84             : 
      85           0 : Reference< XInterface > OToolboxController::create(Reference< XComponentContext > const & xContext)
      86             : {
      87           0 :     return * new OToolboxController(xContext);
      88             : }
      89             : 
      90           0 : OToolboxController::OToolboxController(const Reference< XComponentContext >& _rxORB)
      91             :     : m_pToolbarController(NULL)
      92             :     ,m_nToolBoxId(1)
      93           0 :     ,m_nSlotId(0)
      94             : {
      95           0 :     osl_atomic_increment(&m_refCount);
      96           0 :     m_xContext = _rxORB;
      97           0 :     osl_atomic_decrement(&m_refCount);
      98             : 
      99           0 : }
     100             : 
     101           0 : OToolboxController::~OToolboxController()
     102             : {
     103           0 : }
     104             : 
     105             : // XInterface
     106           0 : Any SAL_CALL OToolboxController::queryInterface( const Type& _rType ) throw (RuntimeException, std::exception)
     107             : {
     108           0 :     Any aReturn = ToolboxController::queryInterface(_rType);
     109           0 :     if (!aReturn.hasValue())
     110           0 :         aReturn = TToolboxController_BASE::queryInterface(_rType);
     111           0 :     return aReturn;
     112             : }
     113             : 
     114           0 : void SAL_CALL OToolboxController::acquire() throw ()
     115             : {
     116           0 :     ToolboxController::acquire();
     117           0 : }
     118             : 
     119           0 : void SAL_CALL OToolboxController::release() throw ()
     120             : {
     121           0 :     ToolboxController::release();
     122           0 : }
     123             : 
     124           0 : void SAL_CALL OToolboxController::initialize( const Sequence< Any >& _rArguments ) throw (Exception, RuntimeException, std::exception)
     125             : {
     126           0 :     ToolboxController::initialize(_rArguments);
     127           0 :     SolarMutexGuard aSolarMutexGuard;
     128           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     129             : 
     130           0 :     VclPtr< ToolBox > pToolBox = static_cast<ToolBox*>(VCLUnoHelper::GetWindow(getParent()).get());
     131           0 :     if ( pToolBox )
     132             :     {
     133           0 :         const sal_uInt16 nCount = pToolBox->GetItemCount();
     134           0 :         for (sal_uInt16 nPos = 0; nPos < nCount; ++nPos)
     135             :         {
     136           0 :             const sal_uInt16 nItemId = pToolBox->GetItemId(nPos);
     137           0 :             if ( pToolBox->GetItemCommand(nItemId) == m_aCommandURL )
     138             :             {
     139           0 :                 m_nToolBoxId = nItemId;
     140           0 :                 break;
     141             :             }
     142             :         }
     143           0 :         if ( m_aCommandURL == ".uno:BasicShapes" )
     144             :         {
     145           0 :             m_aStates.insert(TCommandState::value_type(OUString(".uno:BasicShapes"),sal_True));
     146           0 :             m_pToolbarController = new SvxTbxCtlCustomShapes(m_nSlotId = SID_DRAWTBX_CS_BASIC,m_nToolBoxId,*pToolBox);
     147             :         }
     148           0 :         else if ( m_aCommandURL == ".uno:SymbolShapes" )
     149             :         {
     150           0 :             m_aStates.insert(TCommandState::value_type(OUString(".uno:SymbolShapes"),sal_True));
     151           0 :             m_pToolbarController = new SvxTbxCtlCustomShapes(m_nSlotId = SID_DRAWTBX_CS_SYMBOL,m_nToolBoxId,*pToolBox);
     152             :         }
     153           0 :         else if ( m_aCommandURL == ".uno:ArrowShapes" )
     154             :         {
     155           0 :             m_aStates.insert(TCommandState::value_type(OUString(".uno:ArrowShapes"),sal_True));
     156           0 :             m_pToolbarController = new SvxTbxCtlCustomShapes(m_nSlotId = SID_DRAWTBX_CS_ARROW,m_nToolBoxId,*pToolBox);
     157             :         }
     158           0 :         else if ( m_aCommandURL == ".uno:FlowChartShapes" )
     159             :         {
     160           0 :             m_aStates.insert(TCommandState::value_type(OUString(".uno:FlowChartShapes"),sal_True));
     161           0 :             m_pToolbarController = new SvxTbxCtlCustomShapes(m_nSlotId = SID_DRAWTBX_CS_FLOWCHART,m_nToolBoxId,*pToolBox);
     162             :         }
     163           0 :         else if ( m_aCommandURL == ".uno:CalloutShapes" )
     164             :         {
     165           0 :             m_aStates.insert(TCommandState::value_type(OUString(".uno:CalloutShapes"),sal_True));
     166           0 :             m_pToolbarController = new SvxTbxCtlCustomShapes(m_nSlotId = SID_DRAWTBX_CS_CALLOUT,m_nToolBoxId,*pToolBox);
     167             :         }
     168           0 :         else if ( m_aCommandURL == ".uno:StarShapes" )
     169             :         {
     170           0 :             m_aStates.insert(TCommandState::value_type(OUString(".uno:StarShapes"),sal_True));
     171           0 :             m_pToolbarController = new SvxTbxCtlCustomShapes(m_nSlotId = SID_DRAWTBX_CS_STAR,m_nToolBoxId,*pToolBox);
     172             :         }
     173           0 :         else if ( m_aCommandURL == ".uno:CharFontName" )
     174             :         {
     175           0 :             m_aStates.insert(TCommandState::value_type(OUString(".uno:CharFontName"),sal_True));
     176           0 :             m_pToolbarController = new SvxFontNameToolBoxControl/*SvxStyleToolBoxControl*/(m_nSlotId = SID_ATTR_CHAR_FONT,m_nToolBoxId,*pToolBox);
     177             :         }
     178           0 :         else if ( m_aCommandURL == ".uno:FontColor" || m_aCommandURL == ".uno:Color" )
     179             :         {
     180           0 :             m_aStates.insert(TCommandState::value_type(OUString(".uno:FontColor"),sal_True));
     181           0 :             m_aStates.insert(TCommandState::value_type(OUString(".uno:Color"),sal_True));
     182           0 :             m_pToolbarController = new SvxColorToolBoxControl(m_nSlotId = SID_ATTR_CHAR_COLOR2,m_nToolBoxId,*pToolBox);
     183             :         }
     184             :         else
     185             :         {
     186           0 :             m_aStates.insert(TCommandState::value_type(OUString(".uno:BackgroundColor"),sal_True));
     187           0 :             m_pToolbarController = new SvxColorToolBoxControl(m_nSlotId = SID_BACKGROUND_COLOR,m_nToolBoxId,*pToolBox);
     188             :         }
     189             : 
     190           0 :         TCommandState::iterator aIter = m_aStates.begin();
     191           0 :         for (; aIter != m_aStates.end(); ++aIter)
     192           0 :             addStatusListener(aIter->first);
     193             : 
     194           0 :         if ( m_pToolbarController.is() )
     195           0 :             m_pToolbarController->initialize(_rArguments);
     196             :         // check if paste special is allowed, when not don't add DROPDOWN
     197           0 :         pToolBox->SetItemBits(m_nToolBoxId,pToolBox->GetItemBits(m_nToolBoxId) | ToolBoxItemBits::DROPDOWN);
     198           0 :     }
     199           0 : }
     200             : 
     201           0 : void SAL_CALL OToolboxController::statusChanged( const FeatureStateEvent& Event ) throw ( RuntimeException, std::exception )
     202             : {
     203           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     204           0 :     TCommandState::iterator aFind = m_aStates.find( Event.FeatureURL.Complete );
     205           0 :     if ( aFind != m_aStates.end() )
     206             :     {
     207           0 :         aFind->second = Event.IsEnabled;
     208           0 :         if ( m_pToolbarController.is() )
     209             :         {
     210             :             // All other status events will be processed here
     211           0 :             bool bSetCheckmark      = false;
     212           0 :             bool bCheckmark         = false;
     213             :             //m_pToolbarController->GetToolBox().Enable(Event.IsEnabled);
     214           0 :             ToolBox& rTb = m_pToolbarController->GetToolBox();
     215           0 :             for ( sal_uInt16 i = 0; i < rTb.GetItemCount(); i++ )
     216             :             {
     217           0 :                 sal_uInt16 nId = rTb.GetItemId( i );
     218           0 :                 if ( nId == 0 )
     219           0 :                     continue;
     220             : 
     221           0 :                 OUString aCmd = rTb.GetItemCommand( nId );
     222           0 :                 if ( aCmd == Event.FeatureURL.Complete )
     223             :                 {
     224             :                     // Enable/disable item
     225           0 :                     rTb.EnableItem( nId, Event.IsEnabled );
     226             : 
     227             :                     // Checkmark
     228           0 :                     if ( Event.State >>= bCheckmark )
     229           0 :                         bSetCheckmark = true;
     230             : 
     231           0 :                     if ( bSetCheckmark )
     232           0 :                         rTb.CheckItem( nId, bCheckmark );
     233             :                     else
     234             :                     {
     235           0 :                         OUString aItemText;
     236             : 
     237           0 :                         if ( Event.State >>= aItemText )
     238           0 :                             rTb.SetItemText( nId, aItemText );
     239             :                     }
     240             :                 }
     241           0 :             }
     242             : 
     243           0 :             switch(m_nSlotId)
     244             :             {
     245             :                 case SID_ATTR_CHAR_COLOR2:
     246             :                 case SID_BACKGROUND_COLOR:
     247             :                     {
     248           0 :                         util::Color nColor(COL_TRANSPARENT);
     249           0 :                         Event.State >>= nColor;
     250           0 :                         SvxColorItem aColorItem(::Color(nColor), 1);
     251           0 :                         static_cast<SvxColorToolBoxControl*>(m_pToolbarController.get())->StateChanged(m_nSlotId,Event.IsEnabled ? SfxItemState::SET : SfxItemState::DISABLED,&aColorItem);
     252             :                     }
     253           0 :                     break;
     254             :                 case SID_ATTR_CHAR_FONT:
     255             :                     {
     256           0 :                         SvxFontItem aItem(ITEMID_FONT);
     257           0 :                         aItem.PutValue(Event.State);
     258           0 :                         static_cast<SvxFontNameToolBoxControl*>(m_pToolbarController.get())->StateChanged(m_nSlotId,Event.IsEnabled ? SfxItemState::DEFAULT : SfxItemState::DISABLED,&aItem);
     259             :                     }
     260           0 :                     break;
     261             :             }
     262             :         }
     263           0 :     }
     264           0 : }
     265             : 
     266           0 : Reference< awt::XWindow > SAL_CALL OToolboxController::createPopupWindow() throw (RuntimeException, std::exception)
     267             : {
     268             :     // execute the menu
     269           0 :     SolarMutexGuard aSolarMutexGuard;
     270           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     271             : 
     272           0 :     Reference< awt::XWindow > xRet;
     273           0 :     if ( m_pToolbarController.is() )
     274           0 :         xRet = m_pToolbarController->createPopupWindow();
     275             : 
     276           0 :     return xRet;
     277             : }
     278             : 
     279           0 : void SAL_CALL OToolboxController::execute( sal_Int16 KeyModifier ) throw (uno::RuntimeException, std::exception)
     280             : {
     281           0 :     if ( m_pToolbarController.is() )
     282           0 :         m_pToolbarController->execute( KeyModifier );
     283           0 : }
     284             : 
     285           0 : sal_Bool SAL_CALL OToolboxController::opensSubToolbar() throw (uno::RuntimeException, std::exception)
     286             : {
     287           0 :     return ( m_nSlotId == SID_DRAWTBX_CS_BASIC ||
     288           0 :              m_nSlotId == SID_DRAWTBX_CS_SYMBOL ||
     289           0 :              m_nSlotId == SID_DRAWTBX_CS_ARROW ||
     290           0 :              m_nSlotId == SID_DRAWTBX_CS_FLOWCHART ||
     291           0 :              m_nSlotId == SID_DRAWTBX_CS_CALLOUT ||
     292           0 :              m_nSlotId == SID_DRAWTBX_CS_STAR );
     293             : }
     294             : 
     295           0 : OUString SAL_CALL OToolboxController::getSubToolbarName() throw (uno::RuntimeException, std::exception)
     296             : {
     297           0 :     SolarMutexGuard aSolarMutexGuard;
     298           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     299           0 :     if ( m_pToolbarController.is() )
     300           0 :         return m_pToolbarController->getSubToolbarName();
     301           0 :     return OUString();
     302             : }
     303             : 
     304           0 : void SAL_CALL OToolboxController::functionSelected( const OUString& rCommand ) throw (uno::RuntimeException, std::exception)
     305             : {
     306           0 :     SolarMutexGuard aSolarMutexGuard;
     307           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     308           0 :     if ( m_pToolbarController.is() )
     309             :     {
     310           0 :         m_pToolbarController->functionSelected(m_aCommandURL = rCommand);
     311           0 :     }
     312           0 : }
     313             : 
     314           0 : void SAL_CALL OToolboxController::updateImage(  ) throw (uno::RuntimeException, std::exception)
     315             : {
     316           0 :     SolarMutexGuard aSolarMutexGuard;
     317           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     318           0 :     if ( m_pToolbarController.is() )
     319           0 :         m_pToolbarController->updateImage();
     320           0 : }
     321             : 
     322           0 : uno::Reference< awt::XWindow > SAL_CALL OToolboxController::createItemWindow( const uno::Reference< awt::XWindow >& _xParent)
     323             : throw (uno::RuntimeException, std::exception)
     324             : {
     325           0 :     uno::Reference< awt::XWindow > xWindow;
     326           0 :     if ( m_pToolbarController.is() )
     327             :     {
     328           0 :         switch(m_nSlotId)
     329             :         {
     330             :             case SID_ATTR_CHAR_FONT:
     331           0 :                 xWindow = VCLUnoHelper::GetInterface(static_cast<SvxFontNameToolBoxControl*>(m_pToolbarController.get())->CreateItemWindow(VCLUnoHelper::GetWindow(_xParent)));
     332           0 :                 break;
     333             :             default:
     334             :                 ;
     335             :         }
     336             :     }
     337           0 :     return xWindow;
     338             : }
     339             : 
     340             : 
     341           3 : } // rptui
     342             : 
     343             : 
     344             : 
     345             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11