1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "mediaevent_impl.hxx"
25 #include "mediawindow_impl.hxx"
26 #include <osl/mutex.hxx>
27 #include <vos/mutex.hxx>
28 #include <vcl/svapp.hxx>
29 #include <vcl/event.hxx>
30 
31 using namespace ::com::sun::star;
32 
33 /* Definition of MediaWindowImpl class */
34 
35 namespace avmedia { namespace priv {
36 // ---------------------------
37 // - MediaEventListenersImpl -
38 // ---------------------------
39 
40 MediaEventListenersImpl::MediaEventListenersImpl( Window& rEventWindow ) :
41 	mpNotifyWindow( &rEventWindow )
42 {
43 }
44 
45 // ---------------------------------------------------------------------
46 
47 MediaEventListenersImpl::~MediaEventListenersImpl()
48 {
49 }
50 
51 // ---------------------------------------------------------------------
52 
53 void MediaEventListenersImpl::cleanUp()
54 {
55     Application::RemoveMouseAndKeyEvents( reinterpret_cast< ::Window* >( mpNotifyWindow ) );
56     mpNotifyWindow = NULL;
57 }
58 
59 // ---------------------------------------------------------------------
60 
61 void SAL_CALL MediaEventListenersImpl::disposing( const ::com::sun::star::lang::EventObject& /* Source */ )
62     throw (::com::sun::star::uno::RuntimeException)
63 {
64 }
65 
66 // ---------------------------------------------------------------------
67 
68 void SAL_CALL MediaEventListenersImpl::keyPressed( const ::com::sun::star::awt::KeyEvent& e )
69     throw (::com::sun::star::uno::RuntimeException)
70 {
71     const ::osl::MutexGuard aGuard( maMutex );
72     const ::vos::OGuard aAppGuard( Application::GetSolarMutex() );
73 
74     if( mpNotifyWindow )
75     {
76         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 
82         Application::PostKeyEvent( VCLEVENT_WINDOW_KEYINPUT, reinterpret_cast< ::Window* >( mpNotifyWindow ), &aVCLKeyEvt );
83     }
84 }
85 
86 // ---------------------------------------------------------------------
87 
88 void SAL_CALL MediaEventListenersImpl::keyReleased( const ::com::sun::star::awt::KeyEvent& e )
89     throw (::com::sun::star::uno::RuntimeException)
90 {
91     const ::osl::MutexGuard aGuard( maMutex );
92     const ::vos::OGuard aAppGuard( Application::GetSolarMutex() );
93 
94     if( mpNotifyWindow )
95     {
96         KeyCode aVCLKeyCode( e.KeyCode,
97                             ( ( e.Modifiers & 1 ) ? KEY_SHIFT : 0 ) |
98                             ( ( e.Modifiers & 2 ) ? KEY_MOD1 : 0 ) |
99                             ( ( e.Modifiers & 4 ) ? KEY_MOD2 : 0 ) );
100         KeyEvent aVCLKeyEvt( e.KeyChar, aVCLKeyCode );
101         Application::PostKeyEvent( VCLEVENT_WINDOW_KEYUP, reinterpret_cast< ::Window* >( mpNotifyWindow ), &aVCLKeyEvt );
102     }
103 }
104 
105 // ---------------------------------------------------------------------
106 
107 void SAL_CALL MediaEventListenersImpl::mousePressed( const ::com::sun::star::awt::MouseEvent& e )
108     throw (::com::sun::star::uno::RuntimeException)
109 {
110     const ::osl::MutexGuard aGuard( maMutex );
111     const ::vos::OGuard aAppGuard( Application::GetSolarMutex() );
112 
113     if( mpNotifyWindow )
114     {
115         MouseEvent aVCLMouseEvt( Point( e.X, e.Y ),
116                                  sal::static_int_cast< sal_uInt16 >(e.ClickCount),
117                                  0,
118                                 ( ( e.Buttons & 1 ) ? MOUSE_LEFT : 0 ) |
119                                 ( ( e.Buttons & 2 ) ? MOUSE_RIGHT : 0 ) |
120                                 ( ( e.Buttons & 4 ) ? MOUSE_MIDDLE : 0 ),
121                                 e.Modifiers );
122         Application::PostMouseEvent( VCLEVENT_WINDOW_MOUSEBUTTONDOWN, reinterpret_cast< ::Window* >( mpNotifyWindow ), &aVCLMouseEvt );
123     }
124 }
125 
126 // ----------------------------------------------gvd-----------------------
127 
128 void SAL_CALL MediaEventListenersImpl::mouseReleased( const ::com::sun::star::awt::MouseEvent& e )
129     throw (::com::sun::star::uno::RuntimeException)
130 {
131     const ::osl::MutexGuard aGuard( maMutex );
132     const ::vos::OGuard aAppGuard( Application::GetSolarMutex() );
133 
134     if( mpNotifyWindow )
135     {
136         MouseEvent aVCLMouseEvt( Point( e.X, e.Y ),
137                                  sal::static_int_cast< sal_uInt16 >(e.ClickCount),
138                                  0,
139                                 ( ( e.Buttons & 1 ) ? MOUSE_LEFT : 0 ) |
140                                 ( ( e.Buttons & 2 ) ? MOUSE_RIGHT : 0 ) |
141                                 ( ( e.Buttons & 4 ) ? MOUSE_MIDDLE : 0 ),
142                                 e.Modifiers );
143         Application::PostMouseEvent( VCLEVENT_WINDOW_MOUSEBUTTONUP, reinterpret_cast< ::Window* >( mpNotifyWindow ), &aVCLMouseEvt );
144     }
145 }
146 
147 // ---------------------------------------------------------------------
148 
149 void SAL_CALL MediaEventListenersImpl::mouseEntered( const ::com::sun::star::awt::MouseEvent& /* e */ )
150     throw (::com::sun::star::uno::RuntimeException)
151 {
152     const ::osl::MutexGuard aGuard( maMutex );
153     const ::vos::OGuard aAppGuard( Application::GetSolarMutex() );
154 
155     if( mpNotifyWindow )
156     {
157     }
158 }
159 
160 // ---------------------------------------------------------------------
161 
162 void SAL_CALL MediaEventListenersImpl::mouseExited( const ::com::sun::star::awt::MouseEvent& /* e */ )
163     throw (::com::sun::star::uno::RuntimeException)
164 {
165     const ::osl::MutexGuard aGuard( maMutex );
166     const ::vos::OGuard aAppGuard( Application::GetSolarMutex() );
167 
168     if( mpNotifyWindow )
169     {
170     }
171 }
172 
173 // ---------------------------------------------------------------------
174 
175 void SAL_CALL MediaEventListenersImpl::mouseDragged( const ::com::sun::star::awt::MouseEvent& e )
176     throw (::com::sun::star::uno::RuntimeException)
177 {
178     const ::osl::MutexGuard aGuard( maMutex );
179     const ::vos::OGuard aAppGuard( Application::GetSolarMutex() );
180 
181     if( mpNotifyWindow )
182     {
183         MouseEvent aVCLMouseEvt( Point( e.X, e.Y ), 0, 0, e.Buttons, e.Modifiers );
184         Application::PostMouseEvent( VCLEVENT_WINDOW_MOUSEMOVE, reinterpret_cast< ::Window* >( mpNotifyWindow ), &aVCLMouseEvt );
185     }
186 }
187 
188 // ---------------------------------------------------------------------
189 
190 void SAL_CALL MediaEventListenersImpl::mouseMoved( const ::com::sun::star::awt::MouseEvent& e )
191     throw (::com::sun::star::uno::RuntimeException)
192 {
193     const ::osl::MutexGuard aGuard( maMutex );
194     const ::vos::OGuard aAppGuard( Application::GetSolarMutex() );
195 
196     if( mpNotifyWindow )
197     {
198         MouseEvent aVCLMouseEvt( Point( e.X, e.Y ), 0, 0, e.Buttons, e.Modifiers );
199         Application::PostMouseEvent( VCLEVENT_WINDOW_MOUSEMOVE, reinterpret_cast< ::Window* >( mpNotifyWindow ), &aVCLMouseEvt );
200     }
201 }
202 
203 // ---------------------------------------------------------------------
204 
205 void SAL_CALL MediaEventListenersImpl::focusGained( const ::com::sun::star::awt::FocusEvent& /* e */ )
206     throw (::com::sun::star::uno::RuntimeException)
207 {
208 }
209 
210 // ---------------------------------------------------------------------
211 
212 void SAL_CALL MediaEventListenersImpl::focusLost( const ::com::sun::star::awt::FocusEvent& /* e */ )
213     throw (::com::sun::star::uno::RuntimeException)
214 {
215 }
216 
217 } // namespace priv
218 } // namespace avemdia
219 
220