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