2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-2001 The LyX Team.
10 * ======================================================
16 #pragma implementation
19 #include "lyxlayout.h"
20 #include "lyxtextclass.h"
24 #include "support/lstrings.h"
28 // The order of the LayoutTags enum is no more important. [asierra300396]
39 //LT_ENVIRONMENT_DEFAULT,
56 LT_LABELSTRING_APPENDIX,
80 // Constructor for layout
81 LyXLayout::LyXLayout ()
83 margintype = MARGIN_STATIC;
84 latextype = LATEX_PARAGRAPH;
88 font = LyXFont(LyXFont::ALL_INHERIT);
89 labelfont = LyXFont(LyXFont::ALL_INHERIT);
90 resfont = LyXFont(LyXFont::ALL_SANE);
91 reslabelfont = LyXFont(LyXFont::ALL_SANE);
99 align = LYX_ALIGN_BLOCK;
100 alignpossible = LYX_ALIGN_BLOCK;
101 labeltype = LABEL_NO_LABEL;
102 endlabeltype = END_LABEL_NO_LABEL;
103 // Should or should not. That is the question.
104 // spacing.set(Spacing::OneHalf);
107 newline_allowed = true;
108 free_spacing = false;
113 // Reads a layout definition from file
114 bool LyXLayout::Read (LyXLex & lexrc, LyXTextClass const & tclass)
116 // This table is sorted alphabetically [asierra 30March96]
117 keyword_item layoutTags[] = {
118 { "align", LT_ALIGN },
119 { "alignpossible", LT_ALIGNPOSSIBLE },
120 { "bottomsep", LT_BOTTOMSEP },
121 { "copystyle", LT_COPYSTYLE },
123 { "endlabelstring", LT_ENDLABELSTRING },
124 { "endlabeltype", LT_ENDLABELTYPE },
125 { "fill_bottom", LT_FILL_BOTTOM },
126 { "fill_top", LT_FILL_TOP },
128 { "freespacing", LT_FREE_SPACING },
129 { "intitle", LT_INTITLE },
130 { "itemsep", LT_ITEMSEP },
131 { "keepempty", LT_KEEPEMPTY },
132 { "labelbottomsep", LT_LABEL_BOTTOMSEP },
133 { "labelfont", LT_LABELFONT },
134 { "labelindent", LT_LABELINDENT },
135 { "labelsep", LT_LABELSEP },
136 { "labelstring", LT_LABELSTRING },
137 { "labelstringappendix", LT_LABELSTRING_APPENDIX },
138 { "labeltype", LT_LABELTYPE },
139 { "latexname", LT_LATEXNAME },
140 { "latexparam", LT_LATEXPARAM },
141 { "latextype", LT_LATEXTYPE },
142 { "leftmargin", LT_LEFTMARGIN },
143 { "margin", LT_MARGIN },
144 { "needprotect", LT_NEED_PROTECT },
145 { "newline", LT_NEWLINE },
146 { "nextnoindent", LT_NEXTNOINDENT },
147 { "obsoletedby", LT_OBSOLETEDBY },
148 { "parindent", LT_PARINDENT },
149 { "parsep", LT_PARSEP },
150 { "parskip", LT_PARSKIP },
151 { "passthru", LT_PASS_THRU },
152 { "preamble", LT_PREAMBLE },
153 { "rightmargin", LT_RIGHTMARGIN },
154 { "spacing", LT_SPACING },
155 { "textfont", LT_TEXTFONT },
156 { "topsep", LT_TOPSEP }
160 bool finished = false;
161 lexrc.pushTable(layoutTags, LT_INTITLE);
162 // parse style section
163 while (!finished && lexrc.isOK() && !error) {
164 int le = lexrc.lex();
165 // See comment in lyxrc.C.
167 case LyXLex::LEX_FEOF:
170 case LyXLex::LEX_UNDEF: // parse error
171 lexrc.printError("Unknown layout tag `$$Token'");
176 switch (static_cast<LayoutTags>(le)) {
177 case LT_END: // end of structure
181 case LT_COPYSTYLE: // initialize with a known style
183 string const style = lexrc.getString();
185 if (tclass.hasLayout(style)) {
186 string const tmpname = name_;
187 this->operator=(tclass[style]);
190 lyxerr << "Cannot copy unknown style `" << style << "'" << endl;
191 LyXTextClass::const_iterator it = tclass.begin();
192 LyXTextClass::const_iterator end = tclass.end();
193 lyxerr << "All layouts so far:" << endl;
194 for (; it != end; ++it) {
195 lyxerr << it->name() << endl;
198 //lexrc.printError("Cannot copy known "
199 // "style `$$Token'");
204 case LT_OBSOLETEDBY: // replace with a known style
206 string const style = lexrc.getString();
208 if (tclass.hasLayout(style)) {
209 string const tmpname = name_;
210 this->operator=(tclass[style]);
212 if (obsoleted_by().empty())
213 obsoleted_by_ = style;
215 lyxerr << "Cannot replace with unknown style `" << style << "'" << endl;
217 //lexrc.printError("Cannot replace with"
224 case LT_MARGIN: // Margin style definition.
228 case LT_LATEXTYPE: // Latex style definition.
229 readLatexType(lexrc);
233 intitle = lexrc.next() && lexrc.getInteger();
236 case LT_NEED_PROTECT:
237 needprotect = lexrc.next() && lexrc.getInteger();
241 keepempty = lexrc.next() && lexrc.getInteger();
254 labelfont.lyxRead(lexrc);
257 case LT_NEXTNOINDENT: // Indent next paragraph?
258 if (lexrc.next() && lexrc.getInteger())
261 nextnoindent = false;
266 latexname_ = lexrc.getString();
271 latexparam_ = lexrc.getString();
275 preamble_ = lexrc.getLongString("EndPreamble");
279 readLabelType(lexrc);
282 case LT_ENDLABELTYPE:
283 readEndLabelType(lexrc);
286 case LT_LEFTMARGIN: // left margin type
288 leftmargin = lexrc.getString();
291 case LT_RIGHTMARGIN: // right margin type
293 rightmargin = lexrc.getString();
296 case LT_LABELINDENT: // label indenting flag
298 labelindent = lexrc.getString();
301 case LT_PARINDENT: // paragraph indent. flag
303 parindent = lexrc.getString();
306 case LT_PARSKIP: // paragraph skip size
308 parskip = lexrc.getFloat();
311 case LT_ITEMSEP: // item separation size
313 itemsep = lexrc.getFloat();
316 case LT_TOPSEP: // top separation size
318 topsep = lexrc.getFloat();
321 case LT_BOTTOMSEP: // bottom separation size
323 bottomsep = lexrc.getFloat();
326 case LT_LABEL_BOTTOMSEP: // label bottom separation size
328 labelbottomsep = lexrc.getFloat();
331 case LT_LABELSEP: // label separator
333 labelsep = subst(lexrc.getString(), 'x', ' ');
337 case LT_PARSEP: // par. separation size
339 parsep = lexrc.getFloat();
342 case LT_FILL_TOP: // fill top flag
344 fill_top = lexrc.getInteger();
347 case LT_FILL_BOTTOM: // fill bottom flag
349 fill_bottom = lexrc.getInteger();
352 case LT_NEWLINE: // newlines allowed?
354 newline_allowed = lexrc.getInteger();
357 case LT_ALIGN: // paragraph align
360 case LT_ALIGNPOSSIBLE: // paragraph allowed align
361 readAlignPossible(lexrc);
364 case LT_LABELSTRING: // label string definition
366 labelstring_ = lexrc.getString();
369 case LT_ENDLABELSTRING: // endlabel string definition
371 endlabelstring_ = lexrc.getString();
374 case LT_LABELSTRING_APPENDIX: // label string appendix definition
376 labelstring_appendix_ = lexrc.getString();
379 case LT_FREE_SPACING: // Allow for free spacing.
381 free_spacing = lexrc.getInteger();
384 case LT_PASS_THRU: // Allow for pass thru.
386 pass_thru = lexrc.getInteger();
389 case LT_SPACING: // setspace.sty
408 void LyXLayout::readAlign(LyXLex & lexrc)
410 keyword_item alignTags[] = {
411 { "block", AT_BLOCK },
412 { "center", AT_CENTER },
413 { "layout", AT_LAYOUT },
415 { "right", AT_RIGHT }
418 pushpophelper pph(lexrc, alignTags, AT_LAYOUT);
419 int le = lexrc.lex();
421 case LyXLex::LEX_UNDEF:
422 lexrc.printError("Unknown alignment `$$Token'");
426 switch (static_cast<AlignTags>(le)) {
428 align = LYX_ALIGN_BLOCK;
431 align = LYX_ALIGN_LEFT;
434 align = LYX_ALIGN_RIGHT;
437 align = LYX_ALIGN_CENTER;
440 align = LYX_ALIGN_LAYOUT;
446 void LyXLayout::readAlignPossible(LyXLex & lexrc)
448 keyword_item alignTags[] = {
449 { "block", AT_BLOCK },
450 { "center", AT_CENTER },
451 { "layout", AT_LAYOUT },
453 { "right", AT_RIGHT }
456 lexrc.pushTable(alignTags, AT_LAYOUT);
457 alignpossible = LYX_ALIGN_NONE;
458 int lineno = lexrc.getLineNo();
460 int le = lexrc.lex();
462 case LyXLex::LEX_UNDEF:
463 lexrc.printError("Unknown alignment `$$Token'");
467 switch (static_cast<AlignTags>(le)) {
469 alignpossible |= LYX_ALIGN_BLOCK;
472 alignpossible |= LYX_ALIGN_LEFT;
475 alignpossible |= LYX_ALIGN_RIGHT;
478 alignpossible |= LYX_ALIGN_CENTER;
481 alignpossible |= LYX_ALIGN_LAYOUT;
484 } while (lineno == lexrc.getLineNo());
493 LA_CENTERED_TOP_ENVIRONMENT,
498 LA_COUNTER_SUBSECTION,
499 LA_COUNTER_SUBSUBSECTION,
500 LA_COUNTER_PARAGRAPH,
501 LA_COUNTER_SUBPARAGRAPH,
510 void LyXLayout::readLabelType(LyXLex & lexrc)
512 keyword_item labelTypeTags[] = {
513 { "bibliography", LA_BIBLIO },
514 { "centered_top_environment", LA_CENTERED_TOP_ENVIRONMENT },
515 { "counter_chapter", LA_COUNTER_CHAPTER },
516 { "counter_enumi", LA_COUNTER_ENUMI },
517 { "counter_enumii", LA_COUNTER_ENUMII },
518 { "counter_enumiii", LA_COUNTER_ENUMIII },
519 { "counter_enumiv", LA_COUNTER_ENUMIV },
520 { "counter_paragraph", LA_COUNTER_PARAGRAPH },
521 { "counter_section", LA_COUNTER_SECTION },
522 { "counter_subparagraph", LA_COUNTER_SUBPARAGRAPH },
523 { "counter_subsection", LA_COUNTER_SUBSECTION },
524 { "counter_subsubsection", LA_COUNTER_SUBSUBSECTION },
525 { "manual", LA_MANUAL },
526 { "no_label", LA_NO_LABEL },
527 { "sensitive", LA_SENSITIVE },
528 { "static", LA_STATIC },
529 { "top_environment", LA_TOP_ENVIRONMENT }
532 pushpophelper pph(lexrc, labelTypeTags, LA_BIBLIO);
533 int le = lexrc.lex();
535 case LyXLex::LEX_UNDEF:
536 lexrc.printError("Unknown labeltype tag `$$Token'");
540 switch (static_cast<LabelTypeTags>(le)) {
542 labeltype = LABEL_NO_LABEL;
545 labeltype = LABEL_MANUAL;
547 case LA_TOP_ENVIRONMENT:
548 labeltype = LABEL_TOP_ENVIRONMENT;
550 case LA_CENTERED_TOP_ENVIRONMENT:
551 labeltype = LABEL_CENTERED_TOP_ENVIRONMENT;
554 labeltype = LABEL_STATIC;
557 labeltype = LABEL_SENSITIVE;
559 case LA_COUNTER_CHAPTER:
560 labeltype = LABEL_COUNTER_CHAPTER;
562 case LA_COUNTER_SECTION:
563 labeltype = LABEL_COUNTER_SECTION;
565 case LA_COUNTER_SUBSECTION:
566 labeltype = LABEL_COUNTER_SUBSECTION;
568 case LA_COUNTER_SUBSUBSECTION:
569 labeltype = LABEL_COUNTER_SUBSUBSECTION;
571 case LA_COUNTER_PARAGRAPH:
572 labeltype = LABEL_COUNTER_PARAGRAPH;
574 case LA_COUNTER_SUBPARAGRAPH:
575 labeltype = LABEL_COUNTER_SUBPARAGRAPH;
577 case LA_COUNTER_ENUMI:
578 labeltype = LABEL_COUNTER_ENUMI;
580 case LA_COUNTER_ENUMII:
581 labeltype = LABEL_COUNTER_ENUMII;
583 case LA_COUNTER_ENUMIII:
584 labeltype = LABEL_COUNTER_ENUMIII;
586 case LA_COUNTER_ENUMIV:
587 labeltype = LABEL_COUNTER_ENUMIV;
590 labeltype = LABEL_BIBLIO;
598 keyword_item endlabelTypeTags[] = {
599 { "box", END_LABEL_BOX },
600 { "filled_box", END_LABEL_FILLED_BOX },
601 { "no_label", END_LABEL_NO_LABEL },
602 { "static", END_LABEL_STATIC }
608 void LyXLayout::readEndLabelType(LyXLex & lexrc)
610 pushpophelper pph(lexrc, endlabelTypeTags,
611 END_LABEL_ENUM_LAST-END_LABEL_ENUM_FIRST+1);
612 int le = lexrc.lex();
614 case LyXLex::LEX_UNDEF:
615 lexrc.printError("Unknown labeltype tag `$$Token'");
617 case END_LABEL_STATIC:
619 case END_LABEL_FILLED_BOX:
620 case END_LABEL_NO_LABEL:
621 endlabeltype = static_cast<LYX_END_LABEL_TYPES>(le);
624 lyxerr << "Unhandled value " << le
625 << " in LyXLayout::readEndLabelType." << endl;
631 void LyXLayout::readMargin(LyXLex & lexrc)
633 keyword_item marginTags[] = {
634 { "dynamic", MARGIN_DYNAMIC },
635 { "first_dynamic", MARGIN_FIRST_DYNAMIC },
636 { "manual", MARGIN_MANUAL },
637 { "right_address_box", MARGIN_RIGHT_ADDRESS_BOX },
638 { "static", MARGIN_STATIC }
641 pushpophelper pph(lexrc, marginTags, MARGIN_RIGHT_ADDRESS_BOX);
643 int le = lexrc.lex();
645 case LyXLex::LEX_UNDEF:
646 lexrc.printError("Unknown margin type tag `$$Token'");
651 case MARGIN_FIRST_DYNAMIC:
652 case MARGIN_RIGHT_ADDRESS_BOX:
653 margintype = static_cast<LYX_MARGIN_TYPE>(le);
656 lyxerr << "Unhandled value " << le
657 << " in LyXLayout::readMargin." << endl;
663 void LyXLayout::readLatexType(LyXLex & lexrc)
665 keyword_item latexTypeTags[] = {
666 { "command", LATEX_COMMAND },
667 { "environment", LATEX_ENVIRONMENT },
668 { "item_environment", LATEX_ITEM_ENVIRONMENT },
669 { "list_environment", LATEX_LIST_ENVIRONMENT },
670 { "paragraph", LATEX_PARAGRAPH }
673 pushpophelper pph(lexrc, latexTypeTags, LATEX_LIST_ENVIRONMENT);
674 int le = lexrc.lex();
676 case LyXLex::LEX_UNDEF:
677 lexrc.printError("Unknown latextype tag `$$Token'");
679 case LATEX_PARAGRAPH:
681 case LATEX_ENVIRONMENT:
682 case LATEX_ITEM_ENVIRONMENT:
683 case LATEX_LIST_ENVIRONMENT:
684 latextype = static_cast<LYX_LATEX_TYPES>(le);
687 lyxerr << "Unhandled value " << le
688 << " in LyXLayout::readLatexType." << endl;
695 ST_SPACING_SINGLE = 1,
702 void LyXLayout::readSpacing(LyXLex & lexrc)
704 keyword_item spacingTags[] = {
705 {"double", ST_SPACING_DOUBLE },
706 {"onehalf", ST_SPACING_ONEHALF },
707 {"other", ST_OTHER },
708 {"single", ST_SPACING_SINGLE }
711 pushpophelper pph(lexrc, spacingTags, ST_OTHER);
712 int le = lexrc.lex();
714 case LyXLex::LEX_UNDEF:
715 lexrc.printError("Unknown spacing token `$$Token'");
719 switch (static_cast<SpacingTags>(le)) {
720 case ST_SPACING_SINGLE:
721 spacing.set(Spacing::Single);
723 case ST_SPACING_ONEHALF:
724 spacing.set(Spacing::Onehalf);
726 case ST_SPACING_DOUBLE:
727 spacing.set(Spacing::Double);
731 spacing.set(Spacing::Other, lexrc.getFloat());
737 string const & LyXLayout::name() const
743 void LyXLayout::setName(string const & n)
749 string const & LyXLayout::obsoleted_by() const
751 return obsoleted_by_;