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