LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/vbahelper/source/vbahelper - vbacommandbarcontrol.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 112 0.9 %
Date: 2013-07-09 Functions: 2 24 8.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             : #include "vbacommandbarcontrol.hxx"
      20             : #include "vbacommandbarcontrols.hxx"
      21             : #include <vbahelper/vbahelper.hxx>
      22             : #include <filter/msfilter/msvbahelper.hxx>
      23             : 
      24             : using namespace com::sun::star;
      25             : using namespace ooo::vba;
      26             : 
      27           0 : ScVbaCommandBarControl::ScVbaCommandBarControl( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess >& xSettings, VbaCommandBarHelperRef pHelper, const css::uno::Reference< css::container::XIndexAccess >& xBarSettings, const OUString& sResourceUrl ) throw (css::uno::RuntimeException) : CommandBarControl_BASE( xParent, xContext ), pCBarHelper( pHelper ), m_sResourceUrl( sResourceUrl ), m_xCurrentSettings( xSettings ), m_xBarSettings( xBarSettings ), m_nPosition( 0 ), m_bTemporary( sal_True )
      28             : {
      29           0 : }
      30             : 
      31           0 : void ScVbaCommandBarControl::ApplyChange() throw ( uno::RuntimeException )
      32             : {
      33           0 :     uno::Reference< container::XIndexContainer > xIndexContainer( m_xCurrentSettings, uno::UNO_QUERY_THROW );
      34           0 :     xIndexContainer->replaceByIndex( m_nPosition, uno::makeAny( m_aPropertyValues ) );
      35           0 :     pCBarHelper->ApplyChange( m_sResourceUrl, m_xBarSettings );
      36           0 : }
      37             : 
      38             : OUString SAL_CALL
      39           0 : ScVbaCommandBarControl::getCaption() throw ( uno::RuntimeException )
      40             : {
      41             :     // "Label" always empty
      42           0 :     OUString sCaption;
      43           0 :     getPropertyValue( m_aPropertyValues, "Label" ) >>= sCaption;
      44           0 :     return sCaption;
      45             : }
      46             : 
      47             : void SAL_CALL
      48           0 : ScVbaCommandBarControl::setCaption( const OUString& _caption ) throw (uno::RuntimeException)
      49             : {
      50           0 :     OUString sCaption = _caption.replace('&','~');
      51           0 :     setPropertyValue( m_aPropertyValues, "Label" , uno::makeAny( sCaption ) );
      52           0 :     ApplyChange();
      53           0 : }
      54             : 
      55             : OUString SAL_CALL
      56           0 : ScVbaCommandBarControl::getOnAction() throw (uno::RuntimeException)
      57             : {
      58           0 :     OUString sCommandURL;
      59           0 :     getPropertyValue( m_aPropertyValues, "CommandURL" ) >>= sCommandURL;
      60           0 :     return sCommandURL;
      61             : }
      62             : 
      63             : void SAL_CALL
      64           0 : ScVbaCommandBarControl::setOnAction( const OUString& _onaction ) throw (uno::RuntimeException)
      65             : {
      66             :     // get the current model
      67           0 :     uno::Reference< frame::XModel > xModel( pCBarHelper->getModel() );
      68           0 :     MacroResolvedInfo aResolvedMacro = ooo::vba::resolveVBAMacro( getSfxObjShell( xModel ), _onaction, true );
      69           0 :     if ( aResolvedMacro.mbFound )
      70             :     {
      71           0 :         OUString aCommandURL = ooo::vba::makeMacroURL( aResolvedMacro.msResolvedMacro );
      72             :         SAL_INFO("vbahelper", "ScVbaCommandBarControl::setOnAction: " << aCommandURL);
      73           0 :         setPropertyValue( m_aPropertyValues, "CommandURL" , uno::makeAny( aCommandURL ) );
      74           0 :         ApplyChange();
      75           0 :     }
      76           0 : }
      77             : 
      78             : ::sal_Bool SAL_CALL
      79           0 : ScVbaCommandBarControl::getVisible() throw (uno::RuntimeException)
      80             : {
      81           0 :     sal_Bool bVisible = sal_True;
      82           0 :     uno::Any aValue = getPropertyValue( m_aPropertyValues, ITEM_DESCRIPTOR_ISVISIBLE );
      83           0 :     if( aValue.hasValue() )
      84           0 :         aValue >>= bVisible;
      85           0 :     return bVisible;
      86             : }
      87             : void SAL_CALL
      88           0 : ScVbaCommandBarControl::setVisible( ::sal_Bool _visible ) throw (uno::RuntimeException)
      89             : {
      90           0 :     uno::Any aValue = getPropertyValue( m_aPropertyValues, ITEM_DESCRIPTOR_ISVISIBLE );
      91           0 :     if( aValue.hasValue() )
      92             :     {
      93           0 :         setPropertyValue( m_aPropertyValues, ITEM_DESCRIPTOR_ISVISIBLE , uno::makeAny( _visible ) );
      94           0 :         ApplyChange();
      95           0 :     }
      96           0 : }
      97             : 
      98             : ::sal_Bool SAL_CALL
      99           0 : ScVbaCommandBarControl::getEnabled() throw (uno::RuntimeException)
     100             : {
     101           0 :     sal_Bool bEnabled = sal_True;
     102             : 
     103           0 :     uno::Any aValue = getPropertyValue( m_aPropertyValues, ITEM_DESCRIPTOR_ENABLED );
     104           0 :     if( aValue.hasValue() )
     105             :     {
     106           0 :         aValue >>= bEnabled;
     107             :     }
     108             :     else
     109             :     {
     110             :         // emulated with Visible
     111           0 :         bEnabled = getVisible();
     112             :     }
     113           0 :     return bEnabled;
     114             : }
     115             : 
     116             : void SAL_CALL
     117           0 : ScVbaCommandBarControl::setEnabled( sal_Bool _enabled ) throw (uno::RuntimeException)
     118             : {
     119           0 :     uno::Any aValue = getPropertyValue( m_aPropertyValues, ITEM_DESCRIPTOR_ENABLED );
     120           0 :     if( aValue.hasValue() )
     121             :     {
     122           0 :         setPropertyValue( m_aPropertyValues, ITEM_DESCRIPTOR_ENABLED , uno::makeAny( _enabled ) );
     123           0 :         ApplyChange();
     124             :     }
     125             :     else
     126             :     {
     127             :         // emulated with Visible
     128           0 :         setVisible( _enabled );
     129           0 :     }
     130           0 : }
     131             : 
     132             : ::sal_Bool SAL_CALL
     133           0 : ScVbaCommandBarControl::getBeginGroup() throw (css::uno::RuntimeException)
     134             : {
     135             :     // TODO: need to check if the item before this item is of type 'separator'
     136             :     //#STUB
     137           0 :     return sal_False;
     138             : }
     139             : 
     140             : void SAL_CALL
     141           0 : ScVbaCommandBarControl::setBeginGroup( ::sal_Bool _begin ) throw (css::uno::RuntimeException)
     142             : {
     143           0 :     if( getBeginGroup() != _begin )
     144             :     {
     145             :         // TODO: need to insert or remove an item of type 'separator' before this item
     146             :     }
     147           0 : }
     148             : 
     149             : void SAL_CALL
     150           0 : ScVbaCommandBarControl::Delete(  ) throw (script::BasicErrorException, uno::RuntimeException)
     151             : {
     152           0 :     if( m_xCurrentSettings.is() )
     153             :     {
     154           0 :         uno::Reference< container::XIndexContainer > xIndexContainer( m_xCurrentSettings, uno::UNO_QUERY_THROW );
     155           0 :         xIndexContainer->removeByIndex( m_nPosition );
     156             : 
     157           0 :         pCBarHelper->ApplyChange( m_sResourceUrl, m_xBarSettings );
     158             :     }
     159           0 : }
     160             : 
     161             : uno::Any SAL_CALL
     162           0 : ScVbaCommandBarControl::Controls( const uno::Any& aIndex ) throw (script::BasicErrorException, uno::RuntimeException)
     163             : {
     164             :     // only Popup Menu has controls
     165           0 :     uno::Reference< container::XIndexAccess > xSubMenu;
     166           0 :     getPropertyValue( m_aPropertyValues, ITEM_DESCRIPTOR_CONTAINER ) >>= xSubMenu;
     167           0 :     if( !xSubMenu.is() )
     168           0 :         throw uno::RuntimeException();
     169             : 
     170           0 :     uno::Reference< XCommandBarControls > xCommandBarControls( new ScVbaCommandBarControls( this, mxContext, xSubMenu, pCBarHelper, m_xBarSettings, m_sResourceUrl ) );
     171           0 :     if( aIndex.hasValue() )
     172             :     {
     173           0 :         return xCommandBarControls->Item( aIndex, uno::Any() );
     174             :     }
     175           0 :     return uno::makeAny( xCommandBarControls );
     176             : }
     177             : 
     178             : OUString
     179           0 : ScVbaCommandBarControl::getServiceImplName()
     180             : {
     181           0 :     return OUString("ScVbaCommandBarControl");
     182             : }
     183             : 
     184             : uno::Sequence<OUString>
     185           0 : ScVbaCommandBarControl::getServiceNames()
     186             : {
     187           0 :     static uno::Sequence< OUString > aServiceNames;
     188           0 :     if ( aServiceNames.getLength() == 0 )
     189             :     {
     190           0 :         aServiceNames.realloc( 1 );
     191           0 :         aServiceNames[ 0 ] = "ooo.vba.CommandBarControl";
     192             :     }
     193           0 :     return aServiceNames;
     194             : }
     195             : 
     196             : //////////// ScVbaCommandBarPopup //////////////////////////////
     197           0 : ScVbaCommandBarPopup::ScVbaCommandBarPopup( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess >& xSettings, VbaCommandBarHelperRef pHelper, const css::uno::Reference< css::container::XIndexAccess >& xBarSettings, const OUString& sResourceUrl, sal_Int32 nPosition, sal_Bool bTemporary ) throw (css::uno::RuntimeException) : CommandBarPopup_BASE( xParent, xContext, xSettings, pHelper, xBarSettings, sResourceUrl )
     198             : {
     199           0 :     m_nPosition = nPosition;
     200           0 :     m_bTemporary = bTemporary;
     201           0 :     m_xCurrentSettings->getByIndex( m_nPosition ) >>= m_aPropertyValues;
     202           0 : }
     203             : 
     204             : OUString
     205           0 : ScVbaCommandBarPopup::getServiceImplName()
     206             : {
     207           0 :     return OUString("ScVbaCommandBarPopup");
     208             : }
     209             : 
     210             : uno::Sequence<OUString>
     211           0 : ScVbaCommandBarPopup::getServiceNames()
     212             : {
     213           0 :     static uno::Sequence< OUString > aServiceNames;
     214           0 :     if ( aServiceNames.getLength() == 0 )
     215             :     {
     216           0 :         aServiceNames.realloc( 1 );
     217           0 :         aServiceNames[ 0 ] = "ooo.vba.CommandBarPopup";
     218             :     }
     219           0 :     return aServiceNames;
     220             : }
     221             : 
     222             : //////////// ScVbaCommandBarButton //////////////////////////////
     223           0 : ScVbaCommandBarButton::ScVbaCommandBarButton( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess >& xSettings, VbaCommandBarHelperRef pHelper, const css::uno::Reference< css::container::XIndexAccess >& xBarSettings, const OUString& sResourceUrl, sal_Int32 nPosition, sal_Bool bTemporary ) throw (css::uno::RuntimeException) : CommandBarButton_BASE( xParent, xContext, xSettings, pHelper, xBarSettings, sResourceUrl )
     224             : {
     225           0 :     m_nPosition = nPosition;
     226           0 :     m_bTemporary = bTemporary;
     227           0 :     m_xCurrentSettings->getByIndex( m_nPosition ) >>= m_aPropertyValues;
     228           0 : }
     229             : 
     230             : OUString
     231           0 : ScVbaCommandBarButton::getServiceImplName()
     232             : {
     233           0 :     return OUString("ScVbaCommandBarButton");
     234             : }
     235             : 
     236             : uno::Sequence<OUString>
     237           0 : ScVbaCommandBarButton::getServiceNames()
     238             : {
     239           0 :     static uno::Sequence< OUString > aServiceNames;
     240           0 :     if ( aServiceNames.getLength() == 0 )
     241             :     {
     242           0 :         aServiceNames.realloc( 1 );
     243           0 :         aServiceNames[ 0 ] = "ooo.vba.CommandBarButton";
     244             :     }
     245           0 :     return aServiceNames;
     246         186 : }
     247             : 
     248             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10