The attached patch uses LyXLength for p_width in LyXTabular. I like some of you (Juergen S.?) to try it out before I commit, because I am do not really know what to check. The gain is consistency, and also speed gains in files like TabularExamples.lyx where we spend as much as 38% of the time converting from string to length (it was with -O, but it cannot be that much better with -O2).
Juergen S., there is also some new code for updateWidgetsFromLengthString which is disabled for now (let's do one thing at a time). It greatly simplifies these routines by using the LyXLength parser. You can turn it on by changing the #if 1 in xforms_helpers.C to #if 0. Finally, a few remarks: - the same has to be done for minipages - I still have to use VSpace at one place to get the inPixel functionality. Andre', do you still have plans to rewrite lengths code? JMarc
Index: src/ChangeLog =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/ChangeLog,v retrieving revision 1.454 diff -u -r1.454 ChangeLog --- src/ChangeLog 2001/12/11 14:33:49 1.454 +++ src/ChangeLog 2001/12/11 14:39:12 @@ -1,3 +1,12 @@ +2001-12-10 Jean-Marc Lasgouttes <[EMAIL PROTECTED]> + + * 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 <[EMAIL PROTECTED]> * paragraph.C: fixed missing line number count when exporting Index: src/tabular-old.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/tabular-old.C,v retrieving revision 1.11 diff -u -r1.11 tabular-old.C --- src/tabular-old.C 2001/12/05 08:04:14 1.11 +++ src/tabular-old.C 2001/12/11 14:39:12 @@ -125,6 +125,15 @@ } +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: src/tabular.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/tabular.C,v retrieving revision 1.106 diff -u -r1.106 tabular.C --- src/tabular.C 2001/12/05 08:04:14 1.106 +++ src/tabular.C 2001/12/11 14:39:12 @@ -412,7 +412,7 @@ 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::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 @@ 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 @@ } -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::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 @@ 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 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 @@ << 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, 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 @@ 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 @@ 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 @@ 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 @@ { os << '|'; } - if (!GetPWidth(cell).empty()) { + if (!GetPWidth(cell).zero()) { switch (GetVAlignment(cell)) { case LYX_VALIGN_TOP: os << "p"; @@ -2059,7 +2078,7 @@ os << "b"; break; } - os << "{" << GetPWidth(cell) << '}'; + os << "{" << GetPWidth(cell).asLatexString() << '}'; } else { switch (GetAlignment(cell)) { case LYX_ALIGN_LEFT: @@ -2094,7 +2113,7 @@ 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 @@ os << "b"; break; } - os << "]{" << GetPWidth(cell) << "}\n"; + os << "]{" << GetPWidth(cell).asLatexString() << "}\n"; ++ret; } return ret; @@ -2161,7 +2180,7 @@ } 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 @@ break; } os << "{" - << column_info[i].p_width + << column_info[i].p_width.asLatexString() << '}'; } else { switch (column_info[i].alignment) { @@ -2216,7 +2235,7 @@ 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: src/tabular.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/tabular.h,v retrieving revision 1.45 diff -u -r1.45 tabular.h --- src/tabular.h 2001/12/04 16:10:16 1.45 +++ src/tabular.h 2001/12/11 14:39:12 @@ -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 @@ 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 @@ /// 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 @@ /// 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 @@ /// int width_of_column; /// - string p_width; + LyXLength p_width; /// string align_special; }; Index: src/frontends/xforms/ChangeLog =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/ChangeLog,v retrieving revision 1.209 diff -u -r1.209 ChangeLog --- src/frontends/xforms/ChangeLog 2001/12/10 12:50:08 1.209 +++ src/frontends/xforms/ChangeLog 2001/12/11 14:39:12 @@ -1,3 +1,8 @@ +2001-12-11 Jean-Marc Lasgouttes <[EMAIL PROTECTED]> + + * FormTabular.C: use LyXLength instead of string wherever + necessary; whitespace changes. + 2001-12-08 Jürgen Spitzmüller <[EMAIL PROTECTED]> * forms/form_preferences.fd: use the same name for font sizes Index: src/frontends/xforms/FormTabular.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/FormTabular.C,v retrieving revision 1.27 diff -u -r1.27 FormTabular.C --- src/frontends/xforms/FormTabular.C 2001/10/24 15:07:39 1.27 +++ src/frontends/xforms/FormTabular.C 2001/12/11 14:39:12 @@ -140,7 +140,7 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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: src/frontends/xforms/xforms_helpers.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/xforms_helpers.C,v retrieving revision 1.21 diff -u -r1.21 xforms_helpers.C --- src/frontends/xforms/xforms_helpers.C 2001/12/05 08:04:18 1.21 +++ src/frontends/xforms/xforms_helpers.C 2001/12/11 14:39:12 @@ -122,6 +122,24 @@ } +#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) @@ -179,8 +197,38 @@ 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: src/frontends/xforms/xforms_helpers.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/xforms_helpers.h,v retrieving revision 1.9 diff -u -r1.9 xforms_helpers.h --- src/frontends/xforms/xforms_helpers.h 2001/11/26 10:19:54 1.9 +++ src/frontends/xforms/xforms_helpers.h 2001/12/11 14:39:12 @@ -13,6 +13,7 @@ #include "Color.h" #include "support/lstrings.h" +#include "lyxlength.h" #include <vector> @@ -48,6 +49,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 { Index: src/insets/ChangeLog =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/ChangeLog,v retrieving revision 1.248 diff -u -r1.248 ChangeLog --- src/insets/ChangeLog 2001/12/10 13:30:27 1.248 +++ src/insets/ChangeLog 2001/12/11 14:39:12 @@ -1,6 +1,9 @@ 2001-12-10 Jean-Marc Lasgouttes <[EMAIL PROTECTED]> - * 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 <[EMAIL PROTECTED]> Index: src/insets/insettabular.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettabular.C,v retrieving revision 1.150 diff -u -r1.150 insettabular.C --- src/insets/insettabular.C 2001/12/10 01:22:12 1.150 +++ src/insets/insettabular.C 2001/12/11 14:39:12 @@ -1229,7 +1229,7 @@ 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 @@ 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 @@ 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 @@ 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 @@ // 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); }