Пример #1
0
void RowPainter::paintMisspelledMark(Row::Element const & e) const
{
	if (e.font.fontInfo().nospellcheck() == FONT_ON)
		return;
	// if changed the misspelled marker gets placed slightly lower than normal
	// to avoid drawing at the same vertical offset
	FontMetrics const & fm = theFontMetrics(e.font);
	int const thickness = max(fm.lineWidth(), 2);
	int const y = yo_ + pi_.base.solidLineOffset() + pi_.base.solidLineThickness()
		+ (e.change.changed() ? pi_.base.solidLineThickness() + 1 : 0)
		+ 1 + thickness / 2;

	//FIXME: this could be computed only once, it is probably not costly.
	// check for cursor position
	// don't draw misspelled marker for words at cursor position
	// we don't want to disturb the process of text editing
	DocIterator const nw = pi_.base.bv->cursor().newWord();
	pos_type cpos = -1;
	if (!nw.empty() && par_.id() == nw.paragraph().id()) {
		cpos = nw.pos();
		if (cpos > 0 && cpos == par_.size() && !par_.isWordSeparator(cpos-1))
			--cpos;
		else if (cpos > 0 && par_.isWordSeparator(cpos))
			--cpos;
	}

	pos_type pos = e.pos;
	while (pos < e.pos + pos_type(e.str.length())) {
		if (!par_.isMisspelled(pos)) {
			++pos;
			continue;
		}

		FontSpan const & range = par_.getSpellRange(pos);

		// Skip element which are being edited
		if (range.contains(cpos)) {
			// the range includes the last element
			pos = range.last + 1;
			continue;
		}

		int x1 = fm.pos2x(e.str, range.first - e.pos,
		                  e.isRTL(), e.extra);
		int x2 = fm.pos2x(e.str, min(range.last - e.pos + 1,
									 pos_type(e.str.length())),
									 e.isRTL(), e.extra);
		if (x1 > x2)
			swap(x1, x2);

		pi_.pain.line(int(x_ + x1), y, int(x_ + x2), y,
		              Color_error,
		              Painter::line_onoffdash, thickness);
		pos = range.last + 1;
	}
}
Пример #2
0
bool TocBackend::updateItem(DocIterator const & dit)
{
	if (dit.paragraph().layout().toclevel == Layout::NOT_IN_TOC)
		return false;

	if (toc("tableofcontents").empty()) {
		// FIXME: should not happen, 
		// a call to TocBackend::update() is missing somewhere
		LYXERR0("TocBackend::updateItem called but the TOC is empty!");
		return false;
	}

	BufferParams const & bufparams = buffer_->params();
	const int min_toclevel = bufparams.documentClass().min_toclevel();

	TocIterator toc_item = item("tableofcontents", dit);

	docstring tocstring;

	// For each paragraph, traverse its insets and let them add
	// their toc items
	Paragraph & par = toc_item->dit_.paragraph();
	InsetList::const_iterator it = par.insetList().begin();
	InsetList::const_iterator end = par.insetList().end();
	for (; it != end; ++it) {
		Inset & inset = *it->inset;
		if (inset.lyxCode() == ARG_CODE) {
			if (!tocstring.empty())
				break;
			Paragraph const & inset_par =
				*static_cast<InsetArgument&>(inset).paragraphs().begin();
			if (!par.labelString().empty())
				tocstring = par.labelString() + ' ';
			tocstring += inset_par.asString(AS_STR_INSETS);
			break;
		}
	}

	int const toclevel = par.layout().toclevel;
	if (toclevel != Layout::NOT_IN_TOC && toclevel >= min_toclevel
		&& tocstring.empty())
			tocstring = par.asString(AS_STR_LABEL | AS_STR_INSETS);

	const_cast<TocItem &>(*toc_item).str_ = tocstring;

	buffer_->updateTocItem("tableofcontents", dit);
	return true;
}
Пример #3
0
bool GuiErrorList::goTo(int item)
{
    if (&buffer() != buf_) {
        if (!theBufferList().isLoaded(buf_))
            return false;
        FuncRequest fr(LFUN_BUFFER_SWITCH, buf_->absFileName());
        dispatch(fr);
    }
    ErrorItem const & err = errorList()[item];

    if (err.par_id == -1)
        return false;

    if (from_master_)
        // FIXME: implement
        return false;

    DocIterator dit = buf_->getParFromID(err.par_id);

    if (dit == doc_iterator_end(buf_)) {
        // FIXME: Happens when loading a read-only doc with
        // unknown layout. Should this be the case?
        LYXERR0("par id " << err.par_id << " not found");
        return false;
    }

    // Now make the selection.
    // if pos_end is 0, this means it is end-of-paragraph
    pos_type const s = dit.paragraph().size();
    pos_type const end = err.pos_end ? min(err.pos_end, s) : s;
    pos_type const start = min(err.pos_start, end);
    pos_type const range = end - start;
    dit.pos() = start;
    BufferView * bv = const_cast<BufferView *>(bufferview());
    // FIXME: If we used an LFUN, we would not need this line:
    bv->putSelectionAt(dit, range, false);
    bv->processUpdateFlags(Update::Force | Update::FitCursor);
    return true;
}