Add encode support for blame
[TortoiseGit.git] / src / TortoiseGitBlame / TortoiseGitBlameView.h
blob1959579e3731285ec47ea7737e893a8b06132782
2 // TortoiseGitBlameView.h : interface of the CTortoiseGitBlameView class
3 //
6 #pragma once
8 #include "Scintilla.h"
9 #include "SciLexer.h"
10 #include "registry.h"
11 #include "SciEdit.h"
13 #include "GitBlameLogList.h"
14 #include "Balloon.h"
16 const COLORREF black = RGB(0,0,0);
17 const COLORREF white = RGB(0xff,0xff,0xff);
18 const COLORREF red = RGB(0xFF, 0, 0);
19 const COLORREF offWhite = RGB(0xFF, 0xFB, 0xF0);
20 const COLORREF darkGreen = RGB(0, 0x80, 0);
21 const COLORREF darkBlue = RGB(0, 0, 0x80);
22 const COLORREF lightBlue = RGB(0xA6, 0xCA, 0xF0);
23 const int blockSize = 128 * 1024;
25 #define BLAMESPACE 5
26 #define HEADER_HEIGHT 18
27 #define LOCATOR_WIDTH 10
29 #define MAX_LOG_LENGTH 2000
32 #ifndef GET_X_LPARAM
33 #define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
34 #endif
35 #ifndef GET_Y_LPARAM
36 #define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
37 #endif
39 class CSciEditBlame: public CSciEdit
41 DECLARE_DYNAMIC(CSciEditBlame)
42 public:
43 afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
45 switch (nChar)
47 case (VK_ESCAPE):
49 if ((Call(SCI_AUTOCACTIVE)==0)&&(Call(SCI_CALLTIPACTIVE)==0))
51 ::SendMessage(::AfxGetApp()->GetMainWnd()->m_hWnd, WM_CLOSE, 0, 0);
52 return;
55 break;
57 CWnd::OnKeyDown(nChar, nRepCnt, nFlags);
61 class CTortoiseGitBlameView : public CView
63 protected: // create from serialization only
64 CTortoiseGitBlameView();
65 DECLARE_DYNCREATE(CTortoiseGitBlameView)
67 // Attributes
68 public:
69 CTortoiseGitBlameDoc* GetDocument() const;
70 int GetEncode(unsigned char * buffer, int size, int *bomoffset);
71 // Operations
72 public:
74 // Overrides
75 public:
76 virtual void OnDraw(CDC* pDC); // overridden to draw this view
77 virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
78 protected:
79 virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
80 virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
81 virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
83 // Implementation
84 public:
85 virtual ~CTortoiseGitBlameView();
86 #ifdef _DEBUG
87 virtual void AssertValid() const;
88 virtual void Dump(CDumpContext& dc) const;
89 #endif
91 protected:
93 // Generated message map functions
94 protected:
95 BOOL PreTranslateMessage(MSG* pMsg);
96 afx_msg void OnChangeEncode(UINT nID);
97 afx_msg void OnEditFind();
98 afx_msg void OnEditGoto();
99 afx_msg void OnFilePrintPreview();
100 afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
101 afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
102 afx_msg int OnCreate(LPCREATESTRUCT lpcs);
103 afx_msg void OnSize(UINT nType, int cx, int cy);
104 afx_msg void OnSciPainted(NMHDR*, LRESULT*);
105 afx_msg void OnLButtonDown(UINT nFlags,CPoint point);
106 afx_msg void OnRButtonDown(UINT nFlags,CPoint point){OnLButtonDown(nFlags,point);CView::OnRButtonDown(nFlags,point);};
107 afx_msg void OnSciGetBkColor(NMHDR*, LRESULT*);
108 afx_msg void OnMouseHover(UINT nFlags, CPoint point);
109 afx_msg void OnMouseMove(UINT nFlags, CPoint point);
110 afx_msg LRESULT OnFindDialogMessage(WPARAM wParam, LPARAM lParam);
111 afx_msg void OnViewNext();
112 afx_msg void OnViewPrev();
114 int FindNextLine(CGitHash commithash, bool bUpOrDown=false);
115 int FindFirstLine(CGitHash commithash, int line)
117 while(line>=0)
119 if( m_CommitHash[line] != commithash )
121 return line++;
123 line--;
125 return line;
128 DECLARE_MESSAGE_MAP()
130 static UINT m_FindDialogMessage;
131 public:
133 void UpdateInfo();
134 void FocusOn(GitRev *pRev);
136 CSciEditBlame m_TextView;
137 CBalloon m_ToolTip;
139 HINSTANCE hInstance;
140 HINSTANCE hResource;
141 HWND currentDialog;
142 HWND wMain;
143 HWND m_wEditor;
144 HWND wBlame;
145 HWND wHeader;
146 HWND wLocator;
147 HWND hwndTT;
149 BOOL bIgnoreEOL;
150 BOOL bIgnoreSpaces;
151 BOOL bIgnoreAllSpaces;
153 BOOL m_bShowAuthor;
154 BOOL m_bShowDate;
157 LRESULT SendEditor(UINT Msg, WPARAM wParam=0, LPARAM lParam=0);
159 void GetRange(int start, int end, char *text);
161 void SetTitle();
162 BOOL OpenFile(const char *fileName);
163 BOOL OpenLogFile(const char *fileName);
165 void Command(int id);
166 void Notify(SCNotification *notification);
168 void SetAStyle(int style, COLORREF fore, COLORREF back=::GetSysColor(COLOR_WINDOW), int size=-1, CString *face=0);
170 void InitialiseEditor();
171 void InitSize();
172 LONG GetBlameWidth();
173 void DrawBlame(HDC hDC);
174 void DrawHeader(HDC hDC);
175 void DrawLocatorBar(HDC hDC);
176 void StartSearch();
177 void CopySelectedLogToClipboard();
178 void BlamePreviousRevision();
179 void DiffPreviousRevision();
180 void ShowLog();
181 bool DoSearch(CString what, DWORD flags);
182 bool GotoLine(long line);
183 bool ScrollToLine(long line);
184 void GotoLineDlg();
185 static INT_PTR CALLBACK GotoDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
187 void SetSelectedLine(LONG line) { m_SelectedLine=line;};
189 LONG m_mouserev;
190 LONG m_MouseLine;
191 LONG m_selectedrev;
192 LONG m_selectedorigrev;
193 CGitHash m_SelectedHash;
194 CGitHash m_selecteddate;
195 static long m_gotoline;
196 long m_lowestrev;
197 long m_highestrev;
198 bool m_colorage;
200 // std::vector<bool> m_Mergelines;
201 std::vector<LONG> m_ID;
202 std::vector<LONG> m_LineNum;
203 // std::vector<LONG> m_Origrevs;
204 std::vector<CString> m_Dates;
205 std::vector<CString> m_Authors;
206 std::vector<CGitHash> m_CommitHash;
208 std::map<CString,GitRev> m_NoListCommit;
210 // std::vector<CString> m_Paths;
211 // std::map<LONG, CString> logmessages;
212 char m_szTip[MAX_LOG_LENGTH*2+6];
213 wchar_t m_wszTip[MAX_LOG_LENGTH*2+6];
214 void StringExpand(LPSTR str);
215 void StringExpand(LPWSTR str);
216 BOOL ttVisible;
218 CLogDataVector * GetLogData();
220 BOOL m_bShowLine;
222 protected:
223 void CreateFont();
224 void SetupLexer(CString filename);
225 void SetupCppLexer();
226 COLORREF InterColor(COLORREF c1, COLORREF c2, int Slider);
227 CString GetAppDirectory();
228 std::vector<COLORREF> colors;
229 HFONT m_font;
230 HFONT m_italicfont;
231 LONG m_blamewidth;
232 LONG m_revwidth;
233 LONG m_datewidth;
234 LONG m_authorwidth;
235 LONG m_pathwidth;
236 LONG m_linewidth;
237 LONG m_SelectedLine; ///< zero-based
239 COLORREF m_mouserevcolor;
240 COLORREF m_mouseauthorcolor;
241 COLORREF m_selectedrevcolor;
242 COLORREF m_selectedauthorcolor;
243 COLORREF m_windowcolor;
244 COLORREF m_textcolor;
245 COLORREF m_texthighlightcolor;
247 LRESULT m_directFunction;
248 LRESULT m_directPointer;
249 FINDREPLACE fr;
250 TCHAR szFindWhat[80];
252 CRegStdWORD m_regOldLinesColor;
253 CRegStdWORD m_regNewLinesColor;
255 CGitBlameLogList * GetLogList();
257 CFindReplaceDialog *m_pFindDialog;
259 char *m_Buffer;
261 DWORD m_DateFormat; // DATE_SHORTDATE or DATE_LONGDATE
262 virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);
265 #ifndef _DEBUG // debug version in TortoiseGitBlameView.cpp
266 inline CTortoiseGitBlameDoc* CTortoiseGitBlameView::GetDocument() const
267 { return reinterpret_cast<CTortoiseGitBlameDoc*>(m_pDocument); }
268 #endif