tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / vba / vbamenus.cxx
blobd4be37a782d1e32692222a4dc57ecb0ff6b4ff8c
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>
14 #include <utility>
16 using namespace com::sun::star;
17 using namespace ooo::vba;
19 typedef ::cppu::WeakImplHelper< container::XEnumeration > MenuEnumeration_BASE;
21 namespace {
23 class MenuEnumeration : public MenuEnumeration_BASE
25 uno::Reference< XHelperInterface > m_xParent;
26 uno::Reference< uno::XComponentContext > m_xContext;
27 uno::Reference< container::XEnumeration > m_xEnumeration;
28 public:
29 /// @throws uno::RuntimeException
30 MenuEnumeration( 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 ))
33 virtual sal_Bool SAL_CALL hasMoreElements() override
35 return m_xEnumeration->hasMoreElements();
37 virtual uno::Any SAL_CALL nextElement() override
39 // FIXME: should be add menu
40 if( !hasMoreElements() )
41 throw container::NoSuchElementException();
43 uno::Reference< XCommandBarControl > xCommandBarControl( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW );
44 if( xCommandBarControl->getType() == office::MsoControlType::msoControlPopup )
46 uno::Reference< excel::XMenu > xMenu( new ScVbaMenu( m_xParent, m_xContext, xCommandBarControl ) );
47 return uno::Any( xMenu );
49 nextElement();
51 return uno::Any();
57 ScVbaMenus::ScVbaMenus( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, uno::Reference< XCommandBarControls > xCommandBarControls ) : Menus_BASE( xParent, xContext, uno::Reference< container::XIndexAccess>() ), m_xCommandBarControls(std::move( xCommandBarControls ))
61 // XEnumerationAccess
62 uno::Type SAL_CALL
63 ScVbaMenus::getElementType()
65 return cppu::UnoType<excel::XMenu>::get();
68 uno::Reference< container::XEnumeration >
69 ScVbaMenus::createEnumeration()
71 uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xCommandBarControls, uno::UNO_QUERY_THROW );
72 return uno::Reference< container::XEnumeration >( new MenuEnumeration( this, mxContext, xEnumAccess->createEnumeration() ) );
75 uno::Any
76 ScVbaMenus::createCollectionObject( const uno::Any& aSource )
78 // make no sense
79 return aSource;
82 sal_Int32 SAL_CALL
83 ScVbaMenus::getCount()
85 // FIXME: should check if it is a popup menu
86 return m_xCommandBarControls->getCount();
89 // ScVbaCollectionBaseImpl
90 uno::Any SAL_CALL
91 ScVbaMenus::Item( const uno::Any& aIndex, const uno::Any& /*aIndex2*/ )
93 uno::Reference< XCommandBarControl > xCommandBarControl( m_xCommandBarControls->Item( aIndex, uno::Any() ), uno::UNO_QUERY_THROW );
94 if( xCommandBarControl->getType() != office::MsoControlType::msoControlPopup )
95 throw uno::RuntimeException();
96 return uno::Any( uno::Reference< excel::XMenu > ( new ScVbaMenu( this, mxContext, xCommandBarControl ) ) );
99 uno::Reference< excel::XMenu > SAL_CALL ScVbaMenus::Add( const OUString& Caption, const css::uno::Any& Before, const css::uno::Any& Restore )
101 uno::Reference< XCommandBarControl > xCommandBarControl = m_xCommandBarControls->Add(
102 uno::Any( office::MsoControlType::msoControlPopup ),
103 uno::Any(), uno::Any(), Before, Restore );
104 xCommandBarControl->setCaption( Caption );
105 return uno::Reference< excel::XMenu >( new ScVbaMenu( this, mxContext, xCommandBarControl ) );
108 // XHelperInterface
109 OUString
110 ScVbaMenus::getServiceImplName()
112 return u"ScVbaMenus"_ustr;
115 uno::Sequence<OUString>
116 ScVbaMenus::getServiceNames()
118 static uno::Sequence< OUString > const aServiceNames
120 u"ooo.vba.excel.Menus"_ustr
122 return aServiceNames;
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */