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