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
12
#include "Selection.h"
19
static inline bool IsEOLChar(char ch) {
20
return (ch == '\r') || (ch == '\n');
27
friend class LineLayoutCache;
30
/// Drawing is only performed for @a maxLineLength characters on each line.
34
enum { wrapWidthInfinite = 0x7ffffff };
37
int numCharsBeforeEOL;
38
enum validLevel { llInvalid, llCheckTextAndStyle, llPositions, llLines } validity;
45
unsigned char *styles;
49
char bracePreviousStyles[2];
55
// Wrapped line support
58
int wrapIndent; // In pixels
60
LineLayout(int maxLineLength_);
61
virtual ~LineLayout();
62
void Resize(int maxLineLength_);
64
void Invalidate(validLevel validity_);
65
int LineStart(int line) const;
66
int LineLastVisible(int line) const;
67
bool InLine(int offset, int line) const;
68
void SetLineStart(int line, int start);
69
void SetBracesHighlight(Range rangeLine, Position braces[],
70
char bracesMatchStyle, int xHighlight);
71
void RestoreBracesHighlight(Range rangeLine, Position braces[]);
72
int FindBefore(int x, int lower, int upper) const;
73
int EndLineStyle() const;
78
class LineLayoutCache {
86
void Allocate(int length_);
87
void AllocateForLevel(int linesOnScreen, int linesInDoc);
90
virtual ~LineLayoutCache();
93
llcNone=SC_CACHE_NONE,
94
llcCaret=SC_CACHE_CARET,
95
llcPage=SC_CACHE_PAGE,
96
llcDocument=SC_CACHE_DOCUMENT
98
void Invalidate(LineLayout::validLevel validity_);
99
void SetLevel(int level_);
100
int GetLevel() { return level; }
101
LineLayout *Retrieve(int lineNumber, int lineCaret, int maxChars, int styleClock_,
102
int linesOnScreen, int linesInDoc);
103
void Dispose(LineLayout *ll);
106
class PositionCacheEntry {
107
unsigned int styleNumber:8;
109
unsigned int clock:16;
112
PositionCacheEntry();
113
~PositionCacheEntry();
114
void Set(unsigned int styleNumber_, const char *s_, unsigned int len_, int *positions_, unsigned int clock);
116
bool Retrieve(unsigned int styleNumber_, const char *s_, unsigned int len_, int *positions_) const;
117
static int Hash(unsigned int styleNumber, const char *s, unsigned int len);
118
bool NewerThan(const PositionCacheEntry &other);
122
// Class to break a line of text into shorter runs at sensible places.
124
// If a whole run is longer than lengthStartSubdivision then subdivide
125
// into smaller runs at spaces or punctuation.
126
enum { lengthStartSubdivision = 300 };
127
// Try to make each subdivided run lengthEachSubdivision or shorter.
128
enum { lengthEachSubdivision = 100 };
136
unsigned int saeSize;
138
unsigned int saeCurrentPos;
141
void Insert(int val);
143
BreakFinder(LineLayout *ll_, int lineStart_, int lineEnd_, int posLineStart_, bool utf8_, int xStart, bool breakForSelection);
149
class PositionCache {
150
PositionCacheEntry *pces;
158
void SetSize(size_t size_);
159
int GetSize() { return size; }
160
void MeasureWidths(Surface *surface, ViewStyle &vstyle, unsigned int styleNumber,
161
const char *s, unsigned int len, int *positions);
164
inline bool IsSpaceOrTab(int ch) {
165
return ch == ' ' || ch == '\t';