]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/PositionCache.h
5d486cb60194b458b89d51a6ad4b488a3adda2fb
1 // Scintilla source code edit control
2 /** @file PositionCache.h
3 ** Classes for caching layout information.
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.
8 #ifndef POSITIONCACHE_H
9 #define POSITIONCACHE_H
15 static inline bool IsEOLChar(char ch
) {
16 return (ch
== '\r') || (ch
== '\n');
23 friend class LineLayoutCache
;
26 /// Drawing is only performed for @a maxLineLength characters on each line.
30 enum { wrapWidthInfinite
= 0x7ffffff };
33 enum validLevel
{ llInvalid
, llCheckTextAndStyle
, llPositions
, llLines
} validity
;
41 unsigned char *styles
;
45 char bracePreviousStyles
[2];
51 // Wrapped line support
55 LineLayout(int maxLineLength_
);
56 virtual ~LineLayout();
57 void Resize(int maxLineLength_
);
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;
72 class LineLayoutCache
{
80 void Allocate(int length_
);
81 void AllocateForLevel(int linesOnScreen
, int linesInDoc
);
84 virtual ~LineLayoutCache();
87 llcNone
=SC_CACHE_NONE
,
88 llcCaret
=SC_CACHE_CARET
,
89 llcPage
=SC_CACHE_PAGE
,
90 llcDocument
=SC_CACHE_DOCUMENT
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
);
100 class PositionCacheEntry
{
101 unsigned int styleNumber
:8;
103 unsigned int clock
:16;
106 PositionCacheEntry();
107 ~PositionCacheEntry();
108 void Set(unsigned int styleNumber_
, const char *s_
, unsigned int len_
, int *positions_
, unsigned int clock
);
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
);
116 // Class to break a line of text into shorter runs at sensible places.
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 };
130 unsigned int saeSize
;
132 unsigned int saeCurrentPos
;
135 void Insert(int val
);
137 BreakFinder(LineLayout
*ll_
, int lineStart_
, int lineEnd_
, int posLineStart_
, bool utf8_
, int xStart
);
143 class PositionCache
{
144 PositionCacheEntry
*pces
;
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
);
158 inline bool IsSpaceOrTab(int ch
) {
159 return ch
== ' ' || ch
== '\t';