3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS
13 #include "funcrequest.h"
14 #include "bufferparams.h"
16 #include "FloatList.h"
18 #include "BufferView.h"
22 #include "insets/insetbibitem.h"
23 #include "insets/insetbibtex.h"
24 #include "insets/insetcaption.h"
25 #include "insets/insetcite.h"
26 #include "insets/insetenv.h"
27 #include "insets/insetert.h"
28 #include "insets/insetexternal.h"
29 #include "insets/insetfloat.h"
30 #include "insets/insetfloatlist.h"
31 #include "insets/insetfoot.h"
32 #include "insets/insetgraphics.h"
33 #include "insets/insethfill.h"
34 #include "insets/insetinclude.h"
35 #include "insets/insetindex.h"
36 #include "insets/insetlabel.h"
37 #include "insets/insetmarginal.h"
38 #include "insets/insetminipage.h"
39 #include "insets/insetnote.h"
40 #include "insets/insetoptarg.h"
41 #include "insets/insetref.h"
42 #include "insets/insetspace.h"
43 #include "insets/insettabular.h"
44 #include "insets/insettext.h"
45 #include "insets/insettoc.h"
46 #include "insets/inseturl.h"
47 #include "insets/insetwrap.h"
48 #include "mathed/formulamacro.h"
49 #include "mathed/formula.h"
51 #include "frontends/Dialogs.h"
52 #include "frontends/LyXView.h"
53 #include "support/lstrings.h"
59 Inset * createInset(FuncRequest const & cmd)
61 BufferView * bv = cmd.view();
62 BufferParams const & params = bv->buffer()->params;
66 return new InsetHFill();
68 case LFUN_INSET_MINIPAGE:
69 return new InsetMinipage(params);
71 case LFUN_INSERT_NOTE:
72 return new InsetNote(params);
75 return new InsetERT(params);
77 case LFUN_INSET_FOOTNOTE:
78 return new InsetFoot(params);
80 case LFUN_INSET_MARGINAL:
81 return new InsetMarginal(params);
83 case LFUN_INSET_OPTARG:
84 return new InsetOptArg(params);
86 case LFUN_INSERT_BIBITEM:
87 return new InsetBibitem(InsetCommandParams("bibitem"));
89 case LFUN_INSET_FLOAT:
90 // check if the float type exists
91 if (params.getLyXTextClass().floats().typeExist(cmd.argument))
92 return new InsetFloat(params, cmd.argument);
93 lyxerr << "Non-existent float type: " << cmd.argument << endl;
96 case LFUN_INSET_WIDE_FLOAT:
97 // check if the float type exists
98 if (params.getLyXTextClass().floats().typeExist(cmd.argument)) {
99 InsetFloat * p = new InsetFloat(params, cmd.argument);
100 p->wide(true, params);
102 lyxerr << "Non-existent float type: " << cmd.argument << endl;
105 case LFUN_INSET_WRAP:
106 if (cmd.argument == "figure")
107 return new InsetWrap(params, cmd.argument);
108 lyxerr << "Non-existent floatflt type: " << cmd.argument << endl;
111 case LFUN_INDEX_INSERT: {
112 // Try and generate a valid index entry.
113 InsetCommandParams icp("index");
114 string const contents = cmd.argument.empty() ?
115 bv->getLyXText()->getStringToIndex() :
117 icp.setContents(contents);
119 string data = InsetCommandMailer::params2string("index", icp);
120 LyXView * lv = bv->owner();
122 if (icp.getContents().empty()) {
123 lv->getDialogs().show("index", data, 0);
125 FuncRequest fr(bv, LFUN_INSET_APPLY, data);
131 case LFUN_TABULAR_INSERT:
132 if (!cmd.argument.empty()) {
135 ::sscanf(cmd.argument.c_str(),"%d%d", &r, &c);
136 return new InsetTabular(*bv->buffer(), r, c);
138 bv->owner()->getDialogs().show("tabularcreate");
141 case LFUN_INSET_CAPTION:
142 if (bv->theLockingInset()) {
143 lyxerr << "Locking inset code: "
144 << static_cast<int>(bv->theLockingInset()->lyxCode());
145 InsetCaption * inset = new InsetCaption(params);
146 inset->setOwner(bv->theLockingInset());
147 inset->setAutoBreakRows(true);
148 inset->setDrawFrame(0, InsetText::LOCKED);
149 inset->setFrameColor(0, LColor::captionframe);
154 case LFUN_INDEX_PRINT:
155 return new InsetPrintIndex(InsetCommandParams("printindex"));
157 case LFUN_TOC_INSERT:
158 return new InsetTOC(InsetCommandParams("tableofcontents"));
160 case LFUN_ENVIRONMENT_INSERT:
161 return new InsetEnvironment(params, cmd.argument);
164 case LFUN_INSET_LIST:
165 return new InsetList;
167 case LFUN_INSET_THEOREM:
168 return new InsetTheorem;
171 case LFUN_INSET_INSERT: {
172 string const name = cmd.getArg(0);
174 if (name == "bibitem") {
175 InsetCommandParams icp;
176 InsetCommandMailer::string2params(cmd.argument, icp);
177 return new InsetBibitem(icp);
179 } else if (name == "bibtex") {
180 InsetCommandParams icp;
181 InsetCommandMailer::string2params(cmd.argument, icp);
182 return new InsetBibtex(icp);
184 } else if (name == "citation") {
185 InsetCommandParams icp;
186 InsetCommandMailer::string2params(cmd.argument, icp);
187 InsetCitation * inset = new InsetCitation(icp);
188 inset->setLoadingBuffer(bv->buffer(), false);
191 } else if (name == "ert") {
192 InsetERT * inset = new InsetERT(params);
193 InsetERT::ERTStatus s;
194 InsetERTMailer::string2params(cmd.argument, s);
195 inset->status(bv, s);
198 } else if (name == "external") {
199 InsetExternal::Params iep;
200 InsetExternalMailer::string2params(cmd.argument, iep);
201 InsetExternal * inset = new InsetExternal;
202 string const fpath = cmd.view()->buffer()->filePath();
203 inset->setParams(iep, fpath);
206 } else if (name == "graphics") {
207 InsetGraphicsParams igp;
208 InsetGraphicsMailer::string2params(cmd.argument, igp);
209 InsetGraphics * inset = new InsetGraphics;
210 inset->setParams(igp);
213 } else if (name == "include") {
214 InsetInclude::Params iip;
215 InsetIncludeMailer::string2params(cmd.argument, iip);
216 return new InsetInclude(iip);
218 } else if (name == "index") {
219 InsetCommandParams icp;
220 InsetCommandMailer::string2params(cmd.argument, icp);
221 return new InsetIndex(icp);
223 } else if (name == "label") {
224 InsetCommandParams icp;
225 InsetCommandMailer::string2params(cmd.argument, icp);
226 return new InsetLabel(icp);
228 } else if (name == "ref") {
229 InsetCommandParams icp;
230 InsetCommandMailer::string2params(cmd.argument, icp);
231 return new InsetRef(icp, *bv->buffer());
233 } else if (name == "toc") {
234 InsetCommandParams icp;
235 InsetCommandMailer::string2params(cmd.argument, icp);
236 return new InsetTOC(icp);
238 } else if (name == "url") {
239 InsetCommandParams icp;
240 InsetCommandMailer::string2params(cmd.argument, icp);
241 return new InsetUrl(icp);
245 case LFUN_SPACE_INSERT: {
246 string const name = cmd.argument;
247 if (name == "normal")
248 return new InsetSpace(InsetSpace::NORMAL);
249 else if (name == "protected")
250 return new InsetSpace(InsetSpace::PROTECTED);
251 else if (name == "thin")
252 return new InsetSpace(InsetSpace::THIN);
253 else if (name == "quad")
254 return new InsetSpace(InsetSpace::QUAD);
255 else if (name == "qquad")
256 return new InsetSpace(InsetSpace::QQUAD);
257 else if (name == "enspace")
258 return new InsetSpace(InsetSpace::ENSPACE);
259 else if (name == "enskip")
260 return new InsetSpace(InsetSpace::ENSKIP);
261 else if (name == "negthinspace")
262 return new InsetSpace(InsetSpace::NEGTHIN);
263 else if (name.empty())
264 lyxerr << "LyX function 'space' needs an argument." << endl;
266 lyxerr << "Wrong argument for LyX function 'space'." << endl;
279 Inset * readInset(LyXLex & lex, Buffer const & buf)
282 if (lex.getString() != "\\begin_inset") {
283 lyxerr << "Buffer::readInset: Consistency check failed."
290 string const tmptok = lex.getString();
292 // test the different insets
293 if (tmptok == "LatexCommand") {
294 InsetCommandParams inscmd;
297 string const cmdName = inscmd.getCmdName();
299 // This strange command allows LyX to recognize "natbib" style
300 // citations: citet, citep, Citet etc.
301 if (compare_ascii_no_case(cmdName.substr(0,4), "cite") == 0) {
302 inset = new InsetCitation(inscmd);
303 } else if (cmdName == "bibitem") {
304 lex.printError("Wrong place for bibitem");
305 inset = new InsetBibitem(inscmd);
306 } else if (cmdName == "bibtex") {
307 inset = new InsetBibtex(inscmd);
308 } else if (cmdName == "index") {
309 inset = new InsetIndex(inscmd);
310 } else if (cmdName == "include") {
311 inset = new InsetInclude(inscmd, buf);
312 } else if (cmdName == "label") {
313 inset = new InsetLabel(inscmd);
314 } else if (cmdName == "url"
315 || cmdName == "htmlurl") {
316 inset = new InsetUrl(inscmd);
317 } else if (cmdName == "ref"
318 || cmdName == "eqref"
319 || cmdName == "pageref"
321 || cmdName == "vpageref"
322 || cmdName == "prettyref") {
323 if (!inscmd.getOptions().empty()
324 || !inscmd.getContents().empty()) {
325 inset = new InsetRef(inscmd, buf);
327 } else if (cmdName == "tableofcontents") {
328 inset = new InsetTOC(inscmd);
329 } else if (cmdName == "listofalgorithms") {
330 inset = new InsetFloatList("algorithm");
331 } else if (cmdName == "listoffigures") {
332 inset = new InsetFloatList("figure");
333 } else if (cmdName == "listoftables") {
334 inset = new InsetFloatList("table");
335 } else if (cmdName == "printindex") {
336 inset = new InsetPrintIndex(inscmd);
339 if (tmptok == "Quotes") {
340 inset = new InsetQuotes;
341 } else if (tmptok == "External") {
342 inset = new InsetExternal;
343 } else if (tmptok == "FormulaMacro") {
344 inset = new InsetFormulaMacro;
345 } else if (tmptok == "Formula") {
346 inset = new InsetFormula;
347 } else if (tmptok == "Graphics") {
348 inset = new InsetGraphics;
349 } else if (tmptok == "Note") {
350 inset = new InsetNote(buf.params);
351 } else if (tmptok == "Include") {
352 InsetCommandParams p("Include");
353 inset = new InsetInclude(p, buf);
354 } else if (tmptok == "Environment") {
356 inset = new InsetEnvironment(buf.params, lex.getString());
357 } else if (tmptok == "ERT") {
358 inset = new InsetERT(buf.params);
359 } else if (tmptok == "InsetSpace") {
360 inset = new InsetSpace;
361 } else if (tmptok == "Tabular") {
362 inset = new InsetTabular(buf);
363 } else if (tmptok == "Text") {
364 inset = new InsetText(buf.params);
365 } else if (tmptok == "Foot") {
366 inset = new InsetFoot(buf.params);
367 } else if (tmptok == "Marginal") {
368 inset = new InsetMarginal(buf.params);
369 } else if (tmptok == "OptArg") {
370 inset = new InsetOptArg(buf.params);
371 } else if (tmptok == "Minipage") {
372 inset = new InsetMinipage(buf.params);
373 } else if (tmptok == "Float") {
375 string tmptok = lex.getString();
376 inset = new InsetFloat(buf.params, tmptok);
377 } else if (tmptok == "Wrap") {
379 string tmptok = lex.getString();
380 inset = new InsetWrap(buf.params, tmptok);
382 } else if (tmptok == "List") {
383 inset = new InsetList;
384 } else if (tmptok == "Theorem") {
385 inset = new InsetList;
387 } else if (tmptok == "Caption") {
388 inset = new InsetCaption(buf.params);
389 } else if (tmptok == "FloatList") {
390 inset = new InsetFloatList;
394 inset->read(&buf, lex);