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/platform-implement-win.h>
\r
21 // EXTERNAL INCLUDES
\r
22 #include <windows.h>
\r
24 // INTERNAL INCLUDES
\r
25 #include <dali/internal/window-system/windows/event-system-win.h>
\r
27 static constexpr float INCH = 25.4;
\r
29 using namespace std;
\r
40 namespace WindowsPlatformImplementation
\r
47 while( GetMessage( &nMsg, 0, NULL, NULL ) )
\r
49 if( WIN_CALLBACK_EVENT == nMsg.message )
\r
51 Dali::CallbackBase *callback = ( Dali::CallbackBase* )nMsg.wParam;
\r
52 Dali::CallbackBase::Execute( *callback );
\r
55 TranslateMessage( &nMsg );
\r
56 DispatchMessage( &nMsg );
\r
58 if( WM_CLOSE == nMsg.message )
\r
65 void GetDPI( uint64_t hWnd, float &xDpi, float &yDpi )
\r
67 HDC hdcScreen = GetDC( reinterpret_cast<HWND>( hWnd ) );
\r
69 int32_t iX = GetDeviceCaps( hdcScreen, HORZRES ); // pixel
\r
70 int32_t iY = GetDeviceCaps( hdcScreen, VERTRES ); // pixel
\r
71 int32_t iPhsX = GetDeviceCaps( hdcScreen, HORZSIZE ); // mm
\r
72 int32_t iPhsY = GetDeviceCaps( hdcScreen, VERTSIZE ); // mm
\r
74 xDpi = static_cast<float>( iX ) / static_cast<float>( iPhsX ) * INCH;
\r
75 yDpi = static_cast<float>( iY ) / static_cast<float>( iPhsY ) * INCH;
\r
78 CallbackBase *listener = NULL;
\r
80 LRESULT CALLBACK WinProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
\r
82 if( NULL != listener )
\r
84 TWinEventInfo eventInfo( reinterpret_cast<uint64_t>( hWnd ), uMsg, wParam, lParam);
\r
85 CallbackBase::Execute( *listener, &eventInfo );
\r
88 LRESULT ret = DefWindowProc( hWnd, uMsg, wParam, lParam );
\r
92 DWORD windowStyle = WS_OVERLAPPED;
\r
94 int32_t GetEdgeWidth()
\r
96 switch( windowStyle )
\r
109 int32_t GetEdgeHeight()
\r
111 switch( windowStyle )
\r
113 case WS_OVERLAPPED:
\r
124 class WindowsDisplayInfo
\r
127 static int GetColorDepth()
\r
129 DALI_ASSERT_DEBUG(colorDepth >= 0 && "HWND hasn't been created, no color depth");
\r
133 static void SetHWND( HWND inHWnd )
\r
135 if( hWnd != inHWnd )
\r
138 hdc = GetDC( hWnd );
\r
139 colorDepth = GetDeviceCaps( WindowsDisplayInfo::hdc, BITSPIXEL ) * GetDeviceCaps( WindowsDisplayInfo::hdc, PLANES );
\r
144 static int colorDepth;
\r
149 int WindowsDisplayInfo::colorDepth = -1;
\r
150 HWND WindowsDisplayInfo::hWnd = NULL;
\r
151 HDC WindowsDisplayInfo::hdc = NULL;
\r
153 int GetColorDepth()
\r
155 return WindowsDisplayInfo::GetColorDepth();
\r
158 uint64_t CreateHwnd(
\r
159 _In_opt_ const char *lpClassName,
\r
160 _In_opt_ const char *lpWindowName,
\r
165 _In_opt_ uint64_t parent)
\r
167 WNDCLASS cs = { 0 };
\r
170 cs.hbrBackground = (HBRUSH)( COLOR_WINDOW + 2 );
\r
173 cs.hInstance = GetModuleHandle( NULL );
\r
174 cs.lpfnWndProc = (WNDPROC)WinProc;
\r
175 cs.lpszClassName = lpClassName;
\r
176 cs.lpszMenuName = NULL;
\r
177 cs.style = CS_VREDRAW | CS_HREDRAW;
\r
178 RegisterClass( &cs );
\r
180 HWND hWnd = CreateWindow( lpClassName, lpWindowName, windowStyle, X, Y, nWidth + 2 * GetEdgeWidth(), nHeight + 2 * GetEdgeHeight(), NULL, NULL, cs.hInstance, NULL );
\r
181 ShowWindow( hWnd, SW_SHOW );
\r
183 WindowsDisplayInfo::SetHWND( hWnd );
\r
185 return reinterpret_cast<uint64_t>( hWnd );
\r
188 void SetListener( CallbackBase *callback )
\r
190 listener = callback;
\r
193 bool PostWinMessage(
\r
195 _In_ uint32_t wParam,
\r
196 _In_ uint64_t lParam,
\r
197 _In_ uint64_t hWnd)
\r
199 return (bool)PostMessage( reinterpret_cast<HWND>( hWnd ), Msg, wParam, lParam );
\r
202 bool PostWinThreadMessage(
\r
204 _In_ uint32_t wParam,
\r
205 _In_ uint64_t lParam,
\r
206 _In_ uint64_t threadID/* = -1*/ )
\r
208 if( -1 == threadID )
\r
210 threadID = GetCurrentThreadId();
\r
213 return (bool)PostThreadMessage( threadID, Msg, wParam, lParam );
\r
216 void ShowWindow( uint64_t hWnd)
\r
218 ::ShowWindow( reinterpret_cast<HWND>( hWnd ), SW_SHOW);
\r
221 void HideWindow( uint64_t hWnd)
\r
223 ::ShowWindow( reinterpret_cast<HWND>( hWnd ), SW_HIDE);
\r
226 struct TTimerCallbackInfo
\r
229 timerCallback callback;
\r
233 void CALLBACK TimerProc(HWND hWnd, UINT nMsg, UINT_PTR nTimerid, DWORD dwTime)
\r
235 TTimerCallbackInfo *info = (TTimerCallbackInfo*)nTimerid;
\r
236 info->callback( info->data );
\r
239 int SetTimer(int interval, timerCallback callback, void *data)
\r
241 TTimerCallbackInfo *callbackInfo = new TTimerCallbackInfo;
\r
242 callbackInfo->data = data;
\r
243 callbackInfo->callback = callback;
\r
244 callbackInfo->hWnd = ::GetActiveWindow();
\r
246 UINT_PTR timerID = (UINT_PTR)callbackInfo;
\r
247 ::SetTimer( callbackInfo->hWnd, timerID, interval, TimerProc );
\r
252 void KillTimer(int id)
\r
254 TTimerCallbackInfo *info = (TTimerCallbackInfo*)id;
\r
255 ::KillTimer( info->hWnd, id );
\r
259 const char* GetKeyName( int keyCode )
\r
265 return "Backspace";
\r
348 static LARGE_INTEGER cpuFrequency;
\r
349 static LARGE_INTEGER *pCpuFrequency = NULL;
\r
351 uint64_t GetCurrentThreadId()
\r
353 return ::GetCurrentThreadId();
\r
356 void GetNanoseconds( uint64_t& timeInNanoseconds )
\r
358 if( NULL == pCpuFrequency )
\r
360 pCpuFrequency = &cpuFrequency;
\r
361 QueryPerformanceFrequency( pCpuFrequency );
\r
364 LARGE_INTEGER curTime;
\r
365 QueryPerformanceCounter( &curTime );
\r
367 timeInNanoseconds = static_cast<double>(curTime.QuadPart) / static_cast<double>(pCpuFrequency->QuadPart) * 1000000000;
\r
370 unsigned int GetCurrentMilliSeconds( void )
\r
372 if( NULL == pCpuFrequency )
\r
374 pCpuFrequency = &cpuFrequency;
\r
375 QueryPerformanceFrequency( pCpuFrequency );
\r
378 LARGE_INTEGER curTime;
\r
379 QueryPerformanceCounter( &curTime );
\r
381 return curTime.QuadPart * 1000 / pCpuFrequency->QuadPart;
\r
384 } // namespace WindowsPlatformImplement
386 } // namespace Adaptor
388 } // namespace internal
390 } // namespace Dali
\r