]> git.saurik.com Git - wxWidgets.git/commitdiff
Use ListView_CancelEditLabel() to implement wxListCtrl::EndEditLabel().
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 21 May 2010 13:17:25 +0000 (13:17 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 21 May 2010 13:17:25 +0000 (13:17 +0000)
Windows XP and later finally added a special message to cancel label editing,
use it if available.

Also improve the documentation of this method.

See #7663.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64374 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

interface/wx/listctrl.h
src/msw/listctrl.cpp

index bfa9b019bce850d0c23bbba99551374dc9bc31a9..c8650246b3977f5f2ee4ed98d6cf98322a85edcb 100644 (file)
@@ -252,7 +252,13 @@ public:
 
         This method allows to programmatically end editing a list control item
         in place. Usually it will only be called when editing is in progress,
-        i.e. if GetEditControl() returns non-NULL.
+        i.e. if GetEditControl() returns non-NULL. In particular, do not call
+        it from EVT_LIST_BEGIN_LABEL_EDIT handler as the edit control is not
+        yet fully created by then, just veto the event in this handler instead
+        to prevent the editing from even starting.
+
+        Notice that calling this method will result in EVT_LIST_END_LABEL_EDIT
+        event being generated.
 
         Currently only implemented in wxMSW.
 
index ec5add16ea163eeb5e53ed93b8d4a757d3ad2184..5e0e786436e6b86ca9f8fe93fcf0d00e98090cb3 100644 (file)
@@ -1561,10 +1561,21 @@ bool wxListCtrl::EndEditLabel(bool cancel)
     if ( !hwnd )
         return false;
 
-    // We shouldn't destroy the control ourselves according to MSDN, which
-    // proposes WM_CANCELMODE to do this, but it doesn't seem to work so
-    // emulate the corresponding user action instead.
-    ::SendMessage(hwnd, WM_KEYDOWN, cancel ? VK_ESCAPE : VK_RETURN, 0);
+    // Newer versions of Windows have a special message for cancelling editing,
+    // use it if available.
+#ifdef ListView_CancelEditLabel
+    if ( cancel && (wxApp::GetComCtl32Version() >= 600) )
+    {
+        ListView_CancelEditLabel(GetHwnd());
+    }
+    else
+#endif // ListView_CancelEditLabel
+    {
+        // We shouldn't destroy the control ourselves according to MSDN, which
+        // proposes WM_CANCELMODE to do this, but it doesn't seem to work so
+        // emulate the corresponding user action instead.
+        ::SendMessage(hwnd, WM_KEYDOWN, cancel ? VK_ESCAPE : VK_RETURN, 0);
+    }
 
     return true;
 }