1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_toolkit.hxx" 30 #include <com/sun/star/awt/XTextArea.hpp> 31 #include <com/sun/star/awt/XVclWindowPeer.hpp> 32 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 33 #include <com/sun/star/awt/PosSize.hpp> 34 #include <com/sun/star/awt/VisualEffect.hpp> 35 #include <com/sun/star/awt/LineEndFormat.hpp> 36 #include <com/sun/star/graphic/XGraphicProvider.hpp> 37 #include <com/sun/star/graphic/GraphicObject.hpp> 38 #include <com/sun/star/util/Date.hpp> 39 #include <com/sun/star/awt/ImageScaleMode.hpp> 40 41 42 #include <toolkit/controls/formattedcontrol.hxx> 43 #include <toolkit/controls/roadmapcontrol.hxx> 44 #include <toolkit/controls/unocontrols.hxx> 45 #include <toolkit/controls/stdtabcontroller.hxx> 46 #include <toolkit/helper/property.hxx> 47 #include <toolkit/helper/unopropertyarrayhelper.hxx> 48 #include <toolkit/helper/unomemorystream.hxx> 49 #include <toolkit/helper/servicenames.hxx> 50 #include <toolkit/helper/macros.hxx> 51 #include <toolkit/helper/imagealign.hxx> 52 53 // for introspection 54 #include <toolkit/awt/vclxwindows.hxx> 55 #include <cppuhelper/typeprovider.hxx> 56 #include <comphelper/componentcontext.hxx> 57 #include <comphelper/processfactory.hxx> 58 #include <comphelper/extract.hxx> 59 #include <vcl/wrkwin.hxx> 60 #include <vcl/svapp.hxx> 61 #include <vcl/edit.hxx> 62 #ifndef _SV_BUTTON_HXX 63 #include <vcl/button.hxx> 64 #endif 65 #include <vcl/group.hxx> 66 #include <vcl/fixed.hxx> 67 #include <vcl/lstbox.hxx> 68 #include <vcl/combobox.hxx> 69 #include <tools/debug.hxx> 70 #include <tools/diagnose_ex.h> 71 #include <tools/date.hxx> 72 #include <tools/time.hxx> 73 74 #include <algorithm> 75 #include <functional> 76 77 using namespace ::com::sun::star; 78 using ::com::sun::star::graphic::XGraphic; 79 using ::com::sun::star::uno::Reference; 80 using namespace ::toolkit; 81 82 #define IMPL_SERVICEINFO_DERIVED( ImplName, BaseClass, ServiceName ) \ 83 ::rtl::OUString SAL_CALL ImplName::getImplementationName( ) throw(::com::sun::star::uno::RuntimeException) { return ::rtl::OUString::createFromAscii( "stardiv.Toolkit." #ImplName ); } \ 84 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL ImplName::getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException) \ 85 { \ 86 ::com::sun::star::uno::Sequence< ::rtl::OUString > aNames = BaseClass::getSupportedServiceNames( ); \ 87 aNames.realloc( aNames.getLength() + 1 ); \ 88 aNames[ aNames.getLength() - 1 ] = ::rtl::OUString::createFromAscii( ServiceName ); \ 89 return aNames; \ 90 } \ 91 92 93 94 // ---------------------------------------------------- 95 // class UnoControlEditModel 96 // ---------------------------------------------------- 97 UnoControlEditModel::UnoControlEditModel( const Reference< XMultiServiceFactory >& i_factory ) 98 :UnoControlModel( i_factory ) 99 { 100 UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXEdit ); 101 } 102 103 ::rtl::OUString UnoControlEditModel::getServiceName( ) throw(::com::sun::star::uno::RuntimeException) 104 { 105 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlEditModel ); 106 } 107 108 uno::Any UnoControlEditModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const 109 { 110 uno::Any aReturn; 111 112 switch ( nPropId ) 113 { 114 case BASEPROPERTY_LINE_END_FORMAT: 115 aReturn <<= (sal_Int16)awt::LineEndFormat::LINE_FEED; // LF 116 break; 117 case BASEPROPERTY_DEFAULTCONTROL: 118 aReturn <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlEdit ); 119 break; 120 default: 121 aReturn = UnoControlModel::ImplGetDefaultValue( nPropId ); 122 break; 123 } 124 return aReturn; 125 } 126 127 ::cppu::IPropertyArrayHelper& UnoControlEditModel::getInfoHelper() 128 { 129 static UnoPropertyArrayHelper* pHelper = NULL; 130 if ( !pHelper ) 131 { 132 uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); 133 pHelper = new UnoPropertyArrayHelper( aIDs ); 134 } 135 return *pHelper; 136 } 137 138 // beans::XMultiPropertySet 139 uno::Reference< beans::XPropertySetInfo > UnoControlEditModel::getPropertySetInfo( ) throw(uno::RuntimeException) 140 { 141 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); 142 return xInfo; 143 } 144 145 146 // ---------------------------------------------------- 147 // class UnoEditControl 148 // ---------------------------------------------------- 149 UnoEditControl::UnoEditControl( const Reference< XMultiServiceFactory >& i_factory ) 150 :UnoControlBase( i_factory ) 151 ,maTextListeners( *this ) 152 ,mnMaxTextLen( 0 ) 153 ,mbSetTextInPeer( sal_False ) 154 ,mbSetMaxTextLenInPeer( sal_False ) 155 ,mbHasTextProperty( sal_False ) 156 { 157 maComponentInfos.nWidth = 100; 158 maComponentInfos.nHeight = 12; 159 mnMaxTextLen = 0; 160 mbSetMaxTextLenInPeer = sal_False; 161 } 162 163 uno::Any SAL_CALL UnoEditControl::queryAggregation( const uno::Type & rType ) throw(uno::RuntimeException) 164 { 165 uno::Any aReturn = UnoControlBase::queryAggregation( rType ); 166 if ( !aReturn.hasValue() ) 167 aReturn = UnoEditControl_Base::queryInterface( rType ); 168 return aReturn; 169 } 170 171 uno::Any SAL_CALL UnoEditControl::queryInterface( const uno::Type & rType ) throw(uno::RuntimeException) 172 { 173 return UnoControlBase::queryInterface( rType ); 174 } 175 176 void SAL_CALL UnoEditControl::acquire( ) throw () 177 { 178 UnoControlBase::acquire(); 179 } 180 181 void SAL_CALL UnoEditControl::release( ) throw () 182 { 183 UnoControlBase::release(); 184 } 185 186 IMPLEMENT_FORWARD_XTYPEPROVIDER2( UnoEditControl, UnoControlBase, UnoEditControl_Base ) 187 188 ::rtl::OUString UnoEditControl::GetComponentServiceName() 189 { 190 // by default, we want a simple edit field 191 ::rtl::OUString sName( ::rtl::OUString::createFromAscii( "Edit" ) ); 192 193 // but maybe we are to display multi-line text? 194 uno::Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_MULTILINE ) ); 195 sal_Bool b = sal_Bool(); 196 if ( ( aVal >>= b ) && b ) 197 sName= ::rtl::OUString::createFromAscii( "MultiLineEdit" ); 198 199 return sName; 200 } 201 202 sal_Bool SAL_CALL UnoEditControl::setModel(const uno::Reference< awt::XControlModel >& _rModel) throw ( uno::RuntimeException ) 203 { 204 sal_Bool bReturn = UnoControlBase::setModel( _rModel ); 205 mbHasTextProperty = ImplHasProperty( BASEPROPERTY_TEXT ); 206 return bReturn; 207 } 208 209 void UnoEditControl::ImplSetPeerProperty( const ::rtl::OUString& rPropName, const uno::Any& rVal ) 210 { 211 sal_Bool bDone = sal_False; 212 if ( GetPropertyId( rPropName ) == BASEPROPERTY_TEXT ) 213 { 214 // #96986# use setText(), or text listener will not be called. 215 uno::Reference < awt::XTextComponent > xTextComponent( getPeer(), uno::UNO_QUERY ); 216 if ( xTextComponent.is() ) 217 { 218 ::rtl::OUString sText; 219 rVal >>= sText; 220 ImplCheckLocalize( sText ); 221 xTextComponent->setText( sText ); 222 bDone = sal_True; 223 } 224 } 225 226 if ( !bDone ) 227 UnoControlBase::ImplSetPeerProperty( rPropName, rVal ); 228 } 229 230 void UnoEditControl::dispose() throw(uno::RuntimeException) 231 { 232 lang::EventObject aEvt( *this ); 233 maTextListeners.disposeAndClear( aEvt ); 234 UnoControl::dispose(); 235 } 236 237 void UnoEditControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer ) throw(uno::RuntimeException) 238 { 239 UnoControl::createPeer( rxToolkit, rParentPeer ); 240 241 uno::Reference< awt::XTextComponent > xText( getPeer(), uno::UNO_QUERY ); 242 if ( xText.is() ) 243 { 244 xText->addTextListener( this ); 245 246 if ( mbSetMaxTextLenInPeer ) 247 xText->setMaxTextLen( mnMaxTextLen ); 248 if ( mbSetTextInPeer ) 249 xText->setText( maText ); 250 } 251 } 252 253 void UnoEditControl::textChanged(const awt::TextEvent& e) throw(uno::RuntimeException) 254 { 255 uno::Reference< awt::XTextComponent > xText( getPeer(), uno::UNO_QUERY ); 256 257 if ( mbHasTextProperty ) 258 { 259 uno::Any aAny; 260 aAny <<= xText->getText(); 261 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_TEXT ), aAny, sal_False ); 262 } 263 else 264 { 265 maText = xText->getText(); 266 } 267 268 if ( maTextListeners.getLength() ) 269 maTextListeners.textChanged( e ); 270 } 271 272 void UnoEditControl::addTextListener(const uno::Reference< awt::XTextListener > & l) throw(uno::RuntimeException) 273 { 274 maTextListeners.addInterface( l ); 275 } 276 277 void UnoEditControl::removeTextListener(const uno::Reference< awt::XTextListener > & l) throw(uno::RuntimeException) 278 { 279 maTextListeners.removeInterface( l ); 280 } 281 282 void UnoEditControl::setText( const ::rtl::OUString& aText ) throw(uno::RuntimeException) 283 { 284 if ( mbHasTextProperty ) 285 { 286 uno::Any aAny; 287 aAny <<= aText; 288 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_TEXT ), aAny, sal_True ); 289 } 290 else 291 { 292 maText = aText; 293 mbSetTextInPeer = sal_True; 294 uno::Reference < awt::XTextComponent > xText( getPeer(), uno::UNO_QUERY ); 295 if ( xText.is() ) 296 xText->setText( maText ); 297 } 298 299 // Setting the property to the VCLXWindow doesn't call textChanged 300 if ( maTextListeners.getLength() ) 301 { 302 awt::TextEvent aEvent; 303 aEvent.Source = *this; 304 maTextListeners.textChanged( aEvent ); 305 } 306 } 307 308 namespace 309 { 310 static void lcl_normalize( awt::Selection& _rSel ) 311 { 312 if ( _rSel.Min > _rSel.Max ) 313 ::std::swap( _rSel.Min, _rSel.Max ); 314 } 315 316 /* 317 static bool lcl_intersect( const awt::Selection& _rLHS, const awt::Selection& _rRHS ) 318 { 319 OSL_PRECOND( _rLHS.Min <= _rLHS.Max, "lcl_intersect: LHS to be normalized!" ); 320 OSL_PRECOND( _rRHS.Min <= _rRHS.Max, "lcl_intersect: RHS to be normalized!" ); 321 return !( ( _rLHS.Max < _rRHS.Min ) || ( _rLHS.Min > _rRHS.Max ) ); 322 } 323 */ 324 } 325 326 void UnoEditControl::insertText( const awt::Selection& rSel, const ::rtl::OUString& rNewText ) throw(uno::RuntimeException) 327 { 328 // normalize the selection - OUString::replaceAt has a strange behaviour if the min is greater than the max 329 awt::Selection aSelection( rSel ); 330 lcl_normalize( aSelection ); 331 332 // preserve the selection resp. cursor position 333 awt::Selection aNewSelection( getSelection() ); 334 #ifdef ALSO_PRESERVE_COMPLETE_SELECTION 335 // (not sure - looks uglier ...) 336 sal_Int32 nDeletedCharacters = ( aSelection.Max - aSelection.Min ) - rNewText.getLength(); 337 if ( aNewSelection.Min > aSelection.Min ) 338 aNewSelection.Min -= nDeletedCharacters; 339 if ( aNewSelection.Max > aSelection.Max ) 340 aNewSelection.Max -= nDeletedCharacters; 341 #else 342 aNewSelection.Max = ::std::min( aNewSelection.Min, aNewSelection.Max ) + rNewText.getLength(); 343 aNewSelection.Min = aNewSelection.Max; 344 #endif 345 346 ::rtl::OUString aOldText = getText(); 347 ::rtl::OUString aNewText = aOldText.replaceAt( aSelection.Min, aSelection.Max - aSelection.Min, rNewText ); 348 setText( aNewText ); 349 350 setSelection( aNewSelection ); 351 } 352 353 ::rtl::OUString UnoEditControl::getText() throw(uno::RuntimeException) 354 { 355 ::rtl::OUString aText = maText; 356 357 if ( mbHasTextProperty ) 358 aText = ImplGetPropertyValue_UString( BASEPROPERTY_TEXT ); 359 else 360 { 361 uno::Reference< awt::XTextComponent > xText( getPeer(), uno::UNO_QUERY ); 362 if ( xText.is() ) 363 aText = xText->getText(); 364 } 365 366 return aText; 367 } 368 369 ::rtl::OUString UnoEditControl::getSelectedText( void ) throw(uno::RuntimeException) 370 { 371 ::rtl::OUString sSelected; 372 uno::Reference< awt::XTextComponent > xText( getPeer(), uno::UNO_QUERY ); 373 if ( xText.is() ) 374 sSelected = xText->getSelectedText(); 375 376 return sSelected; 377 } 378 379 void UnoEditControl::setSelection( const awt::Selection& aSelection ) throw(uno::RuntimeException) 380 { 381 uno::Reference< awt::XTextComponent > xText( getPeer(), uno::UNO_QUERY ); 382 if ( xText.is() ) 383 xText->setSelection( aSelection ); 384 } 385 386 awt::Selection UnoEditControl::getSelection( void ) throw(uno::RuntimeException) 387 { 388 awt::Selection aSel; 389 uno::Reference< awt::XTextComponent > xText( getPeer(), uno::UNO_QUERY ); 390 if ( xText.is() ) 391 aSel = xText->getSelection(); 392 return aSel; 393 } 394 395 sal_Bool UnoEditControl::isEditable( void ) throw(uno::RuntimeException) 396 { 397 return !ImplGetPropertyValue_BOOL( BASEPROPERTY_READONLY ); 398 } 399 400 void UnoEditControl::setEditable( sal_Bool bEditable ) throw(uno::RuntimeException) 401 { 402 uno::Any aAny; 403 aAny <<= (sal_Bool)!bEditable; 404 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_READONLY ), aAny, sal_True ); 405 } 406 407 sal_Int16 UnoEditControl::getMaxTextLen() throw(uno::RuntimeException) 408 { 409 sal_Int16 nMaxLen = mnMaxTextLen; 410 411 if ( ImplHasProperty( BASEPROPERTY_MAXTEXTLEN ) ) 412 nMaxLen = ImplGetPropertyValue_INT16( BASEPROPERTY_MAXTEXTLEN ); 413 414 return nMaxLen; 415 } 416 417 void UnoEditControl::setMaxTextLen( sal_Int16 nLen ) throw(uno::RuntimeException) 418 { 419 if ( ImplHasProperty( BASEPROPERTY_MAXTEXTLEN) ) 420 { 421 uno::Any aAny; 422 aAny <<= (sal_Int16)nLen; 423 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_MAXTEXTLEN ), aAny, sal_True ); 424 } 425 else 426 { 427 mnMaxTextLen = nLen; 428 mbSetMaxTextLenInPeer = sal_True; 429 uno::Reference < awt::XTextComponent > xText( getPeer(), uno::UNO_QUERY ); 430 if ( xText.is() ) 431 xText->setMaxTextLen( mnMaxTextLen ); 432 } 433 } 434 435 awt::Size UnoEditControl::getMinimumSize( ) throw(uno::RuntimeException) 436 { 437 return Impl_getMinimumSize(); 438 } 439 440 awt::Size UnoEditControl::getPreferredSize( ) throw(uno::RuntimeException) 441 { 442 return Impl_getPreferredSize(); 443 } 444 445 awt::Size UnoEditControl::calcAdjustedSize( const awt::Size& rNewSize ) throw(uno::RuntimeException) 446 { 447 return Impl_calcAdjustedSize( rNewSize ); 448 } 449 450 awt::Size UnoEditControl::getMinimumSize( sal_Int16 nCols, sal_Int16 nLines ) throw(uno::RuntimeException) 451 { 452 return Impl_getMinimumSize( nCols, nLines ); 453 } 454 455 void UnoEditControl::getColumnsAndLines( sal_Int16& nCols, sal_Int16& nLines ) throw(uno::RuntimeException) 456 { 457 Impl_getColumnsAndLines( nCols, nLines ); 458 } 459 460 461 // ---------------------------------------------------- 462 // class UnoControlFileControlModel 463 // ---------------------------------------------------- 464 UnoControlFileControlModel::UnoControlFileControlModel( const Reference< XMultiServiceFactory >& i_factory ) 465 :UnoControlModel( i_factory ) 466 { 467 ImplRegisterProperty( BASEPROPERTY_ALIGN ); 468 ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR ); 469 ImplRegisterProperty( BASEPROPERTY_BORDER ); 470 ImplRegisterProperty( BASEPROPERTY_BORDERCOLOR ); 471 ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL ); 472 ImplRegisterProperty( BASEPROPERTY_ENABLED ); 473 ImplRegisterProperty( BASEPROPERTY_ENABLEVISIBLE ); 474 ImplRegisterProperty( BASEPROPERTY_FONTDESCRIPTOR ); 475 ImplRegisterProperty( BASEPROPERTY_HELPTEXT ); 476 ImplRegisterProperty( BASEPROPERTY_HELPURL ); 477 ImplRegisterProperty( BASEPROPERTY_PRINTABLE ); 478 ImplRegisterProperty( BASEPROPERTY_READONLY ); 479 ImplRegisterProperty( BASEPROPERTY_TABSTOP ); 480 ImplRegisterProperty( BASEPROPERTY_TEXT ); 481 ImplRegisterProperty( BASEPROPERTY_VERTICALALIGN ); 482 ImplRegisterProperty( BASEPROPERTY_WRITING_MODE ); 483 ImplRegisterProperty( BASEPROPERTY_CONTEXT_WRITING_MODE ); 484 ImplRegisterProperty( BASEPROPERTY_HIDEINACTIVESELECTION ); 485 } 486 487 ::rtl::OUString UnoControlFileControlModel::getServiceName() throw(::com::sun::star::uno::RuntimeException) 488 { 489 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlFileControlModel ); 490 } 491 492 uno::Any UnoControlFileControlModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const 493 { 494 if ( nPropId == BASEPROPERTY_DEFAULTCONTROL ) 495 { 496 uno::Any aAny; 497 aAny <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlFileControl ); 498 return aAny; 499 } 500 return UnoControlModel::ImplGetDefaultValue( nPropId ); 501 } 502 503 ::cppu::IPropertyArrayHelper& UnoControlFileControlModel::getInfoHelper() 504 { 505 static UnoPropertyArrayHelper* pHelper = NULL; 506 if ( !pHelper ) 507 { 508 uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); 509 pHelper = new UnoPropertyArrayHelper( aIDs ); 510 } 511 return *pHelper; 512 } 513 514 // beans::XMultiPropertySet 515 uno::Reference< beans::XPropertySetInfo > UnoControlFileControlModel::getPropertySetInfo( ) throw(uno::RuntimeException) 516 { 517 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); 518 return xInfo; 519 } 520 521 // ---------------------------------------------------- 522 // class UnoFileControl 523 // ---------------------------------------------------- 524 UnoFileControl::UnoFileControl( const Reference< XMultiServiceFactory >& i_factory ) 525 :UnoEditControl( i_factory ) 526 { 527 } 528 529 ::rtl::OUString UnoFileControl::GetComponentServiceName() 530 { 531 return ::rtl::OUString::createFromAscii( "filecontrol" ); 532 } 533 534 // ---------------------------------------------------- 535 // class GraphicControlModel 536 // ---------------------------------------------------- 537 uno::Any GraphicControlModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const 538 { 539 if ( nPropId == BASEPROPERTY_GRAPHIC ) 540 return uno::makeAny( uno::Reference< graphic::XGraphic >() ); 541 542 return UnoControlModel::ImplGetDefaultValue( nPropId ); 543 } 544 uno::Reference< graphic::XGraphic > GraphicControlModel::getGraphicFromURL_nothrow( const ::rtl::OUString& _rURL ) 545 { 546 uno::Reference< graphic::XGraphic > xGraphic; 547 548 if( ( _rURL.compareToAscii( UNO_NAME_GRAPHOBJ_URLPREFIX, RTL_CONSTASCII_LENGTH( UNO_NAME_GRAPHOBJ_URLPREFIX ) ) == 0 ) ) 549 { 550 // graphic manager uniqueid 551 rtl::OUString sID = _rURL.copy( sizeof( UNO_NAME_GRAPHOBJ_URLPREFIX ) - 1 ); 552 // get the DefaultContext 553 mxGrfObj = graphic::GraphicObject::createWithId( maContext.getUNOContext(), sID ); 554 } 555 else // linked 556 mxGrfObj = NULL; // release the GraphicObject 557 558 if ( !_rURL.getLength() ) 559 return xGraphic; 560 561 try 562 { 563 uno::Reference< graphic::XGraphicProvider > xProvider; 564 if ( maContext.createComponent( "com.sun.star.graphic.GraphicProvider", xProvider ) ) 565 { 566 uno::Sequence< beans::PropertyValue > aMediaProperties(1); 567 aMediaProperties[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) ); 568 aMediaProperties[0].Value <<= _rURL; 569 xGraphic = xProvider->queryGraphic( aMediaProperties ); 570 } 571 } 572 catch( const Exception& ) 573 { 574 DBG_UNHANDLED_EXCEPTION(); 575 } 576 577 return xGraphic; 578 } 579 580 void SAL_CALL GraphicControlModel::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue ) throw (::com::sun::star::uno::Exception) 581 { 582 UnoControlModel::setFastPropertyValue_NoBroadcast( nHandle, rValue ); 583 584 // - ImageAlign and ImagePosition need to correspond to each other 585 // - Graphic and ImageURL need to correspond to each other 586 try 587 { 588 switch ( nHandle ) 589 { 590 case BASEPROPERTY_IMAGEURL: 591 if ( !mbAdjustingGraphic && ImplHasProperty( BASEPROPERTY_GRAPHIC ) ) 592 { 593 mbAdjustingGraphic = true; 594 ::rtl::OUString sImageURL; 595 OSL_VERIFY( rValue >>= sImageURL ); 596 setDependentFastPropertyValue( BASEPROPERTY_GRAPHIC, uno::makeAny( getGraphicFromURL_nothrow( sImageURL ) ) ); 597 mbAdjustingGraphic = false; 598 } 599 break; 600 601 case BASEPROPERTY_GRAPHIC: 602 if ( !mbAdjustingGraphic && ImplHasProperty( BASEPROPERTY_IMAGEURL ) ) 603 { 604 mbAdjustingGraphic = true; 605 setDependentFastPropertyValue( BASEPROPERTY_IMAGEURL, uno::makeAny( ::rtl::OUString() ) ); 606 mbAdjustingGraphic = false; 607 } 608 break; 609 610 case BASEPROPERTY_IMAGEALIGN: 611 if ( !mbAdjustingImagePosition && ImplHasProperty( BASEPROPERTY_IMAGEPOSITION ) ) 612 { 613 mbAdjustingImagePosition = true; 614 sal_Int16 nUNOValue = 0; 615 OSL_VERIFY( rValue >>= nUNOValue ); 616 setDependentFastPropertyValue( BASEPROPERTY_IMAGEPOSITION, uno::makeAny( getExtendedImagePosition( nUNOValue ) ) ); 617 mbAdjustingImagePosition = false; 618 } 619 break; 620 case BASEPROPERTY_IMAGEPOSITION: 621 if ( !mbAdjustingImagePosition && ImplHasProperty( BASEPROPERTY_IMAGEALIGN ) ) 622 { 623 mbAdjustingImagePosition = true; 624 sal_Int16 nUNOValue = 0; 625 OSL_VERIFY( rValue >>= nUNOValue ); 626 setDependentFastPropertyValue( BASEPROPERTY_IMAGEALIGN, uno::makeAny( getCompatibleImageAlign( translateImagePosition( nUNOValue ) ) ) ); 627 mbAdjustingImagePosition = false; 628 } 629 break; 630 } 631 } 632 catch( const ::com::sun::star::uno::Exception& ) 633 { 634 OSL_ENSURE( sal_False, "GraphicControlModel::setFastPropertyValue_NoBroadcast: caught an exception while aligning the ImagePosition/ImageAlign properties!" ); 635 mbAdjustingImagePosition = sal_False; 636 } 637 } 638 639 // ---------------------------------------------------- 640 // class UnoControlButtonModel 641 // ---------------------------------------------------- 642 UnoControlButtonModel::UnoControlButtonModel( const Reference< XMultiServiceFactory >& i_factory ) 643 :GraphicControlModel( i_factory ) 644 { 645 UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXButton ); 646 647 osl_incrementInterlockedCount( &m_refCount ); 648 { 649 setFastPropertyValue_NoBroadcast( BASEPROPERTY_IMAGEPOSITION, ImplGetDefaultValue( BASEPROPERTY_IMAGEPOSITION ) ); 650 // this ensures that our ImagePosition is consistent with our ImageAlign property (since both 651 // defaults are not per se consistent), since both are coupled in setFastPropertyValue_NoBroadcast 652 } 653 osl_decrementInterlockedCount( &m_refCount ); 654 } 655 656 ::rtl::OUString UnoControlButtonModel::getServiceName() throw(::com::sun::star::uno::RuntimeException) 657 { 658 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlButtonModel ); 659 } 660 661 uno::Any UnoControlButtonModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const 662 { 663 switch ( nPropId ) 664 { 665 case BASEPROPERTY_DEFAULTCONTROL: 666 return uno::makeAny( ::rtl::OUString::createFromAscii( szServiceName_UnoControlButton ) ); 667 case BASEPROPERTY_TOGGLE: 668 return uno::makeAny( (sal_Bool)sal_False ); 669 case BASEPROPERTY_ALIGN: 670 return uno::makeAny( (sal_Int16)PROPERTY_ALIGN_CENTER ); 671 case BASEPROPERTY_FOCUSONCLICK: 672 return uno::makeAny( (sal_Bool)sal_True ); 673 } 674 675 return GraphicControlModel::ImplGetDefaultValue( nPropId ); 676 } 677 678 ::cppu::IPropertyArrayHelper& UnoControlButtonModel::getInfoHelper() 679 { 680 static UnoPropertyArrayHelper* pHelper = NULL; 681 if ( !pHelper ) 682 { 683 uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); 684 pHelper = new UnoPropertyArrayHelper( aIDs ); 685 } 686 return *pHelper; 687 } 688 689 // beans::XMultiPropertySet 690 uno::Reference< beans::XPropertySetInfo > UnoControlButtonModel::getPropertySetInfo( ) throw(uno::RuntimeException) 691 { 692 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); 693 return xInfo; 694 } 695 696 // ---------------------------------------------------- 697 // class UnoButtonControl 698 // ---------------------------------------------------- 699 UnoButtonControl::UnoButtonControl( const uno::Reference< lang::XMultiServiceFactory >& i_factory ) 700 :UnoButtonControl_Base( i_factory ) 701 ,maActionListeners( *this ) 702 ,maItemListeners( *this ) 703 { 704 maComponentInfos.nWidth = 50; 705 maComponentInfos.nHeight = 14; 706 } 707 708 ::rtl::OUString UnoButtonControl::GetComponentServiceName() 709 { 710 ::rtl::OUString aName( ::rtl::OUString::createFromAscii( "pushbutton" ) ); 711 uno::Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_PUSHBUTTONTYPE ) ); 712 sal_Int16 n = sal_Int16(); 713 if ( ( aVal >>= n ) && n ) 714 { 715 // Use PushButtonType later when available... 716 switch ( n ) 717 { 718 case 1 /*PushButtonType::OK*/: aName= ::rtl::OUString::createFromAscii( "okbutton" ); 719 break; 720 case 2 /*PushButtonType::CANCEL*/: aName= ::rtl::OUString::createFromAscii( "cancelbutton" ); 721 break; 722 case 3 /*PushButtonType::HELP*/: aName= ::rtl::OUString::createFromAscii( "helpbutton" ); 723 break; 724 default: 725 { 726 DBG_ERROR( "Unknown Button Type!" ); 727 } 728 } 729 } 730 return aName; 731 } 732 733 void UnoButtonControl::dispose() throw(uno::RuntimeException) 734 { 735 lang::EventObject aEvt; 736 aEvt.Source = (::cppu::OWeakObject*)this; 737 maActionListeners.disposeAndClear( aEvt ); 738 maItemListeners.disposeAndClear( aEvt ); 739 UnoControlBase::dispose(); 740 } 741 742 void UnoButtonControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer ) throw(uno::RuntimeException) 743 { 744 UnoControlBase::createPeer( rxToolkit, rParentPeer ); 745 746 uno::Reference < awt::XButton > xButton( getPeer(), uno::UNO_QUERY ); 747 xButton->setActionCommand( maActionCommand ); 748 if ( maActionListeners.getLength() ) 749 xButton->addActionListener( &maActionListeners ); 750 751 uno::Reference< XToggleButton > xPushButton( getPeer(), uno::UNO_QUERY ); 752 if ( xPushButton.is() ) 753 xPushButton->addItemListener( this ); 754 } 755 756 void UnoButtonControl::addActionListener(const uno::Reference< awt::XActionListener > & l) throw(uno::RuntimeException) 757 { 758 maActionListeners.addInterface( l ); 759 if( getPeer().is() && maActionListeners.getLength() == 1 ) 760 { 761 uno::Reference < awt::XButton > xButton( getPeer(), uno::UNO_QUERY ); 762 xButton->addActionListener( &maActionListeners ); 763 } 764 } 765 766 void UnoButtonControl::removeActionListener(const uno::Reference< awt::XActionListener > & l) throw(uno::RuntimeException) 767 { 768 if( getPeer().is() && maActionListeners.getLength() == 1 ) 769 { 770 uno::Reference < awt::XButton > xButton( getPeer(), uno::UNO_QUERY ); 771 xButton->removeActionListener( &maActionListeners ); 772 } 773 maActionListeners.removeInterface( l ); 774 } 775 776 void UnoButtonControl::addItemListener(const uno::Reference< awt::XItemListener > & l) throw(uno::RuntimeException) 777 { 778 maItemListeners.addInterface( l ); 779 } 780 781 void UnoButtonControl::removeItemListener(const uno::Reference< awt::XItemListener > & l) throw(uno::RuntimeException) 782 { 783 maItemListeners.removeInterface( l ); 784 } 785 786 void SAL_CALL UnoButtonControl::disposing( const lang::EventObject& Source ) throw (uno::RuntimeException) 787 { 788 UnoControlBase::disposing( Source ); 789 } 790 791 void SAL_CALL UnoButtonControl::itemStateChanged( const awt::ItemEvent& rEvent ) throw (uno::RuntimeException) 792 { 793 // forward to model 794 uno::Any aAny; 795 aAny <<= (sal_Int16)rEvent.Selected; 796 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_STATE ), aAny, sal_False ); 797 798 // multiplex 799 ItemEvent aEvent( rEvent ); 800 aEvent.Source = *this; 801 maItemListeners.itemStateChanged( aEvent ); 802 } 803 804 void UnoButtonControl::setLabel( const ::rtl::OUString& rLabel ) throw(uno::RuntimeException) 805 { 806 uno::Any aAny; 807 aAny <<= rLabel; 808 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_LABEL ), aAny, sal_True ); 809 } 810 811 void UnoButtonControl::setActionCommand( const ::rtl::OUString& rCommand ) throw(uno::RuntimeException) 812 { 813 maActionCommand = rCommand; 814 if ( getPeer().is() ) 815 { 816 uno::Reference < awt::XButton > xButton( getPeer(), uno::UNO_QUERY ); 817 xButton->setActionCommand( rCommand ); 818 } 819 } 820 821 awt::Size UnoButtonControl::getMinimumSize( ) throw(uno::RuntimeException) 822 { 823 return Impl_getMinimumSize(); 824 } 825 826 awt::Size UnoButtonControl::getPreferredSize( ) throw(uno::RuntimeException) 827 { 828 return Impl_getPreferredSize(); 829 } 830 831 awt::Size UnoButtonControl::calcAdjustedSize( const awt::Size& rNewSize ) throw(uno::RuntimeException) 832 { 833 return Impl_calcAdjustedSize( rNewSize ); 834 } 835 836 // ---------------------------------------------------- 837 // class UnoControlImageControlModel 838 // ---------------------------------------------------- 839 UnoControlImageControlModel::UnoControlImageControlModel( const Reference< XMultiServiceFactory >& i_factory ) 840 :GraphicControlModel( i_factory ) 841 ,mbAdjustingImageScaleMode( false ) 842 { 843 UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXImageControl ); 844 } 845 846 ::rtl::OUString UnoControlImageControlModel::getServiceName() throw(::com::sun::star::uno::RuntimeException) 847 { 848 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlImageControlModel ); 849 } 850 851 uno::Any UnoControlImageControlModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const 852 { 853 if ( nPropId == BASEPROPERTY_DEFAULTCONTROL ) 854 return uno::makeAny( ::rtl::OUString::createFromAscii( szServiceName_UnoControlImageControl ) ); 855 856 if ( nPropId == BASEPROPERTY_IMAGE_SCALE_MODE ) 857 return makeAny( awt::ImageScaleMode::Anisotropic ); 858 859 return GraphicControlModel::ImplGetDefaultValue( nPropId ); 860 } 861 862 ::cppu::IPropertyArrayHelper& UnoControlImageControlModel::getInfoHelper() 863 { 864 static UnoPropertyArrayHelper* pHelper = NULL; 865 if ( !pHelper ) 866 { 867 uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); 868 pHelper = new UnoPropertyArrayHelper( aIDs ); 869 } 870 return *pHelper; 871 } 872 873 // beans::XMultiPropertySet 874 uno::Reference< beans::XPropertySetInfo > UnoControlImageControlModel::getPropertySetInfo( ) throw(uno::RuntimeException) 875 { 876 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); 877 return xInfo; 878 } 879 880 void SAL_CALL UnoControlImageControlModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const ::com::sun::star::uno::Any& _rValue ) throw (::com::sun::star::uno::Exception) 881 { 882 GraphicControlModel::setFastPropertyValue_NoBroadcast( _nHandle, _rValue ); 883 884 // ScaleImage is an older (and less powerful) version of ScaleMode, but keep both in sync as far as possible 885 try 886 { 887 switch ( _nHandle ) 888 { 889 case BASEPROPERTY_IMAGE_SCALE_MODE: 890 if ( !mbAdjustingImageScaleMode && ImplHasProperty( BASEPROPERTY_SCALEIMAGE ) ) 891 { 892 mbAdjustingImageScaleMode = true; 893 sal_Int16 nScaleMode( awt::ImageScaleMode::Anisotropic ); 894 OSL_VERIFY( _rValue >>= nScaleMode ); 895 setDependentFastPropertyValue( BASEPROPERTY_SCALEIMAGE, uno::makeAny( sal_Bool( nScaleMode != awt::ImageScaleMode::None ) ) ); 896 mbAdjustingImageScaleMode = false; 897 } 898 break; 899 case BASEPROPERTY_SCALEIMAGE: 900 if ( !mbAdjustingImageScaleMode && ImplHasProperty( BASEPROPERTY_IMAGE_SCALE_MODE ) ) 901 { 902 mbAdjustingImageScaleMode = true; 903 sal_Bool bScale = sal_True; 904 OSL_VERIFY( _rValue >>= bScale ); 905 setDependentFastPropertyValue( BASEPROPERTY_IMAGE_SCALE_MODE, uno::makeAny( bScale ? awt::ImageScaleMode::Anisotropic : awt::ImageScaleMode::None ) ); 906 mbAdjustingImageScaleMode = false; 907 } 908 break; 909 } 910 } 911 catch( const Exception& ) 912 { 913 mbAdjustingImageScaleMode = false; 914 throw; 915 } 916 } 917 918 // ---------------------------------------------------- 919 // class UnoImageControlControl 920 // ---------------------------------------------------- 921 UnoImageControlControl::UnoImageControlControl( const Reference< XMultiServiceFactory >& i_factory ) 922 :UnoImageControlControl_Base( i_factory ) 923 ,maActionListeners( *this ) 924 { 925 // Woher die Defaults nehmen? 926 maComponentInfos.nWidth = 100; 927 maComponentInfos.nHeight = 100; 928 } 929 930 ::rtl::OUString UnoImageControlControl::GetComponentServiceName() 931 { 932 return ::rtl::OUString::createFromAscii( "fixedimage" ); 933 } 934 935 void UnoImageControlControl::dispose() throw(uno::RuntimeException) 936 { 937 lang::EventObject aEvt; 938 aEvt.Source = (::cppu::OWeakObject*)this; 939 maActionListeners.disposeAndClear( aEvt ); 940 UnoControl::dispose(); 941 } 942 943 sal_Bool UnoImageControlControl::isTransparent() throw(uno::RuntimeException) 944 { 945 return sal_True; 946 } 947 948 awt::Size UnoImageControlControl::getMinimumSize( ) throw(uno::RuntimeException) 949 { 950 return Impl_getMinimumSize(); 951 } 952 953 awt::Size UnoImageControlControl::getPreferredSize( ) throw(uno::RuntimeException) 954 { 955 return Impl_getPreferredSize(); 956 } 957 958 awt::Size UnoImageControlControl::calcAdjustedSize( const awt::Size& rNewSize ) throw(uno::RuntimeException) 959 { 960 return Impl_calcAdjustedSize( rNewSize ); 961 } 962 963 // ---------------------------------------------------- 964 // class UnoControlRadioButtonModel 965 // ---------------------------------------------------- 966 UnoControlRadioButtonModel::UnoControlRadioButtonModel( const Reference< XMultiServiceFactory >& i_factory ) 967 :GraphicControlModel( i_factory ) 968 { 969 UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXRadioButton ); 970 } 971 972 ::rtl::OUString UnoControlRadioButtonModel::getServiceName() throw(::com::sun::star::uno::RuntimeException) 973 { 974 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlRadioButtonModel ); 975 } 976 977 uno::Any UnoControlRadioButtonModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const 978 { 979 switch ( nPropId ) 980 { 981 case BASEPROPERTY_DEFAULTCONTROL: 982 return uno::makeAny( ::rtl::OUString::createFromAscii( szServiceName_UnoControlRadioButton ) ); 983 984 case BASEPROPERTY_VISUALEFFECT: 985 return uno::makeAny( (sal_Int16)awt::VisualEffect::LOOK3D ); 986 } 987 988 return GraphicControlModel::ImplGetDefaultValue( nPropId ); 989 } 990 991 ::cppu::IPropertyArrayHelper& UnoControlRadioButtonModel::getInfoHelper() 992 { 993 static UnoPropertyArrayHelper* pHelper = NULL; 994 if ( !pHelper ) 995 { 996 uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); 997 pHelper = new UnoPropertyArrayHelper( aIDs ); 998 } 999 return *pHelper; 1000 } 1001 1002 // beans::XMultiPropertySet 1003 uno::Reference< beans::XPropertySetInfo > UnoControlRadioButtonModel::getPropertySetInfo( ) throw(uno::RuntimeException) 1004 { 1005 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); 1006 return xInfo; 1007 } 1008 1009 1010 1011 // ---------------------------------------------------- 1012 // class UnoRadioButtonControl 1013 // ---------------------------------------------------- 1014 UnoRadioButtonControl::UnoRadioButtonControl( const Reference< XMultiServiceFactory >& i_factory ) 1015 :UnoRadioButtonControl_Base( i_factory ) 1016 ,maItemListeners( *this ) 1017 ,maActionListeners( *this ) 1018 { 1019 maComponentInfos.nWidth = 100; 1020 maComponentInfos.nHeight = 12; 1021 } 1022 1023 ::rtl::OUString UnoRadioButtonControl::GetComponentServiceName() 1024 { 1025 return ::rtl::OUString::createFromAscii( "radiobutton" ); 1026 } 1027 1028 void UnoRadioButtonControl::dispose() throw(uno::RuntimeException) 1029 { 1030 lang::EventObject aEvt; 1031 aEvt.Source = (::cppu::OWeakObject*)this; 1032 maItemListeners.disposeAndClear( aEvt ); 1033 UnoControlBase::dispose(); 1034 } 1035 1036 1037 sal_Bool UnoRadioButtonControl::isTransparent() throw(uno::RuntimeException) 1038 { 1039 return sal_True; 1040 } 1041 1042 void UnoRadioButtonControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer ) throw(uno::RuntimeException) 1043 { 1044 UnoControlBase::createPeer( rxToolkit, rParentPeer ); 1045 1046 uno::Reference < awt::XRadioButton > xRadioButton( getPeer(), uno::UNO_QUERY ); 1047 xRadioButton->addItemListener( this ); 1048 1049 uno::Reference < awt::XButton > xButton( getPeer(), uno::UNO_QUERY ); 1050 xButton->setActionCommand( maActionCommand ); 1051 if ( maActionListeners.getLength() ) 1052 xButton->addActionListener( &maActionListeners ); 1053 1054 // as default, set the "AutoToggle" to true 1055 // (it is set to false in VCLXToolkit::ImplCreateWindow because of #87254#, but we want to 1056 // have it enabled by default because of 85071) 1057 uno::Reference< awt::XVclWindowPeer > xVclWindowPeer( getPeer(), uno::UNO_QUERY ); 1058 if ( xVclWindowPeer.is() ) 1059 xVclWindowPeer->setProperty( GetPropertyName( BASEPROPERTY_AUTOTOGGLE ), ::cppu::bool2any( sal_True ) ); 1060 } 1061 1062 void UnoRadioButtonControl::addItemListener(const uno::Reference < awt::XItemListener > & l) throw(uno::RuntimeException) 1063 { 1064 maItemListeners.addInterface( l ); 1065 } 1066 1067 void UnoRadioButtonControl::removeItemListener(const uno::Reference < awt::XItemListener > & l) throw(uno::RuntimeException) 1068 { 1069 maItemListeners.removeInterface( l ); 1070 } 1071 1072 void UnoRadioButtonControl::addActionListener(const uno::Reference< awt::XActionListener > & l) throw(uno::RuntimeException) 1073 { 1074 maActionListeners.addInterface( l ); 1075 if( getPeer().is() && maActionListeners.getLength() == 1 ) 1076 { 1077 uno::Reference < awt::XButton > xButton( getPeer(), uno::UNO_QUERY ); 1078 xButton->addActionListener( &maActionListeners ); 1079 } 1080 } 1081 1082 void UnoRadioButtonControl::removeActionListener(const uno::Reference< awt::XActionListener > & l) throw(uno::RuntimeException) 1083 { 1084 if( getPeer().is() && maActionListeners.getLength() == 1 ) 1085 { 1086 uno::Reference < awt::XButton > xButton( getPeer(), uno::UNO_QUERY ); 1087 xButton->removeActionListener( &maActionListeners ); 1088 } 1089 maActionListeners.removeInterface( l ); 1090 } 1091 1092 void UnoRadioButtonControl::setLabel( const ::rtl::OUString& rLabel ) throw(uno::RuntimeException) 1093 { 1094 uno::Any aAny; 1095 aAny <<= rLabel; 1096 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_LABEL ), aAny, sal_True ); 1097 } 1098 1099 void UnoRadioButtonControl::setActionCommand( const ::rtl::OUString& rCommand ) throw(uno::RuntimeException) 1100 { 1101 maActionCommand = rCommand; 1102 if ( getPeer().is() ) 1103 { 1104 uno::Reference < awt::XButton > xButton( getPeer(), uno::UNO_QUERY ); 1105 xButton->setActionCommand( rCommand ); 1106 } 1107 } 1108 1109 void UnoRadioButtonControl::setState( sal_Bool bOn ) throw(uno::RuntimeException) 1110 { 1111 sal_Int16 nState = bOn ? 1 : 0; 1112 uno::Any aAny; 1113 aAny <<= nState; 1114 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_STATE ), aAny, sal_True ); 1115 } 1116 1117 sal_Bool UnoRadioButtonControl::getState() throw(uno::RuntimeException) 1118 { 1119 sal_Int16 nState = 0; 1120 uno::Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_STATE ) ); 1121 aVal >>= nState; 1122 return nState ? sal_True : sal_False; 1123 } 1124 1125 void UnoRadioButtonControl::itemStateChanged( const awt::ItemEvent& rEvent ) throw(uno::RuntimeException) 1126 { 1127 uno::Any aAny; 1128 aAny <<= (sal_Int16)rEvent.Selected; 1129 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_STATE ), aAny, sal_False ); 1130 1131 // compatibility: 1132 // in OOo 1.0.x, when the user clicked a radio button in a group of buttons, this resulted 1133 // in _one_ itemStateChanged call for exactly the radio button which's state changed from 1134 // "0" to "1". 1135 // Nowadays, since the listener handling changed a lot towards 1.1 (the VCLXWindow reacts on more 1136 // basic events from the VCL-windows, not anymore on the Link-based events like in 1.0.x), this 1137 // isn't the case anymore: For instance, this method here gets called for the radio button 1138 // which is being implicitily _de_selected, too. This is pretty bad for compatibility. 1139 // Thus, we suppress all events with a new state other than "1". This is unlogical, and weird, when looking 1140 // from a pure API perspective, but it's _compatible_ with older product versions, and this is 1141 // all which matters here. 1142 // #i14703# - 2003-05-23 - fs@openoffice.org 1143 if ( 1 == rEvent.Selected ) 1144 { 1145 if ( maItemListeners.getLength() ) 1146 maItemListeners.itemStateChanged( rEvent ); 1147 } 1148 // note that speaking stricly, this is wrong: When in 1.0.x, the user would have de-selected 1149 // a radio button _without_ selecing another one, this would have caused a notification. 1150 // With the change done here, this today won't cause a notification anymore. 1151 // 1152 // Fortunately, it's not possible for the user to de-select a radio button without selecting another on, 1153 // at least not via the regular UI. It _would_ be possible via the Accessibility API, which 1154 // counts as "user input", too. But in 1.0.x, there was no Accessibility API, so there is nothing 1155 // to be inconsistent with. 1156 } 1157 1158 awt::Size UnoRadioButtonControl::getMinimumSize( ) throw(uno::RuntimeException) 1159 { 1160 return Impl_getMinimumSize(); 1161 } 1162 1163 awt::Size UnoRadioButtonControl::getPreferredSize( ) throw(uno::RuntimeException) 1164 { 1165 return Impl_getPreferredSize(); 1166 } 1167 1168 awt::Size UnoRadioButtonControl::calcAdjustedSize( const awt::Size& rNewSize ) throw(uno::RuntimeException) 1169 { 1170 return Impl_calcAdjustedSize( rNewSize ); 1171 } 1172 1173 // ---------------------------------------------------- 1174 // class UnoControlCheckBoxModel 1175 // ---------------------------------------------------- 1176 UnoControlCheckBoxModel::UnoControlCheckBoxModel( const Reference< XMultiServiceFactory >& i_factory ) 1177 :GraphicControlModel( i_factory ) 1178 { 1179 UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXCheckBox ); 1180 } 1181 1182 ::rtl::OUString UnoControlCheckBoxModel::getServiceName() throw(::com::sun::star::uno::RuntimeException) 1183 { 1184 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlCheckBoxModel ); 1185 } 1186 1187 uno::Any UnoControlCheckBoxModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const 1188 { 1189 switch ( nPropId ) 1190 { 1191 case BASEPROPERTY_DEFAULTCONTROL: 1192 return uno::makeAny( ::rtl::OUString::createFromAscii( szServiceName_UnoControlCheckBox ) ); 1193 1194 case BASEPROPERTY_VISUALEFFECT: 1195 return uno::makeAny( (sal_Int16)awt::VisualEffect::LOOK3D ); 1196 } 1197 1198 return GraphicControlModel::ImplGetDefaultValue( nPropId ); 1199 } 1200 1201 ::cppu::IPropertyArrayHelper& UnoControlCheckBoxModel::getInfoHelper() 1202 { 1203 static UnoPropertyArrayHelper* pHelper = NULL; 1204 if ( !pHelper ) 1205 { 1206 uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); 1207 pHelper = new UnoPropertyArrayHelper( aIDs ); 1208 } 1209 return *pHelper; 1210 } 1211 1212 // beans::XMultiPropertySet 1213 uno::Reference< beans::XPropertySetInfo > UnoControlCheckBoxModel::getPropertySetInfo( ) throw(uno::RuntimeException) 1214 { 1215 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); 1216 return xInfo; 1217 } 1218 1219 1220 1221 // ---------------------------------------------------- 1222 // class UnoCheckBoxControl 1223 // ---------------------------------------------------- 1224 UnoCheckBoxControl::UnoCheckBoxControl( const uno::Reference< lang::XMultiServiceFactory >& i_factory ) 1225 :UnoCheckBoxControl_Base( i_factory ) 1226 ,maItemListeners( *this ), maActionListeners( *this ) 1227 { 1228 maComponentInfos.nWidth = 100; 1229 maComponentInfos.nHeight = 12; 1230 } 1231 1232 ::rtl::OUString UnoCheckBoxControl::GetComponentServiceName() 1233 { 1234 return ::rtl::OUString::createFromAscii( "checkbox" ); 1235 } 1236 1237 void UnoCheckBoxControl::dispose() throw(uno::RuntimeException) 1238 { 1239 lang::EventObject aEvt; 1240 aEvt.Source = (::cppu::OWeakObject*)this; 1241 maItemListeners.disposeAndClear( aEvt ); 1242 UnoControlBase::dispose(); 1243 } 1244 1245 sal_Bool UnoCheckBoxControl::isTransparent() throw(uno::RuntimeException) 1246 { 1247 return sal_True; 1248 } 1249 1250 void UnoCheckBoxControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer ) throw(uno::RuntimeException) 1251 { 1252 UnoControlBase::createPeer( rxToolkit, rParentPeer ); 1253 1254 uno::Reference < awt::XCheckBox > xCheckBox( getPeer(), uno::UNO_QUERY ); 1255 xCheckBox->addItemListener( this ); 1256 1257 uno::Reference < awt::XButton > xButton( getPeer(), uno::UNO_QUERY ); 1258 xButton->setActionCommand( maActionCommand ); 1259 if ( maActionListeners.getLength() ) 1260 xButton->addActionListener( &maActionListeners ); 1261 } 1262 1263 void UnoCheckBoxControl::addItemListener(const uno::Reference < awt::XItemListener > & l) throw(uno::RuntimeException) 1264 { 1265 maItemListeners.addInterface( l ); 1266 } 1267 1268 void UnoCheckBoxControl::removeItemListener(const uno::Reference < awt::XItemListener > & l) throw(uno::RuntimeException) 1269 { 1270 maItemListeners.removeInterface( l ); 1271 } 1272 1273 void UnoCheckBoxControl::addActionListener(const uno::Reference< awt::XActionListener > & l) throw(uno::RuntimeException) 1274 { 1275 maActionListeners.addInterface( l ); 1276 if( getPeer().is() && maActionListeners.getLength() == 1 ) 1277 { 1278 uno::Reference < awt::XButton > xButton( getPeer(), uno::UNO_QUERY ); 1279 xButton->addActionListener( &maActionListeners ); 1280 } 1281 } 1282 1283 void UnoCheckBoxControl::removeActionListener(const uno::Reference< awt::XActionListener > & l) throw(uno::RuntimeException) 1284 { 1285 if( getPeer().is() && maActionListeners.getLength() == 1 ) 1286 { 1287 uno::Reference < awt::XButton > xButton( getPeer(), uno::UNO_QUERY ); 1288 xButton->removeActionListener( &maActionListeners ); 1289 } 1290 maActionListeners.removeInterface( l ); 1291 } 1292 1293 void UnoCheckBoxControl::setActionCommand( const ::rtl::OUString& rCommand ) throw(uno::RuntimeException) 1294 { 1295 maActionCommand = rCommand; 1296 if ( getPeer().is() ) 1297 { 1298 uno::Reference < awt::XButton > xButton( getPeer(), uno::UNO_QUERY ); 1299 xButton->setActionCommand( rCommand ); 1300 } 1301 } 1302 1303 1304 void UnoCheckBoxControl::setLabel( const ::rtl::OUString& rLabel ) throw(uno::RuntimeException) 1305 { 1306 uno::Any aAny; 1307 aAny <<= rLabel; 1308 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_LABEL ), aAny, sal_True ); 1309 } 1310 1311 void UnoCheckBoxControl::setState( short n ) throw(uno::RuntimeException) 1312 { 1313 uno::Any aAny; 1314 aAny <<= (sal_Int16)n; 1315 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_STATE ), aAny, sal_True ); 1316 } 1317 1318 short UnoCheckBoxControl::getState() throw(uno::RuntimeException) 1319 { 1320 short nState = 0; 1321 uno::Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_STATE ) ); 1322 aVal >>= nState; 1323 return nState; 1324 } 1325 1326 void UnoCheckBoxControl::enableTriState( sal_Bool b ) throw(uno::RuntimeException) 1327 { 1328 uno::Any aAny; 1329 aAny <<= b; 1330 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_TRISTATE ), aAny, sal_True ); 1331 } 1332 1333 void UnoCheckBoxControl::itemStateChanged( const awt::ItemEvent& rEvent ) throw(uno::RuntimeException) 1334 { 1335 uno::Any aAny; 1336 aAny <<= (sal_Int16)rEvent.Selected; 1337 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_STATE ), aAny, sal_False ); 1338 1339 if ( maItemListeners.getLength() ) 1340 maItemListeners.itemStateChanged( rEvent ); 1341 } 1342 1343 awt::Size UnoCheckBoxControl::getMinimumSize( ) throw(uno::RuntimeException) 1344 { 1345 return Impl_getMinimumSize(); 1346 } 1347 1348 awt::Size UnoCheckBoxControl::getPreferredSize( ) throw(uno::RuntimeException) 1349 { 1350 return Impl_getPreferredSize(); 1351 } 1352 1353 awt::Size UnoCheckBoxControl::calcAdjustedSize( const awt::Size& rNewSize ) throw(uno::RuntimeException) 1354 { 1355 return Impl_calcAdjustedSize( rNewSize ); 1356 } 1357 1358 // ---------------------------------------------------- 1359 // class UnoControlFixedHyperlinkModel 1360 // ---------------------------------------------------- 1361 UnoControlFixedHyperlinkModel::UnoControlFixedHyperlinkModel( const Reference< XMultiServiceFactory >& i_factory ) 1362 :UnoControlModel( i_factory ) 1363 { 1364 UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXFixedHyperlink ); 1365 } 1366 1367 ::rtl::OUString UnoControlFixedHyperlinkModel::getServiceName() throw(::com::sun::star::uno::RuntimeException) 1368 { 1369 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlFixedHyperlinkModel ); 1370 } 1371 1372 uno::Any UnoControlFixedHyperlinkModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const 1373 { 1374 if ( nPropId == BASEPROPERTY_DEFAULTCONTROL ) 1375 { 1376 uno::Any aAny; 1377 aAny <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlFixedHyperlink ); 1378 return aAny; 1379 } 1380 else if ( nPropId == BASEPROPERTY_BORDER ) 1381 { 1382 uno::Any aAny; 1383 aAny <<= (sal_Int16)0; 1384 return aAny; 1385 } 1386 else if ( nPropId == BASEPROPERTY_URL ) 1387 { 1388 uno::Any aAny; 1389 aAny <<= ::rtl::OUString(); 1390 return aAny; 1391 } 1392 1393 return UnoControlModel::ImplGetDefaultValue( nPropId ); 1394 } 1395 1396 ::cppu::IPropertyArrayHelper& UnoControlFixedHyperlinkModel::getInfoHelper() 1397 { 1398 static UnoPropertyArrayHelper* pHelper = NULL; 1399 if ( !pHelper ) 1400 { 1401 uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); 1402 pHelper = new UnoPropertyArrayHelper( aIDs ); 1403 } 1404 return *pHelper; 1405 } 1406 1407 // beans::XMultiPropertySet 1408 uno::Reference< beans::XPropertySetInfo > UnoControlFixedHyperlinkModel::getPropertySetInfo( ) throw(uno::RuntimeException) 1409 { 1410 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); 1411 return xInfo; 1412 } 1413 1414 // ---------------------------------------------------- 1415 // class UnoFixedHyperlinkControl 1416 // ---------------------------------------------------- 1417 UnoFixedHyperlinkControl::UnoFixedHyperlinkControl( const Reference< XMultiServiceFactory >& i_factory ) 1418 :UnoControlBase( i_factory ) 1419 ,maActionListeners( *this ) 1420 { 1421 maComponentInfos.nWidth = 100; 1422 maComponentInfos.nHeight = 12; 1423 } 1424 1425 ::rtl::OUString UnoFixedHyperlinkControl::GetComponentServiceName() 1426 { 1427 return ::rtl::OUString::createFromAscii( "fixedhyperlink" ); 1428 } 1429 1430 // uno::XInterface 1431 uno::Any UnoFixedHyperlinkControl::queryAggregation( const uno::Type & rType ) throw(uno::RuntimeException) 1432 { 1433 uno::Any aRet = ::cppu::queryInterface( rType, 1434 SAL_STATIC_CAST( awt::XFixedHyperlink*, this ), 1435 SAL_STATIC_CAST( awt::XLayoutConstrains*, this ) ); 1436 return (aRet.hasValue() ? aRet : UnoControlBase::queryAggregation( rType )); 1437 } 1438 1439 // lang::XTypeProvider 1440 IMPL_XTYPEPROVIDER_START( UnoFixedHyperlinkControl ) 1441 getCppuType( ( uno::Reference< awt::XFixedHyperlink>* ) NULL ), 1442 getCppuType( ( uno::Reference< awt::XLayoutConstrains>* ) NULL ), 1443 UnoControlBase::getTypes() 1444 IMPL_XTYPEPROVIDER_END 1445 1446 sal_Bool UnoFixedHyperlinkControl::isTransparent() throw(uno::RuntimeException) 1447 { 1448 return sal_True; 1449 } 1450 1451 void UnoFixedHyperlinkControl::setText( const ::rtl::OUString& Text ) throw(uno::RuntimeException) 1452 { 1453 uno::Any aAny; 1454 aAny <<= Text; 1455 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_LABEL ), aAny, sal_True ); 1456 } 1457 1458 ::rtl::OUString UnoFixedHyperlinkControl::getText() throw(uno::RuntimeException) 1459 { 1460 return ImplGetPropertyValue_UString( BASEPROPERTY_LABEL ); 1461 } 1462 1463 void UnoFixedHyperlinkControl::setURL( const ::rtl::OUString& URL ) throw(::com::sun::star::uno::RuntimeException) 1464 { 1465 uno::Any aAny; 1466 aAny <<= URL; 1467 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_URL ), aAny, sal_True ); 1468 } 1469 1470 ::rtl::OUString UnoFixedHyperlinkControl::getURL( ) throw(::com::sun::star::uno::RuntimeException) 1471 { 1472 return ImplGetPropertyValue_UString( BASEPROPERTY_URL ); 1473 } 1474 1475 void UnoFixedHyperlinkControl::setAlignment( short nAlign ) throw(uno::RuntimeException) 1476 { 1477 uno::Any aAny; 1478 aAny <<= (sal_Int16)nAlign; 1479 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_ALIGN ), aAny, sal_True ); 1480 } 1481 1482 short UnoFixedHyperlinkControl::getAlignment() throw(uno::RuntimeException) 1483 { 1484 short nAlign = 0; 1485 if ( mxModel.is() ) 1486 { 1487 uno::Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_ALIGN ) ); 1488 aVal >>= nAlign; 1489 } 1490 return nAlign; 1491 } 1492 1493 awt::Size UnoFixedHyperlinkControl::getMinimumSize( ) throw(uno::RuntimeException) 1494 { 1495 return Impl_getMinimumSize(); 1496 } 1497 1498 awt::Size UnoFixedHyperlinkControl::getPreferredSize( ) throw(uno::RuntimeException) 1499 { 1500 return Impl_getPreferredSize(); 1501 } 1502 1503 awt::Size UnoFixedHyperlinkControl::calcAdjustedSize( const awt::Size& rNewSize ) throw(uno::RuntimeException) 1504 { 1505 return Impl_calcAdjustedSize( rNewSize ); 1506 } 1507 1508 void UnoFixedHyperlinkControl::dispose() throw(uno::RuntimeException) 1509 { 1510 lang::EventObject aEvt; 1511 aEvt.Source = (::cppu::OWeakObject*)this; 1512 maActionListeners.disposeAndClear( aEvt ); 1513 UnoControlBase::dispose(); 1514 } 1515 1516 void UnoFixedHyperlinkControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer ) throw(uno::RuntimeException) 1517 { 1518 UnoControlBase::createPeer( rxToolkit, rParentPeer ); 1519 1520 uno::Reference < awt::XFixedHyperlink > xFixedHyperlink( getPeer(), uno::UNO_QUERY ); 1521 if ( maActionListeners.getLength() ) 1522 xFixedHyperlink->addActionListener( &maActionListeners ); 1523 } 1524 1525 void UnoFixedHyperlinkControl::addActionListener(const uno::Reference< awt::XActionListener > & l) throw(uno::RuntimeException) 1526 { 1527 maActionListeners.addInterface( l ); 1528 if( getPeer().is() && maActionListeners.getLength() == 1 ) 1529 { 1530 uno::Reference < awt::XFixedHyperlink > xFixedHyperlink( getPeer(), uno::UNO_QUERY ); 1531 xFixedHyperlink->addActionListener( &maActionListeners ); 1532 } 1533 } 1534 1535 void UnoFixedHyperlinkControl::removeActionListener(const uno::Reference< awt::XActionListener > & l) throw(uno::RuntimeException) 1536 { 1537 if( getPeer().is() && maActionListeners.getLength() == 1 ) 1538 { 1539 uno::Reference < awt::XFixedHyperlink > xFixedHyperlink( getPeer(), uno::UNO_QUERY ); 1540 xFixedHyperlink->removeActionListener( &maActionListeners ); 1541 } 1542 maActionListeners.removeInterface( l ); 1543 } 1544 1545 // ---------------------------------------------------- 1546 // class UnoControlFixedTextModel 1547 // ---------------------------------------------------- 1548 UnoControlFixedTextModel::UnoControlFixedTextModel( const Reference< XMultiServiceFactory >& i_factory ) 1549 :UnoControlModel( i_factory ) 1550 { 1551 UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXFixedText ); 1552 } 1553 1554 ::rtl::OUString UnoControlFixedTextModel::getServiceName() throw(::com::sun::star::uno::RuntimeException) 1555 { 1556 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlFixedTextModel ); 1557 } 1558 1559 uno::Any UnoControlFixedTextModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const 1560 { 1561 if ( nPropId == BASEPROPERTY_DEFAULTCONTROL ) 1562 { 1563 uno::Any aAny; 1564 aAny <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlFixedText ); 1565 return aAny; 1566 } 1567 else if ( nPropId == BASEPROPERTY_BORDER ) 1568 { 1569 uno::Any aAny; 1570 aAny <<= (sal_Int16)0; 1571 return aAny; 1572 } 1573 1574 return UnoControlModel::ImplGetDefaultValue( nPropId ); 1575 } 1576 1577 ::cppu::IPropertyArrayHelper& UnoControlFixedTextModel::getInfoHelper() 1578 { 1579 static UnoPropertyArrayHelper* pHelper = NULL; 1580 if ( !pHelper ) 1581 { 1582 uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); 1583 pHelper = new UnoPropertyArrayHelper( aIDs ); 1584 } 1585 return *pHelper; 1586 } 1587 1588 // beans::XMultiPropertySet 1589 uno::Reference< beans::XPropertySetInfo > UnoControlFixedTextModel::getPropertySetInfo( ) throw(uno::RuntimeException) 1590 { 1591 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); 1592 return xInfo; 1593 } 1594 1595 1596 // ---------------------------------------------------- 1597 // class UnoFixedTextControl 1598 // ---------------------------------------------------- 1599 UnoFixedTextControl::UnoFixedTextControl( const Reference< XMultiServiceFactory >& i_factory ) 1600 :UnoControlBase( i_factory ) 1601 { 1602 maComponentInfos.nWidth = 100; 1603 maComponentInfos.nHeight = 12; 1604 } 1605 1606 ::rtl::OUString UnoFixedTextControl::GetComponentServiceName() 1607 { 1608 return ::rtl::OUString::createFromAscii( "fixedtext" ); 1609 } 1610 1611 // uno::XInterface 1612 uno::Any UnoFixedTextControl::queryAggregation( const uno::Type & rType ) throw(uno::RuntimeException) 1613 { 1614 uno::Any aRet = ::cppu::queryInterface( rType, 1615 SAL_STATIC_CAST( awt::XFixedText*, this ), 1616 SAL_STATIC_CAST( awt::XLayoutConstrains*, this ) ); 1617 return (aRet.hasValue() ? aRet : UnoControlBase::queryAggregation( rType )); 1618 } 1619 1620 // lang::XTypeProvider 1621 IMPL_XTYPEPROVIDER_START( UnoFixedTextControl ) 1622 getCppuType( ( uno::Reference< awt::XFixedText>* ) NULL ), 1623 getCppuType( ( uno::Reference< awt::XLayoutConstrains>* ) NULL ), 1624 UnoControlBase::getTypes() 1625 IMPL_XTYPEPROVIDER_END 1626 1627 sal_Bool UnoFixedTextControl::isTransparent() throw(uno::RuntimeException) 1628 { 1629 return sal_True; 1630 } 1631 1632 void UnoFixedTextControl::setText( const ::rtl::OUString& Text ) throw(uno::RuntimeException) 1633 { 1634 uno::Any aAny; 1635 aAny <<= Text; 1636 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_LABEL ), aAny, sal_True ); 1637 } 1638 1639 ::rtl::OUString UnoFixedTextControl::getText() throw(uno::RuntimeException) 1640 { 1641 return ImplGetPropertyValue_UString( BASEPROPERTY_LABEL ); 1642 } 1643 1644 void UnoFixedTextControl::setAlignment( short nAlign ) throw(uno::RuntimeException) 1645 { 1646 uno::Any aAny; 1647 aAny <<= (sal_Int16)nAlign; 1648 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_ALIGN ), aAny, sal_True ); 1649 } 1650 1651 short UnoFixedTextControl::getAlignment() throw(uno::RuntimeException) 1652 { 1653 short nAlign = 0; 1654 if ( mxModel.is() ) 1655 { 1656 uno::Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_ALIGN ) ); 1657 aVal >>= nAlign; 1658 } 1659 return nAlign; 1660 } 1661 1662 awt::Size UnoFixedTextControl::getMinimumSize( ) throw(uno::RuntimeException) 1663 { 1664 return Impl_getMinimumSize(); 1665 } 1666 1667 awt::Size UnoFixedTextControl::getPreferredSize( ) throw(uno::RuntimeException) 1668 { 1669 return Impl_getPreferredSize(); 1670 } 1671 1672 awt::Size UnoFixedTextControl::calcAdjustedSize( const awt::Size& rNewSize ) throw(uno::RuntimeException) 1673 { 1674 return Impl_calcAdjustedSize( rNewSize ); 1675 } 1676 1677 // ---------------------------------------------------- 1678 // class UnoControlGroupBoxModel 1679 // ---------------------------------------------------- 1680 UnoControlGroupBoxModel::UnoControlGroupBoxModel( const Reference< XMultiServiceFactory >& i_factory ) 1681 :UnoControlModel( i_factory ) 1682 { 1683 ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL ); 1684 ImplRegisterProperty( BASEPROPERTY_ENABLED ); 1685 ImplRegisterProperty( BASEPROPERTY_ENABLEVISIBLE ); 1686 ImplRegisterProperty( BASEPROPERTY_FONTDESCRIPTOR ); 1687 ImplRegisterProperty( BASEPROPERTY_HELPTEXT ); 1688 ImplRegisterProperty( BASEPROPERTY_HELPURL ); 1689 ImplRegisterProperty( BASEPROPERTY_LABEL ); 1690 ImplRegisterProperty( BASEPROPERTY_PRINTABLE ); 1691 ImplRegisterProperty( BASEPROPERTY_WRITING_MODE ); 1692 ImplRegisterProperty( BASEPROPERTY_CONTEXT_WRITING_MODE ); 1693 } 1694 1695 ::rtl::OUString UnoControlGroupBoxModel::getServiceName() throw(::com::sun::star::uno::RuntimeException) 1696 { 1697 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlGroupBoxModel ); 1698 } 1699 1700 uno::Any UnoControlGroupBoxModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const 1701 { 1702 if ( nPropId == BASEPROPERTY_DEFAULTCONTROL ) 1703 { 1704 uno::Any aAny; 1705 aAny <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlGroupBox ); 1706 return aAny; 1707 } 1708 return UnoControlModel::ImplGetDefaultValue( nPropId ); 1709 } 1710 1711 ::cppu::IPropertyArrayHelper& UnoControlGroupBoxModel::getInfoHelper() 1712 { 1713 static UnoPropertyArrayHelper* pHelper = NULL; 1714 if ( !pHelper ) 1715 { 1716 uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); 1717 pHelper = new UnoPropertyArrayHelper( aIDs ); 1718 } 1719 return *pHelper; 1720 } 1721 1722 // beans::XMultiPropertySet 1723 uno::Reference< beans::XPropertySetInfo > UnoControlGroupBoxModel::getPropertySetInfo( ) throw(uno::RuntimeException) 1724 { 1725 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); 1726 return xInfo; 1727 } 1728 1729 // ---------------------------------------------------- 1730 // class UnoGroupBoxControl 1731 // ---------------------------------------------------- 1732 UnoGroupBoxControl::UnoGroupBoxControl( const Reference< XMultiServiceFactory >& i_factory ) 1733 :UnoControlBase( i_factory ) 1734 { 1735 maComponentInfos.nWidth = 100; 1736 maComponentInfos.nHeight = 100; 1737 } 1738 1739 ::rtl::OUString UnoGroupBoxControl::GetComponentServiceName() 1740 { 1741 return ::rtl::OUString::createFromAscii( "groupbox" ); 1742 } 1743 1744 sal_Bool UnoGroupBoxControl::isTransparent() throw(uno::RuntimeException) 1745 { 1746 return sal_True; 1747 } 1748 1749 // ===================================================================================================================== 1750 // = UnoControlListBoxModel_Data 1751 // ===================================================================================================================== 1752 struct ListItem 1753 { 1754 ::rtl::OUString ItemText; 1755 ::rtl::OUString ItemImageURL; 1756 Any ItemData; 1757 1758 ListItem() 1759 :ItemText() 1760 ,ItemImageURL() 1761 ,ItemData() 1762 { 1763 } 1764 1765 ListItem( const ::rtl::OUString& i_rItemText ) 1766 :ItemText( i_rItemText ) 1767 ,ItemImageURL() 1768 ,ItemData() 1769 { 1770 } 1771 }; 1772 1773 typedef beans::Pair< ::rtl::OUString, ::rtl::OUString > UnoListItem; 1774 1775 struct StripItemData : public ::std::unary_function< ListItem, UnoListItem > 1776 { 1777 UnoListItem operator()( const ListItem& i_rItem ) 1778 { 1779 return UnoListItem( i_rItem.ItemText, i_rItem.ItemImageURL ); 1780 } 1781 }; 1782 1783 struct UnoControlListBoxModel_Data 1784 { 1785 UnoControlListBoxModel_Data( UnoControlListBoxModel& i_rAntiImpl ) 1786 :m_bSettingLegacyProperty( false ) 1787 ,m_rAntiImpl( i_rAntiImpl ) 1788 ,m_aListItems() 1789 { 1790 } 1791 1792 sal_Int32 getItemCount() const { return sal_Int32( m_aListItems.size() ); } 1793 1794 const ListItem& getItem( const sal_Int32 i_nIndex ) const 1795 { 1796 if ( ( i_nIndex < 0 ) || ( i_nIndex >= sal_Int32( m_aListItems.size() ) ) ) 1797 throw IndexOutOfBoundsException( ::rtl::OUString(), m_rAntiImpl ); 1798 return m_aListItems[ i_nIndex ]; 1799 } 1800 1801 ListItem& getItem( const sal_Int32 i_nIndex ) 1802 { 1803 return const_cast< ListItem& >( static_cast< const UnoControlListBoxModel_Data* >( this )->getItem( i_nIndex ) ); 1804 } 1805 1806 ListItem& insertItem( const sal_Int32 i_nIndex ) 1807 { 1808 if ( ( i_nIndex < 0 ) || ( i_nIndex > sal_Int32( m_aListItems.size() ) ) ) 1809 throw IndexOutOfBoundsException( ::rtl::OUString(), m_rAntiImpl ); 1810 return *m_aListItems.insert( m_aListItems.begin() + i_nIndex, ListItem() ); 1811 } 1812 1813 Sequence< UnoListItem > getAllItems() const 1814 { 1815 Sequence< UnoListItem > aItems( sal_Int32( m_aListItems.size() ) ); 1816 ::std::transform( m_aListItems.begin(), m_aListItems.end(), aItems.getArray(), StripItemData() ); 1817 return aItems; 1818 } 1819 1820 void copyItems( const UnoControlListBoxModel_Data& i_copySource ) 1821 { 1822 m_aListItems = i_copySource.m_aListItems; 1823 } 1824 1825 void setAllItems( const ::std::vector< ListItem >& i_rItems ) 1826 { 1827 m_aListItems = i_rItems; 1828 } 1829 1830 void removeItem( const sal_Int32 i_nIndex ) 1831 { 1832 if ( ( i_nIndex < 0 ) || ( i_nIndex >= sal_Int32( m_aListItems.size() ) ) ) 1833 throw IndexOutOfBoundsException( ::rtl::OUString(), m_rAntiImpl ); 1834 m_aListItems.erase( m_aListItems.begin() + i_nIndex ); 1835 } 1836 1837 void removeAllItems() 1838 { 1839 ::std::vector< ListItem > aEmpty; 1840 m_aListItems.swap( aEmpty ); 1841 } 1842 1843 public: 1844 bool m_bSettingLegacyProperty; 1845 1846 private: 1847 UnoControlListBoxModel& m_rAntiImpl; 1848 ::std::vector< ListItem > m_aListItems; 1849 }; 1850 1851 // ===================================================================================================================== 1852 // = UnoControlListBoxModel 1853 // ===================================================================================================================== 1854 // --------------------------------------------------------------------------------------------------------------------- 1855 UnoControlListBoxModel::UnoControlListBoxModel( const Reference< XMultiServiceFactory >& i_factory, ConstructorMode const i_mode ) 1856 :UnoControlListBoxModel_Base( i_factory ) 1857 ,m_pData( new UnoControlListBoxModel_Data( *this ) ) 1858 ,m_aItemListListeners( GetMutex() ) 1859 { 1860 if ( i_mode == ConstructDefault ) 1861 { 1862 UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXListBox ); 1863 } 1864 } 1865 // --------------------------------------------------------------------------------------------------------------------- 1866 UnoControlListBoxModel::UnoControlListBoxModel( const UnoControlListBoxModel& i_rSource ) 1867 :UnoControlListBoxModel_Base( i_rSource ) 1868 ,m_pData( new UnoControlListBoxModel_Data( *this ) ) 1869 ,m_aItemListListeners( GetMutex() ) 1870 { 1871 m_pData->copyItems( *i_rSource.m_pData ); 1872 } 1873 UnoControlListBoxModel::~UnoControlListBoxModel() 1874 { 1875 } 1876 IMPL_SERVICEINFO_DERIVED( UnoControlListBoxModel, UnoControlModel, szServiceName2_UnoControlListBoxModel ) 1877 // --------------------------------------------------------------------------------------------------------------------- 1878 ::rtl::OUString UnoControlListBoxModel::getServiceName() throw(::com::sun::star::uno::RuntimeException) 1879 { 1880 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlListBoxModel ); 1881 } 1882 1883 // --------------------------------------------------------------------------------------------------------------------- 1884 uno::Any UnoControlListBoxModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const 1885 { 1886 if ( nPropId == BASEPROPERTY_DEFAULTCONTROL ) 1887 { 1888 uno::Any aAny; 1889 aAny <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlListBox ); 1890 return aAny; 1891 } 1892 return UnoControlModel::ImplGetDefaultValue( nPropId ); 1893 } 1894 1895 // --------------------------------------------------------------------------------------------------------------------- 1896 ::cppu::IPropertyArrayHelper& UnoControlListBoxModel::getInfoHelper() 1897 { 1898 static UnoPropertyArrayHelper* pHelper = NULL; 1899 if ( !pHelper ) 1900 { 1901 uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); 1902 pHelper = new UnoPropertyArrayHelper( aIDs ); 1903 } 1904 return *pHelper; 1905 } 1906 1907 // --------------------------------------------------------------------------------------------------------------------- 1908 // beans::XMultiPropertySet 1909 uno::Reference< beans::XPropertySetInfo > UnoControlListBoxModel::getPropertySetInfo( ) throw(uno::RuntimeException) 1910 { 1911 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); 1912 return xInfo; 1913 } 1914 1915 // --------------------------------------------------------------------------------------------------------------------- 1916 namespace 1917 { 1918 struct CreateListItem : public ::std::unary_function< ::rtl::OUString, ListItem > 1919 { 1920 ListItem operator()( const ::rtl::OUString& i_rItemText ) 1921 { 1922 return ListItem( i_rItemText ); 1923 } 1924 }; 1925 } 1926 1927 // --------------------------------------------------------------------------------------------------------------------- 1928 void SAL_CALL UnoControlListBoxModel::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const uno::Any& rValue ) throw (uno::Exception) 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 // --------------------------------------------------------------------------------------------------------------------- 1970 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 // --------------------------------------------------------------------------------------------------------------------- 1981 ::sal_Int32 SAL_CALL UnoControlListBoxModel::getItemCount() throw (RuntimeException) 1982 { 1983 ::osl::MutexGuard aGuard( GetMutex() ); 1984 return m_pData->getItemCount(); 1985 } 1986 1987 // --------------------------------------------------------------------------------------------------------------------- 1988 void SAL_CALL UnoControlListBoxModel::insertItem( ::sal_Int32 i_nPosition, const ::rtl::OUString& i_rItemText, const ::rtl::OUString& i_rItemImageURL ) throw (IndexOutOfBoundsException, RuntimeException) 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 // --------------------------------------------------------------------------------------------------------------------- 2001 void SAL_CALL UnoControlListBoxModel::insertItemText( ::sal_Int32 i_nPosition, const ::rtl::OUString& i_rItemText ) throw (IndexOutOfBoundsException, RuntimeException) 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 // --------------------------------------------------------------------------------------------------------------------- 2013 void SAL_CALL UnoControlListBoxModel::insertItemImage( ::sal_Int32 i_nPosition, const ::rtl::OUString& i_rItemImageURL ) throw (IndexOutOfBoundsException, RuntimeException) 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 // --------------------------------------------------------------------------------------------------------------------- 2025 void SAL_CALL UnoControlListBoxModel::removeItem( ::sal_Int32 i_nPosition ) throw (IndexOutOfBoundsException, RuntimeException) 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 // --------------------------------------------------------------------------------------------------------------------- 2036 void SAL_CALL UnoControlListBoxModel::removeAllItems( ) throw (::com::sun::star::uno::RuntimeException) 2037 { 2038 ::osl::ClearableMutexGuard aGuard( GetMutex() ); 2039 // SYNCHRONIZED -----> 2040 m_pData->removeAllItems(); 2041 2042 impl_handleRemove( -1, aGuard ); 2043 // <----- SYNCHRONIZED 2044 } 2045 2046 // --------------------------------------------------------------------------------------------------------------------- 2047 void SAL_CALL UnoControlListBoxModel::setItemText( ::sal_Int32 i_nPosition, const ::rtl::OUString& i_rItemText ) throw (IndexOutOfBoundsException, RuntimeException) 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 // --------------------------------------------------------------------------------------------------------------------- 2059 void SAL_CALL UnoControlListBoxModel::setItemImage( ::sal_Int32 i_nPosition, const ::rtl::OUString& i_rItemImageURL ) throw (IndexOutOfBoundsException, RuntimeException) 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 // --------------------------------------------------------------------------------------------------------------------- 2071 void SAL_CALL UnoControlListBoxModel::setItemTextAndImage( ::sal_Int32 i_nPosition, const ::rtl::OUString& i_rItemText, const ::rtl::OUString& i_rItemImageURL ) throw (IndexOutOfBoundsException, RuntimeException) 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 // --------------------------------------------------------------------------------------------------------------------- 2084 void SAL_CALL UnoControlListBoxModel::setItemData( ::sal_Int32 i_nPosition, const Any& i_rDataValue ) throw (IndexOutOfBoundsException, RuntimeException) 2085 { 2086 ::osl::ClearableMutexGuard aGuard( GetMutex() ); 2087 ListItem& rItem( m_pData->getItem( i_nPosition ) ); 2088 rItem.ItemData = i_rDataValue; 2089 } 2090 2091 // --------------------------------------------------------------------------------------------------------------------- 2092 ::rtl::OUString SAL_CALL UnoControlListBoxModel::getItemText( ::sal_Int32 i_nPosition ) throw (IndexOutOfBoundsException, RuntimeException) 2093 { 2094 ::osl::MutexGuard aGuard( GetMutex() ); 2095 const ListItem& rItem( m_pData->getItem( i_nPosition ) ); 2096 return rItem.ItemText; 2097 } 2098 2099 // --------------------------------------------------------------------------------------------------------------------- 2100 ::rtl::OUString SAL_CALL UnoControlListBoxModel::getItemImage( ::sal_Int32 i_nPosition ) throw (IndexOutOfBoundsException, RuntimeException) 2101 { 2102 ::osl::MutexGuard aGuard( GetMutex() ); 2103 const ListItem& rItem( m_pData->getItem( i_nPosition ) ); 2104 return rItem.ItemImageURL; 2105 } 2106 2107 // --------------------------------------------------------------------------------------------------------------------- 2108 beans::Pair< ::rtl::OUString, ::rtl::OUString > SAL_CALL UnoControlListBoxModel::getItemTextAndImage( ::sal_Int32 i_nPosition ) throw (IndexOutOfBoundsException, RuntimeException) 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 // --------------------------------------------------------------------------------------------------------------------- 2116 Any SAL_CALL UnoControlListBoxModel::getItemData( ::sal_Int32 i_nPosition ) throw (IndexOutOfBoundsException, RuntimeException) 2117 { 2118 ::osl::ClearableMutexGuard aGuard( GetMutex() ); 2119 const ListItem& rItem( m_pData->getItem( i_nPosition ) ); 2120 return rItem.ItemData; 2121 } 2122 2123 // --------------------------------------------------------------------------------------------------------------------- 2124 Sequence< beans::Pair< ::rtl::OUString, ::rtl::OUString > > SAL_CALL UnoControlListBoxModel::getAllItems( ) throw (RuntimeException) 2125 { 2126 ::osl::MutexGuard aGuard( GetMutex() ); 2127 return m_pData->getAllItems(); 2128 } 2129 2130 // --------------------------------------------------------------------------------------------------------------------- 2131 void SAL_CALL UnoControlListBoxModel::addItemListListener( const uno::Reference< awt::XItemListListener >& i_Listener ) throw (uno::RuntimeException) 2132 { 2133 if ( i_Listener.is() ) 2134 m_aItemListListeners.addInterface( i_Listener ); 2135 } 2136 2137 // --------------------------------------------------------------------------------------------------------------------- 2138 void SAL_CALL UnoControlListBoxModel::removeItemListListener( const uno::Reference< awt::XItemListListener >& i_Listener ) throw (uno::RuntimeException) 2139 { 2140 if ( i_Listener.is() ) 2141 m_aItemListListeners.removeInterface( i_Listener ); 2142 } 2143 2144 // --------------------------------------------------------------------------------------------------------------------- 2145 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 // --------------------------------------------------------------------------------------------------------------------- 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 // --------------------------------------------------------------------------------------------------------------------- 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 // --------------------------------------------------------------------------------------------------------------------- 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 // --------------------------------------------------------------------------------------------------------------------- 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 // --------------------------------------------------------------------------------------------------------------------- 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 // ---------------------------------------------------- 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 2307 ::rtl::OUString UnoListBoxControl::GetComponentServiceName() 2308 { 2309 return ::rtl::OUString::createFromAscii( "listbox" ); 2310 } 2311 IMPL_SERVICEINFO_DERIVED( UnoListBoxControl, UnoControlBase, szServiceName2_UnoControlListBox ) 2312 2313 void UnoListBoxControl::dispose() throw(uno::RuntimeException) 2314 { 2315 lang::EventObject aEvt; 2316 aEvt.Source = (::cppu::OWeakObject*)this; 2317 maActionListeners.disposeAndClear( aEvt ); 2318 maItemListeners.disposeAndClear( aEvt ); 2319 UnoControl::dispose(); 2320 } 2321 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 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 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 2364 void UnoListBoxControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer ) throw(uno::RuntimeException) 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 2375 void UnoListBoxControl::addActionListener(const uno::Reference< awt::XActionListener > & l) throw(uno::RuntimeException) 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 2385 void UnoListBoxControl::removeActionListener(const uno::Reference< awt::XActionListener > & l) throw(uno::RuntimeException) 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 2395 void UnoListBoxControl::addItemListener(const uno::Reference < awt::XItemListener > & l) throw(uno::RuntimeException) 2396 { 2397 maItemListeners.addInterface( l ); 2398 } 2399 2400 void UnoListBoxControl::removeItemListener(const uno::Reference < awt::XItemListener > & l) throw(uno::RuntimeException) 2401 { 2402 maItemListeners.removeInterface( l ); 2403 } 2404 2405 void UnoListBoxControl::addItem( const ::rtl::OUString& aItem, sal_Int16 nPos ) throw(uno::RuntimeException) 2406 { 2407 uno::Sequence< ::rtl::OUString> aSeq( 1 ); 2408 aSeq.getArray()[0] = aItem; 2409 addItems( aSeq, nPos ); 2410 } 2411 2412 void UnoListBoxControl::addItems( const uno::Sequence< ::rtl::OUString>& aItems, sal_Int16 nPos ) throw(uno::RuntimeException) 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 2446 void UnoListBoxControl::removeItems( sal_Int16 nPos, sal_Int16 nCount ) throw(uno::RuntimeException) 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 2478 sal_Int16 UnoListBoxControl::getItemCount() throw(uno::RuntimeException) 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 2486 ::rtl::OUString UnoListBoxControl::getItem( sal_Int16 nPos ) throw(uno::RuntimeException) 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 2497 uno::Sequence< ::rtl::OUString> UnoListBoxControl::getItems() throw(uno::RuntimeException) 2498 { 2499 uno::Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_STRINGITEMLIST ) ); 2500 uno::Sequence< ::rtl::OUString> aSeq; 2501 aVal >>= aSeq; 2502 return aSeq; 2503 } 2504 2505 sal_Int16 UnoListBoxControl::getSelectedItemPos() throw(uno::RuntimeException) 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 2516 uno::Sequence<sal_Int16> UnoListBoxControl::getSelectedItemsPos() throw(uno::RuntimeException) 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 2527 ::rtl::OUString UnoListBoxControl::getSelectedItem() throw(uno::RuntimeException) 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 2538 uno::Sequence< ::rtl::OUString> UnoListBoxControl::getSelectedItems() throw(uno::RuntimeException) 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 2549 void UnoListBoxControl::selectItemPos( sal_Int16 nPos, sal_Bool bSelect ) throw(uno::RuntimeException) 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 2559 void UnoListBoxControl::selectItemsPos( const uno::Sequence<sal_Int16>& aPositions, sal_Bool bSelect ) throw(uno::RuntimeException) 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 2569 void UnoListBoxControl::selectItem( const ::rtl::OUString& aItem, sal_Bool bSelect ) throw(uno::RuntimeException) 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 2579 void UnoListBoxControl::makeVisible( sal_Int16 nEntry ) throw(uno::RuntimeException) 2580 { 2581 if ( getPeer().is() ) 2582 { 2583 uno::Reference < awt::XListBox > xListBox( getPeer(), uno::UNO_QUERY ); 2584 xListBox->makeVisible( nEntry ); 2585 } 2586 } 2587 2588 void UnoListBoxControl::setDropDownLineCount( sal_Int16 nLines ) throw(uno::RuntimeException) 2589 { 2590 uno::Any aAny; 2591 aAny <<= (sal_Int16)nLines; 2592 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_LINECOUNT ), aAny, sal_True ); 2593 } 2594 2595 sal_Int16 UnoListBoxControl::getDropDownLineCount() throw(uno::RuntimeException) 2596 { 2597 return ImplGetPropertyValue_INT16( BASEPROPERTY_LINECOUNT ); 2598 } 2599 2600 sal_Bool UnoListBoxControl::isMutipleMode() throw(uno::RuntimeException) 2601 { 2602 return ImplGetPropertyValue_BOOL( BASEPROPERTY_MULTISELECTION ); 2603 } 2604 2605 void UnoListBoxControl::setMultipleMode( sal_Bool bMulti ) throw(uno::RuntimeException) 2606 { 2607 uno::Any aAny; 2608 aAny <<= bMulti; 2609 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_MULTISELECTION ), aAny, sal_True ); 2610 } 2611 2612 void UnoListBoxControl::itemStateChanged( const awt::ItemEvent& rEvent ) throw(uno::RuntimeException) 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 2634 awt::Size UnoListBoxControl::getMinimumSize( ) throw(uno::RuntimeException) 2635 { 2636 return Impl_getMinimumSize(); 2637 } 2638 2639 awt::Size UnoListBoxControl::getPreferredSize( ) throw(uno::RuntimeException) 2640 { 2641 return Impl_getPreferredSize(); 2642 } 2643 2644 awt::Size UnoListBoxControl::calcAdjustedSize( const awt::Size& rNewSize ) throw(uno::RuntimeException) 2645 { 2646 return Impl_calcAdjustedSize( rNewSize ); 2647 } 2648 2649 awt::Size UnoListBoxControl::getMinimumSize( sal_Int16 nCols, sal_Int16 nLines ) throw(uno::RuntimeException) 2650 { 2651 return Impl_getMinimumSize( nCols, nLines ); 2652 } 2653 2654 void UnoListBoxControl::getColumnsAndLines( sal_Int16& nCols, sal_Int16& nLines ) throw(uno::RuntimeException) 2655 { 2656 Impl_getColumnsAndLines( nCols, nLines ); 2657 } 2658 2659 sal_Bool SAL_CALL UnoListBoxControl::setModel( const uno::Reference< awt::XControlModel >& i_rModel ) throw ( uno::RuntimeException ) 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 2679 void SAL_CALL UnoListBoxControl::listItemInserted( const awt::ItemListEvent& i_rEvent ) throw (uno::RuntimeException) 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 2687 void SAL_CALL UnoListBoxControl::listItemRemoved( const awt::ItemListEvent& i_rEvent ) throw (uno::RuntimeException) 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 2695 void SAL_CALL UnoListBoxControl::listItemModified( const awt::ItemListEvent& i_rEvent ) throw (uno::RuntimeException) 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 2703 void SAL_CALL UnoListBoxControl::allItemsRemoved( const lang::EventObject& i_rEvent ) throw (uno::RuntimeException) 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 2711 void SAL_CALL UnoListBoxControl::itemListChanged( const lang::EventObject& i_rEvent ) throw (uno::RuntimeException) 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 } 2718 ActionListenerMultiplexer& UnoListBoxControl::getActionListeners() 2719 { 2720 return maActionListeners; 2721 } 2722 ItemListenerMultiplexer& UnoListBoxControl::getItemListeners() 2723 { 2724 return maItemListeners; 2725 } 2726 // ---------------------------------------------------- 2727 // class UnoControlComboBoxModel 2728 // ---------------------------------------------------- 2729 UnoControlComboBoxModel::UnoControlComboBoxModel( const Reference< XMultiServiceFactory >& i_factory ) 2730 :UnoControlListBoxModel( i_factory, ConstructWithoutProperties ) 2731 { 2732 UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXComboBox ); 2733 } 2734 2735 IMPL_SERVICEINFO_DERIVED( UnoControlComboBoxModel, UnoControlModel, szServiceName2_UnoControlComboBoxModel ) 2736 2737 uno::Reference< beans::XPropertySetInfo > UnoControlComboBoxModel::getPropertySetInfo( ) throw(uno::RuntimeException) 2738 { 2739 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); 2740 return xInfo; 2741 } 2742 // --------------------------------------------------------------------------------------------------------------------- 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 2755 ::rtl::OUString UnoControlComboBoxModel::getServiceName() throw(::com::sun::star::uno::RuntimeException) 2756 { 2757 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlComboBoxModel ); 2758 } 2759 void SAL_CALL UnoControlComboBoxModel::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const uno::Any& rValue ) throw (uno::Exception) 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 2791 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 // ---------------------------------------------------- 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 } 2813 IMPL_SERVICEINFO_DERIVED( UnoComboBoxControl, UnoEditControl, szServiceName2_UnoControlComboBox ) 2814 2815 ::rtl::OUString UnoComboBoxControl::GetComponentServiceName() 2816 { 2817 return ::rtl::OUString::createFromAscii( "combobox" ); 2818 } 2819 2820 void UnoComboBoxControl::dispose() throw(uno::RuntimeException) 2821 { 2822 lang::EventObject aEvt; 2823 aEvt.Source = (::cppu::OWeakObject*)this; 2824 maActionListeners.disposeAndClear( aEvt ); 2825 maItemListeners.disposeAndClear( aEvt ); 2826 UnoControl::dispose(); 2827 } 2828 uno::Any UnoComboBoxControl::queryAggregation( const uno::Type & rType ) throw(uno::RuntimeException) 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 } 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 } 2872 void UnoComboBoxControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer ) throw(uno::RuntimeException) 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 2883 void UnoComboBoxControl::addActionListener(const uno::Reference< awt::XActionListener > & l) throw(uno::RuntimeException) 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 2893 void UnoComboBoxControl::removeActionListener(const uno::Reference< awt::XActionListener > & l) throw(uno::RuntimeException) 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 2903 void UnoComboBoxControl::addItemListener(const uno::Reference < awt::XItemListener > & l) throw(uno::RuntimeException) 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 2913 void UnoComboBoxControl::removeItemListener(const uno::Reference < awt::XItemListener > & l) throw(uno::RuntimeException) 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 } 2922 void UnoComboBoxControl::itemStateChanged( const awt::ItemEvent& rEvent ) throw(uno::RuntimeException) 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 } 2942 sal_Bool SAL_CALL UnoComboBoxControl::setModel( const uno::Reference< awt::XControlModel >& i_rModel ) throw ( uno::RuntimeException ) 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 2962 void SAL_CALL UnoComboBoxControl::listItemInserted( const awt::ItemListEvent& i_rEvent ) throw (uno::RuntimeException) 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 2970 void SAL_CALL UnoComboBoxControl::listItemRemoved( const awt::ItemListEvent& i_rEvent ) throw (uno::RuntimeException) 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 2978 void SAL_CALL UnoComboBoxControl::listItemModified( const awt::ItemListEvent& i_rEvent ) throw (uno::RuntimeException) 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 2986 void SAL_CALL UnoComboBoxControl::allItemsRemoved( const lang::EventObject& i_rEvent ) throw (uno::RuntimeException) 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 2994 void SAL_CALL UnoComboBoxControl::itemListChanged( const lang::EventObject& i_rEvent ) throw (uno::RuntimeException) 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 } 3001 ActionListenerMultiplexer& UnoComboBoxControl::getActionListeners() 3002 { 3003 return maActionListeners; 3004 } 3005 ItemListenerMultiplexer& UnoComboBoxControl::getItemListeners() 3006 { 3007 return maItemListeners; 3008 } 3009 3010 void UnoComboBoxControl::addItem( const ::rtl::OUString& aItem, sal_Int16 nPos ) throw(uno::RuntimeException) 3011 { 3012 uno::Sequence< ::rtl::OUString> aSeq( 1 ); 3013 aSeq.getArray()[0] = aItem; 3014 addItems( aSeq, nPos ); 3015 } 3016 3017 void UnoComboBoxControl::addItems( const uno::Sequence< ::rtl::OUString>& aItems, sal_Int16 nPos ) throw(uno::RuntimeException) 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 3051 void UnoComboBoxControl::removeItems( sal_Int16 nPos, sal_Int16 nCount ) throw(uno::RuntimeException) 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 3083 sal_Int16 UnoComboBoxControl::getItemCount() throw(uno::RuntimeException) 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 3091 ::rtl::OUString UnoComboBoxControl::getItem( sal_Int16 nPos ) throw(uno::RuntimeException) 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 3102 uno::Sequence< ::rtl::OUString> UnoComboBoxControl::getItems() throw(uno::RuntimeException) 3103 { 3104 uno::Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_STRINGITEMLIST ) ); 3105 uno::Sequence< ::rtl::OUString> aSeq; 3106 aVal >>= aSeq; 3107 return aSeq; 3108 } 3109 3110 void UnoComboBoxControl::setDropDownLineCount( sal_Int16 nLines ) throw(uno::RuntimeException) 3111 { 3112 uno::Any aAny; 3113 aAny <<= nLines; 3114 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_LINECOUNT ), aAny, sal_True ); 3115 } 3116 3117 sal_Int16 UnoComboBoxControl::getDropDownLineCount() throw(uno::RuntimeException) 3118 { 3119 return ImplGetPropertyValue_INT16( BASEPROPERTY_LINECOUNT ); 3120 } 3121 3122 3123 // ---------------------------------------------------- 3124 // UnoSpinFieldControl 3125 // ---------------------------------------------------- 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 3134 uno::Any UnoSpinFieldControl::queryAggregation( const uno::Type & rType ) throw(uno::RuntimeException) 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 ) throw(uno::RuntimeException) 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 3158 void UnoSpinFieldControl::addSpinListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XSpinListener >& l ) throw(::com::sun::star::uno::RuntimeException) 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 3168 void UnoSpinFieldControl::removeSpinListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XSpinListener >& l ) throw(::com::sun::star::uno::RuntimeException) 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 3178 void UnoSpinFieldControl::up() throw(::com::sun::star::uno::RuntimeException) 3179 { 3180 uno::Reference < awt::XSpinField > xField( getPeer(), uno::UNO_QUERY ); 3181 if ( xField.is() ) 3182 xField->up(); 3183 } 3184 3185 void UnoSpinFieldControl::down() throw(::com::sun::star::uno::RuntimeException) 3186 { 3187 uno::Reference < awt::XSpinField > xField( getPeer(), uno::UNO_QUERY ); 3188 if ( xField.is() ) 3189 xField->down(); 3190 } 3191 3192 void UnoSpinFieldControl::first() throw(::com::sun::star::uno::RuntimeException) 3193 { 3194 uno::Reference < awt::XSpinField > xField( getPeer(), uno::UNO_QUERY ); 3195 if ( xField.is() ) 3196 xField->first(); 3197 } 3198 3199 void UnoSpinFieldControl::last() throw(::com::sun::star::uno::RuntimeException) 3200 { 3201 uno::Reference < awt::XSpinField > xField( getPeer(), uno::UNO_QUERY ); 3202 if ( xField.is() ) 3203 xField->last(); 3204 } 3205 3206 void UnoSpinFieldControl::enableRepeat( sal_Bool bRepeat ) throw(::com::sun::star::uno::RuntimeException) 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 // ---------------------------------------------------- 3218 UnoControlDateFieldModel::UnoControlDateFieldModel( const Reference< XMultiServiceFactory >& i_factory ) 3219 :UnoControlModel( i_factory ) 3220 { 3221 UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXDateField ); 3222 } 3223 3224 ::rtl::OUString UnoControlDateFieldModel::getServiceName() throw(::com::sun::star::uno::RuntimeException) 3225 { 3226 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlDateFieldModel ); 3227 } 3228 3229 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 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 3253 uno::Reference< beans::XPropertySetInfo > UnoControlDateFieldModel::getPropertySetInfo( ) throw(uno::RuntimeException) 3254 { 3255 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); 3256 return xInfo; 3257 } 3258 3259 3260 3261 // ---------------------------------------------------- 3262 // class UnoDateFieldControl 3263 // ---------------------------------------------------- 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 3272 ::rtl::OUString UnoDateFieldControl::GetComponentServiceName() 3273 { 3274 return ::rtl::OUString::createFromAscii( "datefield" ); 3275 } 3276 3277 // uno::XInterface 3278 uno::Any UnoDateFieldControl::queryAggregation( const uno::Type & rType ) throw(uno::RuntimeException) 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 ) throw(uno::RuntimeException) 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 3303 void UnoDateFieldControl::textChanged( const awt::TextEvent& e ) throw(uno::RuntimeException) 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 3344 void UnoDateFieldControl::setDate( sal_Int32 Date ) throw(uno::RuntimeException) 3345 { 3346 uno::Any aAny; 3347 aAny <<= Date; 3348 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_DATE ), aAny, sal_True ); 3349 } 3350 3351 sal_Int32 UnoDateFieldControl::getDate() throw(uno::RuntimeException) 3352 { 3353 return ImplGetPropertyValue_INT32( BASEPROPERTY_DATE ); 3354 } 3355 3356 void UnoDateFieldControl::setMin( sal_Int32 Date ) throw(uno::RuntimeException) 3357 { 3358 uno::Any aAny; 3359 aAny <<= Date; 3360 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_DATEMIN ), aAny, sal_True ); 3361 } 3362 3363 sal_Int32 UnoDateFieldControl::getMin() throw(uno::RuntimeException) 3364 { 3365 return ImplGetPropertyValue_INT32( BASEPROPERTY_DATEMIN ); 3366 } 3367 3368 void UnoDateFieldControl::setMax( sal_Int32 Date ) throw(uno::RuntimeException) 3369 { 3370 uno::Any aAny; 3371 aAny <<= Date; 3372 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_DATEMAX ), aAny, sal_True ); 3373 } 3374 3375 sal_Int32 UnoDateFieldControl::getMax() throw(uno::RuntimeException) 3376 { 3377 return ImplGetPropertyValue_INT32( BASEPROPERTY_DATEMAX ); 3378 } 3379 3380 void UnoDateFieldControl::setFirst( sal_Int32 Date ) throw(uno::RuntimeException) 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 3390 sal_Int32 UnoDateFieldControl::getFirst() throw(uno::RuntimeException) 3391 { 3392 return mnFirst; 3393 } 3394 3395 void UnoDateFieldControl::setLast( sal_Int32 Date ) throw(uno::RuntimeException) 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 3405 sal_Int32 UnoDateFieldControl::getLast() throw(uno::RuntimeException) 3406 { 3407 return mnLast; 3408 } 3409 3410 void UnoDateFieldControl::setLongFormat( sal_Bool bLong ) throw(uno::RuntimeException) 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 3420 sal_Bool UnoDateFieldControl::isLongFormat() throw(uno::RuntimeException) 3421 { 3422 return ( mbLongFormat != 2 ) ? mbLongFormat : sal_False; 3423 } 3424 3425 void UnoDateFieldControl::setEmpty() throw(uno::RuntimeException) 3426 { 3427 if ( getPeer().is() ) 3428 { 3429 uno::Reference < awt::XDateField > xField( getPeer(), uno::UNO_QUERY ); 3430 xField->setEmpty(); 3431 } 3432 } 3433 3434 sal_Bool UnoDateFieldControl::isEmpty() throw(uno::RuntimeException) 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 3445 void UnoDateFieldControl::setStrictFormat( sal_Bool bStrict ) throw(uno::RuntimeException) 3446 { 3447 uno::Any aAny; 3448 aAny <<= bStrict; 3449 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_STRICTFORMAT ), aAny, sal_True ); 3450 } 3451 3452 sal_Bool UnoDateFieldControl::isStrictFormat() throw(uno::RuntimeException) 3453 { 3454 return ImplGetPropertyValue_BOOL( BASEPROPERTY_STRICTFORMAT ); 3455 } 3456 3457 // ---------------------------------------------------- 3458 // class UnoControlTimeFieldModel 3459 // ---------------------------------------------------- 3460 UnoControlTimeFieldModel::UnoControlTimeFieldModel( const Reference< XMultiServiceFactory >& i_factory ) 3461 :UnoControlModel( i_factory ) 3462 { 3463 UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXTimeField ); 3464 } 3465 3466 ::rtl::OUString UnoControlTimeFieldModel::getServiceName() throw(::com::sun::star::uno::RuntimeException) 3467 { 3468 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlTimeFieldModel ); 3469 } 3470 3471 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 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 3495 uno::Reference< beans::XPropertySetInfo > UnoControlTimeFieldModel::getPropertySetInfo( ) throw(uno::RuntimeException) 3496 { 3497 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); 3498 return xInfo; 3499 } 3500 3501 3502 3503 // ---------------------------------------------------- 3504 // class UnoTimeFieldControl 3505 // ---------------------------------------------------- 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 3513 ::rtl::OUString UnoTimeFieldControl::GetComponentServiceName() 3514 { 3515 return ::rtl::OUString::createFromAscii( "timefield" ); 3516 } 3517 3518 // uno::XInterface 3519 uno::Any UnoTimeFieldControl::queryAggregation( const uno::Type & rType ) throw(uno::RuntimeException) 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 ) throw(uno::RuntimeException) 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 3541 void UnoTimeFieldControl::textChanged( const awt::TextEvent& e ) throw(uno::RuntimeException) 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 3560 void UnoTimeFieldControl::setTime( sal_Int32 Time ) throw(uno::RuntimeException) 3561 { 3562 uno::Any aAny; 3563 aAny <<= Time; 3564 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_TIME ), aAny, sal_True ); 3565 } 3566 3567 sal_Int32 UnoTimeFieldControl::getTime() throw(uno::RuntimeException) 3568 { 3569 return ImplGetPropertyValue_INT32( BASEPROPERTY_TIME ); 3570 } 3571 3572 void UnoTimeFieldControl::setMin( sal_Int32 Time ) throw(uno::RuntimeException) 3573 { 3574 uno::Any aAny; 3575 aAny <<= Time; 3576 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_TIMEMIN ), aAny, sal_True ); 3577 } 3578 3579 sal_Int32 UnoTimeFieldControl::getMin() throw(uno::RuntimeException) 3580 { 3581 return ImplGetPropertyValue_INT32( BASEPROPERTY_TIMEMIN ); 3582 } 3583 3584 void UnoTimeFieldControl::setMax( sal_Int32 Time ) throw(uno::RuntimeException) 3585 { 3586 uno::Any aAny; 3587 aAny <<= Time; 3588 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_TIMEMAX ), aAny, sal_True ); 3589 } 3590 3591 sal_Int32 UnoTimeFieldControl::getMax() throw(uno::RuntimeException) 3592 { 3593 return ImplGetPropertyValue_INT32( BASEPROPERTY_TIMEMAX ); 3594 } 3595 3596 void UnoTimeFieldControl::setFirst( sal_Int32 Time ) throw(uno::RuntimeException) 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 3606 sal_Int32 UnoTimeFieldControl::getFirst() throw(uno::RuntimeException) 3607 { 3608 return mnFirst; 3609 } 3610 3611 void UnoTimeFieldControl::setLast( sal_Int32 Time ) throw(uno::RuntimeException) 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 3621 sal_Int32 UnoTimeFieldControl::getLast() throw(uno::RuntimeException) 3622 { 3623 return mnLast; 3624 } 3625 3626 void UnoTimeFieldControl::setEmpty() throw(uno::RuntimeException) 3627 { 3628 if ( getPeer().is() ) 3629 { 3630 uno::Reference < awt::XTimeField > xField( getPeer(), uno::UNO_QUERY ); 3631 xField->setEmpty(); 3632 } 3633 } 3634 3635 sal_Bool UnoTimeFieldControl::isEmpty() throw(uno::RuntimeException) 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 3646 void UnoTimeFieldControl::setStrictFormat( sal_Bool bStrict ) throw(uno::RuntimeException) 3647 { 3648 uno::Any aAny; 3649 aAny <<= bStrict; 3650 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_STRICTFORMAT ), aAny, sal_True ); 3651 } 3652 3653 sal_Bool UnoTimeFieldControl::isStrictFormat() throw(uno::RuntimeException) 3654 { 3655 return ImplGetPropertyValue_BOOL( BASEPROPERTY_STRICTFORMAT ); 3656 } 3657 3658 // ---------------------------------------------------- 3659 // class UnoControlNumericFieldModel 3660 // ---------------------------------------------------- 3661 UnoControlNumericFieldModel::UnoControlNumericFieldModel( const Reference< XMultiServiceFactory >& i_factory ) 3662 :UnoControlModel( i_factory ) 3663 { 3664 UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXNumericField ); 3665 } 3666 3667 ::rtl::OUString UnoControlNumericFieldModel::getServiceName() throw(::com::sun::star::uno::RuntimeException) 3668 { 3669 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlNumericFieldModel ); 3670 } 3671 3672 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 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 3696 uno::Reference< beans::XPropertySetInfo > UnoControlNumericFieldModel::getPropertySetInfo( ) throw(uno::RuntimeException) 3697 { 3698 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); 3699 return xInfo; 3700 } 3701 3702 3703 3704 // ---------------------------------------------------- 3705 // class UnoNumericFieldControl 3706 // ---------------------------------------------------- 3707 UnoNumericFieldControl::UnoNumericFieldControl( const Reference< XMultiServiceFactory >& i_factory ) 3708 :UnoSpinFieldControl( i_factory ) 3709 { 3710 mnFirst = 0; 3711 mnLast = 0x7FFFFFFF; 3712 } 3713 3714 ::rtl::OUString UnoNumericFieldControl::GetComponentServiceName() 3715 { 3716 return ::rtl::OUString::createFromAscii( "numericfield" ); 3717 } 3718 3719 // uno::XInterface 3720 uno::Any UnoNumericFieldControl::queryAggregation( const uno::Type & rType ) throw(uno::RuntimeException) 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 ) throw(uno::RuntimeException) 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 3743 void UnoNumericFieldControl::textChanged( const awt::TextEvent& e ) throw(uno::RuntimeException) 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 3754 void UnoNumericFieldControl::setValue( double Value ) throw(uno::RuntimeException) 3755 { 3756 uno::Any aAny; 3757 aAny <<= Value; 3758 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VALUE_DOUBLE ), aAny, sal_True ); 3759 } 3760 3761 double UnoNumericFieldControl::getValue() throw(uno::RuntimeException) 3762 { 3763 return ImplGetPropertyValue_DOUBLE( BASEPROPERTY_VALUE_DOUBLE ); 3764 } 3765 3766 void UnoNumericFieldControl::setMin( double Value ) throw(uno::RuntimeException) 3767 { 3768 uno::Any aAny; 3769 aAny <<= Value; 3770 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VALUEMIN_DOUBLE ), aAny, sal_True ); 3771 } 3772 3773 double UnoNumericFieldControl::getMin() throw(uno::RuntimeException) 3774 { 3775 return ImplGetPropertyValue_DOUBLE( BASEPROPERTY_VALUEMIN_DOUBLE ); 3776 } 3777 3778 void UnoNumericFieldControl::setMax( double Value ) throw(uno::RuntimeException) 3779 { 3780 uno::Any aAny; 3781 aAny <<= Value; 3782 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VALUEMAX_DOUBLE ), aAny, sal_True ); 3783 } 3784 3785 double UnoNumericFieldControl::getMax() throw(uno::RuntimeException) 3786 { 3787 return ImplGetPropertyValue_DOUBLE( BASEPROPERTY_VALUEMAX_DOUBLE ); 3788 } 3789 3790 void UnoNumericFieldControl::setFirst( double Value ) throw(uno::RuntimeException) 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 3800 double UnoNumericFieldControl::getFirst() throw(uno::RuntimeException) 3801 { 3802 return mnFirst; 3803 } 3804 3805 void UnoNumericFieldControl::setLast( double Value ) throw(uno::RuntimeException) 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 3815 double UnoNumericFieldControl::getLast() throw(uno::RuntimeException) 3816 { 3817 return mnLast; 3818 } 3819 3820 void UnoNumericFieldControl::setStrictFormat( sal_Bool bStrict ) throw(uno::RuntimeException) 3821 { 3822 uno::Any aAny; 3823 aAny <<= bStrict; 3824 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_STRICTFORMAT ), aAny, sal_True ); 3825 } 3826 3827 sal_Bool UnoNumericFieldControl::isStrictFormat() throw(uno::RuntimeException) 3828 { 3829 return ImplGetPropertyValue_BOOL( BASEPROPERTY_STRICTFORMAT ); 3830 } 3831 3832 void UnoNumericFieldControl::setSpinSize( double Digits ) throw(uno::RuntimeException) 3833 { 3834 uno::Any aAny; 3835 aAny <<= Digits; 3836 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VALUESTEP_DOUBLE ), aAny, sal_True ); 3837 } 3838 3839 double UnoNumericFieldControl::getSpinSize() throw(uno::RuntimeException) 3840 { 3841 return ImplGetPropertyValue_DOUBLE( BASEPROPERTY_VALUESTEP_DOUBLE ); 3842 } 3843 3844 void UnoNumericFieldControl::setDecimalDigits( sal_Int16 Digits ) throw(uno::RuntimeException) 3845 { 3846 uno::Any aAny; 3847 aAny <<= Digits; 3848 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_DECIMALACCURACY ), aAny, sal_True ); 3849 } 3850 3851 sal_Int16 UnoNumericFieldControl::getDecimalDigits() throw(uno::RuntimeException) 3852 { 3853 return ImplGetPropertyValue_INT16( BASEPROPERTY_DECIMALACCURACY ); 3854 } 3855 3856 // ---------------------------------------------------- 3857 // class UnoControlCurrencyFieldModel 3858 // ---------------------------------------------------- 3859 UnoControlCurrencyFieldModel::UnoControlCurrencyFieldModel( const Reference< XMultiServiceFactory >& i_factory ) 3860 :UnoControlModel( i_factory ) 3861 { 3862 UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXCurrencyField ); 3863 } 3864 3865 ::rtl::OUString UnoControlCurrencyFieldModel::getServiceName() throw(::com::sun::star::uno::RuntimeException) 3866 { 3867 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlCurrencyFieldModel ); 3868 } 3869 3870 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 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 3900 uno::Reference< beans::XPropertySetInfo > UnoControlCurrencyFieldModel::getPropertySetInfo( ) throw(uno::RuntimeException) 3901 { 3902 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); 3903 return xInfo; 3904 } 3905 3906 // ---------------------------------------------------- 3907 // class UnoCurrencyFieldControl 3908 // ---------------------------------------------------- 3909 UnoCurrencyFieldControl::UnoCurrencyFieldControl( const Reference< XMultiServiceFactory >& i_factory ) 3910 :UnoSpinFieldControl( i_factory ) 3911 { 3912 mnFirst = 0; 3913 mnLast = 0x7FFFFFFF; 3914 } 3915 3916 ::rtl::OUString UnoCurrencyFieldControl::GetComponentServiceName() 3917 { 3918 return ::rtl::OUString::createFromAscii( "longcurrencyfield" ); 3919 } 3920 3921 // uno::XInterface 3922 uno::Any UnoCurrencyFieldControl::queryAggregation( const uno::Type & rType ) throw(uno::RuntimeException) 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 ) throw(uno::RuntimeException) 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 3944 void UnoCurrencyFieldControl::textChanged( const awt::TextEvent& e ) throw(uno::RuntimeException) 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 3955 void UnoCurrencyFieldControl::setValue( double Value ) throw(uno::RuntimeException) 3956 { 3957 uno::Any aAny; 3958 aAny <<= Value; 3959 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VALUE_DOUBLE ), aAny, sal_True ); 3960 } 3961 3962 double UnoCurrencyFieldControl::getValue() throw(uno::RuntimeException) 3963 { 3964 return ImplGetPropertyValue_DOUBLE( BASEPROPERTY_VALUE_DOUBLE ); 3965 } 3966 3967 void UnoCurrencyFieldControl::setMin( double Value ) throw(uno::RuntimeException) 3968 { 3969 uno::Any aAny; 3970 aAny <<= Value; 3971 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VALUEMIN_DOUBLE ), aAny, sal_True ); 3972 } 3973 3974 double UnoCurrencyFieldControl::getMin() throw(uno::RuntimeException) 3975 { 3976 return ImplGetPropertyValue_DOUBLE( BASEPROPERTY_VALUEMIN_DOUBLE ); 3977 } 3978 3979 void UnoCurrencyFieldControl::setMax( double Value ) throw(uno::RuntimeException) 3980 { 3981 uno::Any aAny; 3982 aAny <<= Value; 3983 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VALUEMAX_DOUBLE ), aAny, sal_True ); 3984 } 3985 3986 double UnoCurrencyFieldControl::getMax() throw(uno::RuntimeException) 3987 { 3988 return ImplGetPropertyValue_DOUBLE( BASEPROPERTY_VALUEMAX_DOUBLE ); 3989 } 3990 3991 void UnoCurrencyFieldControl::setFirst( double Value ) throw(uno::RuntimeException) 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 4001 double UnoCurrencyFieldControl::getFirst() throw(uno::RuntimeException) 4002 { 4003 return mnFirst; 4004 } 4005 4006 void UnoCurrencyFieldControl::setLast( double Value ) throw(uno::RuntimeException) 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 4016 double UnoCurrencyFieldControl::getLast() throw(uno::RuntimeException) 4017 { 4018 return mnLast; 4019 } 4020 4021 void UnoCurrencyFieldControl::setStrictFormat( sal_Bool bStrict ) throw(uno::RuntimeException) 4022 { 4023 uno::Any aAny; 4024 aAny <<= bStrict; 4025 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_STRICTFORMAT ), aAny, sal_True ); 4026 } 4027 4028 sal_Bool UnoCurrencyFieldControl::isStrictFormat() throw(uno::RuntimeException) 4029 { 4030 return ImplGetPropertyValue_BOOL( BASEPROPERTY_STRICTFORMAT ); 4031 } 4032 4033 void UnoCurrencyFieldControl::setSpinSize( double Digits ) throw(uno::RuntimeException) 4034 { 4035 uno::Any aAny; 4036 aAny <<= Digits; 4037 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VALUESTEP_DOUBLE ), aAny, sal_True ); 4038 } 4039 4040 double UnoCurrencyFieldControl::getSpinSize() throw(uno::RuntimeException) 4041 { 4042 return ImplGetPropertyValue_DOUBLE( BASEPROPERTY_VALUESTEP_DOUBLE ); 4043 } 4044 4045 void UnoCurrencyFieldControl::setDecimalDigits( sal_Int16 Digits ) throw(uno::RuntimeException) 4046 { 4047 uno::Any aAny; 4048 aAny <<= Digits; 4049 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_DECIMALACCURACY ), aAny, sal_True ); 4050 } 4051 4052 sal_Int16 UnoCurrencyFieldControl::getDecimalDigits() throw(uno::RuntimeException) 4053 { 4054 return ImplGetPropertyValue_INT16( BASEPROPERTY_DECIMALACCURACY ); 4055 } 4056 4057 // ---------------------------------------------------- 4058 // class UnoControlPatternFieldModel 4059 // ---------------------------------------------------- 4060 UnoControlPatternFieldModel::UnoControlPatternFieldModel( const Reference< XMultiServiceFactory >& i_factory ) 4061 :UnoControlModel( i_factory ) 4062 { 4063 UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXPatternField ); 4064 } 4065 4066 ::rtl::OUString UnoControlPatternFieldModel::getServiceName() throw(::com::sun::star::uno::RuntimeException) 4067 { 4068 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlPatternFieldModel ); 4069 } 4070 4071 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 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 4094 uno::Reference< beans::XPropertySetInfo > UnoControlPatternFieldModel::getPropertySetInfo( ) throw(uno::RuntimeException) 4095 { 4096 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); 4097 return xInfo; 4098 } 4099 4100 4101 // ---------------------------------------------------- 4102 // class UnoPatternFieldControl 4103 // ---------------------------------------------------- 4104 UnoPatternFieldControl::UnoPatternFieldControl( const Reference< XMultiServiceFactory >& i_factory ) 4105 :UnoSpinFieldControl( i_factory ) 4106 { 4107 } 4108 4109 ::rtl::OUString UnoPatternFieldControl::GetComponentServiceName() 4110 { 4111 return ::rtl::OUString::createFromAscii( "patternfield" ); 4112 } 4113 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 4140 uno::Any UnoPatternFieldControl::queryAggregation( const uno::Type & rType ) throw(uno::RuntimeException) 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 ) throw(uno::RuntimeException) 4154 { 4155 setText( rString ); 4156 } 4157 4158 ::rtl::OUString UnoPatternFieldControl::getString() throw(uno::RuntimeException) 4159 { 4160 return getText(); 4161 } 4162 4163 void UnoPatternFieldControl::setMasks( const ::rtl::OUString& EditMask, const ::rtl::OUString& LiteralMask ) throw(uno::RuntimeException) 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 4172 void UnoPatternFieldControl::getMasks( ::rtl::OUString& EditMask, ::rtl::OUString& LiteralMask ) throw(uno::RuntimeException) 4173 { 4174 EditMask = ImplGetPropertyValue_UString( BASEPROPERTY_EDITMASK ); 4175 LiteralMask = ImplGetPropertyValue_UString( BASEPROPERTY_LITERALMASK ); 4176 } 4177 4178 void UnoPatternFieldControl::setStrictFormat( sal_Bool bStrict ) throw(uno::RuntimeException) 4179 { 4180 uno::Any aAny; 4181 aAny <<= bStrict; 4182 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_STRICTFORMAT ), aAny, sal_True ); 4183 } 4184 4185 sal_Bool UnoPatternFieldControl::isStrictFormat() throw(uno::RuntimeException) 4186 { 4187 return ImplGetPropertyValue_BOOL( BASEPROPERTY_STRICTFORMAT ); 4188 } 4189 4190 4191 // ---------------------------------------------------- 4192 // class UnoControlProgressBarModel 4193 // ---------------------------------------------------- 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 4212 ::rtl::OUString UnoControlProgressBarModel::getServiceName( ) throw(::com::sun::star::uno::RuntimeException) 4213 { 4214 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlProgressBarModel ); 4215 } 4216 4217 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 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 4241 uno::Reference< beans::XPropertySetInfo > UnoControlProgressBarModel::getPropertySetInfo( ) throw(uno::RuntimeException) 4242 { 4243 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); 4244 return xInfo; 4245 } 4246 4247 4248 // ---------------------------------------------------- 4249 // class UnoProgressBarControl 4250 // ---------------------------------------------------- 4251 UnoProgressBarControl::UnoProgressBarControl( const Reference< XMultiServiceFactory >& i_factory ) 4252 :UnoControlBase( i_factory ) 4253 { 4254 } 4255 4256 ::rtl::OUString UnoProgressBarControl::GetComponentServiceName() 4257 { 4258 return ::rtl::OUString::createFromAscii( "ProgressBar" ); 4259 } 4260 4261 // uno::XInterface 4262 uno::Any UnoProgressBarControl::queryAggregation( const uno::Type & rType ) throw(uno::RuntimeException) 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 ) throw(::com::sun::star::uno::RuntimeException) 4277 { 4278 uno::Any aAny; 4279 aAny <<= nColor; 4280 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_FILLCOLOR ), aAny, sal_True ); 4281 } 4282 4283 void UnoProgressBarControl::setBackgroundColor( sal_Int32 nColor ) throw(::com::sun::star::uno::RuntimeException) 4284 { 4285 uno::Any aAny; 4286 aAny <<= nColor; 4287 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_BACKGROUNDCOLOR ), aAny, sal_True ); 4288 } 4289 4290 void UnoProgressBarControl::setValue( sal_Int32 nValue ) throw(::com::sun::star::uno::RuntimeException) 4291 { 4292 uno::Any aAny; 4293 aAny <<= nValue; 4294 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_PROGRESSVALUE ), aAny, sal_True ); 4295 } 4296 4297 void UnoProgressBarControl::setRange( sal_Int32 nMin, sal_Int32 nMax ) throw(::com::sun::star::uno::RuntimeException ) 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 4319 sal_Int32 UnoProgressBarControl::getValue() throw(::com::sun::star::uno::RuntimeException) 4320 { 4321 return ImplGetPropertyValue_INT32( BASEPROPERTY_PROGRESSVALUE ); 4322 } 4323 4324 4325 // ---------------------------------------------------- 4326 // class UnoControlFixedLineModel 4327 // ---------------------------------------------------- 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 4343 ::rtl::OUString UnoControlFixedLineModel::getServiceName( ) throw(::com::sun::star::uno::RuntimeException) 4344 { 4345 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlFixedLineModel ); 4346 } 4347 4348 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 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 4371 uno::Reference< beans::XPropertySetInfo > UnoControlFixedLineModel::getPropertySetInfo( ) throw(uno::RuntimeException) 4372 { 4373 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); 4374 return xInfo; 4375 } 4376 4377 // ---------------------------------------------------- 4378 // class UnoFixedLineControl 4379 // ---------------------------------------------------- 4380 UnoFixedLineControl::UnoFixedLineControl( const Reference< XMultiServiceFactory >& i_factory ) 4381 :UnoControlBase( i_factory ) 4382 { 4383 maComponentInfos.nWidth = 100; // ?? 4384 maComponentInfos.nHeight = 100; // ?? 4385 } 4386 4387 ::rtl::OUString UnoFixedLineControl::GetComponentServiceName() 4388 { 4389 return ::rtl::OUString::createFromAscii( "FixedLine" ); 4390 } 4391 4392 sal_Bool UnoFixedLineControl::isTransparent() throw(uno::RuntimeException) 4393 { 4394 return sal_True; 4395 } 4396 4397