renamed ITEMIS_SUBMODULE to ITEMIS_SUBMODULECONTAINER
[TortoiseGit.git] / src / TortoiseMerge / BaseView.h
blob7e5549e0ba615f043228752cf40b76e60a0525bb
1 // TortoiseMerge - a Diff/Patch program
3 // Copyright (C) 2003-2008 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #pragma once
20 #include "DiffData.h"
21 #include "SVNLineDiff.h"
22 #include "ScrollTool.h"
23 #include "Undo.h"
24 #include "LocatorBar.h"
26 /**
27 * \ingroup TortoiseMerge
29 * View class providing the basic functionality for
30 * showing diffs. Has three parent classes which inherit
31 * from this base class: CLeftView, CRightView and CBottomView.
33 class CBaseView : public CView
35 DECLARE_DYNCREATE(CBaseView)
36 friend class CLineDiffBar;
37 public:
38 CBaseView();
39 virtual ~CBaseView();
41 public:
42 /**
43 * Indicates that the underlying document has been updated. Reloads all
44 * data and redraws the view.
46 virtual void DocumentUpdated();
47 /**
48 * Returns the number of lines visible on the view.
50 int GetScreenLines();
51 /**
52 * Scrolls the view to the given line.
53 * \param nNewTopLine The new top line to scroll the view to
54 * \param bTrackScrollBar If TRUE, then the scrollbars are affected too.
56 void ScrollToLine(int nNewTopLine, BOOL bTrackScrollBar = TRUE);
57 void ScrollAllToLine(int nNewTopLine, BOOL bTrackScrollBar = TRUE);
58 void ScrollSide(int delta);
59 void GoToLine(int nNewLine, BOOL bAll = TRUE);
60 void ScrollToChar(int nNewOffsetChar, BOOL bTrackScrollBar = TRUE);
61 void UseCaret(bool bUse = true) {m_bCaretHidden = !bUse;}
62 bool HasCaret() {return !m_bCaretHidden;}
63 void SetCaretPosition(POINT pt) {m_ptCaretPos = pt ; m_nCaretGoalPos = pt.x; UpdateCaret();}
64 void EnsureCaretVisible();
65 void UpdateCaret();
66 void ClearSelection();
67 void RefreshViews();
69 void SelectLines(int nLine1, int nLine2 = -1);
70 void HiglightLines(int start, int end = -1);
71 inline BOOL IsHidden() const {return m_bIsHidden;}
72 inline void SetHidden(BOOL bHidden) {m_bIsHidden = bHidden;}
73 inline BOOL IsModified() const {return m_bModified;}
74 void SetModified(BOOL bModified = TRUE) {m_bModified = bModified;}
75 BOOL HasSelection() {return (!((m_nSelBlockEnd < 0)||(m_nSelBlockStart < 0)||(m_nSelBlockStart > m_nSelBlockEnd)));}
76 BOOL HasTextSelection() {return ((m_ptSelectionStartPos.x != m_ptSelectionEndPos.x)||(m_ptSelectionStartPos.y != m_ptSelectionEndPos.y));}
77 BOOL GetSelection(int& start, int& end) {start=m_nSelBlockStart; end=m_nSelBlockEnd; return HasSelection();}
78 void SetInlineWordDiff(bool bWord) {m_bInlineWordDiff = bWord;}
80 BOOL IsLineRemoved(int nLineIndex);
81 bool IsBlockWhitespaceOnly(int nLineIndex, bool& bIdentical);
82 bool IsLineConflicted(int nLineIndex);
84 CViewData * m_pViewData;
85 CViewData * m_pOtherViewData;
87 CString m_sWindowName; ///< The name of the view which is shown as a window title to the user
88 CString m_sFullFilePath; ///< The full path of the file shown
89 CFileTextLines::UnicodeType texttype; ///< the text encoding this view uses
90 EOL lineendings; ///< the line endings the view uses
92 BOOL m_bViewWhitespace; ///< If TRUE, then SPACE and TAB are shown as special characters
93 BOOL m_bShowInlineDiff; ///< If TRUE, diffs in lines are marked colored
94 bool m_bShowSelection; ///< If true, selection bars are shown and selected text darkened
95 int m_nTopLine; ///< The topmost text line in the view
97 static CLocatorBar * m_pwndLocator; ///< Pointer to the locator bar on the left
98 static CLineDiffBar * m_pwndLineDiffBar; ///< Pointer to the line diff bar at the bottom
99 static CMFCStatusBar * m_pwndStatusBar;///< Pointer to the status bar
100 static CMainFrame * m_pMainFrame; ///< Pointer to the mainframe
102 void GoToFirstDifference();
103 void AddEmptyLine(int nLineIndex);
104 protected:
105 virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
106 virtual void OnDraw(CDC * pDC);
107 virtual INT_PTR OnToolHitTest(CPoint point, TOOLINFO* pTI) const;
108 BOOL OnToolTipNotify(UINT id, NMHDR *pNMHDR, LRESULT *pResult);
109 afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
110 afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
111 afx_msg BOOL OnEraseBkgnd(CDC* pDC);
112 afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
113 afx_msg void OnDestroy();
114 afx_msg void OnSize(UINT nType, int cx, int cy);
115 afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
116 afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
117 afx_msg void OnKillFocus(CWnd* pNewWnd);
118 afx_msg void OnSetFocus(CWnd* pOldWnd);
119 afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
120 afx_msg void OnMergeNextdifference();
121 afx_msg void OnMergePreviousdifference();
122 afx_msg void OnMergePreviousconflict();
123 afx_msg void OnMergeNextconflict();
124 afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
125 afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
126 afx_msg void OnEditCopy();
127 afx_msg void OnMouseMove(UINT nFlags, CPoint point);
128 afx_msg void OnTimer(UINT_PTR nIDEvent);
129 afx_msg void OnMouseLeave();
130 afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
131 afx_msg void OnCaretDown();
132 afx_msg void OnCaretLeft();
133 afx_msg void OnCaretRight();
134 afx_msg void OnCaretUp();
135 afx_msg void OnCaretWordleft();
136 afx_msg void OnCaretWordright();
137 afx_msg void OnEditCut();
138 afx_msg void OnEditPaste();
140 DECLARE_MESSAGE_MAP()
142 protected:
143 void DrawHeader(CDC *pdc, const CRect &rect);
144 void DrawMargin(CDC *pdc, const CRect &rect, int nLineIndex);
145 void DrawSingleLine(CDC *pDC, const CRect &rc, int nLineIndex);
146 bool DrawInlineDiff(CDC *pDC, const CRect &rc, int nLineIndex, const CString &line, CPoint &origin);
148 * Draws the horizontal lines around current diff block or selection block.
150 void DrawBlockLine(CDC *pDC, const CRect &rc, int nLineIndex);
152 * Draws the line ending 'char'.
154 void DrawLineEnding(CDC *pDC, const CRect &rc, int nLineIndex, const CPoint& origin);
155 void ExpandChars(LPCTSTR pszChars, int nOffset, int nCount, CString &line);
157 void RecalcVertScrollBar(BOOL bPositionOnly = FALSE);
158 void RecalcAllVertScrollBars(BOOL bPositionOnly = FALSE);
159 void RecalcHorzScrollBar(BOOL bPositionOnly = FALSE);
160 void RecalcAllHorzScrollBars(BOOL bPositionOnly = FALSE);
162 void OnDoMouseWheel(UINT nFlags, short zDelta, CPoint pt);
163 void OnDoHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar, CBaseView * master);
164 void OnDoVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar, CBaseView * master);
166 void SetupSelection(int start, int end);
167 void ShowDiffLines(int nLine);
169 int GetTabSize() const {return m_nTabSize;}
171 int GetLineActualLength(int index) const;
172 int GetLineCount() const;
173 void CalcLineCharDim();
174 int GetLineHeight();
175 int GetCharWidth();
176 int GetMaxLineLength();
177 int GetLineLength(int index) const;
178 int GetScreenChars();
179 int GetAllMinScreenChars() const;
180 int GetAllMaxLineLength() const;
181 int GetAllLineCount() const;
182 int GetAllMinScreenLines() const;
183 LPCTSTR GetLineChars(int index) const;
184 int GetLineNumber(int index) const;
185 CFont * GetFont(BOOL bItalic = FALSE, BOOL bBold = FALSE, BOOL bStrikeOut = FALSE);
186 int GetLineFromPoint(CPoint point);
187 int GetMarginWidth();
188 COLORREF IntenseColor(long scale, COLORREF col);
189 COLORREF InlineDiffColor(int nLineIndex);
190 void CheckOtherView();
191 static CString GetWhitespaceBlock(CViewData *viewData, int nLineIndex);
193 /// Returns true if selection should be kept
194 virtual bool OnContextMenu(CPoint point, int nLine, DiffStates state);
196 * Updates the status bar pane. Call this if the document changed.
198 void UpdateStatusBar();
200 void UseTheirAndYourBlock(viewstate &rightstate, viewstate &bottomstate, viewstate &leftstate);
201 void UseYourAndTheirBlock(viewstate &rightstate, viewstate &bottomstate, viewstate &leftstate);
202 void UseBothLeftFirst(viewstate &rightstate, viewstate &leftstate);
203 void UseBothRightFirst(viewstate &rightstate, viewstate &leftstate);
205 bool IsLeftViewGood() const {return ((m_pwndLeft)&&(m_pwndLeft->IsWindowVisible()));}
206 bool IsRightViewGood() const {return ((m_pwndRight)&&(m_pwndRight->IsWindowVisible()));}
207 bool IsBottomViewGood() const {return ((m_pwndBottom)&&(m_pwndBottom->IsWindowVisible()));}
209 int CalculateActualOffset(int nLineIndex, int nCharIndex) const;
210 int CalculateCharIndex(int nLineIndex, int nActualOffset) const;
211 POINT TextToClient(const POINT& point);
212 void DrawText(CDC * pDC, const CRect &rc, LPCTSTR text, int textlength, int nLineIndex, POINT coords, bool bModified, bool bInlineDiff);
213 void ClearCurrentSelection();
214 void AdjustSelection();
215 void SelectNextBlock(int nDirection, bool bConflict, bool bSkipEndOfCurrentBlock = true);
217 void RemoveLine(int nLineIndex);
218 void RemoveSelectedText();
219 void PasteText();
220 void AddUndoLine(int nLine, bool bAddEmptyLine = false);
222 bool MoveCaretLeft();
223 bool MoveCaretRight();
224 void UpdateGoalPos();
226 bool IsWordSeparator(wchar_t ch) const;
227 bool IsCaretAtWordBoundary() const;
229 protected:
230 COLORREF m_InlineRemovedBk;
231 COLORREF m_InlineAddedBk;
232 COLORREF m_ModifiedBk;
233 COLORREF m_WhiteSpaceFg;
234 UINT m_nStatusBarID; ///< The ID of the status bar pane used by this view. Must be set by the parent class.
236 SVNLineDiff m_svnlinediff;
237 BOOL m_bOtherDiffChecked;
238 BOOL m_bModified;
239 BOOL m_bFocused;
240 BOOL m_bViewLinenumbers;
241 BOOL m_bIsHidden;
242 BOOL m_bMouseWithin;
243 BOOL m_bIconLFs;
244 int m_nLineHeight;
245 int m_nCharWidth;
246 int m_nMaxLineLength;
247 int m_nScreenLines;
248 int m_nScreenChars;
249 int m_nOffsetChar;
250 int m_nTabSize;
251 int m_nDigits;
252 bool m_bInlineWordDiff;
254 int m_nSelBlockStart;
255 int m_nSelBlockEnd;
257 int m_nMouseLine;
259 bool m_bCaretHidden;
260 POINT m_ptCaretPos;
261 int m_nCaretGoalPos;
262 POINT m_ptSelectionStartPos;
263 POINT m_ptSelectionEndPos;
264 POINT m_ptSelectionOrigin;
267 HICON m_hAddedIcon;
268 HICON m_hRemovedIcon;
269 HICON m_hConflictedIcon;
270 HICON m_hConflictedIgnoredIcon;
271 HICON m_hWhitespaceBlockIcon;
272 HICON m_hEqualIcon;
273 HICON m_hEditedIcon;
275 HICON m_hLineEndingCR;
276 HICON m_hLineEndingCRLF;
277 HICON m_hLineEndingLF;
279 LOGFONT m_lfBaseFont;
280 CFont * m_apFonts[8];
281 CString m_sConflictedText;
282 CString m_sNoLineNr;
284 CBitmap * m_pCacheBitmap;
285 CDC * m_pDC;
286 CScrollTool m_ScrollTool;
287 CString m_sWordSeparators;
289 char m_szTip[MAX_PATH*2+1];
290 wchar_t m_wszTip[MAX_PATH*2+1];
291 // These three pointers lead to the three parent
292 // classes CLeftView, CRightView and CBottomView
293 // and are used for the communication between
294 // the views (e.g. synchronized scrolling, ...)
295 // To find out which parent class this object
296 // is made of just compare e.g. (m_pwndLeft==this).
297 static CBaseView * m_pwndLeft; ///< Pointer to the left view. Must be set by the CLeftView parent class.
298 static CBaseView * m_pwndRight; ///< Pointer to the right view. Must be set by the CRightView parent class.
299 static CBaseView * m_pwndBottom; ///< Pointer to the bottom view. Must be set by the CBottomView parent class.