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.
51 Element(Type const t, pos_type p, Font const & f, Change const & ch)
52 : type(t), pos(p), endpos(p + 1), inset(0), final(false),
53 font(f), change(ch) {}
56 bool isLineSeparator() const { return type == SEPARATOR; }
58 // The kind of row element
60 // position of the element in the paragraph
62 // first position after the element in the paragraph
64 // The dimension of the chunk (only width for strings)
67 // Non-zero if element is an inset
70 // Non-empty if element is a string or separator
72 // is it possible to add contents to this element?
84 bool changed() const { return changed_; }
86 void setChanged(bool c) { changed_ = c; }
88 void setCrc(size_type crc) const;
89 /// Set the selection begin and end.
91 * This is const because we update the selection status only at draw()
94 void setSelection(pos_type sel_beg, pos_type sel_end) const;
96 bool selection() const;
97 /// Set the selection begin and end and whether the left and/or right
98 /// margins are selected.
99 void setSelectionAndMargins(DocIterator const & beg,
100 DocIterator const & end) const;
103 void pos(pos_type p);
105 pos_type pos() const { return pos_; }
107 void endpos(pos_type p);
109 pos_type endpos() const { return end_; }
111 Dimension const & dimension() const { return dim_; }
113 Dimension & dimension() { return dim_; }
115 int height() const { return dim_.height(); }
117 int width() const { return dim_.wid; }
119 int ascent() const { return dim_.asc; }
121 int descent() const { return dim_.des; }
124 void add(pos_type pos, Inset const * ins, Dimension const & dim,
125 Font const & f, Change const & ch);
127 void add(pos_type pos, char_type const c,
128 Font const & f, Change const & ch);
130 void add(pos_type pos, docstring const & s,
131 Font const & f, Change const & ch);
133 void addSeparator(pos_type pos, char_type const c,
134 Font const & f, Change const & ch);
136 void addSpace(pos_type pos, int width, Font const & f, Change const & ch);
138 bool empty() const { return elements_.empty(); }
140 Element & back() { return elements_.back(); }
142 Element const & back() const { return elements_.back(); }
143 /// remove last element
145 /// remove all row elements
146 void clear() { elements_.clear(); }
148 * remove all elements after last separator and update endpos
150 * \param keep is the minimum amount of text to keep.
152 void separate_back(pos_type keep);
155 * If last element of the row is a string, compute its width
161 * Find sequences of RtL elements and reverse them.
162 * This should be called once the row is completely built.
166 friend std::ostream & operator<<(std::ostream & os, Row const & row);
168 /// width of a separator (i.e. space)
170 /// width of hfills in the label
172 /// the x position of the row
175 mutable pos_type sel_beg;
177 mutable pos_type sel_end;
179 mutable bool begin_margin_sel;
181 mutable bool end_margin_sel;
184 /// Decides whether the margin is selected.
186 * \param margin_begin
190 bool isMarginSelected(bool left_margin, DocIterator const & beg,
191 DocIterator const & end) const;
194 * Returns true if a char or string with font \c f and change
195 * type \c ch can be added to the current last element of the
198 bool sameString(Font const & f, Change const & ch) const;
201 typedef std::vector<Element> Elements;
205 /// has the Row appearance changed since last drawing?
206 mutable bool changed_;
207 /// CRC of row contents.
208 mutable size_type crc_;
209 /// first pos covered by this row
211 /// one behind last pos covered by this row