Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / UnoControls / inc / multiplexer.hxx
blob58bd1563fb0a34f82c862b0477a272759be1d91e
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 #pragma once
22 #include <com/sun/star/awt/XKeyListener.hpp>
23 #include <com/sun/star/awt/XPaintListener.hpp>
24 #include <com/sun/star/awt/XMouseMotionListener.hpp>
25 #include <com/sun/star/awt/XWindowListener.hpp>
26 #include <com/sun/star/awt/XTopWindowListener.hpp>
27 #include <com/sun/star/awt/XMouseListener.hpp>
28 #include <com/sun/star/awt/XFocusListener.hpp>
29 #include <cppuhelper/weak.hxx>
30 #include <cppuhelper/weakref.hxx>
31 #include <comphelper/multicontainer2.hxx>
33 namespace com::sun::star::awt { class XWindow; }
34 namespace com::sun::star::awt { struct KeyEvent; }
35 namespace com::sun::star::awt { struct MouseEvent; }
36 namespace com::sun::star::awt { struct PaintEvent; }
37 namespace com::sun::star::awt { struct WindowEvent; }
39 namespace unocontrols {
41 class OMRCListenerMultiplexerHelper final : public css::awt::XFocusListener
42 , public css::awt::XWindowListener
43 , public css::awt::XKeyListener
44 , public css::awt::XMouseListener
45 , public css::awt::XMouseMotionListener
46 , public css::awt::XPaintListener
47 , public css::awt::XTopWindowListener
48 , public ::cppu::OWeakObject
50 public:
52 /**
53 @short constructor
54 @descr Create a Multiplexer of XWindowEvents.
55 @param rControl The control. All listeners think that this is the original broadcaster.
56 @param rPeer The peer from which the original events are dispatched. Null is allowed.
59 OMRCListenerMultiplexerHelper( const css::uno::Reference< css::awt::XWindow >& xControl ,
60 const css::uno::Reference< css::awt::XWindow >& xPeer );
62 /**
63 @short copy-constructor
64 @descr
65 @param rCopyInstance C++-Reference to instance to make copy from.
68 OMRCListenerMultiplexerHelper( const OMRCListenerMultiplexerHelper& aCopyInstance );
70 virtual ~OMRCListenerMultiplexerHelper() override;
72 // XInterface
74 /**
75 @short give answer, if interface is supported
76 @descr The interfaces are searched by type.
78 @seealso XInterface
80 @param "rType" is the type of searched interface.
82 @return Any information about found interface
84 @onerror A RuntimeException is thrown.
87 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override;
89 /**
90 @short increment refcount
91 @seealso XInterface
92 @seealso release()
93 @onerror A RuntimeException is thrown.
96 virtual void SAL_CALL acquire() noexcept override;
98 /**
99 @short decrement refcount
100 @seealso XInterface
101 @seealso acquire()
102 @onerror A RuntimeException is thrown.
105 virtual void SAL_CALL release() noexcept override;
107 OMRCListenerMultiplexerHelper& operator= ( const OMRCListenerMultiplexerHelper& aCopyInstance );
109 // container methods
112 @short Remove all listeners from the previous set peer and add the needed listeners to rPeer.
113 @param rPeer The peer from which the original events are dispatched. Null is allowed.
116 void setPeer( const css::uno::Reference< css::awt::XWindow >& xPeer );
119 @short Remove all listeners and send a disposing message.
122 void disposeAndClear();
125 @short Add the specified listener to the source.
128 void advise( const css::uno::Type& aType ,
129 const css::uno::Reference< css::uno::XInterface >& xListener );
132 @short Remove the specified listener from the source.
135 void unadvise( const css::uno::Type& aType ,
136 const css::uno::Reference< css::uno::XInterface >& xListener );
138 // XEventListener
140 virtual void SAL_CALL disposing(const css::lang::EventObject& aSource) override;
142 // XFocusListener
144 virtual void SAL_CALL focusGained(const css::awt::FocusEvent& aEvent ) override;
146 virtual void SAL_CALL focusLost(const css::awt::FocusEvent& aEvent ) override;
148 // XWindowListener
150 virtual void SAL_CALL windowResized(const css::awt::WindowEvent& aEvent ) override;
152 virtual void SAL_CALL windowMoved(const css::awt::WindowEvent& aEvent ) override;
154 virtual void SAL_CALL windowShown(const css::lang::EventObject& aEvent ) override;
156 virtual void SAL_CALL windowHidden(const css::lang::EventObject& aEvent ) override;
158 // XKeyListener
160 virtual void SAL_CALL keyPressed( const css::awt::KeyEvent& aEvent ) override;
162 virtual void SAL_CALL keyReleased( const css::awt::KeyEvent& aEvent ) override;
164 // XMouseListener
166 virtual void SAL_CALL mousePressed(const css::awt::MouseEvent& aEvent ) override;
168 virtual void SAL_CALL mouseReleased(const css::awt::MouseEvent& aEvent ) override;
170 virtual void SAL_CALL mouseEntered(const css::awt::MouseEvent& aEvent ) override;
172 virtual void SAL_CALL mouseExited(const css::awt::MouseEvent& aEvent ) override;
174 // XMouseMotionListener
176 virtual void SAL_CALL mouseDragged(const css::awt::MouseEvent& aEvent ) override;
178 virtual void SAL_CALL mouseMoved(const css::awt::MouseEvent& aEvent ) override;
180 // XPaintListener
182 virtual void SAL_CALL windowPaint(const css::awt::PaintEvent& aEvent ) override;
184 // XTopWindowListener
186 virtual void SAL_CALL windowOpened( const css::lang::EventObject& aEvent ) override;
188 virtual void SAL_CALL windowClosing( const css::lang::EventObject& aEvent ) override;
190 virtual void SAL_CALL windowClosed( const css::lang::EventObject& aEvent ) override;
192 virtual void SAL_CALL windowMinimized( const css::lang::EventObject& aEvent ) override;
194 virtual void SAL_CALL windowNormalized( const css::lang::EventObject& aEvent ) override;
196 virtual void SAL_CALL windowActivated( const css::lang::EventObject& aEvent ) override;
198 virtual void SAL_CALL windowDeactivated( const css::lang::EventObject& aEvent ) override;
200 private:
203 @short Remove the listener from the peer.
204 @param xPeer The peer from which the listener is removed.
205 @param rType The listener type, which specify the type of the listener.
208 void impl_adviseToPeer( const css::uno::Reference< css::awt::XWindow >& xPeer ,
209 const css::uno::Type& aType );
212 @short Add the listener to the peer.
213 @param xPeer The peer to which the listener is added.
214 @param rType The listener type, which specify the type of the listener.
217 void impl_unadviseFromPeer( const css::uno::Reference< css::awt::XWindow >& xPeer ,
218 const css::uno::Type& aType );
220 // private variables
222 private:
223 ::osl::Mutex m_aMutex;
224 css::uno::Reference< css::awt::XWindow > m_xPeer; /// The source of the events. Normally this is the peer object.
225 css::uno::WeakReference< css::awt::XWindow > m_xControl;
226 comphelper::OMultiTypeInterfaceContainerHelper2 m_aListenerHolder;
233 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */