LCOV - code coverage report
Current view: top level - libreoffice/sc/source/ui/vba - vbamenuitems.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 52 0.0 %
Date: 2012-12-27 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             :  * Version: MPL 1.1 / GPLv3+ / LGPLv3+
       4             :  *
       5             :  * The contents of this file are subject to the Mozilla Public License Version
       6             :  * 1.1 (the "License"); you may not use this file except in compliance with
       7             :  * the License. You may obtain a copy of the License at
       8             :  * http://www.mozilla.org/MPL/
       9             :  *
      10             :  * Software distributed under the License is distributed on an "AS IS" basis,
      11             :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12             :  * for the specific language governing rights and limitations under the
      13             :  * License.
      14             :  *
      15             :  * The Initial Developer of the Original Code is
      16             :  *       Novell Inc.
      17             :  * Portions created by the Initial Developer are Copyright (C) 2010 the
      18             :  * Initial Developer. All Rights Reserved.
      19             :  *
      20             :  * Contributor(s): Pei Feng Lin <pflin@novell.com>
      21             :  *
      22             :  * Alternatively, the contents of this file may be used under the terms of
      23             :  * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
      24             :  * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
      25             :  * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
      26             :  * instead of those above.
      27             :  */
      28             : #include "vbamenuitems.hxx"
      29             : #include "vbamenuitem.hxx"
      30             : #include "vbamenu.hxx"
      31             : #include <ooo/vba/office/MsoControlType.hpp>
      32             : 
      33             : using namespace com::sun::star;
      34             : using namespace ooo::vba;
      35             : 
      36             : 
      37             : typedef ::cppu::WeakImplHelper1< container::XEnumeration > MenuEnumeration_BASE;
      38             : 
      39           0 : class MenuEnumeration : public MenuEnumeration_BASE
      40             : {
      41             :     uno::Reference< XHelperInterface > m_xParent;
      42             :     uno::Reference< uno::XComponentContext > m_xContext;
      43             :     uno::Reference< container::XEnumeration > m_xEnumeration;
      44             : public:
      45           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 )
      46             :     {
      47           0 :     }
      48           0 :     virtual sal_Bool SAL_CALL hasMoreElements() throw ( uno::RuntimeException )
      49             :     {
      50           0 :         return m_xEnumeration->hasMoreElements();
      51             :     }
      52           0 :     virtual uno::Any SAL_CALL nextElement() throw ( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException )
      53             :     {
      54             :         // FIXME: should be add menu
      55           0 :         if( hasMoreElements() )
      56             :         {
      57           0 :             uno::Reference< XCommandBarControl > xCommandBarControl( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW );
      58           0 :             if( xCommandBarControl->getType() == office::MsoControlType::msoControlPopup )
      59             :             {
      60           0 :                 uno::Reference< excel::XMenu > xMenu( new ScVbaMenu( m_xParent, m_xContext, xCommandBarControl ) );
      61           0 :                 return uno::makeAny( xMenu );
      62             :             }
      63           0 :             else if( xCommandBarControl->getType() == office::MsoControlType::msoControlButton )
      64             :             {
      65           0 :                 uno::Reference< excel::XMenuItem > xMenuItem( new ScVbaMenuItem( m_xParent, m_xContext, xCommandBarControl ) );
      66           0 :                 return uno::makeAny( xMenuItem );
      67             :             }
      68           0 :             nextElement();
      69             :         }
      70             :         else
      71           0 :             throw container::NoSuchElementException();
      72           0 :         return uno::Any();
      73             :     }
      74             : };
      75             : 
      76           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 )
      77             : {
      78           0 : }
      79             : 
      80             : // XEnumerationAccess
      81             : uno::Type SAL_CALL
      82           0 : ScVbaMenuItems::getElementType() throw ( uno::RuntimeException )
      83             : {
      84           0 :     return excel::XMenuItem::static_type( 0 );
      85             : }
      86             : 
      87             : uno::Reference< container::XEnumeration >
      88           0 : ScVbaMenuItems::createEnumeration() throw ( uno::RuntimeException )
      89             : {
      90           0 :     uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xCommandBarControls, uno::UNO_QUERY_THROW );
      91           0 :     return uno::Reference< container::XEnumeration >( new MenuEnumeration( this, mxContext, xEnumAccess->createEnumeration() ) );
      92             : }
      93             : 
      94             : uno::Any
      95           0 : ScVbaMenuItems::createCollectionObject( const uno::Any& aSource )
      96             : {
      97             :     // make no sense
      98           0 :     return aSource;
      99             : }
     100             : 
     101             : sal_Int32 SAL_CALL
     102           0 : ScVbaMenuItems::getCount() throw(css::uno::RuntimeException)
     103             : {
     104             :     // FIXME: should check if it is a popup menu
     105           0 :     return m_xCommandBarControls->getCount();
     106             : }
     107             : 
     108             : // ScVbaCollectionBaseImpl
     109             : uno::Any SAL_CALL
     110           0 : ScVbaMenuItems::Item( const uno::Any& aIndex, const uno::Any& /*aIndex2*/ ) throw( uno::RuntimeException )
     111             : {
     112           0 :     uno::Reference< XCommandBarControl > xCommandBarControl( m_xCommandBarControls->Item( aIndex, uno::Any() ), uno::UNO_QUERY_THROW );
     113           0 :     if( xCommandBarControl->getType() == office::MsoControlType::msoControlPopup )
     114           0 :         return uno::makeAny( uno::Reference< excel::XMenu > ( new ScVbaMenu( this, mxContext, xCommandBarControl ) ) );
     115           0 :     else if( xCommandBarControl->getType() == office::MsoControlType::msoControlButton )
     116           0 :         return uno::makeAny( uno::Reference< excel::XMenuItem > ( new ScVbaMenuItem( this, mxContext, xCommandBarControl ) ) );
     117           0 :     throw uno::RuntimeException();
     118             : }
     119             : 
     120           0 : uno::Reference< excel::XMenuItem > SAL_CALL ScVbaMenuItems::Add( const rtl::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)
     121             : {
     122           0 :     sal_Int32 nType = office::MsoControlType::msoControlButton;
     123           0 :     uno::Reference< XCommandBarControl > xCommandBarControl = m_xCommandBarControls->Add( uno::makeAny( nType ), uno::Any(), uno::Any(), Before, Restore );
     124           0 :     xCommandBarControl->setCaption( Caption );
     125           0 :     if( OnAction.hasValue() )
     126             :     {
     127           0 :         rtl::OUString sAction;
     128           0 :         OnAction >>= sAction;
     129           0 :         xCommandBarControl->setOnAction( sAction );
     130             :     }
     131           0 :     return uno::Reference< excel::XMenuItem >( new ScVbaMenuItem( this, mxContext, xCommandBarControl ) );
     132             : }
     133             : 
     134             : // XHelperInterface
     135             : rtl::OUString
     136           0 : ScVbaMenuItems::getServiceImplName()
     137             : {
     138           0 :     return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ScVbaMenuItems"));
     139             : }
     140             : 
     141             : uno::Sequence<rtl::OUString>
     142           0 : ScVbaMenuItems::getServiceNames()
     143             : {
     144           0 :     static uno::Sequence< rtl::OUString > aServiceNames;
     145           0 :     if ( aServiceNames.getLength() == 0 )
     146             :     {
     147           0 :         aServiceNames.realloc( 1 );
     148           0 :         aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.MenuItems" ) );
     149             :     }
     150           0 :     return aServiceNames;
     151             : }
     152             : 
     153             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10