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