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