]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormTabular.C
(Rob Lahaye): changes to the xforms tabular dialog.
[lyx.git] / src / frontends / xforms / FormTabular.C
1 /**
2  * \file FormTabular.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Jürgen Vigna
7  *
8  * Full author contact details are available in file CREDITS
9  */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "debug.h"
18
19 #include "FormTabular.h"
20 #include "forms/form_tabular.h"
21 #include "frontends/LyXView.h"
22 #include "buffer.h"
23 #include "xforms_helpers.h"
24 #include "lyxrc.h" // to set the default length values
25 #include "helper_funcs.h"
26 #include "input_validators.h"
27
28 #include "insets/insettabular.h"
29
30 #include "support/lstrings.h"
31
32 #include <boost/bind.hpp>
33
34 #include <functional>
35 #include FORMS_H_LOCATION
36
37
38 using std::vector;
39 using std::bind2nd;
40 using std::remove_if;
41
42
43 FormTabular::FormTabular(LyXView & lv, Dialogs & d)
44         : FormInset(lv, d, _("Tabular Layout")),
45           inset_(0), actCell_(-1), closing_(false)
46 {
47 }
48
49
50 void FormTabular::redraw()
51 {
52         if (form() && form()->visible)
53                 fl_redraw_form(form());
54         else
55                 return;
56
57         FL_FORM * outer_form = fl_get_active_folder(dialog_->tabfolder);
58         if (outer_form && outer_form->visible)
59                 fl_redraw_form(outer_form);
60 }
61
62
63 FL_FORM * FormTabular::form() const
64 {
65         if (dialog_.get())
66                 return dialog_->form;
67         return 0;
68 }
69
70
71 void FormTabular::disconnect()
72 {
73         inset_ = 0;
74         FormInset::disconnect();
75 }
76
77
78 void FormTabular::showInset(InsetTabular * inset)
79 {
80         if (inset == 0) return;
81
82         // If connected to another inset, disconnect from it.
83         if (inset_ != inset) {
84                 ih_.disconnect();
85                 ih_ = inset->hideDialog.connect(boost::bind(&FormTabular::hide, this));
86                 inset_ = inset;
87         }
88
89         show();
90 }
91
92
93 void FormTabular::updateInset(InsetTabular * inset)
94 {
95         if (inset == 0 || inset_ == 0) return;
96
97         // If connected to another inset, disconnect from it.
98         if (inset_ != inset) {
99                 ih_.disconnect();
100                 ih_ = inset->hideDialog.connect(boost::bind(&FormTabular::hide, this));
101                 inset_ = inset;
102         }
103
104         update();
105 }
106
107
108 void FormTabular::build()
109 {
110         dialog_.reset(build_tabular(this));
111
112         // Allow the base class to control messages
113         setMessageWidget(dialog_->text_warning);
114
115         // trigger an input event for cut&paste with middle mouse button.
116         setPrehandler(dialog_->input_tabular_column);
117         setPrehandler(dialog_->input_tabular_row);
118
119         // Create the contents of the unit choices; don't include the "%" terms.
120         vector<string> units_vec = getLatexUnits();
121         vector<string>::iterator ret =
122                 remove_if(units_vec.begin(), units_vec.end(),
123                           bind2nd(contains_functor(), "%"));
124         units_vec.erase(ret, units_vec.end());
125         string const units = getStringFromVector(units_vec, "|");
126
127         // tabular options form
128         tabular_options_.reset(build_tabular_options(this));
129
130         // column options form
131         column_options_.reset(build_tabular_column(this));
132
133         fl_set_input_return(column_options_->input_column_width,
134                             FL_RETURN_END);
135         fl_set_input_return(column_options_->input_special_alignment,
136                             FL_RETURN_END);
137
138         // trigger an input event for cut&paste with middle mouse button.
139         setPrehandler(column_options_->input_column_width);
140         setPrehandler(column_options_->input_special_alignment);
141
142         fl_addto_choice(column_options_->choice_value_column_width,
143                         units.c_str());
144
145         // cell options form
146         cell_options_.reset(build_tabular_cell(this));
147
148         fl_set_input_return(cell_options_->input_mcolumn_width,
149                             FL_RETURN_END);
150         fl_set_input_return(cell_options_->input_special_multialign,
151                             FL_RETURN_END);
152
153         // trigger an input event for cut&paste with middle mouse button.
154         setPrehandler(cell_options_->input_mcolumn_width);
155         setPrehandler(cell_options_->input_special_multialign);
156
157         fl_addto_choice(cell_options_->choice_value_mcolumn_width,
158                         units.c_str());
159
160         longtable_options_.reset(build_tabular_longtable(this));
161
162         fl_addto_tabfolder(dialog_->tabfolder, _("Tabular"),
163                            tabular_options_->form);
164         fl_addto_tabfolder(dialog_->tabfolder, _("Column/Row"),
165                            column_options_->form);
166         fl_addto_tabfolder(dialog_->tabfolder, _("Cell"),
167                            cell_options_->form);
168         fl_addto_tabfolder(dialog_->tabfolder, _("LongTable"),
169                            longtable_options_->form);
170
171         // work-around xforms bug re update of folder->x, folder->y coords.
172         setPrehandler(dialog_->tabfolder);
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 (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 > BufferParams::PAPER_EXECUTIVEPAPER;
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,   true);
273                 setEnabled(cell_options_->radio_align_right,  true);
274                 setEnabled(cell_options_->radio_align_center, true);
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 > BufferParams::PAPER_EXECUTIVEPAPER;
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 (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,   true);
381         setEnabled(column_options_->radio_align_right,  true);
382         setEnabled(column_options_->radio_align_center, true);
383         setEnabled(column_options_->radio_valign_top,    !pwidth.zero());
384         setEnabled(column_options_->radio_valign_bottom, !pwidth.zero());
385         setEnabled(column_options_->radio_valign_center, !pwidth.zero());
386
387         fl_set_button(tabular_options_->check_longtable,
388                       tabular->IsLongTabular());
389
390         bool const enable = tabular->IsLongTabular();
391
392         setEnabled(longtable_options_->check_lt_firsthead, enable);
393         setEnabled(longtable_options_->check_1head_2border_above, enable);
394         setEnabled(longtable_options_->check_1head_2border_below, enable);
395         setEnabled(longtable_options_->check_1head_empty, enable);
396         setEnabled(longtable_options_->check_lt_head, enable);
397         setEnabled(longtable_options_->check_head_2border_above, enable);
398         setEnabled(longtable_options_->check_head_2border_below, enable);
399         setEnabled(longtable_options_->check_lt_foot, enable);
400         setEnabled(longtable_options_->check_foot_2border_above, enable);
401         setEnabled(longtable_options_->check_foot_2border_below, enable);
402         setEnabled(longtable_options_->check_lt_lastfoot, enable);
403         setEnabled(longtable_options_->check_lastfoot_2border_above, enable);
404         setEnabled(longtable_options_->check_lastfoot_2border_below, enable);
405         setEnabled(longtable_options_->check_lastfoot_empty, enable);
406         setEnabled(longtable_options_->check_lt_newpage, enable);
407
408         if (enable) {
409                 LyXTabular::ltType ltt;
410                 bool use_empty;
411                 bool row_set = tabular->GetRowOfLTHead(row, ltt);
412                 fl_set_button(longtable_options_->check_lt_head, row_set);
413                 if (ltt.set) {
414                         fl_set_button(longtable_options_->check_head_2border_above,
415                                       ltt.topDL);
416                         fl_set_button(longtable_options_->check_head_2border_above,
417                                       ltt.topDL);
418                         use_empty = true;
419                 } else {
420                         setEnabled(longtable_options_->check_head_2border_above, 0);
421                         setEnabled(longtable_options_->check_head_2border_below, 0);
422                         fl_set_button(longtable_options_->check_head_2border_above,0);
423                         fl_set_button(longtable_options_->check_head_2border_above,0);
424                         fl_set_button(longtable_options_->check_1head_empty,0);
425                         setEnabled(longtable_options_->check_1head_empty, 0);
426                         use_empty = false;
427                 }
428                 //
429                 row_set = tabular->GetRowOfLTFirstHead(row, ltt);
430                 fl_set_button(longtable_options_->check_lt_firsthead, row_set);
431                 if (ltt.set && (!ltt.empty || !use_empty)) {
432                         fl_set_button(longtable_options_->check_1head_2border_above,
433                                       ltt.topDL);
434                         fl_set_button(longtable_options_->check_1head_2border_above,
435                                       ltt.topDL);
436                 } else {
437                         setEnabled(longtable_options_->check_1head_2border_above, 0);
438                         setEnabled(longtable_options_->check_1head_2border_below, 0);
439                         fl_set_button(longtable_options_->check_1head_2border_above,0);
440                         fl_set_button(longtable_options_->check_1head_2border_above,0);
441                         if (use_empty) {
442                                 fl_set_button(longtable_options_->check_1head_empty,ltt.empty);
443                                 if (ltt.empty)
444                                         setEnabled(longtable_options_->check_lt_firsthead, 0);
445                         }
446                 }
447                 //
448                 row_set = tabular->GetRowOfLTFoot(row, ltt);
449                 fl_set_button(longtable_options_->check_lt_foot, row_set);
450                 if (ltt.set) {
451                         fl_set_button(longtable_options_->check_foot_2border_above,
452                                       ltt.topDL);
453                         fl_set_button(longtable_options_->check_foot_2border_above,
454                                       ltt.topDL);
455                         use_empty = true;
456                 } else {
457                         setEnabled(longtable_options_->check_foot_2border_above, 0);
458                         setEnabled(longtable_options_->check_foot_2border_below, 0);
459                         fl_set_button(longtable_options_->check_foot_2border_above,0);
460                         fl_set_button(longtable_options_->check_foot_2border_above,0);
461                         fl_set_button(longtable_options_->check_lastfoot_empty, 0);
462                         setEnabled(longtable_options_->check_lastfoot_empty, 0);
463                         use_empty = false;
464                 }
465                 //
466                 row_set = tabular->GetRowOfLTLastFoot(row, ltt);
467                 fl_set_button(longtable_options_->check_lt_lastfoot, row_set);
468                 if (ltt.set && (!ltt.empty || !use_empty)) {
469                         fl_set_button(longtable_options_->check_lastfoot_2border_above,
470                                       ltt.topDL);
471                         fl_set_button(longtable_options_->check_lastfoot_2border_above,
472                                       ltt.topDL);
473                 } else {
474                         setEnabled(longtable_options_->check_lastfoot_2border_above,0);
475                         setEnabled(longtable_options_->check_lastfoot_2border_below,0);
476                         fl_set_button(longtable_options_->check_lastfoot_2border_above, 0);
477                         fl_set_button(longtable_options_->check_lastfoot_2border_above, 0);
478                         if (use_empty) {
479                                 fl_set_button(longtable_options_->check_lastfoot_empty,
480                                               ltt.empty);
481                                 if (ltt.empty)
482                                         setEnabled(longtable_options_->check_lt_lastfoot, 0);
483                         }
484                 }
485                 fl_set_button(longtable_options_->check_lt_newpage,
486                               tabular->GetLTNewPage(row));
487         } else {
488                 fl_set_button(longtable_options_->check_lt_firsthead, 0);
489                 fl_set_button(longtable_options_->check_1head_2border_above, 0);
490                 fl_set_button(longtable_options_->check_1head_2border_above, 0);
491                 fl_set_button(longtable_options_->check_1head_empty, 0);
492                 fl_set_button(longtable_options_->check_lt_head, 0);
493                 fl_set_button(longtable_options_->check_head_2border_above, 0);
494                 fl_set_button(longtable_options_->check_head_2border_above, 0);
495                 fl_set_button(longtable_options_->check_lt_foot, 0);
496                 fl_set_button(longtable_options_->check_foot_2border_above, 0);
497                 fl_set_button(longtable_options_->check_foot_2border_above, 0);
498                 fl_set_button(longtable_options_->check_lt_lastfoot, 0);
499                 fl_set_button(longtable_options_->check_lastfoot_2border_above, 0);
500                 fl_set_button(longtable_options_->check_lastfoot_2border_above, 0);
501                 fl_set_button(longtable_options_->check_lastfoot_empty, 0);
502                 fl_set_button(longtable_options_->check_lt_newpage, 0);
503         }
504         fl_set_button(tabular_options_->check_rotate_tabular,
505                       tabular->GetRotateTabular());
506 }
507
508
509 bool FormTabular::input(FL_OBJECT * ob, long)
510 {
511         if (!inset_)
512                 return false;
513
514         int s;
515         LyXTabular::Feature num = LyXTabular::LAST_ACTION;
516         string special;;
517
518         int cell = inset_->getActCell();
519
520         // ugly hack to auto-apply the stuff that hasn't been
521         // yet. don't let this continue to exist ...
522         if (ob == dialog_->button_close) {
523                 closing_ = true;
524                 LyXTabular * tabular = inset_->tabular.get();
525                 string str1 =
526                         getLengthFromWidgets(column_options_->input_column_width,
527                                              column_options_->choice_value_column_width);
528                 string str2;
529                 LyXLength llen = tabular->GetColumnPWidth(cell);
530                 if (!llen.zero())
531                         str2 = llen.asString();
532                 if (str1 != str2)
533                         input(column_options_->input_column_width, 0);
534                 str1 = getLengthFromWidgets(cell_options_->input_mcolumn_width,
535                                             cell_options_->choice_value_mcolumn_width);
536                 llen = tabular->GetMColumnPWidth(cell);
537                 if (llen.zero())
538                         str2 = "";
539                 else
540                         str2 = llen.asString();
541                 if (str1 != str2)
542                         input(cell_options_->input_mcolumn_width, 0);
543                 str1 = getString(column_options_->input_special_alignment);
544                 str2 = tabular->GetAlignSpecial(cell, LyXTabular::SET_SPECIAL_COLUMN);
545                 if (str1 != str2)
546                         input(column_options_->input_special_alignment, 0);
547                 str1 = getString(cell_options_->input_special_multialign);
548                 str2 = tabular->GetAlignSpecial(cell, LyXTabular::SET_SPECIAL_MULTI);
549                 if (str1 != str2)
550                         input(cell_options_->input_special_multialign, 0);
551                 closing_ = false;
552                 ok();
553                 return true;
554         }
555
556         if (actCell_ != cell) {
557                 update();
558                 postWarning(_("Wrong Cursor position, updated window"));
559                 return false;
560         }
561         // No point in processing directives that you can't do anything with
562         // anyhow, so exit now if the buffer is read-only.
563         if (lv_.buffer()->isReadonly()) {
564                 update();
565                 return false;
566         }
567         if ((ob == column_options_->input_column_width) ||
568             (ob == column_options_->choice_value_column_width)) {
569                 string const str =
570                         getLengthFromWidgets(column_options_->input_column_width,
571                                              column_options_->choice_value_column_width);
572                 inset_->tabularFeatures(lv_.view().get(), LyXTabular::SET_PWIDTH, str);
573
574                 //check if the input is valid
575                 string const input = getString(column_options_->input_column_width);
576                 if (!input.empty() && !isValidLength(input) && !isStrDbl(input)) {
577                         postWarning(_("Invalid Length (valid example: 10mm)"));
578                         return false;
579                 }
580
581                 update(); // update for alignment
582                 return true;
583         }
584
585         if ((ob == cell_options_->input_mcolumn_width) ||
586             (ob == cell_options_->choice_value_mcolumn_width)) {
587                 string const str =
588                         getLengthFromWidgets(cell_options_->input_mcolumn_width,
589                                              cell_options_->choice_value_mcolumn_width);
590                 inset_->tabularFeatures(lv_.view().get(), LyXTabular::SET_MPWIDTH, str);
591
592                 //check if the input is valid
593                 string const input = getString(cell_options_->input_mcolumn_width);
594                 if (!input.empty() && !isValidLength(input) && !isStrDbl(input)) {
595                         postWarning(_("Invalid Length (valid example: 10mm)"));
596                         return false;
597                 }
598                 update(); // update for alignment
599                 return true;
600         }
601
602         if (ob == tabular_options_->button_append_row)
603                 num = LyXTabular::APPEND_ROW;
604         else if (ob == tabular_options_->button_append_column)
605                 num = LyXTabular::APPEND_COLUMN;
606         else if (ob == tabular_options_->button_delete_row)
607                 num = LyXTabular::DELETE_ROW;
608         else if (ob == tabular_options_->button_delete_column)
609                 num = LyXTabular::DELETE_COLUMN;
610         else if (ob == tabular_options_->button_set_borders)
611                 num = LyXTabular::SET_ALL_LINES;
612         else if (ob == tabular_options_->button_unset_borders)
613                 num = LyXTabular::UNSET_ALL_LINES;
614         else if (ob == column_options_->check_border_top)
615                 num = LyXTabular::TOGGLE_LINE_TOP;
616         else if (ob == column_options_->check_border_bottom)
617                 num = LyXTabular::TOGGLE_LINE_BOTTOM;
618         else if (ob == column_options_->check_border_left)
619                 num = LyXTabular::TOGGLE_LINE_LEFT;
620         else if (ob == column_options_->check_border_right)
621                 num = LyXTabular::TOGGLE_LINE_RIGHT;
622         else if (ob == column_options_->radio_align_left)
623                 num = LyXTabular::ALIGN_LEFT;
624         else if (ob == column_options_->radio_align_right)
625                 num = LyXTabular::ALIGN_RIGHT;
626         else if (ob == column_options_->radio_align_center)
627                 num = LyXTabular::ALIGN_CENTER;
628         else if (ob == column_options_->radio_valign_top)
629                 num = LyXTabular::VALIGN_TOP;
630         else if (ob == column_options_->radio_valign_bottom)
631                 num = LyXTabular::VALIGN_BOTTOM;
632         else if (ob == column_options_->radio_valign_center)
633                 num = LyXTabular::VALIGN_CENTER;
634         else if (ob == cell_options_->check_multicolumn)
635                 num = LyXTabular::MULTICOLUMN;
636         else if (ob == tabular_options_->check_longtable) {
637                 if (fl_get_button(tabular_options_->check_longtable))
638                         num = LyXTabular::SET_LONGTABULAR;
639                 else
640                         num = LyXTabular::UNSET_LONGTABULAR;
641         } else if (ob == tabular_options_->check_rotate_tabular) {
642                 s = fl_get_button(tabular_options_->check_rotate_tabular);
643                 if (s)
644                         num = LyXTabular::SET_ROTATE_TABULAR;
645                 else
646                         num = LyXTabular::UNSET_ROTATE_TABULAR;
647         } else if (ob == cell_options_->check_rotate_cell) {
648                 s = fl_get_button(cell_options_->check_rotate_cell);
649                 if (s)
650                         num = LyXTabular::SET_ROTATE_CELL;
651                 else
652                         num = LyXTabular::UNSET_ROTATE_CELL;
653         } else if (ob == cell_options_->check_useminipage) {
654                 num = LyXTabular::SET_USEBOX;
655                 special = "2";
656         } else if ((ob == longtable_options_->check_lt_firsthead) ||
657                    (ob == longtable_options_->check_1head_2border_above) ||
658                    (ob == longtable_options_->check_1head_2border_below) ||
659                    (ob == longtable_options_->check_1head_empty) ||
660                    (ob == longtable_options_->check_lt_head) ||
661                    (ob == longtable_options_->check_head_2border_above) ||
662                    (ob == longtable_options_->check_head_2border_below) ||
663                    (ob == longtable_options_->check_lt_foot) ||
664                    (ob == longtable_options_->check_foot_2border_above) ||
665                    (ob == longtable_options_->check_foot_2border_below) ||
666                    (ob == longtable_options_->check_lt_lastfoot) ||
667                    (ob == longtable_options_->check_lastfoot_2border_above) ||
668                    (ob == longtable_options_->check_lastfoot_2border_below) ||
669                    (ob == longtable_options_->check_lastfoot_empty)) {
670                 num = static_cast<LyXTabular::Feature>(checkLongtableOptions(ob, special));
671         } else if (ob == longtable_options_->check_lt_newpage) {
672                 num = LyXTabular::SET_LTNEWPAGE;
673         } else if (ob == column_options_->input_special_alignment) {
674                 special = getString(column_options_->input_special_alignment);
675                 num = LyXTabular::SET_SPECIAL_COLUMN;
676         } else if (ob == cell_options_->input_special_multialign) {
677                 special = getString(cell_options_->input_special_multialign);
678                 num = LyXTabular::SET_SPECIAL_MULTI;
679         } else if (ob == cell_options_->check_border_top)
680                 num = LyXTabular::M_TOGGLE_LINE_TOP;
681         else if (ob == cell_options_->check_border_bottom)
682                 num = LyXTabular::M_TOGGLE_LINE_BOTTOM;
683         else if (ob == cell_options_->check_border_left)
684                 num = LyXTabular::M_TOGGLE_LINE_LEFT;
685         else if (ob == cell_options_->check_border_right)
686                 num = LyXTabular::M_TOGGLE_LINE_RIGHT;
687         else if (ob == cell_options_->radio_align_left)
688                 num = LyXTabular::M_ALIGN_LEFT;
689         else if (ob == cell_options_->radio_align_right)
690                 num = LyXTabular::M_ALIGN_RIGHT;
691         else if (ob == cell_options_->radio_align_center)
692                 num = LyXTabular::M_ALIGN_CENTER;
693         else if (ob == cell_options_->radio_valign_top)
694                 num = LyXTabular::M_VALIGN_TOP;
695         else if (ob == cell_options_->radio_valign_bottom)
696                 num = LyXTabular::M_VALIGN_BOTTOM;
697         else if (ob == cell_options_->radio_valign_center)
698                 num = LyXTabular::M_VALIGN_CENTER;
699         else
700                 return false;
701
702         inset_->tabularFeatures(lv_.view().get(), num, special);
703         update();
704
705         return true;
706 }
707
708 int FormTabular::checkLongtableOptions(FL_OBJECT * ob, string & special)
709 {
710         bool flag = fl_get_button(ob);
711         if ((ob == longtable_options_->check_1head_2border_above) ||
712             (ob == longtable_options_->check_head_2border_above) ||
713             (ob == longtable_options_->check_foot_2border_above) ||
714             (ob == longtable_options_->check_lastfoot_2border_above)) {
715                 special = "dl_above";
716         } else if ((ob == longtable_options_->check_1head_2border_below) ||
717                    (ob == longtable_options_->check_head_2border_below) ||
718                    (ob == longtable_options_->check_foot_2border_below) ||
719                    (ob == longtable_options_->check_lastfoot_2border_below)) {
720                 special = "dl_below";
721         } else if ((ob == longtable_options_->check_1head_empty) ||
722                    (ob == longtable_options_->check_lastfoot_empty)) {
723                 special = "empty";
724         } else {
725                 special = "";
726         }
727         if ((ob == longtable_options_->check_lt_firsthead) ||
728             (ob == longtable_options_->check_1head_2border_above) ||
729             (ob == longtable_options_->check_1head_2border_below) ||
730             (ob == longtable_options_->check_1head_empty)) {
731                 return (flag ? LyXTabular::SET_LTFIRSTHEAD :
732                         LyXTabular::UNSET_LTFIRSTHEAD);
733         } else if ((ob == longtable_options_->check_lt_head) ||
734                            (ob == longtable_options_->check_head_2border_above) ||
735                            (ob == longtable_options_->check_head_2border_below)) {
736                 return (flag ? LyXTabular::SET_LTHEAD : LyXTabular::UNSET_LTHEAD);
737         } else if ((ob == longtable_options_->check_lt_foot) ||
738                    (ob == longtable_options_->check_foot_2border_above) ||
739                    (ob == longtable_options_->check_foot_2border_below)) {
740                 return (flag ? LyXTabular::SET_LTFOOT : LyXTabular::UNSET_LTFOOT);
741         } else if ((ob == longtable_options_->check_lt_lastfoot) ||
742                    (ob == longtable_options_->check_lastfoot_2border_above) ||
743                    (ob == longtable_options_->check_lastfoot_2border_below) ||
744                    (ob == longtable_options_->check_lastfoot_empty)) {
745                 return (flag ? LyXTabular::SET_LTLASTFOOT :
746                         LyXTabular::UNSET_LTLASTFOOT);
747         }
748
749         return LyXTabular::LAST_ACTION;
750 }