-/* 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 "BufferView.h"
#include "funcrequest.h"
{
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->repaint();
- }
- bv->update();
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.
-InsetOld * checkInset(BufferView * /*bv*/, LyXText & text,
+ InsetOld * checkInset(BufferView * /*bv*/, LyXText & text,
LyXCursor const & cur, int & x, int & y)
{
lyx::pos_type const pos = cur.pos();
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(),
- cur.iy() + inset->descent()
+ 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;
x -= b.x1;
// The origin of an inset is on the baseline
- y -= text.cursor.iy();
+ y -= text.cursor.y();
return inset;
}
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);
bool same_content)
{
bv()->beforeChange(this);
- update();
string contents;
if (same_content && cursor.pos() < cursor.par()->size()
bv()->owner()->message(_("No more insets"));
}
}
- update();
+ bv()->update();
selection.cursor = cursor;
}
void LyXText::cursorPrevious()
{
- int y = top_y();
+ int y = bv_owner->top_y();
+
+ RowList::iterator rit = cursorRow();
- if (cursorRow() == rows().begin()) {
+ if (rit == firstRow()) {
if (y > 0)
bv()->updateScrollbar();
return;
}
- RowList::iterator cursorrow = cursorRow();
-
setCursorFromCoordinates(cursor.x_fix(), y);
finishUndo();
int new_y;
- if (cursorrow == bv()->text->cursorRow()) {
+ if (rit == 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);
// tall rows, but it's not working right now.
} else {
if (inset_owner) {
- new_y = bv()->text->cursor.iy()
+ new_y = bv()->text->cursor.y()
+ bv()->theLockingInset()->insetInInsetY() + y
- + cursorRow()->height()
+ + rit->height()
- bv()->workHeight() + 1;
} else {
new_y = cursor.y()
- - cursorRow()->baseline()
- + cursorRow()->height()
+ - rit->baseline()
+ + rit->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);
- }
- }
+
+ LyXCursor cur;
+ ParagraphList::iterator pit = cursor.par();
+ previousRow(pit, rit);
+ setCursor(cur, pit, rit->pos(), false);
+ if (cur.y() > bv_owner->top_y())
+ cursorUp(true);
bv()->updateScrollbar();
}
void LyXText::cursorNext()
{
- int topy = top_y();
+ int topy = bv_owner->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());
- bv()->updateScrollbar();
- }
+ RowList::iterator rit = cursorRow();
+ if (rit == lastRow()) {
+ int y = cursor.y() - rit->baseline() + cursorRow()->height();
+ if (y > topy + bv()->workHeight())
+ bv_owner->updateScrollbar();
return;
}
- int y = topy + bv()->workHeight();
+ int y = topy + bv_owner->workHeight();
if (inset_owner && !topy) {
- y -= (bv()->text->cursor.iy()
- - bv()->text->top_y()
- + bv()->theLockingInset()->insetInInsetY());
+ y -= (bv_owner->text->cursor.y()
+ - bv_owner->top_y()
+ + bv_owner->theLockingInset()->insetInInsetY());
}
- getRowNearY(y);
+ ParagraphList::iterator dummypit;
+ y = getRowNearY(y, dummypit)->y();
- RowList::iterator cursorrow = cursorRow();
setCursorFromCoordinates(cursor.x_fix(), y);
// + bv->workHeight());
finishUndo();
int new_y;
- if (cursorrow == bv()->text->cursorRow()) {
+ if (rit == bv_owner->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()
+ new_y = bv()->text->cursor.y()
+ bv()->theLockingInset()->insetInInsetY()
- + y - cursorRow()->baseline();
+ + y - rit->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);
+ new_y = cursor.y() - cursorRow()->baseline();
}
}
+
+ ParagraphList::iterator pit = cursor.par();
+ nextRow(pit, rit);
+ LyXCursor cur;
+ setCursor(cur, pit, rit->pos(), false);
+ if (cur.y() < bv_owner->top_y() + bv()->workHeight())
+ cursorDown(true);
bv()->updateScrollbar();
}
-void LyXText::update()
-{
- bv()->update(this, BufferView::SELECT);
-}
-
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))
if (tmp->params().startOfAppendix()) {
recordUndo(bv, Undo::ATOMIC, tmp);
tmp->params().startOfAppendix(false);
- int tmpy;
- setHeightOfRow(getRow(tmp, 0, tmpy));
+ redoParagraph(tmp);
break;
}
}
// we can set the refreshing parameters now
updateCounters();
- redoHeightOfParagraph();
+ redoParagraph(cursor.par());
setCursor(cursor.par(), cursor.pos());
- update();
+ 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))
cursorLeftOneWord();
else
case LFUN_WORDLEFT:
if (!selection.mark())
bv->beforeChange(this);
- update();
if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
cursorRightOneWord();
else
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 (!selection.set())
+ selection.cursor = cursor;
if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
cursorLeft(bv);
else
break;
case LFUN_LEFTSEL:
- update();
+ if (!selection.set())
+ selection.cursor = cursor;
if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
cursorRight(bv);
else
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))
cursorLeftOneWord();
else
break;
case LFUN_WORDLEFTSEL:
- update();
if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
cursorRightOneWord();
else
break;
case LFUN_WORDSEL: {
- update();
LyXCursor cur1 = cursor;
LyXCursor cur2;
::getWord(cur1, cur2, lyx::WHOLE_WORD, ownerParagraphs());
bool is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params);
if (!selection.mark())
bv->beforeChange(this);
- update();
if (is_rtl)
cursorLeft(false);
if (cursor.pos() < cursor.par()->size()
bool const is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params);
if (!selection.mark())
bv->beforeChange(this);
- update();
LyXCursor const cur = cursor;
if (!is_rtl)
cursorLeft(false);
case LFUN_UP:
if (!selection.mark())
bv->beforeChange(this);
- bv->update(this, BufferView::UPDATE);
cursorUp(false);
finishChange(bv);
break;
case LFUN_DOWN:
if (!selection.mark())
bv->beforeChange(this);
- bv->update(this, BufferView::UPDATE);
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);
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;
replaceSelection(bv->getLyXText());
insertInset(new InsetNewline);
- update();
setCursor(cursor.par(), 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:
cur.par()->params().align(),
cur.par()->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:
if (!selection.set()) {
LyXCursor cur = cursor;
if (cur.pos() == 0
- && !(cur.par()->params().spaceTop()
- == VSpace (VSpace::NONE))) {
+ && !(cur.par()->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(),
+ VSpace(VSpace::NONE),
+ cur.par()->params().spaceBottom(),
cur.par()->params().spacing(),
cur.par()->params().align(),
cur.par()->params().labelWidthString(), 0);
selection.cursor = cur;
}
} else {
- update();
cutSelection(true, false);
}
- update();
+ bv->update();
break;
case LFUN_BREAKPARAGRAPH:
replaceSelection(bv->getLyXText());
breakParagraph(bv->buffer()->paragraphs, 0);
- update();
+ bv->update();
selection.cursor = cursor;
bv->switchKeyMap();
bv->owner()->view_state_changed();
case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
replaceSelection(bv->getLyXText());
breakParagraph(bv->buffer()->paragraphs, 1);
- update();
+ bv->update();
selection.cursor = cursor;
bv->switchKeyMap();
bv->owner()->view_state_changed();
else {
breakParagraph(bv->buffer()->paragraphs, 0);
}
- update();
+ bv->update();
selection.cursor = cur;
bv->switchKeyMap();
bv->owner()->view_state_changed();
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_TOGGLE:
bv->beforeChange(this);
- update();
toggleInset();
- update();
+ bv->update();
bv->switchKeyMap();
break;
case LFUN_SPACE_INSERT:
- if (cursor.par()->layout()->free_spacing) {
+ if (cursor.par()->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();
recordUndo(bv, Undo::ATOMIC, cursor.par());
- if (transposeChars(cursor))
- checkParagraph(cursor.par(), cursor.pos());
- if (inset_owner)
- bv->updateInset(inset_owner);
- update();
+ redoParagraph();
+ bv->update();
break;
case LFUN_PASTE: {
}
pasteSelection(sel_index);
clearSelection(); // bug 393
- update();
+ bv->update();
bv->switchKeyMap();
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();
cursorTop();
finishChange(bv, true);
break;
case LFUN_ENDBUFSEL:
if (inset_owner)
return UNDISPATCHED;
- update();
cursorBottom();
finishChange(bv, true);
break;
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;
}
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;
LyXFont font = bv->text->getFont(cursor.par(), 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();
+ cmd1.y = cmd.y - cursor.y() + bv->top_y();
tli->localDispatch(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->repaint();
- bv->fitCursor();
+ bv->update();
break;
}
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
selection_possible = true;
// Clear the selection
- bv->screen().toggleSelection(bv->text, bv);
bv->text->clearSelection();
- bv->text->partialRebreak();
bv->update();
bv->updateScrollbar();
// 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() == InsetOld::REF_CODE)
recordUndo(bv, Undo::ATOMIC);
// 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_BRANCH:
case LFUN_INSERT_BIBITEM:
case LFUN_INSET_ERT:
case LFUN_INSET_FLOAT: