From bf18321b43f5bd7781efcd61a9eb1849ee4111aa Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Tue, 11 Dec 2001 17:26:52 +0000 Subject: [PATCH] use LyXLength for tabular pwidth git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3192 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 9 +++ src/frontends/xforms/ChangeLog | 5 ++ src/frontends/xforms/FormTabular.C | 100 +++++++++++++------------- src/frontends/xforms/xforms_helpers.C | 50 ++++++++++++- src/frontends/xforms/xforms_helpers.h | 8 +++ src/insets/ChangeLog | 5 +- src/insets/insettabular.C | 33 +++++---- src/tabular-old.C | 9 +++ src/tabular.C | 67 ++++++++++------- src/tabular.h | 15 ++-- 10 files changed, 204 insertions(+), 97 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index d564c506b7..dc8a2b76df 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2001-12-10 Jean-Marc Lasgouttes + + * 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 * paragraph.C: fixed missing line number count when exporting diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 7370ded464..329b608f76 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,8 @@ +2001-12-11 Jean-Marc Lasgouttes + + * FormTabular.C: use LyXLength instead of string wherever + necessary; whitespace changes. + 2001-12-08 Jürgen Spitzmüller * forms/form_preferences.fd: use the same name for font sizes diff --git a/src/frontends/xforms/FormTabular.C b/src/frontends/xforms/FormTabular.C index 40098e95a5..e8a3c70d60 100644 --- a/src/frontends/xforms/FormTabular.C +++ b/src/frontends/xforms/FormTabular.C @@ -140,7 +140,7 @@ void FormTabular::build() for (std::vector::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); diff --git a/src/frontends/xforms/xforms_helpers.C b/src/frontends/xforms/xforms_helpers.C index 9e1373e08c..07ecdadea5 100644 --- a/src/frontends/xforms/xforms_helpers.C +++ b/src/frontends/xforms/xforms_helpers.C @@ -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) { diff --git a/src/frontends/xforms/xforms_helpers.h b/src/frontends/xforms/xforms_helpers.h index f17fdd0758..ad3133a9ea 100644 --- a/src/frontends/xforms/xforms_helpers.h +++ b/src/frontends/xforms/xforms_helpers.h @@ -13,6 +13,7 @@ #include "Color.h" #include "support/lstrings.h" +#include "lyxlength.h" #include @@ -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; diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 940ab34dd4..5f59adb5f7 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,6 +1,9 @@ 2001-12-10 Jean-Marc Lasgouttes - * 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 diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 5e3c7fd2d5..ebc196602a 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -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); } diff --git a/src/tabular-old.C b/src/tabular-old.C index 4a014d3501..9c7c0cac7f 100644 --- a/src/tabular-old.C +++ b/src/tabular-old.C @@ -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) { diff --git a/src/tabular.C b/src/tabular.C index 3d3529753f..88adfa680b 100644 --- a/src/tabular.C +++ b/src/tabular.C @@ -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(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(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(f); cell_info[i][j].usebox = static_cast(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{"; diff --git a/src/tabular.h b/src/tabular.h index e93aa9f7e5..0da578f2ec 100644 --- a/src/tabular.h +++ b/src/tabular.h @@ -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; }; -- 2.39.2