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