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