Corrected wxTreeCtrl and wxListCtrl end_label_edit event behaviour.

wxListCtrl doesn't send this event when the editing was cancelled.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21756 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2003-07-08 11:24:52 +00:00
parent aaaa609fa3
commit 865864592a
2 changed files with 32 additions and 4 deletions

View File

@@ -577,6 +577,7 @@ public:
void OnRenameTimer(); void OnRenameTimer();
bool OnRenameAccept(size_t itemEdit, const wxString& value); bool OnRenameAccept(size_t itemEdit, const wxString& value);
void OnRenameCancelled(size_t itemEdit);
void OnMouse( wxMouseEvent &event ); void OnMouse( wxMouseEvent &event );
@@ -2105,6 +2106,7 @@ void wxListTextCtrl::OnChar( wxKeyEvent &event )
case WXK_ESCAPE: case WXK_ESCAPE:
Finish(); Finish();
m_owner->OnRenameCancelled( m_itemEdited );
break; break;
default: default:
@@ -2139,9 +2141,11 @@ void wxListTextCtrl::OnKillFocus( wxFocusEvent &event )
{ {
if ( !m_finished ) if ( !m_finished )
{ {
(void)AcceptChanges(); // We must finish regardless of success, otherwise we'll get focus problems
Finish(); Finish();
if ( !AcceptChanges() )
m_owner->OnRenameCancelled( m_itemEdited );
} }
event.Skip(); event.Skip();
@@ -2887,6 +2891,30 @@ bool wxListMainWindow::OnRenameAccept(size_t itemEdit, const wxString& value)
le.IsAllowed(); le.IsAllowed();
} }
void wxListMainWindow::OnRenameCancelled(size_t itemEdit)
{
// wxMSW seems not to notify the program about
// cancelled label edits.
return;
// 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 ) void wxListMainWindow::OnMouse( wxMouseEvent &event )
{ {
event.SetEventObject( GetParent() ); event.SetEventObject( GetParent() );

View File

@@ -2928,7 +2928,7 @@ void wxGenericTreeCtrl::OnRenameCancelled(wxGenericTreeItem *item)
le.m_item = (long) item; le.m_item = (long) item;
le.SetEventObject( this ); le.SetEventObject( this );
le.m_label = wxEmptyString; le.m_label = wxEmptyString;
le.m_editCancelled = FALSE; le.m_editCancelled = TRUE;
GetEventHandler()->ProcessEvent( le ); GetEventHandler()->ProcessEvent( le );
} }