]> git.saurik.com Git - wxWidgets.git/commitdiff
don't send clicked event for wxID_CANCEL button when Esc is pressed unless such butto...
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 7 Sep 2002 14:25:03 +0000 (14:25 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 7 Sep 2002 14:25:03 +0000 (14:25 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@17044 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/gtk/window.cpp
src/gtk1/window.cpp

index 30dfae29e094b9f9f9a2d24dbf7cc910a743a902..6411fca957539f7392571af10dc4856a6b83dee3 100644 (file)
@@ -1174,9 +1174,37 @@ static gint gtk_window_key_press_callback( GtkWidget *widget,
     if ( !ret &&
          (gdk_event->keyval == GDK_Escape) )
     {
-        wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL);
-        new_event.SetEventObject( win );
-        ret = win->GetEventHandler()->ProcessEvent( new_event );
+        // however only do it if we have a Cancel button in the dialog,
+        // otherwise the user code may get confused by the events from a
+        // non-existing button and, worse, a wxButton might get button event
+        // from another button which is not really expected
+        wxWindow *winForCancel = win,
+                 *btnCancel = NULL;
+        while ( winForCancel )
+        {
+            btnCancel = winForCancel->FindWindow(wxID_CANCEL);
+            if ( btnCancel )
+            {
+                // found a cancel button
+                break;
+            }
+
+            if ( winForCancel->IsTopLevel() )
+            {
+                // no need to look further
+                break;
+            }
+
+            // maybe our parent has a cancel button?
+            winForCancel = winForCancel->GetParent();
+        }
+
+        if ( btnCancel )
+        {
+            wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
+            event.SetEventObject(btnCancel);
+            ret = btnCancel->GetEventHandler()->ProcessEvent(event);
+        }
     }
 
     // Doesn't work.
index 30dfae29e094b9f9f9a2d24dbf7cc910a743a902..6411fca957539f7392571af10dc4856a6b83dee3 100644 (file)
@@ -1174,9 +1174,37 @@ static gint gtk_window_key_press_callback( GtkWidget *widget,
     if ( !ret &&
          (gdk_event->keyval == GDK_Escape) )
     {
-        wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL);
-        new_event.SetEventObject( win );
-        ret = win->GetEventHandler()->ProcessEvent( new_event );
+        // however only do it if we have a Cancel button in the dialog,
+        // otherwise the user code may get confused by the events from a
+        // non-existing button and, worse, a wxButton might get button event
+        // from another button which is not really expected
+        wxWindow *winForCancel = win,
+                 *btnCancel = NULL;
+        while ( winForCancel )
+        {
+            btnCancel = winForCancel->FindWindow(wxID_CANCEL);
+            if ( btnCancel )
+            {
+                // found a cancel button
+                break;
+            }
+
+            if ( winForCancel->IsTopLevel() )
+            {
+                // no need to look further
+                break;
+            }
+
+            // maybe our parent has a cancel button?
+            winForCancel = winForCancel->GetParent();
+        }
+
+        if ( btnCancel )
+        {
+            wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
+            event.SetEventObject(btnCancel);
+            ret = btnCancel->GetEventHandler()->ProcessEvent(event);
+        }
     }
 
     // Doesn't work.