[AT-SPI] Add resource id to window attribute
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / windows / window-base-win.cpp
1 /*
2  * Copyright (c) 2022 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
216     mKeyEventSignal.Emit(keyEvent);
217   }
218 }
219
220 void WindowBaseWin::OnKeyUp(int type, TWinEventInfo* event)
221 {
222   if(event->mWindow == mWin32Window)
223   {
224     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseWin::OnKeyDown\n");
225
226     int         keyCode = event->wParam;
227     std::string keyName(WindowsPlatform::GetKeyName(keyCode));
228     std::string keyString;
229     std::string emptyString;
230
231     int           modifier(0);
232     unsigned long time(0);
233
234     // Ensure key event string is not NULL as keys like SHIFT have a null string.
235     keyString.push_back(event->wParam);
236
237     Integration::KeyEvent keyEvent(keyName, emptyString, keyString, keyCode, modifier, time, Integration::KeyEvent::UP, emptyString, emptyString, DEFAULT_DEVICE_CLASS, DEFAULT_DEVICE_SUBCLASS);
238
239     mKeyEventSignal.Emit(keyEvent);
240   }
241 }
242
243 Any WindowBaseWin::GetNativeWindow()
244 {
245   return mWin32Window;
246 }
247
248 int WindowBaseWin::GetNativeWindowId()
249 {
250   return mWin32Window;
251 }
252
253 std::string WindowBaseWin::GetNativeWindowResourceId()
254 {
255   return std::string();
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   ::SetWindowPos((HWND)mWin32Window, NULL, positionSize.x, positionSize.y, positionSize.width, positionSize.height, SWP_SHOWWINDOW);
295 }
296
297 void WindowBaseWin::MoveResize(PositionSize positionSize)
298 {
299 }
300
301 void WindowBaseWin::SetClass(const std::string& name, const std::string& className)
302 {
303 }
304
305 void WindowBaseWin::Raise()
306 {
307 }
308
309 void WindowBaseWin::Lower()
310 {
311 }
312
313 void WindowBaseWin::Activate()
314 {
315 }
316
317 void WindowBaseWin::Maximize(bool maximize)
318 {
319 }
320
321 bool WindowBaseWin::IsMaximized() const
322 {
323   return false;
324 }
325
326 void WindowBaseWin::Minimize(bool minimize)
327 {
328 }
329
330 bool WindowBaseWin::IsMinimized() const
331 {
332   return false;
333 }
334
335 void WindowBaseWin::SetAvailableAnlges(const std::vector<int>& angles)
336 {
337 }
338
339 void WindowBaseWin::SetPreferredAngle(int angle)
340 {
341 }
342
343 void WindowBaseWin::SetAcceptFocus(bool accept)
344 {
345 }
346
347 void WindowBaseWin::Show()
348 {
349 }
350
351 void WindowBaseWin::Hide()
352 {
353 }
354
355 unsigned int WindowBaseWin::GetSupportedAuxiliaryHintCount() const
356 {
357   return 0;
358 }
359
360 std::string WindowBaseWin::GetSupportedAuxiliaryHint(unsigned int index) const
361 {
362   return std::string();
363 }
364
365 unsigned int WindowBaseWin::AddAuxiliaryHint(const std::string& hint, const std::string& value)
366 {
367   return 0;
368 }
369
370 bool WindowBaseWin::RemoveAuxiliaryHint(unsigned int id)
371 {
372   return false;
373 }
374
375 bool WindowBaseWin::SetAuxiliaryHintValue(unsigned int id, const std::string& value)
376 {
377   return false;
378 }
379
380 std::string WindowBaseWin::GetAuxiliaryHintValue(unsigned int id) const
381 {
382   return std::string();
383 }
384
385 unsigned int WindowBaseWin::GetAuxiliaryHintId(const std::string& hint) const
386 {
387   return 0;
388 }
389
390 void WindowBaseWin::SetInputRegion(const Rect<int>& inputRegion)
391 {
392 }
393
394 void WindowBaseWin::SetType(Dali::WindowType type)
395 {
396 }
397
398 Dali::WindowType WindowBaseWin::GetType() const
399 {
400   return Dali::WindowType::NORMAL;
401 }
402
403 Dali::WindowOperationResult WindowBaseWin::SetNotificationLevel(Dali::WindowNotificationLevel level)
404 {
405   return Dali::WindowOperationResult::NOT_SUPPORTED;
406 }
407
408 Dali::WindowNotificationLevel WindowBaseWin::GetNotificationLevel() const
409 {
410   return Dali::WindowNotificationLevel::NONE;
411 }
412
413 void WindowBaseWin::SetOpaqueState(bool opaque)
414 {
415 }
416
417 Dali::WindowOperationResult WindowBaseWin::SetScreenOffMode(WindowScreenOffMode screenOffMode)
418 {
419   return Dali::WindowOperationResult::NOT_SUPPORTED;
420 }
421
422 WindowScreenOffMode WindowBaseWin::GetScreenOffMode() const
423 {
424   return WindowScreenOffMode::TIMEOUT;
425 }
426
427 Dali::WindowOperationResult WindowBaseWin::SetBrightness(int brightness)
428 {
429   return Dali::WindowOperationResult::NOT_SUPPORTED;
430 }
431
432 int WindowBaseWin::GetBrightness() const
433 {
434   return 0;
435 }
436
437 bool WindowBaseWin::GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode)
438 {
439   return false;
440 }
441
442 bool WindowBaseWin::UngrabKey(Dali::KEY key)
443 {
444   return false;
445 }
446
447 bool WindowBaseWin::GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result)
448 {
449   return false;
450 }
451
452 bool WindowBaseWin::UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result)
453 {
454   return false;
455 }
456
457 void WindowBaseWin::GetDpi(unsigned int& dpiHorizontal, unsigned int& dpiVertical)
458 {
459   // calculate DPI
460   float xres, yres;
461
462   //// 1 inch = 25.4 millimeters
463   mWindowImpl.GetDPI(xres, yres);
464
465   xres *= 1.5f;
466   yres *= 1.5f;
467
468   dpiHorizontal = static_cast<int>(xres + 0.5f); // rounding
469   dpiVertical   = static_cast<int>(yres + 0.5f);
470 }
471
472 int WindowBaseWin::GetScreenRotationAngle()
473 {
474   return 0;
475 }
476
477 void WindowBaseWin::SetWindowRotationAngle(int degree)
478 {
479 }
480
481 void WindowBaseWin::WindowRotationCompleted(int degree, int width, int height)
482 {
483 }
484
485 void WindowBaseWin::SetTransparency(bool transparent)
486 {
487 }
488
489 int WindowBaseWin::GetOrientation() const
490 {
491   return 0;
492 }
493
494 uintptr_t WindowBaseWin::GetSurfaceId(Any surface) const
495 {
496   uintptr_t surfaceId = 0;
497
498   if(surface.Empty() == false)
499   {
500     // check we have a valid type
501     DALI_ASSERT_ALWAYS((surface.GetType() == typeid(WinWindowHandle)) && "Surface type is invalid");
502
503     surfaceId = AnyCast<WinWindowHandle>(surface);
504   }
505   return surfaceId;
506 }
507
508 void WindowBaseWin::CreateWinWindow(PositionSize positionSize, bool isTransparent)
509 {
510   long hWnd = WindowsPlatform::WindowImpl::CreateHwnd("Demo", positionSize.x, positionSize.y, positionSize.width, positionSize.height, NULL);
511   mWindowImpl.SetHWND(hWnd);
512
513   mWin32Window = static_cast<WinWindowHandle>(hWnd);
514
515   DALI_ASSERT_ALWAYS(mWin32Window != 0 && "There is no Windows window");
516 }
517
518 void WindowBaseWin::SetWinWindow(uintptr_t surfaceId)
519 {
520   HWND hWnd = (HWND)surfaceId;
521
522   mWin32Window = static_cast<WinWindowHandle>(surfaceId);
523
524   mWindowImpl.SetHWND(surfaceId);
525
526   mWindowImpl.SetWinProc();
527 }
528
529 void WindowBaseWin::EventEntry(TWinEventInfo* event)
530 {
531   unsigned int uMsg = event->uMsg;
532
533   switch(uMsg)
534   {
535     case WM_SETFOCUS:
536     {
537       OnFocusIn(uMsg, event);
538       break;
539     }
540
541     case WM_KILLFOCUS:
542     {
543       OnFocusOut(uMsg, event);
544       break;
545     }
546
547     case WM_PAINT:
548     {
549       OnWindowDamaged(uMsg, event);
550       break;
551     }
552
553     case WM_LBUTTONDOWN:
554     {
555       OnMouseButtonDown(uMsg, event);
556       break;
557     }
558
559     case WM_LBUTTONUP:
560     {
561       OnMouseButtonUp(uMsg, event);
562       break;
563     }
564
565     case WM_MOUSEMOVE:
566     {
567       OnMouseButtonMove(uMsg, event);
568       break;
569     }
570
571     case WM_MOUSEWHEEL:
572     {
573       OnMouseWheel(uMsg, event);
574       break;
575     }
576
577     case WM_KEYDOWN:
578     {
579       OnKeyDown(uMsg, event);
580       break;
581     }
582
583     case WM_KEYUP:
584     {
585       OnKeyUp(uMsg, event);
586       break;
587     }
588
589     default:
590       break;
591   }
592 }
593
594 void WindowBaseWin::SetParent(WindowBase* parentWinBase, bool belowParent)
595 {
596 }
597
598 int WindowBaseWin::CreateFrameRenderedSyncFence()
599 {
600   return -1;
601 }
602
603 int WindowBaseWin::CreateFramePresentedSyncFence()
604 {
605   return -1;
606 }
607
608 void WindowBaseWin::SetPositionSizeWithAngle(PositionSize positionSize, int angle)
609 {
610 }
611
612 void WindowBaseWin::InitializeIme()
613 {
614 }
615
616 void WindowBaseWin::ImeWindowReadyToRender()
617 {
618 }
619
620 void WindowBaseWin::RequestMoveToServer()
621 {
622 }
623
624 void WindowBaseWin::RequestResizeToServer(WindowResizeDirection direction)
625 {
626 }
627
628 void WindowBaseWin::EnableFloatingMode(bool enable)
629 {
630 }
631
632 bool WindowBaseWin::IsFloatingModeEnabled() const
633 {
634   return false;
635 }
636
637 void WindowBaseWin::IncludeInputRegion(const Rect<int>& inputRegion)
638 {
639 }
640
641 void WindowBaseWin::ExcludeInputRegion(const Rect<int>& inputRegion)
642 {
643 }
644
645 } // namespace Adaptor
646
647 } // namespace Internal
648
649 } // namespace Dali