X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2bda0e173844e8e0f8acf4e8ad8b5c26e5c6fe5d..77ff2d2639049a0bd8d64d87fbe27694354b7097:/src/msw/dcclient.cpp diff --git a/src/msw/dcclient.cpp b/src/msw/dcclient.cpp index c406939a28..4c6b19b03b 100644 --- a/src/msw/dcclient.cpp +++ b/src/msw/dcclient.cpp @@ -29,6 +29,7 @@ #endif #include "wx/dcclient.h" +#include "wx/log.h" #include @@ -98,44 +99,40 @@ static PAINTSTRUCT g_paintStruct; // Don't call Begin/EndPaint if it's already been called: // for example, if calling a base class OnPaint. -WXHDC wxPaintDC::m_staticPaintHDC = 0; -int wxPaintDC::m_staticPaintCount = 0; +WXHDC wxPaintDC::ms_PaintHDC = 0; +uint wxPaintDC::ms_PaintCount = 0; // count of ms_PaintHDC usage -wxPaintDC::wxPaintDC(wxWindow *the_canvas) +wxPaintDC::wxPaintDC(wxWindow *canvas) { - if ( the_canvas && (m_staticPaintCount == 0)) - { - m_hDC = (WXHDC) ::BeginPaint((HWND) the_canvas->GetHWND(), &g_paintStruct); - m_hDCCount ++; - m_staticPaintCount ++ ; - m_staticPaintHDC = m_hDC ; - } - else - m_hDC = m_staticPaintHDC ; + wxCHECK_RET( canvas, "NULL canvas in wxPaintDC ctor" ); - m_canvas = the_canvas; - RECT updateRect1 = g_paintStruct.rcPaint; - m_canvas->m_updateRect.x = updateRect1.left; - m_canvas->m_updateRect.y = updateRect1.top; - m_canvas->m_updateRect.width = updateRect1.right - updateRect1.left; - m_canvas->m_updateRect.height = updateRect1.bottom - updateRect1.top; -// m_canvas->m_paintHDC = m_staticPaintHDC ; + m_canvas = canvas; + if ( ms_PaintCount > 0 ) { + // it means that we've already called BeginPaint and so we must just + // reuse the same HDC (BeginPaint shouldn't be called more than once) + wxASSERT( ms_PaintHDC ); + + m_hDC = ms_PaintHDC; + ms_PaintCount++; + } + else { + ms_PaintHDC = + m_hDC = (WXHDC)::BeginPaint((HWND)m_canvas->GetHWND(), &g_paintStruct); + ms_PaintCount = 1; + m_hDCCount++; + } } -wxPaintDC::~wxPaintDC(void) +wxPaintDC::~wxPaintDC() { - m_staticPaintCount -- ; - - if (m_staticPaintCount == 0) - { -// m_canvas->m_paintHDC = 0; - - if ( m_hDC && m_canvas) - { - ::EndPaint((HWND) m_canvas->GetHWND(), &g_paintStruct); - m_hDCCount --; - m_hDC = 0; - } - m_staticPaintHDC = 0 ; - } + if ( m_hDC ) { + if ( !--ms_PaintCount ) { + ::EndPaint((HWND)m_canvas->GetHWND(), &g_paintStruct); + m_hDCCount--; + m_hDC = NULL; + ms_PaintHDC = NULL; + } + //else: ms_PaintHDC still in use + } } +