merge the formfield patch from ooo-build
[ooovba.git] / sc / source / ui / vba / vbamenubars.cxx
bloba5f9e9bc0fdc0cd5e5cf8eb57dddeeb892031071
1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile$
7 * $Revision$
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,
32 * MA 02111-1307 USA
34 ************************************************************************/
35 #include "vbamenubars.hxx"
36 #include "vbamenubar.hxx"
37 #include <ooo/vba/excel/XlSheetType.hpp>
39 using namespace com::sun::star;
40 using namespace ooo::vba;
43 typedef ::cppu::WeakImplHelper1< container::XEnumeration > MenuBarEnumeration_BASE;
45 class MenuBarEnumeration : public MenuBarEnumeration_BASE
47 uno::Reference< XHelperInterface > m_xParent;
48 uno::Reference< uno::XComponentContext > m_xContext;
49 uno::Reference< container::XEnumeration > m_xEnumeration;
50 public:
51 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 )
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 menubar
61 if( hasMoreElements() )
63 uno::Reference< XCommandBar > xCommandBar( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW );
64 uno::Reference< excel::XMenuBar > xMenuBar( new ScVbaMenuBar( m_xParent, m_xContext, xCommandBar ) );
65 return uno::makeAny( xMenuBar );
67 else
68 throw container::NoSuchElementException();
69 return uno::Any();
73 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 )
77 ScVbaMenuBars::~ScVbaMenuBars()
81 // XEnumerationAccess
82 uno::Type SAL_CALL
83 ScVbaMenuBars::getElementType() throw ( uno::RuntimeException )
85 return excel::XMenuBar::static_type( 0 );
88 uno::Reference< container::XEnumeration >
89 ScVbaMenuBars::createEnumeration() throw ( uno::RuntimeException )
91 uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xCommandBars, uno::UNO_QUERY_THROW );
92 return uno::Reference< container::XEnumeration >( new MenuBarEnumeration( this, mxContext, xEnumAccess->createEnumeration() ) );
95 uno::Any
96 ScVbaMenuBars::createCollectionObject( const uno::Any& aSource )
98 // make no sense
99 return aSource;
102 sal_Int32 SAL_CALL
103 ScVbaMenuBars::getCount() throw(css::uno::RuntimeException)
105 return m_xCommandBars->getCount();
108 // ScVbaCollectionBaseImpl
109 uno::Any SAL_CALL
110 ScVbaMenuBars::Item( const uno::Any& aIndex, const uno::Any& /*aIndex2*/ ) throw( uno::RuntimeException )
112 sal_Int16 nIndex = 0;
113 aIndex >>= nIndex;
114 if( nIndex == excel::XlSheetType::xlWorksheet )
116 uno::Any aSource;
117 aSource <<= rtl::OUString::createFromAscii( "Worksheet Menu Bar" );
118 uno::Reference< XCommandBar > xCommandBar( m_xCommandBars->Item( aSource, uno::Any() ), uno::UNO_QUERY_THROW );
119 uno::Reference< excel::XMenuBar > xMenuBar( new ScVbaMenuBar( this, mxContext, xCommandBar ) );
120 return uno::makeAny( xMenuBar );
123 throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() );
125 return uno::Any();
128 // XHelperInterface
129 rtl::OUString&
130 ScVbaMenuBars::getServiceImplName()
132 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaMenuBars") );
133 return sImplName;
135 uno::Sequence<rtl::OUString>
136 ScVbaMenuBars::getServiceNames()
138 static uno::Sequence< rtl::OUString > aServiceNames;
139 if ( aServiceNames.getLength() == 0 )
141 aServiceNames.realloc( 1 );
142 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.MenuBars" ) );
144 return aServiceNames;