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
18 #pragma implementation
21 #include "FormTabular.h"
22 #include "form_tabular.h"
25 #include "insets/insettabular.h"
27 #include "xforms_helpers.h"
31 FormTabular::FormTabular(LyXView * lv, Dialogs * d)
32 : FormInset(lv, d, _("Tabular Layout")),
33 inset_(0), actCell_(-1)
35 // let the dialog be shown
36 // This is a permanent connection so we won't bother
37 // storing a copy because we won't be disconnecting.
38 d->showTabular.connect(slot(this, &FormTabular::showInset));
39 d->updateTabular.connect(slot(this, &FormTabular::updateInset));
43 void FormTabular::redraw()
45 if(form() && form()->visible)
46 fl_redraw_form(form());
50 FL_FORM * outer_form = fl_get_active_folder(dialog_->tabFolder);
51 if (outer_form && outer_form->visible)
52 fl_redraw_form(outer_form);
56 FL_FORM * FormTabular::form() const
64 void FormTabular::disconnect()
67 FormInset::disconnect();
71 void FormTabular::showInset(InsetTabular * inset)
73 if (inset == 0) return;
75 // If connected to another inset, disconnect from it.
76 if (inset_ != inset) {
78 ih_ = inset->hideDialog.connect(slot(this, &FormTabular::hide));
86 void FormTabular::updateInset(InsetTabular * inset)
88 if (inset == 0 || inset_ == 0) return;
90 // If connected to another inset, disconnect from it.
91 if (inset_ != inset) {
93 ih_ = inset->hideDialog.connect(slot(this, &FormTabular::hide));
101 void FormTabular::build()
103 dialog_.reset(build_tabular());
104 tabular_options_.reset(build_tabular_options());
105 column_options_.reset(build_column_options());
106 cell_options_.reset(build_cell_options());
107 longtable_options_.reset(build_longtable_options());
109 fl_set_input_return(column_options_->input_column_width,
111 fl_set_input_return(column_options_->input_special_alignment,
113 fl_set_input_return(cell_options_->input_mcolumn_width,
115 fl_set_input_return(cell_options_->input_special_multialign,
118 fl_addto_tabfolder(dialog_->tabFolder, _("Tabular"),
119 tabular_options_->form);
120 fl_addto_tabfolder(dialog_->tabFolder, _("Column/Row"),
121 column_options_->form);
122 fl_addto_tabfolder(dialog_->tabFolder, _("Cell"),
123 cell_options_->form);
124 fl_addto_tabfolder(dialog_->tabFolder, _("LongTable"),
125 longtable_options_->form);
129 void FormTabular::update()
131 if (!inset_ || !inset_->tabular)
134 LyXTabular * tabular = inset_->tabular;
143 actCell_ = cell = inset_->GetActCell();
144 int column = tabular->column_of_cell(cell)+1;
145 fl_set_object_label(dialog_->text_warning,"");
146 fl_activate_object(column_options_->input_special_alignment);
147 fl_activate_object(cell_options_->input_special_multialign);
148 fl_activate_object(column_options_->input_column_width);
149 sprintf(buf,"%d",column);
150 fl_set_input(dialog_->input_tabular_column, buf);
151 fl_deactivate_object(dialog_->input_tabular_column);
152 int row = tabular->row_of_cell(cell)+1;
153 sprintf(buf,"%d",row);
154 fl_set_input(dialog_->input_tabular_row, buf);
155 fl_deactivate_object(dialog_->input_tabular_row);
156 if (tabular->IsMultiColumn(cell)) {
157 fl_set_button(cell_options_->radio_multicolumn, 1);
158 fl_set_button(cell_options_->radio_border_top,
159 tabular->TopLine(cell)?1:0);
160 setEnabled(cell_options_->radio_border_top, true);
161 fl_set_button(cell_options_->radio_border_bottom,
162 tabular->BottomLine(cell)?1:0);
163 setEnabled(cell_options_->radio_border_bottom, true);
164 fl_set_button(cell_options_->radio_border_left,
165 tabular->LeftLine(cell)?1:0);
166 setEnabled(cell_options_->radio_border_left, true);
167 fl_set_button(cell_options_->radio_border_right,
168 tabular->RightLine(cell)?1:0);
169 setEnabled(cell_options_->radio_border_right, true);
170 pwidth = tabular->GetMColumnPWidth(cell);
171 align = tabular->GetAlignment(cell);
172 if (!pwidth.empty() || (align == LYX_ALIGN_LEFT))
173 fl_set_button(cell_options_->radio_align_left, 1);
174 else if (align == LYX_ALIGN_RIGHT)
175 fl_set_button(cell_options_->radio_align_right, 1);
177 fl_set_button(cell_options_->radio_align_center, 1);
178 setEnabled(cell_options_->radio_align_left, true);
179 setEnabled(cell_options_->radio_align_right, true);
180 setEnabled(cell_options_->radio_align_center, true);
181 align = tabular->GetVAlignment(cell);
182 fl_set_button(cell_options_->radio_valign_top, 0);
183 fl_set_button(cell_options_->radio_valign_bottom, 0);
184 fl_set_button(cell_options_->radio_valign_center, 0);
185 if (pwidth.empty() || (align == LyXTabular::LYX_VALIGN_CENTER))
186 fl_set_button(cell_options_->radio_valign_center, 1);
187 else if (align == LyXTabular::LYX_VALIGN_BOTTOM)
188 fl_set_button(cell_options_->radio_valign_bottom, 1);
190 fl_set_button(cell_options_->radio_valign_top, 1);
191 setEnabled(cell_options_->radio_valign_top, true);
192 setEnabled(cell_options_->radio_valign_bottom, true);
193 setEnabled(cell_options_->radio_valign_center, true);
194 special = tabular->GetAlignSpecial(cell,LyXTabular::SET_SPECIAL_MULTI);
195 fl_set_input(cell_options_->input_special_multialign, special.c_str());
196 fl_set_input(cell_options_->input_mcolumn_width,pwidth.c_str());
197 if (!lv_->buffer()->isReadonly()) {
198 setEnabled(cell_options_->input_special_multialign, true);
199 setEnabled(cell_options_->input_mcolumn_width, true);
202 setEnabled(cell_options_->radio_valign_top, !pwidth.empty());
203 setEnabled(cell_options_->radio_valign_bottom, !pwidth.empty());
204 setEnabled(cell_options_->radio_valign_center, !pwidth.empty());
206 setEnabled(cell_options_->radio_align_left, pwidth.empty());
207 setEnabled(cell_options_->radio_align_right, pwidth.empty());
208 setEnabled(cell_options_->radio_align_center, pwidth.empty());
210 fl_set_button(cell_options_->radio_multicolumn, 0);
212 fl_set_button(cell_options_->radio_border_top, 0);
213 setEnabled(cell_options_->radio_border_top, false);
215 fl_set_button(cell_options_->radio_border_bottom, 0);
216 setEnabled(cell_options_->radio_border_bottom, false);
218 fl_set_button(cell_options_->radio_border_left, 0);
219 setEnabled(cell_options_->radio_border_left, false);
221 fl_set_button(cell_options_->radio_border_right, 0);
222 setEnabled(cell_options_->radio_border_right, false);
224 fl_set_button(cell_options_->radio_align_left, 0);
225 setEnabled(cell_options_->radio_align_left, false);
227 fl_set_button(cell_options_->radio_align_right, 0);
228 setEnabled(cell_options_->radio_align_right, false);
230 fl_set_button(cell_options_->radio_align_center, 0);
231 setEnabled(cell_options_->radio_align_center, false);
233 fl_set_button(cell_options_->radio_valign_top, 0);
234 setEnabled(cell_options_->radio_valign_top, false);
236 fl_set_button(cell_options_->radio_valign_bottom, 0);
237 setEnabled(cell_options_->radio_valign_bottom, false);
239 fl_set_button(cell_options_->radio_valign_center, 0);
240 setEnabled(cell_options_->radio_valign_center, false);
242 fl_set_input(cell_options_->input_special_multialign, "");
243 setEnabled(cell_options_->input_special_multialign, false);
245 fl_set_input(cell_options_->input_mcolumn_width, "");
246 setEnabled(cell_options_->input_mcolumn_width, false);
248 if (tabular->GetRotateCell(cell))
249 fl_set_button(cell_options_->radio_rotate_cell, 1);
251 fl_set_button(cell_options_->radio_rotate_cell, 0);
252 if (tabular->TopLine(cell, true))
253 fl_set_button(column_options_->radio_border_top, 1);
255 fl_set_button(column_options_->radio_border_top, 0);
256 if (tabular->BottomLine(cell, true))
257 fl_set_button(column_options_->radio_border_bottom, 1);
259 fl_set_button(column_options_->radio_border_bottom, 0);
260 if (tabular->LeftLine(cell, true))
261 fl_set_button(column_options_->radio_border_left, 1);
263 fl_set_button(column_options_->radio_border_left, 0);
264 if (tabular->RightLine(cell, true))
265 fl_set_button(column_options_->radio_border_right, 1);
267 fl_set_button(column_options_->radio_border_right, 0);
268 special = tabular->GetAlignSpecial(cell,LyXTabular::SET_SPECIAL_COLUMN);
269 fl_set_input(column_options_->input_special_alignment, special.c_str());
271 bool const isReadonly = lv_->buffer()->isReadonly();
272 setEnabled(column_options_->input_special_alignment, !isReadonly);
274 pwidth = tabular->GetColumnPWidth(cell);
275 fl_set_input(column_options_->input_column_width,pwidth.c_str());
276 setEnabled(column_options_->input_column_width, !isReadonly);
278 setEnabled(cell_options_->radio_useminipage, !pwidth.empty());
279 if (!pwidth.empty()) {
280 if (tabular->GetUsebox(cell) == 2)
281 fl_set_button(cell_options_->radio_useminipage, 1);
283 fl_set_button(cell_options_->radio_useminipage, 0);
285 fl_set_button(cell_options_->radio_useminipage,0);
287 align = tabular->GetAlignment(cell, true);
288 fl_set_button(column_options_->radio_align_left, 0);
289 fl_set_button(column_options_->radio_align_right, 0);
290 fl_set_button(column_options_->radio_align_center, 0);
291 if (!pwidth.empty() || (align == LYX_ALIGN_LEFT))
292 fl_set_button(column_options_->radio_align_left, 1);
293 else if (align == LYX_ALIGN_RIGHT)
294 fl_set_button(column_options_->radio_align_right, 1);
296 fl_set_button(column_options_->radio_align_center, 1);
297 align = tabular->GetVAlignment(cell, true);
298 fl_set_button(column_options_->radio_valign_top, 0);
299 fl_set_button(column_options_->radio_valign_bottom, 0);
300 fl_set_button(column_options_->radio_valign_center, 0);
301 if (pwidth.empty() || (align == LyXTabular::LYX_VALIGN_CENTER))
302 fl_set_button(column_options_->radio_valign_center, 1);
303 else if (align == LyXTabular::LYX_VALIGN_BOTTOM)
304 fl_set_button(column_options_->radio_valign_bottom, 1);
306 fl_set_button(column_options_->radio_valign_top, 1);
308 setEnabled(column_options_->radio_align_left, pwidth.empty());
309 setEnabled(column_options_->radio_align_right, pwidth.empty());
310 setEnabled(column_options_->radio_align_center, pwidth.empty());
312 setEnabled(column_options_->radio_valign_top, !pwidth.empty());
313 setEnabled(column_options_->radio_valign_bottom, !pwidth.empty());
314 setEnabled(column_options_->radio_valign_center, !pwidth.empty());
316 fl_set_button(tabular_options_->radio_longtable,
317 tabular->IsLongTabular());
319 bool const enable = tabular->IsLongTabular();
320 setEnabled(longtable_options_->radio_lt_firsthead, enable);
321 setEnabled(longtable_options_->radio_lt_head, enable);
322 setEnabled(longtable_options_->radio_lt_foot, enable);
323 setEnabled(longtable_options_->radio_lt_lastfoot, enable);
324 setEnabled(longtable_options_->radio_lt_newpage, enable);
328 fl_set_button(longtable_options_->radio_lt_firsthead,
329 tabular->GetRowOfLTFirstHead(cell, dummy));
330 fl_set_button(longtable_options_->radio_lt_head,
331 tabular->GetRowOfLTHead(cell, dummy));
332 fl_set_button(longtable_options_->radio_lt_foot,
333 tabular->GetRowOfLTFoot(cell, dummy));
334 fl_set_button(longtable_options_->radio_lt_lastfoot,
335 tabular->GetRowOfLTLastFoot(cell, dummy));
336 fl_set_button(longtable_options_->radio_lt_newpage,
337 tabular->GetLTNewPage(cell));
339 fl_set_button(longtable_options_->radio_lt_firsthead,0);
340 fl_set_button(longtable_options_->radio_lt_head,0);
341 fl_set_button(longtable_options_->radio_lt_foot,0);
342 fl_set_button(longtable_options_->radio_lt_lastfoot,0);
343 fl_set_button(longtable_options_->radio_lt_newpage,0);
345 fl_set_button(tabular_options_->radio_rotate_tabular,
346 tabular->GetRotateTabular());
349 bool FormTabular::input(FL_OBJECT * ob, long)
354 LyXTabular * tabular = inset_->tabular;
356 LyXTabular::Feature num = LyXTabular::LAST_ACTION;
359 int cell = inset_->GetActCell();
360 if (actCell_ != cell) {
362 fl_set_object_label(dialog_->text_warning,
363 _("Warning: Wrong Cursor position, updated window"));
364 fl_show_object(dialog_->text_warning);
367 // No point in processing directives that you can't do anything with
368 // anyhow, so exit now if the buffer is read-only.
369 if (lv_->buffer()->isReadonly()) {
373 if (ob == column_options_->input_column_width) {
374 string str = fl_get_input(ob);
375 if (!str.empty() && !isValidLength(str)) {
376 fl_set_object_label(dialog_->text_warning,
377 _("Warning: Invalid Length (valid example: 10mm)"));
378 fl_show_object(dialog_->text_warning);
381 inset_->TabularFeatures(lv_->view(), LyXTabular::SET_PWIDTH,str);
382 update(); // update for alignment
385 if (ob == cell_options_->input_mcolumn_width) {
386 string str = fl_get_input(ob);
387 if (!str.empty() && !isValidLength(str)) {
388 fl_set_object_label(dialog_->text_warning,
389 _("Warning: Invalid Length (valid example: 10mm)"));
390 fl_show_object(dialog_->text_warning);
393 inset_->TabularFeatures(lv_->view(), LyXTabular::SET_MPWIDTH,str);
394 update(); // update for alignment
397 string str = fl_get_input(column_options_->input_column_width);
398 if (!str.empty() && !isValidLength(str)) {
400 dialog_->text_warning,
401 _("Warning: Invalid Length (valid example: 10mm)"));
402 fl_show_object(dialog_->text_warning);
405 if (ob == tabular_options_->button_append_row)
406 num = LyXTabular::APPEND_ROW;
407 else if (ob == tabular_options_->button_append_column)
408 num = LyXTabular::APPEND_COLUMN;
409 else if (ob == tabular_options_->button_delete_row)
410 num = LyXTabular::DELETE_ROW;
411 else if (ob == tabular_options_->button_delete_column)
412 num = LyXTabular::DELETE_COLUMN;
413 else if (ob == tabular_options_->button_set_borders)
414 num = LyXTabular::SET_ALL_LINES;
415 else if (ob == tabular_options_->button_unset_borders)
416 num = LyXTabular::UNSET_ALL_LINES;
417 else if (ob == column_options_->radio_border_top)
418 num = LyXTabular::TOGGLE_LINE_TOP;
419 else if (ob == column_options_->radio_border_bottom)
420 num = LyXTabular::TOGGLE_LINE_BOTTOM;
421 else if (ob == column_options_->radio_border_left)
422 num = LyXTabular::TOGGLE_LINE_LEFT;
423 else if (ob == column_options_->radio_border_right)
424 num = LyXTabular::TOGGLE_LINE_RIGHT;
425 else if (ob == column_options_->radio_align_left)
426 num = LyXTabular::ALIGN_LEFT;
427 else if (ob == column_options_->radio_align_right)
428 num = LyXTabular::ALIGN_RIGHT;
429 else if (ob == column_options_->radio_align_center)
430 num = LyXTabular::ALIGN_CENTER;
431 else if (ob == column_options_->radio_valign_top)
432 num = LyXTabular::VALIGN_TOP;
433 else if (ob == column_options_->radio_valign_bottom)
434 num = LyXTabular::VALIGN_BOTTOM;
435 else if (ob == column_options_->radio_valign_center)
436 num = LyXTabular::VALIGN_CENTER;
437 else if (ob == cell_options_->radio_multicolumn)
438 num = LyXTabular::MULTICOLUMN;
439 else if (ob == tabular_options_->radio_longtable) {
441 fl_get_button(tabular_options_->radio_longtable);
443 setEnabled(longtable_options_->radio_lt_firsthead, enable);
444 setEnabled(longtable_options_->radio_lt_head, enable);
445 setEnabled(longtable_options_->radio_lt_foot, enable);
446 setEnabled(longtable_options_->radio_lt_lastfoot, enable);
447 setEnabled(longtable_options_->radio_lt_newpage, enable);
450 num = LyXTabular::SET_LONGTABULAR;
452 fl_set_button(longtable_options_->radio_lt_firsthead,
453 tabular->GetRowOfLTFirstHead(cell, dummy));
454 fl_set_button(longtable_options_->radio_lt_head,
455 tabular->GetRowOfLTHead(cell, dummy));
456 fl_set_button(longtable_options_->radio_lt_foot,
457 tabular->GetRowOfLTFoot(cell, dummy));
458 fl_set_button(longtable_options_->radio_lt_lastfoot,
459 tabular->GetRowOfLTLastFoot(cell, dummy));
460 fl_set_button(longtable_options_->radio_lt_firsthead,
461 tabular->GetLTNewPage(cell));
463 num = LyXTabular::UNSET_LONGTABULAR;
464 fl_set_button(longtable_options_->radio_lt_firsthead,0);
465 fl_set_button(longtable_options_->radio_lt_head,0);
466 fl_set_button(longtable_options_->radio_lt_foot,0);
467 fl_set_button(longtable_options_->radio_lt_lastfoot,0);
468 fl_set_button(longtable_options_->radio_lt_newpage,0);
470 } else if (ob == tabular_options_->radio_rotate_tabular) {
471 s = fl_get_button(tabular_options_->radio_rotate_tabular);
473 num = LyXTabular::SET_ROTATE_TABULAR;
475 num = LyXTabular::UNSET_ROTATE_TABULAR;
476 } else if (ob == cell_options_->radio_rotate_cell) {
477 s = fl_get_button(cell_options_->radio_rotate_cell);
479 num = LyXTabular::SET_ROTATE_CELL;
481 num = LyXTabular::UNSET_ROTATE_CELL;
482 } else if (ob == cell_options_->radio_useminipage) {
483 num = LyXTabular::SET_USEBOX;
485 } else if (ob == longtable_options_->radio_lt_firsthead) {
486 num = LyXTabular::SET_LTFIRSTHEAD;
487 } else if (ob == longtable_options_->radio_lt_head) {
488 num = LyXTabular::SET_LTHEAD;
489 } else if (ob == longtable_options_->radio_lt_foot) {
490 num = LyXTabular::SET_LTFOOT;
491 } else if (ob == longtable_options_->radio_lt_lastfoot) {
492 num = LyXTabular::SET_LTLASTFOOT;
493 } else if (ob == longtable_options_->radio_lt_newpage) {
494 num = LyXTabular::SET_LTNEWPAGE;
495 } else if (ob == column_options_->input_special_alignment) {
496 special = fl_get_input(column_options_->input_special_alignment);
497 num = LyXTabular::SET_SPECIAL_COLUMN;
498 } else if (ob == cell_options_->input_special_multialign) {
499 special = fl_get_input(cell_options_->input_special_multialign);
500 num = LyXTabular::SET_SPECIAL_MULTI;
501 } else if (ob == cell_options_->radio_border_top)
502 num = LyXTabular::M_TOGGLE_LINE_TOP;
503 else if (ob == cell_options_->radio_border_bottom)
504 num = LyXTabular::M_TOGGLE_LINE_BOTTOM;
505 else if (ob == cell_options_->radio_border_left)
506 num = LyXTabular::M_TOGGLE_LINE_LEFT;
507 else if (ob == cell_options_->radio_border_right)
508 num = LyXTabular::M_TOGGLE_LINE_RIGHT;
509 else if (ob == cell_options_->radio_align_left)
510 num = LyXTabular::M_ALIGN_LEFT;
511 else if (ob == cell_options_->radio_align_right)
512 num = LyXTabular::M_ALIGN_RIGHT;
513 else if (ob == cell_options_->radio_align_center)
514 num = LyXTabular::M_ALIGN_CENTER;
515 else if (ob == cell_options_->radio_valign_top)
516 num = LyXTabular::M_VALIGN_TOP;
517 else if (ob == cell_options_->radio_valign_bottom)
518 num = LyXTabular::M_VALIGN_BOTTOM;
519 else if (ob == cell_options_->radio_valign_center)
520 num = LyXTabular::M_VALIGN_CENTER;
524 inset_->TabularFeatures(lv_->view(), num, special);