+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
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;
+}
};
bool operator!=(PosIterator const &, PosIterator const &);
+bool operator==(PosIterator const &, PosIterator const &);
+int distance(PosIterator const &, PosIterator const &);
+void advance(PosIterator &, int);
#endif
#include "lyxrow.h"
#include "paragraph.h"
#include "ParagraphParameters.h"
+#include "PosIterator.h"
+#include "iterators.h"
#include "frontends/Alert.h"
#include "frontends/LyXView.h"
}
}
+
+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
class BufferView;
class LyXFont;
class LyXText;
+class PosIterator;
namespace bv_funcs {
*/
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,
bool toggleall = true);
/// replace selection with insertion
extern void replaceSelection(LyXText * lt);
+
+
+
}; // namespace bv_funcs
#endif
#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>
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));
+ }
+ }
+}
class LyXText;
class InsetOld;
class Cursor;
+class BufferView;
class PosIterator;
///
friend
bool operator==(ParIterator const & iter1, ParIterator const & iter2);
+ ///
+ void lockPath(BufferView *) const;
///
PosIterator asPosIterator(lyx::pos_type) const;