add lockPath and a few helpers

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8015 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Alfredo Braunstein 2003-11-03 09:23:23 +00:00
parent 99fe02467a
commit 4faa9e29cf
7 changed files with 99 additions and 0 deletions

View 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

View 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;
}

View 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

View 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

View 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

View File

@ -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 <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));
}
}
}

View 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;