]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlMath.C
Remove a whole heap of redundant functions from classes derived from
[lyx.git] / src / frontends / controllers / ControlMath.C
1 /**
2  * \file ControlMath.C
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 "ControlMath.h"
14 #include "debug.h"
15 #include "funcrequest.h"
16
17 #include "support/lyxalgo.h" // sorted
18 #include "support/lstrings.h"
19 #include "support/filetools.h"
20
21 using lyx::support::compare;
22 using lyx::support::LibFileSearch;
23 using lyx::support::subst;
24
25 using std::string;
26
27
28 ControlMath::ControlMath(Dialog & dialog)
29         : Dialog::Controller(dialog)
30 {}
31
32
33 void ControlMath::dispatchFunc(kb_action action, string const & arg) const
34 {
35         kernel().dispatch(FuncRequest(action, arg));
36 }
37
38
39 void ControlMath::dispatchInsert(string const & name) const
40 {
41         dispatchFunc(LFUN_INSERT_MATH, '\\' + name);
42 }
43
44
45 void ControlMath::dispatchSubscript() const
46 {
47         dispatchFunc(LFUN_SUBSCRIPT);
48 }
49
50
51 void ControlMath::dispatchSuperscript() const
52 {
53         dispatchFunc(LFUN_SUPERSCRIPT);
54 }
55
56
57 void ControlMath::dispatchCubeRoot() const
58 {
59         dispatchFunc(LFUN_INSERT_MATH, "\\root");
60         dispatchFunc(LFUN_SELFINSERT, "3");
61         dispatchFunc(LFUN_RIGHT);
62 }
63
64
65 void ControlMath::dispatchMatrix(string const & str) const
66 {
67         dispatchFunc(LFUN_INSERT_MATRIX, str);
68 }
69
70
71 void ControlMath::dispatchDelim(string const & str) const
72 {
73         dispatchFunc(LFUN_MATH_DELIM, str);
74 }
75
76
77 void ControlMath::dispatchToggleDisplay() const
78 {
79         dispatchFunc(LFUN_MATH_DISPLAY);
80 }
81
82
83 void ControlMath::showDialog(string const & name) const
84 {
85         dispatchFunc(LFUN_DIALOG_SHOW, name);
86 }
87
88
89 char const * function_names[] = {
90         "arccos", "arcsin", "arctan", "arg", "bmod",
91         "cos", "cosh", "cot", "coth", "csc", "deg",
92         "det", "dim", "exp", "gcd", "hom", "inf", "ker",
93         "lg", "lim", "liminf", "limsup", "ln", "log",
94         "max", "min", "sec", "sin", "sinh", "sup",
95         "tan", "tanh", "Pr", ""
96 };
97
98 int const nr_function_names = sizeof(function_names) / sizeof(char const *) - 1;
99
100 char const * latex_dots[] = {
101         "ldots", "cdots", "vdots", "ddots", ""
102 };
103
104 int const nr_latex_dots = sizeof(latex_dots) / sizeof(char const *) - 1;
105
106 char const * latex_deco[] = {
107         "widehat", "widetilde", "overbrace", "overleftarrow", "overrightarrow",
108         "overline", "underbrace", "underline", "underleftarrow", "underrightarrow",
109         "underleftrightarrow", "overleftrightarrow",
110         "hat", "acute", "bar", "dot",
111         "check", "grave", "vec", "ddot",
112         "breve", "tilde", ""
113 };
114
115 int const nr_latex_deco = sizeof(latex_deco) / sizeof(char const *) - 1;
116
117 char const * latex_arrow[] = {
118         "downarrow", "leftarrow", "Downarrow", "Leftarrow",
119         "hookleftarrow", "rightarrow", "uparrow", "Rightarrow", "Uparrow",
120         "hookrightarrow", "updownarrow", "Leftrightarrow", "leftharpoonup",
121         "rightharpoonup", "rightleftharpoons", "leftrightarrow", "Updownarrow",
122         "leftharpoondown", "rightharpoondown", "mapsto",
123         "Longleftarrow", "Longrightarrow", "Longleftrightarrow",
124         "longleftrightarrow", "longleftarrow", "longrightarrow", "longmapsto",
125         "nwarrow", "nearrow", "swarrow", "searrow",  "",
126 };
127
128 int const nr_latex_arrow = sizeof(latex_arrow) / sizeof(char const *);
129
130 char const * latex_bop[] = {
131         "pm", "cap", "diamond", "oplus",
132         "mp", "cup", "bigtriangleup", "ominus",
133         "times", "uplus", "bigtriangledown", "otimes",
134         "div", "sqcap", "triangleright", "oslash",
135         "cdot", "sqcup", "triangleleft", "odot",
136         "star", "vee", "amalg", "bigcirc",
137         "setminus", "wedge", "dagger", "circ",
138         "bullet", "wr", "ddagger", ""
139 };
140
141 int const nr_latex_bop = sizeof(latex_bop) / sizeof(char const *);
142
143 char const * latex_brel[] = {
144         "leq", "geq", "equiv", "models",
145         "prec", "succ", "sim", "perp",
146         "preceq", "succeq", "simeq", "mid",
147         "ll", "gg", "asymp", "parallel",
148         "subset", "supset", "approx", "smile",
149         "subseteq", "supseteq", "cong", "frown",
150         "sqsubseteq", "sqsupseteq", "doteq", "neq",
151         "in", "ni", "propto", "notin",
152         "vdash", "dashv", "bowtie", ""
153 };
154
155 int const nr_latex_brel = sizeof(latex_brel) / sizeof(char const *);
156
157 char const * latex_greek[] = {
158         "Gamma", "Delta", "Theta", "Lambda", "Xi", "Pi",
159         "Sigma", "Upsilon", "Phi", "Psi", "Omega",
160         "alpha", "beta", "gamma", "delta", "epsilon", "varepsilon", "zeta",
161         "eta", "theta", "vartheta", "iota", "kappa", "lambda", "mu",
162         "nu", "xi", "pi", "varpi", "rho", "sigma", "varsigma",
163         "tau", "upsilon", "phi", "varphi", "chi", "psi", "omega", ""
164 };
165
166 int const nr_latex_greek = sizeof(latex_greek) / sizeof(char const *);
167
168 char const * latex_misc[] = {
169         "nabla", "partial", "infty", "prime", "ell",
170         "emptyset", "exists", "forall", "imath",  "jmath",
171         "Re", "Im", "aleph", "wp", "hbar",
172         "angle", "top", "bot", "Vert", "neg",
173         "flat", "natural", "sharp", "surd", "triangle",
174         "diamondsuit", "heartsuit", "clubsuit", "spadesuit",
175         "textrm Å", "textrm Ø", "mathcircumflex", "_",
176         "mathrm T",
177         "mathbb N", "mathbb Z", "mathbb Q",
178         "mathbb R", "mathbb C", "mathbb H",
179         "mathcal F", "mathcal L",
180         "mathcal H", "mathcal O", ""
181 };
182
183 int const nr_latex_misc = sizeof(latex_misc) / sizeof(char const *);
184
185 char const * latex_varsz[] = {
186         "sum", "int", "oint",
187         "prod", "coprod", "bigsqcup",
188         "bigotimes", "bigodot", "bigoplus",
189         "bigcap", "bigcup", "biguplus",
190         "bigvee", "bigwedge", ""
191 };
192
193 int const nr_latex_varsz = sizeof(latex_varsz) / sizeof(char const *);
194
195 char const * latex_ams_misc[] = {
196         "digamma", "varkappa", "beth", "daleth", "gimel",
197         "ulcorner", "urcorner", "llcorner", "lrcorner",
198         "hbar", "hslash", "vartriangle",
199         "triangledown", "square", "lozenge",
200         "circledS", "angle", "measuredangle",
201         "nexists", "mho", "Finv",
202         "Game", "Bbbk", "backprime",
203         "varnothing", "blacktriangle", "blacktriangledown",
204         "blacksquare", "blacklozenge", "bigstar",
205         "sphericalangle", "complement", "eth",
206         "diagup", "diagdown", ""
207 };
208
209 int const nr_latex_ams_misc = sizeof(latex_ams_misc) / sizeof(char const *);
210
211 char const * latex_ams_arrows[] = {
212         "dashrightarrow", "dashleftarrow", "leftleftarrows",
213         "leftrightarrows", "Lleftarrow", "twoheadleftarrow",
214         "leftarrowtail", "looparrowleft", "leftrightharpoons",
215         "curvearrowleft", "circlearrowleft", "Lsh",
216         "upuparrows", "upharpoonleft", "downharpoonleft",
217         "multimap", "leftrightsquigarrow", "rightrightarrows",
218         "rightleftarrows", "rightrightarrows", "rightleftarrows",
219         "twoheadrightarrow", "rightarrowtail", "looparrowright",
220         "rightleftharpoons", "curvearrowright", "circlearrowright",
221         "Rsh", "downdownarrows", "upharpoonright",
222         "downharpoonright", "rightsquigarrow",
223         "nleftarrow", "nrightarrow", "nLeftarrow",
224         "nRightarrow", "nleftrightarrow", "nLeftrightarrow", ""
225 };
226
227 int const nr_latex_ams_arrows = sizeof(latex_ams_arrows) / sizeof(char const *);
228
229 char const * latex_ams_rel[] = {
230         "leqq", "leqslant", "eqslantless", "eqslantgtr", "gtrsim", "gtrapprox",
231         "lesssim", "lessapprox", "approxeq", "gtrdot", "ggg", "gtrless",
232         "lessdot", "lll", "lessgtr", "gtreqless", "gtreqqless", "eqcirc",
233         "lesseqgtr", "lesseqqgtr", "doteqdot", "circeq", "triangleq", "thicksim",
234         "risingdotseq", "fallingdotseq", "backsim", "thickapprox", "supseteqq", "Supset",
235         "backsimeq", "subseteqq", "Subset", "sqsupset", "succcurlyeq", "curlyeqsucc",
236         "sqsubset", "preccurlyeq", "curlyeqprec", "succsim", "succapprox", "vartriangleright",
237         "precsim", "precapprox", "vartriangleleft", "trianglerighteq", "Vdash", "shortmid",
238         "trianglelefteq", "vDash", "Vvdash", "shortparallel", "between", "pitchfork",
239         "smallsmile", "smallfrown", "bumpeq", "varpropto", "blacktriangleleft", "therefore",
240         "Bumpeq", "geqq", "geqslant", "backepsilon", "blacktriangleright", "because", ""
241 };
242
243 int const nr_latex_ams_rel = sizeof(latex_ams_rel) / sizeof(char const *);
244
245 char const * latex_ams_nrel[] = {
246         "nless", "nleq", "nleqslant", "ngeqslant", "ngeqq", "gneq",
247         "nleqq", "lneq", "lneqq", "gneqq", "gvertneqq", "gnsim",
248         "lvertneqq", "lnsim", "lnapprox", "gnapprox", "nsucc", "nsucceq",
249         "nprec", "npreceq", "precnsim","succnsim", "succnapprox", "ncong",
250         "precnapprox", "nsim", "nshortmid", "nshortparallel", "nparallel", "nvDash",
251
252         "nmid", "nvdash", "nvDash", "nVDash", "ntriangleright", "ntrianglerighteq",
253         "ntriangleleft", "ntrianglelefteq", "nsubseteq", "nsupseteq", "nsupseteqq", "supsetneq",
254         "subsetneq", "varsubsetneq", "subsetneqq", "varsupsetneq", "supsetneqq", "varsupsetneqq",
255         "varsubsetneqq", "ngtr", "ngeq", "", "", ""
256 };
257
258 int const nr_latex_ams_nrel = sizeof(latex_ams_nrel) / sizeof(char const *);
259
260
261 char const * latex_ams_ops[] = {
262         "dotplus", "smallsetminus", "Cap",
263         "Cup", "barwedge", "veebar",
264         "doublebarwedge", "boxminus", "boxtimes",
265         "boxdot", "boxplus", "divideontimes",
266         "ltimes", "rtimes", "leftthreetimes",
267         "rightthreetimes", "curlywedge", "curlyvee",
268         "circleddash", "circledast", "circledcirc",
269         "centerdot", "intercal", ""
270 };
271
272 int const nr_latex_ams_ops = sizeof(latex_ams_ops) / sizeof(char const *);
273
274
275 namespace {
276
277 struct XPMmap {
278         char const * key;
279         char const * value;
280 };
281
282
283 bool operator<(XPMmap const & lhs, XPMmap const & rhs)
284 {
285                 return compare(lhs.key, rhs.key) < 0;
286 }
287
288
289 struct CompareKey {
290         CompareKey(string const & name) : name_(name) {}
291         bool operator()(XPMmap const & other) {
292                 return compare(other.key, name_.c_str()) == 0;
293         }
294 private:
295         string const name_;
296 };
297
298
299 XPMmap sorted_xpm_map[] = {
300         { "Bumpeq", "bumpeq2" },
301         { "Cap", "cap2" },
302         { "Cup", "cup2" },
303         { "Delta", "delta2" },
304         { "Downarrow", "downarrow2" },
305         { "Gamma", "gamma2" },
306         { "Lambda", "lambda2" },
307         { "Leftarrow", "leftarrow2" },
308         { "Leftrightarrow", "leftrightarrow2" },
309         { "Longleftarrow", "longleftarrow2" },
310         { "Longleftrightarrow", "longleftrightarrow2" },
311         { "Longrightarrow", "longrightarrow2" },
312         { "Omega", "omega2" },
313         { "Phi", "phi2" },
314         { "Pi", "pi2" },
315         { "Psi", "psi2" },
316         { "Rightarrow", "rightarrow2" },
317         { "Sigma", "sigma2" },
318         { "Subset", "subset2" },
319         { "Supset", "supset2" },
320         { "Theta", "theta2" },
321         { "Uparrow", "uparrow2" },
322         { "Updownarrow", "updownarrow2" },
323         { "Upsilon", "upsilon2" },
324         { "Vdash", "vdash3" },
325         { "Xi", "xi2" },
326         { "nLeftarrow", "nleftarrow2" },
327         { "nLeftrightarrow", "nleftrightarrow2" },
328         { "nRightarrow", "nrightarrow2" },
329         { "nVDash", "nvdash3" },
330         { "nvDash", "nvdash2" },
331         { "textrm_Å", "textrm_A" },
332         { "textrm_Ø", "textrm_0" },
333         { "vDash", "vdash2" }
334 };
335
336 size_t const nr_sorted_xpm_map = sizeof(sorted_xpm_map) / sizeof(XPMmap);
337
338 } // namespace anon
339
340
341 string const find_xpm(string const & name)
342 {
343         XPMmap const * const begin = sorted_xpm_map;
344         XPMmap const * const end = begin + nr_sorted_xpm_map;
345         BOOST_ASSERT(lyx::sorted(begin, end));
346
347         XPMmap const * const it =
348                 std::find_if(begin, end, CompareKey(name));
349
350         string xpm_name;
351         if (it != end)
352                 xpm_name = it->value;
353         else {
354                 xpm_name = subst(name, "_", "underscore");
355                 xpm_name = subst(xpm_name, ' ', '_');
356
357                 // This way we can have "math-delim { }" on the toolbar.
358                 xpm_name = subst(xpm_name, "(", "lparen");
359                 xpm_name = subst(xpm_name, ")", "rparen");
360                 xpm_name = subst(xpm_name, "[", "lbracket");
361                 xpm_name = subst(xpm_name, "]", "rbracket");
362                 xpm_name = subst(xpm_name, "{", "lbrace");
363                 xpm_name = subst(xpm_name, "}", "rbrace");
364                 xpm_name = subst(xpm_name, "|", "bars");
365         }
366
367         lyxerr[Debug::GUI] << "find_xpm(" << name << ")\n"
368                            << "Looking for math XPM called \""
369                            << xpm_name << '"' << std::endl;
370
371         return LibFileSearch("images/math/", xpm_name, "xpm");
372 }