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"
19 extern void BeforeChange();
22 extern FD_form_table_options *fd_form_table_options;
23 extern FD_form_table_extra *fd_form_table_extra;
24 extern BufferView *current_view;
29 // hack to keep the cursor from jumping to the end of the text in the Extra
30 // form input fields during editing. The values in LyXTable itself is changed in
31 // real-time, but we have no callbacks for the input fields, so I simply
32 // store and restore the cursor position for now. (too much of a hazzle to
33 // do it proper; we'll trash all this code in 1.1 anyway)
35 extra_col_cursor_x, // need no y's, one-line input fields
36 extra_multicol_cursor_x;
39 bool UpdateLayoutTable(int flag)
42 if (!current_view->getScreen() || !current_view->available())
45 if (update && current_view->currentBuffer()->text->cursor.par->table) {
55 LyXTable *table = current_view->currentBuffer()->text->cursor.par->table;
57 cell = current_view->currentBuffer()->text->
58 NumberOfCell(current_view->currentBuffer()->text->cursor.par,
59 current_view->currentBuffer()->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->currentBuffer()->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->currentBuffer()->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->currentBuffer()->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 if (fd_form_table_extra->form_table_extra->visible) {
231 fl_raise_form(fd_form_table_extra->form_table_extra);
233 fl_show_form(fd_form_table_extra->form_table_extra,
234 FL_PLACE_MOUSE | FL_FREE_SIZE,FL_FULLBORDER,
235 _("Table Extra Form"));
239 void MenuLayoutTable(int flag)
241 if (UpdateLayoutTable(flag)) {
242 if (fd_form_table_options->form_table_options->visible) {
243 fl_raise_form(fd_form_table_options->form_table_options);
246 fl_show_form(fd_form_table_options->form_table_options,
247 FL_PLACE_MOUSE | FL_FREE_SIZE,FL_FULLBORDER,
253 void TableOptionsCB(FL_OBJECT *ob, long)
265 if (!current_view->available()
267 !(table = current_view->currentBuffer()->text->cursor.par->table))
272 cell = current_view->currentBuffer()->text->
273 NumberOfCell(current_view->currentBuffer()->text->cursor.par,
274 current_view->currentBuffer()->text->cursor.pos);
275 if (ActCell != cell) {
277 fl_set_object_label(fd_form_table_options->text_warning,
278 _("Warning: Wrong Cursor position, updated window"));
279 fl_show_object(fd_form_table_options->text_warning);
280 extra_col_cursor_x=0; // would rather place it at the end, but...
281 extra_multicol_cursor_x=0;
284 // No point in processing directives that you can't do anything with
285 // anyhow, so exit now if the buffer is read-only.
286 if (current_view->currentBuffer()->isReadonly()) {
291 if (ob != fd_form_table_options->button_table_delete) {
292 fl_set_object_label(fd_form_table_options->text_warning,"");
295 str = fl_get_input(fd_form_table_options->input_column_width);
296 if (!str.empty() && !isValidLength(str)) {
297 fl_set_object_label(fd_form_table_options->text_warning,
298 _("Warning: Invalid Length (valid example: 10mm)"));
299 fl_show_object(fd_form_table_options->text_warning);
302 if (((ob==fd_form_table_options->button_delete_row) && (table->rows<=1)) ||
303 ((ob==fd_form_table_options->button_delete_column) && (table->columns<=1)))
304 ob = fd_form_table_options->button_table_delete;
305 if (ob == fd_form_table_options->button_append_row)
306 num = LyXTable::APPEND_ROW;
307 else if (ob == fd_form_table_options->button_append_column)
308 num = LyXTable::APPEND_COLUMN;
309 else if (ob == fd_form_table_options->button_delete_row)
310 num = LyXTable::DELETE_ROW;
311 else if (ob == fd_form_table_options->button_delete_column)
312 num = LyXTable::DELETE_COLUMN;
313 else if (ob == fd_form_table_options->button_set_borders)
314 num = LyXTable::SET_ALL_LINES;
315 else if (ob == fd_form_table_options->button_unset_borders)
316 num = LyXTable::UNSET_ALL_LINES;
317 else if (ob == fd_form_table_options->radio_border_top)
318 num = LyXTable::TOGGLE_LINE_TOP;
319 else if (ob == fd_form_table_options->radio_border_bottom)
320 num = LyXTable::TOGGLE_LINE_BOTTOM;
321 else if (ob == fd_form_table_options->radio_border_left)
322 num = LyXTable::TOGGLE_LINE_LEFT;
323 else if (ob == fd_form_table_options->radio_border_right)
324 num = LyXTable::TOGGLE_LINE_RIGHT;
325 else if (ob == fd_form_table_options->radio_align_left)
326 num = LyXTable::ALIGN_LEFT;
327 else if (ob == fd_form_table_options->radio_align_right)
328 num = LyXTable::ALIGN_RIGHT;
329 else if (ob == fd_form_table_options->radio_align_center)
330 num = LyXTable::ALIGN_CENTER;
331 else if ((ob==fd_form_table_options->button_table_delete) && !Confirmed) {
332 fl_set_object_label(fd_form_table_options->text_warning,
333 _("Confirm: press Delete-Button again"));
336 } else if ((ob == fd_form_table_options->button_table_delete)
338 num = LyXTable::DELETE_TABLE;
340 } else if (ob == fd_form_table_options->radio_multicolumn)
341 num = LyXTable::MULTICOLUMN;
342 else if (ob == fd_form_table_options->radio_longtable) {
343 s=fl_get_button(fd_form_table_options->radio_longtable);
345 num = LyXTable::SET_LONGTABLE;
346 fl_activate_object(fd_form_table_options->radio_lt_firsthead);
347 fl_activate_object(fd_form_table_options->radio_lt_head);
348 fl_activate_object(fd_form_table_options->radio_lt_foot);
349 fl_activate_object(fd_form_table_options->radio_lt_lastfoot);
350 fl_activate_object(fd_form_table_options->radio_lt_newpage);
351 fl_set_button(fd_form_table_options->radio_lt_firsthead,
352 table->RowOfLTFirstHead(cell));
353 fl_set_button(fd_form_table_options->radio_lt_head,
354 table->RowOfLTHead(cell));
355 fl_set_button(fd_form_table_options->radio_lt_foot,
356 table->RowOfLTFoot(cell));
357 fl_set_button(fd_form_table_options->radio_lt_lastfoot,
358 table->RowOfLTLastFoot(cell));
359 fl_set_button(fd_form_table_options->radio_lt_firsthead,
360 table->LTNewPage(cell));
362 num = LyXTable::UNSET_LONGTABLE;
363 fl_deactivate_object(fd_form_table_options->radio_lt_firsthead);
364 fl_deactivate_object(fd_form_table_options->radio_lt_head);
365 fl_deactivate_object(fd_form_table_options->radio_lt_foot);
366 fl_deactivate_object(fd_form_table_options->radio_lt_lastfoot);
367 fl_deactivate_object(fd_form_table_options->radio_lt_newpage);
368 fl_set_button(fd_form_table_options->radio_lt_firsthead,0);
369 fl_set_button(fd_form_table_options->radio_lt_firsthead,0);
370 fl_set_button(fd_form_table_options->radio_lt_firsthead,0);
371 fl_set_button(fd_form_table_options->radio_lt_firsthead,0);
372 fl_set_button(fd_form_table_options->radio_lt_firsthead,0);
373 fl_set_object_lcol(fd_form_table_options->radio_lt_firsthead,
375 fl_set_object_lcol(fd_form_table_options->radio_lt_head,
377 fl_set_object_lcol(fd_form_table_options->radio_lt_foot,
379 fl_set_object_lcol(fd_form_table_options->radio_lt_lastfoot,
381 fl_set_object_lcol(fd_form_table_options->radio_lt_newpage,
384 } else if (ob == fd_form_table_options->radio_rotate_table) {
385 s=fl_get_button(fd_form_table_options->radio_rotate_table);
387 num = LyXTable::SET_ROTATE_TABLE;
389 num = LyXTable::UNSET_ROTATE_TABLE;
390 } else if (ob == fd_form_table_options->radio_rotate_cell) {
391 s=fl_get_button(fd_form_table_options->radio_rotate_cell);
393 num = LyXTable::SET_ROTATE_CELL;
395 num = LyXTable::UNSET_ROTATE_CELL;
396 } else if (ob == fd_form_table_options->radio_linebreak_cell) {
397 num = LyXTable::SET_LINEBREAKS;
398 } else if (ob == fd_form_table_options->radio_lt_firsthead) {
399 num = LyXTable::SET_LTFIRSTHEAD;
400 } else if (ob == fd_form_table_options->radio_lt_head) {
401 num = LyXTable::SET_LTHEAD;
402 } else if (ob == fd_form_table_options->radio_lt_foot) {
403 num = LyXTable::SET_LTFOOT;
404 } else if (ob == fd_form_table_options->radio_lt_lastfoot) {
405 num = LyXTable::SET_LTLASTFOOT;
406 } else if (ob == fd_form_table_options->radio_lt_newpage) {
407 num = LyXTable::SET_LTNEWPAGE;
408 } else if (ob == fd_form_table_options->button_table_extra) {
409 OpenLayoutTableExtra();
411 } else if (ob == fd_form_table_extra->input_special_alignment) {
412 special=fl_get_input(fd_form_table_extra->input_special_alignment);
414 fl_get_input_cursorpos(ob, &extra_col_cursor_x, &dummy);
415 num = LyXTable::SET_SPECIAL_COLUMN;
416 } else if (ob == fd_form_table_extra->input_special_multialign) {
417 special=fl_get_input(fd_form_table_extra->input_special_multialign);
419 fl_get_input_cursorpos(ob, &extra_multicol_cursor_x, &dummy);
420 num = LyXTable::SET_SPECIAL_MULTI;
423 if (current_view->available()){
424 current_view->getScreen()->HideCursor();
425 if (!current_view->currentBuffer()->text->selection){
427 current_view->currentBuffer()->update(-2);
429 if ((num == LyXTable::SET_SPECIAL_COLUMN) ||
430 (num == LyXTable::SET_SPECIAL_MULTI))
431 current_view->currentBuffer()->text->TableFeatures(num,special);
433 current_view->currentBuffer()->text->TableFeatures(num);
434 current_view->currentBuffer()->update(1);
436 if (num == LyXTable::DELETE_TABLE) {
437 fl_set_focus_object(fd_form_table_options->form_table_options,
438 fd_form_table_options->button_table_delete);
439 fl_hide_form(fd_form_table_options->form_table_options);
441 UpdateLayoutTable(true);
445 void TableOptCloseCB(FL_OBJECT *, long)
447 fl_set_focus_object(fd_form_table_options->form_table_options,
448 fd_form_table_options->button_table_delete);
449 fl_hide_form(fd_form_table_options->form_table_options);
453 void TableSpeCloseCB(FL_OBJECT *, long)
455 fl_set_focus_object(fd_form_table_options->form_table_options,
456 fd_form_table_options->button_table_delete);
457 fl_hide_form(fd_form_table_extra->form_table_extra);
461 void SetPWidthCB(FL_OBJECT *ob, long)
463 fl_set_object_label(fd_form_table_options->text_warning,"");
465 if (ob == fd_form_table_options->input_column_width) {
468 str = fl_get_input(ob);
469 if (!str.empty() && !isValidLength(str)) {
470 fl_set_object_label(fd_form_table_options->text_warning,
471 _("Warning: Invalid Length (valid example: 10mm)"));
472 fl_show_object(fd_form_table_options->text_warning);
475 if (current_view->available()){
476 current_view->getScreen()->HideCursor();
477 if (!current_view->currentBuffer()->text->selection){
479 current_view->currentBuffer()->update(-2);
481 current_view->currentBuffer()->text->TableFeatures(LyXTable::SET_PWIDTH,str);
482 current_view->currentBuffer()->update(1);
484 MenuLayoutTable(0); // update for alignment