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