X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4cdc2c137ebe5357e320e2794f085f29be2c74b9..803c55373484d1e2bfed85b46cbbfff8bfad1276:/src/msw/window.cpp diff --git a/src/msw/window.cpp b/src/msw/window.cpp index 11a6da140e..ae5cf582a6 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -288,6 +288,18 @@ wxWindow::~wxWindow() m_isBeingDeleted = TRUE; MSWDetachWindowMenu(); + + // 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; + } + } if ( m_parent ) m_parent->RemoveChild(this); @@ -2246,13 +2258,7 @@ long wxWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) wxPoint pt(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU, GetId(), pt); - GetEventHandler()->ProcessEvent(evtCtx); - - // set processed to true even if the event is not handled - // because if we don't windows will propogate the - // WM_CONTEXTMENU up the parent window chain, which we have - // already done ourselves. - processed = true; + processed = GetEventHandler()->ProcessEvent(evtCtx); } break; #endif // __WIN32__ @@ -2923,19 +2929,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); @@ -3103,9 +3110,8 @@ bool wxWindow::HandleEraseBkgnd(WXHDC hdc) if ( ::IsIconic(GetHwnd()) ) return TRUE; - wxDC dc; + wxDCTemp dc(hdc); - dc.SetHDC(hdc); dc.SetWindow(this); dc.BeginDrawing(); @@ -3114,8 +3120,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; }