]> git.lyx.org Git - lyx.git/blob - src/mathed/math_macrotable.C
mathed29.diff
[lyx.git] / src / mathed / math_macrotable.C
1 #include <config.h>
2
3 #include "math_macrotable.h"
4 #include "math_macro.h"
5 #include "math_macrotemplate.h"
6 #include "math_iter.h"
7 #include "array.h"
8 #include "math_accentinset.h"
9 #include "math_deliminset.h"
10 #include "math_fracinset.h"
11 #include "math_parinset.h"
12 #include "debug.h"
13
14 using std::endl;
15
16 MathMacroTable MathMacroTable::mathMTable;
17
18 bool MathMacroTable::built = false;
19
20
21 MathMacro * MathMacroTable::getMacro(string const & name) const
22 {
23         MathMacroTemplate * mt = getTemplate(name);
24         return (mt) ? new MathMacro(mt): 0;
25 }
26
27
28 // The search is currently linear but will be binary or hash, later.
29 MathMacroTemplate * MathMacroTable::getTemplate(string const & name) const
30 {
31         for (size_type i = 0; i < macro_table.size(); ++i) {
32                 if (name == macro_table[i]->GetName()) 
33                         return macro_table[i];
34         }
35
36         return 0;
37 }
38
39 void MathMacroTable::addTemplate(MathMacroTemplate * m)
40 {
41         macro_table.push_back(m);
42 }
43
44
45 // All this stuff aparently leaks because it's created here and is not 
46 // deleted never, but it have to live all the LyX sesion. OK, would not
47 // so hard to do it in the MacroTable destructor, but this doesn't harm
48 // seriously, so don't bother me with purify results here.   ;-)
49
50 void MathMacroTable::builtinMacros()
51 {
52         MathParInset * inset;// *arg;
53     
54         built = true;
55     
56         lyxerr[Debug::MATHED] << "Building macros" << endl;
57     
58         // This macro doesn't have arguments
59         MathMacroTemplate * m = new MathMacroTemplate("notin");  // this leaks
60         addTemplate(m);
61         {
62                 MathedArray * array = new MathedArray; // this leaks
63                 MathedIter iter(array);
64                 iter.insertInset(new MathAccentInset(LM_in, LM_TC_BOPS, LM_not),
65                                  LM_TC_INSET); // this leaks
66                 m->setData(array);
67         }
68     
69         // These two are only while we are still with LyX 2.x
70         m = new MathMacroTemplate("emptyset"); // this leaks
71         addTemplate(m); 
72         {
73                 MathedArray * array = new MathedArray; // this leaks
74                 MathedIter iter(array);
75                 iter.insertInset(new MathAccentInset('O', LM_TC_RM, LM_not),
76                                  LM_TC_INSET); // this leaks
77                 m->setData(array);
78         }
79     
80         m = new MathMacroTemplate("perp"); // this leaks
81         addTemplate(m);
82         {
83                 MathedArray * array = new MathedArray; // this leaks
84                 MathedIter iter(array);
85                 iter.insert(LM_bot, LM_TC_BOP);
86                 m->setData(array);
87         }
88
89         // binom has two arguments
90         m = new MathMacroTemplate("binom", 2);
91         addTemplate(m);
92         {
93                 MathedArray * array = new MathedArray; 
94                 m->setData(array);
95                 MathedIter iter(array);
96                 inset = new MathDelimInset('(', ')');
97                 iter.insertInset(inset, LM_TC_ACTIVE_INSET);
98                 array = new MathedArray; 
99                 MathedIter iter2(array);
100                 MathFracInset * frac = new MathFracInset(LM_OT_ATOP);
101                 iter2.insertInset(frac, LM_TC_ACTIVE_INSET);
102                 inset->setData(array);
103                 array = new MathedArray;
104                 MathedArray * array2 = new MathedArray;  
105                 MathedIter iter3(array);
106                 iter3.insertInset(m->getMacroPar(0), LM_TC_INSET);
107                 MathedIter iter4(array2);
108                 iter4.insertInset(m->getMacroPar(1), LM_TC_INSET);
109                 frac->SetData(array, array2);
110         }
111
112 /*
113   // Cases has 1 argument
114   m = new MathMacroTemplate("cases", 1, MMF_Env); // this leaks
115   addTemplate(m);
116   array = new MathedArray; // this leaks
117   iter.SetData(array);
118   arg = new MathMatrixInset(2, 1); // this leaks
119
120   m->setArgument(arg);
121   arg->SetAlign('c', "ll");
122   iter.Insert(arg, LM_TC_ACTIVE_INSET);
123   inset = new MathDelimInset('{', '.'); // this leaks
124   inset->SetData(array);
125   array = new MathedArray; // this leaks
126   iter.SetData(array);
127   iter.Insert(inset, LM_TC_ACTIVE_INSET);
128   m->SetData(array);
129   
130
131   // the environment substack has 1 argument
132   m = new MathMacroTemplate("substack", 1, MMF_Env); // this leaks
133   addTemplate(m);     
134   arg = new MathMatrixInset(1, 1); // this leaks
135   m->setArgument(arg);
136   arg->SetType(LM_OT_MACRO);
137   array = new MathedArray; // this leaks
138   iter.SetData(array);
139   iter.Insert(arg, LM_TC_ACTIVE_INSET);
140   m->SetData(array);*/
141 }