]> git.lyx.org Git - lyx.git/blob - src/ParagraphExtra.C
remove the old painter, remove support for mono_video, reverse_video, fast selection...
[lyx.git] / src / ParagraphExtra.C
1 #include <config.h>
2
3 #include <cstdlib>
4 #include FORMS_H_LOCATION
5
6 #include "layout_forms.h"
7 #include "LString.h"
8 #include "minibuffer.h"
9 #include "vspace.h"
10 #include "buffer.h"
11 #include "BufferView.h"
12 #include "lyxparagraph.h"
13 #include "gettext.h"
14 #include "lyxtext.h"
15 #include "LyXView.h"
16
17 extern FD_form_paragraph_extra * fd_form_paragraph_extra;
18 extern BufferView * current_view;
19 static bool CheckInputWidth();
20
21 inline void DeactivateParagraphExtraButtons ()
22 {
23         fl_deactivate_object(fd_form_paragraph_extra->button_ok);
24         fl_deactivate_object(fd_form_paragraph_extra->button_apply);
25         fl_set_object_lcol(fd_form_paragraph_extra->button_ok, FL_INACTIVE);
26         fl_set_object_lcol(fd_form_paragraph_extra->button_apply, FL_INACTIVE);
27 }
28
29 inline void ActivateParagraphExtraButtons ()
30 {
31         fl_activate_object(fd_form_paragraph_extra->button_ok);
32         fl_activate_object(fd_form_paragraph_extra->button_apply);
33         fl_set_object_lcol(fd_form_paragraph_extra->button_ok, FL_BLACK);
34         fl_set_object_lcol(fd_form_paragraph_extra->button_apply, FL_BLACK);
35 }
36
37 inline void DisableParagraphExtra ()
38 {
39         DeactivateParagraphExtraButtons();
40         fl_deactivate_object(fd_form_paragraph_extra->input_pextra_width);
41         fl_deactivate_object(fd_form_paragraph_extra->input_pextra_widthp);
42         fl_deactivate_object(fd_form_paragraph_extra->group_alignment);
43         fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
44         fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
45         fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
46         fl_deactivate_object(fd_form_paragraph_extra->text_warning);
47         fl_deactivate_object(fd_form_paragraph_extra->group_extraopt);
48         fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_indent);
49         fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_minipage);
50         fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_floatflt);
51         fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_hfill);
52         fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_startmp);
53 }       
54
55 inline void EnableParagraphExtra ()
56 {
57         ActivateParagraphExtraButtons();
58         fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
59         fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
60         fl_activate_object(fd_form_paragraph_extra->group_alignment);
61         fl_activate_object(fd_form_paragraph_extra->radio_pextra_top);
62         fl_activate_object(fd_form_paragraph_extra->radio_pextra_middle);
63         fl_activate_object(fd_form_paragraph_extra->radio_pextra_bottom);
64         fl_activate_object(fd_form_paragraph_extra->text_warning);
65         fl_activate_object(fd_form_paragraph_extra->group_extraopt);
66         fl_activate_object(fd_form_paragraph_extra->radio_pextra_indent);
67         fl_activate_object(fd_form_paragraph_extra->radio_pextra_minipage);
68         fl_activate_object(fd_form_paragraph_extra->radio_pextra_floatflt);
69         fl_activate_object(fd_form_paragraph_extra->radio_pextra_hfill);
70         fl_activate_object(fd_form_paragraph_extra->radio_pextra_startmp);
71 }       
72
73
74 bool UpdateParagraphExtra()
75 {
76         bool update = false;
77         if (current_view->available()) {
78                 update = true;
79                 LyXParagraph * par = current_view->text->cursor.par;
80
81                 EnableParagraphExtra();
82
83                 fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
84                 fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
85                 fl_set_input(fd_form_paragraph_extra->input_pextra_width,
86                              par->pextra_width.c_str());
87                 fl_set_input(fd_form_paragraph_extra->input_pextra_widthp,
88                              par->pextra_widthp.c_str());
89                 switch(par->pextra_alignment) {
90                 case LyXParagraph::MINIPAGE_ALIGN_TOP:
91                         fl_set_button(fd_form_paragraph_extra->radio_pextra_top, 1);
92                         break;
93                 case LyXParagraph::MINIPAGE_ALIGN_MIDDLE:
94                         fl_set_button(fd_form_paragraph_extra->radio_pextra_middle, 1);
95                         break;
96                 case LyXParagraph::MINIPAGE_ALIGN_BOTTOM:
97                         fl_set_button(fd_form_paragraph_extra->radio_pextra_bottom, 1);
98                         break;
99                 }
100                 fl_set_button(fd_form_paragraph_extra->radio_pextra_hfill,
101                               par->pextra_hfill);
102                 fl_set_button(fd_form_paragraph_extra->radio_pextra_startmp,
103                               par->pextra_start_minipage);
104                 CheckInputWidth();
105                 if (par->pextra_type == LyXParagraph::PEXTRA_INDENT) {
106                         fl_set_button(fd_form_paragraph_extra->radio_pextra_indent, 1);
107                         fl_set_button(fd_form_paragraph_extra->radio_pextra_minipage, 0);
108                         fl_set_button(fd_form_paragraph_extra->radio_pextra_floatflt, 0);
109                         fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
110                         fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
111                         fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
112                 } else if (par->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
113                         fl_set_button(fd_form_paragraph_extra->radio_pextra_indent, 0);
114                         fl_set_button(fd_form_paragraph_extra->radio_pextra_minipage, 1);
115                         fl_set_button(fd_form_paragraph_extra->radio_pextra_floatflt, 0);
116                         fl_activate_object(fd_form_paragraph_extra->radio_pextra_top);
117                         fl_activate_object(fd_form_paragraph_extra->radio_pextra_middle);
118                         fl_activate_object(fd_form_paragraph_extra->radio_pextra_bottom);
119                 } else if (par->pextra_type == LyXParagraph::PEXTRA_FLOATFLT) {
120                         fl_set_button(fd_form_paragraph_extra->radio_pextra_indent, 0);
121                         fl_set_button(fd_form_paragraph_extra->radio_pextra_minipage, 0);
122                         fl_set_button(fd_form_paragraph_extra->radio_pextra_floatflt, 1);
123                         fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
124                         fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
125                         fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
126                 } else {
127                         fl_set_button(fd_form_paragraph_extra->radio_pextra_indent, 0);
128                         fl_set_button(fd_form_paragraph_extra->radio_pextra_minipage, 0);
129                         fl_deactivate_object(fd_form_paragraph_extra->input_pextra_width);
130                         fl_deactivate_object(fd_form_paragraph_extra->input_pextra_widthp);
131                         fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
132                         fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
133                         fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
134                 }
135                 if (par->pextra_type == LyXParagraph::PEXTRA_NONE)
136                         ActivateParagraphExtraButtons();
137         }
138         fl_hide_object(fd_form_paragraph_extra->text_warning);
139
140         if (current_view->buffer()->isReadonly()) {
141                 DisableParagraphExtra();
142                 fl_set_object_label(fd_form_paragraph_extra->text_warning,
143                                     _("Document is read-only. "
144                                       "No changes to layout permitted."));
145                 fl_show_object(fd_form_paragraph_extra->text_warning);
146         }
147         if (!update && fd_form_paragraph_extra->form_paragraph_extra->visible) {
148                 fl_hide_form(fd_form_paragraph_extra->form_paragraph_extra);
149         }
150         return update;
151 }
152
153
154 void ParagraphExtraOpen(FL_OBJECT *, long)
155 {
156         if (UpdateParagraphExtra()) {
157                 if (fd_form_paragraph_extra->form_paragraph_extra->visible) {
158                         fl_raise_form(fd_form_paragraph_extra->form_paragraph_extra);
159                 } else {
160                         fl_show_form(fd_form_paragraph_extra->form_paragraph_extra,
161                                      FL_PLACE_MOUSE, FL_FULLBORDER,
162                                      _("ParagraphExtra Layout"));
163                 }
164         }
165 }
166
167
168 void ParagraphExtraApplyCB(FL_OBJECT *, long)
169 {
170         if (current_view->available()) {
171                 FD_form_paragraph_extra const * fd = fd_form_paragraph_extra;
172                 char const * width = fl_get_input(fd->input_pextra_width);
173                 char const * widthp = fl_get_input(fd->input_pextra_widthp);
174                 LyXText * text = current_view->text;
175                 int type = LyXParagraph::PEXTRA_NONE;
176                 LyXParagraph::MINIPAGE_ALIGNMENT alignment =
177                         LyXParagraph::MINIPAGE_ALIGN_TOP;
178                 bool
179                         hfill = false,
180                         start_minipage = false;
181
182                 if (fl_get_button(fd_form_paragraph_extra->radio_pextra_indent)) {
183                         type = LyXParagraph::PEXTRA_INDENT;
184                 } else if (fl_get_button(fd_form_paragraph_extra->radio_pextra_minipage)) {
185                         type = LyXParagraph::PEXTRA_MINIPAGE;
186                         hfill = fl_get_button(fd_form_paragraph_extra->radio_pextra_hfill);
187                         start_minipage = 
188                                 fl_get_button(fd_form_paragraph_extra->radio_pextra_startmp);
189                         if (fl_get_button(fd_form_paragraph_extra->radio_pextra_top))
190                                 alignment = LyXParagraph::MINIPAGE_ALIGN_TOP;
191                         else if (fl_get_button(fd_form_paragraph_extra->radio_pextra_middle))
192                                 alignment = LyXParagraph::MINIPAGE_ALIGN_MIDDLE;
193                         else if (fl_get_button(fd_form_paragraph_extra->radio_pextra_bottom))
194                                 alignment = LyXParagraph::MINIPAGE_ALIGN_BOTTOM;
195                 } else if (fl_get_button(fd_form_paragraph_extra->radio_pextra_floatflt)) {
196                         type = LyXParagraph::PEXTRA_FLOATFLT;
197                 }
198                 text->SetParagraphExtraOpt(type, width, widthp, alignment, hfill,
199                                            start_minipage);
200                 current_view->update(1);
201                 current_view->owner()->getMiniBuffer()->
202                         Set(_("ParagraphExtra layout set"));
203         }
204         return;
205 }
206
207
208 void ParagraphExtraCancelCB(FL_OBJECT *, long)
209 {
210         fl_hide_form(fd_form_paragraph_extra->form_paragraph_extra);
211 }
212
213
214 void ParagraphExtraOKCB(FL_OBJECT * ob, long data)
215 {
216         ParagraphExtraCancelCB(ob, data);
217         ParagraphExtraApplyCB(ob, data);
218 }
219
220
221 void CheckPExtraOptCB(FL_OBJECT * ob, long)
222 {
223         ActivateParagraphExtraButtons();
224         CheckInputWidth();
225         if (ob == fd_form_paragraph_extra->radio_pextra_indent) {
226                 int n = fl_get_button(fd_form_paragraph_extra->radio_pextra_indent);
227                 if (n) {
228                         fl_set_button(fd_form_paragraph_extra->radio_pextra_minipage, 0);
229                         fl_set_button(fd_form_paragraph_extra->radio_pextra_floatflt, 0);
230                         fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
231                         fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
232                         fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
233                         fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
234                         fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
235                 } else {
236                         fl_deactivate_object(fd_form_paragraph_extra->input_pextra_width);
237                         fl_deactivate_object(fd_form_paragraph_extra->input_pextra_widthp);
238                         ActivateParagraphExtraButtons();
239                 }
240         } else if (ob == fd_form_paragraph_extra->radio_pextra_minipage) {
241                 int n = fl_get_button(fd_form_paragraph_extra->radio_pextra_minipage);
242                 if (n) {
243                         fl_set_button(fd_form_paragraph_extra->radio_pextra_indent, 0);
244                         fl_set_button(fd_form_paragraph_extra->radio_pextra_floatflt, 0);
245                         fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
246                         fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
247                         fl_activate_object(fd_form_paragraph_extra->radio_pextra_top);
248                         fl_activate_object(fd_form_paragraph_extra->radio_pextra_middle);
249                         fl_activate_object(fd_form_paragraph_extra->radio_pextra_bottom);
250                 } else {
251                         fl_deactivate_object(fd_form_paragraph_extra->input_pextra_width);
252                         fl_deactivate_object(fd_form_paragraph_extra->input_pextra_widthp);
253                         fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
254                         fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
255                         fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
256                         ActivateParagraphExtraButtons();
257                 }
258         } else if (ob == fd_form_paragraph_extra->radio_pextra_floatflt) {
259                 int n = fl_get_button(fd_form_paragraph_extra->radio_pextra_floatflt);
260                 if (n) {
261                         fl_set_button(fd_form_paragraph_extra->radio_pextra_indent, 0);
262                         fl_set_button(fd_form_paragraph_extra->radio_pextra_minipage, 0);
263                         fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
264                         fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
265                         fl_activate_object(fd_form_paragraph_extra->radio_pextra_top);
266                         fl_activate_object(fd_form_paragraph_extra->radio_pextra_middle);
267                         fl_activate_object(fd_form_paragraph_extra->radio_pextra_bottom);
268                 } else {
269                         fl_deactivate_object(fd_form_paragraph_extra->input_pextra_width);
270                         fl_deactivate_object(fd_form_paragraph_extra->input_pextra_widthp);
271                         fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
272                         fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
273                         fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
274                         ActivateParagraphExtraButtons();
275                 }
276         }
277         return;
278 }
279
280
281 static bool CheckInputWidth()
282 {
283         string s1 = fl_get_input(fd_form_paragraph_extra->input_pextra_width);
284         string s2 = fl_get_input(fd_form_paragraph_extra->input_pextra_widthp);
285         if (s1.empty() && s2.empty()) {
286                 fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
287                 fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
288                 fl_hide_object(fd_form_paragraph_extra->text_warning);
289                 DeactivateParagraphExtraButtons();
290                 return false;
291         }
292         if (!s1.empty()) { // LyXLength parameter
293                 fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
294                 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_widthp);
295                 if (!isValidLength(s1)) {
296                         DeactivateParagraphExtraButtons();
297                         fl_set_object_label(fd_form_paragraph_extra->text_warning,
298                                             _("Warning: Invalid Length (valid example: 10mm)"));
299                         fl_show_object(fd_form_paragraph_extra->text_warning);
300                         return false;
301                 }
302         } else { // !s2.empty() % parameter
303                 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_width);
304                 fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
305                 if ((atoi(s2.c_str()) < 0 ) || (atoi(s2.c_str()) > 100)) {
306                         DeactivateParagraphExtraButtons();
307                         fl_set_object_label(fd_form_paragraph_extra->text_warning,
308                                             _("Warning: Invalid percent value (0-100)"));
309                         fl_show_object(fd_form_paragraph_extra->text_warning);
310                         return false;
311                 }
312         }
313         fl_hide_object(fd_form_paragraph_extra->text_warning);
314         return true;
315 }