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