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::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 ZLTextView::onStylusPress(int x, int y) { mySelectionModel.deactivate(); if (myModel.isNull()) { return false; } shared_ptr<ZLTextPositionIndicatorInfo> indicatorInfo = this->indicatorInfo(); if (!indicatorInfo.isNull() && indicatorInfo->isVisible() && indicatorInfo->isSensitive()) { myTreeStateIsFrozen = true; bool indicatorAnswer = positionIndicator()->onStylusPress(x, y); myTreeStateIsFrozen = false; if (indicatorAnswer) { application().refreshWindow(); return true; } } if (myModel->kind() == ZLTextModel::TREE_MODEL) { ZLTextTreeNodeMap::const_iterator it = std::find_if(myTreeNodeMap.begin(), myTreeNodeMap.end(), ZLTextTreeNodeArea::RangeChecker(x, y)); if (it != myTreeNodeMap.end()) { int paragraphNumber = it->ParagraphNumber; ZLTextTreeParagraph *paragraph = (ZLTextTreeParagraph*)(*myModel)[paragraphNumber]; paragraph->open(!paragraph->isOpen()); rebuildPaintInfo(true); preparePaintInfo(); if (paragraph->isOpen()) { int nextParagraphNumber = paragraphNumber + paragraph->fullSize(); int lastParagraphNumber = endCursor().paragraphCursor().index(); if (endCursor().isEndOfParagraph()) { ++lastParagraphNumber; } if (lastParagraphNumber < nextParagraphNumber) { gotoParagraph(nextParagraphNumber, true); preparePaintInfo(); } } int firstParagraphNumber = startCursor().paragraphCursor().index(); if (startCursor().isStartOfParagraph()) { --firstParagraphNumber; } if (firstParagraphNumber >= paragraphNumber) { gotoParagraph(paragraphNumber); preparePaintInfo(); } application().refreshWindow(); return true; } } return false; }
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); } } } }
const BooksPos BooksTextView::rewind() { SUPER::gotoPosition(0, 0, 0); preparePaintInfo(); if (!textArea().isVisible()) nextPage(); return position(); }
void ZLTextAreaController::rebuildPaintInfo(bool strong) { if (myPaintState == NOTHING_TO_PAINT) { return; } if ((myPaintState == TO_SCROLL_FORWARD) || (myPaintState == TO_SCROLL_BACKWARD)) { preparePaintInfo(); } myArea.myLineInfos.clear(); if (strong) { ZLTextParagraphCursorCache::clear(); myArea.myLineInfoCache.clear(); } if (!myArea.myStartCursor.isNull()) { if (strong) { myArea.myStartCursor.rebuild(); } myArea.myEndCursor = 0; myPaintState = START_IS_KNOWN; } else if (!myArea.myEndCursor.isNull()) { if (strong) { myArea.myEndCursor.rebuild(); } myPaintState = END_IS_KNOWN; } }
void ZLTextView::onScrollbarMoved(Direction direction, size_t full, size_t from, size_t to) { if (direction != VERTICAL) { return; } mySelectionModel.deactivate(); if (myModel.isNull()) { return; } if (startCursor().isNull() || endCursor().isNull()) { return; } myTreeStateIsFrozen = true; if (from == 0) { scrollToStartOfText(); } else if (to == full) { scrollToEndOfText(); } else { gotoCharIndex(to); } preparePaintInfo(); myTreeStateIsFrozen = false; myDoUpdateScrollbar = false; application().refreshWindow(); }
void ZLTextView::scrollPage(bool forward, ScrollingMode mode, unsigned int value) { preparePaintInfo(); if (myPaintState == READY) { myPaintState = forward ? TO_SCROLL_FORWARD : TO_SCROLL_BACKWARD; myScrollingMode = mode; myOverlappingValue = value; } }
void ContentsView::gotoReference() { textArea().model()->removeAllMarks(); const size_t selected = currentTextViewParagraph(); highlightParagraph(selected); preparePaintInfo(); gotoParagraph(selected); scrollPage(false, ZLTextAreaController::SCROLL_PERCENTAGE, 40); }
void ZLTextView::paint() { preparePaintInfo(); myTextElementMap.clear(); myTreeNodeMap.clear(); context().clear(ZLTextStyleCollection::instance().baseStyle().BackgroundColorOption.value()); if (empty()) { return; } std::vector<size_t> labels; labels.reserve(myLineInfos.size() + 1); labels.push_back(0); int y = topMargin(); for (std::vector<ZLTextLineInfoPtr>::const_iterator it = myLineInfos.begin(); it != myLineInfos.end(); ++it) { const ZLTextLineInfo &info = **it; prepareTextLine(info, y); y += info.Height + info.Descent + info.VSpaceAfter; labels.push_back(myTextElementMap.size()); } mySelectionModel.update(); y = topMargin(); int index = 0; for (std::vector<ZLTextLineInfoPtr>::const_iterator it = myLineInfos.begin(); it != myLineInfos.end(); ++it) { const ZLTextLineInfo &info = **it; drawTextLine(info, y, labels[index], labels[index + 1]); y += info.Height + info.Descent + info.VSpaceAfter; ++index; } fb::shared_ptr<ZLTextPositionIndicatorInfo> indicatorInfo = this->indicatorInfo(); if (!indicatorInfo.isNull() && (indicatorInfo->type() == ZLTextPositionIndicatorInfo::FB_INDICATOR)) { positionIndicator()->draw(); } if (myDoUpdateScrollbar && !indicatorInfo.isNull()) { myDoUpdateScrollbar = false; const size_t full = positionIndicator()->sizeOfTextBeforeParagraph(positionIndicator()->endTextIndex()); const size_t from = positionIndicator()->sizeOfTextBeforeCursor(startCursor()); const size_t to = positionIndicator()->sizeOfTextBeforeCursor(endCursor()); bool showScrollbar = (indicatorInfo->type() == ZLTextPositionIndicatorInfo::OS_SCROLLBAR) && (to - from < full); if (showScrollbar) { setScrollbarEnabled(VERTICAL, true); setScrollbarParameters(VERTICAL, full, from, to); } else { setScrollbarEnabled(VERTICAL, false); } } ZLTextParagraphCursorCache::cleanup(); }
void ZLTextView::paint() { context().clear(backgroundColor()); // PB // myTextAreaController.area().setOffsets( // textArea().isRtl() ? rightMargin() : leftMargin(), topMargin() // ); myTextAreaController.area().setOffsets(0, 0); // if (!) preparePaintInfo(); ////<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<, if (textArea().isEmpty()) { return; } if (!ZLNXPaintContext::lock_drawing) myTextAreaController.area().paint(); /////<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< shared_ptr<ZLTextPositionIndicatorInfo> indicatorInfo = this->indicatorInfo(); if (!indicatorInfo.isNull() && (indicatorInfo->type() == ZLTextPositionIndicatorInfo::FB_INDICATOR)) { positionIndicator()->draw(); } if (myDoUpdateScrollbar && !indicatorInfo.isNull()) { myDoUpdateScrollbar = false; const size_t full = positionIndicator()->sizeOfTextBeforeParagraph(positionIndicator()->endTextIndex()); const size_t from = positionIndicator()->sizeOfTextBeforeCursor(textArea().startCursor()); const size_t to = positionIndicator()->sizeOfTextBeforeCursor(textArea().endCursor()); bool showScrollbar = (indicatorInfo->type() == ZLTextPositionIndicatorInfo::OS_SCROLLBAR) && (to - from < full); if (showScrollbar) { setScrollbarEnabled(VERTICAL, true); setScrollbarParameters(VERTICAL, full, from, to); } else { setScrollbarEnabled(VERTICAL, false); } } ZLTextParagraphCursorCache::cleanup(); }
void ZLTextView::paint() { context().clear(backgroundColor()); myTextAreaController.area().setOffsets( textArea().isRtl() ? rightMargin() : leftMargin(), topMargin() + headerHeight() ); preparePaintInfo(); if (textArea().isEmpty()) { return; } myTextAreaController.area().paint(); shared_ptr<ZLTextPositionIndicatorInfo> indicatorInfo = this->indicatorInfo(); if (!indicatorInfo.isNull()) { switch (indicatorInfo->type()) { default: break; case ZLTextPositionIndicatorInfo::PAGE_FOOTER: positionIndicator()->draw(); break; case ZLTextPositionIndicatorInfo::PAGE_HEADER: paintHeader(); break; } } if (myDoUpdateScrollbar && !indicatorInfo.isNull()) { myDoUpdateScrollbar = false; const std::size_t full = sizeOfTextBeforeParagraph(endTextIndex()); const std::size_t from = sizeOfTextBeforeCursor(textArea().startCursor()); const std::size_t to = sizeOfTextBeforeCursor(textArea().endCursor()); bool showScrollbar = (indicatorInfo->type() == ZLTextPositionIndicatorInfo::OS_SCROLLBAR) && (to - from < full); if (showScrollbar) { setScrollbarEnabled(VERTICAL, true); setScrollbarParameters(VERTICAL, full, from, to); } else { setScrollbarEnabled(VERTICAL, false); } } ZLTextParagraphCursorCache::cleanup(); }
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 ZLTextView::gotoPage(size_t index) { const size_t symbolIndex = index * 2048 - 128; std::vector<size_t>::const_iterator it = std::lower_bound(myTextSize.begin(), myTextSize.end(), symbolIndex); std::vector<size_t>::const_iterator i = nextBreakIterator(); const size_t startIndex = (i != myTextBreaks.begin()) ? *(i - 1) : 0; const size_t endIndex = (i != myTextBreaks.end()) ? *i : myModel->paragraphsNumber(); size_t paragraphNumber = std::min((size_t)(it - myTextSize.begin()), endIndex) - 1; gotoParagraph(paragraphNumber, true); preparePaintInfo(); const ZLTextWordCursor &cursor = endCursor(); if (!cursor.isNull() && (paragraphNumber == cursor.paragraphCursor().index())) { if (!cursor.paragraphCursor().isLast() || !cursor.isEndOfParagraph()) { size_t paragraphLength = cursor.paragraphCursor().paragraphLength(); if (paragraphLength > 0) { size_t wordNum = (myTextSize[startIndex] + symbolIndex - myTextSize[paragraphNumber]) * paragraphLength / (myTextSize[endIndex] - myTextSize[startIndex]); moveEndCursor(cursor.paragraphCursor().index(), wordNum, 0); } } } }
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(); }
bool ZLTextView::onStylusPress(int x, int y) { AppLog("ZLTextView::onStylusPress 1"); stopSelectionScrolling(); myDoubleClickInfo.update(x, y, true); if (myDoubleClickInfo.Count > 10) { return true; } myTextAreaController.area().selectionModel().deactivate(); shared_ptr<ZLTextModel> model = textArea().model(); if (model.isNull()) { return false; } AppLog("ZLTextView::onStylusPress 2"); shared_ptr<ZLTextPositionIndicatorInfo> indicatorInfo = this->indicatorInfo(); if (!indicatorInfo.isNull() && (indicatorInfo->type() == ZLTextPositionIndicatorInfo::FB_INDICATOR) && indicatorInfo->isSensitive()) { myTreeStateIsFrozen = true; bool indicatorAnswer = positionIndicator()->onStylusPress(x, y); myTreeStateIsFrozen = false; if (indicatorAnswer) { ZLApplication::Instance().refreshWindow(); return true; } } AppLog("ZLTextView::onStylusPress 3"); if (model->kind() == ZLTextModel::TREE_MODEL) { const ZLTextTreeNodeRectangle *node = textArea().treeNodeByCoordinates(x, y); if (node != 0) { int paragraphIndex = node->ParagraphIndex; ZLTextTreeParagraph *paragraph = (ZLTextTreeParagraph*)(*model)[paragraphIndex]; paragraph->open(!paragraph->isOpen()); myTextAreaController.rebuildPaintInfo(true); preparePaintInfo(); if (paragraph->isOpen()) { int nextParagraphIndex = paragraphIndex + paragraph->fullSize(); int lastParagraphIndex = textArea().endCursor().paragraphCursor().index(); if (textArea().endCursor().isEndOfParagraph()) { ++lastParagraphIndex; } if (lastParagraphIndex < nextParagraphIndex) { gotoParagraph(nextParagraphIndex, true); preparePaintInfo(); } } const ZLTextWordCursor &startCursor = textArea().startCursor(); int firstParagraphIndex = startCursor.paragraphCursor().index(); if (startCursor.isStartOfParagraph()) { --firstParagraphIndex; } if (firstParagraphIndex >= paragraphIndex) { gotoParagraph(paragraphIndex); preparePaintInfo(); } ZLApplication::Instance().refreshWindow(); AppLog("ZLTextView::onStylusPress 4"); return true; } } AppLog("ZLTextView::onStylusPress 5"); return false; }
void ZLTextView::scrollPage(bool forward, ZLTextAreaController::ScrollingMode mode, unsigned int value) { preparePaintInfo(); myTextAreaController.scrollPage(forward, mode, value); }