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