]> git.lyx.org Git - lyx.git/blob - src/paragraph_pimpl.h
Don't #include "counters.h" in paragraph.h.
[lyx.git] / src / paragraph_pimpl.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ======================================================
4  *
5  *           LyX, The Document Processor
6  *
7  *          Copyright 1995 Matthias Ettrich
8  *          Copyright 1995-2001 The LyX Team.
9  *
10  * ====================================================== */
11
12 #ifndef PARAGRAPH_PIMPL_H
13 #define PARAGRAPH_PIMPL_H
14
15 #ifdef __GNUG__
16 #pragma interface
17 #endif
18
19 #include "paragraph.h"
20 #include "ParagraphParameters.h"
21 #include "counters.h"
22
23 #include <boost/array.hpp>
24
25 class LyXLayout;
26
27 struct Paragraph::Pimpl {
28         ///
29         typedef std::vector<value_type> TextContainer;
30
31         ///
32         Pimpl(Paragraph * owner);
33         /// Copy constructor
34         Pimpl(Pimpl const &, Paragraph * owner, bool same_ids = false);
35         ///
36         lyx::pos_type size() const {
37                 return text.size();
38         }
39         ///
40         void clear();
41         ///
42         void setContentsFromPar(Paragraph const * par);
43         ///
44         value_type getChar(lyx::pos_type pos) const;
45         ///
46         void setChar(lyx::pos_type pos, value_type c);
47         ///
48         void insertChar(lyx::pos_type pos, value_type c, LyXFont const & font);
49         ///
50         void insertInset(lyx::pos_type pos, Inset * inset, LyXFont const & font);
51         ///
52         void erase(lyx::pos_type pos);
53         ///
54         LyXFont const realizeFont(LyXFont const & font,
55                                   BufferParams const & bparams) const;
56         ///
57         Inset * inset_owner;
58         ///
59         boost::array<int, 10> counter_;
60
61         ///
62         friend struct matchIT;
63         ///
64         struct matchIT {
65                 /// used by lower_bound and upper_bound
66                 inline
67                 int operator()(InsetTable const & a, InsetTable const & b) const {
68                         return a.pos < b.pos;
69                 }
70         };
71         /** A font entry covers a range of positions. Notice that the
72             entries in the list are inserted in random order.
73             I don't think it's worth the effort to implement a more effective
74             datastructure, because the number of different fonts in a paragraph
75             is limited. (Asger)
76             Nevertheless, I decided to store fontlist using a sorted vector:
77             fontlist = { {pos_1,font_1} , {pos_2,font_2} , ... } where
78             pos_1 < pos_2 < ..., font_{i-1} != font_i for all i,
79             and font_i covers the chars in positions pos_{i-1}+1,...,pos_i
80             (font_1 covers the chars 0,...,pos_1) (Dekel)
81         */
82         struct FontTable  {
83                 ///
84                 FontTable(lyx::pos_type p, LyXFont const & f)
85                         : pos_(p)
86                         {
87                                 font_ = container.get(f);
88                         }
89                 ///
90                 lyx::pos_type pos() const { return pos_; }
91                 ///
92                 void pos(lyx::pos_type p) { pos_ = p; }
93                 ///
94                 LyXFont const & font() const { return *font_; }
95                 ///
96                 void font(LyXFont const & f) { font_ = container.get(f);}
97         private:
98                 /// End position of paragraph this font attribute covers
99                 lyx::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                 boost::shared_ptr<LyXFont> font_;
110                 ///
111                 static ShareContainer<LyXFont> container;
112         };
113         ///
114         friend struct matchFT;
115         ///
116         struct matchFT {
117                 /// used by lower_bound and upper_bound
118                 inline
119                 int operator()(FontTable const & a, FontTable const & b) const {
120                         return a.pos() < b.pos();
121                 }
122         };
123
124         ///
125         typedef std::vector<FontTable> FontList;
126         ///
127         FontList fontlist;
128         ///
129         Paragraph * TeXDeeper(Buffer const *, BufferParams const &,
130                                  std::ostream &, TexRow & texrow);
131         ///
132         void simpleTeXBlanks(std::ostream &, TexRow & texrow,
133                              lyx::pos_type const i,
134                              int & column, LyXFont const & font,
135                              LyXLayout const & style);
136         ///
137         void simpleTeXSpecialChars(Buffer const *, BufferParams const &,
138                                    std::ostream &, TexRow & texrow,
139                                    bool moving_arg,
140                                    LyXFont & font, LyXFont & running_font,
141                                    LyXFont & basefont, bool & open_font,
142                                    LyXLayout const & style,
143                                    lyx::pos_type & i,
144                                    int & column, value_type const c);
145
146         ///
147         void validate(LaTeXFeatures & features,
148                       LyXLayout const & layout) const;
149
150         ///
151         Paragraph * getParFromID(int id) const;
152         ///
153         unsigned int id_;
154         ///
155         static unsigned int paragraph_id;
156         ///
157         ParagraphParameters params;
158         ///
159         Counters ctrs;
160
161 private:
162         /// match a string against a particular point in the paragraph
163         bool isTextAt(string const & str, lyx::pos_type pos) const;
164
165         /// Who owns us?
166         Paragraph * owner_;
167         ///
168         TextContainer text;
169 };
170
171 #endif