]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormTabular.C
This file is part of LyX, the document processor.
[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         // Create the contents of the unit choices
149         // Don't include the "%" terms...
150         vector<string> units_vec = getLatexUnits();
151         vector<string>::iterator ret =
152                 remove_if(units_vec.begin(), units_vec.end(),
153                           bind2nd(contains_functor(), "%"));
154         units_vec.erase(ret, units_vec.end());
155
156         string units = getStringFromVector(units_vec, "|");
157
158         fl_addto_choice(column_options_->choice_value_column_width,
159                         units.c_str());
160         fl_addto_choice(cell_options_->choice_value_mcolumn_width,
161                         units.c_str());
162 }
163
164
165 void FormTabular::update()
166 {
167         if (closing_)
168                 return;
169
170         if (!inset_ || !inset_->tabular.get())
171                 return;
172
173         LyXTabular * tabular = inset_->tabular.get();
174         int align;
175         char buf[12];
176         LyXLength pwidth;
177         string special;
178
179         int cell = inset_->getActCell();
180         actCell_ = cell;
181         int column = tabular->column_of_cell(cell) + 1;
182         clearMessage();
183         fl_activate_object(column_options_->input_special_alignment);
184         fl_activate_object(cell_options_->input_special_multialign);
185         fl_activate_object(column_options_->input_column_width);
186         fl_activate_object(column_options_->choice_value_column_width);
187         sprintf(buf, "%d", column);
188         fl_set_input(dialog_->input_tabular_column, buf);
189         fl_deactivate_object(dialog_->input_tabular_column);
190         int row = tabular->row_of_cell(cell);
191         sprintf(buf, "%d", row + 1);
192         fl_set_input(dialog_->input_tabular_row, buf);
193         fl_deactivate_object(dialog_->input_tabular_row);
194         if (tabular->IsMultiColumn(cell)) {
195                 fl_set_button(cell_options_->check_multicolumn, 1);
196                 fl_set_button(cell_options_->check_border_top,
197                               tabular->TopLine(cell)?1:0);
198                 setEnabled(cell_options_->check_border_top, true);
199                 fl_set_button(cell_options_->check_border_bottom,
200                               tabular->BottomLine(cell)?1:0);
201                 setEnabled(cell_options_->check_border_bottom, true);
202                 // pay attention to left/right lines they are only allowed
203                 // to set if we are in first/last cell of row or if the left/right
204                 // cell is also a multicolumn.
205                 if (tabular->IsFirstCellInRow(cell) ||
206                     tabular->IsMultiColumn(cell-1)) {
207                         fl_set_button(cell_options_->check_border_left,
208                                       tabular->LeftLine(cell)?1:0);
209                         setEnabled(cell_options_->check_border_left, true);
210                 } else {
211                         fl_set_button(cell_options_->check_border_left, 0);
212                         setEnabled(cell_options_->check_border_left, false);
213                 }
214                 if (tabular->IsLastCellInRow(cell) ||
215                     tabular->IsMultiColumn(cell+1)) {
216                         fl_set_button(cell_options_->check_border_right,
217                                       tabular->RightLine(cell)?1:0);
218                         setEnabled(cell_options_->check_border_right, true);
219                 } else {
220                         fl_set_button(cell_options_->check_border_right, 0);
221                         setEnabled(cell_options_->check_border_right, false);
222                 }
223                 pwidth = tabular->GetMColumnPWidth(cell);
224                 align = tabular->GetAlignment(cell);
225                 if (!pwidth.zero() || (align == LYX_ALIGN_LEFT))
226                         fl_set_button(cell_options_->radio_align_left, 1);
227                 else if (align == LYX_ALIGN_RIGHT)
228                         fl_set_button(cell_options_->radio_align_right, 1);
229                 else
230                         fl_set_button(cell_options_->radio_align_center, 1);
231
232                 align = tabular->GetVAlignment(cell);
233                 fl_set_button(cell_options_->radio_valign_top, 0);
234                 fl_set_button(cell_options_->radio_valign_bottom, 0);
235                 fl_set_button(cell_options_->radio_valign_center, 0);
236                 if (pwidth.zero() || (align == LyXTabular::LYX_VALIGN_CENTER))
237                         fl_set_button(cell_options_->radio_valign_center, 1);
238                 else if (align == LyXTabular::LYX_VALIGN_BOTTOM)
239                         fl_set_button(cell_options_->radio_valign_bottom, 1);
240                 else
241                         fl_set_button(cell_options_->radio_valign_top, 1);
242
243                 special = tabular->GetAlignSpecial(cell, LyXTabular::SET_SPECIAL_MULTI);
244                 fl_set_input(cell_options_->input_special_multialign, special.c_str());
245                 bool const metric = lyxrc.default_papersize > 3;
246                 string const default_unit = metric ? "cm" : "in";
247                 updateWidgetsFromLength(cell_options_->input_mcolumn_width,
248                                         cell_options_->choice_value_mcolumn_width,
249                                         pwidth, default_unit);
250
251                 if (!lv_.buffer()->isReadonly()) {
252                         setEnabled(cell_options_->input_special_multialign, true);
253                         setEnabled(cell_options_->input_mcolumn_width, true);
254                         setEnabled(cell_options_->choice_value_mcolumn_width, true);
255                 }
256
257                 setEnabled(cell_options_->radio_valign_top,    !pwidth.zero());
258                 setEnabled(cell_options_->radio_valign_bottom, !pwidth.zero());
259                 setEnabled(cell_options_->radio_valign_center, !pwidth.zero());
260
261                 setEnabled(cell_options_->radio_align_left,   pwidth.zero());
262                 setEnabled(cell_options_->radio_align_right,  pwidth.zero());
263                 setEnabled(cell_options_->radio_align_center, pwidth.zero());
264         } else {
265                 fl_set_button(cell_options_->check_multicolumn, 0);
266
267                 fl_set_button(cell_options_->check_border_top, 0);
268                 setEnabled(cell_options_->check_border_top, false);
269
270                 fl_set_button(cell_options_->check_border_bottom, 0);
271                 setEnabled(cell_options_->check_border_bottom, false);
272
273                 fl_set_button(cell_options_->check_border_left, 0);
274                 setEnabled(cell_options_->check_border_left, false);
275
276                 fl_set_button(cell_options_->check_border_right, 0);
277                 setEnabled(cell_options_->check_border_right, false);
278
279                 fl_set_button(cell_options_->radio_align_left, 0);
280                 setEnabled(cell_options_->radio_align_left, false);
281
282                 fl_set_button(cell_options_->radio_align_right, 0);
283                 setEnabled(cell_options_->radio_align_right, false);
284
285                 fl_set_button(cell_options_->radio_align_center, 0);
286                 setEnabled(cell_options_->radio_align_center, false);
287
288                 fl_set_button(cell_options_->radio_valign_top, 0);
289                 setEnabled(cell_options_->radio_valign_top, false);
290
291                 fl_set_button(cell_options_->radio_valign_bottom, 0);
292                 setEnabled(cell_options_->radio_valign_bottom, false);
293
294                 fl_set_button(cell_options_->radio_valign_center, 0);
295                 setEnabled(cell_options_->radio_valign_center, false);
296
297                 fl_set_input(cell_options_->input_special_multialign, "");
298                 setEnabled(cell_options_->input_special_multialign, false);
299
300                 fl_set_input(cell_options_->input_mcolumn_width, "");
301                 setEnabled(cell_options_->input_mcolumn_width, false);
302                 setEnabled(cell_options_->choice_value_mcolumn_width, false);
303         }
304         if (tabular->GetRotateCell(cell))
305                 fl_set_button(cell_options_->check_rotate_cell, 1);
306         else
307                 fl_set_button(cell_options_->check_rotate_cell, 0);
308         if (tabular->TopLine(cell, true))
309                 fl_set_button(column_options_->check_border_top, 1);
310         else
311                 fl_set_button(column_options_->check_border_top, 0);
312         if (tabular->BottomLine(cell, true))
313                 fl_set_button(column_options_->check_border_bottom, 1);
314         else
315                 fl_set_button(column_options_->check_border_bottom, 0);
316         if (tabular->LeftLine(cell, true))
317                 fl_set_button(column_options_->check_border_left, 1);
318         else
319                 fl_set_button(column_options_->check_border_left, 0);
320         if (tabular->RightLine(cell, true))
321                 fl_set_button(column_options_->check_border_right, 1);
322         else
323                 fl_set_button(column_options_->check_border_right, 0);
324         special = tabular->GetAlignSpecial(cell, LyXTabular::SET_SPECIAL_COLUMN);
325         fl_set_input(column_options_->input_special_alignment, special.c_str());
326
327         bool const isReadonly = lv_.buffer()->isReadonly();
328         setEnabled(column_options_->input_special_alignment, !isReadonly);
329
330         pwidth = tabular->GetColumnPWidth(cell);
331         bool const metric = lyxrc.default_papersize > 3;
332         string const default_unit = metric ? "cm" : "in";
333         updateWidgetsFromLength(column_options_->input_column_width,
334                                 column_options_->choice_value_column_width,
335                                 pwidth, default_unit);
336         setEnabled(column_options_->input_column_width, !isReadonly);
337         setEnabled(column_options_->choice_value_column_width, !isReadonly);
338
339         setEnabled(cell_options_->check_useminipage, !pwidth.zero());
340         if (!pwidth.zero()) {
341                 if (tabular->GetUsebox(cell) == 2)
342                         fl_set_button(cell_options_->check_useminipage, 1);
343                 else
344                         fl_set_button(cell_options_->check_useminipage, 0);
345         } else {
346                 fl_set_button(cell_options_->check_useminipage, 0);
347         }
348         align = tabular->GetAlignment(cell, true);
349         fl_set_button(column_options_->radio_align_left, 0);
350         fl_set_button(column_options_->radio_align_right, 0);
351         fl_set_button(column_options_->radio_align_center, 0);
352         if (!pwidth.zero() || (align == LYX_ALIGN_LEFT))
353                 fl_set_button(column_options_->radio_align_left, 1);
354         else if (align == LYX_ALIGN_RIGHT)
355                 fl_set_button(column_options_->radio_align_right, 1);
356         else
357                 fl_set_button(column_options_->radio_align_center, 1);
358         align = tabular->GetVAlignment(cell, true);
359         fl_set_button(column_options_->radio_valign_top, 0);
360         fl_set_button(column_options_->radio_valign_bottom, 0);
361         fl_set_button(column_options_->radio_valign_center, 0);
362         if (pwidth.zero() || (align == LyXTabular::LYX_VALIGN_CENTER))
363                 fl_set_button(column_options_->radio_valign_center, 1);
364         else if (align == LyXTabular::LYX_VALIGN_BOTTOM)
365                 fl_set_button(column_options_->radio_valign_bottom, 1);
366         else
367                 fl_set_button(column_options_->radio_valign_top, 1);
368
369         setEnabled(column_options_->radio_align_left,   pwidth.zero());
370         setEnabled(column_options_->radio_align_right,  pwidth.zero());
371         setEnabled(column_options_->radio_align_center, pwidth.zero());
372
373         setEnabled(column_options_->radio_valign_top,    !pwidth.zero());
374         setEnabled(column_options_->radio_valign_bottom, !pwidth.zero());
375         setEnabled(column_options_->radio_valign_center, !pwidth.zero());
376
377         fl_set_button(tabular_options_->check_longtable,
378                       tabular->IsLongTabular());
379
380         bool const enable = tabular->IsLongTabular();
381
382         setEnabled(longtable_options_->check_lt_firsthead, enable);
383         setEnabled(longtable_options_->check_1head_2border_above, enable);
384         setEnabled(longtable_options_->check_1head_2border_below, enable);
385         setEnabled(longtable_options_->check_1head_empty, enable);
386         setEnabled(longtable_options_->check_lt_head, enable);
387         setEnabled(longtable_options_->check_head_2border_above, enable);
388         setEnabled(longtable_options_->check_head_2border_below, enable);
389         setEnabled(longtable_options_->check_lt_foot, enable);
390         setEnabled(longtable_options_->check_foot_2border_above, enable);
391         setEnabled(longtable_options_->check_foot_2border_below, enable);
392         setEnabled(longtable_options_->check_lt_lastfoot, enable);
393         setEnabled(longtable_options_->check_lastfoot_2border_above, enable);
394         setEnabled(longtable_options_->check_lastfoot_2border_below, enable);
395         setEnabled(longtable_options_->check_lastfoot_empty, enable);
396         setEnabled(longtable_options_->check_lt_newpage, enable);
397
398         if (enable) {
399                 LyXTabular::ltType ltt;
400                 bool use_empty;
401                 bool row_set = tabular->GetRowOfLTHead(row, ltt);
402                 fl_set_button(longtable_options_->check_lt_head, row_set);
403                 if (ltt.set) {
404                         fl_set_button(longtable_options_->check_head_2border_above,
405                                       ltt.topDL);
406                         fl_set_button(longtable_options_->check_head_2border_above,
407                                       ltt.topDL);
408                         use_empty = true;
409                 } else {
410                         setEnabled(longtable_options_->check_head_2border_above, 0);
411                         setEnabled(longtable_options_->check_head_2border_below, 0);
412                         fl_set_button(longtable_options_->check_head_2border_above,0);
413                         fl_set_button(longtable_options_->check_head_2border_above,0);
414                         fl_set_button(longtable_options_->check_1head_empty,0);
415                         setEnabled(longtable_options_->check_1head_empty, 0);
416                         use_empty = false;
417                 }
418                 //
419                 row_set = tabular->GetRowOfLTFirstHead(row, ltt);
420                 fl_set_button(longtable_options_->check_lt_firsthead, row_set);
421                 if (ltt.set && (!ltt.empty || !use_empty)) {
422                         fl_set_button(longtable_options_->check_1head_2border_above,
423                                       ltt.topDL);
424                         fl_set_button(longtable_options_->check_1head_2border_above,
425                                       ltt.topDL);
426                 } else {
427                         setEnabled(longtable_options_->check_1head_2border_above, 0);
428                         setEnabled(longtable_options_->check_1head_2border_below, 0);
429                         fl_set_button(longtable_options_->check_1head_2border_above,0);
430                         fl_set_button(longtable_options_->check_1head_2border_above,0);
431                         if (use_empty) {
432                                 fl_set_button(longtable_options_->check_1head_empty,ltt.empty);
433                                 if (ltt.empty)
434                                         setEnabled(longtable_options_->check_lt_firsthead, 0);
435                         }
436                 }
437                 //
438                 row_set = tabular->GetRowOfLTFoot(row, ltt);
439                 fl_set_button(longtable_options_->check_lt_foot, row_set);
440                 if (ltt.set) {
441                         fl_set_button(longtable_options_->check_foot_2border_above,
442                                       ltt.topDL);
443                         fl_set_button(longtable_options_->check_foot_2border_above,
444                                       ltt.topDL);
445                         use_empty = true;
446                 } else {
447                         setEnabled(longtable_options_->check_foot_2border_above, 0);
448                         setEnabled(longtable_options_->check_foot_2border_below, 0);
449                         fl_set_button(longtable_options_->check_foot_2border_above,0);
450                         fl_set_button(longtable_options_->check_foot_2border_above,0);
451                         fl_set_button(longtable_options_->check_lastfoot_empty, 0);
452                         setEnabled(longtable_options_->check_lastfoot_empty, 0);
453                         use_empty = false;
454                 }
455                 //
456                 row_set = tabular->GetRowOfLTLastFoot(row, ltt);
457                 fl_set_button(longtable_options_->check_lt_lastfoot, row_set);
458                 if (ltt.set && (!ltt.empty || !use_empty)) {
459                         fl_set_button(longtable_options_->check_lastfoot_2border_above,
460                                       ltt.topDL);
461                         fl_set_button(longtable_options_->check_lastfoot_2border_above,
462                                       ltt.topDL);
463                 } else {
464                         setEnabled(longtable_options_->check_lastfoot_2border_above,0);
465                         setEnabled(longtable_options_->check_lastfoot_2border_below,0);
466                         fl_set_button(longtable_options_->check_lastfoot_2border_above, 0);
467                         fl_set_button(longtable_options_->check_lastfoot_2border_above, 0);
468                         if (use_empty) {
469                                 fl_set_button(longtable_options_->check_lastfoot_empty,
470                                               ltt.empty);
471                                 if (ltt.empty)
472                                         setEnabled(longtable_options_->check_lt_lastfoot, 0);
473                         }
474                 }
475                 fl_set_button(longtable_options_->check_lt_newpage,
476                               tabular->GetLTNewPage(row));
477         } else {
478                 fl_set_button(longtable_options_->check_lt_firsthead, 0);
479                 fl_set_button(longtable_options_->check_1head_2border_above, 0);
480                 fl_set_button(longtable_options_->check_1head_2border_above, 0);
481                 fl_set_button(longtable_options_->check_1head_empty, 0);
482                 fl_set_button(longtable_options_->check_lt_head, 0);
483                 fl_set_button(longtable_options_->check_head_2border_above, 0);
484                 fl_set_button(longtable_options_->check_head_2border_above, 0);
485                 fl_set_button(longtable_options_->check_lt_foot, 0);
486                 fl_set_button(longtable_options_->check_foot_2border_above, 0);
487                 fl_set_button(longtable_options_->check_foot_2border_above, 0);
488                 fl_set_button(longtable_options_->check_lt_lastfoot, 0);
489                 fl_set_button(longtable_options_->check_lastfoot_2border_above, 0);
490                 fl_set_button(longtable_options_->check_lastfoot_2border_above, 0);
491                 fl_set_button(longtable_options_->check_lastfoot_empty, 0);
492                 fl_set_button(longtable_options_->check_lt_newpage, 0);
493         }
494         fl_set_button(tabular_options_->check_rotate_tabular,
495                       tabular->GetRotateTabular());
496 }
497
498
499 bool FormTabular::input(FL_OBJECT * ob, long)
500 {
501         if (!inset_)
502                 return false;
503
504         int s;
505         LyXTabular::Feature num = LyXTabular::LAST_ACTION;
506         string special;;
507
508         int cell = inset_->getActCell();
509
510         // ugly hack to auto-apply the stuff that hasn't been
511         // yet. don't let this continue to exist ...
512         if (ob == dialog_->button_close) {
513                 closing_ = true;
514                 LyXTabular * tabular = inset_->tabular.get();
515                 string str1 =
516                         getLengthFromWidgets(column_options_->input_column_width,
517                                              column_options_->choice_value_column_width);
518                 string str2;
519                 LyXLength llen = tabular->GetColumnPWidth(cell);
520                 if (!llen.zero())
521                         str2 = llen.asString();
522                 if (str1 != str2)
523                         input(column_options_->input_column_width, 0);
524                 str1 = getLengthFromWidgets(cell_options_->input_mcolumn_width,
525                                             cell_options_->choice_value_mcolumn_width);
526                 llen = tabular->GetMColumnPWidth(cell);
527                 if (llen.zero())
528                         str2 = "";
529                 else
530                         str2 = llen.asString();
531                 if (str1 != str2)
532                         input(cell_options_->input_mcolumn_width, 0);
533                 str1 = fl_get_input(column_options_->input_special_alignment);
534                 str2 = tabular->GetAlignSpecial(cell, LyXTabular::SET_SPECIAL_COLUMN);
535                 if (str1 != str2)
536                         input(column_options_->input_special_alignment, 0);
537                 str1 = fl_get_input(cell_options_->input_special_multialign);
538                 str2 = tabular->GetAlignSpecial(cell, LyXTabular::SET_SPECIAL_MULTI);
539                 if (str1 != str2)
540                         input(cell_options_->input_special_multialign, 0);
541                 closing_ = false;
542                 ok();
543                 return true;
544         }
545
546         if (actCell_ != cell) {
547                 update();
548                 postWarning(_("Wrong Cursor position, updated window"));
549                 return false;
550         }
551         // No point in processing directives that you can't do anything with
552         // anyhow, so exit now if the buffer is read-only.
553         if (lv_.buffer()->isReadonly()) {
554                 update();
555                 return false;
556         }
557         if ((ob == column_options_->input_column_width) ||
558             (ob == column_options_->choice_value_column_width)) {
559                 string const str =
560                         getLengthFromWidgets(column_options_->input_column_width,
561                                              column_options_->choice_value_column_width);
562                 inset_->tabularFeatures(lv_.view().get(), LyXTabular::SET_PWIDTH, str);
563
564                 //check if the input is valid
565                 string const input =
566                         fl_get_input(column_options_->input_column_width);
567                 if (!input.empty() && !isValidLength(input) && !isStrDbl(input)) {
568                         postWarning(_("Invalid Length (valid example: 10mm)"));
569                         return false;
570                 }
571
572                 update(); // update for alignment
573                 return true;
574         }
575
576         if ((ob == cell_options_->input_mcolumn_width) ||
577             (ob == cell_options_->choice_value_mcolumn_width)) {
578                 string const str =
579                         getLengthFromWidgets(cell_options_->input_mcolumn_width,
580                                              cell_options_->choice_value_mcolumn_width);
581                 inset_->tabularFeatures(lv_.view().get(), LyXTabular::SET_MPWIDTH, str);
582
583                 //check if the input is valid
584                 string const input =
585                         fl_get_input(cell_options_->input_mcolumn_width);
586                 if (!input.empty() && !isValidLength(input) && !isStrDbl(input)) {
587                         postWarning(_("Invalid Length (valid example: 10mm)"));
588                         return false;
589                 }
590                 update(); // update for alignment
591                 return true;
592         }
593
594         if (ob == tabular_options_->button_append_row)
595                 num = LyXTabular::APPEND_ROW;
596         else if (ob == tabular_options_->button_append_column)
597                 num = LyXTabular::APPEND_COLUMN;
598         else if (ob == tabular_options_->button_delete_row)
599                 num = LyXTabular::DELETE_ROW;
600         else if (ob == tabular_options_->button_delete_column)
601                 num = LyXTabular::DELETE_COLUMN;
602         else if (ob == tabular_options_->button_set_borders)
603                 num = LyXTabular::SET_ALL_LINES;
604         else if (ob == tabular_options_->button_unset_borders)
605                 num = LyXTabular::UNSET_ALL_LINES;
606         else if (ob == column_options_->check_border_top)
607                 num = LyXTabular::TOGGLE_LINE_TOP;
608         else if (ob == column_options_->check_border_bottom)
609                 num = LyXTabular::TOGGLE_LINE_BOTTOM;
610         else if (ob == column_options_->check_border_left)
611                 num = LyXTabular::TOGGLE_LINE_LEFT;
612         else if (ob == column_options_->check_border_right)
613                 num = LyXTabular::TOGGLE_LINE_RIGHT;
614         else if (ob == column_options_->radio_align_left)
615                 num = LyXTabular::ALIGN_LEFT;
616         else if (ob == column_options_->radio_align_right)
617                 num = LyXTabular::ALIGN_RIGHT;
618         else if (ob == column_options_->radio_align_center)
619                 num = LyXTabular::ALIGN_CENTER;
620         else if (ob == column_options_->radio_valign_top)
621                 num = LyXTabular::VALIGN_TOP;
622         else if (ob == column_options_->radio_valign_bottom)
623                 num = LyXTabular::VALIGN_BOTTOM;
624         else if (ob == column_options_->radio_valign_center)
625                 num = LyXTabular::VALIGN_CENTER;
626         else if (ob == cell_options_->check_multicolumn)
627                 num = LyXTabular::MULTICOLUMN;
628         else if (ob == tabular_options_->check_longtable) {
629                 if (fl_get_button(tabular_options_->check_longtable))
630                         num = LyXTabular::SET_LONGTABULAR;
631                 else
632                         num = LyXTabular::UNSET_LONGTABULAR;
633         } else if (ob == tabular_options_->check_rotate_tabular) {
634                 s = fl_get_button(tabular_options_->check_rotate_tabular);
635                 if (s)
636                         num = LyXTabular::SET_ROTATE_TABULAR;
637                 else
638                         num = LyXTabular::UNSET_ROTATE_TABULAR;
639         } else if (ob == cell_options_->check_rotate_cell) {
640                 s = fl_get_button(cell_options_->check_rotate_cell);
641                 if (s)
642                         num = LyXTabular::SET_ROTATE_CELL;
643                 else
644                         num = LyXTabular::UNSET_ROTATE_CELL;
645         } else if (ob == cell_options_->check_useminipage) {
646                 num = LyXTabular::SET_USEBOX;
647                 special = "2";
648         } else if ((ob == longtable_options_->check_lt_firsthead) ||
649                    (ob == longtable_options_->check_1head_2border_above) ||
650                    (ob == longtable_options_->check_1head_2border_below) ||
651                    (ob == longtable_options_->check_1head_empty) ||
652                    (ob == longtable_options_->check_lt_head) ||
653                    (ob == longtable_options_->check_head_2border_above) ||
654                    (ob == longtable_options_->check_head_2border_below) ||
655                    (ob == longtable_options_->check_lt_foot) ||
656                    (ob == longtable_options_->check_foot_2border_above) ||
657                    (ob == longtable_options_->check_foot_2border_below) ||
658                    (ob == longtable_options_->check_lt_lastfoot) ||
659                    (ob == longtable_options_->check_lastfoot_2border_above) ||
660                    (ob == longtable_options_->check_lastfoot_2border_below) ||
661                    (ob == longtable_options_->check_lastfoot_empty)) {
662                 num = static_cast<LyXTabular::Feature>(checkLongtableOptions(ob, special));
663         } else if (ob == longtable_options_->check_lt_newpage) {
664                 num = LyXTabular::SET_LTNEWPAGE;
665         } else if (ob == column_options_->input_special_alignment) {
666                 special = fl_get_input(column_options_->input_special_alignment);
667                 num = LyXTabular::SET_SPECIAL_COLUMN;
668         } else if (ob == cell_options_->input_special_multialign) {
669                 special = fl_get_input(cell_options_->input_special_multialign);
670                 num = LyXTabular::SET_SPECIAL_MULTI;
671         } else if (ob == cell_options_->check_border_top)
672                 num = LyXTabular::M_TOGGLE_LINE_TOP;
673         else if (ob == cell_options_->check_border_bottom)
674                 num = LyXTabular::M_TOGGLE_LINE_BOTTOM;
675         else if (ob == cell_options_->check_border_left)
676                 num = LyXTabular::M_TOGGLE_LINE_LEFT;
677         else if (ob == cell_options_->check_border_right)
678                 num = LyXTabular::M_TOGGLE_LINE_RIGHT;
679         else if (ob == cell_options_->radio_align_left)
680                 num = LyXTabular::M_ALIGN_LEFT;
681         else if (ob == cell_options_->radio_align_right)
682                 num = LyXTabular::M_ALIGN_RIGHT;
683         else if (ob == cell_options_->radio_align_center)
684                 num = LyXTabular::M_ALIGN_CENTER;
685         else if (ob == cell_options_->radio_valign_top)
686                 num = LyXTabular::M_VALIGN_TOP;
687         else if (ob == cell_options_->radio_valign_bottom)
688                 num = LyXTabular::M_VALIGN_BOTTOM;
689         else if (ob == cell_options_->radio_valign_center)
690                 num = LyXTabular::M_VALIGN_CENTER;
691         else
692                 return false;
693
694         inset_->tabularFeatures(lv_.view().get(), num, special);
695         update();
696
697         return true;
698 }
699
700 int FormTabular::checkLongtableOptions(FL_OBJECT * ob, string & special)
701 {
702         bool flag = fl_get_button(ob);
703         if ((ob == longtable_options_->check_1head_2border_above) ||
704             (ob == longtable_options_->check_head_2border_above) ||
705             (ob == longtable_options_->check_foot_2border_above) ||
706             (ob == longtable_options_->check_lastfoot_2border_above)) {
707                 special = "dl_above";
708         } else if ((ob == longtable_options_->check_1head_2border_below) ||
709                    (ob == longtable_options_->check_head_2border_below) ||
710                    (ob == longtable_options_->check_foot_2border_below) ||
711                    (ob == longtable_options_->check_lastfoot_2border_below)) {
712                 special = "dl_below";
713         } else if ((ob == longtable_options_->check_1head_empty) ||
714                    (ob == longtable_options_->check_lastfoot_empty)) {
715                 special = "empty";
716         } else {
717                 special = "";
718         }
719         if ((ob == longtable_options_->check_lt_firsthead) ||
720             (ob == longtable_options_->check_1head_2border_above) ||
721             (ob == longtable_options_->check_1head_2border_below) ||
722             (ob == longtable_options_->check_1head_empty)) {
723                 return (flag ? LyXTabular::SET_LTFIRSTHEAD :
724                         LyXTabular::UNSET_LTFIRSTHEAD);
725         } else if ((ob == longtable_options_->check_lt_head) ||
726                            (ob == longtable_options_->check_head_2border_above) ||
727                            (ob == longtable_options_->check_head_2border_below)) {
728                 return (flag ? LyXTabular::SET_LTHEAD : LyXTabular::UNSET_LTHEAD);
729         } else if ((ob == longtable_options_->check_lt_foot) ||
730                    (ob == longtable_options_->check_foot_2border_above) ||
731                    (ob == longtable_options_->check_foot_2border_below)) {
732                 return (flag ? LyXTabular::SET_LTFOOT : LyXTabular::UNSET_LTFOOT);
733         } else if ((ob == longtable_options_->check_lt_lastfoot) ||
734                    (ob == longtable_options_->check_lastfoot_2border_above) ||
735                    (ob == longtable_options_->check_lastfoot_2border_below) ||
736                    (ob == longtable_options_->check_lastfoot_empty)) {
737                 return (flag ? LyXTabular::SET_LTLASTFOOT :
738                         LyXTabular::UNSET_LTLASTFOOT);
739         }
740
741         return LyXTabular::LAST_ACTION;
742 }