]> git.lyx.org Git - features.git/commitdiff
use LyXLength for tabular pwidth
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 11 Dec 2001 17:26:52 +0000 (17:26 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 11 Dec 2001 17:26:52 +0000 (17:26 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3192 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/frontends/xforms/ChangeLog
src/frontends/xforms/FormTabular.C
src/frontends/xforms/xforms_helpers.C
src/frontends/xforms/xforms_helpers.h
src/insets/ChangeLog
src/insets/insettabular.C
src/tabular-old.C
src/tabular.C
src/tabular.h

index d564c506b7c84df475267a7c15bd1ea74ab11772..dc8a2b76df7d37c7aee4f42112314f98070a66b9 100644 (file)
@@ -1,3 +1,12 @@
+2001-12-10  Jean-Marc Lasgouttes  <lasgouttes@freesurf.fr>
+
+       * tabular-old.C (getTokenValue): 
+       * tabular.C (getTokenValue): 
+       (write_attribute): new versions for LyXLength
+       (everywhere): adjust the use of widths
+
+       * tabular.h: change the type of widths from string to LyXLength
+
 2001-12-11  Ben Stanley <bds02@uow.edu.au>
 
        * paragraph.C: fixed missing line number count when exporting
index 7370ded46430d6bcfd5e75edfbf354e8741d6df8..329b608f767cb54f69193660f737aad547ed79ab 100644 (file)
@@ -1,3 +1,8 @@
+2001-12-11  Jean-Marc Lasgouttes  <lasgouttes@freesurf.fr>
+
+       * FormTabular.C: use LyXLength instead of string wherever
+       necessary; whitespace changes.
+
 2001-12-08  Jürgen Spitzmüller  <j.spitzmueller@gmx.de>
 
        * forms/form_preferences.fd: use the same name for font sizes
index 40098e95a50f044fd256443c9e6def5368e3c78e..e8a3c70d60f2665170512fbc5930eb82bc1a514c 100644 (file)
@@ -140,7 +140,7 @@ void FormTabular::build()
        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;
+                       it = units_vec.erase(it, it + 1) - 1;
        }
        string units = getStringFromVector(units_vec, "|");
 
@@ -159,22 +159,22 @@ void FormTabular::update()
        LyXTabular * tabular = inset_->tabular.get();
        int align;
        char buf[12];
-       string pwidth;
+       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,"");
+       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);
        fl_activate_object(column_options_->choice_value_column_width);
-       sprintf(buf,"%d",column);
+       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) + 1;
+       sprintf(buf, "%d", row);
        fl_set_input(dialog_->input_tabular_row, buf);
        fl_deactivate_object(dialog_->input_tabular_row);
        if (tabular->IsMultiColumn(cell)) {
@@ -193,7 +193,7 @@ void FormTabular::update()
                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);
@@ -206,7 +206,7 @@ void FormTabular::update()
                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);
@@ -215,12 +215,12 @@ void FormTabular::update()
                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);
+               special = tabular->GetAlignSpecial(cell, LyXTabular::SET_SPECIAL_MULTI);
                fl_set_input(cell_options_->input_special_multialign, special.c_str());
                string const default_unit = "cm";
-               updateWidgetsFromLengthString(cell_options_->input_mcolumn_width,
-                                             cell_options_->choice_value_mcolumn_width,
-                                             pwidth.c_str(), default_unit);
+               updateWidgetsFromLength(cell_options_->input_mcolumn_width,
+                                       cell_options_->choice_value_mcolumn_width,
+                                       pwidth, default_unit);
 
                if (!lv_->buffer()->isReadonly()) {
                        setEnabled(cell_options_->input_special_multialign, true);
@@ -228,13 +228,13 @@ void FormTabular::update()
                        setEnabled(cell_options_->choice_value_mcolumn_width, true);
                }
 
