]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/treebase.cpp
fixing overrelease and out-of-bounds write, fixes #13725
[wxWidgets.git] / src / common / treebase.cpp
index 06e31ddbc3e3979dab634f4f170d855d1e3f29b0..f831b489adf30e4aa3c9d1e2bd49f4ce16ff0ecb 100644 (file)
@@ -179,6 +179,8 @@ wxTreeCtrlBase::wxTreeCtrlBase()
 
     // quick DoGetBestSize calculation
     m_quickBestSize = true;
+
+    Connect(wxEVT_CHAR_HOOK, wxKeyEventHandler(wxTreeCtrlBase::OnCharHook));
 }
 
 wxTreeCtrlBase::~wxTreeCtrlBase()
@@ -349,4 +351,26 @@ bool wxTreeCtrlBase::IsEmpty() const
     return !GetRootItem().IsOk();
 }
 
+void wxTreeCtrlBase::OnCharHook(wxKeyEvent& event)
+{
+    if ( GetEditControl() )
+    {
+        bool discardChanges = false;
+        switch ( event.GetKeyCode() )
+        {
+            case WXK_ESCAPE:
+                discardChanges = true;
+                // fall through
+
+            case WXK_RETURN:
+                EndEditLabel(GetFocusedItem(), discardChanges);
+
+                // Do not call Skip() below.
+                return;
+        }
+    }
+
+    event.Skip();
+}
+
 #endif // wxUSE_TREECTRL