cleanup .gitignore
[TortoiseGit.git] / src / TortoiseGitBlame / TortoiseGitBlameView.cpp
blobb514bc50f5ed7f30a4638ba53459e32e09168404
1 // TortoiseGitBlame - a Viewer for Git Blames
3 // Copyright (C) 2008-2012 - TortoiseGit
4 // Copyright (C) 2010-2012 Sven Strickroth <email@cs-ware.de>
5 // Copyright (C) 2003-2008 - TortoiseSVN
7 // Copyright (C)2003 Don HO <donho@altern.org>
9 // This program is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU General Public License
11 // as published by the Free Software Foundation; either version 2
12 // of the License, or (at your option) any later version.
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software Foundation,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 // CTortoiseGitBlameView.cpp : implementation of the CTortoiseGitBlameView class
26 #include "stdafx.h"
27 #include "TortoiseGitBlame.h"
28 #include "CommonAppUtils.h"
29 #include "TortoiseGitBlameDoc.h"
30 #include "TortoiseGitBlameView.h"
31 #include "MainFrm.h"
32 #include "EditGotoDlg.h"
33 #include "LoglistUtils.h"
34 #include "FileTextLines.h"
35 #include "UniCodeUtils.h"
36 #include "MenuEncode.h"
37 #include "gitdll.h"
38 #include "SysInfo.h"
40 #ifdef _DEBUG
41 #define new DEBUG_NEW
42 #endif
44 UINT CTortoiseGitBlameView::m_FindDialogMessage;
46 // CTortoiseGitBlameView
47 IMPLEMENT_DYNAMIC(CSciEditBlame,CSciEdit)
49 IMPLEMENT_DYNCREATE(CTortoiseGitBlameView, CView)
51 BEGIN_MESSAGE_MAP(CTortoiseGitBlameView, CView)
52 // Standard printing commands
53 ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
54 ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
55 ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CTortoiseGitBlameView::OnFilePrintPreview)
56 ON_COMMAND(ID_EDIT_FIND,OnEditFind)
57 ON_COMMAND(ID_EDIT_GOTO,OnEditGoto)
58 ON_COMMAND(ID_EDIT_COPY,CopySelectedLogToClipboard)
59 ON_COMMAND(ID_VIEW_NEXT,OnViewNext)
60 ON_COMMAND(ID_VIEW_PREV,OnViewPrev)
61 ON_COMMAND(ID_VIEW_SHOWAUTHOR, OnViewToggleAuthor)
62 ON_UPDATE_COMMAND_UI(ID_VIEW_SHOWAUTHOR, OnUpdateViewToggleAuthor)
63 ON_COMMAND(ID_VIEW_FOLLOWRENAMES, OnViewToggleFollowRenames)
64 ON_UPDATE_COMMAND_UI(ID_VIEW_FOLLOWRENAMES, OnUpdateViewToggleFollowRenames)
65 ON_COMMAND(ID_BLAMEPOPUP_COPYHASHTOCLIPBOARD, CopyHashToClipboard)
66 ON_COMMAND(ID_BLAMEPOPUP_COPYLOGTOCLIPBOARD, CopySelectedLogToClipboard)
67 ON_COMMAND(ID_BLAMEPOPUP_BLAMEPREVIOUSREVISION, BlamePreviousRevision)
68 ON_COMMAND(ID_BLAMEPOPUP_DIFFPREVIOUS, DiffPreviousRevision)
69 ON_COMMAND(ID_BLAMEPOPUP_SHOWLOG, ShowLog)
70 ON_UPDATE_COMMAND_UI(ID_BLAMEPOPUP_BLAMEPREVIOUSREVISION, OnUpdateBlamePopupBlamePrevious)
71 ON_UPDATE_COMMAND_UI(ID_BLAMEPOPUP_DIFFPREVIOUS, OnUpdateBlamePopupDiffPrevious)
72 ON_COMMAND_RANGE(IDM_FORMAT_ENCODE, IDM_FORMAT_ENCODE_END, OnChangeEncode)
73 ON_WM_CREATE()
74 ON_WM_SIZE()
75 ON_WM_MOUSEMOVE()
76 ON_WM_MOUSEHOVER()
77 ON_WM_MOUSELEAVE()
78 ON_WM_LBUTTONDOWN()
79 ON_WM_RBUTTONDOWN()
80 ON_WM_RBUTTONUP()
81 ON_NOTIFY(SCN_PAINTED,0,OnSciPainted)
82 ON_NOTIFY(SCN_GETBKCOLOR,0,OnSciGetBkColor)
83 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
84 END_MESSAGE_MAP()
87 // CTortoiseGitBlameView construction/destruction
89 CTortoiseGitBlameView::CTortoiseGitBlameView()
91 hInstance = 0;
92 hResource = 0;
93 currentDialog = 0;
94 wMain = 0;
95 m_wEditor = 0;
96 wLocator = 0;
98 m_font = 0;
99 m_italicfont = 0;
100 m_blamewidth = 0;
101 m_revwidth = 0;
102 m_datewidth = 0;
103 m_authorwidth = 0;
104 m_pathwidth = 0;
105 m_linewidth = 0;
107 m_windowcolor = ::GetSysColor(COLOR_WINDOW);
108 m_textcolor = ::GetSysColor(COLOR_WINDOWTEXT);
109 m_texthighlightcolor = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
110 m_mouserevcolor = InterColor(m_windowcolor, m_textcolor, 20);
111 m_mouseauthorcolor = InterColor(m_windowcolor, m_textcolor, 10);
112 m_selectedrevcolor = ::GetSysColor(COLOR_HIGHLIGHT);
113 m_selectedauthorcolor = InterColor(m_selectedrevcolor, m_texthighlightcolor, 35);
114 m_mouserev = -2;
116 m_selectedrev = -1;
117 m_selectedorigrev = -1;
118 m_SelectedLine = -1;
119 m_directPointer = 0;
120 m_directFunction = 0;
122 m_lowestrev = LONG_MAX;
123 m_highestrev = 0;
124 m_colorage = true;
126 m_bShowLine=true;
128 m_bShowAuthor = (theApp.GetInt(_T("ShowAuthor"), 1) == 1);
129 m_bShowDate=false;
130 m_bFollowRenames = (theApp.GetInt(_T("FollowRenames"), 0) == 1);
132 m_FindDialogMessage = ::RegisterWindowMessage(FINDMSGSTRING);
133 m_pFindDialog = NULL;
134 // get short/long datetime setting from registry
135 DWORD RegUseShortDateFormat = CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE);
136 if ( RegUseShortDateFormat )
138 m_DateFormat = DATE_SHORTDATE;
140 else
142 m_DateFormat = DATE_LONGDATE;
144 // get relative time display setting from registry
145 DWORD regRelativeTimes = CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE);
146 m_bRelativeTimes = (regRelativeTimes != 0);
148 m_sRev.LoadString(IDS_LOG_REVISION);
149 m_sAuthor.LoadString(IDS_LOG_AUTHOR);
150 m_sDate.LoadString(IDS_LOG_DATE);
151 m_sMessage.LoadString(IDS_LOG_MESSAGE);
153 m_Buffer = NULL;
156 CTortoiseGitBlameView::~CTortoiseGitBlameView()
158 if (m_font)
159 DeleteObject(m_font);
160 if (m_italicfont)
161 DeleteObject(m_italicfont);
163 if(m_Buffer)
165 delete m_Buffer;
166 m_Buffer=NULL;
169 struct EncodingUnit
171 int id;
172 char *name;
175 void CTortoiseGitBlameView::OnChangeEncode(UINT nId)
178 static EncodingUnit encodings[] = {
179 {1250, "windows-1250"}, //IDM_FORMAT_WIN_1250
180 {1251, "windows-1251"}, //IDM_FORMAT_WIN_1251
181 {1252, "windows-1252"}, //IDM_FORMAT_WIN_1252
182 {1253, "windows-1253"}, //IDM_FORMAT_WIN_1253
183 {1254, "windows-1254"}, //IDM_FORMAT_WIN_1254
184 {1255, "windows-1255"}, //IDM_FORMAT_WIN_1255
185 {1256, "windows-1256"}, //IDM_FORMAT_WIN_1256
186 {1257, "windows-1257"}, //IDM_FORMAT_WIN_1257
187 {1258, "windows-1258"}, //IDM_FORMAT_WIN_1258
188 {28591, "latin1 ISO_8859-1 ISO-8859-1 CP819 IBM819 csISOLatin1 iso-ir-100 l1"}, //IDM_FORMAT_ISO_8859_1
189 {28592, "latin2 ISO_8859-2 ISO-8859-2 csISOLatin2 iso-ir-101 l2"}, //IDM_FORMAT_ISO_8859_2
190 {28593, "latin3 ISO_8859-3 ISO-8859-3 csISOLatin3 iso-ir-109 l3"}, //IDM_FORMAT_ISO_8859_3
191 {28594, "latin4 ISO_8859-4 ISO-8859-4 csISOLatin4 iso-ir-110 l4"}, //IDM_FORMAT_ISO_8859_4
192 {28595, "cyrillic ISO_8859-5 ISO-8859-5 csISOLatinCyrillic iso-ir-144"}, //IDM_FORMAT_ISO_8859_5
193 {28596, "arabic ISO_8859-6 ISO-8859-6 csISOLatinArabic iso-ir-127 ASMO-708 ECMA-114"}, //IDM_FORMAT_ISO_8859_6
194 {28597, "greek ISO_8859-7 ISO-8859-7 csISOLatinGreek greek8 iso-ir-126 ELOT_928 ECMA-118"}, //IDM_FORMAT_ISO_8859_7
195 {28598, "hebrew ISO_8859-8 ISO-8859-8 csISOLatinHebrew iso-ir-138"}, //IDM_FORMAT_ISO_8859_8
196 {28599, "latin5 ISO_8859-9 ISO-8859-9 csISOLatin5 iso-ir-148 l5"}, //IDM_FORMAT_ISO_8859_9
197 {28600, "latin6 ISO_8859-10 ISO-8859-10 csISOLatin6 iso-ir-157 l6"}, //IDM_FORMAT_ISO_8859_10
198 {28601, "ISO_8859-11 ISO-8859-11"}, //IDM_FORMAT_ISO_8859_11
199 {28603, "ISO_8859-13 ISO-8859-13"}, //IDM_FORMAT_ISO_8859_13
200 {28604, "iso-celtic latin8 ISO_8859-14 ISO-8859-14 18 iso-ir-199"}, //IDM_FORMAT_ISO_8859_14
201 {28605, "Latin-9 ISO_8859-15 ISO-8859-15"}, //IDM_FORMAT_ISO_8859_15
202 {28606, "latin10 ISO_8859-16 ISO-8859-16 110 iso-ir-226"}, //IDM_FORMAT_ISO_8859_16
203 {437, "IBM437 cp437 437 csPC8CodePage437"}, //IDM_FORMAT_DOS_437
204 {720, "IBM720 cp720 oem720 720"}, //IDM_FORMAT_DOS_720
205 {737, "IBM737 cp737 oem737 737"}, //IDM_FORMAT_DOS_737
206 {775, "IBM775 cp775 oem775 775"}, //IDM_FORMAT_DOS_775
207 {850, "IBM850 cp850 oem850 850"}, //IDM_FORMAT_DOS_850
208 {852, "IBM852 cp852 oem852 852"}, //IDM_FORMAT_DOS_852
209 {855, "IBM855 cp855 oem855 855 csIBM855"}, //IDM_FORMAT_DOS_855
210 {857, "IBM857 cp857 oem857 857"}, //IDM_FORMAT_DOS_857
211 {858, "IBM858 cp858 oem858 858"}, //IDM_FORMAT_DOS_858
212 {860, "IBM860 cp860 oem860 860"}, //IDM_FORMAT_DOS_860
213 {861, "IBM861 cp861 oem861 861"}, //IDM_FORMAT_DOS_861
214 {862, "IBM862 cp862 oem862 862"}, //IDM_FORMAT_DOS_862
215 {863, "IBM863 cp863 oem863 863"}, //IDM_FORMAT_DOS_863
216 {865, "IBM865 cp865 oem865 865"}, //IDM_FORMAT_DOS_865
217 {866, "IBM866 cp866 oem866 866"}, //IDM_FORMAT_DOS_866
218 {869, "IBM869 cp869 oem869 869"}, //IDM_FORMAT_DOS_869
219 {950, "big5 csBig5"}, //IDM_FORMAT_BIG5
220 {936, "gb2312 gbk csGB2312"}, //IDM_FORMAT_GB2312
221 {932, "Shift_JIS MS_Kanji csShiftJIS csWindows31J"}, //IDM_FORMAT_SHIFT_JIS
222 {949, "windows-949 korean"}, //IDM_FORMAT_KOREAN_WIN
223 {51949, "euc-kr csEUCKR"}, //IDM_FORMAT_EUC_KR
224 {874, "tis-620"}, //IDM_FORMAT_TIS_620
225 {10007, "x-mac-cyrillic xmaccyrillic"}, //IDM_FORMAT_MAC_CYRILLIC
226 {21866, "koi8_u"}, //IDM_FORMAT_KOI8U_CYRILLIC
227 {20866, "koi8_r csKOI8R"} //IDM_FORMAT_KOI8R_CYRILLIC
229 if(nId >= IDM_FORMAT_ENCODE && nId <= IDM_FORMAT_ENCODE_END)
230 this->UpdateInfo(encodings[nId - IDM_FORMAT_ENCODE].id);
232 int CTortoiseGitBlameView::OnCreate(LPCREATESTRUCT lpcs)
235 CRect rect,rect1;
236 this->GetWindowRect(&rect1);
237 rect.left=m_blamewidth+LOCATOR_WIDTH;
238 rect.right=rect.Width();
239 rect.top=0;
240 rect.bottom=rect.Height();
241 BOOL b=m_TextView.Create(_T("Scintilla"),_T("source"),0,rect,this,0,0);
242 m_TextView.Init(0,FALSE);
243 m_TextView.ShowWindow( SW_SHOW);
244 //m_TextView.InsertText(_T("Abdadfasdf"));
245 m_wEditor = m_TextView.m_hWnd;
246 CreateFont();
247 InitialiseEditor();
248 m_ToolTip.Create(this->GetParent());
250 ::AfxGetApp()->GetMainWnd();
251 return CView::OnCreate(lpcs);
255 void CTortoiseGitBlameView::OnSize(UINT nType,int cx, int cy)
258 CRect rect;
259 rect.left=m_blamewidth;
260 rect.right=cx;
261 rect.top=0;
262 rect.bottom=cy;
264 m_TextView.MoveWindow(&rect);
267 BOOL CTortoiseGitBlameView::PreCreateWindow(CREATESTRUCT& cs)
269 return CView::PreCreateWindow(cs);
272 // CTortoiseGitBlameView drawing
274 void CTortoiseGitBlameView::OnDraw(CDC* /*pDC*/)
276 CTortoiseGitBlameDoc* pDoc = GetDocument();
277 ASSERT_VALID(pDoc);
278 if (!pDoc)
279 return;
281 DrawBlame(this->GetDC()->m_hDC);
282 DrawLocatorBar(this->GetDC()->m_hDC);
283 // TODO: add draw code for native data here
287 // CTortoiseGitBlameView printing
290 void CTortoiseGitBlameView::OnFilePrintPreview()
292 AFXPrintPreview(this);
295 BOOL CTortoiseGitBlameView::OnPreparePrinting(CPrintInfo* pInfo)
297 // default preparation
298 return DoPreparePrinting(pInfo);
301 void CTortoiseGitBlameView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
303 // TODO: add extra initialization before printing
306 void CTortoiseGitBlameView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
308 // TODO: add cleanup after printing
311 void CTortoiseGitBlameView::OnRButtonUp(UINT nFlags, CPoint point)
313 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
314 LONG_PTR height = SendEditor(SCI_TEXTHEIGHT);
315 line = line + (point.y/height);
316 if (line < (LONG)m_CommitHash.size())
318 if(m_ID[line] >= 0) // only show context menu if we have log data for it
320 m_MouseLine = line;
321 ClientToScreen(&point);
322 theApp.GetContextMenuManager()->ShowPopupMenu(IDR_BLAME_POPUP, point.x, point.y, this, TRUE);
327 void CTortoiseGitBlameView::OnUpdateBlamePopupBlamePrevious(CCmdUI *pCmdUI)
329 if (m_ID[m_MouseLine] <= 1)
331 pCmdUI->Enable(false);
333 else
335 pCmdUI->Enable(true);
339 void CTortoiseGitBlameView::OnUpdateBlamePopupDiffPrevious(CCmdUI *pCmdUI)
341 if (m_ID[m_MouseLine] <= 1)
343 pCmdUI->Enable(false);
345 else
347 pCmdUI->Enable(true);
351 void CTortoiseGitBlameView::CopyHashToClipboard()
353 this->GetLogList()->CopySelectionToClipBoard(TRUE);
356 // CTortoiseGitBlameView diagnostics
358 #ifdef _DEBUG
359 void CTortoiseGitBlameView::AssertValid() const
361 CView::AssertValid();
364 void CTortoiseGitBlameView::Dump(CDumpContext& dc) const
366 CView::Dump(dc);
369 CTortoiseGitBlameDoc* CTortoiseGitBlameView::GetDocument() const // non-debug version is inline
371 ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTortoiseGitBlameDoc)));
372 return (CTortoiseGitBlameDoc*)m_pDocument;
374 #endif //_DEBUG
377 // CTortoiseGitBlameView message handlers
378 CString CTortoiseGitBlameView::GetAppDirectory()
380 CString path;
381 DWORD len = 0;
382 DWORD bufferlen = MAX_PATH; // MAX_PATH is not the limit here!
385 bufferlen += MAX_PATH; // MAX_PATH is not the limit here!
386 TCHAR * pBuf = new TCHAR[bufferlen];
387 len = GetModuleFileName(NULL, pBuf, bufferlen);
388 path = CString(pBuf, len);
389 delete [] pBuf;
390 } while(len == bufferlen);
392 path = path.Left(path.ReverseFind(_T('\\')));
393 //path = path.substr(0, path.rfind('\\') + 1);
395 return path;
398 // Return a color which is interpolated between c1 and c2.
399 // Slider controls the relative proportions as a percentage:
400 // Slider = 0 represents pure c1
401 // Slider = 50 represents equal mixture
402 // Slider = 100 represents pure c2
403 COLORREF CTortoiseGitBlameView::InterColor(COLORREF c1, COLORREF c2, int Slider)
405 int r, g, b;
407 // Limit Slider to 0..100% range
408 if (Slider < 0)
409 Slider = 0;
410 if (Slider > 100)
411 Slider = 100;
413 // The color components have to be treated individually.
414 r = (GetRValue(c2) * Slider + GetRValue(c1) * (100 - Slider)) / 100;
415 g = (GetGValue(c2) * Slider + GetGValue(c1) * (100 - Slider)) / 100;
416 b = (GetBValue(c2) * Slider + GetBValue(c1) * (100 - Slider)) / 100;
418 return RGB(r, g, b);
421 LRESULT CTortoiseGitBlameView::SendEditor(UINT Msg, WPARAM wParam, LPARAM lParam)
423 if (m_directFunction)
425 return ((SciFnDirect) m_directFunction)(m_directPointer, Msg, wParam, lParam);
427 return ::SendMessage(m_wEditor, Msg, wParam, lParam);
430 void CTortoiseGitBlameView::GetRange(int start, int end, char *text)
432 #if 0
433 TEXTRANGE tr;
434 tr.chrg.cpMin = start;
435 tr.chrg.cpMax = end;
436 tr.lpstrText = text;
438 SendMessage(m_wEditor, EM_GETTEXTRANGE, 0, reinterpret_cast<LPARAM>(&tr));
439 #endif
442 void CTortoiseGitBlameView::SetTitle()
444 #if 0
445 char title[MAX_PATH + 100];
446 strcpy_s(title, MAX_PATH + 100, szTitle);
447 strcat_s(title, MAX_PATH + 100, " - ");
448 strcat_s(title, MAX_PATH + 100, szViewtitle);
449 ::SetWindowText(wMain, title);
450 #endif
453 BOOL CTortoiseGitBlameView::OpenLogFile(const char *fileName)
455 #if 0
456 char logmsgbuf[10000+1];
457 FILE * File;
458 fopen_s(&File, fileName, "rb");
459 if (File == 0)
461 return FALSE;
463 LONG rev = 0;
464 CString msg;
465 int slength = 0;
466 int reallength = 0;
467 size_t len = 0;
468 wchar_t wbuf[MAX_LOG_LENGTH+6];
469 for (;;)
471 len = fread(&rev, sizeof(LONG), 1, File);
472 if (len == 0)
474 fclose(File);
475 InitSize();
476 return TRUE;
478 len = fread(&slength, sizeof(int), 1, File);
479 if (len == 0)
481 fclose(File);
482 InitSize();
483 return FALSE;
485 if (slength > MAX_LOG_LENGTH)
487 reallength = slength;
488 slength = MAX_LOG_LENGTH;
490 else
491 reallength = 0;
492 len = fread(logmsgbuf, sizeof(char), slength, File);
493 if (len < (size_t)slength)
495 fclose(File);
496 InitSize();
497 return FALSE;
499 msg = CString(logmsgbuf, slength);
500 if (reallength)
502 fseek(File, reallength-MAX_LOG_LENGTH, SEEK_CUR);
503 msg = msg + _T("\n...");
505 int len2 = ::MultiByteToWideChar(CP_UTF8, NULL, msg.c_str(), min(msg.size(), MAX_LOG_LENGTH+5), wbuf, MAX_LOG_LENGTH+5);
506 wbuf[len2] = 0;
507 len2 = ::WideCharToMultiByte(CP_ACP, NULL, wbuf, len2, logmsgbuf, MAX_LOG_LENGTH+5, NULL, NULL);
508 logmsgbuf[len2] = 0;
509 msg = CString(logmsgbuf);
510 logmessages[rev] = msg;
512 #endif
513 return TRUE;
516 BOOL CTortoiseGitBlameView::OpenFile(const char *fileName)
518 #if 0
519 SendEditor(SCI_SETREADONLY, FALSE);
520 SendEditor(SCI_CLEARALL);
521 SendEditor(EM_EMPTYUNDOBUFFER);
522 SetTitle();
523 SendEditor(SCI_SETSAVEPOINT);
524 SendEditor(SCI_CANCEL);
525 SendEditor(SCI_SETUNDOCOLLECTION, 0);
526 ::ShowWindow(m_wEditor, SW_HIDE);
527 std::ifstream File;
528 File.open(fileName);
529 if (!File.good())
531 return FALSE;
533 char line[100*1024];
534 char * lineptr = NULL;
535 char * trimptr = NULL;
536 //ignore the first two lines, they're of no interest to us
537 File.getline(line, _countof(line));
538 File.getline(line, _countof(line));
539 m_lowestrev = LONG_MAX;
540 m_highestrev = 0;
541 bool bUTF8 = true;
544 File.getline(line, _countof(line));
545 if (File.gcount()>139)
547 mergelines.push_back((line[0] != ' '));
548 lineptr = &line[9];
549 long rev = _ttol(lineptr);
550 revs.push_back(rev);
551 m_lowestrev = min(m_lowestrev, rev);
552 m_highestrev = max(m_highestrev, rev);
553 lineptr += 7;
554 rev = _ttol(lineptr);
555 origrevs.push_back(rev);
556 lineptr += 7;
557 dates.push_back(CString(lineptr, 30));
558 lineptr += 31;
559 // unfortunately, the 'path' entry can be longer than the 60 chars
560 // we made the column. We therefore have to step through the path
561 // string until we find a space
562 trimptr = lineptr;
565 // TODO: how can we deal with the situation where the path has
566 // a space in it, but the space is after the 60 chars reserved
567 // for it?
568 // The only way to deal with that would be to use a custom
569 // binary format for the blame file.
570 trimptr++;
571 trimptr = _tcschr(trimptr, ' ');
572 } while ((trimptr)&&(trimptr+1 < lineptr+61));
573 if (trimptr)
574 *trimptr = 0;
575 else
576 trimptr = lineptr;
577 paths.push_back(CString(lineptr));
578 if (trimptr+1 < lineptr+61)
579 lineptr +=61;
580 else
581 lineptr = (trimptr+1);
582 trimptr = lineptr+30;
583 while ((*trimptr == ' ')&&(trimptr > lineptr))
584 trimptr--;
585 *(trimptr+1) = 0;
586 authors.push_back(CString(lineptr));
587 lineptr += 31;
588 // in case we find an UTF8 BOM at the beginning of the line, we remove it
589 if (((unsigned char)lineptr[0] == 0xEF)&&((unsigned char)lineptr[1] == 0xBB)&&((unsigned char)lineptr[2] == 0xBF))
591 lineptr += 3;
593 if (((unsigned char)lineptr[0] == 0xBB)&&((unsigned char)lineptr[1] == 0xEF)&&((unsigned char)lineptr[2] == 0xBF))
595 lineptr += 3;
597 // check each line for illegal utf8 sequences. If one is found, we treat
598 // the file as ASCII, otherwise we assume an UTF8 file.
599 char * utf8CheckBuf = lineptr;
600 while ((bUTF8)&&(*utf8CheckBuf))
602 if ((*utf8CheckBuf == 0xC0)||(*utf8CheckBuf == 0xC1)||(*utf8CheckBuf >= 0xF5))
604 bUTF8 = false;
605 break;
607 if ((*utf8CheckBuf & 0xE0)==0xC0)
609 utf8CheckBuf++;
610 if (*utf8CheckBuf == 0)
611 break;
612 if ((*utf8CheckBuf & 0xC0)!=0x80)
614 bUTF8 = false;
615 break;
618 if ((*utf8CheckBuf & 0xF0)==0xE0)
620 utf8CheckBuf++;
621 if (*utf8CheckBuf == 0)
622 break;
623 if ((*utf8CheckBuf & 0xC0)!=0x80)
625 bUTF8 = false;
626 break;
628 utf8CheckBuf++;
629 if (*utf8CheckBuf == 0)
630 break;
631 if ((*utf8CheckBuf & 0xC0)!=0x80)
633 bUTF8 = false;
634 break;
637 if ((*utf8CheckBuf & 0xF8)==0xF0)
639 utf8CheckBuf++;
640 if (*utf8CheckBuf == 0)
641 break;
642 if ((*utf8CheckBuf & 0xC0)!=0x80)
644 bUTF8 = false;
645 break;
647 utf8CheckBuf++;
648 if (*utf8CheckBuf == 0)
649 break;
650 if ((*utf8CheckBuf & 0xC0)!=0x80)
652 bUTF8 = false;
653 break;
655 utf8CheckBuf++;
656 if (*utf8CheckBuf == 0)
657 break;
658 if ((*utf8CheckBuf & 0xC0)!=0x80)
660 bUTF8 = false;
661 break;
665 utf8CheckBuf++;
667 SendEditor(SCI_ADDTEXT, _tcslen(lineptr), reinterpret_cast<LPARAM>(static_cast<char *>(lineptr)));
668 SendEditor(SCI_ADDTEXT, 2, (LPARAM)_T("\r\n"));
670 } while (File.gcount() > 0);
672 if (bUTF8)
673 SendEditor(SCI_SETCODEPAGE, SC_CP_UTF8);
675 SendEditor(SCI_SETUNDOCOLLECTION, 1);
676 ::SetFocus(m_wEditor);
677 SendEditor(EM_EMPTYUNDOBUFFER);
678 SendEditor(SCI_SETSAVEPOINT);
679 SendEditor(SCI_GOTOPOS, 0);
680 SendEditor(SCI_SETSCROLLWIDTHTRACKING, TRUE);
681 SendEditor(SCI_SETREADONLY, TRUE);
683 //check which lexer to use, depending on the filetype
684 SetupLexer(fileName);
685 ::ShowWindow(m_wEditor, SW_SHOW);
686 m_blamewidth = 0;
687 ::InvalidateRect(wMain, NULL, TRUE);
688 RECT rc;
689 GetWindowRect(wMain, &rc);
690 SetWindowPos(wMain, 0, rc.left, rc.top, rc.right-rc.left-1, rc.bottom - rc.top, 0);
691 #endif
692 return TRUE;
695 void CTortoiseGitBlameView::SetAStyle(int style, COLORREF fore, COLORREF back, int size, CString *face)
697 SendEditor(SCI_STYLESETFORE, style, fore);
698 SendEditor(SCI_STYLESETBACK, style, back);
699 if (size >= 1)
700 SendEditor(SCI_STYLESETSIZE, style, size);
701 if (face)
702 SendEditor(SCI_STYLESETFONT, style, reinterpret_cast<LPARAM>(this->m_TextView.StringForControl(*face).GetBuffer()));
705 void CTortoiseGitBlameView::InitialiseEditor()
708 m_directFunction = ::SendMessage(m_wEditor, SCI_GETDIRECTFUNCTION, 0, 0);
709 m_directPointer = ::SendMessage(m_wEditor, SCI_GETDIRECTPOINTER, 0, 0);
710 // Set up the global default style. These attributes are used wherever no explicit choices are made.
711 SetAStyle(STYLE_DEFAULT,
712 black,
713 white,
714 (DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10),
715 &CString(((stdstring)CRegStdString(_T("Software\\TortoiseGit\\BlameFontName"), _T("Courier New"))).c_str())
717 SendEditor(SCI_SETTABWIDTH, (DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameTabSize"), 4));
718 SendEditor(SCI_SETREADONLY, TRUE);
719 LRESULT pix = SendEditor(SCI_TEXTWIDTH, STYLE_LINENUMBER, (LPARAM)this->m_TextView.StringForControl(_T("_99999")).GetBuffer());
720 if (m_bShowLine)
721 SendEditor(SCI_SETMARGINWIDTHN, 0, pix);
722 else
723 SendEditor(SCI_SETMARGINWIDTHN, 0);
724 SendEditor(SCI_SETMARGINWIDTHN, 1);
725 SendEditor(SCI_SETMARGINWIDTHN, 2);
726 //Set the default windows colors for edit controls
727 SendEditor(SCI_STYLESETFORE, STYLE_DEFAULT, ::GetSysColor(COLOR_WINDOWTEXT));
728 SendEditor(SCI_STYLESETBACK, STYLE_DEFAULT, ::GetSysColor(COLOR_WINDOW));
729 SendEditor(SCI_SETSELFORE, TRUE, ::GetSysColor(COLOR_HIGHLIGHTTEXT));
730 SendEditor(SCI_SETSELBACK, TRUE, ::GetSysColor(COLOR_HIGHLIGHT));
731 SendEditor(SCI_SETCARETFORE, ::GetSysColor(COLOR_WINDOWTEXT));
732 m_regOldLinesColor = CRegStdDWORD(_T("Software\\TortoiseGit\\BlameOldColor"), RGB(230, 230, 255));
733 m_regNewLinesColor = CRegStdDWORD(_T("Software\\TortoiseGit\\BlameNewColor"), RGB(255, 230, 230));
734 if (SysInfo::Instance().IsWin7OrLater())
736 SendEditor(SCI_SETTECHNOLOGY, SC_TECHNOLOGY_DIRECTWRITE);
737 SendEditor(SCI_SETBUFFEREDDRAW, 0);
739 SendEditor(SCI_SETFONTQUALITY, SC_EFF_QUALITY_LCD_OPTIMIZED);
741 this->m_TextView.Call(SCI_SETWRAPMODE, SC_WRAP_NONE);
745 void CTortoiseGitBlameView::StartSearch()
747 if (m_pFindDialog)
748 return;
749 bool bCase = false;
750 // Initialize FINDREPLACE
751 if (fr.Flags & FR_MATCHCASE)
752 bCase = true;
753 SecureZeroMemory(&fr, sizeof(fr));
754 fr.lStructSize = sizeof(fr);
755 fr.hwndOwner = wMain;
756 fr.lpstrFindWhat = szFindWhat;
757 fr.wFindWhatLen = 80;
758 fr.Flags = FR_HIDEUPDOWN | FR_HIDEWHOLEWORD;
759 fr.Flags |= bCase ? FR_MATCHCASE : 0;
761 currentDialog = FindText(&fr);
764 bool CTortoiseGitBlameView::DoSearch(CString what, DWORD flags)
767 //char szWhat[80];
768 int pos = SendEditor(SCI_GETCURRENTPOS);
769 int line = SendEditor(SCI_LINEFROMPOSITION, pos);
770 bool bFound = false;
771 bool bCaseSensitive = !!(flags & FR_MATCHCASE);
773 //strcpy_s(szWhat, sizeof(szWhat), what);
775 if(!bCaseSensitive)
777 what=what.MakeLower();
780 //CString sWhat = CString(szWhat);
782 //char buf[20];
783 //int i=0;
784 int i=line;
787 int bufsize = SendEditor(SCI_GETLINE, i);
788 char * linebuf = new char[bufsize+1];
789 SecureZeroMemory(linebuf, bufsize+1);
790 SendEditor(SCI_GETLINE, i, (LPARAM)linebuf);
791 CString oneline=this->m_TextView.StringFromControl(linebuf);
792 if (!bCaseSensitive)
794 oneline=oneline.MakeLower();
796 //_stprintf_s(buf, 20, _T("%ld"), revs[i]);
797 if (this->m_Authors[i].Find(what)>=0)
798 bFound = true;
799 else if ((!bCaseSensitive)&&(this->m_Authors[i].MakeLower().Find(what)>=0))
800 bFound = true;
801 else if (oneline.Find(what) >=0)
802 bFound = true;
804 delete [] linebuf;
806 i++;
807 if(i>=(signed int)m_CommitHash.size())
808 i=0;
809 }while(i!=line &&(!bFound));
811 if (bFound)
813 GotoLine(i);
814 int selstart = SendEditor(SCI_GETCURRENTPOS);
815 int selend = SendEditor(SCI_POSITIONFROMLINE, i);
816 SendEditor(SCI_SETSELECTIONSTART, selstart);
817 SendEditor(SCI_SETSELECTIONEND, selend);
818 m_SelectedLine = i-1;
820 else
822 ::MessageBox(wMain, _T("\"") + what + _T("\" ") + CString(MAKEINTRESOURCE(IDS_NOTFOUND)), _T("TortoiseGitBlame"), MB_ICONINFORMATION);
825 return true;
828 bool CTortoiseGitBlameView::GotoLine(long line)
830 --line;
831 if (line < 0)
832 return false;
833 if ((unsigned long)line >= m_CommitHash.size())
835 line = m_CommitHash.size()-1;
838 int nCurrentPos = SendEditor(SCI_GETCURRENTPOS);
839 int nCurrentLine = SendEditor(SCI_LINEFROMPOSITION,nCurrentPos);
840 int nFirstVisibleLine = SendEditor(SCI_GETFIRSTVISIBLELINE);
841 int nLinesOnScreen = SendEditor(SCI_LINESONSCREEN);
843 if ( line>=nFirstVisibleLine && line<=nFirstVisibleLine+nLinesOnScreen)
845 // no need to scroll
846 SendEditor(SCI_GOTOLINE, line);
848 else
850 // Place the requested line one third from the top
851 if ( line > nCurrentLine )
853 SendEditor(SCI_GOTOLINE, (WPARAM)(line+(int)nLinesOnScreen*(2/3.0)));
855 else
857 SendEditor(SCI_GOTOLINE, (WPARAM)(line-(int)nLinesOnScreen*(1/3.0)));
861 // Highlight the line
862 int nPosStart = SendEditor(SCI_POSITIONFROMLINE,line);
863 int nPosEnd = SendEditor(SCI_GETLINEENDPOSITION,line);
864 SendEditor(SCI_SETSEL,nPosEnd,nPosStart);
866 return true;
869 bool CTortoiseGitBlameView::ScrollToLine(long line)
871 if (line < 0)
872 return false;
874 int nCurrentLine = SendEditor(SCI_GETFIRSTVISIBLELINE);
876 int scrolldelta = line - nCurrentLine;
877 SendEditor(SCI_LINESCROLL, 0, scrolldelta);
879 return true;
882 void CTortoiseGitBlameView::CopySelectedLogToClipboard()
884 this->GetLogList()->CopySelectionToClipBoard(FALSE);
887 void CTortoiseGitBlameView::BlamePreviousRevision()
889 CString procCmd = _T("/path:\"");
890 procCmd += ((CMainFrame*)::AfxGetApp()->GetMainWnd())->GetActiveView()->GetDocument()->GetPathName();
891 procCmd += _T("\" ");
892 procCmd += _T(" /command:blame");
893 procCmd += _T(" /endrev:") + this->GetLogData()->GetGitRevAt(this->GetLogData()->size()-m_ID[m_MouseLine]+1).m_CommitHash.ToString();
895 CCommonAppUtils::RunTortoiseProc(procCmd);
898 void CTortoiseGitBlameView::DiffPreviousRevision()
900 CString procCmd = _T("/path:\"");
901 procCmd += ((CMainFrame*)::AfxGetApp()->GetMainWnd())->GetActiveView()->GetDocument()->GetPathName();
902 procCmd += _T("\" ");
903 procCmd += _T(" /command:diff");
904 procCmd += _T(" /startrev:") + this->GetLogData()->GetGitRevAt(this->GetLogData()->size() - m_ID[m_MouseLine]).m_CommitHash.ToString();
905 procCmd += _T(" /endrev:") + this->GetLogData()->GetGitRevAt(this->GetLogData()->size() - m_ID[m_MouseLine] + 1).m_CommitHash.ToString();
907 CCommonAppUtils::RunTortoiseProc(procCmd);
910 void CTortoiseGitBlameView::ShowLog()
912 CString procCmd = _T("/path:\"");
913 procCmd += ((CMainFrame*)::AfxGetApp()->GetMainWnd())->GetActiveView()->GetDocument()->GetPathName();
914 procCmd += _T("\" ");
915 procCmd += _T(" /command:log");
916 procCmd += _T(" /rev:") + this->GetLogData()->GetGitRevAt(this->GetLogData()->size() - m_ID[m_MouseLine]).m_CommitHash.ToString();
918 CCommonAppUtils::RunTortoiseProc(procCmd);
921 void CTortoiseGitBlameView::Notify(SCNotification *notification)
923 switch (notification->nmhdr.code)
925 case SCN_SAVEPOINTREACHED:
926 break;
928 case SCN_SAVEPOINTLEFT:
929 break;
930 case SCN_PAINTED:
931 // InvalidateRect(wBlame, NULL, FALSE);
932 // InvalidateRect(wLocator, NULL, FALSE);
933 break;
934 case SCN_GETBKCOLOR:
935 // if ((m_colorage)&&(notification->line < (int)revs.size()))
936 // {
937 // notification->lParam = InterColor(DWORD(m_regOldLinesColor), DWORD(m_regNewLinesColor), (revs[notification->line]-m_lowestrev)*100/((m_highestrev-m_lowestrev)+1));
938 // }
939 break;
943 void CTortoiseGitBlameView::Command(int id)
945 #if 0
946 switch (id)
948 // case IDM_EXIT:
949 // ::PostQuitMessage(0);
950 // break;
951 case ID_EDIT_FIND:
952 StartSearch();
953 break;
954 case ID_COPYTOCLIPBOARD:
955 CopySelectedLogToClipboard();
956 break;
957 case ID_BLAME_PREVIOUS_REVISION:
958 BlamePreviousRevision();
959 break;
960 case ID_DIFF_PREVIOUS_REVISION:
961 DiffPreviousRevision();
962 break;
963 case ID_SHOWLOG:
964 ShowLog();
965 break;
966 case ID_EDIT_GOTOLINE:
967 GotoLineDlg();
968 break;
969 case ID_VIEW_COLORAGEOFLINES:
971 m_colorage = !m_colorage;
972 HMENU hMenu = GetMenu(wMain);
973 UINT uCheck = MF_BYCOMMAND;
974 uCheck |= m_colorage ? MF_CHECKED : MF_UNCHECKED;
975 CheckMenuItem(hMenu, ID_VIEW_COLORAGEOFLINES, uCheck);
976 m_blamewidth = 0;
977 InitSize();
979 break;
980 case ID_VIEW_MERGEPATH:
982 ShowPath = !ShowPath;
983 HMENU hMenu = GetMenu(wMain);
984 UINT uCheck = MF_BYCOMMAND;
985 uCheck |= ShowPath ? MF_CHECKED : MF_UNCHECKED;
986 CheckMenuItem(hMenu, ID_VIEW_MERGEPATH, uCheck);
987 m_blamewidth = 0;
988 InitSize();
990 default:
991 break;
993 #endif
997 LONG CTortoiseGitBlameView::GetBlameWidth()
999 LONG blamewidth = 0;
1000 SIZE width;
1001 CreateFont();
1002 HDC hDC = this->GetDC()->m_hDC;
1003 HFONT oldfont = (HFONT)::SelectObject(hDC, m_font);
1005 TCHAR buf[MAX_PATH];
1007 ::GetTextExtentPoint32(hDC, _T("fffffff"), 7, &width);
1008 m_revwidth = width.cx + BLAMESPACE;
1009 blamewidth += m_revwidth;
1011 #if 0
1012 _stprintf_s(buf, MAX_PATH, _T("%d"), m_CommitHash.size());
1013 ::GetTextExtentPoint(hDC, buf, _tcslen(buf), &width);
1014 m_linewidth = width.cx + BLAMESPACE;
1015 blamewidth += m_revwidth;
1016 #endif
1018 if (m_bShowDate)
1020 _stprintf_s(buf, MAX_PATH, _T("%30s"), _T("31.08.2001 06:24:14"));
1021 ::GetTextExtentPoint32(hDC, buf, _tcslen(buf), &width);
1022 m_datewidth = width.cx + BLAMESPACE;
1023 blamewidth += m_datewidth;
1025 if ( m_bShowAuthor)
1027 SIZE maxwidth = {0};
1029 for (unsigned int i=0;i<this->m_Authors.size();i++)
1030 //for (std::vector<CString>::iterator I = authors.begin(); I != authors.end(); ++I)
1032 ::GetTextExtentPoint32(hDC,m_Authors[i] , m_Authors[i].GetLength(), &width);
1033 if (width.cx > maxwidth.cx)
1034 maxwidth = width;
1036 m_authorwidth = maxwidth.cx + BLAMESPACE;
1037 blamewidth += m_authorwidth;
1039 #if 0
1040 if (ShowPath)
1042 SIZE maxwidth = {0};
1043 for (std::vector<CString>::iterator I = paths.begin(); I != paths.end(); ++I)
1045 ::GetTextExtentPoint32(hDC, I->c_str(), I->size(), &width);
1046 if (width.cx > maxwidth.cx)
1047 maxwidth = width;
1049 m_pathwidth = maxwidth.cx + BLAMESPACE;
1050 blamewidth += m_pathwidth;
1052 #endif
1053 ::SelectObject(hDC, oldfont);
1054 POINT pt = {blamewidth, 0};
1055 LPtoDP(hDC, &pt, 1);
1056 m_blamewidth = pt.x;
1057 //::ReleaseDC(wBlame, hDC);
1059 //return m_blamewidth;
1060 return blamewidth;
1064 void CTortoiseGitBlameView::CreateFont()
1066 if (m_font)
1067 return;
1068 LOGFONT lf = {0};
1069 lf.lfWeight = 400;
1070 HDC hDC = ::GetDC(wBlame);
1071 lf.lfHeight = -MulDiv((DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10), GetDeviceCaps(hDC, LOGPIXELSY), 72);
1072 lf.lfCharSet = DEFAULT_CHARSET;
1073 CRegStdString fontname = CRegStdString(_T("Software\\TortoiseGit\\BlameFontName"), _T("Courier New"));
1074 _tcscpy_s(lf.lfFaceName, 32, ((stdstring)fontname).c_str());
1075 m_font = ::CreateFontIndirect(&lf);
1077 lf.lfItalic = TRUE;
1078 m_italicfont = ::CreateFontIndirect(&lf);
1080 ::ReleaseDC(wBlame, hDC);
1082 //m_TextView.SetFont(lf.lfFaceName,((DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10)));
1085 void CTortoiseGitBlameView::DrawBlame(HDC hDC)
1088 if (hDC == NULL)
1089 return;
1090 if (m_font == NULL)
1091 return;
1093 HFONT oldfont = NULL;
1094 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
1095 LONG_PTR linesonscreen = SendEditor(SCI_LINESONSCREEN);
1096 LONG_PTR height = SendEditor(SCI_TEXTHEIGHT);
1097 LONG_PTR Y = 0;
1098 TCHAR buf[MAX_PATH];
1099 RECT rc;
1100 BOOL sel = FALSE;
1101 //::GetClientRect(this->m_hWnd, &rc);
1102 for (LRESULT i=line; i<(line+linesonscreen); ++i)
1104 sel = FALSE;
1105 if (i < (int)m_CommitHash.size())
1107 // if (mergelines[i])
1108 // oldfont = (HFONT)::SelectObject(hDC, m_italicfont);
1109 // else
1110 oldfont = (HFONT)::SelectObject(hDC, m_font);
1111 ::SetBkColor(hDC, m_windowcolor);
1112 ::SetTextColor(hDC, m_textcolor);
1113 if (!m_CommitHash[i].IsEmpty())
1115 //if (m_CommitHash[i].Compare(m_MouseHash)==0)
1116 // ::SetBkColor(hDC, m_mouseauthorcolor);
1117 if (m_CommitHash[i] == m_SelectedHash )
1119 ::SetBkColor(hDC, m_selectedauthorcolor);
1120 ::SetTextColor(hDC, m_texthighlightcolor);
1121 sel = TRUE;
1125 if(m_MouseLine == i)
1126 ::SetBkColor(hDC, m_mouserevcolor);
1128 //if ((revs[i] == m_mouserev)&&(!sel))
1129 // ::SetBkColor(hDC, m_mouserevcolor);
1130 //if (revs[i] == m_selectedrev)
1132 // ::SetBkColor(hDC, m_selectedrevcolor);
1133 // ::SetTextColor(hDC, m_texthighlightcolor);
1136 CString str;
1137 str = m_CommitHash[i].ToString().Left(g_Git.GetShortHASHLength());
1139 //_stprintf_s(buf, MAX_PATH, _T("%8ld "), revs[i]);
1140 rc.top=Y;
1141 rc.left=LOCATOR_WIDTH;
1142 rc.bottom=Y+height;
1143 rc.right = rc.left + m_blamewidth;
1144 ::ExtTextOut(hDC, LOCATOR_WIDTH, Y, ETO_CLIPPED, &rc, str, str.GetLength(), 0);
1145 int Left = m_revwidth;
1147 if (m_bShowAuthor)
1149 rc.right = rc.left + Left + m_authorwidth;
1150 //_stprintf_s(buf, MAX_PATH, _T("%-30s "), authors[i].c_str());
1151 ::ExtTextOut(hDC, Left, Y, ETO_CLIPPED, &rc, m_Authors[i], m_Authors[i].GetLength(), 0);
1152 Left += m_authorwidth;
1154 #if 0
1155 if (ShowDate)
1157 rc.right = rc.left + Left + m_datewidth;
1158 _stprintf_s(buf, MAX_PATH, _T("%30s "), dates[i].c_str());
1159 ::ExtTextOut(hDC, Left, Y, ETO_CLIPPED, &rc, buf, _tcslen(buf), 0);
1160 Left += m_datewidth;
1163 #endif
1164 #if 0
1165 if (ShowPath)
1167 rc.right = rc.left + Left + m_pathwidth;
1168 _stprintf_s(buf, MAX_PATH, _T("%-60s "), paths[i].c_str());
1169 ::ExtTextOut(hDC, Left, Y, ETO_CLIPPED, &rc, buf, _tcslen(buf), 0);
1170 Left += m_authorwidth;
1172 #endif
1173 if ((i==m_SelectedLine)&&(m_pFindDialog))
1175 LOGBRUSH brush;
1176 brush.lbColor = m_textcolor;
1177 brush.lbHatch = 0;
1178 brush.lbStyle = BS_SOLID;
1179 HPEN pen = ExtCreatePen(PS_SOLID | PS_GEOMETRIC, 2, &brush, 0, NULL);
1180 HGDIOBJ hPenOld = SelectObject(hDC, pen);
1181 RECT rc2 = rc;
1182 rc2.top = Y;
1183 rc2.bottom = Y + height;
1184 ::MoveToEx(hDC, rc2.left, rc2.top, NULL);
1185 ::LineTo(hDC, rc2.right, rc2.top);
1186 ::LineTo(hDC, rc2.right, rc2.bottom);
1187 ::LineTo(hDC, rc2.left, rc2.bottom);
1188 ::LineTo(hDC, rc2.left, rc2.top);
1189 SelectObject(hDC, hPenOld);
1190 DeleteObject(pen);
1192 Y += height;
1193 ::SelectObject(hDC, oldfont);
1195 else
1197 ::SetBkColor(hDC, m_windowcolor);
1198 for (int j=0; j< MAX_PATH; ++j)
1199 buf[j]=' ';
1200 ::ExtTextOut(hDC, 0, Y, ETO_CLIPPED, &rc, buf, MAX_PATH-1, 0);
1201 Y += height;
1206 void CTortoiseGitBlameView::DrawHeader(HDC hDC)
1208 #if 0
1209 if (hDC == NULL)
1210 return;
1212 RECT rc;
1213 HFONT oldfont = (HFONT)::SelectObject(hDC, GetStockObject(DEFAULT_GUI_FONT));
1214 ::GetClientRect(wHeader, &rc);
1216 ::SetBkColor(hDC, ::GetSysColor(COLOR_BTNFACE));
1218 TCHAR szText[MAX_LOADSTRING];
1219 LoadString(app.hResource, IDS_HEADER_REVISION, szText, MAX_LOADSTRING);
1220 ::ExtTextOut(hDC, LOCATOR_WIDTH, 0, ETO_CLIPPED, &rc, szText, _tcslen(szText), 0);
1221 int Left = m_revwidth+LOCATOR_WIDTH;
1222 if (ShowDate)
1224 LoadString(app.hResource, IDS_HEADER_DATE, szText, MAX_LOADSTRING);
1225 ::ExtTextOut(hDC, Left, 0, ETO_CLIPPED, &rc, szText, _tcslen(szText), 0);
1226 Left += m_datewidth;
1228 if (ShowAuthor)
1230 LoadString(app.hResource, IDS_HEADER_AUTHOR, szText, MAX_LOADSTRING);
1231 ::ExtTextOut(hDC, Left, 0, ETO_CLIPPED, &rc, szText, _tcslen(szText), 0);
1232 Left += m_authorwidth;
1234 if (ShowPath)
1236 LoadString(app.hResource, IDS_HEADER_PATH, szText, MAX_LOADSTRING);
1237 ::ExtTextOut(hDC, Left, 0, ETO_CLIPPED, &rc, szText, _tcslen(szText), 0);
1238 Left += m_pathwidth;
1240 LoadString(app.hResource, IDS_HEADER_LINE, szText, MAX_LOADSTRING);
1241 ::ExtTextOut(hDC, Left, 0, ETO_CLIPPED, &rc, szText, _tcslen(szText), 0);
1243 ::SelectObject(hDC, oldfont);
1244 #endif
1247 void CTortoiseGitBlameView::DrawLocatorBar(HDC hDC)
1249 if (hDC == NULL)
1250 return;
1252 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
1253 LONG_PTR linesonscreen = SendEditor(SCI_LINESONSCREEN);
1254 LONG_PTR Y = 0;
1255 COLORREF blackColor = GetSysColor(COLOR_WINDOWTEXT);
1257 RECT rc;
1258 //::GetClientRect(wLocator, &rc);
1259 this->GetClientRect(&rc);
1261 rc.right=LOCATOR_WIDTH;
1263 RECT lineRect = rc;
1264 LONG height = rc.bottom-rc.top;
1265 LONG currentLine = 0;
1267 // draw the colored bar
1268 for (std::vector<LONG>::const_iterator it = m_ID.begin(); it != m_ID.end(); ++it)
1270 currentLine++;
1271 // get the line color
1272 COLORREF cr = InterColor(DWORD(m_regOldLinesColor), DWORD(m_regNewLinesColor), (*it - m_lowestrev)*100/((m_highestrev-m_lowestrev)+1));
1273 if ((currentLine > line)&&(currentLine <= (line + linesonscreen)))
1275 cr = InterColor(cr, blackColor, 10);
1277 SetBkColor(hDC, cr);
1278 lineRect.top = Y;
1279 lineRect.bottom = (currentLine * height / m_ID.size());
1280 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, NULL, 0, NULL);
1281 Y = lineRect.bottom;
1284 if (m_ID.size())
1286 // now draw two lines indicating the scroll position of the source view
1287 SetBkColor(hDC, blackColor);
1288 lineRect.top = line * height / m_ID.size();
1289 lineRect.bottom = lineRect.top+1;
1290 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, NULL, 0, NULL);
1291 lineRect.top = (line + linesonscreen) * height / m_ID.size();
1292 lineRect.bottom = lineRect.top+1;
1293 ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &lineRect, NULL, 0, NULL);
1298 void CTortoiseGitBlameView::StringExpand(LPSTR str)
1300 char * cPos = str;
1303 cPos = strchr(cPos, '\n');
1304 if (cPos)
1306 memmove(cPos+1, cPos, strlen(cPos)*sizeof(char));
1307 *cPos = '\r';
1308 cPos++;
1309 cPos++;
1311 } while (cPos != NULL);
1313 void CTortoiseGitBlameView::StringExpand(LPWSTR str)
1315 wchar_t * cPos = str;
1318 cPos = wcschr(cPos, '\n');
1319 if (cPos)
1321 memmove(cPos+1, cPos, wcslen(cPos)*sizeof(wchar_t));
1322 *cPos = '\r';
1323 cPos++;
1324 cPos++;
1326 } while (cPos != NULL);
1329 // Forward declarations of functions included in this code module:
1330 ATOM MyRegisterClass(HINSTANCE hResource);
1331 ATOM MyRegisterBlameClass(HINSTANCE hResource);
1332 ATOM MyRegisterHeaderClass(HINSTANCE hResource);
1333 ATOM MyRegisterLocatorClass(HINSTANCE hResource);
1334 BOOL InitInstance(HINSTANCE, int);
1335 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
1336 LRESULT CALLBACK WndBlameProc(HWND, UINT, WPARAM, LPARAM);
1337 LRESULT CALLBACK WndHeaderProc(HWND, UINT, WPARAM, LPARAM);
1338 LRESULT CALLBACK WndLocatorProc(HWND, UINT, WPARAM, LPARAM);
1339 UINT uFindReplaceMsg;
1341 #if 0
1342 int APIENTRY _tWinMain(HINSTANCE hInstance,
1343 HINSTANCE /*hPrevInstance*/,
1344 LPTSTR lpCmdLine,
1345 int nCmdShow)
1347 app.hInstance = hInstance;
1348 MSG msg;
1349 HACCEL hAccelTable;
1351 if (::LoadLibrary("SciLexer.DLL") == NULL)
1352 return FALSE;
1354 CRegStdDWORD loc = CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033);
1355 long langId = loc;
1357 CLangDll langDLL;
1358 app.hResource = langDLL.Init(_T("CTortoiseGitBlameView"), langId);
1359 if (app.hResource == NULL)
1360 app.hResource = app.hInstance;
1362 // Initialize global strings
1363 LoadString(app.hResource, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
1364 LoadString(app.hResource, IDC_TortoiseGitBlameView, szWindowClass, MAX_LOADSTRING);
1365 LoadString(app.hResource, IDS_SEARCHNOTFOUND, searchstringnotfound, MAX_LOADSTRING);
1366 MyRegisterClass(app.hResource);
1367 MyRegisterBlameClass(app.hResource);
1368 MyRegisterHeaderClass(app.hResource);
1369 MyRegisterLocatorClass(app.hResource);
1371 // Perform application initialization:
1372 if (!InitInstance (app.hResource, nCmdShow))
1374 langDLL.Close();
1375 return FALSE;
1378 SecureZeroMemory(szViewtitle, MAX_PATH);
1379 SecureZeroMemory(szOrigPath, MAX_PATH);
1380 char blamefile[MAX_PATH] = {0};
1381 char logfile[MAX_PATH] = {0};
1383 CCmdLineParser parser(lpCmdLine);
1386 if (__argc > 1)
1388 _tcscpy_s(blamefile, MAX_PATH, __argv[1]);
1390 if (__argc > 2)
1392 _tcscpy_s(logfile, MAX_PATH, __argv[2]);
1394 if (__argc > 3)
1396 _tcscpy_s(szViewtitle, MAX_PATH, __argv[3]);
1397 if (parser.HasVal(_T("revrange")))
1399 _tcscat_s(szViewtitle, MAX_PATH, _T(" : "));
1400 _tcscat_s(szViewtitle, MAX_PATH, parser.GetVal(_T("revrange")));
1403 if ((_tcslen(blamefile)==0) || parser.HasKey(_T("?")) || parser.HasKey(_T("help")))
1405 TCHAR szInfo[MAX_LOADSTRING];
1406 LoadString(app.hResource, IDS_COMMANDLINE_INFO, szInfo, MAX_LOADSTRING);
1407 MessageBox(NULL, szInfo, _T("CTortoiseGitBlameView"), MB_ICONERROR);
1408 langDLL.Close();
1409 return 0;
1412 if ( parser.HasKey(_T("path")) )
1414 _tcscpy_s(szOrigPath, MAX_PATH, parser.GetVal(_T("path")));
1416 app.bIgnoreEOL = parser.HasKey(_T("ignoreeol"));
1417 app.bIgnoreSpaces = parser.HasKey(_T("ignorespaces"));
1418 app.bIgnoreAllSpaces = parser.HasKey(_T("ignoreallspaces"));
1420 app.SendEditor(SCI_SETCODEPAGE, GetACP());
1421 app.OpenFile(blamefile);
1422 if (_tcslen(logfile)>0)
1423 app.OpenLogFile(logfile);
1425 if (parser.HasKey(_T("line")))
1427 app.GotoLine(parser.GetLongVal(_T("line")));
1430 CheckMenuItem(GetMenu(app.wMain), ID_VIEW_COLORAGEOFLINES, MF_CHECKED|MF_BYCOMMAND);
1433 hAccelTable = LoadAccelerators(app.hResource, (LPCTSTR)IDC_TortoiseGitBlameView);
1435 BOOL going = TRUE;
1436 msg.wParam = 0;
1437 while (going)
1439 going = GetMessage(&msg, NULL, 0, 0);
1440 if (app.currentDialog && going)
1442 if (!IsDialogMessage(app.currentDialog, &msg))
1444 if (TranslateAccelerator(msg.hwnd, hAccelTable, &msg) == 0)
1446 TranslateMessage(&msg);
1447 DispatchMessage(&msg);
1451 else if (going)
1453 if (TranslateAccelerator(app.wMain, hAccelTable, &msg) == 0)
1455 TranslateMessage(&msg);
1456 DispatchMessage(&msg);
1460 langDLL.Close();
1461 return msg.wParam;
1464 ATOM MyRegisterClass(HINSTANCE hResource)
1466 WNDCLASSEX wcex;
1468 wcex.cbSize = sizeof(WNDCLASSEX);
1470 wcex.style = CS_HREDRAW | CS_VREDRAW;
1471 wcex.lpfnWndProc = (WNDPROC)WndProc;
1472 wcex.cbClsExtra = 0;
1473 wcex.cbWndExtra = 0;
1474 wcex.hInstance = hResource;
1475 wcex.hIcon = LoadIcon(hResource, (LPCTSTR)IDI_TortoiseGitBlameView);
1476 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
1477 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
1478 wcex.lpszMenuName = (LPCTSTR)IDC_TortoiseGitBlameView;
1479 wcex.lpszClassName = szWindowClass;
1480 wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
1482 return RegisterClassEx(&wcex);
1485 ATOM MyRegisterBlameClass(HINSTANCE hResource)
1487 WNDCLASSEX wcex;
1489 wcex.cbSize = sizeof(WNDCLASSEX);
1491 wcex.style = CS_HREDRAW | CS_VREDRAW;
1492 wcex.lpfnWndProc = (WNDPROC)WndBlameProc;
1493 wcex.cbClsExtra = 0;
1494 wcex.cbWndExtra = 0;
1495 wcex.hInstance = hResource;
1496 wcex.hIcon = LoadIcon(hResource, (LPCTSTR)IDI_TortoiseGitBlameView);
1497 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
1498 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
1499 wcex.lpszMenuName = 0;
1500 wcex.lpszClassName = _T("TortoiseGitBlameViewBlame");
1501 wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
1503 return RegisterClassEx(&wcex);
1506 ATOM MyRegisterHeaderClass(HINSTANCE hResource)
1508 WNDCLASSEX wcex;
1510 wcex.cbSize = sizeof(WNDCLASSEX);
1512 wcex.style = CS_HREDRAW | CS_VREDRAW;
1513 wcex.lpfnWndProc = (WNDPROC)WndHeaderProc;
1514 wcex.cbClsExtra = 0;
1515 wcex.cbWndExtra = 0;
1516 wcex.hInstance = hResource;
1517 wcex.hIcon = LoadIcon(hResource, (LPCTSTR)IDI_TortoiseGitBlameView);
1518 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
1519 wcex.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
1520 wcex.lpszMenuName = 0;
1521 wcex.lpszClassName = _T("TortoiseGitBlameViewHeader");
1522 wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
1524 return RegisterClassEx(&wcex);
1527 ATOM MyRegisterLocatorClass(HINSTANCE hResource)
1529 WNDCLASSEX wcex;
1531 wcex.cbSize = sizeof(WNDCLASSEX);
1533 wcex.style = CS_HREDRAW | CS_VREDRAW;
1534 wcex.lpfnWndProc = (WNDPROC)WndLocatorProc;
1535 wcex.cbClsExtra = 0;
1536 wcex.cbWndExtra = 0;
1537 wcex.hInstance = hResource;
1538 wcex.hIcon = LoadIcon(hResource, (LPCTSTR)IDI_TortoiseGitBlameView);
1539 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
1540 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
1541 wcex.lpszMenuName = 0;
1542 wcex.lpszClassName = _T("TortoiseGitBlameViewLocator");
1543 wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
1545 return RegisterClassEx(&wcex);
1548 BOOL InitInstance(HINSTANCE hResource, int nCmdShow)
1550 app.wMain = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
1551 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hResource, NULL);
1553 if (!app.wMain)
1555 return FALSE;
1558 CRegStdDWORD pos(_T("Software\\TortoiseGit\\TBlamePos"), 0);
1559 CRegStdDWORD width(_T("Software\\TortoiseGit\\TBlameSize"), 0);
1560 CRegStdDWORD state(_T("Software\\TortoiseGit\\TBlameState"), 0);
1561 if (DWORD(pos) && DWORD(width))
1563 RECT rc;
1564 rc.left = LOWORD(DWORD(pos));
1565 rc.top = HIWORD(DWORD(pos));
1566 rc.right = rc.left + LOWORD(DWORD(width));
1567 rc.bottom = rc.top + HIWORD(DWORD(width));
1568 HMONITOR hMon = MonitorFromRect(&rc, MONITOR_DEFAULTTONULL);
1569 if (hMon)
1571 // only restore the window position if the monitor is valid
1572 MoveWindow(app.wMain, LOWORD(DWORD(pos)), HIWORD(DWORD(pos)),
1573 LOWORD(DWORD(width)), HIWORD(DWORD(width)), FALSE);
1576 if (DWORD(state) == SW_MAXIMIZE)
1577 ShowWindow(app.wMain, SW_MAXIMIZE);
1578 else
1579 ShowWindow(app.wMain, nCmdShow);
1580 UpdateWindow(app.wMain);
1582 //Create the tooltips
1584 INITCOMMONCONTROLSEX iccex;
1585 app.hwndTT; // handle to the ToolTip control
1586 TOOLINFO ti;
1587 RECT rect; // for client area coordinates
1588 iccex.dwICC = ICC_WIN95_CLASSES;
1589 iccex.dwSize = sizeof(INITCOMMONCONTROLSEX);
1590 InitCommonControlsEx(&iccex);
1592 /* CREATE A TOOLTIP WINDOW */
1593 app.hwndTT = CreateWindowEx(WS_EX_TOPMOST,
1594 TOOLTIPS_CLASS,
1595 NULL,
1596 WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
1597 CW_USEDEFAULT,
1598 CW_USEDEFAULT,
1599 CW_USEDEFAULT,
1600 CW_USEDEFAULT,
1601 app.wBlame,
1602 NULL,
1603 app.hResource,
1604 NULL
1607 SetWindowPos(app.hwndTT,
1608 HWND_TOPMOST,
1613 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
1615 /* GET COORDINATES OF THE MAIN CLIENT AREA */
1616 GetClientRect (app.wBlame, &rect);
1618 /* INITIALIZE MEMBERS OF THE TOOLINFO STRUCTURE */
1619 ti.cbSize = sizeof(TOOLINFO);
1620 ti.uFlags = TTF_TRACK | TTF_ABSOLUTE;//TTF_SUBCLASS | TTF_PARSELINKS;
1621 ti.hwnd = app.wBlame;
1622 ti.hinst = app.hResource;
1623 ti.uId = 0;
1624 ti.lpszText = LPSTR_TEXTCALLBACK;
1625 // ToolTip control will cover the whole window
1626 ti.rect.left = rect.left;
1627 ti.rect.top = rect.top;
1628 ti.rect.right = rect.right;
1629 ti.rect.bottom = rect.bottom;
1631 /* SEND AN ADDTOOL MESSAGE TO THE TOOLTIP CONTROL WINDOW */
1632 SendMessage(app.hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
1633 SendMessage(app.hwndTT, TTM_SETMAXTIPWIDTH, 0, 600);
1634 //SendMessage(app.hwndTT, TTM_SETDELAYTIME, TTDT_AUTOPOP, MAKELONG(50000, 0));
1635 //SendMessage(app.hwndTT, TTM_SETDELAYTIME, TTDT_RESHOW, MAKELONG(1000, 0));
1637 uFindReplaceMsg = RegisterWindowMessage(FINDMSGSTRING);
1639 return TRUE;
1641 #endif
1642 void CTortoiseGitBlameView::InitSize()
1644 RECT rc;
1645 RECT blamerc;
1646 RECT sourcerc;
1647 ::GetClientRect(wMain, &rc);
1648 ::SetWindowPos(wHeader, 0, rc.left, rc.top, rc.right-rc.left, HEADER_HEIGHT, 0);
1649 rc.top += HEADER_HEIGHT;
1650 blamerc.left = rc.left;
1651 blamerc.top = rc.top;
1652 LONG w = GetBlameWidth();
1653 blamerc.right = w > abs(rc.right - rc.left) ? rc.right : w + rc.left;
1654 blamerc.bottom = rc.bottom;
1655 sourcerc.left = blamerc.right;
1656 sourcerc.top = rc.top;
1657 sourcerc.bottom = rc.bottom;
1658 sourcerc.right = rc.right;
1659 if (m_colorage)
1661 ::OffsetRect(&blamerc, LOCATOR_WIDTH, 0);
1662 ::OffsetRect(&sourcerc, LOCATOR_WIDTH, 0);
1663 sourcerc.right -= LOCATOR_WIDTH;
1665 ::InvalidateRect(wMain, NULL, FALSE);
1666 ::SetWindowPos(m_wEditor, 0, sourcerc.left, sourcerc.top, sourcerc.right - sourcerc.left, sourcerc.bottom - sourcerc.top, 0);
1667 ::SetWindowPos(wBlame, 0, blamerc.left, blamerc.top, blamerc.right - blamerc.left, blamerc.bottom - blamerc.top, 0);
1668 if (m_colorage)
1669 ::SetWindowPos(wLocator, 0, 0, blamerc.top, LOCATOR_WIDTH, blamerc.bottom - blamerc.top, SWP_SHOWWINDOW);
1670 else
1671 ::ShowWindow(wLocator, SW_HIDE);
1674 #if 0
1675 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1677 if (message == uFindReplaceMsg)
1679 LPFINDREPLACE lpfr = (LPFINDREPLACE)lParam;
1681 // If the FR_DIALOGTERM flag is set,
1682 // invalidate the handle identifying the dialog box.
1683 if (lpfr->Flags & FR_DIALOGTERM)
1685 app.currentDialog = NULL;
1686 return 0;
1688 if (lpfr->Flags & FR_FINDNEXT)
1690 app.DoSearch(lpfr->lpstrFindWhat, lpfr->Flags);
1692 return 0;
1694 switch (message)
1696 case WM_CREATE:
1697 app.m_wEditor = ::CreateWindow(
1698 "Scintilla",
1699 "Source",
1700 WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_CLIPCHILDREN,
1701 0, 0,
1702 100, 100,
1703 hWnd,
1705 app.hResource,
1707 app.InitialiseEditor();
1708 ::ShowWindow(app.m_wEditor, SW_SHOW);
1709 ::SetFocus(app.m_wEditor);
1710 app.wBlame = ::CreateWindow(
1711 _T("TortoiseGitBlameViewBlame"),
1712 _T("blame"),
1713 WS_CHILD | WS_CLIPCHILDREN,
1714 CW_USEDEFAULT, 0,
1715 CW_USEDEFAULT, 0,
1716 hWnd,
1717 NULL,
1718 app.hResource,
1719 NULL);
1720 ::ShowWindow(app.wBlame, SW_SHOW);
1721 app.wHeader = ::CreateWindow(
1722 _T("TortoiseGitBlameViewHeader"),
1723 _T("header"),
1724 WS_CHILD | WS_CLIPCHILDREN | WS_BORDER,
1725 CW_USEDEFAULT, 0,
1726 CW_USEDEFAULT, 0,
1727 hWnd,
1728 NULL,
1729 app.hResource,
1730 NULL);
1731 ::ShowWindow(app.wHeader, SW_SHOW);
1732 app.wLocator = ::CreateWindow(
1733 _T("TortoiseGitBlameViewLocator"),
1734 _T("locator"),
1735 WS_CHILD | WS_CLIPCHILDREN | WS_BORDER,
1736 CW_USEDEFAULT, 0,
1737 CW_USEDEFAULT, 0,
1738 hWnd,
1739 NULL,
1740 app.hResource,
1741 NULL);
1742 ::ShowWindow(app.wLocator, SW_SHOW);
1743 return 0;
1745 case WM_SIZE:
1746 if (wParam != 1)
1748 app.InitSize();
1750 return 0;
1752 case WM_COMMAND:
1753 app.Command(LOWORD(wParam));
1754 break;
1755 case WM_NOTIFY:
1756 app.Notify(reinterpret_cast<SCNotification *>(lParam));
1757 return 0;
1758 case WM_DESTROY:
1759 PostQuitMessage(0);
1760 break;
1761 case WM_CLOSE:
1763 CRegStdDWORD pos(_T("Software\\TortoiseGit\\TBlamePos"), 0);
1764 CRegStdDWORD width(_T("Software\\TortoiseGit\\TBlameSize"), 0);
1765 CRegStdDWORD state(_T("Software\\TortoiseGit\\TBlameState"), 0);
1766 RECT rc;
1767 GetWindowRect(app.wMain, &rc);
1768 if ((rc.left >= 0)&&(rc.top >= 0))
1770 pos = MAKELONG(rc.left, rc.top);
1771 width = MAKELONG(rc.right-rc.left, rc.bottom-rc.top);
1773 WINDOWPLACEMENT wp = {0};
1774 wp.length = sizeof(WINDOWPLACEMENT);
1775 GetWindowPlacement(app.wMain, &wp);
1776 state = wp.showCmd;
1777 ::DestroyWindow(app.m_wEditor);
1778 ::PostQuitMessage(0);
1780 return 0;
1781 case WM_SETFOCUS:
1782 ::SetFocus(app.wBlame);
1783 break;
1784 default:
1785 return DefWindowProc(hWnd, message, wParam, lParam);
1787 return 0;
1790 LRESULT CALLBACK WndBlameProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1792 PAINTSTRUCT ps;
1793 TRACKMOUSEEVENT mevt;
1794 HDC hDC;
1795 switch (message)
1797 case WM_CREATE:
1798 return 0;
1799 case WM_PAINT:
1800 hDC = BeginPaint(app.wBlame, &ps);
1801 app.DrawBlame(hDC);
1802 EndPaint(app.wBlame, &ps);
1803 break;
1804 case WM_COMMAND:
1805 app.Command(LOWORD(wParam));
1806 break;
1807 case WM_NOTIFY:
1808 switch (((LPNMHDR)lParam)->code)
1810 case TTN_GETDISPINFO:
1812 LPNMHDR pNMHDR = (LPNMHDR)lParam;
1813 NMTTDISPINFOA* pTTTA = (NMTTDISPINFOA*)pNMHDR;
1814 NMTTDISPINFOW* pTTTW = (NMTTDISPINFOW*)pNMHDR;
1815 POINT point;
1816 DWORD ptW = GetMessagePos();
1817 point.x = GET_X_LPARAM(ptW);
1818 point.y = GET_Y_LPARAM(ptW);
1819 ::ScreenToClient(app.wBlame, &point);
1820 LONG_PTR line = app.SendEditor(SCI_GETFIRSTVISIBLELINE);
1821 LONG_PTR height = app.SendEditor(SCI_TEXTHEIGHT);
1822 line = line + (point.y/height);
1823 if (line >= (LONG)app.revs.size())
1824 break;
1825 if (line < 0)
1826 break;
1827 LONG rev = app.revs[line];
1828 if (line >= (LONG)app.revs.size())
1829 break;
1831 SecureZeroMemory(app.m_szTip, sizeof(app.m_szTip));
1832 SecureZeroMemory(app.m_wszTip, sizeof(app.m_wszTip));
1833 std::map<LONG, CString>::iterator iter;
1834 if ((iter = app.logmessages.find(rev)) != app.logmessages.end())
1836 CString msg;
1837 if (!ShowAuthor)
1839 msg += app.authors[line];
1841 if (!ShowDate)
1843 if (!ShowAuthor) msg += " ";
1844 msg += app.dates[line];
1846 if (!ShowAuthor || !ShowDate)
1847 msg += '\n';
1848 msg += iter->second;
1849 // an empty tooltip string will deactivate the tooltips,
1850 // which means we must make sure that the tooltip won't
1851 // be empty.
1852 if (msg.empty())
1853 msg = _T(" ");
1854 if (pNMHDR->code == TTN_NEEDTEXTA)
1856 lstrcpyn(app.m_szTip, msg.c_str(), MAX_LOG_LENGTH*2);
1857 app.StringExpand(app.m_szTip);
1858 pTTTA->lpszText = app.m_szTip;
1860 else
1862 pTTTW->lpszText = app.m_wszTip;
1863 ::MultiByteToWideChar( CP_ACP , 0, msg.c_str(), min(msg.size(), MAX_LOG_LENGTH*2), app.m_wszTip, MAX_LOG_LENGTH*2);
1864 app.StringExpand(app.m_wszTip);
1868 break;
1870 return 0;
1871 case WM_DESTROY:
1872 break;
1873 case WM_CLOSE:
1874 return 0;
1875 case WM_MOUSELEAVE:
1876 app.m_mouserev = -2;
1877 app.m_mouseauthor.clear();
1878 app.ttVisible = FALSE;
1879 SendMessage(app.hwndTT, TTM_TRACKACTIVATE, FALSE, 0);
1880 ::InvalidateRect(app.wBlame, NULL, FALSE);
1881 break;
1882 case WM_MOUSEMOVE:
1884 mevt.cbSize = sizeof(TRACKMOUSEEVENT);
1885 mevt.dwFlags = TME_LEAVE;
1886 mevt.dwHoverTime = HOVER_DEFAULT;
1887 mevt.hwndTrack = app.wBlame;
1888 ::TrackMouseEvent(&mevt);
1889 POINT pt = {((int)(short)LOWORD(lParam)), ((int)(short)HIWORD(lParam))};
1890 ClientToScreen(app.wBlame, &pt);
1891 pt.x += 15;
1892 pt.y += 15;
1893 SendMessage(app.hwndTT, TTM_TRACKPOSITION, 0, MAKELONG(pt.x, pt.y));
1894 if (!app.ttVisible)
1896 TOOLINFO ti;
1897 ti.cbSize = sizeof(TOOLINFO);
1898 ti.hwnd = app.wBlame;
1899 ti.uId = 0;
1900 SendMessage(app.hwndTT, TTM_TRACKACTIVATE, TRUE, (LPARAM)&ti);
1902 int y = ((int)(short)HIWORD(lParam));
1903 LONG_PTR line = app.SendEditor(SCI_GETFIRSTVISIBLELINE);
1904 LONG_PTR height = app.SendEditor(SCI_TEXTHEIGHT);
1905 line = line + (y/height);
1906 app.ttVisible = (line < (LONG)app.revs.size());
1907 if ( app.ttVisible )
1909 if (app.authors[line].compare(app.m_mouseauthor) != 0)
1911 app.m_mouseauthor = app.authors[line];
1913 if (app.revs[line] != app.m_mouserev)
1915 app.m_mouserev = app.revs[line];
1916 ::InvalidateRect(app.wBlame, NULL, FALSE);
1917 SendMessage(app.hwndTT, TTM_UPDATE, 0, 0);
1921 break;
1922 case WM_RBUTTONDOWN:
1923 // fall through
1924 case WM_LBUTTONDOWN:
1926 break;
1927 case WM_SETFOCUS:
1928 ::SetFocus(app.wBlame);
1929 app.SendEditor(SCI_GRABFOCUS);
1930 break;
1931 case WM_CONTEXTMENU:
1933 if (app.m_selectedrev <= 0)
1934 break;;
1935 int xPos = GET_X_LPARAM(lParam);
1936 int yPos = GET_Y_LPARAM(lParam);
1937 if ((xPos < 0)||(yPos < 0))
1939 // requested from keyboard, not mouse pointer
1940 // use the center of the window
1941 RECT rect;
1942 GetClientRect(app.wBlame, &rect);
1943 xPos = rect.right-rect.left;
1944 yPos = rect.bottom-rect.top;
1946 HMENU hMenu = LoadMenu(app.hResource, MAKEINTRESOURCE(IDR_BLAMEPOPUP));
1947 HMENU hPopMenu = GetSubMenu(hMenu, 0);
1949 if ( _tcslen(szOrigPath)==0 )
1951 // Without knowing the original path we cannot blame the previous revision
1952 // because we don't know which filename to pass to tortoiseproc.
1953 EnableMenuItem(hPopMenu,ID_BLAME_PREVIOUS_REVISION, MF_DISABLED|MF_GRAYED);
1956 TrackPopupMenu(hPopMenu, TPM_LEFTALIGN | TPM_RIGHTBUTTON, xPos, yPos, 0, app.wBlame, NULL);
1957 DestroyMenu(hMenu);
1959 break;
1960 default:
1961 return DefWindowProc(hWnd, message, wParam, lParam);
1963 return 0;
1966 LRESULT CALLBACK WndHeaderProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1968 PAINTSTRUCT ps;
1969 HDC hDC;
1970 switch (message)
1972 case WM_CREATE:
1973 return 0;
1974 case WM_PAINT:
1975 hDC = BeginPaint(app.wHeader, &ps);
1976 app.DrawHeader(hDC);
1977 EndPaint(app.wHeader, &ps);
1978 break;
1979 case WM_COMMAND:
1980 break;
1981 case WM_DESTROY:
1982 break;
1983 case WM_CLOSE:
1984 return 0;
1985 default:
1986 return DefWindowProc(hWnd, message, wParam, lParam);
1988 return 0;
1991 LRESULT CALLBACK WndLocatorProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1993 PAINTSTRUCT ps;
1994 HDC hDC;
1995 switch (message)
1997 case WM_PAINT:
1998 hDC = BeginPaint(app.wLocator, &ps);
1999 app.DrawLocatorBar(hDC);
2000 EndPaint(app.wLocator, &ps);
2001 break;
2002 case WM_LBUTTONDOWN:
2003 case WM_MOUSEMOVE:
2004 if (wParam & MK_LBUTTON)
2006 RECT rect;
2007 ::GetClientRect(hWnd, &rect);
2008 int nLine = HIWORD(lParam)*app.revs.size()/(rect.bottom-rect.top);
2010 if (nLine < 0)
2011 nLine = 0;
2012 app.ScrollToLine(nLine);
2014 break;
2015 default:
2016 return DefWindowProc(hWnd, message, wParam, lParam);
2018 return 0;
2020 #endif
2022 void CTortoiseGitBlameView::SetupLexer(CString filename)
2025 TCHAR *line;
2026 //const char * lineptr = _tcsrchr(filename, '.');
2027 int start=filename.ReverseFind(_T('.'));
2028 if (start>0)
2030 //_tcscpy_s(line, 20, lineptr+1);
2031 //_tcslwr_s(line, 20);
2032 CString ext=filename.Right(filename.GetLength()-start-1);
2033 line=ext.GetBuffer();
2035 if ((_tcscmp(line, _T("py"))==0)||
2036 (_tcscmp(line, _T("pyw"))==0))
2038 SendEditor(SCI_SETLEXER, SCLEX_PYTHON);
2039 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("and assert break class continue def del elif \
2040 else except exec finally for from global if import in is lambda None \
2041 not or pass print raise return try while yield")).GetBuffer()));
2042 SetAStyle(SCE_P_DEFAULT, black);
2043 SetAStyle(SCE_P_COMMENTLINE, darkGreen);
2044 SetAStyle(SCE_P_NUMBER, RGB(0, 0x80, 0x80));
2045 SetAStyle(SCE_P_STRING, RGB(0, 0, 0x80));
2046 SetAStyle(SCE_P_CHARACTER, RGB(0, 0, 0x80));
2047 SetAStyle(SCE_P_WORD, RGB(0x80, 0, 0x80));
2048 SetAStyle(SCE_P_TRIPLE, black);
2049 SetAStyle(SCE_P_TRIPLEDOUBLE, black);
2050 SetAStyle(SCE_P_CLASSNAME, darkBlue);
2051 SetAStyle(SCE_P_DEFNAME, darkBlue);
2052 SetAStyle(SCE_P_OPERATOR, darkBlue);
2053 SetAStyle(SCE_P_IDENTIFIER, darkBlue);
2054 SetAStyle(SCE_P_COMMENTBLOCK, darkGreen);
2055 SetAStyle(SCE_P_STRINGEOL, red);
2057 if ((_tcscmp(line, _T("c"))==0)||
2058 (_tcscmp(line, _T("cc"))==0)||
2059 (_tcscmp(line, _T("cpp"))==0)||
2060 (_tcscmp(line, _T("cxx"))==0)||
2061 (_tcscmp(line, _T("h"))==0)||
2062 (_tcscmp(line, _T("hh"))==0)||
2063 (_tcscmp(line, _T("hpp"))==0)||
2064 (_tcscmp(line, _T("hxx"))==0)||
2065 (_tcscmp(line, _T("dlg"))==0)||
2066 (_tcscmp(line, _T("mak"))==0))
2068 SendEditor(SCI_SETLEXER, SCLEX_CPP);
2069 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("and and_eq asm auto bitand bitor bool break \
2070 case catch char class compl const const_cast continue \
2071 default delete do double dynamic_cast else enum explicit export extern false float for \
2072 friend goto if inline int long mutable namespace new not not_eq \
2073 operator or or_eq private protected public \
2074 register reinterpret_cast return short signed sizeof static static_cast struct switch \
2075 template this throw true try typedef typeid typename union unsigned using \
2076 virtual void volatile wchar_t while xor xor_eq")).GetBuffer()));
2077 SendEditor(SCI_SETKEYWORDS, 3, (LPARAM)(m_TextView.StringForControl(_T("a addindex addtogroup anchor arg attention \
2078 author b brief bug c class code date def defgroup deprecated dontinclude \
2079 e em endcode endhtmlonly endif endlatexonly endlink endverbatim enum example exception \
2080 f$ f[ f] file fn hideinitializer htmlinclude htmlonly \
2081 if image include ingroup internal invariant interface latexonly li line link \
2082 mainpage name namespace nosubgrouping note overload \
2083 p page par param post pre ref relates remarks return retval \
2084 sa section see showinitializer since skip skipline struct subsection \
2085 test throw todo typedef union until \
2086 var verbatim verbinclude version warning weakgroup $ @ \\ & < > # { }")).GetBuffer()));
2087 SetupCppLexer();
2089 if (_tcscmp(line, _T("cs"))==0)
2091 SendEditor(SCI_SETLEXER, SCLEX_CPP);
2092 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("abstract as base bool break byte case catch char checked class \
2093 const continue decimal default delegate do double else enum \
2094 event explicit extern false finally fixed float for foreach goto if \
2095 implicit in int interface internal is lock long namespace new null \
2096 object operator out override params private protected public \
2097 readonly ref return sbyte sealed short sizeof stackalloc static \
2098 string struct switch this throw true try typeof uint ulong \
2099 unchecked unsafe ushort using virtual void while")).GetBuffer()));
2100 SetupCppLexer();
2102 if ((_tcscmp(line, _T("rc"))==0)||
2103 (_tcscmp(line, _T("rc2"))==0))
2105 SendEditor(SCI_SETLEXER, SCLEX_CPP);
2106 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("ACCELERATORS ALT AUTO3STATE AUTOCHECKBOX AUTORADIOBUTTON \
2107 BEGIN BITMAP BLOCK BUTTON CAPTION CHARACTERISTICS CHECKBOX CLASS \
2108 COMBOBOX CONTROL CTEXT CURSOR DEFPUSHBUTTON DIALOG DIALOGEX DISCARDABLE \
2109 EDITTEXT END EXSTYLE FONT GROUPBOX ICON LANGUAGE LISTBOX LTEXT \
2110 MENU MENUEX MENUITEM MESSAGETABLE POPUP \
2111 PUSHBUTTON RADIOBUTTON RCDATA RTEXT SCROLLBAR SEPARATOR SHIFT STATE3 \
2112 STRINGTABLE STYLE TEXTINCLUDE VALUE VERSION VERSIONINFO VIRTKEY")).GetBuffer()));
2113 SetupCppLexer();
2115 if ((_tcscmp(line, _T("idl"))==0)||
2116 (_tcscmp(line, _T("odl"))==0))
2118 SendEditor(SCI_SETLEXER, SCLEX_CPP);
2119 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("aggregatable allocate appobject arrays async async_uuid \
2120 auto_handle \
2121 bindable boolean broadcast byte byte_count \
2122 call_as callback char coclass code comm_status \
2123 const context_handle context_handle_noserialize \
2124 context_handle_serialize control cpp_quote custom \
2125 decode default defaultbind defaultcollelem \
2126 defaultvalue defaultvtable dispinterface displaybind dllname \
2127 double dual \
2128 enable_allocate encode endpoint entry enum error_status_t \
2129 explicit_handle \
2130 fault_status first_is float \
2131 handle_t heap helpcontext helpfile helpstring \
2132 helpstringcontext helpstringdll hidden hyper \
2133 id idempotent ignore iid_as iid_is immediatebind implicit_handle \
2134 import importlib in include in_line int __int64 __int3264 interface \
2135 last_is lcid length_is library licensed local long \
2136 max_is maybe message methods midl_pragma \
2137 midl_user_allocate midl_user_free min_is module ms_union \
2138 ncacn_at_dsp ncacn_dnet_nsp ncacn_http ncacn_ip_tcp \
2139 ncacn_nb_ipx ncacn_nb_nb ncacn_nb_tcp ncacn_np \
2140 ncacn_spx ncacn_vns_spp ncadg_ip_udp ncadg_ipx ncadg_mq \
2141 ncalrpc nocode nonbrowsable noncreatable nonextensible notify \
2142 object odl oleautomation optimize optional out out_of_line \
2143 pipe pointer_default pragma properties propget propput propputref \
2144 ptr public \
2145 range readonly ref represent_as requestedit restricted retval \
2146 shape short signed size_is small source strict_context_handle \
2147 string struct switch switch_is switch_type \
2148 transmit_as typedef \
2149 uidefault union unique unsigned user_marshal usesgetlasterror uuid \
2150 v1_enum vararg version void wchar_t wire_marshal")).GetBuffer()));
2151 SetupCppLexer();
2153 if (_tcscmp(line, _T("java"))==0)
2155 SendEditor(SCI_SETLEXER, SCLEX_CPP);
2156 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("abstract assert boolean break byte case catch char class \
2157 const continue default do double else extends final finally float for future \
2158 generic goto if implements import inner instanceof int interface long \
2159 native new null outer package private protected public rest \
2160 return short static super switch synchronized this throw throws \
2161 transient try var void volatile while")).GetBuffer()));
2162 SetupCppLexer();
2164 if (_tcscmp(line, _T("js"))==0)
2166 SendEditor(SCI_SETLEXER, SCLEX_CPP);
2167 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("abstract boolean break byte case catch char class \
2168 const continue debugger default delete do double else enum export extends \
2169 final finally float for function goto if implements import in instanceof \
2170 int interface long native new package private protected public \
2171 return short static super switch synchronized this throw throws \
2172 transient try typeof var void volatile while with")).GetBuffer()));
2173 SetupCppLexer();
2175 if ((_tcscmp(line, _T("pas"))==0)||
2176 (_tcscmp(line, _T("dpr"))==0)||
2177 (_tcscmp(line, _T("pp"))==0))
2179 SendEditor(SCI_SETLEXER, SCLEX_PASCAL);
2180 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("and array as begin case class const constructor \
2181 destructor div do downto else end except file finally \
2182 for function goto if implementation in inherited \
2183 interface is mod not object of on or packed \
2184 procedure program property raise record repeat \
2185 set shl shr then threadvar to try type unit \
2186 until uses var while with xor")).GetBuffer()));
2187 SetupCppLexer();
2189 if ((_tcscmp(line, _T("as"))==0)||
2190 (_tcscmp(line, _T("asc"))==0)||
2191 (_tcscmp(line, _T("jsfl"))==0))
2193 SendEditor(SCI_SETLEXER, SCLEX_CPP);
2194 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("add and break case catch class continue default delete do \
2195 dynamic else eq extends false finally for function ge get gt if implements import in \
2196 instanceof interface intrinsic le lt ne new not null or private public return \
2197 set static super switch this throw true try typeof undefined var void while with")).GetBuffer()));
2198 SendEditor(SCI_SETKEYWORDS, 1, (LPARAM)(m_TextView.StringForControl(_T("Array Arguments Accessibility Boolean Button Camera Color \
2199 ContextMenu ContextMenuItem Date Error Function Key LoadVars LocalConnection Math \
2200 Microphone Mouse MovieClip MovieClipLoader NetConnection NetStream Number Object \
2201 PrintJob Selection SharedObject Sound Stage String StyleSheet System TextField \
2202 TextFormat TextSnapshot Video Void XML XMLNode XMLSocket \
2203 _accProps _focusrect _global _highquality _parent _quality _root _soundbuftime \
2204 arguments asfunction call capabilities chr clearInterval duplicateMovieClip \
2205 escape eval fscommand getProperty getTimer getURL getVersion gotoAndPlay gotoAndStop \
2206 ifFrameLoaded Infinity -Infinity int isFinite isNaN length loadMovie loadMovieNum \
2207 loadVariables loadVariablesNum maxscroll mbchr mblength mbord mbsubstring MMExecute \
2208 NaN newline nextFrame nextScene on onClipEvent onUpdate ord parseFloat parseInt play \
2209 prevFrame prevScene print printAsBitmap printAsBitmapNum printNum random removeMovieClip \
2210 scroll set setInterval setProperty startDrag stop stopAllSounds stopDrag substring \
2211 targetPath tellTarget toggleHighQuality trace unescape unloadMovie unLoadMovieNum updateAfterEvent")).GetBuffer()));
2212 SetupCppLexer();
2214 if ((_tcscmp(line, _T("html"))==0)||
2215 (_tcscmp(line, _T("htm"))==0)||
2216 (_tcscmp(line, _T("shtml"))==0)||
2217 (_tcscmp(line, _T("htt"))==0)||
2218 (_tcscmp(line, _T("xml"))==0)||
2219 (_tcscmp(line, _T("asp"))==0)||
2220 (_tcscmp(line, _T("xsl"))==0)||
2221 (_tcscmp(line, _T("php"))==0)||
2222 (_tcscmp(line, _T("xhtml"))==0)||
2223 (_tcscmp(line, _T("phtml"))==0)||
2224 (_tcscmp(line, _T("cfm"))==0)||
2225 (_tcscmp(line, _T("tpl"))==0)||
2226 (_tcscmp(line, _T("dtd"))==0)||
2227 (_tcscmp(line, _T("hta"))==0)||
2228 (_tcscmp(line, _T("htd"))==0)||
2229 (_tcscmp(line, _T("wxs"))==0))
2231 SendEditor(SCI_SETLEXER, SCLEX_HTML);
2232 SendEditor(SCI_SETSTYLEBITS, 7);
2233 SendEditor(SCI_SETKEYWORDS, 0, (LPARAM)(m_TextView.StringForControl(_T("a abbr acronym address applet area b base basefont \
2234 bdo big blockquote body br button caption center \
2235 cite code col colgroup dd del dfn dir div dl dt em \
2236 fieldset font form frame frameset h1 h2 h3 h4 h5 h6 \
2237 head hr html i iframe img input ins isindex kbd label \
2238 legend li link map menu meta noframes noscript \
2239 object ol optgroup option p param pre q s samp \
2240 script select small span strike strong style sub sup \
2241 table tbody td textarea tfoot th thead title tr tt u ul \
2242 var xml xmlns abbr accept-charset accept accesskey action align alink \
2243 alt archive axis background bgcolor border \
2244 cellpadding cellspacing char charoff charset checked cite \
2245 class classid clear codebase codetype color cols colspan \
2246 compact content coords \
2247 data datafld dataformatas datapagesize datasrc datetime \
2248 declare defer dir disabled enctype event \
2249 face for frame frameborder \
2250 headers height href hreflang hspace http-equiv \
2251 id ismap label lang language leftmargin link longdesc \
2252 marginwidth marginheight maxlength media method multiple \
2253 name nohref noresize noshade nowrap \
2254 object onblur onchange onclick ondblclick onfocus \
2255 onkeydown onkeypress onkeyup onload onmousedown \
2256 onmousemove onmouseover onmouseout onmouseup \
2257 onreset onselect onsubmit onunload \
2258 profile prompt readonly rel rev rows rowspan rules \
2259 scheme scope selected shape size span src standby start style \
2260 summary tabindex target text title topmargin type usemap \
2261 valign value valuetype version vlink vspace width \
2262 text password checkbox radio submit reset \
2263 file hidden image")).GetBuffer()));
2264 SendEditor(SCI_SETKEYWORDS, 1, (LPARAM)(m_TextView.StringForControl(_T("assign audio block break catch choice clear disconnect else elseif \
2265 emphasis enumerate error exit field filled form goto grammar help \
2266 if initial link log menu meta noinput nomatch object option p paragraph \
2267 param phoneme prompt property prosody record reprompt return s say-as \
2268 script sentence subdialog submit throw transfer value var voice vxml")).GetBuffer()));
2269 SendEditor(SCI_SETKEYWORDS, 2, (LPARAM)(m_TextView.StringForControl(_T("accept age alphabet anchor application base beep bridge category charset \
2270 classid cond connecttimeout content contour count dest destexpr dtmf dtmfterm \
2271 duration enctype event eventexpr expr expritem fetchtimeout finalsilence \
2272 gender http-equiv id level maxage maxstale maxtime message messageexpr \
2273 method mime modal mode name namelist next nextitem ph pitch range rate \
2274 scope size sizeexpr skiplist slot src srcexpr sub time timeexpr timeout \
2275 transferaudio type value variant version volume xml:lang")).GetBuffer()));
2276 SendEditor(SCI_SETKEYWORDS, 3, (LPARAM)(m_TextView.StringForControl(_T("and assert break class continue def del elif \
2277 else except exec finally for from global if import in is lambda None \
2278 not or pass print raise return try while yield")).GetBuffer()));
2279 SendEditor(SCI_SETKEYWORDS, 4, (LPARAM)(m_TextView.StringForControl(_T("and argv as argc break case cfunction class continue declare default do \
2280 die echo else elseif empty enddeclare endfor endforeach endif endswitch \
2281 endwhile e_all e_parse e_error e_warning eval exit extends false for \
2282 foreach function global http_cookie_vars http_get_vars http_post_vars \
2283 http_post_files http_env_vars http_server_vars if include include_once \
2284 list new not null old_function or parent php_os php_self php_version \
2285 print require require_once return static switch stdclass this true var \
2286 xor virtual while __file__ __line__ __sleep __wakeup")).GetBuffer()));
2288 SetAStyle(SCE_H_TAG, darkBlue);
2289 SetAStyle(SCE_H_TAGUNKNOWN, red);
2290 SetAStyle(SCE_H_ATTRIBUTE, darkBlue);
2291 SetAStyle(SCE_H_ATTRIBUTEUNKNOWN, red);
2292 SetAStyle(SCE_H_NUMBER, RGB(0x80,0,0x80));
2293 SetAStyle(SCE_H_DOUBLESTRING, RGB(0,0x80,0));
2294 SetAStyle(SCE_H_SINGLESTRING, RGB(0,0x80,0));
2295 SetAStyle(SCE_H_OTHER, RGB(0x80,0,0x80));
2296 SetAStyle(SCE_H_COMMENT, RGB(0x80,0x80,0));
2297 SetAStyle(SCE_H_ENTITY, RGB(0x80,0,0x80));
2299 SetAStyle(SCE_H_TAGEND, darkBlue);
2300 SetAStyle(SCE_H_XMLSTART, darkBlue); // <?
2301 SetAStyle(SCE_H_QUESTION, darkBlue); // <?
2302 SetAStyle(SCE_H_XMLEND, darkBlue); // ?>
2303 SetAStyle(SCE_H_SCRIPT, darkBlue); // <script
2304 SetAStyle(SCE_H_ASP, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <% ... %>
2305 SetAStyle(SCE_H_ASPAT, RGB(0x4F, 0x4F, 0), RGB(0xFF, 0xFF, 0)); // <%@ ... %>
2307 SetAStyle(SCE_HB_DEFAULT, black);
2308 SetAStyle(SCE_HB_COMMENTLINE, darkGreen);
2309 SetAStyle(SCE_HB_NUMBER, RGB(0,0x80,0x80));
2310 SetAStyle(SCE_HB_WORD, darkBlue);
2311 SendEditor(SCI_STYLESETBOLD, SCE_HB_WORD, 1);
2312 SetAStyle(SCE_HB_STRING, RGB(0x80,0,0x80));
2313 SetAStyle(SCE_HB_IDENTIFIER, black);
2315 // This light blue is found in the windows system palette so is safe to use even in 256 colour modes.
2316 // Show the whole section of VBScript with light blue background
2317 for (int bstyle=SCE_HB_DEFAULT; bstyle<=SCE_HB_STRINGEOL; bstyle++) {
2318 SendEditor(SCI_STYLESETFONT, bstyle,
2319 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
2320 SendEditor(SCI_STYLESETBACK, bstyle, lightBlue);
2321 // This call extends the backround colour of the last style on the line to the edge of the window
2322 SendEditor(SCI_STYLESETEOLFILLED, bstyle, 1);
2324 SendEditor(SCI_STYLESETBACK, SCE_HB_STRINGEOL, RGB(0x7F,0x7F,0xFF));
2325 SendEditor(SCI_STYLESETFONT, SCE_HB_COMMENTLINE,
2326 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
2328 SetAStyle(SCE_HBA_DEFAULT, black);
2329 SetAStyle(SCE_HBA_COMMENTLINE, darkGreen);
2330 SetAStyle(SCE_HBA_NUMBER, RGB(0,0x80,0x80));
2331 SetAStyle(SCE_HBA_WORD, darkBlue);
2332 SendEditor(SCI_STYLESETBOLD, SCE_HBA_WORD, 1);
2333 SetAStyle(SCE_HBA_STRING, RGB(0x80,0,0x80));
2334 SetAStyle(SCE_HBA_IDENTIFIER, black);
2336 // Show the whole section of ASP VBScript with bright yellow background
2337 for (int bastyle=SCE_HBA_DEFAULT; bastyle<=SCE_HBA_STRINGEOL; bastyle++) {
2338 SendEditor(SCI_STYLESETFONT, bastyle,
2339 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
2340 SendEditor(SCI_STYLESETBACK, bastyle, RGB(0xFF, 0xFF, 0));
2341 // This call extends the backround colour of the last style on the line to the edge of the window
2342 SendEditor(SCI_STYLESETEOLFILLED, bastyle, 1);
2344 SendEditor(SCI_STYLESETBACK, SCE_HBA_STRINGEOL, RGB(0xCF,0xCF,0x7F));
2345 SendEditor(SCI_STYLESETFONT, SCE_HBA_COMMENTLINE,
2346 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
2348 // If there is no need to support embedded Javascript, the following code can be dropped.
2349 // Javascript will still be correctly processed but will be displayed in just the default style.
2351 SetAStyle(SCE_HJ_START, RGB(0x80,0x80,0));
2352 SetAStyle(SCE_HJ_DEFAULT, black);
2353 SetAStyle(SCE_HJ_COMMENT, darkGreen);
2354 SetAStyle(SCE_HJ_COMMENTLINE, darkGreen);
2355 SetAStyle(SCE_HJ_COMMENTDOC, darkGreen);
2356 SetAStyle(SCE_HJ_NUMBER, RGB(0,0x80,0x80));
2357 SetAStyle(SCE_HJ_WORD, black);
2358 SetAStyle(SCE_HJ_KEYWORD, darkBlue);
2359 SetAStyle(SCE_HJ_DOUBLESTRING, RGB(0x80,0,0x80));
2360 SetAStyle(SCE_HJ_SINGLESTRING, RGB(0x80,0,0x80));
2361 SetAStyle(SCE_HJ_SYMBOLS, black);
2363 SetAStyle(SCE_HJA_START, RGB(0x80,0x80,0));
2364 SetAStyle(SCE_HJA_DEFAULT, black);
2365 SetAStyle(SCE_HJA_COMMENT, darkGreen);
2366 SetAStyle(SCE_HJA_COMMENTLINE, darkGreen);
2367 SetAStyle(SCE_HJA_COMMENTDOC, darkGreen);
2368 SetAStyle(SCE_HJA_NUMBER, RGB(0,0x80,0x80));
2369 SetAStyle(SCE_HJA_WORD, black);
2370 SetAStyle(SCE_HJA_KEYWORD, darkBlue);
2371 SetAStyle(SCE_HJA_DOUBLESTRING, RGB(0x80,0,0x80));
2372 SetAStyle(SCE_HJA_SINGLESTRING, RGB(0x80,0,0x80));
2373 SetAStyle(SCE_HJA_SYMBOLS, black);
2375 SetAStyle(SCE_HPHP_DEFAULT, black);
2376 SetAStyle(SCE_HPHP_HSTRING, RGB(0x80,0,0x80));
2377 SetAStyle(SCE_HPHP_SIMPLESTRING, RGB(0x80,0,0x80));
2378 SetAStyle(SCE_HPHP_WORD, darkBlue);
2379 SetAStyle(SCE_HPHP_NUMBER, RGB(0,0x80,0x80));
2380 SetAStyle(SCE_HPHP_VARIABLE, red);
2381 SetAStyle(SCE_HPHP_HSTRING_VARIABLE, red);
2382 SetAStyle(SCE_HPHP_COMPLEX_VARIABLE, red);
2383 SetAStyle(SCE_HPHP_COMMENT, darkGreen);
2384 SetAStyle(SCE_HPHP_COMMENTLINE, darkGreen);
2385 SetAStyle(SCE_HPHP_OPERATOR, darkBlue);
2387 // Show the whole section of Javascript with off white background
2388 for (int jstyle=SCE_HJ_DEFAULT; jstyle<=SCE_HJ_SYMBOLS; jstyle++) {
2389 SendEditor(SCI_STYLESETFONT, jstyle,
2390 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
2391 SendEditor(SCI_STYLESETBACK, jstyle, offWhite);
2392 SendEditor(SCI_STYLESETEOLFILLED, jstyle, 1);
2394 SendEditor(SCI_STYLESETBACK, SCE_HJ_STRINGEOL, RGB(0xDF, 0xDF, 0x7F));
2395 SendEditor(SCI_STYLESETEOLFILLED, SCE_HJ_STRINGEOL, 1);
2397 // Show the whole section of Javascript with brown background
2398 for (int jastyle=SCE_HJA_DEFAULT; jastyle<=SCE_HJA_SYMBOLS; jastyle++) {
2399 SendEditor(SCI_STYLESETFONT, jastyle,
2400 reinterpret_cast<LPARAM>(m_TextView.StringForControl(_T("Lucida Console")).GetBuffer()));
2401 SendEditor(SCI_STYLESETBACK, jastyle, RGB(0xDF, 0xDF, 0x7F));
2402 SendEditor(SCI_STYLESETEOLFILLED, jastyle, 1);
2404 SendEditor(SCI_STYLESETBACK, SCE_HJA_STRINGEOL, RGB(0x0,0xAF,0x5F));
2405 SendEditor(SCI_STYLESETEOLFILLED, SCE_HJA_STRINGEOL, 1);
2408 else
2410 SendEditor(SCI_SETLEXER, SCLEX_CPP);
2411 SetupCppLexer();
2413 SendEditor(SCI_COLOURISE, 0, -1);
2417 void CTortoiseGitBlameView::SetupCppLexer()
2419 SetAStyle(SCE_C_DEFAULT, RGB(0, 0, 0));
2420 SetAStyle(SCE_C_COMMENT, RGB(0, 0x80, 0));
2421 SetAStyle(SCE_C_COMMENTLINE, RGB(0, 0x80, 0));
2422 SetAStyle(SCE_C_COMMENTDOC, RGB(0, 0x80, 0));
2423 SetAStyle(SCE_C_COMMENTLINEDOC, RGB(0, 0x80, 0));
2424 SetAStyle(SCE_C_COMMENTDOCKEYWORD, RGB(0, 0x80, 0));
2425 SetAStyle(SCE_C_COMMENTDOCKEYWORDERROR, RGB(0, 0x80, 0));
2426 SetAStyle(SCE_C_NUMBER, RGB(0, 0x80, 0x80));
2427 SetAStyle(SCE_C_WORD, RGB(0, 0, 0x80));
2428 SendEditor(SCE_C_WORD, 1);
2429 SetAStyle(SCE_C_STRING, RGB(0x80, 0, 0x80));
2430 SetAStyle(SCE_C_IDENTIFIER, RGB(0, 0, 0));
2431 SetAStyle(SCE_C_PREPROCESSOR, RGB(0x80, 0, 0));
2432 SetAStyle(SCE_C_OPERATOR, RGB(0x80, 0x80, 0));
2435 int CTortoiseGitBlameView::GetEncode(unsigned char *buff, int size, int *bomoffset)
2437 CFileTextLines textlines;
2438 CFileTextLines::UnicodeType type = textlines.CheckUnicodeType(buff, size);
2440 if(type == CFileTextLines::UTF8BOM)
2442 *bomoffset = 3;
2443 return CP_UTF8;
2445 if(type == CFileTextLines::UTF8)
2446 return CP_UTF8;
2448 if(type == CFileTextLines::UNICODE_LE)
2450 *bomoffset = 2;
2451 return 1200;
2454 return GetACP();
2457 void CTortoiseGitBlameView::UpdateInfo(int Encode)
2459 BYTE_VECTOR &data = GetDocument()->m_BlameData;
2460 CString one;
2461 int pos=0;
2463 BYTE_VECTOR vector;
2465 CLogDataVector * pRevs= GetLogData();
2467 this->m_CommitHash.clear();
2468 this->m_Authors.clear();
2469 this->m_ID.clear();
2470 CString line;
2472 CreateFont();
2474 SendEditor(SCI_SETREADONLY, FALSE);
2475 SendEditor(SCI_CLEARALL);
2476 SendEditor(EM_EMPTYUNDOBUFFER);
2477 SendEditor(SCI_SETSAVEPOINT);
2478 SendEditor(SCI_CANCEL);
2479 SendEditor(SCI_SETUNDOCOLLECTION, 0);
2481 SendEditor(SCI_SETCODEPAGE, SC_CP_UTF8);
2483 int current = 0;
2484 int encoding = Encode;
2485 while( pos>=0 && current >=0 && pos<data.size() )
2487 current = data.findData((const BYTE*)"\n",1,pos);
2488 //one=data.Tokenize(_T("\n"),pos);
2490 bool isbound = ( data[pos] == _T('^') );
2492 if( (data.size() - pos) >1 && data[pos] == _T('^'))
2493 pos ++;
2495 if( data[pos] == 0)
2496 continue;
2498 CGitHash hash;
2499 if(isbound)
2501 git_init();
2502 data[pos+39]=0;
2503 if(git_get_sha1((const char*)&data[pos], hash.m_hash))
2505 ::MessageBox(NULL, _T("Can't get hash"), _T("TortoiseGit"), MB_OK|MB_ICONERROR);
2509 else
2510 hash.ConvertFromStrA((char*)&data[pos]);
2513 int start=0;
2514 start=data.findData((const BYTE*)")",1,pos + 40);
2515 if(start>0)
2518 int bomoffset = 0;
2519 CStringA stra;
2520 stra.Empty();
2522 if(current>=0)
2523 data[current] = 0;
2524 else
2525 data.push_back(0);
2527 if( pos <40 && encoding==0)
2529 // first line
2530 encoding = GetEncode( &data[start+2], data.size() - start -2, &bomoffset);
2533 if(encoding == 1200)
2535 CString strw;
2536 // the first bomoffset is 2, after that it's 1 (see issue #920)
2537 if (bomoffset == 0)
2538 bomoffset = 1;
2539 int size = ((current - start -2 - bomoffset)/2);
2540 TCHAR *buffer = strw.GetBuffer(size);
2541 memcpy(buffer, &data[start + 2 + bomoffset],sizeof(TCHAR)*size);
2542 strw.ReleaseBuffer();
2544 stra = CUnicodeUtils::GetUTF8(strw);
2546 else if(encoding == CP_UTF8)
2548 stra = &data[start + 2 + bomoffset ];
2550 else
2552 CString strw;
2553 strw = CUnicodeUtils::GetUnicode(CStringA(&data[start + 2 + bomoffset ]), encoding);
2554 stra = CUnicodeUtils::GetUTF8(strw);
2558 SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)stra);
2559 SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)"\n\0\0\0");
2561 if(current>=0)
2562 data[current] = '\n';
2566 if(this->m_NoListCommit.find(hash) == m_NoListCommit.end() )
2568 this->m_NoListCommit[hash].GetCommitFromHash(hash);
2570 m_ID.push_back(-1); // m_ID is calculated lazy on demand
2571 m_Authors.push_back(m_NoListCommit[hash].GetAuthorName());
2573 m_CommitHash.push_back(hash);
2574 pos = current+1;
2577 #if 0
2578 if(m_Buffer)
2580 delete m_Buffer;
2581 m_Buffer=NULL;
2584 CFile file;
2585 file.Open(this->GetDocument()->m_TempFileName,CFile::modeRead);
2587 m_Buffer = new char[file.GetLength()+4];
2588 m_Buffer[file.GetLength()] =0;
2589 m_Buffer[file.GetLength()+1] =0;
2590 m_Buffer[file.GetLength()+2] =0;
2591 m_Buffer[file.GetLength()+3] =0;
2593 file.Read(m_Buffer, file.GetLength());
2595 int bomoffset =0;
2596 int encoding = GetEncode( (unsigned char *)m_Buffer, file.GetLength(), &bomoffset);
2598 file.Close();
2599 //SendEditor(SCI_SETCODEPAGE, encoding);
2601 //SendEditor(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)(m_Buffer + bomoffset));
2602 #endif
2603 SetupLexer(GetDocument()->m_CurrentFileName);
2605 SendEditor(SCI_SETUNDOCOLLECTION, 1);
2606 SendEditor(EM_EMPTYUNDOBUFFER);
2607 SendEditor(SCI_SETSAVEPOINT);
2608 SendEditor(SCI_GOTOPOS, 0);
2609 SendEditor(SCI_SETSCROLLWIDTHTRACKING, TRUE);
2610 SendEditor(SCI_SETREADONLY, TRUE);
2612 m_lowestrev=0;
2613 m_highestrev=this->GetLogData()->size()+m_NoListCommit.size();
2615 GetBlameWidth();
2616 CRect rect;
2617 this->GetClientRect(rect);
2618 //this->m_TextView.GetWindowRect(rect);
2619 //this->m_TextView.ScreenToClient(rect);
2620 rect.left=this->m_blamewidth;
2621 this->m_TextView.MoveWindow(rect);
2623 this->Invalidate();
2626 CGitBlameLogList * CTortoiseGitBlameView::GetLogList()
2628 return &(GetDocument()->GetMainFrame()->m_wndOutput.m_LogList);
2632 CLogDataVector * CTortoiseGitBlameView::GetLogData()
2634 return &(GetDocument()->GetMainFrame()->m_wndOutput.m_LogList.m_logEntries);
2637 void CTortoiseGitBlameView::OnSciPainted(NMHDR *,LRESULT *)
2639 this->Invalidate();
2642 void CTortoiseGitBlameView::OnLButtonDown(UINT nFlags,CPoint point)
2645 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
2646 LONG_PTR height = SendEditor(SCI_TEXTHEIGHT);
2647 line = line + (point.y/height);
2649 if (line < (LONG)m_CommitHash.size())
2651 SetSelectedLine(line);
2652 if (m_CommitHash[line] != m_SelectedHash)
2654 m_SelectedHash = m_CommitHash[line];
2656 // lazy calculate m_ID
2657 if (m_ID[line] == -1)
2659 m_ID[line] = -2; // don't do this lazy calculation again and again for unfindable hashes
2660 for(int i = 0; i<this->GetLogData()->size(); i++)
2662 if(m_SelectedHash == this->GetLogData()->at(i))
2664 m_ID[line] = this->GetLogData()->size()-i;
2665 break;
2670 if(m_ID[line]>=0)
2672 this->GetLogList()->SetItemState(this->GetLogList()->GetItemCount()-m_ID[line],
2673 LVIS_SELECTED,
2674 LVIS_SELECTED);
2675 this->GetLogList()->EnsureVisible(this->GetLogList()->GetItemCount()-m_ID[line], FALSE);
2677 else
2679 this->GetDocument()->GetMainFrame()->m_wndProperties.UpdateProperties(&m_NoListCommit[m_CommitHash[line]]);
2682 else
2684 m_SelectedHash.Empty();
2686 //::InvalidateRect( NULL, FALSE);
2687 this->Invalidate();
2688 this->m_TextView.Invalidate();
2691 else
2693 SetSelectedLine(-1);
2696 CView::OnLButtonDown(nFlags,point);
2699 void CTortoiseGitBlameView::OnSciGetBkColor(NMHDR* hdr, LRESULT* result)
2702 SCNotification *notification=reinterpret_cast<SCNotification *>(hdr);
2704 if ((m_colorage)&&(notification->line < (int)m_CommitHash.size()))
2706 if(m_CommitHash[notification->line] == this->m_SelectedHash )
2707 notification->lParam = m_selectedauthorcolor;
2708 else
2709 notification->lParam = InterColor(DWORD(m_regOldLinesColor), DWORD(m_regNewLinesColor), (m_ID[notification->line]-m_lowestrev)*100/((m_highestrev-m_lowestrev)+1));
2714 void CTortoiseGitBlameView::FocusOn(GitRev *pRev)
2716 this->GetDocument()->GetMainFrame()->m_wndProperties.UpdateProperties(pRev);
2718 this->Invalidate();
2720 if (m_SelectedHash != pRev->m_CommitHash) {
2721 m_SelectedHash = pRev->m_CommitHash;
2722 int i;
2723 for(i=0;i<m_CommitHash.size();i++)
2725 if( pRev->m_CommitHash == m_CommitHash[i] )
2726 break;
2728 this->GotoLine(i);
2729 this->m_TextView.Invalidate();
2733 void CTortoiseGitBlameView::OnMouseHover(UINT nFlags, CPoint point)
2735 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
2736 LONG_PTR height = SendEditor(SCI_TEXTHEIGHT);
2737 line = line + (point.y/height);
2739 if (line < (LONG)m_CommitHash.size())
2741 if (line != m_MouseLine)
2743 m_MouseLine = line;//m_CommitHash[line];
2744 GitRev *pRev;
2745 if(m_ID[line]<0)
2747 pRev=&this->m_NoListCommit[m_CommitHash[line]];
2750 else
2752 pRev=&this->GetLogData()->GetGitRevAt(this->GetLogList()->GetItemCount()-m_ID[line]);
2755 CString str;
2756 str.Format(_T("%s: %s\n%s: %s\n%s: %s\n%s:\n%s\n%s"), m_sRev, pRev->m_CommitHash.ToString(),
2757 m_sAuthor, pRev->GetAuthorName(),
2758 m_sDate, CLoglistUtils::FormatDateAndTime(pRev->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
2759 m_sMessage, pRev->GetSubject(),
2760 pRev->GetBody());
2762 m_ToolTip.Pop();
2763 m_ToolTip.AddTool(this, str);
2765 CRect rect;
2766 rect.left=LOCATOR_WIDTH;
2767 rect.right=this->m_blamewidth+rect.left;
2768 rect.top=point.y-height;
2769 rect.bottom=point.y+height;
2770 this->InvalidateRect(rect);
2775 void CTortoiseGitBlameView::OnMouseMove(UINT nFlags, CPoint point)
2777 TRACKMOUSEEVENT tme;
2778 tme.cbSize=sizeof(TRACKMOUSEEVENT);
2779 tme.dwFlags=TME_HOVER|TME_LEAVE;
2780 tme.hwndTrack=this->m_hWnd;
2781 tme.dwHoverTime=1;
2782 TrackMouseEvent(&tme);
2786 BOOL CTortoiseGitBlameView::PreTranslateMessage(MSG* pMsg)
2788 m_ToolTip.RelayEvent(pMsg);
2789 return CView::PreTranslateMessage(pMsg);
2792 void CTortoiseGitBlameView::OnEditFind()
2794 m_pFindDialog=new CFindReplaceDialog();
2796 m_pFindDialog->Create(TRUE,_T(""),NULL,FR_DOWN,this);
2799 void CTortoiseGitBlameView::OnEditGoto()
2801 CEditGotoDlg dlg;
2802 if(dlg.DoModal()==IDOK)
2804 this->GotoLine(dlg.m_LineNumber);
2808 LRESULT CTortoiseGitBlameView::OnFindDialogMessage(WPARAM wParam, LPARAM lParam)
2810 ASSERT(m_pFindDialog != NULL);
2812 // If the FR_DIALOGTERM flag is set,
2813 // invalidate the handle identifying the dialog box.
2814 if (m_pFindDialog->IsTerminating())
2816 m_pFindDialog = NULL;
2817 return 0;
2820 // If the FR_FINDNEXT flag is set,
2821 // call the application-defined search routine
2822 // to search for the requested string.
2823 if(m_pFindDialog->FindNext())
2825 //read data from dialog
2826 CString FindName = m_pFindDialog->GetFindString();
2827 bool bMatchCase = m_pFindDialog->MatchCase() == TRUE;
2828 bool bMatchWholeWord = m_pFindDialog->MatchWholeWord() == TRUE;
2829 bool bSearchDown = m_pFindDialog->SearchDown() == TRUE;
2831 DoSearch(FindName,m_pFindDialog->m_fr.Flags);
2832 //with given name do search
2833 // *FindWhatYouNeed(FindName, bMatchCase, bMatchWholeWord, bSearchDown);
2836 return 0;
2839 void CTortoiseGitBlameView::OnViewNext()
2841 FindNextLine(this->m_SelectedHash,false);
2843 void CTortoiseGitBlameView::OnViewPrev()
2845 FindNextLine(this->m_SelectedHash,true);
2848 void CTortoiseGitBlameView::OnViewToggleAuthor()
2850 m_bShowAuthor = ! m_bShowAuthor;
2852 theApp.WriteInt(_T("ShowAuthor"), m_bShowAuthor);
2854 CRect rect;
2855 this->GetClientRect(&rect);
2856 rect.left=GetBlameWidth();
2858 m_TextView.MoveWindow(&rect);
2861 void CTortoiseGitBlameView::OnUpdateViewToggleAuthor(CCmdUI *pCmdUI)
2863 pCmdUI->SetCheck(m_bShowAuthor);
2866 void CTortoiseGitBlameView::OnViewToggleFollowRenames()
2868 m_bFollowRenames = ! m_bFollowRenames;
2870 theApp.WriteInt(_T("FollowRenames"), m_bFollowRenames);
2872 UINT uCheck = MF_BYCOMMAND;
2873 uCheck |= m_bFollowRenames ? MF_CHECKED : MF_UNCHECKED;
2874 CheckMenuItem(GetMenu()->m_hMenu, ID_VIEW_FOLLOWRENAMES, uCheck);
2876 CTortoiseGitBlameDoc *document = (CTortoiseGitBlameDoc *) m_pDocument;
2877 if (!document->m_CurrentFileName.IsEmpty())
2879 theApp.m_pDocManager->OnFileNew();
2880 document->OnOpenDocument(document->m_CurrentFileName, document->m_Rev);
2884 void CTortoiseGitBlameView::OnUpdateViewToggleFollowRenames(CCmdUI *pCmdUI)
2886 pCmdUI->SetCheck(m_bFollowRenames);
2889 int CTortoiseGitBlameView::FindNextLine(CGitHash CommitHash,bool bUpOrDown)
2891 LONG_PTR line = SendEditor(SCI_GETFIRSTVISIBLELINE);
2892 LONG_PTR startline =line;
2893 bool findNoMatch =false;
2894 while(line>=0 && line<m_CommitHash.size())
2896 if(m_CommitHash[line]!=CommitHash)
2898 findNoMatch=true;
2901 if(m_CommitHash[line] == CommitHash && findNoMatch)
2903 if( line == startline+2 )
2905 findNoMatch=false;
2907 else
2909 if( bUpOrDown )
2911 line=FindFirstLine(CommitHash,line);
2913 SendEditor(SCI_LINESCROLL,0,line-startline-2);
2914 return line;
2917 if(bUpOrDown)
2918 line--;
2919 else
2920 line++;
2922 return -1;