]> git.lyx.org Git - lyx.git/blobdiff - src/factory.C
ws changes only
[lyx.git] / src / factory.C
index 6fbcb377b77c9507ce9adc34cba26a2c4da44833..6c728827d22d15f5a48cbb4e86bab3b36165ec48 100644 (file)
@@ -5,18 +5,20 @@
  *
  * \author André Pönitz
  *
- * Full author contact details are available in file CREDITS
+ * Full author contact details are available in file CREDITS.
  */
 
 #include <config.h>
 
-#include "funcrequest.h"
-#include "bufferparams.h"
+#include "factory.h"
+
 #include "buffer.h"
-#include "FloatList.h"
-#include "debug.h"
 #include "BufferView.h"
-#include "lyxtext.h"
+#include "bufferparams.h"
+#include "debug.h"
+#include "FloatList.h"
+#include "funcrequest.h"
+#include "LColor.h"
 #include "lyxlex.h"
 
 #include "insets/insetbibitem.h"
 #include "insets/insetmarginal.h"
 #include "insets/insetminipage.h"
 #include "insets/insetnote.h"
+#include "insets/insetbox.h"
+#include "insets/insetbranch.h"
 #include "insets/insetoptarg.h"
-#include "insets/insetparent.h"
 #include "insets/insetref.h"
+#include "insets/insetspace.h"
 #include "insets/insettabular.h"
-#include "insets/insettext.h"
 #include "insets/insettoc.h"
 #include "insets/inseturl.h"
 #include "insets/insetwrap.h"
 #include "frontends/Dialogs.h"
 #include "frontends/LyXView.h"
 #include "support/lstrings.h"
+#include "support/std_sstream.h"
 
-#include <cstdio>
+#include <boost/assert.hpp>
+
+using lyx::support::compare_ascii_no_case;
 
 using std::endl;
+using std::string;
+
 
-Inset * createInset(FuncRequest const & cmd)
+InsetOld * createInset(FuncRequest const & cmd)
 {
        BufferView * bv = cmd.view();
-       BufferParams const & params = bv->buffer()->params;
+       BufferParams const & params = bv->buffer()->params();
 
        switch (cmd.action) {
        case LFUN_HFILL:
-               return new InsetHFill();
+               return new InsetHFill;
 
        case LFUN_INSET_MINIPAGE:
                return new InsetMinipage(params);
 
        case LFUN_INSERT_NOTE:
-               return new InsetNote(params);
+               {
+                       string arg = cmd.getArg(0);
+                       if (arg.empty())
+                               arg = "Note";
+                       return new InsetNote(params, arg);
+               }
+       case LFUN_INSERT_BOX:
+               {
+                       string arg = cmd.getArg(0);
+                       if (arg.empty())
+                               arg = "Boxed";
+                       return new InsetBox(params, arg);
+               }
+       case LFUN_INSERT_BRANCH:
+               {
+                       string arg = cmd.getArg(0);
+                       if (arg.empty())
+                               arg = "none";
+                       return new InsetBranch(params, arg);
+               }
 
        case LFUN_INSET_ERT:
                return new InsetERT(params);
@@ -112,7 +139,7 @@ Inset * createInset(FuncRequest const & cmd)
                // Try and generate a valid index entry.
                InsetCommandParams icp("index");
                string const contents = cmd.argument.empty() ?
-                       bv->getLyXText()->getStringToIndex(bv) :
+                       bv->getLyXText()->getStringToIndex() :
                        cmd.argument;
                icp.setContents(contents);
 
@@ -122,17 +149,18 @@ Inset * createInset(FuncRequest const & cmd)
                if (icp.getContents().empty()) {
                        lv->getDialogs().show("index", data, 0);
                } else {
-                       FuncRequest fr(bv, LFUN_INSET_APPLY, data);
-                       lv->dispatch(fr);
+                       lv->dispatch(FuncRequest(bv, LFUN_INSET_APPLY, data));
                }
                return 0;
        }
 
        case LFUN_TABULAR_INSERT:
                if (!cmd.argument.empty()) {
-                       int r = 2;
-                       int c = 2;
-                       ::sscanf(cmd.argument.c_str(),"%d%d", &r, &c);
+                       std::istringstream ss(cmd.argument);
+                       int r, c;
+                       ss >> r >> c;
+                       if (r <= 0) r = 2;
+                       if (c <= 0) c = 2;
                        return new InsetTabular(*bv->buffer(), r, c);
                }
                bv->owner()->getDialogs().show("tabularcreate");
@@ -145,8 +173,8 @@ Inset * createInset(FuncRequest const & cmd)
                        InsetCaption * inset = new InsetCaption(params);
                        inset->setOwner(bv->theLockingInset());
                        inset->setAutoBreakRows(true);
-                       inset->setDrawFrame(0, InsetText::LOCKED);
-                       inset->setFrameColor(0, LColor::captionframe);
+                       inset->setDrawFrame(InsetText::LOCKED);
+                       inset->setFrameColor(LColor::captionframe);
                        return inset;
                }
                return 0;
