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