|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2000, 2010 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2011 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
|
Lines 39-44
Link Here
|
| 39 |
import org.eclipse.swt.widgets.Composite; |
39 |
import org.eclipse.swt.widgets.Composite; |
| 40 |
import org.eclipse.swt.widgets.Control; |
40 |
import org.eclipse.swt.widgets.Control; |
| 41 |
import org.eclipse.swt.widgets.Display; |
41 |
import org.eclipse.swt.widgets.Display; |
|
|
42 |
import org.eclipse.swt.widgets.ScrollBar; |
| 42 |
|
43 |
|
| 43 |
import org.eclipse.jface.util.Util; |
44 |
import org.eclipse.jface.util.Util; |
| 44 |
|
45 |
|
|
Lines 307-312
Link Here
|
| 307 |
} |
308 |
} |
| 308 |
} |
309 |
} |
| 309 |
|
310 |
|
|
|
311 |
private static final boolean DEBUG= false; |
| 312 |
|
| 310 |
/** |
313 |
/** |
| 311 |
* <code>true</code> if we're on a Mac, where "new GC(canvas)" is expensive. |
314 |
* <code>true</code> if we're on a Mac, where "new GC(canvas)" is expensive. |
| 312 |
* @see <a href="https://bugs.eclipse.org/298936">bug 298936</a> |
315 |
* @see <a href="https://bugs.eclipse.org/298936">bug 298936</a> |
|
Lines 637-642
Link Here
|
| 637 |
|
640 |
|
| 638 |
Rectangle r= new Rectangle(0, 0, 0, 0); |
641 |
Rectangle r= new Rectangle(0, 0, 0, 0); |
| 639 |
int yy, hh= ANNOTATION_HEIGHT; |
642 |
int yy, hh= ANNOTATION_HEIGHT; |
|
|
643 |
|
| 644 |
/** height of the vertical thumb, or -1 if values have not been calculated yet */ |
| 645 |
int thumbHeight= -1; |
| 646 |
int visibleLines= 1; |
| 647 |
int invisibleLines= 0; |
| 640 |
|
648 |
|
| 641 |
IDocument document= fTextViewer.getDocument(); |
649 |
IDocument document= fTextViewer.getDocument(); |
| 642 |
StyledText textWidget= fTextViewer.getTextWidget(); |
650 |
StyledText textWidget= fTextViewer.getTextWidget(); |
|
Lines 650-658
Link Here
|
| 650 |
int maxLines= textWidget.getLineCount(); |
658 |
int maxLines= textWidget.getLineCount(); |
| 651 |
Point size= fCanvas.getSize(); |
659 |
Point size= fCanvas.getSize(); |
| 652 |
int writable= JFaceTextUtil.computeLineHeight(textWidget, 0, maxLines, maxLines); |
660 |
int writable= JFaceTextUtil.computeLineHeight(textWidget, 0, maxLines, maxLines); |
|
|
661 |
boolean noScrollThumb= false; |
| 653 |
if (size.y > writable) |
662 |
if (size.y > writable) |
| 654 |
size.y= Math.max(writable - fHeader.getSize().y, 0); |
663 |
noScrollThumb= true; |
| 655 |
|
664 |
|
| 656 |
for (Iterator iterator= fAnnotationsSortedByLayer.iterator(); iterator.hasNext();) { |
665 |
for (Iterator iterator= fAnnotationsSortedByLayer.iterator(); iterator.hasNext();) { |
| 657 |
Object annotationType= iterator.next(); |
666 |
Object annotationType= iterator.next(); |
| 658 |
|
667 |
|
|
Lines 706-712
Link Here
|
| 706 |
|
715 |
|
| 707 |
int startOffset= visible != null ? annotationOffset - visible.getOffset() : widgetRegion.getOffset(); |
716 |
int startOffset= visible != null ? annotationOffset - visible.getOffset() : widgetRegion.getOffset(); |
| 708 |
int startLine= textWidget.getLineAtOffset(startOffset); |
717 |
int startLine= textWidget.getLineAtOffset(startOffset); |
| 709 |
yy= Math.min((startLine * size.y) / maxLines, size.y - hh); |
718 |
|
|
|
719 |
if (thumbHeight == -1) { |
| 720 |
ScrollBar verticalBar= textWidget.getVerticalBar(); |
| 721 |
thumbHeight= verticalBar != null ? verticalBar.getThumbBounds().height : 0; |
| 722 |
|
| 723 |
// XXX: To avoid jumping when lines become visible/invisible, visibleLines should ideally be computed as double, not int |
| 724 |
int topIndex= textWidget.getLineIndex(0); |
| 725 |
int partialBottomIndex= JFaceTextUtil.getPartialBottomIndex(textWidget); |
| 726 |
visibleLines= partialBottomIndex - topIndex + 1; |
| 727 |
invisibleLines= maxLines - visibleLines; |
| 728 |
if (DEBUG) |
| 729 |
System.out.println("vis: " + visibleLines + ", invis: " + invisibleLines); //$NON-NLS-1$ //$NON-NLS-2$ |
| 730 |
} |
| 731 |
|
| 732 |
// Hint: (thumbHeight / 2) / (visibleLines / 2) == thumbHeight / visibleLines; |
| 733 |
// Hint2: To avoid rounding errors with integer arithmetic, we have to do the division by 2 only at the very end. |
| 734 |
|
| 735 |
if (noScrollThumb || invisibleLines <= 0) { // relative positions don't make sense: use |
| 736 |
int offset= fCanvas.getLocation().y; |
| 737 |
yy = Math.max(0, (2 * startLine + 1) * writable / (maxLines * 2) - offset); |
| 738 |
|
| 739 |
} else if (startLine + 1 < visibleLines / 2) { // before middle of first page: map to area from 0 to thumbHeight/2 |
| 740 |
yy= startLine * thumbHeight / visibleLines; |
| 741 |
|
| 742 |
} else if (maxLines - visibleLines / 2 <= startLine) { // after middle of last page: map to area from size.y-1 - thumbHeight/2 to size.y-1 |
| 743 |
yy= (2 * (size.y-1) - thumbHeight + 2 * (startLine - (maxLines - visibleLines / 2) + 1) * thumbHeight / visibleLines) / 2; |
| 744 |
|
| 745 |
} else { |
| 746 |
yy= (thumbHeight + 2 * (startLine + 1 - visibleLines / 2) * (size.y - thumbHeight) / invisibleLines) / 2; |
| 747 |
} |
| 748 |
|
| 749 |
// center should be at the calculated position: |
| 750 |
yy-= hh / 2; |
| 751 |
// cap at start/end: |
| 752 |
yy= Math.max(0, Math.min(yy, size.y-1 - hh)); |
| 710 |
|
753 |
|
| 711 |
if (!areColorsComputed) { |
754 |
if (!areColorsComputed) { |
| 712 |
fill= getFillColor(annotationType, style[t] == FilterIterator.TEMPORARY); |
755 |
fill= getFillColor(annotationType, style[t] == FilterIterator.TEMPORARY); |
|
Lines 735-740
Link Here
|
| 735 |
} |
778 |
} |
| 736 |
} |
779 |
} |
| 737 |
} |
780 |
} |
|
|
781 |
|
| 782 |
if (DEBUG) { |
| 783 |
// draw debugging guides (boundaries): |
| 784 |
gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_DARK_MAGENTA)); |
| 785 |
yy= thumbHeight / 2; |
| 786 |
gc.drawLine(0, yy, size.x/2, yy); |
| 787 |
yy= size.y - thumbHeight / 2; |
| 788 |
gc.drawLine(0, yy, size.x/2, yy); |
| 789 |
|
| 790 |
gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_BLUE)); |
| 791 |
yy= 0; |
| 792 |
gc.drawLine(0, yy, size.x/2, yy); |
| 793 |
yy= size.y - 1; |
| 794 |
gc.drawLine(0, yy, size.x/2, yy); |
| 795 |
} |
| 738 |
} |
796 |
} |
| 739 |
|
797 |
|
| 740 |
/* |
798 |
/* |