]> git.lyx.org Git - features.git/commitdiff
* lyxtext.h: make the paragraphs_ a pointer instead a ref to make the
authorAndré Pönitz <poenitz@gmx.net>
Wed, 8 Oct 2003 14:29:16 +0000 (14:29 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Wed, 8 Oct 2003 14:29:16 +0000 (14:29 +0000)
  thing assignable.
* text.C:
* text2.C: adjust

* tabular.[Ch]: fix crash after 'row-insert'

insets:

 * insetcollapsable.C:
  * insettext.[Ch]: saner 'init' structure

  * updatableinset.[Ch]: remove unneeded code

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7880 a592a061-630c-0410-9148-cb99ea01b6c8

13 files changed:
src/ChangeLog
src/insets/ChangeLog
src/insets/insetcollapsable.C
src/insets/insettabular.C
src/insets/insettext.C
src/insets/insettext.h
src/insets/updatableinset.C
src/insets/updatableinset.h
src/lyxtext.h
src/tabular.C
src/tabular.h
src/text.C
src/text2.C

index 258543c59c4d2494c816100d70f84e8809c331a2..50dbb29113f6462db15131c728d9c41dd891506c 100644 (file)
@@ -1,3 +1,12 @@
+2003-10-08  André Pönitz  <poenitz@gmx.net>
+
+       * lyxtext.h: make the paragraphs_ a pointer instead a ref to make the
+         thing assignable.
+       * text.C:
+       * text2.C: adjust
+
+       * tabular.[Ch]: fix crash after 'row-insert'
+
 2003-10-08  Angus Leeming  <leeming@lyx.org>
 
        Fix doxygen warnings.
index 46775fe0fb9f92b7d48b714c2bb767a20a480340..0d39bf7895710ebbfc355f94c063099d0a4e502c 100644 (file)
@@ -1,3 +1,11 @@
+
+2003-10-08  André Pönitz  <poenitz@gmx.net>
+
+       * insetcollapsable.C:
+       * insettext.[Ch]: saner 'init' structure
+
+       * updatableinset.[Ch]: remove unneeded code
+
 2003-10-08  Angus Leeming  <leeming@lyx.org>
 
        Fix doxygen warnings.
index fe670599719b19cd120301e8a7a6f766983a6d8b..5b6e09acf712beca2a3d3de94e886b8eba8230e6 100644 (file)
@@ -61,7 +61,6 @@ InsetCollapsable::InsetCollapsable(InsetCollapsable const & in)
 #endif
          in_update(false), first_after_edit(false)
 {
-       inset.init(&(in.inset));
        inset.setOwner(this);
 }
 
index ab4f7ef0f415c6c7ea1fba94be68c07ea9576897..f2383f1ac654ad3bbf5b3e27ea298d7c35b80c6a 100644 (file)
@@ -36,6 +36,7 @@
 #include "frontends/Painter.h"
 
 #include "support/std_sstream.h"
+#include <iostream>
 
 using lyx::graphics::PreviewLoader;
 
@@ -1679,12 +1680,16 @@ void InsetTabular::tabularFeatures(BufferView * bv,
                // append the row into the tabular
                unlockInsetInInset(bv, the_locking_inset);
                tabular.appendRow(bv->buffer()->params(), actcell);
+               tabular.setOwner(this);
+               //tabular.init(bv->buffer()->params(), tabular.rows(), tabular.columns());
                updateLocal(bv);
                break;
        case LyXTabular::APPEND_COLUMN:
                // append the column into the tabular
                unlockInsetInInset(bv, the_locking_inset);
                tabular.appendColumn(bv->buffer()->params(), actcell);
+               tabular.setOwner(this);
+               //tabular.init(bv->buffer()->params(), tabular.rows(), tabular.columns());
                actcell = tabular.getCellNumber(row, column);
                updateLocal(bv);
                break;
index 0cba30dba00173528802411e519b887d368bf6de..2e52695a2f3450c9ef284a1758195eeda9864481 100644 (file)
@@ -64,60 +64,63 @@ using std::vector;
 
 
 InsetText::InsetText(BufferParams const & bp)
-       : UpdatableInset(), text_(0, this, true, paragraphs)
-{
-       paragraphs.push_back(Paragraph());
+       : UpdatableInset(),
+         paragraphs(1),
+         autoBreakRows_(false),
+         drawFrame_(NEVER),
+         frame_color_(LColor::insetframe),
+         text_(0, this, true, paragraphs)
+{
+       textwidth_ = 0; // broken
        paragraphs.begin()->layout(bp.getLyXTextClass().defaultLayout());
        if (bp.tracking_changes)
                paragraphs.begin()->trackChanges();
-       init(0);
+       init();
 }
 
 
 InsetText::InsetText(InsetText const & in)
-       : UpdatableInset(in), text_(0, this, true, paragraphs)
+       : UpdatableInset(in),
+         text_(in.text_.bv_owner, this, true, paragraphs)
 {
-       init(&in);
+       // this is ugly...
+       operator=(in);
 }
 
 
-InsetText & InsetText::operator=(InsetText const & it)
+void InsetText::operator=(InsetText const & in)
 {
-       init(&it);
-       return *this;
+       UpdatableInset::operator=(in);
+       paragraphs = in.paragraphs;
+       autoBreakRows_ = in.autoBreakRows_;
+       drawFrame_ = in.drawFrame_;
+       frame_color_ = in.frame_color_;
+       textwidth_ = in.textwidth_;
+       text_ = LyXText(in.text_.bv_owner, this, true, paragraphs);
+       init();
 }
 
 
-void InsetText::init(InsetText const * ins)
+void InsetText::init()
 {
-       if (ins) {
-               textwidth_ = ins->textwidth_;
-               text_.bv_owner = ins->text_.bv_owner;
-
-               paragraphs = ins->paragraphs;
-
-               ParagraphList::iterator pit = paragraphs.begin();
-               ParagraphList::iterator end = paragraphs.end();
-               for (; pit != end; ++pit)
-                       pit->setInsetOwner(this);
-
-               autoBreakRows_ = ins->autoBreakRows_;
-               drawFrame_ = ins->drawFrame_;
-               setFrameColor(ins->frameColor());
-       } else {
-               textwidth_ = 0; // broken
-               drawFrame_ = NEVER;
-               setFrameColor(LColor::insetframe);
-               autoBreakRows_ = false;
-       }
-       the_locking_inset = 0;
-       for_each(paragraphs.begin(), paragraphs.end(),
-                boost::bind(&Paragraph::setInsetOwner, _1, this));
+       ParagraphList::iterator pit = paragraphs.begin();
+       ParagraphList::iterator end = paragraphs.end();
+       for (; pit != end; ++pit)
+               pit->setInsetOwner(this);
+       text_.paragraphs_ = &paragraphs;
        top_y = 0;
-       no_selection = true;
+
        locked = false;
+       inset_par = paragraphs.end();
+       inset_pos = 0;
+       inset_x = 0;
+       inset_y = 0;
+       no_selection = true;
+       the_locking_inset = 0;
        old_par = paragraphs.end();
        in_insetAllowed = false;
+       mouse_x = 0;
+       mouse_y = 0;
 }
 
 
index 26b601c242483505cfd7170d15d3f9bc7fae0e0e..5141cc6d26acb7d6fd9d8e3db4b27f1aac27a1a0 100644 (file)
@@ -49,13 +49,13 @@ public:
                ALWAYS
        };
        ///
-       InsetText(BufferParams const &);
+       explicit InsetText(BufferParams const &);
        ///
-       explicit InsetText(InsetText const &);
+       InsetText(InsetText const &);
        ///
        virtual std::auto_ptr<InsetBase> clone() const;
        ///
-       InsetText & operator=(InsetText const & it);
+       void operator=(InsetText const & it);
        /// empty inset to empty par, or just mark as erased
        void clear(bool just_mark_erased);
        ///
@@ -115,8 +115,6 @@ public:
                     bool toggleall = false,
                     bool selectall = false);
        ///
-       void init(InsetText const * ins);
-       ///
        void writeParagraphData(Buffer const &, std::ostream &) const;
        ///
        void setText(std::string const &, LyXFont const &);
@@ -210,6 +208,8 @@ protected:
        void lockInset(BufferView *, UpdatableInset *);
 
 private:
+       ///
+       void init();
        ///
        void lfunMousePress(FuncRequest const &);
        ///
index 6e229995f64c1c851b9ba700fabc8bdf72e4e550..fd5f6f5ffb273c51dcea7f456890be6b89acfd6a 100644 (file)
@@ -32,16 +32,6 @@ using std::string;
 
 // some stuff for inset locking
 
-UpdatableInset::UpdatableInset()
-       : InsetOld()
-{}
-
-
-UpdatableInset::UpdatableInset(UpdatableInset const & in)
-       : InsetOld(in)
-{}
-
-
 void UpdatableInset::insetUnlock(BufferView *)
 {
        lyxerr[Debug::INFO] << "Inset Unlock" << std::endl;
index 7dfe518d8613c61e83205ceb862d46091f0bcf5c..a27cf2d85c03ace1a1d1387e9a4795fd36b127df 100644 (file)
  */
 class UpdatableInset : public InsetOld {
 public:
-       ///
-       UpdatableInset();
-       ///
-       UpdatableInset(UpdatableInset const & in);
-
        /// check if the font of the char we want inserting is correct
        /// and modify it if it is not.
        virtual bool checkInsertChar(LyXFont &) { return true; }
index b440188a13c1ae47510c7e2c82dc3a5585c77dd7..c895f06cb457cd7791774bd3c220f0ef4ccbaf48 100644 (file)
@@ -466,14 +466,13 @@ private:
        ///
        mutable lyx::pos_type bidi_end;
 
-       ///
-       const bool in_inset_;
-       ///
-       ParagraphList & paragraphs_;
-
        ///
        void charInserted();
 public:
+       ///
+       bool in_inset_;
+       ///
+       ParagraphList * paragraphs_;
        //
        // special owner functions
        ///
@@ -495,15 +494,14 @@ public:
        void previousRow(ParagraphList::iterator & pit,
                RowList::iterator & rit) const;
 
-       ///
-       bool noRows() const;
-
 private:
        /** Cursor related data.
          Later this variable has to be removed. There should be now internal
          cursor in a text */
        ///
        ///TextCursor cursor_;
+       /// prohibit this as long as there are back pointers...
+       LyXText(LyXText const &);
 };
 
 /// return the default height of a row in pixels, considering font zoom
index f86490eb90b8511f872e4ddff07a86675277cba7..b1c0407efc923f82afc75b51ea26c3b615636528 100644 (file)
@@ -304,8 +304,8 @@ void l_getline(istream & is, string & str)
 
 /// Define a few methods for the inner structs
 
-LyXTabular::cellstruct::cellstruct(BufferParams const & bg)
-       : inset(bg)
+LyXTabular::cellstruct::cellstruct(BufferParams const & bp)
+       : inset(bp)
 {
        cellno = 0;
        width_of_cell = 0;
@@ -362,12 +362,30 @@ LyXTabular::LyXTabular(BufferParams const & bp, int rows_arg, int columns_arg)
 // activates all lines and sets all widths to 0
 void LyXTabular::init(BufferParams const & bp, int rows_arg, int columns_arg)
 {
-       rows_ = rows_arg;
+       rows_    = rows_arg;
        columns_ = columns_arg;
-       row_info = row_vector(rows_, rowstruct());
-       column_info = column_vector(columns_, columnstruct());
+       row_info = row_vector(rows_);
+       column_info = column_vector(columns_);
        cell_info = cell_vvector(rows_, cell_vector(columns_, cellstruct(bp)));
+       row_info.reserve(10);
+       column_info.reserve(10);
+       cell_info.reserve(100);
+       fixCellNums();
+       for (int i = 0; i < rows_; ++i)
+               cell_info[i].back().right_line = true;
+       row_info.back().bottom_line = true;
+       row_info.front().bottom_line = true;
+       column_info.back().right_line = true;
+       is_long_tabular = false;
+       rotate = false;
+}
+
 
+void LyXTabular::fixCellNums()
+{
+       BOOST_ASSERT(rows_ == row_info.size());
+       BOOST_ASSERT(columns_ == column_info.size());
+       BOOST_ASSERT(rows_ == cell_info.size());
        int cellno = 0;
        for (int i = 0; i < rows_; ++i) {
                for (int j = 0; j < columns_; ++j) {
@@ -376,25 +394,28 @@ void LyXTabular::init(BufferParams const & bp, int rows_arg, int columns_arg)
                }
                cell_info[i].back().right_line = true;
        }
-       row_info.back().bottom_line = true;
-       row_info.front().bottom_line = true;
-       column_info.back().right_line = true;
-       rowofcell.clear();
-       columnofcell.clear();
+
        set_row_column_number_info();
-       is_long_tabular = false;
-       rotate = false;
+       BOOST_ASSERT(rows_ == row_info.size());
+       BOOST_ASSERT(columns_ == column_info.size());
+       BOOST_ASSERT(rows_  == cell_info.size());
 }
 
 
 void LyXTabular::setOwner(InsetTabular * inset)
 {
        for (int i = 0; i < rows_; ++i)
-               for (int j = 0; j < columns_; ++j)
+               for (int j = 0; j < columns_; ++j) {
                        cell_info[i][j].inset.setOwner(inset);
+                       cell_info[i][j].inset.setDrawFrame(InsetText::LOCKED);
+               }
 }
 
 
+#warning for some strange reason, cellstruct does not seem to have copy-semantics
+
+// work around using 'swap' only...
+
 void LyXTabular::appendRow(BufferParams const & bp, int cell)
 {
        ++rows_;
@@ -406,30 +427,22 @@ void LyXTabular::appendRow(BufferParams const & bp, int cell)
        // now set the values of the row before
        row_info[row] = row_info[row + 1];
 
-#if 0
-       cell_vvector::iterator cit = cell_info.begin() + row;
-       cell_info.insert(cit, vector<cellstruct>(columns_, cellstruct(bp)));
-#else
+       cell_vvector old(rows_ - 1);
+       for (int i = 0; i < rows_ - 1; ++i)
+               swap(cell_info[i], old[i]);
 
-       cell_vvector c_info = cell_vvector(rows_, cell_vector(columns_,
-                                                             cellstruct(bp)));
+       cell_info = cell_vvector(rows_, cell_vector(columns_, cellstruct(bp)));
 
        for (int i = 0; i <= row; ++i)
-               for (int j = 0; j < columns_; ++j)
-                       c_info[i][j] = cell_info[i][j];
+               swap(cell_info[i], old[i]);
+       for (int i = row + 2; i < rows_; ++i)
+               swap(cell_info[i], old[i - 1]);
 
-       for (int i = row + 1; i < rows_; ++i)
+       if (bp.tracking_changes)
                for (int j = 0; j < columns_; ++j)
-                       c_info[i][j] = cell_info[i-1][j];
+                       cell_info[row + 1][j].inset.markNew(true);
 
-       cell_info = c_info;
-       ++row;
-       for (int j = 0; j < columns_; ++j) {
-               cell_info[row][j].inset.clear(false);
-               if (bp.tracking_changes)
-                       cell_info[row][j].inset.markNew(true);
-       }
-#endif
+       set_row_column_number_info();
 }
 
 
@@ -442,6 +455,7 @@ void LyXTabular::deleteRow(int row)
        row_info.erase(row_info.begin() + row);
        cell_info.erase(cell_info.begin() + row);
        --rows_;
+       fixCellNums();
 }
 
 
@@ -479,6 +493,7 @@ void LyXTabular::appendColumn(BufferParams const & bp, int cell)
                if (bp.tracking_changes)
                        cell_info[i][column + 1].inset.markNew(true);
        }
+       fixCellNums();
 }
 
 
