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::apply()
150 void FormTabular::update()
157 void FormTabular::updateInset(InsetTabular * ti)
160 if (ti && dialog_ && dialog_->form_tabular->visible) {
165 void FormTabular::input()
167 bool activate = true;
169 // whatever checks you need
177 void FormTabular::free()
179 // we don't need to delete u and h here because
180 // hide() does that after disconnecting.
182 if (dialog_->form_tabular
183 && dialog_->form_tabular->visible) {
186 fl_free_form(dialog_->form_tabular);
193 int FormTabular::WMHideCB(FL_FORM * form, void *)
195 // Ensure that the signals (u and h) are disconnected even if the
196 // window manager is used to close the dialog.
197 FormTabular * pre = static_cast<FormTabular*>(form->u_vdata);
203 void FormTabular::CloseCB(FL_OBJECT * ob, long)
205 FormTabular * pre = static_cast<FormTabular*>(ob->form->u_vdata);
210 void FormTabular::InputCB(FL_OBJECT * ob, long)
212 FormTabular * pre = static_cast<FormTabular*>(ob->form->u_vdata);
217 bool FormTabular::local_update(bool flag)
219 if (!inset_ || !inset_->tabular)
223 * tabular = inset_->tabular;
233 actCell_ = cell = inset_->GetActCell();
234 column = tabular->column_of_cell(cell)+1;
235 fl_set_object_label(dialog_->text_warning,"");
237 fl_activate_object(column_options_->input_special_alignment);
238 fl_activate_object(cell_options_->input_special_multialign);
239 fl_activate_object(column_options_->input_column_width);
240 sprintf(buf,"%d",column);
241 fl_set_input(dialog_->input_tabular_column, buf);
242 fl_deactivate_object(dialog_->input_tabular_column);
243 row = tabular->row_of_cell(cell)+1;
244 sprintf(buf,"%d",row);
245 fl_set_input(dialog_->input_tabular_row, buf);
246 fl_deactivate_object(dialog_->input_tabular_row);
247 if (tabular->IsMultiColumn(cell))
248 fl_set_button(cell_options_->radio_multicolumn, 1);
250 fl_set_button(cell_options_->radio_multicolumn, 0);
251 if (tabular->GetRotateCell(cell))
252 fl_set_button(cell_options_->radio_rotate_cell, 1);
254 fl_set_button(cell_options_->radio_rotate_cell, 0);
255 if (tabular->TopLine(cell))
256 fl_set_button(column_options_->radio_border_top, 1);
258 fl_set_button(column_options_->radio_border_top, 0);
259 if (tabular->BottomLine(cell))
260 fl_set_button(column_options_->radio_border_bottom, 1);
262 fl_set_button(column_options_->radio_border_bottom, 0);
263 if (tabular->LeftLine(cell))
264 fl_set_button(column_options_->radio_border_left, 1);
266 fl_set_button(column_options_->radio_border_left, 0);
267 if (tabular->RightLine(cell))
268 fl_set_button(column_options_->radio_border_right, 1);
270 fl_set_button(column_options_->radio_border_right, 0);
271 align = tabular->GetAlignment(cell);
272 fl_set_button(column_options_->radio_align_left, 0);
273 fl_set_button(column_options_->radio_align_right, 0);
274 fl_set_button(column_options_->radio_align_center, 0);
275 special = tabular->GetAlignSpecial(cell,LyXTabular::SET_SPECIAL_COLUMN);
277 fl_set_input(column_options_->input_special_alignment,
279 if (lv_->buffer()->isReadonly())
280 fl_deactivate_object(column_options_->input_special_alignment);
281 special = tabular->GetAlignSpecial(cell,LyXTabular::SET_SPECIAL_MULTI);
283 fl_set_input(cell_options_->input_special_multialign, special.c_str());
284 if (lv_->buffer()->isReadonly())
285 fl_deactivate_object(cell_options_->input_special_multialign);
286 pwidth = tabular->GetPWidth(cell);
288 fl_set_input(column_options_->input_column_width,pwidth.c_str());
289 if (lv_->buffer()->isReadonly()) {
290 fl_deactivate_object(column_options_->input_column_width);
292 fl_activate_object(column_options_->input_column_width);
294 if (!pwidth.empty()) {
295 fl_activate_object(cell_options_->radio_linebreak_cell);
296 fl_set_object_lcol(cell_options_->radio_linebreak_cell, FL_BLACK);
297 fl_set_button(cell_options_->radio_linebreak_cell,
298 tabular->GetLinebreaks(cell));
300 fl_deactivate_object(cell_options_->radio_linebreak_cell);
301 fl_set_object_lcol(cell_options_->radio_linebreak_cell, FL_INACTIVE);
302 fl_set_button(cell_options_->radio_linebreak_cell,0);
304 if ((!pwidth.empty() && !tabular->IsMultiColumn(cell)) ||
305 (align == LYX_ALIGN_LEFT))
306 fl_set_button(column_options_->radio_align_left, 1);
307 else if (align == LYX_ALIGN_RIGHT)
308 fl_set_button(column_options_->radio_align_right, 1);
310 fl_set_button(column_options_->radio_align_center, 1);
311 if (!pwidth.empty() && !tabular->IsMultiColumn(cell)) {
312 fl_deactivate_object(column_options_->radio_align_left);
313 fl_deactivate_object(column_options_->radio_align_right);
314 fl_deactivate_object(column_options_->radio_align_center);
315 fl_set_object_lcol(column_options_->radio_align_left, FL_INACTIVE);
316 fl_set_object_lcol(column_options_->radio_align_right, FL_INACTIVE);
317 fl_set_object_lcol(column_options_->radio_align_center, FL_INACTIVE);
319 fl_activate_object(column_options_->radio_align_left);
320 fl_activate_object(column_options_->radio_align_right);
321 fl_activate_object(column_options_->radio_align_center);
322 fl_set_object_lcol(column_options_->radio_align_left, FL_BLACK);
323 fl_set_object_lcol(column_options_->radio_align_right, FL_BLACK);
324 fl_set_object_lcol(column_options_->radio_align_center, FL_BLACK);
326 fl_set_button(tabular_options_->radio_longtable,
327 tabular->IsLongTabular());
328 if (tabular->IsLongTabular()) {
329 fl_activate_object(longtable_options_->radio_lt_firsthead);
330 fl_activate_object(longtable_options_->radio_lt_head);
331 fl_activate_object(longtable_options_->radio_lt_foot);
332 fl_activate_object(longtable_options_->radio_lt_lastfoot);
333 fl_activate_object(longtable_options_->radio_lt_newpage);
334 fl_set_object_lcol(longtable_options_->radio_lt_firsthead, FL_BLACK);
335 fl_set_object_lcol(longtable_options_->radio_lt_head, FL_BLACK);
336 fl_set_object_lcol(longtable_options_->radio_lt_foot, FL_BLACK);
337 fl_set_object_lcol(longtable_options_->radio_lt_lastfoot, FL_BLACK);
338 fl_set_object_lcol(longtable_options_->radio_lt_newpage, FL_BLACK);
339 fl_set_button(longtable_options_->radio_lt_firsthead,
340 tabular->GetRowOfLTFirstHead(cell));
341 fl_set_button(longtable_options_->radio_lt_head,
342 tabular->GetRowOfLTHead(cell));
343 fl_set_button(longtable_options_->radio_lt_foot,
344 tabular->GetRowOfLTFoot(cell));
345 fl_set_button(longtable_options_->radio_lt_lastfoot,
346 tabular->GetRowOfLTLastFoot(cell));
347 fl_set_button(longtable_options_->radio_lt_newpage,
348 tabular->GetLTNewPage(cell));
350 fl_deactivate_object(longtable_options_->radio_lt_firsthead);
351 fl_deactivate_object(longtable_options_->radio_lt_head);
352 fl_deactivate_object(longtable_options_->radio_lt_foot);
353 fl_deactivate_object(longtable_options_->radio_lt_lastfoot);
354 fl_deactivate_object(longtable_options_->radio_lt_newpage);
355 fl_set_button(longtable_options_->radio_lt_firsthead,0);
356 fl_set_button(longtable_options_->radio_lt_head,0);
357 fl_set_button(longtable_options_->radio_lt_foot,0);
358 fl_set_button(longtable_options_->radio_lt_lastfoot,0);
359 fl_set_button(longtable_options_->radio_lt_newpage,0);
360 fl_set_object_lcol(longtable_options_->radio_lt_firsthead,FL_INACTIVE);
361 fl_set_object_lcol(longtable_options_->radio_lt_head, FL_INACTIVE);
362 fl_set_object_lcol(longtable_options_->radio_lt_foot, FL_INACTIVE);
363 fl_set_object_lcol(longtable_options_->radio_lt_lastfoot, FL_INACTIVE);
364 fl_set_object_lcol(longtable_options_->radio_lt_newpage, FL_INACTIVE);
366 fl_set_button(tabular_options_->radio_rotate_tabular,
367 tabular->GetRotateTabular());
371 // +-----------------------------------------------------------------------+
372 // | Functions/Dialogs for creating tabular insets |
373 // +-----------------------------------------------------------------------+
375 void FormTabular::show_create()
380 if (create_tabular_->form_create_tabular->visible) {
381 fl_raise_form(create_tabular_->form_create_tabular);
383 fl_show_form(create_tabular_->form_create_tabular,
384 FL_PLACE_MOUSE | FL_FREE_SIZE,
385 FL_FULLBORDER, _("Insert Tabular"));
390 void FormTabular::hide_create()
392 if (create_tabular_->form_create_tabular)
393 fl_hide_form(create_tabular_->form_create_tabular);
397 void FormTabular::apply_create()
402 // comm->setMinibuffer(_("Inserting tabular inset..."));
403 ysize = int(fl_get_slider_value(create_tabular_->slider_columns) + 0.5);
404 xsize = int(fl_get_slider_value(create_tabular_->slider_rows) + 0.5);
405 InsetTabular * in = new InsetTabular(lv_->buffer(),xsize,ysize);
406 if (!lv_->view()->open_new_inset(in)) {
409 // comm->setMinibuffer(_("Tabular mode"));
413 void FormTabular::OKCB(FL_OBJECT * ob, long)
415 FormTabular * pre = (FormTabular*)ob->form->u_vdata;
421 void FormTabular::ApplyCB(FL_OBJECT * ob, long)
423 FormTabular * pre = (FormTabular*)ob->form->u_vdata;
428 void FormTabular::CancelCB(FL_OBJECT * ob, long)
430 FormTabular * pre = (FormTabular*)ob->form->u_vdata;