]> git.lyx.org Git - lyx.git/blob - src/layout.h
fixes because of SUN CC warnings, bmtable now compiled with C compilator, countChar...
[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,
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         typedef LayoutList::const_iterator const_iterator;
343
344         ///
345         LyXTextClass (string const & = string(), 
346                       string const & = string(), 
347                       string const & = string());
348
349         ///
350         const_iterator begin() const { return layoutlist.begin(); }
351         ///
352         const_iterator end() const { return layoutlist.end(); }
353         
354         ///
355         bool Read(string const & filename, bool merge = false);
356         void readOutputType(LyXLex &);
357         void readMaxCounter(LyXLex &);
358         void readClassOptions(LyXLex &);
359         ///
360         bool hasLayout(string const & name) const;
361
362         ///
363         LyXLayout const & GetLayout(string const & vname) const;
364
365         ///
366         LyXLayout & GetLayout(string const & vname);
367
368         /// Sees to that the textclass structure has been loaded
369         void load();
370
371         ///
372         string const & name() const { return name_; }
373         ///
374         string const & latexname() const { return latexname_; }
375         ///
376         string const & description() const { return description_; }
377         ///
378         string const & opt_fontsize() const { return opt_fontsize_; }
379         ///
380         string const & opt_pagestyle() const { return opt_pagestyle_; }
381         ///
382         string const & options() const { return options_; }
383         ///
384         string const & pagestyle() const { return pagestyle_; }
385         ///
386         string const & preamble() const { return preamble_; }
387
388         /// Packages that are already loaded by the class
389         enum Provides {
390                 nothing = 0,
391                 amsmath = 1,
392                 makeidx = 2,
393                 url = 4
394         };
395         bool provides(Provides p) const { return provides_ & p; }
396         
397         ///
398         unsigned int columns() const { return columns_; }
399         ///
400         enum PageSides {
401                 OneSide,
402                 TwoSides
403         };
404         ///
405         PageSides sides() const { return sides_; }
406         ///
407         int secnumdepth() const { return secnumdepth_; }
408         ///
409         int tocdepth() const { return tocdepth_; }
410
411         ///
412         OutputType outputType() const { return outputType_; }
413
414         ///
415         LyXFont const & defaultfont() const { return defaultfont_; }
416
417         /// Text that dictates how wide the left margin is on the screen
418         string const & leftmargin() const { return leftmargin_; }
419
420         /// Text that dictates how wide the right margin is on the screen
421         string const & rightmargin() const { return rightmargin_; }
422         ///
423         int maxcounter() const { return maxcounter_; }
424         ///
425         LayoutList::size_type numLayouts() const { return layoutlist.size(); }
426         ///
427         LyXLayout const & operator[](LayoutList::size_type i) const {
428                 return layoutlist[i];
429         }
430 private:
431         ///
432         bool delete_layout(string const &);
433         ///
434         bool do_readStyle(LyXLex &, LyXLayout &);
435         ///
436         string name_;
437         ///
438         string latexname_;
439         ///
440         string description_;
441         /// Specific class options
442         string opt_fontsize_;
443         ///
444         string opt_pagestyle_;
445         ///
446         string options_;
447         ///
448         string pagestyle_;
449         ///
450         string preamble_;
451         ///
452         Provides provides_;
453         ///
454         unsigned int columns_;
455         ///
456         PageSides sides_;
457         ///
458         int secnumdepth_;
459         ///
460         int tocdepth_;
461         ///
462         OutputType outputType_;
463         /** Base font. The paragraph and layout fonts are resolved against
464             this font. This has to be fully instantiated. Attributes
465             LyXFont::INHERIT, LyXFont::IGNORE, and LyXFont::TOGGLE are
466             extremely illegal.
467         */
468         LyXFont defaultfont_;
469         /// Text that dictates how wide the left margin is on the screen
470         string leftmargin_;
471
472         /// Text that dictates how wide the right margin is on the screen
473         string rightmargin_;
474         ///
475         int maxcounter_; // add approp. signedness
476
477         ///
478         LayoutList layoutlist;
479
480         /// Has this layout file been loaded yet?
481         bool loaded;
482 };
483
484
485 ///
486 inline void operator|=(LyXTextClass::Provides & p1, LyXTextClass::Provides p2)
487 {
488         p1 = static_cast<LyXTextClass::Provides>(p1 | p2);
489 }
490
491
492 ///
493 inline ostream & operator<<(ostream & os, LyXTextClass::PageSides p)
494 {
495         switch (p) {
496         case LyXTextClass::OneSide:
497                 os << "1";
498                 break;
499         case LyXTextClass::TwoSides:
500                 os << "2";
501                 break;
502         }
503         return os;
504 }
505
506
507 ///
508 class LyXTextClassList {
509 public:
510         ///
511         typedef vector<LyXTextClass> ClassList;
512         ///
513         typedef ClassList::const_iterator const_iterator;
514         ///
515         const_iterator begin() const { return classlist.begin(); }
516         ///
517         const_iterator end() const { return classlist.end(); }
518         
519         /// Gets layout structure from layout number and textclass number
520         LyXLayout const & Style(ClassList::size_type textclass,
521                                 LyXTextClass::LayoutList::size_type layout) const;
522
523         /// Gets layout number from textclass number and layout name
524         pair<bool, LyXTextClass::LayoutList::size_type>
525         NumberOfLayout(ClassList::size_type textclass,
526                        string const & name) const;
527
528         /// Gets a layout name from layout number and textclass number
529         string const &
530         NameOfLayout(ClassList::size_type textclass,
531                      LyXTextClass::LayoutList::size_type layout) const;
532
533         /** Gets textclass number from name.
534             Returns -1 if textclass name does not exist
535         */
536         pair<bool, ClassList::size_type>
537         NumberOfClass(string const & textclass) const;
538
539         ///
540         string const & NameOfClass(ClassList::size_type number) const;
541
542         ///
543         string const & LatexnameOfClass(ClassList::size_type number) const;
544
545         ///
546         string const & DescOfClass(ClassList::size_type number) const;
547
548         ///
549         LyXTextClass const & TextClass(ClassList::size_type textclass) const;
550
551         /** Read textclass list.
552             Returns false if this fails
553         */
554         bool Read();
555
556         /** Load textclass.
557             Returns false if this fails
558         */
559         bool Load(ClassList::size_type number) const;
560 private:
561         ///
562         mutable ClassList classlist;
563         ///
564         void Add (LyXTextClass const &);
565 };
566
567 /// Should not be declared here!! (Lgb) Why not? (Asger)
568 extern LyXTextClassList textclasslist;
569  
570 #endif