Make wxGTK code returning correct focus in popup menu presence more robust.
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
This commit is contained in:
parent
7e7ba0dfc5
commit
39258ad796
@ -31,7 +31,6 @@
|
||||
#include "wx/tooltip.h"
|
||||
#include "wx/caret.h"
|
||||
#include "wx/fontutil.h"
|
||||
#include "wx/scopeguard.h"
|
||||
#include "wx/sysopt.h"
|
||||
|
||||
#include <ctype.h>
|
||||
@ -2062,6 +2061,13 @@ void wxWindowGTK::GTKHandleRealized()
|
||||
|
||||
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);
|
||||
@ -4210,14 +4216,6 @@ bool wxWindowGTK::DoPopupMenu( wxMenu *menu, int x, int y )
|
||||
{
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user