LibreOffice Module sc (master) 1
vbamenubars.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 "vbamenubars.hxx"
10#include "vbamenubar.hxx"
12#include <ooo/vba/excel/XlSheetType.hpp>
13#include <ooo/vba/XCommandBars.hpp>
14#include <utility>
15
16using namespace com::sun::star;
17using namespace ooo::vba;
18
19namespace {
20
21class MenuBarEnumeration : public ::cppu::WeakImplHelper< container::XEnumeration >
22{
23 uno::Reference< XHelperInterface > m_xParent;
24 uno::Reference< uno::XComponentContext > m_xContext;
25 uno::Reference< container::XEnumeration > m_xEnumeration;
26public:
28 MenuBarEnumeration( 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 ))
29 {
30 }
31 virtual sal_Bool SAL_CALL hasMoreElements() override
32 {
33 return m_xEnumeration->hasMoreElements();
34 }
35 virtual uno::Any SAL_CALL nextElement() override
36 {
37 // FIXME: should be add menubar
38 if( !hasMoreElements() )
39 throw container::NoSuchElementException();
40
41 uno::Reference< XCommandBar > xCommandBar( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW );
42 uno::Reference< excel::XMenuBar > xMenuBar( new ScVbaMenuBar( m_xParent, m_xContext, xCommandBar ) );
43 return uno::Any( xMenuBar );
44 }
45};
46
47}
48
49ScVbaMenuBars::ScVbaMenuBars( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, uno::Reference< XCommandBars > xCommandBars ) : MenuBars_BASE( xParent, xContext, uno::Reference< container::XIndexAccess>() ), m_xCommandBars(std::move( xCommandBars ))
50{
51}
52
54{
55}
56
57// XEnumerationAccess
58uno::Type SAL_CALL
60{
62}
63
64uno::Reference< container::XEnumeration >
66{
67 uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xCommandBars, uno::UNO_QUERY_THROW );
68 return uno::Reference< container::XEnumeration >( new MenuBarEnumeration( this, mxContext, xEnumAccess->createEnumeration() ) );
69}
70
73{
74 // make no sense
75 return aSource;
76}
77
78sal_Int32 SAL_CALL
80{
81 return m_xCommandBars->getCount();
82}
83
84// ScVbaCollectionBaseImpl
85uno::Any SAL_CALL
86ScVbaMenuBars::Item( const uno::Any& aIndex, const uno::Any& /*aIndex2*/ )
87{
88 sal_Int16 nIndex = 0;
89 aIndex >>= nIndex;
90 if( nIndex == excel::XlSheetType::xlWorksheet )
91 {
92 uno::Any aSource;
93 aSource <<= OUString( "Worksheet Menu Bar" );
94 uno::Reference< XCommandBar > xCommandBar( m_xCommandBars->Item( aSource, uno::Any() ), uno::UNO_QUERY_THROW );
95 uno::Reference< excel::XMenuBar > xMenuBar( new ScVbaMenuBar( this, mxContext, xCommandBar ) );
96 return uno::Any( xMenuBar );
97 }
98
99 throw uno::RuntimeException("Not implemented" );
100}
101
102// XHelperInterface
103OUString
105{
106 return "ScVbaMenuBars";
107}
108
109uno::Sequence<OUString>
111{
112 static uno::Sequence< OUString > const aServiceNames
113 {
114 "ooo.vba.excel.MenuBars"
115 };
116 return aServiceNames;
117}
118
119/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XComponentContext > m_xContext
css::uno::Reference< css::uno::XComponentContext > mxContext
virtual sal_Int32 SAL_CALL getCount() override
Definition: vbamenubars.cxx:79
virtual css::uno::Type SAL_CALL getElementType() override
Definition: vbamenubars.cxx:59
virtual css::uno::Sequence< OUString > getServiceNames() override
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
Definition: vbamenubars.cxx:65
ScVbaMenuBars(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, css::uno::Reference< ov::XCommandBars > xCommandBars)
Definition: vbamenubars.cxx:49
virtual OUString getServiceImplName() override
virtual css::uno::Any SAL_CALL Item(const css::uno::Any &aIndex, const css::uno::Any &) override
Definition: vbamenubars.cxx:86
css::uno::Reference< ov::XCommandBars > m_xCommandBars
Definition: vbamenubars.hxx:21
virtual ~ScVbaMenuBars() override
Definition: vbamenubars.cxx:53
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
Definition: vbamenubars.cxx:72
css::uno::Type const & get()
std::deque< AttacherIndex_Impl > aIndex
Sequence< OUString > aServiceNames
sal_Int32 nIndex
Reference
unsigned char sal_Bool