Skip to content

Commit a92922d

Browse files
徐扬斌coremail-cyt
authored andcommitted
wxOSX: Fix wxPopupTransientWindow's mouse event handling.
In MacOSX/cocoa, wxPopupTransientWindow needs to do mouse capture handling during OnIdle(). But it's done wrongly when decide whether the mouse is within the popup. Not fixed with simply checking the mouse pos against the client rect of the popup.
1 parent 41a1e0c commit a92922d

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/common/popupcmn.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -451,19 +451,23 @@ void wxPopupTransientWindow::OnIdle(wxIdleEvent& event)
451451

452452
if (IsShown() && m_child)
453453
{
454-
// Store the last mouse position to minimize the number of calls to
455-
// wxFindWindowAtPoint() which are quite expensive.
454+
// Store the last mouse position
456455
static wxPoint s_posLast;
457456
const wxPoint pos = wxGetMousePosition();
458457
if ( pos != s_posLast )
459458
{
460459
s_posLast = pos;
461-
462-
wxWindow* const winUnderMouse = wxFindWindowAtPoint(pos);
460+
461+
// DO NOT use wxFindWindowAtPoint() because if there're multiple top level windows,
462+
// it will 'Find the deepest window at the given mouse position in screen coordinates',
463+
// which is not the right one for this logic.
464+
auto screen_rect = GetScreenRect();
465+
const auto mouse_within_me = (pos.x >= screen_rect.GetTopLeft().x and pos.y >= screen_rect.GetTopLeft().y and
466+
pos.x <= screen_rect.GetBottomRight().x and pos.y <= screen_rect.GetBottomRight().y);
463467

464468
// We release the mouse capture while the mouse is inside the popup
465469
// itself to allow using it normally with the controls inside it.
466-
if ( wxGetTopLevelParent(winUnderMouse) == this )
470+
if ( mouse_within_me )
467471
{
468472
if ( m_child->HasCapture() )
469473
{

0 commit comments

Comments
 (0)