]> git.lyx.org Git - lyx.git/blob - src/factory.C
Look for mathed xpms. Doesn't do anything yet due to lack of workable XPMs
[lyx.git] / src / factory.C
1
2 #include "funcrequest.h"
3 #include "bufferparams.h"
4 #include "buffer.h"
5 #include "FloatList.h"
6 #include "debug.h"
7 #include "BufferView.h"
8 #include "lyxtext.h"
9
10 #include "insets/insetcaption.h"
11 #include "insets/insetert.h"
12 #include "insets/insetexternal.h"
13 #include "insets/insetfloat.h"
14 #include "insets/insetfoot.h"
15 #include "insets/insetindex.h"
16 #include "insets/insetmarginal.h"
17 #include "insets/insetminipage.h"
18 #include "insets/insetnote.h"
19 #include "insets/insetoptarg.h"
20 #include "insets/insetparent.h"
21 #include "insets/insetref.h"
22 #include "insets/insettabular.h"
23 #include "insets/insettext.h"
24 #include "insets/insettoc.h"
25 #include "frontends/Dialogs.h"
26 #include "frontends/LyXView.h"
27
28 #include <cstdio>
29
30
31 Inset * createInset(FuncRequest const & cmd)
32 {
33         BufferView * bv = cmd.view();
34         BufferParams const & params = bv->buffer()->params;
35
36         switch (cmd.action) {
37
38                 case LFUN_INSET_MINIPAGE:
39                         return new InsetMinipage(params);
40
41                 case LFUN_INSERT_NOTE:
42                         return new InsetNote(params);
43
44                 case LFUN_INSET_ERT:
45                         return new InsetERT(params);
46
47                 case LFUN_INSET_EXTERNAL:
48                         return new InsetExternal;
49
50                 case LFUN_INSET_FOOTNOTE:
51                         return new InsetFoot(params);
52
53                 case LFUN_INSET_MARGINAL:
54                         return new InsetMarginal(params);
55
56                 case LFUN_INSET_OPTARG:
57                         return new InsetOptArg(params);
58
59                 case LFUN_INSET_FLOAT:
60                         // check if the float type exists
61                         if (params.getLyXTextClass().floats().typeExist(cmd.argument))
62                                 return new InsetFloat(params, cmd.argument);
63                         lyxerr << "Non-existent float type: " << cmd.argument << endl;
64                         return 0;
65
66                 case LFUN_INSET_WIDE_FLOAT:
67                         // check if the float type exists
68                         if (params.getLyXTextClass().floats().typeExist(cmd.argument)) {
69                                 InsetFloat * p = new InsetFloat(params, cmd.argument);
70                                 p->wide(true, params);
71                         }
72                         lyxerr << "Non-existent float type: " << cmd.argument << endl;
73                         return 0;
74
75                 case LFUN_INDEX_INSERT: {
76                         string entry = cmd.argument;
77                         if (entry.empty())
78                                 entry = bv->getLyXText()->getStringToIndex(bv);
79                         if (!entry.empty())
80                                 return new InsetIndex(InsetCommandParams("index", entry));
81                         bv->owner()->getDialogs().createIndex();
82                         return 0;
83                 }
84
85                 case LFUN_TABULAR_INSERT:
86                         if (!cmd.argument.empty()) {
87                                 int r = 2;
88                                 int c = 2;
89                                 ::sscanf(cmd.argument.c_str(),"%d%d", &r, &c);
90                                 return new InsetTabular(*bv->buffer(), r, c);
91                         }
92                         bv->owner()->getDialogs().showTabularCreate();
93                         return 0;
94
95                 case LFUN_INSET_CAPTION:
96                         if (bv->theLockingInset()) {
97                                 lyxerr << "Locking inset code: "
98                                                          << static_cast<int>(bv->theLockingInset()->lyxCode());
99                                 InsetCaption * inset = new InsetCaption(params);
100                                 inset->setOwner(bv->theLockingInset());
101                                 inset->setAutoBreakRows(true);
102                                 inset->setDrawFrame(0, InsetText::LOCKED);
103                                 inset->setFrameColor(0, LColor::captionframe);
104                                 return inset;
105                         }
106                         return 0;
107
108                 case LFUN_INDEX_PRINT: 
109                         return new InsetPrintIndex(InsetCommandParams("printindex"));
110
111                 case LFUN_TOC_INSERT:
112                         return new InsetTOC(InsetCommandParams("tableofcontents"));
113
114                 case LFUN_PARENTINSERT:
115                         return new InsetParent(
116                                 InsetCommandParams("lyxparent", cmd.argument), *bv->buffer());
117
118         #if 0
119                 case LFUN_INSET_LIST:
120                         return new InsetList;
121
122                 case LFUN_INSET_THEOREM:
123                         return new InsetTheorem;
124         #endif
125
126                 default:
127                         break;
128         }
129         return 0;
130 }
131
132