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