1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 The LyX Team.
9 * ======================================================
15 #pragma implementation
18 #include "lyxlayout.h"
19 #include "lyxtextclass.h"
23 #include "support/lstrings.h"
27 // The order of the LayoutTags enum is no more important. [asierra300396]
38 //LT_ENVIRONMENT_DEFAULT,
55 LT_LABELSTRING_APPENDIX,
79 // Constructor for layout
80 LyXLayout::LyXLayout ()
82 margintype = MARGIN_STATIC;
83 latextype = LATEX_PARAGRAPH;
87 font = LyXFont(LyXFont::ALL_INHERIT);
88 labelfont = LyXFont(LyXFont::ALL_INHERIT);
89 resfont = LyXFont(LyXFont::ALL_SANE);
90 reslabelfont = LyXFont(LyXFont::ALL_SANE);
98 align = LYX_ALIGN_BLOCK;
99 alignpossible = LYX_ALIGN_BLOCK;
100 labeltype = LABEL_NO_LABEL;
101 endlabeltype = END_LABEL_NO_LABEL;
102 // Should or should not. That is the question.
103 // spacing.set(Spacing::OneHalf);
106 newline_allowed = true;
107 free_spacing = false;
112 // Reads a layout definition from file
113 bool LyXLayout::Read (LyXLex & lexrc, LyXTextClass const & tclass)
115 // This table is sorted alphabetically [asierra 30March96]
116 keyword_item layoutTags[] = {
117 { "align", LT_ALIGN },
118 { "alignpossible", LT_ALIGNPOSSIBLE },
119 { "bottomsep", LT_BOTTOMSEP },
120 { "copystyle", LT_COPYSTYLE },
122 { "endlabelstring", LT_ENDLABELSTRING },
123 { "endlabeltype", LT_ENDLABELTYPE },
124 { "fill_bottom", LT_FILL_BOTTOM },
125 { "fill_top", LT_FILL_TOP },
127 { "freespacing", LT_FREE_SPACING },
128 { "intitle", LT_INTITLE },
129 { "itemsep", LT_ITEMSEP },
130 { "keepempty", LT_KEEPEMPTY },
131 { "labelbottomsep", LT_LABEL_BOTTOMSEP },
132 { "labelfont", LT_LABELFONT },
133 { "labelindent", LT_LABELINDENT },
134 { "labelsep", LT_LABELSEP },
135 { "labelstring", LT_LABELSTRING },
136 { "labelstringappendix", LT_LABELSTRING_APPENDIX },
137 { "labeltype", LT_LABELTYPE },
138 { "latexname", LT_LATEXNAME },
139 { "latexparam", LT_LATEXPARAM },
140 { "latextype", LT_LATEXTYPE },
141 { "leftmargin", LT_LEFTMARGIN },
142 { "margin", LT_MARGIN },
143 { "needprotect", LT_NEED_PROTECT },
144 { "newline", LT_NEWLINE },
145 { "nextnoindent", LT_NEXTNOINDENT },
146 { "obsoletedby", LT_OBSOLETEDBY },
147 { "parindent", LT_PARINDENT },
148 { "parsep", LT_PARSEP },
149 { "parskip", LT_PARSKIP },
150 { "passthru", LT_PASS_THRU },
151 { "preamble", LT_PREAMBLE },
152 { "rightmargin", LT_RIGHTMARGIN },
153 { "spacing", LT_SPACING },
154 { "textfont", LT_TEXTFONT },
155 { "topsep", LT_TOPSEP }
159 bool finished = false;
160 lexrc.pushTable(layoutTags, LT_INTITLE);
161 // parse style section
162 while (!finished && lexrc.isOK() && !error) {
163 int le = lexrc.lex();
164 // See comment in lyxrc.C.
166 case LyXLex::LEX_FEOF:
169 case LyXLex::LEX_UNDEF: // parse error
170 lexrc.printError("Unknown layout tag `$$Token'");
175 switch (static_cast<LayoutTags>(le)) {
176 case LT_END: // end of structure
180 case LT_COPYSTYLE: // initialize with a known style
182 string const style = lexrc.getString();
184 if (tclass.hasLayout(style)) {
185 string const tmpname = name_;
186 this->operator=(tclass[style]);
189 lyxerr << "Cannot copy unknown style `" << style << "'" << endl;
190 LyXTextClass::const_iterator it = tclass.begin();
191 LyXTextClass::const_iterator end = tclass.end();
192 lyxerr << "All layouts so far:" << endl;
193 for (; it != end; ++it) {
194 lyxerr << it->name() << endl;
197 //lexrc.printError("Cannot copy known "
198 // "style `$$Token'");
203 case LT_OBSOLETEDBY: // replace with a known style
205 string const style = lexrc.getString();
207 if (tclass.hasLayout(style)) {
208 string const tmpname = name_;
209 this->operator=(tclass[style]);
211 if (obsoleted_by().empty())
212 obsoleted_by_ = style;
214 lyxerr << "Cannot replace with unknown style `" << style << "'" << endl;
216 //lexrc.printError("Cannot replace with"
223 case LT_MARGIN: // Margin style definition.
227 case LT_LATEXTYPE: // Latex style definition.
228 readLatexType(lexrc);
232 intitle = lexrc.next() && lexrc.getInteger();
235 case LT_NEED_PROTECT:
236 needprotect = lexrc.next() && lexrc.getInteger();
240 keepempty = lexrc.next() && lexrc.getInteger();
253 labelfont.lyxRead(lexrc);
256 case LT_NEXTNOINDENT: // Indent next paragraph?
257 if (lexrc.next() && lexrc.getInteger())
260 nextnoindent = false;
265 latexname_ = lexrc.getString();
270 latexparam_ = lexrc.getString();
274 preamble_ = lexrc.getLongString("EndPreamble");
278 readLabelType(lexrc);
281 case LT_ENDLABELTYPE:
282 readEndLabelType(lexrc);
285 case LT_LEFTMARGIN: // left margin type
287 leftmargin = lexrc.getString();
290 case LT_RIGHTMARGIN: // right margin type
292 rightmargin = lexrc.getString();
295 case LT_LABELINDENT: // label indenting flag
297 labelindent = lexrc.getString();
300 case LT_PARINDENT: // paragraph indent. flag
302 parindent = lexrc.getString();
305 case LT_PARSKIP: // paragraph skip size
307 parskip = lexrc.getFloat();
310 case LT_ITEMSEP: // item separation size
312 itemsep = lexrc.getFloat();
315 case LT_TOPSEP: // top separation size
317 topsep = lexrc.getFloat();
320 case LT_BOTTOMSEP: // bottom separation size
322 bottomsep = lexrc.getFloat();
325 case LT_LABEL_BOTTOMSEP: // label bottom separation size
327 labelbottomsep = lexrc.getFloat();
330 case LT_LABELSEP: // label separator
332 labelsep = subst(lexrc.getString(), 'x', ' ');
336 case LT_PARSEP: // par. separation size
338 parsep = lexrc.getFloat();
341 case LT_FILL_TOP: // fill top flag
343 fill_top = lexrc.getInteger();
346 case LT_FILL_BOTTOM: // fill bottom flag
348 fill_bottom = lexrc.getInteger();
351 case LT_NEWLINE: // newlines allowed?
353 newline_allowed = lexrc.getInteger();
356 case LT_ALIGN: // paragraph align
359 case LT_ALIGNPOSSIBLE: // paragraph allowed align
360 readAlignPossible(lexrc);
363 case LT_LABELSTRING: // label string definition
365 labelstring_ = lexrc.getString();
368 case LT_ENDLABELSTRING: // endlabel string definition
370 endlabelstring_ = lexrc.getString();
373 case LT_LABELSTRING_APPENDIX: // label string appendix definition
375 labelstring_appendix_ = lexrc.getString();
378 case LT_FREE_SPACING: // Allow for free spacing.
380 free_spacing = lexrc.getInteger();
383 case LT_PASS_THRU: // Allow for pass thru.
385 pass_thru = lexrc.getInteger();
388 case LT_SPACING: // setspace.sty
407 void LyXLayout::readAlign(LyXLex & lexrc)
409 keyword_item alignTags[] = {
410 { "block", AT_BLOCK },
411 { "center", AT_CENTER },
412 { "layout", AT_LAYOUT },
414 { "right", AT_RIGHT }
417 pushpophelper pph(lexrc, alignTags, AT_LAYOUT);
418 int le = lexrc.lex();
420 case LyXLex::LEX_UNDEF:
421 lexrc.printError("Unknown alignment `$$Token'");
425 switch (static_cast<AlignTags>(le)) {
427 align = LYX_ALIGN_BLOCK;
430 align = LYX_ALIGN_LEFT;
433 align = LYX_ALIGN_RIGHT;
436 align = LYX_ALIGN_CENTER;
439 align = LYX_ALIGN_LAYOUT;
445 void LyXLayout::readAlignPossible(LyXLex & lexrc)
447 keyword_item alignTags[] = {
448 { "block", AT_BLOCK },
449 { "center", AT_CENTER },
450 { "layout", AT_LAYOUT },
452 { "right", AT_RIGHT }
455 lexrc.pushTable(alignTags, AT_LAYOUT);
456 alignpossible = LYX_ALIGN_NONE;
457 int lineno = lexrc.getLineNo();
459 int le = lexrc.lex();
461 case LyXLex::LEX_UNDEF:
462 lexrc.printError("Unknown alignment `$$Token'");
466 switch (static_cast<AlignTags>(le)) {
468 alignpossible |= LYX_ALIGN_BLOCK;
471 alignpossible |= LYX_ALIGN_LEFT;
474 alignpossible |= LYX_ALIGN_RIGHT;
477 alignpossible |= LYX_ALIGN_CENTER;
480 alignpossible |= LYX_ALIGN_LAYOUT;
483 } while (lineno == lexrc.getLineNo());
492 LA_CENTERED_TOP_ENVIRONMENT,
497 LA_COUNTER_SUBSECTION,
498 LA_COUNTER_SUBSUBSECTION,
499 LA_COUNTER_PARAGRAPH,
500 LA_COUNTER_SUBPARAGRAPH,
509 void LyXLayout::readLabelType(LyXLex & lexrc)
511 keyword_item labelTypeTags[] = {
512 { "bibliography", LA_BIBLIO },
513 { "centered_top_environment", LA_CENTERED_TOP_ENVIRONMENT },
514 { "counter_chapter", LA_COUNTER_CHAPTER },
515 { "counter_enumi", LA_COUNTER_ENUMI },
516 { "counter_enumii", LA_COUNTER_ENUMII },
517 { "counter_enumiii", LA_COUNTER_ENUMIII },
518 { "counter_enumiv", LA_COUNTER_ENUMIV },
519 { "counter_paragraph", LA_COUNTER_PARAGRAPH },
520 { "counter_section", LA_COUNTER_SECTION },
521 { "counter_subparagraph", LA_COUNTER_SUBPARAGRAPH },
522 { "counter_subsection", LA_COUNTER_SUBSECTION },
523 { "counter_subsubsection", LA_COUNTER_SUBSUBSECTION },
524 { "manual", LA_MANUAL },
525 { "no_label", LA_NO_LABEL },
526 { "sensitive", LA_SENSITIVE },
527 { "static", LA_STATIC },
528 { "top_environment", LA_TOP_ENVIRONMENT }
531 pushpophelper pph(lexrc, labelTypeTags, LA_BIBLIO);
532 int le = lexrc.lex();
534 case LyXLex::LEX_UNDEF:
535 lexrc.printError("Unknown labeltype tag `$$Token'");
539 switch (static_cast<LabelTypeTags>(le)) {
541 labeltype = LABEL_NO_LABEL;
544 labeltype = LABEL_MANUAL;
546 case LA_TOP_ENVIRONMENT:
547 labeltype = LABEL_TOP_ENVIRONMENT;
549 case LA_CENTERED_TOP_ENVIRONMENT:
550 labeltype = LABEL_CENTERED_TOP_ENVIRONMENT;
553 labeltype = LABEL_STATIC;
556 labeltype = LABEL_SENSITIVE;
558 case LA_COUNTER_CHAPTER:
559 labeltype = LABEL_COUNTER_CHAPTER;
561 case LA_COUNTER_SECTION:
562 labeltype = LABEL_COUNTER_SECTION;
564 case LA_COUNTER_SUBSECTION:
565 labeltype = LABEL_COUNTER_SUBSECTION;
567 case LA_COUNTER_SUBSUBSECTION:
568 labeltype = LABEL_COUNTER_SUBSUBSECTION;
570 case LA_COUNTER_PARAGRAPH:
571 labeltype = LABEL_COUNTER_PARAGRAPH;
573 case LA_COUNTER_SUBPARAGRAPH:
574 labeltype = LABEL_COUNTER_SUBPARAGRAPH;
576 case LA_COUNTER_ENUMI:
577 labeltype = LABEL_COUNTER_ENUMI;
579 case LA_COUNTER_ENUMII:
580 labeltype = LABEL_COUNTER_ENUMII;
582 case LA_COUNTER_ENUMIII:
583 labeltype = LABEL_COUNTER_ENUMIII;
585 case LA_COUNTER_ENUMIV:
586 labeltype = LABEL_COUNTER_ENUMIV;
589 labeltype = LABEL_BIBLIO;
597 keyword_item endlabelTypeTags[] = {
598 { "box", END_LABEL_BOX },
599 { "filled_box", END_LABEL_FILLED_BOX },
600 { "no_label", END_LABEL_NO_LABEL },
601 { "static", END_LABEL_STATIC }
607 void LyXLayout::readEndLabelType(LyXLex & lexrc)
609 pushpophelper pph(lexrc, endlabelTypeTags,
610 END_LABEL_ENUM_LAST-END_LABEL_ENUM_FIRST+1);
611 int le = lexrc.lex();
613 case LyXLex::LEX_UNDEF:
614 lexrc.printError("Unknown labeltype tag `$$Token'");
616 case END_LABEL_STATIC:
618 case END_LABEL_FILLED_BOX:
619 case END_LABEL_NO_LABEL:
620 endlabeltype = static_cast<LYX_END_LABEL_TYPES>(le);
623 lyxerr << "Unhandled value " << le
624 << " in LyXLayout::readEndLabelType." << endl;
630 void LyXLayout::readMargin(LyXLex & lexrc)
632 keyword_item marginTags[] = {
633 { "dynamic", MARGIN_DYNAMIC },
634 { "first_dynamic", MARGIN_FIRST_DYNAMIC },
635 { "manual", MARGIN_MANUAL },
636 { "right_address_box", MARGIN_RIGHT_ADDRESS_BOX },
637 { "static", MARGIN_STATIC }
640 pushpophelper pph(lexrc, marginTags, MARGIN_RIGHT_ADDRESS_BOX);
642 int le = lexrc.lex();
644 case LyXLex::LEX_UNDEF:
645 lexrc.printError("Unknown margin type tag `$$Token'");
650 case MARGIN_FIRST_DYNAMIC:
651 case MARGIN_RIGHT_ADDRESS_BOX:
652 margintype = static_cast<LYX_MARGIN_TYPE>(le);
655 lyxerr << "Unhandled value " << le
656 << " in LyXLayout::readMargin." << endl;
662 void LyXLayout::readLatexType(LyXLex & lexrc)
664 keyword_item latexTypeTags[] = {
665 { "command", LATEX_COMMAND },
666 { "environment", LATEX_ENVIRONMENT },
667 { "item_environment", LATEX_ITEM_ENVIRONMENT },
668 { "list_environment", LATEX_LIST_ENVIRONMENT },
669 { "paragraph", LATEX_PARAGRAPH }
672 pushpophelper pph(lexrc, latexTypeTags, LATEX_LIST_ENVIRONMENT);
673 int le = lexrc.lex();
675 case LyXLex::LEX_UNDEF:
676 lexrc.printError("Unknown latextype tag `$$Token'");
678 case LATEX_PARAGRAPH:
680 case LATEX_ENVIRONMENT:
681 case LATEX_ITEM_ENVIRONMENT:
682 case LATEX_LIST_ENVIRONMENT:
683 latextype = static_cast<LYX_LATEX_TYPES>(le);
686 lyxerr << "Unhandled value " << le
687 << " in LyXLayout::readLatexType." << endl;
694 ST_SPACING_SINGLE = 1,
701 void LyXLayout::readSpacing(LyXLex & lexrc)
703 keyword_item spacingTags[] = {
704 {"double", ST_SPACING_DOUBLE },
705 {"onehalf", ST_SPACING_ONEHALF },
706 {"other", ST_OTHER },
707 {"single", ST_SPACING_SINGLE }
710 pushpophelper pph(lexrc, spacingTags, ST_OTHER);
711 int le = lexrc.lex();
713 case LyXLex::LEX_UNDEF:
714 lexrc.printError("Unknown spacing token `$$Token'");
718 switch (static_cast<SpacingTags>(le)) {
719 case ST_SPACING_SINGLE:
720 spacing.set(Spacing::Single);
722 case ST_SPACING_ONEHALF:
723 spacing.set(Spacing::Onehalf);
725 case ST_SPACING_DOUBLE:
726 spacing.set(Spacing::Double);
730 spacing.set(Spacing::Other, lexrc.getFloat());
736 string const & LyXLayout::name() const
742 void LyXLayout::setName(string const & n)
748 string const & LyXLayout::obsoleted_by() const
750 return obsoleted_by_;