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