From 152ec01122a888b1f161c404faa8fc42b5035838 Mon Sep 17 00:00:00 2001 From: ali kettab Date: Sun, 14 Jan 2024 23:23:27 +0100 Subject: [PATCH] Fix wxEVT_SET_CURSOR handling under wxQt Really fix wxSetCursorEvent handling for wxAUI done in commit f608b34 (Send set cursor events whenever there is mouse movement) without breaking the other controls, i.e. wxSplitterWindow, wxHeaderCtrl and wxGrid. Pass the mouse position by const reference to QtSendSetCursorEvent(). Closes #24217. --- include/wx/qt/window.h | 2 +- src/qt/window.cpp | 34 ++++++++++++++++++++-------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/include/wx/qt/window.h b/include/wx/qt/window.h index b0f55efb33..adcaf6b48d 100644 --- a/include/wx/qt/window.h +++ b/include/wx/qt/window.h @@ -167,7 +167,7 @@ public: static void QtStoreWindowPointer( QWidget *widget, const wxWindowQt *window ); static wxWindowQt *QtRetrieveWindowPointer( const QWidget *widget ); - static void QtSendSetCursorEvent(wxWindowQt* win, wxPoint posClient); + static void QtSendSetCursorEvent(wxWindowQt* win, const wxPoint& posClient); #if wxUSE_ACCEL virtual void QtHandleShortcut ( int command ); diff --git a/src/qt/window.cpp b/src/qt/window.cpp index 16974f8b2e..085fbcf99b 100644 --- a/src/qt/window.cpp +++ b/src/qt/window.cpp @@ -271,27 +271,33 @@ static const char WINDOW_POINTER_PROPERTY_NAME[] = "wxWindowPointer"; } /* static */ -void wxWindowQt::QtSendSetCursorEvent(wxWindowQt* win, wxPoint posScreen) +void wxWindowQt::QtSendSetCursorEvent(wxWindowQt* win, const wxPoint& posClient) { - wxWindowQt* w = win; - for ( ;; ) - { - const wxPoint posClient = w->ScreenToClient(posScreen); - wxSetCursorEvent event(posClient.x, posClient.y); - event.SetEventObject(w); + const wxRect rect(win->GetClientAreaOrigin(), win->GetClientSize()); - const bool processedEvtSetCursor = w->ProcessWindowEvent(event); + if ( rect.Contains(posClient) ) + { + wxSetCursorEvent event( posClient.x , posClient.y ); + event.SetId(win->GetId()); + event.SetEventObject(win); + + const bool processedEvtSetCursor = win->HandleWindowEvent(event); if ( processedEvtSetCursor && event.HasCursor() ) { win->SetCursor(event.GetCursor()); - return; } + else + { + // Notice that GetCursor() can return an invalid cursor even if the window already + // has a valid cursor set at the Qt level. Don't override it if this is the case. + const bool hasCursor = win->GetHandle()->testAttribute(Qt::WA_SetCursor); - w = w->GetParent(); - if ( w == nullptr ) - break; + if ( !hasCursor || (!wxIsBusy() && !win->GetParent()) ) + { + win->SetCursor( *wxSTANDARD_CURSOR ); + } + } } - win->SetCursor(wxCursor(wxCURSOR_ARROW)); } static wxWindowQt *s_capturedWindow = nullptr; @@ -1686,7 +1692,7 @@ bool wxWindowQt::QtHandleMouseEvent ( QWidget *handler, QMouseEvent *event ) ProcessWindowEvent( e ); } - QtSendSetCursorEvent(this, wxQtConvertPoint( event->globalPos())); + QtSendSetCursorEvent(this, mousePos); } m_mouseInside = mouseInside;