]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiTabular.cpp
dccad356a56560e5e6e08b4c5d44805c9ccd5eb9
[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::ltHeaderStatus_clicked()
397 {
398         bool enable = headerStatusCB->isChecked();
399         if (enable)
400                 set(Tabular::SET_LTHEAD, "");
401         else
402                 set(Tabular::UNSET_LTHEAD, "");
403         headerBorderAboveCB->setEnabled(enable);
404         headerBorderBelowCB->setEnabled(enable);
405         firstheaderNoContentsCB->setEnabled(enable);
406         changed();
407 }
408
409
410 void GuiTabular::ltHeaderBorderAbove_clicked()
411 {
412         if (headerBorderAboveCB->isChecked())
413                 set(Tabular::SET_LTHEAD, "dl_above");
414         else
415                 set(Tabular::UNSET_LTHEAD, "dl_above");
416         changed();
417 }
418
419
420 void GuiTabular::ltHeaderBorderBelow_clicked()
421 {
422         if (headerBorderBelowCB->isChecked())
423                 set(Tabular::SET_LTHEAD, "dl_below");
424         else
425                 set(Tabular::UNSET_LTHEAD, "dl_below");
426         changed();
427 }
428
429
430 void GuiTabular::ltFirstHeaderBorderAbove_clicked()
431 {
432         if (firstheaderBorderAboveCB->isChecked())
433                 set(Tabular::SET_LTFIRSTHEAD, "dl_above");
434         else
435                 set(Tabular::UNSET_LTFIRSTHEAD, "dl_above");
436         changed();
437 }
438
439
440 void GuiTabular::ltFirstHeaderBorderBelow_clicked()
441 {
442         if (firstheaderBorderBelowCB->isChecked())
443                 set(Tabular::SET_LTFIRSTHEAD, "dl_below");
444         else
445                 set(Tabular::UNSET_LTFIRSTHEAD, "dl_below");
446         changed();
447 }
448
449
450 void GuiTabular::ltFirstHeaderStatus_clicked()
451 {
452         bool enable = firstheaderStatusCB->isChecked();
453         if (enable)
454                 set(Tabular::SET_LTFIRSTHEAD, "");
455         else
456                 set(Tabular::UNSET_LTFIRSTHEAD, "");
457         firstheaderBorderAboveCB->setEnabled(enable);
458         firstheaderBorderBelowCB->setEnabled(enable);
459         changed();
460 }
461
462
463 void GuiTabular::ltFirstHeaderEmpty_clicked()
464 {
465         bool enable = firstheaderNoContentsCB->isChecked();
466         if (enable)
467                 set(Tabular::SET_LTFIRSTHEAD, "empty");
468         else
469                 set(Tabular::UNSET_LTFIRSTHEAD, "empty");
470         firstheaderStatusCB->setEnabled(!enable);
471         firstheaderBorderAboveCB->setEnabled(!enable);
472         firstheaderBorderBelowCB->setEnabled(!enable);
473         changed();
474 }
475
476
477 void GuiTabular::ltFooterStatus_clicked()
478 {
479         bool enable = footerStatusCB->isChecked();
480         if (enable)
481                 set(Tabular::SET_LTFOOT, "");
482         else
483                 set(Tabular::UNSET_LTFOOT, "");
484         footerBorderAboveCB->setEnabled(enable);
485         footerBorderBelowCB->setEnabled(enable);
486         lastfooterNoContentsCB->setEnabled(enable);
487         changed();
488 }
489
490
491 void GuiTabular::ltFooterBorderAbove_clicked()
492 {
493         if (footerBorderAboveCB->isChecked())
494                 set(Tabular::SET_LTFOOT, "dl_above");
495         else
496                 set(Tabular::UNSET_LTFOOT, "dl_above");
497         changed();
498 }
499
500
501 void GuiTabular::ltFooterBorderBelow_clicked()
502 {
503         if (footerBorderBelowCB->isChecked())
504                 set(Tabular::SET_LTFOOT, "dl_below");
505         else
506                 set(Tabular::UNSET_LTFOOT, "dl_below");
507         changed();
508 }
509
510
511 void GuiTabular::ltLastFooterStatus_clicked()
512 {
513         bool enable = lastfooterStatusCB->isChecked();
514         if (enable)
515                 set(Tabular::SET_LTLASTFOOT, "");
516         else
517                 set(Tabular::UNSET_LTLASTFOOT, "");
518         lastfooterBorderAboveCB->setEnabled(enable);
519         lastfooterBorderBelowCB->setEnabled(enable);
520         changed();
521 }
522
523
524 void GuiTabular::ltLastFooterBorderAbove_clicked()
525 {
526         if (lastfooterBorderAboveCB->isChecked())
527                 set(Tabular::SET_LTLASTFOOT, "dl_above");
528         else
529                 set(Tabular::UNSET_LTLASTFOOT, "dl_above");
530         changed();
531 }
532
533
534 void GuiTabular::ltLastFooterBorderBelow_clicked()
535 {
536         if (lastfooterBorderBelowCB->isChecked())
537                 set(Tabular::SET_LTLASTFOOT, "dl_below");
538         else
539                 set(Tabular::UNSET_LTLASTFOOT, "dl_below");
540         changed();
541 }
542
543
544 void GuiTabular::ltLastFooterEmpty_clicked()
545 {
546         bool enable = lastfooterNoContentsCB->isChecked();
547         if (enable)
548                 set(Tabular::SET_LTLASTFOOT, "empty");
549         else
550                 set(Tabular::UNSET_LTLASTFOOT, "empty");
551         lastfooterStatusCB->setEnabled(!enable);
552         lastfooterBorderAboveCB->setEnabled(!enable);
553         lastfooterBorderBelowCB->setEnabled(!enable);
554         changed();
555 }
556
557
558 void GuiTabular::update_borders()
559 {
560         Tabular::idx_type const cell = getActiveCell();
561         borders->setTop(tabular_.topLine(cell));
562         borders->setBottom(tabular_.bottomLine(cell));
563         borders->setLeft(tabular_.leftLine(cell));
564         borders->setRight(tabular_.rightLine(cell));
565         // repaint the setborder widget
566         borders->update();
567 }
568
569
570 namespace {
571
572 Length getColumnPWidth(Tabular const & t, size_t cell)
573 {
574         return t.column_info[t.cellColumn(cell)].p_width;
575 }
576
577
578 Length getMColumnPWidth(Tabular const & t, size_t cell)
579 {
580         if (t.isMultiColumn(cell))
581                 return t.cellInfo(cell).p_width;
582         return Length();
583 }
584
585
586 docstring getAlignSpecial(Tabular const & t, size_t cell, int what)
587 {
588         if (what == Tabular::SET_SPECIAL_MULTI)
589                 return t.cellInfo(cell).align_special;
590         return t.column_info[t.cellColumn(cell)].align_special;
591 }
592
593 }
594
595
596
597 void GuiTabular::updateContents()
598 {
599         initialiseParams(string());
600
601         size_t const cell = getActiveCell();
602
603         Tabular::row_type const row = tabular_.cellRow(cell);
604         Tabular::col_type const col = tabular_.cellColumn(cell);
605
606         tabularRowED->setText(QString::number(row + 1));
607         tabularColumnED->setText(QString::number(col + 1));
608
609         bool const multicol(tabular_.isMultiColumn(cell));
610
611         multicolumnCB->setChecked(multicol);
612
613         rotateCellCB->setChecked(tabular_.getRotateCell(cell));
614         rotateTabularCB->setChecked(tabular_.rotate);
615
616         longTabularCB->setChecked(tabular_.is_long_tabular);
617
618         update_borders();
619
620         Length pwidth;
621         docstring special;
622
623         if (multicol) {
624                 special = getAlignSpecial(tabular_, cell, Tabular::SET_SPECIAL_MULTI);
625                 pwidth = getMColumnPWidth(tabular_, cell);
626         } else {
627                 special = getAlignSpecial(tabular_, cell, Tabular::SET_SPECIAL_COLUMN);
628                 pwidth = getColumnPWidth(tabular_, cell);
629         }
630
631         specialAlignmentED->setText(toqstr(special));
632
633         bool const isReadonly = bc().policy().isReadOnly();
634         specialAlignmentED->setEnabled(!isReadonly);
635
636         Length::UNIT default_unit =
637                 useMetricUnits() ? Length::CM : Length::IN;
638
639         borderDefaultRB->setChecked(!tabular_.use_booktabs);
640         booktabsRB->setChecked(tabular_.use_booktabs);
641
642         if (tabular_.row_info[row].top_space.empty()
643             && !tabular_.row_info[row].top_space_default) {
644                 topspaceCO->setCurrentIndex(0);
645         } else if (tabular_.row_info[row].top_space_default) {
646                 topspaceCO->setCurrentIndex(1);
647         } else {
648                 topspaceCO->setCurrentIndex(2);
649                 lengthToWidgets(topspaceED,
650                                 topspaceUnit,
651                                 tabular_.row_info[row].top_space.asString(),
652                                 default_unit);
653         }
654         topspaceED->setEnabled(!isReadonly
655                 && (topspaceCO->currentIndex() == 2));
656         topspaceUnit->setEnabled(!isReadonly
657                 && (topspaceCO->currentIndex() == 2));
658         topspaceCO->setEnabled(!isReadonly);
659
660         if (tabular_.row_info[row].bottom_space.empty()
661             && !tabular_.row_info[row].bottom_space_default) {
662                 bottomspaceCO->setCurrentIndex(0);
663         } else if (tabular_.row_info[row].bottom_space_default) {
664                 bottomspaceCO->setCurrentIndex(1);
665         } else {
666                 bottomspaceCO->setCurrentIndex(2);
667                 lengthToWidgets(bottomspaceED,
668                                 bottomspaceUnit,
669                                 tabular_.row_info[row].bottom_space.asString(),
670                                 default_unit);
671         }
672         bottomspaceED->setEnabled(!isReadonly
673                 && (bottomspaceCO->currentIndex() == 2));
674         bottomspaceUnit->setEnabled(!isReadonly
675                 && (bottomspaceCO->currentIndex() == 2));
676         bottomspaceCO->setEnabled(!isReadonly);
677
678         if (tabular_.row_info[row].interline_space.empty()
679             && !tabular_.row_info[row].interline_space_default) {
680                 interlinespaceCO->setCurrentIndex(0);
681         } else if (tabular_.row_info[row].interline_space_default) {
682                 interlinespaceCO->setCurrentIndex(1);
683         } else {
684                 interlinespaceCO->setCurrentIndex(2);
685                 lengthToWidgets(interlinespaceED,
686                                 interlinespaceUnit,
687                                 tabular_.row_info[row].interline_space.asString(),
688                                 default_unit);
689         }
690         interlinespaceED->setEnabled(!isReadonly
691                 && (interlinespaceCO->currentIndex() == 2));
692         interlinespaceUnit->setEnabled(!isReadonly
693                 && (interlinespaceCO->currentIndex() == 2));
694         interlinespaceCO->setEnabled(!isReadonly);
695
696         string colwidth;
697         if (!pwidth.zero())
698                 colwidth = pwidth.asString();
699         lengthToWidgets(widthED, widthUnit,
700                 colwidth, default_unit);
701
702         widthED->setEnabled(!isReadonly);
703         widthUnit->setEnabled(!isReadonly);
704
705         hAlignCB->clear();
706         hAlignCB->addItem(qt_("Left"));
707         hAlignCB->addItem(qt_("Center"));
708         hAlignCB->addItem(qt_("Right"));
709         if (!multicol && !pwidth.zero())
710                 hAlignCB->addItem(qt_("Justified"));
711
712         int align = 0;
713         switch (tabular_.getAlignment(cell)) {
714         case LYX_ALIGN_LEFT:
715                 align = 0;
716                 break;
717         case LYX_ALIGN_CENTER:
718                 align = 1;
719                 break;
720         case LYX_ALIGN_RIGHT:
721                 align = 2;
722                 break;
723         case LYX_ALIGN_BLOCK:
724         {
725                 if (!multicol && !pwidth.zero())
726                         align = 3;
727                 break;
728         }
729         default:
730                 align = 0;
731                 break;
732         }
733         hAlignCB->setCurrentIndex(align);
734
735         int valign = 0;
736         switch (tabular_.getVAlignment(cell)) {
737         case Tabular::LYX_VALIGN_TOP:
738                 valign = 0;
739                 break;
740         case Tabular::LYX_VALIGN_MIDDLE:
741                 valign = 1;
742                 break;
743         case Tabular::LYX_VALIGN_BOTTOM:
744                 valign = 2;
745                 break;
746         default:
747                 valign = 1;
748                 break;
749         }
750         if (pwidth.zero())
751                 valign = 1;
752         vAlignCB->setCurrentIndex(valign);
753
754         hAlignCB->setEnabled(true);
755         vAlignCB->setEnabled(!pwidth.zero());
756
757         if (!tabular_.is_long_tabular) {
758                 headerStatusCB->setChecked(false);
759                 headerBorderAboveCB->setChecked(false);
760                 headerBorderBelowCB->setChecked(false);
761                 firstheaderStatusCB->setChecked(false);
762                 firstheaderBorderAboveCB->setChecked(false);
763                 firstheaderBorderBelowCB->setChecked(false);
764                 firstheaderNoContentsCB->setChecked(false);
765                 footerStatusCB->setChecked(false);
766                 footerBorderAboveCB->setChecked(false);
767                 footerBorderBelowCB->setChecked(false);
768                 lastfooterStatusCB->setChecked(false);
769                 lastfooterBorderAboveCB->setChecked(false);
770                 lastfooterBorderBelowCB->setChecked(false);
771                 lastfooterNoContentsCB->setChecked(false);
772                 newpageCB->setChecked(false);
773                 newpageCB->setEnabled(false);
774                 return;
775         }
776
777         Tabular::ltType ltt;
778         bool use_empty;
779         bool row_set = tabular_.getRowOfLTHead(row, ltt);
780         headerStatusCB->setChecked(row_set);
781         if (ltt.set) {
782                 headerBorderAboveCB->setChecked(ltt.topDL);
783                 headerBorderBelowCB->setChecked(ltt.bottomDL);
784                 use_empty = true;
785         } else {
786                 headerBorderAboveCB->setChecked(false);
787                 headerBorderBelowCB->setChecked(false);
788                 headerBorderAboveCB->setEnabled(false);
789                 headerBorderBelowCB->setEnabled(false);
790                 firstheaderNoContentsCB->setChecked(false);
791                 firstheaderNoContentsCB->setEnabled(false);
792                 use_empty = false;
793         }
794
795         row_set = tabular_.getRowOfLTFirstHead(row, ltt);
796         firstheaderStatusCB->setChecked(row_set);
797         if (ltt.set && (!ltt.empty || !use_empty)) {
798                 firstheaderBorderAboveCB->setChecked(ltt.topDL);
799                 firstheaderBorderBelowCB->setChecked(ltt.bottomDL);
800         } else {
801                 firstheaderBorderAboveCB->setEnabled(false);
802                 firstheaderBorderBelowCB->setEnabled(false);
803                 firstheaderBorderAboveCB->setChecked(false);
804                 firstheaderBorderBelowCB->setChecked(false);
805                 if (use_empty) {
806                         firstheaderNoContentsCB->setChecked(ltt.empty);
807                         if (ltt.empty)
808                                 firstheaderStatusCB->setEnabled(false);
809                 }
810         }
811
812         row_set = tabular_.getRowOfLTFoot(row, ltt);
813         footerStatusCB->setChecked(row_set);
814         if (ltt.set) {
815                 footerBorderAboveCB->setChecked(ltt.topDL);
816                 footerBorderBelowCB->setChecked(ltt.bottomDL);
817                 use_empty = true;
818         } else {
819                 footerBorderAboveCB->setChecked(false);
820                 footerBorderBelowCB->setChecked(false);
821                 footerBorderAboveCB->setEnabled(false);
822                 footerBorderBelowCB->setEnabled(false);
823                 lastfooterNoContentsCB->setChecked(false);
824                 lastfooterNoContentsCB->setEnabled(false);
825                 use_empty = false;
826         }
827
828         row_set = tabular_.getRowOfLTLastFoot(row, ltt);
829                 lastfooterStatusCB->setChecked(row_set);
830         if (ltt.set && (!ltt.empty || !use_empty)) {
831                 lastfooterBorderAboveCB->setChecked(ltt.topDL);
832                 lastfooterBorderBelowCB->setChecked(ltt.bottomDL);
833         } else {
834                 lastfooterBorderAboveCB->setEnabled(false);
835                 lastfooterBorderBelowCB->setEnabled(false);
836                 lastfooterBorderAboveCB->setChecked(false);
837                 lastfooterBorderBelowCB->setChecked(false);
838                 if (use_empty) {
839                         lastfooterNoContentsCB->setChecked(ltt.empty);
840                         if (ltt.empty)
841                                 lastfooterStatusCB->setEnabled(false);
842                 }
843         }
844         newpageCB->setChecked(tabular_.getLTNewPage(row));
845 }
846
847
848 void GuiTabular::closeGUI()
849 {
850         // ugly hack to auto-apply the stuff that hasn't been
851         // yet. don't let this continue to exist ...
852
853         // Subtle here, we must /not/ apply any changes and
854         // then refer to tabular, as it will have been freed
855         // since the changes update the actual tabular_
856         //
857         // apply the fixed width values
858         size_t const cell = getActiveCell();
859         bool const multicol = tabular_.isMultiColumn(cell);
860         string width = widgetsToLength(widthED, widthUnit);
861         string width2;
862
863         Length llen = getColumnPWidth(tabular_, cell);
864         Length llenMulti = getMColumnPWidth(tabular_, cell);
865
866         if (multicol && !llenMulti.zero())
867                 width2 = llenMulti.asString();
868         else if (!multicol && !llen.zero())
869                 width2 = llen.asString();
870
871         // apply the special alignment
872         docstring const sa1 = qstring_to_ucs4(specialAlignmentED->text());
873         docstring sa2;
874
875         if (multicol)
876                 sa2 = getAlignSpecial(tabular_, cell, Tabular::SET_SPECIAL_MULTI);
877         else
878                 sa2 = getAlignSpecial(tabular_, cell, Tabular::SET_SPECIAL_COLUMN);
879
880         if (sa1 != sa2) {
881                 if (multicol)
882                         set(Tabular::SET_SPECIAL_MULTI, to_utf8(sa1));
883                 else
884                         set(Tabular::SET_SPECIAL_COLUMN, to_utf8(sa1));
885         }
886
887         if (width != width2) {
888                 if (multicol)
889                         set(Tabular::SET_MPWIDTH, width);
890                 else
891                         set(Tabular::SET_PWIDTH, width);
892         }
893
894         /* DO WE NEED THIS?
895         switch (topspaceCO->currentIndex()) {
896                 case 0:
897                         set(Tabular::SET_TOP_SPACE, "");
898                         break;
899                 case 1:
900                         set(Tabular::SET_TOP_SPACE, "default");
901                         break;
902                 case 2:
903                         set(Tabular::SET_TOP_SPACE,
904                                 widgetsToLength(topspaceED, topspaceUnit));
905                         break;
906         }
907
908         switch (bottomspaceCO->currentIndex()) {
909                 case 0:
910                         set(Tabular::SET_BOTTOM_SPACE, "");
911                         break;
912                 case 1:
913                         set(Tabular::SET_BOTTOM_SPACE, "default");
914                         break;
915                 case 2:
916                         set(Tabular::SET_BOTTOM_SPACE,
917                                 widgetsToLength(bottomspaceED, bottomspaceUnit));
918                         break;
919         }
920
921         switch (interlinespaceCO->currentIndex()) {
922                 case 0:
923                         set(Tabular::SET_INTERLINE_SPACE, "");
924                         break;
925                 case 1:
926                         set(Tabular::SET_INTERLINE_SPACE, "default");
927                         break;
928                 case 2:
929                         set(Tabular::SET_INTERLINE_SPACE,
930                                 widgetsToLength(interlinespaceED, interlinespaceUnit));
931                         break;
932         }
933 */
934 }
935
936
937 bool GuiTabular::initialiseParams(string const & data)
938 {
939         // try to get the current cell
940         BufferView const * const bv = bufferview();
941         InsetTabular const * current_inset = 0;
942         if (bv) {
943                 Cursor const & cur = bv->cursor();
944                 // get the innermost tabular inset;
945                 // assume that it is "ours"
946                 for (int i = cur.depth() - 1; i >= 0; --i)
947                         if (cur[i].inset().lyxCode() == TABULAR_CODE) {
948                                 current_inset = static_cast<InsetTabular const *>(&cur[i].inset());
949                                 active_cell_ = cur[i].idx();
950                                 break;
951                         }
952         }
953
954         if (current_inset && data.empty()) {
955                 tabular_ = Tabular(current_inset->tabular);
956                 return true;
957         }
958
959         InsetTabular tmp(buffer());
960         InsetTabular::string2params(data, tmp);
961         tabular_ = Tabular(tmp.tabular);
962         return true;
963 }
964
965
966 void GuiTabular::clearParams()
967 {
968         InsetTabular tmp(buffer());
969         tabular_ = tmp.tabular;
970         active_cell_ = Tabular::npos;
971 }
972
973
974 Tabular::idx_type GuiTabular::getActiveCell() const
975 {
976         return active_cell_;
977 }
978
979
980 void GuiTabular::set(Tabular::Feature f, string const & arg)
981 {
982         string const data = featureAsString(f) + ' ' + arg;
983         dispatch(FuncRequest(getLfun(), data));
984 }
985
986
987 bool GuiTabular::useMetricUnits() const
988 {
989         return lyxrc.default_papersize > PAPER_USEXECUTIVE;
990 }
991
992
993 void GuiTabular::setSpecial(string const & special)
994 {
995         if (tabular_.isMultiColumn(getActiveCell()))
996                 set(Tabular::SET_SPECIAL_MULTI, special);
997         else
998                 set(Tabular::SET_SPECIAL_COLUMN, special);
999 }
1000
1001
1002 void GuiTabular::setWidth(string const & width)
1003 {
1004         if (tabular_.isMultiColumn(getActiveCell()))
1005                 set(Tabular::SET_MPWIDTH, width);
1006         else
1007                 set(Tabular::SET_PWIDTH, width);
1008
1009         updateView();
1010 }
1011
1012
1013 void GuiTabular::toggleMultiColumn()
1014 {
1015         set(Tabular::MULTICOLUMN);
1016         updateView();
1017 }
1018
1019
1020 void GuiTabular::rotateTabular(bool yes)
1021 {
1022         if (yes)
1023                 set(Tabular::SET_ROTATE_TABULAR);
1024         else
1025                 set(Tabular::UNSET_ROTATE_TABULAR);
1026 }
1027
1028
1029 void GuiTabular::rotateCell(bool yes)
1030 {
1031         if (yes)
1032                 set(Tabular::SET_ROTATE_CELL);
1033         else
1034                 set(Tabular::UNSET_ROTATE_CELL);
1035 }
1036
1037
1038 void GuiTabular::halign(GuiTabular::HALIGN h)
1039 {
1040         Tabular::Feature num = Tabular::ALIGN_LEFT;
1041         Tabular::Feature multi_num = Tabular::M_ALIGN_LEFT;
1042
1043         switch (h) {
1044                 case LEFT:
1045                         num = Tabular::ALIGN_LEFT;
1046                         multi_num = Tabular::M_ALIGN_LEFT;
1047                         break;
1048                 case CENTER:
1049                         num = Tabular::ALIGN_CENTER;
1050                         multi_num = Tabular::M_ALIGN_CENTER;
1051                         break;
1052                 case RIGHT:
1053                         num = Tabular::ALIGN_RIGHT;
1054                         multi_num = Tabular::M_ALIGN_RIGHT;
1055                         break;
1056                 case BLOCK:
1057                         num = Tabular::ALIGN_BLOCK;
1058                         //multi_num: no equivalent
1059                         break;
1060         }
1061
1062         if (tabular_.isMultiColumn(getActiveCell()))
1063                 set(multi_num);
1064         else
1065                 set(num);
1066 }
1067
1068
1069 void GuiTabular::valign(GuiTabular::VALIGN v)
1070 {
1071         Tabular::Feature num = Tabular::VALIGN_MIDDLE;
1072         Tabular::Feature multi_num = Tabular::M_VALIGN_MIDDLE;
1073
1074         switch (v) {
1075                 case TOP:
1076                         num = Tabular::VALIGN_TOP;
1077                         multi_num = Tabular::M_VALIGN_TOP;
1078                         break;
1079                 case MIDDLE:
1080                         num = Tabular::VALIGN_MIDDLE;
1081                         multi_num = Tabular::M_VALIGN_MIDDLE;
1082                         break;
1083                 case BOTTOM:
1084                         num = Tabular::VALIGN_BOTTOM;
1085                         multi_num = Tabular::M_VALIGN_BOTTOM;
1086                         break;
1087         }
1088
1089         if (tabular_.isMultiColumn(getActiveCell()))
1090                 set(multi_num);
1091         else
1092                 set(num);
1093 }
1094
1095
1096 void GuiTabular::booktabs(bool yes)
1097 {
1098         if (yes)
1099                 set(Tabular::SET_BOOKTABS);
1100         else
1101                 set(Tabular::UNSET_BOOKTABS);
1102 }
1103
1104
1105 void GuiTabular::longTabular(bool yes)
1106 {
1107         if (yes)
1108                 set(Tabular::SET_LONGTABULAR);
1109         else
1110                 set(Tabular::UNSET_LONGTABULAR);
1111 }
1112
1113
1114 Dialog * createGuiTabular(GuiView & lv) { return new GuiTabular(lv); }
1115
1116
1117 } // namespace frontend
1118 } // namespace lyx
1119
1120 #include "GuiTabular_moc.cpp"