Commit a66bbe1e authored by Erwan Tulou's avatar Erwan Tulou

skins(Win32): Process events in the winProc (instead of the message loop)

Events like WM_PAINT should be processed in the WinProc, because
some functions directly call the WinProc (e.g UpdateWindow())
parent a38c6d0f
......@@ -45,7 +45,8 @@
#define MY_WM_TRAYACTION (WM_APP + 1)
LRESULT CALLBACK Win32Proc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
LRESULT CALLBACK Win32Factory::Win32Proc( HWND hwnd, UINT uMsg,
WPARAM wParam, LPARAM lParam )
{
// Get pointer to thread info: should only work with the parent window
intf_thread_t *p_intf = (intf_thread_t *)GetWindowLongPtr( hwnd,
......@@ -58,6 +59,7 @@ LRESULT CALLBACK Win32Proc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
}
Win32Factory *pFactory = (Win32Factory*)Win32Factory::instance( p_intf );
GenericWindow *pWin = pFactory->m_windowMap[hwnd];
if( hwnd == pFactory->getParentWindow() )
{
......@@ -92,19 +94,29 @@ LRESULT CALLBACK Win32Proc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
p_intf->p_sys->p_theme->getWindowManager().raiseAll();
CmdDlgHidePopupMenu aCmdPopup( p_intf );
aCmdPopup.execute();
return 0;
}
else if( (UINT)lParam == WM_RBUTTONDOWN )
{
CmdDlgShowPopupMenu aCmdPopup( p_intf );
aCmdPopup.execute();
return 0;
}
else if( (UINT)lParam == WM_LBUTTONDBLCLK )
{
CmdRestore aCmdRestore( p_intf );
aCmdRestore.execute();
return 0;
}
}
}
else if( pWin )
{
Win32Loop* pLoop =
(Win32Loop*) OSFactory::instance( p_intf )->getOSLoop();
if( pLoop )
return pLoop->processEvent( hwnd, uMsg, wParam, lParam );
}
// If hwnd does not match any window or message not processed
return DefWindowProc( hwnd, uMsg, wParam, lParam );
......@@ -131,7 +143,7 @@ bool Win32Factory::init()
// Create window class
WNDCLASS skinWindowClass;
skinWindowClass.style = CS_DBLCLKS;
skinWindowClass.lpfnWndProc = (WNDPROC) Win32Proc;
skinWindowClass.lpfnWndProc = (WNDPROC)Win32Factory::Win32Proc;
skinWindowClass.lpszClassName = _T("SkinWindowClass");
skinWindowClass.lpszMenuName = NULL;
skinWindowClass.cbClsExtra = 0;
......@@ -325,7 +337,6 @@ OSPopup *Win32Factory::createOSPopup()
int Win32Factory::getScreenWidth() const
{
return GetSystemMetrics(SM_CXSCREEN);
}
......
......@@ -118,6 +118,10 @@ public:
HWND getParentWindow() { return m_hParentWindow; }
/// Callback function (Windows Procedure)
static LRESULT CALLBACK Win32Proc( HWND hwnd, UINT uMsg,
WPARAM wParam, LPARAM lParam );
private:
/// Handle of the instance
HINSTANCE m_hInst;
......
......@@ -119,38 +119,40 @@ void Win32Loop::run()
// Compute windows message list
while( GetMessage( &msg, NULL, 0, 0 ) )
{
Win32Factory *pFactory =
(Win32Factory*)Win32Factory::instance( getIntf() );
GenericWindow *pWin = pFactory->m_windowMap[msg.hwnd];
if( pWin == NULL )
{
// We are probably getting a message for a tooltip (which has no
// associated GenericWindow), for a timer, or for the parent window
TranslateMessage( &msg );
DispatchMessage( &msg );
continue;
}
}
LRESULT CALLBACK Win32Loop::processEvent( HWND hwnd, UINT msg,
WPARAM wParam, LPARAM lParam )
{
Win32Factory *pFactory =
(Win32Factory*)Win32Factory::instance( getIntf() );
GenericWindow *pWin = pFactory->m_windowMap[hwnd];
GenericWindow &win = *pWin;
switch( msg.message )
switch( msg )
{
case WM_PAINT:
{
PAINTSTRUCT Infos;
BeginPaint( msg.hwnd, &Infos );
BeginPaint( hwnd, &Infos );
EvtRefresh evt( getIntf(),
Infos.rcPaint.left,
Infos.rcPaint.top,
Infos.rcPaint.right - Infos.rcPaint.left + 1,
Infos.rcPaint.bottom - Infos.rcPaint.top + 1 );
EndPaint( msg.hwnd, &Infos );
win.processEvent( evt );
break;
EndPaint( hwnd, &Infos );
return 0;
}
case WM_COMMAND:
{
EvtMenu evt( getIntf(), LOWORD( msg.wParam ) );
EvtMenu evt( getIntf(), LOWORD( wParam ) );
win.processEvent( evt );
break;
return 0;
}
case WM_MOUSEMOVE:
{
......@@ -158,29 +160,29 @@ void Win32Loop::run()
TRACKMOUSEEVENT TrackEvent;
TrackEvent.cbSize = sizeof( TRACKMOUSEEVENT );
TrackEvent.dwFlags = TME_LEAVE;
TrackEvent.hwndTrack = msg.hwnd;
TrackEvent.hwndTrack = hwnd;
TrackEvent.dwHoverTime = 1;
TrackMouseEvent( &TrackEvent );
// Compute the absolute position of the mouse
int x = GET_X_LPARAM( msg.lParam ) + win.getLeft();
int y = GET_Y_LPARAM( msg.lParam ) + win.getTop();
int x = GET_X_LPARAM( lParam ) + win.getLeft();
int y = GET_Y_LPARAM( lParam ) + win.getTop();
EvtMotion evt( getIntf(), x, y );
win.processEvent( evt );
break;
return 0;
}
case WM_MOUSELEAVE:
{
EvtLeave evt( getIntf() );
win.processEvent( evt );
break;
return 0;
}
case WM_MOUSEWHEEL:
{
int x = GET_X_LPARAM( msg.lParam ) - win.getLeft();
int y = GET_Y_LPARAM( msg.lParam ) - win.getTop();
int mod = getMod( msg.wParam );
if( GET_WHEEL_DELTA_WPARAM( msg.wParam ) > 0 )
int x = GET_X_LPARAM( lParam ) - win.getLeft();
int y = GET_Y_LPARAM( lParam ) - win.getTop();
int mod = getMod( wParam );
if( GET_WHEEL_DELTA_WPARAM( wParam ) > 0 )
{
EvtScroll evt( getIntf(), x, y, EvtScroll::kUp, mod );
win.processEvent( evt );
......@@ -190,61 +192,61 @@ void Win32Loop::run()
EvtScroll evt( getIntf(), x, y, EvtScroll::kDown, mod );
win.processEvent( evt );
}
break;
return 0;
}
case WM_LBUTTONDOWN:
{
SetCapture( msg.hwnd );
EvtMouse evt( getIntf(), GET_X_LPARAM( msg.lParam ),
GET_Y_LPARAM( msg.lParam ), EvtMouse::kLeft,
EvtMouse::kDown, getMod( msg.wParam ) );
SetCapture( hwnd );
EvtMouse evt( getIntf(), GET_X_LPARAM( lParam ),
GET_Y_LPARAM( lParam ), EvtMouse::kLeft,
EvtMouse::kDown, getMod( wParam ) );
win.processEvent( evt );
break;
return 0;
}
case WM_RBUTTONDOWN:
{
SetCapture( msg.hwnd );
EvtMouse evt( getIntf(), GET_X_LPARAM( msg.lParam ),
GET_Y_LPARAM( msg.lParam ), EvtMouse::kRight,
EvtMouse::kDown, getMod( msg.wParam ) );
SetCapture( hwnd );
EvtMouse evt( getIntf(), GET_X_LPARAM( lParam ),
GET_Y_LPARAM( lParam ), EvtMouse::kRight,
EvtMouse::kDown, getMod( wParam ) );
win.processEvent( evt );
break;
return 0;
}
case WM_LBUTTONUP:
{
ReleaseCapture();
EvtMouse evt( getIntf(), GET_X_LPARAM( msg.lParam ),
GET_Y_LPARAM( msg.lParam ), EvtMouse::kLeft,
EvtMouse::kUp, getMod( msg.wParam ) );
EvtMouse evt( getIntf(), GET_X_LPARAM( lParam ),
GET_Y_LPARAM( lParam ), EvtMouse::kLeft,
EvtMouse::kUp, getMod( wParam ) );
win.processEvent( evt );
break;
return 0;
}
case WM_RBUTTONUP:
{
ReleaseCapture();
EvtMouse evt( getIntf(), GET_X_LPARAM( msg.lParam ),
GET_Y_LPARAM( msg.lParam ), EvtMouse::kRight,
EvtMouse::kUp, getMod( msg.wParam ) );
EvtMouse evt( getIntf(), GET_X_LPARAM( lParam ),
GET_Y_LPARAM( lParam ), EvtMouse::kRight,
EvtMouse::kUp, getMod( wParam ) );
win.processEvent( evt );
break;
return 0;
}
case WM_LBUTTONDBLCLK:
{
ReleaseCapture();
EvtMouse evt( getIntf(), GET_X_LPARAM( msg.lParam ),
GET_Y_LPARAM( msg.lParam ), EvtMouse::kLeft,
EvtMouse::kDblClick, getMod( msg.wParam ) );
EvtMouse evt( getIntf(), GET_X_LPARAM( lParam ),
GET_Y_LPARAM( lParam ), EvtMouse::kLeft,
EvtMouse::kDblClick, getMod( wParam ) );
win.processEvent( evt );
break;
return 0;
}
case WM_RBUTTONDBLCLK:
{
ReleaseCapture();
EvtMouse evt( getIntf(), GET_X_LPARAM( msg.lParam ),
GET_Y_LPARAM( msg.lParam ), EvtMouse::kRight,
EvtMouse::kDblClick, getMod( msg.wParam ) );
EvtMouse evt( getIntf(), GET_X_LPARAM( lParam ),
GET_Y_LPARAM( lParam ), EvtMouse::kRight,
EvtMouse::kDblClick, getMod( wParam ) );
win.processEvent( evt );
break;
return 0;
}
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
......@@ -256,11 +258,11 @@ void Win32Loop::run()
// the modifier keys.
// Get VLC key code from the virtual key code
int key = virtKeyToVlcKey[msg.wParam];
int key = virtKeyToVlcKey[wParam];
if( !key )
{
// This appears to be a "normal" (ascii) key
key = tolower( MapVirtualKey( msg.wParam, 2 ) );
key = tolower( MapVirtualKey( wParam, 2 ) );
}
if( key )
......@@ -282,8 +284,8 @@ void Win32Loop::run()
// Get the state
EvtKey::ActionType_t state;
if( msg.message == WM_KEYDOWN ||
msg.message == WM_SYSKEYDOWN )
if( msg == WM_KEYDOWN ||
msg == WM_SYSKEYDOWN )
{
state = EvtKey::kDown;
}
......@@ -295,13 +297,12 @@ void Win32Loop::run()
EvtKey evt( getIntf(), key, state, mod );
win.processEvent( evt );
}
break;
return 0;
}
default:
TranslateMessage( &msg );
DispatchMessage( &msg );
}
break;
}
return DefWindowProc( hwnd, msg, wParam, lParam );;
}
......
......@@ -48,6 +48,10 @@ public:
/// Exit the main loop
virtual void exit();
/// called by the window procedure callback
virtual LRESULT CALLBACK processEvent( HWND hwnd, UINT msg,
WPARAM wParam, LPARAM lParam );
private:
// Private because it is a singleton
Win32Loop( intf_thread_t *pIntf );
......
......@@ -69,8 +69,10 @@ Win32Window::Win32Window( intf_thread_t *pIntf, GenericWindow &rWindow,
m_hWnd = CreateWindowEx( WS_EX_APPWINDOW, "SkinWindowClass",
"default name", WS_POPUP | WS_CLIPCHILDREN,
0, 0, 0, 0, NULL, 0, hInst, NULL );
}
// Store with it a pointer to the interface thread
SetWindowLongPtr( m_hWnd, GWLP_USERDATA, (LONG_PTR)getIntf() );
}
else
{
// top-level window (owned by the root window)
......@@ -78,6 +80,9 @@ Win32Window::Win32Window( intf_thread_t *pIntf, GenericWindow &rWindow,
m_hWnd = CreateWindowEx( 0, "SkinWindowClass",
"default name", WS_POPUP | WS_CLIPCHILDREN,
0, 0, 0, 0, hWnd_owner, 0, hInst, NULL );
// Store with it a pointer to the interface thread
SetWindowLongPtr( m_hWnd, GWLP_USERDATA, (LONG_PTR)getIntf() );
}
if( !m_hWnd )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment