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