Mark method const
[TortoiseGit.git] / src / TortoiseMerge / BaseView.h
blob675e3e317246cf31e605d3cac86d0f45baa2aa9a
1 // TortoiseGitMerge - a Diff/Patch program
3 // Copyright (C) 2003-2015 - 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"
25 #include "LineColors.h"
26 #include "TripleClick.h"
27 #include "IconMenu.h"
28 #include "FindDlg.h"
30 typedef struct inlineDiffPos
32 apr_off_t start;
33 apr_off_t end;
34 } inlineDiffPos;
37 /**
38 * \ingroup TortoiseMerge
40 * View class providing the basic functionality for
41 * showing diffs. Has three parent classes which inherit
42 * from this base class: CLeftView, CRightView and CBottomView.
44 class CBaseView : public CView, public CTripleClick
46 DECLARE_DYNCREATE(CBaseView)
47 friend class CLineDiffBar;
48 public:
49 typedef CFileTextLines::UnicodeType UnicodeType;
50 enum ECharGroup { // ordered by priority low-to-hi
51 CHG_UNKNOWN,
52 CHG_CONTROL, // x00-x08, x0a-x1f
53 CHG_WHITESPACE, // space, tab
54 CHG_WORDSEPARATOR, // 0x21-2f, x3a-x40, x5b-x60, x7b-x7f .,:;!?(){}[]/\<> ...
55 CHG_WORDLETTER, // alpha num _ (others)
58 CBaseView();
59 virtual ~CBaseView();
61 public: // methods
62 /**
63 * Indicates that the underlying document has been updated. Reloads all
64 * data and redraws the view.
66 virtual void DocumentUpdated();
67 /**
68 * Returns the number of lines visible on the view.
70 int GetScreenLines();
71 /**
72 * Scrolls the view to the given line.
73 * \param nNewTopLine The new top line to scroll the view to
74 * \param bTrackScrollBar If TRUE, then the scrollbars are affected too.
76 void ScrollToLine(int nNewTopLine, BOOL bTrackScrollBar = TRUE);
77 void ScrollAllToLine(int nNewTopLine, BOOL bTrackScrollBar = TRUE);
78 void ScrollSide(int delta);
79 void ScrollAllSide(int delta);
80 void ScrollVertical(short delta);
81 static void RecalcAllVertScrollBars(BOOL bPositionOnly = FALSE);
82 static void RecalcAllHorzScrollBars(BOOL bPositionOnly = FALSE);
83 void GoToLine(int nNewLine, BOOL bAll = TRUE);
84 void ScrollToChar(int nNewOffsetChar, BOOL bTrackScrollBar = TRUE);
85 void ScrollAllToChar(int nNewOffsetChar, BOOL bTrackScrollBar = TRUE);
86 void SetReadonly(bool bReadonly = true) {m_bReadonly = bReadonly; if (m_pFindDialog) m_pFindDialog->SetReadonly(m_bReadonly); }
87 void SetWritable(bool bWritable = true) {m_bReadonly = !bWritable; if (m_pFindDialog) m_pFindDialog->SetReadonly(m_bReadonly); }
88 void SetWritableIsChangable(bool bWritableIsChangable = true) {m_bReadonlyIsChangable = bWritableIsChangable;}
89 void SetTarget(bool bTarget = true) {m_bTarget = bTarget;}
90 bool IsReadonly() const {return m_bReadonly;}
91 bool IsWritable() const {return !m_bReadonly && m_pViewData;}
92 bool IsReadonlyChangable() const {return m_bReadonlyIsChangable && !IsModified();}
93 bool IsTarget() const {return m_bTarget;}
94 void SetCaretAndGoalPosition(const POINT& pt) {UpdateCaretPosition(pt); UpdateGoalPos(); }
95 void SetCaretAndGoalViewPosition(const POINT& pt) {UpdateCaretViewPosition(pt); UpdateGoalPos(); }
96 void SetCaretPosition(const POINT& pt) { SetCaretViewPosition(ConvertScreenPosToView(pt)); }
97 POINT GetCaretPosition() { return ConvertViewPosToScreen(GetCaretViewPosition()); }
98 void SetCaretViewPosition(const POINT & pt) { m_ptCaretViewPos = pt; }
99 POINT GetCaretViewPosition() { return m_ptCaretViewPos; }
100 void UpdateCaretPosition(const POINT& pt) { SetCaretPosition(pt); UpdateCaret(); }
101 void UpdateCaretViewPosition(const POINT& pt) { SetCaretViewPosition(pt); UpdateCaret(); EnsureCaretVisible(); }
102 void SetCaretToViewStart() { SetCaretToFirstViewLine(); SetCaretToViewLineStart(); }
103 void SetCaretToFirstViewLine() { m_ptCaretViewPos.y=0; }
104 void SetCaretToViewLineStart() { m_ptCaretViewPos.x=0; }
105 void SetCaretToLineStart() { SetCaretAndGoalPosition(SetupPoint(0, GetCaretPosition().y)); }
106 void EnsureCaretVisible();
107 void UpdateCaret();
109 bool ArePointsSame(const POINT &pt1, const POINT &pt2) {return (pt1.x == pt2.x) && (pt1.y == pt2.y); };
110 POINT SetupPoint(int x, int y) const {POINT ptRet={x, y}; return ptRet; };
111 POINT ConvertScreenPosToView(const POINT& pt);
112 POINT ConvertViewPosToScreen(const POINT& pt);
114 void RefreshViews();
115 static void BuildAllScreen2ViewVector(); ///< schedule full screen2view rebuild
116 static void BuildAllScreen2ViewVector(int ViewLine); ///< schedule rebuild screen2view for single line
117 static void BuildAllScreen2ViewVector(int FirstViewLine, int LastViewLine); ///< schedule rebuild screen2view for line range (first and last inclusive)
118 void UpdateViewLineNumbers();
119 int CleanEmptyLines(); ///< remove line empty in all views
120 int GetLineCount() const;
121 static int GetViewLineForScreen(int screenLine) { return m_Screen2View.GetViewLineForScreen(screenLine); }
122 int FindScreenLineForViewLine(int viewLine);
123 // TODO: find better consistent names for Multiline(line with sublines) and Subline, Count.. or Get..Count ?
124 int CountMultiLines(int nViewLine);
125 int GetSubLineOffset(int index);
126 LineColors & GetLineColors(int nViewLine);
127 static void UpdateLocator() { if (m_pwndLocator) m_pwndLocator->DocumentUpdated(); }
128 void WrapChanged();
130 void HighlightLines(int start, int end = -1);
131 void HighlightViewLines(int start, int end = -1);
132 inline BOOL IsHidden() const {return m_bIsHidden;}
133 inline void SetHidden(BOOL bHidden) {m_bIsHidden = bHidden;}
134 inline bool IsModified() const {return m_bModified;}
135 void SetModified(bool bModified = true) { m_bModified = bModified; m_pState->modifies |= bModified; Invalidate(); }
136 bool HasMarkedBlocks() const { return m_pViewData->HasMarkedBlocks(); }
137 void ClearStepModifiedMark() { m_pState->modifies = false; }
138 void SetInlineWordDiff(bool bWord) {m_bInlineWordDiff = bWord;}
139 void SetInlineDiff(bool bDiff) {m_bShowInlineDiff = bDiff;}
140 void SetMarkedWord(const CString& word) {m_sMarkedWord = word; BuildMarkedWordArray();}
141 LPCTSTR GetMarkedWord() {return (LPCTSTR)m_sMarkedWord;}
142 LPCTSTR GetFindString() {return (LPCTSTR)m_sFindText;}
144 // Selection methods; all public methods dealing with selection go here
145 static void ClearSelection();
146 BOOL GetViewSelection(int& start, int& end) const;
147 BOOL HasSelection() const { return (!((m_nSelViewBlockEnd < 0)||(m_nSelViewBlockStart < 0)||(m_nSelViewBlockStart > m_nSelViewBlockEnd))); }
148 BOOL HasTextSelection() const { return ((m_ptSelectionViewPosStart.x != m_ptSelectionViewPosEnd.x) || (m_ptSelectionViewPosStart.y != m_ptSelectionViewPosEnd.y)); }
149 BOOL HasTextLineSelection() const { return m_ptSelectionViewPosStart.y != m_ptSelectionViewPosEnd.y; }
150 static void SetupAllViewSelection(int start, int end);
151 static void SetupAllSelection(int start, int end);
152 void SetupSelection(int start, int end);
153 static void SetupViewSelection(CBaseView* view, int start, int end);
154 void SetupViewSelection(int start, int end);
155 CString GetSelectedText() const;
156 void CheckModifications(bool& hasMods, bool& hasConflicts, bool& hasWhitespaceMods);
158 // state classifying methods; note: state may belong to more classes
159 static bool IsStateConflicted(DiffStates state);
160 static bool IsStateEmpty(DiffStates state);
161 static bool IsStateRemoved(DiffStates state);
162 static DiffStates ResolveState(DiffStates state);
164 bool IsLineEmpty(int nLineIndex);
165 bool IsViewLineEmpty(int nViewLine);
166 bool IsLineRemoved(int nLineIndex);
167 bool IsViewLineRemoved(int nViewLine);
168 bool IsBlockWhitespaceOnly(int nLineIndex, bool& bIdentical, int& blockstart, int& blockend);
169 bool IsViewLineConflicted(int nLineIndex);
170 bool HasNextConflict();
171 bool HasPrevConflict();
172 bool HasNextDiff();
173 bool HasPrevDiff();
174 bool GetNextInlineDiff(int & nPos);
175 bool GetPrevInlineDiff(int & nPos);
176 bool HasNextInlineDiff();
177 bool HasPrevInlineDiff();
179 static const viewdata& GetEmptyLineData();
180 void InsertViewEmptyLines(int nFirstView, int nCount);
182 virtual void UseBothLeftFirst() {return UseBothBlocks(m_pwndLeft, m_pwndRight); }
183 virtual void UseBothRightFirst() {return UseBothBlocks(m_pwndRight, m_pwndLeft); }
184 void UseTheirAndYourBlock() {return UseBothLeftFirst(); } ///< ! for backward compatibility
185 void UseYourAndTheirBlock() {return UseBothRightFirst(); } ///< ! for backward compatibility
187 virtual void UseLeftBlock() {return UseViewBlock(m_pwndLeft); }
188 virtual void UseLeftFile() {return UseViewFile(m_pwndLeft); }
189 virtual void UseRightBlock() {return UseViewBlock(m_pwndRight); }
190 virtual void UseRightFile() {return UseViewFile(m_pwndRight); }
191 virtual void LeaveOnlyMarkedBlocks() { return LeaveOnlyMarkedBlocks(m_pwndLeft); }
192 virtual void UseViewFileOfMarked() { UseViewFileOfMarked(m_pwndLeft); }
193 virtual void UseViewFileExceptEdited() { UseViewFileExceptEdited(m_pwndLeft); }
195 // ViewData methods
196 void InsertViewData(int index, const CString& sLine, DiffStates state, int linenumber, EOL ending, HIDESTATE hide, int movedline);
197 void InsertViewData(int index, const viewdata& data);
198 void RemoveViewData(int index);
200 const viewdata& GetViewData(int index) const {return m_pViewData->GetData(index); }
201 const CString& GetViewLine(int index) const {return m_pViewData->GetLine(index); }
202 DiffStates GetViewState(int index) const {return m_pViewData->GetState(index); }
203 HIDESTATE GetViewHideState(int index) {return m_pViewData->GetHideState(index); }
204 int GetViewLineNumber(int index) {return m_pViewData->GetLineNumber(index); }
205 int GetViewMovedIndex(int index) {return m_pViewData->GetMovedIndex(index); }
206 int FindViewLineNumber(int number) {return m_pViewData->FindLineNumber(number); }
207 EOL GetViewLineEnding(int index) const {return m_pViewData->GetLineEnding(index); }
208 bool GetViewMarked(int index) const {return m_pViewData->GetMarked(index); }
210 int GetViewCount() const {return m_pViewData ? m_pViewData->GetCount() : -1; }
212 void SetViewData(int index, const viewdata& data);
213 void SetViewState(int index, DiffStates state);
214 void SetViewLine(int index, const CString& sLine);
215 void SetViewLineNumber(int index, int linenumber);
216 void SetViewLineEnding(int index, EOL ending);
217 void SetViewMarked(int index, bool marked);
219 static bool IsViewGood(const CBaseView* view ) { return (view != 0) && view->IsWindowVisible(); }
220 static CBaseView * GetFirstGoodView();
222 int GetIndentCharsForLine(int x, int y);
223 void AddIndentationForSelectedBlock();
224 void RemoveIndentationForSelectedBlock();
225 void ConvertTabToSpaces();
226 void Tabularize();
227 void RemoveTrailWhiteChars();
229 struct TWhitecharsProperties
231 bool HasMixedEols;
232 bool HasTrailWhiteChars;
233 bool HasSpacesToConvert;
234 bool HasTabsToConvert;
237 TWhitecharsProperties GetWhitecharsProperties();
239 public: // variables
240 CViewData * m_pViewData;
241 CViewData * m_pOtherViewData;
242 CBaseView * m_pOtherView;
244 CString m_sWindowName; ///< The name of the view which is shown as a window title to the user
245 CString m_sFullFilePath; ///< The full path of the file shown
246 CString m_sConvertedFilePath; ///< the path to the converted file that's shown in the view
247 CString m_sReflectedName; ///< The reflected name of file
249 BOOL m_bViewWhitespace; ///< If TRUE, then SPACE and TAB are shown as special characters
250 BOOL m_bShowInlineDiff; ///< If TRUE, diffs in lines are marked colored
251 bool m_bShowSelection; ///< If true, selection bars are shown and selected text darkened
252 bool m_bWhitespaceInlineDiffs; ///< if true, inline diffs are shown for identical lines only differing in whitespace
253 int m_nTopLine; ///< The topmost text line in the view
254 std::vector<int> m_arMarkedWordLines; ///< which lines contain a marked word
255 std::vector<int> m_arFindStringLines; ///< which lines contain a found string
257 static CLocatorBar * m_pwndLocator; ///< Pointer to the locator bar on the left
258 static CLineDiffBar * m_pwndLineDiffBar; ///< Pointer to the line diff bar at the bottom
259 static CMFCStatusBar * m_pwndStatusBar;///< Pointer to the status bar
260 static CMFCRibbonStatusBar * m_pwndRibbonStatusBar;///< Pointer to the status bar
261 static CMainFrame * m_pMainFrame; ///< Pointer to the mainframe
263 int m_nTabMode;
264 bool m_bEditorConfigEnabled;
265 BOOL m_bEditorConfigLoaded;
267 void GoToFirstDifference();
268 void GoToFirstConflict();
269 void AddEmptyViewLine(int nLineIndex);
270 #define SAVE_REMOVEDLINES 1
271 int SaveFile(int Flags = 0);
272 int SaveFileTo(CString FileName, int Flags = 0);
274 EOL GetLineEndings(); ///< Get Line endings on view from lineendings or "mixed"
275 EOL GetLineEndings(bool MixelEols);
276 void ReplaceLineEndings(EOL); ///< Set AUTO lineending and replaces all EOLs
277 void SetLineEndingStyle(EOL); ///< Set AUTO lineending
278 UnicodeType GetTextType() { return m_texttype; }
279 void SetTextType(UnicodeType); ///< Changes TextType
280 void AskUserForNewLineEndingsAndTextType(int); ///< Open gui
281 int GetTabMode() { return m_nTabMode; }
282 void SetTabMode(int nTabMode) { m_nTabMode = nTabMode; }
283 int GetTabSize() { return m_nTabSize; }
284 void SetTabSize(int nTabSize) { m_nTabSize = nTabSize; }
285 bool GetEditorConfigEnabled() { return m_bEditorConfigEnabled; }
286 void SetEditorConfigEnabled(bool bEditorConfigEnabled);
287 BOOL GetEditorConfigLoaded() { return m_bEditorConfigLoaded; }
289 CWorkingFile * m_pWorkingFile; ///< pointer to source/destination file parametrers
291 protected: // methods
292 enum {
293 MOVERIGHT =0,
294 MOVELEFT = 1,
297 virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
298 virtual void OnDraw(CDC * pDC);
299 virtual INT_PTR OnToolHitTest(CPoint point, TOOLINFO* pTI) const;
300 virtual BOOL PreTranslateMessage(MSG* pMsg);
301 virtual ULONG GetGestureStatus(CPoint ptTouch) override;
302 BOOL OnToolTipNotify(UINT id, NMHDR *pNMHDR, LRESULT *pResult);
303 afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
304 afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
305 afx_msg BOOL OnEraseBkgnd(CDC* pDC);
306 afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
307 afx_msg void OnDestroy();
308 afx_msg void OnSize(UINT nType, int cx, int cy);
309 afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
310 afx_msg void OnMouseHWheel(UINT nFlags, short zDelta, CPoint pt);
311 afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
312 afx_msg void OnKillFocus(CWnd* pNewWnd);
313 afx_msg void OnSetFocus(CWnd* pOldWnd);
314 afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
315 afx_msg void OnMergeNextdifference();
316 afx_msg void OnMergePreviousdifference();
317 afx_msg void OnMergePreviousconflict();
318 afx_msg void OnMergeNextconflict();
319 afx_msg void OnNavigateNextinlinediff();
320 afx_msg void OnNavigatePrevinlinediff();
321 afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
322 afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
323 afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
324 afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
325 virtual void OnLButtonTrippleClick(UINT nFlags, CPoint point) override;
326 afx_msg void OnEditCopy();
327 afx_msg void OnMouseMove(UINT nFlags, CPoint point);
328 afx_msg void OnTimer(UINT_PTR nIDEvent);
329 afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
330 afx_msg void OnCaretDown();
331 afx_msg void OnCaretLeft();
332 afx_msg void OnCaretRight();
333 afx_msg void OnCaretUp();
334 afx_msg void OnCaretWordleft();
335 afx_msg void OnCaretWordright();
336 afx_msg void OnEditCut();
337 afx_msg void OnEditPaste();
338 afx_msg void OnEditSelectall();
339 afx_msg LRESULT OnFindDialogMessage(WPARAM wParam, LPARAM lParam);
340 afx_msg void OnEditFind();
341 afx_msg void OnEditFindnext();
342 afx_msg void OnEditFindprev();
343 afx_msg void OnEditFindnextStart();
344 afx_msg void OnEditFindprevStart();
345 afx_msg void OnEditGotoline();
346 afx_msg void OnToggleReadonly();
348 DECLARE_MESSAGE_MAP()
350 void DrawHeader(CDC *pdc, const CRect &rect);
351 void DrawMargin(CDC *pdc, const CRect &rect, int nLineIndex);
352 void DrawSingleLine(CDC *pDC, const CRect &rc, int nLineIndex);
354 * Draws the horizontal lines around current diff block or selection block.
356 void DrawBlockLine(CDC *pDC, const CRect &rc, int nLineIndex);
358 * Draws the line ending 'char'.
360 void DrawLineEnding(CDC *pDC, const CRect &rc, int nLineIndex, const CPoint& origin);
361 void ExpandChars(const CString &sLine, int nOffset, int nCount, CString &line);
362 CString ExpandChars(const CString &sLine, int nOffset = 0);
363 int CountExpandedChars(const CString &sLine, int nLength);
365 void RecalcVertScrollBar(BOOL bPositionOnly = FALSE);
366 void RecalcHorzScrollBar(BOOL bPositionOnly = FALSE);
368 void OnDoMouseWheel(UINT nFlags, short zDelta, CPoint pt);
369 void OnDoMouseHWheel(UINT nFlags, short zDelta, CPoint pt);
370 void OnDoHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar, CBaseView * master);
371 void OnDoVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar, CBaseView * master);
373 void ShowDiffLines(int nLine);
375 int GetTabSize() const {return m_nTabSize;}
376 void DeleteFonts();
378 void CalcLineCharDim();
379 int GetLineHeight();
380 int GetCharWidth();
381 int GetMaxLineLength();
382 int GetLineLength(int index);
383 int GetLineLengthWithTabsConverted(int index);
384 int GetViewLineLength(int index) const;
385 int GetScreenChars();
386 int GetAllMinScreenChars() const;
387 int GetAllMaxLineLength() const;
388 int GetAllLineCount() const;
389 int GetAllMinScreenLines() const;
390 CString GetViewLineChars(int index) const;
391 CString GetLineChars(int index);
392 int GetLineNumber(int index) const;
393 CFont * GetFont(BOOL bItalic = FALSE, BOOL bBold = FALSE);
394 int GetLineFromPoint(CPoint point);
395 int GetMarginWidth();
396 COLORREF InlineDiffColor(int nLineIndex);
397 COLORREF InlineViewLineDiffColor(int nLineIndex);
398 bool GetInlineDiffPositions(int lineIndex, std::vector<inlineDiffPos>& positions);
399 void CheckOtherView();
400 void GetWhitespaceBlock(CViewData *viewData, int nLineIndex, int & nStartBlock, int & nEndBlock);
401 CString GetWhitespaceString(CViewData *viewData, int nStartBlock, int nEndBlock);
402 bool IsViewLineHidden(int nViewLine);
403 static bool IsViewLineHidden(CViewData * pViewData, int nViewLine);
405 void OnContextMenu(CPoint point, DiffStates state);
407 * Updates the status bar pane. Call this if the document changed.
409 void UpdateStatusBar();
411 static bool IsLeftViewGood() {return IsViewGood(m_pwndLeft);}
412 static bool IsRightViewGood() {return IsViewGood(m_pwndRight);}
413 static bool IsBottomViewGood() {return IsViewGood(m_pwndBottom);}
415 int CalculateActualOffset(const POINT& point);
416 int CalculateCharIndex(int nLineIndex, int nActualOffset);
417 int CalcColFromPoint(int xpos, int lineIndex);
418 POINT TextToClient(const POINT& point);
419 void DrawTextLine(CDC * pDC, const CRect &rc, int nLineIndex, POINT& coords);
420 void ClearCurrentSelection();
421 void AdjustSelection(bool bMoveLeft);
422 bool SelectNextBlock(int nDirection, bool bConflict, bool bSkipEndOfCurrentBlock = true, bool dryrun = false);
424 enum SearchDirection{SearchNext=0, SearchPrevious=1};
425 bool StringFound(const CString& str, SearchDirection srchDir, int& start, int& end) const;
426 bool Search(SearchDirection srchDir, bool useStart, bool flashIfNotFound, bool stopEof);
427 void BuildFindStringArray();
429 void RemoveLine(int nLineIndex);
430 void RemoveSelectedText();
431 void PasteText();
432 void InsertText(const CString& sText);
433 void AddUndoViewLine(int nViewLine, bool bAddEmptyLine = false);
435 bool MoveCaretLeft();
436 bool MoveCaretRight();
437 void MoveCaretWordLeft();
438 void MoveCaretWordRight();
439 void OnCaretMove(bool bMoveLeft);
440 void OnCaretMove(bool bMoveLeft, bool isShiftPressed);
441 void UpdateGoalPos();
443 ECharGroup GetCharGroup(const CString &str, int index) const { return index >= 0 && index < str.GetLength() ? GetCharGroup(str[index]) : CHG_UNKNOWN; }
444 ECharGroup GetCharGroup(const wchar_t zChar) const;
445 bool IsWordSeparator(const wchar_t ch) const;
446 bool IsCaretAtWordBoundary();
447 void UpdateViewsCaretPosition();
448 void BuildMarkedWordArray();
450 virtual void UseBothBlocks(CBaseView * /*pwndFirst*/, CBaseView * /*pwndLast*/) {};
451 virtual void UseViewBlock(CBaseView * /*pwndView*/) {}
452 void UseViewBlock(CBaseView * pwndView, int nFirstViewLine, int nLastViewLine, std::function<bool(int)> fnSkip = [] (int) -> bool { return false; });
453 virtual void UseViewFile(CBaseView * /*pwndView*/) {}
454 virtual void MarkBlock(bool /*marked*/) {}
455 void MarkBlock(bool marked, int nFirstViewLine, int nLastViewLine);
456 void LeaveOnlyMarkedBlocks(CBaseView *pwndView);
457 void UseViewFileOfMarked(CBaseView *pwndView);
458 void UseViewFileExceptEdited(CBaseView *pwndView);
460 virtual void AddContextItems(CIconMenu& popup, DiffStates state);
461 void AddCutCopyAndPaste(CIconMenu& popup);
462 void CompensateForKeyboard(CPoint& point);
463 static HICON LoadIcon(WORD iconId);
464 void ReleaseBitmap();
465 static bool LinesInOneChange( int direction, DiffStates firstLineState, DiffStates currentLineState );
466 static void FilterWhitespaces(CString& first, CString& second);
467 static void FilterWhitespaces(CString& line);
468 int GetButtonEventLineIndex(const POINT& point);
470 static void ResetUndoStep();
471 void SaveUndoStep();
472 protected: // variables
473 COLORREF m_InlineRemovedBk;
474 COLORREF m_InlineAddedBk;
475 COLORREF m_ModifiedBk;
476 COLORREF m_WhiteSpaceFg;
477 UINT m_nStatusBarID; ///< The ID of the status bar pane used by this view. Must be set by the parent class.
479 SVNLineDiff m_svnlinediff;
480 DWORD m_nInlineDiffMaxLineLength;
481 BOOL m_bOtherDiffChecked;
482 bool m_bModified;
483 BOOL m_bFocused;
484 BOOL m_bViewLinenumbers;
485 BOOL m_bIsHidden;
486 BOOL m_bIconLFs;
487 int m_nLineHeight;
488 int m_nCharWidth;
489 int m_nMaxLineLength;
490 int m_nScreenLines;
491 int m_nScreenChars;
492 int m_nLastScreenChars;
493 int m_nOffsetChar;
494 int m_nTabSize;
495 int m_nDigits;
496 bool m_bInlineWordDiff;
498 // Block selection attributes
499 int m_nSelViewBlockStart;
500 int m_nSelViewBlockEnd;
502 int m_nMouseLine;
503 bool m_mouseInMargin;
504 HCURSOR m_margincursor;
506 // caret
507 bool m_bReadonly;
508 bool m_bReadonlyIsChangable;
509 bool m_bTarget; ///< view intended as result
510 POINT m_ptCaretViewPos;
511 int m_nCaretGoalPos;
513 // Text selection attributes
514 POINT m_ptSelectionViewPosStart;
515 POINT m_ptSelectionViewPosEnd;
516 POINT m_ptSelectionViewPosOrigin;
518 static const UINT m_FindDialogMessage;
519 CFindDlg * m_pFindDialog;
520 CString m_sFindText;
521 BOOL m_bMatchCase;
522 bool m_bLimitToDiff;
523 bool m_bWholeWord;
526 HICON m_hAddedIcon;
527 HICON m_hRemovedIcon;
528 HICON m_hConflictedIcon;
529 HICON m_hConflictedIgnoredIcon;
530 HICON m_hWhitespaceBlockIcon;
531 HICON m_hEqualIcon;
532 HICON m_hEditedIcon;
534 HICON m_hLineEndingCR;
535 HICON m_hLineEndingCRLF;
536 HICON m_hLineEndingLF;
538 HICON m_hMovedIcon;
539 HICON m_hMarkedIcon;
541 LOGFONT m_lfBaseFont;
542 static const int fontsCount = 4;
543 CFont * m_apFonts[fontsCount];
544 CString m_sConflictedText;
545 CString m_sNoLineNr;
546 CString m_sMarkedWord;
547 CString m_sPreviousMarkedWord;
549 CBitmap * m_pCacheBitmap;
550 CDC * m_pDC;
551 CScrollTool m_ScrollTool;
552 CString m_sWordSeparators;
553 CString m_Eols[EOL__COUNT];
555 UnicodeType m_texttype; ///< the text encoding this view uses
556 EOL m_lineendings; ///< the line endings the view uses
557 bool m_bInsertMode;
559 char m_szTip[MAX_PATH*2+1];
560 wchar_t m_wszTip[MAX_PATH*2+1];
561 // These three pointers lead to the three parent
562 // classes CLeftView, CRightView and CBottomView
563 // and are used for the communication between
564 // the views (e.g. synchronized scrolling, ...)
565 // To find out which parent class this object
566 // is made of just compare e.g. (m_pwndLeft==this).
567 static CBaseView * m_pwndLeft; ///< Pointer to the left view. Must be set by the CLeftView parent class.
568 static CBaseView * m_pwndRight; ///< Pointer to the right view. Must be set by the CRightView parent class.
569 static CBaseView * m_pwndBottom; ///< Pointer to the bottom view. Must be set by the CBottomView parent class.
571 struct TScreenLineInfo
573 int nViewLine;
574 int nViewSubLine;
576 class TScreenedViewLine
578 public:
579 TScreenedViewLine()
581 Clear();
584 void Clear()
586 bSublinesSet = false;
587 eIcon = ICN_UNKNOWN;
588 bLineColorsSet = false;
589 bLineColorsSetWhiteSpace = false;
592 bool bSublinesSet;
593 std::vector<CString> SubLines;
595 enum EIcon
597 ICN_UNKNOWN,
598 ICN_NONE,
599 ICN_EDIT,
600 ICN_SAME,
601 ICN_WHITESPACEDIFF,
602 ICN_ADD,
603 ICN_REMOVED,
604 ICN_MOVED,
605 ICN_MARKED,
606 ICN_CONFLICT,
607 ICN_CONFLICTIGNORED,
608 } eIcon;
610 bool bLineColorsSetWhiteSpace;
611 LineColors lineColorsWhiteSpace;
612 bool bLineColorsSet;
613 LineColors lineColors;
615 std::vector<TScreenedViewLine> m_ScreenedViewLine; ///< cached data for screening
617 static allviewstate m_AllState;
618 viewstate * m_pState;
620 enum PopupCommands
622 POPUPCOMMAND_DISMISSED = 0,
623 // 2-pane view commands
624 POPUPCOMMAND_USELEFTBLOCK,
625 POPUPCOMMAND_USELEFTFILE,
626 POPUPCOMMAND_USEBOTHLEFTFIRST,
627 POPUPCOMMAND_USEBOTHRIGHTFIRST,
628 POPUPCOMMAND_MARKBLOCK,
629 POPUPCOMMAND_UNMARKBLOCK,
630 POPUPCOMMAND_LEAVEONLYMARKEDBLOCKS,
631 // multiple writable views
632 POPUPCOMMAND_PREPENDFROMRIGHT,
633 POPUPCOMMAND_REPLACEBYRIGHT,
634 POPUPCOMMAND_APPENDFROMRIGHT,
635 POPUPCOMMAND_USERIGHTFILE,
636 // 3-pane view commands
637 POPUPCOMMAND_USEYOURANDTHEIRBLOCK,
638 POPUPCOMMAND_USETHEIRANDYOURBLOCK,
639 POPUPCOMMAND_USEYOURBLOCK,
640 POPUPCOMMAND_USEYOURFILE,
641 POPUPCOMMAND_USETHEIRBLOCK,
642 POPUPCOMMAND_USETHEIRFILE,
643 // others
644 POPUPCOMMAND_TABTOSPACES,
645 POPUPCOMMAND_SPACESTOTABS,
646 POPUPCOMMAND_REMOVETRAILWHITES,
648 POPUPCOMMAND__LAST,
651 class Screen2View
653 public:
654 Screen2View()
655 : m_pViewData(nullptr)
656 {m_bFull=false; }
658 int GetViewLineForScreen(int screenLine);
659 int GetSubLineOffset(int screenLine);
660 TScreenLineInfo GetScreenLineInfo(int screenLine);
661 int FindScreenLineForViewLine(int viewLine);
662 void ScheduleFullRebuild(CViewData * ViewData);
663 void ScheduleRangeRebuild(CViewData * ViewData, int FirstViewLine, int LastViewLine);
664 int size();
666 private:
667 struct TRebuildRange
669 int FirstViewLine;
670 int LastViewLine;
673 bool FixScreenedCacheSize(CBaseView* View);
674 void RebuildIfNecessary();
675 bool ResetScreenedViewLineCache(CBaseView* View) const;
676 bool ResetScreenedViewLineCache(CBaseView* View, const TRebuildRange& Range) const;
678 CViewData * m_pViewData;
679 bool m_bFull;
680 std::vector<TScreenLineInfo> m_Screen2View;
681 std::vector<TRebuildRange> m_RebuildRanges;
684 static Screen2View m_Screen2View;
685 CFileTextLines::SaveParams m_SaveParams; ///< encoding and new line style for saving