LibreOffice Module sc (master) 1
vbamenuitems.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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"
13#include <ooo/vba/office/MsoControlType.hpp>
14#include <ooo/vba/XCommandBarControls.hpp>
15#include <utility>
16
17using namespace com::sun::star;
18using namespace ooo::vba;
19
20typedef ::cppu::WeakImplHelper< container::XEnumeration > MenuEnumeration_BASE;
21
22namespace {
23
24class MenuEnumeration : public MenuEnumeration_BASE
25{
26 uno::Reference< XHelperInterface > m_xParent;
27 uno::Reference< uno::XComponentContext > m_xContext;
28 uno::Reference< container::XEnumeration > m_xEnumeration;
29public:
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 ))
32 {
33 }
34 virtual sal_Bool SAL_CALL hasMoreElements() override
35 {
36 return m_xEnumeration->hasMoreElements();
37 }
38 virtual uno::Any SAL_CALL nextElement() override
39 {
40 // FIXME: should be add menu
41 if( !hasMoreElements() )
42 throw container::NoSuchElementException();
43
44 uno::Reference< XCommandBarControl > xCommandBarControl( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW );
45 if( xCommandBarControl->getType() == office::MsoControlType::msoControlPopup )
46 {
47 uno::Reference< excel::XMenu > xMenu( new ScVbaMenu( m_xParent, m_xContext, xCommandBarControl ) );
48 return uno::Any( xMenu );
49 }
50 else if( xCommandBarControl->getType() == office::MsoControlType::msoControlButton )
51 {
52 uno::Reference< excel::XMenuItem > xMenuItem( new ScVbaMenuItem( m_xParent, m_xContext, xCommandBarControl ) );
53 return uno::Any( xMenuItem );
54 }
55 nextElement();
56
57 return uno::Any();
58 }
59};
60
61}
62
63ScVbaMenuItems::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 ))
64{
65}
66
67// XEnumerationAccess
68uno::Type SAL_CALL
70{
72}
73
74uno::Reference< container::XEnumeration >
76{
77 uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xCommandBarControls, uno::UNO_QUERY_THROW );
78 return uno::Reference< container::XEnumeration >( new MenuEnumeration( this, mxContext, xEnumAccess->createEnumeration() ) );
79}
80
83{
84 // make no sense
85 return aSource;
86}
87
88sal_Int32 SAL_CALL
90{
91 // FIXME: should check if it is a popup menu
92 return m_xCommandBarControls->getCount();
93}
94
95// ScVbaCollectionBaseImpl
96uno::Any SAL_CALL
97ScVbaMenuItems::Item( const uno::Any& aIndex, const uno::Any& /*aIndex2*/ )
98{
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();
105}
106
107uno::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*/ )
108{
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() )
114 {
115 OUString sAction;
116 OnAction >>= sAction;
117 xCommandBarControl->setOnAction( sAction );
118 }
119 return uno::Reference< excel::XMenuItem >( new ScVbaMenuItem( this, mxContext, xCommandBarControl ) );
120}
121
122// XHelperInterface
123OUString
125{
126 return "ScVbaMenuItems";
127}
128
129uno::Sequence<OUString>
131{
132 static uno::Sequence< OUString > const aServiceNames
133 {
134 "ooo.vba.excel.MenuItems"
135 };
136 return aServiceNames;
137}
138
139/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XComponentContext > m_xContext
css::uno::Reference< css::uno::XComponentContext > mxContext
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
virtual OUString getServiceImplName() override
virtual css::uno::Sequence< OUString > getServiceNames() override
virtual css::uno::Reference< ov::excel::XMenuItem > SAL_CALL 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) override
ScVbaMenuItems(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, css::uno::Reference< ov::XCommandBarControls > xCommandBarControls)
virtual css::uno::Any SAL_CALL Item(const css::uno::Any &Index, const css::uno::Any &) override
virtual sal_Int32 SAL_CALL getCount() override
css::uno::Reference< ov::XCommandBarControls > m_xCommandBarControls
virtual css::uno::Type SAL_CALL getElementType() override
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
css::uno::Type const & get()
std::deque< AttacherIndex_Impl > aIndex
Sequence< OUString > aServiceNames
Reference
unsigned char sal_Bool
::cppu::WeakImplHelper< container::XEnumeration > MenuEnumeration_BASE