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"
57 using namespace lyx::support;
61 InsetOld * createInset(FuncRequest const & cmd)
63 BufferView * bv = cmd.view();
64 BufferParams const & params = bv->buffer()->params;
68 return new InsetHFill();
70 case LFUN_INSET_MINIPAGE:
71 return new InsetMinipage(params);
73 case LFUN_INSERT_NOTE:
75 string arg = cmd.getArg(0);
78 return new InsetNote(params, arg);
81 return new InsetERT(params);
83 case LFUN_INSET_FOOTNOTE:
84 return new InsetFoot(params);
86 case LFUN_INSET_MARGINAL:
87 return new InsetMarginal(params);
89 case LFUN_INSET_OPTARG:
90 return new InsetOptArg(params);
92 case LFUN_INSERT_BIBITEM:
93 return new InsetBibitem(InsetCommandParams("bibitem"));
95 case LFUN_INSET_FLOAT:
96 // check if the float type exists
97 if (params.getLyXTextClass().floats().typeExist(cmd.argument))
98 return new InsetFloat(params, cmd.argument);
99 lyxerr << "Non-existent float type: " << cmd.argument << endl;
102 case LFUN_INSET_WIDE_FLOAT:
103 // check if the float type exists
104 if (params.getLyXTextClass().floats().typeExist(cmd.argument)) {
105 InsetFloat * p = new InsetFloat(params, cmd.argument);
106 p->wide(true, params);
108 lyxerr << "Non-existent float type: " << cmd.argument << endl;
111 case LFUN_INSET_WRAP:
112 if (cmd.argument == "figure")
113 return new InsetWrap(params, cmd.argument);
114 lyxerr << "Non-existent floatflt type: " << cmd.argument << endl;
117 case LFUN_INDEX_INSERT: {
118 // Try and generate a valid index entry.
119 InsetCommandParams icp("index");
120 string const contents = cmd.argument.empty() ?
121 bv->getLyXText()->getStringToIndex() :
123 icp.setContents(contents);
125 string data = InsetCommandMailer::params2string("index", icp);
126 LyXView * lv = bv->owner();
128 if (icp.getContents().empty()) {
129 lv->getDialogs().show("index", data, 0);
131 FuncRequest fr(bv, LFUN_INSET_APPLY, data);
137 case LFUN_TABULAR_INSERT:
138 if (!cmd.argument.empty()) {
141 ::sscanf(cmd.argument.c_str(),"%d%d", &r, &c);
142 return new InsetTabular(*bv->buffer(), r, c);
144 bv->owner()->getDialogs().show("tabularcreate");
147 case LFUN_INSET_CAPTION:
148 if (bv->theLockingInset()) {
149 lyxerr << "Locking inset code: "
150 << static_cast<int>(bv->theLockingInset()->lyxCode());
151 InsetCaption * inset = new InsetCaption(params);
152 inset->setOwner(bv->theLockingInset());
153 inset->setAutoBreakRows(true);
154 inset->setDrawFrame(0, InsetText::LOCKED);
155 inset->setFrameColor(0, LColor::captionframe);
160 case LFUN_INDEX_PRINT:
161 return new InsetPrintIndex(InsetCommandParams("printindex"));
163 case LFUN_TOC_INSERT:
164 return new InsetTOC(InsetCommandParams("tableofcontents"));
166 case LFUN_ENVIRONMENT_INSERT:
167 return new InsetEnvironment(params, cmd.argument);
170 case LFUN_INSET_LIST:
171 return new InsetList;
173 case LFUN_INSET_THEOREM:
174 return new InsetTheorem;
177 case LFUN_INSET_INSERT: {
178 string const name = cmd.getArg(0);
180 if (name == "bibitem") {
181 InsetCommandParams icp;
182 InsetCommandMailer::string2params(cmd.argument, icp);
183 return new InsetBibitem(icp);
185 } else if (name == "bibtex") {
186 InsetCommandParams icp;
187 InsetCommandMailer::string2params(cmd.argument, icp);
188 return new InsetBibtex(icp);
190 } else if (name == "citation") {
191 InsetCommandParams icp;
192 InsetCommandMailer::string2params(cmd.argument, icp);
193 InsetCitation * inset = new InsetCitation(icp);
194 inset->setLoadingBuffer(bv->buffer(), false);
197 } else if (name == "ert") {
198 InsetERT * inset = new InsetERT(params);
199 InsetERT::ERTStatus s;
200 InsetERTMailer::string2params(cmd.argument, s);
201 inset->status(bv, s);
204 } else if (name == "external") {
205 Buffer const * buffer = cmd.view()->buffer();
206 InsetExternal::Params iep;
207 InsetExternalMailer::string2params(cmd.argument,
209 InsetExternal * inset = new InsetExternal;
210 inset->setParams(iep, buffer);
213 } else if (name == "graphics") {
214 Buffer const & buffer = *cmd.view()->buffer();
215 InsetGraphicsParams igp;
216 InsetGraphicsMailer::string2params(cmd.argument,
218 InsetGraphics * inset = new InsetGraphics;
219 inset->setParams(igp);
222 } else if (name == "include") {
223 InsetInclude::Params iip;
224 InsetIncludeMailer::string2params(cmd.argument, iip);
225 return new InsetInclude(iip);
227 } else if (name == "index") {
228 InsetCommandParams icp;
229 InsetCommandMailer::string2params(cmd.argument, icp);
230 return new InsetIndex(icp);
232 } else if (name == "label") {
233 InsetCommandParams icp;
234 InsetCommandMailer::string2params(cmd.argument, icp);
235 return new InsetLabel(icp);
237 } else if (name == "ref") {
238 InsetCommandParams icp;
239 InsetCommandMailer::string2params(cmd.argument, icp);
240 return new InsetRef(icp, *bv->buffer());
242 } else if (name == "toc") {
243 InsetCommandParams icp;
244 InsetCommandMailer::string2params(cmd.argument, icp);
245 return new InsetTOC(icp);
247 } else if (name == "url") {
248 InsetCommandParams icp;
249 InsetCommandMailer::string2params(cmd.argument, icp);
250 return new InsetUrl(icp);
254 case LFUN_SPACE_INSERT: {
255 string const name = cmd.argument;
256 if (name == "normal")
257 return new InsetSpace(InsetSpace::NORMAL);
258 else if (name == "protected")
259 return new InsetSpace(InsetSpace::PROTECTED);
260 else if (name == "thin")
261 return new InsetSpace(InsetSpace::THIN);
262 else if (name == "quad")
263 return new InsetSpace(InsetSpace::QUAD);
264 else if (name == "qquad")
265 return new InsetSpace(InsetSpace::QQUAD);
266 else if (name == "enspace")
267 return new InsetSpace(InsetSpace::ENSPACE);
268 else if (name == "enskip")
269 return new InsetSpace(InsetSpace::ENSKIP);
270 else if (name == "negthinspace")
271 return new InsetSpace(InsetSpace::NEGTHIN);
272 else if (name.empty())
273 lyxerr << "LyX function 'space' needs an argument." << endl;
275 lyxerr << "Wrong argument for LyX function 'space'." << endl;
288 InsetOld * readInset(LyXLex & lex, Buffer const & buf)
291 if (lex.getString() != "\\begin_inset") {
292 lyxerr << "Buffer::readInset: Consistency check failed."
296 InsetOld * inset = 0;
299 string const tmptok = lex.getString();
301 // test the different insets
302 if (tmptok == "LatexCommand") {
303 InsetCommandParams inscmd;
306 string const cmdName = inscmd.getCmdName();
308 // This strange command allows LyX to recognize "natbib" style
309 // citations: citet, citep, Citet etc.
310 if (compare_ascii_no_case(cmdName.substr(0,4), "cite") == 0) {
311 inset = new InsetCitation(inscmd);
312 } else if (cmdName == "bibitem") {
313 lex.printError("Wrong place for bibitem");
314 inset = new InsetBibitem(inscmd);
315 } else if (cmdName == "bibtex") {
316 inset = new InsetBibtex(inscmd);
317 } else if (cmdName == "index") {
318 inset = new InsetIndex(inscmd);
319 } else if (cmdName == "include") {
320 inset = new InsetInclude(inscmd, buf);
321 } else if (cmdName == "label") {
322 inset = new InsetLabel(inscmd);
323 } else if (cmdName == "url"
324 || cmdName == "htmlurl") {
325 inset = new InsetUrl(inscmd);
326 } else if (cmdName == "ref"
327 || cmdName == "eqref"
328 || cmdName == "pageref"
330 || cmdName == "vpageref"
331 || cmdName == "prettyref") {
332 if (!inscmd.getOptions().empty()
333 || !inscmd.getContents().empty()) {
334 inset = new InsetRef(inscmd, buf);
336 } else if (cmdName == "tableofcontents") {
337 inset = new InsetTOC(inscmd);
338 } else if (cmdName == "listofalgorithms") {
339 inset = new InsetFloatList("algorithm");
340 } else if (cmdName == "listoffigures") {
341 inset = new InsetFloatList("figure");
342 } else if (cmdName == "listoftables") {
343 inset = new InsetFloatList("table");
344 } else if (cmdName == "printindex") {
345 inset = new InsetPrintIndex(inscmd);
348 if (tmptok == "Quotes") {
349 inset = new InsetQuotes;
350 } else if (tmptok == "External") {
351 inset = new InsetExternal;
352 } else if (tmptok == "FormulaMacro") {
353 inset = new InsetFormulaMacro;
354 } else if (tmptok == "Formula") {
355 inset = new InsetFormula;
356 } else if (tmptok == "Graphics") {
357 inset = new InsetGraphics;
358 } else if (tmptok == "Note" || tmptok == "Comment"
359 || tmptok == "Greyedout") {
360 inset = new InsetNote(buf.params, tmptok);
361 } else if (tmptok == "Include") {
362 InsetCommandParams p("Include");
363 inset = new InsetInclude(p, buf);
364 } else if (tmptok == "Environment") {
366 inset = new InsetEnvironment(buf.params, lex.getString());
367 } else if (tmptok == "ERT") {
368 inset = new InsetERT(buf.params);
369 } else if (tmptok == "InsetSpace") {
370 inset = new InsetSpace;
371 } else if (tmptok == "Tabular") {
372 inset = new InsetTabular(buf);
373 } else if (tmptok == "Text") {
374 inset = new InsetText(buf.params);
375 } else if (tmptok == "Foot") {
376 inset = new InsetFoot(buf.params);
377 } else if (tmptok == "Marginal") {
378 inset = new InsetMarginal(buf.params);
379 } else if (tmptok == "OptArg") {
380 inset = new InsetOptArg(buf.params);
381 } else if (tmptok == "Minipage") {
382 inset = new InsetMinipage(buf.params);
383 } else if (tmptok == "Float") {
385 string tmptok = lex.getString();
386 inset = new InsetFloat(buf.params, tmptok);
387 } else if (tmptok == "Wrap") {
389 string tmptok = lex.getString();
390 inset = new InsetWrap(buf.params, tmptok);
392 } else if (tmptok == "List") {
393 inset = new InsetList;
394 } else if (tmptok == "Theorem") {
395 inset = new InsetList;
397 } else if (tmptok == "Caption") {
398 inset = new InsetCaption(buf.params);
399 } else if (tmptok == "FloatList") {
400 inset = new InsetFloatList;
404 inset->read(&buf, lex);