This commit was manufactured by cvs2svn to create tag
[lyx.git] / src / layout.h
blob96231b143c3515dded30564af5e722619fb3a97a
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.
10 * ====================================================== */
12 #ifndef LAYOUT_H
13 #define LAYOUT_H
15 #ifdef __GNUG__
16 #pragma interface
17 #endif
19 #include <vector>
21 #include "definitions.h"
22 #include "lyxlex.h"
23 #include "lyxfont.h"
24 #include "Spacing.h"
26 /// Reads the style files
27 extern void LyXSetStyle();
29 /// The different output types
30 enum OutputType {
31 ///
32 LATEX,
33 ///
34 LINUXDOC,
35 ///
36 DOCBOOK,
37 ///
38 LITERATE
41 /// The different margin types
42 enum LYX_MARGIN_TYPE {
43 ///
44 MARGIN_MANUAL,
45 ///
46 MARGIN_FIRST_DYNAMIC,
47 ///
48 MARGIN_DYNAMIC,
49 ///
50 MARGIN_STATIC,
51 ///
52 MARGIN_RIGHT_ADDRESS_BOX
55 ///
56 enum LyXAlignment {
57 ///
58 LYX_ALIGN_NONE = 0,
59 ///
60 LYX_ALIGN_BLOCK = 1,
61 ///
62 LYX_ALIGN_LEFT = 2,
63 ///
64 LYX_ALIGN_RIGHT = 4,
65 ///
66 LYX_ALIGN_CENTER = 8,
67 ///
68 LYX_ALIGN_LAYOUT = 16,
69 ///
70 LYX_ALIGN_SPECIAL = 32
72 inline void operator|=(LyXAlignment & la1, LyXAlignment la2) {
73 la1 = static_cast<LyXAlignment>(la1 | la2);
76 /// The different LaTeX-Types
77 enum LYX_LATEX_TYPES {
78 ///
79 LATEX_PARAGRAPH,
80 ///
81 LATEX_COMMAND,
82 ///
83 LATEX_ENVIRONMENT,
84 ///
85 LATEX_ITEM_ENVIRONMENT,
86 ///
87 LATEX_LIST_ENVIRONMENT
90 /// The different label types
91 enum LYX_LABEL_TYPES {
92 ///
93 LABEL_NO_LABEL,
94 ///
95 LABEL_MANUAL,
96 ///
97 LABEL_BIBLIO,
98 ///
99 LABEL_TOP_ENVIRONMENT,
101 LABEL_CENTERED_TOP_ENVIRONMENT,
103 // the flushright labels following now must start with LABEL_STATIC
105 LABEL_STATIC,
107 LABEL_SENSITIVE,
109 LABEL_COUNTER_CHAPTER,
111 LABEL_COUNTER_SECTION,
113 LABEL_COUNTER_SUBSECTION,
115 LABEL_COUNTER_SUBSUBSECTION,
117 LABEL_COUNTER_PARAGRAPH,
119 LABEL_COUNTER_SUBPARAGRAPH,
121 LABEL_COUNTER_ENUMI,
123 LABEL_COUNTER_ENUMII,
125 LABEL_COUNTER_ENUMIII,
127 LABEL_COUNTER_ENUMIV,
129 LABEL_FIRST_COUNTER = LABEL_COUNTER_CHAPTER
133 /* Fix labels are printed flushright, manual labels flushleft.
134 * MARGIN_MANUAL and MARGIN_FIRST_DYNAMIC are *only* for LABEL_MANUAL,
135 * MARGIN_DYNAMIC and MARGIN_STATIC are *not* for LABEL_MANUAL.
136 * This seems a funny restriction, but I think other combinations are
137 * not needed, so I will not change it yet.
138 * Correction: MARGIN_FIRST_DYNAMIC also usable with LABEL_STATIC
142 /* There is a parindent and a parskip. Which one is used depends on the
143 * paragraph_separation-flag of the text-object.
144 * BUT: parindent is only thrown away, if a parskip is defined! So if you
145 * want a space between the paragraphs and a parindent at the same time,
146 * you should set parskip to zero and use topsep, parsep and bottomsep.
148 * The standard layout is an exception: its parindent is only set, if the
149 * previous paragraph is standard too. Well, this is LateX and it is good!
153 /// Attributes of a layout/paragraph environment
154 class LyXTextClass;
157 class LyXLayout {
158 public:
160 LyXLayout ();
163 bool Read (LyXLex &, LyXTextClass const &);
165 string const & name() const { return name_; }
166 void name(string const & n) { name_ = n; }
167 string const & obsoleted_by() const { return obsoleted_by_; }
168 string const & latexname() const { return latexname_; }
169 string const & labelstring() const { return labelstring_; }
170 string const & preamble() const { return preamble_; }
171 string const & latexparam() const { return latexparam_; }
172 string const & labelstring_appendix() const { return labelstring_appendix_; }
173 /** Default font for this layout/environment.
174 The main font for this kind of environment. If an attribute has
175 LyXFont::INHERITED_*, it means that the value is specified by
176 the defaultfont for the entire layout. If we are nested, the
177 font is inherited from the font in the environment one level
178 up until the font is resolved. The values LyXFont::IGNORE_*
179 and LyXFont::TOGGLE are illegal here.
181 LyXFont font;
183 /** Default font for labels.
184 Interpretation the same as for font above
186 LyXFont labelfont;
188 /** Resolved version of the font for this layout/environment.
189 This is a resolved version the default font. The font is resolved
190 against the defaultfont of the entire layout.
192 LyXFont resfont;
194 /** Resolved version of the font used for labels.
195 This is a resolved version the label font. The font is resolved
196 against the defaultfont of the entire layout.
198 LyXFont reslabelfont;
200 /// Text that dictates how wide the left margin is on the screen
201 string leftmargin;
203 /// Text that dictates how wide the right margin is on the screen
204 string rightmargin;
206 /// Text that dictates how much space to leave after a potential label
207 string labelsep;
209 /// Text that dictates how much space to leave before a potential label
210 string labelindent;
212 /** Text that dictates the width of the indentation of
213 indented paragraphs.
215 string parindent;
218 float parskip;
221 float itemsep;
224 float topsep;
227 float bottomsep;
230 float labelbottomsep;
233 float parsep;
236 Spacing spacing;
239 LyXAlignment align; // add approp. signedness
242 LyXAlignment alignpossible; // add approp. signedness
245 char labeltype; // add approp. signedness
248 char margintype; // add approp. signedness
251 bool fill_top;
254 bool fill_bottom;
257 bool newline_allowed;
260 bool nextnoindent;
263 bool free_spacing;
264 /// true when the fragile commands in the paragraph need to be
265 /// \protect'ed.
266 bool needprotect;
267 /// true when empty paragraphs should be kept.
268 bool keepempty;
270 bool isParagraph() const {
271 return latextype == LATEX_PARAGRAPH;
274 bool isCommand() const {
275 return latextype == LATEX_COMMAND;
278 bool isEnvironment() const {
279 return (latextype == LATEX_ENVIRONMENT
280 || latextype == LATEX_ITEM_ENVIRONMENT
281 || latextype == LATEX_LIST_ENVIRONMENT);
283 /// Type of LaTeX object
284 LYX_LATEX_TYPES latextype;
285 /// Does this object belong in the title part of the document?
286 bool intitle;
287 private:
288 /// Name of the layout/paragraph environment
289 string name_;
291 /** Name of an layout that has replaced this layout.
292 This is used to rename a layout, while keeping backward
293 compatibility
295 string obsoleted_by_;
297 /// LaTeX name for environment
298 string latexname_;
300 /// Label string. "Abstract", "Reference", "Caption"...
301 string labelstring_;
303 /// Label string inside appendix. "Appendix", ...
304 string labelstring_appendix_;
306 /// LaTeX parameter for environment
307 string latexparam_;
309 /// Macro definitions needed for this layout
310 string preamble_;
315 class LyXTextClass {
316 public:
318 typedef vector<LyXLayout> LayoutList;
321 LyXTextClass (string const & = string(),
322 string const & = string(),
323 string const & = string());
326 LayoutList::const_iterator begin() const { return layoutlist.begin(); }
328 LayoutList::const_iterator end() const { return layoutlist.end(); }
331 bool Read(string const & filename, bool merge = false);
334 bool hasLayout(string const & name) const;
337 LyXLayout const & GetLayout(string const & vname) const;
340 LyXLayout & GetLayout(string const & vname);
342 /// Sees to that the textclass structure has been loaded
343 void load();
346 string const & name() const { return name_; }
348 string const & latexname() const { return latexname_; }
350 string const & description() const { return description_; }
352 string const & opt_fontsize() const { return opt_fontsize_; }
354 string const & opt_pagestyle() const { return opt_pagestyle_; }
356 string const & options() const { return options_; }
358 string const & pagestyle() const { return pagestyle_; }
360 string const & preamble() const { return preamble_; }
362 /// Packages that are already loaded by the class
363 enum Provides {
364 nothing = 0,
365 amsmath = 1,
366 makeidx = 2,
367 url = 4
369 bool provides(Provides p) const { return provides_ & p; }
372 unsigned int columns() const { return columns_; }
374 enum PageSides {
375 OneSide,
376 TwoSides
379 PageSides sides() const { return sides_; }
381 int secnumdepth() const { return secnumdepth_; }
383 int tocdepth() const { return tocdepth_; }
386 OutputType outputType() const { return outputType_; }
389 LyXFont const & defaultfont() const { return defaultfont_; }
391 /// Text that dictates how wide the left margin is on the screen
392 string const & leftmargin() const { return leftmargin_; }
394 /// Text that dictates how wide the right margin is on the screen
395 string const & rightmargin() const { return rightmargin_; }
397 int maxcounter() const { return maxcounter_; }
399 LayoutList::size_type numLayouts() const { return layoutlist.size(); }
401 LyXLayout const & operator[](LayoutList::size_type i) const {
402 return layoutlist[i];
404 private:
406 bool delete_layout(string const &);
408 bool do_readStyle(LyXLex &, LyXLayout &);
410 string name_;
412 string latexname_;
414 string description_;
415 /// Specific class options
416 string opt_fontsize_;
418 string opt_pagestyle_;
420 string options_;
422 string pagestyle_;
424 string preamble_;
426 Provides provides_;
428 unsigned int columns_;
430 PageSides sides_;
432 int secnumdepth_;
434 int tocdepth_;
436 OutputType outputType_;
437 /** Base font. The paragraph and layout fonts are resolved against
438 this font. This has to be fully instantiated. Attributes
439 LyXFont::INHERIT, LyXFont::IGNORE, and LyXFont::TOGGLE are
440 extremely illegal.
442 LyXFont defaultfont_;
443 /// Text that dictates how wide the left margin is on the screen
444 string leftmargin_;
446 /// Text that dictates how wide the right margin is on the screen
447 string rightmargin_;
449 int maxcounter_; // add approp. signedness
452 LayoutList layoutlist;
454 /// Has this layout file been loaded yet?
455 bool loaded;
459 inline void operator|=(LyXTextClass::Provides & p1, LyXTextClass::Provides p2)
461 p1 = static_cast<LyXTextClass::Provides>(p1 | p2);
466 class LyXTextClassList {
467 public:
469 typedef vector<LyXTextClass> ClassList;
470 /// Gets layout structure from layout number and textclass number
471 LyXLayout const & Style(ClassList::size_type textclass,
472 LyXTextClass::LayoutList::size_type layout) const;
474 /// Gets layout number from textclass number and layout name
475 pair<bool, LyXTextClass::LayoutList::size_type>
476 NumberOfLayout(ClassList::size_type textclass,
477 string const & name) const;
479 /// Gets a layout name from layout number and textclass number
480 string const &
481 NameOfLayout(ClassList::size_type textclass,
482 LyXTextClass::LayoutList::size_type layout) const;
484 /** Gets textclass number from name.
485 Returns -1 if textclass name does not exist
487 pair<bool, ClassList::size_type>
488 NumberOfClass(string const & textclass) const;
491 string const & NameOfClass(ClassList::size_type number) const;
494 string const & LatexnameOfClass(ClassList::size_type number) const;
497 string const & DescOfClass(ClassList::size_type number) const;
500 LyXTextClass const & TextClass(ClassList::size_type textclass) const;
502 /** Read textclass list.
503 Returns false if this fails
505 bool Read();
507 /** Load textclass.
508 Returns false if this fails
510 bool Load(ClassList::size_type number) const;
511 private:
513 mutable ClassList classlist;
515 void Add (LyXTextClass const &);
518 /// Should not be declared here!! (Lgb) Why not? (Asger)
519 extern LyXTextClassList textclasslist;
521 #endif