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 INCLUDED_UNOCONTROLS_INC_MULTIPLEXER_HXX
21 #define INCLUDED_UNOCONTROLS_INC_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/weakref.hxx>
48 #include <cppuhelper/interfacecontainer.hxx>
52 namespace unocontrols
{
56 class OMRCListenerMultiplexerHelper
: public css::awt::XFocusListener
57 , public css::awt::XWindowListener
58 , public css::awt::XKeyListener
59 , public css::awt::XMouseListener
60 , public css::awt::XMouseMotionListener
61 , public css::awt::XPaintListener
62 , public css::awt::XTopWindowListener
63 , public ::cppu::OWeakObject
68 /**_______________________________________________________________________________________________________
70 @descr Create a Multiplexer of XWindowEvents.
71 @param rControl The control. All listeners think that this is the original broadcaster.
72 @param rPeer The peer from which the original events are dispatched. Null is allowed.
75 OMRCListenerMultiplexerHelper( const css::uno::Reference
< css::awt::XWindow
>& xControl
,
76 const css::uno::Reference
< css::awt::XWindow
>& xPeer
);
78 /**_______________________________________________________________________________________________________
79 @short copy-constructor
81 @param rCopyInstance C++-Reference to instance to make copy from.
84 OMRCListenerMultiplexerHelper( const OMRCListenerMultiplexerHelper
& aCopyInstance
);
86 virtual ~OMRCListenerMultiplexerHelper() override
;
90 /**_______________________________________________________________________________________________________
91 @short give answer, if interface is supported
92 @descr The interfaces are searched by type.
96 @param "rType" is the type of searched interface.
98 @return Any information about found interface
100 @onerror A RuntimeException is thrown.
103 virtual css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& aType
) override
;
105 /**_______________________________________________________________________________________________________
106 @short increment refcount
109 @onerror A RuntimeException is thrown.
112 virtual void SAL_CALL
acquire() throw() override
;
114 /**_______________________________________________________________________________________________________
115 @short decrement refcount
118 @onerror A RuntimeException is thrown.
121 virtual void SAL_CALL
release() throw() override
;
123 OMRCListenerMultiplexerHelper
& operator= ( const OMRCListenerMultiplexerHelper
& aCopyInstance
);
127 /**_______________________________________________________________________________________________________
128 @short Remove all listeners from the previous set peer and add the needed listeners to rPeer.
129 @param rPeer The peer from which the original events are dispatched. Null is allowed.
132 void setPeer( const css::uno::Reference
< css::awt::XWindow
>& xPeer
);
134 /**_______________________________________________________________________________________________________
135 @short Remove all listeners and send a disposing message.
138 void disposeAndClear();
140 /**_______________________________________________________________________________________________________
141 @short Add the specified listener to the source.
144 void advise( const css::uno::Type
& aType
,
145 const css::uno::Reference
< css::uno::XInterface
>& xListener
);
147 /**_______________________________________________________________________________________________________
148 @short Remove the specified listener from the source.
151 void unadvise( const css::uno::Type
& aType
,
152 const css::uno::Reference
< css::uno::XInterface
>& xListener
);
156 virtual void SAL_CALL
disposing(const css::lang::EventObject
& aSource
) override
;
160 virtual void SAL_CALL
focusGained(const css::awt::FocusEvent
& aEvent
) override
;
162 virtual void SAL_CALL
focusLost(const css::awt::FocusEvent
& aEvent
) override
;
166 virtual void SAL_CALL
windowResized(const css::awt::WindowEvent
& aEvent
) override
;
168 virtual void SAL_CALL
windowMoved(const css::awt::WindowEvent
& aEvent
) override
;
170 virtual void SAL_CALL
windowShown(const css::lang::EventObject
& aEvent
) override
;
172 virtual void SAL_CALL
windowHidden(const css::lang::EventObject
& aEvent
) override
;
176 virtual void SAL_CALL
keyPressed( const css::awt::KeyEvent
& aEvent
) override
;
178 virtual void SAL_CALL
keyReleased( const css::awt::KeyEvent
& aEvent
) override
;
182 virtual void SAL_CALL
mousePressed(const css::awt::MouseEvent
& aEvent
) override
;
184 virtual void SAL_CALL
mouseReleased(const css::awt::MouseEvent
& aEvent
) override
;
186 virtual void SAL_CALL
mouseEntered(const css::awt::MouseEvent
& aEvent
) override
;
188 virtual void SAL_CALL
mouseExited(const css::awt::MouseEvent
& aEvent
) override
;
190 // XMouseMotionListener
192 virtual void SAL_CALL
mouseDragged(const css::awt::MouseEvent
& aEvent
) override
;
194 virtual void SAL_CALL
mouseMoved(const css::awt::MouseEvent
& aEvent
) override
;
198 virtual void SAL_CALL
windowPaint(const css::awt::PaintEvent
& aEvent
) override
;
200 // XTopWindowListener
202 virtual void SAL_CALL
windowOpened( const css::lang::EventObject
& aEvent
) override
;
204 virtual void SAL_CALL
windowClosing( const css::lang::EventObject
& aEvent
) override
;
206 virtual void SAL_CALL
windowClosed( const css::lang::EventObject
& aEvent
) override
;
208 virtual void SAL_CALL
windowMinimized( const css::lang::EventObject
& aEvent
) override
;
210 virtual void SAL_CALL
windowNormalized( const css::lang::EventObject
& aEvent
) override
;
212 virtual void SAL_CALL
windowActivated( const css::lang::EventObject
& aEvent
) override
;
214 virtual void SAL_CALL
windowDeactivated( const css::lang::EventObject
& aEvent
) override
;
220 /**_______________________________________________________________________________________________________
221 @short Remove the listener from the peer.
222 @param xPeer The peer from which the listener is removed.
223 @param rType The listener type, which specify the type of the listener.
226 void impl_adviseToPeer( const css::uno::Reference
< css::awt::XWindow
>& xPeer
,
227 const css::uno::Type
& aType
);
229 /**_______________________________________________________________________________________________________
230 @short Add the listener to the peer.
231 @param xPeer The peer to which the listener is added.
232 @param rType The listener type, which specify the type of the listener.
235 void impl_unadviseFromPeer( const css::uno::Reference
< css::awt::XWindow
>& xPeer
,
236 const css::uno::Type
& aType
);
242 ::osl::Mutex m_aMutex
;
243 css::uno::Reference
< css::awt::XWindow
> m_xPeer
; /// The source of the events. Normally this is the peer object.
244 css::uno::WeakReference
< css::awt::XWindow
> m_xControl
;
245 ::cppu::OMultiTypeInterfaceContainerHelper m_aListenerHolder
;
247 }; // class OMRCListenerMultiplexerHelper
249 } // namespace unocontrols
251 #endif // INCLUDED_UNOCONTROLS_INC_MULTIPLEXER_HXX
253 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */