tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / vba / vbamenuitems.cxx
blob37dcc4b25eb366a30620d3fb966bdfd608c857e3
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 "vbamenuitems.hxx"
10 #include "vbamenuitem.hxx"
11 #include "vbamenu.hxx"
12 #include <cppuhelper/implbase.hxx>
13 #include <ooo/vba/office/MsoControlType.hpp>
14 #include <ooo/vba/XCommandBarControls.hpp>
15 #include <utility>
17 using namespace com::sun::star;
18 using namespace ooo::vba;
20 typedef ::cppu::WeakImplHelper< container::XEnumeration > MenuEnumeration_BASE;
22 namespace {
24 class MenuEnumeration : public MenuEnumeration_BASE
26 uno::Reference< XHelperInterface > m_xParent;
27 uno::Reference< uno::XComponentContext > m_xContext;
28 uno::Reference< container::XEnumeration > m_xEnumeration;
29 public:
30 /// @throws uno::RuntimeException
31 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 ))
34 virtual sal_Bool SAL_CALL hasMoreElements() override
36 return m_xEnumeration->hasMoreElements();
38 virtual uno::Any SAL_CALL nextElement() override
40 // FIXME: should be add menu
41 if( !hasMoreElements() )
42 throw container::NoSuchElementException();
44 uno::Reference< XCommandBarControl > xCommandBarControl( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW );
45 if( xCommandBarControl->getType() == office::MsoControlType::msoControlPopup )
47 uno::Reference< excel::XMenu > xMenu( new ScVbaMenu( m_xParent, m_xContext, xCommandBarControl ) );
48 return uno::Any( xMenu );
50 else if( xCommandBarControl->getType() == office::MsoControlType::msoControlButton )
52 uno::Reference< excel::XMenuItem > xMenuItem( new ScVbaMenuItem( m_xParent, m_xContext, xCommandBarControl ) );
53 return uno::Any( xMenuItem );
55 nextElement();
57 return uno::Any();
63 ScVbaMenuItems::ScVbaMenuItems( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, uno::Reference< XCommandBarControls > xCommandBarControls ) : MenuItems_BASE( xParent, xContext, uno::Reference< container::XIndexAccess>() ), m_xCommandBarControls(std::move( xCommandBarControls ))
67 // XEnumerationAccess
68 uno::Type SAL_CALL
69 ScVbaMenuItems::getElementType()
71 return cppu::UnoType<excel::XMenuItem>::get();
74 uno::Reference< container::XEnumeration >
75 ScVbaMenuItems::createEnumeration()
77 uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xCommandBarControls, uno::UNO_QUERY_THROW );
78 return uno::Reference< container::XEnumeration >( new MenuEnumeration( this, mxContext, xEnumAccess->createEnumeration() ) );
81 uno::Any
82 ScVbaMenuItems::createCollectionObject( const uno::Any& aSource )
84 // make no sense
85 return aSource;
88 sal_Int32 SAL_CALL
89 ScVbaMenuItems::getCount()
91 // FIXME: should check if it is a popup menu
92 return m_xCommandBarControls->getCount();
95 // ScVbaCollectionBaseImpl
96 uno::Any SAL_CALL
97 ScVbaMenuItems::Item( const uno::Any& aIndex, const uno::Any& /*aIndex2*/ )
99 uno::Reference< XCommandBarControl > xCommandBarControl( m_xCommandBarControls->Item( aIndex, uno::Any() ), uno::UNO_QUERY_THROW );
100 if( xCommandBarControl->getType() == office::MsoControlType::msoControlPopup )
101 return uno::Any( uno::Reference< excel::XMenu > ( new ScVbaMenu( this, mxContext, xCommandBarControl ) ) );
102 else if( xCommandBarControl->getType() == office::MsoControlType::msoControlButton )
103 return uno::Any( uno::Reference< excel::XMenuItem > ( new ScVbaMenuItem( this, mxContext, xCommandBarControl ) ) );
104 throw uno::RuntimeException();
107 uno::Reference< excel::XMenuItem > SAL_CALL ScVbaMenuItems::Add( const OUString& Caption, const css::uno::Any& OnAction, const css::uno::Any& /*ShortcutKey*/, const css::uno::Any& Before, const css::uno::Any& Restore, const css::uno::Any& /*StatusBar*/, const css::uno::Any& /*HelpFile*/, const css::uno::Any& /*HelpContextID*/ )
109 uno::Reference< XCommandBarControl > xCommandBarControl = m_xCommandBarControls->Add(
110 uno::Any( office::MsoControlType::msoControlButton ),
111 uno::Any(), uno::Any(), Before, Restore );
112 xCommandBarControl->setCaption( Caption );
113 if( OnAction.hasValue() )
115 OUString sAction;
116 OnAction >>= sAction;
117 xCommandBarControl->setOnAction( sAction );
119 return uno::Reference< excel::XMenuItem >( new ScVbaMenuItem( this, mxContext, xCommandBarControl ) );
122 // XHelperInterface
123 OUString
124 ScVbaMenuItems::getServiceImplName()
126 return u"ScVbaMenuItems"_ustr;
129 uno::Sequence<OUString>
130 ScVbaMenuItems::getServiceNames()
132 static uno::Sequence< OUString > const aServiceNames
134 u"ooo.vba.excel.MenuItems"_ustr
136 return aServiceNames;
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */