]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormTabular.C
Change the semantics of 'none' and 'auto' viewers/editors: 'none' means now
[lyx.git] / src / frontends / xforms / FormTabular.C
index 1339b8811c659579a3885cbc09df30cd974a7817..cfb81319dc542ebf0962d541646a11d9f0cb7fbd 100644 (file)
@@ -1,51 +1,62 @@
 /**
  * \file FormTabular.C
- * Copyright 2000-2001 The LyX Team.
- * See the file COPYING.
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- * \author Jürgen Vigna, jug@sad.it
+ * \author Jürgen Vigna
+ *
+ * Full author contact details are available in file CREDITS.
  */
 
 #include <config.h>
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
-#include "debug.h"
-
 #include "FormTabular.h"
-#include "form_tabular.h"
-#include "LyXView.h"
-#include "Dialogs.h"
-#include "buffer.h"
+#include "forms/form_tabular.h"
+
 #include "xforms_helpers.h"
-#include "lyxrc.h" // to set the default length values
-#include "helper_funcs.h"
-#include "input_validators.h"
+#include "xformsBC.h"
 
-#include "insets/insettabular.h"
+#include "controllers/ButtonController.h"
+#include "controllers/ControlTabular.h"
+#include "controllers/helper_funcs.h"
 
+#include "support/convert.h"
 #include "support/lstrings.h"
 
-#include <functional>
+#include "lyx_forms.h"
+
+#include <boost/bind.hpp>
 
+using boost::bind;
 
-using SigC::slot;
+using std::string;
 using std::vector;
-using std::bind2nd;
-using std::remove_if;
+
+namespace lyx {
+
+using support::contains;
+using support::getStringFromVector;
+using support::isStrDbl;
+
+namespace frontend {
+
+namespace {
+
+#if FL_VERSION == 0 || (FL_REVISION == 0 && FL_FIXLEVEL < 2)
+bool const scalableTabfolders = false;
+#else
+bool const scalableTabfolders = true;
+#endif
+
+} // namespace anon
 
 
-FormTabular::FormTabular(LyXView * lv, Dialogs * d)
-       : FormInset(lv, d, _("Tabular Layout")),
-         inset_(0), actCell_(-1), closing_(false)
+typedef FormController<ControlTabular, FormView<FD_tabular> > base_class;
+
+FormTabular::FormTabular(Dialog & parent)
+       : base_class(parent, _("Table Settings"), scalableTabfolders),
+       closing_(false), actCell_(LyXTabular::npos)
 {
-       // let the dialog be shown
-       // This is a permanent connection so we won't bother
-       // storing a copy because we won't be disconnecting.
-       d->showTabular.connect(slot(this, &FormTabular::showInset));
-       d->updateTabular.connect(slot(this, &FormTabular::updateInset));
 }
 
 
@@ -62,113 +73,75 @@ void FormTabular::redraw()
 }
 
 
-FL_FORM * FormTabular::form() const
-{
-       if (dialog_.get())
-               return dialog_->form;
-       return 0;
-}
-
-
-void FormTabular::disconnect()
-{
-       inset_ = 0;
-       FormInset::disconnect();
-}
-
-
-void FormTabular::showInset(InsetTabular * inset)
-{
-       if (inset == 0) return;
-
-       // If connected to another inset, disconnect from it.
-       if (inset_ != inset) {
-               ih_.disconnect();
-               ih_ = inset->hideDialog.connect(slot(this, &FormTabular::hide));
-               inset_ = inset;
-       }
-
-       show();
-}
-
-
-void FormTabular::updateInset(InsetTabular * inset)
-{
-       if (inset == 0 || inset_ == 0) return;
-
-       // If connected to another inset, disconnect from it.
-       if (inset_ != inset) {
-               ih_.disconnect();
-               ih_ = inset->hideDialog.connect(slot(this, &FormTabular::hide));
-               inset_ = inset;
-       }
-
-       update();
-}
-
-
 void FormTabular::build()
 {
-       dialog_.reset(build_tabular());
+       dialog_.reset(build_tabular(this));
 
        // Allow the base class to control messages
        setMessageWidget(dialog_->text_warning);
 
+       // trigger an input event for cut&paste with middle mouse button.
        setPrehandler(dialog_->input_tabular_column);
        setPrehandler(dialog_->input_tabular_row);
 
-       tabular_options_.reset(build_tabular_options());
-       column_options_.reset(build_column_options());
-       cell_options_.reset(build_cell_options());
-       longtable_options_.reset(build_longtable_options());
+       // Create the contents of the unit choices; don't include the "%" terms.
+       vector<string> units_vec = getLatexUnits();
+       vector<string>::iterator ret =
+               remove_if(units_vec.begin(), units_vec.end(),
+                         bind(contains<char>, _1, '%'));
+       units_vec.erase(ret, units_vec.end());
+       string const units = getStringFromVector(units_vec, "|");
+
+       // tabular options form
+       tabular_options_.reset(build_tabular_options(this));
+
+       // column options form
+       column_options_.reset(build_tabular_column(this));
 
        fl_set_input_return(column_options_->input_column_width,
-                           FL_RETURN_END);
+                           FL_RETURN_END);
        fl_set_input_return(column_options_->input_special_alignment,
-                           FL_RETURN_END);
+                           FL_RETURN_END);
 
+       // trigger an input event for cut&paste with middle mouse button.
        setPrehandler(column_options_->input_column_width);
        setPrehandler(column_options_->input_special_alignment);
-       
+
+       fl_addto_choice(column_options_->choice_value_column_width,
+                       units.c_str());
+
+       // cell options form
+       cell_options_.reset(build_tabular_cell(this));
+
        fl_set_input_return(cell_options_->input_mcolumn_width,
-                           FL_RETURN_END);
+                           FL_RETURN_END);
        fl_set_input_return(cell_options_->input_special_multialign,
-                           FL_RETURN_END);
+                           FL_RETURN_END);
 
+       // trigger an input event for cut&paste with middle mouse button.
        setPrehandler(cell_options_->input_mcolumn_width);
        setPrehandler(cell_options_->input_special_multialign);
 
-       fl_addto_tabfolder(dialog_->tabfolder, _("Tabular"),
-                          tabular_options_->form);
-       fl_addto_tabfolder(dialog_->tabfolder, _("Column/Row"),
-                          column_options_->form);
-       fl_addto_tabfolder(dialog_->tabfolder, _("Cell"),
-                          cell_options_->form);
-       fl_addto_tabfolder(dialog_->tabfolder, _("LongTable"),
-                          longtable_options_->form);
-
-       // Create the contents of the unit choices
-       // Don't include the "%" terms...
-       vector<string> units_vec = getLatexUnits();
-#if 0
-       for (vector<string>::iterator it = units_vec.begin();
-            it != units_vec.end(); ++it) {
-               if (contains(*it, "%"))
-                       it = units_vec.erase(it, it + 1) - 1;
-       }
-#else
-       vector<string>::iterator ret =
-               remove_if(units_vec.begin(), units_vec.end(),
-                         bind2nd(contains_functor(), "%"));
-       units_vec.erase(ret, units_vec.end());
-#endif
-       
-       string units = getStringFromVector(units_vec, "|");
-
-       fl_addto_choice(column_options_->choice_value_column_width,
-                       units.c_str());
        fl_addto_choice(cell_options_->choice_value_mcolumn_width,
-                       units.c_str());
+                       units.c_str());
+
+       longtable_options_.reset(build_tabular_longtable(this));
+
+       // Enable the tabfolder to be rescaled correctly.
+       if (scalableTabfolders)
+               fl_set_tabfolder_autofit(dialog_->tabfolder, FL_FIT);
+
+       // Stack tabs
+       fl_addto_tabfolder(dialog_->tabfolder, _("Table").c_str(),
+                          tabular_options_->form);
+       fl_addto_tabfolder(dialog_->tabfolder, _("Column/Row").c_str(),
+                          column_options_->form);
+       fl_addto_tabfolder(dialog_->tabfolder, _("Cell").c_str(),
+                          cell_options_->form);
+       fl_addto_tabfolder(dialog_->tabfolder, _("LongTable").c_str(),
+                          longtable_options_->form);
+
+       //  FIXME: addReadOnly everything
 }
 
 
@@ -176,89 +149,90 @@ void FormTabular::update()
 {
        if (closing_)
                return;
-       if (!inset_ || !inset_->tabular.get())
-               return;
 
-       LyXTabular * tabular = inset_->tabular.get();
+       LyXTabular const & tabular = controller().tabular();
+
        int align;
-       char buf[12];
        LyXLength pwidth;
        string special;
 
-       int cell = inset_->getActCell();
+       LyXTabular::idx_type const cell = controller().getActiveCell();
        actCell_ = cell;
-       int column = tabular->column_of_cell(cell) + 1;
+       LyXTabular::col_type column = tabular.column_of_cell(cell) + 1;
        clearMessage();
        fl_activate_object(column_options_->input_special_alignment);
        fl_activate_object(cell_options_->input_special_multialign);
        fl_activate_object(column_options_->input_column_width);
        fl_activate_object(column_options_->choice_value_column_width);
-       sprintf(buf, "%d", column);
-       fl_set_input(dialog_->input_tabular_column, buf);
+       fl_set_input(dialog_->input_tabular_column,
+                    convert<string>(column).c_str());
        fl_deactivate_object(dialog_->input_tabular_column);
-       int row = tabular->row_of_cell(cell);
-       sprintf(buf, "%d", row + 1);
-       fl_set_input(dialog_->input_tabular_row, buf);
+       LyXTabular::row_type row = tabular.row_of_cell(cell);
+       fl_set_input(dialog_->input_tabular_row,
+                    convert<string>(row + 1).c_str());
        fl_deactivate_object(dialog_->input_tabular_row);
-       if (tabular->IsMultiColumn(cell)) {
+       if (tabular.isMultiColumn(cell)) {
                fl_set_button(cell_options_->check_multicolumn, 1);
                fl_set_button(cell_options_->check_border_top,
-                             tabular->TopLine(cell)?1:0);
+                             tabular.topLine(cell)?1:0);
                setEnabled(cell_options_->check_border_top, true);
                fl_set_button(cell_options_->check_border_bottom,
-                             tabular->BottomLine(cell)?1:0);
+                             tabular.bottomLine(cell)?1:0);
                setEnabled(cell_options_->check_border_bottom, true);
                // 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)) {
+               if (tabular.isFirstCellInRow(cell) ||
+                   tabular.isMultiColumn(cell-1)) {
                        fl_set_button(cell_options_->check_border_left,
-                                     tabular->LeftLine(cell)?1:0);
+                                     tabular.leftLine(cell)?1:0);
                        setEnabled(cell_options_->check_border_left, true);
                } else {
                        fl_set_button(cell_options_->check_border_left, 0);
                        setEnabled(cell_options_->check_border_left, false);
                }
-               if (tabular->IsLastCellInRow(cell) ||
-                   tabular->IsMultiColumn(cell+1)) {
+               if (tabular.isLastCellInRow(cell) ||
+                   tabular.isMultiColumn(cell+1)) {
                        fl_set_button(cell_options_->check_border_right,
-                                     tabular->RightLine(cell)?1:0);
+                                     tabular.rightLine(cell)?1:0);
                        setEnabled(cell_options_->check_border_right, true);
                } else {
                        fl_set_button(cell_options_->check_border_right, 0);
                        setEnabled(cell_options_->check_border_right, false);
                }
-               pwidth = tabular->GetMColumnPWidth(cell);
-               align = tabular->GetAlignment(cell);
-               if (!pwidth.zero() || (align == LYX_ALIGN_LEFT))
-                       fl_set_button(cell_options_->radio_align_left, 1);
-               else if (align == LYX_ALIGN_RIGHT)
+               pwidth = tabular.getMColumnPWidth(cell);
+               align = tabular.getAlignment(cell);
+               // set the horiz. alignment, default is left here
+               fl_set_button(cell_options_->radio_align_left, 0);
+               fl_set_button(cell_options_->radio_align_right, 0);
+               fl_set_button(cell_options_->radio_align_center, 0);
+               if (align == LYX_ALIGN_RIGHT)
                        fl_set_button(cell_options_->radio_align_right, 1);
-               else
+               else if (align == LYX_ALIGN_CENTER)
                        fl_set_button(cell_options_->radio_align_center, 1);
+               else
+                       fl_set_button(cell_options_->radio_align_left, 1);
 
-               align = tabular->GetVAlignment(cell);
+               align = tabular.getVAlignment(cell);
                fl_set_button(cell_options_->radio_valign_top, 0);
                fl_set_button(cell_options_->radio_valign_bottom, 0);
-               fl_set_button(cell_options_->radio_valign_center, 0);
-               if (pwidth.zero() || (align == LyXTabular::LYX_VALIGN_CENTER))
-                       fl_set_button(cell_options_->radio_valign_center, 1);
+               fl_set_button(cell_options_->radio_valign_middle, 0);
+               if (pwidth.zero() || (align == LyXTabular::LYX_VALIGN_MIDDLE))
+                       fl_set_button(cell_options_->radio_valign_middle, 1);
                else if (align == LyXTabular::LYX_VALIGN_BOTTOM)
                        fl_set_button(cell_options_->radio_valign_bottom, 1);
                else
                        fl_set_button(cell_options_->radio_valign_top, 1);
 
-               special = tabular->GetAlignSpecial(cell, LyXTabular::SET_SPECIAL_MULTI);
+               special = tabular.getAlignSpecial(cell, LyXTabular::SET_SPECIAL_MULTI);
                fl_set_input(cell_options_->input_special_multialign, special.c_str());
-               bool const metric = lyxrc.default_papersize > 3;
+               bool const metric(controller().useMetricUnits());
                string const default_unit = metric ? "cm" : "in";
                updateWidgetsFromLength(cell_options_->input_mcolumn_width,
-                                       cell_options_->choice_value_mcolumn_width,
-                                       pwidth, default_unit);
+                                       cell_options_->choice_value_mcolumn_width,
+                                       pwidth, default_unit);
 
-               if (!lv_->buffer()->isReadonly()) {
+               if (!bc().bp().isReadOnly()) {
                        setEnabled(cell_options_->input_special_multialign, true);
                        setEnabled(cell_options_->input_mcolumn_width, true);
                        setEnabled(cell_options_->choice_value_mcolumn_width, true);
@@ -266,11 +240,11 @@ void FormTabular::update()
 
                setEnabled(cell_options_->radio_valign_top,    !pwidth.zero());
                setEnabled(cell_options_->radio_valign_bottom, !pwidth.zero());
-               setEnabled(cell_options_->radio_valign_center, !pwidth.zero());
-               
-               setEnabled(cell_options_->radio_align_left,   pwidth.zero());
-               setEnabled(cell_options_->radio_align_right,  pwidth.zero());
-               setEnabled(cell_options_->radio_align_center, pwidth.zero());
+               setEnabled(cell_options_->radio_valign_middle, !pwidth.zero());
+
+               setEnabled(cell_options_->radio_align_left,   true);
+               setEnabled(cell_options_->radio_align_right,  true);
+               setEnabled(cell_options_->radio_align_center, true);
        } else {
                fl_set_button(cell_options_->check_multicolumn, 0);
 
@@ -301,8 +275,8 @@ void FormTabular::update()
                fl_set_button(cell_options_->radio_valign_bottom, 0);
                setEnabled(cell_options_->radio_valign_bottom, false);
 
-               fl_set_button(cell_options_->radio_valign_center, 0);
-               setEnabled(cell_options_->radio_valign_center, false);
+               fl_set_button(cell_options_->radio_valign_middle, 0);
+               setEnabled(cell_options_->radio_valign_middle, false);
 
                fl_set_input(cell_options_->input_special_multialign, "");
                setEnabled(cell_options_->input_special_multialign, false);
@@ -311,84 +285,87 @@ void FormTabular::update()
                setEnabled(cell_options_->input_mcolumn_width, false);
                setEnabled(cell_options_->choice_value_mcolumn_width, false);
        }
-       if (tabular->GetRotateCell(cell))
+       if (tabular.getRotateCell(cell))
                fl_set_button(cell_options_->check_rotate_cell, 1);
        else
                fl_set_button(cell_options_->check_rotate_cell, 0);
-       if (tabular->TopLine(cell, true))
+       if (tabular.topLine(cell, true))
                fl_set_button(column_options_->check_border_top, 1);
        else
                fl_set_button(column_options_->check_border_top, 0);
-       if (tabular->BottomLine(cell, true))
+       if (tabular.bottomLine(cell, true))
                fl_set_button(column_options_->check_border_bottom, 1);
        else
                fl_set_button(column_options_->check_border_bottom, 0);
-       if (tabular->LeftLine(cell, true))
+       if (tabular.leftLine(cell, true))
                fl_set_button(column_options_->check_border_left, 1);
        else
                fl_set_button(column_options_->check_border_left, 0);
-       if (tabular->RightLine(cell, true))
+       if (tabular.rightLine(cell, true))
                fl_set_button(column_options_->check_border_right, 1);
        else
                fl_set_button(column_options_->check_border_right, 0);
-       special = tabular->GetAlignSpecial(cell, LyXTabular::SET_SPECIAL_COLUMN);
+       special = tabular.getAlignSpecial(cell, LyXTabular::SET_SPECIAL_COLUMN);
        fl_set_input(column_options_->input_special_alignment, special.c_str());
 
-       bool const isReadonly = lv_->buffer()->isReadonly();
+       bool const isReadonly = bc().bp().isReadOnly();
        setEnabled(column_options_->input_special_alignment, !isReadonly);
 
-       pwidth = tabular->GetColumnPWidth(cell);
-       bool const metric = lyxrc.default_papersize > 3;
+       pwidth = tabular.getColumnPWidth(cell);
+       bool const metric = controller().useMetricUnits();
        string const default_unit = metric ? "cm" : "in";
        updateWidgetsFromLength(column_options_->input_column_width,
-                               column_options_->choice_value_column_width,
-                               pwidth, default_unit);
+                               column_options_->choice_value_column_width,
+                               pwidth, default_unit);
        setEnabled(column_options_->input_column_width, !isReadonly);
        setEnabled(column_options_->choice_value_column_width, !isReadonly);
 
        setEnabled(cell_options_->check_useminipage, !pwidth.zero());
        if (!pwidth.zero()) {
-               if (tabular->GetUsebox(cell) == 2)
+               if (tabular.getUsebox(cell) == 2)
                        fl_set_button(cell_options_->check_useminipage, 1);
                else
                        fl_set_button(cell_options_->check_useminipage, 0);
        } else {
                fl_set_button(cell_options_->check_useminipage, 0);
        }
-       align = tabular->GetAlignment(cell, true);
+       align = tabular.getAlignment(cell, true);
        fl_set_button(column_options_->radio_align_left, 0);
        fl_set_button(column_options_->radio_align_right, 0);
        fl_set_button(column_options_->radio_align_center, 0);
-       if (!pwidth.zero() || (align == LYX_ALIGN_LEFT))
+       fl_set_button(column_options_->radio_align_block, 0);
+       if (align == LYX_ALIGN_LEFT)
                fl_set_button(column_options_->radio_align_left, 1);
        else if (align == LYX_ALIGN_RIGHT)
                fl_set_button(column_options_->radio_align_right, 1);
-       else
+       else if (align == LYX_ALIGN_CENTER)
                fl_set_button(column_options_->radio_align_center, 1);
