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 > 65 ScVbaControl::getWindowPeer() 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 exist" ), 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 ); 104 }; 105 106 ScVbaControlListener::ScVbaControlListener( ScVbaControl *pTmpControl ): pControl( pTmpControl ) 107 { 108 } 109 110 ScVbaControlListener::~ScVbaControlListener() 111 { 112 } 113 114 void SAL_CALL 115 ScVbaControlListener::disposing( const lang::EventObject& ) 116 { 117 if( pControl ) 118 { 119 pControl->removeResouce(); 120 pControl = NULL; 121 } 122 } 123 124 //ScVbaControl 125 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 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 153 ScVbaControl::setGeometryHelper( AbstractGeometryAttributes* pHelper ) 154 { 155 mpGeometryHelper.reset( pHelper ); 156 } 157 158 void ScVbaControl::removeResouce() 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 167 sal_Bool SAL_CALL ScVbaControl::getEnabled() 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 176 void SAL_CALL ScVbaControl::setEnabled( sal_Bool bVisible ) 177 { 178 uno::Any aValue( bVisible ); 179 m_xProps->setPropertyValue 180 (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Enabled" ) ), aValue); 181 182 } 183 184 sal_Bool SAL_CALL ScVbaControl::getVisible() 185 { 186 sal_Bool bVisible( sal_True ); 187 m_xProps->getPropertyValue 188 (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EnableVisible" ) )) >>= bVisible; 189 return bVisible; 190 } 191 192 void SAL_CALL ScVbaControl::setVisible( sal_Bool bVisible ) 193 { 194 uno::Any aValue( bVisible ); 195 m_xProps->setPropertyValue 196 (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EnableVisible" ) ), aValue); 197 } 198 double SAL_CALL ScVbaControl::getHeight() 199 { 200 return mpGeometryHelper->getHeight(); 201 } 202 void SAL_CALL ScVbaControl::setHeight( double _height ) 203 { 204 mpGeometryHelper->setHeight( _height ); 205 } 206 207 double SAL_CALL ScVbaControl::getWidth() 208 { 209 return mpGeometryHelper->getWidth(); 210 } 211 void SAL_CALL ScVbaControl::setWidth( double _width ) 212 { 213 mpGeometryHelper->setWidth( _width ); 214 } 215 216 double SAL_CALL 217 ScVbaControl::getLeft() 218 { 219 return mpGeometryHelper->getLeft(); 220 } 221 222 void SAL_CALL 223 ScVbaControl::setLeft( double _left ) 224 { 225 mpGeometryHelper->setLeft( _left ); 226 } 227 228 double SAL_CALL 229 ScVbaControl::getTop() 230 { 231 return mpGeometryHelper->getTop(); 232 } 233 234 void SAL_CALL 235 ScVbaControl::setTop( double _top ) 236 { 237 mpGeometryHelper->setTop( _top ); 238 } 239 240 uno::Reference< uno::XInterface > SAL_CALL 241 ScVbaControl::getObject() 242 { 243 uno::Reference< msforms::XControl > xRet( this ); 244 return xRet; 245 } 246 247 void SAL_CALL ScVbaControl::SetFocus() 248 { 249 uno::Reference< awt::XWindow > xWin( m_xControl, uno::UNO_QUERY_THROW ); 250 xWin->setFocus(); 251 } 252 253 void SAL_CALL ScVbaControl::Move( double Left, double Top, const uno::Any& Width, const uno::Any& Height ) 254 { 255 double nWidth = 0.0; 256 double nHeight = 0.0; 257 258 setLeft( Left ); 259 setTop( Top ); 260 261 if ( Width >>= nWidth ) 262 setWidth( nWidth ); 263 264 if ( Height >>= nHeight ) 265 setHeight( nHeight ); 266 } 267 268 rtl::OUString SAL_CALL 269 ScVbaControl::getControlSource() 270 { 271 // #FIXME I *hate* having these upstream differences 272 // but this is necessary until I manage to upstream other 273 // dependent parts 274 #ifdef VBA_OOBUILD_HACK 275 rtl::OUString sControlSource; 276 uno::Reference< form::binding::XBindableValue > xBindable( m_xProps, uno::UNO_QUERY ); 277 if ( xBindable.is() ) 278 { 279 try 280 { 281 uno::Reference< lang::XMultiServiceFactory > xFac( m_xModel, uno::UNO_QUERY_THROW ); 282 uno::Reference< beans::XPropertySet > xConvertor( xFac->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.table.CellAddressConversion" ))), uno::UNO_QUERY ); 283 uno::Reference< beans::XPropertySet > xProps( xBindable->getValueBinding(), uno::UNO_QUERY_THROW ); 284 table::CellAddress aAddress; 285 xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BoundCell") ) ) >>= aAddress; 286 xConvertor->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Address") ), uno::makeAny( aAddress ) ); 287 xConvertor->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("XL_A1_Representation") ) ) >>= sControlSource; 288 } 289 catch( uno::Exception& ) 290 { 291 } 292 } 293 return sControlSource; 294 #else 295 throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("getControlSource not supported") ), uno::Reference< uno::XInterface >()); // not supported 296 #endif 297 } 298 299 void SAL_CALL 300 ScVbaControl::setControlSource( const rtl::OUString& _controlsource ) 301 { 302 #ifdef VBA_OOBUILD_HACK 303 rtl::OUString sEmpty; 304 svt::BindableControlHelper::ApplyListSourceAndBindableData( m_xModel, m_xProps, _controlsource, sEmpty ); 305 #else 306 throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("setControlSource not supported ") ).concat( _controlsource ), uno::Reference< uno::XInterface >()); // not supported 307 #endif 308 } 309 310 rtl::OUString SAL_CALL 311 ScVbaControl::getRowSource() 312 { 313 #ifdef VBA_OOBUILD_HACK 314 rtl::OUString sRowSource; 315 uno::Reference< form::binding::XListEntrySink > xListSink( m_xProps, uno::UNO_QUERY ); 316 if ( xListSink.is() ) 317 { 318 try 319 { 320 uno::Reference< lang::XMultiServiceFactory > xFac( m_xModel, uno::UNO_QUERY_THROW ); 321 uno::Reference< beans::XPropertySet > xConvertor( xFac->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.table.CellRangeAddressConversion" ))), uno::UNO_QUERY ); 322 323 uno::Reference< beans::XPropertySet > xProps( xListSink->getListEntrySource(), uno::UNO_QUERY_THROW ); 324 table::CellRangeAddress aAddress; 325 xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CellRange") ) ) >>= aAddress; 326 xConvertor->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Address")), uno::makeAny( aAddress ) ); 327 xConvertor->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("XL_A1_Representation") ) ) >>= sRowSource; 328 } 329 catch( uno::Exception& ) 330 { 331 } 332 } 333 return sRowSource; 334 #else 335 throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("getRowSource not supported") ), uno::Reference< uno::XInterface >()); // not supported 336 #endif 337 } 338 339 void SAL_CALL 340 ScVbaControl::setRowSource( const rtl::OUString& _rowsource ) 341 { 342 #ifdef VBA_OOBUILD_HACK 343 rtl::OUString sEmpty; 344 svt::BindableControlHelper::ApplyListSourceAndBindableData( m_xModel, m_xProps, sEmpty, _rowsource ); 345 #else 346 throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("setRowSource not supported ") ).concat( _rowsource ), uno::Reference< uno::XInterface >()); // not supported 347 #endif 348 } 349 350 rtl::OUString SAL_CALL 351 ScVbaControl::getName() 352 { 353 rtl::OUString sName; 354 m_xProps->getPropertyValue 355 (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ) ) >>= sName; 356 return sName; 357 358 } 359 360 void SAL_CALL 361 ScVbaControl::setName( const rtl::OUString& _name ) 362 { 363 m_xProps->setPropertyValue 364 (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ), uno::makeAny( _name ) ); 365 } 366 367 rtl::OUString SAL_CALL 368 ScVbaControl::getControlTipText() 369 { 370 rtl::OUString sName; 371 m_xProps->getPropertyValue 372 (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HelpText" ) ) ) >>= sName; 373 return sName; 374 } 375 376 void SAL_CALL 377 ScVbaControl::setControlTipText( const rtl::OUString& rsToolTip ) 378 { 379 m_xProps->setPropertyValue 380 (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HelpText" ) ), uno::makeAny( rsToolTip ) ); 381 } 382 383 ::rtl::OUString SAL_CALL ScVbaControl::getTag() 384 { 385 return m_aControlTag; 386 } 387 388 void SAL_CALL ScVbaControl::setTag( const ::rtl::OUString& aTag ) 389 { 390 m_aControlTag = aTag; 391 } 392 393 sal_Int32 SAL_CALL ScVbaControl::getTabIndex() 394 { 395 return 1; 396 } 397 398 void SAL_CALL ScVbaControl::setTabIndex( sal_Int32 /*nTabIndex*/ ) 399 { 400 } 401 402 //ScVbaControlFactory 403 404 /*static*/ uno::Reference< msforms::XControl > ScVbaControlFactory::createShapeControl( 405 const uno::Reference< uno::XComponentContext >& xContext, 406 const uno::Reference< drawing::XControlShape >& xControlShape, 407 const uno::Reference< frame::XModel >& xModel ) 408 { 409 uno::Reference< beans::XPropertySet > xProps( xControlShape->getControl(), uno::UNO_QUERY_THROW ); 410 sal_Int32 nClassId = -1; 411 const static rtl::OUString sClassId( RTL_CONSTASCII_USTRINGPARAM("ClassId") ); 412 xProps->getPropertyValue( sClassId ) >>= nClassId; 413 uno::Reference< XHelperInterface > xVbaParent; // #FIXME - should be worksheet I guess 414 uno::Reference< drawing::XShape > xShape( xControlShape, uno::UNO_QUERY_THROW ); 415 ::std::auto_ptr< ConcreteXShapeGeometryAttributes > xGeoHelper( new ConcreteXShapeGeometryAttributes( xContext, xShape ) ); 416 417 switch( nClassId ) 418 { 419 case form::FormComponentType::COMBOBOX: 420 return new ScVbaComboBox( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() ); 421 case form::FormComponentType::COMMANDBUTTON: 422 return new ScVbaButton( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() ); 423 case form::FormComponentType::FIXEDTEXT: 424 return new ScVbaLabel( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() ); 425 case form::FormComponentType::TEXTFIELD: 426 return new ScVbaTextBox( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() ); 427 case form::FormComponentType::RADIOBUTTON: 428 return new ScVbaRadioButton( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() ); 429 case form::FormComponentType::LISTBOX: 430 return new ScVbaListBox( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() ); 431 case form::FormComponentType::SPINBUTTON: 432 return new ScVbaSpinButton( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() ); 433 case form::FormComponentType::IMAGECONTROL: 434 return new ScVbaImage( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() ); 435 } 436 throw uno::RuntimeException( rtl::OUString::createFromAscii("Unsupported control." ), uno::Reference< uno::XInterface >() ); 437 } 438 439 /*static*/ uno::Reference< msforms::XControl > ScVbaControlFactory::createUserformControl( 440 const uno::Reference< uno::XComponentContext >& xContext, 441 const uno::Reference< awt::XControl >& xControl, 442 const uno::Reference< awt::XControl >& xDialog, 443 const uno::Reference< frame::XModel >& xModel, 444 double fOffsetX, double fOffsetY ) 445 { 446 uno::Reference< beans::XPropertySet > xProps( xControl->getModel(), uno::UNO_QUERY_THROW ); 447 uno::Reference< lang::XServiceInfo > xServiceInfo( xProps, uno::UNO_QUERY_THROW ); 448 uno::Reference< msforms::XControl > xVBAControl; 449 uno::Reference< XHelperInterface > xVbaParent; // #FIXME - should be worksheet I guess 450 ::std::auto_ptr< UserFormGeometryHelper > xGeoHelper( new UserFormGeometryHelper( xContext, xControl, fOffsetX, fOffsetY ) ); 451 452 if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlCheckBoxModel") ) ) ) 453 xVBAControl.set( new ScVbaCheckbox( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) ); 454 else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlRadioButtonModel") ) ) ) 455 xVBAControl.set( new ScVbaRadioButton( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) ); 456 else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlEditModel") ) ) ) 457 xVBAControl.set( new ScVbaTextBox( xVbaParent, xContext, xControl, xModel, xGeoHelper.release(), true ) ); 458 else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlButtonModel") ) ) ) 459 { 460 sal_Bool bToggle = sal_False; 461 xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Toggle") ) ) >>= bToggle; 462 if ( bToggle ) 463 xVBAControl.set( new ScVbaToggleButton( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) ); 464 else 465 xVBAControl.set( new ScVbaButton( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) ); 466 } 467 else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlComboBoxModel") ) ) ) 468 xVBAControl.set( new ScVbaComboBox( xVbaParent, xContext, xControl, xModel, xGeoHelper.release(), true ) ); 469 else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlListBoxModel") ) ) ) 470 xVBAControl.set( new ScVbaListBox( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) ); 471 else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlFixedTextModel") ) ) ) 472 xVBAControl.set( new ScVbaLabel( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) ); 473 else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlImageControlModel") ) ) ) 474 xVBAControl.set( new ScVbaImage( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) ); 475 else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlProgressBarModel") ) ) ) 476 xVBAControl.set( new ScVbaProgressBar( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) ); 477 else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlGroupBoxModel") ) ) ) 478 xVBAControl.set( new ScVbaFrame( xVbaParent, xContext, xControl, xModel, xGeoHelper.release(), xDialog ) ); 479 else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlScrollBarModel") ) ) ) 480 xVBAControl.set( new ScVbaScrollBar( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) ); 481 else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoMultiPageModel") ) ) ) 482 xVBAControl.set( new ScVbaMultiPage( xVbaParent, xContext, xControl, xModel, xGeoHelper.release(), xDialog ) ); 483 else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlSpinButtonModel") ) ) ) 484 xVBAControl.set( new ScVbaSpinButton( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) ); 485 else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.custom.awt.UnoControlSystemAXContainerModel") ) ) ) 486 xVBAControl.set( new VbaSystemAXControl( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) ); 487 488 if( xVBAControl.is() ) 489 return xVBAControl; 490 throw uno::RuntimeException( rtl::OUString::createFromAscii("Unsupported control." ), uno::Reference< uno::XInterface >() ); 491 } 492 493 rtl::OUString& 494 ScVbaControl::getServiceImplName() 495 { 496 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaControl") ); 497 return sImplName; 498 } 499 500 uno::Sequence< rtl::OUString > 501 ScVbaControl::getServiceNames() 502 { 503 static uno::Sequence< rtl::OUString > aServiceNames; 504 if ( aServiceNames.getLength() == 0 ) 505 { 506 aServiceNames.realloc( 1 ); 507 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Control" ) ); 508 } 509 return aServiceNames; 510 } 511 512 513 514 typedef cppu::WeakImplHelper1< XControlProvider > ControlProvider_BASE; 515 class ControlProviderImpl : public ControlProvider_BASE 516 { 517 uno::Reference< uno::XComponentContext > m_xCtx; 518 public: 519 ControlProviderImpl( const uno::Reference< uno::XComponentContext >& xCtx ) : m_xCtx( xCtx ) {} 520 virtual uno::Reference< msforms::XControl > SAL_CALL createControl( const uno::Reference< drawing::XControlShape >& xControl, const uno::Reference< frame::XModel >& xDocOwner ); 521 }; 522 523 uno::Reference< msforms::XControl > SAL_CALL 524 ControlProviderImpl::createControl( const uno::Reference< drawing::XControlShape >& xControlShape, const uno::Reference< frame::XModel >& xDocOwner ) 525 { 526 uno::Reference< msforms::XControl > xControlToReturn; 527 if ( xControlShape.is() ) 528 xControlToReturn = ScVbaControlFactory::createShapeControl( m_xCtx, xControlShape, xDocOwner ); 529 return xControlToReturn; 530 531 } 532 533 namespace controlprovider 534 { 535 namespace sdecl = comphelper::service_decl; 536 sdecl::class_<ControlProviderImpl, sdecl::with_args<false> > serviceImpl; 537 extern sdecl::ServiceDecl const serviceDecl( 538 serviceImpl, 539 "ControlProviderImpl", 540 "ooo.vba.ControlProvider" ); 541 } 542