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 lay.resfont.realize(defaultfont(), default_language);
780 lay.reslabelfont = lay.labelfont;
781 lay.reslabelfont.realize(defaultfont(), default_language);
782 return false; // no errors
784 lyxerr << "Error parsing style `" << lay.name() << "'" << endl;
811 // Reads a textclass structure from file.
812 bool LyXTextClass::Read(string const & filename, bool merge)
814 keyword_item textClassTags[] = {
815 { "classoptions", TC_CLASSOPTIONS },
816 { "columns", TC_COLUMNS },
817 { "defaultfont", TC_DEFAULTFONT },
818 { "input", TC_INPUT },
819 { "leftmargin", TC_LEFTMARGIN },
820 { "maxcounter", TC_MAXCOUNTER },
821 { "nostyle", TC_NOSTYLE },
822 { "outputtype", TC_OUTPUTTYPE },
823 { "pagestyle", TC_PAGESTYLE },
824 { "preamble", TC_PREAMBLE },
825 { "providesamsmath", TC_PROVIDESAMSMATH },
826 { "providesmakeidx", TC_PROVIDESMAKEIDX },
827 { "providesurl", TC_PROVIDESURL },
828 { "rightmargin", TC_RIGHTMARGIN },
829 { "secnumdepth", TC_SECNUMDEPTH },
830 { "sides", TC_SIDES },
831 { "style", TC_STYLE },
832 { "tocdepth", TC_TOCDEPTH }
836 lyxerr[Debug::TCLASS] << "Reading textclass "
837 << MakeDisplayPath(filename)
840 lyxerr[Debug::TCLASS] << "Reading input file "
841 << MakeDisplayPath(filename)
844 LyXLex lexrc(textClassTags, TC_RIGHTMARGIN);
847 lexrc.setFile(filename);
848 if (!lexrc.isOK()) error = true;
851 while (lexrc.isOK() && !error) {
852 int le = lexrc.lex();
854 case LyXLex::LEX_FEOF:
857 case LyXLex::LEX_UNDEF:
858 lexrc.printError("Unknown TextClass tag `$$Token'");
863 switch (static_cast<TextClassTags>(le)) {
864 case TC_OUTPUTTYPE: // output type definition
865 readOutputType(lexrc);
868 case TC_INPUT: // Include file
870 string tmp = LibFileSearch("layouts",
874 if (Read(tmp, true)) {
875 lexrc.printError("Error reading input"
884 string name = subst(lexrc.getString(),
886 if (hasLayout(name)) {
887 LyXLayout & lay = GetLayout(name);
888 error = do_readStyle(lexrc, lay);
892 if (!(error = do_readStyle(lexrc, lay)))
893 layoutlist.push_back(lay);
897 lexrc.printError("No name given for style: `$$Token'.");
904 string const style = subst(lexrc.getString(),
906 if (!delete_layout(style))
907 lexrc.printError("Cannot delete style"
914 columns_ = lexrc.getInteger();
919 switch (lexrc.getInteger()) {
920 case 1: sides_ = OneSide; break;
921 case 2: sides_ = TwoSides; break;
923 lyxerr << "Impossible number of page"
924 " sides, setting to one."
934 pagestyle_ = strip(lexrc.getString());
938 defaultfont_.lyxRead(lexrc);
939 if (!defaultfont_.resolved()) {
940 lexrc.printError("Warning: defaultfont should "
941 "be fully instantiated!");
942 defaultfont_.realize(LyXFont(LyXFont::ALL_SANE),
948 readMaxCounter(lexrc);
953 secnumdepth_ = lexrc.getInteger();
958 tocdepth_ = lexrc.getInteger();
961 // First step to support options
962 case TC_CLASSOPTIONS:
963 readClassOptions(lexrc);
967 preamble_ = lexrc.getLongString("EndPreamble");
970 case TC_PROVIDESAMSMATH:
971 if (lexrc.next() && lexrc.getInteger())
972 provides_ |= amsmath;
975 case TC_PROVIDESMAKEIDX:
976 if (lexrc.next() && lexrc.getInteger())
977 provides_ |= makeidx;
981 if (lexrc.next() && lexrc.getInteger())
985 case TC_LEFTMARGIN: // left margin type
987 leftmargin_ = lexrc.getString();
990 case TC_RIGHTMARGIN: // right margin type
992 rightmargin_ = lexrc.getString();
997 if (!merge) { // we are at top level here.
998 lyxerr[Debug::TCLASS] << "Finished reading textclass "
999 << MakeDisplayPath(filename)
1002 lyxerr[Debug::TCLASS] << "Finished reading input file "
1003 << MakeDisplayPath(filename)
1010 void LyXTextClass::readOutputType(LyXLex & lexrc)
1012 keyword_item outputTypeTags[] = {
1013 { "docbook", DOCBOOK },
1015 { "linuxdoc", LINUXDOC },
1016 { "literate", LITERATE }
1019 pushpophelper pph(lexrc, outputTypeTags, LITERATE);
1021 int le = lexrc.lex();
1023 case LyXLex::LEX_UNDEF:
1024 lexrc.printError("Unknown output type `$$Token'");
1030 outputType_ = static_cast<OutputType>(le);
1033 lyxerr << "Unhandled value " << le
1034 << " in LyXTextClass::readOutputType." << endl;
1041 enum MaxCounterTags {
1042 MC_COUNTER_CHAPTER = 1,
1044 MC_COUNTER_SUBSECTION,
1045 MC_COUNTER_SUBSUBSECTION,
1046 MC_COUNTER_PARAGRAPH,
1047 MC_COUNTER_SUBPARAGRAPH,
1055 void LyXTextClass::readMaxCounter(LyXLex & lexrc)
1057 keyword_item maxCounterTags[] = {
1058 {"counter_chapter", MC_COUNTER_CHAPTER },
1059 {"counter_enumi", MC_COUNTER_ENUMI },
1060 {"counter_enumii", MC_COUNTER_ENUMII },
1061 {"counter_enumiii", MC_COUNTER_ENUMIII },
1062 {"counter_enumiv", MC_COUNTER_ENUMIV },
1063 {"counter_paragraph", MC_COUNTER_PARAGRAPH },
1064 {"counter_section", MC_COUNTER_SECTION },
1065 {"counter_subparagraph", MC_COUNTER_SUBPARAGRAPH },
1066 {"counter_subsection", MC_COUNTER_SUBSECTION },
1067 {"counter_subsubsection", MC_COUNTER_SUBSUBSECTION }
1070 pushpophelper pph(lexrc, maxCounterTags, MC_COUNTER_ENUMIV);
1071 int le = lexrc.lex();
1073 case LyXLex::LEX_UNDEF:
1074 lexrc.printError("Unknown MaxCounter tag `$$Token'");
1078 switch (static_cast<MaxCounterTags>(le)) {
1079 case MC_COUNTER_CHAPTER:
1080 maxcounter_ = LABEL_COUNTER_CHAPTER;
1082 case MC_COUNTER_SECTION:
1083 maxcounter_ = LABEL_COUNTER_SECTION;
1085 case MC_COUNTER_SUBSECTION:
1086 maxcounter_ = LABEL_COUNTER_SUBSECTION;
1088 case MC_COUNTER_SUBSUBSECTION:
1089 maxcounter_ = LABEL_COUNTER_SUBSUBSECTION;
1091 case MC_COUNTER_PARAGRAPH:
1092 maxcounter_ = LABEL_COUNTER_PARAGRAPH;
1094 case MC_COUNTER_SUBPARAGRAPH:
1095 maxcounter_ = LABEL_COUNTER_SUBPARAGRAPH;
1097 case MC_COUNTER_ENUMI:
1098 maxcounter_ = LABEL_COUNTER_ENUMI;
1100 case MC_COUNTER_ENUMII:
1101 maxcounter_ = LABEL_COUNTER_ENUMII;
1103 case MC_COUNTER_ENUMIII:
1104 maxcounter_ = LABEL_COUNTER_ENUMIII;
1106 case MC_COUNTER_ENUMIV:
1107 maxcounter_ = LABEL_COUNTER_ENUMIV;
1113 enum ClassOptionsTags {
1121 void LyXTextClass::readClassOptions(LyXLex & lexrc)
1123 keyword_item classOptionsTags[] = {
1125 {"fontsize", CO_FONTSIZE },
1126 {"other", CO_OTHER },
1127 {"pagestyle", CO_PAGESTYLE }
1130 lexrc.pushTable(classOptionsTags, CO_END);
1131 bool getout = false;
1132 while (!getout && lexrc.isOK()) {
1133 int le = lexrc.lex();
1135 case LyXLex::LEX_UNDEF:
1136 lexrc.printError("Unknown ClassOption tag `$$Token'");
1140 switch (static_cast<ClassOptionsTags>(le)) {
1143 opt_fontsize_ = strip(lexrc.getString());
1147 opt_pagestyle_ = strip(lexrc.getString());
1151 options_ = lexrc.getString();
1162 bool LyXTextClass::hasLayout(string const & name) const
1164 return find_if(layoutlist.begin(), layoutlist.end(),
1165 lyx::compare_memfun(&LyXLayout::name, name))
1166 != layoutlist.end();
1170 LyXLayout const & LyXTextClass::GetLayout (string const & name) const
1172 LayoutList::const_iterator cit =
1173 find_if(layoutlist.begin(),
1175 lyx::compare_memfun(&LyXLayout::name, name));
1176 lyx::Assert(cit != layoutlist.end()); // we require the name to exist
1181 LyXLayout & LyXTextClass::GetLayout(string const & name)
1183 LayoutList::iterator it =
1184 find_if(layoutlist.begin(),
1186 lyx::compare_memfun(&LyXLayout::name, name));
1187 lyx::Assert(it != layoutlist.end()); // we require the name to exist
1192 bool LyXTextClass::delete_layout(string const & name)
1194 LayoutList::iterator it =
1195 remove_if(layoutlist.begin(), layoutlist.end(),
1196 lyx::compare_memfun(&LyXLayout::name, name));
1197 LayoutList::iterator end = layoutlist.end();
1198 bool const ret = (it != end);
1199 layoutlist.erase(it, end);
1204 // Load textclass info if not loaded yet
1205 void LyXTextClass::load()
1210 string const real_file = LibFileSearch("layouts", name_, "layout");
1212 if (Read(real_file)) {
1213 lyxerr << "Error reading `"
1214 << MakeDisplayPath(real_file)
1215 << "'\n(Check `" << name_
1216 << "')\nCheck your installation and "
1217 "try Options/Reconfigure..." << endl;
1223 //////////////////////////////////////////
1225 // Gets textclass number from name
1226 pair<bool, LyXTextClassList::size_type> const
1227 LyXTextClassList::NumberOfClass(string const & textclass) const
1229 ClassList::const_iterator cit =
1230 find_if(classlist.begin(), classlist.end(),
1231 lyx::compare_memfun(&LyXTextClass::name, textclass));
1232 return cit != classlist.end() ?
1233 make_pair(true, size_type(cit - classlist.begin())) :
1234 make_pair(false, size_type(0));
1238 // Gets layout structure from style number and textclass number
1240 LyXTextClassList::Style(LyXTextClassList::size_type textclass,
1241 LyXTextClass::size_type layout) const
1243 classlist[textclass].load();
1244 if (layout < classlist[textclass].numLayouts())
1245 return classlist[textclass][layout];
1246 return classlist[textclass][0];
1250 // Gets layout number from name and textclass number
1251 pair<bool, LyXTextClass::size_type> const
1252 LyXTextClassList::NumberOfLayout(LyXTextClassList::size_type textclass,
1253 string const & name) const
1255 classlist[textclass].load();
1256 for (unsigned int i = 0; i < classlist[textclass].numLayouts(); ++i) {
1257 if (classlist[textclass][i].name() == name)
1258 return make_pair(true, i);
1260 if (name == "dummy")
1261 return make_pair(true, LyXTextClassList::size_type(LYX_DUMMY_LAYOUT));
1262 return make_pair(false, LyXTextClass::size_type(0)); // not found
1266 // Gets a layout (style) name from layout number and textclass number
1268 LyXTextClassList::NameOfLayout(LyXTextClassList::size_type textclass,
1269 LyXTextClass::size_type layout) const
1271 static string const dummy("dummy");
1272 classlist[textclass].load();
1273 if (layout < classlist[textclass].numLayouts())
1274 return classlist[textclass][layout].name();
1279 // Gets a textclass name from number
1281 LyXTextClassList::NameOfClass(LyXTextClassList::size_type number) const
1283 static string const dummy("dummy");
1284 if (classlist.size() == 0) {
1287 lyx::Assert(number < classlist.size());
1288 return classlist[number].name();
1292 // Gets a textclass latexname from number
1294 LyXTextClassList::LatexnameOfClass(LyXTextClassList::size_type number) const
1296 static string const dummy("dummy");
1297 classlist[number].load();
1298 if (classlist.size() == 0) {
1301 lyx::Assert(number < classlist.size());
1302 return classlist[number].latexname();
1306 // Gets a textclass description from number
1308 LyXTextClassList::DescOfClass(LyXTextClassList::size_type number) const
1310 static string const dummy("dummy");
1311 if (classlist.size() == 0) {
1314 lyx::Assert(number < classlist.size());
1315 return classlist[number].description();
1319 // Gets a textclass structure from number
1320 LyXTextClass const &
1321 LyXTextClassList::TextClass(LyXTextClassList::size_type textclass) const
1323 classlist[textclass].load();
1324 if (textclass < classlist.size())
1325 return classlist[textclass];
1327 return classlist[0];
1331 void LyXTextClassList::Add(LyXTextClass const & t)
1333 classlist.push_back(t);
1337 // used when sorting the textclass list.
1338 class less_textclass_desc {
1340 int operator()(LyXTextClass const & tc1, LyXTextClass const & tc2) {
1341 return tc1.description() < tc2.description();
1346 // Reads LyX textclass definitions according to textclass config file
1347 bool LyXTextClassList::Read ()
1350 string real_file = LibFileSearch("", "textclass.lst");
1351 lyxerr[Debug::TCLASS] << "Reading textclasses from `"
1352 << real_file << "'" << endl;
1354 if (real_file.empty()) {
1355 lyxerr << "LyXTextClassList::Read: unable to find "
1356 "textclass file `" << MakeDisplayPath(real_file, 1000)
1357 << "'. Exiting." << endl;
1359 WriteAlert(_("LyX wasn't able to find its layout descriptions!"),
1360 _("Check that the file \"textclass.lst\""),
1361 _("is installed correctly. Sorry, has to exit :-("));
1363 // This causes LyX to end... Not a desirable behaviour. Lgb
1364 // What do you propose? That the user gets a file dialog
1365 // and is allowed to hunt for the file? (Asger)
1366 // more that we have a layout for minimal.cls statically
1367 // compiled in... (Lgb)
1370 if (!lex.setFile(real_file)) {
1371 lyxerr << "LyXTextClassList::Read: "
1372 "lyxlex was not able to set file: "
1373 << real_file << endl;
1377 lyxerr << "LyXTextClassList::Read: unable to open "
1378 "textclass file `" << MakeDisplayPath(real_file, 1000)
1379 << "'\nCheck your installation. LyX can't continue."
1384 bool finished = false;
1385 // Parse config-file
1386 lyxerr[Debug::TCLASS] << "Starting parsing of textclass.lst" << endl;
1387 while (lex.isOK() && !finished) {
1388 lyxerr[Debug::TCLASS] << "\tline by line" << endl;
1389 switch (lex.lex()) {
1390 case LyXLex::LEX_FEOF:
1394 string const fname = lex.getString();
1395 lyxerr[Debug::TCLASS] << "Fname: " << fname << endl;
1397 string const clname = lex.getString();
1398 lyxerr[Debug::TCLASS]
1399 << "Clname: " << clname << endl;
1401 string const desc = lex.getString();
1402 lyxerr[Debug::TCLASS]
1403 << "Desc: " << desc << endl;
1404 // This code is run when we have
1405 // fname, clname and desc
1406 LyXTextClass tmpl(fname,
1410 debugging(Debug::TCLASS)) {
1418 lyxerr[Debug::TCLASS] << "End of parsing of textclass.lst" << endl;
1420 if (classlist.size() == 0) {
1421 lyxerr << "LyXTextClassList::Read: no textclasses found!"
1423 WriteAlert(_("LyX wasn't able to find any layout description!"),
1424 _("Check the contents of the file \"textclass.lst\""),
1425 _("Sorry, has to exit :-("));
1428 // Ok everything loaded ok, now sort the list.
1429 sort(classlist.begin(), classlist.end(), less_textclass_desc());
1435 Returns false if this fails
1438 LyXTextClassList::Load (LyXTextClassList::size_type number) const
1441 if (number < classlist.size()) {
1442 classlist[number].load();
1443 if (classlist[number].numLayouts() == 0) {
1453 std::ostream & operator<<(std::ostream & os, LyXTextClass::PageSides p)
1456 case LyXTextClass::OneSide:
1459 case LyXTextClass::TwoSides: