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