]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormTabular.C
Make more use of the feedback controller routines.
[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
114         // Allow the base class to control messages
115         setMessageWidget(dialog_->text_warning);
116
117         setPrehandler(dialog_->input_tabular_column);
118         setPrehandler(dialog_->input_tabular_row);
119
120         tabular_options_.reset(build_tabular_options());
121         column_options_.reset(build_column_options());
122         cell_options_.reset(build_cell_options());
123         longtable_options_.reset(build_longtable_options());
124
125         fl_set_input_return(column_options_->input_column_width,
126                             FL_RETURN_END);
127         fl_set_input_return(column_options_->input_special_alignment,
128                             FL_RETURN_END);
129
130         setPrehandler(column_options_->input_column_width);
131         setPrehandler(column_options_->input_special_alignment);
132         
133         fl_set_input_return(cell_options_->input_mcolumn_width,
134                             FL_RETURN_END);
135         fl_set_input_return(cell_options_->input_special_multialign,
136                             FL_RETURN_END);
137
138         setPrehandler(cell_options_->input_mcolumn_width);
139         setPrehandler(cell_options_->input_special_multialign);
140
141         fl_addto_tabfolder(dialog_->tabfolder, _("Tabular"),
142                            tabular_options_->form);
143         fl_addto_tabfolder(dialog_->tabfolder, _("Column/Row"),
144                            column_options_->form);
145         fl_addto_tabfolder(dialog_->tabfolder, _("Cell"),
146                            cell_options_->form);
147         fl_addto_tabfolder(dialog_->tabfolder, _("LongTable"),
148                            longtable_options_->form);
149
150         // Create the contents of the unit choices
151         // Don't include the "%" terms...
152         vector<string> units_vec = getLatexUnits();
153 #if 0
154         for (vector<string>::iterator it = units_vec.begin();
155              it != units_vec.end(); ++it)
156         {
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                 {
219                         fl_set_button(cell_options_->check_border_left,
220                                       tabular->LeftLine(cell)?1:0);
221                         setEnabled(cell_options_->check_border_left, true);
222                 } else {
223                         fl_set_button(cell_options_->check_border_left, 0);
224                         setEnabled(cell_options_->check_border_left, false);
225                 }
226                 if (tabular->IsLastCellInRow(cell) ||
227                         tabular->IsMultiColumn(cell+1))
228                 {
229                         fl_set_button(cell_options_->check_border_right,
230                                   tabular->RightLine(cell)?1:0);
231                         setEnabled(cell_options_->check_border_right, true);
232                 } else {
233                         fl_set_button(cell_options_->check_border_right, 0);
234                         setEnabled(cell_options_->check_border_right, false);
235                 }
236                 pwidth = tabular->GetMColumnPWidth(cell);
237                 align = tabular->GetAlignment(cell);
238                 if (!pwidth.zero() || (align == LYX_ALIGN_LEFT))
239                         fl_set_button(cell_options_->radio_align_left, 1);
240                 else if (align == LYX_ALIGN_RIGHT)
241                         fl_set_button(cell_options_->radio_align_right, 1);
242                 else
243                         fl_set_button(cell_options_->radio_align_center, 1);
244
245                 align = tabular->GetVAlignment(cell);
246                 fl_set_button(cell_options_->radio_valign_top, 0);
247                 fl_set_button(cell_options_->radio_valign_bottom, 0);
248                 fl_set_button(cell_options_->radio_valign_center, 0);
249                 if (pwidth.zero() || (align == LyXTabular::LYX_VALIGN_CENTER))
250                         fl_set_button(cell_options_->radio_valign_center, 1);
251                 else if (align == LyXTabular::LYX_VALIGN_BOTTOM)
252                         fl_set_button(cell_options_->radio_valign_bottom, 1);
253                 else
254                         fl_set_button(cell_options_->radio_valign_top, 1);
255
256                 special = tabular->GetAlignSpecial(cell, LyXTabular::SET_SPECIAL_MULTI);
257                 fl_set_input(cell_options_->input_special_multialign, special.c_str());
258                 bool const metric = lyxrc.default_papersize > 3;
259                 string const default_unit = metric ? "cm" : "in";
260                 updateWidgetsFromLength(cell_options_->input_mcolumn_width,
261                                         cell_options_->choice_value_mcolumn_width,
262                                         pwidth, default_unit);
263
264                 if (!lv_->buffer()->isReadonly()) {
265                         setEnabled(cell_options_->input_special_multialign, true);
266                         setEnabled(cell_options_->input_mcolumn_width, true);
267                         setEnabled(cell_options_->choice_value_mcolumn_width, true);
268                 }
269
270                 setEnabled(cell_options_->radio_valign_top,    !pwidth.zero());
271                 setEnabled(cell_options_->radio_valign_bottom, !pwidth.zero());
272                 setEnabled(cell_options_->radio_valign_center, !pwidth.zero());
273                 
274                 setEnabled(cell_options_->radio_align_left,   pwidth.zero());
275                 setEnabled(cell_options_->radio_align_right,  pwidth.zero());
276                 setEnabled(cell_options_->radio_align_center, pwidth.zero());
277         } else {
278                 fl_set_button(cell_options_->check_multicolumn, 0);
279
280                 fl_set_button(cell_options_->check_border_top, 0);
281                 setEnabled(cell_options_->check_border_top, false);
282
283                 fl_set_button(cell_options_->check_border_bottom, 0);
284                 setEnabled(cell_options_->check_border_bottom, false);
285
286                 fl_set_button(cell_options_->check_border_left, 0);
287                 setEnabled(cell_options_->check_border_left, false);
288
289                 fl_set_button(cell_options_->check_border_right, 0);
290                 setEnabled(cell_options_->check_border_right, false);
291
292                 fl_set_button(cell_options_->radio_align_left, 0);
293                 setEnabled(cell_options_->radio_align_left, false);
294
295                 fl_set_button(cell_options_->radio_align_right, 0);
296                 setEnabled(cell_options_->radio_align_right, false);
297
298                 fl_set_button(cell_options_->radio_align_center, 0);
299                 setEnabled(cell_options_->radio_align_center, false);
300
301                 fl_set_button(cell_options_->radio_valign_top, 0);
302                 setEnabled(cell_options_->radio_valign_top, false);
303
304                 fl_set_button(cell_options_->radio_valign_bottom, 0);
305                 setEnabled(cell_options_->radio_valign_bottom, false);
306
307                 fl_set_button(cell_options_->radio_valign_center, 0);
308                 setEnabled(cell_options_->radio_valign_center, false);
309
310                 fl_set_input(cell_options_->input_special_multialign, "");
311                 setEnabled(cell_options_->input_special_multialign, false);
312
313                 fl_set_input(cell_options_->input_mcolumn_width, "");
314                 setEnabled(cell_options_->input_mcolumn_width, false);
315                 setEnabled(cell_options_->choice_value_mcolumn_width, false);
316         }
317         if (tabular->GetRotateCell(cell))
318                 fl_set_button(cell_options_->check_rotate_cell, 1);
319         else
320                 fl_set_button(cell_options_->check_rotate_cell, 0);
321         if (tabular->TopLine(cell, true))
322                 fl_set_button(column_options_->check_border_top, 1);
323         else
324                 fl_set_button(column_options_->check_border_top, 0);
325         if (tabular->BottomLine(cell, true))
326                 fl_set_button(column_options_->check_border_bottom, 1);
327         else
328                 fl_set_button(column_options_->check_border_bottom, 0);
329         if (tabular->LeftLine(cell, true))
330                 fl_set_button(column_options_->check_border_left, 1);
331         else
332                 fl_set_button(column_options_->check_border_left, 0);
333         if (tabular->RightLine(cell, true))
334                 fl_set_button(column_options_->check_border_right, 1);
335         else
336                 fl_set_button(column_options_->check_border_right, 0);
337         special = tabular->GetAlignSpecial(cell, LyXTabular::SET_SPECIAL_COLUMN);
338         fl_set_input(column_options_->input_special_alignment, special.c_str());
339
340         bool const isReadonly = lv_->buffer()->isReadonly();
341         setEnabled(column_options_->input_special_alignment, !isReadonly);
342
343         pwidth = tabular->GetColumnPWidth(cell);
344         bool const metric = lyxrc.default_papersize > 3;
345         string const default_unit = metric ? "cm" : "in";
346         updateWidgetsFromLength(column_options_->input_column_width,
347                                 column_options_->choice_value_column_width,
348                                 pwidth, default_unit);
349         setEnabled(column_options_->input_column_width, !isReadonly);
350         setEnabled(column_options_->choice_value_column_width, !isReadonly);
351
352         setEnabled(cell_options_->check_useminipage, !pwidth.zero());
353         if (!pwidth.zero()) {
354                 if (tabular->GetUsebox(cell) == 2)
355                         fl_set_button(cell_options_->check_useminipage, 1);
356                 else
357                         fl_set_button(cell_options_->check_useminipage, 0);
358         } else {
359                 fl_set_button(cell_options_->check_useminipage, 0);
360         }
361         align = tabular->GetAlignment(cell, true);
362         fl_set_button(column_options_->radio_align_left, 0);
363         fl_set_button(column_options_->radio_align_right, 0);
364         fl_set_button(column_options_->radio_align_center, 0);
365         if (!pwidth.zero() || (align == LYX_ALIGN_LEFT))
366                 fl_set_button(column_options_->radio_align_left, 1);
367         else if (align == LYX_ALIGN_RIGHT)
368                 fl_set_button(column_options_->radio_align_right, 1);
369         else
370                 fl_set_button(column_options_->radio_align_center, 1);
371         align = tabular->GetVAlignment(cell, true);
372         fl_set_button(column_options_->radio_valign_top, 0);
373         fl_set_button(column_options_->radio_valign_bottom, 0);
374         fl_set_button(column_options_->radio_valign_center, 0);
375         if (pwidth.zero() || (align == LyXTabular::LYX_VALIGN_CENTER))
376                 fl_set_button(column_options_->radio_valign_center, 1);
377         else if (align == LyXTabular::LYX_VALIGN_BOTTOM)
378                 fl_set_button(column_options_->radio_valign_bottom, 1);
379         else
380                 fl_set_button(column_options_->radio_valign_top, 1);
381
382         setEnabled(column_options_->radio_align_left,   pwidth.zero());
383         setEnabled(column_options_->radio_align_right,  pwidth.zero());
384         setEnabled(column_options_->radio_align_center, pwidth.zero());
385         
386         setEnabled(column_options_->radio_valign_top,    !pwidth.zero());
387         setEnabled(column_options_->radio_valign_bottom, !pwidth.zero());
388         setEnabled(column_options_->radio_valign_center, !pwidth.zero());
389
390         fl_set_button(tabular_options_->check_longtable,
391                       tabular->IsLongTabular());
392
393         bool const enable = tabular->IsLongTabular();
394             
395         setEnabled(longtable_options_->check_lt_firsthead, enable);
396         setEnabled(longtable_options_->check_1head_2border_above, enable);
397         setEnabled(longtable_options_->check_1head_2border_below, enable);
398         setEnabled(longtable_options_->check_1head_empty, enable);
399         setEnabled(longtable_options_->check_lt_head, enable);
400         setEnabled(longtable_options_->check_head_2border_above, enable);
401         setEnabled(longtable_options_->check_head_2border_below, enable);
402         setEnabled(longtable_options_->check_lt_foot, enable);
403         setEnabled(longtable_options_->check_foot_2border_above, enable);
404         setEnabled(longtable_options_->check_foot_2border_below, enable);
405         setEnabled(longtable_options_->check_lt_lastfoot, enable);
406         setEnabled(longtable_options_->check_lastfoot_2border_above, enable);
407         setEnabled(longtable_options_->check_lastfoot_2border_below, enable);
408         setEnabled(longtable_options_->check_lastfoot_empty, enable);
409         setEnabled(longtable_options_->check_lt_newpage, enable);
410
411         if (enable) {
412                 LyXTabular::ltType ltt;
413                 bool use_empty;
414                 bool row_set = tabular->GetRowOfLTHead(row, ltt);
415                 fl_set_button(longtable_options_->check_lt_head, row_set);
416                 if (ltt.set) {
417                         fl_set_button(longtable_options_->check_head_2border_above,
418                                       ltt.topDL);
419                         fl_set_button(longtable_options_->check_head_2border_above,
420                                       ltt.topDL);
421                         use_empty = true;
422                 } else {
423                         setEnabled(longtable_options_->check_head_2border_above, 0);
424                         setEnabled(longtable_options_->check_head_2border_below, 0);
425                         fl_set_button(longtable_options_->check_head_2border_above,0);
426                         fl_set_button(longtable_options_->check_head_2border_above,0);
427                         fl_set_button(longtable_options_->check_1head_empty,0);
428                         setEnabled(longtable_options_->check_1head_empty, 0);
429                         use_empty = false;
430                 }
431                 //
432                 row_set = tabular->GetRowOfLTFirstHead(row, ltt);
433                 fl_set_button(longtable_options_->check_lt_firsthead, row_set);
434                 if (ltt.set && (!ltt.empty || !use_empty)) {
435                         fl_set_button(longtable_options_->check_1head_2border_above,
436                                       ltt.topDL);
437                         fl_set_button(longtable_options_->check_1head_2border_above,
438                                       ltt.topDL);
439                 } else {
440                         setEnabled(longtable_options_->check_1head_2border_above, 0);
441                         setEnabled(longtable_options_->check_1head_2border_below, 0);
442                         fl_set_button(longtable_options_->check_1head_2border_above,0);
443                         fl_set_button(longtable_options_->check_1head_2border_above,0);
444                         if (use_empty) {
445                                 fl_set_button(longtable_options_->check_1head_empty,ltt.empty);
446                                 if (ltt.empty)
447                                         setEnabled(longtable_options_->check_lt_firsthead, 0);
448                         }
449                 }
450                 //
451                 row_set = tabular->GetRowOfLTFoot(row, ltt);
452                 fl_set_button(longtable_options_->check_lt_foot, row_set);
453                 if (ltt.set) {
454                         fl_set_button(longtable_options_->check_foot_2border_above,
455                                       ltt.topDL);
456                         fl_set_button(longtable_options_->check_foot_2border_above,
457                                       ltt.topDL);
458                         use_empty = true;
459                 } else {
460                         setEnabled(longtable_options_->check_foot_2border_above, 0);
461                         setEnabled(longtable_options_->check_foot_2border_below, 0);
462                         fl_set_button(longtable_options_->check_foot_2border_above,0);
463                         fl_set_button(longtable_options_->check_foot_2border_above,0);
464                         fl_set_button(longtable_options_->check_lastfoot_empty, 0);
465                         setEnabled(longtable_options_->check_lastfoot_empty, 0);
466                         use_empty = false;
467                 }
468                 //
469                 row_set = tabular->GetRowOfLTLastFoot(row, ltt);
470                 fl_set_button(longtable_options_->check_lt_lastfoot, row_set);
471                 if (ltt.set && (!ltt.empty || !use_empty)) {
472                         fl_set_button(longtable_options_->check_lastfoot_2border_above,
473                                       ltt.topDL);
474                         fl_set_button(longtable_options_->check_lastfoot_2border_above,
475                                       ltt.topDL);
476                 } else {
477                         setEnabled(longtable_options_->check_lastfoot_2border_above,0);
478                         setEnabled(longtable_options_->check_lastfoot_2border_below,0);
479                         fl_set_button(longtable_options_->check_lastfoot_2border_above, 0);
480                         fl_set_button(longtable_options_->check_lastfoot_2border_above, 0);
481                         if (use_empty) {
482                                 fl_set_button(longtable_options_->check_lastfoot_empty,
483                                               ltt.empty);
484                                 if (ltt.empty)
485                                         setEnabled(longtable_options_->check_lt_lastfoot, 0);
486                         }
487                 }
488                 fl_set_button(longtable_options_->check_lt_newpage,
489                               tabular->GetLTNewPage(row));
490         } else {
491                 fl_set_button(longtable_options_->check_lt_firsthead, 0);
492                 fl_set_button(longtable_options_->check_1head_2border_above, 0);
493                 fl_set_button(longtable_options_->check_1head_2border_above, 0);
494                 fl_set_button(longtable_options_->check_1head_empty, 0);
495                 fl_set_button(longtable_options_->check_lt_head, 0);
496                 fl_set_button(longtable_options_->check_head_2border_above, 0);
497                 fl_set_button(longtable_options_->check_head_2border_above, 0);
498                 fl_set_button(longtable_options_->check_lt_foot, 0);
499                 fl_set_button(longtable_options_->check_foot_2border_above, 0);
500                 fl_set_button(longtable_options_->check_foot_2border_above, 0);
501                 fl_set_button(longtable_options_->check_lt_lastfoot, 0);
502                 fl_set_button(longtable_options_->check_lastfoot_2border_above, 0);
503                 fl_set_button(longtable_options_->check_lastfoot_2border_above, 0);
504                 fl_set_button(longtable_options_->check_lastfoot_empty, 0);
505                 fl_set_button(longtable_options_->check_lt_newpage, 0);
506         }
507         fl_set_button(tabular_options_->check_rotate_tabular,
508                       tabular->GetRotateTabular());
509 }
510
511
512 bool FormTabular::input(FL_OBJECT * ob, long)
513 {
514         if (!inset_)
515                 return false;
516
517         int s;
518         LyXTabular::Feature num = LyXTabular::LAST_ACTION;
519         string special;;
520
521         int cell = inset_->getActCell();
522
523         // ugly hack to auto-apply the stuff that hasn't been
524         // yet. don't let this continue to exist ...
525         if (ob == dialog_->button_close) {
526                 closing_ = true;
527                 LyXTabular * tabular = inset_->tabular.get();
528                 string str1 =
529                         getLengthFromWidgets(column_options_->input_column_width,
530                                                                  column_options_->choice_value_column_width);
531                 string str2;
532                 LyXLength llen = tabular->GetColumnPWidth(cell);
533                 if (!llen.zero())
534                         str2 = llen.asString();
535                 if (str1 != str2)
536                         input(column_options_->input_column_width, 0);
537                 str1 = getLengthFromWidgets(cell_options_->input_mcolumn_width,
538                                             cell_options_->choice_value_mcolumn_width);
539                 llen = tabular->GetMColumnPWidth(cell);
540                 if (llen.zero())
541                         str2 = "";
542                 else
543                         str2 = llen.asString();
544                 if (str1 != str2)
545                         input(cell_options_->input_mcolumn_width, 0);
546                 str1 = fl_get_input(column_options_->input_special_alignment);
547                 str2 = tabular->GetAlignSpecial(cell, LyXTabular::SET_SPECIAL_COLUMN);
548                 if (str1 != str2)
549                         input(column_options_->input_special_alignment, 0);
550                 str1 = fl_get_input(cell_options_->input_special_multialign);
551                 str2 = tabular->GetAlignSpecial(cell, LyXTabular::SET_SPECIAL_MULTI);
552                 if (str1 != str2)
553                         input(cell_options_->input_special_multialign, 0);
554                 closing_ = false;
555                 ok();
556                 return true;
557         }
558  
559         if (actCell_ != cell) {
560                 update();
561                 postWarning(_("Wrong Cursor position, updated window"));
562                 return false;
563         }
564         // No point in processing directives that you can't do anything with
565         // anyhow, so exit now if the buffer is read-only.
566         if (lv_->buffer()->isReadonly()) {
567           update();
568           return false;
569         }
570         if ((ob == column_options_->input_column_width) ||
571                 (ob == column_options_->choice_value_column_width))
572         {
573         string const str =
574                 getLengthFromWidgets(column_options_->input_column_width,
575                                      column_options_->choice_value_column_width);
576         inset_->tabularFeatures(lv_->view(), LyXTabular::SET_PWIDTH, str);
577
578         //check if the input is valid
579         string const input =
580                 fl_get_input(column_options_->input_column_width);
581         if (!input.empty() && !isValidLength(input) && !isStrDbl(input)) {
582                 postWarning(_("Invalid Length (valid example: 10mm)"));
583                 return false;
584         }
585
586         update(); // update for alignment
587         return true;
588         }
589         
590         if ((ob == cell_options_->input_mcolumn_width) ||
591                 (ob == cell_options_->choice_value_mcolumn_width))
592         {
593                 string const str =
594                         getLengthFromWidgets(cell_options_->input_mcolumn_width,
595                                              cell_options_->choice_value_mcolumn_width);
596                 inset_->tabularFeatures(lv_->view(), LyXTabular::SET_MPWIDTH, str);
597
598                 //check if the input is valid
599                 string const input =
600                         fl_get_input(cell_options_->input_mcolumn_width);
601                 if (!input.empty() && !isValidLength(input) && !isStrDbl(input)) {
602                         postWarning(_("Invalid Length (valid example: 10mm)"));
603                         return false;
604                 }
605                 update(); // update for alignment
606                 return true;
607         }
608
609         if (ob == tabular_options_->button_append_row)
610                 num = LyXTabular::APPEND_ROW;
611         else if (ob == tabular_options_->button_append_column)
612                 num = LyXTabular::APPEND_COLUMN;
613         else if (ob == tabular_options_->button_delete_row)
614                 num = LyXTabular::DELETE_ROW;
615         else if (ob == tabular_options_->button_delete_column)
616                 num = LyXTabular::DELETE_COLUMN;
617         else if (ob == tabular_options_->button_set_borders)
618                 num = LyXTabular::SET_ALL_LINES;
619         else if (ob == tabular_options_->button_unset_borders)
620                 num = LyXTabular::UNSET_ALL_LINES;
621         else if (ob == column_options_->check_border_top)
622                 num = LyXTabular::TOGGLE_LINE_TOP;
623         else if (ob == column_options_->check_border_bottom)
624                 num = LyXTabular::TOGGLE_LINE_BOTTOM;
625         else if (ob == column_options_->check_border_left)
626                 num = LyXTabular::TOGGLE_LINE_LEFT;
627         else if (ob == column_options_->check_border_right)
628                 num = LyXTabular::TOGGLE_LINE_RIGHT;
629         else if (ob == column_options_->radio_align_left)
630                 num = LyXTabular::ALIGN_LEFT;
631         else if (ob == column_options_->radio_align_right)
632                 num = LyXTabular::ALIGN_RIGHT;
633         else if (ob == column_options_->radio_align_center)
634                 num = LyXTabular::ALIGN_CENTER;
635         else if (ob == column_options_->radio_valign_top)
636                 num = LyXTabular::VALIGN_TOP;
637         else if (ob == column_options_->radio_valign_bottom)
638                 num = LyXTabular::VALIGN_BOTTOM;
639         else if (ob == column_options_->radio_valign_center)
640                 num = LyXTabular::VALIGN_CENTER;
641         else if (ob == cell_options_->check_multicolumn)
642                 num = LyXTabular::MULTICOLUMN;
643         else if (ob == tabular_options_->check_longtable) {
644                 if (fl_get_button(tabular_options_->check_longtable))
645                     num = LyXTabular::SET_LONGTABULAR;
646                 else
647                         num = LyXTabular::UNSET_LONGTABULAR;
648         } else if (ob == tabular_options_->check_rotate_tabular) {
649                 s = fl_get_button(tabular_options_->check_rotate_tabular);
650                 if (s)
651                         num = LyXTabular::SET_ROTATE_TABULAR;
652                 else
653                         num = LyXTabular::UNSET_ROTATE_TABULAR;
654         } else if (ob == cell_options_->check_rotate_cell) {
655                 s = fl_get_button(cell_options_->check_rotate_cell);
656                 if (s)
657                         num = LyXTabular::SET_ROTATE_CELL;
658                 else
659                         num = LyXTabular::UNSET_ROTATE_CELL;
660         } else if (ob == cell_options_->check_useminipage) {
661                 num = LyXTabular::SET_USEBOX;
662                 special = "2";
663         } else if ((ob == longtable_options_->check_lt_firsthead) ||
664                    (ob == longtable_options_->check_1head_2border_above) ||
665                    (ob == longtable_options_->check_1head_2border_below) ||
666                    (ob == longtable_options_->check_1head_empty) ||
667                    (ob == longtable_options_->check_lt_head) ||
668                    (ob == longtable_options_->check_head_2border_above) ||
669                    (ob == longtable_options_->check_head_2border_below) ||
670                    (ob == longtable_options_->check_lt_foot) ||
671                    (ob == longtable_options_->check_foot_2border_above) ||
672                    (ob == longtable_options_->check_foot_2border_below) ||
673                    (ob == longtable_options_->check_lt_lastfoot) ||
674                    (ob == longtable_options_->check_lastfoot_2border_above) ||
675                    (ob == longtable_options_->check_lastfoot_2border_below) ||
676                    (ob == longtable_options_->check_lastfoot_empty))
677         {
678                 num = static_cast<LyXTabular::Feature>(checkLongtableOptions(ob, special));
679         } else if (ob == longtable_options_->check_lt_newpage) {
680                 num = LyXTabular::SET_LTNEWPAGE;
681         } else if (ob == column_options_->input_special_alignment) {
682                 special = fl_get_input(column_options_->input_special_alignment);
683                 num = LyXTabular::SET_SPECIAL_COLUMN;
684         } else if (ob == cell_options_->input_special_multialign) {
685                 special = fl_get_input(cell_options_->input_special_multialign);
686                 num = LyXTabular::SET_SPECIAL_MULTI;
687         } else if (ob == cell_options_->check_border_top)
688                 num = LyXTabular::M_TOGGLE_LINE_TOP;
689         else if (ob == cell_options_->check_border_bottom)
690                 num = LyXTabular::M_TOGGLE_LINE_BOTTOM;
691         else if (ob == cell_options_->check_border_left)
692                 num = LyXTabular::M_TOGGLE_LINE_LEFT;
693         else if (ob == cell_options_->check_border_right)
694                 num = LyXTabular::M_TOGGLE_LINE_RIGHT;
695         else if (ob == cell_options_->radio_align_left)
696                 num = LyXTabular::M_ALIGN_LEFT;
697         else if (ob == cell_options_->radio_align_right)
698                 num = LyXTabular::M_ALIGN_RIGHT;
699         else if (ob == cell_options_->radio_align_center)
700                 num = LyXTabular::M_ALIGN_CENTER;
701         else if (ob == cell_options_->radio_valign_top)
702                 num = LyXTabular::M_VALIGN_TOP;
703         else if (ob == cell_options_->radio_valign_bottom)
704                 num = LyXTabular::M_VALIGN_BOTTOM;
705         else if (ob == cell_options_->radio_valign_center)
706                 num = LyXTabular::M_VALIGN_CENTER;
707         else
708                 return false;
709         
710         inset_->tabularFeatures(lv_->view(), num, special);
711         update();
712
713         return true;
714 }
715
716 int FormTabular::checkLongtableOptions(FL_OBJECT * ob, string & special)
717 {
718         bool flag = fl_get_button(ob);
719         if ((ob == longtable_options_->check_1head_2border_above) ||
720             (ob == longtable_options_->check_head_2border_above) ||
721             (ob == longtable_options_->check_foot_2border_above) ||
722             (ob == longtable_options_->check_lastfoot_2border_above))
723         {
724                 special = "dl_above";
725         } else if ((ob == longtable_options_->check_1head_2border_below) ||
726                    (ob == longtable_options_->check_head_2border_below) ||
727                    (ob == longtable_options_->check_foot_2border_below) ||
728                    (ob == longtable_options_->check_lastfoot_2border_below))
729         {
730                 special = "dl_below";
731         } else if ((ob == longtable_options_->check_1head_empty) ||
732                    (ob == longtable_options_->check_lastfoot_empty))
733         {
734                 special = "empty";
735         } else {
736                 special = "";
737         }
738         if ((ob == longtable_options_->check_lt_firsthead) ||
739             (ob == longtable_options_->check_1head_2border_above) ||
740             (ob == longtable_options_->check_1head_2border_below) ||
741             (ob == longtable_options_->check_1head_empty))
742         {
743                 return (flag ? LyXTabular::SET_LTFIRSTHEAD :
744                         LyXTabular::UNSET_LTFIRSTHEAD);
745         } else if ((ob == longtable_options_->check_lt_head) ||
746                    (ob == longtable_options_->check_head_2border_above) ||
747                    (ob == longtable_options_->check_head_2border_below))
748         {
749                 return (flag ? LyXTabular::SET_LTHEAD : LyXTabular::UNSET_LTHEAD);
750         } else if ((ob == longtable_options_->check_lt_foot) ||
751                    (ob == longtable_options_->check_foot_2border_above) ||
752                    (ob == longtable_options_->check_foot_2border_below))
753         {
754                 return (flag ? LyXTabular::SET_LTFOOT : LyXTabular::UNSET_LTFOOT);
755         } else if ((ob == longtable_options_->check_lt_lastfoot) ||
756                    (ob == longtable_options_->check_lastfoot_2border_above) ||
757                    (ob == longtable_options_->check_lastfoot_2border_below) ||
758                    (ob == longtable_options_->check_lastfoot_empty))
759         {
760                 return (flag ? LyXTabular::SET_LTLASTFOOT :
761                         LyXTabular::UNSET_LTLASTFOOT);
762         }
763         return LyXTabular::LAST_ACTION;
764 }