]> git.lyx.org Git - lyx.git/blob - src/insets/InsetLayout.cpp
Overtake layout translations from ko.po
[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                                 multipar_ = false;
231                         break;
232                 }
233                 case IL_LATEXTYPE:  {
234                         string lt;
235                         lex >> lt;
236                         latextype_ = translateLaTeXType(lt);
237                         if (latextype_  == ILT_ERROR)
238                                 LYXERR0("Unknown LaTeXType `" << lt << "'.");
239                         break;
240                 }
241                 case IL_LABELSTRING:
242                         lex >> labelstring_;
243                         break;
244                 case IL_DECORATION:
245                         lex >> tmp;
246                         decoration_ = translateDecoration(tmp);
247                         break;
248                 case IL_LATEXNAME:
249                         lex >> latexname_;
250                         break;
251                 case IL_LATEXPARAM:
252                         lex >> tmp;
253                         latexparam_ = subst(tmp, "&quot;", "\"");
254                         break;
255                 case IL_LEFTDELIM:
256                         lex >> leftdelim_;
257                         leftdelim_ = subst(leftdelim_, from_ascii("<br/>"),
258                                                     from_ascii("\n"));
259                         break;
260                 case IL_FIXEDWIDTH_PREAMBLE_ENCODING:
261                         lex >> fixedwidthpreambleencoding_;
262                         break;
263                 case IL_FORCE_LOCAL_FONT_SWITCH:
264                         lex >> forcelocalfontswitch_;
265                         break;
266                 case IL_RIGHTDELIM:
267                         lex >> rightdelim_;
268                         rightdelim_ = subst(rightdelim_, from_ascii("<br/>"),
269                                                      from_ascii("\n"));
270                         break;
271                 case IL_LABELFONT:
272                         labelfont_ = lyxRead(lex, inherit_font);
273                         break;
274                 case IL_FORCELTR:
275                         lex >> forceltr_;
276                         break;
277                 case IL_FORCEOWNLINES:
278                         lex >> forceownlines_;
279                         break;
280                 case IL_INTOC:
281                         lex >> intoc_;
282                         break;
283                 case IL_MULTIPAR:
284                         lex >> multipar_;
285                         // the defaults for these depend upon multipar_
286                         if (readCustomOrPlain)
287                                 LYXERR0("Warning: Read MultiPar after CustomPars or ForcePlain. "
288                                         "Previous value may be overwritten!");
289                         readCustomOrPlain = false;
290                         custompars_ = multipar_;
291                         forceplain_ = !multipar_;
292                         break;
293                 case IL_COUNTER:
294                         lex >> counter_;
295                         break;
296                 case IL_CUSTOMPARS:
297                         lex >> custompars_;
298                         readCustomOrPlain = true;
299                         break;
300                 case IL_FORCEPLAIN:
301                         lex >> forceplain_;
302                         readCustomOrPlain = true;
303                         break;
304                 case IL_PASSTHRU:
305                         lex >> passthru_;
306                         break;
307                 case IL_PASSTHRU_CHARS:
308                         lex >> passthru_chars_;
309                         break;
310                 case IL_PARBREAKISNEWLINE:
311                         lex >> parbreakisnewline_;
312                         break;
313                 case IL_KEEPEMPTY:
314                         lex >> keepempty_;
315                         break;
316                 case IL_FREESPACING:
317                         lex >> freespacing_;
318                         break;
319                 case IL_NEEDPROTECT:
320                         lex >> needprotect_;
321                         break;
322                 case IL_CONTENTASLABEL:
323                         lex >> contentaslabel_;
324                         break;
325                 case IL_COPYSTYLE: {
326                         // initialize with a known style
327                         docstring style;
328                         lex >> style;
329                         style = subst(style, '_', ' ');
330
331                         // We don't want to apply the algorithm in DocumentClass::insetLayout()
332                         // here. So we do it the long way.
333                         TextClass::InsetLayouts::const_iterator it =
334                                         tclass.insetLayouts().find(style);
335                         if (it != tclass.insetLayouts().end()) {
336                                 docstring const tmpname = name_;
337                                 this->operator=(it->second);
338                                 name_ = tmpname;
339                         } else {
340                                 LYXERR0("Cannot copy unknown InsetLayout `"
341                                         << style << "' to InsetLayout `"
342                                         << name() << "'\n"
343                                         << "All InsetLayouts so far:");
344                                 TextClass::InsetLayouts::const_iterator lit =
345                                                 tclass.insetLayouts().begin();
346                                 TextClass::InsetLayouts::const_iterator len =
347                                                 tclass.insetLayouts().end();
348                                 for (; lit != len; ++lit)
349                                         lyxerr << lit->second.name() << "\n";
350                         }
351                         break;
352                 }
353                 case IL_OBSOLETEDBY: {
354                         docstring style;
355                         lex >> style;
356                         style = subst(style, '_', ' ');
357
358                         // We don't want to apply the algorithm in DocumentClass::insetLayout()
359                         // here. So we do it the long way.
360                         TextClass::InsetLayouts::const_iterator it =
361                                         tclass.insetLayouts().find(style);
362                         if (it != tclass.insetLayouts().end()) {
363                                 docstring const tmpname = name_;
364                                 this->operator=(it->second);
365                                 name_ = tmpname;
366                                 if (obsoleted_by().empty())
367                                         obsoleted_by_ = style;
368                         } else {
369                                 LYXERR0("Cannot replace InsetLayout `"
370                                         << name()
371                                         << "' with unknown InsetLayout `"
372                                         << style << "'\n"
373                                         << "All InsetLayouts so far:");
374                                 TextClass::InsetLayouts::const_iterator lit =
375                                                 tclass.insetLayouts().begin();
376                                 TextClass::InsetLayouts::const_iterator len =
377                                                 tclass.insetLayouts().end();
378                                 for (; lit != len; ++lit)
379                                         lyxerr << lit->second.name() << "\n";
380                         }
381                         break;
382                 }
383
384                 case IL_FONT: {
385                         font_ = lyxRead(lex, inherit_font);
386                         // If you want to define labelfont, you need to do so after
387                         // font is defined.
388                         labelfont_ = font_;
389                         break;
390                 }
391                 case IL_RESETARGS:
392                         bool reset;
393                         lex >> reset;
394                         if (reset) {
395                                 latexargs_.clear();
396                                 postcommandargs_.clear();
397                         }
398                         break;
399                 case IL_ARGUMENT:
400                         readArgument(lex);
401                         break;
402                 case IL_BGCOLOR:
403                         lex >> tmp;
404                         bgcolor_ = lcolor.getFromLyXName(tmp);
405                         break;
406                 case IL_PREAMBLE:
407                         preamble_ = from_utf8(lex.getLongString("EndPreamble"));
408                         break;
409                 case IL_BABELPREAMBLE:
410                         babelpreamble_ = from_utf8(lex.getLongString("EndBabelPreamble"));
411                         break;
412                 case IL_LANGPREAMBLE:
413                         langpreamble_ = from_utf8(lex.getLongString("EndLangPreamble"));
414                         break;
415                 case IL_REFPREFIX:
416                         lex >> refprefix_;
417                         break;
418                 case IL_HTMLTAG:
419                         lex >> htmltag_;
420                         break;
421                 case IL_HTMLATTR:
422                         lex >> htmlattr_;
423                         break;
424                 case IL_HTMLFORCECSS:
425                         lex >> htmlforcecss_;
426                         break;
427                 case IL_HTMLINNERTAG:
428                         lex >> htmlinnertag_;
429                         break;
430                 case IL_HTMLINNERATTR:
431                         lex >> htmlinnerattr_;
432                         break;
433                 case IL_HTMLLABEL:
434                         lex >> htmllabel_;
435                         break;
436                 case IL_HTMLISBLOCK:
437                         lex >> htmlisblock_;
438                         break;
439                 case IL_HTMLSTYLE:
440                         htmlstyle_ = from_utf8(lex.getLongString("EndHTMLStyle"));
441                         break;
442                 case IL_HTMLPREAMBLE:
443                         htmlpreamble_ = from_utf8(lex.getLongString("EndPreamble"));
444                         break;
445                 case IL_REQUIRES: {
446                         lex.eatLine();
447                         vector<string> const req
448                                 = getVectorFromString(lex.getString(true));
449                         requires_.insert(req.begin(), req.end());
450                         break;
451                 }
452                 case IL_SPELLCHECK:
453                         lex >> spellcheck_;
454                         break;
455                 case IL_RESETSFONT:
456                         lex >> resetsfont_;
457                         break;
458                 case IL_DISPLAY:
459                         lex >> display_;
460                         break;
461                 case IL_ADDTOTOC:
462                         lex >> toc_type_;
463                         add_to_toc_ = !toc_type_.empty();
464                         break;
465                 case IL_ISTOCCAPTION:
466                         lex >> is_toc_caption_;
467                         break;
468                 case IL_END:
469                         getout = true;
470                         break;
471                 }
472         }
473
474         // Here add element to list if getout == true
475         if (!getout)
476                 return false;
477
478         // The label font is generally used as-is without
479         // any realization against a given context.
480         labelfont_.realize(sane_font);
481
482         lex.popTable();
483         return true;
484 }
485
486
487 InsetLayout::InsetLyXType translateLyXType(std::string const & str)
488 {
489         if (compare_ascii_no_case(str, "charstyle") == 0)
490                 return InsetLayout::CHARSTYLE;
491         if (compare_ascii_no_case(str, "custom") == 0)
492                 return InsetLayout::CUSTOM;
493         if (compare_ascii_no_case(str, "element") == 0)
494                 return InsetLayout::ELEMENT;
495         if (compare_ascii_no_case(str, "end") == 0)
496                 return InsetLayout::END;
497         if (compare_ascii_no_case(str, "standard") == 0)
498                 return InsetLayout::STANDARD;
499         return InsetLayout::NOLYXTYPE;
500 }
501
502
503 string const & InsetLayout::htmltag() const
504 {
505         if (htmltag_.empty())
506                 htmltag_ = multipar_ ? "div" : "span";
507         return htmltag_;
508 }
509
510
511 string const & InsetLayout::htmlattr() const
512 {
513         if (htmlattr_.empty())
514                 htmlattr_ = "class=\"" + defaultCSSClass() + "\"";
515         return htmlattr_;
516 }
517
518
519 string const & InsetLayout::htmlinnerattr() const
520 {
521         if (htmlinnerattr_.empty())
522                 htmlinnerattr_ = "class=\"" + defaultCSSClass() + "_inner\"";
523         return htmlinnerattr_;
524 }
525
526
527 string InsetLayout::defaultCSSClass() const
528 {
529         if (!defaultcssclass_.empty())
530                 return defaultcssclass_;
531         string d;
532         string n = to_utf8(name());
533         string::const_iterator it = n.begin();
534         string::const_iterator en = n.end();
535         for (; it != en; ++it) {
536                 if (!isAlphaASCII(*it))
537                         d += "_";
538                 else if (isLower(*it))
539                         d += *it;
540                 else
541                         d += lowercase(*it);
542         }
543         // are there other characters we need to remove?
544         defaultcssclass_ = d;
545         return defaultcssclass_;
546 }
547
548
549 void InsetLayout::makeDefaultCSS() const
550 {
551         if (!htmldefaultstyle_.empty())
552                 return;
553         docstring const mainfontCSS = font_.asCSS();
554         if (!mainfontCSS.empty())
555                 htmldefaultstyle_ =
556                                 from_ascii(htmltag() + "." + defaultCSSClass() + " {\n") +
557                                 mainfontCSS + from_ascii("\n}\n");
558 }
559
560
561 docstring InsetLayout::htmlstyle() const
562 {
563         if (!htmlstyle_.empty() && !htmlforcecss_)
564                 return htmlstyle_;
565         if (htmldefaultstyle_.empty())
566                 makeDefaultCSS();
567         docstring retval = htmldefaultstyle_;
568         if (!htmlstyle_.empty())
569                 retval += '\n' + htmlstyle_ + '\n';
570         return retval;
571 }
572
573 void InsetLayout::readArgument(Lexer & lex)
574 {
575         Layout::latexarg arg;
576         arg.mandatory = false;
577         arg.autoinsert = false;
578         arg.insertcotext = false;
579         bool error = false;
580         bool finished = false;
581         arg.font = inherit_font;
582         arg.labelfont = inherit_font;
583         arg.is_toc_caption = false;
584         string nr;
585         lex >> nr;
586         bool const postcmd = prefixIs(nr, "post:");
587         while (!finished && lex.isOK() && !error) {
588                 lex.next();
589                 string const tok = ascii_lowercase(lex.getString());
590
591                 if (tok.empty()) {
592                         continue;
593                 } else if (tok == "endargument") {
594                         finished = true;
595                 } else if (tok == "labelstring") {
596                         lex.next();
597                         arg.labelstring = lex.getDocString();
598                 } else if (tok == "menustring") {
599                         lex.next();
600                         arg.menustring = lex.getDocString();
601                 } else if (tok == "mandatory") {
602                         lex.next();
603                         arg.mandatory = lex.getBool();
604                 } else if (tok == "autoinsert") {
605                         lex.next();
606                         arg.autoinsert = lex.getBool();
607                 } else if (tok == "insertcotext") {
608                         lex.next();
609                         arg.insertcotext = lex.getBool();
610                 } else if (tok == "insertcotext") {
611                         lex.next();
612                         arg.insertcotext = lex.getBool();
613                 } else if (tok == "leftdelim") {
614                         lex.next();
615                         arg.ldelim = lex.getDocString();
616                         arg.ldelim = subst(arg.ldelim,
617                                                     from_ascii("<br/>"), from_ascii("\n"));
618                 } else if (tok == "rightdelim") {
619                         lex.next();
620                         arg.rdelim = lex.getDocString();
621                         arg.rdelim = subst(arg.rdelim,
622                                                     from_ascii("<br/>"), from_ascii("\n"));
623                 } else if (tok == "defaultarg") {
624                         lex.next();
625                         arg.defaultarg = lex.getDocString();
626                 } else if (tok == "presetarg") {
627                         lex.next();
628                         arg.presetarg = lex.getDocString();
629                 } else if (tok == "tooltip") {
630                         lex.next();
631                         arg.tooltip = lex.getDocString();
632                 } else if (tok == "requires") {
633                         lex.next();
634                         arg.requires = lex.getString();
635                 } else if (tok == "decoration") {
636                         lex.next();
637                         arg.decoration = lex.getString();
638                 } else if (tok == "font") {
639                         arg.font = lyxRead(lex, arg.font);
640                 } else if (tok == "labelfont") {
641                         arg.labelfont = lyxRead(lex, arg.labelfont);
642                 } else if (tok == "passthruchars") {
643                         lex.next();
644                         arg.pass_thru_chars = lex.getDocString();
645                 } else if (tok == "istoccaption") {
646                         lex.next();
647                         arg.is_toc_caption = lex.getBool();
648                 } else {
649                         lex.printError("Unknown tag");
650                         error = true;
651                 }
652         }
653         if (arg.labelstring.empty())
654                 LYXERR0("Incomplete Argument definition!");
655         else if (postcmd)
656                 postcommandargs_[nr] = arg;
657         else
658                 latexargs_[nr] = arg;
659 }
660
661
662 Layout::LaTeXArgMap InsetLayout::args() const
663 {
664         Layout::LaTeXArgMap args = latexargs_;
665         if (!postcommandargs_.empty())
666                 args.insert(postcommandargs_.begin(), postcommandargs_.end());
667         return args;
668 }
669
670
671 unsigned int InsetLayout::optArgs() const
672 {
673         unsigned int nr = 0;
674         Layout::LaTeXArgMap const args = InsetLayout::args();
675         Layout::LaTeXArgMap::const_iterator it = args.begin();
676         for (; it != args.end(); ++it) {
677                 if (!(*it).second.mandatory)
678                         ++nr;
679         }
680         return nr;
681 }
682
683
684 unsigned int InsetLayout::requiredArgs() const
685 {
686         unsigned int nr = 0;
687         Layout::LaTeXArgMap const args = InsetLayout::args();
688         Layout::LaTeXArgMap::const_iterator it = args.begin();
689         for (; it != args.end(); ++it) {
690                 if ((*it).second.mandatory)
691                         ++nr;
692         }
693         return nr;
694 }
695
696
697 } //namespace lyx