From 6810aa2ab8606a9e1a2d67b80b46ac982dc592d4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Wed, 8 Oct 2003 14:29:16 +0000 Subject: [PATCH] * 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' 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 --- src/ChangeLog | 9 ++++ src/insets/ChangeLog | 8 ++++ src/insets/insetcollapsable.C | 1 - src/insets/insettabular.C | 5 ++ src/insets/insettext.C | 71 ++++++++++++++------------- src/insets/insettext.h | 10 ++-- src/insets/updatableinset.C | 10 ---- src/insets/updatableinset.h | 5 -- src/lyxtext.h | 14 +++--- src/tabular.C | 90 +++++++++++++++++++---------------- src/tabular.h | 6 ++- src/text.C | 6 --- src/text2.C | 8 ++-- 13 files changed, 129 insertions(+), 114 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 258543c59c..50dbb29113 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2003-10-08 André Pönitz + + * 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 Fix doxygen warnings. diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 46775fe0fb..0d39bf7895 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,11 @@ + +2003-10-08 André Pönitz + + * insetcollapsable.C: + * insettext.[Ch]: saner 'init' structure + + * updatableinset.[Ch]: remove unneeded code + 2003-10-08 Angus Leeming Fix doxygen warnings. diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index fe67059971..5b6e09acf7 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -61,7 +61,6 @@ InsetCollapsable::InsetCollapsable(InsetCollapsable const & in) #endif in_update(false), first_after_edit(false) { - inset.init(&(in.inset)); inset.setOwner(this); } diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index ab4f7ef0f4..f2383f1ac6 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -36,6 +36,7 @@ #include "frontends/Painter.h" #include "support/std_sstream.h" +#include 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; diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 0cba30dba0..2e52695a2f 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -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_ = ¶graphs; 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; } diff --git a/src/insets/insettext.h b/src/insets/insettext.h index 26b601c242..5141cc6d26 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -49,13 +49,13 @@ public: ALWAYS }; /// - InsetText(BufferParams const &); + explicit InsetText(BufferParams const &); /// - explicit InsetText(InsetText const &); + InsetText(InsetText const &); /// virtual std::auto_ptr 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 &); /// diff --git a/src/insets/updatableinset.C b/src/insets/updatableinset.C index 6e229995f6..fd5f6f5ffb 100644 --- a/src/insets/updatableinset.C +++ b/src/insets/updatableinset.C @@ -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; diff --git a/src/insets/updatableinset.h b/src/insets/updatableinset.h index 7dfe518d86..a27cf2d85c 100644 --- a/src/insets/updatableinset.h +++ b/src/insets/updatableinset.h @@ -48,11 +48,6 @@ */ 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; } diff --git a/src/lyxtext.h b/src/lyxtext.h index b440188a13..c895f06cb4 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -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 diff --git a/src/tabular.C b/src/tabular.C index f86490eb90..b1c0407efc 100644 --- a/src/tabular.C +++ b/src/tabular.C @@ -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(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; } diff --git a/src/tabular.h b/src/tabular.h index dec907d30a..2775ad6d27 100644 --- a/src/tabular.h +++ b/src/tabular.h @@ -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 diff --git a/src/text.C b/src/text.C index acbbf7acbf..b337daa527 100644 --- a/src/text.C +++ b/src/text.C @@ -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(); -} diff --git a/src/text2.C b/src/text2.C index e6e5a65ada..f4f373f752 100644 --- a/src/text2.C +++ b/src/text2.C @@ -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_(¶graphs) { } @@ -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_; } -- 2.39.2