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