2009-04-24 23:35:41 +00:00
|
|
|
// Scintilla source code edit control
|
|
|
|
/** @file CellBuffer.h
|
|
|
|
** Manages the text of the document.
|
|
|
|
**/
|
|
|
|
// Copyright 1998-2004 by Neil Hodgson <neilh@scintilla.org>
|
|
|
|
// The License.txt file describes the conditions under which this software may be distributed.
|
|
|
|
|
|
|
|
#ifndef CELLBUFFER_H
|
|
|
|
#define CELLBUFFER_H
|
|
|
|
|
|
|
|
#ifdef SCI_NAMESPACE
|
|
|
|
namespace Scintilla {
|
|
|
|
#endif
|
|
|
|
|
2009-06-24 19:09:31 +00:00
|
|
|
// Interface to per-line data that wants to see each line insertion and deletion
|
|
|
|
class PerLine {
|
2009-04-24 23:35:41 +00:00
|
|
|
public:
|
2009-06-24 19:09:31 +00:00
|
|
|
virtual ~PerLine() {}
|
2009-08-23 02:24:48 +00:00
|
|
|
virtual void Init()=0;
|
2015-06-07 21:19:26 +00:00
|
|
|
virtual void InsertLine(int line)=0;
|
|
|
|
virtual void RemoveLine(int line)=0;
|
2009-04-24 23:35:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The line vector contains information about each of the lines in a cell buffer.
|
|
|
|
*/
|
|
|
|
class LineVector {
|
|
|
|
|
|
|
|
Partitioning starts;
|
2009-06-24 19:09:31 +00:00
|
|
|
PerLine *perLine;
|
2009-04-24 23:35:41 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
LineVector();
|
|
|
|
~LineVector();
|
|
|
|
void Init();
|
2009-06-24 19:09:31 +00:00
|
|
|
void SetPerLine(PerLine *pl);
|
2009-04-24 23:35:41 +00:00
|
|
|
|
|
|
|
void InsertText(int line, int delta);
|
2010-07-12 22:19:51 +00:00
|
|
|
void InsertLine(int line, int position, bool lineStart);
|
2009-04-24 23:35:41 +00:00
|
|
|
void SetLineStart(int line, int position);
|
|
|
|
void RemoveLine(int line);
|
|
|
|
int Lines() const {
|
|
|
|
return starts.Partitions();
|
|
|
|
}
|
2009-08-23 02:24:48 +00:00
|
|
|
int LineFromPosition(int pos) const;
|
2009-04-24 23:35:41 +00:00
|
|
|
int LineStart(int line) const {
|
|
|
|
return starts.PositionFromPartition(line);
|
|
|
|
}
|
|
|
|
|
|
|
|
int MarkValue(int line);
|
|
|
|
int AddMark(int line, int marker);
|
|
|
|
void MergeMarkers(int pos);
|
|
|
|
void DeleteMark(int line, int markerNum, bool all);
|
|
|
|
void DeleteMarkFromHandle(int markerHandle);
|
|
|
|
int LineFromHandle(int markerHandle);
|
2009-06-24 19:09:31 +00:00
|
|
|
|
|
|
|
void ClearLevels();
|
|
|
|
int SetLevel(int line, int level);
|
|
|
|
int GetLevel(int line);
|
|
|
|
|
|
|
|
int SetLineState(int line, int state);
|
|
|
|
int GetLineState(int line);
|
|
|
|
int GetMaxLineState();
|
|
|
|
|
2009-04-24 23:35:41 +00:00
|
|
|
};
|
|
|
|
|
2009-06-24 19:09:31 +00:00
|
|
|
enum actionType { insertAction, removeAction, startAction, containerAction };
|
2009-04-24 23:35:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Actions are used to store all the information required to perform one undo/redo step.
|
|
|
|
*/
|
|
|
|
class Action {
|
|
|
|
public:
|
|
|
|
actionType at;
|
|
|
|
int position;
|
|
|
|
char *data;
|
|
|
|
int lenData;
|
|
|
|
bool mayCoalesce;
|
|
|
|
|
|
|
|
Action();
|
|
|
|
~Action();
|
2013-08-28 00:44:27 +00:00
|
|
|
void Create(actionType at_, int position_=0, const char *data_=0, int lenData_=0, bool mayCoalesce_=true);
|
2009-04-24 23:35:41 +00:00
|
|
|
void Destroy();
|
|
|
|
void Grab(Action *source);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class UndoHistory {
|
|
|
|
Action *actions;
|
|
|
|
int lenActions;
|
|
|
|
int maxAction;
|
|
|
|
int currentAction;
|
|
|
|
int undoSequenceDepth;
|
|
|
|
int savePoint;
|
2015-06-07 21:19:26 +00:00
|
|
|
int tentativePoint;
|
2009-04-24 23:35:41 +00:00
|
|
|
|
|
|
|
void EnsureUndoRoom();
|
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
// Private so UndoHistory objects can not be copied
|
|
|
|
UndoHistory(const UndoHistory &);
|
|
|
|
|
2009-04-24 23:35:41 +00:00
|
|
|
public:
|
|
|
|
UndoHistory();
|
|
|
|
~UndoHistory();
|
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
const char *AppendAction(actionType at, int position, const char *data, int length, bool &startSequence, bool mayCoalesce=true);
|
2009-04-24 23:35:41 +00:00
|
|
|
|
|
|
|
void BeginUndoAction();
|
|
|
|
void EndUndoAction();
|
|
|
|
void DropUndoSequence();
|
|
|
|
void DeleteUndoHistory();
|
|
|
|
|
|
|
|
/// The save point is a marker in the undo stack where the container has stated that
|
|
|
|
/// the buffer was saved. Undo and redo can move over the save point.
|
|
|
|
void SetSavePoint();
|
|
|
|
bool IsSavePoint() const;
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
// Tentative actions are used for input composition so that it can be undone cleanly
|
|
|
|
void TentativeStart();
|
|
|
|
void TentativeCommit();
|
|
|
|
bool TentativeActive() const { return tentativePoint >= 0; }
|
|
|
|
int TentativeSteps();
|
|
|
|
|
2009-04-24 23:35:41 +00:00
|
|
|
/// To perform an undo, StartUndo is called to retrieve the number of steps, then UndoStep is
|
|
|
|
/// called that many times. Similarly for redo.
|
|
|
|
bool CanUndo() const;
|
|
|
|
int StartUndo();
|
|
|
|
const Action &GetUndoStep() const;
|
|
|
|
void CompletedUndoStep();
|
|
|
|
bool CanRedo() const;
|
|
|
|
int StartRedo();
|
|
|
|
const Action &GetRedoStep() const;
|
|
|
|
void CompletedRedoStep();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Holder for an expandable array of characters that supports undo and line markers.
|
|
|
|
* Based on article "Data Structures in a Bit-Mapped Text Editor"
|
|
|
|
* by Wilfred J. Hansen, Byte January 1987, page 183.
|
|
|
|
*/
|
|
|
|
class CellBuffer {
|
|
|
|
private:
|
|
|
|
SplitVector<char> substance;
|
|
|
|
SplitVector<char> style;
|
|
|
|
bool readOnly;
|
2013-08-28 00:44:27 +00:00
|
|
|
int utf8LineEnds;
|
2009-04-24 23:35:41 +00:00
|
|
|
|
|
|
|
bool collectingUndo;
|
|
|
|
UndoHistory uh;
|
|
|
|
|
|
|
|
LineVector lv;
|
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
bool UTF8LineEndOverlaps(int position) const;
|
|
|
|
void ResetLineEnds();
|
2011-03-22 00:16:49 +00:00
|
|
|
/// Actions without undo
|
|
|
|
void BasicInsertString(int position, const char *s, int insertLength);
|
|
|
|
void BasicDeleteChars(int position, int deleteLength);
|
|
|
|
|
2009-04-24 23:35:41 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
CellBuffer();
|
|
|
|
~CellBuffer();
|
|
|
|
|
|
|
|
/// Retrieving positions outside the range of the buffer works and returns 0
|
|
|
|
char CharAt(int position) const;
|
2010-07-12 22:19:51 +00:00
|
|
|
void GetCharRange(char *buffer, int position, int lengthRetrieve) const;
|
|
|
|
char StyleAt(int position) const;
|
2011-03-22 00:16:49 +00:00
|
|
|
void GetStyleRange(unsigned char *buffer, int position, int lengthRetrieve) const;
|
2009-04-25 23:38:15 +00:00
|
|
|
const char *BufferPointer();
|
2013-08-28 00:44:27 +00:00
|
|
|
const char *RangePointer(int position, int rangeLength);
|
|
|
|
int GapPosition() const;
|
2009-04-24 23:35:41 +00:00
|
|
|
|
|
|
|
int Length() const;
|
|
|
|
void Allocate(int newSize);
|
2013-08-28 00:44:27 +00:00
|
|
|
int GetLineEndTypes() const { return utf8LineEnds; }
|
|
|
|
void SetLineEndTypes(int utf8LineEnds_);
|
2009-06-24 19:09:31 +00:00
|
|
|
void SetPerLine(PerLine *pl);
|
2009-04-24 23:35:41 +00:00
|
|
|
int Lines() const;
|
|
|
|
int LineStart(int line) const;
|
2009-08-23 02:24:48 +00:00
|
|
|
int LineFromPosition(int pos) const { return lv.LineFromPosition(pos); }
|
2010-07-12 22:19:51 +00:00
|
|
|
void InsertLine(int line, int position, bool lineStart);
|
2009-04-24 23:35:41 +00:00
|
|
|
void RemoveLine(int line);
|
|
|
|
const char *InsertString(int position, const char *s, int insertLength, bool &startSequence);
|
|
|
|
|
|
|
|
/// Setting styles for positions outside the range of the buffer is safe and has no effect.
|
|
|
|
/// @return true if the style of a character is changed.
|
2015-06-07 21:19:26 +00:00
|
|
|
bool SetStyleAt(int position, char styleValue);
|
|
|
|
bool SetStyleFor(int position, int length, char styleValue);
|
2009-04-24 23:35:41 +00:00
|
|
|
|
|
|
|
const char *DeleteChars(int position, int deleteLength, bool &startSequence);
|
|
|
|
|
2010-07-12 22:19:51 +00:00
|
|
|
bool IsReadOnly() const;
|
2009-04-24 23:35:41 +00:00
|
|
|
void SetReadOnly(bool set);
|
|
|
|
|
|
|
|
/// The save point is a marker in the undo stack where the container has stated that
|
|
|
|
/// the buffer was saved. Undo and redo can move over the save point.
|
|
|
|
void SetSavePoint();
|
2013-08-28 00:44:27 +00:00
|
|
|
bool IsSavePoint() const;
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
void TentativeStart();
|
|
|
|
void TentativeCommit();
|
|
|
|
bool TentativeActive() const;
|
|
|
|
int TentativeSteps();
|
|
|
|
|
2009-04-24 23:35:41 +00:00
|
|
|
bool SetUndoCollection(bool collectUndo);
|
2010-07-12 22:19:51 +00:00
|
|
|
bool IsCollectingUndo() const;
|
2009-04-24 23:35:41 +00:00
|
|
|
void BeginUndoAction();
|
|
|
|
void EndUndoAction();
|
2009-06-24 19:09:31 +00:00
|
|
|
void AddUndoAction(int token, bool mayCoalesce);
|
2009-04-24 23:35:41 +00:00
|
|
|
void DeleteUndoHistory();
|
|
|
|
|
|
|
|
/// To perform an undo, StartUndo is called to retrieve the number of steps, then UndoStep is
|
|
|
|
/// called that many times. Similarly for redo.
|
2013-08-28 00:44:27 +00:00
|
|
|
bool CanUndo() const;
|
2009-04-24 23:35:41 +00:00
|
|
|
int StartUndo();
|
|
|
|
const Action &GetUndoStep() const;
|
|
|
|
void PerformUndoStep();
|
2013-08-28 00:44:27 +00:00
|
|
|
bool CanRedo() const;
|
2009-04-24 23:35:41 +00:00
|
|
|
int StartRedo();
|
|
|
|
const Action &GetRedoStep() const;
|
|
|
|
void PerformRedoStep();
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef SCI_NAMESPACE
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|