2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-2000 The LyX Team.
10 *======================================================*/
12 * FormTabular Interface Class Implementation
17 #include "FormTabular.h"
18 #include "form_tabular.h"
21 #include "insets/insettabular.h"
23 #include "xforms_helpers.h"
26 FormTabular::FormTabular(LyXView * lv, Dialogs * d)
27 : FormInset(lv, d, _("Tabular Layout"), new OkCancelReadOnlyPolicy),
28 dialog_(0), tabular_options_(0), column_options_(0),
29 cell_options_(0), longtable_options_(0),
30 inset_(0), actCell_(-1)
32 // let the dialog be shown
33 // This is a permanent connection so we won't bother
34 // storing a copy because we won't be disconnecting.
35 d->showTabular.connect(slot(this, &FormTabular::showInset));
36 d->updateTabular.connect(slot(this, &FormTabular::updateInset));
40 FormTabular::~FormTabular()
43 delete tabular_options_;
44 delete column_options_;
46 delete longtable_options_;
50 void FormTabular::redraw()
52 if(form() && form()->visible)
53 fl_redraw_form(form());
57 FL_FORM * outer_form = fl_get_active_folder(dialog_->tabFolder);
58 if (outer_form && outer_form->visible)
59 fl_redraw_form(outer_form);
63 FL_FORM * FormTabular::form() const
65 if (dialog_) return dialog_->form;
70 void FormTabular::disconnect()
73 FormInset::disconnect();
77 void FormTabular::showInset(InsetTabular * inset)
79 if (inset == 0) return;
81 // If connected to another inset, disconnect from it.
82 if (inset_ != inset) {
84 ih_ = inset->hideDialog.connect(slot(this, &FormTabular::hide));
92 void FormTabular::updateInset(InsetTabular * inset)
94 if (inset == 0 || inset_ == 0) return;
96 // If connected to another inset, disconnect from it.
97 if (inset_ != inset) {
99 ih_ = inset->hideDialog.connect(slot(this, &FormTabular::hide));
107 void FormTabular::build()
109 dialog_ = build_tabular();
110 tabular_options_ = build_tabular_options();
111 column_options_ = build_column_options();
112 cell_options_ = build_cell_options();
113 longtable_options_ = build_longtable_options();
115 // Workaround dumb xforms sizing bug
119 fl_set_input_return(column_options_->input_column_width,
121 fl_set_input_return(column_options_->input_special_alignment,
123 fl_set_input_return(cell_options_->input_mcolumn_width,
125 fl_set_input_return(cell_options_->input_special_multialign,
128 fl_addto_tabfolder(dialog_->tabFolder, _("Tabular"),
129 tabular_options_->form);
130 fl_addto_tabfolder(dialog_->tabFolder, _("Column/Row"),
131 column_options_->form);
132 fl_addto_tabfolder(dialog_->tabFolder, _("Cell"),
133 cell_options_->form);
134 fl_addto_tabfolder(dialog_->tabFolder, _("LongTable"),
135 longtable_options_->form);
139 void FormTabular::update()
141 if (!inset_ || !inset_->tabular)
144 LyXTabular * tabular = inset_->tabular;
153 actCell_ = cell = inset_->GetActCell();
154 int column = tabular->column_of_cell(cell)+1;
155 fl_set_object_label(dialog_->text_warning,"");
156 fl_activate_object(column_options_->input_special_alignment);
157 fl_activate_object(cell_options_->input_special_multialign);
158 fl_activate_object(column_options_->input_column_width);
159 sprintf(buf,"%d",column);
160 fl_set_input(dialog_->input_tabular_column, buf);
161 fl_deactivate_object(dialog_->input_tabular_column);
162 int row = tabular->row_of_cell(cell)+1;
163 sprintf(buf,"%d",row);
164 fl_set_input(dialog_->input_tabular_row, buf);
165 fl_deactivate_object(dialog_->input_tabular_row);
166 if (tabular->IsMultiColumn(cell)) {
167 fl_set_button(cell_options_->radio_multicolumn, 1);
168 fl_set_button(cell_options_->radio_border_top,
169 tabular->TopLine(cell)?1:0);
170 setEnabled(cell_options_->radio_border_top, true);
171 fl_set_button(cell_options_->radio_border_bottom,
172 tabular->BottomLine(cell)?1:0);
173 setEnabled(cell_options_->radio_border_bottom, true);
174 fl_set_button(cell_options_->radio_border_left,
175 tabular->LeftLine(cell)?1:0);
176 setEnabled(cell_options_->radio_border_left, true);
177 fl_set_button(cell_options_->radio_border_right,
178 tabular->RightLine(cell)?1:0);
179 setEnabled(cell_options_->radio_border_right, true);
180 pwidth = tabular->GetMColumnPWidth(cell);
181 align = tabular->GetAlignment(cell);
182 if (!pwidth.empty() || (align == LYX_ALIGN_LEFT))
183 fl_set_button(cell_options_->radio_align_left, 1);
184 else if (align == LYX_ALIGN_RIGHT)
185 fl_set_button(cell_options_->radio_align_right, 1);
187 fl_set_button(cell_options_->radio_align_center, 1);
188 setEnabled(cell_options_->radio_align_left, true);
189 setEnabled(cell_options_->radio_align_right, true);
190 setEnabled(cell_options_->radio_align_center, true);
191 align = tabular->GetVAlignment(cell);
192 fl_set_button(cell_options_->radio_valign_top, 0);
193 fl_set_button(cell_options_->radio_valign_bottom, 0);
194 fl_set_button(cell_options_->radio_valign_center, 0);
195 if (pwidth.empty() || (align == LyXTabular::LYX_VALIGN_CENTER))
196 fl_set_button(cell_options_->radio_valign_center, 1);
197 else if (align == LyXTabular::LYX_VALIGN_BOTTOM)
198 fl_set_button(cell_options_->radio_valign_bottom, 1);
200 fl_set_button(cell_options_->radio_valign_top, 1);
201 setEnabled(cell_options_->radio_valign_top, true);
202 setEnabled(cell_options_->radio_valign_bottom, true);
203 setEnabled(cell_options_->radio_valign_center, true);
204 special = tabular->GetAlignSpecial(cell,LyXTabular::SET_SPECIAL_MULTI);
205 fl_set_input(cell_options_->input_special_multialign, special.c_str());
206 fl_set_input(cell_options_->input_mcolumn_width,pwidth.c_str());
207 if (!lv_->buffer()->isReadonly()) {
208 setEnabled(cell_options_->input_special_multialign, true);
209 setEnabled(cell_options_->input_mcolumn_width, true);
212 setEnabled(cell_options_->radio_valign_top, !pwidth.empty());
213 setEnabled(cell_options_->radio_valign_bottom, !pwidth.empty());
214 setEnabled(cell_options_->radio_valign_center, !pwidth.empty());
216 setEnabled(cell_options_->radio_align_left, pwidth.empty());
217 setEnabled(cell_options_->radio_align_right, pwidth.empty());
218 setEnabled(cell_options_->radio_align_center, pwidth.empty());
220 fl_set_button(cell_options_->radio_multicolumn, 0);
222 fl_set_button(cell_options_->radio_border_top, 0);
223 setEnabled(cell_options_->radio_border_top, false);
225 fl_set_button(cell_options_->radio_border_bottom, 0);
226 setEnabled(cell_options_->radio_border_bottom, false);
228 fl_set_button(cell_options_->radio_border_left, 0);
229 setEnabled(cell_options_->radio_border_left, false);
231 fl_set_button(cell_options_->radio_border_right, 0);
232 setEnabled(cell_options_->radio_border_right, false);
234 fl_set_button(cell_options_->radio_align_left, 0);
235 setEnabled(cell_options_->radio_align_left, false);
237 fl_set_button(cell_options_->radio_align_right, 0);
238 setEnabled(cell_options_->radio_align_right, false);
240 fl_set_button(cell_options_->radio_align_center, 0);
241 setEnabled(cell_options_->radio_align_center, false);
243 fl_set_button(cell_options_->radio_valign_top, 0);
244 setEnabled(cell_options_->radio_valign_top, false);
246 fl_set_button(cell_options_->radio_valign_bottom, 0);
247 setEnabled(cell_options_->radio_valign_bottom, false);
249 fl_set_button(cell_options_->radio_valign_center, 0);
250 setEnabled(cell_options_->radio_valign_center, false);
252 fl_set_input(cell_options_->input_special_multialign, "");
253 setEnabled(cell_options_->input_special_multialign, false);
255 fl_set_input(cell_options_->input_mcolumn_width, "");
256 setEnabled(cell_options_->input_mcolumn_width, false);
258 if (tabular->GetRotateCell(cell))
259 fl_set_button(cell_options_->radio_rotate_cell, 1);
261 fl_set_button(cell_options_->radio_rotate_cell, 0);
262 if (tabular->TopLine(cell, true))
263 fl_set_button(column_options_->radio_border_top, 1);
265 fl_set_button(column_options_->radio_border_top, 0);
266 if (tabular->BottomLine(cell, true))
267 fl_set_button(column_options_->radio_border_bottom, 1);
269 fl_set_button(column_options_->radio_border_bottom, 0);
270 if (tabular->LeftLine(cell, true))
271 fl_set_button(column_options_->radio_border_left, 1);
273 fl_set_button(column_options_->radio_border_left, 0);
274 if (tabular->RightLine(cell, true))
275 fl_set_button(column_options_->radio_border_right, 1);
277 fl_set_button(column_options_->radio_border_right, 0);
278 special = tabular->GetAlignSpecial(cell,LyXTabular::SET_SPECIAL_COLUMN);
279 fl_set_input(column_options_->input_special_alignment, special.c_str());
281 bool const isReadonly = lv_->buffer()->isReadonly();
282 setEnabled(column_options_->input_special_alignment, !isReadonly);
284 pwidth = tabular->GetColumnPWidth(cell);
285 fl_set_input(column_options_->input_column_width,pwidth.c_str());
286 setEnabled(column_options_->input_column_width, !isReadonly);
288 setEnabled(cell_options_->radio_useminipage, !pwidth.empty());
289 if (!pwidth.empty()) {
290 if (tabular->GetUsebox(cell) == 2)
291 fl_set_button(cell_options_->radio_useminipage, 1);
293 fl_set_button(cell_options_->radio_useminipage, 0);
295 fl_set_button(cell_options_->radio_useminipage,0);
297 align = tabular->GetAlignment(cell, true);
298 fl_set_button(column_options_->radio_align_left, 0);
299 fl_set_button(column_options_->radio_align_right, 0);
300 fl_set_button(column_options_->radio_align_center, 0);
301 if (!pwidth.empty() || (align == LYX_ALIGN_LEFT))
302 fl_set_button(column_options_->radio_align_left, 1);
303 else if (align == LYX_ALIGN_RIGHT)
304 fl_set_button(column_options_->radio_align_right, 1);
306 fl_set_button(column_options_->radio_align_center, 1);
307 align = tabular->GetVAlignment(cell, true);
308 fl_set_button(column_options_->radio_valign_top, 0);
309 fl_set_button(column_options_->radio_valign_bottom, 0);
310 fl_set_button(column_options_->radio_valign_center, 0);
311 if (pwidth.empty() || (align == LyXTabular::LYX_VALIGN_CENTER))
312 fl_set_button(column_options_->radio_valign_center, 1);
313 else if (align == LyXTabular::LYX_VALIGN_BOTTOM)
314 fl_set_button(column_options_->radio_valign_bottom, 1);
316 fl_set_button(column_options_->radio_valign_top, 1);
318 setEnabled(column_options_->radio_align_left, pwidth.empty());
319 setEnabled(column_options_->radio_align_right, pwidth.empty());
320 setEnabled(column_options_->radio_align_center, pwidth.empty());
322 setEnabled(column_options_->radio_valign_top, !pwidth.empty());
323 setEnabled(column_options_->radio_valign_bottom, !pwidth.empty());
324 setEnabled(column_options_->radio_valign_center, !pwidth.empty());
326 fl_set_button(tabular_options_->radio_longtable,
327 tabular->IsLongTabular());
329 bool const enable = tabular->IsLongTabular();
330 setEnabled(longtable_options_->radio_lt_firsthead, enable);
331 setEnabled(longtable_options_->radio_lt_head, enable);
332 setEnabled(longtable_options_->radio_lt_foot, enable);
333 setEnabled(longtable_options_->radio_lt_lastfoot, enable);
334 setEnabled(longtable_options_->radio_lt_newpage, enable);
338 fl_set_button(longtable_options_->radio_lt_firsthead,
339 tabular->GetRowOfLTFirstHead(cell, dummy));
340 fl_set_button(longtable_options_->radio_lt_head,
341 tabular->GetRowOfLTHead(cell, dummy));
342 fl_set_button(longtable_options_->radio_lt_foot,
343 tabular->GetRowOfLTFoot(cell, dummy));
344 fl_set_button(longtable_options_->radio_lt_lastfoot,
345 tabular->GetRowOfLTLastFoot(cell, dummy));
346 fl_set_button(longtable_options_->radio_lt_newpage,
347 tabular->GetLTNewPage(cell));
349 fl_set_button(longtable_options_->radio_lt_firsthead,0);
350 fl_set_button(longtable_options_->radio_lt_head,0);
351 fl_set_button(longtable_options_->radio_lt_foot,0);
352 fl_set_button(longtable_options_->radio_lt_lastfoot,0);
353 fl_set_button(longtable_options_->radio_lt_newpage,0);
355 fl_set_button(tabular_options_->radio_rotate_tabular,
356 tabular->GetRotateTabular());
359 bool FormTabular::input(FL_OBJECT * ob, long)
364 LyXTabular * tabular = inset_->tabular;
366 LyXTabular::Feature num = LyXTabular::LAST_ACTION;
369 int cell = inset_->GetActCell();
370 if (actCell_ != cell) {
372 fl_set_object_label(dialog_->text_warning,
373 _("Warning: Wrong Cursor position, updated window"));
374 fl_show_object(dialog_->text_warning);
377 // No point in processing directives that you can't do anything with
378 // anyhow, so exit now if the buffer is read-only.
379 if (lv_->buffer()->isReadonly()) {
383 if (ob == column_options_->input_column_width) {
384 string 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_PWIDTH,str);
392 update(); // update for alignment
395 if (ob == cell_options_->input_mcolumn_width) {
396 string str = fl_get_input(ob);
397 if (!str.empty() && !isValidLength(str)) {
398 fl_set_object_label(dialog_->text_warning,
399 _("Warning: Invalid Length (valid example: 10mm)"));
400 fl_show_object(dialog_->text_warning);
403 inset_->TabularFeatures(lv_->view(), LyXTabular::SET_MPWIDTH,str);
404 update(); // update for alignment
407 string str = fl_get_input(column_options_->input_column_width);
408 if (!str.empty() && !isValidLength(str)) {
410 dialog_->text_warning,
411 _("Warning: Invalid Length (valid example: 10mm)"));
412 fl_show_object(dialog_->text_warning);
415 if (ob == tabular_options_->button_append_row)
416 num = LyXTabular::APPEND_ROW;
417 else if (ob == tabular_options_->button_append_column)
418 num = LyXTabular::APPEND_COLUMN;
419 else if (ob == tabular_options_->button_delete_row)
420 num = LyXTabular::DELETE_ROW;
421 else if (ob == tabular_options_->button_delete_column)
422 num = LyXTabular::DELETE_COLUMN;
423 else if (ob == tabular_options_->button_set_borders)
424 num = LyXTabular::SET_ALL_LINES;
425 else if (ob == tabular_options_->button_unset_borders)
426 num = LyXTabular::UNSET_ALL_LINES;
427 else if (ob == column_options_->radio_border_top)
428 num = LyXTabular::TOGGLE_LINE_TOP;
429 else if (ob == column_options_->radio_border_bottom)
430 num = LyXTabular::TOGGLE_LINE_BOTTOM;
431 else if (ob == column_options_->radio_border_left)
432 num = LyXTabular::TOGGLE_LINE_LEFT;
433 else if (ob == column_options_->radio_border_right)
434 num = LyXTabular::TOGGLE_LINE_RIGHT;
435 else if (ob == column_options_->radio_align_left)
436 num = LyXTabular::ALIGN_LEFT;
437 else if (ob == column_options_->radio_align_right)
438 num = LyXTabular::ALIGN_RIGHT;
439 else if (ob == column_options_->radio_align_center)
440 num = LyXTabular::ALIGN_CENTER;
441 else if (ob == column_options_->radio_valign_top)
442 num = LyXTabular::VALIGN_TOP;
443 else if (ob == column_options_->radio_valign_bottom)
444 num = LyXTabular::VALIGN_BOTTOM;
445 else if (ob == column_options_->radio_valign_center)
446 num = LyXTabular::VALIGN_CENTER;
447 else if (ob == cell_options_->radio_multicolumn)
448 num = LyXTabular::MULTICOLUMN;
449 else if (ob == tabular_options_->radio_longtable) {
451 fl_get_button(tabular_options_->radio_longtable);
453 setEnabled(longtable_options_->radio_lt_firsthead, enable);
454 setEnabled(longtable_options_->radio_lt_head, enable);
455 setEnabled(longtable_options_->radio_lt_foot, enable);
456 setEnabled(longtable_options_->radio_lt_lastfoot, enable);
457 setEnabled(longtable_options_->radio_lt_newpage, enable);
460 num = LyXTabular::SET_LONGTABULAR;
462 fl_set_button(longtable_options_->radio_lt_firsthead,
463 tabular->GetRowOfLTFirstHead(cell, dummy));
464 fl_set_button(longtable_options_->radio_lt_head,
465 tabular->GetRowOfLTHead(cell, dummy));
466 fl_set_button(longtable_options_->radio_lt_foot,
467 tabular->GetRowOfLTFoot(cell, dummy));
468 fl_set_button(longtable_options_->radio_lt_lastfoot,
469 tabular->GetRowOfLTLastFoot(cell, dummy));
470 fl_set_button(longtable_options_->radio_lt_firsthead,
471 tabular->GetLTNewPage(cell));
473 num = LyXTabular::UNSET_LONGTABULAR;
474 fl_set_button(longtable_options_->radio_lt_firsthead,0);
475 fl_set_button(longtable_options_->radio_lt_head,0);
476 fl_set_button(longtable_options_->radio_lt_foot,0);
477 fl_set_button(longtable_options_->radio_lt_lastfoot,0);
478 fl_set_button(longtable_options_->radio_lt_newpage,0);
480 } else if (ob == tabular_options_->radio_rotate_tabular) {
481 s = fl_get_button(tabular_options_->radio_rotate_tabular);
483 num = LyXTabular::SET_ROTATE_TABULAR;
485 num = LyXTabular::UNSET_ROTATE_TABULAR;
486 } else if (ob == cell_options_->radio_rotate_cell) {
487 s = fl_get_button(cell_options_->radio_rotate_cell);
489 num = LyXTabular::SET_ROTATE_CELL;
491 num = LyXTabular::UNSET_ROTATE_CELL;
492 } else if (ob == cell_options_->radio_useminipage) {
493 num = LyXTabular::SET_USEBOX;
495 } else if (ob == longtable_options_->radio_lt_firsthead) {
496 num = LyXTabular::SET_LTFIRSTHEAD;
497 } else if (ob == longtable_options_->radio_lt_head) {
498 num = LyXTabular::SET_LTHEAD;
499 } else if (ob == longtable_options_->radio_lt_foot) {
500 num = LyXTabular::SET_LTFOOT;
501 } else if (ob == longtable_options_->radio_lt_lastfoot) {
502 num = LyXTabular::SET_LTLASTFOOT;
503 } else if (ob == longtable_options_->radio_lt_newpage) {
504 num = LyXTabular::SET_LTNEWPAGE;
505 } else if (ob == column_options_->input_special_alignment) {
506 special = fl_get_input(column_options_->input_special_alignment);
507 num = LyXTabular::SET_SPECIAL_COLUMN;
508 } else if (ob == cell_options_->input_special_multialign) {
509 special = fl_get_input(cell_options_->input_special_multialign);
510 num = LyXTabular::SET_SPECIAL_MULTI;
511 } else if (ob == cell_options_->radio_border_top)
512 num = LyXTabular::M_TOGGLE_LINE_TOP;
513 else if (ob == cell_options_->radio_border_bottom)
514 num = LyXTabular::M_TOGGLE_LINE_BOTTOM;
515 else if (ob == cell_options_->radio_border_left)
516 num = LyXTabular::M_TOGGLE_LINE_LEFT;
517 else if (ob == cell_options_->radio_border_right)
518 num = LyXTabular::M_TOGGLE_LINE_RIGHT;
519 else if (ob == cell_options_->radio_align_left)
520 num = LyXTabular::M_ALIGN_LEFT;
521 else if (ob == cell_options_->radio_align_right)
522 num = LyXTabular::M_ALIGN_RIGHT;
523 else if (ob == cell_options_->radio_align_center)
524 num = LyXTabular::M_ALIGN_CENTER;
525 else if (ob == cell_options_->radio_valign_top)
526 num = LyXTabular::M_VALIGN_TOP;
527 else if (ob == cell_options_->radio_valign_bottom)
528 num = LyXTabular::M_VALIGN_BOTTOM;
529 else if (ob == cell_options_->radio_valign_center)
530 num = LyXTabular::M_VALIGN_CENTER;
534 inset_->TabularFeatures(lv_->view(), num, special);