-/* This file is part of
- * ======================================================
+/**
+ * \file text3.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
- * LyX, The Document Processor
+ * \author Asger Alstrup
+ * \author Lars Gullik Bjønnes
+ * \author Alfredo Braunstein
+ * \author Angus Leeming
+ * \author John Levon
+ * \author André Pönitz
*
- * Copyright 1995 Matthias Ettrich
- * Copyright 1995-2002 The LyX Team.
- *
- * ====================================================== */
+ * Full author contact details are available in file CREDITS.
+ */
#include <config.h>
#include "lyxtext.h"
-#include "lyxrow.h"
-#include "paragraph.h"
+
+#include "buffer.h"
+#include "bufferparams.h"
#include "BufferView.h"
-#include "funcrequest.h"
-#include "lyxrc.h"
-#include "Lsstream.h"
#include "debug.h"
-#include "bufferparams.h"
-#include "buffer.h"
-#include "bufferview_funcs.h"
-#include "ParagraphParameters.h"
-#include "gettext.h"
+#include "dispatchresult.h"
#include "factory.h"
+#include "funcrequest.h"
+#include "gettext.h"
#include "intl.h"
-#include "box.h"
#include "language.h"
-#include "support/tostr.h"
-#include "support/lstrings.h"
-#include "frontends/LyXView.h"
-#include "frontends/screen.h"
+#include "lyxrc.h"
+#include "lyxrow.h"
+#include "paragraph.h"
+#include "ParagraphParameters.h"
+#include "text_funcs.h"
+#include "undo.h"
+#include "vspace.h"
+
#include "frontends/Dialogs.h"
-#include "insets/insetspecialchar.h"
-#include "insets/insettext.h"
-#include "insets/insetquotes.h"
+#include "frontends/LyXView.h"
+
#include "insets/insetcommand.h"
#include "insets/insetnewline.h"
-#include "undo_funcs.h"
-#include "text_funcs.h"
-#include "Lsstream.h"
+#include "insets/insetspecialchar.h"
+#include "insets/insettext.h"
+
+#include "support/lstrings.h"
+#include "support/tostr.h"
-#include <ctime>
+#include "support/std_sstream.h"
#include <clocale>
-using namespace lyx::support;
-using namespace bv_funcs;
+using bv_funcs::replaceSelection;
+
+using lyx::pos_type;
+
+using lyx::support::isStrUnsignedInt;
+using lyx::support::strToUnsignedInt;
using std::endl;
using std::find;
+using std::string;
+using std::istringstream;
using std::vector;
-using lyx::pos_type;
+
extern string current_layout;
extern int bibitemMaxWidth(BufferView *, LyXFont const &);
{
LyXText * lt = bv->getLyXText();
- if (selecting || lt->selection.mark()) {
+// if (!lt->selection.set())
+// lt->selection.cursor = lt->cursor;
+
+ if (selecting || lt->selection.mark())
lt->setSelection();
- if (lt->isInInset())
- bv->updateInset(lt->inset_owner);
- else
- bv->toggleToggle();
- }
- if (!lt->isInInset()) {
- bv->update(lt, BufferView::SELECT);
- } else if (bv->text->needRefresh()) {
- bv->update(BufferView::SELECT);
- }
if (!lt->selection.set())
bv->haveSelection(false);
+ bv->update();
bv->switchKeyMap();
}
// check if the given co-ordinates are inside an inset at the
// given cursor, if one exists. If so, the inset is returned,
// and the co-ordinates are made relative. Otherwise, 0 is returned.
- Inset * checkInset(BufferView * bv, LyXText & text,
+ InsetOld * checkInset(LyXText & text,
LyXCursor const & cur, int & x, int & y)
{
lyx::pos_type const pos = cur.pos();
- ParagraphList::iterator par = cur.par();
+ ParagraphList::iterator par = text.getPar(cur);
if (pos >= par->size() || !par->isInset(pos))
return 0;
- Inset /*const*/ * inset = par->getInset(pos);
+ InsetOld /*const*/ * inset = par->getInset(pos);
if (!isEditableInset(inset))
return 0;
// get inset dimensions
- Assert(par->getInset(pos));
+ BOOST_ASSERT(par->getInset(pos));
- LyXFont const & font = text.getFont(bv->buffer(), par, pos);
+ LyXFont const & font = text.getFont(par, pos);
- int const width = inset->width(bv, font);
+ int const width = inset->width();
int const inset_x = font.isVisibleRightToLeft()
- ? (cur.ix() - width) : cur.ix();
+ ? (cur.x() - width) : cur.x();
Box b(
inset_x + inset->scroll(),
inset_x + width,
- cur.iy() - inset->ascent(bv, font),
- cur.iy() + inset->descent(bv, font)
+ cur.y() - inset->ascent(),
+ cur.y() + inset->descent()
);
- if (!b.contained(x, y)) {
+ if (!b.contains(x, y)) {
lyxerr[Debug::GUI] << "Missed inset at x,y "
<< x << ',' << y
<< " box " << b << endl;
return 0;
}
- text.setCursor(par, pos, true);
+ text.setCursor(cur.par(), pos, true);
x -= b.x1;
// The origin of an inset is on the baseline
- y -= text.cursor.iy();
+ y -= text.cursor.y();
return inset;
}
} // anon namespace
-Inset * LyXText::checkInsetHit(int & x, int & y)
+InsetOld * LyXText::checkInsetHit(int & x, int & y)
{
- int y_tmp = y + top_y();
+ int y_tmp = y + bv_owner->top_y();
LyXCursor cur;
setCursorFromCoordinates(cur, x, y_tmp);
- Inset * inset = checkInset(bv(), *this, cur, x, y_tmp);
+ InsetOld * inset = checkInset(*this, cur, x, y_tmp);
if (inset) {
y = y_tmp;
return inset;
// move back one
setCursor(cur, cur.par(), cur.pos() - 1, true);
- inset = checkInset(bv(), *this, cur, x, y_tmp);
+ inset = checkInset(*this, cur, x, y_tmp);
if (inset)
y = y_tmp;
return inset;
}
-bool LyXText::gotoNextInset(vector<Inset::Code> const & codes,
+bool LyXText::gotoNextInset(vector<InsetOld::Code> const & codes,
string const & contents)
{
ParagraphList::iterator end = ownerParagraphs().end();
- ParagraphList::iterator pit = cursor.par();
+ ParagraphList::iterator pit = cursorPar();
pos_type pos = cursor.pos();
- Inset * inset;
+ InsetOld * inset;
do {
if (pos + 1 < pit->size()) {
++pos;
static_cast<InsetCommand *>(pit->getInset(pos))->getContents()
== contents)));
- if (pit != end) {
- setCursor(pit, pos, false);
- return true;
- }
- return false;
+ if (pit == end)
+ return false;
+
+ setCursor(parOffset(pit), pos, false);
+ return true;
}
-void LyXText::gotoInset(vector<Inset::Code> const & codes,
+void LyXText::gotoInset(vector<InsetOld::Code> const & codes,
bool same_content)
{
bv()->beforeChange(this);
- update();
string contents;
- if (same_content && cursor.pos() < cursor.par()->size()
- && cursor.par()->isInset(cursor.pos())) {
- Inset const * inset = cursor.par()->getInset(cursor.pos());
+ if (same_content && cursor.pos() < cursorPar()->size()
+ && cursorPar()->isInset(cursor.pos())) {
+ InsetOld const * inset = cursorPar()->getInset(cursor.pos());
if (find(codes.begin(), codes.end(), inset->lyxCode())
!= codes.end())
contents = static_cast<InsetCommand const *>(inset)->getContents();
}
if (!gotoNextInset(codes, contents)) {
- if (cursor.pos() || cursor.par() != ownerParagraphs().begin()) {
+ if (cursor.pos() || cursorPar() != ownerParagraphs().begin()) {
LyXCursor tmp = cursor;
- cursor.par(ownerParagraphs().begin());
+ cursor.par(0);
cursor.pos(0);
if (!gotoNextInset(codes, contents)) {
cursor = tmp;
bv()->owner()->message(_("No more insets"));
}
}
- update();
+ bv()->update();
selection.cursor = cursor;
}
-void LyXText::gotoInset(Inset::Code code, bool same_content)
+void LyXText::gotoInset(InsetOld::Code code, bool same_content)
{
- gotoInset(vector<Inset::Code>(1, code), same_content);
+ gotoInset(vector<InsetOld::Code>(1, code), same_content);
}
void LyXText::cursorPrevious()
{
- int y = top_y();
+ int y = bv()->top_y();
+
+ ParagraphList::iterator cpit = cursorPar();
+ RowList::iterator crit = cpit->getRow(cursor.pos());
- if (cursorRow() == rows().begin()) {
- if (y > 0) {
- int new_y = bv()->text->top_y() - bv()->workHeight();
- bv()->screen().draw(bv()->text, bv(), new_y < 0 ? 0 : new_y);
+ if (isFirstRow(cpit, *crit)) {
+ if (y > 0)
bv()->updateScrollbar();
- }
return;
}
- RowList::iterator cursorrow = cursorRow();
-
- setCursorFromCoordinates(cursor.x_fix(), y);
+ setCursorFromCoordinates(bv()->x_target(), y);
finishUndo();
- int new_y;
- if (cursorrow == 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.
-#if 0
- new_y = bv->text->top_y() - bv->workHeight();
-#endif
- } else {
- if (inset_owner) {
- new_y = bv()->text->cursor.iy()
- + bv()->theLockingInset()->insetInInsetY() + y
- + cursorRow()->height()
- - bv()->workHeight() + 1;
- } else {
- new_y = cursor.y()
- - cursorRow()->baseline()
- + cursorRow()->height()
- - bv()->workHeight() + 1;
- }
}
- bv()->screen().draw(bv()->text, bv(), new_y < 0 ? 0 : new_y);
- if (cursorRow() != rows().begin()) {
- LyXCursor cur;
- setCursor(cur, boost::prior(cursorRow())->par(),
- boost::prior(cursorRow())->pos(), false);
- if (cur.y() > top_y()) {
- cursorUp(true);
- }
+
+ int new_y = + crit->height() - bv()->workHeight() + 1;
+
+ if (inset_owner) {
+ new_y += bv()->text->cursor.y()
+ + bv()->theLockingInset()->insetInInsetY() + y;
+ } else {
+ new_y += cursor.y() - crit->baseline();
}
+
+ previousRow(cpit, crit);
+ LyXCursor cur;
+ setCursor(cur, parOffset(cpit), crit->pos(), false);
+ if (cur.y() > bv()->top_y())
+ cursorUp(true);
bv()->updateScrollbar();
}
void LyXText::cursorNext()
{
- int topy = top_y();
+ int topy = bv()->top_y();
- if (boost::next(cursorRow()) == rows().end()) {
- int y = cursor.y() - cursorRow()->baseline() +
- cursorRow()->height();
- if (y > topy + bv()->workHeight()) {
- bv()->screen().draw(bv()->text, bv(), bv()->text->top_y() + bv()->workHeight());
+ 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()->updateScrollbar();
- }
return;
}
int y = topy + bv()->workHeight();
if (inset_owner && !topy) {
- y -= (bv()->text->cursor.iy()
- - bv()->text->top_y()
+ y -= (bv()->text->cursor.y()
+ - bv()->top_y()
+ bv()->theLockingInset()->insetInInsetY());
}
- getRowNearY(y);
+ ParagraphList::iterator dummypit;
+ Row const & rr = *getRowNearY(y, dummypit);
+ y = dummypit->y + rr.y_offset();
- RowList::iterator cursorrow = cursorRow();
- setCursorFromCoordinates(cursor.x_fix(), y);
+ setCursorFromCoordinates(bv()->x_target(), y);
// + bv->workHeight());
finishUndo();
int new_y;
- if (cursorrow == 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 next row instead.
cursorDown(true);
// This is what we used to do, so we wouldn't skip right past
// tall rows, but it's not working right now.
#if 0
- new_y = bv->text->top_y() + bv->workHeight();
+ new_y = bv->top_y() + bv->workHeight();
#endif
- } else {
- if (inset_owner) {
- new_y = bv()->text->cursor.iy()
- + bv()->theLockingInset()->insetInInsetY()
- + y - cursorRow()->baseline();
- } else {
- new_y = cursor.y() - cursorRow()->baseline();
- }
}
- bv()->screen().draw(bv()->text, bv(), new_y);
-
- RowList::iterator next_row = boost::next(cursorRow());
- if (next_row != rows().end()) {
- LyXCursor cur;
- setCursor(cur, next_row->par(), next_row->pos(), false);
- if (cur.y() < top_y() + bv()->workHeight()) {
- cursorDown(true);
- }
+
+ if (inset_owner) {
+ new_y = bv()->text->cursor.y()
+ + bv()->theLockingInset()->insetInInsetY()
+ + y - crit->baseline();
+ } else {
+ new_y = cursor.y() - crit->baseline();
}
- bv()->updateScrollbar();
-}
-void LyXText::update()
-{
- bv()->update(this, BufferView::SELECT);
+ nextRow(cpit, crit);
+ LyXCursor cur;
+ setCursor(cur, parOffset(cpit), crit->pos(), false);
+ if (cur.y() < bv_owner->top_y() + bv()->workHeight())
+ cursorDown(true);
+ bv()->updateScrollbar();
}
+
namespace {
void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind)
{
- lt->update();
+ bv->update();
InsetSpecialChar * new_inset = new InsetSpecialChar(kind);
replaceSelection(lt);
if (!bv->insertInset(new_inset))
void doInsertInset(LyXText * lt, FuncRequest const & cmd,
bool edit, bool pastesel)
{
- Inset * inset = createInset(cmd);
+ InsetOld * inset = createInset(cmd);
BufferView * bv = cmd.view();
if (inset) {
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
-Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
+
+DispatchResult LyXText::dispatch(FuncRequest const & cmd)
{
- lyxerr[Debug::ACTION] << "LyXFunc::dispatch: action[" << cmd.action
- <<"] arg[" << cmd.argument << ']' << endl;
+ lyxerr[Debug::ACTION] << "LyXText::dispatch: action[" << cmd.action
+ <<"] arg[" << cmd.argument << ']' << "xy[" <<
+ cmd.x << ',' << cmd.y << ']' << endl;
BufferView * bv = cmd.view();
switch (cmd.action) {
case LFUN_APPENDIX: {
- ParagraphList::iterator pit = cursor.par();
+ ParagraphList::iterator pit = cursorPar();
bool start = !pit->params().startOfAppendix();
// ensure that we have only one start_of_appendix in this document
for (; tmp != end; ++tmp) {
if (tmp->params().startOfAppendix()) {
- setUndo(bv, Undo::EDIT, tmp);
+ recUndo(parOffset(tmp));
tmp->params().startOfAppendix(false);
- int tmpy;
- setHeightOfRow(getRow(tmp, 0, tmpy));
+ redoParagraph(tmp);
break;
}
}
- setUndo(bv, Undo::EDIT, pit);
+ recUndo(parOffset(pit));
pit->params().startOfAppendix(start);
// we can set the refreshing parameters now
updateCounters();
- redoHeightOfParagraph();
- postPaint(0);
- setCursor(cursor.par(), cursor.pos());
- update();
+ redoParagraph(cursorPar());
+ setCursor(cursorPar(), cursor.pos());
+ bv->update();
break;
}
case LFUN_DELETE_WORD_FORWARD:
bv->beforeChange(this);
- update();
deleteWordForward();
- update();
finishChange(bv);
break;
case LFUN_DELETE_WORD_BACKWARD:
bv->beforeChange(this);
- update();
deleteWordBackward();
- update();
finishChange(bv);
break;
case LFUN_DELETE_LINE_FORWARD:
bv->beforeChange(this);
- update();
deleteLineForward();
- update();
finishChange(bv);
break;
case LFUN_WORDRIGHT:
if (!selection.mark())
bv->beforeChange(this);
- update();
- if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
+ if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
cursorLeftOneWord();
else
cursorRightOneWord();
case LFUN_WORDLEFT:
if (!selection.mark())
bv->beforeChange(this);
- update();
- if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
+ if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
cursorRightOneWord();
else
cursorLeftOneWord();
case LFUN_BEGINNINGBUF:
if (!selection.mark())
bv->beforeChange(this);
- update();
cursorTop();
finishChange(bv);
break;
case LFUN_ENDBUF:
if (selection.mark())
bv->beforeChange(this);
- update();
cursorBottom();
finishChange(bv);
break;
case LFUN_RIGHTSEL:
- update();
- if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
+ if (!selection.set())
+ selection.cursor = cursor;
+ if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
cursorLeft(bv);
else
cursorRight(bv);
break;
case LFUN_LEFTSEL:
- update();
- if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
+ if (!selection.set())
+ selection.cursor = cursor;
+ if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
cursorRight(bv);
else
cursorLeft(bv);
break;
case LFUN_UPSEL:
- update();
+ if (!selection.set())
+ selection.cursor = cursor;
cursorUp(true);
finishChange(bv, true);
break;
case LFUN_DOWNSEL:
- update();
+ if (!selection.set())
+ selection.cursor = cursor;
cursorDown(true);
finishChange(bv, true);
break;
case LFUN_UP_PARAGRAPHSEL:
- update();
+ if (!selection.set())
+ selection.cursor = cursor;
cursorUpParagraph();
finishChange(bv, true);
break;
case LFUN_DOWN_PARAGRAPHSEL:
- update();
+ if (!selection.set())
+ selection.cursor = cursor;
cursorDownParagraph();
finishChange(bv, true);
break;
case LFUN_PRIORSEL:
- update();
+ if (!selection.set())
+ selection.cursor = cursor;
cursorPrevious();
finishChange(bv, true);
break;
case LFUN_NEXTSEL:
- update();
+ if (!selection.set())
+ selection.cursor = cursor;
cursorNext();
finishChange(bv, true);
break;
case LFUN_HOMESEL:
- update();
+ if (!selection.set())
+ selection.cursor = cursor;
cursorHome();
finishChange(bv, true);
break;
case LFUN_ENDSEL:
- update();
+ if (!selection.set())
+ selection.cursor = cursor;
cursorEnd();
finishChange(bv, true);
break;
case LFUN_WORDRIGHTSEL:
- update();
- if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
+ if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
cursorLeftOneWord();
else
cursorRightOneWord();
break;
case LFUN_WORDLEFTSEL:
- update();
- if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
+ if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
cursorRightOneWord();
else
cursorLeftOneWord();
break;
case LFUN_WORDSEL: {
- update();
LyXCursor cur1 = cursor;
LyXCursor cur2;
- ::getWord(cur1, cur2, lyx::WHOLE_WORD, ownerParagraphs());
+ ::getWord(*this, cur1, cur2, lyx::WHOLE_WORD, ownerParagraphs());
setCursor(cur1.par(), cur1.pos());
bv->beforeChange(this);
setCursor(cur2.par(), cur2.pos());
}
case LFUN_RIGHT: {
- bool is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params);
+ bool is_rtl = cursorPar()->isRightToLeftPar(bv->buffer()->params());
if (!selection.mark())
bv->beforeChange(this);
- update();
if (is_rtl)
cursorLeft(false);
- if (cursor.pos() < cursor.par()->size()
- && cursor.par()->isInset(cursor.pos())
- && isHighlyEditableInset(cursor.par()->getInset(cursor.pos()))) {
- Inset * tmpinset = cursor.par()->getInset(cursor.pos());
+ if (cursor.pos() < cursorPar()->size()
+ && cursorPar()->isInset(cursor.pos())
+ && isHighlyEditableInset(cursorPar()->getInset(cursor.pos()))) {
+ 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)
case LFUN_LEFT: {
// This is soooo ugly. Isn`t it possible to make
// it simpler? (Lgb)
- bool const is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params);
+ bool const is_rtl = cursorPar()->isRightToLeftPar(bv->buffer()->params());
if (!selection.mark())
bv->beforeChange(this);
- update();
LyXCursor const cur = cursor;
if (!is_rtl)
cursorLeft(false);
if ((is_rtl || cur != cursor) && // only if really moved!
- cursor.pos() < cursor.par()->size() &&
- cursor.par()->isInset(cursor.pos()) &&
- isHighlyEditableInset(cursor.par()->getInset(cursor.pos()))) {
- Inset * tmpinset = cursor.par()->getInset(cursor.pos());
+ cursor.pos() < cursorPar()->size() &&
+ cursorPar()->isInset(cursor.pos()) &&
+ isHighlyEditableInset(cursorPar()->getInset(cursor.pos()))) {
+ 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)
case LFUN_UP:
if (!selection.mark())
bv->beforeChange(this);
- bv->update(this, BufferView::UPDATE);
- cursorUp(bv);
+ cursorUp(false);
finishChange(bv);
break;
case LFUN_DOWN:
if (!selection.mark())
bv->beforeChange(this);
- bv->update(this, BufferView::UPDATE);
- cursorDown(bv);
+ cursorDown(false);
finishChange(bv);
break;
case LFUN_UP_PARAGRAPH:
if (!selection.mark())
bv->beforeChange(this);
- bv->update(this, BufferView::UPDATE);
cursorUpParagraph();
finishChange(bv);
break;
case LFUN_DOWN_PARAGRAPH:
if (!selection.mark())
bv->beforeChange(this);
- bv->update(this, BufferView::UPDATE);
cursorDownParagraph();
finishChange(bv, false);
break;
case LFUN_PRIOR:
if (!selection.mark())
bv->beforeChange(this);
- bv->update(this, BufferView::UPDATE);
cursorPrevious();
finishChange(bv, false);
- // was:
- // finishUndo();
- // moveCursorUpdate(bv, false, false);
- // owner_->view_state_changed();
break;
case LFUN_NEXT:
if (!selection.mark())
bv->beforeChange(this);
- bv->update(this, BufferView::UPDATE);
cursorNext();
finishChange(bv, false);
break;
case LFUN_HOME:
if (!selection.mark())
bv->beforeChange(this);
- update();
cursorHome();
finishChange(bv, false);
break;
case LFUN_END:
if (!selection.mark())
bv->beforeChange(this);
- update();
cursorEnd();
finishChange(bv, false);
break;
case LFUN_BREAKLINE: {
- lyx::pos_type body = cursor.par()->beginningOfBody();
+ lyx::pos_type body = cursorPar()->beginningOfBody();
// Not allowed by LaTeX (labels or empty par)
if (cursor.pos() <= body)
replaceSelection(bv->getLyXText());
insertInset(new InsetNewline);
- update();
- setCursor(cursor.par(), cursor.pos());
+ setCursor(cursorPar(), cursor.pos());
moveCursorUpdate(bv, false);
break;
}
if (!selection.set()) {
Delete();
selection.cursor = cursor;
- update();
// It is possible to make it a lot faster still
// just comment out the line below...
} else {
- update();
cutSelection(true, false);
- update();
}
moveCursorUpdate(bv, false);
bv->owner()->view_state_changed();
- bv->switchKeyMap();
break;
case LFUN_DELETE_SKIP:
// Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
if (!selection.set()) {
- LyXCursor cur = cursor;
- if (cur.pos() == cur.par()->size()) {
+ if (cursor.pos() == cursorPar()->size()) {
cursorRight(bv);
- cur = cursor;
- if (cur.pos() == 0
- && !(cur.par()->params().spaceTop()
- == VSpace (VSpace::NONE))) {
+ ParagraphParameters & params = cursorPar()->params();
+ if (cursor.pos() == 0
+ && !(params.spaceTop() == VSpace (VSpace::NONE))) {
setParagraph(
- cur.par()->params().lineTop(),
- cur.par()->params().lineBottom(),
- cur.par()->params().pagebreakTop(),
- cur.par()->params().pagebreakBottom(),
VSpace(VSpace::NONE),
- cur.par()->params().spaceBottom(),
- cur.par()->params().spacing(),
- cur.par()->params().align(),
- cur.par()->params().labelWidthString(), 0);
+ params.spaceBottom(),
+ params.spacing(),
+ params.align(),
+ params.labelWidthString(), 0);
cursorLeft(bv);
- update();
} else {
cursorLeft(bv);
Delete();
selection.cursor = cursor;
}
} else {
- update();
cutSelection(true, false);
}
- update();
+ bv->update();
break;
if (bv->owner()->getIntl().getTransManager().backspace()) {
backspace();
selection.cursor = cursor;
- update();
// It is possible to make it a lot faster still
// just comment out the line below...
}
} else {
- update();
cutSelection(true, false);
- update();
}
bv->owner()->view_state_changed();
bv->switchKeyMap();
+ bv->update();
break;
case LFUN_BACKSPACE_SKIP:
// Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
if (!selection.set()) {
- LyXCursor cur = cursor;
- if (cur.pos() == 0
- && !(cur.par()->params().spaceTop()
- == VSpace (VSpace::NONE))) {
+ ParagraphParameters & params = cursorPar()->params();
+ if (cursor.pos() == 0 && !(params.spaceTop() == VSpace(VSpace::NONE))) {
setParagraph(
- cur.par()->params().lineTop(),
- cur.par()->params().lineBottom(),
- cur.par()->params().pagebreakTop(),
- cur.par()->params().pagebreakBottom(),
- VSpace(VSpace::NONE), cur.par()->params().spaceBottom(),
- cur.par()->params().spacing(),
- cur.par()->params().align(),
- cur.par()->params().labelWidthString(), 0);
+ VSpace(VSpace::NONE),
+ params.spaceBottom(),
+ params.spacing(),
+ params.align(),
+ params.labelWidthString(), 0);
} else {
+ LyXCursor cur = cursor;
backspace();
selection.cursor = cur;
}
} else {
- update();
cutSelection(true, false);
}
- update();
+ bv->update();
break;
case LFUN_BREAKPARAGRAPH:
replaceSelection(bv->getLyXText());
- breakParagraph(bv->buffer()->paragraphs, 0);
- update();
+ breakParagraph(bv->buffer()->paragraphs(), 0);
+ bv->update();
selection.cursor = cursor;
bv->switchKeyMap();
bv->owner()->view_state_changed();
case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
replaceSelection(bv->getLyXText());
- breakParagraph(bv->buffer()->paragraphs, 1);
- update();
+ breakParagraph(bv->buffer()->paragraphs(), 1);
+ bv->update();
selection.cursor = cursor;
bv->switchKeyMap();
bv->owner()->view_state_changed();
LyXCursor cur = cursor;
replaceSelection(bv->getLyXText());
if (cur.pos() == 0) {
- if (cur.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
+ ParagraphParameters & params = getPar(cur)->params();
+ if (params.spaceTop() == VSpace(VSpace::NONE)) {
setParagraph(
- cur.par()->params().lineTop(),
- cur.par()->params().lineBottom(),
- cur.par()->params().pagebreakTop(),
- cur.par()->params().pagebreakBottom(),
- VSpace(VSpace::DEFSKIP), cur.par()->params().spaceBottom(),
- cur.par()->params().spacing(),
- cur.par()->params().align(),
- cur.par()->params().labelWidthString(), 1);
+ VSpace(VSpace::DEFSKIP), params.spaceBottom(),
+ params.spacing(),
+ params.align(),
+ params.labelWidthString(), 1);
}
}
else {
- breakParagraph(bv->buffer()->paragraphs, 0);
+ breakParagraph(bv->buffer()->paragraphs(), 0);
}
- update();
+ bv->update();
selection.cursor = cur;
bv->switchKeyMap();
bv->owner()->view_state_changed();
}
case LFUN_PARAGRAPH_SPACING: {
- ParagraphList::iterator pit = cursor.par();
+ ParagraphList::iterator pit = cursorPar();
Spacing::Space cur_spacing = pit->params().spacing().getSpace();
float cur_value = 1.0;
if (cur_spacing == Spacing::Other)
cur_value = pit->params().spacing().getValue();
- istringstream is(STRCONV(cmd.argument));
+ istringstream is(cmd.argument);
string tmp;
is >> tmp;
Spacing::Space new_spacing = cur_spacing;
if (cur_spacing != new_spacing || cur_value != new_value) {
pit->params().spacing(Spacing(new_spacing, new_value));
redoParagraph();
- update();
+ bv->update();
}
break;
}
case LFUN_INSET_SETTINGS:
- Assert(bv->theLockingInset());
+ BOOST_ASSERT(bv->theLockingInset());
bv->theLockingInset()->getLockingInset()->showInsetDialog(bv);
break;
case LFUN_INSET_TOGGLE:
bv->beforeChange(this);
- update();
toggleInset();
- update();
+ bv->update();
bv->switchKeyMap();
break;
case LFUN_SPACE_INSERT:
- if (cursor.par()->layout()->free_spacing) {
+ if (cursorPar()->layout()->free_spacing)
insertChar(' ');
- update();
- } else {
+ else
doInsertInset(this, cmd, false, false);
- }
moveCursorUpdate(bv, false);
break;
case LFUN_MARK_OFF:
bv->beforeChange(this);
- update();
+ bv->update();
selection.cursor = cursor;
cmd.message(N_("Mark off"));
break;
case LFUN_MARK_ON:
bv->beforeChange(this);
selection.mark(true);
- update();
+ bv->update();
selection.cursor = cursor;
cmd.message(N_("Mark on"));
break;
case LFUN_SETMARK:
bv->beforeChange(this);
if (selection.mark()) {
- update();
cmd.message(N_("Mark removed"));
} else {
selection.mark(true);
- update();
cmd.message(N_("Mark set"));
}
selection.cursor = cursor;
+ bv->update();
break;
case LFUN_UPCASE_WORD:
- update();
changeCase(LyXText::text_uppercase);
- if (inset_owner)
- bv->updateInset(inset_owner);
- update();
+ bv->update();
break;
case LFUN_LOWCASE_WORD:
- update();
changeCase(LyXText::text_lowercase);
- if (inset_owner)
- bv->updateInset(inset_owner);
- update();
+ bv->update();
break;
case LFUN_CAPITALIZE_WORD:
- update();
changeCase(LyXText::text_capitalization);
- if (inset_owner)
- bv->updateInset(inset_owner);
- update();
+ bv->update();
break;
case LFUN_TRANSPOSE_CHARS:
- update();
- setUndo(bv, Undo::FINISH, cursor.par());
- if (transposeChars(cursor))
- checkParagraph(cursor.par(), cursor.pos());
- if (inset_owner)
- bv->updateInset(inset_owner);
- update();
+ recUndo(cursor.par());
+ redoParagraph();
+ bv->update();
break;
- case LFUN_PASTE: {
+ case LFUN_PASTE:
cmd.message(_("Paste"));
replaceSelection(bv->getLyXText());
- size_t sel_index = 0;
- string const & arg = cmd.argument;
- if (isStrUnsignedInt(arg)) {
- size_t const paste_arg = strToUnsignedInt(arg);
#warning FIXME Check if the arg is in the domain of available selections.
- sel_index = paste_arg;
- }
- pasteSelection(sel_index);
+ if (isStrUnsignedInt(cmd.argument))
+ pasteSelection(strToUnsignedInt(cmd.argument));
+ else
+ pasteSelection(0);
clearSelection(); // bug 393
- update();
+ bv->update();
bv->switchKeyMap();
+ finishUndo();
break;
- }
case LFUN_CUT:
- update();
cutSelection(true, true);
- update();
cmd.message(_("Cut"));
+ bv->update();
break;
case LFUN_COPY:
case LFUN_BEGINNINGBUFSEL:
if (inset_owner)
- return UNDISPATCHED;
- update();
+ return DispatchResult(false);
cursorTop();
finishChange(bv, true);
break;
case LFUN_ENDBUFSEL:
if (inset_owner)
- return UNDISPATCHED;
- update();
+ return DispatchResult(false);
cursorBottom();
finishChange(bv, true);
break;
case LFUN_SETXY: {
int x = 0;
int y = 0;
- istringstream is(STRCONV(cmd.argument));
+ istringstream is(cmd.argument);
is >> x >> y;
if (!is)
lyxerr << "SETXY: Could not parse coordinates in '"
break;
case LFUN_GETLAYOUT:
- cmd.message(tostr(cursor.par()->layout()));
+ cmd.message(tostr(cursorPar()->layout()));
break;
case LFUN_LAYOUT: {
// Derive layout number from given argument (string)
// and current buffer's textclass (number)
- LyXTextClass const & tclass = bv->buffer()->params.getLyXTextClass();
+ LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
bool hasLayout = tclass.hasLayout(cmd.argument);
string layout = cmd.argument;
if (!change_layout && selection.set() &&
selection.start.par() != selection.end.par())
{
- ParagraphList::iterator spit = selection.start.par();
- ParagraphList::iterator epit = boost::next(selection.end.par());
+ ParagraphList::iterator spit = getPar(selection.start);
+ ParagraphList::iterator epit = boost::next(getPar(selection.end));
while (spit != epit) {
if (spit->layout()->name() != current_layout) {
change_layout = true;
if (change_layout) {
current_layout = layout;
- update();
setLayout(layout);
bv->owner()->setLayout(layout);
- update();
+ bv->update();
bv->switchKeyMap();
}
break;
}
case LFUN_PASTESELECTION: {
- if (!bv->buffer())
- break;
// this was originally a beforeChange(bv->text), i.e
// the outermost LyXText!
bv->beforeChange(this);
else
insertStringAsLines(clip);
clearSelection();
- update();
+ bv->update();
}
break;
}
case LFUN_GOTOERROR:
- gotoInset(Inset::ERROR_CODE, false);
+ gotoInset(InsetOld::ERROR_CODE, false);
break;
case LFUN_GOTONOTE:
- gotoInset(Inset::NOTE_CODE, false);
+ gotoInset(InsetOld::NOTE_CODE, false);
break;
case LFUN_REFERENCE_GOTO:
{
- vector<Inset::Code> tmp;
- tmp.push_back(Inset::LABEL_CODE);
- tmp.push_back(Inset::REF_CODE);
+ vector<InsetOld::Code> tmp;
+ tmp.push_back(InsetOld::LABEL_CODE);
+ tmp.push_back(InsetOld::REF_CODE);
gotoInset(tmp, true);
break;
}
case LFUN_QUOTE: {
replaceSelection(bv->getLyXText());
- ParagraphList::iterator pit = cursor.par();
+ ParagraphList::iterator pit = cursorPar();
lyx::pos_type pos = cursor.pos();
char c;
if (!pos)
LyXLayout_ptr const & style = pit->layout();
+ BufferParams const & bufparams = bv->buffer()->params();
if (style->pass_thru ||
- pit->getFontSettings(bv->buffer()->params,
- pos).language()->lang() == "hebrew" ||
- (!bv->insertInset(new InsetQuotes(c, bv->buffer()->params))))
+ pit->getFontSettings(bufparams,pos).language()->lang() == "hebrew" ||
+ !bv->insertInset(new InsetQuotes(c, bufparams)))
bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
break;
}
int const datetmp_len =
::strftime(datetmp, 32, arg.c_str(), now_tm);
- for (int i = 0; i < datetmp_len; i++) {
+ for (int i = 0; i < datetmp_len; i++)
insertChar(datetmp[i]);
- update();
- }
+
selection.cursor = cursor;
moveCursorUpdate(bv, false);
break;
if (!isInInset() && bv->theLockingInset())
break;
if (cmd.button() == mouse_button::button1) {
- if (!isInInset()) {
- bv->screen().toggleSelection(this, bv);
- }
cursorHome();
selection.cursor = cursor;
cursorEnd();
setSelection();
- if (!isInInset())
- bv->screen().toggleSelection(this, bv, false);
- update();
+ bv->update();
bv->haveSelection(selection.set());
}
break;
if (!isInInset() && bv->theLockingInset())
break;
if (cmd.button() == mouse_button::button1) {
- if (!isInInset()) {
- bv->screen().toggleSelection(this, bv);
- selectWord(lyx::WHOLE_WORD_STRICT);
- bv->screen().toggleSelection(this, bv, false);
- } else {
- selectWord(lyx::WHOLE_WORD_STRICT);
- }
- update();
+ selectWord(lyx::WHOLE_WORD_STRICT);
+ bv->update();
bv->haveSelection(selection.set());
}
break;
// Check for inset locking
if (bv->theLockingInset()) {
- Inset * tli = bv->theLockingInset();
+ InsetOld * tli = bv->theLockingInset();
LyXCursor cursor = bv->text->cursor;
- LyXFont font = bv->text->getFont(bv->buffer(),
- cursor.par(), cursor.pos());
- int width = tli->width(bv, font);
+ LyXFont font = bv->text->getFont(bv->text->cursorPar(), cursor.pos());
+ int width = tli->width();
int inset_x = font.isVisibleRightToLeft()
- ? cursor.ix() - width : cursor.ix();
+ ? cursor.x() - width : cursor.x();
int start_x = inset_x + tli->scroll();
FuncRequest cmd1 = cmd;
cmd1.x = cmd.x - start_x;
- cmd1.y = cmd.y - cursor.iy() + bv->text->top_y();
- tli->localDispatch(cmd1);
+ cmd1.y = cmd.y - cursor.y() + bv->top_y();
+ tli->dispatch(cmd1);
break;
}
}
RowList::iterator cursorrow = bv->text->cursorRow();
- bv->text->setCursorFromCoordinates(cmd.x, cmd.y + bv->text->top_y());
+ bv->text->setCursorFromCoordinates(cmd.x, cmd.y + bv->top_y());
#if 0
// sorry for this but I have a strange error that the y value jumps at
// a certain point. This seems like an error in my xforms library or
bv->text->cursorUp(false);
}
- // Maybe an empty line was deleted
- if (!bv->text->selection.set())
- bv->update(BufferView::UPDATE);
bv->text->setSelection();
- bv->screen().toggleToggle(bv->text, bv);
- bv->fitCursor();
+ bv->update();
break;
}
int x = cmd.x;
int y = cmd.y;
- Inset * inset_hit = bv->text->checkInsetHit(x, y);
+ InsetOld * inset_hit = bv->text->checkInsetHit(x, y);
// Middle button press pastes if we have a selection
// We do this here as if the selection was inside an inset
paste_internally = true;
}
- int const screen_first = bv->text->top_y();
+ int const screen_first = bv->top_y();
if (bv->theLockingInset()) {
// We are in inset locking mode
// 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());
selection_possible = true;
// Clear the selection
- bv->screen().toggleSelection(bv->text, bv);
bv->text->clearSelection();
- bv->text->partialRebreak();
bv->update();
bv->updateScrollbar();
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;
// inset, inset_hit is 0, and inset_x == x, inset_y == y.
int x = cmd.x;
int y = cmd.y;
- Inset * inset_hit = bv->text->checkInsetHit(x, y);
+ InsetOld * inset_hit = bv->text->checkInsetHit(x, y);
if (bv->theLockingInset()) {
// We are in inset locking mode.
// 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;
}
// stack. They don't *have* to
// alter the document...
// (Joacim)
- // ...or maybe the SetCursorParUndo()
+ // ...or maybe the recordUndo()
// below isn't necessary at all anylonger?
- if (inset_hit->lyxCode() == Inset::REF_CODE)
- setCursorParUndo(bv);
+ if (inset_hit->lyxCode() == InsetOld::REF_CODE)
+ 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;
// true (on).
if (lyxrc.auto_region_delete) {
- if (selection.set()) {
+ if (selection.set())
cutSelection(false, false);
- update();
- }
bv->haveSelection(false);
}
bv->beforeChange(this);
- LyXFont const old_font(real_current_font);
+ LyXFont const old_font = real_current_font;
string::const_iterator cit = cmd.argument.begin();
string::const_iterator end = cmd.argument.end();
bv->owner()->getIntl().getTransManager().
TranslateAndInsert(*cit, this);
- update();
selection.cursor = cursor;
moveCursorUpdate(bv, false);
// update the minibuffer
if (old_font != real_current_font)
bv->owner()->view_state_changed();
+ bv->updateScrollbar();
break;
}
case LFUN_INSET_CAPTION:
#endif
case LFUN_INSERT_NOTE:
+ case LFUN_INSERT_BOX:
+ case LFUN_INSERT_BRANCH:
case LFUN_INSERT_BIBITEM:
case LFUN_INSET_ERT:
case LFUN_INSET_FLOAT:
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;
+ case LFUN_DEPTH_MIN:
+ bv_funcs::changeDepth(bv, this, bv_funcs::DEC_DEPTH, false);
+ clearSelection();
+ bv->update();
+ break;
+
+ case LFUN_DEPTH_PLUS:
+ clearSelection();
+ bv_funcs::changeDepth(bv, this, bv_funcs::INC_DEPTH, false);
+ clearSelection();
+ bv->update();
+ break;
+
default:
- return UNDISPATCHED;
+ return DispatchResult(false);
}
- return DISPATCHED;
+ return DispatchResult(true, true);
}