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), changed_(false), crc_(0),
32 pos_(0), end_(0), left_margin_sel(false), right_margin_sel(false)
36 Row::Row(pos_type pos)
37 : separator(0), label_hfill(0), x(0),
38 sel_beg(-1), sel_end(-1), changed_(false), crc_(0),
39 pos_(0), end_(0), left_margin_sel(false), right_margin_sel(false)
43 void Row::setCrc(size_type crc) const
45 changed_ = crc != crc_;
50 void Row::setDimension(Dimension const & dim)
56 void Row::pos(pos_type p)
62 void Row::endpos(pos_type p)
68 bool Row::isMarginSelected(bool left_margin, DocIterator const & beg,
69 DocIterator const & end) const
71 pos_type const sel_pos = left_margin ? sel_beg : sel_end;
72 pos_type const margin_pos = left_margin ? pos_ : end_;
74 // Is the chosen margin selected ?
75 if (sel_pos == margin_pos) {
76 if (beg.pos() == end.pos())
77 // This is a special case in which the space between after
78 // pos i-1 and before pos i is selected, i.e. the margins
79 // (see DocIterator::boundary_).
80 return beg.boundary() && !end.boundary();
81 else if (end.pos() == margin_pos)
82 // If the selection ends around the margin, it is only
83 // drawn if the cursor is after the margin.
84 return !end.boundary();
85 else if (beg.pos() == margin_pos)
86 // If the selection begins around the margin, it is
87 // only drawn if the cursor is before the margin.
88 return beg.boundary();
96 void Row::setSelectionAndMargins(DocIterator const & beg,
97 DocIterator const & end) const
99 setSelection(beg.pos(), end.pos());
102 right_margin_sel = isMarginSelected(false, beg, end);
103 left_margin_sel = isMarginSelected(true, beg, end);
108 void Row::setSelection(pos_type beg, pos_type end) const
110 if (pos_ >= beg && pos_ <= end)
112 else if (beg > pos_ && beg <= end_)
117 if (end_ >= beg && end_ <= end)
119 else if (end < end_ && end >= pos_)
126 bool Row::selection() const
128 return sel_beg != -1 && sel_end != -1;
132 void Row::dump(char const * s) const
134 LYXERR0(s << " pos: " << pos_ << " end: " << end_
135 << " width: " << dim_.wid
136 << " ascent: " << dim_.asc
137 << " descent: " << dim_.des);