X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fwindow-system%2Fwindows%2Fplatform-implement-win.cpp;h=1d79ce85cfd8fc6879588c72fc8b145cd2bc98cf;hb=63d63464ee0ea3f3eb802b90419f8fef6bc67d83;hp=f122a432d4a527eca0e21d98df99d362f375701f;hpb=4313bbfa84fc09f9e7ea89329d4e24c6fdf38faf;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git diff --git a/dali/internal/window-system/windows/platform-implement-win.cpp b/dali/internal/window-system/windows/platform-implement-win.cpp index f122a43..1d79ce8 100755 --- a/dali/internal/window-system/windows/platform-implement-win.cpp +++ b/dali/internal/window-system/windows/platform-implement-win.cpp @@ -1,10 +1,30 @@ +/* +* Copyright (c) 2018 Samsung Electronics Co., Ltd. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ + // CLASS HEADER #include -// EXTERNAL_HEADERS +// EXTERNAL INCLUDES #include -#include -#include + +// INTERNAL INCLUDES +#include + +static constexpr float INCH = 25.4; using namespace std; @@ -17,24 +37,24 @@ namespace Internal namespace Adaptor { -namespace WindowsPlatformImplement +namespace WindowsPlatformImplementation { -HWND roothWnd = NULL; - void RunLoop() { MSG nMsg = { 0 }; while( GetMessage( &nMsg, 0, NULL, NULL ) ) { + if( WIN_CALLBACK_EVENT == nMsg.message ) + { + Dali::CallbackBase *callback = ( Dali::CallbackBase* )nMsg.wParam; + Dali::CallbackBase::Execute( *callback ); + } + TranslateMessage( &nMsg ); DispatchMessage( &nMsg ); -#ifdef _WIN32 - //::Sleep( 20 ); -#endif - if( WM_CLOSE == nMsg.message ) { break; @@ -42,52 +62,27 @@ void RunLoop() } } -void SetParent(long child, long parent) +void GetDPI( uint64_t hWnd, float &xDpi, float &yDpi ) { - if (roothWnd == (HWND)child && NULL != (HWND)parent) - { - roothWnd = (HWND)parent; - } + HDC hdcScreen = GetDC( reinterpret_cast( hWnd ) ); - ::SetParent((HWND)child, (HWND)parent); -} - -#define INCH 25.4 - -void GetDPI(float &xDpi, float &yDpi) -{ - HDC hdcScreen = GetDC(roothWnd); - - int iX = GetDeviceCaps( hdcScreen, HORZRES ); // pixel - int iY = GetDeviceCaps( hdcScreen, VERTRES ); // pixel - int iPhsX = GetDeviceCaps( hdcScreen, HORZSIZE ); // mm - int iPhsY = GetDeviceCaps( hdcScreen, VERTSIZE ); // mm + int32_t iX = GetDeviceCaps( hdcScreen, HORZRES ); // pixel + int32_t iY = GetDeviceCaps( hdcScreen, VERTRES ); // pixel + int32_t iPhsX = GetDeviceCaps( hdcScreen, HORZSIZE ); // mm + int32_t iPhsY = GetDeviceCaps( hdcScreen, VERTSIZE ); // mm - xDpi = (float)iX / (float)iPhsX * INCH; - yDpi = (float)iY / (float)iPhsY * INCH; + xDpi = static_cast( iX ) / static_cast( iPhsX ) * INCH; + yDpi = static_cast( iY ) / static_cast( iPhsY ) * INCH; } -map> callbackMap; -set listenerSet; +CallbackBase *listener = NULL; LRESULT CALLBACK WinProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { - for( set::iterator x = listenerSet.begin(); x != listenerSet.end(); ++x ) + if( NULL != listener ) { - ( *x )( (long)hWnd, (long)uMsg, (long)wParam, (long)lParam ); - } - - { - map>::iterator x = callbackMap.find( uMsg ); - - if( callbackMap.end() != x ) - { - set &cbSet = x->second; - for( set::iterator y = cbSet.begin(); cbSet.end() != y; ++y ) - { - Dali::CallbackBase::Execute(**y); - } - } + TWinEventInfo eventInfo( reinterpret_cast( hWnd ), uMsg, wParam, lParam); + CallbackBase::Execute( *listener, &eventInfo ); } LRESULT ret = DefWindowProc( hWnd, uMsg, wParam, lParam ); @@ -96,42 +91,78 @@ LRESULT CALLBACK WinProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) DWORD windowStyle = WS_OVERLAPPED; -int GetEdgeWidth() +int32_t GetEdgeWidth() { switch( windowStyle ) { - case WS_OVERLAPPED: - return 8; - break; - - default: - return 0; - break; + case WS_OVERLAPPED: + { + return 8; + } + default: + { + return 0; + } } } -int GetEdgeHeight() +int32_t GetEdgeHeight() { switch( windowStyle ) { - case WS_OVERLAPPED: - return 18; - break; + case WS_OVERLAPPED: + { + return 18; + } + default: + { + return 0; + } + } +} + +class WindowsDisplayInfo +{ +public: + static int GetColorDepth() + { + DALI_ASSERT_DEBUG(colorDepth >= 0 && "HWND hasn't been created, no color depth"); + return colorDepth; + } - default: - return 0; - break; + static void SetHWND( HWND inHWnd ) + { + if( hWnd != inHWnd ) + { + hWnd = inHWnd; + hdc = GetDC( hWnd ); + colorDepth = GetDeviceCaps( WindowsDisplayInfo::hdc, BITSPIXEL ) * GetDeviceCaps( WindowsDisplayInfo::hdc, PLANES ); + } } + +private: + static int colorDepth; + static HWND hWnd; + static HDC hdc; +}; + +int WindowsDisplayInfo::colorDepth = -1; +HWND WindowsDisplayInfo::hWnd = NULL; +HDC WindowsDisplayInfo::hdc = NULL; + +int GetColorDepth() +{ + return WindowsDisplayInfo::GetColorDepth(); } -long CreateHwnd( +uint64_t CreateHwnd( _In_opt_ const char *lpClassName, _In_opt_ const char *lpWindowName, _In_ int X, _In_ int Y, _In_ int nWidth, _In_ int nHeight, - _In_opt_ long parent) + _In_opt_ uint64_t parent) { WNDCLASS cs = { 0 }; cs.cbClsExtra = 0; @@ -144,249 +175,210 @@ long CreateHwnd( cs.lpszClassName = lpClassName; cs.lpszMenuName = NULL; cs.style = CS_VREDRAW | CS_HREDRAW; - RegisterClass( &cs );//ʵÏÖ×¢²á´°¿Ú + RegisterClass( &cs ); HWND hWnd = CreateWindow( lpClassName, lpWindowName, windowStyle, X, Y, nWidth + 2 * GetEdgeWidth(), nHeight + 2 * GetEdgeHeight(), NULL, NULL, cs.hInstance, NULL ); ShowWindow( hWnd, SW_SHOW ); - if( hWnd != roothWnd ) - { - roothWnd = hWnd; - } + WindowsDisplayInfo::SetHWND( hWnd ); - return (long)hWnd; + return reinterpret_cast( hWnd ); } -void AddListener(winEventCallback callback) +void SetListener( CallbackBase *callback ) { - listenerSet.insert(callback); + listener = callback; } -void AddListener( int msgType, Dali::CallbackBase *callback ) -{ - map>::iterator x = callbackMap.find( msgType ); - if( callbackMap.end() == x ) - { - set callbackSet; - callbackSet.insert( callback ); - - callbackMap.insert( make_pair( msgType, callbackSet ) ); - } - else - { - set &callbackSet = x->second; - set::iterator y = callbackSet.find( callback ); - if( callbackSet.end() == y ) - { - callbackSet.insert( callback ); - } - } -} - -void RemoveListener(int msgType) +bool PostWinMessage( + _In_ uint32_t Msg, + _In_ uint32_t wParam, + _In_ uint64_t lParam, + _In_ uint64_t hWnd) { - callbackMap.erase(msgType); + return (bool)PostMessage( reinterpret_cast( hWnd ), Msg, wParam, lParam ); } -bool PostWinMessage( - _In_ unsigned int Msg, - _In_ long wParam, - _In_ long lParam, - _In_ long hWnd/* = 0*/) +bool PostWinThreadMessage( + _In_ uint32_t Msg, + _In_ uint32_t wParam, + _In_ uint64_t lParam, + _In_ uint64_t threadID/* = -1*/ ) { - if( 0 == hWnd ) + if( -1 == threadID ) { - return (bool)PostMessage( roothWnd, Msg, wParam, lParam ); + threadID = GetCurrentThreadId(); } - else - { - return (bool)PostMessage( (HWND)hWnd, Msg, wParam, lParam ); - } -} - -void ShowWindow(long hWnd) -{ - ::ShowWindow((HWND)hWnd, SW_SHOW); -} -void HideWindow(long hWnd) -{ - ::ShowWindow((HWND)hWnd, SW_HIDE); -} - -long CreateWinSemaphore(_In_ long lInitialCount, _In_ long lMaximumCount) -{ - return (long)::CreateSemaphore(NULL, lInitialCount, lMaximumCount, NULL); + return (bool)PostThreadMessage( threadID, Msg, wParam, lParam ); } -unsigned long WaitForSingleObject(_In_ long hHandle, _In_ unsigned long dwMilliseconds) +void ShowWindow( uint64_t hWnd) { - return ::WaitForSingleObject((HWND)hHandle, dwMilliseconds); + ::ShowWindow( reinterpret_cast( hWnd ), SW_SHOW); } -bool ReleaseSemaphore(_In_ long hSemaphore, _In_ long lReleaseCount, _Out_opt_ long *lpPreviousCount) +void HideWindow( uint64_t hWnd) { - return ::ReleaseSemaphore((HWND)hSemaphore, lReleaseCount, lpPreviousCount); + ::ShowWindow( reinterpret_cast( hWnd ), SW_HIDE); } struct TTimerCallbackInfo { void *data; timerCallback callback; + HWND hWnd; }; -map mapTimerIDToData; - void CALLBACK TimerProc(HWND hWnd, UINT nMsg, UINT_PTR nTimerid, DWORD dwTime) { - map::iterator x = mapTimerIDToData.find( nTimerid ); - - if( mapTimerIDToData.end() == x ) - { - return; - } - - TTimerCallbackInfo &info = x->second; - - info.callback( info.data ); + TTimerCallbackInfo *info = (TTimerCallbackInfo*)nTimerid; + info->callback( info->data ); } int SetTimer(int interval, timerCallback callback, void *data) { - int timerID = 0; + TTimerCallbackInfo *callbackInfo = new TTimerCallbackInfo; + callbackInfo->data = data; + callbackInfo->callback = callback; + callbackInfo->hWnd = ::GetActiveWindow(); - for( map::iterator x = mapTimerIDToData.begin(); mapTimerIDToData.end() != x; ++x ) - { - int id = x->first; - - if( timerID < id ) - { - break; - } - else - { - timerID++; - } - } - - TTimerCallbackInfo callbackInfo; - callbackInfo.data = data; - callbackInfo.callback = callback; - - mapTimerIDToData.insert( make_pair( timerID, callbackInfo ) ); - - ::SetTimer( roothWnd, timerID, interval, TimerProc ); + UINT_PTR timerID = (UINT_PTR)callbackInfo; + ::SetTimer( callbackInfo->hWnd, timerID, interval, TimerProc ); return timerID; } void KillTimer(int id) { - mapTimerIDToData.erase(id); - ::KillTimer(roothWnd, id); + TTimerCallbackInfo *info = (TTimerCallbackInfo*)id; + ::KillTimer( info->hWnd, id ); + delete info; } const char* GetKeyName( int keyCode ) { switch( keyCode ) { - case VK_BACK: - return "Backspace"; - - case VK_TAB: - return "Tab"; - - case VK_RETURN: - return "Return"; - - case VK_ESCAPE: - return "Escape"; - - case VK_SPACE: - return "space"; - - case VK_LEFT: - return "Left"; - - case VK_UP: - return "Up"; - - case VK_RIGHT: - return "Right"; - - case VK_DOWN: - return "Down"; - - case 48: - return "0"; - - case 49: - return "1"; - - case 50: - return "2"; - - case 51: - return "3"; - - case 52: - return "4"; - - case 53: - return "5"; - - case 54: - return "6"; - - case 55: - return "7"; - - case 56: - return "8"; - - case 57: - return "9"; - - break; + case VK_BACK: + { + return "Backspace"; + } + case VK_TAB: + { + return "Tab"; + } + case VK_RETURN: + { + return "Return"; + } + case VK_ESCAPE: + { + return "Escape"; + } + case VK_SPACE: + { + return "Space"; + } + case VK_LEFT: + { + return "Left"; + } + case VK_UP: + { + return "Up"; + } + case VK_RIGHT: + { + return "Right"; + } + case VK_DOWN: + { + return "Down"; + } + case 48: + { + return "0"; + } + case 49: + { + return "1"; + } + case 50: + { + return "2"; + } + case 51: + { + return "3"; + } + case 52: + { + return "4"; + } + case 53: + { + return "5"; + } + case 54: + { + return "6"; + } + case 55: + { + return "7"; + } + case 56: + { + return "8"; + } + case 57: + { + return "9"; + } + default: + { + break; + } } return ""; } -static LARGE_INTEGER _cpuFrequency; -static LARGE_INTEGER *_pCpuFrequency = NULL; +static LARGE_INTEGER cpuFrequency; +static LARGE_INTEGER *pCpuFrequency = NULL; -long GetCurrentThreadId() +uint64_t GetCurrentThreadId() { return ::GetCurrentThreadId(); } void GetNanoseconds( uint64_t& timeInNanoseconds ) { - if( NULL == _pCpuFrequency ) + if( NULL == pCpuFrequency ) { - _pCpuFrequency = &_cpuFrequency; - QueryPerformanceFrequency( _pCpuFrequency ); + pCpuFrequency = &cpuFrequency; + QueryPerformanceFrequency( pCpuFrequency ); } LARGE_INTEGER curTime; QueryPerformanceCounter( &curTime ); - timeInNanoseconds = (double)curTime.QuadPart / (double)_pCpuFrequency->QuadPart * 1000000000; + timeInNanoseconds = static_cast(curTime.QuadPart) / static_cast(pCpuFrequency->QuadPart) * 1000000000; } unsigned int GetCurrentMilliSeconds( void ) { - if( NULL == _pCpuFrequency ) + if( NULL == pCpuFrequency ) { - _pCpuFrequency = &_cpuFrequency; - QueryPerformanceFrequency( _pCpuFrequency ); + pCpuFrequency = &cpuFrequency; + QueryPerformanceFrequency( pCpuFrequency ); } LARGE_INTEGER curTime; QueryPerformanceCounter( &curTime ); - return curTime.QuadPart * 1000 / _pCpuFrequency->QuadPart; + return curTime.QuadPart * 1000 / pCpuFrequency->QuadPart; } } // namespace WindowsPlatformImplement