OSDN Git Service

Merge X64 Build
[tortoisegit/TortoiseGitJp.git] / ext / scintilla / src / PositionCache.h
1 // Scintilla source code edit control\r
2 /** @file PositionCache.h\r
3  ** Classes for caching layout information.\r
4  **/\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
7 \r
8 #ifndef POSITIONCACHE_H\r
9 #define POSITIONCACHE_H\r
10 \r
11 #ifdef SCI_NAMESPACE\r
12 namespace Scintilla {\r
13 #endif\r
14 \r
15 static inline bool IsEOLChar(char ch) {\r
16         return (ch == '\r') || (ch == '\n');\r
17 }\r
18 \r
19 /**\r
20  */\r
21 class LineLayout {\r
22 private:\r
23         friend class LineLayoutCache;\r
24         int *lineStarts;\r
25         int lenLineStarts;\r
26         /// Drawing is only performed for @a maxLineLength characters on each line.\r
27         int lineNumber;\r
28         bool inCache;\r
29 public:\r
30         enum { wrapWidthInfinite = 0x7ffffff };\r
31         int maxLineLength;\r
32         int numCharsInLine;\r
33         enum validLevel { llInvalid, llCheckTextAndStyle, llPositions, llLines } validity;\r
34         int xHighlightGuide;\r
35         bool highlightColumn;\r
36         int selStart;\r
37         int selEnd;\r
38         bool containsCaret;\r
39         int edgeColumn;\r
40         char *chars;\r
41         unsigned char *styles;\r
42         int styleBitsSet;\r
43         char *indicators;\r
44         int *positions;\r
45         char bracePreviousStyles[2];\r
46 \r
47         // Hotspot support\r
48         int hsStart;\r
49         int hsEnd;\r
50 \r
51         // Wrapped line support\r
52         int widthLine;\r
53         int lines;\r
54 \r
55         LineLayout(int maxLineLength_);\r
56         virtual ~LineLayout();\r
57         void Resize(int maxLineLength_);\r
58         void Free();\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
68 };\r
69 \r
70 /**\r
71  */\r
72 class LineLayoutCache {\r
73         int level;\r
74         int length;\r
75         int size;\r
76         LineLayout **cache;\r
77         bool allInvalidated;\r
78         int styleClock;\r
79         int useCount;\r
80         void Allocate(int length_);\r
81         void AllocateForLevel(int linesOnScreen, int linesInDoc);\r
82 public:\r
83         LineLayoutCache();\r
84         virtual ~LineLayoutCache();\r
85         void Deallocate();\r
86         enum {\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
91         };\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
98 };\r
99 \r
100 class PositionCacheEntry {\r
101         unsigned int styleNumber:8;\r
102         unsigned int len:8;\r
103         unsigned int clock:16;\r
104         short *positions;\r
105 public:\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
109         void Clear();\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
113         void ResetClock();\r
114 };\r
115 \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
123         LineLayout *ll;\r
124         int lineStart;\r
125         int lineEnd;\r
126         int posLineStart;\r
127         bool utf8;\r
128         int nextBreak;\r
129         int *selAndEdge;\r
130         unsigned int saeSize;\r
131         unsigned int saeLen;\r
132         unsigned int saeCurrentPos;\r
133         int saeNext;\r
134         int subBreak;\r
135         void Insert(int val);\r
136 public:\r
137         BreakFinder(LineLayout *ll_, int lineStart_, int lineEnd_, int posLineStart_, bool utf8_, int xStart);\r
138         ~BreakFinder();\r
139         int First();\r
140         int Next();\r
141 };\r
142 \r
143 class PositionCache {\r
144         PositionCacheEntry *pces;\r
145         size_t size;\r
146         unsigned int clock;\r
147         bool allClear;\r
148 public:\r
149         PositionCache();\r
150         ~PositionCache();\r
151         void Clear();\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
156 };\r
157 \r
158 inline bool IsSpaceOrTab(int ch) {\r
159         return ch == ' ' || ch == '\t';\r
160 }\r
161 \r
162 #ifdef SCI_NAMESPACE\r
163 }\r
164 #endif\r
165 \r
166 #endif\r