1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_toolkit.hxx"
26 #include <com/sun/star/awt/XTextArea.hpp>
27 #include <com/sun/star/awt/XVclWindowPeer.hpp>
28 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
29 #include <com/sun/star/awt/PosSize.hpp>
30 #include <com/sun/star/awt/VisualEffect.hpp>
31 #include <com/sun/star/awt/LineEndFormat.hpp>
32 #include <com/sun/star/graphic/XGraphicProvider.hpp>
33 #include <com/sun/star/graphic/GraphicObject.hpp>
34 #include <com/sun/star/util/Date.hpp>
35 #include <com/sun/star/awt/ImageScaleMode.hpp>
36
37
38 #include <toolkit/controls/formattedcontrol.hxx>
39 #include <toolkit/controls/roadmapcontrol.hxx>
40 #include <toolkit/controls/unocontrols.hxx>
41 #include <toolkit/controls/stdtabcontroller.hxx>
42 #include <toolkit/helper/property.hxx>
43 #include <toolkit/helper/unopropertyarrayhelper.hxx>
44 #include <toolkit/helper/unomemorystream.hxx>
45 #include <toolkit/helper/servicenames.hxx>
46 #include <toolkit/helper/macros.hxx>
47 #include <toolkit/helper/imagealign.hxx>
48
49 // for introspection
50 #include <toolkit/awt/vclxwindows.hxx>
51 #include <cppuhelper/typeprovider.hxx>
52 #include <comphelper/componentcontext.hxx>
53 #include <comphelper/processfactory.hxx>
54 #include <comphelper/extract.hxx>
55 #include <vcl/wrkwin.hxx>
56 #include <vcl/svapp.hxx>
57 #include <vcl/edit.hxx>
58 #ifndef _SV_BUTTON_HXX
59 #include <vcl/button.hxx>
60 #endif
61 #include <vcl/group.hxx>
62 #include <vcl/fixed.hxx>
63 #include <vcl/lstbox.hxx>
64 #include <vcl/combobox.hxx>
65 #include <tools/debug.hxx>
66 #include <tools/diagnose_ex.h>
67 #include <tools/date.hxx>
68 #include <tools/time.hxx>
69
70 #include <algorithm>
71 #include <functional>
72
73 using namespace ::com::sun::star;
74 using ::com::sun::star::graphic::XGraphic;
75 using ::com::sun::star::uno::Reference;
76 using namespace ::toolkit;
77
78 #define IMPL_SERVICEINFO_DERIVED( ImplName, BaseClass, ServiceName ) \
79 ::rtl::OUString SAL_CALL ImplName::getImplementationName( ) { return ::rtl::OUString::createFromAscii( "stardiv.Toolkit." #ImplName ); } \
80 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL ImplName::getSupportedServiceNames() \
81 { \
82 ::com::sun::star::uno::Sequence< ::rtl::OUString > aNames = BaseClass::getSupportedServiceNames( ); \
83 aNames.realloc( aNames.getLength() + 1 ); \
84 aNames[ aNames.getLength() - 1 ] = ::rtl::OUString::createFromAscii( ServiceName ); \
85 return aNames; \
86 } \
87
88
89
90 // ----------------------------------------------------
91 // class UnoControlEditModel
92 // ----------------------------------------------------
UnoControlEditModel(const Reference<XMultiServiceFactory> & i_factory)93 UnoControlEditModel::UnoControlEditModel( const Reference< XMultiServiceFactory >& i_factory )
94 :UnoControlModel( i_factory )
95 {
96 UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXEdit );
97 }
98
getServiceName()99 ::rtl::OUString UnoControlEditModel::getServiceName( )
100 {
101 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlEditModel );
102 }
103
ImplGetDefaultValue(sal_uInt16 nPropId) const104 uno::Any UnoControlEditModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
105 {
106 uno::Any aReturn;
107
108 switch ( nPropId )
109 {
110 case BASEPROPERTY_LINE_END_FORMAT:
111 aReturn <<= (sal_Int16)awt::LineEndFormat::LINE_FEED; // LF
112 break;
113 case BASEPROPERTY_DEFAULTCONTROL:
114 aReturn <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlEdit );
115 break;
116 default:
117 aReturn = UnoControlModel::ImplGetDefaultValue( nPropId );
118 break;
119 }
120 return aReturn;
121 }
122
getInfoHelper()123 ::cppu::IPropertyArrayHelper& UnoControlEditModel::getInfoHelper()
124 {
125 static UnoPropertyArrayHelper* pHelper = NULL;
126 if ( !pHelper )
127 {
128 uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
129 pHelper = new UnoPropertyArrayHelper( aIDs );
130 }
131 return *pHelper;
132 }
133
134 // beans::XMultiPropertySet
getPropertySetInfo()135 uno::Reference< beans::XPropertySetInfo > UnoControlEditModel::getPropertySetInfo( )
136 {
137 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
138 return xInfo;
139 }
140
141
142 // ----------------------------------------------------
143 // class UnoEditControl
144 // ----------------------------------------------------
UnoEditControl(const Reference<XMultiServiceFactory> & i_factory)145 UnoEditControl::UnoEditControl( const Reference< XMultiServiceFactory >& i_factory )
146 :UnoControlBase( i_factory )
147 ,maTextListeners( *this )
148 ,mnMaxTextLen( 0 )
149 ,mbSetTextInPeer( sal_False )
150 ,mbSetMaxTextLenInPeer( sal_False )
151 ,mbHasTextProperty( sal_False )
152 {
153 maComponentInfos.nWidth = 100;
154 maComponentInfos.nHeight = 12;
155 mnMaxTextLen = 0;
156 mbSetMaxTextLenInPeer = sal_False;
157 }
158
queryAggregation(const uno::Type & rType)159 uno::Any SAL_CALL UnoEditControl::queryAggregation( const uno::Type & rType )
160 {
161 uno::Any aReturn = UnoControlBase::queryAggregation( rType );
162 if ( !aReturn.hasValue() )
163 aReturn = UnoEditControl_Base::queryInterface( rType );
164 return aReturn;
165 }
166
queryInterface(const uno::Type & rType)167 uno::Any SAL_CALL UnoEditControl::queryInterface( const uno::Type & rType )
168 {
169 return UnoControlBase::queryInterface( rType );
170 }
171
acquire()172 void SAL_CALL UnoEditControl::acquire( ) throw ()
173 {
174 UnoControlBase::acquire();
175 }
176
release()177 void SAL_CALL UnoEditControl::release( ) throw ()
178 {
179 UnoControlBase::release();
180 }
181
IMPLEMENT_FORWARD_XTYPEPROVIDER2(UnoEditControl,UnoControlBase,UnoEditControl_Base)182 IMPLEMENT_FORWARD_XTYPEPROVIDER2( UnoEditControl, UnoControlBase, UnoEditControl_Base )
183
184 ::rtl::OUString UnoEditControl::GetComponentServiceName()
185 {
186 // by default, we want a simple edit field
187 ::rtl::OUString sName( ::rtl::OUString::createFromAscii( "Edit" ) );
188
189 // but maybe we are to display multi-line text?
190 uno::Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_MULTILINE ) );
191 sal_Bool b = sal_Bool();
192 if ( ( aVal >>= b ) && b )
193 sName= ::rtl::OUString::createFromAscii( "MultiLineEdit" );
194
195 return sName;
196 }
197
setModel(const uno::Reference<awt::XControlModel> & _rModel)198 sal_Bool SAL_CALL UnoEditControl::setModel(const uno::Reference< awt::XControlModel >& _rModel)
199 {
200 sal_Bool bReturn = UnoControlBase::setModel( _rModel );
201 mbHasTextProperty = ImplHasProperty( BASEPROPERTY_TEXT );
202 return bReturn;
203 }
204
ImplSetPeerProperty(const::rtl::OUString & rPropName,const uno::Any & rVal)205 void UnoEditControl::ImplSetPeerProperty( const ::rtl::OUString& rPropName, const uno::Any& rVal )
206 {
207 sal_Bool bDone = sal_False;
208 if ( GetPropertyId( rPropName ) == BASEPROPERTY_TEXT )
209 {
210 // #96986# use setText(), or text listener will not be called.
211 uno::Reference < awt::XTextComponent > xTextComponent( getPeer(), uno::UNO_QUERY );
212 if ( xTextComponent.is() )
213 {
214 ::rtl::OUString sText;
215 rVal >>= sText;
216 ImplCheckLocalize( sText );
217 xTextComponent->setText( sText );
218 bDone = sal_True;
219 }
220 }
221
222 if ( !bDone )
223 UnoControlBase::ImplSetPeerProperty( rPropName, rVal );
224 }
225
dispose()226 void UnoEditControl::dispose()
227 {
228 lang::EventObject aEvt( *this );
229 maTextListeners.disposeAndClear( aEvt );
230 UnoControl::dispose();
231 }
232
createPeer(const uno::Reference<awt::XToolkit> & rxToolkit,const uno::Reference<awt::XWindowPeer> & rParentPeer)233 void UnoEditControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer )
234 {
235 UnoControl::createPeer( rxToolkit, rParentPeer );
236
237 uno::Reference< awt::XTextComponent > xText( getPeer(), uno::UNO_QUERY );
238 if ( xText.is() )
239 {
240 xText->addTextListener( this );
241
242 if ( mbSetMaxTextLenInPeer )
243 xText->setMaxTextLen( mnMaxTextLen );
244 if ( mbSetTextInPeer )
245 xText->setText( maText );
246 }
247 }
248
textChanged(const awt::TextEvent & e)249 void UnoEditControl::textChanged(const awt::TextEvent& e)
250 {
251 uno::Reference< awt::XTextComponent > xText( getPeer(), uno::UNO_QUERY );
252
253 if ( mbHasTextProperty )
254 {
255 uno::Any aAny;
256 aAny <<= xText->getText();
257 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_TEXT ), aAny, sal_False );
258 }
259 else
260 {
261 maText = xText->getText();
262 }
263
264 if ( maTextListeners.getLength() )
265 maTextListeners.textChanged( e );
266 }
267
addTextListener(const uno::Reference<awt::XTextListener> & l)268 void UnoEditControl::addTextListener(const uno::Reference< awt::XTextListener > & l)
269 {
270 maTextListeners.addInterface( l );
271 }
272
removeTextListener(const uno::Reference<awt::XTextListener> & l)273 void UnoEditControl::removeTextListener(const uno::Reference< awt::XTextListener > & l)
274 {
275 maTextListeners.removeInterface( l );
276 }
277
setText(const::rtl::OUString & aText)278 void UnoEditControl::setText( const ::rtl::OUString& aText )
279 {
280 if ( mbHasTextProperty )
281 {
282 uno::Any aAny;
283 aAny <<= aText;
284 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_TEXT ), aAny, sal_True );
285 }
286 else
287 {
288 maText = aText;
289 mbSetTextInPeer = sal_True;
290 uno::Reference < awt::XTextComponent > xText( getPeer(), uno::UNO_QUERY );
291 if ( xText.is() )
292 xText->setText( maText );
293 }
294
295 // Setting the property to the VCLXWindow doesn't call textChanged
296 if ( maTextListeners.getLength() )
297 {
298 awt::TextEvent aEvent;
299 aEvent.Source = *this;
300 maTextListeners.textChanged( aEvent );
301 }
302 }
303
304 namespace
305 {
lcl_normalize(awt::Selection & _rSel)306 static void lcl_normalize( awt::Selection& _rSel )
307 {
308 if ( _rSel.Min > _rSel.Max )
309 ::std::swap( _rSel.Min, _rSel.Max );
310 }
311
312 /*
313 static bool lcl_intersect( const awt::Selection& _rLHS, const awt::Selection& _rRHS )
314 {
315 OSL_PRECOND( _rLHS.Min <= _rLHS.Max, "lcl_intersect: LHS to be normalized!" );
316 OSL_PRECOND( _rRHS.Min <= _rRHS.Max, "lcl_intersect: RHS to be normalized!" );
317 return !( ( _rLHS.Max < _rRHS.Min ) || ( _rLHS.Min > _rRHS.Max ) );
318 }
319 */
320 }
321
insertText(const awt::Selection & rSel,const::rtl::OUString & rNewText)322 void UnoEditControl::insertText( const awt::Selection& rSel, const ::rtl::OUString& rNewText )
323 {
324 // normalize the selection - OUString::replaceAt has a strange behaviour if the min is greater than the max
325 awt::Selection aSelection( rSel );
326 lcl_normalize( aSelection );
327
328 // preserve the selection resp. cursor position
329 awt::Selection aNewSelection( getSelection() );
330 #ifdef ALSO_PRESERVE_COMPLETE_SELECTION
331 // (not sure - looks uglier ...)
332 sal_Int32 nDeletedCharacters = ( aSelection.Max - aSelection.Min ) - rNewText.getLength();
333 if ( aNewSelection.Min > aSelection.Min )
334 aNewSelection.Min -= nDeletedCharacters;
335 if ( aNewSelection.Max > aSelection.Max )
336 aNewSelection.Max -= nDeletedCharacters;
337 #else
338 aNewSelection.Max = ::std::min( aNewSelection.Min, aNewSelection.Max ) + rNewText.getLength();
339 aNewSelection.Min = aNewSelection.Max;
340 #endif
341
342 ::rtl::OUString aOldText = getText();
343 ::rtl::OUString aNewText = aOldText.replaceAt( aSelection.Min, aSelection.Max - aSelection.Min, rNewText );
344 setText( aNewText );
345
346 setSelection( aNewSelection );
347 }
348
getText()349 ::rtl::OUString UnoEditControl::getText()
350 {
351 ::rtl::OUString aText = maText;
352
353 if ( mbHasTextProperty )
354 aText = ImplGetPropertyValue_UString( BASEPROPERTY_TEXT );
355 else
356 {
357 uno::Reference< awt::XTextComponent > xText( getPeer(), uno::UNO_QUERY );
358 if ( xText.is() )
359 aText = xText->getText();
360 }
361
362 return aText;
363 }
364
getSelectedText(void)365 ::rtl::OUString UnoEditControl::getSelectedText( void )
366 {
367 ::rtl::OUString sSelected;
368 uno::Reference< awt::XTextComponent > xText( getPeer(), uno::UNO_QUERY );
369 if ( xText.is() )
370 sSelected = xText->getSelectedText();
371
372 return sSelected;
373 }
374
setSelection(const awt::Selection & aSelection)375 void UnoEditControl::setSelection( const awt::Selection& aSelection )
376 {
377 uno::Reference< awt::XTextComponent > xText( getPeer(), uno::UNO_QUERY );
378 if ( xText.is() )
379 xText->setSelection( aSelection );
380 }
381
getSelection(void)382 awt::Selection UnoEditControl::getSelection( void )
383 {
384 awt::Selection aSel;
385 uno::Reference< awt::XTextComponent > xText( getPeer(), uno::UNO_QUERY );
386 if ( xText.is() )
387 aSel = xText->getSelection();
388 return aSel;
389 }
390
isEditable(void)391 sal_Bool UnoEditControl::isEditable( void )
392 {
393 return !ImplGetPropertyValue_BOOL( BASEPROPERTY_READONLY );
394 }
395
setEditable(sal_Bool bEditable)396 void UnoEditControl::setEditable( sal_Bool bEditable )
397 {
398 uno::Any aAny;
399 aAny <<= (sal_Bool)!bEditable;
400 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_READONLY ), aAny, sal_True );
401 }
402
getMaxTextLen()403 sal_Int16 UnoEditControl::getMaxTextLen()
404 {
405 sal_Int16 nMaxLen = mnMaxTextLen;
406
407 if ( ImplHasProperty( BASEPROPERTY_MAXTEXTLEN ) )
408 nMaxLen = ImplGetPropertyValue_INT16( BASEPROPERTY_MAXTEXTLEN );
409
410 return nMaxLen;
411 }
412
setMaxTextLen(sal_Int16 nLen)413 void UnoEditControl::setMaxTextLen( sal_Int16 nLen )
414 {
415 if ( ImplHasProperty( BASEPROPERTY_MAXTEXTLEN) )
416 {
417 uno::Any aAny;
418 aAny <<= (sal_Int16)nLen;
419 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_MAXTEXTLEN ), aAny, sal_True );
420 }
421 else
422 {
423 mnMaxTextLen = nLen;
424 mbSetMaxTextLenInPeer = sal_True;
425 uno::Reference < awt::XTextComponent > xText( getPeer(), uno::UNO_QUERY );
426 if ( xText.is() )
427 xText->setMaxTextLen( mnMaxTextLen );
428 }
429 }
430
getMinimumSize()431 awt::Size UnoEditControl::getMinimumSize( )
432 {
433 return Impl_getMinimumSize();
434 }
435
getPreferredSize()436 awt::Size UnoEditControl::getPreferredSize( )
437 {
438 return Impl_getPreferredSize();
439 }
440
calcAdjustedSize(const awt::Size & rNewSize)441 awt::Size UnoEditControl::calcAdjustedSize( const awt::Size& rNewSize )
442 {
443 return Impl_calcAdjustedSize( rNewSize );
444 }
445
getMinimumSize(sal_Int16 nCols,sal_Int16 nLines)446 awt::Size UnoEditControl::getMinimumSize( sal_Int16 nCols, sal_Int16 nLines )
447 {
448 return Impl_getMinimumSize( nCols, nLines );
449 }
450
getColumnsAndLines(sal_Int16 & nCols,sal_Int16 & nLines)451 void UnoEditControl::getColumnsAndLines( sal_Int16& nCols, sal_Int16& nLines )
452 {
453 Impl_getColumnsAndLines( nCols, nLines );
454 }
455
456
457 // ----------------------------------------------------
458 // class UnoControlFileControlModel
459 // ----------------------------------------------------
UnoControlFileControlModel(const Reference<XMultiServiceFactory> & i_factory)460 UnoControlFileControlModel::UnoControlFileControlModel( const Reference< XMultiServiceFactory >& i_factory )
461 :UnoControlModel( i_factory )
462 {
463 ImplRegisterProperty( BASEPROPERTY_ALIGN );
464 ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR );
465 ImplRegisterProperty( BASEPROPERTY_BORDER );
466 ImplRegisterProperty( BASEPROPERTY_BORDERCOLOR );
467 ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL );
468 ImplRegisterProperty( BASEPROPERTY_ENABLED );
469 ImplRegisterProperty( BASEPROPERTY_ENABLEVISIBLE );
470 ImplRegisterProperty( BASEPROPERTY_FONTDESCRIPTOR );
471 ImplRegisterProperty( BASEPROPERTY_HELPTEXT );
472 ImplRegisterProperty( BASEPROPERTY_HELPURL );
473 ImplRegisterProperty( BASEPROPERTY_PRINTABLE );
474 ImplRegisterProperty( BASEPROPERTY_READONLY );
475 ImplRegisterProperty( BASEPROPERTY_TABSTOP );
476 ImplRegisterProperty( BASEPROPERTY_TEXT );
477 ImplRegisterProperty( BASEPROPERTY_VERTICALALIGN );
478 ImplRegisterProperty( BASEPROPERTY_WRITING_MODE );
479 ImplRegisterProperty( BASEPROPERTY_CONTEXT_WRITING_MODE );
480 ImplRegisterProperty( BASEPROPERTY_HIDEINACTIVESELECTION );
481 }
482
getServiceName()483 ::rtl::OUString UnoControlFileControlModel::getServiceName()
484 {
485 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlFileControlModel );
486 }
487
ImplGetDefaultValue(sal_uInt16 nPropId) const488 uno::Any UnoControlFileControlModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
489 {
490 if ( nPropId == BASEPROPERTY_DEFAULTCONTROL )
491 {
492 uno::Any aAny;
493 aAny <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlFileControl );
494 return aAny;
495 }
496 return UnoControlModel::ImplGetDefaultValue( nPropId );
497 }
498
getInfoHelper()499 ::cppu::IPropertyArrayHelper& UnoControlFileControlModel::getInfoHelper()
500 {
501 static UnoPropertyArrayHelper* pHelper = NULL;
502 if ( !pHelper )
503 {
504 uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
505 pHelper = new UnoPropertyArrayHelper( aIDs );
506 }
507 return *pHelper;
508 }
509
510 // beans::XMultiPropertySet
getPropertySetInfo()511 uno::Reference< beans::XPropertySetInfo > UnoControlFileControlModel::getPropertySetInfo( )
512 {
513 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
514 return xInfo;
515 }
516
517 // ----------------------------------------------------
518 // class UnoFileControl
519 // ----------------------------------------------------
UnoFileControl(const Reference<XMultiServiceFactory> & i_factory)520 UnoFileControl::UnoFileControl( const Reference< XMultiServiceFactory >& i_factory )
521 :UnoEditControl( i_factory )
522 {
523 }
524
GetComponentServiceName()525 ::rtl::OUString UnoFileControl::GetComponentServiceName()
526 {
527 return ::rtl::OUString::createFromAscii( "filecontrol" );
528 }
529
530 // ----------------------------------------------------
531 // class GraphicControlModel
532 // ----------------------------------------------------
ImplGetDefaultValue(sal_uInt16 nPropId) const533 uno::Any GraphicControlModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
534 {
535 if ( nPropId == BASEPROPERTY_GRAPHIC )
536 return uno::makeAny( uno::Reference< graphic::XGraphic >() );
537
538 return UnoControlModel::ImplGetDefaultValue( nPropId );
539 }
getGraphicFromURL_nothrow(const::rtl::OUString & _rURL)540 uno::Reference< graphic::XGraphic > GraphicControlModel::getGraphicFromURL_nothrow( const ::rtl::OUString& _rURL )
541 {
542 uno::Reference< graphic::XGraphic > xGraphic;
543
544 if( ( _rURL.compareToAscii( UNO_NAME_GRAPHOBJ_URLPREFIX, RTL_CONSTASCII_LENGTH( UNO_NAME_GRAPHOBJ_URLPREFIX ) ) == 0 ) )
545 {
546 // graphic manager uniqueid
547 rtl::OUString sID = _rURL.copy( sizeof( UNO_NAME_GRAPHOBJ_URLPREFIX ) - 1 );
548 // get the DefaultContext
549 mxGrfObj = graphic::GraphicObject::createWithId( maContext.getUNOContext(), sID );
550 }
551 else // linked
552 mxGrfObj = NULL; // release the GraphicObject
553
554 if ( !_rURL.getLength() )
555 return xGraphic;
556
557 try
558 {
559 uno::Reference< graphic::XGraphicProvider > xProvider;
560 if ( maContext.createComponent( "com.sun.star.graphic.GraphicProvider", xProvider ) )
561 {
562 uno::Sequence< beans::PropertyValue > aMediaProperties(1);
563 aMediaProperties[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) );
564 aMediaProperties[0].Value <<= _rURL;
565 xGraphic = xProvider->queryGraphic( aMediaProperties );
566 }
567 }
568 catch( const Exception& )
569 {
570 DBG_UNHANDLED_EXCEPTION();
571 }
572
573 return xGraphic;
574 }
575
setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const::com::sun::star::uno::Any & rValue)576 void SAL_CALL GraphicControlModel::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue )
577 {
578 UnoControlModel::setFastPropertyValue_NoBroadcast( nHandle, rValue );
579
580 // - ImageAlign and ImagePosition need to correspond to each other
581 // - Graphic and ImageURL need to correspond to each other
582 try
583 {
584 switch ( nHandle )
585 {
586 case BASEPROPERTY_IMAGEURL:
587 if ( !mbAdjustingGraphic && ImplHasProperty( BASEPROPERTY_GRAPHIC ) )
588 {
589 mbAdjustingGraphic = true;
590 ::rtl::OUString sImageURL;
591 OSL_VERIFY( rValue >>= sImageURL );
592 setDependentFastPropertyValue( BASEPROPERTY_GRAPHIC, uno::makeAny( getGraphicFromURL_nothrow( sImageURL ) ) );
593 mbAdjustingGraphic = false;
594 }
595 break;
596
597 case BASEPROPERTY_GRAPHIC:
598 if ( !mbAdjustingGraphic && ImplHasProperty( BASEPROPERTY_IMAGEURL ) )
599 {
600 mbAdjustingGraphic = true;
601 setDependentFastPropertyValue( BASEPROPERTY_IMAGEURL, uno::makeAny( ::rtl::OUString() ) );
602 mbAdjustingGraphic = false;
603 }
604 break;
605
606 case BASEPROPERTY_IMAGEALIGN:
607 if ( !mbAdjustingImagePosition && ImplHasProperty( BASEPROPERTY_IMAGEPOSITION ) )
608 {
609 mbAdjustingImagePosition = true;
610 sal_Int16 nUNOValue = 0;
611 OSL_VERIFY( rValue >>= nUNOValue );
612 setDependentFastPropertyValue( BASEPROPERTY_IMAGEPOSITION, uno::makeAny( getExtendedImagePosition( nUNOValue ) ) );
613 mbAdjustingImagePosition = false;
614 }
615 break;
616 case BASEPROPERTY_IMAGEPOSITION:
617 if ( !mbAdjustingImagePosition && ImplHasProperty( BASEPROPERTY_IMAGEALIGN ) )
618 {
619 mbAdjustingImagePosition = true;
620 sal_Int16 nUNOValue = 0;
621 OSL_VERIFY( rValue >>= nUNOValue );
622 setDependentFastPropertyValue( BASEPROPERTY_IMAGEALIGN, uno::makeAny( getCompatibleImageAlign( translateImagePosition( nUNOValue ) ) ) );
623 mbAdjustingImagePosition = false;
624 }
625 break;
626 }
627 }
628 catch( const ::com::sun::star::uno::Exception& )
629 {
630 OSL_ENSURE( sal_False, "GraphicControlModel::setFastPropertyValue_NoBroadcast: caught an exception while aligning the ImagePosition/ImageAlign properties!" );
631 mbAdjustingImagePosition = sal_False;
632 }
633 }
634
635 // ----------------------------------------------------
636 // class UnoControlButtonModel
637 // ----------------------------------------------------
UnoControlButtonModel(const Reference<XMultiServiceFactory> & i_factory)638 UnoControlButtonModel::UnoControlButtonModel( const Reference< XMultiServiceFactory >& i_factory )
639 :GraphicControlModel( i_factory )
640 {
641 UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXButton );
642
643 osl_incrementInterlockedCount( &m_refCount );
644 {
645 setFastPropertyValue_NoBroadcast( BASEPROPERTY_IMAGEPOSITION, ImplGetDefaultValue( BASEPROPERTY_IMAGEPOSITION ) );
646 // this ensures that our ImagePosition is consistent with our ImageAlign property (since both
647 // defaults are not per se consistent), since both are coupled in setFastPropertyValue_NoBroadcast
648 }
649 osl_decrementInterlockedCount( &m_refCount );
650 }
651
getServiceName()652 ::rtl::OUString UnoControlButtonModel::getServiceName()
653 {
654 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlButtonModel );
655 }
656
ImplGetDefaultValue(sal_uInt16 nPropId) const657 uno::Any UnoControlButtonModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
658 {
659 switch ( nPropId )
660 {
661 case BASEPROPERTY_DEFAULTCONTROL:
662 return uno::makeAny( ::rtl::OUString::createFromAscii( szServiceName_UnoControlButton ) );
663 case BASEPROPERTY_TOGGLE:
664 return uno::makeAny( (sal_Bool)sal_False );
665 case BASEPROPERTY_ALIGN:
666 return uno::makeAny( (sal_Int16)PROPERTY_ALIGN_CENTER );
667 case BASEPROPERTY_FOCUSONCLICK:
668 return uno::makeAny( (sal_Bool)sal_True );
669 }
670
671 return GraphicControlModel::ImplGetDefaultValue( nPropId );
672 }
673
getInfoHelper()674 ::cppu::IPropertyArrayHelper& UnoControlButtonModel::getInfoHelper()
675 {
676 static UnoPropertyArrayHelper* pHelper = NULL;
677 if ( !pHelper )
678 {
679 uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
680 pHelper = new UnoPropertyArrayHelper( aIDs );
681 }
682 return *pHelper;
683 }
684
685 // beans::XMultiPropertySet
getPropertySetInfo()686 uno::Reference< beans::XPropertySetInfo > UnoControlButtonModel::getPropertySetInfo( )
687 {
688 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
689 return xInfo;
690 }
691
692 // ----------------------------------------------------
693 // class UnoButtonControl
694 // ----------------------------------------------------
UnoButtonControl(const uno::Reference<lang::XMultiServiceFactory> & i_factory)695 UnoButtonControl::UnoButtonControl( const uno::Reference< lang::XMultiServiceFactory >& i_factory )
696 :UnoButtonControl_Base( i_factory )
697 ,maActionListeners( *this )
698 ,maItemListeners( *this )
699 {
700 maComponentInfos.nWidth = 50;
701 maComponentInfos.nHeight = 14;
702 }
703
GetComponentServiceName()704 ::rtl::OUString UnoButtonControl::GetComponentServiceName()
705 {
706 ::rtl::OUString aName( ::rtl::OUString::createFromAscii( "pushbutton" ) );
707 uno::Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_PUSHBUTTONTYPE ) );
708 sal_Int16 n = sal_Int16();
709 if ( ( aVal >>= n ) && n )
710 {
711 // Use PushButtonType later when available...
712 switch ( n )
713 {
714 case 1 /*PushButtonType::OK*/: aName= ::rtl::OUString::createFromAscii( "okbutton" );
715 break;
716 case 2 /*PushButtonType::CANCEL*/: aName= ::rtl::OUString::createFromAscii( "cancelbutton" );
717 break;
718 case 3 /*PushButtonType::HELP*/: aName= ::rtl::OUString::createFromAscii( "helpbutton" );
719 break;
720 default:
721 {
722 DBG_ERROR( "Unknown Button Type!" );
723 }
724 }
725 }
726 return aName;
727 }
728
dispose()729 void UnoButtonControl::dispose()
730 {
731 lang::EventObject aEvt;
732 aEvt.Source = (::cppu::OWeakObject*)this;
733 maActionListeners.disposeAndClear( aEvt );
734 maItemListeners.disposeAndClear( aEvt );
735 UnoControlBase::dispose();
736 }
737
createPeer(const uno::Reference<awt::XToolkit> & rxToolkit,const uno::Reference<awt::XWindowPeer> & rParentPeer)738 void UnoButtonControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer )
739 {
740 UnoControlBase::createPeer( rxToolkit, rParentPeer );
741
742 uno::Reference < awt::XButton > xButton( getPeer(), uno::UNO_QUERY );
743 xButton->setActionCommand( maActionCommand );
744 if ( maActionListeners.getLength() )
745 xButton->addActionListener( &maActionListeners );
746
747 uno::Reference< XToggleButton > xPushButton( getPeer(), uno::UNO_QUERY );
748 if ( xPushButton.is() )
749 xPushButton->addItemListener( this );
750 }
751
addActionListener(const uno::Reference<awt::XActionListener> & l)752 void UnoButtonControl::addActionListener(const uno::Reference< awt::XActionListener > & l)
753 {
754 maActionListeners.addInterface( l );
755 if( getPeer().is() && maActionListeners.getLength() == 1 )
756 {
757 uno::Reference < awt::XButton > xButton( getPeer(), uno::UNO_QUERY );
758 xButton->addActionListener( &maActionListeners );
759 }
760 }
761
removeActionListener(const uno::Reference<awt::XActionListener> & l)762 void UnoButtonControl::removeActionListener(const uno::Reference< awt::XActionListener > & l)
763 {
764 if( getPeer().is() && maActionListeners.getLength() == 1 )
765 {
766 uno::Reference < awt::XButton > xButton( getPeer(), uno::UNO_QUERY );
767 xButton->removeActionListener( &maActionListeners );
768 }
769 maActionListeners.removeInterface( l );
770 }
771
addItemListener(const uno::Reference<awt::XItemListener> & l)772 void UnoButtonControl::addItemListener(const uno::Reference< awt::XItemListener > & l)
773 {
774 maItemListeners.addInterface( l );
775 }
776
removeItemListener(const uno::Reference<awt::XItemListener> & l)777 void UnoButtonControl::removeItemListener(const uno::Reference< awt::XItemListener > & l)
778 {
779 maItemListeners.removeInterface( l );
780 }
781
disposing(const lang::EventObject & Source)782 void SAL_CALL UnoButtonControl::disposing( const lang::EventObject& Source )
783 {
784 UnoControlBase::disposing( Source );
785 }
786
itemStateChanged(const awt::ItemEvent & rEvent)787 void SAL_CALL UnoButtonControl::itemStateChanged( const awt::ItemEvent& rEvent )
788 {
789 // forward to model
790 uno::Any aAny;
791 aAny <<= (sal_Int16)rEvent.Selected;
792 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_STATE ), aAny, sal_False );
793
794 // multiplex
795 ItemEvent aEvent( rEvent );
796 aEvent.Source = *this;
797 maItemListeners.itemStateChanged( aEvent );
798 }
799
setLabel(const::rtl::OUString & rLabel)800 void UnoButtonControl::setLabel( const ::rtl::OUString& rLabel )
801 {
802 uno::Any aAny;
803 aAny <<= rLabel;
804 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_LABEL ), aAny, sal_True );
805 }
806
setActionCommand(const::rtl::OUString & rCommand)807 void UnoButtonControl::setActionCommand( const ::rtl::OUString& rCommand )
808 {
809 maActionCommand = rCommand;
810 if ( getPeer().is() )
811 {
812 uno::Reference < awt::XButton > xButton( getPeer(), uno::UNO_QUERY );
813 xButton->setActionCommand( rCommand );
814 }
815 }
816
getMinimumSize()817 awt::Size UnoButtonControl::getMinimumSize( )
818 {
819 return Impl_getMinimumSize();
820 }
821
getPreferredSize()822 awt::Size UnoButtonControl::getPreferredSize( )
823 {
824 return Impl_getPreferredSize();
825 }
826
calcAdjustedSize(const awt::Size & rNewSize)827 awt::Size UnoButtonControl::calcAdjustedSize( const awt::Size& rNewSize )
828 {
829 return Impl_calcAdjustedSize( rNewSize );
830 }
831
832 // ----------------------------------------------------
833 // class UnoControlImageControlModel
834 // ----------------------------------------------------
UnoControlImageControlModel(const Reference<XMultiServiceFactory> & i_factory)835 UnoControlImageControlModel::UnoControlImageControlModel( const Reference< XMultiServiceFactory >& i_factory )
836 :GraphicControlModel( i_factory )
837 ,mbAdjustingImageScaleMode( false )
838 {
839 UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXImageControl );
840 }
841
getServiceName()842 ::rtl::OUString UnoControlImageControlModel::getServiceName()
843 {
844 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlImageControlModel );
845 }
846
ImplGetDefaultValue(sal_uInt16 nPropId) const847 uno::Any UnoControlImageControlModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
848 {
849 if ( nPropId == BASEPROPERTY_DEFAULTCONTROL )
850 return uno::makeAny( ::rtl::OUString::createFromAscii( szServiceName_UnoControlImageControl ) );
851
852 if ( nPropId == BASEPROPERTY_IMAGE_SCALE_MODE )
853 return makeAny( awt::ImageScaleMode::ANISOTROPIC );
854
855 return GraphicControlModel::ImplGetDefaultValue( nPropId );
856 }
857
getInfoHelper()858 ::cppu::IPropertyArrayHelper& UnoControlImageControlModel::getInfoHelper()
859 {
860 static UnoPropertyArrayHelper* pHelper = NULL;
861 if ( !pHelper )
862 {
863 uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
864 pHelper = new UnoPropertyArrayHelper( aIDs );
865 }
866 return *pHelper;
867 }
868
869 // beans::XMultiPropertySet
getPropertySetInfo()870 uno::Reference< beans::XPropertySetInfo > UnoControlImageControlModel::getPropertySetInfo( )
871 {
872 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
873 return xInfo;
874 }
875
setFastPropertyValue_NoBroadcast(sal_Int32 _nHandle,const::com::sun::star::uno::Any & _rValue)876 void SAL_CALL UnoControlImageControlModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const ::com::sun::star::uno::Any& _rValue )
877 {
878 GraphicControlModel::setFastPropertyValue_NoBroadcast( _nHandle, _rValue );
879
880 // ScaleImage is an older (and less powerful) version of ScaleMode, but keep both in sync as far as possible
881 try
882 {
883 switch ( _nHandle )
884 {
885 case BASEPROPERTY_IMAGE_SCALE_MODE:
886 if ( !mbAdjustingImageScaleMode && ImplHasProperty( BASEPROPERTY_SCALEIMAGE ) )
887 {
888 mbAdjustingImageScaleMode = true;
889 sal_Int16 nScaleMode( awt::ImageScaleMode::ANISOTROPIC );
890 OSL_VERIFY( _rValue >>= nScaleMode );
891 setDependentFastPropertyValue( BASEPROPERTY_SCALEIMAGE, uno::makeAny( sal_Bool( nScaleMode != awt::ImageScaleMode::NONE ) ) );
892 mbAdjustingImageScaleMode = false;
893 }
894 break;
895 case BASEPROPERTY_SCALEIMAGE:
896 if ( !mbAdjustingImageScaleMode && ImplHasProperty( BASEPROPERTY_IMAGE_SCALE_MODE ) )
897 {
898 mbAdjustingImageScaleMode = true;
899 sal_Bool bScale = sal_True;
900 OSL_VERIFY( _rValue >>= bScale );
901 setDependentFastPropertyValue( BASEPROPERTY_IMAGE_SCALE_MODE, uno::makeAny( bScale ? awt::ImageScaleMode::ANISOTROPIC : awt::ImageScaleMode::NONE ) );
902 mbAdjustingImageScaleMode = false;
903 }
904 break;
905 }
906 }
907 catch( const Exception& )
908 {
909 mbAdjustingImageScaleMode = false;
910 throw;
911 }
912 }
913
914 // ----------------------------------------------------
915 // class UnoImageControlControl
916 // ----------------------------------------------------
UnoImageControlControl(const Reference<XMultiServiceFactory> & i_factory)917 UnoImageControlControl::UnoImageControlControl( const Reference< XMultiServiceFactory >& i_factory )
918 :UnoImageControlControl_Base( i_factory )
919 ,maActionListeners( *this )
920 {
921 // Woher die Defaults nehmen?
922 maComponentInfos.nWidth = 100;
923 maComponentInfos.nHeight = 100;
924 }
925
GetComponentServiceName()926 ::rtl::OUString UnoImageControlControl::GetComponentServiceName()
927 {
928 return ::rtl::OUString::createFromAscii( "fixedimage" );
929 }
930
dispose()931 void UnoImageControlControl::dispose()
932 {
933 lang::EventObject aEvt;
934 aEvt.Source = (::cppu::OWeakObject*)this;
935 maActionListeners.disposeAndClear( aEvt );
936 UnoControl::dispose();
937 }
938
isTransparent()939 sal_Bool UnoImageControlControl::isTransparent()
940 {
941 return sal_True;
942 }
943
getMinimumSize()944 awt::Size UnoImageControlControl::getMinimumSize( )
945 {
946 return Impl_getMinimumSize();
947 }
948
getPreferredSize()949 awt::Size UnoImageControlControl::getPreferredSize( )
950 {
951 return Impl_getPreferredSize();
952 }
953
calcAdjustedSize(const awt::Size & rNewSize)954 awt::Size UnoImageControlControl::calcAdjustedSize( const awt::Size& rNewSize )
955 {
956 return Impl_calcAdjustedSize( rNewSize );
957 }
958
959 // ----------------------------------------------------
960 // class UnoControlRadioButtonModel
961 // ----------------------------------------------------
UnoControlRadioButtonModel(const Reference<XMultiServiceFactory> & i_factory)962 UnoControlRadioButtonModel::UnoControlRadioButtonModel( const Reference< XMultiServiceFactory >& i_factory )
963 :GraphicControlModel( i_factory )
964 {
965 UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXRadioButton );
966 }
967
getServiceName()968 ::rtl::OUString UnoControlRadioButtonModel::getServiceName()
969 {
970 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlRadioButtonModel );
971 }
972
ImplGetDefaultValue(sal_uInt16 nPropId) const973 uno::Any UnoControlRadioButtonModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
974 {
975 switch ( nPropId )
976 {
977 case BASEPROPERTY_DEFAULTCONTROL:
978 return uno::makeAny( ::rtl::OUString::createFromAscii( szServiceName_UnoControlRadioButton ) );
979
980 case BASEPROPERTY_VISUALEFFECT:
981 return uno::makeAny( (sal_Int16)awt::VisualEffect::LOOK3D );
982 }
983
984 return GraphicControlModel::ImplGetDefaultValue( nPropId );
985 }
986
getInfoHelper()987 ::cppu::IPropertyArrayHelper& UnoControlRadioButtonModel::getInfoHelper()
988 {
989 static UnoPropertyArrayHelper* pHelper = NULL;
990 if ( !pHelper )
991 {
992 uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
993 pHelper = new UnoPropertyArrayHelper( aIDs );
994 }
995 return *pHelper;
996 }
997
998 // beans::XMultiPropertySet
getPropertySetInfo()999 uno::Reference< beans::XPropertySetInfo > UnoControlRadioButtonModel::getPropertySetInfo( )
1000 {
1001 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
1002 return xInfo;
1003 }
1004
1005
1006
1007 // ----------------------------------------------------
1008 // class UnoRadioButtonControl
1009 // ----------------------------------------------------
UnoRadioButtonControl(const Reference<XMultiServiceFactory> & i_factory)1010 UnoRadioButtonControl::UnoRadioButtonControl( const Reference< XMultiServiceFactory >& i_factory )
1011 :UnoRadioButtonControl_Base( i_factory )
1012 ,maItemListeners( *this )
1013 ,maActionListeners( *this )
1014 {
1015 maComponentInfos.nWidth = 100;
1016 maComponentInfos.nHeight = 12;
1017 }
1018
GetComponentServiceName()1019 ::rtl::OUString UnoRadioButtonControl::GetComponentServiceName()
1020 {
1021 return ::rtl::OUString::createFromAscii( "radiobutton" );
1022 }
1023
dispose()1024 void UnoRadioButtonControl::dispose()
1025 {
1026 lang::EventObject aEvt;
1027 aEvt.Source = (::cppu::OWeakObject*)this;
1028 maItemListeners.disposeAndClear( aEvt );
1029 UnoControlBase::dispose();
1030 }
1031
1032
isTransparent()1033 sal_Bool UnoRadioButtonControl::isTransparent()
1034 {
1035 return sal_True;
1036 }
1037
createPeer(const uno::Reference<awt::XToolkit> & rxToolkit,const uno::Reference<awt::XWindowPeer> & rParentPeer)1038 void UnoRadioButtonControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer )
1039 {
1040 UnoControlBase::createPeer( rxToolkit, rParentPeer );
1041
1042 uno::Reference < awt::XRadioButton > xRadioButton( getPeer(), uno::UNO_QUERY );
1043 xRadioButton->addItemListener( this );
1044
1045 uno::Reference < awt::XButton > xButton( getPeer(), uno::UNO_QUERY );
1046 xButton->setActionCommand( maActionCommand );
1047 if ( maActionListeners.getLength() )
1048 xButton->addActionListener( &maActionListeners );
1049
1050 // as default, set the "AutoToggle" to true
1051 // (it is set to false in VCLXToolkit::ImplCreateWindow because of #87254#, but we want to
1052 // have it enabled by default because of 85071)
1053 uno::Reference< awt::XVclWindowPeer > xVclWindowPeer( getPeer(), uno::UNO_QUERY );
1054 if ( xVclWindowPeer.is() )
1055 xVclWindowPeer->setProperty( GetPropertyName( BASEPROPERTY_AUTOTOGGLE ), ::cppu::bool2any( sal_True ) );
1056 }
1057
addItemListener(const uno::Reference<awt::XItemListener> & l)1058 void UnoRadioButtonControl::addItemListener(const uno::Reference < awt::XItemListener > & l)
1059 {
1060 maItemListeners.addInterface( l );
1061 }
1062
removeItemListener(const uno::Reference<awt::XItemListener> & l)1063 void UnoRadioButtonControl::removeItemListener(const uno::Reference < awt::XItemListener > & l)
1064 {
1065 maItemListeners.removeInterface( l );
1066 }
1067
addActionListener(const uno::Reference<awt::XActionListener> & l)1068 void UnoRadioButtonControl::addActionListener(const uno::Reference< awt::XActionListener > & l)
1069 {
1070 maActionListeners.addInterface( l );
1071 if( getPeer().is() && maActionListeners.getLength() == 1 )
1072 {
1073 uno::Reference < awt::XButton > xButton( getPeer(), uno::UNO_QUERY );
1074 xButton->addActionListener( &maActionListeners );
1075 }
1076 }
1077
removeActionListener(const uno::Reference<awt::XActionListener> & l)1078 void UnoRadioButtonControl::removeActionListener(const uno::Reference< awt::XActionListener > & l)
1079 {
1080 if( getPeer().is() && maActionListeners.getLength() == 1 )
1081 {
1082 uno::Reference < awt::XButton > xButton( getPeer(), uno::UNO_QUERY );
1083 xButton->removeActionListener( &maActionListeners );
1084 }
1085 maActionListeners.removeInterface( l );
1086 }
1087
setLabel(const::rtl::OUString & rLabel)1088 void UnoRadioButtonControl::setLabel( const ::rtl::OUString& rLabel )
1089 {
1090 uno::Any aAny;
1091 aAny <<= rLabel;
1092 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_LABEL ), aAny, sal_True );
1093 }
1094
setActionCommand(const::rtl::OUString & rCommand)1095 void UnoRadioButtonControl::setActionCommand( const ::rtl::OUString& rCommand )
1096 {
1097 maActionCommand = rCommand;
1098 if ( getPeer().is() )
1099 {
1100 uno::Reference < awt::XButton > xButton( getPeer(), uno::UNO_QUERY );
1101 xButton->setActionCommand( rCommand );
1102 }
1103 }
1104
setState(sal_Bool bOn)1105 void UnoRadioButtonControl::setState( sal_Bool bOn )
1106 {
1107 sal_Int16 nState = bOn ? 1 : 0;
1108 uno::Any aAny;
1109 aAny <<= nState;
1110 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_STATE ), aAny, sal_True );
1111 }
1112
getState()1113 sal_Bool UnoRadioButtonControl::getState()
1114 {
1115 sal_Int16 nState = 0;
1116 uno::Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_STATE ) );
1117 aVal >>= nState;
1118 return nState ? sal_True : sal_False;
1119 }
1120
itemStateChanged(const awt::ItemEvent & rEvent)1121 void UnoRadioButtonControl::itemStateChanged( const awt::ItemEvent& rEvent )
1122 {
1123 uno::Any aAny;
1124 aAny <<= (sal_Int16)rEvent.Selected;
1125 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_STATE ), aAny, sal_False );
1126
1127 // compatibility:
1128 // in OOo 1.0.x, when the user clicked a radio button in a group of buttons, this resulted
1129 // in _one_ itemStateChanged call for exactly the radio button which's state changed from
1130 // "0" to "1".
1131 // Nowadays, since the listener handling changed a lot towards 1.1 (the VCLXWindow reacts on more
1132 // basic events from the VCL-windows, not anymore on the Link-based events like in 1.0.x), this
1133 // isn't the case anymore: For instance, this method here gets called for the radio button
1134 // which is being implicitly _de_selected, too. This is pretty bad for compatibility.
1135 // Thus, we suppress all events with a new state other than "1". This is unlogical, and weird, when looking
1136 // from a pure API perspective, but it's _compatible_ with older product versions, and this is
1137 // all which matters here.
1138 // #i14703# - 2003-05-23 - fs@openoffice.org
1139 if ( 1 == rEvent.Selected )
1140 {
1141 if ( maItemListeners.getLength() )
1142 maItemListeners.itemStateChanged( rEvent );
1143 }
1144 // note that speaking strictly, this is wrong: When in 1.0.x, the user would have de-selected
1145 // a radio button _without_ selecting another one, this would have caused a notification.
1146 // With the change done here, this today won't cause a notification anymore.
1147 //
1148 // Fortunately, it's not possible for the user to de-select a radio button without selecting another on,
1149 // at least not via the regular UI. It _would_ be possible via the Accessibility API, which
1150 // counts as "user input", too. But in 1.0.x, there was no Accessibility API, so there is nothing
1151 // to be inconsistent with.
1152 }
1153
getMinimumSize()1154 awt::Size UnoRadioButtonControl::getMinimumSize( )
1155 {
1156 return Impl_getMinimumSize();
1157 }
1158
getPreferredSize()1159 awt::Size UnoRadioButtonControl::getPreferredSize( )
1160 {
1161 return Impl_getPreferredSize();
1162 }
1163
calcAdjustedSize(const awt::Size & rNewSize)1164 awt::Size UnoRadioButtonControl::calcAdjustedSize( const awt::Size& rNewSize )
1165 {
1166 return Impl_calcAdjustedSize( rNewSize );
1167 }
1168
1169 // ----------------------------------------------------
1170 // class UnoControlCheckBoxModel
1171 // ----------------------------------------------------
UnoControlCheckBoxModel(const Reference<XMultiServiceFactory> & i_factory)1172 UnoControlCheckBoxModel::UnoControlCheckBoxModel( const Reference< XMultiServiceFactory >& i_factory )
1173 :GraphicControlModel( i_factory )
1174 {
1175 UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXCheckBox );
1176 }
1177
getServiceName()1178 ::rtl::OUString UnoControlCheckBoxModel::getServiceName()
1179 {
1180 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlCheckBoxModel );
1181 }
1182
ImplGetDefaultValue(sal_uInt16 nPropId) const1183 uno::Any UnoControlCheckBoxModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
1184 {
1185 switch ( nPropId )
1186 {
1187 case BASEPROPERTY_DEFAULTCONTROL:
1188 return uno::makeAny( ::rtl::OUString::createFromAscii( szServiceName_UnoControlCheckBox ) );
1189
1190 case BASEPROPERTY_VISUALEFFECT:
1191 return uno::makeAny( (sal_Int16)awt::VisualEffect::LOOK3D );
1192 }
1193
1194 return GraphicControlModel::ImplGetDefaultValue( nPropId );
1195 }
1196
getInfoHelper()1197 ::cppu::IPropertyArrayHelper& UnoControlCheckBoxModel::getInfoHelper()
1198 {
1199 static UnoPropertyArrayHelper* pHelper = NULL;
1200 if ( !pHelper )
1201 {
1202 uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
1203 pHelper = new UnoPropertyArrayHelper( aIDs );
1204 }
1205 return *pHelper;
1206 }
1207
1208 // beans::XMultiPropertySet
getPropertySetInfo()1209 uno::Reference< beans::XPropertySetInfo > UnoControlCheckBoxModel::getPropertySetInfo( )
1210 {
1211 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
1212 return xInfo;
1213 }
1214
1215
1216
1217 // ----------------------------------------------------
1218 // class UnoCheckBoxControl
1219 // ----------------------------------------------------
UnoCheckBoxControl(const uno::Reference<lang::XMultiServiceFactory> & i_factory)1220 UnoCheckBoxControl::UnoCheckBoxControl( const uno::Reference< lang::XMultiServiceFactory >& i_factory )
1221 :UnoCheckBoxControl_Base( i_factory )
1222 ,maItemListeners( *this ), maActionListeners( *this )
1223 {
1224 maComponentInfos.nWidth = 100;
1225 maComponentInfos.nHeight = 12;
1226 }
1227
GetComponentServiceName()1228 ::rtl::OUString UnoCheckBoxControl::GetComponentServiceName()
1229 {
1230 return ::rtl::OUString::createFromAscii( "checkbox" );
1231 }
1232
dispose()1233 void UnoCheckBoxControl::dispose()
1234 {
1235 lang::EventObject aEvt;
1236 aEvt.Source = (::cppu::OWeakObject*)this;
1237 maItemListeners.disposeAndClear( aEvt );
1238 UnoControlBase::dispose();
1239 }
1240
isTransparent()1241 sal_Bool UnoCheckBoxControl::isTransparent()
1242 {
1243 return sal_True;
1244 }
1245
createPeer(const uno::Reference<awt::XToolkit> & rxToolkit,const uno::Reference<awt::XWindowPeer> & rParentPeer)1246 void UnoCheckBoxControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer )
1247 {
1248 UnoControlBase::createPeer( rxToolkit, rParentPeer );
1249
1250 uno::Reference < awt::XCheckBox > xCheckBox( getPeer(), uno::UNO_QUERY );
1251 xCheckBox->addItemListener( this );
1252
1253 uno::Reference < awt::XButton > xButton( getPeer(), uno::UNO_QUERY );
1254 xButton->setActionCommand( maActionCommand );
1255 if ( maActionListeners.getLength() )
1256 xButton->addActionListener( &maActionListeners );
1257 }
1258
addItemListener(const uno::Reference<awt::XItemListener> & l)1259 void UnoCheckBoxControl::addItemListener(const uno::Reference < awt::XItemListener > & l)
1260 {
1261 maItemListeners.addInterface( l );
1262 }
1263
removeItemListener(const uno::Reference<awt::XItemListener> & l)1264 void UnoCheckBoxControl::removeItemListener(const uno::Reference < awt::XItemListener > & l)
1265 {
1266 maItemListeners.removeInterface( l );
1267 }
1268
addActionListener(const uno::Reference<awt::XActionListener> & l)1269 void UnoCheckBoxControl::addActionListener(const uno::Reference< awt::XActionListener > & l)
1270 {
1271 maActionListeners.addInterface( l );
1272 if( getPeer().is() && maActionListeners.getLength() == 1 )
1273 {
1274 uno::Reference < awt::XButton > xButton( getPeer(), uno::UNO_QUERY );
1275 xButton->addActionListener( &maActionListeners );
1276 }
1277 }
1278
removeActionListener(const uno::Reference<awt::XActionListener> & l)1279 void UnoCheckBoxControl::removeActionListener(const uno::Reference< awt::XActionListener > & l)
1280 {
1281 if( getPeer().is() && maActionListeners.getLength() == 1 )
1282 {
1283 uno::Reference < awt::XButton > xButton( getPeer(), uno::UNO_QUERY );
1284 xButton->removeActionListener( &maActionListeners );
1285 }
1286 maActionListeners.removeInterface( l );
1287 }
1288
setActionCommand(const::rtl::OUString & rCommand)1289 void UnoCheckBoxControl::setActionCommand( const ::rtl::OUString& rCommand )
1290 {
1291 maActionCommand = rCommand;
1292 if ( getPeer().is() )
1293 {
1294 uno::Reference < awt::XButton > xButton( getPeer(), uno::UNO_QUERY );
1295 xButton->setActionCommand( rCommand );
1296 }
1297 }
1298
1299
setLabel(const::rtl::OUString & rLabel)1300 void UnoCheckBoxControl::setLabel( const ::rtl::OUString& rLabel )
1301 {
1302 uno::Any aAny;
1303 aAny <<= rLabel;
1304 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_LABEL ), aAny, sal_True );
1305 }
1306
setState(short n)1307 void UnoCheckBoxControl::setState( short n )
1308 {
1309 uno::Any aAny;
1310 aAny <<= (sal_Int16)n;
1311 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_STATE ), aAny, sal_True );
1312 }
1313
getState()1314 short UnoCheckBoxControl::getState()
1315 {
1316 short nState = 0;
1317 uno::Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_STATE ) );
1318 aVal >>= nState;
1319 return nState;
1320 }
1321
enableTriState(sal_Bool b)1322 void UnoCheckBoxControl::enableTriState( sal_Bool b )
1323 {
1324 uno::Any aAny;
1325 aAny <<= b;
1326 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_TRISTATE ), aAny, sal_True );
1327 }
1328
itemStateChanged(const awt::ItemEvent & rEvent)1329 void UnoCheckBoxControl::itemStateChanged( const awt::ItemEvent& rEvent )
1330 {
1331 uno::Any aAny;
1332 aAny <<= (sal_Int16)rEvent.Selected;
1333 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_STATE ), aAny, sal_False );
1334
1335 if ( maItemListeners.getLength() )
1336 maItemListeners.itemStateChanged( rEvent );
1337 }
1338
getMinimumSize()1339 awt::Size UnoCheckBoxControl::getMinimumSize( )
1340 {
1341 return Impl_getMinimumSize();
1342 }
1343
getPreferredSize()1344 awt::Size UnoCheckBoxControl::getPreferredSize( )
1345 {
1346 return Impl_getPreferredSize();
1347 }
1348
calcAdjustedSize(const awt::Size & rNewSize)1349 awt::Size UnoCheckBoxControl::calcAdjustedSize( const awt::Size& rNewSize )
1350 {
1351 return Impl_calcAdjustedSize( rNewSize );
1352 }
1353
1354 // ----------------------------------------------------
1355 // class UnoControlFixedHyperlinkModel
1356 // ----------------------------------------------------
UnoControlFixedHyperlinkModel(const Reference<XMultiServiceFactory> & i_factory)1357 UnoControlFixedHyperlinkModel::UnoControlFixedHyperlinkModel( const Reference< XMultiServiceFactory >& i_factory )
1358 :UnoControlModel( i_factory )
1359 {
1360 UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXFixedHyperlink );
1361 }
1362
getServiceName()1363 ::rtl::OUString UnoControlFixedHyperlinkModel::getServiceName()
1364 {
1365 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlFixedHyperlinkModel );
1366 }
1367
ImplGetDefaultValue(sal_uInt16 nPropId) const1368 uno::Any UnoControlFixedHyperlinkModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
1369 {
1370 if ( nPropId == BASEPROPERTY_DEFAULTCONTROL )
1371 {
1372 uno::Any aAny;
1373 aAny <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlFixedHyperlink );
1374 return aAny;
1375 }
1376 else if ( nPropId == BASEPROPERTY_BORDER )
1377 {
1378 uno::Any aAny;
1379 aAny <<= (sal_Int16)0;
1380 return aAny;
1381 }
1382 else if ( nPropId == BASEPROPERTY_URL )
1383 {
1384 uno::Any aAny;
1385 aAny <<= ::rtl::OUString();
1386 return aAny;
1387 }
1388
1389 return UnoControlModel::ImplGetDefaultValue( nPropId );
1390 }
1391
getInfoHelper()1392 ::cppu::IPropertyArrayHelper& UnoControlFixedHyperlinkModel::getInfoHelper()
1393 {
1394 static UnoPropertyArrayHelper* pHelper = NULL;
1395 if ( !pHelper )
1396 {
1397 uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
1398 pHelper = new UnoPropertyArrayHelper( aIDs );
1399 }
1400 return *pHelper;
1401 }
1402
1403 // beans::XMultiPropertySet
getPropertySetInfo()1404 uno::Reference< beans::XPropertySetInfo > UnoControlFixedHyperlinkModel::getPropertySetInfo( )
1405 {
1406 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
1407 return xInfo;
1408 }
1409
1410 // ----------------------------------------------------
1411 // class UnoFixedHyperlinkControl
1412 // ----------------------------------------------------
UnoFixedHyperlinkControl(const Reference<XMultiServiceFactory> & i_factory)1413 UnoFixedHyperlinkControl::UnoFixedHyperlinkControl( const Reference< XMultiServiceFactory >& i_factory )
1414 :UnoControlBase( i_factory )
1415 ,maActionListeners( *this )
1416 {
1417 maComponentInfos.nWidth = 100;
1418 maComponentInfos.nHeight = 12;
1419 }
1420
GetComponentServiceName()1421 ::rtl::OUString UnoFixedHyperlinkControl::GetComponentServiceName()
1422 {
1423 return ::rtl::OUString::createFromAscii( "fixedhyperlink" );
1424 }
1425
1426 // uno::XInterface
queryAggregation(const uno::Type & rType)1427 uno::Any UnoFixedHyperlinkControl::queryAggregation( const uno::Type & rType )
1428 {
1429 uno::Any aRet = ::cppu::queryInterface( rType,
1430 SAL_STATIC_CAST( awt::XFixedHyperlink*, this ),
1431 SAL_STATIC_CAST( awt::XLayoutConstrains*, this ) );
1432 return (aRet.hasValue() ? aRet : UnoControlBase::queryAggregation( rType ));
1433 }
1434
1435 // lang::XTypeProvider
1436 IMPL_XTYPEPROVIDER_START( UnoFixedHyperlinkControl )
1437 getCppuType( ( uno::Reference< awt::XFixedHyperlink>* ) NULL ),
1438 getCppuType( ( uno::Reference< awt::XLayoutConstrains>* ) NULL ),
1439 UnoControlBase::getTypes()
1440 IMPL_XTYPEPROVIDER_END
1441
1442 sal_Bool UnoFixedHyperlinkControl::isTransparent()
1443 {
1444 return sal_True;
1445 }
1446
setText(const::rtl::OUString & Text)1447 void UnoFixedHyperlinkControl::setText( const ::rtl::OUString& Text )
1448 {
1449 uno::Any aAny;
1450 aAny <<= Text;
1451 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_LABEL ), aAny, sal_True );
1452 }
1453
getText()1454 ::rtl::OUString UnoFixedHyperlinkControl::getText()
1455 {
1456 return ImplGetPropertyValue_UString( BASEPROPERTY_LABEL );
1457 }
1458
setURL(const::rtl::OUString & URL)1459 void UnoFixedHyperlinkControl::setURL( const ::rtl::OUString& URL )
1460 {
1461 uno::Any aAny;
1462 aAny <<= URL;
1463 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_URL ), aAny, sal_True );
1464 }
1465
getURL()1466 ::rtl::OUString UnoFixedHyperlinkControl::getURL( )
1467 {
1468 return ImplGetPropertyValue_UString( BASEPROPERTY_URL );
1469 }
1470
setAlignment(short nAlign)1471 void UnoFixedHyperlinkControl::setAlignment( short nAlign )
1472 {
1473 uno::Any aAny;
1474 aAny <<= (sal_Int16)nAlign;
1475 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_ALIGN ), aAny, sal_True );
1476 }
1477
getAlignment()1478 short UnoFixedHyperlinkControl::getAlignment()
1479 {
1480 short nAlign = 0;
1481 if ( mxModel.is() )
1482 {
1483 uno::Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_ALIGN ) );
1484 aVal >>= nAlign;
1485 }
1486 return nAlign;
1487 }
1488
getMinimumSize()1489 awt::Size UnoFixedHyperlinkControl::getMinimumSize( )
1490 {
1491 return Impl_getMinimumSize();
1492 }
1493
getPreferredSize()1494 awt::Size UnoFixedHyperlinkControl::getPreferredSize( )
1495 {
1496 return Impl_getPreferredSize();
1497 }
1498
calcAdjustedSize(const awt::Size & rNewSize)1499 awt::Size UnoFixedHyperlinkControl::calcAdjustedSize( const awt::Size& rNewSize )
1500 {
1501 return Impl_calcAdjustedSize( rNewSize );
1502 }
1503
dispose()1504 void UnoFixedHyperlinkControl::dispose()
1505 {
1506 lang::EventObject aEvt;
1507 aEvt.Source = (::cppu::OWeakObject*)this;
1508 maActionListeners.disposeAndClear( aEvt );
1509 UnoControlBase::dispose();
1510 }
1511
createPeer(const uno::Reference<awt::XToolkit> & rxToolkit,const uno::Reference<awt::XWindowPeer> & rParentPeer)1512 void UnoFixedHyperlinkControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer )
1513 {
1514 UnoControlBase::createPeer( rxToolkit, rParentPeer );
1515
1516 uno::Reference < awt::XFixedHyperlink > xFixedHyperlink( getPeer(), uno::UNO_QUERY );
1517 if ( maActionListeners.getLength() )
1518 xFixedHyperlink->addActionListener( &maActionListeners );
1519 }
1520
addActionListener(const uno::Reference<awt::XActionListener> & l)1521 void UnoFixedHyperlinkControl::addActionListener(const uno::Reference< awt::XActionListener > & l)
1522 {
1523 maActionListeners.addInterface( l );
1524 if( getPeer().is() && maActionListeners.getLength() == 1 )
1525 {
1526 uno::Reference < awt::XFixedHyperlink > xFixedHyperlink( getPeer(), uno::UNO_QUERY );
1527 xFixedHyperlink->addActionListener( &maActionListeners );
1528 }
1529 }
1530
removeActionListener(const uno::Reference<awt::XActionListener> & l)1531 void UnoFixedHyperlinkControl::removeActionListener(const uno::Reference< awt::XActionListener > & l)
1532 {
1533 if( getPeer().is() && maActionListeners.getLength() == 1 )
1534 {
1535 uno::Reference < awt::XFixedHyperlink > xFixedHyperlink( getPeer(), uno::UNO_QUERY );
1536 xFixedHyperlink->removeActionListener( &maActionListeners );
1537 }
1538 maActionListeners.removeInterface( l );
1539 }
1540
1541 // ----------------------------------------------------
1542 // class UnoControlFixedTextModel
1543 // ----------------------------------------------------
UnoControlFixedTextModel(const Reference<XMultiServiceFactory> & i_factory)1544 UnoControlFixedTextModel::UnoControlFixedTextModel( const Reference< XMultiServiceFactory >& i_factory )
1545 :UnoControlModel( i_factory )
1546 {
1547 UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXFixedText );
1548 }
1549
getServiceName()1550 ::rtl::OUString UnoControlFixedTextModel::getServiceName()
1551 {
1552 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlFixedTextModel );
1553 }
1554
ImplGetDefaultValue(sal_uInt16 nPropId) const1555 uno::Any UnoControlFixedTextModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
1556 {
1557 if ( nPropId == BASEPROPERTY_DEFAULTCONTROL )
1558 {
1559 uno::Any aAny;
1560 aAny <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlFixedText );
1561 return aAny;
1562 }
1563 else if ( nPropId == BASEPROPERTY_BORDER )
1564 {
1565 uno::Any aAny;
1566 aAny <<= (sal_Int16)0;
1567 return aAny;
1568 }
1569
1570 return UnoControlModel::ImplGetDefaultValue( nPropId );
1571 }
1572
getInfoHelper()1573 ::cppu::IPropertyArrayHelper& UnoControlFixedTextModel::getInfoHelper()
1574 {
1575 static UnoPropertyArrayHelper* pHelper = NULL;
1576 if ( !pHelper )
1577 {
1578 uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
1579 pHelper = new UnoPropertyArrayHelper( aIDs );
1580 }
1581 return *pHelper;
1582 }
1583
1584 // beans::XMultiPropertySet
getPropertySetInfo()1585 uno::Reference< beans::XPropertySetInfo > UnoControlFixedTextModel::getPropertySetInfo( )
1586 {
1587 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
1588 return xInfo;
1589 }
1590
1591
1592 // ----------------------------------------------------
1593 // class UnoFixedTextControl
1594 // ----------------------------------------------------
UnoFixedTextControl(const Reference<XMultiServiceFactory> & i_factory)1595 UnoFixedTextControl::UnoFixedTextControl( const Reference< XMultiServiceFactory >& i_factory )
1596 :UnoControlBase( i_factory )
1597 {
1598 maComponentInfos.nWidth = 100;
1599 maComponentInfos.nHeight = 12;
1600 }
1601
GetComponentServiceName()1602 ::rtl::OUString UnoFixedTextControl::GetComponentServiceName()
1603 {
1604 return ::rtl::OUString::createFromAscii( "fixedtext" );
1605 }
1606
1607 // uno::XInterface
queryAggregation(const uno::Type & rType)1608 uno::Any UnoFixedTextControl::queryAggregation( const uno::Type & rType )
1609 {
1610 uno::Any aRet = ::cppu::queryInterface( rType,
1611 SAL_STATIC_CAST( awt::XFixedText*, this ),
1612 SAL_STATIC_CAST( awt::XLayoutConstrains*, this ) );
1613 return (aRet.hasValue() ? aRet : UnoControlBase::queryAggregation( rType ));
1614 }
1615
1616 // lang::XTypeProvider
1617 IMPL_XTYPEPROVIDER_START( UnoFixedTextControl )
1618 getCppuType( ( uno::Reference< awt::XFixedText>* ) NULL ),
1619 getCppuType( ( uno::Reference< awt::XLayoutConstrains>* ) NULL ),
1620 UnoControlBase::getTypes()
1621 IMPL_XTYPEPROVIDER_END
1622
1623 sal_Bool UnoFixedTextControl::isTransparent()
1624 {
1625 return sal_True;
1626 }
1627
setText(const::rtl::OUString & Text)1628 void UnoFixedTextControl::setText( const ::rtl::OUString& Text )
1629 {
1630 uno::Any aAny;
1631 aAny <<= Text;
1632 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_LABEL ), aAny, sal_True );
1633 }
1634
getText()1635 ::rtl::OUString UnoFixedTextControl::getText()
1636 {
1637 return ImplGetPropertyValue_UString( BASEPROPERTY_LABEL );
1638 }
1639
setAlignment(short nAlign)1640 void UnoFixedTextControl::setAlignment( short nAlign )
1641 {
1642 uno::Any aAny;
1643 aAny <<= (sal_Int16)nAlign;
1644 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_ALIGN ), aAny, sal_True );
1645 }
1646
getAlignment()1647 short UnoFixedTextControl::getAlignment()
1648 {
1649 short nAlign = 0;
1650 if ( mxModel.is() )
1651 {
1652 uno::Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_ALIGN ) );
1653 aVal >>= nAlign;
1654 }
1655 return nAlign;
1656 }
1657
getMinimumSize()1658 awt::Size UnoFixedTextControl::getMinimumSize( )
1659 {
1660 return Impl_getMinimumSize();
1661 }
1662
getPreferredSize()1663 awt::Size UnoFixedTextControl::getPreferredSize( )
1664 {
1665 return Impl_getPreferredSize();
1666 }
1667
calcAdjustedSize(const awt::Size & rNewSize)1668 awt::Size UnoFixedTextControl::calcAdjustedSize( const awt::Size& rNewSize )
1669 {
1670 return Impl_calcAdjustedSize( rNewSize );
1671 }
1672
1673 // ----------------------------------------------------
1674 // class UnoControlGroupBoxModel
1675 // ----------------------------------------------------
UnoControlGroupBoxModel(const Reference<XMultiServiceFactory> & i_factory)1676 UnoControlGroupBoxModel::UnoControlGroupBoxModel( const Reference< XMultiServiceFactory >& i_factory )
1677 :UnoControlModel( i_factory )
1678 {
1679 ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL );
1680 ImplRegisterProperty( BASEPROPERTY_ENABLED );
1681 ImplRegisterProperty( BASEPROPERTY_ENABLEVISIBLE );
1682 ImplRegisterProperty( BASEPROPERTY_FONTDESCRIPTOR );
1683 ImplRegisterProperty( BASEPROPERTY_HELPTEXT );
1684 ImplRegisterProperty( BASEPROPERTY_HELPURL );
1685 ImplRegisterProperty( BASEPROPERTY_LABEL );
1686 ImplRegisterProperty( BASEPROPERTY_PRINTABLE );
1687 ImplRegisterProperty( BASEPROPERTY_WRITING_MODE );
1688 ImplRegisterProperty( BASEPROPERTY_CONTEXT_WRITING_MODE );
1689 }
1690
getServiceName()1691 ::rtl::OUString UnoControlGroupBoxModel::getServiceName()
1692 {
1693 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlGroupBoxModel );
1694 }
1695
ImplGetDefaultValue(sal_uInt16 nPropId) const1696 uno::Any UnoControlGroupBoxModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
1697 {
1698 if ( nPropId == BASEPROPERTY_DEFAULTCONTROL )
1699 {
1700 uno::Any aAny;
1701 aAny <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlGroupBox );
1702 return aAny;
1703 }
1704 return UnoControlModel::ImplGetDefaultValue( nPropId );
1705 }
1706
getInfoHelper()1707 ::cppu::IPropertyArrayHelper& UnoControlGroupBoxModel::getInfoHelper()
1708 {
1709 static UnoPropertyArrayHelper* pHelper = NULL;
1710 if ( !pHelper )
1711 {
1712 uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
1713 pHelper = new UnoPropertyArrayHelper( aIDs );
1714 }
1715 return *pHelper;
1716 }
1717
1718 // beans::XMultiPropertySet
getPropertySetInfo()1719 uno::Reference< beans::XPropertySetInfo > UnoControlGroupBoxModel::getPropertySetInfo( )
1720 {
1721 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
1722 return xInfo;
1723 }
1724
1725 // ----------------------------------------------------
1726 // class UnoGroupBoxControl
1727 // ----------------------------------------------------
UnoGroupBoxControl(const Reference<XMultiServiceFactory> & i_factory)1728 UnoGroupBoxControl::UnoGroupBoxControl( const Reference< XMultiServiceFactory >& i_factory )
1729 :UnoControlBase( i_factory )
1730 {
1731 maComponentInfos.nWidth = 100;
1732 maComponentInfos.nHeight = 100;
1733 }
1734
GetComponentServiceName()1735 ::rtl::OUString UnoGroupBoxControl::GetComponentServiceName()
1736 {
1737 return ::rtl::OUString::createFromAscii( "groupbox" );
1738 }
1739
isTransparent()1740 sal_Bool UnoGroupBoxControl::isTransparent()
1741 {
1742 return sal_True;
1743 }
1744
1745 // =====================================================================================================================
1746 // = UnoControlListBoxModel_Data
1747 // =====================================================================================================================
1748 struct ListItem
1749 {
1750 ::rtl::OUString ItemText;
1751 ::rtl::OUString ItemImageURL;
1752 Any ItemData;
1753
ListItemListItem1754 ListItem()
1755 :ItemText()
1756 ,ItemImageURL()
1757 ,ItemData()
1758 {
1759 }
1760
ListItemListItem1761 ListItem( const ::rtl::OUString& i_rItemText )
1762 :ItemText( i_rItemText )
1763 ,ItemImageURL()
1764 ,ItemData()
1765 {
1766 }
1767 };
1768
1769 typedef beans::Pair< ::rtl::OUString, ::rtl::OUString > UnoListItem;
1770
1771 struct StripItemData
1772 {
1773 typedef ListItem argument_type;
1774 typedef UnoListItem result_type;
operator ()StripItemData1775 UnoListItem operator()( const ListItem& i_rItem )
1776 {
1777 return UnoListItem( i_rItem.ItemText, i_rItem.ItemImageURL );
1778 }
1779 };
1780
1781 struct UnoControlListBoxModel_Data
1782 {
UnoControlListBoxModel_DataUnoControlListBoxModel_Data1783 UnoControlListBoxModel_Data( UnoControlListBoxModel& i_rAntiImpl )
1784 :m_bSettingLegacyProperty( false )
1785 ,m_rAntiImpl( i_rAntiImpl )
1786 ,m_aListItems()
1787 {
1788 }
1789
getItemCountUnoControlListBoxModel_Data1790 sal_Int32 getItemCount() const { return sal_Int32( m_aListItems.size() ); }
1791
getItemUnoControlListBoxModel_Data1792 const ListItem& getItem( const sal_Int32 i_nIndex ) const
1793 {
1794 if ( ( i_nIndex < 0 ) || ( i_nIndex >= sal_Int32( m_aListItems.size() ) ) )
1795 throw IndexOutOfBoundsException( ::rtl::OUString(), m_rAntiImpl );
1796 return m_aListItems[ i_nIndex ];
1797 }
1798
getItemUnoControlListBoxModel_Data1799 ListItem& getItem( const sal_Int32 i_nIndex )
1800 {
1801 return const_cast< ListItem& >( static_cast< const UnoControlListBoxModel_Data* >( this )->getItem( i_nIndex ) );
1802 }
1803
insertItemUnoControlListBoxModel_Data1804 ListItem& insertItem( const sal_Int32 i_nIndex )
1805 {
1806 if ( ( i_nIndex < 0 ) || ( i_nIndex > sal_Int32( m_aListItems.size() ) ) )
1807 throw IndexOutOfBoundsException( ::rtl::OUString(), m_rAntiImpl );
1808 return *m_aListItems.insert( m_aListItems.begin() + i_nIndex, ListItem() );
1809 }
1810
getAllItemsUnoControlListBoxModel_Data1811 Sequence< UnoListItem > getAllItems() const
1812 {
1813 Sequence< UnoListItem > aItems( sal_Int32( m_aListItems.size() ) );
1814 ::std::transform( m_aListItems.begin(), m_aListItems.end(), aItems.getArray(), StripItemData() );
1815 return aItems;
1816 }
1817
copyItemsUnoControlListBoxModel_Data1818 void copyItems( const UnoControlListBoxModel_Data& i_copySource )
1819 {
1820 m_aListItems = i_copySource.m_aListItems;
1821 }
1822
setAllItemsUnoControlListBoxModel_Data1823 void setAllItems( const ::std::vector< ListItem >& i_rItems )
1824 {
1825 m_aListItems = i_rItems;
1826 }
1827
removeItemUnoControlListBoxModel_Data1828 void removeItem( const sal_Int32 i_nIndex )
1829 {
1830 if ( ( i_nIndex < 0 ) || ( i_nIndex >= sal_Int32( m_aListItems.size() ) ) )
1831 throw IndexOutOfBoundsException( ::rtl::OUString(), m_rAntiImpl );
1832 m_aListItems.erase( m_aListItems.begin() + i_nIndex );
1833 }
1834
removeAllItemsUnoControlListBoxModel_Data1835 void removeAllItems()
1836 {
1837 ::std::vector< ListItem > aEmpty;
1838 m_aListItems.swap( aEmpty );
1839 }
1840
1841 public:
1842 bool m_bSettingLegacyProperty;
1843
1844 private:
1845 UnoControlListBoxModel& m_rAntiImpl;
1846 ::std::vector< ListItem > m_aListItems;
1847 };
1848
1849 // =====================================================================================================================
1850 // = UnoControlListBoxModel
1851 // =====================================================================================================================
1852 // ---------------------------------------------------------------------------------------------------------------------
UnoControlListBoxModel(const Reference<XMultiServiceFactory> & i_factory,ConstructorMode const i_mode)1853 UnoControlListBoxModel::UnoControlListBoxModel( const Reference< XMultiServiceFactory >& i_factory, ConstructorMode const i_mode )
1854 :UnoControlListBoxModel_Base( i_factory )
1855 ,m_pData( new UnoControlListBoxModel_Data( *this ) )
1856 ,m_aItemListListeners( GetMutex() )
1857 {
1858 if ( i_mode == ConstructDefault )
1859 {
1860 UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXListBox );
1861 }
1862 }
1863 // ---------------------------------------------------------------------------------------------------------------------
UnoControlListBoxModel(const UnoControlListBoxModel & i_rSource)1864 UnoControlListBoxModel::UnoControlListBoxModel( const UnoControlListBoxModel& i_rSource )
1865 :UnoControlListBoxModel_Base( i_rSource )
1866 ,m_pData( new UnoControlListBoxModel_Data( *this ) )
1867 ,m_aItemListListeners( GetMutex() )
1868 {
1869 m_pData->copyItems( *i_rSource.m_pData );
1870 }
~UnoControlListBoxModel()1871 UnoControlListBoxModel::~UnoControlListBoxModel()
1872 {
1873 }
IMPL_SERVICEINFO_DERIVED(UnoControlListBoxModel,UnoControlModel,szServiceName2_UnoControlListBoxModel)1874 IMPL_SERVICEINFO_DERIVED( UnoControlListBoxModel, UnoControlModel, szServiceName2_UnoControlListBoxModel )
1875 // ---------------------------------------------------------------------------------------------------------------------
1876 ::rtl::OUString UnoControlListBoxModel::getServiceName()
1877 {
1878 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlListBoxModel );
1879 }
1880
1881 // ---------------------------------------------------------------------------------------------------------------------
ImplGetDefaultValue(sal_uInt16 nPropId) const1882 uno::Any UnoControlListBoxModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
1883 {
1884 if ( nPropId == BASEPROPERTY_DEFAULTCONTROL )
1885 {
1886 uno::Any aAny;
1887 aAny <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlListBox );
1888 return aAny;
1889 }
1890 return UnoControlModel::ImplGetDefaultValue( nPropId );
1891 }
1892
1893 // ---------------------------------------------------------------------------------------------------------------------
getInfoHelper()1894 ::cppu::IPropertyArrayHelper& UnoControlListBoxModel::getInfoHelper()
1895 {
1896 static UnoPropertyArrayHelper* pHelper = NULL;
1897 if ( !pHelper )
1898 {
1899 uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
1900 pHelper = new UnoPropertyArrayHelper( aIDs );
1901 }
1902 return *pHelper;
1903 }
1904
1905 // ---------------------------------------------------------------------------------------------------------------------
1906 // beans::XMultiPropertySet
getPropertySetInfo()1907 uno::Reference< beans::XPropertySetInfo > UnoControlListBoxModel::getPropertySetInfo( )
1908 {
1909 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
1910 return xInfo;
1911 }
1912
1913 // ---------------------------------------------------------------------------------------------------------------------
1914 namespace
1915 {
1916 struct CreateListItem
1917 {
1918 typedef ::rtl::OUString argument_type;
1919 typedef ListItem result_type;
operator ()__anon282e3a350211::CreateListItem1920 ListItem operator()( const ::rtl::OUString& i_rItemText )
1921 {
1922 return ListItem( i_rItemText );
1923 }
1924 };
1925 }
1926
1927 // ---------------------------------------------------------------------------------------------------------------------
setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const uno::Any & rValue)1928 void SAL_CALL UnoControlListBoxModel::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const uno::Any& rValue )
1929 {
1930 UnoControlModel::setFastPropertyValue_NoBroadcast( nHandle, rValue );
1931
1932 if ( nHandle == BASEPROPERTY_STRINGITEMLIST )
1933 {
1934 // reset selection
1935 uno::Sequence<sal_Int16> aSeq;
1936 uno::Any aAny;
1937 aAny <<= aSeq;
1938 setDependentFastPropertyValue( BASEPROPERTY_SELECTEDITEMS, aAny );
1939
1940 if ( !m_pData->m_bSettingLegacyProperty )
1941 {
1942 // synchronize the legacy StringItemList property with our list items
1943 Sequence< ::rtl::OUString > aStringItemList;
1944 Any aPropValue;
1945 getFastPropertyValue( aPropValue, BASEPROPERTY_STRINGITEMLIST );
1946 OSL_VERIFY( aPropValue >>= aStringItemList );
1947
1948 ::std::vector< ListItem > aItems( aStringItemList.getLength() );
1949 ::std::transform(
1950 aStringItemList.getConstArray(),
1951 aStringItemList.getConstArray() + aStringItemList.getLength(),
1952 aItems.begin(),
1953 CreateListItem()
1954 );
1955 m_pData->setAllItems( aItems );
1956
1957 // since an XItemListListener does not have a "all items modified" or some such method,
1958 // we simulate this by notifying removal of all items, followed by insertion of all new
1959 // items
1960 lang::EventObject aEvent;
1961 aEvent.Source = *this;
1962 m_aItemListListeners.notifyEach( &XItemListListener::itemListChanged, aEvent );
1963 // TODO: OPropertySetHelper calls into this method with the mutex locked ...
1964 // which is wrong for the above notifications ...
1965 }
1966 }
1967 }
1968
1969 // ---------------------------------------------------------------------------------------------------------------------
ImplNormalizePropertySequence(const sal_Int32 _nCount,sal_Int32 * _pHandles,uno::Any * _pValues,sal_Int32 * _pValidHandles) const1970 void UnoControlListBoxModel::ImplNormalizePropertySequence( const sal_Int32 _nCount, sal_Int32* _pHandles,
1971 uno::Any* _pValues, sal_Int32* _pValidHandles ) const SAL_THROW(())
1972 {
1973 // dependencies we know:
1974 // BASEPROPERTY_STRINGITEMLIST->BASEPROPERTY_SELECTEDITEMS
1975 ImplEnsureHandleOrder( _nCount, _pHandles, _pValues, BASEPROPERTY_STRINGITEMLIST, BASEPROPERTY_SELECTEDITEMS );
1976
1977 UnoControlModel::ImplNormalizePropertySequence( _nCount, _pHandles, _pValues, _pValidHandles );
1978 }
1979
1980 // ---------------------------------------------------------------------------------------------------------------------
getItemCount()1981 ::sal_Int32 SAL_CALL UnoControlListBoxModel::getItemCount()
1982 {
1983 ::osl::MutexGuard aGuard( GetMutex() );
1984 return m_pData->getItemCount();
1985 }
1986
1987 // ---------------------------------------------------------------------------------------------------------------------
insertItem(::sal_Int32 i_nPosition,const::rtl::OUString & i_rItemText,const::rtl::OUString & i_rItemImageURL)1988 void SAL_CALL UnoControlListBoxModel::insertItem( ::sal_Int32 i_nPosition, const ::rtl::OUString& i_rItemText, const ::rtl::OUString& i_rItemImageURL )
1989 {
1990 ::osl::ClearableMutexGuard aGuard( GetMutex() );
1991 // SYNCHRONIZED ----->
1992 ListItem& rItem( m_pData->insertItem( i_nPosition ) );
1993 rItem.ItemText = i_rItemText;
1994 rItem.ItemImageURL = i_rItemImageURL;
1995
1996 impl_handleInsert( i_nPosition, i_rItemText, i_rItemImageURL, aGuard );
1997 // <----- SYNCHRONIZED
1998 }
1999
2000 // ---------------------------------------------------------------------------------------------------------------------
insertItemText(::sal_Int32 i_nPosition,const::rtl::OUString & i_rItemText)2001 void SAL_CALL UnoControlListBoxModel::insertItemText( ::sal_Int32 i_nPosition, const ::rtl::OUString& i_rItemText )
2002 {
2003 ::osl::ClearableMutexGuard aGuard( GetMutex() );
2004 // SYNCHRONIZED ----->
2005 ListItem& rItem( m_pData->insertItem( i_nPosition ) );
2006 rItem.ItemText = i_rItemText;
2007
2008 impl_handleInsert( i_nPosition, i_rItemText, ::boost::optional< ::rtl::OUString >(), aGuard );
2009 // <----- SYNCHRONIZED
2010 }
2011
2012 // ---------------------------------------------------------------------------------------------------------------------
insertItemImage(::sal_Int32 i_nPosition,const::rtl::OUString & i_rItemImageURL)2013 void SAL_CALL UnoControlListBoxModel::insertItemImage( ::sal_Int32 i_nPosition, const ::rtl::OUString& i_rItemImageURL )
2014 {
2015 ::osl::ClearableMutexGuard aGuard( GetMutex() );
2016 // SYNCHRONIZED ----->
2017 ListItem& rItem( m_pData->insertItem( i_nPosition ) );
2018 rItem.ItemImageURL = i_rItemImageURL;
2019
2020 impl_handleInsert( i_nPosition, ::boost::optional< ::rtl::OUString >(), i_rItemImageURL, aGuard );
2021 // <----- SYNCHRONIZED
2022 }
2023
2024 // ---------------------------------------------------------------------------------------------------------------------
removeItem(::sal_Int32 i_nPosition)2025 void SAL_CALL UnoControlListBoxModel::removeItem( ::sal_Int32 i_nPosition )
2026 {
2027 ::osl::ClearableMutexGuard aGuard( GetMutex() );
2028 // SYNCHRONIZED ----->
2029 m_pData->removeItem( i_nPosition );
2030
2031 impl_handleRemove( i_nPosition, aGuard );
2032 // <----- SYNCHRONIZED
2033 }
2034
2035 // ---------------------------------------------------------------------------------------------------------------------
removeAllItems()2036 void SAL_CALL UnoControlListBoxModel::removeAllItems( )
2037 {
2038 ::osl::ClearableMutexGuard aGuard( GetMutex() );
2039 // SYNCHRONIZED ----->
2040 m_pData->removeAllItems();
2041
2042 impl_handleRemove( -1, aGuard );
2043 // <----- SYNCHRONIZED
2044 }
2045
2046 // ---------------------------------------------------------------------------------------------------------------------
setItemText(::sal_Int32 i_nPosition,const::rtl::OUString & i_rItemText)2047 void SAL_CALL UnoControlListBoxModel::setItemText( ::sal_Int32 i_nPosition, const ::rtl::OUString& i_rItemText )
2048 {
2049 ::osl::ClearableMutexGuard aGuard( GetMutex() );
2050 // SYNCHRONIZED ----->
2051 ListItem& rItem( m_pData->getItem( i_nPosition ) );
2052 rItem.ItemText = i_rItemText;
2053
2054 impl_handleModify( i_nPosition, i_rItemText, ::boost::optional< ::rtl::OUString >(), aGuard );
2055 // <----- SYNCHRONIZED
2056 }
2057
2058 // ---------------------------------------------------------------------------------------------------------------------
setItemImage(::sal_Int32 i_nPosition,const::rtl::OUString & i_rItemImageURL)2059 void SAL_CALL UnoControlListBoxModel::setItemImage( ::sal_Int32 i_nPosition, const ::rtl::OUString& i_rItemImageURL )
2060 {
2061 ::osl::ClearableMutexGuard aGuard( GetMutex() );
2062 // SYNCHRONIZED ----->
2063 ListItem& rItem( m_pData->getItem( i_nPosition ) );
2064 rItem.ItemImageURL = i_rItemImageURL;
2065
2066 impl_handleModify( i_nPosition, ::boost::optional< ::rtl::OUString >(), i_rItemImageURL, aGuard );
2067 // <----- SYNCHRONIZED
2068 }
2069
2070 // ---------------------------------------------------------------------------------------------------------------------
setItemTextAndImage(::sal_Int32 i_nPosition,const::rtl::OUString & i_rItemText,const::rtl::OUString & i_rItemImageURL)2071 void SAL_CALL UnoControlListBoxModel::setItemTextAndImage( ::sal_Int32 i_nPosition, const ::rtl::OUString& i_rItemText, const ::rtl::OUString& i_rItemImageURL )
2072 {
2073 ::osl::ClearableMutexGuard aGuard( GetMutex() );
2074 // SYNCHRONIZED ----->
2075 ListItem& rItem( m_pData->getItem( i_nPosition ) );
2076 rItem.ItemText = i_rItemText;
2077 rItem.ItemImageURL = i_rItemImageURL;
2078
2079 impl_handleModify( i_nPosition, i_rItemText, i_rItemImageURL, aGuard );
2080 // <----- SYNCHRONIZED
2081 }
2082
2083 // ---------------------------------------------------------------------------------------------------------------------
setItemData(::sal_Int32 i_nPosition,const Any & i_rDataValue)2084 void SAL_CALL UnoControlListBoxModel::setItemData( ::sal_Int32 i_nPosition, const Any& i_rDataValue )
2085 {
2086 ::osl::ClearableMutexGuard aGuard( GetMutex() );
2087 ListItem& rItem( m_pData->getItem( i_nPosition ) );
2088 rItem.ItemData = i_rDataValue;
2089 }
2090
2091 // ---------------------------------------------------------------------------------------------------------------------
getItemText(::sal_Int32 i_nPosition)2092 ::rtl::OUString SAL_CALL UnoControlListBoxModel::getItemText( ::sal_Int32 i_nPosition )
2093 {
2094 ::osl::MutexGuard aGuard( GetMutex() );
2095 const ListItem& rItem( m_pData->getItem( i_nPosition ) );
2096 return rItem.ItemText;
2097 }
2098
2099 // ---------------------------------------------------------------------------------------------------------------------
getItemImage(::sal_Int32 i_nPosition)2100 ::rtl::OUString SAL_CALL UnoControlListBoxModel::getItemImage( ::sal_Int32 i_nPosition )
2101 {
2102 ::osl::MutexGuard aGuard( GetMutex() );
2103 const ListItem& rItem( m_pData->getItem( i_nPosition ) );
2104 return rItem.ItemImageURL;
2105 }
2106
2107 // ---------------------------------------------------------------------------------------------------------------------
getItemTextAndImage(::sal_Int32 i_nPosition)2108 beans::Pair< ::rtl::OUString, ::rtl::OUString > SAL_CALL UnoControlListBoxModel::getItemTextAndImage( ::sal_Int32 i_nPosition )
2109 {
2110 ::osl::MutexGuard aGuard( GetMutex() );
2111 const ListItem& rItem( m_pData->getItem( i_nPosition ) );
2112 return beans::Pair< ::rtl::OUString, ::rtl::OUString >( rItem.ItemText, rItem.ItemImageURL );
2113 }
2114
2115 // ---------------------------------------------------------------------------------------------------------------------
getItemData(::sal_Int32 i_nPosition)2116 Any SAL_CALL UnoControlListBoxModel::getItemData( ::sal_Int32 i_nPosition )
2117 {
2118 ::osl::ClearableMutexGuard aGuard( GetMutex() );
2119 const ListItem& rItem( m_pData->getItem( i_nPosition ) );
2120 return rItem.ItemData;
2121 }
2122
2123 // ---------------------------------------------------------------------------------------------------------------------
getAllItems()2124 Sequence< beans::Pair< ::rtl::OUString, ::rtl::OUString > > SAL_CALL UnoControlListBoxModel::getAllItems( )
2125 {
2126 ::osl::MutexGuard aGuard( GetMutex() );
2127 return m_pData->getAllItems();
2128 }
2129
2130 // ---------------------------------------------------------------------------------------------------------------------
addItemListListener(const uno::Reference<awt::XItemListListener> & i_Listener)2131 void SAL_CALL UnoControlListBoxModel::addItemListListener( const uno::Reference< awt::XItemListListener >& i_Listener )
2132 {
2133 if ( i_Listener.is() )
2134 m_aItemListListeners.addInterface( i_Listener );
2135 }
2136
2137 // ---------------------------------------------------------------------------------------------------------------------
removeItemListListener(const uno::Reference<awt::XItemListListener> & i_Listener)2138 void SAL_CALL UnoControlListBoxModel::removeItemListListener( const uno::Reference< awt::XItemListListener >& i_Listener )
2139 {
2140 if ( i_Listener.is() )
2141 m_aItemListListeners.removeInterface( i_Listener );
2142 }
2143
2144 // ---------------------------------------------------------------------------------------------------------------------
impl_getStringItemList(::std::vector<::rtl::OUString> & o_rStringItems) const2145 void UnoControlListBoxModel::impl_getStringItemList( ::std::vector< ::rtl::OUString >& o_rStringItems ) const
2146 {
2147 Sequence< ::rtl::OUString > aStringItemList;
2148 Any aPropValue;
2149 getFastPropertyValue( aPropValue, BASEPROPERTY_STRINGITEMLIST );
2150 OSL_VERIFY( aPropValue >>= aStringItemList );
2151
2152 o_rStringItems.resize( size_t( aStringItemList.getLength() ) );
2153 ::std::copy(
2154 aStringItemList.getConstArray(),
2155 aStringItemList.getConstArray() + aStringItemList.getLength(),
2156 o_rStringItems.begin()
2157 );
2158 }
2159
2160 // ---------------------------------------------------------------------------------------------------------------------
impl_setStringItemList_nolck(const::std::vector<::rtl::OUString> & i_rStringItems)2161 void UnoControlListBoxModel::impl_setStringItemList_nolck( const ::std::vector< ::rtl::OUString >& i_rStringItems )
2162 {
2163 Sequence< ::rtl::OUString > aStringItems( i_rStringItems.size() );
2164 ::std::copy(
2165 i_rStringItems.begin(),
2166 i_rStringItems.end(),
2167 aStringItems.getArray()
2168 );
2169 m_pData->m_bSettingLegacyProperty = true;
2170 try
2171 {
2172 setFastPropertyValue( BASEPROPERTY_STRINGITEMLIST, uno::makeAny( aStringItems ) );
2173 }
2174 catch( const Exception& )
2175 {
2176 m_pData->m_bSettingLegacyProperty = false;
2177 throw;
2178 }
2179 m_pData->m_bSettingLegacyProperty = false;
2180 }
2181
2182 // ---------------------------------------------------------------------------------------------------------------------
impl_handleInsert(const sal_Int32 i_nItemPosition,const::boost::optional<::rtl::OUString> & i_rItemText,const::boost::optional<::rtl::OUString> & i_rItemImageURL,::osl::ClearableMutexGuard & i_rClearBeforeNotify)2183 void UnoControlListBoxModel::impl_handleInsert( const sal_Int32 i_nItemPosition, const ::boost::optional< ::rtl::OUString >& i_rItemText,
2184 const ::boost::optional< ::rtl::OUString >& i_rItemImageURL, ::osl::ClearableMutexGuard& i_rClearBeforeNotify )
2185 {
2186 // SYNCHRONIZED ----->
2187 // sync with legacy StringItemList property
2188 ::std::vector< ::rtl::OUString > aStringItems;
2189 impl_getStringItemList( aStringItems );
2190 OSL_ENSURE( size_t( i_nItemPosition ) <= aStringItems.size(), "UnoControlListBoxModel::impl_handleInsert" );
2191 if ( size_t( i_nItemPosition ) <= aStringItems.size() )
2192 {
2193 const ::rtl::OUString sItemText( !!i_rItemText ? *i_rItemText : ::rtl::OUString() );
2194 aStringItems.insert( aStringItems.begin() + i_nItemPosition, sItemText );
2195 }
2196
2197 i_rClearBeforeNotify.clear();
2198 // <----- SYNCHRONIZED
2199 impl_setStringItemList_nolck( aStringItems );
2200
2201 // notify ItemListListeners
2202 impl_notifyItemListEvent_nolck( i_nItemPosition, i_rItemText, i_rItemImageURL, &XItemListListener::listItemInserted );
2203 }
2204
2205 // ---------------------------------------------------------------------------------------------------------------------
impl_handleRemove(const sal_Int32 i_nItemPosition,::osl::ClearableMutexGuard & i_rClearBeforeNotify)2206 void UnoControlListBoxModel::impl_handleRemove( const sal_Int32 i_nItemPosition, ::osl::ClearableMutexGuard& i_rClearBeforeNotify )
2207 {
2208 // SYNCHRONIZED ----->
2209 const bool bAllItems = ( i_nItemPosition < 0 );
2210 // sync with legacy StringItemList property
2211 ::std::vector< ::rtl::OUString > aStringItems;
2212 impl_getStringItemList( aStringItems );
2213 if ( !bAllItems )
2214 {
2215 OSL_ENSURE( size_t( i_nItemPosition ) < aStringItems.size(), "UnoControlListBoxModel::impl_handleRemove" );
2216 if ( size_t( i_nItemPosition ) < aStringItems.size() )
2217 {
2218 aStringItems.erase( aStringItems.begin() + i_nItemPosition );
2219 }
2220 }
2221 else
2222 {
2223 aStringItems.resize(0);
2224 }
2225
2226 i_rClearBeforeNotify.clear();
2227 // <----- SYNCHRONIZED
2228 impl_setStringItemList_nolck( aStringItems );
2229
2230 // notify ItemListListeners
2231 if ( bAllItems )
2232 {
2233 EventObject aEvent( *this );
2234 m_aItemListListeners.notifyEach( &XItemListListener::allItemsRemoved, aEvent );
2235 }
2236 else
2237 {
2238 impl_notifyItemListEvent_nolck( i_nItemPosition, ::boost::optional< ::rtl::OUString >(), ::boost::optional< ::rtl::OUString >(),
2239 &XItemListListener::listItemRemoved );
2240 }
2241 }
2242
2243 // ---------------------------------------------------------------------------------------------------------------------
impl_handleModify(const sal_Int32 i_nItemPosition,const::boost::optional<::rtl::OUString> & i_rItemText,const::boost::optional<::rtl::OUString> & i_rItemImageURL,::osl::ClearableMutexGuard & i_rClearBeforeNotify)2244 void UnoControlListBoxModel::impl_handleModify( const sal_Int32 i_nItemPosition, const ::boost::optional< ::rtl::OUString >& i_rItemText,
2245 const ::boost::optional< ::rtl::OUString >& i_rItemImageURL, ::osl::ClearableMutexGuard& i_rClearBeforeNotify )
2246 {
2247 // SYNCHRONIZED ----->
2248 if ( !!i_rItemText )
2249 {
2250 // sync with legacy StringItemList property
2251 ::std::vector< ::rtl::OUString > aStringItems;
2252 impl_getStringItemList( aStringItems );
2253 OSL_ENSURE( size_t( i_nItemPosition ) < aStringItems.size(), "UnoControlListBoxModel::impl_handleModify" );
2254 if ( size_t( i_nItemPosition ) < aStringItems.size() )
2255 {
2256 aStringItems[ i_nItemPosition] = *i_rItemText;
2257 }
2258
2259 i_rClearBeforeNotify.clear();
2260 // <----- SYNCHRONIZED
2261 impl_setStringItemList_nolck( aStringItems );
2262 }
2263 else
2264 {
2265 i_rClearBeforeNotify.clear();
2266 // <----- SYNCHRONIZED
2267 }
2268
2269 // notify ItemListListeners
2270 impl_notifyItemListEvent_nolck( i_nItemPosition, i_rItemText, i_rItemImageURL, &XItemListListener::listItemModified );
2271 }
2272
2273 // ---------------------------------------------------------------------------------------------------------------------
impl_notifyItemListEvent_nolck(const sal_Int32 i_nItemPosition,const::boost::optional<::rtl::OUString> & i_rItemText,const::boost::optional<::rtl::OUString> & i_rItemImageURL,void (SAL_CALL XItemListListener::* NotificationMethod)(const ItemListEvent &))2274 void UnoControlListBoxModel::impl_notifyItemListEvent_nolck( const sal_Int32 i_nItemPosition, const ::boost::optional< ::rtl::OUString >& i_rItemText,
2275 const ::boost::optional< ::rtl::OUString >& i_rItemImageURL,
2276 void ( SAL_CALL XItemListListener::*NotificationMethod )( const ItemListEvent& ) )
2277 {
2278 ItemListEvent aEvent;
2279 aEvent.Source = *this;
2280 aEvent.ItemPosition = i_nItemPosition;
2281 if ( !!i_rItemText )
2282 {
2283 aEvent.ItemText.IsPresent = sal_True;
2284 aEvent.ItemText.Value = *i_rItemText;
2285 }
2286 if ( !!i_rItemImageURL )
2287 {
2288 aEvent.ItemImageURL.IsPresent = sal_True;
2289 aEvent.ItemImageURL.Value = *i_rItemImageURL;
2290 }
2291
2292 m_aItemListListeners.notifyEach( NotificationMethod, aEvent );
2293 }
2294
2295 // ----------------------------------------------------
2296 // class UnoListBoxControl
2297 // ----------------------------------------------------
UnoListBoxControl(const Reference<XMultiServiceFactory> & i_factory)2298 UnoListBoxControl::UnoListBoxControl( const Reference< XMultiServiceFactory >& i_factory )
2299 :UnoListBoxControl_Base( i_factory )
2300 ,maActionListeners( *this )
2301 ,maItemListeners( *this )
2302 {
2303 maComponentInfos.nWidth = 100;
2304 maComponentInfos.nHeight = 12;
2305 }
2306
GetComponentServiceName()2307 ::rtl::OUString UnoListBoxControl::GetComponentServiceName()
2308 {
2309 return ::rtl::OUString::createFromAscii( "listbox" );
2310 }
IMPL_SERVICEINFO_DERIVED(UnoListBoxControl,UnoControlBase,szServiceName2_UnoControlListBox)2311 IMPL_SERVICEINFO_DERIVED( UnoListBoxControl, UnoControlBase, szServiceName2_UnoControlListBox )
2312
2313 void UnoListBoxControl::dispose()
2314 {
2315 lang::EventObject aEvt;
2316 aEvt.Source = (::cppu::OWeakObject*)this;
2317 maActionListeners.disposeAndClear( aEvt );
2318 maItemListeners.disposeAndClear( aEvt );
2319 UnoControl::dispose();
2320 }
2321
ImplUpdateSelectedItemsProperty()2322 void UnoListBoxControl::ImplUpdateSelectedItemsProperty()
2323 {
2324 if ( getPeer().is() )
2325 {
2326 uno::Reference < awt::XListBox > xListBox( getPeer(), uno::UNO_QUERY );
2327 DBG_ASSERT( xListBox.is(), "XListBox?" );
2328
2329 uno::Sequence<sal_Int16> aSeq = xListBox->getSelectedItemsPos();
2330 uno::Any aAny;
2331 aAny <<= aSeq;
2332 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SELECTEDITEMS ), aAny, sal_False );
2333 }
2334 }
2335
updateFromModel()2336 void UnoListBoxControl::updateFromModel()
2337 {
2338 UnoControlBase::updateFromModel();
2339
2340 Reference< XItemListListener > xItemListListener( getPeer(), UNO_QUERY );
2341 ENSURE_OR_RETURN_VOID( xItemListListener.is(), "UnoListBoxControl::updateFromModel: a peer which is no ItemListListener?!" );
2342
2343 EventObject aEvent( getModel() );
2344 xItemListListener->itemListChanged( aEvent );
2345
2346 // notify the change of the SelectedItems property, again. While our base class, in updateFromModel,
2347 // already did this, our peer(s) can only legitimately set the selection after they have the string
2348 // item list, which we just notified with the itemListChanged call.
2349 const ::rtl::OUString sSelectedItemsPropName( GetPropertyName( BASEPROPERTY_SELECTEDITEMS ) );
2350 ImplSetPeerProperty( sSelectedItemsPropName, ImplGetPropertyValue( sSelectedItemsPropName ) );
2351 }
2352
ImplSetPeerProperty(const::rtl::OUString & rPropName,const uno::Any & rVal)2353 void UnoListBoxControl::ImplSetPeerProperty( const ::rtl::OUString& rPropName, const uno::Any& rVal )
2354 {
2355 if ( rPropName == GetPropertyName( BASEPROPERTY_STRINGITEMLIST ) )
2356 // do not forward this to our peer. We are a XItemListListener at our model, and changes in the string item
2357 // list (which is a legacy property) will, later, arrive as changes in the ItemList. Those latter changes
2358 // will be forwarded to the peer, which will update itself accordingly.
2359 return;
2360
2361 UnoControl::ImplSetPeerProperty( rPropName, rVal );
2362 }
2363
createPeer(const uno::Reference<awt::XToolkit> & rxToolkit,const uno::Reference<awt::XWindowPeer> & rParentPeer)2364 void UnoListBoxControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer )
2365 {
2366 UnoControl::createPeer( rxToolkit, rParentPeer );
2367
2368 uno::Reference < awt::XListBox > xListBox( getPeer(), uno::UNO_QUERY );
2369 xListBox->addItemListener( this );
2370
2371 if ( maActionListeners.getLength() )
2372 xListBox->addActionListener( &maActionListeners );
2373 }
2374
addActionListener(const uno::Reference<awt::XActionListener> & l)2375 void UnoListBoxControl::addActionListener(const uno::Reference< awt::XActionListener > & l)
2376 {
2377 maActionListeners.addInterface( l );
2378 if( getPeer().is() && maActionListeners.getLength() == 1 )
2379 {
2380 uno::Reference < awt::XListBox > xListBox( getPeer(), uno::UNO_QUERY );
2381 xListBox->addActionListener( &maActionListeners );
2382 }
2383 }
2384
removeActionListener(const uno::Reference<awt::XActionListener> & l)2385 void UnoListBoxControl::removeActionListener(const uno::Reference< awt::XActionListener > & l)
2386 {
2387 if( getPeer().is() && maActionListeners.getLength() == 1 )
2388 {
2389 uno::Reference < awt::XListBox > xListBox( getPeer(), uno::UNO_QUERY );
2390 xListBox->removeActionListener( &maActionListeners );
2391 }
2392 maActionListeners.removeInterface( l );
2393 }
2394
addItemListener(const uno::Reference<awt::XItemListener> & l)2395 void UnoListBoxControl::addItemListener(const uno::Reference < awt::XItemListener > & l)
2396 {
2397 maItemListeners.addInterface( l );
2398 }
2399
removeItemListener(const uno::Reference<awt::XItemListener> & l)2400 void UnoListBoxControl::removeItemListener(const uno::Reference < awt::XItemListener > & l)
2401 {
2402 maItemListeners.removeInterface( l );
2403 }
2404
addItem(const::rtl::OUString & aItem,sal_Int16 nPos)2405 void UnoListBoxControl::addItem( const ::rtl::OUString& aItem, sal_Int16 nPos )
2406 {
2407 uno::Sequence< ::rtl::OUString> aSeq( 1 );
2408 aSeq.getArray()[0] = aItem;
2409 addItems( aSeq, nPos );
2410 }
2411
addItems(const uno::Sequence<::rtl::OUString> & aItems,sal_Int16 nPos)2412 void UnoListBoxControl::addItems( const uno::Sequence< ::rtl::OUString>& aItems, sal_Int16 nPos )
2413 {
2414 uno::Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_STRINGITEMLIST ) );
2415 uno::Sequence< ::rtl::OUString> aSeq;
2416 aVal >>= aSeq;
2417 sal_uInt16 nNewItems = (sal_uInt16)aItems.getLength();
2418 sal_uInt16 nOldLen = (sal_uInt16)aSeq.getLength();
2419 sal_uInt16 nNewLen = nOldLen + nNewItems;
2420
2421 uno::Sequence< ::rtl::OUString> aNewSeq( nNewLen );
2422 ::rtl::OUString* pNewData = aNewSeq.getArray();
2423 ::rtl::OUString* pOldData = aSeq.getArray();
2424
2425 if ( ( nPos < 0 ) || ( nPos > nOldLen ) )
2426 nPos = (sal_uInt16) nOldLen;
2427
2428 sal_uInt16 n;
2429 // Items vor der Einfuege-Position
2430 for ( n = 0; n < nPos; n++ )
2431 pNewData[n] = pOldData[n];
2432
2433 // Neue Items
2434 for ( n = 0; n < nNewItems; n++ )
2435 pNewData[nPos+n] = aItems.getConstArray()[n];
2436
2437 // Rest der alten Items
2438 for ( n = nPos; n < nOldLen; n++ )
2439 pNewData[nNewItems+n] = pOldData[n];
2440
2441 uno::Any aAny;
2442 aAny <<= aNewSeq;
2443 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_STRINGITEMLIST ), aAny, sal_True );
2444 }
2445
removeItems(sal_Int16 nPos,sal_Int16 nCount)2446 void UnoListBoxControl::removeItems( sal_Int16 nPos, sal_Int16 nCount )
2447 {
2448 uno::Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_STRINGITEMLIST ) );
2449 uno::Sequence< ::rtl::OUString> aSeq;
2450 aVal >>= aSeq;
2451 sal_uInt16 nOldLen = (sal_uInt16)aSeq.getLength();
2452 if ( nOldLen && ( nPos < nOldLen ) )
2453 {
2454 if ( nCount > ( nOldLen-nPos ) )
2455 nCount = nOldLen-nPos;
2456
2457 sal_uInt16 nNewLen = nOldLen - nCount;
2458
2459 uno::Sequence< ::rtl::OUString> aNewSeq( nNewLen );
2460 ::rtl::OUString* pNewData = aNewSeq.getArray();
2461 ::rtl::OUString* pOldData = aSeq.getArray();
2462
2463 sal_uInt16 n;
2464 // Items vor der Entfern-Position
2465 for ( n = 0; n < nPos; n++ )
2466 pNewData[n] = pOldData[n];
2467
2468 // Rest der Items
2469 for ( n = nPos; n < (nOldLen-nCount); n++ )
2470 pNewData[n] = pOldData[n+nCount];
2471
2472 uno::Any aAny;
2473 aAny <<= aNewSeq;
2474 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_STRINGITEMLIST ), aAny, sal_True );
2475 }
2476 }
2477
getItemCount()2478 sal_Int16 UnoListBoxControl::getItemCount()
2479 {
2480 uno::Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_STRINGITEMLIST ) );
2481 uno::Sequence< ::rtl::OUString> aSeq;
2482 aVal >>= aSeq;
2483 return (sal_Int16)aSeq.getLength();
2484 }
2485
getItem(sal_Int16 nPos)2486 ::rtl::OUString UnoListBoxControl::getItem( sal_Int16 nPos )
2487 {
2488 ::rtl::OUString aItem;
2489 uno::Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_STRINGITEMLIST ) );
2490 uno::Sequence< ::rtl::OUString> aSeq;
2491 aVal >>= aSeq;
2492 if ( nPos < aSeq.getLength() )
2493 aItem = aSeq.getConstArray()[nPos];
2494 return aItem;
2495 }
2496
getItems()2497 uno::Sequence< ::rtl::OUString> UnoListBoxControl::getItems()
2498 {
2499 uno::Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_STRINGITEMLIST ) );
2500 uno::Sequence< ::rtl::OUString> aSeq;
2501 aVal >>= aSeq;
2502 return aSeq;
2503 }
2504
getSelectedItemPos()2505 sal_Int16 UnoListBoxControl::getSelectedItemPos()
2506 {
2507 sal_Int16 n = -1;
2508 if ( getPeer().is() )
2509 {
2510 uno::Reference < awt::XListBox > xListBox( getPeer(), uno::UNO_QUERY );
2511 n = xListBox->getSelectedItemPos();
2512 }
2513 return n;
2514 }
2515
getSelectedItemsPos()2516 uno::Sequence<sal_Int16> UnoListBoxControl::getSelectedItemsPos()
2517 {
2518 uno::Sequence<sal_Int16> aSeq;
2519 if ( getPeer().is() )
2520 {
2521 uno::Reference < awt::XListBox > xListBox( getPeer(), uno::UNO_QUERY );
2522 aSeq = xListBox->getSelectedItemsPos();
2523 }
2524 return aSeq;
2525 }
2526
getSelectedItem()2527 ::rtl::OUString UnoListBoxControl::getSelectedItem()
2528 {
2529 ::rtl::OUString aItem;
2530 if ( getPeer().is() )
2531 {
2532 uno::Reference < awt::XListBox > xListBox( getPeer(), uno::UNO_QUERY );
2533 aItem = xListBox->getSelectedItem();
2534 }
2535 return aItem;
2536 }
2537
getSelectedItems()2538 uno::Sequence< ::rtl::OUString> UnoListBoxControl::getSelectedItems()
2539 {
2540 uno::Sequence< ::rtl::OUString> aSeq;
2541 if ( getPeer().is() )
2542 {
2543 uno::Reference < awt::XListBox > xListBox( getPeer(), uno::UNO_QUERY );
2544 aSeq = xListBox->getSelectedItems();
2545 }
2546 return aSeq;
2547 }
2548
selectItemPos(sal_Int16 nPos,sal_Bool bSelect)2549 void UnoListBoxControl::selectItemPos( sal_Int16 nPos, sal_Bool bSelect )
2550 {
2551 if ( getPeer().is() )
2552 {
2553 uno::Reference < awt::XListBox > xListBox( getPeer(), uno::UNO_QUERY );
2554 xListBox->selectItemPos( nPos, bSelect );
2555 }
2556 ImplUpdateSelectedItemsProperty();
2557 }
2558
selectItemsPos(const uno::Sequence<sal_Int16> & aPositions,sal_Bool bSelect)2559 void UnoListBoxControl::selectItemsPos( const uno::Sequence<sal_Int16>& aPositions, sal_Bool bSelect )
2560 {
2561 if ( getPeer().is() )
2562 {
2563 uno::Reference < awt::XListBox > xListBox( getPeer(), uno::UNO_QUERY );
2564 xListBox->selectItemsPos( aPositions, bSelect );
2565 }
2566 ImplUpdateSelectedItemsProperty();
2567 }
2568
selectItem(const::rtl::OUString & aItem,sal_Bool bSelect)2569 void UnoListBoxControl::selectItem( const ::rtl::OUString& aItem, sal_Bool bSelect )
2570 {
2571 if ( getPeer().is() )
2572 {
2573 uno::Reference < awt::XListBox > xListBox( getPeer(), uno::UNO_QUERY );
2574 xListBox->selectItem( aItem, bSelect );
2575 }
2576 ImplUpdateSelectedItemsProperty();
2577 }
2578
makeVisible(sal_Int16 nEntry)2579 void UnoListBoxControl::makeVisible( sal_Int16 nEntry )
2580 {
2581 if ( getPeer().is() )
2582 {
2583 uno::Reference < awt::XListBox > xListBox( getPeer(), uno::UNO_QUERY );
2584 xListBox->makeVisible( nEntry );
2585 }
2586 }
2587
setDropDownLineCount(sal_Int16 nLines)2588 void UnoListBoxControl::setDropDownLineCount( sal_Int16 nLines )
2589 {
2590 uno::Any aAny;
2591 aAny <<= (sal_Int16)nLines;
2592 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_LINECOUNT ), aAny, sal_True );
2593 }
2594
getDropDownLineCount()2595 sal_Int16 UnoListBoxControl::getDropDownLineCount()
2596 {
2597 return ImplGetPropertyValue_INT16( BASEPROPERTY_LINECOUNT );
2598 }
2599
isMutipleMode()2600 sal_Bool UnoListBoxControl::isMutipleMode()
2601 {
2602 return ImplGetPropertyValue_BOOL( BASEPROPERTY_MULTISELECTION );
2603 }
2604
setMultipleMode(sal_Bool bMulti)2605 void UnoListBoxControl::setMultipleMode( sal_Bool bMulti )
2606 {
2607 uno::Any aAny;
2608 aAny <<= bMulti;
2609 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_MULTISELECTION ), aAny, sal_True );
2610 }
2611
itemStateChanged(const awt::ItemEvent & rEvent)2612 void UnoListBoxControl::itemStateChanged( const awt::ItemEvent& rEvent )
2613 {
2614 ImplUpdateSelectedItemsProperty();
2615 if ( maItemListeners.getLength() )
2616 {
2617 try
2618 {
2619 maItemListeners.itemStateChanged( rEvent );
2620 }
2621 catch( const Exception& e )
2622 {
2623 #if OSL_DEBUG_LEVEL == 0
2624 (void) e; // suppress warning
2625 #else
2626 ::rtl::OString sMessage( "UnoListBoxControl::itemStateChanged: caught an exception:\n" );
2627 sMessage += ::rtl::OString( e.Message.getStr(), e.Message.getLength(), RTL_TEXTENCODING_ASCII_US );
2628 OSL_ENSURE( sal_False, sMessage.getStr() );
2629 #endif
2630 }
2631 }
2632 }
2633
getMinimumSize()2634 awt::Size UnoListBoxControl::getMinimumSize( )
2635 {
2636 return Impl_getMinimumSize();
2637 }
2638
getPreferredSize()2639 awt::Size UnoListBoxControl::getPreferredSize( )
2640 {
2641 return Impl_getPreferredSize();
2642 }
2643
calcAdjustedSize(const awt::Size & rNewSize)2644 awt::Size UnoListBoxControl::calcAdjustedSize( const awt::Size& rNewSize )
2645 {
2646 return Impl_calcAdjustedSize( rNewSize );
2647 }
2648
getMinimumSize(sal_Int16 nCols,sal_Int16 nLines)2649 awt::Size UnoListBoxControl::getMinimumSize( sal_Int16 nCols, sal_Int16 nLines )
2650 {
2651 return Impl_getMinimumSize( nCols, nLines );
2652 }
2653
getColumnsAndLines(sal_Int16 & nCols,sal_Int16 & nLines)2654 void UnoListBoxControl::getColumnsAndLines( sal_Int16& nCols, sal_Int16& nLines )
2655 {
2656 Impl_getColumnsAndLines( nCols, nLines );
2657 }
2658
setModel(const uno::Reference<awt::XControlModel> & i_rModel)2659 sal_Bool SAL_CALL UnoListBoxControl::setModel( const uno::Reference< awt::XControlModel >& i_rModel )
2660 {
2661 ::osl::MutexGuard aGuard( GetMutex() );
2662
2663 const Reference< XItemList > xOldItems( getModel(), UNO_QUERY );
2664 OSL_ENSURE( xOldItems.is() || !getModel().is(), "UnoListBoxControl::setModel: illegal old model!" );
2665 const Reference< XItemList > xNewItems( i_rModel, UNO_QUERY );
2666 OSL_ENSURE( xNewItems.is() || !i_rModel.is(), "UnoListBoxControl::setModel: illegal new model!" );
2667
2668 if ( !UnoListBoxControl_Base::setModel( i_rModel ) )
2669 return sal_False;
2670
2671 if ( xOldItems.is() )
2672 xOldItems->removeItemListListener( this );
2673 if ( xNewItems.is() )
2674 xNewItems->addItemListListener( this );
2675
2676 return sal_True;
2677 }
2678
listItemInserted(const awt::ItemListEvent & i_rEvent)2679 void SAL_CALL UnoListBoxControl::listItemInserted( const awt::ItemListEvent& i_rEvent )
2680 {
2681 const Reference< XItemListListener > xPeerListener( getPeer(), UNO_QUERY );
2682 OSL_ENSURE( xPeerListener.is() || !getPeer().is(), "UnoListBoxControl::listItemInserted: invalid peer!" );
2683 if ( xPeerListener.is() )
2684 xPeerListener->listItemInserted( i_rEvent );
2685 }
2686
listItemRemoved(const awt::ItemListEvent & i_rEvent)2687 void SAL_CALL UnoListBoxControl::listItemRemoved( const awt::ItemListEvent& i_rEvent )
2688 {
2689 const Reference< XItemListListener > xPeerListener( getPeer(), UNO_QUERY );
2690 OSL_ENSURE( xPeerListener.is() || !getPeer().is(), "UnoListBoxControl::listItemRemoved: invalid peer!" );
2691 if ( xPeerListener.is() )
2692 xPeerListener->listItemRemoved( i_rEvent );
2693 }
2694
listItemModified(const awt::ItemListEvent & i_rEvent)2695 void SAL_CALL UnoListBoxControl::listItemModified( const awt::ItemListEvent& i_rEvent )
2696 {
2697 const Reference< XItemListListener > xPeerListener( getPeer(), UNO_QUERY );
2698 OSL_ENSURE( xPeerListener.is() || !getPeer().is(), "UnoListBoxControl::listItemModified: invalid peer!" );
2699 if ( xPeerListener.is() )
2700 xPeerListener->listItemModified( i_rEvent );
2701 }
2702
allItemsRemoved(const lang::EventObject & i_rEvent)2703 void SAL_CALL UnoListBoxControl::allItemsRemoved( const lang::EventObject& i_rEvent )
2704 {
2705 const Reference< XItemListListener > xPeerListener( getPeer(), UNO_QUERY );
2706 OSL_ENSURE( xPeerListener.is() || !getPeer().is(), "UnoListBoxControl::allItemsRemoved: invalid peer!" );
2707 if ( xPeerListener.is() )
2708 xPeerListener->allItemsRemoved( i_rEvent );
2709 }
2710
itemListChanged(const lang::EventObject & i_rEvent)2711 void SAL_CALL UnoListBoxControl::itemListChanged( const lang::EventObject& i_rEvent )
2712 {
2713 const Reference< XItemListListener > xPeerListener( getPeer(), UNO_QUERY );
2714 OSL_ENSURE( xPeerListener.is() || !getPeer().is(), "UnoListBoxControl::itemListChanged: invalid peer!" );
2715 if ( xPeerListener.is() )
2716 xPeerListener->itemListChanged( i_rEvent );
2717 }
getActionListeners()2718 ActionListenerMultiplexer& UnoListBoxControl::getActionListeners()
2719 {
2720 return maActionListeners;
2721 }
getItemListeners()2722 ItemListenerMultiplexer& UnoListBoxControl::getItemListeners()
2723 {
2724 return maItemListeners;
2725 }
2726 // ----------------------------------------------------
2727 // class UnoControlComboBoxModel
2728 // ----------------------------------------------------
UnoControlComboBoxModel(const Reference<XMultiServiceFactory> & i_factory)2729 UnoControlComboBoxModel::UnoControlComboBoxModel( const Reference< XMultiServiceFactory >& i_factory )
2730 :UnoControlListBoxModel( i_factory, ConstructWithoutProperties )
2731 {
2732 UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXComboBox );
2733 }
2734
IMPL_SERVICEINFO_DERIVED(UnoControlComboBoxModel,UnoControlModel,szServiceName2_UnoControlComboBoxModel)2735 IMPL_SERVICEINFO_DERIVED( UnoControlComboBoxModel, UnoControlModel, szServiceName2_UnoControlComboBoxModel )
2736
2737 uno::Reference< beans::XPropertySetInfo > UnoControlComboBoxModel::getPropertySetInfo( )
2738 {
2739 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
2740 return xInfo;
2741 }
2742 // ---------------------------------------------------------------------------------------------------------------------
getInfoHelper()2743 ::cppu::IPropertyArrayHelper& UnoControlComboBoxModel::getInfoHelper()
2744 {
2745 static UnoPropertyArrayHelper* pHelper = NULL;
2746 if ( !pHelper )
2747 {
2748 uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
2749 pHelper = new UnoPropertyArrayHelper( aIDs );
2750 }
2751 return *pHelper;
2752 }
2753
2754
getServiceName()2755 ::rtl::OUString UnoControlComboBoxModel::getServiceName()
2756 {
2757 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlComboBoxModel );
2758 }
setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const uno::Any & rValue)2759 void SAL_CALL UnoControlComboBoxModel::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const uno::Any& rValue )
2760 {
2761 UnoControlModel::setFastPropertyValue_NoBroadcast( nHandle, rValue );
2762
2763 if ( nHandle == BASEPROPERTY_STRINGITEMLIST && !m_pData->m_bSettingLegacyProperty)
2764 {
2765 // synchronize the legacy StringItemList property with our list items
2766 Sequence< ::rtl::OUString > aStringItemList;
2767 Any aPropValue;
2768 getFastPropertyValue( aPropValue, BASEPROPERTY_STRINGITEMLIST );
2769 OSL_VERIFY( aPropValue >>= aStringItemList );
2770
2771 ::std::vector< ListItem > aItems( aStringItemList.getLength() );
2772 ::std::transform(
2773 aStringItemList.getConstArray(),
2774 aStringItemList.getConstArray() + aStringItemList.getLength(),
2775 aItems.begin(),
2776 CreateListItem()
2777 );
2778 m_pData->setAllItems( aItems );
2779
2780 // since an XItemListListener does not have a "all items modified" or some such method,
2781 // we simulate this by notifying removal of all items, followed by insertion of all new
2782 // items
2783 lang::EventObject aEvent;
2784 aEvent.Source = *this;
2785 m_aItemListListeners.notifyEach( &XItemListListener::itemListChanged, aEvent );
2786 // TODO: OPropertySetHelper calls into this method with the mutex locked ...
2787 // which is wrong for the above notifications ...
2788 }
2789 }
2790
ImplGetDefaultValue(sal_uInt16 nPropId) const2791 uno::Any UnoControlComboBoxModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
2792 {
2793 if ( nPropId == BASEPROPERTY_DEFAULTCONTROL )
2794 {
2795 uno::Any aAny;
2796 aAny <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlComboBox );
2797 return aAny;
2798 }
2799 return UnoControlModel::ImplGetDefaultValue( nPropId );
2800 }
2801
2802 // ----------------------------------------------------
2803 // class UnoComboBoxControl
2804 // ----------------------------------------------------
UnoComboBoxControl(const Reference<XMultiServiceFactory> & i_factory)2805 UnoComboBoxControl::UnoComboBoxControl( const Reference< XMultiServiceFactory >& i_factory )
2806 :UnoEditControl( i_factory )
2807 ,maActionListeners( *this )
2808 ,maItemListeners( *this )
2809 {
2810 maComponentInfos.nWidth = 100;
2811 maComponentInfos.nHeight = 12;
2812 }
IMPL_SERVICEINFO_DERIVED(UnoComboBoxControl,UnoEditControl,szServiceName2_UnoControlComboBox)2813 IMPL_SERVICEINFO_DERIVED( UnoComboBoxControl, UnoEditControl, szServiceName2_UnoControlComboBox )
2814
2815 ::rtl::OUString UnoComboBoxControl::GetComponentServiceName()
2816 {
2817 return ::rtl::OUString::createFromAscii( "combobox" );
2818 }
2819
dispose()2820 void UnoComboBoxControl::dispose()
2821 {
2822 lang::EventObject aEvt;
2823 aEvt.Source = (::cppu::OWeakObject*)this;
2824 maActionListeners.disposeAndClear( aEvt );
2825 maItemListeners.disposeAndClear( aEvt );
2826 UnoControl::dispose();
2827 }
queryAggregation(const uno::Type & rType)2828 uno::Any UnoComboBoxControl::queryAggregation( const uno::Type & rType )
2829 {
2830 uno::Any aRet = ::cppu::queryInterface( rType,
2831 SAL_STATIC_CAST( awt::XComboBox*, this ) );
2832 if ( !aRet.hasValue() )
2833 {
2834 aRet = ::cppu::queryInterface( rType,
2835 SAL_STATIC_CAST( awt::XItemListener*, this ) );
2836 if ( !aRet.hasValue() )
2837 {
2838 aRet = ::cppu::queryInterface( rType,
2839 SAL_STATIC_CAST( awt::XItemListListener*, this ) );
2840 }
2841 }
2842 return (aRet.hasValue() ? aRet : UnoEditControl::queryAggregation( rType ));
2843 }
2844 // lang::XTypeProvider
2845 IMPL_XTYPEPROVIDER_START( UnoComboBoxControl )
2846 getCppuType( ( uno::Reference< awt::XComboBox>* ) NULL ),
2847 getCppuType( ( uno::Reference< awt::XItemListener>* ) NULL ),
2848 getCppuType( ( uno::Reference< awt::XItemListListener>* ) NULL ),
2849 UnoEditControl::getTypes()
2850 IMPL_XTYPEPROVIDER_END
2851
2852 void UnoComboBoxControl::updateFromModel()
2853 {
2854 UnoEditControl::updateFromModel();
2855
2856 Reference< XItemListListener > xItemListListener( getPeer(), UNO_QUERY );
2857 ENSURE_OR_RETURN_VOID( xItemListListener.is(), "UnoComboBoxControl::updateFromModel: a peer which is no ItemListListener?!" );
2858
2859 EventObject aEvent( getModel() );
2860 xItemListListener->itemListChanged( aEvent );
2861 }
ImplSetPeerProperty(const::rtl::OUString & rPropName,const uno::Any & rVal)2862 void UnoComboBoxControl::ImplSetPeerProperty( const ::rtl::OUString& rPropName, const uno::Any& rVal )
2863 {
2864 if ( rPropName == GetPropertyName( BASEPROPERTY_STRINGITEMLIST ) )
2865 // do not forward this to our peer. We are a XItemListListener at our model, and changes in the string item
2866 // list (which is a legacy property) will, later, arrive as changes in the ItemList. Those latter changes
2867 // will be forwarded to the peer, which will update itself accordingly.
2868 return;
2869
2870 UnoEditControl::ImplSetPeerProperty( rPropName, rVal );
2871 }
createPeer(const uno::Reference<awt::XToolkit> & rxToolkit,const uno::Reference<awt::XWindowPeer> & rParentPeer)2872 void UnoComboBoxControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer )
2873 {
2874 UnoEditControl::createPeer( rxToolkit, rParentPeer );
2875
2876 uno::Reference < awt::XComboBox > xComboBox( getPeer(), uno::UNO_QUERY );
2877 if ( maActionListeners.getLength() )
2878 xComboBox->addActionListener( &maActionListeners );
2879 if ( maItemListeners.getLength() )
2880 xComboBox->addItemListener( &maItemListeners );
2881 }
2882
addActionListener(const uno::Reference<awt::XActionListener> & l)2883 void UnoComboBoxControl::addActionListener(const uno::Reference< awt::XActionListener > & l)
2884 {
2885 maActionListeners.addInterface( l );
2886 if( getPeer().is() && maActionListeners.getLength() == 1 )
2887 {
2888 uno::Reference < awt::XComboBox > xComboBox( getPeer(), uno::UNO_QUERY );
2889 xComboBox->addActionListener( &maActionListeners );
2890 }
2891 }
2892
removeActionListener(const uno::Reference<awt::XActionListener> & l)2893 void UnoComboBoxControl::removeActionListener(const uno::Reference< awt::XActionListener > & l)
2894 {
2895 if( getPeer().is() && maActionListeners.getLength() == 1 )
2896 {
2897 uno::Reference < awt::XComboBox > xComboBox( getPeer(), uno::UNO_QUERY );
2898 xComboBox->removeActionListener( &maActionListeners );
2899 }
2900 maActionListeners.removeInterface( l );
2901 }
2902
addItemListener(const uno::Reference<awt::XItemListener> & l)2903 void UnoComboBoxControl::addItemListener(const uno::Reference < awt::XItemListener > & l)
2904 {
2905 maItemListeners.addInterface( l );
2906 if( getPeer().is() && maItemListeners.getLength() == 1 )
2907 {
2908 uno::Reference < awt::XComboBox > xComboBox( getPeer(), uno::UNO_QUERY );
2909 xComboBox->addItemListener( &maItemListeners );
2910 }
2911 }
2912
removeItemListener(const uno::Reference<awt::XItemListener> & l)2913 void UnoComboBoxControl::removeItemListener(const uno::Reference < awt::XItemListener > & l)
2914 {
2915 if( getPeer().is() && maItemListeners.getLength() == 1 )
2916 {
2917 uno::Reference < awt::XComboBox > xComboBox( getPeer(), uno::UNO_QUERY ); // MT: Mal alles so umstellen, schoener als Ref anlegen und query rufen
2918 xComboBox->removeItemListener( &maItemListeners );
2919 }
2920 maItemListeners.removeInterface( l );
2921 }
itemStateChanged(const awt::ItemEvent & rEvent)2922 void UnoComboBoxControl::itemStateChanged( const awt::ItemEvent& rEvent )
2923 {
2924 if ( maItemListeners.getLength() )
2925 {
2926 try
2927 {
2928 maItemListeners.itemStateChanged( rEvent );
2929 }
2930 catch( const Exception& e )
2931 {
2932 #if OSL_DEBUG_LEVEL == 0
2933 (void) e; // suppress warning
2934 #else
2935 ::rtl::OString sMessage( "UnoComboBoxControl::itemStateChanged: caught an exception:\n" );
2936 sMessage += ::rtl::OString( e.Message.getStr(), e.Message.getLength(), RTL_TEXTENCODING_ASCII_US );
2937 OSL_ENSURE( sal_False, sMessage.getStr() );
2938 #endif
2939 }
2940 }
2941 }
setModel(const uno::Reference<awt::XControlModel> & i_rModel)2942 sal_Bool SAL_CALL UnoComboBoxControl::setModel( const uno::Reference< awt::XControlModel >& i_rModel )
2943 {
2944 ::osl::MutexGuard aGuard( GetMutex() );
2945
2946 const Reference< XItemList > xOldItems( getModel(), UNO_QUERY );
2947 OSL_ENSURE( xOldItems.is() || !getModel().is(), "UnoComboBoxControl::setModel: illegal old model!" );
2948 const Reference< XItemList > xNewItems( i_rModel, UNO_QUERY );
2949 OSL_ENSURE( xNewItems.is() || !i_rModel.is(), "UnoComboBoxControl::setModel: illegal new model!" );
2950
2951 if ( !UnoEditControl::setModel( i_rModel ) )
2952 return sal_False;
2953
2954 if ( xOldItems.is() )
2955 xOldItems->removeItemListListener( this );
2956 if ( xNewItems.is() )
2957 xNewItems->addItemListListener( this );
2958
2959 return sal_True;
2960 }
2961
listItemInserted(const awt::ItemListEvent & i_rEvent)2962 void SAL_CALL UnoComboBoxControl::listItemInserted( const awt::ItemListEvent& i_rEvent )
2963 {
2964 const Reference< XItemListListener > xPeerListener( getPeer(), UNO_QUERY );
2965 OSL_ENSURE( xPeerListener.is() || !getPeer().is(), "UnoComboBoxControl::listItemInserted: invalid peer!" );
2966 if ( xPeerListener.is() )
2967 xPeerListener->listItemInserted( i_rEvent );
2968 }
2969
listItemRemoved(const awt::ItemListEvent & i_rEvent)2970 void SAL_CALL UnoComboBoxControl::listItemRemoved( const awt::ItemListEvent& i_rEvent )
2971 {
2972 const Reference< XItemListListener > xPeerListener( getPeer(), UNO_QUERY );
2973 OSL_ENSURE( xPeerListener.is() || !getPeer().is(), "UnoComboBoxControl::listItemRemoved: invalid peer!" );
2974 if ( xPeerListener.is() )
2975 xPeerListener->listItemRemoved( i_rEvent );
2976 }
2977
listItemModified(const awt::ItemListEvent & i_rEvent)2978 void SAL_CALL UnoComboBoxControl::listItemModified( const awt::ItemListEvent& i_rEvent )
2979 {
2980 const Reference< XItemListListener > xPeerListener( getPeer(), UNO_QUERY );
2981 OSL_ENSURE( xPeerListener.is() || !getPeer().is(), "UnoComboBoxControl::listItemModified: invalid peer!" );
2982 if ( xPeerListener.is() )
2983 xPeerListener->listItemModified( i_rEvent );
2984 }
2985
allItemsRemoved(const lang::EventObject & i_rEvent)2986 void SAL_CALL UnoComboBoxControl::allItemsRemoved( const lang::EventObject& i_rEvent )
2987 {
2988 const Reference< XItemListListener > xPeerListener( getPeer(), UNO_QUERY );
2989 OSL_ENSURE( xPeerListener.is() || !getPeer().is(), "UnoComboBoxControl::allItemsRemoved: invalid peer!" );
2990 if ( xPeerListener.is() )
2991 xPeerListener->allItemsRemoved( i_rEvent );
2992 }
2993
itemListChanged(const lang::EventObject & i_rEvent)2994 void SAL_CALL UnoComboBoxControl::itemListChanged( const lang::EventObject& i_rEvent )
2995 {
2996 const Reference< XItemListListener > xPeerListener( getPeer(), UNO_QUERY );
2997 OSL_ENSURE( xPeerListener.is() || !getPeer().is(), "UnoComboBoxControl::itemListChanged: invalid peer!" );
2998 if ( xPeerListener.is() )
2999 xPeerListener->itemListChanged( i_rEvent );
3000 }
getActionListeners()3001 ActionListenerMultiplexer& UnoComboBoxControl::getActionListeners()
3002 {
3003 return maActionListeners;
3004 }
getItemListeners()3005 ItemListenerMultiplexer& UnoComboBoxControl::getItemListeners()
3006 {
3007 return maItemListeners;
3008 }
3009
addItem(const::rtl::OUString & aItem,sal_Int16 nPos)3010 void UnoComboBoxControl::addItem( const ::rtl::OUString& aItem, sal_Int16 nPos )
3011 {
3012 uno::Sequence< ::rtl::OUString> aSeq( 1 );
3013 aSeq.getArray()[0] = aItem;
3014 addItems( aSeq, nPos );
3015 }
3016
addItems(const uno::Sequence<::rtl::OUString> & aItems,sal_Int16 nPos)3017 void UnoComboBoxControl::addItems( const uno::Sequence< ::rtl::OUString>& aItems, sal_Int16 nPos )
3018 {
3019 uno::Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_STRINGITEMLIST ) );
3020 uno::Sequence< ::rtl::OUString> aSeq;
3021 aVal >>= aSeq;
3022 sal_uInt16 nNewItems = (sal_uInt16)aItems.getLength();
3023 sal_uInt16 nOldLen = (sal_uInt16)aSeq.getLength();
3024 sal_uInt16 nNewLen = nOldLen + nNewItems;
3025
3026 uno::Sequence< ::rtl::OUString> aNewSeq( nNewLen );
3027 ::rtl::OUString* pNewData = aNewSeq.getArray();
3028 const ::rtl::OUString* pOldData = aSeq.getConstArray();
3029
3030 if ( ( nPos < 0 ) || ( nPos > nOldLen ) )
3031 nPos = (sal_uInt16) nOldLen;
3032
3033 sal_uInt16 n;
3034 // Items vor der Einfuege-Position
3035 for ( n = 0; n < nPos; n++ )
3036 pNewData[n] = pOldData[n];
3037
3038 // Neue Items
3039 for ( n = 0; n < nNewItems; n++ )
3040 pNewData[nPos+n] = aItems.getConstArray()[n];
3041
3042 // Rest der alten Items
3043 for ( n = nPos; n < nOldLen; n++ )
3044 pNewData[nNewItems+n] = pOldData[n];
3045
3046 uno::Any aAny;
3047 aAny <<= aNewSeq;
3048 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_STRINGITEMLIST ), aAny, sal_True );
3049 }
3050
removeItems(sal_Int16 nPos,sal_Int16 nCount)3051 void UnoComboBoxControl::removeItems( sal_Int16 nPos, sal_Int16 nCount )
3052 {
3053 uno::Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_STRINGITEMLIST ) );
3054 uno::Sequence< ::rtl::OUString> aSeq;
3055 aVal >>= aSeq;
3056 sal_uInt16 nOldLen = (sal_uInt16)aSeq.getLength();
3057 if ( nOldLen && ( nPos < nOldLen ) )
3058 {
3059 if ( nCount > ( nOldLen-nPos ) )
3060 nCount = nOldLen-nPos;
3061
3062 sal_uInt16 nNewLen = nOldLen - nCount;
3063
3064 uno::Sequence< ::rtl::OUString> aNewSeq( nNewLen );
3065 ::rtl::OUString* pNewData = aNewSeq.getArray();
3066 ::rtl::OUString* pOldData = aSeq.getArray();
3067
3068 sal_uInt16 n;
3069 // Items vor der Entfern-Position
3070 for ( n = 0; n < nPos; n++ )
3071 pNewData[n] = pOldData[n];
3072
3073 // Rest der Items
3074 for ( n = nPos; n < (nOldLen-nCount); n++ )
3075 pNewData[n] = pOldData[n+nCount];
3076
3077 uno::Any aAny;
3078 aAny <<= aNewSeq;
3079 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_STRINGITEMLIST ), aAny, sal_True );
3080 }
3081 }
3082
getItemCount()3083 sal_Int16 UnoComboBoxControl::getItemCount()
3084 {
3085 uno::Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_STRINGITEMLIST ) );
3086 uno::Sequence< ::rtl::OUString> aSeq;
3087 aVal >>= aSeq;
3088 return (sal_Int16)aSeq.getLength();
3089 }
3090
getItem(sal_Int16 nPos)3091 ::rtl::OUString UnoComboBoxControl::getItem( sal_Int16 nPos )
3092 {
3093 ::rtl::OUString aItem;
3094 uno::Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_STRINGITEMLIST ) );
3095 uno::Sequence< ::rtl::OUString> aSeq;
3096 aVal >>= aSeq;
3097 if ( nPos < aSeq.getLength() )
3098 aItem = aSeq.getConstArray()[nPos];
3099 return aItem;
3100 }
3101
getItems()3102 uno::Sequence< ::rtl::OUString> UnoComboBoxControl::getItems()
3103 {
3104 uno::Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_STRINGITEMLIST ) );
3105 uno::Sequence< ::rtl::OUString> aSeq;
3106 aVal >>= aSeq;
3107 return aSeq;
3108 }
3109
setDropDownLineCount(sal_Int16 nLines)3110 void UnoComboBoxControl::setDropDownLineCount( sal_Int16 nLines )
3111 {
3112 uno::Any aAny;
3113 aAny <<= nLines;
3114 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_LINECOUNT ), aAny, sal_True );
3115 }
3116
getDropDownLineCount()3117 sal_Int16 UnoComboBoxControl::getDropDownLineCount()
3118 {
3119 return ImplGetPropertyValue_INT16( BASEPROPERTY_LINECOUNT );
3120 }
3121
3122
3123 // ----------------------------------------------------
3124 // UnoSpinFieldControl
3125 // ----------------------------------------------------
UnoSpinFieldControl(const Reference<XMultiServiceFactory> & i_factory)3126 UnoSpinFieldControl::UnoSpinFieldControl( const Reference< XMultiServiceFactory >& i_factory )
3127 :UnoEditControl( i_factory )
3128 ,maSpinListeners( *this )
3129 {
3130 mbRepeat = sal_False;
3131 }
3132
3133 // uno::XInterface
queryAggregation(const uno::Type & rType)3134 uno::Any UnoSpinFieldControl::queryAggregation( const uno::Type & rType )
3135 {
3136 uno::Any aRet = ::cppu::queryInterface( rType,
3137 SAL_STATIC_CAST( awt::XSpinField*, this ) );
3138 return (aRet.hasValue() ? aRet : UnoEditControl::queryAggregation( rType ));
3139 }
3140
3141 // lang::XTypeProvider
3142 IMPL_XTYPEPROVIDER_START( UnoSpinFieldControl )
3143 getCppuType( ( uno::Reference< awt::XSpinField>* ) NULL ),
3144 UnoEditControl::getTypes()
3145 IMPL_XTYPEPROVIDER_END
3146
3147 void UnoSpinFieldControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer )
3148 {
3149 UnoEditControl::createPeer( rxToolkit, rParentPeer );
3150
3151 uno::Reference < awt::XSpinField > xField( getPeer(), uno::UNO_QUERY );
3152 xField->enableRepeat( mbRepeat );
3153 if ( maSpinListeners.getLength() )
3154 xField->addSpinListener( &maSpinListeners );
3155 }
3156
3157 // ::com::sun::star::awt::XSpinField
addSpinListener(const::com::sun::star::uno::Reference<::com::sun::star::awt::XSpinListener> & l)3158 void UnoSpinFieldControl::addSpinListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XSpinListener >& l )
3159 {
3160 maSpinListeners.addInterface( l );
3161 if( getPeer().is() && maSpinListeners.getLength() == 1 )
3162 {
3163 uno::Reference < awt::XSpinField > xField( getPeer(), uno::UNO_QUERY );
3164 xField->addSpinListener( &maSpinListeners );
3165 }
3166 }
3167
removeSpinListener(const::com::sun::star::uno::Reference<::com::sun::star::awt::XSpinListener> & l)3168 void UnoSpinFieldControl::removeSpinListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XSpinListener >& l )
3169 {
3170 if( getPeer().is() && maSpinListeners.getLength() == 1 )
3171 {
3172 uno::Reference < awt::XSpinField > xField( getPeer(), uno::UNO_QUERY );
3173 xField->removeSpinListener( &maSpinListeners );
3174 }
3175 maSpinListeners.removeInterface( l );
3176 }
3177
up()3178 void UnoSpinFieldControl::up()
3179 {
3180 uno::Reference < awt::XSpinField > xField( getPeer(), uno::UNO_QUERY );
3181 if ( xField.is() )
3182 xField->up();
3183 }
3184
down()3185 void UnoSpinFieldControl::down()
3186 {
3187 uno::Reference < awt::XSpinField > xField( getPeer(), uno::UNO_QUERY );
3188 if ( xField.is() )
3189 xField->down();
3190 }
3191
first()3192 void UnoSpinFieldControl::first()
3193 {
3194 uno::Reference < awt::XSpinField > xField( getPeer(), uno::UNO_QUERY );
3195 if ( xField.is() )
3196 xField->first();
3197 }
3198
last()3199 void UnoSpinFieldControl::last()
3200 {
3201 uno::Reference < awt::XSpinField > xField( getPeer(), uno::UNO_QUERY );
3202 if ( xField.is() )
3203 xField->last();
3204 }
3205
enableRepeat(sal_Bool bRepeat)3206 void UnoSpinFieldControl::enableRepeat( sal_Bool bRepeat )
3207 {
3208 mbRepeat = bRepeat;
3209
3210 uno::Reference < awt::XSpinField > xField( getPeer(), uno::UNO_QUERY );
3211 if ( xField.is() )
3212 xField->enableRepeat( bRepeat );
3213 }
3214
3215 // ----------------------------------------------------
3216 // class UnoControlDateFieldModel
3217 // ----------------------------------------------------
UnoControlDateFieldModel(const Reference<XMultiServiceFactory> & i_factory)3218 UnoControlDateFieldModel::UnoControlDateFieldModel( const Reference< XMultiServiceFactory >& i_factory )
3219 :UnoControlModel( i_factory )
3220 {
3221 UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXDateField );
3222 }
3223
getServiceName()3224 ::rtl::OUString UnoControlDateFieldModel::getServiceName()
3225 {
3226 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlDateFieldModel );
3227 }
3228
ImplGetDefaultValue(sal_uInt16 nPropId) const3229 uno::Any UnoControlDateFieldModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
3230 {
3231 if ( nPropId == BASEPROPERTY_DEFAULTCONTROL )
3232 {
3233 uno::Any aAny;
3234 aAny <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlDateField );
3235 return aAny;
3236 }
3237 return UnoControlModel::ImplGetDefaultValue( nPropId );
3238 }
3239
3240
getInfoHelper()3241 ::cppu::IPropertyArrayHelper& UnoControlDateFieldModel::getInfoHelper()
3242 {
3243 static UnoPropertyArrayHelper* pHelper = NULL;
3244 if ( !pHelper )
3245 {
3246 uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
3247 pHelper = new UnoPropertyArrayHelper( aIDs );
3248 }
3249 return *pHelper;
3250 }
3251
3252 // beans::XMultiPropertySet
getPropertySetInfo()3253 uno::Reference< beans::XPropertySetInfo > UnoControlDateFieldModel::getPropertySetInfo( )
3254 {
3255 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
3256 return xInfo;
3257 }
3258
3259
3260
3261 // ----------------------------------------------------
3262 // class UnoDateFieldControl
3263 // ----------------------------------------------------
UnoDateFieldControl(const Reference<XMultiServiceFactory> & i_factory)3264 UnoDateFieldControl::UnoDateFieldControl( const Reference< XMultiServiceFactory >& i_factory )
3265 :UnoSpinFieldControl( i_factory )
3266 {
3267 mnFirst = Date( 1, 1, 1900 ).GetDate();
3268 mnLast = Date( 31, 12, 2200 ).GetDate();
3269 mbLongFormat = 2;
3270 }
3271
GetComponentServiceName()3272 ::rtl::OUString UnoDateFieldControl::GetComponentServiceName()
3273 {
3274 return ::rtl::OUString::createFromAscii( "datefield" );
3275 }
3276
3277 // uno::XInterface
queryAggregation(const uno::Type & rType)3278 uno::Any UnoDateFieldControl::queryAggregation( const uno::Type & rType )
3279 {
3280 uno::Any aRet = ::cppu::queryInterface( rType,
3281 SAL_STATIC_CAST( awt::XDateField*, this ) );
3282 return (aRet.hasValue() ? aRet : UnoSpinFieldControl::queryAggregation( rType ));
3283 }
3284
3285 // lang::XTypeProvider
3286 IMPL_XTYPEPROVIDER_START( UnoDateFieldControl )
3287 getCppuType( ( uno::Reference< awt::XDateField>* ) NULL ),
3288 UnoSpinFieldControl::getTypes()
3289 IMPL_XTYPEPROVIDER_END
3290
3291 void UnoDateFieldControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer )
3292 {
3293 UnoSpinFieldControl::createPeer( rxToolkit, rParentPeer );
3294
3295 uno::Reference < awt::XDateField > xField( getPeer(), uno::UNO_QUERY );
3296 xField->setFirst( mnFirst );
3297 xField->setLast( mnLast );
3298 if ( mbLongFormat != 2 ) // not set
3299 xField->setLongFormat( mbLongFormat );
3300 }
3301
3302
textChanged(const awt::TextEvent & e)3303 void UnoDateFieldControl::textChanged( const awt::TextEvent& e )
3304 {
3305 uno::Reference< awt::XVclWindowPeer > xPeer( getPeer(), uno::UNO_QUERY );
3306
3307 // also change the text property (#i25106#)
3308 if ( xPeer.is() )
3309 {
3310 ::rtl::OUString sTextPropertyName = GetPropertyName( BASEPROPERTY_TEXT );
3311 ImplSetPropertyValue( sTextPropertyName, xPeer->getProperty( sTextPropertyName ), sal_False );
3312 }
3313
3314 // re-calc the Date property
3315 uno::Reference < awt::XDateField > xField( getPeer(), uno::UNO_QUERY );
3316 uno::Any aValue;
3317 if ( xField->isEmpty() )
3318 {
3319 // the field says it's empty
3320 sal_Bool bEnforceFormat = sal_True;
3321 if ( xPeer.is() )
3322 xPeer->getProperty( GetPropertyName( BASEPROPERTY_ENFORCE_FORMAT ) ) >>= bEnforceFormat;
3323 if ( !bEnforceFormat )
3324 {
3325 // and it also says that it is currently accepting invalid inputs, without
3326 // forcing it to a valid date
3327 uno::Reference< awt::XTextComponent > xText( xPeer, uno::UNO_QUERY );
3328 if ( xText.is() && xText->getText().getLength() )
3329 // and in real, the text of the peer is *not* empty
3330 // -> simulate an invalid date, which is different from "no date"
3331 aValue <<= util::Date( 0, 0, 0 );
3332 }
3333 }
3334 else
3335 aValue <<= xField->getDate();
3336
3337 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_DATE ), aValue, sal_False );
3338
3339 // multiplex the event
3340 if ( GetTextListeners().getLength() )
3341 GetTextListeners().textChanged( e );
3342 }
3343
setDate(sal_Int32 Date)3344 void UnoDateFieldControl::setDate( sal_Int32 Date )
3345 {
3346 uno::Any aAny;
3347 aAny <<= Date;
3348 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_DATE ), aAny, sal_True );
3349 }
3350
getDate()3351 sal_Int32 UnoDateFieldControl::getDate()
3352 {
3353 return ImplGetPropertyValue_INT32( BASEPROPERTY_DATE );
3354 }
3355
setMin(sal_Int32 Date)3356 void UnoDateFieldControl::setMin( sal_Int32 Date )
3357 {
3358 uno::Any aAny;
3359 aAny <<= Date;
3360 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_DATEMIN ), aAny, sal_True );
3361 }
3362
getMin()3363 sal_Int32 UnoDateFieldControl::getMin()
3364 {
3365 return ImplGetPropertyValue_INT32( BASEPROPERTY_DATEMIN );
3366 }
3367
setMax(sal_Int32 Date)3368 void UnoDateFieldControl::setMax( sal_Int32 Date )
3369 {
3370 uno::Any aAny;
3371 aAny <<= Date;
3372 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_DATEMAX ), aAny, sal_True );
3373 }
3374
getMax()3375 sal_Int32 UnoDateFieldControl::getMax()
3376 {
3377 return ImplGetPropertyValue_INT32( BASEPROPERTY_DATEMAX );
3378 }
3379
setFirst(sal_Int32 Date)3380 void UnoDateFieldControl::setFirst( sal_Int32 Date )
3381 {
3382 mnFirst = Date;
3383 if ( getPeer().is() )
3384 {
3385 uno::Reference < awt::XDateField > xField( getPeer(), uno::UNO_QUERY );
3386 xField->setFirst( Date );
3387 }
3388 }
3389
getFirst()3390 sal_Int32 UnoDateFieldControl::getFirst()
3391 {
3392 return mnFirst;
3393 }
3394
setLast(sal_Int32 Date)3395 void UnoDateFieldControl::setLast( sal_Int32 Date )
3396 {
3397 mnLast = Date;
3398 if ( getPeer().is() )
3399 {
3400 uno::Reference < awt::XDateField > xField( getPeer(), uno::UNO_QUERY );
3401 xField->setLast( Date );
3402 }
3403 }
3404
getLast()3405 sal_Int32 UnoDateFieldControl::getLast()
3406 {
3407 return mnLast;
3408 }
3409
setLongFormat(sal_Bool bLong)3410 void UnoDateFieldControl::setLongFormat( sal_Bool bLong )
3411 {
3412 mbLongFormat = bLong;
3413 if ( getPeer().is() )
3414 {
3415 uno::Reference < awt::XDateField > xField( getPeer(), uno::UNO_QUERY );
3416 xField->setLongFormat( bLong );
3417 }
3418 }
3419
isLongFormat()3420 sal_Bool UnoDateFieldControl::isLongFormat()
3421 {
3422 return ( mbLongFormat != 2 ) ? mbLongFormat : sal_False;
3423 }
3424
setEmpty()3425 void UnoDateFieldControl::setEmpty()
3426 {
3427 if ( getPeer().is() )
3428 {
3429 uno::Reference < awt::XDateField > xField( getPeer(), uno::UNO_QUERY );
3430 xField->setEmpty();
3431 }
3432 }
3433
isEmpty()3434 sal_Bool UnoDateFieldControl::isEmpty()
3435 {
3436 sal_Bool bEmpty = sal_False;
3437 if ( getPeer().is() )
3438 {
3439 uno::Reference < awt::XDateField > xField( getPeer(), uno::UNO_QUERY );
3440 bEmpty = xField->isEmpty();
3441 }
3442 return bEmpty;
3443 }
3444
setStrictFormat(sal_Bool bStrict)3445 void UnoDateFieldControl::setStrictFormat( sal_Bool bStrict )
3446 {
3447 uno::Any aAny;
3448 aAny <<= bStrict;
3449 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_STRICTFORMAT ), aAny, sal_True );
3450 }
3451
isStrictFormat()3452 sal_Bool UnoDateFieldControl::isStrictFormat()
3453 {
3454 return ImplGetPropertyValue_BOOL( BASEPROPERTY_STRICTFORMAT );
3455 }
3456
3457 // ----------------------------------------------------
3458 // class UnoControlTimeFieldModel
3459 // ----------------------------------------------------
UnoControlTimeFieldModel(const Reference<XMultiServiceFactory> & i_factory)3460 UnoControlTimeFieldModel::UnoControlTimeFieldModel( const Reference< XMultiServiceFactory >& i_factory )
3461 :UnoControlModel( i_factory )
3462 {
3463 UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXTimeField );
3464 }
3465
getServiceName()3466 ::rtl::OUString UnoControlTimeFieldModel::getServiceName()
3467 {
3468 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlTimeFieldModel );
3469 }
3470
ImplGetDefaultValue(sal_uInt16 nPropId) const3471 uno::Any UnoControlTimeFieldModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
3472 {
3473 if ( nPropId == BASEPROPERTY_DEFAULTCONTROL )
3474 {
3475 uno::Any aAny;
3476 aAny <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlTimeField );
3477 return aAny;
3478 }
3479 return UnoControlModel::ImplGetDefaultValue( nPropId );
3480 }
3481
3482
getInfoHelper()3483 ::cppu::IPropertyArrayHelper& UnoControlTimeFieldModel::getInfoHelper()
3484 {
3485 static UnoPropertyArrayHelper* pHelper = NULL;
3486 if ( !pHelper )
3487 {
3488 uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
3489 pHelper = new UnoPropertyArrayHelper( aIDs );
3490 }
3491 return *pHelper;
3492 }
3493
3494 // beans::XMultiPropertySet
getPropertySetInfo()3495 uno::Reference< beans::XPropertySetInfo > UnoControlTimeFieldModel::getPropertySetInfo( )
3496 {
3497 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
3498 return xInfo;
3499 }
3500
3501
3502
3503 // ----------------------------------------------------
3504 // class UnoTimeFieldControl
3505 // ----------------------------------------------------
UnoTimeFieldControl(const Reference<XMultiServiceFactory> & i_factory)3506 UnoTimeFieldControl::UnoTimeFieldControl( const Reference< XMultiServiceFactory >& i_factory )
3507 :UnoSpinFieldControl( i_factory )
3508 {
3509 mnFirst = Time( 0, 0 ).GetTime();
3510 mnLast = Time( 23, 59, 59, 99 ).GetTime();
3511 }
3512
GetComponentServiceName()3513 ::rtl::OUString UnoTimeFieldControl::GetComponentServiceName()
3514 {
3515 return ::rtl::OUString::createFromAscii( "timefield" );
3516 }
3517
3518 // uno::XInterface
queryAggregation(const uno::Type & rType)3519 uno::Any UnoTimeFieldControl::queryAggregation( const uno::Type & rType )
3520 {
3521 uno::Any aRet = ::cppu::queryInterface( rType,
3522 SAL_STATIC_CAST( awt::XTimeField*, this ) );
3523 return (aRet.hasValue() ? aRet : UnoSpinFieldControl::queryAggregation( rType ));
3524 }
3525
3526 // lang::XTypeProvider
3527 IMPL_XTYPEPROVIDER_START( UnoTimeFieldControl )
3528 getCppuType( ( uno::Reference< awt::XTimeField>* ) NULL ),
3529 UnoSpinFieldControl::getTypes()
3530 IMPL_XTYPEPROVIDER_END
3531
3532 void UnoTimeFieldControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer )
3533 {
3534 UnoSpinFieldControl::createPeer( rxToolkit, rParentPeer );
3535
3536 uno::Reference < awt::XTimeField > xField( getPeer(), uno::UNO_QUERY );
3537 xField->setFirst( mnFirst );
3538 xField->setLast( mnLast );
3539 }
3540
textChanged(const awt::TextEvent & e)3541 void UnoTimeFieldControl::textChanged( const awt::TextEvent& e )
3542 {
3543 // also change the text property (#i25106#)
3544 uno::Reference< awt::XVclWindowPeer > xPeer( getPeer(), uno::UNO_QUERY );
3545 ::rtl::OUString sTextPropertyName = GetPropertyName( BASEPROPERTY_TEXT );
3546 ImplSetPropertyValue( sTextPropertyName, xPeer->getProperty( sTextPropertyName ), sal_False );
3547
3548 // re-calc the Time property
3549 uno::Reference < awt::XTimeField > xField( getPeer(), uno::UNO_QUERY );
3550 uno::Any aValue;
3551 if ( !xField->isEmpty() )
3552 aValue <<= xField->getTime();
3553 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_TIME ), aValue, sal_False );
3554
3555 // multiplex the event
3556 if ( GetTextListeners().getLength() )
3557 GetTextListeners().textChanged( e );
3558 }
3559
setTime(sal_Int32 Time)3560 void UnoTimeFieldControl::setTime( sal_Int32 Time )
3561 {
3562 uno::Any aAny;
3563 aAny <<= Time;
3564 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_TIME ), aAny, sal_True );
3565 }
3566
getTime()3567 sal_Int32 UnoTimeFieldControl::getTime()
3568 {
3569 return ImplGetPropertyValue_INT32( BASEPROPERTY_TIME );
3570 }
3571
setMin(sal_Int32 Time)3572 void UnoTimeFieldControl::setMin( sal_Int32 Time )
3573 {
3574 uno::Any aAny;
3575 aAny <<= Time;
3576 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_TIMEMIN ), aAny, sal_True );
3577 }
3578
getMin()3579 sal_Int32 UnoTimeFieldControl::getMin()
3580 {
3581 return ImplGetPropertyValue_INT32( BASEPROPERTY_TIMEMIN );
3582 }
3583
setMax(sal_Int32 Time)3584 void UnoTimeFieldControl::setMax( sal_Int32 Time )
3585 {
3586 uno::Any aAny;
3587 aAny <<= Time;
3588 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_TIMEMAX ), aAny, sal_True );
3589 }
3590
getMax()3591 sal_Int32 UnoTimeFieldControl::getMax()
3592 {
3593 return ImplGetPropertyValue_INT32( BASEPROPERTY_TIMEMAX );
3594 }
3595
setFirst(sal_Int32 Time)3596 void UnoTimeFieldControl::setFirst( sal_Int32 Time )
3597 {
3598 mnFirst = Time;
3599 if ( getPeer().is() )
3600 {
3601 uno::Reference < awt::XTimeField > xField( getPeer(), uno::UNO_QUERY );
3602 xField->setFirst( mnFirst );
3603 }
3604 }
3605
getFirst()3606 sal_Int32 UnoTimeFieldControl::getFirst()
3607 {
3608 return mnFirst;
3609 }
3610
setLast(sal_Int32 Time)3611 void UnoTimeFieldControl::setLast( sal_Int32 Time )
3612 {
3613 mnLast = Time;
3614 if ( getPeer().is() )
3615 {
3616 uno::Reference < awt::XTimeField > xField( getPeer(), uno::UNO_QUERY );
3617 xField->setFirst( mnLast );
3618 }
3619 }
3620
getLast()3621 sal_Int32 UnoTimeFieldControl::getLast()
3622 {
3623 return mnLast;
3624 }
3625
setEmpty()3626 void UnoTimeFieldControl::setEmpty()
3627 {
3628 if ( getPeer().is() )
3629 {
3630 uno::Reference < awt::XTimeField > xField( getPeer(), uno::UNO_QUERY );
3631 xField->setEmpty();
3632 }
3633 }
3634
isEmpty()3635 sal_Bool UnoTimeFieldControl::isEmpty()
3636 {
3637 sal_Bool bEmpty = sal_False;
3638 if ( getPeer().is() )
3639 {
3640 uno::Reference < awt::XTimeField > xField( getPeer(), uno::UNO_QUERY );
3641 bEmpty = xField->isEmpty();
3642 }
3643 return bEmpty;
3644 }
3645
setStrictFormat(sal_Bool bStrict)3646 void UnoTimeFieldControl::setStrictFormat( sal_Bool bStrict )
3647 {
3648 uno::Any aAny;
3649 aAny <<= bStrict;
3650 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_STRICTFORMAT ), aAny, sal_True );
3651 }
3652
isStrictFormat()3653 sal_Bool UnoTimeFieldControl::isStrictFormat()
3654 {
3655 return ImplGetPropertyValue_BOOL( BASEPROPERTY_STRICTFORMAT );
3656 }
3657
3658 // ----------------------------------------------------
3659 // class UnoControlNumericFieldModel
3660 // ----------------------------------------------------
UnoControlNumericFieldModel(const Reference<XMultiServiceFactory> & i_factory)3661 UnoControlNumericFieldModel::UnoControlNumericFieldModel( const Reference< XMultiServiceFactory >& i_factory )
3662 :UnoControlModel( i_factory )
3663 {
3664 UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXNumericField );
3665 }
3666
getServiceName()3667 ::rtl::OUString UnoControlNumericFieldModel::getServiceName()
3668 {
3669 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlNumericFieldModel );
3670 }
3671
ImplGetDefaultValue(sal_uInt16 nPropId) const3672 uno::Any UnoControlNumericFieldModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
3673 {
3674 if ( nPropId == BASEPROPERTY_DEFAULTCONTROL )
3675 {
3676 uno::Any aAny;
3677 aAny <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlNumericField );
3678 return aAny;
3679 }
3680 return UnoControlModel::ImplGetDefaultValue( nPropId );
3681 }
3682
3683
getInfoHelper()3684 ::cppu::IPropertyArrayHelper& UnoControlNumericFieldModel::getInfoHelper()
3685 {
3686 static UnoPropertyArrayHelper* pHelper = NULL;
3687 if ( !pHelper )
3688 {
3689 uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
3690 pHelper = new UnoPropertyArrayHelper( aIDs );
3691 }
3692 return *pHelper;
3693 }
3694
3695 // beans::XMultiPropertySet
getPropertySetInfo()3696 uno::Reference< beans::XPropertySetInfo > UnoControlNumericFieldModel::getPropertySetInfo( )
3697 {
3698 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
3699 return xInfo;
3700 }
3701
3702
3703
3704 // ----------------------------------------------------
3705 // class UnoNumericFieldControl
3706 // ----------------------------------------------------
UnoNumericFieldControl(const Reference<XMultiServiceFactory> & i_factory)3707 UnoNumericFieldControl::UnoNumericFieldControl( const Reference< XMultiServiceFactory >& i_factory )
3708 :UnoSpinFieldControl( i_factory )
3709 {
3710 mnFirst = 0;
3711 mnLast = 0x7FFFFFFF;
3712 }
3713
GetComponentServiceName()3714 ::rtl::OUString UnoNumericFieldControl::GetComponentServiceName()
3715 {
3716 return ::rtl::OUString::createFromAscii( "numericfield" );
3717 }
3718
3719 // uno::XInterface
queryAggregation(const uno::Type & rType)3720 uno::Any UnoNumericFieldControl::queryAggregation( const uno::Type & rType )
3721 {
3722 uno::Any aRet = ::cppu::queryInterface( rType,
3723 SAL_STATIC_CAST( awt::XNumericField*, this ) );
3724 return (aRet.hasValue() ? aRet : UnoSpinFieldControl::queryAggregation( rType ));
3725 }
3726
3727 // lang::XTypeProvider
3728 IMPL_XTYPEPROVIDER_START( UnoNumericFieldControl )
3729 getCppuType( ( uno::Reference< awt::XNumericField>* ) NULL ),
3730 UnoSpinFieldControl::getTypes()
3731 IMPL_XTYPEPROVIDER_END
3732
3733 void UnoNumericFieldControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer )
3734 {
3735 UnoSpinFieldControl::createPeer( rxToolkit, rParentPeer );
3736
3737 uno::Reference < awt::XNumericField > xField( getPeer(), uno::UNO_QUERY );
3738 xField->setFirst( mnFirst );
3739 xField->setLast( mnLast );
3740 }
3741
3742
textChanged(const awt::TextEvent & e)3743 void UnoNumericFieldControl::textChanged( const awt::TextEvent& e )
3744 {
3745 uno::Reference < awt::XNumericField > xField( getPeer(), uno::UNO_QUERY );
3746 uno::Any aAny;
3747 aAny <<= xField->getValue();
3748 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VALUE_DOUBLE ), aAny, sal_False );
3749
3750 if ( GetTextListeners().getLength() )
3751 GetTextListeners().textChanged( e );
3752 }
3753
setValue(double Value)3754 void UnoNumericFieldControl::setValue( double Value )
3755 {
3756 uno::Any aAny;
3757 aAny <<= Value;
3758 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VALUE_DOUBLE ), aAny, sal_True );
3759 }
3760
getValue()3761 double UnoNumericFieldControl::getValue()
3762 {
3763 return ImplGetPropertyValue_DOUBLE( BASEPROPERTY_VALUE_DOUBLE );
3764 }
3765
setMin(double Value)3766 void UnoNumericFieldControl::setMin( double Value )
3767 {
3768 uno::Any aAny;
3769 aAny <<= Value;
3770 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VALUEMIN_DOUBLE ), aAny, sal_True );
3771 }
3772
getMin()3773 double UnoNumericFieldControl::getMin()
3774 {
3775 return ImplGetPropertyValue_DOUBLE( BASEPROPERTY_VALUEMIN_DOUBLE );
3776 }
3777
setMax(double Value)3778 void UnoNumericFieldControl::setMax( double Value )
3779 {
3780 uno::Any aAny;
3781 aAny <<= Value;
3782 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VALUEMAX_DOUBLE ), aAny, sal_True );
3783 }
3784
getMax()3785 double UnoNumericFieldControl::getMax()
3786 {
3787 return ImplGetPropertyValue_DOUBLE( BASEPROPERTY_VALUEMAX_DOUBLE );
3788 }
3789
setFirst(double Value)3790 void UnoNumericFieldControl::setFirst( double Value )
3791 {
3792 mnFirst = Value;
3793 if ( getPeer().is() )
3794 {
3795 uno::Reference < awt::XNumericField > xField( getPeer(), uno::UNO_QUERY );
3796 xField->setFirst( mnFirst );
3797 }
3798 }
3799
getFirst()3800 double UnoNumericFieldControl::getFirst()
3801 {
3802 return mnFirst;
3803 }
3804
setLast(double Value)3805 void UnoNumericFieldControl::setLast( double Value )
3806 {
3807 mnLast = Value;
3808 if ( getPeer().is() )
3809 {
3810 uno::Reference < awt::XNumericField > xField( getPeer(), uno::UNO_QUERY );
3811 xField->setLast( mnLast );
3812 }
3813 }
3814
getLast()3815 double UnoNumericFieldControl::getLast()
3816 {
3817 return mnLast;
3818 }
3819
setStrictFormat(sal_Bool bStrict)3820 void UnoNumericFieldControl::setStrictFormat( sal_Bool bStrict )
3821 {
3822 uno::Any aAny;
3823 aAny <<= bStrict;
3824 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_STRICTFORMAT ), aAny, sal_True );
3825 }
3826
isStrictFormat()3827 sal_Bool UnoNumericFieldControl::isStrictFormat()
3828 {
3829 return ImplGetPropertyValue_BOOL( BASEPROPERTY_STRICTFORMAT );
3830 }
3831
setSpinSize(double Digits)3832 void UnoNumericFieldControl::setSpinSize( double Digits )
3833 {
3834 uno::Any aAny;
3835 aAny <<= Digits;
3836 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VALUESTEP_DOUBLE ), aAny, sal_True );
3837 }
3838
getSpinSize()3839 double UnoNumericFieldControl::getSpinSize()
3840 {
3841 return ImplGetPropertyValue_DOUBLE( BASEPROPERTY_VALUESTEP_DOUBLE );
3842 }
3843
setDecimalDigits(sal_Int16 Digits)3844 void UnoNumericFieldControl::setDecimalDigits( sal_Int16 Digits )
3845 {
3846 uno::Any aAny;
3847 aAny <<= Digits;
3848 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_DECIMALACCURACY ), aAny, sal_True );
3849 }
3850
getDecimalDigits()3851 sal_Int16 UnoNumericFieldControl::getDecimalDigits()
3852 {
3853 return ImplGetPropertyValue_INT16( BASEPROPERTY_DECIMALACCURACY );
3854 }
3855
3856 // ----------------------------------------------------
3857 // class UnoControlCurrencyFieldModel
3858 // ----------------------------------------------------
UnoControlCurrencyFieldModel(const Reference<XMultiServiceFactory> & i_factory)3859 UnoControlCurrencyFieldModel::UnoControlCurrencyFieldModel( const Reference< XMultiServiceFactory >& i_factory )
3860 :UnoControlModel( i_factory )
3861 {
3862 UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXCurrencyField );
3863 }
3864
getServiceName()3865 ::rtl::OUString UnoControlCurrencyFieldModel::getServiceName()
3866 {
3867 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlCurrencyFieldModel );
3868 }
3869
ImplGetDefaultValue(sal_uInt16 nPropId) const3870 uno::Any UnoControlCurrencyFieldModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
3871 {
3872 if ( nPropId == BASEPROPERTY_DEFAULTCONTROL )
3873 {
3874 uno::Any aAny;
3875 aAny <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlCurrencyField );
3876 return aAny;
3877 }
3878 if ( nPropId == BASEPROPERTY_CURSYM_POSITION )
3879 {
3880 uno::Any aAny;
3881 aAny <<= (sal_Bool)sal_False;
3882 return aAny;
3883 }
3884
3885 return UnoControlModel::ImplGetDefaultValue( nPropId );
3886 }
3887
getInfoHelper()3888 ::cppu::IPropertyArrayHelper& UnoControlCurrencyFieldModel::getInfoHelper()
3889 {
3890 static UnoPropertyArrayHelper* pHelper = NULL;
3891 if ( !pHelper )
3892 {
3893 uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
3894 pHelper = new UnoPropertyArrayHelper( aIDs );
3895 }
3896 return *pHelper;
3897 }
3898
3899 // beans::XMultiPropertySet
getPropertySetInfo()3900 uno::Reference< beans::XPropertySetInfo > UnoControlCurrencyFieldModel::getPropertySetInfo( )
3901 {
3902 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
3903 return xInfo;
3904 }
3905
3906 // ----------------------------------------------------
3907 // class UnoCurrencyFieldControl
3908 // ----------------------------------------------------
UnoCurrencyFieldControl(const Reference<XMultiServiceFactory> & i_factory)3909 UnoCurrencyFieldControl::UnoCurrencyFieldControl( const Reference< XMultiServiceFactory >& i_factory )
3910 :UnoSpinFieldControl( i_factory )
3911 {
3912 mnFirst = 0;
3913 mnLast = 0x7FFFFFFF;
3914 }
3915
GetComponentServiceName()3916 ::rtl::OUString UnoCurrencyFieldControl::GetComponentServiceName()
3917 {
3918 return ::rtl::OUString::createFromAscii( "longcurrencyfield" );
3919 }
3920
3921 // uno::XInterface
queryAggregation(const uno::Type & rType)3922 uno::Any UnoCurrencyFieldControl::queryAggregation( const uno::Type & rType )
3923 {
3924 uno::Any aRet = ::cppu::queryInterface( rType,
3925 SAL_STATIC_CAST( awt::XCurrencyField*, this ) );
3926 return (aRet.hasValue() ? aRet : UnoSpinFieldControl::queryAggregation( rType ));
3927 }
3928
3929 // lang::XTypeProvider
3930 IMPL_XTYPEPROVIDER_START( UnoCurrencyFieldControl )
3931 getCppuType( ( uno::Reference< awt::XCurrencyField>* ) NULL ),
3932 UnoSpinFieldControl::getTypes()
3933 IMPL_XTYPEPROVIDER_END
3934
3935 void UnoCurrencyFieldControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer )
3936 {
3937 UnoSpinFieldControl::createPeer( rxToolkit, rParentPeer );
3938
3939 uno::Reference < awt::XCurrencyField > xField( getPeer(), uno::UNO_QUERY );
3940 xField->setFirst( mnFirst );
3941 xField->setLast( mnLast );
3942 }
3943
textChanged(const awt::TextEvent & e)3944 void UnoCurrencyFieldControl::textChanged( const awt::TextEvent& e )
3945 {
3946 uno::Reference < awt::XCurrencyField > xField( getPeer(), uno::UNO_QUERY );
3947 uno::Any aAny;
3948 aAny <<= xField->getValue();
3949 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VALUE_DOUBLE ), aAny, sal_False );
3950
3951 if ( GetTextListeners().getLength() )
3952 GetTextListeners().textChanged( e );
3953 }
3954
setValue(double Value)3955 void UnoCurrencyFieldControl::setValue( double Value )
3956 {
3957 uno::Any aAny;
3958 aAny <<= Value;
3959 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VALUE_DOUBLE ), aAny, sal_True );
3960 }
3961
getValue()3962 double UnoCurrencyFieldControl::getValue()
3963 {
3964 return ImplGetPropertyValue_DOUBLE( BASEPROPERTY_VALUE_DOUBLE );
3965 }
3966
setMin(double Value)3967 void UnoCurrencyFieldControl::setMin( double Value )
3968 {
3969 uno::Any aAny;
3970 aAny <<= Value;
3971 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VALUEMIN_DOUBLE ), aAny, sal_True );
3972 }
3973
getMin()3974 double UnoCurrencyFieldControl::getMin()
3975 {
3976 return ImplGetPropertyValue_DOUBLE( BASEPROPERTY_VALUEMIN_DOUBLE );
3977 }
3978
setMax(double Value)3979 void UnoCurrencyFieldControl::setMax( double Value )
3980 {
3981 uno::Any aAny;
3982 aAny <<= Value;
3983 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VALUEMAX_DOUBLE ), aAny, sal_True );
3984 }
3985
getMax()3986 double UnoCurrencyFieldControl::getMax()
3987 {
3988 return ImplGetPropertyValue_DOUBLE( BASEPROPERTY_VALUEMAX_DOUBLE );
3989 }
3990
setFirst(double Value)3991 void UnoCurrencyFieldControl::setFirst( double Value )
3992 {
3993 mnFirst = Value;
3994 if ( getPeer().is() )
3995 {
3996 uno::Reference < awt::XCurrencyField > xField( getPeer(), uno::UNO_QUERY );
3997 xField->setFirst( mnFirst );
3998 }
3999 }
4000
getFirst()4001 double UnoCurrencyFieldControl::getFirst()
4002 {
4003 return mnFirst;
4004 }
4005
setLast(double Value)4006 void UnoCurrencyFieldControl::setLast( double Value )
4007 {
4008 mnLast = Value;
4009 if ( getPeer().is() )
4010 {
4011 uno::Reference < awt::XCurrencyField > xField( getPeer(), uno::UNO_QUERY );
4012 xField->setLast( mnLast );
4013 }
4014 }
4015
getLast()4016 double UnoCurrencyFieldControl::getLast()
4017 {
4018 return mnLast;
4019 }
4020
setStrictFormat(sal_Bool bStrict)4021 void UnoCurrencyFieldControl::setStrictFormat( sal_Bool bStrict )
4022 {
4023 uno::Any aAny;
4024 aAny <<= bStrict;
4025 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_STRICTFORMAT ), aAny, sal_True );
4026 }
4027
isStrictFormat()4028 sal_Bool UnoCurrencyFieldControl::isStrictFormat()
4029 {
4030 return ImplGetPropertyValue_BOOL( BASEPROPERTY_STRICTFORMAT );
4031 }
4032
setSpinSize(double Digits)4033 void UnoCurrencyFieldControl::setSpinSize( double Digits )
4034 {
4035 uno::Any aAny;
4036 aAny <<= Digits;
4037 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VALUESTEP_DOUBLE ), aAny, sal_True );
4038 }
4039
getSpinSize()4040 double UnoCurrencyFieldControl::getSpinSize()
4041 {
4042 return ImplGetPropertyValue_DOUBLE( BASEPROPERTY_VALUESTEP_DOUBLE );
4043 }
4044
setDecimalDigits(sal_Int16 Digits)4045 void UnoCurrencyFieldControl::setDecimalDigits( sal_Int16 Digits )
4046 {
4047 uno::Any aAny;
4048 aAny <<= Digits;
4049 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_DECIMALACCURACY ), aAny, sal_True );
4050 }
4051
getDecimalDigits()4052 sal_Int16 UnoCurrencyFieldControl::getDecimalDigits()
4053 {
4054 return ImplGetPropertyValue_INT16( BASEPROPERTY_DECIMALACCURACY );
4055 }
4056
4057 // ----------------------------------------------------
4058 // class UnoControlPatternFieldModel
4059 // ----------------------------------------------------
UnoControlPatternFieldModel(const Reference<XMultiServiceFactory> & i_factory)4060 UnoControlPatternFieldModel::UnoControlPatternFieldModel( const Reference< XMultiServiceFactory >& i_factory )
4061 :UnoControlModel( i_factory )
4062 {
4063 UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXPatternField );
4064 }
4065
getServiceName()4066 ::rtl::OUString UnoControlPatternFieldModel::getServiceName()
4067 {
4068 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlPatternFieldModel );
4069 }
4070
ImplGetDefaultValue(sal_uInt16 nPropId) const4071 uno::Any UnoControlPatternFieldModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
4072 {
4073 if ( nPropId == BASEPROPERTY_DEFAULTCONTROL )
4074 {
4075 uno::Any aAny;
4076 aAny <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlPatternField );
4077 return aAny;
4078 }
4079 return UnoControlModel::ImplGetDefaultValue( nPropId );
4080 }
4081
getInfoHelper()4082 ::cppu::IPropertyArrayHelper& UnoControlPatternFieldModel::getInfoHelper()
4083 {
4084 static UnoPropertyArrayHelper* pHelper = NULL;
4085 if ( !pHelper )
4086 {
4087 uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
4088 pHelper = new UnoPropertyArrayHelper( aIDs );
4089 }
4090 return *pHelper;
4091 }
4092
4093 // beans::XMultiPropertySet
getPropertySetInfo()4094 uno::Reference< beans::XPropertySetInfo > UnoControlPatternFieldModel::getPropertySetInfo( )
4095 {
4096 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
4097 return xInfo;
4098 }
4099
4100
4101 // ----------------------------------------------------
4102 // class UnoPatternFieldControl
4103 // ----------------------------------------------------
UnoPatternFieldControl(const Reference<XMultiServiceFactory> & i_factory)4104 UnoPatternFieldControl::UnoPatternFieldControl( const Reference< XMultiServiceFactory >& i_factory )
4105 :UnoSpinFieldControl( i_factory )
4106 {
4107 }
4108
GetComponentServiceName()4109 ::rtl::OUString UnoPatternFieldControl::GetComponentServiceName()
4110 {
4111 return ::rtl::OUString::createFromAscii( "patternfield" );
4112 }
4113
ImplSetPeerProperty(const::rtl::OUString & rPropName,const uno::Any & rVal)4114 void UnoPatternFieldControl::ImplSetPeerProperty( const ::rtl::OUString& rPropName, const uno::Any& rVal )
4115 {
4116 sal_uInt16 nType = GetPropertyId( rPropName );
4117 if ( ( nType == BASEPROPERTY_TEXT ) || ( nType == BASEPROPERTY_EDITMASK ) || ( nType == BASEPROPERTY_LITERALMASK ) )
4118 {
4119 // Die Masken koennen nicht nacheinander gesetzt werden.
4120 ::rtl::OUString Text = ImplGetPropertyValue_UString( BASEPROPERTY_TEXT );
4121 ::rtl::OUString EditMask = ImplGetPropertyValue_UString( BASEPROPERTY_EDITMASK );
4122 ::rtl::OUString LiteralMask = ImplGetPropertyValue_UString( BASEPROPERTY_LITERALMASK );
4123
4124 uno::Reference < awt::XPatternField > xPF( getPeer(), uno::UNO_QUERY );
4125 if (xPF.is())
4126 {
4127 // same comment as in UnoControl::ImplSetPeerProperty - see there
4128 ::rtl::OUString sText( Text );
4129 ImplCheckLocalize( sText );
4130 xPF->setString( sText );
4131 xPF->setMasks( EditMask, LiteralMask );
4132 }
4133 }
4134 else
4135 UnoSpinFieldControl::ImplSetPeerProperty( rPropName, rVal );
4136 }
4137
4138
4139 // uno::XInterface
queryAggregation(const uno::Type & rType)4140 uno::Any UnoPatternFieldControl::queryAggregation( const uno::Type & rType )
4141 {
4142 uno::Any aRet = ::cppu::queryInterface( rType,
4143 SAL_STATIC_CAST( awt::XPatternField*, this ) );
4144 return (aRet.hasValue() ? aRet : UnoSpinFieldControl::queryAggregation( rType ));
4145 }
4146
4147 // lang::XTypeProvider
4148 IMPL_XTYPEPROVIDER_START( UnoPatternFieldControl )
4149 getCppuType( ( uno::Reference< awt::XPatternField>* ) NULL ),
4150 UnoSpinFieldControl::getTypes()
4151 IMPL_XTYPEPROVIDER_END
4152
4153 void UnoPatternFieldControl::setString( const ::rtl::OUString& rString )
4154 {
4155 setText( rString );
4156 }
4157
getString()4158 ::rtl::OUString UnoPatternFieldControl::getString()
4159 {
4160 return getText();
4161 }
4162
setMasks(const::rtl::OUString & EditMask,const::rtl::OUString & LiteralMask)4163 void UnoPatternFieldControl::setMasks( const ::rtl::OUString& EditMask, const ::rtl::OUString& LiteralMask )
4164 {
4165 uno::Any aAny;
4166 aAny <<= EditMask;
4167 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_EDITMASK ), aAny, sal_True );
4168 aAny <<= LiteralMask;
4169 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_LITERALMASK ), aAny, sal_True );
4170 }
4171
getMasks(::rtl::OUString & EditMask,::rtl::OUString & LiteralMask)4172 void UnoPatternFieldControl::getMasks( ::rtl::OUString& EditMask, ::rtl::OUString& LiteralMask )
4173 {
4174 EditMask = ImplGetPropertyValue_UString( BASEPROPERTY_EDITMASK );
4175 LiteralMask = ImplGetPropertyValue_UString( BASEPROPERTY_LITERALMASK );
4176 }
4177
setStrictFormat(sal_Bool bStrict)4178 void UnoPatternFieldControl::setStrictFormat( sal_Bool bStrict )
4179 {
4180 uno::Any aAny;
4181 aAny <<= bStrict;
4182 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_STRICTFORMAT ), aAny, sal_True );
4183 }
4184
isStrictFormat()4185 sal_Bool UnoPatternFieldControl::isStrictFormat()
4186 {
4187 return ImplGetPropertyValue_BOOL( BASEPROPERTY_STRICTFORMAT );
4188 }
4189
4190
4191 // ----------------------------------------------------
4192 // class UnoControlProgressBarModel
4193 // ----------------------------------------------------
UnoControlProgressBarModel(const Reference<XMultiServiceFactory> & i_factory)4194 UnoControlProgressBarModel::UnoControlProgressBarModel( const Reference< XMultiServiceFactory >& i_factory )
4195 :UnoControlModel( i_factory )
4196 {
4197 ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR );
4198 ImplRegisterProperty( BASEPROPERTY_BORDER );
4199 ImplRegisterProperty( BASEPROPERTY_BORDERCOLOR );
4200 ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL );
4201 ImplRegisterProperty( BASEPROPERTY_ENABLED );
4202 ImplRegisterProperty( BASEPROPERTY_ENABLEVISIBLE );
4203 ImplRegisterProperty( BASEPROPERTY_FILLCOLOR );
4204 ImplRegisterProperty( BASEPROPERTY_HELPTEXT );
4205 ImplRegisterProperty( BASEPROPERTY_HELPURL );
4206 ImplRegisterProperty( BASEPROPERTY_PRINTABLE );
4207 ImplRegisterProperty( BASEPROPERTY_PROGRESSVALUE );
4208 ImplRegisterProperty( BASEPROPERTY_PROGRESSVALUE_MAX );
4209 ImplRegisterProperty( BASEPROPERTY_PROGRESSVALUE_MIN );
4210 }
4211
getServiceName()4212 ::rtl::OUString UnoControlProgressBarModel::getServiceName( )
4213 {
4214 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlProgressBarModel );
4215 }
4216
ImplGetDefaultValue(sal_uInt16 nPropId) const4217 uno::Any UnoControlProgressBarModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
4218 {
4219 if ( nPropId == BASEPROPERTY_DEFAULTCONTROL )
4220 {
4221 uno::Any aAny;
4222 aAny <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlProgressBar );
4223 return aAny;
4224 }
4225
4226 return UnoControlModel::ImplGetDefaultValue( nPropId );
4227 }
4228
getInfoHelper()4229 ::cppu::IPropertyArrayHelper& UnoControlProgressBarModel::getInfoHelper()
4230 {
4231 static UnoPropertyArrayHelper* pHelper = NULL;
4232 if ( !pHelper )
4233 {
4234 uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
4235 pHelper = new UnoPropertyArrayHelper( aIDs );
4236 }
4237 return *pHelper;
4238 }
4239
4240 // beans::XMultiPropertySet
getPropertySetInfo()4241 uno::Reference< beans::XPropertySetInfo > UnoControlProgressBarModel::getPropertySetInfo( )
4242 {
4243 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
4244 return xInfo;
4245 }
4246
4247
4248 // ----------------------------------------------------
4249 // class UnoProgressBarControl
4250 // ----------------------------------------------------
UnoProgressBarControl(const Reference<XMultiServiceFactory> & i_factory)4251 UnoProgressBarControl::UnoProgressBarControl( const Reference< XMultiServiceFactory >& i_factory )
4252 :UnoControlBase( i_factory )
4253 {
4254 }
4255
GetComponentServiceName()4256 ::rtl::OUString UnoProgressBarControl::GetComponentServiceName()
4257 {
4258 return ::rtl::OUString::createFromAscii( "ProgressBar" );
4259 }
4260
4261 // uno::XInterface
queryAggregation(const uno::Type & rType)4262 uno::Any UnoProgressBarControl::queryAggregation( const uno::Type & rType )
4263 {
4264 uno::Any aRet = ::cppu::queryInterface( rType,
4265 SAL_STATIC_CAST( awt::XProgressBar*, this ) );
4266 return (aRet.hasValue() ? aRet : UnoControlBase::queryAggregation( rType ));
4267 }
4268
4269 // lang::XTypeProvider
4270 IMPL_XTYPEPROVIDER_START( UnoProgressBarControl )
4271 getCppuType( ( uno::Reference< awt::XProgressBar>* ) NULL ),
4272 UnoControlBase::getTypes()
4273 IMPL_XTYPEPROVIDER_END
4274
4275 // ::com::sun::star::awt::XProgressBar
4276 void UnoProgressBarControl::setForegroundColor( sal_Int32 nColor )
4277 {
4278 uno::Any aAny;
4279 aAny <<= nColor;
4280 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_FILLCOLOR ), aAny, sal_True );
4281 }
4282
setBackgroundColor(sal_Int32 nColor)4283 void UnoProgressBarControl::setBackgroundColor( sal_Int32 nColor )
4284 {
4285 uno::Any aAny;
4286 aAny <<= nColor;
4287 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_BACKGROUNDCOLOR ), aAny, sal_True );
4288 }
4289
setValue(sal_Int32 nValue)4290 void UnoProgressBarControl::setValue( sal_Int32 nValue )
4291 {
4292 uno::Any aAny;
4293 aAny <<= nValue;
4294 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_PROGRESSVALUE ), aAny, sal_True );
4295 }
4296
setRange(sal_Int32 nMin,sal_Int32 nMax)4297 void UnoProgressBarControl::setRange( sal_Int32 nMin, sal_Int32 nMax )
4298 {
4299 uno::Any aMin;
4300 uno::Any aMax;
4301
4302 if ( nMin < nMax )
4303 {
4304 // take correct min and max
4305 aMin <<= nMin;
4306 aMax <<= nMax;
4307 }
4308 else
4309 {
4310 // change min and max
4311 aMin <<= nMax;
4312 aMax <<= nMin;
4313 }
4314
4315 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_PROGRESSVALUE_MIN ), aMin, sal_True );
4316 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_PROGRESSVALUE_MAX ), aMax, sal_True );
4317 }
4318
getValue()4319 sal_Int32 UnoProgressBarControl::getValue()
4320 {
4321 return ImplGetPropertyValue_INT32( BASEPROPERTY_PROGRESSVALUE );
4322 }
4323
4324
4325 // ----------------------------------------------------
4326 // class UnoControlFixedLineModel
4327 // ----------------------------------------------------
UnoControlFixedLineModel(const Reference<XMultiServiceFactory> & i_factory)4328 UnoControlFixedLineModel::UnoControlFixedLineModel( const Reference< XMultiServiceFactory >& i_factory )
4329 :UnoControlModel( i_factory )
4330 {
4331 ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR );
4332 ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL );
4333 ImplRegisterProperty( BASEPROPERTY_ENABLED );
4334 ImplRegisterProperty( BASEPROPERTY_ENABLEVISIBLE );
4335 ImplRegisterProperty( BASEPROPERTY_FONTDESCRIPTOR );
4336 ImplRegisterProperty( BASEPROPERTY_HELPTEXT );
4337 ImplRegisterProperty( BASEPROPERTY_HELPURL );
4338 ImplRegisterProperty( BASEPROPERTY_LABEL );
4339 ImplRegisterProperty( BASEPROPERTY_ORIENTATION );
4340 ImplRegisterProperty( BASEPROPERTY_PRINTABLE );
4341 }
4342
getServiceName()4343 ::rtl::OUString UnoControlFixedLineModel::getServiceName( )
4344 {
4345 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlFixedLineModel );
4346 }
4347
ImplGetDefaultValue(sal_uInt16 nPropId) const4348 uno::Any UnoControlFixedLineModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
4349 {
4350 if ( nPropId == BASEPROPERTY_DEFAULTCONTROL )
4351 {
4352 uno::Any aAny;
4353 aAny <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlFixedLine );
4354 return aAny;
4355 }
4356 return UnoControlModel::ImplGetDefaultValue( nPropId );
4357 }
4358
getInfoHelper()4359 ::cppu::IPropertyArrayHelper& UnoControlFixedLineModel::getInfoHelper()
4360 {
4361 static UnoPropertyArrayHelper* pHelper = NULL;
4362 if ( !pHelper )
4363 {
4364 uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
4365 pHelper = new UnoPropertyArrayHelper( aIDs );
4366 }
4367 return *pHelper;
4368 }
4369
4370 // beans::XMultiPropertySet
getPropertySetInfo()4371 uno::Reference< beans::XPropertySetInfo > UnoControlFixedLineModel::getPropertySetInfo( )
4372 {
4373 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
4374 return xInfo;
4375 }
4376
4377 // ----------------------------------------------------
4378 // class UnoFixedLineControl
4379 // ----------------------------------------------------
UnoFixedLineControl(const Reference<XMultiServiceFactory> & i_factory)4380 UnoFixedLineControl::UnoFixedLineControl( const Reference< XMultiServiceFactory >& i_factory )
4381 :UnoControlBase( i_factory )
4382 {
4383 maComponentInfos.nWidth = 100; // ??
4384 maComponentInfos.nHeight = 100; // ??
4385 }
4386
GetComponentServiceName()4387 ::rtl::OUString UnoFixedLineControl::GetComponentServiceName()
4388 {
4389 return ::rtl::OUString::createFromAscii( "FixedLine" );
4390 }
4391
isTransparent()4392 sal_Bool UnoFixedLineControl::isTransparent()
4393 {
4394 return sal_True;
4395 }
4396