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