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 <com/sun/star/form/FormComponentType.hpp>
20 : #include <com/sun/star/awt/XControlModel.hpp>
21 : #include <com/sun/star/awt/XControl.hpp>
22 : #include <com/sun/star/awt/XWindow2.hpp>
23 : #include <com/sun/star/awt/XActionListener.hpp>
24 : #include <com/sun/star/lang/XEventListener.hpp>
25 : #include <com/sun/star/drawing/XShape.hpp>
26 : #include <com/sun/star/drawing/XControlShape.hpp>
27 : #include <com/sun/star/frame/XModel.hpp>
28 : #include <com/sun/star/view/XControlAccess.hpp>
29 : #include <com/sun/star/container/XChild.hpp>
30 : #include <com/sun/star/form/binding/XBindableValue.hpp>
31 : #include <com/sun/star/form/binding/XListEntrySink.hpp>
32 : #include <com/sun/star/table/CellAddress.hpp>
33 : #include <com/sun/star/table/CellRangeAddress.hpp>
34 : #include <com/sun/star/script/XScriptListener.hpp>
35 : #include <com/sun/star/document/XCodeNameQuery.hpp>
36 : #include <com/sun/star/form/XChangeListener.hpp>
37 : #include <ooo/vba/XControlProvider.hpp>
38 : #include <ooo/vba/msforms/fmMousePointer.hpp>
39 : #include <svtools/bindablecontrolhelper.hxx>
40 : #include "vbacontrol.hxx"
41 : #include "vbacombobox.hxx"
42 : #include "vbabutton.hxx"
43 : #include "vbalabel.hxx"
44 : #include "vbatextbox.hxx"
45 : #include "vbaradiobutton.hxx"
46 : #include "vbalistbox.hxx"
47 : #include "vbatogglebutton.hxx"
48 : #include "vbacheckbox.hxx"
49 : #include "vbaframe.hxx"
50 : #include "vbascrollbar.hxx"
51 : #include "vbaprogressbar.hxx"
52 : #include "vbamultipage.hxx"
53 : #include "vbaspinbutton.hxx"
54 : #include "vbasystemaxcontrol.hxx"
55 : #include "vbaimage.hxx"
56 : #include <vbahelper/helperdecl.hxx>
57 : #include <toolkit/helper/vclunohelper.hxx>
58 : #include <vcl/window.hxx>
59 : using namespace com::sun::star;
60 : using namespace ooo::vba;
61 :
62 : uno::Reference< css::awt::XWindowPeer >
63 0 : ScVbaControl::getWindowPeer() throw (uno::RuntimeException)
64 : {
65 0 : uno::Reference< drawing::XControlShape > xControlShape( m_xControl, uno::UNO_QUERY );
66 :
67 0 : uno::Reference< awt::XControlModel > xControlModel;
68 0 : uno::Reference< css::awt::XWindowPeer > xWinPeer;
69 0 : if ( !xControlShape.is() )
70 : {
71 : // would seem to be a Userform control
72 0 : uno::Reference< awt::XControl > xControl( m_xControl, uno::UNO_QUERY_THROW );
73 0 : xWinPeer = xControl->getPeer();
74 0 : return xWinPeer;
75 : }
76 : // form control
77 0 : xControlModel.set( xControlShape->getControl(), uno::UNO_QUERY_THROW );
78 :
79 0 : uno::Reference< view::XControlAccess > xControlAccess( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW );
80 : try
81 : {
82 0 : uno::Reference< awt::XControl > xControl( xControlAccess->getControl( xControlModel ), uno::UNO_QUERY );
83 0 : xWinPeer = xControl->getPeer();
84 : }
85 0 : catch(const uno::Exception&)
86 : {
87 0 : throw uno::RuntimeException( "The Control does not exsit" , uno::Reference< uno::XInterface >() );
88 : }
89 0 : return xWinPeer;
90 : }
91 :
92 : //ScVbaControlListener
93 : class ScVbaControlListener: public cppu::WeakImplHelper1< lang::XEventListener >
94 : {
95 : private:
96 : ScVbaControl *pControl;
97 : public:
98 : ScVbaControlListener( ScVbaControl *pTmpControl );
99 : virtual ~ScVbaControlListener();
100 : virtual void SAL_CALL disposing( const lang::EventObject& rEventObject ) throw( uno::RuntimeException );
101 : };
102 :
103 0 : ScVbaControlListener::ScVbaControlListener( ScVbaControl *pTmpControl ): pControl( pTmpControl )
104 : {
105 0 : }
106 :
107 0 : ScVbaControlListener::~ScVbaControlListener()
108 : {
109 0 : }
110 :
111 : void SAL_CALL
112 0 : ScVbaControlListener::disposing( const lang::EventObject& ) throw( uno::RuntimeException )
113 : {
114 0 : if( pControl )
115 : {
116 0 : pControl->removeResouce();
117 0 : pControl = NULL;
118 : }
119 0 : }
120 :
121 : //ScVbaControl
122 :
123 0 : ScVbaControl::ScVbaControl( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< ::uno::XInterface >& xControl, const css::uno::Reference< css::frame::XModel >& xModel, AbstractGeometryAttributes* pGeomHelper ) : ControlImpl_BASE( xParent, xContext ), bIsDialog(false), m_xControl( xControl ), m_xModel( xModel )
124 : {
125 : //add listener
126 0 : m_xEventListener.set( new ScVbaControlListener( this ) );
127 0 : setGeometryHelper( pGeomHelper );
128 0 : uno::Reference< lang::XComponent > xComponent( m_xControl, uno::UNO_QUERY_THROW );
129 0 : xComponent->addEventListener( m_xEventListener );
130 :
131 : //init m_xProps
132 0 : uno::Reference< drawing::XControlShape > xControlShape( m_xControl, uno::UNO_QUERY ) ;
133 0 : uno::Reference< awt::XControl> xUserFormControl( m_xControl, uno::UNO_QUERY ) ;
134 0 : if ( xControlShape.is() ) // form control
135 : {
136 0 : m_xProps.set( xControlShape->getControl(), uno::UNO_QUERY_THROW );
137 0 : OUString sDefaultControl;
138 0 : m_xProps->getPropertyValue( "DefaultControl" ) >>= sDefaultControl;
139 0 : uno::Reference< lang::XMultiComponentFactory > xMFac( mxContext->getServiceManager(), uno::UNO_QUERY_THROW );
140 0 : m_xEmptyFormControl.set( xMFac->createInstanceWithContext( sDefaultControl, mxContext ), uno::UNO_QUERY_THROW );
141 : }
142 0 : else if ( xUserFormControl.is() ) // userform control
143 : {
144 0 : m_xProps.set( xUserFormControl->getModel(), uno::UNO_QUERY_THROW );
145 0 : bIsDialog = true;
146 0 : }
147 0 : }
148 :
149 0 : ScVbaControl::~ScVbaControl()
150 : {
151 0 : if( m_xControl.is() )
152 : {
153 0 : uno::Reference< lang::XComponent > xComponent( m_xControl, uno::UNO_QUERY_THROW );
154 0 : xComponent->removeEventListener( m_xEventListener );
155 : }
156 0 : }
157 :
158 : void
159 0 : ScVbaControl::setGeometryHelper( AbstractGeometryAttributes* pHelper )
160 : {
161 0 : mpGeometryHelper.reset( pHelper );
162 0 : }
163 :
164 0 : void ScVbaControl::removeResouce() throw( uno::RuntimeException )
165 : {
166 0 : uno::Reference< lang::XComponent > xComponent( m_xControl, uno::UNO_QUERY_THROW );
167 0 : xComponent->removeEventListener( m_xEventListener );
168 0 : m_xControl= NULL;
169 0 : m_xProps = NULL;
170 0 : }
171 :
172 : //In design model has different behavior
173 0 : sal_Bool SAL_CALL ScVbaControl::getEnabled() throw (uno::RuntimeException)
174 : {
175 0 : uno::Any aValue = m_xProps->getPropertyValue ( "Enabled" );
176 0 : sal_Bool bRet = false;
177 0 : aValue >>= bRet;
178 0 : return bRet;
179 : }
180 :
181 0 : void SAL_CALL ScVbaControl::setEnabled( sal_Bool bVisible ) throw (uno::RuntimeException)
182 : {
183 0 : uno::Any aValue( bVisible );
184 0 : m_xProps->setPropertyValue( "Enabled" , aValue);
185 :
186 0 : }
187 :
188 0 : sal_Bool SAL_CALL ScVbaControl::getVisible() throw (uno::RuntimeException)
189 : {
190 0 : sal_Bool bVisible( sal_True );
191 0 : m_xProps->getPropertyValue( "EnableVisible" ) >>= bVisible;
192 0 : return bVisible;
193 : }
194 :
195 0 : void SAL_CALL ScVbaControl::setVisible( sal_Bool bVisible ) throw (uno::RuntimeException)
196 : {
197 0 : uno::Any aValue( bVisible );
198 0 : m_xProps->setPropertyValue( "EnableVisible" , aValue);
199 0 : }
200 0 : double SAL_CALL ScVbaControl::getHeight() throw (uno::RuntimeException)
201 : {
202 0 : return mpGeometryHelper->getHeight();
203 : }
204 0 : void SAL_CALL ScVbaControl::setHeight( double _height ) throw (uno::RuntimeException)
205 : {
206 0 : mpGeometryHelper->setHeight( _height );
207 0 : }
208 :
209 0 : double SAL_CALL ScVbaControl::getWidth() throw (uno::RuntimeException)
210 : {
211 0 : return mpGeometryHelper->getWidth();
212 : }
213 0 : void SAL_CALL ScVbaControl::setWidth( double _width ) throw (uno::RuntimeException)
214 : {
215 0 : mpGeometryHelper->setWidth( _width );
216 0 : }
217 :
218 : double SAL_CALL
219 0 : ScVbaControl::getLeft() throw (uno::RuntimeException)
220 : {
221 0 : return mpGeometryHelper->getLeft();
222 : }
223 :
224 : void SAL_CALL
225 0 : ScVbaControl::setLeft( double _left ) throw (uno::RuntimeException)
226 : {
227 0 : mpGeometryHelper->setLeft( _left );
228 0 : }
229 :
230 : double SAL_CALL
231 0 : ScVbaControl::getTop() throw (uno::RuntimeException)
232 : {
233 0 : return mpGeometryHelper->getTop();
234 : }
235 :
236 : void SAL_CALL
237 0 : ScVbaControl::setTop( double _top ) throw (uno::RuntimeException)
238 : {
239 0 : mpGeometryHelper->setTop( _top );
240 0 : }
241 :
242 : uno::Reference< uno::XInterface > SAL_CALL
243 0 : ScVbaControl::getObject() throw (uno::RuntimeException)
244 : {
245 0 : uno::Reference< msforms::XControl > xRet( this );
246 0 : return xRet;
247 : }
248 :
249 0 : void SAL_CALL ScVbaControl::SetFocus() throw (uno::RuntimeException)
250 : {
251 0 : uno::Reference< awt::XWindow > xWin( m_xControl, uno::UNO_QUERY_THROW );
252 0 : xWin->setFocus();
253 0 : }
254 :
255 0 : void SAL_CALL ScVbaControl::Move( double Left, double Top, const uno::Any& Width, const uno::Any& Height )
256 : throw ( uno::RuntimeException )
257 : {
258 0 : double nWidth = 0.0;
259 0 : double nHeight = 0.0;
260 :
261 0 : setLeft( Left );
262 0 : setTop( Top );
263 :
264 0 : if ( Width >>= nWidth )
265 0 : setWidth( nWidth );
266 :
267 0 : if ( Height >>= nHeight )
268 0 : setHeight( nHeight );
269 0 : }
270 :
271 : OUString SAL_CALL
272 0 : ScVbaControl::getControlSource() throw (uno::RuntimeException)
273 : {
274 : // #FIXME I *hate* having these upstream differences
275 : // but this is necessary until I manage to upstream other
276 : // dependant parts
277 0 : OUString sControlSource;
278 0 : uno::Reference< form::binding::XBindableValue > xBindable( m_xProps, uno::UNO_QUERY );
279 0 : if ( xBindable.is() )
280 : {
281 : try
282 : {
283 0 : uno::Reference< lang::XMultiServiceFactory > xFac( m_xModel, uno::UNO_QUERY_THROW );
284 0 : uno::Reference< beans::XPropertySet > xConvertor( xFac->createInstance( "com.sun.star.table.CellAddressConversion" ), uno::UNO_QUERY );
285 0 : uno::Reference< beans::XPropertySet > xProps( xBindable->getValueBinding(), uno::UNO_QUERY_THROW );
286 0 : table::CellAddress aAddress;
287 0 : xProps->getPropertyValue( "BoundCell" ) >>= aAddress;
288 0 : xConvertor->setPropertyValue( "Address" , uno::makeAny( aAddress ) );
289 0 : xConvertor->getPropertyValue( "XL_A1_Representation" ) >>= sControlSource;
290 : }
291 0 : catch(const uno::Exception&)
292 : {
293 : }
294 : }
295 0 : return sControlSource;
296 : }
297 :
298 : void SAL_CALL
299 0 : ScVbaControl::setControlSource( const OUString& _controlsource ) throw (uno::RuntimeException)
300 : {
301 0 : OUString sEmpty;
302 0 : svt::BindableControlHelper::ApplyListSourceAndBindableData( m_xModel, m_xProps, _controlsource, sEmpty );
303 0 : }
304 :
305 : OUString SAL_CALL
306 0 : ScVbaControl::getRowSource() throw (uno::RuntimeException)
307 : {
308 0 : OUString sRowSource;
309 0 : uno::Reference< form::binding::XListEntrySink > xListSink( m_xProps, uno::UNO_QUERY );
310 0 : if ( xListSink.is() )
311 : {
312 : try
313 : {
314 0 : uno::Reference< lang::XMultiServiceFactory > xFac( m_xModel, uno::UNO_QUERY_THROW );
315 0 : uno::Reference< beans::XPropertySet > xConvertor( xFac->createInstance( "com.sun.star.table.CellRangeAddressConversion" ), uno::UNO_QUERY );
316 :
317 0 : uno::Reference< beans::XPropertySet > xProps( xListSink->getListEntrySource(), uno::UNO_QUERY_THROW );
318 0 : table::CellRangeAddress aAddress;
319 0 : xProps->getPropertyValue( "CellRange" ) >>= aAddress;
320 0 : xConvertor->setPropertyValue( "Address" , uno::makeAny( aAddress ) );
321 0 : xConvertor->getPropertyValue( "XL_A1_Representation" ) >>= sRowSource;
322 : }
323 0 : catch(const uno::Exception&)
324 : {
325 : }
326 : }
327 0 : return sRowSource;
328 : }
329 :
330 : void SAL_CALL
331 0 : ScVbaControl::setRowSource( const OUString& _rowsource ) throw (uno::RuntimeException)
332 : {
333 0 : OUString sEmpty;
334 0 : svt::BindableControlHelper::ApplyListSourceAndBindableData( m_xModel, m_xProps, sEmpty, _rowsource );
335 0 : }
336 :
337 : OUString SAL_CALL
338 0 : ScVbaControl::getName() throw (uno::RuntimeException)
339 : {
340 0 : OUString sName;
341 0 : m_xProps->getPropertyValue( "Name" ) >>= sName;
342 0 : return sName;
343 :
344 : }
345 :
346 : void SAL_CALL
347 0 : ScVbaControl::setName( const OUString& _name ) throw (uno::RuntimeException)
348 : {
349 0 : m_xProps->setPropertyValue( "Name" , uno::makeAny( _name ) );
350 0 : }
351 :
352 : OUString SAL_CALL
353 0 : ScVbaControl::getControlTipText() throw (css::uno::RuntimeException)
354 : {
355 0 : OUString sName;
356 0 : m_xProps->getPropertyValue( "HelpText" ) >>= sName;
357 0 : return sName;
358 : }
359 :
360 : void SAL_CALL
361 0 : ScVbaControl::setControlTipText( const OUString& rsToolTip ) throw (css::uno::RuntimeException)
362 : {
363 0 : m_xProps->setPropertyValue( "HelpText" , uno::makeAny( rsToolTip ) );
364 0 : }
365 :
366 0 : OUString SAL_CALL ScVbaControl::getTag()
367 : throw (css::uno::RuntimeException)
368 : {
369 0 : return m_aControlTag;
370 : }
371 :
372 0 : void SAL_CALL ScVbaControl::setTag( const OUString& aTag )
373 : throw (css::uno::RuntimeException)
374 : {
375 0 : m_aControlTag = aTag;
376 0 : }
377 :
378 0 : ::sal_Int32 SAL_CALL ScVbaControl::getForeColor() throw (::com::sun::star::uno::RuntimeException)
379 : {
380 0 : sal_Int32 nForeColor = -1;
381 0 : m_xProps->getPropertyValue( "TextColor" ) >>= nForeColor;
382 0 : return OORGBToXLRGB( nForeColor );
383 : }
384 :
385 0 : void SAL_CALL ScVbaControl::setForeColor( ::sal_Int32 _forecolor ) throw (::com::sun::star::uno::RuntimeException)
386 : {
387 0 : m_xProps->setPropertyValue( "TextColor" , uno::makeAny( XLRGBToOORGB( _forecolor ) ) );
388 0 : }
389 :
390 : struct PointerStyles
391 : {
392 : long msoPointerStyle;
393 : PointerStyle loPointStyle;
394 : };
395 :
396 : // 1 -> 1 map of styles ( some dubious choices in there though )
397 : PointerStyles styles[] = {
398 : /// assuming pointer default is Arrow
399 : { msforms::fmMousePointer::fmMousePointerDefault, POINTER_ARROW },
400 : { msforms::fmMousePointer::fmMousePointerArrow, POINTER_ARROW },
401 : { msforms::fmMousePointer::fmMousePointerCross, POINTER_CROSS },
402 : { msforms::fmMousePointer::fmMousePointerIBeam, POINTER_TEXT },
403 : { msforms::fmMousePointer::fmMousePointerSizeNESW, POINTER_AUTOSCROLL_NSWE }, // #TODO not correct, need to check, need to find the right one
404 : { msforms::fmMousePointer::fmMousePointerSizeNS, POINTER_AUTOSCROLL_NS },
405 : { msforms::fmMousePointer::fmMousePointerSizeNWSE, POINTER_AUTOSCROLL_NSWE }, // #TODO not correct, need to check, need to find the right one
406 : { msforms::fmMousePointer::fmMousePointerSizeWE, POINTER_AUTOSCROLL_WE },
407 : { msforms::fmMousePointer::fmMousePointerUpArrow, POINTER_WINDOW_NSIZE },
408 : { msforms::fmMousePointer::fmMousePointerHourGlass, POINTER_WAIT },
409 : { msforms::fmMousePointer::fmMousePointerNoDrop, POINTER_NOTALLOWED },
410 : { msforms::fmMousePointer::fmMousePointerAppStarting, POINTER_WAIT },
411 : { msforms::fmMousePointer::fmMousePointerHelp, POINTER_HELP },
412 : { msforms::fmMousePointer::fmMousePointerSizeAll, POINTER_CROSS },
413 : { msforms::fmMousePointer::fmMousePointerCustom, POINTER_ARROW }, // not supported I guess
414 :
415 : };
416 :
417 0 : static long lcl_loPointerToMsoPointer( PointerStyle eType )
418 : {
419 0 : long nRet = msforms::fmMousePointer::fmMousePointerDefault;
420 0 : for ( int i = 0, nElems = SAL_N_ELEMENTS( styles ); i < nElems; ++i )
421 : {
422 0 : if ( styles[ i ].loPointStyle == eType )
423 : {
424 0 : nRet = styles[ i ].msoPointerStyle;
425 0 : break;
426 : }
427 : }
428 0 : return nRet;
429 : }
430 :
431 0 : static Pointer lcl_msoPointerToLOPointer( long msoPointerStyle )
432 : {
433 0 : Pointer aPointer( POINTER_ARROW );
434 0 : for ( int i = 0, nElems = SAL_N_ELEMENTS( styles ); i < nElems; ++i )
435 : {
436 0 : if ( styles[ i ].msoPointerStyle == msoPointerStyle )
437 : {
438 0 : aPointer = Pointer( styles[ i ].loPointStyle );
439 0 : break;
440 : }
441 : }
442 0 : return aPointer;
443 : }
444 :
445 : ::sal_Int32 SAL_CALL
446 0 : ScVbaControl::getMousePointer() throw (::com::sun::star::uno::RuntimeException)
447 : {
448 0 : PointerStyle eType = POINTER_ARROW; // default ?
449 0 : Window* pWindow = VCLUnoHelper::GetWindow( getWindowPeer() );
450 0 : if ( pWindow )
451 : {
452 0 : eType = pWindow->GetPointer().GetStyle();
453 : }
454 0 : return lcl_loPointerToMsoPointer( eType );
455 : }
456 :
457 : void SAL_CALL
458 0 : ScVbaControl::setMousePointer( ::sal_Int32 _mousepointer ) throw (::com::sun::star::uno::RuntimeException)
459 : {
460 0 : Window* pWindow = VCLUnoHelper::GetWindow( getWindowPeer() );
461 0 : if ( pWindow )
462 : {
463 0 : Pointer aPointer( POINTER_ARROW );
464 0 : aPointer = lcl_msoPointerToLOPointer( _mousepointer );
465 0 : pWindow->SetPointer( aPointer );
466 : }
467 0 : }
468 :
469 0 : void ScVbaControl::fireEvent( script::ScriptEvent& evt )
470 : {
471 0 : uno::Reference<lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_QUERY_THROW );
472 0 : uno::Reference< script::XScriptListener > xScriptListener( xServiceManager->createInstanceWithContext( "ooo.vba.EventListener" , mxContext ), uno::UNO_QUERY_THROW );
473 :
474 0 : uno::Reference< beans::XPropertySet > xProps( xScriptListener, uno::UNO_QUERY_THROW );
475 0 : xProps->setPropertyValue( "Model" , uno::makeAny( m_xModel ) );
476 :
477 : // handling for sheet control
478 0 : uno::Reference< msforms::XControl > xThisControl( this );
479 : try
480 : {
481 0 : evt.Arguments.realloc( 1 );
482 0 : lang::EventObject aEvt;
483 :
484 0 : uno::Reference< drawing::XControlShape > xControlShape( m_xControl, uno::UNO_QUERY ) ;
485 0 : uno::Reference< awt::XControl > xControl( m_xControl, uno::UNO_QUERY ) ;
486 :
487 0 : if ( xControlShape.is() )
488 : {
489 0 : evt.Source = xControlShape;
490 0 : aEvt.Source = m_xEmptyFormControl;
491 : // Set up proper scriptcode
492 0 : uno::Reference< lang::XMultiServiceFactory > xDocFac( m_xModel, uno::UNO_QUERY_THROW );
493 0 : uno::Reference< document::XCodeNameQuery > xNameQuery( xDocFac->createInstance( "ooo.vba.VBACodeNameProvider" ), uno::UNO_QUERY_THROW );
494 0 : uno::Reference< uno::XInterface > xIf( xControlShape->getControl(), uno::UNO_QUERY_THROW );
495 0 : evt.ScriptCode = xNameQuery->getCodeNameForObject( xIf );
496 0 : evt.Arguments[ 0 ] = uno::makeAny( aEvt );
497 0 : xScriptListener->firing( evt );
498 : }
499 : else
500 : {
501 0 : if ( xControl.is() ) // normal control ( from dialog/userform )
502 : {
503 : // #FIXME We should probably store a reference to the
504 : // parent dialog/userform here ( other wise the name of
505 : // dialog could be changed and we won't be aware of it.
506 : // ( OTOH this is probably an unlikely scenario )
507 0 : evt.Source = xThisControl;
508 0 : aEvt.Source = xControl;
509 0 : evt.ScriptCode = m_sLibraryAndCodeName;
510 0 : evt.Arguments[ 0 ] = uno::makeAny( aEvt );
511 0 : xScriptListener->firing( evt );
512 : }
513 0 : }
514 : }
515 0 : catch(const uno::Exception&)
516 : {
517 0 : }
518 0 : }
519 0 : void ScVbaControl::fireChangeEvent()
520 : {
521 0 : script::ScriptEvent evt;
522 0 : evt.ScriptType = "VBAInterop";
523 0 : evt.ListenerType = form::XChangeListener::static_type(0);
524 0 : evt.MethodName = "changed";
525 0 : fireEvent( evt );
526 0 : }
527 :
528 0 : void ScVbaControl::fireClickEvent()
529 : {
530 0 : script::ScriptEvent evt;
531 0 : evt.ScriptType = "VBAInterop";
532 0 : evt.ListenerType = awt::XActionListener::static_type(0);
533 0 : evt.MethodName = "actionPerformed";
534 0 : fireEvent( evt );
535 0 : }
536 :
537 0 : sal_Int32 SAL_CALL ScVbaControl::getTabIndex() throw (uno::RuntimeException)
538 : {
539 0 : return 1;
540 : }
541 :
542 0 : void SAL_CALL ScVbaControl::setTabIndex( sal_Int32 /*nTabIndex*/ ) throw (uno::RuntimeException)
543 : {
544 0 : }
545 :
546 : //ScVbaControlFactory
547 :
548 0 : /*static*/ uno::Reference< msforms::XControl > ScVbaControlFactory::createShapeControl(
549 : const uno::Reference< uno::XComponentContext >& xContext,
550 : const uno::Reference< drawing::XControlShape >& xControlShape,
551 : const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException)
552 : {
553 0 : uno::Reference< beans::XPropertySet > xProps( xControlShape->getControl(), uno::UNO_QUERY_THROW );
554 0 : sal_Int32 nClassId = -1;
555 0 : const static OUString sClassId( "ClassId" );
556 0 : xProps->getPropertyValue( sClassId ) >>= nClassId;
557 0 : uno::Reference< XHelperInterface > xVbaParent; // #FIXME - should be worksheet I guess
558 0 : uno::Reference< drawing::XShape > xShape( xControlShape, uno::UNO_QUERY_THROW );
559 0 : ::std::auto_ptr< ConcreteXShapeGeometryAttributes > xGeoHelper( new ConcreteXShapeGeometryAttributes( xContext, xShape ) );
560 0 : switch( nClassId )
561 : {
562 : case form::FormComponentType::COMBOBOX:
563 0 : return new ScVbaComboBox( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() );
564 : case form::FormComponentType::COMMANDBUTTON:
565 0 : return new ScVbaButton( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() );
566 : case form::FormComponentType::FIXEDTEXT:
567 0 : return new ScVbaLabel( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() );
568 : case form::FormComponentType::TEXTFIELD:
569 0 : return new ScVbaTextBox( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() );
570 : case form::FormComponentType::CHECKBOX:
571 0 : return new ScVbaCheckbox( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() );
572 : case form::FormComponentType::RADIOBUTTON:
573 0 : return new ScVbaRadioButton( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() );
574 : case form::FormComponentType::LISTBOX:
575 0 : return new ScVbaListBox( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() );
576 : case form::FormComponentType::SPINBUTTON:
577 0 : return new ScVbaSpinButton( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() );
578 : case form::FormComponentType::IMAGECONTROL:
579 0 : return new ScVbaImage( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() );
580 : case form::FormComponentType::SCROLLBAR:
581 0 : return new ScVbaScrollBar( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() );
582 : }
583 0 : throw uno::RuntimeException( "Unsupported control." , uno::Reference< uno::XInterface >() );
584 : }
585 :
586 0 : /*static*/ uno::Reference< msforms::XControl > ScVbaControlFactory::createUserformControl(
587 : const uno::Reference< uno::XComponentContext >& xContext,
588 : const uno::Reference< awt::XControl >& xControl,
589 : const uno::Reference< awt::XControl >& xDialog,
590 : const uno::Reference< frame::XModel >& xModel,
591 : double fOffsetX, double fOffsetY ) throw (uno::RuntimeException)
592 : {
593 0 : uno::Reference< beans::XPropertySet > xProps( xControl->getModel(), uno::UNO_QUERY_THROW );
594 0 : uno::Reference< lang::XServiceInfo > xServiceInfo( xProps, uno::UNO_QUERY_THROW );
595 0 : uno::Reference< msforms::XControl > xVBAControl;
596 0 : uno::Reference< XHelperInterface > xVbaParent; // #FIXME - should be worksheet I guess
597 0 : ::std::auto_ptr< UserFormGeometryHelper > xGeoHelper( new UserFormGeometryHelper( xContext, xControl, fOffsetX, fOffsetY ) );
598 :
599 0 : if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlCheckBoxModel" ) )
600 0 : xVBAControl.set( new ScVbaCheckbox( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) );
601 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlRadioButtonModel" ) )
602 0 : xVBAControl.set( new ScVbaRadioButton( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) );
603 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlEditModel" ) )
604 0 : xVBAControl.set( new ScVbaTextBox( xVbaParent, xContext, xControl, xModel, xGeoHelper.release(), true ) );
605 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlButtonModel" ) )
606 : {
607 0 : sal_Bool bToggle = sal_False;
608 0 : xProps->getPropertyValue( "Toggle" ) >>= bToggle;
609 0 : if ( bToggle )
610 0 : xVBAControl.set( new ScVbaToggleButton( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) );
611 : else
612 0 : xVBAControl.set( new ScVbaButton( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) );
613 : }
614 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlComboBoxModel" ) )
615 0 : xVBAControl.set( new ScVbaComboBox( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) );
616 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlListBoxModel" ) )
617 0 : xVBAControl.set( new ScVbaListBox( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) );
618 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlFixedTextModel" ) )
619 0 : xVBAControl.set( new ScVbaLabel( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) );
620 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlImageControlModel" ) )
621 0 : xVBAControl.set( new ScVbaImage( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) );
622 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlProgressBarModel" ) )
623 0 : xVBAControl.set( new ScVbaProgressBar( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) );
624 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlGroupBoxModel" ) )
625 0 : xVBAControl.set( new ScVbaFrame( xVbaParent, xContext, xControl, xModel, xGeoHelper.release(), xDialog ) );
626 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlScrollBarModel" ) )
627 0 : xVBAControl.set( new ScVbaScrollBar( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) );
628 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoMultiPageModel" ) )
629 0 : xVBAControl.set( new ScVbaMultiPage( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) );
630 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlSpinButtonModel" ) )
631 0 : xVBAControl.set( new ScVbaSpinButton( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) );
632 0 : else if ( xServiceInfo->supportsService( "com.sun.star.custom.awt.UnoControlSystemAXContainerModel" ) )
633 0 : xVBAControl.set( new VbaSystemAXControl( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) );
634 : // #FIXME implement a page control
635 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoPageModel" ) )
636 0 : xVBAControl.set( new ScVbaControl( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) );
637 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoFrameModel" ) )
638 0 : xVBAControl.set( new ScVbaFrame( xVbaParent, xContext, xControl, xModel, xGeoHelper.release(), xDialog ) );
639 0 : else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlSpinButtonModel" ) )
640 0 : xVBAControl.set( new ScVbaSpinButton( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) );
641 0 : else if ( xServiceInfo->supportsService( "com.sun.star.custom.awt.UnoControlSystemAXContainerModel" ) )
642 0 : xVBAControl.set( new VbaSystemAXControl( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) );
643 0 : if( xVBAControl.is() )
644 0 : return xVBAControl;
645 0 : throw uno::RuntimeException( "Unsupported control." , uno::Reference< uno::XInterface >() );
646 : }
647 :
648 : OUString
649 0 : ScVbaControl::getServiceImplName()
650 : {
651 0 : return OUString("ScVbaControl");
652 : }
653 :
654 : uno::Sequence< OUString >
655 0 : ScVbaControl::getServiceNames()
656 : {
657 0 : static uno::Sequence< OUString > aServiceNames;
658 0 : if ( aServiceNames.getLength() == 0 )
659 : {
660 0 : aServiceNames.realloc( 1 );
661 0 : aServiceNames[ 0 ] = "ooo.vba.excel.Control";
662 : }
663 0 : return aServiceNames;
664 : }
665 :
666 : sal_Int32 nSysCols[] = { 0xC8D0D4, 0x0, 0x6A240A, 0x808080, 0xE4E4E4, 0xFFFFFF, 0x0, 0x0, 0x0, 0xFFFFFF, 0xE4E4E4, 0xE4E4E4, 0x808080, 0x6A240A, 0xFFFFFF, 0xE4E4E4, 0x808080, 0x808080, 0x0, 0xC8D0D4, 0xFFFFFF, 0x404040, 0xE4E4E4, 0x0, 0xE1FFFF };
667 :
668 0 : sal_Int32 ScVbaControl::getBackColor() throw (uno::RuntimeException)
669 : {
670 0 : sal_Int32 nBackColor = 0;
671 0 : m_xProps->getPropertyValue( "BackgroundColor" ) >>= nBackColor;
672 0 : return nBackColor;
673 : }
674 :
675 0 : void ScVbaControl::setBackColor( sal_Int32 nBackColor ) throw (uno::RuntimeException)
676 : {
677 0 : if ( ( nBackColor >= (sal_Int32)0x80000000 ) && ( nBackColor <= (sal_Int32)0x80000018 ) )
678 : {
679 0 : nBackColor = nSysCols[ nBackColor - 0x80000000 ];
680 : }
681 0 : m_xProps->setPropertyValue( "BackgroundColor" , uno::makeAny( XLRGBToOORGB( nBackColor ) ) );
682 0 : }
683 :
684 0 : sal_Bool ScVbaControl::getAutoSize() throw (uno::RuntimeException)
685 : {
686 0 : return sal_False;
687 : }
688 :
689 : // currently no implementation for this
690 0 : void ScVbaControl::setAutoSize( sal_Bool /*bAutoSize*/ ) throw (uno::RuntimeException)
691 : {
692 0 : }
693 :
694 0 : sal_Bool ScVbaControl::getLocked() throw (uno::RuntimeException)
695 : {
696 0 : sal_Bool bRes( sal_False );
697 0 : m_xProps->getPropertyValue( "ReadOnly" ) >>= bRes;
698 0 : return bRes;
699 : }
700 :
701 0 : void ScVbaControl::setLocked( sal_Bool bLocked ) throw (uno::RuntimeException)
702 : {
703 0 : m_xProps->setPropertyValue( "ReadOnly" , uno::makeAny( bLocked ) );
704 0 : }
705 :
706 : typedef cppu::WeakImplHelper1< XControlProvider > ControlProvider_BASE;
707 0 : class ControlProviderImpl : public ControlProvider_BASE
708 : {
709 : uno::Reference< uno::XComponentContext > m_xCtx;
710 : public:
711 0 : ControlProviderImpl( const uno::Reference< uno::XComponentContext >& xCtx ) : m_xCtx( xCtx ) {}
712 : virtual uno::Reference< msforms::XControl > SAL_CALL createControl( const uno::Reference< drawing::XControlShape >& xControl, const uno::Reference< frame::XModel >& xDocOwner ) throw (uno::RuntimeException);
713 : };
714 :
715 : uno::Reference< msforms::XControl > SAL_CALL
716 0 : ControlProviderImpl::createControl( const uno::Reference< drawing::XControlShape >& xControlShape, const uno::Reference< frame::XModel >& xDocOwner ) throw (uno::RuntimeException)
717 : {
718 0 : uno::Reference< msforms::XControl > xControlToReturn;
719 0 : if ( xControlShape.is() )
720 0 : xControlToReturn = ScVbaControlFactory::createShapeControl( m_xCtx, xControlShape, xDocOwner );
721 0 : return xControlToReturn;
722 :
723 : }
724 :
725 : namespace controlprovider
726 : {
727 : namespace sdecl = comphelper::service_decl;
728 0 : sdecl::class_<ControlProviderImpl, sdecl::with_args<false> > serviceImpl;
729 0 : extern sdecl::ServiceDecl const serviceDecl(
730 : serviceImpl,
731 : "ControlProviderImpl",
732 : "ooo.vba.ControlProvider" );
733 0 : }
734 :
735 :
736 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|