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 "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
;
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
);
68 throw container::NoSuchElementException();
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()
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() ) );
96 ScVbaMenuBars::createCollectionObject( const uno::Any
& aSource
)
103 ScVbaMenuBars::getCount() throw(css::uno::RuntimeException
)
105 return m_xCommandBars
->getCount();
108 // ScVbaCollectionBaseImpl
110 ScVbaMenuBars::Item( const uno::Any
& aIndex
, const uno::Any
& /*aIndex2*/ ) throw( uno::RuntimeException
)
112 sal_Int16 nIndex
= 0;
114 if( nIndex
== excel::XlSheetType::xlWorksheet
)
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
>() );
130 ScVbaMenuBars::getServiceImplName()
132 static rtl::OUString
sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaMenuBars") );
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
;