From: Georg Baum Date: Mon, 28 Nov 2005 11:52:03 +0000 (+0000) Subject: restore 1.3 behaviour when changing tabular columns to variable width X-Git-Tag: 1.6.10~13774 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=dd6c706cef7f7c29b0a6c988d3a8de22bbf195ac;p=features.git restore 1.3 behaviour when changing tabular columns to variable width git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10625 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/ChangeLog b/src/ChangeLog index 00cae0fac5..667588c451 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2005-11-28 Georg Baum + + * text2.C (setLayout): move recUndo call to other setLayout method + * tabular.C (toggleFixedWidth): new, handle cell width changes + * tabular.C (setColumnPWidth): move some code from insettabular.C here + and use toggleFixedWidth + * tabular.C (setMColumnPWidth): ditto + 2005-11-25 Jürgen Spitzmüller * paragraph.C (asString): use new inset->textString method (fix bug 2089) diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index e5da110596..cda14ebe3b 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,8 @@ +2005-11-28 Georg Baum + + * insettabular.C (tabularFeatures): Move some code to + setColumnPWidth and setMColumnPWidth + 2005-11-25 Jürgen Spitzmüller * insetbase.h: diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 630502a147..4d7b3085fe 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -1422,10 +1422,7 @@ void InsetTabular::tabularFeatures(LCursor & cur, case LyXTabular::SET_PWIDTH: { LyXLength const len(value); - tabular.setColumnPWidth(cur.idx(), len); - // cur position can become invalid after newlines were removed - if (cur.pos() > cur.lastpos()) - cur.pos() = cur.lastpos(); + tabular.setColumnPWidth(cur, cur.idx(), len); if (len.zero() && tabular.getAlignment(cur.idx(), true) == LYX_ALIGN_BLOCK) tabularFeatures(cur, LyXTabular::ALIGN_CENTER, string()); @@ -1433,10 +1430,7 @@ void InsetTabular::tabularFeatures(LCursor & cur, } case LyXTabular::SET_MPWIDTH: - tabular.setMColumnPWidth(cur.idx(), LyXLength(value)); - // cur position can become invalid after newlines were removed - if (cur.pos() > cur.lastpos()) - cur.pos() = cur.lastpos(); + tabular.setMColumnPWidth(cur, cur.idx(), LyXLength(value)); break; case LyXTabular::SET_SPECIAL_COLUMN: diff --git a/src/lyxtext.h b/src/lyxtext.h index a26b8136ae..5a1fda8861 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -75,7 +75,7 @@ public: void breakParagraph(LCursor & cur, bool keep_layout = false); /// set layout over selection - pit_type setLayout(pit_type start, pit_type end, + void setLayout(pit_type start, pit_type end, std::string const & layout); /// void setLayout(LCursor & cur, std::string const & layout); diff --git a/src/tabular.C b/src/tabular.C index 7775055f3e..acbdae6fc5 100644 --- a/src/tabular.C +++ b/src/tabular.C @@ -21,11 +21,14 @@ #include "buffer.h" #include "bufferparams.h" +#include "BufferView.h" +#include "cursor.h" #include "debug.h" #include "LaTeXFeatures.h" #include "lyxlex.h" #include "outputparams.h" #include "paragraph.h" +#include "paragraph_funcs.h" #include "insets/insettabular.h" @@ -872,7 +875,36 @@ void LyXTabular::setVAlignment(idx_type cell, VAlignment align, } -void LyXTabular::setColumnPWidth(idx_type cell, LyXLength const & width) +namespace { + +/** + * Allow line and paragraph breaks for fixed width cells or disallow them, + * merge cell paragraphs and reset layout to standard for variable width + * cells. + */ +void toggleFixedWidth(LCursor & cur, InsetText * inset, bool fixedWidth) +{ + inset->setAutoBreakRows(fixedWidth); + if (fixedWidth) + return; + + // merge all paragraphs to one + BufferParams const & bp = + inset->getText(0)->bv_owner->buffer()->params(); + while (inset->paragraphs().size() > 1) + mergeParagraph(bp, inset->paragraphs(), 0); + + // reset layout + cur.push(*inset); + inset->getText(0)->setLayout(0, cur.lastpit() + 1, "Standard"); + cur.pop(); +} + +} + + +void LyXTabular::setColumnPWidth(LCursor & cur, idx_type cell, + LyXLength const & width) { col_type const j = column_of_cell(cell); @@ -880,18 +912,32 @@ void LyXTabular::setColumnPWidth(idx_type cell, LyXLength const & width) for (row_type i = 0; i < rows_; ++i) { idx_type const cell = getCellNumber(i, j); // because of multicolumns - getCellInset(cell)->setAutoBreakRows(!getPWidth(cell).zero()); + toggleFixedWidth(cur, getCellInset(cell).get(), + !getPWidth(cell).zero()); } + // cur paragraph can become invalid after paragraphs were merged + if (cur.pit() > cur.lastpit()) + cur.pit() = cur.lastpit(); + // cur position can become invalid after newlines were removed + if (cur.pos() > cur.lastpos()) + cur.pos() = cur.lastpos(); } -bool LyXTabular::setMColumnPWidth(idx_type cell, LyXLength const & width) +bool LyXTabular::setMColumnPWidth(LCursor & cur, idx_type cell, + LyXLength const & width) { if (!isMultiColumn(cell)) return false; cellinfo_of_cell(cell).p_width = width; - getCellInset(cell)->setAutoBreakRows(!width.zero()); + toggleFixedWidth(cur, getCellInset(cell).get(), !width.zero()); + // cur paragraph can become invalid after paragraphs were merged + if (cur.pit() > cur.lastpit()) + cur.pit() = cur.lastpit(); + // cur position can become invalid after newlines were removed + if (cur.pos() > cur.lastpos()) + cur.pos() = cur.lastpos(); return true; } diff --git a/src/tabular.h b/src/tabular.h index 8d73b28d5d..93358d4ab0 100644 --- a/src/tabular.h +++ b/src/tabular.h @@ -24,6 +24,7 @@ #include class InsetTabular; +class LCursor; class OutputParams; /* The features the text class offers for tables */ @@ -241,9 +242,9 @@ public: void setVAlignment(idx_type cell, VAlignment align, bool onlycolumn = false); /// - void setColumnPWidth(idx_type cell, LyXLength const & width); + void setColumnPWidth(LCursor &, idx_type, LyXLength const &); /// - bool setMColumnPWidth(idx_type cell, LyXLength const & width); + bool setMColumnPWidth(LCursor &, idx_type, LyXLength const &); /// void setAlignSpecial(idx_type cell, std::string const & special, Feature what); diff --git a/src/text2.C b/src/text2.C index 059cd30e1b..b56898bf20 100644 --- a/src/text2.C +++ b/src/text2.C @@ -318,11 +318,9 @@ pit_type LyXText::undoSpan(pit_type pit) } -pit_type LyXText::setLayout(pit_type start, pit_type end, string const & layout) +void LyXText::setLayout(pit_type start, pit_type end, string const & layout) { BOOST_ASSERT(start != end); - pit_type undopit = undoSpan(end - 1); - recUndo(start, undopit - 1); BufferParams const & bufparams = bv()->buffer()->params(); LyXLayout_ptr const & lyxlayout = bufparams.getLyXTextClass()[layout]; @@ -333,8 +331,6 @@ pit_type LyXText::setLayout(pit_type start, pit_type end, string const & layout) if (lyxlayout->margintype == MARGIN_MANUAL) pars_[pit].setLabelWidthString(lyxlayout->labelstring()); } - - return undopit; } @@ -361,6 +357,8 @@ void LyXText::setLayout(LCursor & cur, string const & layout) pit_type start = cur.selBegin().pit(); pit_type end = cur.selEnd().pit() + 1; + pit_type undopit = undoSpan(end - 1); + recUndo(start, undopit - 1); setLayout(start, end, layout); updateCounters(cur.buffer()); }