Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 : : *
5 : : * The contents of this file are subject to the Mozilla Public License Version
6 : : * 1.1 (the "License"); you may not use this file except in compliance with
7 : : * the License. You may obtain a copy of the License at
8 : : * http://www.mozilla.org/MPL/
9 : : *
10 : : * Software distributed under the License is distributed on an "AS IS" basis,
11 : : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : : * for the specific language governing rights and limitations under the
13 : : * License.
14 : : *
15 : : * The Initial Developer of the Original Code is
16 : : * Novell Inc.
17 : : * Portions created by the Initial Developer are Copyright (C) 2010 the
18 : : * Initial Developer. All Rights Reserved.
19 : : *
20 : : * Contributor(s): Pei Feng Lin <pflin@novell.com>
21 : : *
22 : : * Alternatively, the contents of this file may be used under the terms of
23 : : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
24 : : * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
25 : : * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
26 : : * instead of those above.
27 : : */
28 : : #include "vbamenus.hxx"
29 : : #include "vbamenu.hxx"
30 : : #include <ooo/vba/office/MsoControlType.hpp>
31 : :
32 : : using namespace com::sun::star;
33 : : using namespace ooo::vba;
34 : :
35 : :
36 : : typedef ::cppu::WeakImplHelper1< container::XEnumeration > MenuEnumeration_BASE;
37 : :
38 [ # # ]: 0 : class MenuEnumeration : public MenuEnumeration_BASE
39 : : {
40 : : uno::Reference< XHelperInterface > m_xParent;
41 : : uno::Reference< uno::XComponentContext > m_xContext;
42 : : uno::Reference< container::XEnumeration > m_xEnumeration;
43 : : public:
44 : 0 : 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 )
45 : : {
46 : 0 : }
47 : 0 : virtual sal_Bool SAL_CALL hasMoreElements() throw ( uno::RuntimeException )
48 : : {
49 : 0 : return m_xEnumeration->hasMoreElements();
50 : : }
51 : 0 : virtual uno::Any SAL_CALL nextElement() throw ( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException )
52 : : {
53 : : // FIXME: should be add menu
54 [ # # ]: 0 : if( hasMoreElements() )
55 : : {
56 [ # # ][ # # ]: 0 : uno::Reference< XCommandBarControl > xCommandBarControl( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW );
[ # # ]
57 [ # # ][ # # ]: 0 : if( xCommandBarControl->getType() == office::MsoControlType::msoControlPopup )
[ # # ]
58 : : {
59 [ # # ][ # # ]: 0 : uno::Reference< excel::XMenu > xMenu( new ScVbaMenu( m_xParent, m_xContext, xCommandBarControl ) );
[ # # ]
60 [ # # ]: 0 : return uno::makeAny( xMenu );
61 : : }
62 [ # # ][ # # ]: 0 : nextElement();
63 : : }
64 : : else
65 [ # # ]: 0 : throw container::NoSuchElementException();
66 : 0 : return uno::Any();
67 : : }
68 : : };
69 : :
70 [ # # ]: 0 : 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 )
71 : : {
72 : 0 : }
73 : :
74 : : // XEnumerationAccess
75 : : uno::Type SAL_CALL
76 : 0 : ScVbaMenus::getElementType() throw ( uno::RuntimeException )
77 : : {
78 : 0 : return excel::XMenu::static_type( 0 );
79 : : }
80 : :
81 : : uno::Reference< container::XEnumeration >
82 : 0 : ScVbaMenus::createEnumeration() throw ( uno::RuntimeException )
83 : : {
84 [ # # ]: 0 : uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xCommandBarControls, uno::UNO_QUERY_THROW );
85 [ # # ][ # # ]: 0 : return uno::Reference< container::XEnumeration >( new MenuEnumeration( this, mxContext, xEnumAccess->createEnumeration() ) );
[ # # ][ # # ]
[ # # ][ # # ]
86 : : }
87 : :
88 : : uno::Any
89 : 0 : ScVbaMenus::createCollectionObject( const uno::Any& aSource )
90 : : {
91 : : // make no sense
92 : 0 : return aSource;
93 : : }
94 : :
95 : : sal_Int32 SAL_CALL
96 : 0 : ScVbaMenus::getCount() throw(css::uno::RuntimeException)
97 : : {
98 : : // FIXME: should check if it is a popup menu
99 : 0 : return m_xCommandBarControls->getCount();
100 : : }
101 : :
102 : : // ScVbaCollectionBaseImpl
103 : : uno::Any SAL_CALL
104 : 0 : ScVbaMenus::Item( const uno::Any& aIndex, const uno::Any& /*aIndex2*/ ) throw( uno::RuntimeException )
105 : : {
106 [ # # ][ # # ]: 0 : uno::Reference< XCommandBarControl > xCommandBarControl( m_xCommandBarControls->Item( aIndex, uno::Any() ), uno::UNO_QUERY_THROW );
[ # # ]
107 [ # # ][ # # ]: 0 : if( xCommandBarControl->getType() != office::MsoControlType::msoControlPopup )
[ # # ]
108 [ # # ]: 0 : throw uno::RuntimeException();
109 [ # # ][ # # ]: 0 : return uno::makeAny( uno::Reference< excel::XMenu > ( new ScVbaMenu( this, mxContext, xCommandBarControl ) ) );
[ # # ][ # # ]
[ # # ]
110 : : }
111 : :
112 : 0 : 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)
113 : : {
114 : 0 : sal_Int32 nType = office::MsoControlType::msoControlPopup;
115 [ # # ][ # # ]: 0 : uno::Reference< XCommandBarControl > xCommandBarControl = m_xCommandBarControls->Add( uno::makeAny( nType ), uno::Any(), uno::Any(), Before, Restore );
[ # # ]
116 [ # # ][ # # ]: 0 : xCommandBarControl->setCaption( Caption );
117 [ # # ][ # # ]: 0 : return uno::Reference< excel::XMenu >( new ScVbaMenu( this, mxContext, xCommandBarControl ) );
[ # # ][ # # ]
118 : : }
119 : :
120 : : // XHelperInterface
121 : : rtl::OUString
122 : 0 : ScVbaMenus::getServiceImplName()
123 : : {
124 : 0 : return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ScVbaMenus"));
125 : : }
126 : :
127 : : uno::Sequence<rtl::OUString>
128 : 0 : ScVbaMenus::getServiceNames()
129 : : {
130 [ # # ][ # # ]: 0 : static uno::Sequence< rtl::OUString > aServiceNames;
[ # # ][ # # ]
131 [ # # ]: 0 : if ( aServiceNames.getLength() == 0 )
132 : : {
133 : 0 : aServiceNames.realloc( 1 );
134 [ # # ]: 0 : aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Menus" ) );
135 : : }
136 : 0 : return aServiceNames;
137 : : }
138 : :
139 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|