2 * @file GhostTextBuffer.h
4 * @brief Declaration of CGhostTextBuffer (subclasses CCrystalTextBuffer to handle ghost lines)
9 #include "ccrystaltextbuffer.h"
12 /////////////////////////////////////////////////////////////////////////////
15 * We use the current ccrystalEditor flags
17 * This flag must be cleared and set in GhostTextBuffer.cpp
18 * and MergeDoc.cpp (Rescan) only.
20 * GetLineColors (in MergeEditView) reads it to choose the line color.
24 LF_GHOST = 0x00400000L, /**< Ghost line. */
27 /////////////////////////////////////////////////////////////////////////////
28 // CCrystalTextBuffer command target
31 * @brief A class handling ghost lines.
32 * Features offered with this class :
34 * <li> apparent/real line conversion
35 * <li> insertText/deleteText working with ghost lines
36 * <li> AddUndoRecord/Undo/Redo working with ghost lines
37 * <li> insertGhostLine function
40 class EDITPADC_CLASS CGhostTextBuffer : public CCrystalTextBuffer
43 DECLARE_DYNCREATE (CGhostTextBuffer)
47 * @brief A struct mapping real lines and apparent (screen) lines.
48 * This struct maps lines between real lines and apparent (screen) lines.
49 * The mapping records for each text block an apparent line and matching
54 int nStartReal; /**< Start line of real block. */
55 int nStartApparent; /**< Start line of apparent block. */
56 int nCount; /**< Lines in the block. */
58 std::vector<RealityBlock> m_RealityBlocks; /**< Mapping of real and apparent lines. */
62 bool InternalInsertGhostLine (CCrystalTextView * pSource, int nLine);
63 bool InternalDeleteGhostLine (CCrystalTextView * pSource, int nLine, int nCount);
65 // Construction/destruction code
69 This should work in base code as ghost lines are real empty lines
70 but maybe it doesn't (if there is an assert to check there is an EOL,
71 or if it adds the default EOL)
73 virtual void GetTextWithoutEmptys (int nStartLine, int nStartChar,
74 int nEndLine, int nEndChar, CString &text,
75 CRLFSTYLE nCrlfStyle =CRLF_STYLE_AUTOMATIC,
76 bool bExcludeInvisibleLines = true);
79 // Text modification functions
80 virtual bool InsertText (CCrystalTextView * pSource, int nLine, int nPos,
81 LPCTSTR pszText, int cchText, int &nEndLine, int &nEndChar,
82 int nAction = CE_ACTION_UNKNOWN, bool bHistory =true);
83 virtual bool DeleteText2 (CCrystalTextView * pSource, int nStartLine,
84 int nStartPos, int nEndLine, int nEndPos,
85 int nAction = CE_ACTION_UNKNOWN, bool bHistory =true);
86 bool InsertGhostLine (CCrystalTextView * pSource, int nLine);
88 virtual void AddUndoRecord (bool bInsert, const CPoint & ptStartPos, const CPoint & ptEndPos,
89 LPCTSTR pszText, int cchText, int nActionType = CE_ACTION_UNKNOWN, CDWordArray *paSavedRevisionNumbers = NULL);
90 virtual UndoRecord GetUndoRecord(int nUndoPos) const;
92 virtual CDWordArray *CopyRevisionNumbers(int nStartLine, int nEndLine) const;
93 virtual void RestoreRevisionNumbers(int nStartLine, CDWordArray *paSavedRevisionNumbers);
98 * @name Real/apparent line number conversion functions.
99 * These functions convert line numbers between file line numbers
100 * (real line numbers) and screen line numbers (apparent line numbers).
102 * This mapping is needed to handle ghost lines (ones with no text or
103 * EOL chars) which WinMerge uses for left-only or right-only lines.
105 int ApparentLastRealLine() const;
106 int ComputeRealLine(int nApparentLine) const;
107 int ComputeApparentLine(int nRealLine) const;
108 /** richer position information yApparent = apparent(yReal) - yGhost */
109 int ComputeRealLineAndGhostAdjustment(int nApparentLine, int& decToReal) const;
110 /** richer position information yApparent = apparent(yReal) - yGhost */
111 int ComputeApparentLine(int nRealLine, int decToReal) const;
114 /** for loading file */
115 void FinishLoading();
116 /** for saving file */
117 void RemoveAllGhostLines();
121 void RecomputeRealityMapping();
122 /** For debugging purpose */
123 void checkFlagsFromReality(bool bFlag) const;
126 virtual void OnNotifyLineHasBeenEdited(int nLine);
131 // ClassWizard generated virtual function overrides
132 //{{AFX_VIRTUAL(CCrystalTextBuffer)
135 // Generated message map functions
136 //{{AFX_MSG(CCrystalTextBuffer)
139 DECLARE_MESSAGE_MAP ()