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_TOOLKIT_HELPER_LISTENERMULTIPLEXER_HXX
21 #define INCLUDED_TOOLKIT_HELPER_LISTENERMULTIPLEXER_HXX
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>
45 #include <cppuhelper/queryinterface.hxx>
46 #include <cppuhelper/weak.hxx>
47 #include <comphelper/interfacecontainer4.hxx>
48 #include <toolkit/helper/macros.hxx>
49 #include <com/sun/star/awt/grid/XGridSelectionListener.hpp>
50 #include <com/sun/star/awt/tab/XTabPageContainerListener.hpp>
52 // class ListenerMultiplexerBase
54 template <class ListenerT
>
55 class UNLESS_MERGELIBS(TOOLKIT_DLLPUBLIC
) ListenerMultiplexerBase
:
56 public css::uno::XInterface
59 ::cppu::OWeakObject
& mrContext
;
61 mutable std::mutex m_aMutex
;
62 ::comphelper::OInterfaceContainerHelper4
<ListenerT
> maListeners
;
64 ::cppu::OWeakObject
& GetContext() { return mrContext
; }
67 ListenerMultiplexerBase( ::cppu::OWeakObject
& rSource
)
72 virtual ~ListenerMultiplexerBase()
76 // css::uno::XInterface
77 css::uno::Any SAL_CALL
queryInterface(const css::uno::Type
& rType
) override
79 return ::cppu::queryInterface(rType
, static_cast<css::uno::XInterface
*>(this));
82 void SAL_CALL
acquire() noexcept override
{ mrContext
.acquire(); }
83 void SAL_CALL
release() noexcept override
{ mrContext
.release(); }
85 void addInterface( const css::uno::Reference
<ListenerT
>& l
)
87 std::unique_lock
g(m_aMutex
);
88 maListeners
.addInterface(g
, l
);
91 void removeInterface( const css::uno::Reference
<ListenerT
>& l
)
93 std::unique_lock
g(m_aMutex
);
94 maListeners
.removeInterface(g
, l
);
97 void disposeAndClear(const css::lang::EventObject
& rDisposeEvent
)
99 std::unique_lock
g(m_aMutex
);
100 maListeners
.disposeAndClear(g
, rDisposeEvent
);
103 void disposeAndClear(std::unique_lock
<std::mutex
>& rGuard
, const css::lang::EventObject
& rDisposeEvent
)
105 maListeners
.disposeAndClear(rGuard
, rDisposeEvent
);
108 sal_Int32
getLength() const
110 std::unique_lock
g(m_aMutex
);
111 return maListeners
.getLength(g
);
114 template <typename EventT
>
115 inline void notifyEach(void (SAL_CALL
ListenerT::*NotificationMethod
)(const EventT
&),
116 const EventT
& Event
) const
118 std::unique_lock
g(m_aMutex
);
119 return maListeners
.notifyEach(g
, NotificationMethod
, Event
);
123 // class EventListenerMultiplexer
125 DECL_LISTENERMULTIPLEXER_START( EventListenerMultiplexer
, css::lang::XEventListener
)
126 DECL_LISTENERMULTIPLEXER_END
129 // class FocusListenerMultiplexer
131 DECL_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
;
134 DECL_LISTENERMULTIPLEXER_END
137 // class WindowListenerMultiplexer
139 DECL_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
;
144 DECL_LISTENERMULTIPLEXER_END
147 // class VclContainerListenerMultiplexer
149 DECL_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
;
152 DECL_LISTENERMULTIPLEXER_END
155 // class KeyListenerMultiplexer
157 DECL_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
;
160 DECL_LISTENERMULTIPLEXER_END
163 // class MouseListenerMultiplexer
165 DECL_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
;
170 DECL_LISTENERMULTIPLEXER_END
173 // class MouseMotionListenerMultiplexer
175 DECL_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
;
178 DECL_LISTENERMULTIPLEXER_END
181 // class PaintListenerMultiplexer
183 DECL_LISTENERMULTIPLEXER_START_DLLPUB( PaintListenerMultiplexer
, css::awt::XPaintListener
)
184 void SAL_CALL
windowPaint( const css::awt::PaintEvent
& e
) override
;
185 DECL_LISTENERMULTIPLEXER_END
188 // class TopWindowListenerMultiplexer
190 DECL_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
;
198 DECL_LISTENERMULTIPLEXER_END
201 // class TextListenerMultiplexer
203 DECL_LISTENERMULTIPLEXER_START_DLLPUB( TextListenerMultiplexer
, css::awt::XTextListener
)
204 void SAL_CALL
textChanged( const css::awt::TextEvent
& rEvent
) override
;
205 DECL_LISTENERMULTIPLEXER_END
208 // class ActionListenerMultiplexer
210 DECL_LISTENERMULTIPLEXER_START( ActionListenerMultiplexer
, css::awt::XActionListener
)
211 void SAL_CALL
actionPerformed( const css::awt::ActionEvent
& rEvent
) override
;
212 DECL_LISTENERMULTIPLEXER_END
215 // class ItemListenerMultiplexer
217 DECL_LISTENERMULTIPLEXER_START( ItemListenerMultiplexer
, css::awt::XItemListener
)
218 void SAL_CALL
itemStateChanged( const css::awt::ItemEvent
& rEvent
) override
;
219 DECL_LISTENERMULTIPLEXER_END
222 // class TabListenerMultiplexer
224 DECL_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
;
230 DECL_LISTENERMULTIPLEXER_END
233 // class ContainerListenerMultiplexer
235 DECL_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
;
239 DECL_LISTENERMULTIPLEXER_END
242 // class SpinListenerMultiplexer
244 DECL_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
;
249 DECL_LISTENERMULTIPLEXER_END
252 // class AdjustmentListenerMultiplexer
254 DECL_LISTENERMULTIPLEXER_START( AdjustmentListenerMultiplexer
, css::awt::XAdjustmentListener
)
255 void SAL_CALL
adjustmentValueChanged( const css::awt::AdjustmentEvent
& rEvent
) override
;
256 DECL_LISTENERMULTIPLEXER_END
259 // class MenuListenerMultiplexer
261 DECL_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
;
266 DECL_LISTENERMULTIPLEXER_END
269 // class TreeSelectionListenerMultiplexer
271 DECL_LISTENERMULTIPLEXER_START( TreeSelectionListenerMultiplexer
, css::view::XSelectionChangeListener
)
272 virtual void SAL_CALL
selectionChanged( const css::lang::EventObject
& aEvent
) override
;
273 DECL_LISTENERMULTIPLEXER_END
276 // class TreeExpansionListenerMultiplexer
278 DECL_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
;
284 DECL_LISTENERMULTIPLEXER_END
287 // class TreeEditListenerMultiplexer
289 DECL_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
;
292 DECL_LISTENERMULTIPLEXER_END
295 // class SelectionListenerMultiplexer
297 DECL_LISTENERMULTIPLEXER_START_DLLPUB( SelectionListenerMultiplexer
, css::awt::grid::XGridSelectionListener
)
298 void SAL_CALL
selectionChanged( const css::awt::grid::GridSelectionEvent
& aEvent
) override
;
299 DECL_LISTENERMULTIPLEXER_END
302 // class TabPageListenerMultiplexer
304 DECL_LISTENERMULTIPLEXER_START( TabPageListenerMultiplexer
, css::awt::tab::XTabPageContainerListener
)
305 void SAL_CALL
tabPageActivated( const css::awt::tab::TabPageActivatedEvent
& aEvent
) override
;
306 DECL_LISTENERMULTIPLEXER_END
308 #endif // INCLUDED_TOOLKIT_HELPER_LISTENERMULTIPLEXER_HXX
310 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */