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)
|
if (inset->lyxCode() != FLEX_CODE)
|
||||||
// FIXME: Should we verify all InsetCollapsable?
|
// FIXME: Should we verify all InsetCollapsable?
|
||||||
continue;
|
continue;
|
||||||
docstring const name = inset->name();
|
inset->setLayout(c2);
|
||||||
InsetLayout const & il = tclass2.insetlayout(name);
|
if (inset->getLayout().labelstring != from_utf8("UNDEFINED"))
|
||||||
inset->setLayout(il);
|
|
||||||
if (il.labelstring != from_utf8("UNDEFINED"))
|
|
||||||
continue;
|
continue;
|
||||||
// The flex inset is undefined in tclass2
|
// The flex inset is undefined in tclass2
|
||||||
docstring const s = bformat(_(
|
docstring const s = bformat(_(
|
||||||
"Flex inset %1$s is "
|
"Flex inset %1$s is "
|
||||||
"undefined because of class "
|
"undefined because of class "
|
||||||
"conversion from\n%2$s to %3$s"),
|
"conversion from\n%2$s to %3$s"),
|
||||||
name, from_utf8(tclass1.name()),
|
inset->name(), from_utf8(tclass1.name()),
|
||||||
from_utf8(tclass2.name()));
|
from_utf8(tclass2.name()));
|
||||||
// To warn the user that something had to be done.
|
// To warn the user that something had to be done.
|
||||||
errorlist.push_back(ErrorItem(
|
errorlist.push_back(ErrorItem(
|
||||||
|
@ -102,9 +102,7 @@ Inset * createInset(Buffer & buf, FuncRequest const & cmd)
|
|||||||
|
|
||||||
case LFUN_FLEX_INSERT: {
|
case LFUN_FLEX_INSERT: {
|
||||||
string s = cmd.getArg(0);
|
string s = cmd.getArg(0);
|
||||||
TextClass const & tclass = params.getTextClass();
|
return new InsetFlex(params, params.getTextClassPtr(), s);
|
||||||
InsetLayout const & il = tclass.insetlayout(from_utf8(s));
|
|
||||||
return new InsetFlex(params, il);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case LFUN_NOTE_INSERT: {
|
case LFUN_NOTE_INSERT: {
|
||||||
@ -385,8 +383,6 @@ Inset * readInset(Lexer & lex, Buffer const & buf)
|
|||||||
|
|
||||||
auto_ptr<Inset> inset;
|
auto_ptr<Inset> inset;
|
||||||
|
|
||||||
TextClass const & tclass = buf.params().getTextClass();
|
|
||||||
|
|
||||||
lex.next();
|
lex.next();
|
||||||
string tmptok = lex.getString();
|
string tmptok = lex.getString();
|
||||||
|
|
||||||
@ -480,8 +476,8 @@ Inset * readInset(Lexer & lex, Buffer const & buf)
|
|||||||
} else if (tmptok == "Flex") {
|
} else if (tmptok == "Flex") {
|
||||||
lex.next();
|
lex.next();
|
||||||
string s = lex.getString();
|
string s = lex.getString();
|
||||||
InsetLayout const & il = tclass.insetlayout(from_utf8(s));
|
inset.reset(new InsetFlex(buf.params(),
|
||||||
inset.reset(new InsetFlex(buf.params(), il));
|
buf.params().getTextClassPtr(), s));
|
||||||
} else if (tmptok == "Branch") {
|
} else if (tmptok == "Branch") {
|
||||||
inset.reset(new InsetBranch(buf.params(),
|
inset.reset(new InsetBranch(buf.params(),
|
||||||
InsetBranchParams()));
|
InsetBranchParams()));
|
||||||
|
@ -74,10 +74,11 @@ InsetCollapsable::Geometry InsetCollapsable::geometry() const
|
|||||||
|
|
||||||
|
|
||||||
InsetCollapsable::InsetCollapsable(BufferParams const & bp,
|
InsetCollapsable::InsetCollapsable(BufferParams const & bp,
|
||||||
CollapseStatus status, InsetLayout const * il)
|
CollapseStatus status, TextClassPtr tc)
|
||||||
: InsetText(bp), layout_(il), status_(status),
|
: InsetText(bp), status_(status),
|
||||||
openinlined_(false), autoOpen_(false), mouse_hover_(false)
|
openinlined_(false), autoOpen_(false), mouse_hover_(false)
|
||||||
{
|
{
|
||||||
|
setLayout(tc);
|
||||||
setAutoBreakRows(true);
|
setAutoBreakRows(true);
|
||||||
setDrawFrame(true);
|
setDrawFrame(true);
|
||||||
setFrameColor(Color_collapsableframe);
|
setFrameColor(Color_collapsableframe);
|
||||||
@ -86,6 +87,7 @@ InsetCollapsable::InsetCollapsable(BufferParams const & bp,
|
|||||||
|
|
||||||
InsetCollapsable::InsetCollapsable(InsetCollapsable const & rhs)
|
InsetCollapsable::InsetCollapsable(InsetCollapsable const & rhs)
|
||||||
: InsetText(rhs),
|
: InsetText(rhs),
|
||||||
|
textClass_(rhs.textClass_),
|
||||||
layout_(rhs.layout_),
|
layout_(rhs.layout_),
|
||||||
labelstring_(rhs.labelstring_),
|
labelstring_(rhs.labelstring_),
|
||||||
button_dim(rhs.button_dim),
|
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)
|
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;
|
textClass_ = tc;
|
||||||
|
if ( tc.get() != 0 ) {
|
||||||
|
layout_ = &tc->insetlayout(name());
|
||||||
labelstring_ = layout_->labelstring;
|
labelstring_ = layout_->labelstring;
|
||||||
|
} else {
|
||||||
|
layout_ = 0;
|
||||||
|
labelstring_ = _("UNDEFINED");
|
||||||
|
}
|
||||||
|
|
||||||
setButtonLabel();
|
setButtonLabel();
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
#include "InsetText.h"
|
#include "InsetText.h"
|
||||||
|
|
||||||
#include "Box.h"
|
#include "Box.h"
|
||||||
|
#include "TextClass.h"
|
||||||
|
#include "TextClassPtr.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@ -41,7 +43,7 @@ public:
|
|||||||
InsetCollapsable(
|
InsetCollapsable(
|
||||||
BufferParams const &,
|
BufferParams const &,
|
||||||
CollapseStatus status = Inset::Open,
|
CollapseStatus status = Inset::Open,
|
||||||
InsetLayout const * il = 0
|
TextClassPtr tc = TextClassPtr((TextClass *)0)
|
||||||
);
|
);
|
||||||
///
|
///
|
||||||
InsetCollapsable(InsetCollapsable const & rhs);
|
InsetCollapsable(InsetCollapsable const & rhs);
|
||||||
@ -52,10 +54,13 @@ public:
|
|||||||
docstring name() const { return from_ascii("Collapsable"); }
|
docstring name() const { return from_ascii("Collapsable"); }
|
||||||
InsetLayout const & getLayout(BufferParams const &) const
|
InsetLayout const & getLayout(BufferParams const &) const
|
||||||
{ return *layout_; }
|
{ return *layout_; }
|
||||||
|
InsetLayout const & getLayout() const
|
||||||
|
{ return *layout_; }
|
||||||
///
|
///
|
||||||
void setLayout(BufferParams const &);
|
void setLayout(BufferParams const &);
|
||||||
/// (Re-)set the character style parameters from \p il
|
/// (Re-)set the character style parameters from \p tc according
|
||||||
void setLayout(InsetLayout const & il);
|
/// to name()
|
||||||
|
void setLayout(TextClassPtr tc);
|
||||||
///
|
///
|
||||||
void read(Buffer const &, Lexer &);
|
void read(Buffer const &, Lexer &);
|
||||||
///
|
///
|
||||||
@ -165,10 +170,11 @@ protected:
|
|||||||
///
|
///
|
||||||
virtual void resetParagraphsFont();
|
virtual void resetParagraphsFont();
|
||||||
|
|
||||||
protected:
|
|
||||||
///
|
|
||||||
InsetLayout const * layout_;
|
|
||||||
private:
|
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;
|
Dimension dimensionCollapsed() const;
|
||||||
///
|
///
|
||||||
|
@ -43,12 +43,13 @@ namespace lyx {
|
|||||||
|
|
||||||
|
|
||||||
InsetFlex::InsetFlex(BufferParams const & bp,
|
InsetFlex::InsetFlex(BufferParams const & bp,
|
||||||
InsetLayout const & il)
|
TextClassPtr tc, string const & layoutName)
|
||||||
: InsetCollapsable(bp, Collapsed, &il)
|
: InsetCollapsable(bp, Collapsed, tc),
|
||||||
|
name_(layoutName)
|
||||||
{
|
{
|
||||||
name_ = il.name;
|
setLayout(tc); // again, because now the name is initialized
|
||||||
packages_ = il.requires;
|
packages_ = getLayout().requires;
|
||||||
preamble_ = il.preamble;
|
preamble_ = getLayout().preamble;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -65,7 +66,7 @@ Inset * InsetFlex::clone() const
|
|||||||
|
|
||||||
bool InsetFlex::undefined() 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();
|
ParagraphList::const_iterator end = paragraphs().end();
|
||||||
|
|
||||||
if (!undefined())
|
if (!undefined())
|
||||||
sgml::openTag(os, layout_->latexname,
|
sgml::openTag(os, getLayout().latexname,
|
||||||
par->getID(buf, runparams) + layout_->latexparam);
|
par->getID(buf, runparams) + getLayout().latexparam);
|
||||||
|
|
||||||
for (; par != end; ++par) {
|
for (; par != end; ++par) {
|
||||||
par->simpleDocBookOnePar(buf, os, runparams,
|
par->simpleDocBookOnePar(buf, os, runparams,
|
||||||
@ -128,7 +129,7 @@ int InsetFlex::docbook(Buffer const & buf, odocstream & os,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!undefined())
|
if (!undefined())
|
||||||
sgml::closeTag(os, layout_->latexname);
|
sgml::closeTag(os, getLayout().latexname);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
#include "InsetCollapsable.h"
|
#include "InsetCollapsable.h"
|
||||||
|
|
||||||
|
using std::string;
|
||||||
|
|
||||||
namespace lyx {
|
namespace lyx {
|
||||||
|
|
||||||
@ -25,7 +26,8 @@ namespace lyx {
|
|||||||
class InsetFlex : public InsetCollapsable {
|
class InsetFlex : public InsetCollapsable {
|
||||||
public:
|
public:
|
||||||
///
|
///
|
||||||
InsetFlex(BufferParams const &, InsetLayout const &);
|
InsetFlex(BufferParams const &,
|
||||||
|
TextClassPtr tc, string const & layoutName);
|
||||||
///
|
///
|
||||||
docstring name() const { return from_utf8(name_); }
|
docstring name() const { return from_utf8(name_); }
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user