remove LyXParagraph Clone use newly added copy constructor instead, some whitespace changes

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1988 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2001-05-08 10:50:09 +00:00
parent da10b97545
commit 352479f603
16 changed files with 157 additions and 51 deletions

View File

@ -9,7 +9,6 @@ src/converter.C
src/CutAndPaste.C src/CutAndPaste.C
src/debug.C src/debug.C
src/exporter.C src/exporter.C
src/ext_l10n.h
src/figure_form.C src/figure_form.C
src/figureForm.C src/figureForm.C
src/FontLoader.C src/FontLoader.C

View File

@ -1,3 +1,11 @@
2001-05-08 Lars Gullik Bjønnes <larsbj@birdstep.com>
* lyxparagraph.[Ch]: add copy constructor, remove Clone
* CutAndPaste.C (copySelection): use LyXParagraph copy constructor
(pasteSelection): likewise
* text2.C (CreateUndo): likewise
2001-05-04 Lars Gullik Bjønnes <larsbj@birdstep.com> 2001-05-04 Lars Gullik Bjønnes <larsbj@birdstep.com>
* minibuffer.C (peek_event): temporarily reduce the functionality * minibuffer.C (peek_event): temporarily reduce the functionality

View File

@ -159,13 +159,21 @@ bool CutAndPaste::copySelection(LyXParagraph * startpar, LyXParagraph * endpar,
// copy more than one paragraph // copy more than one paragraph
// clone the paragraphs within the selection // clone the paragraphs within the selection
LyXParagraph * tmppar = startpar; LyXParagraph * tmppar = startpar;
#if 0
buf = tmppar->Clone(); buf = tmppar->Clone();
#else
buf = new LyXParagraph(*tmppar);
#endif
LyXParagraph * tmppar2 = buf; LyXParagraph * tmppar2 = buf;
while (tmppar != endpar while (tmppar != endpar
&& tmppar->next()) { && tmppar->next()) {
tmppar = tmppar->next(); tmppar = tmppar->next();
#if 0
tmppar2->next(tmppar->Clone()); tmppar2->next(tmppar->Clone());
#else
tmppar2->next(new LyXParagraph(*tmppar));
#endif
tmppar2->next()->previous(tmppar2); tmppar2->next()->previous(tmppar2);
tmppar2 = tmppar2->next(); tmppar2 = tmppar2->next();
} }
@ -195,14 +203,18 @@ bool CutAndPaste::pasteSelection(LyXParagraph ** par, LyXParagraph ** endpar,
if (pos > (*par)->size()) if (pos > (*par)->size())
pos = (*par)->size(); pos = (*par)->size();
LyXParagraph * tmpbuf; // LyXParagraph * tmpbuf;
LyXParagraph * tmppar = *par; LyXParagraph * tmppar = *par;
int tmppos = pos; int tmppos = pos;
// There are two cases: cutbuffer only one paragraph or many // There are two cases: cutbuffer only one paragraph or many
if (!buf->next()) { if (!buf->next()) {
// only within a paragraph // only within a paragraph
tmpbuf = buf->Clone(); #if 0
LyXParagraph * tmpbuf = buf->Clone();
#else
LyXParagraph * tmpbuf = new LyXParagraph(*buf);
#endif
// Some provisions should be done here for checking // Some provisions should be done here for checking
// if we are inserting at the beginning of a // if we are inserting at the beginning of a
// paragraph. If there are a space at the beginning // paragraph. If there are a space at the beginning
@ -230,12 +242,20 @@ bool CutAndPaste::pasteSelection(LyXParagraph ** par, LyXParagraph ** endpar,
// many paragraphs // many paragraphs
// make a copy of the simple cut_buffer // make a copy of the simple cut_buffer
tmpbuf = buf; LyXParagraph * tmpbuf = buf;
#if 0
LyXParagraph * simple_cut_clone = tmpbuf->Clone(); LyXParagraph * simple_cut_clone = tmpbuf->Clone();
#else
LyXParagraph * simple_cut_clone = new LyXParagraph(*tmpbuf);
#endif
LyXParagraph * tmpbuf2 = simple_cut_clone; LyXParagraph * tmpbuf2 = simple_cut_clone;
while (tmpbuf->next()) { while (tmpbuf->next()) {
tmpbuf = tmpbuf->next(); tmpbuf = tmpbuf->next();
#if 0
tmpbuf2->next(tmpbuf->Clone()); tmpbuf2->next(tmpbuf->Clone());
#else
tmpbuf2->next(new LyXParagraph(*tmpbuf));
#endif
tmpbuf2->next()->previous(tmpbuf2); tmpbuf2->next()->previous(tmpbuf2);
tmpbuf2 = tmpbuf2->next(); tmpbuf2 = tmpbuf2->next();
} }

View File

@ -1,3 +1,8 @@
2001-05-08 Lars Gullik Bjønnes <larsbj@birdstep.com>
* insettext.C (Read): use clear
(SetParagraphData): use LyXParagraph copy constructor instead of clone
2001-05-04 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr> 2001-05-04 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr>
* insetfloatlist.h: add a bunch of std:: qualifiers. * insetfloatlist.h: add a bunch of std:: qualifiers.

View File

@ -49,19 +49,6 @@ InsetCollapsable::InsetCollapsable()
} }
#if 0
Inset * InsetCollapsable::Clone(Buffer const &) const
{
InsetCollapsable * result = new InsetCollapsable;
result->inset.init(&inset);
result->inset.setOwner(result);
result->collapsed = collapsed;
return result;
}
#endif
bool InsetCollapsable::InsertInset(BufferView * bv, Inset * in) bool InsetCollapsable::InsertInset(BufferView * bv, Inset * in)
{ {
if (!InsertInsetAllowed(in)) { if (!InsertInsetAllowed(in)) {

View File

@ -42,8 +42,6 @@ public:
/// ///
InsetCollapsable(); InsetCollapsable();
/// ///
//Inset * Clone(Buffer const &) const;
///
void Read(Buffer const *, LyXLex &); void Read(Buffer const *, LyXLex &);
/// ///
void Write(Buffer const *, std::ostream &) const; void Write(Buffer const *, std::ostream &) const;
@ -132,9 +130,11 @@ public:
bool nodraw() const; bool nodraw() const;
/// ///
int scroll(bool recursive=true) const; int scroll(bool recursive=true) const;
///
void scroll(BufferView *bv, float sx) const { void scroll(BufferView *bv, float sx) const {
UpdatableInset::scroll(bv, sx); UpdatableInset::scroll(bv, sx);
} }
///
void scroll(BufferView *bv, int offset) const { void scroll(BufferView *bv, int offset) const {
UpdatableInset::scroll(bv, offset); UpdatableInset::scroll(bv, offset);
} }
@ -167,7 +167,6 @@ protected:
mutable int button_top_y; mutable int button_top_y;
/// ///
mutable int button_bottom_y; mutable int button_bottom_y;
private: private:
/// ///
string label; string label;

View File

@ -164,12 +164,14 @@ InsetGraphics::InsetGraphics()
: cacheHandle(0), imageLoaded(false) : cacheHandle(0), imageLoaded(false)
{} {}
InsetGraphics::~InsetGraphics() InsetGraphics::~InsetGraphics()
{ {
// Emits the hide signal to the dialog connected (if any) // Emits the hide signal to the dialog connected (if any)
hideDialog(); hideDialog();
} }
char const * char const *
InsetGraphics::statusMessage() const InsetGraphics::statusMessage() const
{ {
@ -202,6 +204,7 @@ InsetGraphics::statusMessage() const
return msg; return msg;
} }
int InsetGraphics::ascent(BufferView *, LyXFont const &) const int InsetGraphics::ascent(BufferView *, LyXFont const &) const
{ {
LyXImage * pixmap = 0; LyXImage * pixmap = 0;
@ -236,6 +239,7 @@ int InsetGraphics::width(BufferView *, LyXFont const & font) const
} }
} }
void InsetGraphics::draw(BufferView * bv, LyXFont const & font, void InsetGraphics::draw(BufferView * bv, LyXFont const & font,
int baseline, float & x, bool) const int baseline, float & x, bool) const
{ {
@ -406,7 +410,6 @@ InsetGraphics::createLatexOptions() const
} }
string const string const
InsetGraphics::prepareFile(Buffer const *buf) const InsetGraphics::prepareFile(Buffer const *buf) const
{ {
@ -457,6 +460,7 @@ InsetGraphics::prepareFile(Buffer const *buf) const
return outfile; return outfile;
} }
int InsetGraphics::Latex(Buffer const *buf, ostream & os, int InsetGraphics::Latex(Buffer const *buf, ostream & os,
bool /*fragile*/, bool/*fs*/) const bool /*fragile*/, bool/*fs*/) const
{ {
@ -542,6 +546,7 @@ int InsetGraphics::Linuxdoc(Buffer const *, ostream &) const
return 0; return 0;
} }
// For explanation on inserting graphics into DocBook checkout: // For explanation on inserting graphics into DocBook checkout:
// http://linuxdoc.org/LDP/LDP-Author-Guide/inserting-pictures.html // http://linuxdoc.org/LDP/LDP-Author-Guide/inserting-pictures.html
// See also the docbook guide at http://www.docbook.org/ // See also the docbook guide at http://www.docbook.org/
@ -571,6 +576,7 @@ void InsetGraphics::Validate(LaTeXFeatures & features) const
features.subfigure = true; features.subfigure = true;
} }
// Update the inset after parameters changed (read from file or changed in // Update the inset after parameters changed (read from file or changed in
// dialog. // dialog.
void InsetGraphics::updateInset() const void InsetGraphics::updateInset() const
@ -590,6 +596,7 @@ void InsetGraphics::updateInset() const
cacheHandle = temp; cacheHandle = temp;
} }
bool InsetGraphics::setParams(InsetGraphicsParams const & params) bool InsetGraphics::setParams(InsetGraphicsParams const & params)
{ {
// If nothing is changed, just return and say so. // If nothing is changed, just return and say so.
@ -606,13 +613,16 @@ bool InsetGraphics::setParams(InsetGraphicsParams const & params)
return true; return true;
} }
InsetGraphicsParams InsetGraphics::getParams() const InsetGraphicsParams InsetGraphics::getParams() const
{ {
return params; return params;
} }
Inset * InsetGraphics::Clone(Buffer const &) const Inset * InsetGraphics::Clone(Buffer const &) const
{ {
#warning use the copy constructor instead. (Lgb)
InsetGraphics * newInset = new InsetGraphics; InsetGraphics * newInset = new InsetGraphics;
newInset->cacheHandle = cacheHandle; newInset->cacheHandle = cacheHandle;

View File

@ -135,7 +135,7 @@ void InsetText::clear()
{ {
// delete all instances of LyXText before deleting the paragraps used // delete all instances of LyXText before deleting the paragraps used
// by it. // by it.
for (Cache::iterator cit = cache.begin(); cit != cache.end(); ++cit){ for (Cache::iterator cit = cache.begin(); cit != cache.end(); ++cit) {
delete (*cit).second; delete (*cit).second;
(*cit).second = 0; (*cit).second = 0;
} }
@ -177,6 +177,7 @@ void InsetText::Read(Buffer const * buf, LyXLex & lex)
char depth = 0; // signed or unsigned? char depth = 0; // signed or unsigned?
LyXFont font(LyXFont::ALL_INHERIT); LyXFont font(LyXFont::ALL_INHERIT);
#if 0
// delete all instances of LyXText before deleting the paragraps used // delete all instances of LyXText before deleting the paragraps used
// by it. // by it.
for (Cache::iterator cit = cache.begin(); cit != cache.end(); ++cit) { for (Cache::iterator cit = cache.begin(); cit != cache.end(); ++cit) {
@ -191,6 +192,10 @@ void InsetText::Read(Buffer const * buf, LyXLex & lex)
} }
par = new LyXParagraph; par = new LyXParagraph;
#else
clear();
#endif
while (lex.IsOK()) { while (lex.IsOK()) {
lex.nextToken(); lex.nextToken();
token = lex.GetString(); token = lex.GetString();
@ -1482,12 +1487,20 @@ void InsetText::SetParagraphData(LyXParagraph * p)
par = tmp; par = tmp;
} }
#if 0
par = p->Clone(); par = p->Clone();
#else
par = new LyXParagraph(*p);
#endif
par->SetInsetOwner(this); par->SetInsetOwner(this);
LyXParagraph * np = par; LyXParagraph * np = par;
while (p->next()) { while (p->next()) {
p = p->next(); p = p->next();
#if 0
np->next(p->Clone()); np->next(p->Clone());
#else
np->next(new LyXParagraph(*p));
#endif
np->next()->previous(np); np->next()->previous(np);
np = np->next(); np = np->next();
np->SetInsetOwner(this); np->SetInsetOwner(this);

View File

@ -88,6 +88,8 @@ public:
/// this constructor inserts the new paragraph in a list /// this constructor inserts the new paragraph in a list
explicit explicit
LyXParagraph(LyXParagraph * par); LyXParagraph(LyXParagraph * par);
///
LyXParagraph(LyXParagraph const &);
/// the destructor removes the new paragraph from the list /// the destructor removes the new paragraph from the list
~LyXParagraph(); ~LyXParagraph();
@ -130,9 +132,10 @@ public:
/// ///
LyXParagraph * TeXEnvironment(Buffer const *, BufferParams const &, LyXParagraph * TeXEnvironment(Buffer const *, BufferParams const &,
std::ostream &, TexRow & texrow); std::ostream &, TexRow & texrow);
#if 0
/// ///
LyXParagraph * Clone() const; LyXParagraph * Clone() const;
#endif
/// ///
bool HasSameLayout(LyXParagraph const * par) const; bool HasSameLayout(LyXParagraph const * par) const;

View File

@ -68,6 +68,7 @@ MathedArray::MathedArray(MathedArray const & array)
deep_copy(); deep_copy();
} }
void MathedArray::deep_copy() void MathedArray::deep_copy()
{ {
MathedIter it(this); MathedIter it(this);
@ -81,6 +82,7 @@ void MathedArray::deep_copy()
} }
} }
void MathedArray::substitute(MathMacro * m) void MathedArray::substitute(MathMacro * m)
{ {
if (m->nargs() == 0) if (m->nargs() == 0)
@ -125,6 +127,7 @@ MathedArray & MathedArray::operator=(MathedArray const & array)
return *this; return *this;
} }
void MathedArray::push_back(MathedInset * inset, int t) void MathedArray::push_back(MathedInset * inset, int t)
{ {
MathedIter it(this); MathedIter it(this);
@ -133,6 +136,7 @@ void MathedArray::push_back(MathedInset * inset, int t)
it.insertInset(inset, t); it.insertInset(inset, t);
} }
void MathedArray::push_back(byte b, MathedTextCodes c) void MathedArray::push_back(byte b, MathedTextCodes c)
{ {
MathedIter it(this); MathedIter it(this);
@ -141,6 +145,7 @@ void MathedArray::push_back(byte b, MathedTextCodes c)
it.insert(b, c); it.insert(b, c);
} }
void MathedArray::clear() void MathedArray::clear()
{ {
last_ = 0; last_ = 0;
@ -148,6 +153,7 @@ void MathedArray::clear()
bf_[0] = 0; bf_[0] = 0;
} }
void MathedArray::swap(MathedArray & array) void MathedArray::swap(MathedArray & array)
{ {
if (this != &array) { if (this != &array) {
@ -348,6 +354,7 @@ void MathedArray::dump2(ostream & os) const
os << endl; os << endl;
} }
void MathedArray::dump(ostream & os) const void MathedArray::dump(ostream & os) const
{ {
MathedIter it( const_cast<MathedArray*>(this) ); MathedIter it( const_cast<MathedArray*>(this) );
@ -371,5 +378,3 @@ void MathedArray::dump(ostream & os) const
it.Next(); it.Next();
} }
} }

View File

@ -12,6 +12,7 @@
using std::endl; using std::endl;
MathMacroArgument::MathMacroArgument(int n) MathMacroArgument::MathMacroArgument(int n)
: MathedInset(string(), LM_OT_MACRO_ARG, LM_ST_TEXT), : MathedInset(string(), LM_OT_MACRO_ARG, LM_ST_TEXT),
number_(n) number_(n)
@ -23,17 +24,20 @@ MathMacroArgument::MathMacroArgument(int n)
} }
} }
MathedInset * MathMacroArgument::Clone() MathedInset * MathMacroArgument::Clone()
{ {
//return new MathMacroArgument(*this); //return new MathMacroArgument(*this);
return this; return this;
} }
int MathMacroArgument::number() const int MathMacroArgument::number() const
{ {
return number_; return number_;
} }
void MathMacroArgument::substitute(MathMacro * /*m*/) void MathMacroArgument::substitute(MathMacro * /*m*/)
{ {
lyxerr << "Calling MathMacroArgument::substitute!\n"; lyxerr << "Calling MathMacroArgument::substitute!\n";

View File

@ -26,6 +26,7 @@ MathedRowContainer & MathParInset::getRowSt()
return row_; return row_;
} }
string MathParInset::label() const string MathParInset::label() const
{ {
if (row_.size() == 0) { if (row_.size() == 0) {
@ -53,6 +54,7 @@ MathedInset * MathParInset::Clone()
return new MathParInset(*this); return new MathParInset(*this);
} }
void MathParInset::substitute(MathMacro * m) void MathParInset::substitute(MathMacro * m)
{ {
//lyxerr << "called: MathParInset::substitute, m: " << m << endl; //lyxerr << "called: MathParInset::substitute, m: " << m << endl;

View File

@ -50,6 +50,7 @@ void MathSpaceInset::Write(ostream & os, bool /* fragile */)
} }
} }
void MathSpaceInset::WriteNormal(ostream & os) void MathSpaceInset::WriteNormal(ostream & os)
{ {
os << "[space " << space_ << "] "; os << "[space " << space_ << "] ";

View File

@ -119,6 +119,63 @@ LyXParagraph::LyXParagraph(LyXParagraph * par)
} }
LyXParagraph::LyXParagraph(LyXParagraph const & lp)
{
for (int i = 0; i < 10; ++i) setCounter(i , 0);
enumdepth = 0;
itemdepth = 0;
next_ = 0;
previous_ = 0;
id_ = paragraph_id++;
Clear();
MakeSameLayout(&lp);
// this is because of the dummy layout of the paragraphs that
// follow footnotes
layout = lp.layout;
inset_owner = lp.inset_owner;
// ale970302
if (lp.bibkey)
bibkey = static_cast<InsetBibKey *>
(lp.bibkey->Clone(*current_view->buffer()));
else
bibkey = 0;
// copy everything behind the break-position to the new paragraph
text = lp.text;
fontlist = lp.fontlist;
insetlist = lp.insetlist;
for (InsetList::iterator it = insetlist.begin();
it != insetlist.end(); ++it)
it->inset = it->inset->Clone(*current_view->buffer());
}
// the destructor removes the new paragraph from the list
LyXParagraph::~LyXParagraph()
{
if (previous_)
previous_->next_ = next_;
if (next_)
next_->previous_ = previous_;
for (InsetList::iterator it = insetlist.begin();
it != insetlist.end(); ++it) {
delete (*it).inset;
}
// ale970302
delete bibkey;
//
//lyxerr << "LyXParagraph::paragraph_id = "
// << LyXParagraph::paragraph_id << endl;
}
void LyXParagraph::writeFile(Buffer const * buf, ostream & os, void LyXParagraph::writeFile(Buffer const * buf, ostream & os,
BufferParams const & bparams, BufferParams const & bparams,
char footflag, char dth) const char footflag, char dth) const
@ -408,27 +465,6 @@ void LyXParagraph::Clear()
} }
// the destructor removes the new paragraph from the list
LyXParagraph::~LyXParagraph()
{
if (previous_)
previous_->next_ = next_;
if (next_)
next_->previous_ = previous_;
for (InsetList::iterator it = insetlist.begin();
it != insetlist.end(); ++it) {
delete (*it).inset;
}
// ale970302
delete bibkey;
//
//lyxerr << "LyXParagraph::paragraph_id = "
// << LyXParagraph::paragraph_id << endl;
}
void LyXParagraph::Erase(LyXParagraph::size_type pos) void LyXParagraph::Erase(LyXParagraph::size_type pos)
{ {
lyx::Assert(pos < size()); lyx::Assert(pos < size());
@ -1013,6 +1049,7 @@ int LyXParagraph::StripLeadingSpaces(LyXTextClassList::size_type tclass)
} }
#if 0
LyXParagraph * LyXParagraph::Clone() const LyXParagraph * LyXParagraph::Clone() const
{ {
// create a new paragraph // create a new paragraph
@ -1043,6 +1080,7 @@ LyXParagraph * LyXParagraph::Clone() const
(*it).inset = (*it).inset->Clone(*current_view->buffer()); (*it).inset = (*it).inset->Clone(*current_view->buffer());
return result; return result;
} }
#endif
bool LyXParagraph::HasSameLayout(LyXParagraph const * par) const bool LyXParagraph::HasSameLayout(LyXParagraph const * par) const

