]> git.lyx.org Git - lyx.git/blob - src/Row.cpp
Introduce LFUN_FONT_BOLDSYMBOL, performing the same as LFUN_FONT_BOLD
[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), changed_(false), crc_(0), 
32         pos_(0), end_(0), left_margin_sel(false), right_margin_sel(false)
33 {}
34
35
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)
40 {}
41
42
43 void Row::setCrc(size_type crc) const
44 {
45         changed_ = crc != crc_;
46         crc_ = crc;
47 }
48
49
50 void Row::setDimension(Dimension const & dim)
51 {
52         dim_ = dim;
53 }
54
55
56 void Row::pos(pos_type p)
57 {
58         pos_ = p;
59 }
60
61
62 void Row::endpos(pos_type p)
63 {
64         end_ = p;
65 }
66
67
68 bool Row::isMarginSelected(bool left_margin, DocIterator const & beg,
69                 DocIterator const & end) const
70 {
71         pos_type const sel_pos = left_margin ? sel_beg : sel_end;
72         pos_type const margin_pos = left_margin ? pos_ : end_;
73
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();
89                 else 
90                         return true;
91         }
92         return false;
93 }
94
95
96 void Row::setSelectionAndMargins(DocIterator const & beg, 
97                 DocIterator const & end) const
98 {
99         setSelection(beg.pos(), end.pos());
100         
101         if (selection()) {
102                 right_margin_sel = isMarginSelected(false, beg, end);
103                 left_margin_sel = isMarginSelected(true, beg, end);
104         }
105 }
106
107
108 void Row::setSelection(pos_type beg, pos_type end) const
109 {
110         if (pos_ >= beg && pos_ <= end)
111                 sel_beg = pos_;
112         else if (beg > pos_ && beg <= end_)
113                 sel_beg = beg;
114         else
115                 sel_beg = -1;
116
117         if (end_ >= beg && end_ <= end)
118                 sel_end = end_;
119         else if (end < end_ && end >= pos_)
120                 sel_end = end;
121         else
122                 sel_end = -1;
123 }
124
125
126 bool Row::selection() const
127 {
128         return sel_beg != -1 && sel_end != -1;
129 }
130
131
132 void Row::dump(char const * s) const
133 {
134         LYXERR0(s << " pos: " << pos_ << " end: " << end_
135                 << " width: " << dim_.wid
136                 << " ascent: " << dim_.asc
137                 << " descent: " << dim_.des);
138 }
139
140
141 } // namespace lyx