2 * @file GhostTextBuffer.h
4 * @brief Declaration of CGhostTextBuffer (subclasses CCrystalTextBuffer to handle ghost lines)
6 // ID line follows -- this is updated by SVN
7 // $Id: GhostTextBuffer.h 5762 2008-08-08 05:32:15Z kimmov $
9 #ifndef __GHOSTTEXTBUFFER_H__
10 #define __GHOSTTEXTBUFFER_H__
13 #include "ccrystaltextbuffer.h"
14 #include "GhostUndoRecord.h"
17 /////////////////////////////////////////////////////////////////////////////
20 * We use the current ccrystalEditor flags
22 * This flag must be cleared and set in GhostTextBuffer.cpp
23 * and MergeDoc.cpp (Rescan) only.
25 * GetLineColors (in MergeEditView) reads it to choose the line color.
29 LF_GHOST = 0x00400000L, /**< Ghost line. */
32 /////////////////////////////////////////////////////////////////////////////
33 // CCrystalTextBuffer command target
36 * @brief A class handling ghost lines.
37 * Features offered with this class :
39 * <li> apparent/real line conversion
40 * <li> insertText/deleteText working with ghost lines
41 * <li> AddUndoRecord/Undo/Redo working with ghost lines
42 * <li> insertGhostLine function
45 class EDITPADC_CLASS CGhostTextBuffer : public CCrystalTextBuffer
48 DECLARE_DYNCREATE (CGhostTextBuffer)
52 // Nested class declarations
56 UNDO_BEGINGROUP = 0x0100
65 We need another array with our richer structure.
67 We share the positions with the CCrystalTextBuffer object.
68 We share m_bUndoGroup, its utility is to check we opened the UndoBeginGroup.
69 We share m_nUndoBufSize which is the max buffer size.
71 std::vector<GhostUndoRecord> m_aUndoBuf;
73 This one must be duplicated because the flag UNDO_BEGINGROUP needs to be set in both
74 CGhostTextBuffer::m_aUndoBuf and CCrystalTextBuffer::m_aUndoBuf CArrays
76 BOOL m_bUndoBeginGroup;
78 // [JRT] Support For Descriptions On Undo/Redo Actions
79 virtual void AddUndoRecord (BOOL bInsert, const CPoint & ptStartPos, const CPoint & ptEndPos,
80 LPCTSTR pszText, int cchText, int nRealLinesChanged, int nActionType = CE_ACTION_UNKNOWN, CDWordArray *paSavedRevisonNumbers = NULL);
84 * @brief A struct mapping real lines and apparent (screen) lines.
85 * This struct maps lines between real lines and apparent (screen) lines.
86 * The mapping records for each text block an apparent line and matching
91 int nStartReal; /**< Start line of real block. */
92 int nStartApparent; /**< Start line of apparent block. */
93 int nCount; /**< Lines in the block. */
95 std::vector<RealityBlock> m_RealityBlocks; /**< Mapping of real and apparent lines. */
99 BOOL InternalInsertGhostLine (CCrystalTextView * pSource, int nLine);
100 BOOL InternalDeleteGhostLine (CCrystalTextView * pSource, int nLine, int nCount);
102 // Construction/destruction code
104 virtual BOOL InitNew (CRLFSTYLE nCrlfStyle = CRLF_STYLE_DOS);
107 This should work in base code as ghost lines are real empty lines
108 but maybe it doesn't (if there is an assert to check there is an EOL,
109 or if it adds the default EOL)
111 virtual void GetTextWithoutEmptys (int nStartLine, int nStartChar,
112 int nEndLine, int nEndChar, CString &text,
113 CRLFSTYLE nCrlfStyle =CRLF_STYLE_AUTOMATIC,
114 BOOL bExcludeInvisibleLines = TRUE);
117 // Text modification functions
118 virtual BOOL InsertText (CCrystalTextView * pSource, int nLine, int nPos,
119 LPCTSTR pszText, int cchText, int &nEndLine, int &nEndChar,
120 int nAction = CE_ACTION_UNKNOWN, BOOL bHistory =TRUE);
121 virtual BOOL DeleteText (CCrystalTextView * pSource, int nStartLine,
122 int nStartPos, int nEndLine, int nEndPos,
123 int nAction = CE_ACTION_UNKNOWN, BOOL bHistory =TRUE, BOOL bExcludeInvisibleLines = TRUE);
124 virtual BOOL DeleteText2 (CCrystalTextView * pSource, int nStartLine,
125 int nStartPos, int nEndLine, int nEndPos,
126 int nAction = CE_ACTION_UNKNOWN, BOOL bHistory =TRUE);
127 BOOL InsertGhostLine (CCrystalTextView * pSource, int nLine);
130 virtual BOOL Undo (CCrystalTextView * pSource, CPoint & ptCursorPos);
131 virtual BOOL Redo (CCrystalTextView * pSource, CPoint & ptCursorPos);
134 virtual void BeginUndoGroup (BOOL bMergeWithPrevious = FALSE);
135 virtual void FlushUndoGroup (CCrystalTextView * pSource);
140 * @name Real/apparent line number conversion functions.
141 * These functions convert line numbers between file line numbers
142 * (real line numbers) and screen line numbers (apparent line numbers).
144 * This mapping is needed to handle ghost lines (ones with no text or
145 * EOL chars) which WinMerge uses for left-only or right-only lines.
147 int ApparentLastRealLine() const;
148 int ComputeRealLine(int nApparentLine) const;
149 int ComputeApparentLine(int nRealLine) const;
150 /** richer position information yApparent = apparent(yReal) - yGhost */
151 int ComputeRealLineAndGhostAdjustment(int nApparentLine, int& decToReal) const;
152 /** richer position information yApparent = apparent(yReal) - yGhost */
153 int ComputeApparentLine(int nRealLine, int decToReal) const;
156 /** for loading file */
157 void FinishLoading();
158 /** for saving file */
159 void RemoveAllGhostLines();
163 void RecomputeRealityMapping();
165 Code to set EOL, if the status ghost/real of the line changes
167 We should call a CCrystalTextBuffer function to add the correct EOL
168 (if CCrystalTextBuffer keeps the default EOL for the file)
170 void RecomputeEOL(CCrystalTextView * pSource, int nStartLine, int nEndLine);
171 /** For debugging purpose */
172 void checkFlagsFromReality(BOOL bFlag) const;
175 virtual void OnNotifyLineHasBeenEdited(int nLine);
180 // ClassWizard generated virtual function overrides
181 //{{AFX_VIRTUAL(CCrystalTextBuffer)
184 // Generated message map functions
185 //{{AFX_MSG(CCrystalTextBuffer)
188 DECLARE_MESSAGE_MAP ()
191 /////////////////////////////////////////////////////////////////////////////
193 //{{AFX_INSERT_LOCATION}}
194 // Microsoft Developer Studio will insert additional declarations immediately before the previous line.
197 #endif //__GHOSTTEXTBUFFER_H__