Git Blame Find okay
[TortoiseGit.git] / src / TortoiseGitBlame / TortoiseGitBlameView.cpp
blob782a7f17fcd34fc633d185fd93de78e844f9441e
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"
31 #ifdef _DEBUG
32 #define new DEBUG_NEW
33 #endif
35 UINT CTortoiseGitBlameView::m_FindDialogMessage;
37 // CTortoiseGitBlameView
39 IMPLEMENT_DYNCREATE(CTortoiseGitBlameView, CView)
41 BEGIN_MESSAGE_MAP(CTortoiseGitBlameView, CView)
42 // Standard printing commands
43 ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
44 ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
45 ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CTortoiseGitBlameView::OnFilePrintPreview)
46 ON_COMMAND(ID_EDIT_FIND,OnEditFind)
47 ON_COMMAND(ID_EDIT_GOTO,OnEditGoto)
48 ON_WM_CREATE()
49 ON_WM_SIZE()
50 ON_WM_MOUSEMOVE()
51 ON_WM_MOUSEHOVER()
52 ON_WM_MOUSELEAVE()
53 ON_WM_LBUTTONDOWN()
54 ON_WM_RBUTTONDOWN()
55 ON_NOTIFY(SCN_PAINTED,0,OnSciPainted)
56 ON_NOTIFY(SCN_GETBKCOLOR,0,OnSciGetBkColor)
57 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
58 END_MESSAGE_MAP()
61 // CTortoiseGitBlameView construction/destruction
63 CTortoiseGitBlameView::CTortoiseGitBlameView()
65 // TODO: add construction code here
66 hInstance = 0;
67 hResource = 0;
68 currentDialog = 0;
69 wMain = 0;
70 m_wEditor = 0;
71 wLocator = 0;
73 m_font = 0;
74 m_italicfont = 0;
75 m_blamewidth = 0;
76 m_revwidth = 0;
77 m_datewidth = 0;
78 m_authorwidth = 0;
79 m_pathwidth = 0;
80 m_linewidth = 0;
82 m_windowcolor = ::GetSysColor(COLOR_WINDOW);
83 m_textcolor = ::GetSysColor(COLOR_WINDOWTEXT);
84 m_texthighlightcolor = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
85 m_mouserevcolor = InterColor(m_windowcolor, m_textcolor, 20);
86 m_mouseauthorcolor = InterColor(m_windowcolor, m_textcolor, 10);
87 m_selectedrevcolor = ::GetSysColor(COLOR_HIGHLIGHT);
88 m_selectedauthorcolor = InterColor(m_selectedrevcolor, m_texthighlightcolor, 35);
89 m_mouserev = -2;
91 m_selectedrev = -1;
92 m_selectedorigrev = -1;
93 m_SelectedLine = -1;
94 m_directPointer = 0;
95 m_directFunction = 0;
97 m_lowestrev = LONG_MAX;
98 m_highestrev = 0;
99 m_colorage = true;
101 m_bShowLine=true;
103 m_bShowAuthor=true;
104 m_bShowDate=false;
106 m_FindDialogMessage = ::RegisterWindowMessage(FINDMSGSTRING);
107 m_pFindDialog = NULL;
110 CTortoiseGitBlameView::~CTortoiseGitBlameView()
112 if (m_font)
113 DeleteObject(m_font);
114 if (m_italicfont)
115 DeleteObject(m_italicfont);
119 int CTortoiseGitBlameView::OnCreate(LPCREATESTRUCT lpcs)
122 CRect rect,rect1;
123 this->GetWindowRect(&rect1);
124 rect.left=m_blamewidth+LOCATOR_WIDTH;
125 rect.right=rect.Width();
126 rect.top=0;
127 rect.bottom=rect.Height();
128 BOOL b=m_TextView.Create(_T("Scintilla"),_T("source"),0,rect,this,0,0);
129 m_TextView.Init(0);
130 m_TextView.ShowWindow( SW_SHOW);
131 //m_TextView.InsertText(_T("Abdadfasdf"));
132 m_wEditor = m_TextView.m_hWnd;
133 CreateFont();
134 InitialiseEditor();
135 m_ToolTip.Create(this->GetParent());
136 m_ToolTip.AddTool(this,_T("Test"));
138 return CView::OnCreate(lpcs);
141 void CTortoiseGitBlameView::OnSize(UINT nType,int cx, int cy)
144 CRect rect;
145 rect.left=m_blamewidth;
146 rect.right=cx;
147 rect.top=0;
148 rect.bottom=cy;
150 m_TextView.MoveWindow(&rect);
153 BOOL CTortoiseGitBlameView::PreCreateWindow(CREATESTRUCT& cs)
155 // TODO: Modify the Window class or styles here by modifying
156 // the CREATESTRUCT cs
158 return CView::PreCreateWindow(cs);
161 // CTortoiseGitBlameView drawing
163 void CTortoiseGitBlameView::OnDraw(CDC* /*pDC*/)
165 CTortoiseGitBlameDoc* pDoc = GetDocument();
166 ASSERT_VALID(pDoc);
167 if (!pDoc)
168 return;
170 DrawBlame(this->GetDC()->m_hDC);
171 DrawLocatorBar(this->GetDC()->m_hDC);
172 // TODO: add draw code for native data here
176 // CTortoiseGitBlameView printing
179 void CTortoiseGitBlameView::OnFilePrintPreview()
181 AFXPrintPreview(this);
184 BOOL CTortoiseGitBlameView::OnPreparePrinting(CPrintInfo* pInfo)
186 // default preparation
187 return DoPreparePrinting(pInfo);
190 void CTortoiseGitBlameView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
192 // TODO: add extra initialization before printing
195 void CTortoiseGitBlameView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
197 // TODO: add cleanup after printing
200 void CTortoiseGitBlameView::OnRButtonUp(UINT nFlags, CPoint point)
202 ClientToScreen(&point);
203 OnContextMenu(this, point);
206 void CTortoiseGitBlameView::OnContextMenu(CWnd* pWnd, CPoint point)
208 theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE);
212 // CTortoiseGitBlameView diagnostics
214 #ifdef _DEBUG
215 void CTortoiseGitBlameView::AssertValid() const
217 CView::AssertValid();
220 void CTortoiseGitBlameView::Dump(CDumpContext& dc) const
222 CView::Dump(dc);
225 CTortoiseGitBlameDoc* CTortoiseGitBlameView::GetDocument() const // non-debug version is inline
227 ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTortoiseGitBlameDoc)));
228 return (CTortoiseGitBlameDoc*)m_pDocument;
230 #endif //_DEBUG
233 // CTortoiseGitBlameView message handlers
234 CString CTortoiseGitBlameView::GetAppDirectory()
236 CString path;
237 DWORD len = 0;
238 DWORD bufferlen = MAX_PATH; // MAX_PATH is not the limit here!
241 bufferlen += MAX_PATH; // MAX_PATH is not the limit here!
242 TCHAR * pBuf = new TCHAR[bufferlen];
243 len = GetModuleFileName(NULL, pBuf, bufferlen);
244 path = CString(pBuf, len);
245 delete [] pBuf;
246 } while(len == bufferlen);
248 path = path.Left(path.ReverseFind(_T('\\')));
249 //path = path.substr(0, path.rfind('\\') + 1);
251 return path;
254 // Return a color which is interpolated between c1 and c2.
255 // Slider controls the relative proportions as a percentage:
256 // Slider = 0 represents pure c1
257 // Slider = 50 represents equal mixture
258 // Slider = 100 represents pure c2
259 COLORREF CTortoiseGitBlameView::InterColor(COLORREF c1, COLORREF c2, int Slider)
261 int r, g, b;
263 // Limit Slider to 0..100% range
264 if (Slider < 0)
265 Slider = 0;
266 if (Slider > 100)
267 Slider = 100;
269 // The color components have to be treated individually.
270 r = (GetRValue(c2) * Slider + GetRValue(c1) * (100 - Slider)) / 100;
271 g = (GetGValue(c2) * Slider + GetGValue(c1) * (100 - Slider)) / 100;
272 b = (GetBValue(c2) * Slider + GetBValue(c1) * (100 - Slider)) / 100;
274 return RGB(r, g, b);
277 LRESULT CTortoiseGitBlameView::SendEditor(UINT Msg, WPARAM wParam, LPARAM lParam)
279 if (m_directFunction)
281 return ((SciFnDirect) m_directFunction)(m_directPointer, Msg, wParam, lParam);
283 return ::SendMessage(m_wEditor, Msg, wParam, lParam);
286 void CTortoiseGitBlameView::GetRange(int start, int end, char *text)
288 #if 0
289 TEXTRANGE tr;
290 tr.chrg.cpMin = start;
291 tr.chrg.cpMax = end;
292 tr.lpstrText = text;
294 SendMessage(m_wEditor, EM_GETTEXTRANGE, 0, reinterpret_cast<LPARAM>(&tr));
295 #endif
298 void CTortoiseGitBlameView::SetTitle()
300 #if 0
301 char title[MAX_PATH + 100];
302 strcpy_s(title, MAX_PATH + 100, szTitle);
303 strcat_s(title, MAX_PATH + 100, " - ");
304 strcat_s(title, MAX_PATH + 100, szViewtitle);
305 ::SetWindowText(wMain, title);
306 #endif
309 BOOL CTortoiseGitBlameView::OpenLogFile(const char *fileName)
311 #if 0
312 char logmsgbuf[10000+1];
313 FILE * File;
314 fopen_s(&File, fileName, "rb");
315 if (File == 0)
317 return FALSE;
319 LONG rev = 0;
320 CString msg;
321 int slength = 0;
322 int reallength = 0;
323 size_t len = 0;
324 wchar_t wbuf[MAX_LOG_LENGTH+6];
325 for (;;)
327 len = fread(&rev, sizeof(LONG), 1, File);
328 if (len == 0)
330 fclose(File);
331 InitSize();
332 return TRUE;
334 len = fread(&slength, sizeof(int), 1, File);
335 if (len == 0)
337 fclose(File);
338 InitSize();
339 return FALSE;
341 if (slength > MAX_LOG_LENGTH)
343 reallength = slength;
344 slength = MAX_LOG_LENGTH;
346 else
347 reallength = 0;
348 len = fread(logmsgbuf, sizeof(char), slength, File);
349 if (len < (size_t)slength)
351 fclose(File);
352 InitSize();
353 return FALSE;
355 msg = CString(logmsgbuf, slength);
356 if (reallength)
358 fseek(File, reallength-MAX_LOG_LENGTH, SEEK_CUR);
359 msg = msg + _T("\n...");
361 int len2 = ::MultiByteToWideChar(CP_UTF8, NULL, msg.c_str(), min(msg.size(), MAX_LOG_LENGTH+5), wbuf, MAX_LOG_LENGTH+5);
362 wbuf[len2] = 0;
363 len2 = ::WideCharToMultiByte(CP_ACP, NULL, wbuf, len2, logmsgbuf, MAX_LOG_LENGTH+5, NULL, NULL);
364 logmsgbuf[len2] = 0;
365 msg = CString(logmsgbuf);
366 logmessages[rev] = msg;
368 #endif
369 return TRUE;
372 BOOL CTortoiseGitBlameView::OpenFile(const char *fileName)
374 #if 0
375 SendEditor(SCI_SETREADONLY, FALSE);
376 SendEditor(SCI_CLEARALL);
377 SendEditor(EM_EMPTYUNDOBUFFER);
378 SetTitle();
379 SendEditor(SCI_SETSAVEPOINT);
380 SendEditor(SCI_CANCEL);
381 SendEditor(SCI_SETUNDOCOLLECTION, 0);
382 ::ShowWindow(m_wEditor, SW_HIDE);
383 std::ifstream File;
384 File.open(fileName);
385 if (!File.good())
387 return FALSE;
389 char line[100*1024];
390 char * lineptr = NULL;
391 char * trimptr = NULL;
392 //ignore the first two lines, they're of no interest to us
393 File.getline(line, sizeof(line)/sizeof(char));
394 File.getline(line, sizeof(line)/sizeof(char));
395 m_lowestrev = LONG_MAX;
396 m_highestrev = 0;
397 bool bUTF8 = true;
400 File.getline(line, sizeof(line)/sizeof(TCHAR));
401 if (File.gcount()>139)
403 mergelines.push_back((line[0] != ' '));
404 lineptr = &line[9];
405 long rev = _ttol(lineptr);
406 revs.push_back(rev);
407 m_lowestrev = min(m_lowestrev, rev);
408 m_highestrev = max(m_highestrev, rev);
409 lineptr += 7;
410 rev = _ttol(lineptr);
411 origrevs.push_back(rev);
412 lineptr += 7;
413 dates.push_back(CString(lineptr, 30));
414 lineptr += 31;
415 // unfortunately, the 'path' entry can be longer than the 60 chars
416 // we made the column. We therefore have to step through the path
417 // string until we find a space
418 trimptr = lineptr;
421 // TODO: how can we deal with the situation where the path has
422 // a space in it, but the space is after the 60 chars reserved
423 // for it?
424 // The only way to deal with that would be to use a custom
425 // binary format for the blame file.
426 trimptr++;
427 trimptr = _tcschr(trimptr, ' ');
428 } while ((trimptr)&&(trimptr+1 < lineptr+61));
429 if (trimptr)
430 *trimptr = 0;
431 else
432 trimptr = lineptr;
433 paths.push_back(CString(lineptr));
434 if (trimptr+1 < lineptr+61)
435 lineptr +=61;
436 else
437 lineptr = (trimptr+1);
438 trimptr = lineptr+30;
439 while ((*trimptr == ' ')&&(trimptr > lineptr))
440 trimptr--;
441 *(trimptr+1) = 0;
442 authors.push_back(CString(lineptr));
443 lineptr += 31;
444 // in case we find an UTF8 BOM at the beginning of the line, we remove it
445 if (((unsigned char)lineptr[0] == 0xEF)&&((unsigned char)lineptr[1] == 0xBB)&&((unsigned char)lineptr[2] == 0xBF))
447 lineptr += 3;
449 if (((unsigned char)lineptr[0] == 0xBB)&&((unsigned char)lineptr[1] == 0xEF)&&((unsigned char)lineptr[2] == 0xBF))
451 lineptr += 3;
453 // check each line for illegal utf8 sequences. If one is found, we treat
454 // the file as ASCII, otherwise we assume an UTF8 file.
455 char * utf8CheckBuf = lineptr;
456 while ((bUTF8)&&(*utf8CheckBuf))
458 if ((*utf8CheckBuf == 0xC0)||(*utf8CheckBuf == 0xC1)||(*utf8CheckBuf >= 0xF5))
460 bUTF8 = false;
461 break;
463 if ((*utf8CheckBuf & 0xE0)==0xC0)
465 utf8CheckBuf++;
466 if (*utf8CheckBuf == 0)
467 break;
468 if ((*utf8CheckBuf & 0xC0)!=0x80)
470 bUTF8 = false;
471 break;
474 if ((*utf8CheckBuf & 0xF0)==0xE0)
476 utf8CheckBuf++;
477 if (*utf8CheckBuf == 0)
478 break;
479 if ((*utf8CheckBuf & 0xC0)!=0x80)
481 bUTF8 = false;
482 break;
484 utf8CheckBuf++;
485 if (*utf8CheckBuf == 0)
486 break;
487 if ((*utf8CheckBuf & 0xC0)!=0x80)
489 bUTF8 = false;
490 break;
493 if ((*utf8CheckBuf & 0xF8)==0xF0)
495 utf8CheckBuf++;
496 if (*utf8CheckBuf == 0)
497 break;
498 if ((*utf8CheckBuf & 0xC0)!=0x80)
500 bUTF8 = false;
501 break;
503 utf8CheckBuf++;
504 if (*utf8CheckBuf == 0)
505 break;
506 if ((*utf8CheckBuf & 0xC0)!=0x80)
508 bUTF8 = false;
509 break;
511 utf8CheckBuf++;
512 if (*utf8CheckBuf == 0)
513 break;
514 if ((*utf8CheckBuf & 0xC0)!=0x80)
516 bUTF8 = false;
517 break;
521 utf8CheckBuf++;
523 SendEditor(SCI_ADDTEXT, _tcslen(lineptr), reinterpret_cast<LPARAM>(static_cast<char *>(lineptr)));
524 SendEditor(SCI_ADDTEXT, 2, (LPARAM)_T("\r\n"));
526 } while (File.gcount() > 0);
528 if (bUTF8)
529 SendEditor(SCI_SETCODEPAGE, SC_CP_UTF8);
531 SendEditor(SCI_SETUNDOCOLLECTION, 1);
532 ::SetFocus(m_wEditor);
533 SendEditor(EM_EMPTYUNDOBUFFER);
534 SendEditor(SCI_SETSAVEPOINT);
535 SendEditor(SCI_GOTOPOS, 0);
536 SendEditor(SCI_SETSCROLLWIDTHTRACKING, TRUE);
537 SendEditor(SCI_SETREADONLY, TRUE);
539 //check which lexer to use, depending on the filetype
540 SetupLexer(fileName);
541 ::ShowWindow(m_wEditor, SW_SHOW);
542 m_blamewidth = 0;
543 ::InvalidateRect(wMain, NULL, TRUE);
544 RECT rc;
545 GetWindowRect(wMain, &rc);
546 SetWindowPos(wMain, 0, rc.left, rc.top, rc.right-rc.left-1, rc.bottom - rc.top, 0);
547 #endif
548 return TRUE;
551 void CTortoiseGitBlameView::SetAStyle(int style, COLORREF fore, COLORREF back, int size, CString *face)
553 SendEditor(SCI_STYLESETFORE, style, fore);
554 SendEditor(SCI_STYLESETBACK, style, back);
555 if (size >= 1)
556 SendEditor(SCI_STYLESETSIZE, style, size);
557 if (face)
558 SendEditor(SCI_STYLESETFONT, style, reinterpret_cast<LPARAM>(this->m_TextView.StringForControl(*face).GetBuffer()));
561 void CTortoiseGitBlameView::InitialiseEditor()
564 m_directFunction = ::SendMessage(m_wEditor, SCI_GETDIRECTFUNCTION, 0, 0);
565 m_directPointer = ::SendMessage(m_wEditor, SCI_GETDIRECTPOINTER, 0, 0);
566 // Set up the global default style. These attributes are used wherever no explicit choices are made.
567 SetAStyle(STYLE_DEFAULT,
568 black,
569 white,
570 (DWORD)CRegStdWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10),
571 &CString(((stdstring)CRegStdString(_T("Software\\TortoiseGit\\BlameFontName"), _T("Courier New"))).c_str())
573 SendEditor(SCI_SETTABWIDTH, (DWORD)CRegStdWORD(_T("Software\\TortoiseGit\\BlameTabSize"), 4));
574 SendEditor(SCI_SETREADONLY, TRUE);
575 LRESULT pix = SendEditor(SCI_TEXTWIDTH, STYLE_LINENUMBER, (LPARAM)this->m_TextView.StringForControl(_T("_99999")).GetBuffer());
576 if (m_bShowLine)
577 SendEditor(SCI_SETMARGINWIDTHN, 0, pix);
578 else
579 SendEditor(SCI_SETMARGINWIDTHN, 0);
580 SendEditor(SCI_SETMARGINWIDTHN, 1);
581 SendEditor(SCI_SETMARGINWIDTHN, 2);
582 //Set the default windows colors for edit controls
583 SendEditor(SCI_STYLESETFORE, STYLE_DEFAULT, ::GetSysColor(COLOR_WINDOWTEXT));
584 SendEditor(SCI_STYLESETBACK, STYLE_DEFAULT, ::GetSysColor(COLOR_WINDOW));
585 SendEditor(SCI_SETSELFORE, TRUE, ::GetSysColor(COLOR_HIGHLIGHTTEXT));
586 SendEditor(SCI_SETSELBACK, TRUE, ::GetSysColor(COLOR_HIGHLIGHT));
587 SendEditor(SCI_SETCARETFORE, ::GetSysColor(COLOR_WINDOWTEXT));
588 m_regOldLinesColor = CRegStdWORD(_T("Software\\TortoiseGit\\BlameOldColor"), RGB(230, 230, 255));
589 m_regNewLinesColor = CRegStdWORD(_T("Software\\TortoiseGit\\BlameNewColor"), RGB(255, 230, 230));
591 this->m_TextView.Call(SCI_SETWRAPMODE, SC_WRAP_NONE);
595 void CTortoiseGitBlameView::StartSearch()
597 if (m_pFindDialog)
598 return;
599 bool bCase = false;
600 // Initialize FINDREPLACE
601 if (fr.Flags & FR_MATCHCASE)
602 bCase = true;
603 SecureZeroMemory(&fr, sizeof(fr));
604 fr.lStructSize = sizeof(fr);
605 fr.hwndOwner = wMain;
606 fr.lpstrFindWhat = szFindWhat;
607 fr.wFindWhatLen = 80;
608 fr.Flags = FR_HIDEUPDOWN | FR_HIDEWHOLEWORD;
609 fr.Flags |= bCase ? FR_MATCHCASE : 0;
611 currentDialog = FindText(&fr);
614 bool CTortoiseGitBlameView::DoSearch(CString what, DWORD flags)
617 //char szWhat[80];
618 int pos = SendEditor(SCI_GETCURRENTPOS);
619 int line = SendEditor(SCI_LINEFROMPOSITION, pos);
620 bool bFound = false;
621 bool bCaseSensitive = !!(flags & FR_MATCHCASE);
623 //strcpy_s(szWhat, sizeof(szWhat), what);
625 if(!bCaseSensitive)
627 what=what.MakeLower();
630 //CString sWhat = CString(szWhat);
632 //char buf[20];
633 //int i=0;
634 int i=line;
637 int bufsize = SendEditor(SCI_GETLINE, i);
638 char * linebuf = new char[bufsize+1];
639 SecureZeroMemory(linebuf, bufsize+1);
640 SendEditor(SCI_GETLINE, i, (LPARAM)linebuf);
641 CString oneline=this->m_TextView.StringFromControl(linebuf);
642 if (!bCaseSensitive)
644 oneline=oneline.MakeLower();
646 //_stprintf_s(buf, 20, _T("%ld"), revs[i]);
647 if (this->m_Authors[i].Find(what)>=0)
648 bFound = true;
649 else if ((!bCaseSensitive)&&(this->m_Authors[i].MakeLower().Find(what)>=0))
650 bFound = true;
651 else if (oneline.Find(what) >=0)
652 bFound = true;
654 delete [] linebuf;
656 i++;
657 if(i>=m_CommitHash.size())
658 i=0;
659 }while(i!=line &&(!bFound));
661 if (bFound)
663 GotoLine(i);
664 int selstart = SendEditor(SCI_GETCURRENTPOS);
665 int selend = SendEditor(SCI_POSITIONFROMLINE, i);
666 SendEditor(SCI_SETSELECTIONSTART, selstart);
667 SendEditor(SCI_SETSELECTIONEND, selend);
668 m_SelectedLine = i-1;
670 else
672 ::MessageBox(wMain, what+_T(" not found"), _T("CTortoiseGitBlameView"), MB_ICONINFORMATION);
675 return true;
678 bool CTortoiseGitBlameView::GotoLine(long line)
680 --line;
681 if (line < 0)
682 return false;
683 if ((unsigned long)line >= m_CommitHash.size())
685 line = m_CommitHash.size()-1;
688 int nCurrentPos = SendEditor(SCI_GETCURRENTPOS);
689 int nCurrentLine = SendEditor(SCI_LINEFROMPOSITION,nCurrentPos);
690 int nFirstVisibleLine = SendEditor(SCI_GETFIRSTVISIBLELINE);
691 int nLinesOnScreen = SendEditor(SCI_LINESONSCREEN);
693 if ( line>=nFirstVisibleLine && line<=nFirstVisibleLine+nLinesOnScreen)
695 // no need to scroll
696 SendEditor(SCI_GOTOLINE, line);
698 else
700 // Place the requested line one third from the top
701 if ( line > nCurrentLine )
703 SendEditor(SCI_GOTOLINE, (WPARAM)(line+(int)nLinesOnScreen*(2/3.0)));
705 else
707 SendEditor(SCI_GOTOLINE, (WPARAM)(line-(int)nLinesOnScreen*(1/3.0)));
711 // Highlight the line
712 int nPosStart = SendEditor(SCI_POSITIONFROMLINE,line);
713 int nPosEnd = SendEditor(SCI_GETLINEENDPOSITION,line);
714 SendEditor(SCI_SETSEL,nPosEnd,nPosStart);
716 return true;
719 bool CTortoiseGitBlameView::ScrollToLine(long line)
721 if (line < 0)
722 return false;
724 int nCurrentLine = SendEditor(SCI_GETFIRSTVISIBLELINE);
726 int scrolldelta = line - nCurrentLine;
727 SendEditor(SCI_LINESCROLL, 0, scrolldelta);
729 return true;
732 void CTortoiseGitBlameView::CopySelectedLogToClipboard()
734 #if 0
735 if (m_selectedrev <= 0)
736 return;
737 std::map<LONG, CString>::iterator iter;
738 if ((iter = app.logmessages.find(m_selectedrev)) != app.logmessages.end())
740 CString msg;
741 msg += m_selectedauthor;
742 msg += " ";
743 msg += app.m_selecteddate;
744 msg += '\n';
745 msg += iter->second;
746 msg += _T("\n");
747 if (OpenClipboard(app.wBlame))
749 EmptyClipboard();
750 HGLOBAL hClipboardData;
751 hClipboardData = GlobalAlloc(GMEM_DDESHARE, msg.size()+1);
752 char * pchData;
753 pchData = (char*)GlobalLock(hClipboardData);
754 strcpy_s(pchData, msg.size()+1, msg.c_str());
755 GlobalUnlock(hClipboardData);
756 SetClipboardData(CF_TEXT,hClipboardData);
757 CloseClipboard();
760 #endif
763 void CTortoiseGitBlameView::BlamePreviousRevision()
765 #if 0
766 LONG nRevisionTo = m_selectedorigrev - 1;
767 if ( nRevisionTo<1 )
769 return;
772 // We now determine the smallest revision number in the blame file (but ignore "-1")
773 // We do this for two reasons:
774 // 1. we respect the "From revision" which the user entered
775 // 2. we speed up the call of "svn blame" because previous smaller revision numbers don't have any effect on the result
776 LONG nSmallestRevision = -1;
777 for (LONG line=0;line<(LONG)app.revs.size();line++)
779 const LONG nRevision = app.revs[line];
780 if ( nRevision > 0 )
782 if ( nSmallestRevision < 1 )
784 nSmallestRevision = nRevision;
786 else
788 nSmallestRevision = min(nSmallestRevision,nRevision);
793 char bufStartRev[20];
794 _stprintf_s(bufStartRev, 20, _T("%d"), nSmallestRevision);
796 char bufEndRev[20];
797 _stprintf_s(bufEndRev, 20, _T("%d"), nRevisionTo);
799 char bufLine[20];
800 _stprintf_s(bufLine, 20, _T("%d"), m_SelectedLine+1); //using the current line is a good guess.
802 STARTUPINFO startup;
803 PROCESS_INFORMATION process;
804 memset(&startup, 0, sizeof(startup));
805 startup.cb = sizeof(startup);
806 memset(&process, 0, sizeof(process));
807 stdstring tortoiseProcPath = GetAppDirectory() + _T("TortoiseProc.exe");
808 stdstring svnCmd = _T(" /command:blame ");
809 svnCmd += _T(" /path:\"");
810 svnCmd += szOrigPath;
811 svnCmd += _T("\"");
812 svnCmd += _T(" /startrev:");
813 svnCmd += bufStartRev;
814 svnCmd += _T(" /endrev:");
815 svnCmd += bufEndRev;
816 svnCmd += _T(" /line:");
817 svnCmd += bufLine;
818 if (bIgnoreEOL)
819 svnCmd += _T(" /ignoreeol");
820 if (bIgnoreSpaces)
821 svnCmd += _T(" /ignorespaces");
822 if (bIgnoreAllSpaces)
823 svnCmd += _T(" /ignoreallspaces");
824 if (CreateProcess(tortoiseProcPath.c_str(), const_cast<TCHAR*>(svnCmd.c_str()), NULL, NULL, FALSE, 0, 0, 0, &startup, &process))
826 CloseHandle(process.hThread);
827 CloseHandle(process.hProcess);
829 #endif
832 void CTortoiseGitBlameView::DiffPreviousRevision()
834 #if 0
835 LONG nRevisionTo = m_selectedorigrev;
836 if ( nRevisionTo<1 )
838 return;
841 LONG nRevisionFrom = nRevisionTo-1;
843 char bufStartRev[20];
844 _stprintf_s(bufStartRev, 20, _T("%d"), nRevisionFrom);
846 char bufEndRev[20];
847 _stprintf_s(bufEndRev, 20, _T("%d"), nRevisionTo);
849 STARTUPINFO startup;
850 PROCESS_INFORMATION process;
851 memset(&startup, 0, sizeof(startup));
852 startup.cb = sizeof(startup);
853 memset(&process, 0, sizeof(process));
854 stdstring tortoiseProcPath = GetAppDirectory() + _T("TortoiseProc.exe");
855 stdstring svnCmd = _T(" /command:diff ");
856 svnCmd += _T(" /path:\"");
857 svnCmd += szOrigPath;
858 svnCmd += _T("\"");
859 svnCmd += _T(" /startrev:");
860 svnCmd += bufStartRev;
861 svnCmd += _T(" /endrev:");
862 svnCmd += bufEndRev;
863 if (CreateProcess(tortoiseProcPath.c_str(), const_cast<TCHAR*>(svnCmd.c_str()), NULL, NULL, FALSE, 0, 0, 0, &startup, &process))
865 CloseHandle(process.hThread);
866 CloseHandle(process.hProcess);
868 #endif
871 void CTortoiseGitBlameView::ShowLog()
873 #if 0
874 char bufRev[20];
875 _stprintf_s(bufRev, 20, _T("%d"), m_selectedorigrev);
877 STARTUPINFO startup;
878 PROCESS_INFORMATION process;
879 memset(&startup, 0, sizeof(startup));
880 startup.cb = sizeof(startup);
881 memset(&process, 0, sizeof(process));
882 stdstring tortoiseProcPath = GetAppDirectory() + _T("TortoiseProc.exe");
883 stdstring svnCmd = _T(" /command:log ");
884 svnCmd += _T(" /path:\"");
885 svnCmd += szOrigPath;
886 svnCmd += _T("\"");
887 svnCmd += _T(" /startrev:");
888 svnCmd += bufRev;
889 svnCmd += _T(" /pegrev:");
890 svnCmd += bufRev;
891 if (CreateProcess(tortoiseProcPath.c_str(), const_cast<TCHAR*>(svnCmd.c_str()), NULL, NULL, FALSE, 0, 0, 0, &startup, &process))
893 CloseHandle(process.hThread);
894 CloseHandle(process.hProcess);
896 #endif
899 void CTortoiseGitBlameView::Notify(SCNotification *notification)
901 switch (notification->nmhdr.code)
903 case SCN_SAVEPOINTREACHED:
904 break;
906 case SCN_SAVEPOINTLEFT:
907 break;
908 case SCN_PAINTED:
909 // InvalidateRect(wBlame, NULL, FALSE);
910 // InvalidateRect(wLocator, NULL, FALSE);
911 break;
912 case SCN_GETBKCOLOR:
913 // if ((m_colorage)&&(notification->line < (int)revs.size()))
914 // {
915 // notification->lParam = InterColor(DWORD(m_regOldLinesColor), DWORD(m_regNewLinesColor), (revs[notification->line]-m_lowestrev)*100/((m_highestrev-m_lowestrev)+1));
916 // }
917 break;
921 void CTortoiseGitBlameView::Command(int id)
923 #if 0
924 switch (id)
926 // case IDM_EXIT:
927 // ::PostQuitMessage(0);
928 // break;
929 case ID_EDIT_FIND:
930 StartSearch();
931 break;
932 case ID_COPYTOCLIPBOARD:
933 CopySelectedLogToClipboard();
934 break;
935 case ID_BLAME_PREVIOUS_REVISION:
936 BlamePreviousRevision();
937 break;
938 case ID_DIFF_PREVIOUS_REVISION:
939 DiffPreviousRevision();
940 break;
941 case ID_SHOWLOG:
942 ShowLog();
943 break;
944 case ID_EDIT_GOTOLINE:
945 GotoLineDlg();
946 break;
947 case ID_VIEW_COLORAGEOFLINES:
949 m_colorage = !m_colorage;
950 HMENU hMenu = GetMenu(wMain);
951 UINT uCheck = MF_BYCOMMAND;
952 uCheck |= m_colorage ? MF_CHECKED : MF_UNCHECKED;
953 CheckMenuItem(hMenu, ID_VIEW_COLORAGEOFLINES, uCheck);
954 m_blamewidth = 0;
955 InitSize();
957 break;
958 case ID_VIEW_MERGEPATH:
960 ShowPath = !ShowPath;
961 HMENU hMenu = GetMenu(wMain);
962 UINT uCheck = MF_BYCOMMAND;
963 uCheck |= ShowPath ? MF_CHECKED : MF_UNCHECKED;
964 CheckMenuItem(hMenu, ID_VIEW_MERGEPATH, uCheck);
965 m_blamewidth = 0;
966 InitSize();
968 default:
969 break;
971 #endif
974 void CTortoiseGitBlameView::GotoLineDlg()
976 #if 0
977 if (DialogBox(hResource, MAKEINTRESOURCE(IDD_GOTODLG), wMain, GotoDlgProc)==IDOK)
979 GotoLine(m_gotoline);
981 #endif
984 LONG CTortoiseGitBlameView::GetBlameWidth()
986 LONG blamewidth = 0;
987 SIZE width;
988 CreateFont();
989 HDC hDC = this->GetDC()->m_hDC;
990 HFONT oldfont = (HFONT)::SelectObject(hDC, m_font);
992 TCHAR buf[MAX_PATH];
993 //_stprintf_s(buf, MAX_PATH, _T("%8ld "), 88888888);
994 //::GetTextExtentPoint(hDC, buf, _tcslen(buf), &width);
995 //m_revwidth = width.cx + BLAMESPACE;
996 //blamewidth += m_revwidth;
998 int maxnum=0;
999 for (int i=0;i<this->m_Authors.size();i++)
1001 if(m_ID[i]>maxnum)
1002 maxnum=m_ID[i];
1004 _stprintf_s(buf, MAX_PATH, _T("%d."), maxnum);
1005 ::GetTextExtentPoint(hDC, buf, _tcslen(buf), &width);
1006 m_revwidth = width.cx + BLAMESPACE;
1007 blamewidth += m_revwidth;
1009 #if 0
1010 _stprintf_s(buf, MAX_PATH, _T("%d"), m_CommitHash.size());
1011 ::GetTextExtentPoint(hDC, buf, _tcslen(buf), &width);
1012 m_linewidth = width.cx + BLAMESPACE;
1013 blamewidth += m_revwidth;
1014 #endif
1016 if (m_bShowDate)
1018 _stprintf_s(buf, MAX_PATH, _T("%30s"), _T("31.08.2001 06:24:14"));
1019 ::GetTextExtentPoint32(hDC, buf, _tcslen(buf), &width);
1020 m_datewidth = width.cx + BLAMESPACE;
1021 blamewidth += m_datewidth;
1023 if ( m_bShowAuthor)
1025 SIZE maxwidth = {0};
1027 for (int i=0;i<this->m_Authors.size();i++)
1028 //for (std::vector<CString>::iterator I = authors.begin(); I != authors.end(); ++I)
1030 ::GetTextExtentPoint32(hDC,m_Authors[i] , m_Authors[i].GetLength(), &width);
1031 if (width.cx > maxwidth.cx)
1032 maxwidth = width;
1034 m_authorwidth = maxwidth.cx + BLAMESPACE;
1035 blamewidth += m_authorwidth;
1037 #if 0
1038 if (ShowPath)
1040 SIZE maxwidth = {0};
1041 for (std::vector<CString>::iterator I = paths.begin(); I != paths.end(); ++I)
1043 ::GetTextExtentPoint32(hDC, I->c_str(), I->size(), &width);
1044 if (width.cx > maxwidth.cx)
1045 maxwidth = width;
1047 m_pathwidth = maxwidth.cx + BLAMESPACE;
1048 blamewidth += m_pathwidth;
1050 #endif
1051 ::SelectObject(hDC, oldfont);
1052 POINT pt = {blamewidth, 0};
1053 LPtoDP(hDC, &pt, 1);
1054 m_blamewidth = pt.x;
1055 //::ReleaseDC(wBlame, hDC);
1057 //return m_blamewidth;
1058 return blamewidth;
1062 void CTortoiseGitBlameView::CreateFont()
1064 if (m_font)
1065 return;
1066 LOGFONT lf = {0};
1067 lf.lfWeight = 400;
1068 HDC hDC = ::GetDC(wBlame);
1069 lf.lfHeight = -MulDiv((DWORD)CRegStdWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10), GetDeviceCaps(hDC, LOGPIXELSY), 72);
1070 lf.lfCharSet = DEFAULT_CHARSET;
1071 CRegStdString fontname = CRegStdString(_T("Software\\TortoiseGit\\BlameFontName"), _T("Courier New"));
1072 _tcscpy_s(lf.lfFaceName, 32, ((stdstring)fontname).c_str());
1073 m_font = ::CreateFontIndirect(&lf);
1075 lf.lfItalic = TRUE;
1076 m_italicfont = ::CreateFontIndirect(&lf);
1078 ::ReleaseDC(wBlame, hDC);
1080 //m_TextView.SetFont(lf.lfFaceName,((DWORD)CRegStdWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10)));
1083 void CTortoiseGitBlameView::DrawBlame(HDC hDC)
1086 if (hDC == NULL)
1087 return;
1088 if (m_font == NULL)
1089 return;
1091 HFONT oldfont = NULL;
1092 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
1093 LONG_PTR linesonscreen = SendEditor(SCI_LINESONSCREEN);
1094 LONG_PTR height = SendEditor(SCI_TEXTHEIGHT);
1095 LONG_PTR Y = 0;
1096 TCHAR buf[MAX_PATH];
1097 RECT rc;
1098 BOOL sel = FALSE;
1099 //::GetClientRect(this->m_hWnd, &rc);
1100 for (LRESULT i=line; i<(line+linesonscreen); ++i)
1102 sel = FALSE;
1103 if (i < (int)m_CommitHash.size())
1105 // if (mergelines[i])
1106 // oldfont = (HFONT)::SelectObject(hDC, m_italicfont);
1107 // else
1108 oldfont = (HFONT)::SelectObject(hDC, m_font);
1109 ::SetBkColor(hDC, m_windowcolor);
1110 ::SetTextColor(hDC, m_textcolor);
1111 if (m_CommitHash[i].GetLength()>0)
1113 //if (m_CommitHash[i].Compare(m_MouseHash)==0)
1114 // ::SetBkColor(hDC, m_mouseauthorcolor);
1115 if (m_CommitHash[i].Compare(m_SelectedHash)==0)
1117 ::SetBkColor(hDC, m_selectedauthorcolor);
1118 ::SetTextColor(hDC, m_texthighlightcolor);
1119 sel = TRUE;
1123 if(m_MouseLine == i)
1124 ::SetBkColor(hDC, m_mouserevcolor);
1126 //if ((revs[i] == m_mouserev)&&(!sel))
1127 // ::SetBkColor(hDC, m_mouserevcolor);
1128 //if (revs[i] == m_selectedrev)
1130 // ::SetBkColor(hDC, m_selectedrevcolor);
1131 // ::SetTextColor(hDC, m_texthighlightcolor);
1134 CString str;
1135 str.Format(_T("%d"),m_ID[i]);
1137 //_stprintf_s(buf, MAX_PATH, _T("%8ld "), revs[i]);
1138 rc.top=Y;
1139 rc.left=LOCATOR_WIDTH;
1140 rc.bottom=Y+height;
1141 rc.right = rc.left + m_blamewidth;
1142 ::ExtTextOut(hDC, LOCATOR_WIDTH, Y, ETO_CLIPPED, &rc, str, str.GetLength(), 0);
1143 int Left = m_revwidth;
1145 if (m_bShowAuthor)
1147 rc.right = rc.left + Left + m_authorwidth;
1148 //_stprintf_s(buf, MAX_PATH, _T("%-30s "), authors[i].c_str());
1149 ::ExtTextOut(hDC, Left, Y, ETO_CLIPPED, &rc, m_Authors[i], m_Authors[i].GetLength(), 0);
1150 Left += m_authorwidth;
1152 #if 0
1153 if (ShowDate)
1155 rc.right = rc.left + Left + m_datewidth;
1156 _stprintf_s(buf, MAX_PATH, _T("%30s "), dates[i].c_str());
1157 ::ExtTextOut(hDC, Left, Y, ETO_CLIPPED, &rc, buf, _tcslen(buf), 0);
1158 Left += m_datewidth;
1161 #endif
1162 #if 0
1163 if (ShowPath)
1165 rc.right = rc.left + Left + m_pathwidth;
1166 _stprintf_s(buf, MAX_PATH, _T("%-60s "), paths[i].c_str());
1167 ::ExtTextOut(hDC, Left, Y, ETO_CLIPPED, &rc, buf, _tcslen(buf), 0);
1168 Left += m_authorwidth;
1170 #endif
1171 if ((i==m_SelectedLine)&&(m_pFindDialog))
1173 LOGBRUSH brush;
1174 brush.lbColor = m_textcolor;
1175 brush.lbHatch = 0;
1176 brush.lbStyle = BS_SOLID;
1177 HPEN pen = ExtCreatePen(PS_SOLID | PS_GEOMETRIC, 2, &brush, 0, NULL);
1178 HGDIOBJ hPenOld = SelectObject(hDC, pen);
1179 RECT rc2 = rc;
1180 rc2.top = Y;
1181 rc2.bottom = Y + height;
1182 ::MoveToEx(hDC, rc2.left, rc2.top, NULL);
1183 ::LineTo(hDC, rc2.right, rc2.top);
1184 ::LineTo(hDC, rc2.right, rc2.bottom);
1185 ::LineTo(hDC, rc2.left, rc2.bottom);
1186 ::LineTo(hDC, rc2.left, rc2.top);
1187 SelectObject(hDC, hPenOld);
1188 DeleteObject(pen);
1190 Y += height;
1191 ::SelectObject(hDC, oldfont);
1193 else
1195 ::SetBkColor(hDC, m_windowcolor);
1196 for (int j=0; j< MAX_PATH; ++j)
1197 buf[j]=' ';
1198 ::ExtTextOut(hDC, 0, Y, ETO_CLIPPED, &rc, buf, MAX_PATH-1, 0);
1199 Y += height;
1204 void CTortoiseGitBlameView::DrawHeader(HDC hDC)
1206 #if 0
1207 if (hDC == NULL)
1208 return;
1210 RECT rc;
1211 HFONT oldfont = (HFONT)::SelectObject(hDC, GetStockObject(DEFAULT_GUI_FONT));
1212 ::GetClientRect(wHeader, &rc);
1214 ::SetBkColor(hDC, ::GetSysColor(COLOR_BTNFACE));
1216 TCHAR szText[MAX_LOADSTRING];
1217 LoadString(app.hResource, IDS_HEADER_REVISION, szText, MAX_LOADSTRING);
1218 ::ExtTextOut(hDC, LOCATOR_WIDTH, 0, ETO_CLIPPED, &rc, szText, _tcslen(szText), 0);
1219 int Left = m_revwidth+LOCATOR_WIDTH;
1220 if (ShowDate)
1222 LoadString(app.hResource, IDS_HEADER_DATE, szText, MAX_LOADSTRING);
1223 ::ExtTextOut(hDC, Left, 0, ETO_CLIPPED, &rc, szText, _tcslen(szText), 0);
1224 Left += m_datewidth;
1226 if (ShowAuthor)
1228 LoadString(app.hResource, IDS_HEADER_AUTHOR, szText, MAX_LOADSTRING);
1229 ::ExtTextOut(hDC, Left, 0, ETO_CLIPPED, &rc, szText, _tcslen(szText), 0);
1230 Left += m_authorwidth;
1232 if (ShowPath)
1234 LoadString(app.hResource, IDS_HEADER_PATH, szText, MAX_LOADSTRING);
1235 ::ExtTextOut(hDC, Left, 0, ETO_CLIPPED, &rc, szText, _tcslen(szText), 0);
1236 Left += m_pathwidth;
1238 LoadString(app.hResource, IDS_HEADER_LINE, szText, MAX_LOADSTRING);
1239 ::ExtTextOut(hDC, Left, 0, ETO_CLIPPED, &rc, szText, _tcslen(szText), 0);
1241 ::SelectObject(hDC, oldfont);
1242 #endif
1245 void CTortoiseGitBlameView::DrawLocatorBar(HDC hDC)
1247 if (hDC == NULL)
1248 return;
1250 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
1251 LONG_PTR linesonscreen = SendEditor(SCI_LINESONSCREEN);
1252 LONG_PTR Y = 0;
1253 COLORREF blackColor = GetSysColor(COLOR_WINDOWTEXT);
1255 RECT rc;
1256 //::GetClientRect(wLocator, &rc);
1257 this->GetClientRect(&rc);
1259 rc.right=LOCATOR_WIDTH;
1261 RECT lineRect = rc;
1262 LONG height = rc.bottom-rc.top;
1263 LONG currentLine = 0;
1265 // draw the colored bar
1266 for (std::vector<LONG>::const_iterator it = m_ID.begin(); it != m_ID.end(); ++it)
1268 currentLine++;
1269 // get the line color
1270 COLORREF cr = InterColor(DWORD(m_regOldLinesColor), DWORD(m_regNewLinesColor), (*it - m_lowestrev)*100/((m_highestrev-m_lowestrev)+1));
1271 if ((currentLine > line)&&(currentLine <= (line + linesonscreen)))
1273 cr = InterColor(cr, blackColor, 10);
1275 SetBkColor(hDC, cr);
1276 lineRect.top = Y;
1277 lineRect.bottom = (currentLine * height / m_ID.size());
1278 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, NULL, 0, NULL);
1279 Y = lineRect.bottom;
1282 if (m_ID.size())
1284 // now draw two lines indicating the scroll position of the source view
1285 SetBkColor(hDC, blackColor);
1286 lineRect.top = line * height / m_ID.size();
1287 lineRect.bottom = lineRect.top+1;
1288 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, NULL, 0, NULL);
1289 lineRect.top = (line + linesonscreen) * height / m_ID.size();
1290 lineRect.bottom = lineRect.top+1;
1291 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, NULL, 0, NULL);
1296 void CTortoiseGitBlameView::StringExpand(LPSTR str)
1298 char * cPos = str;
1301 cPos = strchr(cPos, '\n');
1302 if (cPos)
1304 memmove(cPos+1, cPos, strlen(cPos)*sizeof(char));
1305 *cPos = '\r';
1306 cPos++;
1307 cPos++;
1309 } while (cPos != NULL);
1311 void CTortoiseGitBlameView::StringExpand(LPWSTR str)
1313 wchar_t * cPos = str;
1316 cPos = wcschr(cPos, '\n');
1317 if (cPos)
1319 memmove(cPos+1, cPos, wcslen(cPos)*sizeof(wchar_t));
1320 *cPos = '\r';
1321 cPos++;
1322 cPos++;
1324 } while (cPos != NULL);
1327 // Forward declarations of functions included in this code module:
1328 ATOM MyRegisterClass(HINSTANCE hResource);
1329 ATOM MyRegisterBlameClass(HINSTANCE hResource);
1330 ATOM MyRegisterHeaderClass(HINSTANCE hResource);
1331 ATOM MyRegisterLocatorClass(HINSTANCE hResource);
1332 BOOL InitInstance(HINSTANCE, int);
1333 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
1334 LRESULT CALLBACK WndBlameProc(HWND, UINT, WPARAM, LPARAM);
1335 LRESULT CALLBACK WndHeaderProc(HWND, UINT, WPARAM, LPARAM);
1336 LRESULT CALLBACK WndLocatorProc(HWND, UINT, WPARAM, LPARAM);
1337 UINT uFindReplaceMsg;
1339 #if 0
1340 int APIENTRY _tWinMain(HINSTANCE hInstance,
1341 HINSTANCE /*hPrevInstance*/,
1342 LPTSTR lpCmdLine,
1343 int nCmdShow)
1345 app.hInstance = hInstance;
1346 MSG msg;
1347 HACCEL hAccelTable;
1349 if (::LoadLibrary("SciLexer.DLL") == NULL)
1350 return FALSE;
1352 CRegStdWORD loc = CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033);
1353 long langId = loc;
1355 CLangDll langDLL;
1356 app.hResource = langDLL.Init(_T("CTortoiseGitBlameView"), langId);
1357 if (app.hResource == NULL)
1358 app.hResource = app.hInstance;
1360 // Initialize global strings
1361 LoadString(app.hResource, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
1362 LoadString(app.hResource, IDC_TortoiseGitBlameView, szWindowClass, MAX_LOADSTRING);
1363 LoadString(app.hResource, IDS_SEARCHNOTFOUND, searchstringnotfound, MAX_LOADSTRING);
1364 MyRegisterClass(app.hResource);
1365 MyRegisterBlameClass(app.hResource);
1366 MyRegisterHeaderClass(app.hResource);
1367 MyRegisterLocatorClass(app.hResource);
1369 // Perform application initialization:
1370 if (!InitInstance (app.hResource, nCmdShow))
1372 langDLL.Close();
1373 return FALSE;
1376 SecureZeroMemory(szViewtitle, MAX_PATH);
1377 SecureZeroMemory(szOrigPath, MAX_PATH);
1378 char blamefile[MAX_PATH] = {0};
1379 char logfile[MAX_PATH] = {0};
1381 CCmdLineParser parser(lpCmdLine);
1384 if (__argc > 1)
1386 _tcscpy_s(blamefile, MAX_PATH, __argv[1]);
1388 if (__argc > 2)
1390 _tcscpy_s(logfile, MAX_PATH, __argv[2]);
1392 if (__argc > 3)
1394 _tcscpy_s(szViewtitle, MAX_PATH, __argv[3]);
1395 if (parser.HasVal(_T("revrange")))
1397 _tcscat_s(szViewtitle, MAX_PATH, _T(" : "));
1398 _tcscat_s(szViewtitle, MAX_PATH, parser.GetVal(_T("revrange")));
1401 if ((_tcslen(blamefile)==0) || parser.HasKey(_T("?")) || parser.HasKey(_T("help")))
1403 TCHAR szInfo[MAX_LOADSTRING];
1404 LoadString(app.hResource, IDS_COMMANDLINE_INFO, szInfo, MAX_LOADSTRING);
1405 MessageBox(NULL, szInfo, _T("CTortoiseGitBlameView"), MB_ICONERROR);
1406 langDLL.Close();
1407 return 0;
1410 if ( parser.HasKey(_T("path")) )
1412 _tcscpy_s(szOrigPath, MAX_PATH, parser.GetVal(_T("path")));
1414 app.bIgnoreEOL = parser.HasKey(_T("ignoreeol"));
1415 app.bIgnoreSpaces = parser.HasKey(_T("ignorespaces"));
1416 app.bIgnoreAllSpaces = parser.HasKey(_T("ignoreallspaces"));
1418 app.SendEditor(SCI_SETCODEPAGE, GetACP());
1419 app.OpenFile(blamefile);
1420 if (_tcslen(logfile)>0)
1421 app.OpenLogFile(logfile);
1423 if (parser.HasKey(_T("line")))
1425 app.GotoLine(parser.GetLongVal(_T("line")));
1428 CheckMenuItem(GetMenu(app.wMain), ID_VIEW_COLORAGEOFLINES, MF_CHECKED|MF_BYCOMMAND);
1431 hAccelTable = LoadAccelerators(app.hResource, (LPCTSTR)IDC_TortoiseGitBlameView);
1433 BOOL going = TRUE;
1434 msg.wParam = 0;
1435 while (going)
1437 going = GetMessage(&msg, NULL, 0, 0);
1438 if (app.currentDialog && going)
1440 if (!IsDialogMessage(app.currentDialog, &msg))
1442 if (TranslateAccelerator(msg.hwnd, hAccelTable, &msg) == 0)
1444 TranslateMessage(&msg);
1445 DispatchMessage(&msg);
1449 else if (going)
1451 if (TranslateAccelerator(app.wMain, hAccelTable, &msg) == 0)
1453 TranslateMessage(&msg);
1454 DispatchMessage(&msg);
1458 langDLL.Close();
1459 return msg.wParam;
1462 ATOM MyRegisterClass(HINSTANCE hResource)
1464 WNDCLASSEX wcex;
1466 wcex.cbSize = sizeof(WNDCLASSEX);
1468 wcex.style = CS_HREDRAW | CS_VREDRAW;
1469 wcex.lpfnWndProc = (WNDPROC)WndProc;
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 = (LPCTSTR)IDC_TortoiseGitBlameView;
1477 wcex.lpszClassName = szWindowClass;
1478 wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
1480 return RegisterClassEx(&wcex);
1483 ATOM MyRegisterBlameClass(HINSTANCE hResource)
1485 WNDCLASSEX wcex;
1487 wcex.cbSize = sizeof(WNDCLASSEX);
1489 wcex.style = CS_HREDRAW | CS_VREDRAW;
1490 wcex.lpfnWndProc = (WNDPROC)WndBlameProc;
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_WINDOW+1);
1497 wcex.lpszMenuName = 0;
1498 wcex.lpszClassName = _T("TortoiseGitBlameViewBlame");
1499 wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
1501 return RegisterClassEx(&wcex);
1504 ATOM MyRegisterHeaderClass(HINSTANCE hResource)
1506 WNDCLASSEX wcex;
1508 wcex.cbSize = sizeof(WNDCLASSEX);
1510 wcex.style = CS_HREDRAW | CS_VREDRAW;
1511 wcex.lpfnWndProc = (WNDPROC)WndHeaderProc;
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_BTNFACE+1);
1518 wcex.lpszMenuName = 0;
1519 wcex.lpszClassName = _T("TortoiseGitBlameViewHeader");
1520 wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
1522 return RegisterClassEx(&wcex);
1525 ATOM MyRegisterLocatorClass(HINSTANCE hResource)
1527 WNDCLASSEX wcex;
1529 wcex.cbSize = sizeof(WNDCLASSEX);
1531 wcex.style = CS_HREDRAW | CS_VREDRAW;
1532 wcex.lpfnWndProc = (WNDPROC)WndLocatorProc;
1533 wcex.cbClsExtra = 0;
1534 wcex.cbWndExtra = 0;
1535 wcex.hInstance = hResource;
1536 wcex.hIcon = LoadIcon(hResource, (LPCTSTR)IDI_TortoiseGitBlameView);
1537 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
1538 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
1539 wcex.lpszMenuName = 0;
1540 wcex.lpszClassName = _T("TortoiseGitBlameViewLocator");
1541 wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
1543 return RegisterClassEx(&wcex);
1546 BOOL InitInstance(HINSTANCE hResource, int nCmdShow)
1548 app.wMain = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
1549 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hResource, NULL);
1551 if (!app.wMain)
1553 return FALSE;
1556 CRegStdWORD pos(_T("Software\\TortoiseGit\\TBlamePos"), 0);
1557 CRegStdWORD width(_T("Software\\TortoiseGit\\TBlameSize"), 0);
1558 CRegStdWORD state(_T("Software\\TortoiseGit\\TBlameState"), 0);
1559 if (DWORD(pos) && DWORD(width))
1561 RECT rc;
1562 rc.left = LOWORD(DWORD(pos));
1563 rc.top = HIWORD(DWORD(pos));
1564 rc.right = rc.left + LOWORD(DWORD(width));
1565 rc.bottom = rc.top + HIWORD(DWORD(width));
1566 HMONITOR hMon = MonitorFromRect(&rc, MONITOR_DEFAULTTONULL);
1567 if (hMon)
1569 // only restore the window position if the monitor is valid
1570 MoveWindow(app.wMain, LOWORD(DWORD(pos)), HIWORD(DWORD(pos)),
1571 LOWORD(DWORD(width)), HIWORD(DWORD(width)), FALSE);
1574 if (DWORD(state) == SW_MAXIMIZE)
1575 ShowWindow(app.wMain, SW_MAXIMIZE);
1576 else
1577 ShowWindow(app.wMain, nCmdShow);
1578 UpdateWindow(app.wMain);
1580 //Create the tooltips
1582 INITCOMMONCONTROLSEX iccex;
1583 app.hwndTT; // handle to the ToolTip control
1584 TOOLINFO ti;
1585 RECT rect; // for client area coordinates
1586 iccex.dwICC = ICC_WIN95_CLASSES;
1587 iccex.dwSize = sizeof(INITCOMMONCONTROLSEX);
1588 InitCommonControlsEx(&iccex);
1590 /* CREATE A TOOLTIP WINDOW */
1591 app.hwndTT = CreateWindowEx(WS_EX_TOPMOST,
1592 TOOLTIPS_CLASS,
1593 NULL,
1594 WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
1595 CW_USEDEFAULT,
1596 CW_USEDEFAULT,
1597 CW_USEDEFAULT,
1598 CW_USEDEFAULT,
1599 app.wBlame,
1600 NULL,
1601 app.hResource,
1602 NULL
1605 SetWindowPos(app.hwndTT,
1606 HWND_TOPMOST,
1611 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
1613 /* GET COORDINATES OF THE MAIN CLIENT AREA */
1614 GetClientRect (app.wBlame, &rect);
1616 /* INITIALIZE MEMBERS OF THE TOOLINFO STRUCTURE */
1617 ti.cbSize = sizeof(TOOLINFO);
1618 ti.uFlags = TTF_TRACK | TTF_ABSOLUTE;//TTF_SUBCLASS | TTF_PARSELINKS;
1619 ti.hwnd = app.wBlame;
1620 ti.hinst = app.hResource;
1621 ti.uId = 0;
1622 ti.lpszText = LPSTR_TEXTCALLBACK;
1623 // ToolTip control will cover the whole window
1624 ti.rect.left = rect.left;
1625 ti.rect.top = rect.top;
1626 ti.rect.right = rect.right;
1627 ti.rect.bottom = rect.bottom;
1629 /* SEND AN ADDTOOL MESSAGE TO THE TOOLTIP CONTROL WINDOW */
1630 SendMessage(app.hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
1631 SendMessage(app.hwndTT, TTM_SETMAXTIPWIDTH, 0, 600);
1632 //SendMessage(app.hwndTT, TTM_SETDELAYTIME, TTDT_AUTOPOP, MAKELONG(50000, 0));
1633 //SendMessage(app.hwndTT, TTM_SETDELAYTIME, TTDT_RESHOW, MAKELONG(1000, 0));
1635 uFindReplaceMsg = RegisterWindowMessage(FINDMSGSTRING);
1637 return TRUE;
1639 #endif
1640 void CTortoiseGitBlameView::InitSize()
1642 RECT rc;
1643 RECT blamerc;
1644 RECT sourcerc;
1645 ::GetClientRect(wMain, &rc);
1646 ::SetWindowPos(wHeader, 0, rc.left, rc.top, rc.right-rc.left, HEADER_HEIGHT, 0);
1647 rc.top += HEADER_HEIGHT;
1648 blamerc.left = rc.left;
1649 blamerc.top = rc.top;
1650 LONG w = GetBlameWidth();
1651 blamerc.right = w > abs(rc.right - rc.left) ? rc.right : w + rc.left;
1652 blamerc.bottom = rc.bottom;
1653 sourcerc.left = blamerc.right;
1654 sourcerc.top = rc.top;
1655 sourcerc.bottom = rc.bottom;
1656 sourcerc.right = rc.right;
1657 if (m_colorage)
1659 ::OffsetRect(&blamerc, LOCATOR_WIDTH, 0);
1660 ::OffsetRect(&sourcerc, LOCATOR_WIDTH, 0);
1661 sourcerc.right -= LOCATOR_WIDTH;
1663 ::InvalidateRect(wMain, NULL, FALSE);
1664 ::SetWindowPos(m_wEditor, 0, sourcerc.left, sourcerc.top, sourcerc.right - sourcerc.left, sourcerc.bottom - sourcerc.top, 0);
1665 ::SetWindowPos(wBlame, 0, blamerc.left, blamerc.top, blamerc.right - blamerc.left, blamerc.bottom - blamerc.top, 0);
1666 if (m_colorage)
1667 ::SetWindowPos(wLocator, 0, 0, blamerc.top, LOCATOR_WIDTH, blamerc.bottom - blamerc.top, SWP_SHOWWINDOW);
1668 else
1669 ::ShowWindow(wLocator, SW_HIDE);
1672 #if 0
1673 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1675 if (message == uFindReplaceMsg)
1677 LPFINDREPLACE lpfr = (LPFINDREPLACE)lParam;
1679 // If the FR_DIALOGTERM flag is set,
1680 // invalidate the handle identifying the dialog box.
1681 if (lpfr->Flags & FR_DIALOGTERM)
1683 app.currentDialog = NULL;
1684 return 0;
1686 if (lpfr->Flags & FR_FINDNEXT)
1688 app.DoSearch(lpfr->lpstrFindWhat, lpfr->Flags);
1690 return 0;
1692 switch (message)
1694 case WM_CREATE:
1695 app.m_wEditor = ::CreateWindow(
1696 "Scintilla",
1697 "Source",
1698 WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_CLIPCHILDREN,
1699 0, 0,
1700 100, 100,
1701 hWnd,
1703 app.hResource,
1705 app.InitialiseEditor();
1706 ::ShowWindow(app.m_wEditor, SW_SHOW);
1707 ::SetFocus(app.m_wEditor);
1708 app.wBlame = ::CreateWindow(
1709 _T("TortoiseGitBlameViewBlame"),
1710 _T("blame"),
1711 WS_CHILD | WS_CLIPCHILDREN,
1712 CW_USEDEFAULT, 0,
1713 CW_USEDEFAULT, 0,
1714 hWnd,
1715 NULL,
1716 app.hResource,
1717 NULL);
1718 ::ShowWindow(app.wBlame, SW_SHOW);
1719 app.wHeader = ::CreateWindow(
1720 _T("TortoiseGitBlameViewHeader"),
1721 _T("header"),
1722 WS_CHILD | WS_CLIPCHILDREN | WS_BORDER,
1723 CW_USEDEFAULT, 0,
1724 CW_USEDEFAULT, 0,
1725 hWnd,
1726 NULL,
1727 app.hResource,
1728 NULL);
1729 ::ShowWindow(app.wHeader, SW_SHOW);
1730 app.wLocator = ::CreateWindow(
1731 _T("TortoiseGitBlameViewLocator"),
1732 _T("locator"),
1733 WS_CHILD | WS_CLIPCHILDREN | WS_BORDER,
1734 CW_USEDEFAULT, 0,
1735 CW_USEDEFAULT, 0,
1736 hWnd,
1737 NULL,
1738 app.hResource,
1739 NULL);
1740 ::ShowWindow(app.wLocator, SW_SHOW);
1741 return 0;
1743 case WM_SIZE:
1744 if (wParam != 1)
1746 app.InitSize();
1748 return 0;
1750 case WM_COMMAND:
1751 app.Command(LOWORD(wParam));
1752 break;
1753 case WM_NOTIFY:
1754 app.Notify(reinterpret_cast<SCNotification *>(lParam));
1755 return 0;
1756 case WM_DESTROY:
1757 PostQuitMessage(0);
1758 break;
1759 case WM_CLOSE:
1761 CRegStdWORD pos(_T("Software\\TortoiseGit\\TBlamePos"), 0);
1762 CRegStdWORD width(_T("Software\\TortoiseGit\\TBlameSize"), 0);
1763 CRegStdWORD state(_T("Software\\TortoiseGit\\TBlameState"), 0);
1764 RECT rc;
1765 GetWindowRect(app.wMain, &rc);
1766 if ((rc.left >= 0)&&(rc.top >= 0))
1768 pos = MAKELONG(rc.left, rc.top);
1769 width = MAKELONG(rc.right-rc.left, rc.bottom-rc.top);
1771 WINDOWPLACEMENT wp = {0};
1772 wp.length = sizeof(WINDOWPLACEMENT);
1773 GetWindowPlacement(app.wMain, &wp);
1774 state = wp.showCmd;
1775 ::DestroyWindow(app.m_wEditor);
1776 ::PostQuitMessage(0);
1778 return 0;
1779 case WM_SETFOCUS:
1780 ::SetFocus(app.wBlame);
1781 break;
1782 default:
1783 return DefWindowProc(hWnd, message, wParam, lParam);
1785 return 0;
1788 LRESULT CALLBACK WndBlameProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1790 PAINTSTRUCT ps;
1791 TRACKMOUSEEVENT mevt;
1792 HDC hDC;
1793 switch (message)
1795 case WM_CREATE:
1796 return 0;
1797 case WM_PAINT:
1798 hDC = BeginPaint(app.wBlame, &ps);
1799 app.DrawBlame(hDC);
1800 EndPaint(app.wBlame, &ps);
1801 break;
1802 case WM_COMMAND:
1803 app.Command(LOWORD(wParam));
1804 break;
1805 case WM_NOTIFY:
1806 switch (((LPNMHDR)lParam)->code)
1808 case TTN_GETDISPINFO:
1810 LPNMHDR pNMHDR = (LPNMHDR)lParam;
1811 NMTTDISPINFOA* pTTTA = (NMTTDISPINFOA*)pNMHDR;
1812 NMTTDISPINFOW* pTTTW = (NMTTDISPINFOW*)pNMHDR;
1813 POINT point;
1814 DWORD ptW = GetMessagePos();
1815 point.x = GET_X_LPARAM(ptW);
1816 point.y = GET_Y_LPARAM(ptW);
1817 ::ScreenToClient(app.wBlame, &point);
1818 LONG_PTR line = app.SendEditor(SCI_GETFIRSTVISIBLELINE);
1819 LONG_PTR height = app.SendEditor(SCI_TEXTHEIGHT);
1820 line = line + (point.y/height);
1821 if (line >= (LONG)app.revs.size())
1822 break;
1823 if (line < 0)
1824 break;
1825 LONG rev = app.revs[line];
1826 if (line >= (LONG)app.revs.size())
1827 break;
1829 SecureZeroMemory(app.m_szTip, sizeof(app.m_szTip));
1830 SecureZeroMemory(app.m_wszTip, sizeof(app.m_wszTip));
1831 std::map<LONG, CString>::iterator iter;
1832 if ((iter = app.logmessages.find(rev)) != app.logmessages.end())
1834 CString msg;
1835 if (!ShowAuthor)
1837 msg += app.authors[line];
1839 if (!ShowDate)
1841 if (!ShowAuthor) msg += " ";
1842 msg += app.dates[line];
1844 if (!ShowAuthor || !ShowDate)
1845 msg += '\n';
1846 msg += iter->second;
1847 // an empty tooltip string will deactivate the tooltips,
1848 // which means we must make sure that the tooltip won't
1849 // be empty.
1850 if (msg.empty())
1851 msg = _T(" ");
1852 if (pNMHDR->code == TTN_NEEDTEXTA)
1854 lstrcpyn(app.m_szTip, msg.c_str(), MAX_LOG_LENGTH*2);
1855 app.StringExpand(app.m_szTip);
1856 pTTTA->lpszText = app.m_szTip;
1858 else
1860 pTTTW->lpszText = app.m_wszTip;
1861 ::MultiByteToWideChar( CP_ACP , 0, msg.c_str(), min(msg.size(), MAX_LOG_LENGTH*2), app.m_wszTip, MAX_LOG_LENGTH*2);
1862 app.StringExpand(app.m_wszTip);
1866 break;
1868 return 0;
1869 case WM_DESTROY:
1870 break;
1871 case WM_CLOSE:
1872 return 0;
1873 case WM_MOUSELEAVE:
1874 app.m_mouserev = -2;
1875 app.m_mouseauthor.clear();
1876 app.ttVisible = FALSE;
1877 SendMessage(app.hwndTT, TTM_TRACKACTIVATE, FALSE, 0);
1878 ::InvalidateRect(app.wBlame, NULL, FALSE);
1879 break;
1880 case WM_MOUSEMOVE:
1882 mevt.cbSize = sizeof(TRACKMOUSEEVENT);
1883 mevt.dwFlags = TME_LEAVE;
1884 mevt.dwHoverTime = HOVER_DEFAULT;
1885 mevt.hwndTrack = app.wBlame;
1886 ::TrackMouseEvent(&mevt);
1887 POINT pt = {((int)(short)LOWORD(lParam)), ((int)(short)HIWORD(lParam))};
1888 ClientToScreen(app.wBlame, &pt);
1889 pt.x += 15;
1890 pt.y += 15;
1891 SendMessage(app.hwndTT, TTM_TRACKPOSITION, 0, MAKELONG(pt.x, pt.y));
1892 if (!app.ttVisible)
1894 TOOLINFO ti;
1895 ti.cbSize = sizeof(TOOLINFO);
1896 ti.hwnd = app.wBlame;
1897 ti.uId = 0;
1898 SendMessage(app.hwndTT, TTM_TRACKACTIVATE, TRUE, (LPARAM)&ti);
1900 int y = ((int)(short)HIWORD(lParam));
1901 LONG_PTR line = app.SendEditor(SCI_GETFIRSTVISIBLELINE);
1902 LONG_PTR height = app.SendEditor(SCI_TEXTHEIGHT);
1903 line = line + (y/height);
1904 app.ttVisible = (line < (LONG)app.revs.size());
1905 if ( app.ttVisible )
1907 if (app.authors[line].compare(app.m_mouseauthor) != 0)
1909 app.m_mouseauthor = app.authors[line];
1911 if (app.revs[line] != app.m_mouserev)
1913 app.m_mouserev = app.revs[line];
1914 ::InvalidateRect(app.wBlame, NULL, FALSE);
1915 SendMessage(app.hwndTT, TTM_UPDATE, 0, 0);
1919 break;
1920 case WM_RBUTTONDOWN:
1921 // fall through
1922 case WM_LBUTTONDOWN:
1924 break;
1925 case WM_SETFOCUS:
1926 ::SetFocus(app.wBlame);
1927 app.SendEditor(SCI_GRABFOCUS);
1928 break;
1929 case WM_CONTEXTMENU:
1931 if (app.m_selectedrev <= 0)
1932 break;;
1933 int xPos = GET_X_LPARAM(lParam);
1934 int yPos = GET_Y_LPARAM(lParam);
1935 if ((xPos < 0)||(yPos < 0))
1937 // requested from keyboard, not mouse pointer
1938 // use the center of the window
1939 RECT rect;
1940 GetClientRect(app.wBlame, &rect);
1941 xPos = rect.right-rect.left;
1942 yPos = rect.bottom-rect.top;
1944 HMENU hMenu = LoadMenu(app.hResource, MAKEINTRESOURCE(IDR_BLAMEPOPUP));
1945 HMENU hPopMenu = GetSubMenu(hMenu, 0);
1947 if ( _tcslen(szOrigPath)==0 )
1949 // Without knowing the original path we cannot blame the previous revision
1950 // because we don't know which filename to pass to tortoiseproc.
1951 EnableMenuItem(hPopMenu,ID_BLAME_PREVIOUS_REVISION, MF_DISABLED|MF_GRAYED);
1954 TrackPopupMenu(hPopMenu, TPM_LEFTALIGN | TPM_RIGHTBUTTON, xPos, yPos, 0, app.wBlame, NULL);
1955 DestroyMenu(hMenu);
1957 break;
1958 default:
1959 return DefWindowProc(hWnd, message, wParam, lParam);
1961 return 0;
1964 LRESULT CALLBACK WndHeaderProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1966 PAINTSTRUCT ps;
1967 HDC hDC;
1968 switch (message)
1970 case WM_CREATE:
1971 return 0;
1972 case WM_PAINT:
1973 hDC = BeginPaint(app.wHeader, &ps);
1974 app.DrawHeader(hDC);
1975 EndPaint(app.wHeader, &ps);
1976 break;
1977 case WM_COMMAND:
1978 break;
1979 case WM_DESTROY:
1980 break;
1981 case WM_CLOSE:
1982 return 0;
1983 default:
1984 return DefWindowProc(hWnd, message, wParam, lParam);
1986 return 0;
1989 LRESULT CALLBACK WndLocatorProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1991 PAINTSTRUCT ps;
1992 HDC hDC;
1993 switch (message)
1995 case WM_PAINT:
1996 hDC = BeginPaint(app.wLocator, &ps);
1997 app.DrawLocatorBar(hDC);
1998 EndPaint(app.wLocator, &ps);
1999 break;
2000 case WM_LBUTTONDOWN:
2001 case WM_MOUSEMOVE:
2002 if (wParam & MK_LBUTTON)
2004 RECT rect;
2005 ::GetClientRect(hWnd, &rect);
2006 int nLine = HIWORD(lParam)*app.revs.size()/(rect.bottom-rect.top);
2008 if (nLine < 0)
2009 nLine = 0;
2010 app.ScrollToLine(nLine);
2012 break;
2013 default:
2014 return DefWindowProc(hWnd, message, wParam, lParam);
2016 return 0;
2018 #endif
2020 void CTortoiseGitBlameView::SetupLexer(CString filename)
2023 TCHAR *line;
2024 //const char * lineptr = _tcsrchr(filename, '.');
2025 int start=filename.ReverseFind(_T('.'));
2026 if (start>0)
2028 //_tcscpy_s(line, 20, lineptr+1);
2029 //_tcslwr_s(line, 20);
2030 CString ext=filename.Right(filename.GetLength()-start-1);
2031 line=ext.GetBuffer();
2033 if ((_tcscmp(line, _T("py"))==0)||
2034 (_tcscmp(line, _T("pyw"))==0)||
2035 (_tcscmp(line, _T("pyw"))==0))
2037 SendEditor(SCI_SETLEXER, SCLEX_PYTHON);
2038 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("and assert break class continue def del elif \
2039 else except exec finally for from global if import in is lambda None \
2040 not or pass print raise return try while yield")).GetBuffer()));
2041 SetAStyle(SCE_P_DEFAULT, black);
2042 SetAStyle(SCE_P_COMMENTLINE, darkGreen);
2043 SetAStyle(SCE_P_NUMBER, RGB(0, 0x80, 0x80));
2044 SetAStyle(SCE_P_STRING, RGB(0, 0, 0x80));
2045 SetAStyle(SCE_P_CHARACTER, RGB(0, 0, 0x80));
2046 SetAStyle(SCE_P_WORD, RGB(0x80, 0, 0x80));
2047 SetAStyle(SCE_P_TRIPLE, black);
2048 SetAStyle(SCE_P_TRIPLEDOUBLE, black);
2049 SetAStyle(SCE_P_CLASSNAME, darkBlue);
2050 SetAStyle(SCE_P_DEFNAME, darkBlue);
2051 SetAStyle(SCE_P_OPERATOR, darkBlue);
2052 SetAStyle(SCE_P_IDENTIFIER, darkBlue);
2053 SetAStyle(SCE_P_COMMENTBLOCK, darkGreen);
2054 SetAStyle(SCE_P_STRINGEOL, red);
2056 if ((_tcscmp(line, _T("c"))==0)||
2057 (_tcscmp(line, _T("cc"))==0)||
2058 (_tcscmp(line, _T("cpp"))==0)||
2059 (_tcscmp(line, _T("cxx"))==0)||
2060 (_tcscmp(line, _T("h"))==0)||
2061 (_tcscmp(line, _T("hh"))==0)||
2062 (_tcscmp(line, _T("hpp"))==0)||
2063 (_tcscmp(line, _T("hxx"))==0)||
2064 (_tcscmp(line, _T("dlg"))==0)||
2065 (_tcscmp(line, _T("mak"))==0))
2067 SendEditor(SCI_SETLEXER, SCLEX_CPP);
2068 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("and and_eq asm auto bitand bitor bool break \
2069 case catch char class compl const const_cast continue \
2070 default delete do double dynamic_cast else enum explicit export extern false float for \
2071 friend goto if inline int long mutable namespace new not not_eq \
2072 operator or or_eq private protected public \
2073 register reinterpret_cast return short signed sizeof static static_cast struct switch \
2074 template this throw true try typedef typeid typename union unsigned using \
2075 virtual void volatile wchar_t while xor xor_eq")).GetBuffer()));
2076 SendEditor(SCI_SETKEYWORDS, 3, (LPARAM)(m_TextView.StringForControl(_T("a addindex addtogroup anchor arg attention \
2077 author b brief bug c class code date def defgroup deprecated dontinclude \
2078 e em endcode endhtmlonly endif endlatexonly endlink endverbatim enum example exception \
2079 f$ f[ f] file fn hideinitializer htmlinclude htmlonly \
2080 if image include ingroup internal invariant interface latexonly li line link \
2081 mainpage name namespace nosubgrouping note overload \
2082 p page par param post pre ref relates remarks return retval \
2083 sa section see showinitializer since skip skipline struct subsection \
2084 test throw todo typedef union until \
2085 var verbatim verbinclude version warning weakgroup $ @ \\ & < > # { }")).GetBuffer()));
2086 SetupCppLexer();
2088 if (_tcscmp(line, _T("cs"))==0)
2090 SendEditor(SCI_SETLEXER, SCLEX_CPP);
2091 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("abstract as base bool break byte case catch char checked class \
2092 const continue decimal default delegate do double else enum \
2093 event explicit extern false finally fixed float for foreach goto if \
2094 implicit in int interface internal is lock long namespace new null \
2095 object operator out override params private protected public \
2096 readonly ref return sbyte sealed short sizeof stackalloc static \
2097 string struct switch this throw true try typeof uint ulong \
2098 unchecked unsafe ushort using virtual void while")).GetBuffer()));
2099 SetupCppLexer();
2101 if ((_tcscmp(line, _T("rc"))==0)||
2102 (_tcscmp(line, _T("rc2"))==0))
2104 SendEditor(SCI_SETLEXER, SCLEX_CPP);
2105 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("ACCELERATORS ALT AUTO3STATE AUTOCHECKBOX AUTORADIOBUTTON \
2106 BEGIN BITMAP BLOCK BUTTON CAPTION CHARACTERISTICS CHECKBOX CLASS \
2107 COMBOBOX CONTROL CTEXT CURSOR DEFPUSHBUTTON DIALOG DIALOGEX DISCARDABLE \
2108 EDITTEXT END EXSTYLE FONT GROUPBOX ICON LANGUAGE LISTBOX LTEXT \
2109 MENU MENUEX MENUITEM MESSAGETABLE POPUP \
2110 PUSHBUTTON RADIOBUTTON RCDATA RTEXT SCROLLBAR SEPARATOR SHIFT STATE3 \
2111 STRINGTABLE STYLE TEXTINCLUDE VALUE VERSION VERSIONINFO VIRTKEY")).GetBuffer()));
2112 SetupCppLexer();
2114 if ((_tcscmp(line, _T("idl"))==0)||
2115 (_tcscmp(line, _T("odl"))==0))
2117 SendEditor(SCI_SETLEXER, SCLEX_CPP);
2118 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("aggregatable allocate appobject arrays async async_uuid \
2119 auto_handle \
2120 bindable boolean broadcast byte byte_count \
2121 call_as callback char coclass code comm_status \
2122 const context_handle context_handle_noserialize \
2123 context_handle_serialize control cpp_quote custom \
2124 decode default defaultbind defaultcollelem \
2125 defaultvalue defaultvtable dispinterface displaybind dllname \
2126 double dual \
2127 enable_allocate encode endpoint entry enum error_status_t \
2128 explicit_handle \
2129 fault_status first_is float \
2130 handle_t heap helpcontext helpfile helpstring \
2131 helpstringcontext helpstringdll hidden hyper \
2132 id idempotent ignore iid_as iid_is immediatebind implicit_handle \
2133 import importlib in include in_line int __int64 __int3264 interface \
2134 last_is lcid length_is library licensed local long \
2135 max_is maybe message methods midl_pragma \
2136 midl_user_allocate midl_user_free min_is module ms_union \
2137 ncacn_at_dsp ncacn_dnet_nsp ncacn_http ncacn_ip_tcp \
2138 ncacn_nb_ipx ncacn_nb_nb ncacn_nb_tcp ncacn_np \
2139 ncacn_spx ncacn_vns_spp ncadg_ip_udp ncadg_ipx ncadg_mq \
2140 ncalrpc nocode nonbrowsable noncreatable nonextensible notify \
2141 object odl oleautomation optimize optional out out_of_line \
2142 pipe pointer_default pragma properties propget propput propputref \
2143 ptr public \
2144 range readonly ref represent_as requestedit restricted retval \
2145 shape short signed size_is small source strict_context_handle \
2146 string struct switch switch_is switch_type \
2147 transmit_as typedef \
2148 uidefault union unique unsigned user_marshal usesgetlasterror uuid \
2149 v1_enum vararg version void wchar_t wire_marshal")).GetBuffer()));
2150 SetupCppLexer();
2152 if (_tcscmp(line, _T("java"))==0)
2154 SendEditor(SCI_SETLEXER, SCLEX_CPP);
2155 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("abstract assert boolean break byte case catch char class \
2156 const continue default do double else extends final finally float for future \
2157 generic goto if implements import inner instanceof int interface long \
2158 native new null outer package private protected public rest \
2159 return short static super switch synchronized this throw throws \
2160 transient try var void volatile while")).GetBuffer()));
2161 SetupCppLexer();
2163 if (_tcscmp(line, _T("js"))==0)
2165 SendEditor(SCI_SETLEXER, SCLEX_CPP);
2166 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("abstract boolean break byte case catch char class \
2167 const continue debugger default delete do double else enum export extends \
2168 final finally float for function goto if implements import in instanceof \
2169 int interface long native new package private protected public \
2170 return short static super switch synchronized this throw throws \
2171 transient try typeof var void volatile while with")).GetBuffer()));
2172 SetupCppLexer();
2174 if ((_tcscmp(line, _T("pas"))==0)||
2175 (_tcscmp(line, _T("dpr"))==0)||
2176 (_tcscmp(line, _T("pp"))==0))
2178 SendEditor(SCI_SETLEXER, SCLEX_PASCAL);
2179 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("and array as begin case class const constructor \
2180 destructor div do downto else end except file finally \
2181 for function goto if implementation in inherited \
2182 interface is mod not object of on or packed \
2183 procedure program property raise record repeat \
2184 set shl shr then threadvar to try type unit \
2185 until uses var while with xor")).GetBuffer()));
2186 SetupCppLexer();
2188 if ((_tcscmp(line, _T("as"))==0)||
2189 (_tcscmp(line, _T("asc"))==0)||
2190 (_tcscmp(line, _T("jsfl"))==0))
2192 SendEditor(SCI_SETLEXER, SCLEX_CPP);
2193 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("add and break case catch class continue default delete do \
2194 dynamic else eq extends false finally for function ge get gt if implements import in \
2195 instanceof interface intrinsic le lt ne new not null or private public return \
2196 set static super switch this throw true try typeof undefined var void while with")).GetBuffer()));
2197 SendEditor(SCI_SETKEYWORDS, 1, (LPARAM)(m_TextView.StringForControl(_T("Array Arguments Accessibility Boolean Button Camera Color \
2198 ContextMenu ContextMenuItem Date Error Function Key LoadVars LocalConnection Math \
2199 Microphone Mouse MovieClip MovieClipLoader NetConnection NetStream Number Object \
2200 PrintJob Selection SharedObject Sound Stage String StyleSheet System TextField \
2201 TextFormat TextSnapshot Video Void XML XMLNode XMLSocket \
2202 _accProps _focusrect _global _highquality _parent _quality _root _soundbuftime \
2203 arguments asfunction call capabilities chr clearInterval duplicateMovieClip \
2204 escape eval fscommand getProperty getTimer getURL getVersion gotoAndPlay gotoAndStop \
2205 ifFrameLoaded Infinity -Infinity int isFinite isNaN length loadMovie loadMovieNum \
2206 loadVariables loadVariablesNum maxscroll mbchr mblength mbord mbsubstring MMExecute \
2207 NaN newline nextFrame nextScene on onClipEvent onUpdate ord parseFloat parseInt play \
2208 prevFrame prevScene print printAsBitmap printAsBitmapNum printNum random removeMovieClip \
2209 scroll set setInterval setProperty startDrag stop stopAllSounds stopDrag substring \
2210 targetPath tellTarget toggleHighQuality trace unescape unloadMovie unLoadMovieNum updateAfterEvent")).GetBuffer()));
2211 SetupCppLexer();
2213 if ((_tcscmp(line, _T("html"))==0)||
2214 (_tcscmp(line, _T("htm"))==0)||
2215 (_tcscmp(line, _T("shtml"))==0)||
2216 (_tcscmp(line, _T("htt"))==0)||
2217 (_tcscmp(line, _T("xml"))==0)||
2218 (_tcscmp(line, _T("asp"))==0)||
2219 (_tcscmp(line, _T("xsl"))==0)||
2220 (_tcscmp(line, _T("php"))==0)||
2221 (_tcscmp(line, _T("xhtml"))==0)||
2222 (_tcscmp(line, _T("phtml"))==0)||
2223 (_tcscmp(line, _T("cfm"))==0)||
2224 (_tcscmp(line, _T("tpl"))==0)||
2225 (_tcscmp(line, _T("dtd"))==0)||
2226 (_tcscmp(line, _T("hta"))==0)||
2227 (_tcscmp(line, _T("htd"))==0)||
2228 (_tcscmp(line, _T("wxs"))==0))
2230 SendEditor(SCI_SETLEXER, SCLEX_HTML);
2231 SendEditor(SCI_SETSTYLEBITS, 7);
2232 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("a abbr acronym address applet area b base basefont \
2233 bdo big blockquote body br button caption center \
2234 cite code col colgroup dd del dfn dir div dl dt em \
2235 fieldset font form frame frameset h1 h2 h3 h4 h5 h6 \
2236 head hr html i iframe img input ins isindex kbd label \
2237 legend li link map menu meta noframes noscript \
2238 object ol optgroup option p param pre q s samp \
2239 script select small span strike strong style sub sup \
2240 table tbody td textarea tfoot th thead title tr tt u ul \
2241 var xml xmlns abbr accept-charset accept accesskey action align alink \
2242 alt archive axis background bgcolor border \
2243 cellpadding cellspacing char charoff charset checked cite \
2244 class classid clear codebase codetype color cols colspan \
2245 compact content coords \
2246 data datafld dataformatas datapagesize datasrc datetime \
2247 declare defer dir disabled enctype event \
2248 face for frame frameborder \
2249 headers height href hreflang hspace http-equiv \
2250 id ismap label lang language leftmargin link longdesc \
2251 marginwidth marginheight maxlength media method multiple \
2252 name nohref noresize noshade nowrap \
2253 object onblur onchange onclick ondblclick onfocus \
2254 onkeydown onkeypress onkeyup onload onmousedown \
2255 onmousemove onmouseover onmouseout onmouseup \
2256 onreset onselect onsubmit onunload \
2257 profile prompt readonly rel rev rows rowspan rules \
2258 scheme scope selected shape size span src standby start style \
2259 summary tabindex target text title topmargin type usemap \
2260 valign value valuetype version vlink vspace width \
2261 text password checkbox radio submit reset \
2262 file hidden image")).GetBuffer()));
2263 SendEditor(SCI_SETKEYWORDS, 1, (LPARAM)(m_TextView.StringForControl(_T("assign audio block break catch choice clear disconnect else elseif \
2264 emphasis enumerate error exit field filled form goto grammar help \
2265 if initial link log menu meta noinput nomatch object option p paragraph \
2266 param phoneme prompt property prosody record reprompt return s say-as \
2267 script sentence subdialog submit throw transfer value var voice vxml")).GetBuffer()));
2268 SendEditor(SCI_SETKEYWORDS, 2, (LPARAM)(m_TextView.StringForControl(_T("accept age alphabet anchor application base beep bridge category charset \
2269 classid cond connecttimeout content contour count dest destexpr dtmf dtmfterm \
2270 duration enctype event eventexpr expr expritem fetchtimeout finalsilence \
2271 gender http-equiv id level maxage maxstale maxtime message messageexpr \
2272 method mime modal mode name namelist next nextitem ph pitch range rate \
2273 scope size sizeexpr skiplist slot src srcexpr sub time timeexpr timeout \
2274 transferaudio type value variant version volume xml:lang")).GetBuffer()));
2275 SendEditor(SCI_SETKEYWORDS, 3, (LPARAM)(m_TextView.StringForControl(_T("and assert break class continue def del elif \
2276 else except exec finally for from global if import in is lambda None \
2277 not or pass print raise return try while yield")).GetBuffer()));
2278 SendEditor(SCI_SETKEYWORDS, 4, (LPARAM)(m_TextView.StringForControl(_T("and argv as argc break case cfunction class continue declare default do \
2279 die echo else elseif empty enddeclare endfor endforeach endif endswitch \
2280 endwhile e_all e_parse e_error e_warning eval exit extends false for \
2281 foreach function global http_cookie_vars http_get_vars http_post_vars \
2282 http_post_files http_env_vars http_server_vars if include include_once \
2283 list new not null old_function or parent php_os php_self php_version \
2284 print require require_once return static switch stdclass this true var \
2285 xor virtual while __file__ __line__ __sleep __wakeup")).GetBuffer()));
2287 SetAStyle(SCE_H_TAG, darkBlue);
2288 SetAStyle(SCE_H_TAGUNKNOWN, red);
2289 SetAStyle(SCE_H_ATTRIBUTE, darkBlue);
2290 SetAStyle(SCE_H_ATTRIBUTEUNKNOWN, red);
2291 SetAStyle(SCE_H_NUMBER, RGB(0x80,0,0x80));
2292 SetAStyle(SCE_H_DOUBLESTRING, RGB(0,0x80,0));
2293 SetAStyle(SCE_H_SINGLESTRING, RGB(0,0x80,0));
2294 SetAStyle(SCE_H_OTHER, RGB(0x80,0,0x80));
2295 SetAStyle(SCE_H_COMMENT, RGB(0x80,0x80,0));
2296 SetAStyle(SCE_H_ENTITY, RGB(0x80,0,0x80));
2298 SetAStyle(SCE_H_TAGEND, darkBlue);
2299 SetAStyle(SCE_H_XMLSTART, darkBlue); // <?
2300 SetAStyle(SCE_H_QUESTION, darkBlue); // <?
2301 SetAStyle(SCE_H_XMLEND, darkBlue); // ?>
2302 SetAStyle(SCE_H_SCRIPT, darkBlue); // <script
2303 SetAStyle(SCE_H_ASP, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <% ... %>
2304 SetAStyle(SCE_H_ASPAT, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <%@ ... %>
2306 SetAStyle(SCE_HB_DEFAULT, black);
2307 SetAStyle(SCE_HB_COMMENTLINE, darkGreen);
2308 SetAStyle(SCE_HB_NUMBER, RGB(0,0x80,0x80));
2309 SetAStyle(SCE_HB_WORD, darkBlue);
2310 SendEditor(SCI_STYLESETBOLD, SCE_HB_WORD, 1);
2311 SetAStyle(SCE_HB_STRING, RGB(0x80,0,0x80));
2312 SetAStyle(SCE_HB_IDENTIFIER, black);
2314 // This light blue is found in the windows system palette so is safe to use even in 256 colour modes.
2315 // Show the whole section of VBScript with light blue background
2316 for (int bstyle=SCE_HB_DEFAULT; bstyle<=SCE_HB_STRINGEOL; bstyle++) {
2317 SendEditor(SCI_STYLESETFONT, bstyle,
2318 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
2319 SendEditor(SCI_STYLESETBACK, bstyle, lightBlue);
2320 // This call extends the backround colour of the last style on the line to the edge of the window
2321 SendEditor(SCI_STYLESETEOLFILLED, bstyle, 1);
2323 SendEditor(SCI_STYLESETBACK, SCE_HB_STRINGEOL, RGB(0x7F,0x7F,0xFF));
2324 SendEditor(SCI_STYLESETFONT, SCE_HB_COMMENTLINE,
2325 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
2327 SetAStyle(SCE_HBA_DEFAULT, black);
2328 SetAStyle(SCE_HBA_COMMENTLINE, darkGreen);
2329 SetAStyle(SCE_HBA_NUMBER, RGB(0,0x80,0x80));
2330 SetAStyle(SCE_HBA_WORD, darkBlue);
2331 SendEditor(SCI_STYLESETBOLD, SCE_HBA_WORD, 1);
2332 SetAStyle(SCE_HBA_STRING, RGB(0x80,0,0x80));
2333 SetAStyle(SCE_HBA_IDENTIFIER, black);
2335 // Show the whole section of ASP VBScript with bright yellow background
2336 for (int bastyle=SCE_HBA_DEFAULT; bastyle<=SCE_HBA_STRINGEOL; bastyle++) {
2337 SendEditor(SCI_STYLESETFONT, bastyle,
2338 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
2339 SendEditor(SCI_STYLESETBACK, bastyle, RGB(0xFF, 0xFF, 0));
2340 // This call extends the backround colour of the last style on the line to the edge of the window
2341 SendEditor(SCI_STYLESETEOLFILLED, bastyle, 1);
2343 SendEditor(SCI_STYLESETBACK, SCE_HBA_STRINGEOL, RGB(0xCF,0xCF,0x7F));
2344 SendEditor(SCI_STYLESETFONT, SCE_HBA_COMMENTLINE,
2345 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
2347 // If there is no need to support embedded Javascript, the following code can be dropped.
2348 // Javascript will still be correctly processed but will be displayed in just the default style.
2350 SetAStyle(SCE_HJ_START, RGB(0x80,0x80,0));
2351 SetAStyle(SCE_HJ_DEFAULT, black);
2352 SetAStyle(SCE_HJ_COMMENT, darkGreen);
2353 SetAStyle(SCE_HJ_COMMENTLINE, darkGreen);
2354 SetAStyle(SCE_HJ_COMMENTDOC, darkGreen);
2355 SetAStyle(SCE_HJ_NUMBER, RGB(0,0x80,0x80));
2356 SetAStyle(SCE_HJ_WORD, black);
2357 SetAStyle(SCE_HJ_KEYWORD, darkBlue);
2358 SetAStyle(SCE_HJ_DOUBLESTRING, RGB(0x80,0,0x80));
2359 SetAStyle(SCE_HJ_SINGLESTRING, RGB(0x80,0,0x80));
2360 SetAStyle(SCE_HJ_SYMBOLS, black);
2362 SetAStyle(SCE_HJA_START, RGB(0x80,0x80,0));
2363 SetAStyle(SCE_HJA_DEFAULT, black);
2364 SetAStyle(SCE_HJA_COMMENT, darkGreen);
2365 SetAStyle(SCE_HJA_COMMENTLINE, darkGreen);
2366 SetAStyle(SCE_HJA_COMMENTDOC, darkGreen);
2367 SetAStyle(SCE_HJA_NUMBER, RGB(0,0x80,0x80));
2368 SetAStyle(SCE_HJA_WORD, black);
2369 SetAStyle(SCE_HJA_KEYWORD, darkBlue);
2370 SetAStyle(SCE_HJA_DOUBLESTRING, RGB(0x80,0,0x80));
2371 SetAStyle(SCE_HJA_SINGLESTRING, RGB(0x80,0,0x80));
2372 SetAStyle(SCE_HJA_SYMBOLS, black);
2374 SetAStyle(SCE_HPHP_DEFAULT, black);
2375 SetAStyle(SCE_HPHP_HSTRING, RGB(0x80,0,0x80));
2376 SetAStyle(SCE_HPHP_SIMPLESTRING, RGB(0x80,0,0x80));
2377 SetAStyle(SCE_HPHP_WORD, darkBlue);
2378 SetAStyle(SCE_HPHP_NUMBER, RGB(0,0x80,0x80));
2379 SetAStyle(SCE_HPHP_VARIABLE, red);
2380 SetAStyle(SCE_HPHP_HSTRING_VARIABLE, red);
2381 SetAStyle(SCE_HPHP_COMPLEX_VARIABLE, red);
2382 SetAStyle(SCE_HPHP_COMMENT, darkGreen);
2383 SetAStyle(SCE_HPHP_COMMENTLINE, darkGreen);
2384 SetAStyle(SCE_HPHP_OPERATOR, darkBlue);
2386 // Show the whole section of Javascript with off white background
2387 for (int jstyle=SCE_HJ_DEFAULT; jstyle<=SCE_HJ_SYMBOLS; jstyle++) {
2388 SendEditor(SCI_STYLESETFONT, jstyle,
2389 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
2390 SendEditor(SCI_STYLESETBACK, jstyle, offWhite);
2391 SendEditor(SCI_STYLESETEOLFILLED, jstyle, 1);
2393 SendEditor(SCI_STYLESETBACK, SCE_HJ_STRINGEOL, RGB(0xDF, 0xDF, 0x7F));
2394 SendEditor(SCI_STYLESETEOLFILLED, SCE_HJ_STRINGEOL, 1);
2396 // Show the whole section of Javascript with brown background
2397 for (int jastyle=SCE_HJA_DEFAULT; jastyle<=SCE_HJA_SYMBOLS; jastyle++) {
2398 SendEditor(SCI_STYLESETFONT, jastyle,
2399 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
2400 SendEditor(SCI_STYLESETBACK, jastyle, RGB(0xDF, 0xDF, 0x7F));
2401 SendEditor(SCI_STYLESETEOLFILLED, jastyle, 1);
2403 SendEditor(SCI_STYLESETBACK, SCE_HJA_STRINGEOL, RGB(0x0,0xAF,0x5F));
2404 SendEditor(SCI_STYLESETEOLFILLED, SCE_HJA_STRINGEOL, 1);
2407 else
2409 SendEditor(SCI_SETLEXER, SCLEX_CPP);
2410 SetupCppLexer();
2412 SendEditor(SCI_COLOURISE, 0, -1);
2416 void CTortoiseGitBlameView::SetupCppLexer()
2418 SetAStyle(SCE_C_DEFAULT, RGB(0, 0, 0));
2419 SetAStyle(SCE_C_COMMENT, RGB(0, 0x80, 0));
2420 SetAStyle(SCE_C_COMMENTLINE, RGB(0, 0x80, 0));
2421 SetAStyle(SCE_C_COMMENTDOC, RGB(0, 0x80, 0));
2422 SetAStyle(SCE_C_COMMENTLINEDOC, RGB(0, 0x80, 0));
2423 SetAStyle(SCE_C_COMMENTDOCKEYWORD, RGB(0, 0x80, 0));
2424 SetAStyle(SCE_C_COMMENTDOCKEYWORDERROR, RGB(0, 0x80, 0));
2425 SetAStyle(SCE_C_NUMBER, RGB(0, 0x80, 0x80));
2426 SetAStyle(SCE_C_WORD, RGB(0, 0, 0x80));
2427 SendEditor(SCE_C_WORD, 1);
2428 SetAStyle(SCE_C_STRING, RGB(0x80, 0, 0x80));
2429 SetAStyle(SCE_C_IDENTIFIER, RGB(0, 0, 0));
2430 SetAStyle(SCE_C_PREPROCESSOR, RGB(0x80, 0, 0));
2431 SetAStyle(SCE_C_OPERATOR, RGB(0x80, 0x80, 0));
2435 void CTortoiseGitBlameView::UpdateInfo()
2437 CString &data = GetDocument()->m_BlameData;
2438 CString one;
2439 int pos=0;
2441 CLogDataVector * pRevs= GetLogData();
2443 this->m_CommitHash.clear();
2444 this->m_Authors.clear();
2445 this->m_ID.clear();
2446 CString line;
2448 CreateFont();
2450 SendEditor(SCI_SETREADONLY, FALSE);
2451 SendEditor(SCI_CLEARALL);
2452 SendEditor(EM_EMPTYUNDOBUFFER);
2453 SendEditor(SCI_SETSAVEPOINT);
2454 SendEditor(SCI_CANCEL);
2455 SendEditor(SCI_SETUNDOCOLLECTION, 0);
2457 while( pos>=0 )
2459 one=data.Tokenize(_T("\n"),pos);
2460 if(one.IsEmpty())
2461 continue;
2462 m_CommitHash.push_back(one.Left(40));
2463 int start=0;
2464 start=one.Find(_T(')'),40);
2465 if(start>0)
2467 line=one.Right(one.GetLength()-start-2);
2468 this->m_TextView.InsertText(line,true);
2470 int id=pRevs->m_HashMap[one.Left(40)];
2471 if(id>=0 && id <GetLogData()->size())
2473 m_ID.push_back(pRevs->size()-id);
2474 m_Authors.push_back(pRevs->at(id).m_AuthorName);
2475 }else
2477 ASSERT(FALSE);
2481 SetupLexer(GetDocument()->m_CurrentFileName);
2483 SendEditor(SCI_SETUNDOCOLLECTION, 1);
2484 SendEditor(EM_EMPTYUNDOBUFFER);
2485 SendEditor(SCI_SETSAVEPOINT);
2486 SendEditor(SCI_GOTOPOS, 0);
2487 SendEditor(SCI_SETSCROLLWIDTHTRACKING, TRUE);
2488 SendEditor(SCI_SETREADONLY, TRUE);
2490 m_lowestrev=1;
2491 m_highestrev=this->GetLogData()->size();
2493 GetBlameWidth();
2494 CRect rect;
2495 this->GetClientRect(rect);
2496 //this->m_TextView.GetWindowRect(rect);
2497 //this->m_TextView.ScreenToClient(rect);
2498 rect.left=this->m_blamewidth;
2499 this->m_TextView.MoveWindow(rect);
2501 this->Invalidate();
2504 CGitBlameLogList * CTortoiseGitBlameView::GetLogList()
2506 return &(GetDocument()->GetMainFrame()->m_wndOutput.m_LogList);
2510 CLogDataVector * CTortoiseGitBlameView::GetLogData()
2512 return &(GetDocument()->GetMainFrame()->m_wndOutput.m_LogList.m_logEntries);
2515 void CTortoiseGitBlameView::OnSciPainted(NMHDR *,LRESULT *)
2517 this->Invalidate();
2520 void CTortoiseGitBlameView::OnLButtonDown(UINT nFlags,CPoint point)
2523 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
2524 LONG_PTR height = SendEditor(SCI_TEXTHEIGHT);
2525 line = line + (point.y/height);
2527 if (line < (LONG)m_CommitHash.size())
2529 SetSelectedLine(line);
2530 if (m_CommitHash[line] != m_SelectedHash)
2532 m_SelectedHash = m_CommitHash[line];
2533 // app.m_selectedorigrev = app.origrevs[line];
2534 // app.m_selectedauthor = app.authors[line];
2535 // app.m_selecteddate = app.dates[line];
2538 this->GetLogList()->SetItemState(this->GetLogList()->GetItemCount()-m_ID[line],
2539 LVIS_SELECTED,
2540 LVIS_SELECTED);
2542 GitRev *pRev;
2543 pRev=&this->GetLogData()->at(this->GetLogList()->GetItemCount()-m_ID[line]);
2544 this->GetDocument()->GetMainFrame()->m_wndProperties.UpdateProperties(pRev);
2546 else
2548 m_SelectedHash.Empty();
2549 // app.m_selecteddate.clear();
2550 // app.m_selectedrev = -2;
2551 // app.m_selectedorigrev = -2;
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();
2590 this->m_TextView.Invalidate();
2594 void CTortoiseGitBlameView::OnMouseHover(UINT nFlags, CPoint point)
2597 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
2598 LONG_PTR height = SendEditor(SCI_TEXTHEIGHT);
2599 line = line + (point.y/height);
2601 if (line < (LONG)m_CommitHash.size())
2603 if (line != m_MouseLine)
2605 m_MouseLine = line;//m_CommitHash[line];
2606 // app.m_selectedorigrev = app.origrevs[line];
2607 // app.m_selectedauthor = app.authors[line];
2608 // app.m_selecteddate = app.dates[line];
2611 GitRev *pRev;
2612 pRev=&this->GetLogData()->at(this->GetLogList()->GetItemCount()-m_ID[line]);
2613 //this->GetDocument()->GetMainFrame()->m_wndProperties.UpdateProperties(pRev);
2614 this->ClientToScreen(&point);
2615 //BALLOON_INFO bi;
2616 //if(m_ToolTip.GetTool(this, bi))
2618 // bi.sBalloonTip=pRev->m_CommitHash;
2619 CString str;
2620 str.Format(_T("%s\n<b>%s</b>\n%s\n%s"),pRev->m_CommitHash,
2621 pRev->m_Subject,
2622 pRev->m_AuthorDate.Format(_T("%Y-%m-%d %H:%M")),
2623 pRev->m_Body);
2624 m_ToolTip.AddTool(this,str);
2625 m_ToolTip.DisplayToolTip(&point);
2628 CRect rect;
2629 this->ScreenToClient(&point);
2630 rect.left=LOCATOR_WIDTH;
2631 rect.right=this->m_blamewidth+rect.left;
2632 rect.top=point.y-height;
2633 rect.bottom=point.y+height;
2634 this->InvalidateRect(rect);
2637 else
2639 m_MouseLine=-1;
2640 // app.m_selecteddate.clear();
2641 // app.m_selectedrev = -2;
2642 // app.m_selectedorigrev = -2;
2644 //::InvalidateRect( NULL, FALSE);
2645 //this->Invalidate();
2648 // const CString str=_T("this is a <b>Message Balloon</b>\n<hr=100%>\n<ct=0x0000FF>Warning! Warning!</ct>\nSomething unexpected happened");
2649 //CBalloon::ShowBalloon(NULL, point,
2650 // str,
2651 // FALSE, (HICON)IDI_EXCLAMATION,
2652 // (UINT)CBalloon ::BALLOON_RIGHT_TOP, (UINT)CBalloon ::BALLOON_EFFECT_SOLID,(COLORREF)NULL, (COLORREF)NULL, (COLORREF)NULL);
2655 void CTortoiseGitBlameView::OnMouseMove(UINT nFlags, CPoint point)
2657 TRACKMOUSEEVENT tme;
2658 tme.cbSize=sizeof(TRACKMOUSEEVENT);
2659 tme.dwFlags=TME_HOVER|TME_LEAVE;
2660 tme.hwndTrack=this->m_hWnd;
2661 tme.dwHoverTime=1;
2662 TrackMouseEvent(&tme);
2666 BOOL CTortoiseGitBlameView::PreTranslateMessage(MSG* pMsg)
2668 m_ToolTip.RelayEvent(pMsg);
2669 return CView::PreTranslateMessage(pMsg);
2672 void CTortoiseGitBlameView::OnEditFind()
2674 m_pFindDialog=new CFindReplaceDialog();
2676 m_pFindDialog->Create(TRUE,_T(""),NULL,FR_DOWN,this);
2679 void CTortoiseGitBlameView::OnEditGoto()
2681 CEditGotoDlg dlg;
2682 if(dlg.DoModal()==IDOK)
2684 this->GotoLine(dlg.m_LineNumber);
2688 LRESULT CTortoiseGitBlameView::OnFindDialogMessage(WPARAM wParam, LPARAM lParam)//Õâ¸öÒ²ÊÇÕÒÄǸö³ÌÐò¸ÄµÄ£¬Ö»²»¹ý»»³ÉÁË×Ô¼ºµÄÀà
2690 ASSERT(m_pFindDialog != NULL);
2692 // If the FR_DIALOGTERM flag is set,
2693 // invalidate the handle identifying the dialog box.
2694 if (m_pFindDialog->IsTerminating())
2696 m_pFindDialog = NULL;
2697 return 0;
2700 // If the FR_FINDNEXT flag is set,
2701 // call the application-defined search routine
2702 // to search for the requested string.
2703 if(m_pFindDialog->FindNext())
2705 //read data from dialog
2706 CString FindName = m_pFindDialog->GetFindString();
2707 bool bMatchCase = m_pFindDialog->MatchCase() == TRUE;
2708 bool bMatchWholeWord = m_pFindDialog->MatchWholeWord() == TRUE;
2709 bool bSearchDown = m_pFindDialog->SearchDown() == TRUE;
2711 DoSearch(FindName,m_pFindDialog->m_fr.Flags);
2712 //with given name do search
2713 // *FindWhatYouNeed(FindName, bMatchCase, bMatchWholeWord, bSearchDown);
2716 return 0;