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