3 * Copyright 2001 The LyX Team.
4 * See the file COPYING.
6 * \author Alejandro Aguilar Sierra
7 * \author Pablo De Napoli, pdenapo@dm.uba.ar
8 * \author John Levon, moz@compsoc.man.ac.uk
14 #pragma implementation
17 #include FORMS_H_LOCATION
19 #include "support/LAssert.h"
20 #include "FormMaths.h"
21 #include "form_maths.h"
22 #include "MathsSymbols.h"
29 #include "mathed/symbol_def.h"
39 #include "equation.xpm"
51 static int const delim_rversion[] = {
52 1,1,3,3,4,5,7,7,9,9,10,11,
53 13,13,14,15,16,17,19,19,20,21,22,23 };
55 static char const * function_names[] = {
56 "arccos", "arcsin", "arctan", "arg", "bmod",
57 "cos", "cosh", "cot", "coth", "csc", "deg",
58 "det", "dim", "exp", "gcd", "hom", "inf", "ker",
59 "lg", "lim", "liminf", "limsup", "ln", "log",
60 "max", "min", "sec", "sin", "sinh", "sup",
64 static int const nr_function_names = sizeof(function_names) / sizeof(char const *);
66 static char const * decoration_names[] = {
67 "widehat", "widetilde", "overbrace", "overleftarrow", "overrightarrow",
68 "overline", "underbrace", "underline"
71 static int const nr_decoration_names = sizeof(decoration_names) / sizeof(char const *);
73 static int delim_values[] = {
74 '(', ')', LM_lceil, LM_rceil, LM_uparrow, LM_Uparrow,
75 '[', ']', LM_lfloor, LM_rfloor, LM_updownarrow, LM_Updownarrow,
76 '{', '}', '/', LM_backslash, LM_downarrow, LM_Downarrow,
77 LM_langle, LM_rangle, '|', LM_Vert, '.', 0
80 extern "C" int C_FormMathsWMHideCB(FL_FORM * ob, void *)
87 extern "C" void C_FormMathsButtonCB(FL_OBJECT * ob, long data)
89 FormMaths * form = static_cast<FormMaths*>(ob->form->u_vdata);
90 MathsCallbackValues val = static_cast<MathsCallbackValues>(data);
92 lyxerr[Debug::GUI] << "Maths button CB val " << val << endl;
101 form->openBitmapMenu(val);
105 form->insertSymbol("frac");
108 form->insertSymbol("sqrt");
115 form->openSubDialog(val);
123 form->insertFunction();
136 extern "C" void C_FormMathsDelimCB(FL_OBJECT * ob, long data)
138 FormMaths * form = static_cast<FormMaths*>(ob->form->u_vdata);
139 MathsCallbackValues val = static_cast<MathsCallbackValues>(data);
141 lyxerr[Debug::GUI] << "Maths delim CB val " << val << endl;
143 int left = form->delim_->radio_left->u_ldata;
144 int right= form->delim_->radio_right->u_ldata;
145 int const side = (fl_get_button(form->delim_->radio_right) != 0);
146 std::ostringstream ost;
148 ost << delim_values[left] << ' ' << delim_values[right];
152 form->insertDelim(ost.str());
154 fl_hide_form(form->delim_->form);
158 form->insertDelim(ost.str());
163 int const i = fl_get_bmtable(form->delim_->bmtable_delim);
164 int const button = fl_get_bmtable_numb(form->delim_->bmtable_delim);
165 bool const both = (button == FL_MIDDLE_MOUSE);
168 if (side || (button == FL_RIGHT_MOUSE))
173 right = delim_rversion[i];
179 p1 = fl_get_pixmap_pixmap(form->delim_->button_delim_pix, &p1, &p2);
180 fl_draw_bmtable_item(form->delim_->bmtable_delim, left, p1, 0, 0);
181 fl_draw_bmtable_item(form->delim_->bmtable_delim, right, p1, 16, 0);
182 fl_redraw_object(form->delim_->button_delim_pix);
184 form->delim_->radio_left->u_ldata = left;
185 form->delim_->radio_right->u_ldata = right;
188 /* left/right - ignore */
200 extern "C" int align_filter(FL_OBJECT * ob, char const *, char const * cur, int c)
202 FormMaths * form = static_cast<FormMaths*>(ob->u_vdata);
204 int n = int(fl_get_slider_value(form->matrix_->slider_matrix_columns)+0.5) - strlen(cur);
208 if (c == 'c' || c == 'l' || c == 'r')
215 static char h_align_str[80] = "c";
216 static char v_align_c[] = "tcb";
218 extern "C" void C_FormMathsMatrixCB(FL_OBJECT * ob, long data)
221 FormMaths * form = static_cast<FormMaths*>(ob->form->u_vdata);
222 MathsCallbackValues val = static_cast<MathsCallbackValues>(data);
224 lyxerr[Debug::GUI] << "Maths matrix CB val " << val << endl;
228 form->insertMatrix();
230 fl_hide_form(form->matrix_->form);
234 form->insertMatrix();
237 /* rows slider etc.: ignore */
241 /* the "columns" slider */
243 int const nx = int(fl_get_slider_value(form->matrix_->slider_matrix_columns)+0.5);
244 for (int i = 0; i < nx; ++i)
245 h_align_str[i] = 'c';
247 h_align_str[nx] = '\0';
249 fl_set_input(form->matrix_->input_matrix_halign, h_align_str);
250 fl_redraw_object(form->matrix_->input_matrix_halign);
260 extern "C" void C_FormMathsDecoCB(FL_OBJECT * ob, long data)
262 FormMaths * form = static_cast<FormMaths*>(ob->form->u_vdata);
263 MathsCallbackValues val = static_cast<MathsCallbackValues>(data);
265 lyxerr[Debug::GUI] << "Maths deco CB val " << val << endl;
267 int const i = fl_get_bmtable(form->deco_->bmtable_deco);
269 if (i >= nr_decoration_names)
272 string const deco_str = decoration_names[i];
276 form->insertSymbol(deco_str);
278 fl_hide_form(form->deco_->form);
282 form->insertSymbol(deco_str);
292 extern "C" void C_FormMathsSpaceCB(FL_OBJECT * ob, long data)
294 extern char * latex_mathspace[];
295 static short sp = -1;
297 if (data >= 0 && data < 6) {
302 FormMaths * form = static_cast<FormMaths*>(ob->form->u_vdata);
303 MathsCallbackValues val = static_cast<MathsCallbackValues>(data);
305 lyxerr[Debug::GUI] << "Maths space CB val " << val << endl;
310 form->insertSymbol(latex_mathspace[sp]);
312 fl_hide_form(form->space_->form);
317 form->insertSymbol(latex_mathspace[sp]);
327 FormMaths::FormMaths(LyXView * lv, Dialogs * d)
328 : FormBaseBD(lv, d, _("Maths Symbols"))
330 d->showMathPanel.connect(slot(this, &FormMaths::show));
334 FL_FORM * FormMaths::form() const
337 return dialog_->form;
342 extern "C" int C_MathsSymbolsPeekCB(FL_FORM *, void *);
344 void FormMaths::build()
346 dialog_.reset(build_panel());
347 delim_.reset(build_delim());
348 matrix_.reset(build_matrix());
349 deco_.reset(build_deco());
350 space_.reset(build_space());
352 fl_set_form_atclose(delim_->form, C_FormMathsWMHideCB, delim_.get());
353 fl_set_form_atclose(matrix_->form, C_FormMathsWMHideCB, matrix_.get());
354 fl_set_form_atclose(deco_->form, C_FormMathsWMHideCB, deco_.get());
355 fl_set_form_atclose(space_->form, C_FormMathsWMHideCB, space_.get());
357 // work around dumb xforms sizing bug
361 fl_set_button(space_->radio_space_thin, 1);
362 fl_set_button(delim_->radio_left, 1);
363 fl_set_pixmap_data(delim_->button_delim_pix, const_cast<char**>(delim0));
364 delim_->radio_left->u_ldata = 0;
365 delim_->radio_right->u_ldata = 1;
367 fl_set_bmtable_data(delim_->bmtable_delim, 6, 4, delim_width, delim_height, delim_bits);
368 fl_set_bmtable_maxitems(delim_->bmtable_delim, 23);
370 for (int i = 0; i < nr_function_names; ++i)
371 fl_add_browser_line(dialog_->browser_functions, function_names[i]);
373 fl_set_pixmap_data(dialog_->button_sqrt, const_cast<char**>(sqrt_xpm));
374 fl_set_pixmap_data(dialog_->button_frac, const_cast<char**>(frac));
375 fl_set_pixmap_data(dialog_->button_delim, const_cast<char**>(delim));
376 fl_set_pixmap_data(dialog_->button_deco, const_cast<char**>(deco));
377 fl_set_pixmap_data(dialog_->button_space, const_cast<char**>(space_xpm));
378 fl_set_pixmap_data(dialog_->button_matrix, const_cast<char**>(matrix));
379 fl_set_pixmap_data(dialog_->button_equation, const_cast<char**>(equation));
381 fl_addto_choice(matrix_->choice_matrix_valign, _("Top | Center | Bottom"));
382 fl_set_choice(matrix_->choice_matrix_valign, 2);
383 fl_set_input(matrix_->input_matrix_halign, h_align_str);
384 matrix_->input_matrix_halign->u_vdata = this;
385 fl_set_input_filter(matrix_->input_matrix_halign, align_filter);
387 fl_set_bmtable_data(deco_->bmtable_deco, 3, 3, deco_width, deco_height, deco_bits);
388 fl_set_bmtable_maxitems(deco_->bmtable_deco, 8);
390 build_symbol_menus();
392 // to close any bitmap menus on interacting with the main form
393 fl_register_raw_callback(dialog_->form, KeyPressMask|ButtonPressMask, C_MathsSymbolsPeekCB);
395 bc_.setCancel(dialog_->button_close);
400 void FormMaths::build_symbol_menus()
404 greek_.reset(new BitmapMenu(this, 2, dialog_->button_greek));
405 obj = greek_->AddBitmap(MM_GREEK, 6, 2,
406 Greek_width, Greek_height, Greek_bits);
407 fl_set_bmtable_maxitems(obj, 11);
408 obj = greek_->AddBitmap(MM_GREEK, 7, 4,
409 greek_width, greek_height, greek_bits);
412 boperator_.reset(new BitmapMenu(this, 1, dialog_->button_boperator,
414 obj = boperator_->AddBitmap(MM_BOP, 4, 8,
415 bop_width, bop_height, bop_bits);
416 fl_set_bmtable_maxitems(obj, 31);
417 boperator_->create();
419 brelats_.reset(new BitmapMenu(this, 1, dialog_->button_brelats,
421 obj = brelats_->AddBitmap(MM_BRELATS, 4, 9,
422 brel_width, brel_height, brel_bits);
423 fl_set_bmtable_maxitems(obj, 35);
426 arrow_.reset(new BitmapMenu(this, 3, dialog_->button_arrow,
428 obj = arrow_->AddBitmap(MM_ARROW, 5, 4,
429 arrow_width, arrow_height, arrow_bits);
430 obj = arrow_->AddBitmap(MM_ARROW, 2, 4,
431 larrow_width, larrow_height, larrow_bits,
433 fl_set_bmtable_maxitems(obj, 7);
434 obj = arrow_->AddBitmap(MM_ARROW, 2, 2,
435 darrow_width, darrow_height, darrow_bits);
438 varsize_.reset(new BitmapMenu(this, 1, dialog_->button_varsize,
440 obj = varsize_->AddBitmap(MM_VARSIZE, 3, 5,
441 varsz_width, varsz_height, varsz_bits);
442 fl_set_bmtable_maxitems(obj, 14);
445 misc_.reset(new BitmapMenu(this, 2, dialog_->button_misc,
447 obj = misc_->AddBitmap(MM_MISC, 5, 6,
448 misc_width, misc_height, misc_bits);
449 fl_set_bmtable_maxitems(obj, 29);
450 obj = misc_->AddBitmap(MM_DOTS, 4, 1,
451 dots_width, dots_height, dots_bits);
456 void FormMaths::insertMatrix() const
458 char const c = v_align_c[fl_get_choice(matrix_->choice_matrix_valign) - 1];
459 char const * sh = fl_get_input(matrix_->input_matrix_halign);
460 int const nx = int(fl_get_slider_value(matrix_->slider_matrix_columns) + 0.5);
461 int const ny = int(fl_get_slider_value(matrix_->slider_matrix_rows) + 0.5);
463 std::ostringstream ost;
464 ost << nx << ' ' << ny << ' ' << c << sh;
466 lv_->getLyXFunc()->Dispatch(LFUN_INSERT_MATRIX, ost.str().c_str());
470 void FormMaths::insertDelim(string const & delim) const
472 lv_->getLyXFunc()->Dispatch(LFUN_MATH_DELIM, delim);
476 void FormMaths::openBitmapMenu(MathsCallbackValues val) const
503 void FormMaths::insertSymbol(string const & sym) const
505 lv_->getLyXFunc()->Dispatch(LFUN_INSERT_MATH, sym);
509 void FormMaths::mathDisplay() const
511 lv_->getLyXFunc()->Dispatch(LFUN_MATH_DISPLAY);
515 void FormMaths::openSubDialog(MathsCallbackValues val) const
523 title = "Delimiters";
526 form = matrix_->form;
531 title = "Maths Decorations";
535 title = "Maths Spacing";
543 XMapWindow(fl_get_display(), form->window);
545 fl_show_form(form, FL_PLACE_MOUSE | FL_FREE_SIZE, 0, title.c_str());
549 void FormMaths::insertFunction() const
551 int const i = fl_get_browser(dialog_->browser_functions) - 1;
552 insertSymbol(function_names[i]);