bump product version to 4.1.6.2
[LibreOffice.git] / sc / source / ui / vba / vbamenubars.cxx
blob5ee50155c401019176ea9ef544693b00073c43fd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 "vbamenubars.hxx"
10 #include "vbamenubar.hxx"
11 #include <ooo/vba/excel/XlSheetType.hpp>
13 using namespace com::sun::star;
14 using namespace ooo::vba;
17 typedef ::cppu::WeakImplHelper1< container::XEnumeration > MenuBarEnumeration_BASE;
19 class MenuBarEnumeration : public MenuBarEnumeration_BASE
21 uno::Reference< XHelperInterface > m_xParent;
22 uno::Reference< uno::XComponentContext > m_xContext;
23 uno::Reference< container::XEnumeration > m_xEnumeration;
24 public:
25 MenuBarEnumeration( 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 )
28 virtual sal_Bool SAL_CALL hasMoreElements() throw ( uno::RuntimeException )
30 return m_xEnumeration->hasMoreElements();
32 virtual uno::Any SAL_CALL nextElement() throw ( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException )
34 // FIXME: should be add menubar
35 if( hasMoreElements() )
37 uno::Reference< XCommandBar > xCommandBar( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW );
38 uno::Reference< excel::XMenuBar > xMenuBar( new ScVbaMenuBar( m_xParent, m_xContext, xCommandBar ) );
39 return uno::makeAny( xMenuBar );
41 else
42 throw container::NoSuchElementException();
46 ScVbaMenuBars::ScVbaMenuBars( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< XCommandBars >& xCommandBars ) throw ( uno::RuntimeException ) : MenuBars_BASE( xParent, xContext, uno::Reference< container::XIndexAccess>() ), m_xCommandBars( xCommandBars )
50 ScVbaMenuBars::~ScVbaMenuBars()
54 // XEnumerationAccess
55 uno::Type SAL_CALL
56 ScVbaMenuBars::getElementType() throw ( uno::RuntimeException )
58 return excel::XMenuBar::static_type( 0 );
61 uno::Reference< container::XEnumeration >
62 ScVbaMenuBars::createEnumeration() throw ( uno::RuntimeException )
64 uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xCommandBars, uno::UNO_QUERY_THROW );
65 return uno::Reference< container::XEnumeration >( new MenuBarEnumeration( this, mxContext, xEnumAccess->createEnumeration() ) );
68 uno::Any
69 ScVbaMenuBars::createCollectionObject( const uno::Any& aSource )
71 // make no sense
72 return aSource;
75 sal_Int32 SAL_CALL
76 ScVbaMenuBars::getCount() throw(css::uno::RuntimeException)
78 return m_xCommandBars->getCount();
81 // ScVbaCollectionBaseImpl
82 uno::Any SAL_CALL
83 ScVbaMenuBars::Item( const uno::Any& aIndex, const uno::Any& /*aIndex2*/ ) throw( uno::RuntimeException )
85 sal_Int16 nIndex = 0;
86 aIndex >>= nIndex;
87 if( nIndex == excel::XlSheetType::xlWorksheet )
89 uno::Any aSource;
90 aSource <<= OUString( "Worksheet Menu Bar" );
91 uno::Reference< XCommandBar > xCommandBar( m_xCommandBars->Item( aSource, uno::Any() ), uno::UNO_QUERY_THROW );
92 uno::Reference< excel::XMenuBar > xMenuBar( new ScVbaMenuBar( this, mxContext, xCommandBar ) );
93 return uno::makeAny( xMenuBar );
96 throw uno::RuntimeException( OUString("Not implemented"), uno::Reference< uno::XInterface >() );
99 // XHelperInterface
100 OUString
101 ScVbaMenuBars::getServiceImplName()
103 return OUString("ScVbaMenuBars");
106 uno::Sequence<OUString>
107 ScVbaMenuBars::getServiceNames()
109 static uno::Sequence< OUString > aServiceNames;
110 if ( aServiceNames.getLength() == 0 )
112 aServiceNames.realloc( 1 );
113 aServiceNames[ 0 ] = OUString("ooo.vba.excel.MenuBars" );
115 return aServiceNames;
118 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */