tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / UnoControls / source / base / multiplexer.cxx
blob12d3b12d721f2cbf7cb52fd832dc0af559543cef
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 #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&),
35 const Event& 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)
44 return;
45 Listeners<Interface>::list.notifyEach(aGuard, method, aLocalEvent);
48 // construct/destruct
50 OMRCListenerMultiplexerHelper::OMRCListenerMultiplexerHelper( const Reference< XWindow >& xControl ,
51 const Reference< XWindow >& xPeer )
52 : m_xPeer ( xPeer )
53 , m_xControl ( xControl )
57 OMRCListenerMultiplexerHelper::~OMRCListenerMultiplexerHelper()
61 // container method
63 void OMRCListenerMultiplexerHelper::setPeer( const Reference< XWindow >& xPeer )
65 std::unique_lock aGuard(m_aMutex);
66 if( m_xPeer == xPeer )
67 return;
69 if( m_xPeer.is() )
71 for_each_container(
72 [this, &aGuard]<class Ifc>(const comphelper::OInterfaceContainerHelper4<Ifc>& c)
74 if (c.getLength(aGuard) > 0)
75 notifyPeer(m_xPeer, Remove<Ifc>);
76 });
78 m_xPeer = xPeer;
79 if( m_xPeer.is() )
81 for_each_container(
82 [this, &aGuard]<class Ifc>(const comphelper::OInterfaceContainerHelper4<Ifc>& c)
84 if (c.getLength(aGuard) > 0)
85 notifyPeer(m_xPeer, Add<Ifc>);
86 });
90 // container method
92 void OMRCListenerMultiplexerHelper::disposeAndClear()
94 std::unique_lock aGuard(m_aMutex);
95 EventObject aEvent;
96 aEvent.Source = m_xControl;
97 for_each_container([&aGuard, &aEvent](auto& c) { c.disposeAndClear(aGuard, aEvent); });
100 // XEventListener
102 void SAL_CALL OMRCListenerMultiplexerHelper::disposing( const EventObject& /*aSource*/ )
104 std::unique_lock aGuard(m_aMutex);
105 // peer is disposed, clear the reference
106 m_xPeer.clear();
109 // XFcousListener
111 void OMRCListenerMultiplexerHelper::focusGained(const FocusEvent& aEvent )
113 Multiplex(&XFocusListener::focusGained, aEvent);
116 // XFcousListener
118 void OMRCListenerMultiplexerHelper::focusLost(const FocusEvent& aEvent )
120 Multiplex(&XFocusListener::focusLost, aEvent);
123 // XWindowListener
125 void OMRCListenerMultiplexerHelper::windowResized(const WindowEvent& aEvent )
127 Multiplex(&XWindowListener::windowResized, aEvent);
130 // XWindowListener
132 void OMRCListenerMultiplexerHelper::windowMoved(const WindowEvent& aEvent )
134 Multiplex(&XWindowListener::windowMoved, aEvent);
137 // XWindowListener
139 void OMRCListenerMultiplexerHelper::windowShown(const EventObject& aEvent )
141 Multiplex(&XWindowListener::windowShown, aEvent);
144 // XWindowListener
146 void OMRCListenerMultiplexerHelper::windowHidden(const EventObject& aEvent )
148 Multiplex(&XWindowListener::windowHidden, aEvent);
151 // XKeyListener
153 void OMRCListenerMultiplexerHelper::keyPressed(const KeyEvent& aEvent)
155 Multiplex(&XKeyListener::keyPressed, aEvent);
158 // XKeyListener
160 void OMRCListenerMultiplexerHelper::keyReleased(const KeyEvent& aEvent)
162 Multiplex(&XKeyListener::keyReleased, aEvent);
165 // XMouseListener
167 void OMRCListenerMultiplexerHelper::mousePressed(const MouseEvent& aEvent)
169 Multiplex(&XMouseListener::mousePressed, aEvent);
172 // XMouseListener
174 void OMRCListenerMultiplexerHelper::mouseReleased(const MouseEvent& aEvent)
176 Multiplex(&XMouseListener::mouseReleased, aEvent);
179 // XMouseListener
181 void OMRCListenerMultiplexerHelper::mouseEntered(const MouseEvent& aEvent)
183 Multiplex(&XMouseListener::mouseEntered, aEvent);
186 // XMouseListener
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);
207 // XPaintListener
209 void OMRCListenerMultiplexerHelper::windowPaint(const PaintEvent& aEvent)
211 Multiplex(&XPaintListener::windowPaint, aEvent);
214 } // namespace unocontrols
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */