1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
9 * last change: $Author$ $Date$
11 * The Contents of this file are made available subject to
12 * the terms of GNU Lesser General Public License Version 2.1.
15 * GNU Lesser General Public License Version 2.1
16 * =============================================
17 * Copyright 2005 by Sun Microsystems, Inc.
18 * 901 San Antonio Road, Palo Alto, CA 94303, USA
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License version 2.1, as published by the Free Software Foundation.
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * Lesser General Public License for more details.
29 * You should have received a copy of the GNU Lesser General Public
30 * License along with this library; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
34 ************************************************************************/
35 #include "vbamenus.hxx"
36 #include "vbamenu.hxx"
37 #include <ooo/vba/office/MsoControlType.hpp>
39 using namespace com::sun::star
;
40 using namespace ooo::vba
;
43 typedef ::cppu::WeakImplHelper1
< container::XEnumeration
> MenuEnumeration_BASE
;
45 class MenuEnumeration
: public MenuEnumeration_BASE
47 uno::Reference
< XHelperInterface
> m_xParent
;
48 uno::Reference
< uno::XComponentContext
> m_xContext
;
49 uno::Reference
< container::XEnumeration
> m_xEnumeration
;
51 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
)
54 virtual sal_Bool SAL_CALL
hasMoreElements() throw ( uno::RuntimeException
)
56 return m_xEnumeration
->hasMoreElements();
58 virtual uno::Any SAL_CALL
nextElement() throw ( container::NoSuchElementException
, lang::WrappedTargetException
, uno::RuntimeException
)
60 // FIXME: should be add menu
61 if( hasMoreElements() )
63 uno::Reference
< XCommandBarControl
> xCommandBarControl( m_xEnumeration
->nextElement(), uno::UNO_QUERY_THROW
);
64 if( xCommandBarControl
->getType() == office::MsoControlType::msoControlPopup
)
66 uno::Reference
< excel::XMenu
> xMenu( new ScVbaMenu( m_xParent
, m_xContext
, xCommandBarControl
) );
67 return uno::makeAny( xMenu
);
72 throw container::NoSuchElementException();
77 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
)
83 ScVbaMenus::getElementType() throw ( uno::RuntimeException
)
85 return excel::XMenu::static_type( 0 );
88 uno::Reference
< container::XEnumeration
>
89 ScVbaMenus::createEnumeration() throw ( uno::RuntimeException
)
91 uno::Reference
< container::XEnumerationAccess
> xEnumAccess( m_xCommandBarControls
, uno::UNO_QUERY_THROW
);
92 return uno::Reference
< container::XEnumeration
>( new MenuEnumeration( this, mxContext
, xEnumAccess
->createEnumeration() ) );
96 ScVbaMenus::createCollectionObject( const uno::Any
& aSource
)
103 ScVbaMenus::getCount() throw(css::uno::RuntimeException
)
105 // FIXME: should check if it is a popup menu
106 return m_xCommandBarControls
->getCount();
109 // ScVbaCollectionBaseImpl
111 ScVbaMenus::Item( const uno::Any
& aIndex
, const uno::Any
& /*aIndex2*/ ) throw( uno::RuntimeException
)
113 uno::Reference
< XCommandBarControl
> xCommandBarControl( m_xCommandBarControls
->Item( aIndex
, uno::Any() ), uno::UNO_QUERY_THROW
);
114 if( xCommandBarControl
->getType() != office::MsoControlType::msoControlPopup
)
115 throw uno::RuntimeException();
116 return uno::makeAny( uno::Reference
< excel::XMenu
> ( new ScVbaMenu( this, mxContext
, xCommandBarControl
) ) );
119 uno::Reference
< excel::XMenu
> SAL_CALL
ScVbaMenus::Add( const rtl::OUString
& Caption
, const css::uno::Any
& Before
, const css::uno::Any
& Restore
) throw (css::script::BasicErrorException
, css::uno::RuntimeException
)
121 sal_Int32 nType
= office::MsoControlType::msoControlPopup
;
122 uno::Reference
< XCommandBarControl
> xCommandBarControl
= m_xCommandBarControls
->Add( uno::makeAny( nType
), uno::Any(), uno::Any(), Before
, Restore
);
123 xCommandBarControl
->setCaption( Caption
);
124 return uno::Reference
< excel::XMenu
>( new ScVbaMenu( this, mxContext
, xCommandBarControl
) );
129 ScVbaMenus::getServiceImplName()
131 static rtl::OUString
sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaMenus") );
134 uno::Sequence
<rtl::OUString
>
135 ScVbaMenus::getServiceNames()
137 static uno::Sequence
< rtl::OUString
> aServiceNames
;
138 if ( aServiceNames
.getLength() == 0 )
140 aServiceNames
.realloc( 1 );
141 aServiceNames
[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Menus" ) );
143 return aServiceNames
;