Commit d6476bcd authored by Sergey Radionov's avatar Sergey Radionov Committed by Jean-Baptiste Kempf

Win32: attach VlcControlsWnd to VLCHolderWnd

Signed-off-by: Jean-Baptiste Kempf's avatarJean-Baptiste Kempf <jb@videolan.org>
parent 0aa0f689
...@@ -655,6 +655,9 @@ LRESULT CALLBACK VLCHolderWnd::VLCHolderClassWndProc(HWND hWnd, UINT uMsg, WPARA ...@@ -655,6 +655,9 @@ LRESULT CALLBACK VLCHolderWnd::VLCHolderClassWndProc(HWND hWnd, UINT uMsg, WPARA
MoveWindow(hWnd, 0, 0, MoveWindow(hWnd, 0, 0,
(ParentClientRect.right-ParentClientRect.left), (ParentClientRect.right-ParentClientRect.left),
(ParentClientRect.bottom-ParentClientRect.top), FALSE); (ParentClientRect.bottom-ParentClientRect.top), FALSE);
h_data->_CtrlsWnd =
VLCControlsWnd::CreateControlsWindow(h_data->_hinstance, WM,
hWnd);
break; break;
} }
case WM_PAINT:{ case WM_PAINT:{
...@@ -668,6 +671,12 @@ LRESULT CALLBACK VLCHolderWnd::VLCHolderClassWndProc(HWND hWnd, UINT uMsg, WPARA ...@@ -668,6 +671,12 @@ LRESULT CALLBACK VLCHolderWnd::VLCHolderClassWndProc(HWND hWnd, UINT uMsg, WPARA
EndPaint(hWnd, &PaintStruct); EndPaint(hWnd, &PaintStruct);
break; break;
} }
case WM_SHOWWINDOW:{
if(FALSE!=wParam){ //showing
h_data->NeedShowControls();
}
break;
}
case WM_NCDESTROY: case WM_NCDESTROY:
delete h_data; delete h_data;
SetWindowLongPtr(hWnd, GWLP_USERDATA, 0); SetWindowLongPtr(hWnd, GWLP_USERDATA, 0);
...@@ -676,6 +685,19 @@ LRESULT CALLBACK VLCHolderWnd::VLCHolderClassWndProc(HWND hWnd, UINT uMsg, WPARA ...@@ -676,6 +685,19 @@ LRESULT CALLBACK VLCHolderWnd::VLCHolderClassWndProc(HWND hWnd, UINT uMsg, WPARA
h_data->MouseHook(true); h_data->MouseHook(true);
break; break;
} }
case WM_SIZE:
if(h_data->_CtrlsWnd){
int new_client_width = LOWORD(lParam);
int new_client_height = HIWORD(lParam);
RECT rect;
GetWindowRect(h_data->_CtrlsWnd->hWnd(), &rect);
MoveWindow(h_data->_CtrlsWnd->hWnd(),
0, new_client_height - (rect.bottom - rect.top),
new_client_width, (rect.bottom-rect.top), TRUE);
}
break;
case WM_MOUSEMOVE: case WM_MOUSEMOVE:
case WM_LBUTTONDBLCLK: case WM_LBUTTONDBLCLK:
h_data->_WindowsManager->OnMouseEvent(uMsg); h_data->_WindowsManager->OnMouseEvent(uMsg);
...@@ -693,6 +715,12 @@ LRESULT CALLBACK VLCHolderWnd::VLCHolderClassWndProc(HWND hWnd, UINT uMsg, WPARA ...@@ -693,6 +715,12 @@ LRESULT CALLBACK VLCHolderWnd::VLCHolderClassWndProc(HWND hWnd, UINT uMsg, WPARA
void VLCHolderWnd::DestroyWindow() void VLCHolderWnd::DestroyWindow()
{ {
LibVlcDetach(); LibVlcDetach();
if(_CtrlsWnd){
delete _CtrlsWnd;
_CtrlsWnd = 0;
}
if(_hWnd) if(_hWnd)
::DestroyWindow(_hWnd); ::DestroyWindow(_hWnd);
}; };
...@@ -730,14 +758,14 @@ LRESULT CALLBACK VLCHolderWnd::MouseHookProc(int nCode, WPARAM wParam, LPARAM lP ...@@ -730,14 +758,14 @@ LRESULT CALLBACK VLCHolderWnd::MouseHookProc(int nCode, WPARAM wParam, LPARAM lP
void VLCHolderWnd::MouseHook(bool SetHook) void VLCHolderWnd::MouseHook(bool SetHook)
{ {
if(SetHook){ if(SetHook){
const HWND hChildWnd = GetWindow(getHWND(), GW_CHILD); HWND hMPWnd = FindMP_hWnd();
const DWORD WndThreadID = (hChildWnd) ? GetWindowThreadProcessId(hChildWnd, NULL) : 0; const DWORD WndThreadID = (hMPWnd) ? GetWindowThreadProcessId(hMPWnd, NULL) : 0;
if( _hMouseHook &&( !hChildWnd || WndThreadID != _MouseHookThreadId) ){ if( _hMouseHook &&( !hMPWnd || WndThreadID != _MouseHookThreadId) ){
//unhook if something changed //unhook if something changed
MouseHook(false); MouseHook(false);
} }
if(!_hMouseHook && hChildWnd && WndThreadID){ if(!_hMouseHook && hMPWnd && WndThreadID){
_MouseHookThreadId = WndThreadID; _MouseHookThreadId = WndThreadID;
_hMouseHook = _hMouseHook =
SetWindowsHookEx(WH_MOUSE, VLCHolderWnd::MouseHookProc, SetWindowsHookEx(WH_MOUSE, VLCHolderWnd::MouseHookProc,
...@@ -753,6 +781,14 @@ void VLCHolderWnd::MouseHook(bool SetHook) ...@@ -753,6 +781,14 @@ void VLCHolderWnd::MouseHook(bool SetHook)
} }
} }
HWND VLCHolderWnd::FindMP_hWnd()
{
if(_CtrlsWnd)
return GetWindow(_CtrlsWnd->hWnd(), GW_HWNDNEXT);
else
return GetWindow(getHWND(), GW_CHILD);
}
//libvlc events arrives from separate thread //libvlc events arrives from separate thread
void VLCHolderWnd::OnLibVlcEvent(const libvlc_event_t* event) void VLCHolderWnd::OnLibVlcEvent(const libvlc_event_t* event)
{ {
...@@ -762,14 +798,21 @@ void VLCHolderWnd::OnLibVlcEvent(const libvlc_event_t* event) ...@@ -762,14 +798,21 @@ void VLCHolderWnd::OnLibVlcEvent(const libvlc_event_t* event)
//So we try catch events, //So we try catch events,
//(suppose wnd will be ever created), //(suppose wnd will be ever created),
//and then try set mouse hook. //and then try set mouse hook.
const HWND hChildWnd = GetWindow(getHWND(), GW_CHILD); HWND hMPWnd = FindMP_hWnd();
const DWORD WndThreadID = (hChildWnd) ? GetWindowThreadProcessId(hChildWnd, NULL) : 0; const DWORD WndThreadID = (hMPWnd) ? GetWindowThreadProcessId(hMPWnd, NULL) : 0;
//if no hook, or window thread has changed //if no hook, or window thread has changed
if(!_hMouseHook || (hChildWnd && WndThreadID != _MouseHookThreadId)){ if(!_hMouseHook || (hMPWnd && WndThreadID != _MouseHookThreadId)){
DWORD s = GetWindowLong(hMPWnd, GWL_STYLE);
s |= WS_CLIPSIBLINGS;
SetWindowLong(hMPWnd, GWL_STYLE, s);
//libvlc events arrives from separate thread, //libvlc events arrives from separate thread,
//so we need post message to main thread, to notify it. //so we need post message to main thread, to notify it.
PostMessage(getHWND(), WM_TRY_SET_MOUSE_HOOK, 0, 0); PostMessage(getHWND(), WM_TRY_SET_MOUSE_HOOK, 0, 0);
} }
if( _CtrlsWnd )
_CtrlsWnd->OnLibVlcEvent(event);
} }
void VLCHolderWnd::LibVlcAttach() void VLCHolderWnd::LibVlcAttach()
...@@ -1040,6 +1083,7 @@ void VLCWindowsManager::OnMouseEvent(UINT uMouseMsg) ...@@ -1040,6 +1083,7 @@ void VLCWindowsManager::OnMouseEvent(UINT uMouseMsg)
DWORD MsgPos = GetMessagePos(); DWORD MsgPos = GetMessagePos();
if(Last_WM_MOUSEMOVE_Pos != MsgPos){ if(Last_WM_MOUSEMOVE_Pos != MsgPos){
Last_WM_MOUSEMOVE_Pos = MsgPos; Last_WM_MOUSEMOVE_Pos = MsgPos;
_HolderWnd->NeedShowControls();
} }
break; break;
} }
......
...@@ -143,6 +143,9 @@ public: ...@@ -143,6 +143,9 @@ public:
void LibVlcAttach(); void LibVlcAttach();
void LibVlcDetach(); void LibVlcDetach();
void NeedShowControls()
{ if(_CtrlsWnd) _CtrlsWnd->NeedShowControls(); }
//libvlc events arrives from separate thread //libvlc events arrives from separate thread
void OnLibVlcEvent(const libvlc_event_t* event); void OnLibVlcEvent(const libvlc_event_t* event);
...@@ -151,6 +154,8 @@ private: ...@@ -151,6 +154,8 @@ private:
static LRESULT CALLBACK VLCHolderClassWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); static LRESULT CALLBACK VLCHolderClassWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
static LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam); static LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam);
HWND FindMP_hWnd();
HHOOK _hMouseHook; HHOOK _hMouseHook;
DWORD _MouseHookThreadId; DWORD _MouseHookThreadId;
void MouseHook(bool SetHook); void MouseHook(bool SetHook);
...@@ -167,7 +172,7 @@ private: ...@@ -167,7 +172,7 @@ private:
private: private:
VLCHolderWnd(HWND hWnd, VLCWindowsManager* WM) VLCHolderWnd(HWND hWnd, VLCWindowsManager* WM)
: _hMouseHook(NULL), _MouseHookThreadId(0), _hWnd(hWnd), : _hMouseHook(NULL), _MouseHookThreadId(0), _hWnd(hWnd),
_WindowsManager(WM){}; _WindowsManager(WM), _CtrlsWnd(0) {};
public: public:
HWND getHWND() const {return _hWnd;} HWND getHWND() const {return _hWnd;}
...@@ -175,6 +180,7 @@ public: ...@@ -175,6 +180,7 @@ public:
private: private:
HWND _hWnd; HWND _hWnd;
VLCWindowsManager* _WindowsManager; VLCWindowsManager* _WindowsManager;
VLCControlsWnd* _CtrlsWnd;
}; };
/////////////////////// ///////////////////////
......
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