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