]> git.lyx.org Git - features.git/blob - src/TextMetrics.h
Transfer ParagraphMetrics::rowChangeStatus() to Row::changed(). Prepare for fine...
[features.git] / src / TextMetrics.h
1 // -*- C++ -*-
2 /**
3  * \file TextMetrics.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author John Levon
9  * \author Abdelrazak Younes
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #ifndef TEXT_METRICS_H
15 #define TEXT_METRICS_H
16
17 #include "ParagraphMetrics.h"
18
19 #include "support/types.h"
20
21 #include <boost/utility.hpp>
22 #include <boost/tuple/tuple.hpp>
23
24 #include <map>
25
26
27 namespace lyx {
28
29 class BufferView;
30 class Text;
31 class MetricsInfo;
32
33 /// A map from a Text to the map of paragraphs metrics
34 class TextMetrics
35 {
36 public:
37         /// Default constructor (only here for STL containers).
38         TextMetrics(): text_(0) {}
39         /// The only useful constructor.
40         TextMetrics(BufferView *, Text *);
41         ///
42         ParagraphMetrics const & parMetrics(pit_type) const;
43         ///
44         Dimension const & dimension() const;
45         Dimension const & dimension();
46
47         /// compute text metrics.
48         bool metrics(MetricsInfo & mi, Dimension & dim);
49
50         /// Rebreaks the given paragraph.
51         /// \retval true if a full screen redraw is needed.
52         /// \retval false if a single paragraph redraw is enough.
53         bool redoParagraph(pit_type const pit);
54         /// Clear cache of paragraph metrics
55         void clear() { par_metrics_.clear(); }
56
57         ///
58         int ascent() const { return dim_.asc; }
59         ///
60         int descent() const { return dim_.des; }
61         /// current text width.
62         int width() const { return dim_.wid; }
63         /// current text heigth.
64         int height() const { return dim_.height(); }
65
66         ///
67         int maxWidth() const { return max_width_; }
68         ///
69         int singleWidth(pit_type const pit,     pos_type pos) const;
70
71         ///
72         int rightMargin(ParagraphMetrics const & pm) const;
73         int rightMargin(pit_type const pit) const;
74
75         /** this calculates the specified parameters. needed when setting
76          * the cursor and when creating a visible row */
77         void computeRowMetrics(pit_type pit, Row & row) const;
78
79         ///
80         void draw(PainterInfo & pi, int x, int y) const;
81         
82         void drawParagraph(PainterInfo & pi, pit_type pit, int x, int y,
83                 bool repaintAll) const;
84
85 private:
86         ///
87         ParagraphMetrics & parMetrics(pit_type, bool redo_paragraph);
88
89         /// the minimum space a manual label needs on the screen in pixels
90         int labelFill(pit_type const pit, Row const & row) const;
91
92         /// FIXME??
93         int labelEnd(pit_type const pit) const;
94
95         /// sets row.end to the pos value *after* which a row should break.
96         /// for example, the pos after which isNewLine(pos) == true
97         pit_type rowBreakPoint(
98                 int width,
99                 pit_type const pit,
100                 pit_type first
101                 ) const;
102
103         /// sets row.width to the minimum space a row needs on the screen in pixel
104         int rowWidth(
105                 int right_margin,
106                 pit_type const pit,
107                 pos_type const first,
108                 pos_type const end
109                 ) const;
110
111         /// Calculate and set the height of the row
112         boost::tuple<int, int> rowHeight(
113                 pit_type const pit,
114                 pos_type const first,
115                 pos_type const end
116                 ) const;
117
118 // Temporary public:
119 public:
120         /// returns the column near the specified x-coordinate of the row.
121         /// x is an absolute screen coord, it is set to the real beginning
122         /// of this column.
123         pos_type getColumnNearX(pit_type pit, Row const & row, int & x,
124                 bool & boundary) const;
125
126         /// returns pos in given par at given x coord.
127         pos_type x2pos(pit_type pit, int row, int x) const;
128
129         // FIXME: is there a need for this?
130         //int pos2x(pit_type pit, pos_type pos) const;
131
132 private:
133
134         /// The BufferView owner.
135         BufferView * bv_;
136
137         /// The text contents (the model).
138         /// \todo FIXME: this should be const.
139         Text * text_;
140
141         bool main_text_;
142         /// A map from paragraph index number to paragraph metrics
143         typedef std::map<pit_type, ParagraphMetrics> ParMetricsCache;
144         ///
145         mutable ParMetricsCache par_metrics_;
146         Dimension dim_;
147         int max_width_;
148
149         /// FIXME: transfer this code in CoordCache here.
150         /*
151         /// A map from paragraph index number to screen point
152         typedef std::map<pit_type, Point> InnerParPosCache;
153         /// A map from a Text to the map of paragraphs to screen points
154         typedef std::map<Text const *, InnerParPosCache> ParPosCache;
155         /// Paragraph grouped by owning text
156         ParPosCache pars_;
157         */
158 };
159
160 /// return the default height of a row in pixels, considering font zoom
161 int defaultRowHeight();
162
163 } // namespace lyx
164
165 #endif // TEXT_METRICS_H