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