]> git.lyx.org Git - lyx.git/blob - src/mathed/math_macrotable.C
move more support functions into namespace lyx, small other changes
[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 MathMacroTable::mathMTable;
22
23 bool MathMacroTable::built = false;
24
25
26 MathMacro * MathMacroTable::createMacro(string const & name) const
27 {
28         boost::shared_ptr<MathMacroTemplate> mt = getTemplate(name);
29         return (mt.get()) ? new MathMacro(mt) : 0;
30 }
31
32
33 boost::shared_ptr<MathMacroTemplate> const
34 MathMacroTable::getTemplate(string const & name) const
35 {
36         table_type::const_iterator cit = macro_table.find(name);
37         if (cit != macro_table.end()) return (*cit).second;
38         return boost::shared_ptr<MathMacroTemplate>();
39 }
40
41
42 void
43 MathMacroTable::addTemplate(boost::shared_ptr<MathMacroTemplate> const & m)
44 {
45         lyx::Assert(m.get());
46         macro_table[m->GetName()] = m;
47 }
48
49
50 void MathMacroTable::builtinMacros()
51 {
52         built = true;
53     
54         lyxerr[Debug::MATHED] << "Building macros" << endl;
55     
56         // This macro doesn't have arguments
57         {
58                 boost::shared_ptr<MathMacroTemplate> m(new MathMacroTemplate("notin", 0));
59                 addTemplate(m);
60                 MathedArray array;
61                 MathedIter iter(&array);
62                 iter.insertInset(new MathAccentInset(LM_in, LM_TC_BOPS, LM_not),
63                                  LM_TC_INSET);
64                 m->setData(array);
65         }
66     
67         // These two are only while we are still with LyX 2.x
68         {
69                 boost::shared_ptr<MathMacroTemplate> m(new MathMacroTemplate("emptyset", 0));
70                 addTemplate(m); 
71                 MathedArray array;
72                 MathedIter iter(&array);
73                 iter.insertInset(new MathAccentInset('O', LM_TC_RM, LM_not),
74                                  LM_TC_INSET);
75                 m->setData(array);
76         }
77     
78         {
79                 boost::shared_ptr<MathMacroTemplate> m(new MathMacroTemplate("perp", 0));
80                 addTemplate(m);
81                 MathedArray array;
82                 MathedIter iter(&array);
83                 iter.insert(LM_bot, LM_TC_BOP);
84                 m->setData(array);
85         }
86
87         // binom has two arguments
88         {
89                 boost::shared_ptr<MathMacroTemplate> m(new MathMacroTemplate("binom", 2));
90                 addTemplate(m);
91                 MathedArray array;
92                 m->setData(array);
93                 MathedIter iter(&array);
94                 MathParInset * inset = new MathDelimInset('(', ')');
95                 iter.insertInset(inset, LM_TC_ACTIVE_INSET);
96                 array = MathedArray();
97                 MathedIter iter2(&array);
98                 MathFracInset * frac = new MathFracInset(LM_OT_ATOP);
99                 iter2.insertInset(frac, LM_TC_ACTIVE_INSET);
100                 inset->setData(array);
101                 array = MathedArray();
102                 MathedArray array2;
103                 MathedIter iter3(&array);
104                 iter3.insertInset(m->getMacroPar(0), LM_TC_INSET);
105                 MathedIter iter4(&array2);
106                 iter4.insertInset(m->getMacroPar(1), LM_TC_INSET);
107                 frac->SetData(array, array2);
108         }
109 }