summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
3e6807d)
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
extern HCURSOR wxGetCurrentBusyCursor(); // from msw/utils.cpp
extern const wxCursor *wxGetGlobalCursor(); // from msw/cursor.cpp
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);
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);
}
else
#endif //__WXWINCE__
}
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
}
// we need to use listctrl coordinates for the event point so this is what
else
#endif //__WXWINCE__
{
else
#endif //__WXWINCE__
{
- ::GetCursorPos(&(lvhti.pt));
+ wxGetCursorPosMSW(&(lvhti.pt));
}
::ScreenToClient(GetHwnd(), &lvhti.pt);
}
::ScreenToClient(GetHwnd(), &lvhti.pt);
case NM_RCLICK:
{
TV_HITTESTINFO tvhti;
case NM_RCLICK:
{
TV_HITTESTINFO tvhti;
- ::GetCursorPos(&tvhti.pt);
+ wxGetCursorPosMSW(&tvhti.pt);
::ScreenToClient(GetHwnd(), &tvhti.pt);
if ( TreeView_HitTest(GetHwnd(), &tvhti) )
{
::ScreenToClient(GetHwnd(), &tvhti.pt);
if ( TreeView_HitTest(GetHwnd(), &tvhti) )
{
bool wxUIActionSimulator::MouseDown(int button)
{
POINT p;
bool wxUIActionSimulator::MouseDown(int button)
{
POINT p;
mouse_event(EventTypeForMouseButton(button, true), p.x, p.y, 0, 0);
return true;
}
mouse_event(EventTypeForMouseButton(button, true), p.x, p.y, 0, 0);
return true;
}
bool wxUIActionSimulator::MouseUp(int button)
{
POINT p;
bool wxUIActionSimulator::MouseUp(int button)
{
POINT p;
mouse_event(EventTypeForMouseButton(button, false), p.x, p.y, 0, 0);
return true;
}
mouse_event(EventTypeForMouseButton(button, false), p.x, p.y, 0, 0);
return true;
}
void wxGetMousePosition( int* x, int* y )
{
POINT pt;
void wxGetMousePosition( int* x, int* y )
{
POINT pt;
+ wxGetCursorPosMSW( & pt );
if ( x ) *x = pt.x;
if ( y ) *y = pt.y;
}
if ( x ) *x = pt.x;
if ( y ) *y = pt.y;
}
-#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))
{
{
if (!GetCursorPos(pt))
{
+#ifdef __WXWINCE__
+ wxLogLastError(wxT("GetCursorPos"));
+#endif
DWORD pos = GetMessagePos();
DWORD pos = GetMessagePos();
- pt->x = LOWORD(pos);
- pt->y = HIWORD(pos);
+ // the coordinates may be negative in multi-monitor systems
+ pt->x = GET_X_LPARAM(pos);
+ pt->y = GET_Y_LPARAM(pos);
// ---------------------------------------------------------------------------
// event tables
// ---------------------------------------------------------------------------
// event tables
HWND hWnd = GetHwnd();
POINT point;
HWND hWnd = GetHwnd();
POINT point;
-#ifdef __WXWINCE__
- ::GetCursorPosWinCE(&point);
-#else
- ::GetCursorPos(&point);
-#endif
+ ::wxGetCursorPosMSW(&point);
RECT rect = wxGetWindowRect(hWnd);
RECT rect = wxGetWindowRect(hWnd);
// under the cursor and ask it to set its cursor itself as only it
// knows what it is.
POINT pt;
// 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 )
const wxWindowMSW* win = wxFindWindowAtPoint(wxPoint(pt.x, pt.y));
if ( !win )
{
// get the mouse position
POINT pt;
{
// 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
// find the window which currently has the cursor and go up the window
// chain until we find this window - or exhaust it
// 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;
// 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);
state |= MK_RBUTTON;
POINT pt;
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
// we need to have client coordinates here for symmetry with
// wxEVT_ENTER_WINDOW
{
wxMouseState ms;
POINT pt;
{
wxMouseState ms;
POINT pt;
+ wxGetCursorPosMSW(&pt);
ms.SetX(pt.x);
ms.SetY(pt.y);
ms.SetX(pt.x);
ms.SetY(pt.y);
wxPoint wxGetMousePosition()
{
POINT pt;
wxPoint wxGetMousePosition()
{
POINT pt;
-#ifdef __WXWINCE__
- GetCursorPosWinCE(&pt);
-#else
- GetCursorPos( & pt );
-#endif
+ wxGetCursorPosMSW(&pt);
return wxPoint(pt.x, pt.y);
}
return wxPoint(pt.x, pt.y);
}