]> git.lyx.org Git - lyx.git/blob - src/lyxrow_funcs.C
small stuff, whitespace & consistent naming
[lyx.git] / src / lyxrow_funcs.C
1 /**
2  * \file lyxrow_funcs.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  * \author André Pönitz
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "lyxrow_funcs.h"
15 #include "debug.h"
16 #include "lyxlayout.h"
17 #include "lyxrow.h"
18 #include "paragraph.h"
19
20 using lyx::pos_type;
21
22 using std::max;
23 using std::min;
24 using std::endl;
25
26
27 bool isParEnd(Paragraph const & par, Row const & row)
28 {
29         return row.end() == par.size();
30 }
31
32
33 pos_type lastPos(Paragraph const & par, Row const & row)
34 {
35         if (par.empty())
36                 return 0;
37         pos_type pos = row.end() - 1;
38         if (pos == par.size())
39                 --pos;
40         return pos;
41 }
42
43
44 int numberOfSeparators(Paragraph const & par, Row const & row)
45 {
46         pos_type const last = lastPos(par, row);
47         int n = 0;
48         pos_type p = max(row.pos(), par.beginningOfBody());
49         for ( ; p < last; ++p)
50                 if (par.isSeparator(p))
51                         ++n;
52         return n;
53 }
54
55
56 // This is called _once_ from LyXText and should at least be moved into
57 // an anonymous namespace there. (Lgb)
58 int numberOfHfills(Paragraph const & par, Row const & row)
59 {
60         pos_type const last = lastPos(par, row);
61         pos_type first = row.pos();
62
63         // hfill *DO* count at the beginning of paragraphs!
64         if (first)
65                 while (first < last && par.isHfill(first))
66                         ++first;
67
68         first = max(first, par.beginningOfBody());
69
70         int n = 0;
71
72         // last, because the end is ignored!
73         for (pos_type p = first; p < last; ++p) {
74                 if (par.isHfill(p))
75                         ++n;
76         }
77
78         return n;
79 }
80
81
82 // This is called _once_ from LyXText and should at least be moved into
83 // an anonymous namespace there. (Lgb)
84 int numberOfLabelHfills(Paragraph const & par, Row const & row)
85 {
86         pos_type last = lastPos(par, row);
87         pos_type first = row.pos();
88
89         // hfill *DO* count at the beginning of paragraphs!
90         if (first)
91                 while (first < last && par.isHfill(first))
92                         ++first;
93
94         last = min(last, par.beginningOfBody());
95         int n = 0;
96
97         // last, because the end is ignored
98         for (pos_type p = first; p < last; ++p) {
99                 if (par.isHfill(p))
100                         ++n;
101         }
102
103         return n;
104 }
105
106
107 bool hfillExpansion(Paragraph const & par, Row const & row, pos_type pos)
108 {
109         if (!par.isHfill(pos))
110                 return false;
111
112         // at the end of a row it does not count
113         // unless another hfill exists on the line
114         if (pos >= lastPos(par, row)) {
115                 for (pos_type i = row.pos(); i < pos && !par.isHfill(i); ++i)
116                         return false;
117         }
118
119         // at the beginning of a row it does not count, if it is not
120         // the first row of a paragaph
121         if (row.isParStart())
122                 return true;
123
124         // in some labels it does not count
125         if (par.layout()->margintype != MARGIN_MANUAL
126             && pos < par.beginningOfBody())
127                 return false;
128
129         // if there is anything between the first char of the row and
130         // the specified position that is not a newline and not a hfill,
131         // the hfill will count, otherwise not
132         pos_type i = row.pos();
133         while (i < pos && (par.isNewline(i) || par.isHfill(i)))
134                 ++i;
135
136         return i != pos;
137 }