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