1*e6ed5fbcSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*e6ed5fbcSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*e6ed5fbcSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*e6ed5fbcSAndrew Rist * distributed with this work for additional information 6*e6ed5fbcSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*e6ed5fbcSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*e6ed5fbcSAndrew Rist * "License"); you may not use this file except in compliance 9*e6ed5fbcSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*e6ed5fbcSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*e6ed5fbcSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*e6ed5fbcSAndrew Rist * software distributed under the License is distributed on an 15*e6ed5fbcSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*e6ed5fbcSAndrew Rist * KIND, either express or implied. See the License for the 17*e6ed5fbcSAndrew Rist * specific language governing permissions and limitations 18*e6ed5fbcSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*e6ed5fbcSAndrew Rist *************************************************************/ 21*e6ed5fbcSAndrew Rist 22*e6ed5fbcSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include <com/sun/star/awt/XControl.hpp> 25cdf0e10cSrcweir #include <com/sun/star/awt/XControlContainer.hpp> 26cdf0e10cSrcweir #include <com/sun/star/awt/FontWeight.hpp> 27cdf0e10cSrcweir #include <com/sun/star/awt/FontSlant.hpp> 28cdf0e10cSrcweir #include <com/sun/star/awt/FontStrikeout.hpp> 29cdf0e10cSrcweir #include <com/sun/star/awt/FontUnderline.hpp> 30cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp> 31cdf0e10cSrcweir #include <com/sun/star/script/XInvocation.hpp> 32cdf0e10cSrcweir #include <com/sun/star/lang/WrappedTargetException.hpp> 33cdf0e10cSrcweir 34cdf0e10cSrcweir #include "vbacontrols.hxx" 35cdf0e10cSrcweir #include "vbacontrol.hxx" 36cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx> 37cdf0e10cSrcweir #include <ooo/vba/XControlProvider.hpp> 38cdf0e10cSrcweir #include <hash_map> 39cdf0e10cSrcweir 40cdf0e10cSrcweir using namespace com::sun::star; 41cdf0e10cSrcweir using namespace ooo::vba; 42cdf0e10cSrcweir 43cdf0e10cSrcweir 44cdf0e10cSrcweir typedef ::cppu::WeakImplHelper2< container::XNameAccess, container::XIndexAccess > ArrayWrapImpl; 45cdf0e10cSrcweir 46cdf0e10cSrcweir typedef std::hash_map< rtl::OUString, sal_Int32, ::rtl::OUStringHash, 47cdf0e10cSrcweir ::std::equal_to< ::rtl::OUString > > ControlIndexMap; 48cdf0e10cSrcweir typedef std::vector< uno::Reference< awt::XControl > > ControlVec; 49cdf0e10cSrcweir 50cdf0e10cSrcweir class ControlArrayWrapper : public ArrayWrapImpl 51cdf0e10cSrcweir { 52cdf0e10cSrcweir uno::Reference< awt::XControlContainer > mxDialog; 53cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > msNames; 54cdf0e10cSrcweir ControlVec mControls; 55cdf0e10cSrcweir ControlIndexMap mIndices; 56cdf0e10cSrcweir 57cdf0e10cSrcweir private: 58cdf0e10cSrcweir void SetArrayElementTo( const uno::Reference< awt::XControl >& xCtrl, sal_Int32 nIndex = -1 ) 59cdf0e10cSrcweir { 60cdf0e10cSrcweir // initialize the element with specified index to the control 61cdf0e10cSrcweir if ( xCtrl.is() ) 62cdf0e10cSrcweir { 63cdf0e10cSrcweir if ( nIndex == -1 ) 64cdf0e10cSrcweir nIndex = msNames.getLength(); 65cdf0e10cSrcweir 66cdf0e10cSrcweir if ( nIndex >= msNames.getLength() ) 67cdf0e10cSrcweir msNames.realloc( nIndex ); 68cdf0e10cSrcweir 69cdf0e10cSrcweir msNames[ nIndex ] = getControlName( xCtrl ); 70cdf0e10cSrcweir mControls.push_back( xCtrl ); 71cdf0e10cSrcweir mIndices[ msNames[ nIndex ] ] = nIndex; 72cdf0e10cSrcweir } 73cdf0e10cSrcweir } 74cdf0e10cSrcweir 75cdf0e10cSrcweir public: 76cdf0e10cSrcweir ControlArrayWrapper( const uno::Reference< awt::XControl >& xDialog ) 77cdf0e10cSrcweir { 78cdf0e10cSrcweir try 79cdf0e10cSrcweir { 80cdf0e10cSrcweir mxDialog.set( xDialog, uno::UNO_QUERY_THROW ); 81cdf0e10cSrcweir uno::Sequence< uno::Reference< awt::XControl > > sXControls = mxDialog->getControls(); 82cdf0e10cSrcweir 83cdf0e10cSrcweir msNames.realloc( sXControls.getLength() ); 84cdf0e10cSrcweir for ( sal_Int32 i = 0; i < sXControls.getLength(); ++i ) 85cdf0e10cSrcweir SetArrayElementTo( sXControls[ i ], i ); 86cdf0e10cSrcweir } 87cdf0e10cSrcweir catch( uno::Exception& ) 88cdf0e10cSrcweir { 89cdf0e10cSrcweir // accept the case when the dialog already does not exist 90cdf0e10cSrcweir // in this case the wrapper should work in dummy mode 91cdf0e10cSrcweir } 92cdf0e10cSrcweir } 93cdf0e10cSrcweir 94cdf0e10cSrcweir static rtl::OUString getControlName( const uno::Reference< awt::XControl >& xCtrl ) 95cdf0e10cSrcweir { 96cdf0e10cSrcweir if ( !xCtrl.is() ) 97cdf0e10cSrcweir throw uno::RuntimeException(); 98cdf0e10cSrcweir 99cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xProp( xCtrl->getModel(), uno::UNO_QUERY_THROW ); 100cdf0e10cSrcweir rtl::OUString sName; 101cdf0e10cSrcweir xProp->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ) ) >>= sName; 102cdf0e10cSrcweir return sName; 103cdf0e10cSrcweir } 104cdf0e10cSrcweir 105cdf0e10cSrcweir 106cdf0e10cSrcweir // XElementAccess 107cdf0e10cSrcweir virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException) 108cdf0e10cSrcweir { 109cdf0e10cSrcweir return awt::XControl::static_type(0); 110cdf0e10cSrcweir } 111cdf0e10cSrcweir 112cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException) 113cdf0e10cSrcweir { 114cdf0e10cSrcweir return ( mControls.size() > 0 ); 115cdf0e10cSrcweir } 116cdf0e10cSrcweir 117cdf0e10cSrcweir // XNameAcess 118cdf0e10cSrcweir virtual uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) 119cdf0e10cSrcweir { 120cdf0e10cSrcweir if ( !hasByName( aName ) ) 121cdf0e10cSrcweir throw container::NoSuchElementException(); 122cdf0e10cSrcweir return getByIndex( mIndices[ aName ] ); 123cdf0e10cSrcweir } 124cdf0e10cSrcweir 125cdf0e10cSrcweir virtual uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) throw (uno::RuntimeException) 126cdf0e10cSrcweir { 127cdf0e10cSrcweir return msNames; 128cdf0e10cSrcweir } 129cdf0e10cSrcweir 130cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (css::uno::RuntimeException) 131cdf0e10cSrcweir { 132cdf0e10cSrcweir ControlIndexMap::iterator it = mIndices.find( aName ); 133cdf0e10cSrcweir return it != mIndices.end(); 134cdf0e10cSrcweir } 135cdf0e10cSrcweir 136cdf0e10cSrcweir // XElementAccess 137cdf0e10cSrcweir virtual ::sal_Int32 SAL_CALL getCount( ) throw (css::uno::RuntimeException) 138cdf0e10cSrcweir { 139cdf0e10cSrcweir return mControls.size(); 140cdf0e10cSrcweir } 141cdf0e10cSrcweir 142cdf0e10cSrcweir virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException ) 143cdf0e10cSrcweir { 144cdf0e10cSrcweir if ( Index < 0 || Index >= static_cast< sal_Int32 >( mControls.size() ) ) 145cdf0e10cSrcweir throw lang::IndexOutOfBoundsException(); 146cdf0e10cSrcweir return uno::makeAny( mControls[ Index ] ); 147cdf0e10cSrcweir } 148cdf0e10cSrcweir }; 149cdf0e10cSrcweir 150cdf0e10cSrcweir 151cdf0e10cSrcweir class ControlsEnumWrapper : public EnumerationHelper_BASE 152cdf0e10cSrcweir { 153cdf0e10cSrcweir uno::Reference<XHelperInterface > m_xParent; 154cdf0e10cSrcweir uno::Reference<uno::XComponentContext > m_xContext; 155cdf0e10cSrcweir uno::Reference<container::XIndexAccess > m_xIndexAccess; 156cdf0e10cSrcweir uno::Reference<awt::XControl > m_xDlg; 157cdf0e10cSrcweir uno::Reference< frame::XModel > m_xModel; 158cdf0e10cSrcweir double mfOffsetX; 159cdf0e10cSrcweir double mfOffsetY; 160cdf0e10cSrcweir sal_Int32 nIndex; 161cdf0e10cSrcweir 162cdf0e10cSrcweir public: 163cdf0e10cSrcweir 164cdf0e10cSrcweir ControlsEnumWrapper( 165cdf0e10cSrcweir const uno::Reference< XHelperInterface >& xParent, 166cdf0e10cSrcweir const uno::Reference< uno::XComponentContext >& xContext, 167cdf0e10cSrcweir const uno::Reference< container::XIndexAccess >& xIndexAccess, 168cdf0e10cSrcweir const uno::Reference< awt::XControl >& xDlg, 169cdf0e10cSrcweir const uno::Reference< frame::XModel >& xModel, 170cdf0e10cSrcweir double fOffsetX, double fOffsetY ) : 171cdf0e10cSrcweir m_xParent( xParent ), 172cdf0e10cSrcweir m_xContext( xContext), 173cdf0e10cSrcweir m_xIndexAccess( xIndexAccess ), 174cdf0e10cSrcweir m_xDlg( xDlg ), 175cdf0e10cSrcweir m_xModel( xModel ), 176cdf0e10cSrcweir mfOffsetX( fOffsetX ), 177cdf0e10cSrcweir mfOffsetY( fOffsetY ), 178cdf0e10cSrcweir nIndex( 0 ) {} 179cdf0e10cSrcweir 180cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException) 181cdf0e10cSrcweir { 182cdf0e10cSrcweir return ( nIndex < m_xIndexAccess->getCount() ); 183cdf0e10cSrcweir } 184cdf0e10cSrcweir 185cdf0e10cSrcweir virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) 186cdf0e10cSrcweir { 187cdf0e10cSrcweir if ( nIndex < m_xIndexAccess->getCount() ) 188cdf0e10cSrcweir { 189cdf0e10cSrcweir uno::Reference< awt::XControl > xControl; 190cdf0e10cSrcweir m_xIndexAccess->getByIndex( nIndex++ ) >>= xControl; 191cdf0e10cSrcweir 192cdf0e10cSrcweir uno::Reference< msforms::XControl > xVBAControl; 193cdf0e10cSrcweir if ( xControl.is() && m_xDlg.is() ) 194cdf0e10cSrcweir xVBAControl = ScVbaControlFactory::createUserformControl( m_xContext, xControl, m_xDlg, m_xModel, mfOffsetX, mfOffsetY ); 195cdf0e10cSrcweir return uno::makeAny( xVBAControl ); 196cdf0e10cSrcweir } 197cdf0e10cSrcweir throw container::NoSuchElementException(); 198cdf0e10cSrcweir } 199cdf0e10cSrcweir 200cdf0e10cSrcweir }; 201cdf0e10cSrcweir 202cdf0e10cSrcweir 203cdf0e10cSrcweir uno::Reference<container::XIndexAccess > 204cdf0e10cSrcweir lcl_controlsWrapper( const uno::Reference< awt::XControl >& xDlg ) 205cdf0e10cSrcweir { 206cdf0e10cSrcweir return new ControlArrayWrapper( xDlg ); 207cdf0e10cSrcweir } 208cdf0e10cSrcweir 209cdf0e10cSrcweir ScVbaControls::ScVbaControls( 210cdf0e10cSrcweir const uno::Reference< XHelperInterface >& xParent, 211cdf0e10cSrcweir const uno::Reference< uno::XComponentContext >& xContext, 212cdf0e10cSrcweir const css::uno::Reference< awt::XControl >& xDialog, 213cdf0e10cSrcweir const uno::Reference< frame::XModel >& xModel, 214cdf0e10cSrcweir double fOffsetX, double fOffsetY ) : 215cdf0e10cSrcweir ControlsImpl_BASE( xParent, xContext, lcl_controlsWrapper( xDialog ) ), 216cdf0e10cSrcweir mxDialog( xDialog ), 217cdf0e10cSrcweir mxModel( xModel ), 218cdf0e10cSrcweir mfOffsetX( fOffsetX ), 219cdf0e10cSrcweir mfOffsetY( fOffsetY ) 220cdf0e10cSrcweir { 221cdf0e10cSrcweir } 222cdf0e10cSrcweir 223cdf0e10cSrcweir uno::Reference< container::XEnumeration > 224cdf0e10cSrcweir ScVbaControls::createEnumeration() throw (uno::RuntimeException) 225cdf0e10cSrcweir { 226cdf0e10cSrcweir uno::Reference< container::XEnumeration > xEnum( new ControlsEnumWrapper( mxParent, mxContext, m_xIndexAccess, mxDialog, mxModel, mfOffsetX, mfOffsetY ) ); 227cdf0e10cSrcweir if ( !xEnum.is() ) 228cdf0e10cSrcweir throw uno::RuntimeException(); 229cdf0e10cSrcweir return xEnum; 230cdf0e10cSrcweir } 231cdf0e10cSrcweir 232cdf0e10cSrcweir uno::Any 233cdf0e10cSrcweir ScVbaControls::createCollectionObject( const css::uno::Any& aSource ) 234cdf0e10cSrcweir { 235cdf0e10cSrcweir // Create control from awt::XControl 236cdf0e10cSrcweir uno::Reference< awt::XControl > xControl( aSource, uno::UNO_QUERY_THROW ); 237cdf0e10cSrcweir uno::Reference< msforms::XControl > xVBAControl = ScVbaControlFactory::createUserformControl( mxContext, xControl, mxDialog, mxModel, mfOffsetX, mfOffsetY ); 238cdf0e10cSrcweir return uno::Any( xVBAControl ); 239cdf0e10cSrcweir } 240cdf0e10cSrcweir 241cdf0e10cSrcweir void SAL_CALL 242cdf0e10cSrcweir ScVbaControls::Move( double cx, double cy ) throw (uno::RuntimeException) 243cdf0e10cSrcweir { 244cdf0e10cSrcweir uno::Reference< container::XEnumeration > xEnum( createEnumeration() ); 245cdf0e10cSrcweir while ( xEnum->hasMoreElements() ) 246cdf0e10cSrcweir { 247cdf0e10cSrcweir uno::Reference< msforms::XControl > xControl( xEnum->nextElement(), uno::UNO_QUERY_THROW ); 248cdf0e10cSrcweir xControl->setLeft( xControl->getLeft() + cx ); 249cdf0e10cSrcweir xControl->setTop( xControl->getTop() + cy ); 250cdf0e10cSrcweir } 251cdf0e10cSrcweir } 252cdf0e10cSrcweir 253cdf0e10cSrcweir uno::Any SAL_CALL ScVbaControls::Add( const uno::Any& Object, const uno::Any& StringKey, const uno::Any& /*Before*/, const uno::Any& /*After*/ ) 254cdf0e10cSrcweir throw (uno::RuntimeException) 255cdf0e10cSrcweir { 256cdf0e10cSrcweir uno::Any aResult; 257cdf0e10cSrcweir ::rtl::OUString aComServiceName; 258cdf0e10cSrcweir 259cdf0e10cSrcweir try 260cdf0e10cSrcweir { 261cdf0e10cSrcweir if ( !mxDialog.is() ) 262cdf0e10cSrcweir throw uno::RuntimeException(); 263cdf0e10cSrcweir 264cdf0e10cSrcweir uno::Reference< awt::XControl > xNewControl; 265cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xModelFactory( mxDialog->getModel(), uno::UNO_QUERY_THROW ); 266cdf0e10cSrcweir 267cdf0e10cSrcweir uno::Reference< container::XNameContainer > xDialogContainer( xModelFactory, uno::UNO_QUERY_THROW ); 268cdf0e10cSrcweir 269cdf0e10cSrcweir Object >>= aComServiceName; 270cdf0e10cSrcweir 271cdf0e10cSrcweir // TODO: Support Before and After? 272cdf0e10cSrcweir ::rtl::OUString aNewName; 273cdf0e10cSrcweir StringKey >>= aNewName; 274cdf0e10cSrcweir if ( !aNewName.getLength() ) 275cdf0e10cSrcweir { 276cdf0e10cSrcweir aNewName = aComServiceName; 277cdf0e10cSrcweir if ( !aNewName.getLength() ) 278cdf0e10cSrcweir aNewName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Control" ) ); 279cdf0e10cSrcweir 280cdf0e10cSrcweir sal_Int32 nInd = 0; 281cdf0e10cSrcweir while( xDialogContainer->hasByName( aNewName ) && (nInd < SAL_MAX_INT32) ) 282cdf0e10cSrcweir { 283cdf0e10cSrcweir aNewName = aComServiceName; 284cdf0e10cSrcweir aNewName += ::rtl::OUString::valueOf( nInd++ ); 285cdf0e10cSrcweir } 286cdf0e10cSrcweir } 287cdf0e10cSrcweir 288cdf0e10cSrcweir double fDefWidth = 72.0, fDefHeight = 18.0; 289cdf0e10cSrcweir if ( aComServiceName.getLength() ) 290cdf0e10cSrcweir { 291cdf0e10cSrcweir // create a UNO control model based on the passed control type 292cdf0e10cSrcweir uno::Reference< awt::XControlModel > xNewModel; 293cdf0e10cSrcweir bool bFontSupport = false; 294cdf0e10cSrcweir bool bNativeAX = false; 295cdf0e10cSrcweir if( aComServiceName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "Forms.CommandButton.1" ) ) ) 296cdf0e10cSrcweir { 297cdf0e10cSrcweir xNewModel.set( xModelFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlButtonModel" ) ) ), uno::UNO_QUERY_THROW ); 298cdf0e10cSrcweir fDefWidth = 72.0; fDefHeight = 24.0; 299cdf0e10cSrcweir bFontSupport = true; 300cdf0e10cSrcweir } 301cdf0e10cSrcweir else if( aComServiceName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "Forms.Label.1" ) ) ) 302cdf0e10cSrcweir { 303cdf0e10cSrcweir xNewModel.set( xModelFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlFixedTextModel" ) ) ), uno::UNO_QUERY_THROW ); 304cdf0e10cSrcweir fDefWidth = 72.0; fDefHeight = 18.0; 305cdf0e10cSrcweir bFontSupport = true; 306cdf0e10cSrcweir } 307cdf0e10cSrcweir else if( aComServiceName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "Forms.Image.1" ) ) ) 308cdf0e10cSrcweir { 309cdf0e10cSrcweir xNewModel.set( xModelFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlImageControlModel" ) ) ), uno::UNO_QUERY_THROW ); 310cdf0e10cSrcweir fDefWidth = 72.0; fDefHeight = 72.0; 311cdf0e10cSrcweir } 312cdf0e10cSrcweir else if( aComServiceName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "Forms.CheckBox.1" ) ) ) 313cdf0e10cSrcweir { 314cdf0e10cSrcweir xNewModel.set( xModelFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlCheckBoxModel" ) ) ), uno::UNO_QUERY_THROW ); 315cdf0e10cSrcweir fDefWidth = 108.0; fDefHeight = 18.0; 316cdf0e10cSrcweir bFontSupport = true; 317cdf0e10cSrcweir } 318cdf0e10cSrcweir else if( aComServiceName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "Forms.OptionButton.1" ) ) ) 319cdf0e10cSrcweir { 320cdf0e10cSrcweir xNewModel.set( xModelFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlRadioButtonModel" ) ) ), uno::UNO_QUERY_THROW ); 321cdf0e10cSrcweir fDefWidth = 108.0; fDefHeight = 18.0; 322cdf0e10cSrcweir bFontSupport = true; 323cdf0e10cSrcweir } 324cdf0e10cSrcweir else if( aComServiceName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "Forms.TextBox.1" ) ) ) 325cdf0e10cSrcweir { 326cdf0e10cSrcweir xNewModel.set( xModelFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlEditModel" ) ) ), uno::UNO_QUERY_THROW ); 327cdf0e10cSrcweir fDefWidth = 72.0; fDefHeight = 18.0; 328cdf0e10cSrcweir bFontSupport = true; 329cdf0e10cSrcweir } 330cdf0e10cSrcweir else if( aComServiceName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "Forms.ListBox.1" ) ) ) 331cdf0e10cSrcweir { 332cdf0e10cSrcweir xNewModel.set( xModelFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlListBoxModel" ) ) ), uno::UNO_QUERY_THROW ); 333cdf0e10cSrcweir fDefWidth = 72.0; fDefHeight = 18.0; 334cdf0e10cSrcweir bFontSupport = true; 335cdf0e10cSrcweir } 336cdf0e10cSrcweir else if( aComServiceName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "Forms.ComboBox.1" ) ) ) 337cdf0e10cSrcweir { 338cdf0e10cSrcweir xNewModel.set( xModelFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlComboBoxModel" ) ) ), uno::UNO_QUERY_THROW ); 339cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xProps( xNewModel, uno::UNO_QUERY_THROW ); 340cdf0e10cSrcweir xProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Dropdown" ) ), uno::Any( true ) ); 341cdf0e10cSrcweir fDefWidth = 72.0; fDefHeight = 18.0; 342cdf0e10cSrcweir bFontSupport = true; 343cdf0e10cSrcweir } 344cdf0e10cSrcweir else if( aComServiceName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "Forms.ToggleButton.1" ) ) ) 345cdf0e10cSrcweir { 346cdf0e10cSrcweir xNewModel.set( xModelFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlButtonModel" ) ) ), uno::UNO_QUERY_THROW ); 347cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xProps( xNewModel, uno::UNO_QUERY_THROW ); 348cdf0e10cSrcweir xProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Toggle" ) ), uno::Any( true ) ); 349cdf0e10cSrcweir fDefWidth = 72.0; fDefHeight = 18.0; 350cdf0e10cSrcweir bFontSupport = true; 351cdf0e10cSrcweir } 352cdf0e10cSrcweir else if( aComServiceName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "Forms.Frame.1" ) ) ) 353cdf0e10cSrcweir { 354cdf0e10cSrcweir xNewModel.set( xModelFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlGroupBoxModel" ) ) ), uno::UNO_QUERY_THROW ); 355cdf0e10cSrcweir fDefWidth = 216.0; fDefHeight = 144.0; 356cdf0e10cSrcweir bFontSupport = true; 357cdf0e10cSrcweir } 358cdf0e10cSrcweir else if( aComServiceName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "Forms.SpinButton.1" ) ) ) 359cdf0e10cSrcweir { 360cdf0e10cSrcweir xNewModel.set( xModelFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlSpinButtonModel" ) ) ), uno::UNO_QUERY_THROW ); 361cdf0e10cSrcweir fDefWidth = 12.75; fDefHeight = 25.5; 362cdf0e10cSrcweir } 363cdf0e10cSrcweir else if( aComServiceName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "Forms.ScrollBar.1" ) ) ) 364cdf0e10cSrcweir { 365cdf0e10cSrcweir xNewModel.set( xModelFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlScrollBarModel" ) ) ), uno::UNO_QUERY_THROW ); 366cdf0e10cSrcweir fDefWidth = 12.75; fDefHeight = 63.8; 367cdf0e10cSrcweir } 368cdf0e10cSrcweir else 369cdf0e10cSrcweir { 370cdf0e10cSrcweir xNewModel.set( xModelFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.custom.awt.UnoControlSystemAXContainerModel" ) ) ), uno::UNO_QUERY_THROW ); 371cdf0e10cSrcweir fDefWidth = 72.0; fDefHeight = 18.0; 372cdf0e10cSrcweir bNativeAX = true; 373cdf0e10cSrcweir } 374cdf0e10cSrcweir 375cdf0e10cSrcweir // need to set a few font properties to get rid of the default DONT_KNOW values 376cdf0e10cSrcweir if( bFontSupport ) 377cdf0e10cSrcweir { 378cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xModelProps( xNewModel, uno::UNO_QUERY_THROW ); 379cdf0e10cSrcweir xModelProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontName" ) ), uno::Any( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Tahoma" ) ) ) ); 380cdf0e10cSrcweir xModelProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontHeight" ) ), uno::Any( float( 8.0 ) ) ); 381cdf0e10cSrcweir xModelProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontWeight" ) ), uno::Any( awt::FontWeight::NORMAL ) ); 382cdf0e10cSrcweir xModelProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontSlant" ) ), uno::Any( awt::FontSlant_NONE ) ); 383cdf0e10cSrcweir xModelProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontUnderline" ) ), uno::Any( awt::FontUnderline::NONE ) ); 384cdf0e10cSrcweir xModelProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontStrikeout" ) ), uno::Any( awt::FontStrikeout::NONE ) ); 385cdf0e10cSrcweir } 386cdf0e10cSrcweir 387cdf0e10cSrcweir xDialogContainer->insertByName( aNewName, uno::makeAny( xNewModel ) ); 388cdf0e10cSrcweir uno::Reference< awt::XControlContainer > xControlContainer( mxDialog, uno::UNO_QUERY_THROW ); 389cdf0e10cSrcweir xNewControl = xControlContainer->getControl( aNewName ); 390cdf0e10cSrcweir 391cdf0e10cSrcweir if( bNativeAX ) try 392cdf0e10cSrcweir { 393cdf0e10cSrcweir uno::Reference< script::XInvocation > xControlInvoke( xNewControl, uno::UNO_QUERY_THROW ); 394cdf0e10cSrcweir 395cdf0e10cSrcweir uno::Sequence< uno::Any > aArgs( 1 ); 396cdf0e10cSrcweir aArgs[0] <<= aComServiceName; 397cdf0e10cSrcweir uno::Sequence< sal_Int16 > aOutIDDummy; 398cdf0e10cSrcweir uno::Sequence< uno::Any > aOutDummy; 399cdf0e10cSrcweir xControlInvoke->invoke( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SOAddAXControl" ) ), aArgs, aOutIDDummy, aOutDummy ); 400cdf0e10cSrcweir } 401cdf0e10cSrcweir catch( uno::Exception& ) 402cdf0e10cSrcweir { 403cdf0e10cSrcweir xDialogContainer->removeByName( aNewName ); 404cdf0e10cSrcweir throw; 405cdf0e10cSrcweir } 406cdf0e10cSrcweir } 407cdf0e10cSrcweir 408cdf0e10cSrcweir if ( xNewControl.is() ) 409cdf0e10cSrcweir { 410cdf0e10cSrcweir UpdateCollectionIndex( lcl_controlsWrapper( mxDialog ) ); 411cdf0e10cSrcweir aResult <<= xNewControl; 412cdf0e10cSrcweir aResult = createCollectionObject( aResult ); 413cdf0e10cSrcweir uno::Reference< msforms::XControl > xVBAControl( aResult, uno::UNO_QUERY_THROW ); 414cdf0e10cSrcweir if( fDefWidth > 0.0 ) 415cdf0e10cSrcweir xVBAControl->setWidth( fDefWidth ); 416cdf0e10cSrcweir if( fDefHeight > 0.0 ) 417cdf0e10cSrcweir xVBAControl->setHeight( fDefHeight ); 418cdf0e10cSrcweir } 419cdf0e10cSrcweir else 420cdf0e10cSrcweir throw uno::RuntimeException(); 421cdf0e10cSrcweir } 422cdf0e10cSrcweir catch( uno::RuntimeException& ) 423cdf0e10cSrcweir { 424cdf0e10cSrcweir throw; 425cdf0e10cSrcweir } 426cdf0e10cSrcweir catch( uno::Exception& e ) 427cdf0e10cSrcweir { 428cdf0e10cSrcweir throw lang::WrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Can not create AXControl!" ) ), 429cdf0e10cSrcweir uno::Reference< uno::XInterface >(), 430cdf0e10cSrcweir uno::makeAny( e ) ); 431cdf0e10cSrcweir } 432cdf0e10cSrcweir 433cdf0e10cSrcweir return aResult; 434cdf0e10cSrcweir } 435cdf0e10cSrcweir 436cdf0e10cSrcweir void SAL_CALL ScVbaControls::Remove( const uno::Any& StringKeyOrIndex ) 437cdf0e10cSrcweir throw (uno::RuntimeException) 438cdf0e10cSrcweir { 439cdf0e10cSrcweir ::rtl::OUString aControlName; 440cdf0e10cSrcweir sal_Int32 nIndex = -1; 441cdf0e10cSrcweir 442cdf0e10cSrcweir try 443cdf0e10cSrcweir { 444cdf0e10cSrcweir if ( !mxDialog.is() ) 445cdf0e10cSrcweir throw uno::RuntimeException(); 446cdf0e10cSrcweir 447cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xModelFactory( mxDialog->getModel(), uno::UNO_QUERY_THROW ); 448cdf0e10cSrcweir uno::Reference< container::XNameContainer > xDialogContainer( xModelFactory, uno::UNO_QUERY_THROW ); 449cdf0e10cSrcweir 450cdf0e10cSrcweir if ( !( ( StringKeyOrIndex >>= aControlName ) && aControlName.getLength() ) 451cdf0e10cSrcweir && !( ( StringKeyOrIndex >>= nIndex ) && nIndex >= 0 && nIndex < m_xIndexAccess->getCount() ) ) 452cdf0e10cSrcweir throw uno::RuntimeException(); 453cdf0e10cSrcweir 454cdf0e10cSrcweir uno::Reference< awt::XControl > xControl; 455cdf0e10cSrcweir if ( aControlName.getLength() ) 456cdf0e10cSrcweir { 457cdf0e10cSrcweir uno::Reference< awt::XControlContainer > xControlContainer( mxDialog, uno::UNO_QUERY_THROW ); 458cdf0e10cSrcweir xControl = xControlContainer->getControl( aControlName ); 459cdf0e10cSrcweir } 460cdf0e10cSrcweir else 461cdf0e10cSrcweir { 462cdf0e10cSrcweir m_xIndexAccess->getByIndex( nIndex ) >>= xControl; 463cdf0e10cSrcweir } 464cdf0e10cSrcweir 465cdf0e10cSrcweir if ( !xControl.is() ) 466cdf0e10cSrcweir throw uno::RuntimeException(); 467cdf0e10cSrcweir 468cdf0e10cSrcweir if ( !aControlName.getLength() ) 469cdf0e10cSrcweir aControlName = ControlArrayWrapper::getControlName( xControl ); 470cdf0e10cSrcweir 471cdf0e10cSrcweir xDialogContainer->removeByName( aControlName ); 472cdf0e10cSrcweir xControl->dispose(); 473cdf0e10cSrcweir } 474cdf0e10cSrcweir catch( uno::RuntimeException& ) 475cdf0e10cSrcweir { 476cdf0e10cSrcweir // the exceptions are not rethrown, impossibility to find or remove the control is currently not reported 477cdf0e10cSrcweir // since in most cases it means just that the controls is already not there, the VBA seems to do it in the same way 478cdf0e10cSrcweir 479cdf0e10cSrcweir // throw; 480cdf0e10cSrcweir } 481cdf0e10cSrcweir catch( uno::Exception& e ) 482cdf0e10cSrcweir { 483cdf0e10cSrcweir // throw lang::WrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Can not create AXControl!" ) ), 484cdf0e10cSrcweir // uno::Reference< uno::XInterface >(), 485cdf0e10cSrcweir // uno::makeAny( e ) ); 486cdf0e10cSrcweir } 487cdf0e10cSrcweir } 488cdf0e10cSrcweir 489cdf0e10cSrcweir 490cdf0e10cSrcweir uno::Type 491cdf0e10cSrcweir ScVbaControls::getElementType() throw (uno::RuntimeException) 492cdf0e10cSrcweir { 493cdf0e10cSrcweir return ooo::vba::msforms::XControl::static_type(0); 494cdf0e10cSrcweir } 495cdf0e10cSrcweir 496cdf0e10cSrcweir VBAHELPER_IMPL_XHELPERINTERFACE( ScVbaControls, "ooo.vba.msforms.Controls" ) 497