Adjust for Scintilla 4.0.3 and fix warnings
[TortoiseGit.git] / src / TortoiseGitBlame / TortoiseGitBlameView.h
blob16d5f40c9c083410cfffa674cbf963d0faa85428
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013, 2015-2018 - TortoiseGit
4 // Copyright (C) 2003-2008, 2014 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 // TortoiseGitBlameView.h : interface of the CTortoiseGitBlameView class
26 #pragma once
28 #include "Scintilla.h"
29 #include "SciLexer.h"
30 #include "registry.h"
31 #include "SciEdit.h"
33 #include "GitBlameLogList.h"
34 #include "TortoiseGitBlameData.h"
35 #include "Tooltip.h"
37 const COLORREF black = RGB(0,0,0);
38 const COLORREF white = RGB(0xff,0xff,0xff);
39 const COLORREF red = RGB(0xFF, 0, 0);
40 const COLORREF offWhite = RGB(0xFF, 0xFB, 0xF0);
41 const COLORREF darkGreen = RGB(0, 0x80, 0);
42 const COLORREF darkBlue = RGB(0, 0, 0x80);
43 const COLORREF lightBlue = RGB(0xA6, 0xCA, 0xF0);
44 const int blockSize = 128 * 1024;
46 #define BLAMESPACE 5
47 #define HEADER_HEIGHT 18
48 #define LOCATOR_WIDTH 10
50 #define MAX_LOG_LENGTH 2000
53 #ifndef GET_X_LPARAM
54 #define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
55 #endif
56 #ifndef GET_Y_LPARAM
57 #define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
58 #endif
60 class CSciEditBlame: public CSciEdit
62 DECLARE_DYNAMIC(CSciEditBlame)
63 public:
64 afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
66 switch (nChar)
68 case (VK_ESCAPE):
70 if ((Call(SCI_AUTOCACTIVE)==0)&&(Call(SCI_CALLTIPACTIVE)==0))
72 ::SendMessage(::AfxGetApp()->GetMainWnd()->m_hWnd, WM_CLOSE, 0, 0);
73 return;
76 break;
78 CWnd::OnKeyDown(nChar, nRepCnt, nFlags);
82 class CTortoiseGitBlameView : public CView
84 enum
86 // needs to start with 1, since 0 is the return value if *nothing* is clicked on in the context menu
87 ID_BLAMEPREVIOUS = 1,
88 ID_COMPAREWITHPREVIOUS,
89 ID_SHOWLOG,
90 ID_COPYHASHTOCLIPBOARD,
91 ID_COPYLOGTOCLIPBOARD
94 protected: // create from serialization only
95 CTortoiseGitBlameView();
96 DECLARE_DYNCREATE(CTortoiseGitBlameView)
98 // Attributes
99 public:
100 CTortoiseGitBlameDoc* GetDocument() const;
101 int GetEncode(unsigned char * buffer, int size, int *bomoffset);
102 // Operations
103 public:
105 // Overrides
106 public:
107 afx_msg void OnDraw(CDC* pDC); // overridden to draw this view
108 afx_msg BOOL OnEraseBkgnd(CDC* pDC);
109 virtual BOOL PreCreateWindow(CREATESTRUCT& cs) override;
110 protected:
111 afx_msg BOOL OnPreparePrinting(CPrintInfo* pInfo);
112 afx_msg void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
113 afx_msg void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
114 virtual ULONG GetGestureStatus(CPoint ptTouch) override;
116 // Implementation
117 public:
118 virtual ~CTortoiseGitBlameView();
119 #ifdef _DEBUG
120 virtual void AssertValid() const override;
121 virtual void Dump(CDumpContext& dc) const override;
122 #endif
124 protected:
126 // Generated message map functions
127 protected:
128 virtual BOOL PreTranslateMessage(MSG* pMsg) override;
129 afx_msg void OnSysColorChange();
130 afx_msg void OnChangeEncode(UINT nID);
131 afx_msg void OnEditFind();
132 afx_msg void OnEditGoto();
133 afx_msg void OnFindNext();
134 afx_msg void OnFindPrev();
135 afx_msg void OnFilePrintPreview();
136 afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
137 afx_msg int OnCreate(LPCREATESTRUCT lpcs);
138 afx_msg void OnSize(UINT nType, int cx, int cy);
139 afx_msg void OnSciPainted(NMHDR*, LRESULT*);
140 afx_msg void OnLButtonDown(UINT nFlags,CPoint point);
141 afx_msg void OnRButtonDown(UINT nFlags,CPoint point){OnLButtonDown(nFlags,point);CView::OnRButtonDown(nFlags,point);};
142 afx_msg void OnSciGetBkColor(NMHDR*, LRESULT*);
143 afx_msg void OnMouseHover(UINT nFlags, CPoint point);
144 afx_msg void OnMouseMove(UINT nFlags, CPoint point);
145 afx_msg void OnMouseLeave();
146 afx_msg LRESULT OnFindDialogMessage(WPARAM wParam, LPARAM lParam);
147 afx_msg void OnViewNext();
148 afx_msg void OnViewPrev();
149 afx_msg void OnViewToggleAuthor();
150 afx_msg void OnUpdateViewToggleAuthor(CCmdUI *pCmdUI);
151 afx_msg void OnViewToggleDate();
152 afx_msg void OnUpdateViewToggleDate(CCmdUI *pCmdUI);
153 afx_msg void OnViewToggleShowFilename();
154 afx_msg void OnUpdateViewToggleShowFilename(CCmdUI *pCmdUI);
155 afx_msg void OnViewToggleShowOriginalLineNumber();
156 afx_msg void OnUpdateViewToggleShowOriginalLineNumber(CCmdUI *pCmdUI);
157 afx_msg void OnViewDetectMovedOrCopiedLinesToggleDisabled();
158 afx_msg void OnUpdateViewDetectMovedOrCopiedLinesToggleDisabled(CCmdUI *pCmdUI);
159 afx_msg void OnViewDetectMovedOrCopiedLinesToggleWithinFile();
160 afx_msg void OnUpdateViewDetectMovedOrCopiedLinesToggleWithinFile(CCmdUI *pCmdUI);
161 afx_msg void OnViewDetectMovedOrCopiedLinesToggleFromModifiedFiles();
162 afx_msg void OnUpdateViewDetectMovedOrCopiedLinesToggleFromModifiedFiles(CCmdUI *pCmdUI);
163 afx_msg void OnViewDetectMovedOrCopiedLinesToggleFromExistingFilesAtFileCreation();
164 afx_msg void OnUpdateViewDetectMovedOrCopiedLinesToggleFromExistingFilesAtFileCreation(CCmdUI *pCmdUI);
165 afx_msg void OnViewDetectMovedOrCopiedLinesToggleFromExistingFiles();
166 afx_msg void OnUpdateViewDetectMovedOrCopiedLinesToggleFromExistingFiles(CCmdUI *pCmdUI);
167 afx_msg void OnViewToggleIgnoreWhitespace();
168 afx_msg void OnUpdateViewToggleIgnoreWhitespace(CCmdUI *pCmdUI);
169 afx_msg void OnViewToggleShowCompleteLog();
170 afx_msg void OnUpdateViewToggleShowCompleteLog(CCmdUI *pCmdUI);
171 afx_msg void OnViewToggleOnlyFirstParent();
172 afx_msg void OnUpdateViewToggleOnlyFirstParent(CCmdUI* pCmdUI);
173 afx_msg void OnViewToggleFollowRenames();
174 afx_msg void OnUpdateViewToggleFollowRenames(CCmdUI *pCmdUI);
175 afx_msg void OnViewToggleColorByAge();
176 afx_msg void OnUpdateViewToggleColorByAge(CCmdUI *pCmdUI);
177 afx_msg void OnViewToggleLexer();
178 afx_msg void OnUpdateViewToggleLexer(CCmdUI *pCmdUI);
179 afx_msg void OnViewWrapLongLines();
180 afx_msg void OnUpdateViewWrapLongLines(CCmdUI* pCmdUI);
181 afx_msg void OnUpdateViewCopyToClipboard(CCmdUI *pCmdUI);
182 void OnViewDetectMovedOrCopiedLines(DWORD dwDetectMovedOrCopiedLines);
183 void ContextMenuAction(int cmd, GitRev* pRev, GIT_REV_LIST& parentHash, const std::vector<CString>& parentFilename, int line);
184 void ReloadDocument();
186 DECLARE_MESSAGE_MAP()
188 static UINT m_FindDialogMessage;
189 public:
190 void ParseBlame();
191 void MapLineToLogIndex();
192 void UpdateInfo(int encode = 0);
193 CString ResolveCommitFile(int line);
194 CString ResolveCommitFile(const CString& path);
195 void FocusOn(GitRevLoglist* pRev);
197 CSciEditBlame m_TextView;
198 CToolTips m_ToolTip;
200 HINSTANCE hInstance;
201 HINSTANCE hResource;
202 HWND currentDialog;
203 HWND wMain;
204 HWND wBlame;
205 HWND wHeader;
206 HWND wLocator;
207 HWND hwndTT;
209 BOOL bIgnoreEOL;
210 BOOL bIgnoreSpaces;
211 BOOL bIgnoreAllSpaces;
213 BOOL m_bShowAuthor;
214 BOOL m_bShowDate;
215 BOOL m_bShowFilename;
216 BOOL m_bShowOriginalLineNumber;
217 DWORD m_dwDetectMovedOrCopiedLines;
218 BOOL m_bIgnoreWhitespace;
219 BOOL m_bShowCompleteLog;
220 BOOL m_bOnlyFirstParent;
221 BOOL m_bFollowRenames;
222 BOOL m_bBlameOutputContainsOtherFilenames;
224 LRESULT SendEditor(UINT Msg, WPARAM wParam=0, LPARAM lParam=0);
226 void SetAStyle(int style, COLORREF fore, COLORREF back = ::GetSysColor(COLOR_WINDOW), int size = -1, const char* face = nullptr);
228 void InitialiseEditor();
229 LONG GetBlameWidth();
230 void DrawBlame(HDC hDC);
231 void DrawLocatorBar(HDC hDC);
232 void CopyToClipboard();
233 bool DoSearch(CTortoiseGitBlameData::SearchDirection direction);
234 bool GotoLine(int line);
235 bool ScrollToLine(long line);
237 void SetSelectedLine(int line) { m_SelectedLine = line;};
239 int m_MouseLine;
240 CGitHash m_SelectedHash;
241 CGitHash m_selecteddate;
242 bool m_colorage;
243 bool m_bLexer;
244 bool m_bWrapLongLines;
246 CTortoiseGitBlameData m_data;
247 std::vector<int> m_lineToLogIndex;
249 CLogDataVector * GetLogData();
251 BOOL m_bShowLine;
253 protected:
254 void CreateFont();
255 void SetupLexer(CString filename);
256 void SetupCppLexer();
257 int GetLineUnderCursor(CPoint point);
258 COLORREF GetLineColor(size_t line);
259 COLORREF InterColor(COLORREF c1, COLORREF c2, int Slider);
260 CFont m_font;
261 CFont m_italicfont;
262 LONG m_blamewidth;
263 LONG m_revwidth;
264 LONG m_datewidth;
265 LONG m_authorwidth;
266 LONG m_filenameWidth;
267 LONG m_originalLineNumberWidth;
268 LONG m_linewidth;
269 int m_SelectedLine; ///< zero-based
271 COLORREF m_mouserevcolor;
272 COLORREF m_mouseauthorcolor;
273 COLORREF m_selectedrevcolor;
274 COLORREF m_selectedauthorcolor;
275 COLORREF m_windowcolor;
276 COLORREF m_textcolor;
277 COLORREF m_texthighlightcolor;
279 CRegStdDWORD m_regOldLinesColor;
280 CRegStdDWORD m_regNewLinesColor;
282 CGitBlameLogList * GetLogList();
284 CFindReplaceDialog *m_pFindDialog;
286 #ifdef USE_TEMPFILENAME
287 char *m_Buffer;
288 #endif
290 DWORD m_DateFormat; // DATE_SHORTDATE or DATE_LONGDATE
291 bool m_bRelativeTimes; // Show relative times
293 CString m_sRev;
294 CString m_sFileName;
295 CString m_sAuthor;
296 CString m_sDate;
297 CString m_sMessage;
299 CString m_sFindText;
300 bool m_bMatchCase;
303 #ifndef _DEBUG // debug version in TortoiseGitBlameView.cpp
304 inline CTortoiseGitBlameDoc* CTortoiseGitBlameView::GetDocument() const
305 { return reinterpret_cast<CTortoiseGitBlameDoc*>(m_pDocument); }
306 #endif