Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "vbasheetobject.hxx"
30 : : #include <com/sun/star/awt/TextAlign.hpp>
31 : : #include <com/sun/star/container/XIndexContainer.hpp>
32 : : #include <com/sun/star/drawing/XControlShape.hpp>
33 : : #include <com/sun/star/script/ScriptEventDescriptor.hpp>
34 : : #include <com/sun/star/script/XEventAttacherManager.hpp>
35 : : #include <com/sun/star/style/VerticalAlignment.hpp>
36 : : #include <ooo/vba/excel/Constants.hpp>
37 : : #include <ooo/vba/excel/XlOrientation.hpp>
38 : : #include <ooo/vba/excel/XlPlacement.hpp>
39 : : #include <rtl/ustrbuf.hxx>
40 : : #include <filter/msfilter/msvbahelper.hxx>
41 : : #include <oox/helper/helper.hxx>
42 : : #include <svx/unoshape.hxx>
43 : : #include "vbafont.hxx"
44 : : #include "drwlayer.hxx"
45 : :
46 : : using ::rtl::OUString;
47 : : using namespace ::com::sun::star;
48 : : using namespace ::ooo::vba;
49 : :
50 : : // ============================================================================
51 : :
52 : 0 : ScVbaButtonCharacters::ScVbaButtonCharacters(
53 : : const uno::Reference< XHelperInterface >& rxParent,
54 : : const uno::Reference< uno::XComponentContext >& rxContext,
55 : : const uno::Reference< beans::XPropertySet >& rxPropSet,
56 : : const ScVbaPalette& rPalette,
57 : : const uno::Any& rStart,
58 : : const uno::Any& rLength ) throw (uno::RuntimeException) :
59 : : ScVbaButtonCharacters_BASE( rxParent, rxContext ),
60 : : maPalette( rPalette ),
61 [ # # ]: 0 : mxPropSet( rxPropSet, uno::UNO_SET_THROW )
62 : : {
63 : : // extract optional start parameter (missing or invalid -> from beginning)
64 [ # # ][ # # ]: 0 : if( !(rStart >>= mnStart) || (mnStart < 1) )
[ # # ]
65 : 0 : mnStart = 1;
66 : 0 : --mnStart; // VBA is 1-based, rtl string is 0-based
67 : :
68 : : // extract optional length parameter (missing or invalid -> to end)
69 [ # # ][ # # ]: 0 : if( !(rLength >>= mnLength) || (mnLength < 1) )
[ # # ]
70 : 0 : mnLength = SAL_MAX_INT32;
71 : 0 : }
72 : :
73 : 0 : ScVbaButtonCharacters::~ScVbaButtonCharacters()
74 : : {
75 [ # # ]: 0 : }
76 : :
77 : : // XCharacters attributes
78 : :
79 : 0 : OUString SAL_CALL ScVbaButtonCharacters::getCaption() throw (uno::RuntimeException)
80 : : {
81 : : // ignore invalid mnStart and/or mnLength members
82 [ # # ]: 0 : OUString aString = getFullString();
83 [ # # ]: 0 : sal_Int32 nStart = ::std::min( mnStart, aString.getLength() );
84 [ # # ]: 0 : sal_Int32 nLength = ::std::min( mnLength, aString.getLength() - nStart );
85 : 0 : return aString.copy( nStart, nLength );
86 : : }
87 : :
88 : 0 : void SAL_CALL ScVbaButtonCharacters::setCaption( const OUString& rCaption ) throw (uno::RuntimeException)
89 : : {
90 : : /* Replace the covered text with the passed text, ignore invalid mnStart
91 : : and/or mnLength members. This operation does not affect the mnLength
92 : : parameter. If the inserted text is longer than mnLength, the additional
93 : : characters are not covered by this object. If the inserted text is
94 : : shorter than mnLength, other uncovered characters from the original
95 : : string will be covered now, thus may be changed with subsequent
96 : : operations. */
97 [ # # ]: 0 : OUString aString = getFullString();
98 [ # # ]: 0 : sal_Int32 nStart = ::std::min( mnStart, aString.getLength() );
99 [ # # ]: 0 : sal_Int32 nLength = ::std::min( mnLength, aString.getLength() - nStart );
100 [ # # ]: 0 : setFullString( aString.replaceAt( nStart, nLength, rCaption ) );
101 : 0 : }
102 : :
103 : 0 : sal_Int32 SAL_CALL ScVbaButtonCharacters::getCount() throw (uno::RuntimeException)
104 : : {
105 : : // always return the total length of the caption
106 : 0 : return getFullString().getLength();
107 : : }
108 : :
109 : 0 : OUString SAL_CALL ScVbaButtonCharacters::getText() throw (uno::RuntimeException)
110 : : {
111 : : // Text attribute same as Caption attribute?
112 : 0 : return getCaption();
113 : : }
114 : :
115 : 0 : void SAL_CALL ScVbaButtonCharacters::setText( const OUString& rText ) throw (uno::RuntimeException)
116 : : {
117 : : // Text attribute same as Caption attribute?
118 : 0 : setCaption( rText );
119 : 0 : }
120 : :
121 : 0 : uno::Reference< excel::XFont > SAL_CALL ScVbaButtonCharacters::getFont() throw (uno::RuntimeException)
122 : : {
123 [ # # ][ # # ]: 0 : return new ScVbaFont( this, mxContext, maPalette, mxPropSet, 0, true );
[ # # ]
124 : : }
125 : :
126 : 0 : void SAL_CALL ScVbaButtonCharacters::setFont( const uno::Reference< excel::XFont >& /*rxFont*/ ) throw (uno::RuntimeException)
127 : : {
128 : : // TODO
129 : 0 : }
130 : :
131 : : // XCharacters methods
132 : :
133 : 0 : void SAL_CALL ScVbaButtonCharacters::Insert( const OUString& rString ) throw (uno::RuntimeException)
134 : : {
135 : : /* The Insert() operation is in fact "replace covered characters", at
136 : : least for buttons... It seems there is no easy way to really insert a
137 : : substring. This operation does not affect the mnLength parameter. */
138 : 0 : setCaption( rString );
139 : 0 : }
140 : :
141 : 0 : void SAL_CALL ScVbaButtonCharacters::Delete() throw (uno::RuntimeException)
142 : : {
143 : : /* The Delete() operation is nothing else than "replace with empty string".
144 : : This does not affect the mnLength parameter, multiple calls of Delete()
145 : : will remove characters as long as there are some more covered by this
146 : : object. */
147 [ # # ]: 0 : setCaption( OUString() );
148 : 0 : }
149 : :
150 : : // XHelperInterface
151 : :
152 [ # # ][ # # ]: 0 : VBAHELPER_IMPL_XHELPERINTERFACE( ScVbaButtonCharacters, "ooo.vba.excel.Characters" )
[ # # ][ # # ]
[ # # ][ # # ]
153 : :
154 : : // private
155 : :
156 : 0 : OUString ScVbaButtonCharacters::getFullString() const throw (uno::RuntimeException)
157 : : {
158 [ # # ][ # # ]: 0 : return mxPropSet->getPropertyValue( CREATE_OUSTRING( "Label" ) ).get< OUString >();
159 : : }
160 : :
161 : 0 : void ScVbaButtonCharacters::setFullString( const OUString& rString ) throw (uno::RuntimeException)
162 : : {
163 [ # # ][ # # ]: 0 : mxPropSet->setPropertyValue( CREATE_OUSTRING( "Label" ), uno::Any( rString ) );
164 : 0 : }
165 : :
166 : : // ============================================================================
167 : :
168 : 0 : ScVbaSheetObjectBase::ScVbaSheetObjectBase(
169 : : const uno::Reference< XHelperInterface >& rxParent,
170 : : const uno::Reference< uno::XComponentContext >& rxContext,
171 : : const uno::Reference< frame::XModel >& rxModel,
172 : : const uno::Reference< drawing::XShape >& rxShape ) throw (uno::RuntimeException) :
173 : : ScVbaSheetObject_BASE( rxParent, rxContext ),
174 : : maPalette( rxModel ),
175 : : mxModel( rxModel, uno::UNO_SET_THROW ),
176 : : mxShape( rxShape, uno::UNO_SET_THROW ),
177 [ # # ][ # # ]: 0 : mxShapeProps( rxShape, uno::UNO_QUERY_THROW )
[ # # ][ # # ]
178 : : {
179 : 0 : }
180 : :
181 : : // XSheetObject attributes
182 : :
183 : 0 : double SAL_CALL ScVbaSheetObjectBase::getLeft() throw (uno::RuntimeException)
184 : : {
185 [ # # ]: 0 : return HmmToPoints( mxShape->getPosition().X );
186 : : }
187 : :
188 : 0 : void SAL_CALL ScVbaSheetObjectBase::setLeft( double fLeft ) throw (uno::RuntimeException)
189 : : {
190 [ # # ]: 0 : if( fLeft < 0.0 )
191 [ # # ]: 0 : throw uno::RuntimeException();
192 [ # # ][ # # ]: 0 : mxShape->setPosition( awt::Point( PointsToHmm( fLeft ), mxShape->getPosition().Y ) );
193 : 0 : }
194 : :
195 : 0 : double SAL_CALL ScVbaSheetObjectBase::getTop() throw (uno::RuntimeException)
196 : : {
197 [ # # ]: 0 : return HmmToPoints( mxShape->getPosition().Y );
198 : : }
199 : :
200 : 0 : void SAL_CALL ScVbaSheetObjectBase::setTop( double fTop ) throw (uno::RuntimeException)
201 : : {
202 [ # # ]: 0 : if( fTop < 0.0 )
203 [ # # ]: 0 : throw uno::RuntimeException();
204 [ # # ][ # # ]: 0 : mxShape->setPosition( awt::Point( mxShape->getPosition().X, PointsToHmm( fTop ) ) );
[ # # ]
205 : 0 : }
206 : :
207 : 0 : double SAL_CALL ScVbaSheetObjectBase::getWidth() throw (uno::RuntimeException)
208 : : {
209 [ # # ]: 0 : return HmmToPoints( mxShape->getSize().Width );
210 : : }
211 : :
212 : 0 : void SAL_CALL ScVbaSheetObjectBase::setWidth( double fWidth ) throw (uno::RuntimeException)
213 : : {
214 [ # # ]: 0 : if( fWidth <= 0.0 )
215 [ # # ]: 0 : throw uno::RuntimeException();
216 [ # # ][ # # ]: 0 : mxShape->setSize( awt::Size( PointsToHmm( fWidth ), mxShape->getSize().Height ) );
217 : 0 : }
218 : :
219 : 0 : double SAL_CALL ScVbaSheetObjectBase::getHeight() throw (uno::RuntimeException)
220 : : {
221 [ # # ]: 0 : return HmmToPoints( mxShape->getSize().Height );
222 : : }
223 : :
224 : 0 : void SAL_CALL ScVbaSheetObjectBase::setHeight( double fHeight ) throw (uno::RuntimeException)
225 : : {
226 [ # # ]: 0 : if( fHeight <= 0.0 )
227 [ # # ]: 0 : throw uno::RuntimeException();
228 [ # # ][ # # ]: 0 : mxShape->setSize( awt::Size( mxShape->getSize().Width, PointsToHmm( fHeight ) ) );
[ # # ]
229 : 0 : }
230 : :
231 : 0 : OUString SAL_CALL ScVbaSheetObjectBase::getName() throw (uno::RuntimeException)
232 : : {
233 [ # # ][ # # ]: 0 : return mxShapeProps->getPropertyValue( CREATE_OUSTRING( "Name" ) ).get< OUString >();
234 : : }
235 : :
236 : 0 : void SAL_CALL ScVbaSheetObjectBase::setName( const OUString& rName ) throw (uno::RuntimeException)
237 : : {
238 [ # # ][ # # ]: 0 : mxShapeProps->setPropertyValue( CREATE_OUSTRING( "Name" ), uno::Any( rName ) );
239 : 0 : }
240 : :
241 : 0 : sal_Int32 SAL_CALL ScVbaSheetObjectBase::getPlacement() throw (uno::RuntimeException)
242 : : {
243 : 0 : sal_Int32 nRet = excel::XlPlacement::xlMoveAndSize;
244 : : #if 0 // TODO: not working at the moment.
245 : : SvxShape* pShape = SvxShape::getImplementation( mxShape );
246 : : if(pShape)
247 : : {
248 : : SdrObject* pObj = pShape->GetSdrObject();
249 : : if (pObj)
250 : : {
251 : : ScAnchorType eType = ScDrawLayer::GetAnchor(pObj);
252 : : if (eType == SCA_PAGE)
253 : : nRet = excel::XlPlacement::xlFreeFloating;
254 : : }
255 : : }
256 : : #endif
257 : 0 : return nRet;
258 : : }
259 : :
260 : 0 : void SAL_CALL ScVbaSheetObjectBase::setPlacement( sal_Int32 /*nPlacement*/ ) throw (uno::RuntimeException)
261 : : {
262 : : #if 0 // TODO: not working at the moment.
263 : : SvxShape* pShape = SvxShape::getImplementation( mxShape );
264 : : if(pShape)
265 : : {
266 : : SdrObject* pObj = pShape->GetSdrObject();
267 : : if (pObj)
268 : : {
269 : : ScAnchorType eType = SCA_CELL;
270 : : if ( nPlacement == excel::XlPlacement::xlFreeFloating )
271 : : eType = SCA_PAGE;
272 : :
273 : : // xlMove is not supported, treated as SCA_CELL (xlMoveAndSize)
274 : :
275 : : ScDrawLayer::SetAnchor(pObj, eType);
276 : : }
277 : : }
278 : : #endif
279 : 0 : }
280 : :
281 : 0 : sal_Bool SAL_CALL ScVbaSheetObjectBase::getPrintObject() throw (uno::RuntimeException)
282 : : {
283 : : // not supported
284 : 0 : return sal_True;
285 : : }
286 : :
287 : 0 : void SAL_CALL ScVbaSheetObjectBase::setPrintObject( sal_Bool /*bPrintObject*/ ) throw (uno::RuntimeException)
288 : : {
289 : : // not supported
290 : 0 : }
291 : :
292 : : // private
293 : :
294 : 0 : void ScVbaSheetObjectBase::setDefaultProperties( sal_Int32 nIndex ) throw (uno::RuntimeException)
295 : : {
296 [ # # ][ # # ]: 0 : OUString aName = ::rtl::OUStringBuffer( implGetBaseName() ).append( sal_Unicode( ' ' ) ).append( nIndex + 1 ).makeStringAndClear();
[ # # ][ # # ]
[ # # ]
297 [ # # ]: 0 : setName( aName );
298 [ # # ]: 0 : implSetDefaultProperties();
299 : 0 : }
300 : :
301 : 0 : void ScVbaSheetObjectBase::implSetDefaultProperties() throw (uno::RuntimeException)
302 : : {
303 : 0 : }
304 : :
305 : : // ============================================================================
306 : :
307 : 0 : ScVbaControlObjectBase::ScVbaControlObjectBase(
308 : : const uno::Reference< XHelperInterface >& rxParent,
309 : : const uno::Reference< uno::XComponentContext >& rxContext,
310 : : const uno::Reference< frame::XModel >& rxModel,
311 : : const uno::Reference< container::XIndexContainer >& rxFormIC,
312 : : const uno::Reference< drawing::XControlShape >& rxControlShape,
313 : : ListenerType eListenerType ) throw (uno::RuntimeException) :
314 : : ScVbaControlObject_BASE( rxParent, rxContext, rxModel, uno::Reference< drawing::XShape >( rxControlShape, uno::UNO_QUERY_THROW ) ),
315 : : mxFormIC( rxFormIC, uno::UNO_SET_THROW ),
316 [ # # ][ # # ]: 0 : mxControlProps( rxControlShape->getControl(), uno::UNO_QUERY_THROW )
[ # # ][ # # ]
[ # # ]
317 : : {
318 : : // set listener and event name to be used for OnAction attribute
319 [ # # # # : 0 : switch( eListenerType )
# # ]
320 : : {
321 : : case LISTENER_ACTION:
322 [ # # ]: 0 : maListenerType = CREATE_OUSTRING( "XActionListener" );
323 [ # # ]: 0 : maEventMethod = CREATE_OUSTRING( "actionPerformed" );
324 : 0 : break;
325 : : case LISTENER_MOUSE:
326 [ # # ]: 0 : maListenerType = CREATE_OUSTRING( "XMouseListener" );
327 [ # # ]: 0 : maEventMethod = CREATE_OUSTRING( "mouseReleased" );
328 : 0 : break;
329 : : case LISTENER_TEXT:
330 [ # # ]: 0 : maListenerType = CREATE_OUSTRING( "XTextListener" );
331 [ # # ]: 0 : maEventMethod = CREATE_OUSTRING( "textChanged" );
332 : 0 : break;
333 : : case LISTENER_VALUE:
334 [ # # ]: 0 : maListenerType = CREATE_OUSTRING( "XAdjustmentListener" );
335 [ # # ]: 0 : maEventMethod = CREATE_OUSTRING( "adjustmentValueChanged" );
336 : 0 : break;
337 : : case LISTENER_CHANGE:
338 [ # # ]: 0 : maListenerType = CREATE_OUSTRING( "XChangeListener" );
339 [ # # ]: 0 : maEventMethod = CREATE_OUSTRING( "changed" );
340 : 0 : break;
341 : : // no default, to let the compiler complain about missing case
342 : : }
343 : 0 : }
344 : :
345 : : // XSheetObject attributes
346 : :
347 : 0 : OUString SAL_CALL ScVbaControlObjectBase::getName() throw (uno::RuntimeException)
348 : : {
349 [ # # ][ # # ]: 0 : return mxControlProps->getPropertyValue( CREATE_OUSTRING( "Name" ) ).get< OUString >();
350 : : }
351 : :
352 : 0 : void SAL_CALL ScVbaControlObjectBase::setName( const OUString& rName ) throw (uno::RuntimeException)
353 : : {
354 [ # # ][ # # ]: 0 : mxControlProps->setPropertyValue( CREATE_OUSTRING( "Name" ), uno::Any( rName ) );
355 : 0 : }
356 : :
357 : 0 : OUString SAL_CALL ScVbaControlObjectBase::getOnAction() throw (uno::RuntimeException)
358 : : {
359 [ # # ]: 0 : uno::Reference< script::XEventAttacherManager > xEventMgr( mxFormIC, uno::UNO_QUERY_THROW );
360 [ # # ]: 0 : sal_Int32 nIndex = getModelIndexInForm();
361 [ # # ][ # # ]: 0 : uno::Sequence< script::ScriptEventDescriptor > aEvents = xEventMgr->getScriptEvents( nIndex );
362 [ # # ]: 0 : if( aEvents.hasElements() )
363 : : {
364 : 0 : const script::ScriptEventDescriptor* pEvent = aEvents.getConstArray();
365 : 0 : const script::ScriptEventDescriptor* pEventEnd = pEvent + aEvents.getLength();
366 [ # # ]: 0 : const OUString aScriptType = CREATE_OUSTRING( "Script" );
367 [ # # ]: 0 : for( ; pEvent < pEventEnd; ++pEvent )
368 [ # # ][ # # ]: 0 : if( (pEvent->ListenerType == maListenerType) && (pEvent->EventMethod == maEventMethod) && (pEvent->ScriptType == aScriptType) )
[ # # ][ # # ]
369 [ # # ][ # # ]: 0 : return extractMacroName( pEvent->ScriptCode );
370 : : }
371 [ # # ]: 0 : return OUString();
372 : : }
373 : :
374 : 0 : void SAL_CALL ScVbaControlObjectBase::setOnAction( const OUString& rMacroName ) throw (uno::RuntimeException)
375 : : {
376 [ # # ]: 0 : uno::Reference< script::XEventAttacherManager > xEventMgr( mxFormIC, uno::UNO_QUERY_THROW );
377 [ # # ]: 0 : sal_Int32 nIndex = getModelIndexInForm();
378 : :
379 : : // first, remove a registered event (try/catch just in case implementation throws)
380 [ # # ][ # # ]: 0 : try { xEventMgr->revokeScriptEvent( nIndex, maListenerType, maEventMethod, OUString() ); } catch( uno::Exception& ) {}
[ # # # # ]
381 : :
382 : : // if a macro name has been passed, try to attach it to the event
383 [ # # ]: 0 : if( !rMacroName.isEmpty() )
384 : : {
385 [ # # ][ # # ]: 0 : MacroResolvedInfo aResolvedMacro = resolveVBAMacro( getSfxObjShell( mxModel ), rMacroName );
386 [ # # ]: 0 : if( !aResolvedMacro.mbFound )
387 [ # # ]: 0 : throw uno::RuntimeException();
388 : 0 : script::ScriptEventDescriptor aDescriptor;
389 : 0 : aDescriptor.ListenerType = maListenerType;
390 : 0 : aDescriptor.EventMethod = maEventMethod;
391 [ # # ]: 0 : aDescriptor.ScriptType = CREATE_OUSTRING( "Script" );
392 [ # # ][ # # ]: 0 : aDescriptor.ScriptCode = makeMacroURL( aResolvedMacro.msResolvedMacro );
[ # # ]
393 [ # # ][ # # ]: 0 : xEventMgr->registerScriptEvent( nIndex, aDescriptor );
[ # # ]
394 : 0 : }
395 : 0 : }
396 : :
397 : 0 : sal_Bool SAL_CALL ScVbaControlObjectBase::getPrintObject() throw (uno::RuntimeException)
398 : : {
399 [ # # ][ # # ]: 0 : return mxControlProps->getPropertyValue( CREATE_OUSTRING( "Printable" ) ).get< sal_Bool >();
400 : : }
401 : :
402 : 0 : void SAL_CALL ScVbaControlObjectBase::setPrintObject( sal_Bool bPrintObject ) throw (uno::RuntimeException)
403 : : {
404 [ # # ][ # # ]: 0 : mxControlProps->setPropertyValue( CREATE_OUSTRING( "Printable" ), uno::Any( bPrintObject ) );
405 : 0 : }
406 : :
407 : : // XControlObject attributes
408 : :
409 : 0 : sal_Bool SAL_CALL ScVbaControlObjectBase::getAutoSize() throw (uno::RuntimeException)
410 : : {
411 : : // not supported
412 : 0 : return false;
413 : : }
414 : :
415 : 0 : void SAL_CALL ScVbaControlObjectBase::setAutoSize( sal_Bool /*bAutoSize*/ ) throw (uno::RuntimeException)
416 : : {
417 : : // not supported
418 : 0 : }
419 : :
420 : : // private
421 : :
422 : 0 : sal_Int32 ScVbaControlObjectBase::getModelIndexInForm() const throw (uno::RuntimeException)
423 : : {
424 [ # # ]: 0 : for( sal_Int32 nIndex = 0, nCount = mxFormIC->getCount(); nIndex < nCount; ++nIndex )
425 : : {
426 [ # # ][ # # ]: 0 : uno::Reference< beans::XPropertySet > xProps( mxFormIC->getByIndex( nIndex ), uno::UNO_QUERY_THROW );
[ # # ]
427 [ # # ][ # # ]: 0 : if( mxControlProps.get() == xProps.get() )
[ # # ]
428 : 0 : return nIndex;
429 [ # # ]: 0 : }
430 [ # # ]: 0 : throw uno::RuntimeException();
431 : : }
432 : :
433 : : // ============================================================================
434 : :
435 : 0 : ScVbaButton::ScVbaButton(
436 : : const uno::Reference< XHelperInterface >& rxParent,
437 : : const uno::Reference< uno::XComponentContext >& rxContext,
438 : : const uno::Reference< frame::XModel >& rxModel,
439 : : const uno::Reference< container::XIndexContainer >& rxFormIC,
440 : : const uno::Reference< drawing::XControlShape >& rxControlShape ) throw (uno::RuntimeException) :
441 [ # # ]: 0 : ScVbaButton_BASE( rxParent, rxContext, rxModel, rxFormIC, rxControlShape, LISTENER_ACTION )
442 : : {
443 : 0 : }
444 : :
445 : : // XButton attributes
446 : :
447 : 0 : OUString SAL_CALL ScVbaButton::getCaption() throw (uno::RuntimeException)
448 : : {
449 [ # # ][ # # ]: 0 : return mxControlProps->getPropertyValue( CREATE_OUSTRING( "Label" ) ).get< OUString >();
450 : : }
451 : :
452 : 0 : void SAL_CALL ScVbaButton::setCaption( const OUString& rCaption ) throw (uno::RuntimeException)
453 : : {
454 [ # # ][ # # ]: 0 : mxControlProps->setPropertyValue( CREATE_OUSTRING( "Label" ), uno::Any( rCaption ) );
455 : 0 : }
456 : :
457 : 0 : uno::Reference< excel::XFont > SAL_CALL ScVbaButton::getFont() throw (uno::RuntimeException)
458 : : {
459 [ # # ][ # # ]: 0 : return new ScVbaFont( this, mxContext, maPalette, mxControlProps, 0, true );
[ # # ]
460 : : }
461 : :
462 : 0 : void SAL_CALL ScVbaButton::setFont( const uno::Reference< excel::XFont >& /*rxFont*/ ) throw (uno::RuntimeException)
463 : : {
464 : : // TODO
465 : 0 : }
466 : :
467 : 0 : sal_Int32 SAL_CALL ScVbaButton::getHorizontalAlignment() throw (uno::RuntimeException)
468 : : {
469 [ # # ][ # # ]: 0 : switch( mxControlProps->getPropertyValue( CREATE_OUSTRING( "Align" ) ).get< sal_Int16 >() )
[ # # # # ]
470 : : {
471 : 0 : case awt::TextAlign::LEFT: return excel::Constants::xlLeft;
472 : 0 : case awt::TextAlign::RIGHT: return excel::Constants::xlRight;
473 : 0 : case awt::TextAlign::CENTER: return excel::Constants::xlCenter;
474 : : }
475 : 0 : return excel::Constants::xlCenter;
476 : : }
477 : :
478 : 0 : void SAL_CALL ScVbaButton::setHorizontalAlignment( sal_Int32 nAlign ) throw (uno::RuntimeException)
479 : : {
480 : 0 : sal_Int32 nAwtAlign = awt::TextAlign::CENTER;
481 [ # # # # ]: 0 : switch( nAlign )
482 : : {
483 : 0 : case excel::Constants::xlLeft: nAwtAlign = awt::TextAlign::LEFT; break;
484 : 0 : case excel::Constants::xlRight: nAwtAlign = awt::TextAlign::RIGHT; break;
485 : 0 : case excel::Constants::xlCenter: nAwtAlign = awt::TextAlign::CENTER; break;
486 : : }
487 : : // form controls expect short value
488 [ # # ][ # # ]: 0 : mxControlProps->setPropertyValue( CREATE_OUSTRING( "Align" ), uno::Any( static_cast< sal_Int16 >( nAwtAlign ) ) );
[ # # ]
489 : 0 : }
490 : :
491 : 0 : sal_Int32 SAL_CALL ScVbaButton::getVerticalAlignment() throw (uno::RuntimeException)
492 : : {
493 [ # # ][ # # ]: 0 : switch( mxControlProps->getPropertyValue( CREATE_OUSTRING( "VerticalAlign" ) ).get< style::VerticalAlignment >() )
[ # # # # ]
494 : : {
495 : 0 : case style::VerticalAlignment_TOP: return excel::Constants::xlTop;
496 : 0 : case style::VerticalAlignment_BOTTOM: return excel::Constants::xlBottom;
497 : 0 : case style::VerticalAlignment_MIDDLE: return excel::Constants::xlCenter;
498 : : default:;
499 : : }
500 : 0 : return excel::Constants::xlCenter;
501 : : }
502 : :
503 : 0 : void SAL_CALL ScVbaButton::setVerticalAlignment( sal_Int32 nAlign ) throw (uno::RuntimeException)
504 : : {
505 : 0 : style::VerticalAlignment eAwtAlign = style::VerticalAlignment_MIDDLE;
506 [ # # # # ]: 0 : switch( nAlign )
507 : : {
508 : 0 : case excel::Constants::xlTop: eAwtAlign = style::VerticalAlignment_TOP; break;
509 : 0 : case excel::Constants::xlBottom: eAwtAlign = style::VerticalAlignment_BOTTOM; break;
510 : 0 : case excel::Constants::xlCenter: eAwtAlign = style::VerticalAlignment_MIDDLE; break;
511 : : }
512 [ # # ][ # # ]: 0 : mxControlProps->setPropertyValue( CREATE_OUSTRING( "VerticalAlign" ), uno::Any( eAwtAlign ) );
[ # # ][ # # ]
513 : 0 : }
514 : :
515 : 0 : sal_Int32 SAL_CALL ScVbaButton::getOrientation() throw (uno::RuntimeException)
516 : : {
517 : : // not supported
518 : 0 : return excel::XlOrientation::xlHorizontal;
519 : : }
520 : :
521 : 0 : void SAL_CALL ScVbaButton::setOrientation( sal_Int32 /*nOrientation*/ ) throw (uno::RuntimeException)
522 : : {
523 : : // not supported
524 : 0 : }
525 : :
526 : : // XButton methods
527 : :
528 : 0 : uno::Reference< excel::XCharacters > SAL_CALL ScVbaButton::Characters( const uno::Any& rStart, const uno::Any& rLength ) throw (uno::RuntimeException)
529 : : {
530 [ # # ][ # # ]: 0 : return new ScVbaButtonCharacters( this, mxContext, mxControlProps, maPalette, rStart, rLength );
[ # # ]
531 : : }
532 : :
533 : : // XHelperInterface
534 : :
535 [ # # ][ # # ]: 0 : VBAHELPER_IMPL_XHELPERINTERFACE( ScVbaButton, "ooo.vba.excel.Button" )
[ # # ][ # # ]
[ # # ][ # # ]
536 : :
537 : : // private
538 : :
539 : 0 : OUString ScVbaButton::implGetBaseName() const
540 : : {
541 : 0 : return CREATE_OUSTRING( "Button" );
542 : : }
543 : :
544 : 0 : void ScVbaButton::implSetDefaultProperties() throw (uno::RuntimeException)
545 : : {
546 [ # # ]: 0 : setCaption( getName() );
547 : 0 : }
548 : :
549 : : // ============================================================================
550 : :
551 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|