Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / UnoControls / inc / multiplexer.hxx
blobf36ba3a3d6cb1a51aef7a8fa31df34a4f70e3616
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
50 namespace unocontrols {
52 class OMRCListenerMultiplexerHelper : public css::awt::XFocusListener
53 , public css::awt::XWindowListener
54 , public css::awt::XKeyListener
55 , public css::awt::XMouseListener
56 , public css::awt::XMouseMotionListener
57 , public css::awt::XPaintListener
58 , public css::awt::XTopWindowListener
59 , public ::cppu::OWeakObject
61 public:
63 /**
64 @short constructor
65 @descr Create a Multiplexer of XWindowEvents.
66 @param rControl The control. All listeners think that this is the original broadcaster.
67 @param rPeer The peer from which the original events are dispatched. Null is allowed.
70 OMRCListenerMultiplexerHelper( const css::uno::Reference< css::awt::XWindow >& xControl ,
71 const css::uno::Reference< css::awt::XWindow >& xPeer );
73 /**
74 @short copy-constructor
75 @descr
76 @param rCopyInstance C++-Reference to instance to make copy from.
79 OMRCListenerMultiplexerHelper( const OMRCListenerMultiplexerHelper& aCopyInstance );
81 virtual ~OMRCListenerMultiplexerHelper() override;
83 // XInterface
85 /**
86 @short give answer, if interface is supported
87 @descr The interfaces are searched by type.
89 @seealso XInterface
91 @param "rType" is the type of searched interface.
93 @return Any information about found interface
95 @onerror A RuntimeException is thrown.
98 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override;
101 @short increment refcount
102 @seealso XInterface
103 @seealso release()
104 @onerror A RuntimeException is thrown.
107 virtual void SAL_CALL acquire() throw() override;
110 @short decrement refcount
111 @seealso XInterface
112 @seealso acquire()
113 @onerror A RuntimeException is thrown.
116 virtual void SAL_CALL release() throw() override;
118 OMRCListenerMultiplexerHelper& operator= ( const OMRCListenerMultiplexerHelper& aCopyInstance );
120 // container methods
123 @short Remove all listeners from the previous set peer and add the needed listeners to rPeer.
124 @param rPeer The peer from which the original events are dispatched. Null is allowed.
127 void setPeer( const css::uno::Reference< css::awt::XWindow >& xPeer );
130 @short Remove all listeners and send a disposing message.
133 void disposeAndClear();
136 @short Add the specified listener to the source.
139 void advise( const css::uno::Type& aType ,
140 const css::uno::Reference< css::uno::XInterface >& xListener );
143 @short Remove the specified listener from the source.
146 void unadvise( const css::uno::Type& aType ,
147 const css::uno::Reference< css::uno::XInterface >& xListener );
149 // XEventListener
151 virtual void SAL_CALL disposing(const css::lang::EventObject& aSource) override;
153 // XFocusListener
155 virtual void SAL_CALL focusGained(const css::awt::FocusEvent& aEvent ) override;
157 virtual void SAL_CALL focusLost(const css::awt::FocusEvent& aEvent ) override;
159 // XWindowListener
161 virtual void SAL_CALL windowResized(const css::awt::WindowEvent& aEvent ) override;
163 virtual void SAL_CALL windowMoved(const css::awt::WindowEvent& aEvent ) override;
165 virtual void SAL_CALL windowShown(const css::lang::EventObject& aEvent ) override;
167 virtual void SAL_CALL windowHidden(const css::lang::EventObject& aEvent ) override;
169 // XKeyListener
171 virtual void SAL_CALL keyPressed( const css::awt::KeyEvent& aEvent ) override;
173 virtual void SAL_CALL keyReleased( const css::awt::KeyEvent& aEvent ) override;
175 // XMouseListener
177 virtual void SAL_CALL mousePressed(const css::awt::MouseEvent& aEvent ) override;
179 virtual void SAL_CALL mouseReleased(const css::awt::MouseEvent& aEvent ) override;
181 virtual void SAL_CALL mouseEntered(const css::awt::MouseEvent& aEvent ) override;
183 virtual void SAL_CALL mouseExited(const css::awt::MouseEvent& aEvent ) override;
185 // XMouseMotionListener
187 virtual void SAL_CALL mouseDragged(const css::awt::MouseEvent& aEvent ) override;
189 virtual void SAL_CALL mouseMoved(const css::awt::MouseEvent& aEvent ) override;
191 // XPaintListener
193 virtual void SAL_CALL windowPaint(const css::awt::PaintEvent& aEvent ) override;
195 // XTopWindowListener
197 virtual void SAL_CALL windowOpened( const css::lang::EventObject& aEvent ) override;
199 virtual void SAL_CALL windowClosing( const css::lang::EventObject& aEvent ) override;
201 virtual void SAL_CALL windowClosed( const css::lang::EventObject& aEvent ) override;
203 virtual void SAL_CALL windowMinimized( const css::lang::EventObject& aEvent ) override;
205 virtual void SAL_CALL windowNormalized( const css::lang::EventObject& aEvent ) override;
207 virtual void SAL_CALL windowActivated( const css::lang::EventObject& aEvent ) override;
209 virtual void SAL_CALL windowDeactivated( const css::lang::EventObject& aEvent ) override;
211 // protected methods
213 protected:
216 @short Remove the listener from the peer.
217 @param xPeer The peer from which the listener is removed.
218 @param rType The listener type, which specify the type of the listener.
221 void impl_adviseToPeer( const css::uno::Reference< css::awt::XWindow >& xPeer ,
222 const css::uno::Type& aType );
225 @short Add the listener to the peer.
226 @param xPeer The peer to which the listener is added.
227 @param rType The listener type, which specify the type of the listener.
230 void impl_unadviseFromPeer( const css::uno::Reference< css::awt::XWindow >& xPeer ,
231 const css::uno::Type& aType );
233 // private variables
235 private:
236 ::osl::Mutex m_aMutex;
237 css::uno::Reference< css::awt::XWindow > m_xPeer; /// The source of the events. Normally this is the peer object.
238 css::uno::WeakReference< css::awt::XWindow > m_xControl;
239 ::cppu::OMultiTypeInterfaceContainerHelper m_aListenerHolder;
245 #endif // INCLUDED_UNOCONTROLS_INC_MULTIPLEXER_HXX
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */