]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiTabular.cpp
Complete the removal of the embedding stuff. Maybe. It's hard to be sure we got every...
[lyx.git] / src / frontends / qt4 / GuiTabular.cpp
index c0245043518ce292867cd1098a973b9a5a149650..54bf939037bd88f11b21e32ea349362c772ab9bf 100644 (file)
 
 #include "GuiTabular.h"
 
+#include "BufferView.h"
+#include "Cursor.h"
+#include "FuncRequest.h"
 #include "GuiSetBorder.h"
 #include "LengthCombo.h"
-#include "Validator.h"
+#include "LyXRC.h"
 #include "qt_helpers.h"
+#include "Validator.h"
 
-#include "support/convert.h"
+#include "insets/InsetTabular.h"
 
-#include <QCloseEvent>
 #include <QCheckBox>
 #include <QPushButton>
 #include <QRadioButton>
 #include <QLineEdit>
 
-using std::string;
+using namespace std;
 
 namespace lyx {
 namespace frontend {
 
-/////////////////////////////////////////////////////////////////////
-//
-// GuiTabularDialog
-//
-/////////////////////////////////////////////////////////////////////
-
-GuiTabularDialog::GuiTabularDialog(GuiTabular * form)
-       : form_(form)
+GuiTabular::GuiTabular(GuiView & lv)
+       : GuiDialog(lv, "tabular", qt_("Table Settings"))
 {
+       active_cell_ = Tabular::npos;
+
        setupUi(this);
 
        widthED->setValidator(unsignedLengthValidator(widthED));
@@ -98,549 +97,492 @@ GuiTabularDialog::GuiTabularDialog(GuiTabular * form)
        connect(rotateTabularCB, SIGNAL(clicked()), this, SLOT(rotateTabular()));
        connect(rotateCellCB, SIGNAL(clicked()), this, SLOT(rotateCell()));
        connect(longTabularCB, SIGNAL(clicked()), this, SLOT(longTabular()));
+
+       bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
+       bc().setCancel(closePB);
+
+       bc().addReadOnly(topspaceED);
+       bc().addReadOnly(topspaceUnit);
+       bc().addReadOnly(topspaceCO);
+       bc().addReadOnly(bottomspaceED);
+       bc().addReadOnly(bottomspaceUnit);
+       bc().addReadOnly(bottomspaceCO);
+       bc().addReadOnly(interlinespaceED);
+       bc().addReadOnly(interlinespaceUnit);
+       bc().addReadOnly(interlinespaceCO);
+       bc().addReadOnly(borderDefaultRB);
+       bc().addReadOnly(booktabsRB);
+
+       bc().addReadOnly(multicolumnCB);
+       bc().addReadOnly(rotateCellCB);
+       bc().addReadOnly(rotateTabularCB);
+       bc().addReadOnly(specialAlignmentED);
+       bc().addReadOnly(widthED);
+       bc().addReadOnly(widthUnit);
+       bc().addReadOnly(hAlignCB);
+       bc().addReadOnly(vAlignCB);
+       bc().addReadOnly(borderSetPB);
+       bc().addReadOnly(borderUnsetPB);
+       bc().addReadOnly(borders);
+       bc().addReadOnly(longTabularCB);
+       bc().addReadOnly(headerStatusCB);
+       bc().addReadOnly(headerBorderAboveCB);
+       bc().addReadOnly(headerBorderBelowCB);
+       bc().addReadOnly(firstheaderStatusCB);
+       bc().addReadOnly(firstheaderBorderAboveCB);
+       bc().addReadOnly(firstheaderBorderBelowCB);
+       bc().addReadOnly(firstheaderNoContentsCB);
+       bc().addReadOnly(footerStatusCB);
+       bc().addReadOnly(footerBorderAboveCB);
+       bc().addReadOnly(footerBorderBelowCB);
+       bc().addReadOnly(lastfooterStatusCB);
+       bc().addReadOnly(lastfooterBorderAboveCB);
+       bc().addReadOnly(lastfooterBorderBelowCB);
+       bc().addReadOnly(lastfooterNoContentsCB);
+       bc().addReadOnly(newpageCB);
+
+       // initialize the length validator
+       bc().addCheckedLineEdit(widthED, fixedWidthColLA);
+       bc().addCheckedLineEdit(topspaceED, topspaceLA);
+       bc().addCheckedLineEdit(bottomspaceED, bottomspaceLA);
+       bc().addCheckedLineEdit(interlinespaceED, interlinespaceLA);
 }
 
 
-void GuiTabularDialog::change_adaptor()
+GuiTabular::~GuiTabular()
 {
-       form_->changed();
 }
 
 
-void GuiTabularDialog::closeEvent(QCloseEvent * e)
+void GuiTabular::change_adaptor()
 {
-       form_->slotWMHide();
-       e->accept();
+       changed();
 }
 
 
-void GuiTabularDialog::booktabsChanged(bool)
+void GuiTabular::booktabsChanged(bool)
 {
-       form_->changed();
-       form_->controller().booktabs(booktabsRB->isChecked());
-       form_->update_borders();
+       changed();
+       booktabs(booktabsRB->isChecked());
+       update_borders();
 }
 
 
-void GuiTabularDialog::topspace_changed()
+void GuiTabular::topspace_changed()
 {
-       switch(topspaceCO->currentIndex()) {
+       switch (topspaceCO->currentIndex()) {
                case 0: {
-                       form_->controller().set(Tabular::SET_TOP_SPACE, "");
-                               topspaceED->setEnabled(false);
-                               topspaceUnit->setEnabled(false);
+                       set(Tabular::SET_TOP_SPACE, "");
+                       topspaceED->setEnabled(false);
+                       topspaceUnit->setEnabled(false);
                        break;
                }
                case 1: {
-                       form_->controller().set(Tabular::SET_TOP_SPACE, "default");
+                       set(Tabular::SET_TOP_SPACE, "default");
                        topspaceED->setEnabled(false);
                        topspaceUnit->setEnabled(false);
                        break;
                }
                case 2: {
                        if (!topspaceED->text().isEmpty())
-                               form_->controller().set(Tabular::SET_TOP_SPACE,
+                               set(Tabular::SET_TOP_SPACE,
                                        widgetsToLength(topspaceED, topspaceUnit));
-                       if (!form_->bc().policy().isReadOnly()) {
+                       if (!bc().policy().isReadOnly()) {
                                topspaceED->setEnabled(true);
                                topspaceUnit->setEnabled(true);
                        }
                        break;
                }
        }
-       form_->changed();
+       changed();
 }
 
 
-void GuiTabularDialog::bottomspace_changed()
+void GuiTabular::bottomspace_changed()
 {
-       switch(bottomspaceCO->currentIndex()) {
+       switch (bottomspaceCO->currentIndex()) {
                case 0: {
-                       form_->controller().set(Tabular::SET_BOTTOM_SPACE, "");
+                       set(Tabular::SET_BOTTOM_SPACE, "");
                                bottomspaceED->setEnabled(false);
                                bottomspaceUnit->setEnabled(false);
                        break;
                }
                case 1: {
-                       form_->controller().set(Tabular::SET_BOTTOM_SPACE, "default");
+                       set(Tabular::SET_BOTTOM_SPACE, "default");
                        bottomspaceED->setEnabled(false);
                        bottomspaceUnit->setEnabled(false);
                        break;
                }
                case 2: {
                        if (!bottomspaceED->text().isEmpty())
-                               form_->controller().set(Tabular::SET_BOTTOM_SPACE,
+                               set(Tabular::SET_BOTTOM_SPACE,
                                        widgetsToLength(bottomspaceED, bottomspaceUnit));
-                       if (!form_->bc().policy().isReadOnly()) {
+                       if (!bc().policy().isReadOnly()) {
                                bottomspaceED->setEnabled(true);
                                bottomspaceUnit->setEnabled(true);
                        }
                        break;
                }
        }
-       form_->changed();
+       changed();
 }
 
 
-void GuiTabularDialog::interlinespace_changed()
+void GuiTabular::interlinespace_changed()
 {
-       switch(interlinespaceCO->currentIndex()) {
+       switch (interlinespaceCO->currentIndex()) {
                case 0: {
-                       form_->controller().set(Tabular::SET_INTERLINE_SPACE, "");
+                       set(Tabular::SET_INTERLINE_SPACE, "");
                                interlinespaceED->setEnabled(false);
                                interlinespaceUnit->setEnabled(false);
                        break;
                }
                case 1: {
-                       form_->controller().set(Tabular::SET_INTERLINE_SPACE, "default");
+                       set(Tabular::SET_INTERLINE_SPACE, "default");
                        interlinespaceED->setEnabled(false);
                        interlinespaceUnit->setEnabled(false);
                        break;
                }
                case 2: {
                        if (!interlinespaceED->text().isEmpty())
-                               form_->controller().set(Tabular::SET_INTERLINE_SPACE,
+                               set(Tabular::SET_INTERLINE_SPACE,
                                        widgetsToLength(interlinespaceED, interlinespaceUnit));
-                       if (!form_->bc().policy().isReadOnly()) {
+                       if (!bc().policy().isReadOnly()) {
                                interlinespaceED->setEnabled(true);
                                interlinespaceUnit->setEnabled(true);
                        }
                        break;
                }
        }
-       form_->changed();
+       changed();
 }
 
 
-void GuiTabularDialog::close_clicked()
+void GuiTabular::close_clicked()
 {
-       form_->closeGUI();
-       form_->slotClose();
+       closeGUI();
+       slotClose();
 }
 
 
-void GuiTabularDialog::borderSet_clicked()
+void GuiTabular::borderSet_clicked()
 {
-       form_->controller().set(Tabular::SET_ALL_LINES);
-       form_->update_borders();
-       form_->changed();
+       set(Tabular::SET_ALL_LINES);
+       update_borders();
+       changed();
 }
 
 
-void GuiTabularDialog::borderUnset_clicked()
+void GuiTabular::borderUnset_clicked()
 {
-       form_->controller().set(Tabular::UNSET_ALL_LINES);
-       form_->update_borders();
-       form_->changed();
+       set(Tabular::UNSET_ALL_LINES);
+       update_borders();
+       changed();
 }
 
 
-void GuiTabularDialog::leftBorder_changed()
+void GuiTabular::leftBorder_changed()
 {
-       form_->controller().toggleLeftLine();
-       form_->changed();
+       set(Tabular::TOGGLE_LINE_LEFT);
+       changed();
 }
 
 
-void GuiTabularDialog::rightBorder_changed()
+void GuiTabular::rightBorder_changed()
 {
-       form_->controller().toggleRightLine();
-       form_->changed();
+       set(Tabular::TOGGLE_LINE_RIGHT);
+       changed();
 }
 
 
-void GuiTabularDialog::topBorder_changed()
+void GuiTabular::topBorder_changed()
 {
-       form_->controller().toggleTopLine();
-       form_->changed();
+       set(Tabular::TOGGLE_LINE_TOP);
+       changed();
 }
 
 
-void GuiTabularDialog::bottomBorder_changed()
+void GuiTabular::bottomBorder_changed()
 {
-       form_->controller().toggleBottomLine();
-       form_->changed();
+       set(Tabular::TOGGLE_LINE_BOTTOM);
+       changed();
 }
 
 
-void GuiTabularDialog::specialAlignment_changed()
+void GuiTabular::specialAlignment_changed()
 {
        string special = fromqstr(specialAlignmentED->text());
-       form_->controller().setSpecial(special);
-       form_->changed();
+       setSpecial(special);
+       changed();
 }
 
 
-void GuiTabularDialog::width_changed()
+void GuiTabular::width_changed()
 {
-       form_->changed();
+       changed();
        string const width = widgetsToLength(widthED, widthUnit);
-       form_->controller().setWidth(width);
+       setWidth(width);
 }
 
 
-void GuiTabularDialog::multicolumn_clicked()
+void GuiTabular::multicolumn_clicked()
 {
-       form_->controller().toggleMultiColumn();
-       form_->changed();
+       toggleMultiColumn();
+       changed();
 }
 
 
-void GuiTabularDialog::rotateTabular()
+void GuiTabular::rotateTabular()
 {
-       form_->controller().rotateTabular(rotateTabularCB->isChecked());
-       form_->changed();
+       rotateTabular(rotateTabularCB->isChecked());
+       changed();
 }
 
 
-void GuiTabularDialog::rotateCell()
+void GuiTabular::rotateCell()
 {
-       form_->controller().rotateCell(rotateCellCB->isChecked());
-       form_->changed();
+       rotateCell(rotateCellCB->isChecked());
+       changed();
 }
 
 
-void GuiTabularDialog::hAlign_changed(int align)
+void GuiTabular::hAlign_changed(int align)
 {
-       ControlTabular::HALIGN h = ControlTabular::LEFT;
+       GuiTabular::HALIGN h = GuiTabular::LEFT;
 
        switch (align) {
-               case 0: h = ControlTabular::LEFT; break;
-               case 1: h = ControlTabular::CENTER; break;
-               case 2: h = ControlTabular::RIGHT; break;
-               case 3: h = ControlTabular::BLOCK; break;
+               case 0: h = GuiTabular::LEFT; break;
+               case 1: h = GuiTabular::CENTER; break;
+               case 2: h = GuiTabular::RIGHT; break;
+               case 3: h = GuiTabular::BLOCK; break;
        }
 
-       form_->controller().halign(h);
+       halign(h);
 }
 
 
-void GuiTabularDialog::vAlign_changed(int align)
+void GuiTabular::vAlign_changed(int align)
 {
-       ControlTabular::VALIGN v = ControlTabular::TOP;
+       GuiTabular::VALIGN v = GuiTabular::TOP;
 
        switch (align) {
-               case 0: v = ControlTabular::TOP; break;
-               case 1: v = ControlTabular::MIDDLE; break;
-               case 2: v = ControlTabular::BOTTOM; break;
+               case 0: v = GuiTabular::TOP; break;
+               case 1: v = GuiTabular::MIDDLE; break;
+               case 2: v = GuiTabular::BOTTOM; break;
        }
 
-       form_->controller().valign(v);
+       valign(v);
 }
 
 
-void GuiTabularDialog::longTabular()
+void GuiTabular::longTabular()
 {
-       form_->controller().longTabular(longTabularCB->isChecked());
-       form_->changed();
+       longTabular(longTabularCB->isChecked());
+       changed();
 }
 
 
-void GuiTabularDialog::ltNewpage_clicked()
+void GuiTabular::ltNewpage_clicked()
 {
-       form_->controller().set(Tabular::SET_LTNEWPAGE);
-       form_->changed();
+       set(Tabular::SET_LTNEWPAGE);
+       changed();
 }
 
 
-void GuiTabularDialog::ltHeaderStatus_clicked()
+void GuiTabular::ltHeaderStatus_clicked()
 {
-       bool enable(headerStatusCB->isChecked());
+       bool enable = headerStatusCB->isChecked();
        if (enable)
-               form_->controller().set(Tabular::SET_LTHEAD, "");
+               set(Tabular::SET_LTHEAD, "");
        else
-               form_->controller().set(Tabular::UNSET_LTHEAD, "");
+               set(Tabular::UNSET_LTHEAD, "");
        headerBorderAboveCB->setEnabled(enable);
        headerBorderBelowCB->setEnabled(enable);
        firstheaderNoContentsCB->setEnabled(enable);
-       form_->changed();
+       changed();
 }
 
 
-void GuiTabularDialog::ltHeaderBorderAbove_clicked()
+void GuiTabular::ltHeaderBorderAbove_clicked()
 {
        if (headerBorderAboveCB->isChecked())
-               form_->controller().set(Tabular::SET_LTHEAD, "dl_above");
+               set(Tabular::SET_LTHEAD, "dl_above");
        else
-               form_->controller().set(Tabular::UNSET_LTHEAD, "dl_above");
-       form_->changed();
+               set(Tabular::UNSET_LTHEAD, "dl_above");
+       changed();
 }
 
 
-void GuiTabularDialog::ltHeaderBorderBelow_clicked()
+void GuiTabular::ltHeaderBorderBelow_clicked()
 {
        if (headerBorderBelowCB->isChecked())
-               form_->controller().set(Tabular::SET_LTHEAD, "dl_below");
+               set(Tabular::SET_LTHEAD, "dl_below");
        else
-               form_->controller().set(Tabular::UNSET_LTHEAD, "dl_below");
-       form_->changed();
+               set(Tabular::UNSET_LTHEAD, "dl_below");
+       changed();
 }
 
 
-void GuiTabularDialog::ltFirstHeaderBorderAbove_clicked()
+void GuiTabular::ltFirstHeaderBorderAbove_clicked()
 {
        if (firstheaderBorderAboveCB->isChecked())
-               form_->controller().set(Tabular::SET_LTFIRSTHEAD, "dl_above");
+               set(Tabular::SET_LTFIRSTHEAD, "dl_above");
        else
-               form_->controller().set(Tabular::UNSET_LTFIRSTHEAD, "dl_above");
-       form_->changed();
+               set(Tabular::UNSET_LTFIRSTHEAD, "dl_above");
+       changed();
 }
 
 
-void GuiTabularDialog::ltFirstHeaderBorderBelow_clicked()
+void GuiTabular::ltFirstHeaderBorderBelow_clicked()
 {
        if (firstheaderBorderBelowCB->isChecked())
-               form_->controller().set(Tabular::SET_LTFIRSTHEAD, "dl_below");
+               set(Tabular::SET_LTFIRSTHEAD, "dl_below");
        else
-               form_->controller().set(Tabular::UNSET_LTFIRSTHEAD, "dl_below");
-       form_->changed();
+               set(Tabular::UNSET_LTFIRSTHEAD, "dl_below");
+       changed();
 }
 
 
-void GuiTabularDialog::ltFirstHeaderStatus_clicked()
+void GuiTabular::ltFirstHeaderStatus_clicked()
 {
-       bool enable(firstheaderStatusCB->isChecked());
+       bool enable = firstheaderStatusCB->isChecked();
        if (enable)
-               form_->controller().set(Tabular::SET_LTFIRSTHEAD, "");
+               set(Tabular::SET_LTFIRSTHEAD, "");
        else
-               form_->controller().set(Tabular::UNSET_LTFIRSTHEAD, "");
+               set(Tabular::UNSET_LTFIRSTHEAD, "");
        firstheaderBorderAboveCB->setEnabled(enable);
        firstheaderBorderBelowCB->setEnabled(enable);
-       form_->changed();
+       changed();
 }
 
 
-void GuiTabularDialog::ltFirstHeaderEmpty_clicked()
+void GuiTabular::ltFirstHeaderEmpty_clicked()
 {
-       bool enable(firstheaderNoContentsCB->isChecked());
+       bool enable = firstheaderNoContentsCB->isChecked();
        if (enable)
-               form_->controller().set(Tabular::SET_LTFIRSTHEAD, "empty");
+               set(Tabular::SET_LTFIRSTHEAD, "empty");
        else
-               form_->controller().set(Tabular::UNSET_LTFIRSTHEAD, "empty");
+               set(Tabular::UNSET_LTFIRSTHEAD, "empty");
        firstheaderStatusCB->setEnabled(!enable);
        firstheaderBorderAboveCB->setEnabled(!enable);
        firstheaderBorderBelowCB->setEnabled(!enable);
-       form_->changed();
+       changed();
 }
 
 
-void GuiTabularDialog::ltFooterStatus_clicked()
+void GuiTabular::ltFooterStatus_clicked()
 {
-       bool enable(footerStatusCB->isChecked());
+       bool enable = footerStatusCB->isChecked();
        if (enable)
-               form_->controller().set(Tabular::SET_LTFOOT, "");
+               set(Tabular::SET_LTFOOT, "");
        else
-               form_->controller().set(Tabular::UNSET_LTFOOT, "");
+               set(Tabular::UNSET_LTFOOT, "");
        footerBorderAboveCB->setEnabled(enable);
        footerBorderBelowCB->setEnabled(enable);
        lastfooterNoContentsCB->setEnabled(enable);
-       form_->changed();
+       changed();
 }
 
 
-void GuiTabularDialog::ltFooterBorderAbove_clicked()
+void GuiTabular::ltFooterBorderAbove_clicked()
 {
        if (footerBorderAboveCB->isChecked())
-               form_->controller().set(Tabular::SET_LTFOOT, "dl_above");
+               set(Tabular::SET_LTFOOT, "dl_above");
        else
-               form_->controller().set(Tabular::UNSET_LTFOOT, "dl_above");
-       form_->changed();
+               set(Tabular::UNSET_LTFOOT, "dl_above");
+       changed();
 }
 
 
-void GuiTabularDialog::ltFooterBorderBelow_clicked()
+void GuiTabular::ltFooterBorderBelow_clicked()
 {
        if (footerBorderBelowCB->isChecked())
-               form_->controller().set(Tabular::SET_LTFOOT, "dl_below");
+               set(Tabular::SET_LTFOOT, "dl_below");
        else
-               form_->controller().set(Tabular::UNSET_LTFOOT, "dl_below");
-       form_->changed();
+               set(Tabular::UNSET_LTFOOT, "dl_below");
+       changed();
 }
 
 
-void GuiTabularDialog::ltLastFooterStatus_clicked()
+void GuiTabular::ltLastFooterStatus_clicked()
 {
-       bool enable(lastfooterStatusCB->isChecked());
+       bool enable = lastfooterStatusCB->isChecked();
        if (enable)
-               form_->controller().set(Tabular::SET_LTLASTFOOT, "");
+               set(Tabular::SET_LTLASTFOOT, "");
        else
-               form_->controller().set(Tabular::UNSET_LTLASTFOOT, "");
+               set(Tabular::UNSET_LTLASTFOOT, "");
        lastfooterBorderAboveCB->setEnabled(enable);
        lastfooterBorderBelowCB->setEnabled(enable);
-       form_->changed();
+       changed();
 }
 
 
-void GuiTabularDialog::ltLastFooterBorderAbove_clicked()
+void GuiTabular::ltLastFooterBorderAbove_clicked()
 {
        if (lastfooterBorderAboveCB->isChecked())
-               form_->controller().set(Tabular::SET_LTLASTFOOT, "dl_above");
+               set(Tabular::SET_LTLASTFOOT, "dl_above");
        else
-               form_->controller().set(Tabular::UNSET_LTLASTFOOT, "dl_above");
-       form_->changed();
+               set(Tabular::UNSET_LTLASTFOOT, "dl_above");
+       changed();
 }
 
 
-void GuiTabularDialog::ltLastFooterBorderBelow_clicked()
+void GuiTabular::ltLastFooterBorderBelow_clicked()
 {
        if (lastfooterBorderBelowCB->isChecked())
-               form_->controller().set(Tabular::SET_LTLASTFOOT, "dl_below");
+               set(Tabular::SET_LTLASTFOOT, "dl_below");
        else
-               form_->controller().set(Tabular::UNSET_LTLASTFOOT, "dl_below");
-       form_->changed();
+               set(Tabular::UNSET_LTLASTFOOT, "dl_below");
+       changed();
 }
 
 
-void GuiTabularDialog::ltLastFooterEmpty_clicked()
+void GuiTabular::ltLastFooterEmpty_clicked()
 {
-       bool enable(lastfooterNoContentsCB->isChecked());
+       bool enable = lastfooterNoContentsCB->isChecked();
        if (enable)
-               form_->controller().set(Tabular::SET_LTLASTFOOT, "empty");
+               set(Tabular::SET_LTLASTFOOT, "empty");
        else
-               form_->controller().set(Tabular::UNSET_LTLASTFOOT, "empty");
+               set(Tabular::UNSET_LTLASTFOOT, "empty");
        lastfooterStatusCB->setEnabled(!enable);
        lastfooterBorderAboveCB->setEnabled(!enable);
        lastfooterBorderBelowCB->setEnabled(!enable);
-       form_->changed();
-}
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// GuiTabular
-//
-/////////////////////////////////////////////////////////////////////
-
-
-GuiTabular::GuiTabular(GuiDialog & parent)
-       : GuiView<GuiTabularDialog>(parent, _("Table Settings"))
-{
-}
-
-
-void GuiTabular::build_dialog()
-{
-       dialog_.reset(new GuiTabularDialog(this));
-
-       bc().setCancel(dialog_->closePB);
-
-       bc().addReadOnly(dialog_->topspaceED);
-       bc().addReadOnly(dialog_->topspaceUnit);
-       bc().addReadOnly(dialog_->topspaceCO);
-       bc().addReadOnly(dialog_->bottomspaceED);
-       bc().addReadOnly(dialog_->bottomspaceUnit);
-       bc().addReadOnly(dialog_->bottomspaceCO);
-       bc().addReadOnly(dialog_->interlinespaceED);
-       bc().addReadOnly(dialog_->interlinespaceUnit);
-       bc().addReadOnly(dialog_->interlinespaceCO);
-       bc().addReadOnly(dialog_->borderDefaultRB);
-       bc().addReadOnly(dialog_->booktabsRB);
-
-       bc().addReadOnly(dialog_->multicolumnCB);
-       bc().addReadOnly(dialog_->rotateCellCB);
-       bc().addReadOnly(dialog_->rotateTabularCB);
-       bc().addReadOnly(dialog_->specialAlignmentED);
-       bc().addReadOnly(dialog_->widthED);
-       bc().addReadOnly(dialog_->widthUnit);
-       bc().addReadOnly(dialog_->hAlignCB);
-       bc().addReadOnly(dialog_->vAlignCB);
-       bc().addReadOnly(dialog_->borderSetPB);
-       bc().addReadOnly(dialog_->borderUnsetPB);
-       bc().addReadOnly(dialog_->borders);
-       bc().addReadOnly(dialog_->longTabularCB);
-       bc().addReadOnly(dialog_->headerStatusCB);
-       bc().addReadOnly(dialog_->headerBorderAboveCB);
-       bc().addReadOnly(dialog_->headerBorderBelowCB);
-       bc().addReadOnly(dialog_->firstheaderStatusCB);
-       bc().addReadOnly(dialog_->firstheaderBorderAboveCB);
-       bc().addReadOnly(dialog_->firstheaderBorderBelowCB);
-       bc().addReadOnly(dialog_->firstheaderNoContentsCB);
-       bc().addReadOnly(dialog_->footerStatusCB);
-       bc().addReadOnly(dialog_->footerBorderAboveCB);
-       bc().addReadOnly(dialog_->footerBorderBelowCB);
-       bc().addReadOnly(dialog_->lastfooterStatusCB);
-       bc().addReadOnly(dialog_->lastfooterBorderAboveCB);
-       bc().addReadOnly(dialog_->lastfooterBorderBelowCB);
-       bc().addReadOnly(dialog_->lastfooterNoContentsCB);
-       bc().addReadOnly(dialog_->newpageCB);
-
-       // initialize the length validator
-       bc().addCheckedLineEdit(dialog_->widthED, dialog_->fixedWidthColLA);
-       bc().addCheckedLineEdit(dialog_->topspaceED, dialog_->topspaceLA);
-       bc().addCheckedLineEdit(dialog_->bottomspaceED, dialog_->bottomspaceLA);
-       bc().addCheckedLineEdit(dialog_->interlinespaceED, dialog_->interlinespaceLA);
-}
-
-
-bool GuiTabular::isValid()
-{
-       return true;
+       changed();
 }
 
 
 void GuiTabular::update_borders()
 {
-       Tabular const & tabular = controller().tabular();
-       Tabular::idx_type const cell = controller().getActiveCell();
-       bool const isMulticolumnCell = tabular.isMultiColumn(cell);
-
-       if (!isMulticolumnCell) {
-               dialog_->borders->setLeftEnabled(true);
-               dialog_->borders->setRightEnabled(true);
-               dialog_->borders->setTop(tabular.topLine(cell, true));
-               dialog_->borders->setBottom(tabular.bottomLine(cell, true));
-               dialog_->borders->setLeft(tabular.leftLine(cell, true));
-               dialog_->borders->setRight(tabular.rightLine(cell, true));
-               // repaint the setborder widget
-               dialog_->borders->update();
-               return;
-       }
-
-       dialog_->borders->setTop(tabular.topLine(cell));
-       dialog_->borders->setBottom(tabular.bottomLine(cell));
-       // pay attention to left/right lines: they are only allowed
-       // to set if we are in first/last cell of row or if the left/right
-       // cell is also a multicolumn.
-       if (tabular.isFirstCellInRow(cell) || tabular.isMultiColumn(cell - 1)) {
-               dialog_->borders->setLeftEnabled(true);
-               dialog_->borders->setLeft(tabular.leftLine(cell));
-       } else {
-               dialog_->borders->setLeft(false);
-               dialog_->borders->setLeftEnabled(false);
-       }
-       if (tabular.isLastCellInRow(cell) || tabular.isMultiColumn(cell + 1)) {
-               dialog_->borders->setRightEnabled(true);
-               dialog_->borders->setRight(tabular.rightLine(cell));
-       } else {
-               dialog_->borders->setRight(false);
-               dialog_->borders->setRightEnabled(false);
-       }
+       Tabular::idx_type const cell = getActiveCell();
+       borders->setTop(tabular_.topLine(cell));
+       borders->setBottom(tabular_.bottomLine(cell));
+       borders->setLeft(tabular_.leftLine(cell));
+       borders->setRight(tabular_.rightLine(cell));
        // repaint the setborder widget
-       dialog_->borders->update();
+       borders->update();
 }
 
 
-void GuiTabular::update_contents()
+void GuiTabular::updateContents()
 {
-       controller().initialiseParams(string());
+       initialiseParams(string());
 
-       Tabular const & tabular(controller().tabular());
-       Tabular::idx_type const cell = controller().getActiveCell();
+       Tabular::idx_type const cell = getActiveCell();
 
-       Tabular::row_type const row(tabular.row_of_cell(cell));
-       Tabular::col_type const col(tabular.column_of_cell(cell));
+       Tabular::row_type const row = tabular_.cellRow(cell);
+       Tabular::col_type const col = tabular_.cellColumn(cell);
 
-       dialog_->tabularRowED->setText(toqstr(convert<string>(row + 1)));
-       dialog_->tabularColumnED->setText(toqstr(convert<string>(col + 1)));
+       tabularRowED->setText(QString::number(row + 1));
+       tabularColumnED->setText(QString::number(col + 1));
 
-       bool const multicol(tabular.isMultiColumn(cell));
+       bool const multicol(tabular_.isMultiColumn(cell));
 
-       dialog_->multicolumnCB->setChecked(multicol);
+       multicolumnCB->setChecked(multicol);
 
-       dialog_->rotateCellCB->setChecked(tabular.getRotateCell(cell));
-       dialog_->rotateTabularCB->setChecked(tabular.getRotateTabular());
+       rotateCellCB->setChecked(tabular_.getRotateCell(cell));
+       rotateTabularCB->setChecked(tabular_.getRotateTabular());
 
-       dialog_->longTabularCB->setChecked(tabular.isLongTabular());
+       longTabularCB->setChecked(tabular_.isLongTabular());
 
        update_borders();
 
@@ -648,96 +590,96 @@ void GuiTabular::update_contents()
        docstring special;
 
        if (multicol) {
-               special = tabular.getAlignSpecial(cell, Tabular::SET_SPECIAL_MULTI);
-               pwidth = tabular.getMColumnPWidth(cell);
+               special = tabular_.getAlignSpecial(cell, Tabular::SET_SPECIAL_MULTI);
+               pwidth = tabular_.getMColumnPWidth(cell);
        } else {
-               special = tabular.getAlignSpecial(cell, Tabular::SET_SPECIAL_COLUMN);
-               pwidth = tabular.getColumnPWidth(cell);
+               special = tabular_.getAlignSpecial(cell, Tabular::SET_SPECIAL_COLUMN);
+               pwidth = tabular_.getColumnPWidth(cell);
        }
 
-       dialog_->specialAlignmentED->setText(toqstr(special));
+       specialAlignmentED->setText(toqstr(special));
 
        bool const isReadonly = bc().policy().isReadOnly();
-       dialog_->specialAlignmentED->setEnabled(!isReadonly);
+       specialAlignmentED->setEnabled(!isReadonly);
 
        Length::UNIT default_unit =
-               controller().useMetricUnits() ? Length::CM : Length::IN;
+               useMetricUnits() ? Length::CM : Length::IN;
 
-       dialog_->borderDefaultRB->setChecked(!tabular.useBookTabs());
-       dialog_->booktabsRB->setChecked(tabular.useBookTabs());
+       borderDefaultRB->setChecked(!tabular_.useBookTabs());
+       booktabsRB->setChecked(tabular_.useBookTabs());
 
-       if (tabular.row_info[row].top_space.empty()
-           && !tabular.row_info[row].top_space_default) {
-               dialog_->topspaceCO->setCurrentIndex(0);
-       } else if (tabular.row_info[row].top_space_default) {
-               dialog_->topspaceCO->setCurrentIndex(1);
+       if (tabular_.row_info[row].top_space.empty()
+           && !tabular_.row_info[row].top_space_default) {
+               topspaceCO->setCurrentIndex(0);
+       } else if (tabular_.row_info[row].top_space_default) {
+               topspaceCO->setCurrentIndex(1);
        } else {
-               dialog_->topspaceCO->setCurrentIndex(2);
-               lengthToWidgets(dialog_->topspaceED,
-                               dialog_->topspaceUnit,
-                               tabular.row_info[row].top_space.asString(),
+               topspaceCO->setCurrentIndex(2);
+               lengthToWidgets(topspaceED,
+                               topspaceUnit,
+                               tabular_.row_info[row].top_space.asString(),
                                default_unit);
        }
-       dialog_->topspaceED->setEnabled(!isReadonly
-               && (dialog_->topspaceCO->currentIndex() == 2));
-       dialog_->topspaceUnit->setEnabled(!isReadonly
-               && (dialog_->topspaceCO->currentIndex() == 2));
-       dialog_->topspaceCO->setEnabled(!isReadonly);
-
-       if (tabular.row_info[row].bottom_space.empty()
-           && !tabular.row_info[row].bottom_space_default) {
-               dialog_->bottomspaceCO->setCurrentIndex(0);
-       } else if (tabular.row_info[row].bottom_space_default) {
-               dialog_->bottomspaceCO->setCurrentIndex(1);
+       topspaceED->setEnabled(!isReadonly
+               && (topspaceCO->currentIndex() == 2));
+       topspaceUnit->setEnabled(!isReadonly
+               && (topspaceCO->currentIndex() == 2));
+       topspaceCO->setEnabled(!isReadonly);
+
+       if (tabular_.row_info[row].bottom_space.empty()
+           && !tabular_.row_info[row].bottom_space_default) {
+               bottomspaceCO->setCurrentIndex(0);
+       } else if (tabular_.row_info[row].bottom_space_default) {
+               bottomspaceCO->setCurrentIndex(1);
        } else {
-               dialog_->bottomspaceCO->setCurrentIndex(2);
-               lengthToWidgets(dialog_->bottomspaceED,
-                               dialog_->bottomspaceUnit,
-                               tabular.row_info[row].bottom_space.asString(),
+               bottomspaceCO->setCurrentIndex(2);
+               lengthToWidgets(bottomspaceED,
+                               bottomspaceUnit,
+                               tabular_.row_info[row].bottom_space.asString(),
                                default_unit);
        }
-       dialog_->bottomspaceED->setEnabled(!isReadonly
-               && (dialog_->bottomspaceCO->currentIndex() == 2));
-       dialog_->bottomspaceUnit->setEnabled(!isReadonly
-               && (dialog_->bottomspaceCO->currentIndex() == 2));
-       dialog_->bottomspaceCO->setEnabled(!isReadonly);
-
-       if (tabular.row_info[row].interline_space.empty()
-           && !tabular.row_info[row].interline_space_default) {
-               dialog_->interlinespaceCO->setCurrentIndex(0);
-       } else if (tabular.row_info[row].interline_space_default) {
-               dialog_->interlinespaceCO->setCurrentIndex(1);
+       bottomspaceED->setEnabled(!isReadonly
+               && (bottomspaceCO->currentIndex() == 2));
+       bottomspaceUnit->setEnabled(!isReadonly
+               && (bottomspaceCO->currentIndex() == 2));
+       bottomspaceCO->setEnabled(!isReadonly);
+
+       if (tabular_.row_info[row].interline_space.empty()
+           && !tabular_.row_info[row].interline_space_default) {
+               interlinespaceCO->setCurrentIndex(0);
+       } else if (tabular_.row_info[row].interline_space_default) {
+               interlinespaceCO->setCurrentIndex(1);
        } else {
-               dialog_->interlinespaceCO->setCurrentIndex(2);
-               lengthToWidgets(dialog_->interlinespaceED,
-                               dialog_->interlinespaceUnit,
-                               tabular.row_info[row].interline_space.asString(),
+               interlinespaceCO->setCurrentIndex(2);
+               lengthToWidgets(interlinespaceED,
+                               interlinespaceUnit,
+                               tabular_.row_info[row].interline_space.asString(),
                                default_unit);
        }
-       dialog_->interlinespaceED->setEnabled(!isReadonly
-               && (dialog_->interlinespaceCO->currentIndex() == 2));
-       dialog_->interlinespaceUnit->setEnabled(!isReadonly
-               && (dialog_->interlinespaceCO->currentIndex() == 2));
-       dialog_->interlinespaceCO->setEnabled(!isReadonly);
+       interlinespaceED->setEnabled(!isReadonly
+               && (interlinespaceCO->currentIndex() == 2));
+       interlinespaceUnit->setEnabled(!isReadonly
+               && (interlinespaceCO->currentIndex() == 2));
+       interlinespaceCO->setEnabled(!isReadonly);
 
        string colwidth;
        if (!pwidth.zero())
                colwidth = pwidth.asString();
-       lengthToWidgets(dialog_->widthED, dialog_->widthUnit,
+       lengthToWidgets(widthED, widthUnit,
                colwidth, default_unit);
 
-       dialog_->widthED->setEnabled(!isReadonly);
-       dialog_->widthUnit->setEnabled(!isReadonly);
+       widthED->setEnabled(!isReadonly);
+       widthUnit->setEnabled(!isReadonly);
 
-       dialog_->hAlignCB->clear();
-       dialog_->hAlignCB->addItem(qt_("Left"));
-       dialog_->hAlignCB->addItem(qt_("Center"));
-       dialog_->hAlignCB->addItem(qt_("Right"));
+       hAlignCB->clear();
+       hAlignCB->addItem(qt_("Left"));
+       hAlignCB->addItem(qt_("Center"));
+       hAlignCB->addItem(qt_("Right"));
        if (!multicol && !pwidth.zero())
-               dialog_->hAlignCB->addItem(qt_("Justified"));
+               hAlignCB->addItem(qt_("Justified"));
 
        int align = 0;
-       switch (tabular.getAlignment(cell)) {
+       switch (tabular_.getAlignment(cell)) {
        case LYX_ALIGN_LEFT:
                align = 0;
                break;
@@ -757,10 +699,10 @@ void GuiTabular::update_contents()
                align = 0;
                break;
        }
-       dialog_->hAlignCB->setCurrentIndex(align);
+       hAlignCB->setCurrentIndex(align);
 
        int valign = 0;
-       switch (tabular.getVAlignment(cell)) {
+       switch (tabular_.getVAlignment(cell)) {
        case Tabular::LYX_VALIGN_TOP:
                valign = 0;
                break;
@@ -776,99 +718,99 @@ void GuiTabular::update_contents()
        }
        if (pwidth.zero())
                valign = 1;
-       dialog_->vAlignCB->setCurrentIndex(valign);
-
-       dialog_->hAlignCB->setEnabled(true);
-       dialog_->vAlignCB->setEnabled(!pwidth.zero());
-
-       if (!tabular.isLongTabular()) {
-               dialog_->headerStatusCB->setChecked(false);
-               dialog_->headerBorderAboveCB->setChecked(false);
-               dialog_->headerBorderBelowCB->setChecked(false);
-               dialog_->firstheaderStatusCB->setChecked(false);
-               dialog_->firstheaderBorderAboveCB->setChecked(false);
-               dialog_->firstheaderBorderBelowCB->setChecked(false);
-               dialog_->firstheaderNoContentsCB->setChecked(false);
-               dialog_->footerStatusCB->setChecked(false);
-               dialog_->footerBorderAboveCB->setChecked(false);
-               dialog_->footerBorderBelowCB->setChecked(false);
-               dialog_->lastfooterStatusCB->setChecked(false);
-               dialog_->lastfooterBorderAboveCB->setChecked(false);
-               dialog_->lastfooterBorderBelowCB->setChecked(false);
-               dialog_->lastfooterNoContentsCB->setChecked(false);
-               dialog_->newpageCB->setChecked(false);
-               dialog_->newpageCB->setEnabled(false);
+       vAlignCB->setCurrentIndex(valign);
+
+       hAlignCB->setEnabled(true);
+       vAlignCB->setEnabled(!pwidth.zero());
+
+       if (!tabular_.isLongTabular()) {
+               headerStatusCB->setChecked(false);
+               headerBorderAboveCB->setChecked(false);
+               headerBorderBelowCB->setChecked(false);
+               firstheaderStatusCB->setChecked(false);
+               firstheaderBorderAboveCB->setChecked(false);
+               firstheaderBorderBelowCB->setChecked(false);
+               firstheaderNoContentsCB->setChecked(false);
+               footerStatusCB->setChecked(false);
+               footerBorderAboveCB->setChecked(false);
+               footerBorderBelowCB->setChecked(false);
+               lastfooterStatusCB->setChecked(false);
+               lastfooterBorderAboveCB->setChecked(false);
+               lastfooterBorderBelowCB->setChecked(false);
+               lastfooterNoContentsCB->setChecked(false);
+               newpageCB->setChecked(false);
+               newpageCB->setEnabled(false);
                return;
        }
 
        Tabular::ltType ltt;
        bool use_empty;
-       bool row_set = tabular.getRowOfLTHead(row, ltt);
-       dialog_->headerStatusCB->setChecked(row_set);
+       bool row_set = tabular_.getRowOfLTHead(row, ltt);
+       headerStatusCB->setChecked(row_set);
        if (ltt.set) {
-               dialog_->headerBorderAboveCB->setChecked(ltt.topDL);
-               dialog_->headerBorderBelowCB->setChecked(ltt.bottomDL);
+               headerBorderAboveCB->setChecked(ltt.topDL);
+               headerBorderBelowCB->setChecked(ltt.bottomDL);
                use_empty = true;
        } else {
-               dialog_->headerBorderAboveCB->setChecked(false);
-               dialog_->headerBorderBelowCB->setChecked(false);
-               dialog_->headerBorderAboveCB->setEnabled(false);
-               dialog_->headerBorderBelowCB->setEnabled(false);
-               dialog_->firstheaderNoContentsCB->setChecked(false);
-               dialog_->firstheaderNoContentsCB->setEnabled(false);
+               headerBorderAboveCB->setChecked(false);
+               headerBorderBelowCB->setChecked(false);
+               headerBorderAboveCB->setEnabled(false);
+               headerBorderBelowCB->setEnabled(false);
+               firstheaderNoContentsCB->setChecked(false);
+               firstheaderNoContentsCB->setEnabled(false);
                use_empty = false;
        }
 
-       row_set = tabular.getRowOfLTFirstHead(row, ltt);
-       dialog_->firstheaderStatusCB->setChecked(row_set);
+       row_set = tabular_.getRowOfLTFirstHead(row, ltt);
+       firstheaderStatusCB->setChecked(row_set);
        if (ltt.set && (!ltt.empty || !use_empty)) {
-               dialog_->firstheaderBorderAboveCB->setChecked(ltt.topDL);
-               dialog_->firstheaderBorderBelowCB->setChecked(ltt.bottomDL);
+               firstheaderBorderAboveCB->setChecked(ltt.topDL);
+               firstheaderBorderBelowCB->setChecked(ltt.bottomDL);
        } else {
-               dialog_->firstheaderBorderAboveCB->setEnabled(false);
-               dialog_->firstheaderBorderBelowCB->setEnabled(false);
-               dialog_->firstheaderBorderAboveCB->setChecked(false);
-               dialog_->firstheaderBorderBelowCB->setChecked(false);
+               firstheaderBorderAboveCB->setEnabled(false);
+               firstheaderBorderBelowCB->setEnabled(false);
+               firstheaderBorderAboveCB->setChecked(false);
+               firstheaderBorderBelowCB->setChecked(false);
                if (use_empty) {
-                       dialog_->firstheaderNoContentsCB->setChecked(ltt.empty);
+                       firstheaderNoContentsCB->setChecked(ltt.empty);
                        if (ltt.empty)
-                               dialog_->firstheaderStatusCB->setEnabled(false);
+                               firstheaderStatusCB->setEnabled(false);
                }
        }
 
-       row_set = tabular.getRowOfLTFoot(row, ltt);
-       dialog_->footerStatusCB->setChecked(row_set);
+       row_set = tabular_.getRowOfLTFoot(row, ltt);
+       footerStatusCB->setChecked(row_set);
        if (ltt.set) {
-               dialog_->footerBorderAboveCB->setChecked(ltt.topDL);
-               dialog_->footerBorderBelowCB->setChecked(ltt.bottomDL);
+               footerBorderAboveCB->setChecked(ltt.topDL);
+               footerBorderBelowCB->setChecked(ltt.bottomDL);
                use_empty = true;
        } else {
-               dialog_->footerBorderAboveCB->setChecked(false);
-               dialog_->footerBorderBelowCB->setChecked(false);
-               dialog_->footerBorderAboveCB->setEnabled(false);
-               dialog_->footerBorderBelowCB->setEnabled(false);
-               dialog_->lastfooterNoContentsCB->setChecked(false);
-               dialog_->lastfooterNoContentsCB->setEnabled(false);
+               footerBorderAboveCB->setChecked(false);
+               footerBorderBelowCB->setChecked(false);
+               footerBorderAboveCB->setEnabled(false);
+               footerBorderBelowCB->setEnabled(false);
+               lastfooterNoContentsCB->setChecked(false);
+               lastfooterNoContentsCB->setEnabled(false);
                use_empty = false;
        }
 
-       row_set = tabular.getRowOfLTLastFoot(row, ltt);
-               dialog_->lastfooterStatusCB->setChecked(row_set);
+       row_set = tabular_.getRowOfLTLastFoot(row, ltt);
+               lastfooterStatusCB->setChecked(row_set);
        if (ltt.set && (!ltt.empty || !use_empty)) {
-               dialog_->lastfooterBorderAboveCB->setChecked(ltt.topDL);
-               dialog_->lastfooterBorderBelowCB->setChecked(ltt.bottomDL);
+               lastfooterBorderAboveCB->setChecked(ltt.topDL);
+               lastfooterBorderBelowCB->setChecked(ltt.bottomDL);
        } else {
-               dialog_->lastfooterBorderAboveCB->setEnabled(false);
-               dialog_->lastfooterBorderBelowCB->setEnabled(false);
-               dialog_->lastfooterBorderAboveCB->setChecked(false);
-               dialog_->lastfooterBorderBelowCB->setChecked(false);
+               lastfooterBorderAboveCB->setEnabled(false);
+               lastfooterBorderBelowCB->setEnabled(false);
+               lastfooterBorderAboveCB->setChecked(false);
+               lastfooterBorderBelowCB->setChecked(false);
                if (use_empty) {
-                       dialog_->lastfooterNoContentsCB->setChecked(ltt.empty);
+                       lastfooterNoContentsCB->setChecked(ltt.empty);
                        if (ltt.empty)
-                               dialog_->lastfooterStatusCB->setEnabled(false);
+                               lastfooterStatusCB->setEnabled(false);
                }
        }
-       dialog_->newpageCB->setChecked(tabular.getLTNewPage(row));
+       newpageCB->setChecked(tabular_.getLTNewPage(row));
 }
 
 
@@ -879,91 +821,268 @@ void GuiTabular::closeGUI()
 
        // Subtle here, we must /not/ apply any changes and
        // then refer to tabular, as it will have been freed
-       // since the changes update the actual controller().tabular()
-       Tabular const & tabular(controller().tabular());
-
+       // since the changes update the actual tabular_
+       //
        // apply the fixed width values
-       Tabular::idx_type const cell = controller().getActiveCell();
-       bool const multicol = tabular.isMultiColumn(cell);
-       string width = widgetsToLength(dialog_->widthED, dialog_->widthUnit);
+       Tabular::idx_type const cell = getActiveCell();
+       bool const multicol = tabular_.isMultiColumn(cell);
+       string width = widgetsToLength(widthED, widthUnit);
        string width2;
 
-       Length llen = tabular.getColumnPWidth(cell);
-       Length llenMulti = tabular.getMColumnPWidth(cell);
+       Length llen = tabular_.getColumnPWidth(cell);
+       Length llenMulti = tabular_.getMColumnPWidth(cell);
 
        if (multicol && !llenMulti.zero())
-                       width2 = llenMulti.asString();
+               width2 = llenMulti.asString();
        else if (!multicol && !llen.zero())
-                       width2 = llen.asString();
+               width2 = llen.asString();
 
        // apply the special alignment
-       docstring const sa1 = qstring_to_ucs4(dialog_->specialAlignmentED->text());
+       docstring const sa1 = qstring_to_ucs4(specialAlignmentED->text());
        docstring sa2;
 
        if (multicol)
-               sa2 = tabular.getAlignSpecial(cell, Tabular::SET_SPECIAL_MULTI);
+               sa2 = tabular_.getAlignSpecial(cell, Tabular::SET_SPECIAL_MULTI);
        else
-               sa2 = tabular.getAlignSpecial(cell, Tabular::SET_SPECIAL_COLUMN);
+               sa2 = tabular_.getAlignSpecial(cell, Tabular::SET_SPECIAL_COLUMN);
 
        if (sa1 != sa2) {
                if (multicol)
-                       controller().set(Tabular::SET_SPECIAL_MULTI, to_utf8(sa1));
+                       set(Tabular::SET_SPECIAL_MULTI, to_utf8(sa1));
                else
-                       controller().set(Tabular::SET_SPECIAL_COLUMN, to_utf8(sa1));
+                       set(Tabular::SET_SPECIAL_COLUMN, to_utf8(sa1));
        }
 
        if (width != width2) {
                if (multicol)
-                       controller().set(Tabular::SET_MPWIDTH, width);
+                       set(Tabular::SET_MPWIDTH, width);
                else
-                       controller().set(Tabular::SET_PWIDTH, width);
+                       set(Tabular::SET_PWIDTH, width);
        }
 
        /* DO WE NEED THIS?
-       switch (dialog_->topspaceCO->currentIndex()) {
+       switch (topspaceCO->currentIndex()) {
                case 0:
-                       controller().set(Tabular::SET_TOP_SPACE, "");
+                       set(Tabular::SET_TOP_SPACE, "");
                        break;
                case 1:
-                       controller().set(Tabular::SET_TOP_SPACE, "default");
+                       set(Tabular::SET_TOP_SPACE, "default");
                        break;
                case 2:
-                       controller().set(Tabular::SET_TOP_SPACE,
-                               widgetsToLength(dialog_->topspaceED,
-                                       dialog_->topspaceUnit));
+                       set(Tabular::SET_TOP_SPACE,
+                               widgetsToLength(topspaceED, topspaceUnit));
                        break;
        }
 
-       switch (dialog_->bottomspaceCO->currentIndex()) {
+       switch (bottomspaceCO->currentIndex()) {
                case 0:
-                       controller().set(Tabular::SET_BOTTOM_SPACE, "");
+                       set(Tabular::SET_BOTTOM_SPACE, "");
                        break;
                case 1:
-                       controller().set(Tabular::SET_BOTTOM_SPACE, "default");
+                       set(Tabular::SET_BOTTOM_SPACE, "default");
                        break;
                case 2:
-                       controller().set(Tabular::SET_BOTTOM_SPACE,
-                               widgetsToLength(dialog_->bottomspaceED,
-                                       dialog_->bottomspaceUnit));
+                       set(Tabular::SET_BOTTOM_SPACE,
+                               widgetsToLength(bottomspaceED, bottomspaceUnit));
                        break;
        }
 
-       switch (dialog_->interlinespaceCO->currentIndex()) {
+       switch (interlinespaceCO->currentIndex()) {
                case 0:
-                       controller().set(Tabular::SET_INTERLINE_SPACE, "");
+                       set(Tabular::SET_INTERLINE_SPACE, "");
                        break;
                case 1:
-                       controller().set(Tabular::SET_INTERLINE_SPACE, "default");
+                       set(Tabular::SET_INTERLINE_SPACE, "default");
                        break;
                case 2:
-                       controller().set(Tabular::SET_INTERLINE_SPACE,
-                               widgetsToLength(dialog_->interlinespaceED,
-                                       dialog_->interlinespaceUnit));
+                       set(Tabular::SET_INTERLINE_SPACE,
+                               widgetsToLength(interlinespaceED, interlinespaceUnit));
                        break;
        }
 */
 }
 
+
+bool GuiTabular::initialiseParams(string const & data)
+{
+       // try to get the current cell
+       BufferView const * const bv = bufferview();
+       InsetTabular const * current_inset = 0;
+       if (bv) {
+               Cursor const & cur = bv->cursor();
+               // get the innermost tabular inset;
+               // assume that it is "ours"
+               for (int i = cur.depth() - 1; i >= 0; --i)
+                       if (cur[i].inset().lyxCode() == TABULAR_CODE) {
+                               current_inset = static_cast<InsetTabular const *>(&cur[i].inset());
+                               active_cell_ = cur[i].idx();
+                               break;
+                       }
+       }
+
+       if (current_inset && data.empty()) {
+               tabular_ = Tabular(current_inset->tabular);
+               return true;
+       }
+
+       InsetTabular tmp(buffer());
+       InsetTabular::string2params(data, tmp);
+       tabular_ = Tabular(tmp.tabular);
+       return true;
+}
+
+
+void GuiTabular::clearParams()
+{
+       InsetTabular tmp(buffer());
+       tabular_ = tmp.tabular;
+       active_cell_ = Tabular::npos;
+}
+
+
+Tabular::idx_type GuiTabular::getActiveCell() const
+{
+       return active_cell_;
+}
+
+
+void GuiTabular::set(Tabular::Feature f, string const & arg)
+{
+       string const data = featureAsString(f) + ' ' + arg;
+       dispatch(FuncRequest(getLfun(), data));
+}
+
+
+bool GuiTabular::useMetricUnits() const
+{
+       return lyxrc.default_papersize > PAPER_USEXECUTIVE;
+}
+
+
+void GuiTabular::setSpecial(string const & special)
+{
+       if (tabular_.isMultiColumn(getActiveCell()))
+               set(Tabular::SET_SPECIAL_MULTI, special);
+       else
+               set(Tabular::SET_SPECIAL_COLUMN, special);
+}
+
+
+void GuiTabular::setWidth(string const & width)
+{
+       if (tabular_.isMultiColumn(getActiveCell()))
+               set(Tabular::SET_MPWIDTH, width);
+       else
+               set(Tabular::SET_PWIDTH, width);
+
+       updateView();
+}
+
+
+void GuiTabular::toggleMultiColumn()
+{
+       set(Tabular::MULTICOLUMN);
+       updateView();
+}
+
+
+void GuiTabular::rotateTabular(bool yes)
+{
+       if (yes)
+               set(Tabular::SET_ROTATE_TABULAR);
+       else
+               set(Tabular::UNSET_ROTATE_TABULAR);
+}
+
+
+void GuiTabular::rotateCell(bool yes)
+{
+       if (yes)
+               set(Tabular::SET_ROTATE_CELL);
+       else
+               set(Tabular::UNSET_ROTATE_CELL);
+}
+
+
+void GuiTabular::halign(GuiTabular::HALIGN h)
+{
+       Tabular::Feature num = Tabular::ALIGN_LEFT;
+       Tabular::Feature multi_num = Tabular::M_ALIGN_LEFT;
+
+       switch (h) {
+               case LEFT:
+                       num = Tabular::ALIGN_LEFT;
+                       multi_num = Tabular::M_ALIGN_LEFT;
+                       break;
+               case CENTER:
+                       num = Tabular::ALIGN_CENTER;
+                       multi_num = Tabular::M_ALIGN_CENTER;
+                       break;
+               case RIGHT:
+                       num = Tabular::ALIGN_RIGHT;
+                       multi_num = Tabular::M_ALIGN_RIGHT;
+                       break;
+               case BLOCK:
+                       num = Tabular::ALIGN_BLOCK;
+                       //multi_num: no equivalent
+                       break;
+       }
+
+       if (tabular_.isMultiColumn(getActiveCell()))
+               set(multi_num);
+       else
+               set(num);
+}
+
+
+void GuiTabular::valign(GuiTabular::VALIGN v)
+{
+       Tabular::Feature num = Tabular::VALIGN_MIDDLE;
+       Tabular::Feature multi_num = Tabular::M_VALIGN_MIDDLE;
+
+       switch (v) {
+               case TOP:
+                       num = Tabular::VALIGN_TOP;
+                       multi_num = Tabular::M_VALIGN_TOP;
+                       break;
+               case MIDDLE:
+                       num = Tabular::VALIGN_MIDDLE;
+                       multi_num = Tabular::M_VALIGN_MIDDLE;
+                       break;
+               case BOTTOM:
+                       num = Tabular::VALIGN_BOTTOM;
+                       multi_num = Tabular::M_VALIGN_BOTTOM;
+                       break;
+       }
+
+       if (tabular_.isMultiColumn(getActiveCell()))
+               set(multi_num);
+       else
+               set(num);
+}
+
+
+void GuiTabular::booktabs(bool yes)
+{
+       if (yes)
+               set(Tabular::SET_BOOKTABS);
+       else
+               set(Tabular::UNSET_BOOKTABS);
+}
+
+
+void GuiTabular::longTabular(bool yes)
+{
+       if (yes)
+               set(Tabular::SET_LONGTABULAR);
+       else
+               set(Tabular::UNSET_LONGTABULAR);
+}
+
+
+Dialog * createGuiTabular(GuiView & lv) { return new GuiTabular(lv); }
+
+
 } // namespace frontend
 } // namespace lyx