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