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