Exemple #1
0
void DiffBar::DiffStyler::Style(StyleRun& sr) {
	if (m_diffs.empty()) return;

	const unsigned int rstart =  sr.GetRunStart();
	const unsigned int rend = sr.GetRunEnd();
	const cxChangeType primaryType = m_isLeft ? cxDELETION : cxINSERTION;
	const wxColor& primaryColor = m_isLeft ? m_delColor : m_insColor;
	const wxColor& secondaryColor = m_isLeft ? m_insColor : m_delColor;

	for (std::vector<Change>::const_iterator c = m_diffs.begin(); c != m_diffs.end(); ++c) {
		if (c->type == primaryType) {
			if (c->end_pos > rstart && c->start_pos < rend) {
				const unsigned int start = wxMax(rstart, c->start_pos);
				const unsigned int end   = wxMin(rend, c->end_pos);

				sr.SetBackgroundColor(start, end, primaryColor);
				sr.SetShowHidden(start, end, true);
			}
			if (c->end_pos > rend) break;
		}
		else {
			if (c->rev_pos > rend) break;
			else if (c->rev_pos > rstart) {
				sr.SetBackgroundColor(c->rev_pos, c->rev_pos, secondaryColor); // zero-len
			}
		}
	}
}
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);
}
Exemple #3
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 #4
0
void Styler_SearchHL::Style(StyleRun& sr) {
	const unsigned int rstart =  sr.GetRunStart();
	const unsigned int rend = sr.GetRunEnd();

	// Style the run with search ranges
	for (vector<interval>::const_iterator r = m_searchRanges.begin(); r != m_searchRanges.end(); ++r) {
		if (r->end > rstart && r->start < rend) {
			unsigned int start = wxMax(rstart, r->start);
			unsigned int end   = wxMin(rend, r->end);
			sr.SetBackgroundColor(start, end, m_rangeColor);
		}
	}

	// No need for more styling if no search text
	if (m_text.empty()) return;

	// Extend stylerun start/end to get better search results (round up to whole EXTSIZEs)
	unsigned int sr_start = rstart> 100 ? rstart - 100 : 0;
	const unsigned int ext_end = ((rend/EXTSIZE) * EXTSIZE) + EXTSIZE;
	unsigned int sr_end = ext_end < m_lines.GetLength() ? ext_end : m_lines.GetLength();

	// Make sure the extended positions are valid
	cxLOCKDOC_READ(m_doc)
		sr_start = doc.GetValidCharPos(sr_start);
		if (sr_end != m_lines.GetLength()) sr_end = doc.GetValidCharPos(sr_end);
	cxENDLOCK

	//wxLogDebug("Style %u %u", rstart, rend);
	//wxLogDebug(" %u %u - %u %u", sr_start, sr_end, m_search_start, m_search_end);
	// Check if we need to do a new search
	if (sr_start < m_search_start || m_search_end < sr_end) {
		// Check if there is overlap so we can just extend the search area
		if (sr_end > m_search_start && sr_start < m_search_end) {
			sr_start = wxMin(sr_start, m_search_start);
			sr_end = wxMax(sr_end, m_search_end);
		}
		else {
			// Else we have to move it
			m_matches.clear();
			m_search_start = 0;
			m_search_end = 0;
		}

		// Do the search
		if (sr_start < m_search_start) {
			// Search from top
			DoSearch(sr_start, sr_end);
		}
		else if (sr_end > m_search_end) {
			// Search from bottom
			DoSearch(sr_start, sr_end, true);
		}
		else wxASSERT(false);

		m_search_start = sr_start;
		m_search_end = sr_end;
	}

	// Style the run with matches
	for (vector<interval>::iterator p = m_matches.begin(); p != m_matches.end(); ++p) {
		if (p->start > rend) break;

		// Check for overlap (or zero-length sel at start-of-line)
		if ((p->end > rstart && p->start < rend) || (p->start == p->end && p->end == rstart)) {
			unsigned int start = wxMax(rstart, p->start);
			unsigned int end   = wxMin(rend, p->end);

			// Only draw it if it is in range
			if (!m_searchRanges.empty()) {
				bool inRange = false;
				for (vector<interval>::const_iterator s = m_searchRanges.begin(); s != m_searchRanges.end(); ++s) {
					if (start >= s->start && start < s->end) {
						inRange = true;
						break;
					}
				}
				if (!inRange) continue;
			}
			
			ApplyStyle(sr, start, end);
		}
	}
}
Exemple #5
0
void Styler_SearchHL::ApplyStyle(StyleRun& sr, unsigned int start, unsigned int end) {
	sr.SetBackgroundColor(start, end, m_hlcolor);
	sr.SetShowHidden(start, end, true);
}