]> git.lyx.org Git - lyx.git/blob - src/insets/InsetLayout.cpp
Add required elements in the layouts to support DocBook.
[lyx.git] / src / insets / InsetLayout.cpp
1 // -*- C++ -*-
2 /**
3  * \file InsetLayout.cpp
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Martin Vermeer
8  * \author Richard Heck
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "InsetLayout.h"
16
17 #include "ColorSet.h"
18 #include "Layout.h"
19 #include "Lexer.h"
20 #include "TextClass.h"
21
22 #include "support/debug.h"
23 #include "support/lstrings.h"
24 #include "support/textutils.h"
25
26 #include <vector>
27
28 using std::string;
29 using std::set;
30 using std::vector;
31
32 using namespace lyx::support;
33
34 namespace lyx {
35
36 InsetLayout::InsetLayout() :
37         name_(from_ascii("undefined")), lyxtype_(STANDARD),
38         labelstring_(from_ascii("UNDEFINED")), contentaslabel_(false),
39         decoration_(DEFAULT), latextype_(NOLATEXTYPE), font_(inherit_font),
40         labelfont_(sane_font), bgcolor_(Color_error),
41         fixedwidthpreambleencoding_(false), htmlforcecss_ (false),
42         htmlisblock_(true), multipar_(true), custompars_(true),
43         forceplain_(false), passthru_(false), parbreakisnewline_(false),
44         parbreakignored_(false), freespacing_(false), keepempty_(false), forceltr_(false),
45         forceownlines_(false), needprotect_(false), needcprotect_(false),
46         needmboxprotect_(false), intoc_(false), spellcheck_(true),
47         resetsfont_(false), display_(true), forcelocalfontswitch_(false),
48         add_to_toc_(false), is_toc_caption_(false), edit_external_(false)
49 {
50         labelfont_.setColor(Color_error);
51 }
52
53
54 InsetLayout::InsetDecoration translateDecoration(std::string const & str)
55 {
56         if (compare_ascii_no_case(str, "classic") == 0)
57                 return InsetLayout::CLASSIC;
58         if (compare_ascii_no_case(str, "minimalistic") == 0)
59                 return InsetLayout::MINIMALISTIC;
60         if (compare_ascii_no_case(str, "conglomerate") == 0)
61                 return InsetLayout::CONGLOMERATE;
62         return InsetLayout::DEFAULT;
63 }
64
65 namespace {
66
67 InsetLayout::InsetLaTeXType translateLaTeXType(std::string const & str)
68 {
69         if (compare_ascii_no_case(str, "command") == 0)
70                 return InsetLayout::COMMAND;
71         if (compare_ascii_no_case(str, "environment") == 0)
72                 return InsetLayout::ENVIRONMENT;
73         if (compare_ascii_no_case(str, "none") == 0)
74                 return InsetLayout::NOLATEXTYPE;
75         return InsetLayout::ILT_ERROR;
76 }
77
78 } // namespace
79
80
81 bool InsetLayout::read(Lexer & lex, TextClass const & tclass,
82         bool validating)
83 {
84         enum {
85                 IL_ADDTOTOC,
86                 IL_ARGUMENT,
87                 IL_BABELPREAMBLE,
88                 IL_BGCOLOR,
89                 IL_CONTENTASLABEL,
90                 IL_COPYSTYLE,
91                 IL_COUNTER,
92                 IL_CUSTOMPARS,
93                 IL_DECORATION,
94                 IL_DISPLAY,
95                 IL_EDITEXTERNAL,
96                 IL_FIXEDWIDTH_PREAMBLE_ENCODING,
97                 IL_FONT,
98                 IL_FORCE_LOCAL_FONT_SWITCH,
99                 IL_FORCELTR,
100                 IL_FORCEOWNLINES,
101                 IL_FORCEPLAIN,
102                 IL_FREESPACING,
103                 IL_HTMLTAG,
104                 IL_HTMLATTR,
105                 IL_HTMLFORCECSS,
106                 IL_HTMLINNERTAG,
107                 IL_HTMLINNERATTR,
108                 IL_HTMLISBLOCK,
109                 IL_HTMLLABEL,
110                 IL_HTMLSTYLE,
111                 IL_HTMLPREAMBLE,
112                 IL_DOCBOOKTAG,
113                 IL_DOCBOOKATTR,
114                 IL_INTOC,
115                 IL_ISTOCCAPTION,
116                 IL_LABELFONT,
117                 IL_LABELSTRING,
118                 IL_LANGPREAMBLE,
119                 IL_LATEXNAME,
120                 IL_LATEXPARAM,
121                 IL_LATEXTYPE,
122                 IL_LEFTDELIM,
123                 IL_LYXTYPE,
124                 IL_OBSOLETEDBY,
125                 IL_KEEPEMPTY,
126                 IL_MENUSTRING,
127                 IL_MULTIPAR,
128                 IL_NEEDCPROTECT,
129                 IL_NEEDMBOXPROTECT,
130                 IL_NEEDPROTECT,
131                 IL_NEWLINE_CMD,
132                 IL_PASSTHRU,
133                 IL_PASSTHRU_CHARS,
134                 IL_PARBREAKIGNORED,
135                 IL_PARBREAKISNEWLINE,
136                 IL_PREAMBLE,
137                 IL_REQUIRES,
138                 IL_RIGHTDELIM,
139                 IL_REFPREFIX,
140                 IL_RESETARGS,
141                 IL_RESETSFONT,
142                 IL_SPELLCHECK,
143                 IL_END
144         };
145
146
147         LexerKeyword elementTags[] = {
148                 { "addtotoc", IL_ADDTOTOC },
149                 { "argument", IL_ARGUMENT },
150                 { "babelpreamble", IL_BABELPREAMBLE },
151                 { "bgcolor", IL_BGCOLOR },
152                 { "contentaslabel", IL_CONTENTASLABEL },
153                 { "copystyle", IL_COPYSTYLE },
154                 { "counter", IL_COUNTER},
155                 { "custompars", IL_CUSTOMPARS },
156                 { "decoration", IL_DECORATION },
157                 { "display", IL_DISPLAY },
158                 { "docbookattr", IL_DOCBOOKATTR },
159                 { "docbooktag", IL_DOCBOOKTAG },
160                 { "editexternal", IL_EDITEXTERNAL },
161                 { "end", IL_END },
162                 { "fixedwidthpreambleencoding", IL_FIXEDWIDTH_PREAMBLE_ENCODING },
163                 { "font", IL_FONT },
164                 { "forcelocalfontswitch", IL_FORCE_LOCAL_FONT_SWITCH },
165                 { "forceltr", IL_FORCELTR },
166                 { "forceownlines", IL_FORCEOWNLINES },
167                 { "forceplain", IL_FORCEPLAIN },
168                 { "freespacing", IL_FREESPACING },
169                 { "htmlattr", IL_HTMLATTR },
170                 { "htmlforcecss", IL_HTMLFORCECSS },
171                 { "htmlinnerattr", IL_HTMLINNERATTR},
172                 { "htmlinnertag", IL_HTMLINNERTAG},
173                 { "htmlisblock", IL_HTMLISBLOCK},
174                 { "htmllabel", IL_HTMLLABEL },
175                 { "htmlpreamble", IL_HTMLPREAMBLE },
176                 { "htmlstyle", IL_HTMLSTYLE },
177                 { "htmltag", IL_HTMLTAG },
178                 { "intoc", IL_INTOC },
179                 { "istoccaption", IL_ISTOCCAPTION },
180                 { "keepempty", IL_KEEPEMPTY },
181                 { "labelfont", IL_LABELFONT },
182                 { "labelstring", IL_LABELSTRING },
183                 { "langpreamble", IL_LANGPREAMBLE },
184                 { "latexname", IL_LATEXNAME },
185                 { "latexparam", IL_LATEXPARAM },
186                 { "latextype", IL_LATEXTYPE },
187                 { "leftdelim", IL_LEFTDELIM },
188                 { "lyxtype", IL_LYXTYPE },
189                 { "menustring", IL_MENUSTRING },
190                 { "multipar", IL_MULTIPAR },
191                 { "needcprotect", IL_NEEDCPROTECT },
192                 { "needmboxprotect", IL_NEEDMBOXPROTECT },
193                 { "needprotect", IL_NEEDPROTECT },
194                 { "newlinecmd", IL_NEWLINE_CMD },
195                 { "obsoletedby", IL_OBSOLETEDBY },
196                 { "parbreakignored", IL_PARBREAKIGNORED },
197                 { "parbreakisnewline", IL_PARBREAKISNEWLINE },
198                 { "passthru", IL_PASSTHRU },
199                 { "passthruchars", IL_PASSTHRU_CHARS },
200                 { "preamble", IL_PREAMBLE },
201                 { "refprefix", IL_REFPREFIX },
202                 { "requires", IL_REQUIRES },
203                 { "resetargs", IL_RESETARGS },
204                 { "resetsfont", IL_RESETSFONT },
205                 { "rightdelim", IL_RIGHTDELIM },
206                 { "spellcheck", IL_SPELLCHECK }
207         };
208
209         lex.pushTable(elementTags);
210
211         labelfont_ = inherit_font;
212         bgcolor_ = Color_none;
213         bool getout = false;
214         // whether we've read the CustomPars or ForcePlain tag
215         // for issuing a warning in case MultiPars comes later
216         bool readCustomOrPlain = false;
217
218         string tmp;
219         while (!getout && lex.isOK()) {
220                 int le = lex.lex();
221                 switch (le) {
222                 case Lexer::LEX_UNDEF:
223                         lex.printError("Unknown InsetLayout tag");
224                         if (validating)
225                                 return false;
226                         continue;
227                 default:
228                         break;
229                 }
230                 switch (le) {
231                 // FIXME
232                 // Perhaps a more elegant way to deal with the next two would be the
233                 // way this sort of thing is handled in Layout::read(), namely, by
234                 // using the Lexer.
235                 case IL_LYXTYPE: {
236                         // make sure that we have the right sort of name.
237                         if (name_ != from_ascii("undefined")
238                             && name_.substr(0,5) != from_ascii("Flex:")) {
239                                 LYXERR0("Flex insets must have names of the form `Flex:<name>'.\n"
240                                         "This one has the name `" << to_utf8(name_) << "'\n"
241                                         "Ignoring LyXType declaration.");
242                                 // this is not really a reason to abort
243                                 if (validating)
244                                         return false;
245                                 break;
246                         }
247                         string lt;
248                         lex >> lt;
249                         lyxtype_ = translateLyXType(lt);
250                         if (lyxtype_  == NOLYXTYPE) {
251                                 LYXERR0("Unknown LyXType `" << lt << "'.");
252                                 // this is not really a reason to abort
253                                 if (validating)
254                                         return false;
255                         }
256                         if (lyxtype_ == CHARSTYLE) {
257                                 // by default, charstyles force the plain layout
258                                 multipar_ = false;
259                                 forceplain_ = true;
260                         }
261                         break;
262                 }
263                 case IL_LATEXTYPE:  {
264                         string lt;
265                         lex >> lt;
266                         latextype_ = translateLaTeXType(lt);
267                         if (latextype_  == ILT_ERROR) {
268                                 LYXERR0("Unknown LaTeXType `" << lt << "'.");
269                                 // this is not really a reason to abort
270                                 if (validating)
271                                         return false;
272                         }
273                         break;
274                 }
275                 case IL_LABELSTRING:
276                         lex >> labelstring_;
277                         break;
278                 case IL_MENUSTRING:
279                         lex >> menustring_;
280                         break;
281                 case IL_DECORATION:
282                         lex >> tmp;
283                         decoration_ = translateDecoration(tmp);
284                         break;
285                 case IL_LATEXNAME:
286                         lex >> latexname_;
287                         break;
288                 case IL_LATEXPARAM:
289                         lex >> tmp;
290                         latexparam_ = subst(tmp, "&quot;", "\"");
291                         break;
292                 case IL_LEFTDELIM:
293                         lex >> leftdelim_;
294                         leftdelim_ = subst(leftdelim_, from_ascii("<br/>"),
295                                                     from_ascii("\n"));
296                         break;
297                 case IL_FIXEDWIDTH_PREAMBLE_ENCODING:
298                         lex >> fixedwidthpreambleencoding_;
299                         break;
300                 case IL_FORCE_LOCAL_FONT_SWITCH:
301                         lex >> forcelocalfontswitch_;
302                         break;
303                 case IL_RIGHTDELIM:
304                         lex >> rightdelim_;
305                         rightdelim_ = subst(rightdelim_, from_ascii("<br/>"),
306                                                      from_ascii("\n"));
307                         break;
308                 case IL_LABELFONT:
309                         labelfont_ = lyxRead(lex, inherit_font);
310                         break;
311                 case IL_FORCELTR:
312                         lex >> forceltr_;
313                         break;
314                 case IL_FORCEOWNLINES:
315                         lex >> forceownlines_;
316                         break;
317                 case IL_INTOC:
318                         lex >> intoc_;
319                         break;
320                 case IL_MULTIPAR:
321                         lex >> multipar_;
322                         // the defaults for these depend upon multipar_
323                         if (readCustomOrPlain)
324                                 LYXERR0("Warning: Read MultiPar after CustomPars or ForcePlain. "
325                                         "Previous value may be overwritten!");
326                         readCustomOrPlain = false;
327                         custompars_ = multipar_;
328                         forceplain_ = !multipar_;
329                         break;
330                 case IL_COUNTER:
331                         lex >> counter_;
332                         break;
333                 case IL_CUSTOMPARS:
334                         lex >> custompars_;
335                         readCustomOrPlain = true;
336                         break;
337                 case IL_FORCEPLAIN:
338                         lex >> forceplain_;
339                         readCustomOrPlain = true;
340                         break;
341                 case IL_PASSTHRU:
342                         lex >> passthru_;
343                         break;
344                 case IL_PASSTHRU_CHARS:
345                         lex >> passthru_chars_;
346                         break;
347                 case IL_NEWLINE_CMD:
348                         lex >> newline_cmd_;
349                         break;
350                 case IL_PARBREAKIGNORED:
351                         lex >> parbreakignored_;
352                         break;
353                 case IL_PARBREAKISNEWLINE:
354                         lex >> parbreakisnewline_;
355                         break;
356                 case IL_KEEPEMPTY:
357                         lex >> keepempty_;
358                         break;
359                 case IL_FREESPACING:
360                         lex >> freespacing_;
361                         break;
362                 case IL_NEEDPROTECT:
363                         lex >> needprotect_;
364                         break;
365                 case IL_NEEDCPROTECT:
366                         lex >> needcprotect_;
367                         break;
368                 case IL_NEEDMBOXPROTECT:
369                         lex >> needmboxprotect_;
370                         break;
371                 case IL_CONTENTASLABEL:
372                         lex >> contentaslabel_;
373                         break;
374                 case IL_COPYSTYLE: {
375                         // initialize with a known style
376                         docstring style;
377                         lex >> style;
378                         style = subst(style, '_', ' ');
379
380                         // We don't want to apply the algorithm in DocumentClass::insetLayout()
381                         // here. So we do it the long way.
382                         TextClass::InsetLayouts::const_iterator it =
383                                         tclass.insetLayouts().find(style);
384                         if (it != tclass.insetLayouts().end()) {
385                                 docstring const tmpname = name_;
386                                 this->operator=(it->second);
387                                 name_ = tmpname;
388                         } else {
389                                 LYXERR0("Cannot copy unknown InsetLayout `"
390                                         << style << "' to InsetLayout `"
391                                         << name() << "'\n"
392                                         << "All InsetLayouts so far:");
393                                 TextClass::InsetLayouts::const_iterator lit =
394                                                 tclass.insetLayouts().begin();
395                                 TextClass::InsetLayouts::const_iterator len =
396                                                 tclass.insetLayouts().end();
397                                 for (; lit != len; ++lit)
398                                         lyxerr << lit->second.name() << "\n";
399                                 // this is not really a reason to abort
400                                 if (validating)
401                                         return false;
402                         }
403                         break;
404                 }
405                 case IL_OBSOLETEDBY: {
406                         docstring style;
407                         lex >> style;
408                         style = subst(style, '_', ' ');
409
410                         // We don't want to apply the algorithm in DocumentClass::insetLayout()
411                         // here. So we do it the long way.
412                         TextClass::InsetLayouts::const_iterator it =
413                                         tclass.insetLayouts().find(style);
414                         if (it != tclass.insetLayouts().end()) {
415                                 docstring const tmpname = name_;
416                                 this->operator=(it->second);
417                                 name_ = tmpname;
418                                 if (obsoleted_by().empty())
419                                         obsoleted_by_ = style;
420                         } else {
421                                 LYXERR0("Cannot replace InsetLayout `"
422                                         << name()
423                                         << "' with unknown InsetLayout `"
424                                         << style << "'\n"
425                                         << "All InsetLayouts so far:");
426                                 TextClass::InsetLayouts::const_iterator lit =
427                                                 tclass.insetLayouts().begin();
428                                 TextClass::InsetLayouts::const_iterator len =
429                                                 tclass.insetLayouts().end();
430                                 for (; lit != len; ++lit)
431                                         lyxerr << lit->second.name() << "\n";
432                                 // this is not really a reason to abort
433                                 if (validating)
434                                         return false;
435                         }
436                         break;
437                 }
438
439                 case IL_FONT: {
440                         font_ = lyxRead(lex, inherit_font);
441                         // If you want to define labelfont, you need to do so after
442                         // font is defined.
443                         labelfont_ = font_;
444                         break;
445                 }
446                 case IL_RESETARGS:
447                         bool reset;
448                         lex >> reset;
449                         if (reset) {
450                                 latexargs_.clear();
451                                 postcommandargs_.clear();
452                         }
453                         break;
454                 case IL_ARGUMENT:
455                         readArgument(lex);
456                         break;
457                 case IL_BGCOLOR:
458                         lex >> tmp;
459                         bgcolor_ = lcolor.getFromLyXName(tmp);
460                         break;
461                 case IL_PREAMBLE:
462                         preamble_ = lex.getLongString(from_ascii("EndPreamble"));
463                         break;
464                 case IL_BABELPREAMBLE:
465                         babelpreamble_ = lex.getLongString(from_ascii("EndBabelPreamble"));
466                         break;
467                 case IL_LANGPREAMBLE:
468                         langpreamble_ = lex.getLongString(from_ascii("EndLangPreamble"));
469                         break;
470                 case IL_REFPREFIX:
471                         lex >> refprefix_;
472                         break;
473                 case IL_HTMLTAG:
474                         lex >> htmltag_;
475                         break;
476                 case IL_HTMLATTR:
477                         lex >> htmlattr_;
478                         break;
479                 case IL_HTMLFORCECSS:
480                         lex >> htmlforcecss_;
481                         break;
482                 case IL_HTMLINNERTAG:
483                         lex >> htmlinnertag_;
484                         break;
485                 case IL_HTMLINNERATTR:
486                         lex >> htmlinnerattr_;
487                         break;
488                 case IL_HTMLLABEL:
489                         lex >> htmllabel_;
490                         break;
491                 case IL_HTMLISBLOCK:
492                         lex >> htmlisblock_;
493                         break;
494                 case IL_HTMLSTYLE:
495                         htmlstyle_ = lex.getLongString(from_ascii("EndHTMLStyle"));
496                         break;
497                 case IL_HTMLPREAMBLE:
498                         htmlpreamble_ = lex.getLongString(from_ascii("EndPreamble"));
499                         break;
500                 case IL_DOCBOOKTAG:
501                         lex >> docbooktag_;
502                         break;
503                 case IL_DOCBOOKATTR:
504                         lex >> docbookattr_;
505                         break;
506                 case IL_REQUIRES: {
507                         lex.eatLine();
508                         vector<string> const req
509                                 = getVectorFromString(lex.getString(true));
510                         required_.insert(req.begin(), req.end());
511                         break;
512                 }
513                 case IL_SPELLCHECK:
514                         lex >> spellcheck_;
515                         break;
516                 case IL_RESETSFONT:
517                         lex >> resetsfont_;
518                         break;
519                 case IL_DISPLAY:
520                         lex >> display_;
521                         break;
522                 case IL_ADDTOTOC:
523                         lex >> toc_type_;
524                         add_to_toc_ = !toc_type_.empty();
525                         break;
526                 case IL_ISTOCCAPTION:
527                         lex >> is_toc_caption_;
528                         break;
529                 case IL_EDITEXTERNAL:
530                         lex >> edit_external_;
531                         break;
532                 case IL_END:
533                         getout = true;
534                         break;
535                 }
536         }
537
538         // Here add element to list if getout == true
539         if (!getout)
540                 return false;
541
542         // The label font is generally used as-is without
543         // any realization against a given context.
544         labelfont_.realize(sane_font);
545
546         lex.popTable();
547         return true;
548 }
549
550
551 InsetLayout::InsetLyXType translateLyXType(std::string const & str)
552 {
553         if (compare_ascii_no_case(str, "charstyle") == 0)
554                 return InsetLayout::CHARSTYLE;
555         if (compare_ascii_no_case(str, "custom") == 0)
556                 return InsetLayout::CUSTOM;
557         if (compare_ascii_no_case(str, "end") == 0)
558                 return InsetLayout::END;
559         if (compare_ascii_no_case(str, "standard") == 0)
560                 return InsetLayout::STANDARD;
561         return InsetLayout::NOLYXTYPE;
562 }
563
564
565 string const & InsetLayout::htmltag() const
566 {
567         if (htmltag_.empty())
568                 htmltag_ = multipar_ ? "div" : "span";
569         return htmltag_;
570 }
571
572
573 string const & InsetLayout::htmlattr() const
574 {
575         if (htmlattr_.empty())
576                 htmlattr_ = "class=\"" + defaultCSSClass() + "\"";
577         return htmlattr_;
578 }
579
580
581 string const & InsetLayout::htmlinnerattr() const
582 {
583         if (htmlinnerattr_.empty())
584                 htmlinnerattr_ = "class=\"" + defaultCSSClass() + "_inner\"";
585         return htmlinnerattr_;
586 }
587
588
589 string InsetLayout::defaultCSSClass() const
590 {
591         if (!defaultcssclass_.empty())
592                 return defaultcssclass_;
593         string d;
594         string n = to_utf8(name());
595         string::const_iterator it = n.begin();
596         string::const_iterator en = n.end();
597         for (; it != en; ++it) {
598                 if (!isAlphaASCII(*it))
599                         d += "_";
600                 else if (isLower(*it))
601                         d += *it;
602                 else
603                         d += lowercase(*it);
604         }
605         // are there other characters we need to remove?
606         defaultcssclass_ = d;
607         return defaultcssclass_;
608 }
609
610
611 void InsetLayout::makeDefaultCSS() const
612 {
613         if (!htmldefaultstyle_.empty())
614                 return;
615         docstring const mainfontCSS = font_.asCSS();
616         if (!mainfontCSS.empty())
617                 htmldefaultstyle_ =
618                                 from_ascii(htmltag() + "." + defaultCSSClass() + " {\n") +
619                                 mainfontCSS + from_ascii("\n}\n");
620 }
621
622
623 docstring InsetLayout::htmlstyle() const
624 {
625         if (!htmlstyle_.empty() && !htmlforcecss_)
626                 return htmlstyle_;
627         if (htmldefaultstyle_.empty())
628                 makeDefaultCSS();
629         docstring retval = htmldefaultstyle_;
630         if (!htmlstyle_.empty())
631                 retval += '\n' + htmlstyle_ + '\n';
632         return retval;
633 }
634
635 void InsetLayout::readArgument(Lexer & lex)
636 {
637         Layout::latexarg arg;
638         arg.mandatory = false;
639         arg.autoinsert = false;
640         arg.insertcotext = false;
641         arg.insertonnewline = false;
642         bool error = false;
643         bool finished = false;
644         arg.font = inherit_font;
645         arg.labelfont = inherit_font;
646         arg.is_toc_caption = false;
647         arg.free_spacing = false;
648         arg.passthru = PT_INHERITED;
649         arg.nodelims = false;
650         string nr;
651         lex >> nr;
652         bool const postcmd = prefixIs(nr, "post:");
653         while (!finished && lex.isOK() && !error) {
654                 lex.next();
655                 string const tok = ascii_lowercase(lex.getString());
656
657                 if (tok.empty()) {
658                         continue;
659                 } else if (tok == "endargument") {
660                         finished = true;
661                 } else if (tok == "labelstring") {
662                         lex.next();
663                         arg.labelstring = lex.getDocString();
664                 } else if (tok == "menustring") {
665                         lex.next();
666                         arg.menustring = lex.getDocString();
667                 } else if (tok == "mandatory") {
668                         lex.next();
669                         arg.mandatory = lex.getBool();
670                 } else if (tok == "autoinsert") {
671                         lex.next();
672                         arg.autoinsert = lex.getBool();
673                 } else if (tok == "insertcotext") {
674                         lex.next();
675                         arg.insertcotext = lex.getBool();
676                 } else if (tok == "insertonnewline") {
677                         lex.next();
678                         arg.insertonnewline = lex.getBool();
679                 } else if (tok == "leftdelim") {
680                         lex.next();
681                         arg.ldelim = lex.getDocString();
682                         arg.ldelim = subst(arg.ldelim,
683                                                     from_ascii("<br/>"), from_ascii("\n"));
684                 } else if (tok == "rightdelim") {
685                         lex.next();
686                         arg.rdelim = lex.getDocString();
687                         arg.rdelim = subst(arg.rdelim,
688                                                     from_ascii("<br/>"), from_ascii("\n"));
689                 } else if (tok == "defaultarg") {
690                         lex.next();
691                         arg.defaultarg = lex.getDocString();
692                 } else if (tok == "presetarg") {
693                         lex.next();
694                         arg.presetarg = lex.getDocString();
695                 } else if (tok == "tooltip") {
696                         lex.next();
697                         arg.tooltip = lex.getDocString();
698                 } else if (tok == "requires") {
699                         lex.next();
700                         arg.required = lex.getString();
701                 } else if (tok == "decoration") {
702                         lex.next();
703                         arg.decoration = lex.getString();
704                 } else if (tok == "newlinecmd") {
705                         lex.next();
706                         arg.newlinecmd = lex.getString();
707                 } else if (tok == "font") {
708                         arg.font = lyxRead(lex, arg.font);
709                 } else if (tok == "labelfont") {
710                         arg.labelfont = lyxRead(lex, arg.labelfont);
711                 } else if (tok == "passthruchars") {
712                         lex.next();
713                         arg.pass_thru_chars = lex.getDocString();
714                 } else if (tok == "passthru") {
715                         lex.next();
716                         docstring value = lex.getDocString();
717                         if (value == "true" || value == "1")
718                                 arg.passthru = PT_TRUE;
719                         else if (value == "false" || value == "0")
720                                 arg.passthru = PT_FALSE;
721                         else
722                                 arg.passthru = PT_INHERITED;
723                 } else if (tok == "istoccaption") {
724                         lex.next();
725                         arg.is_toc_caption = lex.getBool();
726                 } else if (tok == "freespacing") {
727                         lex.next();
728                         arg.free_spacing = lex.getBool();
729                 } else {
730                         lex.printError("Unknown tag");
731                         error = true;
732                 }
733         }
734         if (arg.labelstring.empty())
735                 LYXERR0("Incomplete Argument definition!");
736         else if (postcmd)
737                 postcommandargs_[nr] = arg;
738         else
739                 latexargs_[nr] = arg;
740 }
741
742
743 Layout::LaTeXArgMap InsetLayout::args() const
744 {
745         Layout::LaTeXArgMap args = latexargs_;
746         if (!postcommandargs_.empty())
747                 args.insert(postcommandargs_.begin(), postcommandargs_.end());
748         return args;
749 }
750
751
752 unsigned int InsetLayout::optArgs() const
753 {
754         unsigned int nr = 0;
755         Layout::LaTeXArgMap const args = InsetLayout::args();
756         Layout::LaTeXArgMap::const_iterator it = args.begin();
757         for (; it != args.end(); ++it) {
758                 if (!(*it).second.mandatory)
759                         ++nr;
760         }
761         return nr;
762 }
763
764
765 unsigned int InsetLayout::requiredArgs() const
766 {
767         unsigned int nr = 0;
768         Layout::LaTeXArgMap const args = InsetLayout::args();
769         Layout::LaTeXArgMap::const_iterator it = args.begin();
770         for (; it != args.end(); ++it) {
771                 if ((*it).second.mandatory)
772                         ++nr;
773         }
774         return nr;
775 }
776
777
778 } //namespace lyx