-       align = tabular->GetVAlignment(cell, true);
+       else
+               fl_set_button(column_options_->radio_align_block, 1);
+       align = tabular.getVAlignment(cell, true);
        fl_set_button(column_options_->radio_valign_top, 0);
        fl_set_button(column_options_->radio_valign_bottom, 0);
-       fl_set_button(column_options_->radio_valign_center, 0);
-       if (pwidth.zero() || (align == LyXTabular::LYX_VALIGN_CENTER))
-               fl_set_button(column_options_->radio_valign_center, 1);
+       fl_set_button(column_options_->radio_valign_middle, 0);
+       if (pwidth.zero() || (align == LyXTabular::LYX_VALIGN_MIDDLE))
+               fl_set_button(column_options_->radio_valign_middle, 1);
        else if (align == LyXTabular::LYX_VALIGN_BOTTOM)
                fl_set_button(column_options_->radio_valign_bottom, 1);
        else
                fl_set_button(column_options_->radio_valign_top, 1);
 
-       setEnabled(column_options_->radio_align_left,   pwidth.zero());
-       setEnabled(column_options_->radio_align_right,  pwidth.zero());
-       setEnabled(column_options_->radio_align_center, pwidth.zero());
-       
+       setEnabled(column_options_->radio_align_left,   true);
+       setEnabled(column_options_->radio_align_right,  true);
+       setEnabled(column_options_->radio_align_center, true);
+       setEnabled(column_options_->radio_align_block,   !pwidth.zero());
        setEnabled(column_options_->radio_valign_top,    !pwidth.zero());
        setEnabled(column_options_->radio_valign_bottom, !pwidth.zero());
-       setEnabled(column_options_->radio_valign_center, !pwidth.zero());
+       setEnabled(column_options_->radio_valign_middle, !pwidth.zero());
 
        fl_set_button(tabular_options_->check_longtable,
-                     tabular->IsLongTabular());
+                     tabular.isLongTabular());
+
+       bool const enable = tabular.isLongTabular();
 
-       bool const enable = tabular->IsLongTabular();
-           
        setEnabled(longtable_options_->check_lt_firsthead, enable);
        setEnabled(longtable_options_->check_1head_2border_above, enable);
        setEnabled(longtable_options_->check_1head_2border_below, enable);
@@ -408,36 +385,36 @@ void FormTabular::update()
        if (enable) {
                LyXTabular::ltType ltt;
                bool use_empty;
-               bool row_set = tabular->GetRowOfLTHead(row, ltt);
+               bool row_set = tabular.getRowOfLTHead(row, ltt);
                fl_set_button(longtable_options_->check_lt_head, row_set);
                if (ltt.set) {
                        fl_set_button(longtable_options_->check_head_2border_above,
-                                     ltt.topDL);
-                       fl_set_button(longtable_options_->check_head_2border_above,
-                                     ltt.topDL);
+                                     ltt.topDL);
+                       fl_set_button(longtable_options_->check_head_2border_below,
+                                     ltt.bottomDL);
                        use_empty = true;
                } else {
                        setEnabled(longtable_options_->check_head_2border_above, 0);
                        setEnabled(longtable_options_->check_head_2border_below, 0);
                        fl_set_button(longtable_options_->check_head_2border_above,0);
-                       fl_set_button(longtable_options_->check_head_2border_above,0);
+                       fl_set_button(longtable_options_->check_head_2border_below,0);
                        fl_set_button(longtable_options_->check_1head_empty,0);
                        setEnabled(longtable_options_->check_1head_empty, 0);
                        use_empty = false;
                }
                //
-               row_set = tabular->GetRowOfLTFirstHead(row, ltt);
+               row_set = tabular.getRowOfLTFirstHead(row, ltt);
                fl_set_button(longtable_options_->check_lt_firsthead, row_set);
                if (ltt.set && (!ltt.empty || !use_empty)) {
                        fl_set_button(longtable_options_->check_1head_2border_above,
-                                     ltt.topDL);
-                       fl_set_button(longtable_options_->check_1head_2border_above,
-                                     ltt.topDL);
+                                     ltt.topDL);
+                       fl_set_button(longtable_options_->check_1head_2border_below,
+                                     ltt.bottomDL);
                } else {
                        setEnabled(longtable_options_->check_1head_2border_above, 0);
                        setEnabled(longtable_options_->check_1head_2border_below, 0);
                        fl_set_button(longtable_options_->check_1head_2border_above,0);
-                       fl_set_button(longtable_options_->check_1head_2border_above,0);
+                       fl_set_button(longtable_options_->check_1head_2border_below,0);
                        if (use_empty) {
                                fl_set_button(longtable_options_->check_1head_empty,ltt.empty);
                                if (ltt.empty)
@@ -445,160 +422,163 @@ void FormTabular::update()
                        }
                }
                //
-               row_set = tabular->GetRowOfLTFoot(row, ltt);
+               row_set = tabular.getRowOfLTFoot(row, ltt);
                fl_set_button(longtable_options_->check_lt_foot, row_set);
                if (ltt.set) {
                        fl_set_button(longtable_options_->check_foot_2border_above,
-                                     ltt.topDL);
-                       fl_set_button(longtable_options_->check_foot_2border_above,
-                                     ltt.topDL);
+                                     ltt.topDL);
+                       fl_set_button(longtable_options_->check_foot_2border_below,
+                                     ltt.bottomDL);
                        use_empty = true;
                } else {
                        setEnabled(longtable_options_->check_foot_2border_above, 0);
                        setEnabled(longtable_options_->check_foot_2border_below, 0);
                        fl_set_button(longtable_options_->check_foot_2border_above,0);
-                       fl_set_button(longtable_options_->check_foot_2border_above,0);
+                       fl_set_button(longtable_options_->check_foot_2border_below,0);
                        fl_set_button(longtable_options_->check_lastfoot_empty, 0);
                        setEnabled(longtable_options_->check_lastfoot_empty, 0);
                        use_empty = false;
                }
                //
-               row_set = tabular->GetRowOfLTLastFoot(row, ltt);
+               row_set = tabular.getRowOfLTLastFoot(row, ltt);
                fl_set_button(longtable_options_->check_lt_lastfoot, row_set);
                if (ltt.set && (!ltt.empty || !use_empty)) {
                        fl_set_button(longtable_options_->check_lastfoot_2border_above,
-                                     ltt.topDL);
-                       fl_set_button(longtable_options_->check_lastfoot_2border_above,
-                                     ltt.topDL);
+                                     ltt.topDL);
+                       fl_set_button(longtable_options_->check_lastfoot_2border_below,
+                                     ltt.bottomDL);
                } else {
                        setEnabled(longtable_options_->check_lastfoot_2border_above,0);
                        setEnabled(longtable_options_->check_lastfoot_2border_below,0);
                        fl_set_button(longtable_options_->check_lastfoot_2border_above, 0);
-                       fl_set_button(longtable_options_->check_lastfoot_2border_above, 0);
+                       fl_set_button(longtable_options_->check_lastfoot_2border_below, 0);
                        if (use_empty) {
                                fl_set_button(longtable_options_->check_lastfoot_empty,
-                                             ltt.empty);
+                                             ltt.empty);
                                if (ltt.empty)
                                        setEnabled(longtable_options_->check_lt_lastfoot, 0);
                        }
                }
                fl_set_button(longtable_options_->check_lt_newpage,
-                             tabular->GetLTNewPage(row));
+                             tabular.getLTNewPage(row));
        } else {
                fl_set_button(longtable_options_->check_lt_firsthead, 0);
                fl_set_button(longtable_options_->check_1head_2border_above, 0);
-               fl_set_button(longtable_options_->check_1head_2border_above, 0);
+               fl_set_button(longtable_options_->check_1head_2border_below, 0);
                fl_set_button(longtable_options_->check_1head_empty, 0);
                fl_set_button(longtable_options_->check_lt_head, 0);
                fl_set_button(longtable_options_->check_head_2border_above, 0);
-               fl_set_button(longtable_options_->check_head_2border_above, 0);
+               fl_set_button(longtable_options_->check_head_2border_below, 0);
                fl_set_button(longtable_options_->check_lt_foot, 0);
                fl_set_button(longtable_options_->check_foot_2border_above, 0);
-               fl_set_button(longtable_options_->check_foot_2border_above, 0);
+               fl_set_button(longtable_options_->check_foot_2border_below, 0);
                fl_set_button(longtable_options_->check_lt_lastfoot, 0);
                fl_set_button(longtable_options_->check_lastfoot_2border_above, 0);
-               fl_set_button(longtable_options_->check_lastfoot_2border_above, 0);
+               fl_set_button(longtable_options_->check_lastfoot_2border_below, 0);
                fl_set_button(longtable_options_->check_lastfoot_empty, 0);
                fl_set_button(longtable_options_->check_lt_newpage, 0);
        }
        fl_set_button(tabular_options_->check_rotate_tabular,
-                     tabular->GetRotateTabular());
+                     tabular.getRotateTabular());
 }
 
 
