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