2 * FormTabular Interface Class Implementation
6 #include "lyx_gui_misc.h"
8 #include FORMS_H_LOCATION
10 #include "FormTabular.h"
11 #include "xform_macros.h"
12 #include "input_validators.h"
18 #include "insets/insettabular.h"
22 #ifdef SIGC_CXX_NAMESPACES
26 C_RETURNCB(FormTabular, WMHideCB)
27 C_GENERICCB(FormTabular, CloseCB)
28 C_GENERICCB(FormTabular, InputCB)
29 C_GENERICCB(FormTabular, OKCB)
30 C_GENERICCB(FormTabular, ApplyCB)
31 C_GENERICCB(FormTabular, CancelCB)
34 FormTabular::FormTabular(LyXView * lv, Dialogs * d)
35 : dialog_(0), tabular_options_(0), column_options_(0),
36 cell_options_(0), longtable_options_(0), create_tabular_(0),
37 lv_(lv), d_(d), u_(0), h_(0), inset_(0), actCell_(-1)
39 // let the dialog be shown
40 // This is a permanent connection so we won't bother
41 // storing a copy because we won't be disconnecting.
42 d->showTabular.connect(slot(this, &FormTabular::showInset));
43 d->updateTabular.connect(slot(this, &FormTabular::updateInset));
44 d->hideTabular.connect(slot(this, &FormTabular::hideInset));
45 d->showTabularCreate.connect(slot(this, &FormTabular::show_create));
49 FormTabular::~FormTabular()
55 void FormTabular::build()
57 dialog_ = build_tabular();
58 tabular_options_ = build_tabular_options();
59 column_options_ = build_column_options();
60 cell_options_ = build_cell_options();
61 longtable_options_ = build_longtable_options();
62 create_tabular_ = build_create_tabular();
64 fl_set_input_return(column_options_->input_column_width,
66 fl_set_input_return(column_options_->input_special_alignment,
68 fl_set_input_return(cell_options_->input_mcolumn_width,
70 fl_set_input_return(cell_options_->input_special_multialign,
73 fl_addto_tabfolder(dialog_->tabFolder, _("Tabular"),
74 tabular_options_->form_tabular_options);
75 fl_addto_tabfolder(dialog_->tabFolder, _("Column/Row"),
76 column_options_->form_column_options);
77 fl_addto_tabfolder(dialog_->tabFolder, _("Cell"),
78 cell_options_->form_cell_options);
79 fl_addto_tabfolder(dialog_->tabFolder, _("LongTable"),
80 longtable_options_->form_longtable_options);
82 fl_set_form_atclose(dialog_->form_tabular,
83 C_FormTabularWMHideCB, 0);
85 fl_set_slider_bounds(create_tabular_->slider_rows, 1, 50);
86 fl_set_slider_bounds(create_tabular_->slider_columns, 1, 50);
87 fl_set_slider_value(create_tabular_->slider_rows, 5);
88 fl_set_slider_value(create_tabular_->slider_columns, 5);
89 fl_set_slider_precision(create_tabular_->slider_rows, 0);
90 fl_set_slider_precision(create_tabular_->slider_columns, 0);
91 fl_set_form_atclose(create_tabular_->form_create_tabular,
92 C_FormTabularWMHideCB, 0);
96 void FormTabular::show()
101 update(); // make sure its up-to-date
103 if (dialog_->form_tabular->visible) {
104 fl_raise_form(dialog_->form_tabular);
106 fl_show_form(dialog_->form_tabular,
107 FL_PLACE_MOUSE | FL_FREE_SIZE,
109 _("Tabular Layout"));
110 // u_ = d_->updateBufferDependent.connect(slot(this,
111 // &FormTabular::update));
112 h_ = d_->hideBufferDependent.connect(slot(this,
113 &FormTabular::hide));
117 void FormTabular::showInset(InsetTabular * ti)
125 void FormTabular::hide()
127 if (dialog_ && dialog_->form_tabular && dialog_->form_tabular->visible) {
128 fl_hide_form(dialog_->form_tabular);
136 void FormTabular::hideInset(InsetTabular * ti)
145 void FormTabular::update()
152 void FormTabular::updateInset(InsetTabular * ti)
155 if (ti && dialog_ && dialog_->form_tabular->visible) {
161 void FormTabular::free()
163 // we don't need to delete u and h here because
164 // hide() does that after disconnecting.
166 if (dialog_->form_tabular
167 && dialog_->form_tabular->visible) {
170 fl_free_form(dialog_->form_tabular);
174 fl_free_form(tabular_options_->form_tabular_options);
175 delete tabular_options_;
176 tabular_options_ = 0;
178 fl_free_form(column_options_->form_column_options);
179 delete column_options_;
182 fl_free_form(cell_options_->form_cell_options);
183 delete cell_options_;
186 fl_free_form(longtable_options_->form_longtable_options);
187 delete longtable_options_;
188 longtable_options_ = 0;
191 fl_free_form(create_tabular_->form_create_tabular);
192 delete create_tabular_;
198 int FormTabular::WMHideCB(FL_FORM * form, void *)
200 // Ensure that the signals (u and h) are disconnected even if the
201 // window manager is used to close the dialog.
202 FormTabular * pre = static_cast<FormTabular*>(form->u_vdata);
208 void FormTabular::CloseCB(FL_OBJECT * ob, long)
210 FormTabular * pre = static_cast<FormTabular*>(ob->form->u_vdata);
215 void FormTabular::InputCB(FL_OBJECT * ob, long l)
217 FormTabular * pre = static_cast<FormTabular*>(ob->form->u_vdata);
218 pre->SetTabularOptions(ob, l);
222 bool FormTabular::local_update(bool flag)
224 if (!inset_ || !inset_->tabular)
228 * tabular = inset_->tabular;
238 actCell_ = cell = inset_->GetActCell();
239 column = tabular->column_of_cell(cell)+1;
240 fl_set_object_label(dialog_->text_warning,"");
241 fl_activate_object(column_options_->input_special_alignment);
242 fl_activate_object(cell_options_->input_special_multialign);
243 fl_activate_object(column_options_->input_column_width);
244 sprintf(buf,"%d",column);
245 fl_set_input(dialog_->input_tabular_column, buf);
246 fl_deactivate_object(dialog_->input_tabular_column);
247 row = tabular->row_of_cell(cell)+1;
248 sprintf(buf,"%d",row);
249 fl_set_input(dialog_->input_tabular_row, buf);
250 fl_deactivate_object(dialog_->input_tabular_row);
251 if (tabular->IsMultiColumn(cell))
252 fl_set_button(cell_options_->radio_multicolumn, 1);
254 fl_set_button(cell_options_->radio_multicolumn, 0);
255 if (tabular->GetRotateCell(cell))
256 fl_set_button(cell_options_->radio_rotate_cell, 1);
258 fl_set_button(cell_options_->radio_rotate_cell, 0);
259 if (tabular->TopLine(cell))
260 fl_set_button(column_options_->radio_border_top, 1);
262 fl_set_button(column_options_->radio_border_top, 0);
263 if (tabular->BottomLine(cell))
264 fl_set_button(column_options_->radio_border_bottom, 1);
266 fl_set_button(column_options_->radio_border_bottom, 0);
267 if (tabular->LeftLine(cell))
268 fl_set_button(column_options_->radio_border_left, 1);
270 fl_set_button(column_options_->radio_border_left, 0);
271 if (tabular->RightLine(cell))
272 fl_set_button(column_options_->radio_border_right, 1);
274 fl_set_button(column_options_->radio_border_right, 0);
275 align = tabular->GetAlignment(cell);
276 fl_set_button(column_options_->radio_align_left, 0);
277 fl_set_button(column_options_->radio_align_right, 0);
278 fl_set_button(column_options_->radio_align_center, 0);
279 special = tabular->GetAlignSpecial(cell,LyXTabular::SET_SPECIAL_COLUMN);
281 fl_set_input(column_options_->input_special_alignment,
283 if (lv_->buffer()->isReadonly())
284 fl_deactivate_object(column_options_->input_special_alignment);
285 special = tabular->GetAlignSpecial(cell,LyXTabular::SET_SPECIAL_MULTI);
287 fl_set_input(cell_options_->input_special_multialign, special.c_str());
288 if (lv_->buffer()->isReadonly())
289 fl_deactivate_object(cell_options_->input_special_multialign);
290 pwidth = tabular->GetPWidth(cell);
292 fl_set_input(column_options_->input_column_width,pwidth.c_str());
293 if (lv_->buffer()->isReadonly()) {
294 fl_deactivate_object(column_options_->input_column_width);
296 fl_activate_object(column_options_->input_column_width);
298 if (!pwidth.empty()) {
299 fl_activate_object(cell_options_->radio_linebreak_cell);
300 fl_set_object_lcol(cell_options_->radio_linebreak_cell, FL_BLACK);
301 fl_set_button(cell_options_->radio_linebreak_cell,
302 tabular->GetLinebreaks(cell));
304 fl_deactivate_object(cell_options_->radio_linebreak_cell);
305 fl_set_object_lcol(cell_options_->radio_linebreak_cell, FL_INACTIVE);
306 fl_set_button(cell_options_->radio_linebreak_cell,0);
308 if ((!pwidth.empty() && !tabular->IsMultiColumn(cell)) ||
309 (align == LYX_ALIGN_LEFT))
310 fl_set_button(column_options_->radio_align_left, 1);
311 else if (align == LYX_ALIGN_RIGHT)
312 fl_set_button(column_options_->radio_align_right, 1);
314 fl_set_button(column_options_->radio_align_center, 1);
315 if (!pwidth.empty() && !tabular->IsMultiColumn(cell)) {
316 fl_deactivate_object(column_options_->radio_align_left);
317 fl_deactivate_object(column_options_->radio_align_right);
318 fl_deactivate_object(column_options_->radio_align_center);
319 fl_set_object_lcol(column_options_->radio_align_left, FL_INACTIVE);
320 fl_set_object_lcol(column_options_->radio_align_right, FL_INACTIVE);
321 fl_set_object_lcol(column_options_->radio_align_center, FL_INACTIVE);
323 fl_activate_object(column_options_->radio_align_left);
324 fl_activate_object(column_options_->radio_align_right);
325 fl_activate_object(column_options_->radio_align_center);
326 fl_set_object_lcol(column_options_->radio_align_left, FL_BLACK);
327 fl_set_object_lcol(column_options_->radio_align_right, FL_BLACK);
328 fl_set_object_lcol(column_options_->radio_align_center, FL_BLACK);
330 fl_set_button(tabular_options_->radio_longtable,
331 tabular->IsLongTabular());
332 if (tabular->IsLongTabular()) {
333 fl_activate_object(longtable_options_->radio_lt_firsthead);
334 fl_activate_object(longtable_options_->radio_lt_head);
335 fl_activate_object(longtable_options_->radio_lt_foot);
336 fl_activate_object(longtable_options_->radio_lt_lastfoot);
337 fl_activate_object(longtable_options_->radio_lt_newpage);
338 fl_set_object_lcol(longtable_options_->radio_lt_firsthead, FL_BLACK);
339 fl_set_object_lcol(longtable_options_->radio_lt_head, FL_BLACK);
340 fl_set_object_lcol(longtable_options_->radio_lt_foot, FL_BLACK);
341 fl_set_object_lcol(longtable_options_->radio_lt_lastfoot, FL_BLACK);
342 fl_set_object_lcol(longtable_options_->radio_lt_newpage, FL_BLACK);
343 fl_set_button(longtable_options_->radio_lt_firsthead,
344 tabular->GetRowOfLTFirstHead(cell));
345 fl_set_button(longtable_options_->radio_lt_head,
346 tabular->GetRowOfLTHead(cell));
347 fl_set_button(longtable_options_->radio_lt_foot,
348 tabular->GetRowOfLTFoot(cell));
349 fl_set_button(longtable_options_->radio_lt_lastfoot,
350 tabular->GetRowOfLTLastFoot(cell));
351 fl_set_button(longtable_options_->radio_lt_newpage,
352 tabular->GetLTNewPage(cell));
354 fl_deactivate_object(longtable_options_->radio_lt_firsthead);
355 fl_deactivate_object(longtable_options_->radio_lt_head);
356 fl_deactivate_object(longtable_options_->radio_lt_foot);
357 fl_deactivate_object(longtable_options_->radio_lt_lastfoot);
358 fl_deactivate_object(longtable_options_->radio_lt_newpage);
359 fl_set_button(longtable_options_->radio_lt_firsthead,0);
360 fl_set_button(longtable_options_->radio_lt_head,0);
361 fl_set_button(longtable_options_->radio_lt_foot,0);
362 fl_set_button(longtable_options_->radio_lt_lastfoot,0);
363 fl_set_button(longtable_options_->radio_lt_newpage,0);
364 fl_set_object_lcol(longtable_options_->radio_lt_firsthead,FL_INACTIVE);
365 fl_set_object_lcol(longtable_options_->radio_lt_head, FL_INACTIVE);
366 fl_set_object_lcol(longtable_options_->radio_lt_foot, FL_INACTIVE);
367 fl_set_object_lcol(longtable_options_->radio_lt_lastfoot, FL_INACTIVE);
368 fl_set_object_lcol(longtable_options_->radio_lt_newpage, FL_INACTIVE);
370 fl_set_button(tabular_options_->radio_rotate_tabular,
371 tabular->GetRotateTabular());
375 void FormTabular::SetTabularOptions(FL_OBJECT * ob, long)
381 * tabular = inset_->tabular;
390 cell = inset_->GetActCell();
391 if (actCell_ != cell) {
393 fl_set_object_label(dialog_->text_warning,
394 _("Warning: Wrong Cursor position, updated window"));
395 fl_show_object(dialog_->text_warning);
398 // No point in processing directives that you can't do anything with
399 // anyhow, so exit now if the buffer is read-only.
400 if (lv_->buffer()->isReadonly()) {
404 if (ob == column_options_->input_column_width) {
407 str = fl_get_input(ob);
408 if (!str.empty() && !isValidLength(str)) {
409 fl_set_object_label(dialog_->text_warning,
410 _("Warning: Invalid Length (valid example: 10mm)"));
411 fl_show_object(dialog_->text_warning);
414 inset_->TabularFeatures(lv_->view(), LyXTabular::SET_PWIDTH,str);
415 local_update(false); // update for alignment
418 str = fl_get_input(column_options_->input_column_width);
419 if (!str.empty() && !isValidLength(str)) {
421 dialog_->text_warning,
422 _("Warning: Invalid Length (valid example: 10mm)"));
423 fl_show_object(dialog_->text_warning);
426 if (ob == tabular_options_->button_append_row)
427 num = LyXTabular::APPEND_ROW;
428 else if (ob == tabular_options_->button_append_column)
429 num = LyXTabular::APPEND_COLUMN;
430 else if (ob == tabular_options_->button_delete_row)
431 num = LyXTabular::DELETE_ROW;
432 else if (ob == tabular_options_->button_delete_column)
433 num = LyXTabular::DELETE_COLUMN;
434 else if (ob == tabular_options_->button_set_borders)
435 num = LyXTabular::SET_ALL_LINES;
436 else if (ob == tabular_options_->button_unset_borders)
437 num = LyXTabular::UNSET_ALL_LINES;
438 else if (ob == column_options_->radio_border_top)
439 num = LyXTabular::TOGGLE_LINE_TOP;
440 else if (ob == column_options_->radio_border_bottom)
441 num = LyXTabular::TOGGLE_LINE_BOTTOM;
442 else if (ob == column_options_->radio_border_left)
443 num = LyXTabular::TOGGLE_LINE_LEFT;
444 else if (ob == column_options_->radio_border_right)
445 num = LyXTabular::TOGGLE_LINE_RIGHT;
446 else if (ob == column_options_->radio_align_left)
447 num = LyXTabular::ALIGN_LEFT;
448 else if (ob == column_options_->radio_align_right)
449 num = LyXTabular::ALIGN_RIGHT;
450 else if (ob == column_options_->radio_align_center)
451 num = LyXTabular::ALIGN_CENTER;
452 else if (ob == cell_options_->radio_multicolumn)
453 num = LyXTabular::MULTICOLUMN;
454 else if (ob == tabular_options_->radio_longtable) {
455 s=fl_get_button(tabular_options_->radio_longtable);
457 num = LyXTabular::SET_LONGTABULAR;
458 fl_activate_object(longtable_options_->radio_lt_firsthead);
459 fl_activate_object(longtable_options_->radio_lt_head);
460 fl_activate_object(longtable_options_->radio_lt_foot);
461 fl_activate_object(longtable_options_->radio_lt_lastfoot);
462 fl_activate_object(longtable_options_->radio_lt_newpage);
463 fl_set_button(longtable_options_->radio_lt_firsthead,
464 tabular->GetRowOfLTFirstHead(cell));
465 fl_set_button(longtable_options_->radio_lt_head,
466 tabular->GetRowOfLTHead(cell));
467 fl_set_button(longtable_options_->radio_lt_foot,
468 tabular->GetRowOfLTFoot(cell));
469 fl_set_button(longtable_options_->radio_lt_lastfoot,
470 tabular->GetRowOfLTLastFoot(cell));
471 fl_set_button(longtable_options_->radio_lt_firsthead,
472 tabular->GetLTNewPage(cell));
474 num = LyXTabular::UNSET_LONGTABULAR;
475 fl_deactivate_object(longtable_options_->radio_lt_firsthead);
476 fl_deactivate_object(longtable_options_->radio_lt_head);
477 fl_deactivate_object(longtable_options_->radio_lt_foot);
478 fl_deactivate_object(longtable_options_->radio_lt_lastfoot);
479 fl_deactivate_object(longtable_options_->radio_lt_newpage);
480 fl_set_button(longtable_options_->radio_lt_firsthead,0);
481 fl_set_button(longtable_options_->radio_lt_head,0);
482 fl_set_button(longtable_options_->radio_lt_foot,0);
483 fl_set_button(longtable_options_->radio_lt_lastfoot,0);
484 fl_set_button(longtable_options_->radio_lt_newpage,0);
485 fl_set_object_lcol(longtable_options_->radio_lt_firsthead,
487 fl_set_object_lcol(longtable_options_->radio_lt_head, FL_INACTIVE);
488 fl_set_object_lcol(longtable_options_->radio_lt_foot, FL_INACTIVE);
489 fl_set_object_lcol(longtable_options_->radio_lt_lastfoot,
491 fl_set_object_lcol(longtable_options_->radio_lt_newpage,
494 } else if (ob == tabular_options_->radio_rotate_tabular) {
495 s=fl_get_button(tabular_options_->radio_rotate_tabular);
497 num = LyXTabular::SET_ROTATE_TABULAR;
499 num = LyXTabular::UNSET_ROTATE_TABULAR;
500 } else if (ob == cell_options_->radio_rotate_cell) {
501 s=fl_get_button(cell_options_->radio_rotate_cell);
503 num = LyXTabular::SET_ROTATE_CELL;
505 num = LyXTabular::UNSET_ROTATE_CELL;
506 } else if (ob == cell_options_->radio_linebreak_cell) {
507 num = LyXTabular::SET_LINEBREAKS;
508 } else if (ob == longtable_options_->radio_lt_firsthead) {
509 num = LyXTabular::SET_LTFIRSTHEAD;
510 } else if (ob == longtable_options_->radio_lt_head) {
511 num = LyXTabular::SET_LTHEAD;
512 } else if (ob == longtable_options_->radio_lt_foot) {
513 num = LyXTabular::SET_LTFOOT;
514 } else if (ob == longtable_options_->radio_lt_lastfoot) {
515 num = LyXTabular::SET_LTLASTFOOT;
516 } else if (ob == longtable_options_->radio_lt_newpage) {
517 num = LyXTabular::SET_LTNEWPAGE;
518 } else if (ob == column_options_->input_special_alignment) {
519 special = fl_get_input(column_options_->input_special_alignment);
520 num = LyXTabular::SET_SPECIAL_COLUMN;
521 } else if (ob == cell_options_->input_special_multialign) {
522 special = fl_get_input(cell_options_->input_special_multialign);
523 num = LyXTabular::SET_SPECIAL_MULTI;
527 inset_->TabularFeatures(lv_->view(), num, special);
531 // +-----------------------------------------------------------------------+
532 // | Functions/Dialogs for creating tabular insets |
533 // +-----------------------------------------------------------------------+
535 void FormTabular::show_create()
540 if (create_tabular_->form_create_tabular->visible) {
541 fl_raise_form(create_tabular_->form_create_tabular);
543 fl_show_form(create_tabular_->form_create_tabular,
544 FL_PLACE_MOUSE | FL_FREE_SIZE,
545 FL_FULLBORDER, _("Insert Tabular"));
550 void FormTabular::hide_create()
552 if (create_tabular_->form_create_tabular &&
553 create_tabular_->form_create_tabular->visible)
554 fl_hide_form(create_tabular_->form_create_tabular);
558 void FormTabular::apply_create()
563 // comm->setMinibuffer(_("Inserting tabular inset..."));
564 ysize = int(fl_get_slider_value(create_tabular_->slider_columns) + 0.5);
565 xsize = int(fl_get_slider_value(create_tabular_->slider_rows) + 0.5);
566 InsetTabular * in = new InsetTabular(lv_->buffer(),xsize,ysize);
567 if (!lv_->view()->open_new_inset(in)) {
570 // comm->setMinibuffer(_("Tabular mode"));
574 void FormTabular::OKCB(FL_OBJECT * ob, long)
576 FormTabular * pre = (FormTabular*)ob->form->u_vdata;
582 void FormTabular::ApplyCB(FL_OBJECT * ob, long)
584 FormTabular * pre = (FormTabular*)ob->form->u_vdata;
589 void FormTabular::CancelCB(FL_OBJECT * ob, long)
591 FormTabular * pre = (FormTabular*)ob->form->u_vdata;