X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d2c52078dc8bf1f6f69b9f1693860d6345686767..eaac8805cd0fc233aeb0fc40a31bf8d8e03bf59c:/src/msw/window.cpp?ds=sidebyside diff --git a/src/msw/window.cpp b/src/msw/window.cpp index dadffe9b6a..fb93646628 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -84,7 +84,7 @@ #include -#ifndef __GNUWIN32_OLD__ +#if !defined(__GNUWIN32_OLD__) || defined(__CYGWIN10__) #include #include #endif @@ -93,7 +93,7 @@ #include #endif -#if !defined(__GNUWIN32_OLD__) && !defined(__TWIN32__) +#if (!defined(__GNUWIN32_OLD__) && !defined(__TWIN32__)) || defined(__CYGWIN10__) #ifdef __WIN95__ #include #endif @@ -111,7 +111,11 @@ #if wxUSE_MOUSEWHEEL #ifndef WM_MOUSEWHEEL #define WM_MOUSEWHEEL 0x020A + #endif + #ifndef WHEEL_DELTA #define WHEEL_DELTA 120 + #endif + #ifndef SPI_GETWHEELSCROLLLINES #define SPI_GETWHEELSCROLLLINES 104 #endif #endif @@ -285,11 +289,26 @@ wxWindow::~wxWindow() MSWDetachWindowMenu(); - if ( m_parent ) - m_parent->RemoveChild(this); + // VS: make sure there's no wxFrame with last focus set to us: + for (wxWindow *win = GetParent(); win; win = win->GetParent()) + { + wxFrame *frame = wxDynamicCast(win, wxFrame); + if ( frame ) + { + if ( frame->GetLastFocus() == this ) + frame->SetLastFocus((wxWindow*)NULL); + break; + } + } + // VS: destroy children first and _then_ detach *this from its parent. + // If we'd do it the other way around, children wouldn't be able + // find their parent frame (see above). DestroyChildren(); + if ( m_parent ) + m_parent->RemoveChild(this); + if ( m_hWnd ) { // VZ: test temp removed to understand what really happens here @@ -375,7 +394,7 @@ wxWindow *wxWindowBase::FindFocus() HWND hWnd = ::GetFocus(); if ( hWnd ) { - return wxFindWinFromHandle((WXHWND) hWnd); + return wxGetWindowFromHWND((WXHWND)hWnd); } return NULL; @@ -392,7 +411,7 @@ bool wxWindow::Enable(bool enable) // VZ: no, this is a bad idea: imagine that you have a dialog with some // disabled controls and disable it - you really wouldn't like the - // disabled controls eb reenabled too when you reenable the dialog! + // disabled controls be reenabled too when you reenable the dialog! #if 0 wxWindowList::Node *node = GetChildren().GetFirst(); while ( node ) @@ -427,7 +446,11 @@ bool wxWindow::Show(bool show) // Raise the window to the top of the Z order void wxWindow::Raise() { +#ifdef __WIN16__ ::BringWindowToTop(GetHwnd()); +#else // Win32 + ::SetForegroundWindow(GetHwnd()); +#endif } // Lower the window to the bottom of the Z order @@ -1465,6 +1488,23 @@ void wxWindow::GetCaretPos(int *x, int *y) const // popup menu // --------------------------------------------------------------------------- +// yield for WM_COMMAND events only, i.e. process all WM_COMMANDs in the queue +// immediately, without waiting for the next event loop iteration +// +// NB: this function should probably be made public later as it can almost +// surely replace wxYield() elsewhere as well +static void wxYieldForCommandsOnly() +{ + // peek all WM_COMMANDs (it will always return WM_QUIT too but we don't + // want to process it here) + MSG msg; + while ( ::PeekMessage(&msg, (HWND)0, WM_COMMAND, WM_COMMAND, PM_REMOVE) + && msg.message != WM_QUIT ) + { + wxTheApp->DoMessage((WXMSG *)&msg); + } +} + bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y) { menu->SetInvokingWindow(this); @@ -1478,7 +1518,16 @@ bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y) ::ClientToScreen(hWnd, &point); wxCurrentPopupMenu = menu; ::TrackPopupMenu(hMenu, TPM_RIGHTBUTTON, point.x, point.y, 0, hWnd, NULL); - wxYieldIfNeeded(); + + // we need to do it righ now as otherwise the events are never going to be + // sent to wxCurrentPopupMenu from HandleCommand() + // + // note that even eliminating (ugly) wxCurrentPopupMenu global wouldn't + // help and we'd still need wxYieldForCommandsOnly() as the menu may be + // destroyed as soon as we return (it can be a local variable in the caller + // for example) and so we do need to process the event immediately + wxYieldForCommandsOnly(); + wxCurrentPopupMenu = NULL; menu->SetInvokingWindow(NULL); @@ -2197,36 +2246,55 @@ long wxWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) rc.result = TRUE; } break; + #ifdef __WIN32__ case WM_HELP: - { - HELPINFO* info = (HELPINFO*) lParam; - // Don't yet process menu help events, just windows - if (info->iContextType == HELPINFO_WINDOW) { - wxWindow* subjectOfHelp = this; - bool eventProcessed = FALSE; - while (subjectOfHelp && !eventProcessed) + HELPINFO* info = (HELPINFO*) lParam; + // Don't yet process menu help events, just windows + if (info->iContextType == HELPINFO_WINDOW) + { + wxWindow* subjectOfHelp = this; + bool eventProcessed = FALSE; + while (subjectOfHelp && !eventProcessed) + { + wxHelpEvent helpEvent(wxEVT_HELP, + subjectOfHelp->GetId(), + wxPoint(info->MousePos.x, + info->MousePos.y) ); + helpEvent.SetEventObject(this); + eventProcessed = + GetEventHandler()->ProcessEvent(helpEvent); + + // Go up the window hierarchy until the event is + // handled (or not) + subjectOfHelp = subjectOfHelp->GetParent(); + } + + processed = eventProcessed; + } + else if (info->iContextType == HELPINFO_MENUITEM) { - wxHelpEvent helpEvent(wxEVT_HELP, subjectOfHelp->GetId(), wxPoint(info->MousePos.x, info->MousePos.y) ) ; // info->iCtrlId); + wxHelpEvent helpEvent(wxEVT_HELP, info->iCtrlId); helpEvent.SetEventObject(this); - eventProcessed = GetEventHandler()->ProcessEvent(helpEvent); + processed = GetEventHandler()->ProcessEvent(helpEvent); - // Go up the window hierarchy until the event is handled (or not) - subjectOfHelp = subjectOfHelp->GetParent(); } - processed = eventProcessed; + //else: processed is already FALSE } - else if (info->iContextType == HELPINFO_MENUITEM) + break; + + case WM_CONTEXTMENU: { - wxHelpEvent helpEvent(wxEVT_HELP, info->iCtrlId) ; - helpEvent.SetEventObject(this); - processed = GetEventHandler()->ProcessEvent(helpEvent); + // we don't convert from screen to client coordinates as + // the event may be handled by a parent window + wxPoint pt(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); + + wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU, GetId(), pt); + processed = GetEventHandler()->ProcessEvent(evtCtx); } - else processed = FALSE; break; - } -#endif +#endif // __WIN32__ } if ( !processed ) @@ -2479,11 +2547,10 @@ bool wxWindow::MSWCreate(int id, { int controlId = 0; if ( style & WS_CHILD ) - { controlId = id; - // all child windows should clip their siblings - // style |= /* WS_CLIPSIBLINGS */ ; - } + + if ( GetWindowStyleFlag() & wxCLIP_SIBLINGS ) + style |= WS_CLIPSIBLINGS; wxString className(wclass); if ( GetWindowStyleFlag() & wxNO_FULL_REPAINT_ON_RESIZE ) @@ -2895,19 +2962,20 @@ bool wxWindow::MSWOnDrawItem(int id, WXDRAWITEMSTRUCT *itemStruct) wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE ); - // prepare to call OnDrawItem() - wxDC dc; - dc.SetHDC((WXHDC)pDrawStruct->hDC, FALSE); + // prepare to call OnDrawItem(): notice using of wxDCTemp to prevent + // the DC from being released + wxDCTemp dc((WXHDC)pDrawStruct->hDC); wxRect rect(pDrawStruct->rcItem.left, pDrawStruct->rcItem.top, pDrawStruct->rcItem.right - pDrawStruct->rcItem.left, pDrawStruct->rcItem.bottom - pDrawStruct->rcItem.top); return pMenuItem->OnDrawItem - ( - dc, rect, - (wxOwnerDrawn::wxODAction)pDrawStruct->itemAction, - (wxOwnerDrawn::wxODStatus)pDrawStruct->itemState - ); + ( + dc, + rect, + (wxOwnerDrawn::wxODAction)pDrawStruct->itemAction, + (wxOwnerDrawn::wxODStatus)pDrawStruct->itemState + ); } wxWindow *item = FindItem(id); @@ -3075,9 +3143,8 @@ bool wxWindow::HandleEraseBkgnd(WXHDC hdc) if ( ::IsIconic(GetHwnd()) ) return TRUE; - wxDC dc; + wxDCTemp dc(hdc); - dc.SetHDC(hdc); dc.SetWindow(this); dc.BeginDrawing(); @@ -3086,8 +3153,9 @@ bool wxWindow::HandleEraseBkgnd(WXHDC hdc) bool rc = GetEventHandler()->ProcessEvent(event); dc.EndDrawing(); + + // must be called manually as ~wxDC doesn't do anything for wxDCTemp dc.SelectOldObjects(hdc); - dc.SetHDC((WXHDC) NULL); return rc; } @@ -3351,7 +3419,7 @@ bool wxWindow::HandleMouseMove(int x, int y, WXUINT flags) if ( (m_lastMouseEvent == wxEVT_RIGHT_DOWN || m_lastMouseEvent == wxEVT_LEFT_DOWN || m_lastMouseEvent == wxEVT_MIDDLE_DOWN) && - (m_lastMouseX == event.m_x && m_lastMouseY == event.m_y) ) + (m_lastMouseX == x && m_lastMouseY == y) ) { m_lastMouseEvent = wxEVT_MOTION; @@ -3371,17 +3439,35 @@ bool wxWindow::HandleMouseWheel(WXWPARAM wParam, WXLPARAM lParam) GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), LOWORD(wParam)); - event.m_wheelRotation = (short)HIWORD(wParam); event.m_wheelDelta = WHEEL_DELTA; - int linesPer; - if (!SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &linesPer, 0)) - linesPer = 1; - event.m_linesPerAction = linesPer; +#ifdef __WIN32__ + static int s_linesPerRotation = -1; + if ( s_linesPerRotation == -1 ) + { + if ( !::SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, + &s_linesPerRotation, 0)) + { + // this is not supposed to happen + wxLogLastError(_T("SystemParametersInfo(GETWHEELSCROLLLINES)")); + // the default is 3, so use it if SystemParametersInfo() failed + s_linesPerRotation = 3; + } + } +#else // Win16 + // no SystemParametersInfo() under Win16 + static const int s_linesPerRotation = 3; +#endif + + event.m_linesPerAction = s_linesPerRotation; return GetEventHandler()->ProcessEvent(event); + #else + (void) wParam; + (void) lParam; + return FALSE; #endif } @@ -3902,24 +3988,37 @@ extern wxWindow *wxGetWindowFromHWND(WXHWND hWnd) win = wxFindWinFromHandle((WXHWND)hwnd); if ( !win ) { - // the radiobox pointer is stored in GWL_USERDATA only under Win32 + // all these hacks only work under Win32 anyhow #ifdef __WIN32__ + +#if wxUSE_RADIOBOX // native radiobuttons return DLGC_RADIOBUTTON here and for any // wxWindow class which overrides WM_GETDLGCODE processing to // do it as well, win would be already non NULL - if ( ::SendMessage((HWND)hwnd, WM_GETDLGCODE, - 0, 0) & DLGC_RADIOBUTTON ) + if ( ::SendMessage(hwnd, WM_GETDLGCODE, 0, 0) & DLGC_RADIOBUTTON ) { win = (wxWindow *)::GetWindowLong(hwnd, GWL_USERDATA); } - else + //else: it's a wxRadioButton, not a radiobutton from wxRadioBox +#endif // wxUSE_RADIOBOX + + // spin control text buddy window should be mapped to spin ctrl + // itself so try it too +#if wxUSE_SPINCTRL + if ( !win ) + { + win = wxSpinCtrl::GetSpinForTextCtrl((WXHWND)hwnd); + } +#endif // wxUSE_SPINCTRL + #endif // Win32 + + if ( !win ) { // hwnd is not a wxWindow, try its parent next below hwnd = ::GetParent(hwnd); } } - //else: it's a wxRadioButton, not a radiobutton from wxRadioBox } while ( hwnd && !win ) @@ -3956,8 +4055,9 @@ void wxSetKeyboardHook(bool doIt) else { UnhookWindowsHookEx(wxTheKeyboardHook); - // avoids warning about statement with no effect (FreeProcInstance - // doesn't do anything under Win32) + + // avoids warning about statement with no effect (FreeProcInstance + // doesn't do anything under Win32) #if !defined(WIN32) && !defined(_WIN32) && !defined(__WIN32__) && !defined(__NT__) && !defined(__GNUWIN32__) FreeProcInstance(wxTheKeyboardHookProc); #endif