LCOV - code coverage report
Current view: top level - libreoffice/vbahelper/source/msforms - vbacontrols.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 223 0.0 %
Date: 2012-12-27 Functions: 0 27 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10