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