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