]> git.lyx.org Git - lyx.git/blob - src/BufferParams.h
Compare: Actually abort the process when cancel is pressed.
[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 "Citation.h"
19 #include "Font.h"
20 #include "LayoutModuleList.h"
21 #include "paper.h"
22
23 #include "insets/InsetQuotes.h"
24
25 #include "support/copied_ptr.h"
26 #include "support/FileName.h"
27
28 #include <list>
29 #include <map>
30 #include <vector>
31
32 namespace lyx {
33
34 namespace support { class FileName; }
35
36 class AuthorList;
37 class BranchList;
38 class Bullet;
39 class DocumentClass;
40 class Encoding;
41 class HSpace;
42 class IndicesList;
43 class Language;
44 class LatexFeatures;
45 class LayoutFile;
46 class LayoutFileIndex;
47 class Lexer;
48 class PDFOptions;
49 class Spacing;
50 class TexRow;
51 class VSpace;
52
53 /** Buffer parameters.
54  *  This class contains all the parameters for this buffer's use. Some
55  *  work needs to be done on this class to make it nice. Now everything
56  *  is in public.
57  */
58 class BufferParams {
59 public:
60         ///
61         enum ParagraphSeparation {
62                 ///
63                 ParagraphIndentSeparation,
64                 ///
65                 ParagraphSkipSeparation
66         };
67         ///
68         BufferParams();
69
70         /// get l10n translated to the buffers language
71         docstring B_(std::string const & l10n) const;
72
73         /// read a header token, if unrecognised, return it or an unknown class name
74         std::string readToken(Lexer & lex,
75                 std::string const & token, ///< token to read.
76                 support::FileName const & filepath);
77
78         ///
79         void writeFile(std::ostream &) const;
80
81         /// check what features are implied by the buffer parameters.
82         void validate(LaTeXFeatures &) const;
83
84         /** \returns true if the babel package is used (interogates
85          *  the BufferParams and a LyXRC variable).
86          *  This returned value can then be passed to the insets...
87          */
88         bool writeLaTeX(odocstream &, LaTeXFeatures &, TexRow &,
89                         support::FileName const &) const;
90
91         ///
92         void useClassDefaults();
93         ///
94         bool hasClassDefaults() const;
95
96         ///
97         HSpace const & getIndentation() const;
98         ///
99         void setIndentation(HSpace const & indent);
100         ///
101         VSpace const & getDefSkip() const;
102         ///
103         void setDefSkip(VSpace const & vs);
104
105         /** Whether paragraphs are separated by using a indent like in
106          *  articles or by using a little skip like in letters.
107          */
108         ParagraphSeparation paragraph_separation;
109         ///
110         InsetQuotes::QuoteLanguage quotes_language;
111         ///
112         InsetQuotes::QuoteTimes quotes_times;
113         ///
114         std::string fontsize;
115         ///Get the LayoutFile this document is using.
116         LayoutFile const * baseClass() const;
117         ///
118         LayoutFileIndex const & baseClassID() const;
119         /// Set the LyX layout file this document is using.
120         /// NOTE: This does not call makeDocumentClass() to update the local 
121         /// DocumentClass. That needs to be done manually.
122         /// \param filename the name of the layout file
123         bool setBaseClass(std::string const & classname);
124         /// Adds the module information to the baseClass information to
125         /// create our local DocumentClass.
126         void makeDocumentClass();
127         /// Returns the DocumentClass currently in use: the BaseClass as modified
128         /// by modules.
129         DocumentClass const & documentClass() const;
130         /// \return A pointer to the DocumentClass currently in use: the BaseClass 
131         /// as modified by modules. 
132         DocumentClass const * documentClassPtr() const;
133         /// This bypasses the baseClass and sets the textClass directly.
134         /// Should be called with care and would be better not being here,
135         /// but it seems to be needed by CutAndPaste::putClipboard().
136         void setDocumentClass(DocumentClass const * const);
137         /// List of modules in use
138         LayoutModuleList const & getModules() const { return layoutModules_; }
139         /// List of default modules the user has removed
140         std::list<std::string> const & getRemovedModules() const 
141                         { return removedModules_; }
142         ///
143         /// Add a module to the list of modules in use. This checks only that the
144         /// module is not already in the list, so use moduleIsCompatible first if
145         /// you want to check for compatibility.
146         /// \return true if module was successfully added.
147         bool addLayoutModule(std::string const & modName);
148         /// checks to make sure module's requriements are satisfied, that it does
149         /// not conflict with already-present modules, isn't already loaded, etc.
150         bool moduleCanBeAdded(std::string const & modName) const;
151         ///
152         void addRemovedModule(std::string const & modName) 
153                         { removedModules_.push_back(modName); }
154         /// Clear the list
155         void clearLayoutModules() { layoutModules_.clear(); }
156         /// Clear the removed module list
157         void clearRemovedModules() { removedModules_.clear(); }
158
159         /// List of included children (for includeonly)
160         std::list<std::string> const & getIncludedChildren() const 
161                         { return includedChildren_; }
162         ///
163         void addIncludedChildren(std::string const & child) 
164                         { includedChildren_.push_back(child); }
165         /// Clear the list of included children
166         void clearIncludedChildren() { includedChildren_.clear(); }
167
168         /// update aux files of unincluded children (with \includeonly)
169         bool maintain_unincluded_children;
170
171         /// returns the main font for the buffer (document)
172         Font const getFont() const;
173
174         /* these are for the PaperLayout */
175         /// the papersize
176         PAPER_SIZE papersize;
177         ///
178         PAPER_ORIENTATION orientation;
179         /// use custom margins
180         bool use_geometry;
181         ///
182         std::string paperwidth;
183         ///
184         std::string paperheight;
185         ///
186         std::string leftmargin;
187         ///
188         std::string topmargin;
189         ///
190         std::string rightmargin;
191         ///
192         std::string bottommargin;
193         ///
194         std::string headheight;
195         ///
196         std::string headsep;
197         ///
198         std::string footskip;
199         ///
200         std::string columnsep;
201
202         /* some LaTeX options */
203         /// The graphics driver
204         std::string graphicsDriver;
205         /// The default output format
206         std::string defaultOutputFormat;
207         /// customized bibliography processor
208         std::string bibtex_command;
209         /// customized index processor
210         std::string index_command;
211         /// font encoding
212         std::string fontenc;
213         /// the rm font
214         std::string fontsRoman;
215         /// the sf font
216         std::string fontsSans;
217         /// the tt font
218         std::string fontsTypewriter;
219         /// the default family (rm, sf, tt)
220         std::string fontsDefaultFamily;
221         /// use the XeTeX processor
222         bool useXetex;
223         /// use expert Small Caps
224         bool fontsSC;
225         /// use Old Style Figures
226         bool fontsOSF;
227         /// the scale factor of the sf font
228         int fontsSansScale;
229         /// the scale factor of the tt font
230         int fontsTypewriterScale;
231         /// the font used by the CJK command
232         std::string fontsCJK;
233         ///
234         Spacing & spacing();
235         Spacing const & spacing() const;
236         ///
237         int secnumdepth;
238         ///
239         int tocdepth;
240         ///
241         Language const * language;
242         /// BranchList:
243         BranchList & branchlist();
244         BranchList const & branchlist() const;
245         /// IndicesList:
246         IndicesList & indiceslist();
247         IndicesList const & indiceslist() const;
248         /**
249          * The input encoding for LaTeX. This can be one of
250          * - \c auto: find out the input encoding from the used languages
251          * - \c default: ditto
252          * - any encoding supported by the inputenc package
253          * The encoding of the LyX file is always utf8 and has nothing to
254          * do with this setting.
255          * The difference between \c auto and \c default is that \c auto also
256          * causes loading of the inputenc package, while \c default does not.
257          * \c default will not work unless the user takes additional measures
258          * (such as using special environments like the CJK environment from
259          * CJK.sty).
260          * \c default can be seen as an unspecified 8bit encoding, since LyX
261          * does not interpret it in any way apart from display on screen.
262          */
263         std::string inputenc;
264         /// The main encoding used by this buffer for LaTeX output.
265         /// Individual pieces of text can use different encodings.
266         Encoding const & encoding() const;
267         ///
268         std::string preamble;
269         ///
270         std::string local_layout;
271         ///
272         std::string options;
273         /// use the class options defined in the layout?
274         bool use_default_options;
275         ///
276         std::string master;
277         ///
278         bool suppress_date;
279         ///
280         std::string float_placement;
281         ///
282         unsigned int columns;
283         /// parameters for the listings package
284         std::string listings_params;
285         ///
286         PageSides sides;
287         ///
288         std::string pagestyle;
289         ///
290         RGBColor backgroundcolor;
291         /// \param index should lie in the range 0 <= \c index <= 3.
292         Bullet & temp_bullet(size_type index);
293         Bullet const & temp_bullet(size_type index) const;
294         /// \param index should lie in the range 0 <= \c index <= 3.
295         Bullet & user_defined_bullet(size_type index);
296         Bullet const & user_defined_bullet(size_type index) const;
297
298         /// Whether to load a package such as amsmath or esint.
299         /// The enum values must not be changed (file format!)
300         enum Package {
301                 /// Don't load the package. For experts only.
302                 package_off = 0,
303                 /// Load the package if needed (recommended)
304                 package_auto = 1,
305                 /// Always load the package (e.g. if the document contains
306                 /// some ERT that needs the package)
307                 package_on = 2
308         };
309         /// Whether and how to load amsmath
310         Package use_amsmath;
311         /// Whether and how to load esint
312         Package use_esint;
313         /// Whether and how to load mhchem
314         Package use_mhchem;
315         /// Split bibliography?
316         bool use_bibtopic;
317         /// Split the index?
318         bool use_indices;
319         /// revision tracking for this buffer ?
320         bool trackChanges;
321         /** This param decides whether change tracking marks should be used
322          *  in output (irrespective of how these marks are actually defined;
323          *  for instance, they may differ for DVI and PDF generation)
324          */
325         bool outputChanges;
326         ///
327         bool compressed;
328
329         /// the author list for the document
330         AuthorList & authors();
331         AuthorList const & authors() const;
332
333         /// map of the file's author IDs to AuthorList indexes
334         std::map<unsigned int, int> author_map;
335         /// the buffer's font encoding
336         std::string const font_encoding() const;
337         ///
338         std::string const dvips_options() const;
339         /** The return value of paperSizeName() depends on the
340          *  purpose for which the paper size is needed, since they
341          *  support different subsets of paper sizes.
342         */
343         enum PapersizePurpose {
344                 ///
345                 DVIPS,
346                 ///
347                 DVIPDFM,
348                 ///
349                 XDVI
350         };
351         ///
352         std::string paperSizeName(PapersizePurpose purpose) const;
353         /// set up if and how babel is called
354         std::string babelCall(std::string const & lang_opts) const;
355         /// return supported drivers for specific packages
356         docstring getGraphicsDriver(std::string const & package) const;
357         /// handle inputenc etc.
358         void writeEncodingPreamble(odocstream & os, LaTeXFeatures & features,
359                                               TexRow & texrow) const;
360         ///
361         std::string const parseFontName(std::string const & name) const;
362         /// set up the document fonts
363         std::string const loadFonts(std::string const & rm,
364                                      std::string const & sf, std::string const & tt,
365                                      bool const & sc, bool const & osf,
366                                      int const & sfscale, int const & ttscale,
367                                      bool const & xetex) const;
368
369         /// get the appropriate cite engine (natbib handling)
370         CiteEngine citeEngine() const;
371         ///
372         void setCiteEngine(CiteEngine const);
373
374         /// options for pdf output
375         PDFOptions & pdfoptions();
376         PDFOptions const & pdfoptions() const;
377
378         /// whether to use MathML for math output, or instead images
379         bool html_use_mathml;
380         /// whether to attempt to be XHTML 1.1 compliant or instead be
381         /// a little more mellow
382         bool html_be_strict;
383
384 private:
385         ///
386         void readPreamble(Lexer &);
387         ///
388         void readLocalLayout(Lexer &);
389         ///
390         void readLanguage(Lexer &);
391         ///
392         void readGraphicsDriver(Lexer &);
393         ///
394         void readBullets(Lexer &);
395         ///
396         void readBulletsLaTeX(Lexer &);
397         ///
398         void readModules(Lexer &);
399         ///
400         void readRemovedModules(Lexer &);
401         ///
402         void readIncludeonly(Lexer &);
403         /// for use with natbib
404         CiteEngine cite_engine_;
405         ///
406         DocumentClass * doc_class_;
407         /// 
408         LayoutModuleList layoutModules_;
409         /// this is for modules that are required by the document class but that
410         /// the user has chosen not to use
411         std::list<std::string> removedModules_;
412
413         /// the list of included children (for includeonly)
414         std::list<std::string> includedChildren_;
415
416         /** Use the Pimpl idiom to hide those member variables that would otherwise
417          *  drag in other header files.
418          */
419         class Impl;
420         class MemoryTraits {
421         public:
422                 static Impl * clone(Impl const *);
423                 static void destroy(Impl *);
424         };
425         support::copied_ptr<Impl, MemoryTraits> pimpl_;
426
427 };
428
429 } // namespace lyx
430
431 #endif