#include "support/tostr.h"
#include "support/std_sstream.h"
-#include "mathed/formulabase.h"
+#include "mathed/math_hullinset.h"
#include <clocale>
extern string current_layout;
-extern int bibitemMaxWidth(BufferView *, LyXFont const &);
// the selection possible is needed, that only motion events are
-// used, where the bottom press event was on the drawing area too
+// used, where the button press event was on the drawing area too
bool selection_possible = false;
if (font.language() != ignore_language ||
font.number() != LyXFont::IGNORE) {
- LyXCursor & cursor = text->cursor;
+ CursorSlice & cur = text->cursor();
Paragraph & par = *text->cursorPar();
text->bidi.computeTables(par, *bv->buffer(),
- *par.getRow(cursor.pos()));
- if (cursor.boundary() !=
+ *par.getRow(cur.pos()));
+ if (cur.boundary() !=
text->bidi.isBoundary(*bv->buffer(), par,
- cursor.pos(),
+ cur.pos(),
text->real_current_font))
- text->setCursor(cursor.par(), cursor.pos(),
- false, !cursor.boundary());
+ text->setCursor(cur.par(), cur.pos(),
+ false, !cur.boundary());
}
}
}
- void moveCursorUpdate(BufferView * bv, bool selecting)
+ void moveCursor(LCursor & cur, bool selecting)
{
- LyXText * lt = bv->getLyXText();
-
-// if (!lt->selection.set())
-// lt->selection.cursor = lt->cursor;
-
- if (selecting || lt->selection.mark())
- lt->setSelection();
-
- if (!lt->selection.set())
- bv->haveSelection(false);
-
- bv->update();
- bv->switchKeyMap();
+ if (selecting || cur.mark())
+ cur.setSelection();
+ if (!cur.selection())
+ cur.bv().haveSelection(false);
+ cur.bv().switchKeyMap();
}
void finishChange(BufferView * bv, bool selecting = false)
{
finishUndo();
- moveCursorUpdate(bv, selecting);
+ moveCursor(bv->cursor(), selecting);
bv->owner()->view_state_changed();
}
}
-
-InsetOld * LyXText::checkInsetHit(int x, int y)
+InsetBase * LyXText::checkInsetHit(int x, int y)
{
ParagraphList::iterator pit;
ParagraphList::iterator end;
- getParsInRange(ownerParagraphs(),
- bv()->top_y(), bv()->top_y() + bv()->workHeight(),
+ getParsInRange(paragraphs(),
+ bv()->top_y(),
+ bv()->top_y() + bv()->workHeight(),
pit, end);
-
+
lyxerr << "checkInsetHit: x: " << x << " y: " << y << endl;
for ( ; pit != end; ++pit) {
InsetList::iterator iit = pit->insetlist.begin();
InsetList::iterator iend = pit->insetlist.end();
for ( ; iit != iend; ++iit) {
- InsetOld * inset = iit->inset;
- //lyxerr << "examining inset " << inset
- // << " xy: " << inset->x() << "/" << inset->y()
- // << " x: " << inset->x() << "..." << inset->x() + inset->width()
- // << " y: " << inset->y() - inset->ascent() << "..."
- // << inset->y() + inset->descent()
- // << endl;
- if (x >= inset->x()
- && x <= inset->x() + inset->width()
- && y >= inset->y() - inset->ascent()
- && y <= inset->y() + inset->descent())
- {
+ InsetBase * inset = iit->inset;
+#if 1
+ lyxerr << "examining inset " << inset
+ //<< " xo/yo: " << inset->xo() << "/" << inset->yo()
+ << " xo: " << inset->xo() << "..." << inset->xo() + inset->width()
+ << " yo: " << inset->yo() - inset->ascent() << "..."
+ << inset->yo() + inset->descent() << endl;
+#endif
+ if (inset->covers(x, y - bv()->top_y())) {
lyxerr << "Hit inset: " << inset << endl;
return inset;
}
}
-bool LyXText::gotoNextInset(vector<InsetOld::Code> const & codes,
+bool LyXText::gotoNextInset(vector<InsetOld_code> const & codes,
string const & contents)
{
- ParagraphList::iterator end = ownerParagraphs().end();
+ ParagraphList::iterator end = paragraphs().end();
ParagraphList::iterator pit = cursorPar();
- pos_type pos = cursor.pos();
+ pos_type pos = cursor().pos();
- InsetOld * inset;
+ InsetBase * inset;
do {
if (pos + 1 < pit->size()) {
++pos;
}
-void LyXText::gotoInset(vector<InsetOld::Code> const & codes,
- bool same_content)
+void LyXText::gotoInset(vector<InsetOld_code> const & codes, bool same_content)
{
- clearSelection();
+ LCursor & cur = bv()->cursor();
+ cur.clearSelection();
string contents;
- if (same_content && cursor.pos() < cursorPar()->size()
- && cursorPar()->isInset(cursor.pos())) {
- InsetOld const * inset = cursorPar()->getInset(cursor.pos());
+ if (same_content
+ && cur.pos() < cur.lastpos()
+ && cur.paragraph().isInset(cur.pos())) {
+ InsetBase const * inset = cur.paragraph().getInset(cur.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() || cursorPar() != ownerParagraphs().begin()) {
- LyXCursor tmp = cursor;
- cursor.par(0);
- cursor.pos(0);
+ if (cur.pos() || cur.par() != 0) {
+ CursorSlice tmp = cursor();
+ cur.par() = 0;
+ cur.pos() = 0;
if (!gotoNextInset(codes, contents)) {
- cursor = tmp;
- bv()->owner()->message(_("No more insets"));
+ cursor() = tmp;
+ cur.bv().owner()->message(_("No more insets"));
}
} else {
- bv()->owner()->message(_("No more insets"));
+ cur.bv().owner()->message(_("No more insets"));
}
}
- bv()->update();
- selection.cursor = cursor;
+ cur.bv().update();
+ cur.resetAnchor();
}
-void LyXText::gotoInset(InsetOld::Code code, bool same_content)
+void LyXText::gotoInset(InsetOld_code code, bool same_content)
{
- gotoInset(vector<InsetOld::Code>(1, code), same_content);
+ gotoInset(vector<InsetOld_code>(1, code), same_content);
}
void LyXText::cursorPrevious()
{
- int y = bv()->top_y();
-
- ParagraphList::iterator cpit = cursorPar();
- RowList::iterator crit = cpit->getRow(cursor.pos());
-
- if (isFirstRow(cpit, *crit)) {
- if (y > 0)
- bv()->updateScrollbar();
- return;
- }
+ LCursor & cur = bv()->cursor();
+ pos_type cpos = cur.pos();
+ lyx::paroffset_type cpar = cur.par();
- setCursorFromCoordinates(bv()->x_target(), y);
- finishUndo();
+ int x = bv()->cursor().x_target();
+ int y = bv()->top_y();
+ setCursorFromCoordinates(x, y);
- if (crit == bv()->text->cursorRow()) {
+ if (cpar == cur.par() && cpos == cur.pos()) {
// we have a row which is taller than the workarea. The
// simplest solution is to move to the previous row instead.
cursorUp(true);
- return;
- }
-
- int new_y = + crit->height() - bv()->workHeight() + 1;
-
- if (inset_owner) {
- new_y += bv()->text->cursor.y()
- + bv()->cursor().innerInset()->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();
+ finishUndo();
}
void LyXText::cursorNext()
{
- int topy = bv()->top_y();
-
- 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.y()
- + bv()->top_y()
- - bv()->cursor().innerInset()->insetInInsetY();
- }
+ LCursor & cur = bv()->cursor();
+ pos_type cpos = cur.pos();
+ lyx::paroffset_type cpar = cur.par();
- ParagraphList::iterator dummypit;
- Row const & row = *getRowNearY(y, dummypit);
- y = dummypit->y + row.y_offset();
+ int x = cur.x_target();
+ int y = bv()->top_y() + bv()->workHeight();
+ setCursorFromCoordinates(x, y);
- setCursorFromCoordinates(bv()->x_target(), y);
- // + bv->workHeight());
- finishUndo();
-
- int new_y;
- if (crit == bv()->text->cursorRow()) {
+ if (cpar == cur.par() && cpos == cur.pos()) {
// we have a row which is taller than the workarea. The
// simplest solution is to move to the next row instead.
cursorDown(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->top_y() + bv->workHeight();
-#endif
- }
-
- if (inset_owner) {
- new_y = bv()->text->cursor.y()
- + bv()->cursor().innerInset()->insetInInsetY()
- + y - crit->baseline();
- } else {
- new_y = cursor.y() - crit->baseline();
}
-
- nextRow(cpit, crit);
- LyXCursor cur;
- setCursor(cur, parOffset(cpit), crit->pos(), false);
- if (cur.y() < bv()->top_y() + bv()->workHeight())
- cursorDown(true);
bv()->updateScrollbar();
+ finishUndo();
}
namespace {
-void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind)
+void specialChar(LyXText * text, BufferView * bv, InsetSpecialChar::Kind kind)
{
bv->update();
InsetSpecialChar * new_inset = new InsetSpecialChar(kind);
- replaceSelection(lt);
+ replaceSelection(text);
if (!bv->insertInset(new_inset))
delete new_inset;
else
}
-void doInsertInset(LyXText * lt, FuncRequest const & cmd,
- bool edit, bool pastesel)
+void doInsertInset(BufferView * bv, FuncRequest const & cmd,
+ bool edit, bool pastesel)
{
- InsetOld * inset = createInset(cmd);
- BufferView * bv = cmd.view();
-
- if (inset) {
- bool gotsel = false;
- if (lt->selection.set()) {
- bv->owner()->dispatch(FuncRequest(LFUN_CUT));
- gotsel = true;
- }
- if (bv->insertInset(inset)) {
- if (edit)
- inset->edit(bv, true);
- if (gotsel && pastesel)
- bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
- }
- else
- delete inset;
+ InsetBase * inset = createInset(bv, cmd);
+ if (!inset)
+ return;
+
+ bool gotsel = false;
+ if (bv->cursor().selection()) {
+ bv->owner()->dispatch(FuncRequest(LFUN_CUT));
+ gotsel = true;
+ }
+ if (bv->insertInset(inset)) {
+ if (edit)
+ inset->edit(bv->cursor(), true);
+ if (gotsel && pastesel)
+ bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
+ } else {
+ delete inset;
}
}
}
-DispatchResult LyXText::dispatch(FuncRequest const & cmd)
+DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
{
- //lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
- lyxerr << "LyXText::dispatch: cmd: " << cmd << endl;
+ lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
+ //lyxerr << "*** LyXText::dispatch: cmd: " << cmd << endl;
- BufferView * bv = cmd.view();
+ BufferView * bv = &cur.bv();
switch (cmd.action) {
bool start = !pit->params().startOfAppendix();
// ensure that we have only one start_of_appendix in this document
- ParagraphList::iterator tmp = ownerParagraphs().begin();
- ParagraphList::iterator end = ownerParagraphs().end();
+ ParagraphList::iterator tmp = paragraphs().begin();
+ ParagraphList::iterator end = paragraphs().end();
for (; tmp != end; ++tmp) {
if (tmp->params().startOfAppendix()) {
// we can set the refreshing parameters now
updateCounters();
redoParagraph(cursorPar());
- setCursor(cursorPar(), cursor.pos());
bv->update();
break;
}
case LFUN_DELETE_WORD_FORWARD:
- clearSelection();
+ cur.clearSelection();
deleteWordForward();
finishChange(bv);
break;
case LFUN_DELETE_WORD_BACKWARD:
- clearSelection();
+ cur.clearSelection();
deleteWordBackward();
finishChange(bv);
break;
case LFUN_DELETE_LINE_FORWARD:
- clearSelection();
+ cur.clearSelection();
deleteLineForward();
finishChange(bv);
break;
case LFUN_WORDRIGHT:
- if (!selection.mark())
- clearSelection();
+ if (!cur.mark())
+ cur.clearSelection();
if (rtl())
cursorLeftOneWord();
else
break;
case LFUN_WORDLEFT:
- if (!selection.mark())
- clearSelection();
+ if (!cur.mark())
+ cur.clearSelection();
if (rtl())
cursorRightOneWord();
else
break;
case LFUN_BEGINNINGBUF:
- if (!selection.mark())
- clearSelection();
+ if (!cur.mark())
+ cur.clearSelection();
cursorTop();
finishChange(bv);
break;
case LFUN_ENDBUF:
- if (selection.mark())
- clearSelection();
+ if (!cur.mark())
+ cur.clearSelection();
cursorBottom();
finishChange(bv);
break;
case LFUN_RIGHTSEL:
- if (!selection.set())
- selection.cursor = cursor;
+ if (!cur.selection())
+ cur.resetAnchor();
if (rtl())
- cursorLeft(bv);
+ cursorLeft(true);
else
- cursorRight(bv);
+ cursorRight(true);
finishChange(bv, true);
break;
case LFUN_LEFTSEL:
- if (!selection.set())
- selection.cursor = cursor;
+ if (!cur.selection())
+ cur.resetAnchor();
if (rtl())
- cursorRight(bv);
+ cursorRight(true);
else
- cursorLeft(bv);
+ cursorLeft(true);
finishChange(bv, true);
break;
case LFUN_UPSEL:
- if (!selection.set())
- selection.cursor = cursor;
+ if (!cur.selection())
+ cur.resetAnchor();
cursorUp(true);
finishChange(bv, true);
break;
case LFUN_DOWNSEL:
- if (!selection.set())
- selection.cursor = cursor;
+ if (!cur.selection())
+ cur.resetAnchor();
cursorDown(true);
finishChange(bv, true);
break;
case LFUN_UP_PARAGRAPHSEL:
- if (!selection.set())
- selection.cursor = cursor;
+ if (!cur.selection())
+ cur.resetAnchor();
cursorUpParagraph();
finishChange(bv, true);
break;
case LFUN_DOWN_PARAGRAPHSEL:
- if (!selection.set())
- selection.cursor = cursor;
+ if (!cur.selection())
+ cur.resetAnchor();
cursorDownParagraph();
finishChange(bv, true);
break;
case LFUN_PRIORSEL:
- if (!selection.set())
- selection.cursor = cursor;
+ if (!cur.selection())
+ cur.resetAnchor();
cursorPrevious();
finishChange(bv, true);
break;
case LFUN_NEXTSEL:
- if (!selection.set())
- selection.cursor = cursor;
+ if (!cur.selection())
+ cur.resetAnchor();
cursorNext();
finishChange(bv, true);
break;
case LFUN_HOMESEL:
- if (!selection.set())
- selection.cursor = cursor;
+ if (!cur.selection())
+ cur.resetAnchor();
cursorHome();
finishChange(bv, true);
break;
case LFUN_ENDSEL:
- if (!selection.set())
- selection.cursor = cursor;
+ if (!cur.selection())
+ cur.resetAnchor();
cursorEnd();
finishChange(bv, true);
break;
case LFUN_WORDRIGHTSEL:
+ if (!cur.selection())
+ cur.resetAnchor();
if (rtl())
cursorLeftOneWord();
else
break;
case LFUN_WORDLEFTSEL:
+ if (!cur.selection())
+ cur.resetAnchor();
if (rtl())
cursorRightOneWord();
else
break;
case LFUN_WORDSEL: {
- LyXCursor cur1 = cursor;
- LyXCursor cur2;
- getWord(cur1, cur2, lyx::WHOLE_WORD);
- setCursor(cur1.par(), cur1.pos());
- clearSelection();
- setCursor(cur2.par(), cur2.pos());
+ selectWord(lyx::WHOLE_WORD);
finishChange(bv, true);
break;
}
- case LFUN_RIGHT: {
- bool is_rtl = rtl();
- if (!selection.mark())
- clearSelection();
- if (is_rtl)
- cursorLeft(false);
- if (cursor.pos() < cursorPar()->size()
- && cursorPar()->isInset(cursor.pos())
- && isHighlyEditableInset(cursorPar()->getInset(cursor.pos()))) {
- InsetOld * tmpinset = cursorPar()->getInset(cursor.pos());
- cmd.message(tmpinset->editMessage());
- tmpinset->edit(bv, !is_rtl);
- break;
- }
- if (!is_rtl)
- cursorRight(false);
+ case LFUN_RIGHT:
finishChange(bv);
- break;
- }
+ return moveRight();
- case LFUN_LEFT: {
- // This is soooo ugly. Isn't it possible to make
- // it simpler? (Lgb)
- bool const is_rtl = rtl();
- if (!selection.mark())
- clearSelection();
- LyXCursor const cur = cursor;
- if (!is_rtl)
- cursorLeft(false);
- if ((is_rtl || cur != cursor) && // only if really moved!
- cursor.pos() < cursorPar()->size() &&
- cursorPar()->isInset(cursor.pos()) &&
- isHighlyEditableInset(cursorPar()->getInset(cursor.pos()))) {
- InsetOld * tmpinset = cursorPar()->getInset(cursor.pos());
- cmd.message(tmpinset->editMessage());
- tmpinset->edit(bv, is_rtl);
- break;
- }
- if (is_rtl)
- cursorRight(false);
+ case LFUN_LEFT:
finishChange(bv);
- break;
- }
+ return moveLeft();
case LFUN_UP:
- if (!selection.mark())
- clearSelection();
- cursorUp(false);
finishChange(bv);
- break;
+ return moveUp();
case LFUN_DOWN:
- if (!selection.mark())
- clearSelection();
- cursorDown(false);
finishChange(bv);
- break;
+ return moveDown();
case LFUN_UP_PARAGRAPH:
- if (!selection.mark())
- clearSelection();
+ if (!cur.mark())
+ cur.clearSelection();
cursorUpParagraph();
finishChange(bv);
break;
case LFUN_DOWN_PARAGRAPH:
- if (!selection.mark())
- clearSelection();
+ if (!cur.mark())
+ cur.clearSelection();
cursorDownParagraph();
finishChange(bv, false);
break;
case LFUN_PRIOR:
- if (!selection.mark())
- clearSelection();
- cursorPrevious();
+ if (!cur.mark())
+ cur.clearSelection();
finishChange(bv, false);
+ if (cur.par() == 0 && cursorRow() == firstRow())
+ return DispatchResult(false, FINISHED_UP);
+ cursorPrevious();
break;
case LFUN_NEXT:
- if (!selection.mark())
- clearSelection();
- cursorNext();
+ if (!cur.mark())
+ cur.clearSelection();
finishChange(bv, false);
+ if (cur.par() == cur.lastpar() && cursorRow() == lastRow())
+ return DispatchResult(false, FINISHED_DOWN);
+ cursorNext();
break;
case LFUN_HOME:
- if (!selection.mark())
- clearSelection();
+ if (!cur.mark())
+ cur.clearSelection();
cursorHome();
finishChange(bv, false);
break;
case LFUN_END:
- if (!selection.mark())
- clearSelection();
+ if (!cur.mark())
+ cur.clearSelection();
cursorEnd();
finishChange(bv, false);
break;
case LFUN_BREAKLINE: {
- lyx::pos_type body = cursorPar()->beginningOfBody();
+ lyx::pos_type body = cursorPar()->beginOfBody();
// Not allowed by LaTeX (labels or empty par)
- if (cursor.pos() <= body)
+ if (cursor().pos() <= body)
break;
replaceSelection(bv->getLyXText());
insertInset(new InsetNewline);
- setCursor(cursorPar(), cursor.pos());
- moveCursorUpdate(bv, false);
+ moveCursor(cur, false);
break;
}
case LFUN_DELETE:
- if (!selection.set()) {
+ if (!cur.selection()) {
Delete();
- selection.cursor = cursor;
+ cur.resetAnchor();
// It is possible to make it a lot faster still
// just comment out the line below...
} else {
cutSelection(true, false);
}
- moveCursorUpdate(bv, false);
+ moveCursor(cur, false);
bv->owner()->view_state_changed();
break;
case LFUN_DELETE_SKIP:
// Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
- if (!selection.set()) {
- if (cursor.pos() == cursorPar()->size()) {
+ if (!cur.selection()) {
+ if (cursor().pos() == cursorPar()->size()) {
cursorRight(bv);
- ParagraphParameters & params = cursorPar()->params();
- if (cursor.pos() == 0
- && !(params.spaceTop() == VSpace (VSpace::NONE))) {
- setParagraph(
- VSpace(VSpace::NONE),
- params.spaceBottom(),
- params.spacing(),
- params.align(),
- params.labelWidthString(), 0);
- cursorLeft(bv);
- } else {
- cursorLeft(bv);
- Delete();
- selection.cursor = cursor;
- }
+ cursorLeft(bv);
+ Delete();
+ cur.resetAnchor();
} else {
Delete();
- selection.cursor = cursor;
+ cur.resetAnchor();
}
} else {
cutSelection(true, false);
case LFUN_BACKSPACE:
- if (!selection.set()) {
+ if (!cur.selection()) {
if (bv->owner()->getIntl().getTransManager().backspace()) {
backspace();
- selection.cursor = cursor;
+ cur.resetAnchor();
// It is possible to make it a lot faster still
// just comment out the line below...
}
case LFUN_BACKSPACE_SKIP:
// Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
- if (!selection.set()) {
- ParagraphParameters & params = cursorPar()->params();
- if (cursor.pos() == 0 && !(params.spaceTop() == VSpace(VSpace::NONE))) {
- setParagraph(
- VSpace(VSpace::NONE),
- params.spaceBottom(),
- params.spacing(),
- params.align(),
- params.labelWidthString(), 0);
- } else {
- LyXCursor cur = cursor;
- backspace();
- selection.cursor = cur;
- }
+ if (!cur.selection()) {
+#warning look here
+ //CursorSlice cur = cursor();
+ backspace();
+ //anchor() = cur;
} else {
cutSelection(true, false);
}
replaceSelection(bv->getLyXText());
breakParagraph(bv->buffer()->paragraphs(), 0);
bv->update();
- selection.cursor = cursor;
+ cur.resetAnchor();
bv->switchKeyMap();
bv->owner()->view_state_changed();
break;
replaceSelection(bv->getLyXText());
breakParagraph(bv->buffer()->paragraphs(), 1);
bv->update();
- selection.cursor = cursor;
+ cur.resetAnchor();
bv->switchKeyMap();
bv->owner()->view_state_changed();
break;
// When at the beginning of a paragraph, remove
// indentation and add a "defskip" at the top.
// Otherwise, do the same as LFUN_BREAKPARAGRAPH.
- LyXCursor cur = cursor;
+#warning look here
+// CursorSlice cur = cursor();
replaceSelection(bv->getLyXText());
if (cur.pos() == 0) {
- ParagraphParameters & params = getPar(cur)->params();
- if (params.spaceTop() == VSpace(VSpace::NONE)) {
- setParagraph(
- VSpace(VSpace::DEFSKIP), params.spaceBottom(),
- params.spacing(),
- params.align(),
- params.labelWidthString(), 1);
- }
- }
- else {
+ ParagraphParameters & params = getPar(cur.current())->params();
+ setParagraph(
+ params.spacing(),
+ params.align(),
+ params.labelWidthString(), 1);
+ } else {
breakParagraph(bv->buffer()->paragraphs(), 0);
}
bv->update();
- selection.cursor = cur;
+// anchor() = cur;
bv->switchKeyMap();
bv->owner()->view_state_changed();
break;
break;
}
+ case LFUN_INSET_APPLY: {
+ string const name = cmd.getArg(0);
+ InsetBase * inset = bv->owner()->getDialogs().getOpenInset(name);
+ if (inset)
+ inset->dispatch(cur, FuncRequest(LFUN_INSET_MODIFY, cmd.argument));
+ else
+ dispatch(cur, FuncRequest(LFUN_INSET_INSERT, cmd.argument));
+ break;
+ }
+
+ case LFUN_INSET_INSERT: {
+ InsetBase * inset = createInset(bv, cmd);
+ if (inset && !bv->insertInset(inset))
+ delete inset;
+ break;
+ }
+
case LFUN_INSET_SETTINGS:
- bv->cursor().innerInset()->showInsetDialog(bv);
+ if (cur.inset() && cur.inset()->asUpdatableInset())
+ cur.inset()->asUpdatableInset()->showInsetDialog(bv);
break;
case LFUN_INSET_TOGGLE:
- clearSelection();
- toggleInset();
+ cur.clearSelection();
+ if (!toggleInset())
+ return DispatchResult(false);
bv->update();
bv->switchKeyMap();
break;
if (cursorPar()->layout()->free_spacing)
insertChar(' ');
else
- doInsertInset(this, cmd, false, false);
- moveCursorUpdate(bv, false);
+ doInsertInset(bv, cmd, false, false);
+ moveCursor(cur, false);
break;
case LFUN_HYPHENATION:
specialChar(this, bv, InsetSpecialChar::MENU_SEPARATOR);
break;
- case LFUN_MARK_OFF:
- clearSelection();
- bv->update();
- selection.cursor = cursor;
- cmd.message(N_("Mark off"));
- break;
-
- case LFUN_MARK_ON:
- clearSelection();
- selection.mark(true);
- bv->update();
- selection.cursor = cursor;
- cmd.message(N_("Mark on"));
- break;
-
- case LFUN_SETMARK:
- clearSelection();
- if (selection.mark()) {
- cmd.message(N_("Mark removed"));
- } else {
- selection.mark(true);
- cmd.message(N_("Mark set"));
- }
- selection.cursor = cursor;
- bv->update();
- break;
-
case LFUN_UPCASE_WORD:
changeCase(LyXText::text_uppercase);
bv->update();
break;
case LFUN_TRANSPOSE_CHARS:
- recUndo(cursor.par());
+ recUndo(cursor().par());
redoParagraph();
bv->update();
break;
case LFUN_PASTE:
- cmd.message(_("Paste"));
+ cur.message(_("Paste"));
replaceSelection(bv->getLyXText());
#warning FIXME Check if the arg is in the domain of available selections.
if (isStrUnsignedInt(cmd.argument))
pasteSelection(strToUnsignedInt(cmd.argument));
else
pasteSelection(0);
- clearSelection(); // bug 393
+ cur.clearSelection(); // bug 393
bv->update();
bv->switchKeyMap();
finishUndo();
case LFUN_CUT:
cutSelection(true, true);
- cmd.message(_("Cut"));
+ cur.message(_("Cut"));
bv->update();
break;
case LFUN_COPY:
copySelection();
- cmd.message(_("Copy"));
+ cur.message(_("Copy"));
break;
case LFUN_BEGINNINGBUFSEL:
- if (inset_owner)
+ if (in_inset_)
return DispatchResult(false);
+ if (!cur.selection())
+ cur.resetAnchor();
cursorTop();
finishChange(bv, true);
break;
case LFUN_ENDBUFSEL:
- if (inset_owner)
+ if (in_inset_)
return DispatchResult(false);
+ if (!cur.selection())
+ cur.resetAnchor();
cursorBottom();
finishChange(bv, true);
break;
case LFUN_GETXY:
- cmd.message(tostr(cursor.x()) + ' ' + tostr(cursor.y()));
+ cur.message(tostr(cursorX(cur.current())) + ' '
+ + tostr(cursorY(cur.current())));
break;
case LFUN_SETXY: {
case LFUN_GETFONT:
if (current_font.shape() == LyXFont::ITALIC_SHAPE)
- cmd.message("E");
+ cur.message("E");
else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
- cmd.message("N");
+ cur.message("N");
else
- cmd.message("0");
+ cur.message("0");
break;
case LFUN_GETLAYOUT:
- cmd.message(tostr(cursorPar()->layout()));
+ cur.message(cursorPar()->layout()->name());
break;
case LFUN_LAYOUT: {
// function list/array with information about what
// functions needs arguments and their type.
if (cmd.argument.empty()) {
- cmd.errorMessage(_("LyX function 'layout' needs an argument."));
+ cur.errorMessage(_("LyX function 'layout' needs an argument."));
break;
}
}
if (!hasLayout) {
- cmd.errorMessage(string(N_("Layout ")) + cmd.argument +
+ cur.errorMessage(string(N_("Layout ")) + cmd.argument +
N_(" not known"));
break;
}
bool change_layout = (current_layout != layout);
- if (!change_layout && selection.set() &&
- selection.start.par() != selection.end.par())
+ if (!change_layout && cur.selection() &&
+ cur.selBegin().par() != cur.selEnd().par())
{
- ParagraphList::iterator spit = getPar(selection.start);
- ParagraphList::iterator epit = boost::next(getPar(selection.end));
+ ParagraphList::iterator spit = getPar(cur.selBegin());
+ ParagraphList::iterator epit = boost::next(getPar(cur.selEnd()));
while (spit != epit) {
if (spit->layout()->name() != current_layout) {
change_layout = true;
}
case LFUN_PASTESELECTION: {
- // this was originally a bv->text->clearSelection(), i.e
- // the outermost LyXText!
- clearSelection();
+ cur.clearSelection();
string const clip = bv->getClipboard();
if (!clip.empty()) {
if (cmd.argument == "paragraph")
}
case LFUN_GOTOERROR:
- gotoInset(InsetOld::ERROR_CODE, false);
+ gotoInset(InsetBase::ERROR_CODE, false);
break;
case LFUN_GOTONOTE:
- gotoInset(InsetOld::NOTE_CODE, false);
+ gotoInset(InsetBase::NOTE_CODE, false);
break;
case LFUN_REFERENCE_GOTO: {
- vector<InsetOld::Code> tmp;
- tmp.push_back(InsetOld::LABEL_CODE);
- tmp.push_back(InsetOld::REF_CODE);
+ vector<InsetOld_code> tmp;
+ tmp.push_back(InsetBase::LABEL_CODE);
+ tmp.push_back(InsetBase::REF_CODE);
gotoInset(tmp, true);
break;
}
case LFUN_QUOTE: {
replaceSelection(bv->getLyXText());
ParagraphList::iterator pit = cursorPar();
- lyx::pos_type pos = cursor.pos();
+ lyx::pos_type pos = cursor().pos();
char c;
if (!pos)
c = ' ';
for (int i = 0; i < datetmp_len; i++)
insertChar(datetmp[i]);
- selection.cursor = cursor;
- moveCursorUpdate(bv, false);
+ cur.resetAnchor();
+ moveCursor(cur, false);
break;
}
case LFUN_MOUSE_TRIPLE:
- if (!bv->buffer())
- break;
- if (cmd.button() == mouse_button::button1) {
+ if (bv->buffer() && cmd.button() == mouse_button::button1) {
+ selection_possible = true;
cursorHome();
- selection.cursor = cursor;
+ cur.resetAnchor();
cursorEnd();
- setSelection();
- bv->update();
- bv->haveSelection(selection.set());
+ cur.setSelection();
+ bv->haveSelection(cur.selection());
}
break;
case LFUN_MOUSE_DOUBLE:
- if (!bv->buffer())
- break;
- if (cmd.button() == mouse_button::button1) {
+ if (bv->buffer() && cmd.button() == mouse_button::button1) {
+ selection_possible = true;
selectWord(lyx::WHOLE_WORD_STRICT);
- bv->update();
- bv->haveSelection(selection.set());
+ bv->haveSelection(cur.selection());
}
break;
case LFUN_MOUSE_MOTION: {
+#if 0
// Only use motion with button 1
//if (ev.button() != mouse_button::button1)
// return false;
+ // don't set anchor_
+ bv->cursor().cursor_ = cur.cursor_;
if (!bv->buffer())
break;
-
- // Check for inset locking
-#ifdef LOCK
- if (bv->innerInset()) {
- InsetOld * tli = bv->innerInset();
- LyXCursor cursor = bv->text->cursor;
- LyXFont font = bv->text->getFont(bv->text->cursorPar(), cursor.pos());
- int width = tli->width();
- int inset_x = font.isVisibleRightToLeft()
- ? 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.y() + bv->top_y();
- tli->dispatch(cmd1);
- break;
- }
-#endif
-
- // The test for not selection possible is needed, that only motion
- // events are used, where the bottom press event was on
- // the drawing area too
+ // The test for not selection possible is needed, that
+ // only motion events are used, where the bottom press
+ // event was on the drawing area too
if (!selection_possible) {
- lyxerr[Debug::ACTION]
- << "BufferView::Pimpl::Dispatch: no selection possible\n";
+ lyxerr[Debug::ACTION] << "BufferView::Pimpl::"
+ "Dispatch: no selection possible\n";
break;
}
+ RowList::iterator cursorrow = cursorRow();
+
+ setCursorFromCoordinates(cmd.x, cmd.y);
- RowList::iterator cursorrow = bv->text->cursorRow();
- 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
- // in some other local environment, but I would like to leave this here
- // for the moment until I can remove this (Jug 20020418)
- if (y_before < bv->text->cursor.y())
- lyxerr << y_before << ':'
- << bv->text->cursor.y() << endl;
- #endif
// This is to allow jumping over large insets
- if (cursorrow == bv->text->cursorRow()) {
- if (cmd.y >= bv->workHeight())
- bv->text->cursorDown(false);
- else if (cmd.y < 0)
- bv->text->cursorUp(false);
+ // FIXME: shouldn't be top-text-specific
+ if (cursorrow == cursorRow() && !in_inset_) {
+ if (cmd.y - bv->top_y() >= bv->workHeight())
+ cursorDown(true);
+ else if (cmd.y - bv->top_y() < 0)
+ cursorUp(true);
}
-
- bv->text->setSelection();
- bv->update();
+ cur.setSelection();
+#endif
break;
}
// it could get cleared on the unlocking of the inset so
// we have to check this first
bool paste_internally = false;
- if (cmd.button() == mouse_button::button2 && selection.set()) {
+ if (cmd.button() == mouse_button::button2 && cur.selection()) {
bv->owner()->dispatch(FuncRequest(LFUN_COPY));
paste_internally = true;
}
- int const screen_first = bv->top_y();
selection_possible = true;
// Clear the selection
- bv->text->clearSelection();
- bv->update();
- bv->updateScrollbar();
+ cur.clearSelection();
// Right click on a footnote flag opens float menu
if (cmd.button() == mouse_button::button3) {
break;
}
- bv->text->setCursorFromCoordinates(cmd.x, cmd.y + screen_first);
+ setCursorFromCoordinates(cur.current(), cmd.x, cmd.y);
+ cur.resetAnchor();
finishUndo();
- bv->text->selection.cursor = bv->text->cursor;
- bv->x_target(bv->text->cursor.x());
+ cur.x_target() = cursorX(cur.current());
+
+ // set cursor and anchor to this position
+ bv->cursor() = cur;
if (bv->fitCursor())
selection_possible = false;
}
case LFUN_MOUSE_RELEASE: {
- // do nothing if we used the mouse wheel
if (!bv->buffer())
break;
+ // do nothing if we used the mouse wheel
if (cmd.button() == mouse_button::button4
|| cmd.button() == mouse_button::button5)
- break;
+ return DispatchResult(true, false);
selection_possible = false;
// finish selection
if (cmd.button() == mouse_button::button1)
- bv->haveSelection(selection.set());
+ bv->haveSelection(cur.selection());
bv->switchKeyMap();
bv->owner()->view_state_changed();
// true (on).
if (lyxrc.auto_region_delete) {
- if (selection.set())
+ if (cur.selection())
cutSelection(false, false);
bv->haveSelection(false);
}
- clearSelection();
+ cur.clearSelection();
LyXFont const old_font = real_current_font;
string::const_iterator cit = cmd.argument.begin();
bv->owner()->getIntl().getTransManager().
TranslateAndInsert(*cit, this);
- selection.cursor = cursor;
- moveCursorUpdate(bv, false);
+ cur.resetAnchor();
+ moveCursor(cur, false);
// real_current_font.number can change so we need to
// update the minibuffer
}
case LFUN_URL: {
- doInsertInset(this, cmd, true, false);
InsetCommandParams p("url");
string const data = InsetCommandMailer::params2string("url", p);
bv->owner()->getDialogs().show("url", data, 0);
}
case LFUN_HTMLURL: {
- doInsertInset(this, cmd, true, false);
InsetCommandParams p("htmlurl");
string const data = InsetCommandMailer::params2string("url", p);
bv->owner()->getDialogs().show("url", data, 0);
break;
}
+ case LFUN_INSERT_LABEL: {
+ InsetCommandParams p("label");
+ string const data = InsetCommandMailer::params2string("label", p);
+ bv->owner()->getDialogs().show("label", data, 0);
+ break;
+ }
+
#if 0
case LFUN_INSET_LIST:
case LFUN_INSET_FLOAT:
case LFUN_INSET_FOOTNOTE:
case LFUN_INSET_MARGINAL:
- case LFUN_INSET_MINIPAGE:
case LFUN_INSET_OPTARG:
case LFUN_INSET_WIDE_FLOAT:
case LFUN_INSET_WRAP:
case LFUN_ENVIRONMENT_INSERT:
// Open the inset, and move the current selection
// inside it.
- doInsertInset(this, cmd, true, true);
+ doInsertInset(bv, cmd, true, true);
break;
case LFUN_INDEX_INSERT:
// Just open the inset
- doInsertInset(this, cmd, true, false);
+ doInsertInset(bv, cmd, true, false);
break;
case LFUN_INDEX_PRINT:
case LFUN_INSERT_LINE:
case LFUN_INSERT_PAGEBREAK:
// do nothing fancy
- doInsertInset(this, cmd, false, false);
+ doInsertInset(bv, cmd, false, false);
break;
case LFUN_DEPTH_MIN:
- clearSelection();
- bv_funcs::changeDepth(bv, this, bv_funcs::DEC_DEPTH, false);
+ bv_funcs::changeDepth(bv, this, bv_funcs::DEC_DEPTH);
bv->update();
break;
case LFUN_DEPTH_PLUS:
- clearSelection();
- bv_funcs::changeDepth(bv, this, bv_funcs::INC_DEPTH, false);
+ bv_funcs::changeDepth(bv, this, bv_funcs::INC_DEPTH);
bv->update();
break;
case LFUN_MATH_NUMBER:
case LFUN_MATH_EXTERN:
case LFUN_MATH_SIZE:
- mathDispatch(cmd);
+ mathDispatch(cur, cmd);
break;
case LFUN_EMPH:
case LFUN_FREEFONT_UPDATE:
update_and_apply_freefont(bv, this, cmd.argument);
break;
-
+
case LFUN_FINISHED_LEFT:
- lyxerr << "swallow LFUN_FINISHED_LEFT" << endl;
+ lyxerr << "handle LFUN_FINISHED_LEFT" << endl;
+ cur.pop(cur.currentDepth());
+ cur.bv().cursor() = cur;
if (rtl())
- cursorRight(bv);
+ cursorLeft(true);
break;
case LFUN_FINISHED_RIGHT:
- lyxerr << "swallow LFUN_FINISHED_RIGHT" << endl;
+ lyxerr << "handle LFUN_FINISHED_RIGHT" << endl;
+ cur.pop(cur.currentDepth());
+ cur.bv().cursor() = cur;
if (!rtl())
- cursorRight(bv);
+ cursorRight(true);
break;
case LFUN_FINISHED_UP:
- lyxerr << "swallow LFUN_FINISHED_UP" << endl;
+ lyxerr << "handle LFUN_FINISHED_UP" << endl;
+ cur.pop(cur.currentDepth());
+ cur.bv().cursor() = cur;
+ cursorUp(true);
break;
case LFUN_FINISHED_DOWN:
- lyxerr << "swallow LFUN_FINISHED_DOWN" << endl;
- cursorRight(bv);
+ lyxerr << "handle LFUN_FINISHED_DOWN" << endl;
+ cur.pop(cur.currentDepth());
+ cur.bv().cursor() = cur;
+ cursorDown(true);
break;
default: