Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : : #include "vbacommandbarcontrols.hxx"
20 : : #include "vbacommandbarcontrol.hxx"
21 : :
22 : : using namespace com::sun::star;
23 : : using namespace ooo::vba;
24 : :
25 : : typedef ::cppu::WeakImplHelper1< container::XEnumeration > CommandBarControlEnumeration_BASE;
26 [ # # ]: 0 : class CommandBarControlEnumeration : public CommandBarControlEnumeration_BASE
27 : : {
28 : : //uno::Reference< uno::XComponentContext > m_xContext;
29 : : CommandBarControls_BASE* m_pCommandBarControls;
30 : : sal_Int32 m_nCurrentPosition;
31 : : public:
32 : 0 : CommandBarControlEnumeration( CommandBarControls_BASE* pCommandBarControls ) : m_pCommandBarControls( pCommandBarControls ), m_nCurrentPosition( 0 ) {}
33 : 0 : virtual sal_Bool SAL_CALL hasMoreElements() throw ( uno::RuntimeException )
34 : : {
35 [ # # ]: 0 : if( m_nCurrentPosition < m_pCommandBarControls->getCount() )
36 : 0 : return sal_True;
37 : 0 : return sal_False;
38 : : }
39 : 0 : virtual uno::Any SAL_CALL nextElement() throw ( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException )
40 : : {
41 [ # # ]: 0 : if( hasMoreElements() )
42 : : {
43 [ # # ][ # # ]: 0 : return m_pCommandBarControls->createCollectionObject( uno::makeAny( m_nCurrentPosition++ ) );
44 : : }
45 : : else
46 [ # # ]: 0 : throw container::NoSuchElementException();
47 : : }
48 : : };
49 : :
50 [ # # ]: 0 : ScVbaCommandBarControls::ScVbaCommandBarControls( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XIndexAccess>& xIndexAccess, VbaCommandBarHelperRef pHelper, const uno::Reference< container::XIndexAccess>& xBarSettings, const rtl::OUString& sResourceUrl ) throw (uno::RuntimeException) : CommandBarControls_BASE( xParent, xContext, xIndexAccess ), pCBarHelper( pHelper ), m_xBarSettings( xBarSettings ), m_sResourceUrl( sResourceUrl )
51 : : {
52 [ # # ]: 0 : m_bIsMenu = sResourceUrl.equalsAscii( ITEM_MENUBAR_URL ) ? sal_True : sal_False;
53 : 0 : }
54 : :
55 : 0 : uno::Sequence< beans::PropertyValue > ScVbaCommandBarControls::CreateMenuItemData( const rtl::OUString& sCommandURL,
56 : : const rtl::OUString& sHelpURL,
57 : : const rtl::OUString& sLabel,
58 : : sal_uInt16 nType,
59 : : const uno::Any& aSubMenu,
60 : : sal_Bool isVisible,
61 : : sal_Bool isEnabled )
62 : : {
63 : 0 : uno::Sequence< beans::PropertyValue > aProps(7);
64 : :
65 [ # # ]: 0 : aProps[0].Name = rtl::OUString( ITEM_DESCRIPTOR_COMMANDURL );
66 [ # # ][ # # ]: 0 : aProps[0].Value <<= sCommandURL;
67 [ # # ]: 0 : aProps[1].Name = rtl::OUString( ITEM_DESCRIPTOR_HELPURL );
68 [ # # ][ # # ]: 0 : aProps[1].Value <<= sHelpURL;
69 [ # # ]: 0 : aProps[2].Name = rtl::OUString( ITEM_DESCRIPTOR_LABEL );
70 [ # # ][ # # ]: 0 : aProps[2].Value <<= sLabel;
71 [ # # ]: 0 : aProps[3].Name = rtl::OUString( ITEM_DESCRIPTOR_TYPE );
72 [ # # ][ # # ]: 0 : aProps[3].Value <<= nType;
73 [ # # ]: 0 : aProps[4].Name = rtl::OUString( ITEM_DESCRIPTOR_CONTAINER );
74 [ # # ]: 0 : aProps[4].Value = aSubMenu;
75 [ # # ]: 0 : aProps[5].Name = rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_ISVISIBLE );
76 [ # # ][ # # ]: 0 : aProps[5].Value <<= isVisible;
77 [ # # ]: 0 : aProps[6].Name = rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_ENABLED );
78 [ # # ][ # # ]: 0 : aProps[6].Value <<= isEnabled;
79 : :
80 : 0 : return aProps;
81 : : }
82 : :
83 : 0 : uno::Sequence< beans::PropertyValue > ScVbaCommandBarControls::CreateToolbarItemData( const rtl::OUString& sCommandURL, const rtl::OUString& sHelpURL, const rtl::OUString& sLabel, sal_uInt16 nType, const uno::Any& aSubMenu, sal_Bool isVisible, sal_Int32 nStyle )
84 : : {
85 : 0 : uno::Sequence< beans::PropertyValue > aProps(7);
86 : :
87 [ # # ]: 0 : aProps[0].Name = rtl::OUString( ITEM_DESCRIPTOR_COMMANDURL );
88 [ # # ][ # # ]: 0 : aProps[0].Value <<= sCommandURL;
89 [ # # ]: 0 : aProps[1].Name = rtl::OUString( ITEM_DESCRIPTOR_HELPURL );
90 [ # # ][ # # ]: 0 : aProps[1].Value <<= sHelpURL;
91 [ # # ]: 0 : aProps[2].Name = rtl::OUString( ITEM_DESCRIPTOR_LABEL );
92 [ # # ][ # # ]: 0 : aProps[2].Value <<= sLabel;
93 [ # # ]: 0 : aProps[3].Name = rtl::OUString( ITEM_DESCRIPTOR_TYPE );
94 [ # # ][ # # ]: 0 : aProps[3].Value <<= nType;
95 [ # # ]: 0 : aProps[4].Name = rtl::OUString( ITEM_DESCRIPTOR_CONTAINER );
96 [ # # ]: 0 : aProps[4].Value = aSubMenu;
97 [ # # ]: 0 : aProps[5].Name = rtl::OUString( ITEM_DESCRIPTOR_ISVISIBLE );
98 [ # # ][ # # ]: 0 : aProps[5].Value <<= isVisible;
99 [ # # ]: 0 : aProps[6].Name = rtl::OUString( ITEM_DESCRIPTOR_STYLE );
100 [ # # ][ # # ]: 0 : aProps[6].Value <<= nStyle;
101 : :
102 : 0 : return aProps;
103 : : }
104 : :
105 : : // XEnumerationAccess
106 : : uno::Type SAL_CALL
107 : 0 : ScVbaCommandBarControls::getElementType() throw ( uno::RuntimeException )
108 : : {
109 : 0 : return XCommandBarControl::static_type( 0 );
110 : : }
111 : :
112 : : uno::Reference< container::XEnumeration >
113 : 0 : ScVbaCommandBarControls::createEnumeration() throw ( uno::RuntimeException )
114 : : {
115 [ # # ][ # # ]: 0 : return uno::Reference< container::XEnumeration >( new CommandBarControlEnumeration( this ) );
116 : : }
117 : :
118 : : uno::Any
119 : 0 : ScVbaCommandBarControls::createCollectionObject( const uno::Any& aSource )
120 : : {
121 : 0 : sal_Int32 nPosition = -1;
122 : 0 : aSource >>= nPosition;
123 [ # # ]: 0 : uno::Sequence< beans::PropertyValue > aProps;
124 [ # # ][ # # ]: 0 : m_xIndexAccess->getByIndex( nPosition ) >>= aProps;
[ # # ]
125 : 0 : uno::Reference< container::XIndexAccess > xSubMenu;
126 [ # # ][ # # ]: 0 : getPropertyValue( aProps, rtl::OUString( ITEM_DESCRIPTOR_CONTAINER ) ) >>= xSubMenu;
127 : 0 : ScVbaCommandBarControl* pNewCommandBarControl = NULL;
128 [ # # ]: 0 : if( xSubMenu.is() )
129 [ # # ][ # # ]: 0 : pNewCommandBarControl = new ScVbaCommandBarPopup( this, mxContext, m_xIndexAccess, pCBarHelper, m_xBarSettings, m_sResourceUrl, nPosition, sal_True );
[ # # ][ # # ]
130 : : else
131 [ # # ][ # # ]: 0 : pNewCommandBarControl = new ScVbaCommandBarButton( this, mxContext, m_xIndexAccess, pCBarHelper, m_xBarSettings, m_sResourceUrl, nPosition, sal_True );
[ # # ][ # # ]
132 : :
133 [ # # ][ # # ]: 0 : return uno::makeAny( uno::Reference< XCommandBarControl > ( pNewCommandBarControl ) );
[ # # ][ # # ]
134 : : }
135 : :
136 : : // Methods
137 : : uno::Any SAL_CALL
138 : 0 : ScVbaCommandBarControls::Item( const uno::Any& aIndex, const uno::Any& /*aIndex*/ ) throw (uno::RuntimeException)
139 : : {
140 : 0 : sal_Int32 nPosition = -1;
141 [ # # ]: 0 : if( aIndex.getValueTypeClass() == uno::TypeClass_STRING )
142 : : {
143 : 0 : rtl::OUString sName;
144 : 0 : aIndex >>= sName;
145 [ # # ]: 0 : nPosition = VbaCommandBarHelper::findControlByName( m_xIndexAccess, sName, m_bIsMenu );
146 : : }
147 : : else
148 : : {
149 : 0 : aIndex >>= nPosition;
150 : : }
151 : :
152 [ # # ][ # # ]: 0 : if( nPosition < 0 || nPosition >= getCount() )
[ # # ][ # # ]
153 : : {
154 [ # # ]: 0 : throw uno::RuntimeException();
155 : : }
156 : :
157 [ # # ][ # # ]: 0 : return createCollectionObject( uno::makeAny( nPosition ) );
158 : : }
159 : :
160 : : uno::Reference< XCommandBarControl > SAL_CALL
161 : 0 : ScVbaCommandBarControls::Add( const uno::Any& Type, const uno::Any& Id, const uno::Any& Parameter, const uno::Any& Before, const uno::Any& Temporary ) throw (script::BasicErrorException, uno::RuntimeException)
162 : : {
163 : : // Parameter is not supported
164 : : // the following name needs to be individually created;
165 : 0 : rtl::OUString sLabel("Custom");
166 : 0 : rtl::OUString sCommandUrl(rtl::OUString( CUSTOM_MENU_STR) + sLabel);
167 : 0 : sal_Int32 nType = office::MsoControlType::msoControlButton;
168 : 0 : sal_Int32 nPosition = 0;
169 : 0 : sal_Bool bTemporary = sal_True;
170 : :
171 [ # # ]: 0 : if( Type.hasValue() )
172 : : {
173 : 0 : Type >>= nType;
174 : : }
175 : :
176 [ # # ][ # # ]: 0 : if( nType != office::MsoControlType::msoControlButton &&
177 : : nType != office::MsoControlType::msoControlPopup )
178 [ # # ]: 0 : throw uno::RuntimeException( rtl::OUString( "Not implemented" ), uno::Reference< uno::XInterface >() );
179 : :
180 [ # # ][ # # ]: 0 : if( Id.hasValue() || Parameter.hasValue( ) )
[ # # ]
181 : : {
182 [ # # ]: 0 : throw uno::RuntimeException( rtl::OUString( "Not implemented" ), uno::Reference< uno::XInterface >() );
183 : : }
184 : :
185 [ # # ]: 0 : if( Before.hasValue() )
186 : 0 : Before >>= nPosition;
187 : : else
188 [ # # ][ # # ]: 0 : nPosition = m_xIndexAccess->getCount();
189 : :
190 [ # # ]: 0 : if( Temporary.hasValue() )
191 : 0 : Temporary >>= bTemporary;
192 : :
193 : 0 : uno::Any aSubMenu;
194 [ # # ]: 0 : if( nType == office::MsoControlType::msoControlPopup )
195 : : {
196 : : // it is a Popmenu
197 [ # # ]: 0 : uno::Reference< lang::XSingleComponentFactory > xSCF( m_xBarSettings, uno::UNO_QUERY_THROW );
198 [ # # ][ # # ]: 0 : aSubMenu <<= xSCF->createInstanceWithContext( mxContext );
[ # # ]
199 : : }
200 : :
201 : : // create control
202 [ # # ]: 0 : uno::Sequence< beans::PropertyValue > aProps;
203 : 0 : rtl::OUString sHelpUrl;
204 : 0 : sal_uInt16 nItemType = 0;
205 [ # # ]: 0 : if( IsMenu() )
206 : : {
207 [ # # ][ # # ]: 0 : aProps = CreateMenuItemData( sCommandUrl, sHelpUrl, sLabel, nItemType, aSubMenu, true, true );
[ # # ]
208 : : }
209 : : else
210 : : {
211 : 0 : sal_Bool isVisible = sal_True;
212 : 0 : sal_Int32 nStyle = 0;
213 [ # # ][ # # ]: 0 : aProps = CreateToolbarItemData( sCommandUrl, sHelpUrl, sLabel, nItemType, aSubMenu, isVisible, nStyle );
[ # # ]
214 : : }
215 : :
216 : :
217 [ # # ]: 0 : uno::Reference< container::XIndexContainer > xIndexContainer( m_xIndexAccess, uno::UNO_QUERY_THROW );
218 [ # # ][ # # ]: 0 : xIndexContainer->insertByIndex( nPosition, uno::makeAny( aProps ) );
[ # # ]
219 : :
220 [ # # ]: 0 : pCBarHelper->ApplyChange( m_sResourceUrl, m_xBarSettings );
221 : :
222 : 0 : ScVbaCommandBarControl* pNewCommandBarControl = NULL;
223 [ # # ]: 0 : if( nType == office::MsoControlType::msoControlPopup )
224 [ # # ][ # # ]: 0 : pNewCommandBarControl = new ScVbaCommandBarPopup( this, mxContext, m_xIndexAccess, pCBarHelper, m_xBarSettings, m_sResourceUrl, nPosition, bTemporary );
[ # # ][ # # ]
225 : : else
226 [ # # ][ # # ]: 0 : pNewCommandBarControl = new ScVbaCommandBarButton( this, mxContext, m_xIndexAccess, pCBarHelper, m_xBarSettings, m_sResourceUrl, nPosition, bTemporary );
[ # # ][ # # ]
227 : :
228 [ # # ][ # # ]: 0 : return uno::Reference< XCommandBarControl >( pNewCommandBarControl );
[ # # ]
229 : : }
230 : :
231 : : // XHelperInterface
232 : : rtl::OUString
233 : 0 : ScVbaCommandBarControls::getServiceImplName()
234 : : {
235 : 0 : return rtl::OUString("ScVbaCommandBarControls");
236 : : }
237 : :
238 : : uno::Sequence<rtl::OUString>
239 : 0 : ScVbaCommandBarControls::getServiceNames()
240 : : {
241 [ # # ][ # # ]: 0 : static uno::Sequence< rtl::OUString > aServiceNames;
[ # # ][ # # ]
242 [ # # ]: 0 : if ( aServiceNames.getLength() == 0 )
243 : : {
244 : 0 : aServiceNames.realloc( 1 );
245 [ # # ]: 0 : aServiceNames[ 0 ] = rtl::OUString( "ooo.vba.CommandBarControls" );
246 : : }
247 : 0 : return aServiceNames;
248 : : }
249 : :
250 : : // ============================================================================
251 : :
252 [ # # ]: 0 : class VbaDummyIndexAccess : public ::cppu::WeakImplHelper1< container::XIndexAccess >
253 : : {
254 : : public:
255 : 0 : inline VbaDummyIndexAccess() {}
256 : : // XIndexAccess
257 : 0 : virtual ::sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException)
258 : 0 : { return 0; }
259 : 0 : virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 /*Index*/ ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
260 [ # # ]: 0 : { throw lang::IndexOutOfBoundsException(); }
261 : : // XElementAccess
262 : 0 : virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException)
263 : 0 : { return XCommandBarControl::static_type( 0 ); }
264 : 0 : virtual ::sal_Bool SAL_CALL hasElements( ) throw (::com::sun::star::uno::RuntimeException)
265 : 0 : { return false; }
266 : : };
267 : :
268 : : // ----------------------------------------------------------------------------
269 : :
270 : 0 : VbaDummyCommandBarControls::VbaDummyCommandBarControls(
271 : : const uno::Reference< XHelperInterface >& xParent,
272 : : const uno::Reference< uno::XComponentContext >& xContext ) throw (uno::RuntimeException) :
273 [ # # ][ # # ]: 0 : CommandBarControls_BASE( xParent, xContext, new VbaDummyIndexAccess )
[ # # ]
274 : : {
275 : 0 : }
276 : :
277 : : // XEnumerationAccess
278 : 0 : uno::Type SAL_CALL VbaDummyCommandBarControls::getElementType() throw ( uno::RuntimeException )
279 : : {
280 : 0 : return XCommandBarControl::static_type( 0 );
281 : : }
282 : :
283 : 0 : uno::Reference< container::XEnumeration > VbaDummyCommandBarControls::createEnumeration() throw ( uno::RuntimeException )
284 : : {
285 [ # # ][ # # ]: 0 : return uno::Reference< container::XEnumeration >( new CommandBarControlEnumeration( this ) );
286 : : }
287 : :
288 : 0 : uno::Any VbaDummyCommandBarControls::createCollectionObject( const uno::Any& /*aSource*/ )
289 : : {
290 [ # # ]: 0 : return uno::Any( uno::Reference< XCommandBarControl >() );
291 : : }
292 : :
293 : : // Methods
294 : 0 : uno::Any SAL_CALL VbaDummyCommandBarControls::Item( const uno::Any& /*aIndex*/, const uno::Any& /*aIndex*/ ) throw (uno::RuntimeException)
295 : : {
296 [ # # ]: 0 : return uno::Any( uno::Reference< XCommandBarControl >() );
297 : : }
298 : :
299 : 0 : uno::Reference< XCommandBarControl > SAL_CALL VbaDummyCommandBarControls::Add(
300 : : const uno::Any& /*Type*/, const uno::Any& /*Id*/, const uno::Any& /*Parameter*/, const uno::Any& /*Before*/, const uno::Any& /*Temporary*/ ) throw (script::BasicErrorException, uno::RuntimeException)
301 : : {
302 : 0 : return uno::Reference< XCommandBarControl >();
303 : : }
304 : :
305 : : // XHelperInterface
306 : 0 : rtl::OUString VbaDummyCommandBarControls::getServiceImplName()
307 : : {
308 : 0 : return rtl::OUString("VbaDummyCommandBarControls");
309 : : }
310 : :
311 : 0 : uno::Sequence<rtl::OUString> VbaDummyCommandBarControls::getServiceNames()
312 : : {
313 [ # # ][ # # ]: 0 : static uno::Sequence< rtl::OUString > aServiceNames;
[ # # ][ # # ]
314 [ # # ]: 0 : if ( aServiceNames.getLength() == 0 )
315 : : {
316 : 0 : aServiceNames.realloc( 1 );
317 [ # # ]: 0 : aServiceNames[ 0 ] = rtl::OUString( "ooo.vba.CommandBarControls" );
318 : : }
319 : 0 : return aServiceNames;
320 : : }
321 : :
322 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|