diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index e19066a622..bcc0851715 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -652,6 +652,7 @@ public: void OnRenameTimer(); bool OnRenameAccept(size_t itemEdit, const wxString& value); + void OnRenameCancelled(size_t itemEdit); void OnMouse( wxMouseEvent &event ); @@ -2302,6 +2303,7 @@ void wxListTextCtrl::OnChar( wxKeyEvent &event ) case WXK_ESCAPE: Finish(); + m_owner->OnRenameCancelled( m_itemEdited ); break; default: @@ -2336,11 +2338,13 @@ void wxListTextCtrl::OnKillFocus( wxFocusEvent &event ) { if ( !m_finished ) { - (void)AcceptChanges(); - + // We must finish regardless of success, otherwise we'll get focus problems Finish(); + + if ( !AcceptChanges() ) + m_owner->OnRenameCancelled( m_itemEdited ); } - + event.Skip(); } @@ -3072,6 +3076,11 @@ void wxListMainWindow::OnRenameTimer() bool wxListMainWindow::OnRenameAccept(size_t itemEdit, const wxString& value) { wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() ); + + // These only exist for wxTreeCtrl, which should probably be changed + // le.m_editCancelled = FALSE; + // le.m_label = value; + le.SetEventObject( GetParent() ); le.m_itemIndex = itemEdit; @@ -3080,10 +3089,31 @@ bool wxListMainWindow::OnRenameAccept(size_t itemEdit, const wxString& value) data->GetItem( 0, le.m_item ); le.m_item.m_text = value; + return !GetParent()->GetEventHandler()->ProcessEvent( le ) || le.IsAllowed(); } +void wxListMainWindow::OnRenameCancelled(size_t itemEdit) +{ + // let owner know that the edit was cancelled + wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() ); + + // These only exist for wxTreeCtrl, which should probably be changed + // le.m_editCancelled = TRUE; + // le.m_label = wxEmptyString; + + le.SetEventObject( GetParent() ); + le.m_itemIndex = itemEdit; + + wxListLineData *data = GetLine(itemEdit); + wxCHECK_RET( data, _T("invalid index in OnRenameCancelled()") ); + + data->GetItem( 0, le.m_item ); + + GetEventHandler()->ProcessEvent( le ); +} + void wxListMainWindow::OnMouse( wxMouseEvent &event ) { event.SetEventObject( GetParent() ); diff --git a/src/generic/treectlg.cpp b/src/generic/treectlg.cpp index 9d03079f86..081b429940 100644 --- a/src/generic/treectlg.cpp +++ b/src/generic/treectlg.cpp @@ -485,16 +485,16 @@ void wxTreeTextCtrl::OnKeyUp( wxKeyEvent &event ) void wxTreeTextCtrl::OnKillFocus( wxFocusEvent &event ) { - if ( m_finished ) - { - event.Skip(); - return; - } - - if ( AcceptChanges() ) + if ( !m_finished ) { + // We must finish regardless of success, otherwise we'll get focus problems Finish(); + + if ( !AcceptChanges() ) + m_owner->OnRenameCancelled( m_itemEdited ); } + + event.Skip(); } // ----------------------------------------------------------------------------- @@ -2900,14 +2900,11 @@ void wxGenericTreeCtrl::OnRenameCancelled(wxGenericTreeItem *item) le.m_item = (long) item; le.SetEventObject( this ); le.m_label = wxEmptyString; - le.m_editCancelled = FALSE; + le.m_editCancelled = TRUE; GetEventHandler()->ProcessEvent( le ); } - - - void wxGenericTreeCtrl::OnRenameTimer() { Edit( m_current );