Exemple #1
0
void Styler_Syntax::DoStyle(StyleRun& sr, unsigned int offset, const auto_vector<stxmatch>& matches) {
	const unsigned int rstart =  sr.GetRunStart();
	const unsigned int rend = sr.GetRunEnd();
	const unsigned int styleStart = offset < rstart ? rstart - offset : 0;
	const stxmatch m(wxEmptyString, NULL, styleStart, 0, 0, 0, NULL);

	if (matches.empty()) return;

	auto_vector<stxmatch>::const_iterator p = lower_bound(matches.begin(), matches.end(), &m, stxmatch_start_less());
	if (p != matches.begin()) --p;

	for (; p != matches.end(); ++p) {
		const unsigned int mStart = (*p)->start+offset;
		const unsigned int mEnd   = (*p)->end+offset;

		if (mStart > rend) break;

		// Check for overlap
		if (mEnd > rstart && mStart < rend) {
			const unsigned int start = wxMax(rstart, mStart);
			const unsigned int end = wxMin(rend, mEnd);

			const style* st = (*p)->st;
			if (st) {
				if (st->foregroundcolor != wxNullColour) sr.SetForegroundColor(start, end, st->foregroundcolor);
				if (st->backgroundcolor != wxNullColour) {
					sr.SetBackgroundColor(start, end, st->backgroundcolor);
					if (mEnd > rend) sr.SetExtendBgColor(st->backgroundcolor);
				}
				if (st->fontflags != wxFONTFLAG_DEFAULT) sr.SetFontStyle(start, end, st->fontflags);
			}

			// Check if there are submatches
			if ((*p)->subMatch.get()) {
				 DoStyle(sr, (*p)->start+offset, (*p)->subMatch->matches);
			}
		}
	}
}
Exemple #2
0
void Styler_Syntax::Style(StyleRun& sr) {
	if (!HaveActiveSyntax()) return;

	unsigned int sr_end = sr.GetRunEnd();

	// Check if we need to do a new search
	if (sr_end > m_syntax_end) {
		// Make sure the extended position is valid and extends
		// from start-of-line to end-of-line
		unsigned int sr_start;
		cxLOCKDOC_READ(m_doc)
			sr_start = doc.GetLineStart(m_syntax_end);
		cxENDLOCK

		// Extend stylerun to get better search results (round up to whole EXTSIZEs)
		const unsigned int ext = ((sr_end / EXTSIZE) + 1) * EXTSIZE;
		sr_end =  ext < m_lines.GetLength() ? ext : m_lines.GetLength();
		sr_end = m_lines.GetLineEndFromPos(sr_end);

		DoSearch(sr_start, sr_end, sr_end);
	}

	// Apply base style
	if (m_topStyle) {
		const unsigned int start =  sr.GetRunStart();
		const unsigned int end = sr.GetRunEnd();
		if (m_topStyle->foregroundcolor != wxNullColour) sr.SetForegroundColor(start, end, m_topStyle->foregroundcolor);
		if (m_topStyle->backgroundcolor != wxNullColour) {
			sr.SetBackgroundColor(start, end, m_topStyle->backgroundcolor);
			sr.SetExtendBgColor(m_topStyle->backgroundcolor);
		}
		if (m_topStyle->fontflags != wxFONTFLAG_DEFAULT) sr.SetFontStyle(start, end, m_topStyle->fontflags);
	}

	// Style the run
	DoStyle(sr, 0, m_topMatches.matches);
}