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