revert r30531, which causes a crash when copying an inset.

Basically, insets in cut stack do not have a buffer, and therefore cannot
acess to buffer parameters. What is annoying here is that acceptChanges 
requires this buffer params only to be able to read a font in moveItem,
in order to read the buffer language, and I doubt this is really needed...

Another change in this patch is that Inset::getLayout now returns a 
plainLayout when the inset does not have a buffer_. This fixes a remaining 
crash where dEPM reads isFreeSpacing() for an inset in the clipboard, but
this looks like a fragile situation. And it will not do the right thing when
doing depm in a freespacing inset.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30605 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jean-Marc Lasgouttes 2009-07-15 14:19:10 +00:00
parent 5d904d95e7
commit c3be74085f
10 changed files with 32 additions and 25 deletions

View File

@ -362,7 +362,8 @@ Change const & Paragraph::lookupChange(pos_type pos) const
} }
void Paragraph::acceptChanges(pos_type start, pos_type end) void Paragraph::acceptChanges(BufferParams const & bparams, pos_type start,
pos_type end)
{ {
LASSERT(start >= 0 && start <= size(), /**/); LASSERT(start >= 0 && start <= size(), /**/);
LASSERT(end > start && end <= size() + 1, /**/); LASSERT(end > start && end <= size() + 1, /**/);
@ -372,14 +373,14 @@ void Paragraph::acceptChanges(pos_type start, pos_type end)
case Change::UNCHANGED: case Change::UNCHANGED:
// accept changes in nested inset // accept changes in nested inset
if (Inset * inset = getInset(pos)) if (Inset * inset = getInset(pos))
inset->acceptChanges(); inset->acceptChanges(bparams);
break; break;
case Change::INSERTED: case Change::INSERTED:
d->changes_.set(Change(Change::UNCHANGED), pos); d->changes_.set(Change(Change::UNCHANGED), pos);
// also accept changes in nested inset // also accept changes in nested inset
if (Inset * inset = getInset(pos)) if (Inset * inset = getInset(pos))
inset->acceptChanges(); inset->acceptChanges(bparams);
break; break;
case Change::DELETED: case Change::DELETED:
@ -397,7 +398,8 @@ void Paragraph::acceptChanges(pos_type start, pos_type end)
} }
void Paragraph::rejectChanges(pos_type start, pos_type end) void Paragraph::rejectChanges(BufferParams const & bparams,
pos_type start, pos_type end)
{ {
LASSERT(start >= 0 && start <= size(), /**/); LASSERT(start >= 0 && start <= size(), /**/);
LASSERT(end > start && end <= size() + 1, /**/); LASSERT(end > start && end <= size() + 1, /**/);
@ -407,7 +409,7 @@ void Paragraph::rejectChanges(pos_type start, pos_type end)
case Change::UNCHANGED: case Change::UNCHANGED:
// reject changes in nested inset // reject changes in nested inset
if (Inset * inset = getInset(pos)) if (Inset * inset = getInset(pos))
inset->rejectChanges(); inset->rejectChanges(bparams);
break; break;
case Change::INSERTED: case Change::INSERTED:

View File

@ -229,10 +229,10 @@ public:
void setChange(pos_type pos, Change const & change); void setChange(pos_type pos, Change const & change);
/// accept changes within the given range /// accept changes within the given range
void acceptChanges(pos_type start, pos_type end); void acceptChanges(BufferParams const & bparams, pos_type start, pos_type end);
/// reject changes within the given range /// reject changes within the given range
void rejectChanges(pos_type start, pos_type end); void rejectChanges(BufferParams const & bparams, pos_type start, pos_type end);
/// Paragraphs can contain "manual labels", for example, Description /// Paragraphs can contain "manual labels", for example, Description
/// environment. The text for this user-editable label is stored in /// environment. The text for this user-editable label is stored in

View File

@ -840,9 +840,9 @@ void Text::acceptOrRejectChanges(Cursor & cur, ChangeOp op)
pos_type right = (pit == endPit ? endPos : parSize); pos_type right = (pit == endPit ? endPos : parSize);
if (op == ACCEPT) { if (op == ACCEPT) {
pars_[pit].acceptChanges(left, right); pars_[pit].acceptChanges(cur.buffer()->params(), left, right);
} else { } else {
pars_[pit].rejectChanges(left, right); pars_[pit].rejectChanges(cur.buffer()->params(), left, right);
} }
} }
@ -919,7 +919,7 @@ void Text::rejectChanges(BufferParams const & bparams)
// (do not consider end-of-par) // (do not consider end-of-par)
for (pit_type pit = 0; pit < pars_size; ++pit) { for (pit_type pit = 0; pit < pars_size; ++pit) {
if (!pars_[pit].empty()) // prevent assertion failure if (!pars_[pit].empty()) // prevent assertion failure
pars_[pit].rejectChanges(0, pars_[pit].size()); pars_[pit].rejectChanges(bparams, 0, pars_[pit].size());
} }
// next, reject imaginary end-of-par characters // next, reject imaginary end-of-par characters

