\r
mCallbacks.insert(callback);\r
\r
- WindowsPlatformImplementation::PostWinThreadMessage( WIN_CALLBACK_EVENT, reinterpret_cast<uint64_t>(callback), 0 );\r
+ WindowsPlatform::PostWinThreadMessage( WIN_CALLBACK_EVENT, reinterpret_cast<uint64_t>(callback), 0 );\r
\r
return true;\r
}\r
{
if( 0 > mImpl->mId )
{
- mImpl->mId = WindowsPlatformImplementation::SetTimer( mImpl->mInterval, TimerSourceFunc, this );
+ mImpl->mId = WindowsPlatform::SetTimer( mImpl->mInterval, TimerSourceFunc, this );
}
}
{
if( 0 <= mImpl->mId )
{
- WindowsPlatformImplementation::KillTimer( mImpl->mId );
+ WindowsPlatform::KillTimer( mImpl->mId );
mImpl->mId = -1;
}
}
mOptions( options )\r
{\r
// Create accompanying file descriptor.\r
- mThreadID = WindowsPlatformImplementation::GetCurrentThreadId();\r
+ mThreadID = WindowsPlatform::GetCurrentThreadId();\r
\r
if ( mThreadID < 0)\r
{\r
// Increment event counter by 1.\r
// Writing to the file descriptor triggers the Dispatch() method in the other thread\r
// (if in multi-threaded environment).\r
- WindowsPlatformImplementation::PostWinThreadMessage( WIN_CALLBACK_EVENT, reinterpret_cast<uint64_t>( mSelfCallback ), 0, mThreadID );\r
+ WindowsPlatform::PostWinThreadMessage( WIN_CALLBACK_EVENT, reinterpret_cast<uint64_t>( mSelfCallback ), 0, mThreadID );\r
}\r
else\r
{\r
namespace
{
-static constexpr float INCH = 25.4;
+constexpr float INCH = 25.4;
}
namespace Dali
namespace Adaptor
{
-namespace WindowsPlatformImplementation
+namespace WindowsPlatform
{
LRESULT CALLBACK WinProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
return ret;
}
-std::map<uint64_t, WindowImpl*> mHWndToListener;
+namespace
+{
+
+const std::string DALI_WINDOW_CLASS_NAME = "DaliWindow";
+
+uint32_t sNumWindows = 0;
+
+void EnsureWindowClassRegistered()
+{
+ if (sNumWindows == 0)
+ {
+ WNDCLASS cs = { 0 };
+ cs.cbClsExtra = 0;
+ cs.cbWndExtra = 0;
+ cs.hbrBackground = (HBRUSH)(COLOR_WINDOW + 2);
+ cs.hCursor = NULL;
+ cs.hIcon = NULL;
+ cs.hInstance = GetModuleHandle(NULL);
+ cs.lpfnWndProc = (WNDPROC)WinProc;
+ cs.lpszClassName = DALI_WINDOW_CLASS_NAME.c_str();
+ cs.lpszMenuName = NULL;
+ cs.style = CS_VREDRAW | CS_HREDRAW;
+ RegisterClass(&cs);
+ }
+}
+
+void EnsureWindowClassUnregistered()
+{
+ if (sNumWindows == 0)
+ {
+ UnregisterClass(DALI_WINDOW_CLASS_NAME.c_str(), GetModuleHandle(NULL));
+ }
+}
+
+std::map<uint64_t, WindowImpl*> sHWndToListener;
+
+void RemoveListener(uint64_t hWnd)
+{
+ std::map<uint64_t, WindowImpl*>::iterator x = sHWndToListener.find(hWnd);
+ if (sHWndToListener.end() != x)
+ {
+ sHWndToListener.erase(x);
+ }
+}
+
+}
+
+const uint32_t WindowImpl::STYLE = WS_OVERLAPPED;
+const int32_t WindowImpl::EDGE_WIDTH = 8;
+const int32_t WindowImpl::EDGE_HEIGHT = 18;
WindowImpl::WindowImpl()
{
mHWnd = 0;
mHdc = 0;
listener = NULL;
- windowStyle = WS_OVERLAPPED;
}
WindowImpl::~WindowImpl()
{
- mHWndToListener.erase( mHWnd );
+ RemoveListener(mHWnd);
}
void WindowImpl::ProcWinMessage( uint64_t hWnd, uint32_t uMsg, uint64_t wParam, uint64_t lParam )
{
- std::map<uint64_t, WindowImpl*>::iterator x = mHWndToListener.find( hWnd );
+ std::map<uint64_t, WindowImpl*>::iterator x = sHWndToListener.find( hWnd );
- if( mHWndToListener.end() != x )
+ if( sHWndToListener.end() != x )
{
CallbackBase* listener = x->second->listener;
}
uint64_t WindowImpl::CreateHwnd(
- _In_opt_ const char *lpClassName,
_In_opt_ const char *lpWindowName,
_In_ int X,
_In_ int Y,
_In_ int nHeight,
_In_opt_ uint64_t parent )
{
- WNDCLASS cs = { 0 };
- cs.cbClsExtra = 0;
- cs.cbWndExtra = 0;
- cs.hbrBackground = (HBRUSH)( COLOR_WINDOW + 2 );
- cs.hCursor = NULL;
- cs.hIcon = NULL;
- cs.hInstance = GetModuleHandle( NULL );
- cs.lpfnWndProc = (WNDPROC)WinProc;
- cs.lpszClassName = lpClassName;
- cs.lpszMenuName = NULL;
- cs.style = CS_VREDRAW | CS_HREDRAW;
- RegisterClass( &cs );
-
- HWND hWnd = CreateWindow( lpClassName, lpWindowName, windowStyle, X, Y, nWidth + 2 * GetEdgeWidth(), nHeight + 2 * GetEdgeHeight(), NULL, NULL, cs.hInstance, NULL );
+ EnsureWindowClassRegistered();
+ ++sNumWindows;
+
+ HWND hWnd = CreateWindow( DALI_WINDOW_CLASS_NAME.c_str(), lpWindowName, STYLE, X, Y,
+ nWidth + 2 * EDGE_WIDTH, nHeight + 2 * EDGE_HEIGHT, NULL, NULL, GetModuleHandle(NULL), NULL );
::ShowWindow( hWnd, SW_SHOW );
- SetHWND( reinterpret_cast<uint64_t>(hWnd) );
+ return reinterpret_cast<uint64_t>(hWnd);
+}
- return mHWnd;
+void WindowImpl::DestroyHWnd(uint64_t hWnd)
+{
+ if (hWnd != 0)
+ {
+ ::DestroyWindow(reinterpret_cast<HWND>(hWnd));
+
+ --sNumWindows;
+ EnsureWindowClassUnregistered();
+ }
}
void WindowImpl::SetListener( CallbackBase *callback )
return (bool)PostMessage( reinterpret_cast<HWND>( mHWnd ), Msg, wParam, lParam );
}
-int32_t WindowImpl::GetEdgeWidth()
-{
- switch( windowStyle )
- {
- case WS_OVERLAPPED:
- {
- return 8;
- }
- default:
- {
- return 0;
- }
- }
-}
-
-int32_t WindowImpl::GetEdgeHeight()
-{
- switch( windowStyle )
- {
- case WS_OVERLAPPED:
- {
- return 18;
- }
- default:
- {
- return 0;
- }
- }
-}
-
void WindowImpl::SetHWND( uint64_t inHWnd )
{
if (mHWnd != inHWnd)
{
+ RemoveListener(mHWnd);
+
mHWnd = inHWnd;
mHdc = reinterpret_cast<uint64_t>(GetDC(reinterpret_cast<HWND>(mHWnd)));
colorDepth = GetDeviceCaps(reinterpret_cast<HDC>(mHdc), BITSPIXEL) * GetDeviceCaps(reinterpret_cast<HDC>(mHdc), PLANES);
- std::map<uint64_t, WindowImpl*>::iterator x = mHWndToListener.find(mHWnd);
-
- if (mHWndToListener.end() == x)
+ std::map<uint64_t, WindowImpl*>::iterator x = sHWndToListener.find(mHWnd);
+ if (sHWndToListener.end() == x)
{
- mHWndToListener.insert(std::make_pair(mHWnd, this));
+ sHWndToListener.insert(std::make_pair(mHWnd, this));
}
else
{
namespace Adaptor\r
{\r
\r
-namespace WindowsPlatformImplementation\r
+namespace WindowsPlatform\r
{\r
\r
bool PostWinThreadMessage(\r
class WindowImpl\r
{\r
public:\r
+ static const uint32_t STYLE;\r
+ static const int32_t EDGE_WIDTH;\r
+ static const int32_t EDGE_HEIGHT;\r
+\r
WindowImpl();\r
\r
virtual ~WindowImpl();\r
\r
static void ProcWinMessage( uint64_t hWnd, uint32_t uMsg, uint64_t wParam, uint64_t lParam );\r
\r
- void GetDPI( float &xDpi, float &yDpi );\r
-\r
- int GetColorDepth();\r
-\r
- uint64_t CreateHwnd(\r
- _In_opt_ const char *lpClassName,\r
+ static uint64_t CreateHwnd(\r
_In_opt_ const char *lpWindowName,\r
_In_ int X,\r
_In_ int Y,\r
_In_ int nHeight,\r
_In_opt_ uint64_t parent );\r
\r
+ static void DestroyHWnd(uint64_t hWnd);\r
+\r
+ void GetDPI( float &xDpi, float &yDpi );\r
+\r
+ int GetColorDepth();\r
+\r
void SetListener( CallbackBase *callback );\r
\r
bool PostWinMessage(\r
_In_ uint64_t wParam,\r
_In_ uint64_t lParam );\r
\r
- int32_t GetEdgeWidth();\r
-\r
- int32_t GetEdgeHeight();\r
-\r
void SetHWND(uint64_t inHWnd);\r
void SetWinProc();\r
\r
protected:\r
\r
private:\r
-\r
- unsigned long windowStyle;\r
-\r
int colorDepth;\r
- uint64_t mHWnd;\r
+ uint64_t mHWnd; // no ownership, managed outside\r
uint64_t mHdc;\r
\r
CallbackBase *listener;\r
Integration::Point point;
point.SetDeviceId( touchEvent.multi.device );
point.SetState( state );
- point.SetScreenPosition( Vector2( touchEvent.x, touchEvent.y + mWindowImpl.GetEdgeHeight() ) );
+ point.SetScreenPosition( Vector2( touchEvent.x, touchEvent.y + WindowsPlatform::WindowImpl::EDGE_HEIGHT ) );
point.SetRadius( touchEvent.multi.radius, Vector2( touchEvent.multi.radius_x, touchEvent.multi.radius_y ) );
point.SetPressure( touchEvent.multi.pressure );
point.SetAngle( Degree( touchEvent.multi.angle ) );
Integration::Point point;
point.SetDeviceId( touchEvent.multi.device );
point.SetState( state );
- point.SetScreenPosition( Vector2( touchEvent.x, touchEvent.y + mWindowImpl.GetEdgeHeight() ) );
+ point.SetScreenPosition( Vector2( touchEvent.x, touchEvent.y + WindowsPlatform::WindowImpl::EDGE_HEIGHT ) );
point.SetRadius( touchEvent.multi.radius, Vector2( touchEvent.multi.radius_x, touchEvent.multi.radius_y ) );
point.SetPressure( touchEvent.multi.pressure );
point.SetAngle( Degree( touchEvent.multi.angle ) );
Integration::Point point;
point.SetDeviceId( touchEvent.multi.device );
point.SetState( state );
- point.SetScreenPosition( Vector2( touchEvent.x, touchEvent.y + mWindowImpl.GetEdgeHeight() ) );
+ point.SetScreenPosition( Vector2( touchEvent.x, touchEvent.y + WindowsPlatform::WindowImpl::EDGE_HEIGHT) );
point.SetRadius( touchEvent.multi.radius, Vector2( touchEvent.multi.radius_x, touchEvent.multi.radius_y ) );
point.SetPressure( touchEvent.multi.pressure );
point.SetAngle( Degree( touchEvent.multi.angle ) );
DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseWin::OnKeyDown\n" );
int keyCode = event->wParam;
- std::string keyName( WindowsPlatformImplementation::GetKeyName( keyCode ) );
+ std::string keyName( WindowsPlatform::GetKeyName( keyCode ) );
std::string keyString;
std::string emptyString;
DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseWin::OnKeyDown\n" );
int keyCode = event->wParam;
- std::string keyName( WindowsPlatformImplementation::GetKeyName( keyCode ) );
+ std::string keyName( WindowsPlatform::GetKeyName( keyCode ) );
std::string keyString;
std::string emptyString;
void WindowBaseWin::CreateWinWindow( PositionSize positionSize, bool isTransparent )
{
- long hWnd = mWindowImpl.CreateHwnd( "Demo", "Demo", positionSize.x, positionSize.y, positionSize.width, positionSize.height, NULL );
+ long hWnd = WindowsPlatform::WindowImpl::CreateHwnd( "Demo", positionSize.x, positionSize.y, positionSize.width, positionSize.height, NULL );
+ mWindowImpl.SetHWND(hWnd);
mWin32Window = static_cast<WinWindowHandle>(hWnd);
bool mIsTransparent:1; ///< Whether the window is transparent (32 bit or 24 bit)
bool mRotationAppSet:1;
- WindowsPlatformImplementation::WindowImpl mWindowImpl;
+ WindowsPlatform::WindowImpl mWindowImpl;
};
} // namespace Adaptor