OSDN Git Service

crystaledit: Use GetProfile*()/WriteProfile*() to read and write the registry wheneve...
[winmerge-jp/winmerge-jp.git] / Src / GhostTextBuffer.h
1 /**
2  * @file  GhostTextBuffer.h
3  *
4  * @brief Declaration of CGhostTextBuffer (subclasses CCrystalTextBuffer to handle ghost lines)
5  */
6 #pragma once
7
8 #include <vector>
9 #include "ccrystaltextbuffer.h"
10
11
12 /////////////////////////////////////////////////////////////////////////////
13
14 /**
15  * We use the current ccrystalEditor flags 
16  *
17  * This flag must be cleared and set in GhostTextBuffer.cpp 
18  * and MergeDoc.cpp (Rescan) only.
19  *
20  * GetLineColors (in MergeEditView) reads it to choose the line color.
21  */
22 enum GHOST_LINEFLAGS
23 {
24         LF_GHOST = 0x00400000UL, /**< Ghost line. */
25 };
26
27 /////////////////////////////////////////////////////////////////////////////
28 // CCrystalTextBuffer command target
29
30 /**
31  * @brief A class handling ghost lines.
32  * Features offered with this class : 
33  * <ul>
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 
38  * </ul>
39  */
40 class EDITPADC_CLASS CGhostTextBuffer : public CCrystalTextBuffer
41 {
42 public:
43         DECLARE_DYNCREATE (CGhostTextBuffer)
44
45 private:
46         /**
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
50          * real line.
51          */
52         struct RealityBlock
53         {
54                 int nStartReal; /**< Start line of real block. */
55                 int nStartApparent; /**< Start line of apparent block. */
56                 int nCount; /**< Lines in the block. */
57         };
58         std::vector<RealityBlock> m_RealityBlocks; /**< Mapping of real and apparent lines. */
59
60         // Operations
61 private:
62 #if 0
63         bool InternalInsertGhostLine (CCrystalTextView * pSource, int nLine);
64 #endif
65         bool InternalDeleteGhostLine (CCrystalTextView * pSource, int nLine, int nCount);
66 public :
67         // Construction/destruction code
68         CGhostTextBuffer ();
69
70         /** 
71         This should work in base code as ghost lines are real empty lines
72         but maybe it doesn't (if there is an assert to check there is an EOL,
73         or if it adds the default EOL)
74         */
75         virtual void GetTextWithoutEmptys (int nStartLine, int nStartChar,
76                         int nEndLine, int nEndChar, CString &text,
77                         CRLFSTYLE nCrlfStyle =CRLFSTYLE::AUTOMATIC,
78                         bool bExcludeInvisibleLines = true) const override;
79
80         virtual bool IsIndentableLine(int nLine) const override { return (GetLineFlags(nLine) & LF_GHOST) == 0; }
81
82         // Text modification functions
83         virtual bool InsertText (CCrystalTextView * pSource, int nLine, int nPos,
84                 LPCTSTR pszText, size_t cchText, int &nEndLine, int &nEndChar,
85                 int nAction = CE_ACTION_UNKNOWN, bool bHistory =true) override;
86         virtual bool DeleteText2 (CCrystalTextView * pSource, int nStartLine,
87                 int nStartPos, int nEndLine, int nEndPos,
88                 int nAction = CE_ACTION_UNKNOWN, bool bHistory =true) override;
89 #if 0
90         bool InsertGhostLine (CCrystalTextView * pSource, int nLine);
91 #endif
92
93         virtual void AddUndoRecord (bool bInsert, const CPoint & ptStartPos, const CPoint & ptEndPos,
94                                     LPCTSTR pszText, size_t cchText, int nActionType = CE_ACTION_UNKNOWN, CDWordArray *paSavedRevisionNumbers = nullptr) override;
95         virtual UndoRecord GetUndoRecord(int nUndoPos) const override;
96         virtual bool UndoInsert(CCrystalTextView * pSource, CPoint & ptCursorPos,
97                                                         const CPoint apparent_ptStartPos, CPoint const apparent_ptEndPos, const UndoRecord & ur) override;
98
99         virtual CDWordArray *CopyRevisionNumbers(int nStartLine, int nEndLine) const override;
100         virtual void RestoreRevisionNumbers(int nStartLine, CDWordArray *paSavedRevisionNumbers) override;
101
102 public:
103         //@{
104         /**
105          * @name Real/apparent line number conversion functions.
106          * These functions convert line numbers between file line numbers
107          * (real line numbers) and screen line numbers (apparent line numbers).
108          *
109          * This mapping is needed to handle ghost lines (ones with no text or
110          * EOL chars) which WinMerge uses for left-only or right-only lines.
111         */
112         int ApparentLastRealLine() const;
113         int ComputeRealLine(int nApparentLine) const;
114         int ComputeApparentLine(int nRealLine) const;
115         /** richer position information   yApparent = apparent(yReal) - yGhost */
116         int ComputeRealLineAndGhostAdjustment(int nApparentLine, int& decToReal) const;
117         /** richer position information   yApparent = apparent(yReal) - yGhost */
118         int ComputeApparentLine(int nRealLine, int decToReal) const;
119         //@}
120
121         /** for loading file */
122         void FinishLoading();
123         /** for saving file */ 
124         void RemoveAllGhostLines();
125
126
127 private:
128         void RecomputeRealityMapping();
129         void CountEolAndLastLineLength(const CPoint& ptStartPos, LPCTSTR pszText, size_t cchText, int& nLastLineLength, int& nEol);
130         /** For debugging purpose */
131         void checkFlagsFromReality() const;
132
133 protected:
134         virtual void OnNotifyLineHasBeenEdited(int nLine);
135
136
137 protected:
138         // Overrides
139         // ClassWizard generated virtual function overrides
140         //{{AFX_VIRTUAL(CCrystalTextBuffer)
141         //}}AFX_VIRTUAL
142
143         // Generated message map functions
144         //{{AFX_MSG(CCrystalTextBuffer)
145         //}}AFX_MSG
146
147         DECLARE_MESSAGE_MAP ()
148 };