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