]> git.lyx.org Git - features.git/blob - src/frontends/xforms/FormMathsDelim.C
More header file include dependency work
[features.git] / src / frontends / xforms / FormMathsDelim.C
1 /**
2  * \file FormMathsDelim.C
3  * Copyright 2001 The LyX Team.
4  * See the file COPYING.
5  *
6  * \author Alejandro Aguilar Sierra
7  * \author Pablo De Napoli, pdenapo@dm.uba.ar
8  * \author John Levon, moz@compsoc.man.ac.uk
9  * \author Angus Leeming, a.leeming@ic.ac.uk
10  */
11
12 #include <config.h>
13
14 #ifdef __GNUG_
15 #pragma implementation
16 #endif
17
18 #include "FormMathsDelim.h"
19 #include "form_maths_delim.h"
20 #include "Dialogs.h"
21 #include "LyXView.h"
22 #include "bmtable.h"
23 #include "debug.h"
24 #include "mathed/symbol_def.h"
25 #include "support/lstrings.h"
26 #include "lyxfunc.h"
27
28 #include "delim.xbm"
29 #include "delim0.xpm"
30
31 static int const delim_rversion[] = { 
32         1,1,3,3,4,5,7,7,9,9,10,11,
33         13,13,14,15,16,17,19,19,20,21,22,23 };
34  
35 static int delim_values[] = {
36         '(', ')', LM_lceil,  LM_rceil,  LM_uparrow,  LM_Uparrow,
37         '[', ']', LM_lfloor,  LM_rfloor,  LM_updownarrow, LM_Updownarrow,
38         '{', '}',  '/', LM_backslash,  LM_downarrow,  LM_Downarrow,
39         LM_langle,  LM_rangle, '|', LM_Vert, '.', 0
40 };
41
42 using std::endl;
43
44 FormMathsDelim::FormMathsDelim(LyXView * lv, Dialogs * d, 
45                                FormMathsPanel const & p)
46         : FormMathsSub(lv, d, p, _("Maths Delimiters"))
47 {}
48
49
50 FL_FORM * FormMathsDelim::form() const
51 {
52         if (dialog_.get())
53                 return dialog_->form;
54         return 0;
55 }
56
57
58 void FormMathsDelim::build()
59 {
60         dialog_.reset(build_maths_delim());
61         
62         fl_set_button(dialog_->radio_left, 1);
63         fl_set_pixmap_data(dialog_->button_pix, const_cast<char**>(delim0));
64         dialog_->radio_left->u_ldata = 0;
65         dialog_->radio_right->u_ldata = 1;
66  
67         fl_set_bmtable_data(dialog_->bmtable, 6, 4,
68                             delim_width, delim_height, delim_bits);
69         fl_set_bmtable_maxitems(dialog_->bmtable, 23);
70
71         bc().setOK(dialog_->button_ok);
72         bc().setApply(dialog_->button_apply);
73         bc().setCancel(dialog_->button_cancel);
74
75         bc().addReadOnly(dialog_->bmtable);
76         bc().addReadOnly(dialog_->radio_right);
77         bc().addReadOnly(dialog_->radio_left);
78         bc().addReadOnly(dialog_->button_pix);
79 }
80
81
82 void FormMathsDelim::apply()
83 {
84         int const left = int(dialog_->radio_left->u_ldata);
85         int const right= int(dialog_->radio_right->u_ldata);
86
87         ostringstream ost;
88         ost << delim_values[left] << ' ' << delim_values[right];
89
90         lv_->getLyXFunc()->dispatch(LFUN_MATH_DELIM, ost.str().c_str());
91 }
92
93 bool FormMathsDelim::input(FL_OBJECT *, long)
94 {
95         int left = int(dialog_->radio_left->u_ldata);
96         int right= int(dialog_->radio_right->u_ldata);
97         int const side = (fl_get_button(dialog_->radio_right) != 0);
98
99         int const i = fl_get_bmtable(dialog_->bmtable);
100         int const button = fl_get_bmtable_numb(dialog_->bmtable);
101         bool const both = (button == FL_MIDDLE_MOUSE);
102         
103         if (i>= 0) {
104                 if (side || (button == FL_RIGHT_MOUSE))
105                         right = i;
106                 else {
107                         left = i;
108                         if (both)
109                                 right = delim_rversion[i];
110                 }
111         }
112  
113         Pixmap p1, p2;
114  
115         p1 = fl_get_pixmap_pixmap(dialog_->button_pix, &p1, &p2);
116         fl_draw_bmtable_item(dialog_->bmtable, left, p1, 0, 0);
117         fl_draw_bmtable_item(dialog_->bmtable, right, p1, 16, 0);
118         fl_redraw_object(dialog_->button_pix);
119         
120         dialog_->radio_left->u_ldata  = left;
121         dialog_->radio_right->u_ldata = right;
122
123         return true;
124 }