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