From 69bee02a8901793b34ac5ca6d07e93910cef4005 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Fri, 16 Jan 2004 10:55:19 +0000 Subject: [PATCH] mathed uglyfication git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8358 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.C | 2 +- src/BufferView_pimpl.C | 29 +- src/BufferView_pimpl.h | 6 +- src/bufferview_funcs.C | 12 +- src/cursor.C | 14 +- src/cursor.h | 11 +- src/cursor_slice.C | 12 + src/cursor_slice.h | 8 + src/insets/insetbase.h | 11 + src/iterators.C | 6 +- src/mathed/formulabase.C | 171 +++---- src/mathed/formulabase.h | 6 +- src/mathed/math_cursor.C | 931 +++++++++++++++++------------------- src/mathed/math_cursor.h | 195 ++++---- src/mathed/math_data.C | 3 +- src/mathed/math_hullinset.C | 2 +- 16 files changed, 691 insertions(+), 728 deletions(-) diff --git a/src/BufferView.C b/src/BufferView.C index aca0952c6e..ecfdd5543b 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -58,7 +58,7 @@ extern BufferList bufferlist; BufferView::BufferView(LyXView * owner, int xpos, int ypos, int width, int height) - : pimpl_(new Pimpl(this, owner, xpos, ypos, width, height)), + : pimpl_(new Pimpl(*this, owner, xpos, ypos, width, height)), x_target_(0) {} diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 97b946aedf..ace9dd4014 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -111,9 +111,9 @@ boost::signals::connection lostcon; } // anon namespace -BufferView::Pimpl::Pimpl(BufferView * bv, LyXView * owner, +BufferView::Pimpl::Pimpl(BufferView & bv, LyXView * owner, int xpos, int ypos, int width, int height) - : bv_(bv), owner_(owner), buffer_(0), cursor_timeout(400), + : bv_(&bv), owner_(owner), buffer_(0), cursor_timeout(400), using_xterm_cursor(false), cursor_(bv) { xsel_cache_.set = false; @@ -160,13 +160,20 @@ void BufferView::Pimpl::connectBuffer(Buffer & buf) if (errorConnection_.connected()) disconnectBuffer(); - errorConnection_ = buf.error.connect(boost::bind(&BufferView::Pimpl::addError, this, _1)); - messageConnection_ = buf.message.connect(boost::bind(&LyXView::message, owner_, _1)); - busyConnection_ = buf.busy.connect(boost::bind(&LyXView::busy, owner_, _1)); - titleConnection_ = buf.updateTitles.connect(boost::bind(&LyXView::updateWindowTitle, owner_)); - timerConnection_ = buf.resetAutosaveTimers.connect(boost::bind(&LyXView::resetAutosaveTimer, owner_)); - readonlyConnection_ = buf.readonly.connect(boost::bind(&BufferView::Pimpl::showReadonly, this, _1)); - closingConnection_ = buf.closing.connect(boost::bind(&BufferView::Pimpl::buffer, this, (Buffer *)0)); + errorConnection_ = + buf.error.connect(boost::bind(&BufferView::Pimpl::addError, this, _1)); + messageConnection_ = + buf.message.connect(boost::bind(&LyXView::message, owner_, _1)); + busyConnection_ = + buf.busy.connect(boost::bind(&LyXView::busy, owner_, _1)); + titleConnection_ = + buf.updateTitles.connect(boost::bind(&LyXView::updateWindowTitle, owner_)); + timerConnection_ = + buf.resetAutosaveTimers.connect(boost::bind(&LyXView::resetAutosaveTimer, owner_)); + readonlyConnection_ = + buf.readonly.connect(boost::bind(&BufferView::Pimpl::showReadonly, this, _1)); + closingConnection_ = + buf.closing.connect(boost::bind(&BufferView::Pimpl::buffer, this, (Buffer *)0)); } @@ -872,7 +879,7 @@ void BufferView::Pimpl::trackChanges() } #warning remove me -LCursor theTempCursor(0); +LCursor theTempCursor; namespace { @@ -881,7 +888,7 @@ namespace { lyxerr << "insetFromCoords" << endl; LyXText * text = bv->text(); InsetOld * inset = 0; - theTempCursor = LCursor(bv); + theTempCursor = LCursor(*bv); while (true) { InsetOld * const inset_hit = text->checkInsetHit(x, y); if (!inset_hit) { diff --git a/src/BufferView_pimpl.h b/src/BufferView_pimpl.h index e63b7b5df6..789b75fc02 100644 --- a/src/BufferView_pimpl.h +++ b/src/BufferView_pimpl.h @@ -45,7 +45,7 @@ class FuncRequest; /// struct BufferView::Pimpl : public boost::signals::trackable { /// - Pimpl(BufferView * bv, LyXView * owner, + Pimpl(BufferView & bv, LyXView * owner, int xpos, int ypos, int width, int height); /// Painter & painter() const; @@ -75,9 +75,7 @@ struct BufferView::Pimpl : public boost::signals::trackable { void updateScrollbar(); /// void scrollDocView(int value); - /** - * Wheel mouse scroll, move by multiples of text->defaultRowHeight(). - */ + /// Wheel mouse scroll, move by multiples of text->defaultRowHeight(). void scroll(int lines); /// typedef boost::shared_ptr LyXKeySymPtr; diff --git a/src/bufferview_funcs.C b/src/bufferview_funcs.C index 02eff20234..58f782b942 100644 --- a/src/bufferview_funcs.C +++ b/src/bufferview_funcs.C @@ -150,18 +150,14 @@ bool string2font(string const & data, LyXFont & font, bool & toggle) bool changeDepthAllowed(BufferView * bv, LyXText * text, DEPTH_CHANGE type) { - if (!bv->available() || !text) - return false; - - return text->changeDepthAllowed(type); + return bv->available() && text && text->changeDepthAllowed(type); } void changeDepth(BufferView * bv, LyXText * text, DEPTH_CHANGE type) { - if (!bv->available() || !text) - return; - text->changeDepth(type); + if (bv->available() && text) + text->changeDepth(type); } @@ -172,7 +168,7 @@ string const currentState(BufferView * bv) return string(); if (mathcursor) - return mathcursor->info(); + return mathcursor->info(*bv); ostringstream state; diff --git a/src/cursor.C b/src/cursor.C index acd21c8402..25ef913692 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -41,8 +41,13 @@ std::ostream & operator<<(std::ostream & os, LCursor const & cur) } -LCursor::LCursor(BufferView * bv) - : cursor_(1), anchor_(1), bv_(bv) +LCursor::LCursor() + : cursor_(1), anchor_(1), bv_(0) +{} + + +LCursor::LCursor(BufferView & bv) + : cursor_(1), anchor_(1), bv_(&bv) {} @@ -153,7 +158,7 @@ LyXText * LCursor::innerText() const void LCursor::updatePos() { if (cursor_.size() > 1) - cached_y_ = bv_->top_y() + innerInset()->y(); + cached_y_ = bv_->top_y() + cursor_.back().inset()->y(); } @@ -165,8 +170,9 @@ void LCursor::getDim(int & asc, int & desc) const Row const & row = *txt->cursorRow(); asc = row.baseline(); desc = row.height() - asc; - } else + } else { innerInset()->getCursorDim(asc, desc); + } } diff --git a/src/cursor.h b/src/cursor.h index 9088e3671e..6858709839 100644 --- a/src/cursor.h +++ b/src/cursor.h @@ -38,8 +38,10 @@ public: /// type for cursor positions within a cell typedef CursorSlice::pos_type pos_type; + /// create 'empty' cursor. REMOVE ME + LCursor(); /// create 'empty' cursor - explicit LCursor(BufferView * bv); + explicit LCursor(BufferView & bv); /// dispatch from innermost inset upwards DispatchResult dispatch(FuncRequest const & cmd); /// @@ -73,6 +75,8 @@ public: void updatePos(); /// sets anchor to cursor position void resetAnchor(); + /// sets anchor to cursor position + BufferView & bv() const; /// friend std::ostream & operator<<(std::ostream &, LCursor const &); public: @@ -87,9 +91,4 @@ private: int cached_y_; }; - -class LCursorS -{ -}; - #endif // LYXCURSOR_H diff --git a/src/cursor_slice.C b/src/cursor_slice.C index ba26f5e87f..6c4befd0a6 100644 --- a/src/cursor_slice.C +++ b/src/cursor_slice.C @@ -45,6 +45,18 @@ void CursorSlice::idx(idx_type idx) } +size_t CursorSlice::nargs() const +{ + return inset_->nargs(); +} + + +size_t CursorSlice::ncols() const +{ + return inset_->ncols(); +} + + CursorSlice::idx_type CursorSlice::idx() const { return idx_; diff --git a/src/cursor_slice.h b/src/cursor_slice.h index 303a0e39cd..51c23cc22d 100644 --- a/src/cursor_slice.h +++ b/src/cursor_slice.h @@ -55,6 +55,8 @@ public: /// explicit CursorSlice(InsetBase *); + /// the current inset + InsetBase * inset() const { return inset_; } /// set the paragraph that contains this cursor void idx(idx_type idx); /// return the paragraph this cursor is in @@ -75,6 +77,12 @@ public: pos_type & pos(); /// return the last position within the paragraph pos_type lastpos() const; + /// return the number of embedded cells + size_t nargs() const; + /// return the number of embedded cells + size_t ncols() const; + /// return the number of embedded cells + size_t nrows() const; /// return the grid row of the current cell row_type row() const; /// return the grid row of the current cell diff --git a/src/insets/insetbase.h b/src/insets/insetbase.h index 3302b99d9b..771ff610fa 100644 --- a/src/insets/insetbase.h +++ b/src/insets/insetbase.h @@ -71,6 +71,17 @@ public: /// Appends \c list with all labels found within this inset. virtual void getLabelList(Buffer const &, std::vector & /* list */) const {} + /// last drawn position for 'important' insets + virtual int x() const { return 0; } + /// last drawn position for 'important' insets + virtual int y() const { return 0; } + + /// number of embedded cells + virtual size_t nargs() const { return 0; } + /// number of rows in gridlike structures + virtual size_t nrows() const { return 0; } + /// number of columns in gridlike structures + virtual size_t ncols() const { return 0; } protected: // the real dispatcher virtual diff --git a/src/iterators.C b/src/iterators.C index fda9d6c5d8..5f5a535bad 100644 --- a/src/iterators.C +++ b/src/iterators.C @@ -401,9 +401,7 @@ ParIterator::ParIterator(PosIterator const & pos) void ParIterator::lockPath(BufferView * bv) const { - bv->fullCursor() = LCursor(bv); - int last = size() - 1; -#warning this seems to create just one entry for InsetTabulars - for (int i = 0; i < last; ++i) + bv->fullCursor() = LCursor(*bv); + for (int i = 0, last = size() - 1; i < last; ++i) (*pimpl_->positions[i].it)->inset->edit(bv, true); } diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index fb3251fbce..90775dbc86 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -50,8 +50,8 @@ using std::string; using std::abs; using std::endl; using std::max; - using std::istringstream; +using std::ostringstream; MathCursor * mathcursor = 0; @@ -117,11 +117,11 @@ void InsetFormulaBase::handleFont // changes... recordUndo(bv, Undo::ATOMIC); - if (mathcursor->inset()->name() == font) - mathcursor->handleFont(font); + if (bv.cursor().inset()->asMathInset()->name() == font) + mathcursor->handleFont(bv, font); else { - mathcursor->handleNest(createMathInset(font)); - mathcursor->insert(arg); + mathcursor->handleNest(bv, createMathInset(font)); + mathcursor->insert(bv, arg); } } @@ -135,7 +135,7 @@ void InsetFormulaBase::handleFont2(BufferView & bv, string const & arg) if (font.color() != LColor::inherit) { MathAtom at = createMathInset("color"); asArray(lcolor.getGUIName(font.color()), at.nucleus()->cell(0)); - mathcursor->handleNest(at, 1); + mathcursor->handleNest(bv, at, 1); } } @@ -151,30 +151,30 @@ string const InsetFormulaBase::editMessage() const } -void InsetFormulaBase::insetUnlock(BufferView * bv) +void InsetFormulaBase::insetUnlock(BufferView & bv) { if (mathcursor) { - if (mathcursor->inMacroMode()) - mathcursor->macroModeClose(); - releaseMathCursor(*bv); + if (mathcursor->inMacroMode(bv)) + mathcursor->macroModeClose(bv); + releaseMathCursor(bv); } - if (bv->buffer()) - generatePreview(*bv->buffer()); - bv->update(); + if (bv.buffer()) + generatePreview(*bv.buffer()); + bv.update(); } -void InsetFormulaBase::getCursor(BufferView &, int & x, int & y) const +void InsetFormulaBase::getCursor(BufferView & bv, int & x, int & y) const { - mathcursor->getScreenPos(x, y); + mathcursor->getScreenPos(bv, x, y); } -void InsetFormulaBase::getCursorPos(int, int & x, int & y) const +void InsetFormulaBase::getCursorPos(BufferView & bv, int & x, int & y) const { if (mathcursor) { - mathcursor->getScreenPos(x, y); - x = mathcursor->targetX(); + mathcursor->getScreenPos(bv, x, y); + x = mathcursor->targetX(bv); x -= xo_; y -= yo_; lyxerr << "InsetFormulaBase::getCursorPos: " << x << ' ' << y << endl; @@ -203,8 +203,8 @@ void InsetFormulaBase::toggleInsetSelection(BufferView * bv) } -DispatchResult InsetFormulaBase::lfunMouseRelease( - BufferView & bv, FuncRequest const & cmd) +DispatchResult +InsetFormulaBase::lfunMouseRelease(BufferView & bv, FuncRequest const & cmd) { if (!mathcursor) return DispatchResult(false); @@ -213,7 +213,7 @@ DispatchResult InsetFormulaBase::lfunMouseRelease( if (cmd.button() == mouse_button::button3) { // try to dispatch to enclosed insets first - if (!mathcursor->dispatch(cmd).dispatched()) { + if (!mathcursor->dispatch(bv, cmd).dispatched()) { // launch math panel for right mouse button lyxerr << "lfunMouseRelease: undispatched: " << cmd.button() << endl; bv.owner()->getDialogs().show("mathpanel"); @@ -224,17 +224,17 @@ DispatchResult InsetFormulaBase::lfunMouseRelease( if (cmd.button() == mouse_button::button2) { MathArray ar; asArray(bv.getClipboard(), ar); - mathcursor->selClear(); - mathcursor->setScreenPos(cmd.x + xo_, cmd.y + yo_); - mathcursor->insert(ar); + mathcursor->selClear(bv); + mathcursor->setScreenPos(bv, cmd.x + xo_, cmd.y + yo_); + mathcursor->insert(bv, ar); bv.update(); return DispatchResult(true, true); } if (cmd.button() == mouse_button::button1) { // try to dispatch to enclosed insets first - mathcursor->dispatch(cmd); - bv.stuffClipboard(mathcursor->grabSelection()); + mathcursor->dispatch(bv, cmd); + bv.stuffClipboard(mathcursor->grabSelection(bv)); // try to set the cursor //delete mathcursor; //mathcursor = new MathCursor(bv, this, x == 0); @@ -247,8 +247,8 @@ DispatchResult InsetFormulaBase::lfunMouseRelease( } -DispatchResult InsetFormulaBase::lfunMousePress( - BufferView & bv, FuncRequest const & cmd) +DispatchResult +InsetFormulaBase::lfunMousePress(BufferView & bv, FuncRequest const & cmd) { //lyxerr << "lfunMousePress: buttons: " << cmd.button() << endl; @@ -257,20 +257,20 @@ DispatchResult InsetFormulaBase::lfunMousePress( releaseMathCursor(bv); mathcursor = new MathCursor(&bv, this, cmd.x == 0); //metrics(bv); - mathcursor->setScreenPos(cmd.x + xo_, cmd.y + yo_); + mathcursor->setScreenPos(bv, cmd.x + xo_, cmd.y + yo_); } if (cmd.button() == mouse_button::button3) { - mathcursor->dispatch(cmd); + mathcursor->dispatch(bv, cmd); return DispatchResult(true, true); } if (cmd.button() == mouse_button::button1) { first_x = cmd.x; first_y = cmd.y; - mathcursor->selClear(); - mathcursor->setScreenPos(cmd.x + xo_, cmd.y + yo_); - mathcursor->dispatch(cmd); + mathcursor->selClear(bv); + mathcursor->setScreenPos(bv, cmd.x + xo_, cmd.y + yo_); + mathcursor->dispatch(bv, cmd); return DispatchResult(true, true); } @@ -279,13 +279,13 @@ DispatchResult InsetFormulaBase::lfunMousePress( } -DispatchResult InsetFormulaBase::lfunMouseMotion( - BufferView & bv, FuncRequest const & cmd) +DispatchResult +InsetFormulaBase::lfunMouseMotion(BufferView & bv, FuncRequest const & cmd) { if (!mathcursor) return DispatchResult(true, true); - if (mathcursor->dispatch(FuncRequest(cmd)).dispatched()) + if (mathcursor->dispatch(bv, FuncRequest(cmd)).dispatched()) return DispatchResult(true, true); // only select with button 1 @@ -299,9 +299,9 @@ DispatchResult InsetFormulaBase::lfunMouseMotion( first_y = cmd.y; if (!mathcursor->selection()) - mathcursor->selStart(); + mathcursor->selStart(bv); - mathcursor->setScreenPos(cmd.x + xo_, cmd.y + yo_); + mathcursor->setScreenPos(bv, cmd.x + xo_, cmd.y + yo_); bv.update(); return DispatchResult(true, true); } @@ -325,7 +325,7 @@ void InsetFormulaBase::edit(BufferView * bv, int x, int y) releaseMathCursor(*bv); mathcursor = new MathCursor(bv, this, true); //metrics(bv); - mathcursor->setScreenPos(x + xo_, y + yo_); + mathcursor->setScreenPos(*bv, 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 @@ -365,13 +365,13 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd) if (!mathcursor) return DispatchResult(false); - string argument = cmd.argument; DispatchResult result(true); + string argument = cmd.argument; bool sel = false; - bool was_macro = mathcursor->inMacroMode(); + bool was_macro = mathcursor->inMacroMode(bv); bool was_selection = mathcursor->selection(); - mathcursor->normalize(); + mathcursor->normalize(bv); mathcursor->touch(); switch (cmd.action) { @@ -389,13 +389,13 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd) case LFUN_PASTESELECTION: case LFUN_MATH_LIMITS: recordUndo(bv, Undo::ATOMIC); - mathcursor->dispatch(cmd); + mathcursor->dispatch(bv, cmd); break; case LFUN_RIGHTSEL: sel = true; // fall through... case LFUN_RIGHT: - result = mathcursor->right(sel) ? + result = mathcursor->right(bv, sel) ? DispatchResult(true, true) : DispatchResult(false, FINISHED_RIGHT); //lyxerr << "calling scroll 20" << endl; //scroll(&bv, 20); @@ -406,27 +406,27 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd) case LFUN_LEFTSEL: sel = true; // fall through case LFUN_LEFT: - result = mathcursor->left(sel) ? + result = mathcursor->left(bv, sel) ? DispatchResult(true, true) : DispatchResult(false, FINISHED); break; case LFUN_UPSEL: sel = true; // fall through case LFUN_UP: - result = mathcursor->up(sel) ? + result = mathcursor->up(bv, sel) ? DispatchResult(true, true) : DispatchResult(false, FINISHED_UP); break; case LFUN_DOWNSEL: sel = true; // fall through case LFUN_DOWN: - result = mathcursor->down(sel) ? + result = mathcursor->down(bv, sel) ? DispatchResult(true, true) : DispatchResult(false, FINISHED_DOWN); break; case LFUN_WORDSEL: - mathcursor->home(false); - mathcursor->end(true); + mathcursor->home(bv, false); + mathcursor->end(bv, true); break; case LFUN_UP_PARAGRAPHSEL: @@ -441,7 +441,8 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd) sel = true; // fall through case LFUN_HOME: case LFUN_WORDLEFT: - result = mathcursor->home(sel) ? DispatchResult(true, true) : DispatchResult(true, FINISHED); + result = mathcursor->home(bv, sel) + ? DispatchResult(true, true) : DispatchResult(true, FINISHED); break; case LFUN_ENDSEL: @@ -449,7 +450,8 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd) sel = true; // fall through case LFUN_END: case LFUN_WORDRIGHT: - result = mathcursor->end(sel) ? DispatchResult(true, true) : DispatchResult(false, FINISHED_RIGHT); + result = mathcursor->end(bv, sel) + ? DispatchResult(true, true) : DispatchResult(false, FINISHED_RIGHT); break; case LFUN_PRIORSEL: @@ -467,17 +469,17 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd) break; case LFUN_CELL_FORWARD: - mathcursor->idxNext(); + mathcursor->idxNext(bv); break; case LFUN_CELL_BACKWARD: - mathcursor->idxPrev(); + mathcursor->idxPrev(bv); break; case LFUN_DELETE_WORD_BACKWARD: case LFUN_BACKSPACE: recordUndo(bv, Undo::ATOMIC); - if (!mathcursor->backspace()) { + if (!mathcursor->backspace(bv)) { result = DispatchResult(true, FINISHED); remove_inset = true; } @@ -486,7 +488,7 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd) case LFUN_DELETE_WORD_FORWARD: case LFUN_DELETE: recordUndo(bv, Undo::ATOMIC); - if (!mathcursor->erase()) { + if (!mathcursor->erase(bv)) { result = DispatchResult(true, FINISHED); remove_inset = true; } @@ -502,7 +504,7 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd) int y = 0; istringstream is(cmd.argument.c_str()); is >> x >> y; - mathcursor->setScreenPos(x, y); + mathcursor->setScreenPos(bv, x, y); break; } @@ -511,19 +513,19 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd) istringstream is(cmd.argument.c_str()); is >> n; if (was_macro) - mathcursor->macroModeClose(); + mathcursor->macroModeClose(bv); recordUndo(bv, Undo::ATOMIC); - mathcursor->selPaste(n); + mathcursor->selPaste(bv, n); break; } case LFUN_CUT: recordUndo(bv, Undo::DELETE); - mathcursor->selCut(); + mathcursor->selCut(bv); break; case LFUN_COPY: - mathcursor->selCopy(); + mathcursor->selCopy(bv); break; @@ -534,7 +536,7 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd) // do superscript if LyX handles // deadkeys recordUndo(bv, Undo::ATOMIC); - mathcursor->script(true); + mathcursor->script(bv, true); } break; @@ -572,8 +574,8 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd) case LFUN_DEFAULT: handleFont(bv, cmd.argument, "textnormal"); break; case LFUN_MATH_MODE: - if (mathcursor->currentMode() == MathInset::TEXT_MODE) - mathcursor->niceInsert(MathAtom(new MathHullInset("simple"))); + if (mathcursor->currentMode(bv) == MathInset::TEXT_MODE) + mathcursor->niceInsert(bv, MathAtom(new MathHullInset("simple"))); else handleFont(bv, cmd.argument, "textrm"); //bv.owner()->message(_("math text mode toggled")); @@ -599,7 +601,7 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd) m = max(1u, m); n = max(1u, n); v_align += 'c'; - mathcursor->niceInsert( + mathcursor->niceInsert(bv, MathAtom(new MathArrayInset("array", m, n, v_align[0], h_align))); break; } @@ -613,16 +615,15 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd) ls = '('; if (rs.empty()) rs = ')'; - recordUndo(bv, Undo::ATOMIC); - mathcursor->handleNest(MathAtom(new MathDelimInset(ls, rs))); + mathcursor->handleNest(bv, MathAtom(new MathDelimInset(ls, rs))); break; } case LFUN_SPACE_INSERT: case LFUN_MATH_SPACE: recordUndo(bv, Undo::ATOMIC); - mathcursor->insert(MathAtom(new MathSpaceInset(","))); + mathcursor->insert(bv, MathAtom(new MathSpaceInset(","))); break; case LFUN_UNDO: @@ -637,7 +638,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('\\'); + mathcursor->interpret(bv, '\\'); break; case LFUN_BREAKPARAGRAPH: @@ -651,7 +652,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(argument); + mathcursor->niceInsert(bv, argument); break; case -1: @@ -659,21 +660,22 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd) if (!argument.empty()) { recordUndo(bv, Undo::ATOMIC); if (argument.size() == 1) - result = mathcursor->interpret(argument[0]) ? DispatchResult(true, true) : DispatchResult(false, FINISHED_RIGHT); + result = mathcursor->interpret(bv, argument[0]) + ? DispatchResult(true, true) : DispatchResult(false, FINISHED_RIGHT); else - mathcursor->insert(argument); + mathcursor->insert(bv, argument); } break; case LFUN_ESCAPE: if (mathcursor->selection()) - mathcursor->selClear(); + mathcursor->selClear(bv); else result = DispatchResult(false); break; case LFUN_INSET_TOGGLE: - mathcursor->insetToggle(); + mathcursor->insetToggle(bv); break; case LFUN_DIALOG_SHOW: @@ -705,7 +707,7 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd) } else { MathArray ar; if (createMathInset_fromDialogStr(cmd.argument, ar)) { - mathcursor->insert(ar); + mathcursor->insert(bv, ar); result = DispatchResult(true, true); } else { result = DispatchResult(false); @@ -729,7 +731,7 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd) if (result == DispatchResult(true, true)) bv.update(); - mathcursor->normalize(); + mathcursor->normalize(bv); mathcursor->touch(); BOOST_ASSERT(mathcursor); @@ -739,7 +741,7 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd) if (result.dispatched()) { revealCodes(bv); - bv.stuffClipboard(mathcursor->grabSelection()); + bv.stuffClipboard(mathcursor->grabSelection(bv)); } else { releaseMathCursor(bv); if (remove_inset) @@ -754,16 +756,15 @@ void InsetFormulaBase::revealCodes(BufferView & bv) const { if (!mathcursor) return; - bv.owner()->message(mathcursor->info()); - -#if 0 + bv.owner()->message(mathcursor->info(bv)); +/* // write something to the minibuffer // translate to latex - mathcursor->markInsert(); + mathcursor->markInsert(bv); ostringstream os; write(NULL, os); string str = os.str(); - mathcursor->markErase(); + mathcursor->markErase(bv); string::size_type pos = 0; string res; for (string::iterator it = str.begin(); it != str.end(); ++it) { @@ -781,7 +782,7 @@ void InsetFormulaBase::revealCodes(BufferView & bv) const if (res.size() > 60) res = res.substr(0, 60); bv.owner()->message(res); -#endif +*/ } @@ -848,7 +849,7 @@ bool InsetFormulaBase::searchForward(BufferView * bv, string const & str, delete mathcursor; mathcursor = new MathCursor(bv, this, true); //metrics(bv); - mathcursor->setSelection(it, ar.size()); + mathcursor->setSelection(*bv, it, ar.size()); current = it; top.pos_ += ar.size(); bv->update(); @@ -876,9 +877,9 @@ bool InsetFormulaBase::display() const } -string InsetFormulaBase::selectionAsString() const +string InsetFormulaBase::selectionAsString(BufferView & bv) const { - return mathcursor ? mathcursor->grabSelection() : string(); + return mathcursor ? mathcursor->grabSelection(bv) : string(); } ///////////////////////////////////////////////////////////////////// diff --git a/src/mathed/formulabase.h b/src/mathed/formulabase.h index e50002ddaa..b705c10ad7 100644 --- a/src/mathed/formulabase.h +++ b/src/mathed/formulabase.h @@ -46,7 +46,7 @@ public: /// what appears in the minibuffer when opening virtual std::string const editMessage() const; /// - virtual void getCursorPos(int cell, int & x, int & y) const; + 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 @@ -54,7 +54,7 @@ public: /// virtual void toggleInsetSelection(BufferView * bv); /// - virtual void insetUnlock(BufferView *); + virtual void insetUnlock(BufferView & bv); /// To allow transparent use of math editing functions //virtual void status(FuncRequest const &); @@ -81,7 +81,7 @@ public: /// bool display() const; // return the selection as std::string - std::string selectionAsString() const; + std::string selectionAsString(BufferView & bv) const; /// void edit(BufferView * bv, bool); /// diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index e13156d5d2..d2bdcd7387 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -54,9 +54,9 @@ limited_stack theCutBuffer; MathCursor::MathCursor(BufferView * bv, InsetFormulaBase * formula, bool front) - : formula_(formula), autocorrect_(false), selection_(false), bv_(bv) + : formula_(formula), autocorrect_(false), selection_(false) { - front ? first() : last(); + front ? first(*bv) : last(*bv); } @@ -68,54 +68,56 @@ MathCursor::~MathCursor() } -void MathCursor::push(MathAtom & t) +void MathCursor::push(BufferView & bv, MathAtom & t) { - bv_->fullCursor().push(t.nucleus()); + bv.fullCursor().push(t.nucleus()); } -void MathCursor::pushLeft(MathAtom & t) +void MathCursor::pushLeft(BufferView & bv, MathAtom & t) { //lyxerr << "Entering atom " << t << " left" << endl; - push(t); - t->idxFirst(*bv_); + push(bv, t); + t->idxFirst(bv); } -void MathCursor::pushRight(MathAtom & t) +void MathCursor::pushRight(BufferView & bv, MathAtom & t) { //lyxerr << "Entering atom " << t << " right" << endl; - posLeft(); - push(t); - t->idxLast(*bv_); + posLeft(bv); + push(bv, t); + t->idxLast(bv); } -bool MathCursor::popLeft() +bool MathCursor::popLeft(BufferView & bv) { + CursorSlice & cur = cursorTip(bv); //lyxerr << "Leaving atom to the left" << endl; - if (depth() <= 1) { - if (depth() == 1) - inset()->notifyCursorLeaves(idx()); + if (depth(bv) <= 1) { + if (depth(bv) == 1) + cur.inset()->asMathInset()->notifyCursorLeaves(cur.idx()); return false; } - inset()->notifyCursorLeaves(idx()); - bv_->fullCursor().pop(); + cur.inset()->asMathInset()->notifyCursorLeaves(cur.idx()); + bv.fullCursor().pop(); return true; } -bool MathCursor::popRight() +bool MathCursor::popRight(BufferView & bv) { - //lyxerr << "Leaving atom "; inset()->write(cerr, false); cerr << " right" << endl; - if (depth() <= 1) { - if (depth() == 1) - inset()->notifyCursorLeaves(idx()); + CursorSlice & cur = cursorTip(bv); + //lyxerr << "Leaving atom "; bv.inset->asMathInset()->write(cerr, false); cerr << " right" << endl; + if (depth(bv) <= 1) { + if (depth(bv) == 1) + cur.inset()->asMathInset()->notifyCursorLeaves(cur.idx()); return false; } - inset()->notifyCursorLeaves(idx()); - bv_->fullCursor().pop(); - posRight(); + cur.inset()->asMathInset()->notifyCursorLeaves(cur.idx()); + bv.fullCursor().pop(); + posRight(bv); return true; } @@ -176,92 +178,94 @@ bool MathCursor::openable(MathAtom const & t, bool sel) const } -bool MathCursor::inNucleus() const +bool MathCursor::inNucleus(BufferView & bv) const { - return inset()->asScriptInset() && idx() == 2; + CursorSlice & cur = cursorTip(bv); + return cur.inset()->asMathInset()->asScriptInset() && cur.idx() == 2; } -bool MathCursor::posLeft() +bool MathCursor::posLeft(BufferView & bv) { - if (pos() == 0) + CursorSlice & cur = cursorTip(bv); + if (cur.pos() == 0) return false; - --pos(); + --cur.pos(); return true; } -bool MathCursor::posRight() +bool MathCursor::posRight(BufferView & bv) { - if (pos() == size()) + CursorSlice & cur = cursorTip(bv); + if (cur.pos() == cur.lastpos()) return false; - ++pos(); + ++cur.pos(); return true; } -bool MathCursor::left(bool sel) +bool MathCursor::left(BufferView & bv, bool sel) { dump("Left 1"); autocorrect_ = false; - bv_->x_target(-1); // "no target" - if (inMacroMode()) { - macroModeClose(); + bv.x_target(-1); // "no target" + if (inMacroMode(bv)) { + macroModeClose(bv); return true; } - selHandle(sel); + selHandle(bv, sel); - if (hasPrevAtom() && openable(prevAtom(), sel)) { - pushRight(prevAtom()); + if (hasPrevAtom(bv) && openable(prevAtom(bv), sel)) { + pushRight(bv, prevAtom(bv)); return true; } - return posLeft() || idxLeft() || popLeft() || selection_; + return posLeft(bv) || idxLeft(bv) || popLeft(bv) || selection_; } -bool MathCursor::right(bool sel) +bool MathCursor::right(BufferView & bv, bool sel) { dump("Right 1"); autocorrect_ = false; - bv_->x_target(-1); // "no target" - if (inMacroMode()) { - macroModeClose(); + bv.x_target(-1); // "no target" + if (inMacroMode(bv)) { + macroModeClose(bv); return true; } - selHandle(sel); + selHandle(bv, sel); - if (hasNextAtom() && openable(nextAtom(), sel)) { - pushLeft(nextAtom()); + if (hasNextAtom(bv) && openable(nextAtom(bv), sel)) { + pushLeft(bv, nextAtom(bv)); return true; } - return posRight() || idxRight() || popRight() || selection_; + return posRight(bv) || idxRight(bv) || popRight(bv) || selection_; } -void MathCursor::first() +void MathCursor::first(BufferView & bv) { #warning FIXME //Cursor_.clear(); - push(formula_->par()); - inset()->idxFirst(*bv_); - bv_->resetAnchor(); + push(bv, formula_->par()); + bv.cursor().inset()->asMathInset()->idxFirst(bv); + bv.resetAnchor(); } -void MathCursor::last() +void MathCursor::last(BufferView & bv) { #warning FIXME //Cursor_.clear(); - push(formula_->par()); - inset()->idxLast(*bv_); - bv_->resetAnchor(); + push(bv, formula_->par()); + bv.cursor().inset()->asMathInset()->idxLast(bv); + bv.resetAnchor(); } -bool positionable - (CursorBase const & cursor, CursorBase const & anchor) +bool positionable(CursorBase const & cursor, CursorBase const & anchor) { // avoid deeper nested insets when selecting if (cursor.size() > anchor.size()) @@ -277,235 +281,241 @@ bool positionable } -void MathCursor::setScreenPos(int x, int y) +void MathCursor::setScreenPos(BufferView & bv, int x, int y) { dump("setScreenPos 1"); - bool res = bruteFind(x, y, + bool res = bruteFind(bv, 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(); + first(bv); } - bv_->x_target(-1); // "no target" + bv.x_target(-1); // "no target" dump("setScreenPos 2"); } -bool MathCursor::home(bool sel) +bool MathCursor::home(BufferView & bv, bool sel) { dump("home 1"); autocorrect_ = false; - selHandle(sel); - macroModeClose(); - if (!inset()->idxHome(*bv_)) - return popLeft(); + selHandle(bv, sel); + macroModeClose(bv); + if (!bv.cursor().inset()->asMathInset()->idxHome(bv)) + return popLeft(bv); dump("home 2"); - bv_->x_target(-1); // "no target" + bv.x_target(-1); // "no target" return true; } -bool MathCursor::end(bool sel) +bool MathCursor::end(BufferView & bv, bool sel) { dump("end 1"); autocorrect_ = false; - selHandle(sel); - macroModeClose(); - if (!inset()->idxEnd(*bv_)) - return popRight(); + selHandle(bv, sel); + macroModeClose(bv); + if (!bv.cursor().inset()->asMathInset()->idxEnd(bv)) + return popRight(bv); dump("end 2"); - bv_->x_target(-1); // "no target" + bv.x_target(-1); // "no target" return true; } -void MathCursor::plainErase() +void MathCursor::plainErase(BufferView & bv) { - array().erase(pos()); + CursorSlice & cur = cursorTip(bv); + cur.cell().erase(cur.pos()); } -void MathCursor::markInsert() +void MathCursor::markInsert(BufferView & bv) { //lyxerr << "inserting mark" << endl; - array().insert(pos(), MathAtom(new MathCharInset(0))); + CursorSlice & cur = cursorTip(bv); + cur.cell().insert(cur.pos(), MathAtom(new MathCharInset(0))); } -void MathCursor::markErase() +void MathCursor::markErase(BufferView & bv) { //lyxerr << "deleting mark" << endl; - array().erase(pos()); + CursorSlice & cur = cursorTip(bv); + cur.cell().erase(cur.pos()); } -void MathCursor::plainInsert(MathAtom const & t) +void MathCursor::plainInsert(BufferView & bv, MathAtom const & t) { dump("plainInsert"); - array().insert(pos(), t); - ++pos(); + CursorSlice & cur = cursorTip(bv); + cur.cell().insert(cur.pos(), t); + ++cur.pos(); } -void MathCursor::insert2(string const & str) +void MathCursor::insert2(BufferView & bv, string const & str) { MathArray ar; asArray(str, ar); - insert(ar); + insert(bv, ar); } -void MathCursor::insert(string const & str) +void MathCursor::insert(BufferView & bv, string const & str) { //lyxerr << "inserting '" << str << "'" << endl; - selClearOrDel(); + selClearOrDel(bv); for (string::const_iterator it = str.begin(); it != str.end(); ++it) - plainInsert(MathAtom(new MathCharInset(*it))); + plainInsert(bv, MathAtom(new MathCharInset(*it))); } -void MathCursor::insert(char c) +void MathCursor::insert(BufferView & bv, char c) { //lyxerr << "inserting '" << c << "'" << endl; - selClearOrDel(); - plainInsert(MathAtom(new MathCharInset(c))); + selClearOrDel(bv); + plainInsert(bv, MathAtom(new MathCharInset(c))); } -void MathCursor::insert(MathAtom const & t) +void MathCursor::insert(BufferView & bv, MathAtom const & t) { - macroModeClose(); - selClearOrDel(); - plainInsert(t); + macroModeClose(bv); + selClearOrDel(bv); + plainInsert(bv, t); } -void MathCursor::niceInsert(string const & t) +void MathCursor::niceInsert(BufferView & bv, string const & t) { MathArray ar; asArray(t, ar); if (ar.size() == 1) - niceInsert(ar[0]); + niceInsert(bv, ar[0]); else - insert(ar); + insert(bv, ar); } -void MathCursor::niceInsert(MathAtom const & t) +void MathCursor::niceInsert(BufferView & bv, MathAtom const & t) { - macroModeClose(); - string safe = grabAndEraseSelection(); - plainInsert(t); + macroModeClose(bv); + string safe = grabAndEraseSelection(bv); + plainInsert(bv, t); // enter the new inset and move the contents of the selection if possible if (t->isActive()) { - posLeft(); - pushLeft(nextAtom()); - paste(safe); + posLeft(bv); + pushLeft(bv, nextAtom(bv)); + paste(bv, safe); } } -void MathCursor::insert(MathArray const & ar) +void MathCursor::insert(BufferView & bv, MathArray const & ar) { - macroModeClose(); + CursorSlice & cur = cursorTip(bv); + macroModeClose(bv); if (selection_) - eraseSelection(); - array().insert(pos(), ar); - pos() += ar.size(); + eraseSelection(bv); + cur.cell().insert(cur.pos(), ar); + cur.pos() += ar.size(); } -void MathCursor::paste(string const & data) +void MathCursor::paste(BufferView & bv, string const & data) { - dispatch(FuncRequest(LFUN_PASTE, data)); + dispatch(bv, FuncRequest(LFUN_PASTE, data)); } -bool MathCursor::backspace() +bool MathCursor::backspace(BufferView & bv) { + CursorSlice & cur = cursorTip(bv); autocorrect_ = false; if (selection_) { - selDel(); + selDel(bv); return true; } - if (pos() == 0) { - if (inset()->ncols() == 1 && - inset()->nrows() == 1 && - depth() == 1 && - size() == 0) + if (cur.pos() == 0) { + if (cur.inset()->asMathInset()->nargs() == 1 && + depth(bv) == 1 && + cur.lastpos() == 0) return false; - pullArg(); + pullArg(bv); return true; } - if (inMacroMode()) { - MathUnknownInset * p = activeMacro(); + if (inMacroMode(bv)) { + MathUnknownInset * p = activeMacro(bv); if (p->name().size() > 1) { p->setName(p->name().substr(0, p->name().size() - 1)); return true; } } - if (hasPrevAtom() && prevAtom()->nargs() > 0) { + if (hasPrevAtom(bv) && prevAtom(bv)->nargs() > 0) { // let's require two backspaces for 'big stuff' and // highlight on the first - left(true); + left(bv, true); } else { - --pos(); - plainErase(); + --cur.pos(); + plainErase(bv); } return true; } -bool MathCursor::erase() +bool MathCursor::erase(BufferView & bv) { + CursorSlice & cur = cursorTip(bv); autocorrect_ = false; - if (inMacroMode()) + if (inMacroMode(bv)) return true; if (selection_) { - selDel(); + selDel(bv); return true; } // delete empty cells if possible - if (array().empty()) - if (inset()->idxDelete(idx())) - return true; +#warning FIXME + //if (cur.cell().empty() && cur.inset()->idxDelete(cur.idx())) + // return true; // special behaviour when in last position of cell - if (pos() == size()) { - bool one_cell = inset()->ncols() == 1 && inset()->nrows() == 1; - if (one_cell && depth() == 1 && size() == 0) + if (cur.pos() == cur.lastpos()) { + bool one_cell = cur.inset()->asMathInset()->nargs() == 1; + if (one_cell && depth(bv) == 1 && cur.lastpos() == 0) return false; // remove markup if (one_cell) - pullArg(); + pullArg(bv); else - inset()->idxGlue(idx()); + cur.inset()->asMathInset()->idxGlue(cur.idx()); return true; } - if (hasNextAtom() && nextAtom()->nargs() > 0) - right(true); + if (hasNextAtom(bv) && nextAtom(bv)->nargs() > 0) + right(bv, true); else - plainErase(); + plainErase(bv); return true; } -bool MathCursor::up(bool sel) +bool MathCursor::up(BufferView & bv, bool sel) { dump("up 1"); - macroModeClose(); - selHandle(sel); + macroModeClose(bv); + selHandle(bv, sel); #warning FIXME #if 0 CursorBase save = Cursor_; @@ -518,11 +528,11 @@ bool MathCursor::up(bool sel) } -bool MathCursor::down(bool sel) +bool MathCursor::down(BufferView & bv, bool sel) { dump("down 1"); - macroModeClose(); - selHandle(sel); + macroModeClose(bv); + selHandle(bv, sel); #warning FIXME #if 0 CursorBase save = Cursor_; @@ -535,15 +545,16 @@ bool MathCursor::down(bool sel) } -void MathCursor::macroModeClose() +void MathCursor::macroModeClose(BufferView & bv) { - if (!inMacroMode()) + CursorSlice & cur = cursorTip(bv); + if (!inMacroMode(bv)) return; - MathUnknownInset * p = activeMacro(); + MathUnknownInset * p = activeMacro(bv); p->finalize(); string s = p->name(); - --pos(); - array().erase(pos()); + --cur.pos(); + cur.cell().erase(cur.pos()); // do nothing if the macro name is empty if (s == "\\") @@ -556,28 +567,28 @@ void MathCursor::macroModeClose() && formula()->getInsetName() == name) lyxerr << "can't enter recursive macro" << endl; - niceInsert(createMathInset(name)); + niceInsert(bv, createMathInset(name)); } -string MathCursor::macroName() const +string MathCursor::macroName(BufferView & bv) const { - return inMacroMode() ? activeMacro()->name() : string(); + return inMacroMode(bv) ? activeMacro(bv)->name() : string(); } -void MathCursor::selClear() +void MathCursor::selClear(BufferView & bv) { - bv_->resetAnchor(); - bv_->clearSelection(); + bv.resetAnchor(); + bv.clearSelection(); } -void MathCursor::selCopy() +void MathCursor::selCopy(BufferView & bv) { dump("selCopy"); if (selection_) { - theCutBuffer.push(grabSelection()); + theCutBuffer.push(grabSelection(bv)); selection_ = false; } else { //theCutBuffer.erase(); @@ -585,58 +596,58 @@ void MathCursor::selCopy() } -void MathCursor::selCut() +void MathCursor::selCut(BufferView & bv) { dump("selCut"); - theCutBuffer.push(grabAndEraseSelection()); + theCutBuffer.push(grabAndEraseSelection(bv)); } -void MathCursor::selDel() +void MathCursor::selDel(BufferView & bv) { dump("selDel"); if (selection_) { - eraseSelection(); + eraseSelection(bv); selection_ = false; } } -void MathCursor::selPaste(size_t n) +void MathCursor::selPaste(BufferView & bv, size_t n) { dump("selPaste"); - selClearOrDel(); + selClearOrDel(bv); if (n < theCutBuffer.size()) - paste(theCutBuffer[n]); - //grabSelection(); + paste(bv, theCutBuffer[n]); + //grabSelection(bv); selection_ = false; } -void MathCursor::selHandle(bool sel) +void MathCursor::selHandle(BufferView & bv, bool sel) { if (sel == selection_) return; //clear(); - bv_->resetAnchor(); + bv.resetAnchor(); selection_ = sel; } -void MathCursor::selStart() +void MathCursor::selStart(BufferView & bv) { dump("selStart 1"); //clear(); - bv_->resetAnchor(); + bv.resetAnchor(); selection_ = true; dump("selStart 2"); } -void MathCursor::selClearOrDel() +void MathCursor::selClearOrDel(BufferView & bv) { if (lyxrc.auto_region_delete) - selDel(); + selDel(bv); else selection_ = false; } @@ -648,111 +659,84 @@ void MathCursor::drawSelection(PainterInfo & pi) const return; CursorSlice i1; CursorSlice i2; - getSelection(i1, i2); + getSelection(*pi.base.bv, i1, i2); i1.asMathInset()->drawSelection(pi, i1.idx_, i1.pos_, i2.idx_, i2.pos_); } -void MathCursor::handleNest(MathAtom const & a, int c) +void MathCursor::handleNest(BufferView & bv, MathAtom const & a, int c) { MathAtom at = a; - asArray(grabAndEraseSelection(), at.nucleus()->cell(c)); - insert(at); - pushRight(prevAtom()); + asArray(grabAndEraseSelection(bv), at.nucleus()->cell(c)); + insert(bv, at); + pushRight(bv, prevAtom(bv)); } -void MathCursor::getScreenPos(int & x, int & y) const +void MathCursor::getScreenPos(BufferView & bv, int & x, int & y) const { - inset()->getScreenPos(idx(), pos(), x, y); + CursorSlice & cur = cursorTip(bv); + cur.inset()->asMathInset()->getScreenPos(cur.idx(), cur.pos(), x, y); } -int MathCursor::targetX() const +int MathCursor::targetX(BufferView & bv) const { - if (bv_->x_target() != -1) - return bv_->x_target(); - int x = 0, y = 0; - getScreenPos(x, y); + if (bv.x_target() != -1) + return bv.x_target(); + int x = 0; + int y = 0; + getScreenPos(bv, x, y); return x; } -MathInset * MathCursor::inset() const -{ - return cursor().asMathInset(); -} - - InsetFormulaBase * MathCursor::formula() const { return formula_; } -MathCursor::idx_type MathCursor::idx() const -{ - return cursor().idx_; -} - - -MathCursor::idx_type & MathCursor::idx() -{ - return cursor().idx_; -} - - -MathCursor::pos_type MathCursor::pos() const -{ - return cursor().pos_; -} - - -void MathCursor::adjust(pos_type from, difference_type diff) -{ +void MathCursor::adjust(BufferView & bv, pos_type from, difference_type diff) +{ + CursorSlice & cur = cursorTip(bv); + if (cur.pos() > from) + cur.pos() += diff; #warning FIXME #if 0 - if (cursor().pos_ > from) - cursor().pos_ += diff; if (Anchor_.back().pos_ > from) Anchor_.back().pos_ += diff; // just to be on the safe side // theoretically unecessary - normalize(); #endif + normalize(bv); } -MathCursor::pos_type & MathCursor::pos() -{ - return cursor().pos_; -} - - -bool MathCursor::inMacroMode() const +bool MathCursor::inMacroMode(BufferView & bv) const { - if (!hasPrevAtom()) + if (!hasPrevAtom(bv)) return false; - MathUnknownInset const * p = prevAtom()->asUnknownInset(); + MathUnknownInset const * p = prevAtom(bv)->asUnknownInset(); return p && !p->final(); } -MathUnknownInset * MathCursor::activeMacro() +MathUnknownInset * MathCursor::activeMacro(BufferView & bv) { - return inMacroMode() ? prevAtom().nucleus()->asUnknownInset() : 0; + return inMacroMode(bv) ? prevAtom(bv).nucleus()->asUnknownInset() : 0; } -MathUnknownInset const * MathCursor::activeMacro() const +MathUnknownInset const * MathCursor::activeMacro(BufferView & bv) const { - return inMacroMode() ? prevAtom()->asUnknownInset() : 0; + return inMacroMode(bv) ? prevAtom(bv)->asUnknownInset() : 0; } -bool MathCursor::inMacroArgMode() const +bool MathCursor::inMacroArgMode(BufferView & bv) const { - return pos() > 0 && prevAtom()->getChar() == '#'; + return bv.cursor().pos() > 0 && prevAtom(bv)->getChar() == '#'; } @@ -762,7 +746,8 @@ bool MathCursor::selection() const } -MathGridInset * MathCursor::enclosingGrid(MathCursor::idx_type & idx) const +MathGridInset * MathCursor::enclosingGrid + (BufferView &, MathCursor::idx_type &) const { #warning FIXME #if 0 @@ -778,44 +763,36 @@ MathGridInset * MathCursor::enclosingGrid(MathCursor::idx_type & idx) const } -void MathCursor::popToHere(MathInset const * p) +void MathCursor::popToHere(BufferView & bv, MathInset const * p) { -#warning FIXME -#if 0 - while (depth() && Cursor_.back().asMathInset() != p) - Cursor_.pop_back(); -#endif + while (depth(bv) && bv.cursor().asMathInset() != p) + bv.fullCursor().cursor_.pop_back(); } -void MathCursor::popToEnclosingGrid() +void MathCursor::popToEnclosingGrid(BufferView & bv) { -#warning FIXME -#if 0 - while (depth() && !Cursor_.back().asMathInset()->asGridInset()) - Cursor_.pop_back(); -#endif + while (depth(bv) && !bv.cursor().asMathInset()->asGridInset()) + bv.fullCursor().cursor_.pop_back(); } -void MathCursor::popToEnclosingHull() +void MathCursor::popToEnclosingHull(BufferView & bv) { -#warning FIXME -#if 0 - while (depth() && !Cursor_.back().asMathInset()->asHullInset()) - Cursor_.pop_back(); -#endif + while (depth(bv) && !bv.cursor().asMathInset()->asGridInset()) + bv.fullCursor().cursor_.pop_back(); } -void MathCursor::pullArg() +void MathCursor::pullArg(BufferView & bv) { + CursorSlice & cur = cursorTip(bv); dump("pullarg"); - MathArray a = array(); - if (popLeft()) { - plainErase(); - array().insert(pos(), a); - bv_->resetAnchor(); + MathArray ar = cur.cell(); + if (popLeft(bv)) { + plainErase(bv); + cur.cell().insert(cur.pos(), ar); + bv.resetAnchor(); } else { formula()->mutateToText(); } @@ -834,183 +811,157 @@ void MathCursor::touch() } -void MathCursor::normalize() +void MathCursor::normalize(BufferView & bv) { - if (idx() >= inset()->nargs()) { + CursorSlice & cur = cursorTip(bv); + if (cur.idx() >= cur.nargs()) { lyxerr << "this should not really happen - 1: " - << idx() << ' ' << inset()->nargs() - << " in: " << inset() << endl; + << cur.idx() << ' ' << cur.nargs() + << " in: " << cur.inset() << endl; dump("error 2"); } - idx() = min(idx(), inset()->nargs() - 1); + cur.idx() = min(cur.idx(), cur.nargs() - 1); - if (pos() > size()) { + if (cur.pos() > cur.lastpos()) { lyxerr << "this should not really happen - 2: " - << pos() << ' ' << size() << " in idx: " << idx() + << cur.pos() << ' ' << cur.lastpos() << " in idx: " << cur.idx() << " in atom: '"; WriteStream wi(lyxerr, false, true); - inset()->write(wi); + cur.inset()->asMathInset()->write(wi); lyxerr << endl; dump("error 4"); } - pos() = pos() < size() ? pos() : size(); + cur.pos() = min(cur.pos(), cur.lastpos()); } -MathCursor::size_type MathCursor::size() const +bool MathCursor::hasPrevAtom(BufferView & bv) const { - return array().size(); + CursorSlice & cur = cursorTip(bv); + return cur.pos() > 0; } -bool MathCursor::hasPrevAtom() const +bool MathCursor::hasNextAtom(BufferView & bv) const { - return pos() > 0; + CursorSlice & cur = cursorTip(bv); + return cur.pos() < cur.lastpos(); } -bool MathCursor::hasNextAtom() const +MathAtom const & MathCursor::prevAtom(BufferView & bv) const { - return pos() < size(); + CursorSlice & cur = cursorTip(bv); + BOOST_ASSERT(cur.pos() > 0); + return cur.cell()[cur.pos() - 1]; } -MathAtom const & MathCursor::prevAtom() const +MathAtom & MathCursor::prevAtom(BufferView & bv) { - BOOST_ASSERT(pos() > 0); - return array()[pos() - 1]; + CursorSlice & cur = cursorTip(bv); + BOOST_ASSERT(cur.pos() > 0); + return cur.cell()[cur.pos() - 1]; } -MathAtom & MathCursor::prevAtom() +MathAtom const & MathCursor::nextAtom(BufferView & bv) const { - BOOST_ASSERT(pos() > 0); - return array()[pos() - 1]; + CursorSlice & cur = cursorTip(bv); + BOOST_ASSERT(cur.pos() < cur.lastpos()); + return cur.cell()[cur.pos()]; } -MathAtom const & MathCursor::nextAtom() const +MathAtom & MathCursor::nextAtom(BufferView & bv) { - BOOST_ASSERT(pos() < size()); - return array()[pos()]; + CursorSlice & cur = cursorTip(bv); + BOOST_ASSERT(cur.pos() < cur.lastpos()); + return cur.cell()[cur.pos()]; } -MathAtom & MathCursor::nextAtom() +void MathCursor::idxNext(BufferView & bv) { - BOOST_ASSERT(pos() < size()); - return array()[pos()]; + CursorSlice & cur = cursorTip(bv); + cur.inset()->asMathInset()->idxNext(bv); } -MathArray & MathCursor::array() const +void MathCursor::idxPrev(BufferView & bv) { - static MathArray dummy; - - if (idx() >= inset()->nargs()) { - lyxerr << "############ idx_ " << idx() << " not valid" << endl; - return dummy; - } - - if (depth() == 0) { - lyxerr << "############ depth() == 0 not valid" << endl; - return dummy; - } - - return cursor().cell(); + CursorSlice & cur = cursorTip(bv); + cur.inset()->asMathInset()->idxPrev(bv); } -void MathCursor::idxNext() -{ - inset()->idxNext(*bv_); -} - - -void MathCursor::idxPrev() -{ - inset()->idxPrev(*bv_); -} - - -char MathCursor::valign() const +char MathCursor::valign(BufferView & bv) const { idx_type idx; - MathGridInset * p = enclosingGrid(idx); + MathGridInset * p = enclosingGrid(bv, idx); return p ? p->valign() : '\0'; } -char MathCursor::halign() const +char MathCursor::halign(BufferView & bv) const { idx_type idx; - MathGridInset * p = enclosingGrid(idx); + MathGridInset * p = enclosingGrid(bv, idx); return p ? p->halign(idx % p->ncols()) : '\0'; } -void MathCursor::getSelection(CursorSlice & i1, CursorSlice & i2) const +void MathCursor::getSelection(BufferView & bv, + CursorSlice & i1, CursorSlice & i2) const { - CursorSlice anc = normalAnchor(); - if (anc < cursor()) { + CursorSlice anc = normalAnchor(bv); + if (anc < bv.cursor()) { i1 = anc; - i2 = cursor(); + i2 = bv.cursor(); } else { - i1 = cursor(); + i1 = bv.cursor(); i2 = anc; } } -CursorSlice & MathCursor::cursor() -{ - return bv_->cursor(); -} - - -CursorSlice const & MathCursor::cursor() const -{ - return bv_->cursor(); -} - - -bool MathCursor::goUpDown(bool up) +bool MathCursor::goUpDown(BufferView & bv, 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(xo, yo); + getScreenPos(bv, 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 (bv.x_target() == -1) + bv.x_target(xo); else - xo = bv_->x_target(); + xo = bv.x_target(); // try neigbouring script insets if (!selection()) { // try left - if (hasPrevAtom()) { - MathScriptInset const * p = prevAtom()->asScriptInset(); + if (hasPrevAtom(bv)) { + MathScriptInset const * p = prevAtom(bv)->asScriptInset(); if (p && p->has(up)) { - --pos(); - push(nextAtom()); - idx() = up; // the superscript has index 1 - pos() = size(); + --bv.cursor().pos(); + push(bv, nextAtom(bv)); + bv.cursor().idx() = up; // the superscript has index 1 + bv.cursor().pos() = bv.cursor().lastpos(); //lyxerr << "updown: handled by scriptinset to the left" << endl; return true; } } // try right - if (hasNextAtom()) { - MathScriptInset const * p = nextAtom()->asScriptInset(); + if (hasNextAtom(bv)) { + MathScriptInset const * p = nextAtom(bv)->asScriptInset(); if (p && p->has(up)) { - push(nextAtom()); - idx() = up; - pos() = 0; + push(bv, nextAtom(bv)); + bv.cursor().idx() = up; + bv.cursor().pos() = 0; //lyxerr << "updown: handled by scriptinset to the right" << endl; return true; } @@ -1018,7 +969,7 @@ bool MathCursor::goUpDown(bool up) } // try current cell for e.g. text insets - if (inset()->idxUpDown2(*bv_, up, bv_->x_target())) + if (bv.cursor().inset()->asMathInset()->idxUpDown2(bv, up, bv.x_target())) return true; //xarray().boundingBox(xlow, xhigh, ylow, yhigh); @@ -1035,18 +986,18 @@ bool MathCursor::goUpDown(bool up) while (1) { //lyxerr << "updown: We are in " << inset() << " idx: " << idx() << endl; // ask inset first - if (inset()->idxUpDown(*bv_, up, bv_->x_target())) { + if (bv.cursor().inset()->asMathInset()->idxUpDown(bv, up, bv.x_target())) { // try to find best position within this inset if (!selection()) - bruteFind2(xo, yo); + bruteFind2(bv, xo, yo); return true; } // no such inset found, just take something "above" //lyxerr << "updown: handled by strange case" << endl; - if (!popLeft()) + if (!popLeft(bv)) return - bruteFind(xo, yo, + bruteFind(bv, xo, yo, formula()->xlow(), formula()->xhigh(), up ? formula()->ylow() : yo + 4, @@ -1055,7 +1006,7 @@ bool MathCursor::goUpDown(bool up) // any improvement so far? int xnew, ynew; - getScreenPos(xnew, ynew); + getScreenPos(bv, xnew, ynew); if (up ? ynew < yo : ynew > yo) return true; } @@ -1063,9 +1014,8 @@ bool MathCursor::goUpDown(bool up) bool MathCursor::bruteFind - (int x, int y, int xlow, int xhigh, int ylow, int yhigh) + (BufferView & bv, int x, int y, int xlow, int xhigh, int ylow, int yhigh) { -#if 0 CursorBase best_cursor; double best_dist = 1e10; @@ -1073,7 +1023,7 @@ bool MathCursor::bruteFind CursorBase et = iend(formula()->par().nucleus()); while (1) { // avoid invalid nesting when selecting - if (!selection_ || positionable(it, Anchor_)) { + if (!selection_ || positionable(it, bv.fullCursor().anchor_)) { int xo, yo; it.back().getScreenPos(xo, yo); if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) { @@ -1093,23 +1043,19 @@ bool MathCursor::bruteFind increment(it); } -#warning FIXME - //if (best_dist < 1e10) - // Cursor_ = best_cursor; + if (best_dist < 1e10) + bv.fullCursor().cursor_ = best_cursor; return best_dist < 1e10; -#endif - return 0; } -void MathCursor::bruteFind2(int x, int y) +void MathCursor::bruteFind2(BufferView & bv, int x, int y) { -#if 0 double best_dist = 1e10; - CursorBase it = bv_->fullCursor().cursor_; + CursorBase it = bv.fullCursor().cursor_; it.back().pos(0); - CursorBase et = bv_->fullCursor().cursor_; + CursorBase et = bv.fullCursor().cursor_; int n = et.back().asMathInset()->cell(et.back().idx_).size(); et.back().pos(n); for (int i = 0; ; ++i) { @@ -1121,129 +1067,132 @@ void MathCursor::bruteFind2(int x, int y) lyxerr << "i: " << i << " d: " << d << " best: " << best_dist << endl; if (d <= best_dist) { best_dist = d; - Cursor_ = it; + bv.fullCursor().cursor_ = it; } if (it == et) break; increment(it); } -#endif } -bool MathCursor::idxLineLast() +bool MathCursor::idxLineLast(BufferView & bv) { - idx() -= idx() % inset()->ncols(); - idx() += inset()->ncols() - 1; - pos() = size(); + CursorSlice & cur = bv.cursor(); + cur.idx() -= cur.idx() % cur.ncols(); + cur.idx() += cur.ncols() - 1; + cur.pos() = cur.lastpos(); return true; } -bool MathCursor::idxLeft() + +bool MathCursor::idxLeft(BufferView & bv) { - return inset()->idxLeft(*bv_); + return bv.cursor().inset()->asMathInset()->idxLeft(bv); } -bool MathCursor::idxRight() +bool MathCursor::idxRight(BufferView & bv) { - return inset()->idxRight(*bv_); + return bv.cursor().inset()->asMathInset()->idxRight(bv); } -bool MathCursor::script(bool up) +bool MathCursor::script(BufferView & bv, bool up) { // Hack to get \\^ and \\_ working - if (inMacroMode() && macroName() == "\\") { + if (inMacroMode(bv) && macroName(bv) == "\\") { if (up) - niceInsert(createMathInset("mathcircumflex")); + niceInsert(bv, createMathInset("mathcircumflex")); else - interpret('_'); + interpret(bv, '_'); return true; } - macroModeClose(); - string safe = grabAndEraseSelection(); - if (inNucleus()) { + macroModeClose(bv); + string safe = grabAndEraseSelection(bv); + if (inNucleus(bv)) { // we are in a nucleus of a script inset, move to _our_ script - inset()->asScriptInset()->ensure(up); - idx() = up; - pos() = 0; - } else if (hasPrevAtom() && prevAtom()->asScriptInset()) { - prevAtom().nucleus()->asScriptInset()->ensure(up); - pushRight(prevAtom()); - idx() = up; - pos() = size(); - } else if (hasPrevAtom()) { - --pos(); - array()[pos()] = MathAtom(new MathScriptInset(nextAtom(), up)); - pushLeft(nextAtom()); - idx() = up; - pos() = 0; + 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; } else { - plainInsert(MathAtom(new MathScriptInset(up))); - prevAtom().nucleus()->asScriptInset()->ensure(up); - pushRight(prevAtom()); - idx() = up; - pos() = 0; + plainInsert(bv, MathAtom(new MathScriptInset(up))); + prevAtom(bv).nucleus()->asScriptInset()->ensure(up); + pushRight(bv, prevAtom(bv)); + bv.cursor().idx() = up; + bv.cursor().pos() = 0; } - paste(safe); + paste(bv, safe); dump("1"); return true; } -bool MathCursor::interpret(char c) +bool MathCursor::interpret(BufferView & bv, char c) { //lyxerr << "interpret 2: '" << c << "'" << endl; - bv_->x_target(-1); // "no target" - if (inMacroArgMode()) { - --pos(); - plainErase(); + CursorSlice & cur = bv.cursor(); + bv.x_target(-1); // "no target" + if (inMacroArgMode(bv)) { + --cur.pos(); + plainErase(bv); int n = c - '0'; MathMacroTemplate const * p = formula()->par()->asMacroTemplate(); if (p && 1 <= n && n <= p->numargs()) - insert(MathAtom(new MathMacroArgument(c - '0'))); + insert(bv, MathAtom(new MathMacroArgument(c - '0'))); else { - insert(createMathInset("#")); - interpret(c); // try again + insert(bv, createMathInset("#")); + interpret(bv, c); // try again } return true; } // handle macroMode - if (inMacroMode()) { - string name = macroName(); + if (inMacroMode(bv)) { + string name = macroName(bv); //lyxerr << "interpret name: '" << name << "'" << endl; if (isalpha(c)) { - activeMacro()->setName(activeMacro()->name() + c); + activeMacro(bv)->setName(activeMacro(bv)->name() + c); return true; } // handle 'special char' macros if (name == "\\") { // remove the '\\' - backspace(); + backspace(bv); if (c == '\\') { - if (currentMode() == MathInset::TEXT_MODE) - niceInsert(createMathInset("textbackslash")); + if (currentMode(bv) == MathInset::TEXT_MODE) + niceInsert(bv, createMathInset("textbackslash")); else - niceInsert(createMathInset("backslash")); + niceInsert(bv, createMathInset("backslash")); } else if (c == '{') { - niceInsert(MathAtom(new MathBraceInset)); + niceInsert(bv, MathAtom(new MathBraceInset)); } else { - niceInsert(createMathInset(string(1, c))); + niceInsert(bv, createMathInset(string(1, c))); } return true; } // leave macro mode and try again if necessary - macroModeClose(); + macroModeClose(bv); if (c == '{') - niceInsert(MathAtom(new MathBraceInset)); + niceInsert(bv, MathAtom(new MathBraceInset)); else if (c != ' ') - interpret(c); + interpret(bv, c); return true; } @@ -1264,57 +1213,57 @@ bool MathCursor::interpret(char c) return true; } - selClearOrDel(); + selClearOrDel(bv); if (c == '\\') { //lyxerr << "starting with macro" << endl; - insert(MathAtom(new MathUnknownInset("\\", false))); + insert(bv, MathAtom(new MathUnknownInset("\\", false))); return true; } if (c == '\n') { - if (currentMode() == MathInset::TEXT_MODE) - insert(c); + if (currentMode(bv) == MathInset::TEXT_MODE) + insert(bv, c); return true; } if (c == ' ') { - if (currentMode() == MathInset::TEXT_MODE) { + if (currentMode(bv) == 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() || prevAtom()->getChar() != ' ') - insert(c); + if (!hasPrevAtom(bv) || prevAtom(bv)->getChar() != ' ') + insert(bv, c); return true; } - if (hasPrevAtom() && prevAtom()->asSpaceInset()) { - prevAtom().nucleus()->asSpaceInset()->incSpace(); + if (hasPrevAtom(bv) && prevAtom(bv)->asSpaceInset()) { + prevAtom(bv).nucleus()->asSpaceInset()->incSpace(); return true; } - if (popRight()) + if (popRight(bv)) return true; // if are at the very end, leave the formula - return pos() != size(); + return cur.pos() != cur.lastpos(); } if (c == '_') { - script(false); + script(bv, false); return true; } if (c == '^') { - script(true); + script(bv, true); return true; } if (c == '{' || c == '}' || c == '#' || c == '&' || c == '$') { - niceInsert(createMathInset(string(1, c))); + niceInsert(bv, createMathInset(string(1, c))); return true; } if (c == '%') { - niceInsert(MathAtom(new MathCommentInset)); + niceInsert(bv, MathAtom(new MathCommentInset)); return true; } @@ -1323,56 +1272,53 @@ bool MathCursor::interpret(char c) // return true; // no special circumstances, so insert the character without any fuss - insert(c); + insert(bv, c); autocorrect_ = true; return true; } -void MathCursor::setSelection(CursorBase const & where, size_type n) +void MathCursor::setSelection + (BufferView & bv, CursorBase const & where, size_t n) { -#warning FIXME -#if 0 selection_ = true; - Anchor_ = where; - Cursor_ = where; - cursor().pos_ += n; -#endif + bv.fullCursor().cursor_ = where; + bv.fullCursor().anchor_ = where; + bv.cursor().pos_ += n; } -void MathCursor::insetToggle() +void MathCursor::insetToggle(BufferView & bv) { - if (hasNextAtom()) { + if (hasNextAtom(bv)) { // toggle previous inset ... - nextAtom().nucleus()->lock(!nextAtom()->lock()); - } else if (popLeft() && hasNextAtom()) { + nextAtom(bv).nucleus()->lock(!nextAtom(bv)->lock()); + } else if (popLeft(bv) && hasNextAtom(bv)) { // ... or enclosing inset if we are in the last inset position - nextAtom().nucleus()->lock(!nextAtom()->lock()); - posRight(); + nextAtom(bv).nucleus()->lock(!nextAtom(bv)->lock()); + posRight(bv); } } -string MathCursor::info() const +string MathCursor::info(BufferView & bv) const { ostringstream os; os << "Math editor mode. "; - for (int i = 0, n = depth(); i < n; ++i) { -#warning FIXME - //Cursor_[i].asMathInset()->infoize(os); + for (int i = 0, n = depth(bv); i < n; ++i) { + bv.fullCursor().cursor_[i].asMathInset()->infoize(os); os << " "; } - if (hasPrevAtom()) - prevAtom()->infoize2(os); + if (hasPrevAtom(bv)) + prevAtom(bv)->infoize2(os); os << " "; return os.str(); } -unsigned MathCursor::depth() const +unsigned MathCursor::depth(BufferView & bv) const { - return bv_->fullCursor().cursor_.size(); + return bv.fullCursor().cursor_.size(); } @@ -1398,14 +1344,14 @@ void region(CursorSlice const & i1, CursorSlice const & i2, } -string MathCursor::grabSelection() const +string MathCursor::grabSelection(BufferView & bv) const { if (!selection_) return string(); CursorSlice i1; CursorSlice i2; - getSelection(i1, i2); + getSelection(bv, i1, i2); if (i1.idx_ == i2.idx_) { MathArray::const_iterator it = i1.cell().begin(); @@ -1430,11 +1376,11 @@ string MathCursor::grabSelection() const } -void MathCursor::eraseSelection() +void MathCursor::eraseSelection(BufferView & bv) { CursorSlice i1; CursorSlice i2; - getSelection(i1, i2); + getSelection(bv, i1, i2); if (i1.idx_ == i2.idx_) i1.cell().erase(i1.pos_, i2.pos_); else { @@ -1446,27 +1392,27 @@ void MathCursor::eraseSelection() for (col_type col = c1; col <= c2; ++col) p->cell(p->index(row, col)).clear(); } - cursor() = i1; + bv.cursor() = i1; } -string MathCursor::grabAndEraseSelection() +string MathCursor::grabAndEraseSelection(BufferView & bv) { if (!selection_) return string(); - string res = grabSelection(); - eraseSelection(); + string res = grabSelection(bv); + eraseSelection(bv); selection_ = false; return res; } -CursorSlice MathCursor::normalAnchor() const +CursorSlice MathCursor::normalAnchor(BufferView & bv) const { #warning FIXME #if 0 if (Anchor_.size() < depth()) { - bv_->resetAnchor(); + bv.resetAnchor(); lyxerr << "unusual Anchor size" << endl; } //lyx::BOOST_ASSERT(Anchor_.size() >= cursor.depth()); @@ -1478,14 +1424,13 @@ CursorSlice MathCursor::normalAnchor() const } return normal; #else - return cursor(); + return bv.cursor(); #endif } -DispatchResult MathCursor::dispatch(FuncRequest const & cmd) +DispatchResult MathCursor::dispatch(BufferView &, FuncRequest const & cmd) { -/* // mouse clicks are somewhat special // check switch (cmd.action) { @@ -1493,30 +1438,32 @@ DispatchResult MathCursor::dispatch(FuncRequest const & cmd) case LFUN_MOUSE_MOTION: case LFUN_MOUSE_RELEASE: case LFUN_MOUSE_DOUBLE: { +/* CursorSlice & pos = Cursor_.back(); int x = 0; int y = 0; getScreenPos(x, y); if (x < cmd.x && hasPrevAtom()) { DispatchResult const res = - prevAtom().nucleus()->dispatch(cmd, pos.idx_, pos.pos_); + prevAtom().nucleus()->dispatch(bv, cmd); if (res.dispatched()) return res; } if (x > cmd.x && hasNextAtom()) { DispatchResult const res = - nextAtom().nucleus()->dispatch(cmd, pos.idx_, pos.pos_); + nextAtom().nucleus()->dispatch(bv, cmd); if (res.dispatched()) return res; } +*/ } default: break; } +/* for (int i = Cursor_.size() - 1; i >= 0; --i) { CursorBase tmp = bv->Cursor_; - bv CursorSlice & pos = tmp.back() DispatchResult const res = pos.asMathInset()->dispatch(bv, cmd); if (res.dispatched()) { @@ -1533,9 +1480,8 @@ DispatchResult MathCursor::dispatch(FuncRequest const & cmd) } -MathInset::mode_type MathCursor::currentMode() const +MathInset::mode_type MathCursor::currentMode(BufferView &) const { -#warning FIXME #if 0 for (int i = Cursor_.size() - 1; i >= 0; --i) { MathInset::mode_type res = Cursor_[i].asMathInset()->currentMode(); @@ -1547,37 +1493,38 @@ MathInset::mode_type MathCursor::currentMode() const } -void MathCursor::handleFont(string const & font) +void MathCursor::handleFont(BufferView & bv, string const & font) { + CursorSlice cur = cursorTip(bv); string safe; if (selection()) { - macroModeClose(); - safe = grabAndEraseSelection(); + macroModeClose(bv); + safe = grabAndEraseSelection(bv); } - if (array().size()) { + if (cur.lastpos() != 0) { // something left in the cell - if (pos() == 0) { + if (cur.pos() == 0) { // cursor in first position - popLeft(); - } else if (pos() == array().size()) { + popLeft(bv); + } else if (cur.pos() == cur.lastpos()) { // cursor in last position - popRight(); + popRight(bv); } else { // cursor in between. split cell - MathArray::iterator bt = array().begin(); + MathArray::iterator bt = cur.cell().begin(); MathAtom at = createMathInset(font); - at.nucleus()->cell(0) = MathArray(bt, bt + pos()); - cursor().cell().erase(bt, bt + pos()); - popLeft(); - plainInsert(at); + at.nucleus()->cell(0) = MathArray(bt, bt + cur.pos()); + cur.cell().erase(bt, bt + cur.pos()); + popLeft(bv); + plainInsert(bv, at); } } else { // nothing left in the cell - pullArg(); - plainErase(); + pullArg(bv); + plainErase(bv); } - insert(safe); + insert(bv, safe); } @@ -1587,6 +1534,6 @@ void releaseMathCursor(BufferView & bv) InsetFormulaBase * f = mathcursor->formula(); delete mathcursor; mathcursor = 0; - f->insetUnlock(&bv); + f->insetUnlock(bv); } } diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index 23c94a7ed7..7e4994de4c 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -56,228 +56,209 @@ public: /// ~MathCursor(); /// - void insert(MathAtom const &); + void insert(BufferView & bv, MathAtom const &); /// - void insert(MathArray const &); + void insert(BufferView & bv, MathArray const &); /// - void insert2(std::string const &); + void insert2(BufferView & bv, std::string const &); /// - void paste(std::string const & data); + void paste(BufferView & bv, std::string const & data); /// return false for empty math insets - bool erase(); + bool erase(BufferView & bv); /// return false for empty math insets - bool backspace(); + bool backspace(BufferView & bv); /// called for LFUN_HOME etc - bool home(bool sel = false); + bool home(BufferView & bv, bool sel = false); /// called for LFUN_END etc - bool end(bool sel = false); + bool end(BufferView & bv, bool sel = false); /// called for LFUN_RIGHT and LFUN_RIGHTSEL - bool right(bool sel = false); + bool right(BufferView & bv, bool sel = false); /// called for LFUN_LEFT etc - bool left(bool sel = false); + bool left(BufferView & bv, bool sel = false); /// called for LFUN_UP etc - bool up(bool sel = false); + bool up(BufferView & bv, bool sel = false); /// called for LFUN_DOWN etc - bool down(bool sel = false); + bool down(BufferView & bv, bool sel = false); /// Put the cursor in the first position - void first(); + void first(BufferView & bv); /// Put the cursor in the last position - void last(); + void last(BufferView & bv); /// move to next cell in current inset - void idxNext(); + void idxNext(BufferView & bv); /// move to previous cell in current inset - void idxPrev(); + void idxPrev(BufferView & bv); /// - void plainErase(); + void plainErase(BufferView & bv); /// - void plainInsert(MathAtom const &); + void plainInsert(BufferView & bv, MathAtom const & at); /// - void niceInsert(MathAtom const &); + void niceInsert(BufferView & bv, MathAtom const & at); /// - void niceInsert(std::string const &); + void niceInsert(BufferView & bv, std::string const & str); /// in pixels from top of screen - void setScreenPos(int x, int y); + void setScreenPos(BufferView & bv, int x, int y); /// in pixels from top of screen - void getScreenPos(int & x, int & y) const; + void getScreenPos(BufferView & bv, int & x, int & y) const; /// in pixels from left of screen - int targetX() const; - /// current inset - MathInset * inset() const; + int targetX(BufferView & bv) const; /// return the next enclosing grid inset and the cursor's index in it - MathGridInset * enclosingGrid(idx_type & idx) const; + MathGridInset * enclosingGrid(BufferView & bv, idx_type & idx) const; /// go up to enclosing grid - void popToEnclosingGrid(); + void popToEnclosingGrid(BufferView & bv); /// go up to the hull inset - void popToEnclosingHull(); + void popToEnclosingHull(BufferView & bv); /// go up to the hull inset - void popToHere(MathInset const * p); + void popToHere(BufferView & bv, MathInset const * p); /// adjust anchor position after deletions/insertions - void adjust(pos_type from, difference_type diff); + void adjust(BufferView & bv, pos_type from, difference_type diff); /// InsetFormulaBase * formula() const; /// current offset in the current cell - pos_type pos() const; - /// current cell - idx_type idx() const; - /// size of current cell - size_type size() const; /// - bool script(bool); + bool script(BufferView & bv, bool); /// - bool interpret(char); + bool interpret(BufferView & bv, char); /// interpret name a name of a macro - void macroModeClose(); + void macroModeClose(BufferView & bv); /// are we currently typing the name of a macro? - bool inMacroMode() const; + bool inMacroMode(BufferView & bv) const; /// get access to the macro we are currently typing - MathUnknownInset * activeMacro(); + MathUnknownInset * activeMacro(BufferView & bv); /// get access to the macro we are currently typing - MathUnknownInset const * activeMacro() const; + MathUnknownInset const * activeMacro(BufferView & bv) const; /// are we currently typing '#1' or '#2' or...? - bool inMacroArgMode() const; + bool inMacroArgMode(BufferView & bv) const; /// are we in math mode (1), text mode (-1) or unsure? - MathInset::mode_type currentMode() const; + MathInset::mode_type currentMode(BufferView & bv) const; // Local selection methods /// bool selection() const; /// - void selCopy(); + void selCopy(BufferView & bv); /// - void selCut(); + void selCut(BufferView & bv); /// - void selDel(); + void selDel(BufferView & bv); /// pastes n-th element of cut buffer - void selPaste(size_t n); + void selPaste(BufferView & bv, size_t n); /// - void selHandle(bool); + void selHandle(BufferView & bv, bool); /// - void selStart(); + void selStart(BufferView & bv); /// - void selClear(); + void selClear(BufferView & bv); /// clears or deletes selection depending on lyxrc setting - void selClearOrDel(); + void selClearOrDel(BufferView & bv); /// 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(MathAtom const & at, int cell = 0); + void handleNest(BufferView & bv, 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() const; + char valign(BufferView & bv) const; /// - char halign() const; + char halign(BufferView & bv) const; /// make sure cursor position is valid - void normalize(); + void normalize(BufferView & bv); /// mark current cursor trace for redraw void touch(); - /// - UpdatableInset * asHyperActiveInset() const; /// enter a MathInset - void push(MathAtom & par); + void push(BufferView & bv, MathAtom & par); /// enter a MathInset from the front - void pushLeft(MathAtom & par); + void pushLeft(BufferView & bv, MathAtom & par); /// enter a MathInset from the back - void pushRight(MathAtom & par); + void pushRight(BufferView & bv, MathAtom & par); /// leave current MathInset to the left - bool popLeft(); + bool popLeft(BufferView & bv); /// leave current MathInset to the left - bool popRight(); + bool popRight(BufferView & bv); /// - MathArray & array() const; - /// - bool hasPrevAtom() const; + bool hasPrevAtom(BufferView & bv) const; /// - bool hasNextAtom() const; + bool hasNextAtom(BufferView & bv) const; /// - MathAtom const & prevAtom() const; + MathAtom const & prevAtom(BufferView & bv) const; /// - MathAtom & prevAtom(); + MathAtom & prevAtom(BufferView & bv); /// - MathAtom const & nextAtom() const; + MathAtom const & nextAtom(BufferView & bv) const; /// - MathAtom & nextAtom(); + MathAtom & nextAtom(BufferView & bv); /// returns the selection - void getSelection(CursorSlice &, CursorSlice &) const; + void getSelection(BufferView & bv, CursorSlice &, CursorSlice &) const; /// returns the normalized anchor of the selection - CursorSlice normalAnchor() const; + CursorSlice normalAnchor(BufferView & bv) const; - /// reference to the last item of the path, i.e. "The Cursor" - CursorSlice & cursor(); - /// reference to the last item of the path, i.e. "The Cursor" - CursorSlice const & cursor() const; /// how deep are we nested? - unsigned depth() const; + unsigned depth(BufferView & bv) const; /// describe the situation - std::string info() const; + std::string info(BufferView & bv) 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(CursorBase const & where, size_type n); + void setSelection(BufferView & bv, CursorBase const & where, size_type n); /// grab selection marked by anchor and current cursor - std::string grabSelection() const; + std::string grabSelection(BufferView & bv) const; /// guess what - std::string grabAndEraseSelection(); + std::string grabAndEraseSelection(BufferView & bv); /// - void insert(char c); + void insert(BufferView & bv, char c); /// - void insert(std::string const & str); + void insert(BufferView & bv, std::string const & str); /// lock/unlock inset - void insetToggle(); + void insetToggle(BufferView & bv); /// hack for reveal codes - void markInsert(); - void markErase(); + void markInsert(BufferView & bv); + void markErase(BufferView & bv); /// injects content of a cell into parent - void pullArg(); + void pullArg(BufferView & bv); /// split font inset etc - void handleFont(std::string const & font); + void handleFont(BufferView & bv, std::string const & font); /// - DispatchResult - dispatch(FuncRequest const & cmd); + DispatchResult dispatch(BufferView & bv, FuncRequest const & cmd); private: /// moves cursor index one cell to the left - bool idxLeft(); + bool idxLeft(BufferView & bv); /// moves cursor index one cell to the right - bool idxRight(); + bool idxRight(BufferView & bv); /// moves cursor to end of last cell of current line - bool idxLineLast(); + bool idxLineLast(BufferView & bv); /// moves cursor position one cell to the left - bool posLeft(); + bool posLeft(BufferView & bv); /// moves cursor position one cell to the right - bool posRight(); + bool posRight(BufferView & bv); /// moves position somehow up or down - bool goUpDown(bool up); + bool goUpDown(BufferView & bv, bool up); /// moves position closest to (x, y) in given box - bool bruteFind(int x, int y, int xlow, int xhigh, int ylow, int yhigh); + bool bruteFind(BufferView & bv, + int x, int y, int xlow, int xhigh, int ylow, int yhigh); /// moves position closest to (x, y) in current cell - void bruteFind2(int x, int y); + void bruteFind2(BufferView & bv, int x, int y); /// are we in a nucleus of a script inset? - bool inNucleus() const; + bool inNucleus(BufferView & bv) const; /// erase the selected part and re-sets the cursor - void eraseSelection(); + void eraseSelection(BufferView & bv); /// the name of the macro we are currently inputting - std::string macroName() const; + std::string macroName(BufferView & bv) const; /// where in the curent cell does the macro name start? - difference_type macroNamePos() const; + difference_type macroNamePos(BufferView & bv) const; /// can we enter the inset? bool openable(MathAtom const &, bool selection) const; - /// write access to cursor cell position - pos_type & pos(); - /// write access to cursor cell index - idx_type & idx(); /// pointer to enclsing LyX inset InsetFormulaBase * formula_; @@ -290,8 +271,6 @@ private: bool selection_; /// are we entering a macro name? bool macromode_; - /// - BufferView * bv_; }; extern MathCursor * mathcursor; diff --git a/src/mathed/math_data.C b/src/mathed/math_data.C index 35c727e263..028d213e5a 100644 --- a/src/mathed/math_data.C +++ b/src/mathed/math_data.C @@ -403,6 +403,7 @@ void MathArray::notifyCursorLeaves() { // do not recurse! +/* // remove base-only "scripts" for (pos_type i = 0; i + 1 < size(); ++i) { MathScriptInset * p = operator[](i).nucleus()->asScriptInset(); @@ -424,5 +425,5 @@ void MathArray::notifyCursorLeaves() mathcursor->adjust(i, -1); } } - +*/ } diff --git a/src/mathed/math_hullinset.C b/src/mathed/math_hullinset.C index c1b6771167..4926e1456e 100644 --- a/src/mathed/math_hullinset.C +++ b/src/mathed/math_hullinset.C @@ -728,7 +728,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(), ar); + asArray(mathcursor->grabAndEraseSelection(bv), ar); } else if (pos == cur.cell().size()) { ar = cur.cell(); lyxerr << "use whole cell: " << ar << endl; -- 2.39.5