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