JX Application Framework
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
JSTStyler Class Referenceabstract

#include <JSTStyler.h>

Classes

struct  TokenData
 
union  TokenExtra
 

Public Member Functions

 JSTStyler ()
 
virtual ~JSTStyler ()
 
void UpdateStyles (const JStyledText *te, const JString &text, JRunArray< JFont > *styles, JStyledText::TextRange *recalcRange, JStyledText::TextRange *redrawRange, const bool deletion, JArray< TokenData > *tokenStartList)
 
bool IsActive () const
 
void SetActive (const bool active)
 

Static Public Member Functions

static JArray< TokenData > * NewTokenStartList ()
 

Protected Member Functions

virtual void Scan (const JStyledText::TextIndex &startIndex, std::istream &input, const TokenExtra &initData)=0
 
virtual TokenExtra GetFirstTokenExtraData () const
 
virtual void PreexpandCheckRange (const JString &text, const JRunArray< JFont > &styles, const JCharacterRange &modifiedRange, const bool deletion, JStyledText::TextRange *checkRange)
 
void ExtendCheckRange (const JIndex newEndCharIndex)
 
const JStyledTextGetStyledText () const
 
const JFontManagerGetFontManager () const
 
const JFontGetDefaultFont () const
 
const JStringGetText () const
 
const JRunArray< JFont > & GetStyles () const
 
JUtf8Character GetCharacter (const JStyledText::TextIndex &index) const
 
bool SetStyle (const JCharacterRange &range, const JFontStyle &style)
 
void SaveTokenStart (const JStyledText::TextIndex &index, const TokenExtra data=TokenExtra())
 
void AdjustStyle (const JCharacterRange &range, const JFontStyle &style)
 
void SetDecimationFactor (const JSize factor)
 

Detailed Description

This is the base class for an object that can efficiently control the
styles inside a JStyledText.  Derive a class from JStyledText and
override AdjustStylesBeforeBroadcast() and pass the arguments directly
to JSTStyler::UpdateStyles().

tokenStartList is used to avoid lexing more of the text than necessary.
Each JStyledText object must own one and must never modify the contents
between calls to UpdateStyles().

Derived classes must override the following function:

    Scan
        Read tokens from the given input stream and call SetStyle() for
        each one.  When SetStyle() returns false, stop scanning.

        Every character in the input stream must be part of some token,
        and the tokens must be passed to SetStyle() in the order that they
        occur in the file.

        Every time the lexer reaches a point where it could be safely
        restarted, call SaveTokenStart().  (This cannot be done for every
        token because, for example, '*' can mean either multiplication or
        dereferencing in C, so one must start further back in order to
        get the context.)

Derived classes can override the following function:

    PreexpandCheckRange
        Called before Scan() to allow the derived class to expand the
        range of characters that need to be checked.  The initial range
        starts with the first character in the style run containing the
        first modified character and ends with the last character in the
        style run containing the last modified character.  These points
        are obviously token boundaries.  In some cases, one needs to check
        a wider range.

While inside Scan(), one may encounter a token that requires checking
at least a certain distance (e.g. to the end of the line).  To handle
this, call ExtendCheckRange() with the index of the last character that
must be checked.  This should be done before calling SetStyle() for the
token.

Constructor & Destructor Documentation

◆ JSTStyler()

JSTStyler::JSTStyler ( )

◆ ~JSTStyler()

JSTStyler::~JSTStyler ( )
virtual

Member Function Documentation

◆ AdjustStyle()

void JSTStyler::AdjustStyle ( const JCharacterRange range,
const JFontStyle style 
)
protected

Call this to change the style of something that the lexer has already processed.

◆ ExtendCheckRange()

void JSTStyler::ExtendCheckRange ( const JIndex  newEndCharIndex)
protected

Extends the end of the check range. It is safe to call this with an index beyond the end of the text.

◆ GetCharacter()

JUtf8Character JSTStyler::GetCharacter ( const JStyledText::TextIndex index) const
protected

Only use if you really need only one single character

◆ GetDefaultFont()

const JFont & JSTStyler::GetDefaultFont ( ) const
inlineprotected

◆ GetFirstTokenExtraData()

JSTStyler::TokenExtra JSTStyler::GetFirstTokenExtraData ( ) const
protectedvirtual

Derived classes can override this to store additional data.

◆ GetFontManager()

const JFontManager * JSTStyler::GetFontManager ( ) const
protected

◆ GetStyledText()

const JStyledText * JSTStyler::GetStyledText ( ) const
inlineprotected

◆ GetStyles()

const JRunArray< JFont > & JSTStyler::GetStyles ( ) const
inlineprotected

◆ GetText()

const JString & JSTStyler::GetText ( ) const
inlineprotected

◆ IsActive()

bool JSTStyler::IsActive ( ) const
inline

◆ NewTokenStartList()

JArray< JSTStyler::TokenData > * JSTStyler::NewTokenStartList ( )
static

Allocates a tokenStartList with a reasonable block size.

◆ PreexpandCheckRange()

void JSTStyler::PreexpandCheckRange ( const JString text,
const JRunArray< JFont > &  styles,
const JCharacterRange modifiedRange,
const bool  deletion,
JStyledText::TextRange checkRange 
)
protectedvirtual

checkRange is only allowed to expand. The default is to do nothing.

modifiedRange is the range of text that was changed. deletion is true if the modification was that text was deleted.

◆ SaveTokenStart()

void JSTStyler::SaveTokenStart ( const JStyledText::TextIndex index,
const TokenExtra  data = TokenExtra() 
)
protected

Automatically decimates the stream of token starts by itsDecimationFactor.

◆ Scan()

virtual void JSTStyler::Scan ( const JStyledText::TextIndex startIndex,
std::istream &  input,
const TokenExtra initData 
)
protectedpure virtual

◆ SetActive()

void JSTStyler::SetActive ( const bool  active)
inline

◆ SetDecimationFactor()

void JSTStyler::SetDecimationFactor ( const JSize  factor)
inlineprotected

◆ SetStyle()

bool JSTStyler::SetStyle ( const JCharacterRange range,
const JFontStyle style 
)
protected

Returns true if the lexer should keep going.

◆ UpdateStyles()

void JSTStyler::UpdateStyles ( const JStyledText st,
const JString text,
JRunArray< JFont > *  styles,
JStyledText::TextRange recalcRange,
JStyledText::TextRange redrawRange,
const bool  deletion,
JArray< TokenData > *  tokenStartList 
)

Ranges are inside [1, text.GetCharacterCount()+1]


The documentation for this class was generated from the following files: