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