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