]> git.lyx.org Git - features.git/commitdiff
restore 1.3 behaviour when changing tabular columns to variable width
authorGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Mon, 28 Nov 2005 11:52:03 +0000 (11:52 +0000)
committerGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Mon, 28 Nov 2005 11:52:03 +0000 (11:52 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10625 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/insets/ChangeLog
src/insets/insettabular.C
src/lyxtext.h
src/tabular.C
src/tabular.h
src/text2.C

index 00cae0fac5b6085734b2b184b06eb5fca14762fc..667588c451a0e3e432b8f63363a48771f025f741 100644 (file)
@@ -1,3 +1,11 @@
+2005-11-28  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
+
+       * 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  <j.spitzmueller@gmx.de>
 
        * paragraph.C (asString): use new inset->textString method (fix bug 2089)
index e5da1105962a9159062ffac978895ef793bc3b59..cda14ebe3b652beb0c40bb010f5f2cd79a7ee760 100644 (file)
@@ -1,3 +1,8 @@
+2005-11-28  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
+
+       * insettabular.C (tabularFeatures): Move some code to
+       setColumnPWidth and setMColumnPWidth
+
 2005-11-25  Jürgen Spitzmüller  <j.spitzmueller@gmx.de>
 
        * insetbase.h: 
index 630502a1472432caeb27889327efffd2d8ee067d..4d7b3085fe6b5ad303d303f2b39538607a103222 100644 (file)
@@ -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:
index a26b8136ae1bfb06d646c6c637c7c79194022be4..5a1fda886160a86ef6d47d74cdac3c5f121c5081 100644 (file)
@@ -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);
index 7775055f3e7064b983f109ca2e758d2dc49d1602..acbdae6fc535cb9adefb409dcee026dd43dfa15a 100644 (file)
 
 #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;
 }
 
index 8d73b28d5dcb11f7c9beb1d7a5360922f339fea1..93358d4ab069a98cb6f5e6ff3f5da20d49a73ffc 100644 (file)
@@ -24,6 +24,7 @@
 #include <vector>
 
 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);
index 059cd30e1be81c40756bf56bdace6a8707cdf191..b56898bf20b6efd0ac99dc414dc5eca707a272a9 100644 (file)
@@ -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());
 }