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::setDimension(Dimension
const & dim
)
50 void Row::pos(pos_type p
)
56 void Row::endpos(pos_type p
)
62 bool Row::isMarginSelected(bool left_margin
, DocIterator
const & beg
,
63 DocIterator
const & end
) const
65 pos_type
const sel_pos
= left_margin
? sel_beg
: sel_end
;
66 pos_type
const margin_pos
= left_margin
? pos_
: end_
;
68 // Is the chosen margin selected ?
69 if (sel_pos
== margin_pos
) {
70 if (beg
.pos() == end
.pos())
71 // This is a special case in which the space between after
72 // pos i-1 and before pos i is selected, i.e. the margins
73 // (see DocIterator::boundary_).
74 return beg
.boundary() && !end
.boundary();
75 else if (end
.pos() == margin_pos
)
76 // If the selection ends around the margin, it is only
77 // drawn if the cursor is after the margin.
78 return !end
.boundary();
79 else if (beg
.pos() == margin_pos
)
80 // If the selection begins around the margin, it is
81 // only drawn if the cursor is before the margin.
82 return beg
.boundary();
90 void Row::setSelectionAndMargins(DocIterator
const & beg
,
91 DocIterator
const & end
) const
93 setSelection(beg
.pos(), end
.pos());
96 end_margin_sel
= isMarginSelected(false, beg
, end
);
97 begin_margin_sel
= isMarginSelected(true, beg
, end
);
102 void Row::setSelection(pos_type beg
, pos_type end
) const
104 if (pos_
>= beg
&& pos_
<= end
)
106 else if (beg
> pos_
&& beg
<= end_
)
111 if (end_
>= beg
&& end_
<= end
)
113 else if (end
< end_
&& end
>= pos_
)
120 bool Row::selection() const
122 return sel_beg
!= -1 && sel_end
!= -1;
126 void Row::dump(char const * s
) const
128 LYXERR0(s
<< " pos: " << pos_
<< " end: " << end_
129 << " width: " << dim_
.wid
130 << " ascent: " << dim_
.asc
131 << " descent: " << dim_
.des
);