nss: upgrade to release 3.73
[LibreOffice.git] / sc / source / ui / vba / vbamenus.cxx
blobf6b33fd896037bab18e6900a54d6bf6f89d675f1
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 namespace {
22 class MenuEnumeration : public MenuEnumeration_BASE
24 uno::Reference< XHelperInterface > m_xParent;
25 uno::Reference< uno::XComponentContext > m_xContext;
26 uno::Reference< container::XEnumeration > m_xEnumeration;
27 public:
28 /// @throws uno::RuntimeException
29 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 )
32 virtual sal_Bool SAL_CALL hasMoreElements() override
34 return m_xEnumeration->hasMoreElements();
36 virtual uno::Any SAL_CALL nextElement() override
38 // FIXME: should be add menu
39 if( !hasMoreElements() )
40 throw container::NoSuchElementException();
42 uno::Reference< XCommandBarControl > xCommandBarControl( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW );
43 if( xCommandBarControl->getType() == office::MsoControlType::msoControlPopup )
45 uno::Reference< excel::XMenu > xMenu( new ScVbaMenu( m_xParent, m_xContext, xCommandBarControl ) );
46 return uno::makeAny( xMenu );
48 nextElement();
50 return uno::Any();
56 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 )
60 // XEnumerationAccess
61 uno::Type SAL_CALL
62 ScVbaMenus::getElementType()
64 return cppu::UnoType<excel::XMenu>::get();
67 uno::Reference< container::XEnumeration >
68 ScVbaMenus::createEnumeration()
70 uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xCommandBarControls, uno::UNO_QUERY_THROW );
71 return uno::Reference< container::XEnumeration >( new MenuEnumeration( this, mxContext, xEnumAccess->createEnumeration() ) );
74 uno::Any
75 ScVbaMenus::createCollectionObject( const uno::Any& aSource )
77 // make no sense
78 return aSource;
81 sal_Int32 SAL_CALL
82 ScVbaMenus::getCount()
84 // FIXME: should check if it is a popup menu
85 return m_xCommandBarControls->getCount();
88 // ScVbaCollectionBaseImpl
89 uno::Any SAL_CALL
90 ScVbaMenus::Item( const uno::Any& aIndex, const uno::Any& /*aIndex2*/ )
92 uno::Reference< XCommandBarControl > xCommandBarControl( m_xCommandBarControls->Item( aIndex, uno::Any() ), uno::UNO_QUERY_THROW );
93 if( xCommandBarControl->getType() != office::MsoControlType::msoControlPopup )
94 throw uno::RuntimeException();
95 return uno::makeAny( uno::Reference< excel::XMenu > ( new ScVbaMenu( this, mxContext, xCommandBarControl ) ) );
98 uno::Reference< excel::XMenu > SAL_CALL ScVbaMenus::Add( const OUString& Caption, const css::uno::Any& Before, const css::uno::Any& Restore )
100 uno::Reference< XCommandBarControl > xCommandBarControl = m_xCommandBarControls->Add(
101 uno::makeAny( office::MsoControlType::msoControlPopup ),
102 uno::Any(), uno::Any(), Before, Restore );
103 xCommandBarControl->setCaption( Caption );
104 return uno::Reference< excel::XMenu >( new ScVbaMenu( this, mxContext, xCommandBarControl ) );
107 // XHelperInterface
108 OUString
109 ScVbaMenus::getServiceImplName()
111 return "ScVbaMenus";
114 uno::Sequence<OUString>
115 ScVbaMenus::getServiceNames()
117 static uno::Sequence< OUString > const aServiceNames
119 "ooo.vba.excel.Menus"
121 return aServiceNames;
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */