]> git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/PositionCache.h
Update Scintilla to version 1.75
[wxWidgets.git] / src / stc / scintilla / src / PositionCache.h
1 // Scintilla source code edit control
2 /** @file PositionCache.h
3 ** Classes for caching layout information.
4 **/
5 // Copyright 1998-2007 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
11 #ifdef SCI_NAMESPACE
12 namespace Scintilla {
13 #endif
14
15 static inline bool IsEOLChar(char ch) {
16 return (ch == '\r') || (ch == '\n');
17 }
18
19 /**
20 */
21 class LineLayout {
22 private:
23 friend class LineLayoutCache;
24 int *lineStarts;
25 int lenLineStarts;
26 /// Drawing is only performed for @a maxLineLength characters on each line.
27 int lineNumber;
28 bool inCache;
29 public:
30 enum { wrapWidthInfinite = 0x7ffffff };
31 int maxLineLength;
32 int numCharsInLine;
33 enum validLevel { llInvalid, llCheckTextAndStyle, llPositions, llLines } validity;
34 int xHighlightGuide;
35 bool highlightColumn;
36 int selStart;
37 int selEnd;
38 bool containsCaret;
39 int edgeColumn;
40 char *chars;
41 unsigned char *styles;
42 int styleBitsSet;
43 char *indicators;
44 int *positions;
45 char bracePreviousStyles[2];
46
47 // Hotspot support
48 int hsStart;
49 int hsEnd;
50
51 // Wrapped line support
52 int widthLine;
53 int lines;
54
55 LineLayout(int maxLineLength_);
56 virtual ~LineLayout();
57 void Resize(int maxLineLength_);
58 void Free();
59 void Invalidate(validLevel validity_);
60 int LineStart(int line) const;
61 int LineLastVisible(int line) const;
62 bool InLine(int offset, int line) const;
63 void SetLineStart(int line, int start);
64 void SetBracesHighlight(Range rangeLine, Position braces[],
65 char bracesMatchStyle, int xHighlight);
66 void RestoreBracesHighlight(Range rangeLine, Position braces[]);
67 int FindBefore(int x, int lower, int upper) const;
68 };
69
70 /**
71 */
72 class LineLayoutCache {
73 int level;
74 int length;
75 int size;
76 LineLayout **cache;
77 bool allInvalidated;
78 int styleClock;
79 int useCount;
80 void Allocate(int length_);
81 void AllocateForLevel(int linesOnScreen, int linesInDoc);
82 public:
83 LineLayoutCache();
84 virtual ~LineLayoutCache();
85 void Deallocate();
86 enum {
87 llcNone=SC_CACHE_NONE,
88 llcCaret=SC_CACHE_CARET,
89 llcPage=SC_CACHE_PAGE,
90 llcDocument=SC_CACHE_DOCUMENT
91 };
92 void Invalidate(LineLayout::validLevel validity_);
93 void SetLevel(int level_);
94 int GetLevel() { return level; }
95 LineLayout *Retrieve(int lineNumber, int lineCaret, int maxChars, int styleClock_,
96 int linesOnScreen, int linesInDoc);
97 void Dispose(LineLayout *ll);
98 };
99
100 class PositionCacheEntry {
101 unsigned int styleNumber:8;
102 unsigned int len:8;
103 unsigned int clock:16;
104 short *positions;
105 public:
106 PositionCacheEntry();
107 ~PositionCacheEntry();
108 void Set(unsigned int styleNumber_, const char *s_, unsigned int len_, int *positions_, unsigned int clock);
109 void Clear();
110 bool Retrieve(unsigned int styleNumber_, const char *s_, unsigned int len_, int *positions_) const;
111 static int Hash(unsigned int styleNumber, const char *s, unsigned int len);
112 bool NewerThan(const PositionCacheEntry &other);
113 void ResetClock();
114 };
115
116 // Class to break a line of text into shorter runs at sensible places.
117 class BreakFinder {
118 // If a whole run is longer than lengthStartSubdivision then subdivide
119 // into smaller runs at spaces or punctuation.
120 enum { lengthStartSubdivision = 300 };
121 // Try to make each subdivided run lengthEachSubdivision or shorter.
122 enum { lengthEachSubdivision = 100 };
123 LineLayout *ll;
124 int lineStart;
125 int lineEnd;
126 int posLineStart;
127 bool utf8;
128 int nextBreak;
129 int *selAndEdge;
130 unsigned int saeSize;
131 unsigned int saeLen;
132 unsigned int saeCurrentPos;
133 int saeNext;
134 int subBreak;
135 void Insert(int val);
136 public:
137 BreakFinder(LineLayout *ll_, int lineStart_, int lineEnd_, int posLineStart_, bool utf8_, int xStart);
138 ~BreakFinder();
139 int First();
140 int Next();
141 };
142
143 class PositionCache {
144 PositionCacheEntry *pces;
145 size_t size;
146 unsigned int clock;
147 bool allClear;
148 public:
149 PositionCache();
150 ~PositionCache();
151 void Clear();
152 void SetSize(size_t size_);
153 int GetSize() { return size; }
154 void MeasureWidths(Surface *surface, ViewStyle &vstyle, unsigned int styleNumber,
155 const char *s, unsigned int len, int *positions);
156 };
157
158 inline bool IsSpaceOrTab(int ch) {
159 return ch == ' ' || ch == '\t';
160 }
161
162 #ifdef SCI_NAMESPACE
163 }
164 #endif
165
166 #endif