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 // Workaround dumb xforms sizing bug
113 fl_set_input_return(column_options_->input_column_width,
115 fl_set_input_return(column_options_->input_special_alignment,
117 fl_set_input_return(cell_options_->input_mcolumn_width,
119 fl_set_input_return(cell_options_->input_special_multialign,
122 fl_addto_tabfolder(dialog_->tabFolder, _("Tabular"),
123 tabular_options_->form);
124 fl_addto_tabfolder(dialog_->tabFolder, _("Column/Row"),
125 column_options_->form);
126 fl_addto_tabfolder(dialog_->tabFolder, _("Cell"),
127 cell_options_->form);
128 fl_addto_tabfolder(dialog_->tabFolder, _("LongTable"),
129 longtable_options_->form);
133 void FormTabular::update()
135 if (!inset_ || !inset_->tabular)
138 LyXTabular * tabular = inset_->tabular;
147 actCell_ = cell = inset_->GetActCell();
148 int column = tabular->column_of_cell(cell)+1;
149 fl_set_object_label(dialog_->text_warning,"");
150 fl_activate_object(column_options_->input_special_alignment);
151 fl_activate_object(cell_options_->input_special_multialign);
152 fl_activate_object(column_options_->input_column_width);
153 sprintf(buf,"%d",column);
154 fl_set_input(dialog_->input_tabular_column, buf);
155 fl_deactivate_object(dialog_->input_tabular_column);
156 int row = tabular->row_of_cell(cell)+1;
157 sprintf(buf,"%d",row);
158 fl_set_input(dialog_->input_tabular_row, buf);
159 fl_deactivate_object(dialog_->input_tabular_row);
160 if (tabular->IsMultiColumn(cell)) {
161 fl_set_button(cell_options_->radio_multicolumn, 1);
162 fl_set_button(cell_options_->radio_border_top,
163 tabular->TopLine(cell)?1:0);
164 setEnabled(cell_options_->radio_border_top, true);
165 fl_set_button(cell_options_->radio_border_bottom,
166 tabular->BottomLine(cell)?1:0);
167 setEnabled(cell_options_->radio_border_bottom, true);
168 fl_set_button(cell_options_->radio_border_left,
169 tabular->LeftLine(cell)?1:0);
170 setEnabled(cell_options_->radio_border_left, true);
171 fl_set_button(cell_options_->radio_border_right,
172 tabular->RightLine(cell)?1:0);
173 setEnabled(cell_options_->radio_border_right, true);
174 pwidth = tabular->GetMColumnPWidth(cell);
175 align = tabular->GetAlignment(cell);
176 if (!pwidth.empty() || (align == LYX_ALIGN_LEFT))
177 fl_set_button(cell_options_->radio_align_left, 1);
178 else if (align == LYX_ALIGN_RIGHT)
179 fl_set_button(cell_options_->radio_align_right, 1);
181 fl_set_button(cell_options_->radio_align_center, 1);
182 setEnabled(cell_options_->radio_align_left, true);
183 setEnabled(cell_options_->radio_align_right, true);
184 setEnabled(cell_options_->radio_align_center, true);
185 align = tabular->GetVAlignment(cell);
186 fl_set_button(cell_options_->radio_valign_top, 0);
187 fl_set_button(cell_options_->radio_valign_bottom, 0);
188 fl_set_button(cell_options_->radio_valign_center, 0);
189 if (pwidth.empty() || (align == LyXTabular::LYX_VALIGN_CENTER))
190 fl_set_button(cell_options_->radio_valign_center, 1);
191 else if (align == LyXTabular::LYX_VALIGN_BOTTOM)
192 fl_set_button(cell_options_->radio_valign_bottom, 1);
194 fl_set_button(cell_options_->radio_valign_top, 1);
195 setEnabled(cell_options_->radio_valign_top, true);
196 setEnabled(cell_options_->radio_valign_bottom, true);
197 setEnabled(cell_options_->radio_valign_center, true);
198 special = tabular->GetAlignSpecial(cell,LyXTabular::SET_SPECIAL_MULTI);
199 fl_set_input(cell_options_->input_special_multialign, special.c_str());
200 fl_set_input(cell_options_->input_mcolumn_width,pwidth.c_str());
201 if (!lv_->buffer()->isReadonly()) {
202 setEnabled(cell_options_->input_special_multialign, true);
203 setEnabled(cell_options_->input_mcolumn_width, true);
206 setEnabled(cell_options_->radio_valign_top, !pwidth.empty());
207 setEnabled(cell_options_->radio_valign_bottom, !pwidth.empty());
208 setEnabled(cell_options_->radio_valign_center, !pwidth.empty());
210 setEnabled(cell_options_->radio_align_left, pwidth.empty());
211 setEnabled(cell_options_->radio_align_right, pwidth.empty());
212 setEnabled(cell_options_->radio_align_center, pwidth.empty());
214 fl_set_button(cell_options_->radio_multicolumn, 0);
216 fl_set_button(cell_options_->radio_border_top, 0);
217 setEnabled(cell_options_->radio_border_top, false);
219 fl_set_button(cell_options_->radio_border_bottom, 0);
220 setEnabled(cell_options_->radio_border_bottom, false);
222 fl_set_button(cell_options_->radio_border_left, 0);
223 setEnabled(cell_options_->radio_border_left, false);
225 fl_set_button(cell_options_->radio_border_right, 0);
226 setEnabled(cell_options_->radio_border_right, false);
228 fl_set_button(cell_options_->radio_align_left, 0);
229 setEnabled(cell_options_->radio_align_left, false);
231 fl_set_button(cell_options_->radio_align_right, 0);
232 setEnabled(cell_options_->radio_align_right, false);
234 fl_set_button(cell_options_->radio_align_center, 0);
235 setEnabled(cell_options_->radio_align_center, false);
237 fl_set_button(cell_options_->radio_valign_top, 0);
238 setEnabled(cell_options_->radio_valign_top, false);
240 fl_set_button(cell_options_->radio_valign_bottom, 0);
241 setEnabled(cell_options_->radio_valign_bottom, false);
243 fl_set_button(cell_options_->radio_valign_center, 0);
244 setEnabled(cell_options_->radio_valign_center, false);
246 fl_set_input(cell_options_->input_special_multialign, "");
247 setEnabled(cell_options_->input_special_multialign, false);
249 fl_set_input(cell_options_->input_mcolumn_width, "");
250 setEnabled(cell_options_->input_mcolumn_width, false);
252 if (tabular->GetRotateCell(cell))
253 fl_set_button(cell_options_->radio_rotate_cell, 1);
255 fl_set_button(cell_options_->radio_rotate_cell, 0);
256 if (tabular->TopLine(cell, true))
257 fl_set_button(column_options_->radio_border_top, 1);
259 fl_set_button(column_options_->radio_border_top, 0);
260 if (tabular->BottomLine(cell, true))
261 fl_set_button(column_options_->radio_border_bottom, 1);
263 fl_set_button(column_options_->radio_border_bottom, 0);
264 if (tabular->LeftLine(cell, true))
265 fl_set_button(column_options_->radio_border_left, 1);
267 fl_set_button(column_options_->radio_border_left, 0);
268 if (tabular->RightLine(cell, true))
269 fl_set_button(column_options_->radio_border_right, 1);
271 fl_set_button(column_options_->radio_border_right, 0);
272 special = tabular->GetAlignSpecial(cell,LyXTabular::SET_SPECIAL_COLUMN);
273 fl_set_input(column_options_->input_special_alignment, special.c_str());
275 bool const isReadonly = lv_->buffer()->isReadonly();
276 setEnabled(column_options_->input_special_alignment, !isReadonly);
278 pwidth = tabular->GetColumnPWidth(cell);
279 fl_set_input(column_options_->input_column_width,pwidth.c_str());
280 setEnabled(column_options_->input_column_width, !isReadonly);
282 setEnabled(cell_options_->radio_useminipage, !pwidth.empty());
283 if (!pwidth.empty()) {
284 if (tabular->GetUsebox(cell) == 2)
285 fl_set_button(cell_options_->radio_useminipage, 1);
287 fl_set_button(cell_options_->radio_useminipage, 0);
289 fl_set_button(cell_options_->radio_useminipage,0);
291 align = tabular->GetAlignment(cell, true);
292 fl_set_button(column_options_->radio_align_left, 0);
293 fl_set_button(column_options_->radio_align_right, 0);
294 fl_set_button(column_options_->radio_align_center, 0);
295 if (!pwidth.empty() || (align == LYX_ALIGN_LEFT))
296 fl_set_button(column_options_->radio_align_left, 1);
297 else if (align == LYX_ALIGN_RIGHT)
298 fl_set_button(column_options_->radio_align_right, 1);
300 fl_set_button(column_options_->radio_align_center, 1);
301 align = tabular->GetVAlignment(cell, true);
302 fl_set_button(column_options_->radio_valign_top, 0);
303 fl_set_button(column_options_->radio_valign_bottom, 0);
304 fl_set_button(column_options_->radio_valign_center, 0);
305 if (pwidth.empty() || (align == LyXTabular::LYX_VALIGN_CENTER))
306 fl_set_button(column_options_->radio_valign_center, 1);
307 else if (align == LyXTabular::LYX_VALIGN_BOTTOM)
308 fl_set_button(column_options_->radio_valign_bottom, 1);
310 fl_set_button(column_options_->radio_valign_top, 1);
312 setEnabled(column_options_->radio_align_left, pwidth.empty());
313 setEnabled(column_options_->radio_align_right, pwidth.empty());
314 setEnabled(column_options_->radio_align_center, pwidth.empty());
316 setEnabled(column_options_->radio_valign_top, !pwidth.empty());
317 setEnabled(column_options_->radio_valign_bottom, !pwidth.empty());
318 setEnabled(column_options_->radio_valign_center, !pwidth.empty());
320 fl_set_button(tabular_options_->radio_longtable,
321 tabular->IsLongTabular());
323 bool const enable = tabular->IsLongTabular();
324 setEnabled(longtable_options_->radio_lt_firsthead, enable);
325 setEnabled(longtable_options_->radio_lt_head, enable);
326 setEnabled(longtable_options_->radio_lt_foot, enable);
327 setEnabled(longtable_options_->radio_lt_lastfoot, enable);
328 setEnabled(longtable_options_->radio_lt_newpage, enable);
332 fl_set_button(longtable_options_->radio_lt_firsthead,
333 tabular->GetRowOfLTFirstHead(cell, dummy));
334 fl_set_button(longtable_options_->radio_lt_head,
335 tabular->GetRowOfLTHead(cell, dummy));
336 fl_set_button(longtable_options_->radio_lt_foot,
337 tabular->GetRowOfLTFoot(cell, dummy));
338 fl_set_button(longtable_options_->radio_lt_lastfoot,
339 tabular->GetRowOfLTLastFoot(cell, dummy));
340 fl_set_button(longtable_options_->radio_lt_newpage,
341 tabular->GetLTNewPage(cell));
343 fl_set_button(longtable_options_->radio_lt_firsthead,0);
344 fl_set_button(longtable_options_->radio_lt_head,0);
345 fl_set_button(longtable_options_->radio_lt_foot,0);
346 fl_set_button(longtable_options_->radio_lt_lastfoot,0);
347 fl_set_button(longtable_options_->radio_lt_newpage,0);
349 fl_set_button(tabular_options_->radio_rotate_tabular,
350 tabular->GetRotateTabular());
353 bool FormTabular::input(FL_OBJECT * ob, long)
358 LyXTabular * tabular = inset_->tabular;
360 LyXTabular::Feature num = LyXTabular::LAST_ACTION;
363 int cell = inset_->GetActCell();
364 if (actCell_ != cell) {
366 fl_set_object_label(dialog_->text_warning,
367 _("Warning: Wrong Cursor position, updated window"));
368 fl_show_object(dialog_->text_warning);
371 // No point in processing directives that you can't do anything with
372 // anyhow, so exit now if the buffer is read-only.
373 if (lv_->buffer()->isReadonly()) {
377 if (ob == column_options_->input_column_width) {
378 string str = fl_get_input(ob);
379 if (!str.empty() && !isValidLength(str)) {
380 fl_set_object_label(dialog_->text_warning,
381 _("Warning: Invalid Length (valid example: 10mm)"));
382 fl_show_object(dialog_->text_warning);
385 inset_->TabularFeatures(lv_->view(), LyXTabular::SET_PWIDTH,str);
386 update(); // update for alignment
389 if (ob == cell_options_->input_mcolumn_width) {
390 string str = fl_get_input(ob);
391 if (!str.empty() && !isValidLength(str)) {
392 fl_set_object_label(dialog_->text_warning,
393 _("Warning: Invalid Length (valid example: 10mm)"));
394 fl_show_object(dialog_->text_warning);
397 inset_->TabularFeatures(lv_->view(), LyXTabular::SET_MPWIDTH,str);
398 update(); // update for alignment
401 string str = fl_get_input(column_options_->input_column_width);
402 if (!str.empty() && !isValidLength(str)) {
404 dialog_->text_warning,
405 _("Warning: Invalid Length (valid example: 10mm)"));
406 fl_show_object(dialog_->text_warning);
409 if (ob == tabular_options_->button_append_row)
410 num = LyXTabular::APPEND_ROW;
411 else if (ob == tabular_options_->button_append_column)
412 num = LyXTabular::APPEND_COLUMN;
413 else if (ob == tabular_options_->button_delete_row)
414 num = LyXTabular::DELETE_ROW;
415 else if (ob == tabular_options_->button_delete_column)
416 num = LyXTabular::DELETE_COLUMN;
417 else if (ob == tabular_options_->button_set_borders)
418 num = LyXTabular::SET_ALL_LINES;
419 else if (ob == tabular_options_->button_unset_borders)
420 num = LyXTabular::UNSET_ALL_LINES;
421 else if (ob == column_options_->radio_border_top)
422 num = LyXTabular::TOGGLE_LINE_TOP;
423 else if (ob == column_options_->radio_border_bottom)
424 num = LyXTabular::TOGGLE_LINE_BOTTOM;
425 else if (ob == column_options_->radio_border_left)
426 num = LyXTabular::TOGGLE_LINE_LEFT;
427 else if (ob == column_options_->radio_border_right)
428 num = LyXTabular::TOGGLE_LINE_RIGHT;
429 else if (ob == column_options_->radio_align_left)
430 num = LyXTabular::ALIGN_LEFT;
431 else if (ob == column_options_->radio_align_right)
432 num = LyXTabular::ALIGN_RIGHT;
433 else if (ob == column_options_->radio_align_center)
434 num = LyXTabular::ALIGN_CENTER;
435 else if (ob == column_options_->radio_valign_top)
436 num = LyXTabular::VALIGN_TOP;
437 else if (ob == column_options_->radio_valign_bottom)
438 num = LyXTabular::VALIGN_BOTTOM;
439 else if (ob == column_options_->radio_valign_center)
440 num = LyXTabular::VALIGN_CENTER;
441 else if (ob == cell_options_->radio_multicolumn)
442 num = LyXTabular::MULTICOLUMN;
443 else if (ob == tabular_options_->radio_longtable) {
445 fl_get_button(tabular_options_->radio_longtable);
447 setEnabled(longtable_options_->radio_lt_firsthead, enable);
448 setEnabled(longtable_options_->radio_lt_head, enable);
449 setEnabled(longtable_options_->radio_lt_foot, enable);
450 setEnabled(longtable_options_->radio_lt_lastfoot, enable);
451 setEnabled(longtable_options_->radio_lt_newpage, enable);
454 num = LyXTabular::SET_LONGTABULAR;
456 fl_set_button(longtable_options_->radio_lt_firsthead,
457 tabular->GetRowOfLTFirstHead(cell, dummy));
458 fl_set_button(longtable_options_->radio_lt_head,
459 tabular->GetRowOfLTHead(cell, dummy));
460 fl_set_button(longtable_options_->radio_lt_foot,
461 tabular->GetRowOfLTFoot(cell, dummy));
462 fl_set_button(longtable_options_->radio_lt_lastfoot,
463 tabular->GetRowOfLTLastFoot(cell, dummy));
464 fl_set_button(longtable_options_->radio_lt_firsthead,
465 tabular->GetLTNewPage(cell));
467 num = LyXTabular::UNSET_LONGTABULAR;
468 fl_set_button(longtable_options_->radio_lt_firsthead,0);
469 fl_set_button(longtable_options_->radio_lt_head,0);
470 fl_set_button(longtable_options_->radio_lt_foot,0);
471 fl_set_button(longtable_options_->radio_lt_lastfoot,0);
472 fl_set_button(longtable_options_->radio_lt_newpage,0);
474 } else if (ob == tabular_options_->radio_rotate_tabular) {
475 s = fl_get_button(tabular_options_->radio_rotate_tabular);
477 num = LyXTabular::SET_ROTATE_TABULAR;
479 num = LyXTabular::UNSET_ROTATE_TABULAR;
480 } else if (ob == cell_options_->radio_rotate_cell) {
481 s = fl_get_button(cell_options_->radio_rotate_cell);
483 num = LyXTabular::SET_ROTATE_CELL;
485 num = LyXTabular::UNSET_ROTATE_CELL;
486 } else if (ob == cell_options_->radio_useminipage) {
487 num = LyXTabular::SET_USEBOX;
489 } else if (ob == longtable_options_->radio_lt_firsthead) {
490 num = LyXTabular::SET_LTFIRSTHEAD;
491 } else if (ob == longtable_options_->radio_lt_head) {
492 num = LyXTabular::SET_LTHEAD;
493 } else if (ob == longtable_options_->radio_lt_foot) {
494 num = LyXTabular::SET_LTFOOT;
495 } else if (ob == longtable_options_->radio_lt_lastfoot) {
496 num = LyXTabular::SET_LTLASTFOOT;
497 } else if (ob == longtable_options_->radio_lt_newpage) {
498 num = LyXTabular::SET_LTNEWPAGE;
499 } else if (ob == column_options_->input_special_alignment) {
500 special = fl_get_input(column_options_->input_special_alignment);
501 num = LyXTabular::SET_SPECIAL_COLUMN;
502 } else if (ob == cell_options_->input_special_multialign) {
503 special = fl_get_input(cell_options_->input_special_multialign);
504 num = LyXTabular::SET_SPECIAL_MULTI;
505 } else if (ob == cell_options_->radio_border_top)
506 num = LyXTabular::M_TOGGLE_LINE_TOP;
507 else if (ob == cell_options_->radio_border_bottom)
508 num = LyXTabular::M_TOGGLE_LINE_BOTTOM;
509 else if (ob == cell_options_->radio_border_left)
510 num = LyXTabular::M_TOGGLE_LINE_LEFT;
511 else if (ob == cell_options_->radio_border_right)
512 num = LyXTabular::M_TOGGLE_LINE_RIGHT;
513 else if (ob == cell_options_->radio_align_left)
514 num = LyXTabular::M_ALIGN_LEFT;
515 else if (ob == cell_options_->radio_align_right)
516 num = LyXTabular::M_ALIGN_RIGHT;
517 else if (ob == cell_options_->radio_align_center)
518 num = LyXTabular::M_ALIGN_CENTER;
519 else if (ob == cell_options_->radio_valign_top)
520 num = LyXTabular::M_VALIGN_TOP;
521 else if (ob == cell_options_->radio_valign_bottom)
522 num = LyXTabular::M_VALIGN_BOTTOM;
523 else if (ob == cell_options_->radio_valign_center)
524 num = LyXTabular::M_VALIGN_CENTER;
528 inset_->TabularFeatures(lv_->view(), num, special);