]> git.lyx.org Git - lyx.git/blob - src/lyxtextclass.C
introduce namespace lyx::support
[lyx.git] / src / lyxtextclass.C
1 /* This file is part of
2  * ======================================================
3  *
4  *           LyX, The Document Processor
5  *
6  *          Copyright 1995 Matthias Ettrich
7  *          Copyright 1995-2001 The LyX Team.
8  *
9  * ======================================================
10  */
11
12 #include <config.h>
13
14 #include "lyxtextclass.h"
15 #include "debug.h"
16 #include "lyxlex.h"
17 #include "counters.h"
18 #include "FloatList.h"
19
20 #include "support/lstrings.h"
21 #include "support/LAssert.h"
22 #include "support/lyxfunctional.h"
23 #include "support/filetools.h"
24
25 #include <algorithm>
26
27 using namespace lyx::support;
28
29 using std::endl;
30 using std::find_if;
31 using std::remove_if;
32 using std::ostream;
33
34 namespace { // anon
35
36 struct compare_name {
37
38         compare_name(string const & name)
39                 : name_(name)
40         {}
41
42         bool operator()(boost::shared_ptr<LyXLayout> const & c)
43         {
44                 return c->name() == name_;
45         }
46
47         string name_;
48
49 };
50
51 } // anon
52
53
54 LyXTextClass::LyXTextClass(string const & fn, string const & cln,
55                            string const & desc, bool texClassAvail )
56         : name_(fn), latexname_(cln), description_(desc),
57           floatlist_(new FloatList), ctrs_(new Counters), texClassAvail_(texClassAvail)
58 {
59         outputType_ = LATEX;
60         columns_ = 1;
61         sides_ = OneSide;
62         secnumdepth_ = 3;
63         tocdepth_ = 3;
64         pagestyle_ = "default";
65         maxcounter_ = LABEL_COUNTER_CHAPTER;
66         defaultfont_ = LyXFont(LyXFont::ALL_SANE);
67         opt_fontsize_ = "10|11|12";
68         opt_pagestyle_ = "empty|plain|headings|fancy";
69         provides_ = nothing;
70         titletype_ = TITLE_COMMAND_AFTER;
71         titlename_ = "maketitle";
72         loaded = false;
73 }
74
75
76 bool LyXTextClass::isTeXClassAvailable() const
77 {
78         return texClassAvail_;
79 }
80
81
82 bool LyXTextClass::do_readStyle(LyXLex & lexrc, LyXLayout & lay)
83 {
84         lyxerr[Debug::TCLASS] << "Reading style " << lay.name() << endl;
85         if (!lay.Read(lexrc, *this)) {
86                 // Resolve fonts
87                 lay.resfont = lay.font;
88                 lay.resfont.realize(defaultfont());
89                 lay.reslabelfont = lay.labelfont;
90                 lay.reslabelfont.realize(defaultfont());
91                 return false; // no errors
92         }
93         lyxerr << "Error parsing style `" << lay.name() << '\'' << endl;
94         return true;
95 }
96
97
98 enum TextClassTags {
99         TC_OUTPUTTYPE = 1,
100         TC_INPUT,
101         TC_STYLE,
102         TC_DEFAULTSTYLE,
103         TC_ENVIRONMENT,
104         TC_NOSTYLE,
105         TC_COLUMNS,
106         TC_SIDES,
107         TC_PAGESTYLE,
108         TC_DEFAULTFONT,
109         TC_MAXCOUNTER,
110         TC_SECNUMDEPTH,
111         TC_TOCDEPTH,
112         TC_CLASSOPTIONS,
113         TC_PREAMBLE,
114         TC_PROVIDESAMSMATH,
115         TC_PROVIDESNATBIB,
116         TC_PROVIDESMAKEIDX,
117         TC_PROVIDESURL,
118         TC_LEFTMARGIN,
119         TC_RIGHTMARGIN,
120         TC_FLOAT,
121         TC_COUNTER,
122         TC_NOFLOAT,
123         TC_TITLELATEXNAME,
124         TC_TITLELATEXTYPE
125 };
126
127 // Reads a textclass structure from file.
128 bool LyXTextClass::Read(string const & filename, bool merge)
129 {
130         keyword_item textClassTags[] = {
131                 { "classoptions",    TC_CLASSOPTIONS },
132                 { "columns",         TC_COLUMNS },
133                 { "counter",         TC_COUNTER },
134                 { "defaultfont",     TC_DEFAULTFONT },
135                 { "defaultstyle",    TC_DEFAULTSTYLE },
136                 { "environment",     TC_ENVIRONMENT },
137                 { "float",           TC_FLOAT },
138                 { "input",           TC_INPUT },
139                 { "leftmargin",      TC_LEFTMARGIN },
140                 { "maxcounter",      TC_MAXCOUNTER },
141                 { "nofloat",         TC_NOFLOAT },
142                 { "nostyle",         TC_NOSTYLE },
143                 { "outputtype",      TC_OUTPUTTYPE },
144                 { "pagestyle",       TC_PAGESTYLE },
145                 { "preamble",        TC_PREAMBLE },
146                 { "providesamsmath", TC_PROVIDESAMSMATH },
147                 { "providesmakeidx", TC_PROVIDESMAKEIDX },
148                 { "providesnatbib",  TC_PROVIDESNATBIB },
149                 { "providesurl",     TC_PROVIDESURL },
150                 { "rightmargin",     TC_RIGHTMARGIN },
151                 { "secnumdepth",     TC_SECNUMDEPTH },
152                 { "sides",           TC_SIDES },
153                 { "style",           TC_STYLE },
154                 { "titlelatexname",  TC_TITLELATEXNAME },
155                 { "titlelatextype",  TC_TITLELATEXTYPE },
156                 { "tocdepth",        TC_TOCDEPTH }
157         };
158
159         if (!merge)
160                 lyxerr[Debug::TCLASS] << "Reading textclass "
161                                       << MakeDisplayPath(filename)
162                                       << endl;
163         else
164                 lyxerr[Debug::TCLASS] << "Reading input file "
165                                      << MakeDisplayPath(filename)
166                                      << endl;
167
168         LyXLex lexrc(textClassTags,
169                 sizeof(textClassTags) / sizeof(textClassTags[0]));
170         bool error = false;
171
172         lexrc.setFile(filename);
173         if (!lexrc.isOK()) error = true;
174
175         // parsing
176         while (lexrc.isOK() && !error) {
177                 int le = lexrc.lex();
178
179                 switch (le) {
180                 case LyXLex::LEX_FEOF:
181                         continue;
182
183                 case LyXLex::LEX_UNDEF:
184                         lexrc.printError("Unknown TextClass tag `$$Token'");
185                         error = true;
186                         continue;
187
188                 default:
189                         break;
190                 }
191
192                 switch (static_cast<TextClassTags>(le)) {
193
194                 case TC_OUTPUTTYPE:   // output type definition
195                         readOutputType(lexrc);
196                         break;
197
198                 case TC_INPUT: // Include file
199                         if (lexrc.next()) {
200                                 string tmp = LibFileSearch("layouts",
201                                                             lexrc.getString(),
202                                                             "layout");
203
204                                 if (Read(tmp, true)) {
205                                         lexrc.printError("Error reading input"
206                                                          "file: "+tmp);
207                                         error = true;
208                                 }
209                         }
210                         break;
211
212                 case TC_DEFAULTSTYLE:
213                         if (lexrc.next()) {
214                                 string const name = subst(lexrc.getString(),
215                                                           '_', ' ');
216                                 defaultlayout_ = name;
217                         }
218                         break;
219
220                 case TC_ENVIRONMENT:
221                 case TC_STYLE:
222                         if (lexrc.next()) {
223                                 string const name = subst(lexrc.getString(),
224                                                     '_', ' ');
225                                 if (hasLayout(name)) {
226                                         LyXLayout * lay = operator[](name).get();
227                                         error = do_readStyle(lexrc, *lay);
228                                 } else {
229                                         LyXLayout lay;
230                                         lay.setName(name);
231                                         if (le == TC_ENVIRONMENT)
232                                                 lay.is_environment = true;
233                                         if (!(error = do_readStyle(lexrc, lay)))
234                                                 layoutlist_.push_back
235                                                         (boost::shared_ptr<LyXLayout>(new LyXLayout(lay)));
236                                         if (defaultlayout_.empty()) {
237                                                 // We do not have a default
238                                                 // layout yet, so we choose
239                                                 // the first layout we
240                                                 // encounter.
241                                                 defaultlayout_ = name;
242                                         }
243                                 }
244                         }
245                         else {
246                                 lexrc.printError("No name given for style: `$$Token'.");
247                                 error = true;
248                         }
249                         break;
250
251                 case TC_NOSTYLE:
252                         if (lexrc.next()) {
253                                 string const style = subst(lexrc.getString(),
254                                                      '_', ' ');
255                                 if (!delete_layout(style))
256                                         lyxerr << "Cannot delete style `"
257                                                << style << '\'' << endl;
258 //                                      lexrc.printError("Cannot delete style"
259 //                                                       " `$$Token'");
260                         }
261                         break;
262
263                 case TC_COLUMNS:
264                         if (lexrc.next())
265                                 columns_ = lexrc.getInteger();
266                         break;
267
268                 case TC_SIDES:
269                         if (lexrc.next()) {
270                                 switch (lexrc.getInteger()) {
271                                 case 1: sides_ = OneSide; break;
272                                 case 2: sides_ = TwoSides; break;
273                                 default:
274                                         lyxerr << "Impossible number of page"
275                                                 " sides, setting to one."
276                                                << endl;
277                                         sides_ = OneSide;
278                                         break;
279                                 }
280                         }
281                         break;
282
283                 case TC_PAGESTYLE:
284                         lexrc.next();
285                         pagestyle_ = rtrim(lexrc.getString());
286                         break;
287
288                 case TC_DEFAULTFONT:
289                         defaultfont_.lyxRead(lexrc);
290                         if (!defaultfont_.resolved()) {
291                                 lexrc.printError("Warning: defaultfont should "
292                                                  "be fully instantiated!");
293                                 defaultfont_.realize(LyXFont(LyXFont::ALL_SANE));
294                         }
295                         break;
296
297                 case TC_MAXCOUNTER:
298                         readMaxCounter(lexrc);
299                         break;
300
301                 case TC_SECNUMDEPTH:
302                         lexrc.next();
303                         secnumdepth_ = lexrc.getInteger();
304                         break;
305
306                 case TC_TOCDEPTH:
307                         lexrc.next();
308                         tocdepth_ = lexrc.getInteger();
309                         break;
310
311                         // First step to support options
312                 case TC_CLASSOPTIONS:
313                         readClassOptions(lexrc);
314                         break;
315
316                 case TC_PREAMBLE:
317                         preamble_ = lexrc.getLongString("EndPreamble");
318                         break;
319
320                 case TC_PROVIDESAMSMATH:
321                         if (lexrc.next() && lexrc.getInteger())
322                                 provides_ |= amsmath;
323                         break;
324
325                 case TC_PROVIDESNATBIB:
326                         if (lexrc.next() && lexrc.getInteger())
327                                 provides_ |= natbib;
328                         break;
329
330                 case TC_PROVIDESMAKEIDX:
331                         if (lexrc.next() && lexrc.getInteger())
332                                 provides_ |= makeidx;
333                         break;
334
335                 case TC_PROVIDESURL:
336                         if (lexrc.next() && lexrc.getInteger())
337                                 provides_ |= url;
338                         break;
339
340                 case TC_LEFTMARGIN:     // left margin type
341                         if (lexrc.next())
342                                 leftmargin_ = lexrc.getString();
343                         break;
344
345                 case TC_RIGHTMARGIN:    // right margin type
346                         if (lexrc.next())
347                                 rightmargin_ = lexrc.getString();
348                         break;
349                 case TC_FLOAT:
350                         readFloat(lexrc);
351                         break;
352                 case TC_COUNTER:
353                         readCounter(lexrc);
354                         break;
355                 case TC_TITLELATEXTYPE:
356                         readTitleType(lexrc);
357                         break;
358                 case TC_TITLELATEXNAME:
359                         if (lexrc.next())
360                                 titlename_ = lexrc.getString();
361                         break;
362                 case TC_NOFLOAT:
363                         if (lexrc.next()) {
364                                 string const nofloat = lexrc.getString();
365                                 floatlist_->erase(nofloat);
366                         }
367                         break;
368                 }
369         }
370
371         if (!merge) { // we are at top level here.
372                 lyxerr[Debug::TCLASS] << "Finished reading textclass "
373                                       << MakeDisplayPath(filename)
374                                       << endl;
375                 if (defaultlayout_.empty()) {
376                         lyxerr << "Error: Textclass '" << name_
377                                << "' is missing a defaultstyle." << endl;
378                         error = true;
379                 }
380         } else
381                 lyxerr[Debug::TCLASS] << "Finished reading input file "
382                                       << MakeDisplayPath(filename)
383                                       << endl;
384
385         return error;
386 }
387
388
389 void LyXTextClass::readTitleType(LyXLex & lexrc)
390 {
391         keyword_item titleTypeTags[] = {
392                 { "commandafter", TITLE_COMMAND_AFTER },
393                 { "environment", TITLE_ENVIRONMENT }
394         };
395
396         pushpophelper pph(lexrc, titleTypeTags, TITLE_ENVIRONMENT);
397
398         int le = lexrc.lex();
399         switch (le) {
400         case LyXLex::LEX_UNDEF:
401                 lexrc.printError("Unknown output type `$$Token'");
402                 return;
403         case TITLE_COMMAND_AFTER:
404         case TITLE_ENVIRONMENT:
405                 titletype_ = static_cast<LYX_TITLE_LATEX_TYPES>(le);
406                 break;
407         default:
408                 lyxerr << "Unhandled value " << le
409                        << " in LyXTextClass::readTitleType." << endl;
410
411                 break;
412         }
413 }
414
415
416 void LyXTextClass::readOutputType(LyXLex & lexrc)
417 {
418         keyword_item outputTypeTags[] = {
419                 { "docbook", DOCBOOK },
420                 { "latex", LATEX },
421                 { "linuxdoc", LINUXDOC },
422                 { "literate", LITERATE }
423         };
424
425         pushpophelper pph(lexrc, outputTypeTags, LITERATE);
426
427         int le = lexrc.lex();
428         switch (le) {
429         case LyXLex::LEX_UNDEF:
430                 lexrc.printError("Unknown output type `$$Token'");
431                 return;
432         case LATEX:
433         case LINUXDOC:
434         case DOCBOOK:
435         case LITERATE:
436                 outputType_ = static_cast<OutputType>(le);
437                 break;
438         default:
439                 lyxerr << "Unhandled value " << le
440                        << " in LyXTextClass::readOutputType." << endl;
441
442                 break;
443         }
444 }
445
446
447 enum MaxCounterTags {
448         MC_COUNTER_CHAPTER = 1,
449         MC_COUNTER_SECTION,
450         MC_COUNTER_SUBSECTION,
451         MC_COUNTER_SUBSUBSECTION,
452         MC_COUNTER_PARAGRAPH,
453         MC_COUNTER_SUBPARAGRAPH,
454         MC_COUNTER_ENUMI,
455         MC_COUNTER_ENUMII,
456         MC_COUNTER_ENUMIII,
457         MC_COUNTER_ENUMIV
458 };
459
460
461 void LyXTextClass::readMaxCounter(LyXLex & lexrc)
462 {
463         keyword_item maxCounterTags[] = {
464                 {"counter_chapter", MC_COUNTER_CHAPTER },
465                 {"counter_enumi", MC_COUNTER_ENUMI },
466                 {"counter_enumii", MC_COUNTER_ENUMII },
467                 {"counter_enumiii", MC_COUNTER_ENUMIII },
468                 {"counter_enumiv", MC_COUNTER_ENUMIV },
469                 {"counter_paragraph", MC_COUNTER_PARAGRAPH },
470                 {"counter_section", MC_COUNTER_SECTION },
471                 {"counter_subparagraph", MC_COUNTER_SUBPARAGRAPH },
472                 {"counter_subsection", MC_COUNTER_SUBSECTION },
473                 {"counter_subsubsection", MC_COUNTER_SUBSUBSECTION }
474         };
475
476         pushpophelper pph(lexrc, maxCounterTags, MC_COUNTER_ENUMIV);
477
478         int le = lexrc.lex();
479         switch (le) {
480         case LyXLex::LEX_UNDEF:
481                 lexrc.printError("Unknown MaxCounter tag `$$Token'");
482                 return;
483         default:
484                 break;
485         }
486
487         switch (static_cast<MaxCounterTags>(le)) {
488         case MC_COUNTER_CHAPTER:
489                 maxcounter_ = LABEL_COUNTER_CHAPTER;
490                 break;
491         case MC_COUNTER_SECTION:
492                 maxcounter_ = LABEL_COUNTER_SECTION;
493                 break;
494         case MC_COUNTER_SUBSECTION:
495                 maxcounter_ = LABEL_COUNTER_SUBSECTION;
496                 break;
497         case MC_COUNTER_SUBSUBSECTION:
498                 maxcounter_ = LABEL_COUNTER_SUBSUBSECTION;
499                 break;
500         case MC_COUNTER_PARAGRAPH:
501                 maxcounter_ = LABEL_COUNTER_PARAGRAPH;
502                 break;
503         case MC_COUNTER_SUBPARAGRAPH:
504                 maxcounter_ = LABEL_COUNTER_SUBPARAGRAPH;
505                 break;
506         case MC_COUNTER_ENUMI:
507                 maxcounter_ = LABEL_COUNTER_ENUMI;
508                 break;
509         case MC_COUNTER_ENUMII:
510                 maxcounter_ = LABEL_COUNTER_ENUMII;
511                 break;
512         case MC_COUNTER_ENUMIII:
513                 maxcounter_ = LABEL_COUNTER_ENUMIII;
514                 break;
515         case MC_COUNTER_ENUMIV:
516                 maxcounter_ = LABEL_COUNTER_ENUMIV;
517                 break;
518         }
519 }
520
521
522 enum ClassOptionsTags {
523         CO_FONTSIZE = 1,
524         CO_PAGESTYLE,
525         CO_OTHER,
526         CO_END
527 };
528
529
530 void LyXTextClass::readClassOptions(LyXLex & lexrc)
531 {
532         keyword_item classOptionsTags[] = {
533                 {"end", CO_END },
534                 {"fontsize", CO_FONTSIZE },
535                 {"other", CO_OTHER },
536                 {"pagestyle", CO_PAGESTYLE }
537         };
538
539         lexrc.pushTable(classOptionsTags, CO_END);
540         bool getout = false;
541         while (!getout && lexrc.isOK()) {
542                 int le = lexrc.lex();
543                 switch (le) {
544                 case LyXLex::LEX_UNDEF:
545                         lexrc.printError("Unknown ClassOption tag `$$Token'");
546                         continue;
547                 default: break;
548                 }
549                 switch (static_cast<ClassOptionsTags>(le)) {
550                 case CO_FONTSIZE:
551                         lexrc.next();
552                         opt_fontsize_ = rtrim(lexrc.getString());
553                         break;
554                 case CO_PAGESTYLE:
555                         lexrc.next();
556                         opt_pagestyle_ = rtrim(lexrc.getString());
557                         break;
558                 case CO_OTHER:
559                         lexrc.next();
560                         options_ = lexrc.getString();
561                         break;
562                 case CO_END:
563                         getout = true;
564                         break;
565                 }
566         }
567         lexrc.popTable();
568 }
569
570
571 enum FloatTags {
572         FT_TYPE = 1,
573         FT_NAME,
574         FT_PLACEMENT,
575         FT_EXT,
576         FT_WITHIN,
577         FT_STYLE,
578         FT_LISTNAME,
579         FT_BUILTIN,
580         FT_END
581 };
582
583 void LyXTextClass::readFloat(LyXLex & lexrc)
584 {
585         keyword_item floatTags[] = {
586                 { "end", FT_END },
587                 { "extension", FT_EXT },
588                 { "guiname", FT_NAME },
589                 { "latexbuiltin", FT_BUILTIN },
590                 { "listname", FT_LISTNAME },
591                 { "numberwithin", FT_WITHIN },
592                 { "placement", FT_PLACEMENT },
593                 { "style", FT_STYLE },
594                 { "type", FT_TYPE }
595         };
596
597         lexrc.pushTable(floatTags, FT_END);
598
599         string type;
600         string placement;
601         string ext;
602         string within;
603         string style;
604         string name;
605         string listname;
606         bool builtin = false;
607
608         bool getout = false;
609         while (!getout && lexrc.isOK()) {
610                 int le = lexrc.lex();
611                 switch (le) {
612                 case LyXLex::LEX_UNDEF:
613                         lexrc.printError("Unknown ClassOption tag `$$Token'");
614                         continue;
615                 default: break;
616                 }
617                 switch (static_cast<FloatTags>(le)) {
618                 case FT_TYPE:
619                         lexrc.next();
620                         type = lexrc.getString();
621                         // Here we could check if this type is already defined
622                         // and modify it with the rest of the vars instead.
623                         break;
624                 case FT_NAME:
625                         lexrc.next();
626                         name = lexrc.getString();
627                         break;
628                 case FT_PLACEMENT:
629                         lexrc.next();
630                         placement = lexrc.getString();
631                         break;
632                 case FT_EXT:
633                         lexrc.next();
634                         ext = lexrc.getString();
635                         break;
636                 case FT_WITHIN:
637                         lexrc.next();
638                         within = lexrc.getString();
639                         if (within == "none")
640                                 within.erase();
641                         break;
642                 case FT_STYLE:
643                         lexrc.next();
644                         style = lexrc.getString();
645                         break;
646                 case FT_LISTNAME:
647                         lexrc.next();
648                         listname = lexrc.getString();
649                         break;
650                 case FT_BUILTIN:
651                         lexrc.next();
652                         builtin = lexrc.getBool();
653                         break;
654                 case FT_END:
655                         getout = true;
656                         break;
657                 }
658         }
659
660         // Here if have a full float if getout == true
661         if (getout) {
662                 Floating newfloat(type, placement, ext, within,
663                                   style, name, listname, builtin);
664                 floatlist_->newFloat(newfloat);
665         }
666
667         lexrc.popTable();
668 }
669
670
671 enum CounterTags {
672         CT_NAME = 1,
673         CT_WITHIN,
674         CT_END
675 };
676
677 void LyXTextClass::readCounter(LyXLex & lexrc)
678 {
679         keyword_item counterTags[] = {
680                 { "end", CT_END },
681                 { "name", CT_NAME },
682                 { "within", CT_WITHIN }
683         };
684
685         lexrc.pushTable(counterTags, CT_END);
686
687         string name;
688         string within;
689
690         bool getout = false;
691         while (!getout && lexrc.isOK()) {
692                 int le = lexrc.lex();
693                 switch (le) {
694                 case LyXLex::LEX_UNDEF:
695                         lexrc.printError("Unknown ClassOption tag `$$Token'");
696                         continue;
697                 default: break;
698                 }
699                 switch (static_cast<CounterTags>(le)) {
700                 case CT_NAME:
701                         lexrc.next();
702                         name = lexrc.getString();
703                         break;
704                 case CT_WITHIN:
705                         lexrc.next();
706                         within = lexrc.getString();
707                         if (within == "none")
708                                 within.erase();
709                         break;
710                 case CT_END:
711                         getout = true;
712                         break;
713                 }
714         }
715
716         // Here if have a full float if getout == true
717         if (getout) {
718                 if (within.empty()) {
719                         ctrs_->newCounter(name);
720                 } else {
721                         ctrs_->newCounter(name, within);
722                 }
723         }
724
725         lexrc.popTable();
726 }
727
728
729 LyXFont const & LyXTextClass::defaultfont() const
730 {
731         return defaultfont_;
732 }
733
734
735 string const & LyXTextClass::leftmargin() const
736 {
737         return leftmargin_;
738 }
739
740
741 string const & LyXTextClass::rightmargin() const
742 {
743         return rightmargin_;
744 }
745
746
747 bool LyXTextClass::hasLayout(string const & n) const
748 {
749         string const name = (n.empty() ? defaultLayoutName() : n);
750
751         return find_if(layoutlist_.begin(), layoutlist_.end(),
752                        compare_name(name))
753                 != layoutlist_.end();
754 }
755
756
757
758 LyXLayout_ptr const & LyXTextClass::operator[](string const & name) const
759 {
760         Assert(!name.empty());
761
762         LayoutList::const_iterator cit =
763                 find_if(layoutlist_.begin(),
764                         layoutlist_.end(),
765                         compare_name(name));
766
767         if (cit == layoutlist_.end()) {
768                 lyxerr << "We failed to find the layout '" << name
769                        << "' in the layout list. You MUST investigate!"
770                        << endl;
771                 for (LayoutList::const_iterator it = layoutlist_.begin();
772                          it != layoutlist_.end(); ++it)
773                         lyxerr  << " " << it->get()->name() << endl;
774
775                 // we require the name to exist
776                 Assert(false);
777         }
778
779         return (*cit);
780 }
781
782
783
784 bool LyXTextClass::delete_layout(string const & name)
785 {
786         if (name == defaultLayoutName())
787                 return false;
788
789         LayoutList::iterator it =
790                 remove_if(layoutlist_.begin(), layoutlist_.end(),
791                           compare_name(name));
792
793         LayoutList::iterator end = layoutlist_.end();
794         bool const ret = (it != end);
795         layoutlist_.erase(it, end);
796         return ret;
797 }
798
799
800 // Load textclass info if not loaded yet
801 bool LyXTextClass::load() const
802 {
803         if (loaded)
804                 return true;
805
806         // Read style-file
807         string const real_file = LibFileSearch("layouts", name_, "layout");
808
809         if (const_cast<LyXTextClass*>(this)->Read(real_file)) {
810                 lyxerr << "Error reading `"
811                        << MakeDisplayPath(real_file)
812                        << "'\n(Check `" << name_
813                        << "')\nCheck your installation and "
814                         "try Options/Reconfigure..." << endl;
815                 loaded = false;
816         }
817         loaded = true;
818         return loaded;
819 }
820
821
822 FloatList & LyXTextClass::floats()
823 {
824         return *floatlist_.get();
825 }
826
827
828 FloatList const & LyXTextClass::floats() const
829 {
830         return *floatlist_.get();
831 }
832
833
834 Counters & LyXTextClass::counters() const
835 {
836         return *ctrs_.get();
837 }
838
839
840 string const & LyXTextClass::defaultLayoutName() const
841 {
842         // This really should come from the actual layout... (Lgb)
843         return defaultlayout_;
844 }
845
846
847 LyXLayout_ptr const & LyXTextClass::defaultLayout() const
848 {
849         return operator[](defaultLayoutName());
850 }
851
852
853 string const & LyXTextClass::name() const
854 {
855         return name_;
856 }
857
858
859 string const & LyXTextClass::latexname() const
860 {
861         const_cast<LyXTextClass*>(this)->load();
862         return latexname_;
863 }
864
865
866 string const & LyXTextClass::description() const
867 {
868         return description_;
869 }
870
871
872 string const & LyXTextClass::opt_fontsize() const
873 {
874         return opt_fontsize_;
875 }
876
877
878 string const & LyXTextClass::opt_pagestyle() const
879 {
880         return opt_pagestyle_;
881 }
882
883
884 string const & LyXTextClass::options() const
885 {
886         return options_;
887 }
888
889
890 string const & LyXTextClass::pagestyle() const
891 {
892         return pagestyle_;
893 }
894
895
896 string const & LyXTextClass::preamble() const
897 {
898         return preamble_;
899 }
900
901
902 LyXTextClass::PageSides LyXTextClass::sides() const
903 {
904         return sides_;
905 }
906
907
908 int LyXTextClass::secnumdepth() const
909 {
910         return secnumdepth_;
911 }
912
913
914 int LyXTextClass::tocdepth() const
915 {
916         return tocdepth_;
917 }
918
919
920 OutputType LyXTextClass::outputType() const
921 {
922         return outputType_;
923 }
924
925
926 bool LyXTextClass::provides(LyXTextClass::Provides p) const
927 {
928         return provides_ & p;
929 }
930
931
932 unsigned int LyXTextClass::columns() const
933 {
934         return columns_;
935 }
936
937
938 int LyXTextClass::maxcounter() const
939 {
940         return maxcounter_;
941 }
942
943
944 LYX_TITLE_LATEX_TYPES LyXTextClass::titletype() const
945 {
946         return titletype_;
947 }
948
949
950 string const & LyXTextClass::titlename() const
951 {
952         return titlename_;
953 }
954
955
956
957
958
959 int LyXTextClass::size() const
960 {
961         return layoutlist_.size();
962 }
963
964
965 ostream & operator<<(ostream & os, LyXTextClass::PageSides p)
966 {
967         switch (p) {
968         case LyXTextClass::OneSide:
969                 os << '1';
970                 break;
971         case LyXTextClass::TwoSides:
972                 os << '2';
973                 break;
974         }
975         return os;
976 }