4 #include "definitions.h"
5 #include FORMS_H_LOCATION
6 #include "layout_forms.h"
10 #include "support/filetools.h"
13 #include "lyx_gui_misc.h"
14 #include "BufferView.h"
15 #include "lyxscreen.h"
20 extern void BeforeChange();
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;
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)
36 extra_col_cursor_x, // need no y's, one-line input fields
37 extra_multicol_cursor_x;
40 bool UpdateLayoutTable(int flag)
43 if (!current_view->getScreen() || !current_view->available())
46 if (update && current_view->buffer()->text->cursor.par->table) {
55 LyXTable * table = current_view->buffer()->text->cursor.par->table;
57 int cell = current_view->buffer()->text->
58 NumberOfCell(current_view->buffer()->text->cursor.par,
59 current_view->buffer()->text->cursor.pos);
61 column = table->column_of_cell(cell)+1;
62 fl_set_object_label(fd_form_table_options->text_warning,"");
64 fl_activate_object(fd_form_table_extra->input_special_alignment);
65 fl_activate_object(fd_form_table_extra->input_special_multialign);
66 fl_activate_object(fd_form_table_options->input_column_width);
67 sprintf(buf,"%d",column);
68 fl_set_input(fd_form_table_options->input_table_column, buf);
69 fl_deactivate_object(fd_form_table_options->input_table_column);
70 row = table->row_of_cell(cell)+1;
71 sprintf(buf,"%d",row);
72 fl_set_input(fd_form_table_options->input_table_row, buf);
73 fl_deactivate_object(fd_form_table_options->input_table_row);
74 if (table->IsMultiColumn(cell))
75 fl_set_button(fd_form_table_options->radio_multicolumn, 1);
77 fl_set_button(fd_form_table_options->radio_multicolumn, 0);
78 if (table->RotateCell(cell))
79 fl_set_button(fd_form_table_options->radio_rotate_cell, 1);
81 fl_set_button(fd_form_table_options->radio_rotate_cell, 0);
82 if (table->TopLine(cell))
83 fl_set_button(fd_form_table_options->radio_border_top, 1);
85 fl_set_button(fd_form_table_options->radio_border_top, 0);
86 if (table->BottomLine(cell))
87 fl_set_button(fd_form_table_options->radio_border_bottom, 1);
89 fl_set_button(fd_form_table_options->radio_border_bottom, 0);
90 if (table->LeftLine(cell))
91 fl_set_button(fd_form_table_options->radio_border_left, 1);
93 fl_set_button(fd_form_table_options->radio_border_left, 0);
94 if (table->RightLine(cell))
95 fl_set_button(fd_form_table_options->radio_border_right, 1);
97 fl_set_button(fd_form_table_options->radio_border_right, 0);
98 align = table->GetAlignment(cell);
99 fl_set_button(fd_form_table_options->radio_align_left, 0);
100 fl_set_button(fd_form_table_options->radio_align_right, 0);
101 fl_set_button(fd_form_table_options->radio_align_center, 0);
102 special = table->GetAlignSpecial(cell,LyXTable::SET_SPECIAL_COLUMN);
105 fl_set_input(fd_form_table_extra->input_special_alignment,
107 fl_set_input_cursorpos(fd_form_table_extra->input_special_alignment,
108 extra_col_cursor_x, 0); // restore the cursor
110 if (current_view->buffer()->isReadonly())
111 fl_deactivate_object(fd_form_table_extra->input_special_alignment);
112 special = table->GetAlignSpecial(cell,LyXTable::SET_SPECIAL_MULTI);
115 fl_set_input(fd_form_table_extra->input_special_multialign,
117 fl_set_input_cursorpos(fd_form_table_extra->input_special_multialign,
118 extra_multicol_cursor_x, 0); // restore the cursor
120 if (current_view->buffer()->isReadonly())
121 fl_deactivate_object(fd_form_table_extra->input_special_multialign);
122 pwidth = table->GetPWidth(cell);
124 fl_set_input(fd_form_table_options->input_column_width,pwidth.c_str());
125 if (current_view->buffer()->isReadonly())
126 fl_deactivate_object(fd_form_table_options->input_column_width);
127 if (!pwidth.empty()) {
128 fl_activate_object(fd_form_table_options->radio_linebreak_cell);
129 fl_set_object_lcol(fd_form_table_options->radio_linebreak_cell,
131 fl_set_button(fd_form_table_options->radio_linebreak_cell,
132 table->Linebreaks(table->FirstVirtualCell(cell)));
134 fl_deactivate_object(fd_form_table_options->radio_linebreak_cell);
135 fl_set_object_lcol(fd_form_table_options->radio_linebreak_cell,
137 fl_set_button(fd_form_table_options->radio_linebreak_cell,0);
139 if ((!pwidth.empty() && !table->IsMultiColumn(cell)) ||
140 (align == LYX_ALIGN_LEFT))
141 fl_set_button(fd_form_table_options->radio_align_left, 1);
142 else if (align == LYX_ALIGN_RIGHT)
143 fl_set_button(fd_form_table_options->radio_align_right, 1);
145 fl_set_button(fd_form_table_options->radio_align_center, 1);
146 if (!pwidth.empty() && !table->IsMultiColumn(cell)) {
147 fl_deactivate_object(fd_form_table_options->radio_align_left);
148 fl_deactivate_object(fd_form_table_options->radio_align_right);
149 fl_deactivate_object(fd_form_table_options->radio_align_center);
150 fl_set_object_lcol(fd_form_table_options->radio_align_left,
152 fl_set_object_lcol(fd_form_table_options->radio_align_right,
154 fl_set_object_lcol(fd_form_table_options->radio_align_center,
157 fl_activate_object(fd_form_table_options->radio_align_left);
158 fl_activate_object(fd_form_table_options->radio_align_right);
159 fl_activate_object(fd_form_table_options->radio_align_center);
160 fl_set_object_lcol(fd_form_table_options->radio_align_left,
162 fl_set_object_lcol(fd_form_table_options->radio_align_right,
164 fl_set_object_lcol(fd_form_table_options->radio_align_center,
167 fl_set_button(fd_form_table_options->radio_longtable,table->IsLongTable());
168 if (table->IsLongTable()) {
169 fl_activate_object(fd_form_table_options->radio_lt_firsthead);
170 fl_activate_object(fd_form_table_options->radio_lt_head);
171 fl_activate_object(fd_form_table_options->radio_lt_foot);
172 fl_activate_object(fd_form_table_options->radio_lt_lastfoot);
173 fl_activate_object(fd_form_table_options->radio_lt_newpage);
174 fl_set_object_lcol(fd_form_table_options->radio_lt_firsthead,
176 fl_set_object_lcol(fd_form_table_options->radio_lt_head,
178 fl_set_object_lcol(fd_form_table_options->radio_lt_foot,
180 fl_set_object_lcol(fd_form_table_options->radio_lt_lastfoot,
182 fl_set_object_lcol(fd_form_table_options->radio_lt_newpage,
184 fl_set_button(fd_form_table_options->radio_lt_firsthead,
185 table->RowOfLTFirstHead(cell));
186 fl_set_button(fd_form_table_options->radio_lt_head,
187 table->RowOfLTHead(cell));
188 fl_set_button(fd_form_table_options->radio_lt_foot,
189 table->RowOfLTFoot(cell));
190 fl_set_button(fd_form_table_options->radio_lt_lastfoot,
191 table->RowOfLTLastFoot(cell));
192 fl_set_button(fd_form_table_options->radio_lt_newpage,
193 table->LTNewPage(cell));
195 fl_deactivate_object(fd_form_table_options->radio_lt_firsthead);
196 fl_deactivate_object(fd_form_table_options->radio_lt_head);
197 fl_deactivate_object(fd_form_table_options->radio_lt_foot);
198 fl_deactivate_object(fd_form_table_options->radio_lt_lastfoot);
199 fl_deactivate_object(fd_form_table_options->radio_lt_newpage);
200 fl_set_button(fd_form_table_options->radio_lt_firsthead,0);
201 fl_set_button(fd_form_table_options->radio_lt_head,0);
202 fl_set_button(fd_form_table_options->radio_lt_foot,0);
203 fl_set_button(fd_form_table_options->radio_lt_lastfoot,0);
204 fl_set_button(fd_form_table_options->radio_lt_newpage,0);
205 fl_set_object_lcol(fd_form_table_options->radio_lt_firsthead,
207 fl_set_object_lcol(fd_form_table_options->radio_lt_head,
209 fl_set_object_lcol(fd_form_table_options->radio_lt_foot,
211 fl_set_object_lcol(fd_form_table_options->radio_lt_lastfoot,
213 fl_set_object_lcol(fd_form_table_options->radio_lt_newpage,
216 fl_set_button(fd_form_table_options->radio_rotate_table,
217 table->RotateTable());
218 fl_set_focus_object(fd_form_table_options->form_table_options,
219 fd_form_table_options->button_table_delete);
220 } else if (fd_form_table_options->form_table_options->visible) {
221 fl_set_focus_object(fd_form_table_options->form_table_options,
222 fd_form_table_options->button_table_delete);
223 fl_hide_form(fd_form_table_options->form_table_options);
228 void OpenLayoutTableExtra()
230 static int ow = -1, oh;
232 if (fd_form_table_extra->form_table_extra->visible) {
233 fl_raise_form(fd_form_table_extra->form_table_extra);
235 fl_show_form(fd_form_table_extra->form_table_extra,
236 FL_PLACE_MOUSE | FL_FREE_SIZE,FL_FULLBORDER,
237 _("Table Extra Form"));
239 ow = fd_form_table_extra->form_table_extra->w;
240 oh = fd_form_table_extra->form_table_extra->h;
242 fl_set_form_minsize(fd_form_table_extra->form_table_extra,
247 void MenuLayoutTable(int flag)
249 if (UpdateLayoutTable(flag)) {
250 if (fd_form_table_options->form_table_options->visible) {
251 fl_raise_form(fd_form_table_options->form_table_options);
254 fl_show_form(fd_form_table_options->form_table_options,
255 FL_PLACE_MOUSE, FL_FULLBORDER,
261 void TableOptionsCB(FL_OBJECT *ob, long)
272 if (!current_view->available()
274 !(table = current_view->buffer()->text->cursor.par->table))
279 int cell = current_view->buffer()->text->
280 NumberOfCell(current_view->buffer()->text->cursor.par,
281 current_view->buffer()->text->cursor.pos);
282 if (ActCell != cell) {
284 fl_set_object_label(fd_form_table_options->text_warning,
285 _("Warning: Wrong Cursor position, updated window"));
286 fl_show_object(fd_form_table_options->text_warning);
287 extra_col_cursor_x=0; // would rather place it at the end, but...
288 extra_multicol_cursor_x=0;
291 // No point in processing directives that you can't do anything with
292 // anyhow, so exit now if the buffer is read-only.
293 if (current_view->buffer()->isReadonly()) {
298 if (ob != fd_form_table_options->button_table_delete) {
299 fl_set_object_label(fd_form_table_options->text_warning,"");
302 str = fl_get_input(fd_form_table_options->input_column_width);
303 if (!str.empty() && !isValidLength(str)) {
304 fl_set_object_label(fd_form_table_options->text_warning,
305 _("Warning: Invalid Length (valid example: 10mm)"));
306 fl_show_object(fd_form_table_options->text_warning);
309 if (((ob==fd_form_table_options->button_delete_row) && (table->rows<=1)) ||
310 ((ob==fd_form_table_options->button_delete_column) && (table->columns<=1)))
311 ob = fd_form_table_options->button_table_delete;
312 if (ob == fd_form_table_options->button_append_row)
313 num = LyXTable::APPEND_ROW;
314 else if (ob == fd_form_table_options->button_append_column)
315 num = LyXTable::APPEND_COLUMN;
316 else if (ob == fd_form_table_options->button_delete_row)
317 num = LyXTable::DELETE_ROW;
318 else if (ob == fd_form_table_options->button_delete_column)
319 num = LyXTable::DELETE_COLUMN;
320 else if (ob == fd_form_table_options->button_set_borders)
321 num = LyXTable::SET_ALL_LINES;
322 else if (ob == fd_form_table_options->button_unset_borders)
323 num = LyXTable::UNSET_ALL_LINES;
324 else if (ob == fd_form_table_options->radio_border_top)
325 num = LyXTable::TOGGLE_LINE_TOP;
326 else if (ob == fd_form_table_options->radio_border_bottom)
327 num = LyXTable::TOGGLE_LINE_BOTTOM;
328 else if (ob == fd_form_table_options->radio_border_left)
329 num = LyXTable::TOGGLE_LINE_LEFT;
330 else if (ob == fd_form_table_options->radio_border_right)
331 num = LyXTable::TOGGLE_LINE_RIGHT;
332 else if (ob == fd_form_table_options->radio_align_left)
333 num = LyXTable::ALIGN_LEFT;
334 else if (ob == fd_form_table_options->radio_align_right)
335 num = LyXTable::ALIGN_RIGHT;
336 else if (ob == fd_form_table_options->radio_align_center)
337 num = LyXTable::ALIGN_CENTER;
338 else if ((ob==fd_form_table_options->button_table_delete) && !Confirmed) {
339 fl_set_object_label(fd_form_table_options->text_warning,
340 _("Confirm: press Delete-Button again"));
343 } else if ((ob == fd_form_table_options->button_table_delete)
345 num = LyXTable::DELETE_TABLE;
347 } else if (ob == fd_form_table_options->radio_multicolumn)
348 num = LyXTable::MULTICOLUMN;
349 else if (ob == fd_form_table_options->radio_longtable) {
350 s=fl_get_button(fd_form_table_options->radio_longtable);
352 num = LyXTable::SET_LONGTABLE;
353 fl_activate_object(fd_form_table_options->radio_lt_firsthead);
354 fl_activate_object(fd_form_table_options->radio_lt_head);
355 fl_activate_object(fd_form_table_options->radio_lt_foot);
356 fl_activate_object(fd_form_table_options->radio_lt_lastfoot);
357 fl_activate_object(fd_form_table_options->radio_lt_newpage);
358 fl_set_button(fd_form_table_options->radio_lt_firsthead,
359 table->RowOfLTFirstHead(cell));
360 fl_set_button(fd_form_table_options->radio_lt_head,
361 table->RowOfLTHead(cell));
362 fl_set_button(fd_form_table_options->radio_lt_foot,
363 table->RowOfLTFoot(cell));
364 fl_set_button(fd_form_table_options->radio_lt_lastfoot,
365 table->RowOfLTLastFoot(cell));
366 fl_set_button(fd_form_table_options->radio_lt_firsthead,
367 table->LTNewPage(cell));
369 num = LyXTable::UNSET_LONGTABLE;
370 fl_deactivate_object(fd_form_table_options->radio_lt_firsthead);
371 fl_deactivate_object(fd_form_table_options->radio_lt_head);
372 fl_deactivate_object(fd_form_table_options->radio_lt_foot);
373 fl_deactivate_object(fd_form_table_options->radio_lt_lastfoot);
374 fl_deactivate_object(fd_form_table_options->radio_lt_newpage);
375 fl_set_button(fd_form_table_options->radio_lt_firsthead,0);
376 fl_set_button(fd_form_table_options->radio_lt_firsthead,0);
377 fl_set_button(fd_form_table_options->radio_lt_firsthead,0);
378 fl_set_button(fd_form_table_options->radio_lt_firsthead,0);
379 fl_set_button(fd_form_table_options->radio_lt_firsthead,0);
380 fl_set_object_lcol(fd_form_table_options->radio_lt_firsthead,
382 fl_set_object_lcol(fd_form_table_options->radio_lt_head,
384 fl_set_object_lcol(fd_form_table_options->radio_lt_foot,
386 fl_set_object_lcol(fd_form_table_options->radio_lt_lastfoot,
388 fl_set_object_lcol(fd_form_table_options->radio_lt_newpage,
391 } else if (ob == fd_form_table_options->radio_rotate_table) {
392 s=fl_get_button(fd_form_table_options->radio_rotate_table);
394 num = LyXTable::SET_ROTATE_TABLE;
396 num = LyXTable::UNSET_ROTATE_TABLE;
397 } else if (ob == fd_form_table_options->radio_rotate_cell) {
398 s=fl_get_button(fd_form_table_options->radio_rotate_cell);
400 num = LyXTable::SET_ROTATE_CELL;
402 num = LyXTable::UNSET_ROTATE_CELL;
403 } else if (ob == fd_form_table_options->radio_linebreak_cell) {
404 num = LyXTable::SET_LINEBREAKS;
405 } else if (ob == fd_form_table_options->radio_lt_firsthead) {
406 num = LyXTable::SET_LTFIRSTHEAD;
407 } else if (ob == fd_form_table_options->radio_lt_head) {
408 num = LyXTable::SET_LTHEAD;
409 } else if (ob == fd_form_table_options->radio_lt_foot) {
410 num = LyXTable::SET_LTFOOT;
411 } else if (ob == fd_form_table_options->radio_lt_lastfoot) {
412 num = LyXTable::SET_LTLASTFOOT;
413 } else if (ob == fd_form_table_options->radio_lt_newpage) {
414 num = LyXTable::SET_LTNEWPAGE;
415 } else if (ob == fd_form_table_options->button_table_extra) {
416 OpenLayoutTableExtra();
418 } else if (ob == fd_form_table_extra->input_special_alignment) {
419 special=fl_get_input(fd_form_table_extra->input_special_alignment);
421 fl_get_input_cursorpos(ob, &extra_col_cursor_x, &dummy);
422 num = LyXTable::SET_SPECIAL_COLUMN;
423 } else if (ob == fd_form_table_extra->input_special_multialign) {
424 special=fl_get_input(fd_form_table_extra->input_special_multialign);
426 fl_get_input_cursorpos(ob, &extra_multicol_cursor_x, &dummy);
427 num = LyXTable::SET_SPECIAL_MULTI;
430 if (current_view->available()){
431 current_view->getScreen()->HideCursor();
432 if (!current_view->buffer()->text->selection){
434 current_view->buffer()->update(-2);
436 if ((num == LyXTable::SET_SPECIAL_COLUMN) ||
437 (num == LyXTable::SET_SPECIAL_MULTI))
438 current_view->buffer()->text->TableFeatures(num,special);
440 current_view->buffer()->text->TableFeatures(num);
441 current_view->buffer()->update(1);
443 if (num == LyXTable::DELETE_TABLE) {
444 fl_set_focus_object(fd_form_table_options->form_table_options,
445 fd_form_table_options->button_table_delete);
446 fl_hide_form(fd_form_table_options->form_table_options);
448 UpdateLayoutTable(true);
452 void TableOptCloseCB(FL_OBJECT *, long)
454 fl_set_focus_object(fd_form_table_options->form_table_options,
455 fd_form_table_options->button_table_delete);
456 fl_hide_form(fd_form_table_options->form_table_options);
460 void TableSpeCloseCB(FL_OBJECT *, long)
462 fl_set_focus_object(fd_form_table_options->form_table_options,
463 fd_form_table_options->button_table_delete);
464 fl_hide_form(fd_form_table_extra->form_table_extra);
468 void SetPWidthCB(FL_OBJECT *ob, long)
470 fl_set_object_label(fd_form_table_options->text_warning,"");
472 if (ob == fd_form_table_options->input_column_width) {
475 str = fl_get_input(ob);
476 if (!str.empty() && !isValidLength(str)) {
477 fl_set_object_label(fd_form_table_options->text_warning,
478 _("Warning: Invalid Length (valid example: 10mm)"));
479 fl_show_object(fd_form_table_options->text_warning);
482 if (current_view->available()){
483 current_view->getScreen()->HideCursor();
484 if (!current_view->buffer()->text->selection){
486 current_view->buffer()->update(-2);
488 current_view->buffer()->text->TableFeatures(LyXTable::SET_PWIDTH,str);
489 current_view->buffer()->update(1);
491 MenuLayoutTable(0); // update for alignment