From: André Pönitz Date: Thu, 15 Jan 2004 17:34:44 +0000 (+0000) Subject: the monster patch X-Git-Tag: 1.6.10~15566 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=70d0ba900118ac7e253c1e1969fd7a3d64ec8e03;p=lyx.git the monster patch mathed is completely broken, but it's difficult to imprevo with such a big patch in the tree. If things don't improve until tomorrow evening, I'll revert this. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8357 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index c751f2771b..97b946aedf 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -914,16 +914,16 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd) case LFUN_MOUSE_MOTION: { if (!available()) return false; - FuncRequest cmd1(cmd, bv_); + FuncRequest cmd1 = cmd; UpdatableInset * inset = bv_->fullCursor().innerInset(); DispatchResult res; if (inset) { cmd1.x -= inset->x(); cmd1.y -= inset->y(); - res = inset->dispatch(cmd1); + res = inset->dispatch(*bv_, cmd1); } else { cmd1.y += bv_->top_y(); - res = bv_->fullCursor().innerText()->dispatch(cmd1); + res = bv_->fullCursor().innerText()->dispatch(*bv_, cmd1); } if (bv_->fitCursor() || res.update()) { @@ -955,17 +955,16 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd) // built temporary path to inset InsetOld * inset = insetFromCoords(bv_, cmd.x, cmd.y); - FuncRequest cmd1(cmd, bv_); DispatchResult res; // try to dispatch to that inset if (inset) { - FuncRequest cmd2 = cmd1; + FuncRequest cmd2 = cmd; lyxerr << "dispatching action " << cmd2.action << " to inset " << inset << endl; cmd2.x -= inset->x(); cmd2.y -= inset->y(); - res = inset->dispatch(cmd2); + res = inset->dispatch(*bv_, cmd2); if (res.update()) { bv_->update(); bv_->fullCursor().updatePos(); @@ -992,12 +991,13 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd) // otherwise set cursor to surrounding LyXText if (!res.dispatched()) { lyxerr << "temp cursor is: " << theTempCursor << endl; - lyxerr << "dispatching " << cmd1 + lyxerr << "dispatching " << cmd << " to surrounding LyXText " << theTempCursor.innerText() << endl; bv_->fullCursor(theTempCursor); + FuncRequest cmd1 = cmd; cmd1.y += bv_->top_y(); - res = bv_->fullCursor().innerText()->dispatch(cmd1); + res = bv_->fullCursor().innerText()->dispatch(*bv_, cmd1); if (bv_->fitCursor() || res.update()) bv_->update(); @@ -1027,12 +1027,9 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd) } -bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in) +bool BufferView::Pimpl::dispatch(FuncRequest const & ev) { // Make sure that the cached BufferView is correct. - FuncRequest ev = ev_in; - ev.setView(bv_); - lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch:" << " action[" << ev.action << ']' << " arg[" << ev.argument << ']' @@ -1138,13 +1135,13 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in) case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection case LFUN_MATH_DISPLAY: // Open or create a displayed math inset case LFUN_MATH_MODE: // Open or create an inlined math inset - mathDispatch(ev); + mathDispatch(*bv_, ev); break; case LFUN_INSET_INSERT: { // Same as above. BOOST_ASSERT(false); - InsetOld * inset = createInset(ev); + InsetOld * inset = createInset(bv_, ev); if (!inset || !insertInset(inset)) delete inset; break; @@ -1236,11 +1233,11 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in) } case LFUN_WORD_FIND: - lyx::find::find(ev); + lyx::find::find(bv_, ev); break; case LFUN_WORD_REPLACE: - lyx::find::replace(ev); + lyx::find::replace(bv_, ev); break; case LFUN_MARK_OFF: @@ -1275,7 +1272,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in) break; default: - return bv_->getLyXText()->dispatch(FuncRequest(ev, bv_)).dispatched(); + return bv_->getLyXText()->dispatch(*bv_, ev).dispatched(); } // end of switch return true; diff --git a/src/ChangeLog b/src/ChangeLog index 2eebfe6000..4d3a440c04 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,19 @@ + +2004-01-15 André Pönitz + + * cursor_slice.[Ch]: add a few covienience functions + + * funcrequest.[Ch]: remove BufferView * member + + * BufferView_pimpl.C: + * cursor.C: + * factory.[Ch]: + * lyxfind.[Ch]: + * lyxfunc.C: + * lyxtext.h: + * text3.C: + * undo.[Ch]: adjust to this and changed signature of Inset::priv_dispatch() + 2004-01-14 Alfredo Braunstein * text.C (getWord): fix getWord (and thus LFUN_WORDSEL) diff --git a/src/cursor.C b/src/cursor.C index 9af49d4638..acd21c8402 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -54,7 +54,7 @@ DispatchResult LCursor::dispatch(FuncRequest const & cmd0) for (int i = cursor_.size() - 1; i >= 1; --i) { CursorSlice const & citem = cursor_[i]; lyxerr << "trying to dispatch to inset " << citem.inset_ << endl; - DispatchResult res = citem.inset_->dispatch(cmd); + DispatchResult res = citem.inset_->dispatch(*bv_, cmd); if (res.dispatched()) { lyxerr << " successfully dispatched to inset " << citem.inset_ << endl; return DispatchResult(true, true); @@ -63,19 +63,19 @@ DispatchResult LCursor::dispatch(FuncRequest const & cmd0) switch (res.val()) { case FINISHED: pop(i); - cmd = FuncRequest(bv_, LFUN_FINISHED_LEFT); + cmd = FuncRequest(LFUN_FINISHED_LEFT); break; case FINISHED_RIGHT: pop(i); - cmd = FuncRequest(bv_, LFUN_FINISHED_RIGHT); + cmd = FuncRequest(LFUN_FINISHED_RIGHT); break; case FINISHED_UP: pop(i); - cmd = FuncRequest(bv_, LFUN_FINISHED_UP); + cmd = FuncRequest(LFUN_FINISHED_UP); break; case FINISHED_DOWN: pop(i); - cmd = FuncRequest(bv_, LFUN_FINISHED_DOWN); + cmd = FuncRequest(LFUN_FINISHED_DOWN); break; default: lyxerr << "not handled on level " << i << " val: " << res.val() << endl; @@ -83,7 +83,7 @@ DispatchResult LCursor::dispatch(FuncRequest const & cmd0) } } lyxerr << "trying to dispatch to main text " << bv_->text() << endl; - DispatchResult res = bv_->text()->dispatch(cmd); + DispatchResult res = bv_->text()->dispatch(*bv_, cmd); lyxerr << " result: " << res.val() << endl; if (!res.dispatched()) { @@ -97,7 +97,7 @@ DispatchResult LCursor::dispatch(FuncRequest const & cmd0) } -void LCursor::push(UpdatableInset * inset) +void LCursor::push(InsetBase * inset) { lyxerr << "LCursor::push() inset: " << inset << endl; cursor_.push_back(CursorSlice(inset)); @@ -186,9 +186,11 @@ void LCursor::getPos(int & x, int & y) const // inset->draw() is not called: this doesn't update // inset.top_baseline, so getCursor() returns an old value. // Ugly as you like. - inset->getCursorPos(cursor_.back().idx_, x, y); - x += inset->x(); - y += cached_y_; + if (inset) { + inset->getCursorPos(cursor_.back().idx_, x, y); + x += inset->x(); + y += cached_y_; + } } } diff --git a/src/cursor.h b/src/cursor.h index 704544cf95..9088e3671e 100644 --- a/src/cursor.h +++ b/src/cursor.h @@ -43,7 +43,7 @@ public: /// dispatch from innermost inset upwards DispatchResult dispatch(FuncRequest const & cmd); /// - void push(UpdatableInset * inset); + void push(InsetBase * inset); /// restrict cursor nesting to given size void pop(int depth); /// pop one level off the cursor diff --git a/src/cursor_slice.C b/src/cursor_slice.C index ce9b4605c3..ba26f5e87f 100644 --- a/src/cursor_slice.C +++ b/src/cursor_slice.C @@ -51,6 +51,12 @@ CursorSlice::idx_type CursorSlice::idx() const } +CursorSlice::idx_type & CursorSlice::idx() +{ + return idx_; +} + + void CursorSlice::par(par_type par) { par_ = par; @@ -63,6 +69,12 @@ CursorSlice::par_type CursorSlice::par() const } +CursorSlice::par_type & CursorSlice::par() +{ + return par_; +} + + void CursorSlice::pos(pos_type pos) { pos_ = pos; @@ -75,6 +87,20 @@ CursorSlice::pos_type CursorSlice::pos() const } +CursorSlice::pos_type & CursorSlice::pos() +{ + return pos_; +} + + +CursorSlice::pos_type CursorSlice::lastpos() const +{ + BOOST_ASSERT(inset_); +#warning implement me for texted, too. + return inset_->asMathInset() ? cell().size() : 0; +} + + void CursorSlice::boundary(bool boundary) { boundary_ = boundary; @@ -87,22 +113,29 @@ bool CursorSlice::boundary() const } -MathInset * CursorSlice::asMathInset() const +CursorSlice::row_type CursorSlice::row() const { - return inset_ ? inset_->asMathInset() : 0; + BOOST_ASSERT(asMathInset()); + asMathInset()->row(idx_); } -UpdatableInset * CursorSlice::asUpdatableInset() const +CursorSlice::col_type CursorSlice::col() const { - return inset_ ? inset_->asUpdatableInset() : 0; + BOOST_ASSERT(asMathInset()); + asMathInset()->col(idx_); } -void CursorSlice::cell(CursorSlice::idx_type idx) const +MathInset * CursorSlice::asMathInset() const { - BOOST_ASSERT(asMathInset()); - asMathInset()->cell(idx); + return inset_ ? inset_->asMathInset() : 0; +} + + +UpdatableInset * CursorSlice::asUpdatableInset() const +{ + return inset_ ? inset_->asUpdatableInset() : 0; } diff --git a/src/cursor_slice.h b/src/cursor_slice.h index 0b557bff9d..303a0e39cd 100644 --- a/src/cursor_slice.h +++ b/src/cursor_slice.h @@ -45,6 +45,10 @@ public: typedef lyx::paroffset_type par_type; /// type for cursor positions within a cell typedef lyx::pos_type pos_type; + /// type for row indices + typedef size_t row_type; + /// type for col indices + typedef size_t col_type; /// CursorSlice(); @@ -55,14 +59,26 @@ public: void idx(idx_type idx); /// return the paragraph this cursor is in idx_type idx() const; + /// return the paragraph this cursor is in + idx_type & idx(); /// set the paragraph that contains this cursor void par(par_type par); /// return the paragraph this cursor is in par_type par() const; + /// return the paragraph this cursor is in + par_type & par(); /// set the position within the paragraph void pos(pos_type pos); /// return the position within the paragraph pos_type pos() const; + /// return the position within the paragraph + pos_type & pos(); + /// return the last position within the paragraph + pos_type lastpos() const; + /// return the grid row of the current cell + row_type row() const; + /// return the grid row of the current cell + col_type col() const; /// FIXME void boundary(bool b); @@ -81,8 +97,6 @@ public: /// /// returns cell corresponding to this position MathArray & cell() const; - /// set cell corresponding to this position - void cell(idx_type idx) const; /// gets screen position of the thing void getScreenPos(int & x, int & y) const; /// diff --git a/src/factory.C b/src/factory.C index c5aab75b5b..f5a79b3ec5 100644 --- a/src/factory.C +++ b/src/factory.C @@ -69,9 +69,8 @@ using std::endl; using std::string; -InsetOld * createInset(FuncRequest const & cmd) +InsetOld * createInset(BufferView * bv, FuncRequest const & cmd) { - BufferView * bv = cmd.view(); BufferParams const & params = bv->buffer()->params(); switch (cmd.action) { @@ -163,7 +162,7 @@ InsetOld * createInset(FuncRequest const & cmd) if (icp.getContents().empty()) { lv->getDialogs().show("index", data, 0); } else { - lv->dispatch(FuncRequest(bv, LFUN_INSET_APPLY, data)); + lv->dispatch(FuncRequest(LFUN_INSET_APPLY, data)); } return 0; } @@ -235,7 +234,7 @@ InsetOld * createInset(FuncRequest const & cmd) return new InsetERT(params, st); } else if (name == "external") { - Buffer const & buffer = *cmd.view()->buffer(); + Buffer const & buffer = *bv->buffer(); InsetExternalParams iep; InsetExternalMailer::string2params(cmd.argument, buffer, iep); @@ -244,7 +243,7 @@ InsetOld * createInset(FuncRequest const & cmd) return inset.release(); } else if (name == "graphics") { - Buffer const & buffer = *cmd.view()->buffer(); + Buffer const & buffer = *bv->buffer(); InsetGraphicsParams igp; InsetGraphicsMailer::string2params(cmd.argument, buffer, igp); diff --git a/src/factory.h b/src/factory.h index f9d76b39c5..d1a6d5e32e 100644 --- a/src/factory.h +++ b/src/factory.h @@ -12,13 +12,15 @@ #ifndef FACTORY_H #define FACTORY_H -class InsetOld; +class Buffer; +class BufferView; class FuncRequest; +class InsetOld; class LyXLex; -class Buffer; + /// creates inset according to 'cmd' -InsetOld * createInset(FuncRequest const & cmd); +InsetOld * createInset(BufferView * bv, FuncRequest const & cmd); /// read inset from a file InsetOld * readInset(LyXLex & lex, Buffer const & buf); diff --git a/src/frontends/LyXView.C b/src/frontends/LyXView.C index a018e067ce..ef85ab1612 100644 --- a/src/frontends/LyXView.C +++ b/src/frontends/LyXView.C @@ -185,12 +185,9 @@ void LyXView::updateWindowTitle() } -void LyXView::dispatch(FuncRequest const & req) +void LyXView::dispatch(FuncRequest const & cmd) { - // substitute the correct BufferView here - FuncRequest r = req; - r.setView(view().get()); - getLyXFunc().dispatch(r); + getLyXFunc().dispatch(cmd); } diff --git a/src/frontends/LyXView.h b/src/frontends/LyXView.h index c16c7a9a33..96b1ebb71d 100644 --- a/src/frontends/LyXView.h +++ b/src/frontends/LyXView.h @@ -130,7 +130,7 @@ public: void resetAutosaveTimer(); /// dispatch to current BufferView - void dispatch(FuncRequest const & req); + void dispatch(FuncRequest const & cmd); /** redraw \c inset in all the BufferViews in which it is currently * visible. If successful return a pointer to the owning Buffer. diff --git a/src/frontends/controllers/ControlSearch.C b/src/frontends/controllers/ControlSearch.C index 075316f9d0..5bd503ad01 100644 --- a/src/frontends/controllers/ControlSearch.C +++ b/src/frontends/controllers/ControlSearch.C @@ -34,19 +34,15 @@ void ControlSearch::find(string const & search, string const data = lyx::find::find2string(search, casesensitive, matchword, forward); - FuncRequest const fr(bufferview(), LFUN_WORD_FIND, data); - lv_.dispatch(fr); + lv_.dispatch(FuncRequest(LFUN_WORD_FIND, data)); } void ControlSearch::replace(string const & search, string const & replace, - bool casesensitive, bool matchword, - bool forward, bool all) + bool casesensitive, bool matchword, bool forward, bool all) { string const data = lyx::find::replace2string(search, replace, - casesensitive, matchword, - all, forward); - FuncRequest const fr(bufferview(), LFUN_WORD_REPLACE, data); - lv_.dispatch(fr); + casesensitive, matchword, all, forward); + lv_.dispatch(FuncRequest(LFUN_WORD_REPLACE, data)); } diff --git a/src/frontends/controllers/ControlThesaurus.C b/src/frontends/controllers/ControlThesaurus.C index 6ea45d044d..fe60194256 100644 --- a/src/frontends/controllers/ControlThesaurus.C +++ b/src/frontends/controllers/ControlThesaurus.C @@ -48,16 +48,13 @@ void ControlThesaurus::replace(string const & newstr) true, // match word false, // all words true); // forward - FuncRequest const fr(kernel().bufferview(), LFUN_WORD_REPLACE, data); - kernel().dispatch(fr); + kernel().dispatch(FuncRequest(LFUN_WORD_REPLACE, data)); } -Thesaurus::Meanings const & -ControlThesaurus::getMeanings(string const & str) +Thesaurus::Meanings const & ControlThesaurus::getMeanings(string const & str) { if (str != laststr_) meanings_ = thesaurus.lookup(str); - return meanings_; } diff --git a/src/funcrequest.C b/src/funcrequest.C index 108fe2a261..8dfd9f6d79 100644 --- a/src/funcrequest.C +++ b/src/funcrequest.C @@ -28,66 +28,31 @@ using std::string; FuncRequest::FuncRequest() - : view_(0), action(LFUN_NOACTION), x(0), y(0), button_(mouse_button::none) + : action(LFUN_NOACTION), x(0), y(0), button_(mouse_button::none) {} FuncRequest::FuncRequest(kb_action act) - : view_(0), action(act), x(0), y(0), button_(mouse_button::none) + : action(act), x(0), y(0), button_(mouse_button::none) {} FuncRequest::FuncRequest(kb_action act, string const & arg) - : view_(0), action(act), argument(arg), x(0), y(0), button_(mouse_button::none) + : action(act), argument(arg), x(0), y(0), button_(mouse_button::none) {} -FuncRequest::FuncRequest - (kb_action act, int ax, int ay, mouse_button::state button) - : view_(0), action(act), x(ax), y(ay), button_(button) -{} - - -FuncRequest::FuncRequest(BufferView * view, kb_action act) - : view_(view), action(act), x(0), y(0), button_(mouse_button::none) -{} - - -FuncRequest::FuncRequest(BufferView * view, kb_action act, string const & arg) - : view_(view), action(act), argument(arg), x(0), y(0), button_(mouse_button::none) -{} - - -FuncRequest::FuncRequest - (BufferView * view, kb_action act, int ax, int ay, mouse_button::state but) - : view_(view), action(act), x(ax), y(ay), button_(but) +FuncRequest::FuncRequest(kb_action act, int ax, int ay, mouse_button::state but) + : action(act), x(ax), y(ay), button_(but) {} FuncRequest::FuncRequest(FuncRequest const & cmd, string const & arg) - : view_(cmd.view_), action(cmd.action), argument(arg), + : action(cmd.action), argument(arg), x(cmd.x), y(cmd.y), button_(cmd.button_) {} -FuncRequest::FuncRequest(FuncRequest const & cmd, BufferView * view) - : view_(view), action(cmd.action), argument(cmd.argument), - x(cmd.x), y(cmd.y), button_(cmd.button_) -{} - - -BufferView * FuncRequest::view() const -{ - return view_; -} - - -void FuncRequest::setView(BufferView * view) -{ - view_ = view; -} - - mouse_button::state FuncRequest::button() const { return button_; @@ -96,19 +61,21 @@ mouse_button::state FuncRequest::button() const void FuncRequest::message(string const & msg) const { - if (view_) - view_->owner()->getLyXFunc().setMessage(msg); - else - lyxerr << "Dropping message '" << msg << "'" << endl; +#warning FIXME + //if (view_) + // view_->owner()->getLyXFunc().setMessage(msg); + //else + lyxerr << "Dropping message '" << msg << "'" << endl; } void FuncRequest::errorMessage(string const & msg) const { - if (view_) - view_->owner()->getLyXFunc().setErrorMessage(msg); - else - lyxerr << "Dropping error message '" << msg << "'" << endl; +#warning FIXME + //if (view_) + // view_->owner()->getLyXFunc().setErrorMessage(msg); + //else + lyxerr << "Dropping error message '" << msg << "'" << endl; } diff --git a/src/funcrequest.h b/src/funcrequest.h index 9501ca9da1..8224d29460 100644 --- a/src/funcrequest.h +++ b/src/funcrequest.h @@ -18,8 +18,6 @@ #include #include -class BufferView; - /** * This class encapsulates a LyX action and its argument * in order to pass it around easily. @@ -34,22 +32,9 @@ public: FuncRequest(kb_action act, int x, int y, mouse_button::state button); /// actions with extra argument FuncRequest(kb_action act, std::string const & arg); - /// actions without extra argument - FuncRequest(BufferView * bv, kb_action act); - /// actions with extra argument - FuncRequest(BufferView * bv, kb_action act, std::string const & arg); - /// for mouse events - FuncRequest(BufferView * bv, kb_action act, - int x, int y, mouse_button::state button); /// for changing requests a bit FuncRequest(FuncRequest const & cmd, std::string const & arg); - /// for changing requests a bit - FuncRequest(FuncRequest const & cmd, BufferView * bv); - /// access to the view - BufferView * view() const; - /// access to the view - void setView(BufferView * bv); /// access to button mouse_button::state button() const; @@ -61,10 +46,7 @@ public: /// argument parsing, extract argument i as std::string std::string getArg(unsigned int i) const; -private: - /// the BufferView we are talking to - BufferView * view_; -public: // should be private, too... +public: // should be private /// the action kb_action action; /// the action's std::string argument diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index e5cee8549c..9bbdf1e70b 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,4 +1,28 @@ +2004-01-15 André Pönitz + + * insetbase.[Ch]: + * insetbibitem.[Ch]: + * insetbibtex.[Ch]: + * insetbox.[Ch]: + * insetbranch.[Ch]: + * insetcharstyle.[Ch]: + * insetcollapsable.[Ch]: + * insetcommand.[Ch]: + * insetert.[Ch]: + * insetexternal.[Ch]: + * insetfloat.[Ch]: + * insetgraphics.[Ch]: + * insetinclude.[Ch]: + * insetlabel.[Ch]: + * insetnote.[Ch]: + * insetref.[Ch]: + * insettabular.[Ch]: + * insettext.[Ch]: + * insetvspace.[Ch]: + * insetwrap.[Ch]: + * updatableinset.[Ch] (priv_dispatch et al): change signature. + 2004-01-08 André Pönitz * insetcollapsable.[Ch]: diff --git a/src/insets/insetbase.C b/src/insets/insetbase.C index fea008ea8b..c9c606203e 100644 --- a/src/insets/insetbase.C +++ b/src/insets/insetbase.C @@ -15,24 +15,14 @@ #include "dispatchresult.h" -DispatchResult -InsetBase::dispatch(FuncRequest const & f, idx_type & i, pos_type & p) -{ - return priv_dispatch(f, i, p); -} - - -DispatchResult -InsetBase::dispatch(FuncRequest const & f) +DispatchResult InsetBase::dispatch(BufferView & bv, FuncRequest const & cmd) { - idx_type i = 0; - pos_type p = 0; - return priv_dispatch(f, i, p); + return priv_dispatch(bv, cmd); } DispatchResult -InsetBase::priv_dispatch(FuncRequest const &, idx_type &, pos_type &) +InsetBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd) { return DispatchResult(false); } diff --git a/src/insets/insetbase.h b/src/insets/insetbase.h index a7de6df4ed..3302b99d9b 100644 --- a/src/insets/insetbase.h +++ b/src/insets/insetbase.h @@ -54,10 +54,7 @@ public: virtual UpdatableInset * asUpdatableInset() { return 0; } // the real dispatcher - DispatchResult - dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos); - // the real dispatcher - DispatchResult dispatch(FuncRequest const & cmd); + DispatchResult dispatch(BufferView & bv, FuncRequest const & cmd); /// cursor enters virtual void edit(BufferView * bv, bool left); @@ -77,8 +74,7 @@ public: protected: // the real dispatcher virtual - DispatchResult - priv_dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos); + DispatchResult priv_dispatch(BufferView & bv, FuncRequest const & cmd); }; #endif diff --git a/src/insets/insetbibitem.C b/src/insets/insetbibitem.C index 25ed6a6b53..6a732d716e 100644 --- a/src/insets/insetbibitem.C +++ b/src/insets/insetbibitem.C @@ -54,8 +54,7 @@ auto_ptr InsetBibitem::clone() const DispatchResult -InsetBibitem::priv_dispatch(FuncRequest const & cmd, - idx_type & idx, pos_type & pos) +InsetBibitem::priv_dispatch(BufferView & bv, FuncRequest const & cmd) { switch (cmd.action) { @@ -65,13 +64,13 @@ InsetBibitem::priv_dispatch(FuncRequest const & cmd, if (p.getCmdName().empty()) return DispatchResult(true, true); setParams(p); - cmd.view()->update(); - cmd.view()->fitCursor(); + bv.update(); + bv.fitCursor(); return DispatchResult(true, true); } default: - return InsetCommand::priv_dispatch(cmd, idx, pos); + return InsetCommand::priv_dispatch(bv, cmd); } } diff --git a/src/insets/insetbibitem.h b/src/insets/insetbibitem.h index 96fe35a949..b64a72f45c 100644 --- a/src/insets/insetbibitem.h +++ b/src/insets/insetbibitem.h @@ -52,7 +52,7 @@ protected: /// virtual DispatchResult - priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &); + priv_dispatch(BufferView & bv, FuncRequest const & cmd); private: /// int counter; diff --git a/src/insets/insetbibtex.C b/src/insets/insetbibtex.C index 028d1dfe71..bfc7806ffa 100644 --- a/src/insets/insetbibtex.C +++ b/src/insets/insetbibtex.C @@ -66,11 +66,8 @@ std::auto_ptr InsetBibtex::clone() const DispatchResult -InsetBibtex::priv_dispatch(FuncRequest const & cmd, - idx_type & idx, pos_type & pos) +InsetBibtex::priv_dispatch(BufferView & bv, FuncRequest const & cmd) { - DispatchResult result(false); - switch (cmd.action) { case LFUN_INSET_MODIFY: { @@ -78,17 +75,12 @@ InsetBibtex::priv_dispatch(FuncRequest const & cmd, InsetCommandMailer::string2params("bibtex", cmd.argument, p); if (!p.getCmdName().empty()) setParams(p); - result.dispatched(true); - result.update(true); + return DispatchResult(true, true); } - break; default: - result = InsetCommand::priv_dispatch(cmd, idx, pos); - break; + return InsetCommand::priv_dispatch(bv, cmd); } - - return result; } diff --git a/src/insets/insetbibtex.h b/src/insets/insetbibtex.h index f00f1ffb0a..2146fff6ed 100644 --- a/src/insets/insetbibtex.h +++ b/src/insets/insetbibtex.h @@ -48,7 +48,7 @@ protected: /// virtual DispatchResult - priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &); + priv_dispatch(BufferView & bv, FuncRequest const & cmd); }; #endif // INSET_BIBTEX_H diff --git a/src/insets/insetbox.C b/src/insets/insetbox.C index e4547b6c1c..bcc0ab67f7 100644 --- a/src/insets/insetbox.C +++ b/src/insets/insetbox.C @@ -170,37 +170,30 @@ bool InsetBox::showInsetDialog(BufferView * bv) const DispatchResult -InsetBox::priv_dispatch(FuncRequest const & cmd, - idx_type & idx, pos_type & pos) +InsetBox::priv_dispatch(BufferView & bv, FuncRequest const & cmd) { - DispatchResult result(false); - BufferView * bv = cmd.view(); - switch (cmd.action) { case LFUN_INSET_MODIFY: { lyxerr << "InsetBox::dispatch MODIFY" << endl; InsetBoxMailer::string2params(cmd.argument, params_); setButtonLabel(); - result.dispatched(true); - result.update(true); - return result; + return DispatchResult(true, true); } case LFUN_INSET_DIALOG_UPDATE: - InsetBoxMailer(*this).updateDialog(bv); - result.dispatched(true); - return result; + InsetBoxMailer(*this).updateDialog(&bv); + return DispatchResult(true); case LFUN_MOUSE_RELEASE: if (cmd.button() == mouse_button::button3 && hitButton(cmd)) { - InsetBoxMailer(*this).showDialog(bv); + InsetBoxMailer(*this).showDialog(&bv); return DispatchResult(true); } - return InsetCollapsable::priv_dispatch(cmd, idx, pos); + return InsetCollapsable::priv_dispatch(bv, cmd); default: - return InsetCollapsable::priv_dispatch(cmd, idx, pos); + return InsetCollapsable::priv_dispatch(bv, cmd); } } diff --git a/src/insets/insetbox.h b/src/insets/insetbox.h index 7be734f89e..af396197b4 100644 --- a/src/insets/insetbox.h +++ b/src/insets/insetbox.h @@ -107,7 +107,7 @@ protected: /// virtual DispatchResult - priv_dispatch(FuncRequest const &, idx_type &, pos_type &); + priv_dispatch(BufferView & bv, FuncRequest const & cmd); private: friend class InsetBoxParams; diff --git a/src/insets/insetbranch.C b/src/insets/insetbranch.C index 67ecbc6e0b..37c3b81ec3 100644 --- a/src/insets/insetbranch.C +++ b/src/insets/insetbranch.C @@ -111,10 +111,8 @@ bool InsetBranch::showInsetDialog(BufferView * bv) const DispatchResult -InsetBranch::priv_dispatch(FuncRequest const & cmd, - idx_type & idx, pos_type & pos) +InsetBranch::priv_dispatch(BufferView & bv, FuncRequest const & cmd) { - BufferView * bv = cmd.view(); switch (cmd.action) { case LFUN_INSET_MODIFY: { InsetBranchParams params; @@ -126,22 +124,22 @@ InsetBranch::priv_dispatch(FuncRequest const & cmd, case LFUN_MOUSE_PRESS: if (cmd.button() != mouse_button::button3) - return InsetCollapsable::priv_dispatch(cmd, idx, pos); + return InsetCollapsable::priv_dispatch(bv, cmd); return DispatchResult(false); case LFUN_INSET_DIALOG_UPDATE: - InsetBranchMailer(*this).updateDialog(bv); + InsetBranchMailer(*this).updateDialog(&bv); return DispatchResult(true); case LFUN_MOUSE_RELEASE: if (cmd.button() == mouse_button::button3 && hitButton(cmd)) { - InsetBranchMailer(*this).showDialog(bv); + InsetBranchMailer(*this).showDialog(&bv); return DispatchResult(true); } - return InsetCollapsable::priv_dispatch(cmd, idx, pos); + return InsetCollapsable::priv_dispatch(bv, cmd); default: - return InsetCollapsable::priv_dispatch(cmd, idx, pos); + return InsetCollapsable::priv_dispatch(bv, cmd); } } diff --git a/src/insets/insetbranch.h b/src/insets/insetbranch.h index f76465c2c9..89dcb076b0 100644 --- a/src/insets/insetbranch.h +++ b/src/insets/insetbranch.h @@ -83,7 +83,7 @@ protected: /// virtual DispatchResult - priv_dispatch(FuncRequest const &, idx_type &, pos_type &); + priv_dispatch(BufferView & bv, FuncRequest const & cmd); private: friend class InsetBranchParams; diff --git a/src/insets/insetcharstyle.C b/src/insets/insetcharstyle.C index dd7c66f783..9189d35544 100644 --- a/src/insets/insetcharstyle.C +++ b/src/insets/insetcharstyle.C @@ -134,7 +134,7 @@ void InsetCharStyle::draw(PainterInfo & pi, int x, int y) const int a = 0; int d = 0; font_metrics::rectText(params_.type, font, w, a, d); - pi.pain.rectText(x + 0.5 * (dim_.wid - w), + pi.pain.rectText(x + (dim_.wid - w) / 2, y + inset.descent() + a, params_.type, font, LColor::none, LColor::none); } @@ -148,8 +148,7 @@ void InsetCharStyle::getDrawFont(LyXFont & font) const DispatchResult -InsetCharStyle::priv_dispatch(FuncRequest const & cmd, - idx_type & idx, pos_type & pos) +InsetCharStyle::priv_dispatch(BufferView & bv, FuncRequest const & cmd) { setStatus(Inlined); switch (cmd.action) { @@ -158,11 +157,10 @@ InsetCharStyle::priv_dispatch(FuncRequest const & cmd, has_label_ = !has_label_; return DispatchResult(true); } - inset.dispatch(cmd); + inset.dispatch(bv, cmd); return DispatchResult(true, true); - break; default: - return InsetCollapsable::priv_dispatch(cmd, idx, pos); + return InsetCollapsable::priv_dispatch(bv, cmd); } } diff --git a/src/insets/insetcharstyle.h b/src/insets/insetcharstyle.h index d7c3f4cd80..58104ba356 100644 --- a/src/insets/insetcharstyle.h +++ b/src/insets/insetcharstyle.h @@ -87,7 +87,7 @@ protected: /// virtual DispatchResult - priv_dispatch(FuncRequest const &, idx_type &, pos_type &); + priv_dispatch(BufferView & bv, FuncRequest const & cmd); private: friend class InsetCharStyleParams; diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index 1f1620982b..b850b4d42b 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -213,13 +213,12 @@ FuncRequest InsetCollapsable::adjustCommand(FuncRequest const & cmd) } -DispatchResult InsetCollapsable::lfunMouseRelease(FuncRequest const & cmd) +DispatchResult +InsetCollapsable::lfunMouseRelease(BufferView & bv, FuncRequest const & cmd) { - BufferView * bv = cmd.view(); - if (cmd.button() == mouse_button::button3) { lyxerr << "InsetCollapsable::lfunMouseRelease 0" << endl; - showInsetDialog(bv); + showInsetDialog(&bv); return DispatchResult(true, true); } @@ -227,7 +226,7 @@ DispatchResult InsetCollapsable::lfunMouseRelease(FuncRequest const & cmd) case Collapsed: lyxerr << "InsetCollapsable::lfunMouseRelease 1" << endl; setStatus(Open); - edit(bv, true); + edit(&bv, true); return DispatchResult(true, true); case Open: @@ -235,13 +234,12 @@ DispatchResult InsetCollapsable::lfunMouseRelease(FuncRequest const & cmd) lyxerr << "InsetCollapsable::lfunMouseRelease 2" << endl; setStatus(Collapsed); return DispatchResult(false, FINISHED_RIGHT); - } else { - lyxerr << "InsetCollapsable::lfunMouseRelease 3" << endl; - return inset.dispatch(adjustCommand(cmd)); - } + } + lyxerr << "InsetCollapsable::lfunMouseRelease 3" << endl; + return inset.dispatch(bv, adjustCommand(cmd)); case Inlined: - return inset.dispatch(cmd); + return inset.dispatch(bv, cmd); } return DispatchResult(true, true); @@ -329,27 +327,27 @@ void InsetCollapsable::edit(BufferView * bv, int x, int y) DispatchResult -InsetCollapsable::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &) +InsetCollapsable::priv_dispatch(BufferView & bv, FuncRequest const & cmd) { //lyxerr << "\nInsetCollapsable::priv_dispatch (begin): cmd: " << cmd // << " button y: " << button_dim.y2 << endl; switch (cmd.action) { case LFUN_MOUSE_PRESS: if (status_ == Inlined) - inset.dispatch(cmd); + inset.dispatch(bv, cmd); else if (status_ == Open && cmd.y > button_dim.y2) - inset.dispatch(adjustCommand(cmd)); + inset.dispatch(bv, adjustCommand(cmd)); return DispatchResult(true, true); case LFUN_MOUSE_MOTION: if (status_ == Inlined) - inset.dispatch(cmd); + inset.dispatch(bv, cmd); else if (status_ == Open && cmd.y > button_dim.y2) - inset.dispatch(adjustCommand(cmd)); + inset.dispatch(bv, adjustCommand(cmd)); return DispatchResult(true, true); case LFUN_MOUSE_RELEASE: - return lfunMouseRelease(cmd); + return lfunMouseRelease(bv, cmd); case LFUN_INSET_TOGGLE: if (inset.text_.toggleInset()) @@ -363,7 +361,7 @@ InsetCollapsable::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &) } default: - return inset.dispatch(adjustCommand(cmd)); + return inset.dispatch(bv, adjustCommand(cmd)); } //lyxerr << "InsetCollapsable::priv_dispatch (end)" << endl; } @@ -463,13 +461,13 @@ void InsetCollapsable::setLabelFont(LyXFont & font) } -void InsetCollapsable::scroll(BufferView * bv, float sx) const +void InsetCollapsable::scroll(BufferView & bv, float sx) const { UpdatableInset::scroll(bv, sx); } -void InsetCollapsable::scroll(BufferView * bv, int offset) const +void InsetCollapsable::scroll(BufferView & bv, int offset) const { UpdatableInset::scroll(bv, offset); } diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index be75893a9d..232e7d00d7 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -91,9 +91,9 @@ public: /// int scroll(bool recursive=true) const; /// - void scroll(BufferView *bv, float sx) const; + void scroll(BufferView & bv, float sx) const; /// - void scroll(BufferView *bv, int offset) const; + void scroll(BufferView & bv, int offset) const; /// int numParagraphs() const; /// @@ -121,7 +121,7 @@ protected: /// virtual DispatchResult - priv_dispatch(FuncRequest const &, idx_type &, pos_type &); + priv_dispatch(BufferView & bv, FuncRequest const & cmd); /// void dimension_collapsed(Dimension &) const; /// @@ -139,7 +139,7 @@ protected: private: /// - DispatchResult lfunMouseRelease(FuncRequest const &); + DispatchResult lfunMouseRelease(BufferView & bv, FuncRequest const &); /// FuncRequest adjustCommand(FuncRequest const &); diff --git a/src/insets/insetcommand.C b/src/insets/insetcommand.C index 80d5ae8d12..354acc3831 100644 --- a/src/insets/insetcommand.C +++ b/src/insets/insetcommand.C @@ -100,7 +100,7 @@ int InsetCommand::docbook(Buffer const &, ostream &, DispatchResult -InsetCommand::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &) +InsetCommand::priv_dispatch(BufferView & bv, FuncRequest const & cmd) { switch (cmd.action) { case LFUN_INSET_MODIFY: { @@ -108,21 +108,19 @@ InsetCommand::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &) InsetCommandMailer::string2params(mailer_name_, cmd.argument, p); if (p.getCmdName().empty()) return DispatchResult(false); - setParams(p); - cmd.view()->update(); + bv.update(); return DispatchResult(true, true); } case LFUN_INSET_DIALOG_UPDATE: - InsetCommandMailer(cmd.argument, *this).updateDialog(cmd.view()); + InsetCommandMailer(cmd.argument, *this).updateDialog(&bv); return DispatchResult(true, true); case LFUN_INSET_DIALOG_SHOW: case LFUN_MOUSE_RELEASE: { if (!mailer_name_.empty()) - InsetCommandMailer(mailer_name_, *this). - showDialog(cmd.view()); + InsetCommandMailer(mailer_name_, *this).showDialog(&bv); return DispatchResult(true); } diff --git a/src/insets/insetcommand.h b/src/insets/insetcommand.h index 829db405bb..c20d3efe0a 100644 --- a/src/insets/insetcommand.h +++ b/src/insets/insetcommand.h @@ -77,7 +77,7 @@ protected: /// virtual DispatchResult - priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &); + priv_dispatch(BufferView & bv, FuncRequest const & cmd); /// std::string const getCommand() const { return p_.getCommand(); } /// diff --git a/src/insets/insetert.C b/src/insets/insetert.C index e81ec4795f..897fc621b0 100644 --- a/src/insets/insetert.C +++ b/src/insets/insetert.C @@ -208,19 +208,16 @@ int InsetERT::docbook(Buffer const &, ostream & os, } -DispatchResult -InsetERT::priv_dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos) +DispatchResult InsetERT::priv_dispatch(BufferView & bv, FuncRequest const & cmd) { switch (cmd.action) { - case LFUN_INSET_MODIFY: - { - InsetCollapsable::CollapseStatus st; - - InsetERTMailer::string2params(cmd.argument, st); - setStatus(st); - return DispatchResult(true, true); - } + case LFUN_INSET_MODIFY: { + InsetCollapsable::CollapseStatus st; + InsetERTMailer::string2params(cmd.argument, st); + setStatus(st); + return DispatchResult(true, true); + } case LFUN_LAYOUT: case LFUN_BOLD: @@ -240,7 +237,7 @@ InsetERT::priv_dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos) return DispatchResult(true); default: - return InsetCollapsable::priv_dispatch(cmd, idx, pos); + return InsetCollapsable::priv_dispatch(bv, cmd); } } diff --git a/src/insets/insetert.h b/src/insets/insetert.h index ef23eb1f6c..a200c7921c 100644 --- a/src/insets/insetert.h +++ b/src/insets/insetert.h @@ -76,7 +76,7 @@ protected: /// virtual DispatchResult - priv_dispatch(FuncRequest const &, idx_type &, pos_type &); + priv_dispatch(BufferView & bv, FuncRequest const & cmd); private: /// void init(); diff --git a/src/insets/insetexternal.C b/src/insets/insetexternal.C index afe126119f..654342b74d 100644 --- a/src/insets/insetexternal.C +++ b/src/insets/insetexternal.C @@ -441,14 +441,12 @@ void InsetExternal::statusChanged() const DispatchResult -InsetExternal::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &) +InsetExternal::priv_dispatch(BufferView & bv, FuncRequest const & cmd) { switch (cmd.action) { case LFUN_EXTERNAL_EDIT: { - BOOST_ASSERT(cmd.view()); - - Buffer const & buffer = *cmd.view()->buffer(); + Buffer const & buffer = *bv.buffer(); InsetExternalParams p; InsetExternalMailer::string2params(cmd.argument, buffer, p); external::editExternal(p, buffer); @@ -456,22 +454,20 @@ InsetExternal::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &) } case LFUN_INSET_MODIFY: { - BOOST_ASSERT(cmd.view()); - - Buffer const & buffer = *cmd.view()->buffer(); + Buffer const & buffer = *bv.buffer(); InsetExternalParams p; InsetExternalMailer::string2params(cmd.argument, buffer, p); setParams(p, buffer); - cmd.view()->update(); + bv.update(); return DispatchResult(true, true); } case LFUN_INSET_DIALOG_UPDATE: - InsetExternalMailer(*this).updateDialog(cmd.view()); + InsetExternalMailer(*this).updateDialog(&bv); return DispatchResult(true, true); case LFUN_MOUSE_RELEASE: - InsetExternalMailer(*this).showDialog(cmd.view()); + InsetExternalMailer(*this).showDialog(&bv); return DispatchResult(true, true); default: diff --git a/src/insets/insetexternal.h b/src/insets/insetexternal.h index 4bd37d3350..0f65f54d4f 100644 --- a/src/insets/insetexternal.h +++ b/src/insets/insetexternal.h @@ -152,7 +152,7 @@ protected: /// virtual DispatchResult - priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &); + priv_dispatch(BufferView & bv, FuncRequest const & cmd); private: /** This method is connected to the graphics loader, so we are * informed when the image has been loaded. diff --git a/src/insets/insetfloat.C b/src/insets/insetfloat.C index 46a7f1ac5c..0ed46be8a3 100644 --- a/src/insets/insetfloat.C +++ b/src/insets/insetfloat.C @@ -156,30 +156,27 @@ InsetFloat::~InsetFloat() DispatchResult -InsetFloat::priv_dispatch(FuncRequest const & cmd, - idx_type & idx, pos_type & pos) +InsetFloat::priv_dispatch(BufferView & bv, FuncRequest const & cmd) { switch (cmd.action) { case LFUN_INSET_MODIFY: { InsetFloatParams params; InsetFloatMailer::string2params(cmd.argument, params); - params_.placement = params.placement; params_.wide = params.wide; - - wide(params_.wide, cmd.view()->buffer()->params()); - cmd.view()->update(); + wide(params_.wide, bv.buffer()->params()); + bv.update(); return DispatchResult(true, true); } case LFUN_INSET_DIALOG_UPDATE: { - InsetFloatMailer(*this).updateDialog(cmd.view()); + InsetFloatMailer(*this).updateDialog(&bv); return DispatchResult(true, true); } default: - return InsetCollapsable::priv_dispatch(cmd, idx, pos); + return InsetCollapsable::priv_dispatch(bv, cmd); } } diff --git a/src/insets/insetfloat.h b/src/insets/insetfloat.h index d7a045cf10..d738916645 100644 --- a/src/insets/insetfloat.h +++ b/src/insets/insetfloat.h @@ -80,7 +80,7 @@ public: protected: virtual DispatchResult - priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &); + priv_dispatch(BufferView & bv, FuncRequest const & cmd); private: /// InsetFloatParams params_; diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index 257efeece2..f9f5e1352f 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -192,26 +192,26 @@ void InsetGraphics::statusChanged() const DispatchResult -InsetGraphics::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &) +InsetGraphics::priv_dispatch(BufferView & bv, FuncRequest const & cmd) { switch (cmd.action) { case LFUN_INSET_MODIFY: { - Buffer const & buffer = *cmd.view()->buffer(); + Buffer const & buffer = *bv.buffer(); InsetGraphicsParams p; InsetGraphicsMailer::string2params(cmd.argument, buffer, p); if (!p.filename.empty()) { setParams(p); - cmd.view()->update(); + bv.update(); } return DispatchResult(true, true); } case LFUN_INSET_DIALOG_UPDATE: - InsetGraphicsMailer(*this).updateDialog(cmd.view()); + InsetGraphicsMailer(*this).updateDialog(&bv); return DispatchResult(true, true); case LFUN_MOUSE_RELEASE: - InsetGraphicsMailer(*this).showDialog(cmd.view()); + InsetGraphicsMailer(*this).showDialog(&bv); return DispatchResult(true, true); default: diff --git a/src/insets/insetgraphics.h b/src/insets/insetgraphics.h index 7efcf15ceb..bd7b4f08ca 100644 --- a/src/insets/insetgraphics.h +++ b/src/insets/insetgraphics.h @@ -83,7 +83,7 @@ protected: /// virtual DispatchResult - priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &); + priv_dispatch(BufferView & bv, FuncRequest const & cmd); private: /// friend class InsetGraphicsMailer; diff --git a/src/insets/insetinclude.C b/src/insets/insetinclude.C index 2b5d00b857..e79356d7d9 100644 --- a/src/insets/insetinclude.C +++ b/src/insets/insetinclude.C @@ -108,7 +108,7 @@ InsetInclude::~InsetInclude() DispatchResult -InsetInclude::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &) +InsetInclude::priv_dispatch(BufferView & bv, FuncRequest const & cmd) { switch (cmd.action) { @@ -116,23 +116,23 @@ InsetInclude::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &) InsetCommandParams p; InsetIncludeMailer::string2params(cmd.argument, p); if (!p.getCmdName().empty()) { - set(p, *cmd.view()->buffer()); - cmd.view()->update(); + set(p, *bv.buffer()); + bv.update(); } return DispatchResult(true, true); } case LFUN_INSET_DIALOG_UPDATE: - InsetIncludeMailer(*this).updateDialog(cmd.view()); + InsetIncludeMailer(*this).updateDialog(&bv); return DispatchResult(true, true); case LFUN_MOUSE_RELEASE: if (button_.box().contains(cmd.x, cmd.y)) - InsetIncludeMailer(*this).showDialog(cmd.view()); + InsetIncludeMailer(*this).showDialog(&bv); return DispatchResult(true, true); case LFUN_INSET_DIALOG_SHOW: - InsetIncludeMailer(*this).showDialog(cmd.view()); + InsetIncludeMailer(*this).showDialog(&bv); return DispatchResult(true, true); default: diff --git a/src/insets/insetinclude.h b/src/insets/insetinclude.h index 95247a5e5a..456abb80a8 100644 --- a/src/insets/insetinclude.h +++ b/src/insets/insetinclude.h @@ -85,7 +85,7 @@ protected: /// virtual DispatchResult - priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &); + priv_dispatch(BufferView & bv, FuncRequest const & cmd); private: /// Slot receiving a signal that the preview is ready to display. void statusChanged() const; diff --git a/src/insets/insetlabel.C b/src/insets/insetlabel.C index 6276c36194..07a2b28763 100644 --- a/src/insets/insetlabel.C +++ b/src/insets/insetlabel.C @@ -52,12 +52,8 @@ string const InsetLabel::getScreenLabel(Buffer const &) const DispatchResult -InsetLabel::priv_dispatch(FuncRequest const & cmd, - idx_type & idx, pos_type & pos) +InsetLabel::priv_dispatch(BufferView & bv, FuncRequest const & cmd) { - BOOST_ASSERT(cmd.view()); - BufferView * const bv = cmd.view(); - switch (cmd.action) { case LFUN_INSET_MODIFY: { @@ -65,20 +61,17 @@ InsetLabel::priv_dispatch(FuncRequest const & cmd, InsetCommandMailer::string2params("label", cmd.argument, p); if (p.getCmdName().empty()) return DispatchResult(false); - bool clean = true; - if (bv && p.getContents() != params().getContents()) { - clean = bv->ChangeRefsIfUnique(params().getContents(), + if (p.getContents() != params().getContents()) + clean = bv.ChangeRefsIfUnique(params().getContents(), p.getContents()); - } - setParams(p); - bv->update(); + bv.update(); return DispatchResult(true, true); } default: - return InsetCommand::priv_dispatch(cmd, idx, pos); + return InsetCommand::priv_dispatch(bv, cmd); } } diff --git a/src/insets/insetlabel.h b/src/insets/insetlabel.h index d81f71556b..8bdea8a291 100644 --- a/src/insets/insetlabel.h +++ b/src/insets/insetlabel.h @@ -44,7 +44,7 @@ protected: /// virtual DispatchResult - priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &); + priv_dispatch(BufferView & bv, FuncRequest const & cmd); }; #endif diff --git a/src/insets/insetnote.C b/src/insets/insetnote.C index 3a8c38a2d3..58c3546c88 100644 --- a/src/insets/insetnote.C +++ b/src/insets/insetnote.C @@ -184,33 +184,30 @@ bool InsetNote::showInsetDialog(BufferView * bv) const DispatchResult -InsetNote::priv_dispatch(FuncRequest const & cmd, - idx_type & idx, pos_type & pos) +InsetNote::priv_dispatch(BufferView & bv, FuncRequest const & cmd) { - BufferView * bv = cmd.view(); - switch (cmd.action) { case LFUN_INSET_MODIFY: { InsetNoteMailer::string2params(cmd.argument, params_); setButtonLabel(); - bv->update(); + bv.update(); return DispatchResult(true, true); } case LFUN_INSET_DIALOG_UPDATE: - InsetNoteMailer(*this).updateDialog(bv); + InsetNoteMailer(*this).updateDialog(&bv); return DispatchResult(true, true); case LFUN_MOUSE_RELEASE: if (cmd.button() == mouse_button::button3 && hitButton(cmd)) { - InsetNoteMailer(*this).showDialog(bv); + InsetNoteMailer(*this).showDialog(&bv); return DispatchResult(true, true); } - // fallthrough: + return InsetCollapsable::priv_dispatch(bv, cmd); default: - return InsetCollapsable::priv_dispatch(cmd, idx, pos); + return InsetCollapsable::priv_dispatch(bv, cmd); } } diff --git a/src/insets/insetnote.h b/src/insets/insetnote.h index c2d660f518..bf58055955 100644 --- a/src/insets/insetnote.h +++ b/src/insets/insetnote.h @@ -77,7 +77,7 @@ protected: /// virtual DispatchResult - priv_dispatch(FuncRequest const &, idx_type &, pos_type &); + priv_dispatch(BufferView & bv, FuncRequest const & cmd); private: friend class InsetNoteParams; diff --git a/src/insets/insetref.C b/src/insets/insetref.C index af6c17cba2..da32aa0c4a 100644 --- a/src/insets/insetref.C +++ b/src/insets/insetref.C @@ -40,21 +40,19 @@ InsetRef::InsetRef(InsetRef const & ir) DispatchResult -InsetRef::priv_dispatch(FuncRequest const & cmd, - idx_type & idx, pos_type & pos) +InsetRef::priv_dispatch(BufferView & bv, FuncRequest const & cmd) { switch (cmd.action) { case LFUN_MOUSE_PRESS: // Eventually trigger dialog with button 3 not 1 if (cmd.button() == mouse_button::button3) - cmd.view()->owner()-> - dispatch(FuncRequest(LFUN_REF_GOTO, getContents())); + bv.owner()->dispatch(FuncRequest(LFUN_REF_GOTO, getContents())); else - InsetCommandMailer("ref", *this).showDialog(cmd.view()); + InsetCommandMailer("ref", *this).showDialog(&bv); return DispatchResult(true, true); default: - return InsetCommand::priv_dispatch(cmd, idx, pos); + return InsetCommand::priv_dispatch(bv, cmd); } } diff --git a/src/insets/insetref.h b/src/insets/insetref.h index 73ab89aa39..dc13a021eb 100644 --- a/src/insets/insetref.h +++ b/src/insets/insetref.h @@ -70,7 +70,7 @@ protected: /// virtual DispatchResult - priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &); + priv_dispatch(BufferView & bv, FuncRequest const & cmd); private: /// bool isLatex; diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index f00f825910..8f912121e4 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -375,9 +375,9 @@ string const InsetTabular::editMessage() const } -void InsetTabular::updateLocal(BufferView * bv) const +void InsetTabular::updateLocal(BufferView & bv) const { - bv->update(); + bv.update(); resetPos(bv); } @@ -385,64 +385,62 @@ extern LCursor theTempCursor; -void InsetTabular::lfunMousePress(FuncRequest const & cmd) +void InsetTabular::lfunMousePress(BufferView & bv, FuncRequest const & cmd) { if (hasSelection() && cmd.button() == mouse_button::button3) return; - BufferView * bv = cmd.view(); - int cell = getCell(cmd.x + xo_, cmd.y + yo_); clearSelection(); lyxerr << "# InsetTabular::lfunMousePress cell: " << cell << endl; if (cell == -1) { tablemode = true; - bv->fullCursor(theTempCursor); - bv->fullCursor().push(this); - bv->fullCursor().cell(cell); + bv.fullCursor(theTempCursor); + bv.fullCursor().push(this); + bv.fullCursor().cell(cell); } else { tablemode = false; setPos(bv, cmd.x, cmd.y); - bv->fullCursor(theTempCursor); - bv->fullCursor().cell(cell); + bv.fullCursor(theTempCursor); + bv.fullCursor().cell(cell); } - lyxerr << bv->cursor() << endl; + lyxerr << bv.cursor() << endl; if (cmd.button() == mouse_button::button2) - dispatch(FuncRequest(bv, LFUN_PASTESELECTION, "paragraph")); + dispatch(bv, FuncRequest(LFUN_PASTESELECTION, "paragraph")); } -void InsetTabular::lfunMouseMotion(FuncRequest const & cmd) +void InsetTabular::lfunMouseMotion(BufferView & bv, FuncRequest const & cmd) { - BufferView * bv = cmd.view(); int const actcell = getCell(cmd.x + xo_, cmd.y + yo_); lyxerr << "# InsetTabular::lfunMouseMotion cell: " << actcell << endl; setPos(bv, cmd.x, cmd.y); if (!hasSelection()) { setSelection(actcell, actcell); - bv->setSelection(); + bv.setSelection(); } else { - bv->cursor().cell(actcell); + bv.cursor().idx(actcell); setSelection(sel_cell_start, actcell); tablemode = (sel_cell_start != actcell); } } -void InsetTabular::lfunMouseRelease(FuncRequest const & cmd) +void InsetTabular::lfunMouseRelease(BufferView & bv, FuncRequest const & cmd) { int const actcell = getCell(cmd.x + xo_, cmd.y + yo_); lyxerr << "# InsetTabular::lfunMouseRelease cell: " << actcell << endl; if (cmd.button() == mouse_button::button3) - InsetTabularMailer(*this).showDialog(cmd.view()); + InsetTabularMailer(*this).showDialog(&bv); } -void InsetTabular::edit(BufferView * bv, bool left) +void InsetTabular::edit(BufferView * view, bool left) { + BufferView & bv = *view; lyxerr << "InsetTabular::edit: " << this << endl; finishUndo(); //tablemode = false; @@ -460,10 +458,10 @@ void InsetTabular::edit(BufferView * bv, bool left) } clearSelection(); resetPos(bv); - bv->fitCursor(); - bv->fullCursor().push(this); - bv->fullCursor().cell(cell); - lyxerr << bv->cursor() << endl; + bv.fitCursor(); + bv.fullCursor().push(this); + bv.fullCursor().cell(cell); + lyxerr << bv.cursor() << endl; } @@ -473,7 +471,7 @@ void InsetTabular::edit(BufferView * bv, int x, int y) << &tabular.cell_info[0][0].inset << endl; finishUndo(); - setPos(bv, x, y); + setPos(*bv, x, y); clearSelection(); finishUndo(); //int xx = cursorx_ - xo_ + tabular.getBeginningOfTextInCell(actcell); @@ -484,40 +482,37 @@ void InsetTabular::edit(BufferView * bv, int x, int y) DispatchResult -InsetTabular::priv_dispatch(FuncRequest const & cmd, - idx_type & idx, pos_type & pos) +InsetTabular::priv_dispatch(BufferView & bv, FuncRequest const & cmd) { lyxerr << "# InsetTabular::dispatch: " << cmd << " tablemode: " << tablemode << endl; DispatchResult result(true, true); - BufferView * bv = cmd.view(); - switch (cmd.action) { case LFUN_MOUSE_PRESS: - lfunMousePress(cmd); + lfunMousePress(bv, cmd); return DispatchResult(true, true); case LFUN_MOUSE_MOTION: - lfunMouseMotion(cmd); + lfunMouseMotion(bv, cmd); return DispatchResult(true, true); case LFUN_MOUSE_RELEASE: - lfunMouseRelease(cmd); + lfunMouseRelease(bv, cmd); return DispatchResult(true, true); default: break; } - CursorSlice & cur = bv->cursor(); + CursorSlice & cur = bv.cursor(); if (!tablemode) { int cell = cur.idx_; lyxerr << "# InsetTabular::dispatch: A " << cur << endl; - result = tabular.getCellInset(cell).dispatch(cmd, idx, pos); + result = tabular.getCellInset(cell).dispatch(bv, cmd); switch (result.val()) { case FINISHED: @@ -571,10 +566,10 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, case LFUN_SCROLL_INSET: if (!cmd.argument.empty()) { if (cmd.argument.find('.') != cmd.argument.npos) - scroll(cmd.view(), static_cast(strToDbl(cmd.argument))); + scroll(bv, static_cast(strToDbl(cmd.argument))); else - scroll(cmd.view(), strToInt(cmd.argument)); - cmd.view()->update(); + scroll(bv, strToInt(cmd.argument)); + bv.update(); return DispatchResult(true, true); } @@ -677,16 +672,16 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, case LFUN_NEXT: { if (hasSelection()) clearSelection(); - int actcell = bv->cursor().idx(); + int actcell = bv.cursor().idx(); int actcol = tabular.column_of_cell(actcell); int column = actcol; - if (bv->top_y() + bv->painter().paperHeight() + if (bv.top_y() + bv.painter().paperHeight() < yo_ + tabular.getHeightOfTabular()) { - bv->scrollDocView(bv->top_y() + bv->painter().paperHeight()); - cur.idx_ = tabular.getCellBelow(first_visible_cell) + column; + bv.scrollDocView(bv.top_y() + bv.painter().paperHeight()); + cur.idx() = tabular.getCellBelow(first_visible_cell) + column; } else { - cur.idx_ = tabular.getFirstCellInRow(tabular.rows() - 1) + column; + cur.idx() = tabular.getFirstCellInRow(tabular.rows() - 1) + column; } resetPos(bv); break; @@ -695,17 +690,17 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, case LFUN_PRIOR: { if (hasSelection()) clearSelection(); - int actcell = bv->cursor().idx(); + int actcell = bv.cursor().idx(); int actcol = tabular.column_of_cell(actcell); int column = actcol; if (yo_ < 0) { - bv->scrollDocView(bv->top_y() - bv->painter().paperHeight()); + bv.scrollDocView(bv.top_y() - bv.painter().paperHeight()); if (yo_ > 0) - cur.idx_ = column; + cur.idx() = column; else - cur.idx_ = tabular.getCellBelow(first_visible_cell) + column; + cur.idx() = tabular.getCellBelow(first_visible_cell) + column; } else { - cur.idx_ = column; + cur.idx() = column; } resetPos(bv); break; @@ -737,11 +732,11 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, break; case LFUN_LAYOUT_TABULAR: - InsetTabularMailer(*this).showDialog(bv); + InsetTabularMailer(*this).showDialog(&bv); break; case LFUN_INSET_DIALOG_UPDATE: - InsetTabularMailer(*this).updateDialog(bv); + InsetTabularMailer(*this).updateDialog(&bv); break; case LFUN_TABULAR_FEATURE: @@ -752,7 +747,7 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, // insert file functions case LFUN_FILE_INSERT_ASCII_PARA: case LFUN_FILE_INSERT_ASCII: { - string tmpstr = getContentsOfAsciiFile(bv, cmd.argument, false); + string tmpstr = getContentsOfAsciiFile(&bv, cmd.argument, false); if (!tmpstr.empty() && !insertAsciiString(bv, tmpstr, false)) result = DispatchResult(false); break; @@ -774,13 +769,13 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, case LFUN_CUT: if (copySelection(bv)) { recordUndo(bv, Undo::DELETE); - cutSelection(bv->buffer()->params()); + cutSelection(bv.buffer()->params()); } break; case LFUN_DELETE: recordUndo(bv, Undo::DELETE); - cutSelection(bv->buffer()->params()); + cutSelection(bv.buffer()->params()); break; case LFUN_COPY: @@ -791,7 +786,7 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, break; case LFUN_PASTESELECTION: { - string const clip = bv->getClipboard(); + string const clip = bv.getClipboard(); if (clip.empty()) break; if (clip.find('\t') != string::npos) { @@ -819,7 +814,7 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, maxCols = max(cols, maxCols); paste_tabular.reset( - new LyXTabular(bv->buffer()->params(), rows, maxCols)); + new LyXTabular(bv.buffer()->params(), rows, maxCols)); string::size_type op = 0; int cell = 0; @@ -883,7 +878,7 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, } updateLocal(bv); - InsetTabularMailer(*this).updateDialog(bv); + InsetTabularMailer(*this).updateDialog(&bv); } if (cmd.action == LFUN_INSET_TOGGLE) { @@ -985,7 +980,7 @@ void InsetTabular::getCursorPos(int cell, int & x, int & y) const } -void InsetTabular::setPos(BufferView * bv, int x, int y) const +void InsetTabular::setPos(BufferView & bv, int x, int y) const { int const cell = getCell(x + xo_, y + yo_); lyxerr << "# InsetTabular::setPos() cell: " << cell << endl; @@ -1036,7 +1031,7 @@ int InsetTabular::getCellXPos(int cell) const } -void InsetTabular::resetPos(BufferView *) const +void InsetTabular::resetPos(BufferView &) const { #if 0 #ifdef WITH_WARNINGS @@ -1074,15 +1069,15 @@ void InsetTabular::resetPos(BufferView *) const updateLocal(bv); } else if (cursorx_ - offset > 20 && cursorx_ - offset + tabular.getWidthOfColumn(actcell) - > bv->workWidth() - 20) { - scroll(bv, - tabular.getWidthOfColumn(actcell) - 20); + > bv.workWidth() - 20) { + scroll(&bv, - tabular.getWidthOfColumn(actcell) - 20); updateLocal(bv); } else if (cursorx_ - offset < 20) { - scroll(bv, 20 - cursorx_ + offset); + scroll(&bv, 20 - cursorx_ + offset); updateLocal(bv); } else if (scroll() && xo_ > 20 && xo_ + tabular.getWidthOfTabular() > bv->workWidth() - 20) { - scroll(bv, old_x - cursorx_); + scroll(&bv, old_x - cursorx_); updateLocal(bv); } InsetTabularMailer(*this).updateDialog(bv); @@ -1091,7 +1086,7 @@ void InsetTabular::resetPos(BufferView *) const } -bool InsetTabular::moveRight(BufferView * bv, CursorSlice & cur) +bool InsetTabular::moveRight(BufferView & bv, CursorSlice & cur) { bool moved = isRightToLeft(bv) ? movePrevCell(bv, cur) : moveNextCell(bv, cur); @@ -1102,7 +1097,7 @@ bool InsetTabular::moveRight(BufferView * bv, CursorSlice & cur) } -bool InsetTabular::moveRightLock(BufferView * bv, CursorSlice & cur) +bool InsetTabular::moveRightLock(BufferView & bv, CursorSlice & cur) { bool moved = isRightToLeft(bv) ? movePrevCell(bv, cur) : moveNextCell(bv, cur); @@ -1113,7 +1108,7 @@ bool InsetTabular::moveRightLock(BufferView * bv, CursorSlice & cur) } -bool InsetTabular::moveLeft(BufferView * bv, CursorSlice & cur) +bool InsetTabular::moveLeft(BufferView & bv, CursorSlice & cur) { bool moved = isRightToLeft(bv) ? moveNextCell(bv, cur) : movePrevCell(bv, cur); @@ -1124,7 +1119,7 @@ bool InsetTabular::moveLeft(BufferView * bv, CursorSlice & cur) } -bool InsetTabular::moveLeftLock(BufferView * bv, CursorSlice & cur) +bool InsetTabular::moveLeftLock(BufferView & bv, CursorSlice & cur) { bool moved = isRightToLeft(bv) ? moveNextCell(bv, cur) : movePrevCell(bv, cur); @@ -1135,7 +1130,7 @@ bool InsetTabular::moveLeftLock(BufferView * bv, CursorSlice & cur) } -bool InsetTabular::moveUp(BufferView * bv, CursorSlice & cur) +bool InsetTabular::moveUp(BufferView & bv, CursorSlice & cur) { if (tabular.row_of_cell(cur.idx_) == 0) return false; @@ -1145,18 +1140,18 @@ bool InsetTabular::moveUp(BufferView * bv, CursorSlice & cur) } -bool InsetTabular::moveUpLock(BufferView * bv, CursorSlice & cur) +bool InsetTabular::moveUpLock(BufferView & bv, CursorSlice & cur) { if (tabular.row_of_cell(cur.idx_) == 0) return false; cur.idx_ = tabular.getCellAbove(cur.idx_); resetPos(bv); - activateCellInset(bv, cur.idx_, bv->x_target(), 0); + activateCellInset(bv, cur.idx_, bv.x_target(), 0); return true; } -bool InsetTabular::moveDown(BufferView * bv, CursorSlice & cur) +bool InsetTabular::moveDown(BufferView & bv, CursorSlice & cur) { if (tabular.row_of_cell(cur.idx_) == tabular.rows() - 1) return false; @@ -1166,18 +1161,18 @@ bool InsetTabular::moveDown(BufferView * bv, CursorSlice & cur) } -bool InsetTabular::moveDownLock(BufferView * bv, CursorSlice & cur) +bool InsetTabular::moveDownLock(BufferView & bv, CursorSlice & cur) { if (tabular.row_of_cell(cur.idx_) == tabular.rows() - 1) return false; cur.idx_ = tabular.getCellBelow(cur.idx_); resetPos(bv); - activateCellInset(bv, cur.idx_, bv->x_target()); + activateCellInset(bv, cur.idx_, bv.x_target()); return true; } -bool InsetTabular::moveNextCell(BufferView * bv, CursorSlice & cur) +bool InsetTabular::moveNextCell(BufferView & bv, CursorSlice & cur) { lyxerr << "InsetTabular::moveNextCell 1 cur: " << cur << endl; if (isRightToLeft(bv)) { @@ -1205,7 +1200,7 @@ bool InsetTabular::moveNextCell(BufferView * bv, CursorSlice & cur) } -bool InsetTabular::movePrevCell(BufferView * bv, CursorSlice & cur) +bool InsetTabular::movePrevCell(BufferView & bv, CursorSlice & cur) { if (isRightToLeft(bv)) { if (tabular.isLastCellInRow(cur.idx_)) { @@ -1231,7 +1226,7 @@ bool InsetTabular::movePrevCell(BufferView * bv, CursorSlice & cur) } -bool InsetTabular::tabularFeatures(BufferView * bv, string const & what) +bool InsetTabular::tabularFeatures(BufferView & bv, string const & what) { LyXTabular::Feature action = LyXTabular::LAST_ACTION; @@ -1279,10 +1274,10 @@ void checkLongtableSpecial(LyXTabular::ltType & ltt, } // anon namespace -void InsetTabular::tabularFeatures(BufferView * bv, +void InsetTabular::tabularFeatures(BufferView & bv, LyXTabular::Feature feature, string const & value) { - int actcell = bv->cursor().idx(); + int actcell = bv.cursor().idx(); int sel_col_start; int sel_col_end; int sel_row_start; @@ -1369,13 +1364,13 @@ void InsetTabular::tabularFeatures(BufferView * bv, case LyXTabular::APPEND_ROW: // append the row into the tabular - tabular.appendRow(bv->buffer()->params(), actcell); + tabular.appendRow(bv.buffer()->params(), actcell); tabular.setOwner(this); break; case LyXTabular::APPEND_COLUMN: // append the column into the tabular - tabular.appendColumn(bv->buffer()->params(), actcell); + tabular.appendColumn(bv.buffer()->params(), actcell); tabular.setOwner(this); actcell = tabular.getCellNumber(row, column); break; @@ -1494,7 +1489,7 @@ void InsetTabular::tabularFeatures(BufferView * bv, if (tabular.isMultiColumn(actcell)) tabular.unsetMultiColumn(actcell); else - tabular.setMultiColumn(bv->buffer(), actcell, 1); + tabular.setMultiColumn(bv.buffer(), actcell, 1); break; } // we have a selection so this means we just add all this @@ -1509,7 +1504,7 @@ void InsetTabular::tabularFeatures(BufferView * bv, s_start = sel_cell_start; s_end = sel_cell_end; } - tabular.setMultiColumn(bv->buffer(), s_start, s_end - s_start + 1); + tabular.setMultiColumn(bv.buffer(), s_start, s_end - s_start + 1); actcell = s_start; clearSelection(); break; @@ -1606,22 +1601,22 @@ void InsetTabular::tabularFeatures(BufferView * bv, } updateLocal(bv); - InsetTabularMailer(*this).updateDialog(bv); + InsetTabularMailer(*this).updateDialog(&bv); } -void InsetTabular::activateCellInset(BufferView * bv, int cell, int x, int y) +void InsetTabular::activateCellInset(BufferView & bv, int cell, int x, int y) { - tabular.getCellInset(cell).edit(bv, x, y); - bv->cursor().cell(cell); + tabular.getCellInset(cell).edit(&bv, x, y); + bv.cursor().idx(cell); updateLocal(bv); } -void InsetTabular::activateCellInset(BufferView * bv, int cell, bool behind) +void InsetTabular::activateCellInset(BufferView & bv, int cell, bool behind) { - tabular.getCellInset(cell).edit(bv, behind); - bv->cursor().cell(cell); + tabular.getCellInset(cell).edit(&bv, behind); + bv.cursor().idx(cell); updateLocal(bv); } @@ -1828,7 +1823,7 @@ void InsetTabular::getLabelList(Buffer const & buffer, } -bool InsetTabular::copySelection(BufferView * bv) +bool InsetTabular::copySelection(BufferView & bv) { if (!hasSelection()) return false; @@ -1874,18 +1869,18 @@ bool InsetTabular::copySelection(BufferView * bv) ostringstream os; OutputParams const runparams; - paste_tabular->plaintext(*bv->buffer(), os, runparams, - ownerPar(*bv->buffer(), this).params().depth(), true, '\t'); - bv->stuffClipboard(os.str()); + paste_tabular->plaintext(*bv.buffer(), os, runparams, + ownerPar(*bv.buffer(), this).params().depth(), true, '\t'); + bv.stuffClipboard(os.str()); return true; } -bool InsetTabular::pasteSelection(BufferView * bv) +bool InsetTabular::pasteSelection(BufferView & bv) { if (!paste_tabular) return false; - int actcell = bv->cursor().idx(); + int actcell = bv.cursor().idx(); int actcol = tabular.column_of_cell(actcell); int actrow = tabular.row_of_cell(actcell); for (int r1 = 0, r2 = actrow; @@ -1946,9 +1941,9 @@ bool InsetTabular::cutSelection(BufferParams const & bp) } -bool InsetTabular::isRightToLeft(BufferView * bv) +bool InsetTabular::isRightToLeft(BufferView & bv) { - return bv->getParentLanguage(this)->RightToLeft(); + return bv.getParentLanguage(this)->RightToLeft(); } @@ -2011,7 +2006,7 @@ bool InsetTabular::forceDefaultParagraphs(InsetOld const * in) const } -bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf, +bool InsetTabular::insertAsciiString(BufferView & bv, string const & buf, bool usePaste) { if (buf.length() <= 0) @@ -2023,7 +2018,7 @@ bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf, string::size_type len = buf.length(); string::size_type p = 0; - int actcell = bv->cursor().idx(); + int actcell = bv.cursor().idx(); int actcol = tabular.column_of_cell(actcell); int actrow = tabular.row_of_cell(actcell); @@ -2048,9 +2043,7 @@ bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf, int row = 0; if (usePaste) { paste_tabular.reset( - new LyXTabular(bv->buffer()->params(), rows, maxCols) - ); - + new LyXTabular(bv.buffer()->params(), rows, maxCols)); paste_tabular->setOwner(this); loctab = paste_tabular.get(); cols = 0; diff --git a/src/insets/insettabular.h b/src/insets/insettabular.h index 09a509de3a..e7c90a4415 100644 --- a/src/insets/insettabular.h +++ b/src/insets/insettabular.h @@ -82,7 +82,7 @@ public: /// std::string const editMessage() const; /// - void updateLocal(BufferView *) const; + void updateLocal(BufferView & bv) const; /// bool insetAllowed(InsetOld::Code) const { return true; } /// @@ -112,9 +112,9 @@ public: /// get the absolute screen x,y of the cursor void getCursorPos(int cell, int & x, int & y) const; /// - bool tabularFeatures(BufferView * bv, std::string const & what); + bool tabularFeatures(BufferView & bv, std::string const & what); /// - void tabularFeatures(BufferView * bv, LyXTabular::Feature feature, + void tabularFeatures(BufferView & bv, LyXTabular::Feature feature, std::string const & val = std::string()); /// void openLayoutDialog(BufferView *) const; @@ -162,14 +162,14 @@ protected: /// virtual DispatchResult - priv_dispatch(FuncRequest const &, idx_type &, pos_type &); + priv_dispatch(BufferView & bv, FuncRequest const & cmd); private: /// - void lfunMousePress(FuncRequest const &); + void lfunMousePress(BufferView & bv, FuncRequest const & cmd); /// - void lfunMouseRelease(FuncRequest const &); + void lfunMouseRelease(BufferView & bv, FuncRequest const & cmd); /// - void lfunMouseMotion(FuncRequest const &); + void lfunMouseMotion(BufferView & bv, FuncRequest const & cmd); /// void calculate_dimensions_of_cells(MetricsInfo & mi) const; /// @@ -179,35 +179,35 @@ private: void drawCellSelection(Painter &, int x, int baseline, int row, int column, int cell) const; /// - void setPos(BufferView *, int x, int y) const; + void setPos(BufferView &, int x, int y) const; /// - bool moveRight(BufferView *, CursorSlice & cur); + bool moveRight(BufferView &, CursorSlice & cur); /// - bool moveLeft(BufferView *, CursorSlice & cur); + bool moveLeft(BufferView &, CursorSlice & cur); /// - bool moveUp(BufferView *, CursorSlice & cur); + bool moveUp(BufferView &, CursorSlice & cur); /// - bool moveDown(BufferView *, CursorSlice & cur); + bool moveDown(BufferView &, CursorSlice & cur); /// - bool moveRightLock(BufferView *, CursorSlice & cur); + bool moveRightLock(BufferView &, CursorSlice & cur); /// - bool moveLeftLock(BufferView *, CursorSlice & cur); + bool moveLeftLock(BufferView &, CursorSlice & cur); /// - bool moveUpLock(BufferView *, CursorSlice & cur); + bool moveUpLock(BufferView &, CursorSlice & cur); /// - bool moveDownLock(BufferView *, CursorSlice & cur); + bool moveDownLock(BufferView &, CursorSlice & cur); /// - bool moveNextCell(BufferView *, CursorSlice & cur); + bool moveNextCell(BufferView &, CursorSlice & cur); /// - bool movePrevCell(BufferView *, CursorSlice & cur); + bool movePrevCell(BufferView &, CursorSlice & cur); /// int getCellXPos(int cell) const; /// - void resetPos(BufferView *) const; + void resetPos(BufferView &) const; /// void removeTabularRow(); /// @@ -215,24 +215,24 @@ private: /// void setSelection(int start, int end) const; /// - void activateCellInset(BufferView *, int cell, int x, int y); + void activateCellInset(BufferView &, int cell, int x, int y); /// - void activateCellInset(BufferView *, int cell, bool behind); + void activateCellInset(BufferView &, int cell, bool behind); /// bool hasPasteBuffer() const; /// - bool copySelection(BufferView *); + bool copySelection(BufferView &); /// - bool pasteSelection(BufferView *); + bool pasteSelection(BufferView &); /// bool cutSelection(BufferParams const & bp); /// - bool isRightToLeft(BufferView *); + bool isRightToLeft(BufferView &); /// void getSelection(int cell, int & scol, int & ecol, int & srow, int & erow) const; /// - bool insertAsciiString(BufferView *, std::string const & buf, bool usePaste); + bool insertAsciiString(BufferView &, std::string const & buf, bool usePaste); // // Private structures and variables diff --git a/src/insets/insettext.C b/src/insets/insettext.C index aa15d2e3d2..cd4953c42a 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -298,14 +298,13 @@ void InsetText::edit(BufferView * bv, int x, int y) } -DispatchResult InsetText::priv_dispatch(FuncRequest const & cmd, - idx_type &, pos_type &) +DispatchResult +InsetText::priv_dispatch(BufferView & bv, FuncRequest const & cmd) { //lyxerr << "InsetText::priv_dispatch (begin), act: " // << cmd.action << " " << endl; - BufferView * bv = cmd.view(); - setViewCache(bv); + setViewCache(&bv); DispatchResult result; result.dispatched(true); @@ -314,10 +313,10 @@ DispatchResult InsetText::priv_dispatch(FuncRequest const & cmd, switch (cmd.action) { case LFUN_MOUSE_PRESS: - bv->fullCursor(theTempCursor); + bv.fullCursor(theTempCursor); // fall through default: - result = text_.dispatch(cmd); + result = text_.dispatch(bv, cmd); break; } @@ -327,7 +326,7 @@ DispatchResult InsetText::priv_dispatch(FuncRequest const & cmd, if (!was_empty && paragraphs().begin()->empty() && paragraphs().size() == 1) { LyXFont font(LyXFont::ALL_IGNORE); - font.setLanguage(bv->getParentLanguage(this)); + font.setLanguage(bv.getParentLanguage(this)); text_.setFont(font, false); } diff --git a/src/insets/insettext.h b/src/insets/insettext.h index 6ed086f9d6..c09f845873 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -116,11 +116,11 @@ public: /// int scroll(bool recursive = true) const; /// - void scroll(BufferView * bv, float sx) const { + void scroll(BufferView & bv, float sx) const { UpdatableInset::scroll(bv, sx); } /// - void scroll(BufferView * bv, int offset) const { + void scroll(BufferView & bv, int offset) const { UpdatableInset::scroll(bv, offset); } /// @@ -156,7 +156,7 @@ public: private: /// DispatchResult - priv_dispatch(FuncRequest const &, idx_type &, pos_type &); + priv_dispatch(BufferView & bv, FuncRequest const & cmd); /// void updateLocal(BufferView *); /// diff --git a/src/insets/insetvspace.C b/src/insets/insetvspace.C index 7b7c9a3998..9a249fffe5 100644 --- a/src/insets/insetvspace.C +++ b/src/insets/insetvspace.C @@ -60,8 +60,7 @@ std::auto_ptr InsetVSpace::clone() const DispatchResult -InsetVSpace::priv_dispatch(FuncRequest const & cmd, - idx_type & idx, pos_type & pos) +InsetVSpace::priv_dispatch(BufferView & bv, FuncRequest const & cmd) { switch (cmd.action) { @@ -71,11 +70,11 @@ InsetVSpace::priv_dispatch(FuncRequest const & cmd, } case LFUN_MOUSE_PRESS: - InsetVSpaceMailer(*this).showDialog(cmd.view()); + InsetVSpaceMailer(*this).showDialog(&bv); return DispatchResult(true, true); default: - return InsetOld::priv_dispatch(cmd, idx, pos); + return InsetOld::priv_dispatch(bv, cmd); } } diff --git a/src/insets/insetvspace.h b/src/insets/insetvspace.h index 42113b4e0f..4ce44ce6bf 100644 --- a/src/insets/insetvspace.h +++ b/src/insets/insetvspace.h @@ -56,7 +56,7 @@ protected: /// virtual DispatchResult - priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &); + priv_dispatch(BufferView & bv, FuncRequest const & cmd); private: /// diff --git a/src/insets/insetwrap.C b/src/insets/insetwrap.C index df42307e19..1ea115fb2a 100644 --- a/src/insets/insetwrap.C +++ b/src/insets/insetwrap.C @@ -80,8 +80,7 @@ InsetWrap::~InsetWrap() DispatchResult -InsetWrap::priv_dispatch(FuncRequest const & cmd, - idx_type & idx, pos_type & pos) +InsetWrap::priv_dispatch(BufferView & bv, FuncRequest const & cmd) { switch (cmd.action) { case LFUN_INSET_MODIFY: { @@ -91,16 +90,16 @@ InsetWrap::priv_dispatch(FuncRequest const & cmd, params_.placement = params.placement; params_.width = params.width; - cmd.view()->update(); + bv.update(); return DispatchResult(true, true); } case LFUN_INSET_DIALOG_UPDATE: - InsetWrapMailer(*this).updateDialog(cmd.view()); + InsetWrapMailer(*this).updateDialog(&bv); return DispatchResult(true, true); default: - return InsetCollapsable::priv_dispatch(cmd, idx, pos); + return InsetCollapsable::priv_dispatch(bv, cmd); } } diff --git a/src/insets/insetwrap.h b/src/insets/insetwrap.h index 7525d45838..60a8872a87 100644 --- a/src/insets/insetwrap.h +++ b/src/insets/insetwrap.h @@ -70,7 +70,7 @@ protected: /// virtual DispatchResult - priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &); + priv_dispatch(BufferView & bv, FuncRequest const & cmd); private: /// InsetWrapParams params_; diff --git a/src/insets/updatableinset.C b/src/insets/updatableinset.C index a0cc5e25cb..dfd3aedd34 100644 --- a/src/insets/updatableinset.C +++ b/src/insets/updatableinset.C @@ -37,14 +37,14 @@ InsetOld::EDITABLE UpdatableInset::editable() const } -void UpdatableInset::scroll(BufferView * bv, float s) const +void UpdatableInset::scroll(BufferView & bv, float s) const { if (!s) { scx = 0; return; } - int const workW = bv->workWidth(); + int const workW = bv.workWidth(); int const tmp_xo_ = xo_ - scx; if (tmp_xo_ > 0 && tmp_xo_ + width() < workW) @@ -60,7 +60,7 @@ void UpdatableInset::scroll(BufferView * bv, float s) const } -void UpdatableInset::scroll(BufferView * bv, int offset) const +void UpdatableInset::scroll(BufferView & bv, int offset) const { if (offset > 0) { if (!scx && xo_ >= 20) @@ -72,10 +72,10 @@ void UpdatableInset::scroll(BufferView * bv, int offset) const scx += offset; } else { #warning metrics? - if (!scx && xo_ + width() < bv->workWidth() - 20) + if (!scx && xo_ + width() < bv.workWidth() - 20) return; - if (xo_ - scx + offset + width() < bv->workWidth() - 20) { - scx += bv->workWidth() - width() - xo_ - 20; + if (xo_ - scx + offset + width() < bv.workWidth() - 20) { + scx += bv.workWidth() - width() - xo_ - 20; } else { scx += offset; } @@ -85,7 +85,7 @@ void UpdatableInset::scroll(BufferView * bv, int offset) const /// An updatable inset could handle lyx editing commands DispatchResult -UpdatableInset::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &) +UpdatableInset::priv_dispatch(BufferView & bv, FuncRequest const & cmd) { switch (cmd.action) { case LFUN_MOUSE_RELEASE: @@ -94,10 +94,10 @@ UpdatableInset::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &) case LFUN_SCROLL_INSET: if (!cmd.argument.empty()) { if (cmd.argument.find('.') != cmd.argument.npos) - scroll(cmd.view(), static_cast(strToDbl(cmd.argument))); + scroll(bv, static_cast(strToDbl(cmd.argument))); else - scroll(cmd.view(), strToInt(cmd.argument)); - cmd.view()->update(); + scroll(bv, strToInt(cmd.argument)); + bv.update(); return DispatchResult(true, true); } diff --git a/src/insets/updatableinset.h b/src/insets/updatableinset.h index b549dc212f..51382ed940 100644 --- a/src/insets/updatableinset.h +++ b/src/insets/updatableinset.h @@ -25,7 +25,7 @@ class UpdatableInset : public InsetOld { public: /// virtual EDITABLE editable() const; - /// identification as math inset + /// identification as text inset in a cursor slice UpdatableInset * asUpdatableInset() { return this; } /// return the cursor pos, relative to the inset pos @@ -37,18 +37,16 @@ public: { return InsetOld::scroll(recursive); } /// virtual bool showInsetDialog(BufferView *) const { return false; } - /// - virtual void toggleSelection(BufferView *, bool /*kill_selection*/) {} protected: /// An updatable inset could handle lyx editing commands virtual DispatchResult - priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &); + priv_dispatch(BufferView & bv, FuncRequest const & cmd); /// scrolls to absolute position in bufferview-workwidth * sx units - void scroll(BufferView *, float sx) const; + void scroll(BufferView &, float sx) const; /// scrolls offset pixels - void scroll(BufferView *, int offset) const; + void scroll(BufferView &, int offset) const; }; #endif diff --git a/src/lyxfind.C b/src/lyxfind.C index 96c3da77a0..65d5843b6b 100644 --- a/src/lyxfind.C +++ b/src/lyxfind.C @@ -106,9 +106,9 @@ string const replace2string(string const & search, string const & replace, } -void find(FuncRequest const & ev) +void find(BufferView * bv, FuncRequest const & ev) { - if (!ev.view() || ev.action != LFUN_WORD_FIND) + if (!bv || ev.action != LFUN_WORD_FIND) return; // data is of the form @@ -121,7 +121,6 @@ void find(FuncRequest const & ev) bool matchword = parse_bool(howto); bool forward = parse_bool(howto); - BufferView * bv = ev.view(); bool const found = ::find(bv, search, forward, casesensitive, matchword); @@ -130,9 +129,9 @@ void find(FuncRequest const & ev) } -void replace(FuncRequest const & ev) +void replace(BufferView * bv, FuncRequest const & ev) { - if (!ev.view() || ev.action != LFUN_WORD_REPLACE) + if (!bv || ev.action != LFUN_WORD_REPLACE) return; // data is of the form @@ -149,7 +148,6 @@ void replace(FuncRequest const & ev) bool all = parse_bool(howto); bool forward = parse_bool(howto); - BufferView * bv = ev.view(); LyXView * lv = bv->owner(); int const replace_count = all ? diff --git a/src/lyxfind.h b/src/lyxfind.h index f37642513b..8a82caac87 100644 --- a/src/lyxfind.h +++ b/src/lyxfind.h @@ -49,13 +49,13 @@ std::string const replace2string(std::string const & search, * \c ev.argument and act on it. * The string is encoded by \c find2string. */ -void find(FuncRequest const & ev); +void find(BufferView * bv, FuncRequest const & ev); /** Parse the string encoding of the replace request that is found in * \c ev.argument and act on it. * The string is encoded by \c replace2string. */ -void replace(FuncRequest const &); +void replace(BufferView * bv, FuncRequest const &); /// find the next change in the buffer bool findNextChange(BufferView * bv); diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 4b040eb805..284f1202b1 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -257,9 +257,7 @@ void LyXFunc::processKeySym(LyXKeySymPtr keysym, if (encoded_last_key != 0) { string arg; arg += encoded_last_key; - - dispatch(FuncRequest(view(), LFUN_SELFINSERT, arg)); - + dispatch(FuncRequest(LFUN_SELFINSERT, arg)); lyxerr[Debug::KEY] << "SelfInsert arg[`" << argument << "']" << endl; } @@ -888,10 +886,8 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose) bool const fw = action == LFUN_WORDFINDFORWARD; string const data = - lyx::find::find2string(searched_string, - true, false, fw); - FuncRequest const fr(view(), LFUN_WORD_FIND, data); - view()->dispatch(fr); + lyx::find::find2string(searched_string, true, false, fw); + view()->dispatch(FuncRequest(LFUN_WORD_FIND, data)); break; } @@ -1295,7 +1291,7 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose) case LFUN_INSET_DIALOG_SHOW: { InsetOld * inset = view()->getLyXText()->getInset(); if (inset) - inset->dispatch(FuncRequest(view(), LFUN_INSET_DIALOG_SHOW)); + inset->dispatch(*view(), FuncRequest(LFUN_INSET_DIALOG_SHOW)); break; } @@ -1304,9 +1300,8 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose) // Can only update a dialog connected to an existing inset InsetBase * inset = owner->getDialogs().getOpenInset(name); if (inset) { - FuncRequest fr(view(), LFUN_INSET_DIALOG_UPDATE, - func.argument); - inset->dispatch(fr); + FuncRequest fr(LFUN_INSET_DIALOG_UPDATE, func.argument); + inset->dispatch(*view(), fr); } else if (name == "paragraph") { dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE)); } @@ -1444,18 +1439,12 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose) break; case LFUN_EXTERNAL_EDIT: - InsetExternal().dispatch(FuncRequest(view(), action, argument)); + InsetExternal().dispatch(*view(), FuncRequest(action, argument)); break; - default: { - DispatchResult result = - view()->fullCursor().dispatch(FuncRequest(func, view())); - if (result.dispatched()) - lyxerr << "dispatched by Cursor::dispatch()" << endl; - else - lyxerr << "### NOT DISPATCHED BY Cursor::dispatch() ###" << endl; - break; - } + default: + view()->fullCursor().dispatch(FuncRequest(func)); + break; } } diff --git a/src/lyxtext.h b/src/lyxtext.h index f63a9a1eaa..87a75db642 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -122,7 +122,7 @@ public: void draw(PainterInfo & pi, int x, int y) const; /// try to handle that request - DispatchResult dispatch(FuncRequest const & cmd); + DispatchResult dispatch(BufferView & bv, FuncRequest const & cmd); BufferView * bv(); diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index f41ca6e5c3..d0f9aaab63 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,10 @@ + + +2004-01-15 André Pönitz + + * *.[Ch]: change signature of priv_dispatch to prepare + inset unification + 2003-12-15 Ronald Florence * math_symbolinset.C: fixed "ugly" patch for Qt/Mac fonts. diff --git a/src/mathed/command_inset.C b/src/mathed/command_inset.C index a2657c8f56..ca0f0ebb4e 100644 --- a/src/mathed/command_inset.C +++ b/src/mathed/command_inset.C @@ -55,12 +55,11 @@ void CommandInset::draw(PainterInfo & pi, int x, int y) const DispatchResult -CommandInset::priv_dispatch(FuncRequest const & cmd, - idx_type & idx, pos_type & pos) +CommandInset::priv_dispatch(BufferView & bv, FuncRequest const & cmd) { switch (cmd.action) { default: - return MathNestInset::priv_dispatch(cmd, idx, pos); + return MathNestInset::priv_dispatch(bv, cmd); } return DispatchResult(false); } diff --git a/src/mathed/command_inset.h b/src/mathed/command_inset.h index c9739b48e2..4ac6a413fb 100644 --- a/src/mathed/command_inset.h +++ b/src/mathed/command_inset.h @@ -42,7 +42,7 @@ protected: /// virtual DispatchResult - priv_dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos); + priv_dispatch(BufferView & bv, FuncRequest const & cmd); private: std::string name_; mutable bool set_label_; diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index 899acf434e..fb3251fbce 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -62,13 +62,13 @@ namespace { int first_x; int first_y; -bool openNewInset(BufferView * bv, UpdatableInset * inset) +bool openNewInset(BufferView & bv, UpdatableInset * inset) { - if (!bv->insertInset(inset)) { + if (!bv.insertInset(inset)) { delete inset; return false; } - inset->edit(bv, true); + inset->edit(&bv, true); return true; } @@ -111,7 +111,7 @@ void InsetFormulaBase::mutateToText() void InsetFormulaBase::handleFont - (BufferView * bv, string const & arg, string const & font) + (BufferView & bv, string const & arg, string const & font) { // this whole function is a hack and won't work for incremental font // changes... @@ -126,7 +126,7 @@ void InsetFormulaBase::handleFont } -void InsetFormulaBase::handleFont2(BufferView * bv, string const & arg) +void InsetFormulaBase::handleFont2(BufferView & bv, string const & arg) { recordUndo(bv, Undo::ATOMIC); LyXFont font; @@ -156,7 +156,7 @@ void InsetFormulaBase::insetUnlock(BufferView * bv) if (mathcursor) { if (mathcursor->inMacroMode()) mathcursor->macroModeClose(); - releaseMathCursor(bv); + releaseMathCursor(*bv); } if (bv->buffer()) generatePreview(*bv->buffer()); @@ -203,13 +203,12 @@ void InsetFormulaBase::toggleInsetSelection(BufferView * bv) } -DispatchResult InsetFormulaBase::lfunMouseRelease(FuncRequest const & cmd) +DispatchResult InsetFormulaBase::lfunMouseRelease( + BufferView & bv, FuncRequest const & cmd) { if (!mathcursor) return DispatchResult(false); - - BufferView * bv = cmd.view(); - bv->update(); + bv.update(); //lyxerr << "lfunMouseRelease: buttons: " << cmd.button() << endl; if (cmd.button() == mouse_button::button3) { @@ -217,28 +216,28 @@ DispatchResult InsetFormulaBase::lfunMouseRelease(FuncRequest const & cmd) if (!mathcursor->dispatch(cmd).dispatched()) { // launch math panel for right mouse button lyxerr << "lfunMouseRelease: undispatched: " << cmd.button() << endl; - bv->owner()->getDialogs().show("mathpanel"); + bv.owner()->getDialogs().show("mathpanel"); } return DispatchResult(true, true); } if (cmd.button() == mouse_button::button2) { MathArray ar; - asArray(bv->getClipboard(), ar); + asArray(bv.getClipboard(), ar); mathcursor->selClear(); mathcursor->setScreenPos(cmd.x + xo_, cmd.y + yo_); mathcursor->insert(ar); - bv->update(); + bv.update(); return DispatchResult(true, true); } if (cmd.button() == mouse_button::button1) { // try to dispatch to enclosed insets first mathcursor->dispatch(cmd); - cmd.view()->stuffClipboard(mathcursor->grabSelection()); + bv.stuffClipboard(mathcursor->grabSelection()); // try to set the cursor //delete mathcursor; - //mathcursor = new MathCursor(this, x == 0); + //mathcursor = new MathCursor(bv, this, x == 0); //metrics(bv); //mathcursor->setScreenPos(x + xo_, y + yo_); return DispatchResult(true, true); @@ -248,15 +247,15 @@ DispatchResult InsetFormulaBase::lfunMouseRelease(FuncRequest const & cmd) } -DispatchResult InsetFormulaBase::lfunMousePress(FuncRequest const & cmd) +DispatchResult InsetFormulaBase::lfunMousePress( + BufferView & bv, FuncRequest const & cmd) { - BufferView * bv = cmd.view(); //lyxerr << "lfunMousePress: buttons: " << cmd.button() << endl; if (!mathcursor || mathcursor->formula() != this) { lyxerr[Debug::MATHED] << "re-create cursor" << endl; releaseMathCursor(bv); - mathcursor = new MathCursor(this, cmd.x == 0); + mathcursor = new MathCursor(&bv, this, cmd.x == 0); //metrics(bv); mathcursor->setScreenPos(cmd.x + xo_, cmd.y + yo_); } @@ -275,12 +274,13 @@ DispatchResult InsetFormulaBase::lfunMousePress(FuncRequest const & cmd) return DispatchResult(true, true); } - bv->update(); + bv.update(); return DispatchResult(true, true); } -DispatchResult InsetFormulaBase::lfunMouseMotion(FuncRequest const & cmd) +DispatchResult InsetFormulaBase::lfunMouseMotion( + BufferView & bv, FuncRequest const & cmd) { if (!mathcursor) return DispatchResult(true, true); @@ -301,9 +301,8 @@ DispatchResult InsetFormulaBase::lfunMouseMotion(FuncRequest const & cmd) if (!mathcursor->selection()) mathcursor->selStart(); - BufferView * bv = cmd.view(); mathcursor->setScreenPos(cmd.x + xo_, cmd.y + yo_); - bv->update(); + bv.update(); return DispatchResult(true, true); } @@ -311,8 +310,8 @@ DispatchResult InsetFormulaBase::lfunMouseMotion(FuncRequest const & cmd) void InsetFormulaBase::edit(BufferView * bv, bool left) { lyxerr << "Called FormulaBase::edit" << endl; - releaseMathCursor(bv); - mathcursor = new MathCursor(this, left); + releaseMathCursor(*bv); + mathcursor = new MathCursor(bv, this, left); bv->fullCursor().push(this); // if that is removed, we won't get the magenta box when entering an // inset for the first time @@ -323,8 +322,8 @@ void InsetFormulaBase::edit(BufferView * bv, bool left) void InsetFormulaBase::edit(BufferView * bv, int x, int y) { lyxerr << "Called FormulaBase::EDIT with '" << x << ' ' << y << "'" << endl; - releaseMathCursor(bv); - mathcursor = new MathCursor(this, true); + releaseMathCursor(*bv); + mathcursor = new MathCursor(bv, this, true); //metrics(bv); mathcursor->setScreenPos(x + xo_, y + yo_); bv->fullCursor().push(this); @@ -335,8 +334,7 @@ void InsetFormulaBase::edit(BufferView * bv, int x, int y) DispatchResult -InsetFormulaBase::priv_dispatch(FuncRequest const & cmd, - idx_type &, pos_type &) +InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd) { //lyxerr << "InsetFormulaBase::localDispatch: act: " << cmd.action // << " arg: '" << cmd.argument @@ -344,24 +342,22 @@ InsetFormulaBase::priv_dispatch(FuncRequest const & cmd, // << " y: '" << cmd.y // << "' button: " << cmd.button() << endl; - BufferView * bv = cmd.view(); - // delete empty mathbox (LFUN_BACKSPACE and LFUN_DELETE) bool remove_inset = false; switch (cmd.action) { case LFUN_MOUSE_PRESS: //lyxerr << "Mouse single press" << endl; - return lfunMousePress(cmd); + return lfunMousePress(bv, cmd); case LFUN_MOUSE_MOTION: //lyxerr << "Mouse motion" << endl; - return lfunMouseMotion(cmd); + return lfunMouseMotion(bv, cmd); case LFUN_MOUSE_RELEASE: //lyxerr << "Mouse single release" << endl; - return lfunMouseRelease(cmd); + return lfunMouseRelease(bv, cmd); case LFUN_MOUSE_DOUBLE: //lyxerr << "Mouse double" << endl; - return dispatch(FuncRequest(LFUN_WORDSEL)); + return dispatch(bv, FuncRequest(LFUN_WORDSEL)); default: break; } @@ -402,9 +398,9 @@ InsetFormulaBase::priv_dispatch(FuncRequest const & cmd, result = mathcursor->right(sel) ? DispatchResult(true, true) : DispatchResult(false, FINISHED_RIGHT); //lyxerr << "calling scroll 20" << endl; - //scroll(bv, 20); + //scroll(&bv, 20); // write something to the minibuffer - //bv->owner()->message(mathcursor->info()); + //bv.owner()->message(mathcursor->info()); break; case LFUN_LEFTSEL: @@ -580,7 +576,7 @@ InsetFormulaBase::priv_dispatch(FuncRequest const & cmd, mathcursor->niceInsert(MathAtom(new MathHullInset("simple"))); else handleFont(bv, cmd.argument, "textrm"); - //bv->owner()->message(_("math text mode toggled")); + //bv.owner()->message(_("math text mode toggled")); break; case LFUN_MATH_SIZE: @@ -630,7 +626,7 @@ InsetFormulaBase::priv_dispatch(FuncRequest const & cmd, break; case LFUN_UNDO: - bv->owner()->message(_("Invalid action in math mode!")); + bv.owner()->message(_("Invalid action in math mode!")); break; @@ -695,18 +691,17 @@ InsetFormulaBase::priv_dispatch(FuncRequest const & cmd, if (data.empty()) result = DispatchResult(false); else - bv->owner()->getDialogs().show(name, data, 0); + bv.owner()->getDialogs().show(name, data, 0); break; } case LFUN_INSET_APPLY: { string const name = cmd.getArg(0); - InsetBase * base = - bv->owner()->getDialogs().getOpenInset(name); + InsetBase * base = bv.owner()->getDialogs().getOpenInset(name); if (base) { - FuncRequest fr(bv, LFUN_INSET_MODIFY, cmd.argument); - result = base->dispatch(fr); + FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument); + result = base->dispatch(bv, fr); } else { MathArray ar; if (createMathInset_fromDialogStr(cmd.argument, ar)) { @@ -722,7 +717,7 @@ InsetFormulaBase::priv_dispatch(FuncRequest const & cmd, case LFUN_WORD_REPLACE: case LFUN_WORD_FIND: { result = - searchForward(cmd.view(), cmd.getArg(0), false, false) + searchForward(&bv, cmd.getArg(0), false, false) ? DispatchResult(true, true) : DispatchResult(false); break; } @@ -732,7 +727,7 @@ InsetFormulaBase::priv_dispatch(FuncRequest const & cmd, } if (result == DispatchResult(true, true)) - bv->update(); + bv.update(); mathcursor->normalize(); mathcursor->touch(); @@ -740,26 +735,26 @@ InsetFormulaBase::priv_dispatch(FuncRequest const & cmd, BOOST_ASSERT(mathcursor); if (mathcursor->selection() || was_selection) - toggleInsetSelection(bv); + toggleInsetSelection(&bv); if (result.dispatched()) { revealCodes(bv); - cmd.view()->stuffClipboard(mathcursor->grabSelection()); + bv.stuffClipboard(mathcursor->grabSelection()); } else { releaseMathCursor(bv); if (remove_inset) - bv->owner()->dispatch(FuncRequest(LFUN_DELETE)); + bv.owner()->dispatch(FuncRequest(LFUN_DELETE)); } return result; // original version } -void InsetFormulaBase::revealCodes(BufferView * bv) const +void InsetFormulaBase::revealCodes(BufferView & bv) const { if (!mathcursor) return; - bv->owner()->message(mathcursor->info()); + bv.owner()->message(mathcursor->info()); #if 0 // write something to the minibuffer @@ -785,7 +780,7 @@ void InsetFormulaBase::revealCodes(BufferView * bv) const res = res.substr(pos - 30); if (res.size() > 60) res = res.substr(0, 60); - bv->owner()->message(res); + bv.owner()->message(res); #endif } @@ -851,7 +846,7 @@ bool InsetFormulaBase::searchForward(BufferView * bv, string const & str, MathArray const & a = top.asMathInset()->cell(top.idx_); if (a.matchpart(ar, top.pos_)) { delete mathcursor; - mathcursor = new MathCursor(this, true); + mathcursor = new MathCursor(bv, this, true); //metrics(bv); mathcursor->setSelection(it, ar.size()); current = it; @@ -889,28 +884,28 @@ string InsetFormulaBase::selectionAsString() const ///////////////////////////////////////////////////////////////////// -void mathDispatchCreation(FuncRequest const & cmd, bool display) +void mathDispatchCreation(BufferView & bv, FuncRequest const & cmd, + bool display) { - BufferView * bv = cmd.view(); // use selection if available.. //string sel; //if (action == LFUN_MATH_IMPORT_SELECTION) // sel = ""; //else - string sel = bv->getLyXText()->selectionAsString(*bv->buffer(), false); + string sel = bv.getLyXText()->selectionAsString(*bv.buffer(), false); if (sel.empty()) { - InsetFormula * f = new InsetFormula(bv); + InsetFormula * f = new InsetFormula(&bv); if (openNewInset(bv, f)) { - bv->fullCursor().innerInset()-> - dispatch(FuncRequest(bv, LFUN_MATH_MUTATE, "simple")); + bv.fullCursor().innerInset()-> + dispatch(bv, FuncRequest(LFUN_MATH_MUTATE, "simple")); // don't do that also for LFUN_MATH_MODE unless you want end up with // always changing to mathrm when opening an inlined inset // -- I really hate "LyXfunc overloading"... if (display) - f->dispatch(FuncRequest(bv, LFUN_MATH_DISPLAY)); - f->dispatch(FuncRequest(bv, LFUN_INSERT_MATH, cmd.argument)); + f->dispatch(bv, FuncRequest(LFUN_MATH_DISPLAY)); + f->dispatch(bv, FuncRequest(LFUN_INSERT_MATH, cmd.argument)); } } else { // create a macro if we see "\\newcommand" somewhere, and an ordinary @@ -921,31 +916,30 @@ void mathDispatchCreation(FuncRequest const & cmd, bool display) f = new InsetFormula(sel); else f = new InsetFormulaMacro(sel); - bv->getLyXText()->cutSelection(true, false); + bv.getLyXText()->cutSelection(true, false); openNewInset(bv, f); } cmd.message(N_("Math editor mode")); } -void mathDispatch(FuncRequest const & cmd) +void mathDispatch(BufferView & bv, FuncRequest const & cmd) { - BufferView * bv = cmd.view(); - if (!bv->available()) + if (!bv.available()) return; switch (cmd.action) { case LFUN_MATH_DISPLAY: - mathDispatchCreation(cmd, true); + mathDispatchCreation(bv, cmd, true); break; case LFUN_MATH_MODE: - mathDispatchCreation(cmd, false); + mathDispatchCreation(bv, cmd, false); break; case LFUN_MATH_IMPORT_SELECTION: - mathDispatchCreation(cmd, false); + mathDispatchCreation(bv, cmd, false); break; case LFUN_MATH_MACRO: @@ -964,11 +958,11 @@ void mathDispatch(FuncRequest const & cmd) case LFUN_INSERT_MATH: case LFUN_INSERT_MATRIX: case LFUN_MATH_DELIM: { - InsetFormula * f = new InsetFormula(bv); + InsetFormula * f = new InsetFormula(&bv); if (openNewInset(bv, f)) { - UpdatableInset * inset = bv->fullCursor().innerInset(); - inset->dispatch(FuncRequest(bv, LFUN_MATH_MUTATE, "simple")); - inset->dispatch(cmd); + UpdatableInset * inset = bv.fullCursor().innerInset(); + inset->dispatch(bv, FuncRequest(LFUN_MATH_MUTATE, "simple")); + inset->dispatch(bv, cmd); } break; } diff --git a/src/mathed/formulabase.h b/src/mathed/formulabase.h index dfc58331ff..e50002ddaa 100644 --- a/src/mathed/formulabase.h +++ b/src/mathed/formulabase.h @@ -75,7 +75,7 @@ public: /// virtual void mutateToText(); /// - virtual void revealCodes(BufferView *) const; + virtual void revealCodes(BufferView & bv) const; /// virtual EDITABLE editable() const { return HIGHLY_EDITABLE; } /// @@ -89,19 +89,18 @@ public: protected: /// To allow transparent use of math editing functions virtual - DispatchResult - priv_dispatch(FuncRequest const &, idx_type &, pos_type &); + DispatchResult priv_dispatch(BufferView & bv, FuncRequest const & cmd); private: /// unimplemented void operator=(const InsetFormulaBase &); /// common base for handling accents - void handleAccent(BufferView * bv, std::string const & arg, std::string const & name); + void handleAccent(BufferView & bv, std::string const & arg, std::string const & name); /// lfun handler - DispatchResult lfunMousePress(FuncRequest const &); + DispatchResult lfunMousePress(BufferView &, FuncRequest const &); /// - DispatchResult lfunMouseRelease(FuncRequest const &); + DispatchResult lfunMouseRelease(BufferView &, FuncRequest const &); /// - DispatchResult lfunMouseMotion(FuncRequest const &); + DispatchResult lfunMouseMotion(BufferView &, FuncRequest const &); protected: @@ -114,16 +113,16 @@ protected: virtual void generatePreview(Buffer const &) const {} /// - void handleFont(BufferView * bv, std::string const & arg, std::string const & font); + void handleFont(BufferView & bv, std::string const & arg, std::string const & font); /// - void handleFont2(BufferView * bv, std::string const & arg); + void handleFont2(BufferView & bv, std::string const & arg); }; // We don't really mess want around with mathed stuff outside mathed. // So do it here. -void mathDispatch(FuncRequest const &); +void mathDispatch(BufferView & bv, FuncRequest const & cmd); /// -void releaseMathCursor(BufferView * bv); +void releaseMathCursor(BufferView & bv); #endif diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index 11578c0f99..e13156d5d2 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -12,13 +12,13 @@ #include #include "math_cursor.h" -#include "lyxrc.h" -#include "support/limited_stack.h" -#include "dispatchresult.h" +#include "BufferView.h" +#include "cursor.h" #include "debug.h" -#include "support/std_sstream.h" +#include "dispatchresult.h" #include "formulabase.h" #include "funcrequest.h" +#include "lyxrc.h" #include "math_braceinset.h" #include "math_commentinset.h" #include "math_charinset.h" @@ -32,6 +32,9 @@ #include "math_support.h" #include "math_unknowninset.h" +#include "support/limited_stack.h" +#include "support/std_sstream.h" + #include //#define FILEDEBUG 1 @@ -43,7 +46,6 @@ using std::isalpha; #endif using std::min; using std::swap; - using std::ostringstream; @@ -51,25 +53,24 @@ using std::ostringstream; limited_stack theCutBuffer; -MathCursor::MathCursor(InsetFormulaBase * formula, bool front) - : formula_(formula), autocorrect_(false), selection_(false), targetx_(-1) +MathCursor::MathCursor(BufferView * bv, InsetFormulaBase * formula, bool front) + : formula_(formula), autocorrect_(false), selection_(false), bv_(bv) { front ? first() : last(); - Anchor_ = Cursor_; } MathCursor::~MathCursor() { // ensure that 'notifyCursorLeave' is called - while (popLeft()) - ; + //while (popLeft()) + // ; } void MathCursor::push(MathAtom & t) { - Cursor_.push_back(CursorSlice(t.nucleus())); + bv_->fullCursor().push(t.nucleus()); } @@ -77,7 +78,7 @@ void MathCursor::pushLeft(MathAtom & t) { //lyxerr << "Entering atom " << t << " left" << endl; push(t); - t->idxFirst(idx(), pos()); + t->idxFirst(*bv_); } @@ -86,7 +87,7 @@ void MathCursor::pushRight(MathAtom & t) //lyxerr << "Entering atom " << t << " right" << endl; posLeft(); push(t); - t->idxLast(idx(), pos()); + t->idxLast(*bv_); } @@ -99,7 +100,7 @@ bool MathCursor::popLeft() return false; } inset()->notifyCursorLeaves(idx()); - Cursor_.pop_back(); + bv_->fullCursor().pop(); return true; } @@ -113,7 +114,7 @@ bool MathCursor::popRight() return false; } inset()->notifyCursorLeaves(idx()); - Cursor_.pop_back(); + bv_->fullCursor().pop(); posRight(); return true; } @@ -137,11 +138,14 @@ bool MathCursor::popRight() #endif -bool MathCursor::isInside(MathInset const * p) const +bool MathCursor::isInside(MathInset const *) const { +#warning FIXME +/* for (unsigned i = 0; i < depth(); ++i) if (Cursor_[i].asMathInset() == p) return true; +*/ return false; } @@ -154,6 +158,8 @@ bool MathCursor::openable(MathAtom const & t, bool sel) const if (t->lock()) return false; +#warning FIXME +#if 0 if (sel) { // we can't move into anything new during selection if (depth() == Anchor_.size()) @@ -161,6 +167,11 @@ bool MathCursor::openable(MathAtom const & t, bool sel) const if (t.operator->() != Anchor_[depth()].asMathInset()) return false; } +#else + if (sel) + return false; +#endif + return true; } @@ -193,7 +204,7 @@ bool MathCursor::left(bool sel) { dump("Left 1"); autocorrect_ = false; - targetx_ = -1; // "no target" + bv_->x_target(-1); // "no target" if (inMacroMode()) { macroModeClose(); return true; @@ -213,7 +224,7 @@ bool MathCursor::right(bool sel) { dump("Right 1"); autocorrect_ = false; - targetx_ = -1; // "no target" + bv_->x_target(-1); // "no target" if (inMacroMode()) { macroModeClose(); return true; @@ -231,17 +242,21 @@ bool MathCursor::right(bool sel) void MathCursor::first() { - Cursor_.clear(); +#warning FIXME + //Cursor_.clear(); push(formula_->par()); - inset()->idxFirst(idx(), pos()); + inset()->idxFirst(*bv_); + bv_->resetAnchor(); } void MathCursor::last() { - Cursor_.clear(); +#warning FIXME + //Cursor_.clear(); push(formula_->par()); - inset()->idxLast(idx(), pos()); + inset()->idxLast(*bv_); + bv_->resetAnchor(); } @@ -273,7 +288,7 @@ void MathCursor::setScreenPos(int x, int y) dump("setScreenPos 1.5"); first(); } - targetx_ = -1; // "no target" + bv_->x_target(-1); // "no target" dump("setScreenPos 2"); } @@ -285,10 +300,10 @@ bool MathCursor::home(bool sel) autocorrect_ = false; selHandle(sel); macroModeClose(); - if (!inset()->idxHome(idx(), pos())) + if (!inset()->idxHome(*bv_)) return popLeft(); dump("home 2"); - targetx_ = -1; // "no target" + bv_->x_target(-1); // "no target" return true; } @@ -299,10 +314,10 @@ bool MathCursor::end(bool sel) autocorrect_ = false; selHandle(sel); macroModeClose(); - if (!inset()->idxEnd(idx(), pos())) + if (!inset()->idxEnd(*bv_)) return popRight(); dump("end 2"); - targetx_ = -1; // "no target" + bv_->x_target(-1); // "no target" return true; } @@ -491,10 +506,13 @@ bool MathCursor::up(bool sel) dump("up 1"); macroModeClose(); selHandle(sel); +#warning FIXME +#if 0 CursorBase save = Cursor_; if (goUpDown(true)) return true; Cursor_ = save; +#endif autocorrect_ = false; return selection_; } @@ -505,10 +523,13 @@ bool MathCursor::down(bool sel) dump("down 1"); macroModeClose(); selHandle(sel); +#warning FIXME +#if 0 CursorBase save = Cursor_; if (goUpDown(false)) return true; Cursor_ = save; +#endif autocorrect_ = false; return selection_; } @@ -547,8 +568,8 @@ string MathCursor::macroName() const void MathCursor::selClear() { - Anchor_.clear(); - selection_ = false; + bv_->resetAnchor(); + bv_->clearSelection(); } @@ -597,7 +618,7 @@ void MathCursor::selHandle(bool sel) if (sel == selection_) return; //clear(); - Anchor_ = Cursor_; + bv_->resetAnchor(); selection_ = sel; } @@ -606,7 +627,7 @@ void MathCursor::selStart() { dump("selStart 1"); //clear(); - Anchor_ = Cursor_; + bv_->resetAnchor(); selection_ = true; dump("selStart 2"); } @@ -649,8 +670,8 @@ void MathCursor::getScreenPos(int & x, int & y) const int MathCursor::targetX() const { - if (targetx_ != -1) - return targetx_; + if (bv_->x_target() != -1) + return bv_->x_target(); int x = 0, y = 0; getScreenPos(x, y); return x; @@ -689,6 +710,8 @@ MathCursor::pos_type MathCursor::pos() const void MathCursor::adjust(pos_type from, difference_type diff) { +#warning FIXME +#if 0 if (cursor().pos_ > from) cursor().pos_ += diff; if (Anchor_.back().pos_ > from) @@ -696,6 +719,7 @@ void MathCursor::adjust(pos_type from, difference_type diff) // just to be on the safe side // theoretically unecessary normalize(); +#endif } @@ -740,6 +764,8 @@ bool MathCursor::selection() const MathGridInset * MathCursor::enclosingGrid(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(); if (p) { @@ -747,28 +773,38 @@ MathGridInset * MathCursor::enclosingGrid(MathCursor::idx_type & idx) const return p; } } +#endif return 0; } void MathCursor::popToHere(MathInset const * p) { +#warning FIXME +#if 0 while (depth() && Cursor_.back().asMathInset() != p) Cursor_.pop_back(); +#endif } void MathCursor::popToEnclosingGrid() { +#warning FIXME +#if 0 while (depth() && !Cursor_.back().asMathInset()->asGridInset()) Cursor_.pop_back(); +#endif } void MathCursor::popToEnclosingHull() { +#warning FIXME +#if 0 while (depth() && !Cursor_.back().asMathInset()->asHullInset()) Cursor_.pop_back(); +#endif } @@ -779,7 +815,7 @@ void MathCursor::pullArg() if (popLeft()) { plainErase(); array().insert(pos(), a); - Anchor_ = Cursor_; + bv_->resetAnchor(); } else { formula()->mutateToText(); } @@ -788,10 +824,13 @@ void MathCursor::pullArg() void MathCursor::touch() { +#warning +#if 0 CursorBase::const_iterator it = Cursor_.begin(); CursorBase::const_iterator et = Cursor_.end(); for ( ; it != et; ++it) it->cell().touch(); +#endif } @@ -884,13 +923,13 @@ MathArray & MathCursor::array() const void MathCursor::idxNext() { - inset()->idxNext(idx(), pos()); + inset()->idxNext(*bv_); } void MathCursor::idxPrev() { - inset()->idxPrev(idx(), pos()); + inset()->idxPrev(*bv_); } @@ -925,15 +964,13 @@ void MathCursor::getSelection(CursorSlice & i1, CursorSlice & i2) const CursorSlice & MathCursor::cursor() { - BOOST_ASSERT(depth()); - return Cursor_.back(); + return bv_->cursor(); } CursorSlice const & MathCursor::cursor() const { - BOOST_ASSERT(depth()); - return Cursor_.back(); + return bv_->cursor(); } @@ -947,10 +984,10 @@ bool MathCursor::goUpDown(bool up) getScreenPos(xo, yo); // check if we had something else in mind, if not, this is the future goal - if (targetx_ == -1) - targetx_ = xo; + if (bv_->x_target() == -1) + bv_->x_target(xo); else - xo = targetx_; + xo = bv_->x_target(); // try neigbouring script insets if (!selection()) { @@ -981,7 +1018,7 @@ bool MathCursor::goUpDown(bool up) } // try current cell for e.g. text insets - if (inset()->idxUpDown2(idx(), pos(), up, targetx_)) + if (inset()->idxUpDown2(*bv_, up, bv_->x_target())) return true; //xarray().boundingBox(xlow, xhigh, ylow, yhigh); @@ -998,7 +1035,7 @@ bool MathCursor::goUpDown(bool up) while (1) { //lyxerr << "updown: We are in " << inset() << " idx: " << idx() << endl; // ask inset first - if (inset()->idxUpDown(idx(), pos(), up, targetx_)) { + if (inset()->idxUpDown(*bv_, up, bv_->x_target())) { // try to find best position within this inset if (!selection()) bruteFind2(xo, yo); @@ -1028,6 +1065,7 @@ bool MathCursor::goUpDown(bool up) bool MathCursor::bruteFind (int x, int y, int xlow, int xhigh, int ylow, int yhigh) { +#if 0 CursorBase best_cursor; double best_dist = 1e10; @@ -1055,19 +1093,23 @@ bool MathCursor::bruteFind increment(it); } - if (best_dist < 1e10) - Cursor_ = best_cursor; +#warning FIXME + //if (best_dist < 1e10) + // Cursor_ = best_cursor; return best_dist < 1e10; +#endif + return 0; } void MathCursor::bruteFind2(int x, int y) { +#if 0 double best_dist = 1e10; - CursorBase it = Cursor_; + CursorBase it = bv_->fullCursor().cursor_; it.back().pos(0); - CursorBase et = 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) { @@ -1085,6 +1127,7 @@ void MathCursor::bruteFind2(int x, int y) break; increment(it); } +#endif } @@ -1098,13 +1141,13 @@ bool MathCursor::idxLineLast() bool MathCursor::idxLeft() { - return inset()->idxLeft(idx(), pos()); + return inset()->idxLeft(*bv_); } bool MathCursor::idxRight() { - return inset()->idxRight(idx(), pos()); + return inset()->idxRight(*bv_); } @@ -1153,7 +1196,7 @@ bool MathCursor::script(bool up) bool MathCursor::interpret(char c) { //lyxerr << "interpret 2: '" << c << "'" << endl; - targetx_ = -1; // "no target" + bv_->x_target(-1); // "no target" if (inMacroArgMode()) { --pos(); plainErase(); @@ -1288,10 +1331,13 @@ bool MathCursor::interpret(char c) void MathCursor::setSelection(CursorBase const & where, size_type n) { +#warning FIXME +#if 0 selection_ = true; Anchor_ = where; Cursor_ = where; cursor().pos_ += n; +#endif } @@ -1313,7 +1359,8 @@ string MathCursor::info() const ostringstream os; os << "Math editor mode. "; for (int i = 0, n = depth(); i < n; ++i) { - Cursor_[i].asMathInset()->infoize(os); +#warning FIXME + //Cursor_[i].asMathInset()->infoize(os); os << " "; } if (hasPrevAtom()) @@ -1325,7 +1372,7 @@ string MathCursor::info() const unsigned MathCursor::depth() const { - return Cursor_.size(); + return bv_->fullCursor().cursor_.size(); } @@ -1416,8 +1463,10 @@ string MathCursor::grabAndEraseSelection() CursorSlice MathCursor::normalAnchor() const { +#warning FIXME +#if 0 if (Anchor_.size() < depth()) { - Anchor_ = Cursor_; + bv_->resetAnchor(); lyxerr << "unusual Anchor size" << endl; } //lyx::BOOST_ASSERT(Anchor_.size() >= cursor.depth()); @@ -1428,11 +1477,15 @@ CursorSlice MathCursor::normalAnchor() const ++normal.pos_; } return normal; +#else + return cursor(); +#endif } DispatchResult MathCursor::dispatch(FuncRequest const & cmd) { +/* // mouse clicks are somewhat special // check switch (cmd.action) { @@ -1462,9 +1515,10 @@ DispatchResult MathCursor::dispatch(FuncRequest const & cmd) } for (int i = Cursor_.size() - 1; i >= 0; --i) { - CursorSlice & pos = Cursor_[i]; - DispatchResult const res = - pos.asMathInset()->dispatch(cmd, pos.idx_, pos.pos_); + CursorBase tmp = bv->Cursor_; + bv + CursorSlice & pos = tmp.back() + DispatchResult const res = pos.asMathInset()->dispatch(bv, cmd); if (res.dispatched()) { if (res.val() == FINISHED) { if (i + 1 < Cursor_.size()) @@ -1474,17 +1528,21 @@ DispatchResult MathCursor::dispatch(FuncRequest const & cmd) return res; } } +*/ return DispatchResult(false); } MathInset::mode_type MathCursor::currentMode() const { +#warning FIXME +#if 0 for (int i = Cursor_.size() - 1; i >= 0; --i) { MathInset::mode_type res = Cursor_[i].asMathInset()->currentMode(); if (res != MathInset::UNDECIDED_MODE) return res; } +#endif return MathInset::UNDECIDED_MODE; } @@ -1523,12 +1581,12 @@ void MathCursor::handleFont(string const & font) } -void releaseMathCursor(BufferView * bv) +void releaseMathCursor(BufferView & bv) { if (mathcursor) { - InsetFormulaBase * f = mathcursor->formula(); + 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 6bf922cbc0..23c94a7ed7 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -19,7 +19,6 @@ #include - class InsetFormulaBase; class BufferView; class PainterInfo; @@ -53,7 +52,7 @@ public: typedef size_t col_type; /// - explicit MathCursor(InsetFormulaBase *, bool left); + explicit MathCursor(BufferView *, InsetFormulaBase *, bool left); /// ~MathCursor(); /// @@ -280,10 +279,6 @@ private: /// write access to cursor cell index idx_type & idx(); - /// path of positions the cursor had to go if it were leaving each inset - CursorBase Cursor_; - /// path of positions the anchor had to go if it were leaving each inset - mutable CursorBase Anchor_; /// pointer to enclsing LyX inset InsetFormulaBase * formula_; // Selection stuff @@ -295,11 +290,11 @@ private: bool selection_; /// are we entering a macro name? bool macromode_; - /// are we targeting a certain x coordinate, if so, which one? - int targetx_; + /// + BufferView * bv_; }; extern MathCursor * mathcursor; -void releaseMathCursor(BufferView * bv); +void releaseMathCursor(BufferView & bv); #endif diff --git a/src/mathed/math_fracbase.C b/src/mathed/math_fracbase.C index 24bbd29ca0..ecc16c71d7 100644 --- a/src/mathed/math_fracbase.C +++ b/src/mathed/math_fracbase.C @@ -19,25 +19,25 @@ MathFracbaseInset::MathFracbaseInset() {} -bool MathFracbaseInset::idxRight(idx_type &, pos_type &) const +bool MathFracbaseInset::idxRight(BufferView &) const { return false; } -bool MathFracbaseInset::idxLeft(idx_type &, pos_type &) const +bool MathFracbaseInset::idxLeft(BufferView &) const { return false; } -bool MathFracbaseInset::idxUpDown(idx_type & idx, pos_type & pos, bool up, - int targetx) const +bool MathFracbaseInset::idxUpDown(BufferView & bv, bool up, int targetx) const { + CursorSlice & cur = cursorTip(bv); MathInset::idx_type target = !up; // up ? 0 : 1, since upper cell has idx 0 - if (idx == target) + if (cur.idx() == target) return false; - idx = target; - pos = cell(idx).x2pos(targetx); + cur.idx() = target; + cur.pos() = cell(target).x2pos(targetx); return true; } diff --git a/src/mathed/math_fracbase.h b/src/mathed/math_fracbase.h index 57645ba5e5..3e4549b9f1 100644 --- a/src/mathed/math_fracbase.h +++ b/src/mathed/math_fracbase.h @@ -20,11 +20,11 @@ public: /// MathFracbaseInset(); /// - bool idxUpDown(idx_type & idx, pos_type & pos, bool up, int targetx) const; + bool idxUpDown(BufferView &, bool up, int targetx) const; /// - bool idxLeft(idx_type & idx, pos_type & pos) const; + bool idxLeft(BufferView &) const; /// - bool idxRight(idx_type & idx, pos_type & pos) const; + bool idxRight(BufferView &) const; }; #endif diff --git a/src/mathed/math_gridinset.C b/src/mathed/math_gridinset.C index d16f82776c..77e3badbc6 100644 --- a/src/mathed/math_gridinset.C +++ b/src/mathed/math_gridinset.C @@ -751,115 +751,119 @@ int MathGridInset::cellYOffset(idx_type idx) const } -bool MathGridInset::idxUpDown(idx_type & idx, pos_type & pos, bool up, - int targetx) const +bool MathGridInset::idxUpDown(BufferView & bv, bool up, int targetx) const { + CursorSlice & cur = cursorTip(bv); if (up) { - if (idx < ncols()) + if (cur.idx() < ncols()) return false; - idx -= ncols(); - pos = cell(idx).x2pos(targetx - cell(idx).xo()); - return true; + cur.idx() -= ncols(); } else { - if (idx >= ncols() * (nrows() - 1)) + if (cur.idx() >= ncols() * (nrows() - 1)) return false; - idx += ncols(); - pos = cell(idx).x2pos(targetx - cell(idx).xo()); - return true; + cur.idx() += ncols(); } + cur.pos() = cur.cell().x2pos(targetx - cur.cell().xo()); + return true; } -bool MathGridInset::idxLeft(idx_type & idx, pos_type & pos) const +bool MathGridInset::idxLeft(BufferView & bv) const { // leave matrix if on the left hand edge - if (col(idx) == 0) + CursorSlice & cur = cursorTip(bv); + if (cur.col() == 0) return false; - --idx; - pos = cell(idx).size(); + --cur.idx(); + cur.pos() = cur.lastpos(); return true; } -bool MathGridInset::idxRight(idx_type & idx, pos_type & pos) const +bool MathGridInset::idxRight(BufferView & bv) const { // leave matrix if on the right hand edge - if (col(idx) + 1 == ncols()) + CursorSlice & cur = cursorTip(bv); + if (cur.col() + 1 == ncols()) return false; - ++idx; - pos = 0; + ++cur.idx(); + cur.pos() = 0; return true; } -bool MathGridInset::idxFirst(idx_type & idx, pos_type & pos) const +bool MathGridInset::idxFirst(BufferView & bv) const { + CursorSlice & cur = cursorTip(bv); switch (v_align_) { case 't': - idx = 0; + cur.idx() = 0; break; case 'b': - idx = (nrows() - 1) * ncols(); + cur.idx() = (nrows() - 1) * ncols(); break; default: - idx = ((nrows() - 1) / 2) * ncols(); + cur.idx() = ((nrows() - 1) / 2) * ncols(); } - pos = 0; + cur.pos() = 0; return true; } -bool MathGridInset::idxLast(idx_type & idx, pos_type & pos) const +bool MathGridInset::idxLast(BufferView & bv) const { + CursorSlice & cur = cursorTip(bv); switch (v_align_) { case 't': - idx = ncols() - 1; + cur.idx() = ncols() - 1; break; case 'b': - idx = nargs() - 1; + cur.idx() = nargs() - 1; break; default: - idx = ((nrows() - 1) / 2 + 1) * ncols() - 1; + cur.idx() = ((nrows() - 1) / 2 + 1) * ncols() - 1; } - pos = cell(idx).size(); + cur.pos() = cur.lastpos(); return true; } -bool MathGridInset::idxHome(idx_type & idx, pos_type & pos) const +bool MathGridInset::idxHome(BufferView & bv) const { - if (pos > 0) { - pos = 0; + CursorSlice & cur = cursorTip(bv); + if (cur.pos() > 0) { + cur.pos() = 0; return true; } - if (col(idx) > 0) { - idx -= idx % ncols(); - pos = 0; + if (cur.col() > 0) { + cur.idx() -= cur.idx() % ncols(); + cur.pos() = 0; return true; } - if (idx > 0) { - idx = 0; - pos = 0; + if (cur.idx() > 0) { + cur.idx() = 0; + cur.pos() = 0; return true; } return false; } -bool MathGridInset::idxEnd(idx_type & idx, pos_type & pos) const +bool MathGridInset::idxEnd(BufferView & bv) const { - if (pos < cell(idx).size()) { - pos = cell(idx).size(); + CursorSlice & cur = cursorTip(bv); + if (cur.pos() < cur.lastpos()) { + cur.pos() = cur.lastpos(); return true; } - if (col(idx) < ncols() - 1) { - idx = idx - idx % ncols() + ncols() - 1; - pos = cell(idx).size(); + if (cur.col() < ncols() - 1) { + cur.idx() = cur.idx() - cur.idx() % ncols() + ncols() - 1; + cur.pos() = cur.lastpos(); return true; } - if (idx < nargs() - 1) { - idx = nargs() - 1; - pos = cell(idx).size(); + if (cur.idx() < nargs() - 1) { + cur.idx() = nargs() - 1; + cur.pos() = cur.lastpos(); return true; } return false; @@ -1029,22 +1033,24 @@ int MathGridInset::border() const } -void MathGridInset::splitCell(idx_type & idx, pos_type & pos) +void MathGridInset::splitCell(BufferView & bv) { - if (idx + 1 == nargs()) + CursorSlice & cur = cursorTip(bv); + if (cur.idx() + 1 == nargs()) return; - MathArray ar = cell(idx); - ar.erase(0, pos); - cell(idx).erase(pos, cell(idx).size()); - ++idx; - pos = 0; - cell(idx).insert(0, ar); + MathArray ar = cur.cell(); + ar.erase(0, cur.pos()); + cur.cell().erase(cur.pos(), cur.lastpos()); + ++cur.idx(); + cur.pos() = 0; + cur.cell().insert(0, ar); } -DispatchResult MathGridInset::priv_dispatch(FuncRequest const & cmd, - idx_type & idx, pos_type & pos) +DispatchResult +MathGridInset::priv_dispatch(BufferView & bv, FuncRequest const & cmd) { + CursorSlice & cur = cursorTip(bv); switch (cmd.action) { case LFUN_MOUSE_RELEASE: @@ -1055,7 +1061,7 @@ DispatchResult MathGridInset::priv_dispatch(FuncRequest const & cmd, return DispatchResult(false); case LFUN_INSET_DIALOG_UPDATE: - GridInsetMailer(*this).updateDialog(cmd.view()); + GridInsetMailer(*this).updateDialog(&bv); return DispatchResult(false); // insert file functions @@ -1067,33 +1073,33 @@ DispatchResult MathGridInset::priv_dispatch(FuncRequest const & cmd, // return; //} if (nrows() > 1) - delRow(row(idx)); - if (idx >= nargs()) - idx = nargs() - 1; - if (pos > cell(idx).size()) - pos = cell(idx).size(); + delRow(cur.row()); + if (cur.idx() >= nargs()) + cur.idx() = nargs() - 1; + if (cur.pos() > cur.lastpos()) + cur.pos() = cur.lastpos(); return DispatchResult(true, FINISHED); case LFUN_CELL_SPLIT: //recordUndo(bv, Undo::ATOMIC); - splitCell(idx, pos); + splitCell(bv); return DispatchResult(true, FINISHED); case LFUN_BREAKLINE: { //recordUndo(bv, Undo::INSERT); - row_type const r = row(idx); + row_type const r = cur.row(); addRow(r); // split line - for (col_type c = col(idx) + 1; c < ncols(); ++c) + for (col_type c = col(cur.idx()) + 1; c < ncols(); ++c) std::swap(cell(index(r, c)), cell(index(r + 1, c))); // split cell - splitCell(idx, pos); - std::swap(cell(idx), cell(idx + ncols() - 1)); - if (idx > 0) - --idx; - pos = cell(idx).size(); + splitCell(bv); + std::swap(cell(cur.idx()), cell(cur.idx() + ncols() - 1)); + if (cur.idx() > 0) + --cur.idx(); + cur.idx() = cur.lastpos(); //mathcursor->normalize(); return DispatchResult(true, FINISHED); @@ -1111,45 +1117,45 @@ DispatchResult MathGridInset::priv_dispatch(FuncRequest const & cmd, else if (s == "valign-bottom") valign('b'); else if (s == "align-left") - halign('l', col(idx)); + halign('l', col(cur.idx())); else if (s == "align-right") - halign('r', col(idx)); + halign('r', col(cur.idx())); else if (s == "align-center") - halign('c', col(idx)); + halign('c', col(cur.idx())); else if (s == "append-row") for (int i = 0, n = extractInt(is); i < n; ++i) - addRow(row(idx)); + addRow(cur.row()); else if (s == "delete-row") for (int i = 0, n = extractInt(is); i < n; ++i) { - delRow(row(idx)); - if (idx > nargs()) - idx -= ncols(); + delRow(cur.row()); + if (cur.idx() > nargs()) + cur.idx() -= ncols(); } else if (s == "copy-row") for (int i = 0, n = extractInt(is); i < n; ++i) - copyRow(row(idx)); + copyRow(cur.row()); else if (s == "swap-row") - swapRow(row(idx)); + swapRow(cur.row()); else if (s == "append-column") for (int i = 0, n = extractInt(is); i < n; ++i) { - row_type r = row(idx); - col_type c = col(idx); + row_type r = cur.row(); + col_type c = col(cur.idx()); addCol(c); - idx = index(r, c); + cur.idx() = index(r, c); } else if (s == "delete-column") for (int i = 0, n = extractInt(is); i < n; ++i) { - row_type r = row(idx); - col_type c = col(idx); - delCol(col(idx)); - idx = index(r, c); - if (idx > nargs()) - idx -= ncols(); + row_type r = cur.row(); + col_type c = col(cur.idx()); + delCol(col(cur.idx())); + cur.idx() = index(r, c); + if (cur.idx() > nargs()) + cur.idx() -= ncols(); } else if (s == "copy-column") - copyCol(col(idx)); + copyCol(col(cur.idx())); else if (s == "swap-column") - swapCol(col(idx)); + swapCol(col(cur.idx())); else return DispatchResult(false); lyxerr << "returning DispatchResult(true, FINISHED)" << endl; @@ -1162,19 +1168,21 @@ DispatchResult MathGridInset::priv_dispatch(FuncRequest const & cmd, mathed_parse_normal(grid, cmd.argument); if (grid.nargs() == 1) { // single cell/part of cell - cell(idx).insert(pos, grid.cell(0)); - pos += grid.cell(0).size(); + cur.cell().insert(cur.pos(), grid.cell(0)); + cur.pos() += grid.cell(0).size(); } else { // multiple cells - col_type const numcols = min(grid.ncols(), ncols() - col(idx)); - row_type const numrows = min(grid.nrows(), nrows() - row(idx)); + col_type const numcols = min(grid.ncols(), ncols() - +col(cur.idx())); + row_type const numrows = min(grid.nrows(), nrows() - +cur.row()); for (row_type r = 0; r < numrows; ++r) { for (col_type c = 0; c < numcols; ++c) { - idx_type i = index(r + row(idx), c + col(idx)); + idx_type i = index(r + cur.row(), c + col(cur.idx())); cell(i).insert(0, grid.cell(grid.index(r, c))); } // append the left over horizontal cells to the last column - idx_type i = index(r + row(idx), ncols() - 1); + idx_type i = index(r + cur.row(), ncols() - 1); for (MathInset::col_type c = numcols; c < grid.ncols(); ++c) cell(i).append(grid.cell(grid.index(r, c))); } @@ -1188,6 +1196,6 @@ DispatchResult MathGridInset::priv_dispatch(FuncRequest const & cmd, } default: - return MathNestInset::priv_dispatch(cmd, idx, pos); + return MathNestInset::priv_dispatch(bv, cmd); } } diff --git a/src/mathed/math_gridinset.h b/src/mathed/math_gridinset.h index c60ed8108f..37ff4a289b 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(idx_type & idx, pos_type & pos, bool up, int targetx) const; + bool idxUpDown(BufferView &, bool up, int targetx) const; /// - bool idxLeft(idx_type & idx, pos_type & pos) const; + bool idxLeft(BufferView &) const; /// - bool idxRight(idx_type & idx, pos_type & pos) const; + bool idxRight(BufferView &) const; /// - bool idxFirst(idx_type & idx, pos_type & pos) const; + bool idxFirst(BufferView &) const; /// - bool idxLast(idx_type & idx, pos_type & pos) const; + bool idxLast(BufferView &) const; /// - bool idxHome(idx_type & idx, pos_type & pos) const; + bool idxHome(BufferView &) const; /// - bool idxEnd(idx_type & idx, pos_type & pos) const; + bool idxEnd(BufferView &) const; /// bool idxDelete(idx_type & idx); /// pulls cell after pressing erase @@ -218,7 +218,7 @@ protected: /// virtual DispatchResult - priv_dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos); + priv_dispatch(BufferView & bv, FuncRequest const & cmd); /// returns x offset of cell compared to inset int cellXOffset(idx_type idx) const; @@ -231,7 +231,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(idx_type &, pos_type & pos); + void splitCell(BufferView & pos); public: /// row info diff --git a/src/mathed/math_hullinset.C b/src/mathed/math_hullinset.C index caf7b23936..c1b6771167 100644 --- a/src/mathed/math_hullinset.C +++ b/src/mathed/math_hullinset.C @@ -135,18 +135,20 @@ MathInset::mode_type MathHullInset::currentMode() const } -bool MathHullInset::idxFirst(idx_type & idx, pos_type & pos) const +bool MathHullInset::idxFirst(BufferView & bv) const { - idx = 0; - pos = 0; + CursorSlice & cur = cursorTip(bv); + cur.idx() = 0; + cur.pos() = 0; return true; } -bool MathHullInset::idxLast(idx_type & idx, pos_type & pos) const +bool MathHullInset::idxLast(BufferView & bv) const { - idx = nargs() - 1; - pos = cell(idx).size(); + CursorSlice & cur = cursorTip(bv); + cur.idx() = nargs() - 1; + cur.pos() = cur.lastpos(); return true; } @@ -694,9 +696,9 @@ void MathHullInset::check() const } -void MathHullInset::doExtern - (FuncRequest const & func, idx_type & idx, pos_type & pos) +void MathHullInset::doExtern(FuncRequest const & func, BufferView & bv) { + CursorSlice & cur = cursorTip(bv); string lang; string extra; istringstream iss(func.argument.c_str()); @@ -719,72 +721,75 @@ void MathHullInset::doExtern eq.push_back(MathAtom(new MathCharInset('='))); // go to first item in line - idx -= idx % ncols(); - pos = 0; + cur.idx() -= cur.idx() % ncols(); + cur.pos() = 0; if (getType() == "simple") { - size_type pos = cell(idx).find_last(eq); + size_type pos = cur.cell().find_last(eq); MathArray ar; if (mathcursor && mathcursor->selection()) { asArray(mathcursor->grabAndEraseSelection(), ar); - } else if (pos == cell(idx).size()) { - ar = cell(idx); + } else if (pos == cur.cell().size()) { + ar = cur.cell(); lyxerr << "use whole cell: " << ar << endl; } else { - ar = MathArray(cell(idx).begin() + pos + 1, cell(idx).end()); + ar = MathArray(cur.cell().begin() + pos + 1, cur.cell().end()); lyxerr << "use partial cell form pos: " << pos << endl; } - cell(idx).append(eq); - cell(idx).append(pipeThroughExtern(lang, extra, ar)); - pos = cell(idx).size(); + cur.cell().append(eq); + cur.cell().append(pipeThroughExtern(lang, extra, ar)); + cur.pos() = cur.lastpos(); return; } if (getType() == "equation") { lyxerr << "use equation inset" << endl; mutate("eqnarray"); - MathArray & ar = cell(idx); + MathArray & ar = cur.cell(); lyxerr << "use cell: " << ar << endl; - cell(idx + 1) = eq; - cell(idx + 2) = pipeThroughExtern(lang, extra, ar); + ++cur.idx(); + cur.cell() = eq; + ++cur.idx(); + cur.cell() = pipeThroughExtern(lang, extra, ar); // move to end of line - idx += 2; - pos = cell(idx).size(); + cur.pos() = cur.lastpos(); return; } { lyxerr << "use eqnarray" << endl; - idx -= idx % ncols(); - idx += 2; - pos = 0; - MathArray ar = cell(idx); + cur.idx() += 2 - cur.idx() % ncols(); + cur.pos() = 0; + MathArray ar = cur.cell(); lyxerr << "use cell: " << ar << endl; #ifdef WITH_WARNINGS #warning temporarily disabled #endif - addRow(row(idx)); - cell(idx + 2) = eq; - cell(idx + 3) = pipeThroughExtern(lang, extra, ar); - idx += 3; - pos = cell(idx).size(); + addRow(cur.row()); + ++cur.idx(); + ++cur.idx(); + cur.cell() = eq; + ++cur.idx(); + cur.cell() = pipeThroughExtern(lang, extra, ar); + cur.pos() = cur.lastpos(); } } -DispatchResult MathHullInset::priv_dispatch - (FuncRequest const & cmd, idx_type & idx, pos_type & pos) +DispatchResult +MathHullInset::priv_dispatch(BufferView & bv, FuncRequest const & cmd) { + CursorSlice & cur = cursorTip(bv); switch (cmd.action) { case LFUN_BREAKLINE: if (type_ == "simple" || type_ == "equation") { mutate("eqnarray"); - idx = 1; - pos = 0; + cur.idx() = 1; + cur.pos() = 0; return DispatchResult(true, FINISHED); } - return MathGridInset::priv_dispatch(cmd, idx, pos); + return MathGridInset::priv_dispatch(bv, cmd); case LFUN_MATH_NUMBER: //lyxerr << "toggling all numbers" << endl; @@ -802,7 +807,7 @@ DispatchResult MathHullInset::priv_dispatch case LFUN_MATH_NONUMBER: if (display()) { - row_type r = (type_ == "multline") ? nrows() - 1 : row(idx); + row_type r = (type_ == "multline") ? nrows() - 1 : cur.row(); //recordUndo(bv, Undo::INSERT); bool old = numbered(r); //bv->owner()->message(old ? _("No number") : _("Number")); @@ -811,7 +816,7 @@ DispatchResult MathHullInset::priv_dispatch return DispatchResult(true, true); case LFUN_INSERT_LABEL: { - row_type r = (type_ == "multline") ? nrows() - 1 : row(idx); + row_type r = (type_ == "multline") ? nrows() - 1 : cur.row(); string old_label = label(r); string new_label = cmd.argument; @@ -836,31 +841,31 @@ DispatchResult MathHullInset::priv_dispatch } case LFUN_MATH_EXTERN: - doExtern(cmd, idx, pos); + doExtern(cmd, bv); return DispatchResult(true, FINISHED); case LFUN_MATH_MUTATE: { lyxerr << "Hull: MUTATE: " << cmd.argument << endl; - row_type r = row(idx); - col_type c = col(idx); + row_type r = cur.row(); + col_type c = cur.col(); mutate(cmd.argument); - idx = r * ncols() + c; - if (idx >= nargs()) - idx = nargs() - 1; - if (pos > cell(idx).size()) - pos = cell(idx).size(); + cur.idx() = r * ncols() + c; + if (cur.idx() >= nargs()) + cur.idx() = nargs() - 1; + if (cur.pos() > cur.lastpos()) + cur.pos() = cur.lastpos(); return DispatchResult(true, FINISHED); } case LFUN_MATH_DISPLAY: { mutate(type_ == "simple" ? "equation" : "simple"); - idx = 0; - pos = cell(idx).size(); + cur.idx() = 0; + cur.pos() = cur.lastpos(); return DispatchResult(true, FINISHED); } default: - return MathGridInset::priv_dispatch(cmd, idx, pos); + return MathGridInset::priv_dispatch(bv, cmd); } } diff --git a/src/mathed/math_hullinset.h b/src/mathed/math_hullinset.h index e568af0db6..2c19c15b74 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(idx_type &, pos_type &) const; + bool idxFirst(BufferView &) const; /// - bool idxLast(idx_type &, pos_type &) const; + bool idxLast(BufferView &) const; /// std::string fileInsetLabel() const; @@ -100,7 +100,7 @@ protected: /// virtual DispatchResult - priv_dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos); + priv_dispatch(BufferView & bv, FuncRequest const & cmd); /// std::string eolString(row_type row, bool fragile) const; @@ -116,7 +116,7 @@ private: /// std::string nicelabel(row_type row) const; /// - void doExtern(FuncRequest const & func, idx_type & idx, pos_type & pos); + void doExtern(FuncRequest const & func, BufferView &); /// void glueall(); /// diff --git a/src/mathed/math_inset.C b/src/mathed/math_inset.C index ae0226a884..fd56951bbc 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(idx_type &, pos_type &) const +bool MathInset::idxNext(BufferView &) const { return false; } -bool MathInset::idxRight(idx_type &, pos_type &) const +bool MathInset::idxRight(BufferView &) const { return false; } -bool MathInset::idxPrev(idx_type &, pos_type &) const +bool MathInset::idxPrev(BufferView &) const { return false; } -bool MathInset::idxLeft(idx_type &, pos_type &) const +bool MathInset::idxLeft(BufferView &) const { return false; } -bool MathInset::idxUpDown(idx_type &, pos_type &, bool, int) const +bool MathInset::idxUpDown(BufferView &, bool, int) const { return false; } -bool MathInset::idxUpDown2(idx_type &, pos_type &, bool, int) const +bool MathInset::idxUpDown2(BufferView &, bool, int) const { return false; } -bool MathInset::idxFirst(idx_type &, pos_type &) const +bool MathInset::idxFirst(BufferView &) const { return false; } -bool MathInset::idxLast(idx_type &, pos_type &) const +bool MathInset::idxLast(BufferView &) const { return false; } -bool MathInset::idxHome(idx_type &, pos_type &) const +bool MathInset::idxHome(BufferView &) const { return false; } -bool MathInset::idxEnd(idx_type &, pos_type &) const +bool MathInset::idxEnd(BufferView &) const { return false; } diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index f3018235aa..2503ca5228 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -13,6 +13,7 @@ #ifndef MATH_INSET_H #define MATH_INSET_H +#include "cursor_slice.h" #include "insets/insetbase.h" #include @@ -94,30 +95,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(idx_type & idx, pos_type & pos, bool up, - int targetx) const; + virtual bool idxUpDown(BufferView & bv, bool up, int targetx) const; /// Where should we go when we press the up or down cursor key? - virtual bool idxUpDown2(idx_type & idx, pos_type & pos, bool up, - int targetx) const; + virtual bool idxUpDown2(BufferView & bv, bool up, int targetx) const; /// The left key - virtual bool idxLeft(idx_type & idx, pos_type & pos) const; + virtual bool idxLeft(BufferView & bv) const; /// The right key - virtual bool idxRight(idx_type & idx, pos_type & pos) const; + virtual bool idxRight(BufferView & bv) const; /// Move one physical cell up - virtual bool idxNext(idx_type & idx, pos_type & pos) const; + virtual bool idxNext(BufferView & bv) const; /// Move one physical cell down - virtual bool idxPrev(idx_type & idx, pos_type & pos) const; + virtual bool idxPrev(BufferView & bv) const; /// Target pos when we enter the inset from the left by pressing "Right" - virtual bool idxFirst(idx_type & idx, pos_type & pos) const; + virtual bool idxFirst(BufferView & bv) const; /// Target pos when we enter the inset from the right by pressing "Left" - virtual bool idxLast(idx_type & idx, pos_type & pos) const; + virtual bool idxLast(BufferView & bv) const; /// Where should we go if we press home? - virtual bool idxHome(idx_type & idx, pos_type & pos) const; + virtual bool idxHome(BufferView & bv) const; /// Where should we go if we press end? - virtual bool idxEnd(idx_type & idx, pos_type & pos) const; + virtual bool idxEnd(BufferView & bv) 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 aaad86b832..30e32bc52a 100644 --- a/src/mathed/math_macro.C +++ b/src/mathed/math_macro.C @@ -155,30 +155,28 @@ void MathMacro::dump() const } -bool MathMacro::idxUpDown(idx_type & idx, pos_type &, bool up, int x) const +bool MathMacro::idxUpDown(BufferView & bv, bool up, int x) const { - pos_type pos; + CursorSlice & cur = cursorTip(bv); if (up) { - if (!MathNestInset::idxLeft(idx, pos)) + if (!MathNestInset::idxLeft(bv)) return false; - pos = cell(idx).x2pos(x); - return true; } else { - if (!MathNestInset::idxRight(idx, pos)) + if (!MathNestInset::idxRight(bv)) return false; - pos = cell(idx).x2pos(x); - return true; } + cur.pos() = cur.cell().x2pos(x); + return true; } -bool MathMacro::idxLeft(idx_type &, pos_type &) const +bool MathMacro::idxLeft(BufferView &) const { return false; } -bool MathMacro::idxRight(idx_type &, pos_type &) const +bool MathMacro::idxRight(BufferView &) const { return false; } diff --git a/src/mathed/math_macro.h b/src/mathed/math_macro.h index 8912501b5e..6e95bc6a4f 100644 --- a/src/mathed/math_macro.h +++ b/src/mathed/math_macro.h @@ -38,11 +38,11 @@ public: void dump() const; /// - bool idxUpDown(idx_type & idx, pos_type & pos, bool up, int targetx) const; + bool idxUpDown(BufferView &, bool up, int targetx) const; /// - bool idxLeft(idx_type & idx, pos_type & pos) const; + bool idxLeft(BufferView &) const; /// - bool idxRight(idx_type & idx, pos_type & pos) const; + bool idxRight(BufferView &) const; /// void validate(LaTeXFeatures &) const; diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index a1a35f9652..1caaee458e 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -71,73 +71,78 @@ void MathNestInset::metrics(MetricsInfo const & mi) const } -bool MathNestInset::idxNext(idx_type & idx, pos_type & pos) const +bool MathNestInset::idxNext(BufferView & bv) const { - if (idx + 1 >= nargs()) + CursorSlice & cur = cursorTip(bv); + if (cur.idx() + 1 >= nargs()) return false; - ++idx; - pos = 0; + ++cur.idx(); + cur.pos() = 0; return true; } -bool MathNestInset::idxRight(idx_type & idx, pos_type & pos) const +bool MathNestInset::idxRight(BufferView & bv) const { - return idxNext(idx, pos); + return idxNext(bv); } -bool MathNestInset::idxPrev(idx_type & idx, pos_type & pos) const +bool MathNestInset::idxPrev(BufferView & bv) const { - if (idx == 0) + CursorSlice & cur = cursorTip(bv); + if (cur.idx() == 0) return false; - --idx; - pos = cell(idx).size(); + --cur.idx(); + cur.pos() = cur.lastpos(); return true; } -bool MathNestInset::idxLeft(idx_type & idx, pos_type & pos) const +bool MathNestInset::idxLeft(BufferView & bv) const { - return idxPrev(idx, pos); + return idxPrev(bv); } -bool MathNestInset::idxFirst(idx_type & idx, pos_type & pos) const +bool MathNestInset::idxFirst(BufferView & bv) const { + CursorSlice & cur = cursorTip(bv); if (nargs() == 0) return false; - idx = 0; - pos = 0; + cur.idx() = 0; + cur.pos() = 0; return true; } -bool MathNestInset::idxLast(idx_type & idx, pos_type & pos) const +bool MathNestInset::idxLast(BufferView & bv) const { + CursorSlice & cur = cursorTip(bv); if (nargs() == 0) return false; - idx = nargs() - 1; - pos = cell(idx).size(); + cur.idx() = nargs() - 1; + cur.pos() = cur.lastpos(); return true; } -bool MathNestInset::idxHome(idx_type & /* idx */, pos_type & pos) const +bool MathNestInset::idxHome(BufferView & bv) const { - if (pos == 0) + CursorSlice & cur = cursorTip(bv); + if (cur.pos() == 0) return false; - pos = 0; + cur.pos() = 0; return true; } -bool MathNestInset::idxEnd(idx_type & idx, pos_type & pos) const +bool MathNestInset::idxEnd(BufferView & bv) const { - pos_type n = cell(idx).size(); - if (pos == n) + CursorSlice & cur = cursorTip(bv); + if (cur.lastpos() == cur.lastpos()) return false; - pos = n; + cur.pos() = cur.lastpos(); return true; } @@ -276,33 +281,29 @@ void MathNestInset::notifyCursorLeaves(idx_type idx) DispatchResult -MathNestInset::priv_dispatch(FuncRequest const & cmd, - idx_type & idx, pos_type & pos) +MathNestInset::priv_dispatch(BufferView & bv, FuncRequest const & cmd) { - BufferView * bv = cmd.view(); - + CursorSlice & cur = cursorTip(bv); switch (cmd.action) { case LFUN_PASTE: { MathArray ar; mathed_parse_cell(ar, cmd.argument); - cell(idx).insert(pos, ar); - pos += ar.size(); + cur.cell().insert(cur.pos(), ar); + cur.pos() += ar.size(); return DispatchResult(true, true); } case LFUN_PASTESELECTION: - return - dispatch( - FuncRequest(bv, LFUN_PASTE, bv->getClipboard()), idx, pos); + return dispatch(bv, FuncRequest(LFUN_PASTE, bv.getClipboard())); case LFUN_MOUSE_PRESS: if (cmd.button() == mouse_button::button2) - return priv_dispatch(FuncRequest(bv, LFUN_PASTESELECTION), idx, pos); + return priv_dispatch(bv, FuncRequest(LFUN_PASTESELECTION)); return DispatchResult(false); default: - return MathInset::priv_dispatch(cmd, idx, pos); + return MathInset::priv_dispatch(bv, cmd); } } diff --git a/src/mathed/math_nestinset.h b/src/mathed/math_nestinset.h index 16bf5e7fe3..2227ac2ae4 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(idx_type & idx, pos_type & pos) const; + bool idxLeft(BufferView &) const; /// order of movement through the cells when pressing the right key - bool idxRight(idx_type & idx, pos_type & pos) const; + bool idxRight(BufferView &) const; /// move one physical cell up - bool idxNext(idx_type & idx, pos_type & pos) const; + bool idxNext(BufferView &) const; /// move one physical cell down - bool idxPrev(idx_type & idx, pos_type & pos) const; + bool idxPrev(BufferView &) const; /// target pos when we enter the inset from the left by pressing "Right" - bool idxFirst(idx_type & idx, pos_type & pos) const; + bool idxFirst(BufferView &) const; /// target pos when we enter the inset from the right by pressing "Left" - bool idxLast(idx_type & idx, pos_type & pos) const; + bool idxLast(BufferView &) const; /// where should we go if we press home? - bool idxHome(idx_type & idx, pos_type & pos) const; + bool idxHome(BufferView &) const; /// where should we go if we press end? - bool idxEnd(idx_type & idx, pos_type & pos) const; + bool idxEnd(BufferView &) const; /// number of cells currently governed by us idx_type nargs() const; @@ -101,7 +101,7 @@ protected: /// virtual DispatchResult - priv_dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos); + priv_dispatch(BufferView & bv, FuncRequest const & cmd); /// we store the cells in a vector typedef std::vector cells_type; diff --git a/src/mathed/math_oversetinset.C b/src/mathed/math_oversetinset.C index c38fc7fcf5..4053c543b3 100644 --- a/src/mathed/math_oversetinset.C +++ b/src/mathed/math_oversetinset.C @@ -47,18 +47,20 @@ void MathOversetInset::draw(PainterInfo & pi, int x, int y) const } -bool MathOversetInset::idxFirst(idx_type & i, pos_type & pos) const +bool MathOversetInset::idxFirst(BufferView & bv) const { - i = 1; - pos = 0; + CursorSlice & cur = cursorTip(bv); + cur.idx() = 1; + cur.pos() = 0; return true; } -bool MathOversetInset::idxLast(idx_type & i, pos_type & pos) const +bool MathOversetInset::idxLast(BufferView & bv) const { - i = 1; - pos = cell(i).size(); + 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 a0dea822b6..72aa05e4fd 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(idx_type & idx, pos_type & pos) const; + bool idxFirst(BufferView &) const; /// - bool idxLast(idx_type & idx, pos_type & pos) const; + bool idxLast(BufferView &) const; /// void write(WriteStream & os) const; diff --git a/src/mathed/math_rootinset.C b/src/mathed/math_rootinset.C index 98c214552a..6d9513a5bb 100644 --- a/src/mathed/math_rootinset.C +++ b/src/mathed/math_rootinset.C @@ -78,13 +78,14 @@ void MathRootInset::normalize(NormalStream & os) const } -bool MathRootInset::idxUpDown(idx_type & idx, pos_type & pos, bool up, int) const +bool MathRootInset::idxUpDown(BufferView & bv, bool up, int) const { + CursorSlice & cur = cursorTip(bv); bool target = !up; // up ? 0 : 1; - if (idx == target) + if (cur.idx() == target) return false; - idx = target; - pos = target ? 0 : cell(0).size(); + cur.idx() = target; + cur.pos() = up ? cur.lastpos() : 0; return true; } diff --git a/src/mathed/math_rootinset.h b/src/mathed/math_rootinset.h index 366c77d43d..e90ae842b0 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(idx_type & idx, pos_type & pos, bool up, int targetx) const; + bool idxUpDown(BufferView &, 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 1118070fe7..5b6c4a2e7f 100644 --- a/src/mathed/math_scriptinset.C +++ b/src/mathed/math_scriptinset.C @@ -72,18 +72,20 @@ MathScriptInset * MathScriptInset::asScriptInset() } -bool MathScriptInset::idxFirst(idx_type & idx, pos_type & pos) const +bool MathScriptInset::idxFirst(BufferView & bv) const { - idx = 2; - pos = 0; + CursorSlice & cur = cursorTip(bv); + cur.idx() = 2; + cur.pos() = 0; return true; } -bool MathScriptInset::idxLast(idx_type & idx, pos_type & pos) const +bool MathScriptInset::idxLast(BufferView & bv) const { - idx = 2; - pos = nuc().size(); + CursorSlice & cur = cursorTip(bv); + cur.idx() = 2; + cur.pos() = nuc().size(); return true; } @@ -313,36 +315,36 @@ bool MathScriptInset::hasDown() const } -bool MathScriptInset::idxRight(idx_type &, pos_type &) const +bool MathScriptInset::idxRight(BufferView &) const { return false; } -bool MathScriptInset::idxLeft(idx_type &, pos_type &) const +bool MathScriptInset::idxLeft(BufferView &) const { return false; } -bool MathScriptInset::idxUpDown(idx_type & idx, pos_type & pos, bool up, - int) const +bool MathScriptInset::idxUpDown(BufferView & bv, bool up, int) const { - if (idx == 1) { + CursorSlice & cur = cursorTip(bv); + if (cur.idx() == 1) { // if we are 'up' we can't go further up if (up) return false; // otherwise go to last base position - idx = 2; - pos = cell(2).size(); + cur.idx() = 2; + cur.pos() = cur.lastpos(); } - else if (idx == 0) { + else if (cur.idx() == 0) { // if we are 'down' we can't go further down if (!up) return false; - idx = 2; - pos = cell(2).size(); + cur.idx() = 2; + cur.pos() = cur.lastpos(); } else { @@ -352,9 +354,9 @@ bool MathScriptInset::idxUpDown(idx_type & idx, pos_type & pos, bool up, return false; // go up/down only if in the last position // or in the first position of something with displayed limits - if (pos == cell(2).size() || (pos == 0 && hasLimits())) { - idx = up; - pos = 0; + if (cur.pos() == cur.lastpos() || (cur.pos() == 0 && hasLimits())) { + cur.idx() = up; + cur.pos() = 0; return true; } return false; @@ -513,8 +515,7 @@ void MathScriptInset::notifyCursorLeaves(idx_type idx) DispatchResult -MathScriptInset::priv_dispatch(FuncRequest const & cmd, - idx_type & idx, pos_type & pos) +MathScriptInset::priv_dispatch(BufferView & bv, FuncRequest const & cmd) { if (cmd.action == LFUN_MATH_LIMITS) { if (!cmd.argument.empty()) { @@ -531,5 +532,5 @@ MathScriptInset::priv_dispatch(FuncRequest const & cmd, return DispatchResult(true, true); } - return MathNestInset::priv_dispatch(cmd, idx, pos); + return MathNestInset::priv_dispatch(bv, cmd); } diff --git a/src/mathed/math_scriptinset.h b/src/mathed/math_scriptinset.h index 5253d0f660..32d0b5479c 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(idx_type &, pos_type &) const; + bool idxLeft(BufferView &) const; /// move cursor right - bool idxRight(idx_type &, pos_type &) const; + bool idxRight(BufferView &) const; /// move cursor up or down - bool idxUpDown(idx_type & idx, pos_type & pos, bool up, int targetx) const; + bool idxUpDown(BufferView &, bool up, int targetx) const; /// Target pos when we enter the inset from the left by pressing "Right" - bool idxFirst(idx_type & idx, pos_type & pos) const; + bool idxFirst(BufferView &) const; /// Target pos when we enter the inset from the right by pressing "Left" - bool idxLast(idx_type & idx, pos_type & pos) const; + bool idxLast(BufferView &) const; /// can we enter this cell? bool validCell(idx_type i) const { return i == 2 || script_[i]; } @@ -99,7 +99,7 @@ protected: /// virtual DispatchResult - priv_dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos); + priv_dispatch(BufferView & bv, FuncRequest const & cmd); private: /// returns x offset for main part int dxx() const; diff --git a/src/mathed/math_textinset.C b/src/mathed/math_textinset.C index 9000c3cb7d..afd9a9a288 100644 --- a/src/mathed/math_textinset.C +++ b/src/mathed/math_textinset.C @@ -49,7 +49,8 @@ void MathTextInset::getScreenPos(idx_type /*idx*/, pos_type pos, int & x, int & } -bool MathTextInset::idxUpDown2(idx_type &, pos_type & pos, bool up, +#if 0 +bool MathTextInset::idxUpDown2(BufferView & pos, bool up, int /*targetx*/) const { // try to move only one screen row up or down if possible @@ -70,6 +71,7 @@ bool MathTextInset::idxUpDown2(idx_type &, pos_type & pos, bool up, pos = cell2.begin_ + cache_.cell(i).x2pos(x, cell2.glue_); return true; } +#endif void MathTextInset::metrics(MetricsInfo & mi, Dimension & dim) const diff --git a/src/mathed/math_textinset.h b/src/mathed/math_textinset.h index 5bc34dc3f5..97d5170598 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(idx_type &, pos_type & pos, bool up, int targetx) const; + //bool idxUpDown2(BufferView & 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 8162266a17..4dce259f58 100644 --- a/src/mathed/math_undersetinset.C +++ b/src/mathed/math_undersetinset.C @@ -47,30 +47,32 @@ void MathUndersetInset::draw(PainterInfo & pi, int x, int y) const } -bool MathUndersetInset::idxFirst(idx_type & i, pos_type & pos) const +bool MathUndersetInset::idxFirst(BufferView & bv) const { - i = 1; - pos = 0; + CursorSlice & cur = cursorTip(bv); + cur.idx() = 1; + cur.pos() = 0; return true; } -bool MathUndersetInset::idxLast(idx_type & i, pos_type & pos) const +bool MathUndersetInset::idxLast(BufferView & bv) const { - i = 1; - pos = cell(i).size(); + CursorSlice & cur = cursorTip(bv); + cur.idx() = 1; + cur.pos() = cur.lastpos(); return true; } -bool MathUndersetInset::idxUpDown(idx_type & idx, pos_type & pos, bool up, - int targetx) const +bool MathUndersetInset::idxUpDown(BufferView & bv, bool up, int targetx) const { + CursorSlice & cur = cursorTip(bv); idx_type target = up; // up ? 1 : 0, since upper cell has idx 1 - if (idx == target) + if (cur.idx() == target) return false; - idx = target; - pos = cell(idx).x2pos(targetx); + cur.idx() = target; + cur.pos() = cur.cell().x2pos(targetx); return true; } diff --git a/src/mathed/math_undersetinset.h b/src/mathed/math_undersetinset.h index 7886a28423..0642355529 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(idx_type & idx, pos_type & pos) const; + bool idxFirst(BufferView &) const; /// - bool idxLast(idx_type & idx, pos_type & pos) const; + bool idxLast(BufferView &) const; /// - bool idxUpDown(idx_type & idx, pos_type & pos, bool up, int targetx) const; + bool idxUpDown(BufferView &, bool up, int targetx) const; /// void write(WriteStream & os) const; /// diff --git a/src/mathed/ref_inset.C b/src/mathed/ref_inset.C index 2e749924bb..23ec4e5b1b 100644 --- a/src/mathed/ref_inset.C +++ b/src/mathed/ref_inset.C @@ -54,8 +54,7 @@ void RefInset::infoize(std::ostream & os) const DispatchResult -RefInset::priv_dispatch(FuncRequest const & cmd, - idx_type & idx, pos_type & pos) +RefInset::priv_dispatch(BufferView & bv, FuncRequest const & cmd) { switch (cmd.action) { case LFUN_INSET_MODIFY: @@ -72,15 +71,14 @@ RefInset::priv_dispatch(FuncRequest const & cmd, case LFUN_MOUSE_RELEASE: if (cmd.button() == mouse_button::button3) { lyxerr << "trying to goto ref" << cell(0) << endl; - cmd.view()->dispatch(FuncRequest(LFUN_REF_GOTO, asString(cell(0)))); + bv.dispatch(FuncRequest(LFUN_REF_GOTO, asString(cell(0)))); return DispatchResult(true, true); } if (cmd.button() == mouse_button::button1) { // Eventually trigger dialog with button 3 // not 1 string const data = createDialogStr("ref"); - cmd.view()->owner()->getDialogs(). - show("ref", data, this); + bv.owner()->getDialogs().show("ref", data, this); return DispatchResult(true, true); } break; @@ -89,7 +87,7 @@ RefInset::priv_dispatch(FuncRequest const & cmd, // eat other mouse commands return DispatchResult(true, true); default: - return CommandInset::priv_dispatch(cmd, idx, pos); + return CommandInset::priv_dispatch(bv, cmd); } // not our business return DispatchResult(false); diff --git a/src/mathed/ref_inset.h b/src/mathed/ref_inset.h index d5de1403dd..a65f9be9e2 100644 --- a/src/mathed/ref_inset.h +++ b/src/mathed/ref_inset.h @@ -62,7 +62,7 @@ protected: /// virtual DispatchResult - priv_dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos); + priv_dispatch(BufferView & bv, FuncRequest const & cmd); }; #endif diff --git a/src/text3.C b/src/text3.C index 7c34e2c4c9..522f1b53de 100644 --- a/src/text3.C +++ b/src/text3.C @@ -409,14 +409,13 @@ void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind) } -void doInsertInset(FuncRequest const & cmd, bool edit, bool pastesel) +void doInsertInset(BufferView * bv, FuncRequest const & cmd, + bool edit, bool pastesel) { - InsetOld * inset = createInset(cmd); + InsetOld * inset = createInset(bv, cmd); if (!inset) return; - BufferView * bv = cmd.view(); - bool gotsel = false; if (bv->selection().set()) { bv->owner()->dispatch(FuncRequest(LFUN_CUT)); @@ -448,11 +447,11 @@ bool LyXText::rtl() const } -DispatchResult LyXText::dispatch(FuncRequest const & cmd) +DispatchResult LyXText::dispatch(BufferView & view, FuncRequest const & cmd) { //lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl; - BufferView * bv = cmd.view(); + BufferView * bv = &view; switch (cmd.action) { @@ -858,17 +857,17 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) string const name = cmd.getArg(0); InsetBase * inset = bv->owner()->getDialogs().getOpenInset(name); if (inset) { - FuncRequest fr(bv, LFUN_INSET_MODIFY, cmd.argument); - inset->dispatch(fr); + FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument); + inset->dispatch(*bv, fr); } else { - FuncRequest fr(bv, LFUN_INSET_INSERT, cmd.argument); - dispatch(fr); + FuncRequest fr(LFUN_INSET_INSERT, cmd.argument); + dispatch(*bv, fr); } break; } case LFUN_INSET_INSERT: { - InsetOld * inset = createInset(cmd); + InsetOld * inset = createInset(bv, cmd); if (inset && !bv->insertInset(inset)) delete inset; break; @@ -890,7 +889,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) if (cursorPar()->layout()->free_spacing) insertChar(' '); else - doInsertInset(cmd, false, false); + doInsertInset(bv, cmd, false, false); moveCursor(bv, false); break; @@ -1358,12 +1357,12 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) case LFUN_ENVIRONMENT_INSERT: // Open the inset, and move the current selection // inside it. - doInsertInset(cmd, true, true); + doInsertInset(bv, cmd, true, true); break; case LFUN_INDEX_INSERT: // Just open the inset - doInsertInset(cmd, true, false); + doInsertInset(bv, cmd, true, false); break; case LFUN_INDEX_PRINT: @@ -1372,7 +1371,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) case LFUN_INSERT_LINE: case LFUN_INSERT_PAGEBREAK: // do nothing fancy - doInsertInset(cmd, false, false); + doInsertInset(bv, cmd, false, false); break; case LFUN_DEPTH_MIN: @@ -1398,7 +1397,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) case LFUN_MATH_NUMBER: case LFUN_MATH_EXTERN: case LFUN_MATH_SIZE: - mathDispatch(cmd); + mathDispatch(*bv, cmd); break; case LFUN_EMPH: diff --git a/src/undo.C b/src/undo.C index 410ec3bc35..2d47d2f51a 100644 --- a/src/undo.C +++ b/src/undo.C @@ -293,5 +293,11 @@ void recordUndo(Undo::undo_kind kind, LyXText const * text, paroffset_type par) void recordUndo(BufferView * bv, Undo::undo_kind kind) { - recordUndo(kind, bv->text(), bv->text()->cursor().par()); + recordUndo(*bv, kind); +} + + +void recordUndo(BufferView & bv, Undo::undo_kind kind) +{ + recordUndo(kind, bv.text(), bv.text()->cursor().par()); } diff --git a/src/undo.h b/src/undo.h index edf8f5562e..a45e97bff5 100644 --- a/src/undo.h +++ b/src/undo.h @@ -110,6 +110,7 @@ void recordUndo(Undo::undo_kind kind, /// convienience: prepare undo for the paragraph that contains the cursor void recordUndo(BufferView *, Undo::undo_kind kind); +void recordUndo(BufferView &, Undo::undo_kind kind); /// are we avoiding tracking undos currently? extern bool undo_frozen;