LibreOffice Module vbahelper (master) 1
vbacontrol.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19#include <memory>
20#include <com/sun/star/form/FormComponentType.hpp>
21#include <com/sun/star/awt/XControlModel.hpp>
22#include <com/sun/star/awt/XControl.hpp>
23#include <com/sun/star/awt/XActionListener.hpp>
24#include <com/sun/star/lang/XEventListener.hpp>
25#include <com/sun/star/lang/XMultiServiceFactory.hpp>
26#include <com/sun/star/lang/XServiceInfo.hpp>
27#include <com/sun/star/drawing/XShape.hpp>
28#include <com/sun/star/drawing/XControlShape.hpp>
29#include <com/sun/star/frame/XModel.hpp>
30#include <com/sun/star/view/XControlAccess.hpp>
31#include <com/sun/star/form/binding/XBindableValue.hpp>
32#include <com/sun/star/form/binding/XListEntrySink.hpp>
33#include <com/sun/star/table/CellAddress.hpp>
34#include <com/sun/star/table/CellRangeAddress.hpp>
35#include <com/sun/star/script/XScriptListener.hpp>
36#include <com/sun/star/document/XCodeNameQuery.hpp>
37#include <com/sun/star/form/XChangeListener.hpp>
38#include <ooo/vba/XControlProvider.hpp>
39#include <ooo/vba/msforms/fmMousePointer.hpp>
41#include "vbacontrol.hxx"
42#include "vbacombobox.hxx"
43#include "vbabutton.hxx"
44#include "vbalabel.hxx"
45#include "vbatextbox.hxx"
46#include "vbaradiobutton.hxx"
47#include "vbalistbox.hxx"
48#include "vbatogglebutton.hxx"
49#include "vbacheckbox.hxx"
50#include "vbaframe.hxx"
51#include "vbascrollbar.hxx"
52#include "vbaprogressbar.hxx"
53#include "vbamultipage.hxx"
54#include "vbaspinbutton.hxx"
56#include "vbaimage.hxx"
58#include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
59#include <com/sun/star/form/XFormsSupplier.hpp>
60#include <svx/svdobj.hxx>
63#include <utility>
64
65using namespace com::sun::star;
66using namespace ooo::vba;
67
68uno::Reference< css::awt::XVclWindowPeer >
70{
71 uno::Reference< drawing::XControlShape > xControlShape( m_xControl, uno::UNO_QUERY );
72
73 uno::Reference< awt::XControlModel > xControlModel;
74 uno::Reference< css::awt::XWindowPeer > xWinPeer;
75 if ( !xControlShape.is() )
76 {
77 // would seem to be a Userform control
78 uno::Reference< awt::XControl > xControl( m_xControl, uno::UNO_QUERY_THROW );
79 xWinPeer = xControl->getPeer();
80 }
81 else
82 {
83 // form control
84 xControlModel.set( xControlShape->getControl(), uno::UNO_SET_THROW );
85
86 uno::Reference< view::XControlAccess > xControlAccess( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW );
87 try
88 {
89 uno::Reference< awt::XControl > xControl = xControlAccess->getControl( xControlModel );
90 xWinPeer = xControl->getPeer();
91 }
92 catch(const uno::Exception&)
93 {
94 throw uno::RuntimeException( "The Control does not exist" );
95 }
96 }
97 uno::Reference< css::awt::XVclWindowPeer > xVclWinPeer(xWinPeer, uno::UNO_QUERY);
98 assert(xVclWinPeer || !xWinPeer);
99 return xVclWinPeer;
100}
101
102namespace {
103
104//ScVbaControlListener
105class ScVbaControlListener: public cppu::WeakImplHelper< lang::XEventListener >
106{
107private:
108 ScVbaControl *pControl;
109public:
110 explicit ScVbaControlListener( ScVbaControl *pTmpControl );
111
112 virtual void SAL_CALL disposing( const lang::EventObject& rEventObject ) override;
113};
114
115}
116
117ScVbaControlListener::ScVbaControlListener( ScVbaControl *pTmpControl ): pControl( pTmpControl )
118{
119}
120
121void SAL_CALL
122ScVbaControlListener::disposing( const lang::EventObject& )
123{
124 if( pControl )
125 {
126 pControl->removeResource();
127 pControl = nullptr;
128 }
129}
130
131//ScVbaControl
132
133ScVbaControl::ScVbaControl( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, uno::Reference< ::uno::XInterface > xControl, css::uno::Reference< css::frame::XModel > xModel, std::unique_ptr<ov::AbstractGeometryAttributes> pGeomHelper )
134 : ControlImpl_BASE( xParent, xContext ), m_xControl(std::move( xControl )), m_xModel(std::move( xModel ))
135{
136 //add listener
137 m_xEventListener.set( new ScVbaControlListener( this ) );
138 setGeometryHelper( std::move(pGeomHelper) );
139 uno::Reference< lang::XComponent > xComponent( m_xControl, uno::UNO_QUERY_THROW );
140 xComponent->addEventListener( m_xEventListener );
141
142 //init m_xProps
143 uno::Reference< drawing::XControlShape > xControlShape( m_xControl, uno::UNO_QUERY ) ;
144 uno::Reference< awt::XControl> xUserFormControl( m_xControl, uno::UNO_QUERY ) ;
145 if ( xControlShape.is() ) // form control
146 {
147 m_xProps.set( xControlShape->getControl(), uno::UNO_QUERY_THROW );
148 OUString sDefaultControl;
149 m_xProps->getPropertyValue( "DefaultControl" ) >>= sDefaultControl;
150 uno::Reference< lang::XMultiComponentFactory > xMFac( mxContext->getServiceManager(), uno::UNO_SET_THROW );
151 m_xEmptyFormControl.set( xMFac->createInstanceWithContext( sDefaultControl, mxContext ), uno::UNO_QUERY_THROW );
152 }
153 else if ( xUserFormControl.is() ) // userform control
154 {
155 m_xProps.set( xUserFormControl->getModel(), uno::UNO_QUERY_THROW );
156 }
157}
158
160{
161 if( m_xControl.is() )
162 {
163 uno::Reference< lang::XComponent > xComponent( m_xControl, uno::UNO_QUERY_THROW );
164 xComponent->removeEventListener( m_xEventListener );
165 }
166}
167
168void
169ScVbaControl::setGeometryHelper( std::unique_ptr<AbstractGeometryAttributes> pHelper )
170{
171 mpGeometryHelper = std::move( pHelper );
172}
173
175{
176 uno::Reference< lang::XComponent > xComponent( m_xControl, uno::UNO_QUERY_THROW );
177 xComponent->removeEventListener( m_xEventListener );
178 m_xControl= nullptr;
179 m_xProps = nullptr;
180}
181
182//In design model has different behavior
184{
185 uno::Any aValue = m_xProps->getPropertyValue ( "Enabled" );
186 bool bRet = false;
187 aValue >>= bRet;
188 return bRet;
189}
190
191void SAL_CALL ScVbaControl::setEnabled( sal_Bool bVisible )
192{
193 uno::Any aValue( bVisible );
194 m_xProps->setPropertyValue( "Enabled" , aValue);
195
196}
197
199{
200 bool bVisible( true );
201 m_xProps->getPropertyValue ( "EnableVisible" ) >>= bVisible;
202 uno::Reference< drawing::XControlShape > xControlShape( m_xControl, uno::UNO_QUERY );
203 if ( xControlShape.is() )
204 {
205 bool bEnableVisible = bVisible;
206 uno::Reference< beans::XPropertySet > xProps( m_xControl, uno::UNO_QUERY_THROW );
207 xProps->getPropertyValue ( "Visible" ) >>= bVisible;
208 bVisible = bVisible && bEnableVisible;
209 }
210 else
211 m_xProps->getPropertyValue ( "EnableVisible" ) >>= bVisible;
212 return bVisible;
213}
214
215void SAL_CALL ScVbaControl::setVisible( sal_Bool bVisible )
216{
217 uno::Any aValue( bVisible );
218 m_xProps->setPropertyValue( "EnableVisible" , aValue);
219 uno::Reference< drawing::XControlShape > xControlShape( m_xControl, uno::UNO_QUERY );
220 if ( xControlShape.is() )
221 {
222 uno::Reference< beans::XPropertySet > xProps( m_xControl, uno::UNO_QUERY_THROW );
223 xProps->setPropertyValue ( "Visible", aValue );
224 }
225}
226double SAL_CALL ScVbaControl::getHeight()
227{
228 return mpGeometryHelper->getHeight();
229}
230void SAL_CALL ScVbaControl::setHeight( double _height )
231{
232 mpGeometryHelper->setHeight( _height );
233}
234
235double SAL_CALL ScVbaControl::getWidth()
236{
237 return mpGeometryHelper->getWidth();
238}
239void SAL_CALL ScVbaControl::setWidth( double _width )
240{
241 mpGeometryHelper->setWidth( _width );
242}
243
244double SAL_CALL
246{
247 return mpGeometryHelper->getLeft();
248}
249
250void SAL_CALL
252{
253 mpGeometryHelper->setLeft( _left );
254}
255
256double SAL_CALL
258{
259 return mpGeometryHelper->getTop();
260}
261
262void SAL_CALL
264{
265 mpGeometryHelper->setTop( _top );
266}
267
268uno::Reference< uno::XInterface > SAL_CALL
270{
271 uno::Reference< msforms::XControl > xRet( this );
272 return xRet;
273}
274
276{
277 uno::Reference< awt::XWindow > xWin( m_xControl, uno::UNO_QUERY_THROW );
278 xWin->setFocus();
279}
280
281void SAL_CALL ScVbaControl::Move( double Left, double Top, const uno::Any& Width, const uno::Any& Height )
282{
283 double nWidth = 0.0;
284 double nHeight = 0.0;
285
286 setLeft( Left );
287 setTop( Top );
288
289 if ( Width >>= nWidth )
290 setWidth( nWidth );
291
292 if ( Height >>= nHeight )
293 setHeight( nHeight );
294}
295
296OUString SAL_CALL
298{
299// #FIXME I *hate* having these upstream differences
300// but this is necessary until I manage to upstream other
301// dependent parts
302 OUString sControlSource;
303 uno::Reference< form::binding::XBindableValue > xBindable( m_xProps, uno::UNO_QUERY );
304 if ( xBindable.is() )
305 {
306 try
307 {
308 uno::Reference< lang::XMultiServiceFactory > xFac( m_xModel, uno::UNO_QUERY_THROW );
309 uno::Reference< beans::XPropertySet > xConvertor( xFac->createInstance( "com.sun.star.table.CellAddressConversion" ), uno::UNO_QUERY );
310 uno::Reference< beans::XPropertySet > xProps( xBindable->getValueBinding(), uno::UNO_QUERY_THROW );
311 table::CellAddress aAddress;
312 xProps->getPropertyValue( "BoundCell" ) >>= aAddress;
313 xConvertor->setPropertyValue( "Address" , uno::Any( aAddress ) );
314 xConvertor->getPropertyValue( "XLA1Representation" ) >>= sControlSource;
315 }
316 catch(const uno::Exception&)
317 {
318 }
319 }
320 return sControlSource;
321}
322
323void SAL_CALL
324ScVbaControl::setControlSource( const OUString& _controlsource )
325{
326 // afaik this is only relevant for Excel documents ( and we need to set up a
327 // reference tab in case no Sheet is specified in "_controlsource"
328 // Can't use the active sheet either, code may of course access
329 uno::Reference< drawing::XDrawPagesSupplier > xSupplier( m_xModel, uno::UNO_QUERY_THROW );
330 uno::Reference< container::XIndexAccess > xIndex( xSupplier->getDrawPages(), uno::UNO_QUERY_THROW );
331 sal_Int32 nLen = xIndex->getCount();
332 bool bMatched = false;
333 sal_Int16 nRefTab = 0;
334 for ( sal_Int32 index = 0; index < nLen; ++index )
335 {
336 try
337 {
338 uno::Reference< form::XFormsSupplier > xFormSupplier( xIndex->getByIndex( index ), uno::UNO_QUERY_THROW );
339 uno::Reference< container::XIndexAccess > xFormIndex( xFormSupplier->getForms(), uno::UNO_QUERY_THROW );
340 // get the www-standard container
341 uno::Reference< container::XIndexAccess > xFormControls( xFormIndex->getByIndex(0), uno::UNO_QUERY_THROW );
342 sal_Int32 nCntrls = xFormControls->getCount();
343 for( sal_Int32 cIndex = 0; cIndex < nCntrls; ++cIndex )
344 {
345 uno::Reference< uno::XInterface > xControl( xFormControls->getByIndex( cIndex ), uno::UNO_QUERY_THROW );
346 bMatched = ( m_xProps == xControl );
347 if ( bMatched )
348 {
349 nRefTab = index;
350 break;
351 }
352 }
353 }
354 catch( uno::Exception& ) {}
355 if ( bMatched )
356 break;
357 }
358
359 svt::BindableControlHelper::ApplyListSourceAndBindableData( m_xModel, m_xProps, _controlsource, "", sal_uInt16( nRefTab ) );
360}
361
362OUString SAL_CALL
364{
365 OUString sRowSource;
366 uno::Reference< form::binding::XListEntrySink > xListSink( m_xProps, uno::UNO_QUERY );
367 if ( xListSink.is() )
368 {
369 try
370 {
371 uno::Reference< lang::XMultiServiceFactory > xFac( m_xModel, uno::UNO_QUERY_THROW );
372 uno::Reference< beans::XPropertySet > xConvertor( xFac->createInstance( "com.sun.star.table.CellRangeAddressConversion" ), uno::UNO_QUERY );
373
374 uno::Reference< beans::XPropertySet > xProps( xListSink->getListEntrySource(), uno::UNO_QUERY_THROW );
375 table::CellRangeAddress aAddress;
376 xProps->getPropertyValue( "CellRange" ) >>= aAddress;
377 xConvertor->setPropertyValue( "Address" , uno::Any( aAddress ) );
378 xConvertor->getPropertyValue( "XLA1Representation" ) >>= sRowSource;
379 }
380 catch(const uno::Exception&)
381 {
382 }
383 }
384 return sRowSource;
385}
386
387void SAL_CALL
388ScVbaControl::setRowSource( const OUString& _rowsource )
389{
391}
392
393OUString SAL_CALL
395{
396 OUString sName;
397 m_xProps->getPropertyValue( "Name" ) >>= sName;
398 return sName;
399
400}
401
402void SAL_CALL
403ScVbaControl::setName( const OUString& _name )
404{
405 m_xProps->setPropertyValue( "Name" , uno::Any( _name ) );
406 }
407
408OUString SAL_CALL
410{
411 OUString sName;
412 m_xProps->getPropertyValue( "HelpText" ) >>= sName;
413 return sName;
414}
415
416void SAL_CALL
417ScVbaControl::setControlTipText( const OUString& rsToolTip )
418{
419 m_xProps->setPropertyValue( "HelpText" , uno::Any( rsToolTip ) );
420}
421
422OUString SAL_CALL ScVbaControl::getTag()
423{
424 return m_aControlTag;
425}
426
427void SAL_CALL ScVbaControl::setTag( const OUString& aTag )
428{
429 m_aControlTag = aTag;
430}
431
432::sal_Int32 SAL_CALL ScVbaControl::getForeColor()
433{
434 Color nForeColor;
435 m_xProps->getPropertyValue( "TextColor" ) >>= nForeColor;
436 return OORGBToXLRGB( nForeColor );
437}
438
439namespace {
440
441struct PointerStyles
442{
443 tools::Long msoPointerStyle;
444 PointerStyle loPointStyle;
445};
446
447}
448
449// 1 -> 1 map of styles ( some dubious choices in there though )
450PointerStyles const styles[] = {
452 { msforms::fmMousePointer::fmMousePointerDefault, PointerStyle::Arrow },
453 { msforms::fmMousePointer::fmMousePointerArrow, PointerStyle::Arrow },
454 { msforms::fmMousePointer::fmMousePointerCross, PointerStyle::Cross },
455 { msforms::fmMousePointer::fmMousePointerIBeam, PointerStyle::Text },
456 { msforms::fmMousePointer::fmMousePointerSizeNESW, PointerStyle::AutoScrollNSWE }, // #TODO not correct, need to check, need to find the right one
457 { msforms::fmMousePointer::fmMousePointerSizeNS, PointerStyle::AutoScrollNS },
458 { msforms::fmMousePointer::fmMousePointerSizeNWSE, PointerStyle::AutoScrollNSWE }, // #TODO not correct, need to check, need to find the right one
459 { msforms::fmMousePointer::fmMousePointerSizeWE, PointerStyle::AutoScrollWE },
460 { msforms::fmMousePointer::fmMousePointerUpArrow, PointerStyle::WindowNSize },
461 { msforms::fmMousePointer::fmMousePointerHourGlass, PointerStyle::Wait },
462 { msforms::fmMousePointer::fmMousePointerNoDrop, PointerStyle::NotAllowed },
463 { msforms::fmMousePointer::fmMousePointerAppStarting, PointerStyle::Wait },
464 { msforms::fmMousePointer::fmMousePointerHelp, PointerStyle::Help },
465 { msforms::fmMousePointer::fmMousePointerSizeAll, PointerStyle::Cross },
466 { msforms::fmMousePointer::fmMousePointerCustom, PointerStyle::Arrow }, // not supported I guess
467
468};
469
471{
472 tools::Long nRet = msforms::fmMousePointer::fmMousePointerDefault;
473 for ( auto const & i: styles )
474 {
475 if ( i.loPointStyle == eType )
476 {
477 nRet = i.msoPointerStyle;
478 break;
479 }
480 }
481 return nRet;
482}
483
485{
486 PointerStyle aPointer( PointerStyle::Arrow );
487 for ( auto const & i: styles )
488 {
489 if ( i.msoPointerStyle == msoPointerStyle )
490 {
491 aPointer = i.loPointStyle;
492 break;
493 }
494 }
495 return aPointer;
496}
497
498::sal_Int32 SAL_CALL
500{
502}
503
504void SAL_CALL
505ScVbaControl::setMousePointer( ::sal_Int32 _mousepointer )
506{
508}
509
510void SAL_CALL ScVbaControl::fireEvent( const script::ScriptEvent& rEvt )
511{
512 script::ScriptEvent evt( rEvt );
513 uno::Reference<lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_SET_THROW );
514 uno::Reference< script::XScriptListener > xScriptListener( xServiceManager->createInstanceWithContext( "ooo.vba.EventListener" , mxContext ), uno::UNO_QUERY_THROW );
515
516 uno::Reference< beans::XPropertySet > xProps( xScriptListener, uno::UNO_QUERY_THROW );
517 xProps->setPropertyValue( "Model" , uno::Any( m_xModel ) );
518
519 // handling for sheet control
520 uno::Reference< msforms::XControl > xThisControl( this );
521 try
522 {
523 evt.Arguments.realloc( 1 );
524 lang::EventObject aEvt;
525
526 uno::Reference< drawing::XControlShape > xControlShape( m_xControl, uno::UNO_QUERY ) ;
527 uno::Reference< awt::XControl > xControl( m_xControl, uno::UNO_QUERY ) ;
528
529 if ( xControlShape.is() )
530 {
531 evt.Source = xControlShape;
532 aEvt.Source = m_xEmptyFormControl;
533 // Set up proper scriptcode
534 uno::Reference< lang::XMultiServiceFactory > xDocFac( m_xModel, uno::UNO_QUERY_THROW );
535 uno::Reference< document::XCodeNameQuery > xNameQuery( xDocFac->createInstance( "ooo.vba.VBACodeNameProvider" ), uno::UNO_QUERY_THROW );
536 uno::Reference< uno::XInterface > xIf( xControlShape->getControl(), uno::UNO_QUERY_THROW );
537 evt.ScriptCode = xNameQuery->getCodeNameForObject( xIf );
538 // handle if we passed in our own arguments
539 if ( !rEvt.Arguments.hasElements() )
540 evt.Arguments.getArray()[ 0 ] <<= aEvt;
541 xScriptListener->firing( evt );
542 }
543 else
544 {
545 if ( xControl.is() ) // normal control ( from dialog/userform )
546 {
547 // #FIXME We should probably store a reference to the
548 // parent dialog/userform here (otherwise the name of
549 // dialog could be changed and we won't be aware of it.
550 // (OTOH this is probably an unlikely scenario)
551 evt.Source = xThisControl;
552 aEvt.Source = xControl;
553 evt.ScriptCode = m_sLibraryAndCodeName;
554 evt.Arguments.getArray()[ 0 ] <<= aEvt;
555 xScriptListener->firing( evt );
556 }
557 }
558 }
559 catch(const uno::Exception&)
560 {
561 }
562}
564{
565 script::ScriptEvent evt;
566 evt.ScriptType = "VBAInterop";
568 evt.MethodName = "changed";
569 fireEvent( evt );
570}
571
573{
574 script::ScriptEvent evt;
575 evt.ScriptType = "VBAInterop";
576 evt.ListenerType = cppu::UnoType<awt::XActionListener>::get();
577 evt.MethodName = "actionPerformed";
578 fireEvent( evt );
579}
580
581sal_Int32 SAL_CALL ScVbaControl::getTabIndex()
582{
583 return 1;
584}
585
586void SAL_CALL ScVbaControl::setTabIndex( sal_Int32 /*nTabIndex*/ )
587{
588}
589
590//ScVbaControlFactory
591
592/*static*/ uno::Reference< msforms::XControl > ScVbaControlFactory::createShapeControl(
593 const uno::Reference< uno::XComponentContext >& xContext,
594 const uno::Reference< drawing::XControlShape >& xControlShape,
595 const uno::Reference< frame::XModel >& xModel )
596{
597 uno::Reference< beans::XPropertySet > xProps( xControlShape->getControl(), uno::UNO_QUERY_THROW );
598 sal_Int32 nClassId = -1;
599 xProps->getPropertyValue( "ClassId" ) >>= nClassId;
600 uno::Reference< XHelperInterface > xVbaParent; // #FIXME - should be worksheet I guess
601 uno::Reference< drawing::XShape > xShape( xControlShape, uno::UNO_QUERY_THROW );
602 ::std::unique_ptr< ConcreteXShapeGeometryAttributes > xGeoHelper( new ConcreteXShapeGeometryAttributes( xShape ) );
603 switch( nClassId )
604 {
605 case form::FormComponentType::COMBOBOX:
606 return new ScVbaComboBox( xVbaParent, xContext, xControlShape, xModel, std::move(xGeoHelper) );
607 case form::FormComponentType::COMMANDBUTTON:
608 {
609 bool bToggle = false;
610 xProps->getPropertyValue( "Toggle" ) >>= bToggle;
611 if ( bToggle )
612 return new ScVbaToggleButton( xVbaParent, xContext, xControlShape, xModel, std::move(xGeoHelper) );
613 else
614 return new VbaButton( xVbaParent, xContext, xControlShape, xModel, std::move(xGeoHelper) );
615 }
616 case form::FormComponentType::FIXEDTEXT:
617 return new ScVbaLabel( xVbaParent, xContext, xControlShape, xModel, std::move(xGeoHelper) );
618 case form::FormComponentType::TEXTFIELD:
619 return new ScVbaTextBox( xVbaParent, xContext, xControlShape, xModel, std::move(xGeoHelper) );
620 case form::FormComponentType::CHECKBOX:
621 return new ScVbaCheckbox( xVbaParent, xContext, xControlShape, xModel, std::move(xGeoHelper) );
622 case form::FormComponentType::RADIOBUTTON:
623 return new ScVbaRadioButton( xVbaParent, xContext, xControlShape, xModel, std::move(xGeoHelper) );
624 case form::FormComponentType::LISTBOX:
625 return new ScVbaListBox( xVbaParent, xContext, xControlShape, xModel, std::move(xGeoHelper) );
626 case form::FormComponentType::SPINBUTTON:
627 return new ScVbaSpinButton( xVbaParent, xContext, xControlShape, xModel, std::move(xGeoHelper) );
628 case form::FormComponentType::IMAGECONTROL:
629 return new ScVbaImage( xVbaParent, xContext, xControlShape, xModel, std::move(xGeoHelper) );
630 case form::FormComponentType::SCROLLBAR:
631 return new ScVbaScrollBar( xVbaParent, xContext, xControlShape, xModel, std::move(xGeoHelper) );
632 }
633 throw uno::RuntimeException( "Unsupported control." );
634}
635
636/*static*/ uno::Reference< msforms::XControl > ScVbaControlFactory::createUserformControl(
637 const uno::Reference< uno::XComponentContext >& xContext,
638 const uno::Reference< awt::XControl >& xControl,
639 const uno::Reference< awt::XControl >& xDialog,
640 const uno::Reference< frame::XModel >& xModel,
641 double fOffsetX, double fOffsetY )
642{
643 uno::Reference< beans::XPropertySet > xProps( xControl->getModel(), uno::UNO_QUERY_THROW );
644 uno::Reference< lang::XServiceInfo > xServiceInfo( xProps, uno::UNO_QUERY_THROW );
645 uno::Reference< msforms::XControl > xVBAControl;
646 uno::Reference< XHelperInterface > xVbaParent; // #FIXME - should be worksheet I guess
647 ::std::unique_ptr< UserFormGeometryHelper > xGeoHelper( new UserFormGeometryHelper( xControl, fOffsetX, fOffsetY ) );
648
649 if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlCheckBoxModel" ) )
650 xVBAControl.set( new ScVbaCheckbox( xVbaParent, xContext, xControl, xModel, std::move(xGeoHelper) ) );
651 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlRadioButtonModel" ) )
652 xVBAControl.set( new ScVbaRadioButton( xVbaParent, xContext, xControl, xModel, std::move(xGeoHelper) ) );
653 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlEditModel" ) )
654 xVBAControl.set( new ScVbaTextBox( xVbaParent, xContext, xControl, xModel, std::move(xGeoHelper), true ) );
655 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlButtonModel" ) )
656 {
657 bool bToggle = false;
658 xProps->getPropertyValue( "Toggle" ) >>= bToggle;
659 if ( bToggle )
660 xVBAControl.set( new ScVbaToggleButton( xVbaParent, xContext, xControl, xModel, std::move(xGeoHelper) ) );
661 else
662 xVBAControl.set( new VbaButton( xVbaParent, xContext, xControl, xModel, std::move(xGeoHelper) ) );
663 }
664 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlComboBoxModel" ) )
665 xVBAControl.set( new ScVbaComboBox( xVbaParent, xContext, xControl, xModel, std::move(xGeoHelper) ) );
666 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlListBoxModel" ) )
667 xVBAControl.set( new ScVbaListBox( xVbaParent, xContext, xControl, xModel, std::move(xGeoHelper) ) );
668 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlFixedTextModel" ) )
669 xVBAControl.set( new ScVbaLabel( xVbaParent, xContext, xControl, xModel, std::move(xGeoHelper) ) );
670 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlImageControlModel" ) )
671 xVBAControl.set( new ScVbaImage( xVbaParent, xContext, xControl, xModel, std::move(xGeoHelper) ) );
672 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlProgressBarModel" ) )
673 xVBAControl.set( new ScVbaProgressBar( xVbaParent, xContext, xControl, xModel, std::move(xGeoHelper) ) );
674 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlGroupBoxModel" ) )
675 xVBAControl.set( new ScVbaFrame( xVbaParent, xContext, xControl, xModel, std::move(xGeoHelper), xDialog ) );
676 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlScrollBarModel" ) )
677 xVBAControl.set( new ScVbaScrollBar( xVbaParent, xContext, xControl, xModel, std::move(xGeoHelper) ) );
678 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoMultiPageModel" ) )
679 xVBAControl.set( new ScVbaMultiPage( xVbaParent, xContext, xControl, xModel, std::move(xGeoHelper) ) );
680 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlSpinButtonModel" ) )
681 xVBAControl.set( new ScVbaSpinButton( xVbaParent, xContext, xControl, xModel, std::move(xGeoHelper) ) );
682 else if ( xServiceInfo->supportsService( "com.sun.star.custom.awt.UnoControlSystemAXContainerModel" ) )
683 xVBAControl.set( new VbaSystemAXControl( xVbaParent, xContext, xControl, xModel, std::move(xGeoHelper) ) );
684 // #FIXME implement a page control
685 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoPageModel" ) )
686 xVBAControl.set( new ScVbaControl( xVbaParent, xContext, xControl, xModel, std::move(xGeoHelper) ) );
687 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoFrameModel" ) )
688 xVBAControl.set( new ScVbaFrame( xVbaParent, xContext, xControl, xModel, std::move(xGeoHelper), xDialog ) );
689 if( xVBAControl.is() )
690 return xVBAControl;
691 throw uno::RuntimeException( "Unsupported control." );
692}
693
694OUString
696{
697 return "ScVbaControl";
698}
699
700uno::Sequence< OUString >
702{
703 return { "ooo.vba.excel.Control" };
704}
705
706sal_Int32 const 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 };
707
709{
710 sal_Int32 nBackColor = 0;
711 m_xProps->getPropertyValue( "BackgroundColor" ) >>= nBackColor;
712 return nBackColor;
713}
714
715void ScVbaControl::setBackColor( sal_Int32 nBackColor )
716{
717 auto const col = static_cast<sal_uInt32>(nBackColor);
718 if ( ( col >= sal_uInt32(0x80000000) ) &&
719 ( col <= sal_uInt32(0x80000000) + SAL_N_ELEMENTS(nSysCols) ) )
720 {
721 nBackColor = nSysCols[ col & 0x0FF];
722 }
723 m_xProps->setPropertyValue( "BackgroundColor" , uno::Any( XLRGBToOORGB( nBackColor ) ) );
724}
725
727{
728 bool bIsResizeEnabled = false;
729 uno::Reference< uno::XInterface > xIf( m_xControl, uno::UNO_SET_THROW );
731 if ( pObj )
732 bIsResizeEnabled = !pObj->IsResizeProtect();
733 return bIsResizeEnabled;
734}
735
736// currently no implementation for this
737void ScVbaControl::setAutoSize( bool bAutoSize )
738{
739 uno::Reference< uno::XInterface > xIf( m_xControl, uno::UNO_SET_THROW );
741 if ( pObj )
742 pObj->SetResizeProtect( !bAutoSize );
743}
744
746{
747 bool bRes( false );
748 m_xProps->getPropertyValue( "ReadOnly" ) >>= bRes;
749 return bRes;
750}
751
752void ScVbaControl::setLocked( bool bLocked )
753{
754 m_xProps->setPropertyValue( "ReadOnly" , uno::Any( bLocked ) );
755}
756
757namespace {
758
759class ControlProviderImpl : public cppu::WeakImplHelper< XControlProvider, css::lang::XServiceInfo >
760{
761 uno::Reference< uno::XComponentContext > m_xCtx;
762public:
763 explicit ControlProviderImpl( uno::Reference< uno::XComponentContext > xCtx ) : m_xCtx(std::move( xCtx )) {}
764 virtual uno::Reference< msforms::XControl > SAL_CALL createControl( const uno::Reference< drawing::XControlShape >& xControl, const uno::Reference< frame::XModel >& xDocOwner ) override;
765
766 // XServiceInfo
767 virtual sal_Bool SAL_CALL supportsService(const OUString& sServiceName) override;
768 virtual OUString SAL_CALL getImplementationName() override;
769 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
770};
771
772}
773
774// XServiceInfo
775sal_Bool ControlProviderImpl::supportsService(const OUString& sServiceName)
776{
777 return cppu::supportsService(this, sServiceName);
778}
779OUString ControlProviderImpl::getImplementationName()
780{
781 return "ControlProviderImpl";
782}
783css::uno::Sequence< OUString > ControlProviderImpl::getSupportedServiceNames()
784{
785 return { "ooo.vba.ControlProvider" };
786}
787
788uno::Reference< msforms::XControl > SAL_CALL
789ControlProviderImpl::createControl( const uno::Reference< drawing::XControlShape >& xControlShape, const uno::Reference< frame::XModel >& xDocOwner )
790{
791 uno::Reference< msforms::XControl > xControlToReturn;
792 if ( xControlShape.is() )
793 xControlToReturn = ScVbaControlFactory::createShapeControl( m_xCtx, xControlShape, xDocOwner );
794 return xControlToReturn;
795
796}
797
798extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
800 css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any> const&)
801{
802 return cppu::acquire(new ControlProviderImpl(context));
803}
804
805/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XComponentContext > m_xCtx
css::uno::Reference< css::uno::XComponentContext > mxContext
virtual sal_Int32 SAL_CALL getTabIndex() override
Definition: vbacontrol.cxx:581
virtual void SAL_CALL setTag(const OUString &aTag) override
Definition: vbacontrol.cxx:427
bool getLocked()
Definition: vbacontrol.cxx:745
virtual OUString getServiceImplName() override
Definition: vbacontrol.cxx:695
virtual void SAL_CALL Move(double Left, double Top, const css::uno::Any &Width, const css::uno::Any &Height) override
Definition: vbacontrol.cxx:281
virtual double SAL_CALL getHeight() override
Definition: vbacontrol.cxx:226
virtual double SAL_CALL getTop() override
Definition: vbacontrol.cxx:257
OUString m_sLibraryAndCodeName
Definition: vbacontrol.hxx:46
virtual ::sal_Int32 SAL_CALL getForeColor()
Definition: vbacontrol.cxx:432
virtual css::uno::Sequence< OUString > getServiceNames() override
Definition: vbacontrol.cxx:701
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getObject() override
Definition: vbacontrol.cxx:269
void setGeometryHelper(std::unique_ptr< ov::AbstractGeometryAttributes > pHelper)
Definition: vbacontrol.cxx:169
virtual double SAL_CALL getWidth() override
Definition: vbacontrol.cxx:235
sal_Int32 getBackColor()
Definition: vbacontrol.cxx:708
virtual void SAL_CALL setMousePointer(::sal_Int32 _mousepointer) override
Definition: vbacontrol.cxx:505
virtual void SAL_CALL setControlTipText(const OUString &) override
Definition: vbacontrol.cxx:417
virtual ::sal_Int32 SAL_CALL getMousePointer() override
Definition: vbacontrol.cxx:499
virtual sal_Bool SAL_CALL getEnabled() override
Definition: vbacontrol.cxx:183
virtual void SAL_CALL setWidth(double _width) override
Definition: vbacontrol.cxx:239
virtual OUString SAL_CALL getRowSource() override
Definition: vbacontrol.cxx:363
virtual void SAL_CALL setEnabled(sal_Bool _enabled) override
Definition: vbacontrol.cxx:191
css::uno::Reference< css::beans::XPropertySet > m_xProps
Definition: vbacontrol.hxx:48
css::uno::Reference< css::awt::XVclWindowPeer > getWindowPeer()
Definition: vbacontrol.cxx:69
bool getAutoSize() const
Definition: vbacontrol.cxx:726
virtual ~ScVbaControl() override
Definition: vbacontrol.cxx:159
css::uno::Reference< css::awt::XControl > m_xEmptyFormControl
Definition: vbacontrol.hxx:40
virtual void SAL_CALL setHeight(double _height) override
Definition: vbacontrol.cxx:230
virtual OUString SAL_CALL getName() override
Definition: vbacontrol.cxx:394
virtual OUString SAL_CALL getControlTipText() override
Definition: vbacontrol.cxx:409
virtual void SAL_CALL setTabIndex(sal_Int32 nTabIndex) override
Definition: vbacontrol.cxx:586
void removeResource()
Definition: vbacontrol.cxx:174
void setAutoSize(bool bAutoSize)
Definition: vbacontrol.cxx:737
virtual void SAL_CALL setRowSource(const OUString &_rowsource) override
Definition: vbacontrol.cxx:388
virtual void SAL_CALL setLeft(double _left) override
Definition: vbacontrol.cxx:251
virtual double SAL_CALL getLeft() override
Definition: vbacontrol.cxx:245
virtual void SAL_CALL fireEvent(const css::script::ScriptEvent &evt) override
Definition: vbacontrol.cxx:510
css::uno::Reference< css::frame::XModel > m_xModel
Definition: vbacontrol.hxx:50
void setBackColor(sal_Int32 nBackColor)
Definition: vbacontrol.cxx:715
css::uno::Reference< css::lang::XEventListener > m_xEventListener
Definition: vbacontrol.hxx:39
std::unique_ptr< ov::AbstractGeometryAttributes > mpGeometryHelper
Definition: vbacontrol.hxx:47
void fireChangeEvent()
Definition: vbacontrol.cxx:563
virtual void SAL_CALL setVisible(sal_Bool _visible) override
Definition: vbacontrol.cxx:215
void setLocked(bool bAutoSize)
Definition: vbacontrol.cxx:752
virtual void SAL_CALL SetFocus() override
Definition: vbacontrol.cxx:275
css::uno::Reference< css::uno::XInterface > m_xControl
Definition: vbacontrol.hxx:49
virtual OUString SAL_CALL getTag() override
Definition: vbacontrol.cxx:422
OUString m_aControlTag
Definition: vbacontrol.hxx:44
virtual void SAL_CALL setName(const OUString &_name) override
Definition: vbacontrol.cxx:403
virtual void SAL_CALL setControlSource(const OUString &_controlsource) override
Definition: vbacontrol.cxx:324
ScVbaControl(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, css::uno::Reference< css::uno::XInterface > xControl, css::uno::Reference< css::frame::XModel > xModel, std::unique_ptr< ov::AbstractGeometryAttributes > pHelper)
Definition: vbacontrol.cxx:133
virtual sal_Bool SAL_CALL getVisible() override
Definition: vbacontrol.cxx:198
void fireClickEvent()
Definition: vbacontrol.cxx:572
virtual OUString SAL_CALL getControlSource() override
Definition: vbacontrol.cxx:297
virtual void SAL_CALL setTop(double _top) override
Definition: vbacontrol.cxx:263
static SdrObject * getSdrObjectFromXShape(const css::uno::Reference< css::uno::XInterface > &xInt)
bool IsResizeProtect() const
void SetResizeProtect(bool bProt)
::PointerStyle getMousePointer(const css::uno::Reference< css::awt::XWindowPeer > &rWindowPeer)
static void setMousePointer(const css::uno::Reference< css::awt::XWindowPeer > &rWindowPeer, ::PointerStyle mousepointer)
css::uno::Type const & get()
Reference< frame::XModel > m_xModel
DocumentType eType
OUString sName
#define SAL_N_ELEMENTS(arr)
RttiCompleteObjectLocator col
css::uno::Reference< ov::msforms::XControl > createShapeControl(const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::drawing::XControlShape > &xControlShape, const css::uno::Reference< css::frame::XModel > &xModel)
css::uno::Reference< ov::msforms::XControl > createUserformControl(const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::awt::XControl > &xControl, const css::uno::Reference< css::awt::XControl > &xDialog, const css::uno::Reference< css::frame::XModel > &xModel, double fOffsetX, double fOffsetY)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
int i
index
sal_Int32 XLRGBToOORGB(sal_Int32 nCol)
Definition: vbahelper.cxx:306
sal_Int32 OORGBToXLRGB(sal_Int32 nCol)
Definition: vbahelper.cxx:289
SVT_DLLPUBLIC void ApplyListSourceAndBindableData(const css::uno::Reference< css::frame::XModel > &xModel, const css::uno::Reference< css::uno::XInterface > &rObj, const OUString &rsCtrlSource, const OUString &rsRowSource, sal_uInt16 nRefTab=0)
long Long
PointerStyle
Reference< XModel > xModel
bool bVisible
Left
unsigned char sal_Bool
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * ControlProviderImpl_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Definition: vbacontrol.cxx:799
static tools::Long lcl_loPointerToMsoPointer(PointerStyle eType)
Definition: vbacontrol.cxx:470
sal_Int32 const nSysCols[]
Definition: vbacontrol.cxx:706
PointerStyles const styles[]
Definition: vbacontrol.cxx:450
static PointerStyle lcl_msoPointerToLOPointer(tools::Long msoPointerStyle)
Definition: vbacontrol.cxx:484
Reference< XControl > m_xControl