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