@@ -157,10 +185,6 @@ Inset * createInset(FuncRequest const & cmd)
        case LFUN_TOC_INSERT:
                return new InsetTOC(InsetCommandParams("tableofcontents"));
 
-       case LFUN_PARENTINSERT:
-               return new InsetParent(
-                       InsetCommandParams("lyxparent", cmd.argument), *bv->buffer());
-
        case LFUN_ENVIRONMENT_INSERT:
                return new InsetEnvironment(params, cmd.argument);
 
@@ -172,7 +196,7 @@ Inset * createInset(FuncRequest const & cmd)
                return new InsetTheorem;
 #endif
 
-       case LFUN_INSET_APPLY: {
+       case LFUN_INSET_INSERT: {
                string const name = cmd.getArg(0);
 
                if (name == "bibitem") {
@@ -189,7 +213,7 @@ Inset * createInset(FuncRequest const & cmd)
                        InsetCommandParams icp;
                        InsetCommandMailer::string2params(cmd.argument, icp);
                        InsetCitation * inset = new InsetCitation(icp);
-                       inset->setLoadingBuffer(bv->buffer(), false);
+                       inset->setLoadingBuffer(*bv->buffer(), false);
                        return inset;
 
                } else if (name == "ert") {
@@ -200,22 +224,25 @@ Inset * createInset(FuncRequest const & cmd)
                        return inset;
 
                } else if (name == "external") {
-                       InsetExternal::Params iep;                      
-                       InsetExternalMailer::string2params(cmd.argument, iep);
+                       Buffer const & buffer = *cmd.view()->buffer();
+                       InsetExternalParams iep;
+                       InsetExternalMailer::string2params(cmd.argument,
+                                                          buffer, iep);
                        InsetExternal * inset = new InsetExternal;
-                       inset->setFromParams(iep);
+                       inset->setParams(iep, buffer);
                        return inset;
 
                } else if (name == "graphics") {
-                       InsetGraphicsParams igp;                        
-                       InsetGraphicsMailer::string2params(cmd.argument, igp);
+                       Buffer const & buffer = *cmd.view()->buffer();
+                       InsetGraphicsParams igp;
+                       InsetGraphicsMailer::string2params(cmd.argument,
+                                                          buffer, igp);
                        InsetGraphics * inset = new InsetGraphics;
-                       string const fpath = cmd.view()->buffer()->filePath();
-                       inset->setParams(igp, fpath);
+                       inset->setParams(igp);
                        return inset;
 
                } else if (name == "include") {
-                       InsetInclude::Params iip;
+                       InsetCommandParams iip;
                        InsetIncludeMailer::string2params(cmd.argument, iip);
                        return new InsetInclude(iip);
 
@@ -245,6 +272,31 @@ Inset * createInset(FuncRequest const & cmd)
                        return new InsetUrl(icp);
                }
        }
+
+       case LFUN_SPACE_INSERT: {
+               string const name = cmd.argument;
+               if (name == "normal")
+                       return new InsetSpace(InsetSpace::NORMAL);
+               else if (name == "protected")
+                       return new InsetSpace(InsetSpace::PROTECTED);
+               else if (name == "thin")
+                       return new InsetSpace(InsetSpace::THIN);
+               else if (name == "quad")
+                       return new InsetSpace(InsetSpace::QUAD);
+               else if (name == "qquad")
+                       return new InsetSpace(InsetSpace::QQUAD);
+               else if (name == "enspace")
+                       return new InsetSpace(InsetSpace::ENSPACE);
+               else if (name == "enskip")
+                       return new InsetSpace(InsetSpace::ENSKIP);
+               else if (name == "negthinspace")
+                       return new InsetSpace(InsetSpace::NEGTHIN);
+               else if (name.empty())
+                       lyxerr << "LyX function 'space' needs an argument." << endl;
+               else
+                       lyxerr << "Wrong argument for LyX function 'space'." << endl;
+       }
+
        break;
 
        default:
@@ -255,7 +307,7 @@ Inset * createInset(FuncRequest const & cmd)
 }
 
 
-Inset * readInset(LyXLex & lex, Buffer const & buf)
+InsetOld * readInset(LyXLex & lex, Buffer const & buf)
 {
        // consistency check
        if (lex.getString() != "\\begin_inset") {
@@ -263,7 +315,7 @@ Inset * readInset(LyXLex & lex, Buffer const & buf)
                       << endl;
        }
 
-       Inset * inset = 0;
+       InsetOld * inset = 0;
 
        lex.next();
        string const tmptok = lex.getString();
@@ -282,18 +334,19 @@ Inset * readInset(LyXLex & lex, Buffer const & buf)
                } else if (cmdName == "bibitem") {
                        lex.printError("Wrong place for bibitem");
                        inset = new InsetBibitem(inscmd);
-               } else if (cmdName == "BibTeX") {
+               } else if (cmdName == "bibtex") {
                        inset = new InsetBibtex(inscmd);
                } else if (cmdName == "index") {
                        inset = new InsetIndex(inscmd);
                } else if (cmdName == "include") {
-                       inset = new InsetInclude(inscmd, buf);
+                       inset = new InsetInclude(inscmd);
                } else if (cmdName == "label") {
                        inset = new InsetLabel(inscmd);
                } else if (cmdName == "url"
                           || cmdName == "htmlurl") {
                        inset = new InsetUrl(inscmd);
                } else if (cmdName == "ref"
+                          || cmdName == "eqref"
                           || cmdName == "pageref"
                           || cmdName == "vref"
                           || cmdName == "vpageref"
@@ -312,8 +365,9 @@ Inset * readInset(LyXLex & lex, Buffer const & buf)
                        inset = new InsetFloatList("table");
                } else if (cmdName == "printindex") {
                        inset = new InsetPrintIndex(inscmd);
-               } else if (cmdName == "lyxparent") {
-                       inset = new InsetParent(inscmd, buf);
+               } else {
+                       lyxerr << "unknown CommandInset '" << cmdName << "'" << std::endl;
+                       BOOST_ASSERT(false);
                }
        } else {
                if (tmptok == "Quotes") {
@@ -326,33 +380,45 @@ Inset * readInset(LyXLex & lex, Buffer const & buf)
                        inset = new InsetFormula;
                } else if (tmptok == "Graphics") {
                        inset = new InsetGraphics;
-               } else if (tmptok == "Note") {
-                       inset = new InsetNote(buf.params);
+               } else if (tmptok == "Note"     || tmptok == "Comment"
+                               || tmptok == "Greyedout") {
+                       inset = new InsetNote(buf.params(), tmptok);
+               } else if (tmptok == "Boxed" || tmptok == "ovalbox"
+                       || tmptok == "Shadowbox" || tmptok == "Doublebox"
+                       || tmptok == "Ovalbox" || tmptok == "Frameless") {
+                       inset = new InsetBox(buf.params(), tmptok);
+               } else if (tmptok == "Branch") {
+                       inset = new InsetBranch(buf.params(), string());
                } else if (tmptok == "Include") {
                        InsetCommandParams p("Include");
-                       inset = new InsetInclude(p, buf);
+                       inset = new InsetInclude(p);
+               } else if (tmptok == "Environment") {
+                       lex.next();
+                       inset = new InsetEnvironment(buf.params(), lex.getString());
                } else if (tmptok == "ERT") {
-                       inset = new InsetERT(buf.params);
+                       inset = new InsetERT(buf.params());
+               } else if (tmptok == "InsetSpace") {
+                       inset = new InsetSpace;
                } else if (tmptok == "Tabular") {
                        inset = new InsetTabular(buf);
                } else if (tmptok == "Text") {
-                       inset = new InsetText(buf.params);
+                       inset = new InsetText(buf.params());
                } else if (tmptok == "Foot") {
-                       inset = new InsetFoot(buf.params);
+                       inset = new InsetFoot(buf.params());
                } else if (tmptok == "Marginal") {
-                       inset = new InsetMarginal(buf.params);
+                       inset = new InsetMarginal(buf.params());
                } else if (tmptok == "OptArg") {
-                       inset = new InsetOptArg(buf.params);
+                       inset = new InsetOptArg(buf.params());
                } else if (tmptok == "Minipage") {
-                       inset = new InsetMinipage(buf.params);
+                       inset = new InsetMinipage(buf.params());
                } else if (tmptok == "Float") {
                        lex.next();
                        string tmptok = lex.getString();
-                       inset = new InsetFloat(buf.params, tmptok);
+                       inset = new InsetFloat(buf.params(), tmptok);
                } else if (tmptok == "Wrap") {
                        lex.next();
                        string tmptok = lex.getString();
-                       inset = new InsetWrap(buf.params, tmptok);
+                       inset = new InsetWrap(buf.params(), tmptok);
 #if 0
                } else if (tmptok == "List") {
                        inset = new InsetList;
@@ -360,13 +426,15 @@ Inset * readInset(LyXLex & lex, Buffer const & buf)
                        inset = new InsetList;
 #endif
                } else if (tmptok == "Caption") {
-                       inset = new InsetCaption(buf.params);
+                       inset = new InsetCaption(buf.params());
                } else if (tmptok == "FloatList") {
                        inset = new InsetFloatList;
+               } else {
+                       lyxerr << "unknown Inset type '" << tmptok << "'" << std::endl;
+                       BOOST_ASSERT(false);
                }
 
-               if (inset)
-                       inset->read(&buf, lex);
+               inset->read(buf, lex);
        }
 
        return inset;