1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef _UNOCONTROLS_MULTIPLEXER_HXX
21 #define _UNOCONTROLS_MULTIPLEXER_HXX
23 #include <com/sun/star/awt/XKeyListener.hpp>
24 #include <com/sun/star/awt/XPaintListener.hpp>
25 #include <com/sun/star/awt/KeyEvent.hpp>
26 #include <com/sun/star/awt/KeyModifier.hpp>
27 #include <com/sun/star/awt/XMouseMotionListener.hpp>
28 #include <com/sun/star/awt/FocusEvent.hpp>
29 #include <com/sun/star/awt/XWindowListener.hpp>
30 #include <com/sun/star/awt/XActivateListener.hpp>
31 #include <com/sun/star/awt/MouseEvent.hpp>
32 #include <com/sun/star/awt/XTopWindowListener.hpp>
33 #include <com/sun/star/awt/PaintEvent.hpp>
34 #include <com/sun/star/awt/InputEvent.hpp>
35 #include <com/sun/star/awt/KeyGroup.hpp>
36 #include <com/sun/star/awt/Key.hpp>
37 #include <com/sun/star/awt/WindowEvent.hpp>
38 #include <com/sun/star/awt/XMouseListener.hpp>
39 #include <com/sun/star/awt/KeyFunction.hpp>
40 #include <com/sun/star/awt/FocusChangeReason.hpp>
41 #include <com/sun/star/awt/MouseButton.hpp>
42 #include <com/sun/star/awt/XFocusListener.hpp>
43 #include <com/sun/star/awt/XTopWindow.hpp>
44 #include <com/sun/star/awt/XWindow.hpp>
45 #include <com/sun/star/awt/PosSize.hpp>
46 #include <cppuhelper/weak.hxx>
47 #include <cppuhelper/interfacecontainer.hxx>
49 //____________________________________________________________________________________________________________
51 //____________________________________________________________________________________________________________
53 namespace unocontrols
{
55 //____________________________________________________________________________________________________________
57 //____________________________________________________________________________________________________________
59 class OMRCListenerMultiplexerHelper
: public ::com::sun::star::awt::XFocusListener
60 , public ::com::sun::star::awt::XWindowListener
61 , public ::com::sun::star::awt::XKeyListener
62 , public ::com::sun::star::awt::XMouseListener
63 , public ::com::sun::star::awt::XMouseMotionListener
64 , public ::com::sun::star::awt::XPaintListener
65 , public ::com::sun::star::awt::XTopWindowListener
66 , public ::cppu::OWeakObject
69 //____________________________________________________________________________________________________________
71 //____________________________________________________________________________________________________________
75 //________________________________________________________________________________________________________
77 //________________________________________________________________________________________________________
79 /**_______________________________________________________________________________________________________
81 @descr Create a Multiplexer of XWindowEvents.
85 @param rControl The control. All listeners think that this is the original broadcaster.
86 @param rPeer The peer from which the original events are dispatched. Null is allowed.
93 OMRCListenerMultiplexerHelper( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
>& xControl
,
94 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
>& xPeer
);
96 /**_______________________________________________________________________________________________________
97 @short copy-constructor
102 @param rCopyInstance C++-Reference to instance to make copy from.
109 OMRCListenerMultiplexerHelper( const OMRCListenerMultiplexerHelper
& aCopyInstance
);
111 /**_______________________________________________________________________________________________________
124 ~OMRCListenerMultiplexerHelper();
126 //________________________________________________________________________________________________________
128 //________________________________________________________________________________________________________
130 /**_______________________________________________________________________________________________________
131 @short give answer, if interface is supported
132 @descr The interfaces are searched by type.
136 @param "rType" is the type of searched interface.
138 @return Any information about found interface
140 @onerror A RuntimeException is thrown.
143 virtual ::com::sun::star::uno::Any SAL_CALL
queryInterface( const ::com::sun::star::uno::Type
& aType
)
144 throw( ::com::sun::star::uno::RuntimeException
);
146 /**_______________________________________________________________________________________________________
147 @short increment refcount
157 @onerror A RuntimeException is thrown.
160 virtual void SAL_CALL
acquire() throw();
162 /**_______________________________________________________________________________________________________
163 @short decrement refcount
173 @onerror A RuntimeException is thrown.
176 virtual void SAL_CALL
release() throw();
178 //________________________________________________________________________________________________________
180 //________________________________________________________________________________________________________
182 /**_______________________________________________________________________________________________________
195 operator ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>() const;
197 /**_______________________________________________________________________________________________________
210 OMRCListenerMultiplexerHelper
& operator= ( const OMRCListenerMultiplexerHelper
& aCopyInstance
);
212 //________________________________________________________________________________________________________
214 //________________________________________________________________________________________________________
216 /**_______________________________________________________________________________________________________
217 @short Remove all listeners from the previous set peer and add the needed listeners to rPeer.
222 @param rPeer The peer from which the original events are dispatched. Null is allowed.
229 void setPeer( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
>& xPeer
);
231 /**_______________________________________________________________________________________________________
232 @short Remove all listeners and send a disposing message.
244 void disposeAndClear();
246 /**_______________________________________________________________________________________________________
247 @short Add the specified listener to the source.
259 void advise( const ::com::sun::star::uno::Type
& aType
,
260 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& xListener
);
262 /**_______________________________________________________________________________________________________
263 @short Remove the specified listener from the source.
275 void unadvise( const ::com::sun::star::uno::Type
& aType
,
276 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& xListener
);
278 //________________________________________________________________________________________________________
280 //________________________________________________________________________________________________________
282 /**_______________________________________________________________________________________________________
296 virtual void SAL_CALL
disposing(const ::com::sun::star::lang::EventObject
& aSource
)
297 throw( ::com::sun::star::uno::RuntimeException
) ;
299 //________________________________________________________________________________________________________
301 //________________________________________________________________________________________________________
303 /**_______________________________________________________________________________________________________
317 virtual void SAL_CALL
focusGained(const ::com::sun::star::awt::FocusEvent
& aEvent
)
318 throw( ::com::sun::star::uno::RuntimeException
) ;
320 /**_______________________________________________________________________________________________________
334 virtual void SAL_CALL
focusLost(const ::com::sun::star::awt::FocusEvent
& aEvent
)
335 throw( ::com::sun::star::uno::RuntimeException
) ;
337 //________________________________________________________________________________________________________
339 //________________________________________________________________________________________________________
341 /**_______________________________________________________________________________________________________
355 virtual void SAL_CALL
windowResized(const ::com::sun::star::awt::WindowEvent
& aEvent
)
356 throw( ::com::sun::star::uno::RuntimeException
) ;
358 /**_______________________________________________________________________________________________________
372 virtual void SAL_CALL
windowMoved(const ::com::sun::star::awt::WindowEvent
& aEvent
)
373 throw( ::com::sun::star::uno::RuntimeException
) ;
375 /**_______________________________________________________________________________________________________
389 virtual void SAL_CALL
windowShown(const ::com::sun::star::lang::EventObject
& aEvent
)
390 throw( ::com::sun::star::uno::RuntimeException
) ;
392 /**_______________________________________________________________________________________________________
406 virtual void SAL_CALL
windowHidden(const ::com::sun::star::lang::EventObject
& aEvent
)
407 throw( ::com::sun::star::uno::RuntimeException
) ;
409 //________________________________________________________________________________________________________
411 //________________________________________________________________________________________________________
413 /**_______________________________________________________________________________________________________
427 virtual void SAL_CALL
keyPressed( const ::com::sun::star::awt::KeyEvent
& aEvent
)
428 throw( ::com::sun::star::uno::RuntimeException
) ;
430 /**_______________________________________________________________________________________________________
444 virtual void SAL_CALL
keyReleased( const ::com::sun::star::awt::KeyEvent
& aEvent
)
445 throw( ::com::sun::star::uno::RuntimeException
) ;
447 //________________________________________________________________________________________________________
449 //________________________________________________________________________________________________________
451 /**_______________________________________________________________________________________________________
465 virtual void SAL_CALL
mousePressed(const ::com::sun::star::awt::MouseEvent
& aEvent
)
466 throw( ::com::sun::star::uno::RuntimeException
) ;
468 /**_______________________________________________________________________________________________________
482 virtual void SAL_CALL
mouseReleased(const ::com::sun::star::awt::MouseEvent
& aEvent
)
483 throw( ::com::sun::star::uno::RuntimeException
) ;
485 /**_______________________________________________________________________________________________________
499 virtual void SAL_CALL
mouseEntered(const ::com::sun::star::awt::MouseEvent
& aEvent
)
500 throw( ::com::sun::star::uno::RuntimeException
) ;
502 /**_______________________________________________________________________________________________________
516 virtual void SAL_CALL
mouseExited(const ::com::sun::star::awt::MouseEvent
& aEvent
)
517 throw( ::com::sun::star::uno::RuntimeException
) ;
519 //________________________________________________________________________________________________________
520 // XMouseMotionListener
521 //________________________________________________________________________________________________________
523 /**_______________________________________________________________________________________________________
537 virtual void SAL_CALL
mouseDragged(const ::com::sun::star::awt::MouseEvent
& aEvent
)
538 throw( ::com::sun::star::uno::RuntimeException
) ;
540 /**_______________________________________________________________________________________________________
554 virtual void SAL_CALL
mouseMoved(const ::com::sun::star::awt::MouseEvent
& aEvent
)
555 throw( ::com::sun::star::uno::RuntimeException
) ;
557 //________________________________________________________________________________________________________
559 //________________________________________________________________________________________________________
561 /**_______________________________________________________________________________________________________
575 virtual void SAL_CALL
windowPaint(const ::com::sun::star::awt::PaintEvent
& aEvent
)
576 throw( ::com::sun::star::uno::RuntimeException
) ;
578 //________________________________________________________________________________________________________
579 // XTopWindowListener
580 //________________________________________________________________________________________________________
582 /**_______________________________________________________________________________________________________
596 virtual void SAL_CALL
windowOpened( const ::com::sun::star::lang::EventObject
& aEvent
)
597 throw( ::com::sun::star::uno::RuntimeException
) ;
599 /**_______________________________________________________________________________________________________
613 virtual void SAL_CALL
windowClosing( const ::com::sun::star::lang::EventObject
& aEvent
)
614 throw( ::com::sun::star::uno::RuntimeException
) ;
616 /**_______________________________________________________________________________________________________
630 virtual void SAL_CALL
windowClosed( const ::com::sun::star::lang::EventObject
& aEvent
)
631 throw( ::com::sun::star::uno::RuntimeException
) ;
633 /**_______________________________________________________________________________________________________
647 virtual void SAL_CALL
windowMinimized( const ::com::sun::star::lang::EventObject
& aEvent
)
648 throw( ::com::sun::star::uno::RuntimeException
) ;
650 /**_______________________________________________________________________________________________________
664 virtual void SAL_CALL
windowNormalized( const ::com::sun::star::lang::EventObject
& aEvent
)
665 throw( ::com::sun::star::uno::RuntimeException
) ;
667 /**_______________________________________________________________________________________________________
681 virtual void SAL_CALL
windowActivated( const ::com::sun::star::lang::EventObject
& aEvent
)
682 throw( ::com::sun::star::uno::RuntimeException
) ;
684 /**_______________________________________________________________________________________________________
698 virtual void SAL_CALL
windowDeactivated( const ::com::sun::star::lang::EventObject
& aEvent
)
699 throw( ::com::sun::star::uno::RuntimeException
) ;
701 //____________________________________________________________________________________________________________
703 //____________________________________________________________________________________________________________
707 /**_______________________________________________________________________________________________________
708 @short Remove the listener from the peer.
713 @param xPeer The peer from which the listener is removed.
714 @param rType The listener type, which specify the type of the listener.
721 void impl_adviseToPeer( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
>& xPeer
,
722 const ::com::sun::star::uno::Type
& aType
);
724 /**_______________________________________________________________________________________________________
725 @short Add the listener to the peer.
730 @param xPeer The peer to which the listener is added.
731 @param rType The listener type, which specify the type of the listener.
738 void impl_unadviseFromPeer( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
>& xPeer
,
739 const ::com::sun::star::uno::Type
& aType
);
741 //____________________________________________________________________________________________________________
743 //____________________________________________________________________________________________________________
747 ::osl::Mutex m_aMutex
;
748 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
> m_xPeer
; /// The source of the events. Normally this is the peer object.
749 ::com::sun::star::uno::WeakReference
< ::com::sun::star::awt::XWindow
> m_xControl
;
750 ::cppu::OMultiTypeInterfaceContainerHelper m_aListenerHolder
;
752 }; // class OMRCListenerMultiplexerHelper
754 } // namespace unocontrols
756 #endif // ifndef _UNOCONTROLS_MULTIPLEXER_HXX
758 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */