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