LibreOffice Module avmedia (master) 1
mediaevent_impl.cxx
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#include "mediaevent_impl.hxx"
21#include <osl/mutex.hxx>
22#include <vcl/svapp.hxx>
23#include <vcl/event.hxx>
24#include <vcl/window.hxx>
25
26using namespace ::com::sun::star;
27
28namespace avmedia::priv {
29
31 mpNotifyWindow( &rEventWindow )
32{
33}
34
35
37{
38}
39
40
42{
44 mpNotifyWindow = nullptr;
45}
46
47
48void SAL_CALL MediaEventListenersImpl::disposing( const css::lang::EventObject& )
49{
50}
51
52
53void SAL_CALL MediaEventListenersImpl::keyPressed( const css::awt::KeyEvent& e )
54{
55 const std::unique_lock aGuard( maMutex );
56
57 if( mpNotifyWindow )
58 {
59 vcl::KeyCode aVCLKeyCode( e.KeyCode,
60 ( ( e.Modifiers & 1 ) ? KEY_SHIFT : 0 ) |
61 ( ( e.Modifiers & 2 ) ? KEY_MOD1 : 0 ) |
62 ( ( e.Modifiers & 4 ) ? KEY_MOD2 : 0 ) );
63 KeyEvent aVCLKeyEvt( e.KeyChar, aVCLKeyCode );
64
65 Application::PostKeyEvent( VclEventId::WindowKeyInput, mpNotifyWindow.get(), &aVCLKeyEvt );
66 }
67}
68
69
70void SAL_CALL MediaEventListenersImpl::keyReleased( const css::awt::KeyEvent& e )
71{
72 const std::unique_lock aGuard( maMutex );
73
74 if( mpNotifyWindow )
75 {
76 vcl::KeyCode aVCLKeyCode( e.KeyCode,
77 ( ( e.Modifiers & 1 ) ? KEY_SHIFT : 0 ) |
78 ( ( e.Modifiers & 2 ) ? KEY_MOD1 : 0 ) |
79 ( ( e.Modifiers & 4 ) ? KEY_MOD2 : 0 ) );
80 KeyEvent aVCLKeyEvt( e.KeyChar, aVCLKeyCode );
81 Application::PostKeyEvent( VclEventId::WindowKeyUp, mpNotifyWindow.get(), &aVCLKeyEvt );
82 }
83}
84
85
86void SAL_CALL MediaEventListenersImpl::mousePressed( const css::awt::MouseEvent& e )
87{
88 const std::unique_lock aGuard( maMutex );
89
90 if( mpNotifyWindow )
91 {
92 MouseEvent aVCLMouseEvt( Point( e.X, e.Y ),
93 sal::static_int_cast< sal_uInt16 >(e.ClickCount),
94 MouseEventModifiers::NONE,
95 ( ( e.Buttons & 1 ) ? MOUSE_LEFT : 0 ) |
96 ( ( e.Buttons & 2 ) ? MOUSE_RIGHT : 0 ) |
97 ( ( e.Buttons & 4 ) ? MOUSE_MIDDLE : 0 ),
98 e.Modifiers );
99 Application::PostMouseEvent( VclEventId::WindowMouseButtonDown, mpNotifyWindow.get(), &aVCLMouseEvt );
100 }
101}
102
103
104void SAL_CALL MediaEventListenersImpl::mouseReleased( const css::awt::MouseEvent& e )
105{
106 const std::unique_lock aGuard( maMutex );
107 const SolarMutexGuard aAppGuard;
108
109 if( mpNotifyWindow )
110 {
111 MouseEvent aVCLMouseEvt( Point( e.X, e.Y ),
112 sal::static_int_cast< sal_uInt16 >(e.ClickCount),
113 MouseEventModifiers::NONE,
114 ( ( e.Buttons & 1 ) ? MOUSE_LEFT : 0 ) |
115 ( ( e.Buttons & 2 ) ? MOUSE_RIGHT : 0 ) |
116 ( ( e.Buttons & 4 ) ? MOUSE_MIDDLE : 0 ),
117 e.Modifiers );
118 Application::PostMouseEvent( VclEventId::WindowMouseButtonUp, mpNotifyWindow.get(), &aVCLMouseEvt );
119 }
120}
121
122
123void SAL_CALL MediaEventListenersImpl::mouseEntered( const css::awt::MouseEvent& )
124{
125}
126
127
128void SAL_CALL MediaEventListenersImpl::mouseExited( const css::awt::MouseEvent& )
129{
130}
131
132
133void SAL_CALL MediaEventListenersImpl::mouseDragged( const css::awt::MouseEvent& e )
134{
135 const std::unique_lock aGuard( maMutex );
136
137 if( mpNotifyWindow )
138 {
139 MouseEvent aVCLMouseEvt( Point( e.X, e.Y ), 0, MouseEventModifiers::NONE, e.Buttons, e.Modifiers );
140 Application::PostMouseEvent( VclEventId::WindowMouseMove, mpNotifyWindow.get(), &aVCLMouseEvt );
141 }
142}
143
144
145void SAL_CALL MediaEventListenersImpl::mouseMoved( const css::awt::MouseEvent& e )
146{
147 const std::unique_lock aGuard( maMutex );
148
149 if( mpNotifyWindow )
150 {
151 MouseEvent aVCLMouseEvt( Point( e.X, e.Y ), 0, MouseEventModifiers::NONE, e.Buttons, e.Modifiers );
152 Application::PostMouseEvent( VclEventId::WindowMouseMove, mpNotifyWindow.get(), &aVCLMouseEvt );
153 }
154}
155
156
157void SAL_CALL MediaEventListenersImpl::focusGained( const css::awt::FocusEvent& )
158{
159}
160
161
162void SAL_CALL MediaEventListenersImpl::focusLost( const css::awt::FocusEvent& )
163{
164}
165
166
167} // namespace
168
169/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static ImplSVEvent * PostKeyEvent(VclEventId nEvent, vcl::Window *pWin, KeyEvent const *pKeyEvent)
static ImplSVEvent * PostMouseEvent(VclEventId nEvent, vcl::Window *pWin, MouseEvent const *pMouseEvent)
static void RemoveMouseAndKeyEvents(vcl::Window *pWin)
reference_type * get() const
MediaEventListenersImpl(vcl::Window &rNotifyWindow)
virtual void SAL_CALL keyReleased(const css::awt::KeyEvent &e) override
virtual void SAL_CALL mouseDragged(const css::awt::MouseEvent &e) override
virtual void SAL_CALL keyPressed(const css::awt::KeyEvent &e) override
virtual void SAL_CALL mouseExited(const css::awt::MouseEvent &e) override
virtual void SAL_CALL mouseEntered(const css::awt::MouseEvent &e) override
virtual void SAL_CALL focusLost(const css::awt::FocusEvent &e) override
virtual void SAL_CALL mouseReleased(const css::awt::MouseEvent &e) override
virtual void SAL_CALL focusGained(const css::awt::FocusEvent &e) override
virtual void SAL_CALL mousePressed(const css::awt::MouseEvent &e) override
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
virtual void SAL_CALL mouseMoved(const css::awt::MouseEvent &e) override
#define MOUSE_LEFT
#define MOUSE_MIDDLE
#define MOUSE_RIGHT
constexpr sal_uInt16 KEY_MOD2
constexpr sal_uInt16 KEY_MOD1
constexpr sal_uInt16 KEY_SHIFT