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 begin_margin_sel(false), end_margin_sel(false),
33 changed_(false), crc_(0), pos_(0), end_(0)
37 void Row::setCrc(size_type crc) const
39 changed_ = crc != crc_;
44 void Row::pos(pos_type p)
50 void Row::endpos(pos_type p)
56 bool Row::isMarginSelected(bool left_margin, DocIterator const & beg,
57 DocIterator const & end) const
59 pos_type const sel_pos = left_margin ? sel_beg : sel_end;
60 pos_type const margin_pos = left_margin ? pos_ : end_;
62 // Is the chosen margin selected ?
63 if (sel_pos == margin_pos) {
64 if (beg.pos() == end.pos())
65 // This is a special case in which the space between after
66 // pos i-1 and before pos i is selected, i.e. the margins
67 // (see DocIterator::boundary_).
68 return beg.boundary() && !end.boundary();
69 else if (end.pos() == margin_pos)
70 // If the selection ends around the margin, it is only
71 // drawn if the cursor is after the margin.
72 return !end.boundary();
73 else if (beg.pos() == margin_pos)
74 // If the selection begins around the margin, it is
75 // only drawn if the cursor is before the margin.
76 return beg.boundary();
84 void Row::setSelectionAndMargins(DocIterator const & beg,
85 DocIterator const & end) const
87 setSelection(beg.pos(), end.pos());
90 end_margin_sel = isMarginSelected(false, beg, end);
91 begin_margin_sel = isMarginSelected(true, beg, end);
96 void Row::setSelection(pos_type beg, pos_type end) const
98 if (pos_ >= beg && pos_ <= end)
100 else if (beg > pos_ && beg <= end_)
105 if (end_ >= beg && end_ <= end)
107 else if (end < end_ && end >= pos_)
114 bool Row::selection() const
116 return sel_beg != -1 && sel_end != -1;
120 void Row::dump(char const * s) const
122 LYXERR0(s << " pos: " << pos_ << " end: " << end_
123 << " width: " << dim_.wid
124 << " ascent: " << dim_.asc
125 << " descent: " << dim_.des);