]> git.lyx.org Git - lyx.git/blob - src/Row.cpp
Update my email and status.
[lyx.git] / src / Row.cpp
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.
5  *
6  * \author unknown
7  * \author Lars Gullik Bjønnes
8  * \author John Levon
9  * \author André Pönitz
10  * \author Jürgen Vigna
11  *
12  * Full author contact details are available in file CREDITS.
13  *
14  * Metrics for an on-screen text row.
15  */
16
17 #include <config.h>
18
19 #include "Row.h"
20
21 #include "DocIterator.h"
22
23 #include "support/debug.h"
24
25
26 namespace lyx {
27
28
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)
34 {}
35
36
37 void Row::setCrc(size_type crc) const
38 {
39         changed_ = crc != crc_;
40         crc_ = crc;
41 }
42
43
44 void Row::setDimension(Dimension const & dim)
45 {
46         dim_ = dim;
47 }
48
49
50 void Row::pos(pos_type p)
51 {
52         pos_ = p;
53 }
54
55
56 void Row::endpos(pos_type p)
57 {
58         end_ = p;
59 }
60
61
62 bool Row::isMarginSelected(bool left_margin, DocIterator const & beg,
63                 DocIterator const & end) const
64 {
65         pos_type const sel_pos = left_margin ? sel_beg : sel_end;
66         pos_type const margin_pos = left_margin ? pos_ : end_;
67
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;
85         }
86         return false;
87 }
88
89
90 void Row::setSelectionAndMargins(DocIterator const & beg, 
91                 DocIterator const & end) const
92 {
93         setSelection(beg.pos(), end.pos());
94         
95         if (selection()) {
96                 end_margin_sel = isMarginSelected(false, beg, end);
97                 begin_margin_sel = isMarginSelected(true, beg, end);
98         }
99 }
100
101
102 void Row::setSelection(pos_type beg, pos_type end) const
103 {
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;
110
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;
117 }
118
119
120 bool Row::selection() const
121 {
122         return sel_beg != -1 && sel_end != -1;
123 }
124
125
126 void Row::dump(char const * s) const
127 {
128         LYXERR0(s << " pos: " << pos_ << " end: " << end_
129                 << " width: " << dim_.wid
130                 << " ascent: " << dim_.asc
131                 << " descent: " << dim_.des);
132 }
133
134
135 } // namespace lyx