]> 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 f67fef0e27c25e9968ce48909e93799cceac30c9..9f9afcb501520f081e6bf1bf73cfd94e3d07e92d 100644 (file)
@@ -24,6 +24,7 @@
 #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"
@@ -32,7 +33,7 @@ using SigC::slot;
 
 FormTabular::FormTabular(LyXView * lv, Dialogs * d)
        : FormInset(lv, d, _("Tabular Layout")),
-         inset_(0), actCell_(-1)
+         inset_(0), actCell_(-1), closing_(false)
 {
        // let the dialog be shown
        // This is a permanent connection so we won't bother
@@ -153,6 +154,9 @@ void FormTabular::build()
 
 void FormTabular::update()
 {
+       if (closing_)
+               return;
        if (!inset_ || !inset_->tabular.get())
                return;
 
@@ -199,9 +203,7 @@ void FormTabular::update()
                        fl_set_button(cell_options_->radio_align_right, 1);
                else
                        fl_set_button(cell_options_->radio_align_center, 1);
-               setEnabled(cell_options_->radio_align_left,   true);
-               setEnabled(cell_options_->radio_align_right,  true);
-               setEnabled(cell_options_->radio_align_center, true);
+
                align = tabular->GetVAlignment(cell);
                fl_set_button(cell_options_->radio_valign_top, 0);
                fl_set_button(cell_options_->radio_valign_bottom, 0);
@@ -212,12 +214,11 @@ void FormTabular::update()
                        fl_set_button(cell_options_->radio_valign_bottom, 1);
                else
                        fl_set_button(cell_options_->radio_valign_top, 1);
-               setEnabled(cell_options_->radio_valign_top,    true);
-               setEnabled(cell_options_->radio_valign_bottom, true);
-               setEnabled(cell_options_->radio_valign_center, true);
+
                special = tabular->GetAlignSpecial(cell, LyXTabular::SET_SPECIAL_MULTI);
                fl_set_input(cell_options_->input_special_multialign, special.c_str());
-               string const default_unit = "cm";
+               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);
@@ -302,7 +303,8 @@ void FormTabular::update()
        setEnabled(column_options_->input_special_alignment, !isReadonly);
 
        pwidth = tabular->GetColumnPWidth(cell);
-       string const default_unit = "cm";
+       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);
@@ -479,7 +481,20 @@ bool FormTabular::input(FL_OBJECT * ob, long)
     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,
@@ -496,20 +511,40 @@ bool FormTabular::input(FL_OBJECT * ob, long)
     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);
+       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) ||
                (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);
+       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;
     }