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