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