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);
			}
		}
	}
}
Exemple #3
0
void ZLTextView::gotoPosition(int paragraphIndex, int elementIndex, int charIndex) {
    gotoParagraph(paragraphIndex, false);
    if (!myStartCursor.isNull() &&
            ((int)myStartCursor.paragraphCursor().index() == paragraphIndex)) {
        moveStartCursor(paragraphIndex, elementIndex, charIndex);
    }
}
void ZLTextView::gotoPosition(int paragraphNumber, int wordNumber, int charNumber) {
    gotoParagraph(paragraphNumber, false);
    if (!myStartCursor.isNull() &&
            ((int)myStartCursor.paragraphCursor().index() == paragraphNumber)) {
        moveStartCursor(paragraphNumber, wordNumber, charNumber);
    }
}
void ContentsView::gotoReference() {
	model()->removeAllMarks();
	const size_t selected = currentTextViewParagraph();
	highlightParagraph(selected);
	gotoParagraph(selected);
	scrollPage(false, ZLTextView::SCROLL_PERCENTAGE, 40);
}
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();
	}
}
Exemple #7
0
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::gotoPosition(int paragraphIndex, int elementIndex, int charIndex) {
	gotoParagraph(paragraphIndex, false);
	const ZLTextWordCursor &startCursor = textArea().startCursor();
	if (!startCursor.isNull() && 
			((int)startCursor.paragraphCursor().index() == paragraphIndex)) {
		myTextAreaController.moveStartCursor(paragraphIndex, elementIndex, charIndex);
	}
}
void BookTextView::scrollToHome() {
	if (!startCursor().isNull() &&
			startCursor().isStartOfParagraph() &&
			startCursor().paragraphCursor().index() == 0) {
		return;
	}

	gotoParagraph(0, false);
	fbreader().refreshWindow();
}
Exemple #10
0
void BookTextView::scrollToHome() {
	if (!textArea().startCursor().isNull() &&
			textArea().startCursor().isStartOfParagraph() &&
			textArea().startCursor().paragraphCursor().index() == 0) {
		return;
	}

	gotoParagraph(0, false);
	FBReader::Instance().refreshWindow();
}
Exemple #11
0
void ZLTextView::scrollToEndOfText() {
    if (endCursor().isNull() || myModel.isNull()) {
        return;
    }

    if (endCursor().isEndOfParagraph() &&
            endCursor().paragraphCursor().isLast()) {
        return;
    }

    std::vector<size_t>::const_iterator i = nextBreakIterator();
    if (i == myTextBreaks.end()) {
        gotoParagraph(myModel->paragraphsNumber(), true);
        myEndCursor.nextParagraph();
    } else {
        gotoParagraph(*i - 1, true);
    }
    myEndCursor.moveToParagraphEnd();
    application().refreshWindow();
}
Exemple #12
0
void ZLTextView::scrollToEndOfText() {
	shared_ptr<ZLTextModel> model = textArea().model();
	if (textArea().endCursor().isNull() || model.isNull()) {
		return;
	}

	if (textArea().endCursor().isEndOfParagraph() &&
			textArea().endCursor().paragraphCursor().isLast()) {
		return;
	}

	std::vector<size_t>::const_iterator i = nextBreakIterator();
	if (i == myTextBreaks.end()) {
		gotoParagraph(model->paragraphsNumber(), true);
		myTextAreaController.area().myEndCursor.nextParagraph();
	} else {
		gotoParagraph(*i - 1, true);
	}
	myTextAreaController.area().myEndCursor.moveToParagraphEnd();
	ZLApplication::Instance().refreshWindow();
}
Exemple #13
0
void ZLTextView::scrollToStartOfText() {
    if (endCursor().isNull()) {
        return;
    }

    if (!startCursor().isNull() &&
            startCursor().isStartOfParagraph() &&
            startCursor().paragraphCursor().isFirst()) {
        return;
    }

    std::vector<size_t>::const_iterator i = nextBreakIterator();
    gotoParagraph((i != myTextBreaks.begin()) ? *(i - 1) : 0, false);
    application().refreshWindow();
}
Exemple #14
0
void ZLTextView::scrollToStartOfText() {
	if (textArea().endCursor().isNull()) {
		return;
	}

	const ZLTextWordCursor &startCursor = textArea().startCursor();
	if (!startCursor.isNull() &&
			startCursor.isStartOfParagraph() &&
			startCursor.paragraphCursor().isFirst()) {
		return;
	}

	std::vector<size_t>::const_iterator i = nextBreakIterator();
	gotoParagraph((i != myTextBreaks.begin()) ? *(i - 1) : 0, false);
	ZLApplication::Instance().refreshWindow();
}
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 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);
            }
        }
    }
}
Exemple #17
0
void CollectionView::removeBook(BookDescriptionPtr book) {
	if (book.isNull()) {
		return;
	}

	if (book == mySelectedBook) {
		mySelectedBook = 0;
	}

	CollectionModel &cModel = collectionModel();

	ZLResourceKey boxKey("removeBookBox");
	const std::string message =
		ZLStringUtil::printf(ZLDialogManager::dialogMessage(boxKey), book->title());
	if (ZLDialogManager::instance().questionBox(boxKey, message,
		ZLDialogManager::YES_BUTTON, ZLDialogManager::NO_BUTTON) == 0) {
		cModel.removeAllMarks();
		BookList().removeFileName(book->fileName());
		
		cModel.removeBook(book);
		if (cModel.paragraphsNumber() == 0) {
			setStartCursor(0);
		} else {
			size_t index = startCursor().paragraphCursor().index();
			if (index >= cModel.paragraphsNumber()) {
				index = cModel.paragraphsNumber() - 1;
			}
			while (!((ZLTextTreeParagraph*)cModel[index])->parent()->isOpen()) {
				--index;
			}
			gotoParagraph(index);
		}
		rebuildPaintInfo(true);
		selectBook(mySelectedBook);
		application().refreshWindow();
		myCollection.rebuild(false);
	}
}
Exemple #18
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);
		}
	}
}
Exemple #19
0
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;
}