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