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 `"
191 << "All layouts so far:"
193 LyXTextClass::const_iterator it =
195 LyXTextClass::const_iterator end =
197 for (; it != end; ++it) {
198 lyxerr << (*it)->name()
202 //lexrc.printError("Cannot copy known "
203 // "style `$$Token'");
208 case LT_OBSOLETEDBY: // replace with a known style
210 string const style = lexrc.getString();
212 if (tclass.hasLayout(style)) {
213 string const tmpname = name_;
214 this->operator=(*tclass[style]);
216 if (obsoleted_by().empty())
217 obsoleted_by_ = style;
219 lyxerr << "Cannot replace with unknown style `" << style << "'" << endl;
221 //lexrc.printError("Cannot replace with"
228 case LT_MARGIN: // Margin style definition.
232 case LT_LATEXTYPE: // Latex style definition.
233 readLatexType(lexrc);
237 intitle = lexrc.next() && lexrc.getInteger();
240 case LT_NEED_PROTECT:
241 needprotect = lexrc.next() && lexrc.getInteger();
245 keepempty = lexrc.next() && lexrc.getInteger();
258 labelfont.lyxRead(lexrc);
261 case LT_NEXTNOINDENT: // Indent next paragraph?
262 if (lexrc.next() && lexrc.getInteger())
265 nextnoindent = false;
270 latexname_ = lexrc.getString();
275 latexparam_ = lexrc.getString();
279 preamble_ = lexrc.getLongString("EndPreamble");
283 readLabelType(lexrc);
286 case LT_ENDLABELTYPE:
287 readEndLabelType(lexrc);
290 case LT_LEFTMARGIN: // left margin type
292 leftmargin = lexrc.getString();
295 case LT_RIGHTMARGIN: // right margin type
297 rightmargin = lexrc.getString();
300 case LT_LABELINDENT: // label indenting flag
302 labelindent = lexrc.getString();
305 case LT_PARINDENT: // paragraph indent. flag
307 parindent = lexrc.getString();
310 case LT_PARSKIP: // paragraph skip size
312 parskip = lexrc.getFloat();
315 case LT_ITEMSEP: // item separation size
317 itemsep = lexrc.getFloat();
320 case LT_TOPSEP: // top separation size
322 topsep = lexrc.getFloat();
325 case LT_BOTTOMSEP: // bottom separation size
327 bottomsep = lexrc.getFloat();
330 case LT_LABEL_BOTTOMSEP: // label bottom separation size
332 labelbottomsep = lexrc.getFloat();
335 case LT_LABELSEP: // label separator
337 labelsep = subst(lexrc.getString(), 'x', ' ');
341 case LT_PARSEP: // par. separation size
343 parsep = lexrc.getFloat();
346 case LT_FILL_TOP: // fill top flag
348 fill_top = lexrc.getInteger();
351 case LT_FILL_BOTTOM: // fill bottom flag
353 fill_bottom = lexrc.getInteger();
356 case LT_NEWLINE: // newlines allowed?
358 newline_allowed = lexrc.getInteger();
361 case LT_ALIGN: // paragraph align
364 case LT_ALIGNPOSSIBLE: // paragraph allowed align
365 readAlignPossible(lexrc);
368 case LT_LABELSTRING: // label string definition
370 labelstring_ = lexrc.getString();
373 case LT_ENDLABELSTRING: // endlabel string definition
375 endlabelstring_ = lexrc.getString();
378 case LT_LABELSTRING_APPENDIX: // label string appendix definition
380 labelstring_appendix_ = lexrc.getString();
383 case LT_FREE_SPACING: // Allow for free spacing.
385 free_spacing = lexrc.getInteger();
388 case LT_PASS_THRU: // Allow for pass thru.
390 pass_thru = lexrc.getInteger();
393 case LT_SPACING: // setspace.sty
412 void LyXLayout::readAlign(LyXLex & lexrc)
414 keyword_item alignTags[] = {
415 { "block", AT_BLOCK },
416 { "center", AT_CENTER },
417 { "layout", AT_LAYOUT },
419 { "right", AT_RIGHT }
422 pushpophelper pph(lexrc, alignTags, AT_LAYOUT);
423 int le = lexrc.lex();
425 case LyXLex::LEX_UNDEF:
426 lexrc.printError("Unknown alignment `$$Token'");
430 switch (static_cast<AlignTags>(le)) {
432 align = LYX_ALIGN_BLOCK;
435 align = LYX_ALIGN_LEFT;
438 align = LYX_ALIGN_RIGHT;
441 align = LYX_ALIGN_CENTER;
444 align = LYX_ALIGN_LAYOUT;
450 void LyXLayout::readAlignPossible(LyXLex & lexrc)
452 keyword_item alignTags[] = {
453 { "block", AT_BLOCK },
454 { "center", AT_CENTER },
455 { "layout", AT_LAYOUT },
457 { "right", AT_RIGHT }
460 lexrc.pushTable(alignTags, AT_LAYOUT);
461 alignpossible = LYX_ALIGN_NONE;
462 int lineno = lexrc.getLineNo();
464 int le = lexrc.lex();
466 case LyXLex::LEX_UNDEF:
467 lexrc.printError("Unknown alignment `$$Token'");
471 switch (static_cast<AlignTags>(le)) {
473 alignpossible |= LYX_ALIGN_BLOCK;
476 alignpossible |= LYX_ALIGN_LEFT;
479 alignpossible |= LYX_ALIGN_RIGHT;
482 alignpossible |= LYX_ALIGN_CENTER;
485 alignpossible |= LYX_ALIGN_LAYOUT;
488 } while (lineno == lexrc.getLineNo());
497 LA_CENTERED_TOP_ENVIRONMENT,
502 LA_COUNTER_SUBSECTION,
503 LA_COUNTER_SUBSUBSECTION,
504 LA_COUNTER_PARAGRAPH,
505 LA_COUNTER_SUBPARAGRAPH,
514 void LyXLayout::readLabelType(LyXLex & lexrc)
516 keyword_item labelTypeTags[] = {
517 { "bibliography", LA_BIBLIO },
518 { "centered_top_environment", LA_CENTERED_TOP_ENVIRONMENT },
519 { "counter_chapter", LA_COUNTER_CHAPTER },
520 { "counter_enumi", LA_COUNTER_ENUMI },
521 { "counter_enumii", LA_COUNTER_ENUMII },
522 { "counter_enumiii", LA_COUNTER_ENUMIII },
523 { "counter_enumiv", LA_COUNTER_ENUMIV },
524 { "counter_paragraph", LA_COUNTER_PARAGRAPH },
525 { "counter_section", LA_COUNTER_SECTION },
526 { "counter_subparagraph", LA_COUNTER_SUBPARAGRAPH },
527 { "counter_subsection", LA_COUNTER_SUBSECTION },
528 { "counter_subsubsection", LA_COUNTER_SUBSUBSECTION },
529 { "manual", LA_MANUAL },
530 { "no_label", LA_NO_LABEL },
531 { "sensitive", LA_SENSITIVE },
532 { "static", LA_STATIC },
533 { "top_environment", LA_TOP_ENVIRONMENT }
536 pushpophelper pph(lexrc, labelTypeTags, LA_BIBLIO);
537 int le = lexrc.lex();
539 case LyXLex::LEX_UNDEF:
540 lexrc.printError("Unknown labeltype tag `$$Token'");
544 switch (static_cast<LabelTypeTags>(le)) {
546 labeltype = LABEL_NO_LABEL;
549 labeltype = LABEL_MANUAL;
551 case LA_TOP_ENVIRONMENT:
552 labeltype = LABEL_TOP_ENVIRONMENT;
554 case LA_CENTERED_TOP_ENVIRONMENT:
555 labeltype = LABEL_CENTERED_TOP_ENVIRONMENT;
558 labeltype = LABEL_STATIC;
561 labeltype = LABEL_SENSITIVE;
563 case LA_COUNTER_CHAPTER:
564 labeltype = LABEL_COUNTER_CHAPTER;
566 case LA_COUNTER_SECTION:
567 labeltype = LABEL_COUNTER_SECTION;
569 case LA_COUNTER_SUBSECTION:
570 labeltype = LABEL_COUNTER_SUBSECTION;
572 case LA_COUNTER_SUBSUBSECTION:
573 labeltype = LABEL_COUNTER_SUBSUBSECTION;
575 case LA_COUNTER_PARAGRAPH:
576 labeltype = LABEL_COUNTER_PARAGRAPH;
578 case LA_COUNTER_SUBPARAGRAPH:
579 labeltype = LABEL_COUNTER_SUBPARAGRAPH;
581 case LA_COUNTER_ENUMI:
582 labeltype = LABEL_COUNTER_ENUMI;
584 case LA_COUNTER_ENUMII:
585 labeltype = LABEL_COUNTER_ENUMII;
587 case LA_COUNTER_ENUMIII:
588 labeltype = LABEL_COUNTER_ENUMIII;
590 case LA_COUNTER_ENUMIV:
591 labeltype = LABEL_COUNTER_ENUMIV;
594 labeltype = LABEL_BIBLIO;
602 keyword_item endlabelTypeTags[] = {
603 { "box", END_LABEL_BOX },
604 { "filled_box", END_LABEL_FILLED_BOX },
605 { "no_label", END_LABEL_NO_LABEL },
606 { "static", END_LABEL_STATIC }
612 void LyXLayout::readEndLabelType(LyXLex & lexrc)
614 pushpophelper pph(lexrc, endlabelTypeTags,
615 END_LABEL_ENUM_LAST-END_LABEL_ENUM_FIRST+1);
616 int le = lexrc.lex();
618 case LyXLex::LEX_UNDEF:
619 lexrc.printError("Unknown labeltype tag `$$Token'");
621 case END_LABEL_STATIC:
623 case END_LABEL_FILLED_BOX:
624 case END_LABEL_NO_LABEL:
625 endlabeltype = static_cast<LYX_END_LABEL_TYPES>(le);
628 lyxerr << "Unhandled value " << le
629 << " in LyXLayout::readEndLabelType." << endl;
635 void LyXLayout::readMargin(LyXLex & lexrc)
637 keyword_item marginTags[] = {
638 { "dynamic", MARGIN_DYNAMIC },
639 { "first_dynamic", MARGIN_FIRST_DYNAMIC },
640 { "manual", MARGIN_MANUAL },
641 { "right_address_box", MARGIN_RIGHT_ADDRESS_BOX },
642 { "static", MARGIN_STATIC }
645 pushpophelper pph(lexrc, marginTags, MARGIN_RIGHT_ADDRESS_BOX);
647 int le = lexrc.lex();
649 case LyXLex::LEX_UNDEF:
650 lexrc.printError("Unknown margin type tag `$$Token'");
655 case MARGIN_FIRST_DYNAMIC:
656 case MARGIN_RIGHT_ADDRESS_BOX:
657 margintype = static_cast<LYX_MARGIN_TYPE>(le);
660 lyxerr << "Unhandled value " << le
661 << " in LyXLayout::readMargin." << endl;
667 void LyXLayout::readLatexType(LyXLex & lexrc)
669 keyword_item latexTypeTags[] = {
670 { "command", LATEX_COMMAND },
671 { "environment", LATEX_ENVIRONMENT },
672 { "item_environment", LATEX_ITEM_ENVIRONMENT },
673 { "list_environment", LATEX_LIST_ENVIRONMENT },
674 { "paragraph", LATEX_PARAGRAPH }
677 pushpophelper pph(lexrc, latexTypeTags, LATEX_LIST_ENVIRONMENT);
678 int le = lexrc.lex();
680 case LyXLex::LEX_UNDEF:
681 lexrc.printError("Unknown latextype tag `$$Token'");
683 case LATEX_PARAGRAPH:
685 case LATEX_ENVIRONMENT:
686 case LATEX_ITEM_ENVIRONMENT:
687 case LATEX_LIST_ENVIRONMENT:
688 latextype = static_cast<LYX_LATEX_TYPES>(le);
691 lyxerr << "Unhandled value " << le
692 << " in LyXLayout::readLatexType." << endl;
699 ST_SPACING_SINGLE = 1,
706 void LyXLayout::readSpacing(LyXLex & lexrc)
708 keyword_item spacingTags[] = {
709 {"double", ST_SPACING_DOUBLE },
710 {"onehalf", ST_SPACING_ONEHALF },
711 {"other", ST_OTHER },
712 {"single", ST_SPACING_SINGLE }
715 pushpophelper pph(lexrc, spacingTags, ST_OTHER);
716 int le = lexrc.lex();
718 case LyXLex::LEX_UNDEF:
719 lexrc.printError("Unknown spacing token `$$Token'");
723 switch (static_cast<SpacingTags>(le)) {
724 case ST_SPACING_SINGLE:
725 spacing.set(Spacing::Single);
727 case ST_SPACING_ONEHALF:
728 spacing.set(Spacing::Onehalf);
730 case ST_SPACING_DOUBLE:
731 spacing.set(Spacing::Double);
735 spacing.set(Spacing::Other, lexrc.getFloat());
741 string const & LyXLayout::name() const
747 void LyXLayout::setName(string const & n)
753 string const & LyXLayout::obsoleted_by() const
755 return obsoleted_by_;