]> git.lyx.org Git - lyx.git/blob - src/paragraph_pimpl.h
Herbert's patch, part 1
[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 <boost/array.hpp>
22
23 struct Paragraph::Pimpl {
24         ///
25         Pimpl(Paragraph * owner);
26         /// Copy constructor
27         Pimpl(Pimpl const &, Paragraph * owner, bool same_ids = false);
28         ///
29         Paragraph::size_type size() const {
30                 return text.size();
31         }
32         ///
33         void clear();
34         ///
35         void setContentsFromPar(Paragraph const * par);
36         ///
37         Paragraph::value_type
38         getChar(Paragraph::size_type pos) const;
39         ///
40         void setChar(Paragraph::size_type pos, Paragraph::value_type c);
41         ///
42         void insertChar(Paragraph::size_type pos,
43                         Paragraph::value_type c,
44                         LyXFont const & font);
45         ///
46         void insertInset(Paragraph::size_type pos,
47                          Inset * inset,
48                          LyXFont const & font);
49         ///
50         void erase(Paragraph::size_type pos);
51         ///
52         LyXFont const realizeFont(LyXFont const & font,
53                                   BufferParams const & bparams) const;
54         ///
55         Inset * inset_owner;
56         ///
57         boost::array<int, 10> counter_;
58
59         ///
60         friend struct matchIT;
61         ///
62         struct matchIT {
63                 /// used by lower_bound and upper_bound
64                 inline
65                 int operator()(Paragraph::InsetTable const & a,
66                                Paragraph::InsetTable const & b) const {
67                         return a.pos < b.pos;
68                 }
69         };
70         /** A font entry covers a range of positions. Notice that the
71             entries in the list are inserted in random order.
72             I don't think it's worth the effort to implement a more effective
73             datastructure, because the number of different fonts in a paragraph
74             is limited. (Asger)
75             Nevertheless, I decided to store fontlist using a sorted vector:
76             fontlist = { {pos_1,font_1} , {pos_2,font_2} , ... } where
77             pos_1 < pos_2 < ..., font_{i-1} != font_i for all i,
78             and font_i covers the chars in positions pos_{i-1}+1,...,pos_i
79             (font_1 covers the chars 0,...,pos_1) (Dekel)
80         */
81         struct FontTable  {
82                 ///
83                 FontTable(size_type p, LyXFont const & f)
84                         : pos_(p)
85                         {
86                                 font_ = container.get(f);
87                         }
88                 ///
89                 size_type pos() const { return pos_; }
90                 ///
91                 void pos(size_type p) { pos_ = p; }
92                 ///
93                 LyXFont const & font() const { return *font_; }
94                 ///
95                 void font(LyXFont const & f) { font_ = container.get(f);}
96         private:
97                 /// End position of paragraph this font attribute covers
98                 size_type pos_;
99                 /** Font. Interpretation of the font values:
100                     If a value is LyXFont::INHERIT_*, it means that the font 
101                     attribute is inherited from either the layout of this
102                     paragraph or, in the case of nested paragraphs, from the 
103                     layout in the environment one level up until completely 
104                     resolved.
105                     The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT 
106                     allowed in these font tables.
107                 */
108                 boost::shared_ptr<LyXFont> font_;
109                 ///
110                 static ShareContainer<LyXFont> container;
111         };
112         ///
113         friend struct matchFT;
114         ///
115         struct matchFT {
116                 /// used by lower_bound and upper_bound
117                 inline
118                 int operator()(Paragraph::Pimpl::FontTable const & a,
119                                Paragraph::Pimpl::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                              size_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                                    size_type & i,
144                                    int & column, value_type const c);
145         ///
146         Paragraph * getParFromID(int id) const;
147         ///
148         unsigned int id_;
149         ///
150         static unsigned int paragraph_id;
151         ///
152         ParagraphParameters params;
153 private:
154         /// Who owns us?
155         Paragraph * owner_;
156         ///
157         TextContainer text;
158 };
159
160 #endif