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
10*e6ed5fbcSAndrew Rist  *
11*e6ed5fbcSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*e6ed5fbcSAndrew Rist  *
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.
19*e6ed5fbcSAndrew Rist  *
20*e6ed5fbcSAndrew Rist  *************************************************************/
21*e6ed5fbcSAndrew Rist 
22*e6ed5fbcSAndrew Rist 
23cdf0e10cSrcweir #include <com/sun/star/form/FormComponentType.hpp>
24cdf0e10cSrcweir #include <com/sun/star/awt/XControlModel.hpp>
25cdf0e10cSrcweir #include <com/sun/star/awt/XControl.hpp>
26cdf0e10cSrcweir #include <com/sun/star/awt/XWindow2.hpp>
27cdf0e10cSrcweir #include <com/sun/star/lang/XEventListener.hpp>
28cdf0e10cSrcweir #include <com/sun/star/drawing/XShape.hpp>
29cdf0e10cSrcweir #include <com/sun/star/drawing/XControlShape.hpp>
30cdf0e10cSrcweir #include <com/sun/star/awt/XControl.hpp>
31cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp>
32cdf0e10cSrcweir #include <com/sun/star/view/XControlAccess.hpp>
33cdf0e10cSrcweir #include <com/sun/star/container/XChild.hpp>
34cdf0e10cSrcweir #include <com/sun/star/form/binding/XBindableValue.hpp>
35cdf0e10cSrcweir #include <com/sun/star/form/binding/XListEntrySink.hpp>
36cdf0e10cSrcweir #include <com/sun/star/table/CellAddress.hpp>
37cdf0e10cSrcweir #include <com/sun/star/table/CellRangeAddress.hpp>
38cdf0e10cSrcweir #include <ooo/vba/XControlProvider.hpp>
39cdf0e10cSrcweir #ifdef VBA_OOBUILD_HACK
40cdf0e10cSrcweir #include <svtools/bindablecontrolhelper.hxx>
41cdf0e10cSrcweir #endif
42cdf0e10cSrcweir #include "vbacontrol.hxx"
43cdf0e10cSrcweir #include "vbacombobox.hxx"
44cdf0e10cSrcweir #include "vbabutton.hxx"
45cdf0e10cSrcweir #include "vbalabel.hxx"
46cdf0e10cSrcweir #include "vbatextbox.hxx"
47cdf0e10cSrcweir #include "vbaradiobutton.hxx"
48cdf0e10cSrcweir #include "vbalistbox.hxx"
49cdf0e10cSrcweir #include "vbatogglebutton.hxx"
50cdf0e10cSrcweir #include "vbacheckbox.hxx"
51cdf0e10cSrcweir #include "vbaframe.hxx"
52cdf0e10cSrcweir #include "vbascrollbar.hxx"
53cdf0e10cSrcweir #include "vbaprogressbar.hxx"
54cdf0e10cSrcweir #include "vbamultipage.hxx"
55cdf0e10cSrcweir #include "vbaspinbutton.hxx"
56cdf0e10cSrcweir #include "vbasystemaxcontrol.hxx"
57cdf0e10cSrcweir #include "vbaimage.hxx"
58cdf0e10cSrcweir #include <vbahelper/helperdecl.hxx>
59cdf0e10cSrcweir 
60cdf0e10cSrcweir 
61cdf0e10cSrcweir using namespace com::sun::star;
62cdf0e10cSrcweir using namespace ooo::vba;
63cdf0e10cSrcweir 
64cdf0e10cSrcweir uno::Reference< css::awt::XWindowPeer >
getWindowPeer()65cdf0e10cSrcweir ScVbaControl::getWindowPeer() throw (uno::RuntimeException)
66cdf0e10cSrcweir {
67cdf0e10cSrcweir     uno::Reference< drawing::XControlShape > xControlShape( m_xControl, uno::UNO_QUERY );
68cdf0e10cSrcweir 
69cdf0e10cSrcweir     uno::Reference< awt::XControlModel > xControlModel;
70cdf0e10cSrcweir     uno::Reference< css::awt::XWindowPeer >  xWinPeer;
71cdf0e10cSrcweir     if ( !xControlShape.is() )
72cdf0e10cSrcweir     {
73cdf0e10cSrcweir         // would seem to be a Userform control
74cdf0e10cSrcweir         uno::Reference< awt::XControl > xControl( m_xControl, uno::UNO_QUERY_THROW );
75cdf0e10cSrcweir         xWinPeer =  xControl->getPeer();
76cdf0e10cSrcweir 	return xWinPeer;
77cdf0e10cSrcweir     }
78cdf0e10cSrcweir     // form control
79cdf0e10cSrcweir     xControlModel.set( xControlShape->getControl(), uno::UNO_QUERY_THROW );
80cdf0e10cSrcweir 
81cdf0e10cSrcweir     uno::Reference< view::XControlAccess > xControlAccess( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW );
82cdf0e10cSrcweir     try
83cdf0e10cSrcweir     {
84cdf0e10cSrcweir         uno::Reference< awt::XControl > xControl( xControlAccess->getControl( xControlModel ), uno::UNO_QUERY );
85cdf0e10cSrcweir         xWinPeer =  xControl->getPeer();
86cdf0e10cSrcweir     }
87cdf0e10cSrcweir     catch( uno::Exception )
88cdf0e10cSrcweir     {
89cdf0e10cSrcweir         throw uno::RuntimeException( rtl::OUString::createFromAscii( "The Control does not exsit" ),
90cdf0e10cSrcweir                 uno::Reference< uno::XInterface >() );
91cdf0e10cSrcweir     }
92cdf0e10cSrcweir     return xWinPeer;
93cdf0e10cSrcweir }
94cdf0e10cSrcweir 
95cdf0e10cSrcweir //ScVbaControlListener
96cdf0e10cSrcweir class ScVbaControlListener: public cppu::WeakImplHelper1< lang::XEventListener >
97cdf0e10cSrcweir {
98cdf0e10cSrcweir private:
99cdf0e10cSrcweir     ScVbaControl *pControl;
100cdf0e10cSrcweir public:
101cdf0e10cSrcweir     ScVbaControlListener( ScVbaControl *pTmpControl );
102cdf0e10cSrcweir     virtual ~ScVbaControlListener();
103cdf0e10cSrcweir     virtual void SAL_CALL disposing( const lang::EventObject& rEventObject ) throw( uno::RuntimeException );
104cdf0e10cSrcweir };
105cdf0e10cSrcweir 
ScVbaControlListener(ScVbaControl * pTmpControl)106cdf0e10cSrcweir ScVbaControlListener::ScVbaControlListener( ScVbaControl *pTmpControl ): pControl( pTmpControl )
107cdf0e10cSrcweir {
108cdf0e10cSrcweir }
109cdf0e10cSrcweir 
~ScVbaControlListener()110cdf0e10cSrcweir ScVbaControlListener::~ScVbaControlListener()
111cdf0e10cSrcweir {
112cdf0e10cSrcweir }
113cdf0e10cSrcweir 
114cdf0e10cSrcweir void SAL_CALL
disposing(const lang::EventObject &)115cdf0e10cSrcweir ScVbaControlListener::disposing( const lang::EventObject& ) throw( uno::RuntimeException )
116cdf0e10cSrcweir {
117cdf0e10cSrcweir     if( pControl )
118cdf0e10cSrcweir     {
119cdf0e10cSrcweir         pControl->removeResouce();
120cdf0e10cSrcweir         pControl = NULL;
121cdf0e10cSrcweir     }
122cdf0e10cSrcweir }
123cdf0e10cSrcweir 
124cdf0e10cSrcweir //ScVbaControl
125cdf0e10cSrcweir 
ScVbaControl(const uno::Reference<XHelperInterface> & xParent,const uno::Reference<uno::XComponentContext> & xContext,const uno::Reference<::uno::XInterface> & xControl,const css::uno::Reference<css::frame::XModel> & xModel,AbstractGeometryAttributes * pGeomHelper)126cdf0e10cSrcweir ScVbaControl::ScVbaControl( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< ::uno::XInterface >& xControl,  const css::uno::Reference< css::frame::XModel >& xModel, AbstractGeometryAttributes* pGeomHelper ) : ControlImpl_BASE( xParent, xContext ),  m_xControl( xControl ), m_xModel( xModel )
127cdf0e10cSrcweir {
128cdf0e10cSrcweir     //add listener
129cdf0e10cSrcweir     m_xEventListener.set( new ScVbaControlListener( this ) );
130cdf0e10cSrcweir     setGeometryHelper( pGeomHelper );
131cdf0e10cSrcweir     uno::Reference< lang::XComponent > xComponent( m_xControl, uno::UNO_QUERY_THROW );
132cdf0e10cSrcweir     xComponent->addEventListener( m_xEventListener );
133cdf0e10cSrcweir 
134cdf0e10cSrcweir     //init m_xProps
135cdf0e10cSrcweir     uno::Reference< drawing::XControlShape > xControlShape( m_xControl, uno::UNO_QUERY ) ;
136cdf0e10cSrcweir     uno::Reference< awt::XControl> xUserFormControl( m_xControl, uno::UNO_QUERY ) ;
137cdf0e10cSrcweir     if ( xControlShape.is() ) // form control
138cdf0e10cSrcweir         m_xProps.set( xControlShape->getControl(), uno::UNO_QUERY_THROW );
139cdf0e10cSrcweir     else if ( xUserFormControl.is() ) // userform control
140cdf0e10cSrcweir         m_xProps.set( xUserFormControl->getModel(), uno::UNO_QUERY_THROW );
141cdf0e10cSrcweir }
142cdf0e10cSrcweir 
~ScVbaControl()143cdf0e10cSrcweir ScVbaControl::~ScVbaControl()
144cdf0e10cSrcweir {
145cdf0e10cSrcweir     if( m_xControl.is() )
146cdf0e10cSrcweir {
147cdf0e10cSrcweir         uno::Reference< lang::XComponent > xComponent( m_xControl, uno::UNO_QUERY_THROW );
148cdf0e10cSrcweir     xComponent->removeEventListener( m_xEventListener );
149cdf0e10cSrcweir }
150cdf0e10cSrcweir }
151cdf0e10cSrcweir 
152cdf0e10cSrcweir void
setGeometryHelper(AbstractGeometryAttributes * pHelper)153cdf0e10cSrcweir ScVbaControl::setGeometryHelper( AbstractGeometryAttributes* pHelper )
154cdf0e10cSrcweir {
155cdf0e10cSrcweir     mpGeometryHelper.reset( pHelper );
156cdf0e10cSrcweir }
157cdf0e10cSrcweir 
removeResouce()158cdf0e10cSrcweir void ScVbaControl::removeResouce() throw( uno::RuntimeException )
159cdf0e10cSrcweir {
160cdf0e10cSrcweir     uno::Reference< lang::XComponent > xComponent( m_xControl, uno::UNO_QUERY_THROW );
161cdf0e10cSrcweir     xComponent->removeEventListener( m_xEventListener );
162cdf0e10cSrcweir     m_xControl= NULL;
163cdf0e10cSrcweir     m_xProps = NULL;
164cdf0e10cSrcweir }
165cdf0e10cSrcweir 
166cdf0e10cSrcweir //In design model has different behavior
getEnabled()167cdf0e10cSrcweir sal_Bool SAL_CALL ScVbaControl::getEnabled() throw (uno::RuntimeException)
168cdf0e10cSrcweir {
169cdf0e10cSrcweir     uno::Any aValue = m_xProps->getPropertyValue
170cdf0e10cSrcweir             (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Enabled" ) ) );
171cdf0e10cSrcweir     sal_Bool bRet = false;
172cdf0e10cSrcweir     aValue >>= bRet;
173cdf0e10cSrcweir     return bRet;
174cdf0e10cSrcweir }
175cdf0e10cSrcweir 
setEnabled(sal_Bool bVisible)176cdf0e10cSrcweir void SAL_CALL ScVbaControl::setEnabled( sal_Bool bVisible ) throw (uno::RuntimeException)
177cdf0e10cSrcweir {
178cdf0e10cSrcweir     uno::Any aValue( bVisible );
179cdf0e10cSrcweir     m_xProps->setPropertyValue
180cdf0e10cSrcweir             (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Enabled" ) ), aValue);
181cdf0e10cSrcweir 
182cdf0e10cSrcweir }
183cdf0e10cSrcweir 
getVisible()184cdf0e10cSrcweir sal_Bool SAL_CALL ScVbaControl::getVisible() throw (uno::RuntimeException)
185cdf0e10cSrcweir {
186cdf0e10cSrcweir     sal_Bool bVisible( sal_True );
187cdf0e10cSrcweir     m_xProps->getPropertyValue
188cdf0e10cSrcweir             (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EnableVisible" ) )) >>= bVisible;
189cdf0e10cSrcweir     return bVisible;
190cdf0e10cSrcweir }
191cdf0e10cSrcweir 
setVisible(sal_Bool bVisible)192cdf0e10cSrcweir void SAL_CALL ScVbaControl::setVisible( sal_Bool bVisible ) throw (uno::RuntimeException)
193cdf0e10cSrcweir {
194cdf0e10cSrcweir     uno::Any aValue( bVisible );
195cdf0e10cSrcweir     m_xProps->setPropertyValue
196cdf0e10cSrcweir             (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EnableVisible" ) ), aValue);
197cdf0e10cSrcweir }
getHeight()198cdf0e10cSrcweir double SAL_CALL ScVbaControl::getHeight() throw (uno::RuntimeException)
199cdf0e10cSrcweir {
200cdf0e10cSrcweir     return mpGeometryHelper->getHeight();
201cdf0e10cSrcweir }
setHeight(double _height)202cdf0e10cSrcweir void SAL_CALL ScVbaControl::setHeight( double _height ) throw (uno::RuntimeException)
203cdf0e10cSrcweir {
204cdf0e10cSrcweir     mpGeometryHelper->setHeight( _height );
205cdf0e10cSrcweir }
206cdf0e10cSrcweir 
getWidth()207cdf0e10cSrcweir double SAL_CALL ScVbaControl::getWidth() throw (uno::RuntimeException)
208cdf0e10cSrcweir {
209cdf0e10cSrcweir     return mpGeometryHelper->getWidth();
210cdf0e10cSrcweir }
setWidth(double _width)211cdf0e10cSrcweir void SAL_CALL ScVbaControl::setWidth( double _width ) throw (uno::RuntimeException)
212cdf0e10cSrcweir {
213cdf0e10cSrcweir     mpGeometryHelper->setWidth( _width );
214cdf0e10cSrcweir }
215cdf0e10cSrcweir 
216cdf0e10cSrcweir double SAL_CALL
getLeft()217cdf0e10cSrcweir ScVbaControl::getLeft() throw (uno::RuntimeException)
218cdf0e10cSrcweir {
219cdf0e10cSrcweir     return mpGeometryHelper->getLeft();
220cdf0e10cSrcweir }
221cdf0e10cSrcweir 
222cdf0e10cSrcweir void SAL_CALL
setLeft(double _left)223cdf0e10cSrcweir ScVbaControl::setLeft( double _left ) throw (uno::RuntimeException)
224cdf0e10cSrcweir {
225cdf0e10cSrcweir     mpGeometryHelper->setLeft( _left );
226cdf0e10cSrcweir }
227cdf0e10cSrcweir 
228cdf0e10cSrcweir double SAL_CALL
getTop()229cdf0e10cSrcweir ScVbaControl::getTop() throw (uno::RuntimeException)
230cdf0e10cSrcweir {
231cdf0e10cSrcweir     return mpGeometryHelper->getTop();
232cdf0e10cSrcweir }
233cdf0e10cSrcweir 
234cdf0e10cSrcweir void SAL_CALL
setTop(double _top)235cdf0e10cSrcweir ScVbaControl::setTop( double _top ) throw (uno::RuntimeException)
236cdf0e10cSrcweir {
237cdf0e10cSrcweir     mpGeometryHelper->setTop( _top );
238cdf0e10cSrcweir }
239cdf0e10cSrcweir 
240cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL
getObject()241cdf0e10cSrcweir ScVbaControl::getObject() throw (uno::RuntimeException)
242cdf0e10cSrcweir {
243cdf0e10cSrcweir 	uno::Reference< msforms::XControl > xRet( this );
244cdf0e10cSrcweir 	return xRet;
245cdf0e10cSrcweir }
246cdf0e10cSrcweir 
SetFocus()247cdf0e10cSrcweir void SAL_CALL ScVbaControl::SetFocus() throw (uno::RuntimeException)
248cdf0e10cSrcweir {
249cdf0e10cSrcweir     uno::Reference< awt::XWindow > xWin( m_xControl, uno::UNO_QUERY_THROW );
250cdf0e10cSrcweir     xWin->setFocus();
251cdf0e10cSrcweir }
252cdf0e10cSrcweir 
Move(double Left,double Top,const uno::Any & Width,const uno::Any & Height)253cdf0e10cSrcweir void SAL_CALL ScVbaControl::Move( double Left, double Top, const uno::Any& Width, const uno::Any& Height )
254cdf0e10cSrcweir     throw ( uno::RuntimeException )
255cdf0e10cSrcweir {
256cdf0e10cSrcweir     double nWidth = 0.0;
257cdf0e10cSrcweir     double nHeight = 0.0;
258cdf0e10cSrcweir 
259cdf0e10cSrcweir     setLeft( Left );
260cdf0e10cSrcweir     setTop( Top );
261cdf0e10cSrcweir 
262cdf0e10cSrcweir     if ( Width >>= nWidth )
263cdf0e10cSrcweir         setWidth( nWidth );
264cdf0e10cSrcweir 
265cdf0e10cSrcweir     if ( Height >>= nHeight )
266cdf0e10cSrcweir         setHeight( nHeight );
267cdf0e10cSrcweir }
268cdf0e10cSrcweir 
269cdf0e10cSrcweir rtl::OUString SAL_CALL
getControlSource()270cdf0e10cSrcweir ScVbaControl::getControlSource() throw (uno::RuntimeException)
271cdf0e10cSrcweir {
272cdf0e10cSrcweir // #FIXME I *hate* having these upstream differences
273cdf0e10cSrcweir // but this is necessary until I manage to upstream other
274cdf0e10cSrcweir // dependant parts
275cdf0e10cSrcweir #ifdef VBA_OOBUILD_HACK
276cdf0e10cSrcweir 	rtl::OUString sControlSource;
277cdf0e10cSrcweir 	uno::Reference< form::binding::XBindableValue > xBindable( m_xProps, uno::UNO_QUERY );
278cdf0e10cSrcweir 	if ( xBindable.is() )
279cdf0e10cSrcweir 	{
280cdf0e10cSrcweir 		try
281cdf0e10cSrcweir 		{
282cdf0e10cSrcweir 			uno::Reference< lang::XMultiServiceFactory > xFac( m_xModel, uno::UNO_QUERY_THROW );
283cdf0e10cSrcweir 			uno::Reference< beans::XPropertySet > xConvertor( xFac->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.table.CellAddressConversion" ))), uno::UNO_QUERY );
284cdf0e10cSrcweir 			uno::Reference< beans::XPropertySet > xProps( xBindable->getValueBinding(), uno::UNO_QUERY_THROW );
285cdf0e10cSrcweir 			table::CellAddress aAddress;
286cdf0e10cSrcweir 			xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BoundCell") ) ) >>= aAddress;
287cdf0e10cSrcweir 			xConvertor->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Address") ), uno::makeAny( aAddress ) );
288cdf0e10cSrcweir                 	xConvertor->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("XL_A1_Representation") ) ) >>= sControlSource;
289cdf0e10cSrcweir 		}
290cdf0e10cSrcweir 		catch( uno::Exception& )
291cdf0e10cSrcweir 		{
292cdf0e10cSrcweir 		}
293cdf0e10cSrcweir 	}
294cdf0e10cSrcweir 	return sControlSource;
295cdf0e10cSrcweir #else
296cdf0e10cSrcweir 	throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("getControlSource not supported") ), uno::Reference< uno::XInterface >()); // not supported
297cdf0e10cSrcweir #endif
298cdf0e10cSrcweir }
299cdf0e10cSrcweir 
300cdf0e10cSrcweir void SAL_CALL
setControlSource(const rtl::OUString & _controlsource)301cdf0e10cSrcweir ScVbaControl::setControlSource( const rtl::OUString& _controlsource ) throw (uno::RuntimeException)
302cdf0e10cSrcweir {
303cdf0e10cSrcweir #ifdef VBA_OOBUILD_HACK
304cdf0e10cSrcweir     rtl::OUString sEmpty;
305cdf0e10cSrcweir     svt::BindableControlHelper::ApplyListSourceAndBindableData( m_xModel, m_xProps, _controlsource, sEmpty );
306cdf0e10cSrcweir #else
307cdf0e10cSrcweir 	throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("setControlSource not supported ") ).concat( _controlsource ), uno::Reference< uno::XInterface >()); // not supported
308cdf0e10cSrcweir #endif
309cdf0e10cSrcweir }
310cdf0e10cSrcweir 
311cdf0e10cSrcweir rtl::OUString SAL_CALL
getRowSource()312cdf0e10cSrcweir ScVbaControl::getRowSource() throw (uno::RuntimeException)
313cdf0e10cSrcweir {
314cdf0e10cSrcweir #ifdef VBA_OOBUILD_HACK
315cdf0e10cSrcweir 	rtl::OUString sRowSource;
316cdf0e10cSrcweir 	uno::Reference< form::binding::XListEntrySink > xListSink( m_xProps, uno::UNO_QUERY );
317cdf0e10cSrcweir 	if ( xListSink.is() )
318cdf0e10cSrcweir     {
319cdf0e10cSrcweir 		try
320cdf0e10cSrcweir 		{
321cdf0e10cSrcweir 			uno::Reference< lang::XMultiServiceFactory > xFac( m_xModel, uno::UNO_QUERY_THROW );
322cdf0e10cSrcweir 			uno::Reference< beans::XPropertySet > xConvertor( xFac->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.table.CellRangeAddressConversion" ))), uno::UNO_QUERY );
323cdf0e10cSrcweir 
324cdf0e10cSrcweir 			uno::Reference< beans::XPropertySet > xProps( xListSink->getListEntrySource(), uno::UNO_QUERY_THROW );
325cdf0e10cSrcweir 			table::CellRangeAddress aAddress;
326cdf0e10cSrcweir 			xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CellRange") ) ) >>= aAddress;
327cdf0e10cSrcweir 			xConvertor->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Address")), uno::makeAny( aAddress ) );
328cdf0e10cSrcweir 			xConvertor->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("XL_A1_Representation") ) ) >>= sRowSource;
329cdf0e10cSrcweir 		}
330cdf0e10cSrcweir 		catch( uno::Exception& )
331cdf0e10cSrcweir 		{
332cdf0e10cSrcweir 		}
333cdf0e10cSrcweir 	}
334cdf0e10cSrcweir 	return sRowSource;
335cdf0e10cSrcweir #else
336cdf0e10cSrcweir 	throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("getRowSource not supported") ), uno::Reference< uno::XInterface >()); // not supported
337cdf0e10cSrcweir #endif
338cdf0e10cSrcweir }
339cdf0e10cSrcweir 
340cdf0e10cSrcweir void SAL_CALL
setRowSource(const rtl::OUString & _rowsource)341cdf0e10cSrcweir ScVbaControl::setRowSource( const rtl::OUString& _rowsource ) throw (uno::RuntimeException)
342cdf0e10cSrcweir {
343cdf0e10cSrcweir #ifdef VBA_OOBUILD_HACK
344cdf0e10cSrcweir     rtl::OUString sEmpty;
345cdf0e10cSrcweir     svt::BindableControlHelper::ApplyListSourceAndBindableData( m_xModel, m_xProps, sEmpty, _rowsource );
346cdf0e10cSrcweir #else
347cdf0e10cSrcweir 	throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("setRowSource not supported ") ).concat( _rowsource ), uno::Reference< uno::XInterface >()); // not supported
348cdf0e10cSrcweir #endif
349cdf0e10cSrcweir }
350cdf0e10cSrcweir 
351cdf0e10cSrcweir rtl::OUString SAL_CALL
getName()352cdf0e10cSrcweir ScVbaControl::getName() throw (uno::RuntimeException)
353cdf0e10cSrcweir {
354cdf0e10cSrcweir 	rtl::OUString sName;
355cdf0e10cSrcweir 	m_xProps->getPropertyValue
356cdf0e10cSrcweir             (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ) ) >>= sName;
357cdf0e10cSrcweir 	return sName;
358cdf0e10cSrcweir 
359cdf0e10cSrcweir }
360cdf0e10cSrcweir 
361cdf0e10cSrcweir void SAL_CALL
setName(const rtl::OUString & _name)362cdf0e10cSrcweir ScVbaControl::setName( const rtl::OUString& _name ) throw (uno::RuntimeException)
363cdf0e10cSrcweir {
364cdf0e10cSrcweir 	m_xProps->setPropertyValue
365cdf0e10cSrcweir             (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ), uno::makeAny( _name ) );
366cdf0e10cSrcweir     }
367cdf0e10cSrcweir 
368cdf0e10cSrcweir rtl::OUString SAL_CALL
getControlTipText()369cdf0e10cSrcweir ScVbaControl::getControlTipText() throw (css::uno::RuntimeException)
370cdf0e10cSrcweir {
371cdf0e10cSrcweir 	rtl::OUString sName;
372cdf0e10cSrcweir 	m_xProps->getPropertyValue
373cdf0e10cSrcweir             (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HelpText" ) ) ) >>= sName;
374cdf0e10cSrcweir 	return sName;
375cdf0e10cSrcweir }
376cdf0e10cSrcweir 
377cdf0e10cSrcweir void SAL_CALL
setControlTipText(const rtl::OUString & rsToolTip)378cdf0e10cSrcweir ScVbaControl::setControlTipText( const rtl::OUString& rsToolTip ) throw (css::uno::RuntimeException)
379cdf0e10cSrcweir {
380cdf0e10cSrcweir 	m_xProps->setPropertyValue
381cdf0e10cSrcweir             (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HelpText" ) ), uno::makeAny( rsToolTip ) );
382cdf0e10cSrcweir }
383cdf0e10cSrcweir 
getTag()384cdf0e10cSrcweir ::rtl::OUString SAL_CALL ScVbaControl::getTag()
385cdf0e10cSrcweir     throw (css::uno::RuntimeException)
386cdf0e10cSrcweir {
387cdf0e10cSrcweir     return m_aControlTag;
388cdf0e10cSrcweir }
389cdf0e10cSrcweir 
setTag(const::rtl::OUString & aTag)390cdf0e10cSrcweir void SAL_CALL ScVbaControl::setTag( const ::rtl::OUString& aTag )
391cdf0e10cSrcweir     throw (css::uno::RuntimeException)
392cdf0e10cSrcweir {
393cdf0e10cSrcweir     m_aControlTag = aTag;
394cdf0e10cSrcweir }
395cdf0e10cSrcweir 
getTabIndex()396cdf0e10cSrcweir sal_Int32 SAL_CALL ScVbaControl::getTabIndex() throw (uno::RuntimeException)
397cdf0e10cSrcweir {
398cdf0e10cSrcweir     return 1;
399cdf0e10cSrcweir }
400cdf0e10cSrcweir 
setTabIndex(sal_Int32)401cdf0e10cSrcweir void SAL_CALL ScVbaControl::setTabIndex( sal_Int32 /*nTabIndex*/ ) throw (uno::RuntimeException)
402cdf0e10cSrcweir {
403cdf0e10cSrcweir }
404cdf0e10cSrcweir 
405cdf0e10cSrcweir //ScVbaControlFactory
406cdf0e10cSrcweir 
createShapeControl(const uno::Reference<uno::XComponentContext> & xContext,const uno::Reference<drawing::XControlShape> & xControlShape,const uno::Reference<frame::XModel> & xModel)407cdf0e10cSrcweir /*static*/ uno::Reference< msforms::XControl > ScVbaControlFactory::createShapeControl(
408cdf0e10cSrcweir         const uno::Reference< uno::XComponentContext >& xContext,
409cdf0e10cSrcweir         const uno::Reference< drawing::XControlShape >& xControlShape,
410cdf0e10cSrcweir         const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException)
411cdf0e10cSrcweir {
412cdf0e10cSrcweir     uno::Reference< beans::XPropertySet > xProps( xControlShape->getControl(), uno::UNO_QUERY_THROW );
413cdf0e10cSrcweir     sal_Int32 nClassId = -1;
414cdf0e10cSrcweir     const static rtl::OUString sClassId( RTL_CONSTASCII_USTRINGPARAM("ClassId") );
415cdf0e10cSrcweir     xProps->getPropertyValue( sClassId ) >>= nClassId;
416cdf0e10cSrcweir     uno::Reference< XHelperInterface > xVbaParent; // #FIXME - should be worksheet I guess
417cdf0e10cSrcweir     uno::Reference< drawing::XShape > xShape( xControlShape, uno::UNO_QUERY_THROW );
418cdf0e10cSrcweir     ::std::auto_ptr< ConcreteXShapeGeometryAttributes > xGeoHelper( new ConcreteXShapeGeometryAttributes( xContext, xShape ) );
419cdf0e10cSrcweir 
420cdf0e10cSrcweir     switch( nClassId )
421cdf0e10cSrcweir     {
422cdf0e10cSrcweir         case form::FormComponentType::COMBOBOX:
423cdf0e10cSrcweir             return new ScVbaComboBox( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() );
424cdf0e10cSrcweir         case form::FormComponentType::COMMANDBUTTON:
425cdf0e10cSrcweir             return new ScVbaButton( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() );
426cdf0e10cSrcweir         case form::FormComponentType::FIXEDTEXT:
427cdf0e10cSrcweir             return new ScVbaLabel( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() );
428cdf0e10cSrcweir         case form::FormComponentType::TEXTFIELD:
429cdf0e10cSrcweir             return new ScVbaTextBox( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() );
430cdf0e10cSrcweir         case form::FormComponentType::RADIOBUTTON:
431cdf0e10cSrcweir             return new ScVbaRadioButton( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() );
432cdf0e10cSrcweir         case form::FormComponentType::LISTBOX:
433cdf0e10cSrcweir             return new ScVbaListBox( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() );
434cdf0e10cSrcweir         case form::FormComponentType::SPINBUTTON:
435cdf0e10cSrcweir             return new ScVbaSpinButton( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() );
436cdf0e10cSrcweir         case form::FormComponentType::IMAGECONTROL:
437cdf0e10cSrcweir             return new ScVbaImage( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() );
438cdf0e10cSrcweir     }
439cdf0e10cSrcweir     throw uno::RuntimeException( rtl::OUString::createFromAscii("Unsupported control." ), uno::Reference< uno::XInterface >() );
440cdf0e10cSrcweir }
441cdf0e10cSrcweir 
createUserformControl(const uno::Reference<uno::XComponentContext> & xContext,const uno::Reference<awt::XControl> & xControl,const uno::Reference<awt::XControl> & xDialog,const uno::Reference<frame::XModel> & xModel,double fOffsetX,double fOffsetY)442cdf0e10cSrcweir /*static*/ uno::Reference< msforms::XControl > ScVbaControlFactory::createUserformControl(
443cdf0e10cSrcweir         const uno::Reference< uno::XComponentContext >& xContext,
444cdf0e10cSrcweir         const uno::Reference< awt::XControl >& xControl,
445cdf0e10cSrcweir         const uno::Reference< awt::XControl >& xDialog,
446cdf0e10cSrcweir         const uno::Reference< frame::XModel >& xModel,
447cdf0e10cSrcweir         double fOffsetX, double fOffsetY ) throw (uno::RuntimeException)
448cdf0e10cSrcweir {
449cdf0e10cSrcweir     uno::Reference< beans::XPropertySet > xProps( xControl->getModel(), uno::UNO_QUERY_THROW );
450cdf0e10cSrcweir     uno::Reference< lang::XServiceInfo > xServiceInfo( xProps, uno::UNO_QUERY_THROW );
451cdf0e10cSrcweir     uno::Reference< msforms::XControl > xVBAControl;
452cdf0e10cSrcweir     uno::Reference< XHelperInterface > xVbaParent; // #FIXME - should be worksheet I guess
453cdf0e10cSrcweir     ::std::auto_ptr< UserFormGeometryHelper > xGeoHelper( new UserFormGeometryHelper( xContext, xControl, fOffsetX, fOffsetY ) );
454cdf0e10cSrcweir 
455cdf0e10cSrcweir     if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlCheckBoxModel") ) ) )
456cdf0e10cSrcweir         xVBAControl.set( new ScVbaCheckbox( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) );
457cdf0e10cSrcweir     else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlRadioButtonModel") ) ) )
458cdf0e10cSrcweir         xVBAControl.set( new ScVbaRadioButton( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) );
459cdf0e10cSrcweir     else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlEditModel") ) ) )
460cdf0e10cSrcweir         xVBAControl.set( new ScVbaTextBox( xVbaParent, xContext, xControl, xModel, xGeoHelper.release(), true ) );
461cdf0e10cSrcweir     else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlButtonModel") ) ) )
462cdf0e10cSrcweir     {
463cdf0e10cSrcweir         sal_Bool bToggle = sal_False;
464cdf0e10cSrcweir         xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Toggle") ) ) >>= bToggle;
465cdf0e10cSrcweir         if ( bToggle )
466cdf0e10cSrcweir             xVBAControl.set( new ScVbaToggleButton( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) );
467cdf0e10cSrcweir         else
468cdf0e10cSrcweir             xVBAControl.set( new ScVbaButton( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) );
469cdf0e10cSrcweir     }
470cdf0e10cSrcweir     else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlComboBoxModel") ) ) )
471cdf0e10cSrcweir         xVBAControl.set( new ScVbaComboBox( xVbaParent, xContext, xControl, xModel, xGeoHelper.release(), true ) );
472cdf0e10cSrcweir     else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlListBoxModel") ) ) )
473cdf0e10cSrcweir         xVBAControl.set( new ScVbaListBox( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) );
474cdf0e10cSrcweir     else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlFixedTextModel") ) ) )
475cdf0e10cSrcweir         xVBAControl.set( new ScVbaLabel( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) );
476cdf0e10cSrcweir     else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlImageControlModel") ) ) )
477cdf0e10cSrcweir         xVBAControl.set( new ScVbaImage( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) );
478cdf0e10cSrcweir     else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlProgressBarModel") ) ) )
479cdf0e10cSrcweir         xVBAControl.set( new ScVbaProgressBar( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) );
480cdf0e10cSrcweir     else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlGroupBoxModel") ) ) )
481cdf0e10cSrcweir         xVBAControl.set( new ScVbaFrame( xVbaParent, xContext, xControl, xModel, xGeoHelper.release(), xDialog ) );
482cdf0e10cSrcweir     else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlScrollBarModel") ) ) )
483cdf0e10cSrcweir         xVBAControl.set( new ScVbaScrollBar( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) );
484cdf0e10cSrcweir     else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoMultiPageModel") ) ) )
485cdf0e10cSrcweir         xVBAControl.set( new ScVbaMultiPage( xVbaParent, xContext, xControl, xModel, xGeoHelper.release(), xDialog ) );
486cdf0e10cSrcweir     else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlSpinButtonModel") ) ) )
487cdf0e10cSrcweir         xVBAControl.set( new ScVbaSpinButton( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) );
488cdf0e10cSrcweir     else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.custom.awt.UnoControlSystemAXContainerModel") ) ) )
489cdf0e10cSrcweir         xVBAControl.set( new VbaSystemAXControl( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) );
490cdf0e10cSrcweir 
491cdf0e10cSrcweir     if( xVBAControl.is() )
492cdf0e10cSrcweir         return xVBAControl;
493cdf0e10cSrcweir     throw uno::RuntimeException( rtl::OUString::createFromAscii("Unsupported control." ), uno::Reference< uno::XInterface >() );
494cdf0e10cSrcweir }
495cdf0e10cSrcweir 
496cdf0e10cSrcweir rtl::OUString&
getServiceImplName()497cdf0e10cSrcweir ScVbaControl::getServiceImplName()
498cdf0e10cSrcweir {
499cdf0e10cSrcweir 	static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaControl") );
500cdf0e10cSrcweir 	return sImplName;
501cdf0e10cSrcweir }
502cdf0e10cSrcweir 
503cdf0e10cSrcweir uno::Sequence< rtl::OUString >
getServiceNames()504cdf0e10cSrcweir ScVbaControl::getServiceNames()
505cdf0e10cSrcweir {
506cdf0e10cSrcweir 	static uno::Sequence< rtl::OUString > aServiceNames;
507cdf0e10cSrcweir 	if ( aServiceNames.getLength() == 0 )
508cdf0e10cSrcweir 	{
509cdf0e10cSrcweir 		aServiceNames.realloc( 1 );
510cdf0e10cSrcweir 		aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Control" ) );
511cdf0e10cSrcweir     }
512cdf0e10cSrcweir 	return aServiceNames;
513cdf0e10cSrcweir }
514cdf0e10cSrcweir 
515cdf0e10cSrcweir 
516cdf0e10cSrcweir 
517cdf0e10cSrcweir typedef cppu::WeakImplHelper1< XControlProvider > ControlProvider_BASE;
518cdf0e10cSrcweir class ControlProviderImpl : public ControlProvider_BASE
519cdf0e10cSrcweir {
520cdf0e10cSrcweir     uno::Reference< uno::XComponentContext > m_xCtx;
521cdf0e10cSrcweir public:
ControlProviderImpl(const uno::Reference<uno::XComponentContext> & xCtx)522cdf0e10cSrcweir     ControlProviderImpl( const uno::Reference< uno::XComponentContext >& xCtx ) : m_xCtx( xCtx ) {}
523cdf0e10cSrcweir     virtual uno::Reference< msforms::XControl > SAL_CALL createControl( const uno::Reference< drawing::XControlShape >& xControl, const uno::Reference< frame::XModel >& xDocOwner ) throw (uno::RuntimeException);
524cdf0e10cSrcweir };
525cdf0e10cSrcweir 
526cdf0e10cSrcweir uno::Reference< msforms::XControl > SAL_CALL
createControl(const uno::Reference<drawing::XControlShape> & xControlShape,const uno::Reference<frame::XModel> & xDocOwner)527cdf0e10cSrcweir ControlProviderImpl::createControl( const uno::Reference< drawing::XControlShape >& xControlShape, const uno::Reference< frame::XModel >& xDocOwner ) throw (uno::RuntimeException)
528cdf0e10cSrcweir {
529cdf0e10cSrcweir 	uno::Reference< msforms::XControl > xControlToReturn;
530cdf0e10cSrcweir 	if ( xControlShape.is() )
531cdf0e10cSrcweir 		xControlToReturn = ScVbaControlFactory::createShapeControl( m_xCtx, xControlShape, xDocOwner );
532cdf0e10cSrcweir 	return xControlToReturn;
533cdf0e10cSrcweir 
534cdf0e10cSrcweir }
535cdf0e10cSrcweir 
536cdf0e10cSrcweir namespace controlprovider
537cdf0e10cSrcweir {
538cdf0e10cSrcweir namespace sdecl = comphelper::service_decl;
539cdf0e10cSrcweir sdecl::class_<ControlProviderImpl, sdecl::with_args<false> > serviceImpl;
540cdf0e10cSrcweir extern sdecl::ServiceDecl const serviceDecl(
541cdf0e10cSrcweir     serviceImpl,
542cdf0e10cSrcweir     "ControlProviderImpl",
543cdf0e10cSrcweir     "ooo.vba.ControlProvider" );
544cdf0e10cSrcweir }
545cdf0e10cSrcweir 
546cdf0e10cSrcweir 
547