X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/93bfd481b7f2f0fec50dd79fcab52374aa59ebbb..ff4aedc55481dfb2bf3ddfc9a604189809af79d6:/src/msw/window.cpp diff --git a/src/msw/window.cpp b/src/msw/window.cpp index a68f7b7dfd..f5a6693112 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -155,11 +155,6 @@ void wxRemoveHandleAssociation(wxWindowMSW *win); extern void wxAssociateWinWithHandle(HWND hWnd, wxWindowMSW *win); wxWindow *wxFindWinFromHandle(WXHWND hWnd); -// this magical function is used to translate VK_APPS key presses to right -// mouse clicks -static void TranslateKbdEventToMouse(wxWindowMSW *win, - int *x, int *y, WPARAM *flags); - // get the text metrics for the current font static TEXTMETRIC wxGetTextMetrics(const wxWindowMSW *win); @@ -586,7 +581,7 @@ void wxWindowMSW::SetFocusFromKbd() } // Get the window with the focus -wxWindow *wxWindowBase::FindFocus() +wxWindow *wxWindowBase::DoFindFocus() { HWND hWnd = ::GetFocus(); if ( hWnd ) @@ -2503,19 +2498,23 @@ WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l // this should never happen wxCHECK_MSG( win, 0, _T("FindWindowForMouseEvent() returned NULL") ); + } + + processed = win->HandleMouseEvent(message, x, y, wParam); + // if the app didn't eat the event, handle it in the default + // way, that is by giving this window the focus + if ( !processed ) + { // for the standard classes their WndProc sets the focus to // them anyhow and doing it from here results in some weird - // problems, but for our windows we want them to acquire - // focus when clicked + // problems, so don't do it for them (unnecessary anyhow) if ( !win->IsOfStandardClass() ) { if ( message == WM_LBUTTONDOWN && win->AcceptsFocus() ) win->SetFocus(); } } - - processed = win->HandleMouseEvent(message, x, y, wParam); } break; @@ -2662,13 +2661,7 @@ WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l // special case of VK_APPS: treat it the same as right mouse // click because both usually pop up a context menu case VK_APPS: - { - WPARAM flags; - int x, y; - - TranslateKbdEventToMouse(this, &x, &y, &flags); - processed = HandleMouseEvent(WM_RBUTTONDOWN, x, y, flags); - } + processed = HandleMouseEvent(WM_RBUTTONDOWN, -1, -1, 0); break; #endif // VK_APPS @@ -2687,11 +2680,7 @@ WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l // special case of VK_APPS: treat it the same as right mouse button if ( wParam == VK_APPS ) { - WPARAM flags; - int x, y; - - TranslateKbdEventToMouse(this, &x, &y, &flags); - processed = HandleMouseEvent(WM_RBUTTONUP, x, y, flags); + processed = HandleMouseEvent(WM_RBUTTONUP, -1, -1, 0); } else #endif // VK_APPS @@ -3122,7 +3111,7 @@ bool wxWindowMSW::MSWCreate(const wxChar *wclass, // do create the window wxWindowCreationHook hook(this); - // VZ: anyonce cares to explain why is this done for CE? + // VZ: anyone care to explain why this is done for CE? #ifdef __WXWINCE__ if (extendedStyle == 0) { @@ -3383,6 +3372,8 @@ bool wxWindowMSW::HandleCreate(WXLPCREATESTRUCT cs, bool *mayCreate) #ifndef __WXWINCE__ if ( ((CREATESTRUCT *)cs)->dwExStyle & WS_EX_CONTROLPARENT ) EnsureParentHasControlParentStyle(GetParent()); +#else + wxUnusedVar(cs); #endif // !__WXWINCE__ // TODO: should generate this event from WM_NCCREATE @@ -3675,7 +3666,8 @@ wxWindowMSW::MSWOnDrawItem(int WXUNUSED_UNLESS_ODRAWN(id), { wxMenuItem *pMenuItem = (wxMenuItem *)(pDrawStruct->itemData); - wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), false ); + wxCHECK_MSG( pMenuItem && pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), + false, _T("MSWOnDrawItem: bad wxMenuItem pointer") ); // prepare to call OnDrawItem(): notice using of wxDCTemp to prevent // the DC from being released @@ -3723,9 +3715,7 @@ wxWindowMSW::MSWOnDrawItem(int WXUNUSED_UNLESS_ODRAWN(id), } bool -wxWindowMSW::MSWOnMeasureItem(int WXUNUSED_UNLESS_ODRAWN(id), - WXMEASUREITEMSTRUCT * - WXUNUSED_UNLESS_ODRAWN(itemStruct)) +wxWindowMSW::MSWOnMeasureItem(int id, WXMEASUREITEMSTRUCT *itemStruct) { #if wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE // is it a menu item? @@ -3734,7 +3724,8 @@ wxWindowMSW::MSWOnMeasureItem(int WXUNUSED_UNLESS_ODRAWN(id), { wxMenuItem *pMenuItem = (wxMenuItem *)(pMeasureStruct->itemData); - wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), false ); + wxCHECK_MSG( pMenuItem && pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), + false, _T("MSWOnMeasureItem: bad wxMenuItem pointer") ); size_t w, h; bool rc = pMenuItem->OnMeasureItem(&w, &h); @@ -3750,7 +3741,10 @@ wxWindowMSW::MSWOnMeasureItem(int WXUNUSED_UNLESS_ODRAWN(id), { return item->MSWOnMeasure(itemStruct); } -#endif // wxUSE_OWNER_DRAWN +#else + wxUnusedVar(id); + wxUnusedVar(itemStruct); +#endif // wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE return false; } @@ -4146,7 +4140,8 @@ bool wxWindowMSW::HandleMaximize() bool wxWindowMSW::HandleMove(int x, int y) { - wxMoveEvent event(wxPoint(x, y), m_windowId); + wxPoint point(x,y); + wxMoveEvent event(point, m_windowId); event.SetEventObject(this); return GetEventHandler()->ProcessEvent(event); @@ -4425,7 +4420,7 @@ static wxWindowMSW *FindWindowForMouseEvent(wxWindowMSW *win, int *x, int *y) // bool wxWindowMSW::HandleMouseEvent(WXUINT msg, int x, int y, WXUINT flags) { // the mouse events take consecutive IDs from WM_MOUSEFIRST to - // WM_MOUSELAST, so it's enough to substract WM_MOUSEMOVE == WM_MOUSEFIRST + // WM_MOUSELAST, so it's enough to subtract WM_MOUSEMOVE == WM_MOUSEFIRST // from the message id and take the value in the table to get wxWin event // id static const wxEventType eventsMouse[] = @@ -4556,7 +4551,7 @@ wxKeyEvent wxWindowMSW::CreateKeyEvent(wxEventType evType, event.m_eventObject = (wxWindow *)this; // const_cast event.m_keyCode = id; #if wxUSE_UNICODE - event.m_uniChar = wParam; + event.m_uniChar = (wxChar) wParam; #endif event.m_rawCode = (wxUint32) wParam; event.m_rawFlags = (wxUint32) lParam; @@ -4720,7 +4715,7 @@ int wxWindowMSW::HandleMenuChar(int chAccel, WXLPARAM lParam) // FIXME-UNICODE: this comparison doesn't risk to work // for non ASCII accelerator characters I'm afraid, but // what can we do? - if ( wxToupper(*p) == (wchar_t)chAccel ) + if ( (wchar_t)wxToupper(*p) == (wchar_t)chAccel ) { return i; } @@ -5056,10 +5051,10 @@ int wxCharCodeMSWToWX(int keySym, WXLPARAM lParam) return id; } -int wxCharCodeWXToMSW(int id, bool *isVirtual) +WXWORD wxCharCodeWXToMSW(int id, bool *isVirtual) { *isVirtual = true; - int keySym; + WXWORD keySym; switch (id) { case WXK_CANCEL: keySym = VK_CANCEL; break; @@ -5128,7 +5123,7 @@ int wxCharCodeWXToMSW(int id, bool *isVirtual) default: { *isVirtual = false; - keySym = id; + keySym = (WORD)id; break; } } @@ -5138,25 +5133,32 @@ int wxCharCodeWXToMSW(int id, bool *isVirtual) bool wxGetKeyState(wxKeyCode key) { bool bVirtual; - int vkey = wxCharCodeWXToMSW(key, &bVirtual); - SHORT state; - switch (key) +//High order with GetAsyncKeyState only available on WIN32 +#ifdef __WIN32__ + //If the requested key is a LED key, return + //true if the led is pressed + if (key == WXK_NUMLOCK || + key == WXK_CAPITAL || + key == WXK_SCROLL) { - case WXK_NUMLOCK: - case WXK_CAPITAL: - case WXK_SCROLL: - // get the toggle state of the special key - state = GetKeyState(vkey); - break; +#endif + //low order bit means LED is highlighted, + //high order means key is down + //Here, for compat with other ports we want both + return GetKeyState( wxCharCodeWXToMSW(key, &bVirtual) ) != 0; - default: - // Get the current state of the physical key - state = GetAsyncKeyState(vkey); - break; +#ifdef __WIN32__ } - // if the most significant bit is set then the key is down - return ( state & 0x0001 ) != 0; + else + { + //normal key + //low order bit means key pressed since last call + //high order means key is down + //We want only the high order bit - the key may not be down if only low order + return ( GetAsyncKeyState( wxCharCodeWXToMSW(key, &bVirtual) ) & (1<<15) ) != 0; + } +#endif } wxWindow *wxGetActiveWindow() @@ -5713,26 +5715,6 @@ const char *wxGetMessageName(int message) } #endif //__WXDEBUG__ -static void TranslateKbdEventToMouse(wxWindowMSW *win, - int *x, int *y, WPARAM *flags) -{ - // construct the key mask - WPARAM& fwKeys = *flags; - - fwKeys = MK_RBUTTON; - if ( wxIsCtrlDown() ) - fwKeys |= MK_CONTROL; - if ( wxIsShiftDown() ) - fwKeys |= MK_SHIFT; - - // simulate right mouse button click - DWORD dwPos = ::GetMessagePos(); - *x = GET_X_LPARAM(dwPos); - *y = GET_Y_LPARAM(dwPos); - - win->ScreenToClient(x, y); -} - static TEXTMETRIC wxGetTextMetrics(const wxWindowMSW *win) { // prepare the DC