make sure the 'setStatus(Collapsed)' crash won't occur otherwise

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9917 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2005-05-06 20:00:31 +00:00
parent 56f0c42919
commit 3a3c1080ee
11 changed files with 35 additions and 86 deletions

View File

@ -507,7 +507,7 @@ std::ostream & operator<<(std::ostream & os, LCursor const & cur)
bool LCursor::isInside(InsetBase const * p) bool LCursor::isInside(InsetBase const * p)
{ {
for (size_t i = 0; i < depth(); ++i) for (size_t i = 0; i != depth(); ++i)
if (&operator[](i).inset() == p) if (&operator[](i).inset() == p)
return true; return true;
return false; return false;
@ -1187,4 +1187,3 @@ void LCursor::fixIfBroken()
lyxerr << "correcting cursor to level " << depth() << endl; lyxerr << "correcting cursor to level " << depth() << endl;
} }
} }

View File

@ -53,7 +53,7 @@ public:
bool popLeft(); bool popLeft();
/// pop one slice off the cursor stack and go right /// pop one slice off the cursor stack and go right
bool popRight(); bool popRight();
/// make sure cursor is outside given inset /// make sure we are outside of given inset
void leaveInset(InsetBase const & inset); void leaveInset(InsetBase const & inset);
/// sets cursor part /// sets cursor part
void setCursor(DocIterator const & it); void setCursor(DocIterator const & it);

View File

