1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vbacontrol.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include <com/sun/star/form/FormComponentType.hpp>
31 #include <com/sun/star/awt/XControlModel.hpp>
32 #include <com/sun/star/awt/XControl.hpp>
33 #include <com/sun/star/awt/XWindow2.hpp>
34 #include <com/sun/star/lang/XEventListener.hpp>
35 #include <com/sun/star/drawing/XShape.hpp>
36 #include <com/sun/star/drawing/XControlShape.hpp>
37 #include <com/sun/star/awt/XControl.hpp>
38 #include <com/sun/star/frame/XModel.hpp>
39 #include <com/sun/star/view/XControlAccess.hpp>
40 #include <com/sun/star/container/XChild.hpp>
41 #include <com/sun/star/form/binding/XBindableValue.hpp>
42 #include <com/sun/star/form/binding/XListEntrySink.hpp>
43 #include <com/sun/star/table/CellAddress.hpp>
44 #include <com/sun/star/table/CellRangeAddress.hpp>
45 #include <ooo/vba/XControlProvider.hpp>
46 #ifdef VBA_OOBUILD_HACK
47 #include <svtools/bindablecontrolhelper.hxx>
49 #include"vbacontrol.hxx"
50 #include"vbacombobox.hxx"
51 #include "vbabutton.hxx"
52 #include "vbalabel.hxx"
53 #include "vbatextbox.hxx"
54 #include "vbaradiobutton.hxx"
55 #include "vbalistbox.hxx"
56 #include "vbatogglebutton.hxx"
57 #include "vbacheckbox.hxx"
58 #include "vbaframe.hxx"
59 #include "vbascrollbar.hxx"
60 #include "vbaprogressbar.hxx"
61 #include "vbamultipage.hxx"
62 #include "vbaspinbutton.hxx"
63 #include "vbaimage.hxx"
64 #include <vbahelper/helperdecl.hxx>
67 using namespace com::sun::star
;
68 using namespace ooo::vba
;
70 uno::Reference
< css::awt::XWindowPeer
>
71 ScVbaControl::getWindowPeer() throw (uno::RuntimeException
)
73 uno::Reference
< drawing::XControlShape
> xControlShape( m_xControl
, uno::UNO_QUERY
);
75 uno::Reference
< awt::XControlModel
> xControlModel
;
76 uno::Reference
< css::awt::XWindowPeer
> xWinPeer
;
77 if ( !xControlShape
.is() )
79 // would seem to be a Userform control
80 uno::Reference
< awt::XControl
> xControl( m_xControl
, uno::UNO_QUERY_THROW
);
81 xWinPeer
= xControl
->getPeer();
85 xControlModel
.set( xControlShape
->getControl(), uno::UNO_QUERY_THROW
);
87 uno::Reference
< view::XControlAccess
> xControlAccess( m_xModel
->getCurrentController(), uno::UNO_QUERY_THROW
);
90 uno::Reference
< awt::XControl
> xControl( xControlAccess
->getControl( xControlModel
), uno::UNO_QUERY
);
91 xWinPeer
= xControl
->getPeer();
93 catch( uno::Exception
)
95 throw uno::RuntimeException( rtl::OUString::createFromAscii( "The Control does not exsit" ),
96 uno::Reference
< uno::XInterface
>() );
101 //ScVbaControlListener
102 class ScVbaControlListener
: public cppu::WeakImplHelper1
< lang::XEventListener
>
105 ScVbaControl
*pControl
;
107 ScVbaControlListener( ScVbaControl
*pTmpControl
);
108 virtual ~ScVbaControlListener();
109 virtual void SAL_CALL
disposing( const lang::EventObject
& rEventObject
) throw( uno::RuntimeException
);
112 ScVbaControlListener::ScVbaControlListener( ScVbaControl
*pTmpControl
): pControl( pTmpControl
)
116 ScVbaControlListener::~ScVbaControlListener()
121 ScVbaControlListener::disposing( const lang::EventObject
& ) throw( uno::RuntimeException
)
125 pControl
->removeResouce();
132 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
)
135 m_xEventListener
.set( new ScVbaControlListener( this ) );
136 setGeometryHelper( pGeomHelper
);
137 uno::Reference
< lang::XComponent
> xComponent( m_xControl
, uno::UNO_QUERY_THROW
);
138 xComponent
->addEventListener( m_xEventListener
);
141 uno::Reference
< drawing::XControlShape
> xControlShape( m_xControl
, uno::UNO_QUERY
) ;
142 uno::Reference
< awt::XControl
> xUserFormControl( m_xControl
, uno::UNO_QUERY
) ;
143 if ( xControlShape
.is() ) // form control
144 m_xProps
.set( xControlShape
->getControl(), uno::UNO_QUERY_THROW
);
145 else if ( xUserFormControl
.is() ) // userform control
146 m_xProps
.set( xUserFormControl
->getModel(), uno::UNO_QUERY_THROW
);
149 ScVbaControl::~ScVbaControl()
151 if( m_xControl
.is() )
153 uno::Reference
< lang::XComponent
> xComponent( m_xControl
, uno::UNO_QUERY_THROW
);
154 xComponent
->removeEventListener( m_xEventListener
);
159 ScVbaControl::setGeometryHelper( AbstractGeometryAttributes
* pHelper
)
161 mpGeometryHelper
.reset( pHelper
);
164 void ScVbaControl::removeResouce() throw( uno::RuntimeException
)
166 uno::Reference
< lang::XComponent
> xComponent( m_xControl
, uno::UNO_QUERY_THROW
);
167 xComponent
->removeEventListener( m_xEventListener
);
172 //In design model has different behavior
173 sal_Bool SAL_CALL
ScVbaControl::getEnabled() throw (uno::RuntimeException
)
175 uno::Any aValue
= m_xProps
->getPropertyValue
176 (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Enabled" ) ) );
177 sal_Bool bRet
= false;
182 void SAL_CALL
ScVbaControl::setEnabled( sal_Bool bVisible
) throw (uno::RuntimeException
)
184 uno::Any
aValue( bVisible
);
185 m_xProps
->setPropertyValue
186 (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Enabled" ) ), aValue
);
190 sal_Bool SAL_CALL
ScVbaControl::getVisible() throw (uno::RuntimeException
)
192 sal_Bool
bVisible( sal_True
);
193 m_xProps
->getPropertyValue
194 (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EnableVisible" ) )) >>= bVisible
;
198 void SAL_CALL
ScVbaControl::setVisible( sal_Bool bVisible
) throw (uno::RuntimeException
)
200 uno::Any
aValue( bVisible
);
201 m_xProps
->setPropertyValue
202 (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EnableVisible" ) ), aValue
);
204 double SAL_CALL
ScVbaControl::getHeight() throw (uno::RuntimeException
)
206 return mpGeometryHelper
->getHeight();
208 void SAL_CALL
ScVbaControl::setHeight( double _height
) throw (uno::RuntimeException
)
210 mpGeometryHelper
->setHeight( _height
);
213 double SAL_CALL
ScVbaControl::getWidth() throw (uno::RuntimeException
)
215 return mpGeometryHelper
->getWidth();
217 void SAL_CALL
ScVbaControl::setWidth( double _width
) throw (uno::RuntimeException
)
219 mpGeometryHelper
->setWidth( _width
);
223 ScVbaControl::getLeft() throw (uno::RuntimeException
)
225 return mpGeometryHelper
->getLeft();
229 ScVbaControl::setLeft( double _left
) throw (uno::RuntimeException
)
231 mpGeometryHelper
->setLeft( _left
);
236 ScVbaControl::getTop() throw (uno::RuntimeException
)
238 return mpGeometryHelper
->getTop();
242 ScVbaControl::setTop( double _top
) throw (uno::RuntimeException
)
244 mpGeometryHelper
->setTop( _top
);
247 uno::Reference
< uno::XInterface
> SAL_CALL
248 ScVbaControl::getObject() throw (uno::RuntimeException
)
250 uno::Reference
< msforms::XControl
> xRet( this );
254 void SAL_CALL
ScVbaControl::SetFocus() throw (uno::RuntimeException
)
256 uno::Reference
< awt::XWindow
> xWin( m_xControl
, uno::UNO_QUERY_THROW
);
260 rtl::OUString SAL_CALL
261 ScVbaControl::getControlSource() throw (uno::RuntimeException
)
263 // #FIXME I *hate* having these upstream differences
264 // but this is necessary until I manage to upstream other
266 #ifdef VBA_OOBUILD_HACK
267 rtl::OUString sControlSource
;
268 uno::Reference
< form::binding::XBindableValue
> xBindable( m_xProps
, uno::UNO_QUERY
);
269 if ( xBindable
.is() )
273 uno::Reference
< lang::XMultiServiceFactory
> xFac( m_xModel
, uno::UNO_QUERY_THROW
);
274 uno::Reference
< beans::XPropertySet
> xConvertor( xFac
->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.table.CellAddressConversion" ))), uno::UNO_QUERY
);
275 uno::Reference
< beans::XPropertySet
> xProps( xBindable
->getValueBinding(), uno::UNO_QUERY_THROW
);
276 table::CellAddress aAddress
;
277 xProps
->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BoundCell") ) ) >>= aAddress
;
278 xConvertor
->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Address") ), uno::makeAny( aAddress
) );
279 xConvertor
->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("XL_A1_Representation") ) ) >>= sControlSource
;
281 catch( uno::Exception
& )
285 return sControlSource
;
287 throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("getControlSource not supported") ), uno::Reference
< uno::XInterface
>()); // not supported
292 ScVbaControl::setControlSource( const rtl::OUString
& _controlsource
) throw (uno::RuntimeException
)
294 #ifdef VBA_OOBUILD_HACK
295 rtl::OUString sEmpty
;
296 svt::BindableControlHelper::ApplyListSourceAndBindableData( m_xModel
, m_xProps
, _controlsource
, sEmpty
);
298 throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("setControlSource not supported ") ).concat( _controlsource
), uno::Reference
< uno::XInterface
>()); // not supported
302 rtl::OUString SAL_CALL
303 ScVbaControl::getRowSource() throw (uno::RuntimeException
)
305 #ifdef VBA_OOBUILD_HACK
306 rtl::OUString sRowSource
;
307 uno::Reference
< form::binding::XListEntrySink
> xListSink( m_xProps
, uno::UNO_QUERY
);
308 if ( xListSink
.is() )
312 uno::Reference
< lang::XMultiServiceFactory
> xFac( m_xModel
, uno::UNO_QUERY_THROW
);
313 uno::Reference
< beans::XPropertySet
> xConvertor( xFac
->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.table.CellRangeAddressConversion" ))), uno::UNO_QUERY
);
315 uno::Reference
< beans::XPropertySet
> xProps( xListSink
->getListEntrySource(), uno::UNO_QUERY_THROW
);
316 table::CellRangeAddress aAddress
;
317 xProps
->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CellRange") ) ) >>= aAddress
;
318 xConvertor
->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Address")), uno::makeAny( aAddress
) );
319 xConvertor
->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("XL_A1_Representation") ) ) >>= sRowSource
;
321 catch( uno::Exception
& )
327 throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("getRowSource not supported") ), uno::Reference
< uno::XInterface
>()); // not supported
332 ScVbaControl::setRowSource( const rtl::OUString
& _rowsource
) throw (uno::RuntimeException
)
334 #ifdef VBA_OOBUILD_HACK
335 rtl::OUString sEmpty
;
336 svt::BindableControlHelper::ApplyListSourceAndBindableData( m_xModel
, m_xProps
, sEmpty
, _rowsource
);
338 throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("setRowSource not supported ") ).concat( _rowsource
), uno::Reference
< uno::XInterface
>()); // not supported
342 rtl::OUString SAL_CALL
343 ScVbaControl::getName() throw (uno::RuntimeException
)
346 m_xProps
->getPropertyValue
347 (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ) ) >>= sName
;
353 ScVbaControl::setName( const rtl::OUString
& _name
) throw (uno::RuntimeException
)
355 m_xProps
->setPropertyValue
356 (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ), uno::makeAny( _name
) );
359 rtl::OUString SAL_CALL
360 ScVbaControl::getControlTipText() throw (css::uno::RuntimeException
)
363 m_xProps
->getPropertyValue
364 (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HelpText" ) ) ) >>= sName
;
369 ScVbaControl::setControlTipText( const rtl::OUString
& rsToolTip
) throw (css::uno::RuntimeException
)
371 m_xProps
->setPropertyValue
372 (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HelpText" ) ), uno::makeAny( rsToolTip
) );
374 //ScVbaControlFactory
376 ScVbaControlFactory::ScVbaControlFactory( const uno::Reference
< uno::XComponentContext
>& xContext
, const uno::Reference
< uno::XInterface
>& xControl
, const uno::Reference
< frame::XModel
>& xModel
): m_xContext( xContext
), m_xControl( xControl
), m_xModel( xModel
)
380 ScVbaControl
* ScVbaControlFactory::createControl() throw (uno::RuntimeException
)
382 return createControl( m_xModel
);
384 ScVbaControl
* ScVbaControlFactory::createControl( const uno::Reference
< uno::XInterface
>& xParent
) throw (uno::RuntimeException
)
386 uno::Reference
< drawing::XControlShape
> xControlShape( m_xControl
, uno::UNO_QUERY
);
387 if ( xControlShape
.is() ) // form controls
388 return createControl( xControlShape
, xParent
);
389 uno::Reference
< awt::XControl
> xControl( m_xControl
, uno::UNO_QUERY
);
390 if ( !xControl
.is() )
391 throw uno::RuntimeException(); // really we should be more informative
392 return createControl( xControl
, xParent
);
396 ScVbaControl
* ScVbaControlFactory::createControl(const uno::Reference
< drawing::XControlShape
>& xControlShape
, const uno::Reference
< uno::XInterface
>& /*xParent*/ ) throw (uno::RuntimeException
)
398 uno::Reference
< beans::XPropertySet
> xProps( xControlShape
->getControl(), uno::UNO_QUERY_THROW
);
399 sal_Int32 nClassId
= -1;
400 const static rtl::OUString
sClassId( RTL_CONSTASCII_USTRINGPARAM("ClassId") );
401 xProps
->getPropertyValue( sClassId
) >>= nClassId
;
402 uno::Reference
< XHelperInterface
> xVbaParent
; // #FIXME - should be worksheet I guess
403 sal_Bool bToggle
= sal_False
; //liuchen 2009-8-11,
406 case form::FormComponentType::COMBOBOX
:
407 return new ScVbaComboBox( xVbaParent
, m_xContext
, xControlShape
, m_xModel
, new ConcreteXShapeGeometryAttributes( m_xContext
, uno::Reference
< drawing::XShape
>( xControlShape
, uno::UNO_QUERY_THROW
) ) );
408 case form::FormComponentType::COMMANDBUTTON
:
410 xProps
->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Toggle") ) ) >>= bToggle
;
412 return new ScVbaToggleButton( xVbaParent
, m_xContext
, xControlShape
, m_xModel
, new ConcreteXShapeGeometryAttributes( m_xContext
, uno::Reference
< drawing::XShape
>( xControlShape
, uno::UNO_QUERY_THROW
) ) );
414 return new ScVbaButton( xVbaParent
, m_xContext
, xControlShape
, m_xModel
, new ConcreteXShapeGeometryAttributes( m_xContext
, uno::Reference
< drawing::XShape
>( xControlShape
, uno::UNO_QUERY_THROW
) ) );
416 case form::FormComponentType::FIXEDTEXT
:
417 return new ScVbaLabel( xVbaParent
, m_xContext
, xControlShape
, m_xModel
, new ConcreteXShapeGeometryAttributes( m_xContext
, uno::Reference
< drawing::XShape
>( xControlShape
, uno::UNO_QUERY_THROW
) ) );
418 case form::FormComponentType::TEXTFIELD
:
419 return new ScVbaTextBox( xVbaParent
, m_xContext
, xControlShape
, m_xModel
, new ConcreteXShapeGeometryAttributes( m_xContext
, uno::Reference
< drawing::XShape
>( xControlShape
, uno::UNO_QUERY_THROW
) ) );
420 case form::FormComponentType::CHECKBOX
:
421 return new ScVbaCheckbox( xVbaParent
, m_xContext
, xControlShape
, m_xModel
, new ConcreteXShapeGeometryAttributes( m_xContext
, uno::Reference
< drawing::XShape
>( xControlShape
, uno::UNO_QUERY_THROW
) ) );
422 case form::FormComponentType::RADIOBUTTON
:
423 return new ScVbaRadioButton( xVbaParent
, m_xContext
, xControlShape
, m_xModel
, new ConcreteXShapeGeometryAttributes( m_xContext
, uno::Reference
< drawing::XShape
>( xControlShape
, uno::UNO_QUERY_THROW
) ) );
424 case form::FormComponentType::LISTBOX
:
425 return new ScVbaListBox( xVbaParent
, m_xContext
, xControlShape
, m_xModel
, new ConcreteXShapeGeometryAttributes( m_xContext
, uno::Reference
< drawing::XShape
>( xControlShape
, uno::UNO_QUERY_THROW
) ) );
426 case form::FormComponentType::SPINBUTTON
:
427 return new ScVbaSpinButton( xVbaParent
, m_xContext
, xControlShape
, m_xModel
, new ConcreteXShapeGeometryAttributes( m_xContext
, uno::Reference
< drawing::XShape
>( xControlShape
, uno::UNO_QUERY_THROW
) ) );
428 case form::FormComponentType::IMAGECONTROL
:
429 return new ScVbaImage( xVbaParent
, m_xContext
, xControlShape
, m_xModel
, new ConcreteXShapeGeometryAttributes( m_xContext
, uno::Reference
< drawing::XShape
>( xControlShape
, uno::UNO_QUERY_THROW
) ) );
431 throw uno::RuntimeException( rtl::OUString::createFromAscii(
432 "Donot support this Control Type." ), uno::Reference
< uno::XInterface
>() );
436 ScVbaControl
* ScVbaControlFactory::createControl( const uno::Reference
< awt::XControl
>& xControl
, const uno::Reference
< uno::XInterface
>& xParent
) throw (uno::RuntimeException
)
438 uno::Reference
< beans::XPropertySet
> xProps( xControl
->getModel(), uno::UNO_QUERY_THROW
);
439 uno::Reference
< lang::XServiceInfo
> xServiceInfo( xProps
, uno::UNO_QUERY_THROW
);
440 ScVbaControl
* pControl
= NULL
;
441 uno::Reference
< XHelperInterface
> xVbaParent
; // #FIXME - should be worksheet I guess
442 if ( xServiceInfo
->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlCheckBoxModel") ) ) )
443 pControl
= new ScVbaCheckbox( xVbaParent
, m_xContext
, xControl
, m_xModel
, new UserFormGeometryHelper( m_xContext
, xControl
) );
444 else if ( xServiceInfo
->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlRadioButtonModel") ) ) )
445 pControl
= new ScVbaRadioButton( xVbaParent
, m_xContext
, xControl
, m_xModel
, new UserFormGeometryHelper( m_xContext
, xControl
) );
446 else if ( xServiceInfo
->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlEditModel") ) ) )
447 pControl
= new ScVbaTextBox( xVbaParent
, m_xContext
, xControl
, m_xModel
, new UserFormGeometryHelper( m_xContext
, xControl
), true );
448 else if ( xServiceInfo
->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlButtonModel") ) ) )
450 sal_Bool bToggle
= sal_False
;
451 xProps
->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Toggle") ) ) >>= bToggle
;
453 pControl
= new ScVbaToggleButton( xVbaParent
, m_xContext
, xControl
, m_xModel
, new UserFormGeometryHelper( m_xContext
, xControl
) );
455 pControl
= new ScVbaButton( xVbaParent
, m_xContext
, xControl
, m_xModel
, new UserFormGeometryHelper( m_xContext
, xControl
) );
457 else if ( xServiceInfo
->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlComboBoxModel") ) ) )
458 pControl
= new ScVbaComboBox( xVbaParent
, m_xContext
, xControl
, m_xModel
, new UserFormGeometryHelper( m_xContext
, xControl
), true );
459 else if ( xServiceInfo
->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlListBoxModel") ) ) )
460 pControl
= new ScVbaListBox( xVbaParent
, m_xContext
, xControl
, m_xModel
, new UserFormGeometryHelper( m_xContext
, xControl
) );
461 else if ( xServiceInfo
->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlFixedTextModel") ) ) )
462 pControl
= new ScVbaLabel( xVbaParent
, m_xContext
, xControl
, m_xModel
, new UserFormGeometryHelper( m_xContext
, xControl
) );
463 else if ( xServiceInfo
->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlImageControlModel") ) ) )
464 pControl
= new ScVbaImage( xVbaParent
, m_xContext
, xControl
, m_xModel
, new UserFormGeometryHelper( m_xContext
, xControl
) );
465 else if ( xServiceInfo
->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlProgressBarModel") ) ) )
466 pControl
= new ScVbaProgressBar( xVbaParent
, m_xContext
, xControl
, m_xModel
, new UserFormGeometryHelper( m_xContext
, xControl
) );
467 else if ( xServiceInfo
->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlGroupBoxModel") ) ) )
468 pControl
= new ScVbaFrame( xVbaParent
, m_xContext
, xControl
, m_xModel
, new UserFormGeometryHelper( m_xContext
, xControl
) );
469 else if ( xServiceInfo
->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlScrollBarModel") ) ) )
470 pControl
= new ScVbaScrollBar( xVbaParent
, m_xContext
, xControl
, m_xModel
, new UserFormGeometryHelper( m_xContext
, xControl
) );
471 else if ( xServiceInfo
->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoMultiPageModel") ) ) )
472 pControl
= new ScVbaMultiPage( xVbaParent
, m_xContext
, xControl
, m_xModel
, new UserFormGeometryHelper( m_xContext
, xControl
), xParent
);
473 else if ( xServiceInfo
->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlSpinButtonModel") ) ) )
474 pControl
= new ScVbaSpinButton( xVbaParent
, m_xContext
, xControl
, m_xModel
, new UserFormGeometryHelper( m_xContext
, xControl
) );
476 throw uno::RuntimeException( rtl::OUString::createFromAscii("Unsupported control " ), uno::Reference
< uno::XInterface
>() );
481 ScVbaControl::getServiceImplName()
483 static rtl::OUString
sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaControl") );
487 uno::Sequence
< rtl::OUString
>
488 ScVbaControl::getServiceNames()
490 static uno::Sequence
< rtl::OUString
> aServiceNames
;
491 if ( aServiceNames
.getLength() == 0 )
493 aServiceNames
.realloc( 1 );
494 aServiceNames
[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Control" ) );
496 return aServiceNames
;
501 typedef cppu::WeakImplHelper1
< XControlProvider
> ControlProvider_BASE
;
502 class ControlProviderImpl
: public ControlProvider_BASE
504 uno::Reference
< uno::XComponentContext
> m_xCtx
;
506 ControlProviderImpl( const uno::Reference
< uno::XComponentContext
>& xCtx
) : m_xCtx( xCtx
) {}
507 virtual uno::Reference
< msforms::XControl
> SAL_CALL
createControl( const uno::Reference
< drawing::XControlShape
>& xControl
, const uno::Reference
< frame::XModel
>& xDocOwner
) throw (uno::RuntimeException
);
508 virtual uno::Reference
< msforms::XControl
> SAL_CALL
createUserformControl( const uno::Reference
< awt::XControl
>& xControl
, const uno::Reference
< awt::XControl
>& xDialog
, const uno::Reference
< frame::XModel
>& xDocOwner
) throw (uno::RuntimeException
);
511 uno::Reference
< msforms::XControl
> SAL_CALL
512 ControlProviderImpl::createControl( const uno::Reference
< drawing::XControlShape
>& xControlShape
, const uno::Reference
< frame::XModel
>& xDocOwner
) throw (uno::RuntimeException
)
514 uno::Reference
< msforms::XControl
> xControlToReturn
;
515 if ( xControlShape
.is() )
517 ScVbaControlFactory
controlFactory( m_xCtx
, xControlShape
, xDocOwner
);
518 xControlToReturn
.set( controlFactory
.createControl( xDocOwner
) );
520 return xControlToReturn
;
523 uno::Reference
< msforms::XControl
> SAL_CALL
524 ControlProviderImpl::createUserformControl( const uno::Reference
< awt::XControl
>& xControl
, const uno::Reference
< awt::XControl
>& xDialog
, const uno::Reference
< frame::XModel
>& xDocOwner
) throw (uno::RuntimeException
)
526 uno::Reference
< msforms::XControl
> xControlToReturn
;
527 if ( xControl
.is() && xDialog
.is() )
530 ScVbaControlFactory
controlFactory( m_xCtx
, xControl
, xDocOwner
);
531 xControlToReturn
.set( controlFactory
.createControl( xDialog
->getModel() ) );
532 ScVbaControl
* pControl
= dynamic_cast< ScVbaControl
* >( xControlToReturn
.get() );
533 pControl
->setGeometryHelper( new UserFormGeometryHelper( m_xCtx
, xControl
) );
535 return xControlToReturn
;
538 namespace controlprovider
540 namespace sdecl
= comphelper::service_decl
;
541 sdecl::class_
<ControlProviderImpl
, sdecl::with_args
<false> > serviceImpl
;
542 extern sdecl::ServiceDecl
const serviceDecl(
544 "ControlProviderImpl",
545 "ooo.vba.ControlProvider" );