Fixed issue #2507: Support keyboard shortcuts in yes/no prompts
[TortoiseGit.git] / src / Utils / MiscUI / BufferDC.cpp
blobaae939f27d7d0cce39c0a4766040e9dd14b0e6e3
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;
28 else
30 ATLASSERT(false);
31 m_hAttributeDC = nullptr;
32 m_hOutputDC = nullptr;
33 m_hMemoryDC = nullptr;
34 m_hPaintBitmap = nullptr;
35 m_hOldBitmap = nullptr;
36 m_ClientRect.right = 0;
37 m_ClientRect.left = 0;
38 m_ClientRect.top = 0;
39 m_ClientRect.bottom = 0;
42 m_bBoundsUpdated = FALSE;
45 CBufferDC::~CBufferDC(void)
47 Flush();
49 ::SelectObject(m_hMemoryDC, m_hOldBitmap);
50 ::DeleteObject(m_hPaintBitmap);
52 CPaintDC::m_hDC = m_hOutputDC;
53 CPaintDC::m_hAttribDC = m_hAttributeDC;
55 ::DeleteDC(m_hMemoryDC);
58 void CBufferDC::Flush()
60 ::BitBlt(
61 m_hOutputDC,
62 m_ClientRect.left, m_ClientRect.top,
63 m_ClientRect.right - m_ClientRect.left,
64 m_ClientRect.bottom - m_ClientRect.top,
65 m_hMemoryDC,
66 0, 0,
67 SRCCOPY);
70 UINT CBufferDC::SetBoundsRect( LPCRECT lpRectBounds, UINT flags )
72 if (lpRectBounds != NULL)
74 if (m_ClientRect.right - m_ClientRect.left > lpRectBounds->right - lpRectBounds->left ||
75 m_ClientRect.bottom - m_ClientRect.top > lpRectBounds->bottom - lpRectBounds->top)
77 lpRectBounds = &m_ClientRect;
80 HBITMAP bmp =
81 ::CreateCompatibleBitmap(
82 m_hOutputDC,
83 lpRectBounds->right - lpRectBounds->left,
84 lpRectBounds->bottom - lpRectBounds->top);
86 HDC tmpDC = ::CreateCompatibleDC(m_hOutputDC);
88 HBITMAP oldBmp = (HBITMAP)::SelectObject(tmpDC, bmp);
90 ::BitBlt(
91 tmpDC,
92 m_ClientRect.left, m_ClientRect.top,
93 m_ClientRect.right - m_ClientRect.left,
94 m_ClientRect.bottom - m_ClientRect.top,
95 m_hMemoryDC,
96 0, 0,
97 SRCCOPY);
99 ::SelectObject(tmpDC, oldBmp);
100 ::DeleteDC(tmpDC);
102 HBITMAP old = (HBITMAP)::SelectObject(m_hMemoryDC, bmp);
104 if (old != NULL && old != m_hPaintBitmap)
106 ::DeleteObject(old);
109 if (m_hPaintBitmap != NULL)
111 ::DeleteObject(m_hPaintBitmap);
114 m_hPaintBitmap = bmp;
116 m_ClientRect = *lpRectBounds;
117 m_bBoundsUpdated = TRUE;
120 return CPaintDC::SetBoundsRect(lpRectBounds, flags);
123 BOOL CBufferDC::RestoreDC( int nSavedDC )
125 BOOL ret = CPaintDC::RestoreDC(nSavedDC);
127 if (m_bBoundsUpdated)
129 SelectObject(m_hPaintBitmap);
132 return ret;