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)
{
for (size_t i = 0; i < depth(); ++i)
for (size_t i = 0; i != depth(); ++i)
if (&operator[](i).inset() == p)
return true;
return false;
@ -1187,4 +1187,3 @@ void LCursor::fixIfBroken()
lyxerr << "correcting cursor to level " << depth() << endl;
}
}

View File

@ -53,7 +53,7 @@ public:
bool popLeft();
/// pop one slice off the cursor stack and go right
bool popRight();
/// make sure cursor is outside given inset
/// make sure we are outside of given inset
void leaveInset(InsetBase const & inset);
/// sets cursor part
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 * buffer_ptr = 0;

View File

@ -80,9 +80,9 @@ public:
Buffer * buffer() const;
/// 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
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>
* insetcommandparams.C (scanCommand): fix out of range string access.

View File

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

View File

@ -45,7 +45,7 @@ using std::ostringstream;
void InsetCharStyle::init()
{
setInsetName("CharStyle");
setStatus(Inlined);
setInlined();
setDrawFrame(false);
has_label_ = true;
}
@ -126,7 +126,7 @@ void InsetCharStyle::write(Buffer const & buf, ostream & os) const
void InsetCharStyle::read(Buffer const & buf, LyXLex & 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)
{
setStatus(Inlined);
setInlined();
switch (cmd.action) {
case LFUN_MOUSE_PRESS:
if (cmd.button() == mouse_button::button3)

View File

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

View File

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

View File

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

View File

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