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