]> git.lyx.org Git - lyx.git/blob - src/layout.h
use more explicit on constructors use the pimpl idom to reduce size with about 500k
[lyx.git] / src / layout.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ======================================================
4  * 
5  *           LyX, The Document Processor
6  *       
7  *           Copyright 1995 Matthias Ettrich
8  *           Copyright 1995-2000 The LyX Team.
9  *
10  * ====================================================== */
11
12 #ifndef LAYOUT_H
13 #define LAYOUT_H
14
15 #include <vector>
16
17 #ifdef __GNUG__
18 #pragma interface
19 #endif
20
21 #include "lyxlex.h"
22 #include "lyxfont.h"
23 #include "Spacing.h"
24
25
26 /// Reads the style files
27 extern void LyXSetStyle();
28
29 ///
30 enum { // no good name for this
31         ///
32         LYX_ENVIRONMENT_DEFAULT = 97,
33         ///
34         LYX_LAYOUT_DEFAULT = 99
35 };
36 // Could this cause confusion that both DUMMY_LAYOUT and  LAYOUT_DEFAULT has
37 // the same value? (Lgb)
38 ///
39 #define LYX_DUMMY_LAYOUT 99
40
41 /// The different output types
42 enum OutputType {
43         ///
44         LATEX = 1,
45         ///
46         LINUXDOC,
47         ///
48         DOCBOOK,
49         ///
50         LITERATE
51 };
52
53 /// The different margin types
54 enum LYX_MARGIN_TYPE {
55         ///
56         MARGIN_MANUAL = 1,
57         ///
58         MARGIN_FIRST_DYNAMIC,
59         ///
60         MARGIN_DYNAMIC,
61         ///
62         MARGIN_STATIC,
63         ///
64         MARGIN_RIGHT_ADDRESS_BOX
65 };
66
67
68 ///
69 enum LyXAlignment {
70         ///
71         LYX_ALIGN_NONE = 0,
72         ///
73         LYX_ALIGN_BLOCK = 1,
74         ///
75         LYX_ALIGN_LEFT = 2,
76         ///
77         LYX_ALIGN_RIGHT = 4,
78         ///
79         LYX_ALIGN_CENTER = 8,
80         ///
81         LYX_ALIGN_LAYOUT = 16,
82         ///
83         LYX_ALIGN_SPECIAL = 32
84 };
85
86
87 inline
88 void operator|=(LyXAlignment & la1, LyXAlignment la2) {
89         la1 = static_cast<LyXAlignment>(la1 | la2);
90 }
91
92 /// The different LaTeX-Types
93 enum LYX_LATEX_TYPES {
94         ///
95         LATEX_PARAGRAPH = 1,
96         ///
97         LATEX_COMMAND,
98         ///
99         LATEX_ENVIRONMENT,
100         ///
101         LATEX_ITEM_ENVIRONMENT,
102         ///
103         LATEX_LIST_ENVIRONMENT
104 };
105
106 /// The different label types
107 enum LYX_LABEL_TYPES {
108         ///
109         LABEL_NO_LABEL,
110         ///
111         LABEL_MANUAL,
112         ///
113         LABEL_BIBLIO,
114         ///
115         LABEL_TOP_ENVIRONMENT,
116         ///
117         LABEL_CENTERED_TOP_ENVIRONMENT,
118
119         // the flushright labels following now must start with LABEL_STATIC
120         ///
121         LABEL_STATIC,
122         ///
123         LABEL_SENSITIVE,
124         ///
125         LABEL_COUNTER_CHAPTER,
126         ///
127         LABEL_COUNTER_SECTION,
128         ///
129         LABEL_COUNTER_SUBSECTION,
130         ///
131         LABEL_COUNTER_SUBSUBSECTION,
132         ///
133         LABEL_COUNTER_PARAGRAPH,
134         ///
135         LABEL_COUNTER_SUBPARAGRAPH,
136         ///
137         LABEL_COUNTER_ENUMI,
138         ///
139         LABEL_COUNTER_ENUMII,
140         ///
141         LABEL_COUNTER_ENUMIII,
142         ///
143         LABEL_COUNTER_ENUMIV,
144         ///
145         LABEL_FIRST_COUNTER = LABEL_COUNTER_CHAPTER
146 };
147
148 enum LYX_END_LABEL_TYPES {
149         ///
150         END_LABEL_NO_LABEL,
151         ///
152         END_LABEL_BOX,
153         ///
154         END_LABEL_FILLED_BOX,
155         ///
156         END_LABEL_ENUM_FIRST = END_LABEL_NO_LABEL,
157         ///
158         END_LABEL_ENUM_LAST = END_LABEL_FILLED_BOX
159 };
160                 
161 /* Fix labels are printed flushright, manual labels flushleft. 
162  * MARGIN_MANUAL and MARGIN_FIRST_DYNAMIC are *only* for LABEL_MANUAL,
163  * MARGIN_DYNAMIC and MARGIN_STATIC are *not* for LABEL_MANUAL. 
164  * This seems a funny restriction, but I think other combinations are
165  * not needed, so I will not change it yet. 
166  * Correction: MARGIN_FIRST_DYNAMIC also usable with LABEL_STATIC
167  */
168
169
170 /* There is a parindent and a parskip. Which one is used depends on the 
171  * paragraph_separation-flag of the text-object. 
172  * BUT: parindent is only thrown away, if a parskip is defined! So if you
173  * want a space between the paragraphs and a parindent at the same time, 
174  * you should set parskip to zero and use topsep, parsep and bottomsep.
175  * 
176  * The standard layout is an exception: its parindent is only set, if the 
177  * previous paragraph is standard too. Well, this is LateX and it is good!
178  */ 
179
180
181 /// Attributes of a layout/paragraph environment
182 class LyXTextClass;
183
184 ///
185 class LyXLayout {
186 public:
187         ///
188         LyXLayout ();
189
190         ///
191         bool Read (LyXLex &, LyXTextClass const &);
192         void readAlign(LyXLex &);
193         void readAlignPossible(LyXLex &);
194         void readLabelType(LyXLex &);
195         void readEndLabelType(LyXLex &);
196         void readMargin(LyXLex &);
197         void readLatexType(LyXLex &);
198         void readSpacing(LyXLex &);
199         string const & name() const { return name_; }
200         void name(string const & n) { name_ = n; }
201         string const & obsoleted_by() const { return obsoleted_by_; }
202         string const & latexname() const { return latexname_; }
203         string const & labelstring() const { return labelstring_; }
204         string const & preamble() const { return preamble_; }
205         string const & latexparam() const { return latexparam_; }
206         string const & labelstring_appendix() const {
207                 return labelstring_appendix_;
208         }
209         /** Default font for this layout/environment.
210             The main font for this kind of environment. If an attribute has
211             LyXFont::INHERITED_*, it means that the value is specified by
212             the defaultfont for the entire layout. If we are nested, the
213             font is inherited from the font in the environment one level
214             up until the font is resolved. The values LyXFont::IGNORE_*
215             and LyXFont::TOGGLE are illegal here.
216         */
217         LyXFont font;
218
219         /** Default font for labels.
220             Interpretation the same as for font above
221         */
222         LyXFont labelfont;
223
224         /** Resolved version of the font for this layout/environment.
225             This is a resolved version the default font. The font is resolved
226             against the defaultfont of the entire layout.
227         */
228         LyXFont resfont;
229
230         /** Resolved version of the font used for labels.
231             This is a resolved version the label font. The font is resolved
232             against the defaultfont of the entire layout.
233         */
234         LyXFont reslabelfont;
235
236         /// Text that dictates how wide the left margin is on the screen
237         string leftmargin;
238
239         /// Text that dictates how wide the right margin is on the screen
240         string rightmargin;
241
242         /// Text that dictates how much space to leave after a potential label
243         string labelsep;
244
245         /// Text that dictates how much space to leave before a potential label
246         string labelindent;
247
248         /** Text that dictates the width of the indentation of
249             indented paragraphs.
250         */
251         string parindent;
252
253         ///
254         float parskip;
255
256         ///
257         float itemsep;
258
259         ///
260         float topsep;
261
262         ///
263         float bottomsep;
264
265         ///
266         float labelbottomsep;
267
268         ///
269         float parsep;
270
271         ///
272         Spacing spacing;
273
274         ///
275         LyXAlignment align;
276
277         ///
278         LyXAlignment alignpossible;
279
280         ///
281         char labeltype; // add approp. type
282
283         ///
284         char endlabeltype;
285
286         ///
287         LYX_MARGIN_TYPE margintype;
288
289         ///
290         bool fill_top;
291
292         ///
293         bool fill_bottom;
294
295         ///
296         bool newline_allowed;
297
298         ///
299         bool nextnoindent;
300
301         ///
302         bool free_spacing;
303         /// true when the fragile commands in the paragraph need to be
304         /// \protect'ed.
305         bool needprotect;
306         /// true when empty paragraphs should be kept.
307         bool keepempty;
308         ///
309         bool isParagraph() const {
310                 return latextype == LATEX_PARAGRAPH;
311         }
312         ///
313         bool isCommand() const { 
314                 return latextype == LATEX_COMMAND;
315         }
316         ///
317         bool isEnvironment() const {
318                 return (latextype == LATEX_ENVIRONMENT
319                         || latextype == LATEX_ITEM_ENVIRONMENT
320                         || latextype == LATEX_LIST_ENVIRONMENT);
321         }
322         /// Type of LaTeX object
323         LYX_LATEX_TYPES latextype;
324         /// Does this object belong in the title part of the document?
325         bool intitle;
326 private:
327         /// Name of the layout/paragraph environment
328         string name_;
329
330         /** Name of an layout that has replaced this layout.
331             This is used to rename a layout, while keeping backward
332             compatibility 
333         */
334         string obsoleted_by_;
335
336         /// LaTeX name for environment
337         string latexname_;
338
339         /// Label string. "Abstract", "Reference", "Caption"...
340         string labelstring_;
341
342         /// Label string inside appendix. "Appendix", ...
343         string labelstring_appendix_;
344
345         /// LaTeX parameter for environment
346         string latexparam_;
347
348         /// Macro definitions needed for this layout
349         string preamble_;
350 };
351
352
353 ///
354 class LyXTextClass {
355 public:
356         ///
357         typedef std::vector<LyXLayout> LayoutList;
358         ///
359         typedef LayoutList::const_iterator const_iterator;
360         ///
361         typedef LayoutList::size_type size_type;
362         ///
363         explicit
364         LyXTextClass (string const & = string(), 
365                       string const & = string(), 
366                       string const & = string());
367
368         ///
369         const_iterator begin() const { return layoutlist.begin(); }
370         ///
371         const_iterator end() const { return layoutlist.end(); }
372         
373         ///
374         bool Read(string const & filename, bool merge = false);
375         void readOutputType(LyXLex &);
376         void readMaxCounter(LyXLex &);
377         void readClassOptions(LyXLex &);
378         ///
379         bool hasLayout(string const & name) const;
380
381         ///
382         LyXLayout const & GetLayout(string const & vname) const;
383
384         ///
385         LyXLayout & GetLayout(string const & vname);
386
387         /// Sees to that the textclass structure has been loaded
388         void load();
389
390         ///
391         string const & name() const { return name_; }
392         ///
393         string const & latexname() const { return latexname_; }
394         ///
395         string const & description() const { return description_; }
396         ///
397         string const & opt_fontsize() const { return opt_fontsize_; }
398         ///
399         string const & opt_pagestyle() const { return opt_pagestyle_; }
400         ///
401         string const & options() const { return options_; }
402         ///
403         string const & pagestyle() const { return pagestyle_; }
404         ///
405         string const & preamble() const { return preamble_; }
406
407         /// Packages that are already loaded by the class
408         enum Provides {
409                 nothing = 0,
410                 amsmath = 1,
411                 makeidx = 2,
412                 url = 4
413         };
414         bool provides(Provides p) const { return provides_ & p; }
415         
416         ///
417         unsigned int columns() const { return columns_; }
418         ///
419         enum PageSides {
420                 OneSide,
421                 TwoSides
422         };
423         ///
424         PageSides sides() const { return sides_; }
425         ///
426         int secnumdepth() const { return secnumdepth_; }
427         ///
428         int tocdepth() const { return tocdepth_; }
429
430         ///
431         OutputType outputType() const { return outputType_; }
432
433         ///
434         LyXFont const & defaultfont() const { return defaultfont_; }
435
436         /// Text that dictates how wide the left margin is on the screen
437         string const & leftmargin() const { return leftmargin_; }
438
439         /// Text that dictates how wide the right margin is on the screen
440         string const & rightmargin() const { return rightmargin_; }
441         ///
442         int maxcounter() const { return maxcounter_; }
443         ///
444         size_type numLayouts() const { return layoutlist.size(); }
445         ///
446         LyXLayout const & operator[](size_type i) const {
447                 return layoutlist[i];
448         }
449 private:
450         ///
451         bool delete_layout(string const &);
452         ///
453         bool do_readStyle(LyXLex &, LyXLayout &);
454         ///
455         string name_;
456         ///
457         string latexname_;
458         ///
459         string description_;
460         /// Specific class options
461         string opt_fontsize_;
462         ///
463         string opt_pagestyle_;
464         ///
465         string options_;
466         ///
467         string pagestyle_;
468         ///
469         string preamble_;
470         ///
471         Provides provides_;
472         ///
473         unsigned int columns_;
474         ///
475         PageSides sides_;
476         ///
477         int secnumdepth_;
478         ///
479         int tocdepth_;
480         ///
481         OutputType outputType_;
482         /** Base font. The paragraph and layout fonts are resolved against
483             this font. This has to be fully instantiated. Attributes
484             LyXFont::INHERIT, LyXFont::IGNORE, and LyXFont::TOGGLE are
485             extremely illegal.
486         */
487         LyXFont defaultfont_;
488         /// Text that dictates how wide the left margin is on the screen
489         string leftmargin_;
490
491         /// Text that dictates how wide the right margin is on the screen
492         string rightmargin_;
493         ///
494         int maxcounter_; // add approp. signedness
495
496         ///
497         LayoutList layoutlist;
498
499         /// Has this layout file been loaded yet?
500         bool loaded;
501 };
502
503
504 ///
505 inline
506 void operator|=(LyXTextClass::Provides & p1, LyXTextClass::Provides p2)
507 {
508         p1 = static_cast<LyXTextClass::Provides>(p1 | p2);
509 }
510
511
512 ///
513 std::ostream & operator<<(std::ostream & os, LyXTextClass::PageSides p);
514
515
516 ///
517 class LyXTextClassList {
518 public:
519         ///
520         typedef std::vector<LyXTextClass> ClassList;
521         ///
522         typedef ClassList::const_iterator const_iterator;
523         ///
524         typedef ClassList::size_type size_type;
525         ///
526         const_iterator begin() const { return classlist.begin(); }
527         ///
528         const_iterator end() const { return classlist.end(); }
529         
530         /// Gets layout structure from layout number and textclass number
531         LyXLayout const & Style(size_type textclass,
532                                 LyXTextClass::size_type layout) const;
533
534         /// Gets layout number from textclass number and layout name
535         std::pair<bool, LyXTextClass::size_type>
536         NumberOfLayout(size_type textclass,
537                        string const & name) const;
538
539         /// Gets a layout name from layout number and textclass number
540         string const &
541         NameOfLayout(size_type textclass,
542                      LyXTextClass::size_type layout) const;
543
544         /** Gets textclass number from name.
545             Returns -1 if textclass name does not exist
546         */
547         std::pair<bool, size_type>
548         NumberOfClass(string const & textclass) const;
549
550         ///
551         string const & NameOfClass(size_type number) const;
552
553         ///
554         string const & LatexnameOfClass(size_type number) const;
555
556         ///
557         string const & DescOfClass(size_type number) const;
558
559         ///
560         LyXTextClass const & TextClass(size_type textclass) const;
561
562         /** Read textclass list.
563             Returns false if this fails
564         */
565         bool Read();
566
567         /** Load textclass.
568             Returns false if this fails
569         */
570         bool Load(size_type number) const;
571 private:
572         ///
573         mutable ClassList classlist;
574         ///
575         void Add (LyXTextClass const &);
576 };
577
578 /// Should not be declared here!! (Lgb) Why not? (Asger)
579 extern LyXTextClassList textclasslist;
580  
581 #endif