-bool FormTabular::input(FL_OBJECT * ob, long)
+ButtonPolicy::SMInput FormTabular::input(FL_OBJECT * ob, long)
 {
-       if (!inset_)
-               return false;
-
        int s;
        LyXTabular::Feature num = LyXTabular::LAST_ACTION;
-       string special;;
+       string special;
 
-       int cell = inset_->getActCell();
+       LyXTabular const & tabular = controller().tabular();
+
+       LyXTabular::idx_type const cell = controller().getActiveCell();
 
        // ugly hack to auto-apply the stuff that hasn't been
        // yet. don't let this continue to exist ...
        if (ob == dialog_->button_close) {
                closing_ = true;
-               LyXTabular * tabular = inset_->tabular.get();
-               string str1 =
+               string w1 =
                        getLengthFromWidgets(column_options_->input_column_width,
                                             column_options_->choice_value_column_width);
-               string str2;
-               LyXLength llen = tabular->GetColumnPWidth(cell);
+               string w2;
+               LyXLength llen = tabular.getColumnPWidth(cell);
                if (!llen.zero())
-                       str2 = llen.asString();
-               if (str1 != str2)
-                       input(column_options_->input_column_width, 0);
-               str1 = getLengthFromWidgets(cell_options_->input_mcolumn_width,
-                                           cell_options_->choice_value_mcolumn_width);
-               llen = tabular->GetMColumnPWidth(cell);
+                       w2 = llen.asString();
+
+               string mw1 = getLengthFromWidgets(cell_options_->input_mcolumn_width,
+                                           cell_options_->choice_value_mcolumn_width);
+               llen = tabular.getMColumnPWidth(cell);
+               string mw2;
                if (llen.zero())
-                       str2 = "";
+                       mw2 = "";
                else
-                       str2 = llen.asString();
-               if (str1 != str2)
+                       mw2 = llen.asString();
+
+               string al1 = getString(column_options_->input_special_alignment);
+               string al2 = tabular.getAlignSpecial(cell, LyXTabular::SET_SPECIAL_COLUMN);
+               string mal1 = getString(cell_options_->input_special_multialign);
+               string mal2 = tabular.getAlignSpecial(cell, LyXTabular::SET_SPECIAL_MULTI);
+
+               // we must do these all at the end
+               if (w1 != w2)
+                       input(column_options_->input_column_width, 0);
+               if (mw1 != mw2)
                        input(cell_options_->input_mcolumn_width, 0);
-               str1 = fl_get_input(column_options_->input_special_alignment);
-               str2 = tabular->GetAlignSpecial(cell, LyXTabular::SET_SPECIAL_COLUMN);
-               if (str1 != str2)
+               if (al1 != al2)
                        input(column_options_->input_special_alignment, 0);
-               str1 = fl_get_input(cell_options_->input_special_multialign);
-               str2 = tabular->GetAlignSpecial(cell, LyXTabular::SET_SPECIAL_MULTI);
-               if (str1 != str2)
+               if (mal1 != mal2)
                        input(cell_options_->input_special_multialign, 0);
                closing_ = false;
-               ok();
-               return true;
+               dialog().OKButton();
+               return ButtonPolicy::SMI_VALID;
        }
+
        if (actCell_ != cell) {
                update();
                postWarning(_("Wrong Cursor position, updated window"));
-               return false;
+               return ButtonPolicy::SMI_VALID;
        }
+
        // No point in processing directives that you can't do anything with
        // anyhow, so exit now if the buffer is read-only.
-       if (lv_->buffer()->isReadonly()) {
+       if (bc().bp().isReadOnly()) {
                update();
-               return false;
+               return ButtonPolicy::SMI_VALID;
        }
+
        if ((ob == column_options_->input_column_width) ||
            (ob == column_options_->choice_value_column_width)) {
                string const str =
                        getLengthFromWidgets(column_options_->input_column_width,
                                             column_options_->choice_value_column_width);
-               inset_->tabularFeatures(lv_->view(), LyXTabular::SET_PWIDTH, str);
+               controller().set(LyXTabular::SET_PWIDTH, str);
 
                //check if the input is valid
-               string const input =
-                       fl_get_input(column_options_->input_column_width);
+               string const input = getString(column_options_->input_column_width);
                if (!input.empty() && !isValidLength(input) && !isStrDbl(input)) {
                        postWarning(_("Invalid Length (valid example: 10mm)"));
-                       return false;
+                       return ButtonPolicy::SMI_INVALID;
                }
 
                update(); // update for alignment
-               return true;
+               return ButtonPolicy::SMI_VALID;
        }
-       
+
        if ((ob == cell_options_->input_mcolumn_width) ||
            (ob == cell_options_->choice_value_mcolumn_width)) {
                string const str =
                        getLengthFromWidgets(cell_options_->input_mcolumn_width,
                                             cell_options_->choice_value_mcolumn_width);
-               inset_->tabularFeatures(lv_->view(), LyXTabular::SET_MPWIDTH, str);
+               controller().set(LyXTabular::SET_MPWIDTH, str);
 
                //check if the input is valid
-               string const input =
-                       fl_get_input(cell_options_->input_mcolumn_width);
+               string const input = getString(cell_options_->input_mcolumn_width);
                if (!input.empty() && !isValidLength(input) && !isStrDbl(input)) {
                        postWarning(_("Invalid Length (valid example: 10mm)"));
-                       return false;
+                       return ButtonPolicy::SMI_INVALID;
                }
                update(); // update for alignment
-               return true;
+               return ButtonPolicy::SMI_VALID;
        }
 
        if (ob == tabular_options_->button_append_row)
@@ -627,12 +607,14 @@ bool FormTabular::input(FL_OBJECT * ob, long)
                num = LyXTabular::ALIGN_RIGHT;
        else if (ob == column_options_->radio_align_center)
                num = LyXTabular::ALIGN_CENTER;
+       else if (ob == column_options_->radio_align_block)
+               num = LyXTabular::ALIGN_BLOCK;
        else if (ob == column_options_->radio_valign_top)
                num = LyXTabular::VALIGN_TOP;
        else if (ob == column_options_->radio_valign_bottom)
                num = LyXTabular::VALIGN_BOTTOM;
-       else if (ob == column_options_->radio_valign_center)
-               num = LyXTabular::VALIGN_CENTER;
+       else if (ob == column_options_->radio_valign_middle)
+               num = LyXTabular::VALIGN_MIDDLE;
        else if (ob == cell_options_->check_multicolumn)
                num = LyXTabular::MULTICOLUMN;
        else if (ob == tabular_options_->check_longtable) {
@@ -656,27 +638,27 @@ bool FormTabular::input(FL_OBJECT * ob, long)
                num = LyXTabular::SET_USEBOX;
                special = "2";
        } else if ((ob == longtable_options_->check_lt_firsthead) ||
-                  (ob == longtable_options_->check_1head_2border_above) ||
-                  (ob == longtable_options_->check_1head_2border_below) ||
-                  (ob == longtable_options_->check_1head_empty) ||
-                  (ob == longtable_options_->check_lt_head) ||
-                  (ob == longtable_options_->check_head_2border_above) ||
-                  (ob == longtable_options_->check_head_2border_below) ||
-                  (ob == longtable_options_->check_lt_foot) ||
-                  (ob == longtable_options_->check_foot_2border_above) ||
-                  (ob == longtable_options_->check_foot_2border_below) ||
-                  (ob == longtable_options_->check_lt_lastfoot) ||
-                  (ob == longtable_options_->check_lastfoot_2border_above) ||
-                  (ob == longtable_options_->check_lastfoot_2border_below) ||
-                  (ob == longtable_options_->check_lastfoot_empty)) {
+                  (ob == longtable_options_->check_1head_2border_above) ||
+                  (ob == longtable_options_->check_1head_2border_below) ||
+                  (ob == longtable_options_->check_1head_empty) ||
+                  (ob == longtable_options_->check_lt_head) ||
+                  (ob == longtable_options_->check_head_2border_above) ||
+                  (ob == longtable_options_->check_head_2border_below) ||
+                  (ob == longtable_options_->check_lt_foot) ||
+                  (ob == longtable_options_->check_foot_2border_above) ||
+                  (ob == longtable_options_->check_foot_2border_below) ||
+                  (ob == longtable_options_->check_lt_lastfoot) ||
+                  (ob == longtable_options_->check_lastfoot_2border_above) ||
+                  (ob == longtable_options_->check_lastfoot_2border_below) ||
+                  (ob == longtable_options_->check_lastfoot_empty)) {
                num = static_cast<LyXTabular::Feature>(checkLongtableOptions(ob, special));
        } else if (ob == longtable_options_->check_lt_newpage) {
                num = LyXTabular::SET_LTNEWPAGE;
        } else if (ob == column_options_->input_special_alignment) {
-               special = fl_get_input(column_options_->input_special_alignment);
+               special = getString(column_options_->input_special_alignment);
                num = LyXTabular::SET_SPECIAL_COLUMN;
        } else if (ob == cell_options_->input_special_multialign) {
-               special = fl_get_input(cell_options_->input_special_multialign);
+               special = getString(cell_options_->input_special_multialign);
                num = LyXTabular::SET_SPECIAL_MULTI;
        } else if (ob == cell_options_->check_border_top)
                num = LyXTabular::M_TOGGLE_LINE_TOP;
@@ -696,17 +678,18 @@ bool FormTabular::input(FL_OBJECT * ob, long)
                num = LyXTabular::M_VALIGN_TOP;
        else if (ob == cell_options_->radio_valign_bottom)
                num = LyXTabular::M_VALIGN_BOTTOM;
-       else if (ob == cell_options_->radio_valign_center)
-               num = LyXTabular::M_VALIGN_CENTER;
+       else if (ob == cell_options_->radio_valign_middle)
+               num = LyXTabular::M_VALIGN_MIDDLE;
        else
-               return false;
-       
-       inset_->tabularFeatures(lv_->view(), num, special);
+               return ButtonPolicy::SMI_VALID;
+
+       controller().set(num, special);
        update();
 
-       return true;
+       return ButtonPolicy::SMI_VALID;
 }
 
+
 int FormTabular::checkLongtableOptions(FL_OBJECT * ob, string & special)
 {
        bool flag = fl_get_button(ob);
@@ -750,3 +733,6 @@ int FormTabular::checkLongtableOptions(FL_OBJECT * ob, string & special)
 
        return LyXTabular::LAST_ACTION;
 }
+
+} // namespace frontend
+} // namespace lyx