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 * ====================================================== */
14 #pragma implementation
21 #include "support/filetools.h"
22 #include "lyx_gui_misc.h"
25 #include "support/LAssert.h"
32 // Global variable: textclass table.
33 LyXTextClassList textclasslist;
36 // Reads the style files
39 lyxerr[Debug::TCLASS] << "LyXSetStyle: parsing configuration...\n";
41 if (!textclasslist.Read()) {
42 lyxerr[Debug::TCLASS] << "LyXSetStyle: an error occured "
43 "during parsing.\n Exiting." << endl;
47 lyxerr[Debug::TCLASS] << "LyXSetStyle: configuration parsed." << endl;
51 // The order of the LayoutTags enum is no more important. [asierra300396]
62 //LT_ENVIRONMENT_DEFAULT,
78 LT_LABELSTRING_APPENDIX,
101 /////////////////////
103 // Constructor for layout
104 LyXLayout::LyXLayout ()
106 margintype = MARGIN_STATIC;
107 latextype = LATEX_PARAGRAPH;
111 font = LyXFont(LyXFont::ALL_INHERIT);
112 labelfont = LyXFont(LyXFont::ALL_INHERIT);
113 resfont = LyXFont(LyXFont::ALL_SANE);
114 reslabelfont = LyXFont(LyXFont::ALL_SANE);
115 nextnoindent = false;
120 labelbottomsep = 0.0;
122 align = LYX_ALIGN_BLOCK;
123 alignpossible = LYX_ALIGN_BLOCK;
124 labeltype = LABEL_NO_LABEL;
125 endlabeltype = END_LABEL_NO_LABEL;
126 // Should or should not. That is the question.
127 // spacing.set(Spacing::OneHalf);
130 newline_allowed = true;
131 free_spacing = false;
135 // Reads a layout definition from file
136 bool LyXLayout::Read (LyXLex & lexrc, LyXTextClass const & tclass)
138 // This table is sorted alphabetically [asierra 30March96]
139 keyword_item layoutTags[] = {
140 { "align", LT_ALIGN },
141 { "alignpossible", LT_ALIGNPOSSIBLE },
142 { "bottomsep", LT_BOTTOMSEP },
143 { "copystyle", LT_COPYSTYLE },
145 { "endlabelstring", LT_ENDLABELSTRING },
146 { "endlabeltype", LT_ENDLABELTYPE },
147 { "fill_bottom", LT_FILL_BOTTOM },
148 { "fill_top", LT_FILL_TOP },
150 { "freespacing", LT_FREE_SPACING },
151 { "intitle", LT_INTITLE },
152 { "itemsep", LT_ITEMSEP },
153 { "keepempty", LT_KEEPEMPTY },
154 { "labelbottomsep", LT_LABEL_BOTTOMSEP },
155 { "labelfont", LT_LABELFONT },
156 { "labelindent", LT_LABELINDENT },
157 { "labelsep", LT_LABELSEP },
158 { "labelstring", LT_LABELSTRING },
159 { "labelstringappendix", LT_LABELSTRING_APPENDIX },
160 { "labeltype", LT_LABELTYPE },
161 { "latexname", LT_LATEXNAME },
162 { "latexparam", LT_LATEXPARAM },
163 { "latextype", LT_LATEXTYPE },
164 { "leftmargin", LT_LEFTMARGIN },
165 { "margin", LT_MARGIN },
166 { "needprotect", LT_NEED_PROTECT },
167 { "newline", LT_NEWLINE },
168 { "nextnoindent", LT_NEXTNOINDENT },
169 { "obsoletedby", LT_OBSOLETEDBY },
170 { "parindent", LT_PARINDENT },
171 { "parsep", LT_PARSEP },
172 { "parskip", LT_PARSKIP },
173 { "preamble", LT_PREAMBLE },
174 { "rightmargin", LT_RIGHTMARGIN },
175 { "spacing", LT_SPACING },
176 { "textfont", LT_TEXTFONT },
177 { "topsep", LT_TOPSEP }
181 bool finished = false;
182 lexrc.pushTable(layoutTags, LT_INTITLE);
183 // parse style section
184 while (!finished && lexrc.IsOK() && !error) {
185 int le = lexrc.lex();
186 // See comment in lyxrc.C.
188 case LyXLex::LEX_FEOF:
191 case LyXLex::LEX_UNDEF: // parse error
192 lexrc.printError("Unknown layout tag `$$Token'");
197 switch(static_cast<LayoutTags>(le)) {
198 case LT_END: // end of structure
202 case LT_COPYSTYLE: // initialize with a known style
204 if (tclass.hasLayout(lexrc.GetString())) {
205 string tmpname = name_;
206 this->operator= (tclass.GetLayout(lexrc.GetString()));
209 lexrc.printError("Cannot copy known "
215 case LT_OBSOLETEDBY: // replace with a known style
217 if (tclass.hasLayout(lexrc.GetString())) {
218 string tmpname = name_;
219 this->operator= (tclass.GetLayout(lexrc.GetString()));
221 if (obsoleted_by().empty())
222 obsoleted_by_ = lexrc.GetString();
224 lexrc.printError("Cannot replace with"
231 case LT_MARGIN: // Margin style definition.
235 case LT_LATEXTYPE: // Latex style definition.
236 readLatexType(lexrc);
240 intitle = lexrc.next() && lexrc.GetInteger();
243 case LT_NEED_PROTECT:
244 needprotect = lexrc.next() && lexrc.GetInteger();
248 keepempty = lexrc.next() && lexrc.GetInteger();
261 labelfont.lyxRead(lexrc);
264 case LT_NEXTNOINDENT: // Indent next paragraph?
265 if (lexrc.next() && lexrc.GetInteger())
268 nextnoindent = false;
273 latexname_ = lexrc.GetString();
278 latexparam_ = lexrc.GetString();
282 preamble_ = lexrc.getLongString("EndPreamble");
286 readLabelType(lexrc);
289 case LT_ENDLABELTYPE:
290 readEndLabelType(lexrc);
293 case LT_LEFTMARGIN: // left margin type
295 leftmargin = lexrc.GetString();
298 case LT_RIGHTMARGIN: // right margin type
300 rightmargin = lexrc.GetString();
303 case LT_LABELINDENT: // label indenting flag
305 labelindent = lexrc.GetString();
308 case LT_PARINDENT: // paragraph indent. flag
310 parindent = lexrc.GetString();
313 case LT_PARSKIP: // paragraph skip size
315 parskip = lexrc.GetFloat();
318 case LT_ITEMSEP: // item separation size
320 itemsep = lexrc.GetFloat();
323 case LT_TOPSEP: // top separation size
325 topsep = lexrc.GetFloat();
328 case LT_BOTTOMSEP: // bottom separation size
330 bottomsep = lexrc.GetFloat();
333 case LT_LABEL_BOTTOMSEP: // label bottom separation size
335 labelbottomsep = lexrc.GetFloat();
338 case LT_LABELSEP: // label separator
340 labelsep = subst(lexrc.GetString(), 'x', ' ');
344 case LT_PARSEP: // par. separation size
346 parsep = lexrc.GetFloat();
349 case LT_FILL_TOP: // fill top flag
351 fill_top = lexrc.GetInteger();
354 case LT_FILL_BOTTOM: // fill bottom flag
356 fill_bottom = lexrc.GetInteger();
359 case LT_NEWLINE: // newlines allowed?
361 newline_allowed = lexrc.GetInteger();
364 case LT_ALIGN: // paragraph align
367 case LT_ALIGNPOSSIBLE: // paragraph allowed align
368 readAlignPossible(lexrc);
371 case LT_LABELSTRING: // label string definition
373 labelstring_ = lexrc.GetString();
376 case LT_ENDLABELSTRING: // endlabel string definition
378 endlabelstring_ = lexrc.GetString();
381 case LT_LABELSTRING_APPENDIX: // label string appendix definition
383 labelstring_appendix_ = lexrc.GetString();
386 case LT_FREE_SPACING: // Allow for free spacing.
388 free_spacing = lexrc.GetInteger();
391 case LT_SPACING: // setspace.sty
410 void LyXLayout::readAlign(LyXLex & lexrc)
412 keyword_item alignTags[] = {
413 { "block", AT_BLOCK },
414 { "center", AT_CENTER },
415 { "layout", AT_LAYOUT },
417 { "right", AT_RIGHT }
420 pushpophelper pph(lexrc, alignTags, AT_LAYOUT);
421 int le = lexrc.lex();
423 case LyXLex::LEX_UNDEF:
424 lexrc.printError("Unknown alignment `$$Token'");
428 switch(static_cast<AlignTags>(le)) {
430 align = LYX_ALIGN_BLOCK;
433 align = LYX_ALIGN_LEFT;
436 align = LYX_ALIGN_RIGHT;
439 align = LYX_ALIGN_CENTER;
442 align = LYX_ALIGN_LAYOUT;
448 void LyXLayout::readAlignPossible(LyXLex & lexrc)
450 keyword_item alignTags[] = {
451 { "block", AT_BLOCK },
452 { "center", AT_CENTER },
453 { "layout", AT_LAYOUT },
455 { "right", AT_RIGHT }
458 lexrc.pushTable(alignTags, AT_LAYOUT);
459 alignpossible = LYX_ALIGN_NONE;
460 int lineno = lexrc.GetLineNo();
462 int le = lexrc.lex();
464 case LyXLex::LEX_UNDEF:
465 lexrc.printError("Unknown alignment `$$Token'");
469 switch (static_cast<AlignTags>(le)) {
471 alignpossible |= LYX_ALIGN_BLOCK;
474 alignpossible |= LYX_ALIGN_LEFT;
477 alignpossible |= LYX_ALIGN_RIGHT;
480 alignpossible |= LYX_ALIGN_CENTER;
483 alignpossible |= LYX_ALIGN_LAYOUT;
486 } while (lineno == lexrc.GetLineNo());
495 LA_CENTERED_TOP_ENVIRONMENT,
500 LA_COUNTER_SUBSECTION,
501 LA_COUNTER_SUBSUBSECTION,
502 LA_COUNTER_PARAGRAPH,
503 LA_COUNTER_SUBPARAGRAPH,
512 void LyXLayout::readLabelType(LyXLex & lexrc)
514 keyword_item labelTypeTags[] = {
515 { "bibliography", LA_BIBLIO },
516 { "centered_top_environment", LA_CENTERED_TOP_ENVIRONMENT },
517 { "counter_chapter", LA_COUNTER_CHAPTER },
518 { "counter_enumi", LA_COUNTER_ENUMI },
519 { "counter_enumii", LA_COUNTER_ENUMII },
520 { "counter_enumiii", LA_COUNTER_ENUMIII },
521 { "counter_enumiv", LA_COUNTER_ENUMIV },
522 { "counter_paragraph", LA_COUNTER_PARAGRAPH },
523 { "counter_section", LA_COUNTER_SECTION },
524 { "counter_subparagraph", LA_COUNTER_SUBPARAGRAPH },
525 { "counter_subsection", LA_COUNTER_SUBSECTION },
526 { "counter_subsubsection", LA_COUNTER_SUBSUBSECTION },
527 { "manual", LA_MANUAL },
528 { "no_label", LA_NO_LABEL },
529 { "sensitive", LA_SENSITIVE },
530 { "static", LA_STATIC },
531 { "top_environment", LA_TOP_ENVIRONMENT }
534 pushpophelper pph(lexrc, labelTypeTags, LA_BIBLIO);
535 int le = lexrc.lex();
537 case LyXLex::LEX_UNDEF:
538 lexrc.printError("Unknown labeltype tag `$$Token'");
542 switch (static_cast<LabelTypeTags>(le)) {
544 labeltype = LABEL_NO_LABEL;
547 labeltype = LABEL_MANUAL;
549 case LA_TOP_ENVIRONMENT:
550 labeltype = LABEL_TOP_ENVIRONMENT;
552 case LA_CENTERED_TOP_ENVIRONMENT:
553 labeltype = LABEL_CENTERED_TOP_ENVIRONMENT;
556 labeltype = LABEL_STATIC;
559 labeltype = LABEL_SENSITIVE;
561 case LA_COUNTER_CHAPTER:
562 labeltype = LABEL_COUNTER_CHAPTER;
564 case LA_COUNTER_SECTION:
565 labeltype = LABEL_COUNTER_SECTION;
567 case LA_COUNTER_SUBSECTION:
568 labeltype = LABEL_COUNTER_SUBSECTION;
570 case LA_COUNTER_SUBSUBSECTION:
571 labeltype = LABEL_COUNTER_SUBSUBSECTION;
573 case LA_COUNTER_PARAGRAPH:
574 labeltype = LABEL_COUNTER_PARAGRAPH;
576 case LA_COUNTER_SUBPARAGRAPH:
577 labeltype = LABEL_COUNTER_SUBPARAGRAPH;
579 case LA_COUNTER_ENUMI:
580 labeltype = LABEL_COUNTER_ENUMI;
582 case LA_COUNTER_ENUMII:
583 labeltype = LABEL_COUNTER_ENUMII;
585 case LA_COUNTER_ENUMIII:
586 labeltype = LABEL_COUNTER_ENUMIII;
588 case LA_COUNTER_ENUMIV:
589 labeltype = LABEL_COUNTER_ENUMIV;
592 labeltype = LABEL_BIBLIO;
597 static 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 }
604 void LyXLayout::readEndLabelType(LyXLex & lexrc)
606 pushpophelper pph(lexrc, endlabelTypeTags,
607 END_LABEL_ENUM_LAST-END_LABEL_ENUM_FIRST+1);
608 int le = lexrc.lex();
610 case LyXLex::LEX_UNDEF:
611 lexrc.printError("Unknown labeltype tag `$$Token'");
613 case END_LABEL_STATIC:
615 case END_LABEL_FILLED_BOX:
616 case END_LABEL_NO_LABEL:
617 endlabeltype = static_cast<LYX_END_LABEL_TYPES>(le);
620 lyxerr << "Unhandled value " << le
621 << " in LyXLayout::readEndLabelType." << endl;
627 void LyXLayout::readMargin(LyXLex & lexrc)
629 keyword_item marginTags[] = {
630 { "dynamic", MARGIN_DYNAMIC },
631 { "first_dynamic", MARGIN_FIRST_DYNAMIC },
632 { "manual", MARGIN_MANUAL },
633 { "right_address_box", MARGIN_RIGHT_ADDRESS_BOX },
634 { "static", MARGIN_STATIC }
637 pushpophelper pph(lexrc, marginTags, MARGIN_RIGHT_ADDRESS_BOX);
639 int le = lexrc.lex();
641 case LyXLex::LEX_UNDEF:
642 lexrc.printError("Unknown margin type tag `$$Token'");
647 case MARGIN_FIRST_DYNAMIC:
648 case MARGIN_RIGHT_ADDRESS_BOX:
649 margintype = static_cast<LYX_MARGIN_TYPE>(le);
652 lyxerr << "Unhandled value " << le
653 << " in LyXLayout::readMargin." << endl;
659 void LyXLayout::readLatexType(LyXLex & lexrc)
661 keyword_item latexTypeTags[] = {
662 { "command", LATEX_COMMAND },
663 { "environment", LATEX_ENVIRONMENT },
664 { "item_environment", LATEX_ITEM_ENVIRONMENT },
665 { "list_environment", LATEX_LIST_ENVIRONMENT },
666 { "paragraph", LATEX_PARAGRAPH }
669 pushpophelper pph(lexrc, latexTypeTags, LATEX_LIST_ENVIRONMENT);
670 int le = lexrc.lex();
672 case LyXLex::LEX_UNDEF:
673 lexrc.printError("Unknown latextype tag `$$Token'");
675 case LATEX_PARAGRAPH:
677 case LATEX_ENVIRONMENT:
678 case LATEX_ITEM_ENVIRONMENT:
679 case LATEX_LIST_ENVIRONMENT:
680 latextype = static_cast<LYX_LATEX_TYPES>(le);
683 lyxerr << "Unhandled value " << le
684 << " in LyXLayout::readLatexType." << endl;
691 ST_SPACING_SINGLE = 1,
698 void LyXLayout::readSpacing(LyXLex & lexrc)
700 keyword_item spacingTags[] = {
701 {"double", ST_SPACING_DOUBLE },
702 {"onehalf", ST_SPACING_ONEHALF },
703 {"other", ST_OTHER },
704 {"single", ST_SPACING_SINGLE }
707 pushpophelper pph(lexrc, spacingTags, ST_OTHER);
708 int le = lexrc.lex();
710 case LyXLex::LEX_UNDEF:
711 lexrc.printError("Unknown spacing token `$$Token'");
715 switch(static_cast<SpacingTags>(le)) {
716 case ST_SPACING_SINGLE:
717 spacing.set(Spacing::Single);
719 case ST_SPACING_ONEHALF:
720 spacing.set(Spacing::Onehalf);
722 case ST_SPACING_DOUBLE:
723 spacing.set(Spacing::Double);
727 spacing.set(Spacing::Other, lexrc.GetFloat());
733 /* ******************************************************************* */
735 LyXTextClass::LyXTextClass(string const & fn, string const & cln,
737 : name_(fn), latexname_(cln), description_(desc)
744 pagestyle_ = "default";
745 maxcounter_ = LABEL_COUNTER_CHAPTER;
746 defaultfont_ = LyXFont(LyXFont::ALL_SANE);
747 opt_fontsize_ = "10|11|12";
748 opt_pagestyle_ = "empty|plain|headings|fancy";
754 bool LyXTextClass::do_readStyle(LyXLex & lexrc, LyXLayout & lay)
756 lyxerr[Debug::TCLASS] << "Reading style " << lay.name() << endl;
757 if (!lay.Read(lexrc, *this)) {
759 lay.resfont = lay.font;
760 lay.resfont.realize(defaultfont());
761 lay.reslabelfont = lay.labelfont;
762 lay.reslabelfont.realize(defaultfont());
763 return false; // no errors
765 lyxerr << "Error parsing style `" << lay.name() << "'" << endl;
792 // Reads a textclass structure from file.
793 bool LyXTextClass::Read(string const & filename, bool merge)
795 keyword_item textClassTags[] = {
796 { "classoptions", TC_CLASSOPTIONS },
797 { "columns", TC_COLUMNS },
798 { "defaultfont", TC_DEFAULTFONT },
799 { "input", TC_INPUT },
800 { "leftmargin", TC_LEFTMARGIN },
801 { "maxcounter", TC_MAXCOUNTER },
802 { "nostyle", TC_NOSTYLE },
803 { "outputtype", TC_OUTPUTTYPE },
804 { "pagestyle", TC_PAGESTYLE },
805 { "preamble", TC_PREAMBLE },
806 { "providesamsmath", TC_PROVIDESAMSMATH },
807 { "providesmakeidx", TC_PROVIDESMAKEIDX },
808 { "providesurl", TC_PROVIDESURL },
809 { "rightmargin", TC_RIGHTMARGIN },
810 { "secnumdepth", TC_SECNUMDEPTH },
811 { "sides", TC_SIDES },
812 { "style", TC_STYLE },
813 { "tocdepth", TC_TOCDEPTH }
817 lyxerr[Debug::TCLASS] << "Reading textclass "
818 << MakeDisplayPath(filename)
821 lyxerr[Debug::TCLASS] << "Reading input file "
822 << MakeDisplayPath(filename)
825 LyXLex lexrc(textClassTags, TC_RIGHTMARGIN);
828 lexrc.setFile(filename);
829 if (!lexrc.IsOK()) error = true;
832 while (lexrc.IsOK() && !error) {
833 int le = lexrc.lex();
835 case LyXLex::LEX_FEOF:
838 case LyXLex::LEX_UNDEF:
839 lexrc.printError("Unknown TextClass tag `$$Token'");
844 switch(static_cast<TextClassTags>(le)) {
845 case TC_OUTPUTTYPE: // output type definition
846 readOutputType(lexrc);
849 case TC_INPUT: // Include file
851 string tmp = LibFileSearch("layouts",
855 if (Read(tmp, true)) {
856 lexrc.printError("Error reading input"
865 string name = subst(lexrc.GetString(),
867 if (hasLayout(name)) {
868 LyXLayout & lay = GetLayout(name);
869 error = do_readStyle(lexrc, lay);
873 if (!(error = do_readStyle(lexrc, lay)))
874 layoutlist.push_back(lay);
878 lexrc.printError("No name given for style: `$$Token'.");
885 string style = subst(lexrc.GetString(),
887 if (!delete_layout(style))
888 lexrc.printError("Cannot delete style"
895 columns_ = lexrc.GetInteger();
900 switch(lexrc.GetInteger()) {
901 case 1: sides_ = OneSide; break;
902 case 2: sides_ = TwoSides; break;
904 lyxerr << "Impossible number of page"
905 " sides, setting to one."
915 pagestyle_ = strip(lexrc.GetString());
919 defaultfont_.lyxRead(lexrc);
920 if (!defaultfont_.resolved()) {
921 lexrc.printError("Warning: defaultfont should "
922 "be fully instantiated!");
923 defaultfont_.realize(LyXFont(LyXFont::ALL_SANE));
928 readMaxCounter(lexrc);
933 secnumdepth_ = lexrc.GetInteger();
938 tocdepth_ = lexrc.GetInteger();
941 // First step to support options
942 case TC_CLASSOPTIONS:
943 readClassOptions(lexrc);
947 preamble_ = lexrc.getLongString("EndPreamble");
950 case TC_PROVIDESAMSMATH:
951 if (lexrc.next() && lexrc.GetInteger())
952 provides_ |= amsmath;
955 case TC_PROVIDESMAKEIDX:
956 if (lexrc.next() && lexrc.GetInteger())
957 provides_ |= makeidx;
961 if (lexrc.next() && lexrc.GetInteger())
965 case TC_LEFTMARGIN: // left margin type
967 leftmargin_ = lexrc.GetString();
970 case TC_RIGHTMARGIN: // right margin type
972 rightmargin_ = lexrc.GetString();
977 if (!merge) { // we are at top level here.
978 lyxerr[Debug::TCLASS] << "Finished reading textclass "
979 << MakeDisplayPath(filename)
982 lyxerr[Debug::TCLASS] << "Finished reading input file "
983 << MakeDisplayPath(filename)
990 void LyXTextClass::readOutputType(LyXLex & lexrc)
992 keyword_item outputTypeTags[] = {
993 { "docbook", DOCBOOK },
995 { "linuxdoc", LINUXDOC },
996 { "literate", LITERATE }
999 pushpophelper pph(lexrc, outputTypeTags, LITERATE);
1001 int le = lexrc.lex();
1003 case LyXLex::LEX_UNDEF:
1004 lexrc.printError("Unknown output type `$$Token'");
1010 outputType_ = static_cast<OutputType>(le);
1013 lyxerr << "Unhandled value " << le
1014 << " in LyXTextClass::readOutputType." << endl;
1021 enum MaxCounterTags {
1022 MC_COUNTER_CHAPTER = 1,
1024 MC_COUNTER_SUBSECTION,
1025 MC_COUNTER_SUBSUBSECTION,
1026 MC_COUNTER_PARAGRAPH,
1027 MC_COUNTER_SUBPARAGRAPH,
1035 void LyXTextClass::readMaxCounter(LyXLex & lexrc)
1037 keyword_item maxCounterTags[] = {
1038 {"counter_chapter", MC_COUNTER_CHAPTER },
1039 {"counter_enumi", MC_COUNTER_ENUMI },
1040 {"counter_enumii", MC_COUNTER_ENUMII },
1041 {"counter_enumiii", MC_COUNTER_ENUMIII },
1042 {"counter_enumiv", MC_COUNTER_ENUMIV },
1043 {"counter_paragraph", MC_COUNTER_PARAGRAPH },
1044 {"counter_section", MC_COUNTER_SECTION },
1045 {"counter_subparagraph", MC_COUNTER_SUBPARAGRAPH },
1046 {"counter_subsection", MC_COUNTER_SUBSECTION },
1047 {"counter_subsubsection", MC_COUNTER_SUBSUBSECTION }
1050 pushpophelper pph(lexrc, maxCounterTags, MC_COUNTER_ENUMIV);
1051 int le = lexrc.lex();
1053 case LyXLex::LEX_UNDEF:
1054 lexrc.printError("Unknown MaxCounter tag `$$Token'");
1058 switch (static_cast<MaxCounterTags>(le)) {
1059 case MC_COUNTER_CHAPTER:
1060 maxcounter_ = LABEL_COUNTER_CHAPTER;
1062 case MC_COUNTER_SECTION:
1063 maxcounter_ = LABEL_COUNTER_SECTION;
1065 case MC_COUNTER_SUBSECTION:
1066 maxcounter_ = LABEL_COUNTER_SUBSECTION;
1068 case MC_COUNTER_SUBSUBSECTION:
1069 maxcounter_ = LABEL_COUNTER_SUBSUBSECTION;
1071 case MC_COUNTER_PARAGRAPH:
1072 maxcounter_ = LABEL_COUNTER_PARAGRAPH;
1074 case MC_COUNTER_SUBPARAGRAPH:
1075 maxcounter_ = LABEL_COUNTER_SUBPARAGRAPH;
1077 case MC_COUNTER_ENUMI:
1078 maxcounter_ = LABEL_COUNTER_ENUMI;
1080 case MC_COUNTER_ENUMII:
1081 maxcounter_ = LABEL_COUNTER_ENUMII;
1083 case MC_COUNTER_ENUMIII:
1084 maxcounter_ = LABEL_COUNTER_ENUMIII;
1086 case MC_COUNTER_ENUMIV:
1087 maxcounter_ = LABEL_COUNTER_ENUMIV;
1093 enum ClassOptionsTags {
1101 void LyXTextClass::readClassOptions(LyXLex & lexrc)
1103 keyword_item classOptionsTags[] = {
1105 {"fontsize", CO_FONTSIZE },
1106 {"other", CO_OTHER },
1107 {"pagestyle", CO_PAGESTYLE }
1110 lexrc.pushTable(classOptionsTags, CO_END);
1111 bool getout = false;
1112 while (!getout && lexrc.IsOK()) {
1113 int le = lexrc.lex();
1115 case LyXLex::LEX_UNDEF:
1116 lexrc.printError("Unknown ClassOption tag `$$Token'");
1120 switch (static_cast<ClassOptionsTags>(le)) {
1123 opt_fontsize_ = strip(lexrc.GetString());
1127 opt_pagestyle_ = strip(lexrc.GetString());
1131 options_ = lexrc.GetString();
1142 bool LyXTextClass::hasLayout(string const & name) const
1144 for (LayoutList::const_iterator cit = layoutlist.begin();
1145 cit != layoutlist.end(); ++cit) {
1146 if ((*cit).name() == name)
1153 LyXLayout const & LyXTextClass::GetLayout (string const & name) const
1155 for (LayoutList::const_iterator cit = layoutlist.begin();
1156 cit != layoutlist.end(); ++cit) {
1157 if ((*cit).name() == name)
1160 Assert(false); // we actually require the name to exist.
1161 return layoutlist.front();
1165 LyXLayout & LyXTextClass::GetLayout(string const & name)
1167 for (LayoutList::iterator it = layoutlist.begin();
1168 it != layoutlist.end(); ++it) {
1169 if ((*it).name() == name)
1172 Assert(false); // we actually require the name to exist.
1173 return layoutlist.front();
1177 bool LyXTextClass::delete_layout (string const & name)
1179 for(LayoutList::iterator it = layoutlist.begin();
1180 it != layoutlist.end(); ++it) {
1181 if ((*it).name() == name) {
1182 layoutlist.erase(it);
1190 // Load textclass info if not loaded yet
1191 void LyXTextClass::load()
1196 string real_file = LibFileSearch("layouts", name_, "layout");
1198 if (Read(real_file)) {
1199 lyxerr << "Error reading `"
1200 << MakeDisplayPath(real_file)
1201 << "'\n(Check `" << name_
1202 << "')\nCheck your installation and "
1203 "try Options/Reconfigure..." << endl;
1209 //////////////////////////////////////////
1211 // Gets textclass number from name
1212 pair<bool, LyXTextClassList::size_type>
1213 LyXTextClassList::NumberOfClass(string const & textclass) const
1215 for (ClassList::const_iterator cit = classlist.begin();
1216 cit != classlist.end(); ++cit) {
1217 if ((*cit).name() == textclass)
1218 return make_pair(true,
1219 size_type(cit - classlist.begin()));
1221 return make_pair(false, size_type(0));
1225 // Gets layout structure from style number and textclass number
1227 LyXTextClassList::Style(LyXTextClassList::size_type textclass,
1228 LyXTextClass::size_type layout) const
1230 classlist[textclass].load();
1231 if (layout < classlist[textclass].numLayouts())
1232 return classlist[textclass][layout];
1233 return classlist[textclass][0];
1237 // Gets layout number from name and textclass number
1238 pair<bool, LyXTextClass::size_type>
1239 LyXTextClassList::NumberOfLayout(LyXTextClassList::size_type textclass,
1240 string const & name) const
1242 classlist[textclass].load();
1243 for(unsigned int i = 0; i < classlist[textclass].numLayouts(); ++i) {
1244 if (classlist[textclass][i].name() == name)
1245 return make_pair(true, i);
1247 if (name == "dummy")
1248 return make_pair(true, LyXTextClassList::size_type(LYX_DUMMY_LAYOUT));
1249 return make_pair(false, LyXTextClass::size_type(0)); // not found
1253 // Gets a layout (style) name from layout number and textclass number
1255 LyXTextClassList::NameOfLayout(LyXTextClassList::size_type textclass,
1256 LyXTextClass::size_type layout) const
1258 static string dummy("dummy");
1259 classlist[textclass].load();
1260 if (layout < classlist[textclass].numLayouts())
1261 return classlist[textclass][layout].name();
1266 // Gets a textclass name from number
1268 LyXTextClassList::NameOfClass(LyXTextClassList::size_type number) const
1270 static string dummy("dummy");
1271 if (classlist.size() == 0) {
1274 Assert(number < classlist.size());
1275 return classlist[number].name();
1279 // Gets a textclass latexname from number
1281 LyXTextClassList::LatexnameOfClass(LyXTextClassList::size_type number) const
1283 static string dummy("dummy");
1284 classlist[number].load();
1285 if (classlist.size() == 0) {
1288 Assert(number < classlist.size());
1289 return classlist[number].latexname();
1293 // Gets a textclass description from number
1295 LyXTextClassList::DescOfClass(LyXTextClassList::size_type number) const
1297 static string dummy("dummy");
1298 if (classlist.size() == 0) {
1301 Assert(number < classlist.size());
1302 return classlist[number].description();
1306 // Gets a textclass structure from number
1307 LyXTextClass const &
1308 LyXTextClassList::TextClass(LyXTextClassList::size_type textclass) const
1310 classlist[textclass].load();
1311 if (textclass < classlist.size())
1312 return classlist[textclass];
1314 return classlist[0];
1318 void LyXTextClassList::Add(LyXTextClass const & t)
1320 classlist.push_back(t);
1324 // used when sorting the textclass list.
1325 class less_textclass_desc {
1327 int operator()(LyXTextClass const & tc1, LyXTextClass const & tc2) {
1328 return tc1.description() < tc2.description();
1333 // Reads LyX textclass definitions according to textclass config file
1334 bool LyXTextClassList::Read ()
1337 string real_file = LibFileSearch("", "textclass.lst");
1338 lyxerr[Debug::TCLASS] << "Reading textclasses from `"
1339 << real_file << "'" << endl;
1341 if (real_file.empty()) {
1342 lyxerr << "LyXTextClassList::Read: unable to find "
1343 "textclass file `" << MakeDisplayPath(real_file, 1000)
1344 << "'. Exiting." << endl;
1346 WriteAlert(_("LyX wasn't able to find its layout descriptions!"),
1347 _("Check that the file \"textclass.lst\""),
1348 _("is installed correctly. Sorry, has to exit :-("));
1350 // This causes LyX to end... Not a desirable behaviour. Lgb
1351 // What do you propose? That the user gets a file dialog
1352 // and is allowed to hunt for the file? (Asger)
1353 // more that we have a layout for minimal.cls statically
1354 // compiled in... (Lgb)
1357 if (!lex.setFile(real_file)) {
1358 lyxerr << "LyXTextClassList::Read: "
1359 "lyxlex was not able to set file: "
1360 << real_file << endl;
1364 lyxerr << "LyXTextClassList::Read: unable to open "
1365 "textclass file `" << MakeDisplayPath(real_file, 1000)
1366 << "'\nCheck your installation. LyX can't continue."
1370 bool finished = false;
1371 string fname, clname, desc;
1372 // Parse config-file
1373 lyxerr[Debug::TCLASS] << "Starting parsing of textclass.lst" << endl;
1374 while (lex.IsOK() && !finished) {
1375 lyxerr[Debug::TCLASS] << "\tline by line" << endl;
1376 switch (lex.lex()) {
1377 case LyXLex::LEX_FEOF:
1381 fname = lex.GetString();
1382 lyxerr[Debug::TCLASS] << "Fname: " << fname << endl;
1384 clname = lex.GetString();
1385 lyxerr[Debug::TCLASS]
1386 << "Clname: " << clname << endl;
1388 desc = lex.GetString();
1389 lyxerr[Debug::TCLASS]
1390 << "Desc: " << desc << endl;
1391 // This code is run when we have
1392 // fname, clname and desc
1393 LyXTextClass tmpl(fname,
1397 debugging(Debug::TCLASS)) {
1405 lyxerr[Debug::TCLASS] << "End of parsing of textclass.lst" << endl;
1407 if (classlist.size() == 0) {
1408 lyxerr << "LyXTextClassList::Read: no textclasses found!"
1410 WriteAlert(_("LyX wasn't able to find any layout description!"),
1411 _("Check the contents of the file \"textclass.lst\""),
1412 _("Sorry, has to exit :-("));
1415 // Ok everything loaded ok, now sort the list.
1416 sort(classlist.begin(), classlist.end(), less_textclass_desc());
1422 Returns false if this fails
1425 LyXTextClassList::Load (LyXTextClassList::size_type number) const
1428 if (number < classlist.size()) {
1429 classlist[number].load();
1430 if (classlist[number].numLayouts() == 0) {
1440 std::ostream & operator<<(std::ostream & os, LyXTextClass::PageSides p)
1443 case LyXTextClass::OneSide:
1446 case LyXTextClass::TwoSides: