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