@@ -492,10 +507,11 @@ void LyXTabular::deleteColumn(int column)
        for (int i = 0; i < rows_; ++i)
                cell_info[i].erase(cell_info[i].begin() + column);
        --columns_;
+       fixCellNums();
 }
 
 
-void LyXTabular::set_row_column_number_info(bool oldformat)
+void LyXTabular::set_row_column_number_info()
 {
        numberofcells = -1;
        for (int row = 0; row < rows_; ++row) {
@@ -532,14 +548,6 @@ void LyXTabular::set_row_column_number_info(bool oldformat)
                for (int column = 0; column < columns_; ++column) {
                        if (isPartOfMultiColumn(row,column))
                                continue;
-                       // now set the right line of multicolumns right for oldformat read
-                       if (oldformat &&
-                               cell_info[row][column].multicolumn == CELL_BEGIN_OF_MULTICOLUMN)
-                       {
-                               int cn = cells_in_multicolumn(cell_info[row][column].cellno);
-                               cell_info[row][column].right_line =
-                                       cell_info[row][column+cn-1].right_line;
-                       }
                        cell_info[row][column].inset.setAutoBreakRows(
                                !getPWidth(getCellNumber(row, column)).zero());
                }
@@ -648,7 +656,7 @@ bool LyXTabular::leftAlreadyDrawn(int cell) const
 
 bool LyXTabular::isLastRow(int cell) const
 {
-       return (row_of_cell(cell) == rows_ - 1);
+       return row_of_cell(cell) == rows_ - 1;
 }
 
 
index dec907d30ad891ee9cb356134acfbc410793caf4..2775ad6d27822e7565bf271be69cbba32c757e02 100644 (file)
@@ -502,7 +502,7 @@ public:
        ///
        void init(BufferParams const &, int rows_arg, int columns_arg);
        ///
-       void set_row_column_number_info(bool oldformat = false);
+       void set_row_column_number_info();
        /// Returns true if a complete update is necessary, otherwise false
        bool setWidthOfMulticolCell(int cell, int new_width);
        ///
@@ -554,6 +554,10 @@ public:
                                           bool onlydata) const;
        /// auxiliary function for docbook
        int docbookRow(Buffer const & buf, std::ostream & os, int row) const;
+
+private:
+       /// renumber cells after structural changes
+       void fixCellNums();
 };
 
 #endif
index acbbf7acbf881fbb78ee88286ae6aebdf7f460c3..b337daa5279014756072893d566eddfee4a9a56c 100644 (file)
@@ -2073,9 +2073,3 @@ void LyXText::previousRow(ParagraphList::iterator & pit,
                rit = boost::prior(pit->rows.end());
        }
 }
-
-
-bool LyXText::noRows() const
-{
-       return ownerParagraphs().begin()->rows.empty();
-}
index e6e5a65ada8249ad3d9d6de1b5c19be93f22c6d4..f4f373f7525315c86cf52b5398c53dc5153566b8 100644 (file)
@@ -72,7 +72,7 @@ LyXText::LyXText(BufferView * bv, InsetText * inset, bool ininset,
          ParagraphList & paragraphs)
        : height(0), width(0), anchor_y_(0),
          inset_owner(inset), the_locking_inset(0), bv_owner(bv),
-         in_inset_(ininset), paragraphs_(paragraphs)
+         in_inset_(ininset), paragraphs_(&paragraphs)
 {
 }
 
@@ -1341,7 +1341,9 @@ void LyXText::setCursor(LyXCursor & cur, ParagraphList::iterator pit,
        cur.par(pit);
        cur.pos(pos);
        cur.boundary(boundary);
-       if (noRows())
+
+       // no rows, no fun...
+       if (ownerParagraphs().begin()->rows.empty())
                return;
 
        // get the cursor y position in text
@@ -1872,7 +1874,7 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
 
 ParagraphList & LyXText::ownerParagraphs() const
 {
-       return paragraphs_;
+       return *paragraphs_;
 }