more global cursor work

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8059 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2003-11-06 16:43:12 +00:00
parent 4dc81d208a
commit 2ad9bd1e7d
12 changed files with 106 additions and 50 deletions

View File

@ -41,8 +41,9 @@ std::ostream & operator<<(std::ostream & os, CursorItem const & item)
std::ostream & operator<<(std::ostream & os, LCursor const & cursor)
{
os << "\n";
for (size_t i = 0, n = cursor.data_.size(); i != n; ++i)
os << " " << cursor.data_[i];
os << " " << cursor.data_[i] << "\n";
return os;
}
@ -68,11 +69,11 @@ bool LCursor::handleResult(DispatchResult const & res)
lyxerr << "LCursor::handleResult: " << res.val() << endl;
switch (res.val()) {
case FINISHED:
pop();
///pop();
return true;
case FINISHED_RIGHT: {
pop();
///pop();
//InsetText * inset = static_cast<InsetText *>(innerInset());
//if (inset)
// inset->moveRightIntern(bv_, false, false);
@ -83,7 +84,7 @@ bool LCursor::handleResult(DispatchResult const & res)
}
case FINISHED_UP: {
pop();
///pop();
//InsetText * inset = static_cast<InsetText *>(inset());
//if (inset)
// result = inset->moveUp(bv);
@ -91,7 +92,7 @@ bool LCursor::handleResult(DispatchResult const & res)
}
case FINISHED_DOWN: {
pop();
///pop();
//InsetText * inset = static_cast<InsetText *>(inset());
//if (inset)
// result = inset->moveDown(bv);
@ -99,7 +100,6 @@ bool LCursor::handleResult(DispatchResult const & res)
}
default:
break;
lyxerr << "# unhandled result: " << res.val() << endl;
return false;
}
@ -114,12 +114,15 @@ LCursor::LCursor(BufferView * bv)
void LCursor::push(InsetOld * inset, LyXText * text)
{
lyxerr << "LCursor::push() inset: " << inset << " text: " << text
<< endl;
data_.push_back(CursorItem(inset, text));
}
void LCursor::pop()
{
lyxerr << "LCursor::pop() " << endl;
//BOOST_ASSERT(!data_.empty());
if (data_.empty())
lyxerr << "### TRYING TO POP FROM EMPTY CURSOR" << endl;

View File

@ -11,6 +11,7 @@
#include <config.h>
#include "insetbase.h"
#include "debug.h"
#include "dispatchresult.h"
@ -38,10 +39,13 @@ InsetBase::priv_dispatch(FuncRequest const &, idx_type &, pos_type &)
void InsetBase::edit(BufferView *, bool)
{}
{
lyxerr << "InsetBase: edit left/right" << std::endl;
}
void InsetBase::edit(BufferView * bv, int, int)
{
lyxerr << "InsetBase: edit xy" << std::endl;
edit(bv, true);
}

View File

@ -16,6 +16,7 @@
#include "buffer.h"
#include "BufferView.h"
#include "cursor.h"
#include "debug.h"
#include "dispatchresult.h"
#include "LColor.h"
@ -276,9 +277,10 @@ bool InsetCollapsable::hitButton(FuncRequest const & cmd) const
void InsetCollapsable::edit(BufferView * bv, bool left)
{
lyxerr << "InsetCollapsable: edit" << endl;
lyxerr << "InsetCollapsable: edit left/right" << endl;
if (!bv->lockInset(this))
lyxerr << "InsetCollapsable: can't lock" << endl;
bv->cursor().push(this, inset.getText(0));
inset.edit(bv, left);
first_after_edit = true;
open(bv);
@ -309,6 +311,7 @@ void InsetCollapsable::edit(BufferView * bv, bool left)
void InsetCollapsable::edit(BufferView * bv, int x, int y)
{
lyxerr << "InsetCollapsable: edit xy" << endl;
if (collapsed_) {
collapsed_ = false;
// set this only here as it should be recollapsed only if
@ -328,16 +331,15 @@ void InsetCollapsable::edit(BufferView * bv, int x, int y)
inset.edit(bv, x,
ascent() + y - (height_collapsed() + inset.ascent()));
}
bv->cursor().push(this, inset.getText(0));
}
DispatchResult
InsetCollapsable::priv_dispatch(FuncRequest const & cmd,
idx_type & idx, pos_type & pos)
InsetCollapsable::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &)
{
//lyxerr << "InsetCollapsable::localDispatch: "
// << cmd.action << " '" << cmd.argument << "'\n";
BufferView * bv = cmd.view();
switch (cmd.action) {
case LFUN_MOUSE_PRESS:
if (!collapsed_ && cmd.y > button_dim.y2)

View File

@ -157,6 +157,8 @@ protected:
void edit(BufferView *, bool);
///
void edit(BufferView *, int, int);
///
UpdatableInset * lockingInset() const { return inset.lockingInset(); }
private:
///

View File

@ -15,6 +15,7 @@
#include "buffer.h"
#include "bufferparams.h"
#include "BufferView.h"
#include "cursor.h"
#include "debug.h"
#include "dispatchresult.h"
#include "funcrequest.h"
@ -641,8 +642,9 @@ void InsetTabular::lfunMouseMotion(FuncRequest const & cmd)
void InsetTabular::edit(BufferView * bv, bool left)
{
lyxerr << "InsetTabular::edit: " << this << " first cell: "
<< &tabular.cell_info[0][0].inset << endl;
lyxerr << "InsetTabular::edit: " << this
<< " first text: " << tabular.cell_info[0][0].inset.getText(0)
<< " first cell: " << &tabular.cell_info[0][0].inset << endl;
if (!bv->lockInset(this)) {
lyxerr << "InsetTabular::Cannot lock inset" << endl;
@ -669,6 +671,7 @@ void InsetTabular::edit(BufferView * bv, bool left)
clearSelection();
resetPos(bv);
bv->fitCursor();
bv->cursor().push(this, 0);
}
@ -696,6 +699,7 @@ void InsetTabular::edit(BufferView * bv, int x, int y)
inset_y = cursory_;
activateCellInset(bv, x - inset_x, y - inset_y);
}
bv->cursor().push(this, tabular.getCellInset(actcell).getText(0));
}
@ -714,8 +718,11 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd,
return result;
}
if (cmd.action < 0 && cmd.argument.empty())
if (cmd.action < 0 && cmd.argument.empty()) {
lyxerr << "InsetTabular: cursor pop 2" << endl;
bv->cursor().pop();
return DispatchResult(false, FINISHED);
}
bool hs = hasSelection();
@ -1107,8 +1114,9 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd,
break;
}
if (result.val() >= FINISHED)
if (result.val() >= FINISHED) {
bv->unlockInset(this);
}
else if (!the_locking_inset && bv->fitCursor())
updateLocal(bv);
@ -1403,8 +1411,11 @@ DispatchResult InsetTabular::moveRight(BufferView * bv, bool lock)
} else {
bool moved = isRightToLeft(bv)
? movePrevCell(bv) : moveNextCell(bv);
if (!moved)
if (!moved) {
lyxerr << "InsetTabular: cursor pop 3" << endl;
bv->cursor().pop();
return DispatchResult(false, FINISHED_RIGHT);
}
if (lock && activateCellInset(bv))
return DispatchResult(true, true);
}
@ -1416,8 +1427,11 @@ DispatchResult InsetTabular::moveRight(BufferView * bv, bool lock)
DispatchResult InsetTabular::moveLeft(BufferView * bv, bool lock)
{
bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
if (!moved)
if (!moved) {
lyxerr << "InsetTabular: cursor pop 4" << endl;
bv->cursor().pop();
return DispatchResult(false, FINISHED);
}
// behind the inset
if (lock && activateCellInset(bv, 0, 0, true))
return DispatchResult(true, true);
@ -1430,8 +1444,11 @@ DispatchResult InsetTabular::moveUp(BufferView * bv, bool lock)
{
int const ocell = actcell;
actcell = tabular.getCellAbove(actcell);
if (actcell == ocell) // we moved out of the inset
if (actcell == ocell) { // we moved out of the inset
lyxerr << "InsetTabular: cursor pop 5" << endl;
bv->cursor().pop();
return DispatchResult(false, FINISHED_UP);
}
resetPos(bv);
if (lock) {
int x = 0;
@ -1451,8 +1468,11 @@ DispatchResult InsetTabular::moveDown(BufferView * bv, bool lock)
{
int const ocell = actcell;
actcell = tabular.getCellBelow(actcell);
if (actcell == ocell) // we moved out of the inset
if (actcell == ocell) { // we moved out of the inset
lyxerr << "InsetTabular: cursor pop 6" << endl;
bv->cursor().pop();
return DispatchResult(false, FINISHED_DOWN);
}
resetPos(bv);
if (lock) {
int x = 0;
@ -1986,6 +2006,7 @@ bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, bool behind)
//inset_x = cursorx_ - top_x + tabular.getBeginningOfTextInCell(actcell);
//inset_y = cursory_;
inset.edit(bv, x, y);
bv->cursor().push(&inset, inset.getText(0));
if (!the_locking_inset)
return false;
updateLocal(bv);

View File

@ -273,6 +273,8 @@ private:
int & srow, int & erow) const;
///
bool insertAsciiString(BufferView *, std::string const & buf, bool usePaste);
///
UpdatableInset * lockingInset() const { return the_locking_inset; }
//
// Private structures and variables

View File

@ -584,9 +584,10 @@ void InsetText::edit(BufferView * bv, bool left)
setViewCache(bv);
if (!bv->lockInset(this)) {
lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
lyxerr << "Cannot lock inset" << endl;
return;
}
lyxerr << "InsetText: edit left/right" << endl;
locked = true;
the_locking_inset = 0;
@ -620,9 +621,10 @@ void InsetText::edit(BufferView * bv, bool left)
void InsetText::edit(BufferView * bv, int x, int y)
{
if (!bv->lockInset(this)) {
lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
lyxerr << "Cannot lock inset" << endl;
return;
}
lyxerr << "InsetText: edit xy" << endl;
locked = true;
the_locking_inset = 0;
@ -720,7 +722,6 @@ InsetText::priv_dispatch(FuncRequest const & cmd,
if (result.val() >= FINISHED) {
updateLocal(bv, false);
bv->unlockInset(this);
bv->cursor().pop();
}
break;
case FINISHED_DOWN:
@ -728,7 +729,6 @@ InsetText::priv_dispatch(FuncRequest const & cmd,
if (result.val() >= FINISHED) {
updateLocal(bv, false);
bv->unlockInset(this);
bv->cursor().pop();
}
break;
default:
@ -795,9 +795,11 @@ InsetText::priv_dispatch(FuncRequest const & cmd,
break;
case LFUN_PRIOR:
if (crow() == text_.firstRow())
if (crow() == text_.firstRow()) {
result.val(FINISHED_UP);
else {
lyxerr << "InsetText: cursor pop 1" << endl;
bv->cursor().pop();
} else {
text_.cursorPrevious();
text_.clearSelection();
result.dispatched(true);
@ -805,9 +807,11 @@ InsetText::priv_dispatch(FuncRequest const & cmd,
break;
case LFUN_NEXT:
if (crow() == text_.lastRow())
if (crow() == text_.lastRow()) {
result.val(FINISHED_DOWN);
else {
lyxerr << "InsetText: cursor pop 2" << endl;
bv->cursor().pop();
} else {
text_.cursorNext();
text_.clearSelection();
result.dispatched(true);
@ -954,7 +958,6 @@ InsetText::priv_dispatch(FuncRequest const & cmd,
if (result.val() >= FINISHED) {
result.val(NONE);
bv->unlockInset(this);
bv->cursor().pop();
}
return result;
@ -1078,8 +1081,11 @@ InsetText::moveRightIntern(BufferView * bv, bool front,
{
ParagraphList::iterator c_par = cpar();
if (boost::next(c_par) == paragraphs.end() && cpos() >= c_par->size())
if (boost::next(c_par) == paragraphs.end() && cpos() >= c_par->size()) {
lyxerr << "InsetText: cursor pop 3" << endl;
bv->cursor().pop();
return DispatchResult(false, FINISHED_RIGHT);
}
if (activate_inset && checkAndActivateInset(bv, front))
return DispatchResult(true, true);
text_.cursorRight(bv);
@ -1093,8 +1099,11 @@ DispatchResult
InsetText::moveLeftIntern(BufferView * bv, bool front,
bool activate_inset, bool selecting)
{
if (cpar() == paragraphs.begin() && cpos() <= 0)
if (cpar() == paragraphs.begin() && cpos() <= 0) {
lyxerr << "InsetText: cursor pop 4" << endl;
bv->cursor().pop();
return DispatchResult(false, FINISHED);
}
text_.cursorLeft(bv);
if (!selecting)
text_.clearSelection();
@ -1106,8 +1115,11 @@ InsetText::moveLeftIntern(BufferView * bv, bool front,
DispatchResult InsetText::moveUp(BufferView * bv)
{
if (crow() == text_.firstRow())
if (crow() == text_.firstRow()) {
lyxerr << "InsetText: cursor pop 5" << endl;
bv->cursor().pop();
return DispatchResult(false, FINISHED_UP);
}
text_.cursorUp(bv);
text_.clearSelection();
return DispatchResult(true);
@ -1116,8 +1128,11 @@ DispatchResult InsetText::moveUp(BufferView * bv)
DispatchResult InsetText::moveDown(BufferView * bv)
{
if (crow() == text_.lastRow())
if (crow() == text_.lastRow()) {
lyxerr << "InsetText: cursor pop 6" << endl;
bv->cursor().pop();
return DispatchResult(false, FINISHED_DOWN);
}
text_.cursorDown(bv);
text_.clearSelection();
return DispatchResult(true);

View File

@ -183,6 +183,8 @@ public:
void edit(BufferView *, bool);
///
void edit(BufferView *, int, int);
///
UpdatableInset * lockingInset() const { return the_locking_inset; }
///
int numParagraphs() const { return 1; }

View File

@ -88,6 +88,8 @@ public:
virtual bool showInsetDialog(BufferView *) const { return false; }
///
virtual void toggleSelection(BufferView *, bool /*kill_selection*/) {}
///
virtual UpdatableInset * lockingInset() const { return 0; }
protected:
/// An updatable inset could handle lyx editing commands

View File

@ -882,10 +882,17 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
view()->hideCursor();
#if 1
if (view()->cursor().innerInset() != view()->theLockingInset()) {
lyxerr << "### CURSOR OUT OF SYNC: tli: "
<< view()->theLockingInset()
<< "\ncursor: " << view()->cursor() << endl;
{
UpdatableInset * innerinset = view()->theLockingInset();
for (UpdatableInset * tmp = innerinset; tmp; tmp = tmp->lockingInset())
innerinset = tmp;
if (view()->cursor().innerInset() != innerinset) {
lyxerr << "### CURSOR OUT OF SYNC: tli: "
<< view()->theLockingInset() << " inner: "
<< innerinset
<< "\ncursor: " << view()->cursor() << endl;
}
}
if (0) {

View File

@ -1629,10 +1629,8 @@ void LyXText::cursorUp(bool selecting)
int y2 = y1;
y -= topy;
InsetOld * inset_hit = checkInsetHit(x, y1);
if (inset_hit && isHighlyEditableInset(inset_hit)) {
if (inset_hit && isHighlyEditableInset(inset_hit))
inset_hit->edit(bv(), x, y - (y2 - y1));
bv()->cursor().push(inset_hit, inset_hit->getText(0));
}
}
#else
lyxerr << "cursorUp: y " << cursor.y() << " bl: " <<
@ -1657,10 +1655,8 @@ void LyXText::cursorDown(bool selecting)
int y2 = y1;
y -= topy;
InsetOld * inset_hit = checkInsetHit(x, y1);
if (inset_hit && isHighlyEditableInset(inset_hit)) {
bv()->cursor().push(inset_hit, inset_hit->getText(0));
if (inset_hit && isHighlyEditableInset(inset_hit))
inset_hit->edit(bv(), x, y - (y2 - y1));
}
}
#else
setCursorFromCoordinates(bv()->x_target(),

View File

@ -376,10 +376,8 @@ void doInsertInset(LyXText * lt, FuncRequest const & cmd,
gotsel = true;
}
if (bv->insertInset(inset)) {
if (edit) {
if (edit)
inset->edit(bv, true);
bv->cursor().push(inset, inset->getText(0));
}
if (gotsel && pastesel)
bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
}
@ -596,7 +594,6 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
InsetOld * tmpinset = cursorPar()->getInset(cursor.pos());
cmd.message(tmpinset->editMessage());
tmpinset->edit(bv, !is_rtl);
bv->cursor().push(tmpinset, tmpinset->getText(0));
break;
}
if (!is_rtl)
@ -1247,8 +1244,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
}
// Single-click on work area
case LFUN_MOUSE_PRESS:
{
case LFUN_MOUSE_PRESS: {
if (!bv->buffer())
break;
@ -1292,6 +1288,8 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
break;
}
bv->unlockInset(bv->theLockingInset());
lyxerr << "Re-initializing cursor" << endl;
bv->cursor() = LCursor(bv);
}
if (!inset_hit)
@ -1304,13 +1302,15 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
// Single left click in math inset?
if (isHighlyEditableInset(inset_hit)) {
// Highly editable inset, like math
lyxerr << "click on highly editable inset, like math" << endl;
UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
selection_possible = false;
bv->owner()->message(inset->editMessage());
// We just have to lock the inset before calling a PressEvent on it!
if (!bv->lockInset(inset))
lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
lyxerr << "Cannot lock inset" << endl;
#warning cell 0 is certainly not always good.
bv->cursor().push(inset, inset->getText(0));
FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());
inset->dispatch(cmd1);
break;