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