void ZLTextView::gotoCharIndex(size_t charIndex) { shared_ptr<ZLTextModel> model = textArea().model(); if (model.isNull() || positionIndicator().isNull()) { return; } std::vector<size_t>::const_iterator i = nextBreakIterator(); const size_t startParagraphIndex = (i != myTextBreaks.begin()) ? *(i - 1) + 1 : 0; const size_t endParagraphIndex = (i != myTextBreaks.end()) ? *i : model->paragraphsNumber(); const size_t fullTextSize = myTextSize[endParagraphIndex] - myTextSize[startParagraphIndex]; charIndex = std::min(charIndex, fullTextSize - 1); std::vector<size_t>::const_iterator j = std::lower_bound(myTextSize.begin(), myTextSize.end(), charIndex + myTextSize[startParagraphIndex]); size_t paragraphIndex = j - myTextSize.begin(); if ((*model)[paragraphIndex]->kind() == ZLTextParagraph::END_OF_SECTION_PARAGRAPH) { gotoParagraph(paragraphIndex, true); return; } if (paragraphIndex > startParagraphIndex) { --paragraphIndex; } gotoParagraph(paragraphIndex, false); preparePaintInfo(); if (!positionIndicator().isNull()) { size_t endCharIndex = positionIndicator()->sizeOfTextBeforeCursor(textArea().endCursor()); if (endCharIndex > charIndex) { while (endCharIndex > charIndex) { scrollPage(false, ZLTextAreaController::SCROLL_LINES, 1); preparePaintInfo(); if (positionIndicator()->sizeOfTextBeforeCursor(textArea().startCursor()) <= myTextSize[startParagraphIndex]) { break; } endCharIndex = positionIndicator()->sizeOfTextBeforeCursor(textArea().endCursor()); } if (endCharIndex < charIndex) { scrollPage(true, ZLTextAreaController::SCROLL_LINES, 1); } } else { int startCharIndex = positionIndicator()->sizeOfTextBeforeCursor(textArea().startCursor()); while (endCharIndex < charIndex) { scrollPage(true, ZLTextAreaController::SCROLL_LINES, 1); preparePaintInfo(); const int newStartCharIndex = positionIndicator()->sizeOfTextBeforeCursor(textArea().startCursor()); if (newStartCharIndex <= startCharIndex) { break; } startCharIndex = newStartCharIndex; endCharIndex = positionIndicator()->sizeOfTextBeforeCursor(textArea().endCursor()); } if (endCharIndex > charIndex) { scrollPage(false, ZLTextAreaController::SCROLL_LINES, 1); } } } }
void ContentsView::gotoReference() { model()->removeAllMarks(); const size_t selected = currentTextViewParagraph(); highlightParagraph(selected); gotoParagraph(selected); scrollPage(false, ZLTextView::SCROLL_PERCENTAGE, 40); }
void ZLTextView::onScrollbarPageStep(Direction direction, int steps) { if (direction == VERTICAL) { const bool forward = steps > 0; scrollPage(forward, NO_OVERLAPPING, forward ? steps : -steps); application().refreshWindow(); } }
void ZLTextView::onScrollbarStep(Direction direction, int steps) { if (direction == VERTICAL) { const bool forward = steps > 0; scrollPage(forward, SCROLL_LINES, forward ? steps : -steps); application().refreshWindow(); } }
void ZLTextView::gotoMark(ZLTextMark mark) { if (mark.ParagraphIndex < 0) { return; } bool doRepaint = false; if (startCursor().isNull()) { doRepaint = true; preparePaintInfo(); } if (startCursor().isNull()) { return; } if (((int)startCursor().paragraphCursor().index() != mark.ParagraphIndex) || (startCursor().position() > mark)) { doRepaint = true; gotoParagraph(mark.ParagraphIndex); preparePaintInfo(); } if (endCursor().isNull()) { preparePaintInfo(); } while (mark > endCursor().position()) { doRepaint = true; scrollPage(true, NO_OVERLAPPING, 0); preparePaintInfo(); } if (doRepaint) { application().refreshWindow(); } }
void ZLTextView::onScrollbarPageStep(Direction direction, int steps) { if (direction == VERTICAL) { const bool forward = steps > 0; scrollPage(forward, ZLTextAreaController::NO_OVERLAPPING, forward ? steps : -steps); ZLApplication::Instance().refreshWindow(); } }
void ZLTextView::gotoMark(ZLTextMark mark) { if (mark.ParagraphIndex < 0) { return; } bool doRepaint = false; if (textArea().startCursor().isNull()) { doRepaint = true; preparePaintInfo(); } if (textArea().startCursor().isNull()) { return; } if (((int)textArea().startCursor().paragraphCursor().index() != mark.ParagraphIndex) || (textArea().startCursor().position() > mark)) { doRepaint = true; gotoParagraph(mark.ParagraphIndex); preparePaintInfo(); } if (textArea().endCursor().isNull()) { preparePaintInfo(); } while (mark > textArea().endCursor().position()) { doRepaint = true; scrollPage(true, ZLTextAreaController::NO_OVERLAPPING, 0); preparePaintInfo(); } if (doRepaint) { ZLApplication::Instance().refreshWindow(); } }
bool BooksTextView::nextPage() { BooksPos saved(position()); BooksPos current(saved); do { scrollPage(true, ZLTextAreaController::NO_OVERLAPPING, 1); preparePaintInfo(); const BooksPos pos = position(); if (pos == current) { gotoPosition(saved); return false; } current = pos; } while (!textArea().isVisible()); return true; }
void ContentsView::gotoReference() { const WordCursor &cursor = fbreader().bookTextView().endCursor(); if (!cursor.isNull()) { long reference = cursor.paragraphCursor().index(); size_t selected = model()->paragraphsNumber() - 1; for (size_t i = 1; i < model()->paragraphsNumber(); ++i) { if (((const ParagraphWithReference*)(*model())[i])->reference() >= reference) { selected = i - 1; break; } } selectParagraph(selected); gotoParagraph(selected); if (selected != model()->paragraphsNumber() - 1) { scrollPage(false, TextView::SCROLL_PERCENTAGE, 40); } } }
void CollectionView::selectBook(BookDescriptionPtr book) { mySelectedBook = book; if (myDoUpdateModel) { shared_ptr<ZLTextModel> oldModel = model(); setModel(0, ""); ((CollectionModel&)*oldModel).update(); setModel(oldModel, ""); myDoUpdateModel = false; } if (!book.isNull()) { collectionModel().removeAllMarks(); const std::vector<int> &toSelect = collectionModel().paragraphIndicesByBook(book); for (std::vector<int>::const_iterator it = toSelect.begin(); it != toSelect.end(); ++it) { highlightParagraph(*it); } if (!toSelect.empty()) { preparePaintInfo(); gotoParagraph(toSelect[toSelect.size() - 1]); scrollPage(false, ZLTextView::SCROLL_PERCENTAGE, 40); } } }
void FBView::scrollAndUpdatePage(bool forward, ScrollingMode mode, unsigned int value) { scrollPage(forward, mode, value); preparePaintInfo(); fbreader().refreshWindow(); }