]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormTabular.C
Port the tabular dialog to the new scheme based on class Dialog.
[lyx.git] / src / frontends / xforms / FormTabular.C
1 /**
2  * \file FormTabular.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Jürgen Vigna
7  *
8  * Full author contact details are available in file CREDITS
9  */
10
11 #include <config.h>
12
13
14 #include <vector>
15 #include <algorithm>
16
17 #include "ControlTabular.h"
18 #include "xformsBC.h"
19 #include "insets/insettabular.h"
20
21 #include "FormTabular.h"
22 #include "forms/form_tabular.h"
23 #include "debug.h"
24 #include "xforms_helpers.h"
25 #include "gettext.h"
26 #include "lyxrc.h"
27 #include "helper_funcs.h"
28 #include "input_validators.h"
29 #include "support/lstrings.h"
30
31 #include FORMS_H_LOCATION
32
33 using std::vector;
34 using std::bind2nd;
35
36
37 typedef FormController<ControlTabular, FormView<FD_tabular> > base_class;
38
39 FormTabular::FormTabular(Dialog & parent)
40         : base_class(parent, _("Edit table settings")),
41         closing_(false), actCell_(-1)
42 {
43 }
44
45
46 void FormTabular::redraw()
47 {
48         if (form() && form()->visible)
49                 fl_redraw_form(form());
50         else
51                 return;
52
53         FL_FORM * outer_form = fl_get_active_folder(dialog_->tabfolder);
54         if (outer_form && outer_form->visible)
55                 fl_redraw_form(outer_form);
56 }
57
58
59 void FormTabular::build()
60 {
61         dialog_.reset(build_tabular(this));
62
63         // Allow the base class to control messages
64         setMessageWidget(dialog_->text_warning);
65
66         // trigger an input event for cut&paste with middle mouse button.
67         setPrehandler(dialog_->input_tabular_column);
68         setPrehandler(dialog_->input_tabular_row);
69
70         // Create the contents of the unit choices; don't include the "%" terms.
71         vector<string> units_vec = getLatexUnits();
72         vector<string>::iterator ret =
73                 remove_if(units_vec.begin(), units_vec.end(),
74                           bind2nd(contains_functor(), "%"));
75         units_vec.erase(ret, units_vec.end());
76         string const units = getStringFromVector(units_vec, "|");
77
78         // tabular options form
79         tabular_options_.reset(build_tabular_options(this));
80
81         // column options form
82         column_options_.reset(build_tabular_column(this));
83
84         fl_set_input_return(column_options_->input_column_width,
85                             FL_RETURN_END);
86         fl_set_input_return(column_options_->input_special_alignment,
87                             FL_RETURN_END);
88
89         // trigger an input event for cut&paste with middle mouse button.
90         setPrehandler(column_options_->input_column_width);
91         setPrehandler(column_options_->input_special_alignment);
92
93         fl_addto_choice(column_options_->choice_value_column_width,
94                         units.c_str());
95
96         // cell options form
97         cell_options_.reset(build_tabular_cell(this));
98
99         fl_set_input_return(cell_options_->input_mcolumn_width,
100                             FL_RETURN_END);
101         fl_set_input_return(cell_options_->input_special_multialign,
102                             FL_RETURN_END);
103
104         // trigger an input event for cut&paste with middle mouse button.
105         setPrehandler(cell_options_->input_mcolumn_width);
106         setPrehandler(cell_options_->input_special_multialign);
107
108         fl_addto_choice(cell_options_->choice_value_mcolumn_width,
109                         units.c_str());
110
111         longtable_options_.reset(build_tabular_longtable(this));
112
113         fl_addto_tabfolder(dialog_->tabfolder, _("Tabular"),
114                            tabular_options_->form);
115         fl_addto_tabfolder(dialog_->tabfolder, _("Column/Row"),
116                            column_options_->form);
117         fl_addto_tabfolder(dialog_->tabfolder, _("Cell"),
118                            cell_options_->form);
119         fl_addto_tabfolder(dialog_->tabfolder, _("LongTable"),
120                            longtable_options_->form);
121
122         // work-around xforms bug re update of folder->x, folder->y coords.
123         setPrehandler(dialog_->tabfolder);
124
125         //  FIXME: addReadOnly everything
126 }
127
128
129 void FormTabular::update()
130 {
131         if (closing_)
132                 return;
133
134         LyXTabular const & tabular = controller().tabular();
135
136         int align;
137         char buf[12];
138         LyXLength pwidth;
139         string special;
140
141         int const cell = controller().getActiveCell();
142         actCell_ = cell;
143         int column = tabular.column_of_cell(cell) + 1;
144         clearMessage();
145         fl_activate_object(column_options_->input_special_alignment);
146         fl_activate_object(cell_options_->input_special_multialign);
147         fl_activate_object(column_options_->input_column_width);
148         fl_activate_object(column_options_->choice_value_column_width);
149         sprintf(buf, "%d", column);
150         fl_set_input(dialog_->input_tabular_column, buf);
151         fl_deactivate_object(dialog_->input_tabular_column);
152         int row = tabular.row_of_cell(cell);
153         sprintf(buf, "%d", row + 1);
154         fl_set_input(dialog_->input_tabular_row, buf);
155         fl_deactivate_object(dialog_->input_tabular_row);
156         if (tabular.IsMultiColumn(cell)) {
157                 fl_set_button(cell_options_->check_multicolumn, 1);
158                 fl_set_button(cell_options_->check_border_top,
159                               tabular.TopLine(cell)?1:0);
160                 setEnabled(cell_options_->check_border_top, true);
161                 fl_set_button(cell_options_->check_border_bottom,
162                               tabular.BottomLine(cell)?1:0);
163                 setEnabled(cell_options_->check_border_bottom, true);
164                 // pay attention to left/right lines they are only allowed
165                 // to set if we are in first/last cell of row or if the left/right
166                 // cell is also a multicolumn.
167                 if (tabular.IsFirstCellInRow(cell) ||
168                     tabular.IsMultiColumn(cell-1)) {
169                         fl_set_button(cell_options_->check_border_left,
170                                       tabular.LeftLine(cell)?1:0);
171                         setEnabled(cell_options_->check_border_left, true);
172                 } else {
173                         fl_set_button(cell_options_->check_border_left, 0);
174                         setEnabled(cell_options_->check_border_left, false);
175                 }
176                 if (tabular.IsLastCellInRow(cell) ||
177                     tabular.IsMultiColumn(cell+1)) {
178                         fl_set_button(cell_options_->check_border_right,
179                                       tabular.RightLine(cell)?1:0);
180                         setEnabled(cell_options_->check_border_right, true);
181                 } else {
182                         fl_set_button(cell_options_->check_border_right, 0);
183                         setEnabled(cell_options_->check_border_right, false);
184                 }
185                 pwidth = tabular.GetMColumnPWidth(cell);
186                 align = tabular.GetAlignment(cell);
187                 // set the horiz. alignment, default is left here
188                 fl_set_button(cell_options_->radio_align_left, 0);
189                 fl_set_button(cell_options_->radio_align_right, 0);
190                 fl_set_button(cell_options_->radio_align_center, 0);
191                 if (align == LYX_ALIGN_RIGHT)
192                         fl_set_button(cell_options_->radio_align_right, 1);
193                 else if (align == LYX_ALIGN_CENTER)
194                         fl_set_button(cell_options_->radio_align_center, 1);
195                 else
196                         fl_set_button(cell_options_->radio_align_left, 1);
197
198                 align = tabular.GetVAlignment(cell);
199                 fl_set_button(cell_options_->radio_valign_top, 0);
200                 fl_set_button(cell_options_->radio_valign_bottom, 0);
201                 fl_set_button(cell_options_->radio_valign_center, 0);
202                 if (pwidth.zero() || (align == LyXTabular::LYX_VALIGN_CENTER))
203                         fl_set_button(cell_options_->radio_valign_center, 1);
204                 else if (align == LyXTabular::LYX_VALIGN_BOTTOM)
205                         fl_set_button(cell_options_->radio_valign_bottom, 1);
206                 else
207                         fl_set_button(cell_options_->radio_valign_top, 1);
208
209                 special = tabular.GetAlignSpecial(cell, LyXTabular::SET_SPECIAL_MULTI);
210                 fl_set_input(cell_options_->input_special_multialign, special.c_str());
211                 bool const metric(controller().useMetricUnits());
212                 string const default_unit = metric ? "cm" : "in";
213                 updateWidgetsFromLength(cell_options_->input_mcolumn_width,
214                                         cell_options_->choice_value_mcolumn_width,
215                                         pwidth, default_unit);
216
217                 if (!bc().bp().isReadOnly()) {
218                         setEnabled(cell_options_->input_special_multialign, true);
219                         setEnabled(cell_options_->input_mcolumn_width, true);
220                         setEnabled(cell_options_->choice_value_mcolumn_width, true);
221                 }
222
223                 setEnabled(cell_options_->radio_valign_top,    !pwidth.zero());
224                 setEnabled(cell_options_->radio_valign_bottom, !pwidth.zero());
225                 setEnabled(cell_options_->radio_valign_center, !pwidth.zero());
226
227                 setEnabled(cell_options_->radio_align_left,   true);
228                 setEnabled(cell_options_->radio_align_right,  true);
229                 setEnabled(cell_options_->radio_align_center, true);
230         } else {
231                 fl_set_button(cell_options_->check_multicolumn, 0);
232
233                 fl_set_button(cell_options_->check_border_top, 0);
234                 setEnabled(cell_options_->check_border_top, false);
235
236                 fl_set_button(cell_options_->check_border_bottom, 0);
237                 setEnabled(cell_options_->check_border_bottom, false);
238
239                 fl_set_button(cell_options_->check_border_left, 0);
240                 setEnabled(cell_options_->check_border_left, false);
241
242                 fl_set_button(cell_options_->check_border_right, 0);
243                 setEnabled(cell_options_->check_border_right, false);
244
245                 fl_set_button(cell_options_->radio_align_left, 0);
246                 setEnabled(cell_options_->radio_align_left, false);
247
248                 fl_set_button(cell_options_->radio_align_right, 0);
249                 setEnabled(cell_options_->radio_align_right, false);
250
251                 fl_set_button(cell_options_->radio_align_center, 0);
252                 setEnabled(cell_options_->radio_align_center, false);
253
254                 fl_set_button(cell_options_->radio_valign_top, 0);
255                 setEnabled(cell_options_->radio_valign_top, false);
256
257                 fl_set_button(cell_options_->radio_valign_bottom, 0);
258                 setEnabled(cell_options_->radio_valign_bottom, false);
259
260                 fl_set_button(cell_options_->radio_valign_center, 0);
261                 setEnabled(cell_options_->radio_valign_center, false);
262
263                 fl_set_input(cell_options_->input_special_multialign, "");
264                 setEnabled(cell_options_->input_special_multialign, false);
265
266                 fl_set_input(cell_options_->input_mcolumn_width, "");
267                 setEnabled(cell_options_->input_mcolumn_width, false);
268                 setEnabled(cell_options_->choice_value_mcolumn_width, false);
269         }
270         if (tabular.GetRotateCell(cell))
271                 fl_set_button(cell_options_->check_rotate_cell, 1);
272         else
273                 fl_set_button(cell_options_->check_rotate_cell, 0);
274         if (tabular.TopLine(cell, true))
275                 fl_set_button(column_options_->check_border_top, 1);
276         else
277                 fl_set_button(column_options_->check_border_top, 0);
278         if (tabular.BottomLine(cell, true))
279                 fl_set_button(column_options_->check_border_bottom, 1);
280         else
281                 fl_set_button(column_options_->check_border_bottom, 0);
282         if (tabular.LeftLine(cell, true))
283                 fl_set_button(column_options_->check_border_left, 1);
284         else
285                 fl_set_button(column_options_->check_border_left, 0);
286         if (tabular.RightLine(cell, true))
287                 fl_set_button(column_options_->check_border_right, 1);
288         else
289                 fl_set_button(column_options_->check_border_right, 0);
290         special = tabular.GetAlignSpecial(cell, LyXTabular::SET_SPECIAL_COLUMN);
291         fl_set_input(column_options_->input_special_alignment, special.c_str());
292
293         bool const isReadonly = bc().bp().isReadOnly();
294         setEnabled(column_options_->input_special_alignment, !isReadonly);
295
296         pwidth = tabular.GetColumnPWidth(cell);
297         bool const metric = controller().useMetricUnits();
298         string const default_unit = metric ? "cm" : "in";
299         updateWidgetsFromLength(column_options_->input_column_width,
300                                 column_options_->choice_value_column_width,
301                                 pwidth, default_unit);
302         setEnabled(column_options_->input_column_width, !isReadonly);
303         setEnabled(column_options_->choice_value_column_width, !isReadonly);
304
305         setEnabled(cell_options_->check_useminipage, !pwidth.zero());
306         if (!pwidth.zero()) {
307                 if (tabular.GetUsebox(cell) == 2)
308                         fl_set_button(cell_options_->check_useminipage, 1);
309                 else
310                         fl_set_button(cell_options_->check_useminipage, 0);
311         } else {
312                 fl_set_button(cell_options_->check_useminipage, 0);
313         }
314         align = tabular.GetAlignment(cell, true);
315         fl_set_button(column_options_->radio_align_left, 0);
316         fl_set_button(column_options_->radio_align_right, 0);
317         fl_set_button(column_options_->radio_align_center, 0);
318         fl_set_button(column_options_->radio_align_block, 0);
319         if (align == LYX_ALIGN_LEFT)
320                 fl_set_button(column_options_->radio_align_left, 1);
321         else if (align == LYX_ALIGN_RIGHT)
322                 fl_set_button(column_options_->radio_align_right, 1);
323         else if (align == LYX_ALIGN_CENTER)
324                 fl_set_button(column_options_->radio_align_center, 1);
325         else
326                 fl_set_button(column_options_->radio_align_block, 1);
327         align = tabular.GetVAlignment(cell, true);
328         fl_set_button(column_options_->radio_valign_top, 0);
329         fl_set_button(column_options_->radio_valign_bottom, 0);
330         fl_set_button(column_options_->radio_valign_center, 0);
331         if (pwidth.zero() || (align == LyXTabular::LYX_VALIGN_CENTER))
332                 fl_set_button(column_options_->radio_valign_center, 1);
333         else if (align == LyXTabular::LYX_VALIGN_BOTTOM)
334                 fl_set_button(column_options_->radio_valign_bottom, 1);
335         else
336                 fl_set_button(column_options_->radio_valign_top, 1);
337
338         setEnabled(column_options_->radio_align_left,   true);
339         setEnabled(column_options_->radio_align_right,  true);
340         setEnabled(column_options_->radio_align_center, true);
341         setEnabled(column_options_->radio_align_block,   !pwidth.zero());
342         setEnabled(column_options_->radio_valign_top,    !pwidth.zero());
343         setEnabled(column_options_->radio_valign_bottom, !pwidth.zero());
344         setEnabled(column_options_->radio_valign_center, !pwidth.zero());
345
346         fl_set_button(tabular_options_->check_longtable,
347                       tabular.IsLongTabular());
348
349         bool const enable = tabular.IsLongTabular();
350
351         setEnabled(longtable_options_->check_lt_firsthead, enable);
352         setEnabled(longtable_options_->check_1head_2border_above, enable);
353         setEnabled(longtable_options_->check_1head_2border_below, enable);
354         setEnabled(longtable_options_->check_1head_empty, enable);
355         setEnabled(longtable_options_->check_lt_head, enable);
356         setEnabled(longtable_options_->check_head_2border_above, enable);
357         setEnabled(longtable_options_->check_head_2border_below, enable);
358         setEnabled(longtable_options_->check_lt_foot, enable);
359         setEnabled(longtable_options_->check_foot_2border_above, enable);
360         setEnabled(longtable_options_->check_foot_2border_below, enable);
361         setEnabled(longtable_options_->check_lt_lastfoot, enable);
362         setEnabled(longtable_options_->check_lastfoot_2border_above, enable);
363         setEnabled(longtable_options_->check_lastfoot_2border_below, enable);
364         setEnabled(longtable_options_->check_lastfoot_empty, enable);
365         setEnabled(longtable_options_->check_lt_newpage, enable);
366
367         if (enable) {
368                 LyXTabular::ltType ltt;
369                 bool use_empty;
370                 bool row_set = tabular.GetRowOfLTHead(row, ltt);
371                 fl_set_button(longtable_options_->check_lt_head, row_set);
372                 if (ltt.set) {
373                         fl_set_button(longtable_options_->check_head_2border_above,
374                                       ltt.topDL);
375                         fl_set_button(longtable_options_->check_head_2border_below,
376                                       ltt.bottomDL);
377                         use_empty = true;
378                 } else {
379                         setEnabled(longtable_options_->check_head_2border_above, 0);
380                         setEnabled(longtable_options_->check_head_2border_below, 0);
381                         fl_set_button(longtable_options_->check_head_2border_above,0);
382                         fl_set_button(longtable_options_->check_head_2border_below,0);
383                         fl_set_button(longtable_options_->check_1head_empty,0);
384                         setEnabled(longtable_options_->check_1head_empty, 0);
385                         use_empty = false;
386                 }
387                 //
388                 row_set = tabular.GetRowOfLTFirstHead(row, ltt);
389                 fl_set_button(longtable_options_->check_lt_firsthead, row_set);
390                 if (ltt.set && (!ltt.empty || !use_empty)) {
391                         fl_set_button(longtable_options_->check_1head_2border_above,
392                                       ltt.topDL);
393                         fl_set_button(longtable_options_->check_1head_2border_below,
394                                       ltt.bottomDL);
395                 } else {
396                         setEnabled(longtable_options_->check_1head_2border_above, 0);
397                         setEnabled(longtable_options_->check_1head_2border_below, 0);
398                         fl_set_button(longtable_options_->check_1head_2border_above,0);
399                         fl_set_button(longtable_options_->check_1head_2border_below,0);
400                         if (use_empty) {
401                                 fl_set_button(longtable_options_->check_1head_empty,ltt.empty);
402                                 if (ltt.empty)
403                                         setEnabled(longtable_options_->check_lt_firsthead, 0);
404                         }
405                 }
406                 //
407                 row_set = tabular.GetRowOfLTFoot(row, ltt);
408                 fl_set_button(longtable_options_->check_lt_foot, row_set);
409                 if (ltt.set) {
410                         fl_set_button(longtable_options_->check_foot_2border_above,
411                                       ltt.topDL);
412                         fl_set_button(longtable_options_->check_foot_2border_below,
413                                       ltt.bottomDL);
414                         use_empty = true;
415                 } else {
416                         setEnabled(longtable_options_->check_foot_2border_above, 0);
417                         setEnabled(longtable_options_->check_foot_2border_below, 0);
418                         fl_set_button(longtable_options_->check_foot_2border_above,0);
419                         fl_set_button(longtable_options_->check_foot_2border_below,0);
420                         fl_set_button(longtable_options_->check_lastfoot_empty, 0);
421                         setEnabled(longtable_options_->check_lastfoot_empty, 0);
422                         use_empty = false;
423                 }
424                 //
425                 row_set = tabular.GetRowOfLTLastFoot(row, ltt);
426                 fl_set_button(longtable_options_->check_lt_lastfoot, row_set);
427                 if (ltt.set && (!ltt.empty || !use_empty)) {
428                         fl_set_button(longtable_options_->check_lastfoot_2border_above,
429                                       ltt.topDL);
430                         fl_set_button(longtable_options_->check_lastfoot_2border_below,
431                                       ltt.bottomDL);
432                 } else {
433                         setEnabled(longtable_options_->check_lastfoot_2border_above,0);
434                         setEnabled(longtable_options_->check_lastfoot_2border_below,0);
435                         fl_set_button(longtable_options_->check_lastfoot_2border_above, 0);
436                         fl_set_button(longtable_options_->check_lastfoot_2border_below, 0);
437                         if (use_empty) {
438                                 fl_set_button(longtable_options_->check_lastfoot_empty,
439                                               ltt.empty);
440                                 if (ltt.empty)
441                                         setEnabled(longtable_options_->check_lt_lastfoot, 0);
442                         }
443                 }
444                 fl_set_button(longtable_options_->check_lt_newpage,
445                               tabular.GetLTNewPage(row));
446         } else {
447                 fl_set_button(longtable_options_->check_lt_firsthead, 0);
448                 fl_set_button(longtable_options_->check_1head_2border_above, 0);
449                 fl_set_button(longtable_options_->check_1head_2border_below, 0);
450                 fl_set_button(longtable_options_->check_1head_empty, 0);
451                 fl_set_button(longtable_options_->check_lt_head, 0);
452                 fl_set_button(longtable_options_->check_head_2border_above, 0);
453                 fl_set_button(longtable_options_->check_head_2border_below, 0);
454                 fl_set_button(longtable_options_->check_lt_foot, 0);
455                 fl_set_button(longtable_options_->check_foot_2border_above, 0);
456                 fl_set_button(longtable_options_->check_foot_2border_below, 0);
457                 fl_set_button(longtable_options_->check_lt_lastfoot, 0);
458                 fl_set_button(longtable_options_->check_lastfoot_2border_above, 0);
459                 fl_set_button(longtable_options_->check_lastfoot_2border_below, 0);
460                 fl_set_button(longtable_options_->check_lastfoot_empty, 0);
461                 fl_set_button(longtable_options_->check_lt_newpage, 0);
462         }
463         fl_set_button(tabular_options_->check_rotate_tabular,
464                       tabular.GetRotateTabular());
465 }
466
467
468 ButtonPolicy::SMInput FormTabular::input(FL_OBJECT * ob, long)
469 {
470         int s;
471         LyXTabular::Feature num = LyXTabular::LAST_ACTION;
472         string special;
473
474         LyXTabular const & tabular = controller().tabular();
475
476         int const cell = controller().getActiveCell();
477
478         // ugly hack to auto-apply the stuff that hasn't been
479         // yet. don't let this continue to exist ...
480         if (ob == dialog_->button_close) {
481                 closing_ = true;
482                 string str1 =
483                         getLengthFromWidgets(column_options_->input_column_width,
484                                              column_options_->choice_value_column_width);
485                 string str2;
486                 LyXLength llen = tabular.GetColumnPWidth(cell);
487                 if (!llen.zero())
488                         str2 = llen.asString();
489                 if (str1 != str2)
490                         input(column_options_->input_column_width, 0);
491                 str1 = getLengthFromWidgets(cell_options_->input_mcolumn_width,
492                                             cell_options_->choice_value_mcolumn_width);
493                 llen = tabular.GetMColumnPWidth(cell);
494                 if (llen.zero())
495                         str2 = "";
496                 else
497                         str2 = llen.asString();
498                 if (str1 != str2)
499                         input(cell_options_->input_mcolumn_width, 0);
500                 str1 = getString(column_options_->input_special_alignment);
501                 str2 = tabular.GetAlignSpecial(cell, LyXTabular::SET_SPECIAL_COLUMN);
502                 if (str1 != str2)
503                         input(column_options_->input_special_alignment, 0);
504                 str1 = getString(cell_options_->input_special_multialign);
505                 str2 = tabular.GetAlignSpecial(cell, LyXTabular::SET_SPECIAL_MULTI);
506                 if (str1 != str2)
507                         input(cell_options_->input_special_multialign, 0);
508
509                 closing_ = false;
510                 dialog().OKButton();
511                 return ButtonPolicy::SMI_VALID;
512         }
513
514         if (actCell_ != cell) {
515                 update();
516                 postWarning(_("Wrong Cursor position, updated window"));
517                 return ButtonPolicy::SMI_VALID;
518         }
519
520         // No point in processing directives that you can't do anything with
521         // anyhow, so exit now if the buffer is read-only.
522         if (bc().bp().isReadOnly()) {
523                 update();
524                 return ButtonPolicy::SMI_VALID;
525         }
526
527         if ((ob == column_options_->input_column_width) ||
528             (ob == column_options_->choice_value_column_width)) {
529                 string const str =
530                         getLengthFromWidgets(column_options_->input_column_width,
531                                              column_options_->choice_value_column_width);
532                 controller().set(LyXTabular::SET_PWIDTH, str);
533
534                 //check if the input is valid
535                 string const input = getString(column_options_->input_column_width);
536                 if (!input.empty() && !isValidLength(input) && !isStrDbl(input)) {
537                         postWarning(_("Invalid Length (valid example: 10mm)"));
538                         return ButtonPolicy::SMI_INVALID;
539                 }
540
541                 update(); // update for alignment
542                 return ButtonPolicy::SMI_VALID;
543         }
544
545         if ((ob == cell_options_->input_mcolumn_width) ||
546             (ob == cell_options_->choice_value_mcolumn_width)) {
547                 string const str =
548                         getLengthFromWidgets(cell_options_->input_mcolumn_width,
549                                              cell_options_->choice_value_mcolumn_width);
550                 controller().set(LyXTabular::SET_MPWIDTH, str);
551
552                 //check if the input is valid
553                 string const input = getString(cell_options_->input_mcolumn_width);
554                 if (!input.empty() && !isValidLength(input) && !isStrDbl(input)) {
555                         postWarning(_("Invalid Length (valid example: 10mm)"));
556                         return ButtonPolicy::SMI_INVALID;
557                 }
558                 update(); // update for alignment
559                 return ButtonPolicy::SMI_VALID;
560         }
561
562         if (ob == tabular_options_->button_append_row)
563                 num = LyXTabular::APPEND_ROW;
564         else if (ob == tabular_options_->button_append_column)
565                 num = LyXTabular::APPEND_COLUMN;
566         else if (ob == tabular_options_->button_delete_row)
567                 num = LyXTabular::DELETE_ROW;
568         else if (ob == tabular_options_->button_delete_column)
569                 num = LyXTabular::DELETE_COLUMN;
570         else if (ob == tabular_options_->button_set_borders)
571                 num = LyXTabular::SET_ALL_LINES;
572         else if (ob == tabular_options_->button_unset_borders)
573                 num = LyXTabular::UNSET_ALL_LINES;
574         else if (ob == column_options_->check_border_top)
575                 num = LyXTabular::TOGGLE_LINE_TOP;
576         else if (ob == column_options_->check_border_bottom)
577                 num = LyXTabular::TOGGLE_LINE_BOTTOM;
578         else if (ob == column_options_->check_border_left)
579                 num = LyXTabular::TOGGLE_LINE_LEFT;
580         else if (ob == column_options_->check_border_right)
581                 num = LyXTabular::TOGGLE_LINE_RIGHT;
582         else if (ob == column_options_->radio_align_left)
583                 num = LyXTabular::ALIGN_LEFT;
584         else if (ob == column_options_->radio_align_right)
585                 num = LyXTabular::ALIGN_RIGHT;
586         else if (ob == column_options_->radio_align_center)
587                 num = LyXTabular::ALIGN_CENTER;
588         else if (ob == column_options_->radio_align_block)
589                 num = LyXTabular::ALIGN_BLOCK;
590         else if (ob == column_options_->radio_valign_top)
591                 num = LyXTabular::VALIGN_TOP;
592         else if (ob == column_options_->radio_valign_bottom)
593                 num = LyXTabular::VALIGN_BOTTOM;
594         else if (ob == column_options_->radio_valign_center)
595                 num = LyXTabular::VALIGN_CENTER;
596         else if (ob == cell_options_->check_multicolumn)
597                 num = LyXTabular::MULTICOLUMN;
598         else if (ob == tabular_options_->check_longtable) {
599                 if (fl_get_button(tabular_options_->check_longtable))
600                         num = LyXTabular::SET_LONGTABULAR;
601                 else
602                         num = LyXTabular::UNSET_LONGTABULAR;
603         } else if (ob == tabular_options_->check_rotate_tabular) {
604                 s = fl_get_button(tabular_options_->check_rotate_tabular);
605                 if (s)
606                         num = LyXTabular::SET_ROTATE_TABULAR;
607                 else
608                         num = LyXTabular::UNSET_ROTATE_TABULAR;
609         } else if (ob == cell_options_->check_rotate_cell) {
610                 s = fl_get_button(cell_options_->check_rotate_cell);
611                 if (s)
612                         num = LyXTabular::SET_ROTATE_CELL;
613                 else
614                         num = LyXTabular::UNSET_ROTATE_CELL;
615         } else if (ob == cell_options_->check_useminipage) {
616                 num = LyXTabular::SET_USEBOX;
617                 special = "2";
618         } else if ((ob == longtable_options_->check_lt_firsthead) ||
619                    (ob == longtable_options_->check_1head_2border_above) ||
620                    (ob == longtable_options_->check_1head_2border_below) ||
621                    (ob == longtable_options_->check_1head_empty) ||
622                    (ob == longtable_options_->check_lt_head) ||
623                    (ob == longtable_options_->check_head_2border_above) ||
624                    (ob == longtable_options_->check_head_2border_below) ||
625                    (ob == longtable_options_->check_lt_foot) ||
626                    (ob == longtable_options_->check_foot_2border_above) ||
627                    (ob == longtable_options_->check_foot_2border_below) ||
628                    (ob == longtable_options_->check_lt_lastfoot) ||
629                    (ob == longtable_options_->check_lastfoot_2border_above) ||
630                    (ob == longtable_options_->check_lastfoot_2border_below) ||
631                    (ob == longtable_options_->check_lastfoot_empty)) {
632                 num = static_cast<LyXTabular::Feature>(checkLongtableOptions(ob, special));
633         } else if (ob == longtable_options_->check_lt_newpage) {
634                 num = LyXTabular::SET_LTNEWPAGE;
635         } else if (ob == column_options_->input_special_alignment) {
636                 special = getString(column_options_->input_special_alignment);
637                 num = LyXTabular::SET_SPECIAL_COLUMN;
638         } else if (ob == cell_options_->input_special_multialign) {
639                 special = getString(cell_options_->input_special_multialign);
640                 num = LyXTabular::SET_SPECIAL_MULTI;
641         } else if (ob == cell_options_->check_border_top)
642                 num = LyXTabular::M_TOGGLE_LINE_TOP;
643         else if (ob == cell_options_->check_border_bottom)
644                 num = LyXTabular::M_TOGGLE_LINE_BOTTOM;
645         else if (ob == cell_options_->check_border_left)
646                 num = LyXTabular::M_TOGGLE_LINE_LEFT;
647         else if (ob == cell_options_->check_border_right)
648                 num = LyXTabular::M_TOGGLE_LINE_RIGHT;
649         else if (ob == cell_options_->radio_align_left)
650                 num = LyXTabular::M_ALIGN_LEFT;
651         else if (ob == cell_options_->radio_align_right)
652                 num = LyXTabular::M_ALIGN_RIGHT;
653         else if (ob == cell_options_->radio_align_center)
654                 num = LyXTabular::M_ALIGN_CENTER;
655         else if (ob == cell_options_->radio_valign_top)
656                 num = LyXTabular::M_VALIGN_TOP;
657         else if (ob == cell_options_->radio_valign_bottom)
658                 num = LyXTabular::M_VALIGN_BOTTOM;
659         else if (ob == cell_options_->radio_valign_center)
660                 num = LyXTabular::M_VALIGN_CENTER;
661         else
662                 return ButtonPolicy::SMI_VALID;
663
664         controller().set(num, special);
665         update();
666
667         return ButtonPolicy::SMI_VALID;
668 }
669
670
671 int FormTabular::checkLongtableOptions(FL_OBJECT * ob, string & special)
672 {
673         bool flag = fl_get_button(ob);
674         if ((ob == longtable_options_->check_1head_2border_above) ||
675             (ob == longtable_options_->check_head_2border_above) ||
676             (ob == longtable_options_->check_foot_2border_above) ||
677             (ob == longtable_options_->check_lastfoot_2border_above)) {
678                 special = "dl_above";
679         } else if ((ob == longtable_options_->check_1head_2border_below) ||
680                    (ob == longtable_options_->check_head_2border_below) ||
681                    (ob == longtable_options_->check_foot_2border_below) ||
682                    (ob == longtable_options_->check_lastfoot_2border_below)) {
683                 special = "dl_below";
684         } else if ((ob == longtable_options_->check_1head_empty) ||
685                    (ob == longtable_options_->check_lastfoot_empty)) {
686                 special = "empty";
687         } else {
688                 special = "";
689         }
690         if ((ob == longtable_options_->check_lt_firsthead) ||
691             (ob == longtable_options_->check_1head_2border_above) ||
692             (ob == longtable_options_->check_1head_2border_below) ||
693             (ob == longtable_options_->check_1head_empty)) {
694                 return (flag ? LyXTabular::SET_LTFIRSTHEAD :
695                         LyXTabular::UNSET_LTFIRSTHEAD);
696         } else if ((ob == longtable_options_->check_lt_head) ||
697                            (ob == longtable_options_->check_head_2border_above) ||
698                            (ob == longtable_options_->check_head_2border_below)) {
699                 return (flag ? LyXTabular::SET_LTHEAD : LyXTabular::UNSET_LTHEAD);
700         } else if ((ob == longtable_options_->check_lt_foot) ||
701                    (ob == longtable_options_->check_foot_2border_above) ||
702                    (ob == longtable_options_->check_foot_2border_below)) {
703                 return (flag ? LyXTabular::SET_LTFOOT : LyXTabular::UNSET_LTFOOT);
704         } else if ((ob == longtable_options_->check_lt_lastfoot) ||
705                    (ob == longtable_options_->check_lastfoot_2border_above) ||
706                    (ob == longtable_options_->check_lastfoot_2border_below) ||
707                    (ob == longtable_options_->check_lastfoot_empty)) {
708                 return (flag ? LyXTabular::SET_LTLASTFOOT :
709                         LyXTabular::UNSET_LTLASTFOOT);
710         }
711
712         return LyXTabular::LAST_ACTION;
713 }