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