]> git.lyx.org Git - lyx.git/blob - src/paragraph.h
remove unused stuff
[lyx.git] / src / paragraph.h
1 // -*- C++ -*-
2 /**
3  * \file paragraph.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  *
13  * Full author contact details are available in file CREDITS.
14  */
15
16 #ifndef PARAGRAPH_H
17 #define PARAGRAPH_H
18
19 #include "changes.h"
20 #include "dimension.h"
21 #include "InsetList.h"
22 #include "lyxlayout_ptr_fwd.h"
23 #include "RowList_fwd.h"
24
25 #include "insets/insetbase.h" // only for InsetBase::Code
26
27
28 namespace lyx {
29
30
31 class Buffer;
32 class BufferParams;
33 class BufferView;
34 class Counters;
35 class InsetBase;
36 class InsetBibitem;
37 class LaTeXFeatures;
38 class InsetBase_code;
39 class Language;
40 class LyXFont;
41 class LyXFont_size;
42 class MetricsInfo;
43 class OutputParams;
44 class PainterInfo;
45 class ParagraphParameters;
46 class TexRow;
47
48
49 class FontSpan {
50 public:
51         /// Invalid font span containing no character
52         FontSpan() : first(0), last(-1) {}
53         /// Span including first and last
54         FontSpan(pos_type f, pos_type l) : first(f), last(l) {}
55
56 public:
57         /// Range including first and last.
58         pos_type first, last;
59 };
60
61 /// Helper class for Paragraph Metrics.
62 /// \todo FIXME: this class deserves its own .[Ch] files.
63 /// Then, the storage of such object should be done in \c BufferView 
64 /// (most probably in the \c CoordCache class along \c Point objects).
65 class ParagraphMetrics  {
66 public:
67         ///
68         Row & getRow(pos_type pos, bool boundary);
69         ///
70         Row const & getRow(pos_type pos, bool boundary) const;
71         ///
72         size_t pos2row(pos_type pos) const;
73
74         /// LyXText::redoParagraph updates this
75         Dimension & dim() { return dim_; }
76         /// total height of paragraph
77         unsigned int height() const { return dim_.height(); }
78         /// total width of paragraph, may differ from workwidth
79         unsigned int width() const { return dim_.width(); }
80         /// ascend of paragraph above baseline
81         unsigned int ascent() const { return dim_.ascent(); }
82         /// descend of paragraph below baseline
83         unsigned int descent() const { return dim_.descent(); }
84         /// LyXText updates the rows using this access point
85         RowList & rows() { return rows_; }
86         /// The painter and others use this
87         RowList const & rows() const { return rows_; }
88         ///
89         RowSignature & rowSignature() const { return rowSignature_; }
90
91         /// dump some information to lyxerr
92         void dump() const;
93
94 private:
95         ///
96         mutable RowList rows_;
97         ///
98         mutable RowSignature rowSignature_;
99         /// cached dimensions of paragraph
100         Dimension dim_;
101 };
102
103
104 /// A Paragraph holds all text, attributes and insets in a text paragraph
105 /// \todo FIXME: any reference to ParagraphMetrics (including inheritance)
106 /// should go in order to complete the Model/View separation of this class.
107 class Paragraph: public ParagraphMetrics  {
108 public:
109         ///
110         enum {
111                 /// Note that this is 1 right now to avoid
112                 /// crashes where getChar() is called wrongly
113                 /// (returning 0) - if this was 0, then we'd
114                 /// try getInset() and crash. We should fix
115                 /// all these places.
116                 //META_INSET = 1 // as in trunk
117                 META_INSET = 0x200001  // above 0x10ffff, for ucs-4
118         };
119         ///
120         typedef char_type value_type;
121         ///
122         typedef std::vector<value_type> TextContainer;
123
124         ///
125         Paragraph();
126         ///
127         Paragraph(Paragraph const &);
128         ///
129         Paragraph & operator=(Paragraph const &);
130         ///
131         ~Paragraph();
132         ///
133         int id() const;
134
135
136         ///
137         Language const * getParLanguage(BufferParams const &) const;
138         ///
139         bool isRightToLeftPar(BufferParams const &) const;
140         ///
141         void changeLanguage(BufferParams const & bparams,
142                             Language const * from, Language const * to);
143         ///
144         bool isMultiLingual(BufferParams const &) const;
145
146         ///
147         docstring const asString(Buffer const &,
148                                    OutputParams const & runparams,
149                                    bool label) const;
150         ///
151         docstring const asString(Buffer const &, bool label) const;
152         ///
153         docstring const asString(Buffer const & buffer,
154                                    pos_type beg,
155                                    pos_type end,
156                                    bool label) const;
157         ///
158         docstring const asString(Buffer const &,
159                                    OutputParams const & runparams,
160                                    pos_type beg,
161                                    pos_type end,
162                                    bool label) const;
163
164         ///
165         void write(Buffer const &, std::ostream &, BufferParams const &,
166                    depth_type & depth) const;
167         ///
168         void validate(LaTeXFeatures &) const;
169
170         ///
171         int startTeXParParams(BufferParams const &, odocstream &, bool) const;
172
173         ///
174         int endTeXParParams(BufferParams const &, odocstream &, bool) const;
175
176
177         ///
178         bool simpleTeXOnePar(Buffer const &, BufferParams const &,
179                              LyXFont const & outerfont, odocstream &,
180                              TexRow & texrow, OutputParams const &) const;
181
182         /// Can we drop the standard paragraph wrapper?
183         bool emptyTag() const;
184
185         /// Get the id of the paragraph, usefull for docbook
186         std::string getID(Buffer const & buf,
187                           OutputParams const & runparams) const;
188
189         // Get the first word of a paragraph, return the position where it left
190         pos_type getFirstWord(Buffer const & buf,
191                                    odocstream & os,
192                                    OutputParams const & runparams) const;
193
194         /// Checks if the paragraph contains only text and no inset or font change.
195         bool onlyText(Buffer const & buf, LyXFont const & outerfont,
196                       pos_type initial) const;
197
198         /// Writes to stream the docbook representation
199         void simpleDocBookOnePar(Buffer const & buf,
200                                  odocstream &,
201                                  OutputParams const & runparams,
202                                  LyXFont const & outerfont,
203                                  pos_type initial = 0) const;
204
205         ///
206         bool hasSameLayout(Paragraph const & par) const;
207
208         ///
209         void makeSameLayout(Paragraph const & par);
210
211         ///
212         void setInsetOwner(InsetBase * inset);
213         ///
214         InsetBase * inInset() const;
215         ///
216         InsetBase::Code ownerCode() const;
217         ///
218         bool forceDefaultParagraphs() const;
219
220         ///
221         pos_type size() const { return text_.size(); }
222         ///
223         bool empty() const { return text_.empty(); }
224         ///
225         void clearContents();
226
227         ///
228         LyXLayout_ptr const & layout() const;
229         ///
230         void layout(LyXLayout_ptr const & new_layout);
231
232         /// This is the item depth, only used by enumerate and itemize
233         signed char itemdepth;
234
235         ///
236         InsetBibitem * bibitem() const;  // ale970302
237
238         /// look up change at given pos
239         Change const lookupChange(pos_type pos) const;
240
241         /// is there a change within the given range ?
242         bool isChanged(pos_type start, pos_type end) const;
243         /// is there an unchanged char at the given pos ?
244         bool isUnchanged(pos_type pos) const {
245                 return lookupChange(pos).type == Change::UNCHANGED;
246         }
247         /// is there an insertion at the given pos ?
248         bool isInserted(pos_type pos) const {
249                 return lookupChange(pos).type == Change::INSERTED;
250         }
251         /// is there a deletion at the given pos ?
252         bool isDeleted(pos_type pos) const {
253                 return lookupChange(pos).type == Change::DELETED;
254         }
255
256         /// will the paragraph be physically merged with the next
257         /// one if the imaginary end-of-par character is logically deleted?
258         bool isMergedOnEndOfParDeletion(bool trackChanges) const;
259
260         /// set change for the entire par
261         void setChange(Change const & change);
262
263         /// set change at given pos
264         void setChange(pos_type pos, Change const & change);
265
266         /// accept changes within the given range
267         void acceptChanges(pos_type start, pos_type end);
268
269         /// reject changes within the given range
270         void rejectChanges(pos_type start, pos_type end);
271
272         /// Paragraphs can contain "manual labels", for example, Description
273         /// environment. The text for this user-editable label is stored in
274         /// the paragraph alongside the text of the rest of the paragraph
275         /// (the body). This function returns the starting position of the
276         /// body of the text in the paragraph.
277         pos_type beginOfBody() const;
278         /// recompute this value
279         void setBeginOfBody();
280
281         ///
282         docstring const & getLabelstring() const;
283
284         /// the next two functions are for the manual labels
285         docstring const getLabelWidthString() const;
286         ///
287         void setLabelWidthString(docstring const & s);
288         /// Actual paragraph alignment used
289         char getAlign() const;
290         /// The nesting depth of a paragraph
291         depth_type getDepth() const;
292         /// The maximal possible depth of a paragraph after this one
293         depth_type getMaxDepthAfter() const;
294         ///
295         void applyLayout(LyXLayout_ptr const & new_layout);
296
297         /// (logically) erase the char at pos; return true if it was actually erased
298         bool eraseChar(pos_type pos, bool trackChanges);
299         /// (logically) erase the given range; return the number of chars actually erased
300         int eraseChars(pos_type start, pos_type end, bool trackChanges);
301
302         /** Get uninstantiated font setting. Returns the difference
303             between the characters font and the layoutfont.
304             This is what is stored in the fonttable
305         */
306         LyXFont const
307         getFontSettings(BufferParams const &, pos_type pos) const;
308         ///
309         LyXFont const getFirstFontSettings(BufferParams const &) const;
310
311         /** Get fully instantiated font. If pos == -1, use the layout
312             font attached to this paragraph.
313             If pos == -2, use the label font of the layout attached here.
314             In all cases, the font is instantiated, i.e. does not have any
315             attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
316             LyXFont::TOGGLE.
317         */
318         LyXFont const getFont(BufferParams const &, pos_type pos,
319                               LyXFont const & outerfont) const;
320         LyXFont const getLayoutFont(BufferParams const &,
321                                     LyXFont const & outerfont) const;
322         LyXFont const getLabelFont(BufferParams const &,
323                                    LyXFont const & outerfont) const;
324         /**
325          * The font returned by the above functions is the same in a
326          * span of characters. This method will return the first and
327          * the last positions in the paragraph for which that font is
328          * the same. This can be used to avoid unnecessary calls to
329    * getFont.
330          */
331         FontSpan fontSpan(pos_type pos) const;
332         ///
333         /// this is a bottleneck.
334         value_type getChar(pos_type pos) const { return text_[pos]; }
335         /// Get the char, but mirror all bracket characters if it is right-to-left
336         value_type getUChar(BufferParams const &, pos_type pos) const;
337         /// pos <= size() (there is a dummy font change at the end of each par)
338         void setFont(pos_type pos, LyXFont const & font);
339         /// Returns the height of the highest font in range
340         LyXFont_size highestFontInRange(pos_type startpos,
341                                         pos_type endpos, LyXFont_size def_size) const;
342         ///
343         void insert(pos_type pos, docstring const & str,
344                     LyXFont const & font, Change const & change);
345         ///
346         void insertChar(pos_type pos, value_type c, bool trackChanges);
347         ///
348         void insertChar(pos_type pos, value_type c,
349                         LyXFont const &, bool trackChanges);
350         ///
351         void insertChar(pos_type pos, value_type c,
352                         LyXFont const &, Change const & change);
353         ///
354         void insertInset(pos_type pos, InsetBase * inset,
355                          Change const & change);
356         ///
357         void insertInset(pos_type pos, InsetBase * inset,
358                          LyXFont const &, Change const & change);
359         ///
360         bool insetAllowed(InsetBase_code code);
361         ///
362         InsetBase * getInset(pos_type pos) {
363                 return insetlist.get(pos);
364         }
365         ///
366         InsetBase const * getInset(pos_type pos) const {
367                 return insetlist.get(pos);
368         }
369
370         ///
371         bool isHfill(pos_type pos) const {
372                 return isInset(pos)
373                        && getInset(pos)->lyxCode() == InsetBase::HFILL_CODE;
374         }
375         /// hinted by profiler
376         bool isInset(pos_type pos) const {
377                 return getChar(pos) == static_cast<value_type>(META_INSET);
378         }
379         ///
380         bool isNewline(pos_type pos) const;
381         /// return true if the char is a word separator
382         bool isSeparator(pos_type pos) const { return getChar(pos) == ' '; }
383         ///
384         bool isLineSeparator(pos_type pos) const;
385         /// True if the character/inset at this point can be part of a word
386         // Note that digits in particular are considered as letters
387         bool isLetter(pos_type pos) const;
388
389         /// returns -1 if inset not found
390         int getPositionOfInset(InsetBase const * inset) const;
391
392         /// Returns the number of line breaks and white-space stripped at the start
393         int stripLeadingSpaces();
394
395         /// return true if we allow multiple spaces
396         bool isFreeSpacing() const;
397
398         /// return true if we allow this par to stay empty
399         bool allowEmpty() const;
400         ///
401         char_type transformChar(char_type c, pos_type pos) const;
402         ///
403         ParagraphParameters & params();
404         ///
405         ParagraphParameters const & params() const;
406         ///
407         bool hfillExpansion(Row const & row, pos_type pos) const;
408
409 public:
410         ///
411         InsetList insetlist;
412
413 private:
414
415         ///
416         LyXLayout_ptr layout_;
417         /**
418          * Keeping this here instead of in the pimpl makes LyX >10% faster
419          * for average tasks as buffer loading/switching etc.
420          */
421         TextContainer text_;
422         /// end of label
423         pos_type begin_of_body_;
424
425         /// Pimpl away stuff
426         class Pimpl;
427         ///
428         friend class Paragraph::Pimpl;
429         ///
430         Pimpl * pimpl_;
431 };
432
433 } // namespace lyx
434
435 #endif // PARAGRAPH_H