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