]> git.lyx.org Git - lyx.git/commitdiff
add lockPath and a few helpers
authorAlfredo Braunstein <abraunst@lyx.org>
Mon, 3 Nov 2003 09:23:23 +0000 (09:23 +0000)
committerAlfredo Braunstein <abraunst@lyx.org>
Mon, 3 Nov 2003 09:23:23 +0000 (09:23 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8015 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/PosIterator.C
src/PosIterator.h
src/bufferview_funcs.C
src/bufferview_funcs.h
src/iterators.C
src/iterators.h

index 67c99bcb15729f009c3589371ea558269e46a7c4..c4dfb6df2855a9d7baf82b69cb231b373d042053 100644 (file)
@@ -1,4 +1,10 @@
 
+2003-11-03  Alfredo Braunstein  <abraunst@libero.it>
+
+       * PosIterator.C (distance, advance): new
+       * bufferview_funcs.[Ch] (put_selection_at): new
+       * iterators.[Ch] (lockPath): new
+
 2003-11-02  Alfredo Braunstein  <abraunst@libero.it>
 
        * iterators.[Ch] (asPosIterator): added
index f89ef75b9ff4825343b93fb3713d00918cbb40b6..61c0ec70911367b7bbc7de089de9cfb3bf3f7262 100644 (file)
@@ -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;
+}
index 2fb5e4706a1892e34a5ea467c42e20f385afafc9..9d77cce44773363faf6b4eb0f1aa4e93e363599d 100644 (file)
@@ -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
 
index 8867bcfeb1ba52624e38fc6b1633810824ac3d6f..82397a6274c42f43763f904dfc518fe970709f36 100644 (file)
@@ -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
index 6ecc07ea7f12f21460e8d3b62c11fc7f451cb41b..264b4b2f0716a9f5de3ae29768dfb05f531c30dc 100644 (file)
@@ -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
index acbe21237c7090aa349a9fb4cc8651a7be8628a8..ee67075ab50d4ead0969c027e8460c35539d80ce 100644 (file)
 #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 <boost/next_prior.hpp>
 #include <boost/optional.hpp>
@@ -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<UpdatableInset *>((*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));
+               }
+       }
+}
index 88711f667b4b433859cc2de4afe1d4a34f121310..c76a7136194db50e64f75603897193d3a3f127ab 100644 (file)
@@ -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;