]> git.saurik.com Git - wxWidgets.git/commitdiff
Corrected wxTreeCtrl and wxListCtrl end_label_edit event behaviour.
authorRobert Roebling <robert@roebling.de>
Tue, 8 Jul 2003 11:24:52 +0000 (11:24 +0000)
committerRobert Roebling <robert@roebling.de>
Tue, 8 Jul 2003 11:24:52 +0000 (11:24 +0000)
    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

src/generic/listctrl.cpp
src/generic/treectlg.cpp

index c80ade054d17a0f82bfad14db991648651d94fba..93a76fd0fd30f087a99bb83e2c7e4116fecc42b6 100644 (file)
@@ -577,6 +577,7 @@ public:
 
     void OnRenameTimer();
     bool OnRenameAccept(size_t itemEdit, const wxString& value);
+    void OnRenameCancelled(size_t itemEdit);
 
     void OnMouse( wxMouseEvent &event );
 
@@ -2105,6 +2106,7 @@ void wxListTextCtrl::OnChar( wxKeyEvent &event )
 
         case WXK_ESCAPE:
             Finish();
+            m_owner->OnRenameCancelled( m_itemEdited );
             break;
 
         default:
@@ -2139,11 +2141,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();
 }
 
@@ -2887,6 +2891,30 @@ bool wxListMainWindow::OnRenameAccept(size_t itemEdit, const wxString& value)
                 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 )
 {
     event.SetEventObject( GetParent() );
index f2134ffc897536ca1db819768e4ab91fa6096390..9255fb67cbfda708bfa5ddba409b02da0a6bf40b 100644 (file)
@@ -2928,7 +2928,7 @@ 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 );
 }