]> git.lyx.org Git - lyx.git/blob - src/BufferParams.h
Embedding patch two: read/write embedded files'
[lyx.git] / src / BufferParams.h
1 // -*- C++ -*-
2 /**
3  * \file BufferParams.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author Jean-Marc Lasgouttes
9  * \author John Levon
10  * \author André Pönitz
11  *
12  * Full author contact details are available in file CREDITS.
13  */
14
15 #ifndef BUFFERPARAMS_H
16 #define BUFFERPARAMS_H
17
18 #include "BiblioInfo.h"
19 #include "TextClass.h"
20 #include "TextClass_ptr.h"
21 #include "paper.h"
22
23 #include "insets/InsetQuotes.h"
24
25 #include "support/copied_ptr.h"
26 #include "support/FileName.h"
27 #include "support/types.h"
28
29 #include "frontends/controllers/frontend_helpers.h"
30
31 #include <vector>
32
33 namespace lyx {
34
35 class AuthorList;
36 class BranchList;
37 class Bullet;
38 class Encoding;
39 class Lexer;
40 class LatexFeatures;
41 class Spacing;
42 class TexRow;
43 class VSpace;
44 class Language;
45
46 /** Buffer parameters.
47  *  This class contains all the parameters for this buffer's use. Some
48  *  work needs to be done on this class to make it nice. Now everything
49  *  is in public.
50  */
51 class BufferParams {
52 public:
53         ///
54         enum PARSEP {
55                 ///
56                 PARSEP_INDENT,
57                 ///
58                 PARSEP_SKIP
59         };
60         ///
61         BufferParams();
62         ~BufferParams();
63
64         /// get l10n translated to the buffers language
65         docstring const B_(std::string const & l10n) const;
66
67         /// read a header token, if unrecognised, return it or an unknown class name
68         std::string const readToken(Lexer & lex, std::string const & token);
69
70         ///
71         void writeFile(std::ostream &) const;
72
73         /** \returns true if the babel package is used (interogates
74          *  the BufferParams and a LyXRC variable).
75          *  This returned value can then be passed to the insets...
76          */
77         bool writeLaTeX(odocstream &, LaTeXFeatures &, TexRow &) const;
78
79         ///
80         void useClassDefaults();
81
82         ///
83         bool hasClassDefaults() const;
84
85         ///
86         VSpace const & getDefSkip() const;
87
88         ///
89         void setDefSkip(VSpace const & vs);
90
91         /** Whether paragraphs are separated by using a indent like in
92          *  articles or by using a little skip like in letters.
93          */
94         PARSEP paragraph_separation;
95         ///
96         InsetQuotes::quote_language quotes_language;
97         ///
98         InsetQuotes::quote_times quotes_times;
99         ///
100         std::string fontsize;
101         ///Get the LyX TextClass (that is, the layout file) this document is using.
102         textclass_type getBaseClass() const;
103         ///Set the LyX TextClass (that is, the layout file) this document is using.
104         ///NOTE This also calls makeTextClass(), to update the local
105         ///TextClass.
106         void setBaseClass(textclass_type);
107         ///Returns the TextClass currently in use: the BaseClass as modified
108         ///by modules.
109         TextClass const & getTextClass() const;
110         ///Returns a pointer to the TextClass currently in use: the BaseClass 
111         ///as modified by modules. (See \file TextClass_ptr.h for the typedef.)
112         TextClass_ptr getTextClass_ptr() const;
113         ///Set the LyX TextClass---layout file---this document is using.
114         ///This does NOT call makeTextClass() and so should be used with
115         ///care. This is most likely not what you want if you are operating on 
116         ///BufferParams that are actually associatd with a Buffer. If, on the
117         ///other hand, you are using a temporary set of BufferParams---say, in
118         ///a controller, it may well be, since in that case the local TextClass
119         ///has nothing to do.
120         void setJustBaseClass(textclass_type);
121         /// This bypasses the baseClass and sets the textClass directly.
122         /// Should be called with care and would be better not being here,
123         /// but it seems to be needed by CutAndPaste::putClipboard().
124         void setTextClass(TextClass_ptr);
125         /// List of modules in use
126         std::vector<std::string> const & getModules() const;
127         /// Add a module to the list of modules in use.
128         /// Returns true if module was successfully added.
129         bool addLayoutModule(std::string modName, bool makeClass = true);
130         /// Add a list of modules.
131         /// Returns true if all modules were successfully added.
132         bool addLayoutModules(std::vector<std::string>modNames);
133         /// Clear the list
134         void clearLayoutModules();
135
136         /// returns the main font for the buffer (document)
137         Font const getFont() const;
138
139         /* this are for the PaperLayout */
140         /// the papersize
141         PAPER_SIZE papersize;
142         ///
143         PAPER_ORIENTATION orientation;
144         /// use custom margins
145         bool use_geometry;
146         ///
147         std::string paperwidth;
148         ///
149         std::string paperheight;
150         ///
151         std::string leftmargin;
152         ///
153         std::string topmargin;
154         ///
155         std::string rightmargin;
156         ///
157         std::string bottommargin;
158         ///
159         std::string headheight;
160         ///
161         std::string headsep;
162         ///
163         std::string footskip;
164
165         /* some LaTeX options */
166         /// The graphics driver
167         std::string graphicsDriver;
168         /// the rm font
169         std::string fontsRoman;
170         /// the sf font
171         std::string fontsSans;
172         /// the tt font
173         std::string fontsTypewriter;
174         /// the default family (rm, sf, tt)
175         std::string fontsDefaultFamily;
176         /// use expert Small Caps
177         bool fontsSC;
178         /// use Old Style Figures
179         bool fontsOSF;
180         /// the scale factor of the sf font
181         int fontsSansScale;
182         /// the scale factor of the tt font
183         int fontsTypewriterScale;
184         ///
185         Spacing & spacing();
186         Spacing const & spacing() const;
187         ///
188         int secnumdepth;
189         ///
190         int tocdepth;
191         ///
192         Language const * language;
193         /// BranchList:
194         BranchList & branchlist();
195         BranchList const & branchlist() const;
196         /**
197          * The input encoding for LaTeX. This can be one of
198          * - \c auto: find out the input encoding from the used languages
199          * - \c default: ditto
200          * - any encoding supported by the inputenc package
201          * The encoding of the LyX file is always utf8 and has nothing to
202          * do with this setting.
203          * The difference between \c auto and \c default is that \c auto also
204          * causes loading of the inputenc package, while \c default does not.
205          * \c default will not work unless the user takes additional measures
206          * (such as using special environments like the CJK environment from
207          * CJK.sty).
208          * \c default can be seen as an unspecified 8bit encoding, since LyX
209          * does not interpret it in any way apart from display on screen.
210          */
211         std::string inputenc;
212         /// The main encoding used by this buffer for LaTeX output.
213         /// Individual pieces of text can use different encodings.
214         Encoding const & encoding() const;
215         ///
216         std::string preamble;
217         ///
218         std::string options;
219         ///
220         std::string float_placement;
221         ///
222         unsigned int columns;
223         /// parameters for the listings package
224         std::string listings_params;
225         ///
226         TextClass::PageSides sides;
227         ///
228         std::string pagestyle;
229         /// \param index should lie in the range 0 <= \c index <= 3.
230         Bullet & temp_bullet(size_type index);
231         Bullet const & temp_bullet(size_type index) const;
232         /// \param index should lie in the range 0 <= \c index <= 3.
233         Bullet & user_defined_bullet(size_type index);
234         Bullet const & user_defined_bullet(size_type index) const;
235
236         /// Whether to load a package such as amsmath or esint.
237         /// The enum values must not be changed (file format!)
238         enum Package {
239                 /// Don't load the package. For experts only.
240                 package_off = 0,
241                 /// Load the package if needed (recommended)
242                 package_auto = 1,
243                 /// Always load the package (e.g. if the document contains
244                 /// some ERT that needs the package)
245                 package_on = 2
246         };
247         /// Whether and how to load amsmath
248         Package use_amsmath;
249         /// Whether and how to load esint
250         Package use_esint;
251         ///
252         bool use_bibtopic;
253         /// revision tracking for this buffer ?
254         bool trackChanges;
255         /** This param decides whether change tracking marks should be used
256          *  in output (irrespective of how these marks are actually defined;
257          *  for instance, they may differ for DVI and PDF generation)
258          */
259         bool outputChanges;
260         /// Time ago we agreed that this was a buffer property [ale990407]
261         std::string parentname;
262         ///
263         bool compressed;
264         ///
265         bool embedded;
266
267         /// the author list for the document
268         AuthorList & authors();
269         AuthorList const & authors() const;
270
271         /// map of the file's author IDs to buffer author IDs
272         std::vector<unsigned int> author_map;
273         ///
274         std::string const dvips_options() const;
275         ///
276         std::string const paperSizeName() const;
277         /// set up if and how babel is called
278         std::string const babelCall(std::string const & lang_opts) const;
279         /// handle inputenc etc.
280         void writeEncodingPreamble(odocstream & os, LaTeXFeatures & features,
281                                               TexRow & texrow) const;
282         /// set up the document fonts
283         std::string const loadFonts(std::string const & rm,
284                                      std::string const & sf, std::string const & tt,
285                                      bool const & sc, bool const & osf,
286                                      int const & sfscale, int const & ttscale) const;
287         /// path of the current buffer
288         std::string filepath;
289         /// get the appropriate cite engine (natbib handling)
290         biblio::CiteEngine getEngine() const;
291
292         ///
293         void setCiteEngine(biblio::CiteEngine const);
294
295 private:
296         ///
297         void readPreamble(Lexer &);
298         ///
299         void readLanguage(Lexer &);
300         ///
301         void readGraphicsDriver(Lexer &);
302         ///
303         void readBullets(Lexer &);
304         ///
305         void readBulletsLaTeX(Lexer &);
306         ///
307         void readModules(Lexer &);
308         /// Adds the module information to the baseClass information to
309         /// create our local TextClass.
310         void makeTextClass();
311
312         
313         /// for use with natbib
314         biblio::CiteEngine cite_engine_;
315         /// the base TextClass associated with the document
316         textclass_type baseClass_;
317         /// the possibly modular TextClass actually in use
318         TextClass_ptr textClass_;
319         ///
320         typedef std::vector<std::string> LayoutModuleList;
321         /// 
322         LayoutModuleList layoutModules_;
323
324         /** Use the Pimpl idiom to hide those member variables that would otherwise
325          *  drag in other header files.
326          */
327         class Impl;
328         class MemoryTraits {
329         public:
330                 static Impl * clone(Impl const *);
331                 static void destroy(Impl *);
332         };
333         support::copied_ptr<Impl, MemoryTraits> pimpl_;
334
335 };
336
337 } // namespace lyx
338
339 #endif