* de.po: sync with branch.
[lyx.git] / src / Row.cpp
blob66b1726d89bd04e09af044f9977cd945e755803e
1 /**
2 * \file Row.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author unknown
7 * \author Lars Gullik Bjønnes
8 * \author John Levon
9 * \author André Pönitz
10 * \author Jürgen Vigna
12 * Full author contact details are available in file CREDITS.
14 * Metrics for an on-screen text row.
17 #include <config.h>
19 #include "Row.h"
21 #include "DocIterator.h"
23 #include "support/debug.h"
26 namespace lyx {
29 Row::Row()
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_;
40 crc_ = crc;
44 void Row::setDimension(Dimension const & dim)
46 dim_ = dim;
50 void Row::pos(pos_type p)
52 pos_ = p;
56 void Row::endpos(pos_type p)
58 end_ = 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();
83 else
84 return true;
86 return false;
90 void Row::setSelectionAndMargins(DocIterator const & beg,
91 DocIterator const & end) const
93 setSelection(beg.pos(), end.pos());
95 if (selection()) {
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)
105 sel_beg = pos_;
106 else if (beg > pos_ && beg <= end_)
107 sel_beg = beg;
108 else
109 sel_beg = -1;
111 if (end_ >= beg && end_ <= end)
112 sel_end = end_;
113 else if (end < end_ && end >= pos_)
114 sel_end = end;
115 else
116 sel_end = -1;
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);
135 } // namespace lyx