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