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
22 #include "support/filetools.h"
23 #include "lyx_gui_misc.h"
26 #include "support/LAssert.h"
27 #include "support/lyxfunctional.h"
36 // Global variable: textclass table.
37 LyXTextClassList textclasslist;
40 // Reads the style files
43 lyxerr[Debug::TCLASS] << "LyXSetStyle: parsing configuration...\n";
45 if (!textclasslist.Read()) {
46 lyxerr[Debug::TCLASS] << "LyXSetStyle: an error occured "
47 "during parsing.\n Exiting." << endl;
51 lyxerr[Debug::TCLASS] << "LyXSetStyle: configuration parsed." << endl;
55 // The order of the LayoutTags enum is no more important. [asierra300396]
66 //LT_ENVIRONMENT_DEFAULT,
83 LT_LABELSTRING_APPENDIX,
106 /////////////////////
108 // Constructor for layout
109 LyXLayout::LyXLayout ()
111 margintype = MARGIN_STATIC;
112 latextype = LATEX_PARAGRAPH;
116 font = LyXFont(LyXFont::ALL_INHERIT);
117 labelfont = LyXFont(LyXFont::ALL_INHERIT);
118 resfont = LyXFont(LyXFont::ALL_SANE);
119 reslabelfont = LyXFont(LyXFont::ALL_SANE);
120 nextnoindent = false;
125 labelbottomsep = 0.0;
127 align = LYX_ALIGN_BLOCK;
128 alignpossible = LYX_ALIGN_BLOCK;
129 labeltype = LABEL_NO_LABEL;
130 endlabeltype = END_LABEL_NO_LABEL;
131 // Should or should not. That is the question.
132 // spacing.set(Spacing::OneHalf);
135 newline_allowed = true;
136 free_spacing = false;
141 // Reads a layout definition from file
142 bool LyXLayout::Read (LyXLex & lexrc, LyXTextClass const & tclass)
144 // This table is sorted alphabetically [asierra 30March96]
145 keyword_item layoutTags[] = {
146 { "align", LT_ALIGN },
147 { "alignpossible", LT_ALIGNPOSSIBLE },
148 { "bottomsep", LT_BOTTOMSEP },
149 { "copystyle", LT_COPYSTYLE },
151 { "endlabelstring", LT_ENDLABELSTRING },
152 { "endlabeltype", LT_ENDLABELTYPE },
153 { "fill_bottom", LT_FILL_BOTTOM },
154 { "fill_top", LT_FILL_TOP },
156 { "freespacing", LT_FREE_SPACING },
157 { "intitle", LT_INTITLE },
158 { "itemsep", LT_ITEMSEP },
159 { "keepempty", LT_KEEPEMPTY },
160 { "labelbottomsep", LT_LABEL_BOTTOMSEP },
161 { "labelfont", LT_LABELFONT },
162 { "labelindent", LT_LABELINDENT },
163 { "labelsep", LT_LABELSEP },
164 { "labelstring", LT_LABELSTRING },
165 { "labelstringappendix", LT_LABELSTRING_APPENDIX },
166 { "labeltype", LT_LABELTYPE },
167 { "latexname", LT_LATEXNAME },
168 { "latexparam", LT_LATEXPARAM },
169 { "latextype", LT_LATEXTYPE },
170 { "leftmargin", LT_LEFTMARGIN },
171 { "margin", LT_MARGIN },
172 { "needprotect", LT_NEED_PROTECT },
173 { "newline", LT_NEWLINE },
174 { "nextnoindent", LT_NEXTNOINDENT },
175 { "obsoletedby", LT_OBSOLETEDBY },
176 { "parindent", LT_PARINDENT },
177 { "parsep", LT_PARSEP },
178 { "parskip", LT_PARSKIP },
179 { "passthru", LT_PASS_THRU },
180 { "preamble", LT_PREAMBLE },
181 { "rightmargin", LT_RIGHTMARGIN },
182 { "spacing", LT_SPACING },
183 { "textfont", LT_TEXTFONT },
184 { "topsep", LT_TOPSEP }
188 bool finished = false;
189 lexrc.pushTable(layoutTags, LT_INTITLE);
190 // parse style section
191 while (!finished && lexrc.IsOK() && !error) {
192 int le = lexrc.lex();
193 // See comment in lyxrc.C.
195 case LyXLex::LEX_FEOF:
198 case LyXLex::LEX_UNDEF: // parse error
199 lexrc.printError("Unknown layout tag `$$Token'");
204 switch (static_cast<LayoutTags>(le)) {
205 case LT_END: // end of structure
209 case LT_COPYSTYLE: // initialize with a known style
211 if (tclass.hasLayout(lexrc.GetString())) {
212 string tmpname = name_;
213 this->operator= (tclass.GetLayout(lexrc.GetString()));
216 lexrc.printError("Cannot copy known "
222 case LT_OBSOLETEDBY: // replace with a known style
224 if (tclass.hasLayout(lexrc.GetString())) {
225 string tmpname = name_;
226 this->operator= (tclass.GetLayout(lexrc.GetString()));
228 if (obsoleted_by().empty())
229 obsoleted_by_ = lexrc.GetString();
231 lexrc.printError("Cannot replace with"
238 case LT_MARGIN: // Margin style definition.
242 case LT_LATEXTYPE: // Latex style definition.
243 readLatexType(lexrc);
247 intitle = lexrc.next() && lexrc.GetInteger();
250 case LT_NEED_PROTECT:
251 needprotect = lexrc.next() && lexrc.GetInteger();
255 keepempty = lexrc.next() && lexrc.GetInteger();
268 labelfont.lyxRead(lexrc);
271 case LT_NEXTNOINDENT: // Indent next paragraph?
272 if (lexrc.next() && lexrc.GetInteger())
275 nextnoindent = false;
280 latexname_ = lexrc.GetString();
285 latexparam_ = lexrc.GetString();
289 preamble_ = lexrc.getLongString("EndPreamble");
293 readLabelType(lexrc);
296 case LT_ENDLABELTYPE:
297 readEndLabelType(lexrc);
300 case LT_LEFTMARGIN: // left margin type
302 leftmargin = lexrc.GetString();
305 case LT_RIGHTMARGIN: // right margin type
307 rightmargin = lexrc.GetString();
310 case LT_LABELINDENT: // label indenting flag
312 labelindent = lexrc.GetString();
315 case LT_PARINDENT: // paragraph indent. flag
317 parindent = lexrc.GetString();
320 case LT_PARSKIP: // paragraph skip size
322 parskip = lexrc.GetFloat();
325 case LT_ITEMSEP: // item separation size
327 itemsep = lexrc.GetFloat();
330 case LT_TOPSEP: // top separation size
332 topsep = lexrc.GetFloat();
335 case LT_BOTTOMSEP: // bottom separation size
337 bottomsep = lexrc.GetFloat();
340 case LT_LABEL_BOTTOMSEP: // label bottom separation size
342 labelbottomsep = lexrc.GetFloat();
345 case LT_LABELSEP: // label separator
347 labelsep = subst(lexrc.GetString(), 'x', ' ');
351 case LT_PARSEP: // par. separation size
353 parsep = lexrc.GetFloat();
356 case LT_FILL_TOP: // fill top flag
358 fill_top = lexrc.GetInteger();
361 case LT_FILL_BOTTOM: // fill bottom flag
363 fill_bottom = lexrc.GetInteger();
366 case LT_NEWLINE: // newlines allowed?
368 newline_allowed = lexrc.GetInteger();
371 case LT_ALIGN: // paragraph align
374 case LT_ALIGNPOSSIBLE: // paragraph allowed align
375 readAlignPossible(lexrc);
378 case LT_LABELSTRING: // label string definition
380 labelstring_ = lexrc.GetString();
383 case LT_ENDLABELSTRING: // endlabel string definition
385 endlabelstring_ = lexrc.GetString();
388 case LT_LABELSTRING_APPENDIX: // label string appendix definition
390 labelstring_appendix_ = lexrc.GetString();
393 case LT_FREE_SPACING: // Allow for free spacing.
395 free_spacing = lexrc.GetInteger();
398 case LT_PASS_THRU: // Allow for pass thru.
400 pass_thru = lexrc.GetInteger();
403 case LT_SPACING: // setspace.sty
422 void LyXLayout::readAlign(LyXLex & lexrc)
424 keyword_item alignTags[] = {
425 { "block", AT_BLOCK },
426 { "center", AT_CENTER },
427 { "layout", AT_LAYOUT },
429 { "right", AT_RIGHT }
432 pushpophelper pph(lexrc, alignTags, AT_LAYOUT);
433 int le = lexrc.lex();
435 case LyXLex::LEX_UNDEF:
436 lexrc.printError("Unknown alignment `$$Token'");
440 switch (static_cast<AlignTags>(le)) {
442 align = LYX_ALIGN_BLOCK;
445 align = LYX_ALIGN_LEFT;
448 align = LYX_ALIGN_RIGHT;
451 align = LYX_ALIGN_CENTER;
454 align = LYX_ALIGN_LAYOUT;
460 void LyXLayout::readAlignPossible(LyXLex & lexrc)
462 keyword_item alignTags[] = {
463 { "block", AT_BLOCK },
464 { "center", AT_CENTER },
465 { "layout", AT_LAYOUT },
467 { "right", AT_RIGHT }
470 lexrc.pushTable(alignTags, AT_LAYOUT);
471 alignpossible = LYX_ALIGN_NONE;
472 int lineno = lexrc.GetLineNo();
474 int le = lexrc.lex();
476 case LyXLex::LEX_UNDEF:
477 lexrc.printError("Unknown alignment `$$Token'");
481 switch (static_cast<AlignTags>(le)) {
483 alignpossible |= LYX_ALIGN_BLOCK;
486 alignpossible |= LYX_ALIGN_LEFT;
489 alignpossible |= LYX_ALIGN_RIGHT;
492 alignpossible |= LYX_ALIGN_CENTER;
495 alignpossible |= LYX_ALIGN_LAYOUT;
498 } while (lineno == lexrc.GetLineNo());
507 LA_CENTERED_TOP_ENVIRONMENT,
512 LA_COUNTER_SUBSECTION,
513 LA_COUNTER_SUBSUBSECTION,
514 LA_COUNTER_PARAGRAPH,
515 LA_COUNTER_SUBPARAGRAPH,
524 void LyXLayout::readLabelType(LyXLex & lexrc)
526 keyword_item labelTypeTags[] = {
527 { "bibliography", LA_BIBLIO },
528 { "centered_top_environment", LA_CENTERED_TOP_ENVIRONMENT },
529 { "counter_chapter", LA_COUNTER_CHAPTER },
530 { "counter_enumi", LA_COUNTER_ENUMI },
531 { "counter_enumii", LA_COUNTER_ENUMII },
532 { "counter_enumiii", LA_COUNTER_ENUMIII },
533 { "counter_enumiv", LA_COUNTER_ENUMIV },
534 { "counter_paragraph", LA_COUNTER_PARAGRAPH },
535 { "counter_section", LA_COUNTER_SECTION },
536 { "counter_subparagraph", LA_COUNTER_SUBPARAGRAPH },
537 { "counter_subsection", LA_COUNTER_SUBSECTION },
538 { "counter_subsubsection", LA_COUNTER_SUBSUBSECTION },
539 { "manual", LA_MANUAL },
540 { "no_label", LA_NO_LABEL },
541 { "sensitive", LA_SENSITIVE },
542 { "static", LA_STATIC },
543 { "top_environment", LA_TOP_ENVIRONMENT }
546 pushpophelper pph(lexrc, labelTypeTags, LA_BIBLIO);
547 int le = lexrc.lex();
549 case LyXLex::LEX_UNDEF:
550 lexrc.printError("Unknown labeltype tag `$$Token'");
554 switch (static_cast<LabelTypeTags>(le)) {
556 labeltype = LABEL_NO_LABEL;
559 labeltype = LABEL_MANUAL;
561 case LA_TOP_ENVIRONMENT:
562 labeltype = LABEL_TOP_ENVIRONMENT;
564 case LA_CENTERED_TOP_ENVIRONMENT:
565 labeltype = LABEL_CENTERED_TOP_ENVIRONMENT;
568 labeltype = LABEL_STATIC;
571 labeltype = LABEL_SENSITIVE;
573 case LA_COUNTER_CHAPTER:
574 labeltype = LABEL_COUNTER_CHAPTER;
576 case LA_COUNTER_SECTION:
577 labeltype = LABEL_COUNTER_SECTION;
579 case LA_COUNTER_SUBSECTION:
580 labeltype = LABEL_COUNTER_SUBSECTION;
582 case LA_COUNTER_SUBSUBSECTION:
583 labeltype = LABEL_COUNTER_SUBSUBSECTION;
585 case LA_COUNTER_PARAGRAPH:
586 labeltype = LABEL_COUNTER_PARAGRAPH;
588 case LA_COUNTER_SUBPARAGRAPH:
589 labeltype = LABEL_COUNTER_SUBPARAGRAPH;
591 case LA_COUNTER_ENUMI:
592 labeltype = LABEL_COUNTER_ENUMI;
594 case LA_COUNTER_ENUMII:
595 labeltype = LABEL_COUNTER_ENUMII;
597 case LA_COUNTER_ENUMIII:
598 labeltype = LABEL_COUNTER_ENUMIII;
600 case LA_COUNTER_ENUMIV:
601 labeltype = LABEL_COUNTER_ENUMIV;
604 labeltype = LABEL_BIBLIO;
612 keyword_item endlabelTypeTags[] = {
613 { "box", END_LABEL_BOX },
614 { "filled_box", END_LABEL_FILLED_BOX },
615 { "no_label", END_LABEL_NO_LABEL },
616 { "static", END_LABEL_STATIC }
622 void LyXLayout::readEndLabelType(LyXLex & lexrc)
624 pushpophelper pph(lexrc, endlabelTypeTags,
625 END_LABEL_ENUM_LAST-END_LABEL_ENUM_FIRST+1);
626 int le = lexrc.lex();
628 case LyXLex::LEX_UNDEF:
629 lexrc.printError("Unknown labeltype tag `$$Token'");
631 case END_LABEL_STATIC:
633 case END_LABEL_FILLED_BOX:
634 case END_LABEL_NO_LABEL:
635 endlabeltype = static_cast<LYX_END_LABEL_TYPES>(le);
638 lyxerr << "Unhandled value " << le
639 << " in LyXLayout::readEndLabelType." << endl;
645 void LyXLayout::readMargin(LyXLex & lexrc)
647 keyword_item marginTags[] = {
648 { "dynamic", MARGIN_DYNAMIC },
649 { "first_dynamic", MARGIN_FIRST_DYNAMIC },
650 { "manual", MARGIN_MANUAL },
651 { "right_address_box", MARGIN_RIGHT_ADDRESS_BOX },
652 { "static", MARGIN_STATIC }
655 pushpophelper pph(lexrc, marginTags, MARGIN_RIGHT_ADDRESS_BOX);
657 int le = lexrc.lex();
659 case LyXLex::LEX_UNDEF:
660 lexrc.printError("Unknown margin type tag `$$Token'");
665 case MARGIN_FIRST_DYNAMIC:
666 case MARGIN_RIGHT_ADDRESS_BOX:
667 margintype = static_cast<LYX_MARGIN_TYPE>(le);
670 lyxerr << "Unhandled value " << le
671 << " in LyXLayout::readMargin." << endl;
677 void LyXLayout::readLatexType(LyXLex & lexrc)
679 keyword_item latexTypeTags[] = {
680 { "command", LATEX_COMMAND },
681 { "environment", LATEX_ENVIRONMENT },
682 { "item_environment", LATEX_ITEM_ENVIRONMENT },
683 { "list_environment", LATEX_LIST_ENVIRONMENT },
684 { "paragraph", LATEX_PARAGRAPH }
687 pushpophelper pph(lexrc, latexTypeTags, LATEX_LIST_ENVIRONMENT);
688 int le = lexrc.lex();
690 case LyXLex::LEX_UNDEF:
691 lexrc.printError("Unknown latextype tag `$$Token'");
693 case LATEX_PARAGRAPH:
695 case LATEX_ENVIRONMENT:
696 case LATEX_ITEM_ENVIRONMENT:
697 case LATEX_LIST_ENVIRONMENT:
698 latextype = static_cast<LYX_LATEX_TYPES>(le);
701 lyxerr << "Unhandled value " << le
702 << " in LyXLayout::readLatexType." << endl;
709 ST_SPACING_SINGLE = 1,
716 void LyXLayout::readSpacing(LyXLex & lexrc)
718 keyword_item spacingTags[] = {
719 {"double", ST_SPACING_DOUBLE },
720 {"onehalf", ST_SPACING_ONEHALF },
721 {"other", ST_OTHER },
722 {"single", ST_SPACING_SINGLE }
725 pushpophelper pph(lexrc, spacingTags, ST_OTHER);
726 int le = lexrc.lex();
728 case LyXLex::LEX_UNDEF:
729 lexrc.printError("Unknown spacing token `$$Token'");
733 switch (static_cast<SpacingTags>(le)) {
734 case ST_SPACING_SINGLE:
735 spacing.set(Spacing::Single);
737 case ST_SPACING_ONEHALF:
738 spacing.set(Spacing::Onehalf);
740 case ST_SPACING_DOUBLE:
741 spacing.set(Spacing::Double);
745 spacing.set(Spacing::Other, lexrc.GetFloat());
751 /* ******************************************************************* */
753 LyXTextClass::LyXTextClass(string const & fn, string const & cln,
755 : name_(fn), latexname_(cln), description_(desc)
762 pagestyle_ = "default";
763 maxcounter_ = LABEL_COUNTER_CHAPTER;
764 defaultfont_ = LyXFont(LyXFont::ALL_SANE);
765 opt_fontsize_ = "10|11|12";
766 opt_pagestyle_ = "empty|plain|headings|fancy";
772 bool LyXTextClass::do_readStyle(LyXLex & lexrc, LyXLayout & lay)
774 lyxerr[Debug::TCLASS] << "Reading style " << lay.name() << endl;
775 if (!lay.Read(lexrc, *this)) {
777 lay.resfont = lay.font;
778 lay.resfont.realize(defaultfont(), default_language);
779 lay.reslabelfont = lay.labelfont;
780 lay.reslabelfont.realize(defaultfont(), default_language);
781 return false; // no errors
783 lyxerr << "Error parsing style `" << lay.name() << "'" << endl;
810 // Reads a textclass structure from file.
811 bool LyXTextClass::Read(string const & filename, bool merge)
813 keyword_item textClassTags[] = {
814 { "classoptions", TC_CLASSOPTIONS },
815 { "columns", TC_COLUMNS },
816 { "defaultfont", TC_DEFAULTFONT },
817 { "input", TC_INPUT },
818 { "leftmargin", TC_LEFTMARGIN },
819 { "maxcounter", TC_MAXCOUNTER },
820 { "nostyle", TC_NOSTYLE },
821 { "outputtype", TC_OUTPUTTYPE },
822 { "pagestyle", TC_PAGESTYLE },
823 { "preamble", TC_PREAMBLE },
824 { "providesamsmath", TC_PROVIDESAMSMATH },
825 { "providesmakeidx", TC_PROVIDESMAKEIDX },
826 { "providesurl", TC_PROVIDESURL },
827 { "rightmargin", TC_RIGHTMARGIN },
828 { "secnumdepth", TC_SECNUMDEPTH },
829 { "sides", TC_SIDES },
830 { "style", TC_STYLE },
831 { "tocdepth", TC_TOCDEPTH }
835 lyxerr[Debug::TCLASS] << "Reading textclass "
836 << MakeDisplayPath(filename)
839 lyxerr[Debug::TCLASS] << "Reading input file "
840 << MakeDisplayPath(filename)
843 LyXLex lexrc(textClassTags, TC_RIGHTMARGIN);
846 lexrc.setFile(filename);
847 if (!lexrc.IsOK()) error = true;
850 while (lexrc.IsOK() && !error) {
851 int le = lexrc.lex();
853 case LyXLex::LEX_FEOF:
856 case LyXLex::LEX_UNDEF:
857 lexrc.printError("Unknown TextClass tag `$$Token'");
862 switch (static_cast<TextClassTags>(le)) {
863 case TC_OUTPUTTYPE: // output type definition
864 readOutputType(lexrc);
867 case TC_INPUT: // Include file
869 string tmp = LibFileSearch("layouts",
873 if (Read(tmp, true)) {
874 lexrc.printError("Error reading input"
883 string name = subst(lexrc.GetString(),
885 if (hasLayout(name)) {
886 LyXLayout & lay = GetLayout(name);
887 error = do_readStyle(lexrc, lay);
891 if (!(error = do_readStyle(lexrc, lay)))
892 layoutlist.push_back(lay);
896 lexrc.printError("No name given for style: `$$Token'.");
903 string style = subst(lexrc.GetString(),
905 if (!delete_layout(style))
906 lexrc.printError("Cannot delete style"
913 columns_ = lexrc.GetInteger();
918 switch (lexrc.GetInteger()) {
919 case 1: sides_ = OneSide; break;
920 case 2: sides_ = TwoSides; break;
922 lyxerr << "Impossible number of page"
923 " sides, setting to one."
933 pagestyle_ = strip(lexrc.GetString());
937 defaultfont_.lyxRead(lexrc);
938 if (!defaultfont_.resolved()) {
939 lexrc.printError("Warning: defaultfont should "
940 "be fully instantiated!");
941 defaultfont_.realize(LyXFont(LyXFont::ALL_SANE),
947 readMaxCounter(lexrc);
952 secnumdepth_ = lexrc.GetInteger();
957 tocdepth_ = lexrc.GetInteger();
960 // First step to support options
961 case TC_CLASSOPTIONS:
962 readClassOptions(lexrc);
966 preamble_ = lexrc.getLongString("EndPreamble");
969 case TC_PROVIDESAMSMATH:
970 if (lexrc.next() && lexrc.GetInteger())
971 provides_ |= amsmath;
974 case TC_PROVIDESMAKEIDX:
975 if (lexrc.next() && lexrc.GetInteger())
976 provides_ |= makeidx;
980 if (lexrc.next() && lexrc.GetInteger())
984 case TC_LEFTMARGIN: // left margin type
986 leftmargin_ = lexrc.GetString();
989 case TC_RIGHTMARGIN: // right margin type
991 rightmargin_ = lexrc.GetString();
996 if (!merge) { // we are at top level here.
997 lyxerr[Debug::TCLASS] << "Finished reading textclass "
998 << MakeDisplayPath(filename)
1001 lyxerr[Debug::TCLASS] << "Finished reading input file "
1002 << MakeDisplayPath(filename)
1009 void LyXTextClass::readOutputType(LyXLex & lexrc)
1011 keyword_item outputTypeTags[] = {
1012 { "docbook", DOCBOOK },
1014 { "linuxdoc", LINUXDOC },
1015 { "literate", LITERATE }
1018 pushpophelper pph(lexrc, outputTypeTags, LITERATE);
1020 int le = lexrc.lex();
1022 case LyXLex::LEX_UNDEF:
1023 lexrc.printError("Unknown output type `$$Token'");
1029 outputType_ = static_cast<OutputType>(le);
1032 lyxerr << "Unhandled value " << le
1033 << " in LyXTextClass::readOutputType." << endl;
1040 enum MaxCounterTags {
1041 MC_COUNTER_CHAPTER = 1,
1043 MC_COUNTER_SUBSECTION,
1044 MC_COUNTER_SUBSUBSECTION,
1045 MC_COUNTER_PARAGRAPH,
1046 MC_COUNTER_SUBPARAGRAPH,
1054 void LyXTextClass::readMaxCounter(LyXLex & lexrc)
1056 keyword_item maxCounterTags[] = {
1057 {"counter_chapter", MC_COUNTER_CHAPTER },
1058 {"counter_enumi", MC_COUNTER_ENUMI },
1059 {"counter_enumii", MC_COUNTER_ENUMII },
1060 {"counter_enumiii", MC_COUNTER_ENUMIII },
1061 {"counter_enumiv", MC_COUNTER_ENUMIV },
1062 {"counter_paragraph", MC_COUNTER_PARAGRAPH },
1063 {"counter_section", MC_COUNTER_SECTION },
1064 {"counter_subparagraph", MC_COUNTER_SUBPARAGRAPH },
1065 {"counter_subsection", MC_COUNTER_SUBSECTION },
1066 {"counter_subsubsection", MC_COUNTER_SUBSUBSECTION }
1069 pushpophelper pph(lexrc, maxCounterTags, MC_COUNTER_ENUMIV);
1070 int le = lexrc.lex();
1072 case LyXLex::LEX_UNDEF:
1073 lexrc.printError("Unknown MaxCounter tag `$$Token'");
1077 switch (static_cast<MaxCounterTags>(le)) {
1078 case MC_COUNTER_CHAPTER:
1079 maxcounter_ = LABEL_COUNTER_CHAPTER;
1081 case MC_COUNTER_SECTION:
1082 maxcounter_ = LABEL_COUNTER_SECTION;
1084 case MC_COUNTER_SUBSECTION:
1085 maxcounter_ = LABEL_COUNTER_SUBSECTION;
1087 case MC_COUNTER_SUBSUBSECTION:
1088 maxcounter_ = LABEL_COUNTER_SUBSUBSECTION;
1090 case MC_COUNTER_PARAGRAPH:
1091 maxcounter_ = LABEL_COUNTER_PARAGRAPH;
1093 case MC_COUNTER_SUBPARAGRAPH:
1094 maxcounter_ = LABEL_COUNTER_SUBPARAGRAPH;
1096 case MC_COUNTER_ENUMI:
1097 maxcounter_ = LABEL_COUNTER_ENUMI;
1099 case MC_COUNTER_ENUMII:
1100 maxcounter_ = LABEL_COUNTER_ENUMII;
1102 case MC_COUNTER_ENUMIII:
1103 maxcounter_ = LABEL_COUNTER_ENUMIII;
1105 case MC_COUNTER_ENUMIV:
1106 maxcounter_ = LABEL_COUNTER_ENUMIV;
1112 enum ClassOptionsTags {
1120 void LyXTextClass::readClassOptions(LyXLex & lexrc)
1122 keyword_item classOptionsTags[] = {
1124 {"fontsize", CO_FONTSIZE },
1125 {"other", CO_OTHER },
1126 {"pagestyle", CO_PAGESTYLE }
1129 lexrc.pushTable(classOptionsTags, CO_END);
1130 bool getout = false;
1131 while (!getout && lexrc.IsOK()) {
1132 int le = lexrc.lex();
1134 case LyXLex::LEX_UNDEF:
1135 lexrc.printError("Unknown ClassOption tag `$$Token'");
1139 switch (static_cast<ClassOptionsTags>(le)) {
1142 opt_fontsize_ = strip(lexrc.GetString());
1146 opt_pagestyle_ = strip(lexrc.GetString());
1150 options_ = lexrc.GetString();
1161 bool LyXTextClass::hasLayout(string const & name) const
1163 return find_if(layoutlist.begin(), layoutlist.end(),
1164 lyx::compare_memfun(&LyXLayout::name, name))
1165 != layoutlist.end();
1169 LyXLayout const & LyXTextClass::GetLayout (string const & name) const
1171 LayoutList::const_iterator cit =
1172 find_if(layoutlist.begin(),
1174 lyx::compare_memfun(&LyXLayout::name, name));
1175 lyx::Assert(cit != layoutlist.end()); // we require the name to exist
1180 LyXLayout & LyXTextClass::GetLayout(string const & name)
1182 LayoutList::iterator it =
1183 find_if(layoutlist.begin(),
1185 lyx::compare_memfun(&LyXLayout::name, name));
1186 lyx::Assert(it != layoutlist.end()); // we require the name to exist
1191 bool LyXTextClass::delete_layout(string const & name)
1193 LayoutList::iterator it =
1194 remove_if(layoutlist.begin(), layoutlist.end(),
1195 lyx::compare_memfun(&LyXLayout::name, name));
1196 LayoutList::iterator end = layoutlist.end();
1197 bool const ret = (it != end);
1198 layoutlist.erase(it, end);
1203 // Load textclass info if not loaded yet
1204 void LyXTextClass::load()
1209 string const real_file = LibFileSearch("layouts", name_, "layout");
1211 if (Read(real_file)) {
1212 lyxerr << "Error reading `"
1213 << MakeDisplayPath(real_file)
1214 << "'\n(Check `" << name_
1215 << "')\nCheck your installation and "
1216 "try Options/Reconfigure..." << endl;
1222 //////////////////////////////////////////
1224 // Gets textclass number from name
1225 pair<bool, LyXTextClassList::size_type> const
1226 LyXTextClassList::NumberOfClass(string const & textclass) const
1228 ClassList::const_iterator cit =
1229 find_if(classlist.begin(), classlist.end(),
1230 lyx::compare_memfun(&LyXTextClass::name, textclass));
1231 return cit != classlist.end() ?
1232 make_pair(true, size_type(cit - classlist.begin())) :
1233 make_pair(false, size_type(0));
1237 // Gets layout structure from style number and textclass number
1239 LyXTextClassList::Style(LyXTextClassList::size_type textclass,
1240 LyXTextClass::size_type layout) const
1242 classlist[textclass].load();
1243 if (layout < classlist[textclass].numLayouts())
1244 return classlist[textclass][layout];
1245 return classlist[textclass][0];
1249 // Gets layout number from name and textclass number
1250 pair<bool, LyXTextClass::size_type> const
1251 LyXTextClassList::NumberOfLayout(LyXTextClassList::size_type textclass,
1252 string const & name) const
1254 classlist[textclass].load();
1255 for (unsigned int i = 0; i < classlist[textclass].numLayouts(); ++i) {
1256 if (classlist[textclass][i].name() == name)
1257 return make_pair(true, i);
1259 if (name == "dummy")
1260 return make_pair(true, LyXTextClassList::size_type(LYX_DUMMY_LAYOUT));
1261 return make_pair(false, LyXTextClass::size_type(0)); // not found
1265 // Gets a layout (style) name from layout number and textclass number
1267 LyXTextClassList::NameOfLayout(LyXTextClassList::size_type textclass,
1268 LyXTextClass::size_type layout) const
1270 static string const dummy("dummy");
1271 classlist[textclass].load();
1272 if (layout < classlist[textclass].numLayouts())
1273 return classlist[textclass][layout].name();
1278 // Gets a textclass name from number
1280 LyXTextClassList::NameOfClass(LyXTextClassList::size_type number) const
1282 static string const dummy("dummy");
1283 if (classlist.size() == 0) {
1286 lyx::Assert(number < classlist.size());
1287 return classlist[number].name();
1291 // Gets a textclass latexname from number
1293 LyXTextClassList::LatexnameOfClass(LyXTextClassList::size_type number) const
1295 static string const dummy("dummy");
1296 classlist[number].load();
1297 if (classlist.size() == 0) {
1300 lyx::Assert(number < classlist.size());
1301 return classlist[number].latexname();
1305 // Gets a textclass description from number
1307 LyXTextClassList::DescOfClass(LyXTextClassList::size_type number) const
1309 static string const dummy("dummy");
1310 if (classlist.size() == 0) {
1313 lyx::Assert(number < classlist.size());
1314 return classlist[number].description();
1318 // Gets a textclass structure from number
1319 LyXTextClass const &
1320 LyXTextClassList::TextClass(LyXTextClassList::size_type textclass) const
1322 classlist[textclass].load();
1323 if (textclass < classlist.size())
1324 return classlist[textclass];
1326 return classlist[0];
1330 void LyXTextClassList::Add(LyXTextClass const & t)
1332 classlist.push_back(t);
1336 // used when sorting the textclass list.
1337 class less_textclass_desc {
1339 int operator()(LyXTextClass const & tc1, LyXTextClass const & tc2) {
1340 return tc1.description() < tc2.description();
1345 // Reads LyX textclass definitions according to textclass config file
1346 bool LyXTextClassList::Read ()
1349 string real_file = LibFileSearch("", "textclass.lst");
1350 lyxerr[Debug::TCLASS] << "Reading textclasses from `"
1351 << real_file << "'" << endl;
1353 if (real_file.empty()) {
1354 lyxerr << "LyXTextClassList::Read: unable to find "
1355 "textclass file `" << MakeDisplayPath(real_file, 1000)
1356 << "'. Exiting." << endl;
1358 WriteAlert(_("LyX wasn't able to find its layout descriptions!"),
1359 _("Check that the file \"textclass.lst\""),
1360 _("is installed correctly. Sorry, has to exit :-("));
1362 // This causes LyX to end... Not a desirable behaviour. Lgb
1363 // What do you propose? That the user gets a file dialog
1364 // and is allowed to hunt for the file? (Asger)
1365 // more that we have a layout for minimal.cls statically
1366 // compiled in... (Lgb)
1369 if (!lex.setFile(real_file)) {
1370 lyxerr << "LyXTextClassList::Read: "
1371 "lyxlex was not able to set file: "
1372 << real_file << endl;
1376 lyxerr << "LyXTextClassList::Read: unable to open "
1377 "textclass file `" << MakeDisplayPath(real_file, 1000)
1378 << "'\nCheck your installation. LyX can't continue."
1382 bool finished = false;
1383 string fname, clname, desc;
1384 // Parse config-file
1385 lyxerr[Debug::TCLASS] << "Starting parsing of textclass.lst" << endl;
1386 while (lex.IsOK() && !finished) {
1387 lyxerr[Debug::TCLASS] << "\tline by line" << endl;
1388 switch (lex.lex()) {
1389 case LyXLex::LEX_FEOF:
1393 fname = lex.GetString();
1394 lyxerr[Debug::TCLASS] << "Fname: " << fname << endl;
1396 clname = lex.GetString();
1397 lyxerr[Debug::TCLASS]
1398 << "Clname: " << clname << endl;
1400 desc = lex.GetString();
1401 lyxerr[Debug::TCLASS]
1402 << "Desc: " << desc << endl;
1403 // This code is run when we have
1404 // fname, clname and desc
1405 LyXTextClass tmpl(fname,
1409 debugging(Debug::TCLASS)) {
1417 lyxerr[Debug::TCLASS] << "End of parsing of textclass.lst" << endl;
1419 if (classlist.size() == 0) {
1420 lyxerr << "LyXTextClassList::Read: no textclasses found!"
1422 WriteAlert(_("LyX wasn't able to find any layout description!"),
1423 _("Check the contents of the file \"textclass.lst\""),
1424 _("Sorry, has to exit :-("));
1427 // Ok everything loaded ok, now sort the list.
1428 sort(classlist.begin(), classlist.end(), less_textclass_desc());
1434 Returns false if this fails
1437 LyXTextClassList::Load (LyXTextClassList::size_type number) const
1440 if (number < classlist.size()) {
1441 classlist[number].load();
1442 if (classlist[number].numLayouts() == 0) {
1452 std::ostream & operator<<(std::ostream & os, LyXTextClass::PageSides p)
1455 case LyXTextClass::OneSide:
1458 case LyXTextClass::TwoSides: