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