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