7c64458e672db9de35e80a03c1680ea40625ab52
[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   mWindowImpl.PostWinMessage( WM_CLOSE, 0, 0 );
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     SetWinWindow( surfaceId );
82   }
83
84   mWindowImpl.SetListener( MakeCallback( this, &WindowBaseWin::EventEntry ) );
85 }
86
87 void WindowBaseWin::OnDeleteRequest()
88 {
89   mDeleteRequestSignal.Emit();
90 }
91
92 void WindowBaseWin::OnFocusIn( int type, TWinEventInfo *event )
93 {
94 }
95
96 void WindowBaseWin::OnFocusOut( int type, TWinEventInfo *event )
97 {
98 }
99
100 void WindowBaseWin::OnWindowDamaged( int type, TWinEventInfo *event )
101 {
102   Event_Mouse_Button* windowDamagedEvent( (Event_Mouse_Button*)event );
103
104   if( windowDamagedEvent->window == mWin32Window )
105   {
106     DamageArea area;
107     area.x = 0;
108     area.y = 0;
109     WindowSystem::GetScreenSize( area.width, area.height );
110
111     mWindowDamagedSignal.Emit( area );
112   }
113 }
114
115 void WindowBaseWin::OnMouseButtonDown( int type, TWinEventInfo *event )
116 {
117   Event_Mouse_Button touchEvent = *((Event_Mouse_Button*)event);
118   touchEvent.timestamp = GetTickCount();
119   touchEvent.x = LOWORD( event->lParam );
120   touchEvent.y = HIWORD( event->lParam );
121   touchEvent.multi.device = DEVICE_MOUSE;
122
123   if( touchEvent.window == mWin32Window )
124   {
125     PointState::Type state ( PointState::DOWN );
126
127     Integration::Point point;
128     point.SetDeviceId( touchEvent.multi.device );
129     point.SetState( state );
130     point.SetScreenPosition( Vector2( touchEvent.x, touchEvent.y + mWindowImpl.GetEdgeHeight() ) );
131     point.SetRadius( touchEvent.multi.radius, Vector2( touchEvent.multi.radius_x, touchEvent.multi.radius_y ) );
132     point.SetPressure( touchEvent.multi.pressure );
133     point.SetAngle( Degree( touchEvent.multi.angle ) );
134
135     mTouchEventSignal.Emit( point, touchEvent.timestamp );
136   }
137 }
138
139 void WindowBaseWin::OnMouseButtonUp( int type, TWinEventInfo *event )
140 {
141   Event_Mouse_Button touchEvent = *( (Event_Mouse_Button*)event );
142   touchEvent.timestamp = GetTickCount();
143   touchEvent.x = LOWORD( event->lParam );
144   touchEvent.y = HIWORD( event->lParam );
145   touchEvent.multi.device = DEVICE_MOUSE;
146
147   if( touchEvent.window == mWin32Window )
148   {
149     PointState::Type state( PointState::UP );
150
151     Integration::Point point;
152     point.SetDeviceId( touchEvent.multi.device );
153     point.SetState( state );
154     point.SetScreenPosition( Vector2( touchEvent.x, touchEvent.y + mWindowImpl.GetEdgeHeight() ) );
155     point.SetRadius( touchEvent.multi.radius, Vector2( touchEvent.multi.radius_x, touchEvent.multi.radius_y ) );
156     point.SetPressure( touchEvent.multi.pressure );
157     point.SetAngle( Degree( touchEvent.multi.angle ) );
158
159     mTouchEventSignal.Emit( point, touchEvent.timestamp );
160   }
161 }
162
163 void WindowBaseWin::OnMouseButtonMove( int type, TWinEventInfo *event )
164 {
165   Event_Mouse_Button touchEvent = *((Event_Mouse_Button*)event);
166   touchEvent.timestamp = GetTickCount();
167   touchEvent.x = LOWORD( event->lParam );
168   touchEvent.y = HIWORD( event->lParam );
169   touchEvent.multi.device = DEVICE_MOUSE;
170
171   if( touchEvent.window == mWin32Window )
172   {
173     PointState::Type state( PointState::MOTION );
174
175     Integration::Point point;
176     point.SetDeviceId( touchEvent.multi.device );
177     point.SetState( state );
178     point.SetScreenPosition( Vector2( touchEvent.x, touchEvent.y + mWindowImpl.GetEdgeHeight() ) );
179     point.SetRadius( touchEvent.multi.radius, Vector2( touchEvent.multi.radius_x, touchEvent.multi.radius_y ) );
180     point.SetPressure( touchEvent.multi.pressure );
181     point.SetAngle( Degree( touchEvent.multi.angle ) );
182
183     mTouchEventSignal.Emit( point, touchEvent.timestamp );
184   }
185 }
186
187 void WindowBaseWin::OnMouseWheel( int type, TWinEventInfo *event )
188 {
189   Event_Mouse_Wheel mouseWheelEvent = *((Event_Mouse_Wheel*)( event ));
190
191   if( mouseWheelEvent.window == mWin32Window )
192   {
193     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 );
194
195     WheelEvent wheelEvent( WheelEvent::MOUSE_WHEEL, mouseWheelEvent.direction, mouseWheelEvent.modifiers, Vector2( mouseWheelEvent.x, mouseWheelEvent.y ), mouseWheelEvent.z, mouseWheelEvent.timestamp );
196
197     mWheelEventSignal.Emit( wheelEvent );
198   }
199 }
200
201 void WindowBaseWin::OnKeyDown( int type, TWinEventInfo *event )
202 {
203   if( event->mWindow == mWin32Window )
204   {
205     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseWin::OnKeyDown\n" );
206
207     int keyCode = event->wParam;
208     std::string keyName( WindowsPlatformImplementation::GetKeyName( keyCode ) );
209     std::string keyString;
210     std::string emptyString;
211
212     int modifier( 0 );
213     unsigned long time( 0 );
214
215     // Ensure key event string is not NULL as keys like SHIFT have a null string.
216     keyString.push_back( event->wParam );
217
218     Integration::KeyEvent keyEvent( keyName, emptyString, keyString, keyCode, modifier, time, Integration::KeyEvent::Down, emptyString, emptyString, DEFAULT_DEVICE_CLASS, DEFAULT_DEVICE_SUBCLASS );
219
220     mKeyEventSignal.Emit( keyEvent );
221   }
222 }
223
224 void WindowBaseWin::OnKeyUp( int type, TWinEventInfo *event )
225 {
226   if( event->mWindow == mWin32Window )
227   {
228     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseWin::OnKeyDown\n" );
229
230     int keyCode = event->wParam;
231     std::string keyName( WindowsPlatformImplementation::GetKeyName( keyCode ) );
232     std::string keyString;
233     std::string emptyString;
234
235     int modifier( 0 );
236     unsigned long time( 0 );
237
238     // Ensure key event string is not NULL as keys like SHIFT have a null string.
239     keyString.push_back( event->wParam );
240
241     Integration::KeyEvent keyEvent( keyName, emptyString, keyString, keyCode, modifier, time, Integration::KeyEvent::Up, emptyString, emptyString, DEFAULT_DEVICE_CLASS, DEFAULT_DEVICE_SUBCLASS );
242
243     mKeyEventSignal.Emit( keyEvent );
244   }
245 }
246
247 Any WindowBaseWin::GetNativeWindow()
248 {
249   return mWin32Window;
250 }
251
252 int WindowBaseWin::GetNativeWindowId()
253 {
254   return mWin32Window;
255 }
256
257 EGLNativeWindowType WindowBaseWin::CreateEglWindow( int width, int height )
258 {
259   return reinterpret_cast< EGLNativeWindowType >( mWin32Window );
260 }
261
262 void WindowBaseWin::DestroyEglWindow()
263 {
264 }
265
266 void WindowBaseWin::SetEglWindowRotation( int angle )
267 {
268 }
269
270 void WindowBaseWin::SetEglWindowBufferTransform( int angle )
271 {
272 }
273
274 void WindowBaseWin::SetEglWindowTransform( int angle )
275 {
276 }
277
278 void WindowBaseWin::ResizeEglWindow( PositionSize positionSize )
279 {
280 }
281
282 bool WindowBaseWin::IsEglWindowRotationSupported()
283 {
284   return false;
285 }
286
287 void WindowBaseWin::Move( PositionSize positionSize )
288 {
289 }
290
291 void WindowBaseWin::Resize( PositionSize positionSize )
292 {
293   ::SetWindowPos( (HWND)mWin32Window, NULL, positionSize.x, positionSize.y, positionSize.width, positionSize.height, SWP_SHOWWINDOW );
294 }
295
296 void WindowBaseWin::MoveResize( PositionSize positionSize )
297 {
298 }
299
300 void WindowBaseWin::SetClass( const std::string& name, const std::string& className )
301 {
302 }
303
304 void WindowBaseWin::Raise()
305 {
306 }
307
308 void WindowBaseWin::Lower()
309 {
310 }
311
312 void WindowBaseWin::Activate()
313 {
314 }
315
316 void WindowBaseWin::SetAvailableAnlges( const std::vector< int >& angles )
317 {
318 }
319
320 void WindowBaseWin::SetPreferredAngle( int angle )
321 {
322 }
323
324 void WindowBaseWin::SetAcceptFocus( bool accept )
325 {
326 }
327
328 void WindowBaseWin::Show()
329 {
330 }
331
332 void WindowBaseWin::Hide()
333 {
334 }
335
336 unsigned int WindowBaseWin::GetSupportedAuxiliaryHintCount() const
337 {
338   return 0;
339 }
340
341 std::string WindowBaseWin::GetSupportedAuxiliaryHint( unsigned int index ) const
342 {
343   return std::string();
344 }
345
346 unsigned int WindowBaseWin::AddAuxiliaryHint( const std::string& hint, const std::string& value )
347 {
348   return 0;
349 }
350
351 bool WindowBaseWin::RemoveAuxiliaryHint( unsigned int id )
352 {
353   return false;
354 }
355
356 bool WindowBaseWin::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
357 {
358   return false;
359 }
360
361 std::string WindowBaseWin::GetAuxiliaryHintValue( unsigned int id ) const
362 {
363   return std::string();
364 }
365
366 unsigned int WindowBaseWin::GetAuxiliaryHintId( const std::string& hint ) const
367 {
368   return 0;
369 }
370
371 void WindowBaseWin::SetInputRegion( const Rect< int >& inputRegion )
372 {
373 }
374
375 void WindowBaseWin::SetType( Dali::Window::Type type )
376 {
377 }
378
379 bool WindowBaseWin::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
380 {
381   return false;
382 }
383
384 Dali::Window::NotificationLevel::Type WindowBaseWin::GetNotificationLevel() const
385 {
386   return Dali::Window::NotificationLevel::NONE;
387 }
388
389 void WindowBaseWin::SetOpaqueState( bool opaque )
390 {
391 }
392
393 bool WindowBaseWin::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
394 {
395   return false;
396 }
397
398 Dali::Window::ScreenOffMode::Type WindowBaseWin::GetScreenOffMode() const
399 {
400   return Dali::Window::ScreenOffMode::TIMEOUT;
401 }
402
403 bool WindowBaseWin::SetBrightness( int brightness )
404 {
405   return false;
406 }
407
408 int WindowBaseWin::GetBrightness() const
409 {
410   return 0;
411 }
412
413 bool WindowBaseWin::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
414 {
415   return false;
416 }
417
418 bool WindowBaseWin::UngrabKey( Dali::KEY key )
419 {
420   return false;
421 }
422
423 bool WindowBaseWin::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
424 {
425   return false;
426 }
427
428 bool WindowBaseWin::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
429 {
430   return false;
431 }
432
433 void WindowBaseWin::GetDpi( unsigned int& dpiHorizontal, unsigned int& dpiVertical )
434 {
435   // calculate DPI
436   float xres, yres;
437
438   //// 1 inch = 25.4 millimeters
439   mWindowImpl.GetDPI( xres, yres );
440
441   xres *= 1.5f;
442   yres *= 1.5f;
443
444   dpiHorizontal = static_cast<int>( xres + 0.5f );  // rounding
445   dpiVertical = static_cast<int>( yres + 0.5f );
446 }
447
448 int WindowBaseWin::GetScreenRotationAngle()
449 {
450   return 0;
451 }
452
453 void WindowBaseWin::SetWindowRotationAngle( int degree )
454 {
455 }
456
457 int WindowBaseWin::GetWindowRotationAngle()
458 {
459 }
460
461 void WindowBaseWin::WindowRotationCompleted( int degree, int width, int height )
462 {
463 }
464
465 void WindowBaseWin::SetTransparency( bool transparent )
466 {
467 }
468
469 int WindowBaseWin::GetOrientation() const
470 {
471 }
472
473 unsigned int WindowBaseWin::GetSurfaceId( Any surface ) const
474 {
475   unsigned int surfaceId = 0;
476
477   if ( surface.Empty() == false )
478   {
479     // check we have a valid type
480     DALI_ASSERT_ALWAYS( (surface.GetType() == typeid ( WinWindowHandle ) )
481                         && "Surface type is invalid" );
482
483     surfaceId = AnyCast< WinWindowHandle >( surface );
484   }
485   return surfaceId;
486 }
487
488 void WindowBaseWin::CreateWinWindow( PositionSize positionSize, bool isTransparent )
489 {
490   long hWnd = mWindowImpl.CreateHwnd( "Demo", "Demo", positionSize.x, positionSize.y, positionSize.width, positionSize.height, NULL );
491
492   mWin32Window = static_cast<WinWindowHandle>(hWnd);
493
494   DALI_ASSERT_ALWAYS( mWin32Window != 0 && "There is no Windows window" );
495 }
496
497 void WindowBaseWin::SetWinWindow( unsigned int surfaceId )
498 {
499   HWND hWnd = (HWND)surfaceId;
500
501   mWin32Window = static_cast<WinWindowHandle>(surfaceId);
502
503   mWindowImpl.SetHWND( reinterpret_cast<uint64_t>(hWnd));
504
505   mWindowImpl.SetWinProc();
506 }
507
508 void WindowBaseWin::EventEntry( TWinEventInfo *event )
509 {
510   unsigned int uMsg = event->uMsg;
511
512   switch( uMsg )
513   {
514   case WM_SETFOCUS:
515   {
516     OnFocusIn( uMsg, event );
517     break;
518   }
519
520   case WM_KILLFOCUS:
521   {
522     OnFocusOut( uMsg, event );
523     break;
524   }
525
526   case WM_PAINT:
527   {
528     OnWindowDamaged( uMsg, event );
529     break;
530   }
531
532   case WM_LBUTTONDOWN:
533   {
534     OnMouseButtonDown( uMsg, event );
535     break;
536   }
537
538   case WM_LBUTTONUP:
539   {
540     OnMouseButtonUp( uMsg, event );
541     break;
542   }
543
544   case WM_MOUSEMOVE:
545   {
546     OnMouseButtonMove( uMsg, event );
547     break;
548   }
549
550   case WM_MOUSEWHEEL:
551   {
552     OnMouseWheel( uMsg, event );
553     break;
554   }
555
556   case WM_KEYDOWN:
557   {
558     OnKeyDown( uMsg, event );
559     break;
560   }
561
562   case WM_KEYUP:
563   {
564     OnKeyUp( uMsg, event );
565     break;
566   }
567
568   default:
569     break;
570   }
571 }
572
573 void WindowBaseWin::SetParent( WindowBase* parentWinBase )
574 {
575
576 }
577
578 } // namespace Adaptor
579
580 } // namespace Internal
581
582 } // namespace Dali
583