From 188309c53b2a759516024fef525e8f31fa07c6fc Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 25 Oct 2017 23:14:29 +0200 Subject: [PATCH] Repaint area covered by SingleChoicePopupMenu after showing it This is a workaround for a problem of the toolbar of the census view not repainting after selecting "Print roster to spreadsheet" from the popup menu shown by one of its toolbar button handlers. Unfortunately, this is somewhat of a hack, as it involves yielding, because neither Refresh()-ing nor even Update()-ing the native MSW toolbar control is sufficient to make it repaint immediately. At least we can only yield for the UI events, such as wxEVT_PAINT, and so don't run the risk of reentrancies due to getting some input event, as would be the case if we just called the global wxYield(). Also notice that, while this fix could be applied just to census_view.cpp, as the only other current use of SingleChoicePopupMenu is in docmanager_ex.cpp, where this problem doesn't arise, it seems more foresighted to do it here, to ensure that it never happens again even if this class is used elsewhere. --- single_choice_popup_menu.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/single_choice_popup_menu.cpp b/single_choice_popup_menu.cpp index 276b234a3..b424647b6 100644 --- a/single_choice_popup_menu.cpp +++ b/single_choice_popup_menu.cpp @@ -23,6 +23,7 @@ #include "single_choice_popup_menu.hpp" +#include #include SingleChoicePopupMenu::SingleChoicePopupMenu @@ -51,5 +52,15 @@ SingleChoicePopupMenu::SingleChoicePopupMenu int SingleChoicePopupMenu::Choose() { int const selection_index = parent_.GetPopupMenuSelectionFromUser(menu_); + + if (wxEventLoopBase* const loop = wxEventLoopBase::GetActive()) + { + // This function can often be used to get users choice before starting + // some time-consuming operation. Ensure that the area previously + // covered by the menu shown by GetPopupMenuSelectionFromUser() is + // repainted to avoid leaving it invalidated for a possibly long time. + loop->YieldFor(wxEVT_CATEGORY_UI); + } + return selection_index != wxID_NONE ? selection_index : -1; }