#include "bufferparams.h"
#include "BufferView.h"
#include "debug.h"
+#include "dispatchresult.h"
#include "factory.h"
#include "funcrequest.h"
#include "gettext.h"
#include "paragraph.h"
#include "ParagraphParameters.h"
#include "text_funcs.h"
-#include "undo_funcs.h"
+#include "undo.h"
#include "vspace.h"
#include "frontends/Dialogs.h"
{
LyXText * lt = bv->getLyXText();
- //if (!lt->selection.set())
- // lt->selection.cursor = lt->cursor;
+// if (!lt->selection.set())
+// lt->selection.cursor = lt->cursor;
if (selecting || lt->selection.mark())
lt->setSelection();
void LyXText::cursorPrevious()
{
- int y = bv_owner->top_y();
+ int y = bv()->top_y();
- RowList::iterator rit = cursorRow();
+ ParagraphList::iterator cpit = cursorPar();
+ RowList::iterator crit = cpit->getRow(cursor.pos());
- if (rit == firstRow()) {
+ if (isFirstRow(cpit, *crit)) {
if (y > 0)
bv()->updateScrollbar();
return;
}
- setCursorFromCoordinates(cursor.x_fix(), y);
+ setCursorFromCoordinates(bv()->x_target(), y);
finishUndo();
- int new_y;
- if (rit == bv()->text->cursorRow()) {
+ if (crit == bv()->text->cursorRow()) {
// we have a row which is taller than the workarea. The
// simplest solution is to move to the previous row instead.
cursorUp(true);
return;
- // This is what we used to do, so we wouldn't skip right past
- // tall rows, but it's not working right now.
+ }
+
+ int new_y = + crit->height() - bv()->workHeight() + 1;
+
+ if (inset_owner) {
+ new_y += bv()->text->cursor.y()
+ + bv()->theLockingInset()->insetInInsetY() + y;
} else {
- if (inset_owner) {
- new_y = bv()->text->cursor.y()
- + bv()->theLockingInset()->insetInInsetY() + y
- + rit->height()
- - bv()->workHeight() + 1;
- } else {
- new_y = cursor.y()
- - rit->baseline()
- + rit->height()
- - bv()->workHeight() + 1;
- }
+ new_y += cursor.y() - crit->baseline();
}
+ previousRow(cpit, crit);
LyXCursor cur;
- ParagraphList::iterator pit = cursorPar();
- previousRow(pit, rit);
- setCursor(cur, parOffset(pit), rit->pos(), false);
- if (cur.y() > bv_owner->top_y())
+ setCursor(cur, parOffset(cpit), crit->pos(), false);
+ if (cur.y() > bv()->top_y())
cursorUp(true);
bv()->updateScrollbar();
}
void LyXText::cursorNext()
{
- int topy = bv_owner->top_y();
+ int topy = bv()->top_y();
- RowList::iterator rit = cursorRow();
- if (rit == lastRow()) {
- int y = cursor.y() - rit->baseline() + cursorRow()->height();
+ ParagraphList::iterator cpit = cursorPar();
+ RowList::iterator crit = cpit->getRow(cursor.pos());
+
+ if (isLastRow(cpit, *crit)) {
+ int y = cursor.y() - crit->baseline() + crit->height();
if (y > topy + bv()->workHeight())
- bv_owner->updateScrollbar();
+ bv()->updateScrollbar();
return;
}
- int y = topy + bv_owner->workHeight();
+ int y = topy + bv()->workHeight();
if (inset_owner && !topy) {
- y -= (bv_owner->text->cursor.y()
- - bv_owner->top_y()
- + bv_owner->theLockingInset()->insetInInsetY());
+ y -= (bv()->text->cursor.y()
+ - bv()->top_y()
+ + bv()->theLockingInset()->insetInInsetY());
}
ParagraphList::iterator dummypit;
- y = getRowNearY(y, dummypit)->y();
+ Row const & rr = *getRowNearY(y, dummypit);
+ y = dummypit->y + rr.y_offset();
- setCursorFromCoordinates(cursor.x_fix(), y);
+ setCursorFromCoordinates(bv()->x_target(), y);
// + bv->workHeight());
finishUndo();
int new_y;
- if (rit == bv_owner->text->cursorRow()) {
+ if (crit == bv()->text->cursorRow()) {
// we have a row which is taller than the workarea. The
// simplest solution is to move to the next row instead.
cursorDown(true);
#if 0
new_y = bv->top_y() + bv->workHeight();
#endif
+ }
+
+ if (inset_owner) {
+ new_y = bv()->text->cursor.y()
+ + bv()->theLockingInset()->insetInInsetY()
+ + y - crit->baseline();
} else {
- if (inset_owner) {
- new_y = bv()->text->cursor.y()
- + bv()->theLockingInset()->insetInInsetY()
- + y - rit->baseline();
- } else {
- new_y = cursor.y() - cursorRow()->baseline();
- }
+ new_y = cursor.y() - crit->baseline();
}
- ParagraphList::iterator pit = cursorPar();
- nextRow(pit, rit);
+
+ nextRow(cpit, crit);
LyXCursor cur;
- setCursor(cur, parOffset(pit), rit->pos(), false);
+ setCursor(cur, parOffset(cpit), crit->pos(), false);
if (cur.y() < bv_owner->top_y() + bv()->workHeight())
cursorDown(true);
bv()->updateScrollbar();
if (bv->insertInset(inset)) {
if (edit) {
FuncRequest cmd(bv, LFUN_INSET_EDIT, "left");
- inset->localDispatch(cmd);
+ inset->dispatch(cmd);
}
if (gotsel && pastesel)
bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
} // anon namespace
-dispatch_result LyXText::dispatch(FuncRequest const & cmd)
+DispatchResult LyXText::dispatch(FuncRequest const & cmd)
{
lyxerr[Debug::ACTION] << "LyXText::dispatch: action[" << cmd.action
<<"] arg[" << cmd.argument << ']' << "xy[" <<
for (; tmp != end; ++tmp) {
if (tmp->params().startOfAppendix()) {
- recordUndo(bv, Undo::ATOMIC, tmp);
+ recUndo(parOffset(tmp));
tmp->params().startOfAppendix(false);
redoParagraph(tmp);
break;
}
}
- recordUndo(bv, Undo::ATOMIC, pit);
+ recUndo(parOffset(pit));
pit->params().startOfAppendix(start);
// we can set the refreshing parameters now
InsetOld * tmpinset = cursorPar()->getInset(cursor.pos());
cmd.message(tmpinset->editMessage());
FuncRequest cmd1(bv, LFUN_INSET_EDIT, is_rtl ? "right" : "left");
- tmpinset->localDispatch(cmd1);
+ tmpinset->dispatch(cmd1);
break;
}
if (!is_rtl)
InsetOld * tmpinset = cursorPar()->getInset(cursor.pos());
cmd.message(tmpinset->editMessage());
FuncRequest cmd1(bv, LFUN_INSET_EDIT, is_rtl ? "left" : "right");
- tmpinset->localDispatch(cmd1);
+ tmpinset->dispatch(cmd1);
break;
}
if (is_rtl)
if (cursor.pos() == 0
&& !(params.spaceTop() == VSpace (VSpace::NONE))) {
setParagraph(
- params.lineTop(),
- params.lineBottom(),
- params.pagebreakTop(),
- params.pagebreakBottom(),
VSpace(VSpace::NONE),
params.spaceBottom(),
params.spacing(),
ParagraphParameters & params = cursorPar()->params();
if (cursor.pos() == 0 && !(params.spaceTop() == VSpace(VSpace::NONE))) {
setParagraph(
- params.lineTop(),
- params.lineBottom(),
- params.pagebreakTop(),
- params.pagebreakBottom(),
VSpace(VSpace::NONE),
params.spaceBottom(),
params.spacing(),
ParagraphParameters & params = getPar(cur)->params();
if (params.spaceTop() == VSpace(VSpace::NONE)) {
setParagraph(
- params.lineTop(),
- params.lineBottom(),
- params.pagebreakTop(),
- params.pagebreakBottom(),
VSpace(VSpace::DEFSKIP), params.spaceBottom(),
params.spacing(),
params.align(),
break;
case LFUN_TRANSPOSE_CHARS:
- recordUndo(bv, Undo::ATOMIC, cursorPar());
+ recUndo(cursor.par());
redoParagraph();
bv->update();
break;
case LFUN_BEGINNINGBUFSEL:
if (inset_owner)
- return UNDISPATCHED;
+ return DispatchResult(false);
cursorTop();
finishChange(bv, true);
break;
case LFUN_ENDBUFSEL:
if (inset_owner)
- return UNDISPATCHED;
+ return DispatchResult(false);
cursorBottom();
finishChange(bv, true);
break;
if (bv->theLockingInset()) {
InsetOld * tli = bv->theLockingInset();
LyXCursor cursor = bv->text->cursor;
- LyXFont font = bv->text->getFont(cursorPar(), cursor.pos());
+ LyXFont font = bv->text->getFont(bv->text->cursorPar(), cursor.pos());
int width = tli->width();
int inset_x = font.isVisibleRightToLeft()
? cursor.x() - width : cursor.x();
FuncRequest cmd1 = cmd;
cmd1.x = cmd.x - start_x;
cmd1.y = cmd.y - cursor.y() + bv->top_y();
- tli->localDispatch(cmd1);
+ tli->dispatch(cmd1);
break;
}
// otherwise give the event to the inset
if (inset_hit == bv->theLockingInset()) {
FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());
- bv->theLockingInset()->localDispatch(cmd1);
+ bv->theLockingInset()->dispatch(cmd1);
break;
}
bv->unlockInset(bv->theLockingInset());
if (!bv->lockInset(inset))
lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());
- inset->localDispatch(cmd1);
+ inset->dispatch(cmd1);
break;
}
// I'm not sure we should continue here if we hit an inset (Jug20020403)
bv->text->setCursorFromCoordinates(x, y + screen_first);
finishUndo();
bv->text->selection.cursor = bv->text->cursor;
- bv->text->cursor.x_fix(bv->text->cursor.x());
+ bv->x_target(bv->text->cursor.x());
if (bv->fitCursor())
selection_possible = false;
// Only a ButtonPress FuncRequest outside the inset will
// force a insetUnlock.
FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
- bv->theLockingInset()->localDispatch(cmd1);
+ bv->theLockingInset()->dispatch(cmd1);
break;
}
// ...or maybe the recordUndo()
// below isn't necessary at all anylonger?
if (inset_hit->lyxCode() == InsetOld::REF_CODE)
- recordUndo(bv, Undo::ATOMIC);
+ recUndo(cursor.par());
bv->owner()->message(inset_hit->editMessage());
FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
- inset_hit->localDispatch(cmd1);
+ inset_hit->dispatch(cmd1);
}
break;
case LFUN_INDEX_PRINT:
case LFUN_TOC_INSERT:
case LFUN_HFILL:
+ case LFUN_INSERT_LINE:
+ case LFUN_INSERT_PAGEBREAK:
// do nothing fancy
doInsertInset(this, cmd, false, false);
break;
break;
default:
- return UNDISPATCHED;
+ return DispatchResult(false);
}
- return DISPATCHED;
+ return DispatchResult(true, true);
}