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