]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormTabular.C
Bugfixes: checkboxes to radiobuttons (from J�rgen S) and remove a little
[lyx.git] / src / frontends / xforms / FormTabular.C
index e8d0c2787644e03c6c719f08179bf1f05b10957c..9f9afcb501520f081e6bf1bf73cfd94e3d07e92d 100644 (file)
@@ -1,11 +1,10 @@
-// -*- C++ -*-
 /* This file is part of
  * ======================================================
  * 
  *           LyX, The Document Processor
  *      
  *         Copyright 1995 Matthias Ettrich
- *          Copyright 1995-2000 The LyX Team.
+ *          Copyright 1995-2001 The LyX Team.
  *
  *======================================================*/
 /* FormTabular.C
 
 #include <config.h>
 
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
 #include "FormTabular.h"
 #include "form_tabular.h"
 #include "LyXView.h"
 #include "Dialogs.h"
 #include "insets/insettabular.h"
 #include "buffer.h"
+#include "xforms_helpers.h"
+#include "lyxrc.h" // to set the default length values
+#include "helper_funcs.h"
+#include "input_validators.h"
+#include "support/lstrings.h"
 
+using SigC::slot;
 
 FormTabular::FormTabular(LyXView * lv, Dialogs * d)
-       : FormInset( lv, d, _("Tabular Layout") ),
-         dialog_(0), tabular_options_(0), column_options_(0),
-         cell_options_(0), longtable_options_(0),
-         inset_(0), actCell_(-1)
+       : FormInset(lv, d, _("Tabular Layout")),
+         inset_(0), actCell_(-1), closing_(false)
 {
        // let the dialog be shown
        // This is a permanent connection so we won't bother
@@ -36,32 +43,23 @@ FormTabular::FormTabular(LyXView * lv, Dialogs * d)
 }
 
 
-FormTabular::~FormTabular()
-{
-       delete dialog_;
-       delete tabular_options_;
-       delete column_options_;
-       delete cell_options_;
-       delete longtable_options_;
-}
-
-
 void FormTabular::redraw()
 {
-       if( form() && form()->visible )
-               fl_redraw_form( form() );
+       if(form() && form()->visible)
+               fl_redraw_form(form());
        else
                return;
 
        FL_FORM * outer_form = fl_get_active_folder(dialog_->tabFolder);
        if (outer_form && outer_form->visible)
-               fl_redraw_form( outer_form );
+               fl_redraw_form(outer_form);
 }
 
 
 FL_FORM * FormTabular::form() const
 {
-       if (dialog_ ) return dialog_->form;
+       if (dialog_.get())
+               return dialog_->form;
        return 0;
 }
 
@@ -73,7 +71,7 @@ void FormTabular::disconnect()
 }
 
 
-void FormTabular::showInset( InsetTabular * inset )
+void FormTabular::showInset(InsetTabular * inset)
 {
        if (inset == 0) return;
 
@@ -88,7 +86,7 @@ void FormTabular::showInset( InsetTabular * inset )
 }
 
 
-void FormTabular::updateInset( InsetTabular * inset )
+void FormTabular::updateInset(InsetTabular * inset)
 {
        if (inset == 0 || inset_ == 0) return;
 
@@ -105,188 +103,178 @@ void FormTabular::updateInset( InsetTabular * inset )
 
 void FormTabular::build()
 {
-       dialog_ = build_tabular();
-       tabular_options_ = build_tabular_options();
-       column_options_ = build_column_options();
-       cell_options_ = build_cell_options();
-       longtable_options_ = build_longtable_options();
-
-       // Workaround dumb xforms sizing bug
-       minw_ = form()->w;
-       minh_ = form()->h;
+       dialog_.reset(build_tabular());
+       tabular_options_.reset(build_tabular_options());
+       column_options_.reset(build_column_options());
+       cell_options_.reset(build_cell_options());
+       longtable_options_.reset(build_longtable_options());
 
        fl_set_input_return(column_options_->input_column_width,
                            FL_RETURN_END);
        fl_set_input_return(column_options_->input_special_alignment,
-                           FL_RETURN_CHANGED);
+                           FL_RETURN_END);
        fl_set_input_return(cell_options_->input_mcolumn_width,
-                           FL_RETURN_CHANGED);
+                           FL_RETURN_END);
        fl_set_input_return(cell_options_->input_special_multialign,
-                           FL_RETURN_CHANGED);
+                           FL_RETURN_END);
 
        fl_addto_tabfolder(dialog_->tabFolder, _("Tabular"),
-                          tabular_options_->form);
+                          tabular_options_->form);
        fl_addto_tabfolder(dialog_->tabFolder, _("Column/Row"),
-                          column_options_->form);
+                          column_options_->form);
        fl_addto_tabfolder(dialog_->tabFolder, _("Cell"),
-                          cell_options_->form);
+                          cell_options_->form);
        fl_addto_tabfolder(dialog_->tabFolder, _("LongTable"),
-                          longtable_options_->form);
+                          longtable_options_->form);
+
+       // We should set these input filters on width fields to make them accept
+       // only unsigned numbers.
+       // But this leeds to trouble with the current apply behaviour (JSpitzm).
+       // fl_set_input_filter(column_options_->input_column_width,
+       //                  fl_unsigned_float_filter);
+       // fl_set_input_filter(cell_options_->input_mcolumn_width,
+       //                  fl_unsigned_float_filter);
+
+       // Create the contents of the unit choices
+       // Don't include the "%" terms...
+       std::vector<string> units_vec = getLatexUnits();
+       for (std::vector<string>::iterator it = units_vec.begin();
+            it != units_vec.end(); ++it) {
+               if (contains(*it, "%"))
+                       it = units_vec.erase(it, it + 1) - 1;
+       }
+       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());
 }
 
 
 void FormTabular::update()
 {
-       if (!inset_ || !inset_->tabular)
+       if (closing_)
+               return;
+       if (!inset_ || !inset_->tabular.get())
                return;
 
-       LyXTabular
-               * tabular = inset_->tabular;
-       int
-               align,
-               cell,
-               column,row;
-       char
-               buf[12];
-       string
-               pwidth, special;
-
-       actCell_ = cell = inset_->GetActCell();
-       column = tabular->column_of_cell(cell)+1;
-       fl_set_object_label(dialog_->text_warning,"");
+       LyXTabular * tabular = inset_->tabular.get();
+       int align;
+       char buf[12];
+       LyXLength pwidth;
+       string special;
+
+       int cell = inset_->getActCell();
+       actCell_ = cell;
+       int column = tabular->column_of_cell(cell) + 1;
+       fl_set_object_label(dialog_->text_warning, "");
        fl_activate_object(column_options_->input_special_alignment);
        fl_activate_object(cell_options_->input_special_multialign);
        fl_activate_object(column_options_->input_column_width);
-       sprintf(buf,"%d",column);
+       fl_activate_object(column_options_->choice_value_column_width);
+       sprintf(buf, "%d", column);
        fl_set_input(dialog_->input_tabular_column, buf);
        fl_deactivate_object(dialog_->input_tabular_column);
-       row = tabular->row_of_cell(cell)+1;
-       sprintf(buf,"%d",row);
+       int row = tabular->row_of_cell(cell);
+       sprintf(buf, "%d", row + 1);
        fl_set_input(dialog_->input_tabular_row, buf);
        fl_deactivate_object(dialog_->input_tabular_row);
        if (tabular->IsMultiColumn(cell)) {
                fl_set_button(cell_options_->radio_multicolumn, 1);
                fl_set_button(cell_options_->radio_border_top,
                              tabular->TopLine(cell)?1:0);
-               fl_activate_object(cell_options_->radio_border_top);
-               fl_set_object_lcol(cell_options_->radio_border_top, FL_BLACK);
+               setEnabled(cell_options_->radio_border_top, true);
                fl_set_button(cell_options_->radio_border_bottom,
                              tabular->BottomLine(cell)?1:0);
-               fl_activate_object(cell_options_->radio_border_bottom);
-               fl_set_object_lcol(cell_options_->radio_border_bottom, FL_BLACK);
+               setEnabled(cell_options_->radio_border_bottom, true);
                fl_set_button(cell_options_->radio_border_left,
                              tabular->LeftLine(cell)?1:0);
-               fl_activate_object(cell_options_->radio_border_left);
-               fl_set_object_lcol(cell_options_->radio_border_left, FL_BLACK);
+               setEnabled(cell_options_->radio_border_left, true);
                fl_set_button(cell_options_->radio_border_right,
                              tabular->RightLine(cell)?1:0);
-               fl_activate_object(cell_options_->radio_border_right);
-               fl_set_object_lcol(cell_options_->radio_border_right, FL_BLACK);
+               setEnabled(cell_options_->radio_border_right, true);
                pwidth = tabular->GetMColumnPWidth(cell);
                align = tabular->GetAlignment(cell);
-               if (!pwidth.empty() || (align == LYX_ALIGN_LEFT))
+               if (!pwidth.zero() || (align == LYX_ALIGN_LEFT))
                        fl_set_button(cell_options_->radio_align_left, 1);
                else if (align == LYX_ALIGN_RIGHT)
                        fl_set_button(cell_options_->radio_align_right, 1);
                else
                        fl_set_button(cell_options_->radio_align_center, 1);
-               fl_activate_object(cell_options_->radio_align_left);
-               fl_set_object_lcol(cell_options_->radio_align_left, FL_BLACK);
-               fl_activate_object(cell_options_->radio_align_right);
-               fl_set_object_lcol(cell_options_->radio_align_right, FL_BLACK);
-               fl_activate_object(cell_options_->radio_align_center);
-               fl_set_object_lcol(cell_options_->radio_align_center, FL_BLACK);
+
                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.empty() || (align == LyXTabular::LYX_VALIGN_CENTER))
+               if (pwidth.zero() || (align == LyXTabular::LYX_VALIGN_CENTER))
                        fl_set_button(cell_options_->radio_valign_center, 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);
-               fl_activate_object(cell_options_->radio_valign_top);
-               fl_set_object_lcol(cell_options_->radio_valign_top, FL_BLACK);
-               fl_activate_object(cell_options_->radio_valign_bottom);
-               fl_set_object_lcol(cell_options_->radio_valign_bottom, FL_BLACK);
-               fl_activate_object(cell_options_->radio_valign_center);
-               fl_set_object_lcol(cell_options_->radio_valign_center, FL_BLACK);
-               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());
-               fl_set_input(cell_options_->input_mcolumn_width,pwidth.c_str());
+               bool const metric = lyxrc.default_papersize > 3;
+               string const default_unit = metric ? "cm" : "in";
+               updateWidgetsFromLength(cell_options_->input_mcolumn_width,
+                                       cell_options_->choice_value_mcolumn_width,
+                                       pwidth, default_unit);
+
                if (!lv_->buffer()->isReadonly()) {
-                       fl_activate_object(cell_options_->input_special_multialign);
-                       fl_set_object_lcol(cell_options_->input_special_multialign,
-                                          FL_BLACK);
-                       fl_activate_object(cell_options_->input_mcolumn_width);
-                       fl_set_object_lcol(cell_options_->input_mcolumn_width, FL_BLACK);
-               }
-               if (!pwidth.empty()) {
-                       fl_deactivate_object(cell_options_->radio_align_left);
-                       fl_deactivate_object(cell_options_->radio_align_right);
-                       fl_deactivate_object(cell_options_->radio_align_center);
-                       fl_set_object_lcol(cell_options_->radio_align_left, FL_INACTIVE);
-                       fl_set_object_lcol(cell_options_->radio_align_right, FL_INACTIVE);
-                       fl_set_object_lcol(cell_options_->radio_align_center, FL_INACTIVE);
-                       fl_activate_object(cell_options_->radio_valign_top);
-                       fl_activate_object(cell_options_->radio_valign_bottom);
-                       fl_activate_object(cell_options_->radio_valign_center);
-                       fl_set_object_lcol(cell_options_->radio_valign_top, FL_BLACK);
-                       fl_set_object_lcol(cell_options_->radio_valign_bottom, FL_BLACK);
-                       fl_set_object_lcol(cell_options_->radio_valign_center, FL_BLACK);
-               } else {
-                       fl_activate_object(cell_options_->radio_align_left);
-                       fl_activate_object(cell_options_->radio_align_right);
-                       fl_activate_object(cell_options_->radio_align_center);
-                       fl_set_object_lcol(cell_options_->radio_align_left, FL_BLACK);
-                       fl_set_object_lcol(cell_options_->radio_align_right, FL_BLACK);
-                       fl_set_object_lcol(cell_options_->radio_align_center, FL_BLACK);
-                       fl_deactivate_object(cell_options_->radio_valign_top);
-                       fl_deactivate_object(cell_options_->radio_valign_bottom);
-                       fl_deactivate_object(cell_options_->radio_valign_center);
-                       fl_set_object_lcol(cell_options_->radio_valign_top, FL_INACTIVE);
-                       fl_set_object_lcol(cell_options_->radio_valign_bottom,FL_INACTIVE);
-                       fl_set_object_lcol(cell_options_->radio_valign_center,FL_INACTIVE);
+                       setEnabled(cell_options_->input_special_multialign, true);
+                       setEnabled(cell_options_->input_mcolumn_width, true);
+                       setEnabled(cell_options_->choice_value_mcolumn_width, true);
                }
+
+               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());
        } else {
                fl_set_button(cell_options_->radio_multicolumn, 0);
+
                fl_set_button(cell_options_->radio_border_top, 0);
-               fl_deactivate_object(cell_options_->radio_border_top);
-               fl_set_object_lcol(cell_options_->radio_border_top, FL_INACTIVE);
+               setEnabled(cell_options_->radio_border_top, false);
+
                fl_set_button(cell_options_->radio_border_bottom, 0);
-               fl_deactivate_object(cell_options_->radio_border_bottom);
-               fl_set_object_lcol(cell_options_->radio_border_bottom, FL_INACTIVE);
+               setEnabled(cell_options_->radio_border_bottom, false);
+
                fl_set_button(cell_options_->radio_border_left, 0);
-               fl_deactivate_object(cell_options_->radio_border_left);
-               fl_set_object_lcol(cell_options_->radio_border_left, FL_INACTIVE);
+               setEnabled(cell_options_->radio_border_left, false);
+
                fl_set_button(cell_options_->radio_border_right, 0);
-               fl_deactivate_object(cell_options_->radio_border_right);
-               fl_set_object_lcol(cell_options_->radio_border_right, FL_INACTIVE);
+               setEnabled(cell_options_->radio_border_right, false);
+
                fl_set_button(cell_options_->radio_align_left, 0);
-               fl_deactivate_object(cell_options_->radio_align_left);
-               fl_set_object_lcol(cell_options_->radio_align_left, FL_INACTIVE);
+               setEnabled(cell_options_->radio_align_left, false);
+
                fl_set_button(cell_options_->radio_align_right, 0);
-               fl_deactivate_object(cell_options_->radio_align_right);
-               fl_set_object_lcol(cell_options_->radio_align_right, FL_INACTIVE);
+               setEnabled(cell_options_->radio_align_right, false);
+
                fl_set_button(cell_options_->radio_align_center, 0);
-               fl_deactivate_object(cell_options_->radio_align_center);
-               fl_set_object_lcol(cell_options_->radio_align_center, FL_INACTIVE);
+               setEnabled(cell_options_->radio_align_center, false);
+
                fl_set_button(cell_options_->radio_valign_top, 0);
-               fl_deactivate_object(cell_options_->radio_valign_top);
-               fl_set_object_lcol(cell_options_->radio_valign_top, FL_INACTIVE);
+               setEnabled(cell_options_->radio_valign_top, false);
+
                fl_set_button(cell_options_->radio_valign_bottom, 0);
-               fl_deactivate_object(cell_options_->radio_valign_bottom);
-               fl_set_object_lcol(cell_options_->radio_valign_bottom, FL_INACTIVE);
+               setEnabled(cell_options_->radio_valign_bottom, false);
+
                fl_set_button(cell_options_->radio_valign_center, 0);
-               fl_deactivate_object(cell_options_->radio_valign_center);
-               fl_set_object_lcol(cell_options_->radio_valign_center, FL_INACTIVE);
+               setEnabled(cell_options_->radio_valign_center, false);
+
                fl_set_input(cell_options_->input_special_multialign, "");
-               fl_deactivate_object(cell_options_->input_special_multialign);
-               fl_set_object_lcol(cell_options_->input_special_multialign, FL_INACTIVE);
-               fl_set_input(cell_options_->input_mcolumn_width,"");
-               fl_deactivate_object(cell_options_->input_mcolumn_width);
-               fl_set_object_lcol(cell_options_->input_mcolumn_width, FL_INACTIVE);
+               setEnabled(cell_options_->input_special_multialign, false);
+
+               fl_set_input(cell_options_->input_mcolumn_width, "");
+               setEnabled(cell_options_->input_mcolumn_width, false);
+               setEnabled(cell_options_->choice_value_mcolumn_width, false);
        }
        if (tabular->GetRotateCell(cell))
                fl_set_button(cell_options_->radio_rotate_cell, 1);
@@ -308,36 +296,35 @@ void FormTabular::update()
                fl_set_button(column_options_->radio_border_right, 1);
        else
                fl_set_button(column_options_->radio_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());
-       if (lv_->buffer()->isReadonly()) 
-               fl_deactivate_object(column_options_->input_special_alignment);
-       else
-               fl_activate_object(column_options_->input_special_alignment);
+
+       bool const isReadonly = lv_->buffer()->isReadonly();
+       setEnabled(column_options_->input_special_alignment, !isReadonly);
+
        pwidth = tabular->GetColumnPWidth(cell);
-       fl_set_input(column_options_->input_column_width,pwidth.c_str());
-       if (lv_->buffer()->isReadonly()) {
-               fl_deactivate_object(column_options_->input_column_width);
-       } else {
-               fl_activate_object(column_options_->input_column_width);
-       }
-       if (!pwidth.empty()) {
-               fl_activate_object(cell_options_->radio_useminipage);
-               fl_set_object_lcol(cell_options_->radio_useminipage, FL_BLACK);
+       bool const metric = lyxrc.default_papersize > 3;
+       string const default_unit = metric ? "cm" : "in";
+       updateWidgetsFromLength(column_options_->input_column_width,
+                               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_->radio_useminipage, !pwidth.zero());
+       if (!pwidth.zero()) {
                if (tabular->GetUsebox(cell) == 2)
                        fl_set_button(cell_options_->radio_useminipage, 1);
                else
                        fl_set_button(cell_options_->radio_useminipage, 0);
        } else {
-               fl_deactivate_object(cell_options_->radio_useminipage);
-               fl_set_object_lcol(cell_options_->radio_useminipage, FL_INACTIVE);
-               fl_set_button(cell_options_->radio_useminipage,0);
+               fl_set_button(cell_options_->radio_useminipage, 0);
        }
        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.empty() || (align == LYX_ALIGN_LEFT))
+       if (!pwidth.zero() || (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);
@@ -347,101 +334,167 @@ void FormTabular::update()
        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.empty() || (align == LyXTabular::LYX_VALIGN_CENTER))
+       if (pwidth.zero() || (align == LyXTabular::LYX_VALIGN_CENTER))
                fl_set_button(column_options_->radio_valign_center, 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);
-       if (!pwidth.empty()) {
-               fl_deactivate_object(column_options_->radio_align_left);
-               fl_deactivate_object(column_options_->radio_align_right);
-               fl_deactivate_object(column_options_->radio_align_center);
-               fl_set_object_lcol(column_options_->radio_align_left, FL_INACTIVE);
-               fl_set_object_lcol(column_options_->radio_align_right, FL_INACTIVE);
-               fl_set_object_lcol(column_options_->radio_align_center, FL_INACTIVE);
-               fl_activate_object(column_options_->radio_valign_top);
-               fl_activate_object(column_options_->radio_valign_bottom);
-               fl_activate_object(column_options_->radio_valign_center);
-               fl_set_object_lcol(column_options_->radio_valign_top, FL_BLACK);
-               fl_set_object_lcol(column_options_->radio_valign_bottom, FL_BLACK);
-               fl_set_object_lcol(column_options_->radio_valign_center, FL_BLACK);
-       } else {
-               fl_activate_object(column_options_->radio_align_left);
-               fl_activate_object(column_options_->radio_align_right);
-               fl_activate_object(column_options_->radio_align_center);
-               fl_set_object_lcol(column_options_->radio_align_left, FL_BLACK);
-               fl_set_object_lcol(column_options_->radio_align_right, FL_BLACK);
-               fl_set_object_lcol(column_options_->radio_align_center, FL_BLACK);
-               fl_deactivate_object(column_options_->radio_valign_top);
-               fl_deactivate_object(column_options_->radio_valign_bottom);
-               fl_deactivate_object(column_options_->radio_valign_center);
-               fl_set_object_lcol(column_options_->radio_valign_top, FL_INACTIVE);
-               fl_set_object_lcol(column_options_->radio_valign_bottom, FL_INACTIVE);
-               fl_set_object_lcol(column_options_->radio_valign_center, FL_INACTIVE);
-       }
+
+       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_valign_top,    !pwidth.zero());
+       setEnabled(column_options_->radio_valign_bottom, !pwidth.zero());
+       setEnabled(column_options_->radio_valign_center, !pwidth.zero());
+
        fl_set_button(tabular_options_->radio_longtable,
                      tabular->IsLongTabular());
-       if (tabular->IsLongTabular()) {
-               fl_activate_object(longtable_options_->radio_lt_firsthead);
-               fl_activate_object(longtable_options_->radio_lt_head);
-               fl_activate_object(longtable_options_->radio_lt_foot);
-               fl_activate_object(longtable_options_->radio_lt_lastfoot);
-               fl_activate_object(longtable_options_->radio_lt_newpage);
-               fl_set_object_lcol(longtable_options_->radio_lt_firsthead, FL_BLACK);
-               fl_set_object_lcol(longtable_options_->radio_lt_head, FL_BLACK);
-               fl_set_object_lcol(longtable_options_->radio_lt_foot, FL_BLACK);
-               fl_set_object_lcol(longtable_options_->radio_lt_lastfoot, FL_BLACK);
-               fl_set_object_lcol(longtable_options_->radio_lt_newpage, FL_BLACK);
-               int dummy;
-               fl_set_button(longtable_options_->radio_lt_firsthead,
-                             tabular->GetRowOfLTFirstHead(cell, dummy));
-               fl_set_button(longtable_options_->radio_lt_head,
-                             tabular->GetRowOfLTHead(cell, dummy));
-               fl_set_button(longtable_options_->radio_lt_foot,
-                             tabular->GetRowOfLTFoot(cell, dummy));
-               fl_set_button(longtable_options_->radio_lt_lastfoot,
-                             tabular->GetRowOfLTLastFoot(cell, dummy));
+
+       bool const enable = tabular->IsLongTabular();
+           
+       setEnabled(longtable_options_->radio_lt_firsthead, enable);
+       setEnabled(longtable_options_->check_1head_2border_above, enable);
+       setEnabled(longtable_options_->check_1head_2border_below, enable);
+       setEnabled(longtable_options_->check_1head_empty, enable);
+       setEnabled(longtable_options_->radio_lt_head, enable);
+       setEnabled(longtable_options_->check_head_2border_above, enable);
+       setEnabled(longtable_options_->check_head_2border_below, enable);
+       setEnabled(longtable_options_->radio_lt_foot, enable);
+       setEnabled(longtable_options_->check_foot_2border_above, enable);
+       setEnabled(longtable_options_->check_foot_2border_below, enable);
+       setEnabled(longtable_options_->radio_lt_lastfoot, enable);
+       setEnabled(longtable_options_->check_lastfoot_2border_above, enable);
+       setEnabled(longtable_options_->check_lastfoot_2border_below, enable);
+       setEnabled(longtable_options_->check_lastfoot_empty, enable);
+       setEnabled(longtable_options_->radio_lt_newpage, enable);
+
+       if (enable) {
+               LyXTabular::ltType ltt;
+               bool use_empty;
+               bool row_set = tabular->GetRowOfLTHead(row, ltt);
+               fl_set_button(longtable_options_->radio_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);
+                       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_1head_empty,0);
+                       setEnabled(longtable_options_->check_1head_empty, 0);
+                       use_empty = false;
+               }
+               //
+               row_set = tabular->GetRowOfLTFirstHead(row, ltt);
+               fl_set_button(longtable_options_->radio_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);
+               } 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);
+                       if (use_empty) {
+                               fl_set_button(longtable_options_->check_1head_empty,ltt.empty);
+                               if (ltt.empty)
+                                       setEnabled(longtable_options_->radio_lt_firsthead, 0);
+                       }
+               }
+               //
+               row_set = tabular->GetRowOfLTFoot(row, ltt);
+               fl_set_button(longtable_options_->radio_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);
+                       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_lastfoot_empty, 0);
+                       setEnabled(longtable_options_->check_lastfoot_empty, 0);
+                       use_empty = false;
+               }
+               //
+               row_set = tabular->GetRowOfLTLastFoot(row, ltt);
+               fl_set_button(longtable_options_->radio_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);
+               } 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);
+                       if (use_empty) {
+                               fl_set_button(longtable_options_->check_lastfoot_empty,
+                                             ltt.empty);
+                               if (ltt.empty)
+                                       setEnabled(longtable_options_->radio_lt_lastfoot, 0);
+                       }
+               }
                fl_set_button(longtable_options_->radio_lt_newpage,
-                             tabular->GetLTNewPage(cell));
+                             tabular->GetLTNewPage(row));
        } else {
-               fl_deactivate_object(longtable_options_->radio_lt_firsthead);
-               fl_deactivate_object(longtable_options_->radio_lt_head);
-               fl_deactivate_object(longtable_options_->radio_lt_foot);
-               fl_deactivate_object(longtable_options_->radio_lt_lastfoot);
-               fl_deactivate_object(longtable_options_->radio_lt_newpage);
-               fl_set_button(longtable_options_->radio_lt_firsthead,0);
-               fl_set_button(longtable_options_->radio_lt_head,0);
-               fl_set_button(longtable_options_->radio_lt_foot,0);
-               fl_set_button(longtable_options_->radio_lt_lastfoot,0);
-               fl_set_button(longtable_options_->radio_lt_newpage,0);
-               fl_set_object_lcol(longtable_options_->radio_lt_firsthead,FL_INACTIVE);
-               fl_set_object_lcol(longtable_options_->radio_lt_head, FL_INACTIVE);
-               fl_set_object_lcol(longtable_options_->radio_lt_foot, FL_INACTIVE);
-               fl_set_object_lcol(longtable_options_->radio_lt_lastfoot, FL_INACTIVE);
-               fl_set_object_lcol(longtable_options_->radio_lt_newpage, FL_INACTIVE);
+               fl_set_button(longtable_options_->radio_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_empty, 0);
+               fl_set_button(longtable_options_->radio_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_->radio_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_->radio_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_empty, 0);
+               fl_set_button(longtable_options_->radio_lt_newpage, 0);
        }
        fl_set_button(tabular_options_->radio_rotate_tabular,
-                     tabular->GetRotateTabular());
+                     tabular->GetRotateTabular());
 }
 
+
 bool FormTabular::input(FL_OBJECT * ob, long)
 {
     if (!inset_)
         return false;
 
-    LyXTabular
-        * tabular = inset_->tabular;
-    int
-        cell,
-        s;
-    LyXTabular::Feature
-        num = LyXTabular::LAST_ACTION;
-    string
-        special,
-        str;
-
-    cell = inset_->GetActCell();
+    int s;
+    LyXTabular::Feature num = LyXTabular::LAST_ACTION;
+    string special;;
+
+    int cell = inset_->getActCell();
+
+    // 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;
+        input(column_options_->input_column_width, 0);
+        input(cell_options_->input_mcolumn_width, 0);
+        input(column_options_->input_special_alignment, 0);
+        input(cell_options_->input_special_multialign, 0);
+        closing_ = false;
+       ok();
+        return true;
+    }
     if (actCell_ != cell) {
         update();
         fl_set_object_label(dialog_->text_warning,
@@ -455,42 +508,47 @@ bool FormTabular::input(FL_OBJECT * ob, long)
       update();
       return false;
     }
-    if (ob == column_options_->input_column_width) {
-        string
-            str;
-        str = fl_get_input(ob);
-        if (!str.empty() && !isValidLength(str)) {
-            fl_set_object_label(dialog_->text_warning,
-                 _("Warning: Invalid Length (valid example: 10mm)"));
-            fl_show_object(dialog_->text_warning);
-            return false;
-        }
-        inset_->TabularFeatures(lv_->view(), LyXTabular::SET_PWIDTH,str);
+    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);
+
+       //check if the input is valid
+       string const input =
+                       fl_get_input(column_options_->input_column_width);
+       if (!input.empty() && !isValidLength(input) && !isStrDbl(input)) {
+               fl_set_object_label(dialog_->text_warning,
+                       _("Warning: Invalid Length (valid example: 10mm)"));
+               fl_show_object(dialog_->text_warning);
+               return false;
+       }
         update(); // update for alignment
         return true;
     }
-    if (ob == cell_options_->input_mcolumn_width) {
-        string
-            str;
-        str = fl_get_input(ob);
-        if (!str.empty() && !isValidLength(str)) {
-            fl_set_object_label(dialog_->text_warning,
-                 _("Warning: Invalid Length (valid example: 10mm)"));
-            fl_show_object(dialog_->text_warning);
-            return false;
-        }
-        inset_->TabularFeatures(lv_->view(), LyXTabular::SET_MPWIDTH,str);
+    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);
+
+       //check if the input is valid
+       string const input =
+               fl_get_input(cell_options_->input_mcolumn_width);
+       if (!input.empty() && !isValidLength(input) && !isStrDbl(input)) {
+               fl_set_object_label(dialog_->text_warning,
+                       _("Warning: Invalid Length (valid example: 10mm)"));
+               fl_show_object(dialog_->text_warning);
+               return false;
+       }
         update(); // update for alignment
         return true;
     }
-    str = fl_get_input(column_options_->input_column_width);
-    if (!str.empty() && !isValidLength(str)) {
-        fl_set_object_label(
-           dialog_->text_warning,
-           _("Warning: Invalid Length (valid example: 10mm)"));
-        fl_show_object(dialog_->text_warning);
-        return false;
-    }
+
     if (ob == tabular_options_->button_append_row)
         num = LyXTabular::APPEND_ROW;
     else if (ob == tabular_options_->button_append_column)
@@ -526,69 +584,41 @@ bool FormTabular::input(FL_OBJECT * ob, long)
     else if (ob == cell_options_->radio_multicolumn)
         num = LyXTabular::MULTICOLUMN;
     else if (ob == tabular_options_->radio_longtable) {
-        s=fl_get_button(tabular_options_->radio_longtable);
-        if (s) {
-            num = LyXTabular::SET_LONGTABULAR;
-            fl_activate_object(longtable_options_->radio_lt_firsthead);
-            fl_activate_object(longtable_options_->radio_lt_head);
-            fl_activate_object(longtable_options_->radio_lt_foot);
-            fl_activate_object(longtable_options_->radio_lt_lastfoot);
-            fl_activate_object(longtable_options_->radio_lt_newpage);
-           int dummy;
-            fl_set_button(longtable_options_->radio_lt_firsthead,
-                          tabular->GetRowOfLTFirstHead(cell, dummy));
-            fl_set_button(longtable_options_->radio_lt_head,
-                         tabular->GetRowOfLTHead(cell, dummy));
-            fl_set_button(longtable_options_->radio_lt_foot,
-                         tabular->GetRowOfLTFoot(cell, dummy));
-            fl_set_button(longtable_options_->radio_lt_lastfoot,
-                          tabular->GetRowOfLTLastFoot(cell, dummy));
-            fl_set_button(longtable_options_->radio_lt_firsthead,
-                         tabular->GetLTNewPage(cell));
-        } else {
-           num = LyXTabular::UNSET_LONGTABULAR;
-            fl_deactivate_object(longtable_options_->radio_lt_firsthead);
-            fl_deactivate_object(longtable_options_->radio_lt_head);
-            fl_deactivate_object(longtable_options_->radio_lt_foot);
-            fl_deactivate_object(longtable_options_->radio_lt_lastfoot);
-            fl_deactivate_object(longtable_options_->radio_lt_newpage);
-            fl_set_button(longtable_options_->radio_lt_firsthead,0);
-            fl_set_button(longtable_options_->radio_lt_head,0);
-            fl_set_button(longtable_options_->radio_lt_foot,0);
-            fl_set_button(longtable_options_->radio_lt_lastfoot,0);
-            fl_set_button(longtable_options_->radio_lt_newpage,0);
-           fl_set_object_lcol(longtable_options_->radio_lt_firsthead,
-                              FL_INACTIVE);
-           fl_set_object_lcol(longtable_options_->radio_lt_head, FL_INACTIVE);
-           fl_set_object_lcol(longtable_options_->radio_lt_foot, FL_INACTIVE);
-           fl_set_object_lcol(longtable_options_->radio_lt_lastfoot,
-                              FL_INACTIVE);
-           fl_set_object_lcol(longtable_options_->radio_lt_newpage,
-                              FL_INACTIVE);
-        }
+           if (fl_get_button(tabular_options_->radio_longtable))
+                   num = LyXTabular::SET_LONGTABULAR;
+               else
+                       num = LyXTabular::UNSET_LONGTABULAR;
     } else if (ob == tabular_options_->radio_rotate_tabular) {
-        s=fl_get_button(tabular_options_->radio_rotate_tabular);
-       if (s)
-            num = LyXTabular::SET_ROTATE_TABULAR;
-       else
-           num = LyXTabular::UNSET_ROTATE_TABULAR;
+               s = fl_get_button(tabular_options_->radio_rotate_tabular);
+               if (s)
+                       num = LyXTabular::SET_ROTATE_TABULAR;
+               else
+                       num = LyXTabular::UNSET_ROTATE_TABULAR;
     } else if (ob == cell_options_->radio_rotate_cell) {
-        s=fl_get_button(cell_options_->radio_rotate_cell);
-       if (s)
-            num = LyXTabular::SET_ROTATE_CELL;
-       else
-           num = LyXTabular::UNSET_ROTATE_CELL;
+               s = fl_get_button(cell_options_->radio_rotate_cell);
+               if (s)
+                       num = LyXTabular::SET_ROTATE_CELL;
+               else
+                       num = LyXTabular::UNSET_ROTATE_CELL;
     } else if (ob == cell_options_->radio_useminipage) {
-        num = LyXTabular::SET_USEBOX;
-       special = "2";
-    } else if (ob == longtable_options_->radio_lt_firsthead) {
-        num = LyXTabular::SET_LTFIRSTHEAD;
-    } else if (ob == longtable_options_->radio_lt_head) {
-        num = LyXTabular::SET_LTHEAD;
-    } else if (ob == longtable_options_->radio_lt_foot) {
-        num = LyXTabular::SET_LTFOOT;
-    } else if (ob == longtable_options_->radio_lt_lastfoot) {
-        num = LyXTabular::SET_LTLASTFOOT;
+               num = LyXTabular::SET_USEBOX;
+               special = "2";
+    } else if ((ob == longtable_options_->radio_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_->radio_lt_head) ||
+                          (ob == longtable_options_->check_head_2border_above) ||
+                          (ob == longtable_options_->check_head_2border_below) ||
+                          (ob == longtable_options_->radio_lt_foot) ||
+                          (ob == longtable_options_->check_foot_2border_above) ||
+                          (ob == longtable_options_->check_foot_2border_below) ||
+                          (ob == longtable_options_->radio_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_->radio_lt_newpage) {
         num = LyXTabular::SET_LTNEWPAGE;
     } else if (ob == column_options_->input_special_alignment) {
@@ -620,8 +650,58 @@ bool FormTabular::input(FL_OBJECT * ob, long)
     else
         return false;
     
-    inset_->TabularFeatures(lv_->view(), num, special);
+    inset_->tabularFeatures(lv_->view(), num, special);
     update();
 
     return true;
 }
+
+int FormTabular::checkLongtableOptions(FL_OBJECT * ob, string & special)
+{
+       bool flag = fl_get_button(ob);
+       if ((ob == longtable_options_->check_1head_2border_above) ||
+               (ob == longtable_options_->check_head_2border_above) ||
+               (ob == longtable_options_->check_foot_2border_above) ||
+               (ob == longtable_options_->check_lastfoot_2border_above))
+       {
+               special = "dl_above";
+       } else if ((ob == longtable_options_->check_1head_2border_below) ||
+                          (ob == longtable_options_->check_head_2border_below) ||
+                          (ob == longtable_options_->check_foot_2border_below) ||
+                          (ob == longtable_options_->check_lastfoot_2border_below))
+       {
+               special = "dl_below";
+       } else if ((ob == longtable_options_->check_1head_empty) ||
+                          (ob == longtable_options_->check_lastfoot_empty))
+       {
+               special = "empty";
+       } else {
+               special = "";
+       }
+       if ((ob == longtable_options_->radio_lt_firsthead) ||
+               (ob == longtable_options_->check_1head_2border_above) ||
+               (ob == longtable_options_->check_1head_2border_below) ||
+               (ob == longtable_options_->check_1head_empty))
+       {
+               return (flag ? LyXTabular::SET_LTFIRSTHEAD :
+                               LyXTabular::UNSET_LTFIRSTHEAD);
+    } else if ((ob == longtable_options_->radio_lt_head) ||
+                          (ob == longtable_options_->check_head_2border_above) ||
+                          (ob == longtable_options_->check_head_2border_below))
+       {
+               return (flag ? LyXTabular::SET_LTHEAD : LyXTabular::UNSET_LTHEAD);
+    } else if ((ob == longtable_options_->radio_lt_foot) ||
+                          (ob == longtable_options_->check_foot_2border_above) ||
+                          (ob == longtable_options_->check_foot_2border_below))
+       {
+               return (flag ? LyXTabular::SET_LTFOOT : LyXTabular::UNSET_LTFOOT);
+    } else if ((ob == longtable_options_->radio_lt_lastfoot) ||
+                          (ob == longtable_options_->check_lastfoot_2border_above) ||
+                          (ob == longtable_options_->check_lastfoot_2border_below) ||
+                          (ob == longtable_options_->check_lastfoot_empty))
+       {
+               return (flag ? LyXTabular::SET_LTLASTFOOT :
+                               LyXTabular::UNSET_LTLASTFOOT);
+       }
+       return LyXTabular::LAST_ACTION;
+}