]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiTabular.cpp
Compil fix.
[lyx.git] / src / frontends / qt4 / GuiTabular.cpp
1 /**
2  * \file GuiTabular.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  * \author Jürgen Spitzmüller
8  * \author Herbert Voß
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "GuiTabular.h"
16
17 #include "GuiSetBorder.h"
18 #include "GuiView.h"
19 #include "LengthCombo.h"
20 #include "qt_helpers.h"
21 #include "Validator.h"
22
23 #include "BufferView.h"
24 #include "Cursor.h"
25 #include "FuncRequest.h"
26 #include "LyXRC.h"
27
28 #include "insets/InsetTabular.h"
29
30 #include <QCheckBox>
31 #include <QPushButton>
32 #include <QRadioButton>
33 #include <QLineEdit>
34
35 using namespace std;
36
37 namespace lyx {
38 namespace frontend {
39
40 GuiTabular::GuiTabular(GuiView & lv)
41         : GuiDialog(lv, "tabular", qt_("Table Settings")),
42         // tabular_ is initialised at dialog construction in initialiseParams()
43         tabular_(*lv.buffer(), 0, 0)
44 {
45         active_cell_ = Tabular::npos;
46
47         setupUi(this);
48
49         widthED->setValidator(unsignedLengthValidator(widthED));
50         topspaceED->setValidator(new LengthValidator(topspaceED));
51         bottomspaceED->setValidator(new LengthValidator(bottomspaceED));
52         interlinespaceED->setValidator(new LengthValidator(interlinespaceED));
53
54         connect(topspaceED, SIGNAL(returnPressed()),
55                 this, SLOT(topspace_changed()));
56         connect(topspaceUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
57                 this, SLOT(topspace_changed()));
58         connect(topspaceCO, SIGNAL(activated(int)), this, SLOT(topspace_changed()));
59         connect(bottomspaceED, SIGNAL(returnPressed()),
60                 this, SLOT(bottomspace_changed()));
61         connect(bottomspaceUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
62                 this, SLOT(bottomspace_changed()));
63         connect(bottomspaceCO, SIGNAL(activated(int)), this, SLOT(bottomspace_changed()));
64         connect(interlinespaceED, SIGNAL(returnPressed()),
65                 this, SLOT(interlinespace_changed()));
66         connect(interlinespaceUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
67                 this, SLOT(interlinespace_changed()));
68         connect(interlinespaceCO, SIGNAL(activated(int)), this, SLOT(interlinespace_changed()));
69         connect(booktabsRB, SIGNAL(clicked(bool)), this, SLOT(booktabsChanged(bool)));
70         connect(borderDefaultRB, SIGNAL(clicked(bool)), this, SLOT(booktabsChanged(bool)));
71         connect(borderSetPB, SIGNAL(clicked()), this, SLOT(borderSet_clicked()));
72         connect(borderUnsetPB, SIGNAL(clicked()), this, SLOT(borderUnset_clicked()));
73         connect(longTabularCB, SIGNAL(toggled(bool)), longtableGB, SLOT(setEnabled(bool)));
74         connect(longTabularCB, SIGNAL(toggled(bool)), newpageCB, SLOT(setEnabled(bool)));
75         connect(hAlignCB, SIGNAL(activated(int)), this, SLOT(hAlign_changed(int)));
76         connect(vAlignCB, SIGNAL(activated(int)), this, SLOT(vAlign_changed(int)));
77         connect(multicolumnCB, SIGNAL(clicked()), this, SLOT(multicolumn_clicked()));
78         connect(newpageCB, SIGNAL(clicked()), this, SLOT(ltNewpage_clicked()));
79         connect(headerStatusCB, SIGNAL(clicked()), this, SLOT(ltHeaderStatus_clicked()));
80         connect(headerBorderAboveCB, SIGNAL(clicked()), this, SLOT(ltHeaderBorderAbove_clicked()));
81         connect(headerBorderBelowCB, SIGNAL(clicked()), this, SLOT(ltHeaderBorderBelow_clicked()));
82         connect(firstheaderStatusCB, SIGNAL(clicked()), this, SLOT(ltFirstHeaderStatus_clicked()));
83         connect(firstheaderBorderAboveCB, SIGNAL(clicked()), this, SLOT(ltFirstHeaderBorderAbove_clicked()));
84         connect(firstheaderBorderBelowCB, SIGNAL(clicked()), this, SLOT(ltFirstHeaderBorderBelow_clicked()));
85         connect(firstheaderNoContentsCB, SIGNAL(clicked()), this, SLOT(ltFirstHeaderEmpty_clicked()));
86         connect(footerStatusCB, SIGNAL(clicked()), this, SLOT(ltFooterStatus_clicked()));
87         connect(footerBorderAboveCB, SIGNAL(clicked()), this, SLOT(ltFooterBorderAbove_clicked()));
88         connect(footerBorderBelowCB, SIGNAL(clicked()), this, SLOT(ltFooterBorderBelow_clicked()));
89         connect(lastfooterStatusCB, SIGNAL(clicked()), this, SLOT(ltLastFooterStatus_clicked()));
90         connect(lastfooterBorderAboveCB, SIGNAL(clicked()), this, SLOT(ltLastFooterBorderAbove_clicked()));
91         connect(lastfooterBorderBelowCB, SIGNAL(clicked()), this, SLOT(ltLastFooterBorderBelow_clicked()));
92         connect(lastfooterNoContentsCB, SIGNAL(clicked()), this, SLOT(ltLastFooterEmpty_clicked()));
93         connect(specialAlignmentED, SIGNAL(returnPressed()), this, SLOT(specialAlignment_changed()));
94         connect(widthED, SIGNAL(returnPressed()), this, SLOT(width_changed()));
95         connect(widthUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)), this, SLOT(width_changed()));
96         connect(closePB, SIGNAL(clicked()), this, SLOT(close_clicked()));
97         connect(borders, SIGNAL(topSet(bool)), this, SLOT(topBorder_changed()));
98         connect(borders, SIGNAL(bottomSet(bool)), this, SLOT(bottomBorder_changed()));
99         connect(borders, SIGNAL(rightSet(bool)), this, SLOT(rightBorder_changed()));
100         connect(borders, SIGNAL(leftSet(bool)), this, SLOT(leftBorder_changed()));
101         connect(rotateTabularCB, SIGNAL(clicked()), this, SLOT(rotateTabular()));
102         connect(rotateCellCB, SIGNAL(clicked()), this, SLOT(rotateCell()));
103         connect(longTabularCB, SIGNAL(clicked()), this, SLOT(longTabular()));
104
105         bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
106         bc().setCancel(closePB);
107
108         bc().addReadOnly(topspaceED);
109         bc().addReadOnly(topspaceUnit);
110         bc().addReadOnly(topspaceCO);
111         bc().addReadOnly(bottomspaceED);
112         bc().addReadOnly(bottomspaceUnit);
113         bc().addReadOnly(bottomspaceCO);
114         bc().addReadOnly(interlinespaceED);
115         bc().addReadOnly(interlinespaceUnit);
116         bc().addReadOnly(interlinespaceCO);
117         bc().addReadOnly(borderDefaultRB);
118         bc().addReadOnly(booktabsRB);
119
120         bc().addReadOnly(multicolumnCB);
121         bc().addReadOnly(rotateCellCB);
122         bc().addReadOnly(rotateTabularCB);
123         bc().addReadOnly(specialAlignmentED);
124         bc().addReadOnly(widthED);
125         bc().addReadOnly(widthUnit);
126         bc().addReadOnly(hAlignCB);
127         bc().addReadOnly(vAlignCB);
128         bc().addReadOnly(borderSetPB);
129         bc().addReadOnly(borderUnsetPB);
130         bc().addReadOnly(borders);
131         bc().addReadOnly(longTabularCB);
132         bc().addReadOnly(headerStatusCB);
133         bc().addReadOnly(headerBorderAboveCB);
134         bc().addReadOnly(headerBorderBelowCB);
135         bc().addReadOnly(firstheaderStatusCB);
136         bc().addReadOnly(firstheaderBorderAboveCB);
137         bc().addReadOnly(firstheaderBorderBelowCB);
138         bc().addReadOnly(firstheaderNoContentsCB);
139         bc().addReadOnly(footerStatusCB);
140         bc().addReadOnly(footerBorderAboveCB);
141         bc().addReadOnly(footerBorderBelowCB);
142         bc().addReadOnly(lastfooterStatusCB);
143         bc().addReadOnly(lastfooterBorderAboveCB);
144         bc().addReadOnly(lastfooterBorderBelowCB);
145         bc().addReadOnly(lastfooterNoContentsCB);
146         bc().addReadOnly(newpageCB);
147
148         // initialize the length validator
149         bc().addCheckedLineEdit(widthED, fixedWidthColLA);
150         bc().addCheckedLineEdit(topspaceED, topspaceLA);
151         bc().addCheckedLineEdit(bottomspaceED, bottomspaceLA);
152         bc().addCheckedLineEdit(interlinespaceED, interlinespaceLA);
153 }
154
155
156 GuiTabular::~GuiTabular()
157 {
158 }
159
160
161 void GuiTabular::change_adaptor()
162 {
163         changed();
164 }
165
166
167 void GuiTabular::booktabsChanged(bool)
168 {
169         changed();
170         booktabs(booktabsRB->isChecked());
171         update_borders();
172 }
173
174
175 void GuiTabular::topspace_changed()
176 {
177         switch (topspaceCO->currentIndex()) {
178                 case 0: {
179                         set(Tabular::SET_TOP_SPACE, "");
180                         topspaceED->setEnabled(false);
181                         topspaceUnit->setEnabled(false);
182                         break;
183                 }
184                 case 1: {
185                         set(Tabular::SET_TOP_SPACE, "default");
186                         topspaceED->setEnabled(false);
187                         topspaceUnit->setEnabled(false);
188                         break;
189                 }
190                 case 2: {
191                         if (!topspaceED->text().isEmpty())
192                                 set(Tabular::SET_TOP_SPACE,
193                                         widgetsToLength(topspaceED, topspaceUnit));
194                         if (!bc().policy().isReadOnly()) {
195                                 topspaceED->setEnabled(true);
196                                 topspaceUnit->setEnabled(true);
197                         }
198                         break;
199                 }
200         }
201         changed();
202 }
203
204
205 void GuiTabular::bottomspace_changed()
206 {
207         switch (bottomspaceCO->currentIndex()) {
208                 case 0: {
209                         set(Tabular::SET_BOTTOM_SPACE, "");
210                                 bottomspaceED->setEnabled(false);
211                                 bottomspaceUnit->setEnabled(false);
212                         break;
213                 }
214                 case 1: {
215                         set(Tabular::SET_BOTTOM_SPACE, "default");
216                         bottomspaceED->setEnabled(false);
217                         bottomspaceUnit->setEnabled(false);
218                         break;
219                 }
220                 case 2: {
221                         if (!bottomspaceED->text().isEmpty())
222                                 set(Tabular::SET_BOTTOM_SPACE,
223                                         widgetsToLength(bottomspaceED, bottomspaceUnit));
224                         if (!bc().policy().isReadOnly()) {
225                                 bottomspaceED->setEnabled(true);
226                                 bottomspaceUnit->setEnabled(true);
227                         }
228                         break;
229                 }
230         }
231         changed();
232 }
233
234
235 void GuiTabular::interlinespace_changed()
236 {
237         switch (interlinespaceCO->currentIndex()) {
238                 case 0: {
239                         set(Tabular::SET_INTERLINE_SPACE, "");
240                                 interlinespaceED->setEnabled(false);
241                                 interlinespaceUnit->setEnabled(false);
242                         break;
243                 }
244                 case 1: {
245                         set(Tabular::SET_INTERLINE_SPACE, "default");
246                         interlinespaceED->setEnabled(false);
247                         interlinespaceUnit->setEnabled(false);
248                         break;
249                 }
250                 case 2: {
251                         if (!interlinespaceED->text().isEmpty())
252                                 set(Tabular::SET_INTERLINE_SPACE,
253                                         widgetsToLength(interlinespaceED, interlinespaceUnit));
254                         if (!bc().policy().isReadOnly()) {
255                                 interlinespaceED->setEnabled(true);
256                                 interlinespaceUnit->setEnabled(true);
257                         }
258                         break;
259                 }
260         }
261         changed();
262 }
263
264
265 void GuiTabular::close_clicked()
266 {
267         closeGUI();
268         slotClose();
269 }
270
271
272 void GuiTabular::borderSet_clicked()
273 {
274         set(Tabular::SET_ALL_LINES);
275         update_borders();
276         changed();
277 }
278
279
280 void GuiTabular::borderUnset_clicked()
281 {
282         set(Tabular::UNSET_ALL_LINES);
283         update_borders();
284         changed();
285 }
286
287
288 void GuiTabular::leftBorder_changed()
289 {
290         set(Tabular::TOGGLE_LINE_LEFT);
291         changed();
292 }
293
294
295 void GuiTabular::rightBorder_changed()
296 {
297         set(Tabular::TOGGLE_LINE_RIGHT);
298         changed();
299 }
300
301
302 void GuiTabular::topBorder_changed()
303 {
304         set(Tabular::TOGGLE_LINE_TOP);
305         changed();
306 }
307
308
309 void GuiTabular::bottomBorder_changed()
310 {
311         set(Tabular::TOGGLE_LINE_BOTTOM);
312         changed();
313 }
314
315
316 void GuiTabular::specialAlignment_changed()
317 {
318         string special = fromqstr(specialAlignmentED->text());
319         setSpecial(special);
320         changed();
321 }
322
323
324 void GuiTabular::width_changed()
325 {
326         changed();
327         string const width = widgetsToLength(widthED, widthUnit);
328         setWidth(width);
329 }
330
331
332 void GuiTabular::multicolumn_clicked()
333 {
334         toggleMultiColumn();
335         changed();
336 }
337
338
339 void GuiTabular::rotateTabular()
340 {
341         rotateTabular(rotateTabularCB->isChecked());
342         changed();
343 }
344
345
346 void GuiTabular::rotateCell()
347 {
348         rotateCell(rotateCellCB->isChecked());
349         changed();
350 }
351
352
353 void GuiTabular::hAlign_changed(int align)
354 {
355         GuiTabular::HALIGN h = GuiTabular::LEFT;
356
357         switch (align) {
358                 case 0: h = GuiTabular::LEFT; break;
359                 case 1: h = GuiTabular::CENTER; break;
360                 case 2: h = GuiTabular::RIGHT; break;
361                 case 3: h = GuiTabular::BLOCK; break;
362         }
363
364         halign(h);
365 }
366
367
368 void GuiTabular::vAlign_changed(int align)
369 {
370         GuiTabular::VALIGN v = GuiTabular::TOP;
371
372         switch (align) {
373                 case 0: v = GuiTabular::TOP; break;
374                 case 1: v = GuiTabular::MIDDLE; break;
375                 case 2: v = GuiTabular::BOTTOM; break;
376         }
377
378         valign(v);
379 }
380
381
382 void GuiTabular::longTabular()
383 {
384         longTabular(longTabularCB->isChecked());
385         changed();
386 }
387
388
389 void GuiTabular::ltNewpage_clicked()
390 {
391         set(Tabular::SET_LTNEWPAGE);
392         changed();
393 }
394
395
396 void GuiTabular::on_captionStatusCB_toggled()
397 {
398         set(Tabular::TOGGLE_LTCAPTION);
399         changed();
400 }
401
402
403 void GuiTabular::ltHeaderStatus_clicked()
404 {
405         bool enable = headerStatusCB->isChecked();
406         if (enable)
407                 set(Tabular::SET_LTHEAD, "");
408         else
409                 set(Tabular::UNSET_LTHEAD, "");
410         headerBorderAboveCB->setEnabled(enable);
411         headerBorderBelowCB->setEnabled(enable);
412         firstheaderNoContentsCB->setEnabled(enable);
413         changed();
414 }
415
416
417 void GuiTabular::ltHeaderBorderAbove_clicked()
418 {
419         if (headerBorderAboveCB->isChecked())
420                 set(Tabular::SET_LTHEAD, "dl_above");
421         else
422                 set(Tabular::UNSET_LTHEAD, "dl_above");
423         changed();
424 }
425
426
427 void GuiTabular::ltHeaderBorderBelow_clicked()
428 {
429         if (headerBorderBelowCB->isChecked())
430                 set(Tabular::SET_LTHEAD, "dl_below");
431         else
432                 set(Tabular::UNSET_LTHEAD, "dl_below");
433         changed();
434 }
435
436
437 void GuiTabular::ltFirstHeaderBorderAbove_clicked()
438 {
439         if (firstheaderBorderAboveCB->isChecked())
440                 set(Tabular::SET_LTFIRSTHEAD, "dl_above");
441         else
442                 set(Tabular::UNSET_LTFIRSTHEAD, "dl_above");
443         changed();
444 }
445
446
447 void GuiTabular::ltFirstHeaderBorderBelow_clicked()
448 {
449         if (firstheaderBorderBelowCB->isChecked())
450                 set(Tabular::SET_LTFIRSTHEAD, "dl_below");
451         else
452                 set(Tabular::UNSET_LTFIRSTHEAD, "dl_below");
453         changed();
454 }
455
456
457 void GuiTabular::ltFirstHeaderStatus_clicked()
458 {
459         bool enable = firstheaderStatusCB->isChecked();
460         if (enable)
461                 set(Tabular::SET_LTFIRSTHEAD, "");
462         else
463                 set(Tabular::UNSET_LTFIRSTHEAD, "");
464         firstheaderBorderAboveCB->setEnabled(enable);
465         firstheaderBorderBelowCB->setEnabled(enable);
466         changed();
467 }
468
469
470 void GuiTabular::ltFirstHeaderEmpty_clicked()
471 {
472         bool enable = firstheaderNoContentsCB->isChecked();
473         if (enable)
474                 set(Tabular::SET_LTFIRSTHEAD, "empty");
475         else
476                 set(Tabular::UNSET_LTFIRSTHEAD, "empty");
477         firstheaderStatusCB->setEnabled(!enable);
478         firstheaderBorderAboveCB->setEnabled(!enable);
479         firstheaderBorderBelowCB->setEnabled(!enable);
480         changed();
481 }
482
483
484 void GuiTabular::ltFooterStatus_clicked()
485 {
486         bool enable = footerStatusCB->isChecked();
487         if (enable)
488                 set(Tabular::SET_LTFOOT, "");
489         else
490                 set(Tabular::UNSET_LTFOOT, "");
491         footerBorderAboveCB->setEnabled(enable);
492         footerBorderBelowCB->setEnabled(enable);
493         lastfooterNoContentsCB->setEnabled(enable);
494         changed();
495 }
496
497
498 void GuiTabular::ltFooterBorderAbove_clicked()
499 {
500         if (footerBorderAboveCB->isChecked())
501                 set(Tabular::SET_LTFOOT, "dl_above");
502         else
503                 set(Tabular::UNSET_LTFOOT, "dl_above");
504         changed();
505 }
506
507
508 void GuiTabular::ltFooterBorderBelow_clicked()
509 {
510         if (footerBorderBelowCB->isChecked())
511                 set(Tabular::SET_LTFOOT, "dl_below");
512         else
513                 set(Tabular::UNSET_LTFOOT, "dl_below");
514         changed();
515 }
516
517
518 void GuiTabular::ltLastFooterStatus_clicked()
519 {
520         bool enable = lastfooterStatusCB->isChecked();
521         if (enable)
522                 set(Tabular::SET_LTLASTFOOT, "");
523         else
524                 set(Tabular::UNSET_LTLASTFOOT, "");
525         lastfooterBorderAboveCB->setEnabled(enable);
526         lastfooterBorderBelowCB->setEnabled(enable);
527         changed();
528 }
529
530
531 void GuiTabular::ltLastFooterBorderAbove_clicked()
532 {
533         if (lastfooterBorderAboveCB->isChecked())
534                 set(Tabular::SET_LTLASTFOOT, "dl_above");
535         else
536                 set(Tabular::UNSET_LTLASTFOOT, "dl_above");
537         changed();
538 }
539
540
541 void GuiTabular::ltLastFooterBorderBelow_clicked()
542 {
543         if (lastfooterBorderBelowCB->isChecked())
544                 set(Tabular::SET_LTLASTFOOT, "dl_below");
545         else
546                 set(Tabular::UNSET_LTLASTFOOT, "dl_below");
547         changed();
548 }
549
550
551 void GuiTabular::ltLastFooterEmpty_clicked()
552 {
553         bool enable = lastfooterNoContentsCB->isChecked();
554         if (enable)
555                 set(Tabular::SET_LTLASTFOOT, "empty");
556         else
557                 set(Tabular::UNSET_LTLASTFOOT, "empty");
558         lastfooterStatusCB->setEnabled(!enable);
559         lastfooterBorderAboveCB->setEnabled(!enable);
560         lastfooterBorderBelowCB->setEnabled(!enable);
561         changed();
562 }
563
564
565 void GuiTabular::update_borders()
566 {
567         Tabular::idx_type const cell = getActiveCell();
568         borders->setTop(tabular_.topLine(cell));
569         borders->setBottom(tabular_.bottomLine(cell));
570         borders->setLeft(tabular_.leftLine(cell));
571         borders->setRight(tabular_.rightLine(cell));
572         // repaint the setborder widget
573         borders->update();
574 }
575
576
577 namespace {
578
579 Length getColumnPWidth(Tabular const & t, size_t cell)
580 {
581         return t.column_info[t.cellColumn(cell)].p_width;
582 }
583
584
585 Length getMColumnPWidth(Tabular const & t, size_t cell)
586 {
587         if (t.isMultiColumn(cell))
588                 return t.cellInfo(cell).p_width;
589         return Length();
590 }
591
592
593 docstring getAlignSpecial(Tabular const & t, size_t cell, int what)
594 {
595         if (what == Tabular::SET_SPECIAL_MULTI)
596                 return t.cellInfo(cell).align_special;
597         return t.column_info[t.cellColumn(cell)].align_special;
598 }
599
600 }
601
602
603
604 void GuiTabular::updateContents()
605 {
606         initialiseParams(string());
607
608         size_t const cell = getActiveCell();
609
610         Tabular::row_type const row = tabular_.cellRow(cell);
611         Tabular::col_type const col = tabular_.cellColumn(cell);
612
613         tabularRowED->setText(QString::number(row + 1));
614         tabularColumnED->setText(QString::number(col + 1));
615
616         bool const multicol(tabular_.isMultiColumn(cell));
617
618         multicolumnCB->setChecked(multicol);
619
620         rotateCellCB->setChecked(tabular_.getRotateCell(cell));
621         rotateTabularCB->setChecked(tabular_.rotate);
622
623         longTabularCB->setChecked(tabular_.is_long_tabular);
624
625         update_borders();
626
627         Length pwidth;
628         docstring special;
629
630         if (multicol) {
631                 special = getAlignSpecial(tabular_, cell, Tabular::SET_SPECIAL_MULTI);
632                 pwidth = getMColumnPWidth(tabular_, cell);
633         } else {
634                 special = getAlignSpecial(tabular_, cell, Tabular::SET_SPECIAL_COLUMN);
635                 pwidth = getColumnPWidth(tabular_, cell);
636         }
637
638         specialAlignmentED->setText(toqstr(special));
639
640         bool const isReadonly = bc().policy().isReadOnly();
641         specialAlignmentED->setEnabled(!isReadonly);
642
643         Length::UNIT default_unit =
644                 useMetricUnits() ? Length::CM : Length::IN;
645
646         borderDefaultRB->setChecked(!tabular_.use_booktabs);
647         booktabsRB->setChecked(tabular_.use_booktabs);
648
649         if (tabular_.row_info[row].top_space.empty()
650             && !tabular_.row_info[row].top_space_default) {
651                 topspaceCO->setCurrentIndex(0);
652         } else if (tabular_.row_info[row].top_space_default) {
653                 topspaceCO->setCurrentIndex(1);
654         } else {
655                 topspaceCO->setCurrentIndex(2);
656                 lengthToWidgets(topspaceED,
657                                 topspaceUnit,
658                                 tabular_.row_info[row].top_space.asString(),
659                                 default_unit);
660         }
661         topspaceED->setEnabled(!isReadonly
662                 && (topspaceCO->currentIndex() == 2));
663         topspaceUnit->setEnabled(!isReadonly
664                 && (topspaceCO->currentIndex() == 2));
665         topspaceCO->setEnabled(!isReadonly);
666
667         if (tabular_.row_info[row].bottom_space.empty()
668             && !tabular_.row_info[row].bottom_space_default) {
669                 bottomspaceCO->setCurrentIndex(0);
670         } else if (tabular_.row_info[row].bottom_space_default) {
671                 bottomspaceCO->setCurrentIndex(1);
672         } else {
673                 bottomspaceCO->setCurrentIndex(2);
674                 lengthToWidgets(bottomspaceED,
675                                 bottomspaceUnit,
676                                 tabular_.row_info[row].bottom_space.asString(),
677                                 default_unit);
678         }
679         bottomspaceED->setEnabled(!isReadonly
680                 && (bottomspaceCO->currentIndex() == 2));
681         bottomspaceUnit->setEnabled(!isReadonly
682                 && (bottomspaceCO->currentIndex() == 2));
683         bottomspaceCO->setEnabled(!isReadonly);
684
685         if (tabular_.row_info[row].interline_space.empty()
686             && !tabular_.row_info[row].interline_space_default) {
687                 interlinespaceCO->setCurrentIndex(0);
688         } else if (tabular_.row_info[row].interline_space_default) {
689                 interlinespaceCO->setCurrentIndex(1);
690         } else {
691                 interlinespaceCO->setCurrentIndex(2);
692                 lengthToWidgets(interlinespaceED,
693                                 interlinespaceUnit,
694                                 tabular_.row_info[row].interline_space.asString(),
695                                 default_unit);
696         }
697         interlinespaceED->setEnabled(!isReadonly
698                 && (interlinespaceCO->currentIndex() == 2));
699         interlinespaceUnit->setEnabled(!isReadonly
700                 && (interlinespaceCO->currentIndex() == 2));
701         interlinespaceCO->setEnabled(!isReadonly);
702
703         string colwidth;
704         if (!pwidth.zero())
705                 colwidth = pwidth.asString();
706         lengthToWidgets(widthED, widthUnit,
707                 colwidth, default_unit);
708
709         widthED->setEnabled(!isReadonly);
710         widthUnit->setEnabled(!isReadonly);
711
712         hAlignCB->clear();
713         hAlignCB->addItem(qt_("Left"));
714         hAlignCB->addItem(qt_("Center"));
715         hAlignCB->addItem(qt_("Right"));
716         if (!multicol && !pwidth.zero())
717                 hAlignCB->addItem(qt_("Justified"));
718
719         int align = 0;
720         switch (tabular_.getAlignment(cell)) {
721         case LYX_ALIGN_LEFT:
722                 align = 0;
723                 break;
724         case LYX_ALIGN_CENTER:
725                 align = 1;
726                 break;
727         case LYX_ALIGN_RIGHT:
728                 align = 2;
729                 break;
730         case LYX_ALIGN_BLOCK:
731         {
732                 if (!multicol && !pwidth.zero())
733                         align = 3;
734                 break;
735         }
736         default:
737                 align = 0;
738                 break;
739         }
740         hAlignCB->setCurrentIndex(align);
741
742         int valign = 0;
743         switch (tabular_.getVAlignment(cell)) {
744         case Tabular::LYX_VALIGN_TOP:
745                 valign = 0;
746                 break;
747         case Tabular::LYX_VALIGN_MIDDLE:
748                 valign = 1;
749                 break;
750         case Tabular::LYX_VALIGN_BOTTOM:
751                 valign = 2;
752                 break;
753         default:
754                 valign = 1;
755                 break;
756         }
757         if (pwidth.zero())
758                 valign = 1;
759         vAlignCB->setCurrentIndex(valign);
760
761         hAlignCB->setEnabled(true);
762         vAlignCB->setEnabled(!pwidth.zero());
763
764         if (!tabular_.is_long_tabular) {
765                 headerStatusCB->setChecked(false);
766                 headerBorderAboveCB->setChecked(false);
767                 headerBorderBelowCB->setChecked(false);
768                 firstheaderStatusCB->setChecked(false);
769                 firstheaderBorderAboveCB->setChecked(false);
770                 firstheaderBorderBelowCB->setChecked(false);
771                 firstheaderNoContentsCB->setChecked(false);
772                 footerStatusCB->setChecked(false);
773                 footerBorderAboveCB->setChecked(false);
774                 footerBorderBelowCB->setChecked(false);
775                 lastfooterStatusCB->setChecked(false);
776                 lastfooterBorderAboveCB->setChecked(false);
777                 lastfooterBorderBelowCB->setChecked(false);
778                 lastfooterNoContentsCB->setChecked(false);
779                 newpageCB->setChecked(false);
780                 newpageCB->setEnabled(false);
781                 captionStatusCB->blockSignals(true);
782                 captionStatusCB->setChecked(false);
783                 captionStatusCB->blockSignals(false);
784                 return;
785         }
786         captionStatusCB->blockSignals(true);
787         captionStatusCB->setChecked(tabular_.ltCaption(row));
788         captionStatusCB->blockSignals(false);
789
790         Tabular::ltType ltt;
791         bool use_empty;
792         bool row_set = tabular_.getRowOfLTHead(row, ltt);
793         headerStatusCB->setChecked(row_set);
794         if (ltt.set) {
795                 headerBorderAboveCB->setChecked(ltt.topDL);
796                 headerBorderBelowCB->setChecked(ltt.bottomDL);
797                 use_empty = true;
798         } else {
799                 headerBorderAboveCB->setChecked(false);
800                 headerBorderBelowCB->setChecked(false);
801                 headerBorderAboveCB->setEnabled(false);
802                 headerBorderBelowCB->setEnabled(false);
803                 firstheaderNoContentsCB->setChecked(false);
804                 firstheaderNoContentsCB->setEnabled(false);
805                 use_empty = false;
806         }
807
808         row_set = tabular_.getRowOfLTFirstHead(row, ltt);
809         firstheaderStatusCB->setChecked(row_set);
810         if (ltt.set && (!ltt.empty || !use_empty)) {
811                 firstheaderBorderAboveCB->setChecked(ltt.topDL);
812                 firstheaderBorderBelowCB->setChecked(ltt.bottomDL);
813         } else {
814                 firstheaderBorderAboveCB->setEnabled(false);
815                 firstheaderBorderBelowCB->setEnabled(false);
816                 firstheaderBorderAboveCB->setChecked(false);
817                 firstheaderBorderBelowCB->setChecked(false);
818                 if (use_empty) {
819                         firstheaderNoContentsCB->setChecked(ltt.empty);
820                         if (ltt.empty)
821                                 firstheaderStatusCB->setEnabled(false);
822                 }
823         }
824
825         row_set = tabular_.getRowOfLTFoot(row, ltt);
826         footerStatusCB->setChecked(row_set);
827         if (ltt.set) {
828                 footerBorderAboveCB->setChecked(ltt.topDL);
829                 footerBorderBelowCB->setChecked(ltt.bottomDL);
830                 use_empty = true;
831         } else {
832                 footerBorderAboveCB->setChecked(false);
833                 footerBorderBelowCB->setChecked(false);
834                 footerBorderAboveCB->setEnabled(false);
835                 footerBorderBelowCB->setEnabled(false);
836                 lastfooterNoContentsCB->setChecked(false);
837                 lastfooterNoContentsCB->setEnabled(false);
838                 use_empty = false;
839         }
840
841         row_set = tabular_.getRowOfLTLastFoot(row, ltt);
842                 lastfooterStatusCB->setChecked(row_set);
843         if (ltt.set && (!ltt.empty || !use_empty)) {
844                 lastfooterBorderAboveCB->setChecked(ltt.topDL);
845                 lastfooterBorderBelowCB->setChecked(ltt.bottomDL);
846         } else {
847                 lastfooterBorderAboveCB->setEnabled(false);
848                 lastfooterBorderBelowCB->setEnabled(false);
849                 lastfooterBorderAboveCB->setChecked(false);
850                 lastfooterBorderBelowCB->setChecked(false);
851                 if (use_empty) {
852                         lastfooterNoContentsCB->setChecked(ltt.empty);
853                         if (ltt.empty)
854                                 lastfooterStatusCB->setEnabled(false);
855                 }
856         }
857         newpageCB->setChecked(tabular_.getLTNewPage(row));
858 }
859
860
861 void GuiTabular::closeGUI()
862 {
863         // ugly hack to auto-apply the stuff that hasn't been
864         // yet. don't let this continue to exist ...
865
866         // Subtle here, we must /not/ apply any changes and
867         // then refer to tabular, as it will have been freed
868         // since the changes update the actual tabular_
869         //
870         // apply the fixed width values
871         size_t const cell = getActiveCell();
872         bool const multicol = tabular_.isMultiColumn(cell);
873         string width = widgetsToLength(widthED, widthUnit);
874         string width2;
875
876         Length llen = getColumnPWidth(tabular_, cell);
877         Length llenMulti = getMColumnPWidth(tabular_, cell);
878
879         if (multicol && !llenMulti.zero())
880                 width2 = llenMulti.asString();
881         else if (!multicol && !llen.zero())
882                 width2 = llen.asString();
883
884         // apply the special alignment
885         docstring const sa1 = qstring_to_ucs4(specialAlignmentED->text());
886         docstring sa2;
887
888         if (multicol)
889                 sa2 = getAlignSpecial(tabular_, cell, Tabular::SET_SPECIAL_MULTI);
890         else
891                 sa2 = getAlignSpecial(tabular_, cell, Tabular::SET_SPECIAL_COLUMN);
892
893         if (sa1 != sa2) {
894                 if (multicol)
895                         set(Tabular::SET_SPECIAL_MULTI, to_utf8(sa1));
896                 else
897                         set(Tabular::SET_SPECIAL_COLUMN, to_utf8(sa1));
898         }
899
900         if (width != width2) {
901                 if (multicol)
902                         set(Tabular::SET_MPWIDTH, width);
903                 else
904                         set(Tabular::SET_PWIDTH, width);
905         }
906
907         /* DO WE NEED THIS?
908         switch (topspaceCO->currentIndex()) {
909                 case 0:
910                         set(Tabular::SET_TOP_SPACE, "");
911                         break;
912                 case 1:
913                         set(Tabular::SET_TOP_SPACE, "default");
914                         break;
915                 case 2:
916                         set(Tabular::SET_TOP_SPACE,
917                                 widgetsToLength(topspaceED, topspaceUnit));
918                         break;
919         }
920
921         switch (bottomspaceCO->currentIndex()) {
922                 case 0:
923                         set(Tabular::SET_BOTTOM_SPACE, "");
924                         break;
925                 case 1:
926                         set(Tabular::SET_BOTTOM_SPACE, "default");
927                         break;
928                 case 2:
929                         set(Tabular::SET_BOTTOM_SPACE,
930                                 widgetsToLength(bottomspaceED, bottomspaceUnit));
931                         break;
932         }
933
934         switch (interlinespaceCO->currentIndex()) {
935                 case 0:
936                         set(Tabular::SET_INTERLINE_SPACE, "");
937                         break;
938                 case 1:
939                         set(Tabular::SET_INTERLINE_SPACE, "default");
940                         break;
941                 case 2:
942                         set(Tabular::SET_INTERLINE_SPACE,
943                                 widgetsToLength(interlinespaceED, interlinespaceUnit));
944                         break;
945         }
946 */
947 }
948
949
950 bool GuiTabular::initialiseParams(string const & data)
951 {
952         // try to get the current cell
953         BufferView const * const bv = bufferview();
954         InsetTabular const * current_inset = 0;
955         if (bv) {
956                 Cursor const & cur = bv->cursor();
957                 // get the innermost tabular inset;
958                 // assume that it is "ours"
959                 for (int i = cur.depth() - 1; i >= 0; --i)
960                         if (cur[i].inset().lyxCode() == TABULAR_CODE) {
961                                 current_inset = static_cast<InsetTabular const *>(&cur[i].inset());
962                                 active_cell_ = cur[i].idx();
963                                 break;
964                         }
965         }
966
967         if (current_inset && data.empty()) {
968                 tabular_ = Tabular(current_inset->tabular);
969                 return true;
970         }
971
972         InsetTabular tmp(buffer());
973         InsetTabular::string2params(data, tmp);
974         tabular_ = Tabular(tmp.tabular);
975         return true;
976 }
977
978
979 void GuiTabular::clearParams()
980 {
981         InsetTabular tmp(buffer());
982         tabular_ = tmp.tabular;
983         active_cell_ = Tabular::npos;
984 }
985
986
987 Tabular::idx_type GuiTabular::getActiveCell() const
988 {
989         return active_cell_;
990 }
991
992
993 void GuiTabular::set(Tabular::Feature f, string const & arg)
994 {
995         string const data = featureAsString(f) + ' ' + arg;
996         dispatch(FuncRequest(getLfun(), data));
997 }
998
999
1000 bool GuiTabular::useMetricUnits() const
1001 {
1002         return lyxrc.default_papersize > PAPER_USEXECUTIVE;
1003 }
1004
1005
1006 void GuiTabular::setSpecial(string const & special)
1007 {
1008         if (tabular_.isMultiColumn(getActiveCell()))
1009                 set(Tabular::SET_SPECIAL_MULTI, special);
1010         else
1011                 set(Tabular::SET_SPECIAL_COLUMN, special);
1012 }
1013
1014
1015 void GuiTabular::setWidth(string const & width)
1016 {
1017         if (tabular_.isMultiColumn(getActiveCell()))
1018                 set(Tabular::SET_MPWIDTH, width);
1019         else
1020                 set(Tabular::SET_PWIDTH, width);
1021
1022         updateView();
1023 }
1024
1025
1026 void GuiTabular::toggleMultiColumn()
1027 {
1028         set(Tabular::MULTICOLUMN);
1029         updateView();
1030 }
1031
1032
1033 void GuiTabular::rotateTabular(bool yes)
1034 {
1035         if (yes)
1036                 set(Tabular::SET_ROTATE_TABULAR);
1037         else
1038                 set(Tabular::UNSET_ROTATE_TABULAR);
1039 }
1040
1041
1042 void GuiTabular::rotateCell(bool yes)
1043 {
1044         if (yes)
1045                 set(Tabular::SET_ROTATE_CELL);
1046         else
1047                 set(Tabular::UNSET_ROTATE_CELL);
1048 }
1049
1050
1051 void GuiTabular::halign(GuiTabular::HALIGN h)
1052 {
1053         Tabular::Feature num = Tabular::ALIGN_LEFT;
1054         Tabular::Feature multi_num = Tabular::M_ALIGN_LEFT;
1055
1056         switch (h) {
1057                 case LEFT:
1058                         num = Tabular::ALIGN_LEFT;
1059                         multi_num = Tabular::M_ALIGN_LEFT;
1060                         break;
1061                 case CENTER:
1062                         num = Tabular::ALIGN_CENTER;
1063                         multi_num = Tabular::M_ALIGN_CENTER;
1064                         break;
1065                 case RIGHT:
1066                         num = Tabular::ALIGN_RIGHT;
1067                         multi_num = Tabular::M_ALIGN_RIGHT;
1068                         break;
1069                 case BLOCK:
1070                         num = Tabular::ALIGN_BLOCK;
1071                         //multi_num: no equivalent
1072                         break;
1073         }
1074
1075         if (tabular_.isMultiColumn(getActiveCell()))
1076                 set(multi_num);
1077         else
1078                 set(num);
1079 }
1080
1081
1082 void GuiTabular::valign(GuiTabular::VALIGN v)
1083 {
1084         Tabular::Feature num = Tabular::VALIGN_MIDDLE;
1085         Tabular::Feature multi_num = Tabular::M_VALIGN_MIDDLE;
1086
1087         switch (v) {
1088                 case TOP:
1089                         num = Tabular::VALIGN_TOP;
1090                         multi_num = Tabular::M_VALIGN_TOP;
1091                         break;
1092                 case MIDDLE:
1093                         num = Tabular::VALIGN_MIDDLE;
1094                         multi_num = Tabular::M_VALIGN_MIDDLE;
1095                         break;
1096                 case BOTTOM:
1097                         num = Tabular::VALIGN_BOTTOM;
1098                         multi_num = Tabular::M_VALIGN_BOTTOM;
1099                         break;
1100         }
1101
1102         if (tabular_.isMultiColumn(getActiveCell()))
1103                 set(multi_num);
1104         else
1105                 set(num);
1106 }
1107
1108
1109 void GuiTabular::booktabs(bool yes)
1110 {
1111         if (yes)
1112                 set(Tabular::SET_BOOKTABS);
1113         else
1114                 set(Tabular::UNSET_BOOKTABS);
1115 }
1116
1117
1118 void GuiTabular::longTabular(bool yes)
1119 {
1120         if (yes)
1121                 set(Tabular::SET_LONGTABULAR);
1122         else
1123                 set(Tabular::UNSET_LONGTABULAR);
1124 }
1125
1126
1127 Dialog * createGuiTabular(GuiView & lv) { return new GuiTabular(lv); }
1128
1129
1130 } // namespace frontend
1131 } // namespace lyx
1132
1133 #include "GuiTabular_moc.cpp"