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