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 <cppuhelper/implbase.hxx>
12 #include <ooo/vba/excel/XlSheetType.hpp>
13 #include <ooo/vba/XCommandBars.hpp>
16 using namespace com::sun::star
;
17 using namespace ooo::vba
;
21 class MenuBarEnumeration
: public ::cppu::WeakImplHelper
< container::XEnumeration
>
23 uno::Reference
< XHelperInterface
> m_xParent
;
24 uno::Reference
< uno::XComponentContext
> m_xContext
;
25 uno::Reference
< container::XEnumeration
> m_xEnumeration
;
27 /// @throws uno::RuntimeException
28 MenuBarEnumeration( uno::Reference
< XHelperInterface
> xParent
, uno::Reference
< uno::XComponentContext
> xContext
, uno::Reference
< container::XEnumeration
> xEnumeration
) : m_xParent(std::move( xParent
)), m_xContext(std::move( xContext
)), m_xEnumeration(std::move( xEnumeration
))
31 virtual sal_Bool SAL_CALL
hasMoreElements() override
33 return m_xEnumeration
->hasMoreElements();
35 virtual uno::Any SAL_CALL
nextElement() override
37 // FIXME: should be add menubar
38 if( !hasMoreElements() )
39 throw container::NoSuchElementException();
41 uno::Reference
< XCommandBar
> xCommandBar( m_xEnumeration
->nextElement(), uno::UNO_QUERY_THROW
);
42 uno::Reference
< excel::XMenuBar
> xMenuBar( new ScVbaMenuBar( m_xParent
, m_xContext
, xCommandBar
) );
43 return uno::Any( xMenuBar
);
49 ScVbaMenuBars::ScVbaMenuBars( const uno::Reference
< XHelperInterface
>& xParent
, const uno::Reference
< uno::XComponentContext
>& xContext
, uno::Reference
< XCommandBars
> xCommandBars
) : MenuBars_BASE( xParent
, xContext
, uno::Reference
< container::XIndexAccess
>() ), m_xCommandBars(std::move( xCommandBars
))
53 ScVbaMenuBars::~ScVbaMenuBars()
59 ScVbaMenuBars::getElementType()
61 return cppu::UnoType
<excel::XMenuBar
>::get();
64 uno::Reference
< container::XEnumeration
>
65 ScVbaMenuBars::createEnumeration()
67 uno::Reference
< container::XEnumerationAccess
> xEnumAccess( m_xCommandBars
, uno::UNO_QUERY_THROW
);
68 return uno::Reference
< container::XEnumeration
>( new MenuBarEnumeration( this, mxContext
, xEnumAccess
->createEnumeration() ) );
72 ScVbaMenuBars::createCollectionObject( const uno::Any
& aSource
)
79 ScVbaMenuBars::getCount()
81 return m_xCommandBars
->getCount();
84 // ScVbaCollectionBaseImpl
86 ScVbaMenuBars::Item( const uno::Any
& aIndex
, const uno::Any
& /*aIndex2*/ )
90 if( nIndex
== excel::XlSheetType::xlWorksheet
)
93 aSource
<<= u
"Worksheet Menu Bar"_ustr
;
94 uno::Reference
< XCommandBar
> xCommandBar( m_xCommandBars
->Item( aSource
, uno::Any() ), uno::UNO_QUERY_THROW
);
95 uno::Reference
< excel::XMenuBar
> xMenuBar( new ScVbaMenuBar( this, mxContext
, xCommandBar
) );
96 return uno::Any( xMenuBar
);
99 throw uno::RuntimeException(u
"Not implemented"_ustr
);
104 ScVbaMenuBars::getServiceImplName()
106 return u
"ScVbaMenuBars"_ustr
;
109 uno::Sequence
<OUString
>
110 ScVbaMenuBars::getServiceNames()
112 static uno::Sequence
< OUString
> const aServiceNames
114 u
"ooo.vba.excel.MenuBars"_ustr
116 return aServiceNames
;
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */