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"
28 #include "support/lstrings.h"
37 // Global variable: textclass table.
38 LyXTextClassList textclasslist;
41 // Reads the style files
44 lyxerr[Debug::TCLASS] << "LyXSetStyle: parsing configuration...\n";
46 if (!textclasslist.Read()) {
47 lyxerr[Debug::TCLASS] << "LyXSetStyle: an error occured "
48 "during parsing.\n Exiting." << endl;
52 lyxerr[Debug::TCLASS] << "LyXSetStyle: configuration parsed." << endl;
56 // The order of the LayoutTags enum is no more important. [asierra300396]
67 //LT_ENVIRONMENT_DEFAULT,
84 LT_LABELSTRING_APPENDIX,
107 /////////////////////
109 // Constructor for layout
110 LyXLayout::LyXLayout ()
112 margintype = MARGIN_STATIC;
113 latextype = LATEX_PARAGRAPH;
117 font = LyXFont(LyXFont::ALL_INHERIT);
118 labelfont = LyXFont(LyXFont::ALL_INHERIT);
119 resfont = LyXFont(LyXFont::ALL_SANE);
120 reslabelfont = LyXFont(LyXFont::ALL_SANE);
121 nextnoindent = false;
126 labelbottomsep = 0.0;
128 align = LYX_ALIGN_BLOCK;
129 alignpossible = LYX_ALIGN_BLOCK;
130 labeltype = LABEL_NO_LABEL;
131 endlabeltype = END_LABEL_NO_LABEL;
132 // Should or should not. That is the question.
133 // spacing.set(Spacing::OneHalf);
136 newline_allowed = true;
137 free_spacing = false;
142 // Reads a layout definition from file
143 bool LyXLayout::Read (LyXLex & lexrc, LyXTextClass const & tclass)
145 // This table is sorted alphabetically [asierra 30March96]
146 keyword_item layoutTags[] = {
147 { "align", LT_ALIGN },
148 { "alignpossible", LT_ALIGNPOSSIBLE },
149 { "bottomsep", LT_BOTTOMSEP },
150 { "copystyle", LT_COPYSTYLE },
152 { "endlabelstring", LT_ENDLABELSTRING },
153 { "endlabeltype", LT_ENDLABELTYPE },
154 { "fill_bottom", LT_FILL_BOTTOM },
155 { "fill_top", LT_FILL_TOP },
157 { "freespacing", LT_FREE_SPACING },
158 { "intitle", LT_INTITLE },
159 { "itemsep", LT_ITEMSEP },
160 { "keepempty", LT_KEEPEMPTY },
161 { "labelbottomsep", LT_LABEL_BOTTOMSEP },
162 { "labelfont", LT_LABELFONT },
163 { "labelindent", LT_LABELINDENT },
164 { "labelsep", LT_LABELSEP },
165 { "labelstring", LT_LABELSTRING },
166 { "labelstringappendix", LT_LABELSTRING_APPENDIX },
167 { "labeltype", LT_LABELTYPE },
168 { "latexname", LT_LATEXNAME },
169 { "latexparam", LT_LATEXPARAM },
170 { "latextype", LT_LATEXTYPE },
171 { "leftmargin", LT_LEFTMARGIN },
172 { "margin", LT_MARGIN },
173 { "needprotect", LT_NEED_PROTECT },
174 { "newline", LT_NEWLINE },
175 { "nextnoindent", LT_NEXTNOINDENT },
176 { "obsoletedby", LT_OBSOLETEDBY },
177 { "parindent", LT_PARINDENT },
178 { "parsep", LT_PARSEP },
179 { "parskip", LT_PARSKIP },
180 { "passthru", LT_PASS_THRU },
181 { "preamble", LT_PREAMBLE },
182 { "rightmargin", LT_RIGHTMARGIN },
183 { "spacing", LT_SPACING },
184 { "textfont", LT_TEXTFONT },
185 { "topsep", LT_TOPSEP }
189 bool finished = false;
190 lexrc.pushTable(layoutTags, LT_INTITLE);
191 // parse style section
192 while (!finished && lexrc.isOK() && !error) {
193 int le = lexrc.lex();
194 // See comment in lyxrc.C.
196 case LyXLex::LEX_FEOF:
199 case LyXLex::LEX_UNDEF: // parse error
200 lexrc.printError("Unknown layout tag `$$Token'");
205 switch (static_cast<LayoutTags>(le)) {
206 case LT_END: // end of structure
210 case LT_COPYSTYLE: // initialize with a known style
212 if (tclass.hasLayout(lexrc.getString())) {
213 string const tmpname = name_;
214 this->operator= (tclass.GetLayout(lexrc.getString()));
217 lexrc.printError("Cannot copy known "
223 case LT_OBSOLETEDBY: // replace with a known style
225 if (tclass.hasLayout(lexrc.getString())) {
226 string const tmpname = name_;
227 this->operator= (tclass.GetLayout(lexrc.getString()));
229 if (obsoleted_by().empty())
230 obsoleted_by_ = lexrc.getString();
232 lexrc.printError("Cannot replace with"
239 case LT_MARGIN: // Margin style definition.
243 case LT_LATEXTYPE: // Latex style definition.
244 readLatexType(lexrc);
248 intitle = lexrc.next() && lexrc.getInteger();
251 case LT_NEED_PROTECT:
252 needprotect = lexrc.next() && lexrc.getInteger();
256 keepempty = lexrc.next() && lexrc.getInteger();
269 labelfont.lyxRead(lexrc);
272 case LT_NEXTNOINDENT: // Indent next paragraph?
273 if (lexrc.next() && lexrc.getInteger())
276 nextnoindent = false;
281 latexname_ = lexrc.getString();
286 latexparam_ = lexrc.getString();
290 preamble_ = lexrc.getLongString("EndPreamble");
294 readLabelType(lexrc);
297 case LT_ENDLABELTYPE:
298 readEndLabelType(lexrc);
301 case LT_LEFTMARGIN: // left margin type
303 leftmargin = lexrc.getString();
306 case LT_RIGHTMARGIN: // right margin type
308 rightmargin = lexrc.getString();
311 case LT_LABELINDENT: // label indenting flag
313 labelindent = lexrc.getString();
316 case LT_PARINDENT: // paragraph indent. flag
318 parindent = lexrc.getString();
321 case LT_PARSKIP: // paragraph skip size
323 parskip = lexrc.getFloat();
326 case LT_ITEMSEP: // item separation size
328 itemsep = lexrc.getFloat();
331 case LT_TOPSEP: // top separation size
333 topsep = lexrc.getFloat();
336 case LT_BOTTOMSEP: // bottom separation size
338 bottomsep = lexrc.getFloat();
341 case LT_LABEL_BOTTOMSEP: // label bottom separation size
343 labelbottomsep = lexrc.getFloat();
346 case LT_LABELSEP: // label separator
348 labelsep = subst(lexrc.getString(), 'x', ' ');
352 case LT_PARSEP: // par. separation size
354 parsep = lexrc.getFloat();
357 case LT_FILL_TOP: // fill top flag
359 fill_top = lexrc.getInteger();
362 case LT_FILL_BOTTOM: // fill bottom flag
364 fill_bottom = lexrc.getInteger();
367 case LT_NEWLINE: // newlines allowed?
369 newline_allowed = lexrc.getInteger();
372 case LT_ALIGN: // paragraph align
375 case LT_ALIGNPOSSIBLE: // paragraph allowed align
376 readAlignPossible(lexrc);
379 case LT_LABELSTRING: // label string definition
381 labelstring_ = lexrc.getString();
384 case LT_ENDLABELSTRING: // endlabel string definition
386 endlabelstring_ = lexrc.getString();
389 case LT_LABELSTRING_APPENDIX: // label string appendix definition
391 labelstring_appendix_ = lexrc.getString();
394 case LT_FREE_SPACING: // Allow for free spacing.
396 free_spacing = lexrc.getInteger();
399 case LT_PASS_THRU: // Allow for pass thru.
401 pass_thru = lexrc.getInteger();
404 case LT_SPACING: // setspace.sty
423 void LyXLayout::readAlign(LyXLex & lexrc)
425 keyword_item alignTags[] = {
426 { "block", AT_BLOCK },
427 { "center", AT_CENTER },
428 { "layout", AT_LAYOUT },
430 { "right", AT_RIGHT }
433 pushpophelper pph(lexrc, alignTags, AT_LAYOUT);
434 int le = lexrc.lex();
436 case LyXLex::LEX_UNDEF:
437 lexrc.printError("Unknown alignment `$$Token'");
441 switch (static_cast<AlignTags>(le)) {
443 align = LYX_ALIGN_BLOCK;
446 align = LYX_ALIGN_LEFT;
449 align = LYX_ALIGN_RIGHT;
452 align = LYX_ALIGN_CENTER;
455 align = LYX_ALIGN_LAYOUT;
461 void LyXLayout::readAlignPossible(LyXLex & lexrc)
463 keyword_item alignTags[] = {
464 { "block", AT_BLOCK },
465 { "center", AT_CENTER },
466 { "layout", AT_LAYOUT },
468 { "right", AT_RIGHT }
471 lexrc.pushTable(alignTags, AT_LAYOUT);
472 alignpossible = LYX_ALIGN_NONE;
473 int lineno = lexrc.getLineNo();
475 int le = lexrc.lex();
477 case LyXLex::LEX_UNDEF:
478 lexrc.printError("Unknown alignment `$$Token'");
482 switch (static_cast<AlignTags>(le)) {
484 alignpossible |= LYX_ALIGN_BLOCK;
487 alignpossible |= LYX_ALIGN_LEFT;
490 alignpossible |= LYX_ALIGN_RIGHT;
493 alignpossible |= LYX_ALIGN_CENTER;
496 alignpossible |= LYX_ALIGN_LAYOUT;
499 } while (lineno == lexrc.getLineNo());
508 LA_CENTERED_TOP_ENVIRONMENT,
513 LA_COUNTER_SUBSECTION,
514 LA_COUNTER_SUBSUBSECTION,
515 LA_COUNTER_PARAGRAPH,
516 LA_COUNTER_SUBPARAGRAPH,
525 void LyXLayout::readLabelType(LyXLex & lexrc)
527 keyword_item labelTypeTags[] = {
528 { "bibliography", LA_BIBLIO },
529 { "centered_top_environment", LA_CENTERED_TOP_ENVIRONMENT },
530 { "counter_chapter", LA_COUNTER_CHAPTER },
531 { "counter_enumi", LA_COUNTER_ENUMI },
532 { "counter_enumii", LA_COUNTER_ENUMII },
533 { "counter_enumiii", LA_COUNTER_ENUMIII },
534 { "counter_enumiv", LA_COUNTER_ENUMIV },
535 { "counter_paragraph", LA_COUNTER_PARAGRAPH },
536 { "counter_section", LA_COUNTER_SECTION },
537 { "counter_subparagraph", LA_COUNTER_SUBPARAGRAPH },
538 { "counter_subsection", LA_COUNTER_SUBSECTION },
539 { "counter_subsubsection", LA_COUNTER_SUBSUBSECTION },
540 { "manual", LA_MANUAL },
541 { "no_label", LA_NO_LABEL },
542 { "sensitive", LA_SENSITIVE },
543 { "static", LA_STATIC },
544 { "top_environment", LA_TOP_ENVIRONMENT }
547 pushpophelper pph(lexrc, labelTypeTags, LA_BIBLIO);
548 int le = lexrc.lex();
550 case LyXLex::LEX_UNDEF:
551 lexrc.printError("Unknown labeltype tag `$$Token'");
555 switch (static_cast<LabelTypeTags>(le)) {
557 labeltype = LABEL_NO_LABEL;
560 labeltype = LABEL_MANUAL;
562 case LA_TOP_ENVIRONMENT:
563 labeltype = LABEL_TOP_ENVIRONMENT;
565 case LA_CENTERED_TOP_ENVIRONMENT:
566 labeltype = LABEL_CENTERED_TOP_ENVIRONMENT;
569 labeltype = LABEL_STATIC;
572 labeltype = LABEL_SENSITIVE;
574 case LA_COUNTER_CHAPTER:
575 labeltype = LABEL_COUNTER_CHAPTER;
577 case LA_COUNTER_SECTION:
578 labeltype = LABEL_COUNTER_SECTION;
580 case LA_COUNTER_SUBSECTION:
581 labeltype = LABEL_COUNTER_SUBSECTION;
583 case LA_COUNTER_SUBSUBSECTION:
584 labeltype = LABEL_COUNTER_SUBSUBSECTION;
586 case LA_COUNTER_PARAGRAPH:
587 labeltype = LABEL_COUNTER_PARAGRAPH;
589 case LA_COUNTER_SUBPARAGRAPH:
590 labeltype = LABEL_COUNTER_SUBPARAGRAPH;
592 case LA_COUNTER_ENUMI:
593 labeltype = LABEL_COUNTER_ENUMI;
595 case LA_COUNTER_ENUMII:
596 labeltype = LABEL_COUNTER_ENUMII;
598 case LA_COUNTER_ENUMIII:
599 labeltype = LABEL_COUNTER_ENUMIII;
601 case LA_COUNTER_ENUMIV:
602 labeltype = LABEL_COUNTER_ENUMIV;
605 labeltype = LABEL_BIBLIO;
613 keyword_item endlabelTypeTags[] = {
614 { "box", END_LABEL_BOX },
615 { "filled_box", END_LABEL_FILLED_BOX },
616 { "no_label", END_LABEL_NO_LABEL },
617 { "static", END_LABEL_STATIC }
623 void LyXLayout::readEndLabelType(LyXLex & lexrc)
625 pushpophelper pph(lexrc, endlabelTypeTags,
626 END_LABEL_ENUM_LAST-END_LABEL_ENUM_FIRST+1);
627 int le = lexrc.lex();
629 case LyXLex::LEX_UNDEF:
630 lexrc.printError("Unknown labeltype tag `$$Token'");
632 case END_LABEL_STATIC:
634 case END_LABEL_FILLED_BOX:
635 case END_LABEL_NO_LABEL:
636 endlabeltype = static_cast<LYX_END_LABEL_TYPES>(le);
639 lyxerr << "Unhandled value " << le
640 << " in LyXLayout::readEndLabelType." << endl;
646 void LyXLayout::readMargin(LyXLex & lexrc)
648 keyword_item marginTags[] = {
649 { "dynamic", MARGIN_DYNAMIC },
650 { "first_dynamic", MARGIN_FIRST_DYNAMIC },
651 { "manual", MARGIN_MANUAL },
652 { "right_address_box", MARGIN_RIGHT_ADDRESS_BOX },
653 { "static", MARGIN_STATIC }
656 pushpophelper pph(lexrc, marginTags, MARGIN_RIGHT_ADDRESS_BOX);
658 int le = lexrc.lex();
660 case LyXLex::LEX_UNDEF:
661 lexrc.printError("Unknown margin type tag `$$Token'");
666 case MARGIN_FIRST_DYNAMIC:
667 case MARGIN_RIGHT_ADDRESS_BOX:
668 margintype = static_cast<LYX_MARGIN_TYPE>(le);
671 lyxerr << "Unhandled value " << le
672 << " in LyXLayout::readMargin." << endl;
678 void LyXLayout::readLatexType(LyXLex & lexrc)
680 keyword_item latexTypeTags[] = {
681 { "command", LATEX_COMMAND },
682 { "environment", LATEX_ENVIRONMENT },
683 { "item_environment", LATEX_ITEM_ENVIRONMENT },
684 { "list_environment", LATEX_LIST_ENVIRONMENT },
685 { "paragraph", LATEX_PARAGRAPH }
688 pushpophelper pph(lexrc, latexTypeTags, LATEX_LIST_ENVIRONMENT);
689 int le = lexrc.lex();
691 case LyXLex::LEX_UNDEF:
692 lexrc.printError("Unknown latextype tag `$$Token'");
694 case LATEX_PARAGRAPH:
696 case LATEX_ENVIRONMENT:
697 case LATEX_ITEM_ENVIRONMENT:
698 case LATEX_LIST_ENVIRONMENT:
699 latextype = static_cast<LYX_LATEX_TYPES>(le);
702 lyxerr << "Unhandled value " << le
703 << " in LyXLayout::readLatexType." << endl;
710 ST_SPACING_SINGLE = 1,
717 void LyXLayout::readSpacing(LyXLex & lexrc)
719 keyword_item spacingTags[] = {
720 {"double", ST_SPACING_DOUBLE },
721 {"onehalf", ST_SPACING_ONEHALF },
722 {"other", ST_OTHER },
723 {"single", ST_SPACING_SINGLE }
726 pushpophelper pph(lexrc, spacingTags, ST_OTHER);
727 int le = lexrc.lex();
729 case LyXLex::LEX_UNDEF:
730 lexrc.printError("Unknown spacing token `$$Token'");
734 switch (static_cast<SpacingTags>(le)) {
735 case ST_SPACING_SINGLE:
736 spacing.set(Spacing::Single);
738 case ST_SPACING_ONEHALF:
739 spacing.set(Spacing::Onehalf);
741 case ST_SPACING_DOUBLE:
742 spacing.set(Spacing::Double);
746 spacing.set(Spacing::Other, lexrc.getFloat());
752 /* ******************************************************************* */
754 LyXTextClass::LyXTextClass(string const & fn, string const & cln,
756 : name_(fn), latexname_(cln), description_(desc)
763 pagestyle_ = "default";
764 maxcounter_ = LABEL_COUNTER_CHAPTER;
765 defaultfont_ = LyXFont(LyXFont::ALL_SANE);
766 opt_fontsize_ = "10|11|12";
767 opt_pagestyle_ = "empty|plain|headings|fancy";
773 bool LyXTextClass::do_readStyle(LyXLex & lexrc, LyXLayout & lay)
775 lyxerr[Debug::TCLASS] << "Reading style " << lay.name() << endl;
776 if (!lay.Read(lexrc, *this)) {
778 lay.resfont = lay.font;
779 #ifndef INHERIT_LANGUAGE
780 lay.resfont.realize(defaultfont());
781 lay.reslabelfont = lay.labelfont;
782 lay.reslabelfont.realize(defaultfont());
784 lay.resfont.realize(defaultfont(), default_language);
785 lay.reslabelfont = lay.labelfont;
786 lay.reslabelfont.realize(defaultfont(), default_language);
788 return false; // no errors
790 lyxerr << "Error parsing style `" << lay.name() << "'" << endl;
817 // Reads a textclass structure from file.
818 bool LyXTextClass::Read(string const & filename, bool merge)
820 keyword_item textClassTags[] = {
821 { "classoptions", TC_CLASSOPTIONS },
822 { "columns", TC_COLUMNS },
823 { "defaultfont", TC_DEFAULTFONT },
824 { "input", TC_INPUT },
825 { "leftmargin", TC_LEFTMARGIN },
826 { "maxcounter", TC_MAXCOUNTER },
827 { "nostyle", TC_NOSTYLE },
828 { "outputtype", TC_OUTPUTTYPE },
829 { "pagestyle", TC_PAGESTYLE },
830 { "preamble", TC_PREAMBLE },
831 { "providesamsmath", TC_PROVIDESAMSMATH },
832 { "providesmakeidx", TC_PROVIDESMAKEIDX },
833 { "providesurl", TC_PROVIDESURL },
834 { "rightmargin", TC_RIGHTMARGIN },
835 { "secnumdepth", TC_SECNUMDEPTH },
836 { "sides", TC_SIDES },
837 { "style", TC_STYLE },
838 { "tocdepth", TC_TOCDEPTH }
842 lyxerr[Debug::TCLASS] << "Reading textclass "
843 << MakeDisplayPath(filename)
846 lyxerr[Debug::TCLASS] << "Reading input file "
847 << MakeDisplayPath(filename)
850 LyXLex lexrc(textClassTags, TC_RIGHTMARGIN);
853 lexrc.setFile(filename);
854 if (!lexrc.isOK()) error = true;
857 while (lexrc.isOK() && !error) {
858 int le = lexrc.lex();
860 case LyXLex::LEX_FEOF:
863 case LyXLex::LEX_UNDEF:
864 lexrc.printError("Unknown TextClass tag `$$Token'");
869 switch (static_cast<TextClassTags>(le)) {
870 case TC_OUTPUTTYPE: // output type definition
871 readOutputType(lexrc);
874 case TC_INPUT: // Include file
876 string tmp = LibFileSearch("layouts",
880 if (Read(tmp, true)) {
881 lexrc.printError("Error reading input"
890 string name = subst(lexrc.getString(),
892 if (hasLayout(name)) {
893 LyXLayout & lay = GetLayout(name);
894 error = do_readStyle(lexrc, lay);
898 if (!(error = do_readStyle(lexrc, lay)))
899 layoutlist.push_back(lay);
903 lexrc.printError("No name given for style: `$$Token'.");
910 string const style = subst(lexrc.getString(),
912 if (!delete_layout(style))
913 lexrc.printError("Cannot delete style"
920 columns_ = lexrc.getInteger();
925 switch (lexrc.getInteger()) {
926 case 1: sides_ = OneSide; break;
927 case 2: sides_ = TwoSides; break;
929 lyxerr << "Impossible number of page"
930 " sides, setting to one."
940 pagestyle_ = strip(lexrc.getString());
944 defaultfont_.lyxRead(lexrc);
945 if (!defaultfont_.resolved()) {
946 lexrc.printError("Warning: defaultfont should "
947 "be fully instantiated!");
948 #ifndef INHERIT_LANGUAGE
949 defaultfont_.realize(LyXFont(LyXFont::ALL_SANE));
951 defaultfont_.realize(LyXFont(LyXFont::ALL_SANE),
958 readMaxCounter(lexrc);
963 secnumdepth_ = lexrc.getInteger();
968 tocdepth_ = lexrc.getInteger();
971 // First step to support options
972 case TC_CLASSOPTIONS:
973 readClassOptions(lexrc);
977 preamble_ = lexrc.getLongString("EndPreamble");
980 case TC_PROVIDESAMSMATH:
981 if (lexrc.next() && lexrc.getInteger())
982 provides_ |= amsmath;
985 case TC_PROVIDESMAKEIDX:
986 if (lexrc.next() && lexrc.getInteger())
987 provides_ |= makeidx;
991 if (lexrc.next() && lexrc.getInteger())
995 case TC_LEFTMARGIN: // left margin type
997 leftmargin_ = lexrc.getString();
1000 case TC_RIGHTMARGIN: // right margin type
1002 rightmargin_ = lexrc.getString();
1007 if (!merge) { // we are at top level here.
1008 lyxerr[Debug::TCLASS] << "Finished reading textclass "
1009 << MakeDisplayPath(filename)
1012 lyxerr[Debug::TCLASS] << "Finished reading input file "
1013 << MakeDisplayPath(filename)
1020 void LyXTextClass::readOutputType(LyXLex & lexrc)
1022 keyword_item outputTypeTags[] = {
1023 { "docbook", DOCBOOK },
1025 { "linuxdoc", LINUXDOC },
1026 { "literate", LITERATE }
1029 pushpophelper pph(lexrc, outputTypeTags, LITERATE);
1031 int le = lexrc.lex();
1033 case LyXLex::LEX_UNDEF:
1034 lexrc.printError("Unknown output type `$$Token'");
1040 outputType_ = static_cast<OutputType>(le);
1043 lyxerr << "Unhandled value " << le
1044 << " in LyXTextClass::readOutputType." << endl;
1051 enum MaxCounterTags {
1052 MC_COUNTER_CHAPTER = 1,
1054 MC_COUNTER_SUBSECTION,
1055 MC_COUNTER_SUBSUBSECTION,
1056 MC_COUNTER_PARAGRAPH,
1057 MC_COUNTER_SUBPARAGRAPH,
1065 void LyXTextClass::readMaxCounter(LyXLex & lexrc)
1067 keyword_item maxCounterTags[] = {
1068 {"counter_chapter", MC_COUNTER_CHAPTER },
1069 {"counter_enumi", MC_COUNTER_ENUMI },
1070 {"counter_enumii", MC_COUNTER_ENUMII },
1071 {"counter_enumiii", MC_COUNTER_ENUMIII },
1072 {"counter_enumiv", MC_COUNTER_ENUMIV },
1073 {"counter_paragraph", MC_COUNTER_PARAGRAPH },
1074 {"counter_section", MC_COUNTER_SECTION },
1075 {"counter_subparagraph", MC_COUNTER_SUBPARAGRAPH },
1076 {"counter_subsection", MC_COUNTER_SUBSECTION },
1077 {"counter_subsubsection", MC_COUNTER_SUBSUBSECTION }
1080 pushpophelper pph(lexrc, maxCounterTags, MC_COUNTER_ENUMIV);
1081 int le = lexrc.lex();
1083 case LyXLex::LEX_UNDEF:
1084 lexrc.printError("Unknown MaxCounter tag `$$Token'");
1088 switch (static_cast<MaxCounterTags>(le)) {
1089 case MC_COUNTER_CHAPTER:
1090 maxcounter_ = LABEL_COUNTER_CHAPTER;
1092 case MC_COUNTER_SECTION:
1093 maxcounter_ = LABEL_COUNTER_SECTION;
1095 case MC_COUNTER_SUBSECTION:
1096 maxcounter_ = LABEL_COUNTER_SUBSECTION;
1098 case MC_COUNTER_SUBSUBSECTION:
1099 maxcounter_ = LABEL_COUNTER_SUBSUBSECTION;
1101 case MC_COUNTER_PARAGRAPH:
1102 maxcounter_ = LABEL_COUNTER_PARAGRAPH;
1104 case MC_COUNTER_SUBPARAGRAPH:
1105 maxcounter_ = LABEL_COUNTER_SUBPARAGRAPH;
1107 case MC_COUNTER_ENUMI:
1108 maxcounter_ = LABEL_COUNTER_ENUMI;
1110 case MC_COUNTER_ENUMII:
1111 maxcounter_ = LABEL_COUNTER_ENUMII;
1113 case MC_COUNTER_ENUMIII:
1114 maxcounter_ = LABEL_COUNTER_ENUMIII;
1116 case MC_COUNTER_ENUMIV:
1117 maxcounter_ = LABEL_COUNTER_ENUMIV;
1123 enum ClassOptionsTags {
1131 void LyXTextClass::readClassOptions(LyXLex & lexrc)
1133 keyword_item classOptionsTags[] = {
1135 {"fontsize", CO_FONTSIZE },
1136 {"other", CO_OTHER },
1137 {"pagestyle", CO_PAGESTYLE }
1140 lexrc.pushTable(classOptionsTags, CO_END);
1141 bool getout = false;
1142 while (!getout && lexrc.isOK()) {
1143 int le = lexrc.lex();
1145 case LyXLex::LEX_UNDEF:
1146 lexrc.printError("Unknown ClassOption tag `$$Token'");
1150 switch (static_cast<ClassOptionsTags>(le)) {
1153 opt_fontsize_ = strip(lexrc.getString());
1157 opt_pagestyle_ = strip(lexrc.getString());
1161 options_ = lexrc.getString();
1172 bool LyXTextClass::hasLayout(string const & name) const
1174 return find_if(layoutlist.begin(), layoutlist.end(),
1175 lyx::compare_memfun(&LyXLayout::name, name))
1176 != layoutlist.end();
1180 LyXLayout const & LyXTextClass::GetLayout (string const & name) const
1182 LayoutList::const_iterator cit =
1183 find_if(layoutlist.begin(),
1185 lyx::compare_memfun(&LyXLayout::name, name));
1186 lyx::Assert(cit != layoutlist.end()); // we require the name to exist
1191 LyXLayout & LyXTextClass::GetLayout(string const & name)
1193 LayoutList::iterator it =
1194 find_if(layoutlist.begin(),
1196 lyx::compare_memfun(&LyXLayout::name, name));
1197 lyx::Assert(it != layoutlist.end()); // we require the name to exist
1202 bool LyXTextClass::delete_layout(string const & name)
1204 LayoutList::iterator it =
1205 remove_if(layoutlist.begin(), layoutlist.end(),
1206 lyx::compare_memfun(&LyXLayout::name, name));
1207 LayoutList::iterator end = layoutlist.end();
1208 bool const ret = (it != end);
1209 layoutlist.erase(it, end);
1214 // Load textclass info if not loaded yet
1215 void LyXTextClass::load()
1220 string const real_file = LibFileSearch("layouts", name_, "layout");
1222 if (Read(real_file)) {
1223 lyxerr << "Error reading `"
1224 << MakeDisplayPath(real_file)
1225 << "'\n(Check `" << name_
1226 << "')\nCheck your installation and "
1227 "try Options/Reconfigure..." << endl;
1233 //////////////////////////////////////////
1235 // Gets textclass number from name
1236 pair<bool, LyXTextClassList::size_type> const
1237 LyXTextClassList::NumberOfClass(string const & textclass) const
1239 ClassList::const_iterator cit =
1240 find_if(classlist.begin(), classlist.end(),
1241 lyx::compare_memfun(&LyXTextClass::name, textclass));
1242 return cit != classlist.end() ?
1243 make_pair(true, size_type(cit - classlist.begin())) :
1244 make_pair(false, size_type(0));
1248 // Gets layout structure from style number and textclass number
1250 LyXTextClassList::Style(LyXTextClassList::size_type textclass,
1251 LyXTextClass::size_type layout) const
1253 classlist[textclass].load();
1254 if (layout < classlist[textclass].numLayouts())
1255 return classlist[textclass][layout];
1256 return classlist[textclass][0];
1260 // Gets layout number from name and textclass number
1261 pair<bool, LyXTextClass::size_type> const
1262 LyXTextClassList::NumberOfLayout(LyXTextClassList::size_type textclass,
1263 string const & name) const
1265 classlist[textclass].load();
1266 for (unsigned int i = 0; i < classlist[textclass].numLayouts(); ++i) {
1267 if (classlist[textclass][i].name() == name)
1268 return make_pair(true, i);
1270 if (name == "dummy")
1271 return make_pair(true, LyXTextClassList::size_type(LYX_DUMMY_LAYOUT));
1272 return make_pair(false, LyXTextClass::size_type(0)); // not found
1276 // Gets a layout (style) name from layout number and textclass number
1278 LyXTextClassList::NameOfLayout(LyXTextClassList::size_type textclass,
1279 LyXTextClass::size_type layout) const
1281 static string const dummy("dummy");
1282 classlist[textclass].load();
1283 if (layout < classlist[textclass].numLayouts())
1284 return classlist[textclass][layout].name();
1289 // Gets a textclass name from number
1291 LyXTextClassList::NameOfClass(LyXTextClassList::size_type number) const
1293 static string const dummy("dummy");
1294 if (classlist.size() == 0) {
1297 lyx::Assert(number < classlist.size());
1298 return classlist[number].name();
1302 // Gets a textclass latexname from number
1304 LyXTextClassList::LatexnameOfClass(LyXTextClassList::size_type number) const
1306 static string const dummy("dummy");
1307 classlist[number].load();
1308 if (classlist.size() == 0) {
1311 lyx::Assert(number < classlist.size());
1312 return classlist[number].latexname();
1316 // Gets a textclass description from number
1318 LyXTextClassList::DescOfClass(LyXTextClassList::size_type number) const
1320 static string const dummy("dummy");
1321 if (classlist.size() == 0) {
1324 lyx::Assert(number < classlist.size());
1325 return classlist[number].description();
1329 // Gets a textclass structure from number
1330 LyXTextClass const &
1331 LyXTextClassList::TextClass(LyXTextClassList::size_type textclass) const
1333 classlist[textclass].load();
1334 if (textclass < classlist.size())
1335 return classlist[textclass];
1337 return classlist[0];
1341 void LyXTextClassList::Add(LyXTextClass const & t)
1343 classlist.push_back(t);
1347 // used when sorting the textclass list.
1348 class less_textclass_desc {
1350 int operator()(LyXTextClass const & tc1, LyXTextClass const & tc2) {
1351 return tc1.description() < tc2.description();
1356 // Reads LyX textclass definitions according to textclass config file
1357 bool LyXTextClassList::Read ()
1360 string real_file = LibFileSearch("", "textclass.lst");
1361 lyxerr[Debug::TCLASS] << "Reading textclasses from `"
1362 << real_file << "'" << endl;
1364 if (real_file.empty()) {
1365 lyxerr << "LyXTextClassList::Read: unable to find "
1366 "textclass file `" << MakeDisplayPath(real_file, 1000)
1367 << "'. Exiting." << endl;
1369 WriteAlert(_("LyX wasn't able to find its layout descriptions!"),
1370 _("Check that the file \"textclass.lst\""),
1371 _("is installed correctly. Sorry, has to exit :-("));
1373 // This causes LyX to end... Not a desirable behaviour. Lgb
1374 // What do you propose? That the user gets a file dialog
1375 // and is allowed to hunt for the file? (Asger)
1376 // more that we have a layout for minimal.cls statically
1377 // compiled in... (Lgb)
1380 if (!lex.setFile(real_file)) {
1381 lyxerr << "LyXTextClassList::Read: "
1382 "lyxlex was not able to set file: "
1383 << real_file << endl;
1387 lyxerr << "LyXTextClassList::Read: unable to open "
1388 "textclass file `" << MakeDisplayPath(real_file, 1000)
1389 << "'\nCheck your installation. LyX can't continue."
1394 bool finished = false;
1395 // Parse config-file
1396 lyxerr[Debug::TCLASS] << "Starting parsing of textclass.lst" << endl;
1397 while (lex.isOK() && !finished) {
1398 lyxerr[Debug::TCLASS] << "\tline by line" << endl;
1399 switch (lex.lex()) {
1400 case LyXLex::LEX_FEOF:
1404 string const fname = lex.getString();
1405 lyxerr[Debug::TCLASS] << "Fname: " << fname << endl;
1407 string const clname = lex.getString();
1408 lyxerr[Debug::TCLASS]
1409 << "Clname: " << clname << endl;
1411 string const desc = lex.getString();
1412 lyxerr[Debug::TCLASS]
1413 << "Desc: " << desc << endl;
1414 // This code is run when we have
1415 // fname, clname and desc
1416 LyXTextClass tmpl(fname,
1420 debugging(Debug::TCLASS)) {
1428 lyxerr[Debug::TCLASS] << "End of parsing of textclass.lst" << endl;
1430 if (classlist.size() == 0) {
1431 lyxerr << "LyXTextClassList::Read: no textclasses found!"
1433 WriteAlert(_("LyX wasn't able to find any layout description!"),
1434 _("Check the contents of the file \"textclass.lst\""),
1435 _("Sorry, has to exit :-("));
1438 // Ok everything loaded ok, now sort the list.
1439 sort(classlist.begin(), classlist.end(), less_textclass_desc());
1445 Returns false if this fails
1448 LyXTextClassList::Load (LyXTextClassList::size_type number) const
1451 if (number < classlist.size()) {
1452 classlist[number].load();
1453 if (classlist[number].numLayouts() == 0) {
1463 std::ostream & operator<<(std::ostream & os, LyXTextClass::PageSides p)
1466 case LyXTextClass::OneSide:
1469 case LyXTextClass::TwoSides: