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