]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiMath.cpp
We do not need to update just because the class has been changed.
[lyx.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 #include "support/debug.h"
15 #include "FuncRequest.h"
16
17 using namespace std;
18
19 namespace lyx {
20 namespace frontend {
21
22 GuiMath::GuiMath(GuiView & lv, string const & name)
23         : GuiDialog(lv, name)
24 {
25         // FIXME: Ideally, those unicode codepoints would be defined
26         // in "lib/symbols". Unfortunately, some of those are already
27         // defined with non-unicode ids for use within mathed.
28         // FIXME 2: We should fill-in this map with the parsed "symbols"
29         // file done in MathFactory.cpp.
30         math_symbols_["("] = MathSymbol('(');
31         math_symbols_[")"] = MathSymbol(')');
32         math_symbols_["{"] = MathSymbol('{');
33         math_symbols_["}"] = MathSymbol('}');
34         math_symbols_["["] = MathSymbol('[');
35         math_symbols_["]"] = MathSymbol(']');
36         math_symbols_["|"] = MathSymbol('|');
37         math_symbols_["/"] = MathSymbol('/', 54, CMSY_FAMILY);
38         math_symbols_["backslash"] = MathSymbol('\\', 110, CMSY_FAMILY);
39         math_symbols_["lceil"] = MathSymbol(0x2308, 100, CMSY_FAMILY);
40         math_symbols_["rceil"] = MathSymbol(0x2309, 101, CMSY_FAMILY);
41         math_symbols_["lfloor"] = MathSymbol(0x230A, 98, CMSY_FAMILY);
42         math_symbols_["rfloor"] = MathSymbol(0x230B, 99, CMSY_FAMILY);
43         math_symbols_["langle"] = MathSymbol(0x2329, 104, CMSY_FAMILY);
44         math_symbols_["rangle"] = MathSymbol(0x232A, 105, CMSY_FAMILY);
45         math_symbols_["uparrow"] = MathSymbol(0x2191, 34, CMSY_FAMILY);
46         math_symbols_["Uparrow"] = MathSymbol(0x21D1, 42, CMSY_FAMILY);
47         math_symbols_["updownarrow"] = MathSymbol(0x2195, 108, CMSY_FAMILY);
48         math_symbols_["Updownarrow"] = MathSymbol(0x21D5, 109, CMSY_FAMILY);
49         math_symbols_["downarrow"] = MathSymbol(0x2193, 35, CMSY_FAMILY);
50         math_symbols_["Downarrow"] = MathSymbol(0x21D3, 43, CMSY_FAMILY);
51         math_symbols_["downdownarrows"] = MathSymbol(0x21CA, 184, MSA_FAMILY);
52         math_symbols_["downharpoonleft"] = MathSymbol(0x21C3, 188, MSA_FAMILY);
53         math_symbols_["downharpoonright"] = MathSymbol(0x21C2, 186, MSA_FAMILY);
54         math_symbols_["vert"] = MathSymbol(0x007C, 106, CMSY_FAMILY);
55         math_symbols_["Vert"] = MathSymbol(0x2016, 107, CMSY_FAMILY);
56
57         map<string, MathSymbol>::const_iterator it = math_symbols_.begin();
58         map<string, MathSymbol>::const_iterator end = math_symbols_.end();
59         for (; it != end; ++it)
60                 tex_names_[it->second.unicode] = it->first;
61 }
62
63
64 void GuiMath::dispatchFunc(kb_action action, string const & arg) const
65 {
66         dispatch(FuncRequest(action, arg));
67 }
68
69
70 void GuiMath::dispatchInsert(string const & name) const
71 {
72         dispatchFunc(LFUN_MATH_INSERT, '\\' + name);
73 }
74
75
76 void GuiMath::dispatchSubscript() const
77 {
78         dispatchFunc(LFUN_MATH_INSERT, "_");
79 }
80
81
82 void GuiMath::dispatchSuperscript() const
83 {
84         dispatchFunc(LFUN_MATH_INSERT, "^");
85 }
86
87
88 void GuiMath::dispatchCubeRoot() const
89 {
90         dispatchFunc(LFUN_MATH_INSERT, "\\root");
91         dispatchFunc(LFUN_SELF_INSERT, "3");
92         dispatchFunc(LFUN_CHAR_FORWARD);
93 }
94
95
96 void GuiMath::dispatchMatrix(string const & str) const
97 {
98         dispatchFunc(LFUN_MATH_MATRIX, str);
99 }
100
101
102 void GuiMath::dispatchDelim(string const & str) const
103 {
104         dispatchFunc(LFUN_MATH_DELIM, str);
105 }
106
107
108 void GuiMath::dispatchBigDelim(string const & str) const
109 {
110         dispatchFunc(LFUN_MATH_BIGDELIM, str);
111 }
112
113
114 void GuiMath::dispatchToggleDisplay() const
115 {
116         dispatchFunc(LFUN_MATH_DISPLAY);
117 }
118
119
120 void GuiMath::showDialog(string const & name) const
121 {
122         dispatchFunc(LFUN_DIALOG_SHOW, name);
123 }
124
125
126 MathSymbol const & GuiMath::mathSymbol(string tex_name) const
127 {
128         map<string, MathSymbol>::const_iterator it =
129                 math_symbols_.find(tex_name);
130
131         static MathSymbol unknown_symbol;
132         if (it == math_symbols_.end())
133                 return unknown_symbol;
134
135         return it->second;
136 }
137
138
139 string const & GuiMath::texName(char_type math_symbol) const
140 {
141         map<char_type, string>::const_iterator it =
142                 tex_names_.find(math_symbol);
143
144         static string empty_string;
145         if (it == tex_names_.end())
146                 return empty_string;
147
148         return it->second;
149 }
150
151
152 } // namespace frontend
153 } // namespace lyx