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 #include <multiplexer.hxx>
22 #include <osl/diagnose.h>
23 #include <cppuhelper/queryinterface.hxx>
25 using namespace ::cppu
;
26 using namespace ::osl
;
27 using namespace ::com::sun::star::uno
;
28 using namespace ::com::sun::star::awt
;
29 using namespace ::com::sun::star::lang
;
31 namespace unocontrols
{
33 template <class Interface
, typename Event
>
34 void OMRCListenerMultiplexerHelper::Multiplex(void (SAL_CALL
Interface::*method
)(const Event
&),
37 std::unique_lock
aGuard(m_aMutex
);
38 Event aLocalEvent
= event
;
39 /* Remark: The control is the event source not the peer.*/
40 /* We must change the source of the event. */
41 aLocalEvent
.Source
= m_xControl
;
42 /* Is the control not destroyed? */
43 if (!aLocalEvent
.Source
)
45 Listeners
<Interface
>::list
.notifyEach(aGuard
, method
, aLocalEvent
);
50 OMRCListenerMultiplexerHelper::OMRCListenerMultiplexerHelper( const Reference
< XWindow
>& xControl
,
51 const Reference
< XWindow
>& xPeer
)
53 , m_xControl ( xControl
)
57 OMRCListenerMultiplexerHelper::~OMRCListenerMultiplexerHelper()
63 void OMRCListenerMultiplexerHelper::setPeer( const Reference
< XWindow
>& xPeer
)
65 std::unique_lock
aGuard(m_aMutex
);
66 if( m_xPeer
== xPeer
)
72 [this, &aGuard
]<class Ifc
>(const comphelper::OInterfaceContainerHelper4
<Ifc
>& c
)
74 if (c
.getLength(aGuard
) > 0)
75 notifyPeer(m_xPeer
, Remove
<Ifc
>);
82 [this, &aGuard
]<class Ifc
>(const comphelper::OInterfaceContainerHelper4
<Ifc
>& c
)
84 if (c
.getLength(aGuard
) > 0)
85 notifyPeer(m_xPeer
, Add
<Ifc
>);
92 void OMRCListenerMultiplexerHelper::disposeAndClear()
94 std::unique_lock
aGuard(m_aMutex
);
96 aEvent
.Source
= m_xControl
;
97 for_each_container([&aGuard
, &aEvent
](auto& c
) { c
.disposeAndClear(aGuard
, aEvent
); });
102 void SAL_CALL
OMRCListenerMultiplexerHelper::disposing( const EventObject
& /*aSource*/ )
104 std::unique_lock
aGuard(m_aMutex
);
105 // peer is disposed, clear the reference
111 void OMRCListenerMultiplexerHelper::focusGained(const FocusEvent
& aEvent
)
113 Multiplex(&XFocusListener::focusGained
, aEvent
);
118 void OMRCListenerMultiplexerHelper::focusLost(const FocusEvent
& aEvent
)
120 Multiplex(&XFocusListener::focusLost
, aEvent
);
125 void OMRCListenerMultiplexerHelper::windowResized(const WindowEvent
& aEvent
)
127 Multiplex(&XWindowListener::windowResized
, aEvent
);
132 void OMRCListenerMultiplexerHelper::windowMoved(const WindowEvent
& aEvent
)
134 Multiplex(&XWindowListener::windowMoved
, aEvent
);
139 void OMRCListenerMultiplexerHelper::windowShown(const EventObject
& aEvent
)
141 Multiplex(&XWindowListener::windowShown
, aEvent
);
146 void OMRCListenerMultiplexerHelper::windowHidden(const EventObject
& aEvent
)
148 Multiplex(&XWindowListener::windowHidden
, aEvent
);
153 void OMRCListenerMultiplexerHelper::keyPressed(const KeyEvent
& aEvent
)
155 Multiplex(&XKeyListener::keyPressed
, aEvent
);
160 void OMRCListenerMultiplexerHelper::keyReleased(const KeyEvent
& aEvent
)
162 Multiplex(&XKeyListener::keyReleased
, aEvent
);
167 void OMRCListenerMultiplexerHelper::mousePressed(const MouseEvent
& aEvent
)
169 Multiplex(&XMouseListener::mousePressed
, aEvent
);
174 void OMRCListenerMultiplexerHelper::mouseReleased(const MouseEvent
& aEvent
)
176 Multiplex(&XMouseListener::mouseReleased
, aEvent
);
181 void OMRCListenerMultiplexerHelper::mouseEntered(const MouseEvent
& aEvent
)
183 Multiplex(&XMouseListener::mouseEntered
, aEvent
);
188 void OMRCListenerMultiplexerHelper::mouseExited(const MouseEvent
& aEvent
)
190 Multiplex(&XMouseListener::mouseExited
, aEvent
);
193 // XMouseMotionListener
195 void OMRCListenerMultiplexerHelper::mouseDragged(const MouseEvent
& aEvent
)
197 Multiplex(&XMouseMotionListener::mouseDragged
, aEvent
);
200 // XMouseMotionListener
202 void OMRCListenerMultiplexerHelper::mouseMoved(const MouseEvent
& aEvent
)
204 Multiplex(&XMouseMotionListener::mouseMoved
, aEvent
);
209 void OMRCListenerMultiplexerHelper::windowPaint(const PaintEvent
& aEvent
)
211 Multiplex(&XPaintListener::windowPaint
, aEvent
);
214 } // namespace unocontrols
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */