1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #include <com/sun/star/form/FormComponentType.hpp>
20 #include <com/sun/star/awt/XControlModel.hpp>
21 #include <com/sun/star/awt/XControl.hpp>
22 #include <com/sun/star/awt/XWindow2.hpp>
23 #include <com/sun/star/awt/XActionListener.hpp>
24 #include <com/sun/star/lang/XEventListener.hpp>
25 #include <com/sun/star/drawing/XShape.hpp>
26 #include <com/sun/star/drawing/XControlShape.hpp>
27 #include <com/sun/star/frame/XModel.hpp>
28 #include <com/sun/star/view/XControlAccess.hpp>
29 #include <com/sun/star/container/XChild.hpp>
30 #include <com/sun/star/form/binding/XBindableValue.hpp>
31 #include <com/sun/star/form/binding/XListEntrySink.hpp>
32 #include <com/sun/star/table/CellAddress.hpp>
33 #include <com/sun/star/table/CellRangeAddress.hpp>
34 #include <com/sun/star/script/XScriptListener.hpp>
35 #include <com/sun/star/document/XCodeNameQuery.hpp>
36 #include <com/sun/star/form/XChangeListener.hpp>
37 #include <ooo/vba/XControlProvider.hpp>
38 #include <ooo/vba/msforms/fmMousePointer.hpp>
39 #include <svtools/bindablecontrolhelper.hxx>
40 #include "vbacontrol.hxx"
41 #include "vbacombobox.hxx"
42 #include "vbabutton.hxx"
43 #include "vbalabel.hxx"
44 #include "vbatextbox.hxx"
45 #include "vbaradiobutton.hxx"
46 #include "vbalistbox.hxx"
47 #include "vbatogglebutton.hxx"
48 #include "vbacheckbox.hxx"
49 #include "vbaframe.hxx"
50 #include "vbascrollbar.hxx"
51 #include "vbaprogressbar.hxx"
52 #include "vbamultipage.hxx"
53 #include "vbaspinbutton.hxx"
54 #include "vbasystemaxcontrol.hxx"
55 #include "vbaimage.hxx"
56 #include <vbahelper/helperdecl.hxx>
57 #include <toolkit/helper/vclunohelper.hxx>
58 #include <vcl/window.hxx>
59 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
60 #include <com/sun/star/form/XFormsSupplier.hpp>
61 #include <svx/svdobj.hxx>
63 using namespace com::sun::star
;
64 using namespace ooo::vba
;
66 uno::Reference
< css::awt::XWindowPeer
>
67 ScVbaControl::getWindowPeer() throw (uno::RuntimeException
)
69 uno::Reference
< drawing::XControlShape
> xControlShape( m_xControl
, uno::UNO_QUERY
);
71 uno::Reference
< awt::XControlModel
> xControlModel
;
72 uno::Reference
< css::awt::XWindowPeer
> xWinPeer
;
73 if ( !xControlShape
.is() )
75 // would seem to be a Userform control
76 uno::Reference
< awt::XControl
> xControl( m_xControl
, uno::UNO_QUERY_THROW
);
77 xWinPeer
= xControl
->getPeer();
81 xControlModel
.set( xControlShape
->getControl(), uno::UNO_QUERY_THROW
);
83 uno::Reference
< view::XControlAccess
> xControlAccess( m_xModel
->getCurrentController(), uno::UNO_QUERY_THROW
);
86 uno::Reference
< awt::XControl
> xControl( xControlAccess
->getControl( xControlModel
), uno::UNO_QUERY
);
87 xWinPeer
= xControl
->getPeer();
89 catch(const uno::Exception
&)
91 throw uno::RuntimeException( "The Control does not exsit" , uno::Reference
< uno::XInterface
>() );
96 //ScVbaControlListener
97 class ScVbaControlListener
: public cppu::WeakImplHelper1
< lang::XEventListener
>
100 ScVbaControl
*pControl
;
102 ScVbaControlListener( ScVbaControl
*pTmpControl
);
103 virtual ~ScVbaControlListener();
104 virtual void SAL_CALL
disposing( const lang::EventObject
& rEventObject
) throw( uno::RuntimeException
);
107 ScVbaControlListener::ScVbaControlListener( ScVbaControl
*pTmpControl
): pControl( pTmpControl
)
111 ScVbaControlListener::~ScVbaControlListener()
116 ScVbaControlListener::disposing( const lang::EventObject
& ) throw( uno::RuntimeException
)
120 pControl
->removeResouce();
127 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
), bIsDialog(false), m_xControl( xControl
), m_xModel( xModel
)
130 m_xEventListener
.set( new ScVbaControlListener( this ) );
131 setGeometryHelper( pGeomHelper
);
132 uno::Reference
< lang::XComponent
> xComponent( m_xControl
, uno::UNO_QUERY_THROW
);
133 xComponent
->addEventListener( m_xEventListener
);
136 uno::Reference
< drawing::XControlShape
> xControlShape( m_xControl
, uno::UNO_QUERY
) ;
137 uno::Reference
< awt::XControl
> xUserFormControl( m_xControl
, uno::UNO_QUERY
) ;
138 if ( xControlShape
.is() ) // form control
140 m_xProps
.set( xControlShape
->getControl(), uno::UNO_QUERY_THROW
);
141 OUString sDefaultControl
;
142 m_xProps
->getPropertyValue( "DefaultControl" ) >>= sDefaultControl
;
143 uno::Reference
< lang::XMultiComponentFactory
> xMFac( mxContext
->getServiceManager(), uno::UNO_QUERY_THROW
);
144 m_xEmptyFormControl
.set( xMFac
->createInstanceWithContext( sDefaultControl
, mxContext
), uno::UNO_QUERY_THROW
);
146 else if ( xUserFormControl
.is() ) // userform control
148 m_xProps
.set( xUserFormControl
->getModel(), uno::UNO_QUERY_THROW
);
153 ScVbaControl::~ScVbaControl()
155 if( m_xControl
.is() )
157 uno::Reference
< lang::XComponent
> xComponent( m_xControl
, uno::UNO_QUERY_THROW
);
158 xComponent
->removeEventListener( m_xEventListener
);
163 ScVbaControl::setGeometryHelper( AbstractGeometryAttributes
* pHelper
)
165 mpGeometryHelper
.reset( pHelper
);
168 void ScVbaControl::removeResouce() throw( uno::RuntimeException
)
170 uno::Reference
< lang::XComponent
> xComponent( m_xControl
, uno::UNO_QUERY_THROW
);
171 xComponent
->removeEventListener( m_xEventListener
);
176 //In design model has different behavior
177 sal_Bool SAL_CALL
ScVbaControl::getEnabled() throw (uno::RuntimeException
)
179 uno::Any aValue
= m_xProps
->getPropertyValue ( "Enabled" );
180 sal_Bool bRet
= false;
185 void SAL_CALL
ScVbaControl::setEnabled( sal_Bool bVisible
) throw (uno::RuntimeException
)
187 uno::Any
aValue( bVisible
);
188 m_xProps
->setPropertyValue( "Enabled" , aValue
);
192 sal_Bool SAL_CALL
ScVbaControl::getVisible() throw (uno::RuntimeException
)
194 sal_Bool
bVisible( sal_True
);
195 m_xProps
->getPropertyValue ( "EnableVisible" ) >>= bVisible
;
196 uno::Reference
< drawing::XControlShape
> xControlShape( m_xControl
, uno::UNO_QUERY
);
197 if ( xControlShape
.is() )
199 bool bEnableVisible
= bVisible
;
200 uno::Reference
< beans::XPropertySet
> xProps( m_xControl
, uno::UNO_QUERY_THROW
);
201 xProps
->getPropertyValue ( "Visible" ) >>= bVisible
;
202 bVisible
= bVisible
&& bEnableVisible
;
205 m_xProps
->getPropertyValue ( "EnableVisible" ) >>= bVisible
;
209 void SAL_CALL
ScVbaControl::setVisible( sal_Bool bVisible
) throw (uno::RuntimeException
)
211 uno::Any
aValue( bVisible
);
212 m_xProps
->setPropertyValue( "EnableVisible" , aValue
);
213 uno::Reference
< drawing::XControlShape
> xControlShape( m_xControl
, uno::UNO_QUERY
);
214 if ( xControlShape
.is() )
216 uno::Reference
< beans::XPropertySet
> xProps( m_xControl
, uno::UNO_QUERY_THROW
);
217 xProps
->setPropertyValue ( "Visible", aValue
);
220 double SAL_CALL
ScVbaControl::getHeight() throw (uno::RuntimeException
)
222 return mpGeometryHelper
->getHeight();
224 void SAL_CALL
ScVbaControl::setHeight( double _height
) throw (uno::RuntimeException
)
226 mpGeometryHelper
->setHeight( _height
);
229 double SAL_CALL
ScVbaControl::getWidth() throw (uno::RuntimeException
)
231 return mpGeometryHelper
->getWidth();
233 void SAL_CALL
ScVbaControl::setWidth( double _width
) throw (uno::RuntimeException
)
235 mpGeometryHelper
->setWidth( _width
);
239 ScVbaControl::getLeft() throw (uno::RuntimeException
)
241 return mpGeometryHelper
->getLeft();
245 ScVbaControl::setLeft( double _left
) throw (uno::RuntimeException
)
247 mpGeometryHelper
->setLeft( _left
);
251 ScVbaControl::getTop() throw (uno::RuntimeException
)
253 return mpGeometryHelper
->getTop();
257 ScVbaControl::setTop( double _top
) throw (uno::RuntimeException
)
259 mpGeometryHelper
->setTop( _top
);
262 uno::Reference
< uno::XInterface
> SAL_CALL
263 ScVbaControl::getObject() throw (uno::RuntimeException
)
265 uno::Reference
< msforms::XControl
> xRet( this );
269 void SAL_CALL
ScVbaControl::SetFocus() throw (uno::RuntimeException
)
271 uno::Reference
< awt::XWindow
> xWin( m_xControl
, uno::UNO_QUERY_THROW
);
275 void SAL_CALL
ScVbaControl::Move( double Left
, double Top
, const uno::Any
& Width
, const uno::Any
& Height
)
276 throw ( uno::RuntimeException
)
279 double nHeight
= 0.0;
284 if ( Width
>>= nWidth
)
287 if ( Height
>>= nHeight
)
288 setHeight( nHeight
);
292 ScVbaControl::getControlSource() throw (uno::RuntimeException
)
294 // #FIXME I *hate* having these upstream differences
295 // but this is necessary until I manage to upstream other
297 OUString sControlSource
;
298 uno::Reference
< form::binding::XBindableValue
> xBindable( m_xProps
, uno::UNO_QUERY
);
299 if ( xBindable
.is() )
303 uno::Reference
< lang::XMultiServiceFactory
> xFac( m_xModel
, uno::UNO_QUERY_THROW
);
304 uno::Reference
< beans::XPropertySet
> xConvertor( xFac
->createInstance( "com.sun.star.table.CellAddressConversion" ), uno::UNO_QUERY
);
305 uno::Reference
< beans::XPropertySet
> xProps( xBindable
->getValueBinding(), uno::UNO_QUERY_THROW
);
306 table::CellAddress aAddress
;
307 xProps
->getPropertyValue( "BoundCell" ) >>= aAddress
;
308 xConvertor
->setPropertyValue( "Address" , uno::makeAny( aAddress
) );
309 xConvertor
->getPropertyValue( "XLA1Representation" ) >>= sControlSource
;
311 catch(const uno::Exception
&)
315 return sControlSource
;
319 ScVbaControl::setControlSource( const OUString
& _controlsource
) throw (uno::RuntimeException
)
322 // afaik this is only relevant for Excel documents ( and we need to set up a
323 // reference tab in case no Sheet is specified in "_controlsource"
324 // Can't use the active sheet either, code may of course access
325 uno::Reference
< drawing::XDrawPagesSupplier
> xSupplier( m_xModel
, uno::UNO_QUERY_THROW
);
326 uno::Reference
< container::XIndexAccess
> xIndex( xSupplier
->getDrawPages(), uno::UNO_QUERY_THROW
);
327 sal_Int32 nLen
= xIndex
->getCount();
328 bool bMatched
= false;
329 sal_Int16 nRefTab
= 0;
330 for ( sal_Int32 index
= 0; index
< nLen
; ++index
)
334 uno::Reference
< form::XFormsSupplier
> xFormSupplier( xIndex
->getByIndex( index
), uno::UNO_QUERY_THROW
);
335 uno::Reference
< container::XIndexAccess
> xFormIndex( xFormSupplier
->getForms(), uno::UNO_QUERY_THROW
);
336 // get the www-standard container
337 uno::Reference
< container::XIndexAccess
> xFormControls( xFormIndex
->getByIndex(0), uno::UNO_QUERY_THROW
);
338 sal_Int32 nCntrls
= xFormControls
->getCount();
339 for( sal_Int32 cIndex
= 0; cIndex
< nCntrls
; ++cIndex
)
341 uno::Reference
< uno::XInterface
> xControl( xFormControls
->getByIndex( cIndex
), uno::UNO_QUERY_THROW
);
342 bMatched
= ( m_xProps
== xControl
);
350 catch( uno::Exception
& ) {}
355 svt::BindableControlHelper::ApplyListSourceAndBindableData( m_xModel
, m_xProps
, _controlsource
, sEmpty
, sal_uInt16( nRefTab
) );
359 ScVbaControl::getRowSource() throw (uno::RuntimeException
)
362 uno::Reference
< form::binding::XListEntrySink
> xListSink( m_xProps
, uno::UNO_QUERY
);
363 if ( xListSink
.is() )
367 uno::Reference
< lang::XMultiServiceFactory
> xFac( m_xModel
, uno::UNO_QUERY_THROW
);
368 uno::Reference
< beans::XPropertySet
> xConvertor( xFac
->createInstance( "com.sun.star.table.CellRangeAddressConversion" ), uno::UNO_QUERY
);
370 uno::Reference
< beans::XPropertySet
> xProps( xListSink
->getListEntrySource(), uno::UNO_QUERY_THROW
);
371 table::CellRangeAddress aAddress
;
372 xProps
->getPropertyValue( "CellRange" ) >>= aAddress
;
373 xConvertor
->setPropertyValue( "Address" , uno::makeAny( aAddress
) );
374 xConvertor
->getPropertyValue( "XLA1Representation" ) >>= sRowSource
;
376 catch(const uno::Exception
&)
384 ScVbaControl::setRowSource( const OUString
& _rowsource
) throw (uno::RuntimeException
)
387 svt::BindableControlHelper::ApplyListSourceAndBindableData( m_xModel
, m_xProps
, sEmpty
, _rowsource
);
391 ScVbaControl::getName() throw (uno::RuntimeException
)
394 m_xProps
->getPropertyValue( "Name" ) >>= sName
;
400 ScVbaControl::setName( const OUString
& _name
) throw (uno::RuntimeException
)
402 m_xProps
->setPropertyValue( "Name" , uno::makeAny( _name
) );
406 ScVbaControl::getControlTipText() throw (css::uno::RuntimeException
)
409 m_xProps
->getPropertyValue( "HelpText" ) >>= sName
;
414 ScVbaControl::setControlTipText( const OUString
& rsToolTip
) throw (css::uno::RuntimeException
)
416 m_xProps
->setPropertyValue( "HelpText" , uno::makeAny( rsToolTip
) );
419 OUString SAL_CALL
ScVbaControl::getTag()
420 throw (css::uno::RuntimeException
)
422 return m_aControlTag
;
425 void SAL_CALL
ScVbaControl::setTag( const OUString
& aTag
)
426 throw (css::uno::RuntimeException
)
428 m_aControlTag
= aTag
;
431 ::sal_Int32 SAL_CALL
ScVbaControl::getForeColor() throw (::com::sun::star::uno::RuntimeException
)
433 sal_Int32 nForeColor
= -1;
434 m_xProps
->getPropertyValue( "TextColor" ) >>= nForeColor
;
435 return OORGBToXLRGB( nForeColor
);
438 void SAL_CALL
ScVbaControl::setForeColor( ::sal_Int32 _forecolor
) throw (::com::sun::star::uno::RuntimeException
)
440 m_xProps
->setPropertyValue( "TextColor" , uno::makeAny( XLRGBToOORGB( _forecolor
) ) );
445 long msoPointerStyle
;
446 PointerStyle loPointStyle
;
449 // 1 -> 1 map of styles ( some dubious choices in there though )
450 PointerStyles styles
[] = {
451 /// assuming pointer default is Arrow
452 { msforms::fmMousePointer::fmMousePointerDefault
, POINTER_ARROW
},
453 { msforms::fmMousePointer::fmMousePointerArrow
, POINTER_ARROW
},
454 { msforms::fmMousePointer::fmMousePointerCross
, POINTER_CROSS
},
455 { msforms::fmMousePointer::fmMousePointerIBeam
, POINTER_TEXT
},
456 { msforms::fmMousePointer::fmMousePointerSizeNESW
, POINTER_AUTOSCROLL_NSWE
}, // #TODO not correct, need to check, need to find the right one
457 { msforms::fmMousePointer::fmMousePointerSizeNS
, POINTER_AUTOSCROLL_NS
},
458 { msforms::fmMousePointer::fmMousePointerSizeNWSE
, POINTER_AUTOSCROLL_NSWE
}, // #TODO not correct, need to check, need to find the right one
459 { msforms::fmMousePointer::fmMousePointerSizeWE
, POINTER_AUTOSCROLL_WE
},
460 { msforms::fmMousePointer::fmMousePointerUpArrow
, POINTER_WINDOW_NSIZE
},
461 { msforms::fmMousePointer::fmMousePointerHourGlass
, POINTER_WAIT
},
462 { msforms::fmMousePointer::fmMousePointerNoDrop
, POINTER_NOTALLOWED
},
463 { msforms::fmMousePointer::fmMousePointerAppStarting
, POINTER_WAIT
},
464 { msforms::fmMousePointer::fmMousePointerHelp
, POINTER_HELP
},
465 { msforms::fmMousePointer::fmMousePointerSizeAll
, POINTER_CROSS
},
466 { msforms::fmMousePointer::fmMousePointerCustom
, POINTER_ARROW
}, // not supported I guess
470 static long lcl_loPointerToMsoPointer( PointerStyle eType
)
472 long nRet
= msforms::fmMousePointer::fmMousePointerDefault
;
473 for ( int i
= 0, nElems
= SAL_N_ELEMENTS( styles
); i
< nElems
; ++i
)
475 if ( styles
[ i
].loPointStyle
== eType
)
477 nRet
= styles
[ i
].msoPointerStyle
;
484 static Pointer
lcl_msoPointerToLOPointer( long msoPointerStyle
)
486 Pointer
aPointer( POINTER_ARROW
);
487 for ( int i
= 0, nElems
= SAL_N_ELEMENTS( styles
); i
< nElems
; ++i
)
489 if ( styles
[ i
].msoPointerStyle
== msoPointerStyle
)
491 aPointer
= Pointer( styles
[ i
].loPointStyle
);
499 ScVbaControl::getMousePointer() throw (::com::sun::star::uno::RuntimeException
)
501 PointerStyle eType
= POINTER_ARROW
; // default ?
502 Window
* pWindow
= VCLUnoHelper::GetWindow( getWindowPeer() );
505 eType
= pWindow
->GetPointer().GetStyle();
507 return lcl_loPointerToMsoPointer( eType
);
511 ScVbaControl::setMousePointer( ::sal_Int32 _mousepointer
) throw (::com::sun::star::uno::RuntimeException
)
513 Window
* pWindow
= VCLUnoHelper::GetWindow( getWindowPeer() );
516 Pointer
aPointer( POINTER_ARROW
);
517 aPointer
= lcl_msoPointerToLOPointer( _mousepointer
);
518 pWindow
->SetPointer( aPointer
);
522 void SAL_CALL
ScVbaControl::fireEvent( const script::ScriptEvent
& rEvt
) throw (uno::RuntimeException
)
524 script::ScriptEvent
evt( rEvt
);
525 uno::Reference
<lang::XMultiComponentFactory
> xServiceManager( mxContext
->getServiceManager(), uno::UNO_QUERY_THROW
);
526 uno::Reference
< script::XScriptListener
> xScriptListener( xServiceManager
->createInstanceWithContext( "ooo.vba.EventListener" , mxContext
), uno::UNO_QUERY_THROW
);
528 uno::Reference
< beans::XPropertySet
> xProps( xScriptListener
, uno::UNO_QUERY_THROW
);
529 xProps
->setPropertyValue( "Model" , uno::makeAny( m_xModel
) );
531 // handling for sheet control
532 uno::Reference
< msforms::XControl
> xThisControl( this );
535 evt
.Arguments
.realloc( 1 );
536 lang::EventObject aEvt
;
538 uno::Reference
< drawing::XControlShape
> xControlShape( m_xControl
, uno::UNO_QUERY
) ;
539 uno::Reference
< awt::XControl
> xControl( m_xControl
, uno::UNO_QUERY
) ;
541 if ( xControlShape
.is() )
543 evt
.Source
= xControlShape
;
544 aEvt
.Source
= m_xEmptyFormControl
;
545 // Set up proper scriptcode
546 uno::Reference
< lang::XMultiServiceFactory
> xDocFac( m_xModel
, uno::UNO_QUERY_THROW
);
547 uno::Reference
< document::XCodeNameQuery
> xNameQuery( xDocFac
->createInstance( "ooo.vba.VBACodeNameProvider" ), uno::UNO_QUERY_THROW
);
548 uno::Reference
< uno::XInterface
> xIf( xControlShape
->getControl(), uno::UNO_QUERY_THROW
);
549 evt
.ScriptCode
= xNameQuery
->getCodeNameForObject( xIf
);
550 // handle if we passed in our own arguments
551 if ( !rEvt
.Arguments
.getLength() )
552 evt
.Arguments
[ 0 ] = uno::makeAny( aEvt
);
553 xScriptListener
->firing( evt
);
557 if ( xControl
.is() ) // normal control ( from dialog/userform )
559 // #FIXME We should probably store a reference to the
560 // parent dialog/userform here ( other wise the name of
561 // dialog could be changed and we won't be aware of it.
562 // ( OTOH this is probably an unlikely scenario )
563 evt
.Source
= xThisControl
;
564 aEvt
.Source
= xControl
;
565 evt
.ScriptCode
= m_sLibraryAndCodeName
;
566 evt
.Arguments
[ 0 ] = uno::makeAny( aEvt
);
567 xScriptListener
->firing( evt
);
571 catch(const uno::Exception
&)
575 void ScVbaControl::fireChangeEvent()
577 script::ScriptEvent evt
;
578 evt
.ScriptType
= "VBAInterop";
579 evt
.ListenerType
= form::XChangeListener::static_type(0);
580 evt
.MethodName
= "changed";
584 void ScVbaControl::fireClickEvent()
586 script::ScriptEvent evt
;
587 evt
.ScriptType
= "VBAInterop";
588 evt
.ListenerType
= awt::XActionListener::static_type(0);
589 evt
.MethodName
= "actionPerformed";
593 sal_Int32 SAL_CALL
ScVbaControl::getTabIndex() throw (uno::RuntimeException
)
598 void SAL_CALL
ScVbaControl::setTabIndex( sal_Int32
/*nTabIndex*/ ) throw (uno::RuntimeException
)
602 //ScVbaControlFactory
604 /*static*/ uno::Reference
< msforms::XControl
> ScVbaControlFactory::createShapeControl(
605 const uno::Reference
< uno::XComponentContext
>& xContext
,
606 const uno::Reference
< drawing::XControlShape
>& xControlShape
,
607 const uno::Reference
< frame::XModel
>& xModel
) throw (uno::RuntimeException
)
609 uno::Reference
< beans::XPropertySet
> xProps( xControlShape
->getControl(), uno::UNO_QUERY_THROW
);
610 sal_Int32 nClassId
= -1;
611 const static OUString
sClassId( "ClassId" );
612 xProps
->getPropertyValue( sClassId
) >>= nClassId
;
613 uno::Reference
< XHelperInterface
> xVbaParent
; // #FIXME - should be worksheet I guess
614 uno::Reference
< drawing::XShape
> xShape( xControlShape
, uno::UNO_QUERY_THROW
);
615 ::std::auto_ptr
< ConcreteXShapeGeometryAttributes
> xGeoHelper( new ConcreteXShapeGeometryAttributes( xContext
, xShape
) );
618 case form::FormComponentType::COMBOBOX
:
619 return new ScVbaComboBox( xVbaParent
, xContext
, xControlShape
, xModel
, xGeoHelper
.release() );
620 case form::FormComponentType::COMMANDBUTTON
:
622 sal_Bool bToggle
= sal_False
;
623 xProps
->getPropertyValue( "Toggle" ) >>= bToggle
;
625 return new ScVbaToggleButton( xVbaParent
, xContext
, xControlShape
, xModel
, xGeoHelper
.release() );
627 return new ScVbaButton( xVbaParent
, xContext
, xControlShape
, xModel
, xGeoHelper
.release() );
629 case form::FormComponentType::FIXEDTEXT
:
630 return new ScVbaLabel( xVbaParent
, xContext
, xControlShape
, xModel
, xGeoHelper
.release() );
631 case form::FormComponentType::TEXTFIELD
:
632 return new ScVbaTextBox( xVbaParent
, xContext
, xControlShape
, xModel
, xGeoHelper
.release() );
633 case form::FormComponentType::CHECKBOX
:
634 return new ScVbaCheckbox( xVbaParent
, xContext
, xControlShape
, xModel
, xGeoHelper
.release() );
635 case form::FormComponentType::RADIOBUTTON
:
636 return new ScVbaRadioButton( xVbaParent
, xContext
, xControlShape
, xModel
, xGeoHelper
.release() );
637 case form::FormComponentType::LISTBOX
:
638 return new ScVbaListBox( xVbaParent
, xContext
, xControlShape
, xModel
, xGeoHelper
.release() );
639 case form::FormComponentType::SPINBUTTON
:
640 return new ScVbaSpinButton( xVbaParent
, xContext
, xControlShape
, xModel
, xGeoHelper
.release() );
641 case form::FormComponentType::IMAGECONTROL
:
642 return new ScVbaImage( xVbaParent
, xContext
, xControlShape
, xModel
, xGeoHelper
.release() );
643 case form::FormComponentType::SCROLLBAR
:
644 return new ScVbaScrollBar( xVbaParent
, xContext
, xControlShape
, xModel
, xGeoHelper
.release() );
646 throw uno::RuntimeException( "Unsupported control." , uno::Reference
< uno::XInterface
>() );
649 /*static*/ uno::Reference
< msforms::XControl
> ScVbaControlFactory::createUserformControl(
650 const uno::Reference
< uno::XComponentContext
>& xContext
,
651 const uno::Reference
< awt::XControl
>& xControl
,
652 const uno::Reference
< awt::XControl
>& xDialog
,
653 const uno::Reference
< frame::XModel
>& xModel
,
654 double fOffsetX
, double fOffsetY
) throw (uno::RuntimeException
)
656 uno::Reference
< beans::XPropertySet
> xProps( xControl
->getModel(), uno::UNO_QUERY_THROW
);
657 uno::Reference
< lang::XServiceInfo
> xServiceInfo( xProps
, uno::UNO_QUERY_THROW
);
658 uno::Reference
< msforms::XControl
> xVBAControl
;
659 uno::Reference
< XHelperInterface
> xVbaParent
; // #FIXME - should be worksheet I guess
660 ::std::auto_ptr
< UserFormGeometryHelper
> xGeoHelper( new UserFormGeometryHelper( xContext
, xControl
, fOffsetX
, fOffsetY
) );
662 if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlCheckBoxModel" ) )
663 xVBAControl
.set( new ScVbaCheckbox( xVbaParent
, xContext
, xControl
, xModel
, xGeoHelper
.release() ) );
664 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlRadioButtonModel" ) )
665 xVBAControl
.set( new ScVbaRadioButton( xVbaParent
, xContext
, xControl
, xModel
, xGeoHelper
.release() ) );
666 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlEditModel" ) )
667 xVBAControl
.set( new ScVbaTextBox( xVbaParent
, xContext
, xControl
, xModel
, xGeoHelper
.release(), true ) );
668 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlButtonModel" ) )
670 sal_Bool bToggle
= sal_False
;
671 xProps
->getPropertyValue( "Toggle" ) >>= bToggle
;
673 xVBAControl
.set( new ScVbaToggleButton( xVbaParent
, xContext
, xControl
, xModel
, xGeoHelper
.release() ) );
675 xVBAControl
.set( new ScVbaButton( xVbaParent
, xContext
, xControl
, xModel
, xGeoHelper
.release() ) );
677 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlComboBoxModel" ) )
678 xVBAControl
.set( new ScVbaComboBox( xVbaParent
, xContext
, xControl
, xModel
, xGeoHelper
.release() ) );
679 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlListBoxModel" ) )
680 xVBAControl
.set( new ScVbaListBox( xVbaParent
, xContext
, xControl
, xModel
, xGeoHelper
.release() ) );
681 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlFixedTextModel" ) )
682 xVBAControl
.set( new ScVbaLabel( xVbaParent
, xContext
, xControl
, xModel
, xGeoHelper
.release() ) );
683 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlImageControlModel" ) )
684 xVBAControl
.set( new ScVbaImage( xVbaParent
, xContext
, xControl
, xModel
, xGeoHelper
.release() ) );
685 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlProgressBarModel" ) )
686 xVBAControl
.set( new ScVbaProgressBar( xVbaParent
, xContext
, xControl
, xModel
, xGeoHelper
.release() ) );
687 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlGroupBoxModel" ) )
688 xVBAControl
.set( new ScVbaFrame( xVbaParent
, xContext
, xControl
, xModel
, xGeoHelper
.release(), xDialog
) );
689 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlScrollBarModel" ) )
690 xVBAControl
.set( new ScVbaScrollBar( xVbaParent
, xContext
, xControl
, xModel
, xGeoHelper
.release() ) );
691 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoMultiPageModel" ) )
692 xVBAControl
.set( new ScVbaMultiPage( xVbaParent
, xContext
, xControl
, xModel
, xGeoHelper
.release() ) );
693 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlSpinButtonModel" ) )
694 xVBAControl
.set( new ScVbaSpinButton( xVbaParent
, xContext
, xControl
, xModel
, xGeoHelper
.release() ) );
695 else if ( xServiceInfo
->supportsService( "com.sun.star.custom.awt.UnoControlSystemAXContainerModel" ) )
696 xVBAControl
.set( new VbaSystemAXControl( xVbaParent
, xContext
, xControl
, xModel
, xGeoHelper
.release() ) );
697 // #FIXME implement a page control
698 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoPageModel" ) )
699 xVBAControl
.set( new ScVbaControl( xVbaParent
, xContext
, xControl
, xModel
, xGeoHelper
.release() ) );
700 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoFrameModel" ) )
701 xVBAControl
.set( new ScVbaFrame( xVbaParent
, xContext
, xControl
, xModel
, xGeoHelper
.release(), xDialog
) );
702 else if ( xServiceInfo
->supportsService( "com.sun.star.awt.UnoControlSpinButtonModel" ) )
703 xVBAControl
.set( new ScVbaSpinButton( xVbaParent
, xContext
, xControl
, xModel
, xGeoHelper
.release() ) );
704 else if ( xServiceInfo
->supportsService( "com.sun.star.custom.awt.UnoControlSystemAXContainerModel" ) )
705 xVBAControl
.set( new VbaSystemAXControl( xVbaParent
, xContext
, xControl
, xModel
, xGeoHelper
.release() ) );
706 if( xVBAControl
.is() )
708 throw uno::RuntimeException( "Unsupported control." , uno::Reference
< uno::XInterface
>() );
712 ScVbaControl::getServiceImplName()
714 return OUString("ScVbaControl");
717 uno::Sequence
< OUString
>
718 ScVbaControl::getServiceNames()
720 static uno::Sequence
< OUString
> aServiceNames
;
721 if ( aServiceNames
.getLength() == 0 )
723 aServiceNames
.realloc( 1 );
724 aServiceNames
[ 0 ] = "ooo.vba.excel.Control";
726 return aServiceNames
;
729 sal_Int32 nSysCols
[] = { 0xC8D0D4, 0x0, 0x6A240A, 0x808080, 0xE4E4E4, 0xFFFFFF, 0x0, 0x0, 0x0, 0xFFFFFF, 0xE4E4E4, 0xE4E4E4, 0x808080, 0x6A240A, 0xFFFFFF, 0xE4E4E4, 0x808080, 0x808080, 0x0, 0xC8D0D4, 0xFFFFFF, 0x404040, 0xE4E4E4, 0x0, 0xE1FFFF };
731 sal_Int32
ScVbaControl::getBackColor() throw (uno::RuntimeException
)
733 sal_Int32 nBackColor
= 0;
734 m_xProps
->getPropertyValue( "BackgroundColor" ) >>= nBackColor
;
738 void ScVbaControl::setBackColor( sal_Int32 nBackColor
) throw (uno::RuntimeException
)
740 if ( ( nBackColor
>= (sal_Int32
)0x80000000 ) && ( nBackColor
<= (sal_Int32
)0x80000018 ) )
742 nBackColor
= nSysCols
[ nBackColor
- 0x80000000 ];
744 m_xProps
->setPropertyValue( "BackgroundColor" , uno::makeAny( XLRGBToOORGB( nBackColor
) ) );
747 sal_Bool
ScVbaControl::getAutoSize() throw (uno::RuntimeException
)
749 bool bIsResizeEnabled
= false;
750 uno::Reference
< uno::XInterface
> xIf( m_xControl
, uno::UNO_QUERY_THROW
);
751 SdrObject
* pObj
= SdrObject::getSdrObjectFromXShape( xIf
);
753 bIsResizeEnabled
= !pObj
->IsResizeProtect();
754 return bIsResizeEnabled
;
757 // currently no implementation for this
758 void ScVbaControl::setAutoSize( sal_Bool bAutoSize
) throw (uno::RuntimeException
)
760 uno::Reference
< uno::XInterface
> xIf( m_xControl
, uno::UNO_QUERY_THROW
);
761 SdrObject
* pObj
= SdrObject::getSdrObjectFromXShape( xIf
);
763 pObj
->SetResizeProtect( !bAutoSize
);
766 sal_Bool
ScVbaControl::getLocked() throw (uno::RuntimeException
)
768 sal_Bool
bRes( sal_False
);
769 m_xProps
->getPropertyValue( "ReadOnly" ) >>= bRes
;
773 void ScVbaControl::setLocked( sal_Bool bLocked
) throw (uno::RuntimeException
)
775 m_xProps
->setPropertyValue( "ReadOnly" , uno::makeAny( bLocked
) );
778 typedef cppu::WeakImplHelper1
< XControlProvider
> ControlProvider_BASE
;
779 class ControlProviderImpl
: public ControlProvider_BASE
781 uno::Reference
< uno::XComponentContext
> m_xCtx
;
783 ControlProviderImpl( const uno::Reference
< uno::XComponentContext
>& xCtx
) : m_xCtx( xCtx
) {}
784 virtual uno::Reference
< msforms::XControl
> SAL_CALL
createControl( const uno::Reference
< drawing::XControlShape
>& xControl
, const uno::Reference
< frame::XModel
>& xDocOwner
) throw (uno::RuntimeException
);
787 uno::Reference
< msforms::XControl
> SAL_CALL
788 ControlProviderImpl::createControl( const uno::Reference
< drawing::XControlShape
>& xControlShape
, const uno::Reference
< frame::XModel
>& xDocOwner
) throw (uno::RuntimeException
)
790 uno::Reference
< msforms::XControl
> xControlToReturn
;
791 if ( xControlShape
.is() )
792 xControlToReturn
= ScVbaControlFactory::createShapeControl( m_xCtx
, xControlShape
, xDocOwner
);
793 return xControlToReturn
;
797 namespace controlprovider
799 namespace sdecl
= comphelper::service_decl
;
800 sdecl::class_
<ControlProviderImpl
, sdecl::with_args
<false> > serviceImpl
;
801 extern sdecl::ServiceDecl
const serviceDecl(
803 "ControlProviderImpl",
804 "ooo.vba.ControlProvider" );
808 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */