1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23 #include <com/sun/star/form/FormComponentType.hpp>
24 #include <com/sun/star/awt/XControlModel.hpp>
25 #include <com/sun/star/awt/XControl.hpp>
26 #include <com/sun/star/awt/XWindow2.hpp>
27 #include <com/sun/star/lang/XEventListener.hpp>
28 #include <com/sun/star/drawing/XShape.hpp>
29 #include <com/sun/star/drawing/XControlShape.hpp>
30 #include <com/sun/star/awt/XControl.hpp>
31 #include <com/sun/star/frame/XModel.hpp>
32 #include <com/sun/star/view/XControlAccess.hpp>
33 #include <com/sun/star/container/XChild.hpp>
34 #include <com/sun/star/form/binding/XBindableValue.hpp>
35 #include <com/sun/star/form/binding/XListEntrySink.hpp>
36 #include <com/sun/star/table/CellAddress.hpp>
37 #include <com/sun/star/table/CellRangeAddress.hpp>
38 #include <ooo/vba/XControlProvider.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
60
61 using namespace com::sun::star;
62 using namespace ooo::vba;
63
64 uno::Reference< css::awt::XWindowPeer >
getWindowPeer()65 ScVbaControl::getWindowPeer() throw (uno::RuntimeException)
66 {
67 uno::Reference< drawing::XControlShape > xControlShape( m_xControl, uno::UNO_QUERY );
68
69 uno::Reference< awt::XControlModel > xControlModel;
70 uno::Reference< css::awt::XWindowPeer > xWinPeer;
71 if ( !xControlShape.is() )
72 {
73 // would seem to be a Userform control
74 uno::Reference< awt::XControl > xControl( m_xControl, uno::UNO_QUERY_THROW );
75 xWinPeer = xControl->getPeer();
76 return xWinPeer;
77 }
78 // form control
79 xControlModel.set( xControlShape->getControl(), uno::UNO_QUERY_THROW );
80
81 uno::Reference< view::XControlAccess > xControlAccess( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW );
82 try
83 {
84 uno::Reference< awt::XControl > xControl( xControlAccess->getControl( xControlModel ), uno::UNO_QUERY );
85 xWinPeer = xControl->getPeer();
86 }
87 catch( uno::Exception )
88 {
89 throw uno::RuntimeException( rtl::OUString::createFromAscii( "The Control does not exsit" ),
90 uno::Reference< uno::XInterface >() );
91 }
92 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
ScVbaControlListener(ScVbaControl * pTmpControl)106 ScVbaControlListener::ScVbaControlListener( ScVbaControl *pTmpControl ): pControl( pTmpControl )
107 {
108 }
109
~ScVbaControlListener()110 ScVbaControlListener::~ScVbaControlListener()
111 {
112 }
113
114 void SAL_CALL
disposing(const lang::EventObject &)115 ScVbaControlListener::disposing( const lang::EventObject& ) throw( uno::RuntimeException )
116 {
117 if( pControl )
118 {
119 pControl->removeResouce();
120 pControl = NULL;
121 }
122 }
123
124 //ScVbaControl
125
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)126 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 ), m_xControl( xControl ), m_xModel( xModel )
127 {
128 //add listener
129 m_xEventListener.set( new ScVbaControlListener( this ) );
130 setGeometryHelper( pGeomHelper );
131 uno::Reference< lang::XComponent > xComponent( m_xControl, uno::UNO_QUERY_THROW );
132 xComponent->addEventListener( m_xEventListener );
133
134 //init m_xProps
135 uno::Reference< drawing::XControlShape > xControlShape( m_xControl, uno::UNO_QUERY ) ;
136 uno::Reference< awt::XControl> xUserFormControl( m_xControl, uno::UNO_QUERY ) ;
137 if ( xControlShape.is() ) // form control
138 m_xProps.set( xControlShape->getControl(), uno::UNO_QUERY_THROW );
139 else if ( xUserFormControl.is() ) // userform control
140 m_xProps.set( xUserFormControl->getModel(), uno::UNO_QUERY_THROW );
141 }
142
~ScVbaControl()143 ScVbaControl::~ScVbaControl()
144 {
145 if( m_xControl.is() )
146 {
147 uno::Reference< lang::XComponent > xComponent( m_xControl, uno::UNO_QUERY_THROW );
148 xComponent->removeEventListener( m_xEventListener );
149 }
150 }
151
152 void
setGeometryHelper(AbstractGeometryAttributes * pHelper)153 ScVbaControl::setGeometryHelper( AbstractGeometryAttributes* pHelper )
154 {
155 mpGeometryHelper.reset( pHelper );
156 }
157
removeResouce()158 void ScVbaControl::removeResouce() throw( uno::RuntimeException )
159 {
160 uno::Reference< lang::XComponent > xComponent( m_xControl, uno::UNO_QUERY_THROW );
161 xComponent->removeEventListener( m_xEventListener );
162 m_xControl= NULL;
163 m_xProps = NULL;
164 }
165
166 //In design model has different behavior
getEnabled()167 sal_Bool SAL_CALL ScVbaControl::getEnabled() throw (uno::RuntimeException)
168 {
169 uno::Any aValue = m_xProps->getPropertyValue
170 (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Enabled" ) ) );
171 sal_Bool bRet = false;
172 aValue >>= bRet;
173 return bRet;
174 }
175
setEnabled(sal_Bool bVisible)176 void SAL_CALL ScVbaControl::setEnabled( sal_Bool bVisible ) throw (uno::RuntimeException)
177 {
178 uno::Any aValue( bVisible );
179 m_xProps->setPropertyValue
180 (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Enabled" ) ), aValue);
181
182 }
183
getVisible()184 sal_Bool SAL_CALL ScVbaControl::getVisible() throw (uno::RuntimeException)
185 {
186 sal_Bool bVisible( sal_True );
187 m_xProps->getPropertyValue
188 (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EnableVisible" ) )) >>= bVisible;
189 return bVisible;
190 }
191
setVisible(sal_Bool bVisible)192 void SAL_CALL ScVbaControl::setVisible( sal_Bool bVisible ) throw (uno::RuntimeException)
193 {
194 uno::Any aValue( bVisible );
195 m_xProps->setPropertyValue
196 (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EnableVisible" ) ), aValue);
197 }
getHeight()198 double SAL_CALL ScVbaControl::getHeight() throw (uno::RuntimeException)
199 {
200 return mpGeometryHelper->getHeight();
201 }
setHeight(double _height)202 void SAL_CALL ScVbaControl::setHeight( double _height ) throw (uno::RuntimeException)
203 {
204 mpGeometryHelper->setHeight( _height );
205 }
206
getWidth()207 double SAL_CALL ScVbaControl::getWidth() throw (uno::RuntimeException)
208 {
209 return mpGeometryHelper->getWidth();
210 }
setWidth(double _width)211 void SAL_CALL ScVbaControl::setWidth( double _width ) throw (uno::RuntimeException)
212 {
213 mpGeometryHelper->setWidth( _width );
214 }
215
216 double SAL_CALL
getLeft()217 ScVbaControl::getLeft() throw (uno::RuntimeException)
218 {
219 return mpGeometryHelper->getLeft();
220 }
221
222 void SAL_CALL
setLeft(double _left)223 ScVbaControl::setLeft( double _left ) throw (uno::RuntimeException)
224 {
225 mpGeometryHelper->setLeft( _left );
226 }
227
228 double SAL_CALL
getTop()229 ScVbaControl::getTop() throw (uno::RuntimeException)
230 {
231 return mpGeometryHelper->getTop();
232 }
233
234 void SAL_CALL
setTop(double _top)235 ScVbaControl::setTop( double _top ) throw (uno::RuntimeException)
236 {
237 mpGeometryHelper->setTop( _top );
238 }
239
240 uno::Reference< uno::XInterface > SAL_CALL
getObject()241 ScVbaControl::getObject() throw (uno::RuntimeException)
242 {
243 uno::Reference< msforms::XControl > xRet( this );
244 return xRet;
245 }
246
SetFocus()247 void SAL_CALL ScVbaControl::SetFocus() throw (uno::RuntimeException)
248 {
249 uno::Reference< awt::XWindow > xWin( m_xControl, uno::UNO_QUERY_THROW );
250 xWin->setFocus();
251 }
252
Move(double Left,double Top,const uno::Any & Width,const uno::Any & Height)253 void SAL_CALL ScVbaControl::Move( double Left, double Top, const uno::Any& Width, const uno::Any& Height )
254 throw ( uno::RuntimeException )
255 {
256 double nWidth = 0.0;
257 double nHeight = 0.0;
258
259 setLeft( Left );
260 setTop( Top );
261
262 if ( Width >>= nWidth )
263 setWidth( nWidth );
264
265 if ( Height >>= nHeight )
266 setHeight( nHeight );
267 }
268
269 rtl::OUString SAL_CALL
getControlSource()270 ScVbaControl::getControlSource() throw (uno::RuntimeException)
271 {
272 // #FIXME I *hate* having these upstream differences
273 // but this is necessary until I manage to upstream other
274 // dependant parts
275 #ifdef VBA_OOBUILD_HACK
276 rtl::OUString sControlSource;
277 uno::Reference< form::binding::XBindableValue > xBindable( m_xProps, uno::UNO_QUERY );
278 if ( xBindable.is() )
279 {
280 try
281 {
282 uno::Reference< lang::XMultiServiceFactory > xFac( m_xModel, uno::UNO_QUERY_THROW );
283 uno::Reference< beans::XPropertySet > xConvertor( xFac->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.table.CellAddressConversion" ))), uno::UNO_QUERY );
284 uno::Reference< beans::XPropertySet > xProps( xBindable->getValueBinding(), uno::UNO_QUERY_THROW );
285 table::CellAddress aAddress;
286 xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BoundCell") ) ) >>= aAddress;
287 xConvertor->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Address") ), uno::makeAny( aAddress ) );
288 xConvertor->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("XL_A1_Representation") ) ) >>= sControlSource;
289 }
290 catch( uno::Exception& )
291 {
292 }
293 }
294 return sControlSource;
295 #else
296 throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("getControlSource not supported") ), uno::Reference< uno::XInterface >()); // not supported
297 #endif
298 }
299
300 void SAL_CALL
setControlSource(const rtl::OUString & _controlsource)301 ScVbaControl::setControlSource( const rtl::OUString& _controlsource ) throw (uno::RuntimeException)
302 {
303 #ifdef VBA_OOBUILD_HACK
304 rtl::OUString sEmpty;
305 svt::BindableControlHelper::ApplyListSourceAndBindableData( m_xModel, m_xProps, _controlsource, sEmpty );
306 #else
307 throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("setControlSource not supported ") ).concat( _controlsource ), uno::Reference< uno::XInterface >()); // not supported
308 #endif
309 }
310
311 rtl::OUString SAL_CALL
getRowSource()312 ScVbaControl::getRowSource() throw (uno::RuntimeException)
313 {
314 #ifdef VBA_OOBUILD_HACK
315 rtl::OUString sRowSource;
316 uno::Reference< form::binding::XListEntrySink > xListSink( m_xProps, uno::UNO_QUERY );
317 if ( xListSink.is() )
318 {
319 try
320 {
321 uno::Reference< lang::XMultiServiceFactory > xFac( m_xModel, uno::UNO_QUERY_THROW );
322 uno::Reference< beans::XPropertySet > xConvertor( xFac->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.table.CellRangeAddressConversion" ))), uno::UNO_QUERY );
323
324 uno::Reference< beans::XPropertySet > xProps( xListSink->getListEntrySource(), uno::UNO_QUERY_THROW );
325 table::CellRangeAddress aAddress;
326 xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CellRange") ) ) >>= aAddress;
327 xConvertor->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Address")), uno::makeAny( aAddress ) );
328 xConvertor->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("XL_A1_Representation") ) ) >>= sRowSource;
329 }
330 catch( uno::Exception& )
331 {
332 }
333 }
334 return sRowSource;
335 #else
336 throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("getRowSource not supported") ), uno::Reference< uno::XInterface >()); // not supported
337 #endif
338 }
339
340 void SAL_CALL
setRowSource(const rtl::OUString & _rowsource)341 ScVbaControl::setRowSource( const rtl::OUString& _rowsource ) throw (uno::RuntimeException)
342 {
343 #ifdef VBA_OOBUILD_HACK
344 rtl::OUString sEmpty;
345 svt::BindableControlHelper::ApplyListSourceAndBindableData( m_xModel, m_xProps, sEmpty, _rowsource );
346 #else
347 throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("setRowSource not supported ") ).concat( _rowsource ), uno::Reference< uno::XInterface >()); // not supported
348 #endif
349 }
350
351 rtl::OUString SAL_CALL
getName()352 ScVbaControl::getName() throw (uno::RuntimeException)
353 {
354 rtl::OUString sName;
355 m_xProps->getPropertyValue
356 (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ) ) >>= sName;
357 return sName;
358
359 }
360
361 void SAL_CALL
setName(const rtl::OUString & _name)362 ScVbaControl::setName( const rtl::OUString& _name ) throw (uno::RuntimeException)
363 {
364 m_xProps->setPropertyValue
365 (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ), uno::makeAny( _name ) );
366 }
367
368 rtl::OUString SAL_CALL
getControlTipText()369 ScVbaControl::getControlTipText() throw (css::uno::RuntimeException)
370 {
371 rtl::OUString sName;
372 m_xProps->getPropertyValue
373 (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HelpText" ) ) ) >>= sName;
374 return sName;
375 }
376
377 void SAL_CALL
setControlTipText(const rtl::OUString & rsToolTip)378 ScVbaControl::setControlTipText( const rtl::OUString& rsToolTip ) throw (css::uno::RuntimeException)
379 {
380 m_xProps->setPropertyValue
381 (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HelpText" ) ), uno::makeAny( rsToolTip ) );
382 }
383
getTag()384 ::rtl::OUString SAL_CALL ScVbaControl::getTag()
385 throw (css::uno::RuntimeException)
386 {
387 return m_aControlTag;
388 }
389
setTag(const::rtl::OUString & aTag)390 void SAL_CALL ScVbaControl::setTag( const ::rtl::OUString& aTag )
391 throw (css::uno::RuntimeException)
392 {
393 m_aControlTag = aTag;
394 }
395
getTabIndex()396 sal_Int32 SAL_CALL ScVbaControl::getTabIndex() throw (uno::RuntimeException)
397 {
398 return 1;
399 }
400
setTabIndex(sal_Int32)401 void SAL_CALL ScVbaControl::setTabIndex( sal_Int32 /*nTabIndex*/ ) throw (uno::RuntimeException)
402 {
403 }
404
405 //ScVbaControlFactory
406
createShapeControl(const uno::Reference<uno::XComponentContext> & xContext,const uno::Reference<drawing::XControlShape> & xControlShape,const uno::Reference<frame::XModel> & xModel)407 /*static*/ uno::Reference< msforms::XControl > ScVbaControlFactory::createShapeControl(
408 const uno::Reference< uno::XComponentContext >& xContext,
409 const uno::Reference< drawing::XControlShape >& xControlShape,
410 const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException)
411 {
412 uno::Reference< beans::XPropertySet > xProps( xControlShape->getControl(), uno::UNO_QUERY_THROW );
413 sal_Int32 nClassId = -1;
414 const static rtl::OUString sClassId( RTL_CONSTASCII_USTRINGPARAM("ClassId") );
415 xProps->getPropertyValue( sClassId ) >>= nClassId;
416 uno::Reference< XHelperInterface > xVbaParent; // #FIXME - should be worksheet I guess
417 uno::Reference< drawing::XShape > xShape( xControlShape, uno::UNO_QUERY_THROW );
418 ::std::auto_ptr< ConcreteXShapeGeometryAttributes > xGeoHelper( new ConcreteXShapeGeometryAttributes( xContext, xShape ) );
419
420 switch( nClassId )
421 {
422 case form::FormComponentType::COMBOBOX:
423 return new ScVbaComboBox( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() );
424 case form::FormComponentType::COMMANDBUTTON:
425 return new ScVbaButton( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() );
426 case form::FormComponentType::FIXEDTEXT:
427 return new ScVbaLabel( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() );
428 case form::FormComponentType::TEXTFIELD:
429 return new ScVbaTextBox( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() );
430 case form::FormComponentType::RADIOBUTTON:
431 return new ScVbaRadioButton( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() );
432 case form::FormComponentType::LISTBOX:
433 return new ScVbaListBox( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() );
434 case form::FormComponentType::SPINBUTTON:
435 return new ScVbaSpinButton( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() );
436 case form::FormComponentType::IMAGECONTROL:
437 return new ScVbaImage( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() );
438 }
439 throw uno::RuntimeException( rtl::OUString::createFromAscii("Unsupported control." ), uno::Reference< uno::XInterface >() );
440 }
441
createUserformControl(const uno::Reference<uno::XComponentContext> & xContext,const uno::Reference<awt::XControl> & xControl,const uno::Reference<awt::XControl> & xDialog,const uno::Reference<frame::XModel> & xModel,double fOffsetX,double fOffsetY)442 /*static*/ uno::Reference< msforms::XControl > ScVbaControlFactory::createUserformControl(
443 const uno::Reference< uno::XComponentContext >& xContext,
444 const uno::Reference< awt::XControl >& xControl,
445 const uno::Reference< awt::XControl >& xDialog,
446 const uno::Reference< frame::XModel >& xModel,
447 double fOffsetX, double fOffsetY ) throw (uno::RuntimeException)
448 {
449 uno::Reference< beans::XPropertySet > xProps( xControl->getModel(), uno::UNO_QUERY_THROW );
450 uno::Reference< lang::XServiceInfo > xServiceInfo( xProps, uno::UNO_QUERY_THROW );
451 uno::Reference< msforms::XControl > xVBAControl;
452 uno::Reference< XHelperInterface > xVbaParent; // #FIXME - should be worksheet I guess
453 ::std::auto_ptr< UserFormGeometryHelper > xGeoHelper( new UserFormGeometryHelper( xContext, xControl, fOffsetX, fOffsetY ) );
454
455 if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlCheckBoxModel") ) ) )
456 xVBAControl.set( new ScVbaCheckbox( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) );
457 else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlRadioButtonModel") ) ) )
458 xVBAControl.set( new ScVbaRadioButton( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) );
459 else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlEditModel") ) ) )
460 xVBAControl.set( new ScVbaTextBox( xVbaParent, xContext, xControl, xModel, xGeoHelper.release(), true ) );
461 else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlButtonModel") ) ) )
462 {
463 sal_Bool bToggle = sal_False;
464 xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Toggle") ) ) >>= bToggle;
465 if ( bToggle )
466 xVBAControl.set( new ScVbaToggleButton( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) );
467 else
468 xVBAControl.set( new ScVbaButton( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) );
469 }
470 else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlComboBoxModel") ) ) )
471 xVBAControl.set( new ScVbaComboBox( xVbaParent, xContext, xControl, xModel, xGeoHelper.release(), true ) );
472 else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlListBoxModel") ) ) )
473 xVBAControl.set( new ScVbaListBox( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) );
474 else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlFixedTextModel") ) ) )
475 xVBAControl.set( new ScVbaLabel( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) );
476 else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlImageControlModel") ) ) )
477 xVBAControl.set( new ScVbaImage( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) );
478 else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlProgressBarModel") ) ) )
479 xVBAControl.set( new ScVbaProgressBar( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) );
480 else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlGroupBoxModel") ) ) )
481 xVBAControl.set( new ScVbaFrame( xVbaParent, xContext, xControl, xModel, xGeoHelper.release(), xDialog ) );
482 else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlScrollBarModel") ) ) )
483 xVBAControl.set( new ScVbaScrollBar( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) );
484 else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoMultiPageModel") ) ) )
485 xVBAControl.set( new ScVbaMultiPage( xVbaParent, xContext, xControl, xModel, xGeoHelper.release(), xDialog ) );
486 else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlSpinButtonModel") ) ) )
487 xVBAControl.set( new ScVbaSpinButton( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) );
488 else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.custom.awt.UnoControlSystemAXContainerModel") ) ) )
489 xVBAControl.set( new VbaSystemAXControl( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) );
490
491 if( xVBAControl.is() )
492 return xVBAControl;
493 throw uno::RuntimeException( rtl::OUString::createFromAscii("Unsupported control." ), uno::Reference< uno::XInterface >() );
494 }
495
496 rtl::OUString&
getServiceImplName()497 ScVbaControl::getServiceImplName()
498 {
499 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaControl") );
500 return sImplName;
501 }
502
503 uno::Sequence< rtl::OUString >
getServiceNames()504 ScVbaControl::getServiceNames()
505 {
506 static uno::Sequence< rtl::OUString > aServiceNames;
507 if ( aServiceNames.getLength() == 0 )
508 {
509 aServiceNames.realloc( 1 );
510 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Control" ) );
511 }
512 return aServiceNames;
513 }
514
515
516
517 typedef cppu::WeakImplHelper1< XControlProvider > ControlProvider_BASE;
518 class ControlProviderImpl : public ControlProvider_BASE
519 {
520 uno::Reference< uno::XComponentContext > m_xCtx;
521 public:
ControlProviderImpl(const uno::Reference<uno::XComponentContext> & xCtx)522 ControlProviderImpl( const uno::Reference< uno::XComponentContext >& xCtx ) : m_xCtx( xCtx ) {}
523 virtual uno::Reference< msforms::XControl > SAL_CALL createControl( const uno::Reference< drawing::XControlShape >& xControl, const uno::Reference< frame::XModel >& xDocOwner ) throw (uno::RuntimeException);
524 };
525
526 uno::Reference< msforms::XControl > SAL_CALL
createControl(const uno::Reference<drawing::XControlShape> & xControlShape,const uno::Reference<frame::XModel> & xDocOwner)527 ControlProviderImpl::createControl( const uno::Reference< drawing::XControlShape >& xControlShape, const uno::Reference< frame::XModel >& xDocOwner ) throw (uno::RuntimeException)
528 {
529 uno::Reference< msforms::XControl > xControlToReturn;
530 if ( xControlShape.is() )
531 xControlToReturn = ScVbaControlFactory::createShapeControl( m_xCtx, xControlShape, xDocOwner );
532 return xControlToReturn;
533
534 }
535
536 namespace controlprovider
537 {
538 namespace sdecl = comphelper::service_decl;
539 sdecl::class_<ControlProviderImpl, sdecl::with_args<false> > serviceImpl;
540 extern sdecl::ServiceDecl const serviceDecl(
541 serviceImpl,
542 "ControlProviderImpl",
543 "ooo.vba.ControlProvider" );
544 }
545
546
547