From 6bc4157b6e9c6a32ee79d6629ead47aa46cf3dc5 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 13 Feb 2008 23:07:30 +0000 Subject: [PATCH] use header window coordinates when searching for the right-clicked column (bug 1879009) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@51774 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/listctrl.cpp | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index d39d80529a..cb686ebf52 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -1862,28 +1862,40 @@ bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) // where did the click occur? POINT ptClick; #if defined(__WXWINCE__) && !defined(__HANDHELDPC__) && _WIN32_WCE < 400 - if(nmhdr->code == GN_CONTEXTMENU) { - ptClick = ((NMRGINFO*)nmhdr)->ptAction; - } else + if ( nmhdr->code == GN_CONTEXTMENU ) + { + ptClick = ((NMRGINFO*)nmhdr)->ptAction; + } + else #endif //__WXWINCE__ if ( !::GetCursorPos(&ptClick) ) { wxLogLastError(_T("GetCursorPos")); } - if ( !::ScreenToClient(GetHwnd(), &ptClick) ) + // we need to use listctrl coordinates for the event point + // but for comparison with Header_GetItemRect() result + // below we need to use header window coordinates + POINT ptClickList = ptClick; + if ( ::ScreenToClient(GetHwnd(), &ptClickList) ) + { + event.m_pointDrag.x = ptClickList.x; + event.m_pointDrag.y = ptClickList.y; + } + else + { + wxLogLastError(_T("ScreenToClient(listctrl)")); + } + + if ( !::ScreenToClient(hwndHdr, &ptClick) ) { wxLogLastError(_T("ScreenToClient(listctrl header)")); } - event.m_pointDrag.x = ptClick.x; - event.m_pointDrag.y = ptClick.y; - - int colCount = Header_GetItemCount(hwndHdr); - - RECT rect; + const int colCount = Header_GetItemCount(hwndHdr); for ( int col = 0; col < colCount; col++ ) { + RECT rect; if ( Header_GetItemRect(hwndHdr, col, &rect) ) { if ( ::PtInRect(&rect, ptClick) )