don't send clicked event for wxID_CANCEL button when Esc is pressed unless such button really exists (and then send it to the right window!)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@17044 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2002-09-07 14:25:03 +00:00
parent aa5b885706
commit 6ce16bdb55
2 changed files with 62 additions and 6 deletions

View 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.

View 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.