1 // Scintilla source code edit control
\r
2 /** @file PositionCache.h
\r
3 ** Classes for caching layout information.
\r
5 // Copyright 1998-2007 by Neil Hodgson <neilh@scintilla.org>
\r
6 // The License.txt file describes the conditions under which this software may be distributed.
\r
8 #ifndef POSITIONCACHE_H
\r
9 #define POSITIONCACHE_H
\r
11 #ifdef SCI_NAMESPACE
\r
12 namespace Scintilla {
\r
15 static inline bool IsEOLChar(char ch) {
\r
16 return (ch == '\r') || (ch == '\n');
\r
23 friend class LineLayoutCache;
\r
26 /// Drawing is only performed for @a maxLineLength characters on each line.
\r
30 enum { wrapWidthInfinite = 0x7ffffff };
\r
33 enum validLevel { llInvalid, llCheckTextAndStyle, llPositions, llLines } validity;
\r
34 int xHighlightGuide;
\r
35 bool highlightColumn;
\r
41 unsigned char *styles;
\r
45 char bracePreviousStyles[2];
\r
51 // Wrapped line support
\r
55 LineLayout(int maxLineLength_);
\r
56 virtual ~LineLayout();
\r
57 void Resize(int maxLineLength_);
\r
59 void Invalidate(validLevel validity_);
\r
60 int LineStart(int line) const;
\r
61 int LineLastVisible(int line) const;
\r
62 bool InLine(int offset, int line) const;
\r
63 void SetLineStart(int line, int start);
\r
64 void SetBracesHighlight(Range rangeLine, Position braces[],
\r
65 char bracesMatchStyle, int xHighlight);
\r
66 void RestoreBracesHighlight(Range rangeLine, Position braces[]);
\r
67 int FindBefore(int x, int lower, int upper) const;
\r
72 class LineLayoutCache {
\r
77 bool allInvalidated;
\r
80 void Allocate(int length_);
\r
81 void AllocateForLevel(int linesOnScreen, int linesInDoc);
\r
84 virtual ~LineLayoutCache();
\r
87 llcNone=SC_CACHE_NONE,
\r
88 llcCaret=SC_CACHE_CARET,
\r
89 llcPage=SC_CACHE_PAGE,
\r
90 llcDocument=SC_CACHE_DOCUMENT
\r
92 void Invalidate(LineLayout::validLevel validity_);
\r
93 void SetLevel(int level_);
\r
94 int GetLevel() { return level; }
\r
95 LineLayout *Retrieve(int lineNumber, int lineCaret, int maxChars, int styleClock_,
\r
96 int linesOnScreen, int linesInDoc);
\r
97 void Dispose(LineLayout *ll);
\r
100 class PositionCacheEntry {
\r
101 unsigned int styleNumber:8;
\r
102 unsigned int len:8;
\r
103 unsigned int clock:16;
\r
106 PositionCacheEntry();
\r
107 ~PositionCacheEntry();
\r
108 void Set(unsigned int styleNumber_, const char *s_, unsigned int len_, int *positions_, unsigned int clock);
\r
110 bool Retrieve(unsigned int styleNumber_, const char *s_, unsigned int len_, int *positions_) const;
\r
111 static int Hash(unsigned int styleNumber, const char *s, unsigned int len);
\r
112 bool NewerThan(const PositionCacheEntry &other);
\r
116 // Class to break a line of text into shorter runs at sensible places.
\r
117 class BreakFinder {
\r
118 // If a whole run is longer than lengthStartSubdivision then subdivide
\r
119 // into smaller runs at spaces or punctuation.
\r
120 enum { lengthStartSubdivision = 300 };
\r
121 // Try to make each subdivided run lengthEachSubdivision or shorter.
\r
122 enum { lengthEachSubdivision = 100 };
\r
130 unsigned int saeSize;
\r
131 unsigned int saeLen;
\r
132 unsigned int saeCurrentPos;
\r
135 void Insert(int val);
\r
137 BreakFinder(LineLayout *ll_, int lineStart_, int lineEnd_, int posLineStart_, bool utf8_, int xStart);
\r
143 class PositionCache {
\r
144 PositionCacheEntry *pces;
\r
146 unsigned int clock;
\r
152 void SetSize(size_t size_);
\r
153 int GetSize() { return size; }
\r
154 void MeasureWidths(Surface *surface, ViewStyle &vstyle, unsigned int styleNumber,
\r
155 const char *s, unsigned int len, int *positions);
\r
158 inline bool IsSpaceOrTab(int ch) {
\r
159 return ch == ' ' || ch == '\t';
\r
162 #ifdef SCI_NAMESPACE
\r