[dali_2.3.20] Merge branch 'devel/master'
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / windows / window-base-win.cpp
1 /*
2  * Copyright (c) 2023 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/integration-api/debug.h>
23 #include <dali/public-api/object/any.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 namespace Internal
33 {
34 namespace Adaptor
35 {
36 namespace
37 {
38 const Device::Class::Type    DEFAULT_DEVICE_CLASS    = Device::Class::NONE;
39 const Device::Subclass::Type DEFAULT_DEVICE_SUBCLASS = Device::Subclass::NONE;
40
41 const unsigned int PRIMARY_TOUCH_BUTTON_ID(1);
42
43 #if defined(DEBUG_ENABLED)
44 Debug::Filter* gWindowBaseLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_WINDOW_BASE");
45 #endif
46
47 } // unnamed namespace
48
49 WindowBaseWin::WindowBaseWin(Dali::PositionSize positionSize, Any surface, bool isTransparent)
50 : mWin32Window(0),
51   mOwnSurface(false),
52   mIsTransparent(false), // Should only be set to true once we actually create a transparent window regardless of what isTransparent is.
53   mRotationAppSet(false)
54 {
55   Initialize(positionSize, surface, isTransparent);
56 }
57
58 WindowBaseWin::~WindowBaseWin()
59 {
60   mWindowImpl.PostWinMessage(WM_CLOSE, 0, 0);
61 }
62
63 void WindowBaseWin::Initialize(PositionSize positionSize, Any surface, bool isTransparent)
64 {
65   // see if there is a surface in Any surface
66   uintptr_t surfaceId = GetSurfaceId(surface);
67
68   // if the surface is empty, create a new one.
69   if(surfaceId == 0)
70   {
71     // we own the surface about to created
72     mOwnSurface = true;
73     CreateWinWindow(positionSize, isTransparent);
74   }
75   else
76   {
77     SetWinWindow(surfaceId);
78   }
79
80   mWindowImpl.SetListener(MakeCallback(this, &WindowBaseWin::EventEntry));
81 }
82
83 void WindowBaseWin::OnDeleteRequest()
84 {
85   mDeleteRequestSignal.Emit();
86 }
87
88 void WindowBaseWin::OnFocusIn(int type, TWinEventInfo* event)
89 {
90 }
91
92 void WindowBaseWin::OnFocusOut(int type, TWinEventInfo* event)
93 {
94 }
95
96 void WindowBaseWin::OnWindowDamaged(int type, TWinEventInfo* event)
97 {
98   Event_Mouse_Button* windowDamagedEvent((Event_Mouse_Button*)event);
99
100   if(windowDamagedEvent->window == mWin32Window)
101   {
102     DamageArea area;
103     area.x = 0;
104     area.y = 0;
105     WindowSystem::GetScreenSize(area.width, area.height);
106
107     mWindowDamagedSignal.Emit(area);
108   }
109 }
110
111 void WindowBaseWin::OnMouseButtonDown(int type, TWinEventInfo* event)
112 {
113   Event_Mouse_Button touchEvent = *((Event_Mouse_Button*)event);
114   touchEvent.timestamp          = GetTickCount();
115   touchEvent.x                  = LOWORD(event->lParam);
116   touchEvent.y                  = HIWORD(event->lParam);
117   touchEvent.multi.device       = DEVICE_MOUSE;
118
119   if(touchEvent.window == mWin32Window)
120   {
121     PointState::Type state(PointState::DOWN);
122
123     Integration::Point point;
124     point.SetDeviceId(touchEvent.multi.device);
125     point.SetState(state);
126     point.SetScreenPosition(Vector2(touchEvent.x, touchEvent.y + WindowsPlatform::WindowImpl::EDGE_HEIGHT));
127     point.SetRadius(touchEvent.multi.radius, Vector2(touchEvent.multi.radius_x, touchEvent.multi.radius_y));
128     point.SetPressure(touchEvent.multi.pressure);
129     point.SetAngle(Degree(touchEvent.multi.angle));
130
131     mTouchEventSignal.Emit(point, touchEvent.timestamp);
132   }
133 }
134
135 void WindowBaseWin::OnMouseButtonUp(int type, TWinEventInfo* event)
136 {
137   Event_Mouse_Button touchEvent = *((Event_Mouse_Button*)event);
138   touchEvent.timestamp          = GetTickCount();
139   touchEvent.x                  = LOWORD(event->lParam);
140   touchEvent.y                  = HIWORD(event->lParam);
141   touchEvent.multi.device       = DEVICE_MOUSE;
142
143   if(touchEvent.window == mWin32Window)
144   {
145     PointState::Type state(PointState::UP);
146
147     Integration::Point point;
148     point.SetDeviceId(touchEvent.multi.device);
149     point.SetState(state);
150     point.SetScreenPosition(Vector2(touchEvent.x, touchEvent.y + WindowsPlatform::WindowImpl::EDGE_HEIGHT));
151     point.SetRadius(touchEvent.multi.radius, Vector2(touchEvent.multi.radius_x, touchEvent.multi.radius_y));
152     point.SetPressure(touchEvent.multi.pressure);
153     point.SetAngle(Degree(touchEvent.multi.angle));
154
155     mTouchEventSignal.Emit(point, touchEvent.timestamp);
156   }
157 }
158
159 void WindowBaseWin::OnMouseButtonMove(int type, TWinEventInfo* event)
160 {
161   Event_Mouse_Button touchEvent = *((Event_Mouse_Button*)event);
162   touchEvent.timestamp          = GetTickCount();
163   touchEvent.x                  = LOWORD(event->lParam);
164   touchEvent.y                  = HIWORD(event->lParam);
165   touchEvent.multi.device       = DEVICE_MOUSE;
166
167   if(touchEvent.window == mWin32Window)
168   {
169     PointState::Type state(PointState::MOTION);
170
171     Integration::Point point;
172     point.SetDeviceId(touchEvent.multi.device);
173     point.SetState(state);
174     point.SetScreenPosition(Vector2(touchEvent.x, touchEvent.y + WindowsPlatform::WindowImpl::EDGE_HEIGHT));
175     point.SetRadius(touchEvent.multi.radius, Vector2(touchEvent.multi.radius_x, touchEvent.multi.radius_y));
176     point.SetPressure(touchEvent.multi.pressure);
177     point.SetAngle(Degree(touchEvent.multi.angle));
178
179     mTouchEventSignal.Emit(point, touchEvent.timestamp);
180   }
181 }
182
183 void WindowBaseWin::OnMouseWheel(int type, TWinEventInfo* event)
184 {
185   Event_Mouse_Wheel mouseWheelEvent = *((Event_Mouse_Wheel*)(event));
186
187   if(mouseWheelEvent.window == mWin32Window)
188   {
189     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);
190
191     Integration::WheelEvent wheelEvent(Integration::WheelEvent::MOUSE_WHEEL, mouseWheelEvent.direction, mouseWheelEvent.modifiers, Vector2(mouseWheelEvent.x, mouseWheelEvent.y), mouseWheelEvent.z, mouseWheelEvent.timestamp);
192
193     mWheelEventSignal.Emit(wheelEvent);
194   }
195 }
196
197 void WindowBaseWin::OnKeyDown(int type, TWinEventInfo* event)
198 {
199   if(event->mWindow == mWin32Window)
200   {
201     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseWin::OnKeyDown\n");
202
203     int         keyCode = event->wParam;
204     std::string keyName(WindowsPlatform::GetKeyName(keyCode));
205     std::string keyString;
206     std::string emptyString;
207
208     int           modifier(0);
209     unsigned long time(0);
210
211     // Ensure key event string is not NULL as keys like SHIFT have a null string.
212     keyString.push_back(event->wParam);
213
214     Integration::KeyEvent keyEvent(keyName, emptyString, keyString, keyCode, modifier, time, Integration::KeyEvent::DOWN, emptyString, emptyString, DEFAULT_DEVICE_CLASS, DEFAULT_DEVICE_SUBCLASS);
215     keyEvent.windowId = GetNativeWindowId();
216
217     mKeyEventSignal.Emit(keyEvent);
218   }
219 }
220
221 void WindowBaseWin::OnKeyUp(int type, TWinEventInfo* event)
222 {
223   if(event->mWindow == mWin32Window)
224   {
225     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseWin::OnKeyDown\n");
226
227     int         keyCode = event->wParam;
228     std::string keyName(WindowsPlatform::GetKeyName(keyCode));
229     std::string keyString;
230     std::string emptyString;
231
232     int           modifier(0);
233     unsigned long time(0);
234
235     // Ensure key event string is not NULL as keys like SHIFT have a null string.
236     keyString.push_back(event->wParam);
237
238     Integration::KeyEvent keyEvent(keyName, emptyString, keyString, keyCode, modifier, time, Integration::KeyEvent::UP, emptyString, emptyString, DEFAULT_DEVICE_CLASS, DEFAULT_DEVICE_SUBCLASS);
239     keyEvent.windowId = GetNativeWindowId();
240
241     mKeyEventSignal.Emit(keyEvent);
242   }
243 }
244
245 Any WindowBaseWin::GetNativeWindow()
246 {
247   return mWin32Window;
248 }
249
250 int WindowBaseWin::GetNativeWindowId()
251 {
252   return mWin32Window;
253 }
254
255 std::string WindowBaseWin::GetNativeWindowResourceId()
256 {
257   return std::string();
258 }
259
260 EGLNativeWindowType WindowBaseWin::CreateEglWindow(int width, int height)
261 {
262   return reinterpret_cast<EGLNativeWindowType>(mWin32Window);
263 }
264
265 void WindowBaseWin::DestroyEglWindow()
266 {
267 }
268
269 void WindowBaseWin::SetEglWindowRotation(int angle)
270 {
271 }
272
273 void WindowBaseWin::SetEglWindowBufferTransform(int angle)
274 {
275 }
276
277 void WindowBaseWin::SetEglWindowTransform(int angle)
278 {
279 }
280
281 void WindowBaseWin::ResizeEglWindow(PositionSize positionSize)
282 {
283 }
284
285 bool WindowBaseWin::IsEglWindowRotationSupported()
286 {
287   return false;
288 }
289
290 void WindowBaseWin::Move(PositionSize positionSize)
291 {
292 }
293
294 void WindowBaseWin::Resize(PositionSize positionSize)
295 {
296   ::SetWindowPos((HWND)mWin32Window, NULL, positionSize.x, positionSize.y, positionSize.width, positionSize.height, SWP_SHOWWINDOW);
297 }
298
299 void WindowBaseWin::MoveResize(PositionSize positionSize)
300 {
301 }
302
303 void WindowBaseWin::SetLayout(unsigned int numCols, unsigned int numRows, unsigned int column, unsigned int row, unsigned int colSpan, unsigned int rowSpan)
304 {
305 }
306
307 void WindowBaseWin::SetClass(const std::string& name, const std::string& className)
308 {
309 }
310
311 void WindowBaseWin::Raise()
312 {
313 }
314
315 void WindowBaseWin::Lower()
316 {
317 }
318
319 void WindowBaseWin::Activate()
320 {
321 }
322
323 void WindowBaseWin::Maximize(bool maximize)
324 {
325 }
326
327 bool WindowBaseWin::IsMaximized() const
328 {
329   return false;
330 }
331
332 void WindowBaseWin::SetMaximumSize(Dali::Window::WindowSize size)
333 {
334 }
335
336 void WindowBaseWin::Minimize(bool minimize)
337 {
338 }
339
340 bool WindowBaseWin::IsMinimized() const
341 {
342   return false;
343 }
344
345 void WindowBaseWin::SetMimimumSize(Dali::Window::WindowSize size)
346 {
347 }
348
349 void WindowBaseWin::SetAvailableAnlges(const std::vector<int>& angles)
350 {
351 }
352
353 void WindowBaseWin::SetPreferredAngle(int angle)
354 {
355 }
356
357 void WindowBaseWin::SetAcceptFocus(bool accept)
358 {
359 }
360
361 void WindowBaseWin::Show()
362 {
363 }
364
365 void WindowBaseWin::Hide()
366 {
367 }
368
369 unsigned int WindowBaseWin::GetSupportedAuxiliaryHintCount() const
370 {
371   return 0;
372 }
373
374 std::string WindowBaseWin::GetSupportedAuxiliaryHint(unsigned int index) const
375 {
376   return std::string();
377 }
378
379 unsigned int WindowBaseWin::AddAuxiliaryHint(const std::string& hint, const std::string& value)
380 {
381   return 0;
382 }
383
384 bool WindowBaseWin::RemoveAuxiliaryHint(unsigned int id)
385 {
386   return false;
387 }
388
389 bool WindowBaseWin::SetAuxiliaryHintValue(unsigned int id, const std::string& value)
390 {
391   return false;
392 }
393
394 std::string WindowBaseWin::GetAuxiliaryHintValue(unsigned int id) const
395 {
396   return std::string();
397 }
398
399 unsigned int WindowBaseWin::GetAuxiliaryHintId(const std::string& hint) const
400 {
401   return 0;
402 }
403
404 void WindowBaseWin::SetInputRegion(const Rect<int>& inputRegion)
405 {
406 }
407
408 void WindowBaseWin::SetType(Dali::WindowType type)
409 {
410 }
411
412 Dali::WindowType WindowBaseWin::GetType() const
413 {
414   return Dali::WindowType::NORMAL;
415 }
416
417 Dali::WindowOperationResult WindowBaseWin::SetNotificationLevel(Dali::WindowNotificationLevel level)
418 {
419   return Dali::WindowOperationResult::NOT_SUPPORTED;
420 }
421
422 Dali::WindowNotificationLevel WindowBaseWin::GetNotificationLevel() const
423 {
424   return Dali::WindowNotificationLevel::NONE;
425 }
426
427 void WindowBaseWin::SetOpaqueState(bool opaque)
428 {
429 }
430
431 Dali::WindowOperationResult WindowBaseWin::SetScreenOffMode(WindowScreenOffMode screenOffMode)
432 {
433   return Dali::WindowOperationResult::NOT_SUPPORTED;
434 }
435
436 WindowScreenOffMode WindowBaseWin::GetScreenOffMode() const
437 {
438   return WindowScreenOffMode::TIMEOUT;
439 }
440
441 Dali::WindowOperationResult WindowBaseWin::SetBrightness(int brightness)
442 {
443   return Dali::WindowOperationResult::NOT_SUPPORTED;
444 }
445
446 int WindowBaseWin::GetBrightness() const
447 {
448   return 0;
449 }
450
451 bool WindowBaseWin::GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode)
452 {
453   return false;
454 }
455
456 bool WindowBaseWin::UngrabKey(Dali::KEY key)
457 {
458   return false;
459 }
460
461 bool WindowBaseWin::GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result)
462 {
463   return false;
464 }
465
466 bool WindowBaseWin::UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result)
467 {
468   return false;
469 }
470
471 void WindowBaseWin::GetDpi(unsigned int& dpiHorizontal, unsigned int& dpiVertical)
472 {
473   // calculate DPI
474   float xres, yres;
475
476   //// 1 inch = 25.4 millimeters
477   mWindowImpl.GetDPI(xres, yres);
478
479   xres *= 1.5f;
480   yres *= 1.5f;
481
482   dpiHorizontal = static_cast<int>(xres + 0.5f); // rounding
483   dpiVertical   = static_cast<int>(yres + 0.5f);
484 }
485
486 int WindowBaseWin::GetScreenRotationAngle()
487 {
488   return 0;
489 }
490
491 void WindowBaseWin::SetWindowRotationAngle(int degree)
492 {
493 }
494
495 void WindowBaseWin::WindowRotationCompleted(int degree, int width, int height)
496 {
497 }
498
499 void WindowBaseWin::SetTransparency(bool transparent)
500 {
501 }
502
503 int WindowBaseWin::GetWindowRotationAngle() const
504 {
505   return 0;
506 }
507
508 uintptr_t WindowBaseWin::GetSurfaceId(Any surface) const
509 {
510   uintptr_t surfaceId = 0;
511
512   if(surface.Empty() == false)
513   {
514     // check we have a valid type
515     DALI_ASSERT_ALWAYS((surface.GetType() == typeid(WinWindowHandle)) && "Surface type is invalid");
516
517     surfaceId = AnyCast<WinWindowHandle>(surface);
518   }
519   return surfaceId;
520 }
521
522 void WindowBaseWin::CreateWinWindow(PositionSize positionSize, bool isTransparent)
523 {
524   long hWnd = WindowsPlatform::WindowImpl::CreateHwnd("Demo", positionSize.x, positionSize.y, positionSize.width, positionSize.height, NULL);
525   mWindowImpl.SetHWND(hWnd);
526
527   mWin32Window = static_cast<WinWindowHandle>(hWnd);
528
529   DALI_ASSERT_ALWAYS(mWin32Window != 0 && "There is no Windows window");
530 }
531
532 void WindowBaseWin::SetWinWindow(uintptr_t surfaceId)
533 {
534   HWND hWnd = (HWND)surfaceId;
535
536   mWin32Window = static_cast<WinWindowHandle>(surfaceId);
537
538   mWindowImpl.SetHWND(surfaceId);
539
540   mWindowImpl.SetWinProc();
541 }
542
543 void WindowBaseWin::EventEntry(TWinEventInfo* event)
544 {
545   unsigned int uMsg = event->uMsg;
546
547   switch(uMsg)
548   {
549     case WM_SETFOCUS:
550     {
551       OnFocusIn(uMsg, event);
552       break;
553     }
554
555     case WM_KILLFOCUS:
556     {
557       OnFocusOut(uMsg, event);
558       break;
559     }
560
561     case WM_PAINT:
562     {
563       OnWindowDamaged(uMsg, event);
564       break;
565     }
566
567     case WM_LBUTTONDOWN:
568     {
569       OnMouseButtonDown(uMsg, event);
570       break;
571     }
572
573     case WM_LBUTTONUP:
574     {
575       OnMouseButtonUp(uMsg, event);
576       break;
577     }
578
579     case WM_MOUSEMOVE:
580     {
581       OnMouseButtonMove(uMsg, event);
582       break;
583     }
584
585     case WM_MOUSEWHEEL:
586     {
587       OnMouseWheel(uMsg, event);
588       break;
589     }
590
591     case WM_KEYDOWN:
592     {
593       OnKeyDown(uMsg, event);
594       break;
595     }
596
597     case WM_KEYUP:
598     {
599       OnKeyUp(uMsg, event);
600       break;
601     }
602
603     default:
604       break;
605   }
606 }
607
608 void WindowBaseWin::SetParent(WindowBase* parentWinBase, bool belowParent)
609 {
610 }
611
612 int WindowBaseWin::CreateFrameRenderedSyncFence()
613 {
614   return -1;
615 }
616
617 int WindowBaseWin::CreateFramePresentedSyncFence()
618 {
619   return -1;
620 }
621
622 void WindowBaseWin::SetPositionSizeWithAngle(PositionSize positionSize, int angle)
623 {
624 }
625
626 void WindowBaseWin::InitializeIme()
627 {
628 }
629
630 void WindowBaseWin::ImeWindowReadyToRender()
631 {
632 }
633
634 void WindowBaseWin::RequestMoveToServer()
635 {
636 }
637
638 void WindowBaseWin::RequestResizeToServer(WindowResizeDirection direction)
639 {
640 }
641
642 void WindowBaseWin::EnableFloatingMode(bool enable)
643 {
644 }
645
646 bool WindowBaseWin::IsFloatingModeEnabled() const
647 {
648   return false;
649 }
650
651 void WindowBaseWin::IncludeInputRegion(const Rect<int>& inputRegion)
652 {
653 }
654
655 void WindowBaseWin::ExcludeInputRegion(const Rect<int>& inputRegion)
656 {
657 }
658
659 bool WindowBaseWin::PointerConstraintsLock()
660 {
661   return false;
662 }
663
664 bool WindowBaseWin::PointerConstraintsUnlock()
665 {
666   return false;
667 }
668
669 void WindowBaseWin::LockedPointerRegionSet(int32_t x, int32_t y, int32_t width, int32_t height)
670 {
671 }
672
673 void WindowBaseWin::LockedPointerCursorPositionHintSet(int32_t x, int32_t y)
674 {
675 }
676
677 bool WindowBaseWin::PointerWarp(int32_t x, int32_t y)
678 {
679   return false;
680 }
681
682 void WindowBaseWin::CursorVisibleSet(bool visible)
683 {
684 }
685
686 bool WindowBaseWin::KeyboardGrab(Device::Subclass::Type deviceSubclass)
687 {
688   return false;
689 }
690
691 bool WindowBaseWin::KeyboardUnGrab()
692 {
693   return false;
694 }
695
696 void WindowBaseWin::SetFullScreen(bool fullscreen)
697 {
698   return;
699 }
700
701 bool WindowBaseWin::GetFullScreen()
702 {
703   return false;
704 }
705
706 void WindowBaseWin::SetFrontBufferRendering(bool enable)
707 {
708 }
709
710 bool WindowBaseWin::GetFrontBufferRendering()
711 {
712   return false;
713 }
714
715 void WindowBaseWin::SetEglWindowFrontBufferMode(bool enable)
716 {
717 }
718
719 } // namespace Adaptor
720
721 } // namespace Internal
722
723 } // namespace Dali