-               setEnabled(cell_options_->radio_valign_top,    !pwidth.empty());
-               setEnabled(cell_options_->radio_valign_bottom, !pwidth.empty());
-               setEnabled(cell_options_->radio_valign_center, !pwidth.empty());
+               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.empty());
-               setEnabled(cell_options_->radio_align_right,  pwidth.empty());
-               setEnabled(cell_options_->radio_align_center, pwidth.empty());
+               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);
 
@@ -295,7 +295,7 @@ 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());
 
        bool const isReadonly = lv_->buffer()->isReadonly();
@@ -303,26 +303,26 @@ void FormTabular::update()
 
        pwidth = tabular->GetColumnPWidth(cell);
        string const default_unit = "cm";
-       updateWidgetsFromLengthString(column_options_->input_column_width,
-                                     column_options_->choice_value_column_width,
-                                     pwidth.c_str(), default_unit);
+       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.empty());
-       if (!pwidth.empty()) {
+       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_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);
@@ -332,20 +332,20 @@ 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);
 
-       setEnabled(column_options_->radio_align_left,   pwidth.empty());
-       setEnabled(column_options_->radio_align_right,  pwidth.empty());
-       setEnabled(column_options_->radio_align_center, pwidth.empty());
+       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.empty());
-       setEnabled(column_options_->radio_valign_bottom, !pwidth.empty());
-       setEnabled(column_options_->radio_valign_center, !pwidth.empty());
+       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());
@@ -360,21 +360,21 @@ void FormTabular::update()
        if (enable) {
                LyXTabular::ltType dummyltt;
                fl_set_button(longtable_options_->radio_lt_firsthead,
-                             tabular->GetRowOfLTFirstHead(row-1, dummyltt));
+                             tabular->GetRowOfLTFirstHead(row - 1, dummyltt));
                fl_set_button(longtable_options_->radio_lt_head,
-                             tabular->GetRowOfLTHead(row-1, dummyltt));
+                             tabular->GetRowOfLTHead(row - 1, dummyltt));
                fl_set_button(longtable_options_->radio_lt_foot,
-                             tabular->GetRowOfLTFoot(row-1, dummyltt));
+                             tabular->GetRowOfLTFoot(row - 1, dummyltt));
                fl_set_button(longtable_options_->radio_lt_lastfoot,
-                             tabular->GetRowOfLTLastFoot(row-1, dummyltt));
+                             tabular->GetRowOfLTLastFoot(row - 1, dummyltt));
                fl_set_button(longtable_options_->radio_lt_newpage,
                              tabular->GetLTNewPage(cell));
        } else {
-               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_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_button(tabular_options_->radio_rotate_tabular,
                      tabular->GetRotateTabular());
@@ -411,7 +411,7 @@ bool FormTabular::input(FL_OBJECT * ob, long)
            string const str =
                    getLengthFromWidgets(column_options_->input_column_width,
                                         column_options_->choice_value_column_width);
-        inset_->tabularFeatures(lv_->view(), LyXTabular::SET_PWIDTH,str);
+        inset_->tabularFeatures(lv_->view(), LyXTabular::SET_PWIDTH, str);
         update(); // update for alignment
         return true;
     }
@@ -419,7 +419,7 @@ bool FormTabular::input(FL_OBJECT * ob, long)
            string const str =
                    getLengthFromWidgets(cell_options_->input_mcolumn_width,
                                         cell_options_->choice_value_mcolumn_width);
-        inset_->tabularFeatures(lv_->view(), LyXTabular::SET_MPWIDTH,str);
+        inset_->tabularFeatures(lv_->view(), LyXTabular::SET_MPWIDTH, str);
         update(); // update for alignment
         return true;
     }
@@ -483,11 +483,11 @@ bool FormTabular::input(FL_OBJECT * ob, long)
                                  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);
+                   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);
index 9e1373e08ca72fdf0cd68da3258d7158fa1a22d1..07ecdadea56559ba83b9445643fd736849e49d4a 100644 (file)
@@ -122,6 +122,24 @@ string getLengthFromWidgets(FL_OBJECT * input, FL_OBJECT * choice)
 }
        
 
