]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormMathsDelim.C
use exclicit temp var
[lyx.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 "support/lstrings.h"
25 #include "lyxfunc.h"
26
27 #include "delim.xbm"
28 #include "delim0.xpm"
29
30 static int const delim_rversion[] = { 
31         1,1,3,3,4,5,7,7,9,9,10,11,
32         13,13,14,15,16,17,19,19,20,21,22,23 };
33  
34 static char const * delim_values[] = {
35         "(", ")", "lceil",  "rceil",  "uparrow",  "Uparrow",
36         "[", "]", "lfloor", "rfloor", "updownarrow", "Updownarrow",
37         "{", "}",  "/", "\\",  "downarrow",  "Downarrow",
38         "langle",  "rangle", "|", "Vert", ".", 0
39 };
40
41 using std::endl;
42
43 FormMathsDelim::FormMathsDelim(LyXView * lv, Dialogs * d, 
44                                FormMathsPanel const & p)
45         : FormMathsSub(lv, d, p, _("Maths Delimiters"), false)
46 {}
47
48
49 FL_FORM * FormMathsDelim::form() const
50 {
51         if (dialog_.get())
52                 return dialog_->form;
53         return 0;
54 }
55
56
57 void FormMathsDelim::build()
58 {
59         dialog_.reset(build_maths_delim());
60         
61         fl_set_button(dialog_->radio_left, 1);
62         fl_set_pixmap_data(dialog_->button_pix, const_cast<char**>(delim0));
63         dialog_->radio_left->u_ldata = 0;
64         dialog_->radio_right->u_ldata = 1;
65         dialog_->radio_both->u_ldata = 2;
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_->radio_both);
79         bc().addReadOnly(dialog_->button_pix);
80 }
81
82
83 void FormMathsDelim::apply()
84 {
85         int const left = int(dialog_->radio_left->u_ldata);
86         int const right= int(dialog_->radio_right->u_ldata);
87
88         ostringstream ost;
89         ost << delim_values[left] << ' ' << delim_values[right];
90
91         lv_->getLyXFunc()->dispatch(LFUN_MATH_DELIM, ost.str().c_str());
92 }
93
94 bool FormMathsDelim::input(FL_OBJECT *, long)
95 {
96         int left = int(dialog_->radio_left->u_ldata);
97         int right= int(dialog_->radio_right->u_ldata);
98         int const side = (fl_get_button(dialog_->radio_right) != 0);
99
100         int const i = fl_get_bmtable(dialog_->bmtable);
101         int const button = fl_get_bmtable_numb(dialog_->bmtable);
102         bool const both = (button == FL_MIDDLE_MOUSE) 
103                         || (fl_get_button(dialog_->radio_both) != 0);
104         
105         if (i >= 0) {
106                 if (side || (button == FL_RIGHT_MOUSE))
107                         right = i;
108                 else {
109                         left = i;
110                         if (both)
111                                 right = delim_rversion[i];
112                 }
113         }
114  
115         Pixmap p1, p2;
116  
117         p1 = fl_get_pixmap_pixmap(dialog_->button_pix, &p1, &p2);
118         fl_draw_bmtable_item(dialog_->bmtable, left, p1, 0, 0);
119         fl_draw_bmtable_item(dialog_->bmtable, right, p1, 16, 0);
120         fl_redraw_object(dialog_->button_pix);
121         
122         dialog_->radio_left->u_ldata  = left;
123         dialog_->radio_right->u_ldata = right;
124
125         return true;
126 }