LCOV - code coverage report
Current view: top level - sc/source/ui/vba - vbamenuitems.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 52 0.0 %
Date: 2014-04-11 Functions: 0 14 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             : #include "vbamenuitems.hxx"
      10             : #include "vbamenuitem.hxx"
      11             : #include "vbamenu.hxx"
      12             : #include <ooo/vba/office/MsoControlType.hpp>
      13             : 
      14             : using namespace com::sun::star;
      15             : using namespace ooo::vba;
      16             : 
      17             : 
      18             : typedef ::cppu::WeakImplHelper1< container::XEnumeration > MenuEnumeration_BASE;
      19             : 
      20           0 : class MenuEnumeration : public MenuEnumeration_BASE
      21             : {
      22             :     uno::Reference< XHelperInterface > m_xParent;
      23             :     uno::Reference< uno::XComponentContext > m_xContext;
      24             :     uno::Reference< container::XEnumeration > m_xEnumeration;
      25             : public:
      26           0 :     MenuEnumeration( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XEnumeration >& xEnumeration) throw ( uno::RuntimeException ) : m_xParent( xParent ), m_xContext( xContext ), m_xEnumeration( xEnumeration )
      27             :     {
      28           0 :     }
      29           0 :     virtual sal_Bool SAL_CALL hasMoreElements() throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE
      30             :     {
      31           0 :         return m_xEnumeration->hasMoreElements();
      32             :     }
      33           0 :     virtual uno::Any SAL_CALL nextElement() throw ( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception ) SAL_OVERRIDE
      34             :     {
      35             :         // FIXME: should be add menu
      36           0 :         if( hasMoreElements() )
      37             :         {
      38           0 :             uno::Reference< XCommandBarControl > xCommandBarControl( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW );
      39           0 :             if( xCommandBarControl->getType() == office::MsoControlType::msoControlPopup )
      40             :             {
      41           0 :                 uno::Reference< excel::XMenu > xMenu( new ScVbaMenu( m_xParent, m_xContext, xCommandBarControl ) );
      42           0 :                 return uno::makeAny( xMenu );
      43             :             }
      44           0 :             else if( xCommandBarControl->getType() == office::MsoControlType::msoControlButton )
      45             :             {
      46           0 :                 uno::Reference< excel::XMenuItem > xMenuItem( new ScVbaMenuItem( m_xParent, m_xContext, xCommandBarControl ) );
      47           0 :                 return uno::makeAny( xMenuItem );
      48             :             }
      49           0 :             nextElement();
      50             :         }
      51             :         else
      52           0 :             throw container::NoSuchElementException();
      53           0 :         return uno::Any();
      54             :     }
      55             : };
      56             : 
      57           0 : ScVbaMenuItems::ScVbaMenuItems( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< XCommandBarControls >& xCommandBarControls ) throw ( uno::RuntimeException ) : MenuItems_BASE( xParent, xContext, uno::Reference< container::XIndexAccess>() ), m_xCommandBarControls( xCommandBarControls )
      58             : {
      59           0 : }
      60             : 
      61             : // XEnumerationAccess
      62             : uno::Type SAL_CALL
      63           0 : ScVbaMenuItems::getElementType() throw ( uno::RuntimeException )
      64             : {
      65           0 :     return cppu::UnoType<excel::XMenuItem>::get();
      66             : }
      67             : 
      68             : uno::Reference< container::XEnumeration >
      69           0 : ScVbaMenuItems::createEnumeration() throw ( uno::RuntimeException )
      70             : {
      71           0 :     uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xCommandBarControls, uno::UNO_QUERY_THROW );
      72           0 :     return uno::Reference< container::XEnumeration >( new MenuEnumeration( this, mxContext, xEnumAccess->createEnumeration() ) );
      73             : }
      74             : 
      75             : uno::Any
      76           0 : ScVbaMenuItems::createCollectionObject( const uno::Any& aSource )
      77             : {
      78             :     // make no sense
      79           0 :     return aSource;
      80             : }
      81             : 
      82             : sal_Int32 SAL_CALL
      83           0 : ScVbaMenuItems::getCount() throw(css::uno::RuntimeException)
      84             : {
      85             :     // FIXME: should check if it is a popup menu
      86           0 :     return m_xCommandBarControls->getCount();
      87             : }
      88             : 
      89             : // ScVbaCollectionBaseImpl
      90             : uno::Any SAL_CALL
      91           0 : ScVbaMenuItems::Item( const uno::Any& aIndex, const uno::Any& /*aIndex2*/ ) throw( uno::RuntimeException )
      92             : {
      93           0 :     uno::Reference< XCommandBarControl > xCommandBarControl( m_xCommandBarControls->Item( aIndex, uno::Any() ), uno::UNO_QUERY_THROW );
      94           0 :     if( xCommandBarControl->getType() == office::MsoControlType::msoControlPopup )
      95           0 :         return uno::makeAny( uno::Reference< excel::XMenu > ( new ScVbaMenu( this, mxContext, xCommandBarControl ) ) );
      96           0 :     else if( xCommandBarControl->getType() == office::MsoControlType::msoControlButton )
      97           0 :         return uno::makeAny( uno::Reference< excel::XMenuItem > ( new ScVbaMenuItem( this, mxContext, xCommandBarControl ) ) );
      98           0 :     throw uno::RuntimeException();
      99             : }
     100             : 
     101           0 : uno::Reference< excel::XMenuItem > SAL_CALL ScVbaMenuItems::Add( const OUString& Caption, const css::uno::Any& OnAction, const css::uno::Any& /*ShortcutKey*/, const css::uno::Any& Before, const css::uno::Any& Restore, const css::uno::Any& /*StatusBar*/, const css::uno::Any& /*HelpFile*/, const css::uno::Any& /*HelpContextID*/ ) throw (css::script::BasicErrorException, css::uno::RuntimeException, std::exception)
     102             : {
     103           0 :     sal_Int32 nType = office::MsoControlType::msoControlButton;
     104           0 :     uno::Reference< XCommandBarControl > xCommandBarControl = m_xCommandBarControls->Add( uno::makeAny( nType ), uno::Any(), uno::Any(), Before, Restore );
     105           0 :     xCommandBarControl->setCaption( Caption );
     106           0 :     if( OnAction.hasValue() )
     107             :     {
     108           0 :         OUString sAction;
     109           0 :         OnAction >>= sAction;
     110           0 :         xCommandBarControl->setOnAction( sAction );
     111             :     }
     112           0 :     return uno::Reference< excel::XMenuItem >( new ScVbaMenuItem( this, mxContext, xCommandBarControl ) );
     113             : }
     114             : 
     115             : // XHelperInterface
     116             : OUString
     117           0 : ScVbaMenuItems::getServiceImplName()
     118             : {
     119           0 :     return OUString("ScVbaMenuItems");
     120             : }
     121             : 
     122             : uno::Sequence<OUString>
     123           0 : ScVbaMenuItems::getServiceNames()
     124             : {
     125           0 :     static uno::Sequence< OUString > aServiceNames;
     126           0 :     if ( aServiceNames.getLength() == 0 )
     127             :     {
     128           0 :         aServiceNames.realloc( 1 );
     129           0 :         aServiceNames[ 0 ] = "ooo.vba.excel.MenuItems";
     130             :     }
     131           0 :     return aServiceNames;
     132             : }
     133             : 
     134             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10