OSDN Git Service

Change Dir Structure to be same as TortoiseSVN'
[tortoisegit/TortoiseGitJp.git] / src / Utils / MiscUI / BufferDC.cpp
1 #include "StdAfx.h"\r
2 #include "BufferDC.h"\r
3 \r
4 IMPLEMENT_DYNAMIC(CBufferDC, CPaintDC)\r
5 \r
6 CBufferDC::CBufferDC(CWnd* pWnd) : CPaintDC(pWnd)\r
7 {\r
8         if (pWnd != NULL && CPaintDC::m_hDC != NULL)\r
9         {\r
10                 m_hOutputDC    = CPaintDC::m_hDC;\r
11                 m_hAttributeDC = CPaintDC::m_hAttribDC;\r
12 \r
13                 pWnd->GetClientRect(&m_ClientRect);\r
14 \r
15                 m_hMemoryDC = ::CreateCompatibleDC(m_hOutputDC);\r
16 \r
17                 m_hPaintBitmap =\r
18                         ::CreateCompatibleBitmap(\r
19                                         m_hOutputDC,\r
20                                         m_ClientRect.right  - m_ClientRect.left,\r
21                                         m_ClientRect.bottom - m_ClientRect.top);\r
22 \r
23                 m_hOldBitmap = (HBITMAP)::SelectObject(m_hMemoryDC, m_hPaintBitmap);\r
24 \r
25                 CPaintDC::m_hDC       = m_hMemoryDC;\r
26                 CPaintDC::m_hAttribDC = m_hMemoryDC;\r
27         }\r
28 \r
29         m_bBoundsUpdated = FALSE;\r
30 }\r
31 \r
32 CBufferDC::~CBufferDC(void)\r
33 {\r
34         Flush();\r
35 \r
36         ::SelectObject(m_hMemoryDC, m_hOldBitmap);\r
37         ::DeleteObject(m_hPaintBitmap);\r
38 \r
39         CPaintDC::m_hDC           = m_hOutputDC;\r
40         CPaintDC::m_hAttribDC = m_hAttributeDC;\r
41 \r
42         ::DeleteDC(m_hMemoryDC);\r
43 }\r
44 \r
45 void CBufferDC::Flush()\r
46 {\r
47         ::BitBlt(\r
48                 m_hOutputDC,\r
49                 m_ClientRect.left, m_ClientRect.top,\r
50                 m_ClientRect.right  - m_ClientRect.left, \r
51                 m_ClientRect.bottom - m_ClientRect.top,\r
52                 m_hMemoryDC,\r
53                 0, 0,\r
54                 SRCCOPY);\r
55 }\r
56 \r
57 UINT CBufferDC::SetBoundsRect( LPCRECT lpRectBounds, UINT flags )\r
58 {\r
59         if (lpRectBounds != NULL)\r
60         {\r
61                 if (m_ClientRect.right  - m_ClientRect.left > lpRectBounds->right  - lpRectBounds->left ||\r
62                         m_ClientRect.bottom - m_ClientRect.top  > lpRectBounds->bottom - lpRectBounds->top)\r
63                 {\r
64                         lpRectBounds = &m_ClientRect;\r
65                 }\r
66 \r
67                 HBITMAP bmp =\r
68                         ::CreateCompatibleBitmap(\r
69                                         m_hOutputDC, \r
70                                         lpRectBounds->right - lpRectBounds->left, \r
71                                         lpRectBounds->bottom - lpRectBounds->top);\r
72 \r
73                 HDC tmpDC  = ::CreateCompatibleDC(m_hOutputDC);\r
74                 \r
75                 HBITMAP oldBmp = (HBITMAP)::SelectObject(tmpDC, bmp);\r
76 \r
77                 ::BitBlt(\r
78                         tmpDC,\r
79                         m_ClientRect.left, m_ClientRect.top,\r
80                         m_ClientRect.right  - m_ClientRect.left, \r
81                         m_ClientRect.bottom - m_ClientRect.top,\r
82                         m_hMemoryDC,\r
83                         0, 0,\r
84                         SRCCOPY);\r
85 \r
86                 ::SelectObject(tmpDC, oldBmp);\r
87                 ::DeleteDC(tmpDC);\r
88 \r
89                 HBITMAP old = (HBITMAP)::SelectObject(m_hMemoryDC, bmp);\r
90 \r
91                 if (old != NULL && old != m_hPaintBitmap)\r
92                 {\r
93                         ::DeleteObject(old);\r
94                 }\r
95 \r
96                 if (m_hPaintBitmap != NULL)\r
97                 {\r
98                         ::DeleteObject(m_hPaintBitmap);\r
99                 }\r
100 \r
101                 m_hPaintBitmap = bmp;\r
102 \r
103                 m_ClientRect = *lpRectBounds;\r
104                 m_bBoundsUpdated = TRUE;\r
105         }\r
106 \r
107         return CPaintDC::SetBoundsRect(lpRectBounds, flags);\r
108 }\r
109 \r
110 BOOL CBufferDC::RestoreDC( int nSavedDC )\r
111 {\r
112         BOOL ret = CPaintDC::RestoreDC(nSavedDC);\r
113 \r
114         if (m_bBoundsUpdated)\r
115         {\r
116                 SelectObject(m_hPaintBitmap);\r
117         }\r
118 \r
119         return ret;\r
120 }