Fix blame show wrong when first char is '^'
[TortoiseGit.git] / src / TortoiseGitBlame / TortoiseGitBlameView.cpp
blob22127bebed11410d4c48f882016b5f4e981f3104
1 // TortoiseGitBlame - a Viewer for Git Blames
3 // Copyright (C) 2003-2008 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // CTortoiseGitBlameView.cpp : implementation of the CTortoiseGitBlameView class
22 #include "stdafx.h"
23 #include "TortoiseGitBlame.h"
25 #include "TortoiseGitBlameDoc.h"
26 #include "TortoiseGitBlameView.h"
27 #include "MainFrm.h"
28 #include "Balloon.h"
29 #include "EditGotoDlg.h"
30 #include "TortoiseGitBlameAppUtils.h"
32 #ifdef _DEBUG
33 #define new DEBUG_NEW
34 #endif
36 UINT CTortoiseGitBlameView::m_FindDialogMessage;
38 // CTortoiseGitBlameView
39 IMPLEMENT_DYNAMIC(CSciEditBlame,CSciEdit)
41 IMPLEMENT_DYNCREATE(CTortoiseGitBlameView, CView)
43 BEGIN_MESSAGE_MAP(CTortoiseGitBlameView, CView)
44 // Standard printing commands
45 ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
46 ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
47 ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CTortoiseGitBlameView::OnFilePrintPreview)
48 ON_COMMAND(ID_EDIT_FIND,OnEditFind)
49 ON_COMMAND(ID_EDIT_GOTO,OnEditGoto)
50 ON_COMMAND(ID_EDIT_COPY,CopySelectedLogToClipboard)
51 ON_COMMAND(ID_VIEW_NEXT,OnViewNext)
52 ON_COMMAND(ID_VIEW_PREV,OnViewPrev)
53 ON_WM_CREATE()
54 ON_WM_SIZE()
55 ON_WM_MOUSEMOVE()
56 ON_WM_MOUSEHOVER()
57 ON_WM_MOUSELEAVE()
58 ON_WM_LBUTTONDOWN()
59 ON_WM_RBUTTONDOWN()
60 ON_NOTIFY(SCN_PAINTED,0,OnSciPainted)
61 ON_NOTIFY(SCN_GETBKCOLOR,0,OnSciGetBkColor)
62 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
63 END_MESSAGE_MAP()
66 // CTortoiseGitBlameView construction/destruction
68 CTortoiseGitBlameView::CTortoiseGitBlameView()
70 // TODO: add construction code here
71 hInstance = 0;
72 hResource = 0;
73 currentDialog = 0;
74 wMain = 0;
75 m_wEditor = 0;
76 wLocator = 0;
78 m_font = 0;
79 m_italicfont = 0;
80 m_blamewidth = 0;
81 m_revwidth = 0;
82 m_datewidth = 0;
83 m_authorwidth = 0;
84 m_pathwidth = 0;
85 m_linewidth = 0;
87 m_windowcolor = ::GetSysColor(COLOR_WINDOW);
88 m_textcolor = ::GetSysColor(COLOR_WINDOWTEXT);
89 m_texthighlightcolor = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
90 m_mouserevcolor = InterColor(m_windowcolor, m_textcolor, 20);
91 m_mouseauthorcolor = InterColor(m_windowcolor, m_textcolor, 10);
92 m_selectedrevcolor = ::GetSysColor(COLOR_HIGHLIGHT);
93 m_selectedauthorcolor = InterColor(m_selectedrevcolor, m_texthighlightcolor, 35);
94 m_mouserev = -2;
96 m_selectedrev = -1;
97 m_selectedorigrev = -1;
98 m_SelectedLine = -1;
99 m_directPointer = 0;
100 m_directFunction = 0;
102 m_lowestrev = LONG_MAX;
103 m_highestrev = 0;
104 m_colorage = true;
106 m_bShowLine=true;
108 m_bShowAuthor=true;
109 m_bShowDate=false;
111 m_FindDialogMessage = ::RegisterWindowMessage(FINDMSGSTRING);
112 m_pFindDialog = NULL;
113 // get short/long datetime setting from registry
114 DWORD RegUseShortDateFormat = CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE);
115 if ( RegUseShortDateFormat )
117 m_DateFormat = DATE_SHORTDATE;
119 else
121 m_DateFormat = DATE_LONGDATE;
125 CTortoiseGitBlameView::~CTortoiseGitBlameView()
127 if (m_font)
128 DeleteObject(m_font);
129 if (m_italicfont)
130 DeleteObject(m_italicfont);
134 int CTortoiseGitBlameView::OnCreate(LPCREATESTRUCT lpcs)
137 CRect rect,rect1;
138 this->GetWindowRect(&rect1);
139 rect.left=m_blamewidth+LOCATOR_WIDTH;
140 rect.right=rect.Width();
141 rect.top=0;
142 rect.bottom=rect.Height();
143 BOOL b=m_TextView.Create(_T("Scintilla"),_T("source"),0,rect,this,0,0);
144 m_TextView.Init(0);
145 m_TextView.ShowWindow( SW_SHOW);
146 //m_TextView.InsertText(_T("Abdadfasdf"));
147 m_wEditor = m_TextView.m_hWnd;
148 CreateFont();
149 InitialiseEditor();
150 m_ToolTip.Create(this->GetParent());
151 m_ToolTip.AddTool(this,_T("Test"));
153 ::AfxGetApp()->GetMainWnd();
154 return CView::OnCreate(lpcs);
158 void CTortoiseGitBlameView::OnSize(UINT nType,int cx, int cy)
161 CRect rect;
162 rect.left=m_blamewidth;
163 rect.right=cx;
164 rect.top=0;
165 rect.bottom=cy;
167 m_TextView.MoveWindow(&rect);
170 BOOL CTortoiseGitBlameView::PreCreateWindow(CREATESTRUCT& cs)
172 // TODO: Modify the Window class or styles here by modifying
173 // the CREATESTRUCT cs
175 return CView::PreCreateWindow(cs);
178 // CTortoiseGitBlameView drawing
180 void CTortoiseGitBlameView::OnDraw(CDC* /*pDC*/)
182 CTortoiseGitBlameDoc* pDoc = GetDocument();
183 ASSERT_VALID(pDoc);
184 if (!pDoc)
185 return;
187 DrawBlame(this->GetDC()->m_hDC);
188 DrawLocatorBar(this->GetDC()->m_hDC);
189 // TODO: add draw code for native data here
193 // CTortoiseGitBlameView printing
196 void CTortoiseGitBlameView::OnFilePrintPreview()
198 AFXPrintPreview(this);
201 BOOL CTortoiseGitBlameView::OnPreparePrinting(CPrintInfo* pInfo)
203 // default preparation
204 return DoPreparePrinting(pInfo);
207 void CTortoiseGitBlameView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
209 // TODO: add extra initialization before printing
212 void CTortoiseGitBlameView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
214 // TODO: add cleanup after printing
217 void CTortoiseGitBlameView::OnRButtonUp(UINT nFlags, CPoint point)
219 ClientToScreen(&point);
220 OnContextMenu(this, point);
223 void CTortoiseGitBlameView::OnContextMenu(CWnd* pWnd, CPoint point)
225 theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE);
229 // CTortoiseGitBlameView diagnostics
231 #ifdef _DEBUG
232 void CTortoiseGitBlameView::AssertValid() const
234 CView::AssertValid();
237 void CTortoiseGitBlameView::Dump(CDumpContext& dc) const
239 CView::Dump(dc);
242 CTortoiseGitBlameDoc* CTortoiseGitBlameView::GetDocument() const // non-debug version is inline
244 ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTortoiseGitBlameDoc)));
245 return (CTortoiseGitBlameDoc*)m_pDocument;
247 #endif //_DEBUG
250 // CTortoiseGitBlameView message handlers
251 CString CTortoiseGitBlameView::GetAppDirectory()
253 CString path;
254 DWORD len = 0;
255 DWORD bufferlen = MAX_PATH; // MAX_PATH is not the limit here!
258 bufferlen += MAX_PATH; // MAX_PATH is not the limit here!
259 TCHAR * pBuf = new TCHAR[bufferlen];
260 len = GetModuleFileName(NULL, pBuf, bufferlen);
261 path = CString(pBuf, len);
262 delete [] pBuf;
263 } while(len == bufferlen);
265 path = path.Left(path.ReverseFind(_T('\\')));
266 //path = path.substr(0, path.rfind('\\') + 1);
268 return path;
271 // Return a color which is interpolated between c1 and c2.
272 // Slider controls the relative proportions as a percentage:
273 // Slider = 0 represents pure c1
274 // Slider = 50 represents equal mixture
275 // Slider = 100 represents pure c2
276 COLORREF CTortoiseGitBlameView::InterColor(COLORREF c1, COLORREF c2, int Slider)
278 int r, g, b;
280 // Limit Slider to 0..100% range
281 if (Slider < 0)
282 Slider = 0;
283 if (Slider > 100)
284 Slider = 100;
286 // The color components have to be treated individually.
287 r = (GetRValue(c2) * Slider + GetRValue(c1) * (100 - Slider)) / 100;
288 g = (GetGValue(c2) * Slider + GetGValue(c1) * (100 - Slider)) / 100;
289 b = (GetBValue(c2) * Slider + GetBValue(c1) * (100 - Slider)) / 100;
291 return RGB(r, g, b);
294 LRESULT CTortoiseGitBlameView::SendEditor(UINT Msg, WPARAM wParam, LPARAM lParam)
296 if (m_directFunction)
298 return ((SciFnDirect) m_directFunction)(m_directPointer, Msg, wParam, lParam);
300 return ::SendMessage(m_wEditor, Msg, wParam, lParam);
303 void CTortoiseGitBlameView::GetRange(int start, int end, char *text)
305 #if 0
306 TEXTRANGE tr;
307 tr.chrg.cpMin = start;
308 tr.chrg.cpMax = end;
309 tr.lpstrText = text;
311 SendMessage(m_wEditor, EM_GETTEXTRANGE, 0, reinterpret_cast<LPARAM>(&tr));
312 #endif
315 void CTortoiseGitBlameView::SetTitle()
317 #if 0
318 char title[MAX_PATH + 100];
319 strcpy_s(title, MAX_PATH + 100, szTitle);
320 strcat_s(title, MAX_PATH + 100, " - ");
321 strcat_s(title, MAX_PATH + 100, szViewtitle);
322 ::SetWindowText(wMain, title);
323 #endif
326 BOOL CTortoiseGitBlameView::OpenLogFile(const char *fileName)
328 #if 0
329 char logmsgbuf[10000+1];
330 FILE * File;
331 fopen_s(&File, fileName, "rb");
332 if (File == 0)
334 return FALSE;
336 LONG rev = 0;
337 CString msg;
338 int slength = 0;
339 int reallength = 0;
340 size_t len = 0;
341 wchar_t wbuf[MAX_LOG_LENGTH+6];
342 for (;;)
344 len = fread(&rev, sizeof(LONG), 1, File);
345 if (len == 0)
347 fclose(File);
348 InitSize();
349 return TRUE;
351 len = fread(&slength, sizeof(int), 1, File);
352 if (len == 0)
354 fclose(File);
355 InitSize();
356 return FALSE;
358 if (slength > MAX_LOG_LENGTH)
360 reallength = slength;
361 slength = MAX_LOG_LENGTH;
363 else
364 reallength = 0;
365 len = fread(logmsgbuf, sizeof(char), slength, File);
366 if (len < (size_t)slength)
368 fclose(File);
369 InitSize();
370 return FALSE;
372 msg = CString(logmsgbuf, slength);
373 if (reallength)
375 fseek(File, reallength-MAX_LOG_LENGTH, SEEK_CUR);
376 msg = msg + _T("\n...");
378 int len2 = ::MultiByteToWideChar(CP_UTF8, NULL, msg.c_str(), min(msg.size(), MAX_LOG_LENGTH+5), wbuf, MAX_LOG_LENGTH+5);
379 wbuf[len2] = 0;
380 len2 = ::WideCharToMultiByte(CP_ACP, NULL, wbuf, len2, logmsgbuf, MAX_LOG_LENGTH+5, NULL, NULL);
381 logmsgbuf[len2] = 0;
382 msg = CString(logmsgbuf);
383 logmessages[rev] = msg;
385 #endif
386 return TRUE;
389 BOOL CTortoiseGitBlameView::OpenFile(const char *fileName)
391 #if 0
392 SendEditor(SCI_SETREADONLY, FALSE);
393 SendEditor(SCI_CLEARALL);
394 SendEditor(EM_EMPTYUNDOBUFFER);
395 SetTitle();
396 SendEditor(SCI_SETSAVEPOINT);
397 SendEditor(SCI_CANCEL);
398 SendEditor(SCI_SETUNDOCOLLECTION, 0);
399 ::ShowWindow(m_wEditor, SW_HIDE);
400 std::ifstream File;
401 File.open(fileName);
402 if (!File.good())
404 return FALSE;
406 char line[100*1024];
407 char * lineptr = NULL;
408 char * trimptr = NULL;
409 //ignore the first two lines, they're of no interest to us
410 File.getline(line, sizeof(line)/sizeof(char));
411 File.getline(line, sizeof(line)/sizeof(char));
412 m_lowestrev = LONG_MAX;
413 m_highestrev = 0;
414 bool bUTF8 = true;
417 File.getline(line, sizeof(line)/sizeof(TCHAR));
418 if (File.gcount()>139)
420 mergelines.push_back((line[0] != ' '));
421 lineptr = &line[9];
422 long rev = _ttol(lineptr);
423 revs.push_back(rev);
424 m_lowestrev = min(m_lowestrev, rev);
425 m_highestrev = max(m_highestrev, rev);
426 lineptr += 7;
427 rev = _ttol(lineptr);
428 origrevs.push_back(rev);
429 lineptr += 7;
430 dates.push_back(CString(lineptr, 30));
431 lineptr += 31;
432 // unfortunately, the 'path' entry can be longer than the 60 chars
433 // we made the column. We therefore have to step through the path
434 // string until we find a space
435 trimptr = lineptr;
438 // TODO: how can we deal with the situation where the path has
439 // a space in it, but the space is after the 60 chars reserved
440 // for it?
441 // The only way to deal with that would be to use a custom
442 // binary format for the blame file.
443 trimptr++;
444 trimptr = _tcschr(trimptr, ' ');
445 } while ((trimptr)&&(trimptr+1 < lineptr+61));
446 if (trimptr)
447 *trimptr = 0;
448 else
449 trimptr = lineptr;
450 paths.push_back(CString(lineptr));
451 if (trimptr+1 < lineptr+61)
452 lineptr +=61;
453 else
454 lineptr = (trimptr+1);
455 trimptr = lineptr+30;
456 while ((*trimptr == ' ')&&(trimptr > lineptr))
457 trimptr--;
458 *(trimptr+1) = 0;
459 authors.push_back(CString(lineptr));
460 lineptr += 31;
461 // in case we find an UTF8 BOM at the beginning of the line, we remove it
462 if (((unsigned char)lineptr[0] == 0xEF)&&((unsigned char)lineptr[1] == 0xBB)&&((unsigned char)lineptr[2] == 0xBF))
464 lineptr += 3;
466 if (((unsigned char)lineptr[0] == 0xBB)&&((unsigned char)lineptr[1] == 0xEF)&&((unsigned char)lineptr[2] == 0xBF))
468 lineptr += 3;
470 // check each line for illegal utf8 sequences. If one is found, we treat
471 // the file as ASCII, otherwise we assume an UTF8 file.
472 char * utf8CheckBuf = lineptr;
473 while ((bUTF8)&&(*utf8CheckBuf))
475 if ((*utf8CheckBuf == 0xC0)||(*utf8CheckBuf == 0xC1)||(*utf8CheckBuf >= 0xF5))
477 bUTF8 = false;
478 break;
480 if ((*utf8CheckBuf & 0xE0)==0xC0)
482 utf8CheckBuf++;
483 if (*utf8CheckBuf == 0)
484 break;
485 if ((*utf8CheckBuf & 0xC0)!=0x80)
487 bUTF8 = false;
488 break;
491 if ((*utf8CheckBuf & 0xF0)==0xE0)
493 utf8CheckBuf++;
494 if (*utf8CheckBuf == 0)
495 break;
496 if ((*utf8CheckBuf & 0xC0)!=0x80)
498 bUTF8 = false;
499 break;
501 utf8CheckBuf++;
502 if (*utf8CheckBuf == 0)
503 break;
504 if ((*utf8CheckBuf & 0xC0)!=0x80)
506 bUTF8 = false;
507 break;
510 if ((*utf8CheckBuf & 0xF8)==0xF0)
512 utf8CheckBuf++;
513 if (*utf8CheckBuf == 0)
514 break;
515 if ((*utf8CheckBuf & 0xC0)!=0x80)
517 bUTF8 = false;
518 break;
520 utf8CheckBuf++;
521 if (*utf8CheckBuf == 0)
522 break;
523 if ((*utf8CheckBuf & 0xC0)!=0x80)
525 bUTF8 = false;
526 break;
528 utf8CheckBuf++;
529 if (*utf8CheckBuf == 0)
530 break;
531 if ((*utf8CheckBuf & 0xC0)!=0x80)
533 bUTF8 = false;
534 break;
538 utf8CheckBuf++;
540 SendEditor(SCI_ADDTEXT, _tcslen(lineptr), reinterpret_cast<LPARAM>(static_cast<char *>(lineptr)));
541 SendEditor(SCI_ADDTEXT, 2, (LPARAM)_T("\r\n"));
543 } while (File.gcount() > 0);
545 if (bUTF8)
546 SendEditor(SCI_SETCODEPAGE, SC_CP_UTF8);
548 SendEditor(SCI_SETUNDOCOLLECTION, 1);
549 ::SetFocus(m_wEditor);
550 SendEditor(EM_EMPTYUNDOBUFFER);
551 SendEditor(SCI_SETSAVEPOINT);
552 SendEditor(SCI_GOTOPOS, 0);
553 SendEditor(SCI_SETSCROLLWIDTHTRACKING, TRUE);
554 SendEditor(SCI_SETREADONLY, TRUE);
556 //check which lexer to use, depending on the filetype
557 SetupLexer(fileName);
558 ::ShowWindow(m_wEditor, SW_SHOW);
559 m_blamewidth = 0;
560 ::InvalidateRect(wMain, NULL, TRUE);
561 RECT rc;
562 GetWindowRect(wMain, &rc);
563 SetWindowPos(wMain, 0, rc.left, rc.top, rc.right-rc.left-1, rc.bottom - rc.top, 0);
564 #endif
565 return TRUE;
568 void CTortoiseGitBlameView::SetAStyle(int style, COLORREF fore, COLORREF back, int size, CString *face)
570 SendEditor(SCI_STYLESETFORE, style, fore);
571 SendEditor(SCI_STYLESETBACK, style, back);
572 if (size >= 1)
573 SendEditor(SCI_STYLESETSIZE, style, size);
574 if (face)
575 SendEditor(SCI_STYLESETFONT, style, reinterpret_cast<LPARAM>(this->m_TextView.StringForControl(*face).GetBuffer()));
578 void CTortoiseGitBlameView::InitialiseEditor()
581 m_directFunction = ::SendMessage(m_wEditor, SCI_GETDIRECTFUNCTION, 0, 0);
582 m_directPointer = ::SendMessage(m_wEditor, SCI_GETDIRECTPOINTER, 0, 0);
583 // Set up the global default style. These attributes are used wherever no explicit choices are made.
584 SetAStyle(STYLE_DEFAULT,
585 black,
586 white,
587 (DWORD)CRegStdWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10),
588 &CString(((stdstring)CRegStdString(_T("Software\\TortoiseGit\\BlameFontName"), _T("Courier New"))).c_str())
590 SendEditor(SCI_SETTABWIDTH, (DWORD)CRegStdWORD(_T("Software\\TortoiseGit\\BlameTabSize"), 4));
591 SendEditor(SCI_SETREADONLY, TRUE);
592 LRESULT pix = SendEditor(SCI_TEXTWIDTH, STYLE_LINENUMBER, (LPARAM)this->m_TextView.StringForControl(_T("_99999")).GetBuffer());
593 if (m_bShowLine)
594 SendEditor(SCI_SETMARGINWIDTHN, 0, pix);
595 else
596 SendEditor(SCI_SETMARGINWIDTHN, 0);
597 SendEditor(SCI_SETMARGINWIDTHN, 1);
598 SendEditor(SCI_SETMARGINWIDTHN, 2);
599 //Set the default windows colors for edit controls
600 SendEditor(SCI_STYLESETFORE, STYLE_DEFAULT, ::GetSysColor(COLOR_WINDOWTEXT));
601 SendEditor(SCI_STYLESETBACK, STYLE_DEFAULT, ::GetSysColor(COLOR_WINDOW));
602 SendEditor(SCI_SETSELFORE, TRUE, ::GetSysColor(COLOR_HIGHLIGHTTEXT));
603 SendEditor(SCI_SETSELBACK, TRUE, ::GetSysColor(COLOR_HIGHLIGHT));
604 SendEditor(SCI_SETCARETFORE, ::GetSysColor(COLOR_WINDOWTEXT));
605 m_regOldLinesColor = CRegStdWORD(_T("Software\\TortoiseGit\\BlameOldColor"), RGB(230, 230, 255));
606 m_regNewLinesColor = CRegStdWORD(_T("Software\\TortoiseGit\\BlameNewColor"), RGB(255, 230, 230));
608 this->m_TextView.Call(SCI_SETWRAPMODE, SC_WRAP_NONE);
612 void CTortoiseGitBlameView::StartSearch()
614 if (m_pFindDialog)
615 return;
616 bool bCase = false;
617 // Initialize FINDREPLACE
618 if (fr.Flags & FR_MATCHCASE)
619 bCase = true;
620 SecureZeroMemory(&fr, sizeof(fr));
621 fr.lStructSize = sizeof(fr);
622 fr.hwndOwner = wMain;
623 fr.lpstrFindWhat = szFindWhat;
624 fr.wFindWhatLen = 80;
625 fr.Flags = FR_HIDEUPDOWN | FR_HIDEWHOLEWORD;
626 fr.Flags |= bCase ? FR_MATCHCASE : 0;
628 currentDialog = FindText(&fr);
631 bool CTortoiseGitBlameView::DoSearch(CString what, DWORD flags)
634 //char szWhat[80];
635 int pos = SendEditor(SCI_GETCURRENTPOS);
636 int line = SendEditor(SCI_LINEFROMPOSITION, pos);
637 bool bFound = false;
638 bool bCaseSensitive = !!(flags & FR_MATCHCASE);
640 //strcpy_s(szWhat, sizeof(szWhat), what);
642 if(!bCaseSensitive)
644 what=what.MakeLower();
647 //CString sWhat = CString(szWhat);
649 //char buf[20];
650 //int i=0;
651 int i=line;
654 int bufsize = SendEditor(SCI_GETLINE, i);
655 char * linebuf = new char[bufsize+1];
656 SecureZeroMemory(linebuf, bufsize+1);
657 SendEditor(SCI_GETLINE, i, (LPARAM)linebuf);
658 CString oneline=this->m_TextView.StringFromControl(linebuf);
659 if (!bCaseSensitive)
661 oneline=oneline.MakeLower();
663 //_stprintf_s(buf, 20, _T("%ld"), revs[i]);
664 if (this->m_Authors[i].Find(what)>=0)
665 bFound = true;
666 else if ((!bCaseSensitive)&&(this->m_Authors[i].MakeLower().Find(what)>=0))
667 bFound = true;
668 else if (oneline.Find(what) >=0)
669 bFound = true;
671 delete [] linebuf;
673 i++;
674 if(i>=(signed int)m_CommitHash.size())
675 i=0;
676 }while(i!=line &&(!bFound));
678 if (bFound)
680 GotoLine(i);
681 int selstart = SendEditor(SCI_GETCURRENTPOS);
682 int selend = SendEditor(SCI_POSITIONFROMLINE, i);
683 SendEditor(SCI_SETSELECTIONSTART, selstart);
684 SendEditor(SCI_SETSELECTIONEND, selend);
685 m_SelectedLine = i-1;
687 else
689 ::MessageBox(wMain, what+_T(" not found"), _T("CTortoiseGitBlameView"), MB_ICONINFORMATION);
692 return true;
695 bool CTortoiseGitBlameView::GotoLine(long line)
697 --line;
698 if (line < 0)
699 return false;
700 if ((unsigned long)line >= m_CommitHash.size())
702 line = m_CommitHash.size()-1;
705 int nCurrentPos = SendEditor(SCI_GETCURRENTPOS);
706 int nCurrentLine = SendEditor(SCI_LINEFROMPOSITION,nCurrentPos);
707 int nFirstVisibleLine = SendEditor(SCI_GETFIRSTVISIBLELINE);
708 int nLinesOnScreen = SendEditor(SCI_LINESONSCREEN);
710 if ( line>=nFirstVisibleLine && line<=nFirstVisibleLine+nLinesOnScreen)
712 // no need to scroll
713 SendEditor(SCI_GOTOLINE, line);
715 else
717 // Place the requested line one third from the top
718 if ( line > nCurrentLine )
720 SendEditor(SCI_GOTOLINE, (WPARAM)(line+(int)nLinesOnScreen*(2/3.0)));
722 else
724 SendEditor(SCI_GOTOLINE, (WPARAM)(line-(int)nLinesOnScreen*(1/3.0)));
728 // Highlight the line
729 int nPosStart = SendEditor(SCI_POSITIONFROMLINE,line);
730 int nPosEnd = SendEditor(SCI_GETLINEENDPOSITION,line);
731 SendEditor(SCI_SETSEL,nPosEnd,nPosStart);
733 return true;
736 bool CTortoiseGitBlameView::ScrollToLine(long line)
738 if (line < 0)
739 return false;
741 int nCurrentLine = SendEditor(SCI_GETFIRSTVISIBLELINE);
743 int scrolldelta = line - nCurrentLine;
744 SendEditor(SCI_LINESCROLL, 0, scrolldelta);
746 return true;
749 void CTortoiseGitBlameView::CopySelectedLogToClipboard()
751 this->GetLogList()->CopySelectionToClipBoard(FALSE);
754 void CTortoiseGitBlameView::BlamePreviousRevision()
756 #if 0
757 LONG nRevisionTo = m_selectedorigrev - 1;
758 if ( nRevisionTo<1 )
760 return;
763 // We now determine the smallest revision number in the blame file (but ignore "-1")
764 // We do this for two reasons:
765 // 1. we respect the "From revision" which the user entered
766 // 2. we speed up the call of "svn blame" because previous smaller revision numbers don't have any effect on the result
767 LONG nSmallestRevision = -1;
768 for (LONG line=0;line<(LONG)app.revs.size();line++)
770 const LONG nRevision = app.revs[line];
771 if ( nRevision > 0 )
773 if ( nSmallestRevision < 1 )
775 nSmallestRevision = nRevision;
777 else
779 nSmallestRevision = min(nSmallestRevision,nRevision);
784 char bufStartRev[20];
785 _stprintf_s(bufStartRev, 20, _T("%d"), nSmallestRevision);
787 char bufEndRev[20];
788 _stprintf_s(bufEndRev, 20, _T("%d"), nRevisionTo);
790 char bufLine[20];
791 _stprintf_s(bufLine, 20, _T("%d"), m_SelectedLine+1); //using the current line is a good guess.
793 STARTUPINFO startup;
794 PROCESS_INFORMATION process;
795 memset(&startup, 0, sizeof(startup));
796 startup.cb = sizeof(startup);
797 memset(&process, 0, sizeof(process));
798 stdstring tortoiseProcPath = GetAppDirectory() + _T("TortoiseProc.exe");
799 stdstring svnCmd = _T(" /command:blame ");
800 svnCmd += _T(" /path:\"");
801 svnCmd += szOrigPath;
802 svnCmd += _T("\"");
803 svnCmd += _T(" /startrev:");
804 svnCmd += bufStartRev;
805 svnCmd += _T(" /endrev:");
806 svnCmd += bufEndRev;
807 svnCmd += _T(" /line:");
808 svnCmd += bufLine;
809 if (bIgnoreEOL)
810 svnCmd += _T(" /ignoreeol");
811 if (bIgnoreSpaces)
812 svnCmd += _T(" /ignorespaces");
813 if (bIgnoreAllSpaces)
814 svnCmd += _T(" /ignoreallspaces");
815 if (CreateProcess(tortoiseProcPath.c_str(), const_cast<TCHAR*>(svnCmd.c_str()), NULL, NULL, FALSE, 0, 0, 0, &startup, &process))
817 CloseHandle(process.hThread);
818 CloseHandle(process.hProcess);
820 #endif
823 void CTortoiseGitBlameView::DiffPreviousRevision()
825 #if 0
826 LONG nRevisionTo = m_selectedorigrev;
827 if ( nRevisionTo<1 )
829 return;
832 LONG nRevisionFrom = nRevisionTo-1;
834 char bufStartRev[20];
835 _stprintf_s(bufStartRev, 20, _T("%d"), nRevisionFrom);
837 char bufEndRev[20];
838 _stprintf_s(bufEndRev, 20, _T("%d"), nRevisionTo);
840 STARTUPINFO startup;
841 PROCESS_INFORMATION process;
842 memset(&startup, 0, sizeof(startup));
843 startup.cb = sizeof(startup);
844 memset(&process, 0, sizeof(process));
845 stdstring tortoiseProcPath = GetAppDirectory() + _T("TortoiseProc.exe");
846 stdstring svnCmd = _T(" /command:diff ");
847 svnCmd += _T(" /path:\"");
848 svnCmd += szOrigPath;
849 svnCmd += _T("\"");
850 svnCmd += _T(" /startrev:");
851 svnCmd += bufStartRev;
852 svnCmd += _T(" /endrev:");
853 svnCmd += bufEndRev;
854 if (CreateProcess(tortoiseProcPath.c_str(), const_cast<TCHAR*>(svnCmd.c_str()), NULL, NULL, FALSE, 0, 0, 0, &startup, &process))
856 CloseHandle(process.hThread);
857 CloseHandle(process.hProcess);
859 #endif
862 void CTortoiseGitBlameView::ShowLog()
864 #if 0
865 char bufRev[20];
866 _stprintf_s(bufRev, 20, _T("%d"), m_selectedorigrev);
868 STARTUPINFO startup;
869 PROCESS_INFORMATION process;
870 memset(&startup, 0, sizeof(startup));
871 startup.cb = sizeof(startup);
872 memset(&process, 0, sizeof(process));
873 stdstring tortoiseProcPath = GetAppDirectory() + _T("TortoiseProc.exe");
874 stdstring svnCmd = _T(" /command:log ");
875 svnCmd += _T(" /path:\"");
876 svnCmd += szOrigPath;
877 svnCmd += _T("\"");
878 svnCmd += _T(" /startrev:");
879 svnCmd += bufRev;
880 svnCmd += _T(" /pegrev:");
881 svnCmd += bufRev;
882 if (CreateProcess(tortoiseProcPath.c_str(), const_cast<TCHAR*>(svnCmd.c_str()), NULL, NULL, FALSE, 0, 0, 0, &startup, &process))
884 CloseHandle(process.hThread);
885 CloseHandle(process.hProcess);
887 #endif
890 void CTortoiseGitBlameView::Notify(SCNotification *notification)
892 switch (notification->nmhdr.code)
894 case SCN_SAVEPOINTREACHED:
895 break;
897 case SCN_SAVEPOINTLEFT:
898 break;
899 case SCN_PAINTED:
900 // InvalidateRect(wBlame, NULL, FALSE);
901 // InvalidateRect(wLocator, NULL, FALSE);
902 break;
903 case SCN_GETBKCOLOR:
904 // if ((m_colorage)&&(notification->line < (int)revs.size()))
905 // {
906 // notification->lParam = InterColor(DWORD(m_regOldLinesColor), DWORD(m_regNewLinesColor), (revs[notification->line]-m_lowestrev)*100/((m_highestrev-m_lowestrev)+1));
907 // }
908 break;
912 void CTortoiseGitBlameView::Command(int id)
914 #if 0
915 switch (id)
917 // case IDM_EXIT:
918 // ::PostQuitMessage(0);
919 // break;
920 case ID_EDIT_FIND:
921 StartSearch();
922 break;
923 case ID_COPYTOCLIPBOARD:
924 CopySelectedLogToClipboard();
925 break;
926 case ID_BLAME_PREVIOUS_REVISION:
927 BlamePreviousRevision();
928 break;
929 case ID_DIFF_PREVIOUS_REVISION:
930 DiffPreviousRevision();
931 break;
932 case ID_SHOWLOG:
933 ShowLog();
934 break;
935 case ID_EDIT_GOTOLINE:
936 GotoLineDlg();
937 break;
938 case ID_VIEW_COLORAGEOFLINES:
940 m_colorage = !m_colorage;
941 HMENU hMenu = GetMenu(wMain);
942 UINT uCheck = MF_BYCOMMAND;
943 uCheck |= m_colorage ? MF_CHECKED : MF_UNCHECKED;
944 CheckMenuItem(hMenu, ID_VIEW_COLORAGEOFLINES, uCheck);
945 m_blamewidth = 0;
946 InitSize();
948 break;
949 case ID_VIEW_MERGEPATH:
951 ShowPath = !ShowPath;
952 HMENU hMenu = GetMenu(wMain);
953 UINT uCheck = MF_BYCOMMAND;
954 uCheck |= ShowPath ? MF_CHECKED : MF_UNCHECKED;
955 CheckMenuItem(hMenu, ID_VIEW_MERGEPATH, uCheck);
956 m_blamewidth = 0;
957 InitSize();
959 default:
960 break;
962 #endif
966 LONG CTortoiseGitBlameView::GetBlameWidth()
968 LONG blamewidth = 0;
969 SIZE width;
970 CreateFont();
971 HDC hDC = this->GetDC()->m_hDC;
972 HFONT oldfont = (HFONT)::SelectObject(hDC, m_font);
974 TCHAR buf[MAX_PATH];
976 int maxnum=0;
977 for (unsigned int i=0;i<this->m_ID.size();i++)
979 if(m_ID[i]>maxnum)
980 maxnum=m_ID[i];
982 _stprintf_s(buf, MAX_PATH, _T("%d."), maxnum);
983 ::GetTextExtentPoint(hDC, buf, _tcslen(buf), &width);
984 m_revwidth = width.cx + BLAMESPACE;
985 blamewidth += m_revwidth;
987 #if 0
988 _stprintf_s(buf, MAX_PATH, _T("%d"), m_CommitHash.size());
989 ::GetTextExtentPoint(hDC, buf, _tcslen(buf), &width);
990 m_linewidth = width.cx + BLAMESPACE;
991 blamewidth += m_revwidth;
992 #endif
994 if (m_bShowDate)
996 _stprintf_s(buf, MAX_PATH, _T("%30s"), _T("31.08.2001 06:24:14"));
997 ::GetTextExtentPoint32(hDC, buf, _tcslen(buf), &width);
998 m_datewidth = width.cx + BLAMESPACE;
999 blamewidth += m_datewidth;
1001 if ( m_bShowAuthor)
1003 SIZE maxwidth = {0};
1005 for (unsigned int i=0;i<this->m_Authors.size();i++)
1006 //for (std::vector<CString>::iterator I = authors.begin(); I != authors.end(); ++I)
1008 ::GetTextExtentPoint32(hDC,m_Authors[i] , m_Authors[i].GetLength(), &width);
1009 if (width.cx > maxwidth.cx)
1010 maxwidth = width;
1012 m_authorwidth = maxwidth.cx + BLAMESPACE;
1013 blamewidth += m_authorwidth;
1015 #if 0
1016 if (ShowPath)
1018 SIZE maxwidth = {0};
1019 for (std::vector<CString>::iterator I = paths.begin(); I != paths.end(); ++I)
1021 ::GetTextExtentPoint32(hDC, I->c_str(), I->size(), &width);
1022 if (width.cx > maxwidth.cx)
1023 maxwidth = width;
1025 m_pathwidth = maxwidth.cx + BLAMESPACE;
1026 blamewidth += m_pathwidth;
1028 #endif
1029 ::SelectObject(hDC, oldfont);
1030 POINT pt = {blamewidth, 0};
1031 LPtoDP(hDC, &pt, 1);
1032 m_blamewidth = pt.x;
1033 //::ReleaseDC(wBlame, hDC);
1035 //return m_blamewidth;
1036 return blamewidth;
1040 void CTortoiseGitBlameView::CreateFont()
1042 if (m_font)
1043 return;
1044 LOGFONT lf = {0};
1045 lf.lfWeight = 400;
1046 HDC hDC = ::GetDC(wBlame);
1047 lf.lfHeight = -MulDiv((DWORD)CRegStdWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10), GetDeviceCaps(hDC, LOGPIXELSY), 72);
1048 lf.lfCharSet = DEFAULT_CHARSET;
1049 CRegStdString fontname = CRegStdString(_T("Software\\TortoiseGit\\BlameFontName"), _T("Courier New"));
1050 _tcscpy_s(lf.lfFaceName, 32, ((stdstring)fontname).c_str());
1051 m_font = ::CreateFontIndirect(&lf);
1053 lf.lfItalic = TRUE;
1054 m_italicfont = ::CreateFontIndirect(&lf);
1056 ::ReleaseDC(wBlame, hDC);
1058 //m_TextView.SetFont(lf.lfFaceName,((DWORD)CRegStdWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10)));
1061 void CTortoiseGitBlameView::DrawBlame(HDC hDC)
1064 if (hDC == NULL)
1065 return;
1066 if (m_font == NULL)
1067 return;
1069 HFONT oldfont = NULL;
1070 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
1071 LONG_PTR linesonscreen = SendEditor(SCI_LINESONSCREEN);
1072 LONG_PTR height = SendEditor(SCI_TEXTHEIGHT);
1073 LONG_PTR Y = 0;
1074 TCHAR buf[MAX_PATH];
1075 RECT rc;
1076 BOOL sel = FALSE;
1077 //::GetClientRect(this->m_hWnd, &rc);
1078 for (LRESULT i=line; i<(line+linesonscreen); ++i)
1080 sel = FALSE;
1081 if (i < (int)m_CommitHash.size())
1083 // if (mergelines[i])
1084 // oldfont = (HFONT)::SelectObject(hDC, m_italicfont);
1085 // else
1086 oldfont = (HFONT)::SelectObject(hDC, m_font);
1087 ::SetBkColor(hDC, m_windowcolor);
1088 ::SetTextColor(hDC, m_textcolor);
1089 if (m_CommitHash[i].GetLength()>0)
1091 //if (m_CommitHash[i].Compare(m_MouseHash)==0)
1092 // ::SetBkColor(hDC, m_mouseauthorcolor);
1093 if (m_CommitHash[i].Compare(m_SelectedHash)==0)
1095 ::SetBkColor(hDC, m_selectedauthorcolor);
1096 ::SetTextColor(hDC, m_texthighlightcolor);
1097 sel = TRUE;
1101 if(m_MouseLine == i)
1102 ::SetBkColor(hDC, m_mouserevcolor);
1104 //if ((revs[i] == m_mouserev)&&(!sel))
1105 // ::SetBkColor(hDC, m_mouserevcolor);
1106 //if (revs[i] == m_selectedrev)
1108 // ::SetBkColor(hDC, m_selectedrevcolor);
1109 // ::SetTextColor(hDC, m_texthighlightcolor);
1112 CString str;
1113 if(m_ID[i]>=0)
1114 str.Format(_T("%d"),m_ID[i]);
1116 //_stprintf_s(buf, MAX_PATH, _T("%8ld "), revs[i]);
1117 rc.top=Y;
1118 rc.left=LOCATOR_WIDTH;
1119 rc.bottom=Y+height;
1120 rc.right = rc.left + m_blamewidth;
1121 ::ExtTextOut(hDC, LOCATOR_WIDTH, Y, ETO_CLIPPED, &rc, str, str.GetLength(), 0);
1122 int Left = m_revwidth;
1124 if (m_bShowAuthor)
1126 rc.right = rc.left + Left + m_authorwidth;
1127 //_stprintf_s(buf, MAX_PATH, _T("%-30s "), authors[i].c_str());
1128 ::ExtTextOut(hDC, Left, Y, ETO_CLIPPED, &rc, m_Authors[i], m_Authors[i].GetLength(), 0);
1129 Left += m_authorwidth;
1131 #if 0
1132 if (ShowDate)
1134 rc.right = rc.left + Left + m_datewidth;
1135 _stprintf_s(buf, MAX_PATH, _T("%30s "), dates[i].c_str());
1136 ::ExtTextOut(hDC, Left, Y, ETO_CLIPPED, &rc, buf, _tcslen(buf), 0);
1137 Left += m_datewidth;
1140 #endif
1141 #if 0
1142 if (ShowPath)
1144 rc.right = rc.left + Left + m_pathwidth;
1145 _stprintf_s(buf, MAX_PATH, _T("%-60s "), paths[i].c_str());
1146 ::ExtTextOut(hDC, Left, Y, ETO_CLIPPED, &rc, buf, _tcslen(buf), 0);
1147 Left += m_authorwidth;
1149 #endif
1150 if ((i==m_SelectedLine)&&(m_pFindDialog))
1152 LOGBRUSH brush;
1153 brush.lbColor = m_textcolor;
1154 brush.lbHatch = 0;
1155 brush.lbStyle = BS_SOLID;
1156 HPEN pen = ExtCreatePen(PS_SOLID | PS_GEOMETRIC, 2, &brush, 0, NULL);
1157 HGDIOBJ hPenOld = SelectObject(hDC, pen);
1158 RECT rc2 = rc;
1159 rc2.top = Y;
1160 rc2.bottom = Y + height;
1161 ::MoveToEx(hDC, rc2.left, rc2.top, NULL);
1162 ::LineTo(hDC, rc2.right, rc2.top);
1163 ::LineTo(hDC, rc2.right, rc2.bottom);
1164 ::LineTo(hDC, rc2.left, rc2.bottom);
1165 ::LineTo(hDC, rc2.left, rc2.top);
1166 SelectObject(hDC, hPenOld);
1167 DeleteObject(pen);
1169 Y += height;
1170 ::SelectObject(hDC, oldfont);
1172 else
1174 ::SetBkColor(hDC, m_windowcolor);
1175 for (int j=0; j< MAX_PATH; ++j)
1176 buf[j]=' ';
1177 ::ExtTextOut(hDC, 0, Y, ETO_CLIPPED, &rc, buf, MAX_PATH-1, 0);
1178 Y += height;
1183 void CTortoiseGitBlameView::DrawHeader(HDC hDC)
1185 #if 0
1186 if (hDC == NULL)
1187 return;
1189 RECT rc;
1190 HFONT oldfont = (HFONT)::SelectObject(hDC, GetStockObject(DEFAULT_GUI_FONT));
1191 ::GetClientRect(wHeader, &rc);
1193 ::SetBkColor(hDC, ::GetSysColor(COLOR_BTNFACE));
1195 TCHAR szText[MAX_LOADSTRING];
1196 LoadString(app.hResource, IDS_HEADER_REVISION, szText, MAX_LOADSTRING);
1197 ::ExtTextOut(hDC, LOCATOR_WIDTH, 0, ETO_CLIPPED, &rc, szText, _tcslen(szText), 0);
1198 int Left = m_revwidth+LOCATOR_WIDTH;
1199 if (ShowDate)
1201 LoadString(app.hResource, IDS_HEADER_DATE, szText, MAX_LOADSTRING);
1202 ::ExtTextOut(hDC, Left, 0, ETO_CLIPPED, &rc, szText, _tcslen(szText), 0);
1203 Left += m_datewidth;
1205 if (ShowAuthor)
1207 LoadString(app.hResource, IDS_HEADER_AUTHOR, szText, MAX_LOADSTRING);
1208 ::ExtTextOut(hDC, Left, 0, ETO_CLIPPED, &rc, szText, _tcslen(szText), 0);
1209 Left += m_authorwidth;
1211 if (ShowPath)
1213 LoadString(app.hResource, IDS_HEADER_PATH, szText, MAX_LOADSTRING);
1214 ::ExtTextOut(hDC, Left, 0, ETO_CLIPPED, &rc, szText, _tcslen(szText), 0);
1215 Left += m_pathwidth;
1217 LoadString(app.hResource, IDS_HEADER_LINE, szText, MAX_LOADSTRING);
1218 ::ExtTextOut(hDC, Left, 0, ETO_CLIPPED, &rc, szText, _tcslen(szText), 0);
1220 ::SelectObject(hDC, oldfont);
1221 #endif
1224 void CTortoiseGitBlameView::DrawLocatorBar(HDC hDC)
1226 if (hDC == NULL)
1227 return;
1229 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
1230 LONG_PTR linesonscreen = SendEditor(SCI_LINESONSCREEN);
1231 LONG_PTR Y = 0;
1232 COLORREF blackColor = GetSysColor(COLOR_WINDOWTEXT);
1234 RECT rc;
1235 //::GetClientRect(wLocator, &rc);
1236 this->GetClientRect(&rc);
1238 rc.right=LOCATOR_WIDTH;
1240 RECT lineRect = rc;
1241 LONG height = rc.bottom-rc.top;
1242 LONG currentLine = 0;
1244 // draw the colored bar
1245 for (std::vector<LONG>::const_iterator it = m_ID.begin(); it != m_ID.end(); ++it)
1247 currentLine++;
1248 // get the line color
1249 COLORREF cr = InterColor(DWORD(m_regOldLinesColor), DWORD(m_regNewLinesColor), (*it - m_lowestrev)*100/((m_highestrev-m_lowestrev)+1));
1250 if ((currentLine > line)&&(currentLine <= (line + linesonscreen)))
1252 cr = InterColor(cr, blackColor, 10);
1254 SetBkColor(hDC, cr);
1255 lineRect.top = Y;
1256 lineRect.bottom = (currentLine * height / m_ID.size());
1257 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, NULL, 0, NULL);
1258 Y = lineRect.bottom;
1261 if (m_ID.size())
1263 // now draw two lines indicating the scroll position of the source view
1264 SetBkColor(hDC, blackColor);
1265 lineRect.top = line * height / m_ID.size();
1266 lineRect.bottom = lineRect.top+1;
1267 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, NULL, 0, NULL);
1268 lineRect.top = (line + linesonscreen) * height / m_ID.size();
1269 lineRect.bottom = lineRect.top+1;
1270 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, NULL, 0, NULL);
1275 void CTortoiseGitBlameView::StringExpand(LPSTR str)
1277 char * cPos = str;
1280 cPos = strchr(cPos, '\n');
1281 if (cPos)
1283 memmove(cPos+1, cPos, strlen(cPos)*sizeof(char));
1284 *cPos = '\r';
1285 cPos++;
1286 cPos++;
1288 } while (cPos != NULL);
1290 void CTortoiseGitBlameView::StringExpand(LPWSTR str)
1292 wchar_t * cPos = str;
1295 cPos = wcschr(cPos, '\n');
1296 if (cPos)
1298 memmove(cPos+1, cPos, wcslen(cPos)*sizeof(wchar_t));
1299 *cPos = '\r';
1300 cPos++;
1301 cPos++;
1303 } while (cPos != NULL);
1306 // Forward declarations of functions included in this code module:
1307 ATOM MyRegisterClass(HINSTANCE hResource);
1308 ATOM MyRegisterBlameClass(HINSTANCE hResource);
1309 ATOM MyRegisterHeaderClass(HINSTANCE hResource);
1310 ATOM MyRegisterLocatorClass(HINSTANCE hResource);
1311 BOOL InitInstance(HINSTANCE, int);
1312 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
1313 LRESULT CALLBACK WndBlameProc(HWND, UINT, WPARAM, LPARAM);
1314 LRESULT CALLBACK WndHeaderProc(HWND, UINT, WPARAM, LPARAM);
1315 LRESULT CALLBACK WndLocatorProc(HWND, UINT, WPARAM, LPARAM);
1316 UINT uFindReplaceMsg;
1318 #if 0
1319 int APIENTRY _tWinMain(HINSTANCE hInstance,
1320 HINSTANCE /*hPrevInstance*/,
1321 LPTSTR lpCmdLine,
1322 int nCmdShow)
1324 app.hInstance = hInstance;
1325 MSG msg;
1326 HACCEL hAccelTable;
1328 if (::LoadLibrary("SciLexer.DLL") == NULL)
1329 return FALSE;
1331 CRegStdWORD loc = CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033);
1332 long langId = loc;
1334 CLangDll langDLL;
1335 app.hResource = langDLL.Init(_T("CTortoiseGitBlameView"), langId);
1336 if (app.hResource == NULL)
1337 app.hResource = app.hInstance;
1339 // Initialize global strings
1340 LoadString(app.hResource, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
1341 LoadString(app.hResource, IDC_TortoiseGitBlameView, szWindowClass, MAX_LOADSTRING);
1342 LoadString(app.hResource, IDS_SEARCHNOTFOUND, searchstringnotfound, MAX_LOADSTRING);
1343 MyRegisterClass(app.hResource);
1344 MyRegisterBlameClass(app.hResource);
1345 MyRegisterHeaderClass(app.hResource);
1346 MyRegisterLocatorClass(app.hResource);
1348 // Perform application initialization:
1349 if (!InitInstance (app.hResource, nCmdShow))
1351 langDLL.Close();
1352 return FALSE;
1355 SecureZeroMemory(szViewtitle, MAX_PATH);
1356 SecureZeroMemory(szOrigPath, MAX_PATH);
1357 char blamefile[MAX_PATH] = {0};
1358 char logfile[MAX_PATH] = {0};
1360 CCmdLineParser parser(lpCmdLine);
1363 if (__argc > 1)
1365 _tcscpy_s(blamefile, MAX_PATH, __argv[1]);
1367 if (__argc > 2)
1369 _tcscpy_s(logfile, MAX_PATH, __argv[2]);
1371 if (__argc > 3)
1373 _tcscpy_s(szViewtitle, MAX_PATH, __argv[3]);
1374 if (parser.HasVal(_T("revrange")))
1376 _tcscat_s(szViewtitle, MAX_PATH, _T(" : "));
1377 _tcscat_s(szViewtitle, MAX_PATH, parser.GetVal(_T("revrange")));
1380 if ((_tcslen(blamefile)==0) || parser.HasKey(_T("?")) || parser.HasKey(_T("help")))
1382 TCHAR szInfo[MAX_LOADSTRING];
1383 LoadString(app.hResource, IDS_COMMANDLINE_INFO, szInfo, MAX_LOADSTRING);
1384 MessageBox(NULL, szInfo, _T("CTortoiseGitBlameView"), MB_ICONERROR);
1385 langDLL.Close();
1386 return 0;
1389 if ( parser.HasKey(_T("path")) )
1391 _tcscpy_s(szOrigPath, MAX_PATH, parser.GetVal(_T("path")));
1393 app.bIgnoreEOL = parser.HasKey(_T("ignoreeol"));
1394 app.bIgnoreSpaces = parser.HasKey(_T("ignorespaces"));
1395 app.bIgnoreAllSpaces = parser.HasKey(_T("ignoreallspaces"));
1397 app.SendEditor(SCI_SETCODEPAGE, GetACP());
1398 app.OpenFile(blamefile);
1399 if (_tcslen(logfile)>0)
1400 app.OpenLogFile(logfile);
1402 if (parser.HasKey(_T("line")))
1404 app.GotoLine(parser.GetLongVal(_T("line")));
1407 CheckMenuItem(GetMenu(app.wMain), ID_VIEW_COLORAGEOFLINES, MF_CHECKED|MF_BYCOMMAND);
1410 hAccelTable = LoadAccelerators(app.hResource, (LPCTSTR)IDC_TortoiseGitBlameView);
1412 BOOL going = TRUE;
1413 msg.wParam = 0;
1414 while (going)
1416 going = GetMessage(&msg, NULL, 0, 0);
1417 if (app.currentDialog && going)
1419 if (!IsDialogMessage(app.currentDialog, &msg))
1421 if (TranslateAccelerator(msg.hwnd, hAccelTable, &msg) == 0)
1423 TranslateMessage(&msg);
1424 DispatchMessage(&msg);
1428 else if (going)
1430 if (TranslateAccelerator(app.wMain, hAccelTable, &msg) == 0)
1432 TranslateMessage(&msg);
1433 DispatchMessage(&msg);
1437 langDLL.Close();
1438 return msg.wParam;
1441 ATOM MyRegisterClass(HINSTANCE hResource)
1443 WNDCLASSEX wcex;
1445 wcex.cbSize = sizeof(WNDCLASSEX);
1447 wcex.style = CS_HREDRAW | CS_VREDRAW;
1448 wcex.lpfnWndProc = (WNDPROC)WndProc;
1449 wcex.cbClsExtra = 0;
1450 wcex.cbWndExtra = 0;
1451 wcex.hInstance = hResource;
1452 wcex.hIcon = LoadIcon(hResource, (LPCTSTR)IDI_TortoiseGitBlameView);
1453 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
1454 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
1455 wcex.lpszMenuName = (LPCTSTR)IDC_TortoiseGitBlameView;
1456 wcex.lpszClassName = szWindowClass;
1457 wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
1459 return RegisterClassEx(&wcex);
1462 ATOM MyRegisterBlameClass(HINSTANCE hResource)
1464 WNDCLASSEX wcex;
1466 wcex.cbSize = sizeof(WNDCLASSEX);
1468 wcex.style = CS_HREDRAW | CS_VREDRAW;
1469 wcex.lpfnWndProc = (WNDPROC)WndBlameProc;
1470 wcex.cbClsExtra = 0;
1471 wcex.cbWndExtra = 0;
1472 wcex.hInstance = hResource;
1473 wcex.hIcon = LoadIcon(hResource, (LPCTSTR)IDI_TortoiseGitBlameView);
1474 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
1475 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
1476 wcex.lpszMenuName = 0;
1477 wcex.lpszClassName = _T("TortoiseGitBlameViewBlame");
1478 wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
1480 return RegisterClassEx(&wcex);
1483 ATOM MyRegisterHeaderClass(HINSTANCE hResource)
1485 WNDCLASSEX wcex;
1487 wcex.cbSize = sizeof(WNDCLASSEX);
1489 wcex.style = CS_HREDRAW | CS_VREDRAW;
1490 wcex.lpfnWndProc = (WNDPROC)WndHeaderProc;
1491 wcex.cbClsExtra = 0;
1492 wcex.cbWndExtra = 0;
1493 wcex.hInstance = hResource;
1494 wcex.hIcon = LoadIcon(hResource, (LPCTSTR)IDI_TortoiseGitBlameView);
1495 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
1496 wcex.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
1497 wcex.lpszMenuName = 0;
1498 wcex.lpszClassName = _T("TortoiseGitBlameViewHeader");
1499 wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
1501 return RegisterClassEx(&wcex);
1504 ATOM MyRegisterLocatorClass(HINSTANCE hResource)
1506 WNDCLASSEX wcex;
1508 wcex.cbSize = sizeof(WNDCLASSEX);
1510 wcex.style = CS_HREDRAW | CS_VREDRAW;
1511 wcex.lpfnWndProc = (WNDPROC)WndLocatorProc;
1512 wcex.cbClsExtra = 0;
1513 wcex.cbWndExtra = 0;
1514 wcex.hInstance = hResource;
1515 wcex.hIcon = LoadIcon(hResource, (LPCTSTR)IDI_TortoiseGitBlameView);
1516 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
1517 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
1518 wcex.lpszMenuName = 0;
1519 wcex.lpszClassName = _T("TortoiseGitBlameViewLocator");
1520 wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
1522 return RegisterClassEx(&wcex);
1525 BOOL InitInstance(HINSTANCE hResource, int nCmdShow)
1527 app.wMain = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
1528 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hResource, NULL);
1530 if (!app.wMain)
1532 return FALSE;
1535 CRegStdWORD pos(_T("Software\\TortoiseGit\\TBlamePos"), 0);
1536 CRegStdWORD width(_T("Software\\TortoiseGit\\TBlameSize"), 0);
1537 CRegStdWORD state(_T("Software\\TortoiseGit\\TBlameState"), 0);
1538 if (DWORD(pos) && DWORD(width))
1540 RECT rc;
1541 rc.left = LOWORD(DWORD(pos));
1542 rc.top = HIWORD(DWORD(pos));
1543 rc.right = rc.left + LOWORD(DWORD(width));
1544 rc.bottom = rc.top + HIWORD(DWORD(width));
1545 HMONITOR hMon = MonitorFromRect(&rc, MONITOR_DEFAULTTONULL);
1546 if (hMon)
1548 // only restore the window position if the monitor is valid
1549 MoveWindow(app.wMain, LOWORD(DWORD(pos)), HIWORD(DWORD(pos)),
1550 LOWORD(DWORD(width)), HIWORD(DWORD(width)), FALSE);
1553 if (DWORD(state) == SW_MAXIMIZE)
1554 ShowWindow(app.wMain, SW_MAXIMIZE);
1555 else
1556 ShowWindow(app.wMain, nCmdShow);
1557 UpdateWindow(app.wMain);
1559 //Create the tooltips
1561 INITCOMMONCONTROLSEX iccex;
1562 app.hwndTT; // handle to the ToolTip control
1563 TOOLINFO ti;
1564 RECT rect; // for client area coordinates
1565 iccex.dwICC = ICC_WIN95_CLASSES;
1566 iccex.dwSize = sizeof(INITCOMMONCONTROLSEX);
1567 InitCommonControlsEx(&iccex);
1569 /* CREATE A TOOLTIP WINDOW */
1570 app.hwndTT = CreateWindowEx(WS_EX_TOPMOST,
1571 TOOLTIPS_CLASS,
1572 NULL,
1573 WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
1574 CW_USEDEFAULT,
1575 CW_USEDEFAULT,
1576 CW_USEDEFAULT,
1577 CW_USEDEFAULT,
1578 app.wBlame,
1579 NULL,
1580 app.hResource,
1581 NULL
1584 SetWindowPos(app.hwndTT,
1585 HWND_TOPMOST,
1590 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
1592 /* GET COORDINATES OF THE MAIN CLIENT AREA */
1593 GetClientRect (app.wBlame, &rect);
1595 /* INITIALIZE MEMBERS OF THE TOOLINFO STRUCTURE */
1596 ti.cbSize = sizeof(TOOLINFO);
1597 ti.uFlags = TTF_TRACK | TTF_ABSOLUTE;//TTF_SUBCLASS | TTF_PARSELINKS;
1598 ti.hwnd = app.wBlame;
1599 ti.hinst = app.hResource;
1600 ti.uId = 0;
1601 ti.lpszText = LPSTR_TEXTCALLBACK;
1602 // ToolTip control will cover the whole window
1603 ti.rect.left = rect.left;
1604 ti.rect.top = rect.top;
1605 ti.rect.right = rect.right;
1606 ti.rect.bottom = rect.bottom;
1608 /* SEND AN ADDTOOL MESSAGE TO THE TOOLTIP CONTROL WINDOW */
1609 SendMessage(app.hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
1610 SendMessage(app.hwndTT, TTM_SETMAXTIPWIDTH, 0, 600);
1611 //SendMessage(app.hwndTT, TTM_SETDELAYTIME, TTDT_AUTOPOP, MAKELONG(50000, 0));
1612 //SendMessage(app.hwndTT, TTM_SETDELAYTIME, TTDT_RESHOW, MAKELONG(1000, 0));
1614 uFindReplaceMsg = RegisterWindowMessage(FINDMSGSTRING);
1616 return TRUE;
1618 #endif
1619 void CTortoiseGitBlameView::InitSize()
1621 RECT rc;
1622 RECT blamerc;
1623 RECT sourcerc;
1624 ::GetClientRect(wMain, &rc);
1625 ::SetWindowPos(wHeader, 0, rc.left, rc.top, rc.right-rc.left, HEADER_HEIGHT, 0);
1626 rc.top += HEADER_HEIGHT;
1627 blamerc.left = rc.left;
1628 blamerc.top = rc.top;
1629 LONG w = GetBlameWidth();
1630 blamerc.right = w > abs(rc.right - rc.left) ? rc.right : w + rc.left;
1631 blamerc.bottom = rc.bottom;
1632 sourcerc.left = blamerc.right;
1633 sourcerc.top = rc.top;
1634 sourcerc.bottom = rc.bottom;
1635 sourcerc.right = rc.right;
1636 if (m_colorage)
1638 ::OffsetRect(&blamerc, LOCATOR_WIDTH, 0);
1639 ::OffsetRect(&sourcerc, LOCATOR_WIDTH, 0);
1640 sourcerc.right -= LOCATOR_WIDTH;
1642 ::InvalidateRect(wMain, NULL, FALSE);
1643 ::SetWindowPos(m_wEditor, 0, sourcerc.left, sourcerc.top, sourcerc.right - sourcerc.left, sourcerc.bottom - sourcerc.top, 0);
1644 ::SetWindowPos(wBlame, 0, blamerc.left, blamerc.top, blamerc.right - blamerc.left, blamerc.bottom - blamerc.top, 0);
1645 if (m_colorage)
1646 ::SetWindowPos(wLocator, 0, 0, blamerc.top, LOCATOR_WIDTH, blamerc.bottom - blamerc.top, SWP_SHOWWINDOW);
1647 else
1648 ::ShowWindow(wLocator, SW_HIDE);
1651 #if 0
1652 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1654 if (message == uFindReplaceMsg)
1656 LPFINDREPLACE lpfr = (LPFINDREPLACE)lParam;
1658 // If the FR_DIALOGTERM flag is set,
1659 // invalidate the handle identifying the dialog box.
1660 if (lpfr->Flags & FR_DIALOGTERM)
1662 app.currentDialog = NULL;
1663 return 0;
1665 if (lpfr->Flags & FR_FINDNEXT)
1667 app.DoSearch(lpfr->lpstrFindWhat, lpfr->Flags);
1669 return 0;
1671 switch (message)
1673 case WM_CREATE:
1674 app.m_wEditor = ::CreateWindow(
1675 "Scintilla",
1676 "Source",
1677 WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_CLIPCHILDREN,
1678 0, 0,
1679 100, 100,
1680 hWnd,
1682 app.hResource,
1684 app.InitialiseEditor();
1685 ::ShowWindow(app.m_wEditor, SW_SHOW);
1686 ::SetFocus(app.m_wEditor);
1687 app.wBlame = ::CreateWindow(
1688 _T("TortoiseGitBlameViewBlame"),
1689 _T("blame"),
1690 WS_CHILD | WS_CLIPCHILDREN,
1691 CW_USEDEFAULT, 0,
1692 CW_USEDEFAULT, 0,
1693 hWnd,
1694 NULL,
1695 app.hResource,
1696 NULL);
1697 ::ShowWindow(app.wBlame, SW_SHOW);
1698 app.wHeader = ::CreateWindow(
1699 _T("TortoiseGitBlameViewHeader"),
1700 _T("header"),
1701 WS_CHILD | WS_CLIPCHILDREN | WS_BORDER,
1702 CW_USEDEFAULT, 0,
1703 CW_USEDEFAULT, 0,
1704 hWnd,
1705 NULL,
1706 app.hResource,
1707 NULL);
1708 ::ShowWindow(app.wHeader, SW_SHOW);
1709 app.wLocator = ::CreateWindow(
1710 _T("TortoiseGitBlameViewLocator"),
1711 _T("locator"),
1712 WS_CHILD | WS_CLIPCHILDREN | WS_BORDER,
1713 CW_USEDEFAULT, 0,
1714 CW_USEDEFAULT, 0,
1715 hWnd,
1716 NULL,
1717 app.hResource,
1718 NULL);
1719 ::ShowWindow(app.wLocator, SW_SHOW);
1720 return 0;
1722 case WM_SIZE:
1723 if (wParam != 1)
1725 app.InitSize();
1727 return 0;
1729 case WM_COMMAND:
1730 app.Command(LOWORD(wParam));
1731 break;
1732 case WM_NOTIFY:
1733 app.Notify(reinterpret_cast<SCNotification *>(lParam));
1734 return 0;
1735 case WM_DESTROY:
1736 PostQuitMessage(0);
1737 break;
1738 case WM_CLOSE:
1740 CRegStdWORD pos(_T("Software\\TortoiseGit\\TBlamePos"), 0);
1741 CRegStdWORD width(_T("Software\\TortoiseGit\\TBlameSize"), 0);
1742 CRegStdWORD state(_T("Software\\TortoiseGit\\TBlameState"), 0);
1743 RECT rc;
1744 GetWindowRect(app.wMain, &rc);
1745 if ((rc.left >= 0)&&(rc.top >= 0))
1747 pos = MAKELONG(rc.left, rc.top);
1748 width = MAKELONG(rc.right-rc.left, rc.bottom-rc.top);
1750 WINDOWPLACEMENT wp = {0};
1751 wp.length = sizeof(WINDOWPLACEMENT);
1752 GetWindowPlacement(app.wMain, &wp);
1753 state = wp.showCmd;
1754 ::DestroyWindow(app.m_wEditor);
1755 ::PostQuitMessage(0);
1757 return 0;
1758 case WM_SETFOCUS:
1759 ::SetFocus(app.wBlame);
1760 break;
1761 default:
1762 return DefWindowProc(hWnd, message, wParam, lParam);
1764 return 0;
1767 LRESULT CALLBACK WndBlameProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1769 PAINTSTRUCT ps;
1770 TRACKMOUSEEVENT mevt;
1771 HDC hDC;
1772 switch (message)
1774 case WM_CREATE:
1775 return 0;
1776 case WM_PAINT:
1777 hDC = BeginPaint(app.wBlame, &ps);
1778 app.DrawBlame(hDC);
1779 EndPaint(app.wBlame, &ps);
1780 break;
1781 case WM_COMMAND:
1782 app.Command(LOWORD(wParam));
1783 break;
1784 case WM_NOTIFY:
1785 switch (((LPNMHDR)lParam)->code)
1787 case TTN_GETDISPINFO:
1789 LPNMHDR pNMHDR = (LPNMHDR)lParam;
1790 NMTTDISPINFOA* pTTTA = (NMTTDISPINFOA*)pNMHDR;
1791 NMTTDISPINFOW* pTTTW = (NMTTDISPINFOW*)pNMHDR;
1792 POINT point;
1793 DWORD ptW = GetMessagePos();
1794 point.x = GET_X_LPARAM(ptW);
1795 point.y = GET_Y_LPARAM(ptW);
1796 ::ScreenToClient(app.wBlame, &point);
1797 LONG_PTR line = app.SendEditor(SCI_GETFIRSTVISIBLELINE);
1798 LONG_PTR height = app.SendEditor(SCI_TEXTHEIGHT);
1799 line = line + (point.y/height);
1800 if (line >= (LONG)app.revs.size())
1801 break;
1802 if (line < 0)
1803 break;
1804 LONG rev = app.revs[line];
1805 if (line >= (LONG)app.revs.size())
1806 break;
1808 SecureZeroMemory(app.m_szTip, sizeof(app.m_szTip));
1809 SecureZeroMemory(app.m_wszTip, sizeof(app.m_wszTip));
1810 std::map<LONG, CString>::iterator iter;
1811 if ((iter = app.logmessages.find(rev)) != app.logmessages.end())
1813 CString msg;
1814 if (!ShowAuthor)
1816 msg += app.authors[line];
1818 if (!ShowDate)
1820 if (!ShowAuthor) msg += " ";
1821 msg += app.dates[line];
1823 if (!ShowAuthor || !ShowDate)
1824 msg += '\n';
1825 msg += iter->second;
1826 // an empty tooltip string will deactivate the tooltips,
1827 // which means we must make sure that the tooltip won't
1828 // be empty.
1829 if (msg.empty())
1830 msg = _T(" ");
1831 if (pNMHDR->code == TTN_NEEDTEXTA)
1833 lstrcpyn(app.m_szTip, msg.c_str(), MAX_LOG_LENGTH*2);
1834 app.StringExpand(app.m_szTip);
1835 pTTTA->lpszText = app.m_szTip;
1837 else
1839 pTTTW->lpszText = app.m_wszTip;
1840 ::MultiByteToWideChar( CP_ACP , 0, msg.c_str(), min(msg.size(), MAX_LOG_LENGTH*2), app.m_wszTip, MAX_LOG_LENGTH*2);
1841 app.StringExpand(app.m_wszTip);
1845 break;
1847 return 0;
1848 case WM_DESTROY:
1849 break;
1850 case WM_CLOSE:
1851 return 0;
1852 case WM_MOUSELEAVE:
1853 app.m_mouserev = -2;
1854 app.m_mouseauthor.clear();
1855 app.ttVisible = FALSE;
1856 SendMessage(app.hwndTT, TTM_TRACKACTIVATE, FALSE, 0);
1857 ::InvalidateRect(app.wBlame, NULL, FALSE);
1858 break;
1859 case WM_MOUSEMOVE:
1861 mevt.cbSize = sizeof(TRACKMOUSEEVENT);
1862 mevt.dwFlags = TME_LEAVE;
1863 mevt.dwHoverTime = HOVER_DEFAULT;
1864 mevt.hwndTrack = app.wBlame;
1865 ::TrackMouseEvent(&mevt);
1866 POINT pt = {((int)(short)LOWORD(lParam)), ((int)(short)HIWORD(lParam))};
1867 ClientToScreen(app.wBlame, &pt);
1868 pt.x += 15;
1869 pt.y += 15;
1870 SendMessage(app.hwndTT, TTM_TRACKPOSITION, 0, MAKELONG(pt.x, pt.y));
1871 if (!app.ttVisible)
1873 TOOLINFO ti;
1874 ti.cbSize = sizeof(TOOLINFO);
1875 ti.hwnd = app.wBlame;
1876 ti.uId = 0;
1877 SendMessage(app.hwndTT, TTM_TRACKACTIVATE, TRUE, (LPARAM)&ti);
1879 int y = ((int)(short)HIWORD(lParam));
1880 LONG_PTR line = app.SendEditor(SCI_GETFIRSTVISIBLELINE);
1881 LONG_PTR height = app.SendEditor(SCI_TEXTHEIGHT);
1882 line = line + (y/height);
1883 app.ttVisible = (line < (LONG)app.revs.size());
1884 if ( app.ttVisible )
1886 if (app.authors[line].compare(app.m_mouseauthor) != 0)
1888 app.m_mouseauthor = app.authors[line];
1890 if (app.revs[line] != app.m_mouserev)
1892 app.m_mouserev = app.revs[line];
1893 ::InvalidateRect(app.wBlame, NULL, FALSE);
1894 SendMessage(app.hwndTT, TTM_UPDATE, 0, 0);
1898 break;
1899 case WM_RBUTTONDOWN:
1900 // fall through
1901 case WM_LBUTTONDOWN:
1903 break;
1904 case WM_SETFOCUS:
1905 ::SetFocus(app.wBlame);
1906 app.SendEditor(SCI_GRABFOCUS);
1907 break;
1908 case WM_CONTEXTMENU:
1910 if (app.m_selectedrev <= 0)
1911 break;;
1912 int xPos = GET_X_LPARAM(lParam);
1913 int yPos = GET_Y_LPARAM(lParam);
1914 if ((xPos < 0)||(yPos < 0))
1916 // requested from keyboard, not mouse pointer
1917 // use the center of the window
1918 RECT rect;
1919 GetClientRect(app.wBlame, &rect);
1920 xPos = rect.right-rect.left;
1921 yPos = rect.bottom-rect.top;
1923 HMENU hMenu = LoadMenu(app.hResource, MAKEINTRESOURCE(IDR_BLAMEPOPUP));
1924 HMENU hPopMenu = GetSubMenu(hMenu, 0);
1926 if ( _tcslen(szOrigPath)==0 )
1928 // Without knowing the original path we cannot blame the previous revision
1929 // because we don't know which filename to pass to tortoiseproc.
1930 EnableMenuItem(hPopMenu,ID_BLAME_PREVIOUS_REVISION, MF_DISABLED|MF_GRAYED);
1933 TrackPopupMenu(hPopMenu, TPM_LEFTALIGN | TPM_RIGHTBUTTON, xPos, yPos, 0, app.wBlame, NULL);
1934 DestroyMenu(hMenu);
1936 break;
1937 default:
1938 return DefWindowProc(hWnd, message, wParam, lParam);
1940 return 0;
1943 LRESULT CALLBACK WndHeaderProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1945 PAINTSTRUCT ps;
1946 HDC hDC;
1947 switch (message)
1949 case WM_CREATE:
1950 return 0;
1951 case WM_PAINT:
1952 hDC = BeginPaint(app.wHeader, &ps);
1953 app.DrawHeader(hDC);
1954 EndPaint(app.wHeader, &ps);
1955 break;
1956 case WM_COMMAND:
1957 break;
1958 case WM_DESTROY:
1959 break;
1960 case WM_CLOSE:
1961 return 0;
1962 default:
1963 return DefWindowProc(hWnd, message, wParam, lParam);
1965 return 0;
1968 LRESULT CALLBACK WndLocatorProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1970 PAINTSTRUCT ps;
1971 HDC hDC;
1972 switch (message)
1974 case WM_PAINT:
1975 hDC = BeginPaint(app.wLocator, &ps);
1976 app.DrawLocatorBar(hDC);
1977 EndPaint(app.wLocator, &ps);
1978 break;
1979 case WM_LBUTTONDOWN:
1980 case WM_MOUSEMOVE:
1981 if (wParam & MK_LBUTTON)
1983 RECT rect;
1984 ::GetClientRect(hWnd, &rect);
1985 int nLine = HIWORD(lParam)*app.revs.size()/(rect.bottom-rect.top);
1987 if (nLine < 0)
1988 nLine = 0;
1989 app.ScrollToLine(nLine);
1991 break;
1992 default:
1993 return DefWindowProc(hWnd, message, wParam, lParam);
1995 return 0;
1997 #endif
1999 void CTortoiseGitBlameView::SetupLexer(CString filename)
2002 TCHAR *line;
2003 //const char * lineptr = _tcsrchr(filename, '.');
2004 int start=filename.ReverseFind(_T('.'));
2005 if (start>0)
2007 //_tcscpy_s(line, 20, lineptr+1);
2008 //_tcslwr_s(line, 20);
2009 CString ext=filename.Right(filename.GetLength()-start-1);
2010 line=ext.GetBuffer();
2012 if ((_tcscmp(line, _T("py"))==0)||
2013 (_tcscmp(line, _T("pyw"))==0)||
2014 (_tcscmp(line, _T("pyw"))==0))
2016 SendEditor(SCI_SETLEXER, SCLEX_PYTHON);
2017 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("and assert break class continue def del elif \
2018 else except exec finally for from global if import in is lambda None \
2019 not or pass print raise return try while yield")).GetBuffer()));
2020 SetAStyle(SCE_P_DEFAULT, black);
2021 SetAStyle(SCE_P_COMMENTLINE, darkGreen);
2022 SetAStyle(SCE_P_NUMBER, RGB(0, 0x80, 0x80));
2023 SetAStyle(SCE_P_STRING, RGB(0, 0, 0x80));
2024 SetAStyle(SCE_P_CHARACTER, RGB(0, 0, 0x80));
2025 SetAStyle(SCE_P_WORD, RGB(0x80, 0, 0x80));
2026 SetAStyle(SCE_P_TRIPLE, black);
2027 SetAStyle(SCE_P_TRIPLEDOUBLE, black);
2028 SetAStyle(SCE_P_CLASSNAME, darkBlue);
2029 SetAStyle(SCE_P_DEFNAME, darkBlue);
2030 SetAStyle(SCE_P_OPERATOR, darkBlue);
2031 SetAStyle(SCE_P_IDENTIFIER, darkBlue);
2032 SetAStyle(SCE_P_COMMENTBLOCK, darkGreen);
2033 SetAStyle(SCE_P_STRINGEOL, red);
2035 if ((_tcscmp(line, _T("c"))==0)||
2036 (_tcscmp(line, _T("cc"))==0)||
2037 (_tcscmp(line, _T("cpp"))==0)||
2038 (_tcscmp(line, _T("cxx"))==0)||
2039 (_tcscmp(line, _T("h"))==0)||
2040 (_tcscmp(line, _T("hh"))==0)||
2041 (_tcscmp(line, _T("hpp"))==0)||
2042 (_tcscmp(line, _T("hxx"))==0)||
2043 (_tcscmp(line, _T("dlg"))==0)||
2044 (_tcscmp(line, _T("mak"))==0))
2046 SendEditor(SCI_SETLEXER, SCLEX_CPP);
2047 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("and and_eq asm auto bitand bitor bool break \
2048 case catch char class compl const const_cast continue \
2049 default delete do double dynamic_cast else enum explicit export extern false float for \
2050 friend goto if inline int long mutable namespace new not not_eq \
2051 operator or or_eq private protected public \
2052 register reinterpret_cast return short signed sizeof static static_cast struct switch \
2053 template this throw true try typedef typeid typename union unsigned using \
2054 virtual void volatile wchar_t while xor xor_eq")).GetBuffer()));
2055 SendEditor(SCI_SETKEYWORDS, 3, (LPARAM)(m_TextView.StringForControl(_T("a addindex addtogroup anchor arg attention \
2056 author b brief bug c class code date def defgroup deprecated dontinclude \
2057 e em endcode endhtmlonly endif endlatexonly endlink endverbatim enum example exception \
2058 f$ f[ f] file fn hideinitializer htmlinclude htmlonly \
2059 if image include ingroup internal invariant interface latexonly li line link \
2060 mainpage name namespace nosubgrouping note overload \
2061 p page par param post pre ref relates remarks return retval \
2062 sa section see showinitializer since skip skipline struct subsection \
2063 test throw todo typedef union until \
2064 var verbatim verbinclude version warning weakgroup $ @ \\ & < > # { }")).GetBuffer()));
2065 SetupCppLexer();
2067 if (_tcscmp(line, _T("cs"))==0)
2069 SendEditor(SCI_SETLEXER, SCLEX_CPP);
2070 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("abstract as base bool break byte case catch char checked class \
2071 const continue decimal default delegate do double else enum \
2072 event explicit extern false finally fixed float for foreach goto if \
2073 implicit in int interface internal is lock long namespace new null \
2074 object operator out override params private protected public \
2075 readonly ref return sbyte sealed short sizeof stackalloc static \
2076 string struct switch this throw true try typeof uint ulong \
2077 unchecked unsafe ushort using virtual void while")).GetBuffer()));
2078 SetupCppLexer();
2080 if ((_tcscmp(line, _T("rc"))==0)||
2081 (_tcscmp(line, _T("rc2"))==0))
2083 SendEditor(SCI_SETLEXER, SCLEX_CPP);
2084 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("ACCELERATORS ALT AUTO3STATE AUTOCHECKBOX AUTORADIOBUTTON \
2085 BEGIN BITMAP BLOCK BUTTON CAPTION CHARACTERISTICS CHECKBOX CLASS \
2086 COMBOBOX CONTROL CTEXT CURSOR DEFPUSHBUTTON DIALOG DIALOGEX DISCARDABLE \
2087 EDITTEXT END EXSTYLE FONT GROUPBOX ICON LANGUAGE LISTBOX LTEXT \
2088 MENU MENUEX MENUITEM MESSAGETABLE POPUP \
2089 PUSHBUTTON RADIOBUTTON RCDATA RTEXT SCROLLBAR SEPARATOR SHIFT STATE3 \
2090 STRINGTABLE STYLE TEXTINCLUDE VALUE VERSION VERSIONINFO VIRTKEY")).GetBuffer()));
2091 SetupCppLexer();
2093 if ((_tcscmp(line, _T("idl"))==0)||
2094 (_tcscmp(line, _T("odl"))==0))
2096 SendEditor(SCI_SETLEXER, SCLEX_CPP);
2097 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("aggregatable allocate appobject arrays async async_uuid \
2098 auto_handle \
2099 bindable boolean broadcast byte byte_count \
2100 call_as callback char coclass code comm_status \
2101 const context_handle context_handle_noserialize \
2102 context_handle_serialize control cpp_quote custom \
2103 decode default defaultbind defaultcollelem \
2104 defaultvalue defaultvtable dispinterface displaybind dllname \
2105 double dual \
2106 enable_allocate encode endpoint entry enum error_status_t \
2107 explicit_handle \
2108 fault_status first_is float \
2109 handle_t heap helpcontext helpfile helpstring \
2110 helpstringcontext helpstringdll hidden hyper \
2111 id idempotent ignore iid_as iid_is immediatebind implicit_handle \
2112 import importlib in include in_line int __int64 __int3264 interface \
2113 last_is lcid length_is library licensed local long \
2114 max_is maybe message methods midl_pragma \
2115 midl_user_allocate midl_user_free min_is module ms_union \
2116 ncacn_at_dsp ncacn_dnet_nsp ncacn_http ncacn_ip_tcp \
2117 ncacn_nb_ipx ncacn_nb_nb ncacn_nb_tcp ncacn_np \
2118 ncacn_spx ncacn_vns_spp ncadg_ip_udp ncadg_ipx ncadg_mq \
2119 ncalrpc nocode nonbrowsable noncreatable nonextensible notify \
2120 object odl oleautomation optimize optional out out_of_line \
2121 pipe pointer_default pragma properties propget propput propputref \
2122 ptr public \
2123 range readonly ref represent_as requestedit restricted retval \
2124 shape short signed size_is small source strict_context_handle \
2125 string struct switch switch_is switch_type \
2126 transmit_as typedef \
2127 uidefault union unique unsigned user_marshal usesgetlasterror uuid \
2128 v1_enum vararg version void wchar_t wire_marshal")).GetBuffer()));
2129 SetupCppLexer();
2131 if (_tcscmp(line, _T("java"))==0)
2133 SendEditor(SCI_SETLEXER, SCLEX_CPP);
2134 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("abstract assert boolean break byte case catch char class \
2135 const continue default do double else extends final finally float for future \
2136 generic goto if implements import inner instanceof int interface long \
2137 native new null outer package private protected public rest \
2138 return short static super switch synchronized this throw throws \
2139 transient try var void volatile while")).GetBuffer()));
2140 SetupCppLexer();
2142 if (_tcscmp(line, _T("js"))==0)
2144 SendEditor(SCI_SETLEXER, SCLEX_CPP);
2145 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("abstract boolean break byte case catch char class \
2146 const continue debugger default delete do double else enum export extends \
2147 final finally float for function goto if implements import in instanceof \
2148 int interface long native new package private protected public \
2149 return short static super switch synchronized this throw throws \
2150 transient try typeof var void volatile while with")).GetBuffer()));
2151 SetupCppLexer();
2153 if ((_tcscmp(line, _T("pas"))==0)||
2154 (_tcscmp(line, _T("dpr"))==0)||
2155 (_tcscmp(line, _T("pp"))==0))
2157 SendEditor(SCI_SETLEXER, SCLEX_PASCAL);
2158 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("and array as begin case class const constructor \
2159 destructor div do downto else end except file finally \
2160 for function goto if implementation in inherited \
2161 interface is mod not object of on or packed \
2162 procedure program property raise record repeat \
2163 set shl shr then threadvar to try type unit \
2164 until uses var while with xor")).GetBuffer()));
2165 SetupCppLexer();
2167 if ((_tcscmp(line, _T("as"))==0)||
2168 (_tcscmp(line, _T("asc"))==0)||
2169 (_tcscmp(line, _T("jsfl"))==0))
2171 SendEditor(SCI_SETLEXER, SCLEX_CPP);
2172 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("add and break case catch class continue default delete do \
2173 dynamic else eq extends false finally for function ge get gt if implements import in \
2174 instanceof interface intrinsic le lt ne new not null or private public return \
2175 set static super switch this throw true try typeof undefined var void while with")).GetBuffer()));
2176 SendEditor(SCI_SETKEYWORDS, 1, (LPARAM)(m_TextView.StringForControl(_T("Array Arguments Accessibility Boolean Button Camera Color \
2177 ContextMenu ContextMenuItem Date Error Function Key LoadVars LocalConnection Math \
2178 Microphone Mouse MovieClip MovieClipLoader NetConnection NetStream Number Object \
2179 PrintJob Selection SharedObject Sound Stage String StyleSheet System TextField \
2180 TextFormat TextSnapshot Video Void XML XMLNode XMLSocket \
2181 _accProps _focusrect _global _highquality _parent _quality _root _soundbuftime \
2182 arguments asfunction call capabilities chr clearInterval duplicateMovieClip \
2183 escape eval fscommand getProperty getTimer getURL getVersion gotoAndPlay gotoAndStop \
2184 ifFrameLoaded Infinity -Infinity int isFinite isNaN length loadMovie loadMovieNum \
2185 loadVariables loadVariablesNum maxscroll mbchr mblength mbord mbsubstring MMExecute \
2186 NaN newline nextFrame nextScene on onClipEvent onUpdate ord parseFloat parseInt play \
2187 prevFrame prevScene print printAsBitmap printAsBitmapNum printNum random removeMovieClip \
2188 scroll set setInterval setProperty startDrag stop stopAllSounds stopDrag substring \
2189 targetPath tellTarget toggleHighQuality trace unescape unloadMovie unLoadMovieNum updateAfterEvent")).GetBuffer()));
2190 SetupCppLexer();
2192 if ((_tcscmp(line, _T("html"))==0)||
2193 (_tcscmp(line, _T("htm"))==0)||
2194 (_tcscmp(line, _T("shtml"))==0)||
2195 (_tcscmp(line, _T("htt"))==0)||
2196 (_tcscmp(line, _T("xml"))==0)||
2197 (_tcscmp(line, _T("asp"))==0)||
2198 (_tcscmp(line, _T("xsl"))==0)||
2199 (_tcscmp(line, _T("php"))==0)||
2200 (_tcscmp(line, _T("xhtml"))==0)||
2201 (_tcscmp(line, _T("phtml"))==0)||
2202 (_tcscmp(line, _T("cfm"))==0)||
2203 (_tcscmp(line, _T("tpl"))==0)||
2204 (_tcscmp(line, _T("dtd"))==0)||
2205 (_tcscmp(line, _T("hta"))==0)||
2206 (_tcscmp(line, _T("htd"))==0)||
2207 (_tcscmp(line, _T("wxs"))==0))
2209 SendEditor(SCI_SETLEXER, SCLEX_HTML);
2210 SendEditor(SCI_SETSTYLEBITS, 7);
2211 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("a abbr acronym address applet area b base basefont \
2212 bdo big blockquote body br button caption center \
2213 cite code col colgroup dd del dfn dir div dl dt em \
2214 fieldset font form frame frameset h1 h2 h3 h4 h5 h6 \
2215 head hr html i iframe img input ins isindex kbd label \
2216 legend li link map menu meta noframes noscript \
2217 object ol optgroup option p param pre q s samp \
2218 script select small span strike strong style sub sup \
2219 table tbody td textarea tfoot th thead title tr tt u ul \
2220 var xml xmlns abbr accept-charset accept accesskey action align alink \
2221 alt archive axis background bgcolor border \
2222 cellpadding cellspacing char charoff charset checked cite \
2223 class classid clear codebase codetype color cols colspan \
2224 compact content coords \
2225 data datafld dataformatas datapagesize datasrc datetime \
2226 declare defer dir disabled enctype event \
2227 face for frame frameborder \
2228 headers height href hreflang hspace http-equiv \
2229 id ismap label lang language leftmargin link longdesc \
2230 marginwidth marginheight maxlength media method multiple \
2231 name nohref noresize noshade nowrap \
2232 object onblur onchange onclick ondblclick onfocus \
2233 onkeydown onkeypress onkeyup onload onmousedown \
2234 onmousemove onmouseover onmouseout onmouseup \
2235 onreset onselect onsubmit onunload \
2236 profile prompt readonly rel rev rows rowspan rules \
2237 scheme scope selected shape size span src standby start style \
2238 summary tabindex target text title topmargin type usemap \
2239 valign value valuetype version vlink vspace width \
2240 text password checkbox radio submit reset \
2241 file hidden image")).GetBuffer()));
2242 SendEditor(SCI_SETKEYWORDS, 1, (LPARAM)(m_TextView.StringForControl(_T("assign audio block break catch choice clear disconnect else elseif \
2243 emphasis enumerate error exit field filled form goto grammar help \
2244 if initial link log menu meta noinput nomatch object option p paragraph \
2245 param phoneme prompt property prosody record reprompt return s say-as \
2246 script sentence subdialog submit throw transfer value var voice vxml")).GetBuffer()));
2247 SendEditor(SCI_SETKEYWORDS, 2, (LPARAM)(m_TextView.StringForControl(_T("accept age alphabet anchor application base beep bridge category charset \
2248 classid cond connecttimeout content contour count dest destexpr dtmf dtmfterm \
2249 duration enctype event eventexpr expr expritem fetchtimeout finalsilence \
2250 gender http-equiv id level maxage maxstale maxtime message messageexpr \
2251 method mime modal mode name namelist next nextitem ph pitch range rate \
2252 scope size sizeexpr skiplist slot src srcexpr sub time timeexpr timeout \
2253 transferaudio type value variant version volume xml:lang")).GetBuffer()));
2254 SendEditor(SCI_SETKEYWORDS, 3, (LPARAM)(m_TextView.StringForControl(_T("and assert break class continue def del elif \
2255 else except exec finally for from global if import in is lambda None \
2256 not or pass print raise return try while yield")).GetBuffer()));
2257 SendEditor(SCI_SETKEYWORDS, 4, (LPARAM)(m_TextView.StringForControl(_T("and argv as argc break case cfunction class continue declare default do \
2258 die echo else elseif empty enddeclare endfor endforeach endif endswitch \
2259 endwhile e_all e_parse e_error e_warning eval exit extends false for \
2260 foreach function global http_cookie_vars http_get_vars http_post_vars \
2261 http_post_files http_env_vars http_server_vars if include include_once \
2262 list new not null old_function or parent php_os php_self php_version \
2263 print require require_once return static switch stdclass this true var \
2264 xor virtual while __file__ __line__ __sleep __wakeup")).GetBuffer()));
2266 SetAStyle(SCE_H_TAG, darkBlue);
2267 SetAStyle(SCE_H_TAGUNKNOWN, red);
2268 SetAStyle(SCE_H_ATTRIBUTE, darkBlue);
2269 SetAStyle(SCE_H_ATTRIBUTEUNKNOWN, red);
2270 SetAStyle(SCE_H_NUMBER, RGB(0x80,0,0x80));
2271 SetAStyle(SCE_H_DOUBLESTRING, RGB(0,0x80,0));
2272 SetAStyle(SCE_H_SINGLESTRING, RGB(0,0x80,0));
2273 SetAStyle(SCE_H_OTHER, RGB(0x80,0,0x80));
2274 SetAStyle(SCE_H_COMMENT, RGB(0x80,0x80,0));
2275 SetAStyle(SCE_H_ENTITY, RGB(0x80,0,0x80));
2277 SetAStyle(SCE_H_TAGEND, darkBlue);
2278 SetAStyle(SCE_H_XMLSTART, darkBlue); // <?
2279 SetAStyle(SCE_H_QUESTION, darkBlue); // <?
2280 SetAStyle(SCE_H_XMLEND, darkBlue); // ?>
2281 SetAStyle(SCE_H_SCRIPT, darkBlue); // <script
2282 SetAStyle(SCE_H_ASP, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <% ... %>
2283 SetAStyle(SCE_H_ASPAT, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <%@ ... %>
2285 SetAStyle(SCE_HB_DEFAULT, black);
2286 SetAStyle(SCE_HB_COMMENTLINE, darkGreen);
2287 SetAStyle(SCE_HB_NUMBER, RGB(0,0x80,0x80));
2288 SetAStyle(SCE_HB_WORD, darkBlue);
2289 SendEditor(SCI_STYLESETBOLD, SCE_HB_WORD, 1);
2290 SetAStyle(SCE_HB_STRING, RGB(0x80,0,0x80));
2291 SetAStyle(SCE_HB_IDENTIFIER, black);
2293 // This light blue is found in the windows system palette so is safe to use even in 256 colour modes.
2294 // Show the whole section of VBScript with light blue background
2295 for (int bstyle=SCE_HB_DEFAULT; bstyle<=SCE_HB_STRINGEOL; bstyle++) {
2296 SendEditor(SCI_STYLESETFONT, bstyle,
2297 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
2298 SendEditor(SCI_STYLESETBACK, bstyle, lightBlue);
2299 // This call extends the backround colour of the last style on the line to the edge of the window
2300 SendEditor(SCI_STYLESETEOLFILLED, bstyle, 1);
2302 SendEditor(SCI_STYLESETBACK, SCE_HB_STRINGEOL, RGB(0x7F,0x7F,0xFF));
2303 SendEditor(SCI_STYLESETFONT, SCE_HB_COMMENTLINE,
2304 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
2306 SetAStyle(SCE_HBA_DEFAULT, black);
2307 SetAStyle(SCE_HBA_COMMENTLINE, darkGreen);
2308 SetAStyle(SCE_HBA_NUMBER, RGB(0,0x80,0x80));
2309 SetAStyle(SCE_HBA_WORD, darkBlue);
2310 SendEditor(SCI_STYLESETBOLD, SCE_HBA_WORD, 1);
2311 SetAStyle(SCE_HBA_STRING, RGB(0x80,0,0x80));
2312 SetAStyle(SCE_HBA_IDENTIFIER, black);
2314 // Show the whole section of ASP VBScript with bright yellow background
2315 for (int bastyle=SCE_HBA_DEFAULT; bastyle<=SCE_HBA_STRINGEOL; bastyle++) {
2316 SendEditor(SCI_STYLESETFONT, bastyle,
2317 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
2318 SendEditor(SCI_STYLESETBACK, bastyle, RGB(0xFF, 0xFF, 0));
2319 // This call extends the backround colour of the last style on the line to the edge of the window
2320 SendEditor(SCI_STYLESETEOLFILLED, bastyle, 1);
2322 SendEditor(SCI_STYLESETBACK, SCE_HBA_STRINGEOL, RGB(0xCF,0xCF,0x7F));
2323 SendEditor(SCI_STYLESETFONT, SCE_HBA_COMMENTLINE,
2324 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
2326 // If there is no need to support embedded Javascript, the following code can be dropped.
2327 // Javascript will still be correctly processed but will be displayed in just the default style.
2329 SetAStyle(SCE_HJ_START, RGB(0x80,0x80,0));
2330 SetAStyle(SCE_HJ_DEFAULT, black);
2331 SetAStyle(SCE_HJ_COMMENT, darkGreen);
2332 SetAStyle(SCE_HJ_COMMENTLINE, darkGreen);
2333 SetAStyle(SCE_HJ_COMMENTDOC, darkGreen);
2334 SetAStyle(SCE_HJ_NUMBER, RGB(0,0x80,0x80));
2335 SetAStyle(SCE_HJ_WORD, black);
2336 SetAStyle(SCE_HJ_KEYWORD, darkBlue);
2337 SetAStyle(SCE_HJ_DOUBLESTRING, RGB(0x80,0,0x80));
2338 SetAStyle(SCE_HJ_SINGLESTRING, RGB(0x80,0,0x80));
2339 SetAStyle(SCE_HJ_SYMBOLS, black);
2341 SetAStyle(SCE_HJA_START, RGB(0x80,0x80,0));
2342 SetAStyle(SCE_HJA_DEFAULT, black);
2343 SetAStyle(SCE_HJA_COMMENT, darkGreen);
2344 SetAStyle(SCE_HJA_COMMENTLINE, darkGreen);
2345 SetAStyle(SCE_HJA_COMMENTDOC, darkGreen);
2346 SetAStyle(SCE_HJA_NUMBER, RGB(0,0x80,0x80));
2347 SetAStyle(SCE_HJA_WORD, black);
2348 SetAStyle(SCE_HJA_KEYWORD, darkBlue);
2349 SetAStyle(SCE_HJA_DOUBLESTRING, RGB(0x80,0,0x80));
2350 SetAStyle(SCE_HJA_SINGLESTRING, RGB(0x80,0,0x80));
2351 SetAStyle(SCE_HJA_SYMBOLS, black);
2353 SetAStyle(SCE_HPHP_DEFAULT, black);
2354 SetAStyle(SCE_HPHP_HSTRING, RGB(0x80,0,0x80));
2355 SetAStyle(SCE_HPHP_SIMPLESTRING, RGB(0x80,0,0x80));
2356 SetAStyle(SCE_HPHP_WORD, darkBlue);
2357 SetAStyle(SCE_HPHP_NUMBER, RGB(0,0x80,0x80));
2358 SetAStyle(SCE_HPHP_VARIABLE, red);
2359 SetAStyle(SCE_HPHP_HSTRING_VARIABLE, red);
2360 SetAStyle(SCE_HPHP_COMPLEX_VARIABLE, red);
2361 SetAStyle(SCE_HPHP_COMMENT, darkGreen);
2362 SetAStyle(SCE_HPHP_COMMENTLINE, darkGreen);
2363 SetAStyle(SCE_HPHP_OPERATOR, darkBlue);
2365 // Show the whole section of Javascript with off white background
2366 for (int jstyle=SCE_HJ_DEFAULT; jstyle<=SCE_HJ_SYMBOLS; jstyle++) {
2367 SendEditor(SCI_STYLESETFONT, jstyle,
2368 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
2369 SendEditor(SCI_STYLESETBACK, jstyle, offWhite);
2370 SendEditor(SCI_STYLESETEOLFILLED, jstyle, 1);
2372 SendEditor(SCI_STYLESETBACK, SCE_HJ_STRINGEOL, RGB(0xDF, 0xDF, 0x7F));
2373 SendEditor(SCI_STYLESETEOLFILLED, SCE_HJ_STRINGEOL, 1);
2375 // Show the whole section of Javascript with brown background
2376 for (int jastyle=SCE_HJA_DEFAULT; jastyle<=SCE_HJA_SYMBOLS; jastyle++) {
2377 SendEditor(SCI_STYLESETFONT, jastyle,
2378 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
2379 SendEditor(SCI_STYLESETBACK, jastyle, RGB(0xDF, 0xDF, 0x7F));
2380 SendEditor(SCI_STYLESETEOLFILLED, jastyle, 1);
2382 SendEditor(SCI_STYLESETBACK, SCE_HJA_STRINGEOL, RGB(0x0,0xAF,0x5F));
2383 SendEditor(SCI_STYLESETEOLFILLED, SCE_HJA_STRINGEOL, 1);
2386 else
2388 SendEditor(SCI_SETLEXER, SCLEX_CPP);
2389 SetupCppLexer();
2391 SendEditor(SCI_COLOURISE, 0, -1);
2395 void CTortoiseGitBlameView::SetupCppLexer()
2397 SetAStyle(SCE_C_DEFAULT, RGB(0, 0, 0));
2398 SetAStyle(SCE_C_COMMENT, RGB(0, 0x80, 0));
2399 SetAStyle(SCE_C_COMMENTLINE, RGB(0, 0x80, 0));
2400 SetAStyle(SCE_C_COMMENTDOC, RGB(0, 0x80, 0));
2401 SetAStyle(SCE_C_COMMENTLINEDOC, RGB(0, 0x80, 0));
2402 SetAStyle(SCE_C_COMMENTDOCKEYWORD, RGB(0, 0x80, 0));
2403 SetAStyle(SCE_C_COMMENTDOCKEYWORDERROR, RGB(0, 0x80, 0));
2404 SetAStyle(SCE_C_NUMBER, RGB(0, 0x80, 0x80));
2405 SetAStyle(SCE_C_WORD, RGB(0, 0, 0x80));
2406 SendEditor(SCE_C_WORD, 1);
2407 SetAStyle(SCE_C_STRING, RGB(0x80, 0, 0x80));
2408 SetAStyle(SCE_C_IDENTIFIER, RGB(0, 0, 0));
2409 SetAStyle(SCE_C_PREPROCESSOR, RGB(0x80, 0, 0));
2410 SetAStyle(SCE_C_OPERATOR, RGB(0x80, 0x80, 0));
2414 void CTortoiseGitBlameView::UpdateInfo()
2416 CString &data = GetDocument()->m_BlameData;
2417 CString one;
2418 int pos=0;
2420 BYTE_VECTOR vector;
2422 CLogDataVector * pRevs= GetLogData();
2424 this->m_CommitHash.clear();
2425 this->m_Authors.clear();
2426 this->m_ID.clear();
2427 CString line;
2429 CreateFont();
2431 SendEditor(SCI_SETREADONLY, FALSE);
2432 SendEditor(SCI_CLEARALL);
2433 SendEditor(EM_EMPTYUNDOBUFFER);
2434 SendEditor(SCI_SETSAVEPOINT);
2435 SendEditor(SCI_CANCEL);
2436 SendEditor(SCI_SETUNDOCOLLECTION, 0);
2438 while( pos>=0 )
2440 one=data.Tokenize(_T("\n"),pos);
2442 if(one.GetLength()>1 && one[0] == _T('^'))
2443 one=one.Mid(1);
2445 if(one.IsEmpty())
2446 continue;
2447 m_CommitHash.push_back(one.Left(40));
2448 int start=0;
2449 start=one.Find(_T(')'),40);
2450 if(start>0)
2452 line=one.Right(one.GetLength()-start-2);
2453 this->m_TextView.InsertText(line,true);
2455 int id;
2456 if(pRevs->m_HashMap.find(one.Left(40))!=pRevs->m_HashMap.end())
2458 id=pRevs->m_HashMap[one.Left(40)];
2460 else
2462 id=-1;
2463 if(this->m_NoListCommit.find(one.Left(40)) == m_NoListCommit.end() )
2465 g_Git.GetLog(vector,one.Left(40),NULL,1);
2466 this->m_NoListCommit[one.Left(40)].ParserFromLog(vector);
2471 if(id>=0 && id <(int)GetLogData()->size())
2473 m_ID.push_back(pRevs->size()-id);
2474 m_Authors.push_back(pRevs->at(id).m_AuthorName);
2475 }else
2477 m_ID.push_back(id);
2478 m_Authors.push_back(one.Left(6));
2482 SetupLexer(GetDocument()->m_CurrentFileName);
2484 SendEditor(SCI_SETUNDOCOLLECTION, 1);
2485 SendEditor(EM_EMPTYUNDOBUFFER);
2486 SendEditor(SCI_SETSAVEPOINT);
2487 SendEditor(SCI_GOTOPOS, 0);
2488 SendEditor(SCI_SETSCROLLWIDTHTRACKING, TRUE);
2489 SendEditor(SCI_SETREADONLY, TRUE);
2491 m_lowestrev=0;
2492 m_highestrev=this->GetLogData()->size()+m_NoListCommit.size();
2494 GetBlameWidth();
2495 CRect rect;
2496 this->GetClientRect(rect);
2497 //this->m_TextView.GetWindowRect(rect);
2498 //this->m_TextView.ScreenToClient(rect);
2499 rect.left=this->m_blamewidth;
2500 this->m_TextView.MoveWindow(rect);
2502 this->Invalidate();
2505 CGitBlameLogList * CTortoiseGitBlameView::GetLogList()
2507 return &(GetDocument()->GetMainFrame()->m_wndOutput.m_LogList);
2511 CLogDataVector * CTortoiseGitBlameView::GetLogData()
2513 return &(GetDocument()->GetMainFrame()->m_wndOutput.m_LogList.m_logEntries);
2516 void CTortoiseGitBlameView::OnSciPainted(NMHDR *,LRESULT *)
2518 this->Invalidate();
2521 void CTortoiseGitBlameView::OnLButtonDown(UINT nFlags,CPoint point)
2524 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
2525 LONG_PTR height = SendEditor(SCI_TEXTHEIGHT);
2526 line = line + (point.y/height);
2528 if (line < (LONG)m_CommitHash.size())
2530 SetSelectedLine(line);
2531 if (m_CommitHash[line] != m_SelectedHash)
2533 m_SelectedHash = m_CommitHash[line];
2535 if(m_ID[line]>=0)
2537 this->GetLogList()->SetItemState(this->GetLogList()->GetItemCount()-m_ID[line],
2538 LVIS_SELECTED,
2539 LVIS_SELECTED);
2541 GitRev *pRev;
2542 pRev=&this->GetLogData()->at(this->GetLogList()->GetItemCount()-m_ID[line]);
2543 this->GetDocument()->GetMainFrame()->m_wndProperties.UpdateProperties(pRev);
2544 }else
2546 this->GetDocument()->GetMainFrame()->m_wndProperties.UpdateProperties(&m_NoListCommit[m_CommitHash[line]]);
2549 else
2551 m_SelectedHash.Empty();
2553 //::InvalidateRect( NULL, FALSE);
2554 this->Invalidate();
2555 this->m_TextView.Invalidate();
2558 else
2560 SetSelectedLine(-1);
2563 CView::OnLButtonDown(nFlags,point);
2566 void CTortoiseGitBlameView::OnSciGetBkColor(NMHDR* hdr, LRESULT* result)
2569 SCNotification *notification=reinterpret_cast<SCNotification *>(hdr);
2571 if ((m_colorage)&&(notification->line < (int)m_CommitHash.size()))
2573 if(m_CommitHash[notification->line] == this->m_SelectedHash )
2574 notification->lParam = m_selectedauthorcolor;
2575 else
2576 notification->lParam = InterColor(DWORD(m_regOldLinesColor), DWORD(m_regNewLinesColor), (m_ID[notification->line]-m_lowestrev)*100/((m_highestrev-m_lowestrev)+1));
2581 void CTortoiseGitBlameView::FocusOn(GitRev *pRev)
2583 m_SelectedHash = pRev->m_CommitHash;
2585 //GitRev *pRev;
2586 //pRev=&this->GetLogData()->at(this->GetLogList()->GetItemCount()-m_ID[line]);
2587 this->GetDocument()->GetMainFrame()->m_wndProperties.UpdateProperties(pRev);
2589 this->Invalidate();
2591 int i;
2592 for(i=0;i<m_CommitHash.size();i++)
2594 if( pRev->m_CommitHash == m_CommitHash[i] )
2595 break;
2597 this->GotoLine(i);
2598 this->m_TextView.Invalidate();
2602 void CTortoiseGitBlameView::OnMouseHover(UINT nFlags, CPoint point)
2605 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
2606 LONG_PTR height = SendEditor(SCI_TEXTHEIGHT);
2607 line = line + (point.y/height);
2609 if (line < (LONG)m_CommitHash.size())
2611 if (line != m_MouseLine)
2613 m_MouseLine = line;//m_CommitHash[line];
2614 GitRev *pRev;
2615 if(m_ID[line]<0)
2617 pRev=&this->m_NoListCommit[m_CommitHash[line]];
2619 }else
2621 pRev=&this->GetLogData()->at(this->GetLogList()->GetItemCount()-m_ID[line]);
2624 this->ClientToScreen(&point);
2626 CString str;
2627 str.Format(_T("%s\n<b>%s</b>\n%s %s\n%s"),pRev->m_CommitHash,
2628 pRev->m_Subject,
2629 pRev->m_AuthorName,
2630 CAppUtils::FormatDateAndTime( pRev->m_AuthorDate, m_DateFormat ),
2631 pRev->m_Body);
2632 m_ToolTip.AddTool(this,str);
2633 m_ToolTip.DisplayToolTip(&point);
2635 CRect rect;
2636 this->ScreenToClient(&point);
2637 rect.left=LOCATOR_WIDTH;
2638 rect.right=this->m_blamewidth+rect.left;
2639 rect.top=point.y-height;
2640 rect.bottom=point.y+height;
2641 this->InvalidateRect(rect);
2644 else
2646 m_MouseLine=-1;
2651 void CTortoiseGitBlameView::OnMouseMove(UINT nFlags, CPoint point)
2653 TRACKMOUSEEVENT tme;
2654 tme.cbSize=sizeof(TRACKMOUSEEVENT);
2655 tme.dwFlags=TME_HOVER|TME_LEAVE;
2656 tme.hwndTrack=this->m_hWnd;
2657 tme.dwHoverTime=1;
2658 TrackMouseEvent(&tme);
2662 BOOL CTortoiseGitBlameView::PreTranslateMessage(MSG* pMsg)
2664 m_ToolTip.RelayEvent(pMsg);
2665 return CView::PreTranslateMessage(pMsg);
2668 void CTortoiseGitBlameView::OnEditFind()
2670 m_pFindDialog=new CFindReplaceDialog();
2672 m_pFindDialog->Create(TRUE,_T(""),NULL,FR_DOWN,this);
2675 void CTortoiseGitBlameView::OnEditGoto()
2677 CEditGotoDlg dlg;
2678 if(dlg.DoModal()==IDOK)
2680 this->GotoLine(dlg.m_LineNumber);
2684 LRESULT CTortoiseGitBlameView::OnFindDialogMessage(WPARAM wParam, LPARAM lParam)//Õâ¸öÒ²ÊÇÕÒÄǸö³ÌÐò¸ÄµÄ£¬Ö»²»¹ý»»³ÉÁË×Ô¼ºµÄÀà
2686 ASSERT(m_pFindDialog != NULL);
2688 // If the FR_DIALOGTERM flag is set,
2689 // invalidate the handle identifying the dialog box.
2690 if (m_pFindDialog->IsTerminating())
2692 m_pFindDialog = NULL;
2693 return 0;
2696 // If the FR_FINDNEXT flag is set,
2697 // call the application-defined search routine
2698 // to search for the requested string.
2699 if(m_pFindDialog->FindNext())
2701 //read data from dialog
2702 CString FindName = m_pFindDialog->GetFindString();
2703 bool bMatchCase = m_pFindDialog->MatchCase() == TRUE;
2704 bool bMatchWholeWord = m_pFindDialog->MatchWholeWord() == TRUE;
2705 bool bSearchDown = m_pFindDialog->SearchDown() == TRUE;
2707 DoSearch(FindName,m_pFindDialog->m_fr.Flags);
2708 //with given name do search
2709 // *FindWhatYouNeed(FindName, bMatchCase, bMatchWholeWord, bSearchDown);
2712 return 0;
2715 void CTortoiseGitBlameView::OnViewNext()
2717 FindNextLine(this->m_SelectedHash,false);
2719 void CTortoiseGitBlameView::OnViewPrev()
2721 FindNextLine(this->m_SelectedHash,true);
2724 int CTortoiseGitBlameView::FindNextLine(CString CommitHash,bool bUpOrDown)
2726 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
2727 LONG_PTR startline =line;
2728 bool findNoMatch =false;
2729 while(line>=0 && line<m_CommitHash.size())
2731 if(m_CommitHash[line]!=CommitHash)
2733 findNoMatch=true;
2736 if(m_CommitHash[line] == CommitHash && findNoMatch)
2738 if( line == startline+2 )
2740 findNoMatch=false;
2742 else
2744 if( bUpOrDown )
2746 line=FindFirstLine(CommitHash,line);
2748 SendEditor(SCI_LINESCROLL,0,line-startline-2);
2749 return line;
2752 if(bUpOrDown)
2753 line--;
2754 else
2755 line++;
2757 return -1;