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