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"
34 // Global variable: textclass table.
35 LyXTextClassList textclasslist;
38 // Reads the style files
41 lyxerr[Debug::TCLASS] << "LyXSetStyle: parsing configuration...\n";
43 if (!textclasslist.Read()) {
44 lyxerr[Debug::TCLASS] << "LyXSetStyle: an error occured "
45 "during parsing.\n Exiting." << endl;
49 lyxerr[Debug::TCLASS] << "LyXSetStyle: configuration parsed." << endl;
53 // The order of the LayoutTags enum is no more important. [asierra300396]
64 //LT_ENVIRONMENT_DEFAULT,
80 LT_LABELSTRING_APPENDIX,
103 /////////////////////
105 // Constructor for layout
106 LyXLayout::LyXLayout ()
108 margintype = MARGIN_STATIC;
109 latextype = LATEX_PARAGRAPH;
113 font = LyXFont(LyXFont::ALL_INHERIT);
114 labelfont = LyXFont(LyXFont::ALL_INHERIT);
115 resfont = LyXFont(LyXFont::ALL_SANE);
116 reslabelfont = LyXFont(LyXFont::ALL_SANE);
117 nextnoindent = false;
122 labelbottomsep = 0.0;
124 align = LYX_ALIGN_BLOCK;
125 alignpossible = LYX_ALIGN_BLOCK;
126 labeltype = LABEL_NO_LABEL;
127 endlabeltype = END_LABEL_NO_LABEL;
128 // Should or should not. That is the question.
129 // spacing.set(Spacing::OneHalf);
132 newline_allowed = true;
133 free_spacing = false;
137 // Reads a layout definition from file
138 bool LyXLayout::Read (LyXLex & lexrc, LyXTextClass const & tclass)
140 // This table is sorted alphabetically [asierra 30March96]
141 keyword_item layoutTags[] = {
142 { "align", LT_ALIGN },
143 { "alignpossible", LT_ALIGNPOSSIBLE },
144 { "bottomsep", LT_BOTTOMSEP },
145 { "copystyle", LT_COPYSTYLE },
147 { "endlabelstring", LT_ENDLABELSTRING },
148 { "endlabeltype", LT_ENDLABELTYPE },
149 { "fill_bottom", LT_FILL_BOTTOM },
150 { "fill_top", LT_FILL_TOP },
152 { "freespacing", LT_FREE_SPACING },
153 { "intitle", LT_INTITLE },
154 { "itemsep", LT_ITEMSEP },
155 { "keepempty", LT_KEEPEMPTY },
156 { "labelbottomsep", LT_LABEL_BOTTOMSEP },
157 { "labelfont", LT_LABELFONT },
158 { "labelindent", LT_LABELINDENT },
159 { "labelsep", LT_LABELSEP },
160 { "labelstring", LT_LABELSTRING },
161 { "labelstringappendix", LT_LABELSTRING_APPENDIX },
162 { "labeltype", LT_LABELTYPE },
163 { "latexname", LT_LATEXNAME },
164 { "latexparam", LT_LATEXPARAM },
165 { "latextype", LT_LATEXTYPE },
166 { "leftmargin", LT_LEFTMARGIN },
167 { "margin", LT_MARGIN },
168 { "needprotect", LT_NEED_PROTECT },
169 { "newline", LT_NEWLINE },
170 { "nextnoindent", LT_NEXTNOINDENT },
171 { "obsoletedby", LT_OBSOLETEDBY },
172 { "parindent", LT_PARINDENT },
173 { "parsep", LT_PARSEP },
174 { "parskip", LT_PARSKIP },
175 { "preamble", LT_PREAMBLE },
176 { "rightmargin", LT_RIGHTMARGIN },
177 { "spacing", LT_SPACING },
178 { "textfont", LT_TEXTFONT },
179 { "topsep", LT_TOPSEP }
183 bool finished = false;
184 lexrc.pushTable(layoutTags, LT_INTITLE);
185 // parse style section
186 while (!finished && lexrc.IsOK() && !error) {
187 int le = lexrc.lex();
188 // See comment in lyxrc.C.
190 case LyXLex::LEX_FEOF:
193 case LyXLex::LEX_UNDEF: // parse error
194 lexrc.printError("Unknown layout tag `$$Token'");
199 switch(static_cast<LayoutTags>(le)) {
200 case LT_END: // end of structure
204 case LT_COPYSTYLE: // initialize with a known style
206 if (tclass.hasLayout(lexrc.GetString())) {
207 string tmpname = name_;
208 this->operator= (tclass.GetLayout(lexrc.GetString()));
211 lexrc.printError("Cannot copy known "
217 case LT_OBSOLETEDBY: // replace with a known style
219 if (tclass.hasLayout(lexrc.GetString())) {
220 string tmpname = name_;
221 this->operator= (tclass.GetLayout(lexrc.GetString()));
223 if (obsoleted_by().empty())
224 obsoleted_by_ = lexrc.GetString();
226 lexrc.printError("Cannot replace with"
233 case LT_MARGIN: // Margin style definition.
237 case LT_LATEXTYPE: // Latex style definition.
238 readLatexType(lexrc);
242 intitle = lexrc.next() && lexrc.GetInteger();
245 case LT_NEED_PROTECT:
246 needprotect = lexrc.next() && lexrc.GetInteger();
250 keepempty = lexrc.next() && lexrc.GetInteger();
263 labelfont.lyxRead(lexrc);
266 case LT_NEXTNOINDENT: // Indent next paragraph?
267 if (lexrc.next() && lexrc.GetInteger())
270 nextnoindent = false;
275 latexname_ = lexrc.GetString();
280 latexparam_ = lexrc.GetString();
284 preamble_ = lexrc.getLongString("EndPreamble");
288 readLabelType(lexrc);
291 case LT_ENDLABELTYPE:
292 readEndLabelType(lexrc);
295 case LT_LEFTMARGIN: // left margin type
297 leftmargin = lexrc.GetString();
300 case LT_RIGHTMARGIN: // right margin type
302 rightmargin = lexrc.GetString();
305 case LT_LABELINDENT: // label indenting flag
307 labelindent = lexrc.GetString();
310 case LT_PARINDENT: // paragraph indent. flag
312 parindent = lexrc.GetString();
315 case LT_PARSKIP: // paragraph skip size
317 parskip = lexrc.GetFloat();
320 case LT_ITEMSEP: // item separation size
322 itemsep = lexrc.GetFloat();
325 case LT_TOPSEP: // top separation size
327 topsep = lexrc.GetFloat();
330 case LT_BOTTOMSEP: // bottom separation size
332 bottomsep = lexrc.GetFloat();
335 case LT_LABEL_BOTTOMSEP: // label bottom separation size
337 labelbottomsep = lexrc.GetFloat();
340 case LT_LABELSEP: // label separator
342 labelsep = subst(lexrc.GetString(), 'x', ' ');
346 case LT_PARSEP: // par. separation size
348 parsep = lexrc.GetFloat();
351 case LT_FILL_TOP: // fill top flag
353 fill_top = lexrc.GetInteger();
356 case LT_FILL_BOTTOM: // fill bottom flag
358 fill_bottom = lexrc.GetInteger();
361 case LT_NEWLINE: // newlines allowed?
363 newline_allowed = lexrc.GetInteger();
366 case LT_ALIGN: // paragraph align
369 case LT_ALIGNPOSSIBLE: // paragraph allowed align
370 readAlignPossible(lexrc);
373 case LT_LABELSTRING: // label string definition
375 labelstring_ = lexrc.GetString();
378 case LT_ENDLABELSTRING: // endlabel string definition
380 endlabelstring_ = lexrc.GetString();
383 case LT_LABELSTRING_APPENDIX: // label string appendix definition
385 labelstring_appendix_ = lexrc.GetString();
388 case LT_FREE_SPACING: // Allow for free spacing.
390 free_spacing = lexrc.GetInteger();
393 case LT_SPACING: // setspace.sty
412 void LyXLayout::readAlign(LyXLex & lexrc)
414 keyword_item alignTags[] = {
415 { "block", AT_BLOCK },
416 { "center", AT_CENTER },
417 { "layout", AT_LAYOUT },
419 { "right", AT_RIGHT }
422 pushpophelper pph(lexrc, alignTags, AT_LAYOUT);
423 int le = lexrc.lex();
425 case LyXLex::LEX_UNDEF:
426 lexrc.printError("Unknown alignment `$$Token'");
430 switch(static_cast<AlignTags>(le)) {
432 align = LYX_ALIGN_BLOCK;
435 align = LYX_ALIGN_LEFT;
438 align = LYX_ALIGN_RIGHT;
441 align = LYX_ALIGN_CENTER;
444 align = LYX_ALIGN_LAYOUT;
450 void LyXLayout::readAlignPossible(LyXLex & lexrc)
452 keyword_item alignTags[] = {
453 { "block", AT_BLOCK },
454 { "center", AT_CENTER },
455 { "layout", AT_LAYOUT },
457 { "right", AT_RIGHT }
460 lexrc.pushTable(alignTags, AT_LAYOUT);
461 alignpossible = LYX_ALIGN_NONE;
462 int lineno = lexrc.GetLineNo();
464 int le = lexrc.lex();
466 case LyXLex::LEX_UNDEF:
467 lexrc.printError("Unknown alignment `$$Token'");
471 switch (static_cast<AlignTags>(le)) {
473 alignpossible |= LYX_ALIGN_BLOCK;
476 alignpossible |= LYX_ALIGN_LEFT;
479 alignpossible |= LYX_ALIGN_RIGHT;
482 alignpossible |= LYX_ALIGN_CENTER;
485 alignpossible |= LYX_ALIGN_LAYOUT;
488 } while (lineno == lexrc.GetLineNo());
497 LA_CENTERED_TOP_ENVIRONMENT,
502 LA_COUNTER_SUBSECTION,
503 LA_COUNTER_SUBSUBSECTION,
504 LA_COUNTER_PARAGRAPH,
505 LA_COUNTER_SUBPARAGRAPH,
514 void LyXLayout::readLabelType(LyXLex & lexrc)
516 keyword_item labelTypeTags[] = {
517 { "bibliography", LA_BIBLIO },
518 { "centered_top_environment", LA_CENTERED_TOP_ENVIRONMENT },
519 { "counter_chapter", LA_COUNTER_CHAPTER },
520 { "counter_enumi", LA_COUNTER_ENUMI },
521 { "counter_enumii", LA_COUNTER_ENUMII },
522 { "counter_enumiii", LA_COUNTER_ENUMIII },
523 { "counter_enumiv", LA_COUNTER_ENUMIV },
524 { "counter_paragraph", LA_COUNTER_PARAGRAPH },
525 { "counter_section", LA_COUNTER_SECTION },
526 { "counter_subparagraph", LA_COUNTER_SUBPARAGRAPH },
527 { "counter_subsection", LA_COUNTER_SUBSECTION },
528 { "counter_subsubsection", LA_COUNTER_SUBSUBSECTION },
529 { "manual", LA_MANUAL },
530 { "no_label", LA_NO_LABEL },
531 { "sensitive", LA_SENSITIVE },
532 { "static", LA_STATIC },
533 { "top_environment", LA_TOP_ENVIRONMENT }
536 pushpophelper pph(lexrc, labelTypeTags, LA_BIBLIO);
537 int le = lexrc.lex();
539 case LyXLex::LEX_UNDEF:
540 lexrc.printError("Unknown labeltype tag `$$Token'");
544 switch (static_cast<LabelTypeTags>(le)) {
546 labeltype = LABEL_NO_LABEL;
549 labeltype = LABEL_MANUAL;
551 case LA_TOP_ENVIRONMENT:
552 labeltype = LABEL_TOP_ENVIRONMENT;
554 case LA_CENTERED_TOP_ENVIRONMENT:
555 labeltype = LABEL_CENTERED_TOP_ENVIRONMENT;
558 labeltype = LABEL_STATIC;
561 labeltype = LABEL_SENSITIVE;
563 case LA_COUNTER_CHAPTER:
564 labeltype = LABEL_COUNTER_CHAPTER;
566 case LA_COUNTER_SECTION:
567 labeltype = LABEL_COUNTER_SECTION;
569 case LA_COUNTER_SUBSECTION:
570 labeltype = LABEL_COUNTER_SUBSECTION;
572 case LA_COUNTER_SUBSUBSECTION:
573 labeltype = LABEL_COUNTER_SUBSUBSECTION;
575 case LA_COUNTER_PARAGRAPH:
576 labeltype = LABEL_COUNTER_PARAGRAPH;
578 case LA_COUNTER_SUBPARAGRAPH:
579 labeltype = LABEL_COUNTER_SUBPARAGRAPH;
581 case LA_COUNTER_ENUMI:
582 labeltype = LABEL_COUNTER_ENUMI;
584 case LA_COUNTER_ENUMII:
585 labeltype = LABEL_COUNTER_ENUMII;
587 case LA_COUNTER_ENUMIII:
588 labeltype = LABEL_COUNTER_ENUMIII;
590 case LA_COUNTER_ENUMIV:
591 labeltype = LABEL_COUNTER_ENUMIV;
594 labeltype = LABEL_BIBLIO;
599 static keyword_item endlabelTypeTags[] = {
600 { "box", END_LABEL_BOX },
601 { "filled_box", END_LABEL_FILLED_BOX },
602 { "no_label", END_LABEL_NO_LABEL },
603 { "static", END_LABEL_STATIC }
606 void LyXLayout::readEndLabelType(LyXLex & lexrc)
608 pushpophelper pph(lexrc, endlabelTypeTags,
609 END_LABEL_ENUM_LAST-END_LABEL_ENUM_FIRST+1);
610 int le = lexrc.lex();
612 case LyXLex::LEX_UNDEF:
613 lexrc.printError("Unknown labeltype tag `$$Token'");
615 case END_LABEL_STATIC:
617 case END_LABEL_FILLED_BOX:
618 case END_LABEL_NO_LABEL:
619 endlabeltype = static_cast<LYX_END_LABEL_TYPES>(le);
622 lyxerr << "Unhandled value " << le
623 << " in LyXLayout::readEndLabelType." << endl;
629 void LyXLayout::readMargin(LyXLex & lexrc)
631 keyword_item marginTags[] = {
632 { "dynamic", MARGIN_DYNAMIC },
633 { "first_dynamic", MARGIN_FIRST_DYNAMIC },
634 { "manual", MARGIN_MANUAL },
635 { "right_address_box", MARGIN_RIGHT_ADDRESS_BOX },
636 { "static", MARGIN_STATIC }
639 pushpophelper pph(lexrc, marginTags, MARGIN_RIGHT_ADDRESS_BOX);
641 int le = lexrc.lex();
643 case LyXLex::LEX_UNDEF:
644 lexrc.printError("Unknown margin type tag `$$Token'");
649 case MARGIN_FIRST_DYNAMIC:
650 case MARGIN_RIGHT_ADDRESS_BOX:
651 margintype = static_cast<LYX_MARGIN_TYPE>(le);
654 lyxerr << "Unhandled value " << le
655 << " in LyXLayout::readMargin." << endl;
661 void LyXLayout::readLatexType(LyXLex & lexrc)
663 keyword_item latexTypeTags[] = {
664 { "command", LATEX_COMMAND },
665 { "environment", LATEX_ENVIRONMENT },
666 { "item_environment", LATEX_ITEM_ENVIRONMENT },
667 { "list_environment", LATEX_LIST_ENVIRONMENT },
668 { "paragraph", LATEX_PARAGRAPH }
671 pushpophelper pph(lexrc, latexTypeTags, LATEX_LIST_ENVIRONMENT);
672 int le = lexrc.lex();
674 case LyXLex::LEX_UNDEF:
675 lexrc.printError("Unknown latextype tag `$$Token'");
677 case LATEX_PARAGRAPH:
679 case LATEX_ENVIRONMENT:
680 case LATEX_ITEM_ENVIRONMENT:
681 case LATEX_LIST_ENVIRONMENT:
682 latextype = static_cast<LYX_LATEX_TYPES>(le);
685 lyxerr << "Unhandled value " << le
686 << " in LyXLayout::readLatexType." << endl;
693 ST_SPACING_SINGLE = 1,
700 void LyXLayout::readSpacing(LyXLex & lexrc)
702 keyword_item spacingTags[] = {
703 {"double", ST_SPACING_DOUBLE },
704 {"onehalf", ST_SPACING_ONEHALF },
705 {"other", ST_OTHER },
706 {"single", ST_SPACING_SINGLE }
709 pushpophelper pph(lexrc, spacingTags, ST_OTHER);
710 int le = lexrc.lex();
712 case LyXLex::LEX_UNDEF:
713 lexrc.printError("Unknown spacing token `$$Token'");
717 switch(static_cast<SpacingTags>(le)) {
718 case ST_SPACING_SINGLE:
719 spacing.set(Spacing::Single);
721 case ST_SPACING_ONEHALF:
722 spacing.set(Spacing::Onehalf);
724 case ST_SPACING_DOUBLE:
725 spacing.set(Spacing::Double);
729 spacing.set(Spacing::Other, lexrc.GetFloat());
735 /* ******************************************************************* */
737 LyXTextClass::LyXTextClass(string const & fn, string const & cln,
739 : name_(fn), latexname_(cln), description_(desc)
746 pagestyle_ = "default";
747 maxcounter_ = LABEL_COUNTER_CHAPTER;
748 defaultfont_ = LyXFont(LyXFont::ALL_SANE);
749 opt_fontsize_ = "10|11|12";
750 opt_pagestyle_ = "empty|plain|headings|fancy";
756 bool LyXTextClass::do_readStyle(LyXLex & lexrc, LyXLayout & lay)
758 lyxerr[Debug::TCLASS] << "Reading style " << lay.name() << endl;
759 if (!lay.Read(lexrc, *this)) {
761 lay.resfont = lay.font;
762 lay.resfont.realize(defaultfont());
763 lay.reslabelfont = lay.labelfont;
764 lay.reslabelfont.realize(defaultfont());
765 return false; // no errors
767 lyxerr << "Error parsing style `" << lay.name() << "'" << endl;
794 // Reads a textclass structure from file.
795 bool LyXTextClass::Read(string const & filename, bool merge)
797 keyword_item textClassTags[] = {
798 { "classoptions", TC_CLASSOPTIONS },
799 { "columns", TC_COLUMNS },
800 { "defaultfont", TC_DEFAULTFONT },
801 { "input", TC_INPUT },
802 { "leftmargin", TC_LEFTMARGIN },
803 { "maxcounter", TC_MAXCOUNTER },
804 { "nostyle", TC_NOSTYLE },
805 { "outputtype", TC_OUTPUTTYPE },
806 { "pagestyle", TC_PAGESTYLE },
807 { "preamble", TC_PREAMBLE },
808 { "providesamsmath", TC_PROVIDESAMSMATH },
809 { "providesmakeidx", TC_PROVIDESMAKEIDX },
810 { "providesurl", TC_PROVIDESURL },
811 { "rightmargin", TC_RIGHTMARGIN },
812 { "secnumdepth", TC_SECNUMDEPTH },
813 { "sides", TC_SIDES },
814 { "style", TC_STYLE },
815 { "tocdepth", TC_TOCDEPTH }
819 lyxerr[Debug::TCLASS] << "Reading textclass "
820 << MakeDisplayPath(filename)
823 lyxerr[Debug::TCLASS] << "Reading input file "
824 << MakeDisplayPath(filename)
827 LyXLex lexrc(textClassTags, TC_RIGHTMARGIN);
830 lexrc.setFile(filename);
831 if (!lexrc.IsOK()) error = true;
834 while (lexrc.IsOK() && !error) {
835 int le = lexrc.lex();
837 case LyXLex::LEX_FEOF:
840 case LyXLex::LEX_UNDEF:
841 lexrc.printError("Unknown TextClass tag `$$Token'");
846 switch(static_cast<TextClassTags>(le)) {
847 case TC_OUTPUTTYPE: // output type definition
848 readOutputType(lexrc);
851 case TC_INPUT: // Include file
853 string tmp = LibFileSearch("layouts",
857 if (Read(tmp, true)) {
858 lexrc.printError("Error reading input"
867 string name = subst(lexrc.GetString(),
869 if (hasLayout(name)) {
870 LyXLayout & lay = GetLayout(name);
871 error = do_readStyle(lexrc, lay);
875 if (!(error = do_readStyle(lexrc, lay)))
876 layoutlist.push_back(lay);
880 lexrc.printError("No name given for style: `$$Token'.");
887 string style = subst(lexrc.GetString(),
889 if (!delete_layout(style))
890 lexrc.printError("Cannot delete style"
897 columns_ = lexrc.GetInteger();
902 switch(lexrc.GetInteger()) {
903 case 1: sides_ = OneSide; break;
904 case 2: sides_ = TwoSides; break;
906 lyxerr << "Impossible number of page"
907 " sides, setting to one."
917 pagestyle_ = strip(lexrc.GetString());
921 defaultfont_.lyxRead(lexrc);
922 if (!defaultfont_.resolved()) {
923 lexrc.printError("Warning: defaultfont should "
924 "be fully instantiated!");
925 defaultfont_.realize(LyXFont(LyXFont::ALL_SANE));
930 readMaxCounter(lexrc);
935 secnumdepth_ = lexrc.GetInteger();
940 tocdepth_ = lexrc.GetInteger();
943 // First step to support options
944 case TC_CLASSOPTIONS:
945 readClassOptions(lexrc);
949 preamble_ = lexrc.getLongString("EndPreamble");
952 case TC_PROVIDESAMSMATH:
953 if (lexrc.next() && lexrc.GetInteger())
954 provides_ |= amsmath;
957 case TC_PROVIDESMAKEIDX:
958 if (lexrc.next() && lexrc.GetInteger())
959 provides_ |= makeidx;
963 if (lexrc.next() && lexrc.GetInteger())
967 case TC_LEFTMARGIN: // left margin type
969 leftmargin_ = lexrc.GetString();
972 case TC_RIGHTMARGIN: // right margin type
974 rightmargin_ = lexrc.GetString();
979 if (!merge) { // we are at top level here.
980 lyxerr[Debug::TCLASS] << "Finished reading textclass "
981 << MakeDisplayPath(filename)
984 lyxerr[Debug::TCLASS] << "Finished reading input file "
985 << MakeDisplayPath(filename)
992 void LyXTextClass::readOutputType(LyXLex & lexrc)
994 keyword_item outputTypeTags[] = {
995 { "docbook", DOCBOOK },
997 { "linuxdoc", LINUXDOC },
998 { "literate", LITERATE }
1001 pushpophelper pph(lexrc, outputTypeTags, LITERATE);
1003 int le = lexrc.lex();
1005 case LyXLex::LEX_UNDEF:
1006 lexrc.printError("Unknown output type `$$Token'");
1012 outputType_ = static_cast<OutputType>(le);
1015 lyxerr << "Unhandled value " << le
1016 << " in LyXTextClass::readOutputType." << endl;
1023 enum MaxCounterTags {
1024 MC_COUNTER_CHAPTER = 1,
1026 MC_COUNTER_SUBSECTION,
1027 MC_COUNTER_SUBSUBSECTION,
1028 MC_COUNTER_PARAGRAPH,
1029 MC_COUNTER_SUBPARAGRAPH,
1037 void LyXTextClass::readMaxCounter(LyXLex & lexrc)
1039 keyword_item maxCounterTags[] = {
1040 {"counter_chapter", MC_COUNTER_CHAPTER },
1041 {"counter_enumi", MC_COUNTER_ENUMI },
1042 {"counter_enumii", MC_COUNTER_ENUMII },
1043 {"counter_enumiii", MC_COUNTER_ENUMIII },
1044 {"counter_enumiv", MC_COUNTER_ENUMIV },
1045 {"counter_paragraph", MC_COUNTER_PARAGRAPH },
1046 {"counter_section", MC_COUNTER_SECTION },
1047 {"counter_subparagraph", MC_COUNTER_SUBPARAGRAPH },
1048 {"counter_subsection", MC_COUNTER_SUBSECTION },
1049 {"counter_subsubsection", MC_COUNTER_SUBSUBSECTION }
1052 pushpophelper pph(lexrc, maxCounterTags, MC_COUNTER_ENUMIV);
1053 int le = lexrc.lex();
1055 case LyXLex::LEX_UNDEF:
1056 lexrc.printError("Unknown MaxCounter tag `$$Token'");
1060 switch (static_cast<MaxCounterTags>(le)) {
1061 case MC_COUNTER_CHAPTER:
1062 maxcounter_ = LABEL_COUNTER_CHAPTER;
1064 case MC_COUNTER_SECTION:
1065 maxcounter_ = LABEL_COUNTER_SECTION;
1067 case MC_COUNTER_SUBSECTION:
1068 maxcounter_ = LABEL_COUNTER_SUBSECTION;
1070 case MC_COUNTER_SUBSUBSECTION:
1071 maxcounter_ = LABEL_COUNTER_SUBSUBSECTION;
1073 case MC_COUNTER_PARAGRAPH:
1074 maxcounter_ = LABEL_COUNTER_PARAGRAPH;
1076 case MC_COUNTER_SUBPARAGRAPH:
1077 maxcounter_ = LABEL_COUNTER_SUBPARAGRAPH;
1079 case MC_COUNTER_ENUMI:
1080 maxcounter_ = LABEL_COUNTER_ENUMI;
1082 case MC_COUNTER_ENUMII:
1083 maxcounter_ = LABEL_COUNTER_ENUMII;
1085 case MC_COUNTER_ENUMIII:
1086 maxcounter_ = LABEL_COUNTER_ENUMIII;
1088 case MC_COUNTER_ENUMIV:
1089 maxcounter_ = LABEL_COUNTER_ENUMIV;
1095 enum ClassOptionsTags {
1103 void LyXTextClass::readClassOptions(LyXLex & lexrc)
1105 keyword_item classOptionsTags[] = {
1107 {"fontsize", CO_FONTSIZE },
1108 {"other", CO_OTHER },
1109 {"pagestyle", CO_PAGESTYLE }
1112 lexrc.pushTable(classOptionsTags, CO_END);
1113 bool getout = false;
1114 while (!getout && lexrc.IsOK()) {
1115 int le = lexrc.lex();
1117 case LyXLex::LEX_UNDEF:
1118 lexrc.printError("Unknown ClassOption tag `$$Token'");
1122 switch (static_cast<ClassOptionsTags>(le)) {
1125 opt_fontsize_ = strip(lexrc.GetString());
1129 opt_pagestyle_ = strip(lexrc.GetString());
1133 options_ = lexrc.GetString();
1144 bool LyXTextClass::hasLayout(string const & name) const
1146 return find_if(layoutlist.begin(), layoutlist.end(),
1147 compare_memfun(&LyXLayout::name, name))
1148 != layoutlist.end();
1152 LyXLayout const & LyXTextClass::GetLayout (string const & name) const
1154 LayoutList::const_iterator cit =
1155 find_if(layoutlist.begin(),
1157 compare_memfun(&LyXLayout::name, name));
1158 Assert(cit != layoutlist.end()); // we require the name to exist
1163 LyXLayout & LyXTextClass::GetLayout(string const & name)
1165 LayoutList::iterator it =
1166 find_if(layoutlist.begin(),
1168 compare_memfun(&LyXLayout::name, name));
1169 Assert(it != layoutlist.end()); // we require the name to exist
1174 bool LyXTextClass::delete_layout(string const & name)
1176 LayoutList::iterator it =
1177 remove_if(layoutlist.begin(), layoutlist.end(),
1178 compare_memfun(&LyXLayout::name, name));
1179 LayoutList::iterator end = layoutlist.end();
1180 bool const ret = (it != end);
1181 layoutlist.erase(it, end);
1186 // Load textclass info if not loaded yet
1187 void LyXTextClass::load()
1192 string const real_file = LibFileSearch("layouts", name_, "layout");
1194 if (Read(real_file)) {
1195 lyxerr << "Error reading `"
1196 << MakeDisplayPath(real_file)
1197 << "'\n(Check `" << name_
1198 << "')\nCheck your installation and "
1199 "try Options/Reconfigure..." << endl;
1205 //////////////////////////////////////////
1207 // Gets textclass number from name
1208 pair<bool, LyXTextClassList::size_type> const
1209 LyXTextClassList::NumberOfClass(string const & textclass) const
1211 ClassList::const_iterator cit =
1212 find_if(classlist.begin(), classlist.end(),
1213 compare_memfun(&LyXTextClass::name, textclass));
1214 return cit != classlist.end() ?
1215 make_pair(true, size_type(cit - classlist.begin())) :
1216 make_pair(false, size_type(0));
1220 // Gets layout structure from style number and textclass number
1222 LyXTextClassList::Style(LyXTextClassList::size_type textclass,
1223 LyXTextClass::size_type layout) const
1225 classlist[textclass].load();
1226 if (layout < classlist[textclass].numLayouts())
1227 return classlist[textclass][layout];
1228 return classlist[textclass][0];
1232 // Gets layout number from name and textclass number
1233 pair<bool, LyXTextClass::size_type> const
1234 LyXTextClassList::NumberOfLayout(LyXTextClassList::size_type textclass,
1235 string const & name) const
1237 classlist[textclass].load();
1238 for(unsigned int i = 0; i < classlist[textclass].numLayouts(); ++i) {
1239 if (classlist[textclass][i].name() == name)
1240 return make_pair(true, i);
1242 if (name == "dummy")
1243 return make_pair(true, LyXTextClassList::size_type(LYX_DUMMY_LAYOUT));
1244 return make_pair(false, LyXTextClass::size_type(0)); // not found
1248 // Gets a layout (style) name from layout number and textclass number
1250 LyXTextClassList::NameOfLayout(LyXTextClassList::size_type textclass,
1251 LyXTextClass::size_type layout) const
1253 static string dummy("dummy");
1254 classlist[textclass].load();
1255 if (layout < classlist[textclass].numLayouts())
1256 return classlist[textclass][layout].name();
1261 // Gets a textclass name from number
1263 LyXTextClassList::NameOfClass(LyXTextClassList::size_type number) const
1265 static string dummy("dummy");
1266 if (classlist.size() == 0) {
1269 Assert(number < classlist.size());
1270 return classlist[number].name();
1274 // Gets a textclass latexname from number
1276 LyXTextClassList::LatexnameOfClass(LyXTextClassList::size_type number) const
1278 static string dummy("dummy");
1279 classlist[number].load();
1280 if (classlist.size() == 0) {
1283 Assert(number < classlist.size());
1284 return classlist[number].latexname();
1288 // Gets a textclass description from number
1290 LyXTextClassList::DescOfClass(LyXTextClassList::size_type number) const
1292 static string dummy("dummy");
1293 if (classlist.size() == 0) {
1296 Assert(number < classlist.size());
1297 return classlist[number].description();
1301 // Gets a textclass structure from number
1302 LyXTextClass const &
1303 LyXTextClassList::TextClass(LyXTextClassList::size_type textclass) const
1305 classlist[textclass].load();
1306 if (textclass < classlist.size())
1307 return classlist[textclass];
1309 return classlist[0];
1313 void LyXTextClassList::Add(LyXTextClass const & t)
1315 classlist.push_back(t);
1319 // used when sorting the textclass list.
1320 class less_textclass_desc {
1322 int operator()(LyXTextClass const & tc1, LyXTextClass const & tc2) {
1323 return tc1.description() < tc2.description();
1328 // Reads LyX textclass definitions according to textclass config file
1329 bool LyXTextClassList::Read ()
1332 string real_file = LibFileSearch("", "textclass.lst");
1333 lyxerr[Debug::TCLASS] << "Reading textclasses from `"
1334 << real_file << "'" << endl;
1336 if (real_file.empty()) {
1337 lyxerr << "LyXTextClassList::Read: unable to find "
1338 "textclass file `" << MakeDisplayPath(real_file, 1000)
1339 << "'. Exiting." << endl;
1341 WriteAlert(_("LyX wasn't able to find its layout descriptions!"),
1342 _("Check that the file \"textclass.lst\""),
1343 _("is installed correctly. Sorry, has to exit :-("));
1345 // This causes LyX to end... Not a desirable behaviour. Lgb
1346 // What do you propose? That the user gets a file dialog
1347 // and is allowed to hunt for the file? (Asger)
1348 // more that we have a layout for minimal.cls statically
1349 // compiled in... (Lgb)
1352 if (!lex.setFile(real_file)) {
1353 lyxerr << "LyXTextClassList::Read: "
1354 "lyxlex was not able to set file: "
1355 << real_file << endl;
1359 lyxerr << "LyXTextClassList::Read: unable to open "
1360 "textclass file `" << MakeDisplayPath(real_file, 1000)
1361 << "'\nCheck your installation. LyX can't continue."
1365 bool finished = false;
1366 string fname, clname, desc;
1367 // Parse config-file
1368 lyxerr[Debug::TCLASS] << "Starting parsing of textclass.lst" << endl;
1369 while (lex.IsOK() && !finished) {
1370 lyxerr[Debug::TCLASS] << "\tline by line" << endl;
1371 switch (lex.lex()) {
1372 case LyXLex::LEX_FEOF:
1376 fname = lex.GetString();
1377 lyxerr[Debug::TCLASS] << "Fname: " << fname << endl;
1379 clname = lex.GetString();
1380 lyxerr[Debug::TCLASS]
1381 << "Clname: " << clname << endl;
1383 desc = lex.GetString();
1384 lyxerr[Debug::TCLASS]
1385 << "Desc: " << desc << endl;
1386 // This code is run when we have
1387 // fname, clname and desc
1388 LyXTextClass tmpl(fname,
1392 debugging(Debug::TCLASS)) {
1400 lyxerr[Debug::TCLASS] << "End of parsing of textclass.lst" << endl;
1402 if (classlist.size() == 0) {
1403 lyxerr << "LyXTextClassList::Read: no textclasses found!"
1405 WriteAlert(_("LyX wasn't able to find any layout description!"),
1406 _("Check the contents of the file \"textclass.lst\""),
1407 _("Sorry, has to exit :-("));
1410 // Ok everything loaded ok, now sort the list.
1411 sort(classlist.begin(), classlist.end(), less_textclass_desc());
1417 Returns false if this fails
1420 LyXTextClassList::Load (LyXTextClassList::size_type number) const
1423 if (number < classlist.size()) {
1424 classlist[number].load();
1425 if (classlist[number].numLayouts() == 0) {
1435 std::ostream & operator<<(std::ostream & os, LyXTextClass::PageSides p)
1438 case LyXTextClass::OneSide:
1441 case LyXTextClass::TwoSides: