1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 #include "vbamenus.hxx"
10 #include "vbamenu.hxx"
11 #include <ooo/vba/office/MsoControlType.hpp>
13 using namespace com::sun::star
;
14 using namespace ooo::vba
;
16 typedef ::cppu::WeakImplHelper1
< container::XEnumeration
> MenuEnumeration_BASE
;
18 class MenuEnumeration
: public MenuEnumeration_BASE
20 uno::Reference
< XHelperInterface
> m_xParent
;
21 uno::Reference
< uno::XComponentContext
> m_xContext
;
22 uno::Reference
< container::XEnumeration
> m_xEnumeration
;
24 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
)
27 virtual sal_Bool SAL_CALL
hasMoreElements() throw ( uno::RuntimeException
, std::exception
) SAL_OVERRIDE
29 return m_xEnumeration
->hasMoreElements();
31 virtual uno::Any SAL_CALL
nextElement() throw ( container::NoSuchElementException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
) SAL_OVERRIDE
33 // FIXME: should be add menu
34 if( hasMoreElements() )
36 uno::Reference
< XCommandBarControl
> xCommandBarControl( m_xEnumeration
->nextElement(), uno::UNO_QUERY_THROW
);
37 if( xCommandBarControl
->getType() == office::MsoControlType::msoControlPopup
)
39 uno::Reference
< excel::XMenu
> xMenu( new ScVbaMenu( m_xParent
, m_xContext
, xCommandBarControl
) );
40 return uno::makeAny( xMenu
);
45 throw container::NoSuchElementException();
50 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
)
56 ScVbaMenus::getElementType() throw ( uno::RuntimeException
)
58 return cppu::UnoType
<excel::XMenu
>::get();
61 uno::Reference
< container::XEnumeration
>
62 ScVbaMenus::createEnumeration() throw ( uno::RuntimeException
)
64 uno::Reference
< container::XEnumerationAccess
> xEnumAccess( m_xCommandBarControls
, uno::UNO_QUERY_THROW
);
65 return uno::Reference
< container::XEnumeration
>( new MenuEnumeration( this, mxContext
, xEnumAccess
->createEnumeration() ) );
69 ScVbaMenus::createCollectionObject( const uno::Any
& aSource
)
76 ScVbaMenus::getCount() throw(css::uno::RuntimeException
)
78 // FIXME: should check if it is a popup menu
79 return m_xCommandBarControls
->getCount();
82 // ScVbaCollectionBaseImpl
84 ScVbaMenus::Item( const uno::Any
& aIndex
, const uno::Any
& /*aIndex2*/ ) throw( uno::RuntimeException
)
86 uno::Reference
< XCommandBarControl
> xCommandBarControl( m_xCommandBarControls
->Item( aIndex
, uno::Any() ), uno::UNO_QUERY_THROW
);
87 if( xCommandBarControl
->getType() != office::MsoControlType::msoControlPopup
)
88 throw uno::RuntimeException();
89 return uno::makeAny( uno::Reference
< excel::XMenu
> ( new ScVbaMenu( this, mxContext
, xCommandBarControl
) ) );
92 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
)
94 sal_Int32 nType
= office::MsoControlType::msoControlPopup
;
95 uno::Reference
< XCommandBarControl
> xCommandBarControl
= m_xCommandBarControls
->Add( uno::makeAny( nType
), uno::Any(), uno::Any(), Before
, Restore
);
96 xCommandBarControl
->setCaption( Caption
);
97 return uno::Reference
< excel::XMenu
>( new ScVbaMenu( this, mxContext
, xCommandBarControl
) );
102 ScVbaMenus::getServiceImplName()
104 return OUString("ScVbaMenus");
107 uno::Sequence
<OUString
>
108 ScVbaMenus::getServiceNames()
110 static uno::Sequence
< OUString
> aServiceNames
;
111 if ( aServiceNames
.getLength() == 0 )
113 aServiceNames
.realloc( 1 );
114 aServiceNames
[ 0 ] = "ooo.vba.excel.Menus";
116 return aServiceNames
;
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */