Allow to replace with empty string, and disable replace textbox and buttons when...
[TortoiseGit.git] / src / TortoiseMerge / BaseView.h
blob2aba1a881c326e7f847d1419c75204a97a86073e
1 // TortoiseGitMerge - a Diff/Patch program
3 // Copyright (C) 2003-2014 - 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) {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 void ClearStepModifiedMark() { m_pState->modifies = false; }
137 void SetInlineWordDiff(bool bWord) {m_bInlineWordDiff = bWord;}
138 void SetInlineDiff(bool bDiff) {m_bShowInlineDiff = bDiff;}
139 void SetMarkedWord(const CString& word) {m_sMarkedWord = word; BuildMarkedWordArray();}
140 LPCTSTR GetMarkedWord() {return (LPCTSTR)m_sMarkedWord;}
141 LPCTSTR GetFindString() {return (LPCTSTR)m_sFindText;}
143 // Selection methods; all public methods dealing with selection go here
144 static void ClearSelection();
145 BOOL GetViewSelection(int& start, int& end) const;
146 BOOL HasSelection() const { return (!((m_nSelViewBlockEnd < 0)||(m_nSelViewBlockStart < 0)||(m_nSelViewBlockStart > m_nSelViewBlockEnd))); }
147 BOOL HasTextSelection() const { return ((m_ptSelectionViewPosStart.x != m_ptSelectionViewPosEnd.x) || (m_ptSelectionViewPosStart.y != m_ptSelectionViewPosEnd.y)); }
148 BOOL HasTextLineSelection() const { return m_ptSelectionViewPosStart.y != m_ptSelectionViewPosEnd.y; }
149 static void SetupAllViewSelection(int start, int end);
150 static void SetupAllSelection(int start, int end);
151 void SetupSelection(int start, int end);
152 static void SetupViewSelection(CBaseView* view, int start, int end);
153 void SetupViewSelection(int start, int end);
154 CString GetSelectedText() const;
155 void CheckModifications(bool& hasMods, bool& hasConflicts, bool& hasWhitespaceMods);
157 // state classifying methods; note: state may belong to more classes
158 static bool IsStateConflicted(DiffStates state);
159 static bool IsStateEmpty(DiffStates state);
160 static bool IsStateRemoved(DiffStates state);
161 static DiffStates ResolveState(DiffStates state);
163 bool IsLineEmpty(int nLineIndex);
164 bool IsViewLineEmpty(int nViewLine);
165 bool IsLineRemoved(int nLineIndex);
166 bool IsViewLineRemoved(int nViewLine);
167 bool IsBlockWhitespaceOnly(int nLineIndex, bool& bIdentical, int& blockstart, int& blockend);
168 bool IsViewLineConflicted(int nLineIndex);
169 bool HasNextConflict();
170 bool HasPrevConflict();
171 bool HasNextDiff();
172 bool HasPrevDiff();
173 bool GetNextInlineDiff(int & nPos);
174 bool GetPrevInlineDiff(int & nPos);
175 bool HasNextInlineDiff();
176 bool HasPrevInlineDiff();
178 static const viewdata& GetEmptyLineData();
179 void InsertViewEmptyLines(int nFirstView, int nCount);
181 virtual void UseBothLeftFirst() {return UseBothBlocks(m_pwndLeft, m_pwndRight); }
182 virtual void UseBothRightFirst() {return UseBothBlocks(m_pwndRight, m_pwndLeft); }
183 void UseTheirAndYourBlock() {return UseBothLeftFirst(); } ///< ! for backward compatibility
184 void UseYourAndTheirBlock() {return UseBothRightFirst(); } ///< ! for backward compatibility
186 virtual void UseLeftBlock() {return UseViewBlock(m_pwndLeft); }
187 virtual void UseLeftFile() {return UseViewFile(m_pwndLeft); }
188 virtual void UseRightBlock() {return UseViewBlock(m_pwndRight); }
189 virtual void UseRightFile() {return UseViewFile(m_pwndRight); }
190 virtual void UseLeftFileExceptMarked() { return UseViewFileExceptMarked(m_pwndLeft); }
192 // ViewData methods
193 void InsertViewData(int index, const CString& sLine, DiffStates state, int linenumber, EOL ending, HIDESTATE hide, int movedline);
194 void InsertViewData(int index, const viewdata& data);
195 void RemoveViewData(int index);
197 const viewdata& GetViewData(int index) const {return m_pViewData->GetData(index); }
198 const CString& GetViewLine(int index) const {return m_pViewData->GetLine(index); }
199 DiffStates GetViewState(int index) const {return m_pViewData->GetState(index); }
200 HIDESTATE GetViewHideState(int index) {return m_pViewData->GetHideState(index); }
201 int GetViewLineNumber(int index) {return m_pViewData->GetLineNumber(index); }
202 int GetViewMovedIndex(int index) {return m_pViewData->GetMovedIndex(index); }
203 int FindViewLineNumber(int number) {return m_pViewData->FindLineNumber(number); }
204 EOL GetViewLineEnding(int index) const {return m_pViewData->GetLineEnding(index); }
205 bool GetViewMarked(int index) const {return m_pViewData->GetMarked(index); }
207 int GetViewCount() const {return m_pViewData ? m_pViewData->GetCount() : -1; }
209 void SetViewData(int index, const viewdata& data);
210 void SetViewState(int index, DiffStates state);
211 void SetViewLine(int index, const CString& sLine);
212 void SetViewLineNumber(int index, int linenumber);
213 void SetViewLineEnding(int index, EOL ending);
214 void SetViewMarked(int index, bool marked);
216 static bool IsViewGood(const CBaseView* view ) { return (view != 0) && view->IsWindowVisible(); }
217 static CBaseView * GetFirstGoodView();
219 int GetIndentCharsForLine(int x, int y);
220 void AddIndentationForSelectedBlock();
221 void RemoveIndentationForSelectedBlock();
222 void ConvertTabToSpaces();
223 void Tabularize();
224 void RemoveTrailWhiteChars();
226 struct TWhitecharsProperties
228 bool HasMixedEols;
229 bool HasTrailWhiteChars;
230 bool HasSpacesToConvert;
231 bool HasTabsToConvert;
234 TWhitecharsProperties GetWhitecharsProperties();
236 public: // variables
237 CViewData * m_pViewData;
238 CViewData * m_pOtherViewData;
239 CBaseView * m_pOtherView;
241 CString m_sWindowName; ///< The name of the view which is shown as a window title to the user
242 CString m_sFullFilePath; ///< The full path of the file shown
243 CString m_sConvertedFilePath; ///< the path to the converted file that's shown in the view
245 BOOL m_bViewWhitespace; ///< If TRUE, then SPACE and TAB are shown as special characters
246 BOOL m_bShowInlineDiff; ///< If TRUE, diffs in lines are marked colored
247 bool m_bShowSelection; ///< If true, selection bars are shown and selected text darkened
248 bool m_bWhitespaceInlineDiffs; ///< if true, inline diffs are shown for identical lines only differing in whitespace
249 int m_nTopLine; ///< The topmost text line in the view
250 std::vector<int> m_arMarkedWordLines; ///< which lines contain a marked word
251 std::vector<int> m_arFindStringLines; ///< which lines contain a found string
253 static CLocatorBar * m_pwndLocator; ///< Pointer to the locator bar on the left
254 static CLineDiffBar * m_pwndLineDiffBar; ///< Pointer to the line diff bar at the bottom
255 static CMFCStatusBar * m_pwndStatusBar;///< Pointer to the status bar
256 static CMFCRibbonStatusBar * m_pwndRibbonStatusBar;///< Pointer to the status bar
257 static CMainFrame * m_pMainFrame; ///< Pointer to the mainframe
259 int m_nTabMode;
261 void GoToFirstDifference();
262 void GoToFirstConflict();
263 void AddEmptyViewLine(int nLineIndex);
264 #define SAVE_REMOVEDLINES 1
265 int SaveFile(int Flags = 0);
266 int SaveFileTo(CString FileName, int Flags = 0);
268 EOL GetLineEndings(); ///< Get Line endings on view from lineendings or "mixed"
269 EOL GetLineEndings(bool MixelEols);
270 void ReplaceLineEndings(EOL); ///< Set AUTO lineending and replaces all EOLs
271 void SetLineEndingStyle(EOL); ///< Set AUTO lineending
272 UnicodeType GetTextType() { return m_texttype; }
273 void SetTextType(UnicodeType); ///< Changes TextType
274 void AskUserForNewLineEndingsAndTextType(int); ///< Open gui
276 CWorkingFile * m_pWorkingFile; ///< pointer to source/destination file parametrers
278 protected: // methods
279 enum {
280 MOVERIGHT =0,
281 MOVELEFT = 1,
284 virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
285 virtual void OnDraw(CDC * pDC);
286 virtual INT_PTR OnToolHitTest(CPoint point, TOOLINFO* pTI) const;
287 virtual BOOL PreTranslateMessage(MSG* pMsg);
288 BOOL OnToolTipNotify(UINT id, NMHDR *pNMHDR, LRESULT *pResult);
289 afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
290 afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
291 afx_msg BOOL OnEraseBkgnd(CDC* pDC);
292 afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
293 afx_msg void OnDestroy();
294 afx_msg void OnSize(UINT nType, int cx, int cy);
295 afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
296 afx_msg void OnMouseHWheel(UINT nFlags, short zDelta, CPoint pt);
297 afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
298 afx_msg void OnKillFocus(CWnd* pNewWnd);
299 afx_msg void OnSetFocus(CWnd* pOldWnd);
300 afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
301 afx_msg void OnMergeNextdifference();
302 afx_msg void OnMergePreviousdifference();
303 afx_msg void OnMergePreviousconflict();
304 afx_msg void OnMergeNextconflict();
305 afx_msg void OnNavigateNextinlinediff();
306 afx_msg void OnNavigatePrevinlinediff();
307 afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
308 afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
309 afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
310 afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
311 virtual void OnLButtonTrippleClick(UINT nFlags, CPoint point) override;
312 afx_msg void OnEditCopy();
313 afx_msg void OnMouseMove(UINT nFlags, CPoint point);
314 afx_msg void OnTimer(UINT_PTR nIDEvent);
315 afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
316 afx_msg void OnCaretDown();
317 afx_msg void OnCaretLeft();
318 afx_msg void OnCaretRight();
319 afx_msg void OnCaretUp();
320 afx_msg void OnCaretWordleft();
321 afx_msg void OnCaretWordright();
322 afx_msg void OnEditCut();
323 afx_msg void OnEditPaste();
324 afx_msg void OnEditSelectall();
325 afx_msg LRESULT OnFindDialogMessage(WPARAM wParam, LPARAM lParam);
326 afx_msg void OnEditFind();
327 afx_msg void OnEditFindnext();
328 afx_msg void OnEditFindprev();
329 afx_msg void OnEditFindnextStart();
330 afx_msg void OnEditFindprevStart();
331 afx_msg void OnEditGotoline();
332 afx_msg void OnToggleReadonly();
334 DECLARE_MESSAGE_MAP()
336 void DrawHeader(CDC *pdc, const CRect &rect);
337 void DrawMargin(CDC *pdc, const CRect &rect, int nLineIndex);
338 void DrawSingleLine(CDC *pDC, const CRect &rc, int nLineIndex);
340 * Draws the horizontal lines around current diff block or selection block.
342 void DrawBlockLine(CDC *pDC, const CRect &rc, int nLineIndex);
344 * Draws the line ending 'char'.
346 void DrawLineEnding(CDC *pDC, const CRect &rc, int nLineIndex, const CPoint& origin);
347 void ExpandChars(const CString &sLine, int nOffset, int nCount, CString &line);
348 CString ExpandChars(const CString &sLine, int nOffset = 0);
349 int CountExpandedChars(const CString &sLine, int nLength);
351 void RecalcVertScrollBar(BOOL bPositionOnly = FALSE);
352 void RecalcHorzScrollBar(BOOL bPositionOnly = FALSE);
354 void OnDoMouseWheel(UINT nFlags, short zDelta, CPoint pt);
355 void OnDoMouseHWheel(UINT nFlags, short zDelta, CPoint pt);
356 void OnDoHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar, CBaseView * master);
357 void OnDoVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar, CBaseView * master);
359 void ShowDiffLines(int nLine);
361 int GetTabSize() const {return m_nTabSize;}
362 void DeleteFonts();
364 void CalcLineCharDim();
365 int GetLineHeight();
366 int GetCharWidth();
367 int GetMaxLineLength();
368 int GetLineLength(int index);
369 int GetViewLineLength(int index) const;
370 int GetScreenChars();
371 int GetAllMinScreenChars() const;
372 int GetAllMaxLineLength() const;
373 int GetAllLineCount() const;
374 int GetAllMinScreenLines() const;
375 CString GetViewLineChars(int index) const;
376 CString GetLineChars(int index);
377 int GetLineNumber(int index) const;
378 CFont * GetFont(BOOL bItalic = FALSE, BOOL bBold = FALSE);
379 int GetLineFromPoint(CPoint point);
380 int GetMarginWidth();
381 COLORREF InlineDiffColor(int nLineIndex);
382 COLORREF InlineViewLineDiffColor(int nLineIndex);
383 bool GetInlineDiffPositions(int lineIndex, std::vector<inlineDiffPos>& positions);
384 void CheckOtherView();
385 void GetWhitespaceBlock(CViewData *viewData, int nLineIndex, int & nStartBlock, int & nEndBlock);
386 CString GetWhitespaceString(CViewData *viewData, int nStartBlock, int nEndBlock);
387 bool IsViewLineHidden(int nViewLine);
388 static bool IsViewLineHidden(CViewData * pViewData, int nViewLine);
390 void OnContextMenu(CPoint point, DiffStates state);
392 * Updates the status bar pane. Call this if the document changed.
394 void UpdateStatusBar();
396 static bool IsLeftViewGood() {return IsViewGood(m_pwndLeft);}
397 static bool IsRightViewGood() {return IsViewGood(m_pwndRight);}
398 static bool IsBottomViewGood() {return IsViewGood(m_pwndBottom);}
400 int CalculateActualOffset(const POINT& point);
401 int CalculateCharIndex(int nLineIndex, int nActualOffset);
402 POINT TextToClient(const POINT& point);
403 void DrawTextLine(CDC * pDC, const CRect &rc, int nLineIndex, POINT& coords);
404 void ClearCurrentSelection();
405 void AdjustSelection(bool bMoveLeft);
406 bool SelectNextBlock(int nDirection, bool bConflict, bool bSkipEndOfCurrentBlock = true, bool dryrun = false);
408 enum SearchDirection{SearchNext=0, SearchPrevious=1};
409 bool StringFound(const CString& str, SearchDirection srchDir, int& start, int& end) const;
410 bool Search(SearchDirection srchDir, bool useStart, bool flashIfNotFound, bool stopEof);
411 void BuildFindStringArray();
413 void RemoveLine(int nLineIndex);
414 void RemoveSelectedText();
415 void PasteText();
416 void InsertText(const CString& sText);
417 void AddUndoViewLine(int nViewLine, bool bAddEmptyLine = false);
419 bool MoveCaretLeft();
420 bool MoveCaretRight();
421 void MoveCaretWordLeft();
422 void MoveCaretWordRight();
423 void OnCaretMove(bool bMoveLeft);
424 void OnCaretMove(bool bMoveLeft, bool isShiftPressed);
425 void UpdateGoalPos();
427 ECharGroup GetCharGroup(const CString &str, int index) const { return index >= 0 && index < str.GetLength() ? GetCharGroup(str[index]) : CHG_UNKNOWN; }
428 ECharGroup GetCharGroup(const wchar_t zChar) const;
429 bool IsWordSeparator(const wchar_t ch) const;
430 bool IsCaretAtWordBoundary();
431 void UpdateViewsCaretPosition();
432 void BuildMarkedWordArray();
434 virtual void UseBothBlocks(CBaseView * /*pwndFirst*/, CBaseView * /*pwndLast*/) {};
435 virtual void UseViewBlock(CBaseView * /*pwndView*/) {}
436 void UseViewBlock(CBaseView * pwndView, int nFirstViewLine, int nLastViewLine, bool skipMarked = false);
437 virtual void UseViewFile(CBaseView * /*pwndView*/) {}
438 virtual void MarkBlock(bool /*marked*/) {}
439 void MarkBlock(bool marked, int nFirstViewLine, int nLastViewLine);
440 void UseViewFileExceptMarked(CBaseView *pwndView);
442 virtual void AddContextItems(CIconMenu& popup, DiffStates state);
443 void AddCutCopyAndPaste(CIconMenu& popup);
444 void CompensateForKeyboard(CPoint& point);
445 static HICON LoadIcon(WORD iconId);
446 void ReleaseBitmap();
447 static bool LinesInOneChange( int direction, DiffStates firstLineState, DiffStates currentLineState );
448 static void FilterWhitespaces(CString& first, CString& second);
449 static void FilterWhitespaces(CString& line);
450 int GetButtonEventLineIndex(const POINT& point);
452 static void ResetUndoStep();
453 void SaveUndoStep();
454 protected: // variables
455 COLORREF m_InlineRemovedBk;
456 COLORREF m_InlineAddedBk;
457 COLORREF m_ModifiedBk;
458 COLORREF m_WhiteSpaceFg;
459 UINT m_nStatusBarID; ///< The ID of the status bar pane used by this view. Must be set by the parent class.
461 SVNLineDiff m_svnlinediff;
462 DWORD m_nInlineDiffMaxLineLength;
463 BOOL m_bOtherDiffChecked;
464 bool m_bModified;
465 BOOL m_bFocused;
466 BOOL m_bViewLinenumbers;
467 BOOL m_bIsHidden;
468 BOOL m_bIconLFs;
469 int m_nLineHeight;
470 int m_nCharWidth;
471 int m_nMaxLineLength;
472 int m_nScreenLines;
473 int m_nScreenChars;
474 int m_nLastScreenChars;
475 int m_nOffsetChar;
476 int m_nTabSize;
477 int m_nDigits;
478 bool m_bInlineWordDiff;
480 // Block selection attributes
481 int m_nSelViewBlockStart;
482 int m_nSelViewBlockEnd;
484 int m_nMouseLine;
485 bool m_mouseInMargin;
486 HCURSOR m_margincursor;
488 // caret
489 bool m_bReadonly;
490 bool m_bReadonlyIsChangable;
491 bool m_bTarget; ///< view intended as result
492 POINT m_ptCaretViewPos;
493 int m_nCaretGoalPos;
495 // Text selection attributes
496 POINT m_ptSelectionViewPosStart;
497 POINT m_ptSelectionViewPosEnd;
498 POINT m_ptSelectionViewPosOrigin;
500 static const UINT m_FindDialogMessage;
501 CFindDlg * m_pFindDialog;
502 CString m_sFindText;
503 BOOL m_bMatchCase;
504 bool m_bLimitToDiff;
505 bool m_bWholeWord;
508 HICON m_hAddedIcon;
509 HICON m_hRemovedIcon;
510 HICON m_hConflictedIcon;
511 HICON m_hConflictedIgnoredIcon;
512 HICON m_hWhitespaceBlockIcon;
513 HICON m_hEqualIcon;
514 HICON m_hEditedIcon;
516 HICON m_hLineEndingCR;
517 HICON m_hLineEndingCRLF;
518 HICON m_hLineEndingLF;
520 HICON m_hMovedIcon;
521 HICON m_hMarkedIcon;
523 LOGFONT m_lfBaseFont;
524 static const int fontsCount = 4;
525 CFont * m_apFonts[fontsCount];
526 CString m_sConflictedText;
527 CString m_sNoLineNr;
528 CString m_sMarkedWord;
529 CString m_sPreviousMarkedWord;
531 CBitmap * m_pCacheBitmap;
532 CDC * m_pDC;
533 CScrollTool m_ScrollTool;
534 CString m_sWordSeparators;
535 CString m_Eols[EOL__COUNT];
537 UnicodeType m_texttype; ///< the text encoding this view uses
538 EOL m_lineendings; ///< the line endings the view uses
539 bool m_bInsertMode;
541 char m_szTip[MAX_PATH*2+1];
542 wchar_t m_wszTip[MAX_PATH*2+1];
543 // These three pointers lead to the three parent
544 // classes CLeftView, CRightView and CBottomView
545 // and are used for the communication between
546 // the views (e.g. synchronized scrolling, ...)
547 // To find out which parent class this object
548 // is made of just compare e.g. (m_pwndLeft==this).
549 static CBaseView * m_pwndLeft; ///< Pointer to the left view. Must be set by the CLeftView parent class.
550 static CBaseView * m_pwndRight; ///< Pointer to the right view. Must be set by the CRightView parent class.
551 static CBaseView * m_pwndBottom; ///< Pointer to the bottom view. Must be set by the CBottomView parent class.
553 struct TScreenLineInfo
555 int nViewLine;
556 int nViewSubLine;
558 class TScreenedViewLine
560 public:
561 TScreenedViewLine()
563 Clear();
566 void Clear()
568 bSublinesSet = false;
569 eIcon = ICN_UNKNOWN;
570 bLineColorsSet = false;
571 bLineColorsSetWhiteSpace = false;
574 bool bSublinesSet;
575 std::vector<CString> SubLines;
577 enum EIcon
579 ICN_UNKNOWN,
580 ICN_NONE,
581 ICN_EDIT,
582 ICN_SAME,
583 ICN_WHITESPACEDIFF,
584 ICN_ADD,
585 ICN_REMOVED,
586 ICN_MOVED,
587 ICN_MARKED,
588 ICN_CONFLICT,
589 ICN_CONFLICTIGNORED,
590 } eIcon;
592 bool bLineColorsSetWhiteSpace;
593 LineColors lineColorsWhiteSpace;
594 bool bLineColorsSet;
595 LineColors lineColors;
597 std::vector<TScreenedViewLine> m_ScreenedViewLine; ///< cached data for screening
599 static allviewstate m_AllState;
600 viewstate * m_pState;
602 enum PopupCommands
604 POPUPCOMMAND_DISMISSED = 0,
605 // 2-pane view commands
606 POPUPCOMMAND_USELEFTBLOCK,
607 POPUPCOMMAND_USELEFTFILE,
608 POPUPCOMMAND_USEBOTHLEFTFIRST,
609 POPUPCOMMAND_USEBOTHRIGHTFIRST,
610 POPUPCOMMAND_MARKBLOCK,
611 POPUPCOMMAND_UNMARKBLOCK,
612 POPUPCOMMAND_USELEFTFILEEXCEPTMARKED,
613 // multiple writable views
614 POPUPCOMMAND_PREPENDFROMRIGHT,
615 POPUPCOMMAND_REPLACEBYRIGHT,
616 POPUPCOMMAND_APPENDFROMRIGHT,
617 POPUPCOMMAND_USERIGHTFILE,
618 // 3-pane view commands
619 POPUPCOMMAND_USEYOURANDTHEIRBLOCK,
620 POPUPCOMMAND_USETHEIRANDYOURBLOCK,
621 POPUPCOMMAND_USEYOURBLOCK,
622 POPUPCOMMAND_USEYOURFILE,
623 POPUPCOMMAND_USETHEIRBLOCK,
624 POPUPCOMMAND_USETHEIRFILE,
625 // others
626 POPUPCOMMAND_TABTOSPACES,
627 POPUPCOMMAND_SPACESTOTABS,
628 POPUPCOMMAND_REMOVETRAILWHITES,
630 POPUPCOMMAND__LAST,
633 class Screen2View
635 public:
636 Screen2View()
637 : m_pViewData(NULL)
638 {m_bFull=false; }
640 int GetViewLineForScreen(int screenLine);
641 int GetSubLineOffset(int screenLine);
642 TScreenLineInfo GetScreenLineInfo(int screenLine);
643 int FindScreenLineForViewLine(int viewLine);
644 void ScheduleFullRebuild(CViewData * ViewData);
645 void ScheduleRangeRebuild(CViewData * ViewData, int FirstViewLine, int LastViewLine);
646 int size();
648 private:
649 struct TRebuildRange
651 int FirstViewLine;
652 int LastViewLine;
655 bool FixScreenedCacheSize(CBaseView* View);
656 void RebuildIfNecessary();
657 bool ResetScreenedViewLineCache(CBaseView* View) const;
658 bool ResetScreenedViewLineCache(CBaseView* View, const TRebuildRange& Range) const;
660 CViewData * m_pViewData;
661 bool m_bFull;
662 std::vector<TScreenLineInfo> m_Screen2View;
663 std::vector<TRebuildRange> m_RebuildRanges;
666 static Screen2View m_Screen2View;
667 CFileTextLines::SaveParams m_SaveParams; ///< encoding and new line style for saving