From bd03eaa571bc3ad21e3e5f6d69d748b78ab1ed10 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Sat, 29 Sep 2007 07:34:42 +0000 Subject: [PATCH] make some bufferview related stuff more local git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20576 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.cpp | 106 +++++++++++++++++++++++++++++++++++---- src/bufferview_funcs.cpp | 85 +------------------------------ src/bufferview_funcs.h | 15 ------ 3 files changed, 96 insertions(+), 110 deletions(-) diff --git a/src/BufferView.cpp b/src/BufferView.cpp index fd503fbffb..77c53e507a 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -109,17 +109,101 @@ namespace { /// Return an inset of this class if it exists at the current cursor position template -T * getInsetByCode(Cursor & cur, Inset::Code code) +T * getInsetByCode(Cursor const & cur, Inset::Code code) { - T * inset = 0; DocIterator it = cur; - if (it.nextInset() && - it.nextInset()->lyxCode() == code) { - inset = static_cast(it.nextInset()); + Inset * inset = it.nextInset(); + if (inset && inset->lyxCode() == code) + return static_cast(inset); + return 0; +} + + +bool findInset(DocIterator & dit, vector const & codes, + bool same_content); + +bool findNextInset(DocIterator & dit, vector const & codes, + string const & contents) +{ + DocIterator tmpdit = dit; + + while (tmpdit) { + Inset const * inset = tmpdit.nextInset(); + if (inset + && find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() + && (contents.empty() || + static_cast(inset)->getContents() == contents)) { + dit = tmpdit; + return true; + } + tmpdit.forwardInset(); } - return inset; + + return false; +} + + +/// Looks for next inset with one of the the given code +bool findInset(DocIterator & dit, vector const & codes, + bool same_content) +{ + string contents; + DocIterator tmpdit = dit; + tmpdit.forwardInset(); + if (!tmpdit) + return false; + + if (same_content) { + Inset const * inset = tmpdit.nextInset(); + if (inset + && find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end()) { + contents = static_cast(inset)->getContents(); + } + } + + if (!findNextInset(tmpdit, codes, contents)) { + if (dit.depth() != 1 || dit.pit() != 0 || dit.pos() != 0) { + tmpdit = doc_iterator_begin(tmpdit.bottom().inset()); + if (!findNextInset(tmpdit, codes, contents)) + return false; + } else + return false; + } + + dit = tmpdit; + return true; +} + + +/// Looks for next inset with the given code +void findInset(DocIterator & dit, Inset_code code, bool same_content) +{ + findInset(dit, vector(1, code), same_content); +} + + +/// Moves cursor to the next inset with one of the given codes. +void gotoInset(BufferView * bv, vector const & codes, + bool same_content) +{ + Cursor tmpcur = bv->cursor(); + if (!findInset(tmpcur, codes, same_content)) { + bv->cursor().message(_("No more insets")); + return; + } + + tmpcur.clearSelection(); + bv->setCursor(tmpcur); } + +/// Moves cursor to the next inset with given code. +void gotoInset(BufferView * bv, Inset_code code, bool same_content) +{ + gotoInset(bv, vector(1, code), same_content); +} + + } // anon namespace @@ -756,14 +840,14 @@ Update::flags BufferView::dispatch(FuncRequest const & cmd) break; case LFUN_NOTE_NEXT: - bv_funcs::gotoInset(this, Inset::NOTE_CODE, false); + gotoInset(this, Inset::NOTE_CODE, false); break; case LFUN_REFERENCE_NEXT: { vector tmp; tmp.push_back(Inset::LABEL_CODE); tmp.push_back(Inset::REF_CODE); - bv_funcs::gotoInset(this, tmp, true); + gotoInset(this, tmp, true); break; } @@ -873,7 +957,7 @@ Update::flags BufferView::dispatch(FuncRequest const & cmd) case LFUN_BIBTEX_DATABASE_ADD: { Cursor tmpcur = cursor_; - bv_funcs::findInset(tmpcur, Inset::BIBTEX_CODE, false); + findInset(tmpcur, Inset::BIBTEX_CODE, false); InsetBibtex * inset = getInsetByCode(tmpcur, Inset::BIBTEX_CODE); if (inset) { @@ -885,7 +969,7 @@ Update::flags BufferView::dispatch(FuncRequest const & cmd) case LFUN_BIBTEX_DATABASE_DEL: { Cursor tmpcur = cursor_; - bv_funcs::findInset(tmpcur, Inset::BIBTEX_CODE, false); + findInset(tmpcur, Inset::BIBTEX_CODE, false); InsetBibtex * inset = getInsetByCode(tmpcur, Inset::BIBTEX_CODE); if (inset) { @@ -1192,7 +1276,7 @@ void BufferView::scrollDown(int offset) while (true) { std::pair last = tm.last(); int bottom_pos = last.second->position() + last.second->descent(); - if (last.first == text->paragraphs().size() - 1) { + if (last.first + 1 == int(text->paragraphs().size())) { if (bottom_pos <= height_) return; offset = min(offset, bottom_pos - height_); diff --git a/src/bufferview_funcs.cpp b/src/bufferview_funcs.cpp index 3b902f1087..6d4283bd93 100644 --- a/src/bufferview_funcs.cpp +++ b/src/bufferview_funcs.cpp @@ -261,95 +261,12 @@ CurStatus status(BufferView const * bv, DocIterator const & dit) Point const p = bv_funcs::getPos(*bv, dit, dit.boundary()); if (p.y_ < 0) return CUR_ABOVE; - else if (p.y_ > bv->workHeight()) + if (p.y_ > bv->workHeight()) return CUR_BELOW; return CUR_INSIDE; } -namespace { - -bool findNextInset(DocIterator & dit, - vector const & codes, - string const & contents) -{ - DocIterator tmpdit = dit; - - while (tmpdit) { - Inset const * inset = tmpdit.nextInset(); - if (inset - && find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() - && (contents.empty() || - static_cast(inset)->getContents() == contents)) { - dit = tmpdit; - return true; - } - tmpdit.forwardInset(); - } - - return false; -} - -} // namespace anon - - -bool findInset(DocIterator & dit, vector const & codes, - bool same_content) -{ - string contents; - DocIterator tmpdit = dit; - tmpdit.forwardInset(); - if (!tmpdit) - return false; - - if (same_content) { - Inset const * inset = tmpdit.nextInset(); - if (inset - && find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end()) { - contents = static_cast(inset)->getContents(); - } - } - - if (!findNextInset(tmpdit, codes, contents)) { - if (dit.depth() != 1 || dit.pit() != 0 || dit.pos() != 0) { - tmpdit = doc_iterator_begin(tmpdit.bottom().inset()); - if (!findNextInset(tmpdit, codes, contents)) { - return false; - } - } else - return false; - } - - dit = tmpdit; - return true; -} - - -void findInset(DocIterator & dit, Inset_code code, bool same_content) -{ - findInset(dit, vector(1, code), same_content); -} - - -void gotoInset(BufferView * bv, vector const & codes, - bool same_content) -{ - Cursor tmpcur = bv->cursor(); - if (!findInset(tmpcur, codes, same_content)) { - bv->cursor().message(_("No more insets")); - return; - } - - tmpcur.clearSelection(); - bv->setCursor(tmpcur); -} - - -void gotoInset(BufferView * bv, Inset_code code, bool same_content) -{ - gotoInset(bv, vector(1, code), same_content); -} - } // namespace bv_funcs diff --git a/src/bufferview_funcs.h b/src/bufferview_funcs.h index 161ed4a5ef..cbfd04c3af 100644 --- a/src/bufferview_funcs.h +++ b/src/bufferview_funcs.h @@ -52,21 +52,6 @@ CurStatus status(BufferView const * bv, DocIterator const & dit); Point coordOffset(BufferView const & bv, DocIterator const & dit, bool boundary); -/// Moves cursor to the next inset with one of the given codes. -void gotoInset(BufferView * bv, std::vector const & codes, - bool same_content); - -/// Moves cursor to the next inset with given code. -void gotoInset(BufferView * bv, Inset_code code, bool same_content); - -/// Looks for next inset with one of the the given code -bool findInset(DocIterator & dit, std::vector const & codes, - bool same_content); - -/// Looks for next inset with the given code -void findInset(DocIterator & dit, Inset_code code, bool same_content); - - } // namespace bv_funcs -- 2.39.2