]> git.lyx.org Git - lyx.git/blob - src/mathed/math_macrotable.C
mathed64.diff
[lyx.git] / src / mathed / math_macrotable.C
1 #include <config.h>
2
3 #ifdef __GNUG__
4 #pragma implementation
5 #endif
6
7 #include "math_macrotable.h"
8 #include "math_macro.h"
9 #include "math_macrotemplate.h"
10 #include "math_iter.h"
11 #include "array.h"
12 #include "math_accentinset.h"
13 #include "math_deliminset.h"
14 #include "math_fracinset.h"
15 #include "math_parinset.h"
16 #include "debug.h"
17 #include "support/LAssert.h"
18
19 using std::endl;
20
21 MathMacroTable::table_type MathMacroTable::macro_table;
22
23 bool MathMacroTable::built = false;
24
25
26 void MathMacroTable::dump()
27 {
28         cerr << "\n------------------------------------------\n";
29         table_type::const_iterator it;
30         for (it = macro_table.begin(); it != macro_table.end(); ++it)
31                 cerr << it->first << ": " << it->second->GetData() << endl;
32         cerr << "------------------------------------------\n";
33 }
34
35
36 MathMacroTemplate &
37 MathMacroTable::provideTemplate(string const & name, int na)
38 {
39         if (!built)
40                 builtinMacros();
41         
42         if (macro_table.find(name) == macro_table.end())
43                 macro_table.insert(make_pair(name, new MathMacroTemplate(name, na)));
44         
45         return *(macro_table.find(name)->second);
46 }
47
48
49 MathMacroTemplate &
50 MathMacroTable::provideTemplate(string const & name)
51 {
52         if (!built)
53                 builtinMacros();
54         
55         return *macro_table[name];
56 }
57
58
59 bool MathMacroTable::hasTemplate(string const & name)
60 {
61         if (!built)
62                 builtinMacros();
63         
64         return macro_table.find(name) != macro_table.end();
65 }
66
67
68 MathMacro * MathMacroTable::cloneTemplate(string const & name)
69 {
70         return new MathMacro(provideTemplate(name));
71 }
72
73
74 void MathMacroTable::builtinMacros()
75 {
76         built = true;
77     
78         lyxerr[Debug::MATHED] << "Building macros" << endl;
79     
80         // This macro doesn't have arguments
81         {
82                 MathMacroTemplate & m = provideTemplate("notin", 0);
83                 MathedIter iter(&m.GetData());
84                 iter.insertInset(new MathAccentInset(LM_in, LM_TC_BOPS, LM_not),
85                                  LM_TC_INSET);
86         }
87
88         // These two are only while we are still with LyX 2.x
89         {
90                 MathMacroTemplate & m = provideTemplate("emptyset", 0);
91                 MathedIter iter(&m.GetData());
92                 iter.insertInset(new MathAccentInset('0', LM_TC_RM, LM_not),
93                                  LM_TC_INSET);
94         }
95
96         {
97                 MathMacroTemplate & m = provideTemplate("perp", 0);
98                 MathedIter iter(&m.GetData());
99                 iter.insert(LM_bot, LM_TC_BOP);
100         }
101
102         // binom has two arguments
103         {
104                 MathMacroTemplate & m = provideTemplate("binom", 2);
105                 MathedIter iter(&m.GetData());
106
107                 MathParInset * inset = new MathDelimInset('(', ')');
108                 iter.insertInset(inset, LM_TC_ACTIVE_INSET);
109
110                 MathedArray array2;
111                 MathedIter iter2(&array2);
112                 MathFracInset * frac = new MathFracInset(LM_OT_ATOP);
113                 iter2.insertInset(frac, LM_TC_ACTIVE_INSET);
114                 frac->setData(array2);
115
116                 MathedArray array3;
117                 MathedIter iter3(&array3);
118                 iter3.insertInset(new MathMacroArgument(1), LM_TC_INSET);
119
120                 MathedArray array4;
121                 MathedIter iter4(&array4);
122                 iter4.insertInset(new MathMacroArgument(2), LM_TC_INSET);
123
124                 frac->SetData(array3, array4);
125         }
126
127 /*    
128         {
129                 boost::shared_ptr<MathMacroTemplate> m(new MathMacroTemplate("perp", 0));
130                 addTemplate(m);
131                 MathedArray array;
132                 MathedIter iter(&array);
133                 iter.insert(LM_bot, LM_TC_BOP);
134                 m->setData(array);
135         }
136
137         // binom has two arguments
138         {
139                 boost::shared_ptr<MathMacroTemplate> m(new MathMacroTemplate("binom", 2));
140                 addTemplate(m);
141                 MathedArray array;
142                 m->setData(array);
143                 MathedIter iter(&array);
144                 MathParInset * inset = new MathDelimInset('(', ')');
145                 iter.insertInset(inset, LM_TC_ACTIVE_INSET);
146                 array = MathedArray();
147                 MathedIter iter2(&array);
148                 MathFracInset * frac = new MathFracInset(LM_OT_ATOP);
149                 iter2.insertInset(frac, LM_TC_ACTIVE_INSET);
150                 inset->setData(array);
151                 array = MathedArray();
152                 MathedArray array2;
153                 MathedIter iter3(&array);
154                 iter3.insertInset(m->getMacroPar(0), LM_TC_INSET);
155                 MathedIter iter4(&array2);
156                 iter4.insertInset(m->getMacroPar(1), LM_TC_INSET);
157                 frac->SetData(array, array2);
158         }
159 */
160 }