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());
779 lay.reslabelfont = lay.labelfont;
780 lay.reslabelfont.realize(defaultfont());
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));
946 readMaxCounter(lexrc);
951 secnumdepth_ = lexrc.GetInteger();
956 tocdepth_ = lexrc.GetInteger();
959 // First step to support options
960 case TC_CLASSOPTIONS:
961 readClassOptions(lexrc);
965 preamble_ = lexrc.getLongString("EndPreamble");
968 case TC_PROVIDESAMSMATH:
969 if (lexrc.next() && lexrc.GetInteger())
970 provides_ |= amsmath;
973 case TC_PROVIDESMAKEIDX:
974 if (lexrc.next() && lexrc.GetInteger())
975 provides_ |= makeidx;
979 if (lexrc.next() && lexrc.GetInteger())
983 case TC_LEFTMARGIN: // left margin type
985 leftmargin_ = lexrc.GetString();
988 case TC_RIGHTMARGIN: // right margin type
990 rightmargin_ = lexrc.GetString();
995 if (!merge) { // we are at top level here.
996 lyxerr[Debug::TCLASS] << "Finished reading textclass "
997 << MakeDisplayPath(filename)
1000 lyxerr[Debug::TCLASS] << "Finished reading input file "
1001 << MakeDisplayPath(filename)
1008 void LyXTextClass::readOutputType(LyXLex & lexrc)
1010 keyword_item outputTypeTags[] = {
1011 { "docbook", DOCBOOK },
1013 { "linuxdoc", LINUXDOC },
1014 { "literate", LITERATE }
1017 pushpophelper pph(lexrc, outputTypeTags, LITERATE);
1019 int le = lexrc.lex();
1021 case LyXLex::LEX_UNDEF:
1022 lexrc.printError("Unknown output type `$$Token'");
1028 outputType_ = static_cast<OutputType>(le);
1031 lyxerr << "Unhandled value " << le
1032 << " in LyXTextClass::readOutputType." << endl;
1039 enum MaxCounterTags {
1040 MC_COUNTER_CHAPTER = 1,
1042 MC_COUNTER_SUBSECTION,
1043 MC_COUNTER_SUBSUBSECTION,
1044 MC_COUNTER_PARAGRAPH,
1045 MC_COUNTER_SUBPARAGRAPH,
1053 void LyXTextClass::readMaxCounter(LyXLex & lexrc)
1055 keyword_item maxCounterTags[] = {
1056 {"counter_chapter", MC_COUNTER_CHAPTER },
1057 {"counter_enumi", MC_COUNTER_ENUMI },
1058 {"counter_enumii", MC_COUNTER_ENUMII },
1059 {"counter_enumiii", MC_COUNTER_ENUMIII },
1060 {"counter_enumiv", MC_COUNTER_ENUMIV },
1061 {"counter_paragraph", MC_COUNTER_PARAGRAPH },
1062 {"counter_section", MC_COUNTER_SECTION },
1063 {"counter_subparagraph", MC_COUNTER_SUBPARAGRAPH },
1064 {"counter_subsection", MC_COUNTER_SUBSECTION },
1065 {"counter_subsubsection", MC_COUNTER_SUBSUBSECTION }
1068 pushpophelper pph(lexrc, maxCounterTags, MC_COUNTER_ENUMIV);
1069 int le = lexrc.lex();
1071 case LyXLex::LEX_UNDEF:
1072 lexrc.printError("Unknown MaxCounter tag `$$Token'");
1076 switch (static_cast<MaxCounterTags>(le)) {
1077 case MC_COUNTER_CHAPTER:
1078 maxcounter_ = LABEL_COUNTER_CHAPTER;
1080 case MC_COUNTER_SECTION:
1081 maxcounter_ = LABEL_COUNTER_SECTION;
1083 case MC_COUNTER_SUBSECTION:
1084 maxcounter_ = LABEL_COUNTER_SUBSECTION;
1086 case MC_COUNTER_SUBSUBSECTION:
1087 maxcounter_ = LABEL_COUNTER_SUBSUBSECTION;
1089 case MC_COUNTER_PARAGRAPH:
1090 maxcounter_ = LABEL_COUNTER_PARAGRAPH;
1092 case MC_COUNTER_SUBPARAGRAPH:
1093 maxcounter_ = LABEL_COUNTER_SUBPARAGRAPH;
1095 case MC_COUNTER_ENUMI:
1096 maxcounter_ = LABEL_COUNTER_ENUMI;
1098 case MC_COUNTER_ENUMII:
1099 maxcounter_ = LABEL_COUNTER_ENUMII;
1101 case MC_COUNTER_ENUMIII:
1102 maxcounter_ = LABEL_COUNTER_ENUMIII;
1104 case MC_COUNTER_ENUMIV:
1105 maxcounter_ = LABEL_COUNTER_ENUMIV;
1111 enum ClassOptionsTags {
1119 void LyXTextClass::readClassOptions(LyXLex & lexrc)
1121 keyword_item classOptionsTags[] = {
1123 {"fontsize", CO_FONTSIZE },
1124 {"other", CO_OTHER },
1125 {"pagestyle", CO_PAGESTYLE }
1128 lexrc.pushTable(classOptionsTags, CO_END);
1129 bool getout = false;
1130 while (!getout && lexrc.IsOK()) {
1131 int le = lexrc.lex();
1133 case LyXLex::LEX_UNDEF:
1134 lexrc.printError("Unknown ClassOption tag `$$Token'");
1138 switch (static_cast<ClassOptionsTags>(le)) {
1141 opt_fontsize_ = strip(lexrc.GetString());
1145 opt_pagestyle_ = strip(lexrc.GetString());
1149 options_ = lexrc.GetString();
1160 bool LyXTextClass::hasLayout(string const & name) const
1162 return find_if(layoutlist.begin(), layoutlist.end(),
1163 lyx::compare_memfun(&LyXLayout::name, name))
1164 != layoutlist.end();
1168 LyXLayout const & LyXTextClass::GetLayout (string const & name) const
1170 LayoutList::const_iterator cit =
1171 find_if(layoutlist.begin(),
1173 lyx::compare_memfun(&LyXLayout::name, name));
1174 lyx::Assert(cit != layoutlist.end()); // we require the name to exist
1179 LyXLayout & LyXTextClass::GetLayout(string const & name)
1181 LayoutList::iterator it =
1182 find_if(layoutlist.begin(),
1184 lyx::compare_memfun(&LyXLayout::name, name));
1185 lyx::Assert(it != layoutlist.end()); // we require the name to exist
1190 bool LyXTextClass::delete_layout(string const & name)
1192 LayoutList::iterator it =
1193 remove_if(layoutlist.begin(), layoutlist.end(),
1194 lyx::compare_memfun(&LyXLayout::name, name));
1195 LayoutList::iterator end = layoutlist.end();
1196 bool const ret = (it != end);
1197 layoutlist.erase(it, end);
1202 // Load textclass info if not loaded yet
1203 void LyXTextClass::load()
1208 string const real_file = LibFileSearch("layouts", name_, "layout");
1210 if (Read(real_file)) {
1211 lyxerr << "Error reading `"
1212 << MakeDisplayPath(real_file)
1213 << "'\n(Check `" << name_
1214 << "')\nCheck your installation and "
1215 "try Options/Reconfigure..." << endl;
1221 //////////////////////////////////////////
1223 // Gets textclass number from name
1224 pair<bool, LyXTextClassList::size_type> const
1225 LyXTextClassList::NumberOfClass(string const & textclass) const
1227 ClassList::const_iterator cit =
1228 find_if(classlist.begin(), classlist.end(),
1229 lyx::compare_memfun(&LyXTextClass::name, textclass));
1230 return cit != classlist.end() ?
1231 make_pair(true, size_type(cit - classlist.begin())) :
1232 make_pair(false, size_type(0));
1236 // Gets layout structure from style number and textclass number
1238 LyXTextClassList::Style(LyXTextClassList::size_type textclass,
1239 LyXTextClass::size_type layout) const
1241 classlist[textclass].load();
1242 if (layout < classlist[textclass].numLayouts())
1243 return classlist[textclass][layout];
1244 return classlist[textclass][0];
1248 // Gets layout number from name and textclass number
1249 pair<bool, LyXTextClass::size_type> const
1250 LyXTextClassList::NumberOfLayout(LyXTextClassList::size_type textclass,
1251 string const & name) const
1253 classlist[textclass].load();
1254 for (unsigned int i = 0; i < classlist[textclass].numLayouts(); ++i) {
1255 if (classlist[textclass][i].name() == name)
1256 return make_pair(true, i);
1258 if (name == "dummy")
1259 return make_pair(true, LyXTextClassList::size_type(LYX_DUMMY_LAYOUT));
1260 return make_pair(false, LyXTextClass::size_type(0)); // not found
1264 // Gets a layout (style) name from layout number and textclass number
1266 LyXTextClassList::NameOfLayout(LyXTextClassList::size_type textclass,
1267 LyXTextClass::size_type layout) const
1269 static string const dummy("dummy");
1270 classlist[textclass].load();
1271 if (layout < classlist[textclass].numLayouts())
1272 return classlist[textclass][layout].name();
1277 // Gets a textclass name from number
1279 LyXTextClassList::NameOfClass(LyXTextClassList::size_type number) const
1281 static string const dummy("dummy");
1282 if (classlist.size() == 0) {
1285 lyx::Assert(number < classlist.size());
1286 return classlist[number].name();
1290 // Gets a textclass latexname from number
1292 LyXTextClassList::LatexnameOfClass(LyXTextClassList::size_type number) const
1294 static string const dummy("dummy");
1295 classlist[number].load();
1296 if (classlist.size() == 0) {
1299 lyx::Assert(number < classlist.size());
1300 return classlist[number].latexname();
1304 // Gets a textclass description from number
1306 LyXTextClassList::DescOfClass(LyXTextClassList::size_type number) const
1308 static string const dummy("dummy");
1309 if (classlist.size() == 0) {
1312 lyx::Assert(number < classlist.size());
1313 return classlist[number].description();
1317 // Gets a textclass structure from number
1318 LyXTextClass const &
1319 LyXTextClassList::TextClass(LyXTextClassList::size_type textclass) const
1321 classlist[textclass].load();
1322 if (textclass < classlist.size())
1323 return classlist[textclass];
1325 return classlist[0];
1329 void LyXTextClassList::Add(LyXTextClass const & t)
1331 classlist.push_back(t);
1335 // used when sorting the textclass list.
1336 class less_textclass_desc {
1338 int operator()(LyXTextClass const & tc1, LyXTextClass const & tc2) {
1339 return tc1.description() < tc2.description();
1344 // Reads LyX textclass definitions according to textclass config file
1345 bool LyXTextClassList::Read ()
1348 string real_file = LibFileSearch("", "textclass.lst");
1349 lyxerr[Debug::TCLASS] << "Reading textclasses from `"
1350 << real_file << "'" << endl;
1352 if (real_file.empty()) {
1353 lyxerr << "LyXTextClassList::Read: unable to find "
1354 "textclass file `" << MakeDisplayPath(real_file, 1000)
1355 << "'. Exiting." << endl;
1357 WriteAlert(_("LyX wasn't able to find its layout descriptions!"),
1358 _("Check that the file \"textclass.lst\""),
1359 _("is installed correctly. Sorry, has to exit :-("));
1361 // This causes LyX to end... Not a desirable behaviour. Lgb
1362 // What do you propose? That the user gets a file dialog
1363 // and is allowed to hunt for the file? (Asger)
1364 // more that we have a layout for minimal.cls statically
1365 // compiled in... (Lgb)
1368 if (!lex.setFile(real_file)) {
1369 lyxerr << "LyXTextClassList::Read: "
1370 "lyxlex was not able to set file: "
1371 << real_file << endl;
1375 lyxerr << "LyXTextClassList::Read: unable to open "
1376 "textclass file `" << MakeDisplayPath(real_file, 1000)
1377 << "'\nCheck your installation. LyX can't continue."
1381 bool finished = false;
1382 string fname, clname, desc;
1383 // Parse config-file
1384 lyxerr[Debug::TCLASS] << "Starting parsing of textclass.lst" << endl;
1385 while (lex.IsOK() && !finished) {
1386 lyxerr[Debug::TCLASS] << "\tline by line" << endl;
1387 switch (lex.lex()) {
1388 case LyXLex::LEX_FEOF:
1392 fname = lex.GetString();
1393 lyxerr[Debug::TCLASS] << "Fname: " << fname << endl;
1395 clname = lex.GetString();
1396 lyxerr[Debug::TCLASS]
1397 << "Clname: " << clname << endl;
1399 desc = lex.GetString();
1400 lyxerr[Debug::TCLASS]
1401 << "Desc: " << desc << endl;
1402 // This code is run when we have
1403 // fname, clname and desc
1404 LyXTextClass tmpl(fname,
1408 debugging(Debug::TCLASS)) {
1416 lyxerr[Debug::TCLASS] << "End of parsing of textclass.lst" << endl;
1418 if (classlist.size() == 0) {
1419 lyxerr << "LyXTextClassList::Read: no textclasses found!"
1421 WriteAlert(_("LyX wasn't able to find any layout description!"),
1422 _("Check the contents of the file \"textclass.lst\""),
1423 _("Sorry, has to exit :-("));
1426 // Ok everything loaded ok, now sort the list.
1427 sort(classlist.begin(), classlist.end(), less_textclass_desc());
1433 Returns false if this fails
1436 LyXTextClassList::Load (LyXTextClassList::size_type number) const
1439 if (number < classlist.size()) {
1440 classlist[number].load();
1441 if (classlist[number].numLayouts() == 0) {
1451 std::ostream & operator<<(std::ostream & os, LyXTextClass::PageSides p)
1454 case LyXTextClass::OneSide:
1457 case LyXTextClass::TwoSides: