]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormTabular.C
whitespace changes only (believe it or not!)
[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                 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         clearMessage();
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_->check_multicolumn, 1);
206                 fl_set_button(cell_options_->check_border_top,
207                               tabular->TopLine(cell)?1:0);
208                 setEnabled(cell_options_->check_border_top, true);
209                 fl_set_button(cell_options_->check_border_bottom,
210                               tabular->BottomLine(cell)?1:0);
211                 setEnabled(cell_options_->check_border_bottom, true);
212                 // pay attention to left/right lines they are only allowed
213                 // to set if we are in first/last cell of row or if the left/right
214                 // cell is also a multicolumn.
215                 if (tabular->IsFirstCellInRow(cell) ||
216                     tabular->IsMultiColumn(cell-1)) {
217                         fl_set_button(cell_options_->check_border_left,
218                                       tabular->LeftLine(cell)?1:0);
219                         setEnabled(cell_options_->check_border_left, true);
220                 } else {
221                         fl_set_button(cell_options_->check_border_left, 0);
222                         setEnabled(cell_options_->check_border_left, false);
223                 }
224                 if (tabular->IsLastCellInRow(cell) ||
225                     tabular->IsMultiColumn(cell+1)) {
226                         fl_set_button(cell_options_->check_border_right,
227                                       tabular->RightLine(cell)?1:0);
228                         setEnabled(cell_options_->check_border_right, true);
229                 } else {
230                         fl_set_button(cell_options_->check_border_right, 0);
231                         setEnabled(cell_options_->check_border_right, false);
232                 }
233                 pwidth = tabular->GetMColumnPWidth(cell);
234                 align = tabular->GetAlignment(cell);
235                 if (!pwidth.zero() || (align == LYX_ALIGN_LEFT))
236                         fl_set_button(cell_options_->radio_align_left, 1);
237                 else if (align == LYX_ALIGN_RIGHT)
238                         fl_set_button(cell_options_->radio_align_right, 1);
239                 else
240                         fl_set_button(cell_options_->radio_align_center, 1);
241
242                 align = tabular->GetVAlignment(cell);
243                 fl_set_button(cell_options_->radio_valign_top, 0);
244                 fl_set_button(cell_options_->radio_valign_bottom, 0);
245                 fl_set_button(cell_options_->radio_valign_center, 0);
246                 if (pwidth.zero() || (align == LyXTabular::LYX_VALIGN_CENTER))
247                         fl_set_button(cell_options_->radio_valign_center, 1);
248                 else if (align == LyXTabular::LYX_VALIGN_BOTTOM)
249                         fl_set_button(cell_options_->radio_valign_bottom, 1);
250                 else
251                         fl_set_button(cell_options_->radio_valign_top, 1);
252
253                 special = tabular->GetAlignSpecial(cell, LyXTabular::SET_SPECIAL_MULTI);
254                 fl_set_input(cell_options_->input_special_multialign, special.c_str());
255                 bool const metric = lyxrc.default_papersize > 3;
256                 string const default_unit = metric ? "cm" : "in";
257                 updateWidgetsFromLength(cell_options_->input_mcolumn_width,
258                                         cell_options_->choice_value_mcolumn_width,
259                                         pwidth, default_unit);
260
261                 if (!lv_->buffer()->isReadonly()) {
262                         setEnabled(cell_options_->input_special_multialign, true);
263                         setEnabled(cell_options_->input_mcolumn_width, true);
264                         setEnabled(cell_options_->choice_value_mcolumn_width, true);
265                 }
266
267                 setEnabled(cell_options_->radio_valign_top,    !pwidth.zero());
268                 setEnabled(cell_options_->radio_valign_bottom, !pwidth.zero());
269                 setEnabled(cell_options_->radio_valign_center, !pwidth.zero());
270                 
271                 setEnabled(cell_options_->radio_align_left,   pwidth.zero());
272                 setEnabled(cell_options_->radio_align_right,  pwidth.zero());
273                 setEnabled(cell_options_->radio_align_center, pwidth.zero());
274         } else {
275                 fl_set_button(cell_options_->check_multicolumn, 0);
276
277                 fl_set_button(cell_options_->check_border_top, 0);
278                 setEnabled(cell_options_->check_border_top, false);
279
280                 fl_set_button(cell_options_->check_border_bottom, 0);
281                 setEnabled(cell_options_->check_border_bottom, false);
282
283                 fl_set_button(cell_options_->check_border_left, 0);
284                 setEnabled(cell_options_->check_border_left, false);
285
286                 fl_set_button(cell_options_->check_border_right, 0);
287                 setEnabled(cell_options_->check_border_right, false);
288
289                 fl_set_button(cell_options_->radio_align_left, 0);
290                 setEnabled(cell_options_->radio_align_left, false);
291
292                 fl_set_button(cell_options_->radio_align_right, 0);
293                 setEnabled(cell_options_->radio_align_right, false);
294
295                 fl_set_button(cell_options_->radio_align_center, 0);
296                 setEnabled(cell_options_->radio_align_center, false);
297
298                 fl_set_button(cell_options_->radio_valign_top, 0);
299                 setEnabled(cell_options_->radio_valign_top, false);
300
301                 fl_set_button(cell_options_->radio_valign_bottom, 0);
302                 setEnabled(cell_options_->radio_valign_bottom, false);
303
304                 fl_set_button(cell_options_->radio_valign_center, 0);
305                 setEnabled(cell_options_->radio_valign_center, false);
306
307                 fl_set_input(cell_options_->input_special_multialign, "");
308                 setEnabled(cell_options_->input_special_multialign, false);
309
310                 fl_set_input(cell_options_->input_mcolumn_width, "");
311                 setEnabled(cell_options_->input_mcolumn_width, false);
312                 setEnabled(cell_options_->choice_value_mcolumn_width, false);
313         }
314         if (tabular->GetRotateCell(cell))
315                 fl_set_button(cell_options_->check_rotate_cell, 1);
316         else
317                 fl_set_button(cell_options_->check_rotate_cell, 0);
318         if (tabular->TopLine(cell, true))
319                 fl_set_button(column_options_->check_border_top, 1);
320         else
321                 fl_set_button(column_options_->check_border_top, 0);
322         if (tabular->BottomLine(cell, true))
323                 fl_set_button(column_options_->check_border_bottom, 1);
324         else
325                 fl_set_button(column_options_->check_border_bottom, 0);
326         if (tabular->LeftLine(cell, true))
327                 fl_set_button(column_options_->check_border_left, 1);
328         else
329                 fl_set_button(column_options_->check_border_left, 0);
330         if (tabular->RightLine(cell, true))
331                 fl_set_button(column_options_->check_border_right, 1);
332         else
333                 fl_set_button(column_options_->check_border_right, 0);
334         special = tabular->GetAlignSpecial(cell, LyXTabular::SET_SPECIAL_COLUMN);
335         fl_set_input(column_options_->input_special_alignment, special.c_str());
336
337         bool const isReadonly = lv_->buffer()->isReadonly();
338         setEnabled(column_options_->input_special_alignment, !isReadonly);
339
340         pwidth = tabular->GetColumnPWidth(cell);
341         bool const metric = lyxrc.default_papersize > 3;
342         string const default_unit = metric ? "cm" : "in";
343         updateWidgetsFromLength(column_options_->input_column_width,
344                                 column_options_->choice_value_column_width,
345                                 pwidth, default_unit);
346         setEnabled(column_options_->input_column_width, !isReadonly);
347         setEnabled(column_options_->choice_value_column_width, !isReadonly);
348
349         setEnabled(cell_options_->check_useminipage, !pwidth.zero());
350         if (!pwidth.zero()) {
351                 if (tabular->GetUsebox(cell) == 2)
352                         fl_set_button(cell_options_->check_useminipage, 1);
353                 else
354                         fl_set_button(cell_options_->check_useminipage, 0);
355         } else {
356                 fl_set_button(cell_options_->check_useminipage, 0);
357         }
358         align = tabular->GetAlignment(cell, true);
359         fl_set_button(column_options_->radio_align_left, 0);
360         fl_set_button(column_options_->radio_align_right, 0);
361         fl_set_button(column_options_->radio_align_center, 0);
362         if (!pwidth.zero() || (align == LYX_ALIGN_LEFT))
363                 fl_set_button(column_options_->radio_align_left, 1);
364         else if (align == LYX_ALIGN_RIGHT)
365                 fl_set_button(column_options_->radio_align_right, 1);
366         else
367                 fl_set_button(column_options_->radio_align_center, 1);
368         align = tabular->GetVAlignment(cell, true);
369         fl_set_button(column_options_->radio_valign_top, 0);
370         fl_set_button(column_options_->radio_valign_bottom, 0);
371         fl_set_button(column_options_->radio_valign_center, 0);
372         if (pwidth.zero() || (align == LyXTabular::LYX_VALIGN_CENTER))
373                 fl_set_button(column_options_->radio_valign_center, 1);
374         else if (align == LyXTabular::LYX_VALIGN_BOTTOM)
375                 fl_set_button(column_options_->radio_valign_bottom, 1);
376         else
377                 fl_set_button(column_options_->radio_valign_top, 1);
378
379         setEnabled(column_options_->radio_align_left,   pwidth.zero());
380         setEnabled(column_options_->radio_align_right,  pwidth.zero());
381         setEnabled(column_options_->radio_align_center, pwidth.zero());
382         
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 = fl_get_input(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 = fl_get_input(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(), LyXTabular::SET_PWIDTH, str);
573
574                 //check if the input is valid
575                 string const input =
576                         fl_get_input(column_options_->input_column_width);
577                 if (!input.empty() && !isValidLength(input) && !isStrDbl(input)) {
578                         postWarning(_("Invalid Length (valid example: 10mm)"));
579                         return false;
580                 }
581
582                 update(); // update for alignment
583                 return true;
584         }
585         
586         if ((ob == cell_options_->input_mcolumn_width) ||
587             (ob == cell_options_->choice_value_mcolumn_width)) {
588                 string const str =
589                         getLengthFromWidgets(cell_options_->input_mcolumn_width,
590                                              cell_options_->choice_value_mcolumn_width);
591                 inset_->tabularFeatures(lv_->view(), LyXTabular::SET_MPWIDTH, str);
592
593                 //check if the input is valid
594                 string const input =
595                         fl_get_input(cell_options_->input_mcolumn_width);
596                 if (!input.empty() && !isValidLength(input) && !isStrDbl(input)) {
597                         postWarning(_("Invalid Length (valid example: 10mm)"));
598                         return false;
599                 }
600                 update(); // update for alignment
601                 return true;
602         }
603
604         if (ob == tabular_options_->button_append_row)
605                 num = LyXTabular::APPEND_ROW;
606         else if (ob == tabular_options_->button_append_column)
607                 num = LyXTabular::APPEND_COLUMN;
608         else if (ob == tabular_options_->button_delete_row)
609                 num = LyXTabular::DELETE_ROW;
610         else if (ob == tabular_options_->button_delete_column)
611                 num = LyXTabular::DELETE_COLUMN;
612         else if (ob == tabular_options_->button_set_borders)
613                 num = LyXTabular::SET_ALL_LINES;
614         else if (ob == tabular_options_->button_unset_borders)
615                 num = LyXTabular::UNSET_ALL_LINES;
616         else if (ob == column_options_->check_border_top)
617                 num = LyXTabular::TOGGLE_LINE_TOP;
618         else if (ob == column_options_->check_border_bottom)
619                 num = LyXTabular::TOGGLE_LINE_BOTTOM;
620         else if (ob == column_options_->check_border_left)
621                 num = LyXTabular::TOGGLE_LINE_LEFT;
622         else if (ob == column_options_->check_border_right)
623                 num = LyXTabular::TOGGLE_LINE_RIGHT;
624         else if (ob == column_options_->radio_align_left)
625                 num = LyXTabular::ALIGN_LEFT;
626         else if (ob == column_options_->radio_align_right)
627                 num = LyXTabular::ALIGN_RIGHT;
628         else if (ob == column_options_->radio_align_center)
629                 num = LyXTabular::ALIGN_CENTER;
630         else if (ob == column_options_->radio_valign_top)
631                 num = LyXTabular::VALIGN_TOP;
632         else if (ob == column_options_->radio_valign_bottom)
633                 num = LyXTabular::VALIGN_BOTTOM;
634         else if (ob == column_options_->radio_valign_center)
635                 num = LyXTabular::VALIGN_CENTER;
636         else if (ob == cell_options_->check_multicolumn)
637                 num = LyXTabular::MULTICOLUMN;
638         else if (ob == tabular_options_->check_longtable) {
639                 if (fl_get_button(tabular_options_->check_longtable))
640                         num = LyXTabular::SET_LONGTABULAR;
641                 else
642                         num = LyXTabular::UNSET_LONGTABULAR;
643         } else if (ob == tabular_options_->check_rotate_tabular) {
644                 s = fl_get_button(tabular_options_->check_rotate_tabular);
645                 if (s)
646                         num = LyXTabular::SET_ROTATE_TABULAR;
647                 else
648                         num = LyXTabular::UNSET_ROTATE_TABULAR;
649         } else if (ob == cell_options_->check_rotate_cell) {
650                 s = fl_get_button(cell_options_->check_rotate_cell);
651                 if (s)
652                         num = LyXTabular::SET_ROTATE_CELL;
653                 else
654                         num = LyXTabular::UNSET_ROTATE_CELL;
655         } else if (ob == cell_options_->check_useminipage) {
656                 num = LyXTabular::SET_USEBOX;
657                 special = "2";
658         } else if ((ob == longtable_options_->check_lt_firsthead) ||
659                    (ob == longtable_options_->check_1head_2border_above) ||
660                    (ob == longtable_options_->check_1head_2border_below) ||
661                    (ob == longtable_options_->check_1head_empty) ||
662                    (ob == longtable_options_->check_lt_head) ||
663                    (ob == longtable_options_->check_head_2border_above) ||
664                    (ob == longtable_options_->check_head_2border_below) ||
665                    (ob == longtable_options_->check_lt_foot) ||
666                    (ob == longtable_options_->check_foot_2border_above) ||
667                    (ob == longtable_options_->check_foot_2border_below) ||
668                    (ob == longtable_options_->check_lt_lastfoot) ||
669                    (ob == longtable_options_->check_lastfoot_2border_above) ||
670                    (ob == longtable_options_->check_lastfoot_2border_below) ||
671                    (ob == longtable_options_->check_lastfoot_empty)) {
672                 num = static_cast<LyXTabular::Feature>(checkLongtableOptions(ob, special));
673         } else if (ob == longtable_options_->check_lt_newpage) {
674                 num = LyXTabular::SET_LTNEWPAGE;
675         } else if (ob == column_options_->input_special_alignment) {
676                 special = fl_get_input(column_options_->input_special_alignment);
677                 num = LyXTabular::SET_SPECIAL_COLUMN;
678         } else if (ob == cell_options_->input_special_multialign) {
679                 special = fl_get_input(cell_options_->input_special_multialign);
680                 num = LyXTabular::SET_SPECIAL_MULTI;
681         } else if (ob == cell_options_->check_border_top)
682                 num = LyXTabular::M_TOGGLE_LINE_TOP;
683         else if (ob == cell_options_->check_border_bottom)
684                 num = LyXTabular::M_TOGGLE_LINE_BOTTOM;
685         else if (ob == cell_options_->check_border_left)
686                 num = LyXTabular::M_TOGGLE_LINE_LEFT;
687         else if (ob == cell_options_->check_border_right)
688                 num = LyXTabular::M_TOGGLE_LINE_RIGHT;
689         else if (ob == cell_options_->radio_align_left)
690                 num = LyXTabular::M_ALIGN_LEFT;
691         else if (ob == cell_options_->radio_align_right)
692                 num = LyXTabular::M_ALIGN_RIGHT;
693         else if (ob == cell_options_->radio_align_center)
694                 num = LyXTabular::M_ALIGN_CENTER;
695         else if (ob == cell_options_->radio_valign_top)
696                 num = LyXTabular::M_VALIGN_TOP;
697         else if (ob == cell_options_->radio_valign_bottom)
698                 num = LyXTabular::M_VALIGN_BOTTOM;
699         else if (ob == cell_options_->radio_valign_center)
700                 num = LyXTabular::M_VALIGN_CENTER;
701         else
702                 return false;
703         
704         inset_->tabularFeatures(lv_->view(), num, special);
705         update();
706
707         return true;
708 }
709
710 int FormTabular::checkLongtableOptions(FL_OBJECT * ob, string & special)
711 {
712         bool flag = fl_get_button(ob);
713         if ((ob == longtable_options_->check_1head_2border_above) ||
714             (ob == longtable_options_->check_head_2border_above) ||
715             (ob == longtable_options_->check_foot_2border_above) ||
716             (ob == longtable_options_->check_lastfoot_2border_above)) {
717                 special = "dl_above";
718         } else if ((ob == longtable_options_->check_1head_2border_below) ||
719                    (ob == longtable_options_->check_head_2border_below) ||
720                    (ob == longtable_options_->check_foot_2border_below) ||
721                    (ob == longtable_options_->check_lastfoot_2border_below)) {
722                 special = "dl_below";
723         } else if ((ob == longtable_options_->check_1head_empty) ||
724                    (ob == longtable_options_->check_lastfoot_empty)) {
725                 special = "empty";
726         } else {
727                 special = "";
728         }
729         if ((ob == longtable_options_->check_lt_firsthead) ||
730             (ob == longtable_options_->check_1head_2border_above) ||
731             (ob == longtable_options_->check_1head_2border_below) ||
732             (ob == longtable_options_->check_1head_empty)) {
733                 return (flag ? LyXTabular::SET_LTFIRSTHEAD :
734                         LyXTabular::UNSET_LTFIRSTHEAD);
735         } else if ((ob == longtable_options_->check_lt_head) ||
736                            (ob == longtable_options_->check_head_2border_above) ||
737                            (ob == longtable_options_->check_head_2border_below)) {
738                 return (flag ? LyXTabular::SET_LTHEAD : LyXTabular::UNSET_LTHEAD);
739         } else if ((ob == longtable_options_->check_lt_foot) ||
740                    (ob == longtable_options_->check_foot_2border_above) ||
741                    (ob == longtable_options_->check_foot_2border_below)) {
742                 return (flag ? LyXTabular::SET_LTFOOT : LyXTabular::UNSET_LTFOOT);
743         } else if ((ob == longtable_options_->check_lt_lastfoot) ||
744                    (ob == longtable_options_->check_lastfoot_2border_above) ||
745                    (ob == longtable_options_->check_lastfoot_2border_below) ||
746                    (ob == longtable_options_->check_lastfoot_empty)) {
747                 return (flag ? LyXTabular::SET_LTLASTFOOT :
748                         LyXTabular::UNSET_LTLASTFOOT);
749         }
750
751         return LyXTabular::LAST_ACTION;
752 }