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