LibreOffice Module sc (master) 1
vbamenus.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 "vbamenus.hxx"
10#include "vbamenu.hxx"
12#include <ooo/vba/office/MsoControlType.hpp>
13#include <ooo/vba/XCommandBarControls.hpp>
14#include <utility>
15
16using namespace com::sun::star;
17using namespace ooo::vba;
18
19typedef ::cppu::WeakImplHelper< container::XEnumeration > MenuEnumeration_BASE;
20
21namespace {
22
23class MenuEnumeration : public MenuEnumeration_BASE
24{
25 uno::Reference< XHelperInterface > m_xParent;
26 uno::Reference< uno::XComponentContext > m_xContext;
27 uno::Reference< container::XEnumeration > m_xEnumeration;
28public:
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 ))
31 {
32 }
33 virtual sal_Bool SAL_CALL hasMoreElements() override
34 {
35 return m_xEnumeration->hasMoreElements();
36 }
37 virtual uno::Any SAL_CALL nextElement() override
38 {
39 // FIXME: should be add menu
40 if( !hasMoreElements() )
41 throw container::NoSuchElementException();
42
43 uno::Reference< XCommandBarControl > xCommandBarControl( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW );
44 if( xCommandBarControl->getType() == office::MsoControlType::msoControlPopup )
45 {
46 uno::Reference< excel::XMenu > xMenu( new ScVbaMenu( m_xParent, m_xContext, xCommandBarControl ) );
47 return uno::Any( xMenu );
48 }
49 nextElement();
50
51 return uno::Any();
52 }
53};
54
55}
56
57ScVbaMenus::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 ))
58{
59}
60
61// XEnumerationAccess
62uno::Type SAL_CALL
64{
66}
67
68uno::Reference< container::XEnumeration >
70{
71 uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xCommandBarControls, uno::UNO_QUERY_THROW );
72 return uno::Reference< container::XEnumeration >( new MenuEnumeration( this, mxContext, xEnumAccess->createEnumeration() ) );
73}
74
77{
78 // make no sense
79 return aSource;
80}
81
82sal_Int32 SAL_CALL
84{
85 // FIXME: should check if it is a popup menu
86 return m_xCommandBarControls->getCount();
87}
88
89// ScVbaCollectionBaseImpl
90uno::Any SAL_CALL
91ScVbaMenus::Item( const uno::Any& aIndex, const uno::Any& /*aIndex2*/ )
92{
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 ) ) );
97}
98
99uno::Reference< excel::XMenu > SAL_CALL ScVbaMenus::Add( const OUString& Caption, const css::uno::Any& Before, const css::uno::Any& Restore )
100{
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 ) );
106}
107
108// XHelperInterface
109OUString
111{
112 return "ScVbaMenus";
113}
114
115uno::Sequence<OUString>
117{
118 static uno::Sequence< OUString > const aServiceNames
119 {
120 "ooo.vba.excel.Menus"
121 };
122 return aServiceNames;
123}
124
125/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XComponentContext > m_xContext
css::uno::Reference< css::uno::XComponentContext > mxContext
virtual css::uno::Any SAL_CALL Item(const css::uno::Any &Index, const css::uno::Any &) override
Definition: vbamenus.cxx:91
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
Definition: vbamenus.cxx:76
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
Definition: vbamenus.cxx:69
css::uno::Reference< ov::XCommandBarControls > m_xCommandBarControls
Definition: vbamenus.hxx:22
ScVbaMenus(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, css::uno::Reference< ov::XCommandBarControls > xCommandBarControls)
Definition: vbamenus.cxx:57
virtual css::uno::Sequence< OUString > getServiceNames() override
Definition: vbamenus.cxx:116
virtual sal_Int32 SAL_CALL getCount() override
Definition: vbamenus.cxx:83
virtual OUString getServiceImplName() override
Definition: vbamenus.cxx:110
virtual css::uno::Type SAL_CALL getElementType() override
Definition: vbamenus.cxx:63
virtual css::uno::Reference< ov::excel::XMenu > SAL_CALL Add(const OUString &Caption, const css::uno::Any &Before, const css::uno::Any &Restore) override
Definition: vbamenus.cxx:99
css::uno::Type const & get()
std::deque< AttacherIndex_Impl > aIndex
Sequence< OUString > aServiceNames
Reference
unsigned char sal_Bool
::cppu::WeakImplHelper< container::XEnumeration > MenuEnumeration_BASE
::cppu::WeakImplHelper< container::XEnumeration > MenuEnumeration_BASE
Definition: vbamenus.cxx:19