]> git.lyx.org Git - lyx.git/blob - src/Row.cpp
Change TextMetrics::rowHeight to setRowHeight
[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::pos(pos_type p)
45 {
46         pos_ = p;
47 }
48
49
50 void Row::endpos(pos_type p)
51 {
52         end_ = p;
53 }
54
55
56 bool Row::isMarginSelected(bool left_margin, DocIterator const & beg,
57                 DocIterator const & end) const
58 {
59         pos_type const sel_pos = left_margin ? sel_beg : sel_end;
60         pos_type const margin_pos = left_margin ? pos_ : end_;
61
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();
77                 else 
78                         return true;
79         }
80         return false;
81 }
82
83
84 void Row::setSelectionAndMargins(DocIterator const & beg, 
85                 DocIterator const & end) const
86 {
87         setSelection(beg.pos(), end.pos());
88         
89         if (selection()) {
90                 end_margin_sel = isMarginSelected(false, beg, end);
91                 begin_margin_sel = isMarginSelected(true, beg, end);
92         }
93 }
94
95
96 void Row::setSelection(pos_type beg, pos_type end) const
97 {
98         if (pos_ >= beg && pos_ <= end)
99                 sel_beg = pos_;
100         else if (beg > pos_ && beg <= end_)
101                 sel_beg = beg;
102         else
103                 sel_beg = -1;
104
105         if (end_ >= beg && end_ <= end)
106                 sel_end = end_;
107         else if (end < end_ && end >= pos_)
108                 sel_end = end;
109         else
110                 sel_end = -1;
111 }
112
113
114 bool Row::selection() const
115 {
116         return sel_beg != -1 && sel_end != -1;
117 }
118
119
120 void Row::dump(char const * s) const
121 {
122         LYXERR0(s << " pos: " << pos_ << " end: " << end_
123                 << " width: " << dim_.wid
124                 << " ascent: " << dim_.asc
125                 << " descent: " << dim_.des);
126 }
127
128
129 } // namespace lyx