1 // Scintilla source code edit control
2 /** @file PositionCache.h
3 ** Classes for caching layout information.
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.
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 int numCharsBeforeEOL
;
34 enum validLevel
{ llInvalid
, llCheckTextAndStyle
, llPositions
, llLines
} validity
;
41 unsigned char *styles
;
45 char bracePreviousStyles
[2];
51 // Wrapped line support
54 int wrapIndent
; // In pixels
56 LineLayout(int maxLineLength_
);
57 virtual ~LineLayout();
58 void Resize(int maxLineLength_
);
60 void Invalidate(validLevel validity_
);
61 int LineStart(int line
) const;
62 int LineLastVisible(int line
) const;
63 bool InLine(int offset
, int line
) const;
64 void SetLineStart(int line
, int start
);
65 void SetBracesHighlight(Range rangeLine
, Position braces
[],
66 char bracesMatchStyle
, int xHighlight
);
67 void RestoreBracesHighlight(Range rangeLine
, Position braces
[]);
68 int FindBefore(int x
, int lower
, int upper
) const;
69 int EndLineStyle() const;
74 class LineLayoutCache
{
82 void Allocate(int length_
);
83 void AllocateForLevel(int linesOnScreen
, int linesInDoc
);
86 virtual ~LineLayoutCache();
89 llcNone
=SC_CACHE_NONE
,
90 llcCaret
=SC_CACHE_CARET
,
91 llcPage
=SC_CACHE_PAGE
,
92 llcDocument
=SC_CACHE_DOCUMENT
94 void Invalidate(LineLayout::validLevel validity_
);
95 void SetLevel(int level_
);
96 int GetLevel() const { return level
; }
97 LineLayout
*Retrieve(int lineNumber
, int lineCaret
, int maxChars
, int styleClock_
,
98 int linesOnScreen
, int linesInDoc
);
99 void Dispose(LineLayout
*ll
);
102 class PositionCacheEntry
{
103 unsigned int styleNumber
:8;
105 unsigned int clock
:16;
108 PositionCacheEntry();
109 ~PositionCacheEntry();
110 void Set(unsigned int styleNumber_
, const char *s_
, unsigned int len_
, int *positions_
, unsigned int clock
);
112 bool Retrieve(unsigned int styleNumber_
, const char *s_
, unsigned int len_
, int *positions_
) const;
113 static int Hash(unsigned int styleNumber
, const char *s
, unsigned int len
);
114 bool NewerThan(const PositionCacheEntry
&other
) const;
118 // Class to break a line of text into shorter runs at sensible places.
120 // If a whole run is longer than lengthStartSubdivision then subdivide
121 // into smaller runs at spaces or punctuation.
122 enum { lengthStartSubdivision
= 300 };
123 // Try to make each subdivided run lengthEachSubdivision or shorter.
124 enum { lengthEachSubdivision
= 100 };
132 unsigned int saeSize
;
134 unsigned int saeCurrentPos
;
137 void Insert(int val
);
139 BreakFinder(LineLayout
*ll_
, int lineStart_
, int lineEnd_
, int posLineStart_
, bool utf8_
, int xStart
, bool breakForSelection
);
145 class PositionCache
{
146 PositionCacheEntry
*pces
;
154 void SetSize(size_t size_
);
155 int GetSize() const { return size
; }
156 void MeasureWidths(Surface
*surface
, ViewStyle
&vstyle
, unsigned int styleNumber
,
157 const char *s
, unsigned int len
, int *positions
);
160 inline bool IsSpaceOrTab(int ch
) {
161 return ch
== ' ' || ch
== '\t';