geany/scintilla/src/PositionCache.h

202 lines
5.6 KiB
C
Raw Normal View History

// Scintilla source code edit control
/** @file PositionCache.h
** Classes for caching layout information.
**/
// Copyright 1998-2009 by Neil Hodgson <neilh@scintilla.org>
// The License.txt file describes the conditions under which this software may be distributed.
#ifndef POSITIONCACHE_H
#define POSITIONCACHE_H
#ifdef SCI_NAMESPACE
namespace Scintilla {
#endif
static inline bool IsEOLChar(char ch) {
return (ch == '\r') || (ch == '\n');
}
/**
*/
class LineLayout {
private:
friend class LineLayoutCache;
int *lineStarts;
int lenLineStarts;
/// Drawing is only performed for @a maxLineLength characters on each line.
int lineNumber;
bool inCache;
public:
enum { wrapWidthInfinite = 0x7ffffff };
int maxLineLength;
int numCharsInLine;
int numCharsBeforeEOL;
enum validLevel { llInvalid, llCheckTextAndStyle, llPositions, llLines } validity;
int xHighlightGuide;
bool highlightColumn;
bool containsCaret;
int edgeColumn;
char *chars;
unsigned char *styles;
2012-06-26 20:48:16 +02:00
XYPOSITION *positions;
char bracePreviousStyles[2];
// Hotspot support
2014-07-04 03:06:17 +02:00
Range hotspot;
// Wrapped line support
int widthLine;
int lines;
2012-06-26 20:48:16 +02:00
XYPOSITION wrapIndent; // In pixels
2014-04-14 16:25:01 +02:00
explicit LineLayout(int maxLineLength_);
virtual ~LineLayout();
void Resize(int maxLineLength_);
void Free();
void Invalidate(validLevel validity_);
int LineStart(int line) const;
int LineLastVisible(int line) const;
2014-04-14 16:25:01 +02:00
Range SubLineRange(int line) const;
bool InLine(int offset, int line) const;
void SetLineStart(int line, int start);
2014-07-04 03:06:17 +02:00
void SetBracesHighlight(Range rangeLine, const Position braces[],
2011-10-18 15:51:50 +02:00
char bracesMatchStyle, int xHighlight, bool ignoreStyle);
2014-07-04 03:06:17 +02:00
void RestoreBracesHighlight(Range rangeLine, const Position braces[], bool ignoreStyle);
2012-06-26 20:48:16 +02:00
int FindBefore(XYPOSITION x, int lower, int upper) const;
2014-04-14 16:25:01 +02:00
int FindPositionFromX(XYPOSITION x, Range range, bool charPosition) const;
Point PointFromPosition(int posInLine, int lineHeight) const;
int EndLineStyle() const;
};
/**
*/
class LineLayoutCache {
int level;
2013-05-22 03:23:57 +02:00
std::vector<LineLayout *>cache;
bool allInvalidated;
int styleClock;
int useCount;
2013-05-22 03:23:57 +02:00
void Allocate(size_t length_);
void AllocateForLevel(int linesOnScreen, int linesInDoc);
public:
LineLayoutCache();
virtual ~LineLayoutCache();
void Deallocate();
enum {
llcNone=SC_CACHE_NONE,
llcCaret=SC_CACHE_CARET,
llcPage=SC_CACHE_PAGE,
llcDocument=SC_CACHE_DOCUMENT
};
void Invalidate(LineLayout::validLevel validity_);
void SetLevel(int level_);
int GetLevel() const { return level; }
LineLayout *Retrieve(int lineNumber, int lineCaret, int maxChars, int styleClock_,
int linesOnScreen, int linesInDoc);
void Dispose(LineLayout *ll);
};
class PositionCacheEntry {
unsigned int styleNumber:8;
unsigned int len:8;
unsigned int clock:16;
2012-06-26 20:48:16 +02:00
XYPOSITION *positions;
public:
PositionCacheEntry();
~PositionCacheEntry();
2014-08-10 02:17:32 +02:00
void Set(unsigned int styleNumber_, const char *s_, unsigned int len_, XYPOSITION *positions_, unsigned int clock_);
void Clear();
2012-06-26 20:48:16 +02:00
bool Retrieve(unsigned int styleNumber_, const char *s_, unsigned int len_, XYPOSITION *positions_) const;
2014-05-17 22:15:57 +02:00
static unsigned int Hash(unsigned int styleNumber_, const char *s, unsigned int len);
bool NewerThan(const PositionCacheEntry &other) const;
void ResetClock();
};
2013-09-18 15:15:05 +02:00
class Representation {
public:
std::string stringRep;
2014-04-14 16:25:01 +02:00
explicit Representation(const char *value="") : stringRep(value) {
2013-09-18 15:15:05 +02:00
}
};
typedef std::map<int, Representation> MapRepresentation;
class SpecialRepresentations {
MapRepresentation mapReprs;
short startByteHasReprs[0x100];
public:
SpecialRepresentations();
void SetRepresentation(const char *charBytes, const char *value);
void ClearRepresentation(const char *charBytes);
2014-07-04 03:06:17 +02:00
const Representation *RepresentationFromCharacter(const char *charBytes, size_t len) const;
2013-09-18 15:15:05 +02:00
bool Contains(const char *charBytes, size_t len) const;
void Clear();
};
struct TextSegment {
int start;
int length;
2014-07-04 03:06:17 +02:00
const Representation *representation;
TextSegment(int start_=0, int length_=0, const Representation *representation_=0) :
2013-09-18 15:15:05 +02:00
start(start_), length(length_), representation(representation_) {
}
int end() const {
return start + length;
}
};
// Class to break a line of text into shorter runs at sensible places.
class BreakFinder {
2014-07-04 03:06:17 +02:00
const LineLayout *ll;
2014-08-10 02:17:32 +02:00
Range lineRange;
int posLineStart;
int nextBreak;
2013-05-22 03:23:57 +02:00
std::vector<int> selAndEdge;
unsigned int saeCurrentPos;
int saeNext;
int subBreak;
2014-07-04 03:06:17 +02:00
const Document *pdoc;
2013-09-18 15:15:05 +02:00
EncodingFamily encodingFamily;
2014-07-04 03:06:17 +02:00
const SpecialRepresentations *preprs;
void Insert(int val);
2013-04-27 16:09:29 +02:00
// Private so BreakFinder objects can not be copied
BreakFinder(const BreakFinder &);
public:
2011-10-18 15:51:50 +02:00
// If a whole run is longer than lengthStartSubdivision then subdivide
// into smaller runs at spaces or punctuation.
enum { lengthStartSubdivision = 300 };
// Try to make each subdivided run lengthEachSubdivision or shorter.
enum { lengthEachSubdivision = 100 };
2014-08-10 02:17:32 +02:00
BreakFinder(const LineLayout *ll_, const Selection *psel, Range rangeLine_, int posLineStart_,
2015-03-08 14:30:34 +01:00
int xStart, bool breakForSelection, const Document *pdoc_, const SpecialRepresentations *preprs_, const ViewStyle *pvsDraw);
~BreakFinder();
2013-09-18 15:15:05 +02:00
TextSegment Next();
bool More() const;
};
class PositionCache {
2013-05-22 03:23:57 +02:00
std::vector<PositionCacheEntry> pces;
unsigned int clock;
bool allClear;
2013-04-27 16:09:29 +02:00
// Private so PositionCache objects can not be copied
PositionCache(const PositionCache &);
public:
PositionCache();
~PositionCache();
void Clear();
void SetSize(size_t size_);
2013-05-22 03:23:57 +02:00
size_t GetSize() const { return pces.size(); }
2014-07-04 03:06:17 +02:00
void MeasureWidths(Surface *surface, const ViewStyle &vstyle, unsigned int styleNumber,
2012-06-26 20:48:16 +02:00
const char *s, unsigned int len, XYPOSITION *positions, Document *pdoc);
};
inline bool IsSpaceOrTab(int ch) {
return ch == ' ' || ch == '\t';
}
#ifdef SCI_NAMESPACE
}
#endif
#endif