]> git.lyx.org Git - lyx.git/blob - src/layout.h
Dekels arabic patch, + some small things by me
[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 = 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 enum LYX_END_LABEL_TYPES {
150         ///
151         END_LABEL_NO_LABEL,
152         ///
153         END_LABEL_BOX,
154         ///
155         END_LABEL_FILLED_BOX,
156         ///
157         END_LABEL_ENUM_FIRST = END_LABEL_NO_LABEL,
158         ///
159         END_LABEL_ENUM_LAST = END_LABEL_FILLED_BOX
160 };
161                 
162 /* Fix labels are printed flushright, manual labels flushleft. 
163  * MARGIN_MANUAL and MARGIN_FIRST_DYNAMIC are *only* for LABEL_MANUAL,
164  * MARGIN_DYNAMIC and MARGIN_STATIC are *not* for LABEL_MANUAL. 
165  * This seems a funny restriction, but I think other combinations are
166  * not needed, so I will not change it yet. 
167  * Correction: MARGIN_FIRST_DYNAMIC also usable with LABEL_STATIC
168  */
169
170
171 /* There is a parindent and a parskip. Which one is used depends on the 
172  * paragraph_separation-flag of the text-object. 
173  * BUT: parindent is only thrown away, if a parskip is defined! So if you
174  * want a space between the paragraphs and a parindent at the same time, 
175  * you should set parskip to zero and use topsep, parsep and bottomsep.
176  * 
177  * The standard layout is an exception: its parindent is only set, if the 
178  * previous paragraph is standard too. Well, this is LateX and it is good!
179  */ 
180
181
182 /// Attributes of a layout/paragraph environment
183 class LyXTextClass;
184
185 ///
186 class LyXLayout {
187 public:
188         ///
189         LyXLayout ();
190
191         ///
192         bool Read (LyXLex &, LyXTextClass const &);
193         void readAlign(LyXLex &);
194         void readAlignPossible(LyXLex &);
195         void readLabelType(LyXLex &);
196         void readEndLabelType(LyXLex &);
197         void readMargin(LyXLex &);
198         void readLatexType(LyXLex &);
199         void readSpacing(LyXLex &);
200         string const & name() const { return name_; }
201         void name(string const & n) { name_ = n; }
202         string const & obsoleted_by() const { return obsoleted_by_; }
203         string const & latexname() const { return latexname_; }
204         string const & labelstring() const { return labelstring_; }
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         /// Label string inside appendix. "Appendix", ...
344         string labelstring_appendix_;
345
346         /// LaTeX parameter for environment
347         string latexparam_;
348
349         /// Macro definitions needed for this layout
350         string preamble_;
351 };
352
353
354 ///
355 class LyXTextClass {
356 public:
357         ///
358         typedef vector<LyXLayout> LayoutList;
359         ///
360         typedef LayoutList::const_iterator const_iterator;
361         ///
362         typedef LayoutList::size_type size_type;
363         ///
364         LyXTextClass (string const & = string(), 
365                       string const & = string(), 
366                       string const & = string());
367
368         ///
369         const_iterator begin() const { return layoutlist.begin(); }
370         ///
371         const_iterator end() const { return layoutlist.end(); }
372         
373         ///
374         bool Read(string const & filename, bool merge = false);
375         void readOutputType(LyXLex &);
376         void readMaxCounter(LyXLex &);
377         void readClassOptions(LyXLex &);
378         ///
379         bool hasLayout(string const & name) const;
380
381         ///
382         LyXLayout const & GetLayout(string const & vname) const;
383
384         ///
385         LyXLayout & GetLayout(string const & vname);
386
387         /// Sees to that the textclass structure has been loaded
388         void load();
389
390         ///
391         string const & name() const { return name_; }
392         ///
393         string const & latexname() const { return latexname_; }
394         ///
395         string const & description() const { return description_; }
396         ///
397         string const & opt_fontsize() const { return opt_fontsize_; }
398         ///
399         string const & opt_pagestyle() const { return opt_pagestyle_; }
400         ///
401         string const & options() const { return options_; }
402         ///
403         string const & pagestyle() const { return pagestyle_; }
404         ///
405         string const & preamble() const { return preamble_; }
406
407         /// Packages that are already loaded by the class
408         enum Provides {
409                 nothing = 0,
410                 amsmath = 1,
411                 makeidx = 2,
412                 url = 4
413         };
414         bool provides(Provides p) const { return provides_ & p; }
415         
416         ///
417         unsigned int columns() const { return columns_; }
418         ///
419         enum PageSides {
420                 OneSide,
421                 TwoSides
422         };
423         ///
424         PageSides sides() const { return sides_; }
425         ///
426         int secnumdepth() const { return secnumdepth_; }
427         ///
428         int tocdepth() const { return tocdepth_; }
429
430         ///
431         OutputType outputType() const { return outputType_; }
432
433         ///
434         LyXFont const & defaultfont() const { return defaultfont_; }
435
436         /// Text that dictates how wide the left margin is on the screen
437         string const & leftmargin() const { return leftmargin_; }
438
439         /// Text that dictates how wide the right margin is on the screen
440         string const & rightmargin() const { return rightmargin_; }
441         ///
442         int maxcounter() const { return maxcounter_; }
443         ///
444         size_type numLayouts() const { return layoutlist.size(); }
445         ///
446         LyXLayout const & operator[](size_type i) const {
447                 return layoutlist[i];
448         }
449 private:
450         ///
451         bool delete_layout(string const &);
452         ///
453         bool do_readStyle(LyXLex &, LyXLayout &);
454         ///
455         string name_;
456         ///
457         string latexname_;
458         ///
459         string description_;
460         /// Specific class options
461         string opt_fontsize_;
462         ///
463         string opt_pagestyle_;
464         ///
465         string options_;
466         ///
467         string pagestyle_;
468         ///
469         string preamble_;
470         ///
471         Provides provides_;
472         ///
473         unsigned int columns_;
474         ///
475         PageSides sides_;
476         ///
477         int secnumdepth_;
478         ///
479         int tocdepth_;
480         ///
481         OutputType outputType_;
482         /** Base font. The paragraph and layout fonts are resolved against
483             this font. This has to be fully instantiated. Attributes
484             LyXFont::INHERIT, LyXFont::IGNORE, and LyXFont::TOGGLE are
485             extremely illegal.
486         */
487         LyXFont defaultfont_;
488         /// Text that dictates how wide the left margin is on the screen
489         string leftmargin_;
490
491         /// Text that dictates how wide the right margin is on the screen
492         string rightmargin_;
493         ///
494         int maxcounter_; // add approp. signedness
495
496         ///
497         LayoutList layoutlist;
498
499         /// Has this layout file been loaded yet?
500         bool loaded;
501 };
502
503
504 ///
505 inline
506 void operator|=(LyXTextClass::Provides & p1, LyXTextClass::Provides p2)
507 {
508         p1 = static_cast<LyXTextClass::Provides>(p1 | p2);
509 }
510
511
512 ///
513 inline
514 ostream & operator<<(ostream & os, LyXTextClass::PageSides p)
515 {
516         switch (p) {
517         case LyXTextClass::OneSide:
518                 os << "1";
519                 break;
520         case LyXTextClass::TwoSides:
521                 os << "2";
522                 break;
523         }
524         return os;
525 }
526
527
528 ///
529 class LyXTextClassList {
530 public:
531         ///
532         typedef vector<LyXTextClass> ClassList;
533         ///
534         typedef ClassList::const_iterator const_iterator;
535         ///
536         typedef ClassList::size_type size_type;
537         ///
538         const_iterator begin() const { return classlist.begin(); }
539         ///
540         const_iterator end() const { return classlist.end(); }
541         
542         /// Gets layout structure from layout number and textclass number
543         LyXLayout const & Style(size_type textclass,
544                                 LyXTextClass::size_type layout) const;
545
546         /// Gets layout number from textclass number and layout name
547         pair<bool, LyXTextClass::size_type>
548         NumberOfLayout(size_type textclass,
549                        string const & name) const;
550
551         /// Gets a layout name from layout number and textclass number
552         string const &
553         NameOfLayout(size_type textclass,
554                      LyXTextClass::size_type layout) const;
555
556         /** Gets textclass number from name.
557             Returns -1 if textclass name does not exist
558         */
559         pair<bool, size_type>
560         NumberOfClass(string const & textclass) const;
561
562         ///
563         string const & NameOfClass(size_type number) const;
564
565         ///
566         string const & LatexnameOfClass(size_type number) const;
567
568         ///
569         string const & DescOfClass(size_type number) const;
570
571         ///
572         LyXTextClass const & TextClass(size_type textclass) const;
573
574         /** Read textclass list.
575             Returns false if this fails
576         */
577         bool Read();
578
579         /** Load textclass.
580             Returns false if this fails
581         */
582         bool Load(size_type number) const;
583 private:
584         ///
585         mutable ClassList classlist;
586         ///
587         void Add (LyXTextClass const &);
588 };
589
590 /// Should not be declared here!! (Lgb) Why not? (Asger)
591 extern LyXTextClassList textclasslist;
592  
593 #endif