]> git.lyx.org Git - lyx.git/blob - src/paragraph_pimpl.h
The InsetList
[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         bool empty() const {
41                 return text.empty();
42         }
43         ///
44         void clear();
45         ///
46         void setContentsFromPar(Paragraph const * par);
47         ///
48         value_type getChar(lyx::pos_type pos) const;
49         ///
50         void setChar(lyx::pos_type pos, value_type c);
51         ///
52         void insertChar(lyx::pos_type pos, value_type c, LyXFont const & font);
53         ///
54         void insertInset(lyx::pos_type pos, Inset * inset, LyXFont const & font);
55         ///
56         void erase(lyx::pos_type pos);
57         ///
58         LyXFont const realizeFont(LyXFont const & font,
59                                   BufferParams const & bparams) const;
60         ///
61         Inset * inset_owner;
62         ///
63         boost::array<int, 10> counter_;
64
65         /** A font entry covers a range of positions. Notice that the
66             entries in the list are inserted in random order.
67             I don't think it's worth the effort to implement a more effective
68             datastructure, because the number of different fonts in a paragraph
69             is limited. (Asger)
70             Nevertheless, I decided to store fontlist using a sorted vector:
71             fontlist = { {pos_1,font_1} , {pos_2,font_2} , ... } where
72             pos_1 < pos_2 < ..., font_{i-1} != font_i for all i,
73             and font_i covers the chars in positions pos_{i-1}+1,...,pos_i
74             (font_1 covers the chars 0,...,pos_1) (Dekel)
75         */
76         struct FontTable  {
77                 ///
78                 FontTable(lyx::pos_type p, LyXFont const & f)
79                         : pos_(p)
80                         {
81                                 font_ = container.get(f);
82                         }
83                 ///
84                 lyx::pos_type pos() const { return pos_; }
85                 ///
86                 void pos(lyx::pos_type p) { pos_ = p; }
87                 ///
88                 LyXFont const & font() const { return *font_; }
89                 ///
90                 void font(LyXFont const & f) { font_ = container.get(f);}
91         private:
92                 /// End position of paragraph this font attribute covers
93                 lyx::pos_type pos_;
94                 /** Font. Interpretation of the font values:
95                     If a value is LyXFont::INHERIT_*, it means that the font
96                     attribute is inherited from either the layout of this
97                     paragraph or, in the case of nested paragraphs, from the
98                     layout in the environment one level up until completely
99                     resolved.
100                     The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
101                     allowed in these font tables.
102                 */
103                 boost::shared_ptr<LyXFont> font_;
104                 ///
105                 static ShareContainer<LyXFont> container;
106         };
107         ///
108         friend struct matchFT;
109         ///
110         struct matchFT {
111                 /// used by lower_bound and upper_bound
112                 inline
113                 int operator()(FontTable const & a, FontTable const & b) const {
114                         return a.pos() < b.pos();
115                 }
116         };
117
118         ///
119         typedef std::vector<FontTable> FontList;
120         ///
121         FontList fontlist;
122         ///
123         Paragraph * TeXDeeper(Buffer const *, BufferParams const &,
124                                  std::ostream &, TexRow & texrow);
125         ///
126         void simpleTeXBlanks(std::ostream &, TexRow & texrow,
127                              lyx::pos_type const i,
128                              int & column, LyXFont const & font,
129                              LyXLayout const & style);
130         ///
131         void simpleTeXSpecialChars(Buffer const *, BufferParams const &,
132                                    std::ostream &, TexRow & texrow,
133                                    bool moving_arg,
134                                    LyXFont & font, LyXFont & running_font,
135                                    LyXFont & basefont, bool & open_font,
136                                    LyXLayout const & style,
137                                    lyx::pos_type & i,
138                                    int & column, value_type const c);
139
140         ///
141         void validate(LaTeXFeatures & features,
142                       LyXLayout const & layout) const;
143
144         ///
145         Paragraph * getParFromID(int id) const;
146         ///
147         unsigned int id_;
148         ///
149         static unsigned int paragraph_id;
150         ///
151         ParagraphParameters params;
152         ///
153         Counters ctrs;
154
155 private:
156         /// match a string against a particular point in the paragraph
157         bool isTextAt(string const & str, lyx::pos_type pos) const;
158
159         /// Who owns us?
160         Paragraph * owner_;
161         ///
162         TextContainer text;
163 };
164
165 #endif