View File

@ -461,6 +461,8 @@ bool Inset::covers(BufferView const & bv, int x, int y) const
InsetLayout const & Inset::getLayout() const InsetLayout const & Inset::getLayout() const
{ {
if (!buffer_)
return DocumentClass::plainInsetLayout();
return buffer().params().documentClass().insetLayout(name()); return buffer().params().documentClass().insetLayout(name());
} }

View File

@ -27,6 +27,7 @@ namespace lyx {
class BiblioInfo; class BiblioInfo;
class Buffer; class Buffer;
class BufferParams;
class BufferView; class BufferView;
class Change; class Change;
class CompletionList; class CompletionList;
@ -486,9 +487,9 @@ public:
/// set the change for the entire inset /// set the change for the entire inset
virtual void setChange(Change const &) {} virtual void setChange(Change const &) {}
/// accept the changes within the inset /// accept the changes within the inset
virtual void acceptChanges() {}; virtual void acceptChanges(BufferParams const &) {};
/// reject the changes within the inset /// reject the changes within the inset
virtual void rejectChanges() {}; virtual void rejectChanges(BufferParams const &) {};
/// ///
virtual Dimension const dimension(BufferView const &) const; virtual Dimension const dimension(BufferView const &) const;

View File

@ -5152,17 +5152,17 @@ void InsetTabular::setChange(Change const & change)
} }
void InsetTabular::acceptChanges() void InsetTabular::acceptChanges(BufferParams const & bparams)
{ {
for (idx_type idx = 0; idx < nargs(); ++idx) for (idx_type idx = 0; idx < nargs(); ++idx)
cell(idx)->acceptChanges(); cell(idx)->acceptChanges(bparams);
} }
void InsetTabular::rejectChanges() void InsetTabular::rejectChanges(BufferParams const & bparams)
{ {
for (idx_type idx = 0; idx < nargs(); ++idx) for (idx_type idx = 0; idx < nargs(); ++idx)
cell(idx)->rejectChanges(); cell(idx)->rejectChanges(bparams);
} }

View File

@ -48,6 +48,7 @@
namespace lyx { namespace lyx {
class Buffer; class Buffer;
class BufferParams;
class BufferView; class BufferView;
class CompletionList; class CompletionList;
class CursorSlice; class CursorSlice;
@ -802,9 +803,9 @@ public:
/// set the change for the entire inset /// set the change for the entire inset
void setChange(Change const & change); void setChange(Change const & change);
/// accept the changes within the inset /// accept the changes within the inset
void acceptChanges(); void acceptChanges(BufferParams const & bparams);
/// reject the changes within the inset /// reject the changes within the inset
void rejectChanges(); void rejectChanges(BufferParams const & bparams);
// this should return true if we have a "normal" cell, otherwise false. // this should return true if we have a "normal" cell, otherwise false.
// "normal" means without width set! // "normal" means without width set!

View File

@ -355,15 +355,15 @@ void InsetText::setChange(Change const & change)
} }
void InsetText::acceptChanges() void InsetText::acceptChanges(BufferParams const & bparams)
{ {
text_.acceptChanges(buffer().params()); text_.acceptChanges(bparams);
} }
void InsetText::rejectChanges() void InsetText::rejectChanges(BufferParams const & bparams)
{ {
text_.rejectChanges(buffer().params()); text_.rejectChanges(bparams);
} }

View File

@ -21,6 +21,7 @@
namespace lyx { namespace lyx {
class BufferParams;
class CompletionList; class CompletionList;
class CursorSlice; class CursorSlice;
class Dimension; class Dimension;
@ -115,9 +116,9 @@ public:
/// set the change for the entire inset /// set the change for the entire inset
void setChange(Change const & change); void setChange(Change const & change);
/// accept the changes within the inset /// accept the changes within the inset
void acceptChanges(); void acceptChanges(BufferParams const & bparams);
/// reject the changes within the inset /// reject the changes within the inset
void rejectChanges(); void rejectChanges(BufferParams const & bparams);
/// append text onto the existing text /// append text onto the existing text
void appendParagraphs(ParagraphList &); void appendParagraphs(ParagraphList &);

View File

@ -354,7 +354,7 @@ void acceptChanges(ParagraphList & pars, BufferParams const & bparams)
// (do not consider end-of-par) // (do not consider end-of-par)
for (pit_type pit = 0; pit < pars_size; ++pit) { for (pit_type pit = 0; pit < pars_size; ++pit) {
if (!pars[pit].empty()) // prevent assertion failure if (!pars[pit].empty()) // prevent assertion failure
pars[pit].acceptChanges(0, pars[pit].size()); pars[pit].acceptChanges(bparams, 0, pars[pit].size());
} }
// next, accept imaginary end-of-par characters // next, accept imaginary end-of-par characters