3 * Copyright 2001 the LyX Team
4 * Read the file COPYING
6 * \author Alejandro Aguilar Sierra
13 #include XPM_H_LOCATION
16 #pragma implementation
19 #include "support/lstrings.h"
20 #include "support/LAssert.h"
23 #include "MathsSymbols.h"
24 #include "FormMaths.h"
30 /* Latex code for those bitmaps */
32 char const * latex_greek[] = {
33 "Gamma", "Delta", "Theta", "Lambda", "Xi", "Pi",
34 "Sigma", "Upsilon", "Phi", "Psi", "Omega",
35 "alpha", "beta", "gamma", "delta", "epsilon", "varepsilon", "zeta",
36 "eta", "theta", "vartheta", "iota", "kappa", "lambda", "mu",
37 "nu", "xi", "pi", "varpi", "rho", "sigma", "varsigma",
38 "tau", "upsilon", "phi", "varphi", "chi", "psi", "omega", ""
42 char const * latex_brel[] = {
43 "leq", "geq", "equiv", "models",
44 "prec", "succ", "sim", "perp",
45 "preceq", "succeq", "simeq", "mid",
46 "ll", "gg", "asymp", "parallel",
47 "subset", "supset", "approx", "smile",
48 "subseteq", "supseteq", "cong", "frown",
49 "sqsubseteq", "sqsupseteq", "doteq", "neq",
50 "in", "ni", "propto", "notin",
51 "vdash", "dashv", "bowtie", ""
55 char const * latex_arrow[] = {
56 "downarrow", "leftarrow", "Downarrow", "Leftarrow",
57 "hookleftarrow", "rightarrow", "uparrow", "Rightarrow", "Uparrow",
58 "hookrightarrow", "updownarrow", "Leftrightarrow", "leftharpoonup",
59 "rightharpoonup", "rightleftharpoons", "leftrightarrow", "Updownarrow",
60 "leftharpoondown", "rightharpoondown", "mapsto",
61 "Longleftarrow", "Longrightarrow", "Longleftrightarrow",
62 "longleftrightarrow", "longleftarrow", "longrightarrow", "longmapsto",
63 "nwarrow", "nearrow", "swarrow", "searrow", "",
66 char const * latex_varsz[] = {
68 "prod", "coprod", "bigsqcup",
69 "bigotimes", "bigodot", "bigoplus",
70 "bigcap", "bigcup", "biguplus",
71 "bigvee", "bigwedge", ""
75 char const * latex_bop[] = {
76 "pm", "cap", "diamond", "oplus",
77 "mp", "cup", "bigtriangleup", "ominus",
78 "times", "uplus", "bigtriangledown", "otimes",
79 "div", "sqcap", "triangleright", "oslash",
80 "cdot", "sqcup", "triangleleft", "odot",
81 "star", "vee", "amalg", "bigcirc",
82 "setminus", "wedge", "dagger", "circ",
83 "bullet", "wr", "ddagger", ""
87 char const * latex_misc[] = {
88 "nabla", "partial", "infty", "prime", "ell",
89 "emptyset", "exists", "forall", "imath", "jmath",
90 "Re", "Im", "aleph", "wp", "hbar",
91 "angle", "top", "bot", "Vert", "neg",
92 "flat", "natural", "sharp", "surd", "triangle",
93 "diamondsuit", "heartsuit", "clubsuit", "spadesuit", ""
97 char const * latex_dots[] = {
98 "ldots", "cdots", "vdots", "ddots"
101 BitmapMenu * BitmapMenu::active = 0;
103 extern "C" void C_MathsSymbolsBitmapCB(FL_OBJECT * ob, long data)
105 BitmapMenu * menu = static_cast<BitmapMenu*>(ob->u_vdata);
106 int const i = menu->GetIndex(ob);
109 lyxerr[Debug::GUI] << "Bitmap callback value " << data << endl;
116 str = latex_greek[i];
119 str = latex_arrow[i];
128 str = latex_varsz[i];
135 str = latex_dots[i - 29];
142 menu->form_->insertSymbol(str);
147 extern "C" int C_MathsSymbolsPeekCB(FL_FORM *, void * xev)
149 if (!BitmapMenu::active)
152 if (static_cast<XEvent *>(xev)->type == ButtonPress) {
153 BitmapMenu::active->hide();
157 if (static_cast<XEvent *>(xev)->type != KeyPress)
164 XLookupString(&static_cast<XEvent *>(xev)->xkey, &c[0], 5, &keysym, 0);
165 if (keysym == XK_Left)
166 BitmapMenu::active->prev();
167 else if (keysym == XK_Right)
168 BitmapMenu::active->next();
170 BitmapMenu::active->hide();
176 BitmapMenu::BitmapMenu(FormMaths * f, int n, FL_OBJECT * bt, BitmapMenu * prevx)
177 : current_(0), bitmaps_(n), form_(f)
181 ww = 2 * FL_abs(FL_BOUND_WIDTH);
185 button->u_vdata = this;
193 BitmapMenu::~BitmapMenu()
202 void BitmapMenu::hide()
205 fl_set_button(button, 0);
210 void BitmapMenu::show()
216 fl_set_button(button, 1);
217 fl_show_form(form, FL_PLACE_MOUSE, FL_NOBORDER, "");
222 BitmapMenu::AddBitmap(int id, int nx, int ny, int bw, int bh,
223 unsigned char const * data, bool vert)
225 if (current_ >= bitmaps_.size())
228 int wx = bw + ww / 2;
229 int wy = bh + ww / 2;
232 FL_OBJECT * obj = fl_create_bmtable(1, x, y, wx, wy, "");
233 fl_set_object_callback(obj, C_MathsSymbolsBitmapCB, id);
234 fl_set_object_lcol(obj, FL_BLUE);
235 fl_set_object_boxtype(obj, FL_UP_BOX);
236 fl_set_bmtable_data(obj, nx, ny, bw, bh, data);
240 w = max(x + wx + ww, w);
244 h = max(y + wy + ww, h);
246 bitmaps_[current_++] = obj;
251 void BitmapMenu::create()
253 Assert(current_ >= bitmaps_.size());
255 form = fl_bgn_form(FL_UP_BOX, w, h);
257 for (current_ = 0; current_ < bitmaps_.size(); ++current_) {
258 fl_add_object(form, bitmaps_[current_]);
259 bitmaps_[current_]->u_vdata = this;
264 fl_register_raw_callback(form, KeyPressMask, C_MathsSymbolsPeekCB);
268 int BitmapMenu::GetIndex(FL_OBJECT * ob)
270 if (active == this) {
272 for (current_ = 0; current_ < bitmaps_.size(); ++current_) {
273 if (bitmaps_[current_] == ob)
274 return k + fl_get_bmtable(ob);
275 k += fl_get_bmtable_maxitems(bitmaps_[current_]);
281 /* the below is stuff used by Toolbar to make icons. It should be elsewhere
282 * but depends on the name arrays above ...
286 #include "arrows.xbm"
292 #include "mathed/math_parser.h"
300 #include "matrix.xpm"
301 #include "equation.xpm"
303 static char const ** mathed_get_pixmap_from_icon(int d)
306 case MM_FRAC: return frac;
307 case MM_SQRT: return sqrt_xpm;
308 case MM_DELIM: return delim;
309 case MM_MATRIX: return matrix;
310 case MM_EQU: return equation;
311 case MM_DECO: return deco;
312 case MM_SPACE: return space_xpm;
317 static char const ** pixmapFromBitmapData(char const * s, int wx, int hx)
319 char const ** data = 0;
325 char const ** latex_str = 0;
327 case 0: latex_str = latex_greek; break;
328 case 1: latex_str = latex_bop; break;
329 case 2: latex_str = latex_brel; break;
330 case 3: latex_str = latex_arrow; break;
331 case 4: latex_str = latex_varsz; break;
332 case 5: latex_str = latex_misc; break;
335 for (int k = 0; latex_str[k][0] > ' '; ++k) {
336 if (compare(latex_str[k], s) == 0) {
343 if (i < 6 && id >= 0) {
344 unsigned char const * bdata = 0;
350 lyxerr[Debug::MATHED] << "Imando " << i << ", " << id << endl;
389 } else if (id > 28) {
423 XImage * xima = XCreateImage(fl_get_display(), 0, 1, XYBitmap, 0,
424 const_cast<char*>(reinterpret_cast<char const *>(bdata)), w, h, 8, 0);
425 xima->byte_order = LSBFirst;
426 xima->bitmap_bit_order = LSBFirst;
427 int x = (id % dw) * ww;
428 int y = (id/dw) * hh;
429 if (ww > wx) ww = wx;
430 if (hh > hx) hh = hx;
431 XImage * sbima = XSubImage(xima, x, y, ww, hh);
432 XpmCreateDataFromImage(fl_get_display(), const_cast<char***>(&data), sbima, sbima, 0);
434 // Dirty hack to get blue symbols quickly
435 char * sx = const_cast<char*>(strstr(data[2], "FFFFFFFF"));
437 for (int k = 0; k < 8; ++k) sx[k] = '0';
440 // XDestroyImage(xima);
447 char const ** get_pixmap_from_symbol(char const * arg, int wx, int hx)
449 char const ** data = 0;
450 latexkeys const * l = in_word_set (arg, strlen(arg));
456 data = mathed_get_pixmap_from_icon(MM_FRAC);
459 data = mathed_get_pixmap_from_icon(MM_SQRT);
463 // I have to use directly the bitmap data since the
464 // bitmap tables are not yet created when this
465 // function is called.
466 data = pixmapFromBitmapData(arg, wx, hx);