]> git.lyx.org Git - lyx.git/blob - src/insets/InsetLayout.cpp
Stupid bug fix.
[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 "Color.h"
18 #include "Font.h"
19 #include "Lexer.h"
20
21 #include "support/lstrings.h"
22
23 #include <vector>
24
25 using std::string;
26 using std::set;
27 using std::vector;
28
29 namespace lyx {
30
31 InsetLayout::InsetLayout() :
32         name_(from_ascii("undefined")), labelstring_(from_ascii("UNDEFINED")),
33         decoration_(InsetLayout::Default),
34         font_(sane_font), labelfont_(sane_font), bgcolor_(Color_error), 
35         multipar_(false), passthru_(false), needprotect_(false),
36         freespacing_(false), keepempty_(false), forceltr_(false)
37
38         labelfont_.setColor(Color_error); 
39 }
40
41
42 namespace {
43
44 InsetLayout::InsetDecoration translateDecoration(std::string const & str) 
45 {
46         if (str == "classic")
47                 return InsetLayout::Classic;
48         if (str == "minimalistic")
49                 return InsetLayout::Minimalistic;
50         if (str == "conglomerate")
51                 return InsetLayout::Conglomerate;
52         return InsetLayout::Default;
53 }
54
55 }
56
57
58 bool InsetLayout::read(Lexer & lex)
59 {
60         name_ = support::subst(lex.getDocString(), '_', ' ');
61
62         enum {
63                 IL_FONT,
64                 IL_BGCOLOR,
65                 IL_DECORATION,
66                 IL_FREESPACING,
67                 IL_FORCELTR,
68                 IL_LABELFONT,
69                 IL_LABELSTRING,
70                 IL_LATEXNAME,
71                 IL_LATEXPARAM,
72                 IL_LATEXTYPE,
73                 IL_LYXTYPE,
74                 IL_KEEPEMPTY,
75                 IL_MULTIPAR,
76                 IL_NEEDPROTECT,
77                 IL_PASSTHRU,
78                 IL_PREAMBLE,
79                 IL_REQUIRES,
80                 IL_END
81         };
82
83
84         LexerKeyword elementTags[] = {
85                 { "bgcolor", IL_BGCOLOR },
86                 { "decoration", IL_DECORATION },
87                 { "end", IL_END },
88                 { "font", IL_FONT },
89                 { "forceltr", IL_FORCELTR },
90                 { "freespacing", IL_FREESPACING },
91                 { "keepempty", IL_KEEPEMPTY },
92                 { "labelfont", IL_LABELFONT },
93                 { "labelstring", IL_LABELSTRING },
94                 { "latexname", IL_LATEXNAME },
95                 { "latexparam", IL_LATEXPARAM },
96                 { "latextype", IL_LATEXTYPE },
97                 { "lyxtype", IL_LYXTYPE },
98                 { "multipar", IL_MULTIPAR },
99                 { "needprotect", IL_NEEDPROTECT },
100                 { "passthru", IL_PASSTHRU },
101                 { "preamble", IL_PREAMBLE },
102                 { "requires", IL_REQUIRES }
103         };
104
105         lex.pushTable(elementTags);
106
107         FontInfo font = inherit_font;
108         labelfont_ = inherit_font;
109         bgcolor_ = Color_background;
110         bool getout = false;
111
112         string tmp;     
113         while (!getout && lex.isOK()) {
114                 int le = lex.lex();
115                 switch (le) {
116                 case Lexer::LEX_UNDEF:
117                         lex.printError("Unknown InsetLayout tag");
118                         continue;
119                 default:
120                         break;
121                 }
122                 switch (le) {
123                 case IL_LYXTYPE:
124                         lex >> lyxtype_;
125                         break;
126                 case IL_LATEXTYPE:
127                         lex >> latextype_;
128                         break;
129                 case IL_LABELSTRING:
130                         lex >> labelstring_;
131                         break;
132                 case IL_DECORATION:
133                         lex >> tmp;
134                         decoration_ = translateDecoration(tmp);
135                         break;
136                 case IL_LATEXNAME:
137                         lex >> latexname_;
138                         break;
139                 case IL_LATEXPARAM:
140                         lex >> tmp;
141                         latexparam_ = support::subst(tmp, "&quot;", "\"");
142                         break;
143                 case IL_LABELFONT:
144                         labelfont_ = lyxRead(lex, inherit_font);
145                         break;
146                 case IL_FORCELTR:
147                         lex >> forceltr_;
148                         break;
149                 case IL_MULTIPAR:
150                         lex >> multipar_;
151                         break;
152                 case IL_PASSTHRU:
153                         lex >> passthru_;
154                         break;
155                 case IL_KEEPEMPTY:
156                         lex >> keepempty_;
157                         break;
158                 case IL_FREESPACING:
159                         lex >> freespacing_;
160                         break;
161                 case IL_NEEDPROTECT:
162                         lex >> needprotect_;
163                         break;
164                 case IL_FONT: {
165                         font_ = lyxRead(lex, inherit_font);
166                         // If you want to define labelfont, you need to do so after
167                         // font is defined.
168                         labelfont_ = font_;
169                         break;
170                 }
171                 case IL_BGCOLOR:
172                         lex >> tmp;
173                         bgcolor_ = lcolor.getFromLyXName(tmp);
174                         break;
175                 case IL_PREAMBLE:
176                         preamble_ = lex.getLongString("EndPreamble");
177                         break;
178                 case IL_REQUIRES: {
179                         lex.eatLine();
180                         vector<string> const req 
181                                 = support::getVectorFromString(lex.getString());
182                         requires_.insert(req.begin(), req.end());
183                         break;
184                 }
185                 case IL_END:
186                         getout = true;
187                         break;
188                 }
189         }
190
191         // Here add element to list if getout == true
192         if (!getout)
193                 return false;
194         
195         // The label font is generally used as-is without
196         // any realization against a given context.
197         labelfont_.realize(sane_font);
198
199         lex.popTable();
200         return true;
201 }
202
203 } //namespace lyx