2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
\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
8 * http://www.apache.org/licenses/LICENSE-2.0
\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
19 #include <dali/internal/window-system/windows/window-base-win.h>
\r
22 #include <dali/public-api/object/any.h>
\r
23 #include <dali/integration-api/debug.h>
\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
42 const Device::Class::Type DEFAULT_DEVICE_CLASS = Device::Class::NONE;
\r
43 const Device::Subclass::Type DEFAULT_DEVICE_SUBCLASS = Device::Subclass::NONE;
\r
45 const unsigned int PRIMARY_TOUCH_BUTTON_ID( 1 );
\r
47 #if defined(DEBUG_ENABLED)
\r
48 Debug::Filter* gWindowBaseLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_WINDOW_BASE" );
\r
51 } // unnamed namespace
\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
59 Initialize( positionSize, surface, isTransparent );
\r
62 WindowBaseWin::~WindowBaseWin()
\r
64 WindowsPlatformImplementation::PostWinMessage( WM_CLOSE, 0, 0, mWin32Window );
\r
67 void WindowBaseWin::Initialize( PositionSize positionSize, Any surface, bool isTransparent )
\r
69 // see if there is a surface in Any surface
\r
70 unsigned int surfaceId = GetSurfaceId( surface );
\r
72 // if the surface is empty, create a new one.
\r
73 if( surfaceId == 0 )
\r
75 // we own the surface about to created
\r
77 CreateWinWindow( positionSize, isTransparent );
\r
81 // XLib should already be initialized so no point in calling XInitThreads
\r
82 mWin32Window = static_cast< WinWindowHandle >( surfaceId );
\r
85 WindowsPlatformImplementation::SetListener( MakeCallback( this, &WindowBaseWin::EventEntry ) );
\r
88 void WindowBaseWin::OnDeleteRequest()
\r
90 mDeleteRequestSignal.Emit();
\r
93 void WindowBaseWin::OnFocusIn( int type, TWinEventInfo *event )
\r
97 void WindowBaseWin::OnFocusOut( int type, TWinEventInfo *event )
\r
101 void WindowBaseWin::OnWindowDamaged( int type, TWinEventInfo *event )
\r
103 Event_Mouse_Button* windowDamagedEvent( (Event_Mouse_Button*)event );
\r
105 if( windowDamagedEvent->window == mWin32Window )
\r
110 WindowSystem::GetScreenSize( area.width, area.height );
\r
112 mWindowDamagedSignal.Emit( area );
\r
116 void WindowBaseWin::OnMouseButtonDown( int type, TWinEventInfo *event )
\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
124 if( touchEvent.window == mWin32Window )
\r
126 PointState::Type state ( PointState::DOWN );
\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
136 mTouchEventSignal.Emit( point, touchEvent.timestamp );
\r
140 void WindowBaseWin::OnMouseButtonUp( int type, TWinEventInfo *event )
\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
148 if( touchEvent.window == mWin32Window )
\r
150 PointState::Type state( PointState::UP );
\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
160 mTouchEventSignal.Emit( point, touchEvent.timestamp );
\r
164 void WindowBaseWin::OnMouseButtonMove( int type, TWinEventInfo *event )
\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
172 if( touchEvent.window == mWin32Window )
\r
174 PointState::Type state( PointState::MOTION );
\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
184 mTouchEventSignal.Emit( point, touchEvent.timestamp );
\r
188 void WindowBaseWin::OnMouseWheel( int type, TWinEventInfo *event )
\r
190 Event_Mouse_Wheel mouseWheelEvent = *((Event_Mouse_Wheel*)( event ));
\r
192 if( mouseWheelEvent.window == mWin32Window )
\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
196 WheelEvent wheelEvent( WheelEvent::MOUSE_WHEEL, mouseWheelEvent.direction, mouseWheelEvent.modifiers, Vector2( mouseWheelEvent.x, mouseWheelEvent.y ), mouseWheelEvent.z, mouseWheelEvent.timestamp );
\r
198 mWheelEventSignal.Emit( wheelEvent );
\r
202 void WindowBaseWin::OnKeyDown( int type, TWinEventInfo *event )
\r
204 if( event->mWindow == mWin32Window )
\r
206 DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseWin::OnKeyDown\n" );
\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
214 unsigned long time( 0 );
\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
219 Integration::KeyEvent keyEvent( keyName, emptyString, keyString, keyCode, modifier, time, Integration::KeyEvent::Down, emptyString, emptyString, DEFAULT_DEVICE_CLASS, DEFAULT_DEVICE_SUBCLASS );
\r
221 mKeyEventSignal.Emit( keyEvent );
\r
225 void WindowBaseWin::OnKeyUp( int type, TWinEventInfo *event )
\r
227 if( event->mWindow == mWin32Window )
\r
229 DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseWin::OnKeyDown\n" );
\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
237 unsigned long time( 0 );
\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
242 Integration::KeyEvent keyEvent( keyName, emptyString, keyString, keyCode, modifier, time, Integration::KeyEvent::Down, emptyString, emptyString, DEFAULT_DEVICE_CLASS, DEFAULT_DEVICE_SUBCLASS );
\r
244 mKeyEventSignal.Emit( keyEvent );
\r
248 Any WindowBaseWin::GetNativeWindow()
\r
250 return mWin32Window;
\r
253 int WindowBaseWin::GetNativeWindowId()
\r
255 return mWin32Window;
\r
258 EGLNativeWindowType WindowBaseWin::CreateEglWindow( int width, int height )
\r
260 return reinterpret_cast< EGLNativeWindowType >( mWin32Window );
\r
263 void WindowBaseWin::DestroyEglWindow()
\r
267 void WindowBaseWin::SetEglWindowRotation( int angle )
\r
271 void WindowBaseWin::SetEglWindowBufferTransform( int angle )
\r
275 void WindowBaseWin::SetEglWindowTransform( int angle )
\r
279 void WindowBaseWin::ResizeEglWindow( PositionSize positionSize )
\r
283 bool WindowBaseWin::IsEglWindowRotationSupported()
\r
288 void WindowBaseWin::Move( PositionSize positionSize )
\r
292 void WindowBaseWin::Resize( PositionSize positionSize )
\r
296 void WindowBaseWin::MoveResize( PositionSize positionSize )
\r
300 void WindowBaseWin::SetClass( const std::string& name, const std::string& className )
\r
304 void WindowBaseWin::Raise()
\r
308 void WindowBaseWin::Lower()
\r
312 void WindowBaseWin::Activate()
\r
316 void WindowBaseWin::SetAvailableOrientations( const std::vector< Dali::Window::WindowOrientation >& orientations )
\r
320 void WindowBaseWin::SetPreferredOrientation( Dali::Window::WindowOrientation orientation )
\r
324 void WindowBaseWin::SetAcceptFocus( bool accept )
\r
328 void WindowBaseWin::Show()
\r
332 void WindowBaseWin::Hide()
\r
336 unsigned int WindowBaseWin::GetSupportedAuxiliaryHintCount() const
\r
341 std::string WindowBaseWin::GetSupportedAuxiliaryHint( unsigned int index ) const
\r
343 return std::string();
\r
346 unsigned int WindowBaseWin::AddAuxiliaryHint( const std::string& hint, const std::string& value )
\r
351 bool WindowBaseWin::RemoveAuxiliaryHint( unsigned int id )
\r
356 bool WindowBaseWin::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
\r
361 std::string WindowBaseWin::GetAuxiliaryHintValue( unsigned int id ) const
\r
363 return std::string();
\r
366 unsigned int WindowBaseWin::GetAuxiliaryHintId( const std::string& hint ) const
\r
371 void WindowBaseWin::SetInputRegion( const Rect< int >& inputRegion )
\r
375 void WindowBaseWin::SetType( Dali::Window::Type type )
\r
379 bool WindowBaseWin::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
\r
384 Dali::Window::NotificationLevel::Type WindowBaseWin::GetNotificationLevel() const
\r
386 return Dali::Window::NotificationLevel::NONE;
\r
389 void WindowBaseWin::SetOpaqueState( bool opaque )
\r
393 bool WindowBaseWin::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
\r
398 Dali::Window::ScreenOffMode::Type WindowBaseWin::GetScreenOffMode() const
\r
400 return Dali::Window::ScreenOffMode::TIMEOUT;
\r
403 bool WindowBaseWin::SetBrightness( int brightness )
\r
408 int WindowBaseWin::GetBrightness() const
\r
413 bool WindowBaseWin::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
\r
418 bool WindowBaseWin::UngrabKey( Dali::KEY key )
\r
423 bool WindowBaseWin::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
\r
428 bool WindowBaseWin::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
\r
433 void WindowBaseWin::GetDpi( unsigned int& dpiHorizontal, unsigned int& dpiVertical )
\r
438 //// 1 inch = 25.4 millimeters
\r
439 WindowsPlatformImplementation::GetDPI( mWin32Window, xres, yres );
\r
444 dpiHorizontal = static_cast<int>( xres + 0.5f ); // rounding
\r
445 dpiVertical = static_cast<int>( yres + 0.5f );
\r
448 int WindowBaseWin::GetScreenRotationAngle()
\r
453 void WindowBaseWin::SetWindowRotationAngle( int degree )
\r
457 int WindowBaseWin::GetWindowRotationAngle()
\r
461 void WindowBaseWin::WindowRotationCompleted( int degree, int width, int height )
\r
465 void WindowBaseWin::SetTransparency( bool transparent )
\r
469 int WindowBaseWin::GetOrientation() const
\r
473 unsigned int WindowBaseWin::GetSurfaceId( Any surface ) const
\r
475 unsigned int surfaceId = 0;
\r
477 if ( surface.Empty() == false )
\r
479 // check we have a valid type
\r
480 DALI_ASSERT_ALWAYS( (surface.GetType() == typeid ( WinWindowHandle ) )
\r
481 && "Surface type is invalid" );
\r
483 surfaceId = AnyCast< WinWindowHandle >( surface );
\r
488 void WindowBaseWin::CreateWinWindow( PositionSize positionSize, bool isTransparent )
\r
490 long hWnd = WindowsPlatformImplementation::CreateHwnd( "Demo", "Demo", positionSize.x, positionSize.y, positionSize.width, positionSize.height, NULL );
\r
492 WindowsPlatformImplementation::ShowWindow( hWnd );
\r
494 mWin32Window = (WinWindowHandle)hWnd;
\r
495 DALI_ASSERT_ALWAYS( mWin32Window != 0 && "There is no Windows window" );
\r
498 void WindowBaseWin::EventEntry( TWinEventInfo *event )
\r
500 unsigned int uMsg = event->uMsg;
\r
506 OnFocusIn( uMsg, event );
\r
512 OnFocusOut( uMsg, event );
\r
518 OnWindowDamaged( uMsg, event );
\r
522 case WM_LBUTTONDOWN:
\r
524 OnMouseButtonDown( uMsg, event );
\r
530 OnMouseButtonUp( uMsg, event );
\r
536 OnMouseButtonMove( uMsg, event );
\r
540 case WM_MOUSEWHEEL:
\r
542 OnMouseWheel( uMsg, event );
\r
548 OnKeyDown( uMsg, event );
\r
554 OnKeyUp( uMsg, event );
\r
563 } // namespace Adaptor
\r
565 } // namespace Internal
\r
567 } // namespace Dali
\r