1 // Scintilla source code edit control
2 /** @file PerLine.h
3  ** Manages data associated with each line of the document
4  **/
5 // Copyright 1998-2009 by Neil Hodgson <neilh@scintilla.org>
6 // The License.txt file describes the conditions under which this software may be distributed.
7 
8 #ifndef PERLINE_H
9 #define PERLINE_H
10 
11 namespace Scintilla {
12 
13 /**
14  * This holds the marker identifier and the marker type to display.
15  * MarkerHandleNumbers are members of lists.
16  */
17 struct MarkerHandleNumber {
18 	int handle;
19 	int number;
MarkerHandleNumberMarkerHandleNumber20 	MarkerHandleNumber(int handle_, int number_) noexcept : handle(handle_), number(number_) {}
21 };
22 
23 /**
24  * A marker handle set contains any number of MarkerHandleNumbers.
25  */
26 class MarkerHandleSet {
27 	std::forward_list<MarkerHandleNumber> mhList;
28 
29 public:
30 	MarkerHandleSet();
31 	// Deleted so MarkerHandleSet objects can not be copied.
32 	MarkerHandleSet(const MarkerHandleSet &) = delete;
33 	MarkerHandleSet(MarkerHandleSet &&) = delete;
34 	void operator=(const MarkerHandleSet &) = delete;
35 	void operator=(MarkerHandleSet &&) = delete;
36 	~MarkerHandleSet();
37 	bool Empty() const noexcept;
38 	int MarkValue() const noexcept;	///< Bit set of marker numbers.
39 	bool Contains(int handle) const noexcept;
40 	bool InsertHandle(int handle, int markerNum);
41 	void RemoveHandle(int handle);
42 	bool RemoveNumber(int markerNum, bool all);
43 	void CombineWith(MarkerHandleSet *other) noexcept;
44 	MarkerHandleNumber const *GetMarkerHandleNumber(int which) const noexcept;
45 };
46 
47 class LineMarkers : public PerLine {
48 	SplitVector<std::unique_ptr<MarkerHandleSet>> markers;
49 	/// Handles are allocated sequentially and should never have to be reused as 32 bit ints are very big.
50 	int handleCurrent;
51 public:
LineMarkers()52 	LineMarkers() : handleCurrent(0) {
53 	}
54 	// Deleted so LineMarkers objects can not be copied.
55 	LineMarkers(const LineMarkers &) = delete;
56 	LineMarkers(LineMarkers &&) = delete;
57 	void operator=(const LineMarkers &) = delete;
58 	void operator=(LineMarkers &&) = delete;
59 	~LineMarkers() override;
60 	void Init() override;
61 	void InsertLine(Sci::Line line) override;
62 	void InsertLines(Sci::Line line, Sci::Line lines) override;
63 	void RemoveLine(Sci::Line line) override;
64 
65 	int MarkValue(Sci::Line line) const noexcept;
66 	Sci::Line MarkerNext(Sci::Line lineStart, int mask) const noexcept;
67 	int AddMark(Sci::Line line, int markerNum, Sci::Line lines);
68 	void MergeMarkers(Sci::Line line);
69 	bool DeleteMark(Sci::Line line, int markerNum, bool all);
70 	void DeleteMarkFromHandle(int markerHandle);
71 	Sci::Line LineFromHandle(int markerHandle) const noexcept;
72 	int HandleFromLine(Sci::Line line, int which) const noexcept;
73 	int NumberFromLine(Sci::Line line, int which) const noexcept;
74 };
75 
76 class LineLevels : public PerLine {
77 	SplitVector<int> levels;
78 public:
LineLevels()79 	LineLevels() {
80 	}
81 	// Deleted so LineLevels objects can not be copied.
82 	LineLevels(const LineLevels &) = delete;
83 	LineLevels(LineLevels &&) = delete;
84 	void operator=(const LineLevels &) = delete;
85 	void operator=(LineLevels &&) = delete;
86 	~LineLevels() override;
87 	void Init() override;
88 	void InsertLine(Sci::Line line) override;
89 	void InsertLines(Sci::Line line, Sci::Line lines) override;
90 	void RemoveLine(Sci::Line line) override;
91 
92 	void ExpandLevels(Sci::Line sizeNew=-1);
93 	void ClearLevels();
94 	int SetLevel(Sci::Line line, int level, Sci::Line lines);
95 	int GetLevel(Sci::Line line) const noexcept;
96 };
97 
98 class LineState : public PerLine {
99 	SplitVector<int> lineStates;
100 public:
LineState()101 	LineState() {
102 	}
103 	// Deleted so LineState objects can not be copied.
104 	LineState(const LineState &) = delete;
105 	LineState(LineState &&) = delete;
106 	void operator=(const LineState &) = delete;
107 	void operator=(LineState &&) = delete;
108 	~LineState() override;
109 	void Init() override;
110 	void InsertLine(Sci::Line line) override;
111 	void InsertLines(Sci::Line line, Sci::Line lines) override;
112 	void RemoveLine(Sci::Line line) override;
113 
114 	int SetLineState(Sci::Line line, int state);
115 	int GetLineState(Sci::Line line);
116 	Sci::Line GetMaxLineState() const noexcept;
117 };
118 
119 class LineAnnotation : public PerLine {
120 	SplitVector<std::unique_ptr<char []>> annotations;
121 public:
LineAnnotation()122 	LineAnnotation() {
123 	}
124 	// Deleted so LineAnnotation objects can not be copied.
125 	LineAnnotation(const LineAnnotation &) = delete;
126 	LineAnnotation(LineAnnotation &&) = delete;
127 	void operator=(const LineAnnotation &) = delete;
128 	void operator=(LineAnnotation &&) = delete;
129 	~LineAnnotation() override;
130 	void Init() override;
131 	void InsertLine(Sci::Line line) override;
132 	void InsertLines(Sci::Line line, Sci::Line lines) override;
133 	void RemoveLine(Sci::Line line) override;
134 
135 	bool MultipleStyles(Sci::Line line) const noexcept;
136 	int Style(Sci::Line line) const noexcept;
137 	const char *Text(Sci::Line line) const noexcept;
138 	const unsigned char *Styles(Sci::Line line) const noexcept;
139 	void SetText(Sci::Line line, const char *text);
140 	void ClearAll();
141 	void SetStyle(Sci::Line line, int style);
142 	void SetStyles(Sci::Line line, const unsigned char *styles);
143 	int Length(Sci::Line line) const noexcept;
144 	int Lines(Sci::Line line) const noexcept;
145 };
146 
147 typedef std::vector<int> TabstopList;
148 
149 class LineTabstops : public PerLine {
150 	SplitVector<std::unique_ptr<TabstopList>> tabstops;
151 public:
LineTabstops()152 	LineTabstops() {
153 	}
154 	// Deleted so LineTabstops objects can not be copied.
155 	LineTabstops(const LineTabstops &) = delete;
156 	LineTabstops(LineTabstops &&) = delete;
157 	void operator=(const LineTabstops &) = delete;
158 	void operator=(LineTabstops &&) = delete;
159 	~LineTabstops() override;
160 	void Init() override;
161 	void InsertLine(Sci::Line line) override;
162 	void InsertLines(Sci::Line line, Sci::Line lines) override;
163 	void RemoveLine(Sci::Line line) override;
164 
165 	bool ClearTabstops(Sci::Line line) noexcept;
166 	bool AddTabstop(Sci::Line line, int x);
167 	int GetNextTabstop(Sci::Line line, int x) const noexcept;
168 };
169 
170 }
171 
172 #endif
173