1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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
;
16 typedef ::cppu::WeakImplHelper1
< container::XEnumeration
> MenuBarEnumeration_BASE
;
18 class MenuBarEnumeration
: public MenuBarEnumeration_BASE
20 uno::Reference
< XHelperInterface
> m_xParent
;
21 uno::Reference
< uno::XComponentContext
> m_xContext
;
22 uno::Reference
< container::XEnumeration
> m_xEnumeration
;
24 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
)
27 virtual sal_Bool SAL_CALL
hasMoreElements() throw ( uno::RuntimeException
, std::exception
) SAL_OVERRIDE
29 return m_xEnumeration
->hasMoreElements();
31 virtual uno::Any SAL_CALL
nextElement() throw ( container::NoSuchElementException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
) SAL_OVERRIDE
33 // FIXME: should be add menubar
34 if( hasMoreElements() )
36 uno::Reference
< XCommandBar
> xCommandBar( m_xEnumeration
->nextElement(), uno::UNO_QUERY_THROW
);
37 uno::Reference
< excel::XMenuBar
> xMenuBar( new ScVbaMenuBar( m_xParent
, m_xContext
, xCommandBar
) );
38 return uno::makeAny( xMenuBar
);
41 throw container::NoSuchElementException();
45 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
)
49 ScVbaMenuBars::~ScVbaMenuBars()
55 ScVbaMenuBars::getElementType() throw ( uno::RuntimeException
)
57 return cppu::UnoType
<excel::XMenuBar
>::get();
60 uno::Reference
< container::XEnumeration
>
61 ScVbaMenuBars::createEnumeration() throw ( uno::RuntimeException
)
63 uno::Reference
< container::XEnumerationAccess
> xEnumAccess( m_xCommandBars
, uno::UNO_QUERY_THROW
);
64 return uno::Reference
< container::XEnumeration
>( new MenuBarEnumeration( this, mxContext
, xEnumAccess
->createEnumeration() ) );
68 ScVbaMenuBars::createCollectionObject( const uno::Any
& aSource
)
75 ScVbaMenuBars::getCount() throw(css::uno::RuntimeException
)
77 return m_xCommandBars
->getCount();
80 // ScVbaCollectionBaseImpl
82 ScVbaMenuBars::Item( const uno::Any
& aIndex
, const uno::Any
& /*aIndex2*/ ) throw( uno::RuntimeException
)
86 if( nIndex
== excel::XlSheetType::xlWorksheet
)
89 aSource
<<= OUString( "Worksheet Menu Bar" );
90 uno::Reference
< XCommandBar
> xCommandBar( m_xCommandBars
->Item( aSource
, uno::Any() ), uno::UNO_QUERY_THROW
);
91 uno::Reference
< excel::XMenuBar
> xMenuBar( new ScVbaMenuBar( this, mxContext
, xCommandBar
) );
92 return uno::makeAny( xMenuBar
);
95 throw uno::RuntimeException("Not implemented" );
100 ScVbaMenuBars::getServiceImplName()
102 return OUString("ScVbaMenuBars");
105 uno::Sequence
<OUString
>
106 ScVbaMenuBars::getServiceNames()
108 static uno::Sequence
< OUString
> aServiceNames
;
109 if ( aServiceNames
.getLength() == 0 )
111 aServiceNames
.realloc( 1 );
112 aServiceNames
[ 0 ] = "ooo.vba.excel.MenuBars";
114 return aServiceNames
;
117 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */