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