1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include "mediaevent_impl.hxx"
29 #include "mediawindow_impl.hxx"
30 #include <osl/mutex.hxx>
31 #include <vos/mutex.hxx>
32 #include <vcl/svapp.hxx>
33 #include <vcl/event.hxx>
34 
35 using namespace ::com::sun::star;
36 
37 /* Definition of MediaWindowImpl class */
38 
39 namespace avmedia { namespace priv {
40 // ---------------------------
41 // - MediaEventListenersImpl -
42 // ---------------------------
43 
44 MediaEventListenersImpl::MediaEventListenersImpl( Window& rEventWindow ) :
45 	mpNotifyWindow( &rEventWindow )
46 {
47 }
48 
49 // ---------------------------------------------------------------------
50 
51 MediaEventListenersImpl::~MediaEventListenersImpl()
52 {
53 }
54 
55 // ---------------------------------------------------------------------
56 
57 void MediaEventListenersImpl::cleanUp()
58 {
59     Application::RemoveMouseAndKeyEvents( reinterpret_cast< ::Window* >( mpNotifyWindow ) );
60     mpNotifyWindow = NULL;
61 }
62 
63 // ---------------------------------------------------------------------
64 
65 void SAL_CALL MediaEventListenersImpl::disposing( const ::com::sun::star::lang::EventObject& /* Source */ )
66     throw (::com::sun::star::uno::RuntimeException)
67 {
68 }
69 
70 // ---------------------------------------------------------------------
71 
72 void SAL_CALL MediaEventListenersImpl::keyPressed( const ::com::sun::star::awt::KeyEvent& e )
73     throw (::com::sun::star::uno::RuntimeException)
74 {
75     const ::osl::MutexGuard aGuard( maMutex );
76     const ::vos::OGuard aAppGuard( Application::GetSolarMutex() );
77 
78     if( mpNotifyWindow )
79     {
80         KeyCode aVCLKeyCode( e.KeyCode,
81                             ( ( e.Modifiers & 1 ) ? KEY_SHIFT : 0 ) |
82                             ( ( e.Modifiers & 2 ) ? KEY_MOD1 : 0 ) |
83                             ( ( e.Modifiers & 4 ) ? KEY_MOD2 : 0 ) );
84         KeyEvent aVCLKeyEvt( e.KeyChar, aVCLKeyCode );
85 
86         Application::PostKeyEvent( VCLEVENT_WINDOW_KEYINPUT, reinterpret_cast< ::Window* >( mpNotifyWindow ), &aVCLKeyEvt );
87     }
88 }
89 
90 // ---------------------------------------------------------------------
91 
92 void SAL_CALL MediaEventListenersImpl::keyReleased( const ::com::sun::star::awt::KeyEvent& e )
93     throw (::com::sun::star::uno::RuntimeException)
94 {
95     const ::osl::MutexGuard aGuard( maMutex );
96     const ::vos::OGuard aAppGuard( Application::GetSolarMutex() );
97 
98     if( mpNotifyWindow )
99     {
100         KeyCode aVCLKeyCode( e.KeyCode,
101                             ( ( e.Modifiers & 1 ) ? KEY_SHIFT : 0 ) |
102                             ( ( e.Modifiers & 2 ) ? KEY_MOD1 : 0 ) |
103                             ( ( e.Modifiers & 4 ) ? KEY_MOD2 : 0 ) );
104         KeyEvent aVCLKeyEvt( e.KeyChar, aVCLKeyCode );
105         Application::PostKeyEvent( VCLEVENT_WINDOW_KEYUP, reinterpret_cast< ::Window* >( mpNotifyWindow ), &aVCLKeyEvt );
106     }
107 }
108 
109 // ---------------------------------------------------------------------
110 
111 void SAL_CALL MediaEventListenersImpl::mousePressed( const ::com::sun::star::awt::MouseEvent& e )
112     throw (::com::sun::star::uno::RuntimeException)
113 {
114     const ::osl::MutexGuard aGuard( maMutex );
115     const ::vos::OGuard aAppGuard( Application::GetSolarMutex() );
116 
117     if( mpNotifyWindow )
118     {
119         MouseEvent aVCLMouseEvt( Point( e.X, e.Y ),
120                                  sal::static_int_cast< sal_uInt16 >(e.ClickCount),
121                                  0,
122                                 ( ( e.Buttons & 1 ) ? MOUSE_LEFT : 0 ) |
123                                 ( ( e.Buttons & 2 ) ? MOUSE_RIGHT : 0 ) |
124                                 ( ( e.Buttons & 4 ) ? MOUSE_MIDDLE : 0 ),
125                                 e.Modifiers );
126         Application::PostMouseEvent( VCLEVENT_WINDOW_MOUSEBUTTONDOWN, reinterpret_cast< ::Window* >( mpNotifyWindow ), &aVCLMouseEvt );
127     }
128 }
129 
130 // ----------------------------------------------gvd-----------------------
131 
132 void SAL_CALL MediaEventListenersImpl::mouseReleased( const ::com::sun::star::awt::MouseEvent& e )
133     throw (::com::sun::star::uno::RuntimeException)
134 {
135     const ::osl::MutexGuard aGuard( maMutex );
136     const ::vos::OGuard aAppGuard( Application::GetSolarMutex() );
137 
138     if( mpNotifyWindow )
139     {
140         MouseEvent aVCLMouseEvt( Point( e.X, e.Y ),
141                                  sal::static_int_cast< sal_uInt16 >(e.ClickCount),
142                                  0,
143                                 ( ( e.Buttons & 1 ) ? MOUSE_LEFT : 0 ) |
144                                 ( ( e.Buttons & 2 ) ? MOUSE_RIGHT : 0 ) |
145                                 ( ( e.Buttons & 4 ) ? MOUSE_MIDDLE : 0 ),
146                                 e.Modifiers );
147         Application::PostMouseEvent( VCLEVENT_WINDOW_MOUSEBUTTONUP, reinterpret_cast< ::Window* >( mpNotifyWindow ), &aVCLMouseEvt );
148     }
149 }
150 
151 // ---------------------------------------------------------------------
152 
153 void SAL_CALL MediaEventListenersImpl::mouseEntered( const ::com::sun::star::awt::MouseEvent& /* e */ )
154     throw (::com::sun::star::uno::RuntimeException)
155 {
156     const ::osl::MutexGuard aGuard( maMutex );
157     const ::vos::OGuard aAppGuard( Application::GetSolarMutex() );
158 
159     if( mpNotifyWindow )
160     {
161     }
162 }
163 
164 // ---------------------------------------------------------------------
165 
166 void SAL_CALL MediaEventListenersImpl::mouseExited( const ::com::sun::star::awt::MouseEvent& /* e */ )
167     throw (::com::sun::star::uno::RuntimeException)
168 {
169     const ::osl::MutexGuard aGuard( maMutex );
170     const ::vos::OGuard aAppGuard( Application::GetSolarMutex() );
171 
172     if( mpNotifyWindow )
173     {
174     }
175 }
176 
177 // ---------------------------------------------------------------------
178 
179 void SAL_CALL MediaEventListenersImpl::mouseDragged( const ::com::sun::star::awt::MouseEvent& e )
180     throw (::com::sun::star::uno::RuntimeException)
181 {
182     const ::osl::MutexGuard aGuard( maMutex );
183     const ::vos::OGuard aAppGuard( Application::GetSolarMutex() );
184 
185     if( mpNotifyWindow )
186     {
187         MouseEvent aVCLMouseEvt( Point( e.X, e.Y ), 0, 0, e.Buttons, e.Modifiers );
188         Application::PostMouseEvent( VCLEVENT_WINDOW_MOUSEMOVE, reinterpret_cast< ::Window* >( mpNotifyWindow ), &aVCLMouseEvt );
189     }
190 }
191 
192 // ---------------------------------------------------------------------
193 
194 void SAL_CALL MediaEventListenersImpl::mouseMoved( const ::com::sun::star::awt::MouseEvent& e )
195     throw (::com::sun::star::uno::RuntimeException)
196 {
197     const ::osl::MutexGuard aGuard( maMutex );
198     const ::vos::OGuard aAppGuard( Application::GetSolarMutex() );
199 
200     if( mpNotifyWindow )
201     {
202         MouseEvent aVCLMouseEvt( Point( e.X, e.Y ), 0, 0, e.Buttons, e.Modifiers );
203         Application::PostMouseEvent( VCLEVENT_WINDOW_MOUSEMOVE, reinterpret_cast< ::Window* >( mpNotifyWindow ), &aVCLMouseEvt );
204     }
205 }
206 
207 // ---------------------------------------------------------------------
208 
209 void SAL_CALL MediaEventListenersImpl::focusGained( const ::com::sun::star::awt::FocusEvent& /* e */ )
210     throw (::com::sun::star::uno::RuntimeException)
211 {
212 }
213 
214 // ---------------------------------------------------------------------
215 
216 void SAL_CALL MediaEventListenersImpl::focusLost( const ::com::sun::star::awt::FocusEvent& /* e */ )
217     throw (::com::sun::star::uno::RuntimeException)
218 {
219 }
220 
221 } // namespace priv
222 } // namespace avemdia
223 
224