+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.
+
+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.
#endif
in_update(false), first_after_edit(false)
{
- inset.init(&(in.inset));
inset.setOwner(this);
}
#include "frontends/Painter.h"
#include "support/std_sstream.h"
+#include <iostream>
using lyx::graphics::PreviewLoader;
// 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;
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;
}
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);
///
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 &);
void lockInset(BufferView *, UpdatableInset *);
private:
+ ///
+ void init();
///
void lfunMousePress(FuncRequest const &);
///
// 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;
*/
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; }
///
mutable lyx::pos_type bidi_end;
- ///
- const bool in_inset_;
- ///
- ParagraphList & paragraphs_;
-
///
void charInserted();
public:
+ ///
+ bool in_inset_;
+ ///
+ ParagraphList * paragraphs_;
//
// special owner functions
///
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
/// 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;
// 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) {
}
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_;
// 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();
}
row_info.erase(row_info.begin() + row);
cell_info.erase(cell_info.begin() + row);
--rows_;
+ fixCellNums();
}
if (bp.tracking_changes)
cell_info[i][column + 1].inset.markNew(true);
}
+ fixCellNums();
}
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) {
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());
}
bool LyXTabular::isLastRow(int cell) const
{
- return (row_of_cell(cell) == rows_ - 1);
+ return row_of_cell(cell) == rows_ - 1;
}
///
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);
///
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
rit = boost::prior(pit->rows.end());
}
}
-
-
-bool LyXText::noRows() const
-{
- return ownerParagraphs().begin()->rows.empty();
-}
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)
{
}
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
ParagraphList & LyXText::ownerParagraphs() const
{
- return paragraphs_;
+ return *paragraphs_;
}