]> 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 e8a3c70d60f2665170512fbc5930eb82bc1a514c..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
@@ -118,13 +119,13 @@ void FormTabular::build()
                            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.
@@ -153,6 +154,9 @@ void FormTabular::build()
 
 void FormTabular::update()
 {
+       if (closing_)
+               return;
        if (!inset_ || !inset_->tabular.get())
                return;
 
@@ -173,8 +177,8 @@ void FormTabular::update()
        sprintf(buf, "%d", column);
        fl_set_input(dialog_->input_tabular_column, buf);
        fl_deactivate_object(dialog_->input_tabular_column);
-       int 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)) {
@@ -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);
@@ -351,33 +353,121 @@ void FormTabular::update()
                      tabular->IsLongTabular());
 
        bool const enable = tabular->IsLongTabular();
+           
        setEnabled(longtable_options_->radio_lt_firsthead, enable);
-       setEnabled(longtable_options_->radio_lt_head,      enable);
-       setEnabled(longtable_options_->radio_lt_foot,      enable);
-       setEnabled(longtable_options_->radio_lt_lastfoot,  enable);
-       setEnabled(longtable_options_->radio_lt_newpage,   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 dummyltt;
-               fl_set_button(longtable_options_->radio_lt_firsthead,
-                             tabular->GetRowOfLTFirstHead(row - 1, dummyltt));
-               fl_set_button(longtable_options_->radio_lt_head,
-                             tabular->GetRowOfLTHead(row - 1, dummyltt));
-               fl_set_button(longtable_options_->radio_lt_foot,
-                             tabular->GetRowOfLTFoot(row - 1, dummyltt));
-               fl_set_button(longtable_options_->radio_lt_lastfoot,
-                             tabular->GetRowOfLTLastFoot(row - 1, dummyltt));
+               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_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());
 }
 
 
@@ -386,14 +476,25 @@ bool FormTabular::input(FL_OBJECT * ob, long)
     if (!inset_)
         return false;
 
-    LyXTabular * tabular = inset_->tabular.get();
     int s;
     LyXTabular::Feature num = LyXTabular::LAST_ACTION;
     string special;;
 
     int cell = inset_->getActCell();
-       int row = tabular->row_of_cell(cell);
-       
+
+    // 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,
@@ -407,19 +508,43 @@ bool FormTabular::input(FL_OBJECT * ob, long)
       update();
       return false;
     }
-    if (ob == column_options_->input_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);
+    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 const str =
-                   getLengthFromWidgets(cell_options_->input_mcolumn_width,
-                                        cell_options_->choice_value_mcolumn_width);
-        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;
     }
@@ -459,71 +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) {
-           bool const enable =
-                   fl_get_button(tabular_options_->radio_longtable);
-           
-           setEnabled(longtable_options_->radio_lt_firsthead, enable);
-           setEnabled(longtable_options_->radio_lt_head,      enable);
-           setEnabled(longtable_options_->radio_lt_foot,      enable);
-           setEnabled(longtable_options_->radio_lt_lastfoot,  enable);
-           setEnabled(longtable_options_->radio_lt_newpage,   enable);
-
-           if (enable) {
+           if (fl_get_button(tabular_options_->radio_longtable))
                    num = LyXTabular::SET_LONGTABULAR;
-                   LyXTabular::ltType dummyltt;
-                   fl_set_button(longtable_options_->radio_lt_firsthead,
-                                 tabular->GetRowOfLTFirstHead(row, dummyltt));
-                   fl_set_button(longtable_options_->radio_lt_head,
-                                 tabular->GetRowOfLTHead(row, dummyltt));
-                   fl_set_button(longtable_options_->radio_lt_foot,
-                                 tabular->GetRowOfLTFoot(row, dummyltt));
-                   fl_set_button(longtable_options_->radio_lt_lastfoot,
-                                 tabular->GetRowOfLTLastFoot(row, dummyltt));
-                   fl_set_button(longtable_options_->radio_lt_firsthead,
-                                 tabular->GetLTNewPage(cell));
-           } else {
-                   num = LyXTabular::UNSET_LONGTABULAR;
-                   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);
-           }
-    } 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;
-    } 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;
-    } else if (ob == cell_options_->radio_useminipage) {
-        num = LyXTabular::SET_USEBOX;
-       special = "2";
-    } else if (ob == longtable_options_->radio_lt_firsthead) {
-               if (fl_get_button(ob))
-                       num = LyXTabular::SET_LTFIRSTHEAD;
                else
-                       num = LyXTabular::UNSET_LTFIRSTHEAD;
-    } else if (ob == longtable_options_->radio_lt_head) {
-               if (fl_get_button(ob))
-                       num = LyXTabular::SET_LTHEAD;
-               else
-                       num = LyXTabular::UNSET_LTHEAD;
-    } else if (ob == longtable_options_->radio_lt_foot) {
-               if (fl_get_button(ob))
-                       num = LyXTabular::SET_LTFOOT;
+                       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_LTFOOT;
-    } else if (ob == longtable_options_->radio_lt_lastfoot) {
-               if (fl_get_button(ob))
-                       num = LyXTabular::SET_LTLASTFOOT;
+                       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_LTLASTFOOT;
+                       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) ||
+                          (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) {
@@ -560,3 +655,53 @@ bool FormTabular::input(FL_OBJECT * ob, long)
 
     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;
+}