LibreOffice Module toolkit (master) 1
listenermultiplexer.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#ifndef INCLUDED_TOOLKIT_HELPER_LISTENERMULTIPLEXER_HXX
21#define INCLUDED_TOOLKIT_HELPER_LISTENERMULTIPLEXER_HXX
22
23#include <config_options.h>
24#include <toolkit/dllapi.h>
25#include <com/sun/star/lang/XEventListener.hpp>
26#include <com/sun/star/awt/XFocusListener.hpp>
27#include <com/sun/star/awt/XWindowListener.hpp>
28#include <com/sun/star/awt/XVclContainerListener.hpp>
29#include <com/sun/star/awt/XKeyListener.hpp>
30#include <com/sun/star/awt/XMouseListener.hpp>
31#include <com/sun/star/awt/XMouseMotionListener.hpp>
32#include <com/sun/star/awt/XPaintListener.hpp>
33#include <com/sun/star/awt/XTopWindowListener.hpp>
34#include <com/sun/star/awt/XTextListener.hpp>
35#include <com/sun/star/awt/XActionListener.hpp>
36#include <com/sun/star/awt/XItemListener.hpp>
37#include <com/sun/star/awt/XTabListener.hpp>
38#include <com/sun/star/container/XContainerListener.hpp>
39#include <com/sun/star/awt/XSpinListener.hpp>
40#include <com/sun/star/awt/XAdjustmentListener.hpp>
41#include <com/sun/star/awt/XMenuListener.hpp>
42#include <com/sun/star/awt/tree/XTreeExpansionListener.hpp>
43#include <com/sun/star/awt/tree/XTreeEditListener.hpp>
44#include <com/sun/star/view/XSelectionChangeListener.hpp>
46#include <cppuhelper/weak.hxx>
49#include <com/sun/star/awt/grid/XGridSelectionListener.hpp>
50#include <com/sun/star/awt/tab/XTabPageContainerListener.hpp>
51
52// class ListenerMultiplexerBase
53
54template <class ListenerT>
55class UNLESS_MERGELIBS(TOOLKIT_DLLPUBLIC) ListenerMultiplexerBase :
56 public css::uno::XInterface
57{
58private:
60protected:
61 mutable std::mutex m_aMutex;
63
64 ::cppu::OWeakObject& GetContext() { return mrContext; }
65
66public:
68 : mrContext(rSource)
69 {
70 }
71
73 {
74 }
75
76 // css::uno::XInterface
77 css::uno::Any SAL_CALL queryInterface(const css::uno::Type & rType) override
78 {
79 return ::cppu::queryInterface(rType, static_cast<css::uno::XInterface*>(this));
80 }
81
82 void SAL_CALL acquire() noexcept override { mrContext.acquire(); }
83 void SAL_CALL release() noexcept override { mrContext.release(); }
84
85 void addInterface( const css::uno::Reference<ListenerT>& l)
86 {
87 std::unique_lock g(m_aMutex);
88 maListeners.addInterface(g, l);
89 }
90
91 void removeInterface( const css::uno::Reference<ListenerT>& l)
92 {
93 std::unique_lock g(m_aMutex);
94 maListeners.removeInterface(g, l);
95 }
96
97 void disposeAndClear(const css::lang::EventObject& rDisposeEvent)
98 {
99 std::unique_lock g(m_aMutex);
100 maListeners.disposeAndClear(g, rDisposeEvent);
101 }
102
103 void disposeAndClear(std::unique_lock<std::mutex>& rGuard, const css::lang::EventObject& rDisposeEvent)
104 {
105 maListeners.disposeAndClear(rGuard, rDisposeEvent);
106 }
107
108 sal_Int32 getLength() const
109 {
110 std::unique_lock g(m_aMutex);
111 return maListeners.getLength(g);
112 }
113
114 template <typename EventT>
115 inline void notifyEach(void (SAL_CALL ListenerT::*NotificationMethod)(const EventT&),
116 const EventT& Event) const
117 {
118 std::unique_lock g(m_aMutex);
119 return maListeners.notifyEach(g, NotificationMethod, Event);
120 }
121};
122
123// class EventListenerMultiplexer
124
125DECL_LISTENERMULTIPLEXER_START( EventListenerMultiplexer, css::lang::XEventListener )
127
128
129// class FocusListenerMultiplexer
130
131DECL_LISTENERMULTIPLEXER_START_DLLPUB( FocusListenerMultiplexer, css::awt::XFocusListener )
132 void SAL_CALL focusGained( const css::awt::FocusEvent& e ) override;
133 void SAL_CALL focusLost( const css::awt::FocusEvent& e ) override;
135
136
137// class WindowListenerMultiplexer
138
139DECL_LISTENERMULTIPLEXER_START_DLLPUB( WindowListenerMultiplexer, css::awt::XWindowListener )
140 void SAL_CALL windowResized( const css::awt::WindowEvent& e ) override;
141 void SAL_CALL windowMoved( const css::awt::WindowEvent& e ) override;
142 void SAL_CALL windowShown( const css::lang::EventObject& e ) override;
143 void SAL_CALL windowHidden( const css::lang::EventObject& e ) override;
145
146
147// class VclContainerListenerMultiplexer
148
149DECL_LISTENERMULTIPLEXER_START( VclContainerListenerMultiplexer, css::awt::XVclContainerListener )
150 void SAL_CALL windowAdded( const css::awt::VclContainerEvent& e ) override;
151 void SAL_CALL windowRemoved( const css::awt::VclContainerEvent& e ) override;
153
154
155// class KeyListenerMultiplexer
156
157DECL_LISTENERMULTIPLEXER_START_DLLPUB( KeyListenerMultiplexer, css::awt::XKeyListener )
158 void SAL_CALL keyPressed( const css::awt::KeyEvent& e ) override;
159 void SAL_CALL keyReleased( const css::awt::KeyEvent& e ) override;
161
162
163// class MouseListenerMultiplexer
164
165DECL_LISTENERMULTIPLEXER_START_DLLPUB( MouseListenerMultiplexer, css::awt::XMouseListener )
166 void SAL_CALL mousePressed( const css::awt::MouseEvent& e ) override;
167 void SAL_CALL mouseReleased( const css::awt::MouseEvent& e ) override;
168 void SAL_CALL mouseEntered( const css::awt::MouseEvent& e ) override;
169 void SAL_CALL mouseExited( const css::awt::MouseEvent& e ) override;
171
172
173// class MouseMotionListenerMultiplexer
174
175DECL_LISTENERMULTIPLEXER_START_DLLPUB( MouseMotionListenerMultiplexer, css::awt::XMouseMotionListener )
176 void SAL_CALL mouseDragged( const css::awt::MouseEvent& e ) override;
177 void SAL_CALL mouseMoved( const css::awt::MouseEvent& e ) override;
179
180
181// class PaintListenerMultiplexer
182
183DECL_LISTENERMULTIPLEXER_START_DLLPUB( PaintListenerMultiplexer, css::awt::XPaintListener )
184 void SAL_CALL windowPaint( const css::awt::PaintEvent& e ) override;
186
187
188// class TopWindowListenerMultiplexer
189
190DECL_LISTENERMULTIPLEXER_START( TopWindowListenerMultiplexer, css::awt::XTopWindowListener )
191 void SAL_CALL windowOpened( const css::lang::EventObject& e ) override;
192 void SAL_CALL windowClosing( const css::lang::EventObject& e ) override;
193 void SAL_CALL windowClosed( const css::lang::EventObject& e ) override;
194 void SAL_CALL windowMinimized( const css::lang::EventObject& e ) override;
195 void SAL_CALL windowNormalized( const css::lang::EventObject& e ) override;
196 void SAL_CALL windowActivated( const css::lang::EventObject& e ) override;
197 void SAL_CALL windowDeactivated( const css::lang::EventObject& e ) override;
199
200
201// class TextListenerMultiplexer
202
203DECL_LISTENERMULTIPLEXER_START_DLLPUB( TextListenerMultiplexer, css::awt::XTextListener )
204 void SAL_CALL textChanged( const css::awt::TextEvent& rEvent ) override;
206
207
208// class ActionListenerMultiplexer
209
210DECL_LISTENERMULTIPLEXER_START( ActionListenerMultiplexer, css::awt::XActionListener )
211 void SAL_CALL actionPerformed( const css::awt::ActionEvent& rEvent ) override;
213
214
215// class ItemListenerMultiplexer
216
217DECL_LISTENERMULTIPLEXER_START( ItemListenerMultiplexer, css::awt::XItemListener )
218 void SAL_CALL itemStateChanged( const css::awt::ItemEvent& rEvent ) override;
220
221
222// class TabListenerMultiplexer
223
224DECL_LISTENERMULTIPLEXER_START( TabListenerMultiplexer, css::awt::XTabListener )
225 void SAL_CALL inserted( ::sal_Int32 ID ) override;
226 void SAL_CALL removed( ::sal_Int32 ID ) override;
227 void SAL_CALL changed( ::sal_Int32 ID, const css::uno::Sequence< css::beans::NamedValue >& Properties ) override;
228 void SAL_CALL activated( ::sal_Int32 ID ) override;
229 void SAL_CALL deactivated( ::sal_Int32 ID ) override;
231
232
233// class ContainerListenerMultiplexer
234
235DECL_LISTENERMULTIPLEXER_START( ContainerListenerMultiplexer, css::container::XContainerListener )
236 void SAL_CALL elementInserted( const css::container::ContainerEvent& Event ) override;
237 void SAL_CALL elementRemoved( const css::container::ContainerEvent& Event ) override;
238 void SAL_CALL elementReplaced( const css::container::ContainerEvent& Event ) override;
240
241
242// class SpinListenerMultiplexer
243
244DECL_LISTENERMULTIPLEXER_START_DLLPUB( SpinListenerMultiplexer, css::awt::XSpinListener )
245 void SAL_CALL up( const css::awt::SpinEvent& rEvent ) override;
246 void SAL_CALL down( const css::awt::SpinEvent& rEvent ) override;
247 void SAL_CALL first( const css::awt::SpinEvent& rEvent ) override;
248 void SAL_CALL last( const css::awt::SpinEvent& rEvent ) override;
250
251
252// class AdjustmentListenerMultiplexer
253
254DECL_LISTENERMULTIPLEXER_START( AdjustmentListenerMultiplexer, css::awt::XAdjustmentListener )
255 void SAL_CALL adjustmentValueChanged( const css::awt::AdjustmentEvent& rEvent ) override;
257
258
259// class MenuListenerMultiplexer
260
261DECL_LISTENERMULTIPLEXER_START( MenuListenerMultiplexer, css::awt::XMenuListener )
262 void SAL_CALL itemHighlighted( const css::awt::MenuEvent& rEvent ) override;
263 void SAL_CALL itemSelected( const css::awt::MenuEvent& rEvent ) override;
264 void SAL_CALL itemActivated( const css::awt::MenuEvent& rEvent ) override;
265 void SAL_CALL itemDeactivated( const css::awt::MenuEvent& rEvent ) override;
267
268
269// class TreeSelectionListenerMultiplexer
270
271DECL_LISTENERMULTIPLEXER_START( TreeSelectionListenerMultiplexer, css::view::XSelectionChangeListener )
272 virtual void SAL_CALL selectionChanged( const css::lang::EventObject& aEvent ) override;
274
275
276// class TreeExpansionListenerMultiplexer
277
278DECL_LISTENERMULTIPLEXER_START( TreeExpansionListenerMultiplexer, css::awt::tree::XTreeExpansionListener )
279 virtual void SAL_CALL requestChildNodes( const css::awt::tree::TreeExpansionEvent& aEvent ) override;
280 virtual void SAL_CALL treeExpanding( const css::awt::tree::TreeExpansionEvent& aEvent ) override;
281 virtual void SAL_CALL treeCollapsing( const css::awt::tree::TreeExpansionEvent& aEvent ) override;
282 virtual void SAL_CALL treeExpanded( const css::awt::tree::TreeExpansionEvent& aEvent ) override;
283 virtual void SAL_CALL treeCollapsed( const css::awt::tree::TreeExpansionEvent& aEvent ) override;
285
286
287// class TreeEditListenerMultiplexer
288
289DECL_LISTENERMULTIPLEXER_START( TreeEditListenerMultiplexer, css::awt::tree::XTreeEditListener )
290 virtual void SAL_CALL nodeEditing( const css::uno::Reference< css::awt::tree::XTreeNode >& Node ) override;
291 virtual void SAL_CALL nodeEdited( const css::uno::Reference< css::awt::tree::XTreeNode >& Node, const OUString& NewText ) override;
293
294
295// class SelectionListenerMultiplexer
296
297DECL_LISTENERMULTIPLEXER_START_DLLPUB( SelectionListenerMultiplexer, css::awt::grid::XGridSelectionListener )
298 void SAL_CALL selectionChanged( const css::awt::grid::GridSelectionEvent& aEvent ) override;
300
301
302// class TabPageListenerMultiplexer
303
304DECL_LISTENERMULTIPLEXER_START( TabPageListenerMultiplexer, css::awt::tab::XTabPageContainerListener )
305 void SAL_CALL tabPageActivated( const css::awt::tab::TabPageActivatedEvent& aEvent ) override;
307
308#endif // INCLUDED_TOOLKIT_HELPER_LISTENERMULTIPLEXER_HXX
309
310/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const NodeContext & mrContext
sal_Int32 addInterface(std::unique_lock< std::mutex > &rGuard, const css::uno::Reference< ListenerT > &rxIFace)
void notifyEach(std::unique_lock< std::mutex > &rGuard, void(SAL_CALL ListenerT::*NotificationMethod)(const EventT &), const EventT &Event) const
void disposeAndClear(::std::unique_lock<::std::mutex > &rGuard, const css::lang::EventObject &rEvt)
sal_Int32 getLength(std::unique_lock< std::mutex > &rGuard) const
sal_Int32 removeInterface(std::unique_lock< std::mutex > &rGuard, const css::uno::Reference< ListenerT > &rxIFace)
std::mutex m_aMutex
void SAL_CALL windowClosed(const css::lang::EventObject &e) override
void SAL_CALL windowMinimized(const css::lang::EventObject &e) override
DECL_LISTENERMULTIPLEXER_END void SAL_CALL actionPerformed(const css::awt::ActionEvent &rEvent) override
void SAL_CALL windowDeactivated(const css::lang::EventObject &e) override
void SAL_CALL itemDeactivated(const css::awt::MenuEvent &rEvent) override
virtual void SAL_CALL nodeEdited(const css::uno::Reference< css::awt::tree::XTreeNode > &Node, const OUString &NewText) override
virtual void SAL_CALL treeExpanded(const css::awt::tree::TreeExpansionEvent &aEvent) override
DECL_LISTENERMULTIPLEXER_END void SAL_CALL textChanged(const css::awt::TextEvent &rEvent) override
void SAL_CALL windowHidden(const css::lang::EventObject &e) override
void SAL_CALL windowActivated(const css::lang::EventObject &e) override
void SAL_CALL deactivated(::sal_Int32 ID) override
DECL_LISTENERMULTIPLEXER_END void SAL_CALL up(const css::awt::SpinEvent &rEvent) override
DECL_LISTENERMULTIPLEXER_END void SAL_CALL windowResized(const css::awt::WindowEvent &e) override
void SAL_CALL mouseReleased(const css::awt::MouseEvent &e) override
DECL_LISTENERMULTIPLEXER_END void SAL_CALL windowAdded(const css::awt::VclContainerEvent &e) override
void SAL_CALL mouseExited(const css::awt::MouseEvent &e) override
void SAL_CALL itemActivated(const css::awt::MenuEvent &rEvent) override
void SAL_CALL down(const css::awt::SpinEvent &rEvent) override
virtual DECL_LISTENERMULTIPLEXER_END void SAL_CALL selectionChanged(const css::lang::EventObject &aEvent) override
void SAL_CALL elementReplaced(const css::container::ContainerEvent &Event) override
DECL_LISTENERMULTIPLEXER_END void SAL_CALL itemHighlighted(const css::awt::MenuEvent &rEvent) override
DECL_LISTENERMULTIPLEXER_END void SAL_CALL inserted(::sal_Int32 ID) override
void SAL_CALL changed(::sal_Int32 ID, const css::uno::Sequence< css::beans::NamedValue > &Properties) override
void SAL_CALL mouseMoved(const css::awt::MouseEvent &e) override
DECL_LISTENERMULTIPLEXER_END void SAL_CALL windowPaint(const css::awt::PaintEvent &e) override
void SAL_CALL elementRemoved(const css::container::ContainerEvent &Event) override
virtual DECL_LISTENERMULTIPLEXER_END void SAL_CALL nodeEditing(const css::uno::Reference< css::awt::tree::XTreeNode > &Node) override
DECL_LISTENERMULTIPLEXER_END void SAL_CALL mousePressed(const css::awt::MouseEvent &e) override
void SAL_CALL last(const css::awt::SpinEvent &rEvent) override
void SAL_CALL first(const css::awt::SpinEvent &rEvent) override
DECL_LISTENERMULTIPLEXER_END void SAL_CALL windowOpened(const css::lang::EventObject &e) override
void SAL_CALL windowClosing(const css::lang::EventObject &e) override
DECL_LISTENERMULTIPLEXER_END void SAL_CALL elementInserted(const css::container::ContainerEvent &Event) override
void SAL_CALL mouseEntered(const css::awt::MouseEvent &e) override
DECL_LISTENERMULTIPLEXER_END void SAL_CALL itemStateChanged(const css::awt::ItemEvent &rEvent) override
void SAL_CALL removed(::sal_Int32 ID) override
void SAL_CALL windowRemoved(const css::awt::VclContainerEvent &e) override
DECL_LISTENERMULTIPLEXER_END void SAL_CALL keyPressed(const css::awt::KeyEvent &e) override
virtual void SAL_CALL treeCollapsed(const css::awt::tree::TreeExpansionEvent &aEvent) override
void SAL_CALL keyReleased(const css::awt::KeyEvent &e) override
class UNLESS_MERGELIBS(TOOLKIT_DLLPUBLIC) ListenerMultiplexerBase DECL_LISTENERMULTIPLEXER_END void SAL_CALL focusGained(const css::awt::FocusEvent &e) override
void SAL_CALL focusLost(const css::awt::FocusEvent &e) override
virtual void SAL_CALL treeExpanding(const css::awt::tree::TreeExpansionEvent &aEvent) override
void SAL_CALL itemSelected(const css::awt::MenuEvent &rEvent) override
void SAL_CALL windowShown(const css::lang::EventObject &e) override
DECL_LISTENERMULTIPLEXER_END void SAL_CALL tabPageActivated(const css::awt::tab::TabPageActivatedEvent &aEvent) override
void SAL_CALL activated(::sal_Int32 ID) override
virtual DECL_LISTENERMULTIPLEXER_END void SAL_CALL requestChildNodes(const css::awt::tree::TreeExpansionEvent &aEvent) override
DECL_LISTENERMULTIPLEXER_END void SAL_CALL adjustmentValueChanged(const css::awt::AdjustmentEvent &rEvent) override
DECL_LISTENERMULTIPLEXER_END void SAL_CALL mouseDragged(const css::awt::MouseEvent &e) override
virtual void SAL_CALL treeCollapsing(const css::awt::tree::TreeExpansionEvent &aEvent) override
void SAL_CALL windowNormalized(const css::lang::EventObject &e) override
void SAL_CALL windowMoved(const css::awt::WindowEvent &e) override
#define DECL_LISTENERMULTIPLEXER_START(ClassName, InterfaceName)
Definition: macros.hxx:34
#define DECL_LISTENERMULTIPLEXER_END
Definition: macros.hxx:56
#define DECL_LISTENERMULTIPLEXER_START_DLLPUB(ClassName, InterfaceName)
Definition: macros.hxx:45
double getLength(const B2DPolygon &rCandidate)
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)