View File

@ -115,6 +115,12 @@ LyXTabular::LyXTabular(Buffer const * buf, InsetTabular * inset, LyXLex & lex)
LyXTabular & LyXTabular::operator=(LyXTabular const & lt) LyXTabular & LyXTabular::operator=(LyXTabular const & lt)
{ {
#if 0
#warning This while method should look like this: (Lgb)
LyXTabular tmp(lt);
tmp.swap(*this);
#else
// If this and lt is not of the same size we have a serious bug // If this and lt is not of the same size we have a serious bug
// So then it is ok to throw an exception, or for now // So then it is ok to throw an exception, or for now
// call abort() // call abort()
@ -134,7 +140,7 @@ LyXTabular & LyXTabular::operator=(LyXTabular const & lt)
rotate = lt.rotate; rotate = lt.rotate;
Reinit(); Reinit();
#endif
return *this; return *this;
} }

View File

@ -2672,8 +2672,6 @@ Undo * LyXText::CreateUndo(Buffer * buf, Undo::undo_kind kind,
} }
// create a new Undo // create a new Undo
LyXParagraph * undopar; LyXParagraph * undopar;
LyXParagraph * tmppar;
LyXParagraph * tmppar2;
LyXParagraph * start = 0; LyXParagraph * start = 0;
LyXParagraph * end = 0; LyXParagraph * end = 0;
@ -2691,8 +2689,12 @@ Undo * LyXText::CreateUndo(Buffer * buf, Undo::undo_kind kind,
} }
if (start && end && (start != end->next()) && if (start && end && (start != end->next()) &&
((before != behind) || (!before && !behind))) { ((before != behind) || (!before && !behind))) {
tmppar = start; LyXParagraph * tmppar = start;
tmppar2 = tmppar->Clone(); #if 0
LyXParagraph * tmppar2 = tmppar->Clone();
#else
LyXParagraph * tmppar2 = new LyXParagraph(*tmppar);
#endif
tmppar2->id(tmppar->id()); tmppar2->id(tmppar->id());
// a memory optimization: Just store the layout information // a memory optimization: Just store the layout information
@ -2706,7 +2708,11 @@ Undo * LyXText::CreateUndo(Buffer * buf, Undo::undo_kind kind,
while (tmppar != end && tmppar->next()) { while (tmppar != end && tmppar->next()) {
tmppar = tmppar->next(); tmppar = tmppar->next();
#if 0
tmppar2->next(tmppar->Clone()); tmppar2->next(tmppar->Clone());
#else
tmppar2->next(new LyXParagraph(*tmppar));
#endif
tmppar2->next()->id(tmppar->id()); tmppar2->next()->id(tmppar->id());
// a memory optimization: Just store the layout // a memory optimization: Just store the layout
// information when only edit // information when only edit