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.
21 //#include "SVNLineDiff.h"
22 #include "ScrollTool.h"
24 #include "LocatorBar.h"
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
;
43 * Indicates that the underlying document has been updated. Reloads all
44 * data and redraws the view.
46 virtual void DocumentUpdated();
48 * Returns the number of lines visible on the view.
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();
66 void ClearSelection();
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
);
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 OnMouseLeave();
129 afx_msg
void OnChar(UINT nChar
, UINT nRepCnt
, UINT nFlags
);
130 afx_msg
void OnCaretDown();
131 afx_msg
void OnCaretLeft();
132 afx_msg
void OnCaretRight();
133 afx_msg
void OnCaretUp();
134 afx_msg
void OnCaretWordleft();
135 afx_msg
void OnCaretWordright();
136 afx_msg
void OnEditCut();
137 afx_msg
void OnEditPaste();
139 DECLARE_MESSAGE_MAP()
142 void DrawHeader(CDC
*pdc
, const CRect
&rect
);
143 void DrawMargin(CDC
*pdc
, const CRect
&rect
, int nLineIndex
);
144 void DrawSingleLine(CDC
*pDC
, const CRect
&rc
, int nLineIndex
);
145 bool DrawInlineDiff(CDC
*pDC
, const CRect
&rc
, int nLineIndex
, const CString
&line
, CPoint
&origin
);
147 * Draws the horizontal lines around current diff block or selection block.
149 void DrawBlockLine(CDC
*pDC
, const CRect
&rc
, int nLineIndex
);
151 * Draws the line ending 'char'.
153 void DrawLineEnding(CDC
*pDC
, const CRect
&rc
, int nLineIndex
, const CPoint
& origin
);
154 void ExpandChars(LPCTSTR pszChars
, int nOffset
, int nCount
, CString
&line
);
156 void RecalcVertScrollBar(BOOL bPositionOnly
= FALSE
);
157 void RecalcAllVertScrollBars(BOOL bPositionOnly
= FALSE
);
158 void RecalcHorzScrollBar(BOOL bPositionOnly
= FALSE
);
159 void RecalcAllHorzScrollBars(BOOL bPositionOnly
= FALSE
);
161 void OnDoMouseWheel(UINT nFlags
, short zDelta
, CPoint pt
);
162 void OnDoHScroll(UINT nSBCode
, UINT nPos
, CScrollBar
* pScrollBar
, CBaseView
* master
);
163 void OnDoVScroll(UINT nSBCode
, UINT nPos
, CScrollBar
* pScrollBar
, CBaseView
* master
);
165 void SetupSelection(int start
, int end
);
166 void ShowDiffLines(int nLine
);
168 int GetTabSize() const {return m_nTabSize
;}
170 int GetLineActualLength(int index
) const;
171 int GetLineCount() const;
172 void CalcLineCharDim();
175 int GetMaxLineLength();
176 int GetLineLength(int index
) const;
177 int GetScreenChars();
178 int GetAllMinScreenChars() const;
179 int GetAllMaxLineLength() const;
180 int GetAllLineCount() const;
181 int GetAllMinScreenLines() const;
182 LPCTSTR
GetLineChars(int index
) const;
183 int GetLineNumber(int index
) const;
184 CFont
* GetFont(BOOL bItalic
= FALSE
, BOOL bBold
= FALSE
, BOOL bStrikeOut
= FALSE
);
185 int GetLineFromPoint(CPoint point
);
186 int GetMarginWidth();
187 COLORREF
IntenseColor(long scale
, COLORREF col
);
188 COLORREF
InlineDiffColor(int nLineIndex
);
189 void CheckOtherView();
190 static CString
GetWhitespaceBlock(CViewData
*viewData
, int nLineIndex
);
192 /// Returns true if selection should be kept
193 virtual bool OnContextMenu(CPoint point
, int nLine
, DiffStates state
);
195 * Updates the status bar pane. Call this if the document changed.
197 void UpdateStatusBar();
199 void UseTheirAndYourBlock(viewstate
&rightstate
, viewstate
&bottomstate
, viewstate
&leftstate
);
200 void UseYourAndTheirBlock(viewstate
&rightstate
, viewstate
&bottomstate
, viewstate
&leftstate
);
201 void UseBothLeftFirst(viewstate
&rightstate
, viewstate
&leftstate
);
202 void UseBothRightFirst(viewstate
&rightstate
, viewstate
&leftstate
);
204 bool IsLeftViewGood() const {return ((m_pwndLeft
)&&(m_pwndLeft
->IsWindowVisible()));}
205 bool IsRightViewGood() const {return ((m_pwndRight
)&&(m_pwndRight
->IsWindowVisible()));}
206 bool IsBottomViewGood() const {return ((m_pwndBottom
)&&(m_pwndBottom
->IsWindowVisible()));}
208 int CalculateActualOffset(int nLineIndex
, int nCharIndex
) const;
209 int CalculateCharIndex(int nLineIndex
, int nActualOffset
) const;
210 POINT
TextToClient(const POINT
& point
);
211 void DrawText(CDC
* pDC
, const CRect
&rc
, LPCTSTR text
, int textlength
, int nLineIndex
, POINT coords
, bool bModified
, bool bInlineDiff
);
212 void ClearCurrentSelection();
213 void AdjustSelection();
214 void SelectNextBlock(int nDirection
, bool bConflict
);
216 void RemoveLine(int nLineIndex
);
217 void RemoveSelectedText();
219 void AddUndoLine(int nLine
, bool bAddEmptyLine
= false);
221 bool MoveCaretLeft();
222 bool MoveCaretRight();
223 void UpdateGoalPos();
225 bool IsWordSeparator(wchar_t ch
) const;
226 bool IsCaretAtWordBoundary() const;
229 COLORREF m_InlineRemovedBk
;
230 COLORREF m_InlineAddedBk
;
231 COLORREF m_ModifiedBk
;
232 COLORREF m_WhiteSpaceFg
;
233 UINT m_nStatusBarID
; ///< The ID of the status bar pane used by this view. Must be set by the parent class.
235 // SVNLineDiff m_svnlinediff;
236 BOOL m_bOtherDiffChecked
;
239 BOOL m_bViewLinenumbers
;
245 int m_nMaxLineLength
;
251 bool m_bInlineWordDiff
;
253 int m_nSelBlockStart
;
261 POINT m_ptSelectionStartPos
;
262 POINT m_ptSelectionEndPos
;
263 POINT m_ptSelectionOrigin
;
267 HICON m_hRemovedIcon
;
268 HICON m_hConflictedIcon
;
269 HICON m_hConflictedIgnoredIcon
;
270 HICON m_hWhitespaceBlockIcon
;
274 HICON m_hLineEndingCR
;
275 HICON m_hLineEndingCRLF
;
276 HICON m_hLineEndingLF
;
278 LOGFONT m_lfBaseFont
;
279 CFont
* m_apFonts
[8];
280 CString m_sConflictedText
;
283 CBitmap
* m_pCacheBitmap
;
285 CScrollTool m_ScrollTool
;
286 CString m_sWordSeparators
;
288 char m_szTip
[MAX_PATH
*2+1];
289 wchar_t m_wszTip
[MAX_PATH
*2+1];
290 // These three pointers lead to the three parent
291 // classes CLeftView, CRightView and CBottomView
292 // and are used for the communication between
293 // the views (e.g. synchronized scrolling, ...)
294 // To find out which parent class this object
295 // is made of just compare e.g. (m_pwndLeft==this).
296 static CBaseView
* m_pwndLeft
; ///< Pointer to the left view. Must be set by the CLeftView parent class.
297 static CBaseView
* m_pwndRight
; ///< Pointer to the right view. Must be set by the CRightView parent class.
298 static CBaseView
* m_pwndBottom
; ///< Pointer to the bottom view. Must be set by the CBottomView parent class.