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