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 //____________________________________________________________________________________________________________ 29 // my own include 30 //____________________________________________________________________________________________________________ 31 32 #include "basecontrol.hxx" 33 34 //____________________________________________________________________________________________________________ 35 // includes of other projects 36 //____________________________________________________________________________________________________________ 37 #include <com/sun/star/awt/XDevice.hpp> 38 #include <com/sun/star/awt/XDisplayBitmap.hpp> 39 #include <com/sun/star/awt/DeviceInfo.hpp> 40 #include <com/sun/star/awt/WindowAttribute.hpp> 41 #include <com/sun/star/awt/PosSize.hpp> 42 #include <cppuhelper/typeprovider.hxx> 43 44 //____________________________________________________________________________________________________________ 45 // includes of my own project 46 //____________________________________________________________________________________________________________ 47 48 //____________________________________________________________________________________________________________ 49 // namespaces 50 //____________________________________________________________________________________________________________ 51 52 using namespace ::cppu ; 53 using namespace ::osl ; 54 using namespace ::rtl ; 55 using namespace ::com::sun::star::uno ; 56 using namespace ::com::sun::star::lang ; 57 using namespace ::com::sun::star::awt ; 58 59 namespace unocontrols{ 60 61 //____________________________________________________________________________________________________________ 62 // defines 63 //____________________________________________________________________________________________________________ 64 65 #define DEFAULT_PMULTIPLEXER NULL 66 #define DEFAULT_X 0 67 #define DEFAULT_Y 0 68 #define DEFAULT_WIDTH 100 69 #define DEFAULT_HEIGHT 100 70 #define DEFAULT_VISIBLE sal_False 71 #define DEFAULT_INDESIGNMODE sal_False 72 #define DEFAULT_ENABLE sal_True 73 #define SERVICE_VCLTOOLKIT "com.sun.star.awt.Toolkit" 74 75 //____________________________________________________________________________________________________________ 76 // construct/destruct 77 //____________________________________________________________________________________________________________ 78 79 BaseControl::BaseControl( const Reference< XMultiServiceFactory >& xFactory ) 80 : IMPL_MutexContainer ( ) 81 , OComponentHelper ( m_aMutex ) 82 , m_xFactory ( xFactory ) 83 , m_pMultiplexer ( DEFAULT_PMULTIPLEXER ) 84 , m_nX ( DEFAULT_X ) 85 , m_nY ( DEFAULT_Y ) 86 , m_nWidth ( DEFAULT_WIDTH ) 87 , m_nHeight ( DEFAULT_HEIGHT ) 88 , m_bVisible ( DEFAULT_VISIBLE ) 89 , m_bInDesignMode ( DEFAULT_INDESIGNMODE ) 90 , m_bEnable ( DEFAULT_ENABLE ) 91 { 92 } 93 94 BaseControl::~BaseControl() 95 { 96 } 97 98 //____________________________________________________________________________________________________________ 99 // XInterface 100 //____________________________________________________________________________________________________________ 101 102 Any SAL_CALL BaseControl::queryInterface( const Type& rType ) throw( RuntimeException ) 103 { 104 Any aReturn ; 105 if ( m_xDelegator.is() == sal_True ) 106 { 107 // If an delegator exist, forward question to his queryInterface. 108 // Delegator will ask his own queryAggregation! 109 aReturn = m_xDelegator->queryInterface( rType ); 110 } 111 else 112 { 113 // If an delegator unknown, forward question to own queryAggregation. 114 aReturn = queryAggregation( rType ); 115 } 116 117 return aReturn ; 118 } 119 120 //____________________________________________________________________________________________________________ 121 // XInterface 122 //____________________________________________________________________________________________________________ 123 124 void SAL_CALL BaseControl::acquire() throw() 125 { 126 // Attention: 127 // Don't use mutex or guard in this method!!! Is a method of XInterface. 128 129 // Forward to baseclass 130 OComponentHelper::acquire(); 131 } 132 133 //____________________________________________________________________________________________________________ 134 // XInterface 135 //____________________________________________________________________________________________________________ 136 137 void SAL_CALL BaseControl::release() throw() 138 { 139 // Attention: 140 // Don't use mutex or guard in this method!!! Is a method of XInterface. 141 142 // Forward to baseclass 143 OComponentHelper::release(); 144 } 145 146 //____________________________________________________________________________________________________________ 147 // XTypeProvider 148 //____________________________________________________________________________________________________________ 149 150 Sequence< Type > SAL_CALL BaseControl::getTypes() throw( RuntimeException ) 151 { 152 // Optimize this method ! 153 // We initialize a static variable only one time. And we don't must use a mutex at every call! 154 // For the first call; pTypeCollection is NULL - for the second call pTypeCollection is different from NULL! 155 static OTypeCollection* pTypeCollection = NULL ; 156 157 if ( pTypeCollection == NULL ) 158 { 159 // Ready for multithreading; get global mutex for first call of this method only! see before 160 MutexGuard aGuard( Mutex::getGlobalMutex() ); 161 162 // Control these pointer again ... it can be, that another instance will be faster then these! 163 if ( pTypeCollection == NULL ) 164 { 165 // Create a static typecollection ... 166 static OTypeCollection aTypeCollection ( ::getCppuType(( const Reference< XPaintListener >*)NULL ) , 167 ::getCppuType(( const Reference< XWindowListener>*)NULL ) , 168 ::getCppuType(( const Reference< XView >*)NULL ) , 169 ::getCppuType(( const Reference< XWindow >*)NULL ) , 170 ::getCppuType(( const Reference< XServiceInfo >*)NULL ) , 171 ::getCppuType(( const Reference< XControl >*)NULL ) , 172 OComponentHelper::getTypes() 173 ); 174 175 // ... and set his address to static pointer! 176 pTypeCollection = &aTypeCollection ; 177 } 178 } 179 180 return pTypeCollection->getTypes(); 181 } 182 183 //____________________________________________________________________________________________________________ 184 // XTypeProvider 185 //____________________________________________________________________________________________________________ 186 187 Sequence< sal_Int8 > SAL_CALL BaseControl::getImplementationId() throw( RuntimeException ) 188 { 189 // Create one Id for all instances of this class. 190 // Use ethernet address to do this! (sal_True) 191 192 // Optimize this method 193 // We initialize a static variable only one time. And we don't must use a mutex at every call! 194 // For the first call; pID is NULL - for the second call pID is different from NULL! 195 static OImplementationId* pID = NULL ; 196 197 if ( pID == NULL ) 198 { 199 // Ready for multithreading; get global mutex for first call of this method only! see before 200 MutexGuard aGuard( Mutex::getGlobalMutex() ); 201 202 // Control these pointer again ... it can be, that another instance will be faster then these! 203 if ( pID == NULL ) 204 { 205 // Create a new static ID ... 206 static OImplementationId aID( sal_False ); 207 // ... and set his address to static pointer! 208 pID = &aID ; 209 } 210 } 211 212 return pID->getImplementationId(); 213 } 214 215 //____________________________________________________________________________________________________________ 216 // XAggregation 217 //____________________________________________________________________________________________________________ 218 219 void SAL_CALL BaseControl::setDelegator( const Reference< XInterface >& xDel ) throw( RuntimeException ) 220 { 221 // Ready for multithreading 222 MutexGuard aGuard( m_aMutex ); 223 m_xDelegator = xDel; 224 } 225 226 //____________________________________________________________________________________________________________ 227 // XAggregation 228 //____________________________________________________________________________________________________________ 229 230 Any SAL_CALL BaseControl::queryAggregation( const Type& aType ) throw( RuntimeException ) 231 { 232 // Ask for my own supported interfaces ... 233 // Attention: XTypeProvider and XInterface are supported by OComponentHelper! 234 Any aReturn ( ::cppu::queryInterface( aType , 235 static_cast< XPaintListener*> ( this ) , 236 static_cast< XWindowListener*> ( this ) , 237 static_cast< XView* > ( this ) , 238 static_cast< XWindow* > ( this ) , 239 static_cast< XServiceInfo* > ( this ) , 240 static_cast< XControl* > ( this ) 241 ) 242 ); 243 244 // If searched interface supported by this class ... 245 if ( aReturn.hasValue() == sal_True ) 246 { 247 // ... return this information. 248 return aReturn ; 249 } 250 else 251 { 252 // Else; ... ask baseclass for interfaces! 253 return OComponentHelper::queryAggregation( aType ); 254 } 255 } 256 257 //____________________________________________________________________________________________________________ 258 // XServiceInfo 259 //____________________________________________________________________________________________________________ 260 261 OUString SAL_CALL BaseControl::getImplementationName() throw( RuntimeException ) 262 { 263 return impl_getStaticImplementationName(); 264 } 265 266 //____________________________________________________________________________________________________________ 267 // XServiceInfo 268 //____________________________________________________________________________________________________________ 269 270 sal_Bool SAL_CALL BaseControl::supportsService( const OUString& sServiceName ) throw( RuntimeException ) 271 { 272 Sequence< OUString > seqServiceNames = getSupportedServiceNames(); 273 const OUString* pArray = seqServiceNames.getConstArray(); 274 for ( sal_Int32 nCounter=0; nCounter<seqServiceNames.getLength(); nCounter++ ) 275 { 276 if ( pArray[nCounter] == sServiceName ) 277 { 278 return sal_True ; 279 } 280 } 281 return sal_False ; 282 } 283 284 //____________________________________________________________________________________________________________ 285 // XServiceInfo 286 //____________________________________________________________________________________________________________ 287 288 Sequence< OUString > SAL_CALL BaseControl::getSupportedServiceNames() throw( RuntimeException ) 289 { 290 return impl_getStaticSupportedServiceNames(); 291 } 292 293 //____________________________________________________________________________________________________________ 294 // XComponent 295 //____________________________________________________________________________________________________________ 296 297 void SAL_CALL BaseControl::dispose() throw( RuntimeException ) 298 { 299 // Ready for multithreading 300 MutexGuard aGuard( m_aMutex ); 301 302 if ( m_pMultiplexer != NULL ) 303 { 304 // to all other paint, focus, etc. 305 m_pMultiplexer->disposeAndClear(); 306 } 307 308 // set the service manager to disposed 309 OComponentHelper::dispose(); 310 311 // release context and peer 312 m_xContext = Reference< XInterface >(); 313 impl_releasePeer(); 314 315 // release view 316 if ( m_xGraphicsView.is() == sal_True ) 317 { 318 m_xGraphicsView = Reference< XGraphics >(); 319 } 320 } 321 322 //____________________________________________________________________________________________________________ 323 // XComponent 324 //____________________________________________________________________________________________________________ 325 326 void SAL_CALL BaseControl::addEventListener( const Reference< XEventListener >& xListener ) throw( RuntimeException ) 327 { 328 // Ready for multithreading 329 MutexGuard aGuard( m_aMutex ); 330 OComponentHelper::addEventListener( xListener ); 331 } 332 333 //____________________________________________________________________________________________________________ 334 // XComponent 335 //____________________________________________________________________________________________________________ 336 337 void SAL_CALL BaseControl::removeEventListener( const Reference< XEventListener >& xListener ) throw( RuntimeException ) 338 { 339 // Ready for multithreading 340 MutexGuard aGuard( m_aMutex ); 341 OComponentHelper::removeEventListener( xListener ); 342 } 343 344 //____________________________________________________________________________________________________________ 345 // XControl 346 //____________________________________________________________________________________________________________ 347 348 void SAL_CALL BaseControl::createPeer( const Reference< XToolkit >& xToolkit , 349 const Reference< XWindowPeer >& xParentPeer ) throw( RuntimeException ) 350 { 351 // Ready for multithreading 352 MutexGuard aGuard( m_aMutex ); 353 354 if ( m_xPeer.is() == sal_False ) 355 { 356 // use method "BaseControl::getWindowDescriptor()" fot change window attributes !!! 357 WindowDescriptor* pDescriptor = impl_getWindowDescriptor( xParentPeer ); 358 359 if ( m_bVisible == sal_True ) 360 { 361 pDescriptor->WindowAttributes |= WindowAttribute::SHOW ; 362 } 363 364 // very slow under remote conditions! 365 // create the window on the server 366 Reference< XToolkit > xLocalToolkit = xToolkit ; 367 if ( xLocalToolkit.is() == sal_False ) 368 { 369 // but first create wellknown toolkit, if it not exist 370 xLocalToolkit = Reference< XToolkit > ( m_xFactory->createInstance( OUString::createFromAscii( SERVICE_VCLTOOLKIT ) ), UNO_QUERY ); 371 } 372 m_xPeer = xLocalToolkit->createWindow( *pDescriptor ); 373 m_xPeerWindow = Reference< XWindow >( m_xPeer, UNO_QUERY ); 374 375 // don't forget to release the memory! 376 delete pDescriptor ; 377 378 if ( m_xPeerWindow.is() == sal_True ) 379 { 380 if ( m_pMultiplexer != NULL ) 381 { 382 m_pMultiplexer->setPeer( m_xPeerWindow ); 383 } 384 385 // create new referenz to xgraphics for painting on a peer 386 // and add a paint listener 387 Reference< XDevice > xDevice( m_xPeerWindow, UNO_QUERY ); 388 389 if ( xDevice.is() == sal_True ) 390 { 391 m_xGraphicsPeer = xDevice->createGraphics(); 392 } 393 394 if ( m_xGraphicsPeer.is() == sal_True ) 395 { 396 addPaintListener( this ); 397 addWindowListener( this ); 398 } 399 400 // PosSize_POSSIZE defined in <stardiv/uno/awt/window.hxx> 401 m_xPeerWindow->setPosSize( m_nX, m_nY, m_nWidth, m_nHeight, PosSize::POSSIZE ); 402 m_xPeerWindow->setEnable( m_bEnable ); 403 m_xPeerWindow->setVisible( m_bVisible && !m_bInDesignMode ); 404 } 405 } 406 } 407 408 //____________________________________________________________________________________________________________ 409 // XControl 410 //____________________________________________________________________________________________________________ 411 412 void SAL_CALL BaseControl::setContext( const Reference< XInterface >& xContext ) throw( RuntimeException ) 413 { 414 // Ready for multithreading 415 MutexGuard aGuard( m_aMutex ); 416 m_xContext = xContext ; 417 } 418 419 //____________________________________________________________________________________________________________ 420 // XControl 421 //____________________________________________________________________________________________________________ 422 423 void SAL_CALL BaseControl::setDesignMode( sal_Bool bOn ) throw( RuntimeException ) 424 { 425 // Ready for multithreading 426 MutexGuard aGuard( m_aMutex ); 427 m_bInDesignMode = bOn ; 428 } 429 430 //____________________________________________________________________________________________________________ 431 // XControl 432 //____________________________________________________________________________________________________________ 433 434 Reference< XInterface > SAL_CALL BaseControl::getContext() throw( RuntimeException ) 435 { 436 // Ready for multithreading 437 MutexGuard aGuard( m_aMutex ); 438 return m_xContext ; 439 } 440 441 //____________________________________________________________________________________________________________ 442 // XControl 443 //____________________________________________________________________________________________________________ 444 445 Reference< XWindowPeer > SAL_CALL BaseControl::getPeer() throw( RuntimeException ) 446 { 447 // Ready for multithreading 448 MutexGuard aGuard( m_aMutex ); 449 return m_xPeer ; 450 } 451 452 //____________________________________________________________________________________________________________ 453 // XControl 454 //____________________________________________________________________________________________________________ 455 456 Reference< XView > SAL_CALL BaseControl::getView() throw( RuntimeException ) 457 { 458 // Ready for multithreading 459 MutexGuard aGuard( m_aMutex ); 460 return Reference< XView >( (OWeakObject*)this, UNO_QUERY ); 461 } 462 463 //____________________________________________________________________________________________________________ 464 // XControl 465 //____________________________________________________________________________________________________________ 466 467 sal_Bool SAL_CALL BaseControl::isDesignMode() throw( RuntimeException ) 468 { 469 // Ready for multithreading 470 MutexGuard aGuard( m_aMutex ); 471 return m_bInDesignMode ; 472 } 473 474 //____________________________________________________________________________________________________________ 475 // XControl 476 //____________________________________________________________________________________________________________ 477 478 sal_Bool SAL_CALL BaseControl::isTransparent() throw( RuntimeException ) 479 { 480 return sal_False ; 481 } 482 483 //____________________________________________________________________________________________________________ 484 // XWindow 485 //____________________________________________________________________________________________________________ 486 487 void SAL_CALL BaseControl::setPosSize( sal_Int32 nX , 488 sal_Int32 nY , 489 sal_Int32 nWidth , 490 sal_Int32 nHeight , 491 sal_Int16 nFlags ) throw( RuntimeException ) 492 { 493 // - change size and position of window and save the values 494 // - "nFlags" declared in <stardiv/uno/awt/window.hxx> ("#define PosSize_X .....") 495 496 // Ready for multithreading 497 MutexGuard aGuard( m_aMutex ); 498 499 sal_Bool bChanged = sal_False ; 500 501 if ( nFlags & PosSize::X ) 502 { 503 bChanged |= m_nX != nX, m_nX = nX ; 504 } 505 506 if ( nFlags & PosSize::Y ) 507 { 508 bChanged |= m_nY != nY, m_nY = nY ; 509 } 510 511 if ( nFlags & PosSize::WIDTH ) 512 { 513 bChanged |= m_nWidth != nWidth, m_nWidth = nWidth ; 514 } 515 516 if ( nFlags & PosSize::HEIGHT ) 517 { 518 bChanged |= m_nHeight != nHeight, m_nHeight = nHeight ; 519 } 520 521 if ( bChanged && m_xPeerWindow.is() ) 522 { 523 m_xPeerWindow->setPosSize( m_nX, m_nY, m_nWidth, m_nHeight, nFlags ); 524 } 525 } 526 527 //____________________________________________________________________________________________________________ 528 // XWindow 529 //____________________________________________________________________________________________________________ 530 531 void SAL_CALL BaseControl::setVisible( sal_Bool bVisible ) throw( RuntimeException ) 532 { 533 // Ready for multithreading 534 MutexGuard aGuard( m_aMutex ); 535 536 // Set new state of flag 537 m_bVisible = bVisible ; 538 539 if ( m_xPeerWindow.is() == sal_True ) 540 { 541 // Set it also on peerwindow 542 m_xPeerWindow->setVisible( m_bVisible ); 543 } 544 } 545 546 //____________________________________________________________________________________________________________ 547 // XWindow 548 //____________________________________________________________________________________________________________ 549 550 void SAL_CALL BaseControl::setEnable( sal_Bool bEnable ) throw( RuntimeException ) 551 { 552 // Ready for multithreading 553 MutexGuard aGuard( m_aMutex ); 554 555 // Set new state of flag 556 m_bEnable = bEnable ; 557 558 if ( m_xPeerWindow.is() == sal_True ) 559 { 560 // Set it also on peerwindow 561 m_xPeerWindow->setEnable( m_bEnable ); 562 } 563 } 564 565 //____________________________________________________________________________________________________________ 566 // XWindow 567 //____________________________________________________________________________________________________________ 568 569 void SAL_CALL BaseControl::setFocus() throw( RuntimeException ) 570 { 571 // Ready for multithreading 572 MutexGuard aGuard( m_aMutex ); 573 574 if ( m_xPeerWindow.is() == sal_True ) 575 { 576 m_xPeerWindow->setFocus(); 577 } 578 } 579 580 //____________________________________________________________________________________________________________ 581 // XWindow 582 //____________________________________________________________________________________________________________ 583 584 Rectangle SAL_CALL BaseControl::getPosSize() throw( RuntimeException ) 585 { 586 // Ready for multithreading 587 MutexGuard aGuard( m_aMutex ); 588 return Rectangle( m_nX, m_nY , m_nWidth, m_nHeight ); 589 } 590 591 //____________________________________________________________________________________________________________ 592 // XWindow 593 //____________________________________________________________________________________________________________ 594 595 void SAL_CALL BaseControl::addWindowListener( const Reference< XWindowListener >& xListener ) throw( RuntimeException ) 596 { 597 impl_getMultiplexer()->advise( ::getCppuType(( const Reference< XWindowListener >*)0), xListener ); 598 } 599 600 //____________________________________________________________________________________________________________ 601 // XWindow 602 //____________________________________________________________________________________________________________ 603 604 void SAL_CALL BaseControl::addFocusListener( const Reference< XFocusListener >& xListener ) throw( RuntimeException ) 605 { 606 impl_getMultiplexer()->advise( ::getCppuType(( const Reference< XFocusListener >*)0), xListener ); 607 } 608 609 //____________________________________________________________________________________________________________ 610 // XWindow 611 //____________________________________________________________________________________________________________ 612 613 void SAL_CALL BaseControl::addKeyListener( const Reference< XKeyListener >& xListener ) throw( RuntimeException ) 614 { 615 impl_getMultiplexer()->advise( ::getCppuType(( const Reference< XKeyListener >*)0), xListener ); 616 } 617 618 //____________________________________________________________________________________________________________ 619 // XWindow 620 //____________________________________________________________________________________________________________ 621 622 void SAL_CALL BaseControl::addMouseListener( const Reference< XMouseListener >& xListener ) throw( RuntimeException ) 623 { 624 impl_getMultiplexer()->advise( ::getCppuType(( const Reference< XMouseListener >*)0), xListener ); 625 } 626 627 //____________________________________________________________________________________________________________ 628 // XWindow 629 //____________________________________________________________________________________________________________ 630 631 void SAL_CALL BaseControl::addMouseMotionListener( const Reference< XMouseMotionListener >& xListener ) throw( RuntimeException ) 632 { 633 impl_getMultiplexer()->advise( ::getCppuType(( const Reference< XMouseMotionListener >*)0), xListener ); 634 } 635 636 //____________________________________________________________________________________________________________ 637 // XWindow 638 //____________________________________________________________________________________________________________ 639 640 void SAL_CALL BaseControl::addPaintListener( const Reference< XPaintListener >& xListener ) throw( RuntimeException ) 641 { 642 impl_getMultiplexer()->advise( ::getCppuType(( const Reference< XPaintListener >*)0), xListener ); 643 } 644 645 //____________________________________________________________________________________________________________ 646 // XWindow 647 //____________________________________________________________________________________________________________ 648 649 void SAL_CALL BaseControl::removeWindowListener( const Reference< XWindowListener >& xListener ) throw( RuntimeException ) 650 { 651 impl_getMultiplexer()->unadvise( ::getCppuType(( const Reference< XWindowListener >*)0), xListener ); 652 } 653 654 //____________________________________________________________________________________________________________ 655 // XWindow 656 //____________________________________________________________________________________________________________ 657 658 void SAL_CALL BaseControl::removeFocusListener( const Reference< XFocusListener >& xListener ) throw( RuntimeException ) 659 { 660 impl_getMultiplexer()->unadvise( ::getCppuType(( const Reference< XFocusListener >*)0), xListener ); 661 } 662 663 //____________________________________________________________________________________________________________ 664 // XWindow 665 //____________________________________________________________________________________________________________ 666 667 void SAL_CALL BaseControl::removeKeyListener( const Reference< XKeyListener >& xListener ) throw( RuntimeException ) 668 { 669 impl_getMultiplexer()->unadvise( ::getCppuType(( const Reference< XKeyListener >*)0), xListener ); 670 } 671 672 //____________________________________________________________________________________________________________ 673 // XWindow 674 //____________________________________________________________________________________________________________ 675 676 void SAL_CALL BaseControl::removeMouseListener( const Reference< XMouseListener >& xListener ) throw( RuntimeException ) 677 { 678 impl_getMultiplexer()->unadvise( ::getCppuType(( const Reference< XMouseListener >*)0), xListener ); 679 } 680 681 //____________________________________________________________________________________________________________ 682 // XWindow 683 //____________________________________________________________________________________________________________ 684 685 void SAL_CALL BaseControl::removeMouseMotionListener( const Reference< XMouseMotionListener >& xListener ) throw( RuntimeException ) 686 { 687 impl_getMultiplexer()->unadvise( ::getCppuType(( const Reference< XMouseMotionListener >*)0), xListener ); 688 } 689 690 //____________________________________________________________________________________________________________ 691 // XWindow 692 //____________________________________________________________________________________________________________ 693 694 void SAL_CALL BaseControl::removePaintListener( const Reference< XPaintListener >& xListener ) throw( RuntimeException ) 695 { 696 impl_getMultiplexer()->unadvise( ::getCppuType(( const Reference< XPaintListener >*)0), xListener ); 697 } 698 699 //____________________________________________________________________________________________________________ 700 // XView 701 //____________________________________________________________________________________________________________ 702 703 void SAL_CALL BaseControl::draw( sal_Int32 nX , 704 sal_Int32 nY ) throw( RuntimeException ) 705 { 706 // Ready for multithreading 707 MutexGuard aGuard( m_aMutex ); 708 709 // - paint to an view 710 // - use the method "paint()" 711 // - see also "windowPaint()" 712 impl_paint( nX, nY, m_xGraphicsView ); 713 } 714 715 //____________________________________________________________________________________________________________ 716 // XView 717 //____________________________________________________________________________________________________________ 718 719 sal_Bool SAL_CALL BaseControl::setGraphics( const Reference< XGraphics >& xDevice ) throw( RuntimeException ) 720 { 721 // - set the graphics for an view 722 // - in this class exist 2 graphics-member ... one for peer[_xGraphicsPeer] and one for view[_xGraphicsView] 723 // - they are used by "windowPaint() and draw()", forwarded to "paint ()" 724 sal_Bool bReturn = sal_False ; 725 if ( xDevice.is() == sal_True ) 726 { 727 // Ready for multithreading 728 MutexGuard aGuard( m_aMutex ); 729 730 m_xGraphicsView = xDevice ; 731 bReturn = sal_True ; 732 } 733 734 return bReturn ; 735 } 736 737 //____________________________________________________________________________________________________________ 738 // XView 739 //____________________________________________________________________________________________________________ 740 741 void SAL_CALL BaseControl::setZoom( float /*fZoomX*/ , 742 float /*fZoomY*/ ) throw( RuntimeException ) 743 { 744 // Not implemented yet 745 } 746 747 //____________________________________________________________________________________________________________ 748 // XView 749 //____________________________________________________________________________________________________________ 750 751 Reference< XGraphics > SAL_CALL BaseControl::getGraphics() throw( RuntimeException ) 752 { 753 // Ready for multithreading 754 MutexGuard aGuard( m_aMutex ); 755 return m_xGraphicsView ; 756 } 757 758 //____________________________________________________________________________________________________________ 759 // XView 760 //____________________________________________________________________________________________________________ 761 762 Size SAL_CALL BaseControl::getSize() throw( RuntimeException ) 763 { 764 // Ready for multithreading 765 MutexGuard aGuard( m_aMutex ); 766 return Size( m_nWidth, m_nHeight ); 767 } 768 769 //____________________________________________________________________________________________________________ 770 // XEventListener 771 //____________________________________________________________________________________________________________ 772 773 void SAL_CALL BaseControl::disposing( const EventObject& /*aSource*/ ) throw( RuntimeException ) 774 { 775 // Ready for multithreading 776 MutexGuard aGuard( m_aMutex ); 777 778 // - release ALL references 779 // - it must be !!! 780 if ( m_xGraphicsPeer.is() == sal_True ) 781 { 782 removePaintListener( this ); 783 removeWindowListener( this ); 784 m_xGraphicsPeer = Reference< XGraphics >(); 785 } 786 787 if ( m_xGraphicsView.is() == sal_True ) 788 { 789 m_xGraphicsView = Reference< XGraphics >(); 790 } 791 } 792 793 //____________________________________________________________________________________________________________ 794 // XPaintListener 795 //____________________________________________________________________________________________________________ 796 797 void SAL_CALL BaseControl::windowPaint( const PaintEvent& /*aEvent*/ ) throw( RuntimeException ) 798 { 799 // Ready for multithreading 800 MutexGuard aGuard( m_aMutex ); 801 802 // - repaint the peer 803 // - use the method "paint ()" for painting on a peer and a print device !!! 804 // - see also "draw ()" 805 impl_paint( 0, 0, m_xGraphicsPeer ); 806 } 807 808 //____________________________________________________________________________________________________________ 809 // XWindowListener 810 //____________________________________________________________________________________________________________ 811 812 void SAL_CALL BaseControl::windowResized( const WindowEvent& aEvent ) throw( RuntimeException ) 813 { 814 // Ready for multithreading 815 MutexGuard aGuard( m_aMutex ); 816 817 m_nWidth = aEvent.Width ; 818 m_nHeight = aEvent.Height ; 819 WindowEvent aMappedEvent = aEvent; 820 aMappedEvent.X = 0; 821 aMappedEvent.Y = 0; 822 impl_recalcLayout( aMappedEvent ); 823 } 824 825 //____________________________________________________________________________________________________________ 826 // XWindowListener 827 //____________________________________________________________________________________________________________ 828 829 void SAL_CALL BaseControl::windowMoved( const WindowEvent& aEvent ) throw( RuntimeException ) 830 { 831 // Ready for multithreading 832 MutexGuard aGuard( m_aMutex ); 833 834 m_nWidth = aEvent.Width ; 835 m_nHeight = aEvent.Height ; 836 WindowEvent aMappedEvent = aEvent; 837 aMappedEvent.X = 0; 838 aMappedEvent.Y = 0; 839 impl_recalcLayout( aMappedEvent ); 840 } 841 842 //____________________________________________________________________________________________________________ 843 // XWindowListener 844 //____________________________________________________________________________________________________________ 845 846 void SAL_CALL BaseControl::windowShown( const EventObject& /*aEvent*/ ) throw( RuntimeException ) 847 { 848 } 849 850 //____________________________________________________________________________________________________________ 851 // XWindowListener 852 //____________________________________________________________________________________________________________ 853 854 void SAL_CALL BaseControl::windowHidden( const EventObject& /*aEvent*/ ) throw( RuntimeException ) 855 { 856 } 857 858 //____________________________________________________________________________________________________________ 859 // impl but public method to register service in DLL 860 // (In this BASE-implementation not implemented! Overwrite it in derived classes.) 861 //____________________________________________________________________________________________________________ 862 863 const Sequence< OUString > BaseControl::impl_getStaticSupportedServiceNames() 864 { 865 return Sequence< OUString >(); 866 } 867 868 //____________________________________________________________________________________________________________ 869 // impl but public method to register service in DLL 870 // (In this BASE-implementation not implemented! Overwrite it in derived classes.) 871 //____________________________________________________________________________________________________________ 872 873 const OUString BaseControl::impl_getStaticImplementationName() 874 { 875 return OUString(); 876 } 877 878 //____________________________________________________________________________________________________________ 879 // protected method 880 //____________________________________________________________________________________________________________ 881 882 const Reference< XMultiServiceFactory > BaseControl::impl_getMultiServiceFactory() 883 { 884 return m_xFactory ; 885 } 886 887 //____________________________________________________________________________________________________________ 888 // protected method 889 //____________________________________________________________________________________________________________ 890 891 const Reference< XWindow > BaseControl::impl_getPeerWindow() 892 { 893 return m_xPeerWindow ; 894 } 895 896 //____________________________________________________________________________________________________________ 897 // protected method 898 //____________________________________________________________________________________________________________ 899 900 const Reference< XGraphics > BaseControl::impl_getGraphicsPeer() 901 { 902 return m_xGraphicsPeer ; 903 } 904 905 //____________________________________________________________________________________________________________ 906 // protected method 907 //____________________________________________________________________________________________________________ 908 909 const sal_Int32& BaseControl::impl_getWidth() 910 { 911 return m_nWidth ; 912 } 913 914 //____________________________________________________________________________________________________________ 915 // protected method 916 //____________________________________________________________________________________________________________ 917 918 const sal_Int32& BaseControl::impl_getHeight() 919 { 920 return m_nHeight ; 921 } 922 923 //____________________________________________________________________________________________________________ 924 // protected method 925 //____________________________________________________________________________________________________________ 926 927 WindowDescriptor* BaseControl::impl_getWindowDescriptor( const Reference< XWindowPeer >& xParentPeer ) 928 { 929 // - used from "createPeer()" to set the values of an ::com::sun::star::awt::WindowDescriptor !!! 930 // - if you will change the descriptor-values, you must override this virtuell function 931 // - the caller must release the memory for this dynamical descriptor !!! 932 933 WindowDescriptor* pDescriptor = new WindowDescriptor ; 934 935 pDescriptor->Type = WindowClass_SIMPLE ; 936 pDescriptor->WindowServiceName = OUString::createFromAscii( "window" ) ; 937 pDescriptor->ParentIndex = -1 ; 938 pDescriptor->Parent = xParentPeer ; 939 pDescriptor->Bounds = getPosSize () ; 940 pDescriptor->WindowAttributes = 0 ; 941 942 return pDescriptor ; 943 } 944 945 //____________________________________________________________________________________________________________ 946 // protected method 947 //____________________________________________________________________________________________________________ 948 949 void BaseControl::impl_paint( sal_Int32 /*nX*/ , 950 sal_Int32 /*nY*/ , 951 const Reference< XGraphics >& /*xGraphics*/ ) 952 { 953 // - one paint method for peer AND view !!! 954 // (see also => "windowPaint()" and "draw()") 955 // - not used in this implementation, but its not necessary to make it pure virtual !!! 956 } 957 958 //____________________________________________________________________________________________________________ 959 // protected method 960 //____________________________________________________________________________________________________________ 961 962 void BaseControl::impl_recalcLayout( const WindowEvent& /*aEvent*/ ) 963 { 964 // We need as virtual function to support automaticly resizing of derived controls! 965 // But we make it not pure virtual because it's not neccessary for all derived classes! 966 } 967 968 //____________________________________________________________________________________________________________ 969 // protected method 970 //____________________________________________________________________________________________________________ 971 972 Reference< XInterface > BaseControl::impl_getDelegator() 973 { 974 return m_xDelegator ; 975 } 976 977 //____________________________________________________________________________________________________________ 978 // private method 979 //____________________________________________________________________________________________________________ 980 981 void BaseControl::impl_releasePeer() 982 { 983 if ( m_xPeer.is() == sal_True ) 984 { 985 if ( m_xGraphicsPeer.is() == sal_True ) 986 { 987 removePaintListener( this ); 988 removeWindowListener( this ); 989 m_xGraphicsPeer = Reference< XGraphics >(); 990 } 991 992 m_xPeer->dispose(); 993 m_xPeerWindow = Reference< XWindow >(); 994 m_xPeer = Reference< XWindowPeer >(); 995 996 if ( m_pMultiplexer != NULL ) 997 { 998 // take changes on multiplexer 999 m_pMultiplexer->setPeer( Reference< XWindow >() ); 1000 } 1001 } 1002 } 1003 1004 //____________________________________________________________________________________________________________ 1005 // private method 1006 //____________________________________________________________________________________________________________ 1007 1008 OMRCListenerMultiplexerHelper* BaseControl::impl_getMultiplexer() 1009 { 1010 if ( m_pMultiplexer == NULL ) 1011 { 1012 m_pMultiplexer = new OMRCListenerMultiplexerHelper( (XWindow*)this, m_xPeerWindow ); 1013 m_xMultiplexer = Reference< XInterface >( (OWeakObject*)m_pMultiplexer, UNO_QUERY ); 1014 } 1015 1016 return m_pMultiplexer ; 1017 } 1018 1019 } // namespace unocontrols 1020