#include <windowsx.h>
#endif
-#if !defined __WXWINCE__ && !defined NEED_PBT_H
- #include <pbt.h>
-#endif
-
#if defined(__WXWINCE__)
#include "wx/msw/wince/missing.h"
#ifdef __POCKETPC__
// This is a hack used by the owner-drawn wxButton implementation to ensure
// that the brush used for erasing its background is correctly aligned with the
// control.
-extern wxWindowMSW *wxWindowBeingErased = NULL;
+wxWindowMSW *wxWindowBeingErased = NULL;
#endif // wxUSE_UXTHEME
namespace
#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))
{
+#ifdef __WXWINCE__
+ wxLogLastError(wxT("GetCursorPos"));
+#endif
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);
}
- return true;
}
-#endif
// ---------------------------------------------------------------------------
// event tables
return true;
}
+
bool wxWindowMSW::SetCursor(const wxCursor& cursor)
{
if ( !wxWindowBase::SetCursor(cursor) )
}
// don't "overwrite" busy cursor
- if ( m_cursor.IsOk() && !wxIsBusy() )
+ if ( wxIsBusy() )
+ return true;
+
+ if ( m_cursor.IsOk() )
{
// normally we should change the cursor only if it's over this window
// but we should do it always if we capture the mouse currently
HWND hWnd = GetHwnd();
POINT point;
-#ifdef __WXWINCE__
- ::GetCursorPosWinCE(&point);
-#else
- ::GetCursorPos(&point);
-#endif
+ ::wxGetCursorPosMSW(&point);
RECT rect = wxGetWindowRect(hWnd);
}
//else: will be set later when the mouse enters this window
}
+ else // Invalid cursor: this means reset to the default one.
+ {
+ // To revert to the correct cursor we need to find the window currently
+ // under the cursor and ask it to set its cursor itself as only it
+ // knows what it is.
+ POINT pt;
+ wxGetCursorPosMSW(&pt);
+
+ const wxWindowMSW* win = wxFindWindowAtPoint(wxPoint(pt.x, pt.y));
+ if ( !win )
+ win = this;
+
+ ::SendMessage(GetHwndOf(win), WM_SETCURSOR,
+ (WPARAM)GetHwndOf(win),
+ MAKELPARAM(HTCLIENT, WM_MOUSEMOVE));
+ }
return true;
}
{
// 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
{
menu->UpdateUI();
+ wxPoint pt;
if ( x == wxDefaultCoord && y == wxDefaultCoord )
{
- wxPoint mouse = ScreenToClient(wxGetMousePosition());
- x = mouse.x; y = mouse.y;
+ pt = wxGetMousePosition();
+ }
+ else
+ {
+ pt = ClientToScreen(wxPoint(x, y));
}
- HWND hWnd = GetHwnd();
- HMENU hMenu = GetHmenuOf(menu);
- POINT point;
- point.x = x;
- point.y = y;
- ::ClientToScreen(hWnd, &point);
#if defined(__WXWINCE__)
static const UINT flags = 0;
#else // !__WXWINCE__
}
#endif // __WXWINCE__/!__WXWINCE__
- ::TrackPopupMenu(hMenu, flags, point.x, point.y, 0, hWnd, NULL);
+ ::TrackPopupMenu(GetHmenuOf(menu), flags, pt.x, pt.y, 0, GetHwnd(), NULL);
// we need to do it right now as otherwise the events are never going to be
// sent to wxCurrentPopupMenu from HandleCommand()
// emulate the button click
btn = wxFindWinFromHandle(msg->hwnd);
}
-
- bProcess = false;
}
else // not a button itself, do we have default button?
{
return true;
}
+ // This "Return" key press won't be actually used for
+ // navigation so don't generate wxNavigationKeyEvent
+ // for it but still pass it to IsDialogMessage() as it
+ // may handle it in some other way (e.g. by playing the
+ // default error sound).
+ bProcess = false;
+
#endif // wxUSE_BUTTON
#ifdef __WXWINCE__
return rc;
}
-WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
+bool
+wxWindowMSW::MSWHandleMessage(WXLRESULT *result,
+ WXUINT message,
+ WXWPARAM wParam,
+ WXLPARAM lParam)
{
// did we process the message?
bool processed = false;
case VK_OEM_5:
case VK_OEM_6:
case VK_OEM_7:
+ case VK_OEM_102:
case VK_OEM_PLUS:
case VK_OEM_COMMA:
case VK_OEM_MINUS:
}
if ( !processed )
+ return false;
+
+ *result = rc.result;
+
+ return true;
+}
+
+WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
+{
+ WXLRESULT result;
+ if ( !MSWHandleMessage(&result, message, wParam, lParam) )
{
#if wxDEBUG_LEVEL >= 2
wxLogTrace("winmsg", wxT("Forwarding %s to DefWindowProc."),
wxGetMessageName(message));
#endif // wxDEBUG_LEVEL >= 2
- rc.result = MSWDefWindowProc(message, wParam, lParam);
+ result = MSWDefWindowProc(message, wParam, lParam);
}
- return rc.result;
+ return result;
}
// ----------------------------------------------------------------------------
// 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;
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
case VK_OEM_5:
case VK_OEM_6:
case VK_OEM_7:
+ case VK_OEM_102:
// MapVirtualKey() returns 0 if it fails to convert the virtual
// key which nicely corresponds to our WXK_NONE.
wxk = ::MapVirtualKey(vk, MAPVK_VK_TO_CHAR);
// don't use ChooseNormalOrExtended() here as the keys are reversed
// here: numpad enter is the extended one
wxk = HIWORD(lParam) & KF_EXTENDED ? WXK_NUMPAD_ENTER : WXK_RETURN;
+
+ if ( uc )
+ *uc = WXK_RETURN;
break;
default:
{
wxMouseState ms;
POINT pt;
- GetCursorPos( &pt );
+ wxGetCursorPosMSW(&pt);
ms.SetX(pt.x);
ms.SetY(pt.y);
#endif // wxUSE_UNICODE
)
{
- const wxWindow * const win = wxGetActiveWindow();
+ wxWindow const* win = wxWindow::DoFindFocus();
+ if ( !win )
+ {
+ // Even if the focus got lost somehow, still send the event
+ // to the top level parent to allow a wxDialog to always
+ // close on Escape.
+ win = wxGetActiveWindow();
+ }
wxKeyEvent event(wxEVT_CHAR_HOOK);
MSWInitAnyKeyEvent(event, wParam, lParam, win);
if ( handler && handler->ProcessEvent(event) )
{
- // processed
- return 1;
+ if ( !event.IsNextEventAllowed() )
+ {
+ // Stop processing of this event.
+ return 1;
+ }
}
}
}
wxPoint wxGetMousePosition()
{
POINT pt;
-#ifdef __WXWINCE__
- GetCursorPosWinCE(&pt);
-#else
- GetCursorPos( & pt );
-#endif
+ wxGetCursorPosMSW(&pt);
return wxPoint(pt.x, pt.y);
}