1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
9 * last change: $Author$ $Date$
11 * The Contents of this file are made available subject to
12 * the terms of GNU Lesser General Public License Version 2.1.
15 * GNU Lesser General Public License Version 2.1
16 * =============================================
17 * Copyright 2005 by Sun Microsystems, Inc.
18 * 901 San Antonio Road, Palo Alto, CA 94303, USA
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License version 2.1, as published by the Free Software Foundation.
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * Lesser General Public License for more details.
29 * You should have received a copy of the GNU Lesser General Public
30 * License along with this library; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
34 ************************************************************************/
35 #include <vbahelper/helperdecl.hxx>
36 #include "vbauserform.hxx"
37 #include <com/sun/star/awt/XControl.hpp>
38 #include <com/sun/star/awt/XControlContainer.hpp>
39 #include <com/sun/star/beans/PropertyConcept.hpp>
40 #include <basic/sbx.hxx>
41 #include <basic/sbstar.hxx>
42 #include <basic/sbmeth.hxx>
43 #include "vbacontrols.hxx"
45 using namespace ::ooo::vba
;
46 using namespace ::com::sun::star
;
49 // XDialog implementation has the following interesting bits
50 // a Controls property ( which is an array of the container controls )
51 // each item in the controls array is a XControl, where the model is
52 // basically a property bag
53 // additionally the XDialog instance has itself a model
54 // this model has a ControlModels ( array of models ) property
55 // the models in ControlModels can be accessed by name
56 // also the XDialog is a XControl ( to access the model above
58 ScVbaUserForm::ScVbaUserForm( uno::Sequence
< uno::Any
> const& aArgs
, uno::Reference
< uno::XComponentContext
>const& xContext
) throw ( lang::IllegalArgumentException
) : ScVbaUserForm_BASE( getXSomethingFromArgs
< XHelperInterface
>( aArgs
, 0 ), xContext
, getXSomethingFromArgs
< uno::XInterface
>( aArgs
, 1 ), getXSomethingFromArgs
< frame::XModel
>( aArgs
, 2 ), static_cast< ooo::vba::AbstractGeometryAttributes
* >(0) ), mbDispose( true )
60 m_xDialog
.set( m_xControl
, uno::UNO_QUERY_THROW
);
61 uno::Reference
< awt::XControl
> xControl( m_xDialog
, uno::UNO_QUERY_THROW
);
62 m_xProps
.set( xControl
->getModel(), uno::UNO_QUERY_THROW
);
63 setGeometryHelper( new UserFormGeometryHelper( xContext
, xControl
) );
66 ScVbaUserForm::~ScVbaUserForm()
71 ScVbaUserForm::Show( ) throw (uno::RuntimeException
)
73 OSL_TRACE("ScVbaUserForm::Show( )");
77 aRet
= m_xDialog
->execute();
78 OSL_TRACE("ScVbaUserForm::Show() execute returned %d", aRet
);
83 uno::Reference
< lang::XComponent
> xComp( m_xDialog
, uno::UNO_QUERY_THROW
);
88 catch( uno::Exception
& )
94 rtl::OUString SAL_CALL
95 ScVbaUserForm::getCaption() throw (::com::sun::star::uno::RuntimeException
)
97 rtl::OUString sCaption
;
98 m_xProps
->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Title") ) ) >>= sCaption
;
102 ScVbaUserForm::setCaption( const ::rtl::OUString
& _caption
) throw (::com::sun::star::uno::RuntimeException
)
104 m_xProps
->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Title") ), uno::makeAny( _caption
) );
108 ScVbaUserForm::Hide( ) throw (uno::RuntimeException
)
110 mbDispose
= false; // hide not dispose
111 if ( m_xDialog
.is() )
112 m_xDialog
->endExecute();
116 ScVbaUserForm::RePaint( ) throw (uno::RuntimeException
)
122 ScVbaUserForm::UnloadObject( ) throw (uno::RuntimeException
)
125 if ( m_xDialog
.is() )
126 m_xDialog
->endExecute();
130 ScVbaUserForm::getServiceImplName()
132 static rtl::OUString
sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaUserForm") );
136 uno::Sequence
< rtl::OUString
>
137 ScVbaUserForm::getServiceNames()
139 static uno::Sequence
< rtl::OUString
> aServiceNames
;
140 if ( aServiceNames
.getLength() == 0 )
142 aServiceNames
.realloc( 1 );
143 aServiceNames
[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.UserForm" ) );
145 return aServiceNames
;
148 uno::Reference
< beans::XIntrospectionAccess
> SAL_CALL
149 ScVbaUserForm::getIntrospection( ) throw (uno::RuntimeException
)
151 return uno::Reference
< beans::XIntrospectionAccess
>();
155 ScVbaUserForm::invoke( const ::rtl::OUString
& /*aFunctionName*/, const uno::Sequence
< uno::Any
>& /*aParams*/, uno::Sequence
< ::sal_Int16
>& /*aOutParamIndex*/, uno::Sequence
< uno::Any
>& /*aOutParam*/ ) throw (lang::IllegalArgumentException
, script::CannotConvertException
, reflection::InvocationTargetException
, uno::RuntimeException
)
157 throw uno::RuntimeException(); // unsupported operation
161 ScVbaUserForm::setValue( const ::rtl::OUString
& aPropertyName
, const uno::Any
& aValue
) throw (beans::UnknownPropertyException
, script::CannotConvertException
, reflection::InvocationTargetException
, uno::RuntimeException
)
163 uno::Any aObject
= getValue( aPropertyName
);
164 // The Object *must* support XDefaultProperty here because getValue will
165 // only return properties that are Objects ( e.g. controls )
166 // e.g. Userform1.aControl = something
167 // 'aControl' has to support XDefaultProperty to make sense here
168 uno::Reference
< script::XDefaultProperty
> xDfltProp( aObject
, uno::UNO_QUERY_THROW
);
169 rtl::OUString aDfltPropName
= xDfltProp
->getDefaultPropertyName();
170 uno::Reference
< beans::XIntrospectionAccess
> xUnoAccess( getIntrospectionAccess( aObject
) );
171 uno::Reference
< beans::XPropertySet
> xPropSet( xUnoAccess
->queryAdapter( ::getCppuType( (const uno::Reference
< beans::XPropertySet
> *)0 ) ), uno::UNO_QUERY_THROW
);
172 xPropSet
->setPropertyValue( aDfltPropName
, aValue
);
176 ScVbaUserForm::getValue( const ::rtl::OUString
& aPropertyName
) throw (beans::UnknownPropertyException
, uno::RuntimeException
)
178 uno::Reference
< awt::XControl
> xDialogControl( m_xDialog
, uno::UNO_QUERY_THROW
);
179 uno::Reference
< awt::XControlContainer
> xContainer( m_xDialog
, uno::UNO_QUERY_THROW
);
180 uno::Reference
< awt::XControl
> xControl
= xContainer
->getControl( aPropertyName
);
181 ScVbaControlFactory
aFac( mxContext
, xControl
, m_xModel
);
182 uno::Reference
< msforms::XControl
> xVBAControl( aFac
.createControl( xDialogControl
->getModel() ) );
183 ScVbaControl
* pControl
= dynamic_cast< ScVbaControl
* >( xVBAControl
.get() );
184 pControl
->setGeometryHelper( new UserFormGeometryHelper( mxContext
, xControl
) );
185 return uno::makeAny( xVBAControl
);
189 ScVbaUserForm::hasMethod( const ::rtl::OUString
& /*aName*/ ) throw (uno::RuntimeException
)
194 ScVbaUserForm::Controls( const uno::Any
& index
) throw (uno::RuntimeException
)
196 uno::Reference
< awt::XControl
> xDialogControl( m_xDialog
, uno::UNO_QUERY_THROW
);
197 uno::Reference
< XCollection
> xControls( new ScVbaControls( this, mxContext
, xDialogControl
) );
198 if ( index
.hasValue() )
199 return uno::makeAny( xControls
->Item( index
, uno::Any() ) );
200 return uno::makeAny( xControls
);
204 ScVbaUserForm::hasProperty( const ::rtl::OUString
& aName
) throw (uno::RuntimeException
)
206 uno::Reference
< awt::XControl
> xControl( m_xDialog
, uno::UNO_QUERY
);
207 OSL_TRACE("ScVbaUserForm::hasProperty(%s) %d", rtl::OUStringToOString( aName
, RTL_TEXTENCODING_UTF8
).getStr(), xControl
.is() );
210 uno::Reference
< container::XNameAccess
> xNameAccess( xControl
->getModel(), uno::UNO_QUERY_THROW
);
211 sal_Bool bRes
= xNameAccess
->hasByName( aName
);
212 OSL_TRACE("ScVbaUserForm::hasProperty(%s) %d ---> %d", rtl::OUStringToOString( aName
, RTL_TEXTENCODING_UTF8
).getStr(), xControl
.is(), bRes
);
220 namespace sdecl
= comphelper::service_decl
;
221 sdecl::vba_service_class_
<ScVbaUserForm
, sdecl::with_args
<true> > serviceImpl
;
222 extern sdecl::ServiceDecl
const serviceDecl(
225 "ooo.vba.msforms.UserForm" );