2003-09-17 16:44:51 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file cursor.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
2003-11-04 12:36:59 +00:00
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
2003-09-17 16:44:51 +00:00
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "buffer.h"
|
|
|
|
|
#include "BufferView.h"
|
|
|
|
|
#include "cursor.h"
|
|
|
|
|
#include "debug.h"
|
2003-10-29 10:47:21 +00:00
|
|
|
|
#include "dispatchresult.h"
|
2003-09-17 16:44:51 +00:00
|
|
|
|
#include "iterators.h"
|
|
|
|
|
#include "lyxtext.h"
|
|
|
|
|
#include "paragraph.h"
|
|
|
|
|
|
|
|
|
|
#include "insets/updatableinset.h"
|
2003-11-04 12:36:59 +00:00
|
|
|
|
#include "insets/insettext.h"
|
|
|
|
|
|
|
|
|
|
#include <boost/assert.hpp>
|
2003-09-17 16:44:51 +00:00
|
|
|
|
|
|
|
|
|
using std::vector;
|
2003-10-29 12:18:08 +00:00
|
|
|
|
using std::endl;
|
2003-09-17 16:44:51 +00:00
|
|
|
|
|
|
|
|
|
|
2003-11-04 12:36:59 +00:00
|
|
|
|
std::ostream & operator<<(std::ostream & os, CursorItem const & item)
|
|
|
|
|
{
|
|
|
|
|
os << " inset: " << item.inset_
|
|
|
|
|
<< " idx: " << item.idx_
|
|
|
|
|
<< " text: " << item.text_
|
|
|
|
|
<< " par: " << item.par_
|
|
|
|
|
<< " pos: " << item.pos_;
|
|
|
|
|
return os;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::ostream & operator<<(std::ostream & os, LCursor const & cursor)
|
|
|
|
|
{
|
|
|
|
|
for (size_t i = 0, n = cursor.data_.size(); i != n; ++i)
|
|
|
|
|
os << " " << cursor.data_[i];
|
|
|
|
|
return os;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DispatchResult LCursor::dispatch(FuncRequest const & cmd)
|
2003-09-17 16:44:51 +00:00
|
|
|
|
{
|
|
|
|
|
for (int i = data_.size() - 1; i >= 0; --i) {
|
2003-11-04 08:33:23 +00:00
|
|
|
|
CursorItem & citem = data_[i];
|
|
|
|
|
|
|
|
|
|
lyxerr << "trying to dispatch to inset" << citem.inset_ << endl;
|
|
|
|
|
DispatchResult res = citem.inset_->dispatch(cmd);
|
2003-10-29 13:24:57 +00:00
|
|
|
|
lyxerr << " result: " << res.val() << endl;
|
2003-10-29 12:18:08 +00:00
|
|
|
|
|
2003-11-04 12:36:59 +00:00
|
|
|
|
switch (res.val()) {
|
|
|
|
|
case FINISHED:
|
|
|
|
|
pop();
|
|
|
|
|
return DispatchResult(true, true);
|
|
|
|
|
|
|
|
|
|
case FINISHED_RIGHT: {
|
|
|
|
|
pop();
|
|
|
|
|
//InsetText * inset = static_cast<InsetText *>(innerInset());
|
|
|
|
|
//if (inset)
|
|
|
|
|
// inset->moveRightIntern(bv_, false, false);
|
|
|
|
|
//else
|
|
|
|
|
// bv_->text->cursorRight(bv_);
|
|
|
|
|
innerText()->cursorRight(bv_);
|
|
|
|
|
return DispatchResult(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case FINISHED_UP: {
|
|
|
|
|
pop();
|
|
|
|
|
//InsetText * inset = static_cast<InsetText *>(inset());
|
|
|
|
|
//if (inset)
|
|
|
|
|
// result = inset->moveUp(bv);
|
|
|
|
|
return DispatchResult(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case FINISHED_DOWN: {
|
|
|
|
|
pop();
|
|
|
|
|
//InsetText * inset = static_cast<InsetText *>(inset());
|
|
|
|
|
//if (inset)
|
|
|
|
|
// result = inset->moveDown(bv);
|
|
|
|
|
return DispatchResult(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2003-10-29 13:24:57 +00:00
|
|
|
|
|
|
|
|
|
lyxerr << "# unhandled result: " << res.val() << endl;
|
2003-09-17 16:44:51 +00:00
|
|
|
|
}
|
2003-11-04 12:36:59 +00:00
|
|
|
|
|
|
|
|
|
lyxerr << "trying to dispatch to main text " << bv_->text << endl;
|
|
|
|
|
DispatchResult res = bv_->text->dispatch(cmd);
|
|
|
|
|
lyxerr << " result: " << res.val() << endl;
|
|
|
|
|
return res;
|
2003-09-17 16:44:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-04 12:36:59 +00:00
|
|
|
|
LCursor::LCursor(BufferView * bv)
|
|
|
|
|
: bv_(bv)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LCursor::push(InsetOld * inset, LyXText * text)
|
2003-09-17 16:44:51 +00:00
|
|
|
|
{
|
2003-11-04 12:36:59 +00:00
|
|
|
|
data_.push_back(CursorItem(inset, text));
|
|
|
|
|
}
|
2003-09-17 16:44:51 +00:00
|
|
|
|
|
|
|
|
|
|
2003-11-04 12:36:59 +00:00
|
|
|
|
void LCursor::pop()
|
|
|
|
|
{
|
|
|
|
|
BOOST_ASSERT(!data_.empty());
|
|
|
|
|
data_.pop_back();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InsetOld * LCursor::innerInset() const
|
|
|
|
|
{
|
|
|
|
|
return data_.empty() ? 0 : data_.back().inset_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LyXText * LCursor::innerText() const
|
|
|
|
|
{
|
|
|
|
|
return data_.empty() ? bv_->text : data_.back().text_;
|
2003-09-17 16:44:51 +00:00
|
|
|
|
}
|