GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / sc / source / ui / vba / vbamenus.cxx
blob6fbe213ec82d701f00b834b27f273ee75ef4cff2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
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;
17 typedef ::cppu::WeakImplHelper1< container::XEnumeration > MenuEnumeration_BASE;
19 class MenuEnumeration : public MenuEnumeration_BASE
21 uno::Reference< XHelperInterface > m_xParent;
22 uno::Reference< uno::XComponentContext > m_xContext;
23 uno::Reference< container::XEnumeration > m_xEnumeration;
24 public:
25 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 )
28 virtual sal_Bool SAL_CALL hasMoreElements() throw ( uno::RuntimeException )
30 return m_xEnumeration->hasMoreElements();
32 virtual uno::Any SAL_CALL nextElement() throw ( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException )
34 // FIXME: should be add menu
35 if( hasMoreElements() )
37 uno::Reference< XCommandBarControl > xCommandBarControl( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW );
38 if( xCommandBarControl->getType() == office::MsoControlType::msoControlPopup )
40 uno::Reference< excel::XMenu > xMenu( new ScVbaMenu( m_xParent, m_xContext, xCommandBarControl ) );
41 return uno::makeAny( xMenu );
43 nextElement();
45 else
46 throw container::NoSuchElementException();
47 return uno::Any();
51 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 )
55 // XEnumerationAccess
56 uno::Type SAL_CALL
57 ScVbaMenus::getElementType() throw ( uno::RuntimeException )
59 return excel::XMenu::static_type( 0 );
62 uno::Reference< container::XEnumeration >
63 ScVbaMenus::createEnumeration() throw ( uno::RuntimeException )
65 uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xCommandBarControls, uno::UNO_QUERY_THROW );
66 return uno::Reference< container::XEnumeration >( new MenuEnumeration( this, mxContext, xEnumAccess->createEnumeration() ) );
69 uno::Any
70 ScVbaMenus::createCollectionObject( const uno::Any& aSource )
72 // make no sense
73 return aSource;
76 sal_Int32 SAL_CALL
77 ScVbaMenus::getCount() throw(css::uno::RuntimeException)
79 // FIXME: should check if it is a popup menu
80 return m_xCommandBarControls->getCount();
83 // ScVbaCollectionBaseImpl
84 uno::Any SAL_CALL
85 ScVbaMenus::Item( const uno::Any& aIndex, const uno::Any& /*aIndex2*/ ) throw( uno::RuntimeException )
87 uno::Reference< XCommandBarControl > xCommandBarControl( m_xCommandBarControls->Item( aIndex, uno::Any() ), uno::UNO_QUERY_THROW );
88 if( xCommandBarControl->getType() != office::MsoControlType::msoControlPopup )
89 throw uno::RuntimeException();
90 return uno::makeAny( uno::Reference< excel::XMenu > ( new ScVbaMenu( this, mxContext, xCommandBarControl ) ) );
93 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)
95 sal_Int32 nType = office::MsoControlType::msoControlPopup;
96 uno::Reference< XCommandBarControl > xCommandBarControl = m_xCommandBarControls->Add( uno::makeAny( nType ), uno::Any(), uno::Any(), Before, Restore );
97 xCommandBarControl->setCaption( Caption );
98 return uno::Reference< excel::XMenu >( new ScVbaMenu( this, mxContext, xCommandBarControl ) );
101 // XHelperInterface
102 OUString
103 ScVbaMenus::getServiceImplName()
105 return OUString("ScVbaMenus");
108 uno::Sequence<OUString>
109 ScVbaMenus::getServiceNames()
111 static uno::Sequence< OUString > aServiceNames;
112 if ( aServiceNames.getLength() == 0 )
114 aServiceNames.realloc( 1 );
115 aServiceNames[ 0 ] = "ooo.vba.excel.Menus";
117 return aServiceNames;
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */