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) : type(t), pos(0), inset(0),
55 bool isLineSeparator() const { return type == SEPARATOR_ELT; }
57 // The kind of row element
59 // position of the element in the paragraph
61 // The dimension of the chunk (only width for strings)
64 // Non-zero if element is an inset
67 // Non-empty if element is a string or separator
69 // is it possible to add contents to this element?
81 bool changed() const { return changed_; }
83 void setChanged(bool c) { changed_ = c; }
85 void setCrc(size_type crc) const;
86 /// Set the selection begin and end.
88 * This is const because we update the selection status only at draw()
91 void setSelection(pos_type sel_beg, pos_type sel_end) const;
93 bool selection() const;
94 /// Set the selection begin and end and whether the left and/or right
95 /// margins are selected.
96 void setSelectionAndMargins(DocIterator const & beg,
97 DocIterator const & end) const;
100 void pos(pos_type p);
102 pos_type pos() const { return pos_; }
104 void endpos(pos_type p);
106 pos_type endpos() const { return end_; }
108 Dimension const & dimension() const { return dim_; }
110 Dimension & dimension() { return dim_; }
112 int height() const { return dim_.height(); }
114 int width() const { return dim_.wid; }
116 int ascent() const { return dim_.asc; }
118 int descent() const { return dim_.des; }
121 void add(pos_type pos, Inset const * ins, Dimension const & dim);
123 void add(pos_type pos, docstring const & s,
124 Font const & f, Change const & ch);
126 void add(pos_type pos, char_type const c,
127 Font const & f, Change const & ch);
129 void addSeparator(pos_type pos, char_type const c,
130 Font const & f, Change const & ch);
132 void addSpace(pos_type pos, int width);
134 bool empty() const { return elements_.empty(); }
136 Element & back() { return elements_.back(); }
138 Element const & back() const { return elements_.back(); }
139 /// remove last element
141 /// remove all row elements
142 void clear() { elements_.clear(); }
144 * remove all elements after last separator and update endpos
146 * \param keep is the minimum amount of text to keep.
148 void separate_back(pos_type keep);
151 * If last element of the row is a string, compute its width
156 friend std::ostream & operator<<(std::ostream & os, Row const & row);
158 /// current debugging only
159 void dump(char const * = "") const;
161 /// width of a separator (i.e. space)
163 /// width of hfills in the label
165 /// the x position of the row
168 mutable pos_type sel_beg;
170 mutable pos_type sel_end;
172 mutable bool begin_margin_sel;
174 mutable bool end_margin_sel;
177 /// Decides whether the margin is selected.
179 * \param margin_begin
183 bool isMarginSelected(bool left_margin, DocIterator const & beg,
184 DocIterator const & end) const;
187 * Returns true if a char or string with font \c f and change
188 * type \c ch can be added to the current last element of the
191 bool sameString(Font const & f, Change const & ch) const;
194 typedef std::vector<Element> Elements;
198 /// has the Row appearance changed since last drawing?
199 mutable bool changed_;
200 /// CRC of row contents.
201 mutable size_type crc_;
202 /// first pos covered by this row
204 /// one behind last pos covered by this row