X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4286a5b59579f09c014fd81683732cd8609cfe9f..b3818fbe8e439bc9af8c20371774520a5a2bc9c7:/src/msw/window.cpp diff --git a/src/msw/window.cpp b/src/msw/window.cpp index 95424f3bc6..9e27c1d6aa 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -117,18 +117,7 @@ extern MSG s_currentMsg; wxMenu *wxCurrentPopupMenu = NULL; extern wxList WXDLLEXPORT wxPendingDelete; -extern char wxCanvasClassName[]; - -#ifdef __WXDEBUG__ - // see comments in dcclient.cpp where g_isPainting is defined - extern bool g_isPainting; - - inline static void wxStartPainting() { g_isPainting = TRUE; } - inline static void wxEndPainting() { g_isPainting = FALSE; } -#else // !debug - inline static void wxStartPainting() { } - inline static void wxEndPainting() { } -#endif // debug/!debug +extern wxChar wxCanvasClassName[]; // --------------------------------------------------------------------------- // private functions @@ -257,6 +246,11 @@ void wxWindow::Init() // wxWnd m_hMenu = 0; + m_hWnd = 0; + + // pass WM_GETDLGCODE to DefWindowProc() + m_lDlgCode = 0; + m_xThumbSize = 0; m_yThumbSize = 0; m_backgroundTransparent = FALSE; @@ -301,7 +295,7 @@ bool wxWindow::Create(wxWindow *parent, wxWindowID id, long style, const wxString& name) { - wxCHECK_MSG( parent, FALSE, "can't create wxWindow without parent" ); + wxCHECK_MSG( parent, FALSE, _T("can't create wxWindow without parent") ); CreateBase(parent, id, pos, size, style, name); @@ -328,6 +322,15 @@ bool wxWindow::Create(wxWindow *parent, wxWindowID id, msflags |= WS_BORDER; } + // calculate the value to return from WM_GETDLGCODE handler + if ( GetWindowStyleFlag() & wxWANTS_CHARS ) + { + // want everything: i.e. all keys and WM_CHAR message + m_lDlgCode = DLGC_WANTARROWS | DLGC_WANTCHARS | + DLGC_WANTTAB | DLGC_WANTMESSAGE; + + } + MSWCreate(m_windowId, parent, wxCanvasClassName, this, NULL, pos.x, pos.y, WidthDefault(size.x), HeightDefault(size.y), @@ -796,7 +799,7 @@ void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect) void wxWindow::SubclassWin(WXHWND hWnd) { - wxASSERT_MSG( !m_oldWndProc, "subclassing window twice?" ); + wxASSERT_MSG( !m_oldWndProc, _T("subclassing window twice?") ); wxAssociateWinWithHandle((HWND)hWnd, this); @@ -1295,7 +1298,7 @@ void wxWindow::GetTextExtent(const wxString& string, SIZE sizeRect; TEXTMETRIC tm; - GetTextExtentPoint(dc, (const char *)string, (int)string.Length(), &sizeRect); + GetTextExtentPoint(dc, (const wxChar *)string, (int)string.Length(), &sizeRect); GetTextMetrics(dc, &tm); if ( fontToUse && fnt && hfontOld ) @@ -1379,6 +1382,7 @@ bool wxWindow::MSWProcessMessage(WXMSG* pMsg) if ( bProcess ) { bool bCtrlDown = (::GetKeyState(VK_CONTROL) & 0x100) != 0; + bool bShiftDown = (::GetKeyState(VK_SHIFT) & 0x100) != 0; // WM_GETDLGCODE: ask the control if it wants the key for itself, // don't process it if it's the case (except for Ctrl-Tab/Enter @@ -1395,13 +1399,16 @@ bool wxWindow::MSWProcessMessage(WXMSG* pMsg) switch ( msg->wParam ) { case VK_TAB: - if ( lDlgCode & DLGC_WANTTAB ) { + // assume that nobody wants Shift-TAB for himself - if we + // don't do it there is no easy way for a control to grab + // TABs but still let Shift-TAB work as navugation key + if ( (lDlgCode & DLGC_WANTTAB) && !bShiftDown ) { bProcess = FALSE; } else { // Ctrl-Tab cycles thru notebook pages bWindowChange = bCtrlDown; - bForward = !(::GetKeyState(VK_SHIFT) & 0x100); + bForward = !bShiftDown; } break; @@ -1421,27 +1428,21 @@ bool wxWindow::MSWProcessMessage(WXMSG* pMsg) case VK_RETURN: { - if ( lDlgCode & DLGC_WANTMESSAGE ) + if ( (lDlgCode & DLGC_WANTMESSAGE) && !bCtrlDown ) { // control wants to process Enter itself, don't // call IsDialogMessage() which would interpret // it return FALSE; } -#ifndef __WIN16__ - wxButton *btnDefault = GetDefaultItem(); - if ( btnDefault && !bCtrlDown ) + else if ( lDlgCode & DLGC_BUTTON ) { - // if there is a default button, Enter should - // press it - (void)::SendMessage((HWND)btnDefault->GetHWND(), - BM_CLICK, 0, 0); - return TRUE; + // buttons want process Enter themselevs + bProcess = FALSE; } - // else: but if there is not it makes sense to make it + // else: but if it does not it makes sense to make it // work like a TAB - and that's what we do. // Note that Ctrl-Enter always works this way. -#endif } break; @@ -1457,7 +1458,16 @@ bool wxWindow::MSWProcessMessage(WXMSG* pMsg) event.SetEventObject(this); if ( GetEventHandler()->ProcessEvent(event) ) + { + wxButton *btn = wxDynamicCast(FindFocus(), wxButton); + if ( btn ) + { + // the button which has focus should be default + btn->SetDefault(); + } + return TRUE; + } } } @@ -1561,7 +1571,7 @@ void wxWindow::UnpackScroll(WXWPARAM wParam, WXLPARAM lParam, void wxWindow::UnpackCtlColor(WXWPARAM wParam, WXLPARAM lParam, WXWORD *nCtlColor, WXHDC *hdc, WXHWND *hwnd) { - *control = (WXHWND)LOWORD(lParam); + *hwnd = (WXHWND)LOWORD(lParam); *nCtlColor = (int)HIWORD(lParam); *hdc = (WXHDC)wParam; } @@ -1589,7 +1599,7 @@ LRESULT APIENTRY _EXPORT wxWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA { // trace all messages - useful for the debugging #ifdef __WXDEBUG__ - wxLogTrace(wxTraceMessages, "Processing %s(wParam=%8lx, lParam=%8lx)", + wxLogTrace(wxTraceMessages, _T("Processing %s(wParam=%8lx, lParam=%8lx)"), wxGetMessageName(message), wParam, lParam); #endif // __WXDEBUG__ @@ -1688,9 +1698,7 @@ long wxWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) break; case WM_PAINT: - wxStartPainting(); processed = HandlePaint(); - wxEndPainting(); break; case WM_CLOSE: @@ -1780,11 +1788,12 @@ long wxWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) break; case WM_GETDLGCODE: - if ( GetWindowStyleFlag() & wxWANTS_CHARS ) + if ( m_lDlgCode ) { - rc.result = DLGC_WANTARROWS | DLGC_WANTCHARS | DLGC_WANTTAB; + rc.result = m_lDlgCode; processed = TRUE; } + //else: get the dlg code from the DefWindowProc() break; case WM_KEYDOWN: @@ -1814,7 +1823,10 @@ long wxWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) case VK_RETURN: case VK_BACK: case VK_TAB: - processed = TRUE; + // but set processed to FALSE, not TRUE to still pass them to + // the control's default window proc - otherwise built-in + // keyboard handling won't work + processed = FALSE; break; @@ -1945,7 +1957,7 @@ long wxWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) break; case WM_GETMINMAXINFO: - processed = HandleGetMinMaxInfo((LPMINMAXINFO)lParam); + processed = HandleGetMinMaxInfo((MINMAXINFO*)lParam); break; case WM_SETCURSOR: @@ -1966,7 +1978,7 @@ long wxWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) if ( !processed ) { #ifdef __WXDEBUG__ - wxLogTrace(wxTraceMessages, "Forwarding %s to DefWindowProc.", + wxLogTrace(wxTraceMessages, _T("Forwarding %s to DefWindowProc."), wxGetMessageName(message)); #endif // __WXDEBUG__ rc.result = MSWDefWindowProc(message, wParam, lParam); @@ -2007,7 +2019,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 != (HWND)NULL, - "attempt to add a NULL hWnd to window list ignored" ); + _T("attempt to add a NULL hWnd to window list ignored") ); if ( !wxWinHandleList->Find((long)hWnd) ) wxWinHandleList->Append((long)hWnd, win); @@ -2034,16 +2046,16 @@ void wxWindow::MSWDetachWindowMenu() int i; for (i = 0; i < N; i++) { - char buf[100]; + wxChar buf[100]; int chars = GetMenuString(hMenu, i, buf, 100, MF_BYPOSITION); if ( !chars ) { - wxLogLastError("GetMenuString"); + wxLogLastError(_T("GetMenuString")); continue; } - if ( strcmp(buf, "&Window") == 0 ) + if ( wxStrcmp(buf, _T("&Window")) == 0 ) { RemoveMenu(hMenu, i, MF_BYPOSITION); @@ -2055,15 +2067,15 @@ void wxWindow::MSWDetachWindowMenu() bool wxWindow::MSWCreate(int id, wxWindow *parent, - const char *wclass, + const wxChar *wclass, wxWindow *wx_win, - const char *title, + const wxChar *title, int x, int y, int width, int height, WXDWORD style, - const char *dialog_template, + const wxChar *dialog_template, WXDWORD extendedStyle) { int x1 = CW_USEDEFAULT; @@ -2119,14 +2131,14 @@ bool wxWindow::MSWCreate(int id, if ( !::SetWindowPos(GetHwnd(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE) ) { - wxLogLastError("SetWindowPos"); + wxLogLastError(_T("SetWindowPos")); } } // move the dialog to its initial position without forcing repainting if ( !::MoveWindow(GetHwnd(), x1, y1, width1, height1, FALSE) ) { - wxLogLastError("MoveWindow"); + wxLogLastError(_T("MoveWindow")); } } else @@ -2137,7 +2149,7 @@ bool wxWindow::MSWCreate(int id, m_hWnd = (WXHWND)CreateWindowEx(extendedStyle, wclass, - title ? title : "", + title ? title : _T(""), style, x1, y1, width1, height1, @@ -2211,7 +2223,7 @@ bool wxWindow::MSWOnNotify(int WXUNUSED(idCtrl), if ( hdr->code == TTN_NEEDTEXT && m_tooltip ) { TOOLTIPTEXT *ttt = (TOOLTIPTEXT *)lParam; - ttt->lpszText = (char *)m_tooltip->GetTip().c_str(); + ttt->lpszText = (wxChar *)m_tooltip->GetTip().c_str(); // processed return TRUE; @@ -2324,10 +2336,10 @@ bool wxWindow::HandleSetFocus(WXHWND WXUNUSED(hwnd)) #endif // wxUSE_CARET // panel wants to track the window which was the last to have focus in it - wxWindow *parent = GetParent(); - if ( parent && parent->IsKindOf(CLASSINFO(wxPanel)) ) + wxPanel *panel = wxDynamicCast(GetParent(), wxPanel); + if ( panel ) { - ((wxPanel *)parent)->SetLastFocus(GetId()); + panel->SetLastFocus(this); } wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId); @@ -2388,7 +2400,7 @@ bool wxWindow::HandleDropFiles(WXWPARAM wParam) int wIndex; for (wIndex=0; wIndex < (int)gwFilesDropped; wIndex++) { - DragQueryFile (hFilesInfo, wIndex, (LPSTR) wxBuffer, 1000); + DragQueryFile (hFilesInfo, wIndex, (LPTSTR) wxBuffer, 1000); files[wIndex] = wxBuffer; } DragFinish (hFilesInfo); @@ -3101,7 +3113,7 @@ bool wxWindow::HandleJoystickEvent(WXUINT msg, int x, int y, WXUINT flags) break; default: - wxFAIL_MSG("no such joystick event"); + wxFAIL_MSG(_T("no such joystick event")); return FALSE; }