OSDN Git Service

Success build TortoiseMerge.
[tortoisegit/TortoiseGitJp.git] / src / TortoiseMerge / LocatorBar.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 #include "DiffColors.h"\r
27 \r
28 \r
29 IMPLEMENT_DYNAMIC(CLocatorBar, CPaneDialog)\r
30 CLocatorBar::CLocatorBar() : CPaneDialog()\r
31 {\r
32         m_pMainFrm = NULL;\r
33         m_pCacheBitmap = NULL;\r
34         m_bMouseWithin = FALSE;\r
35 }\r
36 \r
37 CLocatorBar::~CLocatorBar()\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(CLocatorBar, CPaneDialog)\r
48         ON_WM_PAINT()\r
49         ON_WM_SIZE()\r
50         ON_WM_ERASEBKGND()\r
51         ON_WM_LBUTTONDOWN()\r
52         ON_WM_MOUSEMOVE()\r
53         ON_MESSAGE(WM_MOUSELEAVE, OnMouseLeave)\r
54 END_MESSAGE_MAP()\r
55 \r
56 void CLocatorBar::DocumentUpdated()\r
57 {\r
58         m_pMainFrm = (CMainFrame *)this->GetParentFrame();\r
59         m_arLeftIdent.RemoveAll();\r
60         m_arLeftState.RemoveAll();\r
61         m_arRightIdent.RemoveAll();\r
62         m_arRightState.RemoveAll();\r
63         m_arBottomIdent.RemoveAll();\r
64         m_arBottomState.RemoveAll();\r
65         DiffStates state = DIFFSTATE_UNKNOWN;\r
66         long identcount = 1;\r
67         m_nLines = 0;\r
68         if (m_pMainFrm->m_pwndLeftView->m_pViewData)\r
69         {\r
70                 if (m_pMainFrm->m_pwndLeftView->m_pViewData->GetCount())\r
71                         state = m_pMainFrm->m_pwndLeftView->m_pViewData->GetState(0);\r
72                 for (int i=0; i<m_pMainFrm->m_pwndLeftView->m_pViewData->GetCount(); i++)\r
73                 {\r
74                         if (state == m_pMainFrm->m_pwndLeftView->m_pViewData->GetState(i))\r
75                         {\r
76                                 identcount++;\r
77                         }\r
78                         else\r
79                         {\r
80                                 m_arLeftIdent.Add(identcount);\r
81                                 m_arLeftState.Add(state);\r
82                                 state = m_pMainFrm->m_pwndLeftView->m_pViewData->GetState(i);\r
83                                 identcount = 1;\r
84                         } \r
85                 }\r
86                 m_arLeftIdent.Add(identcount);\r
87                 m_arLeftState.Add(state);\r
88         }\r
89 \r
90         if (m_pMainFrm->m_pwndRightView->m_pViewData)\r
91         {\r
92                 if (m_pMainFrm->m_pwndRightView->m_pViewData->GetCount())\r
93                         state = m_pMainFrm->m_pwndRightView->m_pViewData->GetState(0);\r
94                 identcount = 1;\r
95                 for (int i=0; i<m_pMainFrm->m_pwndRightView->m_pViewData->GetCount(); i++)\r
96                 {\r
97                         if (state == m_pMainFrm->m_pwndRightView->m_pViewData->GetState(i))\r
98                         {\r
99                                 identcount++;\r
100                         }\r
101                         else\r
102                         {\r
103                                 m_arRightIdent.Add(identcount);\r
104                                 m_arRightState.Add(state);\r
105                                 state = m_pMainFrm->m_pwndRightView->m_pViewData->GetState(i);\r
106                                 identcount = 1;\r
107                         }\r
108                 }\r
109                 m_arRightIdent.Add(identcount);\r
110                 m_arRightState.Add(state);\r
111         }\r
112 \r
113         if (m_pMainFrm->m_pwndBottomView->m_pViewData)\r
114         {\r
115                 if (m_pMainFrm->m_pwndBottomView->m_pViewData->GetCount())\r
116                         state = m_pMainFrm->m_pwndBottomView->m_pViewData->GetState(0);\r
117                 identcount = 1;\r
118                 for (int i=0; i<m_pMainFrm->m_pwndBottomView->m_pViewData->GetCount(); i++)\r
119                 {\r
120                         if (state == m_pMainFrm->m_pwndBottomView->m_pViewData->GetState(i))\r
121                         {\r
122                                 identcount++;\r
123                         }\r
124                         else\r
125                         {\r
126                                 m_arBottomIdent.Add(identcount);\r
127                                 m_arBottomState.Add(state);\r
128                                 state = m_pMainFrm->m_pwndBottomView->m_pViewData->GetState(i);\r
129                                 identcount = 1;\r
130                         }\r
131                 }\r
132                 m_arBottomIdent.Add(identcount);\r
133                 m_arBottomState.Add(state);\r
134                 m_nLines = (int)max(m_pMainFrm->m_pwndBottomView->m_pViewData->GetCount(), m_pMainFrm->m_pwndRightView->m_pViewData->GetCount());\r
135         }\r
136         else if (m_pMainFrm->m_pwndRightView->m_pViewData)\r
137                 m_nLines = (int)max(0, m_pMainFrm->m_pwndRightView->m_pViewData->GetCount());\r
138 \r
139         if (m_pMainFrm->m_pwndLeftView->m_pViewData)\r
140                 m_nLines = (int)max(m_nLines, m_pMainFrm->m_pwndLeftView->m_pViewData->GetCount());\r
141         else\r
142                 m_nLines = 0;\r
143         m_nLines++;\r
144         Invalidate();\r
145 }\r
146 \r
147 void CLocatorBar::OnPaint()\r
148 {\r
149         CPaintDC dc(this); // device context for painting\r
150         CRect rect;\r
151         GetClientRect(rect);\r
152         long height = rect.Height();\r
153         long width = rect.Width();\r
154         long nTopLine = 0;\r
155         long nBottomLine = 0;\r
156         if ((m_pMainFrm)&&(m_pMainFrm->m_pwndLeftView))\r
157         {\r
158                 nTopLine = m_pMainFrm->m_pwndLeftView->m_nTopLine;\r
159                 nBottomLine = nTopLine + m_pMainFrm->m_pwndLeftView->GetScreenLines();\r
160         }\r
161         CDC cacheDC;\r
162         VERIFY(cacheDC.CreateCompatibleDC(&dc));\r
163 \r
164         if (m_pCacheBitmap == NULL)\r
165         {\r
166                 m_pCacheBitmap = new CBitmap;\r
167                 VERIFY(m_pCacheBitmap->CreateCompatibleBitmap(&dc, width, height));\r
168         }\r
169         CBitmap *pOldBitmap = cacheDC.SelectObject(m_pCacheBitmap);\r
170 \r
171 \r
172         COLORREF color, color2;\r
173         \r
174         CDiffColors::GetInstance().GetColors(DIFFSTATE_UNKNOWN, color, color2);\r
175         cacheDC.FillSolidRect(rect, color);\r
176         \r
177         long barwidth = (width/3);\r
178         DWORD state = 0;\r
179         long identcount = 0;\r
180         long linecount = 0;\r
181         \r
182         if (m_nLines)\r
183                 cacheDC.FillSolidRect(rect.left, height*nTopLine/m_nLines,\r
184                         rect.Width(), (height*nBottomLine/m_nLines)-(height*nTopLine/m_nLines), RGB(180,180,255));\r
185         if (m_pMainFrm->m_pwndLeftView->IsWindowVisible())\r
186         {\r
187                 for (long i=0; i<m_arLeftIdent.GetCount(); i++)\r
188                 {\r
189                         identcount = m_arLeftIdent.GetAt(i);\r
190                         state = m_arLeftState.GetAt(i);\r
191                         CDiffColors::GetInstance().GetColors((DiffStates)state, color, color2);\r
192                         if ((DiffStates)state != DIFFSTATE_NORMAL)\r
193                                 cacheDC.FillSolidRect(rect.left, height*linecount/m_nLines, \r
194                                                         barwidth, max(height*identcount/m_nLines,1), color);\r
195                         linecount += identcount;\r
196                 }\r
197         }\r
198         state = 0;\r
199         identcount = 0;\r
200         linecount = 0;\r
201 \r
202         if (m_pMainFrm->m_pwndRightView->IsWindowVisible())\r
203         {\r
204                 for (long i=0; i<m_arRightIdent.GetCount(); i++)\r
205                 {\r
206                         identcount = m_arRightIdent.GetAt(i);\r
207                         state = m_arRightState.GetAt(i);\r
208                         CDiffColors::GetInstance().GetColors((DiffStates)state, color, color2);\r
209                         if ((DiffStates)state != DIFFSTATE_NORMAL)\r
210                                 cacheDC.FillSolidRect(rect.left + (width*2/3), height*linecount/m_nLines, \r
211                                                         barwidth, max(height*identcount/m_nLines,1), color);\r
212                         linecount += identcount;\r
213                 }\r
214         }\r
215         state = 0;\r
216         identcount = 0;\r
217         linecount = 0;\r
218         if (m_pMainFrm->m_pwndBottomView->IsWindowVisible())\r
219         {\r
220                 for (long i=0; i<m_arBottomIdent.GetCount(); i++)\r
221                 {\r
222                         identcount = m_arBottomIdent.GetAt(i);\r
223                         state = m_arBottomState.GetAt(i);\r
224                         CDiffColors::GetInstance().GetColors((DiffStates)state, color, color2);\r
225                         if ((DiffStates)state != DIFFSTATE_NORMAL)\r
226                                 cacheDC.FillSolidRect(rect.left + (width/3), height*linecount/m_nLines, \r
227                                                         barwidth, max(height*identcount/m_nLines,1), color);\r
228                         linecount += identcount;\r
229                 }\r
230         }\r
231 \r
232         if (m_nLines == 0)\r
233                 m_nLines = 1;\r
234         cacheDC.FillSolidRect(rect.left, height*nTopLine/m_nLines,\r
235                 rect.Width(), 2, RGB(0,0,0));\r
236         cacheDC.FillSolidRect(rect.left, height*nBottomLine/m_nLines,\r
237                 rect.Width(), 2, RGB(0,0,0));\r
238         //draw two vertical lines, so there are three rows visible indicating the three panes\r
239         cacheDC.FillSolidRect(rect.left + (width/3), rect.top, 1, height, RGB(0,0,0));\r
240         cacheDC.FillSolidRect(rect.left + (width*2/3), rect.top, 1, height, RGB(0,0,0));\r
241 \r
242         // draw the fish eye\r
243         if (m_bMouseWithin)\r
244         {\r
245                 int fishstart = m_MousePos.y - height/20;\r
246                 int fishheight = height/10;\r
247                 cacheDC.FillSolidRect(rect.left, fishstart-1, width, 1, RGB(0,0,100));\r
248                 cacheDC.FillSolidRect(rect.left, fishstart+fishheight+1, width, 1, RGB(0,0,100));\r
249                 VERIFY(cacheDC.StretchBlt(rect.left, fishstart, width, fishheight, \r
250                         &cacheDC, 0, fishstart + (3*fishheight/8), width, fishheight/4, SRCCOPY));\r
251                 // draw the magnified area a little darker, so the\r
252                 // user has a clear indication of the magnifier\r
253                 for (int i=rect.left; i<(width - rect.left); i++)\r
254                 {\r
255                         for (int j=fishstart; j<fishstart+fishheight; j++)\r
256                         {\r
257                                 color = cacheDC.GetPixel(i, j);\r
258                                 int r,g,b;\r
259                                 r = max(GetRValue(color)-20, 0);\r
260                                 g = max(GetGValue(color)-20, 0);\r
261                                 b = max(GetBValue(color)-20, 0);\r
262                                 cacheDC.SetPixel(i, j, RGB(r,g,b));\r
263                         }\r
264                 }\r
265         }\r
266         VERIFY(dc.BitBlt(rect.left, rect.top, width, height, &cacheDC, 0, 0, SRCCOPY));\r
267         \r
268         cacheDC.SelectObject(pOldBitmap);\r
269         cacheDC.DeleteDC();\r
270 }\r
271 \r
272 void CLocatorBar::OnSize(UINT nType, int cx, int cy)\r
273 {\r
274         CPaneDialog::OnSize(nType, cx, cy);\r
275 \r
276         if (m_pCacheBitmap != NULL)\r
277         {\r
278                 m_pCacheBitmap->DeleteObject();\r
279                 delete m_pCacheBitmap;\r
280                 m_pCacheBitmap = NULL;\r
281         }\r
282         Invalidate();\r
283 }\r
284 \r
285 BOOL CLocatorBar::OnEraseBkgnd(CDC* /*pDC*/)\r
286 {\r
287         return TRUE;\r
288 }\r
289 \r
290 void CLocatorBar::OnLButtonDown(UINT nFlags, CPoint point)\r
291 {\r
292         CRect rect;\r
293         GetClientRect(rect); \r
294         int nLine = point.y*m_nLines/rect.Height();\r
295 \r
296         if (nLine < 0)\r
297                 nLine = 0;\r
298         if ((m_pMainFrm)&&(m_pMainFrm->m_pwndBottomView))\r
299                 m_pMainFrm->m_pwndBottomView->GoToLine(nLine, FALSE);\r
300         if ((m_pMainFrm)&&(m_pMainFrm->m_pwndLeftView))\r
301                 m_pMainFrm->m_pwndLeftView->GoToLine(nLine, FALSE);\r
302         if ((m_pMainFrm)&&(m_pMainFrm->m_pwndRightView))\r
303                 m_pMainFrm->m_pwndRightView->GoToLine(nLine, FALSE);\r
304         Invalidate();\r
305         CPaneDialog::OnLButtonDown(nFlags, point);\r
306 }\r
307 \r
308 void CLocatorBar::OnMouseMove(UINT nFlags, CPoint point)\r
309 {\r
310         m_MousePos = point;\r
311         if (!m_bMouseWithin)\r
312         { \r
313                 m_bMouseWithin = TRUE;\r
314                 TRACKMOUSEEVENT tme;\r
315                 tme.cbSize = sizeof(TRACKMOUSEEVENT);\r
316                 tme.dwFlags = TME_LEAVE;\r
317                 tme.hwndTrack = m_hWnd;\r
318                 _TrackMouseEvent(&tme);\r
319         }\r
320 \r
321         if (nFlags & MK_LBUTTON)\r
322         {\r
323                 CRect rect;\r
324                 GetClientRect(rect); \r
325                 int nLine = point.y*m_nLines/rect.Height();\r
326 \r
327                 if (nLine < 0)\r
328                         nLine = 0;\r
329                 if ((m_pMainFrm)&&(m_pMainFrm->m_pwndBottomView))\r
330                         m_pMainFrm->m_pwndBottomView->GoToLine(nLine, FALSE);\r
331                 if ((m_pMainFrm)&&(m_pMainFrm->m_pwndLeftView))\r
332                         m_pMainFrm->m_pwndLeftView->GoToLine(nLine, FALSE);\r
333                 if ((m_pMainFrm)&&(m_pMainFrm->m_pwndRightView))\r
334                         m_pMainFrm->m_pwndRightView->GoToLine(nLine, FALSE);\r
335         }\r
336         Invalidate();\r
337 }\r
338 \r
339 LRESULT CLocatorBar::OnMouseLeave(WPARAM, LPARAM)\r
340 {\r
341         m_bMouseWithin = FALSE;\r
342         Invalidate();\r
343         return 0;\r
344\r
345 \r
346 \r
347 \r