From 33fe475aeb7ad2bd10bcfc3e79dcfff220b9a3a9 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Mon, 7 Mar 2005 17:25:29 +0000 Subject: [PATCH] This fixes a problem in the two tree and list controls that are trigger if the user app shows dialog in reaction to the user pressing e.g. . The edit text control will lose focus and emit another event. Might be possible to fix without adding another field, but this way it surely works. Also added correction to treecontrol as per listcontrol in the situation when a label change happens by losing the focus and the user cannot reject it, another event is emitted. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32632 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/generic/listctrl.cpp | 7 ++++--- src/generic/treectlg.cpp | 13 ++++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index 120bdf489a..1126d66902 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -494,6 +494,7 @@ private: wxString m_startValue; size_t m_itemEdited; bool m_finished; + bool m_aboutToFinish; DECLARE_EVENT_TABLE() }; @@ -2032,6 +2033,7 @@ wxListTextCtrl::wxListTextCtrl(wxListMainWindow *owner, size_t itemEdit) { m_owner = owner; m_finished = false; + m_aboutToFinish = false; wxRect rectLabel = owner->GetLineLabelRect(itemEdit); @@ -2082,12 +2084,11 @@ void wxListTextCtrl::OnChar( wxKeyEvent &event ) switch ( event.m_keyCode ) { case WXK_RETURN: + m_aboutToFinish = true; // Notify the owner about the changes AcceptChanges(); - // Even if vetoed, close the control (consistent with MSW) Finish(); - break; case WXK_ESCAPE: @@ -2136,7 +2137,7 @@ void wxListTextCtrl::OnKillFocus( wxFocusEvent &event ) } // We must let the native text control handle focus, too, otherwise - // it could have problems with the cursor (e.g., in wxGTK): + // it could have problems with the cursor (e.g., in wxGTK). event.Skip(); } diff --git a/src/generic/treectlg.cpp b/src/generic/treectlg.cpp index 728cbe2f54..5a6c21a1b3 100644 --- a/src/generic/treectlg.cpp +++ b/src/generic/treectlg.cpp @@ -108,6 +108,7 @@ private: wxGenericTreeItem *m_itemEdited; wxString m_startValue; bool m_finished; + bool m_aboutToFinish; DECLARE_EVENT_TABLE() DECLARE_NO_COPY_CLASS(wxTreeTextCtrl) @@ -341,6 +342,7 @@ wxTreeTextCtrl::wxTreeTextCtrl(wxGenericTreeCtrl *owner, { m_owner = owner; m_finished = false; + m_aboutToFinish = false; int w = m_itemEdited->GetWidth(), h = m_itemEdited->GetHeight(); @@ -413,7 +415,7 @@ bool wxTreeTextCtrl::AcceptChanges() void wxTreeTextCtrl::Finish() { - if ( !m_finished ) + if ( !m_finished && !m_aboutToFinish ) { m_owner->ResetTextControl(); @@ -430,12 +432,11 @@ void wxTreeTextCtrl::OnChar( wxKeyEvent &event ) switch ( event.m_keyCode ) { case WXK_RETURN: + m_aboutToFinish = true; // Notify the owner about the changes AcceptChanges(); - // Even if vetoed, close the control (consistent with MSW) Finish(); - break; case WXK_ESCAPE: @@ -471,14 +472,16 @@ void wxTreeTextCtrl::OnKillFocus( wxFocusEvent &event ) { if ( !m_finished ) { - AcceptChanges(); // We must finish regardless of success, otherwise we'll get // focus problems: Finish(); + + if ( !AcceptChanges() ) + m_owner->OnRenameCancelled( m_itemEdited ); } // We must let the native text control handle focus, too, otherwise - // it could have problems with the cursor (e.g., in wxGTK): + // it could have problems with the cursor (e.g., in wxGTK). event.Skip(); } -- 2.45.2