From 57536be00f30e3f7e49363ec47aea7afac66768a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Wed, 17 Sep 2003 16:44:51 +0000 Subject: [PATCH] preliminary 'global cursor' stuff git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7784 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.C | 3 +- src/BufferView_pimpl.C | 7 ++-- src/Makefile.am | 2 ++ src/bufferview_funcs.C | 10 ++++-- src/cursor.C | 78 ++++++++++++++++++++++++++++++++++++++++++ src/cursor.h | 62 +++++++++++++++++++++++++++++++++ src/lyxfunc.C | 13 +++++++ 7 files changed, 169 insertions(+), 6 deletions(-) create mode 100644 src/cursor.C create mode 100644 src/cursor.h diff --git a/src/BufferView.C b/src/BufferView.C index 8bcd2fb324..54d25dbb15 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -492,7 +492,8 @@ int BufferView::unlockInset(UpdatableInset * inset) dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE)); finishUndo(); return 0; - } else if (inset && theLockingInset() && + } + if (inset && theLockingInset() && theLockingInset()->unlockInsetInInset(this, inset)) { // Tell the paragraph dialog that we changed paragraph dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE)); diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 22a9cd4b77..c1e05f05ce 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -23,6 +23,7 @@ #include "buffer_funcs.h" #include "bufferlist.h" #include "bufferparams.h" +#include "cursor.h" #include "debug.h" #include "factory.h" #include "FloatList.h" @@ -456,8 +457,8 @@ void BufferView::Pimpl::resizeCurrentBuffer() } #warning does not help much - bv_->text->redoParagraphs(bv_->text->ownerParagraphs().begin(), - bv_->text->ownerParagraphs().end()); + //bv_->text->redoParagraphs(bv_->text->ownerParagraphs().begin(), + // bv_->text->ownerParagraphs().end()); if (par != bv_->text->ownerParagraphs().end()) { bv_->text->selection.set(true); @@ -1323,7 +1324,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in) ev.errorMessage(N_("Unknown function!")); break; - default: + default: return bv_->getLyXText()->dispatch(FuncRequest(ev, bv_)); } // end of switch diff --git a/src/Makefile.am b/src/Makefile.am index 045dd3a3db..aba9d4ea53 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -137,6 +137,8 @@ lyx_SOURCES = \ converter.h \ counters.C \ counters.h \ + cursor.C \ + cursor.h \ debug.C \ debug.h \ dimension.C \ diff --git a/src/bufferview_funcs.C b/src/bufferview_funcs.C index 7945e4fbc2..0d56ad2f6d 100644 --- a/src/bufferview_funcs.C +++ b/src/bufferview_funcs.C @@ -368,8 +368,14 @@ string const currentState(BufferView * bv) state << _(", Position: ") << text->cursor.pos(); RowList::iterator rit = text->cursorRow(); state << bformat(_(", Row b:%1$d e:%2$d"), rit->pos(), rit->end()); - state << _(", Inset: ") << - (text->cursor.par()->inInset() ? text->cursor.par()->inInset()->id() : -1); + state << _(", Inset: "); + InsetOld * inset = text->cursor.par()->inInset(); + if (inset) + state << inset << " id: " << inset->id() + << " text: " << inset->getLyXText(bv, true) + << " owner: " << inset->owner(); + else + state << -1; #endif return state.str(); } diff --git a/src/cursor.C b/src/cursor.C new file mode 100644 index 0000000000..0e1d34b17e --- /dev/null +++ b/src/cursor.C @@ -0,0 +1,78 @@ +/** + * \file cursor.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Jürgen Vigna + * + * Full author contact details are available in file CREDITS. + */ + +#include + +#include "buffer.h" +#include "BufferView.h" +#include "cursor.h" +#include "debug.h" +#include "iterators.h" +#include "lyxtext.h" +#include "paragraph.h" + +#include "insets/updatableinset.h" + +using std::vector; + + +dispatch_result Cursor::dispatch(FuncRequest const &) +{ + for (int i = data_.size() - 1; i >= 0; --i) { + lyxerr << "trying to dispatch to " << data_[i].text_ << std::endl; + } + return UNDISPATCHED; +} + + +void buildCursor(Cursor & cursor, BufferView & bv) +{ + UpdatableInset * inset = bv.theLockingInset(); + lyxerr << "\nbuildCursor: " << inset << std::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; + } + + if (!ok) { + lyxerr << " tli not found! inset: " << inset << std::endl; + return; + } + + vector pits; + vector plists; + vector texts; +/* + pit.getPits(pits, plists, texts); + + cursor.data_.resize(pits.size()); + for (size_t i = 0, n = pits.size(); i != n; ++i) { + cursor.data_[i].text_ = texts[i]; + cursor.data_[i].pit_ = pits[i]; + //cursor.data_[i].pos_ = texts[i]->cursor.pos(); + cursor.data_[i].pos_ = 0; + lyxerr << " text: " << cursor.data_[i].text_ + << " pit: " << cursor.data_[i].pit_->id() + << " pos: " << cursor.data_[i].pos_ + << std::endl; + } +*/ +} diff --git a/src/cursor.h b/src/cursor.h new file mode 100644 index 0000000000..bb99d96b62 --- /dev/null +++ b/src/cursor.h @@ -0,0 +1,62 @@ +// -*- C++ -*- +/** + * \file cursor.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author André Pönitz + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef CURSOR_H +#define CURSOR_H + +#include "ParagraphList_fwd.h" +#include "textcursor.h" + +#include "support/types.h" + +#include "insets/insetbase.h" + +#include + +class LyXText; + + +/** + * The cursor class describes the position of a cursor within a document. + */ + +class CursorItem : public TextCursor { +public: + /// + CursorItem() : text_(0) {} +public: + /// + LyXText * text_; + /// + ParagraphList::iterator pit_; + /// + int pos_; +}; + + +class Cursor { +public: + /// + Cursor() {} + /// + dispatch_result dispatch(FuncRequest const & cmd); +public: + /// mainly used as stack, bnut wee need random access + std::vector data_; +}; + +/// 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/lyxfunc.C b/src/lyxfunc.C index 13a9d2d8ee..43b1d9010e 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -27,6 +27,7 @@ #include "bufferlist.h" #include "bufferparams.h" #include "BufferView.h" +#include "cursor.h" #include "debug.h" #include "encoding.h" #include "exporter.h" @@ -891,6 +892,18 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose) if (view()->available()) view()->hideCursor(); +#if 1 + { + Cursor cursor; + buildCursor(cursor, *view()); + if (cursor.dispatch(FuncRequest(ev, view())) == DISPATCHED) { + lyxerr << "dispatched by Cursor::dispatch()\n"; + goto exit_with_message; + } + } +#endif + + if (view()->available() && view()->theLockingInset()) { InsetOld::RESULT result; if (action > 1 || (action == LFUN_UNKNOWN_ACTION && -- 2.39.2