]> git.saurik.com Git - wxWidgets.git/commitdiff
Fix wxListCtrl::EndEditLabel() which simply didn't work.
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 20 May 2010 22:04:03 +0000 (22:04 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 20 May 2010 22:04:03 +0000 (22:04 +0000)
Also document it (even though it's wxMSW-only for now) and add a test for it
in the sample.

Closes #7663.

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

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

index 9a6ddd739bd683c57ef756d4ab91e5518279ccf5..bfa9b019bce850d0c23bbba99551374dc9bc31a9 100644 (file)
@@ -247,6 +247,23 @@ public:
     wxTextCtrl* EditLabel(long item,
                           wxClassInfo* textControlClass = CLASSINFO(wxTextCtrl));
 
+    /**
+        Finish editing the label.
+
+        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.
+
+        Currently only implemented in wxMSW.
+
+        @param cancel If @true, discard the changes made by user, as if @c
+            Escape key was pressed. Otherwise, accept the changes as if @c
+            Return was pressed.
+        @return @true if item editing wad finished or @false if no item as
+            being edited.
+     */
+    bool EndEditLabel(bool cancel);
+
     /**
         Ensures this item is visible.
     */
index bf2ef2c376383075d31b5e099447bce882c4d2a3..4cf75b240684842a73c3eed7f3f1ad14342f12ef 100644 (file)
@@ -840,16 +840,26 @@ void MyFrame::OnAdd(wxCommandEvent& WXUNUSED(event))
 
 void MyFrame::OnEdit(wxCommandEvent& WXUNUSED(event))
 {
-    long itemCur = m_listCtrl->GetNextItem(-1, wxLIST_NEXT_ALL,
-                                           wxLIST_STATE_FOCUSED);
-
-    if ( itemCur != -1 )
+    // demonstrate cancelling editing: this currently is wxMSW-only
+#ifdef __WXMSW__
+    if ( m_listCtrl->GetEditControl() )
     {
-        m_listCtrl->EditLabel(itemCur);
+        m_listCtrl->EndEditLabel(true);
     }
-    else
+    else // start editing
+#endif // __WXMSW__
     {
-        m_logWindow->WriteText(wxT("No item to edit"));
+        long itemCur = m_listCtrl->GetNextItem(-1, wxLIST_NEXT_ALL,
+                                               wxLIST_STATE_FOCUSED);
+
+        if ( itemCur != -1 )
+        {
+            m_listCtrl->EditLabel(itemCur);
+        }
+        else
+        {
+            m_logWindow->WriteText(wxT("No item to edit"));
+        }
     }
 }
 
index f688344557a5a9d67b5e6342ae41243c393aabd9..ec5add16ea163eeb5e53ed93b8d4a757d3ad2184 100644 (file)
@@ -1561,14 +1561,10 @@ bool wxListCtrl::EndEditLabel(bool cancel)
     if ( !hwnd )
         return false;
 
-    if ( cancel )
-        ::SetWindowText(hwnd, wxEmptyString); // dubious but better than nothing
-
-    // we shouldn't destroy the control ourselves according to MSDN, which
-    // proposes WM_CANCELMODE to do this, but it doesn't seem to work
-    //
-    // posting WM_CLOSE to it does seem to work without any side effects
-    ::PostMessage(hwnd, WM_CLOSE, 0, 0);
+    // 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;
 }