From 3dbfe8f44f6ff4f3b888b59111ff51dad45fb060 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 16 Jan 2006 02:31:40 +0000 Subject: [PATCH] reset g_SelectionBeforePopup sooner in gtk_popup_hide_callback() to ensure that GetSelection() returns the new selection when called from wxEVT_COMMAND_COMBOBOX_SELECTED handler git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@36890 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/gtk/combobox.cpp | 15 ++++++++++----- src/gtk1/combobox.cpp | 15 ++++++++++----- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/gtk/combobox.cpp b/src/gtk/combobox.cpp index 6c967b58be..517993327f 100644 --- a/src/gtk/combobox.cpp +++ b/src/gtk/combobox.cpp @@ -75,8 +75,16 @@ gtk_popup_hide_callback(GtkCombo *WXUNUSED(gtk_combo), wxComboBox *combo) { // when the popup is hidden, throw a SELECTED event only if the combobox // selection changed. - int curSelection = combo->GetCurrentSelection(); - if (g_SelectionBeforePopup != curSelection) + const int curSelection = combo->GetCurrentSelection(); + + const bool hasChanged = curSelection != g_SelectionBeforePopup; + + // reset the selection flag to value meaning that it is hidden and do it + // now, before generating the events, so that GetSelection() returns the + // new value from the event handler + g_SelectionBeforePopup = wxID_NONE; + + if ( hasChanged ) { wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, combo->GetId() ); event.SetInt( curSelection ); @@ -90,9 +98,6 @@ gtk_popup_hide_callback(GtkCombo *WXUNUSED(gtk_combo), wxComboBox *combo) event2.SetEventObject( combo ); combo->GetEventHandler()->ProcessEvent( event2 ); } - - // reset the selection flag to value meaning that it is hidden - g_SelectionBeforePopup = wxID_NONE; } } diff --git a/src/gtk1/combobox.cpp b/src/gtk1/combobox.cpp index 6c967b58be..517993327f 100644 --- a/src/gtk1/combobox.cpp +++ b/src/gtk1/combobox.cpp @@ -75,8 +75,16 @@ gtk_popup_hide_callback(GtkCombo *WXUNUSED(gtk_combo), wxComboBox *combo) { // when the popup is hidden, throw a SELECTED event only if the combobox // selection changed. - int curSelection = combo->GetCurrentSelection(); - if (g_SelectionBeforePopup != curSelection) + const int curSelection = combo->GetCurrentSelection(); + + const bool hasChanged = curSelection != g_SelectionBeforePopup; + + // reset the selection flag to value meaning that it is hidden and do it + // now, before generating the events, so that GetSelection() returns the + // new value from the event handler + g_SelectionBeforePopup = wxID_NONE; + + if ( hasChanged ) { wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, combo->GetId() ); event.SetInt( curSelection ); @@ -90,9 +98,6 @@ gtk_popup_hide_callback(GtkCombo *WXUNUSED(gtk_combo), wxComboBox *combo) event2.SetEventObject( combo ); combo->GetEventHandler()->ProcessEvent( event2 ); } - - // reset the selection flag to value meaning that it is hidden - g_SelectionBeforePopup = wxID_NONE; } } -- 2.50.0