3 * Purpose: Mathed GUI for lyx
4 * Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
5 * Created: March 28, 1996
7 * Dependencies: Xlib, Xpm, XForms, Lyx
9 * Copyright: 1996, Alejandro Aguilar Sierra
11 * You are free to use and modify it under the terms of
12 * the GNU General Public Licence version 2 or later.
19 #include FORMS_H_LOCATION
21 #include "lyx_gui_misc.h"
22 #include "math_panel.h"
23 #include "symbol_def.h"
38 #include "equation.xpm"
41 static LyXFunc * lyxfunc = 0;
43 //static FD_panel* symb_form= 0;
49 FD_matrix * fd_matrix;
52 '(', ')', LM_lceil, LM_rceil, LM_uparrow, LM_Uparrow,
53 '[', ']', LM_lfloor, LM_rfloor, LM_updownarrow, LM_Updownarrow,
54 '{', '}', '/', LM_backslash, LM_downarrow, LM_Downarrow,
55 LM_langle, LM_rangle, '|', LM_Vert, '.', 0
58 // indexes to get the left and right versions of each delimiter
59 // Contributed by Pablo De Napoli (pdenapo@dm.uba.ar)
60 int delim_lversion[] = { 0,0,2,2,4,5,
65 int delim_rversion[] = { 1,1,3,3,4,5,
71 static char const * deco_code[] = {
72 "widehat", "widetilde", "overbrace", "overleftarrow", "overrightarrow",
73 "overline", "underbrace", "underline"
77 static char const * func_code[] = {
78 "arccos", "arcsin", "arctan", "arg", "bmod",
79 "cos", "cosh", "cot", "coth", "csc", "deg",
80 "det", "dim", "exp", "gcd", "hom", "inf", "ker",
81 "lg", "lim", "liminf", "limsup", "ln", "log",
82 "max", "min", "sec", "sin", "sinh", "sup",
86 static char h_align_str[80] = "c";
88 /* callbacks for form panel */
89 void button_cb(FL_OBJECT * ob, long data)
91 extern void free_symbols_form();
100 BitmapMenu * menu = static_cast<BitmapMenu *>(ob->u_vdata);
105 lyxfunc->Dispatch(LFUN_INSERT_MATH, "frac");
108 lyxfunc->Dispatch(LFUN_INSERT_MATH, "sqrt");
111 fl_show_form(fd_delim->delim,
112 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT,
114 fl_set_form_atclose(fd_delim->delim, CancelCloseBoxCB, 0);
117 fl_show_form(fd_deco->deco,
118 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT,
120 fl_set_form_atclose(fd_deco->deco, CancelCloseBoxCB, 0);
123 fl_show_form(fd_space->space,
124 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT,
126 fl_set_form_atclose(fd_space->space, CancelCloseBoxCB, 0);
129 fl_show_form(fd_matrix->matrix,
130 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT,
132 fl_set_form_atclose(fd_matrix->matrix, CancelCloseBoxCB, 0);
135 lyxfunc->Dispatch(LFUN_MATH_DISPLAY);
139 int i = fl_get_browser(fd_panel->func_browse) - 1;
140 lyxfunc->Dispatch(LFUN_INSERT_MATH, func_code[i]);
150 /* callbacks for form delim */
151 void delim_cb(FL_OBJECT *, long data)
153 int left = fd_delim->left->u_ldata;
154 int right= fd_delim->right->u_ldata;
155 int side = (fl_get_button(fd_delim->right) != 0);
161 std::ostringstream ost;
162 ost << delim_code[left] << ' ' << delim_code[right];
163 lyxfunc->Dispatch(LFUN_MATH_DELIM, ost.str().c_str());
164 if (data == MM_APPLY) break;
166 case MM_CLOSE: fl_hide_form(fd_delim->delim); break;
169 int i = fl_get_bmtable(fd_delim->menu);
170 int button = fl_get_bmtable_numb(fd_delim->menu);
171 bool both = (button==FL_MIDDLE_MOUSE);
175 if (side || (button== FL_RIGHT_MOUSE)) {
180 right = delim_rversion[i];
184 p1 = fl_get_pixmap_pixmap(fd_delim->pix, &p1, &p2);
185 fl_draw_bmtable_item(fd_delim->menu, left, p1, 0, 0);
186 fl_draw_bmtable_item(fd_delim->menu, right, p1, 16, 0);
187 fl_redraw_object(fd_delim->pix);
189 fd_delim->left->u_ldata = left;
190 fd_delim->right->u_ldata = right;
199 /* callbacks for form matrix */
200 void matrix_cb(FL_OBJECT *, long data)
202 static char v_align_c[] = "tcb";
208 char c = v_align_c[fl_get_choice(fd_matrix->valign) - 1];
209 char const * sh = fl_get_input(fd_matrix->halign);
210 int nx = int(fl_get_slider_value(fd_matrix->columns) + 0.5);
211 int ny = int(fl_get_slider_value(fd_matrix->rows) + 0.5);
212 if (data == MM_OK) fl_hide_form(fd_matrix->matrix);
213 std::ostringstream ost;
214 ost << nx << ' ' << ny << ' ' << c << sh;
215 lyxfunc->Dispatch(LFUN_INSERT_MATRIX, ost.str().c_str());
218 case MM_CLOSE: fl_hide_form(fd_matrix->matrix); break;
221 int nx = int(fl_get_slider_value(fd_matrix->columns)+0.5);
222 for (int i = 0; i < nx; ++i) h_align_str[i] = 'c';
223 //memset(h_align_str, 'c', nx);
224 h_align_str[nx] = '\0';
225 // fl_freeze_form(fd_form_main->form_main);
226 // fl_addto_form(fd_form_main->form_main);
228 fl_set_input(fd_matrix->halign, h_align_str);
229 fl_redraw_object(fd_matrix->halign);
235 /* callbacks for form deco */
236 void deco_cb(FL_OBJECT *, long data)
242 int const i = fl_get_bmtable(fd_deco->menu);
243 int const l = sizeof(deco_code)/sizeof(deco_code[0]);
244 // ideally the callback should not be called if the index is
245 // greater than the maxitem of the bmtable, but I do not know
246 // how to enforce that (JMarc)
248 lyxfunc->Dispatch(LFUN_INSERT_MATH, deco_code[i]);
249 if (data == MM_APPLY) break;
253 case MM_CLOSE: fl_hide_form(fd_deco->deco); break;
258 /* callbacks for form space */
259 void space_cb(FL_OBJECT *, long data)
261 static short sp = -1;
262 extern char * latex_mathspace[];
264 if (data >= 0 && data < 6)
272 lyxfunc->Dispatch(LFUN_INSERT_MATH, latex_mathspace[sp]);
273 if (data == MM_APPLY) break;
275 case MM_CLOSE: fl_hide_form(fd_space->space); break;
280 extern "C" int align_filter(FL_OBJECT *, char const *, char const * cur, int c)
282 int n = int(fl_get_slider_value(fd_matrix->columns)+0.5) - strlen(cur);
283 return ((c == 'c'||c == 'l'||c == 'r') && n>= 0) ? FL_VALID: FL_INVALID;
287 char const ** mathed_get_pixmap_from_icon(int d)
290 case MM_FRAC: return frac;
291 case MM_SQRT: return sqrt_xpm;
292 case MM_DELIM: return delim;
293 case MM_MATRIX: return matrix;
294 case MM_EQU: return equation;
295 case MM_DECO: return deco;
296 case MM_SPACE: return space_xpm;
302 FD_panel * create_math_panel( )
304 fd_panel = create_form_panel();
305 fd_delim = create_form_delim();
306 fd_deco = create_form_deco();
307 fd_space = create_form_space();
308 fd_matrix = create_form_matrix();
310 /* fill-in form initialization code */
311 fl_set_button(fd_delim->left, 1);
312 fl_set_pixmap_data(fd_delim->pix, const_cast<char**>(delim0));
313 fl_set_bmtable_data(fd_delim->menu, 6, 4, delim_width, delim_height,
315 fl_set_bmtable_maxitems(fd_delim->menu, 23);
317 fl_set_pixmap_data(fd_panel->sqrt, const_cast<char**>(sqrt_xpm));
318 fl_set_pixmap_data(fd_panel->frac, const_cast<char**>(frac));
319 fl_set_pixmap_data(fd_panel->delim, const_cast<char**>(delim));
320 fl_set_pixmap_data(fd_panel->deco, const_cast<char**>(deco));
321 fl_set_pixmap_data(fd_panel->space, const_cast<char**>(space_xpm));
322 fl_set_pixmap_data(fd_panel->matrix, const_cast<char**>(matrix));
323 fl_set_pixmap_data(fd_panel->equation, const_cast<char**>(equation));
325 for (int i = 0; i < 32; ++i) {
326 fl_add_browser_line(fd_panel->func_browse, func_code[i]);
329 fl_addto_choice(fd_matrix->valign, _("Top | Center | Bottom"));
330 fl_set_choice(fd_matrix->valign, 2);
331 fl_set_input(fd_matrix->halign, h_align_str);
332 fl_set_input_filter(fd_matrix->halign, align_filter);
334 fl_set_bmtable_data(fd_deco->menu, 3, 3, deco_width, deco_height,
336 fl_set_bmtable_maxitems(fd_deco->menu, 8);
338 fd_delim->left->u_ldata = 0;
339 fd_delim->right->u_ldata = 1;
344 extern BitmapMenu * sym_menu;
345 extern void create_symbol_menues(FD_panel *);
348 void free_symbols_form()
351 fl_hide_form(fd_panel->panel);
352 fl_free_form(fd_panel->panel);
360 extern "C" int AtClose_symbols_form(FL_FORM *, void *)
367 void show_symbols_form(LyXFunc * lf)
371 fd_panel = create_math_panel();
372 fl_register_raw_callback(fd_panel->panel,
373 ButtonPressMask|KeyPressMask, C_peek_event);
374 create_symbol_menues(fd_panel);
375 fl_set_form_atclose(fd_panel->panel, AtClose_symbols_form, 0);
377 if (fd_panel->panel->visible) {
378 fl_raise_form(fd_panel->panel);
380 fl_show_form(fd_panel->panel,
381 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT,