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