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 "vbamenus.hxx"
10 #include "vbamenu.hxx"
11 #include <cppuhelper/implbase.hxx>
12 #include <ooo/vba/office/MsoControlType.hpp>
13 #include <ooo/vba/XCommandBarControls.hpp>
15 using namespace com::sun::star
;
16 using namespace ooo::vba
;
18 typedef ::cppu::WeakImplHelper
< container::XEnumeration
> MenuEnumeration_BASE
;
20 class MenuEnumeration
: public MenuEnumeration_BASE
22 uno::Reference
< XHelperInterface
> m_xParent
;
23 uno::Reference
< uno::XComponentContext
> m_xContext
;
24 uno::Reference
< container::XEnumeration
> m_xEnumeration
;
26 /// @throws uno::RuntimeException
27 MenuEnumeration( const uno::Reference
< XHelperInterface
>& xParent
, const uno::Reference
< uno::XComponentContext
>& xContext
, const uno::Reference
< container::XEnumeration
>& xEnumeration
) : m_xParent( xParent
), m_xContext( xContext
), m_xEnumeration( xEnumeration
)
30 virtual sal_Bool SAL_CALL
hasMoreElements() override
32 return m_xEnumeration
->hasMoreElements();
34 virtual uno::Any SAL_CALL
nextElement() override
36 // FIXME: should be add menu
37 if( !hasMoreElements() )
38 throw container::NoSuchElementException();
40 uno::Reference
< XCommandBarControl
> xCommandBarControl( m_xEnumeration
->nextElement(), uno::UNO_QUERY_THROW
);
41 if( xCommandBarControl
->getType() == office::MsoControlType::msoControlPopup
)
43 uno::Reference
< excel::XMenu
> xMenu( new ScVbaMenu( m_xParent
, m_xContext
, xCommandBarControl
) );
44 return uno::makeAny( xMenu
);
52 ScVbaMenus::ScVbaMenus( const uno::Reference
< XHelperInterface
>& xParent
, const uno::Reference
< uno::XComponentContext
>& xContext
, const uno::Reference
< XCommandBarControls
>& xCommandBarControls
) : Menus_BASE( xParent
, xContext
, uno::Reference
< container::XIndexAccess
>() ), m_xCommandBarControls( xCommandBarControls
)
58 ScVbaMenus::getElementType()
60 return cppu::UnoType
<excel::XMenu
>::get();
63 uno::Reference
< container::XEnumeration
>
64 ScVbaMenus::createEnumeration()
66 uno::Reference
< container::XEnumerationAccess
> xEnumAccess( m_xCommandBarControls
, uno::UNO_QUERY_THROW
);
67 return uno::Reference
< container::XEnumeration
>( new MenuEnumeration( this, mxContext
, xEnumAccess
->createEnumeration() ) );
71 ScVbaMenus::createCollectionObject( const uno::Any
& aSource
)
78 ScVbaMenus::getCount()
80 // FIXME: should check if it is a popup menu
81 return m_xCommandBarControls
->getCount();
84 // ScVbaCollectionBaseImpl
86 ScVbaMenus::Item( const uno::Any
& aIndex
, const uno::Any
& /*aIndex2*/ )
88 uno::Reference
< XCommandBarControl
> xCommandBarControl( m_xCommandBarControls
->Item( aIndex
, uno::Any() ), uno::UNO_QUERY_THROW
);
89 if( xCommandBarControl
->getType() != office::MsoControlType::msoControlPopup
)
90 throw uno::RuntimeException();
91 return uno::makeAny( uno::Reference
< excel::XMenu
> ( new ScVbaMenu( this, mxContext
, xCommandBarControl
) ) );
94 uno::Reference
< excel::XMenu
> SAL_CALL
ScVbaMenus::Add( const OUString
& Caption
, const css::uno::Any
& Before
, const css::uno::Any
& Restore
)
96 uno::Reference
< XCommandBarControl
> xCommandBarControl
= m_xCommandBarControls
->Add(
97 uno::makeAny( office::MsoControlType::msoControlPopup
),
98 uno::Any(), uno::Any(), Before
, Restore
);
99 xCommandBarControl
->setCaption( Caption
);
100 return uno::Reference
< excel::XMenu
>( new ScVbaMenu( this, mxContext
, xCommandBarControl
) );
105 ScVbaMenus::getServiceImplName()
110 uno::Sequence
<OUString
>
111 ScVbaMenus::getServiceNames()
113 static uno::Sequence
< OUString
> const aServiceNames
115 "ooo.vba.excel.Menus"
117 return aServiceNames
;
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */