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