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/insettabular.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 extern void OpenLayoutTableExtra();
27 extern bool UpdateLayoutTabular(bool, InsetTabular *);
29 static int Confirmed = false;
32 // hack to keep the cursor from jumping to the end of the text in the Extra
33 // form input fields during editing. The values in LyXTabular itself is
34 // changed in real-time, but we have no callbacks for the input fields,
35 // so I simply store and restore the cursor position for now.
36 // (too much of a hazzle to do it proper; we'll trash all this code
38 static int extra_col_cursor_x; // need no y's, one-line input fields
39 static int extra_multicol_cursor_x;
42 static InsetTabular * inset = 0;
44 void MenuLayoutTabular(bool flag, InsetTabular * ins)
49 if (UpdateLayoutTabular(flag, ins)) {
50 if (fd_form_table_options->form_table_options->visible) {
51 fl_raise_form(fd_form_table_options->form_table_options);
54 fl_show_form(fd_form_table_options->form_table_options,
55 FL_PLACE_MOUSE, FL_FULLBORDER,
61 bool UpdateLayoutTabular(bool flag, InsetTabular *ins)
69 if (!current_view->available())
74 string pwidth, special;
76 LyXTabular * table = inset->tabular;
78 int cell = inset->GetActCell();
80 int column = table->column_of_cell(cell)+1;
81 fl_set_object_label(fd_form_table_options->text_warning, "");
83 fl_activate_object(fd_form_table_extra->input_special_alignment);
84 fl_activate_object(fd_form_table_extra->input_special_multialign);
85 fl_activate_object(fd_form_table_options->input_column_width);
86 sprintf(buf, "%d", column);
87 fl_set_input(fd_form_table_options->input_table_column, buf);
88 fl_deactivate_object(fd_form_table_options->input_table_column);
89 int row = table->row_of_cell(cell)+1;
90 sprintf(buf, "%d", row);
91 fl_set_input(fd_form_table_options->input_table_row, buf);
92 fl_deactivate_object(fd_form_table_options->input_table_row);
93 if (table->IsMultiColumn(cell))
94 fl_set_button(fd_form_table_options->radio_multicolumn, 1);
96 fl_set_button(fd_form_table_options->radio_multicolumn, 0);
97 if (table->GetRotateCell(cell))
98 fl_set_button(fd_form_table_options->radio_rotate_cell, 1);
100 fl_set_button(fd_form_table_options->radio_rotate_cell, 0);
101 if (table->TopLine(cell))
102 fl_set_button(fd_form_table_options->radio_border_top, 1);
104 fl_set_button(fd_form_table_options->radio_border_top, 0);
105 if (table->BottomLine(cell))
106 fl_set_button(fd_form_table_options->radio_border_bottom, 1);
108 fl_set_button(fd_form_table_options->radio_border_bottom, 0);
109 if (table->LeftLine(cell))
110 fl_set_button(fd_form_table_options->radio_border_left, 1);
112 fl_set_button(fd_form_table_options->radio_border_left, 0);
113 if (table->RightLine(cell))
114 fl_set_button(fd_form_table_options->radio_border_right, 1);
116 fl_set_button(fd_form_table_options->radio_border_right, 0);
117 int align = table->GetAlignment(cell);
118 fl_set_button(fd_form_table_options->radio_align_left, 0);
119 fl_set_button(fd_form_table_options->radio_align_right, 0);
120 fl_set_button(fd_form_table_options->radio_align_center, 0);
121 special = table->GetAlignSpecial(cell, LyXTabular::SET_SPECIAL_COLUMN);
124 fl_set_input(fd_form_table_extra->input_special_alignment,
126 fl_set_input_cursorpos(fd_form_table_extra->input_special_alignment,
127 extra_col_cursor_x, 0); // restore the cursor
129 if (current_view->buffer()->isReadonly())
130 fl_deactivate_object(fd_form_table_extra->input_special_alignment);
131 special = table->GetAlignSpecial(cell, LyXTabular::SET_SPECIAL_MULTI);
134 fl_set_input(fd_form_table_extra->input_special_multialign,
136 fl_set_input_cursorpos(fd_form_table_extra->input_special_multialign,
137 extra_multicol_cursor_x, 0); // restore the cursor
139 if (current_view->buffer()->isReadonly())
140 fl_deactivate_object(fd_form_table_extra->input_special_multialign);
141 pwidth = table->GetPWidth(cell);
143 fl_set_input(fd_form_table_options->input_column_width, pwidth.c_str());
144 if (current_view->buffer()->isReadonly())
145 fl_deactivate_object(fd_form_table_options->input_column_width);
146 if (!pwidth.empty()) {
147 fl_activate_object(fd_form_table_options->radio_linebreak_cell);
148 fl_set_object_lcol(fd_form_table_options->radio_linebreak_cell,
150 fl_set_button(fd_form_table_options->radio_linebreak_cell,
151 table->GetLinebreaks(cell));
153 fl_deactivate_object(fd_form_table_options->radio_linebreak_cell);
154 fl_set_object_lcol(fd_form_table_options->radio_linebreak_cell,
156 fl_set_button(fd_form_table_options->radio_linebreak_cell, 0);
158 if ((!pwidth.empty() && !table->IsMultiColumn(cell)) ||
159 (align == LYX_ALIGN_LEFT))
160 fl_set_button(fd_form_table_options->radio_align_left, 1);
161 else if (align == LYX_ALIGN_RIGHT)
162 fl_set_button(fd_form_table_options->radio_align_right, 1);
164 fl_set_button(fd_form_table_options->radio_align_center, 1);
165 if (!pwidth.empty() && !table->IsMultiColumn(cell)) {
166 fl_deactivate_object(fd_form_table_options->radio_align_left);
167 fl_deactivate_object(fd_form_table_options->radio_align_right);
168 fl_deactivate_object(fd_form_table_options->radio_align_center);
169 fl_set_object_lcol(fd_form_table_options->radio_align_left,
171 fl_set_object_lcol(fd_form_table_options->radio_align_right,
173 fl_set_object_lcol(fd_form_table_options->radio_align_center,
176 fl_activate_object(fd_form_table_options->radio_align_left);
177 fl_activate_object(fd_form_table_options->radio_align_right);
178 fl_activate_object(fd_form_table_options->radio_align_center);
179 fl_set_object_lcol(fd_form_table_options->radio_align_left,
181 fl_set_object_lcol(fd_form_table_options->radio_align_right,
183 fl_set_object_lcol(fd_form_table_options->radio_align_center,
186 fl_set_button(fd_form_table_options->radio_longtable, table->IsLongTabular());
187 if (table->IsLongTabular()) {
188 fl_activate_object(fd_form_table_options->radio_lt_firsthead);
189 fl_activate_object(fd_form_table_options->radio_lt_head);
190 fl_activate_object(fd_form_table_options->radio_lt_foot);
191 fl_activate_object(fd_form_table_options->radio_lt_lastfoot);
192 fl_activate_object(fd_form_table_options->radio_lt_newpage);
193 fl_set_object_lcol(fd_form_table_options->radio_lt_firsthead,
195 fl_set_object_lcol(fd_form_table_options->radio_lt_head,
197 fl_set_object_lcol(fd_form_table_options->radio_lt_foot,
199 fl_set_object_lcol(fd_form_table_options->radio_lt_lastfoot,
201 fl_set_object_lcol(fd_form_table_options->radio_lt_newpage,
203 fl_set_button(fd_form_table_options->radio_lt_firsthead,
204 table->GetRowOfLTFirstHead(cell));
205 fl_set_button(fd_form_table_options->radio_lt_head,
206 table->GetRowOfLTHead(cell));
207 fl_set_button(fd_form_table_options->radio_lt_foot,
208 table->GetRowOfLTFoot(cell));
209 fl_set_button(fd_form_table_options->radio_lt_lastfoot,
210 table->GetRowOfLTLastFoot(cell));
211 fl_set_button(fd_form_table_options->radio_lt_newpage,
212 table->GetLTNewPage(cell));
214 fl_deactivate_object(fd_form_table_options->radio_lt_firsthead);
215 fl_deactivate_object(fd_form_table_options->radio_lt_head);
216 fl_deactivate_object(fd_form_table_options->radio_lt_foot);
217 fl_deactivate_object(fd_form_table_options->radio_lt_lastfoot);
218 fl_deactivate_object(fd_form_table_options->radio_lt_newpage);
219 fl_set_button(fd_form_table_options->radio_lt_firsthead, 0);
220 fl_set_button(fd_form_table_options->radio_lt_head, 0);
221 fl_set_button(fd_form_table_options->radio_lt_foot, 0);
222 fl_set_button(fd_form_table_options->radio_lt_lastfoot, 0);
223 fl_set_button(fd_form_table_options->radio_lt_newpage, 0);
224 fl_set_object_lcol(fd_form_table_options->radio_lt_firsthead,
226 fl_set_object_lcol(fd_form_table_options->radio_lt_head,
228 fl_set_object_lcol(fd_form_table_options->radio_lt_foot,
230 fl_set_object_lcol(fd_form_table_options->radio_lt_lastfoot,
232 fl_set_object_lcol(fd_form_table_options->radio_lt_newpage,
235 fl_set_button(fd_form_table_options->radio_rotate_table,
236 table->GetRotateTabular());
237 fl_set_focus_object(fd_form_table_options->form_table_options,
238 fd_form_table_options->button_table_delete);
239 } else if (fd_form_table_options->form_table_options->visible) {
240 fl_set_focus_object(fd_form_table_options->form_table_options,
241 fd_form_table_options->button_table_delete);
242 fl_hide_form(fd_form_table_options->form_table_options);
248 void TabularOptionsCB(FL_OBJECT * ob, long)
256 LyXTabular * table = inset->tabular;
258 int cell = inset->GetActCell();
259 if (ActCell != cell) {
260 MenuLayoutTabular(false, inset);
261 fl_set_object_label(fd_form_table_options->text_warning,
262 _("Warning: Wrong Cursor position, updated window"));
263 fl_show_object(fd_form_table_options->text_warning);
264 extra_col_cursor_x = 0; // would rather place it at the end, but...
265 extra_multicol_cursor_x = 0;
269 // No point in processing directives that you can't do anything with
270 // anyhow, so exit now if the buffer is read-only.
271 if (current_view->buffer()->isReadonly()) {
272 MenuLayoutTabular(false, inset);
276 if (ob != fd_form_table_options->button_table_delete) {
277 fl_set_object_label(fd_form_table_options->text_warning, "");
280 str = fl_get_input(fd_form_table_options->input_column_width);
281 if (!str.empty() && !isValidLength(str)) {
282 fl_set_object_label(fd_form_table_options->text_warning,
283 _("Warning: Invalid Length (valid example: 10mm)"));
284 fl_show_object(fd_form_table_options->text_warning);
287 if (((ob==fd_form_table_options->button_delete_row)&&(table->rows()<=1)) ||
288 ((ob==fd_form_table_options->button_delete_column)&&(table->columns()<=1)))
289 ob = fd_form_table_options->button_table_delete;
290 if (ob == fd_form_table_options->button_append_row)
291 num = LyXTabular::APPEND_ROW;
292 else if (ob == fd_form_table_options->button_append_column)
293 num = LyXTabular::APPEND_COLUMN;
294 else if (ob == fd_form_table_options->button_delete_row)
295 num = LyXTabular::DELETE_ROW;
296 else if (ob == fd_form_table_options->button_delete_column)
297 num = LyXTabular::DELETE_COLUMN;
298 else if (ob == fd_form_table_options->button_set_borders)
299 num = LyXTabular::SET_ALL_LINES;
300 else if (ob == fd_form_table_options->button_unset_borders)
301 num = LyXTabular::UNSET_ALL_LINES;
302 else if (ob == fd_form_table_options->radio_border_top)
303 num = LyXTabular::TOGGLE_LINE_TOP;
304 else if (ob == fd_form_table_options->radio_border_bottom)
305 num = LyXTabular::TOGGLE_LINE_BOTTOM;
306 else if (ob == fd_form_table_options->radio_border_left)
307 num = LyXTabular::TOGGLE_LINE_LEFT;
308 else if (ob == fd_form_table_options->radio_border_right)
309 num = LyXTabular::TOGGLE_LINE_RIGHT;
310 else if (ob == fd_form_table_options->radio_align_left)
311 num = LyXTabular::ALIGN_LEFT;
312 else if (ob == fd_form_table_options->radio_align_right)
313 num = LyXTabular::ALIGN_RIGHT;
314 else if (ob == fd_form_table_options->radio_align_center)
315 num = LyXTabular::ALIGN_CENTER;
316 else if ((ob == fd_form_table_options->button_table_delete) && !Confirmed) {
317 fl_set_object_label(fd_form_table_options->text_warning,
318 _("Confirm: press Delete-Button again"));
321 } else if ((ob == fd_form_table_options->button_table_delete)
323 num = LyXTabular::DELETE_TABULAR;
325 } else if (ob == fd_form_table_options->radio_multicolumn)
326 num = LyXTabular::MULTICOLUMN;
327 else if (ob == fd_form_table_options->radio_longtable) {
328 s = fl_get_button(fd_form_table_options->radio_longtable);
330 num = LyXTabular::SET_LONGTABULAR;
331 fl_activate_object(fd_form_table_options->radio_lt_firsthead);
332 fl_activate_object(fd_form_table_options->radio_lt_head);
333 fl_activate_object(fd_form_table_options->radio_lt_foot);
334 fl_activate_object(fd_form_table_options->radio_lt_lastfoot);
335 fl_activate_object(fd_form_table_options->radio_lt_newpage);
336 fl_set_button(fd_form_table_options->radio_lt_firsthead,
337 table->GetRowOfLTFirstHead(cell));
338 fl_set_button(fd_form_table_options->radio_lt_head,
339 table->GetRowOfLTHead(cell));
340 fl_set_button(fd_form_table_options->radio_lt_foot,
341 table->GetRowOfLTFoot(cell));
342 fl_set_button(fd_form_table_options->radio_lt_lastfoot,
343 table->GetRowOfLTLastFoot(cell));
344 fl_set_button(fd_form_table_options->radio_lt_firsthead,
345 table->GetLTNewPage(cell));
347 num = LyXTabular::UNSET_LONGTABULAR;
348 fl_deactivate_object(fd_form_table_options->radio_lt_firsthead);
349 fl_deactivate_object(fd_form_table_options->radio_lt_head);
350 fl_deactivate_object(fd_form_table_options->radio_lt_foot);
351 fl_deactivate_object(fd_form_table_options->radio_lt_lastfoot);
352 fl_deactivate_object(fd_form_table_options->radio_lt_newpage);
353 fl_set_button(fd_form_table_options->radio_lt_firsthead, 0);
354 fl_set_button(fd_form_table_options->radio_lt_firsthead, 0);
355 fl_set_button(fd_form_table_options->radio_lt_firsthead, 0);
356 fl_set_button(fd_form_table_options->radio_lt_firsthead, 0);
357 fl_set_button(fd_form_table_options->radio_lt_firsthead, 0);
358 fl_set_object_lcol(fd_form_table_options->radio_lt_firsthead,
360 fl_set_object_lcol(fd_form_table_options->radio_lt_head,
362 fl_set_object_lcol(fd_form_table_options->radio_lt_foot,
364 fl_set_object_lcol(fd_form_table_options->radio_lt_lastfoot,
366 fl_set_object_lcol(fd_form_table_options->radio_lt_newpage,
369 } else if (ob == fd_form_table_options->radio_rotate_table) {
370 s = fl_get_button(fd_form_table_options->radio_rotate_table);
372 num = LyXTabular::SET_ROTATE_TABULAR;
374 num = LyXTabular::UNSET_ROTATE_TABULAR;
375 } else if (ob == fd_form_table_options->radio_rotate_cell) {
376 s = fl_get_button(fd_form_table_options->radio_rotate_cell);
378 num = LyXTabular::SET_ROTATE_CELL;
380 num = LyXTabular::UNSET_ROTATE_CELL;
381 } else if (ob == fd_form_table_options->radio_linebreak_cell) {
382 num = LyXTabular::SET_LINEBREAKS;
383 } else if (ob == fd_form_table_options->radio_lt_firsthead) {
384 num = LyXTabular::SET_LTFIRSTHEAD;
385 } else if (ob == fd_form_table_options->radio_lt_head) {
386 num = LyXTabular::SET_LTHEAD;
387 } else if (ob == fd_form_table_options->radio_lt_foot) {
388 num = LyXTabular::SET_LTFOOT;
389 } else if (ob == fd_form_table_options->radio_lt_lastfoot) {
390 num = LyXTabular::SET_LTLASTFOOT;
391 } else if (ob == fd_form_table_options->radio_lt_newpage) {
392 num = LyXTabular::SET_LTNEWPAGE;
393 } else if (ob == fd_form_table_options->button_table_extra) {
394 OpenLayoutTableExtra();
396 } else if (ob == fd_form_table_extra->input_special_alignment) {
397 special = fl_get_input(fd_form_table_extra->input_special_alignment);
399 fl_get_input_cursorpos(ob, &extra_col_cursor_x, &dummy);
400 num = LyXTabular::SET_SPECIAL_COLUMN;
401 } else if (ob == fd_form_table_extra->input_special_multialign) {
402 special = fl_get_input(fd_form_table_extra->input_special_multialign);
404 fl_get_input_cursorpos(ob, &extra_multicol_cursor_x, &dummy);
405 num = LyXTabular::SET_SPECIAL_MULTI;
408 if (current_view->available()) {
409 current_view->hideCursor();
410 inset->TabularFeatures(current_view, num, special);
412 if (num == LyXTabular::DELETE_TABULAR) {
413 fl_set_focus_object(fd_form_table_options->form_table_options,
414 fd_form_table_options->button_table_delete);
415 fl_hide_form(fd_form_table_options->form_table_options);
417 UpdateLayoutTabular(true, inset);
421 void SetPWidthTabularCB(FL_OBJECT * ob, long)
427 fl_set_object_label(fd_form_table_options->text_warning, "");
429 if (ob == fd_form_table_options->input_column_width) {
430 string str = fl_get_input(ob);
431 if (!str.empty() && !isValidLength(str)) {
432 fl_set_object_label(fd_form_table_options->text_warning,
433 _("Warning: Invalid Length (valid example: 10mm)"));
434 fl_show_object(fd_form_table_options->text_warning);
437 if (current_view->available()){
438 current_view->hideCursor();
439 inset->TabularFeatures(current_view, LyXTabular::SET_PWIDTH, str);
441 MenuLayoutTabular(false, inset); // update for alignment
445 void TabularOptClose()