3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
10 * \author Jürgen Vigna
12 * Full author contact details are available in file CREDITS.
14 * Metrics for an on-screen text row.
21 #include "DocIterator.h"
23 #include "support/debug.h"
30 : separator(0), label_hfill(0), x(0),
31 sel_beg(-1), sel_end(-1),
32 left_margin_sel(false), right_margin_sel(false),
33 changed_(false), crc_(0), pos_(0), end_(0)
37 Row::Row(pos_type pos)
38 : separator(0), label_hfill(0), x(0),
39 sel_beg(-1), sel_end(-1),
40 left_margin_sel(false), right_margin_sel(false),
41 changed_(false), crc_(0), pos_(pos), end_(0)
45 void Row::setCrc(size_type crc) const
47 changed_ = crc != crc_;
52 void Row::setDimension(Dimension const & dim)
58 void Row::pos(pos_type p)
64 void Row::endpos(pos_type p)
70 bool Row::isMarginSelected(bool left_margin, DocIterator const & beg,
71 DocIterator const & end) const
73 pos_type const sel_pos = left_margin ? sel_beg : sel_end;
74 pos_type const margin_pos = left_margin ? pos_ : end_;
76 // Is the chosen margin selected ?
77 if (sel_pos == margin_pos) {
78 if (beg.pos() == end.pos())
79 // This is a special case in which the space between after
80 // pos i-1 and before pos i is selected, i.e. the margins
81 // (see DocIterator::boundary_).
82 return beg.boundary() && !end.boundary();
83 else if (end.pos() == margin_pos)
84 // If the selection ends around the margin, it is only
85 // drawn if the cursor is after the margin.
86 return !end.boundary();
87 else if (beg.pos() == margin_pos)
88 // If the selection begins around the margin, it is
89 // only drawn if the cursor is before the margin.
90 return beg.boundary();
98 void Row::setSelectionAndMargins(DocIterator const & beg,
99 DocIterator const & end) const
101 setSelection(beg.pos(), end.pos());
104 right_margin_sel = isMarginSelected(false, beg, end);
105 left_margin_sel = isMarginSelected(true, beg, end);
110 void Row::setSelection(pos_type beg, pos_type end) const
112 if (pos_ >= beg && pos_ <= end)
114 else if (beg > pos_ && beg <= end_)
119 if (end_ >= beg && end_ <= end)
121 else if (end < end_ && end >= pos_)
128 bool Row::selection() const
130 return sel_beg != -1 && sel_end != -1;
134 void Row::dump(char const * s) const
136 LYXERR0(s << " pos: " << pos_ << " end: " << end_
137 << " width: " << dim_.wid
138 << " ascent: " << dim_.asc
139 << " descent: " << dim_.des);