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: (c) 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.
17 #include FORMS_H_LOCATION
21 #include "lyx_gui_misc.h"
22 #include "math_panel.h"
23 #include "symbol_def.h"
38 #include "equation.xpm"
40 static LyXFunc *lyxfunc=0;
42 //static FD_panel* symb_form=0;
51 '(', ')', LM_lceil, LM_rceil, LM_uparrow, LM_Uparrow,
52 '[', ']', LM_lfloor, LM_rfloor, LM_updownarrow, LM_Updownarrow,
53 '{', '}', '/', LM_backslash, LM_downarrow, LM_Downarrow,
54 LM_langle, LM_rangle, '|', LM_Vert, '.', 0
57 static char const *deco_code[] = {
58 "widehat", "widetilde", "overbrace", "overleftarrow", "overrightarrow",
59 "overline","underbrace", "underline"
63 static char const *func_code[] = {
64 "arccos", "arcsin", "arctan", "arg", "bmod",
65 "cos", "cosh", "cot", "coth", "csc", "deg",
66 "det", "dim", "exp", "gcd", "hom", "inf", "ker",
67 "lg", "lim", "liminf", "limsup", "ln", "log",
68 "max", "min", "sec", "sin", "sinh", "sup",
72 static char h_align_str[80] = "c";
74 /* callbacks for form panel */
75 void button_cb(FL_OBJECT *ob, long data)
77 extern void free_symbols_form();
86 BitmapMenu *menu = (BitmapMenu *)ob->u_vdata;
91 lyxfunc->Dispatch(LFUN_INSERT_MATH, "frac");
94 lyxfunc->Dispatch(LFUN_INSERT_MATH, "sqrt");
97 fl_show_form(fd_delim->delim,FL_PLACE_MOUSE,FL_FULLBORDER, _("Delimiter"));
98 fl_set_form_atclose(fd_delim->delim, CancelCloseBoxCB, 0);
101 fl_show_form(fd_deco->deco,FL_PLACE_MOUSE,FL_FULLBORDER,_("Decoration"));
102 fl_set_form_atclose(fd_deco->deco, CancelCloseBoxCB, 0);
105 fl_show_form(fd_space->space,FL_PLACE_MOUSE,FL_FULLBORDER,_("Spacing"));
106 fl_set_form_atclose(fd_space->space, CancelCloseBoxCB, 0);
109 fl_show_form(fd_matrix->matrix,FL_PLACE_MOUSE,FL_FULLBORDER,_("Matrix"));
110 fl_set_form_atclose(fd_matrix->matrix, CancelCloseBoxCB, 0);
113 lyxfunc->Dispatch(LFUN_MATH_DISPLAY);
117 int i = fl_get_browser(fd_panel->func_browse) - 1;
118 lyxfunc->Dispatch(LFUN_INSERT_MATH, func_code[i]);
128 /* callbacks for form delim */
129 void delim_cb(FL_OBJECT *, long data)
131 int left=fd_delim->left->u_ldata, right=fd_delim->right->u_ldata;
132 int side=(fl_get_button(fd_delim->right)!=0);
140 sprintf(s, "%d %d", delim_code[left], delim_code[right]);
141 lyxfunc->Dispatch(LFUN_MATH_DELIM, s);
142 if (data==MM_APPLY) break;
144 case MM_CLOSE: fl_hide_form(fd_delim->delim); break;
147 int i = fl_get_bmtable(fd_delim->menu);
150 if (side || (fl_get_bmtable_numb(fd_delim->menu)!=FL_LEFT_MOUSE))
152 if (side || (fl_get_bmtable_numb(fd_delim->menu)!= 1))
159 p1 = fl_get_pixmap_pixmap(fd_delim->pix, &p1, &p2);
160 fl_draw_bmtable_item(fd_delim->menu,left,p1,0,0);
161 fl_draw_bmtable_item(fd_delim->menu,right,p1,16,0);
162 fl_redraw_object(fd_delim->pix);
164 fd_delim->left->u_ldata = left;
165 fd_delim->right->u_ldata = right;
174 /* callbacks for form matrix */
175 void matrix_cb(FL_OBJECT *, long data)
178 static char v_align_c[] = "tcb";
185 char c = v_align_c[fl_get_choice(fd_matrix->valign)-1];
186 char const *sh = fl_get_input(fd_matrix->halign);
187 nx = (int)(fl_get_slider_value(fd_matrix->columns)+0.5);
188 ny = (int)(fl_get_slider_value(fd_matrix->rows)+0.5);
189 sprintf(s, "%d %d %c%s", nx, ny, c, sh);
190 if (data==MM_OK) fl_hide_form(fd_matrix->matrix);
191 lyxfunc->Dispatch(LFUN_INSERT_MATRIX, s);
194 case MM_CLOSE: fl_hide_form(fd_matrix->matrix); break;
197 nx = (int)(fl_get_slider_value(fd_matrix->columns)+0.5);
198 for (int i=0; i<nx; i++) h_align_str[i] = 'c';
199 //memset(h_align_str, 'c', nx);
200 h_align_str[nx] = '\0';
201 // fl_freeze_form(fd_form_main->form_main);
202 // fl_addto_form(fd_form_main->form_main);
204 fl_set_input(fd_matrix->halign, h_align_str);
205 fl_redraw_object(fd_matrix->halign);
211 /* callbacks for form deco */
212 void deco_cb(FL_OBJECT *, long data)
218 int i = fl_get_bmtable(fd_deco->menu);
219 lyxfunc->Dispatch(LFUN_INSERT_MATH, deco_code[i]);
220 if (data==MM_APPLY) break;
222 case MM_CLOSE: fl_hide_form(fd_deco->deco); break;
226 /* callbacks for form space */
227 void space_cb(FL_OBJECT *, long data)
230 extern char *latex_mathspace[];
232 if (data>=0 && data<6)
240 lyxfunc->Dispatch(LFUN_INSERT_MATH, latex_mathspace[sp]);
241 if (data==MM_APPLY) break;
243 case MM_CLOSE: fl_hide_form(fd_space->space); break;
247 int align_filter(FL_OBJECT *, char const *, char const *cur, int c)
249 int n = (int)(fl_get_slider_value(fd_matrix->columns)+0.5) - strlen(cur);
250 return ((c=='c'||c=='l'||c=='r') && n>=0) ? FL_VALID: FL_INVALID;
253 char** mathed_get_pixmap_from_icon(int d)
256 case MM_FRAC: return frac;
257 case MM_SQRT: return sqrt;
258 case MM_DELIM: return delim;
259 case MM_MATRIX: return matrix;
260 case MM_EQU: return equation;
261 case MM_DECO: return deco;
262 case MM_SPACE: return space_xpm;
267 FD_panel *create_math_panel( )
269 fd_panel = create_form_panel();
270 fd_delim = create_form_delim();
271 fd_deco = create_form_deco();
272 fd_space = create_form_space();
273 fd_matrix = create_form_matrix();
275 /* fill-in form initialization code */
276 fl_set_button(fd_delim->left, 1);
277 fl_set_pixmap_data(fd_delim->pix, delim0);
278 fl_set_bmtable_data(fd_delim->menu,6,4,delim_width,delim_height,
280 fl_set_bmtable_maxitems(fd_delim->menu, 23);
282 fl_set_pixmap_data(fd_panel->sqrt, sqrt);
283 fl_set_pixmap_data(fd_panel->frac, frac);
284 fl_set_pixmap_data(fd_panel->delim, delim);
285 fl_set_pixmap_data(fd_panel->deco, deco);
286 fl_set_pixmap_data(fd_panel->space, space_xpm);
287 fl_set_pixmap_data(fd_panel->matrix, matrix);
288 fl_set_pixmap_data(fd_panel->equation, equation);
290 for (int i=0; i<32; i++) {
291 fl_add_browser_line(fd_panel->func_browse, func_code[i]);
294 fl_addto_choice(fd_matrix->valign, _("Top | Center | Bottom"));
295 fl_set_choice(fd_matrix->valign, 2);
296 fl_set_input(fd_matrix->halign, h_align_str);
297 fl_set_input_filter(fd_matrix->halign, align_filter);
299 fl_set_bmtable_data(fd_deco->menu,3,3,deco_width,deco_height,
301 fl_set_bmtable_maxitems(fd_deco->menu, 8);
303 fd_delim->left->u_ldata = 0;
304 fd_delim->right->u_ldata = 1;
309 extern BitmapMenu* sym_menu;
310 extern void create_symbol_menues(FD_panel *);
312 void free_symbols_form()
315 fl_hide_form(fd_panel->panel);
316 fl_free_form(fd_panel->panel);
323 int AtClose_symbols_form(FL_FORM *, void *)
330 void show_symbols_form(LyXFunc *lf)
334 fd_panel = create_math_panel();
335 fl_register_raw_callback(fd_panel->panel,
336 ButtonPressMask|KeyPressMask, peek_event);
337 create_symbol_menues(fd_panel);
338 fl_set_form_atclose(fd_panel->panel, AtClose_symbols_form, 0);
340 if (fd_panel->panel->visible) {
341 fl_raise_form(fd_panel->panel);
343 fl_show_form(fd_panel->panel, FL_PLACE_MOUSE | FL_FREE_SIZE,
344 FL_FULLBORDER, _("Math Panel"));