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();
28 static int Confirmed = false;
31 // hack to keep the cursor from jumping to the end of the text in the Extra
32 // form input fields during editing. The values in LyXTabular itself is
33 // changed in real-time, but we have no callbacks for the input fields,
34 // so I simply store and restore the cursor position for now.
35 // (too much of a hazzle to do it proper; we'll trash all this code
37 static int extra_col_cursor_x; // need no y's, one-line input fields
38 static int extra_multicol_cursor_x;
42 bool UpdateLayoutTabular(int flag)
45 if (!current_view->available())
48 if (update && current_view->the_locking_inset &&
49 (current_view->the_locking_inset->LyxCode() == Inset::TABULAR_CODE)) {
51 string pwidth, special;
53 InsetTabular * inset = static_cast<InsetTabular *>
54 (current_view->the_locking_inset);
55 LyXTabular * table = inset->tabular;
57 int cell = inset->GetActCell();
59 int column = table->column_of_cell(cell)+1;
60 fl_set_object_label(fd_form_table_options->text_warning, "");
62 fl_activate_object(fd_form_table_extra->input_special_alignment);
63 fl_activate_object(fd_form_table_extra->input_special_multialign);
64 fl_activate_object(fd_form_table_options->input_column_width);
65 sprintf(buf, "%d", column);
66 fl_set_input(fd_form_table_options->input_table_column, buf);
67 fl_deactivate_object(fd_form_table_options->input_table_column);
68 int row = table->row_of_cell(cell)+1;
69 sprintf(buf, "%d", row);
70 fl_set_input(fd_form_table_options->input_table_row, buf);
71 fl_deactivate_object(fd_form_table_options->input_table_row);
72 if (table->IsMultiColumn(cell))
73 fl_set_button(fd_form_table_options->radio_multicolumn, 1);
75 fl_set_button(fd_form_table_options->radio_multicolumn, 0);
76 if (table->GetRotateCell(cell))
77 fl_set_button(fd_form_table_options->radio_rotate_cell, 1);
79 fl_set_button(fd_form_table_options->radio_rotate_cell, 0);
80 if (table->TopLine(cell))
81 fl_set_button(fd_form_table_options->radio_border_top, 1);
83 fl_set_button(fd_form_table_options->radio_border_top, 0);
84 if (table->BottomLine(cell))
85 fl_set_button(fd_form_table_options->radio_border_bottom, 1);
87 fl_set_button(fd_form_table_options->radio_border_bottom, 0);
88 if (table->LeftLine(cell))
89 fl_set_button(fd_form_table_options->radio_border_left, 1);
91 fl_set_button(fd_form_table_options->radio_border_left, 0);
92 if (table->RightLine(cell))
93 fl_set_button(fd_form_table_options->radio_border_right, 1);
95 fl_set_button(fd_form_table_options->radio_border_right, 0);
96 int align = table->GetAlignment(cell);
97 fl_set_button(fd_form_table_options->radio_align_left, 0);
98 fl_set_button(fd_form_table_options->radio_align_right, 0);
99 fl_set_button(fd_form_table_options->radio_align_center, 0);
100 special = table->GetAlignSpecial(cell, LyXTabular::SET_SPECIAL_COLUMN);
103 fl_set_input(fd_form_table_extra->input_special_alignment,
105 fl_set_input_cursorpos(fd_form_table_extra->input_special_alignment,
106 extra_col_cursor_x, 0); // restore the cursor
108 if (current_view->buffer()->isReadonly())
109 fl_deactivate_object(fd_form_table_extra->input_special_alignment);
110 special = table->GetAlignSpecial(cell, LyXTabular::SET_SPECIAL_MULTI);
113 fl_set_input(fd_form_table_extra->input_special_multialign,
115 fl_set_input_cursorpos(fd_form_table_extra->input_special_multialign,
116 extra_multicol_cursor_x, 0); // restore the cursor
118 if (current_view->buffer()->isReadonly())
119 fl_deactivate_object(fd_form_table_extra->input_special_multialign);
120 pwidth = table->GetPWidth(cell);
122 fl_set_input(fd_form_table_options->input_column_width, pwidth.c_str());
123 if (current_view->buffer()->isReadonly())
124 fl_deactivate_object(fd_form_table_options->input_column_width);
125 if (!pwidth.empty()) {
126 fl_activate_object(fd_form_table_options->radio_linebreak_cell);
127 fl_set_object_lcol(fd_form_table_options->radio_linebreak_cell,
129 fl_set_button(fd_form_table_options->radio_linebreak_cell,
130 table->GetLinebreaks(cell));
132 fl_deactivate_object(fd_form_table_options->radio_linebreak_cell);
133 fl_set_object_lcol(fd_form_table_options->radio_linebreak_cell,
135 fl_set_button(fd_form_table_options->radio_linebreak_cell, 0);
137 if ((!pwidth.empty() && !table->IsMultiColumn(cell)) ||
138 (align == LYX_ALIGN_LEFT))
139 fl_set_button(fd_form_table_options->radio_align_left, 1);
140 else if (align == LYX_ALIGN_RIGHT)
141 fl_set_button(fd_form_table_options->radio_align_right, 1);
143 fl_set_button(fd_form_table_options->radio_align_center, 1);
144 if (!pwidth.empty() && !table->IsMultiColumn(cell)) {
145 fl_deactivate_object(fd_form_table_options->radio_align_left);
146 fl_deactivate_object(fd_form_table_options->radio_align_right);
147 fl_deactivate_object(fd_form_table_options->radio_align_center);
148 fl_set_object_lcol(fd_form_table_options->radio_align_left,
150 fl_set_object_lcol(fd_form_table_options->radio_align_right,
152 fl_set_object_lcol(fd_form_table_options->radio_align_center,
155 fl_activate_object(fd_form_table_options->radio_align_left);
156 fl_activate_object(fd_form_table_options->radio_align_right);
157 fl_activate_object(fd_form_table_options->radio_align_center);
158 fl_set_object_lcol(fd_form_table_options->radio_align_left,
160 fl_set_object_lcol(fd_form_table_options->radio_align_right,
162 fl_set_object_lcol(fd_form_table_options->radio_align_center,
165 fl_set_button(fd_form_table_options->radio_longtable, table->IsLongTabular());
166 if (table->IsLongTabular()) {
167 fl_activate_object(fd_form_table_options->radio_lt_firsthead);
168 fl_activate_object(fd_form_table_options->radio_lt_head);
169 fl_activate_object(fd_form_table_options->radio_lt_foot);
170 fl_activate_object(fd_form_table_options->radio_lt_lastfoot);
171 fl_activate_object(fd_form_table_options->radio_lt_newpage);
172 fl_set_object_lcol(fd_form_table_options->radio_lt_firsthead,
174 fl_set_object_lcol(fd_form_table_options->radio_lt_head,
176 fl_set_object_lcol(fd_form_table_options->radio_lt_foot,
178 fl_set_object_lcol(fd_form_table_options->radio_lt_lastfoot,
180 fl_set_object_lcol(fd_form_table_options->radio_lt_newpage,
182 fl_set_button(fd_form_table_options->radio_lt_firsthead,
183 table->GetRowOfLTFirstHead(cell));
184 fl_set_button(fd_form_table_options->radio_lt_head,
185 table->GetRowOfLTHead(cell));
186 fl_set_button(fd_form_table_options->radio_lt_foot,
187 table->GetRowOfLTFoot(cell));
188 fl_set_button(fd_form_table_options->radio_lt_lastfoot,
189 table->GetRowOfLTLastFoot(cell));
190 fl_set_button(fd_form_table_options->radio_lt_newpage,
191 table->GetLTNewPage(cell));
193 fl_deactivate_object(fd_form_table_options->radio_lt_firsthead);
194 fl_deactivate_object(fd_form_table_options->radio_lt_head);
195 fl_deactivate_object(fd_form_table_options->radio_lt_foot);
196 fl_deactivate_object(fd_form_table_options->radio_lt_lastfoot);
197 fl_deactivate_object(fd_form_table_options->radio_lt_newpage);
198 fl_set_button(fd_form_table_options->radio_lt_firsthead, 0);
199 fl_set_button(fd_form_table_options->radio_lt_head, 0);
200 fl_set_button(fd_form_table_options->radio_lt_foot, 0);
201 fl_set_button(fd_form_table_options->radio_lt_lastfoot, 0);
202 fl_set_button(fd_form_table_options->radio_lt_newpage, 0);
203 fl_set_object_lcol(fd_form_table_options->radio_lt_firsthead,
205 fl_set_object_lcol(fd_form_table_options->radio_lt_head,
207 fl_set_object_lcol(fd_form_table_options->radio_lt_foot,
209 fl_set_object_lcol(fd_form_table_options->radio_lt_lastfoot,
211 fl_set_object_lcol(fd_form_table_options->radio_lt_newpage,
214 fl_set_button(fd_form_table_options->radio_rotate_table,
215 table->GetRotateTabular());
216 fl_set_focus_object(fd_form_table_options->form_table_options,
217 fd_form_table_options->button_table_delete);
218 } else if (fd_form_table_options->form_table_options->visible) {
219 fl_set_focus_object(fd_form_table_options->form_table_options,
220 fd_form_table_options->button_table_delete);
221 fl_hide_form(fd_form_table_options->form_table_options);
227 void TabularOptionsCB(FL_OBJECT * ob, long)
229 if (!current_view->available() || !current_view->the_locking_inset ||
230 (current_view->the_locking_inset->LyxCode() != Inset::TABULAR_CODE)) {
237 InsetTabular * inset = static_cast<InsetTabular *>
238 (current_view->the_locking_inset);
239 LyXTabular * table = inset->tabular;
241 int cell = inset->GetActCell();
242 if (ActCell != cell) {
244 fl_set_object_label(fd_form_table_options->text_warning,
245 _("Warning: Wrong Cursor position, updated window"));
246 fl_show_object(fd_form_table_options->text_warning);
247 extra_col_cursor_x = 0; // would rather place it at the end, but...
248 extra_multicol_cursor_x = 0;
252 // No point in processing directives that you can't do anything with
253 // anyhow, so exit now if the buffer is read-only.
254 if (current_view->buffer()->isReadonly()) {
259 if (ob != fd_form_table_options->button_table_delete) {
260 fl_set_object_label(fd_form_table_options->text_warning, "");
263 str = fl_get_input(fd_form_table_options->input_column_width);
264 if (!str.empty() && !isValidLength(str)) {
265 fl_set_object_label(fd_form_table_options->text_warning,
266 _("Warning: Invalid Length (valid example: 10mm)"));
267 fl_show_object(fd_form_table_options->text_warning);
270 if (((ob==fd_form_table_options->button_delete_row)&&(table->rows()<=1)) ||
271 ((ob==fd_form_table_options->button_delete_column)&&(table->columns()<=1)))
272 ob = fd_form_table_options->button_table_delete;
273 if (ob == fd_form_table_options->button_append_row)
274 num = LyXTabular::APPEND_ROW;
275 else if (ob == fd_form_table_options->button_append_column)
276 num = LyXTabular::APPEND_COLUMN;
277 else if (ob == fd_form_table_options->button_delete_row)
278 num = LyXTabular::DELETE_ROW;
279 else if (ob == fd_form_table_options->button_delete_column)
280 num = LyXTabular::DELETE_COLUMN;
281 else if (ob == fd_form_table_options->button_set_borders)
282 num = LyXTabular::SET_ALL_LINES;
283 else if (ob == fd_form_table_options->button_unset_borders)
284 num = LyXTabular::UNSET_ALL_LINES;
285 else if (ob == fd_form_table_options->radio_border_top)
286 num = LyXTabular::TOGGLE_LINE_TOP;
287 else if (ob == fd_form_table_options->radio_border_bottom)
288 num = LyXTabular::TOGGLE_LINE_BOTTOM;
289 else if (ob == fd_form_table_options->radio_border_left)
290 num = LyXTabular::TOGGLE_LINE_LEFT;
291 else if (ob == fd_form_table_options->radio_border_right)
292 num = LyXTabular::TOGGLE_LINE_RIGHT;
293 else if (ob == fd_form_table_options->radio_align_left)
294 num = LyXTabular::ALIGN_LEFT;
295 else if (ob == fd_form_table_options->radio_align_right)
296 num = LyXTabular::ALIGN_RIGHT;
297 else if (ob == fd_form_table_options->radio_align_center)
298 num = LyXTabular::ALIGN_CENTER;
299 else if ((ob == fd_form_table_options->button_table_delete) && !Confirmed) {
300 fl_set_object_label(fd_form_table_options->text_warning,
301 _("Confirm: press Delete-Button again"));
304 } else if ((ob == fd_form_table_options->button_table_delete)
306 num = LyXTabular::DELETE_TABULAR;
308 } else if (ob == fd_form_table_options->radio_multicolumn)
309 num = LyXTabular::MULTICOLUMN;
310 else if (ob == fd_form_table_options->radio_longtable) {
311 s = fl_get_button(fd_form_table_options->radio_longtable);
313 num = LyXTabular::SET_LONGTABULAR;
314 fl_activate_object(fd_form_table_options->radio_lt_firsthead);
315 fl_activate_object(fd_form_table_options->radio_lt_head);
316 fl_activate_object(fd_form_table_options->radio_lt_foot);
317 fl_activate_object(fd_form_table_options->radio_lt_lastfoot);
318 fl_activate_object(fd_form_table_options->radio_lt_newpage);
319 fl_set_button(fd_form_table_options->radio_lt_firsthead,
320 table->GetRowOfLTFirstHead(cell));
321 fl_set_button(fd_form_table_options->radio_lt_head,
322 table->GetRowOfLTHead(cell));
323 fl_set_button(fd_form_table_options->radio_lt_foot,
324 table->GetRowOfLTFoot(cell));
325 fl_set_button(fd_form_table_options->radio_lt_lastfoot,
326 table->GetRowOfLTLastFoot(cell));
327 fl_set_button(fd_form_table_options->radio_lt_firsthead,
328 table->GetLTNewPage(cell));
330 num = LyXTabular::UNSET_LONGTABULAR;
331 fl_deactivate_object(fd_form_table_options->radio_lt_firsthead);
332 fl_deactivate_object(fd_form_table_options->radio_lt_head);
333 fl_deactivate_object(fd_form_table_options->radio_lt_foot);
334 fl_deactivate_object(fd_form_table_options->radio_lt_lastfoot);
335 fl_deactivate_object(fd_form_table_options->radio_lt_newpage);
336 fl_set_button(fd_form_table_options->radio_lt_firsthead, 0);
337 fl_set_button(fd_form_table_options->radio_lt_firsthead, 0);
338 fl_set_button(fd_form_table_options->radio_lt_firsthead, 0);
339 fl_set_button(fd_form_table_options->radio_lt_firsthead, 0);
340 fl_set_button(fd_form_table_options->radio_lt_firsthead, 0);
341 fl_set_object_lcol(fd_form_table_options->radio_lt_firsthead,
343 fl_set_object_lcol(fd_form_table_options->radio_lt_head,
345 fl_set_object_lcol(fd_form_table_options->radio_lt_foot,
347 fl_set_object_lcol(fd_form_table_options->radio_lt_lastfoot,
349 fl_set_object_lcol(fd_form_table_options->radio_lt_newpage,
352 } else if (ob == fd_form_table_options->radio_rotate_table) {
353 s = fl_get_button(fd_form_table_options->radio_rotate_table);
355 num = LyXTabular::SET_ROTATE_TABULAR;
357 num = LyXTabular::UNSET_ROTATE_TABULAR;
358 } else if (ob == fd_form_table_options->radio_rotate_cell) {
359 s = fl_get_button(fd_form_table_options->radio_rotate_cell);
361 num = LyXTabular::SET_ROTATE_CELL;
363 num = LyXTabular::UNSET_ROTATE_CELL;
364 } else if (ob == fd_form_table_options->radio_linebreak_cell) {
365 num = LyXTabular::SET_LINEBREAKS;
366 } else if (ob == fd_form_table_options->radio_lt_firsthead) {
367 num = LyXTabular::SET_LTFIRSTHEAD;
368 } else if (ob == fd_form_table_options->radio_lt_head) {
369 num = LyXTabular::SET_LTHEAD;
370 } else if (ob == fd_form_table_options->radio_lt_foot) {
371 num = LyXTabular::SET_LTFOOT;
372 } else if (ob == fd_form_table_options->radio_lt_lastfoot) {
373 num = LyXTabular::SET_LTLASTFOOT;
374 } else if (ob == fd_form_table_options->radio_lt_newpage) {
375 num = LyXTabular::SET_LTNEWPAGE;
376 } else if (ob == fd_form_table_options->button_table_extra) {
377 OpenLayoutTableExtra();
379 } else if (ob == fd_form_table_extra->input_special_alignment) {
380 special = fl_get_input(fd_form_table_extra->input_special_alignment);
382 fl_get_input_cursorpos(ob, &extra_col_cursor_x, &dummy);
383 num = LyXTabular::SET_SPECIAL_COLUMN;
384 } else if (ob == fd_form_table_extra->input_special_multialign) {
385 special = fl_get_input(fd_form_table_extra->input_special_multialign);
387 fl_get_input_cursorpos(ob, &extra_multicol_cursor_x, &dummy);
388 num = LyXTabular::SET_SPECIAL_MULTI;
391 if (current_view->available()) {
392 current_view->hideCursor();
393 // if ((num == LyXTabular::SET_SPECIAL_COLUMN) ||
394 // (num == LyXTabular::SET_SPECIAL_MULTI))
395 inset->TabularFeatures(current_view, num, special);
397 // inset->TabularFeatures(num);
399 if (num == LyXTabular::DELETE_TABULAR) {
400 fl_set_focus_object(fd_form_table_options->form_table_options,
401 fd_form_table_options->button_table_delete);
402 fl_hide_form(fd_form_table_options->form_table_options);
404 UpdateLayoutTabular(true);
408 void SetPWidthTabularCB(FL_OBJECT * ob, long)
410 if (!current_view->available() || !current_view->the_locking_inset ||
411 (current_view->the_locking_inset->LyxCode() != Inset::TABULAR_CODE)) {
414 InsetTabular * inset = static_cast<InsetTabular *>
415 (current_view->the_locking_inset);
417 fl_set_object_label(fd_form_table_options->text_warning, "");
419 if (ob == fd_form_table_options->input_column_width) {
420 string str = fl_get_input(ob);
421 if (!str.empty() && !isValidLength(str)) {
422 fl_set_object_label(fd_form_table_options->text_warning,
423 _("Warning: Invalid Length (valid example: 10mm)"));
424 fl_show_object(fd_form_table_options->text_warning);
427 if (current_view->available()){
428 current_view->hideCursor();
429 inset->TabularFeatures(current_view, LyXTabular::SET_PWIDTH, str);
431 MenuLayoutTable(0); // update for alignment