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