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