LCOV - code coverage report
Current view: top level - reportdesign/source/ui/misc - toolboxcontroller.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 2 157 1.3 %
Date: 2014-04-11 Functions: 1 20 5.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           2 : OUString OToolboxController::getImplementationName_Static() throw( RuntimeException )
      64             : {
      65           2 :     return OUString("com.sun.star.report.comp.ReportToolboxController");
      66             : }
      67             : 
      68           0 : Sequence< OUString> OToolboxController::getSupportedServiceNames_Static(void) 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 :     ToolBox*    pToolBox = static_cast<ToolBox*>(VCLUnoHelper::GetWindow(getParent()));
     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 = TToolbarHelper::createFromQuery(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 = TToolbarHelper::createFromQuery(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 = TToolbarHelper::createFromQuery(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 = TToolbarHelper::createFromQuery(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 = TToolbarHelper::createFromQuery(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 = TToolbarHelper::createFromQuery(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 = TToolbarHelper::createFromQuery(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 = TToolbarHelper::createFromQuery(new SvxColorExtToolBoxControl(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 = TToolbarHelper::createFromQuery(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) | TIB_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 :             sal_Bool bSetCheckmark      = sal_False;
     212           0 :             sal_Bool bCheckmark         = sal_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 = sal_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 :                         ::Color aGcc3WorkaroundTemporary( nColor);
     251           0 :                         SvxColorItem aColorItem(aGcc3WorkaroundTemporary,1);
     252           0 :                         if ( SID_ATTR_CHAR_COLOR2 == m_nSlotId )
     253           0 :                             static_cast<SvxColorExtToolBoxControl*>(m_pToolbarController.get())->StateChanged(m_nSlotId,Event.IsEnabled ? SFX_ITEM_SET : SFX_ITEM_DISABLED,&aColorItem);
     254             :                         else
     255           0 :                             static_cast<SvxColorToolBoxControl*>(m_pToolbarController.get())->StateChanged(m_nSlotId,Event.IsEnabled ? SFX_ITEM_SET : SFX_ITEM_DISABLED,&aColorItem);
     256             :                     }
     257           0 :                     break;
     258             :                 case SID_ATTR_CHAR_FONT:
     259             :                     {
     260           0 :                         SvxFontItem aItem(ITEMID_FONT);
     261           0 :                         aItem.PutValue(Event.State);
     262           0 :                         static_cast<SvxFontNameToolBoxControl*>(m_pToolbarController.get())->StateChanged(m_nSlotId,Event.IsEnabled ? SFX_ITEM_AVAILABLE : SFX_ITEM_DISABLED,&aItem);
     263             :                     }
     264           0 :                     break;
     265             :             }
     266             :         }
     267           0 :     }
     268           0 : }
     269             : 
     270           0 : Reference< awt::XWindow > SAL_CALL OToolboxController::createPopupWindow() throw (RuntimeException, std::exception)
     271             : {
     272             :     // execute the menu
     273           0 :     SolarMutexGuard aSolarMutexGuard;
     274           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     275             : 
     276           0 :     Reference< awt::XWindow > xRet;
     277           0 :     if ( m_pToolbarController.is() )
     278           0 :         xRet = m_pToolbarController.getRef()->createPopupWindow();
     279             : 
     280           0 :     return xRet;
     281             : }
     282             : 
     283           0 : sal_Bool SAL_CALL OToolboxController::opensSubToolbar() throw (uno::RuntimeException, std::exception)
     284             : {
     285           0 :     return m_nSlotId == SID_DRAWTBX_CS_BASIC;
     286             : }
     287             : 
     288           0 : OUString SAL_CALL OToolboxController::getSubToolbarName() throw (uno::RuntimeException, std::exception)
     289             : {
     290           0 :     SolarMutexGuard aSolarMutexGuard;
     291           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     292           0 :     uno::Reference< frame::XSubToolbarController> xSub(m_pToolbarController.getRef(),uno::UNO_QUERY);
     293           0 :     if ( xSub.is() )
     294           0 :         return xSub->getSubToolbarName();
     295           0 :     return OUString();
     296             : }
     297             : 
     298           0 : void SAL_CALL OToolboxController::functionSelected( const OUString& rCommand ) throw (uno::RuntimeException, std::exception)
     299             : {
     300           0 :     SolarMutexGuard aSolarMutexGuard;
     301           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     302             : 
     303           0 :     uno::Reference< frame::XSubToolbarController> xSub(m_pToolbarController.getRef(),uno::UNO_QUERY);
     304           0 :     if ( xSub.is() )
     305             :     {
     306           0 :         xSub->functionSelected(m_aCommandURL = rCommand);
     307           0 :     }
     308           0 : }
     309             : 
     310           0 : void SAL_CALL OToolboxController::updateImage(  ) throw (uno::RuntimeException, std::exception)
     311             : {
     312           0 :     SolarMutexGuard aSolarMutexGuard;
     313           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     314             : 
     315           0 :     uno::Reference< frame::XSubToolbarController> xSub(m_pToolbarController.getRef(),uno::UNO_QUERY);
     316           0 :     if ( xSub.is() )
     317           0 :         xSub->updateImage();
     318           0 : }
     319             : 
     320           0 : uno::Reference< awt::XWindow > SAL_CALL OToolboxController::createItemWindow( const uno::Reference< awt::XWindow >& _xParent)
     321             : throw (uno::RuntimeException, std::exception)
     322             : {
     323           0 :     uno::Reference< awt::XWindow > xWindow;
     324           0 :     if ( m_pToolbarController.is() )
     325             :     {
     326           0 :         switch(m_nSlotId)
     327             :         {
     328             :             case SID_ATTR_CHAR_FONT:
     329           0 :                 xWindow = VCLUnoHelper::GetInterface(static_cast<SvxFontNameToolBoxControl*>(m_pToolbarController.get())->CreateItemWindow(VCLUnoHelper::GetWindow(_xParent)));
     330           0 :                 break;
     331             :             default:
     332             :                 ;
     333             :         }
     334             :     }
     335           0 :     return xWindow;
     336             : }
     337             : 
     338             : 
     339             : } // rptui
     340             : 
     341             : 
     342             : 
     343             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10