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