@ -203,20 +203,6 @@ void LyXView::dispatch(FuncRequest const & cmd)
} }
LyXFunc & LyXView::getLyXFunc()
{
BOOST_ASSERT(lyxfunc_.get());
return *lyxfunc_.get();
}
LyXFunc const & LyXView::getLyXFunc() const
{
BOOST_ASSERT(lyxfunc_.get());
return *lyxfunc_.get();
}
Buffer const * const LyXView::updateInset(InsetBase const * inset) const Buffer const * const LyXView::updateInset(InsetBase const * inset) const
{ {
Buffer const * buffer_ptr = 0; Buffer const * buffer_ptr = 0;

View File

@ -80,9 +80,9 @@ public:
Buffer * buffer() const; Buffer * buffer() const;
/// return the LyX function handler for this view /// return the LyX function handler for this view
LyXFunc & getLyXFunc(); LyXFunc & getLyXFunc() { return *lyxfunc_.get(); }
/// ///
LyXFunc const & getLyXFunc() const; LyXFunc const & getLyXFunc() const { return *lyxfunc_.get(); }
/// return the toolbar for this view /// return the toolbar for this view
Toolbars & getToolbars() { return *toolbars_.get(); } Toolbars & getToolbars() { return *toolbars_.get(); }

View File

@ -1,8 +1,3 @@
2005-05-07 André Pönitz <poenitz@gmx.net>
* insetert.C (doDispatch): move cursor out of collapsed insets
2005-05-06 José Matos <jamatos@lyx.org> 2005-05-06 José Matos <jamatos@lyx.org>
* insetcommandparams.C (scanCommand): fix out of range string access. * insetcommandparams.C (scanCommand): fix out of range string access.

View File

@ -147,32 +147,24 @@ void InsetBranch::doDispatch(LCursor & cur, FuncRequest & cmd)
cur.dispatched(); cur.dispatched();
if (cmd.argument == "open") if (cmd.argument == "open")
setStatus(Open); setStatus(cur, Open);
else if (cmd.argument == "close") { else if (cmd.argument == "close")
setStatus(Collapsed); setStatus(cur, Collapsed);
cur.leaveInset(*this); else if (cmd.argument == "toggle")
} else if (cmd.argument == "toggle") { setStatus(cur, isOpen() ? Collapsed : Open);
if (isOpen()) { else if (cmd.argument == "assign" || cmd.argument.empty()) {
setStatus(Collapsed); // The branch inset uses "assign".
cur.leaveInset(*this);
} else {
setStatus(Open);
}
// The branch inset uses "assign".
} else if (cmd.argument == "assign" || cmd.argument.empty()) {
BranchList const & branchlist = BranchList const & branchlist =
cur.buffer().params().branchlist(); cur.buffer().params().branchlist();
if (isBranchSelected(branchlist)) { if (isBranchSelected(branchlist)) {
if (status() != Open) if (status() != Open)
setStatus(Open); setStatus(cur, Open);
else else
cur.undispatched(); cur.undispatched();
} else { } else {
if (status() != Collapsed) { if (status() != Collapsed)
setStatus(Collapsed); setStatus(cur, Collapsed);
cur.leaveInset(*this); else
} else
cur.undispatched(); cur.undispatched();
} }
} }
@ -198,7 +190,8 @@ bool InsetBranch::getStatus(LCursor & cur, FuncRequest const & cmd,
if (cmd.argument == "open" || cmd.argument == "close" || if (cmd.argument == "open" || cmd.argument == "close" ||
cmd.argument == "toggle") cmd.argument == "toggle")
flag.enabled(true); flag.enabled(true);
else if (cmd.argument == "assign" || cmd.argument.empty()) { else if (cmd.argument == "assign"
|| cmd.argument.empty()) {
BranchList const & branchlist = BranchList const & branchlist =
cur.buffer().params().branchlist(); cur.buffer().params().branchlist();
if (isBranchSelected(branchlist)) if (isBranchSelected(branchlist))

View File

@ -45,7 +45,7 @@ using std::ostringstream;
void InsetCharStyle::init() void InsetCharStyle::init()
{ {
setInsetName("CharStyle"); setInsetName("CharStyle");
setStatus(Inlined); setInlined();
setDrawFrame(false); setDrawFrame(false);
has_label_ = true; has_label_ = true;
} }
@ -126,7 +126,7 @@ void InsetCharStyle::write(Buffer const & buf, ostream & os) const
void InsetCharStyle::read(Buffer const & buf, LyXLex & lex) void InsetCharStyle::read(Buffer const & buf, LyXLex & lex)
{ {
InsetCollapsable::read(buf, lex); InsetCollapsable::read(buf, lex);
setStatus(Inlined); setInlined();
} }
@ -209,7 +209,7 @@ void InsetCharStyle::getDrawFont(LyXFont & font) const
void InsetCharStyle::doDispatch(LCursor & cur, FuncRequest & cmd) void InsetCharStyle::doDispatch(LCursor & cur, FuncRequest & cmd)
{ {
setStatus(Inlined); setInlined();
switch (cmd.action) { switch (cmd.action) {
case LFUN_MOUSE_PRESS: case LFUN_MOUSE_PRESS:
if (cmd.button() == mouse_button::button3) if (cmd.button() == mouse_button::button3)

View File

@ -206,8 +206,7 @@ void InsetCollapsable::getCursorPos
if (openinlined_) if (openinlined_)
x += dimensionCollapsed().wid; x += dimensionCollapsed().wid;
else else
y += dimensionCollapsed().height() - ascent() y += dimensionCollapsed().height() - ascent() + TEXT_TO_INSET_OFFSET + textdim_.asc;
+ TEXT_TO_INSET_OFFSET + textdim_.asc;
} }
x += TEXT_TO_INSET_OFFSET; x += TEXT_TO_INSET_OFFSET;
@ -316,8 +315,7 @@ void InsetCollapsable::doDispatch(LCursor & cur, FuncRequest & cmd)
case Open: { case Open: {
if (hitButton(cmd)) { if (hitButton(cmd)) {
lyxerr << "InsetCollapsable::lfunMouseRelease 2" << endl; lyxerr << "InsetCollapsable::lfunMouseRelease 2" << endl;
setStatus(Collapsed); setStatus(cur, Collapsed);
cur.leaveInset(*this);
cur.bv().cursor() = cur; cur.bv().cursor() = cur;
} else { } else {
lyxerr << "InsetCollapsable::lfunMouseRelease 3" << endl; lyxerr << "InsetCollapsable::lfunMouseRelease 3" << endl;
@ -335,18 +333,12 @@ void InsetCollapsable::doDispatch(LCursor & cur, FuncRequest & cmd)
case LFUN_INSET_TOGGLE: case LFUN_INSET_TOGGLE:
if (cmd.argument == "open") if (cmd.argument == "open")
setStatus(Open); setStatus(cur, Open);
else if (cmd.argument == "close") { else if (cmd.argument == "close")
setStatus(Collapsed); setStatus(cur, Collapsed);
cur.leaveInset(*this); else if (cmd.argument == "toggle" || cmd.argument.empty())
} else if (cmd.argument == "toggle" || cmd.argument.empty()) { setStatus(cur, isOpen() ? Collapsed : Open);
if (isOpen()) { else // if assign or anything else
setStatus(Collapsed);
cur.leaveInset(*this);
} else {
setStatus(Open);
}
} else // if assign or anything else
cur.undispatched(); cur.undispatched();
cur.dispatched(); cur.dispatched();
break; break;
@ -388,29 +380,18 @@ int InsetCollapsable::scroll(bool recursive) const
} }
void InsetCollapsable::open()
{
if (status_ == Collapsed) // ...but not inlined
setStatus(Open);
}
void InsetCollapsable::close()
{
setStatus(Collapsed);
}
void InsetCollapsable::setLabel(string const & l) void InsetCollapsable::setLabel(string const & l)
{ {
label = l; label = l;
} }
void InsetCollapsable::setStatus(CollapseStatus status) void InsetCollapsable::setStatus(LCursor & cur, CollapseStatus status)
{ {
status_ = status; status_ = status;
setButtonLabel(); setButtonLabel();
if (status_ == Collapsed)
cur.leaveInset(*this);
} }

View File

@ -83,17 +83,13 @@ public:
/// ///
CollapseStatus status() const { return status_; } CollapseStatus status() const { return status_; }
/// ///
void open();
///
void close();
///
bool allowSpellCheck() const { return true; } bool allowSpellCheck() const { return true; }
/// ///
bool getStatus(LCursor &, FuncRequest const &, FuncStatus &) const; bool getStatus(LCursor &, FuncRequest const &, FuncStatus &) const;
protected: protected:
/// ///
void setStatus(CollapseStatus st); void setStatus(LCursor & cur, CollapseStatus st);
/// ///
virtual void doDispatch(LCursor & cur, FuncRequest & cmd); virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
/// ///
@ -106,6 +102,8 @@ protected:
void edit(LCursor & cur, bool left); void edit(LCursor & cur, bool left);
/// ///
InsetBase * editXY(LCursor & cur, int x, int y) const; InsetBase * editXY(LCursor & cur, int x, int y) const;
///
void setInlined() { status_ = Inlined; }
protected: protected:
/// ///

View File

@ -207,9 +207,7 @@ void InsetERT::doDispatch(LCursor & cur, FuncRequest & cmd)
case LFUN_INSET_MODIFY: { case LFUN_INSET_MODIFY: {
InsetCollapsable::CollapseStatus st; InsetCollapsable::CollapseStatus st;
InsetERTMailer::string2params(cmd.argument, st); InsetERTMailer::string2params(cmd.argument, st);
setStatus(st); setStatus(cur, st);
if (status() == Collapsed)
cur.leaveInset(*this);
break; break;
} }
case LFUN_PASTE: case LFUN_PASTE:

View File

@ -1518,7 +1518,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
} }
} }
BOOST_ASSERT(view());
if (view()->available()) { if (view()->available()) {
// Redraw screen unless explicitly told otherwise. // Redraw screen unless explicitly told otherwise.
// This also initializes the position cache for all insets // This also initializes the position cache for all insets