Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sc / source / ui / vba / vbamenus.cxx
blob84c001d9adec3e8b75e8f5d14b08f8072544e709
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 "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;
25 public:
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 );
46 nextElement();
48 return uno::Any();
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 )
56 // XEnumerationAccess
57 uno::Type SAL_CALL
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() ) );
70 uno::Any
71 ScVbaMenus::createCollectionObject( const uno::Any& aSource )
73 // make no sense
74 return aSource;
77 sal_Int32 SAL_CALL
78 ScVbaMenus::getCount()
80 // FIXME: should check if it is a popup menu
81 return m_xCommandBarControls->getCount();
84 // ScVbaCollectionBaseImpl
85 uno::Any SAL_CALL
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 ) );
103 // XHelperInterface
104 OUString
105 ScVbaMenus::getServiceImplName()
107 return "ScVbaMenus";
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: */