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