use of org.eclipse.swt.custom.StyledText in project eclipse.platform.text by eclipse.
the class VerticalRuler method doPaint1.
/**
* Draws the vertical ruler w/o drawing the Canvas background. Uses
* <code>ITextViewerExtension5</code> for its implementation. Will replace
* <code>doPaint(GC)</code>.
*
* @param gc the GC to draw into
*/
protected void doPaint1(GC gc) {
if (fModel == null || fTextViewer == null)
return;
IAnnotationAccessExtension annotationAccessExtension = null;
if (fAnnotationAccess instanceof IAnnotationAccessExtension)
annotationAccessExtension = (IAnnotationAccessExtension) fAnnotationAccess;
ITextViewerExtension5 extension = (ITextViewerExtension5) fTextViewer;
StyledText textWidget = fTextViewer.getTextWidget();
fScrollPos = textWidget.getTopPixel();
Point dimension = fCanvas.getSize();
// draw Annotations
Rectangle r = new Rectangle(0, 0, 0, 0);
// loop at least once through layers.
int maxLayer = 1;
for (int layer = 0; layer < maxLayer; layer++) {
Iterator<Annotation> iter = fModel.getAnnotationIterator();
while (iter.hasNext()) {
IAnnotationPresentation annotationPresentation = null;
Annotation annotation = iter.next();
int lay = IAnnotationAccessExtension.DEFAULT_LAYER;
if (annotationAccessExtension != null)
lay = annotationAccessExtension.getLayer(annotation);
else if (annotation instanceof IAnnotationPresentation) {
annotationPresentation = (IAnnotationPresentation) annotation;
lay = annotationPresentation.getLayer();
}
// dynamically update layer maximum
maxLayer = Math.max(maxLayer, lay + 1);
if (// wrong layer: skip annotation
lay != layer)
continue;
Position position = fModel.getPosition(annotation);
if (position == null)
continue;
IRegion widgetRegion = extension.modelRange2WidgetRange(new Region(position.getOffset(), position.getLength()));
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(textWidget, 0, startLine, startLine) - fScrollPos;
r.width = dimension.x;
int lines = endLine - startLine;
r.height = JFaceTextUtil.computeLineHeight(textWidget, startLine, endLine + 1, lines + 1);
if (// annotation within visible area
r.y < dimension.y && annotationAccessExtension != null)
annotationAccessExtension.paint(annotation, gc, fCanvas, r);
else if (annotationPresentation != null)
annotationPresentation.paint(gc, fCanvas, r);
}
}
}
use of org.eclipse.swt.custom.StyledText in project eclipse.platform.text by eclipse.
the class VisibleLinesTracker method track.
/**
* Track the line height change of the {@link StyledText} of the given handler an call the given
* handler.
*
* @param viewer the viewer to track
* @param handler the handler to call when line height change.
*/
static void track(ITextViewer viewer, Consumer<StyledText> handler) {
StyledText textWidget = viewer != null ? viewer.getTextWidget() : null;
if (textWidget == null) {
return;
}
VisibleLinesTracker tracker = (VisibleLinesTracker) textWidget.getData(DATA_KEY);
if (tracker == null) {
tracker = new VisibleLinesTracker(viewer);
textWidget.setData(DATA_KEY, tracker);
}
tracker.addHandler(handler);
}
use of org.eclipse.swt.custom.StyledText in project eclipse.platform.text by eclipse.
the class VisibleLinesTracker method paintControl.
@Override
public void paintControl(PaintEvent e) {
StyledText textWidget = viewer.getTextWidget();
// track if bottom line index or bottom line pixel changed.
if (oldBottom == -1) {
oldBottom = JFaceTextUtil.getPartialBottomIndex(viewer);
oldBottomPixel = JFaceTextUtil.getLinePixel(textWidget, oldBottom);
return;
}
int newBottom = JFaceTextUtil.getPartialBottomIndex(viewer);
if (newBottom != oldBottom) {
oldBottom = newBottom;
oldBottomPixel = JFaceTextUtil.getLinePixel(textWidget, oldBottom);
handlers.forEach(handler -> handler.accept(textWidget));
return;
}
int newBottomPixel = JFaceTextUtil.getLinePixel(textWidget, newBottom);
if (newBottomPixel != oldBottomPixel) {
oldBottomPixel = newBottomPixel;
handlers.forEach(handler -> handler.accept(textWidget));
return;
}
}
use of org.eclipse.swt.custom.StyledText in project eclipse.platform.text by eclipse.
the class AbstractInlinedAnnotation method redraw.
/**
* Redraw the inlined annotation.
*/
public void redraw() {
StyledText text = getTextWidget();
InlinedAnnotationSupport.runInUIThread(text, (t) -> {
Position pos = getPosition();
int offset = pos.getOffset();
ISourceViewer viewer = getViewer();
if (viewer instanceof ITextViewerExtension5) {
// adjust offset according folded content
offset = ((ITextViewerExtension5) viewer).modelOffset2WidgetOffset(offset);
}
InlinedAnnotationDrawingStrategy.draw(this, null, t, offset, pos.getLength(), null);
});
}
use of org.eclipse.swt.custom.StyledText in project eclipse.platform.text by eclipse.
the class AbstractInlinedAnnotation method onMouseOut.
/**
* Called when mouse out the inlined annotation.
*
* @param e the mouse event
*/
public void onMouseOut(MouseEvent e) {
StyledText styledText = (StyledText) e.widget;
styledText.setCursor(null);
}
Aggregations