1 // Scintilla source code edit control
3 ** Manages the text of the document.
5 // Copyright 1998-2004 by Neil Hodgson <neilh@scintilla.org>
6 // The License.txt file describes the conditions under which this software may be distributed.
15 // Interface to per-line data that wants to see each line insertion and deletion
19 virtual void Init()=0;
20 virtual void InsertLine(int line
)=0;
21 virtual void RemoveLine(int line
)=0;
25 * The line vector contains information about each of the lines in a cell buffer.
37 void SetPerLine(PerLine
*pl
);
39 void InsertText(int line
, int delta
);
40 void InsertLine(int line
, int position
, bool lineStart
);
41 void SetLineStart(int line
, int position
);
42 void RemoveLine(int line
);
44 return starts
.Partitions();
46 int LineFromPosition(int pos
) const;
47 int LineStart(int line
) const {
48 return starts
.PositionFromPartition(line
);
51 int MarkValue(int line
);
52 int AddMark(int line
, int marker
);
53 void MergeMarkers(int pos
);
54 void DeleteMark(int line
, int markerNum
, bool all
);
55 void DeleteMarkFromHandle(int markerHandle
);
56 int LineFromHandle(int markerHandle
);
59 int SetLevel(int line
, int level
);
60 int GetLevel(int line
);
62 int SetLineState(int line
, int state
);
63 int GetLineState(int line
);
64 int GetMaxLineState();
68 enum actionType
{ insertAction
, removeAction
, startAction
, containerAction
};
71 * Actions are used to store all the information required to perform one undo/redo step.
83 void Create(actionType at_
, int position_
=0, const char *data_
=0, int lenData_
=0, bool mayCoalesce_
=true);
85 void Grab(Action
*source
);
96 int undoSequenceDepth
;
100 void EnsureUndoRoom();
102 // Private so UndoHistory objects can not be copied
103 UndoHistory(const UndoHistory
&);
109 const char *AppendAction(actionType at
, int position
, const char *data
, int length
, bool &startSequence
, bool mayCoalesce
=true);
111 void BeginUndoAction();
112 void EndUndoAction();
113 void DropUndoSequence();
114 void DeleteUndoHistory();
116 /// The save point is a marker in the undo stack where the container has stated that
117 /// the buffer was saved. Undo and redo can move over the save point.
119 bool IsSavePoint() const;
121 // Tentative actions are used for input composition so that it can be undone cleanly
122 void TentativeStart();
123 void TentativeCommit();
124 bool TentativeActive() const { return tentativePoint
>= 0; }
125 int TentativeSteps();
127 /// To perform an undo, StartUndo is called to retrieve the number of steps, then UndoStep is
128 /// called that many times. Similarly for redo.
129 bool CanUndo() const;
131 const Action
&GetUndoStep() const;
132 void CompletedUndoStep();
133 bool CanRedo() const;
135 const Action
&GetRedoStep() const;
136 void CompletedRedoStep();
140 * Holder for an expandable array of characters that supports undo and line markers.
141 * Based on article "Data Structures in a Bit-Mapped Text Editor"
142 * by Wilfred J. Hansen, Byte January 1987, page 183.
146 SplitVector
<char> substance
;
147 SplitVector
<char> style
;
156 bool UTF8LineEndOverlaps(int position
) const;
157 void ResetLineEnds();
158 /// Actions without undo
159 void BasicInsertString(int position
, const char *s
, int insertLength
);
160 void BasicDeleteChars(int position
, int deleteLength
);
167 /// Retrieving positions outside the range of the buffer works and returns 0
168 char CharAt(int position
) const;
169 void GetCharRange(char *buffer
, int position
, int lengthRetrieve
) const;
170 char StyleAt(int position
) const;
171 void GetStyleRange(unsigned char *buffer
, int position
, int lengthRetrieve
) const;
172 const char *BufferPointer();
173 const char *RangePointer(int position
, int rangeLength
);
174 int GapPosition() const;
177 void Allocate(int newSize
);
178 int GetLineEndTypes() const { return utf8LineEnds
; }
179 void SetLineEndTypes(int utf8LineEnds_
);
180 bool ContainsLineEnd(const char *s
, int length
) const;
181 void SetPerLine(PerLine
*pl
);
183 int LineStart(int line
) const;
184 int LineFromPosition(int pos
) const { return lv
.LineFromPosition(pos
); }
185 void InsertLine(int line
, int position
, bool lineStart
);
186 void RemoveLine(int line
);
187 const char *InsertString(int position
, const char *s
, int insertLength
, bool &startSequence
);
189 /// Setting styles for positions outside the range of the buffer is safe and has no effect.
190 /// @return true if the style of a character is changed.
191 bool SetStyleAt(int position
, char styleValue
);
192 bool SetStyleFor(int position
, int length
, char styleValue
);
194 const char *DeleteChars(int position
, int deleteLength
, bool &startSequence
);
196 bool IsReadOnly() const;
197 void SetReadOnly(bool set
);
199 /// The save point is a marker in the undo stack where the container has stated that
200 /// the buffer was saved. Undo and redo can move over the save point.
202 bool IsSavePoint() const;
204 void TentativeStart();
205 void TentativeCommit();
206 bool TentativeActive() const;
207 int TentativeSteps();
209 bool SetUndoCollection(bool collectUndo
);
210 bool IsCollectingUndo() const;
211 void BeginUndoAction();
212 void EndUndoAction();
213 void AddUndoAction(int token
, bool mayCoalesce
);
214 void DeleteUndoHistory();
216 /// To perform an undo, StartUndo is called to retrieve the number of steps, then UndoStep is
217 /// called that many times. Similarly for redo.
218 bool CanUndo() const;
220 const Action
&GetUndoStep() const;
221 void PerformUndoStep();
222 bool CanRedo() const;
224 const Action
&GetRedoStep() const;
225 void PerformRedoStep();