From 4faa9e29cf9d341bd1ab84e0e1a99985f2cceac2 Mon Sep 17 00:00:00 2001 From: Alfredo Braunstein Date: Mon, 3 Nov 2003 09:23:23 +0000 Subject: [PATCH] add lockPath and a few helpers git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8015 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 6 ++++++ src/PosIterator.C | 18 ++++++++++++++++++ src/PosIterator.h | 3 +++ src/bufferview_funcs.C | 32 ++++++++++++++++++++++++++++++++ src/bufferview_funcs.h | 9 +++++++++ src/iterators.C | 28 ++++++++++++++++++++++++++++ src/iterators.h | 3 +++ 7 files changed, 99 insertions(+) diff --git a/src/ChangeLog b/src/ChangeLog index 67c99bcb15..c4dfb6df28 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,4 +1,10 @@ +2003-11-03 Alfredo Braunstein + + * PosIterator.C (distance, advance): new + * bufferview_funcs.[Ch] (put_selection_at): new + * iterators.[Ch] (lockPath): new + 2003-11-02 Alfredo Braunstein * iterators.[Ch] (asPosIterator): added diff --git a/src/PosIterator.C b/src/PosIterator.C index f89ef75b9f..61c0ec7091 100644 --- a/src/PosIterator.C +++ b/src/PosIterator.C @@ -147,3 +147,21 @@ PosIterator::PosIterator(BufferView & bv) operator=(par.asPosIterator(pos)); } + + +int distance(PosIterator const & cur, PosIterator const & end) +{ + PosIterator p = cur; + int count = 0; + for (; p != end; ++p, ++count); + return count; +} + + +void advance(PosIterator & cur, int howmuch) +{ + for (int i = 0; i < howmuch; ++i) + ++cur; + for (int i = 0; i > howmuch; --i) + --cur; +} diff --git a/src/PosIterator.h b/src/PosIterator.h index 2fb5e4706a..9d77cce447 100644 --- a/src/PosIterator.h +++ b/src/PosIterator.h @@ -62,7 +62,10 @@ private: }; bool operator!=(PosIterator const &, PosIterator const &); +bool operator==(PosIterator const &, PosIterator const &); +int distance(PosIterator const &, PosIterator const &); +void advance(PosIterator &, int); #endif diff --git a/src/bufferview_funcs.C b/src/bufferview_funcs.C index 8867bcfeb1..82397a6274 100644 --- a/src/bufferview_funcs.C +++ b/src/bufferview_funcs.C @@ -26,6 +26,8 @@ #include "lyxrow.h" #include "paragraph.h" #include "ParagraphParameters.h" +#include "PosIterator.h" +#include "iterators.h" #include "frontends/Alert.h" #include "frontends/LyXView.h" @@ -422,4 +424,34 @@ void replaceSelection(LyXText * text) } } + +void put_selection_at(BufferView * bv, PosIterator const & cur, + int length, bool backwards) +{ + ParIterator par = bv->buffer()->par_iterator_begin(); + for (; par.pit() != cur.pit(); ++par) + ; + + bv->getLyXText()->clearSelection(); + + LyXText * text = par.text() ? par.text() : bv->text; + + par.lockPath(bv); + + text->setCursor(cur.pit(), cur.pos()); + + if (length) { + text->setSelectionRange(length); + text->setSelection(); + if (backwards) + text->cursor = text->selection.start; + } + + + bv->fitCursor(); + bv->update(); + +} + + }; // namespace bv_funcs diff --git a/src/bufferview_funcs.h b/src/bufferview_funcs.h index 6ecc07ea7f..264b4b2f07 100644 --- a/src/bufferview_funcs.h +++ b/src/bufferview_funcs.h @@ -20,6 +20,7 @@ class BufferView; class LyXFont; class LyXText; +class PosIterator; namespace bv_funcs { @@ -44,6 +45,11 @@ void update_and_apply_freefont(BufferView * bv, std::string const & data); */ void apply_freefont(BufferView * bv); + +void put_selection_at(BufferView * bv, PosIterator & cur, + int length, bool backwards); + + /// what type of depth change to make enum DEPTH_CHANGE { INC_DEPTH, @@ -88,6 +94,9 @@ extern void toggleAndShow(BufferView *, LyXFont const &, bool toggleall = true); /// replace selection with insertion extern void replaceSelection(LyXText * lt); + + + }; // namespace bv_funcs #endif diff --git a/src/iterators.C b/src/iterators.C index acbe21237c..ee67075ab5 100644 --- a/src/iterators.C +++ b/src/iterators.C @@ -15,9 +15,15 @@ #include "paragraph.h" #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" #include #include @@ -374,3 +380,25 @@ PosIterator ParIterator::asPosIterator(lyx::pos_type pos) const pp.pit, pos, 0)); return p; } + + +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); + 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 + // 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)); + } + } +} diff --git a/src/iterators.h b/src/iterators.h index 88711f667b..c76a713619 100644 --- a/src/iterators.h +++ b/src/iterators.h @@ -20,6 +20,7 @@ class LyXText; class InsetOld; class Cursor; +class BufferView; class PosIterator; @@ -59,6 +60,8 @@ public: /// friend bool operator==(ParIterator const & iter1, ParIterator const & iter2); + /// + void lockPath(BufferView *) const; /// PosIterator asPosIterator(lyx::pos_type) const; -- 2.39.2