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;
601 static keyword_item endlabelTypeTags[] = {
602 { "box", END_LABEL_BOX },
603 { "filled_box", END_LABEL_FILLED_BOX },
604 { "no_label", END_LABEL_NO_LABEL },
605 { "static", END_LABEL_STATIC }
608 void LyXLayout::readEndLabelType(LyXLex & lexrc)
610 pushpophelper pph(lexrc, endlabelTypeTags,
611 END_LABEL_ENUM_LAST-END_LABEL_ENUM_FIRST+1);
612 int le = lexrc.lex();
614 case LyXLex::LEX_UNDEF:
615 lexrc.printError("Unknown labeltype tag `$$Token'");
617 case END_LABEL_STATIC:
619 case END_LABEL_FILLED_BOX:
620 case END_LABEL_NO_LABEL:
621 endlabeltype = static_cast<LYX_END_LABEL_TYPES>(le);
624 lyxerr << "Unhandled value " << le
625 << " in LyXLayout::readEndLabelType." << endl;
631 void LyXLayout::readMargin(LyXLex & lexrc)
633 keyword_item marginTags[] = {
634 { "dynamic", MARGIN_DYNAMIC },
635 { "first_dynamic", MARGIN_FIRST_DYNAMIC },
636 { "manual", MARGIN_MANUAL },
637 { "right_address_box", MARGIN_RIGHT_ADDRESS_BOX },
638 { "static", MARGIN_STATIC }
641 pushpophelper pph(lexrc, marginTags, MARGIN_RIGHT_ADDRESS_BOX);
643 int le = lexrc.lex();
645 case LyXLex::LEX_UNDEF:
646 lexrc.printError("Unknown margin type tag `$$Token'");
651 case MARGIN_FIRST_DYNAMIC:
652 case MARGIN_RIGHT_ADDRESS_BOX:
653 margintype = static_cast<LYX_MARGIN_TYPE>(le);
656 lyxerr << "Unhandled value " << le
657 << " in LyXLayout::readMargin." << endl;
663 void LyXLayout::readLatexType(LyXLex & lexrc)
665 keyword_item latexTypeTags[] = {
666 { "command", LATEX_COMMAND },
667 { "environment", LATEX_ENVIRONMENT },
668 { "item_environment", LATEX_ITEM_ENVIRONMENT },
669 { "list_environment", LATEX_LIST_ENVIRONMENT },
670 { "paragraph", LATEX_PARAGRAPH }
673 pushpophelper pph(lexrc, latexTypeTags, LATEX_LIST_ENVIRONMENT);
674 int le = lexrc.lex();
676 case LyXLex::LEX_UNDEF:
677 lexrc.printError("Unknown latextype tag `$$Token'");
679 case LATEX_PARAGRAPH:
681 case LATEX_ENVIRONMENT:
682 case LATEX_ITEM_ENVIRONMENT:
683 case LATEX_LIST_ENVIRONMENT:
684 latextype = static_cast<LYX_LATEX_TYPES>(le);
687 lyxerr << "Unhandled value " << le
688 << " in LyXLayout::readLatexType." << endl;
695 ST_SPACING_SINGLE = 1,
702 void LyXLayout::readSpacing(LyXLex & lexrc)
704 keyword_item spacingTags[] = {
705 {"double", ST_SPACING_DOUBLE },
706 {"onehalf", ST_SPACING_ONEHALF },
707 {"other", ST_OTHER },
708 {"single", ST_SPACING_SINGLE }
711 pushpophelper pph(lexrc, spacingTags, ST_OTHER);
712 int le = lexrc.lex();
714 case LyXLex::LEX_UNDEF:
715 lexrc.printError("Unknown spacing token `$$Token'");
719 switch(static_cast<SpacingTags>(le)) {
720 case ST_SPACING_SINGLE:
721 spacing.set(Spacing::Single);
723 case ST_SPACING_ONEHALF:
724 spacing.set(Spacing::Onehalf);
726 case ST_SPACING_DOUBLE:
727 spacing.set(Spacing::Double);
731 spacing.set(Spacing::Other, lexrc.GetFloat());
737 /* ******************************************************************* */
739 LyXTextClass::LyXTextClass(string const & fn, string const & cln,
741 : name_(fn), latexname_(cln), description_(desc)
748 pagestyle_ = "default";
749 maxcounter_ = LABEL_COUNTER_CHAPTER;
750 defaultfont_ = LyXFont(LyXFont::ALL_SANE);
751 opt_fontsize_ = "10|11|12";
752 opt_pagestyle_ = "empty|plain|headings|fancy";
758 bool LyXTextClass::do_readStyle(LyXLex & lexrc, LyXLayout & lay)
760 lyxerr[Debug::TCLASS] << "Reading style " << lay.name() << endl;
761 if (!lay.Read(lexrc, *this)) {
763 lay.resfont = lay.font;
764 lay.resfont.realize(defaultfont());
765 lay.reslabelfont = lay.labelfont;
766 lay.reslabelfont.realize(defaultfont());
767 return false; // no errors
769 lyxerr << "Error parsing style `" << lay.name() << "'" << endl;
796 // Reads a textclass structure from file.
797 bool LyXTextClass::Read(string const & filename, bool merge)
799 keyword_item textClassTags[] = {
800 { "classoptions", TC_CLASSOPTIONS },
801 { "columns", TC_COLUMNS },
802 { "defaultfont", TC_DEFAULTFONT },
803 { "input", TC_INPUT },
804 { "leftmargin", TC_LEFTMARGIN },
805 { "maxcounter", TC_MAXCOUNTER },
806 { "nostyle", TC_NOSTYLE },
807 { "outputtype", TC_OUTPUTTYPE },
808 { "pagestyle", TC_PAGESTYLE },
809 { "preamble", TC_PREAMBLE },
810 { "providesamsmath", TC_PROVIDESAMSMATH },
811 { "providesmakeidx", TC_PROVIDESMAKEIDX },
812 { "providesurl", TC_PROVIDESURL },
813 { "rightmargin", TC_RIGHTMARGIN },
814 { "secnumdepth", TC_SECNUMDEPTH },
815 { "sides", TC_SIDES },
816 { "style", TC_STYLE },
817 { "tocdepth", TC_TOCDEPTH }
821 lyxerr[Debug::TCLASS] << "Reading textclass "
822 << MakeDisplayPath(filename)
825 lyxerr[Debug::TCLASS] << "Reading input file "
826 << MakeDisplayPath(filename)
829 LyXLex lexrc(textClassTags, TC_RIGHTMARGIN);
832 lexrc.setFile(filename);
833 if (!lexrc.IsOK()) error = true;
836 while (lexrc.IsOK() && !error) {
837 int le = lexrc.lex();
839 case LyXLex::LEX_FEOF:
842 case LyXLex::LEX_UNDEF:
843 lexrc.printError("Unknown TextClass tag `$$Token'");
848 switch(static_cast<TextClassTags>(le)) {
849 case TC_OUTPUTTYPE: // output type definition
850 readOutputType(lexrc);
853 case TC_INPUT: // Include file
855 string tmp = LibFileSearch("layouts",
859 if (Read(tmp, true)) {
860 lexrc.printError("Error reading input"
869 string name = subst(lexrc.GetString(),
871 if (hasLayout(name)) {
872 LyXLayout & lay = GetLayout(name);
873 error = do_readStyle(lexrc, lay);
877 if (!(error = do_readStyle(lexrc, lay)))
878 layoutlist.push_back(lay);
882 lexrc.printError("No name given for style: `$$Token'.");
889 string style = subst(lexrc.GetString(),
891 if (!delete_layout(style))
892 lexrc.printError("Cannot delete style"
899 columns_ = lexrc.GetInteger();
904 switch(lexrc.GetInteger()) {
905 case 1: sides_ = OneSide; break;
906 case 2: sides_ = TwoSides; break;
908 lyxerr << "Impossible number of page"
909 " sides, setting to one."
919 pagestyle_ = strip(lexrc.GetString());
923 defaultfont_.lyxRead(lexrc);
924 if (!defaultfont_.resolved()) {
925 lexrc.printError("Warning: defaultfont should "
926 "be fully instantiated!");
927 defaultfont_.realize(LyXFont(LyXFont::ALL_SANE));
932 readMaxCounter(lexrc);
937 secnumdepth_ = lexrc.GetInteger();
942 tocdepth_ = lexrc.GetInteger();
945 // First step to support options
946 case TC_CLASSOPTIONS:
947 readClassOptions(lexrc);
951 preamble_ = lexrc.getLongString("EndPreamble");
954 case TC_PROVIDESAMSMATH:
955 if (lexrc.next() && lexrc.GetInteger())
956 provides_ |= amsmath;
959 case TC_PROVIDESMAKEIDX:
960 if (lexrc.next() && lexrc.GetInteger())
961 provides_ |= makeidx;
965 if (lexrc.next() && lexrc.GetInteger())
969 case TC_LEFTMARGIN: // left margin type
971 leftmargin_ = lexrc.GetString();
974 case TC_RIGHTMARGIN: // right margin type
976 rightmargin_ = lexrc.GetString();
981 if (!merge) { // we are at top level here.
982 lyxerr[Debug::TCLASS] << "Finished reading textclass "
983 << MakeDisplayPath(filename)
986 lyxerr[Debug::TCLASS] << "Finished reading input file "
987 << MakeDisplayPath(filename)
994 void LyXTextClass::readOutputType(LyXLex & lexrc)
996 keyword_item outputTypeTags[] = {
997 { "docbook", DOCBOOK },
999 { "linuxdoc", LINUXDOC },
1000 { "literate", LITERATE }
1003 pushpophelper pph(lexrc, outputTypeTags, LITERATE);
1005 int le = lexrc.lex();
1007 case LyXLex::LEX_UNDEF:
1008 lexrc.printError("Unknown output type `$$Token'");
1014 outputType_ = static_cast<OutputType>(le);
1017 lyxerr << "Unhandled value " << le
1018 << " in LyXTextClass::readOutputType." << endl;
1025 enum MaxCounterTags {
1026 MC_COUNTER_CHAPTER = 1,
1028 MC_COUNTER_SUBSECTION,
1029 MC_COUNTER_SUBSUBSECTION,
1030 MC_COUNTER_PARAGRAPH,
1031 MC_COUNTER_SUBPARAGRAPH,
1039 void LyXTextClass::readMaxCounter(LyXLex & lexrc)
1041 keyword_item maxCounterTags[] = {
1042 {"counter_chapter", MC_COUNTER_CHAPTER },
1043 {"counter_enumi", MC_COUNTER_ENUMI },
1044 {"counter_enumii", MC_COUNTER_ENUMII },
1045 {"counter_enumiii", MC_COUNTER_ENUMIII },
1046 {"counter_enumiv", MC_COUNTER_ENUMIV },
1047 {"counter_paragraph", MC_COUNTER_PARAGRAPH },
1048 {"counter_section", MC_COUNTER_SECTION },
1049 {"counter_subparagraph", MC_COUNTER_SUBPARAGRAPH },
1050 {"counter_subsection", MC_COUNTER_SUBSECTION },
1051 {"counter_subsubsection", MC_COUNTER_SUBSUBSECTION }
1054 pushpophelper pph(lexrc, maxCounterTags, MC_COUNTER_ENUMIV);
1055 int le = lexrc.lex();
1057 case LyXLex::LEX_UNDEF:
1058 lexrc.printError("Unknown MaxCounter tag `$$Token'");
1062 switch (static_cast<MaxCounterTags>(le)) {
1063 case MC_COUNTER_CHAPTER:
1064 maxcounter_ = LABEL_COUNTER_CHAPTER;
1066 case MC_COUNTER_SECTION:
1067 maxcounter_ = LABEL_COUNTER_SECTION;
1069 case MC_COUNTER_SUBSECTION:
1070 maxcounter_ = LABEL_COUNTER_SUBSECTION;
1072 case MC_COUNTER_SUBSUBSECTION:
1073 maxcounter_ = LABEL_COUNTER_SUBSUBSECTION;
1075 case MC_COUNTER_PARAGRAPH:
1076 maxcounter_ = LABEL_COUNTER_PARAGRAPH;
1078 case MC_COUNTER_SUBPARAGRAPH:
1079 maxcounter_ = LABEL_COUNTER_SUBPARAGRAPH;
1081 case MC_COUNTER_ENUMI:
1082 maxcounter_ = LABEL_COUNTER_ENUMI;
1084 case MC_COUNTER_ENUMII:
1085 maxcounter_ = LABEL_COUNTER_ENUMII;
1087 case MC_COUNTER_ENUMIII:
1088 maxcounter_ = LABEL_COUNTER_ENUMIII;
1090 case MC_COUNTER_ENUMIV:
1091 maxcounter_ = LABEL_COUNTER_ENUMIV;
1097 enum ClassOptionsTags {
1105 void LyXTextClass::readClassOptions(LyXLex & lexrc)
1107 keyword_item classOptionsTags[] = {
1109 {"fontsize", CO_FONTSIZE },
1110 {"other", CO_OTHER },
1111 {"pagestyle", CO_PAGESTYLE }
1114 lexrc.pushTable(classOptionsTags, CO_END);
1115 bool getout = false;
1116 while (!getout && lexrc.IsOK()) {
1117 int le = lexrc.lex();
1119 case LyXLex::LEX_UNDEF:
1120 lexrc.printError("Unknown ClassOption tag `$$Token'");
1124 switch (static_cast<ClassOptionsTags>(le)) {
1127 opt_fontsize_ = strip(lexrc.GetString());
1131 opt_pagestyle_ = strip(lexrc.GetString());
1135 options_ = lexrc.GetString();
1146 bool LyXTextClass::hasLayout(string const & name) const
1148 return find_if(layoutlist.begin(), layoutlist.end(),
1149 compare_memfun(&LyXLayout::name, name))
1150 != layoutlist.end();
1154 LyXLayout const & LyXTextClass::GetLayout (string const & name) const
1156 LayoutList::const_iterator cit =
1157 find_if(layoutlist.begin(),
1159 compare_memfun(&LyXLayout::name, name));
1160 Assert(cit != layoutlist.end()); // we require the name to exist
1165 LyXLayout & LyXTextClass::GetLayout(string const & name)
1167 LayoutList::iterator it =
1168 find_if(layoutlist.begin(),
1170 compare_memfun(&LyXLayout::name, name));
1171 Assert(it != layoutlist.end()); // we require the name to exist
1176 bool LyXTextClass::delete_layout(string const & name)
1178 LayoutList::iterator it =
1179 remove_if(layoutlist.begin(), layoutlist.end(),
1180 compare_memfun(&LyXLayout::name, name));
1181 LayoutList::iterator end = layoutlist.end();
1182 bool const ret = (it != end);
1183 layoutlist.erase(it, end);
1188 // Load textclass info if not loaded yet
1189 void LyXTextClass::load()
1194 string const real_file = LibFileSearch("layouts", name_, "layout");
1196 if (Read(real_file)) {
1197 lyxerr << "Error reading `"
1198 << MakeDisplayPath(real_file)
1199 << "'\n(Check `" << name_
1200 << "')\nCheck your installation and "
1201 "try Options/Reconfigure..." << endl;
1207 //////////////////////////////////////////
1209 // Gets textclass number from name
1210 pair<bool, LyXTextClassList::size_type> const
1211 LyXTextClassList::NumberOfClass(string const & textclass) const
1213 ClassList::const_iterator cit =
1214 find_if(classlist.begin(), classlist.end(),
1215 compare_memfun(&LyXTextClass::name, textclass));
1216 return cit != classlist.end() ?
1217 make_pair(true, size_type(cit - classlist.begin())) :
1218 make_pair(false, size_type(0));
1222 // Gets layout structure from style number and textclass number
1224 LyXTextClassList::Style(LyXTextClassList::size_type textclass,
1225 LyXTextClass::size_type layout) const
1227 classlist[textclass].load();
1228 if (layout < classlist[textclass].numLayouts())
1229 return classlist[textclass][layout];
1230 return classlist[textclass][0];
1234 // Gets layout number from name and textclass number
1235 pair<bool, LyXTextClass::size_type> const
1236 LyXTextClassList::NumberOfLayout(LyXTextClassList::size_type textclass,
1237 string const & name) const
1239 classlist[textclass].load();
1240 for(unsigned int i = 0; i < classlist[textclass].numLayouts(); ++i) {
1241 if (classlist[textclass][i].name() == name)
1242 return make_pair(true, i);
1244 if (name == "dummy")
1245 return make_pair(true, LyXTextClassList::size_type(LYX_DUMMY_LAYOUT));
1246 return make_pair(false, LyXTextClass::size_type(0)); // not found
1250 // Gets a layout (style) name from layout number and textclass number
1252 LyXTextClassList::NameOfLayout(LyXTextClassList::size_type textclass,
1253 LyXTextClass::size_type layout) const
1255 static string dummy("dummy");
1256 classlist[textclass].load();
1257 if (layout < classlist[textclass].numLayouts())
1258 return classlist[textclass][layout].name();
1263 // Gets a textclass name from number
1265 LyXTextClassList::NameOfClass(LyXTextClassList::size_type number) const
1267 static string dummy("dummy");
1268 if (classlist.size() == 0) {
1271 Assert(number < classlist.size());
1272 return classlist[number].name();
1276 // Gets a textclass latexname from number
1278 LyXTextClassList::LatexnameOfClass(LyXTextClassList::size_type number) const
1280 static string dummy("dummy");
1281 classlist[number].load();
1282 if (classlist.size() == 0) {
1285 Assert(number < classlist.size());
1286 return classlist[number].latexname();
1290 // Gets a textclass description from number
1292 LyXTextClassList::DescOfClass(LyXTextClassList::size_type number) const
1294 static string dummy("dummy");
1295 if (classlist.size() == 0) {
1298 Assert(number < classlist.size());
1299 return classlist[number].description();
1303 // Gets a textclass structure from number
1304 LyXTextClass const &
1305 LyXTextClassList::TextClass(LyXTextClassList::size_type textclass) const
1307 classlist[textclass].load();
1308 if (textclass < classlist.size())
1309 return classlist[textclass];
1311 return classlist[0];
1315 void LyXTextClassList::Add(LyXTextClass const & t)
1317 classlist.push_back(t);
1321 // used when sorting the textclass list.
1322 class less_textclass_desc {
1324 int operator()(LyXTextClass const & tc1, LyXTextClass const & tc2) {
1325 return tc1.description() < tc2.description();
1330 // Reads LyX textclass definitions according to textclass config file
1331 bool LyXTextClassList::Read ()
1334 string real_file = LibFileSearch("", "textclass.lst");
1335 lyxerr[Debug::TCLASS] << "Reading textclasses from `"
1336 << real_file << "'" << endl;
1338 if (real_file.empty()) {
1339 lyxerr << "LyXTextClassList::Read: unable to find "
1340 "textclass file `" << MakeDisplayPath(real_file, 1000)
1341 << "'. Exiting." << endl;
1343 WriteAlert(_("LyX wasn't able to find its layout descriptions!"),
1344 _("Check that the file \"textclass.lst\""),
1345 _("is installed correctly. Sorry, has to exit :-("));
1347 // This causes LyX to end... Not a desirable behaviour. Lgb
1348 // What do you propose? That the user gets a file dialog
1349 // and is allowed to hunt for the file? (Asger)
1350 // more that we have a layout for minimal.cls statically
1351 // compiled in... (Lgb)
1354 if (!lex.setFile(real_file)) {
1355 lyxerr << "LyXTextClassList::Read: "
1356 "lyxlex was not able to set file: "
1357 << real_file << endl;
1361 lyxerr << "LyXTextClassList::Read: unable to open "
1362 "textclass file `" << MakeDisplayPath(real_file, 1000)
1363 << "'\nCheck your installation. LyX can't continue."
1367 bool finished = false;
1368 string fname, clname, desc;
1369 // Parse config-file
1370 lyxerr[Debug::TCLASS] << "Starting parsing of textclass.lst" << endl;
1371 while (lex.IsOK() && !finished) {
1372 lyxerr[Debug::TCLASS] << "\tline by line" << endl;
1373 switch (lex.lex()) {
1374 case LyXLex::LEX_FEOF:
1378 fname = lex.GetString();
1379 lyxerr[Debug::TCLASS] << "Fname: " << fname << endl;
1381 clname = lex.GetString();
1382 lyxerr[Debug::TCLASS]
1383 << "Clname: " << clname << endl;
1385 desc = lex.GetString();
1386 lyxerr[Debug::TCLASS]
1387 << "Desc: " << desc << endl;
1388 // This code is run when we have
1389 // fname, clname and desc
1390 LyXTextClass tmpl(fname,
1394 debugging(Debug::TCLASS)) {
1402 lyxerr[Debug::TCLASS] << "End of parsing of textclass.lst" << endl;
1404 if (classlist.size() == 0) {
1405 lyxerr << "LyXTextClassList::Read: no textclasses found!"
1407 WriteAlert(_("LyX wasn't able to find any layout description!"),
1408 _("Check the contents of the file \"textclass.lst\""),
1409 _("Sorry, has to exit :-("));
1412 // Ok everything loaded ok, now sort the list.
1413 sort(classlist.begin(), classlist.end(), less_textclass_desc());
1419 Returns false if this fails
1422 LyXTextClassList::Load (LyXTextClassList::size_type number) const
1425 if (number < classlist.size()) {
1426 classlist[number].load();
1427 if (classlist[number].numLayouts() == 0) {
1437 std::ostream & operator<<(std::ostream & os, LyXTextClass::PageSides p)
1440 case LyXTextClass::OneSide:
1443 case LyXTextClass::TwoSides: