geany  1.38
About: Geany is a text editor (using GTK2) with basic features of an integrated development environment (syntax highlighting, code folding, symbol name auto-completion, ...). F: office T: editor programming GTK+ IDE
  Fossies Dox: geany-1.38.tar.bz2  ("unofficial" and yet experimental doxygen-generated source code documentation)  

PositionCache.h
Go to the documentation of this file.
1// Scintilla source code edit control
2/** @file PositionCache.h
3 ** Classes for caching layout information.
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 POSITIONCACHE_H
9#define POSITIONCACHE_H
10
11namespace Scintilla {
12
13inline constexpr bool IsEOLChar(int ch) noexcept {
14 return (ch == '\r') || (ch == '\n');
15}
16
17inline constexpr bool IsSpaceOrTab(int ch) noexcept {
18 return ch == ' ' || ch == '\t';
19}
20
21/**
22* A point in document space.
23* Uses double for sufficient resolution in large (>20,000,000 line) documents.
24*/
26public:
27 double x;
28 double y;
29
30 explicit PointDocument(double x_ = 0, double y_ = 0) noexcept : x(x_), y(y_) {
31 }
32
33 // Conversion from Point.
34 explicit PointDocument(Point pt) noexcept : x(pt.x), y(pt.y) {
35 }
36};
37
38// There are two points for some positions and this enumeration
39// can choose between the end of the first line or subline
40// and the start of the next line or subline.
42 peDefault = 0x0,
43 peLineEnd = 0x1,
44 peSubLineEnd = 0x2
45};
46
47/**
48 */
50private:
51 friend class LineLayoutCache;
52 std::unique_ptr<int []>lineStarts;
54 /// Drawing is only performed for @a maxLineLength characters on each line.
56 bool inCache;
57public:
58 enum { wrapWidthInfinite = 0x7ffffff };
59
68 std::unique_ptr<char[]> chars;
69 std::unique_ptr<unsigned char[]> styles;
70 std::unique_ptr<XYPOSITION[]> positions;
72
73 // Hotspot support
75
76 // Wrapped line support
78 int lines;
79 XYPOSITION wrapIndent; // In pixels
80
81 explicit LineLayout(int maxLineLength_);
82 // Deleted so LineLayout objects can not be copied.
83 LineLayout(const LineLayout &) = delete;
84 LineLayout(LineLayout &&) = delete;
85 void operator=(const LineLayout &) = delete;
86 void operator=(LineLayout &&) = delete;
87 virtual ~LineLayout();
88 void Resize(int maxLineLength_);
89 void Free() noexcept;
90 void Invalidate(ValidLevel validity_) noexcept;
91 int LineStart(int line) const noexcept;
92 int LineLength(int line) const noexcept;
93 enum class Scope { visibleOnly, includeEnd };
94 int LineLastVisible(int line, Scope scope) const noexcept;
95 Range SubLineRange(int subLine, Scope scope) const noexcept;
96 bool InLine(int offset, int line) const noexcept;
97 void SetLineStart(int line, int start);
98 void SetBracesHighlight(Range rangeLine, const Sci::Position braces[],
99 char bracesMatchStyle, int xHighlight, bool ignoreStyle);
100 void RestoreBracesHighlight(Range rangeLine, const Sci::Position braces[], bool ignoreStyle);
101 int FindBefore(XYPOSITION x, Range range) const noexcept;
102 int FindPositionFromX(XYPOSITION x, Range range, bool charPosition) const noexcept;
103 Point PointFromPosition(int posInLine, int lineHeight, PointEnd pe) const noexcept;
104 int EndLineStyle() const noexcept;
105};
106
107/**
108 */
110 int level;
111 std::vector<std::unique_ptr<LineLayout>>cache;
115 void Allocate(size_t length_);
116 void AllocateForLevel(Sci::Line linesOnScreen, Sci::Line linesInDoc);
117public:
119 // Deleted so LineLayoutCache objects can not be copied.
122 void operator=(const LineLayoutCache &) = delete;
123 void operator=(LineLayoutCache &&) = delete;
124 virtual ~LineLayoutCache();
125 void Deallocate() noexcept;
126 enum {
130 llcDocument=SC_CACHE_DOCUMENT
131 };
132 void Invalidate(LineLayout::ValidLevel validity_) noexcept;
133 void SetLevel(int level_) noexcept;
134 int GetLevel() const noexcept { return level; }
135 LineLayout *Retrieve(Sci::Line lineNumber, Sci::Line lineCaret, int maxChars, int styleClock_,
136 Sci::Line linesOnScreen, Sci::Line linesInDoc);
137 void Dispose(LineLayout *ll) noexcept;
138};
139
141 unsigned int styleNumber:8;
142 unsigned int len:8;
143 unsigned int clock:16;
144 std::unique_ptr<XYPOSITION []> positions;
145public:
146 PositionCacheEntry() noexcept;
147 // Copy constructor not currently used, but needed for being element in std::vector.
149 // PositionCacheEntry objects should not be moved but MSVC 2015 requires this.
151 void operator=(const PositionCacheEntry &) = delete;
152 void operator=(PositionCacheEntry &&) = delete;
154 void Set(unsigned int styleNumber_, const char *s_, unsigned int len_, const XYPOSITION *positions_, unsigned int clock_);
155 void Clear() noexcept;
156 bool Retrieve(unsigned int styleNumber_, const char *s_, unsigned int len_, XYPOSITION *positions_) const noexcept;
157 static unsigned int Hash(unsigned int styleNumber_, const char *s, unsigned int len_) noexcept;
158 bool NewerThan(const PositionCacheEntry &other) const noexcept;
159 void ResetClock() noexcept;
160};
161
163public:
164 std::string stringRep;
165 explicit Representation(const char *value="") : stringRep(value) {
166 }
167};
168
169typedef std::map<unsigned int, Representation> MapRepresentation;
170
173 short startByteHasReprs[0x100];
174public:
176 void SetRepresentation(const char *charBytes, const char *value);
177 void ClearRepresentation(const char *charBytes);
178 const Representation *RepresentationFromCharacter(const char *charBytes, size_t len) const;
179 bool Contains(const char *charBytes, size_t len) const;
180 void Clear();
181};
182
184 int start;
187 TextSegment(int start_=0, int length_=0, const Representation *representation_=nullptr) noexcept :
188 start(start_), length(length_), representation(representation_) {
189 }
190 int end() const noexcept {
191 return start + length;
192 }
193};
194
195// Class to break a line of text into shorter runs at sensible places.
201 std::vector<int> selAndEdge;
202 unsigned int saeCurrentPos;
208 void Insert(Sci::Position val);
209public:
210 // If a whole run is longer than lengthStartSubdivision then subdivide
211 // into smaller runs at spaces or punctuation.
212 enum { lengthStartSubdivision = 300 };
213 // Try to make each subdivided run lengthEachSubdivision or shorter.
214 enum { lengthEachSubdivision = 100 };
215 BreakFinder(const LineLayout *ll_, const Selection *psel, Range lineRange_, Sci::Position posLineStart_,
216 int xStart, bool breakForSelection, const Document *pdoc_, const SpecialRepresentations *preprs_, const ViewStyle *pvsDraw);
217 // Deleted so BreakFinder objects can not be copied.
218 BreakFinder(const BreakFinder &) = delete;
220 void operator=(const BreakFinder &) = delete;
221 void operator=(BreakFinder &&) = delete;
222 ~BreakFinder();
223 TextSegment Next();
224 bool More() const noexcept;
225};
226
228 std::vector<PositionCacheEntry> pces;
229 unsigned int clock;
231public:
233 // Deleted so PositionCache objects can not be copied.
234 PositionCache(const PositionCache &) = delete;
236 void operator=(const PositionCache &) = delete;
237 void operator=(PositionCache &&) = delete;
239 void Clear() noexcept;
240 void SetSize(size_t size_);
241 size_t GetSize() const noexcept { return pces.size(); }
242 void MeasureWidths(Surface *surface, const ViewStyle &vstyle, unsigned int styleNumber,
243 const char *s, unsigned int len, XYPOSITION *positions, const Document *pdoc);
244};
245
246}
247
248#endif
#define SC_CACHE_CARET
Definition: Scintilla.h:580
#define SC_CACHE_NONE
Definition: Scintilla.h:579
#define SC_CACHE_DOCUMENT
Definition: Scintilla.h:582
#define SC_CACHE_PAGE
Definition: Scintilla.h:581
const LineLayout * ll
Sci::Position posLineStart
EncodingFamily encodingFamily
unsigned int saeCurrentPos
BreakFinder(const BreakFinder &)=delete
void operator=(BreakFinder &&)=delete
BreakFinder(BreakFinder &&)=delete
const Document * pdoc
std::vector< int > selAndEdge
const SpecialRepresentations * preprs
void operator=(const BreakFinder &)=delete
void operator=(const LineLayoutCache &)=delete
LineLayoutCache(const LineLayoutCache &)=delete
LineLayoutCache(LineLayoutCache &&)=delete
int GetLevel() const noexcept
std::vector< std::unique_ptr< LineLayout > > cache
void operator=(LineLayoutCache &&)=delete
int LineLastVisible(int line, Scope scope) const noexcept
LineLayout(const LineLayout &)=delete
int FindPositionFromX(XYPOSITION x, Range range, bool charPosition) const noexcept
std::unique_ptr< int[]> lineStarts
Definition: PositionCache.h:52
void operator=(const LineLayout &)=delete
int FindBefore(XYPOSITION x, Range range) const noexcept
int LineLength(int line) const noexcept
void operator=(LineLayout &&)=delete
int LineStart(int line) const noexcept
void Resize(int maxLineLength_)
Range SubLineRange(int subLine, Scope scope) const noexcept
std::unique_ptr< char[]> chars
Definition: PositionCache.h:68
LineLayout(LineLayout &&)=delete
void SetBracesHighlight(Range rangeLine, const Sci::Position braces[], char bracesMatchStyle, int xHighlight, bool ignoreStyle)
enum Scintilla::LineLayout::ValidLevel validity
std::unique_ptr< XYPOSITION[]> positions
Definition: PositionCache.h:70
friend class LineLayoutCache
Definition: PositionCache.h:51
int EndLineStyle() const noexcept
std::unique_ptr< unsigned char[]> styles
Definition: PositionCache.h:69
Sci::Line lineNumber
Drawing is only performed for maxLineLength characters on each line.
Definition: PositionCache.h:55
bool InLine(int offset, int line) const noexcept
LineLayout(int maxLineLength_)
void SetLineStart(int line, int start)
void Invalidate(ValidLevel validity_) noexcept
Point PointFromPosition(int posInLine, int lineHeight, PointEnd pe) const noexcept
void RestoreBracesHighlight(Range rangeLine, const Sci::Position braces[], bool ignoreStyle)
void Free() noexcept
A point in document space.
Definition: PositionCache.h:25
PointDocument(Point pt) noexcept
Definition: PositionCache.h:34
PointDocument(double x_=0, double y_=0) noexcept
Definition: PositionCache.h:30
A geometric point class.
Definition: Platform.h:99
std::unique_ptr< XYPOSITION[]> positions
void operator=(const PositionCache &)=delete
std::vector< PositionCacheEntry > pces
void operator=(PositionCache &&)=delete
PositionCache(const PositionCache &)=delete
PositionCache(PositionCache &&)=delete
The range class represents a range of text in a document.
Definition: Document.h:29
Representation(const char *value="")
A surface abstracts a place to draw.
Definition: Platform.h:340
default
Definition: filetypes.c:4
vString * line
Definition: geany_cobol.c:133
static vString * scope
Definition: geany_go.c:78
ptrdiff_t Position
Definition: Position.h:19
ptrdiff_t Line
Definition: Position.h:20
Styling buffer using one element for each run rather than using a filled buffer.
Definition: Converter.h:9
constexpr bool IsEOLChar(int ch) noexcept
Definition: PositionCache.h:13
float XYPOSITION
Definition: Platform.h:81
constexpr bool IsSpaceOrTab(int ch) noexcept
Definition: PositionCache.h:17
EncodingFamily
Definition: Document.h:21
std::map< unsigned int, Representation > MapRepresentation
const Representation * representation
TextSegment(int start_=0, int length_=0, const Representation *representation_=nullptr) noexcept
int end() const noexcept