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