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