LibreOffice Module UnoControls (master)  1
multiplexer.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #pragma once
21 
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>
32 
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; }
38 
39 namespace unocontrols {
40 
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
49 {
50 public:
51 
59  OMRCListenerMultiplexerHelper( const css::uno::Reference< css::awt::XWindow >& xControl ,
60  const css::uno::Reference< css::awt::XWindow >& xPeer );
61 
69 
70  virtual ~OMRCListenerMultiplexerHelper() override;
71 
72  // XInterface
73 
87  virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override;
88 
96  virtual void SAL_CALL acquire() noexcept override;
97 
105  virtual void SAL_CALL release() noexcept override;
106 
108 
109  // container methods
110 
116  void setPeer( const css::uno::Reference< css::awt::XWindow >& xPeer );
117 
122  void disposeAndClear();
123 
128  void advise( const css::uno::Type& aType ,
129  const css::uno::Reference< css::uno::XInterface >& xListener );
130 
135  void unadvise( const css::uno::Type& aType ,
136  const css::uno::Reference< css::uno::XInterface >& xListener );
137 
138  // XEventListener
139 
140  virtual void SAL_CALL disposing(const css::lang::EventObject& aSource) override;
141 
142  // XFocusListener
143 
144  virtual void SAL_CALL focusGained(const css::awt::FocusEvent& aEvent ) override;
145 
146  virtual void SAL_CALL focusLost(const css::awt::FocusEvent& aEvent ) override;
147 
148  // XWindowListener
149 
150  virtual void SAL_CALL windowResized(const css::awt::WindowEvent& aEvent ) override;
151 
152  virtual void SAL_CALL windowMoved(const css::awt::WindowEvent& aEvent ) override;
153 
154  virtual void SAL_CALL windowShown(const css::lang::EventObject& aEvent ) override;
155 
156  virtual void SAL_CALL windowHidden(const css::lang::EventObject& aEvent ) override;
157 
158  // XKeyListener
159 
160  virtual void SAL_CALL keyPressed( const css::awt::KeyEvent& aEvent ) override;
161 
162  virtual void SAL_CALL keyReleased( const css::awt::KeyEvent& aEvent ) override;
163 
164  // XMouseListener
165 
166  virtual void SAL_CALL mousePressed(const css::awt::MouseEvent& aEvent ) override;
167 
168  virtual void SAL_CALL mouseReleased(const css::awt::MouseEvent& aEvent ) override;
169 
170  virtual void SAL_CALL mouseEntered(const css::awt::MouseEvent& aEvent ) override;
171 
172  virtual void SAL_CALL mouseExited(const css::awt::MouseEvent& aEvent ) override;
173 
174  // XMouseMotionListener
175 
176  virtual void SAL_CALL mouseDragged(const css::awt::MouseEvent& aEvent ) override;
177 
178  virtual void SAL_CALL mouseMoved(const css::awt::MouseEvent& aEvent ) override;
179 
180  // XPaintListener
181 
182  virtual void SAL_CALL windowPaint(const css::awt::PaintEvent& aEvent ) override;
183 
184  // XTopWindowListener
185 
186  virtual void SAL_CALL windowOpened( const css::lang::EventObject& aEvent ) override;
187 
188  virtual void SAL_CALL windowClosing( const css::lang::EventObject& aEvent ) override;
189 
190  virtual void SAL_CALL windowClosed( const css::lang::EventObject& aEvent ) override;
191 
192  virtual void SAL_CALL windowMinimized( const css::lang::EventObject& aEvent ) override;
193 
194  virtual void SAL_CALL windowNormalized( const css::lang::EventObject& aEvent ) override;
195 
196  virtual void SAL_CALL windowActivated( const css::lang::EventObject& aEvent ) override;
197 
198  virtual void SAL_CALL windowDeactivated( const css::lang::EventObject& aEvent ) override;
199 
200 private:
201 
208  void impl_adviseToPeer( const css::uno::Reference< css::awt::XWindow >& xPeer ,
209  const css::uno::Type& aType );
210 
217  void impl_unadviseFromPeer( const css::uno::Reference< css::awt::XWindow >& xPeer ,
218  const css::uno::Type& aType );
219 
220 // private variables
221 
222 private:
223  ::osl::Mutex m_aMutex;
224  css::uno::Reference< css::awt::XWindow > m_xPeer;
225  css::uno::WeakReference< css::awt::XWindow > m_xControl;
227 
228 };
229 
230 }
231 
232 
233 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL mouseMoved(const css::awt::MouseEvent &aEvent) override
void impl_adviseToPeer(const css::uno::Reference< css::awt::XWindow > &xPeer, const css::uno::Type &aType)
Remove the listener from the peer.
void unadvise(const css::uno::Type &aType, const css::uno::Reference< css::uno::XInterface > &xListener)
Remove the specified listener from the source.
void advise(const css::uno::Type &aType, const css::uno::Reference< css::uno::XInterface > &xListener)
Add the specified listener to the source.
virtual void SAL_CALL windowResized(const css::awt::WindowEvent &aEvent) override
virtual void SAL_CALL windowClosed(const css::lang::EventObject &aEvent) override
virtual void SAL_CALL keyReleased(const css::awt::KeyEvent &aEvent) override
virtual void SAL_CALL windowOpened(const css::lang::EventObject &aEvent) override
virtual void SAL_CALL windowPaint(const css::awt::PaintEvent &aEvent) override
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &aType) override
give answer, if interface is supported The interfaces are searched by type.
Definition: multiplexer.cxx:94
virtual void SAL_CALL acquire() noexcept override
increment refcount XInterface release() A RuntimeException is thrown.
virtual void SAL_CALL windowActivated(const css::lang::EventObject &aEvent) override
virtual void SAL_CALL mouseDragged(const css::awt::MouseEvent &aEvent) override
virtual void SAL_CALL windowMoved(const css::awt::WindowEvent &aEvent) override
virtual void SAL_CALL focusLost(const css::awt::FocusEvent &aEvent) override
void setPeer(const css::uno::Reference< css::awt::XWindow > &xPeer)
Remove all listeners from the previous set peer and add the needed listeners to rPeer.
virtual void SAL_CALL keyPressed(const css::awt::KeyEvent &aEvent) override
virtual void SAL_CALL focusGained(const css::awt::FocusEvent &aEvent) override
virtual void SAL_CALL windowDeactivated(const css::lang::EventObject &aEvent) override
css::uno::WeakReference< css::awt::XWindow > m_xControl
The source of the events. Normally this is the peer object.
OMRCListenerMultiplexerHelper(const css::uno::Reference< css::awt::XWindow > &xControl, const css::uno::Reference< css::awt::XWindow > &xPeer)
constructor Create a Multiplexer of XWindowEvents.
virtual void SAL_CALL disposing(const css::lang::EventObject &aSource) override
virtual void SAL_CALL mouseEntered(const css::awt::MouseEvent &aEvent) override
virtual void SAL_CALL mouseReleased(const css::awt::MouseEvent &aEvent) override
virtual void SAL_CALL windowNormalized(const css::lang::EventObject &aEvent) override
virtual void SAL_CALL windowHidden(const css::lang::EventObject &aEvent) override
virtual void SAL_CALL windowShown(const css::lang::EventObject &aEvent) override
virtual void SAL_CALL windowMinimized(const css::lang::EventObject &aEvent) override
virtual void SAL_CALL mousePressed(const css::awt::MouseEvent &aEvent) override
comphelper::OMultiTypeInterfaceContainerHelper2 m_aListenerHolder
virtual void SAL_CALL release() noexcept override
decrement refcount XInterface acquire() A RuntimeException is thrown.
virtual void SAL_CALL mouseExited(const css::awt::MouseEvent &aEvent) override
virtual void SAL_CALL windowClosing(const css::lang::EventObject &aEvent) override
css::uno::Reference< css::awt::XWindow > m_xPeer
OMRCListenerMultiplexerHelper & operator=(const OMRCListenerMultiplexerHelper &aCopyInstance)
void impl_unadviseFromPeer(const css::uno::Reference< css::awt::XWindow > &xPeer, const css::uno::Type &aType)
Add the listener to the peer.
AnyEventRef aEvent
void disposeAndClear()
Remove all listeners and send a disposing message.