1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * ======================================================
15 #pragma implementation
22 #include "support/filetools.h"
23 #include "lyx_gui_misc.h"
26 #include "support/LAssert.h"
33 // Global variable: textclass table.
34 LyXTextClassList textclasslist;
37 // Reads the style files
40 lyxerr[Debug::TCLASS] << "LyXSetStyle: parsing configuration...\n";
42 if (!textclasslist.Read()) {
43 lyxerr[Debug::TCLASS] << "LyXSetStyle: an error occured "
44 "during parsing.\n Exiting." << endl;
48 lyxerr[Debug::TCLASS] << "LyXSetStyle: configuration parsed." << endl;
52 // The order of the LayoutTags enum is no more important. [asierra300396]
63 //LT_ENVIRONMENT_DEFAULT,
79 LT_LABELSTRING_APPENDIX,
102 /////////////////////
104 // Constructor for layout
105 LyXLayout::LyXLayout ()
107 margintype = MARGIN_STATIC;
108 latextype = LATEX_PARAGRAPH;
112 font = LyXFont(LyXFont::ALL_INHERIT);
113 labelfont = LyXFont(LyXFont::ALL_INHERIT);
114 resfont = LyXFont(LyXFont::ALL_SANE);
115 reslabelfont = LyXFont(LyXFont::ALL_SANE);
116 nextnoindent = false;
121 labelbottomsep = 0.0;
123 align = LYX_ALIGN_BLOCK;
124 alignpossible = LYX_ALIGN_BLOCK;
125 labeltype = LABEL_NO_LABEL;
126 endlabeltype = END_LABEL_NO_LABEL;
127 // Should or should not. That is the question.
128 // spacing.set(Spacing::OneHalf);
131 newline_allowed = true;
132 free_spacing = false;
136 // Reads a layout definition from file
137 bool LyXLayout::Read (LyXLex & lexrc, LyXTextClass const & tclass)
139 // This table is sorted alphabetically [asierra 30March96]
140 keyword_item layoutTags[] = {
141 { "align", LT_ALIGN },
142 { "alignpossible", LT_ALIGNPOSSIBLE },
143 { "bottomsep", LT_BOTTOMSEP },
144 { "copystyle", LT_COPYSTYLE },
146 { "endlabelstring", LT_ENDLABELSTRING },
147 { "endlabeltype", LT_ENDLABELTYPE },
148 { "fill_bottom", LT_FILL_BOTTOM },
149 { "fill_top", LT_FILL_TOP },
151 { "freespacing", LT_FREE_SPACING },
152 { "intitle", LT_INTITLE },
153 { "itemsep", LT_ITEMSEP },
154 { "keepempty", LT_KEEPEMPTY },
155 { "labelbottomsep", LT_LABEL_BOTTOMSEP },
156 { "labelfont", LT_LABELFONT },
157 { "labelindent", LT_LABELINDENT },
158 { "labelsep", LT_LABELSEP },
159 { "labelstring", LT_LABELSTRING },
160 { "labelstringappendix", LT_LABELSTRING_APPENDIX },
161 { "labeltype", LT_LABELTYPE },
162 { "latexname", LT_LATEXNAME },
163 { "latexparam", LT_LATEXPARAM },
164 { "latextype", LT_LATEXTYPE },
165 { "leftmargin", LT_LEFTMARGIN },
166 { "margin", LT_MARGIN },
167 { "needprotect", LT_NEED_PROTECT },
168 { "newline", LT_NEWLINE },
169 { "nextnoindent", LT_NEXTNOINDENT },
170 { "obsoletedby", LT_OBSOLETEDBY },
171 { "parindent", LT_PARINDENT },
172 { "parsep", LT_PARSEP },
173 { "parskip", LT_PARSKIP },
174 { "preamble", LT_PREAMBLE },
175 { "rightmargin", LT_RIGHTMARGIN },
176 { "spacing", LT_SPACING },
177 { "textfont", LT_TEXTFONT },
178 { "topsep", LT_TOPSEP }
182 bool finished = false;
183 lexrc.pushTable(layoutTags, LT_INTITLE);
184 // parse style section
185 while (!finished && lexrc.IsOK() && !error) {
186 int le = lexrc.lex();
187 // See comment in lyxrc.C.
189 case LyXLex::LEX_FEOF:
192 case LyXLex::LEX_UNDEF: // parse error
193 lexrc.printError("Unknown layout tag `$$Token'");
198 switch(static_cast<LayoutTags>(le)) {
199 case LT_END: // end of structure
203 case LT_COPYSTYLE: // initialize with a known style
205 if (tclass.hasLayout(lexrc.GetString())) {
206 string tmpname = name_;
207 this->operator= (tclass.GetLayout(lexrc.GetString()));
210 lexrc.printError("Cannot copy known "
216 case LT_OBSOLETEDBY: // replace with a known style
218 if (tclass.hasLayout(lexrc.GetString())) {
219 string tmpname = name_;
220 this->operator= (tclass.GetLayout(lexrc.GetString()));
222 if (obsoleted_by().empty())
223 obsoleted_by_ = lexrc.GetString();
225 lexrc.printError("Cannot replace with"
232 case LT_MARGIN: // Margin style definition.
236 case LT_LATEXTYPE: // Latex style definition.
237 readLatexType(lexrc);
241 intitle = lexrc.next() && lexrc.GetInteger();
244 case LT_NEED_PROTECT:
245 needprotect = lexrc.next() && lexrc.GetInteger();
249 keepempty = lexrc.next() && lexrc.GetInteger();
262 labelfont.lyxRead(lexrc);
265 case LT_NEXTNOINDENT: // Indent next paragraph?
266 if (lexrc.next() && lexrc.GetInteger())
269 nextnoindent = false;
274 latexname_ = lexrc.GetString();
279 latexparam_ = lexrc.GetString();
283 preamble_ = lexrc.getLongString("EndPreamble");
287 readLabelType(lexrc);
290 case LT_ENDLABELTYPE:
291 readEndLabelType(lexrc);
294 case LT_LEFTMARGIN: // left margin type
296 leftmargin = lexrc.GetString();
299 case LT_RIGHTMARGIN: // right margin type
301 rightmargin = lexrc.GetString();
304 case LT_LABELINDENT: // label indenting flag
306 labelindent = lexrc.GetString();
309 case LT_PARINDENT: // paragraph indent. flag
311 parindent = lexrc.GetString();
314 case LT_PARSKIP: // paragraph skip size
316 parskip = lexrc.GetFloat();
319 case LT_ITEMSEP: // item separation size
321 itemsep = lexrc.GetFloat();
324 case LT_TOPSEP: // top separation size
326 topsep = lexrc.GetFloat();
329 case LT_BOTTOMSEP: // bottom separation size
331 bottomsep = lexrc.GetFloat();
334 case LT_LABEL_BOTTOMSEP: // label bottom separation size
336 labelbottomsep = lexrc.GetFloat();
339 case LT_LABELSEP: // label separator
341 labelsep = subst(lexrc.GetString(), 'x', ' ');
345 case LT_PARSEP: // par. separation size
347 parsep = lexrc.GetFloat();
350 case LT_FILL_TOP: // fill top flag
352 fill_top = lexrc.GetInteger();
355 case LT_FILL_BOTTOM: // fill bottom flag
357 fill_bottom = lexrc.GetInteger();
360 case LT_NEWLINE: // newlines allowed?
362 newline_allowed = lexrc.GetInteger();
365 case LT_ALIGN: // paragraph align
368 case LT_ALIGNPOSSIBLE: // paragraph allowed align
369 readAlignPossible(lexrc);
372 case LT_LABELSTRING: // label string definition
374 labelstring_ = lexrc.GetString();
377 case LT_ENDLABELSTRING: // endlabel string definition
379 endlabelstring_ = lexrc.GetString();
382 case LT_LABELSTRING_APPENDIX: // label string appendix definition
384 labelstring_appendix_ = lexrc.GetString();
387 case LT_FREE_SPACING: // Allow for free spacing.
389 free_spacing = lexrc.GetInteger();
392 case LT_SPACING: // setspace.sty
411 void LyXLayout::readAlign(LyXLex & lexrc)
413 keyword_item alignTags[] = {
414 { "block", AT_BLOCK },
415 { "center", AT_CENTER },
416 { "layout", AT_LAYOUT },
418 { "right", AT_RIGHT }
421 pushpophelper pph(lexrc, alignTags, AT_LAYOUT);
422 int le = lexrc.lex();
424 case LyXLex::LEX_UNDEF:
425 lexrc.printError("Unknown alignment `$$Token'");
429 switch(static_cast<AlignTags>(le)) {
431 align = LYX_ALIGN_BLOCK;
434 align = LYX_ALIGN_LEFT;
437 align = LYX_ALIGN_RIGHT;
440 align = LYX_ALIGN_CENTER;
443 align = LYX_ALIGN_LAYOUT;
449 void LyXLayout::readAlignPossible(LyXLex & lexrc)
451 keyword_item alignTags[] = {
452 { "block", AT_BLOCK },
453 { "center", AT_CENTER },
454 { "layout", AT_LAYOUT },
456 { "right", AT_RIGHT }
459 lexrc.pushTable(alignTags, AT_LAYOUT);
460 alignpossible = LYX_ALIGN_NONE;
461 int lineno = lexrc.GetLineNo();
463 int le = lexrc.lex();
465 case LyXLex::LEX_UNDEF:
466 lexrc.printError("Unknown alignment `$$Token'");
470 switch (static_cast<AlignTags>(le)) {
472 alignpossible |= LYX_ALIGN_BLOCK;
475 alignpossible |= LYX_ALIGN_LEFT;
478 alignpossible |= LYX_ALIGN_RIGHT;
481 alignpossible |= LYX_ALIGN_CENTER;
484 alignpossible |= LYX_ALIGN_LAYOUT;
487 } while (lineno == lexrc.GetLineNo());
496 LA_CENTERED_TOP_ENVIRONMENT,
501 LA_COUNTER_SUBSECTION,
502 LA_COUNTER_SUBSUBSECTION,
503 LA_COUNTER_PARAGRAPH,
504 LA_COUNTER_SUBPARAGRAPH,
513 void LyXLayout::readLabelType(LyXLex & lexrc)
515 keyword_item labelTypeTags[] = {
516 { "bibliography", LA_BIBLIO },
517 { "centered_top_environment", LA_CENTERED_TOP_ENVIRONMENT },
518 { "counter_chapter", LA_COUNTER_CHAPTER },
519 { "counter_enumi", LA_COUNTER_ENUMI },
520 { "counter_enumii", LA_COUNTER_ENUMII },
521 { "counter_enumiii", LA_COUNTER_ENUMIII },
522 { "counter_enumiv", LA_COUNTER_ENUMIV },
523 { "counter_paragraph", LA_COUNTER_PARAGRAPH },
524 { "counter_section", LA_COUNTER_SECTION },
525 { "counter_subparagraph", LA_COUNTER_SUBPARAGRAPH },
526 { "counter_subsection", LA_COUNTER_SUBSECTION },
527 { "counter_subsubsection", LA_COUNTER_SUBSUBSECTION },
528 { "manual", LA_MANUAL },
529 { "no_label", LA_NO_LABEL },
530 { "sensitive", LA_SENSITIVE },
531 { "static", LA_STATIC },
532 { "top_environment", LA_TOP_ENVIRONMENT }
535 pushpophelper pph(lexrc, labelTypeTags, LA_BIBLIO);
536 int le = lexrc.lex();
538 case LyXLex::LEX_UNDEF:
539 lexrc.printError("Unknown labeltype tag `$$Token'");
543 switch (static_cast<LabelTypeTags>(le)) {
545 labeltype = LABEL_NO_LABEL;
548 labeltype = LABEL_MANUAL;
550 case LA_TOP_ENVIRONMENT:
551 labeltype = LABEL_TOP_ENVIRONMENT;
553 case LA_CENTERED_TOP_ENVIRONMENT:
554 labeltype = LABEL_CENTERED_TOP_ENVIRONMENT;
557 labeltype = LABEL_STATIC;
560 labeltype = LABEL_SENSITIVE;
562 case LA_COUNTER_CHAPTER:
563 labeltype = LABEL_COUNTER_CHAPTER;
565 case LA_COUNTER_SECTION:
566 labeltype = LABEL_COUNTER_SECTION;
568 case LA_COUNTER_SUBSECTION:
569 labeltype = LABEL_COUNTER_SUBSECTION;
571 case LA_COUNTER_SUBSUBSECTION:
572 labeltype = LABEL_COUNTER_SUBSUBSECTION;
574 case LA_COUNTER_PARAGRAPH:
575 labeltype = LABEL_COUNTER_PARAGRAPH;
577 case LA_COUNTER_SUBPARAGRAPH:
578 labeltype = LABEL_COUNTER_SUBPARAGRAPH;
580 case LA_COUNTER_ENUMI:
581 labeltype = LABEL_COUNTER_ENUMI;
583 case LA_COUNTER_ENUMII:
584 labeltype = LABEL_COUNTER_ENUMII;
586 case LA_COUNTER_ENUMIII:
587 labeltype = LABEL_COUNTER_ENUMIII;
589 case LA_COUNTER_ENUMIV:
590 labeltype = LABEL_COUNTER_ENUMIV;
593 labeltype = LABEL_BIBLIO;
598 static 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 }
605 void LyXLayout::readEndLabelType(LyXLex & lexrc)
607 pushpophelper pph(lexrc, endlabelTypeTags,
608 END_LABEL_ENUM_LAST-END_LABEL_ENUM_FIRST+1);
609 int le = lexrc.lex();
611 case LyXLex::LEX_UNDEF:
612 lexrc.printError("Unknown labeltype tag `$$Token'");
614 case END_LABEL_STATIC:
616 case END_LABEL_FILLED_BOX:
617 case END_LABEL_NO_LABEL:
618 endlabeltype = static_cast<LYX_END_LABEL_TYPES>(le);
621 lyxerr << "Unhandled value " << le
622 << " in LyXLayout::readEndLabelType." << endl;
628 void LyXLayout::readMargin(LyXLex & lexrc)
630 keyword_item marginTags[] = {
631 { "dynamic", MARGIN_DYNAMIC },
632 { "first_dynamic", MARGIN_FIRST_DYNAMIC },
633 { "manual", MARGIN_MANUAL },
634 { "right_address_box", MARGIN_RIGHT_ADDRESS_BOX },
635 { "static", MARGIN_STATIC }
638 pushpophelper pph(lexrc, marginTags, MARGIN_RIGHT_ADDRESS_BOX);
640 int le = lexrc.lex();
642 case LyXLex::LEX_UNDEF:
643 lexrc.printError("Unknown margin type tag `$$Token'");
648 case MARGIN_FIRST_DYNAMIC:
649 case MARGIN_RIGHT_ADDRESS_BOX:
650 margintype = static_cast<LYX_MARGIN_TYPE>(le);
653 lyxerr << "Unhandled value " << le
654 << " in LyXLayout::readMargin." << endl;
660 void LyXLayout::readLatexType(LyXLex & lexrc)
662 keyword_item latexTypeTags[] = {
663 { "command", LATEX_COMMAND },
664 { "environment", LATEX_ENVIRONMENT },
665 { "item_environment", LATEX_ITEM_ENVIRONMENT },
666 { "list_environment", LATEX_LIST_ENVIRONMENT },
667 { "paragraph", LATEX_PARAGRAPH }
670 pushpophelper pph(lexrc, latexTypeTags, LATEX_LIST_ENVIRONMENT);
671 int le = lexrc.lex();
673 case LyXLex::LEX_UNDEF:
674 lexrc.printError("Unknown latextype tag `$$Token'");
676 case LATEX_PARAGRAPH:
678 case LATEX_ENVIRONMENT:
679 case LATEX_ITEM_ENVIRONMENT:
680 case LATEX_LIST_ENVIRONMENT:
681 latextype = static_cast<LYX_LATEX_TYPES>(le);
684 lyxerr << "Unhandled value " << le
685 << " in LyXLayout::readLatexType." << endl;
692 ST_SPACING_SINGLE = 1,
699 void LyXLayout::readSpacing(LyXLex & lexrc)
701 keyword_item spacingTags[] = {
702 {"double", ST_SPACING_DOUBLE },
703 {"onehalf", ST_SPACING_ONEHALF },
704 {"other", ST_OTHER },
705 {"single", ST_SPACING_SINGLE }
708 pushpophelper pph(lexrc, spacingTags, ST_OTHER);
709 int le = lexrc.lex();
711 case LyXLex::LEX_UNDEF:
712 lexrc.printError("Unknown spacing token `$$Token'");
716 switch(static_cast<SpacingTags>(le)) {
717 case ST_SPACING_SINGLE:
718 spacing.set(Spacing::Single);
720 case ST_SPACING_ONEHALF:
721 spacing.set(Spacing::Onehalf);
723 case ST_SPACING_DOUBLE:
724 spacing.set(Spacing::Double);
728 spacing.set(Spacing::Other, lexrc.GetFloat());
734 /* ******************************************************************* */
736 LyXTextClass::LyXTextClass(string const & fn, string const & cln,
738 : name_(fn), latexname_(cln), description_(desc)
745 pagestyle_ = "default";
746 maxcounter_ = LABEL_COUNTER_CHAPTER;
747 defaultfont_ = LyXFont(LyXFont::ALL_SANE);
748 opt_fontsize_ = "10|11|12";
749 opt_pagestyle_ = "empty|plain|headings|fancy";
755 bool LyXTextClass::do_readStyle(LyXLex & lexrc, LyXLayout & lay)
757 lyxerr[Debug::TCLASS] << "Reading style " << lay.name() << endl;
758 if (!lay.Read(lexrc, *this)) {
760 lay.resfont = lay.font;
761 lay.resfont.realize(defaultfont());
762 lay.reslabelfont = lay.labelfont;
763 lay.reslabelfont.realize(defaultfont());
764 return false; // no errors
766 lyxerr << "Error parsing style `" << lay.name() << "'" << endl;
793 // Reads a textclass structure from file.
794 bool LyXTextClass::Read(string const & filename, bool merge)
796 keyword_item textClassTags[] = {
797 { "classoptions", TC_CLASSOPTIONS },
798 { "columns", TC_COLUMNS },
799 { "defaultfont", TC_DEFAULTFONT },
800 { "input", TC_INPUT },
801 { "leftmargin", TC_LEFTMARGIN },
802 { "maxcounter", TC_MAXCOUNTER },
803 { "nostyle", TC_NOSTYLE },
804 { "outputtype", TC_OUTPUTTYPE },
805 { "pagestyle", TC_PAGESTYLE },
806 { "preamble", TC_PREAMBLE },
807 { "providesamsmath", TC_PROVIDESAMSMATH },
808 { "providesmakeidx", TC_PROVIDESMAKEIDX },
809 { "providesurl", TC_PROVIDESURL },
810 { "rightmargin", TC_RIGHTMARGIN },
811 { "secnumdepth", TC_SECNUMDEPTH },
812 { "sides", TC_SIDES },
813 { "style", TC_STYLE },
814 { "tocdepth", TC_TOCDEPTH }
818 lyxerr[Debug::TCLASS] << "Reading textclass "
819 << MakeDisplayPath(filename)
822 lyxerr[Debug::TCLASS] << "Reading input file "
823 << MakeDisplayPath(filename)
826 LyXLex lexrc(textClassTags, TC_RIGHTMARGIN);
829 lexrc.setFile(filename);
830 if (!lexrc.IsOK()) error = true;
833 while (lexrc.IsOK() && !error) {
834 int le = lexrc.lex();
836 case LyXLex::LEX_FEOF:
839 case LyXLex::LEX_UNDEF:
840 lexrc.printError("Unknown TextClass tag `$$Token'");
845 switch(static_cast<TextClassTags>(le)) {
846 case TC_OUTPUTTYPE: // output type definition
847 readOutputType(lexrc);
850 case TC_INPUT: // Include file
852 string tmp = LibFileSearch("layouts",
856 if (Read(tmp, true)) {
857 lexrc.printError("Error reading input"
866 string name = subst(lexrc.GetString(),
868 if (hasLayout(name)) {
869 LyXLayout & lay = GetLayout(name);
870 error = do_readStyle(lexrc, lay);
874 if (!(error = do_readStyle(lexrc, lay)))
875 layoutlist.push_back(lay);
879 lexrc.printError("No name given for style: `$$Token'.");
886 string style = subst(lexrc.GetString(),
888 if (!delete_layout(style))
889 lexrc.printError("Cannot delete style"
896 columns_ = lexrc.GetInteger();
901 switch(lexrc.GetInteger()) {
902 case 1: sides_ = OneSide; break;
903 case 2: sides_ = TwoSides; break;
905 lyxerr << "Impossible number of page"
906 " sides, setting to one."
916 pagestyle_ = strip(lexrc.GetString());
920 defaultfont_.lyxRead(lexrc);
921 if (!defaultfont_.resolved()) {
922 lexrc.printError("Warning: defaultfont should "
923 "be fully instantiated!");
924 defaultfont_.realize(LyXFont(LyXFont::ALL_SANE));
929 readMaxCounter(lexrc);
934 secnumdepth_ = lexrc.GetInteger();
939 tocdepth_ = lexrc.GetInteger();
942 // First step to support options
943 case TC_CLASSOPTIONS:
944 readClassOptions(lexrc);
948 preamble_ = lexrc.getLongString("EndPreamble");
951 case TC_PROVIDESAMSMATH:
952 if (lexrc.next() && lexrc.GetInteger())
953 provides_ |= amsmath;
956 case TC_PROVIDESMAKEIDX:
957 if (lexrc.next() && lexrc.GetInteger())
958 provides_ |= makeidx;
962 if (lexrc.next() && lexrc.GetInteger())
966 case TC_LEFTMARGIN: // left margin type
968 leftmargin_ = lexrc.GetString();
971 case TC_RIGHTMARGIN: // right margin type
973 rightmargin_ = lexrc.GetString();
978 if (!merge) { // we are at top level here.
979 lyxerr[Debug::TCLASS] << "Finished reading textclass "
980 << MakeDisplayPath(filename)
983 lyxerr[Debug::TCLASS] << "Finished reading input file "
984 << MakeDisplayPath(filename)
991 void LyXTextClass::readOutputType(LyXLex & lexrc)
993 keyword_item outputTypeTags[] = {
994 { "docbook", DOCBOOK },
996 { "linuxdoc", LINUXDOC },
997 { "literate", LITERATE }
1000 pushpophelper pph(lexrc, outputTypeTags, LITERATE);
1002 int le = lexrc.lex();
1004 case LyXLex::LEX_UNDEF:
1005 lexrc.printError("Unknown output type `$$Token'");
1011 outputType_ = static_cast<OutputType>(le);
1014 lyxerr << "Unhandled value " << le
1015 << " in LyXTextClass::readOutputType." << endl;
1022 enum MaxCounterTags {
1023 MC_COUNTER_CHAPTER = 1,
1025 MC_COUNTER_SUBSECTION,
1026 MC_COUNTER_SUBSUBSECTION,
1027 MC_COUNTER_PARAGRAPH,
1028 MC_COUNTER_SUBPARAGRAPH,
1036 void LyXTextClass::readMaxCounter(LyXLex & lexrc)
1038 keyword_item maxCounterTags[] = {
1039 {"counter_chapter", MC_COUNTER_CHAPTER },
1040 {"counter_enumi", MC_COUNTER_ENUMI },
1041 {"counter_enumii", MC_COUNTER_ENUMII },
1042 {"counter_enumiii", MC_COUNTER_ENUMIII },
1043 {"counter_enumiv", MC_COUNTER_ENUMIV },
1044 {"counter_paragraph", MC_COUNTER_PARAGRAPH },
1045 {"counter_section", MC_COUNTER_SECTION },
1046 {"counter_subparagraph", MC_COUNTER_SUBPARAGRAPH },
1047 {"counter_subsection", MC_COUNTER_SUBSECTION },
1048 {"counter_subsubsection", MC_COUNTER_SUBSUBSECTION }
1051 pushpophelper pph(lexrc, maxCounterTags, MC_COUNTER_ENUMIV);
1052 int le = lexrc.lex();
1054 case LyXLex::LEX_UNDEF:
1055 lexrc.printError("Unknown MaxCounter tag `$$Token'");
1059 switch (static_cast<MaxCounterTags>(le)) {
1060 case MC_COUNTER_CHAPTER:
1061 maxcounter_ = LABEL_COUNTER_CHAPTER;
1063 case MC_COUNTER_SECTION:
1064 maxcounter_ = LABEL_COUNTER_SECTION;
1066 case MC_COUNTER_SUBSECTION:
1067 maxcounter_ = LABEL_COUNTER_SUBSECTION;
1069 case MC_COUNTER_SUBSUBSECTION:
1070 maxcounter_ = LABEL_COUNTER_SUBSUBSECTION;
1072 case MC_COUNTER_PARAGRAPH:
1073 maxcounter_ = LABEL_COUNTER_PARAGRAPH;
1075 case MC_COUNTER_SUBPARAGRAPH:
1076 maxcounter_ = LABEL_COUNTER_SUBPARAGRAPH;
1078 case MC_COUNTER_ENUMI:
1079 maxcounter_ = LABEL_COUNTER_ENUMI;
1081 case MC_COUNTER_ENUMII:
1082 maxcounter_ = LABEL_COUNTER_ENUMII;
1084 case MC_COUNTER_ENUMIII:
1085 maxcounter_ = LABEL_COUNTER_ENUMIII;
1087 case MC_COUNTER_ENUMIV:
1088 maxcounter_ = LABEL_COUNTER_ENUMIV;
1094 enum ClassOptionsTags {
1102 void LyXTextClass::readClassOptions(LyXLex & lexrc)
1104 keyword_item classOptionsTags[] = {
1106 {"fontsize", CO_FONTSIZE },
1107 {"other", CO_OTHER },
1108 {"pagestyle", CO_PAGESTYLE }
1111 lexrc.pushTable(classOptionsTags, CO_END);
1112 bool getout = false;
1113 while (!getout && lexrc.IsOK()) {
1114 int le = lexrc.lex();
1116 case LyXLex::LEX_UNDEF:
1117 lexrc.printError("Unknown ClassOption tag `$$Token'");
1121 switch (static_cast<ClassOptionsTags>(le)) {
1124 opt_fontsize_ = strip(lexrc.GetString());
1128 opt_pagestyle_ = strip(lexrc.GetString());
1132 options_ = lexrc.GetString();
1143 bool LyXTextClass::hasLayout(string const & name) const
1145 for (LayoutList::const_iterator cit = layoutlist.begin();
1146 cit != layoutlist.end(); ++cit) {
1147 if ((*cit).name() == name)
1154 LyXLayout const & LyXTextClass::GetLayout (string const & name) const
1156 for (LayoutList::const_iterator cit = layoutlist.begin();
1157 cit != layoutlist.end(); ++cit) {
1158 if ((*cit).name() == name)
1161 Assert(false); // we actually require the name to exist.
1162 return layoutlist.front();
1166 LyXLayout & LyXTextClass::GetLayout(string const & name)
1168 for (LayoutList::iterator it = layoutlist.begin();
1169 it != layoutlist.end(); ++it) {
1170 if ((*it).name() == name)
1173 Assert(false); // we actually require the name to exist.
1174 return layoutlist.front();
1178 bool LyXTextClass::delete_layout (string const & name)
1180 for(LayoutList::iterator it = layoutlist.begin();
1181 it != layoutlist.end(); ++it) {
1182 if ((*it).name() == name) {
1183 layoutlist.erase(it);
1191 // Load textclass info if not loaded yet
1192 void LyXTextClass::load()
1197 string real_file = LibFileSearch("layouts", name_, "layout");
1199 if (Read(real_file)) {
1200 lyxerr << "Error reading `"
1201 << MakeDisplayPath(real_file)
1202 << "'\n(Check `" << name_
1203 << "')\nCheck your installation and "
1204 "try Options/Reconfigure..." << endl;
1210 //////////////////////////////////////////
1212 // Gets textclass number from name
1213 pair<bool, LyXTextClassList::size_type>
1214 LyXTextClassList::NumberOfClass(string const & textclass) const
1216 for (ClassList::const_iterator cit = classlist.begin();
1217 cit != classlist.end(); ++cit) {
1218 if ((*cit).name() == textclass)
1219 return make_pair(true,
1220 size_type(cit - classlist.begin()));
1222 return make_pair(false, size_type(0));
1226 // Gets layout structure from style number and textclass number
1228 LyXTextClassList::Style(LyXTextClassList::size_type textclass,
1229 LyXTextClass::size_type layout) const
1231 classlist[textclass].load();
1232 if (layout < classlist[textclass].numLayouts())
1233 return classlist[textclass][layout];
1234 return classlist[textclass][0];
1238 // Gets layout number from name and textclass number
1239 pair<bool, LyXTextClass::size_type>
1240 LyXTextClassList::NumberOfLayout(LyXTextClassList::size_type textclass,
1241 string const & name) const
1243 classlist[textclass].load();
1244 for(unsigned int i = 0; i < classlist[textclass].numLayouts(); ++i) {
1245 if (classlist[textclass][i].name() == name)
1246 return make_pair(true, i);
1248 if (name == "dummy")
1249 return make_pair(true, LyXTextClassList::size_type(LYX_DUMMY_LAYOUT));
1250 return make_pair(false, LyXTextClass::size_type(0)); // not found
1254 // Gets a layout (style) name from layout number and textclass number
1256 LyXTextClassList::NameOfLayout(LyXTextClassList::size_type textclass,
1257 LyXTextClass::size_type layout) const
1259 static string dummy("dummy");
1260 classlist[textclass].load();
1261 if (layout < classlist[textclass].numLayouts())
1262 return classlist[textclass][layout].name();
1267 // Gets a textclass name from number
1269 LyXTextClassList::NameOfClass(LyXTextClassList::size_type number) const
1271 static string dummy("dummy");
1272 if (classlist.size() == 0) {
1275 Assert(number < classlist.size());
1276 return classlist[number].name();
1280 // Gets a textclass latexname from number
1282 LyXTextClassList::LatexnameOfClass(LyXTextClassList::size_type number) const
1284 static string dummy("dummy");
1285 classlist[number].load();
1286 if (classlist.size() == 0) {
1289 Assert(number < classlist.size());
1290 return classlist[number].latexname();
1294 // Gets a textclass description from number
1296 LyXTextClassList::DescOfClass(LyXTextClassList::size_type number) const
1298 static string dummy("dummy");
1299 if (classlist.size() == 0) {
1302 Assert(number < classlist.size());
1303 return classlist[number].description();
1307 // Gets a textclass structure from number
1308 LyXTextClass const &
1309 LyXTextClassList::TextClass(LyXTextClassList::size_type textclass) const
1311 classlist[textclass].load();
1312 if (textclass < classlist.size())
1313 return classlist[textclass];
1315 return classlist[0];
1319 void LyXTextClassList::Add(LyXTextClass const & t)
1321 classlist.push_back(t);
1325 // used when sorting the textclass list.
1326 class less_textclass_desc {
1328 int operator()(LyXTextClass const & tc1, LyXTextClass const & tc2) {
1329 return tc1.description() < tc2.description();
1334 // Reads LyX textclass definitions according to textclass config file
1335 bool LyXTextClassList::Read ()
1338 string real_file = LibFileSearch("", "textclass.lst");
1339 lyxerr[Debug::TCLASS] << "Reading textclasses from `"
1340 << real_file << "'" << endl;
1342 if (real_file.empty()) {
1343 lyxerr << "LyXTextClassList::Read: unable to find "
1344 "textclass file `" << MakeDisplayPath(real_file, 1000)
1345 << "'. Exiting." << endl;
1347 WriteAlert(_("LyX wasn't able to find its layout descriptions!"),
1348 _("Check that the file \"textclass.lst\""),
1349 _("is installed correctly. Sorry, has to exit :-("));
1351 // This causes LyX to end... Not a desirable behaviour. Lgb
1352 // What do you propose? That the user gets a file dialog
1353 // and is allowed to hunt for the file? (Asger)
1354 // more that we have a layout for minimal.cls statically
1355 // compiled in... (Lgb)
1358 if (!lex.setFile(real_file)) {
1359 lyxerr << "LyXTextClassList::Read: "
1360 "lyxlex was not able to set file: "
1361 << real_file << endl;
1365 lyxerr << "LyXTextClassList::Read: unable to open "
1366 "textclass file `" << MakeDisplayPath(real_file, 1000)
1367 << "'\nCheck your installation. LyX can't continue."
1371 bool finished = false;
1372 string fname, clname, desc;
1373 // Parse config-file
1374 lyxerr[Debug::TCLASS] << "Starting parsing of textclass.lst" << endl;
1375 while (lex.IsOK() && !finished) {
1376 lyxerr[Debug::TCLASS] << "\tline by line" << endl;
1377 switch (lex.lex()) {
1378 case LyXLex::LEX_FEOF:
1382 fname = lex.GetString();
1383 lyxerr[Debug::TCLASS] << "Fname: " << fname << endl;
1385 clname = lex.GetString();
1386 lyxerr[Debug::TCLASS]
1387 << "Clname: " << clname << endl;
1389 desc = lex.GetString();
1390 lyxerr[Debug::TCLASS]
1391 << "Desc: " << desc << endl;
1392 // This code is run when we have
1393 // fname, clname and desc
1394 LyXTextClass tmpl(fname,
1398 debugging(Debug::TCLASS)) {
1406 lyxerr[Debug::TCLASS] << "End of parsing of textclass.lst" << endl;
1408 if (classlist.size() == 0) {
1409 lyxerr << "LyXTextClassList::Read: no textclasses found!"
1411 WriteAlert(_("LyX wasn't able to find any layout description!"),
1412 _("Check the contents of the file \"textclass.lst\""),
1413 _("Sorry, has to exit :-("));
1416 // Ok everything loaded ok, now sort the list.
1417 sort(classlist.begin(), classlist.end(), less_textclass_desc());
1423 Returns false if this fails
1426 LyXTextClassList::Load (LyXTextClassList::size_type number) const
1429 if (number < classlist.size()) {
1430 classlist[number].load();
1431 if (classlist[number].numLayouts() == 0) {
1441 std::ostream & operator<<(std::ostream & os, LyXTextClass::PageSides p)
1444 case LyXTextClass::OneSide:
1447 case LyXTextClass::TwoSides: