2 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/window-system/windows/window-base-win.h>
22 #include <dali/integration-api/debug.h>
23 #include <dali/public-api/object/any.h>
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>
38 const Device::Class::Type DEFAULT_DEVICE_CLASS = Device::Class::NONE;
39 const Device::Subclass::Type DEFAULT_DEVICE_SUBCLASS = Device::Subclass::NONE;
41 const unsigned int PRIMARY_TOUCH_BUTTON_ID(1);
43 #if defined(DEBUG_ENABLED)
44 Debug::Filter* gWindowBaseLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_WINDOW_BASE");
47 } // unnamed namespace
49 WindowBaseWin::WindowBaseWin(Dali::PositionSize positionSize, Any surface, bool isTransparent)
52 mIsTransparent(false), // Should only be set to true once we actually create a transparent window regardless of what isTransparent is.
53 mRotationAppSet(false)
55 Initialize(positionSize, surface, isTransparent);
58 WindowBaseWin::~WindowBaseWin()
60 mWindowImpl.PostWinMessage(WM_CLOSE, 0, 0);
63 void WindowBaseWin::Initialize(PositionSize positionSize, Any surface, bool isTransparent)
65 // see if there is a surface in Any surface
66 uintptr_t surfaceId = GetSurfaceId(surface);
68 // if the surface is empty, create a new one.
71 // we own the surface about to created
73 CreateWinWindow(positionSize, isTransparent);
77 SetWinWindow(surfaceId);
80 mWindowImpl.SetListener(MakeCallback(this, &WindowBaseWin::EventEntry));
83 void WindowBaseWin::OnDeleteRequest()
85 mDeleteRequestSignal.Emit();
88 void WindowBaseWin::OnFocusIn(int type, TWinEventInfo* event)
92 void WindowBaseWin::OnFocusOut(int type, TWinEventInfo* event)
96 void WindowBaseWin::OnWindowDamaged(int type, TWinEventInfo* event)
98 Event_Mouse_Button* windowDamagedEvent((Event_Mouse_Button*)event);
100 if(windowDamagedEvent->window == mWin32Window)
105 WindowSystem::GetScreenSize(area.width, area.height);
107 mWindowDamagedSignal.Emit(area);
111 void WindowBaseWin::OnMouseButtonDown(int type, TWinEventInfo* event)
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;
119 if(touchEvent.window == mWin32Window)
121 PointState::Type state(PointState::DOWN);
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));
131 mTouchEventSignal.Emit(point, touchEvent.timestamp);
135 void WindowBaseWin::OnMouseButtonUp(int type, TWinEventInfo* event)
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;
143 if(touchEvent.window == mWin32Window)
145 PointState::Type state(PointState::UP);
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));
155 mTouchEventSignal.Emit(point, touchEvent.timestamp);
159 void WindowBaseWin::OnMouseButtonMove(int type, TWinEventInfo* event)
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;
167 if(touchEvent.window == mWin32Window)
169 PointState::Type state(PointState::MOTION);
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));
179 mTouchEventSignal.Emit(point, touchEvent.timestamp);
183 void WindowBaseWin::OnMouseWheel(int type, TWinEventInfo* event)
185 Event_Mouse_Wheel mouseWheelEvent = *((Event_Mouse_Wheel*)(event));
187 if(mouseWheelEvent.window == mWin32Window)
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);
191 Integration::WheelEvent wheelEvent(Integration::WheelEvent::MOUSE_WHEEL, mouseWheelEvent.direction, mouseWheelEvent.modifiers, Vector2(mouseWheelEvent.x, mouseWheelEvent.y), mouseWheelEvent.z, mouseWheelEvent.timestamp);
193 mWheelEventSignal.Emit(wheelEvent);
197 void WindowBaseWin::OnKeyDown(int type, TWinEventInfo* event)
199 if(event->mWindow == mWin32Window)
201 DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseWin::OnKeyDown\n");
203 int keyCode = event->wParam;
204 std::string keyName(WindowsPlatform::GetKeyName(keyCode));
205 std::string keyString;
206 std::string emptyString;
209 unsigned long time(0);
211 // Ensure key event string is not NULL as keys like SHIFT have a null string.
212 keyString.push_back(event->wParam);
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();
217 mKeyEventSignal.Emit(keyEvent);
221 void WindowBaseWin::OnKeyUp(int type, TWinEventInfo* event)
223 if(event->mWindow == mWin32Window)
225 DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseWin::OnKeyDown\n");
227 int keyCode = event->wParam;
228 std::string keyName(WindowsPlatform::GetKeyName(keyCode));
229 std::string keyString;
230 std::string emptyString;
233 unsigned long time(0);
235 // Ensure key event string is not NULL as keys like SHIFT have a null string.
236 keyString.push_back(event->wParam);
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();
241 mKeyEventSignal.Emit(keyEvent);
245 Any WindowBaseWin::GetNativeWindow()
250 int WindowBaseWin::GetNativeWindowId()
255 std::string WindowBaseWin::GetNativeWindowResourceId()
257 return std::string();
260 EGLNativeWindowType WindowBaseWin::CreateEglWindow(int width, int height)
262 return reinterpret_cast<EGLNativeWindowType>(mWin32Window);
265 void WindowBaseWin::DestroyEglWindow()
269 void WindowBaseWin::SetEglWindowRotation(int angle)
273 void WindowBaseWin::SetEglWindowBufferTransform(int angle)
277 void WindowBaseWin::SetEglWindowTransform(int angle)
281 void WindowBaseWin::ResizeEglWindow(PositionSize positionSize)
285 bool WindowBaseWin::IsEglWindowRotationSupported()
290 void WindowBaseWin::Move(PositionSize positionSize)
294 void WindowBaseWin::Resize(PositionSize positionSize)
296 ::SetWindowPos((HWND)mWin32Window, NULL, positionSize.x, positionSize.y, positionSize.width, positionSize.height, SWP_SHOWWINDOW);
299 void WindowBaseWin::MoveResize(PositionSize positionSize)
303 void WindowBaseWin::SetLayout(unsigned int numCols, unsigned int numRows, unsigned int column, unsigned int row, unsigned int colSpan, unsigned int rowSpan)
307 void WindowBaseWin::SetClass(const std::string& name, const std::string& className)
311 void WindowBaseWin::Raise()
315 void WindowBaseWin::Lower()
319 void WindowBaseWin::Activate()
323 void WindowBaseWin::Maximize(bool maximize)
327 bool WindowBaseWin::IsMaximized() const
332 void WindowBaseWin::SetMaximumSize(Dali::Window::WindowSize size)
336 void WindowBaseWin::Minimize(bool minimize)
340 bool WindowBaseWin::IsMinimized() const
345 void WindowBaseWin::SetMimimumSize(Dali::Window::WindowSize size)
349 void WindowBaseWin::SetAvailableAnlges(const std::vector<int>& angles)
353 void WindowBaseWin::SetPreferredAngle(int angle)
357 void WindowBaseWin::SetAcceptFocus(bool accept)
361 void WindowBaseWin::Show()
365 void WindowBaseWin::Hide()
369 unsigned int WindowBaseWin::GetSupportedAuxiliaryHintCount() const
374 std::string WindowBaseWin::GetSupportedAuxiliaryHint(unsigned int index) const
376 return std::string();
379 unsigned int WindowBaseWin::AddAuxiliaryHint(const std::string& hint, const std::string& value)
384 bool WindowBaseWin::RemoveAuxiliaryHint(unsigned int id)
389 bool WindowBaseWin::SetAuxiliaryHintValue(unsigned int id, const std::string& value)
394 std::string WindowBaseWin::GetAuxiliaryHintValue(unsigned int id) const
396 return std::string();
399 unsigned int WindowBaseWin::GetAuxiliaryHintId(const std::string& hint) const
404 void WindowBaseWin::SetInputRegion(const Rect<int>& inputRegion)
408 void WindowBaseWin::SetType(Dali::WindowType type)
412 Dali::WindowType WindowBaseWin::GetType() const
414 return Dali::WindowType::NORMAL;
417 Dali::WindowOperationResult WindowBaseWin::SetNotificationLevel(Dali::WindowNotificationLevel level)
419 return Dali::WindowOperationResult::NOT_SUPPORTED;
422 Dali::WindowNotificationLevel WindowBaseWin::GetNotificationLevel() const
424 return Dali::WindowNotificationLevel::NONE;
427 void WindowBaseWin::SetOpaqueState(bool opaque)
431 Dali::WindowOperationResult WindowBaseWin::SetScreenOffMode(WindowScreenOffMode screenOffMode)
433 return Dali::WindowOperationResult::NOT_SUPPORTED;
436 WindowScreenOffMode WindowBaseWin::GetScreenOffMode() const
438 return WindowScreenOffMode::TIMEOUT;
441 Dali::WindowOperationResult WindowBaseWin::SetBrightness(int brightness)
443 return Dali::WindowOperationResult::NOT_SUPPORTED;
446 int WindowBaseWin::GetBrightness() const
451 bool WindowBaseWin::GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode)
456 bool WindowBaseWin::UngrabKey(Dali::KEY key)
461 bool WindowBaseWin::GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result)
466 bool WindowBaseWin::UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result)
471 void WindowBaseWin::GetDpi(unsigned int& dpiHorizontal, unsigned int& dpiVertical)
476 //// 1 inch = 25.4 millimeters
477 mWindowImpl.GetDPI(xres, yres);
482 dpiHorizontal = static_cast<int>(xres + 0.5f); // rounding
483 dpiVertical = static_cast<int>(yres + 0.5f);
486 int WindowBaseWin::GetScreenRotationAngle()
491 void WindowBaseWin::SetWindowRotationAngle(int degree)
495 void WindowBaseWin::WindowRotationCompleted(int degree, int width, int height)
499 void WindowBaseWin::SetTransparency(bool transparent)
503 int WindowBaseWin::GetWindowRotationAngle() const
508 uintptr_t WindowBaseWin::GetSurfaceId(Any surface) const
510 uintptr_t surfaceId = 0;
512 if(surface.Empty() == false)
514 // check we have a valid type
515 DALI_ASSERT_ALWAYS((surface.GetType() == typeid(WinWindowHandle)) && "Surface type is invalid");
517 surfaceId = AnyCast<WinWindowHandle>(surface);
522 void WindowBaseWin::CreateWinWindow(PositionSize positionSize, bool isTransparent)
524 long hWnd = WindowsPlatform::WindowImpl::CreateHwnd("Demo", positionSize.x, positionSize.y, positionSize.width, positionSize.height, NULL);
525 mWindowImpl.SetHWND(hWnd);
527 mWin32Window = static_cast<WinWindowHandle>(hWnd);
529 DALI_ASSERT_ALWAYS(mWin32Window != 0 && "There is no Windows window");
532 void WindowBaseWin::SetWinWindow(uintptr_t surfaceId)
534 HWND hWnd = (HWND)surfaceId;
536 mWin32Window = static_cast<WinWindowHandle>(surfaceId);
538 mWindowImpl.SetHWND(surfaceId);
540 mWindowImpl.SetWinProc();
543 void WindowBaseWin::EventEntry(TWinEventInfo* event)
545 unsigned int uMsg = event->uMsg;
551 OnFocusIn(uMsg, event);
557 OnFocusOut(uMsg, event);
563 OnWindowDamaged(uMsg, event);
569 OnMouseButtonDown(uMsg, event);
575 OnMouseButtonUp(uMsg, event);
581 OnMouseButtonMove(uMsg, event);
587 OnMouseWheel(uMsg, event);
593 OnKeyDown(uMsg, event);
599 OnKeyUp(uMsg, event);
608 void WindowBaseWin::SetParent(WindowBase* parentWinBase, bool belowParent)
612 int WindowBaseWin::CreateFrameRenderedSyncFence()
617 int WindowBaseWin::CreateFramePresentedSyncFence()
622 void WindowBaseWin::SetPositionSizeWithAngle(PositionSize positionSize, int angle)
626 void WindowBaseWin::InitializeIme()
630 void WindowBaseWin::ImeWindowReadyToRender()
634 void WindowBaseWin::RequestMoveToServer()
638 void WindowBaseWin::RequestResizeToServer(WindowResizeDirection direction)
642 void WindowBaseWin::EnableFloatingMode(bool enable)
646 bool WindowBaseWin::IsFloatingModeEnabled() const
651 void WindowBaseWin::IncludeInputRegion(const Rect<int>& inputRegion)
655 void WindowBaseWin::ExcludeInputRegion(const Rect<int>& inputRegion)
659 bool WindowBaseWin::PointerConstraintsLock()
664 bool WindowBaseWin::PointerConstraintsUnlock()
669 void WindowBaseWin::LockedPointerRegionSet(int32_t x, int32_t y, int32_t width, int32_t height)
673 void WindowBaseWin::LockedPointerCursorPositionHintSet(int32_t x, int32_t y)
677 bool WindowBaseWin::PointerWarp(int32_t x, int32_t y)
682 void WindowBaseWin::CursorVisibleSet(bool visible)
686 bool WindowBaseWin::KeyboardGrab(Device::Subclass::Type deviceSubclass)
691 bool WindowBaseWin::KeyboardUnGrab()
696 void WindowBaseWin::SetFullScreen(bool fullscreen)
701 bool WindowBaseWin::GetFullScreen()
706 void WindowBaseWin::SetFrontBufferRendering(bool enable)
710 bool WindowBaseWin::GetFrontBufferRendering()
715 void WindowBaseWin::SetEglWindowFrontBufferMode(bool enable)
719 } // namespace Adaptor
721 } // namespace Internal