protected void doPaint1(GC gc) {
if (fModel == null || fCachedTextViewer == null)
return;
ITextViewerExtension5 extension= (ITextViewerExtension5) fCachedTextViewer;
fScrollPos= fCachedTextWidget.getTopPixel();
Point dimension= fCanvas.getSize();
int vOffset= getInclusiveTopIndexStartOffset();
int vLength= getExclusiveBottomIndexEndOffset() - vOffset;
// draw Annotations
Rectangle r= new Rectangle(0, 0, 0, 0);
ReusableRegion range= new ReusableRegion();
int minLayer= Integer.MAX_VALUE, maxLayer= Integer.MIN_VALUE;
fCachedAnnotations.clear();
Iterator iter;
if (fModel instanceof IAnnotationModelExtension2)
iter= ((IAnnotationModelExtension2)fModel).getAnnotationIterator(vOffset, vLength + 1, true, true);
else
iter= fModel.getAnnotationIterator();
while (iter.hasNext()) {
Annotation annotation= (Annotation) iter.next();
if (skip(annotation))
continue;
Position position= fModel.getPosition(annotation);
if (position == null)
continue;
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=217710
int extendedVLength= position.getLength() == 0 ? vLength + 1 : vLength;
if (!position.overlapsWith(vOffset, extendedVLength))
continue;
int lay= IAnnotationAccessExtension.DEFAULT_LAYER;
if (fAnnotationAccessExtension != null)
lay= fAnnotationAccessExtension.getLayer(annotation);
minLayer= Math.min(minLayer, lay);
maxLayer= Math.max(maxLayer, lay);
fCachedAnnotations.add(new Tuple(annotation, position));
}
Collections.sort(fCachedAnnotations, fTupleComparator);
for (int layer= minLayer; layer <= maxLayer; layer++) {
for (int i= 0, n= fCachedAnnotations.size(); i < n; i++) {
Tuple tuple= (Tuple) fCachedAnnotations.get(i);
Annotation annotation= tuple.annotation;
Position position= tuple.position;
int lay= IAnnotationAccessExtension.DEFAULT_LAYER;
if (fAnnotationAccessExtension != null)
lay= fAnnotationAccessExtension.getLayer(annotation);
if (lay != layer) // wrong layer: skip annotation
continue;
range.setOffset(position.getOffset());
range.setLength(position.getLength());
IRegion widgetRegion= extension.modelRange2WidgetRange(range);
if (widgetRegion == null)
continue;
int startLine= extension.widgetLineOfWidgetOffset(widgetRegion.getOffset());
if (startLine == -1)
continue;
int endLine= extension.widgetLineOfWidgetOffset(widgetRegion.getOffset() + Math.max(widgetRegion.getLength() -1, 0));
if (endLine == -1)
continue;
r.x= 0;
r.y= JFaceTextUtil.computeLineHeight(fCachedTextWidget, 0, startLine, startLine) - fScrollPos;