]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormTabular.C
1ed5fe40358abb8785c523f35f13843e7c78400e
[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         setPrehandler(dialog_->input_tabular_column);
115         setPrehandler(dialog_->input_tabular_row);
116
117         tabular_options_.reset(build_tabular_options());
118         column_options_.reset(build_column_options());
119         cell_options_.reset(build_cell_options());
120         longtable_options_.reset(build_longtable_options());
121
122         fl_set_input_return(column_options_->input_column_width,
123                             FL_RETURN_END);
124         fl_set_input_return(column_options_->input_special_alignment,
125                             FL_RETURN_END);
126
127         setPrehandler(column_options_->input_column_width);
128         setPrehandler(column_options_->input_special_alignment);
129         
130         fl_set_input_return(cell_options_->input_mcolumn_width,
131                             FL_RETURN_END);
132         fl_set_input_return(cell_options_->input_special_multialign,
133                             FL_RETURN_END);
134
135         setPrehandler(cell_options_->input_mcolumn_width);
136         setPrehandler(cell_options_->input_special_multialign);
137
138         fl_addto_tabfolder(dialog_->tabfolder, _("Tabular"),
139                            tabular_options_->form);
140         fl_addto_tabfolder(dialog_->tabfolder, _("Column/Row"),
141                            column_options_->form);
142         fl_addto_tabfolder(dialog_->tabfolder, _("Cell"),
143                            cell_options_->form);
144         fl_addto_tabfolder(dialog_->tabfolder, _("LongTable"),
145                            longtable_options_->form);
146
147         // Create the contents of the unit choices
148         // Don't include the "%" terms...
149         vector<string> units_vec = getLatexUnits();
150 #if 0
151         for (vector<string>::iterator it = units_vec.begin();
152              it != units_vec.end(); ++it)
153         {
154                 if (contains(*it, "%"))
155                         it = units_vec.erase(it, it + 1) - 1;
156         }
157 #else
158         vector<string>::iterator ret =
159                 remove_if(units_vec.begin(), units_vec.end(),
160                           bind2nd(contains_functor(), "%"));
161         units_vec.erase(ret, units_vec.end());
162 #endif
163         
164         string units = getStringFromVector(units_vec, "|");
165
166         fl_addto_choice(column_options_->choice_value_column_width,
167                         units.c_str());
168         fl_addto_choice(cell_options_->choice_value_mcolumn_width,
169                         units.c_str());
170 }
171
172
173 void FormTabular::update()
174 {
175         if (closing_)
176                 return;
177  
178         if (!inset_ || !inset_->tabular.get())
179                 return;
180
181         LyXTabular * tabular = inset_->tabular.get();
182         int align;
183         char buf[12];
184         LyXLength pwidth;
185         string special;
186
187         int cell = inset_->getActCell();
188         actCell_ = cell;
189         int column = tabular->column_of_cell(cell) + 1;
190         fl_set_object_label(dialog_->text_warning, "");
191         fl_activate_object(column_options_->input_special_alignment);
192         fl_activate_object(cell_options_->input_special_multialign);
193         fl_activate_object(column_options_->input_column_width);
194         fl_activate_object(column_options_->choice_value_column_width);
195         sprintf(buf, "%d", column);
196         fl_set_input(dialog_->input_tabular_column, buf);
197         fl_deactivate_object(dialog_->input_tabular_column);
198         int row = tabular->row_of_cell(cell);
199         sprintf(buf, "%d", row + 1);
200         fl_set_input(dialog_->input_tabular_row, buf);
201         fl_deactivate_object(dialog_->input_tabular_row);
202         if (tabular->IsMultiColumn(cell)) {
203                 fl_set_button(cell_options_->check_multicolumn, 1);
204                 fl_set_button(cell_options_->check_border_top,
205                               tabular->TopLine(cell)?1:0);
206                 setEnabled(cell_options_->check_border_top, true);
207                 fl_set_button(cell_options_->check_border_bottom,
208                               tabular->BottomLine(cell)?1:0);
209                 setEnabled(cell_options_->check_border_bottom, true);
210                 // pay attention to left/right lines they are only allowed
211                 // to set if we are in first/last cell of row or if the left/right
212                 // cell is also a multicolumn.
213                 if (tabular->IsFirstCellInRow(cell) ||
214                         tabular->IsMultiColumn(cell-1))
215                 {
216                         fl_set_button(cell_options_->check_border_left,
217                                       tabular->LeftLine(cell)?1:0);
218                         setEnabled(cell_options_->check_border_left, true);
219                 } else {
220                         fl_set_button(cell_options_->check_border_left, 0);
221                         setEnabled(cell_options_->check_border_left, false);
222                 }
223                 if (tabular->IsLastCellInRow(cell) ||
224                         tabular->IsMultiColumn(cell+1))
225                 {
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                 fl_set_object_label(dialog_->text_warning,
559                         _("Warning: Wrong Cursor position, updated window"));
560                 fl_show_object(dialog_->text_warning);
561                 return false;
562         }
563         // No point in processing directives that you can't do anything with
564         // anyhow, so exit now if the buffer is read-only.
565         if (lv_->buffer()->isReadonly()) {
566           update();
567           return false;
568         }
569         if ((ob == column_options_->input_column_width) ||
570                 (ob == column_options_->choice_value_column_width))
571         {
572         string const str =
573                 getLengthFromWidgets(column_options_->input_column_width,
574                                      column_options_->choice_value_column_width);
575         inset_->tabularFeatures(lv_->view(), LyXTabular::SET_PWIDTH, str);
576
577         //check if the input is valid
578         string const input =
579                 fl_get_input(column_options_->input_column_width);
580         if (!input.empty() && !isValidLength(input) && !isStrDbl(input)) {
581                 fl_set_object_label(dialog_->text_warning,
582                         _("Warning: Invalid Length (valid example: 10mm)"));
583                 fl_show_object(dialog_->text_warning);
584                 return false;
585         }
586                 update(); // update for alignment
587                 return true;
588         }
589         if ((ob == cell_options_->input_mcolumn_width) ||
590                 (ob == cell_options_->choice_value_mcolumn_width))
591         {
592                 string const str =
593                         getLengthFromWidgets(cell_options_->input_mcolumn_width,
594                                              cell_options_->choice_value_mcolumn_width);
595                 inset_->tabularFeatures(lv_->view(), LyXTabular::SET_MPWIDTH, str);
596
597                 //check if the input is valid
598                 string const input =
599                         fl_get_input(cell_options_->input_mcolumn_width);
600                 if (!input.empty() && !isValidLength(input) && !isStrDbl(input)) {
601                         fl_set_object_label(dialog_->text_warning,
602                                 _("Warning: Invalid Length (valid example: 10mm)"));
603                         fl_show_object(dialog_->text_warning);
604                         return false;
605                 }
606                 update(); // update for alignment
607                 return true;
608         }
609
610         if (ob == tabular_options_->button_append_row)
611                 num = LyXTabular::APPEND_ROW;
612         else if (ob == tabular_options_->button_append_column)
613                 num = LyXTabular::APPEND_COLUMN;
614         else if (ob == tabular_options_->button_delete_row)
615                 num = LyXTabular::DELETE_ROW;
616         else if (ob == tabular_options_->button_delete_column)
617                 num = LyXTabular::DELETE_COLUMN;
618         else if (ob == tabular_options_->button_set_borders)
619                 num = LyXTabular::SET_ALL_LINES;
620         else if (ob == tabular_options_->button_unset_borders)
621                 num = LyXTabular::UNSET_ALL_LINES;
622         else if (ob == column_options_->check_border_top)
623                 num = LyXTabular::TOGGLE_LINE_TOP;
624         else if (ob == column_options_->check_border_bottom)
625                 num = LyXTabular::TOGGLE_LINE_BOTTOM;
626         else if (ob == column_options_->check_border_left)
627                 num = LyXTabular::TOGGLE_LINE_LEFT;
628         else if (ob == column_options_->check_border_right)
629                 num = LyXTabular::TOGGLE_LINE_RIGHT;
630         else if (ob == column_options_->radio_align_left)
631                 num = LyXTabular::ALIGN_LEFT;
632         else if (ob == column_options_->radio_align_right)
633                 num = LyXTabular::ALIGN_RIGHT;
634         else if (ob == column_options_->radio_align_center)
635                 num = LyXTabular::ALIGN_CENTER;
636         else if (ob == column_options_->radio_valign_top)
637                 num = LyXTabular::VALIGN_TOP;
638         else if (ob == column_options_->radio_valign_bottom)
639                 num = LyXTabular::VALIGN_BOTTOM;
640         else if (ob == column_options_->radio_valign_center)
641                 num = LyXTabular::VALIGN_CENTER;
642         else if (ob == cell_options_->check_multicolumn)
643                 num = LyXTabular::MULTICOLUMN;
644         else if (ob == tabular_options_->check_longtable) {
645                 if (fl_get_button(tabular_options_->check_longtable))
646                     num = LyXTabular::SET_LONGTABULAR;
647                 else
648                         num = LyXTabular::UNSET_LONGTABULAR;
649         } else if (ob == tabular_options_->check_rotate_tabular) {
650                 s = fl_get_button(tabular_options_->check_rotate_tabular);
651                 if (s)
652                         num = LyXTabular::SET_ROTATE_TABULAR;
653                 else
654                         num = LyXTabular::UNSET_ROTATE_TABULAR;
655         } else if (ob == cell_options_->check_rotate_cell) {
656                 s = fl_get_button(cell_options_->check_rotate_cell);
657                 if (s)
658                         num = LyXTabular::SET_ROTATE_CELL;
659                 else
660                         num = LyXTabular::UNSET_ROTATE_CELL;
661         } else if (ob == cell_options_->check_useminipage) {
662                 num = LyXTabular::SET_USEBOX;
663                 special = "2";
664         } else if ((ob == longtable_options_->check_lt_firsthead) ||
665                    (ob == longtable_options_->check_1head_2border_above) ||
666                    (ob == longtable_options_->check_1head_2border_below) ||
667                    (ob == longtable_options_->check_1head_empty) ||
668                    (ob == longtable_options_->check_lt_head) ||
669                    (ob == longtable_options_->check_head_2border_above) ||
670                    (ob == longtable_options_->check_head_2border_below) ||
671                    (ob == longtable_options_->check_lt_foot) ||
672                    (ob == longtable_options_->check_foot_2border_above) ||
673                    (ob == longtable_options_->check_foot_2border_below) ||
674                    (ob == longtable_options_->check_lt_lastfoot) ||
675                    (ob == longtable_options_->check_lastfoot_2border_above) ||
676                    (ob == longtable_options_->check_lastfoot_2border_below) ||
677                    (ob == longtable_options_->check_lastfoot_empty))
678         {
679                 num = static_cast<LyXTabular::Feature>(checkLongtableOptions(ob, special));
680         } else if (ob == longtable_options_->check_lt_newpage) {
681                 num = LyXTabular::SET_LTNEWPAGE;
682         } else if (ob == column_options_->input_special_alignment) {
683                 special = fl_get_input(column_options_->input_special_alignment);
684                 num = LyXTabular::SET_SPECIAL_COLUMN;
685         } else if (ob == cell_options_->input_special_multialign) {
686                 special = fl_get_input(cell_options_->input_special_multialign);
687                 num = LyXTabular::SET_SPECIAL_MULTI;
688         } else if (ob == cell_options_->check_border_top)
689                 num = LyXTabular::M_TOGGLE_LINE_TOP;
690         else if (ob == cell_options_->check_border_bottom)
691                 num = LyXTabular::M_TOGGLE_LINE_BOTTOM;
692         else if (ob == cell_options_->check_border_left)
693                 num = LyXTabular::M_TOGGLE_LINE_LEFT;
694         else if (ob == cell_options_->check_border_right)
695                 num = LyXTabular::M_TOGGLE_LINE_RIGHT;
696         else if (ob == cell_options_->radio_align_left)
697                 num = LyXTabular::M_ALIGN_LEFT;
698         else if (ob == cell_options_->radio_align_right)
699                 num = LyXTabular::M_ALIGN_RIGHT;
700         else if (ob == cell_options_->radio_align_center)
701                 num = LyXTabular::M_ALIGN_CENTER;
702         else if (ob == cell_options_->radio_valign_top)
703                 num = LyXTabular::M_VALIGN_TOP;
704         else if (ob == cell_options_->radio_valign_bottom)
705                 num = LyXTabular::M_VALIGN_BOTTOM;
706         else if (ob == cell_options_->radio_valign_center)
707                 num = LyXTabular::M_VALIGN_CENTER;
708         else
709                 return false;
710         
711         inset_->tabularFeatures(lv_->view(), num, special);
712         update();
713
714         return true;
715 }
716
717 int FormTabular::checkLongtableOptions(FL_OBJECT * ob, string & special)
718 {
719         bool flag = fl_get_button(ob);
720         if ((ob == longtable_options_->check_1head_2border_above) ||
721             (ob == longtable_options_->check_head_2border_above) ||
722             (ob == longtable_options_->check_foot_2border_above) ||
723             (ob == longtable_options_->check_lastfoot_2border_above))
724         {
725                 special = "dl_above";
726         } else if ((ob == longtable_options_->check_1head_2border_below) ||
727                    (ob == longtable_options_->check_head_2border_below) ||
728                    (ob == longtable_options_->check_foot_2border_below) ||
729                    (ob == longtable_options_->check_lastfoot_2border_below))
730         {
731                 special = "dl_below";
732         } else if ((ob == longtable_options_->check_1head_empty) ||
733                    (ob == longtable_options_->check_lastfoot_empty))
734         {
735                 special = "empty";
736         } else {
737                 special = "";
738         }
739         if ((ob == longtable_options_->check_lt_firsthead) ||
740             (ob == longtable_options_->check_1head_2border_above) ||
741             (ob == longtable_options_->check_1head_2border_below) ||
742             (ob == longtable_options_->check_1head_empty))
743         {
744                 return (flag ? LyXTabular::SET_LTFIRSTHEAD :
745                         LyXTabular::UNSET_LTFIRSTHEAD);
746         } else if ((ob == longtable_options_->check_lt_head) ||
747                    (ob == longtable_options_->check_head_2border_above) ||
748                    (ob == longtable_options_->check_head_2border_below))
749         {
750                 return (flag ? LyXTabular::SET_LTHEAD : LyXTabular::UNSET_LTHEAD);
751         } else if ((ob == longtable_options_->check_lt_foot) ||
752                    (ob == longtable_options_->check_foot_2border_above) ||
753                    (ob == longtable_options_->check_foot_2border_below))
754         {
755                 return (flag ? LyXTabular::SET_LTFOOT : LyXTabular::UNSET_LTFOOT);
756         } else if ((ob == longtable_options_->check_lt_lastfoot) ||
757                    (ob == longtable_options_->check_lastfoot_2border_above) ||
758                    (ob == longtable_options_->check_lastfoot_2border_below) ||
759                    (ob == longtable_options_->check_lastfoot_empty))
760         {
761                 return (flag ? LyXTabular::SET_LTLASTFOOT :
762                         LyXTabular::UNSET_LTLASTFOOT);
763         }
764         return LyXTabular::LAST_ACTION;
765 }