mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
* Do not keep pointers to data structures around if you don't know
whether the data structure outlives the pointer: InsetLayouts are really owned by the corresponding TextClass. So keep the TextClass alive by keeping a TextClassPtr around for the pointers lifetime. This fixes Bug #4538. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22782 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
790411d174
commit
2f1699747a
@ -445,17 +445,15 @@ void switchBetweenClasses(TextClassPtr const & c1,
|
||||
if (inset->lyxCode() != FLEX_CODE)
|
||||
// FIXME: Should we verify all InsetCollapsable?
|
||||
continue;
|
||||
docstring const name = inset->name();
|
||||
InsetLayout const & il = tclass2.insetlayout(name);
|
||||
inset->setLayout(il);
|
||||
if (il.labelstring != from_utf8("UNDEFINED"))
|
||||
inset->setLayout(c2);
|
||||
if (inset->getLayout().labelstring != from_utf8("UNDEFINED"))
|
||||
continue;
|
||||
// The flex inset is undefined in tclass2
|
||||
docstring const s = bformat(_(
|
||||
"Flex inset %1$s is "
|
||||
"undefined because of class "
|
||||
"conversion from\n%2$s to %3$s"),
|
||||
name, from_utf8(tclass1.name()),
|
||||
inset->name(), from_utf8(tclass1.name()),
|
||||
from_utf8(tclass2.name()));
|
||||
// To warn the user that something had to be done.
|
||||
errorlist.push_back(ErrorItem(
|
||||
|
@ -102,9 +102,7 @@ Inset * createInset(Buffer & buf, FuncRequest const & cmd)
|
||||
|
||||
case LFUN_FLEX_INSERT: {
|
||||
string s = cmd.getArg(0);
|
||||
TextClass const & tclass = params.getTextClass();
|
||||
InsetLayout const & il = tclass.insetlayout(from_utf8(s));
|
||||
return new InsetFlex(params, il);
|
||||
return new InsetFlex(params, params.getTextClassPtr(), s);
|
||||
}
|
||||
|
||||
case LFUN_NOTE_INSERT: {
|
||||
@ -385,8 +383,6 @@ Inset * readInset(Lexer & lex, Buffer const & buf)
|
||||
|
||||
auto_ptr<Inset> inset;
|
||||
|
||||
TextClass const & tclass = buf.params().getTextClass();
|
||||
|
||||
lex.next();
|
||||
string tmptok = lex.getString();
|
||||
|
||||
@ -480,8 +476,8 @@ Inset * readInset(Lexer & lex, Buffer const & buf)
|
||||
} else if (tmptok == "Flex") {
|
||||
lex.next();
|
||||
string s = lex.getString();
|
||||
InsetLayout const & il = tclass.insetlayout(from_utf8(s));
|
||||
inset.reset(new InsetFlex(buf.params(), il));
|
||||
inset.reset(new InsetFlex(buf.params(),
|
||||
buf.params().getTextClassPtr(), s));
|
||||
} else if (tmptok == "Branch") {
|
||||
inset.reset(new InsetBranch(buf.params(),
|
||||
InsetBranchParams()));
|
||||
|
@ -74,10 +74,11 @@ InsetCollapsable::Geometry InsetCollapsable::geometry() const
|
||||
|
||||
|
||||
InsetCollapsable::InsetCollapsable(BufferParams const & bp,
|
||||
CollapseStatus status, InsetLayout const * il)
|
||||
: InsetText(bp), layout_(il), status_(status),
|
||||
CollapseStatus status, TextClassPtr tc)
|
||||
: InsetText(bp), status_(status),
|
||||
openinlined_(false), autoOpen_(false), mouse_hover_(false)
|
||||
{
|
||||
setLayout(tc);
|
||||
setAutoBreakRows(true);
|
||||
setDrawFrame(true);
|
||||
setFrameColor(Color_collapsableframe);
|
||||
@ -86,6 +87,7 @@ InsetCollapsable::InsetCollapsable(BufferParams const & bp,
|
||||
|
||||
InsetCollapsable::InsetCollapsable(InsetCollapsable const & rhs)
|
||||
: InsetText(rhs),
|
||||
textClass_(rhs.textClass_),
|
||||
layout_(rhs.layout_),
|
||||
labelstring_(rhs.labelstring_),
|
||||
button_dim(rhs.button_dim),
|
||||
@ -116,14 +118,20 @@ docstring InsetCollapsable::toolTip(BufferView const & bv, int x, int y) const
|
||||
|
||||
void InsetCollapsable::setLayout(BufferParams const & bp)
|
||||
{
|
||||
setLayout(bp.getTextClass().insetlayout(name()));
|
||||
setLayout(bp.getTextClassPtr());
|
||||
}
|
||||
|
||||
|
||||
void InsetCollapsable::setLayout(InsetLayout const & il)
|
||||
void InsetCollapsable::setLayout(TextClassPtr tc)
|
||||
{
|
||||
layout_ = &il;
|
||||
labelstring_ = layout_->labelstring;
|
||||
textClass_ = tc;
|
||||
if ( tc.get() != 0 ) {
|
||||
layout_ = &tc->insetlayout(name());
|
||||
labelstring_ = layout_->labelstring;
|
||||
} else {
|
||||
layout_ = 0;
|
||||
labelstring_ = _("UNDEFINED");
|
||||
}
|
||||
|
||||
setButtonLabel();
|
||||
}
|
||||
|
@ -19,6 +19,8 @@
|
||||
#include "InsetText.h"
|
||||
|
||||
#include "Box.h"
|
||||
#include "TextClass.h"
|
||||
#include "TextClassPtr.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
@ -41,7 +43,7 @@ public:
|
||||
InsetCollapsable(
|
||||
BufferParams const &,
|
||||
CollapseStatus status = Inset::Open,
|
||||
InsetLayout const * il = 0
|
||||
TextClassPtr tc = TextClassPtr((TextClass *)0)
|
||||
);
|
||||
///
|
||||
InsetCollapsable(InsetCollapsable const & rhs);
|
||||
@ -52,10 +54,13 @@ public:
|
||||
docstring name() const { return from_ascii("Collapsable"); }
|
||||
InsetLayout const & getLayout(BufferParams const &) const
|
||||
{ return *layout_; }
|
||||
InsetLayout const & getLayout() const
|
||||
{ return *layout_; }
|
||||
///
|
||||
void setLayout(BufferParams const &);
|
||||
/// (Re-)set the character style parameters from \p il
|
||||
void setLayout(InsetLayout const & il);
|
||||
/// (Re-)set the character style parameters from \p tc according
|
||||
/// to name()
|
||||
void setLayout(TextClassPtr tc);
|
||||
///
|
||||
void read(Buffer const &, Lexer &);
|
||||
///
|
||||
@ -165,10 +170,11 @@ protected:
|
||||
///
|
||||
virtual void resetParagraphsFont();
|
||||
|
||||
protected:
|
||||
///
|
||||
InsetLayout const * layout_;
|
||||
private:
|
||||
/// text class to keep the InsetLayout above in memory
|
||||
TextClassPtr textClass_;
|
||||
/// cache for the layout_. Make sure it is in sync with the text class!
|
||||
InsetLayout const * layout_;
|
||||
///
|
||||
Dimension dimensionCollapsed() const;
|
||||
///
|
||||
|
@ -43,12 +43,13 @@ namespace lyx {
|
||||
|
||||
|
||||
InsetFlex::InsetFlex(BufferParams const & bp,
|
||||
InsetLayout const & il)
|
||||
: InsetCollapsable(bp, Collapsed, &il)
|
||||
TextClassPtr tc, string const & layoutName)
|
||||
: InsetCollapsable(bp, Collapsed, tc),
|
||||
name_(layoutName)
|
||||
{
|
||||
name_ = il.name;
|
||||
packages_ = il.requires;
|
||||
preamble_ = il.preamble;
|
||||
setLayout(tc); // again, because now the name is initialized
|
||||
packages_ = getLayout().requires;
|
||||
preamble_ = getLayout().preamble;
|
||||
}
|
||||
|
||||
|
||||
@ -65,7 +66,7 @@ Inset * InsetFlex::clone() const
|
||||
|
||||
bool InsetFlex::undefined() const
|
||||
{
|
||||
return layout_->labelstring == from_utf8("UNDEFINED");
|
||||
return getLayout().labelstring == from_utf8("UNDEFINED");
|
||||
}
|
||||
|
||||
|
||||
@ -118,8 +119,8 @@ int InsetFlex::docbook(Buffer const & buf, odocstream & os,
|
||||
ParagraphList::const_iterator end = paragraphs().end();
|
||||
|
||||
if (!undefined())
|
||||
sgml::openTag(os, layout_->latexname,
|
||||
par->getID(buf, runparams) + layout_->latexparam);
|
||||
sgml::openTag(os, getLayout().latexname,
|
||||
par->getID(buf, runparams) + getLayout().latexparam);
|
||||
|
||||
for (; par != end; ++par) {
|
||||
par->simpleDocBookOnePar(buf, os, runparams,
|
||||
@ -128,7 +129,7 @@ int InsetFlex::docbook(Buffer const & buf, odocstream & os,
|
||||
}
|
||||
|
||||
if (!undefined())
|
||||
sgml::closeTag(os, layout_->latexname);
|
||||
sgml::closeTag(os, getLayout().latexname);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
#include "InsetCollapsable.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace lyx {
|
||||
|
||||
@ -25,7 +26,8 @@ namespace lyx {
|
||||
class InsetFlex : public InsetCollapsable {
|
||||
public:
|
||||
///
|
||||
InsetFlex(BufferParams const &, InsetLayout const &);
|
||||
InsetFlex(BufferParams const &,
|
||||
TextClassPtr tc, string const & layoutName);
|
||||
///
|
||||
docstring name() const { return from_utf8(name_); }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user