1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 The LyX Team.
9 *======================================================*/
11 * FormTabular Interface Class Implementation
17 #pragma implementation
20 #include "FormTabular.h"
21 #include "form_tabular.h"
24 #include "insets/insettabular.h"
26 #include "xforms_helpers.h"
30 FormTabular::FormTabular(LyXView * lv, Dialogs * d)
31 : FormInset(lv, d, _("Tabular Layout")),
32 inset_(0), actCell_(-1)
34 // let the dialog be shown
35 // This is a permanent connection so we won't bother
36 // storing a copy because we won't be disconnecting.
37 d->showTabular.connect(slot(this, &FormTabular::showInset));
38 d->updateTabular.connect(slot(this, &FormTabular::updateInset));
42 void FormTabular::redraw()
44 if(form() && form()->visible)
45 fl_redraw_form(form());
49 FL_FORM * outer_form = fl_get_active_folder(dialog_->tabFolder);
50 if (outer_form && outer_form->visible)
51 fl_redraw_form(outer_form);
55 FL_FORM * FormTabular::form() const
63 void FormTabular::disconnect()
66 FormInset::disconnect();
70 void FormTabular::showInset(InsetTabular * inset)
72 if (inset == 0) return;
74 // If connected to another inset, disconnect from it.
75 if (inset_ != inset) {
77 ih_ = inset->hideDialog.connect(slot(this, &FormTabular::hide));
85 void FormTabular::updateInset(InsetTabular * inset)
87 if (inset == 0 || inset_ == 0) return;
89 // If connected to another inset, disconnect from it.
90 if (inset_ != inset) {
92 ih_ = inset->hideDialog.connect(slot(this, &FormTabular::hide));
100 void FormTabular::build()
102 dialog_.reset(build_tabular());
103 tabular_options_.reset(build_tabular_options());
104 column_options_.reset(build_column_options());
105 cell_options_.reset(build_cell_options());
106 longtable_options_.reset(build_longtable_options());
108 fl_set_input_return(column_options_->input_column_width,
110 fl_set_input_return(column_options_->input_special_alignment,
112 fl_set_input_return(cell_options_->input_mcolumn_width,
114 fl_set_input_return(cell_options_->input_special_multialign,
117 fl_addto_tabfolder(dialog_->tabFolder, _("Tabular"),
118 tabular_options_->form);
119 fl_addto_tabfolder(dialog_->tabFolder, _("Column/Row"),
120 column_options_->form);
121 fl_addto_tabfolder(dialog_->tabFolder, _("Cell"),
122 cell_options_->form);
123 fl_addto_tabfolder(dialog_->tabFolder, _("LongTable"),
124 longtable_options_->form);
128 void FormTabular::update()
130 if (!inset_ || !inset_->tabular.get())
133 LyXTabular * tabular = inset_->tabular.get();
139 int cell = inset_->getActCell();
141 int column = tabular->column_of_cell(cell)+1;
142 fl_set_object_label(dialog_->text_warning,"");
143 fl_activate_object(column_options_->input_special_alignment);
144 fl_activate_object(cell_options_->input_special_multialign);
145 fl_activate_object(column_options_->input_column_width);
146 sprintf(buf,"%d",column);
147 fl_set_input(dialog_->input_tabular_column, buf);
148 fl_deactivate_object(dialog_->input_tabular_column);
149 int row = tabular->row_of_cell(cell)+1;
150 sprintf(buf,"%d",row);
151 fl_set_input(dialog_->input_tabular_row, buf);
152 fl_deactivate_object(dialog_->input_tabular_row);
153 if (tabular->IsMultiColumn(cell)) {
154 fl_set_button(cell_options_->radio_multicolumn, 1);
155 fl_set_button(cell_options_->radio_border_top,
156 tabular->TopLine(cell)?1:0);
157 setEnabled(cell_options_->radio_border_top, true);
158 fl_set_button(cell_options_->radio_border_bottom,
159 tabular->BottomLine(cell)?1:0);
160 setEnabled(cell_options_->radio_border_bottom, true);
161 fl_set_button(cell_options_->radio_border_left,
162 tabular->LeftLine(cell)?1:0);
163 setEnabled(cell_options_->radio_border_left, true);
164 fl_set_button(cell_options_->radio_border_right,
165 tabular->RightLine(cell)?1:0);
166 setEnabled(cell_options_->radio_border_right, true);
167 pwidth = tabular->GetMColumnPWidth(cell);
168 align = tabular->GetAlignment(cell);
169 if (!pwidth.empty() || (align == LYX_ALIGN_LEFT))
170 fl_set_button(cell_options_->radio_align_left, 1);
171 else if (align == LYX_ALIGN_RIGHT)
172 fl_set_button(cell_options_->radio_align_right, 1);
174 fl_set_button(cell_options_->radio_align_center, 1);
175 setEnabled(cell_options_->radio_align_left, true);
176 setEnabled(cell_options_->radio_align_right, true);
177 setEnabled(cell_options_->radio_align_center, true);
178 align = tabular->GetVAlignment(cell);
179 fl_set_button(cell_options_->radio_valign_top, 0);
180 fl_set_button(cell_options_->radio_valign_bottom, 0);
181 fl_set_button(cell_options_->radio_valign_center, 0);
182 if (pwidth.empty() || (align == LyXTabular::LYX_VALIGN_CENTER))
183 fl_set_button(cell_options_->radio_valign_center, 1);
184 else if (align == LyXTabular::LYX_VALIGN_BOTTOM)
185 fl_set_button(cell_options_->radio_valign_bottom, 1);
187 fl_set_button(cell_options_->radio_valign_top, 1);
188 setEnabled(cell_options_->radio_valign_top, true);
189 setEnabled(cell_options_->radio_valign_bottom, true);
190 setEnabled(cell_options_->radio_valign_center, true);
191 special = tabular->GetAlignSpecial(cell,LyXTabular::SET_SPECIAL_MULTI);
192 fl_set_input(cell_options_->input_special_multialign, special.c_str());
193 fl_set_input(cell_options_->input_mcolumn_width,pwidth.c_str());
194 if (!lv_->buffer()->isReadonly()) {
195 setEnabled(cell_options_->input_special_multialign, true);
196 setEnabled(cell_options_->input_mcolumn_width, true);
199 setEnabled(cell_options_->radio_valign_top, !pwidth.empty());
200 setEnabled(cell_options_->radio_valign_bottom, !pwidth.empty());
201 setEnabled(cell_options_->radio_valign_center, !pwidth.empty());
203 setEnabled(cell_options_->radio_align_left, pwidth.empty());
204 setEnabled(cell_options_->radio_align_right, pwidth.empty());
205 setEnabled(cell_options_->radio_align_center, pwidth.empty());
207 fl_set_button(cell_options_->radio_multicolumn, 0);
209 fl_set_button(cell_options_->radio_border_top, 0);
210 setEnabled(cell_options_->radio_border_top, false);
212 fl_set_button(cell_options_->radio_border_bottom, 0);
213 setEnabled(cell_options_->radio_border_bottom, false);
215 fl_set_button(cell_options_->radio_border_left, 0);
216 setEnabled(cell_options_->radio_border_left, false);
218 fl_set_button(cell_options_->radio_border_right, 0);
219 setEnabled(cell_options_->radio_border_right, false);
221 fl_set_button(cell_options_->radio_align_left, 0);
222 setEnabled(cell_options_->radio_align_left, false);
224 fl_set_button(cell_options_->radio_align_right, 0);
225 setEnabled(cell_options_->radio_align_right, false);
227 fl_set_button(cell_options_->radio_align_center, 0);
228 setEnabled(cell_options_->radio_align_center, false);
230 fl_set_button(cell_options_->radio_valign_top, 0);
231 setEnabled(cell_options_->radio_valign_top, false);
233 fl_set_button(cell_options_->radio_valign_bottom, 0);
234 setEnabled(cell_options_->radio_valign_bottom, false);
236 fl_set_button(cell_options_->radio_valign_center, 0);
237 setEnabled(cell_options_->radio_valign_center, false);
239 fl_set_input(cell_options_->input_special_multialign, "");
240 setEnabled(cell_options_->input_special_multialign, false);
242 fl_set_input(cell_options_->input_mcolumn_width, "");
243 setEnabled(cell_options_->input_mcolumn_width, false);
245 if (tabular->GetRotateCell(cell))
246 fl_set_button(cell_options_->radio_rotate_cell, 1);
248 fl_set_button(cell_options_->radio_rotate_cell, 0);
249 if (tabular->TopLine(cell, true))
250 fl_set_button(column_options_->radio_border_top, 1);
252 fl_set_button(column_options_->radio_border_top, 0);
253 if (tabular->BottomLine(cell, true))
254 fl_set_button(column_options_->radio_border_bottom, 1);
256 fl_set_button(column_options_->radio_border_bottom, 0);
257 if (tabular->LeftLine(cell, true))
258 fl_set_button(column_options_->radio_border_left, 1);
260 fl_set_button(column_options_->radio_border_left, 0);
261 if (tabular->RightLine(cell, true))
262 fl_set_button(column_options_->radio_border_right, 1);
264 fl_set_button(column_options_->radio_border_right, 0);
265 special = tabular->GetAlignSpecial(cell,LyXTabular::SET_SPECIAL_COLUMN);
266 fl_set_input(column_options_->input_special_alignment, special.c_str());
268 bool const isReadonly = lv_->buffer()->isReadonly();
269 setEnabled(column_options_->input_special_alignment, !isReadonly);
271 pwidth = tabular->GetColumnPWidth(cell);
272 fl_set_input(column_options_->input_column_width,pwidth.c_str());
273 setEnabled(column_options_->input_column_width, !isReadonly);
275 setEnabled(cell_options_->radio_useminipage, !pwidth.empty());
276 if (!pwidth.empty()) {
277 if (tabular->GetUsebox(cell) == 2)
278 fl_set_button(cell_options_->radio_useminipage, 1);
280 fl_set_button(cell_options_->radio_useminipage, 0);
282 fl_set_button(cell_options_->radio_useminipage,0);
284 align = tabular->GetAlignment(cell, true);
285 fl_set_button(column_options_->radio_align_left, 0);
286 fl_set_button(column_options_->radio_align_right, 0);
287 fl_set_button(column_options_->radio_align_center, 0);
288 if (!pwidth.empty() || (align == LYX_ALIGN_LEFT))
289 fl_set_button(column_options_->radio_align_left, 1);
290 else if (align == LYX_ALIGN_RIGHT)
291 fl_set_button(column_options_->radio_align_right, 1);
293 fl_set_button(column_options_->radio_align_center, 1);
294 align = tabular->GetVAlignment(cell, true);
295 fl_set_button(column_options_->radio_valign_top, 0);
296 fl_set_button(column_options_->radio_valign_bottom, 0);
297 fl_set_button(column_options_->radio_valign_center, 0);
298 if (pwidth.empty() || (align == LyXTabular::LYX_VALIGN_CENTER))
299 fl_set_button(column_options_->radio_valign_center, 1);
300 else if (align == LyXTabular::LYX_VALIGN_BOTTOM)
301 fl_set_button(column_options_->radio_valign_bottom, 1);
303 fl_set_button(column_options_->radio_valign_top, 1);
305 setEnabled(column_options_->radio_align_left, pwidth.empty());
306 setEnabled(column_options_->radio_align_right, pwidth.empty());
307 setEnabled(column_options_->radio_align_center, pwidth.empty());
309 setEnabled(column_options_->radio_valign_top, !pwidth.empty());
310 setEnabled(column_options_->radio_valign_bottom, !pwidth.empty());
311 setEnabled(column_options_->radio_valign_center, !pwidth.empty());
313 fl_set_button(tabular_options_->radio_longtable,
314 tabular->IsLongTabular());
316 bool const enable = tabular->IsLongTabular();
317 setEnabled(longtable_options_->radio_lt_firsthead, enable);
318 setEnabled(longtable_options_->radio_lt_head, enable);
319 setEnabled(longtable_options_->radio_lt_foot, enable);
320 setEnabled(longtable_options_->radio_lt_lastfoot, enable);
321 setEnabled(longtable_options_->radio_lt_newpage, enable);
325 fl_set_button(longtable_options_->radio_lt_firsthead,
326 tabular->GetRowOfLTFirstHead(cell, dummy));
327 fl_set_button(longtable_options_->radio_lt_head,
328 tabular->GetRowOfLTHead(cell, dummy));
329 fl_set_button(longtable_options_->radio_lt_foot,
330 tabular->GetRowOfLTFoot(cell, dummy));
331 fl_set_button(longtable_options_->radio_lt_lastfoot,
332 tabular->GetRowOfLTLastFoot(cell, dummy));
333 fl_set_button(longtable_options_->radio_lt_newpage,
334 tabular->GetLTNewPage(cell));
336 fl_set_button(longtable_options_->radio_lt_firsthead,0);
337 fl_set_button(longtable_options_->radio_lt_head,0);
338 fl_set_button(longtable_options_->radio_lt_foot,0);
339 fl_set_button(longtable_options_->radio_lt_lastfoot,0);
340 fl_set_button(longtable_options_->radio_lt_newpage,0);
342 fl_set_button(tabular_options_->radio_rotate_tabular,
343 tabular->GetRotateTabular());
347 bool FormTabular::input(FL_OBJECT * ob, long)
352 LyXTabular * tabular = inset_->tabular.get();
354 LyXTabular::Feature num = LyXTabular::LAST_ACTION;
357 int cell = inset_->getActCell();
358 if (actCell_ != cell) {
360 fl_set_object_label(dialog_->text_warning,
361 _("Warning: Wrong Cursor position, updated window"));
362 fl_show_object(dialog_->text_warning);
365 // No point in processing directives that you can't do anything with
366 // anyhow, so exit now if the buffer is read-only.
367 if (lv_->buffer()->isReadonly()) {
371 if (ob == column_options_->input_column_width) {
372 string const str = fl_get_input(ob);
373 if (!str.empty() && !isValidLength(str)) {
374 fl_set_object_label(dialog_->text_warning,
375 _("Warning: Invalid Length (valid example: 10mm)"));
376 fl_show_object(dialog_->text_warning);
379 inset_->tabularFeatures(lv_->view(), LyXTabular::SET_PWIDTH,str);
380 update(); // update for alignment
383 if (ob == cell_options_->input_mcolumn_width) {
384 string const str = fl_get_input(ob);
385 if (!str.empty() && !isValidLength(str)) {
386 fl_set_object_label(dialog_->text_warning,
387 _("Warning: Invalid Length (valid example: 10mm)"));
388 fl_show_object(dialog_->text_warning);
391 inset_->tabularFeatures(lv_->view(), LyXTabular::SET_MPWIDTH,str);
392 update(); // update for alignment
395 string const str = fl_get_input(column_options_->input_column_width);
396 if (!str.empty() && !isValidLength(str)) {
398 dialog_->text_warning,
399 _("Warning: Invalid Length (valid example: 10mm)"));
400 fl_show_object(dialog_->text_warning);
403 if (ob == tabular_options_->button_append_row)
404 num = LyXTabular::APPEND_ROW;
405 else if (ob == tabular_options_->button_append_column)
406 num = LyXTabular::APPEND_COLUMN;
407 else if (ob == tabular_options_->button_delete_row)
408 num = LyXTabular::DELETE_ROW;
409 else if (ob == tabular_options_->button_delete_column)
410 num = LyXTabular::DELETE_COLUMN;
411 else if (ob == tabular_options_->button_set_borders)
412 num = LyXTabular::SET_ALL_LINES;
413 else if (ob == tabular_options_->button_unset_borders)
414 num = LyXTabular::UNSET_ALL_LINES;
415 else if (ob == column_options_->radio_border_top)
416 num = LyXTabular::TOGGLE_LINE_TOP;
417 else if (ob == column_options_->radio_border_bottom)
418 num = LyXTabular::TOGGLE_LINE_BOTTOM;
419 else if (ob == column_options_->radio_border_left)
420 num = LyXTabular::TOGGLE_LINE_LEFT;
421 else if (ob == column_options_->radio_border_right)
422 num = LyXTabular::TOGGLE_LINE_RIGHT;
423 else if (ob == column_options_->radio_align_left)
424 num = LyXTabular::ALIGN_LEFT;
425 else if (ob == column_options_->radio_align_right)
426 num = LyXTabular::ALIGN_RIGHT;
427 else if (ob == column_options_->radio_align_center)
428 num = LyXTabular::ALIGN_CENTER;
429 else if (ob == column_options_->radio_valign_top)
430 num = LyXTabular::VALIGN_TOP;
431 else if (ob == column_options_->radio_valign_bottom)
432 num = LyXTabular::VALIGN_BOTTOM;
433 else if (ob == column_options_->radio_valign_center)
434 num = LyXTabular::VALIGN_CENTER;
435 else if (ob == cell_options_->radio_multicolumn)
436 num = LyXTabular::MULTICOLUMN;
437 else if (ob == tabular_options_->radio_longtable) {
439 fl_get_button(tabular_options_->radio_longtable);
441 setEnabled(longtable_options_->radio_lt_firsthead, enable);
442 setEnabled(longtable_options_->radio_lt_head, enable);
443 setEnabled(longtable_options_->radio_lt_foot, enable);
444 setEnabled(longtable_options_->radio_lt_lastfoot, enable);
445 setEnabled(longtable_options_->radio_lt_newpage, enable);
448 num = LyXTabular::SET_LONGTABULAR;
450 fl_set_button(longtable_options_->radio_lt_firsthead,
451 tabular->GetRowOfLTFirstHead(cell, dummy));
452 fl_set_button(longtable_options_->radio_lt_head,
453 tabular->GetRowOfLTHead(cell, dummy));
454 fl_set_button(longtable_options_->radio_lt_foot,
455 tabular->GetRowOfLTFoot(cell, dummy));
456 fl_set_button(longtable_options_->radio_lt_lastfoot,
457 tabular->GetRowOfLTLastFoot(cell, dummy));
458 fl_set_button(longtable_options_->radio_lt_firsthead,
459 tabular->GetLTNewPage(cell));
461 num = LyXTabular::UNSET_LONGTABULAR;
462 fl_set_button(longtable_options_->radio_lt_firsthead,0);
463 fl_set_button(longtable_options_->radio_lt_head,0);
464 fl_set_button(longtable_options_->radio_lt_foot,0);
465 fl_set_button(longtable_options_->radio_lt_lastfoot,0);
466 fl_set_button(longtable_options_->radio_lt_newpage,0);
468 } else if (ob == tabular_options_->radio_rotate_tabular) {
469 s = fl_get_button(tabular_options_->radio_rotate_tabular);
471 num = LyXTabular::SET_ROTATE_TABULAR;
473 num = LyXTabular::UNSET_ROTATE_TABULAR;
474 } else if (ob == cell_options_->radio_rotate_cell) {
475 s = fl_get_button(cell_options_->radio_rotate_cell);
477 num = LyXTabular::SET_ROTATE_CELL;
479 num = LyXTabular::UNSET_ROTATE_CELL;
480 } else if (ob == cell_options_->radio_useminipage) {
481 num = LyXTabular::SET_USEBOX;
483 } else if (ob == longtable_options_->radio_lt_firsthead) {
484 num = LyXTabular::SET_LTFIRSTHEAD;
485 } else if (ob == longtable_options_->radio_lt_head) {
486 num = LyXTabular::SET_LTHEAD;
487 } else if (ob == longtable_options_->radio_lt_foot) {
488 num = LyXTabular::SET_LTFOOT;
489 } else if (ob == longtable_options_->radio_lt_lastfoot) {
490 num = LyXTabular::SET_LTLASTFOOT;
491 } else if (ob == longtable_options_->radio_lt_newpage) {
492 num = LyXTabular::SET_LTNEWPAGE;
493 } else if (ob == column_options_->input_special_alignment) {
494 special = fl_get_input(column_options_->input_special_alignment);
495 num = LyXTabular::SET_SPECIAL_COLUMN;
496 } else if (ob == cell_options_->input_special_multialign) {
497 special = fl_get_input(cell_options_->input_special_multialign);
498 num = LyXTabular::SET_SPECIAL_MULTI;
499 } else if (ob == cell_options_->radio_border_top)
500 num = LyXTabular::M_TOGGLE_LINE_TOP;
501 else if (ob == cell_options_->radio_border_bottom)
502 num = LyXTabular::M_TOGGLE_LINE_BOTTOM;
503 else if (ob == cell_options_->radio_border_left)
504 num = LyXTabular::M_TOGGLE_LINE_LEFT;
505 else if (ob == cell_options_->radio_border_right)
506 num = LyXTabular::M_TOGGLE_LINE_RIGHT;
507 else if (ob == cell_options_->radio_align_left)
508 num = LyXTabular::M_ALIGN_LEFT;
509 else if (ob == cell_options_->radio_align_right)
510 num = LyXTabular::M_ALIGN_RIGHT;
511 else if (ob == cell_options_->radio_align_center)
512 num = LyXTabular::M_ALIGN_CENTER;
513 else if (ob == cell_options_->radio_valign_top)
514 num = LyXTabular::M_VALIGN_TOP;
515 else if (ob == cell_options_->radio_valign_bottom)
516 num = LyXTabular::M_VALIGN_BOTTOM;
517 else if (ob == cell_options_->radio_valign_center)
518 num = LyXTabular::M_VALIGN_CENTER;
522 inset_->tabularFeatures(lv_->view(), num, special);