* 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
This commit is contained in:
André Pönitz 2003-10-08 14:29:16 +00:00
parent 627f2c70fa
commit 6810aa2ab8
13 changed files with 128 additions and 113 deletions

View 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.

View 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.

View 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);
}

View 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;

View File

@ -64,60 +64,63 @@ using std::vector;
InsetText::InsetText(BufferParams const & bp)
: UpdatableInset(), text_(0, this, true, paragraphs)
: UpdatableInset(),
paragraphs(1),
autoBreakRows_(false),
drawFrame_(NEVER),
frame_color_(LColor::insetframe),
text_(0, this, true, paragraphs)
{
paragraphs.push_back(Paragraph());
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;
}

View 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 &);
///

View 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;

View File

@ -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; }

View 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

View 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;
}

View 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

View 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();
}

View 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_;
}