2 * Copyright (c) 2018 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/public-api/object/any.h>
23 #include <dali/integration-api/debug.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>
42 const Device::Class::Type DEFAULT_DEVICE_CLASS = Device::Class::NONE;
43 const Device::Subclass::Type DEFAULT_DEVICE_SUBCLASS = Device::Subclass::NONE;
45 const unsigned int PRIMARY_TOUCH_BUTTON_ID( 1 );
47 #if defined(DEBUG_ENABLED)
48 Debug::Filter* gWindowBaseLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_WINDOW_BASE" );
51 } // unnamed namespace
53 WindowBaseWin::WindowBaseWin( Dali::PositionSize positionSize, Any surface, bool isTransparent )
56 mIsTransparent( false ), // Should only be set to true once we actually create a transparent window regardless of what isTransparent is.
57 mRotationAppSet( false )
59 Initialize( positionSize, surface, isTransparent );
62 WindowBaseWin::~WindowBaseWin()
64 mWindowImpl.PostWinMessage( WM_CLOSE, 0, 0 );
67 void WindowBaseWin::Initialize( PositionSize positionSize, Any surface, bool isTransparent )
69 // see if there is a surface in Any surface
70 unsigned int surfaceId = GetSurfaceId( surface );
72 // if the surface is empty, create a new one.
75 // we own the surface about to created
77 CreateWinWindow( positionSize, isTransparent );
81 // XLib should already be initialized so no point in calling XInitThreads
82 mWin32Window = static_cast< WinWindowHandle >( surfaceId );
85 mWindowImpl.SetListener( MakeCallback( this, &WindowBaseWin::EventEntry ) );
88 void WindowBaseWin::OnDeleteRequest()
90 mDeleteRequestSignal.Emit();
93 void WindowBaseWin::OnFocusIn( int type, TWinEventInfo *event )
97 void WindowBaseWin::OnFocusOut( int type, TWinEventInfo *event )
101 void WindowBaseWin::OnWindowDamaged( int type, TWinEventInfo *event )
103 Event_Mouse_Button* windowDamagedEvent( (Event_Mouse_Button*)event );
105 if( windowDamagedEvent->window == mWin32Window )
110 WindowSystem::GetScreenSize( area.width, area.height );
112 mWindowDamagedSignal.Emit( area );
116 void WindowBaseWin::OnMouseButtonDown( int type, TWinEventInfo *event )
118 Event_Mouse_Button touchEvent = *((Event_Mouse_Button*)event);
119 touchEvent.timestamp = GetTickCount();
120 touchEvent.x = LOWORD( event->lParam );
121 touchEvent.y = HIWORD( event->lParam );
122 touchEvent.multi.device = DEVICE_MOUSE;
124 if( touchEvent.window == mWin32Window )
126 PointState::Type state ( PointState::DOWN );
128 Integration::Point point;
129 point.SetDeviceId( touchEvent.multi.device );
130 point.SetState( state );
131 point.SetScreenPosition( Vector2( touchEvent.x, touchEvent.y + mWindowImpl.GetEdgeHeight() ) );
132 point.SetRadius( touchEvent.multi.radius, Vector2( touchEvent.multi.radius_x, touchEvent.multi.radius_y ) );
133 point.SetPressure( touchEvent.multi.pressure );
134 point.SetAngle( Degree( touchEvent.multi.angle ) );
136 mTouchEventSignal.Emit( point, touchEvent.timestamp );
140 void WindowBaseWin::OnMouseButtonUp( int type, TWinEventInfo *event )
142 Event_Mouse_Button touchEvent = *( (Event_Mouse_Button*)event );
143 touchEvent.timestamp = GetTickCount();
144 touchEvent.x = LOWORD( event->lParam );
145 touchEvent.y = HIWORD( event->lParam );
146 touchEvent.multi.device = DEVICE_MOUSE;
148 if( touchEvent.window == mWin32Window )
150 PointState::Type state( PointState::UP );
152 Integration::Point point;
153 point.SetDeviceId( touchEvent.multi.device );
154 point.SetState( state );
155 point.SetScreenPosition( Vector2( touchEvent.x, touchEvent.y + mWindowImpl.GetEdgeHeight() ) );
156 point.SetRadius( touchEvent.multi.radius, Vector2( touchEvent.multi.radius_x, touchEvent.multi.radius_y ) );
157 point.SetPressure( touchEvent.multi.pressure );
158 point.SetAngle( Degree( touchEvent.multi.angle ) );
160 mTouchEventSignal.Emit( point, touchEvent.timestamp );
164 void WindowBaseWin::OnMouseButtonMove( int type, TWinEventInfo *event )
166 Event_Mouse_Button touchEvent = *((Event_Mouse_Button*)event);
167 touchEvent.timestamp = GetTickCount();
168 touchEvent.x = LOWORD( event->lParam );
169 touchEvent.y = HIWORD( event->lParam );
170 touchEvent.multi.device = DEVICE_MOUSE;
172 if( touchEvent.window == mWin32Window )
174 PointState::Type state( PointState::MOTION );
176 Integration::Point point;
177 point.SetDeviceId( touchEvent.multi.device );
178 point.SetState( state );
179 point.SetScreenPosition( Vector2( touchEvent.x, touchEvent.y + mWindowImpl.GetEdgeHeight() ) );
180 point.SetRadius( touchEvent.multi.radius, Vector2( touchEvent.multi.radius_x, touchEvent.multi.radius_y ) );
181 point.SetPressure( touchEvent.multi.pressure );
182 point.SetAngle( Degree( touchEvent.multi.angle ) );
184 mTouchEventSignal.Emit( point, touchEvent.timestamp );
188 void WindowBaseWin::OnMouseWheel( int type, TWinEventInfo *event )
190 Event_Mouse_Wheel mouseWheelEvent = *((Event_Mouse_Wheel*)( event ));
192 if( mouseWheelEvent.window == mWin32Window )
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 );
196 WheelEvent wheelEvent( WheelEvent::MOUSE_WHEEL, mouseWheelEvent.direction, mouseWheelEvent.modifiers, Vector2( mouseWheelEvent.x, mouseWheelEvent.y ), mouseWheelEvent.z, mouseWheelEvent.timestamp );
198 mWheelEventSignal.Emit( wheelEvent );
202 void WindowBaseWin::OnKeyDown( int type, TWinEventInfo *event )
204 if( event->mWindow == mWin32Window )
206 DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseWin::OnKeyDown\n" );
208 int keyCode = event->wParam;
209 std::string keyName( WindowsPlatformImplementation::GetKeyName( keyCode ) );
210 std::string keyString;
211 std::string emptyString;
214 unsigned long time( 0 );
216 // Ensure key event string is not NULL as keys like SHIFT have a null string.
217 keyString.push_back( event->wParam );
219 Integration::KeyEvent keyEvent( keyName, emptyString, keyString, keyCode, modifier, time, Integration::KeyEvent::Down, emptyString, emptyString, DEFAULT_DEVICE_CLASS, DEFAULT_DEVICE_SUBCLASS );
221 mKeyEventSignal.Emit( keyEvent );
225 void WindowBaseWin::OnKeyUp( int type, TWinEventInfo *event )
227 if( event->mWindow == mWin32Window )
229 DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseWin::OnKeyDown\n" );
231 int keyCode = event->wParam;
232 std::string keyName( WindowsPlatformImplementation::GetKeyName( keyCode ) );
233 std::string keyString;
234 std::string emptyString;
237 unsigned long time( 0 );
239 // Ensure key event string is not NULL as keys like SHIFT have a null string.
240 keyString.push_back( event->wParam );
242 Integration::KeyEvent keyEvent( keyName, emptyString, keyString, keyCode, modifier, time, Integration::KeyEvent::Up, emptyString, emptyString, DEFAULT_DEVICE_CLASS, DEFAULT_DEVICE_SUBCLASS );
244 mKeyEventSignal.Emit( keyEvent );
248 Any WindowBaseWin::GetNativeWindow()
253 int WindowBaseWin::GetNativeWindowId()
258 EGLNativeWindowType WindowBaseWin::CreateEglWindow( int width, int height )
260 return reinterpret_cast< EGLNativeWindowType >( mWin32Window );
263 void WindowBaseWin::DestroyEglWindow()
267 void WindowBaseWin::SetEglWindowRotation( int angle )
271 void WindowBaseWin::SetEglWindowBufferTransform( int angle )
275 void WindowBaseWin::SetEglWindowTransform( int angle )
279 void WindowBaseWin::ResizeEglWindow( PositionSize positionSize )
283 bool WindowBaseWin::IsEglWindowRotationSupported()
288 void WindowBaseWin::Move( PositionSize positionSize )
292 void WindowBaseWin::Resize( PositionSize positionSize )
294 ::SetWindowPos( (HWND)mWin32Window, NULL, positionSize.x, positionSize.y, positionSize.width, positionSize.height, SWP_SHOWWINDOW );
297 void WindowBaseWin::MoveResize( PositionSize positionSize )
301 void WindowBaseWin::SetClass( const std::string& name, const std::string& className )
305 void WindowBaseWin::Raise()
309 void WindowBaseWin::Lower()
313 void WindowBaseWin::Activate()
317 void WindowBaseWin::SetAvailableAnlges( const std::vector< int >& angles )
321 void WindowBaseWin::SetPreferredAngle( int angle )
325 void WindowBaseWin::SetAcceptFocus( bool accept )
329 void WindowBaseWin::Show()
333 void WindowBaseWin::Hide()
337 unsigned int WindowBaseWin::GetSupportedAuxiliaryHintCount() const
342 std::string WindowBaseWin::GetSupportedAuxiliaryHint( unsigned int index ) const
344 return std::string();
347 unsigned int WindowBaseWin::AddAuxiliaryHint( const std::string& hint, const std::string& value )
352 bool WindowBaseWin::RemoveAuxiliaryHint( unsigned int id )
357 bool WindowBaseWin::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
362 std::string WindowBaseWin::GetAuxiliaryHintValue( unsigned int id ) const
364 return std::string();
367 unsigned int WindowBaseWin::GetAuxiliaryHintId( const std::string& hint ) const
372 void WindowBaseWin::SetInputRegion( const Rect< int >& inputRegion )
376 void WindowBaseWin::SetType( Dali::Window::Type type )
380 bool WindowBaseWin::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
385 Dali::Window::NotificationLevel::Type WindowBaseWin::GetNotificationLevel() const
387 return Dali::Window::NotificationLevel::NONE;
390 void WindowBaseWin::SetOpaqueState( bool opaque )
394 bool WindowBaseWin::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
399 Dali::Window::ScreenOffMode::Type WindowBaseWin::GetScreenOffMode() const
401 return Dali::Window::ScreenOffMode::TIMEOUT;
404 bool WindowBaseWin::SetBrightness( int brightness )
409 int WindowBaseWin::GetBrightness() const
414 bool WindowBaseWin::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
419 bool WindowBaseWin::UngrabKey( Dali::KEY key )
424 bool WindowBaseWin::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
429 bool WindowBaseWin::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
434 void WindowBaseWin::GetDpi( unsigned int& dpiHorizontal, unsigned int& dpiVertical )
439 //// 1 inch = 25.4 millimeters
440 mWindowImpl.GetDPI( xres, yres );
445 dpiHorizontal = static_cast<int>( xres + 0.5f ); // rounding
446 dpiVertical = static_cast<int>( yres + 0.5f );
449 int WindowBaseWin::GetScreenRotationAngle()
454 void WindowBaseWin::SetWindowRotationAngle( int degree )
458 void WindowBaseWin::WindowRotationCompleted( int degree, int width, int height )
462 void WindowBaseWin::SetTransparency( bool transparent )
466 unsigned int WindowBaseWin::GetSurfaceId( Any surface ) const
468 unsigned int surfaceId = 0;
470 if ( surface.Empty() == false )
472 // check we have a valid type
473 DALI_ASSERT_ALWAYS( (surface.GetType() == typeid ( WinWindowHandle ) )
474 && "Surface type is invalid" );
476 surfaceId = AnyCast< WinWindowHandle >( surface );
481 void WindowBaseWin::CreateWinWindow( PositionSize positionSize, bool isTransparent )
483 long hWnd = mWindowImpl.CreateHwnd( "Demo", "Demo", positionSize.x, positionSize.y, positionSize.width, positionSize.height, NULL );
485 mWin32Window = (WinWindowHandle)hWnd;
486 DALI_ASSERT_ALWAYS( mWin32Window != 0 && "There is no Windows window" );
489 void WindowBaseWin::EventEntry( TWinEventInfo *event )
491 unsigned int uMsg = event->uMsg;
497 OnFocusIn( uMsg, event );
503 OnFocusOut( uMsg, event );
509 OnWindowDamaged( uMsg, event );
515 OnMouseButtonDown( uMsg, event );
521 OnMouseButtonUp( uMsg, event );
527 OnMouseButtonMove( uMsg, event );
533 OnMouseWheel( uMsg, event );
539 OnKeyDown( uMsg, event );
545 OnKeyUp( uMsg, event );
554 void WindowBaseWin::SetParent( WindowBase* parentWinBase )
559 } // namespace Adaptor
561 } // namespace Internal