Fixed issue #478: Fix Blame timing because it shows wrong date and 00000.... commit...
[TortoiseGit.git] / src / TortoiseGitBlame / TortoiseGitBlameView.cpp
blobb52783281c896b015ff80f029d4903f904dafd5a
1 // TortoiseGitBlame - a Viewer for Git Blames
3 // Copyright (C) 2003-2008 - TortoiseSVN
5 // Copyright (C)2003 Don HO <donho@altern.org>
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software Foundation,
19 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 // CTortoiseGitBlameView.cpp : implementation of the CTortoiseGitBlameView class
24 #include "stdafx.h"
25 #include "TortoiseGitBlame.h"
27 #include "TortoiseGitBlameDoc.h"
28 #include "TortoiseGitBlameView.h"
29 #include "MainFrm.h"
30 #include "Balloon.h"
31 #include "EditGotoDlg.h"
32 #include "TortoiseGitBlameAppUtils.h"
33 #include "FileTextLines.h"
34 #include "UniCodeUtils.h"
35 #include "MenuEncode.h"
36 #include "gitdll.h"
38 #ifdef _DEBUG
39 #define new DEBUG_NEW
40 #endif
42 UINT CTortoiseGitBlameView::m_FindDialogMessage;
44 // CTortoiseGitBlameView
45 IMPLEMENT_DYNAMIC(CSciEditBlame,CSciEdit)
47 IMPLEMENT_DYNCREATE(CTortoiseGitBlameView, CView)
49 BEGIN_MESSAGE_MAP(CTortoiseGitBlameView, CView)
50 // Standard printing commands
51 ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
52 ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
53 ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CTortoiseGitBlameView::OnFilePrintPreview)
54 ON_COMMAND(ID_EDIT_FIND,OnEditFind)
55 ON_COMMAND(ID_EDIT_GOTO,OnEditGoto)
56 ON_COMMAND(ID_EDIT_COPY,CopySelectedLogToClipboard)
57 ON_COMMAND(ID_VIEW_NEXT,OnViewNext)
58 ON_COMMAND(ID_VIEW_PREV,OnViewPrev)
59 ON_COMMAND_RANGE(IDM_FORMAT_ENCODE, IDM_FORMAT_ENCODE_END, OnChangeEncode)
60 ON_WM_CREATE()
61 ON_WM_SIZE()
62 ON_WM_MOUSEMOVE()
63 ON_WM_MOUSEHOVER()
64 ON_WM_MOUSELEAVE()
65 ON_WM_LBUTTONDOWN()
66 ON_WM_RBUTTONDOWN()
67 ON_NOTIFY(SCN_PAINTED,0,OnSciPainted)
68 ON_NOTIFY(SCN_GETBKCOLOR,0,OnSciGetBkColor)
69 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
70 END_MESSAGE_MAP()
73 // CTortoiseGitBlameView construction/destruction
75 CTortoiseGitBlameView::CTortoiseGitBlameView()
77 // TODO: add construction code here
78 hInstance = 0;
79 hResource = 0;
80 currentDialog = 0;
81 wMain = 0;
82 m_wEditor = 0;
83 wLocator = 0;
85 m_font = 0;
86 m_italicfont = 0;
87 m_blamewidth = 0;
88 m_revwidth = 0;
89 m_datewidth = 0;
90 m_authorwidth = 0;
91 m_pathwidth = 0;
92 m_linewidth = 0;
94 m_windowcolor = ::GetSysColor(COLOR_WINDOW);
95 m_textcolor = ::GetSysColor(COLOR_WINDOWTEXT);
96 m_texthighlightcolor = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
97 m_mouserevcolor = InterColor(m_windowcolor, m_textcolor, 20);
98 m_mouseauthorcolor = InterColor(m_windowcolor, m_textcolor, 10);
99 m_selectedrevcolor = ::GetSysColor(COLOR_HIGHLIGHT);
100 m_selectedauthorcolor = InterColor(m_selectedrevcolor, m_texthighlightcolor, 35);
101 m_mouserev = -2;
103 m_selectedrev = -1;
104 m_selectedorigrev = -1;
105 m_SelectedLine = -1;
106 m_directPointer = 0;
107 m_directFunction = 0;
109 m_lowestrev = LONG_MAX;
110 m_highestrev = 0;
111 m_colorage = true;
113 m_bShowLine=true;
115 m_bShowAuthor=true;
116 m_bShowDate=false;
118 m_FindDialogMessage = ::RegisterWindowMessage(FINDMSGSTRING);
119 m_pFindDialog = NULL;
120 // get short/long datetime setting from registry
121 DWORD RegUseShortDateFormat = CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE);
122 if ( RegUseShortDateFormat )
124 m_DateFormat = DATE_SHORTDATE;
126 else
128 m_DateFormat = DATE_LONGDATE;
131 m_Buffer = NULL;
134 CTortoiseGitBlameView::~CTortoiseGitBlameView()
136 if (m_font)
137 DeleteObject(m_font);
138 if (m_italicfont)
139 DeleteObject(m_italicfont);
141 if(m_Buffer)
143 delete m_Buffer;
144 m_Buffer=NULL;
147 struct EncodingUnit
149 int id;
150 char *name;
153 void CTortoiseGitBlameView::OnChangeEncode(UINT nId)
156 static EncodingUnit encodings[] = {
157 {1250, "windows-1250"}, //IDM_FORMAT_WIN_1250
158 {1251, "windows-1251"}, //IDM_FORMAT_WIN_1251
159 {1252, "windows-1252"}, //IDM_FORMAT_WIN_1252
160 {1253, "windows-1253"}, //IDM_FORMAT_WIN_1253
161 {1254, "windows-1254"}, //IDM_FORMAT_WIN_1254
162 {1255, "windows-1255"}, //IDM_FORMAT_WIN_1255
163 {1256, "windows-1256"}, //IDM_FORMAT_WIN_1256
164 {1257, "windows-1257"}, //IDM_FORMAT_WIN_1257
165 {1258, "windows-1258"}, //IDM_FORMAT_WIN_1258
166 {28591, "latin1 ISO_8859-1 ISO-8859-1 CP819 IBM819 csISOLatin1 iso-ir-100 l1"}, //IDM_FORMAT_ISO_8859_1
167 {28592, "latin2 ISO_8859-2 ISO-8859-2 csISOLatin2 iso-ir-101 l2"}, //IDM_FORMAT_ISO_8859_2
168 {28593, "latin3 ISO_8859-3 ISO-8859-3 csISOLatin3 iso-ir-109 l3"}, //IDM_FORMAT_ISO_8859_3
169 {28594, "latin4 ISO_8859-4 ISO-8859-4 csISOLatin4 iso-ir-110 l4"}, //IDM_FORMAT_ISO_8859_4
170 {28595, "cyrillic ISO_8859-5 ISO-8859-5 csISOLatinCyrillic iso-ir-144"}, //IDM_FORMAT_ISO_8859_5
171 {28596, "arabic ISO_8859-6 ISO-8859-6 csISOLatinArabic iso-ir-127 ASMO-708 ECMA-114"}, //IDM_FORMAT_ISO_8859_6
172 {28597, "greek ISO_8859-7 ISO-8859-7 csISOLatinGreek greek8 iso-ir-126 ELOT_928 ECMA-118"}, //IDM_FORMAT_ISO_8859_7
173 {28598, "hebrew ISO_8859-8 ISO-8859-8 csISOLatinHebrew iso-ir-138"}, //IDM_FORMAT_ISO_8859_8
174 {28599, "latin5 ISO_8859-9 ISO-8859-9 csISOLatin5 iso-ir-148 l5"}, //IDM_FORMAT_ISO_8859_9
175 {28600, "latin6 ISO_8859-10 ISO-8859-10 csISOLatin6 iso-ir-157 l6"}, //IDM_FORMAT_ISO_8859_10
176 {28601, "ISO_8859-11 ISO-8859-11"}, //IDM_FORMAT_ISO_8859_11
177 {28603, "ISO_8859-13 ISO-8859-13"}, //IDM_FORMAT_ISO_8859_13
178 {28604, "iso-celtic latin8 ISO_8859-14 ISO-8859-14 18 iso-ir-199"}, //IDM_FORMAT_ISO_8859_14
179 {28605, "Latin-9 ISO_8859-15 ISO-8859-15"}, //IDM_FORMAT_ISO_8859_15
180 {28606, "latin10 ISO_8859-16 ISO-8859-16 110 iso-ir-226"}, //IDM_FORMAT_ISO_8859_16
181 {437, "IBM437 cp437 437 csPC8CodePage437"}, //IDM_FORMAT_DOS_437
182 {720, "IBM720 cp720 oem720 720"}, //IDM_FORMAT_DOS_720
183 {737, "IBM737 cp737 oem737 737"}, //IDM_FORMAT_DOS_737
184 {775, "IBM775 cp775 oem775 775"}, //IDM_FORMAT_DOS_775
185 {850, "IBM850 cp850 oem850 850"}, //IDM_FORMAT_DOS_850
186 {852, "IBM852 cp852 oem852 852"}, //IDM_FORMAT_DOS_852
187 {855, "IBM855 cp855 oem855 855 csIBM855"}, //IDM_FORMAT_DOS_855
188 {857, "IBM857 cp857 oem857 857"}, //IDM_FORMAT_DOS_857
189 {858, "IBM858 cp858 oem858 858"}, //IDM_FORMAT_DOS_858
190 {860, "IBM860 cp860 oem860 860"}, //IDM_FORMAT_DOS_860
191 {861, "IBM861 cp861 oem861 861"}, //IDM_FORMAT_DOS_861
192 {862, "IBM862 cp862 oem862 862"}, //IDM_FORMAT_DOS_862
193 {863, "IBM863 cp863 oem863 863"}, //IDM_FORMAT_DOS_863
194 {865, "IBM865 cp865 oem865 865"}, //IDM_FORMAT_DOS_865
195 {866, "IBM866 cp866 oem866 866"}, //IDM_FORMAT_DOS_866
196 {869, "IBM869 cp869 oem869 869"}, //IDM_FORMAT_DOS_869
197 {950, "big5 csBig5"}, //IDM_FORMAT_BIG5
198 {936, "gb2312 gbk csGB2312"}, //IDM_FORMAT_GB2312
199 {932, "Shift_JIS MS_Kanji csShiftJIS csWindows31J"}, //IDM_FORMAT_SHIFT_JIS
200 {949, "windows-949 korean"}, //IDM_FORMAT_KOREAN_WIN
201 {51949, "euc-kr csEUCKR"}, //IDM_FORMAT_EUC_KR
202 {874, "tis-620"}, //IDM_FORMAT_TIS_620
203 {10007, "x-mac-cyrillic xmaccyrillic"}, //IDM_FORMAT_MAC_CYRILLIC
204 {21866, "koi8_u"}, //IDM_FORMAT_KOI8U_CYRILLIC
205 {20866, "koi8_r csKOI8R"} //IDM_FORMAT_KOI8R_CYRILLIC
208 if(nId >= IDM_FORMAT_ENCODE && nId <= IDM_FORMAT_ENCODE_END)
209 this->UpdateInfo(encodings[nId - IDM_FORMAT_ENCODE].id);
211 int CTortoiseGitBlameView::OnCreate(LPCREATESTRUCT lpcs)
214 CRect rect,rect1;
215 this->GetWindowRect(&rect1);
216 rect.left=m_blamewidth+LOCATOR_WIDTH;
217 rect.right=rect.Width();
218 rect.top=0;
219 rect.bottom=rect.Height();
220 BOOL b=m_TextView.Create(_T("Scintilla"),_T("source"),0,rect,this,0,0);
221 m_TextView.Init(0,FALSE);
222 m_TextView.ShowWindow( SW_SHOW);
223 //m_TextView.InsertText(_T("Abdadfasdf"));
224 m_wEditor = m_TextView.m_hWnd;
225 CreateFont();
226 InitialiseEditor();
227 m_ToolTip.Create(this->GetParent());
228 m_ToolTip.AddTool(this,_T("Test"));
230 ::AfxGetApp()->GetMainWnd();
231 return CView::OnCreate(lpcs);
235 void CTortoiseGitBlameView::OnSize(UINT nType,int cx, int cy)
238 CRect rect;
239 rect.left=m_blamewidth;
240 rect.right=cx;
241 rect.top=0;
242 rect.bottom=cy;
244 m_TextView.MoveWindow(&rect);
247 BOOL CTortoiseGitBlameView::PreCreateWindow(CREATESTRUCT& cs)
249 // TODO: Modify the Window class or styles here by modifying
250 // the CREATESTRUCT cs
252 return CView::PreCreateWindow(cs);
255 // CTortoiseGitBlameView drawing
257 void CTortoiseGitBlameView::OnDraw(CDC* /*pDC*/)
259 CTortoiseGitBlameDoc* pDoc = GetDocument();
260 ASSERT_VALID(pDoc);
261 if (!pDoc)
262 return;
264 DrawBlame(this->GetDC()->m_hDC);
265 DrawLocatorBar(this->GetDC()->m_hDC);
266 // TODO: add draw code for native data here
270 // CTortoiseGitBlameView printing
273 void CTortoiseGitBlameView::OnFilePrintPreview()
275 AFXPrintPreview(this);
278 BOOL CTortoiseGitBlameView::OnPreparePrinting(CPrintInfo* pInfo)
280 // default preparation
281 return DoPreparePrinting(pInfo);
284 void CTortoiseGitBlameView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
286 // TODO: add extra initialization before printing
289 void CTortoiseGitBlameView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
291 // TODO: add cleanup after printing
294 void CTortoiseGitBlameView::OnRButtonUp(UINT nFlags, CPoint point)
296 ClientToScreen(&point);
297 OnContextMenu(this, point);
300 void CTortoiseGitBlameView::OnContextMenu(CWnd* pWnd, CPoint point)
302 theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE);
306 // CTortoiseGitBlameView diagnostics
308 #ifdef _DEBUG
309 void CTortoiseGitBlameView::AssertValid() const
311 CView::AssertValid();
314 void CTortoiseGitBlameView::Dump(CDumpContext& dc) const
316 CView::Dump(dc);
319 CTortoiseGitBlameDoc* CTortoiseGitBlameView::GetDocument() const // non-debug version is inline
321 ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTortoiseGitBlameDoc)));
322 return (CTortoiseGitBlameDoc*)m_pDocument;
324 #endif //_DEBUG
327 // CTortoiseGitBlameView message handlers
328 CString CTortoiseGitBlameView::GetAppDirectory()
330 CString path;
331 DWORD len = 0;
332 DWORD bufferlen = MAX_PATH; // MAX_PATH is not the limit here!
335 bufferlen += MAX_PATH; // MAX_PATH is not the limit here!
336 TCHAR * pBuf = new TCHAR[bufferlen];
337 len = GetModuleFileName(NULL, pBuf, bufferlen);
338 path = CString(pBuf, len);
339 delete [] pBuf;
340 } while(len == bufferlen);
342 path = path.Left(path.ReverseFind(_T('\\')));
343 //path = path.substr(0, path.rfind('\\') + 1);
345 return path;
348 // Return a color which is interpolated between c1 and c2.
349 // Slider controls the relative proportions as a percentage:
350 // Slider = 0 represents pure c1
351 // Slider = 50 represents equal mixture
352 // Slider = 100 represents pure c2
353 COLORREF CTortoiseGitBlameView::InterColor(COLORREF c1, COLORREF c2, int Slider)
355 int r, g, b;
357 // Limit Slider to 0..100% range
358 if (Slider < 0)
359 Slider = 0;
360 if (Slider > 100)
361 Slider = 100;
363 // The color components have to be treated individually.
364 r = (GetRValue(c2) * Slider + GetRValue(c1) * (100 - Slider)) / 100;
365 g = (GetGValue(c2) * Slider + GetGValue(c1) * (100 - Slider)) / 100;
366 b = (GetBValue(c2) * Slider + GetBValue(c1) * (100 - Slider)) / 100;
368 return RGB(r, g, b);
371 LRESULT CTortoiseGitBlameView::SendEditor(UINT Msg, WPARAM wParam, LPARAM lParam)
373 if (m_directFunction)
375 return ((SciFnDirect) m_directFunction)(m_directPointer, Msg, wParam, lParam);
377 return ::SendMessage(m_wEditor, Msg, wParam, lParam);
380 void CTortoiseGitBlameView::GetRange(int start, int end, char *text)
382 #if 0
383 TEXTRANGE tr;
384 tr.chrg.cpMin = start;
385 tr.chrg.cpMax = end;
386 tr.lpstrText = text;
388 SendMessage(m_wEditor, EM_GETTEXTRANGE, 0, reinterpret_cast<LPARAM>(&tr));
389 #endif
392 void CTortoiseGitBlameView::SetTitle()
394 #if 0
395 char title[MAX_PATH + 100];
396 strcpy_s(title, MAX_PATH + 100, szTitle);
397 strcat_s(title, MAX_PATH + 100, " - ");
398 strcat_s(title, MAX_PATH + 100, szViewtitle);
399 ::SetWindowText(wMain, title);
400 #endif
403 BOOL CTortoiseGitBlameView::OpenLogFile(const char *fileName)
405 #if 0
406 char logmsgbuf[10000+1];
407 FILE * File;
408 fopen_s(&File, fileName, "rb");
409 if (File == 0)
411 return FALSE;
413 LONG rev = 0;
414 CString msg;
415 int slength = 0;
416 int reallength = 0;
417 size_t len = 0;
418 wchar_t wbuf[MAX_LOG_LENGTH+6];
419 for (;;)
421 len = fread(&rev, sizeof(LONG), 1, File);
422 if (len == 0)
424 fclose(File);
425 InitSize();
426 return TRUE;
428 len = fread(&slength, sizeof(int), 1, File);
429 if (len == 0)
431 fclose(File);
432 InitSize();
433 return FALSE;
435 if (slength > MAX_LOG_LENGTH)
437 reallength = slength;
438 slength = MAX_LOG_LENGTH;
440 else
441 reallength = 0;
442 len = fread(logmsgbuf, sizeof(char), slength, File);
443 if (len < (size_t)slength)
445 fclose(File);
446 InitSize();
447 return FALSE;
449 msg = CString(logmsgbuf, slength);
450 if (reallength)
452 fseek(File, reallength-MAX_LOG_LENGTH, SEEK_CUR);
453 msg = msg + _T("\n...");
455 int len2 = ::MultiByteToWideChar(CP_UTF8, NULL, msg.c_str(), min(msg.size(), MAX_LOG_LENGTH+5), wbuf, MAX_LOG_LENGTH+5);
456 wbuf[len2] = 0;
457 len2 = ::WideCharToMultiByte(CP_ACP, NULL, wbuf, len2, logmsgbuf, MAX_LOG_LENGTH+5, NULL, NULL);
458 logmsgbuf[len2] = 0;
459 msg = CString(logmsgbuf);
460 logmessages[rev] = msg;
462 #endif
463 return TRUE;
466 BOOL CTortoiseGitBlameView::OpenFile(const char *fileName)
468 #if 0
469 SendEditor(SCI_SETREADONLY, FALSE);
470 SendEditor(SCI_CLEARALL);
471 SendEditor(EM_EMPTYUNDOBUFFER);
472 SetTitle();
473 SendEditor(SCI_SETSAVEPOINT);
474 SendEditor(SCI_CANCEL);
475 SendEditor(SCI_SETUNDOCOLLECTION, 0);
476 ::ShowWindow(m_wEditor, SW_HIDE);
477 std::ifstream File;
478 File.open(fileName);
479 if (!File.good())
481 return FALSE;
483 char line[100*1024];
484 char * lineptr = NULL;
485 char * trimptr = NULL;
486 //ignore the first two lines, they're of no interest to us
487 File.getline(line, sizeof(line)/sizeof(char));
488 File.getline(line, sizeof(line)/sizeof(char));
489 m_lowestrev = LONG_MAX;
490 m_highestrev = 0;
491 bool bUTF8 = true;
494 File.getline(line, sizeof(line)/sizeof(TCHAR));
495 if (File.gcount()>139)
497 mergelines.push_back((line[0] != ' '));
498 lineptr = &line[9];
499 long rev = _ttol(lineptr);
500 revs.push_back(rev);
501 m_lowestrev = min(m_lowestrev, rev);
502 m_highestrev = max(m_highestrev, rev);
503 lineptr += 7;
504 rev = _ttol(lineptr);
505 origrevs.push_back(rev);
506 lineptr += 7;
507 dates.push_back(CString(lineptr, 30));
508 lineptr += 31;
509 // unfortunately, the 'path' entry can be longer than the 60 chars
510 // we made the column. We therefore have to step through the path
511 // string until we find a space
512 trimptr = lineptr;
515 // TODO: how can we deal with the situation where the path has
516 // a space in it, but the space is after the 60 chars reserved
517 // for it?
518 // The only way to deal with that would be to use a custom
519 // binary format for the blame file.
520 trimptr++;
521 trimptr = _tcschr(trimptr, ' ');
522 } while ((trimptr)&&(trimptr+1 < lineptr+61));
523 if (trimptr)
524 *trimptr = 0;
525 else
526 trimptr = lineptr;
527 paths.push_back(CString(lineptr));
528 if (trimptr+1 < lineptr+61)
529 lineptr +=61;
530 else
531 lineptr = (trimptr+1);
532 trimptr = lineptr+30;
533 while ((*trimptr == ' ')&&(trimptr > lineptr))
534 trimptr--;
535 *(trimptr+1) = 0;
536 authors.push_back(CString(lineptr));
537 lineptr += 31;
538 // in case we find an UTF8 BOM at the beginning of the line, we remove it
539 if (((unsigned char)lineptr[0] == 0xEF)&&((unsigned char)lineptr[1] == 0xBB)&&((unsigned char)lineptr[2] == 0xBF))
541 lineptr += 3;
543 if (((unsigned char)lineptr[0] == 0xBB)&&((unsigned char)lineptr[1] == 0xEF)&&((unsigned char)lineptr[2] == 0xBF))
545 lineptr += 3;
547 // check each line for illegal utf8 sequences. If one is found, we treat
548 // the file as ASCII, otherwise we assume an UTF8 file.
549 char * utf8CheckBuf = lineptr;
550 while ((bUTF8)&&(*utf8CheckBuf))
552 if ((*utf8CheckBuf == 0xC0)||(*utf8CheckBuf == 0xC1)||(*utf8CheckBuf >= 0xF5))
554 bUTF8 = false;
555 break;
557 if ((*utf8CheckBuf & 0xE0)==0xC0)
559 utf8CheckBuf++;
560 if (*utf8CheckBuf == 0)
561 break;
562 if ((*utf8CheckBuf & 0xC0)!=0x80)
564 bUTF8 = false;
565 break;
568 if ((*utf8CheckBuf & 0xF0)==0xE0)
570 utf8CheckBuf++;
571 if (*utf8CheckBuf == 0)
572 break;
573 if ((*utf8CheckBuf & 0xC0)!=0x80)
575 bUTF8 = false;
576 break;
578 utf8CheckBuf++;
579 if (*utf8CheckBuf == 0)
580 break;
581 if ((*utf8CheckBuf & 0xC0)!=0x80)
583 bUTF8 = false;
584 break;
587 if ((*utf8CheckBuf & 0xF8)==0xF0)
589 utf8CheckBuf++;
590 if (*utf8CheckBuf == 0)
591 break;
592 if ((*utf8CheckBuf & 0xC0)!=0x80)
594 bUTF8 = false;
595 break;
597 utf8CheckBuf++;
598 if (*utf8CheckBuf == 0)
599 break;
600 if ((*utf8CheckBuf & 0xC0)!=0x80)
602 bUTF8 = false;
603 break;
605 utf8CheckBuf++;
606 if (*utf8CheckBuf == 0)
607 break;
608 if ((*utf8CheckBuf & 0xC0)!=0x80)
610 bUTF8 = false;
611 break;
615 utf8CheckBuf++;
617 SendEditor(SCI_ADDTEXT, _tcslen(lineptr), reinterpret_cast<LPARAM>(static_cast<char *>(lineptr)));
618 SendEditor(SCI_ADDTEXT, 2, (LPARAM)_T("\r\n"));
620 } while (File.gcount() > 0);
622 if (bUTF8)
623 SendEditor(SCI_SETCODEPAGE, SC_CP_UTF8);
625 SendEditor(SCI_SETUNDOCOLLECTION, 1);
626 ::SetFocus(m_wEditor);
627 SendEditor(EM_EMPTYUNDOBUFFER);
628 SendEditor(SCI_SETSAVEPOINT);
629 SendEditor(SCI_GOTOPOS, 0);
630 SendEditor(SCI_SETSCROLLWIDTHTRACKING, TRUE);
631 SendEditor(SCI_SETREADONLY, TRUE);
633 //check which lexer to use, depending on the filetype
634 SetupLexer(fileName);
635 ::ShowWindow(m_wEditor, SW_SHOW);
636 m_blamewidth = 0;
637 ::InvalidateRect(wMain, NULL, TRUE);
638 RECT rc;
639 GetWindowRect(wMain, &rc);
640 SetWindowPos(wMain, 0, rc.left, rc.top, rc.right-rc.left-1, rc.bottom - rc.top, 0);
641 #endif
642 return TRUE;
645 void CTortoiseGitBlameView::SetAStyle(int style, COLORREF fore, COLORREF back, int size, CString *face)
647 SendEditor(SCI_STYLESETFORE, style, fore);
648 SendEditor(SCI_STYLESETBACK, style, back);
649 if (size >= 1)
650 SendEditor(SCI_STYLESETSIZE, style, size);
651 if (face)
652 SendEditor(SCI_STYLESETFONT, style, reinterpret_cast<LPARAM>(this->m_TextView.StringForControl(*face).GetBuffer()));
655 void CTortoiseGitBlameView::InitialiseEditor()
658 m_directFunction = ::SendMessage(m_wEditor, SCI_GETDIRECTFUNCTION, 0, 0);
659 m_directPointer = ::SendMessage(m_wEditor, SCI_GETDIRECTPOINTER, 0, 0);
660 // Set up the global default style. These attributes are used wherever no explicit choices are made.
661 SetAStyle(STYLE_DEFAULT,
662 black,
663 white,
664 (DWORD)CRegStdWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10),
665 &CString(((stdstring)CRegStdString(_T("Software\\TortoiseGit\\BlameFontName"), _T("Courier New"))).c_str())
667 SendEditor(SCI_SETTABWIDTH, (DWORD)CRegStdWORD(_T("Software\\TortoiseGit\\BlameTabSize"), 4));
668 SendEditor(SCI_SETREADONLY, TRUE);
669 LRESULT pix = SendEditor(SCI_TEXTWIDTH, STYLE_LINENUMBER, (LPARAM)this->m_TextView.StringForControl(_T("_99999")).GetBuffer());
670 if (m_bShowLine)
671 SendEditor(SCI_SETMARGINWIDTHN, 0, pix);
672 else
673 SendEditor(SCI_SETMARGINWIDTHN, 0);
674 SendEditor(SCI_SETMARGINWIDTHN, 1);
675 SendEditor(SCI_SETMARGINWIDTHN, 2);
676 //Set the default windows colors for edit controls
677 SendEditor(SCI_STYLESETFORE, STYLE_DEFAULT, ::GetSysColor(COLOR_WINDOWTEXT));
678 SendEditor(SCI_STYLESETBACK, STYLE_DEFAULT, ::GetSysColor(COLOR_WINDOW));
679 SendEditor(SCI_SETSELFORE, TRUE, ::GetSysColor(COLOR_HIGHLIGHTTEXT));
680 SendEditor(SCI_SETSELBACK, TRUE, ::GetSysColor(COLOR_HIGHLIGHT));
681 SendEditor(SCI_SETCARETFORE, ::GetSysColor(COLOR_WINDOWTEXT));
682 m_regOldLinesColor = CRegStdWORD(_T("Software\\TortoiseGit\\BlameOldColor"), RGB(230, 230, 255));
683 m_regNewLinesColor = CRegStdWORD(_T("Software\\TortoiseGit\\BlameNewColor"), RGB(255, 230, 230));
685 this->m_TextView.Call(SCI_SETWRAPMODE, SC_WRAP_NONE);
689 void CTortoiseGitBlameView::StartSearch()
691 if (m_pFindDialog)
692 return;
693 bool bCase = false;
694 // Initialize FINDREPLACE
695 if (fr.Flags & FR_MATCHCASE)
696 bCase = true;
697 SecureZeroMemory(&fr, sizeof(fr));
698 fr.lStructSize = sizeof(fr);
699 fr.hwndOwner = wMain;
700 fr.lpstrFindWhat = szFindWhat;
701 fr.wFindWhatLen = 80;
702 fr.Flags = FR_HIDEUPDOWN | FR_HIDEWHOLEWORD;
703 fr.Flags |= bCase ? FR_MATCHCASE : 0;
705 currentDialog = FindText(&fr);
708 bool CTortoiseGitBlameView::DoSearch(CString what, DWORD flags)
711 //char szWhat[80];
712 int pos = SendEditor(SCI_GETCURRENTPOS);
713 int line = SendEditor(SCI_LINEFROMPOSITION, pos);
714 bool bFound = false;
715 bool bCaseSensitive = !!(flags & FR_MATCHCASE);
717 //strcpy_s(szWhat, sizeof(szWhat), what);
719 if(!bCaseSensitive)
721 what=what.MakeLower();
724 //CString sWhat = CString(szWhat);
726 //char buf[20];
727 //int i=0;
728 int i=line;
731 int bufsize = SendEditor(SCI_GETLINE, i);
732 char * linebuf = new char[bufsize+1];
733 SecureZeroMemory(linebuf, bufsize+1);
734 SendEditor(SCI_GETLINE, i, (LPARAM)linebuf);
735 CString oneline=this->m_TextView.StringFromControl(linebuf);
736 if (!bCaseSensitive)
738 oneline=oneline.MakeLower();
740 //_stprintf_s(buf, 20, _T("%ld"), revs[i]);
741 if (this->m_Authors[i].Find(what)>=0)
742 bFound = true;
743 else if ((!bCaseSensitive)&&(this->m_Authors[i].MakeLower().Find(what)>=0))
744 bFound = true;
745 else if (oneline.Find(what) >=0)
746 bFound = true;
748 delete [] linebuf;
750 i++;
751 if(i>=(signed int)m_CommitHash.size())
752 i=0;
753 }while(i!=line &&(!bFound));
755 if (bFound)
757 GotoLine(i);
758 int selstart = SendEditor(SCI_GETCURRENTPOS);
759 int selend = SendEditor(SCI_POSITIONFROMLINE, i);
760 SendEditor(SCI_SETSELECTIONSTART, selstart);
761 SendEditor(SCI_SETSELECTIONEND, selend);
762 m_SelectedLine = i-1;
764 else
766 ::MessageBox(wMain, what+_T(" not found"), _T("CTortoiseGitBlameView"), MB_ICONINFORMATION);
769 return true;
772 bool CTortoiseGitBlameView::GotoLine(long line)
774 --line;
775 if (line < 0)
776 return false;
777 if ((unsigned long)line >= m_CommitHash.size())
779 line = m_CommitHash.size()-1;
782 int nCurrentPos = SendEditor(SCI_GETCURRENTPOS);
783 int nCurrentLine = SendEditor(SCI_LINEFROMPOSITION,nCurrentPos);
784 int nFirstVisibleLine = SendEditor(SCI_GETFIRSTVISIBLELINE);
785 int nLinesOnScreen = SendEditor(SCI_LINESONSCREEN);
787 if ( line>=nFirstVisibleLine && line<=nFirstVisibleLine+nLinesOnScreen)
789 // no need to scroll
790 SendEditor(SCI_GOTOLINE, line);
792 else
794 // Place the requested line one third from the top
795 if ( line > nCurrentLine )
797 SendEditor(SCI_GOTOLINE, (WPARAM)(line+(int)nLinesOnScreen*(2/3.0)));
799 else
801 SendEditor(SCI_GOTOLINE, (WPARAM)(line-(int)nLinesOnScreen*(1/3.0)));
805 // Highlight the line
806 int nPosStart = SendEditor(SCI_POSITIONFROMLINE,line);
807 int nPosEnd = SendEditor(SCI_GETLINEENDPOSITION,line);
808 SendEditor(SCI_SETSEL,nPosEnd,nPosStart);
810 return true;
813 bool CTortoiseGitBlameView::ScrollToLine(long line)
815 if (line < 0)
816 return false;
818 int nCurrentLine = SendEditor(SCI_GETFIRSTVISIBLELINE);
820 int scrolldelta = line - nCurrentLine;
821 SendEditor(SCI_LINESCROLL, 0, scrolldelta);
823 return true;
826 void CTortoiseGitBlameView::CopySelectedLogToClipboard()
828 this->GetLogList()->CopySelectionToClipBoard(FALSE);
831 void CTortoiseGitBlameView::BlamePreviousRevision()
833 #if 0
834 LONG nRevisionTo = m_selectedorigrev - 1;
835 if ( nRevisionTo<1 )
837 return;
840 // We now determine the smallest revision number in the blame file (but ignore "-1")
841 // We do this for two reasons:
842 // 1. we respect the "From revision" which the user entered
843 // 2. we speed up the call of "svn blame" because previous smaller revision numbers don't have any effect on the result
844 LONG nSmallestRevision = -1;
845 for (LONG line=0;line<(LONG)app.revs.size();line++)
847 const LONG nRevision = app.revs[line];
848 if ( nRevision > 0 )
850 if ( nSmallestRevision < 1 )
852 nSmallestRevision = nRevision;
854 else
856 nSmallestRevision = min(nSmallestRevision,nRevision);
861 char bufStartRev[20];
862 _stprintf_s(bufStartRev, 20, _T("%d"), nSmallestRevision);
864 char bufEndRev[20];
865 _stprintf_s(bufEndRev, 20, _T("%d"), nRevisionTo);
867 char bufLine[20];
868 _stprintf_s(bufLine, 20, _T("%d"), m_SelectedLine+1); //using the current line is a good guess.
870 STARTUPINFO startup;
871 PROCESS_INFORMATION process;
872 memset(&startup, 0, sizeof(startup));
873 startup.cb = sizeof(startup);
874 memset(&process, 0, sizeof(process));
875 stdstring tortoiseProcPath = GetAppDirectory() + _T("TortoiseProc.exe");
876 stdstring svnCmd = _T(" /command:blame ");
877 svnCmd += _T(" /path:\"");
878 svnCmd += szOrigPath;
879 svnCmd += _T("\"");
880 svnCmd += _T(" /startrev:");
881 svnCmd += bufStartRev;
882 svnCmd += _T(" /endrev:");
883 svnCmd += bufEndRev;
884 svnCmd += _T(" /line:");
885 svnCmd += bufLine;
886 if (bIgnoreEOL)
887 svnCmd += _T(" /ignoreeol");
888 if (bIgnoreSpaces)
889 svnCmd += _T(" /ignorespaces");
890 if (bIgnoreAllSpaces)
891 svnCmd += _T(" /ignoreallspaces");
892 if (CreateProcess(tortoiseProcPath.c_str(), const_cast<TCHAR*>(svnCmd.c_str()), NULL, NULL, FALSE, 0, 0, 0, &startup, &process))
894 CloseHandle(process.hThread);
895 CloseHandle(process.hProcess);
897 #endif
900 void CTortoiseGitBlameView::DiffPreviousRevision()
902 #if 0
903 LONG nRevisionTo = m_selectedorigrev;
904 if ( nRevisionTo<1 )
906 return;
909 LONG nRevisionFrom = nRevisionTo-1;
911 char bufStartRev[20];
912 _stprintf_s(bufStartRev, 20, _T("%d"), nRevisionFrom);
914 char bufEndRev[20];
915 _stprintf_s(bufEndRev, 20, _T("%d"), nRevisionTo);
917 STARTUPINFO startup;
918 PROCESS_INFORMATION process;
919 memset(&startup, 0, sizeof(startup));
920 startup.cb = sizeof(startup);
921 memset(&process, 0, sizeof(process));
922 stdstring tortoiseProcPath = GetAppDirectory() + _T("TortoiseProc.exe");
923 stdstring svnCmd = _T(" /command:diff ");
924 svnCmd += _T(" /path:\"");
925 svnCmd += szOrigPath;
926 svnCmd += _T("\"");
927 svnCmd += _T(" /startrev:");
928 svnCmd += bufStartRev;
929 svnCmd += _T(" /endrev:");
930 svnCmd += bufEndRev;
931 if (CreateProcess(tortoiseProcPath.c_str(), const_cast<TCHAR*>(svnCmd.c_str()), NULL, NULL, FALSE, 0, 0, 0, &startup, &process))
933 CloseHandle(process.hThread);
934 CloseHandle(process.hProcess);
936 #endif
939 void CTortoiseGitBlameView::ShowLog()
941 #if 0
942 char bufRev[20];
943 _stprintf_s(bufRev, 20, _T("%d"), m_selectedorigrev);
945 STARTUPINFO startup;
946 PROCESS_INFORMATION process;
947 memset(&startup, 0, sizeof(startup));
948 startup.cb = sizeof(startup);
949 memset(&process, 0, sizeof(process));
950 stdstring tortoiseProcPath = GetAppDirectory() + _T("TortoiseProc.exe");
951 stdstring svnCmd = _T(" /command:log ");
952 svnCmd += _T(" /path:\"");
953 svnCmd += szOrigPath;
954 svnCmd += _T("\"");
955 svnCmd += _T(" /startrev:");
956 svnCmd += bufRev;
957 svnCmd += _T(" /pegrev:");
958 svnCmd += bufRev;
959 if (CreateProcess(tortoiseProcPath.c_str(), const_cast<TCHAR*>(svnCmd.c_str()), NULL, NULL, FALSE, 0, 0, 0, &startup, &process))
961 CloseHandle(process.hThread);
962 CloseHandle(process.hProcess);
964 #endif
967 void CTortoiseGitBlameView::Notify(SCNotification *notification)
969 switch (notification->nmhdr.code)
971 case SCN_SAVEPOINTREACHED:
972 break;
974 case SCN_SAVEPOINTLEFT:
975 break;
976 case SCN_PAINTED:
977 // InvalidateRect(wBlame, NULL, FALSE);
978 // InvalidateRect(wLocator, NULL, FALSE);
979 break;
980 case SCN_GETBKCOLOR:
981 // if ((m_colorage)&&(notification->line < (int)revs.size()))
982 // {
983 // notification->lParam = InterColor(DWORD(m_regOldLinesColor), DWORD(m_regNewLinesColor), (revs[notification->line]-m_lowestrev)*100/((m_highestrev-m_lowestrev)+1));
984 // }
985 break;
989 void CTortoiseGitBlameView::Command(int id)
991 #if 0
992 switch (id)
994 // case IDM_EXIT:
995 // ::PostQuitMessage(0);
996 // break;
997 case ID_EDIT_FIND:
998 StartSearch();
999 break;
1000 case ID_COPYTOCLIPBOARD:
1001 CopySelectedLogToClipboard();
1002 break;
1003 case ID_BLAME_PREVIOUS_REVISION:
1004 BlamePreviousRevision();
1005 break;
1006 case ID_DIFF_PREVIOUS_REVISION:
1007 DiffPreviousRevision();
1008 break;
1009 case ID_SHOWLOG:
1010 ShowLog();
1011 break;
1012 case ID_EDIT_GOTOLINE:
1013 GotoLineDlg();
1014 break;
1015 case ID_VIEW_COLORAGEOFLINES:
1017 m_colorage = !m_colorage;
1018 HMENU hMenu = GetMenu(wMain);
1019 UINT uCheck = MF_BYCOMMAND;
1020 uCheck |= m_colorage ? MF_CHECKED : MF_UNCHECKED;
1021 CheckMenuItem(hMenu, ID_VIEW_COLORAGEOFLINES, uCheck);
1022 m_blamewidth = 0;
1023 InitSize();
1025 break;
1026 case ID_VIEW_MERGEPATH:
1028 ShowPath = !ShowPath;
1029 HMENU hMenu = GetMenu(wMain);
1030 UINT uCheck = MF_BYCOMMAND;
1031 uCheck |= ShowPath ? MF_CHECKED : MF_UNCHECKED;
1032 CheckMenuItem(hMenu, ID_VIEW_MERGEPATH, uCheck);
1033 m_blamewidth = 0;
1034 InitSize();
1036 default:
1037 break;
1039 #endif
1043 LONG CTortoiseGitBlameView::GetBlameWidth()
1045 LONG blamewidth = 0;
1046 SIZE width;
1047 CreateFont();
1048 HDC hDC = this->GetDC()->m_hDC;
1049 HFONT oldfont = (HFONT)::SelectObject(hDC, m_font);
1051 TCHAR buf[MAX_PATH];
1053 int maxnum=0;
1054 for (unsigned int i=0;i<this->m_ID.size();i++)
1056 if(m_ID[i]>maxnum)
1057 maxnum=m_ID[i];
1059 _stprintf_s(buf, MAX_PATH, _T("%d."), maxnum);
1060 ::GetTextExtentPoint(hDC, buf, _tcslen(buf), &width);
1061 m_revwidth = width.cx + BLAMESPACE;
1062 blamewidth += m_revwidth;
1064 #if 0
1065 _stprintf_s(buf, MAX_PATH, _T("%d"), m_CommitHash.size());
1066 ::GetTextExtentPoint(hDC, buf, _tcslen(buf), &width);
1067 m_linewidth = width.cx + BLAMESPACE;
1068 blamewidth += m_revwidth;
1069 #endif
1071 if (m_bShowDate)
1073 _stprintf_s(buf, MAX_PATH, _T("%30s"), _T("31.08.2001 06:24:14"));
1074 ::GetTextExtentPoint32(hDC, buf, _tcslen(buf), &width);
1075 m_datewidth = width.cx + BLAMESPACE;
1076 blamewidth += m_datewidth;
1078 if ( m_bShowAuthor)
1080 SIZE maxwidth = {0};
1082 for (unsigned int i=0;i<this->m_Authors.size();i++)
1083 //for (std::vector<CString>::iterator I = authors.begin(); I != authors.end(); ++I)
1085 ::GetTextExtentPoint32(hDC,m_Authors[i] , m_Authors[i].GetLength(), &width);
1086 if (width.cx > maxwidth.cx)
1087 maxwidth = width;
1089 m_authorwidth = maxwidth.cx + BLAMESPACE;
1090 blamewidth += m_authorwidth;
1092 #if 0
1093 if (ShowPath)
1095 SIZE maxwidth = {0};
1096 for (std::vector<CString>::iterator I = paths.begin(); I != paths.end(); ++I)
1098 ::GetTextExtentPoint32(hDC, I->c_str(), I->size(), &width);
1099 if (width.cx > maxwidth.cx)
1100 maxwidth = width;
1102 m_pathwidth = maxwidth.cx + BLAMESPACE;
1103 blamewidth += m_pathwidth;
1105 #endif
1106 ::SelectObject(hDC, oldfont);
1107 POINT pt = {blamewidth, 0};
1108 LPtoDP(hDC, &pt, 1);
1109 m_blamewidth = pt.x;
1110 //::ReleaseDC(wBlame, hDC);
1112 //return m_blamewidth;
1113 return blamewidth;
1117 void CTortoiseGitBlameView::CreateFont()
1119 if (m_font)
1120 return;
1121 LOGFONT lf = {0};
1122 lf.lfWeight = 400;
1123 HDC hDC = ::GetDC(wBlame);
1124 lf.lfHeight = -MulDiv((DWORD)CRegStdWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10), GetDeviceCaps(hDC, LOGPIXELSY), 72);
1125 lf.lfCharSet = DEFAULT_CHARSET;
1126 CRegStdString fontname = CRegStdString(_T("Software\\TortoiseGit\\BlameFontName"), _T("Courier New"));
1127 _tcscpy_s(lf.lfFaceName, 32, ((stdstring)fontname).c_str());
1128 m_font = ::CreateFontIndirect(&lf);
1130 lf.lfItalic = TRUE;
1131 m_italicfont = ::CreateFontIndirect(&lf);
1133 ::ReleaseDC(wBlame, hDC);
1135 //m_TextView.SetFont(lf.lfFaceName,((DWORD)CRegStdWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10)));
1138 void CTortoiseGitBlameView::DrawBlame(HDC hDC)
1141 if (hDC == NULL)
1142 return;
1143 if (m_font == NULL)
1144 return;
1146 HFONT oldfont = NULL;
1147 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
1148 LONG_PTR linesonscreen = SendEditor(SCI_LINESONSCREEN);
1149 LONG_PTR height = SendEditor(SCI_TEXTHEIGHT);
1150 LONG_PTR Y = 0;
1151 TCHAR buf[MAX_PATH];
1152 RECT rc;
1153 BOOL sel = FALSE;
1154 //::GetClientRect(this->m_hWnd, &rc);
1155 for (LRESULT i=line; i<(line+linesonscreen); ++i)
1157 sel = FALSE;
1158 if (i < (int)m_CommitHash.size())
1160 // if (mergelines[i])
1161 // oldfont = (HFONT)::SelectObject(hDC, m_italicfont);
1162 // else
1163 oldfont = (HFONT)::SelectObject(hDC, m_font);
1164 ::SetBkColor(hDC, m_windowcolor);
1165 ::SetTextColor(hDC, m_textcolor);
1166 if (!m_CommitHash[i].IsEmpty())
1168 //if (m_CommitHash[i].Compare(m_MouseHash)==0)
1169 // ::SetBkColor(hDC, m_mouseauthorcolor);
1170 if (m_CommitHash[i] == m_SelectedHash )
1172 ::SetBkColor(hDC, m_selectedauthorcolor);
1173 ::SetTextColor(hDC, m_texthighlightcolor);
1174 sel = TRUE;
1178 if(m_MouseLine == i)
1179 ::SetBkColor(hDC, m_mouserevcolor);
1181 //if ((revs[i] == m_mouserev)&&(!sel))
1182 // ::SetBkColor(hDC, m_mouserevcolor);
1183 //if (revs[i] == m_selectedrev)
1185 // ::SetBkColor(hDC, m_selectedrevcolor);
1186 // ::SetTextColor(hDC, m_texthighlightcolor);
1189 CString str;
1190 if(i<m_ID.size() && m_ID[i]>=0)
1191 str.Format(_T("%d"),m_ID[i]);
1193 //_stprintf_s(buf, MAX_PATH, _T("%8ld "), revs[i]);
1194 rc.top=Y;
1195 rc.left=LOCATOR_WIDTH;
1196 rc.bottom=Y+height;
1197 rc.right = rc.left + m_blamewidth;
1198 ::ExtTextOut(hDC, LOCATOR_WIDTH, Y, ETO_CLIPPED, &rc, str, str.GetLength(), 0);
1199 int Left = m_revwidth;
1201 if (m_bShowAuthor)
1203 rc.right = rc.left + Left + m_authorwidth;
1204 //_stprintf_s(buf, MAX_PATH, _T("%-30s "), authors[i].c_str());
1205 ::ExtTextOut(hDC, Left, Y, ETO_CLIPPED, &rc, m_Authors[i], m_Authors[i].GetLength(), 0);
1206 Left += m_authorwidth;
1208 #if 0
1209 if (ShowDate)
1211 rc.right = rc.left + Left + m_datewidth;
1212 _stprintf_s(buf, MAX_PATH, _T("%30s "), dates[i].c_str());
1213 ::ExtTextOut(hDC, Left, Y, ETO_CLIPPED, &rc, buf, _tcslen(buf), 0);
1214 Left += m_datewidth;
1217 #endif
1218 #if 0
1219 if (ShowPath)
1221 rc.right = rc.left + Left + m_pathwidth;
1222 _stprintf_s(buf, MAX_PATH, _T("%-60s "), paths[i].c_str());
1223 ::ExtTextOut(hDC, Left, Y, ETO_CLIPPED, &rc, buf, _tcslen(buf), 0);
1224 Left += m_authorwidth;
1226 #endif
1227 if ((i==m_SelectedLine)&&(m_pFindDialog))
1229 LOGBRUSH brush;
1230 brush.lbColor = m_textcolor;
1231 brush.lbHatch = 0;
1232 brush.lbStyle = BS_SOLID;
1233 HPEN pen = ExtCreatePen(PS_SOLID | PS_GEOMETRIC, 2, &brush, 0, NULL);
1234 HGDIOBJ hPenOld = SelectObject(hDC, pen);
1235 RECT rc2 = rc;
1236 rc2.top = Y;
1237 rc2.bottom = Y + height;
1238 ::MoveToEx(hDC, rc2.left, rc2.top, NULL);
1239 ::LineTo(hDC, rc2.right, rc2.top);
1240 ::LineTo(hDC, rc2.right, rc2.bottom);
1241 ::LineTo(hDC, rc2.left, rc2.bottom);
1242 ::LineTo(hDC, rc2.left, rc2.top);
1243 SelectObject(hDC, hPenOld);
1244 DeleteObject(pen);
1246 Y += height;
1247 ::SelectObject(hDC, oldfont);
1249 else
1251 ::SetBkColor(hDC, m_windowcolor);
1252 for (int j=0; j< MAX_PATH; ++j)
1253 buf[j]=' ';
1254 ::ExtTextOut(hDC, 0, Y, ETO_CLIPPED, &rc, buf, MAX_PATH-1, 0);
1255 Y += height;
1260 void CTortoiseGitBlameView::DrawHeader(HDC hDC)
1262 #if 0
1263 if (hDC == NULL)
1264 return;
1266 RECT rc;
1267 HFONT oldfont = (HFONT)::SelectObject(hDC, GetStockObject(DEFAULT_GUI_FONT));
1268 ::GetClientRect(wHeader, &rc);
1270 ::SetBkColor(hDC, ::GetSysColor(COLOR_BTNFACE));
1272 TCHAR szText[MAX_LOADSTRING];
1273 LoadString(app.hResource, IDS_HEADER_REVISION, szText, MAX_LOADSTRING);
1274 ::ExtTextOut(hDC, LOCATOR_WIDTH, 0, ETO_CLIPPED, &rc, szText, _tcslen(szText), 0);
1275 int Left = m_revwidth+LOCATOR_WIDTH;
1276 if (ShowDate)
1278 LoadString(app.hResource, IDS_HEADER_DATE, szText, MAX_LOADSTRING);
1279 ::ExtTextOut(hDC, Left, 0, ETO_CLIPPED, &rc, szText, _tcslen(szText), 0);
1280 Left += m_datewidth;
1282 if (ShowAuthor)
1284 LoadString(app.hResource, IDS_HEADER_AUTHOR, szText, MAX_LOADSTRING);
1285 ::ExtTextOut(hDC, Left, 0, ETO_CLIPPED, &rc, szText, _tcslen(szText), 0);
1286 Left += m_authorwidth;
1288 if (ShowPath)
1290 LoadString(app.hResource, IDS_HEADER_PATH, szText, MAX_LOADSTRING);
1291 ::ExtTextOut(hDC, Left, 0, ETO_CLIPPED, &rc, szText, _tcslen(szText), 0);
1292 Left += m_pathwidth;
1294 LoadString(app.hResource, IDS_HEADER_LINE, szText, MAX_LOADSTRING);
1295 ::ExtTextOut(hDC, Left, 0, ETO_CLIPPED, &rc, szText, _tcslen(szText), 0);
1297 ::SelectObject(hDC, oldfont);
1298 #endif
1301 void CTortoiseGitBlameView::DrawLocatorBar(HDC hDC)
1303 if (hDC == NULL)
1304 return;
1306 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
1307 LONG_PTR linesonscreen = SendEditor(SCI_LINESONSCREEN);
1308 LONG_PTR Y = 0;
1309 COLORREF blackColor = GetSysColor(COLOR_WINDOWTEXT);
1311 RECT rc;
1312 //::GetClientRect(wLocator, &rc);
1313 this->GetClientRect(&rc);
1315 rc.right=LOCATOR_WIDTH;
1317 RECT lineRect = rc;
1318 LONG height = rc.bottom-rc.top;
1319 LONG currentLine = 0;
1321 // draw the colored bar
1322 for (std::vector<LONG>::const_iterator it = m_ID.begin(); it != m_ID.end(); ++it)
1324 currentLine++;
1325 // get the line color
1326 COLORREF cr = InterColor(DWORD(m_regOldLinesColor), DWORD(m_regNewLinesColor), (*it - m_lowestrev)*100/((m_highestrev-m_lowestrev)+1));
1327 if ((currentLine > line)&&(currentLine <= (line + linesonscreen)))
1329 cr = InterColor(cr, blackColor, 10);
1331 SetBkColor(hDC, cr);
1332 lineRect.top = Y;
1333 lineRect.bottom = (currentLine * height / m_ID.size());
1334 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, NULL, 0, NULL);
1335 Y = lineRect.bottom;
1338 if (m_ID.size())
1340 // now draw two lines indicating the scroll position of the source view
1341 SetBkColor(hDC, blackColor);
1342 lineRect.top = line * height / m_ID.size();
1343 lineRect.bottom = lineRect.top+1;
1344 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, NULL, 0, NULL);
1345 lineRect.top = (line + linesonscreen) * height / m_ID.size();
1346 lineRect.bottom = lineRect.top+1;
1347 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, NULL, 0, NULL);
1352 void CTortoiseGitBlameView::StringExpand(LPSTR str)
1354 char * cPos = str;
1357 cPos = strchr(cPos, '\n');
1358 if (cPos)
1360 memmove(cPos+1, cPos, strlen(cPos)*sizeof(char));
1361 *cPos = '\r';
1362 cPos++;
1363 cPos++;
1365 } while (cPos != NULL);
1367 void CTortoiseGitBlameView::StringExpand(LPWSTR str)
1369 wchar_t * cPos = str;
1372 cPos = wcschr(cPos, '\n');
1373 if (cPos)
1375 memmove(cPos+1, cPos, wcslen(cPos)*sizeof(wchar_t));
1376 *cPos = '\r';
1377 cPos++;
1378 cPos++;
1380 } while (cPos != NULL);
1383 // Forward declarations of functions included in this code module:
1384 ATOM MyRegisterClass(HINSTANCE hResource);
1385 ATOM MyRegisterBlameClass(HINSTANCE hResource);
1386 ATOM MyRegisterHeaderClass(HINSTANCE hResource);
1387 ATOM MyRegisterLocatorClass(HINSTANCE hResource);
1388 BOOL InitInstance(HINSTANCE, int);
1389 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
1390 LRESULT CALLBACK WndBlameProc(HWND, UINT, WPARAM, LPARAM);
1391 LRESULT CALLBACK WndHeaderProc(HWND, UINT, WPARAM, LPARAM);
1392 LRESULT CALLBACK WndLocatorProc(HWND, UINT, WPARAM, LPARAM);
1393 UINT uFindReplaceMsg;
1395 #if 0
1396 int APIENTRY _tWinMain(HINSTANCE hInstance,
1397 HINSTANCE /*hPrevInstance*/,
1398 LPTSTR lpCmdLine,
1399 int nCmdShow)
1401 app.hInstance = hInstance;
1402 MSG msg;
1403 HACCEL hAccelTable;
1405 if (::LoadLibrary("SciLexer.DLL") == NULL)
1406 return FALSE;
1408 CRegStdWORD loc = CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033);
1409 long langId = loc;
1411 CLangDll langDLL;
1412 app.hResource = langDLL.Init(_T("CTortoiseGitBlameView"), langId);
1413 if (app.hResource == NULL)
1414 app.hResource = app.hInstance;
1416 // Initialize global strings
1417 LoadString(app.hResource, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
1418 LoadString(app.hResource, IDC_TortoiseGitBlameView, szWindowClass, MAX_LOADSTRING);
1419 LoadString(app.hResource, IDS_SEARCHNOTFOUND, searchstringnotfound, MAX_LOADSTRING);
1420 MyRegisterClass(app.hResource);
1421 MyRegisterBlameClass(app.hResource);
1422 MyRegisterHeaderClass(app.hResource);
1423 MyRegisterLocatorClass(app.hResource);
1425 // Perform application initialization:
1426 if (!InitInstance (app.hResource, nCmdShow))
1428 langDLL.Close();
1429 return FALSE;
1432 SecureZeroMemory(szViewtitle, MAX_PATH);
1433 SecureZeroMemory(szOrigPath, MAX_PATH);
1434 char blamefile[MAX_PATH] = {0};
1435 char logfile[MAX_PATH] = {0};
1437 CCmdLineParser parser(lpCmdLine);
1440 if (__argc > 1)
1442 _tcscpy_s(blamefile, MAX_PATH, __argv[1]);
1444 if (__argc > 2)
1446 _tcscpy_s(logfile, MAX_PATH, __argv[2]);
1448 if (__argc > 3)
1450 _tcscpy_s(szViewtitle, MAX_PATH, __argv[3]);
1451 if (parser.HasVal(_T("revrange")))
1453 _tcscat_s(szViewtitle, MAX_PATH, _T(" : "));
1454 _tcscat_s(szViewtitle, MAX_PATH, parser.GetVal(_T("revrange")));
1457 if ((_tcslen(blamefile)==0) || parser.HasKey(_T("?")) || parser.HasKey(_T("help")))
1459 TCHAR szInfo[MAX_LOADSTRING];
1460 LoadString(app.hResource, IDS_COMMANDLINE_INFO, szInfo, MAX_LOADSTRING);
1461 MessageBox(NULL, szInfo, _T("CTortoiseGitBlameView"), MB_ICONERROR);
1462 langDLL.Close();
1463 return 0;
1466 if ( parser.HasKey(_T("path")) )
1468 _tcscpy_s(szOrigPath, MAX_PATH, parser.GetVal(_T("path")));
1470 app.bIgnoreEOL = parser.HasKey(_T("ignoreeol"));
1471 app.bIgnoreSpaces = parser.HasKey(_T("ignorespaces"));
1472 app.bIgnoreAllSpaces = parser.HasKey(_T("ignoreallspaces"));
1474 app.SendEditor(SCI_SETCODEPAGE, GetACP());
1475 app.OpenFile(blamefile);
1476 if (_tcslen(logfile)>0)
1477 app.OpenLogFile(logfile);
1479 if (parser.HasKey(_T("line")))
1481 app.GotoLine(parser.GetLongVal(_T("line")));
1484 CheckMenuItem(GetMenu(app.wMain), ID_VIEW_COLORAGEOFLINES, MF_CHECKED|MF_BYCOMMAND);
1487 hAccelTable = LoadAccelerators(app.hResource, (LPCTSTR)IDC_TortoiseGitBlameView);
1489 BOOL going = TRUE;
1490 msg.wParam = 0;
1491 while (going)
1493 going = GetMessage(&msg, NULL, 0, 0);
1494 if (app.currentDialog && going)
1496 if (!IsDialogMessage(app.currentDialog, &msg))
1498 if (TranslateAccelerator(msg.hwnd, hAccelTable, &msg) == 0)
1500 TranslateMessage(&msg);
1501 DispatchMessage(&msg);
1505 else if (going)
1507 if (TranslateAccelerator(app.wMain, hAccelTable, &msg) == 0)
1509 TranslateMessage(&msg);
1510 DispatchMessage(&msg);
1514 langDLL.Close();
1515 return msg.wParam;
1518 ATOM MyRegisterClass(HINSTANCE hResource)
1520 WNDCLASSEX wcex;
1522 wcex.cbSize = sizeof(WNDCLASSEX);
1524 wcex.style = CS_HREDRAW | CS_VREDRAW;
1525 wcex.lpfnWndProc = (WNDPROC)WndProc;
1526 wcex.cbClsExtra = 0;
1527 wcex.cbWndExtra = 0;
1528 wcex.hInstance = hResource;
1529 wcex.hIcon = LoadIcon(hResource, (LPCTSTR)IDI_TortoiseGitBlameView);
1530 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
1531 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
1532 wcex.lpszMenuName = (LPCTSTR)IDC_TortoiseGitBlameView;
1533 wcex.lpszClassName = szWindowClass;
1534 wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
1536 return RegisterClassEx(&wcex);
1539 ATOM MyRegisterBlameClass(HINSTANCE hResource)
1541 WNDCLASSEX wcex;
1543 wcex.cbSize = sizeof(WNDCLASSEX);
1545 wcex.style = CS_HREDRAW | CS_VREDRAW;
1546 wcex.lpfnWndProc = (WNDPROC)WndBlameProc;
1547 wcex.cbClsExtra = 0;
1548 wcex.cbWndExtra = 0;
1549 wcex.hInstance = hResource;
1550 wcex.hIcon = LoadIcon(hResource, (LPCTSTR)IDI_TortoiseGitBlameView);
1551 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
1552 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
1553 wcex.lpszMenuName = 0;
1554 wcex.lpszClassName = _T("TortoiseGitBlameViewBlame");
1555 wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
1557 return RegisterClassEx(&wcex);
1560 ATOM MyRegisterHeaderClass(HINSTANCE hResource)
1562 WNDCLASSEX wcex;
1564 wcex.cbSize = sizeof(WNDCLASSEX);
1566 wcex.style = CS_HREDRAW | CS_VREDRAW;
1567 wcex.lpfnWndProc = (WNDPROC)WndHeaderProc;
1568 wcex.cbClsExtra = 0;
1569 wcex.cbWndExtra = 0;
1570 wcex.hInstance = hResource;
1571 wcex.hIcon = LoadIcon(hResource, (LPCTSTR)IDI_TortoiseGitBlameView);
1572 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
1573 wcex.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
1574 wcex.lpszMenuName = 0;
1575 wcex.lpszClassName = _T("TortoiseGitBlameViewHeader");
1576 wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
1578 return RegisterClassEx(&wcex);
1581 ATOM MyRegisterLocatorClass(HINSTANCE hResource)
1583 WNDCLASSEX wcex;
1585 wcex.cbSize = sizeof(WNDCLASSEX);
1587 wcex.style = CS_HREDRAW | CS_VREDRAW;
1588 wcex.lpfnWndProc = (WNDPROC)WndLocatorProc;
1589 wcex.cbClsExtra = 0;
1590 wcex.cbWndExtra = 0;
1591 wcex.hInstance = hResource;
1592 wcex.hIcon = LoadIcon(hResource, (LPCTSTR)IDI_TortoiseGitBlameView);
1593 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
1594 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
1595 wcex.lpszMenuName = 0;
1596 wcex.lpszClassName = _T("TortoiseGitBlameViewLocator");
1597 wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
1599 return RegisterClassEx(&wcex);
1602 BOOL InitInstance(HINSTANCE hResource, int nCmdShow)
1604 app.wMain = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
1605 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hResource, NULL);
1607 if (!app.wMain)
1609 return FALSE;
1612 CRegStdWORD pos(_T("Software\\TortoiseGit\\TBlamePos"), 0);
1613 CRegStdWORD width(_T("Software\\TortoiseGit\\TBlameSize"), 0);
1614 CRegStdWORD state(_T("Software\\TortoiseGit\\TBlameState"), 0);
1615 if (DWORD(pos) && DWORD(width))
1617 RECT rc;
1618 rc.left = LOWORD(DWORD(pos));
1619 rc.top = HIWORD(DWORD(pos));
1620 rc.right = rc.left + LOWORD(DWORD(width));
1621 rc.bottom = rc.top + HIWORD(DWORD(width));
1622 HMONITOR hMon = MonitorFromRect(&rc, MONITOR_DEFAULTTONULL);
1623 if (hMon)
1625 // only restore the window position if the monitor is valid
1626 MoveWindow(app.wMain, LOWORD(DWORD(pos)), HIWORD(DWORD(pos)),
1627 LOWORD(DWORD(width)), HIWORD(DWORD(width)), FALSE);
1630 if (DWORD(state) == SW_MAXIMIZE)
1631 ShowWindow(app.wMain, SW_MAXIMIZE);
1632 else
1633 ShowWindow(app.wMain, nCmdShow);
1634 UpdateWindow(app.wMain);
1636 //Create the tooltips
1638 INITCOMMONCONTROLSEX iccex;
1639 app.hwndTT; // handle to the ToolTip control
1640 TOOLINFO ti;
1641 RECT rect; // for client area coordinates
1642 iccex.dwICC = ICC_WIN95_CLASSES;
1643 iccex.dwSize = sizeof(INITCOMMONCONTROLSEX);
1644 InitCommonControlsEx(&iccex);
1646 /* CREATE A TOOLTIP WINDOW */
1647 app.hwndTT = CreateWindowEx(WS_EX_TOPMOST,
1648 TOOLTIPS_CLASS,
1649 NULL,
1650 WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
1651 CW_USEDEFAULT,
1652 CW_USEDEFAULT,
1653 CW_USEDEFAULT,
1654 CW_USEDEFAULT,
1655 app.wBlame,
1656 NULL,
1657 app.hResource,
1658 NULL
1661 SetWindowPos(app.hwndTT,
1662 HWND_TOPMOST,
1667 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
1669 /* GET COORDINATES OF THE MAIN CLIENT AREA */
1670 GetClientRect (app.wBlame, &rect);
1672 /* INITIALIZE MEMBERS OF THE TOOLINFO STRUCTURE */
1673 ti.cbSize = sizeof(TOOLINFO);
1674 ti.uFlags = TTF_TRACK | TTF_ABSOLUTE;//TTF_SUBCLASS | TTF_PARSELINKS;
1675 ti.hwnd = app.wBlame;
1676 ti.hinst = app.hResource;
1677 ti.uId = 0;
1678 ti.lpszText = LPSTR_TEXTCALLBACK;
1679 // ToolTip control will cover the whole window
1680 ti.rect.left = rect.left;
1681 ti.rect.top = rect.top;
1682 ti.rect.right = rect.right;
1683 ti.rect.bottom = rect.bottom;
1685 /* SEND AN ADDTOOL MESSAGE TO THE TOOLTIP CONTROL WINDOW */
1686 SendMessage(app.hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
1687 SendMessage(app.hwndTT, TTM_SETMAXTIPWIDTH, 0, 600);
1688 //SendMessage(app.hwndTT, TTM_SETDELAYTIME, TTDT_AUTOPOP, MAKELONG(50000, 0));
1689 //SendMessage(app.hwndTT, TTM_SETDELAYTIME, TTDT_RESHOW, MAKELONG(1000, 0));
1691 uFindReplaceMsg = RegisterWindowMessage(FINDMSGSTRING);
1693 return TRUE;
1695 #endif
1696 void CTortoiseGitBlameView::InitSize()
1698 RECT rc;
1699 RECT blamerc;
1700 RECT sourcerc;
1701 ::GetClientRect(wMain, &rc);
1702 ::SetWindowPos(wHeader, 0, rc.left, rc.top, rc.right-rc.left, HEADER_HEIGHT, 0);
1703 rc.top += HEADER_HEIGHT;
1704 blamerc.left = rc.left;
1705 blamerc.top = rc.top;
1706 LONG w = GetBlameWidth();
1707 blamerc.right = w > abs(rc.right - rc.left) ? rc.right : w + rc.left;
1708 blamerc.bottom = rc.bottom;
1709 sourcerc.left = blamerc.right;
1710 sourcerc.top = rc.top;
1711 sourcerc.bottom = rc.bottom;
1712 sourcerc.right = rc.right;
1713 if (m_colorage)
1715 ::OffsetRect(&blamerc, LOCATOR_WIDTH, 0);
1716 ::OffsetRect(&sourcerc, LOCATOR_WIDTH, 0);
1717 sourcerc.right -= LOCATOR_WIDTH;
1719 ::InvalidateRect(wMain, NULL, FALSE);
1720 ::SetWindowPos(m_wEditor, 0, sourcerc.left, sourcerc.top, sourcerc.right - sourcerc.left, sourcerc.bottom - sourcerc.top, 0);
1721 ::SetWindowPos(wBlame, 0, blamerc.left, blamerc.top, blamerc.right - blamerc.left, blamerc.bottom - blamerc.top, 0);
1722 if (m_colorage)
1723 ::SetWindowPos(wLocator, 0, 0, blamerc.top, LOCATOR_WIDTH, blamerc.bottom - blamerc.top, SWP_SHOWWINDOW);
1724 else
1725 ::ShowWindow(wLocator, SW_HIDE);
1728 #if 0
1729 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1731 if (message == uFindReplaceMsg)
1733 LPFINDREPLACE lpfr = (LPFINDREPLACE)lParam;
1735 // If the FR_DIALOGTERM flag is set,
1736 // invalidate the handle identifying the dialog box.
1737 if (lpfr->Flags & FR_DIALOGTERM)
1739 app.currentDialog = NULL;
1740 return 0;
1742 if (lpfr->Flags & FR_FINDNEXT)
1744 app.DoSearch(lpfr->lpstrFindWhat, lpfr->Flags);
1746 return 0;
1748 switch (message)
1750 case WM_CREATE:
1751 app.m_wEditor = ::CreateWindow(
1752 "Scintilla",
1753 "Source",
1754 WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_CLIPCHILDREN,
1755 0, 0,
1756 100, 100,
1757 hWnd,
1759 app.hResource,
1761 app.InitialiseEditor();
1762 ::ShowWindow(app.m_wEditor, SW_SHOW);
1763 ::SetFocus(app.m_wEditor);
1764 app.wBlame = ::CreateWindow(
1765 _T("TortoiseGitBlameViewBlame"),
1766 _T("blame"),
1767 WS_CHILD | WS_CLIPCHILDREN,
1768 CW_USEDEFAULT, 0,
1769 CW_USEDEFAULT, 0,
1770 hWnd,
1771 NULL,
1772 app.hResource,
1773 NULL);
1774 ::ShowWindow(app.wBlame, SW_SHOW);
1775 app.wHeader = ::CreateWindow(
1776 _T("TortoiseGitBlameViewHeader"),
1777 _T("header"),
1778 WS_CHILD | WS_CLIPCHILDREN | WS_BORDER,
1779 CW_USEDEFAULT, 0,
1780 CW_USEDEFAULT, 0,
1781 hWnd,
1782 NULL,
1783 app.hResource,
1784 NULL);
1785 ::ShowWindow(app.wHeader, SW_SHOW);
1786 app.wLocator = ::CreateWindow(
1787 _T("TortoiseGitBlameViewLocator"),
1788 _T("locator"),
1789 WS_CHILD | WS_CLIPCHILDREN | WS_BORDER,
1790 CW_USEDEFAULT, 0,
1791 CW_USEDEFAULT, 0,
1792 hWnd,
1793 NULL,
1794 app.hResource,
1795 NULL);
1796 ::ShowWindow(app.wLocator, SW_SHOW);
1797 return 0;
1799 case WM_SIZE:
1800 if (wParam != 1)
1802 app.InitSize();
1804 return 0;
1806 case WM_COMMAND:
1807 app.Command(LOWORD(wParam));
1808 break;
1809 case WM_NOTIFY:
1810 app.Notify(reinterpret_cast<SCNotification *>(lParam));
1811 return 0;
1812 case WM_DESTROY:
1813 PostQuitMessage(0);
1814 break;
1815 case WM_CLOSE:
1817 CRegStdWORD pos(_T("Software\\TortoiseGit\\TBlamePos"), 0);
1818 CRegStdWORD width(_T("Software\\TortoiseGit\\TBlameSize"), 0);
1819 CRegStdWORD state(_T("Software\\TortoiseGit\\TBlameState"), 0);
1820 RECT rc;
1821 GetWindowRect(app.wMain, &rc);
1822 if ((rc.left >= 0)&&(rc.top >= 0))
1824 pos = MAKELONG(rc.left, rc.top);
1825 width = MAKELONG(rc.right-rc.left, rc.bottom-rc.top);
1827 WINDOWPLACEMENT wp = {0};
1828 wp.length = sizeof(WINDOWPLACEMENT);
1829 GetWindowPlacement(app.wMain, &wp);
1830 state = wp.showCmd;
1831 ::DestroyWindow(app.m_wEditor);
1832 ::PostQuitMessage(0);
1834 return 0;
1835 case WM_SETFOCUS:
1836 ::SetFocus(app.wBlame);
1837 break;
1838 default:
1839 return DefWindowProc(hWnd, message, wParam, lParam);
1841 return 0;
1844 LRESULT CALLBACK WndBlameProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1846 PAINTSTRUCT ps;
1847 TRACKMOUSEEVENT mevt;
1848 HDC hDC;
1849 switch (message)
1851 case WM_CREATE:
1852 return 0;
1853 case WM_PAINT:
1854 hDC = BeginPaint(app.wBlame, &ps);
1855 app.DrawBlame(hDC);
1856 EndPaint(app.wBlame, &ps);
1857 break;
1858 case WM_COMMAND:
1859 app.Command(LOWORD(wParam));
1860 break;
1861 case WM_NOTIFY:
1862 switch (((LPNMHDR)lParam)->code)
1864 case TTN_GETDISPINFO:
1866 LPNMHDR pNMHDR = (LPNMHDR)lParam;
1867 NMTTDISPINFOA* pTTTA = (NMTTDISPINFOA*)pNMHDR;
1868 NMTTDISPINFOW* pTTTW = (NMTTDISPINFOW*)pNMHDR;
1869 POINT point;
1870 DWORD ptW = GetMessagePos();
1871 point.x = GET_X_LPARAM(ptW);
1872 point.y = GET_Y_LPARAM(ptW);
1873 ::ScreenToClient(app.wBlame, &point);
1874 LONG_PTR line = app.SendEditor(SCI_GETFIRSTVISIBLELINE);
1875 LONG_PTR height = app.SendEditor(SCI_TEXTHEIGHT);
1876 line = line + (point.y/height);
1877 if (line >= (LONG)app.revs.size())
1878 break;
1879 if (line < 0)
1880 break;
1881 LONG rev = app.revs[line];
1882 if (line >= (LONG)app.revs.size())
1883 break;
1885 SecureZeroMemory(app.m_szTip, sizeof(app.m_szTip));
1886 SecureZeroMemory(app.m_wszTip, sizeof(app.m_wszTip));
1887 std::map<LONG, CString>::iterator iter;
1888 if ((iter = app.logmessages.find(rev)) != app.logmessages.end())
1890 CString msg;
1891 if (!ShowAuthor)
1893 msg += app.authors[line];
1895 if (!ShowDate)
1897 if (!ShowAuthor) msg += " ";
1898 msg += app.dates[line];
1900 if (!ShowAuthor || !ShowDate)
1901 msg += '\n';
1902 msg += iter->second;
1903 // an empty tooltip string will deactivate the tooltips,
1904 // which means we must make sure that the tooltip won't
1905 // be empty.
1906 if (msg.empty())
1907 msg = _T(" ");
1908 if (pNMHDR->code == TTN_NEEDTEXTA)
1910 lstrcpyn(app.m_szTip, msg.c_str(), MAX_LOG_LENGTH*2);
1911 app.StringExpand(app.m_szTip);
1912 pTTTA->lpszText = app.m_szTip;
1914 else
1916 pTTTW->lpszText = app.m_wszTip;
1917 ::MultiByteToWideChar( CP_ACP , 0, msg.c_str(), min(msg.size(), MAX_LOG_LENGTH*2), app.m_wszTip, MAX_LOG_LENGTH*2);
1918 app.StringExpand(app.m_wszTip);
1922 break;
1924 return 0;
1925 case WM_DESTROY:
1926 break;
1927 case WM_CLOSE:
1928 return 0;
1929 case WM_MOUSELEAVE:
1930 app.m_mouserev = -2;
1931 app.m_mouseauthor.clear();
1932 app.ttVisible = FALSE;
1933 SendMessage(app.hwndTT, TTM_TRACKACTIVATE, FALSE, 0);
1934 ::InvalidateRect(app.wBlame, NULL, FALSE);
1935 break;
1936 case WM_MOUSEMOVE:
1938 mevt.cbSize = sizeof(TRACKMOUSEEVENT);
1939 mevt.dwFlags = TME_LEAVE;
1940 mevt.dwHoverTime = HOVER_DEFAULT;
1941 mevt.hwndTrack = app.wBlame;
1942 ::TrackMouseEvent(&mevt);
1943 POINT pt = {((int)(short)LOWORD(lParam)), ((int)(short)HIWORD(lParam))};
1944 ClientToScreen(app.wBlame, &pt);
1945 pt.x += 15;
1946 pt.y += 15;
1947 SendMessage(app.hwndTT, TTM_TRACKPOSITION, 0, MAKELONG(pt.x, pt.y));
1948 if (!app.ttVisible)
1950 TOOLINFO ti;
1951 ti.cbSize = sizeof(TOOLINFO);
1952 ti.hwnd = app.wBlame;
1953 ti.uId = 0;
1954 SendMessage(app.hwndTT, TTM_TRACKACTIVATE, TRUE, (LPARAM)&ti);
1956 int y = ((int)(short)HIWORD(lParam));
1957 LONG_PTR line = app.SendEditor(SCI_GETFIRSTVISIBLELINE);
1958 LONG_PTR height = app.SendEditor(SCI_TEXTHEIGHT);
1959 line = line + (y/height);
1960 app.ttVisible = (line < (LONG)app.revs.size());
1961 if ( app.ttVisible )
1963 if (app.authors[line].compare(app.m_mouseauthor) != 0)
1965 app.m_mouseauthor = app.authors[line];
1967 if (app.revs[line] != app.m_mouserev)
1969 app.m_mouserev = app.revs[line];
1970 ::InvalidateRect(app.wBlame, NULL, FALSE);
1971 SendMessage(app.hwndTT, TTM_UPDATE, 0, 0);
1975 break;
1976 case WM_RBUTTONDOWN:
1977 // fall through
1978 case WM_LBUTTONDOWN:
1980 break;
1981 case WM_SETFOCUS:
1982 ::SetFocus(app.wBlame);
1983 app.SendEditor(SCI_GRABFOCUS);
1984 break;
1985 case WM_CONTEXTMENU:
1987 if (app.m_selectedrev <= 0)
1988 break;;
1989 int xPos = GET_X_LPARAM(lParam);
1990 int yPos = GET_Y_LPARAM(lParam);
1991 if ((xPos < 0)||(yPos < 0))
1993 // requested from keyboard, not mouse pointer
1994 // use the center of the window
1995 RECT rect;
1996 GetClientRect(app.wBlame, &rect);
1997 xPos = rect.right-rect.left;
1998 yPos = rect.bottom-rect.top;
2000 HMENU hMenu = LoadMenu(app.hResource, MAKEINTRESOURCE(IDR_BLAMEPOPUP));
2001 HMENU hPopMenu = GetSubMenu(hMenu, 0);
2003 if ( _tcslen(szOrigPath)==0 )
2005 // Without knowing the original path we cannot blame the previous revision
2006 // because we don't know which filename to pass to tortoiseproc.
2007 EnableMenuItem(hPopMenu,ID_BLAME_PREVIOUS_REVISION, MF_DISABLED|MF_GRAYED);
2010 TrackPopupMenu(hPopMenu, TPM_LEFTALIGN | TPM_RIGHTBUTTON, xPos, yPos, 0, app.wBlame, NULL);
2011 DestroyMenu(hMenu);
2013 break;
2014 default:
2015 return DefWindowProc(hWnd, message, wParam, lParam);
2017 return 0;
2020 LRESULT CALLBACK WndHeaderProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
2022 PAINTSTRUCT ps;
2023 HDC hDC;
2024 switch (message)
2026 case WM_CREATE:
2027 return 0;
2028 case WM_PAINT:
2029 hDC = BeginPaint(app.wHeader, &ps);
2030 app.DrawHeader(hDC);
2031 EndPaint(app.wHeader, &ps);
2032 break;
2033 case WM_COMMAND:
2034 break;
2035 case WM_DESTROY:
2036 break;
2037 case WM_CLOSE:
2038 return 0;
2039 default:
2040 return DefWindowProc(hWnd, message, wParam, lParam);
2042 return 0;
2045 LRESULT CALLBACK WndLocatorProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
2047 PAINTSTRUCT ps;
2048 HDC hDC;
2049 switch (message)
2051 case WM_PAINT:
2052 hDC = BeginPaint(app.wLocator, &ps);
2053 app.DrawLocatorBar(hDC);
2054 EndPaint(app.wLocator, &ps);
2055 break;
2056 case WM_LBUTTONDOWN:
2057 case WM_MOUSEMOVE:
2058 if (wParam & MK_LBUTTON)
2060 RECT rect;
2061 ::GetClientRect(hWnd, &rect);
2062 int nLine = HIWORD(lParam)*app.revs.size()/(rect.bottom-rect.top);
2064 if (nLine < 0)
2065 nLine = 0;
2066 app.ScrollToLine(nLine);
2068 break;
2069 default:
2070 return DefWindowProc(hWnd, message, wParam, lParam);
2072 return 0;
2074 #endif
2076 void CTortoiseGitBlameView::SetupLexer(CString filename)
2079 TCHAR *line;
2080 //const char * lineptr = _tcsrchr(filename, '.');
2081 int start=filename.ReverseFind(_T('.'));
2082 if (start>0)
2084 //_tcscpy_s(line, 20, lineptr+1);
2085 //_tcslwr_s(line, 20);
2086 CString ext=filename.Right(filename.GetLength()-start-1);
2087 line=ext.GetBuffer();
2089 if ((_tcscmp(line, _T("py"))==0)||
2090 (_tcscmp(line, _T("pyw"))==0)||
2091 (_tcscmp(line, _T("pyw"))==0))
2093 SendEditor(SCI_SETLEXER, SCLEX_PYTHON);
2094 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("and assert break class continue def del elif \
2095 else except exec finally for from global if import in is lambda None \
2096 not or pass print raise return try while yield")).GetBuffer()));
2097 SetAStyle(SCE_P_DEFAULT, black);
2098 SetAStyle(SCE_P_COMMENTLINE, darkGreen);
2099 SetAStyle(SCE_P_NUMBER, RGB(0, 0x80, 0x80));
2100 SetAStyle(SCE_P_STRING, RGB(0, 0, 0x80));
2101 SetAStyle(SCE_P_CHARACTER, RGB(0, 0, 0x80));
2102 SetAStyle(SCE_P_WORD, RGB(0x80, 0, 0x80));
2103 SetAStyle(SCE_P_TRIPLE, black);
2104 SetAStyle(SCE_P_TRIPLEDOUBLE, black);
2105 SetAStyle(SCE_P_CLASSNAME, darkBlue);
2106 SetAStyle(SCE_P_DEFNAME, darkBlue);
2107 SetAStyle(SCE_P_OPERATOR, darkBlue);
2108 SetAStyle(SCE_P_IDENTIFIER, darkBlue);
2109 SetAStyle(SCE_P_COMMENTBLOCK, darkGreen);
2110 SetAStyle(SCE_P_STRINGEOL, red);
2112 if ((_tcscmp(line, _T("c"))==0)||
2113 (_tcscmp(line, _T("cc"))==0)||
2114 (_tcscmp(line, _T("cpp"))==0)||
2115 (_tcscmp(line, _T("cxx"))==0)||
2116 (_tcscmp(line, _T("h"))==0)||
2117 (_tcscmp(line, _T("hh"))==0)||
2118 (_tcscmp(line, _T("hpp"))==0)||
2119 (_tcscmp(line, _T("hxx"))==0)||
2120 (_tcscmp(line, _T("dlg"))==0)||
2121 (_tcscmp(line, _T("mak"))==0))
2123 SendEditor(SCI_SETLEXER, SCLEX_CPP);
2124 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("and and_eq asm auto bitand bitor bool break \
2125 case catch char class compl const const_cast continue \
2126 default delete do double dynamic_cast else enum explicit export extern false float for \
2127 friend goto if inline int long mutable namespace new not not_eq \
2128 operator or or_eq private protected public \
2129 register reinterpret_cast return short signed sizeof static static_cast struct switch \
2130 template this throw true try typedef typeid typename union unsigned using \
2131 virtual void volatile wchar_t while xor xor_eq")).GetBuffer()));
2132 SendEditor(SCI_SETKEYWORDS, 3, (LPARAM)(m_TextView.StringForControl(_T("a addindex addtogroup anchor arg attention \
2133 author b brief bug c class code date def defgroup deprecated dontinclude \
2134 e em endcode endhtmlonly endif endlatexonly endlink endverbatim enum example exception \
2135 f$ f[ f] file fn hideinitializer htmlinclude htmlonly \
2136 if image include ingroup internal invariant interface latexonly li line link \
2137 mainpage name namespace nosubgrouping note overload \
2138 p page par param post pre ref relates remarks return retval \
2139 sa section see showinitializer since skip skipline struct subsection \
2140 test throw todo typedef union until \
2141 var verbatim verbinclude version warning weakgroup $ @ \\ & < > # { }")).GetBuffer()));
2142 SetupCppLexer();
2144 if (_tcscmp(line, _T("cs"))==0)
2146 SendEditor(SCI_SETLEXER, SCLEX_CPP);
2147 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("abstract as base bool break byte case catch char checked class \
2148 const continue decimal default delegate do double else enum \
2149 event explicit extern false finally fixed float for foreach goto if \
2150 implicit in int interface internal is lock long namespace new null \
2151 object operator out override params private protected public \
2152 readonly ref return sbyte sealed short sizeof stackalloc static \
2153 string struct switch this throw true try typeof uint ulong \
2154 unchecked unsafe ushort using virtual void while")).GetBuffer()));
2155 SetupCppLexer();
2157 if ((_tcscmp(line, _T("rc"))==0)||
2158 (_tcscmp(line, _T("rc2"))==0))
2160 SendEditor(SCI_SETLEXER, SCLEX_CPP);
2161 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("ACCELERATORS ALT AUTO3STATE AUTOCHECKBOX AUTORADIOBUTTON \
2162 BEGIN BITMAP BLOCK BUTTON CAPTION CHARACTERISTICS CHECKBOX CLASS \
2163 COMBOBOX CONTROL CTEXT CURSOR DEFPUSHBUTTON DIALOG DIALOGEX DISCARDABLE \
2164 EDITTEXT END EXSTYLE FONT GROUPBOX ICON LANGUAGE LISTBOX LTEXT \
2165 MENU MENUEX MENUITEM MESSAGETABLE POPUP \
2166 PUSHBUTTON RADIOBUTTON RCDATA RTEXT SCROLLBAR SEPARATOR SHIFT STATE3 \
2167 STRINGTABLE STYLE TEXTINCLUDE VALUE VERSION VERSIONINFO VIRTKEY")).GetBuffer()));
2168 SetupCppLexer();
2170 if ((_tcscmp(line, _T("idl"))==0)||
2171 (_tcscmp(line, _T("odl"))==0))
2173 SendEditor(SCI_SETLEXER, SCLEX_CPP);
2174 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("aggregatable allocate appobject arrays async async_uuid \
2175 auto_handle \
2176 bindable boolean broadcast byte byte_count \
2177 call_as callback char coclass code comm_status \
2178 const context_handle context_handle_noserialize \
2179 context_handle_serialize control cpp_quote custom \
2180 decode default defaultbind defaultcollelem \
2181 defaultvalue defaultvtable dispinterface displaybind dllname \
2182 double dual \
2183 enable_allocate encode endpoint entry enum error_status_t \
2184 explicit_handle \
2185 fault_status first_is float \
2186 handle_t heap helpcontext helpfile helpstring \
2187 helpstringcontext helpstringdll hidden hyper \
2188 id idempotent ignore iid_as iid_is immediatebind implicit_handle \
2189 import importlib in include in_line int __int64 __int3264 interface \
2190 last_is lcid length_is library licensed local long \
2191 max_is maybe message methods midl_pragma \
2192 midl_user_allocate midl_user_free min_is module ms_union \
2193 ncacn_at_dsp ncacn_dnet_nsp ncacn_http ncacn_ip_tcp \
2194 ncacn_nb_ipx ncacn_nb_nb ncacn_nb_tcp ncacn_np \
2195 ncacn_spx ncacn_vns_spp ncadg_ip_udp ncadg_ipx ncadg_mq \
2196 ncalrpc nocode nonbrowsable noncreatable nonextensible notify \
2197 object odl oleautomation optimize optional out out_of_line \
2198 pipe pointer_default pragma properties propget propput propputref \
2199 ptr public \
2200 range readonly ref represent_as requestedit restricted retval \
2201 shape short signed size_is small source strict_context_handle \
2202 string struct switch switch_is switch_type \
2203 transmit_as typedef \
2204 uidefault union unique unsigned user_marshal usesgetlasterror uuid \
2205 v1_enum vararg version void wchar_t wire_marshal")).GetBuffer()));
2206 SetupCppLexer();
2208 if (_tcscmp(line, _T("java"))==0)
2210 SendEditor(SCI_SETLEXER, SCLEX_CPP);
2211 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("abstract assert boolean break byte case catch char class \
2212 const continue default do double else extends final finally float for future \
2213 generic goto if implements import inner instanceof int interface long \
2214 native new null outer package private protected public rest \
2215 return short static super switch synchronized this throw throws \
2216 transient try var void volatile while")).GetBuffer()));
2217 SetupCppLexer();
2219 if (_tcscmp(line, _T("js"))==0)
2221 SendEditor(SCI_SETLEXER, SCLEX_CPP);
2222 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("abstract boolean break byte case catch char class \
2223 const continue debugger default delete do double else enum export extends \
2224 final finally float for function goto if implements import in instanceof \
2225 int interface long native new package private protected public \
2226 return short static super switch synchronized this throw throws \
2227 transient try typeof var void volatile while with")).GetBuffer()));
2228 SetupCppLexer();
2230 if ((_tcscmp(line, _T("pas"))==0)||
2231 (_tcscmp(line, _T("dpr"))==0)||
2232 (_tcscmp(line, _T("pp"))==0))
2234 SendEditor(SCI_SETLEXER, SCLEX_PASCAL);
2235 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("and array as begin case class const constructor \
2236 destructor div do downto else end except file finally \
2237 for function goto if implementation in inherited \
2238 interface is mod not object of on or packed \
2239 procedure program property raise record repeat \
2240 set shl shr then threadvar to try type unit \
2241 until uses var while with xor")).GetBuffer()));
2242 SetupCppLexer();
2244 if ((_tcscmp(line, _T("as"))==0)||
2245 (_tcscmp(line, _T("asc"))==0)||
2246 (_tcscmp(line, _T("jsfl"))==0))
2248 SendEditor(SCI_SETLEXER, SCLEX_CPP);
2249 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("add and break case catch class continue default delete do \
2250 dynamic else eq extends false finally for function ge get gt if implements import in \
2251 instanceof interface intrinsic le lt ne new not null or private public return \
2252 set static super switch this throw true try typeof undefined var void while with")).GetBuffer()));
2253 SendEditor(SCI_SETKEYWORDS, 1, (LPARAM)(m_TextView.StringForControl(_T("Array Arguments Accessibility Boolean Button Camera Color \
2254 ContextMenu ContextMenuItem Date Error Function Key LoadVars LocalConnection Math \
2255 Microphone Mouse MovieClip MovieClipLoader NetConnection NetStream Number Object \
2256 PrintJob Selection SharedObject Sound Stage String StyleSheet System TextField \
2257 TextFormat TextSnapshot Video Void XML XMLNode XMLSocket \
2258 _accProps _focusrect _global _highquality _parent _quality _root _soundbuftime \
2259 arguments asfunction call capabilities chr clearInterval duplicateMovieClip \
2260 escape eval fscommand getProperty getTimer getURL getVersion gotoAndPlay gotoAndStop \
2261 ifFrameLoaded Infinity -Infinity int isFinite isNaN length loadMovie loadMovieNum \
2262 loadVariables loadVariablesNum maxscroll mbchr mblength mbord mbsubstring MMExecute \
2263 NaN newline nextFrame nextScene on onClipEvent onUpdate ord parseFloat parseInt play \
2264 prevFrame prevScene print printAsBitmap printAsBitmapNum printNum random removeMovieClip \
2265 scroll set setInterval setProperty startDrag stop stopAllSounds stopDrag substring \
2266 targetPath tellTarget toggleHighQuality trace unescape unloadMovie unLoadMovieNum updateAfterEvent")).GetBuffer()));
2267 SetupCppLexer();
2269 if ((_tcscmp(line, _T("html"))==0)||
2270 (_tcscmp(line, _T("htm"))==0)||
2271 (_tcscmp(line, _T("shtml"))==0)||
2272 (_tcscmp(line, _T("htt"))==0)||
2273 (_tcscmp(line, _T("xml"))==0)||
2274 (_tcscmp(line, _T("asp"))==0)||
2275 (_tcscmp(line, _T("xsl"))==0)||
2276 (_tcscmp(line, _T("php"))==0)||
2277 (_tcscmp(line, _T("xhtml"))==0)||
2278 (_tcscmp(line, _T("phtml"))==0)||
2279 (_tcscmp(line, _T("cfm"))==0)||
2280 (_tcscmp(line, _T("tpl"))==0)||
2281 (_tcscmp(line, _T("dtd"))==0)||
2282 (_tcscmp(line, _T("hta"))==0)||
2283 (_tcscmp(line, _T("htd"))==0)||
2284 (_tcscmp(line, _T("wxs"))==0))
2286 SendEditor(SCI_SETLEXER, SCLEX_HTML);
2287 SendEditor(SCI_SETSTYLEBITS, 7);
2288 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("a abbr acronym address applet area b base basefont \
2289 bdo big blockquote body br button caption center \
2290 cite code col colgroup dd del dfn dir div dl dt em \
2291 fieldset font form frame frameset h1 h2 h3 h4 h5 h6 \
2292 head hr html i iframe img input ins isindex kbd label \
2293 legend li link map menu meta noframes noscript \
2294 object ol optgroup option p param pre q s samp \
2295 script select small span strike strong style sub sup \
2296 table tbody td textarea tfoot th thead title tr tt u ul \
2297 var xml xmlns abbr accept-charset accept accesskey action align alink \
2298 alt archive axis background bgcolor border \
2299 cellpadding cellspacing char charoff charset checked cite \
2300 class classid clear codebase codetype color cols colspan \
2301 compact content coords \
2302 data datafld dataformatas datapagesize datasrc datetime \
2303 declare defer dir disabled enctype event \
2304 face for frame frameborder \
2305 headers height href hreflang hspace http-equiv \
2306 id ismap label lang language leftmargin link longdesc \
2307 marginwidth marginheight maxlength media method multiple \
2308 name nohref noresize noshade nowrap \
2309 object onblur onchange onclick ondblclick onfocus \
2310 onkeydown onkeypress onkeyup onload onmousedown \
2311 onmousemove onmouseover onmouseout onmouseup \
2312 onreset onselect onsubmit onunload \
2313 profile prompt readonly rel rev rows rowspan rules \
2314 scheme scope selected shape size span src standby start style \
2315 summary tabindex target text title topmargin type usemap \
2316 valign value valuetype version vlink vspace width \
2317 text password checkbox radio submit reset \
2318 file hidden image")).GetBuffer()));
2319 SendEditor(SCI_SETKEYWORDS, 1, (LPARAM)(m_TextView.StringForControl(_T("assign audio block break catch choice clear disconnect else elseif \
2320 emphasis enumerate error exit field filled form goto grammar help \
2321 if initial link log menu meta noinput nomatch object option p paragraph \
2322 param phoneme prompt property prosody record reprompt return s say-as \
2323 script sentence subdialog submit throw transfer value var voice vxml")).GetBuffer()));
2324 SendEditor(SCI_SETKEYWORDS, 2, (LPARAM)(m_TextView.StringForControl(_T("accept age alphabet anchor application base beep bridge category charset \
2325 classid cond connecttimeout content contour count dest destexpr dtmf dtmfterm \
2326 duration enctype event eventexpr expr expritem fetchtimeout finalsilence \
2327 gender http-equiv id level maxage maxstale maxtime message messageexpr \
2328 method mime modal mode name namelist next nextitem ph pitch range rate \
2329 scope size sizeexpr skiplist slot src srcexpr sub time timeexpr timeout \
2330 transferaudio type value variant version volume xml:lang")).GetBuffer()));
2331 SendEditor(SCI_SETKEYWORDS, 3, (LPARAM)(m_TextView.StringForControl(_T("and assert break class continue def del elif \
2332 else except exec finally for from global if import in is lambda None \
2333 not or pass print raise return try while yield")).GetBuffer()));
2334 SendEditor(SCI_SETKEYWORDS, 4, (LPARAM)(m_TextView.StringForControl(_T("and argv as argc break case cfunction class continue declare default do \
2335 die echo else elseif empty enddeclare endfor endforeach endif endswitch \
2336 endwhile e_all e_parse e_error e_warning eval exit extends false for \
2337 foreach function global http_cookie_vars http_get_vars http_post_vars \
2338 http_post_files http_env_vars http_server_vars if include include_once \
2339 list new not null old_function or parent php_os php_self php_version \
2340 print require require_once return static switch stdclass this true var \
2341 xor virtual while __file__ __line__ __sleep __wakeup")).GetBuffer()));
2343 SetAStyle(SCE_H_TAG, darkBlue);
2344 SetAStyle(SCE_H_TAGUNKNOWN, red);
2345 SetAStyle(SCE_H_ATTRIBUTE, darkBlue);
2346 SetAStyle(SCE_H_ATTRIBUTEUNKNOWN, red);
2347 SetAStyle(SCE_H_NUMBER, RGB(0x80,0,0x80));
2348 SetAStyle(SCE_H_DOUBLESTRING, RGB(0,0x80,0));
2349 SetAStyle(SCE_H_SINGLESTRING, RGB(0,0x80,0));
2350 SetAStyle(SCE_H_OTHER, RGB(0x80,0,0x80));
2351 SetAStyle(SCE_H_COMMENT, RGB(0x80,0x80,0));
2352 SetAStyle(SCE_H_ENTITY, RGB(0x80,0,0x80));
2354 SetAStyle(SCE_H_TAGEND, darkBlue);
2355 SetAStyle(SCE_H_XMLSTART, darkBlue); // <?
2356 SetAStyle(SCE_H_QUESTION, darkBlue); // <?
2357 SetAStyle(SCE_H_XMLEND, darkBlue); // ?>
2358 SetAStyle(SCE_H_SCRIPT, darkBlue); // <script
2359 SetAStyle(SCE_H_ASP, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <% ... %>
2360 SetAStyle(SCE_H_ASPAT, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <%@ ... %>
2362 SetAStyle(SCE_HB_DEFAULT, black);
2363 SetAStyle(SCE_HB_COMMENTLINE, darkGreen);
2364 SetAStyle(SCE_HB_NUMBER, RGB(0,0x80,0x80));
2365 SetAStyle(SCE_HB_WORD, darkBlue);
2366 SendEditor(SCI_STYLESETBOLD, SCE_HB_WORD, 1);
2367 SetAStyle(SCE_HB_STRING, RGB(0x80,0,0x80));
2368 SetAStyle(SCE_HB_IDENTIFIER, black);
2370 // This light blue is found in the windows system palette so is safe to use even in 256 colour modes.
2371 // Show the whole section of VBScript with light blue background
2372 for (int bstyle=SCE_HB_DEFAULT; bstyle<=SCE_HB_STRINGEOL; bstyle++) {
2373 SendEditor(SCI_STYLESETFONT, bstyle,
2374 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
2375 SendEditor(SCI_STYLESETBACK, bstyle, lightBlue);
2376 // This call extends the backround colour of the last style on the line to the edge of the window
2377 SendEditor(SCI_STYLESETEOLFILLED, bstyle, 1);
2379 SendEditor(SCI_STYLESETBACK, SCE_HB_STRINGEOL, RGB(0x7F,0x7F,0xFF));
2380 SendEditor(SCI_STYLESETFONT, SCE_HB_COMMENTLINE,
2381 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
2383 SetAStyle(SCE_HBA_DEFAULT, black);
2384 SetAStyle(SCE_HBA_COMMENTLINE, darkGreen);
2385 SetAStyle(SCE_HBA_NUMBER, RGB(0,0x80,0x80));
2386 SetAStyle(SCE_HBA_WORD, darkBlue);
2387 SendEditor(SCI_STYLESETBOLD, SCE_HBA_WORD, 1);
2388 SetAStyle(SCE_HBA_STRING, RGB(0x80,0,0x80));
2389 SetAStyle(SCE_HBA_IDENTIFIER, black);
2391 // Show the whole section of ASP VBScript with bright yellow background
2392 for (int bastyle=SCE_HBA_DEFAULT; bastyle<=SCE_HBA_STRINGEOL; bastyle++) {
2393 SendEditor(SCI_STYLESETFONT, bastyle,
2394 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
2395 SendEditor(SCI_STYLESETBACK, bastyle, RGB(0xFF, 0xFF, 0));
2396 // This call extends the backround colour of the last style on the line to the edge of the window
2397 SendEditor(SCI_STYLESETEOLFILLED, bastyle, 1);
2399 SendEditor(SCI_STYLESETBACK, SCE_HBA_STRINGEOL, RGB(0xCF,0xCF,0x7F));
2400 SendEditor(SCI_STYLESETFONT, SCE_HBA_COMMENTLINE,
2401 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
2403 // If there is no need to support embedded Javascript, the following code can be dropped.
2404 // Javascript will still be correctly processed but will be displayed in just the default style.
2406 SetAStyle(SCE_HJ_START, RGB(0x80,0x80,0));
2407 SetAStyle(SCE_HJ_DEFAULT, black);
2408 SetAStyle(SCE_HJ_COMMENT, darkGreen);
2409 SetAStyle(SCE_HJ_COMMENTLINE, darkGreen);
2410 SetAStyle(SCE_HJ_COMMENTDOC, darkGreen);
2411 SetAStyle(SCE_HJ_NUMBER, RGB(0,0x80,0x80));
2412 SetAStyle(SCE_HJ_WORD, black);
2413 SetAStyle(SCE_HJ_KEYWORD, darkBlue);
2414 SetAStyle(SCE_HJ_DOUBLESTRING, RGB(0x80,0,0x80));
2415 SetAStyle(SCE_HJ_SINGLESTRING, RGB(0x80,0,0x80));
2416 SetAStyle(SCE_HJ_SYMBOLS, black);
2418 SetAStyle(SCE_HJA_START, RGB(0x80,0x80,0));
2419 SetAStyle(SCE_HJA_DEFAULT, black);
2420 SetAStyle(SCE_HJA_COMMENT, darkGreen);
2421 SetAStyle(SCE_HJA_COMMENTLINE, darkGreen);
2422 SetAStyle(SCE_HJA_COMMENTDOC, darkGreen);
2423 SetAStyle(SCE_HJA_NUMBER, RGB(0,0x80,0x80));
2424 SetAStyle(SCE_HJA_WORD, black);
2425 SetAStyle(SCE_HJA_KEYWORD, darkBlue);
2426 SetAStyle(SCE_HJA_DOUBLESTRING, RGB(0x80,0,0x80));
2427 SetAStyle(SCE_HJA_SINGLESTRING, RGB(0x80,0,0x80));
2428 SetAStyle(SCE_HJA_SYMBOLS, black);
2430 SetAStyle(SCE_HPHP_DEFAULT, black);
2431 SetAStyle(SCE_HPHP_HSTRING, RGB(0x80,0,0x80));
2432 SetAStyle(SCE_HPHP_SIMPLESTRING, RGB(0x80,0,0x80));
2433 SetAStyle(SCE_HPHP_WORD, darkBlue);
2434 SetAStyle(SCE_HPHP_NUMBER, RGB(0,0x80,0x80));
2435 SetAStyle(SCE_HPHP_VARIABLE, red);
2436 SetAStyle(SCE_HPHP_HSTRING_VARIABLE, red);
2437 SetAStyle(SCE_HPHP_COMPLEX_VARIABLE, red);
2438 SetAStyle(SCE_HPHP_COMMENT, darkGreen);
2439 SetAStyle(SCE_HPHP_COMMENTLINE, darkGreen);
2440 SetAStyle(SCE_HPHP_OPERATOR, darkBlue);
2442 // Show the whole section of Javascript with off white background
2443 for (int jstyle=SCE_HJ_DEFAULT; jstyle<=SCE_HJ_SYMBOLS; jstyle++) {
2444 SendEditor(SCI_STYLESETFONT, jstyle,
2445 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
2446 SendEditor(SCI_STYLESETBACK, jstyle, offWhite);
2447 SendEditor(SCI_STYLESETEOLFILLED, jstyle, 1);
2449 SendEditor(SCI_STYLESETBACK, SCE_HJ_STRINGEOL, RGB(0xDF, 0xDF, 0x7F));
2450 SendEditor(SCI_STYLESETEOLFILLED, SCE_HJ_STRINGEOL, 1);
2452 // Show the whole section of Javascript with brown background
2453 for (int jastyle=SCE_HJA_DEFAULT; jastyle<=SCE_HJA_SYMBOLS; jastyle++) {
2454 SendEditor(SCI_STYLESETFONT, jastyle,
2455 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
2456 SendEditor(SCI_STYLESETBACK, jastyle, RGB(0xDF, 0xDF, 0x7F));
2457 SendEditor(SCI_STYLESETEOLFILLED, jastyle, 1);
2459 SendEditor(SCI_STYLESETBACK, SCE_HJA_STRINGEOL, RGB(0x0,0xAF,0x5F));
2460 SendEditor(SCI_STYLESETEOLFILLED, SCE_HJA_STRINGEOL, 1);
2463 else
2465 SendEditor(SCI_SETLEXER, SCLEX_CPP);
2466 SetupCppLexer();
2468 SendEditor(SCI_COLOURISE, 0, -1);
2472 void CTortoiseGitBlameView::SetupCppLexer()
2474 SetAStyle(SCE_C_DEFAULT, RGB(0, 0, 0));
2475 SetAStyle(SCE_C_COMMENT, RGB(0, 0x80, 0));
2476 SetAStyle(SCE_C_COMMENTLINE, RGB(0, 0x80, 0));
2477 SetAStyle(SCE_C_COMMENTDOC, RGB(0, 0x80, 0));
2478 SetAStyle(SCE_C_COMMENTLINEDOC, RGB(0, 0x80, 0));
2479 SetAStyle(SCE_C_COMMENTDOCKEYWORD, RGB(0, 0x80, 0));
2480 SetAStyle(SCE_C_COMMENTDOCKEYWORDERROR, RGB(0, 0x80, 0));
2481 SetAStyle(SCE_C_NUMBER, RGB(0, 0x80, 0x80));
2482 SetAStyle(SCE_C_WORD, RGB(0, 0, 0x80));
2483 SendEditor(SCE_C_WORD, 1);
2484 SetAStyle(SCE_C_STRING, RGB(0x80, 0, 0x80));
2485 SetAStyle(SCE_C_IDENTIFIER, RGB(0, 0, 0));
2486 SetAStyle(SCE_C_PREPROCESSOR, RGB(0x80, 0, 0));
2487 SetAStyle(SCE_C_OPERATOR, RGB(0x80, 0x80, 0));
2490 int CTortoiseGitBlameView::GetEncode(unsigned char *buff, int size, int *bomoffset)
2492 CFileTextLines textlines;
2493 CFileTextLines::UnicodeType type = textlines.CheckUnicodeType(buff, size);
2495 if(type == CFileTextLines::UTF8BOM)
2497 *bomoffset = 3;
2498 return CP_UTF8;
2500 if(type == CFileTextLines::UTF8)
2501 return CP_UTF8;
2503 if(type == CFileTextLines::UNICODE_LE)
2505 *bomoffset = 2;
2506 return 1200;
2509 return GetACP();
2512 void CTortoiseGitBlameView::UpdateInfo(int Encode)
2514 BYTE_VECTOR &data = GetDocument()->m_BlameData;
2515 CString one;
2516 int pos=0;
2518 BYTE_VECTOR vector;
2520 CLogDataVector * pRevs= GetLogData();
2522 this->m_CommitHash.clear();
2523 this->m_Authors.clear();
2524 this->m_ID.clear();
2525 CString line;
2527 CreateFont();
2529 SendEditor(SCI_SETREADONLY, FALSE);
2530 SendEditor(SCI_CLEARALL);
2531 SendEditor(EM_EMPTYUNDOBUFFER);
2532 SendEditor(SCI_SETSAVEPOINT);
2533 SendEditor(SCI_CANCEL);
2534 SendEditor(SCI_SETUNDOCOLLECTION, 0);
2536 SendEditor(SCI_SETCODEPAGE, SC_CP_UTF8);
2538 int current = 0;
2539 int encoding = Encode;
2540 while( pos>=0 && current >=0 && pos<data.size() )
2542 current = data.findData((const BYTE*)"\n",1,pos);
2543 //one=data.Tokenize(_T("\n"),pos);
2545 bool isbound = ( data[pos] == _T('^') );
2547 if( (data.size() - pos) >1 && data[pos] == _T('^'))
2548 pos ++;
2550 if( data[pos] == 0)
2551 continue;
2553 CGitHash hash;
2554 if(isbound)
2556 git_init();
2557 data[pos+39]=0;
2558 if(git_get_sha1((const char*)&data[pos], hash.m_hash))
2560 ::MessageBox(NULL, _T("Can't get hash"), _T("TortoiseGit"), MB_OK|MB_ICONERROR);
2563 }else
2564 hash.ConvertFromStrA((char*)&data[pos]);
2567 int start=0;
2568 start=data.findData((const BYTE*)")",1,pos + 40);
2569 if(start>0)
2572 int bomoffset = 0;
2573 CStringA stra;
2574 stra.Empty();
2576 if(current>=0)
2577 data[current] = 0;
2578 else
2579 data.push_back(0);
2581 if( pos <40 && encoding==0)
2583 // first line
2584 encoding = GetEncode( &data[start+2], data.size() - start -2, &bomoffset);
2587 if(encoding == 1200)
2589 CString strw;
2590 int size = ((current - start -2 - bomoffset)/2);
2591 TCHAR *buffer = strw.GetBuffer(size);
2592 memcpy(buffer, &data[start + 2 + bomoffset],sizeof(TCHAR)*size);
2593 strw.ReleaseBuffer();
2595 stra = CUnicodeUtils::GetUTF8(strw);
2597 }else if(encoding == CP_UTF8)
2599 stra = &data[start + 2 + bomoffset ];
2601 else
2603 CString strw;
2604 strw = CUnicodeUtils::GetUnicode(CStringA(&data[start + 2 + bomoffset ]), encoding);
2605 stra = CUnicodeUtils::GetUTF8(strw);
2610 SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)stra);
2611 SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)"\n\0\0\0");
2613 if(current>=0)
2614 data[current] = '\n';
2618 int id;
2619 if(pRevs->m_HashMap.find(hash)!=pRevs->m_HashMap.end())
2621 id=pRevs->m_HashMap[hash];
2623 else
2625 id=-1;
2626 if(this->m_NoListCommit.find(hash) == m_NoListCommit.end() )
2628 g_Git.GetLog(vector,hash.ToString(),NULL,1);
2629 this->m_NoListCommit[hash].ParserFromLog(vector);
2634 if(id>=0 && id <(int)GetLogData()->size())
2636 m_ID.push_back(pRevs->size()-id);
2637 m_Authors.push_back(pRevs->GetGitRevAt(id).m_AuthorName);
2638 }else
2640 m_ID.push_back(id);
2641 m_Authors.push_back(hash.ToString().Left(6));
2644 m_CommitHash.push_back(hash);
2645 pos = current+1;
2648 #if 0
2649 if(m_Buffer)
2651 delete m_Buffer;
2652 m_Buffer=NULL;
2655 CFile file;
2656 file.Open(this->GetDocument()->m_TempFileName,CFile::modeRead);
2658 m_Buffer = new char[file.GetLength()+4];
2659 m_Buffer[file.GetLength()] =0;
2660 m_Buffer[file.GetLength()+1] =0;
2661 m_Buffer[file.GetLength()+2] =0;
2662 m_Buffer[file.GetLength()+3] =0;
2664 file.Read(m_Buffer, file.GetLength());
2667 int bomoffset =0;
2668 int encoding = GetEncode( (unsigned char *)m_Buffer, file.GetLength(), &bomoffset);
2670 file.Close();
2671 //SendEditor(SCI_SETCODEPAGE, encoding);
2673 //SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)(m_Buffer + bomoffset));
2674 #endif
2675 SetupLexer(GetDocument()->m_CurrentFileName);
2677 SendEditor(SCI_SETUNDOCOLLECTION, 1);
2678 SendEditor(EM_EMPTYUNDOBUFFER);
2679 SendEditor(SCI_SETSAVEPOINT);
2680 SendEditor(SCI_GOTOPOS, 0);
2681 SendEditor(SCI_SETSCROLLWIDTHTRACKING, TRUE);
2682 SendEditor(SCI_SETREADONLY, TRUE);
2684 m_lowestrev=0;
2685 m_highestrev=this->GetLogData()->size()+m_NoListCommit.size();
2687 GetBlameWidth();
2688 CRect rect;
2689 this->GetClientRect(rect);
2690 //this->m_TextView.GetWindowRect(rect);
2691 //this->m_TextView.ScreenToClient(rect);
2692 rect.left=this->m_blamewidth;
2693 this->m_TextView.MoveWindow(rect);
2695 this->Invalidate();
2698 CGitBlameLogList * CTortoiseGitBlameView::GetLogList()
2700 return &(GetDocument()->GetMainFrame()->m_wndOutput.m_LogList);
2704 CLogDataVector * CTortoiseGitBlameView::GetLogData()
2706 return &(GetDocument()->GetMainFrame()->m_wndOutput.m_LogList.m_logEntries);
2709 void CTortoiseGitBlameView::OnSciPainted(NMHDR *,LRESULT *)
2711 this->Invalidate();
2714 void CTortoiseGitBlameView::OnLButtonDown(UINT nFlags,CPoint point)
2717 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
2718 LONG_PTR height = SendEditor(SCI_TEXTHEIGHT);
2719 line = line + (point.y/height);
2721 if (line < (LONG)m_CommitHash.size())
2723 SetSelectedLine(line);
2724 if (m_CommitHash[line] != m_SelectedHash)
2726 m_SelectedHash = m_CommitHash[line];
2728 if(m_ID[line]>=0)
2730 this->GetLogList()->SetItemState(this->GetLogList()->GetItemCount()-m_ID[line],
2731 LVIS_SELECTED,
2732 LVIS_SELECTED);
2734 GitRev *pRev;
2735 pRev=&this->GetLogData()->GetGitRevAt(this->GetLogList()->GetItemCount()-m_ID[line]);
2736 this->GetDocument()->GetMainFrame()->m_wndProperties.UpdateProperties(pRev);
2737 }else
2739 this->GetDocument()->GetMainFrame()->m_wndProperties.UpdateProperties(&m_NoListCommit[m_CommitHash[line]]);
2742 else
2744 m_SelectedHash.Empty();
2746 //::InvalidateRect( NULL, FALSE);
2747 this->Invalidate();
2748 this->m_TextView.Invalidate();
2751 else
2753 SetSelectedLine(-1);
2756 CView::OnLButtonDown(nFlags,point);
2759 void CTortoiseGitBlameView::OnSciGetBkColor(NMHDR* hdr, LRESULT* result)
2762 SCNotification *notification=reinterpret_cast<SCNotification *>(hdr);
2764 if ((m_colorage)&&(notification->line < (int)m_CommitHash.size()))
2766 if(m_CommitHash[notification->line] == this->m_SelectedHash )
2767 notification->lParam = m_selectedauthorcolor;
2768 else
2769 notification->lParam = InterColor(DWORD(m_regOldLinesColor), DWORD(m_regNewLinesColor), (m_ID[notification->line]-m_lowestrev)*100/((m_highestrev-m_lowestrev)+1));
2774 void CTortoiseGitBlameView::FocusOn(GitRev *pRev)
2776 m_SelectedHash = pRev->m_CommitHash;
2778 //GitRev *pRev;
2779 //pRev=&this->GetLogData()->at(this->GetLogList()->GetItemCount()-m_ID[line]);
2780 this->GetDocument()->GetMainFrame()->m_wndProperties.UpdateProperties(pRev);
2782 this->Invalidate();
2784 int i;
2785 for(i=0;i<m_CommitHash.size();i++)
2787 if( pRev->m_CommitHash == m_CommitHash[i] )
2788 break;
2790 this->GotoLine(i);
2791 this->m_TextView.Invalidate();
2795 void CTortoiseGitBlameView::OnMouseHover(UINT nFlags, CPoint point)
2798 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
2799 LONG_PTR height = SendEditor(SCI_TEXTHEIGHT);
2800 line = line + (point.y/height);
2802 if (line < (LONG)m_CommitHash.size())
2804 if (line != m_MouseLine)
2806 m_MouseLine = line;//m_CommitHash[line];
2807 GitRev *pRev;
2808 if(m_ID[line]<0)
2810 pRev=&this->m_NoListCommit[m_CommitHash[line]];
2812 }else
2814 pRev=&this->GetLogData()->GetGitRevAt(this->GetLogList()->GetItemCount()-m_ID[line]);
2817 this->ClientToScreen(&point);
2819 CString str;
2820 str.Format(_T("%s\n<b>%s</b>\n%s %s\n%s"),pRev->m_CommitHash.ToString(),
2821 pRev->m_Subject,
2822 pRev->m_AuthorName,
2823 CAppUtils::FormatDateAndTime( pRev->m_AuthorDate, m_DateFormat ),
2824 pRev->m_Body);
2825 m_ToolTip.AddTool(this,str);
2826 m_ToolTip.DisplayToolTip(&point);
2828 CRect rect;
2829 this->ScreenToClient(&point);
2830 rect.left=LOCATOR_WIDTH;
2831 rect.right=this->m_blamewidth+rect.left;
2832 rect.top=point.y-height;
2833 rect.bottom=point.y+height;
2834 this->InvalidateRect(rect);
2837 else
2839 m_MouseLine=-1;
2844 void CTortoiseGitBlameView::OnMouseMove(UINT nFlags, CPoint point)
2846 TRACKMOUSEEVENT tme;
2847 tme.cbSize=sizeof(TRACKMOUSEEVENT);
2848 tme.dwFlags=TME_HOVER|TME_LEAVE;
2849 tme.hwndTrack=this->m_hWnd;
2850 tme.dwHoverTime=1;
2851 TrackMouseEvent(&tme);
2855 BOOL CTortoiseGitBlameView::PreTranslateMessage(MSG* pMsg)
2857 m_ToolTip.RelayEvent(pMsg);
2858 return CView::PreTranslateMessage(pMsg);
2861 void CTortoiseGitBlameView::OnEditFind()
2863 m_pFindDialog=new CFindReplaceDialog();
2865 m_pFindDialog->Create(TRUE,_T(""),NULL,FR_DOWN,this);
2868 void CTortoiseGitBlameView::OnEditGoto()
2870 CEditGotoDlg dlg;
2871 if(dlg.DoModal()==IDOK)
2873 this->GotoLine(dlg.m_LineNumber);
2877 LRESULT CTortoiseGitBlameView::OnFindDialogMessage(WPARAM wParam, LPARAM lParam)//Õâ¸öÒ²ÊÇÕÒÄǸö³ÌÐò¸ÄµÄ£¬Ö»²»¹ý»»³ÉÁË×Ô¼ºµÄÀà
2879 ASSERT(m_pFindDialog != NULL);
2881 // If the FR_DIALOGTERM flag is set,
2882 // invalidate the handle identifying the dialog box.
2883 if (m_pFindDialog->IsTerminating())
2885 m_pFindDialog = NULL;
2886 return 0;
2889 // If the FR_FINDNEXT flag is set,
2890 // call the application-defined search routine
2891 // to search for the requested string.
2892 if(m_pFindDialog->FindNext())
2894 //read data from dialog
2895 CString FindName = m_pFindDialog->GetFindString();
2896 bool bMatchCase = m_pFindDialog->MatchCase() == TRUE;
2897 bool bMatchWholeWord = m_pFindDialog->MatchWholeWord() == TRUE;
2898 bool bSearchDown = m_pFindDialog->SearchDown() == TRUE;
2900 DoSearch(FindName,m_pFindDialog->m_fr.Flags);
2901 //with given name do search
2902 // *FindWhatYouNeed(FindName, bMatchCase, bMatchWholeWord, bSearchDown);
2905 return 0;
2908 void CTortoiseGitBlameView::OnViewNext()
2910 FindNextLine(this->m_SelectedHash,false);
2912 void CTortoiseGitBlameView::OnViewPrev()
2914 FindNextLine(this->m_SelectedHash,true);
2917 int CTortoiseGitBlameView::FindNextLine(CGitHash CommitHash,bool bUpOrDown)
2919 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
2920 LONG_PTR startline =line;
2921 bool findNoMatch =false;
2922 while(line>=0 && line<m_CommitHash.size())
2924 if(m_CommitHash[line]!=CommitHash)
2926 findNoMatch=true;
2929 if(m_CommitHash[line] == CommitHash && findNoMatch)
2931 if( line == startline+2 )
2933 findNoMatch=false;
2935 else
2937 if( bUpOrDown )
2939 line=FindFirstLine(CommitHash,line);
2941 SendEditor(SCI_LINESCROLL,0,line-startline-2);
2942 return line;
2945 if(bUpOrDown)
2946 line--;
2947 else
2948 line++;
2950 return -1;
2952 BOOL CTortoiseGitBlameView::OnCommand(WPARAM wParam, LPARAM lParam)
2954 // TODO: Add your specialized code here and/or call the base class
2956 return CView::OnCommand(wParam, lParam);