OSDN Git Service

Update version number to 1.2.1.0
[tortoisegit/TortoiseGitJp.git] / src / TortoiseMerge / LineDiffBar.cpp
1 // TortoiseMerge - a Diff/Patch program\r
2 \r
3 // Copyright (C) 2006-2008 - TortoiseSVN\r
4 \r
5 // This program is free software; you can redistribute it and/or\r
6 // modify it under the terms of the GNU General Public License\r
7 // as published by the Free Software Foundation; either version 2\r
8 // of the License, or (at your option) any later version.\r
9 \r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 \r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, write to the Free Software Foundation,\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
18 //\r
19 #include "stdafx.h"\r
20 #include "TortoiseMerge.h"\r
21 #include "MainFrm.h"\r
22 #include "LocatorBar.h"\r
23 #include "LeftView.h"\r
24 #include "RightView.h"\r
25 #include "BottomView.h"\r
26 \r
27 IMPLEMENT_DYNAMIC(CLineDiffBar, CPaneDialog)\r
28 CLineDiffBar::CLineDiffBar() : CPaneDialog()\r
29 {\r
30         m_pMainFrm = NULL;\r
31         m_pCacheBitmap = NULL;\r
32         m_nLineIndex = -1;\r
33         m_nLineHeight = 0;\r
34         m_bExclusiveRow = TRUE;\r
35 }\r
36 \r
37 CLineDiffBar::~CLineDiffBar()\r
38 {\r
39         if (m_pCacheBitmap)\r
40         {\r
41                 m_pCacheBitmap->DeleteObject();\r
42                 delete m_pCacheBitmap;\r
43                 m_pCacheBitmap = NULL;\r
44         }\r
45 }\r
46 \r
47 BEGIN_MESSAGE_MAP(CLineDiffBar, CPaneDialog)\r
48         ON_WM_PAINT()\r
49         ON_WM_SIZE()\r
50         ON_WM_ERASEBKGND()\r
51 END_MESSAGE_MAP()\r
52 \r
53 void CLineDiffBar::DocumentUpdated()\r
54 {\r
55         //resize according to the font size\r
56         if ((m_pMainFrm)&&(m_pMainFrm->m_pwndLeftView))\r
57         {\r
58                 m_nLineHeight = m_pMainFrm->m_pwndLeftView->GetLineHeight();\r
59         }\r
60         CRect rect;\r
61         GetWindowRect(rect);\r
62         CSize size = rect.Size();\r
63         size.cy = 2 * m_nLineHeight;\r
64         SetMinSize(size);\r
65         SetWindowPos(NULL, 0, 0, size.cx, 2*m_nLineHeight, SWP_NOMOVE);\r
66         RecalcLayout();\r
67         if (m_pMainFrm)\r
68                 m_pMainFrm->RecalcLayout();\r
69 }\r
70 \r
71 void CLineDiffBar::ShowLines(int nLineIndex)\r
72 {\r
73         m_nLineIndex = nLineIndex;\r
74         Invalidate();\r
75 }\r
76 \r
77 void CLineDiffBar::OnPaint()\r
78 {\r
79         CPaintDC dc(this); // device context for painting\r
80         CRect rect;\r
81         GetClientRect(rect);\r
82         int height = rect.Height();\r
83         int width = rect.Width();\r
84 \r
85         CDC cacheDC;\r
86         VERIFY(cacheDC.CreateCompatibleDC(&dc));\r
87         cacheDC.FillSolidRect(&rect, ::GetSysColor(COLOR_WINDOW));\r
88         if (m_pCacheBitmap == NULL)\r
89         {\r
90                 m_pCacheBitmap = new CBitmap;\r
91                 VERIFY(m_pCacheBitmap->CreateCompatibleBitmap(&dc, width, height));\r
92         }\r
93         CBitmap *pOldBitmap = cacheDC.SelectObject(m_pCacheBitmap);\r
94 \r
95         CRect upperrect = CRect(rect.left, rect.top, rect.right, rect.bottom/2);\r
96         CRect lowerrect = CRect(rect.left, rect.bottom/2, rect.right, rect.bottom);\r
97 \r
98         if ((m_pMainFrm)&&(m_pMainFrm->m_pwndLeftView)&&(m_pMainFrm->m_pwndRightView))\r
99         {\r
100                 if ((m_pMainFrm->m_pwndLeftView->IsWindowVisible())&&(m_pMainFrm->m_pwndRightView->IsWindowVisible()))\r
101                 {\r
102                         BOOL bViewWhiteSpace = m_pMainFrm->m_pwndLeftView->m_bViewWhitespace;\r
103                         BOOL bInlineDiffs = m_pMainFrm->m_pwndLeftView->m_bShowInlineDiff;\r
104                         \r
105                         m_pMainFrm->m_pwndLeftView->m_bViewWhitespace = TRUE;\r
106                         m_pMainFrm->m_pwndLeftView->m_bShowInlineDiff = TRUE;\r
107                         m_pMainFrm->m_pwndLeftView->m_bShowSelection = false;\r
108                         m_pMainFrm->m_pwndRightView->m_bViewWhitespace = TRUE;\r
109                         m_pMainFrm->m_pwndRightView->m_bShowInlineDiff = TRUE;\r
110                         m_pMainFrm->m_pwndRightView->m_bShowSelection = false;\r
111 \r
112                         // Use left and right view to display lines next to each other\r
113                         m_pMainFrm->m_pwndLeftView->DrawSingleLine(&cacheDC, &upperrect, m_nLineIndex);\r
114                         m_pMainFrm->m_pwndRightView->DrawSingleLine(&cacheDC, &lowerrect, m_nLineIndex);\r
115 \r
116                         m_pMainFrm->m_pwndLeftView->m_bViewWhitespace = bViewWhiteSpace;\r
117                         m_pMainFrm->m_pwndLeftView->m_bShowInlineDiff = bInlineDiffs;\r
118                         m_pMainFrm->m_pwndLeftView->m_bShowSelection = true;\r
119                         m_pMainFrm->m_pwndRightView->m_bViewWhitespace = bViewWhiteSpace;\r
120                         m_pMainFrm->m_pwndRightView->m_bShowInlineDiff = bInlineDiffs;\r
121                         m_pMainFrm->m_pwndRightView->m_bShowSelection = true;\r
122                 }\r
123         } \r
124 \r
125         VERIFY(dc.BitBlt(rect.left, rect.top, width, height, &cacheDC, 0, 0, SRCCOPY));\r
126 \r
127         cacheDC.SelectObject(pOldBitmap);\r
128         cacheDC.DeleteDC();\r
129 }\r
130 \r
131 void CLineDiffBar::OnSize(UINT nType, int cx, int cy)\r
132 {\r
133         CPaneDialog::OnSize(nType, cx, cy);\r
134 \r
135         if (m_pCacheBitmap != NULL)\r
136         {\r
137                 m_pCacheBitmap->DeleteObject();\r
138                 delete m_pCacheBitmap;\r
139                 m_pCacheBitmap = NULL;\r
140         }\r
141         SetWindowPos(NULL, 0, 0, cx, 2*m_nLineHeight, SWP_NOMOVE);\r
142         Invalidate();\r
143 }\r
144 \r
145 BOOL CLineDiffBar::OnEraseBkgnd(CDC* /*pDC*/)\r
146 {\r
147         return TRUE;\r
148 }\r
149 \r
150 \r