Exemplo n.º 1
0
bool ZLTextView::search(const std::string &text, bool ignoreCase, bool wholeText, bool backward, bool thisSectionOnly) {
    if (text.empty()) {
        return false;
    }

    size_t startIndex = 0;
    size_t endIndex = myModel->paragraphsNumber();
    if (thisSectionOnly) {
        std::vector<size_t>::const_iterator i = nextBreakIterator();
        if (i != myTextBreaks.begin()) {
            startIndex = *(i - 1);
        }
        if (i != myTextBreaks.end()) {
            endIndex = *i;
        }
    }

    myModel->search(text, startIndex, endIndex, ignoreCase);
    if (!startCursor().isNull()) {
        rebuildPaintInfo(true);
        ZLTextMark position = startCursor().position();
        gotoMark(wholeText ?
                 (backward ? myModel->lastMark() : myModel->firstMark()) :
                 (backward ? myModel->previousMark(position) : //myModel->nextMark(position)));
                  myModel->nextMark(position).ParagraphIndex > -1 ? myModel->nextMark(position) : myModel->previousMark(position)));
        application().refreshWindow();
    }

    if(myModel->marks().empty())
        return false;
    else
        return true;
}
Exemplo n.º 2
0
void ZLTextView::search(const std::string &text, bool ignoreCase, bool wholeText, bool backward, bool thisSectionOnly) {
	shared_ptr<ZLTextModel> model = textArea().model();
	if (model.isNull() || text.empty()) {
		return;
	}

	size_t startIndex = 0;
	size_t endIndex = model->paragraphsNumber();
	if (thisSectionOnly) {
		std::vector<size_t>::const_iterator i = nextBreakIterator();
		if (i != myTextBreaks.begin()) {
			startIndex = *(i - 1);
		}
		if (i != myTextBreaks.end()) {
			endIndex = *i;
		}
	}

	model->search(text, startIndex, endIndex, ignoreCase);
	const ZLTextWordCursor &startCursor = textArea().startCursor();
	if (!startCursor.isNull()) {
		myTextAreaController.rebuildPaintInfo(true);
		ZLTextMark position = startCursor.position();
		gotoMark(wholeText ?
							(backward ? model->lastMark() : model->firstMark()) :
							(backward ? model->previousMark(position) : model->nextMark(position)));
		ZLApplication::Instance().refreshWindow();
	}
}
Exemplo n.º 3
0
size_t ZLTextView::pageNumber() const {
    if (empty()) {
        return 0;
    }
    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();
    return (myTextSize[endIndex] - myTextSize[startIndex]) / 2048 + 1;
}
Exemplo n.º 4
0
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);
			}
		}
	}
}
Exemplo n.º 5
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();
}
Exemplo n.º 6
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();
}
Exemplo n.º 7
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();
}
Exemplo n.º 8
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();
}
Exemplo n.º 9
0
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);
            }
        }
    }
}