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