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