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 "mediaevent_impl.hxx"
21 #include <osl/mutex.hxx>
22 #include <vcl/svapp.hxx>
23 #include <vcl/event.hxx>
24 #include <vcl/window.hxx>
26 using namespace ::com::sun::star
;
28 namespace avmedia::priv
{
30 MediaEventListenersImpl::MediaEventListenersImpl( vcl::Window
& rEventWindow
) :
31 mpNotifyWindow( &rEventWindow
)
36 MediaEventListenersImpl::~MediaEventListenersImpl()
41 void MediaEventListenersImpl::cleanUp()
43 Application::RemoveMouseAndKeyEvents( mpNotifyWindow
.get() );
44 mpNotifyWindow
= nullptr;
48 void SAL_CALL
MediaEventListenersImpl::disposing( const css::lang::EventObject
& )
53 void SAL_CALL
MediaEventListenersImpl::keyPressed( const css::awt::KeyEvent
& e
)
55 const std::unique_lock
aGuard( maMutex
);
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
);
65 Application::PostKeyEvent( VclEventId::WindowKeyInput
, mpNotifyWindow
.get(), &aVCLKeyEvt
);
70 void SAL_CALL
MediaEventListenersImpl::keyReleased( const css::awt::KeyEvent
& e
)
72 const std::unique_lock
aGuard( maMutex
);
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
);
86 void SAL_CALL
MediaEventListenersImpl::mousePressed( const css::awt::MouseEvent
& e
)
88 const std::unique_lock
aGuard( maMutex
);
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 ),
99 Application::PostMouseEvent( VclEventId::WindowMouseButtonDown
, mpNotifyWindow
.get(), &aVCLMouseEvt
);
104 void SAL_CALL
MediaEventListenersImpl::mouseReleased( const css::awt::MouseEvent
& e
)
106 const std::unique_lock
aGuard( maMutex
);
107 const SolarMutexGuard aAppGuard
;
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 ),
118 Application::PostMouseEvent( VclEventId::WindowMouseButtonUp
, mpNotifyWindow
.get(), &aVCLMouseEvt
);
123 void SAL_CALL
MediaEventListenersImpl::mouseEntered( const css::awt::MouseEvent
& )
128 void SAL_CALL
MediaEventListenersImpl::mouseExited( const css::awt::MouseEvent
& )
133 void SAL_CALL
MediaEventListenersImpl::mouseDragged( const css::awt::MouseEvent
& e
)
135 const std::unique_lock
aGuard( maMutex
);
139 MouseEvent
aVCLMouseEvt( Point( e
.X
, e
.Y
), 0, MouseEventModifiers::NONE
, e
.Buttons
, e
.Modifiers
);
140 Application::PostMouseEvent( VclEventId::WindowMouseMove
, mpNotifyWindow
.get(), &aVCLMouseEvt
);
145 void SAL_CALL
MediaEventListenersImpl::mouseMoved( const css::awt::MouseEvent
& e
)
147 const std::unique_lock
aGuard( maMutex
);
151 MouseEvent
aVCLMouseEvt( Point( e
.X
, e
.Y
), 0, MouseEventModifiers::NONE
, e
.Buttons
, e
.Modifiers
);
152 Application::PostMouseEvent( VclEventId::WindowMouseMove
, mpNotifyWindow
.get(), &aVCLMouseEvt
);
157 void SAL_CALL
MediaEventListenersImpl::focusGained( const css::awt::FocusEvent
& )
162 void SAL_CALL
MediaEventListenersImpl::focusLost( const css::awt::FocusEvent
& )
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */