]> git.lyx.org Git - lyx.git/blob - src/paragraph_pimpl.h
Fix 3188, update the labels at each Caption insertion.
[lyx.git] / src / paragraph_pimpl.h
1 // -*- C++ -*-
2 /**
3  * \file paragraph_pimpl.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 Jean-Marc Lasgouttes
9  * \author John Levon
10  * \author André Pönitz
11  *
12  * Full author contact details are available in file CREDITS.
13  */
14
15 #ifndef PARAGRAPH_PIMPL_H
16 #define PARAGRAPH_PIMPL_H
17
18 #include "paragraph.h"
19
20 #include "changes.h"
21 #include "lyxfont.h"
22 #include "ParagraphParameters.h"
23
24 #include <boost/scoped_ptr.hpp>
25
26
27 namespace lyx {
28
29 class Encoding;
30 class LyXLayout;
31
32
33 class Paragraph::Pimpl {
34 public:
35         ///
36         Pimpl(Paragraph * owner);
37         /// "Copy constructor"
38         Pimpl(Pimpl const &, Paragraph * owner);
39
40         //
41         // Change tracking
42         //
43         /// look up change at given pos
44         Change const & lookupChange(pos_type pos) const;
45         /// is there a change within the given range ?
46         bool isChanged(pos_type start, pos_type end) const;
47         /// will the paragraph be physically merged with the next
48         /// one if the imaginary end-of-par character is logically deleted?
49         bool isMergedOnEndOfParDeletion(bool trackChanges) const;
50         /// set change for the entire par
51         void setChange(Change const & change);
52         /// set change at given pos
53         void setChange(pos_type pos, Change const & change);
54         /// accept changes within the given range
55         void acceptChanges(BufferParams const & bparams, pos_type start, pos_type end);
56         /// reject changes within the given range
57         void rejectChanges(BufferParams const & bparams, pos_type start, pos_type end);
58
59         ///
60         value_type getChar(pos_type pos) const;
61         ///
62         void insertChar(pos_type pos, value_type c, Change const & change);
63         ///
64         void insertInset(pos_type pos, InsetBase * inset, Change const & change);
65         /// (logically) erase the char at pos; return true if it was actually erased
66         bool eraseChar(pos_type pos, bool trackChanges);
67         /// (logically) erase the given range; return the number of chars actually erased
68         int eraseChars(pos_type start, pos_type end, bool trackChanges);
69         ///
70         InsetBase * inset_owner;
71
72         /** A font entry covers a range of positions. Notice that the
73             entries in the list are inserted in random order.
74             I don't think it's worth the effort to implement a more effective
75             datastructure, because the number of different fonts in a paragraph
76             is limited. (Asger)
77             Nevertheless, I decided to store fontlist using a sorted vector:
78             fontlist = { {pos_1,font_1} , {pos_2,font_2} , ... } where
79             pos_1 < pos_2 < ..., font_{i-1} != font_i for all i,
80             and font_i covers the chars in positions pos_{i-1}+1,...,pos_i
81             (font_1 covers the chars 0,...,pos_1) (Dekel)
82         */
83         class FontTable  {
84         public:
85                 ///
86                 FontTable(pos_type p, LyXFont const & f)
87                         : pos_(p), font_(f)
88                 {}
89                 ///
90                 pos_type pos() const { return pos_; }
91                 ///
92                 void pos(pos_type p) { pos_ = p; }
93                 ///
94                 LyXFont const & font() const { return font_; }
95                 ///
96                 void font(LyXFont const & f) { font_ = f;}
97         private:
98                 /// End position of paragraph this font attribute covers
99                 pos_type pos_;
100                 /** Font. Interpretation of the font values:
101                     If a value is LyXFont::INHERIT_*, it means that the font
102                     attribute is inherited from either the layout of this
103                     paragraph or, in the case of nested paragraphs, from the
104                     layout in the environment one level up until completely
105                     resolved.
106                     The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
107                     allowed in these font tables.
108                 */
109                 LyXFont font_;
110         };
111         ///
112         friend class matchFT;
113         ///
114         class matchFT {
115         public:
116                 /// used by lower_bound and upper_bound
117                 int operator()(FontTable const & a, FontTable const & b) const {
118                         return a.pos() < b.pos();
119                 }
120         };
121
122         ///
123         typedef std::vector<FontTable> FontList;
124         ///
125         FontList fontlist;
126
127         /// Output the surrogate pair formed by \p c and \p next to \p os.
128         /// \return the number of characters written.
129         int latexSurrogatePair(odocstream & os, value_type c, value_type next,
130                                Encoding const &);
131         /// Output a space in appropriate formatting (or a surrogate pair
132         /// if the next character is a combining character).
133         /// \return whether a surrogate pair was output.
134         bool simpleTeXBlanks(BufferParams const &, Encoding const &,
135                              odocstream &, TexRow & texrow,
136                              pos_type & i,
137                              unsigned int & column,
138                              LyXFont const & font,
139                              LyXLayout const & style);
140         ///
141         void simpleTeXSpecialChars(Buffer const &, BufferParams const &,
142                                    Encoding const &, odocstream &,
143                                    TexRow & texrow, OutputParams const &,
144                                    LyXFont & font, LyXFont & running_font,
145                                    LyXFont & basefont,
146                                    LyXFont const & outerfont,
147                                    bool & open_font,
148                                    Change::Type & running_change,
149                                    LyXLayout const & style,
150                                    pos_type & i,
151                                    unsigned int & column, value_type const c);
152
153         ///
154         void validate(LaTeXFeatures & features,
155                       LyXLayout const & layout) const;
156
157         ///
158         unsigned int id_;
159         ///
160         static unsigned int paragraph_id;
161         ///
162         ParagraphParameters params;
163
164 private:
165         ///
166         pos_type size() const { return owner_->size(); }
167         /// match a string against a particular point in the paragraph
168         bool isTextAt(std::string const & str, pos_type pos) const;
169
170         /// for recording and looking up changes
171         Changes changes_;
172
173         /// Who owns us?
174         Paragraph * owner_;
175 };
176
177
178 } // namespace lyx
179
180 #endif