From ff36293942a2c10913ae8775bfdc53562d0fc128 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrgen=20Vigna?= Date: Wed, 19 Dec 2001 21:25:34 +0000 Subject: [PATCH] More fixes for longtable options, still more to come. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3253 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/xforms/FormTabular.C | 73 +++++++++------- src/insets/insettabular.C | 29 ++++--- src/tabular-old.C | 21 ++++- src/tabular.C | 130 +++++++++++++++++------------ src/tabular.h | 36 ++++---- 5 files changed, 176 insertions(+), 113 deletions(-) diff --git a/src/frontends/xforms/FormTabular.C b/src/frontends/xforms/FormTabular.C index 9f8a3f0593..d92c765ae2 100644 --- a/src/frontends/xforms/FormTabular.C +++ b/src/frontends/xforms/FormTabular.C @@ -370,51 +370,65 @@ void FormTabular::update() if (enable) { LyXTabular::ltType ltt; - fl_set_button(longtable_options_->radio_lt_firsthead, - tabular->GetRowOfLTFirstHead(row, ltt)); - if (ltt.row && !ltt.empty) { - fl_set_button(longtable_options_->check_1head_2border_above, - ltt.topDL); - fl_set_button(longtable_options_->check_1head_2border_above, - ltt.topDL); - } else { - setEnabled(longtable_options_->check_1head_2border_above, 0); - setEnabled(longtable_options_->check_1head_2border_below, 0); - fl_set_button(longtable_options_->check_1head_2border_above,0); - fl_set_button(longtable_options_->check_1head_2border_above,0); - fl_set_button(longtable_options_->check_1head_empty,ltt.empty); - if (ltt.empty) - setEnabled(longtable_options_->radio_lt_firsthead, 0); - } - fl_set_button(longtable_options_->radio_lt_head, - tabular->GetRowOfLTHead(row, ltt)); - if (ltt.row) { + bool use_empty; + bool row_set = tabular->GetRowOfLTHead(row, ltt); + fl_set_button(longtable_options_->radio_lt_head, row_set); + if (row_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 (row_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); + } } - fl_set_button(longtable_options_->radio_lt_foot, - tabular->GetRowOfLTFoot(row, ltt)); - if (ltt.row) { + // + row_set = tabular->GetRowOfLTFoot(row, ltt); + fl_set_button(longtable_options_->radio_lt_foot, row_set); + if (row_set) { fl_set_button(longtable_options_->check_foot_2border_above, ltt.topDL); fl_set_button(longtable_options_->check_foot_2border_above, ltt.topDL); + use_empty = true; } else { setEnabled(longtable_options_->check_foot_2border_above, 0); setEnabled(longtable_options_->check_foot_2border_below, 0); fl_set_button(longtable_options_->check_foot_2border_above,0); fl_set_button(longtable_options_->check_foot_2border_above,0); + fl_set_button(longtable_options_->check_lastfoot_empty, 0); + setEnabled(longtable_options_->check_lastfoot_empty, 0); + use_empty = false; } - fl_set_button(longtable_options_->radio_lt_lastfoot, - tabular->GetRowOfLTLastFoot(row, ltt)); - if (ltt.row && !ltt.empty) { + // + row_set = tabular->GetRowOfLTLastFoot(row, ltt); + fl_set_button(longtable_options_->radio_lt_lastfoot, row_set); + if (row_set && (!ltt.empty || !use_empty)) { fl_set_button(longtable_options_->check_lastfoot_2border_above, ltt.topDL); fl_set_button(longtable_options_->check_lastfoot_2border_above, @@ -424,9 +438,12 @@ void FormTabular::update() setEnabled(longtable_options_->check_lastfoot_2border_below,0); fl_set_button(longtable_options_->check_lastfoot_2border_above, 0); fl_set_button(longtable_options_->check_lastfoot_2border_above, 0); - fl_set_button(longtable_options_->check_lastfoot_empty, ltt.empty); - if (ltt.empty) - setEnabled(longtable_options_->radio_lt_lastfoot, 0); + if (use_empty) { + fl_set_button(longtable_options_->check_lastfoot_empty, + ltt.empty); + if (ltt.empty) + setEnabled(longtable_options_->radio_lt_lastfoot, 0); + } } fl_set_button(longtable_options_->radio_lt_newpage, tabular->GetLTNewPage(row)); diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 56ee3f2926..d8a6f8212a 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -1670,20 +1670,19 @@ bool InsetTabular::tabularFeatures(BufferView * bv, string const & what) } static void checkLongtableSpecial(LyXTabular::ltType & ltt, - string const & special, - int const row, bool const flag) + string const & special, bool & flag) { if (special == "dl_above") { ltt.topDL = flag; + flag = true; } else if (special == "dl_below") { ltt.bottomDL = flag; + flag = true; } else if (special == "empty") { ltt.empty = flag; - } else { - if (flag) - ltt.row = row; - else - ltt.row = 0; + flag = false; + } else if (flag) { + ltt.empty = false; } } @@ -1994,29 +1993,29 @@ void InsetTabular::tabularFeatures(BufferView * bv, flag = false; case LyXTabular::SET_LTFIRSTHEAD: (void)tabular->GetRowOfLTFirstHead(row, ltt); - checkLongtableSpecial(ltt, value, row + 1, flag); - tabular->SetLTHead(ltt, true); + checkLongtableSpecial(ltt, value, flag); + tabular->SetLTHead(row, flag, ltt, true); break; case LyXTabular::UNSET_LTHEAD: flag = false; case LyXTabular::SET_LTHEAD: (void)tabular->GetRowOfLTHead(row, ltt); - checkLongtableSpecial(ltt, value, row + 1, flag); - tabular->SetLTHead(ltt, false); + checkLongtableSpecial(ltt, value, flag); + tabular->SetLTHead(row, flag, ltt, false); break; case LyXTabular::UNSET_LTFOOT: flag = false; case LyXTabular::SET_LTFOOT: (void)tabular->GetRowOfLTFoot(row, ltt); - checkLongtableSpecial(ltt, value, row + 1, flag); - tabular->SetLTFoot(ltt, false); + checkLongtableSpecial(ltt, value, flag); + tabular->SetLTFoot(row, flag, ltt, false); break; case LyXTabular::UNSET_LTLASTFOOT: flag = false; case LyXTabular::SET_LTLASTFOOT: (void)tabular->GetRowOfLTLastFoot(row, ltt); - checkLongtableSpecial(ltt, value, row + 1, flag); - tabular->SetLTFoot(ltt, true); + checkLongtableSpecial(ltt, value, flag); + tabular->SetLTFoot(row, flag, ltt, true); break; case LyXTabular::SET_LTNEWPAGE: { diff --git a/src/tabular-old.C b/src/tabular-old.C index 9c7c0cac7f..33d23c79ef 100644 --- a/src/tabular-old.C +++ b/src/tabular-old.C @@ -166,10 +166,23 @@ void LyXTabular::ReadOld(Buffer const * buf, istream & is, return; } getTokenValue(line, "islongtable", is_long_tabular); - getTokenValue(line, "endhead", endhead.row); - getTokenValue(line, "endfirsthead", endfirsthead.row); - getTokenValue(line, "endfoot", endfoot.row); - getTokenValue(line, "endlastfoot", endlastfoot.row); + int hrow; + int fhrow; + int frow; + int lfrow; + + getTokenValue(line, "endhead", hrow); + getTokenValue(line, "endfirsthead", fhrow); + getTokenValue(line, "endfoot", frow); + getTokenValue(line, "endlastfoot", lfrow); + if (abs(hrow) > 0) + row_info[abs(hrow)-1].endhead = true; + if (abs(fhrow)) + row_info[abs(fhrow)-1].endfirsthead = true; + if (abs(frow)) + row_info[abs(frow)-1].endfoot = true; + if (abs(lfrow)) + row_info[abs(lfrow)-1].endlastfoot = true; for (int i = 0; i < rows_; ++i) { l_getline(is, line); diff --git a/src/tabular.C b/src/tabular.C index 4ae7a62122..d151ce58fc 100644 --- a/src/tabular.C +++ b/src/tabular.C @@ -79,6 +79,10 @@ LyXTabular::rowstruct::rowstruct() bottom_line = false; ascent_of_row = 0; descent_of_row = 0; + endhead = false; + endfirsthead = false; + endfoot = false; + endlastfoot = false; newpage = false; } @@ -95,7 +99,6 @@ LyXTabular::columnstruct::columnstruct() LyXTabular::lttype::lttype() { - row = 0; topDL = false; bottomDL = false; empty = false; @@ -161,14 +164,7 @@ LyXTabular & LyXTabular::operator=(LyXTabular const & lt) cell_info = lt.cell_info; row_info = lt.row_info; column_info = lt.column_info; - - // long tabular stuff SetLongTabular(lt.is_long_tabular); - endhead = lt.endhead; - endfoot = lt.endfoot; - endfirsthead = lt.endfirsthead; - endlastfoot = lt.endlastfoot; - rotate = lt.rotate; Reinit(); @@ -232,10 +228,6 @@ void LyXTabular::Init(int rows_arg, int columns_arg, LyXTabular const * lt) set_row_column_number_info(); is_long_tabular = false; rotate = false; - endhead.row = 0; - endfirsthead.row = 0; - endfoot.row = 0; - endlastfoot.row = 0; } @@ -1119,7 +1111,7 @@ void LyXTabular::Write(Buffer const * buf, ostream & os) const { // header line os << "\n"; @@ -1127,10 +1119,16 @@ void LyXTabular::Write(Buffer const * buf, ostream & os) const os << "\n"; for (int j = 0; j < columns_; ++j) { os << "\n"; for (int j = 0; j < columns_; ++j) { @@ -1349,13 +1351,13 @@ void LyXTabular::Read(Buffer const * buf, LyXLex & lex) return; if (version == 1) ReadOld(buf, is, lex, line); - else if (version == 2) - ReadNew(buf, is, lex, line); + else if (version >= 2) + ReadNew(buf, is, lex, line, version); } void LyXTabular::ReadNew(Buffer const * buf, istream & is, - LyXLex & lex, string const & l) + LyXLex & lex, string const & l, int const version) { string line(l); int rows_arg; @@ -1373,14 +1375,37 @@ void LyXTabular::ReadNew(Buffer const * buf, istream & is, } getTokenValue(line, "rotate", rotate); getTokenValue(line, "islongtable", is_long_tabular); - getTokenValue(line, "endhead", endhead.row); - getTokenValue(line, "endfirsthead", endfirsthead.row); - getTokenValue(line, "endfoot", endfoot.row); - getTokenValue(line, "endlastfoot", endlastfoot.row); - endhead.row = abs(endhead.row); - endfirsthead.row = abs(endfirsthead.row); - endfoot.row = abs(endfoot.row); - endlastfoot.row = abs(endlastfoot.row); + // compatibility read for old longtable options + if (version < 3) { + int hrow; + int fhrow; + int frow; + int lfrow; + + getTokenValue(line, "endhead", hrow); + getTokenValue(line, "endfirsthead", fhrow); + getTokenValue(line, "endfoot", frow); + getTokenValue(line, "endlastfoot", lfrow); + if (abs(hrow) > 0) + row_info[abs(hrow)-1].endhead = true; + if (abs(fhrow)) + row_info[abs(fhrow)-1].endfirsthead = true; + if (abs(frow)) + row_info[abs(frow)-1].endfoot = true; + if (abs(lfrow)) + row_info[abs(lfrow)-1].endlastfoot = true; + } else { + getTokenValue(line, "firstHeadTopDL", endfirsthead.topDL); + getTokenValue(line, "firstHeadBottomDL", endfirsthead.bottomDL); + getTokenValue(line, "firstHeadEmpty", endfirsthead.empty); + getTokenValue(line, "headTopDL", endhead.topDL); + getTokenValue(line, "headBottomDL", endhead.bottomDL); + getTokenValue(line, "footTopDL", endfoot.topDL); + getTokenValue(line, "footBottomDL", endfoot.bottomDL); + getTokenValue(line, "lastFootTopDL", endlastfoot.topDL); + getTokenValue(line, "lastFootBottomDL", endlastfoot.bottomDL); + getTokenValue(line, "lastFootEmpty", endlastfoot.empty); + } for (int j = 0; j < columns_; ++j) { l_getline(is,line); if (!prefixIs(line,"(rows_arg); SetLongTabular(is_long_tabular_arg); SetRotateTabular(rotate_arg); - endhead.row = a + 1; - endfirsthead.row = b + 1; - endfoot.row = c + 1; - endlastfoot.row = d + 1; + row_info[a].endhead = true; + row_info[b].endfirsthead = true; + row_info[c].endfoot = true; + row_info[d].endlastfoot = true; for (i = 0; i < rows_; ++i) { a = b = c = d = e = f = g = 0; is >> a >> b >> c >> d; @@ -1860,20 +1885,15 @@ LyXTabular::BoxType LyXTabular::GetUsebox(int cell) const return UseParbox(cell); } -bool LyXTabular::checkLTType(int row, ltType const & ltt) const -{ - if (!ltt.row || (ltt.row > rows_)) - return false; - return (row == (ltt.row - 1)); -} - -void LyXTabular::SetLTHead(ltType const & hd, bool first) +void LyXTabular::SetLTHead(int row, bool flag, ltType const & hd, bool first) { if (first) { endfirsthead = hd; + row_info[row].endfirsthead = flag; } else { endhead = hd; + row_info[row].endhead = flag; } } @@ -1881,23 +1901,25 @@ void LyXTabular::SetLTHead(ltType const & hd, bool first) bool LyXTabular::GetRowOfLTHead(int row, ltType & hd) const { hd = endhead; - return checkLTType(row, hd); + return row_info[row].endhead; } bool LyXTabular::GetRowOfLTFirstHead(int row, ltType & hd) const { hd = endfirsthead; - return checkLTType(row, hd); + return row_info[row].endfirsthead; } -void LyXTabular::SetLTFoot(ltType const & fd, bool last) +void LyXTabular::SetLTFoot(int row, bool flag, ltType const & fd, bool last) { if (last) { endlastfoot = fd; + row_info[row].endlastfoot = flag; } else { endfoot = fd; + row_info[row].endfoot = flag; } } @@ -1905,14 +1927,14 @@ void LyXTabular::SetLTFoot(ltType const & fd, bool last) bool LyXTabular::GetRowOfLTFoot(int row, ltType & fd) const { fd = endfoot; - return checkLTType(row, fd); + return row_info[row].endfoot; } bool LyXTabular::GetRowOfLTLastFoot(int row, ltType & fd) const { fd = endlastfoot; - return checkLTType(row, fd); + return row_info[row].endlastfoot; } @@ -2255,25 +2277,25 @@ int LyXTabular::Latex(Buffer const * buf, ++ret; ret += TeXBottomHLine(os, i); if (IsLongTabular()) { - if (i == (endhead.row - 1)) { + if (row_info[i].endhead) { if (endhead.bottomDL) ret += TeXBottomHLine(os, i); os << "\\endhead\n"; ++ret; } - if (i == (endfirsthead.row - 1)) { + if (row_info[i].endfirsthead) { if (endfirsthead.bottomDL) ret += TeXBottomHLine(os, i); os << "\\endfirsthead\n"; ++ret; } - if (i == (endfoot.row - 1)) { + if (row_info[i].endfoot) { if (endfoot.bottomDL) ret += TeXBottomHLine(os, i); os << "\\endfoot\n"; ++ret; } - if (i == (endlastfoot.row - 1)) { + if (row_info[i].endlastfoot) { if (endlastfoot.bottomDL) ret += TeXBottomHLine(os, i); os << "\\endlastfoot\n"; @@ -2386,9 +2408,12 @@ int LyXTabular::DocBook(Buffer const * buf, ostream & os) const //+ Long Tabular case + //+--------------------------------------------------------------------- +#warning Jose please have a look here I changed the longtable header/footer +#warning ---- options so I had to disable the docbook code (Jug 20011219) +#if 0 if ( IsLongTabular() ) { // Header - if( endhead.row || endfirsthead.row ) { + if(endhead.row || endfirsthead.row ) { os << "\n"; if( endfirsthead.row ) { docbookRow( buf, os, endfirsthead.row - 1); @@ -2411,6 +2436,7 @@ int LyXTabular::DocBook(Buffer const * buf, ostream & os) const os << "\n"; } } +#endif //+--------------------------------------------------------------------- //+ the single row and columns (cells) + //+--------------------------------------------------------------------- @@ -2418,8 +2444,8 @@ int LyXTabular::DocBook(Buffer const * buf, ostream & os) const os << "\n"; for (int i = 0; i < rows_; ++i) { if(!IsLongTabular() || ( - i != endhead.row - 1 && i != endfirsthead.row - 1 && - i != endfoot.row - 1 && i != endlastfoot.row - 1)) { + !row_info[i].endhead && !row_info[i].endfirsthead && + !row_info[i].endfoot && !row_info[i].endlastfoot)) { docbookRow( buf, os, i); } } diff --git a/src/tabular.h b/src/tabular.h index f13a86ac4e..8393379e5d 100644 --- a/src/tabular.h +++ b/src/tabular.h @@ -161,8 +161,6 @@ public: struct lttype { // constructor lttype(); - // row of the header/footer type end definition - int row; // double borders on top bool topDL; // double borders on bottom @@ -368,13 +366,13 @@ public: /// bool checkLTType(int row, ltType const &) const; /// - void SetLTHead(ltType const &, bool first); + void SetLTHead(int row, bool flag, ltType const &, bool first); /// bool GetRowOfLTHead(int row, ltType &) const; /// bool GetRowOfLTFirstHead(int row, ltType &) const; /// - void SetLTFoot(ltType const &, bool last); + void SetLTFoot(int row, bool flag, ltType const &, bool last); /// bool GetRowOfLTFoot(int row, ltType &) const; /// @@ -446,14 +444,23 @@ private: /// rowstruct(); /// - bool top_line; - /// - bool bottom_line; - /// int ascent_of_row; /// int descent_of_row; + /// + bool top_line; + /// + bool bottom_line; /// This are for longtabulars only + /// a row of endhead + bool endhead; + /// a row of endfirsthead + bool endfirsthead; + /// a row of endfoot + bool endfoot; + /// row of endlastfoot + bool endlastfoot; + /// row for a pagebreak bool newpage; }; /// @@ -483,7 +490,7 @@ private: /// void ReadNew(Buffer const * buf, std::istream & is, - LyXLex & lex, string const & l); + LyXLex & lex, string const & l, int const version); /// void ReadOld(Buffer const * buf, std::istream & is, LyXLex & lex, string const & l); @@ -509,16 +516,17 @@ private: bool rotate; // // for long tabulars - /// + // bool is_long_tabular; - /// row of endhead + /// endhead data ltType endhead; - /// row of endfirsthead + /// endfirsthead data ltType endfirsthead; - /// row of endfoot + /// endfoot data ltType endfoot; - /// row of endlastfoot + /// endlastfoot data ltType endlastfoot; + // /// InsetTabular * owner_; -- 2.39.5