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"
15 #include "lyxscreen.h"
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;
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;
40 bool UpdateLayoutTable(int flag)
43 if (!current_view->getScreen() || !current_view->available())
46 if (update && current_view->text->cursor.par->table) {
48 string pwidth, special;
50 LyXTable * table = current_view->text->cursor.par->table;
52 int cell = current_view->text->
53 NumberOfCell(current_view->text->cursor.par,
54 current_view->text->cursor.pos);
56 int column = table->column_of_cell(cell)+1;
57 fl_set_object_label(fd_form_table_options->text_warning, "");
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);
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);
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);
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);
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);
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);
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);
100 fl_set_input(fd_form_table_extra->input_special_alignment,
102 fl_set_input_cursorpos(fd_form_table_extra->input_special_alignment,
103 extra_col_cursor_x, 0); // restore the cursor
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);
110 fl_set_input(fd_form_table_extra->input_special_multialign,
112 fl_set_input_cursorpos(fd_form_table_extra->input_special_multialign,
113 extra_multicol_cursor_x, 0); // restore the cursor
115 if (current_view->buffer()->isReadonly())
116 fl_deactivate_object(fd_form_table_extra->input_special_multialign);
117 pwidth = table->GetPWidth(cell);
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,
126 fl_set_button(fd_form_table_options->radio_linebreak_cell,
127 table->Linebreaks(table->FirstVirtualCell(cell)));
129 fl_deactivate_object(fd_form_table_options->radio_linebreak_cell);
130 fl_set_object_lcol(fd_form_table_options->radio_linebreak_cell,
132 fl_set_button(fd_form_table_options->radio_linebreak_cell, 0);
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);
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,
147 fl_set_object_lcol(fd_form_table_options->radio_align_right,
149 fl_set_object_lcol(fd_form_table_options->radio_align_center,
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,
157 fl_set_object_lcol(fd_form_table_options->radio_align_right,
159 fl_set_object_lcol(fd_form_table_options->radio_align_center,
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,
171 fl_set_object_lcol(fd_form_table_options->radio_lt_head,
173 fl_set_object_lcol(fd_form_table_options->radio_lt_foot,
175 fl_set_object_lcol(fd_form_table_options->radio_lt_lastfoot,
177 fl_set_object_lcol(fd_form_table_options->radio_lt_newpage,
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));
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,
202 fl_set_object_lcol(fd_form_table_options->radio_lt_head,
204 fl_set_object_lcol(fd_form_table_options->radio_lt_foot,
206 fl_set_object_lcol(fd_form_table_options->radio_lt_lastfoot,
208 fl_set_object_lcol(fd_form_table_options->radio_lt_newpage,
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);
224 void OpenLayoutTableExtra()
227 if (fd_form_table_extra->form_table_extra->visible) {
228 fl_raise_form(fd_form_table_extra->form_table_extra);
230 static int ow = -1, oh;
231 fl_show_form(fd_form_table_extra->form_table_extra,
232 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
233 _("Table Extra Form"));
235 ow = fd_form_table_extra->form_table_extra->w;
236 oh = fd_form_table_extra->form_table_extra->h;
238 fl_set_form_minsize(fd_form_table_extra->form_table_extra,
244 void MenuLayoutTable(int flag)
246 if (UpdateLayoutTable(flag)) {
247 if (fd_form_table_options->form_table_options->visible) {
248 fl_raise_form(fd_form_table_options->form_table_options);
251 fl_show_form(fd_form_table_options->form_table_options,
252 FL_PLACE_MOUSE, FL_FULLBORDER,
259 void TableOptionsCB(FL_OBJECT * ob, long)
261 LyXTable * table = 0;
265 if (!current_view->available()
266 || !(table = current_view->text->cursor.par->table)) {
270 int cell = current_view->text->
271 NumberOfCell(current_view->text->cursor.par,
272 current_view->text->cursor.pos);
273 if (ActCell != cell) {
275 fl_set_object_label(fd_form_table_options->text_warning,
276 _("Warning: Wrong Cursor position, updated window"));
277 fl_show_object(fd_form_table_options->text_warning);
278 extra_col_cursor_x = 0; // would rather place it at the end, but...
279 extra_multicol_cursor_x = 0;
283 // No point in processing directives that you can't do anything with
284 // anyhow, so exit now if the buffer is read-only.
285 if (current_view->buffer()->isReadonly()) {
290 if (ob != fd_form_table_options->button_table_delete) {
291 fl_set_object_label(fd_form_table_options->text_warning, "");
294 str = fl_get_input(fd_form_table_options->input_column_width);
295 if (!str.empty() && !isValidLength(str)) {
296 fl_set_object_label(fd_form_table_options->text_warning,
297 _("Warning: Invalid Length (valid example: 10mm)"));
298 fl_show_object(fd_form_table_options->text_warning);
301 if (((ob == fd_form_table_options->button_delete_row) && (table->rows<= 1)) ||
302 ((ob == fd_form_table_options->button_delete_column) && (table->columns<= 1)))
303 ob = fd_form_table_options->button_table_delete;
304 if (ob == fd_form_table_options->button_append_row)
305 num = LyXTable::APPEND_ROW;
306 else if (ob == fd_form_table_options->button_append_column)
307 num = LyXTable::APPEND_COLUMN;
308 else if (ob == fd_form_table_options->button_delete_row)
309 num = LyXTable::DELETE_ROW;
310 else if (ob == fd_form_table_options->button_delete_column)
311 num = LyXTable::DELETE_COLUMN;
312 else if (ob == fd_form_table_options->button_set_borders)
313 num = LyXTable::SET_ALL_LINES;
314 else if (ob == fd_form_table_options->button_unset_borders)
315 num = LyXTable::UNSET_ALL_LINES;
316 else if (ob == fd_form_table_options->radio_border_top)
317 num = LyXTable::TOGGLE_LINE_TOP;
318 else if (ob == fd_form_table_options->radio_border_bottom)
319 num = LyXTable::TOGGLE_LINE_BOTTOM;
320 else if (ob == fd_form_table_options->radio_border_left)
321 num = LyXTable::TOGGLE_LINE_LEFT;
322 else if (ob == fd_form_table_options->radio_border_right)
323 num = LyXTable::TOGGLE_LINE_RIGHT;
324 else if (ob == fd_form_table_options->radio_align_left)
325 num = LyXTable::ALIGN_LEFT;
326 else if (ob == fd_form_table_options->radio_align_right)
327 num = LyXTable::ALIGN_RIGHT;
328 else if (ob == fd_form_table_options->radio_align_center)
329 num = LyXTable::ALIGN_CENTER;
330 else if ((ob == fd_form_table_options->button_table_delete) && !Confirmed) {
331 fl_set_object_label(fd_form_table_options->text_warning,
332 _("Confirm: press Delete-Button again"));
335 } else if ((ob == fd_form_table_options->button_table_delete)
337 num = LyXTable::DELETE_TABLE;
339 } else if (ob == fd_form_table_options->radio_multicolumn)
340 num = LyXTable::MULTICOLUMN;
341 else if (ob == fd_form_table_options->radio_longtable) {
342 s = fl_get_button(fd_form_table_options->radio_longtable);
344 num = LyXTable::SET_LONGTABLE;
345 fl_activate_object(fd_form_table_options->radio_lt_firsthead);
346 fl_activate_object(fd_form_table_options->radio_lt_head);
347 fl_activate_object(fd_form_table_options->radio_lt_foot);
348 fl_activate_object(fd_form_table_options->radio_lt_lastfoot);
349 fl_activate_object(fd_form_table_options->radio_lt_newpage);
350 fl_set_button(fd_form_table_options->radio_lt_firsthead,
351 table->RowOfLTFirstHead(cell));
352 fl_set_button(fd_form_table_options->radio_lt_head,
353 table->RowOfLTHead(cell));
354 fl_set_button(fd_form_table_options->radio_lt_foot,
355 table->RowOfLTFoot(cell));
356 fl_set_button(fd_form_table_options->radio_lt_lastfoot,
357 table->RowOfLTLastFoot(cell));
358 fl_set_button(fd_form_table_options->radio_lt_firsthead,
359 table->LTNewPage(cell));
361 num = LyXTable::UNSET_LONGTABLE;
362 fl_deactivate_object(fd_form_table_options->radio_lt_firsthead);
363 fl_deactivate_object(fd_form_table_options->radio_lt_head);
364 fl_deactivate_object(fd_form_table_options->radio_lt_foot);
365 fl_deactivate_object(fd_form_table_options->radio_lt_lastfoot);
366 fl_deactivate_object(fd_form_table_options->radio_lt_newpage);
367 fl_set_button(fd_form_table_options->radio_lt_firsthead, 0);
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_object_lcol(fd_form_table_options->radio_lt_firsthead,
374 fl_set_object_lcol(fd_form_table_options->radio_lt_head,
376 fl_set_object_lcol(fd_form_table_options->radio_lt_foot,
378 fl_set_object_lcol(fd_form_table_options->radio_lt_lastfoot,
380 fl_set_object_lcol(fd_form_table_options->radio_lt_newpage,
383 } else if (ob == fd_form_table_options->radio_rotate_table) {
384 s = fl_get_button(fd_form_table_options->radio_rotate_table);
386 num = LyXTable::SET_ROTATE_TABLE;
388 num = LyXTable::UNSET_ROTATE_TABLE;
389 } else if (ob == fd_form_table_options->radio_rotate_cell) {
390 s = fl_get_button(fd_form_table_options->radio_rotate_cell);
392 num = LyXTable::SET_ROTATE_CELL;
394 num = LyXTable::UNSET_ROTATE_CELL;
395 } else if (ob == fd_form_table_options->radio_linebreak_cell) {
396 num = LyXTable::SET_LINEBREAKS;
397 } else if (ob == fd_form_table_options->radio_lt_firsthead) {
398 num = LyXTable::SET_LTFIRSTHEAD;
399 } else if (ob == fd_form_table_options->radio_lt_head) {
400 num = LyXTable::SET_LTHEAD;
401 } else if (ob == fd_form_table_options->radio_lt_foot) {
402 num = LyXTable::SET_LTFOOT;
403 } else if (ob == fd_form_table_options->radio_lt_lastfoot) {
404 num = LyXTable::SET_LTLASTFOOT;
405 } else if (ob == fd_form_table_options->radio_lt_newpage) {
406 num = LyXTable::SET_LTNEWPAGE;
407 } else if (ob == fd_form_table_options->button_table_extra) {
408 OpenLayoutTableExtra();
410 } else if (ob == fd_form_table_extra->input_special_alignment) {
411 special = fl_get_input(fd_form_table_extra->input_special_alignment);
413 fl_get_input_cursorpos(ob, &extra_col_cursor_x, &dummy);
414 num = LyXTable::SET_SPECIAL_COLUMN;
415 } else if (ob == fd_form_table_extra->input_special_multialign) {
416 special = fl_get_input(fd_form_table_extra->input_special_multialign);
418 fl_get_input_cursorpos(ob, &extra_multicol_cursor_x, &dummy);
419 num = LyXTable::SET_SPECIAL_MULTI;
422 if (current_view->available()) {
423 current_view->getScreen()->HideCursor();
424 if (!current_view->text->selection){
425 current_view->beforeChange();
426 current_view->update(-2);
428 if ((num == LyXTable::SET_SPECIAL_COLUMN) ||
429 (num == LyXTable::SET_SPECIAL_MULTI))
430 current_view->text->TableFeatures(num, special);
432 current_view->text->TableFeatures(num);
433 current_view->update(1);
435 if (num == LyXTable::DELETE_TABLE) {
436 fl_set_focus_object(fd_form_table_options->form_table_options,
437 fd_form_table_options->button_table_delete);
438 fl_hide_form(fd_form_table_options->form_table_options);
440 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) {
466 string str = fl_get_input(ob);
467 if (!str.empty() && !isValidLength(str)) {
468 fl_set_object_label(fd_form_table_options->text_warning,
469 _("Warning: Invalid Length (valid example: 10mm)"));
470 fl_show_object(fd_form_table_options->text_warning);
473 if (current_view->available()){
474 current_view->getScreen()->HideCursor();
475 if (!current_view->text->selection) {
476 current_view->beforeChange();
477 current_view->update(-2);
479 current_view->text->TableFeatures(LyXTable::SET_PWIDTH, str);
480 current_view->update(1);
482 MenuLayoutTable(0); // update for alignment