1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef _UNOCONTROLS_MULTIPLEXER_HXX 25 #define _UNOCONTROLS_MULTIPLEXER_HXX 26 27 //____________________________________________________________________________________________________________ 28 // includes of other projects 29 //____________________________________________________________________________________________________________ 30 31 #include <com/sun/star/awt/XKeyListener.hpp> 32 #include <com/sun/star/awt/XPaintListener.hpp> 33 #include <com/sun/star/awt/KeyEvent.hpp> 34 #include <com/sun/star/awt/KeyModifier.hpp> 35 #include <com/sun/star/awt/XMouseMotionListener.hpp> 36 #include <com/sun/star/awt/FocusEvent.hpp> 37 #include <com/sun/star/awt/XWindowListener.hpp> 38 #include <com/sun/star/awt/XActivateListener.hpp> 39 #include <com/sun/star/awt/MouseEvent.hpp> 40 #include <com/sun/star/awt/XTopWindowListener.hpp> 41 #include <com/sun/star/awt/PaintEvent.hpp> 42 #include <com/sun/star/awt/InputEvent.hpp> 43 #include <com/sun/star/awt/KeyGroup.hpp> 44 #include <com/sun/star/awt/Key.hpp> 45 #include <com/sun/star/awt/WindowEvent.hpp> 46 #include <com/sun/star/awt/XMouseListener.hpp> 47 #include <com/sun/star/awt/KeyFunction.hpp> 48 #include <com/sun/star/awt/FocusChangeReason.hpp> 49 #include <com/sun/star/awt/MouseButton.hpp> 50 #include <com/sun/star/awt/XFocusListener.hpp> 51 #include <com/sun/star/awt/XTopWindow.hpp> 52 #include <com/sun/star/awt/XWindow.hpp> 53 #include <com/sun/star/awt/PosSize.hpp> 54 #include <cppuhelper/weak.hxx> 55 #include <cppuhelper/interfacecontainer.hxx> 56 //____________________________________________________________________________________________________________ 57 // includes of my own project 58 //____________________________________________________________________________________________________________ 59 60 //____________________________________________________________________________________________________________ 61 // "namespaces" 62 //____________________________________________________________________________________________________________ 63 64 namespace unocontrols{ 65 66 #define UNO3_OWEAKOBJECT ::cppu::OWeakObject 67 #define UNO3_XWINDOW ::com::sun::star::awt::XWindow 68 #define UNO3_REFERENCE ::com::sun::star::uno::Reference 69 #define UNO3_WEAKREFERENCE ::com::sun::star::uno::WeakReference 70 #define UNO3_MUTEX ::osl::Mutex 71 #define UNO3_XWINDOWLISTENER ::com::sun::star::awt::XWindowListener 72 #define UNO3_XKEYLISTENER ::com::sun::star::awt::XKeyListener 73 #define UNO3_XMOUSELISTENER ::com::sun::star::awt::XMouseListener 74 #define UNO3_XMOUSEMOTIONLISTENER ::com::sun::star::awt::XMouseMotionListener 75 #define UNO3_XPAINTLISTENER ::com::sun::star::awt::XPaintListener 76 #define UNO3_XTOPWINDOWLISTENER ::com::sun::star::awt::XTopWindowListener 77 #define UNO3_XFOCUSLISTENER ::com::sun::star::awt::XFocusListener 78 #define UNO3_ANY ::com::sun::star::uno::Any 79 #define UNO3_TYPE ::com::sun::star::uno::Type 80 #define UNO3_RUNTIMEEXCEPTION ::com::sun::star::uno::RuntimeException 81 #define UNO3_XINTERFACE ::com::sun::star::uno::XInterface 82 #define UNO3_EVENTOBJECT ::com::sun::star::lang::EventObject 83 #define UNO3_FOCUSEVENT ::com::sun::star::awt::FocusEvent 84 #define UNO3_WINDOWEVENT ::com::sun::star::awt::WindowEvent 85 #define UNO3_KEYEVENT ::com::sun::star::awt::KeyEvent 86 #define UNO3_MOUSEEVENT ::com::sun::star::awt::MouseEvent 87 #define UNO3_PAINTEVENT ::com::sun::star::awt::PaintEvent 88 #define UNO3_OMULTITYPEINTERFACECONTAINERHELPER ::cppu::OMultiTypeInterfaceContainerHelper 89 90 //____________________________________________________________________________________________________________ 91 // class 92 //____________________________________________________________________________________________________________ 93 94 class OMRCListenerMultiplexerHelper : public UNO3_XFOCUSLISTENER 95 , public UNO3_XWINDOWLISTENER 96 , public UNO3_XKEYLISTENER 97 , public UNO3_XMOUSELISTENER 98 , public UNO3_XMOUSEMOTIONLISTENER 99 , public UNO3_XPAINTLISTENER 100 , public UNO3_XTOPWINDOWLISTENER 101 , public UNO3_OWEAKOBJECT 102 { 103 104 //____________________________________________________________________________________________________________ 105 // public methods 106 //____________________________________________________________________________________________________________ 107 108 public: 109 110 //________________________________________________________________________________________________________ 111 // construct/destruct 112 //________________________________________________________________________________________________________ 113 114 /**_______________________________________________________________________________________________________ 115 @short constructor 116 @descr Create a Multiplexer of XWindowEvents. 117 118 @seealso - 119 120 @param rControl The control. All listeners think that this is the original broadcaster. 121 @param rPeer The peer from which the original events are dispatched. Null is allowed. 122 123 @return - 124 125 @onerror - 126 */ 127 128 OMRCListenerMultiplexerHelper( const UNO3_REFERENCE< UNO3_XWINDOW >& xControl , 129 const UNO3_REFERENCE< UNO3_XWINDOW >& xPeer ); 130 131 /**_______________________________________________________________________________________________________ 132 @short copy-constructor 133 @descr 134 135 @seealso - 136 137 @param rCopyInstance C++-Reference to instance to make copy from. 138 139 @return - 140 141 @onerror - 142 */ 143 144 OMRCListenerMultiplexerHelper( const OMRCListenerMultiplexerHelper& aCopyInstance ); 145 146 /**_______________________________________________________________________________________________________ 147 @short destructor 148 @descr - 149 150 @seealso - 151 152 @param - 153 154 @return - 155 156 @onerror - 157 */ 158 159 ~OMRCListenerMultiplexerHelper(); 160 161 //________________________________________________________________________________________________________ 162 // XInterface 163 //________________________________________________________________________________________________________ 164 165 /**_______________________________________________________________________________________________________ 166 @short give answer, if interface is supported 167 @descr The interfaces are searched by type. 168 169 @seealso XInterface 170 171 @param "rType" is the type of searched interface. 172 173 @return Any information about found interface 174 175 @onerror A RuntimeException is thrown. 176 */ 177 178 virtual UNO3_ANY SAL_CALL queryInterface( const UNO3_TYPE& aType ) throw( UNO3_RUNTIMEEXCEPTION ); 179 180 /**_______________________________________________________________________________________________________ 181 @short increment refcount 182 @descr - 183 184 @seealso XInterface 185 @seealso release() 186 187 @param - 188 189 @return - 190 191 @onerror A RuntimeException is thrown. 192 */ 193 194 virtual void SAL_CALL acquire() throw(); 195 196 /**_______________________________________________________________________________________________________ 197 @short decrement refcount 198 @descr - 199 200 @seealso XInterface 201 @seealso acquire() 202 203 @param - 204 205 @return - 206 207 @onerror A RuntimeException is thrown. 208 */ 209 210 virtual void SAL_CALL release() throw(); 211 212 //________________________________________________________________________________________________________ 213 // operator 214 //________________________________________________________________________________________________________ 215 216 /**_______________________________________________________________________________________________________ 217 @short - 218 @descr - 219 220 @seealso - 221 222 @param - 223 224 @return - 225 226 @onerror - 227 */ 228 229 operator UNO3_REFERENCE< UNO3_XINTERFACE >() const; 230 231 /**_______________________________________________________________________________________________________ 232 @short - 233 @descr - 234 235 @seealso - 236 237 @param - 238 239 @return - 240 241 @onerror - 242 */ 243 244 OMRCListenerMultiplexerHelper& operator= ( const OMRCListenerMultiplexerHelper& aCopyInstance ); 245 246 //________________________________________________________________________________________________________ 247 // container methods 248 //________________________________________________________________________________________________________ 249 250 /**_______________________________________________________________________________________________________ 251 @short Remove all listeners from the previous set peer and add the needed listeners to rPeer. 252 @descr - 253 254 @seealso - 255 256 @param rPeer The peer from which the original events are dispatched. Null is allowed. 257 258 @return - 259 260 @onerror - 261 */ 262 263 void setPeer( const UNO3_REFERENCE< UNO3_XWINDOW >& xPeer ); 264 265 /**_______________________________________________________________________________________________________ 266 @short Remove all listeners and send a disposing message. 267 @descr - 268 269 @seealso - 270 271 @param - 272 273 @return - 274 275 @onerror - 276 */ 277 278 void disposeAndClear(); 279 280 /**_______________________________________________________________________________________________________ 281 @short Add the specified listener to the source. 282 @descr - 283 284 @seealso - 285 286 @param - 287 288 @return - 289 290 @onerror - 291 */ 292 293 void advise( const UNO3_TYPE& aType , 294 const UNO3_REFERENCE< UNO3_XINTERFACE >& xListener ); 295 296 /**_______________________________________________________________________________________________________ 297 @short Remove the specified listener from the source. 298 @descr - 299 300 @seealso - 301 302 @param - 303 304 @return - 305 306 @onerror - 307 */ 308 309 void unadvise( const UNO3_TYPE& aType , 310 const UNO3_REFERENCE< UNO3_XINTERFACE >& xListener ); 311 312 //________________________________________________________________________________________________________ 313 // XEventListener 314 //________________________________________________________________________________________________________ 315 316 /**_______________________________________________________________________________________________________ 317 @short - 318 @descr - 319 320 @seealso - 321 @seealso - 322 323 @param - 324 325 @return - 326 327 @onerror - 328 */ 329 330 virtual void SAL_CALL disposing(const UNO3_EVENTOBJECT& aSource) throw( UNO3_RUNTIMEEXCEPTION ) ; 331 332 //________________________________________________________________________________________________________ 333 // XFocusListener 334 //________________________________________________________________________________________________________ 335 336 /**_______________________________________________________________________________________________________ 337 @short - 338 @descr - 339 340 @seealso - 341 @seealso - 342 343 @param - 344 345 @return - 346 347 @onerror - 348 */ 349 350 virtual void SAL_CALL focusGained(const UNO3_FOCUSEVENT& aEvent ) throw( UNO3_RUNTIMEEXCEPTION ) ; 351 352 /**_______________________________________________________________________________________________________ 353 @short - 354 @descr - 355 356 @seealso - 357 @seealso - 358 359 @param - 360 361 @return - 362 363 @onerror - 364 */ 365 366 virtual void SAL_CALL focusLost(const UNO3_FOCUSEVENT& aEvent ) throw( UNO3_RUNTIMEEXCEPTION ) ; 367 368 //________________________________________________________________________________________________________ 369 // XWindowListener 370 //________________________________________________________________________________________________________ 371 372 /**_______________________________________________________________________________________________________ 373 @short - 374 @descr - 375 376 @seealso - 377 @seealso - 378 379 @param - 380 381 @return - 382 383 @onerror - 384 */ 385 386 virtual void SAL_CALL windowResized(const UNO3_WINDOWEVENT& aEvent ) throw( UNO3_RUNTIMEEXCEPTION ) ; 387 388 /**_______________________________________________________________________________________________________ 389 @short - 390 @descr - 391 392 @seealso - 393 @seealso - 394 395 @param - 396 397 @return - 398 399 @onerror - 400 */ 401 402 virtual void SAL_CALL windowMoved(const UNO3_WINDOWEVENT& aEvent ) throw( UNO3_RUNTIMEEXCEPTION ) ; 403 404 /**_______________________________________________________________________________________________________ 405 @short - 406 @descr - 407 408 @seealso - 409 @seealso - 410 411 @param - 412 413 @return - 414 415 @onerror - 416 */ 417 418 virtual void SAL_CALL windowShown(const UNO3_EVENTOBJECT& aEvent ) throw( UNO3_RUNTIMEEXCEPTION ) ; 419 420 /**_______________________________________________________________________________________________________ 421 @short - 422 @descr - 423 424 @seealso - 425 @seealso - 426 427 @param - 428 429 @return - 430 431 @onerror - 432 */ 433 434 virtual void SAL_CALL windowHidden(const UNO3_EVENTOBJECT& aEvent ) throw( UNO3_RUNTIMEEXCEPTION ) ; 435 436 //________________________________________________________________________________________________________ 437 // XKeyListener 438 //________________________________________________________________________________________________________ 439 440 /**_______________________________________________________________________________________________________ 441 @short - 442 @descr - 443 444 @seealso - 445 @seealso - 446 447 @param - 448 449 @return - 450 451 @onerror - 452 */ 453 454 virtual void SAL_CALL keyPressed( const UNO3_KEYEVENT& aEvent ) throw( UNO3_RUNTIMEEXCEPTION ) ; 455 456 /**_______________________________________________________________________________________________________ 457 @short - 458 @descr - 459 460 @seealso - 461 @seealso - 462 463 @param - 464 465 @return - 466 467 @onerror - 468 */ 469 470 virtual void SAL_CALL keyReleased( const UNO3_KEYEVENT& aEvent ) throw( UNO3_RUNTIMEEXCEPTION ) ; 471 472 //________________________________________________________________________________________________________ 473 // XMouseListener 474 //________________________________________________________________________________________________________ 475 476 /**_______________________________________________________________________________________________________ 477 @short - 478 @descr - 479 480 @seealso - 481 @seealso - 482 483 @param - 484 485 @return - 486 487 @onerror - 488 */ 489 490 virtual void SAL_CALL mousePressed(const UNO3_MOUSEEVENT& aEvent ) throw( UNO3_RUNTIMEEXCEPTION ) ; 491 492 /**_______________________________________________________________________________________________________ 493 @short - 494 @descr - 495 496 @seealso - 497 @seealso - 498 499 @param - 500 501 @return - 502 503 @onerror - 504 */ 505 506 virtual void SAL_CALL mouseReleased(const UNO3_MOUSEEVENT& aEvent ) throw( UNO3_RUNTIMEEXCEPTION ) ; 507 508 /**_______________________________________________________________________________________________________ 509 @short - 510 @descr - 511 512 @seealso - 513 @seealso - 514 515 @param - 516 517 @return - 518 519 @onerror - 520 */ 521 522 virtual void SAL_CALL mouseEntered(const UNO3_MOUSEEVENT& aEvent ) throw( UNO3_RUNTIMEEXCEPTION ) ; 523 524 /**_______________________________________________________________________________________________________ 525 @short - 526 @descr - 527 528 @seealso - 529 @seealso - 530 531 @param - 532 533 @return - 534 535 @onerror - 536 */ 537 538 virtual void SAL_CALL mouseExited(const UNO3_MOUSEEVENT& aEvent ) throw( UNO3_RUNTIMEEXCEPTION ) ; 539 540 //________________________________________________________________________________________________________ 541 // XMouseMotionListener 542 //________________________________________________________________________________________________________ 543 544 /**_______________________________________________________________________________________________________ 545 @short - 546 @descr - 547 548 @seealso - 549 @seealso - 550 551 @param - 552 553 @return - 554 555 @onerror - 556 */ 557 558 virtual void SAL_CALL mouseDragged(const UNO3_MOUSEEVENT& aEvent ) throw( UNO3_RUNTIMEEXCEPTION ) ; 559 560 /**_______________________________________________________________________________________________________ 561 @short - 562 @descr - 563 564 @seealso - 565 @seealso - 566 567 @param - 568 569 @return - 570 571 @onerror - 572 */ 573 574 virtual void SAL_CALL mouseMoved(const UNO3_MOUSEEVENT& aEvent ) throw( UNO3_RUNTIMEEXCEPTION ) ; 575 576 //________________________________________________________________________________________________________ 577 // XPaintListener 578 //________________________________________________________________________________________________________ 579 580 /**_______________________________________________________________________________________________________ 581 @short - 582 @descr - 583 584 @seealso - 585 @seealso - 586 587 @param - 588 589 @return - 590 591 @onerror - 592 */ 593 594 virtual void SAL_CALL windowPaint(const UNO3_PAINTEVENT& aEvent ) throw( UNO3_RUNTIMEEXCEPTION ) ; 595 596 //________________________________________________________________________________________________________ 597 // XTopWindowListener 598 //________________________________________________________________________________________________________ 599 600 /**_______________________________________________________________________________________________________ 601 @short - 602 @descr - 603 604 @seealso - 605 @seealso - 606 607 @param - 608 609 @return - 610 611 @onerror - 612 */ 613 614 virtual void SAL_CALL windowOpened( const UNO3_EVENTOBJECT& aEvent ) throw( UNO3_RUNTIMEEXCEPTION ) ; 615 616 /**_______________________________________________________________________________________________________ 617 @short - 618 @descr - 619 620 @seealso - 621 @seealso - 622 623 @param - 624 625 @return - 626 627 @onerror - 628 */ 629 630 virtual void SAL_CALL windowClosing( const UNO3_EVENTOBJECT& aEvent ) throw( UNO3_RUNTIMEEXCEPTION ) ; 631 632 /**_______________________________________________________________________________________________________ 633 @short - 634 @descr - 635 636 @seealso - 637 @seealso - 638 639 @param - 640 641 @return - 642 643 @onerror - 644 */ 645 646 virtual void SAL_CALL windowClosed( const UNO3_EVENTOBJECT& aEvent ) throw( UNO3_RUNTIMEEXCEPTION ) ; 647 648 /**_______________________________________________________________________________________________________ 649 @short - 650 @descr - 651 652 @seealso - 653 @seealso - 654 655 @param - 656 657 @return - 658 659 @onerror - 660 */ 661 662 virtual void SAL_CALL windowMinimized( const UNO3_EVENTOBJECT& aEvent ) throw( UNO3_RUNTIMEEXCEPTION ) ; 663 664 /**_______________________________________________________________________________________________________ 665 @short - 666 @descr - 667 668 @seealso - 669 @seealso - 670 671 @param - 672 673 @return - 674 675 @onerror - 676 */ 677 678 virtual void SAL_CALL windowNormalized( const UNO3_EVENTOBJECT& aEvent ) throw( UNO3_RUNTIMEEXCEPTION ) ; 679 680 /**_______________________________________________________________________________________________________ 681 @short - 682 @descr - 683 684 @seealso - 685 @seealso - 686 687 @param - 688 689 @return - 690 691 @onerror - 692 */ 693 694 virtual void SAL_CALL windowActivated( const UNO3_EVENTOBJECT& aEvent ) throw( UNO3_RUNTIMEEXCEPTION ) ; 695 696 /**_______________________________________________________________________________________________________ 697 @short - 698 @descr - 699 700 @seealso - 701 @seealso - 702 703 @param - 704 705 @return - 706 707 @onerror - 708 */ 709 710 virtual void SAL_CALL windowDeactivated( const UNO3_EVENTOBJECT& aEvent ) throw( UNO3_RUNTIMEEXCEPTION ) ; 711 712 //____________________________________________________________________________________________________________ 713 // protected methods 714 //____________________________________________________________________________________________________________ 715 716 protected: 717 718 /**_______________________________________________________________________________________________________ 719 @short Remove the listener from the peer. 720 @descr - 721 722 @seealso - 723 724 @param xPeer The peer from which the listener is removed. 725 @param rType The listener type, which specify the type of the listener. 726 727 @return - 728 729 @onerror - 730 */ 731 732 void impl_adviseToPeer( const UNO3_REFERENCE< UNO3_XWINDOW >& xPeer , 733 const UNO3_TYPE& aType ); 734 735 /**_______________________________________________________________________________________________________ 736 @short Add the listener to the peer. 737 @descr - 738 739 @seealso - 740 741 @param xPeer The peer to which the listener is added. 742 @param rType The listener type, which specify the type of the listener. 743 744 @return - 745 746 @onerror - 747 */ 748 749 void impl_unadviseFromPeer( const UNO3_REFERENCE< UNO3_XWINDOW >& xPeer , 750 const UNO3_TYPE& aType ); 751 752 //____________________________________________________________________________________________________________ 753 // private variables 754 //____________________________________________________________________________________________________________ 755 756 private: 757 758 UNO3_MUTEX m_aMutex ; 759 UNO3_REFERENCE< UNO3_XWINDOW > m_xPeer ; /// The source of the events. Normally this is the peer object. 760 UNO3_WEAKREFERENCE< UNO3_XWINDOW > m_xControl ; 761 UNO3_OMULTITYPEINTERFACECONTAINERHELPER m_aListenerHolder ; 762 763 }; // class OMRCListenerMultiplexerHelper 764 765 } // namespace unocontrols 766 767 #endif // ifndef _UNOCONTROLS_MULTIPLEXER_HXX 768