1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * ======================================================
15 #pragma implementation
22 #include "support/filetools.h"
23 #include "lyx_gui_misc.h"
26 #include "support/LAssert.h"
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,
82 LT_LABELSTRING_APPENDIX,
105 /////////////////////
107 // Constructor for layout
108 LyXLayout::LyXLayout ()
110 margintype = MARGIN_STATIC;
111 latextype = LATEX_PARAGRAPH;
115 font = LyXFont(LyXFont::ALL_INHERIT);
116 labelfont = LyXFont(LyXFont::ALL_INHERIT);
117 resfont = LyXFont(LyXFont::ALL_SANE);
118 reslabelfont = LyXFont(LyXFont::ALL_SANE);
119 nextnoindent = false;
124 labelbottomsep = 0.0;
126 align = LYX_ALIGN_BLOCK;
127 alignpossible = LYX_ALIGN_BLOCK;
128 labeltype = LABEL_NO_LABEL;
129 endlabeltype = END_LABEL_NO_LABEL;
130 // Should or should not. That is the question.
131 // spacing.set(Spacing::OneHalf);
134 newline_allowed = true;
135 free_spacing = false;
139 // Reads a layout definition from file
140 bool LyXLayout::Read (LyXLex & lexrc, LyXTextClass const & tclass)
142 // This table is sorted alphabetically [asierra 30March96]
143 keyword_item layoutTags[] = {
144 { "align", LT_ALIGN },
145 { "alignpossible", LT_ALIGNPOSSIBLE },
146 { "bottomsep", LT_BOTTOMSEP },
147 { "copystyle", LT_COPYSTYLE },
149 { "endlabelstring", LT_ENDLABELSTRING },
150 { "endlabeltype", LT_ENDLABELTYPE },
151 { "fill_bottom", LT_FILL_BOTTOM },
152 { "fill_top", LT_FILL_TOP },
154 { "freespacing", LT_FREE_SPACING },
155 { "intitle", LT_INTITLE },
156 { "itemsep", LT_ITEMSEP },
157 { "keepempty", LT_KEEPEMPTY },
158 { "labelbottomsep", LT_LABEL_BOTTOMSEP },
159 { "labelfont", LT_LABELFONT },
160 { "labelindent", LT_LABELINDENT },
161 { "labelsep", LT_LABELSEP },
162 { "labelstring", LT_LABELSTRING },
163 { "labelstringappendix", LT_LABELSTRING_APPENDIX },
164 { "labeltype", LT_LABELTYPE },
165 { "latexname", LT_LATEXNAME },
166 { "latexparam", LT_LATEXPARAM },
167 { "latextype", LT_LATEXTYPE },
168 { "leftmargin", LT_LEFTMARGIN },
169 { "margin", LT_MARGIN },
170 { "needprotect", LT_NEED_PROTECT },
171 { "newline", LT_NEWLINE },
172 { "nextnoindent", LT_NEXTNOINDENT },
173 { "obsoletedby", LT_OBSOLETEDBY },
174 { "parindent", LT_PARINDENT },
175 { "parsep", LT_PARSEP },
176 { "parskip", LT_PARSKIP },
177 { "preamble", LT_PREAMBLE },
178 { "rightmargin", LT_RIGHTMARGIN },
179 { "spacing", LT_SPACING },
180 { "textfont", LT_TEXTFONT },
181 { "topsep", LT_TOPSEP }
185 bool finished = false;
186 lexrc.pushTable(layoutTags, LT_INTITLE);
187 // parse style section
188 while (!finished && lexrc.IsOK() && !error) {
189 int le = lexrc.lex();
190 // See comment in lyxrc.C.
192 case LyXLex::LEX_FEOF:
195 case LyXLex::LEX_UNDEF: // parse error
196 lexrc.printError("Unknown layout tag `$$Token'");
201 switch (static_cast<LayoutTags>(le)) {
202 case LT_END: // end of structure
206 case LT_COPYSTYLE: // initialize with a known style
208 if (tclass.hasLayout(lexrc.GetString())) {
209 string tmpname = name_;
210 this->operator= (tclass.GetLayout(lexrc.GetString()));
213 lexrc.printError("Cannot copy known "
219 case LT_OBSOLETEDBY: // replace with a known style
221 if (tclass.hasLayout(lexrc.GetString())) {
222 string tmpname = name_;
223 this->operator= (tclass.GetLayout(lexrc.GetString()));
225 if (obsoleted_by().empty())
226 obsoleted_by_ = lexrc.GetString();
228 lexrc.printError("Cannot replace with"
235 case LT_MARGIN: // Margin style definition.
239 case LT_LATEXTYPE: // Latex style definition.
240 readLatexType(lexrc);
244 intitle = lexrc.next() && lexrc.GetInteger();
247 case LT_NEED_PROTECT:
248 needprotect = lexrc.next() && lexrc.GetInteger();
252 keepempty = lexrc.next() && lexrc.GetInteger();
265 labelfont.lyxRead(lexrc);
268 case LT_NEXTNOINDENT: // Indent next paragraph?
269 if (lexrc.next() && lexrc.GetInteger())
272 nextnoindent = false;
277 latexname_ = lexrc.GetString();
282 latexparam_ = lexrc.GetString();
286 preamble_ = lexrc.getLongString("EndPreamble");
290 readLabelType(lexrc);
293 case LT_ENDLABELTYPE:
294 readEndLabelType(lexrc);
297 case LT_LEFTMARGIN: // left margin type
299 leftmargin = lexrc.GetString();
302 case LT_RIGHTMARGIN: // right margin type
304 rightmargin = lexrc.GetString();
307 case LT_LABELINDENT: // label indenting flag
309 labelindent = lexrc.GetString();
312 case LT_PARINDENT: // paragraph indent. flag
314 parindent = lexrc.GetString();
317 case LT_PARSKIP: // paragraph skip size
319 parskip = lexrc.GetFloat();
322 case LT_ITEMSEP: // item separation size
324 itemsep = lexrc.GetFloat();
327 case LT_TOPSEP: // top separation size
329 topsep = lexrc.GetFloat();
332 case LT_BOTTOMSEP: // bottom separation size
334 bottomsep = lexrc.GetFloat();
337 case LT_LABEL_BOTTOMSEP: // label bottom separation size
339 labelbottomsep = lexrc.GetFloat();
342 case LT_LABELSEP: // label separator
344 labelsep = subst(lexrc.GetString(), 'x', ' ');
348 case LT_PARSEP: // par. separation size
350 parsep = lexrc.GetFloat();
353 case LT_FILL_TOP: // fill top flag
355 fill_top = lexrc.GetInteger();
358 case LT_FILL_BOTTOM: // fill bottom flag
360 fill_bottom = lexrc.GetInteger();
363 case LT_NEWLINE: // newlines allowed?
365 newline_allowed = lexrc.GetInteger();
368 case LT_ALIGN: // paragraph align
371 case LT_ALIGNPOSSIBLE: // paragraph allowed align
372 readAlignPossible(lexrc);
375 case LT_LABELSTRING: // label string definition
377 labelstring_ = lexrc.GetString();
380 case LT_ENDLABELSTRING: // endlabel string definition
382 endlabelstring_ = lexrc.GetString();
385 case LT_LABELSTRING_APPENDIX: // label string appendix definition
387 labelstring_appendix_ = lexrc.GetString();
390 case LT_FREE_SPACING: // Allow for free spacing.
392 free_spacing = lexrc.GetInteger();
395 case LT_SPACING: // setspace.sty
414 void LyXLayout::readAlign(LyXLex & lexrc)
416 keyword_item alignTags[] = {
417 { "block", AT_BLOCK },
418 { "center", AT_CENTER },
419 { "layout", AT_LAYOUT },
421 { "right", AT_RIGHT }
424 pushpophelper pph(lexrc, alignTags, AT_LAYOUT);
425 int le = lexrc.lex();
427 case LyXLex::LEX_UNDEF:
428 lexrc.printError("Unknown alignment `$$Token'");
432 switch (static_cast<AlignTags>(le)) {
434 align = LYX_ALIGN_BLOCK;
437 align = LYX_ALIGN_LEFT;
440 align = LYX_ALIGN_RIGHT;
443 align = LYX_ALIGN_CENTER;
446 align = LYX_ALIGN_LAYOUT;
452 void LyXLayout::readAlignPossible(LyXLex & lexrc)
454 keyword_item alignTags[] = {
455 { "block", AT_BLOCK },
456 { "center", AT_CENTER },
457 { "layout", AT_LAYOUT },
459 { "right", AT_RIGHT }
462 lexrc.pushTable(alignTags, AT_LAYOUT);
463 alignpossible = LYX_ALIGN_NONE;
464 int lineno = lexrc.GetLineNo();
466 int le = lexrc.lex();
468 case LyXLex::LEX_UNDEF:
469 lexrc.printError("Unknown alignment `$$Token'");
473 switch (static_cast<AlignTags>(le)) {
475 alignpossible |= LYX_ALIGN_BLOCK;
478 alignpossible |= LYX_ALIGN_LEFT;
481 alignpossible |= LYX_ALIGN_RIGHT;
484 alignpossible |= LYX_ALIGN_CENTER;
487 alignpossible |= LYX_ALIGN_LAYOUT;
490 } while (lineno == lexrc.GetLineNo());
499 LA_CENTERED_TOP_ENVIRONMENT,
504 LA_COUNTER_SUBSECTION,
505 LA_COUNTER_SUBSUBSECTION,
506 LA_COUNTER_PARAGRAPH,
507 LA_COUNTER_SUBPARAGRAPH,
516 void LyXLayout::readLabelType(LyXLex & lexrc)
518 keyword_item labelTypeTags[] = {
519 { "bibliography", LA_BIBLIO },
520 { "centered_top_environment", LA_CENTERED_TOP_ENVIRONMENT },
521 { "counter_chapter", LA_COUNTER_CHAPTER },
522 { "counter_enumi", LA_COUNTER_ENUMI },
523 { "counter_enumii", LA_COUNTER_ENUMII },
524 { "counter_enumiii", LA_COUNTER_ENUMIII },
525 { "counter_enumiv", LA_COUNTER_ENUMIV },
526 { "counter_paragraph", LA_COUNTER_PARAGRAPH },
527 { "counter_section", LA_COUNTER_SECTION },
528 { "counter_subparagraph", LA_COUNTER_SUBPARAGRAPH },
529 { "counter_subsection", LA_COUNTER_SUBSECTION },
530 { "counter_subsubsection", LA_COUNTER_SUBSUBSECTION },
531 { "manual", LA_MANUAL },
532 { "no_label", LA_NO_LABEL },
533 { "sensitive", LA_SENSITIVE },
534 { "static", LA_STATIC },
535 { "top_environment", LA_TOP_ENVIRONMENT }
538 pushpophelper pph(lexrc, labelTypeTags, LA_BIBLIO);
539 int le = lexrc.lex();
541 case LyXLex::LEX_UNDEF:
542 lexrc.printError("Unknown labeltype tag `$$Token'");
546 switch (static_cast<LabelTypeTags>(le)) {
548 labeltype = LABEL_NO_LABEL;
551 labeltype = LABEL_MANUAL;
553 case LA_TOP_ENVIRONMENT:
554 labeltype = LABEL_TOP_ENVIRONMENT;
556 case LA_CENTERED_TOP_ENVIRONMENT:
557 labeltype = LABEL_CENTERED_TOP_ENVIRONMENT;
560 labeltype = LABEL_STATIC;
563 labeltype = LABEL_SENSITIVE;
565 case LA_COUNTER_CHAPTER:
566 labeltype = LABEL_COUNTER_CHAPTER;
568 case LA_COUNTER_SECTION:
569 labeltype = LABEL_COUNTER_SECTION;
571 case LA_COUNTER_SUBSECTION:
572 labeltype = LABEL_COUNTER_SUBSECTION;
574 case LA_COUNTER_SUBSUBSECTION:
575 labeltype = LABEL_COUNTER_SUBSUBSECTION;
577 case LA_COUNTER_PARAGRAPH:
578 labeltype = LABEL_COUNTER_PARAGRAPH;
580 case LA_COUNTER_SUBPARAGRAPH:
581 labeltype = LABEL_COUNTER_SUBPARAGRAPH;
583 case LA_COUNTER_ENUMI:
584 labeltype = LABEL_COUNTER_ENUMI;
586 case LA_COUNTER_ENUMII:
587 labeltype = LABEL_COUNTER_ENUMII;
589 case LA_COUNTER_ENUMIII:
590 labeltype = LABEL_COUNTER_ENUMIII;
592 case LA_COUNTER_ENUMIV:
593 labeltype = LABEL_COUNTER_ENUMIV;
596 labeltype = LABEL_BIBLIO;
604 keyword_item endlabelTypeTags[] = {
605 { "box", END_LABEL_BOX },
606 { "filled_box", END_LABEL_FILLED_BOX },
607 { "no_label", END_LABEL_NO_LABEL },
608 { "static", END_LABEL_STATIC }
614 void LyXLayout::readEndLabelType(LyXLex & lexrc)
616 pushpophelper pph(lexrc, endlabelTypeTags,
617 END_LABEL_ENUM_LAST-END_LABEL_ENUM_FIRST+1);
618 int le = lexrc.lex();
620 case LyXLex::LEX_UNDEF:
621 lexrc.printError("Unknown labeltype tag `$$Token'");
623 case END_LABEL_STATIC:
625 case END_LABEL_FILLED_BOX:
626 case END_LABEL_NO_LABEL:
627 endlabeltype = static_cast<LYX_END_LABEL_TYPES>(le);
630 lyxerr << "Unhandled value " << le
631 << " in LyXLayout::readEndLabelType." << endl;
637 void LyXLayout::readMargin(LyXLex & lexrc)
639 keyword_item marginTags[] = {
640 { "dynamic", MARGIN_DYNAMIC },
641 { "first_dynamic", MARGIN_FIRST_DYNAMIC },
642 { "manual", MARGIN_MANUAL },
643 { "right_address_box", MARGIN_RIGHT_ADDRESS_BOX },
644 { "static", MARGIN_STATIC }
647 pushpophelper pph(lexrc, marginTags, MARGIN_RIGHT_ADDRESS_BOX);
649 int le = lexrc.lex();
651 case LyXLex::LEX_UNDEF:
652 lexrc.printError("Unknown margin type tag `$$Token'");
657 case MARGIN_FIRST_DYNAMIC:
658 case MARGIN_RIGHT_ADDRESS_BOX:
659 margintype = static_cast<LYX_MARGIN_TYPE>(le);
662 lyxerr << "Unhandled value " << le
663 << " in LyXLayout::readMargin." << endl;
669 void LyXLayout::readLatexType(LyXLex & lexrc)
671 keyword_item latexTypeTags[] = {
672 { "command", LATEX_COMMAND },
673 { "environment", LATEX_ENVIRONMENT },
674 { "item_environment", LATEX_ITEM_ENVIRONMENT },
675 { "list_environment", LATEX_LIST_ENVIRONMENT },
676 { "paragraph", LATEX_PARAGRAPH }
679 pushpophelper pph(lexrc, latexTypeTags, LATEX_LIST_ENVIRONMENT);
680 int le = lexrc.lex();
682 case LyXLex::LEX_UNDEF:
683 lexrc.printError("Unknown latextype tag `$$Token'");
685 case LATEX_PARAGRAPH:
687 case LATEX_ENVIRONMENT:
688 case LATEX_ITEM_ENVIRONMENT:
689 case LATEX_LIST_ENVIRONMENT:
690 latextype = static_cast<LYX_LATEX_TYPES>(le);
693 lyxerr << "Unhandled value " << le
694 << " in LyXLayout::readLatexType." << endl;
701 ST_SPACING_SINGLE = 1,
708 void LyXLayout::readSpacing(LyXLex & lexrc)
710 keyword_item spacingTags[] = {
711 {"double", ST_SPACING_DOUBLE },
712 {"onehalf", ST_SPACING_ONEHALF },
713 {"other", ST_OTHER },
714 {"single", ST_SPACING_SINGLE }
717 pushpophelper pph(lexrc, spacingTags, ST_OTHER);
718 int le = lexrc.lex();
720 case LyXLex::LEX_UNDEF:
721 lexrc.printError("Unknown spacing token `$$Token'");
725 switch (static_cast<SpacingTags>(le)) {
726 case ST_SPACING_SINGLE:
727 spacing.set(Spacing::Single);
729 case ST_SPACING_ONEHALF:
730 spacing.set(Spacing::Onehalf);
732 case ST_SPACING_DOUBLE:
733 spacing.set(Spacing::Double);
737 spacing.set(Spacing::Other, lexrc.GetFloat());
743 /* ******************************************************************* */
745 LyXTextClass::LyXTextClass(string const & fn, string const & cln,
747 : name_(fn), latexname_(cln), description_(desc)
754 pagestyle_ = "default";
755 maxcounter_ = LABEL_COUNTER_CHAPTER;
756 defaultfont_ = LyXFont(LyXFont::ALL_SANE);
757 opt_fontsize_ = "10|11|12";
758 opt_pagestyle_ = "empty|plain|headings|fancy";
764 bool LyXTextClass::do_readStyle(LyXLex & lexrc, LyXLayout & lay)
766 lyxerr[Debug::TCLASS] << "Reading style " << lay.name() << endl;
767 if (!lay.Read(lexrc, *this)) {
769 lay.resfont = lay.font;
770 lay.resfont.realize(defaultfont());
771 lay.reslabelfont = lay.labelfont;
772 lay.reslabelfont.realize(defaultfont());
773 return false; // no errors
775 lyxerr << "Error parsing style `" << lay.name() << "'" << endl;
802 // Reads a textclass structure from file.
803 bool LyXTextClass::Read(string const & filename, bool merge)
805 keyword_item textClassTags[] = {
806 { "classoptions", TC_CLASSOPTIONS },
807 { "columns", TC_COLUMNS },
808 { "defaultfont", TC_DEFAULTFONT },
809 { "input", TC_INPUT },
810 { "leftmargin", TC_LEFTMARGIN },
811 { "maxcounter", TC_MAXCOUNTER },
812 { "nostyle", TC_NOSTYLE },
813 { "outputtype", TC_OUTPUTTYPE },
814 { "pagestyle", TC_PAGESTYLE },
815 { "preamble", TC_PREAMBLE },
816 { "providesamsmath", TC_PROVIDESAMSMATH },
817 { "providesmakeidx", TC_PROVIDESMAKEIDX },
818 { "providesurl", TC_PROVIDESURL },
819 { "rightmargin", TC_RIGHTMARGIN },
820 { "secnumdepth", TC_SECNUMDEPTH },
821 { "sides", TC_SIDES },
822 { "style", TC_STYLE },
823 { "tocdepth", TC_TOCDEPTH }
827 lyxerr[Debug::TCLASS] << "Reading textclass "
828 << MakeDisplayPath(filename)
831 lyxerr[Debug::TCLASS] << "Reading input file "
832 << MakeDisplayPath(filename)
835 LyXLex lexrc(textClassTags, TC_RIGHTMARGIN);
838 lexrc.setFile(filename);
839 if (!lexrc.IsOK()) error = true;
842 while (lexrc.IsOK() && !error) {
843 int le = lexrc.lex();
845 case LyXLex::LEX_FEOF:
848 case LyXLex::LEX_UNDEF:
849 lexrc.printError("Unknown TextClass tag `$$Token'");
854 switch (static_cast<TextClassTags>(le)) {
855 case TC_OUTPUTTYPE: // output type definition
856 readOutputType(lexrc);
859 case TC_INPUT: // Include file
861 string tmp = LibFileSearch("layouts",
865 if (Read(tmp, true)) {
866 lexrc.printError("Error reading input"
875 string name = subst(lexrc.GetString(),
877 if (hasLayout(name)) {
878 LyXLayout & lay = GetLayout(name);
879 error = do_readStyle(lexrc, lay);
883 if (!(error = do_readStyle(lexrc, lay)))
884 layoutlist.push_back(lay);
888 lexrc.printError("No name given for style: `$$Token'.");
895 string style = subst(lexrc.GetString(),
897 if (!delete_layout(style))
898 lexrc.printError("Cannot delete style"
905 columns_ = lexrc.GetInteger();
910 switch (lexrc.GetInteger()) {
911 case 1: sides_ = OneSide; break;
912 case 2: sides_ = TwoSides; break;
914 lyxerr << "Impossible number of page"
915 " sides, setting to one."
925 pagestyle_ = strip(lexrc.GetString());
929 defaultfont_.lyxRead(lexrc);
930 if (!defaultfont_.resolved()) {
931 lexrc.printError("Warning: defaultfont should "
932 "be fully instantiated!");
933 defaultfont_.realize(LyXFont(LyXFont::ALL_SANE));
938 readMaxCounter(lexrc);
943 secnumdepth_ = lexrc.GetInteger();
948 tocdepth_ = lexrc.GetInteger();
951 // First step to support options
952 case TC_CLASSOPTIONS:
953 readClassOptions(lexrc);
957 preamble_ = lexrc.getLongString("EndPreamble");
960 case TC_PROVIDESAMSMATH:
961 if (lexrc.next() && lexrc.GetInteger())
962 provides_ |= amsmath;
965 case TC_PROVIDESMAKEIDX:
966 if (lexrc.next() && lexrc.GetInteger())
967 provides_ |= makeidx;
971 if (lexrc.next() && lexrc.GetInteger())
975 case TC_LEFTMARGIN: // left margin type
977 leftmargin_ = lexrc.GetString();
980 case TC_RIGHTMARGIN: // right margin type
982 rightmargin_ = lexrc.GetString();
987 if (!merge) { // we are at top level here.
988 lyxerr[Debug::TCLASS] << "Finished reading textclass "
989 << MakeDisplayPath(filename)
992 lyxerr[Debug::TCLASS] << "Finished reading input file "
993 << MakeDisplayPath(filename)
1000 void LyXTextClass::readOutputType(LyXLex & lexrc)
1002 keyword_item outputTypeTags[] = {
1003 { "docbook", DOCBOOK },
1005 { "linuxdoc", LINUXDOC },
1006 { "literate", LITERATE }
1009 pushpophelper pph(lexrc, outputTypeTags, LITERATE);
1011 int le = lexrc.lex();
1013 case LyXLex::LEX_UNDEF:
1014 lexrc.printError("Unknown output type `$$Token'");
1020 outputType_ = static_cast<OutputType>(le);
1023 lyxerr << "Unhandled value " << le
1024 << " in LyXTextClass::readOutputType." << endl;
1031 enum MaxCounterTags {
1032 MC_COUNTER_CHAPTER = 1,
1034 MC_COUNTER_SUBSECTION,
1035 MC_COUNTER_SUBSUBSECTION,
1036 MC_COUNTER_PARAGRAPH,
1037 MC_COUNTER_SUBPARAGRAPH,
1045 void LyXTextClass::readMaxCounter(LyXLex & lexrc)
1047 keyword_item maxCounterTags[] = {
1048 {"counter_chapter", MC_COUNTER_CHAPTER },
1049 {"counter_enumi", MC_COUNTER_ENUMI },
1050 {"counter_enumii", MC_COUNTER_ENUMII },
1051 {"counter_enumiii", MC_COUNTER_ENUMIII },
1052 {"counter_enumiv", MC_COUNTER_ENUMIV },
1053 {"counter_paragraph", MC_COUNTER_PARAGRAPH },
1054 {"counter_section", MC_COUNTER_SECTION },
1055 {"counter_subparagraph", MC_COUNTER_SUBPARAGRAPH },
1056 {"counter_subsection", MC_COUNTER_SUBSECTION },
1057 {"counter_subsubsection", MC_COUNTER_SUBSUBSECTION }
1060 pushpophelper pph(lexrc, maxCounterTags, MC_COUNTER_ENUMIV);
1061 int le = lexrc.lex();
1063 case LyXLex::LEX_UNDEF:
1064 lexrc.printError("Unknown MaxCounter tag `$$Token'");
1068 switch (static_cast<MaxCounterTags>(le)) {
1069 case MC_COUNTER_CHAPTER:
1070 maxcounter_ = LABEL_COUNTER_CHAPTER;
1072 case MC_COUNTER_SECTION:
1073 maxcounter_ = LABEL_COUNTER_SECTION;
1075 case MC_COUNTER_SUBSECTION:
1076 maxcounter_ = LABEL_COUNTER_SUBSECTION;
1078 case MC_COUNTER_SUBSUBSECTION:
1079 maxcounter_ = LABEL_COUNTER_SUBSUBSECTION;
1081 case MC_COUNTER_PARAGRAPH:
1082 maxcounter_ = LABEL_COUNTER_PARAGRAPH;
1084 case MC_COUNTER_SUBPARAGRAPH:
1085 maxcounter_ = LABEL_COUNTER_SUBPARAGRAPH;
1087 case MC_COUNTER_ENUMI:
1088 maxcounter_ = LABEL_COUNTER_ENUMI;
1090 case MC_COUNTER_ENUMII:
1091 maxcounter_ = LABEL_COUNTER_ENUMII;
1093 case MC_COUNTER_ENUMIII:
1094 maxcounter_ = LABEL_COUNTER_ENUMIII;
1096 case MC_COUNTER_ENUMIV:
1097 maxcounter_ = LABEL_COUNTER_ENUMIV;
1103 enum ClassOptionsTags {
1111 void LyXTextClass::readClassOptions(LyXLex & lexrc)
1113 keyword_item classOptionsTags[] = {
1115 {"fontsize", CO_FONTSIZE },
1116 {"other", CO_OTHER },
1117 {"pagestyle", CO_PAGESTYLE }
1120 lexrc.pushTable(classOptionsTags, CO_END);
1121 bool getout = false;
1122 while (!getout && lexrc.IsOK()) {
1123 int le = lexrc.lex();
1125 case LyXLex::LEX_UNDEF:
1126 lexrc.printError("Unknown ClassOption tag `$$Token'");
1130 switch (static_cast<ClassOptionsTags>(le)) {
1133 opt_fontsize_ = strip(lexrc.GetString());
1137 opt_pagestyle_ = strip(lexrc.GetString());
1141 options_ = lexrc.GetString();
1152 bool LyXTextClass::hasLayout(string const & name) const
1154 return find_if(layoutlist.begin(), layoutlist.end(),
1155 compare_memfun(&LyXLayout::name, name))
1156 != layoutlist.end();
1160 LyXLayout const & LyXTextClass::GetLayout (string const & name) const
1162 LayoutList::const_iterator cit =
1163 find_if(layoutlist.begin(),
1165 compare_memfun(&LyXLayout::name, name));
1166 Assert(cit != layoutlist.end()); // we require the name to exist
1171 LyXLayout & LyXTextClass::GetLayout(string const & name)
1173 LayoutList::iterator it =
1174 find_if(layoutlist.begin(),
1176 compare_memfun(&LyXLayout::name, name));
1177 Assert(it != layoutlist.end()); // we require the name to exist
1182 bool LyXTextClass::delete_layout(string const & name)
1184 LayoutList::iterator it =
1185 remove_if(layoutlist.begin(), layoutlist.end(),
1186 compare_memfun(&LyXLayout::name, name));
1187 LayoutList::iterator end = layoutlist.end();
1188 bool const ret = (it != end);
1189 layoutlist.erase(it, end);
1194 // Load textclass info if not loaded yet
1195 void LyXTextClass::load()
1200 string const real_file = LibFileSearch("layouts", name_, "layout");
1202 if (Read(real_file)) {
1203 lyxerr << "Error reading `"
1204 << MakeDisplayPath(real_file)
1205 << "'\n(Check `" << name_
1206 << "')\nCheck your installation and "
1207 "try Options/Reconfigure..." << endl;
1213 //////////////////////////////////////////
1215 // Gets textclass number from name
1216 pair<bool, LyXTextClassList::size_type> const
1217 LyXTextClassList::NumberOfClass(string const & textclass) const
1219 ClassList::const_iterator cit =
1220 find_if(classlist.begin(), classlist.end(),
1221 compare_memfun(&LyXTextClass::name, textclass));
1222 return cit != classlist.end() ?
1223 make_pair(true, size_type(cit - classlist.begin())) :
1224 make_pair(false, size_type(0));
1228 // Gets layout structure from style number and textclass number
1230 LyXTextClassList::Style(LyXTextClassList::size_type textclass,
1231 LyXTextClass::size_type layout) const
1233 classlist[textclass].load();
1234 if (layout < classlist[textclass].numLayouts())
1235 return classlist[textclass][layout];
1236 return classlist[textclass][0];
1240 // Gets layout number from name and textclass number
1241 pair<bool, LyXTextClass::size_type> const
1242 LyXTextClassList::NumberOfLayout(LyXTextClassList::size_type textclass,
1243 string const & name) const
1245 classlist[textclass].load();
1246 for (unsigned int i = 0; i < classlist[textclass].numLayouts(); ++i) {
1247 if (classlist[textclass][i].name() == name)
1248 return make_pair(true, i);
1250 if (name == "dummy")
1251 return make_pair(true, LyXTextClassList::size_type(LYX_DUMMY_LAYOUT));
1252 return make_pair(false, LyXTextClass::size_type(0)); // not found
1256 // Gets a layout (style) name from layout number and textclass number
1258 LyXTextClassList::NameOfLayout(LyXTextClassList::size_type textclass,
1259 LyXTextClass::size_type layout) const
1261 static string dummy("dummy");
1262 classlist[textclass].load();
1263 if (layout < classlist[textclass].numLayouts())
1264 return classlist[textclass][layout].name();
1269 // Gets a textclass name from number
1271 LyXTextClassList::NameOfClass(LyXTextClassList::size_type number) const
1273 static string dummy("dummy");
1274 if (classlist.size() == 0) {
1277 Assert(number < classlist.size());
1278 return classlist[number].name();
1282 // Gets a textclass latexname from number
1284 LyXTextClassList::LatexnameOfClass(LyXTextClassList::size_type number) const
1286 static string dummy("dummy");
1287 classlist[number].load();
1288 if (classlist.size() == 0) {
1291 Assert(number < classlist.size());
1292 return classlist[number].latexname();
1296 // Gets a textclass description from number
1298 LyXTextClassList::DescOfClass(LyXTextClassList::size_type number) const
1300 static string dummy("dummy");
1301 if (classlist.size() == 0) {
1304 Assert(number < classlist.size());
1305 return classlist[number].description();
1309 // Gets a textclass structure from number
1310 LyXTextClass const &
1311 LyXTextClassList::TextClass(LyXTextClassList::size_type textclass) const
1313 classlist[textclass].load();
1314 if (textclass < classlist.size())
1315 return classlist[textclass];
1317 return classlist[0];
1321 void LyXTextClassList::Add(LyXTextClass const & t)
1323 classlist.push_back(t);
1327 // used when sorting the textclass list.
1328 class less_textclass_desc {
1330 int operator()(LyXTextClass const & tc1, LyXTextClass const & tc2) {
1331 return tc1.description() < tc2.description();
1336 // Reads LyX textclass definitions according to textclass config file
1337 bool LyXTextClassList::Read ()
1340 string real_file = LibFileSearch("", "textclass.lst");
1341 lyxerr[Debug::TCLASS] << "Reading textclasses from `"
1342 << real_file << "'" << endl;
1344 if (real_file.empty()) {
1345 lyxerr << "LyXTextClassList::Read: unable to find "
1346 "textclass file `" << MakeDisplayPath(real_file, 1000)
1347 << "'. Exiting." << endl;
1349 WriteAlert(_("LyX wasn't able to find its layout descriptions!"),
1350 _("Check that the file \"textclass.lst\""),
1351 _("is installed correctly. Sorry, has to exit :-("));
1353 // This causes LyX to end... Not a desirable behaviour. Lgb
1354 // What do you propose? That the user gets a file dialog
1355 // and is allowed to hunt for the file? (Asger)
1356 // more that we have a layout for minimal.cls statically
1357 // compiled in... (Lgb)
1360 if (!lex.setFile(real_file)) {
1361 lyxerr << "LyXTextClassList::Read: "
1362 "lyxlex was not able to set file: "
1363 << real_file << endl;
1367 lyxerr << "LyXTextClassList::Read: unable to open "
1368 "textclass file `" << MakeDisplayPath(real_file, 1000)
1369 << "'\nCheck your installation. LyX can't continue."
1373 bool finished = false;
1374 string fname, clname, desc;
1375 // Parse config-file
1376 lyxerr[Debug::TCLASS] << "Starting parsing of textclass.lst" << endl;
1377 while (lex.IsOK() && !finished) {
1378 lyxerr[Debug::TCLASS] << "\tline by line" << endl;
1379 switch (lex.lex()) {
1380 case LyXLex::LEX_FEOF:
1384 fname = lex.GetString();
1385 lyxerr[Debug::TCLASS] << "Fname: " << fname << endl;
1387 clname = lex.GetString();
1388 lyxerr[Debug::TCLASS]
1389 << "Clname: " << clname << endl;
1391 desc = lex.GetString();
1392 lyxerr[Debug::TCLASS]
1393 << "Desc: " << desc << endl;
1394 // This code is run when we have
1395 // fname, clname and desc
1396 LyXTextClass tmpl(fname,
1400 debugging(Debug::TCLASS)) {
1408 lyxerr[Debug::TCLASS] << "End of parsing of textclass.lst" << endl;
1410 if (classlist.size() == 0) {
1411 lyxerr << "LyXTextClassList::Read: no textclasses found!"
1413 WriteAlert(_("LyX wasn't able to find any layout description!"),
1414 _("Check the contents of the file \"textclass.lst\""),
1415 _("Sorry, has to exit :-("));
1418 // Ok everything loaded ok, now sort the list.
1419 sort(classlist.begin(), classlist.end(), less_textclass_desc());
1425 Returns false if this fails
1428 LyXTextClassList::Load (LyXTextClassList::size_type number) const
1431 if (number < classlist.size()) {
1432 classlist[number].load();
1433 if (classlist[number].numLayouts() == 0) {
1443 std::ostream & operator<<(std::ostream & os, LyXTextClass::PageSides p)
1446 case LyXTextClass::OneSide:
1449 case LyXTextClass::TwoSides: