2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-2001 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.get())
134 LyXTabular * tabular = inset_->tabular.get();
140 int cell = inset_->GetActCell();
142 int column = tabular->column_of_cell(cell)+1;
143 fl_set_object_label(dialog_->text_warning,"");
144 fl_activate_object(column_options_->input_special_alignment);
145 fl_activate_object(cell_options_->input_special_multialign);
146 fl_activate_object(column_options_->input_column_width);
147 sprintf(buf,"%d",column);
148 fl_set_input(dialog_->input_tabular_column, buf);
149 fl_deactivate_object(dialog_->input_tabular_column);
150 int row = tabular->row_of_cell(cell)+1;
151 sprintf(buf,"%d",row);
152 fl_set_input(dialog_->input_tabular_row, buf);
153 fl_deactivate_object(dialog_->input_tabular_row);
154 if (tabular->IsMultiColumn(cell)) {
155 fl_set_button(cell_options_->radio_multicolumn, 1);
156 fl_set_button(cell_options_->radio_border_top,
157 tabular->TopLine(cell)?1:0);
158 setEnabled(cell_options_->radio_border_top, true);
159 fl_set_button(cell_options_->radio_border_bottom,
160 tabular->BottomLine(cell)?1:0);
161 setEnabled(cell_options_->radio_border_bottom, true);
162 fl_set_button(cell_options_->radio_border_left,
163 tabular->LeftLine(cell)?1:0);
164 setEnabled(cell_options_->radio_border_left, true);
165 fl_set_button(cell_options_->radio_border_right,
166 tabular->RightLine(cell)?1:0);
167 setEnabled(cell_options_->radio_border_right, true);
168 pwidth = tabular->GetMColumnPWidth(cell);
169 align = tabular->GetAlignment(cell);
170 if (!pwidth.empty() || (align == LYX_ALIGN_LEFT))
171 fl_set_button(cell_options_->radio_align_left, 1);
172 else if (align == LYX_ALIGN_RIGHT)
173 fl_set_button(cell_options_->radio_align_right, 1);
175 fl_set_button(cell_options_->radio_align_center, 1);
176 setEnabled(cell_options_->radio_align_left, true);
177 setEnabled(cell_options_->radio_align_right, true);
178 setEnabled(cell_options_->radio_align_center, true);
179 align = tabular->GetVAlignment(cell);
180 fl_set_button(cell_options_->radio_valign_top, 0);
181 fl_set_button(cell_options_->radio_valign_bottom, 0);
182 fl_set_button(cell_options_->radio_valign_center, 0);
183 if (pwidth.empty() || (align == LyXTabular::LYX_VALIGN_CENTER))
184 fl_set_button(cell_options_->radio_valign_center, 1);
185 else if (align == LyXTabular::LYX_VALIGN_BOTTOM)
186 fl_set_button(cell_options_->radio_valign_bottom, 1);
188 fl_set_button(cell_options_->radio_valign_top, 1);
189 setEnabled(cell_options_->radio_valign_top, true);
190 setEnabled(cell_options_->radio_valign_bottom, true);
191 setEnabled(cell_options_->radio_valign_center, true);
192 special = tabular->GetAlignSpecial(cell,LyXTabular::SET_SPECIAL_MULTI);
193 fl_set_input(cell_options_->input_special_multialign, special.c_str());
194 fl_set_input(cell_options_->input_mcolumn_width,pwidth.c_str());
195 if (!lv_->buffer()->isReadonly()) {
196 setEnabled(cell_options_->input_special_multialign, true);
197 setEnabled(cell_options_->input_mcolumn_width, true);
200 setEnabled(cell_options_->radio_valign_top, !pwidth.empty());
201 setEnabled(cell_options_->radio_valign_bottom, !pwidth.empty());
202 setEnabled(cell_options_->radio_valign_center, !pwidth.empty());
204 setEnabled(cell_options_->radio_align_left, pwidth.empty());
205 setEnabled(cell_options_->radio_align_right, pwidth.empty());
206 setEnabled(cell_options_->radio_align_center, pwidth.empty());
208 fl_set_button(cell_options_->radio_multicolumn, 0);
210 fl_set_button(cell_options_->radio_border_top, 0);
211 setEnabled(cell_options_->radio_border_top, false);
213 fl_set_button(cell_options_->radio_border_bottom, 0);
214 setEnabled(cell_options_->radio_border_bottom, false);
216 fl_set_button(cell_options_->radio_border_left, 0);
217 setEnabled(cell_options_->radio_border_left, false);
219 fl_set_button(cell_options_->radio_border_right, 0);
220 setEnabled(cell_options_->radio_border_right, false);
222 fl_set_button(cell_options_->radio_align_left, 0);
223 setEnabled(cell_options_->radio_align_left, false);
225 fl_set_button(cell_options_->radio_align_right, 0);
226 setEnabled(cell_options_->radio_align_right, false);
228 fl_set_button(cell_options_->radio_align_center, 0);
229 setEnabled(cell_options_->radio_align_center, false);
231 fl_set_button(cell_options_->radio_valign_top, 0);
232 setEnabled(cell_options_->radio_valign_top, false);
234 fl_set_button(cell_options_->radio_valign_bottom, 0);
235 setEnabled(cell_options_->radio_valign_bottom, false);
237 fl_set_button(cell_options_->radio_valign_center, 0);
238 setEnabled(cell_options_->radio_valign_center, false);
240 fl_set_input(cell_options_->input_special_multialign, "");
241 setEnabled(cell_options_->input_special_multialign, false);
243 fl_set_input(cell_options_->input_mcolumn_width, "");
244 setEnabled(cell_options_->input_mcolumn_width, false);
246 if (tabular->GetRotateCell(cell))
247 fl_set_button(cell_options_->radio_rotate_cell, 1);
249 fl_set_button(cell_options_->radio_rotate_cell, 0);
250 if (tabular->TopLine(cell, true))
251 fl_set_button(column_options_->radio_border_top, 1);
253 fl_set_button(column_options_->radio_border_top, 0);
254 if (tabular->BottomLine(cell, true))
255 fl_set_button(column_options_->radio_border_bottom, 1);
257 fl_set_button(column_options_->radio_border_bottom, 0);
258 if (tabular->LeftLine(cell, true))
259 fl_set_button(column_options_->radio_border_left, 1);
261 fl_set_button(column_options_->radio_border_left, 0);
262 if (tabular->RightLine(cell, true))
263 fl_set_button(column_options_->radio_border_right, 1);
265 fl_set_button(column_options_->radio_border_right, 0);
266 special = tabular->GetAlignSpecial(cell,LyXTabular::SET_SPECIAL_COLUMN);
267 fl_set_input(column_options_->input_special_alignment, special.c_str());
269 bool const isReadonly = lv_->buffer()->isReadonly();
270 setEnabled(column_options_->input_special_alignment, !isReadonly);
272 pwidth = tabular->GetColumnPWidth(cell);
273 fl_set_input(column_options_->input_column_width,pwidth.c_str());
274 setEnabled(column_options_->input_column_width, !isReadonly);
276 setEnabled(cell_options_->radio_useminipage, !pwidth.empty());
277 if (!pwidth.empty()) {
278 if (tabular->GetUsebox(cell) == 2)
279 fl_set_button(cell_options_->radio_useminipage, 1);
281 fl_set_button(cell_options_->radio_useminipage, 0);
283 fl_set_button(cell_options_->radio_useminipage,0);
285 align = tabular->GetAlignment(cell, true);
286 fl_set_button(column_options_->radio_align_left, 0);
287 fl_set_button(column_options_->radio_align_right, 0);
288 fl_set_button(column_options_->radio_align_center, 0);
289 if (!pwidth.empty() || (align == LYX_ALIGN_LEFT))
290 fl_set_button(column_options_->radio_align_left, 1);
291 else if (align == LYX_ALIGN_RIGHT)
292 fl_set_button(column_options_->radio_align_right, 1);
294 fl_set_button(column_options_->radio_align_center, 1);
295 align = tabular->GetVAlignment(cell, true);
296 fl_set_button(column_options_->radio_valign_top, 0);
297 fl_set_button(column_options_->radio_valign_bottom, 0);
298 fl_set_button(column_options_->radio_valign_center, 0);
299 if (pwidth.empty() || (align == LyXTabular::LYX_VALIGN_CENTER))
300 fl_set_button(column_options_->radio_valign_center, 1);
301 else if (align == LyXTabular::LYX_VALIGN_BOTTOM)
302 fl_set_button(column_options_->radio_valign_bottom, 1);
304 fl_set_button(column_options_->radio_valign_top, 1);
306 setEnabled(column_options_->radio_align_left, pwidth.empty());
307 setEnabled(column_options_->radio_align_right, pwidth.empty());
308 setEnabled(column_options_->radio_align_center, pwidth.empty());
310 setEnabled(column_options_->radio_valign_top, !pwidth.empty());
311 setEnabled(column_options_->radio_valign_bottom, !pwidth.empty());
312 setEnabled(column_options_->radio_valign_center, !pwidth.empty());
314 fl_set_button(tabular_options_->radio_longtable,
315 tabular->IsLongTabular());
317 bool const enable = tabular->IsLongTabular();
318 setEnabled(longtable_options_->radio_lt_firsthead, enable);
319 setEnabled(longtable_options_->radio_lt_head, enable);
320 setEnabled(longtable_options_->radio_lt_foot, enable);
321 setEnabled(longtable_options_->radio_lt_lastfoot, enable);
322 setEnabled(longtable_options_->radio_lt_newpage, enable);
326 fl_set_button(longtable_options_->radio_lt_firsthead,
327 tabular->GetRowOfLTFirstHead(cell, dummy));
328 fl_set_button(longtable_options_->radio_lt_head,
329 tabular->GetRowOfLTHead(cell, dummy));
330 fl_set_button(longtable_options_->radio_lt_foot,
331 tabular->GetRowOfLTFoot(cell, dummy));
332 fl_set_button(longtable_options_->radio_lt_lastfoot,
333 tabular->GetRowOfLTLastFoot(cell, dummy));
334 fl_set_button(longtable_options_->radio_lt_newpage,
335 tabular->GetLTNewPage(cell));
337 fl_set_button(longtable_options_->radio_lt_firsthead,0);
338 fl_set_button(longtable_options_->radio_lt_head,0);
339 fl_set_button(longtable_options_->radio_lt_foot,0);
340 fl_set_button(longtable_options_->radio_lt_lastfoot,0);
341 fl_set_button(longtable_options_->radio_lt_newpage,0);
343 fl_set_button(tabular_options_->radio_rotate_tabular,
344 tabular->GetRotateTabular());
348 bool FormTabular::input(FL_OBJECT * ob, long)
353 LyXTabular * tabular = inset_->tabular.get();
355 LyXTabular::Feature num = LyXTabular::LAST_ACTION;
358 int cell = inset_->GetActCell();
359 if (actCell_ != cell) {
361 fl_set_object_label(dialog_->text_warning,
362 _("Warning: Wrong Cursor position, updated window"));
363 fl_show_object(dialog_->text_warning);
366 // No point in processing directives that you can't do anything with
367 // anyhow, so exit now if the buffer is read-only.
368 if (lv_->buffer()->isReadonly()) {
372 if (ob == column_options_->input_column_width) {
373 string const str = fl_get_input(ob);
374 if (!str.empty() && !isValidLength(str)) {
375 fl_set_object_label(dialog_->text_warning,
376 _("Warning: Invalid Length (valid example: 10mm)"));
377 fl_show_object(dialog_->text_warning);
380 inset_->TabularFeatures(lv_->view(), LyXTabular::SET_PWIDTH,str);
381 update(); // update for alignment
384 if (ob == cell_options_->input_mcolumn_width) {
385 string const str = fl_get_input(ob);
386 if (!str.empty() && !isValidLength(str)) {
387 fl_set_object_label(dialog_->text_warning,
388 _("Warning: Invalid Length (valid example: 10mm)"));
389 fl_show_object(dialog_->text_warning);
392 inset_->TabularFeatures(lv_->view(), LyXTabular::SET_MPWIDTH,str);
393 update(); // update for alignment
396 string const str = fl_get_input(column_options_->input_column_width);
397 if (!str.empty() && !isValidLength(str)) {
399 dialog_->text_warning,
400 _("Warning: Invalid Length (valid example: 10mm)"));
401 fl_show_object(dialog_->text_warning);
404 if (ob == tabular_options_->button_append_row)
405 num = LyXTabular::APPEND_ROW;
406 else if (ob == tabular_options_->button_append_column)
407 num = LyXTabular::APPEND_COLUMN;
408 else if (ob == tabular_options_->button_delete_row)
409 num = LyXTabular::DELETE_ROW;
410 else if (ob == tabular_options_->button_delete_column)
411 num = LyXTabular::DELETE_COLUMN;
412 else if (ob == tabular_options_->button_set_borders)
413 num = LyXTabular::SET_ALL_LINES;
414 else if (ob == tabular_options_->button_unset_borders)
415 num = LyXTabular::UNSET_ALL_LINES;
416 else if (ob == column_options_->radio_border_top)
417 num = LyXTabular::TOGGLE_LINE_TOP;
418 else if (ob == column_options_->radio_border_bottom)
419 num = LyXTabular::TOGGLE_LINE_BOTTOM;
420 else if (ob == column_options_->radio_border_left)
421 num = LyXTabular::TOGGLE_LINE_LEFT;
422 else if (ob == column_options_->radio_border_right)
423 num = LyXTabular::TOGGLE_LINE_RIGHT;
424 else if (ob == column_options_->radio_align_left)
425 num = LyXTabular::ALIGN_LEFT;
426 else if (ob == column_options_->radio_align_right)
427 num = LyXTabular::ALIGN_RIGHT;
428 else if (ob == column_options_->radio_align_center)
429 num = LyXTabular::ALIGN_CENTER;
430 else if (ob == column_options_->radio_valign_top)
431 num = LyXTabular::VALIGN_TOP;
432 else if (ob == column_options_->radio_valign_bottom)
433 num = LyXTabular::VALIGN_BOTTOM;
434 else if (ob == column_options_->radio_valign_center)
435 num = LyXTabular::VALIGN_CENTER;
436 else if (ob == cell_options_->radio_multicolumn)
437 num = LyXTabular::MULTICOLUMN;
438 else if (ob == tabular_options_->radio_longtable) {
440 fl_get_button(tabular_options_->radio_longtable);
442 setEnabled(longtable_options_->radio_lt_firsthead, enable);
443 setEnabled(longtable_options_->radio_lt_head, enable);
444 setEnabled(longtable_options_->radio_lt_foot, enable);
445 setEnabled(longtable_options_->radio_lt_lastfoot, enable);
446 setEnabled(longtable_options_->radio_lt_newpage, enable);
449 num = LyXTabular::SET_LONGTABULAR;
451 fl_set_button(longtable_options_->radio_lt_firsthead,
452 tabular->GetRowOfLTFirstHead(cell, dummy));
453 fl_set_button(longtable_options_->radio_lt_head,
454 tabular->GetRowOfLTHead(cell, dummy));
455 fl_set_button(longtable_options_->radio_lt_foot,
456 tabular->GetRowOfLTFoot(cell, dummy));
457 fl_set_button(longtable_options_->radio_lt_lastfoot,
458 tabular->GetRowOfLTLastFoot(cell, dummy));
459 fl_set_button(longtable_options_->radio_lt_firsthead,
460 tabular->GetLTNewPage(cell));
462 num = LyXTabular::UNSET_LONGTABULAR;
463 fl_set_button(longtable_options_->radio_lt_firsthead,0);
464 fl_set_button(longtable_options_->radio_lt_head,0);
465 fl_set_button(longtable_options_->radio_lt_foot,0);
466 fl_set_button(longtable_options_->radio_lt_lastfoot,0);
467 fl_set_button(longtable_options_->radio_lt_newpage,0);
469 } else if (ob == tabular_options_->radio_rotate_tabular) {
470 s = fl_get_button(tabular_options_->radio_rotate_tabular);
472 num = LyXTabular::SET_ROTATE_TABULAR;
474 num = LyXTabular::UNSET_ROTATE_TABULAR;
475 } else if (ob == cell_options_->radio_rotate_cell) {
476 s = fl_get_button(cell_options_->radio_rotate_cell);
478 num = LyXTabular::SET_ROTATE_CELL;
480 num = LyXTabular::UNSET_ROTATE_CELL;
481 } else if (ob == cell_options_->radio_useminipage) {
482 num = LyXTabular::SET_USEBOX;
484 } else if (ob == longtable_options_->radio_lt_firsthead) {
485 num = LyXTabular::SET_LTFIRSTHEAD;
486 } else if (ob == longtable_options_->radio_lt_head) {
487 num = LyXTabular::SET_LTHEAD;
488 } else if (ob == longtable_options_->radio_lt_foot) {
489 num = LyXTabular::SET_LTFOOT;
490 } else if (ob == longtable_options_->radio_lt_lastfoot) {
491 num = LyXTabular::SET_LTLASTFOOT;
492 } else if (ob == longtable_options_->radio_lt_newpage) {
493 num = LyXTabular::SET_LTNEWPAGE;
494 } else if (ob == column_options_->input_special_alignment) {
495 special = fl_get_input(column_options_->input_special_alignment);
496 num = LyXTabular::SET_SPECIAL_COLUMN;
497 } else if (ob == cell_options_->input_special_multialign) {
498 special = fl_get_input(cell_options_->input_special_multialign);
499 num = LyXTabular::SET_SPECIAL_MULTI;
500 } else if (ob == cell_options_->radio_border_top)
501 num = LyXTabular::M_TOGGLE_LINE_TOP;
502 else if (ob == cell_options_->radio_border_bottom)
503 num = LyXTabular::M_TOGGLE_LINE_BOTTOM;
504 else if (ob == cell_options_->radio_border_left)
505 num = LyXTabular::M_TOGGLE_LINE_LEFT;
506 else if (ob == cell_options_->radio_border_right)
507 num = LyXTabular::M_TOGGLE_LINE_RIGHT;
508 else if (ob == cell_options_->radio_align_left)
509 num = LyXTabular::M_ALIGN_LEFT;
510 else if (ob == cell_options_->radio_align_right)
511 num = LyXTabular::M_ALIGN_RIGHT;
512 else if (ob == cell_options_->radio_align_center)
513 num = LyXTabular::M_ALIGN_CENTER;
514 else if (ob == cell_options_->radio_valign_top)
515 num = LyXTabular::M_VALIGN_TOP;
516 else if (ob == cell_options_->radio_valign_bottom)
517 num = LyXTabular::M_VALIGN_BOTTOM;
518 else if (ob == cell_options_->radio_valign_center)
519 num = LyXTabular::M_VALIGN_CENTER;
523 inset_->TabularFeatures(lv_->view(), num, special);