4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Matthias Ettrich
8 * \author Lars Gullik Bjønnes
10 * Full author contact details are available in file CREDITS.
12 * Metrics for an on-screen text row.
19 #include "Dimension.h"
22 #include "support/docstring.h"
23 #include "support/types.h"
33 * An on-screen row of text. A paragraph is broken into a
34 * RowList for display. Each Row contains position pointers
35 * into the first and last character positions of that row.
40 * One element of a Row. It has a set of attributes that can be used
41 * by other methods that need to parse the Row contents.
52 Element(Type const t, pos_type p, Font const & f, Change const & ch)
53 : type(t), pos(p), endpos(p + 1), inset(0),
54 extra(0), font(f), change(ch), final(false) {}
57 bool isSeparator() const { return type == SEPARATOR; }
58 // returns total width of element, including separator overhead
59 double width() const { return dim.wid + extra; };
60 // returns position in pixels (from the left) of position
61 // \param i in the row element
62 double pos2x(pos_type const i) const;
64 // The kind of row element
66 // position of the element in the paragraph
68 // first position after the element in the paragraph
70 // The dimension of the chunk (does not contains the
71 // separator correction)
74 // Non-zero only if element is an inset
77 // Only non-null for separator elements
80 // Non-empty if element is a string or separator
86 // is it possible to add contents to this element?
89 friend std::ostream & operator<<(std::ostream & os, Element const & row);
96 bool changed() const { return changed_; }
98 void setChanged(bool c) { changed_ = c; }
100 void setCrc(size_type crc) const;
101 /// Set the selection begin and end.
103 * This is const because we update the selection status only at draw()
106 void setSelection(pos_type sel_beg, pos_type sel_end) const;
108 bool selection() const;
109 /// Set the selection begin and end and whether the left and/or right
110 /// margins are selected.
111 void setSelectionAndMargins(DocIterator const & beg,
112 DocIterator const & end) const;
115 void pos(pos_type p);
117 pos_type pos() const { return pos_; }
119 void endpos(pos_type p);
121 pos_type endpos() const { return end_; }
123 Dimension const & dimension() const { return dim_; }
125 Dimension & dimension() { return dim_; }
127 int height() const { return dim_.height(); }
129 int width() const { return dim_.wid; }
131 int ascent() const { return dim_.asc; }
133 int descent() const { return dim_.des; }
136 void add(pos_type pos, Inset const * ins, Dimension const & dim,
137 Font const & f, Change const & ch);
139 void add(pos_type pos, char_type const c,
140 Font const & f, Change const & ch);
142 void addCompletion(pos_type pos, docstring const & s,
143 Font const & f, Change const & ch);
145 void addSeparator(pos_type pos, char_type const c,
146 Font const & f, Change const & ch);
148 void addSpace(pos_type pos, int width, Font const & f, Change const & ch);
151 typedef std::vector<Element> Elements;
153 typedef Elements::iterator iterator;
155 typedef Elements::const_iterator const_iterator;
157 iterator begin() { return elements_.begin(); }
159 iterator end() { return elements_.end(); }
161 const_iterator begin() const { return elements_.begin(); }
163 const_iterator end() const { return elements_.end(); }
166 bool empty() const { return elements_.empty(); }
168 Element & back() { return elements_.back(); }
170 Element const & back() const { return elements_.back(); }
171 /// remove last element
173 /// remove all row elements
174 void clear() { elements_.clear(); }
176 * remove all elements after last separator and update endpos
178 * \param keep is the minimum amount of text to keep.
180 void separate_back(pos_type keep);
183 * If last element of the row is a string, compute its width
189 * Find sequences of RtL elements and reverse them.
190 * This should be called once the row is completely built.
194 friend std::ostream & operator<<(std::ostream & os, Row const & row);
196 /// width of a separator (i.e. space)
198 /// width of hfills in the label
200 /// the x position of the row
203 mutable pos_type sel_beg;
205 mutable pos_type sel_end;
207 mutable bool begin_margin_sel;
209 mutable bool end_margin_sel;
212 /// Decides whether the margin is selected.
214 * \param margin_begin
218 bool isMarginSelected(bool left_margin, DocIterator const & beg,
219 DocIterator const & end) const;
222 * Returns true if a char or string with font \c f and change
223 * type \c ch can be added to the current last element of the
226 bool sameString(Font const & f, Change const & ch) const;
231 /// has the Row appearance changed since last drawing?
232 mutable bool changed_;
233 /// CRC of row contents.
234 mutable size_type crc_;
235 /// first pos covered by this row
237 /// one behind last pos covered by this row