]> git.lyx.org Git - features.git/blob - src/frontends/xforms/FormMathsDelim.C
9d88e60c86e517c95a3d50142227ff8c736e5c66
[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 <leeming@lyx.org>
10  */
11
12 #include <config.h>
13
14 #ifdef __GNUG__
15 #pragma implementation
16 #endif
17
18 #include "FormMathsDelim.h"
19 #include "forms/form_maths_delim.h"
20
21 #include "bmtable.h"
22
23 #include "debug.h"
24 #include "funcrequest.h"
25 #include "lyxfunc.h"
26
27 #include "frontends/LyXView.h"
28
29 #include "support/lstrings.h"
30
31 #include "Lsstream.h"
32
33 #include FORMS_H_LOCATION
34
35 #include "delim.xbm"
36 #include "delim0.xpm"
37 #include "delim1.xpm"
38
39
40 static int const delim_rversion[] = {
41         1,1,3,3,4,5,7,7,9,9,10,11,
42         13,13,14,15,16,17,19,19,20,21,22,23
43 };
44
45
46 static char const * delim_values[] = {
47         "(", ")", "lceil",  "rceil",  "uparrow",  "Uparrow",
48         "[", "]", "lfloor", "rfloor", "updownarrow", "Updownarrow",
49         "{", "}",  "/", "\\",  "downarrow",  "Downarrow",
50         "langle",  "rangle", "|", "Vert", ".", 0
51 };
52
53 using std::endl;
54
55 FormMathsDelim::FormMathsDelim(LyXView & lv, Dialogs & d,
56                                FormMathsPanel const & p)
57         : FormMathsSub(lv, d, p, _("Maths Delimiters"), false)
58 {}
59
60
61 FL_FORM * FormMathsDelim::form() const
62 {
63         if (dialog_.get())
64                 return dialog_->form;
65         return 0;
66 }
67
68
69 void FormMathsDelim::build()
70 {
71         dialog_.reset(build_maths_delim(this));
72
73         fl_set_button(dialog_->radio_left, 1);
74         // Initialize button_pix to "()" as found in images/delim0.xpm:
75         fl_set_pixmap_data(dialog_->button_pix, const_cast<char**>(delim0));
76         dialog_->radio_left->u_ldata = 0;
77         dialog_->radio_right->u_ldata = 1;
78         //dialog_->radio_both->u_ldata = 2;
79
80         fl_set_bmtable_data(dialog_->bmtable, 12, 2,
81                             delim_width, delim_height, delim_bits);
82         fl_set_bmtable_maxitems(dialog_->bmtable, 23);
83
84         bc().setOK(dialog_->button_ok);
85         bc().setApply(dialog_->button_apply);
86         bc().setCancel(dialog_->button_close);
87
88         bc().addReadOnly(dialog_->bmtable);
89         bc().addReadOnly(dialog_->radio_right);
90         bc().addReadOnly(dialog_->radio_left);
91         bc().addReadOnly(dialog_->radio_both);
92         bc().addReadOnly(dialog_->button_pix);
93 }
94
95
96 void FormMathsDelim::apply()
97 {
98         int const left  = int(dialog_->radio_left->u_ldata);
99         int const right = int(dialog_->radio_right->u_ldata);
100
101         ostringstream os;
102         os << delim_values[left] << ' ' << delim_values[right];
103
104         lv_.dispatch(FuncRequest(LFUN_MATH_DELIM, os.str().c_str()));
105 }
106
107
108 bool FormMathsDelim::input(FL_OBJECT *, long)
109 {
110         int left = int(dialog_->radio_left->u_ldata);
111         int right= int(dialog_->radio_right->u_ldata);
112         int const side = (fl_get_button(dialog_->radio_right) != 0);
113
114         int const i = fl_get_bmtable(dialog_->bmtable);
115         int const button = fl_get_bmtable_numb(dialog_->bmtable);
116         bool const both = (button == FL_MIDDLE_MOUSE ||
117                            fl_get_button(dialog_->radio_both) != 0);
118
119         if (i >= 0) {
120                 if (side || (button == FL_RIGHT_MOUSE))
121                         right = i;
122                 else {
123                         left = i;
124                         if (both) {
125                                 right = delim_rversion[i];
126                                 // Add left delimiter in "both" case if right one was pressed:
127                                 for (int j = 0; j <= 23; ++j) {
128                                         if (delim_rversion[j] == left) {
129                                                 right = left;
130                                                 left = j;
131                                         }
132                                 }
133                         }
134                 }
135         }
136
137         // Re-initialize button_pix to solid blue 
138         // (not elegant but works, MV 24.5.2002)
139         fl_free_pixmap_pixmap(dialog_->button_pix);
140         fl_set_pixmap_data(dialog_->button_pix, const_cast<char**>(delim1));
141         Pixmap p1;
142         fl_get_pixmap_pixmap(dialog_->button_pix, &p1, 0);
143         
144         fl_draw_bmtable_item(dialog_->bmtable, left, p1, 0, 0);
145         fl_draw_bmtable_item(dialog_->bmtable, right, p1, 16, 0);
146         fl_redraw_object(dialog_->button_pix);
147
148         dialog_->radio_left->u_ldata  = left;
149         dialog_->radio_right->u_ldata = right;
150
151         return true;
152 }