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