4 #include FORMS_H_LOCATION
6 #include "layout_forms.h"
10 #include "support/filetools.h"
13 #include "lyx_gui_misc.h"
14 #include "BufferView.h"
18 #include "insets/lyxinset.h"
21 extern FD_form_table_options * fd_form_table_options;
22 extern FD_form_table_extra * fd_form_table_extra;
23 extern BufferView * current_view;
26 static int Confirmed = false;
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
31 // changed in real-time, but we have no callbacks for the input fields,
32 // so I simply store and restore the cursor position for now.
33 // (too much of a hazzle to do it proper; we'll trash all this code
35 static int extra_col_cursor_x; // need no y's, one-line input fields
36 static int extra_multicol_cursor_x;
41 bool UpdateLayoutTable(int flag)
44 if (!current_view->available())
48 if (update && current_view->text->cursor.par()->table) {
50 string pwidth, special;
52 LyXTable * table = current_view->text->cursor.par()->table;
54 int cell = current_view->text->
55 NumberOfCell(current_view->text->cursor.par(),
56 current_view->text->cursor.pos());
58 int column = table->column_of_cell(cell)+1;
59 fl_set_object_label(fd_form_table_options->text_warning, "");
61 fl_activate_object(fd_form_table_extra->input_special_alignment);
62 fl_activate_object(fd_form_table_extra->input_special_multialign);
63 fl_activate_object(fd_form_table_options->input_column_width);
64 sprintf(buf, "%d", column);
65 fl_set_input(fd_form_table_options->input_table_column, buf);
66 fl_deactivate_object(fd_form_table_options->input_table_column);
67 int row = table->row_of_cell(cell)+1;
68 sprintf(buf, "%d", row);
69 fl_set_input(fd_form_table_options->input_table_row, buf);
70 fl_deactivate_object(fd_form_table_options->input_table_row);
71 if (table->IsMultiColumn(cell))
72 fl_set_button(fd_form_table_options->radio_multicolumn, 1);
74 fl_set_button(fd_form_table_options->radio_multicolumn, 0);
75 if (table->RotateCell(cell))
76 fl_set_button(fd_form_table_options->radio_rotate_cell, 1);
78 fl_set_button(fd_form_table_options->radio_rotate_cell, 0);
79 if (table->TopLine(cell))
80 fl_set_button(fd_form_table_options->radio_border_top, 1);
82 fl_set_button(fd_form_table_options->radio_border_top, 0);
83 if (table->BottomLine(cell))
84 fl_set_button(fd_form_table_options->radio_border_bottom, 1);
86 fl_set_button(fd_form_table_options->radio_border_bottom, 0);
87 if (table->LeftLine(cell))
88 fl_set_button(fd_form_table_options->radio_border_left, 1);
90 fl_set_button(fd_form_table_options->radio_border_left, 0);
91 if (table->RightLine(cell))
92 fl_set_button(fd_form_table_options->radio_border_right, 1);
94 fl_set_button(fd_form_table_options->radio_border_right, 0);
95 int align = table->GetAlignment(cell);
96 fl_set_button(fd_form_table_options->radio_align_left, 0);
97 fl_set_button(fd_form_table_options->radio_align_right, 0);
98 fl_set_button(fd_form_table_options->radio_align_center, 0);
99 special = table->GetAlignSpecial(cell, LyXTable::SET_SPECIAL_COLUMN);
102 fl_set_input(fd_form_table_extra->input_special_alignment,
104 fl_set_input_cursorpos(fd_form_table_extra->input_special_alignment,
105 extra_col_cursor_x, 0); // restore the cursor
107 if (current_view->buffer()->isReadonly())
108 fl_deactivate_object(fd_form_table_extra->input_special_alignment);
109 special = table->GetAlignSpecial(cell, LyXTable::SET_SPECIAL_MULTI);
112 fl_set_input(fd_form_table_extra->input_special_multialign,
114 fl_set_input_cursorpos(fd_form_table_extra->input_special_multialign,
115 extra_multicol_cursor_x, 0); // restore the cursor
117 if (current_view->buffer()->isReadonly())
118 fl_deactivate_object(fd_form_table_extra->input_special_multialign);
119 pwidth = table->GetPWidth(cell);
121 fl_set_input(fd_form_table_options->input_column_width, pwidth.c_str());
122 if (current_view->buffer()->isReadonly())
123 fl_deactivate_object(fd_form_table_options->input_column_width);
124 if (!pwidth.empty()) {
125 fl_activate_object(fd_form_table_options->radio_linebreak_cell);
126 fl_set_object_lcol(fd_form_table_options->radio_linebreak_cell,
128 fl_set_button(fd_form_table_options->radio_linebreak_cell,
129 table->Linebreaks(table->FirstVirtualCell(cell)));
131 fl_deactivate_object(fd_form_table_options->radio_linebreak_cell);
132 fl_set_object_lcol(fd_form_table_options->radio_linebreak_cell,
134 fl_set_button(fd_form_table_options->radio_linebreak_cell, 0);
136 if ((!pwidth.empty() && !table->IsMultiColumn(cell)) ||
137 (align == LYX_ALIGN_LEFT))
138 fl_set_button(fd_form_table_options->radio_align_left, 1);
139 else if (align == LYX_ALIGN_RIGHT)
140 fl_set_button(fd_form_table_options->radio_align_right, 1);
142 fl_set_button(fd_form_table_options->radio_align_center, 1);
143 if (!pwidth.empty() && !table->IsMultiColumn(cell)) {
144 fl_deactivate_object(fd_form_table_options->radio_align_left);
145 fl_deactivate_object(fd_form_table_options->radio_align_right);
146 fl_deactivate_object(fd_form_table_options->radio_align_center);
147 fl_set_object_lcol(fd_form_table_options->radio_align_left,
149 fl_set_object_lcol(fd_form_table_options->radio_align_right,
151 fl_set_object_lcol(fd_form_table_options->radio_align_center,
154 fl_activate_object(fd_form_table_options->radio_align_left);
155 fl_activate_object(fd_form_table_options->radio_align_right);
156 fl_activate_object(fd_form_table_options->radio_align_center);
157 fl_set_object_lcol(fd_form_table_options->radio_align_left,
159 fl_set_object_lcol(fd_form_table_options->radio_align_right,
161 fl_set_object_lcol(fd_form_table_options->radio_align_center,
164 fl_set_button(fd_form_table_options->radio_longtable, table->IsLongTable());
165 if (table->IsLongTable()) {
166 fl_activate_object(fd_form_table_options->radio_lt_firsthead);
167 fl_activate_object(fd_form_table_options->radio_lt_head);
168 fl_activate_object(fd_form_table_options->radio_lt_foot);
169 fl_activate_object(fd_form_table_options->radio_lt_lastfoot);
170 fl_activate_object(fd_form_table_options->radio_lt_newpage);
171 fl_set_object_lcol(fd_form_table_options->radio_lt_firsthead,
173 fl_set_object_lcol(fd_form_table_options->radio_lt_head,
175 fl_set_object_lcol(fd_form_table_options->radio_lt_foot,
177 fl_set_object_lcol(fd_form_table_options->radio_lt_lastfoot,
179 fl_set_object_lcol(fd_form_table_options->radio_lt_newpage,
181 fl_set_button(fd_form_table_options->radio_lt_firsthead,
182 table->RowOfLTFirstHead(cell));
183 fl_set_button(fd_form_table_options->radio_lt_head,
184 table->RowOfLTHead(cell));
185 fl_set_button(fd_form_table_options->radio_lt_foot,
186 table->RowOfLTFoot(cell));
187 fl_set_button(fd_form_table_options->radio_lt_lastfoot,
188 table->RowOfLTLastFoot(cell));
189 fl_set_button(fd_form_table_options->radio_lt_newpage,
190 table->LTNewPage(cell));
192 fl_deactivate_object(fd_form_table_options->radio_lt_firsthead);
193 fl_deactivate_object(fd_form_table_options->radio_lt_head);
194 fl_deactivate_object(fd_form_table_options->radio_lt_foot);
195 fl_deactivate_object(fd_form_table_options->radio_lt_lastfoot);
196 fl_deactivate_object(fd_form_table_options->radio_lt_newpage);
197 fl_set_button(fd_form_table_options->radio_lt_firsthead, 0);
198 fl_set_button(fd_form_table_options->radio_lt_head, 0);
199 fl_set_button(fd_form_table_options->radio_lt_foot, 0);
200 fl_set_button(fd_form_table_options->radio_lt_lastfoot, 0);
201 fl_set_button(fd_form_table_options->radio_lt_newpage, 0);
202 fl_set_object_lcol(fd_form_table_options->radio_lt_firsthead,
204 fl_set_object_lcol(fd_form_table_options->radio_lt_head,
206 fl_set_object_lcol(fd_form_table_options->radio_lt_foot,
208 fl_set_object_lcol(fd_form_table_options->radio_lt_lastfoot,
210 fl_set_object_lcol(fd_form_table_options->radio_lt_newpage,
213 fl_set_button(fd_form_table_options->radio_rotate_table,
214 table->RotateTable());
215 fl_set_focus_object(fd_form_table_options->form_table_options,
216 fd_form_table_options->button_table_delete);
219 if (fd_form_table_options->form_table_options->visible) {
220 fl_set_focus_object(fd_form_table_options->form_table_options,
221 fd_form_table_options->button_table_delete);
222 fl_hide_form(fd_form_table_options->form_table_options);
228 void OpenLayoutTableExtra()
231 if (fd_form_table_extra->form_table_extra->visible) {
232 fl_raise_form(fd_form_table_extra->form_table_extra);
234 static int ow = -1, oh;
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,
262 void TableOptionsCB(FL_OBJECT * ob, long)
265 LyXTable * table = 0;
269 if (!current_view->available()
270 || !(table = current_view->text->cursor.par()->table)) {
274 int cell = current_view->text->
275 NumberOfCell(current_view->text->cursor.par(),
276 current_view->text->cursor.pos());
277 if (ActCell != cell) {
279 fl_set_object_label(fd_form_table_options->text_warning,
280 _("Warning: Wrong Cursor position, updated window"));
281 fl_show_object(fd_form_table_options->text_warning);
282 extra_col_cursor_x = 0; // would rather place it at the end, but...
283 extra_multicol_cursor_x = 0;
287 // No point in processing directives that you can't do anything with
288 // anyhow, so exit now if the buffer is read-only.
289 if (current_view->buffer()->isReadonly()) {
294 if (ob != fd_form_table_options->button_table_delete) {
295 fl_set_object_label(fd_form_table_options->text_warning, "");
298 str = fl_get_input(fd_form_table_options->input_column_width);
299 if (!str.empty() && !isValidLength(str)) {
300 fl_set_object_label(fd_form_table_options->text_warning,
301 _("Warning: Invalid Length (valid example: 10mm)"));
302 fl_show_object(fd_form_table_options->text_warning);
305 if (((ob == fd_form_table_options->button_delete_row) && (table->rows<= 1)) ||
306 ((ob == fd_form_table_options->button_delete_column) && (table->columns<= 1)))
307 ob = fd_form_table_options->button_table_delete;
308 if (ob == fd_form_table_options->button_append_row)
309 num = LyXTable::APPEND_ROW;
310 else if (ob == fd_form_table_options->button_append_column)
311 num = LyXTable::APPEND_COLUMN;
312 else if (ob == fd_form_table_options->button_delete_row)
313 num = LyXTable::DELETE_ROW;
314 else if (ob == fd_form_table_options->button_delete_column)
315 num = LyXTable::DELETE_COLUMN;
316 else if (ob == fd_form_table_options->button_set_borders)
317 num = LyXTable::SET_ALL_LINES;
318 else if (ob == fd_form_table_options->button_unset_borders)
319 num = LyXTable::UNSET_ALL_LINES;
320 else if (ob == fd_form_table_options->radio_border_top)
321 num = LyXTable::TOGGLE_LINE_TOP;
322 else if (ob == fd_form_table_options->radio_border_bottom)
323 num = LyXTable::TOGGLE_LINE_BOTTOM;
324 else if (ob == fd_form_table_options->radio_border_left)
325 num = LyXTable::TOGGLE_LINE_LEFT;
326 else if (ob == fd_form_table_options->radio_border_right)
327 num = LyXTable::TOGGLE_LINE_RIGHT;
328 else if (ob == fd_form_table_options->radio_align_left)
329 num = LyXTable::ALIGN_LEFT;
330 else if (ob == fd_form_table_options->radio_align_right)
331 num = LyXTable::ALIGN_RIGHT;
332 else if (ob == fd_form_table_options->radio_align_center)
333 num = LyXTable::ALIGN_CENTER;
334 else if ((ob == fd_form_table_options->button_table_delete) && !Confirmed) {
335 fl_set_object_label(fd_form_table_options->text_warning,
336 _("Confirm: press Delete-Button again"));
339 } else if ((ob == fd_form_table_options->button_table_delete)
341 num = LyXTable::DELETE_TABLE;
343 } else if (ob == fd_form_table_options->radio_multicolumn)
344 num = LyXTable::MULTICOLUMN;
345 else if (ob == fd_form_table_options->radio_longtable) {
346 s = fl_get_button(fd_form_table_options->radio_longtable);
348 num = LyXTable::SET_LONGTABLE;
349 fl_activate_object(fd_form_table_options->radio_lt_firsthead);
350 fl_activate_object(fd_form_table_options->radio_lt_head);
351 fl_activate_object(fd_form_table_options->radio_lt_foot);
352 fl_activate_object(fd_form_table_options->radio_lt_lastfoot);
353 fl_activate_object(fd_form_table_options->radio_lt_newpage);
354 fl_set_button(fd_form_table_options->radio_lt_firsthead,
355 table->RowOfLTFirstHead(cell));
356 fl_set_button(fd_form_table_options->radio_lt_head,
357 table->RowOfLTHead(cell));
358 fl_set_button(fd_form_table_options->radio_lt_foot,
359 table->RowOfLTFoot(cell));
360 fl_set_button(fd_form_table_options->radio_lt_lastfoot,
361 table->RowOfLTLastFoot(cell));
362 fl_set_button(fd_form_table_options->radio_lt_firsthead,
363 table->LTNewPage(cell));
365 num = LyXTable::UNSET_LONGTABLE;
366 fl_deactivate_object(fd_form_table_options->radio_lt_firsthead);
367 fl_deactivate_object(fd_form_table_options->radio_lt_head);
368 fl_deactivate_object(fd_form_table_options->radio_lt_foot);
369 fl_deactivate_object(fd_form_table_options->radio_lt_lastfoot);
370 fl_deactivate_object(fd_form_table_options->radio_lt_newpage);
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_button(fd_form_table_options->radio_lt_firsthead, 0);
374 fl_set_button(fd_form_table_options->radio_lt_firsthead, 0);
375 fl_set_button(fd_form_table_options->radio_lt_firsthead, 0);
376 fl_set_object_lcol(fd_form_table_options->radio_lt_firsthead,
378 fl_set_object_lcol(fd_form_table_options->radio_lt_head,
380 fl_set_object_lcol(fd_form_table_options->radio_lt_foot,
382 fl_set_object_lcol(fd_form_table_options->radio_lt_lastfoot,
384 fl_set_object_lcol(fd_form_table_options->radio_lt_newpage,
387 } else if (ob == fd_form_table_options->radio_rotate_table) {
388 s = fl_get_button(fd_form_table_options->radio_rotate_table);
390 num = LyXTable::SET_ROTATE_TABLE;
392 num = LyXTable::UNSET_ROTATE_TABLE;
393 } else if (ob == fd_form_table_options->radio_rotate_cell) {
394 s = fl_get_button(fd_form_table_options->radio_rotate_cell);
396 num = LyXTable::SET_ROTATE_CELL;
398 num = LyXTable::UNSET_ROTATE_CELL;
399 } else if (ob == fd_form_table_options->radio_linebreak_cell) {
400 num = LyXTable::SET_LINEBREAKS;
401 } else if (ob == fd_form_table_options->radio_lt_firsthead) {
402 num = LyXTable::SET_LTFIRSTHEAD;
403 } else if (ob == fd_form_table_options->radio_lt_head) {
404 num = LyXTable::SET_LTHEAD;
405 } else if (ob == fd_form_table_options->radio_lt_foot) {
406 num = LyXTable::SET_LTFOOT;
407 } else if (ob == fd_form_table_options->radio_lt_lastfoot) {
408 num = LyXTable::SET_LTLASTFOOT;
409 } else if (ob == fd_form_table_options->radio_lt_newpage) {
410 num = LyXTable::SET_LTNEWPAGE;
411 } else if (ob == fd_form_table_options->button_table_extra) {
412 OpenLayoutTableExtra();
414 } else if (ob == fd_form_table_extra->input_special_alignment) {
415 special = fl_get_input(fd_form_table_extra->input_special_alignment);
417 fl_get_input_cursorpos(ob, &extra_col_cursor_x, &dummy);
418 num = LyXTable::SET_SPECIAL_COLUMN;
419 } else if (ob == fd_form_table_extra->input_special_multialign) {
420 special = fl_get_input(fd_form_table_extra->input_special_multialign);
422 fl_get_input_cursorpos(ob, &extra_multicol_cursor_x, &dummy);
423 num = LyXTable::SET_SPECIAL_MULTI;
426 if (current_view->available()) {
427 current_view->hideCursor();
428 if (!current_view->text->selection){
429 current_view->beforeChange();
430 current_view->update(BufferView::SELECT|BufferView::FITCUR);
432 if ((num == LyXTable::SET_SPECIAL_COLUMN) ||
433 (num == LyXTable::SET_SPECIAL_MULTI))
434 current_view->text->TableFeatures(current_view, num, special);
436 current_view->text->TableFeatures(current_view, num);
437 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
439 if (num == LyXTable::DELETE_TABLE) {
440 fl_set_focus_object(fd_form_table_options->form_table_options,
441 fd_form_table_options->button_table_delete);
442 fl_hide_form(fd_form_table_options->form_table_options);
444 UpdateLayoutTable(true);
450 void TableOptCloseCB(FL_OBJECT *, long)
452 fl_set_focus_object(fd_form_table_options->form_table_options,
453 fd_form_table_options->button_table_delete);
454 fl_hide_form(fd_form_table_options->form_table_options);
458 void TableSpeCloseCB(FL_OBJECT *, long)
460 fl_set_focus_object(fd_form_table_options->form_table_options,
461 fd_form_table_options->button_table_delete);
462 fl_hide_form(fd_form_table_extra->form_table_extra);
466 void SetPWidthCB(FL_OBJECT * ob, long)
469 fl_set_object_label(fd_form_table_options->text_warning, "");
471 if (ob == fd_form_table_options->input_column_width) {
472 string str = fl_get_input(ob);
473 if (!str.empty() && !isValidLength(str)) {
474 fl_set_object_label(fd_form_table_options->text_warning,
475 _("Warning: Invalid Length (valid example: 10mm)"));
476 fl_show_object(fd_form_table_options->text_warning);
479 if (current_view->available()){
480 current_view->hideCursor();
481 if (!current_view->text->selection) {
482 current_view->beforeChange();
483 current_view->update(BufferView::SELECT|BufferView::FITCUR);
485 current_view->text->TableFeatures(current_view, LyXTable::SET_PWIDTH, str);
486 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
488 MenuLayoutTable(0); // update for alignment