Replace the changes of r69938 with an alternative and simpler solution:
instead of playing games with gs_pendingFocus, which could break down if its
old value became invalid while the menu was shown as happened if one of the
menu commands resulted in this window being destroyed, just take the currently
shown popup menu into account in DoFindFocus() itself.
This should be safer as there is no danger of any dangling pointers here and
is also simpler and more obviously correct.
Closes #14103.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71313
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
#include "wx/tooltip.h"
#include "wx/caret.h"
#include "wx/fontutil.h"
#include "wx/tooltip.h"
#include "wx/caret.h"
#include "wx/fontutil.h"
-#include "wx/scopeguard.h"
#include "wx/sysopt.h"
#include <ctype.h>
#include "wx/sysopt.h"
#include <ctype.h>
wxWindow *wxWindowBase::DoFindFocus()
{
wxWindow *wxWindowBase::DoFindFocus()
{
+ // For compatibility with wxMSW, pretend that showing a popup menu doesn't
+ // change the focus and that it remains on the window showing it, even
+ // though the real focus does change in GTK.
+ extern wxMenu *wxCurrentPopupMenu;
+ if ( wxCurrentPopupMenu )
+ return wxCurrentPopupMenu->GetInvokingWindow();
+
wxWindowGTK *focus = gs_pendingFocus ? gs_pendingFocus : gs_currentFocus;
// the cast is necessary when we compile in wxUniversal mode
return static_cast<wxWindow*>(focus);
wxWindowGTK *focus = gs_pendingFocus ? gs_pendingFocus : gs_currentFocus;
// the cast is necessary when we compile in wxUniversal mode
return static_cast<wxWindow*>(focus);
{
wxCHECK_MSG( m_widget != NULL, false, wxT("invalid window") );
{
wxCHECK_MSG( m_widget != NULL, false, wxT("invalid window") );
- // For compatibility with other ports, pretend that the window showing the
- // menu has focus while the menu is shown. This is needed because the popup
- // menu actually steals the focus from the window it's associated it in
- // wxGTK unlike, say, wxMSW.
- wxWindowGTK* const oldPendingFocus = gs_pendingFocus;
- gs_pendingFocus = this;
- wxON_BLOCK_EXIT_SET( gs_pendingFocus, oldPendingFocus );
-
menu->UpdateUI();
wxPoint pos;
menu->UpdateUI();
wxPoint pos;