+#if 1
+// this should definitely be the other way around!!!
+void updateWidgetsFromLength(FL_OBJECT * input, FL_OBJECT * choice,
+                            LyXLength const & len,
+                            string const & default_unit)
+{
+       if (len.zero())
+               updateWidgetsFromLengthString(input, choice,
+                                             string(), default_unit);
+       else
+               updateWidgetsFromLengthString(input, choice,
+                                             len.asString(), default_unit);
+
+}
+
+
+// Most of the code here is a poor duplication of the parser code
+// which is in LyXLength. Use that instead
 void updateWidgetsFromLengthString(FL_OBJECT * input, FL_OBJECT * choice,
                                   string const & str,
                                   string const & default_unit)
@@ -180,7 +198,37 @@ void updateWidgetsFromLengthString(FL_OBJECT * input, FL_OBJECT * choice,
        fl_set_input(input,   len.c_str());
        fl_set_choice(choice, unitpos);
 }
+#else
+void updateWidgetsFromLengthString(FL_OBJECT * input, FL_OBJECT * choice,
+                                  string const & str,
+                                  string const & default_unit)
+{
+       updateWidgetsFromLength(input, choice,
+                               LyXLength(str), default_unit);
+}
+
+
+void updateWidgetsFromLength(FL_OBJECT * input, FL_OBJECT * choice,
+                            LyXLength const & len,
+                            string const & default_unit)
+{
+       // Paranoia check
+       lyx::Assert(input  && input->objclass  == FL_INPUT &&
+                   choice && choice->objclass == FL_CHOICE);
+
+       if (len.zero()) {
+               fl_set_input(input, "");
+               fl_set_choice_text(choice, default_unit.c_str());
+       } else {
+               ostringstream buffer;
+               buffer << len.value();
+               fl_set_input(input, buffer.str().c_str());
+               fl_set_choice_text(choice, stringFromUnit(len.unit()));
+       }
+}
+#endif
+
+
 // Take a string and add breaks so that it fits into a desired label width, w
 string formatted(string const & sin, int w, int size, int style)
 {
index f17fdd07585b03a98a51b9a38a1e7204bb6cbdc5..ad3133a9ea3856148ab1c5386681501f8e05ca65 100644 (file)
@@ -13,6 +13,7 @@
  
 #include "Color.h"
 #include "support/lstrings.h"
+#include "lyxlength.h"
  
 #include <vector>
 
@@ -49,6 +50,13 @@ void updateWidgetsFromLengthString(FL_OBJECT * input, FL_OBJECT * choice,
                                   string const & str,
                                   string const & default_unit);
 
+/** Given a LyXLength, set the input and choice widgets.
+    If the length is null, the choice will be set to default_unit.
+ */
+void updateWidgetsFromLength(FL_OBJECT * input, FL_OBJECT * choice,
+                            LyXLength const & len,
+                            string const & default_unit);
+
 /// struct holding xform-specific colors
 struct XformsColor : public NamedColor {
        int colorID;
index 940ab34dd41adf951402a9617a985dd35c64782a..5f59adb5f7faf68f6ec4084baa72f1289a644b13 100644 (file)
@@ -1,6 +1,9 @@
 2001-12-10  Jean-Marc Lasgouttes  <lasgouttes@freesurf.fr>
 
-       * insettext.C (draw): re-introduce the calls to width() ascent()
+       * insettabular.C (everywhere): adapt because widths are now real
+       widths and not strings
+
+       * insettext.C (draw): re-introduce the calls to width(), ascent()
        and descent() to initialize the caching variables.
 
 2001-12-09  Jean-Marc Lasgouttes  <lasgouttes@freesurf.fr>
index 5e3c7fd2d5415ba6470325fec27356165a0a99b0..ebc196602a67770b3704d3fd547e1ba86867a2bb 100644 (file)
@@ -1229,7 +1229,7 @@ bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
                                continue;
                        ++cell;
                        inset = tabular->GetCellInset(cell);
-                       if (!reinit && !tabular->GetPWidth(cell).empty())
+                       if (!reinit && !tabular->GetPWidth(cell).zero())
                                inset->update(bv, font, false);
                        maxAsc = max(maxAsc, inset->ascent(bv, font));
                        maxDesc = max(maxDesc, inset->descent(bv, font));
@@ -1645,27 +1645,27 @@ void InsetTabular::tabularFeatures(BufferView * bv,
        switch (feature) {
        case LyXTabular::M_ALIGN_LEFT:
        case LyXTabular::ALIGN_LEFT:
-               setAlign=LYX_ALIGN_LEFT;
+               setAlign = LYX_ALIGN_LEFT;
                break;
        case LyXTabular::M_ALIGN_RIGHT:
        case LyXTabular::ALIGN_RIGHT:
-               setAlign=LYX_ALIGN_RIGHT;
+               setAlign = LYX_ALIGN_RIGHT;
                break;
        case LyXTabular::M_ALIGN_CENTER:
        case LyXTabular::ALIGN_CENTER:
-               setAlign=LYX_ALIGN_CENTER;
+               setAlign = LYX_ALIGN_CENTER;
                break;
        case LyXTabular::M_VALIGN_TOP:
        case LyXTabular::VALIGN_TOP:
-               setVAlign=LyXTabular::LYX_VALIGN_TOP;
+               setVAlign = LyXTabular::LYX_VALIGN_TOP;
                break;
        case LyXTabular::M_VALIGN_BOTTOM:
        case LyXTabular::VALIGN_BOTTOM:
-               setVAlign=LyXTabular::LYX_VALIGN_BOTTOM;
+               setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
                break;
        case LyXTabular::M_VALIGN_CENTER:
        case LyXTabular::VALIGN_CENTER:
-               setVAlign=LyXTabular::LYX_VALIGN_CENTER;
+               setVAlign = LyXTabular::LYX_VALIGN_CENTER;
                break;
        default:
                break;
@@ -1688,8 +1688,9 @@ void InsetTabular::tabularFeatures(BufferView * bv,
        switch (feature) {
        case LyXTabular::SET_PWIDTH:
        {
-               bool const update = (tabular->GetColumnPWidth(actcell) != value);
-               tabular->SetColumnPWidth(actcell,value);
+               LyXLength const vallen = LyXLength(value);
+               bool const update = (tabular->GetColumnPWidth(actcell) != vallen);
+               tabular->SetColumnPWidth(actcell,vallen);
                if (update) {
                        for (int i = 0; i < tabular->rows(); ++i) {
                                tabular->GetCellInset(tabular->GetCellNumber(i, column))->
@@ -1701,8 +1702,9 @@ void InsetTabular::tabularFeatures(BufferView * bv,
        break;
        case LyXTabular::SET_MPWIDTH:
        {
-               bool const update = (tabular->GetPWidth(actcell) != value);
-               tabular->SetMColumnPWidth(actcell,value);
+               LyXLength const vallen = LyXLength(value);
+               bool const update = (tabular->GetPWidth(actcell) != vallen);
+               tabular->SetMColumnPWidth(actcell,vallen);
                if (update) {
                        for (int i = 0; i < tabular->rows(); ++i) {
                                tabular->GetCellInset(tabular->GetCellNumber(i, column))->
@@ -1999,11 +2001,14 @@ bool InsetTabular::insetHit(BufferView *, int x, int) const
 // in pixels if we have a pwidth for this cell.
 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
 {
-       string const s = tabular->GetPWidth(cell);
+       LyXLength const len = tabular->GetPWidth(cell);
        
-       if (s.empty())
+       if (len.zero())
                return -1;
-       return VSpace(s).inPixels(bv);
+#ifdef WITH_WARNINGS
+#warning Remove use of VSpace as soon as LyXLength::inPixels exists (JMarc)
+#endif
+       return VSpace(len).inPixels(bv);
 }
 
 
index 4a014d35015780a0bc86c5412743c518ef6642fe..9c7c0cac7f80892abe8c4d2c30fdc386140f1bb2 100644 (file)
@@ -125,6 +125,15 @@ bool getTokenValue(string const & str, char const * token, bool & flag)
 }
 
 
+bool getTokenValue(string const & str, const char * token, LyXLength & len)
+{
+       string tmp;
+       if (!getTokenValue(str, token, tmp))
+               return false;
+       return isValidLength(tmp, &len);
+}    
+
+
 inline
 void l_getline(istream & is, string & str)
 {
index 3d3529753f9751fac8b612a9a1da51d5c134cc93..88adfa680b09258ff6812247bd90278812fdbb38 100644 (file)
@@ -412,7 +412,7 @@ void LyXTabular::set_row_column_number_info(bool oldformat)
                                        cell_info[row][column+cn-1].right_line;
                        }
                        cell_info[row][column].inset.setAutoBreakRows(
-                               !GetPWidth(GetCellNumber(row, column)).empty());
+                               !GetPWidth(GetCellNumber(row, column)).zero());
                }
        }
 }
@@ -730,9 +730,9 @@ bool LyXTabular::SetVAlignment(int cell, VAlignment align, bool onlycolumn)
 }
 
 
-bool LyXTabular::SetColumnPWidth(int cell, string const & width)
+bool LyXTabular::SetColumnPWidth(int cell, LyXLength const & width)
 {
-       bool flag = !width.empty();
+       bool flag = !width.zero();
        int const j = column_of_cell(cell);
 
        column_info[j].p_width = width;
@@ -740,16 +740,16 @@ bool LyXTabular::SetColumnPWidth(int cell, string const & width)
                SetAlignment(cell, LYX_ALIGN_LEFT);
        for (int i = 0; i < rows_; ++i) {
                int c = GetCellNumber(i, j);
-               flag = !GetPWidth(c).empty(); // because of multicolumns!
+               flag = !GetPWidth(c).zero(); // because of multicolumns!
                GetCellInset(c)->setAutoBreakRows(flag);
        }
        return true;
 }
 
 
-bool LyXTabular::SetMColumnPWidth(int cell, string const & width)
+bool LyXTabular::SetMColumnPWidth(int cell, LyXLength const & width)
 {
-       bool const flag = !width.empty();
+       bool const flag = !width.zero();
 
        cellinfo_of_cell(cell)->p_width = width;
        if (IsMultiColumn(cell)) {
@@ -842,7 +842,7 @@ LyXTabular::GetVAlignment(int cell, bool onlycolumn) const
 }
 
 
-string const LyXTabular::GetPWidth(int cell) const
+LyXLength const LyXTabular::GetPWidth(int cell) const
 {
        if (IsMultiColumn(cell))
                return cellinfo_of_cell(cell)->p_width;
@@ -850,17 +850,17 @@ string const LyXTabular::GetPWidth(int cell) const
 }
 
 
-string const LyXTabular::GetColumnPWidth(int cell) const
+LyXLength const LyXTabular::GetColumnPWidth(int cell) const
 {
        return column_info[column_of_cell(cell)].p_width;
 }
 
 
-string const LyXTabular::GetMColumnPWidth(int cell) const
+LyXLength const LyXTabular::GetMColumnPWidth(int cell) const
 {
        if (IsMultiColumn(cell))
                return cellinfo_of_cell(cell)->p_width;
-       return string();
+       return LyXLength();
 }
 
 
@@ -1022,6 +1022,11 @@ string const write_attribute(string const & name, bool const & b)
        return write_attribute(name, int(b));
 }
 
+template <>
+string const write_attribute(string const & name, LyXLength const & value)
+{
+       return write_attribute(name, value.asString());
+}
 #else
 
 string const write_attribute(string const & name, int value)
@@ -1043,6 +1048,13 @@ string const write_attribute(string const & name, bool value)
        string str = " " + name + "=\"" + tostr(static_cast<int>(value)) + "\"";
        return str;
 }
+
+
+string const write_attribute(string const & name, LyXLength const & value)
+{
+       string str = " " + name + "=\"" + value.asString() + "\"";
+       return str;
+}
 #endif
 
 
@@ -1125,9 +1137,7 @@ void LyXTabular::Write(Buffer const * buf, ostream & os) const
                   << write_attribute("valignment", tostr(column_info[j].valignment))
                   << write_attribute("leftline", tostr(column_info[j].left_line))
                   << write_attribute("rightline", tostr(column_info[j].right_line))
-                  << write_attribute("width",
-                                                         VSpace(column_info[j].p_width)
-                                                         .asLyXCommand())
+                  << write_attribute("width", column_info[j].p_width.asString())
                   << write_attribute("special", column_info[j].align_special)
                   << ">\n";
        }
@@ -1298,6 +1308,15 @@ bool getTokenValue(string const & str, const char * token, bool & flag)
 }    
 
 
+bool getTokenValue(string const & str, const char * token, LyXLength & len)
+{
+       string tmp;
+       if (!getTokenValue(str, token, tmp))
+               return false;
+       return isValidLength(tmp, &len);
+}    
+
+
 inline
 void l_getline(istream & is, string & str)
 {
@@ -1525,7 +1544,7 @@ void LyXTabular::OldFormatRead(LyXLex & lex, string const & fl)
                        column_info[i].alignment = static_cast<LyXAlignment>(a);
                        column_info[i].left_line = b;
                        column_info[i].right_line = c;
-                       column_info[i].p_width = s1;
+                       column_info[i].p_width = LyXLength(s1);
                        column_info[i].align_special = s2;
                }
                for (i = 0; i < rows_; ++i) {
@@ -1557,7 +1576,7 @@ void LyXTabular::OldFormatRead(LyXLex & lex, string const & fl)
                                cell_info[i][j].rotate = static_cast<bool>(f);
                                cell_info[i][j].usebox = static_cast<BoxType>(g);
                                cell_info[i][j].align_special = s1;
-                               cell_info[i][j].p_width = s2;
+                               cell_info[i][j].p_width = LyXLength(s2);
                        }
                }
        }
@@ -1832,8 +1851,8 @@ void LyXTabular::SetUsebox(int cell, BoxType type)
 
 LyXTabular::BoxType LyXTabular::GetUsebox(int cell) const
 {
-       if (column_info[column_of_cell(cell)].p_width.empty() &&
-               !(IsMultiColumn(cell) && !cellinfo_of_cell(cell)->p_width.empty()))
+       if (column_info[column_of_cell(cell)].p_width.zero() &&
+               !(IsMultiColumn(cell) && !cellinfo_of_cell(cell)->p_width.zero()))
                return BOX_NONE;
        if (cellinfo_of_cell(cell)->usebox > 1)
                return cellinfo_of_cell(cell)->usebox;
@@ -2047,7 +2066,7 @@ int LyXTabular::TeXCellPreamble(ostream & os, int cell) const
                        {
                                os << '|';
                        }
-                       if (!GetPWidth(cell).empty()) {
+                       if (!GetPWidth(cell).zero()) {
                                switch (GetVAlignment(cell)) {
                                case LYX_VALIGN_TOP:
                                        os << "p";
@@ -2059,7 +2078,7 @@ int LyXTabular::TeXCellPreamble(ostream & os, int cell) const
                                        os << "b";
                                        break;
                                }
-                               os << "{" << GetPWidth(cell) << '}';
+                               os << "{" << GetPWidth(cell).asLatexString() << '}';
                        } else {
                                switch (GetAlignment(cell)) {
                                case LYX_ALIGN_LEFT:
@@ -2094,7 +2113,7 @@ int LyXTabular::TeXCellPreamble(ostream & os, int cell) const
                        os << "b";
                        break;
                }
-               os << "]{" << GetPWidth(cell) << "}{";
+               os << "]{" << GetPWidth(cell).asLatexString() << "}{";
        } else if (GetUsebox(cell) == BOX_MINIPAGE) {
                os << "\\begin{minipage}[";
                switch (GetVAlignment(cell)) {
@@ -2108,7 +2127,7 @@ int LyXTabular::TeXCellPreamble(ostream & os, int cell) const
                        os << "b";
                        break;
                }
-               os << "]{" << GetPWidth(cell) << "}\n";
+               os << "]{" << GetPWidth(cell).asLatexString() << "}\n";
                ++ret;
        }
        return ret;
@@ -2161,7 +2180,7 @@ int LyXTabular::Latex(Buffer const * buf,
                } else { 
                        if (column_info[i].left_line)
                                os << '|';
-                       if (!column_info[i].p_width.empty()) {
+                       if (!column_info[i].p_width.zero()) {
                                switch (column_info[i].valignment) {
                                case LYX_VALIGN_TOP:
                                        os << "p";
@@ -2174,7 +2193,7 @@ int LyXTabular::Latex(Buffer const * buf,
                                        break;
                        }
                                os << "{"
-                                  << column_info[i].p_width
+                                  << column_info[i].p_width.asLatexString()
                                   << '}';
                        } else {
                                switch (column_info[i].alignment) {
@@ -2216,7 +2235,7 @@ int LyXTabular::Latex(Buffer const * buf,
                        InsetText * inset = GetCellInset(cell);
 
                        bool rtl = inset->paragraph()->isRightToLeftPar(buf->params) &&
-                                       inset->paragraph()->size() > 0 && GetPWidth(cell).empty();
+                                       inset->paragraph()->size() > 0 && GetPWidth(cell).zero();
 
                        if (rtl)
                                os << "\\R{";
index e93aa9f7e5b1bf97af207b9bc8fcb1f4931a1c41..0da578f2ec46c503af99acc9252f6b8e388eba45 100644 (file)
@@ -23,6 +23,7 @@
 #include "layout.h"
 #include "LString.h"
 #include "insets/insettext.h"
+#include "lyxlength.h"
 
 class InsetTabular;
 class LaTeXFeatures;
@@ -238,9 +239,9 @@ public:
        bool SetVAlignment(int cell, VAlignment align,
                           bool onlycolumn = false);
        ///
-       bool SetColumnPWidth(int cell, string const & width);
+       bool SetColumnPWidth(int cell, LyXLength const & width);
        ///
-       bool SetMColumnPWidth(int cell, string const & width);
+       bool SetMColumnPWidth(int cell, LyXLength const & width);
        ///
        bool SetAlignSpecial(int cell, string const & special, Feature what);
        ///
@@ -248,11 +249,11 @@ public:
        ///
        VAlignment GetVAlignment(int cell, bool onlycolumn = false) const;
        ///
-       string const GetPWidth(int cell) const;
+       LyXLength const GetPWidth(int cell) const;
        ///
-       string const GetColumnPWidth(int cell) const;
+       LyXLength const GetColumnPWidth(int cell) const;
        ///
-       string const GetMColumnPWidth(int cell) const;
+       LyXLength const GetMColumnPWidth(int cell) const;
        ///
        string const GetAlignSpecial(int cell, int what) const;
        ///
@@ -428,7 +429,7 @@ private:
                ///
                string align_special;
                ///
-               string p_width; // this is only set for multicolumn!!!
+               LyXLength p_width; // this is only set for multicolumn!!!
                ///
                InsetText inset;
        };
@@ -470,7 +471,7 @@ private:
                ///
                int  width_of_column;
                ///
-               string p_width;
+               LyXLength p_width;
                ///
                string align_special;
        };