2b75b9f7108a4e5e35de3ee2e62d98baec85c52d
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / windows / window-base-win.cpp
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/window-system/windows/window-base-win.h>
20
21 // EXTERNAL_HEADERS
22 #include <dali/public-api/object/any.h>
23 #include <dali/integration-api/debug.h>
24
25 // INTERNAL HEADERS
26 #include <dali/internal/window-system/common/window-impl.h>
27 #include <dali/internal/window-system/common/window-render-surface.h>
28 #include <dali/internal/window-system/common/window-system.h>
29
30 namespace Dali
31 {
32
33 namespace Internal
34 {
35
36 namespace Adaptor
37 {
38
39 namespace
40 {
41
42 const Device::Class::Type DEFAULT_DEVICE_CLASS = Device::Class::NONE;
43 const Device::Subclass::Type DEFAULT_DEVICE_SUBCLASS = Device::Subclass::NONE;
44
45 const unsigned int PRIMARY_TOUCH_BUTTON_ID( 1 );
46
47 #if defined(DEBUG_ENABLED)
48 Debug::Filter* gWindowBaseLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_WINDOW_BASE" );
49 #endif
50
51 } // unnamed namespace
52
53 WindowBaseWin::WindowBaseWin( Dali::PositionSize positionSize, Any surface, bool isTransparent )
54 : mWin32Window( 0 ),
55   mOwnSurface( false ),
56   mIsTransparent( false ), // Should only be set to true once we actually create a transparent window regardless of what isTransparent is.
57   mRotationAppSet( false )
58 {
59   Initialize( positionSize, surface, isTransparent );
60 }
61
62 WindowBaseWin::~WindowBaseWin()
63 {
64   WindowsPlatformImplementation::PostWinMessage( WM_CLOSE, 0, 0, mWin32Window );
65 }
66
67 void WindowBaseWin::Initialize( PositionSize positionSize, Any surface, bool isTransparent )
68 {
69   // see if there is a surface in Any surface
70   unsigned int surfaceId = GetSurfaceId( surface );
71
72   // if the surface is empty, create a new one.
73   if( surfaceId == 0 )
74   {
75     // we own the surface about to created
76     mOwnSurface = true;
77     CreateWinWindow( positionSize, isTransparent );
78   }
79   else
80   {
81     // XLib should already be initialized so no point in calling XInitThreads
82     mWin32Window = static_cast< WinWindowHandle >( surfaceId );
83   }
84
85   WindowsPlatformImplementation::SetListener( MakeCallback( this, &WindowBaseWin::EventEntry ) );
86 }
87
88 void WindowBaseWin::OnDeleteRequest()
89 {
90   mDeleteRequestSignal.Emit();
91 }
92
93 void WindowBaseWin::OnFocusIn( int type, TWinEventInfo *event )
94 {
95 }
96
97 void WindowBaseWin::OnFocusOut( int type, TWinEventInfo *event )
98 {
99 }
100
101 void WindowBaseWin::OnWindowDamaged( int type, TWinEventInfo *event )
102 {
103   Event_Mouse_Button* windowDamagedEvent( (Event_Mouse_Button*)event );\r
104 \r
105   if( windowDamagedEvent->window == mWin32Window )\r
106   {\r
107     DamageArea area;\r
108     area.x = 0;\r
109     area.y = 0;\r
110     WindowSystem::GetScreenSize( area.width, area.height );\r
111 \r
112     mWindowDamagedSignal.Emit( area );\r
113   }\r
114 }
115
116 void WindowBaseWin::OnMouseButtonDown( int type, TWinEventInfo *event )
117 {
118   Event_Mouse_Button touchEvent = *((Event_Mouse_Button*)event);
119   touchEvent.timestamp = GetTickCount();
120   touchEvent.x = LOWORD( event->lParam );\r
121   touchEvent.y = HIWORD( event->lParam );\r
122   touchEvent.multi.device = DEVICE_MOUSE;
123
124   if( touchEvent.window == mWin32Window )
125   {
126     PointState::Type state ( PointState::DOWN );
127
128     Integration::Point point;
129     point.SetDeviceId( touchEvent.multi.device );
130     point.SetState( state );
131     point.SetScreenPosition( Vector2( touchEvent.x, touchEvent.y + WindowsPlatformImplementation::GetEdgeHeight() ) );
132     point.SetRadius( touchEvent.multi.radius, Vector2( touchEvent.multi.radius_x, touchEvent.multi.radius_y ) );
133     point.SetPressure( touchEvent.multi.pressure );
134     point.SetAngle( Degree( touchEvent.multi.angle ) );
135
136     mTouchEventSignal.Emit( point, touchEvent.timestamp );
137   }
138 }
139
140 void WindowBaseWin::OnMouseButtonUp( int type, TWinEventInfo *event )
141 {
142   Event_Mouse_Button touchEvent = *( (Event_Mouse_Button*)event );
143   touchEvent.timestamp = GetTickCount();
144   touchEvent.x = LOWORD( event->lParam );\r
145   touchEvent.y = HIWORD( event->lParam );\r
146   touchEvent.multi.device = DEVICE_MOUSE;
147
148   if( touchEvent.window == mWin32Window )
149   {
150     PointState::Type state( PointState::UP );
151
152     Integration::Point point;
153     point.SetDeviceId( touchEvent.multi.device );
154     point.SetState( state );
155     point.SetScreenPosition( Vector2( touchEvent.x, touchEvent.y + WindowsPlatformImplementation::GetEdgeHeight() ) );
156     point.SetRadius( touchEvent.multi.radius, Vector2( touchEvent.multi.radius_x, touchEvent.multi.radius_y ) );
157     point.SetPressure( touchEvent.multi.pressure );
158     point.SetAngle( Degree( touchEvent.multi.angle ) );
159
160     mTouchEventSignal.Emit( point, touchEvent.timestamp );
161   }
162 }
163
164 void WindowBaseWin::OnMouseButtonMove( int type, TWinEventInfo *event )
165 {
166   Event_Mouse_Button touchEvent = *((Event_Mouse_Button*)event);
167   touchEvent.timestamp = GetTickCount();
168   touchEvent.x = LOWORD( event->lParam );\r
169   touchEvent.y = HIWORD( event->lParam );\r
170   touchEvent.multi.device = DEVICE_MOUSE;
171
172   if( touchEvent.window == mWin32Window )
173   {
174     PointState::Type state( PointState::MOTION );
175
176     Integration::Point point;
177     point.SetDeviceId( touchEvent.multi.device );
178     point.SetState( state );
179     point.SetScreenPosition( Vector2( touchEvent.x, touchEvent.y + WindowsPlatformImplementation::GetEdgeHeight() ) );
180     point.SetRadius( touchEvent.multi.radius, Vector2( touchEvent.multi.radius_x, touchEvent.multi.radius_y ) );
181     point.SetPressure( touchEvent.multi.pressure );
182     point.SetAngle( Degree( touchEvent.multi.angle ) );
183
184     mTouchEventSignal.Emit( point, touchEvent.timestamp );
185   }
186 }
187
188 void WindowBaseWin::OnMouseWheel( int type, TWinEventInfo *event )
189 {
190   Event_Mouse_Wheel mouseWheelEvent = *((Event_Mouse_Wheel*)( event ));
191
192   if( mouseWheelEvent.window == mWin32Window )
193   {
194     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseWin::OnMouseWheel: direction: %d, modifiers: %d, x: %d, y: %d, z: %d\n", mouseWheelEvent.direction, mouseWheelEvent.modifiers, mouseWheelEvent.x, mouseWheelEvent.y, mouseWheelEvent.z );
195
196     WheelEvent wheelEvent( WheelEvent::MOUSE_WHEEL, mouseWheelEvent.direction, mouseWheelEvent.modifiers, Vector2( mouseWheelEvent.x, mouseWheelEvent.y ), mouseWheelEvent.z, mouseWheelEvent.timestamp );
197
198     mWheelEventSignal.Emit( wheelEvent );
199   }
200 }
201
202 void WindowBaseWin::OnKeyDown( int type, TWinEventInfo *event )
203 {
204   if( event->mWindow == mWin32Window )
205   {
206     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseWin::OnKeyDown\n" );
207
208     int keyCode = event->wParam;
209     std::string keyName( WindowsPlatformImplementation::GetKeyName( keyCode ) );
210     std::string keyString;
211     std::string emptyString;
212
213     int modifier( 0 );
214     unsigned long time( 0 );
215
216     // Ensure key event string is not NULL as keys like SHIFT have a null string.
217     keyString.push_back( event->wParam );
218
219     Integration::KeyEvent keyEvent( keyName, emptyString, keyString, keyCode, modifier, time, Integration::KeyEvent::Down, emptyString, emptyString, DEFAULT_DEVICE_CLASS, DEFAULT_DEVICE_SUBCLASS );
220
221     mKeyEventSignal.Emit( keyEvent );
222   }
223 }
224
225 void WindowBaseWin::OnKeyUp( int type, TWinEventInfo *event )
226 {
227   if( event->mWindow == mWin32Window )
228   {
229     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseWin::OnKeyDown\n" );
230
231     int keyCode = event->wParam;
232     std::string keyName( WindowsPlatformImplementation::GetKeyName( keyCode ) );
233     std::string keyString;
234     std::string emptyString;
235
236     int modifier( 0 );
237     unsigned long time( 0 );
238
239     // Ensure key event string is not NULL as keys like SHIFT have a null string.
240     keyString.push_back( event->wParam );
241
242     Integration::KeyEvent keyEvent( keyName, emptyString, keyString, keyCode, modifier, time, Integration::KeyEvent::Down, emptyString, emptyString, DEFAULT_DEVICE_CLASS, DEFAULT_DEVICE_SUBCLASS );
243
244     mKeyEventSignal.Emit( keyEvent );
245   }
246 }
247
248 Any WindowBaseWin::GetNativeWindow()
249 {
250   return mWin32Window;
251 }
252
253 int WindowBaseWin::GetNativeWindowId()
254 {
255   return mWin32Window;
256 }
257
258 EGLNativeWindowType WindowBaseWin::CreateEglWindow( int width, int height )
259 {
260   return reinterpret_cast< EGLNativeWindowType >( mWin32Window );
261 }
262
263 void WindowBaseWin::DestroyEglWindow()
264 {
265 }
266
267 void WindowBaseWin::SetEglWindowRotation( int angle )
268 {
269 }
270
271 void WindowBaseWin::SetEglWindowBufferTransform( int angle )
272 {
273 }
274
275 void WindowBaseWin::SetEglWindowTransform( int angle )
276 {
277 }
278
279 void WindowBaseWin::ResizeEglWindow( PositionSize positionSize )
280 {
281 }
282
283 bool WindowBaseWin::IsEglWindowRotationSupported()
284 {
285   return false;
286 }
287
288 void WindowBaseWin::Move( PositionSize positionSize )
289 {
290 }
291
292 void WindowBaseWin::Resize( PositionSize positionSize )
293 {
294 }
295
296 void WindowBaseWin::MoveResize( PositionSize positionSize )
297 {
298 }
299
300 void WindowBaseWin::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode, Dali::Window::IndicatorBgOpacity opacityMode )
301 {
302 }
303
304 void WindowBaseWin::SetIndicatorProperties( bool isShow, Dali::Window::WindowOrientation lastOrientation )
305 {
306 }
307
308 void WindowBaseWin::IndicatorTypeChanged( IndicatorInterface::Type type )
309 {
310 }
311
312 void WindowBaseWin::SetClass( const std::string& name, const std::string& className )
313 {
314 }
315
316 void WindowBaseWin::Raise()
317 {
318 }
319
320 void WindowBaseWin::Lower()
321 {
322 }
323
324 void WindowBaseWin::Activate()
325 {
326 }
327
328 void WindowBaseWin::SetAvailableOrientations( const std::vector< Dali::Window::WindowOrientation >& orientations )
329 {
330 }
331
332 void WindowBaseWin::SetPreferredOrientation( Dali::Window::WindowOrientation orientation )
333 {
334 }
335
336 void WindowBaseWin::SetAcceptFocus( bool accept )
337 {
338 }
339
340 void WindowBaseWin::Show()
341 {
342 }
343
344 void WindowBaseWin::Hide()
345 {
346 }
347
348 unsigned int WindowBaseWin::GetSupportedAuxiliaryHintCount() const
349 {
350   return 0;
351 }
352
353 std::string WindowBaseWin::GetSupportedAuxiliaryHint( unsigned int index ) const
354 {
355   return std::string();
356 }
357
358 unsigned int WindowBaseWin::AddAuxiliaryHint( const std::string& hint, const std::string& value )
359 {
360   return 0;
361 }
362
363 bool WindowBaseWin::RemoveAuxiliaryHint( unsigned int id )
364 {
365   return false;
366 }
367
368 bool WindowBaseWin::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
369 {
370   return false;
371 }
372
373 std::string WindowBaseWin::GetAuxiliaryHintValue( unsigned int id ) const
374 {
375   return std::string();
376 }
377
378 unsigned int WindowBaseWin::GetAuxiliaryHintId( const std::string& hint ) const
379 {
380   return 0;
381 }
382
383 void WindowBaseWin::SetInputRegion( const Rect< int >& inputRegion )
384 {
385 }
386
387 void WindowBaseWin::SetType( Dali::Window::Type type )
388 {
389 }
390
391 bool WindowBaseWin::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
392 {
393   return false;
394 }
395
396 Dali::Window::NotificationLevel::Type WindowBaseWin::GetNotificationLevel() const
397 {
398   return Dali::Window::NotificationLevel::NONE;
399 }
400
401 void WindowBaseWin::SetOpaqueState( bool opaque )
402 {
403 }
404
405 bool WindowBaseWin::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
406 {
407   return false;
408 }
409
410 Dali::Window::ScreenOffMode::Type WindowBaseWin::GetScreenOffMode() const
411 {
412   return Dali::Window::ScreenOffMode::TIMEOUT;
413 }
414
415 bool WindowBaseWin::SetBrightness( int brightness )
416 {
417   return false;
418 }
419
420 int WindowBaseWin::GetBrightness() const
421 {
422   return 0;
423 }
424
425 bool WindowBaseWin::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
426 {
427   return false;
428 }
429
430 bool WindowBaseWin::UngrabKey( Dali::KEY key )
431 {
432   return false;
433 }
434
435 bool WindowBaseWin::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
436 {
437   return false;
438 }
439
440 bool WindowBaseWin::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
441 {
442   return false;
443 }
444
445 void WindowBaseWin::GetDpi( unsigned int& dpiHorizontal, unsigned int& dpiVertical )
446 {
447   // calculate DPI
448   float xres, yres;
449
450   //// 1 inch = 25.4 millimeters
451   WindowsPlatformImplementation::GetDPI( mWin32Window, xres, yres );
452
453   xres *= 1.5f;
454   yres *= 1.5f;
455
456   dpiHorizontal = static_cast<int>( xres + 0.5f );  // rounding
457   dpiVertical = static_cast<int>( yres + 0.5f );
458 }
459
460 int WindowBaseWin::GetScreenRotationAngle()
461 {
462   return 0;
463 }
464
465 void WindowBaseWin::SetWindowRotationAngle( int degree )
466 {
467 }
468
469 void WindowBaseWin::WindowRotationCompleted( int degree, int width, int height )
470 {
471 }
472
473 void WindowBaseWin::SetTransparency( bool transparent )
474 {
475 }
476
477 unsigned int WindowBaseWin::GetSurfaceId( Any surface ) const
478 {
479   unsigned int surfaceId = 0;
480
481   if ( surface.Empty() == false )
482   {
483     // check we have a valid type
484     DALI_ASSERT_ALWAYS( (surface.GetType() == typeid ( WinWindowHandle ) )
485                         && "Surface type is invalid" );
486
487     surfaceId = AnyCast< WinWindowHandle >( surface );
488   }
489   return surfaceId;
490 }
491
492 void WindowBaseWin::CreateWinWindow( PositionSize positionSize, bool isTransparent )
493 {
494   long hWnd = WindowsPlatformImplementation::CreateHwnd( "Demo", "Demo", positionSize.x, positionSize.y, positionSize.width, positionSize.height, NULL );\r
495 \r
496   WindowsPlatformImplementation::ShowWindow( hWnd );\r
497 \r
498   mWin32Window = (WinWindowHandle)hWnd;\r
499   DALI_ASSERT_ALWAYS( mWin32Window != 0 && "There is no Windows window" );
500 }
501
502 void WindowBaseWin::EventEntry( TWinEventInfo *event )
503 {
504   unsigned int uMsg = event->uMsg;
505
506   switch( uMsg )\r
507   {\r
508   case WM_SETFOCUS:\r
509   {\r
510     OnFocusIn( uMsg, event );\r
511     break;\r
512   }\r
513 \r
514   case WM_KILLFOCUS:\r
515   {\r
516     OnFocusOut( uMsg, event );\r
517     break;\r
518   }\r
519 \r
520   case WM_PAINT:\r
521   {\r
522     OnWindowDamaged( uMsg, event );\r
523     break;\r
524   }\r
525 \r
526   case WM_LBUTTONDOWN:\r
527   {\r
528     OnMouseButtonDown( uMsg, event );\r
529     break;\r
530   }\r
531 \r
532   case WM_LBUTTONUP:\r
533   {\r
534     OnMouseButtonUp( uMsg, event );\r
535     break;\r
536   }\r
537 \r
538   case WM_MOUSEMOVE:\r
539   {\r
540     OnMouseButtonMove( uMsg, event );\r
541     break;\r
542   }\r
543 \r
544   case WM_MOUSEWHEEL:\r
545   {\r
546     OnMouseWheel( uMsg, event );\r
547     break;\r
548   }\r
549 \r
550   case WM_KEYDOWN:\r
551   {\r
552     OnKeyDown( uMsg, event );\r
553     break;\r
554   }\r
555 \r
556   case WM_KEYUP:\r
557   {\r
558     OnKeyUp( uMsg, event );\r
559     break;\r
560   }\r
561 \r
562   default:
563     break;\r
564   }
565 }
566
567 } // namespace Adaptor
568
569 } // namespace Internal
570
571 } // namespace Dali
572