]> git.lyx.org Git - features.git/blob - src/frontends/qt4/GuiMath.cpp
f3d3a982d75674b96aa7fdc5d05aa910f8eff57d
[features.git] / src / frontends / qt4 / GuiMath.cpp
1 /**
2  * \file GuiMath.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "GuiMath.h"
14
15 #include "FuncRequest.h"
16
17 #include "support/debug.h"
18
19 using namespace std;
20
21 namespace lyx {
22 namespace frontend {
23
24 GuiMath::GuiMath(GuiView & lv, QString const & name, QString const & title)
25         : GuiDialog(lv, name, title)
26 {
27         // FIXME: Ideally, those unicode codepoints would be defined
28         // in "lib/symbols". Unfortunately, some of those are already
29         // defined with non-unicode ids for use within mathed.
30         // FIXME 2: We should fill-in this map with the parsed "symbols"
31         // file done in MathFactory.cpp.
32         math_symbols_["("] = MathSymbol('(');
33         math_symbols_[")"] = MathSymbol(')');
34         math_symbols_["{"] = MathSymbol('{');
35         math_symbols_["}"] = MathSymbol('}');
36         math_symbols_["["] = MathSymbol('[');
37         math_symbols_["]"] = MathSymbol(']');
38         math_symbols_["|"] = MathSymbol('|');
39         math_symbols_["/"] = MathSymbol('/', 54, CMSY_FAMILY);
40         math_symbols_["backslash"] = MathSymbol('\\', 110, CMSY_FAMILY);
41         math_symbols_["lceil"] = MathSymbol(0x2308, 100, CMSY_FAMILY);
42         math_symbols_["rceil"] = MathSymbol(0x2309, 101, CMSY_FAMILY);
43         math_symbols_["lfloor"] = MathSymbol(0x230A, 98, CMSY_FAMILY);
44         math_symbols_["rfloor"] = MathSymbol(0x230B, 99, CMSY_FAMILY);
45         math_symbols_["langle"] = MathSymbol(0x2329, 104, CMSY_FAMILY);
46         math_symbols_["rangle"] = MathSymbol(0x232A, 105, CMSY_FAMILY);
47         math_symbols_["uparrow"] = MathSymbol(0x2191, 34, CMSY_FAMILY);
48         math_symbols_["Uparrow"] = MathSymbol(0x21D1, 42, CMSY_FAMILY);
49         math_symbols_["updownarrow"] = MathSymbol(0x2195, 108, CMSY_FAMILY);
50         math_symbols_["Updownarrow"] = MathSymbol(0x21D5, 109, CMSY_FAMILY);
51         math_symbols_["downarrow"] = MathSymbol(0x2193, 35, CMSY_FAMILY);
52         math_symbols_["Downarrow"] = MathSymbol(0x21D3, 43, CMSY_FAMILY);
53         math_symbols_["downdownarrows"] = MathSymbol(0x21CA, 184, MSA_FAMILY);
54         math_symbols_["downharpoonleft"] = MathSymbol(0x21C3, 188, MSA_FAMILY);
55         math_symbols_["downharpoonright"] = MathSymbol(0x21C2, 186, MSA_FAMILY);
56         math_symbols_["vert"] = MathSymbol(0x007C, 106, CMSY_FAMILY);
57         math_symbols_["Vert"] = MathSymbol(0x2016, 107, CMSY_FAMILY);
58
59         map<string, MathSymbol>::const_iterator it = math_symbols_.begin();
60         map<string, MathSymbol>::const_iterator end = math_symbols_.end();
61         for (; it != end; ++it)
62                 tex_names_[it->second.unicode] = it->first;
63 }
64
65
66 void GuiMath::dispatchFunc(FuncCode action, string const & arg) const
67 {
68         dispatch(FuncRequest(action, arg));
69 }
70
71
72 MathSymbol const & GuiMath::mathSymbol(string tex_name) const
73 {
74         map<string, MathSymbol>::const_iterator it =
75                 math_symbols_.find(tex_name);
76
77         static MathSymbol unknown_symbol;
78         if (it == math_symbols_.end())
79                 return unknown_symbol;
80
81         return it->second;
82 }
83
84
85 string const & GuiMath::texName(char_type math_symbol) const
86 {
87         map<char_type, string>::const_iterator it =
88                 tex_names_.find(math_symbol);
89
90         static string empty_string;
91         if (it == tex_names_.end())
92                 return empty_string;
93
94         return it->second;
95 }
96
97
98 } // namespace frontend
99 } // namespace lyx