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