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