]> git.lyx.org Git - lyx.git/blob - src/ParagraphMetrics.h
DocBook: fix file inclusion.
[lyx.git] / src / ParagraphMetrics.h
1 // -*- C++ -*-
2 /**
3  * \file ParagraphMetrics.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Asger Alstrup
8  * \author Lars Gullik Bjønnes
9  * \author John Levon
10  * \author André Pönitz
11  * \author Jürgen Vigna
12  * \author Abdelrazak Younes
13  *
14  * Full author contact details are available in file CREDITS.
15  */
16
17 #ifndef PARAGRAPH_METRICS_H
18 #define PARAGRAPH_METRICS_H
19
20 #include "Dimension.h"
21 #include "Row.h"
22
23 #include <vector>
24
25 namespace lyx {
26
27 /**
28  * Each paragraph is broken up into a number of rows on the screen.
29  * This is a list of such on-screen rows, ordered from the top row
30  * downwards.
31  */
32 typedef std::vector<Row> RowList;
33
34 class BufferView;
35 class Paragraph;
36
37 /// Helper class for paragraph metrics.
38 class ParagraphMetrics {
39 public:
40         /// Default constructor (only here for STL containers).
41         ParagraphMetrics() : position_(0), par_(0) {}
42         /// The only useful constructor.
43         explicit ParagraphMetrics(Paragraph const & par);
44
45         /// Copy operator.
46         ParagraphMetrics & operator=(ParagraphMetrics const &);
47
48         void reset(Paragraph const & par);
49
50         ///
51         Row const & getRow(pos_type pos, bool boundary) const;
52         ///
53         size_t pos2row(pos_type pos) const;
54
55         /// TextMetrics::redoParagraph updates this
56         Dimension const & dim() const { return dim_; }
57         Dimension & dim() { return dim_; }
58         /// total height of paragraph
59         int height() const { return dim_.height(); }
60         /// total width of paragraph, may differ from workwidth
61         int width() const { return dim_.width(); }
62         /// ascend of paragraph above baseline
63         int ascent() const { return dim_.ascent(); }
64         /// descend of paragraph below baseline
65         int descent() const { return dim_.descent(); }
66         /// Text updates the rows using this access point
67         RowList & rows() { return rows_; }
68         /// The painter and others use this
69         RowList const & rows() const { return rows_; }
70         ///
71         int rightMargin(BufferView const & bv) const;
72
73         /// dump some information to lyxerr
74         void dump() const;
75
76         ///
77         bool hfillExpansion(Row const & row, pos_type pos) const;
78
79         ///
80         int position() const { return position_; }
81         void setPosition(int position);
82
83 private:
84         ///
85         int position_;
86         ///
87         mutable RowList rows_;
88         /// cached dimensions of paragraph
89         Dimension dim_;
90         ///
91         Paragraph const * par_;
92 };
93
94 } // namespace lyx
95
96 #endif // PARAGRAPH_METRICS_H