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