2003-02-26 17:04:10 +00:00
|
|
|
/**
|
2014-07-25 19:55:08 +00:00
|
|
|
* \file RowPainter.cpp
|
2003-02-26 17:04:10 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author various
|
|
|
|
* \author John Levon
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-02-26 17:04:10 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
2008-03-17 21:11:17 +00:00
|
|
|
#include <algorithm>
|
2003-02-26 17:04:10 +00:00
|
|
|
|
2014-07-25 19:55:08 +00:00
|
|
|
#include "RowPainter.h"
|
2003-02-26 17:04:10 +00:00
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Buffer.h"
|
|
|
|
#include "CoordCache.h"
|
2007-04-26 14:56:30 +00:00
|
|
|
#include "Cursor.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "BufferParams.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
#include "BufferView.h"
|
2007-10-18 15:29:51 +00:00
|
|
|
#include "Changes.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Language.h"
|
2007-09-29 20:02:32 +00:00
|
|
|
#include "Layout.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "LyXRC.h"
|
|
|
|
#include "Row.h"
|
|
|
|
#include "MetricsInfo.h"
|
|
|
|
#include "Paragraph.h"
|
2006-12-29 23:54:48 +00:00
|
|
|
#include "ParagraphMetrics.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
#include "ParagraphParameters.h"
|
2006-12-29 23:54:48 +00:00
|
|
|
#include "TextMetrics.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "VSpace.h"
|
2003-02-26 17:04:10 +00:00
|
|
|
|
2006-10-07 16:15:06 +00:00
|
|
|
#include "frontends/FontMetrics.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
#include "frontends/Painter.h"
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
#include "insets/InsetText.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
|
2010-12-22 00:16:51 +00:00
|
|
|
#include "mathed/InsetMath.h"
|
|
|
|
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/debug.h"
|
2009-07-19 01:41:47 +00:00
|
|
|
#include "support/gettext.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
#include "support/textutils.h"
|
2003-06-30 23:56:22 +00:00
|
|
|
|
2008-04-30 08:26:40 +00:00
|
|
|
#include "support/lassert.h"
|
2005-12-30 19:02:52 +00:00
|
|
|
#include <boost/crc.hpp>
|
|
|
|
|
2016-07-04 18:36:16 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2004-01-30 11:41:12 +00:00
|
|
|
|
2007-08-28 08:57:13 +00:00
|
|
|
namespace lyx {
|
2003-07-14 17:50:00 +00:00
|
|
|
|
2007-08-28 08:57:13 +00:00
|
|
|
using frontend::Painter;
|
|
|
|
using frontend::FontMetrics;
|
2003-07-28 12:20:42 +00:00
|
|
|
|
2012-10-27 13:45:27 +00:00
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
RowPainter::RowPainter(PainterInfo & pi,
|
2016-05-18 07:39:47 +00:00
|
|
|
Text const & text, Row const & row, int x, int y)
|
2007-08-30 14:26:52 +00:00
|
|
|
: pi_(pi), text_(text),
|
2007-08-30 13:53:02 +00:00
|
|
|
text_metrics_(pi_.base.bv->textMetrics(&text)),
|
2006-12-29 23:54:48 +00:00
|
|
|
pars_(text.paragraphs()),
|
2016-05-18 07:39:47 +00:00
|
|
|
row_(row), par_(text.paragraphs()[row.pit()]),
|
|
|
|
pm_(text_metrics_.parMetrics(row.pit())), change_(pi_.change_),
|
2016-05-22 21:48:28 +00:00
|
|
|
xo_(x), yo_(y), width_(text_metrics_.width())
|
2003-11-24 16:26:55 +00:00
|
|
|
{
|
2014-12-22 09:36:53 +00:00
|
|
|
x_ = row_.left_margin + xo_;
|
2004-08-14 15:55:22 +00:00
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
//lyxerr << "RowPainter: x: " << x_ << " xo: " << xo_ << " yo: " << yo_ << endl;
|
|
|
|
//row_.dump();
|
|
|
|
|
2016-05-18 07:39:47 +00:00
|
|
|
LBUFERR(row.pit() >= 0);
|
|
|
|
LBUFERR(row.pit() < int(text.paragraphs().size()));
|
2003-11-24 16:26:55 +00:00
|
|
|
}
|
2003-02-26 17:04:10 +00:00
|
|
|
|
|
|
|
|
2008-02-27 23:03:26 +00:00
|
|
|
FontInfo RowPainter::labelFont() const
|
2003-02-26 17:04:10 +00:00
|
|
|
{
|
2010-09-06 14:35:02 +00:00
|
|
|
FontInfo f = text_.labelFont(par_);
|
|
|
|
// selected text?
|
|
|
|
if (row_.begin_margin_sel || pi_.selected)
|
|
|
|
f.setPaintColor(Color_selectiontext);
|
|
|
|
return f;
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-03 15:39:58 +00:00
|
|
|
// If you want to debug inset metrics uncomment the following line:
|
2007-08-30 09:01:30 +00:00
|
|
|
//#define DEBUG_METRICS
|
2006-11-03 15:39:58 +00:00
|
|
|
// This draws green lines around each inset.
|
|
|
|
|
|
|
|
|
2016-05-17 13:00:09 +00:00
|
|
|
void RowPainter::paintInset(Row::Element const & e) const
|
2003-02-26 17:04:10 +00:00
|
|
|
{
|
2015-07-16 21:10:44 +00:00
|
|
|
// Handle selection
|
|
|
|
bool const pi_selected = pi_.selected;
|
|
|
|
Cursor const & cur = pi_.base.bv->cursor();
|
|
|
|
if (cur.selection() && cur.text() == &text_
|
|
|
|
&& cur.normalAnchor().text() == &text_)
|
2016-02-28 15:42:35 +00:00
|
|
|
pi_.selected = row_.sel_beg <= e.pos && row_.sel_end > e.pos;
|
2015-07-16 21:10:44 +00:00
|
|
|
|
2016-02-28 15:42:35 +00:00
|
|
|
LASSERT(e.inset, return);
|
2008-01-14 16:24:01 +00:00
|
|
|
// Backup full_repaint status because some insets (InsetTabular)
|
|
|
|
// requires a full repaint
|
2015-05-06 16:39:24 +00:00
|
|
|
bool const pi_full_repaint = pi_.full_repaint;
|
|
|
|
bool const pi_do_spellcheck = pi_.do_spellcheck;
|
2015-07-16 21:34:33 +00:00
|
|
|
Change const pi_change = pi_.change_;
|
2008-01-14 16:24:01 +00:00
|
|
|
|
2016-02-28 15:42:35 +00:00
|
|
|
pi_.base.font = e.inset->inheritFont() ? e.font.fontInfo() :
|
2011-02-22 19:41:04 +00:00
|
|
|
pi_.base.bv->buffer().params().getFont().fontInfo();
|
2016-02-28 15:42:35 +00:00
|
|
|
pi_.ltr_pos = !e.font.isVisibleRightToLeft();
|
|
|
|
pi_.change_ = change_.changed() ? change_ : e.change;
|
|
|
|
pi_.do_spellcheck &= e.inset->allowSpellCheck();
|
2009-02-09 21:14:23 +00:00
|
|
|
|
2008-12-22 18:16:05 +00:00
|
|
|
int const x1 = int(x_);
|
2016-02-28 15:42:35 +00:00
|
|
|
pi_.base.bv->coordCache().insets().add(e.inset, x1, yo_);
|
2007-08-27 14:38:29 +00:00
|
|
|
// insets are painted completely. Recursive
|
2010-11-25 13:08:26 +00:00
|
|
|
// FIXME: it is wrong to completely paint the background
|
|
|
|
// if we want to do single row painting.
|
2016-02-28 15:42:35 +00:00
|
|
|
e.inset->drawBackground(pi_, x1, yo_);
|
|
|
|
e.inset->drawSelection(pi_, x1, yo_);
|
|
|
|
e.inset->draw(pi_, x1, yo_);
|
2007-08-30 09:01:30 +00:00
|
|
|
|
2008-01-14 16:24:01 +00:00
|
|
|
// Restore full_repaint status.
|
|
|
|
pi_.full_repaint = pi_full_repaint;
|
2015-07-16 21:34:33 +00:00
|
|
|
pi_.change_ = pi_change;
|
2015-05-06 16:39:24 +00:00
|
|
|
pi_.do_spellcheck = pi_do_spellcheck;
|
2015-07-16 21:10:44 +00:00
|
|
|
pi_.selected = pi_selected;
|
2008-01-14 16:24:01 +00:00
|
|
|
|
2006-11-03 15:39:58 +00:00
|
|
|
#ifdef DEBUG_METRICS
|
2016-05-17 13:00:09 +00:00
|
|
|
Dimension const & dim = pi_.base.bv->coordCache().insets().dim(e.inset);
|
2006-11-03 15:39:58 +00:00
|
|
|
int const x2 = x1 + dim.wid;
|
|
|
|
int const y1 = yo_ + dim.des;
|
|
|
|
int const y2 = yo_ - dim.asc;
|
2007-10-25 12:41:02 +00:00
|
|
|
pi_.pain.line(x1, y1, x1, y2, Color_green);
|
|
|
|
pi_.pain.line(x1, y1, x2, y1, Color_green);
|
|
|
|
pi_.pain.line(x2, y1, x2, y2, Color_green);
|
|
|
|
pi_.pain.line(x1, y2, x2, y2, Color_green);
|
2006-11-03 15:39:58 +00:00
|
|
|
#endif
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-17 13:00:09 +00:00
|
|
|
void RowPainter::paintForeignMark(Row::Element const & e) const
|
2015-07-14 21:45:41 +00:00
|
|
|
{
|
2016-05-17 13:00:09 +00:00
|
|
|
Language const * lang = e.font.language();
|
2015-07-14 21:45:41 +00:00
|
|
|
if (!lyxrc.mark_foreign_language)
|
|
|
|
return;
|
|
|
|
if (lang == latex_language)
|
|
|
|
return;
|
|
|
|
if (lang == pi_.base.bv->buffer().params().language)
|
|
|
|
return;
|
|
|
|
|
2016-05-17 13:00:09 +00:00
|
|
|
int const desc = e.inset ? e.dim.descent() : 0;
|
2016-05-22 21:48:28 +00:00
|
|
|
int const y = yo_ + pi_.base.solidLineOffset()
|
|
|
|
+ desc + pi_.base.solidLineThickness() / 2;
|
2016-05-17 13:00:09 +00:00
|
|
|
pi_.pain.line(int(x_), y, int(x_ + e.full_width()), y, Color_language,
|
2016-05-22 21:48:28 +00:00
|
|
|
Painter::line_solid, pi_.base.solidLineThickness());
|
2015-07-14 21:45:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-17 13:00:09 +00:00
|
|
|
void RowPainter::paintMisspelledMark(Row::Element const & e) const
|
2015-07-14 21:45:41 +00:00
|
|
|
{
|
|
|
|
// if changed the misspelled marker gets placed slightly lower than normal
|
|
|
|
// to avoid drawing at the same vertical offset
|
2015-11-25 21:09:45 +00:00
|
|
|
FontMetrics const & fm = theFontMetrics(e.font);
|
|
|
|
int const thickness = max(fm.lineWidth(), 2);
|
2016-05-22 21:48:28 +00:00
|
|
|
int const y = yo_ + pi_.base.solidLineOffset() + pi_.base.solidLineThickness()
|
|
|
|
+ (e.change.changed() ? pi_.base.solidLineThickness() + 1 : 0)
|
2015-11-25 21:09:45 +00:00
|
|
|
+ 1 + thickness / 2;
|
2015-07-14 21:45:41 +00:00
|
|
|
|
|
|
|
//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;
|
|
|
|
}
|
|
|
|
|
2015-07-18 23:22:10 +00:00
|
|
|
pos_type pos = e.pos;
|
|
|
|
while (pos < e.pos + pos_type(e.str.length())) {
|
2015-07-14 21:45:41 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-07-18 23:22:10 +00:00
|
|
|
FontMetrics const & fm = theFontMetrics(e.font);
|
|
|
|
int x1 = fm.pos2x(e.str, range.first - e.pos,
|
2015-09-18 14:42:24 +00:00
|
|
|
e.isRTL(), e.extra);
|
2015-07-18 23:22:10 +00:00
|
|
|
int x2 = fm.pos2x(e.str, min(range.last - e.pos + 1,
|
|
|
|
pos_type(e.str.length())),
|
2015-09-18 14:42:24 +00:00
|
|
|
e.isRTL(), e.extra);
|
2015-07-14 21:45:41 +00:00
|
|
|
if (x1 > x2)
|
|
|
|
swap(x1, x2);
|
|
|
|
|
2016-07-02 18:12:34 +00:00
|
|
|
pi_.pain.line(int(x_ + x1), y, int(x_ + x2), y,
|
|
|
|
Color_error,
|
2015-11-25 21:09:45 +00:00
|
|
|
Painter::line_onoffdash, thickness);
|
2015-07-14 21:45:41 +00:00
|
|
|
pos = range.last + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-17 13:00:09 +00:00
|
|
|
void RowPainter::paintStringAndSel(Row::Element const & e) const
|
2015-07-14 21:45:41 +00:00
|
|
|
{
|
|
|
|
// at least part of text selected?
|
2015-07-18 23:22:10 +00:00
|
|
|
bool const some_sel = (e.endpos >= row_.sel_beg && e.pos < row_.sel_end)
|
2015-07-14 21:45:41 +00:00
|
|
|
|| pi_.selected;
|
|
|
|
// all the text selected?
|
2015-07-18 23:22:10 +00:00
|
|
|
bool const all_sel = (e.pos >= row_.sel_beg && e.endpos < row_.sel_end)
|
2015-07-14 21:45:41 +00:00
|
|
|
|| pi_.selected;
|
|
|
|
|
2015-10-28 09:29:48 +00:00
|
|
|
if (all_sel || e.change.changed()) {
|
2015-07-18 23:22:10 +00:00
|
|
|
Font copy = e.font;
|
2015-10-28 09:29:48 +00:00
|
|
|
Color const col = e.change.changed() ? e.change.color()
|
|
|
|
: Color_selectiontext;
|
|
|
|
copy.fontInfo().setPaintColor(col);
|
2016-03-20 19:02:05 +00:00
|
|
|
pi_.pain.text(int(x_), yo_, e.str, copy, e.extra, e.full_width());
|
2015-07-14 21:45:41 +00:00
|
|
|
} else if (!some_sel) {
|
2016-03-20 19:02:05 +00:00
|
|
|
pi_.pain.text(int(x_), yo_, e.str, e.font, e.extra, e.full_width());
|
2015-07-14 21:45:41 +00:00
|
|
|
} else {
|
2015-07-18 23:22:10 +00:00
|
|
|
pi_.pain.text(int(x_), yo_, e.str, e.font, Color_selectiontext,
|
2016-03-20 19:02:05 +00:00
|
|
|
max(row_.sel_beg, e.pos) - e.pos,
|
|
|
|
min(row_.sel_end, e.endpos) - e.pos,
|
|
|
|
e.extra, e.full_width());
|
2015-07-14 21:45:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-17 13:00:09 +00:00
|
|
|
void RowPainter::paintChange(Row::Element const & e) const
|
2015-07-16 21:18:55 +00:00
|
|
|
{
|
2016-05-22 21:48:28 +00:00
|
|
|
e.change.paintCue(pi_, x_, yo_, x_ + e.full_width(), e.font.fontInfo());
|
2015-07-16 21:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-29 14:12:11 +00:00
|
|
|
void RowPainter::paintChangeBar() const
|
2003-02-26 17:04:10 +00:00
|
|
|
{
|
2003-10-23 08:15:57 +00:00
|
|
|
pos_type const start = row_.pos();
|
2006-10-31 20:07:26 +00:00
|
|
|
pos_type end = row_.endpos();
|
|
|
|
|
|
|
|
if (par_.size() == end) {
|
|
|
|
// this is the last row of the paragraph;
|
|
|
|
// thus, we must also consider the imaginary end-of-par character
|
|
|
|
end++;
|
|
|
|
}
|
2003-02-26 17:04:10 +00:00
|
|
|
|
2006-03-13 11:05:07 +00:00
|
|
|
if (start == end || !par_.isChanged(start, end))
|
2003-02-26 17:04:10 +00:00
|
|
|
return;
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2016-05-18 07:39:47 +00:00
|
|
|
int const height = text_metrics_.isLastRow(row_)
|
2004-11-30 01:59:49 +00:00
|
|
|
? row_.ascent()
|
|
|
|
: row_.height();
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2007-10-25 12:41:02 +00:00
|
|
|
pi_.pain.fillRectangle(5, yo_ - row_.ascent(), 3, height, Color_changebar);
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
|
|
|
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2015-06-29 14:12:11 +00:00
|
|
|
void RowPainter::paintAppendix() const
|
2003-02-26 17:04:10 +00:00
|
|
|
{
|
2007-07-17 13:35:32 +00:00
|
|
|
// only draw the appendix frame once (for the main text)
|
2009-08-09 15:29:34 +00:00
|
|
|
if (!par_.params().appendix() || !text_.isMainText())
|
2003-03-13 19:55:39 +00:00
|
|
|
return;
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
int y = yo_ - row_.ascent();
|
2003-03-13 19:55:39 +00:00
|
|
|
|
2004-08-15 00:01:45 +00:00
|
|
|
if (par_.params().startOfAppendix())
|
2003-03-13 19:55:39 +00:00
|
|
|
y += 2 * defaultRowHeight();
|
|
|
|
|
2007-10-25 12:41:02 +00:00
|
|
|
pi_.pain.line(1, y, 1, yo_ + row_.height(), Color_appendix);
|
|
|
|
pi_.pain.line(width_ - 2, y, width_ - 2, yo_ + row_.height(), Color_appendix);
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-29 14:12:11 +00:00
|
|
|
void RowPainter::paintDepthBar() const
|
2003-02-26 17:04:10 +00:00
|
|
|
{
|
2006-10-21 00:16:43 +00:00
|
|
|
depth_type const depth = par_.getDepth();
|
2003-02-26 17:04:10 +00:00
|
|
|
|
|
|
|
if (depth <= 0)
|
|
|
|
return;
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
depth_type prev_depth = 0;
|
2016-05-18 07:39:47 +00:00
|
|
|
if (!text_metrics_.isFirstRow(row_)) {
|
|
|
|
pit_type pit2 = row_.pit();
|
2003-10-23 08:15:57 +00:00
|
|
|
if (row_.pos() == 0)
|
2003-08-14 12:06:11 +00:00
|
|
|
--pit2;
|
2004-03-25 09:16:36 +00:00
|
|
|
prev_depth = pars_[pit2].getDepth();
|
2003-08-14 12:06:11 +00:00
|
|
|
}
|
2003-06-18 17:43:49 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
depth_type next_depth = 0;
|
2016-05-18 07:39:47 +00:00
|
|
|
if (!text_metrics_.isLastRow(row_)) {
|
|
|
|
pit_type pit2 = row_.pit();
|
2004-03-25 09:16:36 +00:00
|
|
|
if (row_.endpos() >= pars_[pit2].size())
|
2003-08-14 12:06:11 +00:00
|
|
|
++pit2;
|
2004-03-25 09:16:36 +00:00
|
|
|
next_depth = pars_[pit2].getDepth();
|
2003-08-14 12:06:11 +00:00
|
|
|
}
|
2003-02-26 17:04:10 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
for (depth_type i = 1; i <= depth; ++i) {
|
2004-08-14 15:55:22 +00:00
|
|
|
int const w = nestMargin() / 5;
|
2004-08-14 21:56:40 +00:00
|
|
|
int x = int(xo_) + w * i;
|
|
|
|
// only consider the changebar space if we're drawing outermost text
|
2009-08-09 15:29:34 +00:00
|
|
|
if (text_.isMainText())
|
2004-08-14 15:55:22 +00:00
|
|
|
x += changebarMargin();
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
int const starty = yo_ - row_.ascent();
|
|
|
|
int const h = row_.height() - 1 - (i - next_depth - 1) * 3;
|
2003-02-26 17:04:10 +00:00
|
|
|
|
2007-10-25 12:41:02 +00:00
|
|
|
pi_.pain.line(x, starty, x, starty + h, Color_depthbar);
|
2003-02-26 17:04:10 +00:00
|
|
|
|
2003-07-28 12:20:42 +00:00
|
|
|
if (i > prev_depth)
|
2007-10-25 12:41:02 +00:00
|
|
|
pi_.pain.fillRectangle(x, starty, w, 2, Color_depthbar);
|
2003-07-28 12:20:42 +00:00
|
|
|
if (i > next_depth)
|
2007-10-25 12:41:02 +00:00
|
|
|
pi_.pain.fillRectangle(x, starty + h, w, 2, Color_depthbar);
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-12 09:55:38 +00:00
|
|
|
void RowPainter::paintAppendixStart(int y) const
|
2003-03-13 19:55:39 +00:00
|
|
|
{
|
2007-10-29 08:47:19 +00:00
|
|
|
FontInfo pb_font = sane_font;
|
2007-10-25 12:41:02 +00:00
|
|
|
pb_font.setColor(Color_appendix);
|
2003-09-16 09:01:15 +00:00
|
|
|
pb_font.decSize();
|
2003-03-13 19:55:39 +00:00
|
|
|
|
|
|
|
int w = 0;
|
|
|
|
int a = 0;
|
|
|
|
int d = 0;
|
2006-10-17 14:46:45 +00:00
|
|
|
|
|
|
|
docstring const label = _("Appendix");
|
|
|
|
theFontMetrics(pb_font).rectText(label, w, a, d);
|
2003-03-13 19:55:39 +00:00
|
|
|
|
2003-07-28 12:20:42 +00:00
|
|
|
int const text_start = int(xo_ + (width_ - w) / 2);
|
2003-03-13 19:55:39 +00:00
|
|
|
int const text_end = text_start + w;
|
|
|
|
|
2007-10-25 12:41:02 +00:00
|
|
|
pi_.pain.rectText(text_start, y + d, label, pb_font, Color_none, Color_none);
|
2003-03-13 19:55:39 +00:00
|
|
|
|
2007-10-25 12:41:02 +00:00
|
|
|
pi_.pain.line(int(xo_ + 1), y, text_start, y, Color_appendix);
|
|
|
|
pi_.pain.line(text_end, y, int(xo_ + width_ - 2), y, Color_appendix);
|
2003-03-13 19:55:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-29 14:12:11 +00:00
|
|
|
void RowPainter::paintTooLargeMarks(bool const left, bool const right) const
|
2014-07-27 16:55:10 +00:00
|
|
|
{
|
|
|
|
if (left)
|
2016-05-22 21:48:28 +00:00
|
|
|
pi_.pain.line(pi_.base.dottedLineThickness(), yo_ - row_.ascent(),
|
|
|
|
pi_.base.dottedLineThickness(), yo_ + row_.descent(),
|
|
|
|
Color_scroll, Painter::line_onoffdash,
|
|
|
|
pi_.base.dottedLineThickness());
|
2014-07-27 16:55:10 +00:00
|
|
|
if (right) {
|
2016-05-22 21:48:28 +00:00
|
|
|
int const wwidth =
|
|
|
|
pi_.base.bv->workWidth() - pi_.base.dottedLineThickness();
|
2014-07-27 16:55:10 +00:00
|
|
|
pi_.pain.line(wwidth, yo_ - row_.ascent(),
|
2015-01-11 16:13:36 +00:00
|
|
|
wwidth, yo_ + row_.descent(),
|
2016-05-22 21:48:28 +00:00
|
|
|
Color_scroll, Painter::line_onoffdash,
|
|
|
|
pi_.base.dottedLineThickness());
|
2014-07-27 16:55:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-29 14:12:11 +00:00
|
|
|
void RowPainter::paintFirst() const
|
2003-02-26 17:04:10 +00:00
|
|
|
{
|
2010-09-06 10:56:27 +00:00
|
|
|
Layout const & layout = par_.layout();
|
2003-02-26 17:04:10 +00:00
|
|
|
|
|
|
|
// start of appendix?
|
2011-10-30 09:16:30 +00:00
|
|
|
if (par_.params().startOfAppendix())
|
2015-10-12 09:55:38 +00:00
|
|
|
paintAppendixStart(yo_ - row_.ascent() + 2 * defaultRowHeight());
|
2003-02-26 17:04:10 +00:00
|
|
|
|
2013-02-09 16:13:01 +00:00
|
|
|
bool const is_first =
|
2016-05-18 07:39:47 +00:00
|
|
|
text_.isFirstInSequence(row_.pit()) || !layout.isParagraphGroup();
|
2007-12-12 19:28:07 +00:00
|
|
|
//lyxerr << "paintFirst: " << par_.id() << " is_seq: " << is_seq << endl;
|
2003-02-26 17:04:10 +00:00
|
|
|
|
2013-02-09 16:13:01 +00:00
|
|
|
if (layout.labelIsInline()
|
2015-10-12 09:55:38 +00:00
|
|
|
&& (layout.labeltype != LABEL_STATIC || is_first))
|
2011-10-30 09:16:30 +00:00
|
|
|
paintLabel();
|
2015-10-12 09:55:38 +00:00
|
|
|
else if (is_first && layout.labelIsAbove())
|
2011-10-30 09:16:30 +00:00
|
|
|
paintTopLevelLabel();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-29 14:12:11 +00:00
|
|
|
void RowPainter::paintLabel() const
|
2011-10-30 09:16:30 +00:00
|
|
|
{
|
2016-06-29 16:51:55 +00:00
|
|
|
docstring const & str = par_.labelString();
|
2011-10-30 09:16:30 +00:00
|
|
|
if (str.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
bool const is_rtl = text_.isRTL(par_);
|
|
|
|
Layout const & layout = par_.layout();
|
|
|
|
FontInfo const font = labelFont();
|
|
|
|
FontMetrics const & fm = theFontMetrics(font);
|
|
|
|
double x = x_;
|
|
|
|
|
2015-07-17 22:07:30 +00:00
|
|
|
if (is_rtl)
|
|
|
|
x = width_ - row_.right_margin + fm.width(layout.labelsep);
|
|
|
|
else
|
|
|
|
x = x_ - fm.width(layout.labelsep) - fm.width(str);
|
2013-02-09 16:13:40 +00:00
|
|
|
|
|
|
|
pi_.pain.text(int(x), yo_, str, font);
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-29 14:12:11 +00:00
|
|
|
void RowPainter::paintTopLevelLabel() const
|
2011-10-30 09:16:30 +00:00
|
|
|
{
|
|
|
|
BufferParams const & bparams = pi_.base.bv->buffer().params();
|
|
|
|
bool const is_rtl = text_.isRTL(par_);
|
|
|
|
ParagraphParameters const & pparams = par_.params();
|
|
|
|
Layout const & layout = par_.layout();
|
|
|
|
FontInfo const font = labelFont();
|
|
|
|
docstring const str = par_.labelString();
|
|
|
|
if (str.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
double spacing_val = 1.0;
|
|
|
|
if (!pparams.spacing().isDefault())
|
|
|
|
spacing_val = pparams.spacing().getValue();
|
|
|
|
else
|
|
|
|
spacing_val = bparams.spacing().getValue();
|
|
|
|
|
|
|
|
FontMetrics const & fm = theFontMetrics(font);
|
|
|
|
|
|
|
|
int const labeladdon = int(fm.maxHeight()
|
|
|
|
* layout.spacing.getValue() * spacing_val);
|
|
|
|
|
|
|
|
int maxdesc =
|
|
|
|
int(fm.maxDescent() * layout.spacing.getValue() * spacing_val
|
|
|
|
+ (layout.labelbottomsep * defaultRowHeight()));
|
|
|
|
|
|
|
|
double x = x_;
|
2013-02-09 16:13:01 +00:00
|
|
|
if (layout.labeltype == LABEL_CENTERED) {
|
2015-07-17 22:07:30 +00:00
|
|
|
x = row_.left_margin + (width_ - row_.left_margin - row_.right_margin) / 2;
|
2011-10-30 09:16:30 +00:00
|
|
|
x -= fm.width(str) / 2;
|
|
|
|
} else if (is_rtl) {
|
2015-07-17 22:07:30 +00:00
|
|
|
x = width_ - row_.right_margin - fm.width(str);
|
2011-10-30 09:16:30 +00:00
|
|
|
}
|
|
|
|
pi_.pain.text(int(x), yo_ - maxdesc - labeladdon, str, font);
|
|
|
|
}
|
|
|
|
|
2012-10-27 13:45:27 +00:00
|
|
|
|
2009-08-09 18:35:39 +00:00
|
|
|
/** Check if the current paragraph is the last paragraph in a
|
|
|
|
proof environment */
|
|
|
|
static int getEndLabel(pit_type p, Text const & text)
|
|
|
|
{
|
|
|
|
ParagraphList const & pars = text.paragraphs();
|
|
|
|
pit_type pit = p;
|
|
|
|
depth_type par_depth = pars[p].getDepth();
|
|
|
|
while (pit != pit_type(pars.size())) {
|
|
|
|
Layout const & layout = pars[pit].layout();
|
|
|
|
int const endlabeltype = layout.endlabeltype;
|
|
|
|
|
|
|
|
if (endlabeltype != END_LABEL_NO_LABEL) {
|
|
|
|
if (p + 1 == pit_type(pars.size()))
|
|
|
|
return endlabeltype;
|
|
|
|
|
|
|
|
depth_type const next_depth =
|
|
|
|
pars[p + 1].getDepth();
|
|
|
|
if (par_depth > next_depth ||
|
|
|
|
(par_depth == next_depth && layout != pars[p + 1].layout()))
|
|
|
|
return endlabeltype;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (par_depth == 0)
|
|
|
|
break;
|
|
|
|
pit = text.outerHook(pit);
|
|
|
|
if (pit != pit_type(pars.size()))
|
|
|
|
par_depth = pars[pit].getDepth();
|
|
|
|
}
|
|
|
|
return END_LABEL_NO_LABEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-17 13:00:09 +00:00
|
|
|
void RowPainter::paintLast() const
|
2003-02-26 17:04:10 +00:00
|
|
|
{
|
2009-08-09 15:29:34 +00:00
|
|
|
bool const is_rtl = text_.isRTL(par_);
|
2016-05-18 07:39:47 +00:00
|
|
|
int const endlabel = getEndLabel(row_.pit(), text_);
|
2003-02-26 17:04:10 +00:00
|
|
|
|
2006-11-23 18:59:05 +00:00
|
|
|
// paint imaginary end-of-paragraph character
|
|
|
|
|
2008-09-22 15:30:26 +00:00
|
|
|
Change const & change = par_.lookupChange(par_.size());
|
|
|
|
if (change.changed()) {
|
2008-09-22 15:41:05 +00:00
|
|
|
FontMetrics const & fm =
|
2008-09-22 15:30:26 +00:00
|
|
|
theFontMetrics(pi_.base.bv->buffer().params().getFont());
|
2006-11-23 18:59:05 +00:00
|
|
|
int const length = fm.maxAscent() / 2;
|
2009-02-09 20:47:32 +00:00
|
|
|
Color col = change.color();
|
2007-05-28 22:27:45 +00:00
|
|
|
|
2007-08-30 13:53:02 +00:00
|
|
|
pi_.pain.line(int(x_) + 1, yo_ + 2, int(x_) + 1, yo_ + 2 - length, col,
|
2010-09-05 14:56:07 +00:00
|
|
|
Painter::line_solid, 3);
|
2008-09-22 15:41:05 +00:00
|
|
|
|
2008-09-22 15:30:26 +00:00
|
|
|
if (change.deleted()) {
|
2008-09-22 15:41:05 +00:00
|
|
|
pi_.pain.line(int(x_) + 1 - length, yo_ + 2, int(x_) + 1 + length,
|
2010-09-05 14:56:07 +00:00
|
|
|
yo_ + 2, col, Painter::line_solid, 3);
|
2008-09-22 15:30:26 +00:00
|
|
|
} else {
|
2008-09-22 15:41:05 +00:00
|
|
|
pi_.pain.line(int(x_) + 1 - length, yo_ + 2, int(x_) + 1,
|
2010-09-05 14:56:07 +00:00
|
|
|
yo_ + 2, col, Painter::line_solid, 3);
|
2008-09-22 15:30:26 +00:00
|
|
|
}
|
2006-11-23 18:59:05 +00:00
|
|
|
}
|
|
|
|
|
2003-02-26 17:04:10 +00:00
|
|
|
// draw an endlabel
|
2006-11-23 18:59:05 +00:00
|
|
|
|
2003-02-26 17:04:10 +00:00
|
|
|
switch (endlabel) {
|
|
|
|
case END_LABEL_BOX:
|
2003-10-28 11:18:40 +00:00
|
|
|
case END_LABEL_FILLED_BOX: {
|
2008-02-27 23:03:26 +00:00
|
|
|
FontInfo const font = labelFont();
|
2006-10-11 17:24:46 +00:00
|
|
|
FontMetrics const & fm = theFontMetrics(font);
|
2006-10-07 16:15:06 +00:00
|
|
|
int const size = int(0.75 * fm.maxAscent());
|
2004-11-30 01:59:49 +00:00
|
|
|
int const y = yo_ - size;
|
2003-02-26 17:04:10 +00:00
|
|
|
|
2008-01-29 07:31:24 +00:00
|
|
|
// If needed, move the box a bit to avoid overlapping with text.
|
2016-08-23 15:43:38 +00:00
|
|
|
int x = 0;
|
|
|
|
if (is_rtl) {
|
|
|
|
int const normal_x = nestMargin() + changebarMargin();
|
|
|
|
x = min(normal_x, row_.left_margin - size - Inset::TEXT_TO_INSET_OFFSET);
|
|
|
|
} else {
|
|
|
|
int const normal_x = width_ - row_.right_margin
|
|
|
|
- size - Inset::TEXT_TO_INSET_OFFSET;
|
|
|
|
x = max(normal_x, row_.width());
|
|
|
|
}
|
2003-02-26 17:04:10 +00:00
|
|
|
|
2003-07-28 12:20:42 +00:00
|
|
|
if (endlabel == END_LABEL_BOX)
|
2007-10-25 12:41:02 +00:00
|
|
|
pi_.pain.rectangle(x, y, size, size, Color_eolmarker);
|
2003-07-28 12:20:42 +00:00
|
|
|
else
|
2007-10-25 12:41:02 +00:00
|
|
|
pi_.pain.fillRectangle(x, y, size, size, Color_eolmarker);
|
2003-02-26 17:04:10 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-10-28 11:18:40 +00:00
|
|
|
|
|
|
|
case END_LABEL_STATIC: {
|
2008-02-27 23:03:26 +00:00
|
|
|
FontInfo const font = labelFont();
|
2006-10-11 17:24:46 +00:00
|
|
|
FontMetrics const & fm = theFontMetrics(font);
|
2008-03-06 21:31:27 +00:00
|
|
|
docstring const & str = par_.layout().endlabelstring();
|
2009-08-22 17:51:41 +00:00
|
|
|
double const x = is_rtl ? x_ - fm.width(str) : x_;
|
2007-08-30 13:53:02 +00:00
|
|
|
pi_.pain.text(int(x), yo_, str, font);
|
2003-02-26 17:04:10 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-10-28 11:18:40 +00:00
|
|
|
|
2003-02-26 17:04:10 +00:00
|
|
|
case END_LABEL_NO_LABEL:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-30 13:19:24 +00:00
|
|
|
void RowPainter::paintOnlyInsets()
|
|
|
|
{
|
2015-07-18 18:37:53 +00:00
|
|
|
Row::const_iterator cit = row_.begin();
|
|
|
|
Row::const_iterator const & end = row_.end();
|
|
|
|
for ( ; cit != end ; ++cit) {
|
|
|
|
Row::Element const & e = *cit;
|
2016-07-20 21:25:17 +00:00
|
|
|
if (e.type == Row::INSET) {
|
|
|
|
paintInset(e);
|
|
|
|
// The line that indicates word in a different language
|
|
|
|
paintForeignMark(e);
|
|
|
|
// change tracking (not for insets that handle it themselves)
|
|
|
|
if (!e.inset->canPaintChange(*pi_.base.bv))
|
|
|
|
paintChange(e);
|
|
|
|
}
|
|
|
|
|
2016-05-17 13:00:09 +00:00
|
|
|
x_ += e.full_width();
|
2007-08-30 13:19:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-18 18:37:53 +00:00
|
|
|
|
2003-03-22 17:26:03 +00:00
|
|
|
void RowPainter::paintText()
|
2015-07-16 21:18:55 +00:00
|
|
|
{
|
|
|
|
Row::const_iterator cit = row_.begin();
|
|
|
|
Row::const_iterator const & end = row_.end();
|
|
|
|
for ( ; cit != end ; ++cit) {
|
|
|
|
Row::Element const & e = *cit;
|
|
|
|
|
|
|
|
switch (e.type) {
|
|
|
|
case Row::STRING:
|
|
|
|
case Row::VIRTUAL:
|
2015-07-18 23:22:10 +00:00
|
|
|
paintStringAndSel(e);
|
2015-07-16 21:18:55 +00:00
|
|
|
|
2015-08-26 11:54:35 +00:00
|
|
|
// Paint the spelling marks if enabled.
|
2015-12-07 09:32:34 +00:00
|
|
|
if (lyxrc.spellcheck_continuously && pi_.do_spellcheck && pi_.pain.isDrawingEnabled())
|
2016-05-17 13:00:09 +00:00
|
|
|
paintMisspelledMark(e);
|
2015-07-16 21:18:55 +00:00
|
|
|
break;
|
2016-05-17 13:00:09 +00:00
|
|
|
|
|
|
|
case Row::INSET:
|
2016-02-28 15:42:35 +00:00
|
|
|
paintInset(e);
|
2015-07-16 21:18:55 +00:00
|
|
|
break;
|
2016-05-17 13:00:09 +00:00
|
|
|
|
2015-07-16 21:18:55 +00:00
|
|
|
case Row::SPACE:
|
2015-07-21 07:51:06 +00:00
|
|
|
pi_.pain.textDecoration(e.font.fontInfo(), int(x_), yo_, int(e.full_width()));
|
2015-07-16 21:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// The line that indicates word in a different language
|
2016-05-17 13:00:09 +00:00
|
|
|
paintForeignMark(e);
|
2015-07-16 21:18:55 +00:00
|
|
|
|
2016-05-22 21:48:28 +00:00
|
|
|
// change tracking (not for insets that handle it themselves)
|
|
|
|
if (e.type != Row::INSET || ! e.inset->canPaintChange(*pi_.base.bv))
|
2016-05-17 13:00:09 +00:00
|
|
|
paintChange(e);
|
|
|
|
|
|
|
|
x_ += e.full_width();
|
2015-07-16 21:18:55 +00:00
|
|
|
}
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
|
|
|
|
2008-02-22 14:05:27 +00:00
|
|
|
|
2015-06-29 14:12:11 +00:00
|
|
|
void RowPainter::paintSelection() const
|
2010-11-25 13:16:30 +00:00
|
|
|
{
|
|
|
|
if (!row_.selection())
|
|
|
|
return;
|
2016-10-25 07:28:14 +00:00
|
|
|
|
2010-11-25 13:16:30 +00:00
|
|
|
int const y1 = yo_ - row_.ascent();
|
|
|
|
int const y2 = y1 + row_.height();
|
2016-10-25 07:28:14 +00:00
|
|
|
bool const rtl = text_.isRTL(par_);
|
2010-11-25 13:16:30 +00:00
|
|
|
|
|
|
|
// draw the margins
|
2016-10-25 07:28:14 +00:00
|
|
|
if ((row_.begin_margin_sel && !rtl) || (row_.end_margin_sel && rtl))
|
|
|
|
pi_.pain.fillRectangle(int(xo_), y1, row_.left_margin, y2 - y1,
|
|
|
|
Color_selection);
|
2010-11-25 13:16:30 +00:00
|
|
|
// go through row and draw from RTL boundary to RTL boundary
|
2016-10-26 08:52:55 +00:00
|
|
|
double x = xo_ + row_.left_margin;
|
2016-10-25 07:28:14 +00:00
|
|
|
for (auto const & e : row_) {
|
|
|
|
// at least part of text selected?
|
|
|
|
bool const some_sel = (e.endpos >= row_.sel_beg && e.pos <= row_.sel_end)
|
|
|
|
|| pi_.selected;
|
|
|
|
// all the text selected?
|
|
|
|
bool const all_sel = (e.pos >= row_.sel_beg && e.endpos <= row_.sel_end)
|
|
|
|
|| pi_.selected;
|
|
|
|
|
|
|
|
if (all_sel) {
|
2016-10-26 08:52:55 +00:00
|
|
|
pi_.pain.fillRectangle(int(x), y1, int(e.full_width()), y2 - y1,
|
2016-10-25 07:28:14 +00:00
|
|
|
Color_selection);
|
|
|
|
} else if (some_sel) {
|
|
|
|
pos_type const from = min(max(row_.sel_beg, e.pos), e.endpos);
|
|
|
|
pos_type const to = max(min(row_.sel_end, e.endpos), e.pos);
|
2016-10-26 08:52:55 +00:00
|
|
|
double x1 = e.pos2x(from);
|
|
|
|
double x2 = e.pos2x(to);
|
2016-10-25 07:28:14 +00:00
|
|
|
if (x1 > x2)
|
|
|
|
swap(x1, x2);
|
2016-10-26 08:52:55 +00:00
|
|
|
pi_.pain.fillRectangle(int(x + x1), y1, int(x2 - x1), y2 - y1,
|
2016-10-25 07:28:14 +00:00
|
|
|
Color_selection);
|
2010-11-25 13:16:30 +00:00
|
|
|
}
|
2016-10-25 07:28:14 +00:00
|
|
|
x += e.full_width();
|
2010-11-25 13:16:30 +00:00
|
|
|
}
|
2016-10-25 14:14:35 +00:00
|
|
|
|
|
|
|
if ((row_.begin_margin_sel && rtl) || (row_.end_margin_sel && !rtl))
|
|
|
|
pi_.pain.fillRectangle(x, y1, int(xo_) + text_metrics_.width() - x, y2 - y1,
|
|
|
|
Color_selection);
|
|
|
|
|
2010-11-25 13:16:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|