]> 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 9f8a3f0593af122191687880186af9153c4ff496..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);
@@ -370,51 +372,65 @@ void FormTabular::update()
 
        if (enable) {
                LyXTabular::ltType ltt;
-               fl_set_button(longtable_options_->radio_lt_firsthead,
-                                         tabular->GetRowOfLTFirstHead(row, ltt));
-               if (ltt.row && !ltt.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);
-                       fl_set_button(longtable_options_->check_1head_empty,ltt.empty);
-                       if (ltt.empty)
-                               setEnabled(longtable_options_->radio_lt_firsthead, 0);
-               }
-               fl_set_button(longtable_options_->radio_lt_head,
-                             tabular->GetRowOfLTHead(row, ltt));
-               if (ltt.row) {
+               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;
                }
-               fl_set_button(longtable_options_->radio_lt_foot,
-                             tabular->GetRowOfLTFoot(row, ltt));
-               if (ltt.row) {
+               //
+               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;
                }
-               fl_set_button(longtable_options_->radio_lt_lastfoot,
-                             tabular->GetRowOfLTLastFoot(row, ltt));
-               if (ltt.row && !ltt.empty) {
+               //
+               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,
@@ -424,9 +440,12 @@ void FormTabular::update()
                        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_empty, ltt.empty);
-                       if (ltt.empty)
-                               setEnabled(longtable_options_->radio_lt_lastfoot, 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(row));
@@ -462,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,
@@ -479,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;
     }