From db78dbfa042037997d764adca41d4a3c46ed981b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Tue, 4 Nov 2003 12:36:59 +0000 Subject: [PATCH] cursor changes git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8035 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.C | 12 +++ src/BufferView.h | 7 ++ src/BufferView_pimpl.C | 2 +- src/BufferView_pimpl.h | 5 +- src/ChangeLog | 17 ++++ src/cursor.C | 124 ++++++++++++++++------- src/cursor.h | 32 ++++-- src/insets/ChangeLog | 19 ++++ src/insets/inset.h | 2 - src/insets/insetbase.C | 10 ++ src/insets/insetbase.h | 5 + src/insets/insetbibitem.C | 2 +- src/insets/insetbranch.C | 8 +- src/insets/insetbranch.h | 2 - src/insets/insetcite.C | 7 +- src/insets/insetcite.h | 2 - src/insets/insetcollapsable.C | 105 ++++++++++---------- src/insets/insetcollapsable.h | 6 +- src/insets/insetcommand.C | 3 +- src/insets/insetert.C | 59 +++++------ src/insets/insetert.h | 2 + src/insets/insetexternal.C | 7 +- src/insets/insetexternal.h | 2 + src/insets/insetgraphics.C | 7 +- src/insets/insetgraphics.h | 2 + src/insets/insetindex.C | 7 +- src/insets/insetindex.h | 6 +- src/insets/insetlabel.C | 3 +- src/insets/insetnote.C | 5 - src/insets/insetnote.h | 3 +- src/insets/insetref.C | 2 +- src/insets/insettabular.C | 112 ++++++++++----------- src/insets/insettabular.h | 7 +- src/insets/insettext.C | 178 +++++++++++++++++----------------- src/insets/insettext.h | 16 ++- src/insets/inseturl.C | 2 +- src/iterators.C | 29 +----- src/iterators.h | 2 - src/lfuns.h | 13 ++- src/lyxfunc.C | 9 +- src/mathed/formulabase.C | 48 +++++---- src/mathed/formulabase.h | 4 + src/tabular.C | 5 +- src/text2.C | 9 +- src/text3.C | 13 +-- 45 files changed, 510 insertions(+), 412 deletions(-) diff --git a/src/BufferView.C b/src/BufferView.C index 3224536433..8f89513cb4 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -547,6 +547,18 @@ int BufferView::workHeight() const } +LCursor & BufferView::cursor() +{ + return pimpl_->cursor_; +} + + +LCursor const & BufferView::cursor() const +{ + return pimpl_->cursor_; +} + + void BufferView::x_target(int x) { x_target_ = x; diff --git a/src/BufferView.h b/src/BufferView.h index 34b9b25cba..f304f07f09 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -27,6 +27,7 @@ class ErrorList; class FuncRequest; class InsetOld; class Language; +class LCursor; class LyXText; class LyXScreen; class LyXView; @@ -34,6 +35,7 @@ class Painter; class TeXErrors; class UpdatableInset; + /** * A buffer view encapsulates a view onto a particular * buffer, and allows access to operate upon it. A view @@ -200,6 +202,11 @@ public: /// return target x position of cursor int BufferView::x_target() const; + /// access to cursor + LCursor & cursor(); + /// access to cursor + LCursor const & cursor() const; + private: /// Set the current locking inset void theLockingInset(UpdatableInset * inset); diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 93b49159fe..bbcc1282af 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -122,7 +122,7 @@ boost::signals::connection lostcon; BufferView::Pimpl::Pimpl(BufferView * bv, LyXView * owner, int xpos, int ypos, int width, int height) : bv_(bv), owner_(owner), buffer_(0), cursor_timeout(400), - using_xterm_cursor(false) + using_xterm_cursor(false), cursor_(bv) { workarea_.reset(WorkAreaFactory::create(xpos, ypos, width, height)); screen_.reset(LyXScreenFactory::create(workarea())); diff --git a/src/BufferView_pimpl.h b/src/BufferView_pimpl.h index 58704e2d70..80a0152ae6 100644 --- a/src/BufferView_pimpl.h +++ b/src/BufferView_pimpl.h @@ -19,6 +19,7 @@ #define BUFFERVIEW_PIMPL_H #include "BufferView.h" +#include "cursor.h" #include "errorlist.h" #include "insets/inset.h" @@ -43,7 +44,7 @@ class FuncRequest; /// struct BufferView::Pimpl : public boost::signals::trackable { /// - Pimpl(BufferView * i, LyXView * o, + Pimpl(BufferView * bv, LyXView * owner, int xpos, int ypos, int width, int height); /// Painter & painter() const; @@ -196,5 +197,7 @@ private: void MenuInsertLyXFile(std::string const & filen); /// our workarea WorkArea & workarea() const; + /// + LCursor cursor_; }; #endif // BUFFERVIEW_PIMPL_H diff --git a/src/ChangeLog b/src/ChangeLog index 086b6668aa..42db83d324 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,20 @@ +2003-11-04 André Pönitz + + * cursor.[Ch]: restructure + + * BufferView.[Ch]: + * BufferView_pimpl.[Ch]: new LCursor cursor_ member + + * iterators.[Ch] (asCursor): remove + + * lfuns.h: remove LFUN_INSET_EDIT + + * lyxfunc.C: + * tabular.C: + * text.C: + * text2.C: + * text3.C: use Inset::edit() instead of dispatch(LFUN_INSET_EDIT) + 2003-11-04 Alfredo Braunstein * lyxfind.[Ch]: complete overhaul diff --git a/src/cursor.C b/src/cursor.C index 3e27a80541..d823670c4c 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -3,7 +3,7 @@ * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * - * \author Jürgen Vigna + * \author André Pönitz * * Full author contact details are available in file CREDITS. */ @@ -20,12 +20,34 @@ #include "paragraph.h" #include "insets/updatableinset.h" +#include "insets/insettext.h" + +#include using std::vector; using std::endl; -DispatchResult Cursor::dispatch(FuncRequest const & cmd) +std::ostream & operator<<(std::ostream & os, CursorItem const & item) +{ + os << " inset: " << item.inset_ + << " idx: " << item.idx_ + << " text: " << item.text_ + << " par: " << item.par_ + << " pos: " << item.pos_; + return os; +} + + +std::ostream & operator<<(std::ostream & os, LCursor const & cursor) +{ + for (size_t i = 0, n = cursor.data_.size(); i != n; ++i) + os << " " << cursor.data_[i]; + return os; +} + + +DispatchResult LCursor::dispatch(FuncRequest const & cmd) { for (int i = data_.size() - 1; i >= 0; --i) { CursorItem & citem = data_[i]; @@ -34,47 +56,77 @@ DispatchResult Cursor::dispatch(FuncRequest const & cmd) DispatchResult res = citem.inset_->dispatch(cmd); lyxerr << " result: " << res.val() << endl; - if (res.dispatched()) - return res; + switch (res.val()) { + case FINISHED: + pop(); + return DispatchResult(true, true); + + case FINISHED_RIGHT: { + pop(); + //InsetText * inset = static_cast(innerInset()); + //if (inset) + // inset->moveRightIntern(bv_, false, false); + //else + // bv_->text->cursorRight(bv_); + innerText()->cursorRight(bv_); + return DispatchResult(true); + } + + case FINISHED_UP: { + pop(); + //InsetText * inset = static_cast(inset()); + //if (inset) + // result = inset->moveUp(bv); + return DispatchResult(true); + } + + case FINISHED_DOWN: { + pop(); + //InsetText * inset = static_cast(inset()); + //if (inset) + // result = inset->moveDown(bv); + return DispatchResult(true); + } + + default: + break; + } lyxerr << "# unhandled result: " << res.val() << endl; } - return DispatchResult(false); + + lyxerr << "trying to dispatch to main text " << bv_->text << endl; + DispatchResult res = bv_->text->dispatch(cmd); + lyxerr << " result: " << res.val() << endl; + return res; } -void buildCursor(Cursor & cursor, BufferView & bv) +LCursor::LCursor(BufferView * bv) + : bv_(bv) +{} + + +void LCursor::push(InsetOld * inset, LyXText * text) { - UpdatableInset * inset = bv.theLockingInset(); - lyxerr << "\nbuildCursor: " << inset << endl; - if (!inset) - return; - - inset = inset->getLockingInset(); - - bool ok = false; - ParIterator pit = bv.buffer()->par_iterator_begin(); - ParIterator end = bv.buffer()->par_iterator_end(); - for ( ; pit != end && !ok; ++pit) { - InsetList::iterator it = pit->insetlist.begin(); - InsetList::iterator iend = pit->insetlist.end(); - for ( ; it != iend && !ok; ++it) - if (it->inset == inset || it->inset == inset->owner()) - ok = true; - } + data_.push_back(CursorItem(inset, text)); +} - if (!ok) { - lyxerr << " tli not found! inset: " << inset << endl; - return; - } - pit.asCursor(cursor); - for (size_t i = 0, n = cursor.data_.size(); i != n; ++i) { - lyxerr << " inset: " << cursor.data_[i].inset_ - << " idx: " << cursor.data_[i].idx_ - << " text: " << cursor.data_[i].text_ - << " par: " << cursor.data_[i].par_ - << " pos: " << cursor.data_[i].pos_ - << endl; - } +void LCursor::pop() +{ + BOOST_ASSERT(!data_.empty()); + data_.pop_back(); +} + + +InsetOld * LCursor::innerInset() const +{ + return data_.empty() ? 0 : data_.back().inset_; +} + + +LyXText * LCursor::innerText() const +{ + return data_.empty() ? bv_->text : data_.back().text_; } diff --git a/src/cursor.h b/src/cursor.h index e56b7486be..d34954d894 100644 --- a/src/cursor.h +++ b/src/cursor.h @@ -29,10 +29,16 @@ class LyXText; * The cursor class describes the position of a cursor within a document. */ -class CursorItem : public TextCursor { +class CursorItem { public: /// CursorItem() : inset_(0), text_(0), idx_(0), par_(0), pos_(0) {} + /// + CursorItem(InsetOld * inset, LyXText * text) + : inset_(inset), text_(text), idx_(0), par_(0), pos_(0) + {} + /// + friend std::ostream & operator<<(std::ostream &, CursorItem const &); public: /// InsetOld * inset_; @@ -47,21 +53,27 @@ public: }; -class Cursor { +class LCursor { public: /// - Cursor() {} + LCursor(BufferView * bv); /// DispatchResult dispatch(FuncRequest const & cmd); + /// + void push(InsetOld *, LyXText *); + /// + void pop(); + /// + InsetOld * innerInset() const; + /// + LyXText * innerText() const; + /// + friend std::ostream & operator<<(std::ostream &, LCursor const &); public: - /// mainly used as stack, bnut wee need random access + /// mainly used as stack, but wee need random access std::vector data_; + /// + BufferView * bv_; }; -/// build cursor from current cursor in view -void buildCursor(Cursor & cursor, BufferView & bv); - -/// build cursor from (x,y) coordinates -void buildCursor(Cursor & cursor, BufferView & bv, int x, int y); - #endif // LYXCURSOR_H diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 2a304e608c..3e755a7c88 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,22 @@ +2003-11-04 André Pönitz + + * inset.h (edit): move locking code from dispatch() to edit() + + * insetbase.[Ch]: + * insetbibitem.C: + * insetbranch.[Ch]: + * insetcite.[Ch]: + * insetcollapsable.[Ch]: + * insetcommand.C: + * insetert.[Ch]: + * insetexternal.[Ch]: + * insetgraphics.[Ch]: + * insetindex.[Ch]: + * insetlabel.C: + * insetnote.[Ch]: + * insetref.C: + * insettabular.[Ch]: + * insettext.[Ch]: adjust 2003-11-04 Alfredo Braunstein diff --git a/src/insets/inset.h b/src/insets/inset.h index 45cde09eee..65ea2bd230 100644 --- a/src/insets/inset.h +++ b/src/insets/inset.h @@ -240,8 +240,6 @@ public: /// return the cursor if we own one otherwise giv'em just the /// BufferView cursor to work with. virtual LyXCursor const & cursor(BufferView * bview) const; - /// lock cell with given index - virtual void edit(BufferView *, int /*index*/) {} /// used to toggle insets // is the inset open? diff --git a/src/insets/insetbase.C b/src/insets/insetbase.C index e0df020b61..051e2fdff3 100644 --- a/src/insets/insetbase.C +++ b/src/insets/insetbase.C @@ -35,3 +35,13 @@ InsetBase::priv_dispatch(FuncRequest const &, idx_type &, pos_type &) { return DispatchResult(false); } + + +void InsetBase::edit(BufferView *, bool) +{} + + +void InsetBase::edit(BufferView * bv, int, int) +{ + edit(bv, true); +} diff --git a/src/insets/insetbase.h b/src/insets/insetbase.h index 179b43db3e..5b84726c4b 100644 --- a/src/insets/insetbase.h +++ b/src/insets/insetbase.h @@ -53,6 +53,11 @@ public: DispatchResult dispatch(FuncRequest const & cmd); + /// cursor enters + virtual void edit(BufferView * bv, bool left); + /// cursor enters + virtual void edit(BufferView * bv, int x, int y); + /// compute the size of the object returned in dim virtual void metrics(MetricsInfo & mi, Dimension & dim) const = 0; /// draw inset and update (xo, yo)-cache diff --git a/src/insets/insetbibitem.C b/src/insets/insetbibitem.C index b35f605850..f7bb99dd6b 100644 --- a/src/insets/insetbibitem.C +++ b/src/insets/insetbibitem.C @@ -65,7 +65,7 @@ InsetBibitem::priv_dispatch(FuncRequest const & cmd, { switch (cmd.action) { - case LFUN_INSET_EDIT: + case LFUN_MOUSE_PRESS: InsetCommandMailer("bibitem", *this).showDialog(cmd.view()); return DispatchResult(true, true); diff --git a/src/insets/insetbranch.C b/src/insets/insetbranch.C index 4cc82711fe..29189e9ce1 100644 --- a/src/insets/insetbranch.C +++ b/src/insets/insetbranch.C @@ -131,7 +131,8 @@ InsetBranch::priv_dispatch(FuncRequest const & cmd, bv->updateInset(this); return DispatchResult(true, true); } - case LFUN_INSET_EDIT: + + case LFUN_MOUSE_PRESS: if (cmd.button() != mouse_button::button3) return InsetCollapsable::priv_dispatch(cmd, idx, pos); return DispatchResult(false); @@ -142,10 +143,11 @@ InsetBranch::priv_dispatch(FuncRequest const & cmd, case LFUN_MOUSE_RELEASE: if (cmd.button() == mouse_button::button3 && hitButton(cmd)) { - InsetBranchMailer("branch", *this).showDialog(bv); + InsetBranchMailer("branch", *this).showDialog(bv); return DispatchResult(true); } - // fallthrough: + return InsetCollapsable::priv_dispatch(cmd, idx, pos); + default: return InsetCollapsable::priv_dispatch(cmd, idx, pos); } diff --git a/src/insets/insetbranch.h b/src/insets/insetbranch.h index 65a3d1194c..2422ef171a 100644 --- a/src/insets/insetbranch.h +++ b/src/insets/insetbranch.h @@ -34,8 +34,6 @@ class InsetBranch : public InsetCollapsable { public: /// - - InsetBranch(BufferParams const &, std::string const &); /// Copy constructor InsetBranch(InsetBranch const &); diff --git a/src/insets/insetcite.C b/src/insets/insetcite.C index 187c0b663a..8d8ba89afd 100644 --- a/src/insets/insetcite.C +++ b/src/insets/insetcite.C @@ -311,10 +311,11 @@ string const InsetCitation::getScreenLabel(Buffer const & buffer) const DispatchResult InsetCitation::priv_dispatch(FuncRequest const & cmd, - idx_type & idx, pos_type & pos) + idx_type & idx, pos_type & pos) { switch (cmd.action) { - case LFUN_INSET_EDIT: + + case LFUN_MOUSE_PRESS: InsetCommandMailer("citation", *this).showDialog(cmd.view()); return DispatchResult(true, true); @@ -322,7 +323,7 @@ InsetCitation::priv_dispatch(FuncRequest const & cmd, return InsetCommand::priv_dispatch(cmd, idx, pos); } } - + int InsetCitation::ascii(Buffer const & buffer, ostream & os, int) const { diff --git a/src/insets/insetcite.h b/src/insets/insetcite.h index a4cda12ec8..b26fe970e6 100644 --- a/src/insets/insetcite.h +++ b/src/insets/insetcite.h @@ -40,8 +40,6 @@ public: int latex(Buffer const &, std::ostream &, LatexRunParams const &) const; /// - DispatchResult localDispatch(FuncRequest const & cmd); - /// void validate(LaTeXFeatures &) const; protected: /// diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index fa467dfeb4..1b17118234 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -274,15 +274,61 @@ bool InsetCollapsable::hitButton(FuncRequest const & cmd) const } -void InsetCollapsable::edit(BufferView * bv, int index) +void InsetCollapsable::edit(BufferView * bv, bool left) { lyxerr << "InsetCollapsable: edit" << endl; if (!bv->lockInset(this)) - lyxerr << "InsetCollapsable: can't lock index " << index << endl; - inset.dispatch(FuncRequest(bv, LFUN_INSET_EDIT, "left")); + lyxerr << "InsetCollapsable: can't lock" << endl; + inset.edit(bv, left); first_after_edit = true; } +/* + if (!cmd.argument.empty()) { + UpdatableInset::edit( + if (collapsed_) { + lyxerr << "branch collapsed_" << endl; + collapsed_ = false; + if (bv->lockInset(this)) { + bv->updateInset(this); + bv->buffer()->markDirty(); + inset.dispatch(cmd); + first_after_edit = true; + } + } else { + lyxerr << "branch not collapsed_" << endl; + if (bv->lockInset(this)) + inset.dispatch(cmd); + } + return; + } + UpdatableInset::edit(cmd, idx, pos); +*/ + + +void InsetCollapsable::edit(BufferView * bv, int x, int y) +{ + if (collapsed_) { + collapsed_ = false; + // set this only here as it should be recollapsed only if + // it was already collapsed! + first_after_edit = true; + if (!bv->lockInset(this)) + return; + bv->updateInset(this); + bv->buffer()->markDirty(); + inset.edit(bv, x, y); + } else { + if (!bv->lockInset(this)) + return; + if (y <= button_dim.y2) + inset.edit(bv, x, 0); + else + inset.edit(bv, x, + ascent() + y - (height_collapsed() + inset.ascent())); + } +} + DispatchResult InsetCollapsable::priv_dispatch(FuncRequest const & cmd, @@ -292,57 +338,6 @@ InsetCollapsable::priv_dispatch(FuncRequest const & cmd, // << cmd.action << " '" << cmd.argument << "'\n"; BufferView * bv = cmd.view(); switch (cmd.action) { - case LFUN_INSET_EDIT: { - if (!cmd.argument.empty()) { - UpdatableInset::priv_dispatch(cmd, idx, pos); - if (collapsed_) { - lyxerr << "branch collapsed_" << endl; - collapsed_ = false; - if (bv->lockInset(this)) { - bv->updateInset(this); - bv->buffer()->markDirty(); - inset.dispatch(cmd); - first_after_edit = true; - } - } else { - lyxerr << "branch not collapsed_" << endl; - if (bv->lockInset(this)) - inset.dispatch(cmd); - } - return DispatchResult(true, true); - } - -#ifdef WITH_WARNINGS -#warning Fix this properly in BufferView_pimpl::workAreaButtonRelease -#endif - if (cmd.button() == mouse_button::button3) - return DispatchResult(true, true); - - UpdatableInset::priv_dispatch(cmd, idx, pos); - - if (collapsed_) { - collapsed_ = false; - // set this only here as it should be recollapsed only if - // it was already collapsed! - first_after_edit = true; - if (!bv->lockInset(this)) - return DispatchResult(true, true); - bv->updateInset(this); - bv->buffer()->markDirty(); - inset.dispatch(cmd); - } else { - if (!bv->lockInset(this)) - return DispatchResult(true, true); - if (cmd.y <= button_dim.y2) { - FuncRequest cmd1 = cmd; - cmd1.y = 0; - inset.dispatch(cmd1); - } else - inset.dispatch(adjustCommand(cmd)); - } - return DispatchResult(true, true); - } - case LFUN_MOUSE_PRESS: if (!collapsed_ && cmd.y > button_dim.y2) inset.dispatch(adjustCommand(cmd)); @@ -359,8 +354,6 @@ InsetCollapsable::priv_dispatch(FuncRequest const & cmd, default: DispatchResult const result = inset.dispatch(cmd); - if (result.val() >= FINISHED) - bv->unlockInset(this); first_after_edit = false; return result; } diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index de9f2229b1..ead9ce9425 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -153,14 +153,16 @@ protected: void setCollapsed(bool) const; /// Box const & buttonDim() const; + /// + void edit(BufferView *, bool); + /// + void edit(BufferView *, int, int); private: /// void lfunMouseRelease(FuncRequest const &); /// FuncRequest adjustCommand(FuncRequest const &); - /// - void edit(BufferView *, int index); public: /// diff --git a/src/insets/insetcommand.C b/src/insets/insetcommand.C index 451079e749..27f44991e6 100644 --- a/src/insets/insetcommand.C +++ b/src/insets/insetcommand.C @@ -108,7 +108,8 @@ InsetCommand::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &) return DispatchResult(true, true); case LFUN_MOUSE_RELEASE: - return dispatch(FuncRequest(cmd.view(), LFUN_INSET_EDIT)); + edit(cmd.view(), true); + return DispatchResult(true); default: return DispatchResult(false); diff --git a/src/insets/insetert.C b/src/insets/insetert.C index 1621b2016c..96358be220 100644 --- a/src/insets/insetert.C +++ b/src/insets/insetert.C @@ -424,35 +424,31 @@ int InsetERT::docbook(Buffer const &, ostream & os, } +void InsetERT::edit(BufferView * bv, bool left) +{ + if (status_ == Inlined) { + if (!bv->lockInset(this)) + return; + inset.edit(bv, left); + } else { + InsetCollapsable::edit(bv, left); + } + set_latex_font(bv); + updateStatus(bv); +} + + DispatchResult InsetERT::priv_dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos) { - DispatchResult result = DispatchResult(false); BufferView * bv = cmd.view(); - if (inset.paragraphs.begin()->empty()) { + if (inset.paragraphs.begin()->empty()) set_latex_font(bv); - } switch (cmd.action) { - case LFUN_INSET_EDIT: - if (cmd.button() == mouse_button::button3) - break; - if (status_ == Inlined) { - if (!bv->lockInset(this)) - break; - result = inset.dispatch(cmd); - } else { - // Is the following line correct? Ab - open(bv); - result = InsetCollapsable::priv_dispatch(cmd, idx, pos); - } - set_latex_font(bv); - updateStatus(bv); - break; - case LFUN_INSET_MODIFY: { InsetERT::ERTStatus status_; InsetERTMailer::string2params(cmd.argument, status_); @@ -467,35 +463,25 @@ InsetERT::priv_dispatch(FuncRequest const & cmd, */ inset.getLyXText(cmd.view())->fullRebreak(); bv->updateInset(this); - result = DispatchResult(true, true); + return DispatchResult(true, true); } - break; case LFUN_MOUSE_PRESS: lfunMousePress(cmd); - result = DispatchResult(true, true); - break; + return DispatchResult(true, true); case LFUN_MOUSE_MOTION: lfunMouseMotion(cmd); - result = DispatchResult(true, true); - break; + return DispatchResult(true, true); case LFUN_MOUSE_RELEASE: lfunMouseRelease(cmd); - result = DispatchResult(true, true); - break; + return DispatchResult(true, true); case LFUN_LAYOUT: bv->owner()->setLayout(inset.paragraphs.begin()->layout()->name()); - result = DispatchResult(true); - break; + return DispatchResult(true); - default: - result = InsetCollapsable::priv_dispatch(cmd, idx, pos); - } - - switch (cmd.action) { case LFUN_BREAKPARAGRAPH: case LFUN_BREAKPARAGRAPHKEEPLAYOUT: case LFUN_BACKSPACE: @@ -505,12 +491,11 @@ InsetERT::priv_dispatch(FuncRequest const & cmd, case LFUN_DELETE_LINE_FORWARD: case LFUN_CUT: set_latex_font(bv); - break; + return DispatchResult(false); default: - break; + return InsetCollapsable::priv_dispatch(cmd, idx, pos); } - return result; } diff --git a/src/insets/insetert.h b/src/insets/insetert.h index 2999f73397..177293504e 100644 --- a/src/insets/insetert.h +++ b/src/insets/insetert.h @@ -131,6 +131,8 @@ private: void set_latex_font(BufferView *); /// update status on button void updateStatus(BufferView *, bool = false) const; + /// + void edit(BufferView * bv, bool left); /// mutable ERTStatus status_; diff --git a/src/insets/insetexternal.C b/src/insets/insetexternal.C index 6611c02da7..2bc5e6fa40 100644 --- a/src/insets/insetexternal.C +++ b/src/insets/insetexternal.C @@ -458,7 +458,6 @@ InsetExternal::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &) return DispatchResult(true, true); case LFUN_MOUSE_RELEASE: - case LFUN_INSET_EDIT: InsetExternalMailer(*this).showDialog(cmd.view()); return DispatchResult(true, true); @@ -468,6 +467,12 @@ InsetExternal::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &) } +void InsetExternal::edit(BufferView * bv, bool) +{ + InsetExternalMailer(*this).showDialog(bv); +} + + void InsetExternal::metrics(MetricsInfo & mi, Dimension & dim) const { renderer_->metrics(mi, dim); diff --git a/src/insets/insetexternal.h b/src/insets/insetexternal.h index ea7e9bc120..24560f8c17 100644 --- a/src/insets/insetexternal.h +++ b/src/insets/insetexternal.h @@ -140,6 +140,8 @@ public: void setParams(InsetExternalParams const &, Buffer const &); /// void addPreview(lyx::graphics::PreviewLoader &) const; + /// + void edit(BufferView * bv, bool); protected: /// diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index 94225b8c05..fa0b84d122 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -210,7 +210,6 @@ InsetGraphics::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &) InsetGraphicsMailer(*this).updateDialog(cmd.view()); return DispatchResult(true, true); - case LFUN_INSET_EDIT: case LFUN_MOUSE_RELEASE: InsetGraphicsMailer(*this).showDialog(cmd.view()); return DispatchResult(true, true); @@ -221,6 +220,12 @@ InsetGraphics::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &) } +void InsetGraphics::edit(BufferView * bv, bool) +{ + InsetGraphicsMailer(*this).showDialog(bv); +} + + void InsetGraphics::metrics(MetricsInfo & mi, Dimension & dim) const { graphic_->metrics(mi, dim); diff --git a/src/insets/insetgraphics.h b/src/insets/insetgraphics.h index 070a096e9a..997d3ad804 100644 --- a/src/insets/insetgraphics.h +++ b/src/insets/insetgraphics.h @@ -77,6 +77,8 @@ public: InsetGraphicsParams const & params() const; /// void draw(PainterInfo & pi, int x, int y) const; + /// + void edit(BufferView * bv, bool); protected: /// virtual diff --git a/src/insets/insetindex.C b/src/insets/insetindex.C index 248c9fc400..8ac08e7fad 100644 --- a/src/insets/insetindex.C +++ b/src/insets/insetindex.C @@ -61,12 +61,11 @@ void InsetPrintIndex::draw(PainterInfo & pi, int x, int y) const } -DispatchResult -InsetIndex::priv_dispatch(FuncRequest const & cmd, - idx_type & idx, pos_type & pos) +DispatchResult InsetIndex::priv_dispatch(FuncRequest const & cmd, + idx_type & idx, pos_type & pos) { switch (cmd.action) { - case LFUN_INSET_EDIT: + case LFUN_MOUSE_RELEASE: InsetCommandMailer("index", *this).showDialog(cmd.view()); return DispatchResult(true, true); diff --git a/src/insets/insetindex.h b/src/insets/insetindex.h index 01147da850..a26c1e9eb0 100644 --- a/src/insets/insetindex.h +++ b/src/insets/insetindex.h @@ -38,11 +38,9 @@ public: /// int docbook(Buffer const &, std::ostream &, LatexRunParams const &) const; -protected: /// - virtual - DispatchResult - priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &); + DispatchResult priv_dispatch(FuncRequest const & cmd, + idx_type & idx, pos_type & pos); }; diff --git a/src/insets/insetlabel.C b/src/insets/insetlabel.C index b96d27ef4d..032a015746 100644 --- a/src/insets/insetlabel.C +++ b/src/insets/insetlabel.C @@ -66,10 +66,9 @@ InsetLabel::priv_dispatch(FuncRequest const & cmd, switch (cmd.action) { - case LFUN_INSET_EDIT: + case LFUN_MOUSE_RELEASE: InsetCommandMailer("label", *this).showDialog(bv); return DispatchResult(true, true); - break; case LFUN_INSET_MODIFY: { InsetCommandParams p; diff --git a/src/insets/insetnote.C b/src/insets/insetnote.C index 66c9896b02..7cbf9b77a9 100644 --- a/src/insets/insetnote.C +++ b/src/insets/insetnote.C @@ -145,11 +145,6 @@ InsetNote::priv_dispatch(FuncRequest const & cmd, return DispatchResult(true, true); } - case LFUN_INSET_EDIT: - if (cmd.button() == mouse_button::button3) - return DispatchResult(false); - return InsetCollapsable::priv_dispatch(cmd, idx, pos); - case LFUN_INSET_DIALOG_UPDATE: InsetNoteMailer("note", *this).updateDialog(bv); return DispatchResult(true, true); diff --git a/src/insets/insetnote.h b/src/insets/insetnote.h index dab6c2fa97..7c08678bf9 100644 --- a/src/insets/insetnote.h +++ b/src/insets/insetnote.h @@ -12,11 +12,10 @@ #ifndef INSETNOTE_H #define INSETNOTE_H - #include "insetcollapsable.h" - struct InsetNoteParams { +struct InsetNoteParams { /// void write(std::ostream & os) const; /// diff --git a/src/insets/insetref.C b/src/insets/insetref.C index a6a1538e8d..673b96bb0b 100644 --- a/src/insets/insetref.C +++ b/src/insets/insetref.C @@ -51,7 +51,7 @@ InsetRef::priv_dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos) { switch (cmd.action) { - case LFUN_INSET_EDIT: + case LFUN_MOUSE_PRESS: // Eventually trigger dialog with button 3 not 1 if (cmd.button() == mouse_button::button3) cmd.view()->owner()-> diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index eb170b68bb..ba85379c96 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -454,7 +454,7 @@ bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset) the_locking_inset = in; locked = true; resetPos(bv); - in->dispatch(FuncRequest(bv, LFUN_INSET_EDIT)); + in->edit(bv, true); return true; } } @@ -639,27 +639,63 @@ void InsetTabular::lfunMouseMotion(FuncRequest const & cmd) } -void InsetTabular::edit(BufferView * bv, int index) +void InsetTabular::edit(BufferView * bv, bool left) { - lyxerr << "InsetTabular::edit" << endl; + lyxerr << "InsetTabular::edit: " << this << " first cell: " + << &tabular.cell_info[0][0].inset << endl; + if (!bv->lockInset(this)) { - lyxerr << "InsetTabular::Cannot lock inset (2)" << endl; + lyxerr << "InsetTabular::Cannot lock inset" << endl; return; } + finishUndo(); locked = true; the_locking_inset = 0; inset_x = 0; inset_y = 0; - actcell = index; + + if (left) { + if (isRightToLeft(bv)) + actcell = tabular.getLastCellInRow(0); + else + actcell = 0; + } else { + if (isRightToLeft(bv)) + actcell = tabular.getFirstCellInRow(tabular.rows()-1); + else + actcell = tabular.getNumberOfCells() - 1; + } clearSelection(); resetPos(bv); bv->fitCursor(); +} - UpdatableInset & inset = tabular.getCellInset(actcell); - inset.dispatch(FuncRequest(bv, LFUN_INSET_EDIT, "left")); - if (the_locking_inset) - updateLocal(bv); + +void InsetTabular::edit(BufferView * bv, int x, int y) +{ + lyxerr << "InsetTabular::edit: " << this << " first cell " + << &tabular.cell_info[0][0].inset << endl; + + if (!bv->lockInset(this)) { + lyxerr << "InsetTabular::Cannot lock inset" << endl; + return; + } + + finishUndo(); + locked = true; + the_locking_inset = 0; + inset_x = 0; + inset_y = 0; + + setPos(bv, x, y); + clearSelection(); + finishUndo(); + if (insetHit(bv, x, y)) { + inset_x = cursorx_ - top_x + tabular.getBeginningOfTextInCell(actcell); + inset_y = cursory_; + activateCellInset(bv, x - inset_x, y - inset_y); + } } @@ -673,53 +709,6 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, DispatchResult result = UpdatableInset::priv_dispatch(cmd, idx, pos); BufferView * bv = cmd.view(); - if (cmd.action == LFUN_INSET_EDIT) { - - lyxerr << "InsetTabular::edit: " << this << " args: '" - << cmd.argument << "' first cell: " - << &tabular.cell_info[0][0].inset << endl; - - if (!bv->lockInset(this)) { - lyxerr << "InsetTabular::Cannot lock inset" << endl; - return DispatchResult(true, true); - } - - finishUndo(); - locked = true; - the_locking_inset = 0; - inset_x = 0; - inset_y = 0; - - if (cmd.argument.size()) { - if (cmd.argument == "left") { - if (isRightToLeft(bv)) - actcell = tabular.getLastCellInRow(0); - else - actcell = 0; - } else { - if (isRightToLeft(bv)) - actcell = tabular.getFirstCellInRow(tabular.rows()-1); - else - actcell = tabular.getNumberOfCells() - 1; - } - clearSelection(); - resetPos(bv); - bv->fitCursor(); - } - - else { - setPos(bv, cmd.x, cmd.y); - clearSelection(); - finishUndo(); - if (insetHit(bv, cmd.x, cmd.y) && cmd.button() != mouse_button::button3) { - inset_x = cursorx_ - top_x + tabular.getBeginningOfTextInCell(actcell); - inset_y = cursory_; - activateCellInset(bv, cmd.x - inset_x, cmd.y - inset_y, cmd.button()); - } - } - return DispatchResult(true, true); - } - if (result.dispatched()) { resetPos(bv); return result; @@ -1430,7 +1419,7 @@ DispatchResult InsetTabular::moveLeft(BufferView * bv, bool lock) if (!moved) return DispatchResult(false, FINISHED); // behind the inset - if (lock && activateCellInset(bv, 0, 0, mouse_button::none, true)) + if (lock && activateCellInset(bv, 0, 0, true)) return DispatchResult(true, true); resetPos(bv); return DispatchResult(true); @@ -1501,7 +1490,7 @@ bool InsetTabular::moveNextCell(BufferView * bv, bool lock) if (lock) { bool rtl = tabular.getCellInset(actcell).paragraphs.begin()-> isRightToLeftPar(bv->buffer()->params()); - activateCellInset(bv, 0, 0, mouse_button::none, !rtl); + activateCellInset(bv, 0, 0, !rtl); } resetPos(bv); return true; @@ -1530,7 +1519,7 @@ bool InsetTabular::movePrevCell(BufferView * bv, bool lock) if (lock) { bool rtl = tabular.getCellInset(actcell).paragraphs.begin()-> isRightToLeftPar(bv->buffer()->params()); - activateCellInset(bv, 0, 0, mouse_button::none, !rtl); + activateCellInset(bv, 0, 0, !rtl); } resetPos(bv); return true; @@ -1986,8 +1975,7 @@ void InsetTabular::tabularFeatures(BufferView * bv, } -bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, - mouse_button::state button, bool behind) +bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, bool behind) { UpdatableInset & inset = tabular.getCellInset(actcell); if (behind) { @@ -1997,7 +1985,7 @@ bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, } //inset_x = cursorx_ - top_x + tabular.getBeginningOfTextInCell(actcell); //inset_y = cursory_; - inset.dispatch(FuncRequest(bv, LFUN_INSET_EDIT, x, y, button)); + inset.edit(bv, x, y); if (!the_locking_inset) return false; updateLocal(bv); diff --git a/src/insets/insettabular.h b/src/insets/insettabular.h index 0e012ba93c..43efc29fbc 100644 --- a/src/insets/insettabular.h +++ b/src/insets/insettabular.h @@ -193,14 +193,16 @@ public: /// set the owning buffer void buffer(Buffer * buf); + /// lock cell with given index + void edit(BufferView * bv, bool); + /// + void edit(BufferView * bv, int, int); protected: /// virtual DispatchResult priv_dispatch(FuncRequest const &, idx_type &, pos_type &); private: - /// lock cell with given index - void edit(BufferView * bv, int index); /// void lfunMousePress(FuncRequest const &); /// @@ -253,7 +255,6 @@ private: } /// bool activateCellInset(BufferView *, int x = 0, int y = 0, - mouse_button::state button = mouse_button::none, bool behind = false); /// bool insetHit(BufferView * bv, int x, int y) const; diff --git a/src/insets/insettext.C b/src/insets/insettext.C index e029e2cd49..885c9f91a8 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -108,11 +108,8 @@ void InsetText::init() for (; pit != end; ++pit) pit->setInsetOwner(this); text_.paragraphs_ = ¶graphs; - top_y = 0; locked = false; - inset_par = -1; - inset_pos = 0; inset_x = 0; inset_y = 0; no_selection = true; @@ -267,13 +264,8 @@ void InsetText::draw(PainterInfo & pi, int x, int y) const x += scroll(); top_baseline = y; - top_y = y - dim_.asc; - - if (the_locking_inset - && text_.cursor.par() == inset_par && cpos() == inset_pos) { - inset_x = cx() - x; - inset_y = cy(); - } + inset_x = cx() - x; + inset_y = cy(); x += TEXT_TO_INSET_OFFSET; @@ -353,9 +345,8 @@ void InsetText::lockInset(BufferView * bv) { locked = true; the_locking_inset = 0; - inset_pos = inset_x = inset_y = 0; + inset_x = inset_y = 0; inset_boundary = false; - inset_par = -1; old_par = -1; text_.setCursorIntern(0, 0); text_.clearSelection(); @@ -376,8 +367,6 @@ void InsetText::lockInset(BufferView * /*bv*/, UpdatableInset * inset) the_locking_inset = inset; inset_x = cx() - top_x; inset_y = cy(); - inset_pos = cpos(); - inset_par = text_.cursor.par(); inset_boundary = cboundary(); } @@ -418,13 +407,8 @@ bool InsetText::lockInsetInInset(BufferView * bv, UpdatableInset * inset) } if (the_locking_inset && the_locking_inset == inset) { - if (text_.cursor.par() == inset_par && cpos() == inset_pos) { - lyxerr[Debug::INSETS] << "OK" << endl; - inset_x = cx() - top_x; - inset_y = cy(); - } else { - lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl; - } + inset_x = cx() - top_x; + inset_y = cy(); } else if (the_locking_inset) { lyxerr[Debug::INSETS] << "MAYBE" << endl; return the_locking_inset->lockInsetInInset(bv, inset); @@ -547,7 +531,6 @@ bool InsetText::lfunMouseRelease(FuncRequest const & cmd) no_selection = true; if (the_locking_inset) { DispatchResult const res = the_locking_inset->dispatch(cmd1); - return res.dispatched(); } @@ -591,70 +574,95 @@ void InsetText::lfunMouseMotion(FuncRequest const & cmd) } -DispatchResult -InsetText::priv_dispatch(FuncRequest const & cmd, - idx_type & idx, pos_type & pos) +void InsetText::edit(BufferView * bv, bool left) { - BufferView * bv = cmd.view(); - setViewCache(bv); + if (!bv->lockInset(this)) { + lyxerr[Debug::INSETS] << "Cannot lock inset" << endl; + return; + } - switch (cmd.action) { - case LFUN_INSET_EDIT: { - UpdatableInset::priv_dispatch(cmd, idx, pos); + locked = true; + the_locking_inset = 0; + inset_x = 0; + inset_y = 0; + inset_boundary = false; + old_par = -1; - if (!bv->lockInset(this)) { - lyxerr[Debug::INSETS] << "Cannot lock inset" << endl; - return DispatchResult(true, true); - } + if (left) + text_.setCursorIntern(0, 0); + else + text_.setCursor(paragraphs.size() - 1, paragraphs.back().size()); - locked = true; - the_locking_inset = 0; - inset_pos = 0; - inset_x = 0; - inset_y = 0; - inset_boundary = false; - inset_par = -1; - old_par = -1; + // If the inset is empty set the language of the current font to the + // language to the surronding text (if different). + if (paragraphs.begin()->empty() && + paragraphs.size() == 1 && + bv->getParentLanguage(this) != text_.current_font.language()) + { + LyXFont font(LyXFont::ALL_IGNORE); + font.setLanguage(bv->getParentLanguage(this)); + setFont(bv, font, false); + } + updateLocal(bv, false); + // Tell the paragraph dialog that we've entered an insettext. + bv->dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE)); +} - if (cmd.argument.size()) { - if (cmd.argument == "left") - text_.setCursorIntern(0, 0); - else - text_.setCursor(paragraphs.size() - 1, paragraphs.back().size()); - } else { - int tmp_y = (cmd.y < 0) ? 0 : cmd.y; - // we put here -1 and not button as now the button in the - // edit call should not be needed we will fix this in 1.3.x - // cycle hopefully (Jug 20020509) - // FIXME: GUII I've changed this to none: probably WRONG - if (!checkAndActivateInset(bv, cmd.x, tmp_y, mouse_button::none)) { - text_.setCursorFromCoordinates(cmd.x, cmd.y + dim_.asc); - text_.cursor.x(text_.cursor.x()); - bv->x_target(text_.cursor.x()); - } - } - text_.clearSelection(); - finishUndo(); +void InsetText::edit(BufferView * bv, int x, int y) +{ + if (!bv->lockInset(this)) { + lyxerr[Debug::INSETS] << "Cannot lock inset" << endl; + return; + } - // If the inset is empty set the language of the current font to the - // language to the surronding text (if different). - if (paragraphs.begin()->empty() && - paragraphs.size() == 1 && - bv->getParentLanguage(this) != text_.current_font.language()) - { - LyXFont font(LyXFont::ALL_IGNORE); - font.setLanguage(bv->getParentLanguage(this)); - setFont(bv, font, false); - } + locked = true; + the_locking_inset = 0; + inset_x = 0; + inset_y = 0; + inset_boundary = false; + old_par = -1; - updateLocal(bv, false); - // Tell the paragraph dialog that we've entered an insettext. - bv->dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE)); - return DispatchResult(true, true); + int tmp_y = (y < 0) ? 0 : y; + // we put here -1 and not button as now the button in the + // edit call should not be needed we will fix this in 1.3.x + // cycle hopefully (Jug 20020509) + // FIXME: GUII I've changed this to none: probably WRONG + if (!checkAndActivateInset(bv, x, tmp_y)) { + text_.setCursorFromCoordinates(x, y + dim_.asc); + text_.cursor.x(text_.cursor.x()); + bv->x_target(text_.cursor.x()); } + text_.clearSelection(); + finishUndo(); + + // If the inset is empty set the language of the current font to the + // language to the surronding text (if different). + if (paragraphs.begin()->empty() && + paragraphs.size() == 1 && + bv->getParentLanguage(this) != text_.current_font.language()) + { + LyXFont font(LyXFont::ALL_IGNORE); + font.setLanguage(bv->getParentLanguage(this)); + setFont(bv, font, false); + } + + updateLocal(bv, false); + // Tell the paragraph dialog that we've entered an insettext. + bv->dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE)); +} + + +DispatchResult +InsetText::priv_dispatch(FuncRequest const & cmd, + idx_type & idx, pos_type & pos) +{ + BufferView * bv = cmd.view(); + setViewCache(bv); + + switch (cmd.action) { case LFUN_MOUSE_PRESS: lfunMousePress(cmd); return DispatchResult(true, true); @@ -1193,7 +1201,6 @@ void InsetText::setFont(BufferView * bv, LyXFont const & font, bool toggleall, return; } - if (text_.selection.set()) text_.recUndo(text_.cursor.par()); @@ -1221,8 +1228,7 @@ bool InsetText::checkAndActivateInset(BufferView * bv, bool front) InsetOld * inset = cpar()->getInset(cpos()); if (!isHighlyEditableInset(inset)) return false; - FuncRequest cmd(bv, LFUN_INSET_EDIT, front ? "left" : "right"); - inset->dispatch(cmd); + inset->edit(bv, front); if (!the_locking_inset) return false; updateLocal(bv, false); @@ -1230,30 +1236,22 @@ bool InsetText::checkAndActivateInset(BufferView * bv, bool front) } -bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y, - mouse_button::state button) +bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y) { int dummyx = x; int dummyy = y + dim_.asc; InsetOld * inset = getLyXText(bv)->checkInsetHit(dummyx, dummyy); - // we only do the edit() call if the inset was hit by the mouse - // or if it is a highly editable inset. So we should call this - // function from our own edit with button < 0. - // FIXME: GUII jbl. I've changed this to ::none for now which is probably - // WRONG - if (button == mouse_button::none && !isHighlyEditableInset(inset)) - return false; - if (!inset) return false; + if (!isHighlyEditableInset(inset)) + return false; if (x < 0) x = dim_.wid; if (y < 0) y = dim_.des; inset_x = cx() - top_x; inset_y = cy(); - FuncRequest cmd(bv, LFUN_INSET_EDIT, x - inset_x, y - inset_y, button); - inset->dispatch(cmd); + inset->edit(bv, x - inset_x, y - inset_y); if (!the_locking_inset) return false; updateLocal(bv, false); diff --git a/src/insets/insettext.h b/src/insets/insettext.h index 57ce3daa25..02b3da1c5c 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -179,6 +179,11 @@ public: /// void addPreview(lyx::graphics::PreviewLoader &) const; + /// + void edit(BufferView *, bool); + /// + void edit(BufferView *, int, int); + /// int numParagraphs() const { return 1; } /// @@ -221,14 +226,13 @@ private: /// DispatchResult moveUp(BufferView *); /// - DispatchResult moveDown(BufferView *); + DispatchResult moveDown(BufferView *); /// void setCharFont(Buffer const &, int pos, LyXFont const & font); /// bool checkAndActivateInset(BufferView * bv, bool front); /// - bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0, - mouse_button::state button = mouse_button::none); + bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0); /// void removeNewlines(); /// @@ -262,12 +266,6 @@ private: /// mutable bool locked; /// - mutable int top_y; - /// - lyx::paroffset_type inset_par; - /// - lyx::pos_type inset_pos; - /// bool inset_boundary; /// mutable int inset_x; diff --git a/src/insets/inseturl.C b/src/insets/inseturl.C index 67933a134c..ec996776ae 100644 --- a/src/insets/inseturl.C +++ b/src/insets/inseturl.C @@ -49,7 +49,7 @@ InsetUrl::priv_dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos) { switch (cmd.action) { - case LFUN_INSET_EDIT: + case LFUN_MOUSE_PRESS: InsetCommandMailer("url", *this).showDialog(cmd.view()); return DispatchResult(true, true); default: diff --git a/src/iterators.C b/src/iterators.C index 609f6e6bba..6240fd82aa 100644 --- a/src/iterators.C +++ b/src/iterators.C @@ -16,11 +16,8 @@ #include "PosIterator.h" #include "cursor.h" #include "BufferView.h" -#include "funcrequest.h" #include "dispatchresult.h" - - #include "insets/inset.h" #include "insets/updatableinset.h" #include "insets/insettext.h" @@ -183,22 +180,6 @@ int ParIterator::index() const } -void ParIterator::asCursor(Cursor & cursor) const -{ - cursor.data_.clear(); - for (size_t i = 1, n = size(); i < n; ++i) { - ParPosition const & pos = pimpl_->positions[i - 1]; - CursorItem item; - item.inset_ = (*pos.it)->inset; - item.idx_ = (*pos.index); - item.text_ = (*pos.it)->inset->getText(*pos.index); - item.par_ = 0; - item.pos_ = 0; - cursor.data_.push_back(item); - } -} - - Paragraph & ParIterator::operator*() const { return *pimpl_->positions.back().pit; @@ -387,18 +368,18 @@ void ParIterator::lockPath(BufferView * bv) const bv->insetUnlock(); int last = size() - 1; for (int i = 0; i < last; ++i) { - UpdatableInset * outer = dynamic_cast((*pimpl_->positions[i].it)->inset); - FuncRequest cmd(bv, LFUN_INSET_EDIT); - outer->dispatch(cmd); + UpdatableInset * outer = + dynamic_cast((*pimpl_->positions[i].it)->inset); + outer->edit(bv, true); LyXText * txt = outer->getText(*pimpl_->positions[i].index); InsetText * inner = txt->inset_owner; - // deep vodoo magic: on a table, the edit call locks the first + // deep voodoo magic: on a table, the edit call locks the first // cell and further lock calls get lost there. // We have to unlock it to then lock the correct one. if (outer != inner) { outer->insetUnlock(bv); outer->lockInsetInInset(bv, inner); - inner->dispatch(FuncRequest(bv, LFUN_INSET_EDIT)); + inner->edit(bv, true); } } } diff --git a/src/iterators.h b/src/iterators.h index c76a713619..b705a4a129 100644 --- a/src/iterators.h +++ b/src/iterators.h @@ -56,8 +56,6 @@ public: /// size_t size() const; /// - void asCursor(Cursor & cursor) const; - /// friend bool operator==(ParIterator const & iter1, ParIterator const & iter2); /// diff --git a/src/lfuns.h b/src/lfuns.h index 359b3161fc..daae7eb2b6 100644 --- a/src/lfuns.h +++ b/src/lfuns.h @@ -293,41 +293,40 @@ enum kb_action { // 220 LFUN_MOUSE_DOUBLE, // André 9 Aug 2002 LFUN_MOUSE_TRIPLE, // André 9 Aug 2002 - LFUN_INSET_EDIT, // André 16 Aug 2002 LFUN_INSET_WRAP, // Dekel 7 Apr 2002 LFUN_TRACK_CHANGES, // Levon 20021001 (cool date !) - // 225 LFUN_MERGE_CHANGES, // Levon 20021016 + // 225 LFUN_ACCEPT_CHANGE, // Levon 20021016 LFUN_REJECT_CHANGE, // Levon 20021016 LFUN_ACCEPT_ALL_CHANGES, // Levon 20021016 LFUN_REJECT_ALL_CHANGES, // Levon 20021016 - // 230 LFUN_INSERT_BIBITEM, // André 14 Feb 2003 + // 230 LFUN_DIALOG_SHOW, LFUN_DIALOG_SHOW_NEW_INSET, LFUN_DIALOG_SHOW_NEXT_INSET, LFUN_DIALOG_UPDATE, - // 235 LFUN_DIALOG_HIDE, + // 235 LFUN_DIALOG_DISCONNECT_INSET, LFUN_INSET_APPLY, LFUN_INSET_INSERT, LFUN_INSET_MODIFY, - // 240 LFUN_INSET_DIALOG_UPDATE, + // 240 LFUN_INSET_SETTINGS, LFUN_PARAGRAPH_APPLY, LFUN_PARAGRAPH_UPDATE, LFUN_EXTERNAL_EDIT, - // 245 LFUN_INSERT_BRANCH, + // 245 LFUN_INSET_DIALOG_SHOW, LFUN_INSERT_BOX, LFUN_INSERT_LINE, LFUN_INSERT_PAGEBREAK, - // 250 LFUN_REPEAT, + // 250 LFUN_LASTACTION // end of the table }; diff --git a/src/lyxfunc.C b/src/lyxfunc.C index a4bac22fb7..2c5c7356d4 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -882,11 +882,9 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose) view()->hideCursor(); #if 1 - { - Cursor cursor; - buildCursor(cursor, *view()); + if (0) { DispatchResult result = - cursor.dispatch(FuncRequest(func, view())); + view()->cursor().dispatch(FuncRequest(func, view())); if (result.dispatched()) { if (result.update()) { @@ -1411,8 +1409,7 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose) LyXText * lt = view()->getLyXText(); if (par->inInset()) { - FuncRequest cmd(view(), LFUN_INSET_EDIT, "left"); - par.inset()->dispatch(cmd); + par.inset()->edit(view(), true); lt = par->inInset()->getLyXText(view()); } diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index 8d0a514cc2..b3ad9ca447 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -67,7 +67,7 @@ bool openNewInset(BufferView * bv, UpdatableInset * new_inset) delete new_inset; return false; } - new_inset->dispatch(FuncRequest(bv, LFUN_INSET_EDIT, "left")); + new_inset->edit(bv, true); return true; } @@ -317,6 +317,34 @@ DispatchResult InsetFormulaBase::lfunMouseMotion(FuncRequest const & cmd) } +void InsetFormulaBase::edit(BufferView * bv, bool left) +{ + lyxerr << "Called FormulaBase::edit" << endl; + if (!bv->lockInset(this)) + lyxerr << "Cannot lock math inset in edit call!" << endl; + releaseMathCursor(bv); + mathcursor = new MathCursor(this, left); + // if that is removed, we won't get the magenta box when entering an + // inset for the first time + bv->updateInset(this); +} + + +void InsetFormulaBase::edit(BufferView * bv, int x, int y) +{ + lyxerr << "Called FormulaBase::EDIT with '" << x << ' ' << y << "'" << endl; + if (!bv->lockInset(this)) + lyxerr << "Cannot lock math inset in edit call!" << endl; + releaseMathCursor(bv); + mathcursor = new MathCursor(this, true); + //metrics(bv); + mathcursor->setPos(x + xo_, y + yo_); + // if that is removed, we won't get the magenta box when entering an + // inset for the first time + bv->updateInset(this); +} + + DispatchResult InsetFormulaBase::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &) @@ -333,24 +361,6 @@ InsetFormulaBase::priv_dispatch(FuncRequest const & cmd, bool remove_inset = false; switch (cmd.action) { - case LFUN_INSET_EDIT: - lyxerr << "Called EDIT with '" << cmd.argument << "'" << endl; - if (!bv->lockInset(this)) - lyxerr << "Cannot lock math inset in edit call!" << endl; - releaseMathCursor(bv); - if (!cmd.argument.empty()) { - mathcursor = new MathCursor(this, cmd.argument == "left"); - //metrics(bv); - } else { - mathcursor = new MathCursor(this, true); - //metrics(bv); - mathcursor->setPos(cmd.x + xo_, cmd.y + yo_); - } - // if that is removed, we won't get the magenta box when entering an - // inset for the first time - bv->updateInset(this); - return DispatchResult(true, true); - case LFUN_MOUSE_PRESS: //lyxerr << "Mouse single press" << endl; return lfunMousePress(cmd); diff --git a/src/mathed/formulabase.h b/src/mathed/formulabase.h index 56075c6b9c..3f93f4c452 100644 --- a/src/mathed/formulabase.h +++ b/src/mathed/formulabase.h @@ -81,6 +81,10 @@ public: bool display() const; // return the selection as std::string std::string selectionAsString() const; + /// + void edit(BufferView * bv, bool); + /// + void edit(BufferView * bv, int, int); protected: /// To allow transparent use of math editing functions virtual diff --git a/src/tabular.C b/src/tabular.C index e140abd634..82fb4afb8b 100644 --- a/src/tabular.C +++ b/src/tabular.C @@ -2560,7 +2560,7 @@ int LyXTabular::getCellFromInset(InsetOld const * inset) const return -1; } - for (int cell = getNumberOfCells(); cell >= 0; --cell) + for (int cell = 0, n = getNumberOfCells(); cell < n; ++cell) if (&getCellInset(cell) == inset) { lyxerr[Debug::INSETTEXT] << "LyXTabular::getCellFromInset: " << "cell=" << cell << endl; @@ -2568,7 +2568,8 @@ int LyXTabular::getCellFromInset(InsetOld const * inset) const } // We should have found a cell at this point - lyxerr << "LyXTabular::getCellFromInset: Cell not found!" << endl; + lyxerr << "LyXTabular::getCellFromInset: Cell of inset " + << inset << " not found!" << endl; return -1; } diff --git a/src/text2.C b/src/text2.C index 6b5d4328a0..64a2fc00db 100644 --- a/src/text2.C +++ b/src/text2.C @@ -27,6 +27,7 @@ #include "BufferView.h" #include "Bullet.h" #include "counters.h" +#include "cursor.h" #include "CutAndPaste.h" #include "debug.h" #include "dispatchresult.h" @@ -1629,8 +1630,8 @@ void LyXText::cursorUp(bool selecting) y -= topy; InsetOld * inset_hit = checkInsetHit(x, y1); if (inset_hit && isHighlyEditableInset(inset_hit)) { - inset_hit->dispatch( - FuncRequest(bv(), LFUN_INSET_EDIT, x, y - (y2 - y1), mouse_button::none)); + inset_hit->edit(bv(), x, y - (y2 - y1)); + bv()->cursor().push(inset_hit, inset_hit->getText(0)); } } #else @@ -1657,8 +1658,8 @@ void LyXText::cursorDown(bool selecting) y -= topy; InsetOld * inset_hit = checkInsetHit(x, y1); if (inset_hit && isHighlyEditableInset(inset_hit)) { - FuncRequest cmd(bv(), LFUN_INSET_EDIT, x, y - (y2 - y1), mouse_button::none); - inset_hit->dispatch(cmd); + bv()->cursor().push(inset_hit, inset_hit->getText(0)); + inset_hit->edit(bv(), x, y - (y2 - y1)); } } #else diff --git a/src/text3.C b/src/text3.C index 5635facaa4..4fdef9729f 100644 --- a/src/text3.C +++ b/src/text3.C @@ -20,6 +20,7 @@ #include "buffer.h" #include "bufferparams.h" #include "BufferView.h" +#include "cursor.h" #include "debug.h" #include "dispatchresult.h" #include "factory.h" @@ -376,8 +377,8 @@ void doInsertInset(LyXText * lt, FuncRequest const & cmd, } if (bv->insertInset(inset)) { if (edit) { - FuncRequest cmd(bv, LFUN_INSET_EDIT, "left"); - inset->dispatch(cmd); + inset->edit(bv, true); + bv->cursor().push(inset, inset->getText(0)); } if (gotsel && pastesel) bv->owner()->dispatch(FuncRequest(LFUN_PASTE)); @@ -594,8 +595,8 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) && isHighlyEditableInset(cursorPar()->getInset(cursor.pos()))) { InsetOld * tmpinset = cursorPar()->getInset(cursor.pos()); cmd.message(tmpinset->editMessage()); - FuncRequest cmd1(bv, LFUN_INSET_EDIT, is_rtl ? "right" : "left"); - tmpinset->dispatch(cmd1); + tmpinset->edit(bv, !is_rtl); + bv->cursor().push(tmpinset, tmpinset->getText(0)); break; } if (!is_rtl) @@ -619,8 +620,8 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) isHighlyEditableInset(cursorPar()->getInset(cursor.pos()))) { InsetOld * tmpinset = cursorPar()->getInset(cursor.pos()); cmd.message(tmpinset->editMessage()); - FuncRequest cmd1(bv, LFUN_INSET_EDIT, is_rtl ? "left" : "right"); - tmpinset->dispatch(cmd1); + tmpinset->edit(bv, is_rtl); + bv->cursor().push(tmpinset, tmpinset->getText(0)); break; } if (is_rtl) -- 2.39.2