X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/cde9f08e1f2bba81294708c1d65bb869ed744e56..eeccd5d94ce6b11f36af95db4ac528a2e2e0c4c5:/src/msw/window.cpp diff --git a/src/msw/window.cpp b/src/msw/window.cpp index 2d3212aaed..7df1986533 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -17,7 +17,7 @@ #include "wx/wxprec.h" #ifdef __BORLANDC__ -#pragma hdrstop + #pragma hdrstop #endif #ifndef WX_PRECOMP @@ -39,11 +39,11 @@ #endif #if wxUSE_OWNER_DRAWN -#include "wx/ownerdrw.h" + #include "wx/ownerdrw.h" #endif #if wxUSE_DRAG_AND_DROP -#include "wx/msw/ole/droptgt.h" + #include "wx/msw/ole/droptgt.h" #endif #include "wx/menuitem.h" @@ -61,9 +61,11 @@ #include #endif +#ifndef __TWIN32__ #ifdef __GNUWIN32__ #include #endif +#endif #ifdef GetCharWidth #undef GetCharWidth @@ -82,7 +84,7 @@ #endif #ifdef __WXDEBUG__ -const char *wxGetMessageName(int message); + const char *wxGetMessageName(int message); #endif //__WXDEBUG__ #define WINDOW_MARGIN 3 // This defines sensitivity of Leave events @@ -100,6 +102,8 @@ IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxEvtHandler) BEGIN_EVENT_TABLE(wxWindow, wxEvtHandler) EVT_CHAR(wxWindow::OnChar) + EVT_KEY_DOWN(wxWindow::OnKeyDown) + EVT_KEY_UP(wxWindow::OnKeyUp) EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground) EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged) EVT_INIT_DIALOG(wxWindow::OnInitDialog) @@ -123,7 +127,7 @@ wxWindow *wxWindow::FindItem(int id) const if (childWin->IsKindOf(CLASSINFO(wxControl))) { wxControl *item = (wxControl *)childWin; - if (item->m_windowId == id) + if (item->GetId() == id) return item; else { @@ -841,7 +845,6 @@ LRESULT APIENTRY _EXPORT wxWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA wxWndHook = NULL; wnd->m_hWnd = (WXHWND) hWnd; } - // wxDebugMsg("hWnd = %d, m_hWnd = %d, msg = %d\n", hWnd, m_hWnd, message); // Stop right here if we don't have a valid handle // in our wxWnd object. @@ -866,17 +869,16 @@ LRESULT APIENTRY _EXPORT wxWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA // Should probably have a test for 'genuine' NT #if defined(__WIN32__) -#define DIMENSION_TYPE short + #define DIMENSION_TYPE short #else -#define DIMENSION_TYPE int + #define DIMENSION_TYPE int #endif // Main Windows 3 window proc long wxWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) { wxASSERT( m_lastMsg == message && - m_lastWParam == wParam && - m_lastLParam == lParam ); + m_lastWParam == wParam && m_lastLParam == lParam ); #ifdef __WXDEBUG__ wxLogTrace(wxTraceMessages, "Processing %s(%lx, %lx)", @@ -1163,6 +1165,9 @@ long wxWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) } case WM_KEYDOWN: + { + MSWOnKeyDown((WORD) wParam, lParam); +#if 0 // we consider these message "not interesting" if ( wParam == VK_SHIFT || wParam == VK_CONTROL ) return Default(); @@ -1180,8 +1185,15 @@ long wxWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) MSWOnChar((WORD)wParam, lParam); else return Default(); +#endif break; + } + case WM_KEYUP: + { + MSWOnKeyUp((WORD) wParam, lParam); + break; + } case WM_CHAR: // Always an ASCII character { MSWOnChar((WORD)wParam, lParam, TRUE); @@ -1410,7 +1422,7 @@ void wxAssociateWinWithHandle(HWND hWnd, wxWindow *win) { // adding NULL hWnd is (first) surely a result of an error and // (secondly) breaks menu command processing - wxCHECK_RET( hWnd != NULL, "attempt to add a NULL hWnd to window list" ); + wxCHECK_RET( hWnd != (HWND) NULL, "attempt to add a NULL hWnd to window list" ); if ( !wxWinHandleList->Find((long)hWnd) ) wxWinHandleList->Append((long)hWnd, win); @@ -2394,6 +2406,74 @@ void wxWindow::MSWOnChar(WXWORD wParam, WXLPARAM lParam, bool isASCII) } } +void wxWindow::MSWOnKeyDown(WXWORD wParam, WXLPARAM lParam, bool isASCII) +{ + int id; + + if ((id = wxCharCodeMSWToWX(wParam)) == 0) { + id = wParam; + } + + if (id != -1) + { + wxKeyEvent event(wxEVT_KEY_DOWN); + event.m_shiftDown = (::GetKeyState(VK_SHIFT)&0x100?TRUE:FALSE); + event.m_controlDown = (::GetKeyState(VK_CONTROL)&0x100?TRUE:FALSE); + if ((HIWORD(lParam) & KF_ALTDOWN) == KF_ALTDOWN) + event.m_altDown = TRUE; + + event.m_eventObject = this; + event.m_keyCode = id; + event.SetTimestamp(wxApp::sm_lastMessageTime); + + POINT pt ; + GetCursorPos(&pt) ; + RECT rect ; + GetWindowRect((HWND) GetHWND(),&rect) ; + pt.x -= rect.left ; + pt.y -= rect.top ; + + event.m_x = pt.x; event.m_y = pt.y; + + if (!GetEventHandler()->ProcessEvent(event)) + Default(); + } +} + +void wxWindow::MSWOnKeyUp(WXWORD wParam, WXLPARAM lParam, bool isASCII) +{ + int id; + + if ((id = wxCharCodeMSWToWX(wParam)) == 0) { + id = wParam; + } + + if (id != -1) + { + wxKeyEvent event(wxEVT_KEY_UP); + event.m_shiftDown = (::GetKeyState(VK_SHIFT)&0x100?TRUE:FALSE); + event.m_controlDown = (::GetKeyState(VK_CONTROL)&0x100?TRUE:FALSE); + if ((HIWORD(lParam) & KF_ALTDOWN) == KF_ALTDOWN) + event.m_altDown = TRUE; + + event.m_eventObject = this; + event.m_keyCode = id; + event.SetTimestamp(wxApp::sm_lastMessageTime); + + POINT pt ; + GetCursorPos(&pt) ; + RECT rect ; + GetWindowRect((HWND) GetHWND(),&rect) ; + pt.x -= rect.left ; + pt.y -= rect.top ; + + event.m_x = pt.x; event.m_y = pt.y; + + if (!GetEventHandler()->ProcessEvent(event)) + Default(); + } +} + void wxWindow::MSWOnJoyDown(int joystick, int x, int y, WXUINT flags) { int buttons = 0; @@ -2885,7 +2965,7 @@ void wxSetKeyboardHook(bool doIt) { wxTheKeyboardHookProc = MakeProcInstance((FARPROC) wxKeyboardHook, wxGetInstance()); wxTheKeyboardHook = SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC) wxTheKeyboardHookProc, wxGetInstance(), -#ifdef __WIN32__ +#if defined(__WIN32__) && !defined(__TWIN32__) GetCurrentThreadId()); // (DWORD)GetCurrentProcess()); // This is another possibility. Which is right? #else @@ -3024,10 +3104,14 @@ bool wxWindow::MSWOnEraseBkgnd (WXHDC pDC) void wxWindow::OnEraseBackground(wxEraseEvent& event) { + if (!GetHWND()) + return; + RECT rect; ::GetClientRect((HWND) GetHWND(), &rect); - HBRUSH hBrush = ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue())); + COLORREF ref = PALETTERGB(m_backgroundColour.Red(), m_backgroundColour.Green(), m_backgroundColour.Blue()) ; + HBRUSH hBrush = ::CreateSolidBrush(ref); int mode = ::SetMapMode((HDC) event.GetDC()->GetHDC(), MM_TEXT); // ::GetClipBox((HDC) event.GetDC()->GetHDC(), &rect); @@ -3466,6 +3550,8 @@ WXDWORD wxWindow::Determine3DEffects(WXDWORD defaultBorderStyle, bool *want3D) void wxWindow::OnChar(wxKeyEvent& event) { +/* I'm commenting this out because otherwise, we lose tabs in e.g. a text window (see MDI sample) + * (JACS, 14/01/99) if ( event.KeyCode() == WXK_TAB ) { // propagate the TABs to the parent - it's up to it to decide what // to do with it @@ -3474,6 +3560,7 @@ void wxWindow::OnChar(wxKeyEvent& event) return; } } +*/ bool isVirtual; int id = wxCharCodeWXToMSW((int)event.KeyCode(), &isVirtual); @@ -3485,6 +3572,16 @@ void wxWindow::OnChar(wxKeyEvent& event) (void) MSWDefWindowProc(m_lastMsg, (WPARAM) id, m_lastLParam); } +void wxWindow::OnKeyDown(wxKeyEvent& event) +{ + Default(); +} + +void wxWindow::OnKeyUp(wxKeyEvent& event) +{ + Default(); +} + void wxWindow::OnPaint(wxPaintEvent& event) { Default();