From ea53de7c85a432377f87a4e0cc47a027d7793a74 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Fri, 16 Jan 2004 12:36:23 +0000 Subject: [PATCH] and some mathed de-uglyfication git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8359 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/bufferview_funcs.C | 2 +- src/cursor.C | 16 +- src/cursor.h | 46 +- src/cursor_slice.C | 4 +- src/insets/insettabular.C | 8 +- src/mathed/formulabase.C | 176 ++++---- src/mathed/formulabase.h | 11 +- src/mathed/math_cursor.C | 738 +++++++++++++++----------------- src/mathed/math_cursor.h | 172 ++++---- src/mathed/math_fracbase.C | 7 +- src/mathed/math_fracbase.h | 6 +- src/mathed/math_gridinset.C | 33 +- src/mathed/math_gridinset.h | 21 +- src/mathed/math_hullinset.C | 14 +- src/mathed/math_hullinset.h | 6 +- src/mathed/math_inset.C | 20 +- src/mathed/math_inset.h | 25 +- src/mathed/math_macro.C | 11 +- src/mathed/math_macro.h | 6 +- src/mathed/math_nestinset.C | 26 +- src/mathed/math_nestinset.h | 16 +- src/mathed/math_oversetinset.C | 6 +- src/mathed/math_oversetinset.h | 4 +- src/mathed/math_rootinset.C | 3 +- src/mathed/math_rootinset.h | 2 +- src/mathed/math_scriptinset.C | 13 +- src/mathed/math_scriptinset.h | 10 +- src/mathed/math_textinset.C | 2 +- src/mathed/math_textinset.h | 2 +- src/mathed/math_undersetinset.C | 9 +- src/mathed/math_undersetinset.h | 6 +- 31 files changed, 681 insertions(+), 740 deletions(-) diff --git a/src/bufferview_funcs.C b/src/bufferview_funcs.C index 58f782b942..fb14fbf9bb 100644 --- a/src/bufferview_funcs.C +++ b/src/bufferview_funcs.C @@ -168,7 +168,7 @@ string const currentState(BufferView * bv) return string(); if (mathcursor) - return mathcursor->info(*bv); + return mathcursor->info(bv->fullCursor()); ostringstream state; diff --git a/src/cursor.C b/src/cursor.C index 25ef913692..919c68375a 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -217,21 +217,13 @@ InsetTabular * LCursor::innerInsetTabular() const } -void LCursor::cell(int idx) -{ - BOOST_ASSERT(!cursor_.empty()); - cursor_.back().idx_ = idx; -} - - -int LCursor::cell() const +void LCursor::resetAnchor() { - BOOST_ASSERT(!cursor_.empty()); - return cursor_.back().idx_; + anchor_ = cursor_; } -void LCursor::resetAnchor() +BufferView & LCursor::bv() const { - anchor_ = cursor_; + return *bv_; } diff --git a/src/cursor.h b/src/cursor.h index 6858709839..9fa55a711b 100644 --- a/src/cursor.h +++ b/src/cursor.h @@ -37,10 +37,14 @@ public: typedef CursorSlice::par_type par_type; /// type for cursor positions within a cell typedef CursorSlice::pos_type pos_type; + /// type for row indices + typedef CursorSlice::row_type row_type; + /// type for col indices + typedef CursorSlice::col_type col_type; /// create 'empty' cursor. REMOVE ME LCursor(); - /// create 'empty' cursor + /// create the cursor of a BufferView explicit LCursor(BufferView & bv); /// dispatch from innermost inset upwards DispatchResult dispatch(FuncRequest const & cmd); @@ -54,11 +58,41 @@ public: CursorSlice & top() { return cursor_.back(); } /// access to cursor 'tip' CursorSlice const & top() const { return cursor_.back(); } + /// how many nested insets do we have? + size_t depth() const { return cursor_.size(); } + + /// access to the topmost slice + /// the current inset + InsetBase * inset() const { return top().inset(); } + /// return the text-ed cell this cursor is in + idx_type idx() const { return top().idx(); } + /// return the text-ed cell this cursor is in + idx_type & idx() { return top().idx(); } + /// return the mathed cell this cursor is in + MathArray const & cell() const { return top().cell(); } + /// return the mathed cell this cursor is in + MathArray & cell() { return top().cell(); } + /// return the paragraph this cursor is in + par_type par() const { return top().par(); } + /// return the paragraph this cursor is in + par_type & par() { return top().par(); } + /// return the position within the paragraph + pos_type pos() const { return top().pos(); } + /// return the position within the paragraph + pos_type & pos() { return top().pos(); } + /// return the last position within the paragraph + pos_type lastpos() const { return top().lastpos(); } + /// return the number of embedded cells + size_t nargs() const { return top().nargs(); } + /// return the number of embedded cells + size_t ncols() const { return top().ncols(); } + /// return the number of embedded cells + size_t nrows() const { return top().nrows(); } + /// return the grid row of the current cell + row_type row() const { return top().row(); } + /// return the grid row of the current cell + col_type col() const { return top().col(); } - /// set the cell the cursor is in - void cell(int); - /// return the cell this cursor is in - int cell() const; /// UpdatableInset * innerInset() const; /// @@ -75,7 +109,7 @@ public: void updatePos(); /// sets anchor to cursor position void resetAnchor(); - /// sets anchor to cursor position + /// access to owning BufferView BufferView & bv() const; /// friend std::ostream & operator<<(std::ostream &, LCursor const &); diff --git a/src/cursor_slice.C b/src/cursor_slice.C index 6c4befd0a6..f4e6fb43a9 100644 --- a/src/cursor_slice.C +++ b/src/cursor_slice.C @@ -128,14 +128,14 @@ bool CursorSlice::boundary() const CursorSlice::row_type CursorSlice::row() const { BOOST_ASSERT(asMathInset()); - asMathInset()->row(idx_); + return asMathInset()->row(idx_); } CursorSlice::col_type CursorSlice::col() const { BOOST_ASSERT(asMathInset()); - asMathInset()->col(idx_); + return asMathInset()->col(idx_); } diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 8f912121e4..d7851585cd 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -398,12 +398,12 @@ void InsetTabular::lfunMousePress(BufferView & bv, FuncRequest const & cmd) tablemode = true; bv.fullCursor(theTempCursor); bv.fullCursor().push(this); - bv.fullCursor().cell(cell); + bv.fullCursor().idx() = cell; } else { tablemode = false; setPos(bv, cmd.x, cmd.y); bv.fullCursor(theTempCursor); - bv.fullCursor().cell(cell); + bv.fullCursor().idx() = cell; } lyxerr << bv.cursor() << endl; @@ -422,7 +422,7 @@ void InsetTabular::lfunMouseMotion(BufferView & bv, FuncRequest const & cmd) setSelection(actcell, actcell); bv.setSelection(); } else { - bv.cursor().idx(actcell); + bv.cursor().idx() = actcell; setSelection(sel_cell_start, actcell); tablemode = (sel_cell_start != actcell); } @@ -460,7 +460,7 @@ void InsetTabular::edit(BufferView * view, bool left) resetPos(bv); bv.fitCursor(); bv.fullCursor().push(this); - bv.fullCursor().cell(cell); + bv.fullCursor().idx() = cell; lyxerr << bv.cursor() << endl; } diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index 90775dbc86..78cbdbfc3c 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -111,31 +111,31 @@ void InsetFormulaBase::mutateToText() void InsetFormulaBase::handleFont - (BufferView & bv, string const & arg, string const & font) + (LCursor & cur, string const & arg, string const & font) { // this whole function is a hack and won't work for incremental font // changes... - recordUndo(bv, Undo::ATOMIC); + recordUndo(cur.bv(), Undo::ATOMIC); - if (bv.cursor().inset()->asMathInset()->name() == font) - mathcursor->handleFont(bv, font); + if (cur.inset()->asMathInset()->name() == font) + mathcursor->handleFont(cur, font); else { - mathcursor->handleNest(bv, createMathInset(font)); - mathcursor->insert(bv, arg); + mathcursor->handleNest(cur, createMathInset(font)); + mathcursor->insert(cur, arg); } } -void InsetFormulaBase::handleFont2(BufferView & bv, string const & arg) +void InsetFormulaBase::handleFont2(LCursor & cur, string const & arg) { - recordUndo(bv, Undo::ATOMIC); + recordUndo(cur.bv(), Undo::ATOMIC); LyXFont font; bool b; bv_funcs::string2font(arg, font, b); if (font.color() != LColor::inherit) { MathAtom at = createMathInset("color"); asArray(lcolor.getGUIName(font.color()), at.nucleus()->cell(0)); - mathcursor->handleNest(bv, at, 1); + mathcursor->handleNest(cur, at, 1); } } @@ -154,8 +154,8 @@ string const InsetFormulaBase::editMessage() const void InsetFormulaBase::insetUnlock(BufferView & bv) { if (mathcursor) { - if (mathcursor->inMacroMode(bv)) - mathcursor->macroModeClose(bv); + if (mathcursor->inMacroMode(bv.fullCursor())) + mathcursor->macroModeClose(bv.fullCursor()); releaseMathCursor(bv); } if (bv.buffer()) @@ -164,17 +164,11 @@ void InsetFormulaBase::insetUnlock(BufferView & bv) } -void InsetFormulaBase::getCursor(BufferView & bv, int & x, int & y) const -{ - mathcursor->getScreenPos(bv, x, y); -} - - void InsetFormulaBase::getCursorPos(BufferView & bv, int & x, int & y) const { if (mathcursor) { - mathcursor->getScreenPos(bv, x, y); - x = mathcursor->targetX(bv); + mathcursor->getScreenPos(bv.fullCursor(), x, y); + x = mathcursor->targetX(bv.fullCursor()); x -= xo_; y -= yo_; lyxerr << "InsetFormulaBase::getCursorPos: " << x << ' ' << y << endl; @@ -196,13 +190,6 @@ void InsetFormulaBase::getCursorDim(int & asc, int & desc) const } -void InsetFormulaBase::toggleInsetSelection(BufferView * bv) -{ - if (mathcursor) - bv->update(); -} - - DispatchResult InsetFormulaBase::lfunMouseRelease(BufferView & bv, FuncRequest const & cmd) { @@ -213,7 +200,7 @@ InsetFormulaBase::lfunMouseRelease(BufferView & bv, FuncRequest const & cmd) if (cmd.button() == mouse_button::button3) { // try to dispatch to enclosed insets first - if (!mathcursor->dispatch(bv, cmd).dispatched()) { + if (!mathcursor->dispatch(bv.fullCursor(), cmd).dispatched()) { // launch math panel for right mouse button lyxerr << "lfunMouseRelease: undispatched: " << cmd.button() << endl; bv.owner()->getDialogs().show("mathpanel"); @@ -224,17 +211,17 @@ InsetFormulaBase::lfunMouseRelease(BufferView & bv, FuncRequest const & cmd) if (cmd.button() == mouse_button::button2) { MathArray ar; asArray(bv.getClipboard(), ar); - mathcursor->selClear(bv); - mathcursor->setScreenPos(bv, cmd.x + xo_, cmd.y + yo_); - mathcursor->insert(bv, ar); + mathcursor->selClear(bv.fullCursor()); + mathcursor->setScreenPos(bv.fullCursor(), cmd.x + xo_, cmd.y + yo_); + mathcursor->insert(bv.fullCursor(), ar); bv.update(); return DispatchResult(true, true); } if (cmd.button() == mouse_button::button1) { // try to dispatch to enclosed insets first - mathcursor->dispatch(bv, cmd); - bv.stuffClipboard(mathcursor->grabSelection(bv)); + mathcursor->dispatch(bv.fullCursor(), cmd); + bv.stuffClipboard(mathcursor->grabSelection(bv.fullCursor())); // try to set the cursor //delete mathcursor; //mathcursor = new MathCursor(bv, this, x == 0); @@ -257,20 +244,20 @@ InsetFormulaBase::lfunMousePress(BufferView & bv, FuncRequest const & cmd) releaseMathCursor(bv); mathcursor = new MathCursor(&bv, this, cmd.x == 0); //metrics(bv); - mathcursor->setScreenPos(bv, cmd.x + xo_, cmd.y + yo_); + mathcursor->setScreenPos(bv.fullCursor(), cmd.x + xo_, cmd.y + yo_); } if (cmd.button() == mouse_button::button3) { - mathcursor->dispatch(bv, cmd); + mathcursor->dispatch(bv.fullCursor(), cmd); return DispatchResult(true, true); } if (cmd.button() == mouse_button::button1) { first_x = cmd.x; first_y = cmd.y; - mathcursor->selClear(bv); - mathcursor->setScreenPos(bv, cmd.x + xo_, cmd.y + yo_); - mathcursor->dispatch(bv, cmd); + mathcursor->selClear(bv.fullCursor()); + mathcursor->setScreenPos(bv.fullCursor(), cmd.x + xo_, cmd.y + yo_); + mathcursor->dispatch(bv.fullCursor(), cmd); return DispatchResult(true, true); } @@ -285,7 +272,7 @@ InsetFormulaBase::lfunMouseMotion(BufferView & bv, FuncRequest const & cmd) if (!mathcursor) return DispatchResult(true, true); - if (mathcursor->dispatch(bv, FuncRequest(cmd)).dispatched()) + if (mathcursor->dispatch(bv.fullCursor(), FuncRequest(cmd)).dispatched()) return DispatchResult(true, true); // only select with button 1 @@ -299,9 +286,9 @@ InsetFormulaBase::lfunMouseMotion(BufferView & bv, FuncRequest const & cmd) first_y = cmd.y; if (!mathcursor->selection()) - mathcursor->selStart(bv); + mathcursor->selStart(bv.fullCursor()); - mathcursor->setScreenPos(bv, cmd.x + xo_, cmd.y + yo_); + mathcursor->setScreenPos(bv.fullCursor(), cmd.x + xo_, cmd.y + yo_); bv.update(); return DispatchResult(true, true); } @@ -325,7 +312,7 @@ void InsetFormulaBase::edit(BufferView * bv, int x, int y) releaseMathCursor(*bv); mathcursor = new MathCursor(bv, this, true); //metrics(bv); - mathcursor->setScreenPos(*bv, x + xo_, y + yo_); + mathcursor->setScreenPos(bv->fullCursor(), x + xo_, y + yo_); bv->fullCursor().push(this); // if that is removed, we won't get the magenta box when entering an // inset for the first time @@ -344,6 +331,7 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd) // delete empty mathbox (LFUN_BACKSPACE and LFUN_DELETE) bool remove_inset = false; + LCursor & cur = bv.fullCursor(); switch (cmd.action) { case LFUN_MOUSE_PRESS: @@ -368,10 +356,9 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd) DispatchResult result(true); string argument = cmd.argument; bool sel = false; - bool was_macro = mathcursor->inMacroMode(bv); - bool was_selection = mathcursor->selection(); + bool was_macro = mathcursor->inMacroMode(cur); - mathcursor->normalize(bv); + mathcursor->normalize(cur); mathcursor->touch(); switch (cmd.action) { @@ -389,13 +376,13 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd) case LFUN_PASTESELECTION: case LFUN_MATH_LIMITS: recordUndo(bv, Undo::ATOMIC); - mathcursor->dispatch(bv, cmd); + mathcursor->dispatch(cur, cmd); break; case LFUN_RIGHTSEL: sel = true; // fall through... case LFUN_RIGHT: - result = mathcursor->right(bv, sel) ? + result = mathcursor->right(cur, sel) ? DispatchResult(true, true) : DispatchResult(false, FINISHED_RIGHT); //lyxerr << "calling scroll 20" << endl; //scroll(&bv, 20); @@ -406,27 +393,27 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd) case LFUN_LEFTSEL: sel = true; // fall through case LFUN_LEFT: - result = mathcursor->left(bv, sel) ? + result = mathcursor->left(cur, sel) ? DispatchResult(true, true) : DispatchResult(false, FINISHED); break; case LFUN_UPSEL: sel = true; // fall through case LFUN_UP: - result = mathcursor->up(bv, sel) ? + result = mathcursor->up(cur, sel) ? DispatchResult(true, true) : DispatchResult(false, FINISHED_UP); break; case LFUN_DOWNSEL: sel = true; // fall through case LFUN_DOWN: - result = mathcursor->down(bv, sel) ? + result = mathcursor->down(cur, sel) ? DispatchResult(true, true) : DispatchResult(false, FINISHED_DOWN); break; case LFUN_WORDSEL: - mathcursor->home(bv, false); - mathcursor->end(bv, true); + mathcursor->home(cur, false); + mathcursor->end(cur, true); break; case LFUN_UP_PARAGRAPHSEL: @@ -441,7 +428,7 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd) sel = true; // fall through case LFUN_HOME: case LFUN_WORDLEFT: - result = mathcursor->home(bv, sel) + result = mathcursor->home(cur, sel) ? DispatchResult(true, true) : DispatchResult(true, FINISHED); break; @@ -450,7 +437,7 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd) sel = true; // fall through case LFUN_END: case LFUN_WORDRIGHT: - result = mathcursor->end(bv, sel) + result = mathcursor->end(cur, sel) ? DispatchResult(true, true) : DispatchResult(false, FINISHED_RIGHT); break; @@ -469,17 +456,17 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd) break; case LFUN_CELL_FORWARD: - mathcursor->idxNext(bv); + mathcursor->idxNext(cur); break; case LFUN_CELL_BACKWARD: - mathcursor->idxPrev(bv); + mathcursor->idxPrev(cur); break; case LFUN_DELETE_WORD_BACKWARD: case LFUN_BACKSPACE: recordUndo(bv, Undo::ATOMIC); - if (!mathcursor->backspace(bv)) { + if (!mathcursor->backspace(cur)) { result = DispatchResult(true, FINISHED); remove_inset = true; } @@ -488,7 +475,7 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd) case LFUN_DELETE_WORD_FORWARD: case LFUN_DELETE: recordUndo(bv, Undo::ATOMIC); - if (!mathcursor->erase(bv)) { + if (!mathcursor->erase(cur)) { result = DispatchResult(true, FINISHED); remove_inset = true; } @@ -504,7 +491,7 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd) int y = 0; istringstream is(cmd.argument.c_str()); is >> x >> y; - mathcursor->setScreenPos(bv, x, y); + mathcursor->setScreenPos(cur, x, y); break; } @@ -513,19 +500,19 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd) istringstream is(cmd.argument.c_str()); is >> n; if (was_macro) - mathcursor->macroModeClose(bv); + mathcursor->macroModeClose(cur); recordUndo(bv, Undo::ATOMIC); - mathcursor->selPaste(bv, n); + mathcursor->selPaste(cur, n); break; } case LFUN_CUT: recordUndo(bv, Undo::DELETE); - mathcursor->selCut(bv); + mathcursor->selCut(cur); break; case LFUN_COPY: - mathcursor->selCopy(bv); + mathcursor->selCopy(cur); break; @@ -536,7 +523,7 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd) // do superscript if LyX handles // deadkeys recordUndo(bv, Undo::ATOMIC); - mathcursor->script(bv, true); + mathcursor->script(cur, true); } break; @@ -559,26 +546,26 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd) // Math fonts case LFUN_FREEFONT_APPLY: case LFUN_FREEFONT_UPDATE: - handleFont2(bv, cmd.argument); + handleFont2(cur, cmd.argument); break; - case LFUN_BOLD: handleFont(bv, cmd.argument, "mathbf"); break; - case LFUN_SANS: handleFont(bv, cmd.argument, "mathsf"); break; - case LFUN_EMPH: handleFont(bv, cmd.argument, "mathcal"); break; - case LFUN_ROMAN: handleFont(bv, cmd.argument, "mathrm"); break; - case LFUN_CODE: handleFont(bv, cmd.argument, "texttt"); break; - case LFUN_FRAK: handleFont(bv, cmd.argument, "mathfrak"); break; - case LFUN_ITAL: handleFont(bv, cmd.argument, "mathit"); break; - case LFUN_NOUN: handleFont(bv, cmd.argument, "mathbb"); break; - //case LFUN_FREEFONT_APPLY: handleFont(bv, cmd.argument, "textrm"); break; - case LFUN_DEFAULT: handleFont(bv, cmd.argument, "textnormal"); break; + case LFUN_BOLD: handleFont(cur, cmd.argument, "mathbf"); break; + case LFUN_SANS: handleFont(cur, cmd.argument, "mathsf"); break; + case LFUN_EMPH: handleFont(cur, cmd.argument, "mathcal"); break; + case LFUN_ROMAN: handleFont(cur, cmd.argument, "mathrm"); break; + case LFUN_CODE: handleFont(cur, cmd.argument, "texttt"); break; + case LFUN_FRAK: handleFont(cur, cmd.argument, "mathfrak"); break; + case LFUN_ITAL: handleFont(cur, cmd.argument, "mathit"); break; + case LFUN_NOUN: handleFont(cur, cmd.argument, "mathbb"); break; + //case LFUN_FREEFONT_APPLY: handleFont(cur, cmd.argument, "textrm"); break; + case LFUN_DEFAULT: handleFont(cur, cmd.argument, "textnormal"); break; case LFUN_MATH_MODE: - if (mathcursor->currentMode(bv) == MathInset::TEXT_MODE) - mathcursor->niceInsert(bv, MathAtom(new MathHullInset("simple"))); + if (mathcursor->currentMode(cur) == MathInset::TEXT_MODE) + mathcursor->niceInsert(cur, MathAtom(new MathHullInset("simple"))); else - handleFont(bv, cmd.argument, "textrm"); - //bv.owner()->message(_("math text mode toggled")); + handleFont(cur, cmd.argument, "textrm"); + //cur.owner()->message(_("math text mode toggled")); break; case LFUN_MATH_SIZE: @@ -601,7 +588,7 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd) m = max(1u, m); n = max(1u, n); v_align += 'c'; - mathcursor->niceInsert(bv, + mathcursor->niceInsert(cur, MathAtom(new MathArrayInset("array", m, n, v_align[0], h_align))); break; } @@ -616,14 +603,14 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd) if (rs.empty()) rs = ')'; recordUndo(bv, Undo::ATOMIC); - mathcursor->handleNest(bv, MathAtom(new MathDelimInset(ls, rs))); + mathcursor->handleNest(cur, MathAtom(new MathDelimInset(ls, rs))); break; } case LFUN_SPACE_INSERT: case LFUN_MATH_SPACE: recordUndo(bv, Undo::ATOMIC); - mathcursor->insert(bv, MathAtom(new MathSpaceInset(","))); + mathcursor->insert(cur, MathAtom(new MathSpaceInset(","))); break; case LFUN_UNDO: @@ -638,7 +625,7 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd) case LFUN_INSET_ERT: // interpret this as if a backslash was typed recordUndo(bv, Undo::ATOMIC); - mathcursor->interpret(bv, '\\'); + mathcursor->interpret(cur, '\\'); break; case LFUN_BREAKPARAGRAPH: @@ -652,7 +639,7 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd) // math-insert only handles special math things like "matrix". case LFUN_INSERT_MATH: recordUndo(bv, Undo::ATOMIC); - mathcursor->niceInsert(bv, argument); + mathcursor->niceInsert(cur, argument); break; case -1: @@ -660,22 +647,22 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd) if (!argument.empty()) { recordUndo(bv, Undo::ATOMIC); if (argument.size() == 1) - result = mathcursor->interpret(bv, argument[0]) + result = mathcursor->interpret(cur, argument[0]) ? DispatchResult(true, true) : DispatchResult(false, FINISHED_RIGHT); else - mathcursor->insert(bv, argument); + mathcursor->insert(cur, argument); } break; case LFUN_ESCAPE: if (mathcursor->selection()) - mathcursor->selClear(bv); + mathcursor->selClear(cur); else result = DispatchResult(false); break; case LFUN_INSET_TOGGLE: - mathcursor->insetToggle(bv); + mathcursor->insetToggle(cur); break; case LFUN_DIALOG_SHOW: @@ -707,7 +694,7 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd) } else { MathArray ar; if (createMathInset_fromDialogStr(cmd.argument, ar)) { - mathcursor->insert(bv, ar); + mathcursor->insert(cur, ar); result = DispatchResult(true, true); } else { result = DispatchResult(false); @@ -731,17 +718,14 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd) if (result == DispatchResult(true, true)) bv.update(); - mathcursor->normalize(bv); + mathcursor->normalize(cur); mathcursor->touch(); BOOST_ASSERT(mathcursor); - if (mathcursor->selection() || was_selection) - toggleInsetSelection(&bv); - if (result.dispatched()) { revealCodes(bv); - bv.stuffClipboard(mathcursor->grabSelection(bv)); + bv.stuffClipboard(mathcursor->grabSelection(cur)); } else { releaseMathCursor(bv); if (remove_inset) @@ -756,7 +740,7 @@ void InsetFormulaBase::revealCodes(BufferView & bv) const { if (!mathcursor) return; - bv.owner()->message(mathcursor->info(bv)); + bv.owner()->message(mathcursor->info(bv.fullCursor())); /* // write something to the minibuffer // translate to latex @@ -849,7 +833,7 @@ bool InsetFormulaBase::searchForward(BufferView * bv, string const & str, delete mathcursor; mathcursor = new MathCursor(bv, this, true); //metrics(bv); - mathcursor->setSelection(*bv, it, ar.size()); + mathcursor->setSelection(bv->fullCursor(), it, ar.size()); current = it; top.pos_ += ar.size(); bv->update(); @@ -879,7 +863,7 @@ bool InsetFormulaBase::display() const string InsetFormulaBase::selectionAsString(BufferView & bv) const { - return mathcursor ? mathcursor->grabSelection(bv) : string(); + return mathcursor ? mathcursor->grabSelection(bv.fullCursor()) : string(); } ///////////////////////////////////////////////////////////////////// diff --git a/src/mathed/formulabase.h b/src/mathed/formulabase.h index b705c10ad7..7de324fac8 100644 --- a/src/mathed/formulabase.h +++ b/src/mathed/formulabase.h @@ -20,6 +20,7 @@ class Buffer; class BufferView; class MathAtom; class CursorSlice; +class LCursor; /// An abstract base class for all math related LyX insets @@ -45,14 +46,10 @@ public: virtual InsetOld::Code lyxCode() const; /// what appears in the minibuffer when opening virtual std::string const editMessage() const; - /// + /// get the absolute document x,y of the cursor virtual void getCursorPos(BufferView & bv, int & x, int & y) const; /// virtual void getCursorDim(int &, int &) const; - /// get the absolute document x,y of the cursor - virtual void getCursor(BufferView & bv, int & x, int & y) const; - /// - virtual void toggleInsetSelection(BufferView * bv); /// virtual void insetUnlock(BufferView & bv); @@ -113,9 +110,9 @@ protected: virtual void generatePreview(Buffer const &) const {} /// - void handleFont(BufferView & bv, std::string const & arg, std::string const & font); + void handleFont(LCursor &, std::string const & arg, std::string const & font); /// - void handleFont2(BufferView & bv, std::string const & arg); + void handleFont2(LCursor &, std::string const & arg); }; // We don't really mess want around with mathed stuff outside mathed. diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index d2bdcd7387..438df2d365 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -56,7 +56,7 @@ limited_stack theCutBuffer; MathCursor::MathCursor(BufferView * bv, InsetFormulaBase * formula, bool front) : formula_(formula), autocorrect_(false), selection_(false) { - front ? first(*bv) : last(*bv); + front ? first(bv->fullCursor()) : last(bv->fullCursor()); } @@ -68,56 +68,54 @@ MathCursor::~MathCursor() } -void MathCursor::push(BufferView & bv, MathAtom & t) +void MathCursor::push(LCursor & cur, MathAtom & t) { - bv.fullCursor().push(t.nucleus()); + cur.push(t.nucleus()); } -void MathCursor::pushLeft(BufferView & bv, MathAtom & t) +void MathCursor::pushLeft(LCursor & cur, MathAtom & t) { //lyxerr << "Entering atom " << t << " left" << endl; - push(bv, t); - t->idxFirst(bv); + push(cur, t); + t->idxFirst(cur); } -void MathCursor::pushRight(BufferView & bv, MathAtom & t) +void MathCursor::pushRight(LCursor & cur, MathAtom & t) { //lyxerr << "Entering atom " << t << " right" << endl; - posLeft(bv); - push(bv, t); - t->idxLast(bv); + posLeft(cur); + push(cur, t); + t->idxLast(cur); } -bool MathCursor::popLeft(BufferView & bv) +bool MathCursor::popLeft(LCursor & cur) { - CursorSlice & cur = cursorTip(bv); //lyxerr << "Leaving atom to the left" << endl; - if (depth(bv) <= 1) { - if (depth(bv) == 1) + if (cur.depth() <= 1) { + if (cur.depth() == 1) cur.inset()->asMathInset()->notifyCursorLeaves(cur.idx()); return false; } cur.inset()->asMathInset()->notifyCursorLeaves(cur.idx()); - bv.fullCursor().pop(); + cur.pop(); return true; } -bool MathCursor::popRight(BufferView & bv) +bool MathCursor::popRight(LCursor & cur) { - CursorSlice & cur = cursorTip(bv); //lyxerr << "Leaving atom "; bv.inset->asMathInset()->write(cerr, false); cerr << " right" << endl; - if (depth(bv) <= 1) { - if (depth(bv) == 1) + if (cur.depth() <= 1) { + if (cur.depth() == 1) cur.inset()->asMathInset()->notifyCursorLeaves(cur.idx()); return false; } cur.inset()->asMathInset()->notifyCursorLeaves(cur.idx()); - bv.fullCursor().pop(); - posRight(bv); + cur.pop(); + posRight(cur); return true; } @@ -127,8 +125,8 @@ bool MathCursor::popRight(BufferView & bv) void MathCursor::dump(char const * what) const { lyxerr << "MC: " << what << endl; - lyxerr << " Cursor: " << depth() << endl; - for (unsigned i = 0; i < depth(); ++i) + lyxerr << " Cursor: " << cur.depth() << endl; + for (unsigned i = 0; i < cur.depth(); ++i) lyxerr << " i: " << i << ' ' << Cursor_[i] << endl; lyxerr << " Anchor: " << Anchor_.size() << endl; for (unsigned i = 0; i < Anchor_.size(); ++i) @@ -144,7 +142,7 @@ bool MathCursor::isInside(MathInset const *) const { #warning FIXME /* - for (unsigned i = 0; i < depth(); ++i) + for (unsigned i = 0; i < cur.depth(); ++i) if (Cursor_[i].asMathInset() == p) return true; */ @@ -164,9 +162,9 @@ bool MathCursor::openable(MathAtom const & t, bool sel) const #if 0 if (sel) { // we can't move into anything new during selection - if (depth() == Anchor_.size()) + if (cur.depth() == Anchor_.size()) return false; - if (t.operator->() != Anchor_[depth()].asMathInset()) + if (t.operator->() != Anchor_[cur.depth()].asMathInset()) return false; } #else @@ -178,16 +176,14 @@ bool MathCursor::openable(MathAtom const & t, bool sel) const } -bool MathCursor::inNucleus(BufferView & bv) const +bool MathCursor::inNucleus(LCursor & cur) const { - CursorSlice & cur = cursorTip(bv); return cur.inset()->asMathInset()->asScriptInset() && cur.idx() == 2; } -bool MathCursor::posLeft(BufferView & bv) +bool MathCursor::posLeft(LCursor & cur) { - CursorSlice & cur = cursorTip(bv); if (cur.pos() == 0) return false; --cur.pos(); @@ -195,9 +191,8 @@ bool MathCursor::posLeft(BufferView & bv) } -bool MathCursor::posRight(BufferView & bv) +bool MathCursor::posRight(LCursor & cur) { - CursorSlice & cur = cursorTip(bv); if (cur.pos() == cur.lastpos()) return false; ++cur.pos(); @@ -205,63 +200,63 @@ bool MathCursor::posRight(BufferView & bv) } -bool MathCursor::left(BufferView & bv, bool sel) +bool MathCursor::left(LCursor & cur, bool sel) { dump("Left 1"); autocorrect_ = false; - bv.x_target(-1); // "no target" - if (inMacroMode(bv)) { - macroModeClose(bv); + cur.bv().x_target(-1); // "no target" + if (inMacroMode(cur)) { + macroModeClose(cur); return true; } - selHandle(bv, sel); + selHandle(cur, sel); - if (hasPrevAtom(bv) && openable(prevAtom(bv), sel)) { - pushRight(bv, prevAtom(bv)); + if (hasPrevAtom(cur) && openable(prevAtom(cur), sel)) { + pushRight(cur, prevAtom(cur)); return true; } - return posLeft(bv) || idxLeft(bv) || popLeft(bv) || selection_; + return posLeft(cur) || idxLeft(cur) || popLeft(cur) || selection_; } -bool MathCursor::right(BufferView & bv, bool sel) +bool MathCursor::right(LCursor & cur, bool sel) { dump("Right 1"); autocorrect_ = false; - bv.x_target(-1); // "no target" - if (inMacroMode(bv)) { - macroModeClose(bv); + cur.bv().x_target(-1); // "no target" + if (inMacroMode(cur)) { + macroModeClose(cur); return true; } - selHandle(bv, sel); + selHandle(cur, sel); - if (hasNextAtom(bv) && openable(nextAtom(bv), sel)) { - pushLeft(bv, nextAtom(bv)); + if (hasNextAtom(cur) && openable(nextAtom(cur), sel)) { + pushLeft(cur, nextAtom(cur)); return true; } - return posRight(bv) || idxRight(bv) || popRight(bv) || selection_; + return posRight(cur) || idxRight(cur) || popRight(cur) || selection_; } -void MathCursor::first(BufferView & bv) +void MathCursor::first(LCursor & cur) { #warning FIXME //Cursor_.clear(); - push(bv, formula_->par()); - bv.cursor().inset()->asMathInset()->idxFirst(bv); - bv.resetAnchor(); + push(cur, formula_->par()); + cur.inset()->asMathInset()->idxFirst(cur); + cur.resetAnchor(); } -void MathCursor::last(BufferView & bv) +void MathCursor::last(LCursor & cur) { #warning FIXME //Cursor_.clear(); - push(bv, formula_->par()); - bv.cursor().inset()->asMathInset()->idxLast(bv); - bv.resetAnchor(); + push(cur, formula_->par()); + cur.inset()->asMathInset()->idxLast(cur); + cur.resetAnchor(); } @@ -281,206 +276,199 @@ bool positionable(CursorBase const & cursor, CursorBase const & anchor) } -void MathCursor::setScreenPos(BufferView & bv, int x, int y) +void MathCursor::setScreenPos(LCursor & cur, int x, int y) { dump("setScreenPos 1"); - bool res = bruteFind(bv, x, y, + bool res = bruteFind(cur, x, y, formula()->xlow(), formula()->xhigh(), formula()->ylow(), formula()->yhigh()); if (!res) { // this can happen on creation of "math-display" dump("setScreenPos 1.5"); - first(bv); + first(cur); } - bv.x_target(-1); // "no target" + cur.bv().x_target(-1); // "no target" dump("setScreenPos 2"); } -bool MathCursor::home(BufferView & bv, bool sel) +bool MathCursor::home(LCursor & cur, bool sel) { dump("home 1"); autocorrect_ = false; - selHandle(bv, sel); - macroModeClose(bv); - if (!bv.cursor().inset()->asMathInset()->idxHome(bv)) - return popLeft(bv); + selHandle(cur, sel); + macroModeClose(cur); + if (!cur.inset()->asMathInset()->idxHome(cur)) + return popLeft(cur); dump("home 2"); - bv.x_target(-1); // "no target" + cur.bv().x_target(-1); // "no target" return true; } -bool MathCursor::end(BufferView & bv, bool sel) +bool MathCursor::end(LCursor & cur, bool sel) { dump("end 1"); autocorrect_ = false; - selHandle(bv, sel); - macroModeClose(bv); - if (!bv.cursor().inset()->asMathInset()->idxEnd(bv)) - return popRight(bv); + selHandle(cur, sel); + macroModeClose(cur); + if (!cur.inset()->asMathInset()->idxEnd(cur)) + return popRight(cur); dump("end 2"); - bv.x_target(-1); // "no target" + cur.bv().x_target(-1); // "no target" return true; } -void MathCursor::plainErase(BufferView & bv) +void MathCursor::plainErase(LCursor & cur) { - CursorSlice & cur = cursorTip(bv); cur.cell().erase(cur.pos()); } -void MathCursor::markInsert(BufferView & bv) +void MathCursor::markInsert(LCursor & cur) { //lyxerr << "inserting mark" << endl; - CursorSlice & cur = cursorTip(bv); cur.cell().insert(cur.pos(), MathAtom(new MathCharInset(0))); } -void MathCursor::markErase(BufferView & bv) +void MathCursor::markErase(LCursor & cur) { //lyxerr << "deleting mark" << endl; - CursorSlice & cur = cursorTip(bv); cur.cell().erase(cur.pos()); } -void MathCursor::plainInsert(BufferView & bv, MathAtom const & t) +void MathCursor::plainInsert(LCursor & cur, MathAtom const & t) { dump("plainInsert"); - CursorSlice & cur = cursorTip(bv); cur.cell().insert(cur.pos(), t); ++cur.pos(); } -void MathCursor::insert2(BufferView & bv, string const & str) +void MathCursor::insert2(LCursor & cur, string const & str) { MathArray ar; asArray(str, ar); - insert(bv, ar); + insert(cur, ar); } -void MathCursor::insert(BufferView & bv, string const & str) +void MathCursor::insert(LCursor & cur, string const & str) { //lyxerr << "inserting '" << str << "'" << endl; - selClearOrDel(bv); + selClearOrDel(cur); for (string::const_iterator it = str.begin(); it != str.end(); ++it) - plainInsert(bv, MathAtom(new MathCharInset(*it))); + plainInsert(cur, MathAtom(new MathCharInset(*it))); } -void MathCursor::insert(BufferView & bv, char c) +void MathCursor::insert(LCursor & cur, char c) { //lyxerr << "inserting '" << c << "'" << endl; - selClearOrDel(bv); - plainInsert(bv, MathAtom(new MathCharInset(c))); + selClearOrDel(cur); + plainInsert(cur, MathAtom(new MathCharInset(c))); } -void MathCursor::insert(BufferView & bv, MathAtom const & t) +void MathCursor::insert(LCursor & cur, MathAtom const & t) { - macroModeClose(bv); - selClearOrDel(bv); - plainInsert(bv, t); + macroModeClose(cur); + selClearOrDel(cur); + plainInsert(cur, t); } -void MathCursor::niceInsert(BufferView & bv, string const & t) +void MathCursor::niceInsert(LCursor & cur, string const & t) { MathArray ar; asArray(t, ar); if (ar.size() == 1) - niceInsert(bv, ar[0]); + niceInsert(cur, ar[0]); else - insert(bv, ar); + insert(cur, ar); } -void MathCursor::niceInsert(BufferView & bv, MathAtom const & t) +void MathCursor::niceInsert(LCursor & cur, MathAtom const & t) { - macroModeClose(bv); - string safe = grabAndEraseSelection(bv); - plainInsert(bv, t); + macroModeClose(cur); + string safe = grabAndEraseSelection(cur); + plainInsert(cur, t); // enter the new inset and move the contents of the selection if possible if (t->isActive()) { - posLeft(bv); - pushLeft(bv, nextAtom(bv)); - paste(bv, safe); + posLeft(cur); + pushLeft(cur, nextAtom(cur)); + paste(cur, safe); } } -void MathCursor::insert(BufferView & bv, MathArray const & ar) +void MathCursor::insert(LCursor & cur, MathArray const & ar) { - CursorSlice & cur = cursorTip(bv); - macroModeClose(bv); + macroModeClose(cur); if (selection_) - eraseSelection(bv); + eraseSelection(cur); cur.cell().insert(cur.pos(), ar); cur.pos() += ar.size(); } -void MathCursor::paste(BufferView & bv, string const & data) +void MathCursor::paste(LCursor & cur, string const & data) { - dispatch(bv, FuncRequest(LFUN_PASTE, data)); + dispatch(cur, FuncRequest(LFUN_PASTE, data)); } -bool MathCursor::backspace(BufferView & bv) +bool MathCursor::backspace(LCursor & cur) { - CursorSlice & cur = cursorTip(bv); autocorrect_ = false; if (selection_) { - selDel(bv); + selDel(cur); return true; } if (cur.pos() == 0) { if (cur.inset()->asMathInset()->nargs() == 1 && - depth(bv) == 1 && + cur.depth() == 1 && cur.lastpos() == 0) return false; - pullArg(bv); + pullArg(cur); return true; } - if (inMacroMode(bv)) { - MathUnknownInset * p = activeMacro(bv); + if (inMacroMode(cur)) { + MathUnknownInset * p = activeMacro(cur); if (p->name().size() > 1) { p->setName(p->name().substr(0, p->name().size() - 1)); return true; } } - if (hasPrevAtom(bv) && prevAtom(bv)->nargs() > 0) { + if (hasPrevAtom(cur) && prevAtom(cur)->nargs() > 0) { // let's require two backspaces for 'big stuff' and // highlight on the first - left(bv, true); + left(cur, true); } else { --cur.pos(); - plainErase(bv); + plainErase(cur); } return true; } -bool MathCursor::erase(BufferView & bv) +bool MathCursor::erase(LCursor & cur) { - CursorSlice & cur = cursorTip(bv); autocorrect_ = false; - if (inMacroMode(bv)) + if (inMacroMode(cur)) return true; if (selection_) { - selDel(bv); + selDel(cur); return true; } @@ -492,30 +480,30 @@ bool MathCursor::erase(BufferView & bv) // special behaviour when in last position of cell if (cur.pos() == cur.lastpos()) { bool one_cell = cur.inset()->asMathInset()->nargs() == 1; - if (one_cell && depth(bv) == 1 && cur.lastpos() == 0) + if (one_cell && cur.depth() == 1 && cur.lastpos() == 0) return false; // remove markup if (one_cell) - pullArg(bv); + pullArg(cur); else cur.inset()->asMathInset()->idxGlue(cur.idx()); return true; } - if (hasNextAtom(bv) && nextAtom(bv)->nargs() > 0) - right(bv, true); + if (hasNextAtom(cur) && nextAtom(cur)->nargs() > 0) + right(cur, true); else - plainErase(bv); + plainErase(cur); return true; } -bool MathCursor::up(BufferView & bv, bool sel) +bool MathCursor::up(LCursor & cur, bool sel) { dump("up 1"); - macroModeClose(bv); - selHandle(bv, sel); + macroModeClose(cur); + selHandle(cur, sel); #warning FIXME #if 0 CursorBase save = Cursor_; @@ -528,11 +516,11 @@ bool MathCursor::up(BufferView & bv, bool sel) } -bool MathCursor::down(BufferView & bv, bool sel) +bool MathCursor::down(LCursor & cur, bool sel) { dump("down 1"); - macroModeClose(bv); - selHandle(bv, sel); + macroModeClose(cur); + selHandle(cur, sel); #warning FIXME #if 0 CursorBase save = Cursor_; @@ -545,12 +533,11 @@ bool MathCursor::down(BufferView & bv, bool sel) } -void MathCursor::macroModeClose(BufferView & bv) +void MathCursor::macroModeClose(LCursor & cur) { - CursorSlice & cur = cursorTip(bv); - if (!inMacroMode(bv)) + if (!inMacroMode(cur)) return; - MathUnknownInset * p = activeMacro(bv); + MathUnknownInset * p = activeMacro(cur); p->finalize(); string s = p->name(); --cur.pos(); @@ -567,28 +554,28 @@ void MathCursor::macroModeClose(BufferView & bv) && formula()->getInsetName() == name) lyxerr << "can't enter recursive macro" << endl; - niceInsert(bv, createMathInset(name)); + niceInsert(cur, createMathInset(name)); } -string MathCursor::macroName(BufferView & bv) const +string MathCursor::macroName(LCursor & cur) const { - return inMacroMode(bv) ? activeMacro(bv)->name() : string(); + return inMacroMode(cur) ? activeMacro(cur)->name() : string(); } -void MathCursor::selClear(BufferView & bv) +void MathCursor::selClear(LCursor & cur) { - bv.resetAnchor(); - bv.clearSelection(); + cur.resetAnchor(); + cur.bv().clearSelection(); } -void MathCursor::selCopy(BufferView & bv) +void MathCursor::selCopy(LCursor & cur) { dump("selCopy"); if (selection_) { - theCutBuffer.push(grabSelection(bv)); + theCutBuffer.push(grabSelection(cur)); selection_ = false; } else { //theCutBuffer.erase(); @@ -596,58 +583,58 @@ void MathCursor::selCopy(BufferView & bv) } -void MathCursor::selCut(BufferView & bv) +void MathCursor::selCut(LCursor & cur) { dump("selCut"); - theCutBuffer.push(grabAndEraseSelection(bv)); + theCutBuffer.push(grabAndEraseSelection(cur)); } -void MathCursor::selDel(BufferView & bv) +void MathCursor::selDel(LCursor & cur) { dump("selDel"); if (selection_) { - eraseSelection(bv); + eraseSelection(cur); selection_ = false; } } -void MathCursor::selPaste(BufferView & bv, size_t n) +void MathCursor::selPaste(LCursor & cur, size_t n) { dump("selPaste"); - selClearOrDel(bv); + selClearOrDel(cur); if (n < theCutBuffer.size()) - paste(bv, theCutBuffer[n]); - //grabSelection(bv); + paste(cur, theCutBuffer[n]); + //grabSelection(cur); selection_ = false; } -void MathCursor::selHandle(BufferView & bv, bool sel) +void MathCursor::selHandle(LCursor & cur, bool sel) { if (sel == selection_) return; //clear(); - bv.resetAnchor(); + cur.resetAnchor(); selection_ = sel; } -void MathCursor::selStart(BufferView & bv) +void MathCursor::selStart(LCursor & cur) { dump("selStart 1"); //clear(); - bv.resetAnchor(); + cur.resetAnchor(); selection_ = true; dump("selStart 2"); } -void MathCursor::selClearOrDel(BufferView & bv) +void MathCursor::selClearOrDel(LCursor & cur) { if (lyxrc.auto_region_delete) - selDel(bv); + selDel(cur); else selection_ = false; } @@ -659,34 +646,33 @@ void MathCursor::drawSelection(PainterInfo & pi) const return; CursorSlice i1; CursorSlice i2; - getSelection(*pi.base.bv, i1, i2); + getSelection(pi.base.bv->fullCursor(), i1, i2); i1.asMathInset()->drawSelection(pi, i1.idx_, i1.pos_, i2.idx_, i2.pos_); } -void MathCursor::handleNest(BufferView & bv, MathAtom const & a, int c) +void MathCursor::handleNest(LCursor & cur, MathAtom const & a, int c) { MathAtom at = a; - asArray(grabAndEraseSelection(bv), at.nucleus()->cell(c)); - insert(bv, at); - pushRight(bv, prevAtom(bv)); + asArray(grabAndEraseSelection(cur), at.nucleus()->cell(c)); + insert(cur, at); + pushRight(cur, prevAtom(cur)); } -void MathCursor::getScreenPos(BufferView & bv, int & x, int & y) const +void MathCursor::getScreenPos(LCursor & cur, int & x, int & y) const { - CursorSlice & cur = cursorTip(bv); cur.inset()->asMathInset()->getScreenPos(cur.idx(), cur.pos(), x, y); } -int MathCursor::targetX(BufferView & bv) const +int MathCursor::targetX(LCursor & cur) const { - if (bv.x_target() != -1) - return bv.x_target(); + if (cur.bv().x_target() != -1) + return cur.bv().x_target(); int x = 0; int y = 0; - getScreenPos(bv, x, y); + getScreenPos(cur, x, y); return x; } @@ -697,9 +683,8 @@ InsetFormulaBase * MathCursor::formula() const } -void MathCursor::adjust(BufferView & bv, pos_type from, difference_type diff) +void MathCursor::adjust(LCursor & cur, pos_type from, difference_type diff) { - CursorSlice & cur = cursorTip(bv); if (cur.pos() > from) cur.pos() += diff; #warning FIXME @@ -709,34 +694,34 @@ void MathCursor::adjust(BufferView & bv, pos_type from, difference_type diff) // just to be on the safe side // theoretically unecessary #endif - normalize(bv); + normalize(cur); } -bool MathCursor::inMacroMode(BufferView & bv) const +bool MathCursor::inMacroMode(LCursor & cur) const { - if (!hasPrevAtom(bv)) + if (!hasPrevAtom(cur)) return false; - MathUnknownInset const * p = prevAtom(bv)->asUnknownInset(); + MathUnknownInset const * p = prevAtom(cur)->asUnknownInset(); return p && !p->final(); } -MathUnknownInset * MathCursor::activeMacro(BufferView & bv) +MathUnknownInset * MathCursor::activeMacro(LCursor & cur) { - return inMacroMode(bv) ? prevAtom(bv).nucleus()->asUnknownInset() : 0; + return inMacroMode(cur) ? prevAtom(cur).nucleus()->asUnknownInset() : 0; } -MathUnknownInset const * MathCursor::activeMacro(BufferView & bv) const +MathUnknownInset const * MathCursor::activeMacro(LCursor & cur) const { - return inMacroMode(bv) ? prevAtom(bv)->asUnknownInset() : 0; + return inMacroMode(cur) ? prevAtom(cur)->asUnknownInset() : 0; } -bool MathCursor::inMacroArgMode(BufferView & bv) const +bool MathCursor::inMacroArgMode(LCursor & cur) const { - return bv.cursor().pos() > 0 && prevAtom(bv)->getChar() == '#'; + return cur.pos() > 0 && prevAtom(cur)->getChar() == '#'; } @@ -746,53 +731,52 @@ bool MathCursor::selection() const } -MathGridInset * MathCursor::enclosingGrid - (BufferView &, MathCursor::idx_type &) const +MathGridInset * +MathCursor::enclosingGrid(LCursor & cur, MathCursor::idx_type & idx) const { -#warning FIXME -#if 0 - for (MathInset::difference_type i = depth() - 1; i >= 0; --i) { - MathGridInset * p = Cursor_[i].asMathInset()->asGridInset(); + for (MathInset::difference_type i = cur.depth() - 1; i >= 0; --i) { + MathInset * m = cur.cursor_[i].inset()->asMathInset(); + if (!m) + return 0; + MathGridInset * p = m->asGridInset(); if (p) { - idx = Cursor_[i].idx_; + idx = cur.cursor_[i].idx_; return p; } } -#endif return 0; } -void MathCursor::popToHere(BufferView & bv, MathInset const * p) +void MathCursor::popToHere(LCursor & cur, MathInset const * p) { - while (depth(bv) && bv.cursor().asMathInset() != p) - bv.fullCursor().cursor_.pop_back(); + while (cur.depth() && cur.inset()->asMathInset() != p) + cur.pop(); } -void MathCursor::popToEnclosingGrid(BufferView & bv) +void MathCursor::popToEnclosingGrid(LCursor & cur) { - while (depth(bv) && !bv.cursor().asMathInset()->asGridInset()) - bv.fullCursor().cursor_.pop_back(); + while (cur.depth() && !cur.inset()->asMathInset()->asGridInset()) + cur.pop(); } -void MathCursor::popToEnclosingHull(BufferView & bv) +void MathCursor::popToEnclosingHull(LCursor & cur) { - while (depth(bv) && !bv.cursor().asMathInset()->asGridInset()) - bv.fullCursor().cursor_.pop_back(); + while (cur.depth() && !cur.inset()->asMathInset()->asGridInset()) + cur.pop(); } -void MathCursor::pullArg(BufferView & bv) +void MathCursor::pullArg(LCursor & cur) { - CursorSlice & cur = cursorTip(bv); dump("pullarg"); MathArray ar = cur.cell(); - if (popLeft(bv)) { - plainErase(bv); + if (popLeft(cur)) { + plainErase(cur); cur.cell().insert(cur.pos(), ar); - bv.resetAnchor(); + cur.resetAnchor(); } else { formula()->mutateToText(); } @@ -811,9 +795,8 @@ void MathCursor::touch() } -void MathCursor::normalize(BufferView & bv) +void MathCursor::normalize(LCursor & cur) { - CursorSlice & cur = cursorTip(bv); if (cur.idx() >= cur.nargs()) { lyxerr << "this should not really happen - 1: " << cur.idx() << ' ' << cur.nargs() @@ -835,133 +818,125 @@ void MathCursor::normalize(BufferView & bv) } -bool MathCursor::hasPrevAtom(BufferView & bv) const +bool MathCursor::hasPrevAtom(LCursor & cur) const { - CursorSlice & cur = cursorTip(bv); return cur.pos() > 0; } -bool MathCursor::hasNextAtom(BufferView & bv) const +bool MathCursor::hasNextAtom(LCursor & cur) const { - CursorSlice & cur = cursorTip(bv); return cur.pos() < cur.lastpos(); } -MathAtom const & MathCursor::prevAtom(BufferView & bv) const +MathAtom const & MathCursor::prevAtom(LCursor & cur) const { - CursorSlice & cur = cursorTip(bv); BOOST_ASSERT(cur.pos() > 0); return cur.cell()[cur.pos() - 1]; } -MathAtom & MathCursor::prevAtom(BufferView & bv) +MathAtom & MathCursor::prevAtom(LCursor & cur) { - CursorSlice & cur = cursorTip(bv); BOOST_ASSERT(cur.pos() > 0); return cur.cell()[cur.pos() - 1]; } -MathAtom const & MathCursor::nextAtom(BufferView & bv) const +MathAtom const & MathCursor::nextAtom(LCursor & cur) const { - CursorSlice & cur = cursorTip(bv); BOOST_ASSERT(cur.pos() < cur.lastpos()); return cur.cell()[cur.pos()]; } -MathAtom & MathCursor::nextAtom(BufferView & bv) +MathAtom & MathCursor::nextAtom(LCursor & cur) { - CursorSlice & cur = cursorTip(bv); BOOST_ASSERT(cur.pos() < cur.lastpos()); return cur.cell()[cur.pos()]; } -void MathCursor::idxNext(BufferView & bv) +void MathCursor::idxNext(LCursor & cur) { - CursorSlice & cur = cursorTip(bv); - cur.inset()->asMathInset()->idxNext(bv); + cur.inset()->asMathInset()->idxNext(cur); } -void MathCursor::idxPrev(BufferView & bv) +void MathCursor::idxPrev(LCursor & cur) { - CursorSlice & cur = cursorTip(bv); - cur.inset()->asMathInset()->idxPrev(bv); + cur.inset()->asMathInset()->idxPrev(cur); } -char MathCursor::valign(BufferView & bv) const +char MathCursor::valign(LCursor & cur) const { idx_type idx; - MathGridInset * p = enclosingGrid(bv, idx); + MathGridInset * p = enclosingGrid(cur, idx); return p ? p->valign() : '\0'; } -char MathCursor::halign(BufferView & bv) const +char MathCursor::halign(LCursor & cur) const { idx_type idx; - MathGridInset * p = enclosingGrid(bv, idx); + MathGridInset * p = enclosingGrid(cur, idx); return p ? p->halign(idx % p->ncols()) : '\0'; } -void MathCursor::getSelection(BufferView & bv, +void MathCursor::getSelection(LCursor & cur, CursorSlice & i1, CursorSlice & i2) const { - CursorSlice anc = normalAnchor(bv); - if (anc < bv.cursor()) { + CursorSlice anc = normalAnchor(cur); + if (anc < cur.top()) { i1 = anc; - i2 = bv.cursor(); + i2 = cur.top(); } else { - i1 = bv.cursor(); + i1 = cur.top(); i2 = anc; } } -bool MathCursor::goUpDown(BufferView & bv, bool up) +bool MathCursor::goUpDown(LCursor & cur, bool up) { // Be warned: The 'logic' implemented in this function is highly fragile. // A distance of one pixel or a '<' vs '<=' _really_ matters. // So fiddle around with it only if you know what you are doing! int xo = 0; int yo = 0; - getScreenPos(bv, xo, yo); + getScreenPos(cur, xo, yo); // check if we had something else in mind, if not, this is the future goal - if (bv.x_target() == -1) - bv.x_target(xo); + if (cur.bv().x_target() == -1) + cur.bv().x_target(xo); else - xo = bv.x_target(); + xo = cur.bv().x_target(); // try neigbouring script insets if (!selection()) { // try left - if (hasPrevAtom(bv)) { - MathScriptInset const * p = prevAtom(bv)->asScriptInset(); + if (hasPrevAtom(cur)) { + MathScriptInset const * p = prevAtom(cur)->asScriptInset(); if (p && p->has(up)) { - --bv.cursor().pos(); - push(bv, nextAtom(bv)); - bv.cursor().idx() = up; // the superscript has index 1 - bv.cursor().pos() = bv.cursor().lastpos(); + --cur.pos(); + push(cur, nextAtom(cur)); + cur.idx() = up; // the superscript has index 1 + cur.pos() = cur.lastpos(); //lyxerr << "updown: handled by scriptinset to the left" << endl; return true; } } // try right - if (hasNextAtom(bv)) { - MathScriptInset const * p = nextAtom(bv)->asScriptInset(); + if (hasNextAtom(cur)) { + MathScriptInset const * p = nextAtom(cur)->asScriptInset(); if (p && p->has(up)) { - push(bv, nextAtom(bv)); - bv.cursor().idx() = up; - bv.cursor().pos() = 0; + push(cur, nextAtom(cur)); + cur.idx() = up; + cur.pos() = 0; //lyxerr << "updown: handled by scriptinset to the right" << endl; return true; } @@ -969,7 +944,7 @@ bool MathCursor::goUpDown(BufferView & bv, bool up) } // try current cell for e.g. text insets - if (bv.cursor().inset()->asMathInset()->idxUpDown2(bv, up, bv.x_target())) + if (cur.inset()->asMathInset()->idxUpDown2(cur, up, cur.bv().x_target())) return true; //xarray().boundingBox(xlow, xhigh, ylow, yhigh); @@ -986,18 +961,18 @@ bool MathCursor::goUpDown(BufferView & bv, bool up) while (1) { //lyxerr << "updown: We are in " << inset() << " idx: " << idx() << endl; // ask inset first - if (bv.cursor().inset()->asMathInset()->idxUpDown(bv, up, bv.x_target())) { + if (cur.inset()->asMathInset()->idxUpDown(cur, up, cur.bv().x_target())) { // try to find best position within this inset if (!selection()) - bruteFind2(bv, xo, yo); + bruteFind2(cur, xo, yo); return true; } // no such inset found, just take something "above" //lyxerr << "updown: handled by strange case" << endl; - if (!popLeft(bv)) + if (!popLeft(cur)) return - bruteFind(bv, xo, yo, + bruteFind(cur, xo, yo, formula()->xlow(), formula()->xhigh(), up ? formula()->ylow() : yo + 4, @@ -1006,7 +981,7 @@ bool MathCursor::goUpDown(BufferView & bv, bool up) // any improvement so far? int xnew, ynew; - getScreenPos(bv, xnew, ynew); + getScreenPos(cur, xnew, ynew); if (up ? ynew < yo : ynew > yo) return true; } @@ -1014,7 +989,7 @@ bool MathCursor::goUpDown(BufferView & bv, bool up) bool MathCursor::bruteFind - (BufferView & bv, int x, int y, int xlow, int xhigh, int ylow, int yhigh) + (LCursor & cur, int x, int y, int xlow, int xhigh, int ylow, int yhigh) { CursorBase best_cursor; double best_dist = 1e10; @@ -1023,7 +998,7 @@ bool MathCursor::bruteFind CursorBase et = iend(formula()->par().nucleus()); while (1) { // avoid invalid nesting when selecting - if (!selection_ || positionable(it, bv.fullCursor().anchor_)) { + if (!selection_ || positionable(it, cur.anchor_)) { int xo, yo; it.back().getScreenPos(xo, yo); if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) { @@ -1044,18 +1019,18 @@ bool MathCursor::bruteFind } if (best_dist < 1e10) - bv.fullCursor().cursor_ = best_cursor; + cur.cursor_ = best_cursor; return best_dist < 1e10; } -void MathCursor::bruteFind2(BufferView & bv, int x, int y) +void MathCursor::bruteFind2(LCursor & cur, int x, int y) { double best_dist = 1e10; - CursorBase it = bv.fullCursor().cursor_; + CursorBase it = cur.cursor_; it.back().pos(0); - CursorBase et = bv.fullCursor().cursor_; + CursorBase et = cur.cursor_; int n = et.back().asMathInset()->cell(et.back().idx_).size(); et.back().pos(n); for (int i = 0; ; ++i) { @@ -1067,7 +1042,7 @@ void MathCursor::bruteFind2(BufferView & bv, int x, int y) lyxerr << "i: " << i << " d: " << d << " best: " << best_dist << endl; if (d <= best_dist) { best_dist = d; - bv.fullCursor().cursor_ = it; + cur.cursor_ = it; } if (it == et) break; @@ -1076,9 +1051,8 @@ void MathCursor::bruteFind2(BufferView & bv, int x, int y) } -bool MathCursor::idxLineLast(BufferView & bv) +bool MathCursor::idxLineLast(LCursor & cur) { - CursorSlice & cur = bv.cursor(); cur.idx() -= cur.idx() % cur.ncols(); cur.idx() += cur.ncols() - 1; cur.pos() = cur.lastpos(); @@ -1086,113 +1060,112 @@ bool MathCursor::idxLineLast(BufferView & bv) } -bool MathCursor::idxLeft(BufferView & bv) +bool MathCursor::idxLeft(LCursor & cur) { - return bv.cursor().inset()->asMathInset()->idxLeft(bv); + return cur.inset()->asMathInset()->idxLeft(cur); } -bool MathCursor::idxRight(BufferView & bv) +bool MathCursor::idxRight(LCursor & cur) { - return bv.cursor().inset()->asMathInset()->idxRight(bv); + return cur.inset()->asMathInset()->idxRight(cur); } -bool MathCursor::script(BufferView & bv, bool up) +bool MathCursor::script(LCursor & cur, bool up) { // Hack to get \\^ and \\_ working - if (inMacroMode(bv) && macroName(bv) == "\\") { + if (inMacroMode(cur) && macroName(cur) == "\\") { if (up) - niceInsert(bv, createMathInset("mathcircumflex")); + niceInsert(cur, createMathInset("mathcircumflex")); else - interpret(bv, '_'); + interpret(cur, '_'); return true; } - macroModeClose(bv); - string safe = grabAndEraseSelection(bv); - if (inNucleus(bv)) { + macroModeClose(cur); + string safe = grabAndEraseSelection(cur); + if (inNucleus(cur)) { // we are in a nucleus of a script inset, move to _our_ script - bv.cursor().inset()->asMathInset()->asScriptInset()->ensure(up); - bv.cursor().idx() = up; - bv.cursor().pos() = 0; - } else if (hasPrevAtom(bv) && prevAtom(bv)->asScriptInset()) { - prevAtom(bv).nucleus()->asScriptInset()->ensure(up); - pushRight(bv, prevAtom(bv)); - bv.cursor().idx() = up; - bv.cursor().pos() = bv.cursor().lastpos(); - } else if (hasPrevAtom(bv)) { - --bv.cursor().pos(); - bv.cursor().cell()[bv.cursor().pos()] - = MathAtom(new MathScriptInset(nextAtom(bv), up)); - pushLeft(bv, nextAtom(bv)); - bv.cursor().idx() = up; - bv.cursor().pos() = 0; + cur.inset()->asMathInset()->asScriptInset()->ensure(up); + cur.idx() = up; + cur.pos() = 0; + } else if (hasPrevAtom(cur) && prevAtom(cur)->asScriptInset()) { + prevAtom(cur).nucleus()->asScriptInset()->ensure(up); + pushRight(cur, prevAtom(cur)); + cur.idx() = up; + cur.pos() = cur.lastpos(); + } else if (hasPrevAtom(cur)) { + --cur.pos(); + cur.cell()[cur.pos()] + = MathAtom(new MathScriptInset(nextAtom(cur), up)); + pushLeft(cur, nextAtom(cur)); + cur.idx() = up; + cur.pos() = 0; } else { - plainInsert(bv, MathAtom(new MathScriptInset(up))); - prevAtom(bv).nucleus()->asScriptInset()->ensure(up); - pushRight(bv, prevAtom(bv)); - bv.cursor().idx() = up; - bv.cursor().pos() = 0; + plainInsert(cur, MathAtom(new MathScriptInset(up))); + prevAtom(cur).nucleus()->asScriptInset()->ensure(up); + pushRight(cur, prevAtom(cur)); + cur.idx() = up; + cur.pos() = 0; } - paste(bv, safe); + paste(cur, safe); dump("1"); return true; } -bool MathCursor::interpret(BufferView & bv, char c) +bool MathCursor::interpret(LCursor & cur, char c) { //lyxerr << "interpret 2: '" << c << "'" << endl; - CursorSlice & cur = bv.cursor(); - bv.x_target(-1); // "no target" - if (inMacroArgMode(bv)) { + cur.bv().x_target(-1); // "no target" + if (inMacroArgMode(cur)) { --cur.pos(); - plainErase(bv); + plainErase(cur); int n = c - '0'; MathMacroTemplate const * p = formula()->par()->asMacroTemplate(); if (p && 1 <= n && n <= p->numargs()) - insert(bv, MathAtom(new MathMacroArgument(c - '0'))); + insert(cur, MathAtom(new MathMacroArgument(c - '0'))); else { - insert(bv, createMathInset("#")); - interpret(bv, c); // try again + insert(cur, createMathInset("#")); + interpret(cur, c); // try again } return true; } // handle macroMode - if (inMacroMode(bv)) { - string name = macroName(bv); + if (inMacroMode(cur)) { + string name = macroName(cur); //lyxerr << "interpret name: '" << name << "'" << endl; if (isalpha(c)) { - activeMacro(bv)->setName(activeMacro(bv)->name() + c); + activeMacro(cur)->setName(activeMacro(cur)->name() + c); return true; } // handle 'special char' macros if (name == "\\") { // remove the '\\' - backspace(bv); + backspace(cur); if (c == '\\') { - if (currentMode(bv) == MathInset::TEXT_MODE) - niceInsert(bv, createMathInset("textbackslash")); + if (currentMode(cur) == MathInset::TEXT_MODE) + niceInsert(cur, createMathInset("textbackslash")); else - niceInsert(bv, createMathInset("backslash")); + niceInsert(cur, createMathInset("backslash")); } else if (c == '{') { - niceInsert(bv, MathAtom(new MathBraceInset)); + niceInsert(cur, MathAtom(new MathBraceInset)); } else { - niceInsert(bv, createMathInset(string(1, c))); + niceInsert(cur, createMathInset(string(1, c))); } return true; } // leave macro mode and try again if necessary - macroModeClose(bv); + macroModeClose(cur); if (c == '{') - niceInsert(bv, MathAtom(new MathBraceInset)); + niceInsert(cur, MathAtom(new MathBraceInset)); else if (c != ' ') - interpret(bv, c); + interpret(cur, c); return true; } @@ -1213,57 +1186,57 @@ bool MathCursor::interpret(BufferView & bv, char c) return true; } - selClearOrDel(bv); + selClearOrDel(cur); if (c == '\\') { //lyxerr << "starting with macro" << endl; - insert(bv, MathAtom(new MathUnknownInset("\\", false))); + insert(cur, MathAtom(new MathUnknownInset("\\", false))); return true; } if (c == '\n') { - if (currentMode(bv) == MathInset::TEXT_MODE) - insert(bv, c); + if (currentMode(cur) == MathInset::TEXT_MODE) + insert(cur, c); return true; } if (c == ' ') { - if (currentMode(bv) == MathInset::TEXT_MODE) { + if (currentMode(cur) == MathInset::TEXT_MODE) { // insert spaces in text mode, // but suppress direct insertion of two spaces in a row // the still allows typing 'a' and deleting the 'a', but // it is better than nothing... - if (!hasPrevAtom(bv) || prevAtom(bv)->getChar() != ' ') - insert(bv, c); + if (!hasPrevAtom(cur) || prevAtom(cur)->getChar() != ' ') + insert(cur, c); return true; } - if (hasPrevAtom(bv) && prevAtom(bv)->asSpaceInset()) { - prevAtom(bv).nucleus()->asSpaceInset()->incSpace(); + if (hasPrevAtom(cur) && prevAtom(cur)->asSpaceInset()) { + prevAtom(cur).nucleus()->asSpaceInset()->incSpace(); return true; } - if (popRight(bv)) + if (popRight(cur)) return true; // if are at the very end, leave the formula return cur.pos() != cur.lastpos(); } if (c == '_') { - script(bv, false); + script(cur, false); return true; } if (c == '^') { - script(bv, true); + script(cur, true); return true; } if (c == '{' || c == '}' || c == '#' || c == '&' || c == '$') { - niceInsert(bv, createMathInset(string(1, c))); + niceInsert(cur, createMathInset(string(1, c))); return true; } if (c == '%') { - niceInsert(bv, MathAtom(new MathCommentInset)); + niceInsert(cur, MathAtom(new MathCommentInset)); return true; } @@ -1272,58 +1245,50 @@ bool MathCursor::interpret(BufferView & bv, char c) // return true; // no special circumstances, so insert the character without any fuss - insert(bv, c); + insert(cur, c); autocorrect_ = true; return true; } void MathCursor::setSelection - (BufferView & bv, CursorBase const & where, size_t n) + (LCursor & cur, CursorBase const & where, size_t n) { selection_ = true; - bv.fullCursor().cursor_ = where; - bv.fullCursor().anchor_ = where; - bv.cursor().pos_ += n; + cur.cursor_ = where; + cur.anchor_ = where; + cur.pos() += n; } -void MathCursor::insetToggle(BufferView & bv) +void MathCursor::insetToggle(LCursor & cur) { - if (hasNextAtom(bv)) { + if (hasNextAtom(cur)) { // toggle previous inset ... - nextAtom(bv).nucleus()->lock(!nextAtom(bv)->lock()); - } else if (popLeft(bv) && hasNextAtom(bv)) { + nextAtom(cur).nucleus()->lock(!nextAtom(cur)->lock()); + } else if (popLeft(cur) && hasNextAtom(cur)) { // ... or enclosing inset if we are in the last inset position - nextAtom(bv).nucleus()->lock(!nextAtom(bv)->lock()); - posRight(bv); + nextAtom(cur).nucleus()->lock(!nextAtom(cur)->lock()); + posRight(cur); } } -string MathCursor::info(BufferView & bv) const +string MathCursor::info(LCursor & cur) const { ostringstream os; os << "Math editor mode. "; - for (int i = 0, n = depth(bv); i < n; ++i) { - bv.fullCursor().cursor_[i].asMathInset()->infoize(os); + for (int i = 0, n = cur.depth(); i < n; ++i) { + cur.cursor_[i].asMathInset()->infoize(os); os << " "; } - if (hasPrevAtom(bv)) - prevAtom(bv)->infoize2(os); + if (hasPrevAtom(cur)) + prevAtom(cur)->infoize2(os); os << " "; return os.str(); } -unsigned MathCursor::depth(BufferView & bv) const -{ - return bv.fullCursor().cursor_.size(); -} - - - - namespace { void region(CursorSlice const & i1, CursorSlice const & i2, @@ -1344,14 +1309,14 @@ void region(CursorSlice const & i1, CursorSlice const & i2, } -string MathCursor::grabSelection(BufferView & bv) const +string MathCursor::grabSelection(LCursor & cur) const { if (!selection_) return string(); CursorSlice i1; CursorSlice i2; - getSelection(bv, i1, i2); + getSelection(cur, i1, i2); if (i1.idx_ == i2.idx_) { MathArray::const_iterator it = i1.cell().begin(); @@ -1376,11 +1341,11 @@ string MathCursor::grabSelection(BufferView & bv) const } -void MathCursor::eraseSelection(BufferView & bv) +void MathCursor::eraseSelection(LCursor & cur) { CursorSlice i1; CursorSlice i2; - getSelection(bv, i1, i2); + getSelection(cur, i1, i2); if (i1.idx_ == i2.idx_) i1.cell().erase(i1.pos_, i2.pos_); else { @@ -1392,44 +1357,44 @@ void MathCursor::eraseSelection(BufferView & bv) for (col_type col = c1; col <= c2; ++col) p->cell(p->index(row, col)).clear(); } - bv.cursor() = i1; + cur.top() = i1; } -string MathCursor::grabAndEraseSelection(BufferView & bv) +string MathCursor::grabAndEraseSelection(LCursor & cur) { if (!selection_) return string(); - string res = grabSelection(bv); - eraseSelection(bv); + string res = grabSelection(cur); + eraseSelection(cur); selection_ = false; return res; } -CursorSlice MathCursor::normalAnchor(BufferView & bv) const +CursorSlice MathCursor::normalAnchor(LCursor & cur) const { #warning FIXME #if 0 - if (Anchor_.size() < depth()) { - bv.resetAnchor(); + if (Anchor_.size() < cur.depth()) { + cur.resetAnchor(); lyxerr << "unusual Anchor size" << endl; } - //lyx::BOOST_ASSERT(Anchor_.size() >= cursor.depth()); + //lyx::BOOST_ASSERT(Anchor_.size() >= cursor.cur.depth()); // use Anchor on the same level as Cursor - CursorSlice normal = Anchor_[depth() - 1]; - if (depth() < Anchor_.size() && !(normal < cursor())) { + CursorSlice normal = Anchor_[cur.depth() - 1]; + if (cur.depth() < Anchor_.size() && !(normal < cursor())) { // anchor is behind cursor -> move anchor behind the inset ++normal.pos_; } return normal; #else - return bv.cursor(); + return cur.top(); #endif } -DispatchResult MathCursor::dispatch(BufferView &, FuncRequest const & cmd) +DispatchResult MathCursor::dispatch(LCursor &, FuncRequest const & cmd) { // mouse clicks are somewhat special // check @@ -1445,13 +1410,13 @@ DispatchResult MathCursor::dispatch(BufferView &, FuncRequest const & cmd) getScreenPos(x, y); if (x < cmd.x && hasPrevAtom()) { DispatchResult const res = - prevAtom().nucleus()->dispatch(bv, cmd); + prevAtom().nucleus()->dispatch(cur, cmd); if (res.dispatched()) return res; } if (x > cmd.x && hasNextAtom()) { DispatchResult const res = - nextAtom().nucleus()->dispatch(bv, cmd); + nextAtom().nucleus()->dispatch(cur, cmd); if (res.dispatched()) return res; } @@ -1462,10 +1427,10 @@ DispatchResult MathCursor::dispatch(BufferView &, FuncRequest const & cmd) } /* - for (int i = Cursor_.size() - 1; i >= 0; --i) { - CursorBase tmp = bv->Cursor_; + for (int i = cur.depth() - 1; i >= 0; --i) { + CursorBase tmp = cur->cursor_; CursorSlice & pos = tmp.back() - DispatchResult const res = pos.asMathInset()->dispatch(bv, cmd); + DispatchResult const res = pos.asMathInset()->dispatch(cur, cmd); if (res.dispatched()) { if (res.val() == FINISHED) { if (i + 1 < Cursor_.size()) @@ -1480,7 +1445,7 @@ DispatchResult MathCursor::dispatch(BufferView &, FuncRequest const & cmd) } -MathInset::mode_type MathCursor::currentMode(BufferView &) const +MathInset::mode_type MathCursor::currentMode(LCursor &) const { #if 0 for (int i = Cursor_.size() - 1; i >= 0; --i) { @@ -1493,38 +1458,37 @@ MathInset::mode_type MathCursor::currentMode(BufferView &) const } -void MathCursor::handleFont(BufferView & bv, string const & font) +void MathCursor::handleFont(LCursor & cur, string const & font) { - CursorSlice cur = cursorTip(bv); string safe; if (selection()) { - macroModeClose(bv); - safe = grabAndEraseSelection(bv); + macroModeClose(cur); + safe = grabAndEraseSelection(cur); } if (cur.lastpos() != 0) { // something left in the cell if (cur.pos() == 0) { // cursor in first position - popLeft(bv); + popLeft(cur); } else if (cur.pos() == cur.lastpos()) { // cursor in last position - popRight(bv); + popRight(cur); } else { // cursor in between. split cell MathArray::iterator bt = cur.cell().begin(); MathAtom at = createMathInset(font); at.nucleus()->cell(0) = MathArray(bt, bt + cur.pos()); cur.cell().erase(bt, bt + cur.pos()); - popLeft(bv); - plainInsert(bv, at); + popLeft(cur); + plainInsert(cur, at); } } else { // nothing left in the cell - pullArg(bv); - plainErase(bv); + pullArg(cur); + plainErase(cur); } - insert(bv, safe); + insert(cur, safe); } diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index 7e4994de4c..94c851a633 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -56,207 +56,207 @@ public: /// ~MathCursor(); /// - void insert(BufferView & bv, MathAtom const &); + void insert(LCursor & cur, MathAtom const &); /// - void insert(BufferView & bv, MathArray const &); + void insert(LCursor & cur, MathArray const &); /// - void insert2(BufferView & bv, std::string const &); + void insert2(LCursor & cur, std::string const &); /// - void paste(BufferView & bv, std::string const & data); + void paste(LCursor & cur, std::string const & data); /// return false for empty math insets - bool erase(BufferView & bv); + bool erase(LCursor & cur); /// return false for empty math insets - bool backspace(BufferView & bv); + bool backspace(LCursor & cur); /// called for LFUN_HOME etc - bool home(BufferView & bv, bool sel = false); + bool home(LCursor & cur, bool sel = false); /// called for LFUN_END etc - bool end(BufferView & bv, bool sel = false); + bool end(LCursor & cur, bool sel = false); /// called for LFUN_RIGHT and LFUN_RIGHTSEL - bool right(BufferView & bv, bool sel = false); + bool right(LCursor & cur, bool sel = false); /// called for LFUN_LEFT etc - bool left(BufferView & bv, bool sel = false); + bool left(LCursor & cur, bool sel = false); /// called for LFUN_UP etc - bool up(BufferView & bv, bool sel = false); + bool up(LCursor & cur, bool sel = false); /// called for LFUN_DOWN etc - bool down(BufferView & bv, bool sel = false); + bool down(LCursor & cur, bool sel = false); /// Put the cursor in the first position - void first(BufferView & bv); + void first(LCursor & cur); /// Put the cursor in the last position - void last(BufferView & bv); + void last(LCursor & cur); /// move to next cell in current inset - void idxNext(BufferView & bv); + void idxNext(LCursor & bv); /// move to previous cell in current inset - void idxPrev(BufferView & bv); + void idxPrev(LCursor & bv); /// - void plainErase(BufferView & bv); + void plainErase(LCursor & cur); /// - void plainInsert(BufferView & bv, MathAtom const & at); + void plainInsert(LCursor & cur, MathAtom const & at); /// - void niceInsert(BufferView & bv, MathAtom const & at); + void niceInsert(LCursor & cur, MathAtom const & at); /// - void niceInsert(BufferView & bv, std::string const & str); + void niceInsert(LCursor & cur, std::string const & str); /// in pixels from top of screen - void setScreenPos(BufferView & bv, int x, int y); + void setScreenPos(LCursor & cur, int x, int y); /// in pixels from top of screen - void getScreenPos(BufferView & bv, int & x, int & y) const; + void getScreenPos(LCursor & cur, int & x, int & y) const; /// in pixels from left of screen - int targetX(BufferView & bv) const; + int targetX(LCursor & cur) const; /// return the next enclosing grid inset and the cursor's index in it - MathGridInset * enclosingGrid(BufferView & bv, idx_type & idx) const; + MathGridInset * enclosingGrid(LCursor & cur, idx_type & idx) const; /// go up to enclosing grid - void popToEnclosingGrid(BufferView & bv); + void popToEnclosingGrid(LCursor & cur); /// go up to the hull inset - void popToEnclosingHull(BufferView & bv); + void popToEnclosingHull(LCursor & cur); /// go up to the hull inset - void popToHere(BufferView & bv, MathInset const * p); + void popToHere(LCursor & cur, MathInset const * p); /// adjust anchor position after deletions/insertions - void adjust(BufferView & bv, pos_type from, difference_type diff); + void adjust(LCursor & cur, pos_type from, difference_type diff); /// InsetFormulaBase * formula() const; /// current offset in the current cell /// - bool script(BufferView & bv, bool); + bool script(LCursor & cur, bool); /// - bool interpret(BufferView & bv, char); + bool interpret(LCursor & cur, char); /// interpret name a name of a macro - void macroModeClose(BufferView & bv); + void macroModeClose(LCursor & cur); /// are we currently typing the name of a macro? - bool inMacroMode(BufferView & bv) const; + bool inMacroMode(LCursor & cur) const; /// get access to the macro we are currently typing - MathUnknownInset * activeMacro(BufferView & bv); + MathUnknownInset * activeMacro(LCursor & cur); /// get access to the macro we are currently typing - MathUnknownInset const * activeMacro(BufferView & bv) const; + MathUnknownInset const * activeMacro(LCursor & cur) const; /// are we currently typing '#1' or '#2' or...? - bool inMacroArgMode(BufferView & bv) const; + bool inMacroArgMode(LCursor & cur) const; /// are we in math mode (1), text mode (-1) or unsure? - MathInset::mode_type currentMode(BufferView & bv) const; + MathInset::mode_type currentMode(LCursor & cur) const; // Local selection methods /// bool selection() const; /// - void selCopy(BufferView & bv); + void selCopy(LCursor & cur); /// - void selCut(BufferView & bv); + void selCut(LCursor & cur); /// - void selDel(BufferView & bv); + void selDel(LCursor & cur); /// pastes n-th element of cut buffer - void selPaste(BufferView & bv, size_t n); + void selPaste(LCursor & cur, size_t n); /// - void selHandle(BufferView & bv, bool); + void selHandle(LCursor & cur, bool); /// - void selStart(BufferView & bv); + void selStart(LCursor & cur); /// - void selClear(BufferView & bv); + void selClear(LCursor & cur); /// clears or deletes selection depending on lyxrc setting - void selClearOrDel(BufferView & bv); + void selClearOrDel(LCursor & cur); /// draws light-blue selection background void drawSelection(PainterInfo & pi) const; /// replace selected stuff with at, placing the former // selection in given cell of atom - void handleNest(BufferView & bv, MathAtom const & at, int cell = 0); + void handleNest(LCursor & cur, MathAtom const & at, int cell = 0); /// remove this as soon as LyXFunc::getStatus is "localized" std::string getLastCode() const { return "mathnormal"; } /// bool isInside(MathInset const *) const; /// - char valign(BufferView & bv) const; + char valign(LCursor & cur) const; /// - char halign(BufferView & bv) const; + char halign(LCursor & cur) const; /// make sure cursor position is valid - void normalize(BufferView & bv); + void normalize(LCursor & cur); /// mark current cursor trace for redraw void touch(); /// enter a MathInset - void push(BufferView & bv, MathAtom & par); + void push(LCursor & cur, MathAtom & par); /// enter a MathInset from the front - void pushLeft(BufferView & bv, MathAtom & par); + void pushLeft(LCursor & cur, MathAtom & par); /// enter a MathInset from the back - void pushRight(BufferView & bv, MathAtom & par); + void pushRight(LCursor & cur, MathAtom & par); /// leave current MathInset to the left - bool popLeft(BufferView & bv); + bool popLeft(LCursor & cur); /// leave current MathInset to the left - bool popRight(BufferView & bv); + bool popRight(LCursor & cur); /// - bool hasPrevAtom(BufferView & bv) const; + bool hasPrevAtom(LCursor & cur) const; /// - bool hasNextAtom(BufferView & bv) const; + bool hasNextAtom(LCursor & cur) const; /// - MathAtom const & prevAtom(BufferView & bv) const; + MathAtom const & prevAtom(LCursor & cur) const; /// - MathAtom & prevAtom(BufferView & bv); + MathAtom & prevAtom(LCursor & cur); /// - MathAtom const & nextAtom(BufferView & bv) const; + MathAtom const & nextAtom(LCursor & cur) const; /// - MathAtom & nextAtom(BufferView & bv); + MathAtom & nextAtom(LCursor & cur); /// returns the selection - void getSelection(BufferView & bv, CursorSlice &, CursorSlice &) const; + void getSelection(LCursor & cur, CursorSlice &, CursorSlice &) const; /// returns the normalized anchor of the selection - CursorSlice normalAnchor(BufferView & bv) const; + CursorSlice normalAnchor(LCursor & cur) const; /// how deep are we nested? - unsigned depth(BufferView & bv) const; + unsigned depth(LCursor & cur) const; /// describe the situation - std::string info(BufferView & bv) const; + std::string info(LCursor & cur) const; /// dump selection information for debugging void seldump(char const * str) const; /// dump selection information for debugging void dump(char const * str) const; /// moves on - void setSelection(BufferView & bv, CursorBase const & where, size_type n); + void setSelection(LCursor & cur, CursorBase const & where, size_type n); /// grab selection marked by anchor and current cursor - std::string grabSelection(BufferView & bv) const; + std::string grabSelection(LCursor & cur) const; /// guess what - std::string grabAndEraseSelection(BufferView & bv); + std::string grabAndEraseSelection(LCursor & cur); /// - void insert(BufferView & bv, char c); + void insert(LCursor & cur, char c); /// - void insert(BufferView & bv, std::string const & str); + void insert(LCursor & cur, std::string const & str); /// lock/unlock inset - void insetToggle(BufferView & bv); + void insetToggle(LCursor & cur); /// hack for reveal codes - void markInsert(BufferView & bv); - void markErase(BufferView & bv); + void markInsert(LCursor & cur); + void markErase(LCursor & cur); /// injects content of a cell into parent - void pullArg(BufferView & bv); + void pullArg(LCursor & cur); /// split font inset etc - void handleFont(BufferView & bv, std::string const & font); + void handleFont(LCursor & cur, std::string const & font); /// - DispatchResult dispatch(BufferView & bv, FuncRequest const & cmd); + DispatchResult dispatch(LCursor & cur, FuncRequest const & cmd); private: /// moves cursor index one cell to the left - bool idxLeft(BufferView & bv); + bool idxLeft(LCursor & bv); /// moves cursor index one cell to the right - bool idxRight(BufferView & bv); + bool idxRight(LCursor & bv); /// moves cursor to end of last cell of current line - bool idxLineLast(BufferView & bv); + bool idxLineLast(LCursor & bv); /// moves cursor position one cell to the left - bool posLeft(BufferView & bv); + bool posLeft(LCursor & cur); /// moves cursor position one cell to the right - bool posRight(BufferView & bv); + bool posRight(LCursor & cur); /// moves position somehow up or down - bool goUpDown(BufferView & bv, bool up); + bool goUpDown(LCursor & cur, bool up); /// moves position closest to (x, y) in given box - bool bruteFind(BufferView & bv, + bool bruteFind(LCursor & cur, int x, int y, int xlow, int xhigh, int ylow, int yhigh); /// moves position closest to (x, y) in current cell - void bruteFind2(BufferView & bv, int x, int y); + void bruteFind2(LCursor & cur, int x, int y); /// are we in a nucleus of a script inset? - bool inNucleus(BufferView & bv) const; + bool inNucleus(LCursor & cur) const; /// erase the selected part and re-sets the cursor - void eraseSelection(BufferView & bv); + void eraseSelection(LCursor & cur); /// the name of the macro we are currently inputting - std::string macroName(BufferView & bv) const; + std::string macroName(LCursor & cur) const; /// where in the curent cell does the macro name start? - difference_type macroNamePos(BufferView & bv) const; + difference_type macroNamePos(LCursor & cur) const; /// can we enter the inset? bool openable(MathAtom const &, bool selection) const; diff --git a/src/mathed/math_fracbase.C b/src/mathed/math_fracbase.C index ecc16c71d7..53c8805990 100644 --- a/src/mathed/math_fracbase.C +++ b/src/mathed/math_fracbase.C @@ -19,21 +19,20 @@ MathFracbaseInset::MathFracbaseInset() {} -bool MathFracbaseInset::idxRight(BufferView &) const +bool MathFracbaseInset::idxRight(LCursor &) const { return false; } -bool MathFracbaseInset::idxLeft(BufferView &) const +bool MathFracbaseInset::idxLeft(LCursor &) const { return false; } -bool MathFracbaseInset::idxUpDown(BufferView & bv, bool up, int targetx) const +bool MathFracbaseInset::idxUpDown(LCursor & cur, bool up, int targetx) const { - CursorSlice & cur = cursorTip(bv); MathInset::idx_type target = !up; // up ? 0 : 1, since upper cell has idx 0 if (cur.idx() == target) return false; diff --git a/src/mathed/math_fracbase.h b/src/mathed/math_fracbase.h index 3e4549b9f1..03558bae28 100644 --- a/src/mathed/math_fracbase.h +++ b/src/mathed/math_fracbase.h @@ -20,11 +20,11 @@ public: /// MathFracbaseInset(); /// - bool idxUpDown(BufferView &, bool up, int targetx) const; + bool idxUpDown(LCursor &, bool up, int targetx) const; /// - bool idxLeft(BufferView &) const; + bool idxLeft(LCursor &) const; /// - bool idxRight(BufferView &) const; + bool idxRight(LCursor &) const; }; #endif diff --git a/src/mathed/math_gridinset.C b/src/mathed/math_gridinset.C index 77e3badbc6..1384d1e399 100644 --- a/src/mathed/math_gridinset.C +++ b/src/mathed/math_gridinset.C @@ -14,11 +14,14 @@ #include "math_data.h" #include "math_mathmlstream.h" #include "math_streamstr.h" +#include "BufferView.h" #include "dispatchresult.h" #include "debug.h" #include "funcrequest.h" #include "LColor.h" + #include "frontends/Painter.h" + #include "support/std_sstream.h" #include "insets/mailinset.h" @@ -751,9 +754,8 @@ int MathGridInset::cellYOffset(idx_type idx) const } -bool MathGridInset::idxUpDown(BufferView & bv, bool up, int targetx) const +bool MathGridInset::idxUpDown(LCursor & cur, bool up, int targetx) const { - CursorSlice & cur = cursorTip(bv); if (up) { if (cur.idx() < ncols()) return false; @@ -768,10 +770,9 @@ bool MathGridInset::idxUpDown(BufferView & bv, bool up, int targetx) const } -bool MathGridInset::idxLeft(BufferView & bv) const +bool MathGridInset::idxLeft(LCursor & cur) const { // leave matrix if on the left hand edge - CursorSlice & cur = cursorTip(bv); if (cur.col() == 0) return false; --cur.idx(); @@ -780,10 +781,9 @@ bool MathGridInset::idxLeft(BufferView & bv) const } -bool MathGridInset::idxRight(BufferView & bv) const +bool MathGridInset::idxRight(LCursor & cur) const { // leave matrix if on the right hand edge - CursorSlice & cur = cursorTip(bv); if (cur.col() + 1 == ncols()) return false; ++cur.idx(); @@ -792,9 +792,8 @@ bool MathGridInset::idxRight(BufferView & bv) const } -bool MathGridInset::idxFirst(BufferView & bv) const +bool MathGridInset::idxFirst(LCursor & cur) const { - CursorSlice & cur = cursorTip(bv); switch (v_align_) { case 't': cur.idx() = 0; @@ -810,9 +809,8 @@ bool MathGridInset::idxFirst(BufferView & bv) const } -bool MathGridInset::idxLast(BufferView & bv) const +bool MathGridInset::idxLast(LCursor & cur) const { - CursorSlice & cur = cursorTip(bv); switch (v_align_) { case 't': cur.idx() = ncols() - 1; @@ -828,9 +826,8 @@ bool MathGridInset::idxLast(BufferView & bv) const } -bool MathGridInset::idxHome(BufferView & bv) const +bool MathGridInset::idxHome(LCursor & cur) const { - CursorSlice & cur = cursorTip(bv); if (cur.pos() > 0) { cur.pos() = 0; return true; @@ -849,9 +846,8 @@ bool MathGridInset::idxHome(BufferView & bv) const } -bool MathGridInset::idxEnd(BufferView & bv) const +bool MathGridInset::idxEnd(LCursor & cur) const { - CursorSlice & cur = cursorTip(bv); if (cur.pos() < cur.lastpos()) { cur.pos() = cur.lastpos(); return true; @@ -1033,9 +1029,8 @@ int MathGridInset::border() const } -void MathGridInset::splitCell(BufferView & bv) +void MathGridInset::splitCell(LCursor & cur) { - CursorSlice & cur = cursorTip(bv); if (cur.idx() + 1 == nargs()) return; MathArray ar = cur.cell(); @@ -1050,7 +1045,7 @@ void MathGridInset::splitCell(BufferView & bv) DispatchResult MathGridInset::priv_dispatch(BufferView & bv, FuncRequest const & cmd) { - CursorSlice & cur = cursorTip(bv); + LCursor & cur = bv.fullCursor(); switch (cmd.action) { case LFUN_MOUSE_RELEASE: @@ -1082,7 +1077,7 @@ MathGridInset::priv_dispatch(BufferView & bv, FuncRequest const & cmd) case LFUN_CELL_SPLIT: //recordUndo(bv, Undo::ATOMIC); - splitCell(bv); + splitCell(cur); return DispatchResult(true, FINISHED); case LFUN_BREAKLINE: { @@ -1095,7 +1090,7 @@ MathGridInset::priv_dispatch(BufferView & bv, FuncRequest const & cmd) std::swap(cell(index(r, c)), cell(index(r + 1, c))); // split cell - splitCell(bv); + splitCell(cur); std::swap(cell(cur.idx()), cell(cur.idx() + ncols() - 1)); if (cur.idx() > 0) --cur.idx(); diff --git a/src/mathed/math_gridinset.h b/src/mathed/math_gridinset.h index 37ff4a289b..648fc7a588 100644 --- a/src/mathed/math_gridinset.h +++ b/src/mathed/math_gridinset.h @@ -145,19 +145,19 @@ public: row_type row(idx_type idx) const; /// - bool idxUpDown(BufferView &, bool up, int targetx) const; + bool idxUpDown(LCursor &, bool up, int targetx) const; /// - bool idxLeft(BufferView &) const; + bool idxLeft(LCursor &) const; /// - bool idxRight(BufferView &) const; + bool idxRight(LCursor &) const; /// - bool idxFirst(BufferView &) const; + bool idxFirst(LCursor &) const; /// - bool idxLast(BufferView &) const; + bool idxLast(LCursor &) const; /// - bool idxHome(BufferView &) const; + bool idxHome(LCursor &) const; /// - bool idxEnd(BufferView &) const; + bool idxEnd(LCursor &) const; /// bool idxDelete(idx_type & idx); /// pulls cell after pressing erase @@ -216,10 +216,7 @@ public: protected: /// - virtual - DispatchResult - priv_dispatch(BufferView & bv, FuncRequest const & cmd); - + DispatchResult priv_dispatch(BufferView & bv, FuncRequest const & cmd); /// returns x offset of cell compared to inset int cellXOffset(idx_type idx) const; /// returns y offset of cell compared to inset @@ -231,7 +228,7 @@ protected: /// extract number of columns from alignment string col_type guessColumns(std::string const & halign) const; /// splits cells and shifts right part to the next cell - void splitCell(BufferView & pos); + void splitCell(LCursor & cur); public: /// row info diff --git a/src/mathed/math_hullinset.C b/src/mathed/math_hullinset.C index 4926e1456e..c18072ee95 100644 --- a/src/mathed/math_hullinset.C +++ b/src/mathed/math_hullinset.C @@ -18,6 +18,7 @@ #include "math_extern.h" #include "math_charinset.h" #include "textpainter.h" +#include "BufferView.h" #include "dispatchresult.h" #include "debug.h" #include "funcrequest.h" @@ -135,18 +136,16 @@ MathInset::mode_type MathHullInset::currentMode() const } -bool MathHullInset::idxFirst(BufferView & bv) const +bool MathHullInset::idxFirst(LCursor & cur) const { - CursorSlice & cur = cursorTip(bv); cur.idx() = 0; cur.pos() = 0; return true; } -bool MathHullInset::idxLast(BufferView & bv) const +bool MathHullInset::idxLast(LCursor & cur) const { - CursorSlice & cur = cursorTip(bv); cur.idx() = nargs() - 1; cur.pos() = cur.lastpos(); return true; @@ -696,9 +695,8 @@ void MathHullInset::check() const } -void MathHullInset::doExtern(FuncRequest const & func, BufferView & bv) +void MathHullInset::doExtern(LCursor & cur, FuncRequest const & func) { - CursorSlice & cur = cursorTip(bv); string lang; string extra; istringstream iss(func.argument.c_str()); @@ -728,7 +726,7 @@ void MathHullInset::doExtern(FuncRequest const & func, BufferView & bv) size_type pos = cur.cell().find_last(eq); MathArray ar; if (mathcursor && mathcursor->selection()) { - asArray(mathcursor->grabAndEraseSelection(bv), ar); + asArray(mathcursor->grabAndEraseSelection(cur), ar); } else if (pos == cur.cell().size()) { ar = cur.cell(); lyxerr << "use whole cell: " << ar << endl; @@ -841,7 +839,7 @@ MathHullInset::priv_dispatch(BufferView & bv, FuncRequest const & cmd) } case LFUN_MATH_EXTERN: - doExtern(cmd, bv); + doExtern(bv.fullCursor(), cmd); return DispatchResult(true, FINISHED); case LFUN_MATH_MUTATE: { diff --git a/src/mathed/math_hullinset.h b/src/mathed/math_hullinset.h index 2c19c15b74..0885bf6f1d 100644 --- a/src/mathed/math_hullinset.h +++ b/src/mathed/math_hullinset.h @@ -81,9 +81,9 @@ public: /// char defaultColAlign(col_type col); /// - bool idxFirst(BufferView &) const; + bool idxFirst(LCursor &) const; /// - bool idxLast(BufferView &) const; + bool idxLast(LCursor &) const; /// std::string fileInsetLabel() const; @@ -116,7 +116,7 @@ private: /// std::string nicelabel(row_type row) const; /// - void doExtern(FuncRequest const & func, BufferView &); + void doExtern(LCursor & cur, FuncRequest const & func); /// void glueall(); /// diff --git a/src/mathed/math_inset.C b/src/mathed/math_inset.C index fd56951bbc..33f2119d50 100644 --- a/src/mathed/math_inset.C +++ b/src/mathed/math_inset.C @@ -56,61 +56,61 @@ void MathInset::substitute(MathMacro const &) {} -bool MathInset::idxNext(BufferView &) const +bool MathInset::idxNext(LCursor &) const { return false; } -bool MathInset::idxRight(BufferView &) const +bool MathInset::idxRight(LCursor &) const { return false; } -bool MathInset::idxPrev(BufferView &) const +bool MathInset::idxPrev(LCursor &) const { return false; } -bool MathInset::idxLeft(BufferView &) const +bool MathInset::idxLeft(LCursor &) const { return false; } -bool MathInset::idxUpDown(BufferView &, bool, int) const +bool MathInset::idxUpDown(LCursor &, bool, int) const { return false; } -bool MathInset::idxUpDown2(BufferView &, bool, int) const +bool MathInset::idxUpDown2(LCursor &, bool, int) const { return false; } -bool MathInset::idxFirst(BufferView &) const +bool MathInset::idxFirst(LCursor &) const { return false; } -bool MathInset::idxLast(BufferView &) const +bool MathInset::idxLast(LCursor &) const { return false; } -bool MathInset::idxHome(BufferView &) const +bool MathInset::idxHome(LCursor &) const { return false; } -bool MathInset::idxEnd(BufferView &) const +bool MathInset::idxEnd(LCursor &) const { return false; } diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index 2503ca5228..25d77e9a3c 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -13,7 +13,7 @@ #ifndef MATH_INSET_H #define MATH_INSET_H -#include "cursor_slice.h" +#include "cursor.h" #include "insets/insetbase.h" #include @@ -64,13 +64,10 @@ class MathMLStream; class WriteStream; class InfoStream; -class BufferView; -class UpdatableInset; class MathMacroTemplate; class MathMacro; class MathPosFinder; class Dimension; -class FuncRequest; class TextPainter; class TextMetricsInfo; class ReplaceData; @@ -95,28 +92,28 @@ public: virtual void drawT(TextPainter &, int x, int y) const; /// Where should we go when we press the up or down cursor key? - virtual bool idxUpDown(BufferView & bv, bool up, int targetx) const; + virtual bool idxUpDown(LCursor & cur, bool up, int targetx) const; /// Where should we go when we press the up or down cursor key? - virtual bool idxUpDown2(BufferView & bv, bool up, int targetx) const; + virtual bool idxUpDown2(LCursor & cur, bool up, int targetx) const; /// The left key - virtual bool idxLeft(BufferView & bv) const; + virtual bool idxLeft(LCursor & cur) const; /// The right key - virtual bool idxRight(BufferView & bv) const; + virtual bool idxRight(LCursor & cur) const; /// Move one physical cell up - virtual bool idxNext(BufferView & bv) const; + virtual bool idxNext(LCursor & cur) const; /// Move one physical cell down - virtual bool idxPrev(BufferView & bv) const; + virtual bool idxPrev(LCursor & cur) const; /// Target pos when we enter the inset from the left by pressing "Right" - virtual bool idxFirst(BufferView & bv) const; + virtual bool idxFirst(LCursor & cur) const; /// Target pos when we enter the inset from the right by pressing "Left" - virtual bool idxLast(BufferView & bv) const; + virtual bool idxLast(LCursor & cur) const; /// Where should we go if we press home? - virtual bool idxHome(BufferView & bv) const; + virtual bool idxHome(LCursor & cur) const; /// Where should we go if we press end? - virtual bool idxEnd(BufferView & bv) const; + virtual bool idxEnd(LCursor & cur) const; /// Delete a cell and move cursor virtual bool idxDelete(idx_type &) { return false; } diff --git a/src/mathed/math_macro.C b/src/mathed/math_macro.C index 30e32bc52a..0092dd52e0 100644 --- a/src/mathed/math_macro.C +++ b/src/mathed/math_macro.C @@ -155,14 +155,13 @@ void MathMacro::dump() const } -bool MathMacro::idxUpDown(BufferView & bv, bool up, int x) const +bool MathMacro::idxUpDown(LCursor & cur, bool up, int x) const { - CursorSlice & cur = cursorTip(bv); if (up) { - if (!MathNestInset::idxLeft(bv)) + if (!MathNestInset::idxLeft(cur)) return false; } else { - if (!MathNestInset::idxRight(bv)) + if (!MathNestInset::idxRight(cur)) return false; } cur.pos() = cur.cell().x2pos(x); @@ -170,13 +169,13 @@ bool MathMacro::idxUpDown(BufferView & bv, bool up, int x) const } -bool MathMacro::idxLeft(BufferView &) const +bool MathMacro::idxLeft(LCursor &) const { return false; } -bool MathMacro::idxRight(BufferView &) const +bool MathMacro::idxRight(LCursor &) const { return false; } diff --git a/src/mathed/math_macro.h b/src/mathed/math_macro.h index 6e95bc6a4f..1df6ed4bb0 100644 --- a/src/mathed/math_macro.h +++ b/src/mathed/math_macro.h @@ -38,11 +38,11 @@ public: void dump() const; /// - bool idxUpDown(BufferView &, bool up, int targetx) const; + bool idxUpDown(LCursor &, bool up, int targetx) const; /// - bool idxLeft(BufferView &) const; + bool idxLeft(LCursor &) const; /// - bool idxRight(BufferView &) const; + bool idxRight(LCursor &) const; /// void validate(LaTeXFeatures &) const; diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index 1caaee458e..da4ea89da9 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -71,9 +71,8 @@ void MathNestInset::metrics(MetricsInfo const & mi) const } -bool MathNestInset::idxNext(BufferView & bv) const +bool MathNestInset::idxNext(LCursor & cur) const { - CursorSlice & cur = cursorTip(bv); if (cur.idx() + 1 >= nargs()) return false; ++cur.idx(); @@ -82,15 +81,14 @@ bool MathNestInset::idxNext(BufferView & bv) const } -bool MathNestInset::idxRight(BufferView & bv) const +bool MathNestInset::idxRight(LCursor & cur) const { - return idxNext(bv); + return idxNext(cur); } -bool MathNestInset::idxPrev(BufferView & bv) const +bool MathNestInset::idxPrev(LCursor & cur) const { - CursorSlice & cur = cursorTip(bv); if (cur.idx() == 0) return false; --cur.idx(); @@ -99,15 +97,14 @@ bool MathNestInset::idxPrev(BufferView & bv) const } -bool MathNestInset::idxLeft(BufferView & bv) const +bool MathNestInset::idxLeft(LCursor & cur) const { - return idxPrev(bv); + return idxPrev(cur); } -bool MathNestInset::idxFirst(BufferView & bv) const +bool MathNestInset::idxFirst(LCursor & cur) const { - CursorSlice & cur = cursorTip(bv); if (nargs() == 0) return false; cur.idx() = 0; @@ -116,9 +113,8 @@ bool MathNestInset::idxFirst(BufferView & bv) const } -bool MathNestInset::idxLast(BufferView & bv) const +bool MathNestInset::idxLast(LCursor & cur) const { - CursorSlice & cur = cursorTip(bv); if (nargs() == 0) return false; cur.idx() = nargs() - 1; @@ -127,9 +123,8 @@ bool MathNestInset::idxLast(BufferView & bv) const } -bool MathNestInset::idxHome(BufferView & bv) const +bool MathNestInset::idxHome(LCursor & cur) const { - CursorSlice & cur = cursorTip(bv); if (cur.pos() == 0) return false; cur.pos() = 0; @@ -137,9 +132,8 @@ bool MathNestInset::idxHome(BufferView & bv) const } -bool MathNestInset::idxEnd(BufferView & bv) const +bool MathNestInset::idxEnd(LCursor & cur) const { - CursorSlice & cur = cursorTip(bv); if (cur.lastpos() == cur.lastpos()) return false; cur.pos() = cur.lastpos(); diff --git a/src/mathed/math_nestinset.h b/src/mathed/math_nestinset.h index 2227ac2ae4..9fd8401a81 100644 --- a/src/mathed/math_nestinset.h +++ b/src/mathed/math_nestinset.h @@ -43,24 +43,24 @@ public: void getScreenPos(idx_type idx, pos_type pos, int & x, int & y) const; /// order of movement through the cells when pressing the left key - bool idxLeft(BufferView &) const; + bool idxLeft(LCursor &) const; /// order of movement through the cells when pressing the right key - bool idxRight(BufferView &) const; + bool idxRight(LCursor &) const; /// move one physical cell up - bool idxNext(BufferView &) const; + bool idxNext(LCursor &) const; /// move one physical cell down - bool idxPrev(BufferView &) const; + bool idxPrev(LCursor &) const; /// target pos when we enter the inset from the left by pressing "Right" - bool idxFirst(BufferView &) const; + bool idxFirst(LCursor &) const; /// target pos when we enter the inset from the right by pressing "Left" - bool idxLast(BufferView &) const; + bool idxLast(LCursor &) const; /// where should we go if we press home? - bool idxHome(BufferView &) const; + bool idxHome(LCursor &) const; /// where should we go if we press end? - bool idxEnd(BufferView &) const; + bool idxEnd(LCursor &) const; /// number of cells currently governed by us idx_type nargs() const; diff --git a/src/mathed/math_oversetinset.C b/src/mathed/math_oversetinset.C index 4053c543b3..5f32d98e84 100644 --- a/src/mathed/math_oversetinset.C +++ b/src/mathed/math_oversetinset.C @@ -47,18 +47,16 @@ void MathOversetInset::draw(PainterInfo & pi, int x, int y) const } -bool MathOversetInset::idxFirst(BufferView & bv) const +bool MathOversetInset::idxFirst(LCursor & cur) const { - CursorSlice & cur = cursorTip(bv); cur.idx() = 1; cur.pos() = 0; return true; } -bool MathOversetInset::idxLast(BufferView & bv) const +bool MathOversetInset::idxLast(LCursor & cur) const { - CursorSlice & cur = cursorTip(bv); cur.idx() = 1; cur.pos() = cur.lastpos(); return true; diff --git a/src/mathed/math_oversetinset.h b/src/mathed/math_oversetinset.h index 72aa05e4fd..8fe16c09df 100644 --- a/src/mathed/math_oversetinset.h +++ b/src/mathed/math_oversetinset.h @@ -25,9 +25,9 @@ public: /// void draw(PainterInfo & pi, int x, int y) const; /// - bool idxFirst(BufferView &) const; + bool idxFirst(LCursor &) const; /// - bool idxLast(BufferView &) const; + bool idxLast(LCursor &) const; /// void write(WriteStream & os) const; diff --git a/src/mathed/math_rootinset.C b/src/mathed/math_rootinset.C index 6d9513a5bb..7ba1100ede 100644 --- a/src/mathed/math_rootinset.C +++ b/src/mathed/math_rootinset.C @@ -78,9 +78,8 @@ void MathRootInset::normalize(NormalStream & os) const } -bool MathRootInset::idxUpDown(BufferView & bv, bool up, int) const +bool MathRootInset::idxUpDown(LCursor & cur, bool up, int) const { - CursorSlice & cur = cursorTip(bv); bool target = !up; // up ? 0 : 1; if (cur.idx() == target) return false; diff --git a/src/mathed/math_rootinset.h b/src/mathed/math_rootinset.h index e90ae842b0..406dd60e99 100644 --- a/src/mathed/math_rootinset.h +++ b/src/mathed/math_rootinset.h @@ -24,7 +24,7 @@ public: /// virtual std::auto_ptr clone() const; /// - bool idxUpDown(BufferView &, bool up, int targetx) const; + bool idxUpDown(LCursor &, bool up, int targetx) const; /// void metrics(MetricsInfo & mi, Dimension & dim) const; /// diff --git a/src/mathed/math_scriptinset.C b/src/mathed/math_scriptinset.C index 5b6c4a2e7f..4e52e1abd4 100644 --- a/src/mathed/math_scriptinset.C +++ b/src/mathed/math_scriptinset.C @@ -72,18 +72,16 @@ MathScriptInset * MathScriptInset::asScriptInset() } -bool MathScriptInset::idxFirst(BufferView & bv) const +bool MathScriptInset::idxFirst(LCursor & cur) const { - CursorSlice & cur = cursorTip(bv); cur.idx() = 2; cur.pos() = 0; return true; } -bool MathScriptInset::idxLast(BufferView & bv) const +bool MathScriptInset::idxLast(LCursor & cur) const { - CursorSlice & cur = cursorTip(bv); cur.idx() = 2; cur.pos() = nuc().size(); return true; @@ -315,21 +313,20 @@ bool MathScriptInset::hasDown() const } -bool MathScriptInset::idxRight(BufferView &) const +bool MathScriptInset::idxRight(LCursor &) const { return false; } -bool MathScriptInset::idxLeft(BufferView &) const +bool MathScriptInset::idxLeft(LCursor &) const { return false; } -bool MathScriptInset::idxUpDown(BufferView & bv, bool up, int) const +bool MathScriptInset::idxUpDown(LCursor & cur, bool up, int) const { - CursorSlice & cur = cursorTip(bv); if (cur.idx() == 1) { // if we are 'up' we can't go further up if (up) diff --git a/src/mathed/math_scriptinset.h b/src/mathed/math_scriptinset.h index 32d0b5479c..c948751f86 100644 --- a/src/mathed/math_scriptinset.h +++ b/src/mathed/math_scriptinset.h @@ -48,15 +48,15 @@ public: /// write content as something readable by Octave void octave(OctaveStream &) const; /// move cursor left - bool idxLeft(BufferView &) const; + bool idxLeft(LCursor &) const; /// move cursor right - bool idxRight(BufferView &) const; + bool idxRight(LCursor &) const; /// move cursor up or down - bool idxUpDown(BufferView &, bool up, int targetx) const; + bool idxUpDown(LCursor &, bool up, int targetx) const; /// Target pos when we enter the inset from the left by pressing "Right" - bool idxFirst(BufferView &) const; + bool idxFirst(LCursor &) const; /// Target pos when we enter the inset from the right by pressing "Left" - bool idxLast(BufferView &) const; + bool idxLast(LCursor &) const; /// can we enter this cell? bool validCell(idx_type i) const { return i == 2 || script_[i]; } diff --git a/src/mathed/math_textinset.C b/src/mathed/math_textinset.C index afd9a9a288..6a8ef248eb 100644 --- a/src/mathed/math_textinset.C +++ b/src/mathed/math_textinset.C @@ -50,7 +50,7 @@ void MathTextInset::getScreenPos(idx_type /*idx*/, pos_type pos, int & x, int & #if 0 -bool MathTextInset::idxUpDown2(BufferView & pos, bool up, +bool MathTextInset::idxUpDown2(LCursor & pos, bool up, int /*targetx*/) const { // try to move only one screen row up or down if possible diff --git a/src/mathed/math_textinset.h b/src/mathed/math_textinset.h index 97d5170598..f146467bdf 100644 --- a/src/mathed/math_textinset.h +++ b/src/mathed/math_textinset.h @@ -33,7 +33,7 @@ public: void drawSelection(PainterInfo & pi, idx_type idx1, pos_type pos1, idx_type idx2, pos_type pos2) const; /// moves cursor up or down - //bool idxUpDown2(BufferView & pos, bool up, int targetx) const; + //bool idxUpDown2(LCursor & pos, bool up, int targetx) const; protected: /// row corresponding to given position idx_type pos2row(pos_type pos) const; diff --git a/src/mathed/math_undersetinset.C b/src/mathed/math_undersetinset.C index 4dce259f58..6d1f34ecd4 100644 --- a/src/mathed/math_undersetinset.C +++ b/src/mathed/math_undersetinset.C @@ -47,27 +47,24 @@ void MathUndersetInset::draw(PainterInfo & pi, int x, int y) const } -bool MathUndersetInset::idxFirst(BufferView & bv) const +bool MathUndersetInset::idxFirst(LCursor & cur) const { - CursorSlice & cur = cursorTip(bv); cur.idx() = 1; cur.pos() = 0; return true; } -bool MathUndersetInset::idxLast(BufferView & bv) const +bool MathUndersetInset::idxLast(LCursor & cur) const { - CursorSlice & cur = cursorTip(bv); cur.idx() = 1; cur.pos() = cur.lastpos(); return true; } -bool MathUndersetInset::idxUpDown(BufferView & bv, bool up, int targetx) const +bool MathUndersetInset::idxUpDown(LCursor & cur, bool up, int targetx) const { - CursorSlice & cur = cursorTip(bv); idx_type target = up; // up ? 1 : 0, since upper cell has idx 1 if (cur.idx() == target) return false; diff --git a/src/mathed/math_undersetinset.h b/src/mathed/math_undersetinset.h index 0642355529..0be7417cd0 100644 --- a/src/mathed/math_undersetinset.h +++ b/src/mathed/math_undersetinset.h @@ -25,11 +25,11 @@ public: /// void draw(PainterInfo & pi, int x, int y) const; /// - bool idxFirst(BufferView &) const; + bool idxFirst(LCursor &) const; /// - bool idxLast(BufferView &) const; + bool idxLast(LCursor &) const; /// - bool idxUpDown(BufferView &, bool up, int targetx) const; + bool idxUpDown(LCursor &, bool up, int targetx) const; /// void write(WriteStream & os) const; /// -- 2.39.2