]> git.lyx.org Git - features.git/blob - src/TableLayout.C
a0ff8eb436aacffb1dd42b27d64508b55284c0e7
[features.git] / src / TableLayout.C
1 #include <config.h>
2
3 #include <cstdlib>
4 #include FORMS_H_LOCATION
5
6 #include "layout_forms.h"
7 #include "lyx_main.h"
8 #include "lyxrc.h"
9 #include "LString.h"
10 #include "support/filetools.h"
11 #include "buffer.h"
12 #include "vspace.h"
13 #include "lyx_gui_misc.h"
14 #include "BufferView.h"
15 #include "lyxscreen.h"
16 #include "gettext.h"
17 #include "lyxtext.h"
18 #include "layout.h"
19
20 extern void BeforeChange();
21
22 // Prototypes
23 extern FD_form_table_options * fd_form_table_options;
24 extern FD_form_table_extra * fd_form_table_extra;
25 extern BufferView * current_view;
26
27 static int Confirmed = false;
28 static int ActCell;
29
30 // hack to keep the cursor from jumping to the end of the text in the Extra
31 // form input fields during editing. The values in LyXTable itself is changed in
32 // real-time, but we have no callbacks for the input fields, so I simply
33 // store and restore the cursor position for now. (too much of a hazzle to
34 // do it proper; we'll trash all this code in 1.1 anyway)
35 static int extra_col_cursor_x; // need no y's, one-line input fields
36 static int extra_multicol_cursor_x;
37 // Joacim
38
39 #ifdef MOVE_TEXT
40 bool UpdateLayoutTable(int flag)
41 {
42     bool update = true;
43     if (!current_view->getScreen() || !current_view->available())
44         update = false;
45     
46     if (update && current_view->text->cursor.par->table) {
47         char buf[12];
48         string pwidth, special;
49    
50         LyXTable * table = current_view->text->cursor.par->table;
51
52         int cell = current_view->text->
53             NumberOfCell(current_view->text->cursor.par, 
54                          current_view->text->cursor.pos);
55         ActCell = cell;
56         int column = table->column_of_cell(cell)+1;
57         fl_set_object_label(fd_form_table_options->text_warning, "");
58         Confirmed = false;
59         fl_activate_object(fd_form_table_extra->input_special_alignment);
60         fl_activate_object(fd_form_table_extra->input_special_multialign);
61         fl_activate_object(fd_form_table_options->input_column_width);
62         sprintf(buf, "%d", column);
63         fl_set_input(fd_form_table_options->input_table_column, buf);
64         fl_deactivate_object(fd_form_table_options->input_table_column);
65         int row = table->row_of_cell(cell)+1;
66         sprintf(buf, "%d", row);
67         fl_set_input(fd_form_table_options->input_table_row, buf);
68         fl_deactivate_object(fd_form_table_options->input_table_row);
69         if (table->IsMultiColumn(cell))
70             fl_set_button(fd_form_table_options->radio_multicolumn, 1);
71         else
72             fl_set_button(fd_form_table_options->radio_multicolumn, 0);
73         if (table->RotateCell(cell))
74             fl_set_button(fd_form_table_options->radio_rotate_cell, 1);
75         else
76             fl_set_button(fd_form_table_options->radio_rotate_cell, 0);
77         if (table->TopLine(cell))
78             fl_set_button(fd_form_table_options->radio_border_top, 1);
79         else
80             fl_set_button(fd_form_table_options->radio_border_top, 0);
81         if (table->BottomLine(cell))
82             fl_set_button(fd_form_table_options->radio_border_bottom, 1);
83         else
84             fl_set_button(fd_form_table_options->radio_border_bottom, 0);
85         if (table->LeftLine(cell))
86             fl_set_button(fd_form_table_options->radio_border_left, 1);
87         else
88             fl_set_button(fd_form_table_options->radio_border_left, 0);
89         if (table->RightLine(cell))
90             fl_set_button(fd_form_table_options->radio_border_right, 1);
91         else
92             fl_set_button(fd_form_table_options->radio_border_right, 0);
93         int align = table->GetAlignment(cell);
94         fl_set_button(fd_form_table_options->radio_align_left, 0);
95         fl_set_button(fd_form_table_options->radio_align_right, 0);
96         fl_set_button(fd_form_table_options->radio_align_center, 0);
97         special = table->GetAlignSpecial(cell, LyXTable::SET_SPECIAL_COLUMN);
98         if (flag)
99         {
100             fl_set_input(fd_form_table_extra->input_special_alignment,
101                          special.c_str());
102             fl_set_input_cursorpos(fd_form_table_extra->input_special_alignment,
103                     extra_col_cursor_x, 0); // restore the cursor
104         }
105         if (current_view->buffer()->isReadonly()) 
106             fl_deactivate_object(fd_form_table_extra->input_special_alignment);
107         special = table->GetAlignSpecial(cell, LyXTable::SET_SPECIAL_MULTI);
108         if (flag)
109         {
110             fl_set_input(fd_form_table_extra->input_special_multialign,
111                          special.c_str());
112             fl_set_input_cursorpos(fd_form_table_extra->input_special_multialign,
113                     extra_multicol_cursor_x, 0); // restore the cursor
114         }
115         if (current_view->buffer()->isReadonly()) 
116             fl_deactivate_object(fd_form_table_extra->input_special_multialign);
117         pwidth = table->GetPWidth(cell);
118         if (flag)
119             fl_set_input(fd_form_table_options->input_column_width, pwidth.c_str());
120         if (current_view->buffer()->isReadonly()) 
121             fl_deactivate_object(fd_form_table_options->input_column_width);
122         if (!pwidth.empty()) {
123             fl_activate_object(fd_form_table_options->radio_linebreak_cell);
124             fl_set_object_lcol(fd_form_table_options->radio_linebreak_cell,
125                                FL_BLACK);
126             fl_set_button(fd_form_table_options->radio_linebreak_cell,
127                           table->Linebreaks(table->FirstVirtualCell(cell)));
128         } else {
129             fl_deactivate_object(fd_form_table_options->radio_linebreak_cell);
130             fl_set_object_lcol(fd_form_table_options->radio_linebreak_cell,
131                                FL_INACTIVE);
132             fl_set_button(fd_form_table_options->radio_linebreak_cell, 0);
133         }
134         if ((!pwidth.empty() && !table->IsMultiColumn(cell)) ||
135             (align == LYX_ALIGN_LEFT))
136             fl_set_button(fd_form_table_options->radio_align_left, 1);
137         else if (align == LYX_ALIGN_RIGHT)
138             fl_set_button(fd_form_table_options->radio_align_right, 1);
139         else
140             fl_set_button(fd_form_table_options->radio_align_center, 1);
141         if (!pwidth.empty() && !table->IsMultiColumn(cell)) {
142             fl_deactivate_object(fd_form_table_options->radio_align_left);
143             fl_deactivate_object(fd_form_table_options->radio_align_right);
144             fl_deactivate_object(fd_form_table_options->radio_align_center);
145             fl_set_object_lcol(fd_form_table_options->radio_align_left,
146                                FL_INACTIVE);
147             fl_set_object_lcol(fd_form_table_options->radio_align_right,
148                                FL_INACTIVE);
149             fl_set_object_lcol(fd_form_table_options->radio_align_center,
150                                FL_INACTIVE);
151         } else {
152             fl_activate_object(fd_form_table_options->radio_align_left);
153             fl_activate_object(fd_form_table_options->radio_align_right);
154             fl_activate_object(fd_form_table_options->radio_align_center);
155             fl_set_object_lcol(fd_form_table_options->radio_align_left,
156                                FL_BLACK);
157             fl_set_object_lcol(fd_form_table_options->radio_align_right,
158                                FL_BLACK);
159             fl_set_object_lcol(fd_form_table_options->radio_align_center,
160                                FL_BLACK);
161         }
162         fl_set_button(fd_form_table_options->radio_longtable, table->IsLongTable());
163         if (table->IsLongTable()) {
164             fl_activate_object(fd_form_table_options->radio_lt_firsthead);
165             fl_activate_object(fd_form_table_options->radio_lt_head);
166             fl_activate_object(fd_form_table_options->radio_lt_foot);
167             fl_activate_object(fd_form_table_options->radio_lt_lastfoot);
168             fl_activate_object(fd_form_table_options->radio_lt_newpage);
169             fl_set_object_lcol(fd_form_table_options->radio_lt_firsthead,
170                                FL_BLACK);
171             fl_set_object_lcol(fd_form_table_options->radio_lt_head,
172                                FL_BLACK);
173             fl_set_object_lcol(fd_form_table_options->radio_lt_foot,
174                                FL_BLACK);
175             fl_set_object_lcol(fd_form_table_options->radio_lt_lastfoot,
176                                FL_BLACK);
177             fl_set_object_lcol(fd_form_table_options->radio_lt_newpage,
178                                FL_BLACK);
179             fl_set_button(fd_form_table_options->radio_lt_firsthead,
180                           table->RowOfLTFirstHead(cell));
181             fl_set_button(fd_form_table_options->radio_lt_head,
182                           table->RowOfLTHead(cell));
183             fl_set_button(fd_form_table_options->radio_lt_foot,
184                           table->RowOfLTFoot(cell));
185             fl_set_button(fd_form_table_options->radio_lt_lastfoot,
186                           table->RowOfLTLastFoot(cell));
187             fl_set_button(fd_form_table_options->radio_lt_newpage,
188                           table->LTNewPage(cell));
189         } else {
190             fl_deactivate_object(fd_form_table_options->radio_lt_firsthead);
191             fl_deactivate_object(fd_form_table_options->radio_lt_head);
192             fl_deactivate_object(fd_form_table_options->radio_lt_foot);
193             fl_deactivate_object(fd_form_table_options->radio_lt_lastfoot);
194             fl_deactivate_object(fd_form_table_options->radio_lt_newpage);
195             fl_set_button(fd_form_table_options->radio_lt_firsthead, 0);
196             fl_set_button(fd_form_table_options->radio_lt_head, 0);
197             fl_set_button(fd_form_table_options->radio_lt_foot, 0);
198             fl_set_button(fd_form_table_options->radio_lt_lastfoot, 0);
199             fl_set_button(fd_form_table_options->radio_lt_newpage, 0);
200             fl_set_object_lcol(fd_form_table_options->radio_lt_firsthead,
201                                FL_INACTIVE);
202             fl_set_object_lcol(fd_form_table_options->radio_lt_head,
203                                FL_INACTIVE);
204             fl_set_object_lcol(fd_form_table_options->radio_lt_foot,
205                                FL_INACTIVE);
206             fl_set_object_lcol(fd_form_table_options->radio_lt_lastfoot,
207                                FL_INACTIVE);
208             fl_set_object_lcol(fd_form_table_options->radio_lt_newpage,
209                                FL_INACTIVE);
210         }
211         fl_set_button(fd_form_table_options->radio_rotate_table,
212                       table->RotateTable());
213         fl_set_focus_object(fd_form_table_options->form_table_options,
214                             fd_form_table_options->button_table_delete);
215     } else if (fd_form_table_options->form_table_options->visible) {
216         fl_set_focus_object(fd_form_table_options->form_table_options,
217                             fd_form_table_options->button_table_delete);
218         fl_hide_form(fd_form_table_options->form_table_options);
219     }
220     return update;
221 }
222 #else
223 bool UpdateLayoutTable(int flag)
224 {
225     bool update = true;
226     if (!current_view->getScreen() || !current_view->available())
227         update = false;
228     
229     if (update && current_view->buffer()->text->cursor.par->table) {
230         char buf[12];
231         string pwidth, special;
232    
233         LyXTable * table = current_view->buffer()->text->cursor.par->table;
234
235         int cell = current_view->buffer()->text->
236             NumberOfCell(current_view->buffer()->text->cursor.par, 
237                          current_view->buffer()->text->cursor.pos);
238         ActCell = cell;
239         int column = table->column_of_cell(cell)+1;
240         fl_set_object_label(fd_form_table_options->text_warning, "");
241         Confirmed = false;
242         fl_activate_object(fd_form_table_extra->input_special_alignment);
243         fl_activate_object(fd_form_table_extra->input_special_multialign);
244         fl_activate_object(fd_form_table_options->input_column_width);
245         sprintf(buf, "%d", column);
246         fl_set_input(fd_form_table_options->input_table_column, buf);
247         fl_deactivate_object(fd_form_table_options->input_table_column);
248         int row = table->row_of_cell(cell)+1;
249         sprintf(buf, "%d", row);
250         fl_set_input(fd_form_table_options->input_table_row, buf);
251         fl_deactivate_object(fd_form_table_options->input_table_row);
252         if (table->IsMultiColumn(cell))
253             fl_set_button(fd_form_table_options->radio_multicolumn, 1);
254         else
255             fl_set_button(fd_form_table_options->radio_multicolumn, 0);
256         if (table->RotateCell(cell))
257             fl_set_button(fd_form_table_options->radio_rotate_cell, 1);
258         else
259             fl_set_button(fd_form_table_options->radio_rotate_cell, 0);
260         if (table->TopLine(cell))
261             fl_set_button(fd_form_table_options->radio_border_top, 1);
262         else
263             fl_set_button(fd_form_table_options->radio_border_top, 0);
264         if (table->BottomLine(cell))
265             fl_set_button(fd_form_table_options->radio_border_bottom, 1);
266         else
267             fl_set_button(fd_form_table_options->radio_border_bottom, 0);
268         if (table->LeftLine(cell))
269             fl_set_button(fd_form_table_options->radio_border_left, 1);
270         else
271             fl_set_button(fd_form_table_options->radio_border_left, 0);
272         if (table->RightLine(cell))
273             fl_set_button(fd_form_table_options->radio_border_right, 1);
274         else
275             fl_set_button(fd_form_table_options->radio_border_right, 0);
276         int align = table->GetAlignment(cell);
277         fl_set_button(fd_form_table_options->radio_align_left, 0);
278         fl_set_button(fd_form_table_options->radio_align_right, 0);
279         fl_set_button(fd_form_table_options->radio_align_center, 0);
280         special = table->GetAlignSpecial(cell, LyXTable::SET_SPECIAL_COLUMN);
281         if (flag)
282         {
283             fl_set_input(fd_form_table_extra->input_special_alignment,
284                          special.c_str());
285             fl_set_input_cursorpos(fd_form_table_extra->input_special_alignment,
286                     extra_col_cursor_x, 0); // restore the cursor
287         }
288         if (current_view->buffer()->isReadonly()) 
289             fl_deactivate_object(fd_form_table_extra->input_special_alignment);
290         special = table->GetAlignSpecial(cell, LyXTable::SET_SPECIAL_MULTI);
291         if (flag)
292         {
293             fl_set_input(fd_form_table_extra->input_special_multialign,
294                          special.c_str());
295             fl_set_input_cursorpos(fd_form_table_extra->input_special_multialign,
296                     extra_multicol_cursor_x, 0); // restore the cursor
297         }
298         if (current_view->buffer()->isReadonly()) 
299             fl_deactivate_object(fd_form_table_extra->input_special_multialign);
300         pwidth = table->GetPWidth(cell);
301         if (flag)
302             fl_set_input(fd_form_table_options->input_column_width, pwidth.c_str());
303         if (current_view->buffer()->isReadonly()) 
304             fl_deactivate_object(fd_form_table_options->input_column_width);
305         if (!pwidth.empty()) {
306             fl_activate_object(fd_form_table_options->radio_linebreak_cell);
307             fl_set_object_lcol(fd_form_table_options->radio_linebreak_cell,
308                                FL_BLACK);
309             fl_set_button(fd_form_table_options->radio_linebreak_cell,
310                           table->Linebreaks(table->FirstVirtualCell(cell)));
311         } else {
312             fl_deactivate_object(fd_form_table_options->radio_linebreak_cell);
313             fl_set_object_lcol(fd_form_table_options->radio_linebreak_cell,
314                                FL_INACTIVE);
315             fl_set_button(fd_form_table_options->radio_linebreak_cell, 0);
316         }
317         if ((!pwidth.empty() && !table->IsMultiColumn(cell)) ||
318             (align == LYX_ALIGN_LEFT))
319             fl_set_button(fd_form_table_options->radio_align_left, 1);
320         else if (align == LYX_ALIGN_RIGHT)
321             fl_set_button(fd_form_table_options->radio_align_right, 1);
322         else
323             fl_set_button(fd_form_table_options->radio_align_center, 1);
324         if (!pwidth.empty() && !table->IsMultiColumn(cell)) {
325             fl_deactivate_object(fd_form_table_options->radio_align_left);
326             fl_deactivate_object(fd_form_table_options->radio_align_right);
327             fl_deactivate_object(fd_form_table_options->radio_align_center);
328             fl_set_object_lcol(fd_form_table_options->radio_align_left,
329                                FL_INACTIVE);
330             fl_set_object_lcol(fd_form_table_options->radio_align_right,
331                                FL_INACTIVE);
332             fl_set_object_lcol(fd_form_table_options->radio_align_center,
333                                FL_INACTIVE);
334         } else {
335             fl_activate_object(fd_form_table_options->radio_align_left);
336             fl_activate_object(fd_form_table_options->radio_align_right);
337             fl_activate_object(fd_form_table_options->radio_align_center);
338             fl_set_object_lcol(fd_form_table_options->radio_align_left,
339                                FL_BLACK);
340             fl_set_object_lcol(fd_form_table_options->radio_align_right,
341                                FL_BLACK);
342             fl_set_object_lcol(fd_form_table_options->radio_align_center,
343                                FL_BLACK);
344         }
345         fl_set_button(fd_form_table_options->radio_longtable, table->IsLongTable());
346         if (table->IsLongTable()) {
347             fl_activate_object(fd_form_table_options->radio_lt_firsthead);
348             fl_activate_object(fd_form_table_options->radio_lt_head);
349             fl_activate_object(fd_form_table_options->radio_lt_foot);
350             fl_activate_object(fd_form_table_options->radio_lt_lastfoot);
351             fl_activate_object(fd_form_table_options->radio_lt_newpage);
352             fl_set_object_lcol(fd_form_table_options->radio_lt_firsthead,
353                                FL_BLACK);
354             fl_set_object_lcol(fd_form_table_options->radio_lt_head,
355                                FL_BLACK);
356             fl_set_object_lcol(fd_form_table_options->radio_lt_foot,
357                                FL_BLACK);
358             fl_set_object_lcol(fd_form_table_options->radio_lt_lastfoot,
359                                FL_BLACK);
360             fl_set_object_lcol(fd_form_table_options->radio_lt_newpage,
361                                FL_BLACK);
362             fl_set_button(fd_form_table_options->radio_lt_firsthead,
363                           table->RowOfLTFirstHead(cell));
364             fl_set_button(fd_form_table_options->radio_lt_head,
365                           table->RowOfLTHead(cell));
366             fl_set_button(fd_form_table_options->radio_lt_foot,
367                           table->RowOfLTFoot(cell));
368             fl_set_button(fd_form_table_options->radio_lt_lastfoot,
369                           table->RowOfLTLastFoot(cell));
370             fl_set_button(fd_form_table_options->radio_lt_newpage,
371                           table->LTNewPage(cell));
372         } else {
373             fl_deactivate_object(fd_form_table_options->radio_lt_firsthead);
374             fl_deactivate_object(fd_form_table_options->radio_lt_head);
375             fl_deactivate_object(fd_form_table_options->radio_lt_foot);
376             fl_deactivate_object(fd_form_table_options->radio_lt_lastfoot);
377             fl_deactivate_object(fd_form_table_options->radio_lt_newpage);
378             fl_set_button(fd_form_table_options->radio_lt_firsthead, 0);
379             fl_set_button(fd_form_table_options->radio_lt_head, 0);
380             fl_set_button(fd_form_table_options->radio_lt_foot, 0);
381             fl_set_button(fd_form_table_options->radio_lt_lastfoot, 0);
382             fl_set_button(fd_form_table_options->radio_lt_newpage, 0);
383             fl_set_object_lcol(fd_form_table_options->radio_lt_firsthead,
384                                FL_INACTIVE);
385             fl_set_object_lcol(fd_form_table_options->radio_lt_head,
386                                FL_INACTIVE);
387             fl_set_object_lcol(fd_form_table_options->radio_lt_foot,
388                                FL_INACTIVE);
389             fl_set_object_lcol(fd_form_table_options->radio_lt_lastfoot,
390                                FL_INACTIVE);
391             fl_set_object_lcol(fd_form_table_options->radio_lt_newpage,
392                                FL_INACTIVE);
393         }
394         fl_set_button(fd_form_table_options->radio_rotate_table,
395                       table->RotateTable());
396         fl_set_focus_object(fd_form_table_options->form_table_options,
397                             fd_form_table_options->button_table_delete);
398     } else if (fd_form_table_options->form_table_options->visible) {
399         fl_set_focus_object(fd_form_table_options->form_table_options,
400                             fd_form_table_options->button_table_delete);
401         fl_hide_form(fd_form_table_options->form_table_options);
402     }
403     return update;
404 }
405 #endif
406
407 void OpenLayoutTableExtra()
408 {
409
410         if (fd_form_table_extra->form_table_extra->visible) {
411                 fl_raise_form(fd_form_table_extra->form_table_extra);
412         } else {
413                 static int ow = -1, oh;
414                 fl_show_form(fd_form_table_extra->form_table_extra,
415                              FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
416                              _("Table Extra Form"));
417                 if (ow < 0) {
418                         ow = fd_form_table_extra->form_table_extra->w;
419                         oh = fd_form_table_extra->form_table_extra->h;
420                 }
421                 fl_set_form_minsize(fd_form_table_extra->form_table_extra,
422                                     ow, oh);
423         }
424 }
425
426
427 void MenuLayoutTable(int flag)
428 {
429     if (UpdateLayoutTable(flag)) {
430         if (fd_form_table_options->form_table_options->visible) {
431             fl_raise_form(fd_form_table_options->form_table_options);
432         }
433         else {
434             fl_show_form(fd_form_table_options->form_table_options,
435                          FL_PLACE_MOUSE, FL_FULLBORDER,
436                          _("Table Layout"));
437         }
438     }
439 }
440
441
442 void TableOptionsCB(FL_OBJECT * ob, long)
443 {
444     LyXTable * table = 0;
445     int s, num = 0;
446     string special, str;
447
448 #ifdef MOVE_TEXT
449     if (!current_view->available()
450         || !(table = current_view->text->cursor.par->table)) {
451         MenuLayoutTable(0);
452         return;
453       }
454     int cell = current_view->text->
455         NumberOfCell(current_view->text->cursor.par, 
456                      current_view->text->cursor.pos);
457     if (ActCell != cell) {
458         MenuLayoutTable(0);
459         fl_set_object_label(fd_form_table_options->text_warning,
460                             _("Warning: Wrong Cursor position, updated window"));
461         fl_show_object(fd_form_table_options->text_warning);
462         extra_col_cursor_x = 0; // would rather place it at the end, but...
463         extra_multicol_cursor_x = 0;
464         return;
465     }
466 #else
467     if (!current_view->available()
468         ||
469         !(table = current_view->buffer()->text->cursor.par->table)) {
470         MenuLayoutTable(0);
471         return;
472       }
473     int cell = current_view->buffer()->text->
474         NumberOfCell(current_view->buffer()->text->cursor.par, 
475                      current_view->buffer()->text->cursor.pos);
476     if (ActCell != cell) {
477         MenuLayoutTable(0);
478         fl_set_object_label(fd_form_table_options->text_warning,
479                             _("Warning: Wrong Cursor position, updated window"));
480         fl_show_object(fd_form_table_options->text_warning);
481         extra_col_cursor_x = 0; // would rather place it at the end, but...
482         extra_multicol_cursor_x = 0;
483         return;
484     }
485 #endif
486     // No point in processing directives that you can't do anything with
487     // anyhow, so exit now if the buffer is read-only.
488     if (current_view->buffer()->isReadonly()) {
489       MenuLayoutTable(0);
490       return;
491     }
492     
493     if (ob != fd_form_table_options->button_table_delete) {
494         fl_set_object_label(fd_form_table_options->text_warning, "");
495         Confirmed = false;
496     }
497     str = fl_get_input(fd_form_table_options->input_column_width);
498     if (!str.empty() && !isValidLength(str)) {
499         fl_set_object_label(fd_form_table_options->text_warning,
500                             _("Warning: Invalid Length (valid example: 10mm)"));
501         fl_show_object(fd_form_table_options->text_warning);
502         return;
503     }
504     if (((ob == fd_form_table_options->button_delete_row) && (table->rows<= 1)) ||
505         ((ob == fd_form_table_options->button_delete_column) && (table->columns<= 1)))
506         ob = fd_form_table_options->button_table_delete;
507     if (ob == fd_form_table_options->button_append_row)
508         num = LyXTable::APPEND_ROW;
509     else if (ob == fd_form_table_options->button_append_column)
510         num = LyXTable::APPEND_COLUMN;
511     else if (ob == fd_form_table_options->button_delete_row)
512         num = LyXTable::DELETE_ROW;
513     else if (ob == fd_form_table_options->button_delete_column)
514         num = LyXTable::DELETE_COLUMN;
515     else if (ob == fd_form_table_options->button_set_borders)
516         num = LyXTable::SET_ALL_LINES;
517     else if (ob == fd_form_table_options->button_unset_borders)
518         num = LyXTable::UNSET_ALL_LINES;
519     else if (ob == fd_form_table_options->radio_border_top)
520         num = LyXTable::TOGGLE_LINE_TOP;
521     else if (ob == fd_form_table_options->radio_border_bottom)
522         num = LyXTable::TOGGLE_LINE_BOTTOM;
523     else if (ob == fd_form_table_options->radio_border_left)
524         num = LyXTable::TOGGLE_LINE_LEFT;
525     else if (ob == fd_form_table_options->radio_border_right)
526         num = LyXTable::TOGGLE_LINE_RIGHT;
527     else if (ob == fd_form_table_options->radio_align_left)
528         num = LyXTable::ALIGN_LEFT;
529     else if (ob == fd_form_table_options->radio_align_right)
530         num = LyXTable::ALIGN_RIGHT;
531     else if (ob == fd_form_table_options->radio_align_center)
532         num = LyXTable::ALIGN_CENTER;
533     else if ((ob == fd_form_table_options->button_table_delete) && !Confirmed) {
534         fl_set_object_label(fd_form_table_options->text_warning,
535                             _("Confirm: press Delete-Button again"));
536         Confirmed = true;
537         return;
538     } else if ((ob == fd_form_table_options->button_table_delete) 
539                && Confirmed) {
540         num = LyXTable::DELETE_TABLE;
541         Confirmed = false;
542     } else if (ob == fd_form_table_options->radio_multicolumn)
543         num = LyXTable::MULTICOLUMN;
544     else if (ob == fd_form_table_options->radio_longtable) {
545         s = fl_get_button(fd_form_table_options->radio_longtable);
546         if (s) {
547             num = LyXTable::SET_LONGTABLE;
548             fl_activate_object(fd_form_table_options->radio_lt_firsthead);
549             fl_activate_object(fd_form_table_options->radio_lt_head);
550             fl_activate_object(fd_form_table_options->radio_lt_foot);
551             fl_activate_object(fd_form_table_options->radio_lt_lastfoot);
552             fl_activate_object(fd_form_table_options->radio_lt_newpage);
553             fl_set_button(fd_form_table_options->radio_lt_firsthead,
554                           table->RowOfLTFirstHead(cell));
555             fl_set_button(fd_form_table_options->radio_lt_head,
556                           table->RowOfLTHead(cell));
557             fl_set_button(fd_form_table_options->radio_lt_foot,
558                           table->RowOfLTFoot(cell));
559             fl_set_button(fd_form_table_options->radio_lt_lastfoot,
560                           table->RowOfLTLastFoot(cell));
561             fl_set_button(fd_form_table_options->radio_lt_firsthead,
562                           table->LTNewPage(cell));
563         } else {
564             num = LyXTable::UNSET_LONGTABLE;
565             fl_deactivate_object(fd_form_table_options->radio_lt_firsthead);
566             fl_deactivate_object(fd_form_table_options->radio_lt_head);
567             fl_deactivate_object(fd_form_table_options->radio_lt_foot);
568             fl_deactivate_object(fd_form_table_options->radio_lt_lastfoot);
569             fl_deactivate_object(fd_form_table_options->radio_lt_newpage);
570             fl_set_button(fd_form_table_options->radio_lt_firsthead, 0);
571             fl_set_button(fd_form_table_options->radio_lt_firsthead, 0);
572             fl_set_button(fd_form_table_options->radio_lt_firsthead, 0);
573             fl_set_button(fd_form_table_options->radio_lt_firsthead, 0);
574             fl_set_button(fd_form_table_options->radio_lt_firsthead, 0);
575             fl_set_object_lcol(fd_form_table_options->radio_lt_firsthead,
576                                FL_INACTIVE);
577             fl_set_object_lcol(fd_form_table_options->radio_lt_head,
578                                FL_INACTIVE);
579             fl_set_object_lcol(fd_form_table_options->radio_lt_foot,
580                                FL_INACTIVE);
581             fl_set_object_lcol(fd_form_table_options->radio_lt_lastfoot,
582                                FL_INACTIVE);
583             fl_set_object_lcol(fd_form_table_options->radio_lt_newpage,
584                                FL_INACTIVE);
585         }
586     } else if (ob == fd_form_table_options->radio_rotate_table) {
587         s = fl_get_button(fd_form_table_options->radio_rotate_table);
588         if (s)
589             num = LyXTable::SET_ROTATE_TABLE;
590         else
591             num = LyXTable::UNSET_ROTATE_TABLE;
592     } else if (ob == fd_form_table_options->radio_rotate_cell) {
593         s = fl_get_button(fd_form_table_options->radio_rotate_cell);
594         if (s)
595             num = LyXTable::SET_ROTATE_CELL;
596         else
597             num = LyXTable::UNSET_ROTATE_CELL;
598     } else if (ob == fd_form_table_options->radio_linebreak_cell) {
599         num = LyXTable::SET_LINEBREAKS;
600     } else if (ob == fd_form_table_options->radio_lt_firsthead) {
601         num = LyXTable::SET_LTFIRSTHEAD;
602     } else if (ob == fd_form_table_options->radio_lt_head) {
603         num = LyXTable::SET_LTHEAD;
604     } else if (ob == fd_form_table_options->radio_lt_foot) {
605         num = LyXTable::SET_LTFOOT;
606     } else if (ob == fd_form_table_options->radio_lt_lastfoot) {
607         num = LyXTable::SET_LTLASTFOOT;
608     } else if (ob == fd_form_table_options->radio_lt_newpage) {
609         num = LyXTable::SET_LTNEWPAGE;
610     } else if (ob == fd_form_table_options->button_table_extra) {
611         OpenLayoutTableExtra();
612         return;
613     } else if (ob == fd_form_table_extra->input_special_alignment) {
614         special = fl_get_input(fd_form_table_extra->input_special_alignment);
615         int dummy;
616         fl_get_input_cursorpos(ob, &extra_col_cursor_x, &dummy);
617         num = LyXTable::SET_SPECIAL_COLUMN;
618     } else if (ob == fd_form_table_extra->input_special_multialign) {
619         special = fl_get_input(fd_form_table_extra->input_special_multialign);
620         int dummy;
621         fl_get_input_cursorpos(ob, &extra_multicol_cursor_x, &dummy);
622         num = LyXTable::SET_SPECIAL_MULTI;
623     } else
624         return;
625     if (current_view->available()){
626         current_view->getScreen()->HideCursor();
627 #ifdef MOVE_TEXT
628         if (!current_view->text->selection){
629             BeforeChange(); 
630             current_view->update(-2);
631         }
632         if ((num == LyXTable::SET_SPECIAL_COLUMN) ||
633             (num == LyXTable::SET_SPECIAL_MULTI))
634             current_view->text->TableFeatures(num, special);
635         else
636             current_view->text->TableFeatures(num);
637         current_view->update(1);
638 #else
639         if (!current_view->buffer()->text->selection){
640             BeforeChange(); 
641             current_view->buffer()->update(-2);
642         }
643         if ((num == LyXTable::SET_SPECIAL_COLUMN) ||
644             (num == LyXTable::SET_SPECIAL_MULTI))
645             current_view->buffer()->text->TableFeatures(num, special);
646         else
647             current_view->buffer()->text->TableFeatures(num);
648         current_view->buffer()->update(1);
649 #endif
650     }
651     if (num == LyXTable::DELETE_TABLE) {
652         fl_set_focus_object(fd_form_table_options->form_table_options,
653                             fd_form_table_options->button_table_delete);
654         fl_hide_form(fd_form_table_options->form_table_options);
655     } else
656         UpdateLayoutTable(true);
657     return;
658 }
659
660 void TableOptCloseCB(FL_OBJECT *, long)
661 {
662     fl_set_focus_object(fd_form_table_options->form_table_options,
663                         fd_form_table_options->button_table_delete);
664     fl_hide_form(fd_form_table_options->form_table_options);
665     return;
666 }
667
668 void TableSpeCloseCB(FL_OBJECT *, long)
669 {
670     fl_set_focus_object(fd_form_table_options->form_table_options,
671                         fd_form_table_options->button_table_delete);
672     fl_hide_form(fd_form_table_extra->form_table_extra);
673     return;
674 }
675
676 void SetPWidthCB(FL_OBJECT *ob, long)
677 {
678     fl_set_object_label(fd_form_table_options->text_warning, "");
679     Confirmed = false;
680     if (ob == fd_form_table_options->input_column_width) {
681         string
682             str;
683         str = fl_get_input(ob);
684         if (!str.empty() && !isValidLength(str)) {
685             fl_set_object_label(fd_form_table_options->text_warning,
686                             _("Warning: Invalid Length (valid example: 10mm)"));
687             fl_show_object(fd_form_table_options->text_warning);
688             return;
689         }
690         if (current_view->available()){
691             current_view->getScreen()->HideCursor();
692 #ifdef MOVE_TEXT
693             if (!current_view->text->selection){
694                 BeforeChange(); 
695                 current_view->update(-2);
696             }
697             current_view->text->TableFeatures(LyXTable::SET_PWIDTH, str);
698             current_view->update(1);
699 #else
700             if (!current_view->buffer()->text->selection){
701                 BeforeChange(); 
702                 current_view->buffer()->update(-2);
703             }
704             current_view->buffer()->text->TableFeatures(LyXTable::SET_PWIDTH, str);
705             current_view->buffer()->update(1);
706 #endif
707         }
708         MenuLayoutTable(0); // update for alignment
709     }
710 }