bool ZLTextAreaController::preparePaintInfo() {
	if ((myPaintState == NOTHING_TO_PAINT) || (myPaintState == READY)) {
		return false;
	}

            myArea.myLineInfoCache.insert(myArea.myLineInfos.begin(), myArea.myLineInfos.end());



	switch (myPaintState) {
		default:
			break;
		case TO_SCROLL_FORWARD:
			if (!myArea.myEndCursor.paragraphCursor().isLast() ||
					!myArea.myEndCursor.isEndOfParagraph()) {
				ZLTextWordCursor startCursor;
				switch (myScrollingMode) {
					case NO_OVERLAPPING:
						break;
					case KEEP_LINES:
						startCursor = findLineFromEnd(myOverlappingValue);
						break;
					case SCROLL_LINES:
						startCursor = findLineFromStart(myOverlappingValue);
						if (startCursor.isEndOfParagraph()) {
							startCursor.nextParagraph();
						}
						break;
					case SCROLL_PERCENTAGE:
						startCursor = findPercentFromStart(myOverlappingValue);
						break;
				}

				if (!startCursor.isNull() && (startCursor == myArea.myStartCursor)) {

					startCursor = findLineFromStart(1);

				}

				if (!startCursor.isNull()) {

					ZLTextWordCursor endCursor = buildInfos(startCursor);


					if (!visiblePageIsEmpty() && ((myScrollingMode != KEEP_LINES) || (endCursor != myArea.myEndCursor))) {

                                                    myArea.myStartCursor = startCursor;
                                                    myArea.myEndCursor = endCursor;

						break;
					}

				}

                                    myArea.myStartCursor = myArea.myEndCursor;
                                    myArea.myEndCursor = buildInfos(myArea.myStartCursor);

			}
			break;
		case TO_SCROLL_BACKWARD:
			if (!myArea.myStartCursor.paragraphCursor().isFirst() || !myArea.myStartCursor.isStartOfParagraph()) {
				switch (myScrollingMode) {
					case NO_OVERLAPPING:
						myArea.myStartCursor = findStart(myArea.myStartCursor, PIXEL_UNIT, myArea.height());
						break;
					case KEEP_LINES:
					{
						ZLTextWordCursor endCursor = findLineFromStart(myOverlappingValue);
						if (!endCursor.isNull() && (endCursor == myArea.myEndCursor)) {
							endCursor = findLineFromEnd(1);
						}
						if (!endCursor.isNull()) {
							ZLTextWordCursor startCursor = findStart(endCursor, PIXEL_UNIT, myArea.height());
							myArea.myStartCursor =
								(startCursor != myArea.myStartCursor) ?
									startCursor : findStart(myArea.myStartCursor, PIXEL_UNIT, myArea.height());
						} else {
							myArea.myStartCursor = findStart(myArea.myStartCursor, PIXEL_UNIT, myArea.height());
						}
						break;
					}
					case SCROLL_LINES:
						myArea.myStartCursor = findStart(myArea.myStartCursor, LINE_UNIT, myOverlappingValue);
						break;
					case SCROLL_PERCENTAGE:
						myArea.myStartCursor =
							findStart(myArea.myStartCursor, PIXEL_UNIT, myArea.height() * myOverlappingValue / 100);
						break;
				}
				myArea.myEndCursor = buildInfos(myArea.myStartCursor);
				if (visiblePageIsEmpty()) {
					myArea.myStartCursor = findStart(myArea.myStartCursor, LINE_UNIT, 1);
					myArea.myEndCursor = buildInfos(myArea.myStartCursor);
				}
			}
			break;
		case START_IS_KNOWN:
			myArea.myEndCursor = buildInfos(myArea.myStartCursor);
			if (visiblePageIsEmpty()) {
				ZLTextWordCursor startCursor = findLineFromStart(1);
				if (!startCursor.isNull()) {
					myArea.myStartCursor = startCursor;
					if (myArea.myStartCursor.isEndOfParagraph()) {
						myArea.myStartCursor.nextParagraph();
					}
					myArea.myEndCursor = buildInfos(myArea.myStartCursor);
				}
			}
			break;
		case END_IS_KNOWN:
			myArea.myStartCursor = findStart(myArea.myEndCursor, PIXEL_UNIT, myArea.height());
			myArea.myEndCursor = buildInfos(myArea.myStartCursor);
			break;
	}

        myPaintState = READY;
        myArea.myLineInfoCache.clear();
	return true;
}
Exemplo n.º 2
0
void TextView::preparePaintInfo() {
  context().setLeftMargin(TextStyleCollection::instance().baseStyle().LeftMarginOption.value());
  context().setRightMargin(TextStyleCollection::instance().baseStyle().RightMarginOption.value());
  context().setTopMargin(TextStyleCollection::instance().baseStyle().TopMarginOption.value());
  context().setBottomMargin(TextStyleCollection::instance().baseStyle().BottomMarginOption.value());

  int newWidth = context().width();
  int newHeight = myStyle.textAreaHeight();
  if ((newWidth != myOldWidth) || (newHeight != myOldHeight)) {
    myOldWidth = newWidth;
    myOldHeight = newHeight;
    rebuildPaintInfo(false);
  }

  if ((myPaintState == NOTHING_TO_PAINT) || (myPaintState == READY)) {
    return;
  }

  myLineInfoCache.insert(myLineInfos.begin(), myLineInfos.end());

  switch (myPaintState) {
    default:
      break;
    case TO_SCROLL_FORWARD:
      if (!myEndCursor.paragraphCursor().isLast() || !myEndCursor.isEndOfParagraph()) {
        WordCursor startCursor;
        switch (myScrollingMode) {
          case NO_OVERLAPPING:
            break;
          case KEEP_LINES:
            startCursor = findLineFromEnd(myOverlappingValue);
            break;
          case SCROLL_LINES:
            startCursor = findLineFromStart(myOverlappingValue);
            break;
          case SCROLL_PERCENTAGE:
            startCursor = findPercentFromStart(myOverlappingValue);
            break;
        }
      
        if (!startCursor.isNull() && (startCursor == myStartCursor)) {
          startCursor = findLineFromStart(1);
        }

        if (!startCursor.isNull()) {
          WordCursor endCursor = buildInfos(startCursor);
          if (!pageIsEmpty() && ((myScrollingMode != KEEP_LINES) || (endCursor != myEndCursor))) {
            myStartCursor = startCursor;
            myEndCursor = endCursor;
            break;
          }
        }
        myStartCursor = myEndCursor;
        myEndCursor = buildInfos(myStartCursor);
      }
      break;
    case TO_SCROLL_BACKWARD:
      if (!myStartCursor.paragraphCursor().isFirst() || !myStartCursor.isStartOfParagraph()) {
        switch (myScrollingMode) {
          case NO_OVERLAPPING:
            myStartCursor = findStart(myStartCursor, PIXEL_UNIT, myStyle.textAreaHeight());
            break;
          case KEEP_LINES:
          {
            WordCursor endCursor = findLineFromStart(myOverlappingValue);
            if (!endCursor.isNull() && (endCursor == myEndCursor)) {
              endCursor = findLineFromEnd(1);
            }
            if (!endCursor.isNull()) {
              WordCursor startCursor = findStart(endCursor, PIXEL_UNIT, myStyle.textAreaHeight());
              myStartCursor =
                (startCursor != myStartCursor) ?
                  startCursor : findStart(myStartCursor, PIXEL_UNIT, myStyle.textAreaHeight());
            } else {
              myStartCursor = findStart(myStartCursor, PIXEL_UNIT, myStyle.textAreaHeight());
            }
            break;
          }
          case SCROLL_LINES:
            myStartCursor = findStart(myStartCursor, LINE_UNIT, myOverlappingValue);
            break;
          case SCROLL_PERCENTAGE:
            myStartCursor =
              findStart(myStartCursor, PIXEL_UNIT, myStyle.textAreaHeight() * myOverlappingValue / 100);
            break;
        }
        myEndCursor = buildInfos(myStartCursor);
      }
      break;
    case START_IS_KNOWN:
      myEndCursor = buildInfos(myStartCursor);
      break;
    case END_IS_KNOWN:
      myStartCursor = findStart(myEndCursor, PIXEL_UNIT, myStyle.textAreaHeight());
      myEndCursor = buildInfos(myStartCursor);
      break;
  }
  myPaintState = READY;
  myLineInfoCache.clear();
}