Sync TortoiseIDiff and TortoiseUDiff from TortoiseSVN
[TortoiseGit.git] / src / Utils / MiscUI / BufferDC.cpp
blobfd3ba7eb7b693f8105ccf29a3911c4666d5d0b97
1 #include "stdafx.h"
2 #include "BufferDC.h"
4 IMPLEMENT_DYNAMIC(CBufferDC, CPaintDC)
6 CBufferDC::CBufferDC(CWnd* pWnd) : CPaintDC(pWnd)
8 if (pWnd != NULL && CPaintDC::m_hDC != NULL)
10 m_hOutputDC = CPaintDC::m_hDC;
11 m_hAttributeDC = CPaintDC::m_hAttribDC;
13 pWnd->GetClientRect(&m_ClientRect);
15 m_hMemoryDC = ::CreateCompatibleDC(m_hOutputDC);
17 m_hPaintBitmap =
18 ::CreateCompatibleBitmap(
19 m_hOutputDC,
20 m_ClientRect.right - m_ClientRect.left,
21 m_ClientRect.bottom - m_ClientRect.top);
23 m_hOldBitmap = (HBITMAP)::SelectObject(m_hMemoryDC, m_hPaintBitmap);
25 CPaintDC::m_hDC = m_hMemoryDC;
26 CPaintDC::m_hAttribDC = m_hMemoryDC;
29 m_bBoundsUpdated = FALSE;
32 CBufferDC::~CBufferDC(void)
34 Flush();
36 ::SelectObject(m_hMemoryDC, m_hOldBitmap);
37 ::DeleteObject(m_hPaintBitmap);
39 CPaintDC::m_hDC = m_hOutputDC;
40 CPaintDC::m_hAttribDC = m_hAttributeDC;
42 ::DeleteDC(m_hMemoryDC);
45 void CBufferDC::Flush()
47 ::BitBlt(
48 m_hOutputDC,
49 m_ClientRect.left, m_ClientRect.top,
50 m_ClientRect.right - m_ClientRect.left,
51 m_ClientRect.bottom - m_ClientRect.top,
52 m_hMemoryDC,
53 0, 0,
54 SRCCOPY);
57 UINT CBufferDC::SetBoundsRect( LPCRECT lpRectBounds, UINT flags )
59 if (lpRectBounds != NULL)
61 if (m_ClientRect.right - m_ClientRect.left > lpRectBounds->right - lpRectBounds->left ||
62 m_ClientRect.bottom - m_ClientRect.top > lpRectBounds->bottom - lpRectBounds->top)
64 lpRectBounds = &m_ClientRect;
67 HBITMAP bmp =
68 ::CreateCompatibleBitmap(
69 m_hOutputDC,
70 lpRectBounds->right - lpRectBounds->left,
71 lpRectBounds->bottom - lpRectBounds->top);
73 HDC tmpDC = ::CreateCompatibleDC(m_hOutputDC);
75 HBITMAP oldBmp = (HBITMAP)::SelectObject(tmpDC, bmp);
77 ::BitBlt(
78 tmpDC,
79 m_ClientRect.left, m_ClientRect.top,
80 m_ClientRect.right - m_ClientRect.left,
81 m_ClientRect.bottom - m_ClientRect.top,
82 m_hMemoryDC,
83 0, 0,
84 SRCCOPY);
86 ::SelectObject(tmpDC, oldBmp);
87 ::DeleteDC(tmpDC);
89 HBITMAP old = (HBITMAP)::SelectObject(m_hMemoryDC, bmp);
91 if (old != NULL && old != m_hPaintBitmap)
93 ::DeleteObject(old);
96 if (m_hPaintBitmap != NULL)
98 ::DeleteObject(m_hPaintBitmap);
101 m_hPaintBitmap = bmp;
103 m_ClientRect = *lpRectBounds;
104 m_bBoundsUpdated = TRUE;
107 return CPaintDC::SetBoundsRect(lpRectBounds, flags);
110 BOOL CBufferDC::RestoreDC( int nSavedDC )
112 BOOL ret = CPaintDC::RestoreDC(nSavedDC);
114 if (m_bBoundsUpdated)
116 SelectObject(m_hPaintBitmap);
119 return ret;