1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: multiplexer.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _UNOCONTROLS_MULTIPLEXER_HXX
32 #define _UNOCONTROLS_MULTIPLEXER_HXX
34 //____________________________________________________________________________________________________________
35 // includes of other projects
36 //____________________________________________________________________________________________________________
38 #include <com/sun/star/awt/XKeyListener.hpp>
39 #include <com/sun/star/awt/XPaintListener.hpp>
40 #include <com/sun/star/awt/KeyEvent.hpp>
41 #include <com/sun/star/awt/KeyModifier.hpp>
42 #include <com/sun/star/awt/XMouseMotionListener.hpp>
43 #include <com/sun/star/awt/FocusEvent.hpp>
44 #include <com/sun/star/awt/XWindowListener.hpp>
45 #include <com/sun/star/awt/XActivateListener.hpp>
46 #include <com/sun/star/awt/MouseEvent.hpp>
47 #include <com/sun/star/awt/XTopWindowListener.hpp>
48 #include <com/sun/star/awt/PaintEvent.hpp>
49 #include <com/sun/star/awt/InputEvent.hpp>
50 #include <com/sun/star/awt/KeyGroup.hpp>
51 #include <com/sun/star/awt/Key.hpp>
52 #include <com/sun/star/awt/WindowEvent.hpp>
53 #include <com/sun/star/awt/XMouseListener.hpp>
54 #include <com/sun/star/awt/KeyFunction.hpp>
55 #include <com/sun/star/awt/FocusChangeReason.hpp>
56 #include <com/sun/star/awt/MouseButton.hpp>
57 #include <com/sun/star/awt/XFocusListener.hpp>
58 #include <com/sun/star/awt/XTopWindow.hpp>
59 #include <com/sun/star/awt/XWindow.hpp>
60 #include <com/sun/star/awt/PosSize.hpp>
61 #include <cppuhelper/weak.hxx>
62 #include <cppuhelper/interfacecontainer.hxx>
63 //____________________________________________________________________________________________________________
64 // includes of my own project
65 //____________________________________________________________________________________________________________
67 //____________________________________________________________________________________________________________
69 //____________________________________________________________________________________________________________
71 namespace unocontrols
{
73 #define UNO3_OWEAKOBJECT ::cppu::OWeakObject
74 #define UNO3_XWINDOW ::com::sun::star::awt::XWindow
75 #define UNO3_REFERENCE ::com::sun::star::uno::Reference
76 #define UNO3_WEAKREFERENCE ::com::sun::star::uno::WeakReference
77 #define UNO3_MUTEX ::osl::Mutex
78 #define UNO3_XWINDOWLISTENER ::com::sun::star::awt::XWindowListener
79 #define UNO3_XKEYLISTENER ::com::sun::star::awt::XKeyListener
80 #define UNO3_XMOUSELISTENER ::com::sun::star::awt::XMouseListener
81 #define UNO3_XMOUSEMOTIONLISTENER ::com::sun::star::awt::XMouseMotionListener
82 #define UNO3_XPAINTLISTENER ::com::sun::star::awt::XPaintListener
83 #define UNO3_XTOPWINDOWLISTENER ::com::sun::star::awt::XTopWindowListener
84 #define UNO3_XFOCUSLISTENER ::com::sun::star::awt::XFocusListener
85 #define UNO3_ANY ::com::sun::star::uno::Any
86 #define UNO3_TYPE ::com::sun::star::uno::Type
87 #define UNO3_RUNTIMEEXCEPTION ::com::sun::star::uno::RuntimeException
88 #define UNO3_XINTERFACE ::com::sun::star::uno::XInterface
89 #define UNO3_EVENTOBJECT ::com::sun::star::lang::EventObject
90 #define UNO3_FOCUSEVENT ::com::sun::star::awt::FocusEvent
91 #define UNO3_WINDOWEVENT ::com::sun::star::awt::WindowEvent
92 #define UNO3_KEYEVENT ::com::sun::star::awt::KeyEvent
93 #define UNO3_MOUSEEVENT ::com::sun::star::awt::MouseEvent
94 #define UNO3_PAINTEVENT ::com::sun::star::awt::PaintEvent
95 #define UNO3_OMULTITYPEINTERFACECONTAINERHELPER ::cppu::OMultiTypeInterfaceContainerHelper
97 //____________________________________________________________________________________________________________
99 //____________________________________________________________________________________________________________
101 class OMRCListenerMultiplexerHelper
: public UNO3_XFOCUSLISTENER
102 , public UNO3_XWINDOWLISTENER
103 , public UNO3_XKEYLISTENER
104 , public UNO3_XMOUSELISTENER
105 , public UNO3_XMOUSEMOTIONLISTENER
106 , public UNO3_XPAINTLISTENER
107 , public UNO3_XTOPWINDOWLISTENER
108 , public UNO3_OWEAKOBJECT
111 //____________________________________________________________________________________________________________
113 //____________________________________________________________________________________________________________
117 //________________________________________________________________________________________________________
118 // construct/destruct
119 //________________________________________________________________________________________________________
121 /**_______________________________________________________________________________________________________
123 @descr Create a Multiplexer of XWindowEvents.
127 @param rControl The control. All listeners think that this is the original broadcaster.
128 @param rPeer The peer from which the original events are dispatched. Null is allowed.
135 OMRCListenerMultiplexerHelper( const UNO3_REFERENCE
< UNO3_XWINDOW
>& xControl
,
136 const UNO3_REFERENCE
< UNO3_XWINDOW
>& xPeer
);
138 /**_______________________________________________________________________________________________________
139 @short copy-constructor
144 @param rCopyInstance C++-Reference to instance to make copy from.
151 OMRCListenerMultiplexerHelper( const OMRCListenerMultiplexerHelper
& aCopyInstance
);
153 /**_______________________________________________________________________________________________________
166 ~OMRCListenerMultiplexerHelper();
168 //________________________________________________________________________________________________________
170 //________________________________________________________________________________________________________
172 /**_______________________________________________________________________________________________________
173 @short give answer, if interface is supported
174 @descr The interfaces are searched by type.
178 @param "rType" is the type of searched interface.
180 @return Any information about found interface
182 @onerror A RuntimeException is thrown.
185 virtual UNO3_ANY SAL_CALL
queryInterface( const UNO3_TYPE
& aType
) throw( UNO3_RUNTIMEEXCEPTION
);
187 /**_______________________________________________________________________________________________________
188 @short increment refcount
198 @onerror A RuntimeException is thrown.
201 virtual void SAL_CALL
acquire() throw();
203 /**_______________________________________________________________________________________________________
204 @short decrement refcount
214 @onerror A RuntimeException is thrown.
217 virtual void SAL_CALL
release() throw();
219 //________________________________________________________________________________________________________
221 //________________________________________________________________________________________________________
223 /**_______________________________________________________________________________________________________
236 operator UNO3_REFERENCE
< UNO3_XINTERFACE
>() const;
238 /**_______________________________________________________________________________________________________
251 OMRCListenerMultiplexerHelper
& operator= ( const OMRCListenerMultiplexerHelper
& aCopyInstance
);
253 //________________________________________________________________________________________________________
255 //________________________________________________________________________________________________________
257 /**_______________________________________________________________________________________________________
258 @short Remove all listeners from the previous set peer and add the needed listeners to rPeer.
263 @param rPeer The peer from which the original events are dispatched. Null is allowed.
270 void setPeer( const UNO3_REFERENCE
< UNO3_XWINDOW
>& xPeer
);
272 /**_______________________________________________________________________________________________________
273 @short Remove all listeners and send a disposing message.
285 void disposeAndClear();
287 /**_______________________________________________________________________________________________________
288 @short Add the specified listener to the source.
300 void advise( const UNO3_TYPE
& aType
,
301 const UNO3_REFERENCE
< UNO3_XINTERFACE
>& xListener
);
303 /**_______________________________________________________________________________________________________
304 @short Remove the specified listener from the source.
316 void unadvise( const UNO3_TYPE
& aType
,
317 const UNO3_REFERENCE
< UNO3_XINTERFACE
>& xListener
);
319 //________________________________________________________________________________________________________
321 //________________________________________________________________________________________________________
323 /**_______________________________________________________________________________________________________
337 virtual void SAL_CALL
disposing(const UNO3_EVENTOBJECT
& aSource
) throw( UNO3_RUNTIMEEXCEPTION
) ;
339 //________________________________________________________________________________________________________
341 //________________________________________________________________________________________________________
343 /**_______________________________________________________________________________________________________
357 virtual void SAL_CALL
focusGained(const UNO3_FOCUSEVENT
& aEvent
) throw( UNO3_RUNTIMEEXCEPTION
) ;
359 /**_______________________________________________________________________________________________________
373 virtual void SAL_CALL
focusLost(const UNO3_FOCUSEVENT
& aEvent
) throw( UNO3_RUNTIMEEXCEPTION
) ;
375 //________________________________________________________________________________________________________
377 //________________________________________________________________________________________________________
379 /**_______________________________________________________________________________________________________
393 virtual void SAL_CALL
windowResized(const UNO3_WINDOWEVENT
& aEvent
) throw( UNO3_RUNTIMEEXCEPTION
) ;
395 /**_______________________________________________________________________________________________________
409 virtual void SAL_CALL
windowMoved(const UNO3_WINDOWEVENT
& aEvent
) throw( UNO3_RUNTIMEEXCEPTION
) ;
411 /**_______________________________________________________________________________________________________
425 virtual void SAL_CALL
windowShown(const UNO3_EVENTOBJECT
& aEvent
) throw( UNO3_RUNTIMEEXCEPTION
) ;
427 /**_______________________________________________________________________________________________________
441 virtual void SAL_CALL
windowHidden(const UNO3_EVENTOBJECT
& aEvent
) throw( UNO3_RUNTIMEEXCEPTION
) ;
443 //________________________________________________________________________________________________________
445 //________________________________________________________________________________________________________
447 /**_______________________________________________________________________________________________________
461 virtual void SAL_CALL
keyPressed( const UNO3_KEYEVENT
& aEvent
) throw( UNO3_RUNTIMEEXCEPTION
) ;
463 /**_______________________________________________________________________________________________________
477 virtual void SAL_CALL
keyReleased( const UNO3_KEYEVENT
& aEvent
) throw( UNO3_RUNTIMEEXCEPTION
) ;
479 //________________________________________________________________________________________________________
481 //________________________________________________________________________________________________________
483 /**_______________________________________________________________________________________________________
497 virtual void SAL_CALL
mousePressed(const UNO3_MOUSEEVENT
& aEvent
) throw( UNO3_RUNTIMEEXCEPTION
) ;
499 /**_______________________________________________________________________________________________________
513 virtual void SAL_CALL
mouseReleased(const UNO3_MOUSEEVENT
& aEvent
) throw( UNO3_RUNTIMEEXCEPTION
) ;
515 /**_______________________________________________________________________________________________________
529 virtual void SAL_CALL
mouseEntered(const UNO3_MOUSEEVENT
& aEvent
) throw( UNO3_RUNTIMEEXCEPTION
) ;
531 /**_______________________________________________________________________________________________________
545 virtual void SAL_CALL
mouseExited(const UNO3_MOUSEEVENT
& aEvent
) throw( UNO3_RUNTIMEEXCEPTION
) ;
547 //________________________________________________________________________________________________________
548 // XMouseMotionListener
549 //________________________________________________________________________________________________________
551 /**_______________________________________________________________________________________________________
565 virtual void SAL_CALL
mouseDragged(const UNO3_MOUSEEVENT
& aEvent
) throw( UNO3_RUNTIMEEXCEPTION
) ;
567 /**_______________________________________________________________________________________________________
581 virtual void SAL_CALL
mouseMoved(const UNO3_MOUSEEVENT
& aEvent
) throw( UNO3_RUNTIMEEXCEPTION
) ;
583 //________________________________________________________________________________________________________
585 //________________________________________________________________________________________________________
587 /**_______________________________________________________________________________________________________
601 virtual void SAL_CALL
windowPaint(const UNO3_PAINTEVENT
& aEvent
) throw( UNO3_RUNTIMEEXCEPTION
) ;
603 //________________________________________________________________________________________________________
604 // XTopWindowListener
605 //________________________________________________________________________________________________________
607 /**_______________________________________________________________________________________________________
621 virtual void SAL_CALL
windowOpened( const UNO3_EVENTOBJECT
& aEvent
) throw( UNO3_RUNTIMEEXCEPTION
) ;
623 /**_______________________________________________________________________________________________________
637 virtual void SAL_CALL
windowClosing( const UNO3_EVENTOBJECT
& aEvent
) throw( UNO3_RUNTIMEEXCEPTION
) ;
639 /**_______________________________________________________________________________________________________
653 virtual void SAL_CALL
windowClosed( const UNO3_EVENTOBJECT
& aEvent
) throw( UNO3_RUNTIMEEXCEPTION
) ;
655 /**_______________________________________________________________________________________________________
669 virtual void SAL_CALL
windowMinimized( const UNO3_EVENTOBJECT
& aEvent
) throw( UNO3_RUNTIMEEXCEPTION
) ;
671 /**_______________________________________________________________________________________________________
685 virtual void SAL_CALL
windowNormalized( const UNO3_EVENTOBJECT
& aEvent
) throw( UNO3_RUNTIMEEXCEPTION
) ;
687 /**_______________________________________________________________________________________________________
701 virtual void SAL_CALL
windowActivated( const UNO3_EVENTOBJECT
& aEvent
) throw( UNO3_RUNTIMEEXCEPTION
) ;
703 /**_______________________________________________________________________________________________________
717 virtual void SAL_CALL
windowDeactivated( const UNO3_EVENTOBJECT
& aEvent
) throw( UNO3_RUNTIMEEXCEPTION
) ;
719 //____________________________________________________________________________________________________________
721 //____________________________________________________________________________________________________________
725 /**_______________________________________________________________________________________________________
726 @short Remove the listener from the peer.
731 @param xPeer The peer from which the listener is removed.
732 @param rType The listener type, which specify the type of the listener.
739 void impl_adviseToPeer( const UNO3_REFERENCE
< UNO3_XWINDOW
>& xPeer
,
740 const UNO3_TYPE
& aType
);
742 /**_______________________________________________________________________________________________________
743 @short Add the listener to the peer.
748 @param xPeer The peer to which the listener is added.
749 @param rType The listener type, which specify the type of the listener.
756 void impl_unadviseFromPeer( const UNO3_REFERENCE
< UNO3_XWINDOW
>& xPeer
,
757 const UNO3_TYPE
& aType
);
759 //____________________________________________________________________________________________________________
761 //____________________________________________________________________________________________________________
765 UNO3_MUTEX m_aMutex
;
766 UNO3_REFERENCE
< UNO3_XWINDOW
> m_xPeer
; /// The source of the events. Normally this is the peer object.
767 UNO3_WEAKREFERENCE
< UNO3_XWINDOW
> m_xControl
;
768 UNO3_OMULTITYPEINTERFACECONTAINERHELPER m_aListenerHolder
;
770 }; // class OMRCListenerMultiplexerHelper
772 } // namespace unocontrols
774 #endif // ifndef _UNOCONTROLS_MULTIPLEXER_HXX