Add Command Line Argument to select blame version.
[TortoiseGit.git] / src / TortoiseGitBlame / TortoiseGitBlameView.cpp
blob4653405a850fdf85364c74a06baef4d81a29c80f
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_COMMAND(ID_EDIT_COPY,CopySelectedLogToClipboard)
49 ON_WM_CREATE()
50 ON_WM_SIZE()
51 ON_WM_MOUSEMOVE()
52 ON_WM_MOUSEHOVER()
53 ON_WM_MOUSELEAVE()
54 ON_WM_LBUTTONDOWN()
55 ON_WM_RBUTTONDOWN()
56 ON_NOTIFY(SCN_PAINTED,0,OnSciPainted)
57 ON_NOTIFY(SCN_GETBKCOLOR,0,OnSciGetBkColor)
58 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
59 END_MESSAGE_MAP()
62 // CTortoiseGitBlameView construction/destruction
64 CTortoiseGitBlameView::CTortoiseGitBlameView()
66 // TODO: add construction code here
67 hInstance = 0;
68 hResource = 0;
69 currentDialog = 0;
70 wMain = 0;
71 m_wEditor = 0;
72 wLocator = 0;
74 m_font = 0;
75 m_italicfont = 0;
76 m_blamewidth = 0;
77 m_revwidth = 0;
78 m_datewidth = 0;
79 m_authorwidth = 0;
80 m_pathwidth = 0;
81 m_linewidth = 0;
83 m_windowcolor = ::GetSysColor(COLOR_WINDOW);
84 m_textcolor = ::GetSysColor(COLOR_WINDOWTEXT);
85 m_texthighlightcolor = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
86 m_mouserevcolor = InterColor(m_windowcolor, m_textcolor, 20);
87 m_mouseauthorcolor = InterColor(m_windowcolor, m_textcolor, 10);
88 m_selectedrevcolor = ::GetSysColor(COLOR_HIGHLIGHT);
89 m_selectedauthorcolor = InterColor(m_selectedrevcolor, m_texthighlightcolor, 35);
90 m_mouserev = -2;
92 m_selectedrev = -1;
93 m_selectedorigrev = -1;
94 m_SelectedLine = -1;
95 m_directPointer = 0;
96 m_directFunction = 0;
98 m_lowestrev = LONG_MAX;
99 m_highestrev = 0;
100 m_colorage = true;
102 m_bShowLine=true;
104 m_bShowAuthor=true;
105 m_bShowDate=false;
107 m_FindDialogMessage = ::RegisterWindowMessage(FINDMSGSTRING);
108 m_pFindDialog = NULL;
111 CTortoiseGitBlameView::~CTortoiseGitBlameView()
113 if (m_font)
114 DeleteObject(m_font);
115 if (m_italicfont)
116 DeleteObject(m_italicfont);
120 int CTortoiseGitBlameView::OnCreate(LPCREATESTRUCT lpcs)
123 CRect rect,rect1;
124 this->GetWindowRect(&rect1);
125 rect.left=m_blamewidth+LOCATOR_WIDTH;
126 rect.right=rect.Width();
127 rect.top=0;
128 rect.bottom=rect.Height();
129 BOOL b=m_TextView.Create(_T("Scintilla"),_T("source"),0,rect,this,0,0);
130 m_TextView.Init(0);
131 m_TextView.ShowWindow( SW_SHOW);
132 //m_TextView.InsertText(_T("Abdadfasdf"));
133 m_wEditor = m_TextView.m_hWnd;
134 CreateFont();
135 InitialiseEditor();
136 m_ToolTip.Create(this->GetParent());
137 m_ToolTip.AddTool(this,_T("Test"));
139 ::AfxGetApp()->GetMainWnd();
140 return CView::OnCreate(lpcs);
144 void CTortoiseGitBlameView::OnSize(UINT nType,int cx, int cy)
147 CRect rect;
148 rect.left=m_blamewidth;
149 rect.right=cx;
150 rect.top=0;
151 rect.bottom=cy;
153 m_TextView.MoveWindow(&rect);
156 BOOL CTortoiseGitBlameView::PreCreateWindow(CREATESTRUCT& cs)
158 // TODO: Modify the Window class or styles here by modifying
159 // the CREATESTRUCT cs
161 return CView::PreCreateWindow(cs);
164 // CTortoiseGitBlameView drawing
166 void CTortoiseGitBlameView::OnDraw(CDC* /*pDC*/)
168 CTortoiseGitBlameDoc* pDoc = GetDocument();
169 ASSERT_VALID(pDoc);
170 if (!pDoc)
171 return;
173 DrawBlame(this->GetDC()->m_hDC);
174 DrawLocatorBar(this->GetDC()->m_hDC);
175 // TODO: add draw code for native data here
179 // CTortoiseGitBlameView printing
182 void CTortoiseGitBlameView::OnFilePrintPreview()
184 AFXPrintPreview(this);
187 BOOL CTortoiseGitBlameView::OnPreparePrinting(CPrintInfo* pInfo)
189 // default preparation
190 return DoPreparePrinting(pInfo);
193 void CTortoiseGitBlameView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
195 // TODO: add extra initialization before printing
198 void CTortoiseGitBlameView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
200 // TODO: add cleanup after printing
203 void CTortoiseGitBlameView::OnRButtonUp(UINT nFlags, CPoint point)
205 ClientToScreen(&point);
206 OnContextMenu(this, point);
209 void CTortoiseGitBlameView::OnContextMenu(CWnd* pWnd, CPoint point)
211 theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE);
215 // CTortoiseGitBlameView diagnostics
217 #ifdef _DEBUG
218 void CTortoiseGitBlameView::AssertValid() const
220 CView::AssertValid();
223 void CTortoiseGitBlameView::Dump(CDumpContext& dc) const
225 CView::Dump(dc);
228 CTortoiseGitBlameDoc* CTortoiseGitBlameView::GetDocument() const // non-debug version is inline
230 ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTortoiseGitBlameDoc)));
231 return (CTortoiseGitBlameDoc*)m_pDocument;
233 #endif //_DEBUG
236 // CTortoiseGitBlameView message handlers
237 CString CTortoiseGitBlameView::GetAppDirectory()
239 CString path;
240 DWORD len = 0;
241 DWORD bufferlen = MAX_PATH; // MAX_PATH is not the limit here!
244 bufferlen += MAX_PATH; // MAX_PATH is not the limit here!
245 TCHAR * pBuf = new TCHAR[bufferlen];
246 len = GetModuleFileName(NULL, pBuf, bufferlen);
247 path = CString(pBuf, len);
248 delete [] pBuf;
249 } while(len == bufferlen);
251 path = path.Left(path.ReverseFind(_T('\\')));
252 //path = path.substr(0, path.rfind('\\') + 1);
254 return path;
257 // Return a color which is interpolated between c1 and c2.
258 // Slider controls the relative proportions as a percentage:
259 // Slider = 0 represents pure c1
260 // Slider = 50 represents equal mixture
261 // Slider = 100 represents pure c2
262 COLORREF CTortoiseGitBlameView::InterColor(COLORREF c1, COLORREF c2, int Slider)
264 int r, g, b;
266 // Limit Slider to 0..100% range
267 if (Slider < 0)
268 Slider = 0;
269 if (Slider > 100)
270 Slider = 100;
272 // The color components have to be treated individually.
273 r = (GetRValue(c2) * Slider + GetRValue(c1) * (100 - Slider)) / 100;
274 g = (GetGValue(c2) * Slider + GetGValue(c1) * (100 - Slider)) / 100;
275 b = (GetBValue(c2) * Slider + GetBValue(c1) * (100 - Slider)) / 100;
277 return RGB(r, g, b);
280 LRESULT CTortoiseGitBlameView::SendEditor(UINT Msg, WPARAM wParam, LPARAM lParam)
282 if (m_directFunction)
284 return ((SciFnDirect) m_directFunction)(m_directPointer, Msg, wParam, lParam);
286 return ::SendMessage(m_wEditor, Msg, wParam, lParam);
289 void CTortoiseGitBlameView::GetRange(int start, int end, char *text)
291 #if 0
292 TEXTRANGE tr;
293 tr.chrg.cpMin = start;
294 tr.chrg.cpMax = end;
295 tr.lpstrText = text;
297 SendMessage(m_wEditor, EM_GETTEXTRANGE, 0, reinterpret_cast<LPARAM>(&tr));
298 #endif
301 void CTortoiseGitBlameView::SetTitle()
303 #if 0
304 char title[MAX_PATH + 100];
305 strcpy_s(title, MAX_PATH + 100, szTitle);
306 strcat_s(title, MAX_PATH + 100, " - ");
307 strcat_s(title, MAX_PATH + 100, szViewtitle);
308 ::SetWindowText(wMain, title);
309 #endif
312 BOOL CTortoiseGitBlameView::OpenLogFile(const char *fileName)
314 #if 0
315 char logmsgbuf[10000+1];
316 FILE * File;
317 fopen_s(&File, fileName, "rb");
318 if (File == 0)
320 return FALSE;
322 LONG rev = 0;
323 CString msg;
324 int slength = 0;
325 int reallength = 0;
326 size_t len = 0;
327 wchar_t wbuf[MAX_LOG_LENGTH+6];
328 for (;;)
330 len = fread(&rev, sizeof(LONG), 1, File);
331 if (len == 0)
333 fclose(File);
334 InitSize();
335 return TRUE;
337 len = fread(&slength, sizeof(int), 1, File);
338 if (len == 0)
340 fclose(File);
341 InitSize();
342 return FALSE;
344 if (slength > MAX_LOG_LENGTH)
346 reallength = slength;
347 slength = MAX_LOG_LENGTH;
349 else
350 reallength = 0;
351 len = fread(logmsgbuf, sizeof(char), slength, File);
352 if (len < (size_t)slength)
354 fclose(File);
355 InitSize();
356 return FALSE;
358 msg = CString(logmsgbuf, slength);
359 if (reallength)
361 fseek(File, reallength-MAX_LOG_LENGTH, SEEK_CUR);
362 msg = msg + _T("\n...");
364 int len2 = ::MultiByteToWideChar(CP_UTF8, NULL, msg.c_str(), min(msg.size(), MAX_LOG_LENGTH+5), wbuf, MAX_LOG_LENGTH+5);
365 wbuf[len2] = 0;
366 len2 = ::WideCharToMultiByte(CP_ACP, NULL, wbuf, len2, logmsgbuf, MAX_LOG_LENGTH+5, NULL, NULL);
367 logmsgbuf[len2] = 0;
368 msg = CString(logmsgbuf);
369 logmessages[rev] = msg;
371 #endif
372 return TRUE;
375 BOOL CTortoiseGitBlameView::OpenFile(const char *fileName)
377 #if 0
378 SendEditor(SCI_SETREADONLY, FALSE);
379 SendEditor(SCI_CLEARALL);
380 SendEditor(EM_EMPTYUNDOBUFFER);
381 SetTitle();
382 SendEditor(SCI_SETSAVEPOINT);
383 SendEditor(SCI_CANCEL);
384 SendEditor(SCI_SETUNDOCOLLECTION, 0);
385 ::ShowWindow(m_wEditor, SW_HIDE);
386 std::ifstream File;
387 File.open(fileName);
388 if (!File.good())
390 return FALSE;
392 char line[100*1024];
393 char * lineptr = NULL;
394 char * trimptr = NULL;
395 //ignore the first two lines, they're of no interest to us
396 File.getline(line, sizeof(line)/sizeof(char));
397 File.getline(line, sizeof(line)/sizeof(char));
398 m_lowestrev = LONG_MAX;
399 m_highestrev = 0;
400 bool bUTF8 = true;
403 File.getline(line, sizeof(line)/sizeof(TCHAR));
404 if (File.gcount()>139)
406 mergelines.push_back((line[0] != ' '));
407 lineptr = &line[9];
408 long rev = _ttol(lineptr);
409 revs.push_back(rev);
410 m_lowestrev = min(m_lowestrev, rev);
411 m_highestrev = max(m_highestrev, rev);
412 lineptr += 7;
413 rev = _ttol(lineptr);
414 origrevs.push_back(rev);
415 lineptr += 7;
416 dates.push_back(CString(lineptr, 30));
417 lineptr += 31;
418 // unfortunately, the 'path' entry can be longer than the 60 chars
419 // we made the column. We therefore have to step through the path
420 // string until we find a space
421 trimptr = lineptr;
424 // TODO: how can we deal with the situation where the path has
425 // a space in it, but the space is after the 60 chars reserved
426 // for it?
427 // The only way to deal with that would be to use a custom
428 // binary format for the blame file.
429 trimptr++;
430 trimptr = _tcschr(trimptr, ' ');
431 } while ((trimptr)&&(trimptr+1 < lineptr+61));
432 if (trimptr)
433 *trimptr = 0;
434 else
435 trimptr = lineptr;
436 paths.push_back(CString(lineptr));
437 if (trimptr+1 < lineptr+61)
438 lineptr +=61;
439 else
440 lineptr = (trimptr+1);
441 trimptr = lineptr+30;
442 while ((*trimptr == ' ')&&(trimptr > lineptr))
443 trimptr--;
444 *(trimptr+1) = 0;
445 authors.push_back(CString(lineptr));
446 lineptr += 31;
447 // in case we find an UTF8 BOM at the beginning of the line, we remove it
448 if (((unsigned char)lineptr[0] == 0xEF)&&((unsigned char)lineptr[1] == 0xBB)&&((unsigned char)lineptr[2] == 0xBF))
450 lineptr += 3;
452 if (((unsigned char)lineptr[0] == 0xBB)&&((unsigned char)lineptr[1] == 0xEF)&&((unsigned char)lineptr[2] == 0xBF))
454 lineptr += 3;
456 // check each line for illegal utf8 sequences. If one is found, we treat
457 // the file as ASCII, otherwise we assume an UTF8 file.
458 char * utf8CheckBuf = lineptr;
459 while ((bUTF8)&&(*utf8CheckBuf))
461 if ((*utf8CheckBuf == 0xC0)||(*utf8CheckBuf == 0xC1)||(*utf8CheckBuf >= 0xF5))
463 bUTF8 = false;
464 break;
466 if ((*utf8CheckBuf & 0xE0)==0xC0)
468 utf8CheckBuf++;
469 if (*utf8CheckBuf == 0)
470 break;
471 if ((*utf8CheckBuf & 0xC0)!=0x80)
473 bUTF8 = false;
474 break;
477 if ((*utf8CheckBuf & 0xF0)==0xE0)
479 utf8CheckBuf++;
480 if (*utf8CheckBuf == 0)
481 break;
482 if ((*utf8CheckBuf & 0xC0)!=0x80)
484 bUTF8 = false;
485 break;
487 utf8CheckBuf++;
488 if (*utf8CheckBuf == 0)
489 break;
490 if ((*utf8CheckBuf & 0xC0)!=0x80)
492 bUTF8 = false;
493 break;
496 if ((*utf8CheckBuf & 0xF8)==0xF0)
498 utf8CheckBuf++;
499 if (*utf8CheckBuf == 0)
500 break;
501 if ((*utf8CheckBuf & 0xC0)!=0x80)
503 bUTF8 = false;
504 break;
506 utf8CheckBuf++;
507 if (*utf8CheckBuf == 0)
508 break;
509 if ((*utf8CheckBuf & 0xC0)!=0x80)
511 bUTF8 = false;
512 break;
514 utf8CheckBuf++;
515 if (*utf8CheckBuf == 0)
516 break;
517 if ((*utf8CheckBuf & 0xC0)!=0x80)
519 bUTF8 = false;
520 break;
524 utf8CheckBuf++;
526 SendEditor(SCI_ADDTEXT, _tcslen(lineptr), reinterpret_cast<LPARAM>(static_cast<char *>(lineptr)));
527 SendEditor(SCI_ADDTEXT, 2, (LPARAM)_T("\r\n"));
529 } while (File.gcount() > 0);
531 if (bUTF8)
532 SendEditor(SCI_SETCODEPAGE, SC_CP_UTF8);
534 SendEditor(SCI_SETUNDOCOLLECTION, 1);
535 ::SetFocus(m_wEditor);
536 SendEditor(EM_EMPTYUNDOBUFFER);
537 SendEditor(SCI_SETSAVEPOINT);
538 SendEditor(SCI_GOTOPOS, 0);
539 SendEditor(SCI_SETSCROLLWIDTHTRACKING, TRUE);
540 SendEditor(SCI_SETREADONLY, TRUE);
542 //check which lexer to use, depending on the filetype
543 SetupLexer(fileName);
544 ::ShowWindow(m_wEditor, SW_SHOW);
545 m_blamewidth = 0;
546 ::InvalidateRect(wMain, NULL, TRUE);
547 RECT rc;
548 GetWindowRect(wMain, &rc);
549 SetWindowPos(wMain, 0, rc.left, rc.top, rc.right-rc.left-1, rc.bottom - rc.top, 0);
550 #endif
551 return TRUE;
554 void CTortoiseGitBlameView::SetAStyle(int style, COLORREF fore, COLORREF back, int size, CString *face)
556 SendEditor(SCI_STYLESETFORE, style, fore);
557 SendEditor(SCI_STYLESETBACK, style, back);
558 if (size >= 1)
559 SendEditor(SCI_STYLESETSIZE, style, size);
560 if (face)
561 SendEditor(SCI_STYLESETFONT, style, reinterpret_cast<LPARAM>(this->m_TextView.StringForControl(*face).GetBuffer()));
564 void CTortoiseGitBlameView::InitialiseEditor()
567 m_directFunction = ::SendMessage(m_wEditor, SCI_GETDIRECTFUNCTION, 0, 0);
568 m_directPointer = ::SendMessage(m_wEditor, SCI_GETDIRECTPOINTER, 0, 0);
569 // Set up the global default style. These attributes are used wherever no explicit choices are made.
570 SetAStyle(STYLE_DEFAULT,
571 black,
572 white,
573 (DWORD)CRegStdWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10),
574 &CString(((stdstring)CRegStdString(_T("Software\\TortoiseGit\\BlameFontName"), _T("Courier New"))).c_str())
576 SendEditor(SCI_SETTABWIDTH, (DWORD)CRegStdWORD(_T("Software\\TortoiseGit\\BlameTabSize"), 4));
577 SendEditor(SCI_SETREADONLY, TRUE);
578 LRESULT pix = SendEditor(SCI_TEXTWIDTH, STYLE_LINENUMBER, (LPARAM)this->m_TextView.StringForControl(_T("_99999")).GetBuffer());
579 if (m_bShowLine)
580 SendEditor(SCI_SETMARGINWIDTHN, 0, pix);
581 else
582 SendEditor(SCI_SETMARGINWIDTHN, 0);
583 SendEditor(SCI_SETMARGINWIDTHN, 1);
584 SendEditor(SCI_SETMARGINWIDTHN, 2);
585 //Set the default windows colors for edit controls
586 SendEditor(SCI_STYLESETFORE, STYLE_DEFAULT, ::GetSysColor(COLOR_WINDOWTEXT));
587 SendEditor(SCI_STYLESETBACK, STYLE_DEFAULT, ::GetSysColor(COLOR_WINDOW));
588 SendEditor(SCI_SETSELFORE, TRUE, ::GetSysColor(COLOR_HIGHLIGHTTEXT));
589 SendEditor(SCI_SETSELBACK, TRUE, ::GetSysColor(COLOR_HIGHLIGHT));
590 SendEditor(SCI_SETCARETFORE, ::GetSysColor(COLOR_WINDOWTEXT));
591 m_regOldLinesColor = CRegStdWORD(_T("Software\\TortoiseGit\\BlameOldColor"), RGB(230, 230, 255));
592 m_regNewLinesColor = CRegStdWORD(_T("Software\\TortoiseGit\\BlameNewColor"), RGB(255, 230, 230));
594 this->m_TextView.Call(SCI_SETWRAPMODE, SC_WRAP_NONE);
598 void CTortoiseGitBlameView::StartSearch()
600 if (m_pFindDialog)
601 return;
602 bool bCase = false;
603 // Initialize FINDREPLACE
604 if (fr.Flags & FR_MATCHCASE)
605 bCase = true;
606 SecureZeroMemory(&fr, sizeof(fr));
607 fr.lStructSize = sizeof(fr);
608 fr.hwndOwner = wMain;
609 fr.lpstrFindWhat = szFindWhat;
610 fr.wFindWhatLen = 80;
611 fr.Flags = FR_HIDEUPDOWN | FR_HIDEWHOLEWORD;
612 fr.Flags |= bCase ? FR_MATCHCASE : 0;
614 currentDialog = FindText(&fr);
617 bool CTortoiseGitBlameView::DoSearch(CString what, DWORD flags)
620 //char szWhat[80];
621 int pos = SendEditor(SCI_GETCURRENTPOS);
622 int line = SendEditor(SCI_LINEFROMPOSITION, pos);
623 bool bFound = false;
624 bool bCaseSensitive = !!(flags & FR_MATCHCASE);
626 //strcpy_s(szWhat, sizeof(szWhat), what);
628 if(!bCaseSensitive)
630 what=what.MakeLower();
633 //CString sWhat = CString(szWhat);
635 //char buf[20];
636 //int i=0;
637 int i=line;
640 int bufsize = SendEditor(SCI_GETLINE, i);
641 char * linebuf = new char[bufsize+1];
642 SecureZeroMemory(linebuf, bufsize+1);
643 SendEditor(SCI_GETLINE, i, (LPARAM)linebuf);
644 CString oneline=this->m_TextView.StringFromControl(linebuf);
645 if (!bCaseSensitive)
647 oneline=oneline.MakeLower();
649 //_stprintf_s(buf, 20, _T("%ld"), revs[i]);
650 if (this->m_Authors[i].Find(what)>=0)
651 bFound = true;
652 else if ((!bCaseSensitive)&&(this->m_Authors[i].MakeLower().Find(what)>=0))
653 bFound = true;
654 else if (oneline.Find(what) >=0)
655 bFound = true;
657 delete [] linebuf;
659 i++;
660 if(i>=m_CommitHash.size())
661 i=0;
662 }while(i!=line &&(!bFound));
664 if (bFound)
666 GotoLine(i);
667 int selstart = SendEditor(SCI_GETCURRENTPOS);
668 int selend = SendEditor(SCI_POSITIONFROMLINE, i);
669 SendEditor(SCI_SETSELECTIONSTART, selstart);
670 SendEditor(SCI_SETSELECTIONEND, selend);
671 m_SelectedLine = i-1;
673 else
675 ::MessageBox(wMain, what+_T(" not found"), _T("CTortoiseGitBlameView"), MB_ICONINFORMATION);
678 return true;
681 bool CTortoiseGitBlameView::GotoLine(long line)
683 --line;
684 if (line < 0)
685 return false;
686 if ((unsigned long)line >= m_CommitHash.size())
688 line = m_CommitHash.size()-1;
691 int nCurrentPos = SendEditor(SCI_GETCURRENTPOS);
692 int nCurrentLine = SendEditor(SCI_LINEFROMPOSITION,nCurrentPos);
693 int nFirstVisibleLine = SendEditor(SCI_GETFIRSTVISIBLELINE);
694 int nLinesOnScreen = SendEditor(SCI_LINESONSCREEN);
696 if ( line>=nFirstVisibleLine && line<=nFirstVisibleLine+nLinesOnScreen)
698 // no need to scroll
699 SendEditor(SCI_GOTOLINE, line);
701 else
703 // Place the requested line one third from the top
704 if ( line > nCurrentLine )
706 SendEditor(SCI_GOTOLINE, (WPARAM)(line+(int)nLinesOnScreen*(2/3.0)));
708 else
710 SendEditor(SCI_GOTOLINE, (WPARAM)(line-(int)nLinesOnScreen*(1/3.0)));
714 // Highlight the line
715 int nPosStart = SendEditor(SCI_POSITIONFROMLINE,line);
716 int nPosEnd = SendEditor(SCI_GETLINEENDPOSITION,line);
717 SendEditor(SCI_SETSEL,nPosEnd,nPosStart);
719 return true;
722 bool CTortoiseGitBlameView::ScrollToLine(long line)
724 if (line < 0)
725 return false;
727 int nCurrentLine = SendEditor(SCI_GETFIRSTVISIBLELINE);
729 int scrolldelta = line - nCurrentLine;
730 SendEditor(SCI_LINESCROLL, 0, scrolldelta);
732 return true;
735 void CTortoiseGitBlameView::CopySelectedLogToClipboard()
737 this->GetLogList()->CopySelectionToClipBoard(FALSE);
740 void CTortoiseGitBlameView::BlamePreviousRevision()
742 #if 0
743 LONG nRevisionTo = m_selectedorigrev - 1;
744 if ( nRevisionTo<1 )
746 return;
749 // We now determine the smallest revision number in the blame file (but ignore "-1")
750 // We do this for two reasons:
751 // 1. we respect the "From revision" which the user entered
752 // 2. we speed up the call of "svn blame" because previous smaller revision numbers don't have any effect on the result
753 LONG nSmallestRevision = -1;
754 for (LONG line=0;line<(LONG)app.revs.size();line++)
756 const LONG nRevision = app.revs[line];
757 if ( nRevision > 0 )
759 if ( nSmallestRevision < 1 )
761 nSmallestRevision = nRevision;
763 else
765 nSmallestRevision = min(nSmallestRevision,nRevision);
770 char bufStartRev[20];
771 _stprintf_s(bufStartRev, 20, _T("%d"), nSmallestRevision);
773 char bufEndRev[20];
774 _stprintf_s(bufEndRev, 20, _T("%d"), nRevisionTo);
776 char bufLine[20];
777 _stprintf_s(bufLine, 20, _T("%d"), m_SelectedLine+1); //using the current line is a good guess.
779 STARTUPINFO startup;
780 PROCESS_INFORMATION process;
781 memset(&startup, 0, sizeof(startup));
782 startup.cb = sizeof(startup);
783 memset(&process, 0, sizeof(process));
784 stdstring tortoiseProcPath = GetAppDirectory() + _T("TortoiseProc.exe");
785 stdstring svnCmd = _T(" /command:blame ");
786 svnCmd += _T(" /path:\"");
787 svnCmd += szOrigPath;
788 svnCmd += _T("\"");
789 svnCmd += _T(" /startrev:");
790 svnCmd += bufStartRev;
791 svnCmd += _T(" /endrev:");
792 svnCmd += bufEndRev;
793 svnCmd += _T(" /line:");
794 svnCmd += bufLine;
795 if (bIgnoreEOL)
796 svnCmd += _T(" /ignoreeol");
797 if (bIgnoreSpaces)
798 svnCmd += _T(" /ignorespaces");
799 if (bIgnoreAllSpaces)
800 svnCmd += _T(" /ignoreallspaces");
801 if (CreateProcess(tortoiseProcPath.c_str(), const_cast<TCHAR*>(svnCmd.c_str()), NULL, NULL, FALSE, 0, 0, 0, &startup, &process))
803 CloseHandle(process.hThread);
804 CloseHandle(process.hProcess);
806 #endif
809 void CTortoiseGitBlameView::DiffPreviousRevision()
811 #if 0
812 LONG nRevisionTo = m_selectedorigrev;
813 if ( nRevisionTo<1 )
815 return;
818 LONG nRevisionFrom = nRevisionTo-1;
820 char bufStartRev[20];
821 _stprintf_s(bufStartRev, 20, _T("%d"), nRevisionFrom);
823 char bufEndRev[20];
824 _stprintf_s(bufEndRev, 20, _T("%d"), nRevisionTo);
826 STARTUPINFO startup;
827 PROCESS_INFORMATION process;
828 memset(&startup, 0, sizeof(startup));
829 startup.cb = sizeof(startup);
830 memset(&process, 0, sizeof(process));
831 stdstring tortoiseProcPath = GetAppDirectory() + _T("TortoiseProc.exe");
832 stdstring svnCmd = _T(" /command:diff ");
833 svnCmd += _T(" /path:\"");
834 svnCmd += szOrigPath;
835 svnCmd += _T("\"");
836 svnCmd += _T(" /startrev:");
837 svnCmd += bufStartRev;
838 svnCmd += _T(" /endrev:");
839 svnCmd += bufEndRev;
840 if (CreateProcess(tortoiseProcPath.c_str(), const_cast<TCHAR*>(svnCmd.c_str()), NULL, NULL, FALSE, 0, 0, 0, &startup, &process))
842 CloseHandle(process.hThread);
843 CloseHandle(process.hProcess);
845 #endif
848 void CTortoiseGitBlameView::ShowLog()
850 #if 0
851 char bufRev[20];
852 _stprintf_s(bufRev, 20, _T("%d"), m_selectedorigrev);
854 STARTUPINFO startup;
855 PROCESS_INFORMATION process;
856 memset(&startup, 0, sizeof(startup));
857 startup.cb = sizeof(startup);
858 memset(&process, 0, sizeof(process));
859 stdstring tortoiseProcPath = GetAppDirectory() + _T("TortoiseProc.exe");
860 stdstring svnCmd = _T(" /command:log ");
861 svnCmd += _T(" /path:\"");
862 svnCmd += szOrigPath;
863 svnCmd += _T("\"");
864 svnCmd += _T(" /startrev:");
865 svnCmd += bufRev;
866 svnCmd += _T(" /pegrev:");
867 svnCmd += bufRev;
868 if (CreateProcess(tortoiseProcPath.c_str(), const_cast<TCHAR*>(svnCmd.c_str()), NULL, NULL, FALSE, 0, 0, 0, &startup, &process))
870 CloseHandle(process.hThread);
871 CloseHandle(process.hProcess);
873 #endif
876 void CTortoiseGitBlameView::Notify(SCNotification *notification)
878 switch (notification->nmhdr.code)
880 case SCN_SAVEPOINTREACHED:
881 break;
883 case SCN_SAVEPOINTLEFT:
884 break;
885 case SCN_PAINTED:
886 // InvalidateRect(wBlame, NULL, FALSE);
887 // InvalidateRect(wLocator, NULL, FALSE);
888 break;
889 case SCN_GETBKCOLOR:
890 // if ((m_colorage)&&(notification->line < (int)revs.size()))
891 // {
892 // notification->lParam = InterColor(DWORD(m_regOldLinesColor), DWORD(m_regNewLinesColor), (revs[notification->line]-m_lowestrev)*100/((m_highestrev-m_lowestrev)+1));
893 // }
894 break;
898 void CTortoiseGitBlameView::Command(int id)
900 #if 0
901 switch (id)
903 // case IDM_EXIT:
904 // ::PostQuitMessage(0);
905 // break;
906 case ID_EDIT_FIND:
907 StartSearch();
908 break;
909 case ID_COPYTOCLIPBOARD:
910 CopySelectedLogToClipboard();
911 break;
912 case ID_BLAME_PREVIOUS_REVISION:
913 BlamePreviousRevision();
914 break;
915 case ID_DIFF_PREVIOUS_REVISION:
916 DiffPreviousRevision();
917 break;
918 case ID_SHOWLOG:
919 ShowLog();
920 break;
921 case ID_EDIT_GOTOLINE:
922 GotoLineDlg();
923 break;
924 case ID_VIEW_COLORAGEOFLINES:
926 m_colorage = !m_colorage;
927 HMENU hMenu = GetMenu(wMain);
928 UINT uCheck = MF_BYCOMMAND;
929 uCheck |= m_colorage ? MF_CHECKED : MF_UNCHECKED;
930 CheckMenuItem(hMenu, ID_VIEW_COLORAGEOFLINES, uCheck);
931 m_blamewidth = 0;
932 InitSize();
934 break;
935 case ID_VIEW_MERGEPATH:
937 ShowPath = !ShowPath;
938 HMENU hMenu = GetMenu(wMain);
939 UINT uCheck = MF_BYCOMMAND;
940 uCheck |= ShowPath ? MF_CHECKED : MF_UNCHECKED;
941 CheckMenuItem(hMenu, ID_VIEW_MERGEPATH, uCheck);
942 m_blamewidth = 0;
943 InitSize();
945 default:
946 break;
948 #endif
952 LONG CTortoiseGitBlameView::GetBlameWidth()
954 LONG blamewidth = 0;
955 SIZE width;
956 CreateFont();
957 HDC hDC = this->GetDC()->m_hDC;
958 HFONT oldfont = (HFONT)::SelectObject(hDC, m_font);
960 TCHAR buf[MAX_PATH];
961 //_stprintf_s(buf, MAX_PATH, _T("%8ld "), 88888888);
962 //::GetTextExtentPoint(hDC, buf, _tcslen(buf), &width);
963 //m_revwidth = width.cx + BLAMESPACE;
964 //blamewidth += m_revwidth;
966 int maxnum=0;
967 for (int i=0;i<this->m_Authors.size();i++)
969 if(m_ID[i]>maxnum)
970 maxnum=m_ID[i];
972 _stprintf_s(buf, MAX_PATH, _T("%d."), maxnum);
973 ::GetTextExtentPoint(hDC, buf, _tcslen(buf), &width);
974 m_revwidth = width.cx + BLAMESPACE;
975 blamewidth += m_revwidth;
977 #if 0
978 _stprintf_s(buf, MAX_PATH, _T("%d"), m_CommitHash.size());
979 ::GetTextExtentPoint(hDC, buf, _tcslen(buf), &width);
980 m_linewidth = width.cx + BLAMESPACE;
981 blamewidth += m_revwidth;
982 #endif
984 if (m_bShowDate)
986 _stprintf_s(buf, MAX_PATH, _T("%30s"), _T("31.08.2001 06:24:14"));
987 ::GetTextExtentPoint32(hDC, buf, _tcslen(buf), &width);
988 m_datewidth = width.cx + BLAMESPACE;
989 blamewidth += m_datewidth;
991 if ( m_bShowAuthor)
993 SIZE maxwidth = {0};
995 for (int i=0;i<this->m_Authors.size();i++)
996 //for (std::vector<CString>::iterator I = authors.begin(); I != authors.end(); ++I)
998 ::GetTextExtentPoint32(hDC,m_Authors[i] , m_Authors[i].GetLength(), &width);
999 if (width.cx > maxwidth.cx)
1000 maxwidth = width;
1002 m_authorwidth = maxwidth.cx + BLAMESPACE;
1003 blamewidth += m_authorwidth;
1005 #if 0
1006 if (ShowPath)
1008 SIZE maxwidth = {0};
1009 for (std::vector<CString>::iterator I = paths.begin(); I != paths.end(); ++I)
1011 ::GetTextExtentPoint32(hDC, I->c_str(), I->size(), &width);
1012 if (width.cx > maxwidth.cx)
1013 maxwidth = width;
1015 m_pathwidth = maxwidth.cx + BLAMESPACE;
1016 blamewidth += m_pathwidth;
1018 #endif
1019 ::SelectObject(hDC, oldfont);
1020 POINT pt = {blamewidth, 0};
1021 LPtoDP(hDC, &pt, 1);
1022 m_blamewidth = pt.x;
1023 //::ReleaseDC(wBlame, hDC);
1025 //return m_blamewidth;
1026 return blamewidth;
1030 void CTortoiseGitBlameView::CreateFont()
1032 if (m_font)
1033 return;
1034 LOGFONT lf = {0};
1035 lf.lfWeight = 400;
1036 HDC hDC = ::GetDC(wBlame);
1037 lf.lfHeight = -MulDiv((DWORD)CRegStdWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10), GetDeviceCaps(hDC, LOGPIXELSY), 72);
1038 lf.lfCharSet = DEFAULT_CHARSET;
1039 CRegStdString fontname = CRegStdString(_T("Software\\TortoiseGit\\BlameFontName"), _T("Courier New"));
1040 _tcscpy_s(lf.lfFaceName, 32, ((stdstring)fontname).c_str());
1041 m_font = ::CreateFontIndirect(&lf);
1043 lf.lfItalic = TRUE;
1044 m_italicfont = ::CreateFontIndirect(&lf);
1046 ::ReleaseDC(wBlame, hDC);
1048 //m_TextView.SetFont(lf.lfFaceName,((DWORD)CRegStdWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10)));
1051 void CTortoiseGitBlameView::DrawBlame(HDC hDC)
1054 if (hDC == NULL)
1055 return;
1056 if (m_font == NULL)
1057 return;
1059 HFONT oldfont = NULL;
1060 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
1061 LONG_PTR linesonscreen = SendEditor(SCI_LINESONSCREEN);
1062 LONG_PTR height = SendEditor(SCI_TEXTHEIGHT);
1063 LONG_PTR Y = 0;
1064 TCHAR buf[MAX_PATH];
1065 RECT rc;
1066 BOOL sel = FALSE;
1067 //::GetClientRect(this->m_hWnd, &rc);
1068 for (LRESULT i=line; i<(line+linesonscreen); ++i)
1070 sel = FALSE;
1071 if (i < (int)m_CommitHash.size())
1073 // if (mergelines[i])
1074 // oldfont = (HFONT)::SelectObject(hDC, m_italicfont);
1075 // else
1076 oldfont = (HFONT)::SelectObject(hDC, m_font);
1077 ::SetBkColor(hDC, m_windowcolor);
1078 ::SetTextColor(hDC, m_textcolor);
1079 if (m_CommitHash[i].GetLength()>0)
1081 //if (m_CommitHash[i].Compare(m_MouseHash)==0)
1082 // ::SetBkColor(hDC, m_mouseauthorcolor);
1083 if (m_CommitHash[i].Compare(m_SelectedHash)==0)
1085 ::SetBkColor(hDC, m_selectedauthorcolor);
1086 ::SetTextColor(hDC, m_texthighlightcolor);
1087 sel = TRUE;
1091 if(m_MouseLine == i)
1092 ::SetBkColor(hDC, m_mouserevcolor);
1094 //if ((revs[i] == m_mouserev)&&(!sel))
1095 // ::SetBkColor(hDC, m_mouserevcolor);
1096 //if (revs[i] == m_selectedrev)
1098 // ::SetBkColor(hDC, m_selectedrevcolor);
1099 // ::SetTextColor(hDC, m_texthighlightcolor);
1102 CString str;
1103 str.Format(_T("%d"),m_ID[i]);
1105 //_stprintf_s(buf, MAX_PATH, _T("%8ld "), revs[i]);
1106 rc.top=Y;
1107 rc.left=LOCATOR_WIDTH;
1108 rc.bottom=Y+height;
1109 rc.right = rc.left + m_blamewidth;
1110 ::ExtTextOut(hDC, LOCATOR_WIDTH, Y, ETO_CLIPPED, &rc, str, str.GetLength(), 0);
1111 int Left = m_revwidth;
1113 if (m_bShowAuthor)
1115 rc.right = rc.left + Left + m_authorwidth;
1116 //_stprintf_s(buf, MAX_PATH, _T("%-30s "), authors[i].c_str());
1117 ::ExtTextOut(hDC, Left, Y, ETO_CLIPPED, &rc, m_Authors[i], m_Authors[i].GetLength(), 0);
1118 Left += m_authorwidth;
1120 #if 0
1121 if (ShowDate)
1123 rc.right = rc.left + Left + m_datewidth;
1124 _stprintf_s(buf, MAX_PATH, _T("%30s "), dates[i].c_str());
1125 ::ExtTextOut(hDC, Left, Y, ETO_CLIPPED, &rc, buf, _tcslen(buf), 0);
1126 Left += m_datewidth;
1129 #endif
1130 #if 0
1131 if (ShowPath)
1133 rc.right = rc.left + Left + m_pathwidth;
1134 _stprintf_s(buf, MAX_PATH, _T("%-60s "), paths[i].c_str());
1135 ::ExtTextOut(hDC, Left, Y, ETO_CLIPPED, &rc, buf, _tcslen(buf), 0);
1136 Left += m_authorwidth;
1138 #endif
1139 if ((i==m_SelectedLine)&&(m_pFindDialog))
1141 LOGBRUSH brush;
1142 brush.lbColor = m_textcolor;
1143 brush.lbHatch = 0;
1144 brush.lbStyle = BS_SOLID;
1145 HPEN pen = ExtCreatePen(PS_SOLID | PS_GEOMETRIC, 2, &brush, 0, NULL);
1146 HGDIOBJ hPenOld = SelectObject(hDC, pen);
1147 RECT rc2 = rc;
1148 rc2.top = Y;
1149 rc2.bottom = Y + height;
1150 ::MoveToEx(hDC, rc2.left, rc2.top, NULL);
1151 ::LineTo(hDC, rc2.right, rc2.top);
1152 ::LineTo(hDC, rc2.right, rc2.bottom);
1153 ::LineTo(hDC, rc2.left, rc2.bottom);
1154 ::LineTo(hDC, rc2.left, rc2.top);
1155 SelectObject(hDC, hPenOld);
1156 DeleteObject(pen);
1158 Y += height;
1159 ::SelectObject(hDC, oldfont);
1161 else
1163 ::SetBkColor(hDC, m_windowcolor);
1164 for (int j=0; j< MAX_PATH; ++j)
1165 buf[j]=' ';
1166 ::ExtTextOut(hDC, 0, Y, ETO_CLIPPED, &rc, buf, MAX_PATH-1, 0);
1167 Y += height;
1172 void CTortoiseGitBlameView::DrawHeader(HDC hDC)
1174 #if 0
1175 if (hDC == NULL)
1176 return;
1178 RECT rc;
1179 HFONT oldfont = (HFONT)::SelectObject(hDC, GetStockObject(DEFAULT_GUI_FONT));
1180 ::GetClientRect(wHeader, &rc);
1182 ::SetBkColor(hDC, ::GetSysColor(COLOR_BTNFACE));
1184 TCHAR szText[MAX_LOADSTRING];
1185 LoadString(app.hResource, IDS_HEADER_REVISION, szText, MAX_LOADSTRING);
1186 ::ExtTextOut(hDC, LOCATOR_WIDTH, 0, ETO_CLIPPED, &rc, szText, _tcslen(szText), 0);
1187 int Left = m_revwidth+LOCATOR_WIDTH;
1188 if (ShowDate)
1190 LoadString(app.hResource, IDS_HEADER_DATE, szText, MAX_LOADSTRING);
1191 ::ExtTextOut(hDC, Left, 0, ETO_CLIPPED, &rc, szText, _tcslen(szText), 0);
1192 Left += m_datewidth;
1194 if (ShowAuthor)
1196 LoadString(app.hResource, IDS_HEADER_AUTHOR, szText, MAX_LOADSTRING);
1197 ::ExtTextOut(hDC, Left, 0, ETO_CLIPPED, &rc, szText, _tcslen(szText), 0);
1198 Left += m_authorwidth;
1200 if (ShowPath)
1202 LoadString(app.hResource, IDS_HEADER_PATH, szText, MAX_LOADSTRING);
1203 ::ExtTextOut(hDC, Left, 0, ETO_CLIPPED, &rc, szText, _tcslen(szText), 0);
1204 Left += m_pathwidth;
1206 LoadString(app.hResource, IDS_HEADER_LINE, szText, MAX_LOADSTRING);
1207 ::ExtTextOut(hDC, Left, 0, ETO_CLIPPED, &rc, szText, _tcslen(szText), 0);
1209 ::SelectObject(hDC, oldfont);
1210 #endif
1213 void CTortoiseGitBlameView::DrawLocatorBar(HDC hDC)
1215 if (hDC == NULL)
1216 return;
1218 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
1219 LONG_PTR linesonscreen = SendEditor(SCI_LINESONSCREEN);
1220 LONG_PTR Y = 0;
1221 COLORREF blackColor = GetSysColor(COLOR_WINDOWTEXT);
1223 RECT rc;
1224 //::GetClientRect(wLocator, &rc);
1225 this->GetClientRect(&rc);
1227 rc.right=LOCATOR_WIDTH;
1229 RECT lineRect = rc;
1230 LONG height = rc.bottom-rc.top;
1231 LONG currentLine = 0;
1233 // draw the colored bar
1234 for (std::vector<LONG>::const_iterator it = m_ID.begin(); it != m_ID.end(); ++it)
1236 currentLine++;
1237 // get the line color
1238 COLORREF cr = InterColor(DWORD(m_regOldLinesColor), DWORD(m_regNewLinesColor), (*it - m_lowestrev)*100/((m_highestrev-m_lowestrev)+1));
1239 if ((currentLine > line)&&(currentLine <= (line + linesonscreen)))
1241 cr = InterColor(cr, blackColor, 10);
1243 SetBkColor(hDC, cr);
1244 lineRect.top = Y;
1245 lineRect.bottom = (currentLine * height / m_ID.size());
1246 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, NULL, 0, NULL);
1247 Y = lineRect.bottom;
1250 if (m_ID.size())
1252 // now draw two lines indicating the scroll position of the source view
1253 SetBkColor(hDC, blackColor);
1254 lineRect.top = line * height / m_ID.size();
1255 lineRect.bottom = lineRect.top+1;
1256 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, NULL, 0, NULL);
1257 lineRect.top = (line + linesonscreen) * height / m_ID.size();
1258 lineRect.bottom = lineRect.top+1;
1259 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, NULL, 0, NULL);
1264 void CTortoiseGitBlameView::StringExpand(LPSTR str)
1266 char * cPos = str;
1269 cPos = strchr(cPos, '\n');
1270 if (cPos)
1272 memmove(cPos+1, cPos, strlen(cPos)*sizeof(char));
1273 *cPos = '\r';
1274 cPos++;
1275 cPos++;
1277 } while (cPos != NULL);
1279 void CTortoiseGitBlameView::StringExpand(LPWSTR str)
1281 wchar_t * cPos = str;
1284 cPos = wcschr(cPos, '\n');
1285 if (cPos)
1287 memmove(cPos+1, cPos, wcslen(cPos)*sizeof(wchar_t));
1288 *cPos = '\r';
1289 cPos++;
1290 cPos++;
1292 } while (cPos != NULL);
1295 // Forward declarations of functions included in this code module:
1296 ATOM MyRegisterClass(HINSTANCE hResource);
1297 ATOM MyRegisterBlameClass(HINSTANCE hResource);
1298 ATOM MyRegisterHeaderClass(HINSTANCE hResource);
1299 ATOM MyRegisterLocatorClass(HINSTANCE hResource);
1300 BOOL InitInstance(HINSTANCE, int);
1301 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
1302 LRESULT CALLBACK WndBlameProc(HWND, UINT, WPARAM, LPARAM);
1303 LRESULT CALLBACK WndHeaderProc(HWND, UINT, WPARAM, LPARAM);
1304 LRESULT CALLBACK WndLocatorProc(HWND, UINT, WPARAM, LPARAM);
1305 UINT uFindReplaceMsg;
1307 #if 0
1308 int APIENTRY _tWinMain(HINSTANCE hInstance,
1309 HINSTANCE /*hPrevInstance*/,
1310 LPTSTR lpCmdLine,
1311 int nCmdShow)
1313 app.hInstance = hInstance;
1314 MSG msg;
1315 HACCEL hAccelTable;
1317 if (::LoadLibrary("SciLexer.DLL") == NULL)
1318 return FALSE;
1320 CRegStdWORD loc = CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033);
1321 long langId = loc;
1323 CLangDll langDLL;
1324 app.hResource = langDLL.Init(_T("CTortoiseGitBlameView"), langId);
1325 if (app.hResource == NULL)
1326 app.hResource = app.hInstance;
1328 // Initialize global strings
1329 LoadString(app.hResource, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
1330 LoadString(app.hResource, IDC_TortoiseGitBlameView, szWindowClass, MAX_LOADSTRING);
1331 LoadString(app.hResource, IDS_SEARCHNOTFOUND, searchstringnotfound, MAX_LOADSTRING);
1332 MyRegisterClass(app.hResource);
1333 MyRegisterBlameClass(app.hResource);
1334 MyRegisterHeaderClass(app.hResource);
1335 MyRegisterLocatorClass(app.hResource);
1337 // Perform application initialization:
1338 if (!InitInstance (app.hResource, nCmdShow))
1340 langDLL.Close();
1341 return FALSE;
1344 SecureZeroMemory(szViewtitle, MAX_PATH);
1345 SecureZeroMemory(szOrigPath, MAX_PATH);
1346 char blamefile[MAX_PATH] = {0};
1347 char logfile[MAX_PATH] = {0};
1349 CCmdLineParser parser(lpCmdLine);
1352 if (__argc > 1)
1354 _tcscpy_s(blamefile, MAX_PATH, __argv[1]);
1356 if (__argc > 2)
1358 _tcscpy_s(logfile, MAX_PATH, __argv[2]);
1360 if (__argc > 3)
1362 _tcscpy_s(szViewtitle, MAX_PATH, __argv[3]);
1363 if (parser.HasVal(_T("revrange")))
1365 _tcscat_s(szViewtitle, MAX_PATH, _T(" : "));
1366 _tcscat_s(szViewtitle, MAX_PATH, parser.GetVal(_T("revrange")));
1369 if ((_tcslen(blamefile)==0) || parser.HasKey(_T("?")) || parser.HasKey(_T("help")))
1371 TCHAR szInfo[MAX_LOADSTRING];
1372 LoadString(app.hResource, IDS_COMMANDLINE_INFO, szInfo, MAX_LOADSTRING);
1373 MessageBox(NULL, szInfo, _T("CTortoiseGitBlameView"), MB_ICONERROR);
1374 langDLL.Close();
1375 return 0;
1378 if ( parser.HasKey(_T("path")) )
1380 _tcscpy_s(szOrigPath, MAX_PATH, parser.GetVal(_T("path")));
1382 app.bIgnoreEOL = parser.HasKey(_T("ignoreeol"));
1383 app.bIgnoreSpaces = parser.HasKey(_T("ignorespaces"));
1384 app.bIgnoreAllSpaces = parser.HasKey(_T("ignoreallspaces"));
1386 app.SendEditor(SCI_SETCODEPAGE, GetACP());
1387 app.OpenFile(blamefile);
1388 if (_tcslen(logfile)>0)
1389 app.OpenLogFile(logfile);
1391 if (parser.HasKey(_T("line")))
1393 app.GotoLine(parser.GetLongVal(_T("line")));
1396 CheckMenuItem(GetMenu(app.wMain), ID_VIEW_COLORAGEOFLINES, MF_CHECKED|MF_BYCOMMAND);
1399 hAccelTable = LoadAccelerators(app.hResource, (LPCTSTR)IDC_TortoiseGitBlameView);
1401 BOOL going = TRUE;
1402 msg.wParam = 0;
1403 while (going)
1405 going = GetMessage(&msg, NULL, 0, 0);
1406 if (app.currentDialog && going)
1408 if (!IsDialogMessage(app.currentDialog, &msg))
1410 if (TranslateAccelerator(msg.hwnd, hAccelTable, &msg) == 0)
1412 TranslateMessage(&msg);
1413 DispatchMessage(&msg);
1417 else if (going)
1419 if (TranslateAccelerator(app.wMain, hAccelTable, &msg) == 0)
1421 TranslateMessage(&msg);
1422 DispatchMessage(&msg);
1426 langDLL.Close();
1427 return msg.wParam;
1430 ATOM MyRegisterClass(HINSTANCE hResource)
1432 WNDCLASSEX wcex;
1434 wcex.cbSize = sizeof(WNDCLASSEX);
1436 wcex.style = CS_HREDRAW | CS_VREDRAW;
1437 wcex.lpfnWndProc = (WNDPROC)WndProc;
1438 wcex.cbClsExtra = 0;
1439 wcex.cbWndExtra = 0;
1440 wcex.hInstance = hResource;
1441 wcex.hIcon = LoadIcon(hResource, (LPCTSTR)IDI_TortoiseGitBlameView);
1442 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
1443 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
1444 wcex.lpszMenuName = (LPCTSTR)IDC_TortoiseGitBlameView;
1445 wcex.lpszClassName = szWindowClass;
1446 wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
1448 return RegisterClassEx(&wcex);
1451 ATOM MyRegisterBlameClass(HINSTANCE hResource)
1453 WNDCLASSEX wcex;
1455 wcex.cbSize = sizeof(WNDCLASSEX);
1457 wcex.style = CS_HREDRAW | CS_VREDRAW;
1458 wcex.lpfnWndProc = (WNDPROC)WndBlameProc;
1459 wcex.cbClsExtra = 0;
1460 wcex.cbWndExtra = 0;
1461 wcex.hInstance = hResource;
1462 wcex.hIcon = LoadIcon(hResource, (LPCTSTR)IDI_TortoiseGitBlameView);
1463 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
1464 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
1465 wcex.lpszMenuName = 0;
1466 wcex.lpszClassName = _T("TortoiseGitBlameViewBlame");
1467 wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
1469 return RegisterClassEx(&wcex);
1472 ATOM MyRegisterHeaderClass(HINSTANCE hResource)
1474 WNDCLASSEX wcex;
1476 wcex.cbSize = sizeof(WNDCLASSEX);
1478 wcex.style = CS_HREDRAW | CS_VREDRAW;
1479 wcex.lpfnWndProc = (WNDPROC)WndHeaderProc;
1480 wcex.cbClsExtra = 0;
1481 wcex.cbWndExtra = 0;
1482 wcex.hInstance = hResource;
1483 wcex.hIcon = LoadIcon(hResource, (LPCTSTR)IDI_TortoiseGitBlameView);
1484 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
1485 wcex.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
1486 wcex.lpszMenuName = 0;
1487 wcex.lpszClassName = _T("TortoiseGitBlameViewHeader");
1488 wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
1490 return RegisterClassEx(&wcex);
1493 ATOM MyRegisterLocatorClass(HINSTANCE hResource)
1495 WNDCLASSEX wcex;
1497 wcex.cbSize = sizeof(WNDCLASSEX);
1499 wcex.style = CS_HREDRAW | CS_VREDRAW;
1500 wcex.lpfnWndProc = (WNDPROC)WndLocatorProc;
1501 wcex.cbClsExtra = 0;
1502 wcex.cbWndExtra = 0;
1503 wcex.hInstance = hResource;
1504 wcex.hIcon = LoadIcon(hResource, (LPCTSTR)IDI_TortoiseGitBlameView);
1505 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
1506 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
1507 wcex.lpszMenuName = 0;
1508 wcex.lpszClassName = _T("TortoiseGitBlameViewLocator");
1509 wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
1511 return RegisterClassEx(&wcex);
1514 BOOL InitInstance(HINSTANCE hResource, int nCmdShow)
1516 app.wMain = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
1517 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hResource, NULL);
1519 if (!app.wMain)
1521 return FALSE;
1524 CRegStdWORD pos(_T("Software\\TortoiseGit\\TBlamePos"), 0);
1525 CRegStdWORD width(_T("Software\\TortoiseGit\\TBlameSize"), 0);
1526 CRegStdWORD state(_T("Software\\TortoiseGit\\TBlameState"), 0);
1527 if (DWORD(pos) && DWORD(width))
1529 RECT rc;
1530 rc.left = LOWORD(DWORD(pos));
1531 rc.top = HIWORD(DWORD(pos));
1532 rc.right = rc.left + LOWORD(DWORD(width));
1533 rc.bottom = rc.top + HIWORD(DWORD(width));
1534 HMONITOR hMon = MonitorFromRect(&rc, MONITOR_DEFAULTTONULL);
1535 if (hMon)
1537 // only restore the window position if the monitor is valid
1538 MoveWindow(app.wMain, LOWORD(DWORD(pos)), HIWORD(DWORD(pos)),
1539 LOWORD(DWORD(width)), HIWORD(DWORD(width)), FALSE);
1542 if (DWORD(state) == SW_MAXIMIZE)
1543 ShowWindow(app.wMain, SW_MAXIMIZE);
1544 else
1545 ShowWindow(app.wMain, nCmdShow);
1546 UpdateWindow(app.wMain);
1548 //Create the tooltips
1550 INITCOMMONCONTROLSEX iccex;
1551 app.hwndTT; // handle to the ToolTip control
1552 TOOLINFO ti;
1553 RECT rect; // for client area coordinates
1554 iccex.dwICC = ICC_WIN95_CLASSES;
1555 iccex.dwSize = sizeof(INITCOMMONCONTROLSEX);
1556 InitCommonControlsEx(&iccex);
1558 /* CREATE A TOOLTIP WINDOW */
1559 app.hwndTT = CreateWindowEx(WS_EX_TOPMOST,
1560 TOOLTIPS_CLASS,
1561 NULL,
1562 WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
1563 CW_USEDEFAULT,
1564 CW_USEDEFAULT,
1565 CW_USEDEFAULT,
1566 CW_USEDEFAULT,
1567 app.wBlame,
1568 NULL,
1569 app.hResource,
1570 NULL
1573 SetWindowPos(app.hwndTT,
1574 HWND_TOPMOST,
1579 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
1581 /* GET COORDINATES OF THE MAIN CLIENT AREA */
1582 GetClientRect (app.wBlame, &rect);
1584 /* INITIALIZE MEMBERS OF THE TOOLINFO STRUCTURE */
1585 ti.cbSize = sizeof(TOOLINFO);
1586 ti.uFlags = TTF_TRACK | TTF_ABSOLUTE;//TTF_SUBCLASS | TTF_PARSELINKS;
1587 ti.hwnd = app.wBlame;
1588 ti.hinst = app.hResource;
1589 ti.uId = 0;
1590 ti.lpszText = LPSTR_TEXTCALLBACK;
1591 // ToolTip control will cover the whole window
1592 ti.rect.left = rect.left;
1593 ti.rect.top = rect.top;
1594 ti.rect.right = rect.right;
1595 ti.rect.bottom = rect.bottom;
1597 /* SEND AN ADDTOOL MESSAGE TO THE TOOLTIP CONTROL WINDOW */
1598 SendMessage(app.hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
1599 SendMessage(app.hwndTT, TTM_SETMAXTIPWIDTH, 0, 600);
1600 //SendMessage(app.hwndTT, TTM_SETDELAYTIME, TTDT_AUTOPOP, MAKELONG(50000, 0));
1601 //SendMessage(app.hwndTT, TTM_SETDELAYTIME, TTDT_RESHOW, MAKELONG(1000, 0));
1603 uFindReplaceMsg = RegisterWindowMessage(FINDMSGSTRING);
1605 return TRUE;
1607 #endif
1608 void CTortoiseGitBlameView::InitSize()
1610 RECT rc;
1611 RECT blamerc;
1612 RECT sourcerc;
1613 ::GetClientRect(wMain, &rc);
1614 ::SetWindowPos(wHeader, 0, rc.left, rc.top, rc.right-rc.left, HEADER_HEIGHT, 0);
1615 rc.top += HEADER_HEIGHT;
1616 blamerc.left = rc.left;
1617 blamerc.top = rc.top;
1618 LONG w = GetBlameWidth();
1619 blamerc.right = w > abs(rc.right - rc.left) ? rc.right : w + rc.left;
1620 blamerc.bottom = rc.bottom;
1621 sourcerc.left = blamerc.right;
1622 sourcerc.top = rc.top;
1623 sourcerc.bottom = rc.bottom;
1624 sourcerc.right = rc.right;
1625 if (m_colorage)
1627 ::OffsetRect(&blamerc, LOCATOR_WIDTH, 0);
1628 ::OffsetRect(&sourcerc, LOCATOR_WIDTH, 0);
1629 sourcerc.right -= LOCATOR_WIDTH;
1631 ::InvalidateRect(wMain, NULL, FALSE);
1632 ::SetWindowPos(m_wEditor, 0, sourcerc.left, sourcerc.top, sourcerc.right - sourcerc.left, sourcerc.bottom - sourcerc.top, 0);
1633 ::SetWindowPos(wBlame, 0, blamerc.left, blamerc.top, blamerc.right - blamerc.left, blamerc.bottom - blamerc.top, 0);
1634 if (m_colorage)
1635 ::SetWindowPos(wLocator, 0, 0, blamerc.top, LOCATOR_WIDTH, blamerc.bottom - blamerc.top, SWP_SHOWWINDOW);
1636 else
1637 ::ShowWindow(wLocator, SW_HIDE);
1640 #if 0
1641 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1643 if (message == uFindReplaceMsg)
1645 LPFINDREPLACE lpfr = (LPFINDREPLACE)lParam;
1647 // If the FR_DIALOGTERM flag is set,
1648 // invalidate the handle identifying the dialog box.
1649 if (lpfr->Flags & FR_DIALOGTERM)
1651 app.currentDialog = NULL;
1652 return 0;
1654 if (lpfr->Flags & FR_FINDNEXT)
1656 app.DoSearch(lpfr->lpstrFindWhat, lpfr->Flags);
1658 return 0;
1660 switch (message)
1662 case WM_CREATE:
1663 app.m_wEditor = ::CreateWindow(
1664 "Scintilla",
1665 "Source",
1666 WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_CLIPCHILDREN,
1667 0, 0,
1668 100, 100,
1669 hWnd,
1671 app.hResource,
1673 app.InitialiseEditor();
1674 ::ShowWindow(app.m_wEditor, SW_SHOW);
1675 ::SetFocus(app.m_wEditor);
1676 app.wBlame = ::CreateWindow(
1677 _T("TortoiseGitBlameViewBlame"),
1678 _T("blame"),
1679 WS_CHILD | WS_CLIPCHILDREN,
1680 CW_USEDEFAULT, 0,
1681 CW_USEDEFAULT, 0,
1682 hWnd,
1683 NULL,
1684 app.hResource,
1685 NULL);
1686 ::ShowWindow(app.wBlame, SW_SHOW);
1687 app.wHeader = ::CreateWindow(
1688 _T("TortoiseGitBlameViewHeader"),
1689 _T("header"),
1690 WS_CHILD | WS_CLIPCHILDREN | WS_BORDER,
1691 CW_USEDEFAULT, 0,
1692 CW_USEDEFAULT, 0,
1693 hWnd,
1694 NULL,
1695 app.hResource,
1696 NULL);
1697 ::ShowWindow(app.wHeader, SW_SHOW);
1698 app.wLocator = ::CreateWindow(
1699 _T("TortoiseGitBlameViewLocator"),
1700 _T("locator"),
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.wLocator, SW_SHOW);
1709 return 0;
1711 case WM_SIZE:
1712 if (wParam != 1)
1714 app.InitSize();
1716 return 0;
1718 case WM_COMMAND:
1719 app.Command(LOWORD(wParam));
1720 break;
1721 case WM_NOTIFY:
1722 app.Notify(reinterpret_cast<SCNotification *>(lParam));
1723 return 0;
1724 case WM_DESTROY:
1725 PostQuitMessage(0);
1726 break;
1727 case WM_CLOSE:
1729 CRegStdWORD pos(_T("Software\\TortoiseGit\\TBlamePos"), 0);
1730 CRegStdWORD width(_T("Software\\TortoiseGit\\TBlameSize"), 0);
1731 CRegStdWORD state(_T("Software\\TortoiseGit\\TBlameState"), 0);
1732 RECT rc;
1733 GetWindowRect(app.wMain, &rc);
1734 if ((rc.left >= 0)&&(rc.top >= 0))
1736 pos = MAKELONG(rc.left, rc.top);
1737 width = MAKELONG(rc.right-rc.left, rc.bottom-rc.top);
1739 WINDOWPLACEMENT wp = {0};
1740 wp.length = sizeof(WINDOWPLACEMENT);
1741 GetWindowPlacement(app.wMain, &wp);
1742 state = wp.showCmd;
1743 ::DestroyWindow(app.m_wEditor);
1744 ::PostQuitMessage(0);
1746 return 0;
1747 case WM_SETFOCUS:
1748 ::SetFocus(app.wBlame);
1749 break;
1750 default:
1751 return DefWindowProc(hWnd, message, wParam, lParam);
1753 return 0;
1756 LRESULT CALLBACK WndBlameProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1758 PAINTSTRUCT ps;
1759 TRACKMOUSEEVENT mevt;
1760 HDC hDC;
1761 switch (message)
1763 case WM_CREATE:
1764 return 0;
1765 case WM_PAINT:
1766 hDC = BeginPaint(app.wBlame, &ps);
1767 app.DrawBlame(hDC);
1768 EndPaint(app.wBlame, &ps);
1769 break;
1770 case WM_COMMAND:
1771 app.Command(LOWORD(wParam));
1772 break;
1773 case WM_NOTIFY:
1774 switch (((LPNMHDR)lParam)->code)
1776 case TTN_GETDISPINFO:
1778 LPNMHDR pNMHDR = (LPNMHDR)lParam;
1779 NMTTDISPINFOA* pTTTA = (NMTTDISPINFOA*)pNMHDR;
1780 NMTTDISPINFOW* pTTTW = (NMTTDISPINFOW*)pNMHDR;
1781 POINT point;
1782 DWORD ptW = GetMessagePos();
1783 point.x = GET_X_LPARAM(ptW);
1784 point.y = GET_Y_LPARAM(ptW);
1785 ::ScreenToClient(app.wBlame, &point);
1786 LONG_PTR line = app.SendEditor(SCI_GETFIRSTVISIBLELINE);
1787 LONG_PTR height = app.SendEditor(SCI_TEXTHEIGHT);
1788 line = line + (point.y/height);
1789 if (line >= (LONG)app.revs.size())
1790 break;
1791 if (line < 0)
1792 break;
1793 LONG rev = app.revs[line];
1794 if (line >= (LONG)app.revs.size())
1795 break;
1797 SecureZeroMemory(app.m_szTip, sizeof(app.m_szTip));
1798 SecureZeroMemory(app.m_wszTip, sizeof(app.m_wszTip));
1799 std::map<LONG, CString>::iterator iter;
1800 if ((iter = app.logmessages.find(rev)) != app.logmessages.end())
1802 CString msg;
1803 if (!ShowAuthor)
1805 msg += app.authors[line];
1807 if (!ShowDate)
1809 if (!ShowAuthor) msg += " ";
1810 msg += app.dates[line];
1812 if (!ShowAuthor || !ShowDate)
1813 msg += '\n';
1814 msg += iter->second;
1815 // an empty tooltip string will deactivate the tooltips,
1816 // which means we must make sure that the tooltip won't
1817 // be empty.
1818 if (msg.empty())
1819 msg = _T(" ");
1820 if (pNMHDR->code == TTN_NEEDTEXTA)
1822 lstrcpyn(app.m_szTip, msg.c_str(), MAX_LOG_LENGTH*2);
1823 app.StringExpand(app.m_szTip);
1824 pTTTA->lpszText = app.m_szTip;
1826 else
1828 pTTTW->lpszText = app.m_wszTip;
1829 ::MultiByteToWideChar( CP_ACP , 0, msg.c_str(), min(msg.size(), MAX_LOG_LENGTH*2), app.m_wszTip, MAX_LOG_LENGTH*2);
1830 app.StringExpand(app.m_wszTip);
1834 break;
1836 return 0;
1837 case WM_DESTROY:
1838 break;
1839 case WM_CLOSE:
1840 return 0;
1841 case WM_MOUSELEAVE:
1842 app.m_mouserev = -2;
1843 app.m_mouseauthor.clear();
1844 app.ttVisible = FALSE;
1845 SendMessage(app.hwndTT, TTM_TRACKACTIVATE, FALSE, 0);
1846 ::InvalidateRect(app.wBlame, NULL, FALSE);
1847 break;
1848 case WM_MOUSEMOVE:
1850 mevt.cbSize = sizeof(TRACKMOUSEEVENT);
1851 mevt.dwFlags = TME_LEAVE;
1852 mevt.dwHoverTime = HOVER_DEFAULT;
1853 mevt.hwndTrack = app.wBlame;
1854 ::TrackMouseEvent(&mevt);
1855 POINT pt = {((int)(short)LOWORD(lParam)), ((int)(short)HIWORD(lParam))};
1856 ClientToScreen(app.wBlame, &pt);
1857 pt.x += 15;
1858 pt.y += 15;
1859 SendMessage(app.hwndTT, TTM_TRACKPOSITION, 0, MAKELONG(pt.x, pt.y));
1860 if (!app.ttVisible)
1862 TOOLINFO ti;
1863 ti.cbSize = sizeof(TOOLINFO);
1864 ti.hwnd = app.wBlame;
1865 ti.uId = 0;
1866 SendMessage(app.hwndTT, TTM_TRACKACTIVATE, TRUE, (LPARAM)&ti);
1868 int y = ((int)(short)HIWORD(lParam));
1869 LONG_PTR line = app.SendEditor(SCI_GETFIRSTVISIBLELINE);
1870 LONG_PTR height = app.SendEditor(SCI_TEXTHEIGHT);
1871 line = line + (y/height);
1872 app.ttVisible = (line < (LONG)app.revs.size());
1873 if ( app.ttVisible )
1875 if (app.authors[line].compare(app.m_mouseauthor) != 0)
1877 app.m_mouseauthor = app.authors[line];
1879 if (app.revs[line] != app.m_mouserev)
1881 app.m_mouserev = app.revs[line];
1882 ::InvalidateRect(app.wBlame, NULL, FALSE);
1883 SendMessage(app.hwndTT, TTM_UPDATE, 0, 0);
1887 break;
1888 case WM_RBUTTONDOWN:
1889 // fall through
1890 case WM_LBUTTONDOWN:
1892 break;
1893 case WM_SETFOCUS:
1894 ::SetFocus(app.wBlame);
1895 app.SendEditor(SCI_GRABFOCUS);
1896 break;
1897 case WM_CONTEXTMENU:
1899 if (app.m_selectedrev <= 0)
1900 break;;
1901 int xPos = GET_X_LPARAM(lParam);
1902 int yPos = GET_Y_LPARAM(lParam);
1903 if ((xPos < 0)||(yPos < 0))
1905 // requested from keyboard, not mouse pointer
1906 // use the center of the window
1907 RECT rect;
1908 GetClientRect(app.wBlame, &rect);
1909 xPos = rect.right-rect.left;
1910 yPos = rect.bottom-rect.top;
1912 HMENU hMenu = LoadMenu(app.hResource, MAKEINTRESOURCE(IDR_BLAMEPOPUP));
1913 HMENU hPopMenu = GetSubMenu(hMenu, 0);
1915 if ( _tcslen(szOrigPath)==0 )
1917 // Without knowing the original path we cannot blame the previous revision
1918 // because we don't know which filename to pass to tortoiseproc.
1919 EnableMenuItem(hPopMenu,ID_BLAME_PREVIOUS_REVISION, MF_DISABLED|MF_GRAYED);
1922 TrackPopupMenu(hPopMenu, TPM_LEFTALIGN | TPM_RIGHTBUTTON, xPos, yPos, 0, app.wBlame, NULL);
1923 DestroyMenu(hMenu);
1925 break;
1926 default:
1927 return DefWindowProc(hWnd, message, wParam, lParam);
1929 return 0;
1932 LRESULT CALLBACK WndHeaderProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1934 PAINTSTRUCT ps;
1935 HDC hDC;
1936 switch (message)
1938 case WM_CREATE:
1939 return 0;
1940 case WM_PAINT:
1941 hDC = BeginPaint(app.wHeader, &ps);
1942 app.DrawHeader(hDC);
1943 EndPaint(app.wHeader, &ps);
1944 break;
1945 case WM_COMMAND:
1946 break;
1947 case WM_DESTROY:
1948 break;
1949 case WM_CLOSE:
1950 return 0;
1951 default:
1952 return DefWindowProc(hWnd, message, wParam, lParam);
1954 return 0;
1957 LRESULT CALLBACK WndLocatorProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1959 PAINTSTRUCT ps;
1960 HDC hDC;
1961 switch (message)
1963 case WM_PAINT:
1964 hDC = BeginPaint(app.wLocator, &ps);
1965 app.DrawLocatorBar(hDC);
1966 EndPaint(app.wLocator, &ps);
1967 break;
1968 case WM_LBUTTONDOWN:
1969 case WM_MOUSEMOVE:
1970 if (wParam & MK_LBUTTON)
1972 RECT rect;
1973 ::GetClientRect(hWnd, &rect);
1974 int nLine = HIWORD(lParam)*app.revs.size()/(rect.bottom-rect.top);
1976 if (nLine < 0)
1977 nLine = 0;
1978 app.ScrollToLine(nLine);
1980 break;
1981 default:
1982 return DefWindowProc(hWnd, message, wParam, lParam);
1984 return 0;
1986 #endif
1988 void CTortoiseGitBlameView::SetupLexer(CString filename)
1991 TCHAR *line;
1992 //const char * lineptr = _tcsrchr(filename, '.');
1993 int start=filename.ReverseFind(_T('.'));
1994 if (start>0)
1996 //_tcscpy_s(line, 20, lineptr+1);
1997 //_tcslwr_s(line, 20);
1998 CString ext=filename.Right(filename.GetLength()-start-1);
1999 line=ext.GetBuffer();
2001 if ((_tcscmp(line, _T("py"))==0)||
2002 (_tcscmp(line, _T("pyw"))==0)||
2003 (_tcscmp(line, _T("pyw"))==0))
2005 SendEditor(SCI_SETLEXER, SCLEX_PYTHON);
2006 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("and assert break class continue def del elif \
2007 else except exec finally for from global if import in is lambda None \
2008 not or pass print raise return try while yield")).GetBuffer()));
2009 SetAStyle(SCE_P_DEFAULT, black);
2010 SetAStyle(SCE_P_COMMENTLINE, darkGreen);
2011 SetAStyle(SCE_P_NUMBER, RGB(0, 0x80, 0x80));
2012 SetAStyle(SCE_P_STRING, RGB(0, 0, 0x80));
2013 SetAStyle(SCE_P_CHARACTER, RGB(0, 0, 0x80));
2014 SetAStyle(SCE_P_WORD, RGB(0x80, 0, 0x80));
2015 SetAStyle(SCE_P_TRIPLE, black);
2016 SetAStyle(SCE_P_TRIPLEDOUBLE, black);
2017 SetAStyle(SCE_P_CLASSNAME, darkBlue);
2018 SetAStyle(SCE_P_DEFNAME, darkBlue);
2019 SetAStyle(SCE_P_OPERATOR, darkBlue);
2020 SetAStyle(SCE_P_IDENTIFIER, darkBlue);
2021 SetAStyle(SCE_P_COMMENTBLOCK, darkGreen);
2022 SetAStyle(SCE_P_STRINGEOL, red);
2024 if ((_tcscmp(line, _T("c"))==0)||
2025 (_tcscmp(line, _T("cc"))==0)||
2026 (_tcscmp(line, _T("cpp"))==0)||
2027 (_tcscmp(line, _T("cxx"))==0)||
2028 (_tcscmp(line, _T("h"))==0)||
2029 (_tcscmp(line, _T("hh"))==0)||
2030 (_tcscmp(line, _T("hpp"))==0)||
2031 (_tcscmp(line, _T("hxx"))==0)||
2032 (_tcscmp(line, _T("dlg"))==0)||
2033 (_tcscmp(line, _T("mak"))==0))
2035 SendEditor(SCI_SETLEXER, SCLEX_CPP);
2036 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("and and_eq asm auto bitand bitor bool break \
2037 case catch char class compl const const_cast continue \
2038 default delete do double dynamic_cast else enum explicit export extern false float for \
2039 friend goto if inline int long mutable namespace new not not_eq \
2040 operator or or_eq private protected public \
2041 register reinterpret_cast return short signed sizeof static static_cast struct switch \
2042 template this throw true try typedef typeid typename union unsigned using \
2043 virtual void volatile wchar_t while xor xor_eq")).GetBuffer()));
2044 SendEditor(SCI_SETKEYWORDS, 3, (LPARAM)(m_TextView.StringForControl(_T("a addindex addtogroup anchor arg attention \
2045 author b brief bug c class code date def defgroup deprecated dontinclude \
2046 e em endcode endhtmlonly endif endlatexonly endlink endverbatim enum example exception \
2047 f$ f[ f] file fn hideinitializer htmlinclude htmlonly \
2048 if image include ingroup internal invariant interface latexonly li line link \
2049 mainpage name namespace nosubgrouping note overload \
2050 p page par param post pre ref relates remarks return retval \
2051 sa section see showinitializer since skip skipline struct subsection \
2052 test throw todo typedef union until \
2053 var verbatim verbinclude version warning weakgroup $ @ \\ & < > # { }")).GetBuffer()));
2054 SetupCppLexer();
2056 if (_tcscmp(line, _T("cs"))==0)
2058 SendEditor(SCI_SETLEXER, SCLEX_CPP);
2059 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("abstract as base bool break byte case catch char checked class \
2060 const continue decimal default delegate do double else enum \
2061 event explicit extern false finally fixed float for foreach goto if \
2062 implicit in int interface internal is lock long namespace new null \
2063 object operator out override params private protected public \
2064 readonly ref return sbyte sealed short sizeof stackalloc static \
2065 string struct switch this throw true try typeof uint ulong \
2066 unchecked unsafe ushort using virtual void while")).GetBuffer()));
2067 SetupCppLexer();
2069 if ((_tcscmp(line, _T("rc"))==0)||
2070 (_tcscmp(line, _T("rc2"))==0))
2072 SendEditor(SCI_SETLEXER, SCLEX_CPP);
2073 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("ACCELERATORS ALT AUTO3STATE AUTOCHECKBOX AUTORADIOBUTTON \
2074 BEGIN BITMAP BLOCK BUTTON CAPTION CHARACTERISTICS CHECKBOX CLASS \
2075 COMBOBOX CONTROL CTEXT CURSOR DEFPUSHBUTTON DIALOG DIALOGEX DISCARDABLE \
2076 EDITTEXT END EXSTYLE FONT GROUPBOX ICON LANGUAGE LISTBOX LTEXT \
2077 MENU MENUEX MENUITEM MESSAGETABLE POPUP \
2078 PUSHBUTTON RADIOBUTTON RCDATA RTEXT SCROLLBAR SEPARATOR SHIFT STATE3 \
2079 STRINGTABLE STYLE TEXTINCLUDE VALUE VERSION VERSIONINFO VIRTKEY")).GetBuffer()));
2080 SetupCppLexer();
2082 if ((_tcscmp(line, _T("idl"))==0)||
2083 (_tcscmp(line, _T("odl"))==0))
2085 SendEditor(SCI_SETLEXER, SCLEX_CPP);
2086 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("aggregatable allocate appobject arrays async async_uuid \
2087 auto_handle \
2088 bindable boolean broadcast byte byte_count \
2089 call_as callback char coclass code comm_status \
2090 const context_handle context_handle_noserialize \
2091 context_handle_serialize control cpp_quote custom \
2092 decode default defaultbind defaultcollelem \
2093 defaultvalue defaultvtable dispinterface displaybind dllname \
2094 double dual \
2095 enable_allocate encode endpoint entry enum error_status_t \
2096 explicit_handle \
2097 fault_status first_is float \
2098 handle_t heap helpcontext helpfile helpstring \
2099 helpstringcontext helpstringdll hidden hyper \
2100 id idempotent ignore iid_as iid_is immediatebind implicit_handle \
2101 import importlib in include in_line int __int64 __int3264 interface \
2102 last_is lcid length_is library licensed local long \
2103 max_is maybe message methods midl_pragma \
2104 midl_user_allocate midl_user_free min_is module ms_union \
2105 ncacn_at_dsp ncacn_dnet_nsp ncacn_http ncacn_ip_tcp \
2106 ncacn_nb_ipx ncacn_nb_nb ncacn_nb_tcp ncacn_np \
2107 ncacn_spx ncacn_vns_spp ncadg_ip_udp ncadg_ipx ncadg_mq \
2108 ncalrpc nocode nonbrowsable noncreatable nonextensible notify \
2109 object odl oleautomation optimize optional out out_of_line \
2110 pipe pointer_default pragma properties propget propput propputref \
2111 ptr public \
2112 range readonly ref represent_as requestedit restricted retval \
2113 shape short signed size_is small source strict_context_handle \
2114 string struct switch switch_is switch_type \
2115 transmit_as typedef \
2116 uidefault union unique unsigned user_marshal usesgetlasterror uuid \
2117 v1_enum vararg version void wchar_t wire_marshal")).GetBuffer()));
2118 SetupCppLexer();
2120 if (_tcscmp(line, _T("java"))==0)
2122 SendEditor(SCI_SETLEXER, SCLEX_CPP);
2123 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("abstract assert boolean break byte case catch char class \
2124 const continue default do double else extends final finally float for future \
2125 generic goto if implements import inner instanceof int interface long \
2126 native new null outer package private protected public rest \
2127 return short static super switch synchronized this throw throws \
2128 transient try var void volatile while")).GetBuffer()));
2129 SetupCppLexer();
2131 if (_tcscmp(line, _T("js"))==0)
2133 SendEditor(SCI_SETLEXER, SCLEX_CPP);
2134 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("abstract boolean break byte case catch char class \
2135 const continue debugger default delete do double else enum export extends \
2136 final finally float for function goto if implements import in instanceof \
2137 int interface long native new package private protected public \
2138 return short static super switch synchronized this throw throws \
2139 transient try typeof var void volatile while with")).GetBuffer()));
2140 SetupCppLexer();
2142 if ((_tcscmp(line, _T("pas"))==0)||
2143 (_tcscmp(line, _T("dpr"))==0)||
2144 (_tcscmp(line, _T("pp"))==0))
2146 SendEditor(SCI_SETLEXER, SCLEX_PASCAL);
2147 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("and array as begin case class const constructor \
2148 destructor div do downto else end except file finally \
2149 for function goto if implementation in inherited \
2150 interface is mod not object of on or packed \
2151 procedure program property raise record repeat \
2152 set shl shr then threadvar to try type unit \
2153 until uses var while with xor")).GetBuffer()));
2154 SetupCppLexer();
2156 if ((_tcscmp(line, _T("as"))==0)||
2157 (_tcscmp(line, _T("asc"))==0)||
2158 (_tcscmp(line, _T("jsfl"))==0))
2160 SendEditor(SCI_SETLEXER, SCLEX_CPP);
2161 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("add and break case catch class continue default delete do \
2162 dynamic else eq extends false finally for function ge get gt if implements import in \
2163 instanceof interface intrinsic le lt ne new not null or private public return \
2164 set static super switch this throw true try typeof undefined var void while with")).GetBuffer()));
2165 SendEditor(SCI_SETKEYWORDS, 1, (LPARAM)(m_TextView.StringForControl(_T("Array Arguments Accessibility Boolean Button Camera Color \
2166 ContextMenu ContextMenuItem Date Error Function Key LoadVars LocalConnection Math \
2167 Microphone Mouse MovieClip MovieClipLoader NetConnection NetStream Number Object \
2168 PrintJob Selection SharedObject Sound Stage String StyleSheet System TextField \
2169 TextFormat TextSnapshot Video Void XML XMLNode XMLSocket \
2170 _accProps _focusrect _global _highquality _parent _quality _root _soundbuftime \
2171 arguments asfunction call capabilities chr clearInterval duplicateMovieClip \
2172 escape eval fscommand getProperty getTimer getURL getVersion gotoAndPlay gotoAndStop \
2173 ifFrameLoaded Infinity -Infinity int isFinite isNaN length loadMovie loadMovieNum \
2174 loadVariables loadVariablesNum maxscroll mbchr mblength mbord mbsubstring MMExecute \
2175 NaN newline nextFrame nextScene on onClipEvent onUpdate ord parseFloat parseInt play \
2176 prevFrame prevScene print printAsBitmap printAsBitmapNum printNum random removeMovieClip \
2177 scroll set setInterval setProperty startDrag stop stopAllSounds stopDrag substring \
2178 targetPath tellTarget toggleHighQuality trace unescape unloadMovie unLoadMovieNum updateAfterEvent")).GetBuffer()));
2179 SetupCppLexer();
2181 if ((_tcscmp(line, _T("html"))==0)||
2182 (_tcscmp(line, _T("htm"))==0)||
2183 (_tcscmp(line, _T("shtml"))==0)||
2184 (_tcscmp(line, _T("htt"))==0)||
2185 (_tcscmp(line, _T("xml"))==0)||
2186 (_tcscmp(line, _T("asp"))==0)||
2187 (_tcscmp(line, _T("xsl"))==0)||
2188 (_tcscmp(line, _T("php"))==0)||
2189 (_tcscmp(line, _T("xhtml"))==0)||
2190 (_tcscmp(line, _T("phtml"))==0)||
2191 (_tcscmp(line, _T("cfm"))==0)||
2192 (_tcscmp(line, _T("tpl"))==0)||
2193 (_tcscmp(line, _T("dtd"))==0)||
2194 (_tcscmp(line, _T("hta"))==0)||
2195 (_tcscmp(line, _T("htd"))==0)||
2196 (_tcscmp(line, _T("wxs"))==0))
2198 SendEditor(SCI_SETLEXER, SCLEX_HTML);
2199 SendEditor(SCI_SETSTYLEBITS, 7);
2200 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("a abbr acronym address applet area b base basefont \
2201 bdo big blockquote body br button caption center \
2202 cite code col colgroup dd del dfn dir div dl dt em \
2203 fieldset font form frame frameset h1 h2 h3 h4 h5 h6 \
2204 head hr html i iframe img input ins isindex kbd label \
2205 legend li link map menu meta noframes noscript \
2206 object ol optgroup option p param pre q s samp \
2207 script select small span strike strong style sub sup \
2208 table tbody td textarea tfoot th thead title tr tt u ul \
2209 var xml xmlns abbr accept-charset accept accesskey action align alink \
2210 alt archive axis background bgcolor border \
2211 cellpadding cellspacing char charoff charset checked cite \
2212 class classid clear codebase codetype color cols colspan \
2213 compact content coords \
2214 data datafld dataformatas datapagesize datasrc datetime \
2215 declare defer dir disabled enctype event \
2216 face for frame frameborder \
2217 headers height href hreflang hspace http-equiv \
2218 id ismap label lang language leftmargin link longdesc \
2219 marginwidth marginheight maxlength media method multiple \
2220 name nohref noresize noshade nowrap \
2221 object onblur onchange onclick ondblclick onfocus \
2222 onkeydown onkeypress onkeyup onload onmousedown \
2223 onmousemove onmouseover onmouseout onmouseup \
2224 onreset onselect onsubmit onunload \
2225 profile prompt readonly rel rev rows rowspan rules \
2226 scheme scope selected shape size span src standby start style \
2227 summary tabindex target text title topmargin type usemap \
2228 valign value valuetype version vlink vspace width \
2229 text password checkbox radio submit reset \
2230 file hidden image")).GetBuffer()));
2231 SendEditor(SCI_SETKEYWORDS, 1, (LPARAM)(m_TextView.StringForControl(_T("assign audio block break catch choice clear disconnect else elseif \
2232 emphasis enumerate error exit field filled form goto grammar help \
2233 if initial link log menu meta noinput nomatch object option p paragraph \
2234 param phoneme prompt property prosody record reprompt return s say-as \
2235 script sentence subdialog submit throw transfer value var voice vxml")).GetBuffer()));
2236 SendEditor(SCI_SETKEYWORDS, 2, (LPARAM)(m_TextView.StringForControl(_T("accept age alphabet anchor application base beep bridge category charset \
2237 classid cond connecttimeout content contour count dest destexpr dtmf dtmfterm \
2238 duration enctype event eventexpr expr expritem fetchtimeout finalsilence \
2239 gender http-equiv id level maxage maxstale maxtime message messageexpr \
2240 method mime modal mode name namelist next nextitem ph pitch range rate \
2241 scope size sizeexpr skiplist slot src srcexpr sub time timeexpr timeout \
2242 transferaudio type value variant version volume xml:lang")).GetBuffer()));
2243 SendEditor(SCI_SETKEYWORDS, 3, (LPARAM)(m_TextView.StringForControl(_T("and assert break class continue def del elif \
2244 else except exec finally for from global if import in is lambda None \
2245 not or pass print raise return try while yield")).GetBuffer()));
2246 SendEditor(SCI_SETKEYWORDS, 4, (LPARAM)(m_TextView.StringForControl(_T("and argv as argc break case cfunction class continue declare default do \
2247 die echo else elseif empty enddeclare endfor endforeach endif endswitch \
2248 endwhile e_all e_parse e_error e_warning eval exit extends false for \
2249 foreach function global http_cookie_vars http_get_vars http_post_vars \
2250 http_post_files http_env_vars http_server_vars if include include_once \
2251 list new not null old_function or parent php_os php_self php_version \
2252 print require require_once return static switch stdclass this true var \
2253 xor virtual while __file__ __line__ __sleep __wakeup")).GetBuffer()));
2255 SetAStyle(SCE_H_TAG, darkBlue);
2256 SetAStyle(SCE_H_TAGUNKNOWN, red);
2257 SetAStyle(SCE_H_ATTRIBUTE, darkBlue);
2258 SetAStyle(SCE_H_ATTRIBUTEUNKNOWN, red);
2259 SetAStyle(SCE_H_NUMBER, RGB(0x80,0,0x80));
2260 SetAStyle(SCE_H_DOUBLESTRING, RGB(0,0x80,0));
2261 SetAStyle(SCE_H_SINGLESTRING, RGB(0,0x80,0));
2262 SetAStyle(SCE_H_OTHER, RGB(0x80,0,0x80));
2263 SetAStyle(SCE_H_COMMENT, RGB(0x80,0x80,0));
2264 SetAStyle(SCE_H_ENTITY, RGB(0x80,0,0x80));
2266 SetAStyle(SCE_H_TAGEND, darkBlue);
2267 SetAStyle(SCE_H_XMLSTART, darkBlue); // <?
2268 SetAStyle(SCE_H_QUESTION, darkBlue); // <?
2269 SetAStyle(SCE_H_XMLEND, darkBlue); // ?>
2270 SetAStyle(SCE_H_SCRIPT, darkBlue); // <script
2271 SetAStyle(SCE_H_ASP, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <% ... %>
2272 SetAStyle(SCE_H_ASPAT, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <%@ ... %>
2274 SetAStyle(SCE_HB_DEFAULT, black);
2275 SetAStyle(SCE_HB_COMMENTLINE, darkGreen);
2276 SetAStyle(SCE_HB_NUMBER, RGB(0,0x80,0x80));
2277 SetAStyle(SCE_HB_WORD, darkBlue);
2278 SendEditor(SCI_STYLESETBOLD, SCE_HB_WORD, 1);
2279 SetAStyle(SCE_HB_STRING, RGB(0x80,0,0x80));
2280 SetAStyle(SCE_HB_IDENTIFIER, black);
2282 // This light blue is found in the windows system palette so is safe to use even in 256 colour modes.
2283 // Show the whole section of VBScript with light blue background
2284 for (int bstyle=SCE_HB_DEFAULT; bstyle<=SCE_HB_STRINGEOL; bstyle++) {
2285 SendEditor(SCI_STYLESETFONT, bstyle,
2286 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
2287 SendEditor(SCI_STYLESETBACK, bstyle, lightBlue);
2288 // This call extends the backround colour of the last style on the line to the edge of the window
2289 SendEditor(SCI_STYLESETEOLFILLED, bstyle, 1);
2291 SendEditor(SCI_STYLESETBACK, SCE_HB_STRINGEOL, RGB(0x7F,0x7F,0xFF));
2292 SendEditor(SCI_STYLESETFONT, SCE_HB_COMMENTLINE,
2293 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
2295 SetAStyle(SCE_HBA_DEFAULT, black);
2296 SetAStyle(SCE_HBA_COMMENTLINE, darkGreen);
2297 SetAStyle(SCE_HBA_NUMBER, RGB(0,0x80,0x80));
2298 SetAStyle(SCE_HBA_WORD, darkBlue);
2299 SendEditor(SCI_STYLESETBOLD, SCE_HBA_WORD, 1);
2300 SetAStyle(SCE_HBA_STRING, RGB(0x80,0,0x80));
2301 SetAStyle(SCE_HBA_IDENTIFIER, black);
2303 // Show the whole section of ASP VBScript with bright yellow background
2304 for (int bastyle=SCE_HBA_DEFAULT; bastyle<=SCE_HBA_STRINGEOL; bastyle++) {
2305 SendEditor(SCI_STYLESETFONT, bastyle,
2306 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
2307 SendEditor(SCI_STYLESETBACK, bastyle, RGB(0xFF, 0xFF, 0));
2308 // This call extends the backround colour of the last style on the line to the edge of the window
2309 SendEditor(SCI_STYLESETEOLFILLED, bastyle, 1);
2311 SendEditor(SCI_STYLESETBACK, SCE_HBA_STRINGEOL, RGB(0xCF,0xCF,0x7F));
2312 SendEditor(SCI_STYLESETFONT, SCE_HBA_COMMENTLINE,
2313 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
2315 // If there is no need to support embedded Javascript, the following code can be dropped.
2316 // Javascript will still be correctly processed but will be displayed in just the default style.
2318 SetAStyle(SCE_HJ_START, RGB(0x80,0x80,0));
2319 SetAStyle(SCE_HJ_DEFAULT, black);
2320 SetAStyle(SCE_HJ_COMMENT, darkGreen);
2321 SetAStyle(SCE_HJ_COMMENTLINE, darkGreen);
2322 SetAStyle(SCE_HJ_COMMENTDOC, darkGreen);
2323 SetAStyle(SCE_HJ_NUMBER, RGB(0,0x80,0x80));
2324 SetAStyle(SCE_HJ_WORD, black);
2325 SetAStyle(SCE_HJ_KEYWORD, darkBlue);
2326 SetAStyle(SCE_HJ_DOUBLESTRING, RGB(0x80,0,0x80));
2327 SetAStyle(SCE_HJ_SINGLESTRING, RGB(0x80,0,0x80));
2328 SetAStyle(SCE_HJ_SYMBOLS, black);
2330 SetAStyle(SCE_HJA_START, RGB(0x80,0x80,0));
2331 SetAStyle(SCE_HJA_DEFAULT, black);
2332 SetAStyle(SCE_HJA_COMMENT, darkGreen);
2333 SetAStyle(SCE_HJA_COMMENTLINE, darkGreen);
2334 SetAStyle(SCE_HJA_COMMENTDOC, darkGreen);
2335 SetAStyle(SCE_HJA_NUMBER, RGB(0,0x80,0x80));
2336 SetAStyle(SCE_HJA_WORD, black);
2337 SetAStyle(SCE_HJA_KEYWORD, darkBlue);
2338 SetAStyle(SCE_HJA_DOUBLESTRING, RGB(0x80,0,0x80));
2339 SetAStyle(SCE_HJA_SINGLESTRING, RGB(0x80,0,0x80));
2340 SetAStyle(SCE_HJA_SYMBOLS, black);
2342 SetAStyle(SCE_HPHP_DEFAULT, black);
2343 SetAStyle(SCE_HPHP_HSTRING, RGB(0x80,0,0x80));
2344 SetAStyle(SCE_HPHP_SIMPLESTRING, RGB(0x80,0,0x80));
2345 SetAStyle(SCE_HPHP_WORD, darkBlue);
2346 SetAStyle(SCE_HPHP_NUMBER, RGB(0,0x80,0x80));
2347 SetAStyle(SCE_HPHP_VARIABLE, red);
2348 SetAStyle(SCE_HPHP_HSTRING_VARIABLE, red);
2349 SetAStyle(SCE_HPHP_COMPLEX_VARIABLE, red);
2350 SetAStyle(SCE_HPHP_COMMENT, darkGreen);
2351 SetAStyle(SCE_HPHP_COMMENTLINE, darkGreen);
2352 SetAStyle(SCE_HPHP_OPERATOR, darkBlue);
2354 // Show the whole section of Javascript with off white background
2355 for (int jstyle=SCE_HJ_DEFAULT; jstyle<=SCE_HJ_SYMBOLS; jstyle++) {
2356 SendEditor(SCI_STYLESETFONT, jstyle,
2357 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
2358 SendEditor(SCI_STYLESETBACK, jstyle, offWhite);
2359 SendEditor(SCI_STYLESETEOLFILLED, jstyle, 1);
2361 SendEditor(SCI_STYLESETBACK, SCE_HJ_STRINGEOL, RGB(0xDF, 0xDF, 0x7F));
2362 SendEditor(SCI_STYLESETEOLFILLED, SCE_HJ_STRINGEOL, 1);
2364 // Show the whole section of Javascript with brown background
2365 for (int jastyle=SCE_HJA_DEFAULT; jastyle<=SCE_HJA_SYMBOLS; jastyle++) {
2366 SendEditor(SCI_STYLESETFONT, jastyle,
2367 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
2368 SendEditor(SCI_STYLESETBACK, jastyle, RGB(0xDF, 0xDF, 0x7F));
2369 SendEditor(SCI_STYLESETEOLFILLED, jastyle, 1);
2371 SendEditor(SCI_STYLESETBACK, SCE_HJA_STRINGEOL, RGB(0x0,0xAF,0x5F));
2372 SendEditor(SCI_STYLESETEOLFILLED, SCE_HJA_STRINGEOL, 1);
2375 else
2377 SendEditor(SCI_SETLEXER, SCLEX_CPP);
2378 SetupCppLexer();
2380 SendEditor(SCI_COLOURISE, 0, -1);
2384 void CTortoiseGitBlameView::SetupCppLexer()
2386 SetAStyle(SCE_C_DEFAULT, RGB(0, 0, 0));
2387 SetAStyle(SCE_C_COMMENT, RGB(0, 0x80, 0));
2388 SetAStyle(SCE_C_COMMENTLINE, RGB(0, 0x80, 0));
2389 SetAStyle(SCE_C_COMMENTDOC, RGB(0, 0x80, 0));
2390 SetAStyle(SCE_C_COMMENTLINEDOC, RGB(0, 0x80, 0));
2391 SetAStyle(SCE_C_COMMENTDOCKEYWORD, RGB(0, 0x80, 0));
2392 SetAStyle(SCE_C_COMMENTDOCKEYWORDERROR, RGB(0, 0x80, 0));
2393 SetAStyle(SCE_C_NUMBER, RGB(0, 0x80, 0x80));
2394 SetAStyle(SCE_C_WORD, RGB(0, 0, 0x80));
2395 SendEditor(SCE_C_WORD, 1);
2396 SetAStyle(SCE_C_STRING, RGB(0x80, 0, 0x80));
2397 SetAStyle(SCE_C_IDENTIFIER, RGB(0, 0, 0));
2398 SetAStyle(SCE_C_PREPROCESSOR, RGB(0x80, 0, 0));
2399 SetAStyle(SCE_C_OPERATOR, RGB(0x80, 0x80, 0));
2403 void CTortoiseGitBlameView::UpdateInfo()
2405 CString &data = GetDocument()->m_BlameData;
2406 CString one;
2407 int pos=0;
2409 CLogDataVector * pRevs= GetLogData();
2411 this->m_CommitHash.clear();
2412 this->m_Authors.clear();
2413 this->m_ID.clear();
2414 CString line;
2416 CreateFont();
2418 SendEditor(SCI_SETREADONLY, FALSE);
2419 SendEditor(SCI_CLEARALL);
2420 SendEditor(EM_EMPTYUNDOBUFFER);
2421 SendEditor(SCI_SETSAVEPOINT);
2422 SendEditor(SCI_CANCEL);
2423 SendEditor(SCI_SETUNDOCOLLECTION, 0);
2425 while( pos>=0 )
2427 one=data.Tokenize(_T("\n"),pos);
2428 if(one.IsEmpty())
2429 continue;
2430 m_CommitHash.push_back(one.Left(40));
2431 int start=0;
2432 start=one.Find(_T(')'),40);
2433 if(start>0)
2435 line=one.Right(one.GetLength()-start-2);
2436 this->m_TextView.InsertText(line,true);
2438 int id=pRevs->m_HashMap[one.Left(40)];
2439 if(id>=0 && id <GetLogData()->size())
2441 m_ID.push_back(pRevs->size()-id);
2442 m_Authors.push_back(pRevs->at(id).m_AuthorName);
2443 }else
2445 ASSERT(FALSE);
2449 SetupLexer(GetDocument()->m_CurrentFileName);
2451 SendEditor(SCI_SETUNDOCOLLECTION, 1);
2452 SendEditor(EM_EMPTYUNDOBUFFER);
2453 SendEditor(SCI_SETSAVEPOINT);
2454 SendEditor(SCI_GOTOPOS, 0);
2455 SendEditor(SCI_SETSCROLLWIDTHTRACKING, TRUE);
2456 SendEditor(SCI_SETREADONLY, TRUE);
2458 m_lowestrev=1;
2459 m_highestrev=this->GetLogData()->size();
2461 GetBlameWidth();
2462 CRect rect;
2463 this->GetClientRect(rect);
2464 //this->m_TextView.GetWindowRect(rect);
2465 //this->m_TextView.ScreenToClient(rect);
2466 rect.left=this->m_blamewidth;
2467 this->m_TextView.MoveWindow(rect);
2469 this->Invalidate();
2472 CGitBlameLogList * CTortoiseGitBlameView::GetLogList()
2474 return &(GetDocument()->GetMainFrame()->m_wndOutput.m_LogList);
2478 CLogDataVector * CTortoiseGitBlameView::GetLogData()
2480 return &(GetDocument()->GetMainFrame()->m_wndOutput.m_LogList.m_logEntries);
2483 void CTortoiseGitBlameView::OnSciPainted(NMHDR *,LRESULT *)
2485 this->Invalidate();
2488 void CTortoiseGitBlameView::OnLButtonDown(UINT nFlags,CPoint point)
2491 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
2492 LONG_PTR height = SendEditor(SCI_TEXTHEIGHT);
2493 line = line + (point.y/height);
2495 if (line < (LONG)m_CommitHash.size())
2497 SetSelectedLine(line);
2498 if (m_CommitHash[line] != m_SelectedHash)
2500 m_SelectedHash = m_CommitHash[line];
2501 // app.m_selectedorigrev = app.origrevs[line];
2502 // app.m_selectedauthor = app.authors[line];
2503 // app.m_selecteddate = app.dates[line];
2506 this->GetLogList()->SetItemState(this->GetLogList()->GetItemCount()-m_ID[line],
2507 LVIS_SELECTED,
2508 LVIS_SELECTED);
2510 GitRev *pRev;
2511 pRev=&this->GetLogData()->at(this->GetLogList()->GetItemCount()-m_ID[line]);
2512 this->GetDocument()->GetMainFrame()->m_wndProperties.UpdateProperties(pRev);
2514 else
2516 m_SelectedHash.Empty();
2517 // app.m_selecteddate.clear();
2518 // app.m_selectedrev = -2;
2519 // app.m_selectedorigrev = -2;
2521 //::InvalidateRect( NULL, FALSE);
2522 this->Invalidate();
2523 this->m_TextView.Invalidate();
2526 else
2528 SetSelectedLine(-1);
2531 CView::OnLButtonDown(nFlags,point);
2534 void CTortoiseGitBlameView::OnSciGetBkColor(NMHDR* hdr, LRESULT* result)
2537 SCNotification *notification=reinterpret_cast<SCNotification *>(hdr);
2539 if ((m_colorage)&&(notification->line < (int)m_CommitHash.size()))
2541 if(m_CommitHash[notification->line] == this->m_SelectedHash )
2542 notification->lParam = m_selectedauthorcolor;
2543 else
2544 notification->lParam = InterColor(DWORD(m_regOldLinesColor), DWORD(m_regNewLinesColor), (m_ID[notification->line]-m_lowestrev)*100/((m_highestrev-m_lowestrev)+1));
2549 void CTortoiseGitBlameView::FocusOn(GitRev *pRev)
2551 m_SelectedHash = pRev->m_CommitHash;
2553 //GitRev *pRev;
2554 //pRev=&this->GetLogData()->at(this->GetLogList()->GetItemCount()-m_ID[line]);
2555 this->GetDocument()->GetMainFrame()->m_wndProperties.UpdateProperties(pRev);
2557 this->Invalidate();
2558 this->m_TextView.Invalidate();
2562 void CTortoiseGitBlameView::OnMouseHover(UINT nFlags, CPoint point)
2565 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
2566 LONG_PTR height = SendEditor(SCI_TEXTHEIGHT);
2567 line = line + (point.y/height);
2569 if (line < (LONG)m_CommitHash.size())
2571 if (line != m_MouseLine)
2573 m_MouseLine = line;//m_CommitHash[line];
2574 // app.m_selectedorigrev = app.origrevs[line];
2575 // app.m_selectedauthor = app.authors[line];
2576 // app.m_selecteddate = app.dates[line];
2579 GitRev *pRev;
2580 pRev=&this->GetLogData()->at(this->GetLogList()->GetItemCount()-m_ID[line]);
2581 //this->GetDocument()->GetMainFrame()->m_wndProperties.UpdateProperties(pRev);
2582 this->ClientToScreen(&point);
2583 //BALLOON_INFO bi;
2584 //if(m_ToolTip.GetTool(this, bi))
2586 // bi.sBalloonTip=pRev->m_CommitHash;
2587 CString str;
2588 str.Format(_T("%s\n<b>%s</b>\n%s\n%s"),pRev->m_CommitHash,
2589 pRev->m_Subject,
2590 pRev->m_AuthorDate.Format(_T("%Y-%m-%d %H:%M")),
2591 pRev->m_Body);
2592 m_ToolTip.AddTool(this,str);
2593 m_ToolTip.DisplayToolTip(&point);
2596 CRect rect;
2597 this->ScreenToClient(&point);
2598 rect.left=LOCATOR_WIDTH;
2599 rect.right=this->m_blamewidth+rect.left;
2600 rect.top=point.y-height;
2601 rect.bottom=point.y+height;
2602 this->InvalidateRect(rect);
2605 else
2607 m_MouseLine=-1;
2608 // app.m_selecteddate.clear();
2609 // app.m_selectedrev = -2;
2610 // app.m_selectedorigrev = -2;
2612 //::InvalidateRect( NULL, FALSE);
2613 //this->Invalidate();
2616 // const CString str=_T("this is a <b>Message Balloon</b>\n<hr=100%>\n<ct=0x0000FF>Warning! Warning!</ct>\nSomething unexpected happened");
2617 //CBalloon::ShowBalloon(NULL, point,
2618 // str,
2619 // FALSE, (HICON)IDI_EXCLAMATION,
2620 // (UINT)CBalloon ::BALLOON_RIGHT_TOP, (UINT)CBalloon ::BALLOON_EFFECT_SOLID,(COLORREF)NULL, (COLORREF)NULL, (COLORREF)NULL);
2623 void CTortoiseGitBlameView::OnMouseMove(UINT nFlags, CPoint point)
2625 TRACKMOUSEEVENT tme;
2626 tme.cbSize=sizeof(TRACKMOUSEEVENT);
2627 tme.dwFlags=TME_HOVER|TME_LEAVE;
2628 tme.hwndTrack=this->m_hWnd;
2629 tme.dwHoverTime=1;
2630 TrackMouseEvent(&tme);
2634 BOOL CTortoiseGitBlameView::PreTranslateMessage(MSG* pMsg)
2636 m_ToolTip.RelayEvent(pMsg);
2637 return CView::PreTranslateMessage(pMsg);
2640 void CTortoiseGitBlameView::OnEditFind()
2642 m_pFindDialog=new CFindReplaceDialog();
2644 m_pFindDialog->Create(TRUE,_T(""),NULL,FR_DOWN,this);
2647 void CTortoiseGitBlameView::OnEditGoto()
2649 CEditGotoDlg dlg;
2650 if(dlg.DoModal()==IDOK)
2652 this->GotoLine(dlg.m_LineNumber);
2656 LRESULT CTortoiseGitBlameView::OnFindDialogMessage(WPARAM wParam, LPARAM lParam)//Õâ¸öÒ²ÊÇÕÒÄǸö³ÌÐò¸ÄµÄ£¬Ö»²»¹ý»»³ÉÁË×Ô¼ºµÄÀà
2658 ASSERT(m_pFindDialog != NULL);
2660 // If the FR_DIALOGTERM flag is set,
2661 // invalidate the handle identifying the dialog box.
2662 if (m_pFindDialog->IsTerminating())
2664 m_pFindDialog = NULL;
2665 return 0;
2668 // If the FR_FINDNEXT flag is set,
2669 // call the application-defined search routine
2670 // to search for the requested string.
2671 if(m_pFindDialog->FindNext())
2673 //read data from dialog
2674 CString FindName = m_pFindDialog->GetFindString();
2675 bool bMatchCase = m_pFindDialog->MatchCase() == TRUE;
2676 bool bMatchWholeWord = m_pFindDialog->MatchWholeWord() == TRUE;
2677 bool bSearchDown = m_pFindDialog->SearchDown() == TRUE;
2679 DoSearch(FindName,m_pFindDialog->m_fr.Flags);
2680 //with given name do search
2681 // *FindWhatYouNeed(FindName, bMatchCase, bMatchWholeWord, bSearchDown);
2684 return 0;