Fall back on ::GetMessagePos() if ::GetCursorPos() fails under MSW.
In some rare but reproducible cases GetCursorPos() can fail and return without filling in the provided point. Fall back to GetMessagePos() if this happens: this is not ideal but clearly better than using uninitialized position or hard coding something like (0, 0). Closes #13664. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@69758 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -923,6 +923,9 @@ WXDLLIMPEXP_BASE wxWinVersion wxGetWinVersion();
|
||||
extern HCURSOR wxGetCurrentBusyCursor(); // from msw/utils.cpp
|
||||
extern const wxCursor *wxGetGlobalCursor(); // from msw/cursor.cpp
|
||||
|
||||
// GetCursorPos can fail without populating the POINT. This falls back to GetMessagePos.
|
||||
WXDLLIMPEXP_CORE void wxGetCursorPosMSW(POINT* pt);
|
||||
|
||||
WXDLLIMPEXP_CORE void wxGetCharSize(WXHWND wnd, int *x, int *y, const wxFont& the_font);
|
||||
WXDLLIMPEXP_CORE void wxFillLogFont(LOGFONT *logFont, const wxFont *font);
|
||||
WXDLLIMPEXP_CORE wxFont wxCreateFontFromLogFont(const LOGFONT *logFont);
|
||||
|
@@ -1905,9 +1905,8 @@ int WXDLLIMPEXP_CORE wxMSWGetColumnClicked(NMHDR *nmhdr, POINT *ptClick)
|
||||
}
|
||||
else
|
||||
#endif //__WXWINCE__
|
||||
if ( !::GetCursorPos(ptClick) )
|
||||
{
|
||||
wxLogLastError(wxT("GetCursorPos"));
|
||||
wxGetCursorPosMSW(ptClick);
|
||||
}
|
||||
|
||||
// we need to use listctrl coordinates for the event point so this is what
|
||||
@@ -2323,7 +2322,7 @@ bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
|
||||
else
|
||||
#endif //__WXWINCE__
|
||||
{
|
||||
::GetCursorPos(&(lvhti.pt));
|
||||
wxGetCursorPosMSW(&(lvhti.pt));
|
||||
}
|
||||
|
||||
::ScreenToClient(GetHwnd(), &lvhti.pt);
|
||||
|
@@ -3645,7 +3645,7 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
|
||||
case NM_RCLICK:
|
||||
{
|
||||
TV_HITTESTINFO tvhti;
|
||||
::GetCursorPos(&tvhti.pt);
|
||||
wxGetCursorPosMSW(&tvhti.pt);
|
||||
::ScreenToClient(GetHwnd(), &tvhti.pt);
|
||||
if ( TreeView_HitTest(GetHwnd(), &tvhti) )
|
||||
{
|
||||
|
@@ -49,7 +49,7 @@ DWORD EventTypeForMouseButton(int button, bool isDown)
|
||||
bool wxUIActionSimulator::MouseDown(int button)
|
||||
{
|
||||
POINT p;
|
||||
GetCursorPos(&p);
|
||||
wxGetCursorPosMSW(&p);
|
||||
mouse_event(EventTypeForMouseButton(button, true), p.x, p.y, 0, 0);
|
||||
return true;
|
||||
}
|
||||
@@ -71,7 +71,7 @@ bool wxUIActionSimulator::MouseMove(long x, long y)
|
||||
bool wxUIActionSimulator::MouseUp(int button)
|
||||
{
|
||||
POINT p;
|
||||
GetCursorPos(&p);
|
||||
wxGetCursorPosMSW(&p);
|
||||
mouse_event(EventTypeForMouseButton(button, false), p.x, p.y, 0, 0);
|
||||
return true;
|
||||
}
|
||||
|
@@ -113,7 +113,7 @@ bool wxCheckForInterrupt(wxWindow *wnd)
|
||||
void wxGetMousePosition( int* x, int* y )
|
||||
{
|
||||
POINT pt;
|
||||
GetCursorPos( & pt );
|
||||
wxGetCursorPosMSW( & pt );
|
||||
if ( x ) *x = pt.x;
|
||||
if ( y ) *y = pt.y;
|
||||
}
|
||||
|
@@ -321,20 +321,23 @@ static void EnsureParentHasControlParentStyle(wxWindow *parent)
|
||||
|
||||
#endif // !__WXWINCE__
|
||||
|
||||
#ifdef __WXWINCE__
|
||||
// On Windows CE, GetCursorPos can return an error, so use this function
|
||||
// instead
|
||||
bool GetCursorPosWinCE(POINT* pt)
|
||||
// GetCursorPos can return an error, so use this function
|
||||
// instead.
|
||||
// Error originally observed with WinCE, but later using Remote Desktop
|
||||
// to connect to XP.
|
||||
void wxGetCursorPosMSW(POINT* pt)
|
||||
{
|
||||
if (!GetCursorPos(pt))
|
||||
{
|
||||
DWORD pos = GetMessagePos();
|
||||
pt->x = LOWORD(pos);
|
||||
pt->y = HIWORD(pos);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#ifdef __WXWINCE__
|
||||
wxLogLastError(wxT("GetCursorPos"));
|
||||
#endif
|
||||
DWORD pos = GetMessagePos();
|
||||
// the coordinates may be negative in multi-monitor systems
|
||||
pt->x = GET_X_LPARAM(pos);
|
||||
pt->y = GET_Y_LPARAM(pos);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// event tables
|
||||
@@ -852,11 +855,7 @@ bool wxWindowMSW::SetCursor(const wxCursor& cursor)
|
||||
HWND hWnd = GetHwnd();
|
||||
|
||||
POINT point;
|
||||
#ifdef __WXWINCE__
|
||||
::GetCursorPosWinCE(&point);
|
||||
#else
|
||||
::GetCursorPos(&point);
|
||||
#endif
|
||||
::wxGetCursorPosMSW(&point);
|
||||
|
||||
RECT rect = wxGetWindowRect(hWnd);
|
||||
|
||||
@@ -875,11 +874,7 @@ bool wxWindowMSW::SetCursor(const wxCursor& cursor)
|
||||
// under the cursor and ask it to set its cursor itself as only it
|
||||
// knows what it is.
|
||||
POINT pt;
|
||||
if ( !::GetCursorPos(&pt) )
|
||||
{
|
||||
wxLogLastError(wxT("GetCursorPos"));
|
||||
return false;
|
||||
}
|
||||
wxGetCursorPosMSW(&pt);
|
||||
|
||||
const wxWindowMSW* win = wxFindWindowAtPoint(wxPoint(pt.x, pt.y));
|
||||
if ( !win )
|
||||
@@ -1517,11 +1512,7 @@ bool wxWindowMSW::IsMouseInWindow() const
|
||||
{
|
||||
// get the mouse position
|
||||
POINT pt;
|
||||
#ifdef __WXWINCE__
|
||||
::GetCursorPosWinCE(&pt);
|
||||
#else
|
||||
::GetCursorPos(&pt);
|
||||
#endif
|
||||
wxGetCursorPosMSW(&pt);
|
||||
|
||||
// find the window which currently has the cursor and go up the window
|
||||
// chain until we find this window - or exhaust it
|
||||
@@ -4204,14 +4195,7 @@ bool wxWindowMSW::HandleSetCursor(WXHWND WXUNUSED(hWnd),
|
||||
// first ask the user code - it may wish to set the cursor in some very
|
||||
// specific way (for example, depending on the current position)
|
||||
POINT pt;
|
||||
#ifdef __WXWINCE__
|
||||
if ( !::GetCursorPosWinCE(&pt))
|
||||
#else
|
||||
if ( !::GetCursorPos(&pt) )
|
||||
#endif
|
||||
{
|
||||
wxLogLastError(wxT("GetCursorPos"));
|
||||
}
|
||||
wxGetCursorPosMSW(&pt);
|
||||
|
||||
int x = pt.x,
|
||||
y = pt.y;
|
||||
@@ -5628,14 +5612,7 @@ void wxWindowMSW::GenerateMouseLeave()
|
||||
state |= MK_RBUTTON;
|
||||
|
||||
POINT pt;
|
||||
#ifdef __WXWINCE__
|
||||
if ( !::GetCursorPosWinCE(&pt) )
|
||||
#else
|
||||
if ( !::GetCursorPos(&pt) )
|
||||
#endif
|
||||
{
|
||||
wxLogLastError(wxT("GetCursorPos"));
|
||||
}
|
||||
wxGetCursorPosMSW(&pt);
|
||||
|
||||
// we need to have client coordinates here for symmetry with
|
||||
// wxEVT_ENTER_WINDOW
|
||||
@@ -6521,7 +6498,7 @@ wxMouseState wxGetMouseState()
|
||||
{
|
||||
wxMouseState ms;
|
||||
POINT pt;
|
||||
GetCursorPos( &pt );
|
||||
wxGetCursorPosMSW(&pt);
|
||||
|
||||
ms.SetX(pt.x);
|
||||
ms.SetY(pt.y);
|
||||
@@ -7224,11 +7201,7 @@ wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
|
||||
wxPoint wxGetMousePosition()
|
||||
{
|
||||
POINT pt;
|
||||
#ifdef __WXWINCE__
|
||||
GetCursorPosWinCE(&pt);
|
||||
#else
|
||||
GetCursorPos( & pt );
|
||||
#endif
|
||||
wxGetCursorPosMSW(&pt);
|
||||
|
||||
return wxPoint(pt.x, pt.y);
|
||||
}
|
||||
|
Reference in New Issue
Block a user