]> git.saurik.com Git - wxWidgets.git/commitdiff
use listctrl coordinates for the wxEVT_COMMAND_LIST_COL_RIGHT_CLICK events (this...
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 13 Feb 2008 23:16:04 +0000 (23:16 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 13 Feb 2008 23:16:04 +0000 (23:16 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51776 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/msw/listctrl.cpp

index a32c13669629cdab8e934e580dbff383f8b0ad93..6b0b8c4666006997e13015a9f661c3a60168e3fb 100644 (file)
@@ -1863,15 +1863,12 @@ bool wxListCtrl::MSWCommand(WXUINT cmd, WXWORD id_)
 // utility used by wxListCtrl::MSWOnNotify and by wxDataViewHeaderWindowMSW::MSWOnNotify
 int WXDLLIMPEXP_CORE wxMSWGetColumnClicked(NMHDR *nmhdr, POINT *ptClick)
 {
 // utility used by wxListCtrl::MSWOnNotify and by wxDataViewHeaderWindowMSW::MSWOnNotify
 int WXDLLIMPEXP_CORE wxMSWGetColumnClicked(NMHDR *nmhdr, POINT *ptClick)
 {
-    wxASSERT(nmhdr && ptClick);
-
-    // find the column clicked: we have to search for it
-    // ourselves as the notification message doesn't provide
-    // this info
+    // find the column clicked: we have to search for it ourselves as the
+    // notification message doesn't provide this info
 
     // where did the click occur?
 #if defined(__WXWINCE__) && !defined(__HANDHELDPC__) && _WIN32_WCE < 400
 
     // where did the click occur?
 #if defined(__WXWINCE__) && !defined(__HANDHELDPC__) && _WIN32_WCE < 400
-    if (nmhdr->code == GN_CONTEXTMENU)
+    if ( nmhdr->code == GN_CONTEXTMENU )
     {
         *ptClick = ((NMRGINFO*)nmhdr)->ptAction;
     }
     {
         *ptClick = ((NMRGINFO*)nmhdr)->ptAction;
     }
@@ -1882,19 +1879,27 @@ int WXDLLIMPEXP_CORE wxMSWGetColumnClicked(NMHDR *nmhdr, POINT *ptClick)
         wxLogLastError(_T("GetCursorPos"));
     }
 
         wxLogLastError(_T("GetCursorPos"));
     }
 
-    if ( !::ScreenToClient(nmhdr->hwndFrom, ptClick) )
+    // we need to use listctrl coordinates for the event point so this is what
+    // we return in ptClick, but for comparison with Header_GetItemRect()
+    // result below we need to use header window coordinates
+    POINT ptClickHeader = *ptClick;
+    if ( !::ScreenToClient(nmhdr->hwndFrom, &ptClickHeader) )
     {
     {
-        wxLogLastError(_T("ScreenToClient(header)"));
+        wxLogLastError(_T("ScreenToClient(listctrl header)"));
     }
 
     }
 
-    int colCount = Header_GetItemCount(nmhdr->hwndFrom);
+    if ( !::ScreenToClient(::GetParent(nmhdr->hwndFrom), ptClick) )
+    {
+        wxLogLastError(_T("ScreenToClient(listctrl)"));
+    }
 
 
-    RECT rect;
+    const int colCount = Header_GetItemCount(nmhdr->hwndFrom);
     for ( int col = 0; col < colCount; col++ )
     {
     for ( int col = 0; col < colCount; col++ )
     {
+        RECT rect;
         if ( Header_GetItemRect(nmhdr->hwndFrom, col, &rect) )
         {
         if ( Header_GetItemRect(nmhdr->hwndFrom, col, &rect) )
         {
-            if ( ::PtInRect(&rect, *ptClick) )
+            if ( ::PtInRect(&rect, ptClickHeader) )
             {
                 return col;
             }
             {
                 return col;
             }